@hyperframes/studio 0.9.41 → 0.9.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/assets/{codec-B_mpbc4w.js → codec-DHChmhF2.js} +1 -1
  2. package/dist/assets/{hyperframes-player-Dvi3I_mv.js → hyperframes-player-CdbweVDs.js} +1 -1
  3. package/dist/assets/{index-B5ExwsOp.js → index-CjWDrWWG.js} +166 -166
  4. package/dist/assets/{index-BrFm9Y5k.js → index-l-ti2dV8.js} +1 -1
  5. package/dist/assets/{pausedVideoDecoder-MHQ57yZ6.js → pausedVideoDecoder-xqOQ0ciK.js} +1 -1
  6. package/dist/index.d.ts +9 -1
  7. package/dist/index.html +1 -1
  8. package/dist/index.js +1380 -989
  9. package/package.json +10 -10
  10. package/src/components/editor/LayersPanel.opaque.test.ts +176 -0
  11. package/src/components/editor/LayersPanel.tsx +41 -10
  12. package/src/components/editor/domEditInlineText.ts +1 -16
  13. package/src/components/editor/domEditOverlayGeometry.ts +2 -0
  14. package/src/components/editor/domEditOverlayStartGesture.ts +31 -7
  15. package/src/components/editor/domEditingTypes.ts +7 -1
  16. package/src/components/editor/gestureUndoRevert.ts +18 -1
  17. package/src/components/editor/inlineTextStyleRange.fill.test.ts +129 -0
  18. package/src/components/editor/inlineTextStyleRange.test.ts +0 -82
  19. package/src/components/editor/layerKind.ts +2 -19
  20. package/src/components/editor/layersPanelSort.ts +2 -2
  21. package/src/components/editor/manualEdits.ts +1 -0
  22. package/src/components/editor/manualEditsSnapshot.ts +10 -0
  23. package/src/components/editor/manualOffsetDrag.test.ts +1 -1
  24. package/src/components/editor/manualOffsetDrag.ts +17 -6
  25. package/src/components/editor/marqueeCommit.ts +47 -4
  26. package/src/components/editor/plainTranslate.ts +37 -16
  27. package/src/components/editor/previewDrafts.test.ts +263 -0
  28. package/src/components/editor/previewDrafts.ts +73 -0
  29. package/src/components/editor/previewGestureStartRead.test.ts +279 -0
  30. package/src/components/editor/previewGestureStartRead.ts +67 -0
  31. package/src/components/editor/previewGestureStarts.ts +21 -15
  32. package/src/components/editor/previewLayers.test.ts +308 -0
  33. package/src/components/editor/previewLayers.ts +164 -0
  34. package/src/components/editor/previewOverlayRects.test.ts +62 -0
  35. package/src/components/editor/previewOverlayRects.ts +23 -8
  36. package/src/components/editor/previewPointerTargets.test.ts +68 -1
  37. package/src/components/editor/previewSelection.ts +55 -11
  38. package/src/components/editor/resizeDraft.ts +38 -0
  39. package/src/components/editor/snapTargetCollection.ts +26 -62
  40. package/src/components/editor/useDomEditOverlayGestures.ts +2 -2
  41. package/src/components/editor/useLayerDrag.ts +1 -1
  42. package/src/components/nle/NLEPreview.slowBoot.test.ts +0 -1
  43. package/src/hooks/domEditDeleteMembers.test.ts +7 -0
  44. package/src/hooks/domSelectionTimelineMirror.ts +3 -1
  45. package/src/hooks/timelineTimingSync.ts +4 -1
  46. package/src/hooks/useDomSelection.ts +2 -0
  47. package/src/hooks/useEditorSave.test.tsx +22 -1
  48. package/src/hooks/useEditorSave.ts +3 -1
  49. package/src/hooks/usePreviewInteraction.ts +4 -1
  50. package/src/hooks/useProjectFileWriter.ts +7 -3
  51. package/src/hooks/useTimelineSelectionPreviewSync.test.tsx +30 -0
  52. package/src/hooks/useTimelineSelectionPreviewSync.ts +7 -2
  53. package/src/player/lib/layerOrdering.ts +2 -11
  54. package/src/player/lib/previewElements.ts +68 -0
  55. package/src/test-setup.ts +2 -0
  56. package/src/utils/gsapSoftReload.ts +1 -1
  57. package/src/utils/studioFileHistory.ts +1 -1
  58. package/src/utils/studioHelpers.ts +27 -4
  59. package/src/utils/studioSaveDiagnostics.test.ts +34 -0
  60. package/src/utils/studioSaveDiagnostics.ts +35 -6
  61. package/src/utils/timelineCompositionInsert.ts +3 -1
