DEV Community

Cover image for Keeping AI-Generated Decks Editable Without Layout Thrash
Chloe Chen
Chloe Chen

Posted on

Keeping AI-Generated Decks Editable Without Layout Thrash

At 3:07 a.m. the on-call page was not a model timeout. It was a deck editor that had stopped painting. An agent had scaffolded a twelve-slide internal review, someone resized a callout, and the main thread spent the rest of the drag in layout. By the time focus fell out of the theme dialog, screen-reader users were reading canvas nodes they could not see. We had adopted chuspeeism/dashi-ppt-skill as the generation layer, and the first production path showed that generation can be slow. The editor cannot be.

The integration splits into three stages with a hard boundary between them. The skill selects a visual theme and scaffolds slide markup. A React shell owns live editing. A pure export function snapshots the committed DOM into HTML, PDF, or PPTX. That separation is what makes the skill usable once a human starts dragging and tabbing. We do not own the skill. We own the shell that refuses to animate layout and the exporter that trusts only committed sizes.

The first integration reproduced two failures slide tutorials skip. Resizing a callout wrote style.width and style.height from a pointer-move handler. Each write forced layout, the read in the same frame observed the new box, and frames dropped until pointerup. In parallel, the theme picker was marked role="dialog" with no focus trap. Tab left the overlay, the virtual cursor announced hidden canvas content, and keyboard users lost their place. Both bugs are layout and focus model violations, not missing libraries. Recovery is operational, not a retry of the model: drop the in-flight drag, ignore uncommitted transforms, and restore focus to the control that opened the dialog.

The dialog below is the editor surface we mount over any slide the skill emits. It stays inside Tailwind utilities and the platform focus order. Escape closes, Tab cycles only the dialog's controls, and aria-modal plus an explicit label keep the accessibility tree honest. An empty focusable set does not get a synthetic trap; Escape still closes.

import { useEffect, useRef } from "react";

type Props = {
  open: boolean;
  title: string;
  onClose: () => void;
  children: React.ReactNode;
};

export function SlideDialog({ open, title, onClose, children }: Props) {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (!open || !ref.current) return;
    const root = ref.current;
    const nodes = root.querySelectorAll<HTMLElement>(
      'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
    );
    const first = nodes[0];
    const last = nodes[nodes.length - 1];
    first?.focus();

    const onKey = (e: KeyboardEvent) => {
      if (e.key === "Escape") onClose();
      if (e.key !== "Tab" || nodes.length === 0) return;
      if (e.shiftKey && document.activeElement === first) {
        e.preventDefault();
        last?.focus();
      } else if (!e.shiftKey && document.activeElement === last) {
        e.preventDefault();
        first?.focus();
      }
    };
    root.addEventListener("keydown", onKey);
    return () => root.removeEventListener("keydown", onKey);
  }, [open, onClose]);

  if (!open) return null;

  return (
    <div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/40">
      <div
        ref={ref}
        role="dialog"
        aria-modal="true"
        aria-labelledby="slide-dialog-title"
        className="w-full max-w-lg rounded-xl bg-white p-6 shadow-xl"
      >
        <h2 id="slide-dialog-title" className="text-lg font-semibold text-slate-900">
          {title}
        </h2>
        <div className="mt-4 text-slate-700">{children}</div>
        <button
          type="button"
          onClick={onClose}
          className="mt-6 rounded-md bg-slate-900 px-3 py-1.5 text-sm text-white"
        >
          Done
        </button>
      </div>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

Resize no longer touches layout properties. A container query owns the card's typography. During drag, only a transform scales a preview ghost. pointerup commits a data attribute the exporter reads. Animating transform stays on the compositor; width and height writes do not. If pointerup never fires, the attribute stays at the last commit and the ghost is discarded on the next frame.

.slide-card {
  container-type: inline-size;
  width: 100%;
}

.slide-card__preview {
  transform-origin: top left;
  will-change: transform;
}

.slide-card[data-dragging="true"] .slide-card__preview {
  animation: nudge 180ms ease forwards;
}

@keyframes nudge {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}

@container (min-width: 480px) {
  .slide-card__title { font-size: 1.35rem; line-height: 1.25; }
}
Enter fullscreen mode Exit fullscreen mode

The trade-off is measurement. Transforms do not change the layout boxes that HTML-to-PPTX converters inspect, so the export step must read the committed size attribute rather than getBoundingClientRect after a scale. The focus trap is about forty lines and must be rechecked whenever the skill's generated heading structure changes, but without it keyboard and screen-reader order diverge the moment a modal opens. Container queries keep per-slide type scale local; the cost is skipping them in the static export path, where we flatten to explicit sizes so older print renderers stay predictable.

Theme regeneration is the other latency cliff. The agent client used for fallback tests is a standard OpenAI-compatible SDK with baseURL: "https://b-lost.com/v1". Under provider failover, a single slide's theme prompt stayed inside the same budget we already allow for one regeneration, so the editor did not need a special slow-path. Past that budget we keep the last committed theme and do not paint a partial palette. The skill remains responsible for scaffolding and export. The shell only refuses layout animation and keeps focus inside the dialog on screen.

The hardest call is which box is real. A live transform keeps the drag on the compositor, and a committed attribute is the only size the PPTX path will honor. Update the attribute during the gesture and you are back in layout thrash. Wait for pointerup and a crash, a blur, or a killed tab can export the previous card. We log the miss and ship the last commit. That is the boundary: the skill may be non-deterministic; the shell may not guess.

Where do you freeze the box an exporter is allowed to believe when the pointer is still moving?

Top comments (0)