mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
* feat(studio): layers panel and marquee read an opaque preview over its channel The runtime answers a new layers request with the Layers walk: each layer's handle, depth, child count, z-index and kind, by the rules Studio walks a scriptable frame with, which move to core. On an opaque frame the Layers panel lists, selects and drills in from it, and the marquee measures its candidates over the channel and selects from their descriptions. An opaque selection maps to a timeline clip known only by its clip id, so a marquee's picks survive the timeline sync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(studio): opaque preview hover, layers drill-in, marquee paging and delete path Review follow-ups for the opaque-preview Layers panel and marquee: - Delete on an opaque selection runs the DOM delete again. The clip-id match that lets a selection find a row known only by its clip id is now opt-in (`clipIdScope`), passed only by selection sync and the Layers seek, never by delete or group commits, which need a patch target that row lacks. A row with no file reads as in the open composition, as the forward lookup does. - The runtime's `layers` reports a drill-in group it no longer has (`missingGroup`) and lists nothing, so the panel leaves the drill-in after a reload as the same-origin branch does, rather than list the whole page. - `layers` takes an `offset`, and the marquee pages through every layer, so elements past one reply's 2,048 cap still band-select. - A Layers refresh that lands while an opaque read is in flight runs once more when it settles, instead of being dropped. - A hover resolved for a pointer move that a leave or newer move superseded is dropped. - `pointer-targets` reads the hit stack once per request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(core): keep the layers paging test inside the Windows runner's timeout The paging test walked the 2,051-layer page three times with every row mapped, which ran past 5 s on windows-latest. It now maps only the last page's rows and has its own 20 s timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
4.5 KiB
TypeScript
116 lines
4.5 KiB
TypeScript
/** The Layers walk `layers` answers; Studio walks a frame it scripts by the same rules. */
|
|
import { isRichTextFormattingTag } from "../utils/richTextSanitize";
|
|
import { isClipHiddenByRuntime } from "../studioPreviewMark";
|
|
import { MAX_QUERY_MATCHES, type EditingElementHandle } from "./editingElement";
|
|
import { elementForHandle, handleFor } from "./editingHandles";
|
|
import { isDomLayerElement } from "./editingTargets";
|
|
import { isElementNode } from "./domRealm";
|
|
|
|
export type LayerKind = "image" | "video" | "audio" | "vector" | "group" | "text" | "shape";
|
|
|
|
export interface EditingLayer {
|
|
handle: EditingElementHandle;
|
|
depth: number;
|
|
childCount: number;
|
|
zIndex: number;
|
|
kind: LayerKind;
|
|
}
|
|
|
|
export function isCompositionHost(el: Element): boolean {
|
|
return el.hasAttribute("data-composition-src") || el.hasAttribute("data-composition-file");
|
|
}
|
|
|
|
export function hasOnlyFormattingChildren(element: HTMLElement): boolean {
|
|
for (const child of Array.from(element.children)) {
|
|
if (!isRichTextFormattingTag(child.tagName)) return false;
|
|
if (child.namespaceURI !== "http://www.w3.org/1999/xhtml") return false;
|
|
// Formatting nests, and a structural child hidden inside a span is still structural.
|
|
if (!hasOnlyFormattingChildren(child as HTMLElement)) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/** What a Layers row tells a person an element is: its media tag, a group, text, or else a shape. */
|
|
export function layerKindOf(el: Element, hasChildren: boolean): LayerKind {
|
|
const tag = el.tagName.toLowerCase();
|
|
if (tag === "img" || tag === "picture") return "image";
|
|
if (tag === "video") return "video";
|
|
if (tag === "audio") return "audio";
|
|
if (tag === "svg") return "vector";
|
|
if (el.hasAttribute("data-hf-group") || isCompositionHost(el)) return "group";
|
|
if (hasOnlyFormattingChildren(el as HTMLElement) && el.textContent?.trim()) return "text";
|
|
return hasChildren ? "group" : "shape";
|
|
}
|
|
|
|
/** The inline `z-index`, else the computed one; 0 for `auto` or none. */
|
|
export function elementZIndex(element: HTMLElement): number {
|
|
const inline = element.style?.zIndex;
|
|
if (inline && inline !== "auto") {
|
|
const parsed = parseInt(inline, 10);
|
|
if (Number.isFinite(parsed)) return parsed;
|
|
}
|
|
const value = element.ownerDocument?.defaultView?.getComputedStyle(element).zIndex;
|
|
if (!value || value === "auto") return 0;
|
|
const parsed = parseInt(value, 10);
|
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
}
|
|
|
|
const layerChildren = (el: Element) =>
|
|
Array.from(el.children).filter(
|
|
(child) => isElementNode(child) && isDomLayerElement(child as HTMLElement),
|
|
).length;
|
|
|
|
/** Every layer under `roots`, in document order, with its depth among layers. */
|
|
function walkLayers(
|
|
roots: readonly Element[],
|
|
max = Number.POSITIVE_INFINITY,
|
|
): {
|
|
layers: Array<{ element: HTMLElement; depth: number; childCount: number }>;
|
|
truncated: boolean;
|
|
} {
|
|
const layers: Array<{ element: HTMLElement; depth: number; childCount: number }> = [];
|
|
let truncated = false;
|
|
const visit = (el: HTMLElement, depth: number) => {
|
|
if (truncated || isClipHiddenByRuntime(el)) return;
|
|
const layer = isDomLayerElement(el);
|
|
if (layer) {
|
|
if (layers.length === max) {
|
|
truncated = true;
|
|
return;
|
|
}
|
|
layers.push({ element: el, depth, childCount: layerChildren(el) });
|
|
}
|
|
for (const child of Array.from(el.children)) {
|
|
if (isElementNode(child)) visit(child as HTMLElement, layer ? depth + 1 : depth);
|
|
}
|
|
};
|
|
for (const root of roots) if (isElementNode(root)) visit(root as HTMLElement, 0);
|
|
return { layers, truncated };
|
|
}
|
|
|
|
/**
|
|
* `layers`: the composition's layers, or the drilled-into group's when `group` names one, from the
|
|
* `offset`th on. A `group` this page no longer has lists nothing, so Studio can leave the drill-in.
|
|
*/
|
|
export function layersOf(
|
|
group?: EditingElementHandle,
|
|
offset = 0,
|
|
): { layers: EditingLayer[]; truncated: boolean; missingGroup: boolean } {
|
|
const scope = group ? elementForHandle(group) : null;
|
|
if (group && !scope) return { layers: [], truncated: false, missingGroup: true };
|
|
const root = document.querySelector("[data-composition-id]") ?? document.documentElement;
|
|
const roots = scope ? Array.from(scope.children) : root ? [root] : [];
|
|
const walk = walkLayers(roots, offset + MAX_QUERY_MATCHES);
|
|
return {
|
|
truncated: walk.truncated,
|
|
missingGroup: false,
|
|
layers: walk.layers.slice(offset).map(({ element, depth, childCount }) => ({
|
|
handle: handleFor(element),
|
|
depth,
|
|
childCount,
|
|
zIndex: elementZIndex(element),
|
|
kind: layerKindOf(element, childCount > 0),
|
|
})),
|
|
};
|
|
}
|