@@ -0,0 +1,129 @@
1
+ // @vitest-environment jsdom
2
+ // happy-dom drops the vendor-prefixed fill property these tests assert on.
3
+
4
+ import { afterEach, describe, expect, it, vi } from "vitest";
5
+ import { applyInlineStyle } from "./inlineTextStyleRange";
6
+
7
+ afterEach(() => {
8
+ vi.restoreAllMocks();
9
+ document.body.innerHTML = "";
10
+ });
11
+
12
+ function mount(html: string): HTMLElement {
13
+ document.body.innerHTML = `<h1>${html}</h1>`;
14
+ return document.body.firstElementChild as HTMLElement;
15
+ }
16
+
17
+ /** Every text node and line break in order, with the offset each one starts at. */
18
+ function charSpans(host: HTMLElement): Array<{ node: Node; from: number; length: number }> {
19
+ const spans: Array<{ node: Node; from: number; length: number }> = [];
20
+ const walker = document.createTreeWalker(host, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT);
21
+ let seen = 0;
22
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
23
+ const isBreak = node.nodeType === 1 && (node as Element).tagName === "BR";
24
+ if (node.nodeType === 1 && !isBreak) continue;
25
+ const length = isBreak ? 1 : (node.textContent?.length ?? 0);
26
+ spans.push({ node, from: seen, length });
27
+ seen += length;
28
+ }
29
+ return spans;
30
+ }
31
+
32
+ /**
33
+ * A range over the host's text, by character offsets across the whole element.
34
+ *
35
+ * A line break counts as one character, the same way the module does, but is
36
+ * never landed on: a boundary there belongs to the text beside it, which is
37
+ * where a real selection would put it too.
38
+ */
39
+ function rangeOver(host: HTMLElement, start: number, end: number): Range {
40
+ const range = document.createRange();
41
+ const text = charSpans(host).filter((span) => span.node.nodeType === 3);
42
+ const at = (offset: number) => text.find((span) => span.from + span.length >= offset);
43
+ const from = at(start);
44
+ const to = at(end);
45
+ if (from) range.setStart(from.node, start - from.from);
46
+ if (from && to) range.setEnd(to.node, end - to.from);
47
+ return range;
48
+ }
49
+
50
+ /**
51
+ * A colour that does not paint is the same to the user as one that did not save.
52
+ *
53
+ * `-webkit-text-fill-color` inherits and paints the glyph fill, so a composition
54
+ * that sets it on a text element wins over any `color` the editor puts on a run
55
+ * inside it. The run saved correctly and rendered in someone else's colour,
56
+ * which reads as the colour picker being broken.
57
+ */
58
+ describe("applyInlineStyle when something else is painting the glyphs", () => {
59
+ function stubFill(fill: string | null | ((element: HTMLElement) => string | null)) {
60
+ const real = window.getComputedStyle.bind(window);
61
+ vi.spyOn(window, "getComputedStyle").mockImplementation(((element: Element) => {
62
+ const computed = real(element as HTMLElement);
63
+ const resolvedFill = typeof fill === "function" ? fill(element as HTMLElement) : fill;
64
+ return new Proxy(computed, {
65
+ get: (target, key) => {
66
+ if (key === "webkitTextFillColor") return resolvedFill ?? undefined;
67
+ if (key === "color") return (element as HTMLElement).style.color || "rgb(0, 0, 0)";
68
+ return Reflect.get(target, key);
69
+ },
70
+ });
71
+ }) as typeof window.getComputedStyle);
72
+ }
73
+
74
+ it("mirrors the colour into the fill when an ancestor is overpainting", () => {
75
+ const host = mount("Hello world");
76
+ stubFill("rgb(255, 255, 255)");
77
+ applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" });
78
+
79
+ expect(host.innerHTML).toContain("-webkit-text-fill-color: rgb(255, 0, 149)");
80
+ expect(host.innerHTML).toContain("color: rgb(255, 0, 149)");
81
+ });
82
+
83
+ it("leaves the markup alone when nothing is overpainting", () => {
84
+ const host = mount("Hello world");
85
+ stubFill("rgb(255, 0, 149)");
86
+ applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" });
87
+
88
+ expect(host.innerHTML).not.toContain("-webkit-text-fill-color");
89
+ expect(host.innerHTML).toContain("color: rgb(255, 0, 149)");
90
+ });
91
+
92
+ it("says nothing about a run that carries no colour", () => {
93
+ const host = mount("Hello world");
94
+ stubFill("rgb(255, 255, 255)");
95
+ applyInlineStyle(rangeOver(host, 6, 11), { "font-weight": "700" });
96
+
97
+ expect(host.innerHTML).not.toContain("-webkit-text-fill-color");
98
+ });
99
+
100
+ it("mirrors only the run whose own ancestor path is overpainting", () => {
101
+ const host = mount(
102
+ '<span data-hf-text-key="child:0" style="color: blue">left</span>' +
103
+ '<span data-hf-text-key="child:1" style="color: green">right</span>',
104
+ );
105
+ stubFill((element) =>
106
+ element.textContent === "left" ? "rgb(255, 255, 255)" : element.style.color,
107
+ );
108
+
109
+ applyInlineStyle(rangeOver(host, 4, 9), { color: "red" });
110
+
111
+ const [left, right] = Array.from(host.querySelectorAll<HTMLElement>("span"));
112
+ expect(left?.style.getPropertyValue("-webkit-text-fill-color")).toBe("blue");
113
+ expect(right?.style.getPropertyValue("-webkit-text-fill-color")).toBe("");
114
+ });
115
+
116
+ it("drops a generated mirror when the ancestor stops overpainting", () => {
117
+ const host = mount("Hello world");
118
+ let overpainted = true;
119
+ stubFill((element) => (overpainted ? "rgb(255, 255, 255)" : element.style.color));
120
+ applyInlineStyle(rangeOver(host, 6, 11), { color: "red" });
121
+ expect(host.innerHTML).toContain("-webkit-text-fill-color");
122
+
123
+ overpainted = false;
124
+ const live = document.getSelection()?.getRangeAt(0);
125
+ if (live) applyInlineStyle(live, { "font-weight": "700" });
126
+
127
+ expect(host.innerHTML).not.toContain("-webkit-text-fill-color");
128
+ });
129
+ });
@@ -621,88 +621,6 @@ describe("applyInlineStyle survives a control that fires repeatedly", () => {
621
621
  expect(document.getSelection()?.toString()).toBe("cde");
622
622
  });
