@hyperframes/studio 0.9.40 → 0.9.42

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 (93) hide show
  1. package/dist/assets/{codec-BPK_2CLL.js → codec-CKqLGYc6.js} +1 -1
  2. package/dist/assets/{hyperframes-player-D7qTTDIp.js → hyperframes-player-DoEYqOIa.js} +1 -1
  3. package/dist/assets/{index-CdA00Ybn.js → index-DLyQ91Ek.js} +166 -166
  4. package/dist/assets/{index-QS-DuxAU.js → index-s9iqoWnr.js} +1 -1
  5. package/dist/assets/{pausedVideoDecoder-Byzz98Gb.js → pausedVideoDecoder-B-ReRg6i.js} +1 -1
  6. package/dist/{chunk-KF6YVXJP.js → chunk-4QQMX4BX.js} +6 -3
  7. package/dist/{chunk-VZ5MD32A.js → chunk-GVW7AU57.js} +190 -254
  8. package/dist/{chunk-AV2PV7NE.js → chunk-VHV2ZDKY.js} +4 -40
  9. package/dist/{domEditingLayers-4KRREI5C.js → domEditingLayers-SA5KLSSS.js} +4 -2
  10. package/dist/index.d.ts +12 -0
  11. package/dist/index.html +1 -1
  12. package/dist/index.js +1501 -818
  13. package/dist/player.js +2 -2
  14. package/package.json +10 -10
  15. package/src/components/editor/DomEditOverlay.tsx +3 -15
  16. package/src/components/editor/LayersPanel.opaque.test.ts +176 -0
  17. package/src/components/editor/LayersPanel.tsx +41 -10
  18. package/src/components/editor/clickAfterPreventedPress.test.tsx +17 -1
  19. package/src/components/editor/domEditInlineText.ts +1 -16
  20. package/src/components/editor/domEditOverlayBasis.ts +7 -2
  21. package/src/components/editor/domEditOverlayCrop.test.ts +1 -1
  22. package/src/components/editor/domEditOverlayCrop.ts +17 -3
  23. package/src/components/editor/domEditOverlayGeometry.ts +64 -139
  24. package/src/components/editor/domEditSelectionRules.ts +138 -0
  25. package/src/components/editor/domEditing.test.ts +6 -28
  26. package/src/components/editor/domEditingDom.preview.test.ts +3 -3
  27. package/src/components/editor/domEditingDom.ts +3 -76
  28. package/src/components/editor/domEditingElement.ts +19 -240
  29. package/src/components/editor/domEditingGroups.ts +0 -31
  30. package/src/components/editor/domEditingLayers.ts +95 -100
  31. package/src/components/editor/domEditingRootLayer.ts +35 -30
  32. package/src/components/editor/domEditingTypes.ts +10 -0
  33. package/src/components/editor/gestureUndoRevert.ts +18 -1
  34. package/src/components/editor/inlineTextStyleRange.fill.test.ts +129 -0
  35. package/src/components/editor/inlineTextStyleRange.test.ts +0 -82
  36. package/src/components/editor/layerKind.ts +2 -19
  37. package/src/components/editor/layersPanelSort.ts +2 -2
  38. package/src/components/editor/manualEdits.ts +1 -0
  39. package/src/components/editor/manualEditsSnapshot.ts +10 -0
  40. package/src/components/editor/manualOffsetDrag.test.ts +1 -1
  41. package/src/components/editor/manualOffsetDrag.ts +7 -1
  42. package/src/components/editor/marqueeCommit.ts +47 -4
  43. package/src/components/editor/plainTranslate.ts +35 -16
  44. package/src/components/editor/previewDrafts.test.ts +263 -0
  45. package/src/components/editor/previewDrafts.ts +73 -0
  46. package/src/components/editor/previewGestureStarts.ts +73 -10
  47. package/src/components/editor/previewLayers.test.ts +308 -0
  48. package/src/components/editor/previewLayers.ts +164 -0
  49. package/src/components/editor/previewOverlayRects.test.ts +316 -0
  50. package/src/components/editor/previewOverlayRects.ts +150 -0
  51. package/src/components/editor/previewPointerTargets.test.ts +327 -0
  52. package/src/components/editor/previewSelection.test.ts +481 -0
  53. package/src/components/editor/previewSelection.ts +516 -0
  54. package/src/components/editor/probeSourceElement.ts +19 -1
  55. package/src/components/editor/propertyPanelFill.tsx +5 -1
  56. package/src/components/editor/resizeDraft.ts +38 -0
  57. package/src/components/editor/useDomEditOverlayGestures.ts +2 -2
  58. package/src/components/editor/useDomEditOverlayRects.ts +80 -1
  59. package/src/components/editor/useInlineTextEditing.tsx +1 -6
  60. package/src/components/editor/useLayerDrag.ts +1 -1
  61. package/src/components/nle/NLEPreview.slowBoot.test.ts +0 -1
  62. package/src/hooks/domEditDeleteMembers.test.ts +7 -0
  63. package/src/hooks/domSelectionTestHarness.ts +1 -1
  64. package/src/hooks/domSelectionTimelineMirror.ts +3 -1
  65. package/src/hooks/timelineTimingSync.ts +4 -1
  66. package/src/hooks/useDomEditSession.test.tsx +23 -1
  67. package/src/hooks/useDomEditSession.ts +2 -1
  68. package/src/hooks/useDomSelection.ts +63 -47
  69. package/src/hooks/useEditorSave.test.tsx +22 -1
  70. package/src/hooks/useEditorSave.ts +3 -1
  71. package/src/hooks/useGsapSelectionHandlers.test.tsx +17 -0
  72. package/src/hooks/useGsapSelectionHandlers.ts +2 -1
  73. package/src/hooks/usePreviewInteraction.test.ts +10 -2
  74. package/src/hooks/usePreviewInteraction.ts +9 -5
  75. package/src/hooks/useProjectFileWriter.ts +7 -3
  76. package/src/hooks/useStudioSelectionPublisher.test.tsx +50 -0
  77. package/src/hooks/useStudioSelectionPublisher.ts +9 -7
  78. package/src/hooks/useTimelineSelectionPreviewSync.test.tsx +30 -0
  79. package/src/hooks/useTimelineSelectionPreviewSync.ts +7 -2
  80. package/src/player/lib/layerOrdering.ts +2 -11
  81. package/src/player/lib/previewChannel.ts +4 -3
  82. package/src/player/lib/previewElements.ts +143 -3
  83. package/src/styles/hex-baseline.json +1 -2
  84. package/src/test-setup.ts +2 -0
  85. package/src/utils/gsapSoftReload.ts +1 -1
  86. package/src/utils/studioFileHistory.ts +1 -1
  87. package/src/utils/studioHelpers.ts +27 -17
  88. package/src/utils/studioPreviewHelpers.test.ts +8 -8
  89. package/src/utils/studioPreviewHelpers.ts +26 -242
  90. package/src/utils/studioSaveDiagnostics.test.ts +34 -0
  91. package/src/utils/studioSaveDiagnostics.ts +35 -6
  92. package/src/utils/timelineCompositionInsert.ts +3 -1
  93. package/src/components/editor/domEditOverlayTransform.ts +0 -126