623
623
  });
624
-
625
- /**
626
- * A colour that does not paint is the same to the user as one that did not save.
627
- *
628
- * `-webkit-text-fill-color` inherits and paints the glyph fill, so a composition
629
- * that sets it on a text element wins over any `color` the editor puts on a run
630
- * inside it. The run saved correctly and rendered in someone else's colour,
631
- * which reads as the colour picker being broken.
632
- */
633
- describe("applyInlineStyle when something else is painting the glyphs", () => {
634
- function stubFill(fill: string | null | ((element: HTMLElement) => string | null)) {
635
- const real = window.getComputedStyle.bind(window);
636
- vi.spyOn(window, "getComputedStyle").mockImplementation(((element: Element) => {
637
- const computed = real(element as HTMLElement);
638
- const resolvedFill = typeof fill === "function" ? fill(element as HTMLElement) : fill;
639
- return new Proxy(computed, {
640
- get: (target, key) => {
641
- if (key === "webkitTextFillColor") return resolvedFill ?? undefined;
642
- if (key === "color") return (element as HTMLElement).style.color || "rgb(0, 0, 0)";
643
- return Reflect.get(target, key);
644
- },
645
- });
646
- }) as typeof window.getComputedStyle);
647
- }
648
-
649
- it("mirrors the colour into the fill when an ancestor is overpainting", () => {
650
- const host = mount("Hello world");
651
- stubFill("rgb(255, 255, 255)");
652
- applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" });
653
-
654
- expect(host.innerHTML).toContain("-webkit-text-fill-color: rgb(255, 0, 149)");
655
- expect(host.innerHTML).toContain("color: rgb(255, 0, 149)");
656
- });
657
-
658
- it("leaves the markup alone when nothing is overpainting", () => {
659
- const host = mount("Hello world");
660
- stubFill("rgb(255, 0, 149)");
661
- applyInlineStyle(rangeOver(host, 6, 11), { color: "rgb(255, 0, 149)" });
662
-
663
- expect(host.innerHTML).not.toContain("-webkit-text-fill-color");
664
- expect(host.innerHTML).toContain("color: rgb(255, 0, 149)");
665
- });
666
-
667
- it("says nothing about a run that carries no colour", () => {
668
- const host = mount("Hello world");
669
- stubFill("rgb(255, 255, 255)");
670
- applyInlineStyle(rangeOver(host, 6, 11), { "font-weight": "700" });
671
-
672
- expect(host.innerHTML).not.toContain("-webkit-text-fill-color");
673
- });
674
-
675
- it("mirrors only the run whose own ancestor path is overpainting", () => {
676
- const host = mount(
677
- '<span data-hf-text-key="child:0" style="color: blue">left</span>' +
678
- '<span data-hf-text-key="child:1" style="color: green">right</span>',
679
- );
680
- stubFill((element) =>
681
- element.textContent === "left" ? "rgb(255, 255, 255)" : element.style.color,
682
- );
683
-
684
- applyInlineStyle(rangeOver(host, 4, 9), { color: "red" });
685
-
686
- const [left, right] = Array.from(host.querySelectorAll<HTMLElement>("span"));
687
- expect(left?.style.getPropertyValue("-webkit-text-fill-color")).toBe("blue");
688
- expect(right?.style.getPropertyValue("-webkit-text-fill-color")).toBe("");
689
- });
690
-
691
- it("drops a generated mirror when the ancestor stops overpainting", () => {
692
- const host = mount("Hello world");
693
- let overpainted = true;
694
- stubFill((element) => (overpainted ? "rgb(255, 255, 255)" : element.style.color));
695
- applyInlineStyle(rangeOver(host, 6, 11), { color: "red" });
696
- expect(host.innerHTML).toContain("-webkit-text-fill-color");
697
-
698
- overpainted = false;
699
- const live = document.getSelection()?.getRangeAt(0);
700
- if (live) applyInlineStyle(live, { "font-weight": "700" });
701
-
702
- expect(host.innerHTML).not.toContain("-webkit-text-fill-color");
703
- });
704
- });
705
-
706
624
  describe("readInlineStyleSpread", () => {
707
625
  it("reports every distinct colour in the selection, in order", () => {
708
626
  const host = mount(
@@ -1,19 +1,2 @@
1
- import { hasOnlyFormattingChildren } from "./domEditInlineText";
2
-
3
- export type LayerKind = "image" | "video" | "audio" | "vector" | "group" | "text" | "shape";
4
-
5
- export function isCompositionHost(el: Element): boolean {
6
- return el.hasAttribute("data-composition-src") || el.hasAttribute("data-composition-file");
7
- }
8
-
9
- /** What a Layers row tells a person an element is: its media tag, a group, text, or else a shape. */
10
- export function layerKindOf(el: Element, hasChildren: boolean): LayerKind {
11
- const tag = el.tagName.toLowerCase();
12
- if (tag === "img" || tag === "picture") return "image";
13
- if (tag === "video") return "video";
14
- if (tag === "audio") return "audio";
15
- if (tag === "svg") return "vector";
16
- if (el.hasAttribute("data-hf-group") || isCompositionHost(el)) return "group";
17
- if (hasOnlyFormattingChildren(el as HTMLElement) && el.textContent?.trim()) return "text";
18
- return hasChildren ? "group" : "shape";
19
- }
1
+ // One kind rule for Studio's Layers rows and the runtime that lists an opaque frame's layers.
2
+ export { isCompositionHost, layerKindOf } from "@hyperframes/core/runtime/editing-port";
@@ -40,8 +40,8 @@ export function sortLayersByZIndex(layers: DomEditLayerItem[]): DomEditLayerItem
40
40
  }
41
41
 
42
42
  chunks.sort((a, b) => {
43
- const zA = getElementZIndex(a.root.element);
44
- const zB = getElementZIndex(b.root.element);
43
+ const zA = a.root.preview?.zIndex ?? getElementZIndex(a.root.element);
44
+ const zB = b.root.preview?.zIndex ?? getElementZIndex(b.root.element);
45
45
  if (zA !== zB) return zB - zA;
46
46
  return b.domIndex - a.domIndex;
47
47
  });
@@ -41,6 +41,7 @@ export {
41
41
  restoreStudioBoxSize,
42
42
  restoreStudioRotation,
43
43
  restoreStudioPathOffset,
44
+ restoreStudioPathOffsetStyles,
44
45
  clearStudioPathOffset,
45
46
  clearStudioRotation,
46
47
  clearStudioBoxSize,
@@ -36,6 +36,7 @@ import {
36
36
  STUDIO_ORIGINAL_ROTATION_TRANSFORM_ORIGIN_ATTR,
37
37
  STUDIO_ROTATION_DRAFT_ATTR,
38
38
  } from "./manualEditsTypes";
39
+ import { endPreviewDraft } from "./previewDrafts";
39
40
  import type {
40
41
  StudioBoxSizeSnapshot,
41
42
  StudioRotationSnapshot,
@@ -117,6 +118,7 @@ function restoreStyleProperty(element: HTMLElement, property: string, value: str
117
118
  }
118
119
 
119
120
  export function restoreStudioBoxSize(element: HTMLElement, previous: StudioBoxSizeSnapshot): void {
121
+ endPreviewDraft(element, "restore");
120
122
  forgetStudioBoxSizeDraftBase(element);
121
123
  restoreStyleProperty(element, "width", previous.width);
122
124
  restoreStyleProperty(element, "height", previous.height);
@@ -176,6 +178,14 @@ export function restoreStudioRotation(
176
178
  export function restoreStudioPathOffset(
177
179
  element: HTMLElement,
178
180
  previous: StudioPathOffsetSnapshot,
181
+ ): void {
182
+ endPreviewDraft(element, "restore");
183
+ restoreStudioPathOffsetStyles(element, previous);
184
+ }
185
+
186
+ export function restoreStudioPathOffsetStyles(
187
+ element: HTMLElement,
188
+ previous: StudioPathOffsetSnapshot,
179
189
  ): void {
180
190
  if (previous.translate) element.style.setProperty("translate", previous.translate);
181
191
  else element.style.removeProperty("translate");
@@ -128,7 +128,7 @@ describe("measureManualOffsetDragScreenToOffsetMatrix", () => {
128
128
  });
129
129
 
130
130
  it("measures movement in parent viewport pixels when the element is inside a scaled iframe", () => {
131
- const window = new Window();
131
+ const window = new Window({ settings: { enableIframePageLoading: true } });
132
132
  const iframe = window.document.createElement("iframe");
133
133
  window.document.body.append(iframe);
134
134
  const iframeWindow = iframe.contentWindow;
@@ -10,12 +10,15 @@ import {
10
10
  isStudioManualEditGestureCurrent,
11
11
  readAppliedStudioPathOffset,
12
12
  restoreStudioPathOffset,
13
+ restoreStudioPathOffsetStyles,
13
14
  type StudioPathOffsetSnapshot,
14
15
  } from "./manualEdits";
15
16
  import type { EditMoment } from "./manualEditsTypes";
16
17
  import { computeDraggedGsapPosition } from "../../hooks/draggedGsapPosition";
17
18
  import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
18
19
  import { readTranslatePx, UNREADABLE_TRANSLATE, writeTranslatePx } from "./plainTranslate";
20
+ import { drawPreviewDraft, endPreviewDraft } from "./previewDrafts";
21
+ import type { PreviewGestureStart } from "./previewGestureStartRead";
19
22
 
20
23
  interface OffsetDragGsap {
21
24
  set: (el: Element, vars: Record<string, number | string>) => void;
@@ -289,7 +292,7 @@ export function measureManualOffsetDragScreenToOffsetMatrix(
289
292
 
290
293
  return { ok: true, matrix: screenToOffset };
291
294
  } finally {
292
- restoreStudioPathOffset(element, snapshot);
295
+ restoreStudioPathOffsetStyles(element, snapshot);
293
296
  }
294
297
  }
295
298
 
@@ -318,9 +321,13 @@ export function createManualOffsetDragMember(input: {
318
321
  rect: ManualOffsetDragRect;
319
322
  gesture?: "drag" | "nudge" | "resize"; // resize: the anchor that keeps its centre planted
320
323
  at?: EditMoment;
324
+ start?: PreviewGestureStart;
321
325
  }): ManualOffsetDragMemberResult {
326
+ const { start, gesture } = input;
322
327
  const plainTranslate =
323
- !!input.gesture && editsPlainCss(input.element, input.gesture === "resize" ? "resize" : "move");
328
+ start && gesture !== "resize"
329
+ ? !start.gsap
330
+ : !!gesture && editsPlainCss(input.element, gesture === "resize" ? "resize" : "move");
324
331
  // The APPLIED offset, never a dormant var, so a stale one can't fling the element off-screen.
325
332
  const initialOffset = plainTranslate
326
333
  ? readTranslatePx(input.element)
@@ -336,7 +343,7 @@ export function createManualOffsetDragMember(input: {
336
343
  // getProperty makes GSAP bake the CSS translate into its transform, so a plain move never reads it.
337
344
  const gsapX = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "x")) || 0;
338
345
  const gsapY = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "y")) || 0;
339
- const baseGsap = { x: gsapX, y: gsapY };
346
+ const baseGsap = start?.gsap ? { x: start.gsap.x, y: start.gsap.y } : { x: gsapX, y: gsapY };
340
347
  if (!plainTranslate) stampGestureBase(input.element, initialOffset, baseGsap);
341
348
 
342
349
  if (win?.__timelines) {
@@ -367,9 +374,10 @@ export function createManualOffsetDragMember(input: {
367
374
  scaleY: input.rect.editScaleY,
368
375
  plainTranslate,
369
376
  });
377
+ endPreviewDraft(input.element, "keep");
370
378
  if (!measured.ok) {
371
- // GSAP transforms can defeat the probe: approximate with the preview scale. The commit
372
- // reads GSAP's real position, so only the drag preview is imprecise.
379
+ // A stand-in has no box: the frame probed its element at the press. GSAP transforms can defeat
380
+ // the probe: approximate with the preview scale; the commit reads GSAP's real position.
373
381
  const scaleX = input.rect.editScaleX || 1;
374
382
  const scaleY = input.rect.editScaleY || 1;
375
383
  const w = readTransformWDivisor(input.element);
@@ -384,7 +392,7 @@ export function createManualOffsetDragMember(input: {
384
392
  baseGsap,
385
393
  initialPathOffset,
386
394
  gestureToken,
387
- screenToOffset: { a: w / scaleX, b: 0, c: 0, d: w / scaleY },
395
+ screenToOffset: start?.screenToOffset ?? { a: w / scaleX, b: 0, c: 0, d: w / scaleY },
388
396
  originRect: input.rect,
389
397
  },
390
398
  };
@@ -426,6 +434,8 @@ function drawMemberOffset(
426
434
  offset: { x: number; y: number },
427
435
  commit: boolean,
428
436
  ): void {
437
+ const { x, y } = member.initialOffset;
438
+ drawPreviewDraft(member.element, { translate: { x: offset.x - x, y: offset.y - y } });
429
439
  if (member.plainTranslate) writeTranslatePx(member.element, offset);
430
440
  else if (applyOffsetDragDraftViaGsap(member.element, offset, member.baseGsap)) return;
431
441
  else if (commit) applyStudioPathOffset(member.element, offset);
@@ -537,6 +547,7 @@ export function endManualOffsetDragMembers(members: ManualOffsetDragMember[]): v
537
547
  for (const member of members) {
538
548
  if (!isStudioManualEditGestureCurrent(member.element, member.gestureToken)) continue;
539
549
  endStudioManualEditGesture(member.element, member.gestureToken);
550
+ endPreviewDraft(member.element, "keep");
540
551
  member.element.removeAttribute("data-hf-drag-initial-offset-x");
541
552
  member.element.removeAttribute("data-hf-drag-initial-offset-y");
542
553
  member.element.removeAttribute("data-hf-drag-gsap-base-x");
@@ -16,6 +16,12 @@ import {
16
16
  } from "../../utils/marqueeGeometry";
17
17
  import { toVisibleOverlayRect } from "./domEditOverlayGeometry";
18
18
  import { movesGesture } from "./domEditOverlayGestures";
19
+ import { previewFrameOpaque } from "../../player/lib/previewChannel";
20
+ import {
21
+ collectPreviewMarqueeCandidates,
22
+ resolvePreviewMarqueeHits,
23
+ type PreviewMarqueeHit,
24
+ } from "./previewLayers";
19
25
 
20
26
  interface MarqueeState {
21
27
  startX: number;
@@ -42,6 +48,7 @@ const MARQUEE_THRESHOLD_PX = 4;
42
48
  interface MarqueeHit {
43
49
  element: HTMLElement;
44
50
  rect: Rect;
51
+ description?: PreviewMarqueeHit["description"];
45
52
  }
46
53
 
47
54
  /**
@@ -118,6 +125,25 @@ async function resolveDomEditSelections(
118
125
  return hits;
119
126
  }
120
127
 
128
+ /** The band's candidates: an opaque frame's are measured over its channel, once per band. */
129
+ function bandCandidates(
130
+ iframe: HTMLIFrameElement,
131
+ overlay: HTMLDivElement,
132
+ acp: string,
133
+ measured: { cached: MarqueeHit[] | null; measuring: Promise<MarqueeHit[]> | null },
134
+ ): MarqueeHit[] | Promise<MarqueeHit[]> {
135
+ if (!previewFrameOpaque(iframe))
136
+ return currentMarqueeCandidates(measured.cached, iframe, overlay, acp);
137
+ return measured.measuring ?? collectPreviewMarqueeCandidates(iframe, overlay);
138
+ }
139
+
140
+ /** Studio's edit selections for the hits; an opaque frame's are read from their descriptions. */
141
+ function resolveMarqueeHits(iframe: HTMLIFrameElement, hits: MarqueeHit[], acp: string) {
142
+ const elements = hits.map((hit) => hit.element);
143
+ if (!previewFrameOpaque(iframe)) return resolveDomEditSelections(elements, acp);
144
+ return resolvePreviewMarqueeHits(iframe, hits as PreviewMarqueeHit[], acp);
145
+ }
146
+
121
147
  export interface MarqueeGesturesDeps<T = DomEditSelection> {
122
148
  iframeRef: React.RefObject<HTMLIFrameElement | null>;
123
149
  overlayRef: React.RefObject<HTMLDivElement | null>;
@@ -176,6 +202,8 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
176
202
  const [candidateRects, setCandidateRects] = useState<Rect[]>([]);
177
203
  // Measured once when the drag passes the threshold and reused until it ends.
178
204
  const candidatesRef = useRef<MarqueeHit[] | null>(null);
205
+ const opaqueCandidatesRef = useRef<Promise<MarqueeHit[]> | null>(null);
206
+ const bandRef = useRef<{ rect: Rect; mode: MarqueeSelectionMode } | null>(null);
179
207
 
180
208
  const commitMarquee = useCallback(
181
209
  async (rect: Rect, mode: MarqueeSelectionMode) => {
@@ -183,12 +211,12 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
183
211
  const overlay = deps.overlayRef.current;
184
212
  if (!iframe || !overlay || !deps.onMarqueeSelectRef.current) return;
185
213
  const acp = deps.activeCompositionPathRef.current ?? "index.html";
186
- const candidates = currentMarqueeCandidates(candidatesRef.current, iframe, overlay, acp);
187
- const elements = hitsWithin(rect, candidates).map((hit) => hit.element);
214
+ const measured = { cached: candidatesRef.current, measuring: opaqueCandidatesRef.current };
215
+ const hits = hitsWithin(rect, await bandCandidates(iframe, overlay, acp, measured));
188
216
  const resolveHits = deps.resolveHits;
189
217
  const picks = resolveHits
190
- ? await resolveHits(elements)
191
- : ((await resolveDomEditSelections(elements, acp)) as T[]);
218
+ ? await resolveHits(hits.map((hit) => hit.element))
219
+ : ((await resolveMarqueeHits(iframe, hits, acp)) as T[]);
192
220
  const applySelection = deps.onMarqueeSelectRef.current;
193
221
  if (!applySelection) return;
194
222
  const result = applySelection(picks, mode);
@@ -208,6 +236,8 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
208
236
  setMarqueeRect(null);
209
237
  setCandidateRects([]);
210
238
  candidatesRef.current = null;
239
+ opaqueCandidatesRef.current = null;
240
+ bandRef.current = null;
211
241
  }, []);
212
242
 
213
243
  const begin = useCallback(
@@ -261,6 +291,18 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
261
291
  const overlay = deps.overlayRef.current;
262
292
  if (!iframe || !overlay) return;
263
293
  const acp = deps.activeCompositionPathRef.current ?? "index.html";
294
+ bandRef.current = { rect, mode };
295
+ if (!candidatesRef.current && previewFrameOpaque(iframe)) {
296
+ if (opaqueCandidatesRef.current) return;
297
+ const measuring = collectPreviewMarqueeCandidates(iframe, overlay);
298
+ opaqueCandidatesRef.current = measuring;
299
+ void measuring.then((hits) => {
300
+ if (opaqueCandidatesRef.current !== measuring || !bandRef.current) return;
301
+ candidatesRef.current = hits;
302
+ showCandidates(bandRef.current.rect, bandRef.current.mode);
303
+ });
304
+ return;
305
+ }
264
306
  candidatesRef.current ??= collectMarqueeCandidates(iframe, overlay, acp);
265
307
  let hits = hitsWithin(rect, candidatesRef.current);
266
308
  if (mode === "subtract") hits = hits.filter((h) => isSelectedElement(h.element));
@@ -284,6 +326,7 @@ export function useMarqueeGestures<T>(deps: MarqueeGesturesDeps<T>): MarqueeGest
284
326
  if (Math.hypot(dx, dy) < MARQUEE_THRESHOLD_PX) return;
285
327
  m.pastThreshold = true;
286
328
  candidatesRef.current = null;
329
+ opaqueCandidatesRef.current = null;
287
330
  }
288
331
  const rect: Rect = {
289
332
  left: Math.min(m.startX, m.currentX),
@@ -70,36 +70,55 @@ function evaluateLength(value: string, side: number): number {
70
70
 
71
71
  const CONTENT_BOXES = new Set(["content-box", "fill-box"]);
72
72
 
73
+ type ComputedRead = (property: string) => string;
74
+
75
+ export const TRANSLATE_PX_PROPERTIES = [
76
+ "translate",
77
+ "width",
78
+ "height",
79
+ "box-sizing",
80
+ "transform-box",
81
+ ...["left", "right", "top", "bottom"].flatMap((s) => [`padding-${s}`, `border-${s}-width`]),
82
+ ];
83
+
73
84
  /** The side % resolves against: the box `transform-box` names (fill-box is the content box on HTML). */
74
- function referenceBox(
75
- cs: CSSStyleDeclaration,
76
- size: "width" | "height",
77
- a: string,
78
- b: string,
79
- ): number {
80
- const n = (prop: string) => Number.parseFloat(cs.getPropertyValue(prop)) || 0;
85
+ function referenceBox(read: ComputedRead, size: "width" | "height", a: string, b: string): number {
86
+ const n = (prop: string) => Number.parseFloat(read(prop)) || 0;
81
87
  const pad =
82
88
  n(`padding-${a}`) + n(`padding-${b}`) + n(`border-${a}-width`) + n(`border-${b}-width`);
83
- const content = n(size) - (cs.boxSizing === "border-box" ? pad : 0);
84
- return CONTENT_BOXES.has(cs.getPropertyValue("transform-box")) ? content : content + pad;
89
+ const content = n(size) - (read("box-sizing") === "border-box" ? pad : 0);
90
+ return CONTENT_BOXES.has(read("transform-box")) ? content : content + pad;
85
91
  }
86
92
 
87
- /** The element's CSS `translate` in px, as it renders now. */
88
- // ponytail: a 3-value translate loses its z on the next move; keep z when a fixture needs it.
89
- export function readTranslatePx(el: HTMLElement): Point {
90
- const cs = el.ownerDocument.defaultView?.getComputedStyle(el);
91
- // Computed first: Chrome resolves em, vw and var() there and leaves only % to work out.
92
- const value = cs?.translate || el.style.getPropertyValue("translate") || "none";
93
+ /** A computed translate in px; with no styles to size the box, a % is NaN rather than 0. */
94
+ export function translatePx(value: string, read?: ComputedRead): Point {
93
95
  if (value === "none") return { x: 0, y: 0 };
94
96
  const [x = "0px", y = "0px"] = splitTopLevelWhitespace(value);
95
97
  const side = (size: "width" | "height", a: string, b: string) =>
96
- cs ? referenceBox(cs, size, a, b) : 0;
98
+ read ? referenceBox(read, size, a, b) : Number.NaN;
97
99
  return {
98
100
  x: evaluateLength(x, side("width", "left", "right")),
99
101
  y: evaluateLength(y, side("height", "top", "bottom")),
100
102
  };
101
103
  }
102
104
 
105
+ const frameTranslates = new WeakMap<Element, { inline: string; px: Point }>();
106
+
107
+ export function rememberFrameTranslate(el: HTMLElement, px: Point): void {
108
+ frameTranslates.set(el, { inline: el.style.getPropertyValue("translate"), px });
109
+ }
110
+
111
+ /** The element's CSS `translate` in px, as it renders now. */
112
+ // ponytail: a 3-value translate loses its z on the next move; keep z when a fixture needs it.
113
+ export function readTranslatePx(el: HTMLElement): Point {
114
+ const cs = el.ownerDocument.defaultView?.getComputedStyle(el);
115
+ const inline = el.style.getPropertyValue("translate");
116
+ const frame = cs ? undefined : frameTranslates.get(el);
117
+ if (frame?.inline === inline) return frame.px;
118
+ // Computed first: Chrome resolves em, vw and var() there and leaves only % to work out.
119
+ return translatePx(cs?.translate || inline || "none", cs && ((p) => cs.getPropertyValue(p)));
120
+ }
121
+
103
122
  export function readTranslatePxLeavingPercent(el: HTMLElement): Point {
104
123
  const value = el.ownerDocument.defaultView?.getComputedStyle(el).translate || "none";
105
124
  const [x = "0px", y = "0px"] = value === "none" ? [] : splitTopLevelWhitespace(value);
@@ -109,6 +128,8 @@ export function readTranslatePxLeavingPercent(el: HTMLElement): Point {
109
128
 
110
129
  export const UNREADABLE_TRANSLATE =
111
130
  "Studio can't read this layer's translate. Move it in the Code tab.";
131
+ export const MOVING_LAYER_UNREADABLE =
132
+ "This preview can't save a move of a layer its animation moves yet. Move it in the Code tab.";
112
133
 
113
134
  /** Plain px only: GSAP's CSSPlugin splits `translate` on spaces and drops a calc(). */
114
135
  function formatTranslatePx(p: Point): string {