@@ -12,32 +12,36 @@ function approximatelyEqual(a: number, b: number) {
12
12
  return Math.abs(a - b) <= COMPOSITION_ROOT_LAYER_EPSILON_PX;
13
13
  }
14
14
 
15
- function getCompositionRootBounds(doc: Document) {
16
- const root =
17
- doc.querySelector<HTMLElement>("[data-composition-id]") ?? doc.documentElement ?? null;
18
- const rootWidth = readPositiveDimension(root?.getAttribute("data-width") ?? null);
19
- const rootHeight = readPositiveDimension(root?.getAttribute("data-height") ?? null);
20
- if (!root || !rootWidth || !rootHeight) return null;
21
- return { rect: root.getBoundingClientRect(), width: rootWidth, height: rootHeight };
15
+ interface Box {
16
+ left: number;
17
+ top: number;
18
+ width: number;
19
+ height: number;
22
20
  }
23
21
 
24
- function getRenderedLayerSize(element: HTMLElement, computedStyles: Record<string, string>) {
25
- const rect = element.getBoundingClientRect();
26
- const width = rect.width || parsePx(computedStyles.width);
27
- const height = rect.height || parsePx(computedStyles.height);
28
- return width && height ? { width, height } : null;
22
+ export interface CompositionRootFacts {
23
+ rect: Box;
24
+ width: string | null;
25
+ height: string | null;
29
26
  }
30
27
 
31
- function matchesCompositionRootBounds(
32
- elementRect: DOMRect,
33
- elementSize: { width: number; height: number },
34
- rootBounds: { rect: DOMRect; width: number; height: number },
35
- ) {
36
- return (
37
- approximatelyEqual(elementRect.left, rootBounds.rect.left) &&
38
- approximatelyEqual(elementRect.top, rootBounds.rect.top) &&
39
- approximatelyEqual(elementSize.width, rootBounds.width) &&
40
- approximatelyEqual(elementSize.height, rootBounds.height)
28
+ export function coversCompositionRoot(
29
+ layer: { rect: Box; computedStyles: Record<string, string> },
30
+ root: CompositionRootFacts | null,
31
+ ): boolean {
32
+ if (isExplicitFullBleedLayer(layer.computedStyles)) return false;
33
+ const rootWidth = readPositiveDimension(root?.width ?? null);
34
+ const rootHeight = readPositiveDimension(root?.height ?? null);
35
+ if (!root || !rootWidth || !rootHeight) return false;
36
+ const width = layer.rect.width || parsePx(layer.computedStyles.width);
37
+ const height = layer.rect.height || parsePx(layer.computedStyles.height);
38
+ return Boolean(
39
+ width &&
40
+ height &&
41
+ approximatelyEqual(layer.rect.left, root.rect.left) &&
42
+ approximatelyEqual(layer.rect.top, root.rect.top) &&
43
+ approximatelyEqual(width, rootWidth) &&
44
+ approximatelyEqual(height, rootHeight),
41
45
  );
42
46
  }
43
47
 
@@ -52,13 +56,14 @@ export function isCompositionRootLayer(
52
56
  ) {
53
57
  if (element.parentElement !== doc.body) return false;
54
58
  if (element.hasAttribute("data-hf-allow-root-edit")) return false;
55
- if (isExplicitFullBleedLayer(computedStyles)) return false;
56
-
57
- const rootBounds = getCompositionRootBounds(doc);
58
- const elementSize = getRenderedLayerSize(element, computedStyles);
59
- return Boolean(
60
- rootBounds &&
61
- elementSize &&
62
- matchesCompositionRootBounds(element.getBoundingClientRect(), elementSize, rootBounds),
59
+ const root =
60
+ doc.querySelector<HTMLElement>("[data-composition-id]") ?? doc.documentElement ?? null;
61
+ return coversCompositionRoot(
62
+ { rect: element.getBoundingClientRect(), computedStyles },
63
+ root && {
64
+ rect: root.getBoundingClientRect(),
65
+ width: root.getAttribute("data-width"),
66
+ height: root.getAttribute("data-height"),
67
+ },
63
68
  );
64
69
  }
@@ -1,5 +1,6 @@
1
1
  import type { PatchTarget } from "../../utils/sourcePatcher";
2
2
  import type { GsapAnimation } from "@hyperframes/parsers/gsap-parser";
3
+ import type { EditingElementHandle, LayerKind } from "@hyperframes/core/runtime/editing-port";
3
4
 
4
5
  export const CURATED_STYLE_PROPERTIES = [
5
6
  "position",
@@ -78,6 +79,9 @@ export interface DomEditTextField {
78
79
 
79
80
  export interface DomEditSelection extends PatchTarget {
80
81
  element: HTMLElement;
82
+ handle?: EditingElementHandle;
83
+ hasAudio?: boolean;
84
+ src?: string | null;
81
85
  label: string;
82
86
  tagName: string;
83
87
  sourceFile: string;
@@ -108,6 +112,12 @@ export interface DomEditLayerItem {
108
112
  selector?: string;
109
113
  selectorIndex?: number;
110
114
  sourceFile: string;
115
+ preview?: {
116
+ handle: string;
117
+ zIndex: number;
118
+ kind: LayerKind;
119
+ dataAttributes: Record<string, string>;
120
+ };
111
121
  }
112
122
 
113
123
  export interface DomEditContextOptions {
@@ -1,8 +1,11 @@
1
1
  import {
2
2
  captureStudioPathOffset,
3
+ readAppliedStudioPathOffset,
3
4
  restoreStudioPathOffset,
4
5
  type StudioPathOffsetSnapshot,
5
6
  } from "./manualEdits";
7
+ import { readTranslatePx } from "./plainTranslate";
8
+ import { drawPreviewDraft } from "./previewDrafts";
6
9
  import {
7
10
  getOffsetDragGsap,
8
11
  stampGestureBase,
@@ -49,6 +52,16 @@ function showMemberPosition(member: ManualOffsetDragMember, position: MemberPosi
49
52
  stampGestureBase(member.element, member.initialOffset, member.baseGsap);
50
53
  }
51
54
 
55
+ function redrawMemberOnFrame(member: ManualOffsetDragMember): void {
56
+ const { element, initialOffset } = member;
57
+ const offset = member.plainTranslate
58
+ ? readTranslatePx(element)
59
+ : readAppliedStudioPathOffset(element);
60
+ const translate = { x: offset.x - initialOffset.x, y: offset.y - initialOffset.y };
61
+ if (Number.isFinite(translate.x) && Number.isFinite(translate.y) && (translate.x || translate.y))
62
+ drawPreviewDraft(element, { translate });
63
+ }
64
+
52
65
  /** Undo's live revert of a move: its members at gesture start. */
53
66
  export function manualOffsetMoveRevert(members: ManualOffsetDragMember[]): StudioEditRevert {
54
67
  const startPlacement = members.map((member) => placementOf(member.element));
@@ -61,7 +74,11 @@ export function manualOffsetMoveRevert(members: ManualOffsetDragMember[]): Studi
61
74
  placement: startPlacement[i]!,
62
75
  }),
63
76
  );
64
- return () => members.forEach((member, i) => showMemberPosition(member, shown[i]!));
77
+ return () =>
78
+ members.forEach((member, i) => {
79
+ showMemberPosition(member, shown[i]!);
80
+ redrawMemberOnFrame(member);
81
+ });
65
82
  };
66
83
  }
67
84
 
@@ -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,14 @@ 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";
19
21
 
20
22
  interface OffsetDragGsap {
21
23
  set: (el: Element, vars: Record<string, number | string>) => void;
@@ -289,7 +291,7 @@ export function measureManualOffsetDragScreenToOffsetMatrix(
289
291
 
290
292
  return { ok: true, matrix: screenToOffset };
291
293
  } finally {
292
- restoreStudioPathOffset(element, snapshot);
294
+ restoreStudioPathOffsetStyles(element, snapshot);
293
295
  }
294
296
  }
295
297
 
@@ -367,6 +369,7 @@ export function createManualOffsetDragMember(input: {
367
369
  scaleY: input.rect.editScaleY,
368
370
  plainTranslate,
369
371
  });
372
+ endPreviewDraft(input.element, "keep");
370
373
  if (!measured.ok) {
371
374
  // GSAP transforms can defeat the probe: approximate with the preview scale. The commit
372
375
  // reads GSAP's real position, so only the drag preview is imprecise.
@@ -426,6 +429,8 @@ function drawMemberOffset(
426
429
  offset: { x: number; y: number },
427
430
  commit: boolean,
428
431
  ): void {
432
+ const { x, y } = member.initialOffset;
433
+ drawPreviewDraft(member.element, { translate: { x: offset.x - x, y: offset.y - y } });
429
434
  if (member.plainTranslate) writeTranslatePx(member.element, offset);
430
435
  else if (applyOffsetDragDraftViaGsap(member.element, offset, member.baseGsap)) return;
431
436
  else if (commit) applyStudioPathOffset(member.element, offset);
@@ -537,6 +542,7 @@ export function endManualOffsetDragMembers(members: ManualOffsetDragMember[]): v
537
542
  for (const member of members) {
538
543
  if (!isStudioManualEditGestureCurrent(member.element, member.gestureToken)) continue;
539
544
  endStudioManualEditGesture(member.element, member.gestureToken);
545
+ endPreviewDraft(member.element, "keep");
540
546
  member.element.removeAttribute("data-hf-drag-initial-offset-x");
541
547
  member.element.removeAttribute("data-hf-drag-initial-offset-y");
542
548
  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),