@hyperframes/studio 0.9.41 → 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 (54) hide show
  1. package/dist/assets/{codec-B_mpbc4w.js → codec-CKqLGYc6.js} +1 -1
  2. package/dist/assets/{hyperframes-player-Dvi3I_mv.js → hyperframes-player-DoEYqOIa.js} +1 -1
  3. package/dist/assets/{index-B5ExwsOp.js → index-DLyQ91Ek.js} +160 -160
  4. package/dist/assets/{index-BrFm9Y5k.js → index-s9iqoWnr.js} +1 -1
  5. package/dist/assets/{pausedVideoDecoder-MHQ57yZ6.js → pausedVideoDecoder-B-ReRg6i.js} +1 -1
  6. package/dist/index.d.ts +9 -1
  7. package/dist/index.html +1 -1
  8. package/dist/index.js +1057 -721
  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/domEditingTypes.ts +7 -1
  14. package/src/components/editor/gestureUndoRevert.ts +18 -1
  15. package/src/components/editor/inlineTextStyleRange.fill.test.ts +129 -0
  16. package/src/components/editor/inlineTextStyleRange.test.ts +0 -82
  17. package/src/components/editor/layerKind.ts +2 -19
  18. package/src/components/editor/layersPanelSort.ts +2 -2
  19. package/src/components/editor/manualEdits.ts +1 -0
  20. package/src/components/editor/manualEditsSnapshot.ts +10 -0
  21. package/src/components/editor/manualOffsetDrag.test.ts +1 -1
  22. package/src/components/editor/manualOffsetDrag.ts +7 -1
  23. package/src/components/editor/marqueeCommit.ts +47 -4
  24. package/src/components/editor/plainTranslate.ts +35 -16
  25. package/src/components/editor/previewDrafts.test.ts +263 -0
  26. package/src/components/editor/previewDrafts.ts +73 -0
  27. package/src/components/editor/previewLayers.test.ts +308 -0
  28. package/src/components/editor/previewLayers.ts +164 -0
  29. package/src/components/editor/previewOverlayRects.ts +27 -0
  30. package/src/components/editor/previewPointerTargets.test.ts +68 -1
  31. package/src/components/editor/previewSelection.ts +55 -11
  32. package/src/components/editor/resizeDraft.ts +38 -0
  33. package/src/components/editor/useDomEditOverlayGestures.ts +2 -2
  34. package/src/components/editor/useLayerDrag.ts +1 -1
  35. package/src/components/nle/NLEPreview.slowBoot.test.ts +0 -1
  36. package/src/hooks/domEditDeleteMembers.test.ts +7 -0
  37. package/src/hooks/domSelectionTimelineMirror.ts +3 -1
  38. package/src/hooks/timelineTimingSync.ts +4 -1
  39. package/src/hooks/useDomSelection.ts +2 -0
  40. package/src/hooks/useEditorSave.test.tsx +22 -1
  41. package/src/hooks/useEditorSave.ts +3 -1
  42. package/src/hooks/usePreviewInteraction.ts +4 -1
  43. package/src/hooks/useProjectFileWriter.ts +7 -3
  44. package/src/hooks/useTimelineSelectionPreviewSync.test.tsx +30 -0
  45. package/src/hooks/useTimelineSelectionPreviewSync.ts +7 -2
  46. package/src/player/lib/layerOrdering.ts +2 -11
  47. package/src/player/lib/previewElements.ts +31 -0
  48. package/src/test-setup.ts +2 -0
  49. package/src/utils/gsapSoftReload.ts +1 -1
  50. package/src/utils/studioFileHistory.ts +1 -1
  51. package/src/utils/studioHelpers.ts +27 -4
  52. package/src/utils/studioSaveDiagnostics.test.ts +34 -0
  53. package/src/utils/studioSaveDiagnostics.ts +35 -6
  54. package/src/utils/timelineCompositionInsert.ts +3 -1
@@ -3,10 +3,11 @@
3
3
  * descriptions. Which element a selection lands on comes from `domEditSelectionRules.ts`, the
4
4
  * rules a scriptable frame's selections use, so both kinds of frame select the same element.
5
5
  *
6
- * Such a selection's `element` is a stand-in: an element with only the target's tag, in a
7
- * document with no window, the same one for a handle for the whole frame load. Nothing in it
8
- * loads, runs or renders, and nothing from the frame is copied into it. The frame's element is
9
- * the selection's `handle`.
6
+ * Such a selection's `element` is a stand-in: an element with the target's tag, in a document
7
+ * with no window, the same one for a handle for the whole frame load. Nothing in it loads, runs or
8
+ * renders; from the frame it takes only the inline translate, box and Studio marks a gesture starts
9
+ * from, and the px the frame renders that translate as. The frame's element is the selection's
10
+ * `handle`.
10
11
  */
11
12
  import { resolveEditingAffordances } from "@hyperframes/core/editing";
12
13
  import {
@@ -60,6 +61,17 @@ import {
60
61
  getPreviewTargetFromPointer,
61
62
  } from "../../utils/studioPreviewHelpers";
62
63
  import { isVideoAudible } from "../../player/lib/timelineElementHelpers";
64
+ import { registerPreviewStandIn } from "./previewDrafts";
65
+ import {
66
+ STUDIO_HEIGHT_PROP,
67
+ STUDIO_OFFSET_X_PROP,
68
+ STUDIO_OFFSET_Y_PROP,
69
+ STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR,
70
+ STUDIO_ORIGINAL_TRANSLATE_ATTR,
71
+ STUDIO_PATH_OFFSET_ATTR,
72
+ STUDIO_WIDTH_PROP,
73
+ } from "./manualEditsTypes";
74
+ import { rememberFrameTranslate, TRANSLATE_PX_PROPERTIES, translatePx } from "./plainTranslate";
63
75
 
64
76
  let inertDocument: Document | undefined;
65
77
  const inert = () => (inertDocument ??= document.implementation.createHTMLDocument(""));
@@ -72,19 +84,40 @@ function inertElement(tag: string): HTMLElement {
72
84
  }
73
85
  }
74
86
 
87
+ const GESTURE_START_STYLES = [
88
+ "translate",
89
+ STUDIO_OFFSET_X_PROP,
90
+ STUDIO_OFFSET_Y_PROP,
91
+ STUDIO_WIDTH_PROP,
92
+ STUDIO_HEIGHT_PROP,
93
+ ];
94
+ const GESTURE_START_ATTRS = [
95
+ STUDIO_PATH_OFFSET_ATTR,
96
+ STUDIO_ORIGINAL_TRANSLATE_ATTR,
97
+ STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR,
98
+ ];
75
99
  const standIns = new WeakMap<EditingPortClient, Map<string, HTMLElement>>();
76
100
  const standInHandles = new WeakMap<Element, string>();
77
101
  const standInAncestors = new WeakMap<Element, string[]>();
78
102
 
79
- function standInFor(iframe: HTMLIFrameElement, element: PreviewElement): HTMLElement {
103
+ export function standInFor(iframe: HTMLIFrameElement, element: PreviewElement): HTMLElement {
80
104
  const client = previewEditingClient(iframe);
81
105
  const byHandle = standIns.get(client) ?? new Map<string, HTMLElement>();
82
106
  standIns.set(client, byHandle);
83
107
  let standIn = byHandle.get(element.handle);
84
108
  if (!standIn) {
85
109
  standIn = inertElement(element.tag);
110
+ for (const name of GESTURE_START_STYLES) {
111
+ const value = element.inlineStyles[name];
112
+ if (value && !mayBeCut(value)) standIn.style.setProperty(name, value);
113
+ }
114
+ for (const name of GESTURE_START_ATTRS) {
115
+ const value = attr(element, name);
116
+ if (value !== null && !mayBeCut(value)) standIn.setAttribute(name, value);
117
+ }
86
118
  byHandle.set(element.handle, standIn);
87
119
  standInHandles.set(standIn, element.handle);
120
+ registerPreviewStandIn(standIn, iframe, element.handle);
88
121
  }
89
122
  return standIn;
90
123
  }
@@ -93,7 +126,7 @@ function standInFor(iframe: HTMLIFrameElement, element: PreviewElement): HTMLEle
93
126
  * The description as an element of the inert document, discarded after the read, so the label,
94
127
  * data-attribute and inline-style helpers read it as they read a live element.
95
128
  */
96
- function readable(element: PreviewElement): HTMLElement {
129
+ export function readable(element: PreviewElement): HTMLElement {
97
130
  const probe = inertElement(element.tag);
98
131
  for (const [name, value] of element.attributes) {
99
132
  if (name !== "id" && name !== "class" && !name.startsWith("data-")) continue;
@@ -262,7 +295,7 @@ function chainIndex(
262
295
  });
263
296
  }
264
297
 
265
- function previewIdentity(current: PreviewElement, path: string | null) {
298
+ export function previewIdentity(current: PreviewElement, path: string | null) {
266
299
  const selector = current.selector ?? undefined;
267
300
  return {
268
301
  id: current.id || undefined,
@@ -316,10 +349,18 @@ export async function resolvePreviewSelection(
316
349
  const compositionSrc = compositionSourceOf(current);
317
350
  const probe = readable(current);
318
351
  const inlineStyles = getInlineStyles(probe);
319
- const computedStyles = await previewComputedStyles(iframe, current, [
320
- ...CURATED_STYLE_PROPERTIES,
352
+ const styles = await previewComputedStyles(iframe, current, [
353
+ ...new Set([...CURATED_STYLE_PROPERTIES, ...TRANSLATE_PX_PROPERTIES]),
321
354
  ]);
322
- if (!computedStyles) return null;
355
+ if (!styles) return null;
356
+ // The stand-in has no box to size a % or em against: a move starts from what the frame renders.
357
+ rememberFrameTranslate(
358
+ element,
359
+ translatePx(styles.translate ?? "none", (p) => styles[p] ?? ""),
360
+ );
361
+ const computedStyles = Object.fromEntries(
362
+ CURATED_STYLE_PROPERTIES.flatMap((p) => (p in styles ? [[p, styles[p]!]] : [])),
363
+ );
323
364
  const isCompositionRoot = await isPreviewCompositionRoot(iframe, chain, index, computedStyles);
324
365
  if (isCompositionRoot === null) return null;
325
366
  const isInsideLocked = chainLocked(chain, chainReader(chain), index);
@@ -414,6 +455,8 @@ export async function findOpaqueTimelineElement(
414
455
  return (await findPreviewElementForTimelineElement(iframe, element, lookup)) ?? null;
415
456
  }
416
457
 
458
+ export const standInHandle = (element: Element) => standInHandles.get(element);
459
+
417
460
  export function elementWithin(container: HTMLElement, element: HTMLElement): boolean {
418
461
  const handle = standInHandles.get(container);
419
462
  if (handle === undefined) return container.contains(element);
@@ -440,7 +483,8 @@ export function pointerMayHitElement(iframe: HTMLIFrameElement, clientX: number,
440
483
  if (!previewFrameOpaque(iframe))
441
484
  return Boolean(getPreviewTargetFromPointer(iframe, clientX, clientY));
442
485
  const answer = pointerAnswers.get(iframe);
443
- return answer?.x === clientX && answer.y === clientY ? answer.found : true;
486
+ const near = answer && Math.hypot(answer.x - clientX, answer.y - clientY) <= 2;
487
+ return near ? answer.found : true;
444
488
  }
445
489
 
446
490
  export async function findPointerTarget(
@@ -9,6 +9,9 @@ import {
9
9
  import { computeNextResizeAnchor, resizeRemainderShift } from "./domEditResizeLocal";
10
10
  import type { ResizeDraftSizes } from "./domEditResizeLocal";
11
11
  import { applyManualOffsetDragDraft } from "./manualOffsetDrag";
12
+ import { endStudioManualEditGesture, isStudioManualEditGestureCurrent } from "./manualEdits";
13
+ import { drawPreviewDraft, endPreviewDraft } from "./previewDrafts";
14
+ import { previewFrameOpaque } from "../../player/lib/previewChannel";
12
15
 
13
16
  type Corners = ReturnType<typeof elementCornerOverlayPoints>;
14
17
 
@@ -80,6 +83,40 @@ function resolveAnchoredResizeDraft(
80
83
  );
81
84
  }
82
85
 
86
+ /** A frame Studio cannot measure: the box grows about its centre by the size the draft wrote. */
87
+ function resolveUnmeasuredResizeDraft(
88
+ g: GestureState,
89
+ element: HTMLElement,
90
+ { written }: ResizeDraftSizes,
91
+ ): OverlayRect {
92
+ const width = (g.originWidth * written.width) / g.actualWidth;
93
+ const height = (g.originHeight * written.height) / g.actualHeight;
94
+ if (g.pathOffsetMember) {
95
+ const anchor = {
96
+ dx: ((g.actualWidth - written.width) / 2) * g.editScaleX,
97
+ dy: ((g.actualHeight - written.height) / 2) * g.editScaleY,
98
+ };
99
+ g.lastResizeAnchor = anchor;
100
+ applyManualOffsetDragDraft(g.pathOffsetMember, anchor.dx, anchor.dy);
101
+ }
102
+ drawPreviewDraft(element, { size: written });
103
+ return {
104
+ left: g.originLeft + (g.originWidth - width) / 2,
105
+ top: g.originTop + (g.originHeight - height) / 2,
106
+ width,
107
+ height,
108
+ editScaleX: g.editScaleX,
109
+ editScaleY: g.editScaleY,
110
+ angle: g.actualRotation,
111
+ };
112
+ }
113
+
114
+ /** Ends a settled resize that has no offset member; a frame it drew on keeps the new size. */
115
+ export function endResizeWithoutMember(element: HTMLElement, token: string | undefined): void {
116
+ if (!token || isStudioManualEditGestureCurrent(element, token)) endPreviewDraft(element, "keep");
117
+ endStudioManualEditGesture(element, token);
118
+ }
119
+
83
120
  /** The overlay rect to paint for the current resize pointer-move frame. */
84
121
  export function resolveResizeDraftRect(
85
122
  g: GestureState,
@@ -89,6 +126,7 @@ export function resolveResizeDraftRect(
89
126
  measureOrientedRect: () => OverlayRect | null,
90
127
  sizes: ResizeDraftSizes,
91
128
  ): OverlayRect {
129
+ if (iframe && previewFrameOpaque(iframe)) return resolveUnmeasuredResizeDraft(g, element, sizes);
92
130
  if (g.pathOffsetMember) {
93
131
  return resolveAnchoredResizeDraft(
94
132
  g,
@@ -45,7 +45,7 @@ import {
45
45
  resolveDomEditRotationGesture,
46
46
  } from "./domEditOverlayGestures";
47
47
  import { resolveCenterResizeSize } from "./domEditResizeLocal";
48
- import { resolveResizeDraftRect } from "./resizeDraft";
48
+ import { endResizeWithoutMember, resolveResizeDraftRect } from "./resizeDraft";
49
49
  import { notifyBlockedPress } from "./domEditOverlayStartGesture";
50
50
  import { hugRectForElement } from "./domEditOverlayCrop";
51
51
  import {
@@ -530,7 +530,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
530
530
  })
531
531
  .finally(() => {
532
532
  if (member) endManualOffsetDragMembers([member]);
533
- else endStudioManualEditGesture(sel.element, g.manualEditDragToken);
533
+ else endResizeWithoutMember(sel.element, g.manualEditDragToken);
534
534
  });
535
535
  edit.settle(saved);
536
536
  logResizeSettle(sel.element, "post-release");
@@ -36,7 +36,7 @@ export interface UseLayerDragReturn {
36
36
  }
37
37
 
38
38
  export function isLayerDraggable(layer: DomEditLayerItem): boolean {
39
- if (!(layer.selector || layer.id)) return false;
39
+ if (!(layer.selector || layer.id) || layer.preview) return false;
40
40
  let el: HTMLElement | null = layer.element;
41
41
  while (el) {
42
42
  if (el.hasAttribute("data-timeline-locked")) return false;
@@ -1,5 +1,4 @@
1
1
  // @vitest-environment happy-dom
2
- // @vitest-environment-options {"happyDOM":{"settings":{"disableIframePageLoading":true}}}
3
2
 
4
3
  import React, { act, createRef } from "react";
5
4
  import { createRoot } from "react-dom/client";
@@ -27,4 +27,11 @@ describe("timelineElementsForDelete", () => {
27
27
  const elements = [clip("a", "clip-a")];
28
28
  expect(timelineElementsForDelete([sel("nested-text")], elements)).toBeNull();
29
29
  });
30
+
31
+ it("leaves an opaque frame's selection on the DOM path, as its clip-id row has no patch target", () => {
32
+ // An opaque frame's rows carry only the clip id; the selection carries the frame's handle.
33
+ const row = { id: "title", sourceFile: "index.html", start: 0, duration: 1, track: 0 };
34
+ const opaque = { ...sel("title"), handle: "0123456789abcdef:1" } as DomEditSelection;
35
+ expect(timelineElementsForDelete([opaque], [row as TimelineElement])).toBeNull();
36
+ });
30
37
  });
@@ -6,6 +6,7 @@ import { logSelect } from "../utils/selectDebug";
6
6
 
7
7
  interface TimelineMirrorDeps {
8
8
  timelineElements: TimelineElement[];
9
+ activeCompPath: string | null;
9
10
  getTimelineSelectionSet: () => ReadonlySet<string>;
10
11
  setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void;
11
12
  setTimelineSelectionSet: (ids: Set<string>) => void;
@@ -32,6 +33,7 @@ export function announceTimelineSelection(
32
33
  ): void {
33
34
  const {
34
35
  timelineElements,
36
+ activeCompPath,
35
37
  getTimelineSelectionSet,
36
38
  setSelectedTimelineElementId,
37
39
  setTimelineSelectionSet,
@@ -42,7 +44,7 @@ export function announceTimelineSelection(
42
44
  return;
43
45
  }
44
46
  const timelineIdFor = (selection: DomEditSelection) =>
45
- findMatchingTimelineElementId(selection, timelineElements) ??
47
+ findMatchingTimelineElementId(selection, timelineElements, activeCompPath || "index.html") ??
46
48
  findTimelineIdByAncestor(
47
49
  selection.element,
48
50
  timelineElements,
@@ -30,6 +30,7 @@ import {
30
30
  type StudioProjectFileWriter,
31
31
  } from "../utils/studioFileMutationCoordinator";
32
32
  import { studioApiFetch } from "../utils/studioApiFetch";
33
+ import { createStudioSaveHttpError } from "../utils/studioSaveDiagnostics";
33
34
  import { moveLiveTweens } from "../utils/gsapLiveRetime";
34
35
 
35
36
  export async function readFileContent(projectId: string, targetPath: string): Promise<string> {
@@ -40,7 +41,9 @@ export async function readFileContent(projectId: string, targetPath: string): Pr
40
41
  `/api/projects/${encodeURIComponent(projectId)}/files/${encodeURIComponent(targetPath)}`,
41
42
  );
42
43
  if (!response.ok) {
43
- throw new Error(`Failed to read ${targetPath}`);
44
+ throw await createStudioSaveHttpError(response, `Failed to read ${targetPath}`, {
45
+ path: targetPath,
46
+ });
44
47
  }
45
48
  const data = (await response.json()) as { content?: string };
46
49
  if (typeof data.content !== "string") {
@@ -104,6 +104,7 @@ export function useDomSelection({
104
104
  announceSelectionToTimeline(
105
105
  {
106
106
  timelineElements,
107
+ activeCompPath,
107
108
  getTimelineSelectionSet,
108
109
  setSelectedTimelineElementId,
109
110
  setTimelineSelectionSet,
@@ -113,6 +114,7 @@ export function useDomSelection({
113
114
  replaceSet,
114
115
  ),
115
116
  [
117
+ activeCompPath,
116
118
  getTimelineSelectionSet,
117
119
  setSelectedTimelineElementId,
118
120
  setTimelineSelectionSet,
@@ -9,7 +9,7 @@ vi.mock("../utils/studioSaveDiagnostics", async (importOriginal) => ({
9
9
  trackStudioSaveFailure,
10
10
  }));
11
11
 
12
- import { StudioFileConflictError } from "../utils/studioSaveDiagnostics";
12
+ import { StudioFileConflictError, createStudioSaveHttpError } from "../utils/studioSaveDiagnostics";
13
13
  import { useEditorSave, type EditorSaveHandle } from "./useEditorSave";
14
14
 
15
15
  (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -150,6 +150,27 @@ describe("useEditorSave pending work", () => {
150
150
  await mounted.unmount();
151
151
  });
152
152
 
153
+ // fails without the fix: the toast told the person to check the preview server for a file another program holds open.
154
+ it("toasts a held file in its own words, not the generic preview-server advice", async () => {
155
+ const held = await createStudioSaveHttpError(
156
+ new Response(JSON.stringify({ why: "busy" }), { status: 423 }),
157
+ "Failed to save index.html",
158
+ { path: "index.html" },
159
+ );
160
+ const mounted = await mountEditorSave(async () => {
161
+ throw held;
162
+ });
163
+
164
+ act(() => mounted.handle.handleContentChange("edit"));
165
+ await mounted.handle.flushPendingSave();
166
+
167
+ expect(mounted.showToast).toHaveBeenCalledWith(
168
+ "index.html is open in another program. Close it there, then try again.",
169
+ "error",
170
+ );
171
+ await mounted.unmount();
172
+ });
173
+
153
174
  it("emits a changed failure immediately and repeats after the burst window", async () => {
154
175
  const now = vi.spyOn(Date, "now").mockReturnValue(1_000);
155
176
  const writeProjectFile = vi
@@ -3,6 +3,7 @@ import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
3
3
  import {
4
4
  StudioFileConflictError,
5
5
  buildStudioSaveFailureProperties,
6
+ heldFileWords,
6
7
  trackStudioSaveFailure,
7
8
  type StudioSaveDrainResult,
8
9
  } from "../utils/studioSaveDiagnostics";
@@ -93,7 +94,8 @@ export function useEditorSave({
93
94
  ) {
94
95
  lastFailureToastAtRef.current = now;
95
96
  showToast(
96
- `Couldn't save ${path}. Your latest edits are NOT persisted. Check the preview server; editing again retries the save.`,
97
+ heldFileWords(error) ??
98
+ `Couldn't save ${path}. Your latest edits are NOT persisted. Check the preview server; editing again retries the save.`,
97
99
  "error",
98
100
  );
99
101
  }
@@ -74,6 +74,7 @@ export function usePreviewInteraction({
74
74
  }: UsePreviewInteractionParams) {
75
75
  const cycleRef = useRef<ClickCycleState | null>(null);
76
76
  const lastDownRef = useRef<{ t: number; x: number; y: number } | null>(null);
77
+ const hoverSeqRef = useRef(0);
77
78
 
78
79
  const pausePreviewPlayback = useCallback(() => {
79
80
  const pausedTime = pauseStudioPreviewPlayback(previewIframeRef.current);
@@ -238,6 +239,7 @@ export function usePreviewInteraction({
238
239
  const handlePreviewCanvasPointerMove = useCallback(
239
240
  // fallow-ignore-next-line complexity
240
241
  async (e: React.PointerEvent<HTMLDivElement>, options?: { preferClipAncestor?: boolean }) => {
242
+ const seq = ++hoverSeqRef.current;
241
243
  if (captionEditMode || compositionLoading) {
242
244
  updateDomEditHoverSelection(null);
243
245
  return null;
@@ -247,7 +249,7 @@ export function usePreviewInteraction({
247
249
  preferClipAncestor: options?.preferClipAncestor ?? false,
248
250
  skipSourceProbe: true,
249
251
  });
250
- updateDomEditHoverSelection(nextSelection);
252
+ if (seq === hoverSeqRef.current) updateDomEditHoverSelection(nextSelection);
251
253
  return nextSelection;
252
254
  },
253
255
  [
@@ -259,6 +261,7 @@ export function usePreviewInteraction({
259
261
  );
260
262
 
261
263
  const handlePreviewCanvasPointerLeave = useCallback(() => {
264
+ hoverSeqRef.current += 1;
262
265
  updateDomEditHoverSelection(null);
263
266
  }, [updateDomEditHoverSelection]);
264
267
 
@@ -17,7 +17,8 @@ async function fetchProjectFile(projectId: string | null, path: string, query: s
17
17
  const response = await studioApiFetch(
18
18
  `/api/projects/${encodeURIComponent(projectId)}/files/${encodeURIComponent(path)}${query}`,
19
19
  );
20
- if (!response.ok) throw new Error(`Failed to read ${path}`);
20
+ if (!response.ok)
21
+ throw await createStudioSaveHttpError(response, `Failed to read ${path}`, { path });
21
22
  const data = (await response.json()) as { content?: string; version?: string };
22
23
  return { content: data.content, version: data.version ?? response.headers.get("etag") };
23
24
  }
@@ -78,7 +79,9 @@ export function useProjectFileWriter({ projectId }: UseProjectFileWriterOptions)
78
79
  } else if (preflight.status === 404) {
79
80
  expectedVersion = null;
80
81
  } else {
81
- throw await createStudioSaveHttpError(preflight, `Failed to read ${path} before save`);
82
+ throw await createStudioSaveHttpError(preflight, `Failed to read ${path} before save`, {
83
+ path,
84
+ });
82
85
  }
83
86
  }
84
87
  // fallow-ignore-next-line complexity
@@ -121,7 +124,8 @@ export function useProjectFileWriter({ projectId }: UseProjectFileWriterOptions)
121
124
  attemptedContent: content,
122
125
  });
123
126
  }
124
- if (!response.ok) throw await createStudioSaveHttpError(response, `Failed to save ${path}`);
127
+ if (!response.ok)
128
+ throw await createStudioSaveHttpError(response, `Failed to save ${path}`, { path });
125
129
  const result = (await response.json()) as { version?: string };
126
130
  const version = result.version ?? response.headers.get("etag");
127
131
  if (!version)
@@ -80,6 +80,36 @@ function makeSyncFixture() {
80
80
  }
81
81
 
82
82
  describe("useTimelineSelectionPreviewSync", () => {
83
+ it("keeps an opaque frame's selection that matches a clip known only by its id", async () => {
84
+ // An opaque frame's rows carry only the clip id; its selections carry the frame's handle.
85
+ const timelineElements = [
86
+ { id: "clip-1", tag: "div", start: 0, duration: 1, track: 0 },
87
+ ] as TimelineElement[];
88
+ const element = document.createElement("div");
89
+ element.id = "clip-1";
90
+ const selection = { ...makeSelection("First", element), handle: "0123456789abcdef:1" };
91
+ const applyDomSelection = vi.fn();
92
+ const applyMarqueeSelection = vi.fn();
93
+ const buildDomSelectionForTimelineElement = vi.fn(async () => null);
94
+ const harness = renderHarness();
95
+
96
+ await harness.rerender({
97
+ selectedElementId: "clip-1",
98
+ selectedElementIds: new Set(["clip-1"]),
99
+ timelineElements,
100
+ domEditSelection: selection,
101
+ domEditGroupSelections: [selection],
102
+ buildDomSelectionForTimelineElement,
103
+ applyDomSelection,
104
+ applyMarqueeSelection,
105
+ onSelectionNotFound: vi.fn(),
106
+ });
107
+
108
+ expect(buildDomSelectionForTimelineElement).not.toHaveBeenCalled();
109
+ expect(applyDomSelection).not.toHaveBeenCalled();
110
+ harness.cleanup();
111
+ });
112
+
83
113
  it("syncs a multi-id timeline selection into preview group selections", async () => {
84
114
  const { firstSelection, secondSelection, timelineElements, selectionById } = makeSyncFixture();
85
115
  const applyDomSelection = vi.fn();
@@ -139,11 +139,16 @@ export function useTimelineSelectionPreviewSync({
139
139
  : [];
140
140
  const currentIds = currentSelections
141
141
  .map((selection) =>
142
- resolveTimelineIdForSelection(selection, timelineElements, activeCompPath),
142
+ resolveTimelineIdForSelection(selection, timelineElements, activeCompPath, true),
143
143
  )
144
144
  .filter((id): id is string => Boolean(id));
145
145
  const currentAnchor = currentDomEditSelection
146
- ? resolveTimelineIdForSelection(currentDomEditSelection, timelineElements, activeCompPath)
146
+ ? resolveTimelineIdForSelection(
147
+ currentDomEditSelection,
148
+ timelineElements,
149
+ activeCompPath,
150
+ true,
151
+ )
147
152
  : null;
148
153
 
149
154
  if (selectedIds.length === 0) {
@@ -1,3 +1,4 @@
1
+ import { elementZIndex } from "@hyperframes/core/runtime/editing-port";
1
2
  import { readLayerRevealPriorZ } from "./timelineElementHelpers";
2
3
 
3
4
  export interface StackingContextDescriptor {
@@ -16,17 +17,7 @@ export function getElementZIndex(element: HTMLElement): number {
16
17
  // An active Layers-panel reveal lift reports the element's TRUE z.
17
18
  const prior = readLayerRevealPriorZ(element);
18
19
  if (prior != null) return prior;
19
- const inline = element.style?.zIndex;
20
- if (inline && inline !== "auto") {
21
- const parsed = parseInt(inline, 10);
22
- if (Number.isFinite(parsed)) return parsed;
23
- }
24
- const win = element.ownerDocument?.defaultView;
25
- if (!win) return 0;
26
- const value = win.getComputedStyle(element).zIndex;
27
- if (value === "auto" || value === "") return 0;
28
- const parsed = parseInt(value, 10);
29
- return Number.isFinite(parsed) ? parsed : 0;
20
+ return elementZIndex(element);
30
21
  } catch {
31
22
  return 0;
32
23
  }
@@ -14,6 +14,7 @@ import {
14
14
  type EditingElementHit,
15
15
  type EditingElementMatch,
16
16
  type EditingElementSource,
17
+ type EditingLayer,
17
18
  } from "@hyperframes/core/runtime/editing-port";
18
19
  import { resolveElementSourceFile } from "../../components/editor/domEditingDom";
19
20
  import { previewRequest } from "./previewChannel";
@@ -224,3 +225,33 @@ export async function previewGeometry(
224
225
  children: children && childrenOk ? (boxes as EditingElementBox[]) : null,
225
226
  };
226
227
  }
228
+
229
+ const LAYER_KINDS = new Set(["image", "video", "audio", "vector", "group", "text", "shape"]);
230
+ const isLayer = (value: unknown): value is EditingLayer =>
231
+ isFields(value) &&
232
+ isHandle(value.handle) &&
233
+ isCount(value.depth) &&
234
+ isCount(value.childCount) &&
235
+ Number.isFinite(value.zIndex) &&
236
+ LAYER_KINDS.has(value.kind as string);
237
+
238
+ export interface PreviewLayers {
239
+ layers: EditingLayer[];
240
+ truncated: boolean;
241
+ missingGroup: boolean;
242
+ }
243
+
244
+ /** One page of the frame's layers in document order from `offset`, scoped to `group` when given; null when the runtime cannot answer. */
245
+ export async function previewLayers(
246
+ iframe: HTMLIFrameElement,
247
+ group?: string,
248
+ offset = 0,
249
+ ): Promise<PreviewLayers | null> {
250
+ const params = { ...(group ? { group } : {}), ...(offset ? { offset } : {}) };
251
+ const reply = await previewRequest(iframe, "layers", params);
252
+ const layers: unknown = reply?.layers;
253
+ const { truncated, missingGroup } = reply ?? {};
254
+ if (!Array.isArray(layers) || typeof truncated !== "boolean") return null;
255
+ if (typeof missingGroup !== "boolean") return null;
256
+ return layers.every(isLayer) ? { layers, truncated, missingGroup } : null;
257
+ }
package/src/test-setup.ts CHANGED
@@ -12,3 +12,5 @@ if (typeof CSS.escape !== "function") {
12
12
  if (typeof globalThis.confirm !== "function") {
13
13
  (globalThis as Record<string, unknown>).confirm = () => false;
14
14
  }
15
+
16
+ (globalThis as Record<string, unknown>).BASE_UI_ANIMATIONS_DISABLED = true;
@@ -286,8 +286,8 @@ export function applySoftReloadFinalization(
286
286
  currentTime: number,
287
287
  ): boolean {
288
288
  const win = iframe?.contentWindow as IframeWindow | null;
289
- if (!win?.__hfForceTimelineRebind) return false;
290
289
  try {
290
+ if (!win?.__hfForceTimelineRebind) return false;
291
291
  if (win.__hfSuppressSceneMutations) {
292
292
  win.__hfSuppressSceneMutations(() => finalizeSoftReload(win, currentTime));
293
293
  } else {
@@ -75,7 +75,7 @@ export async function readProjectFileContent(pid: string, path: string): Promise
75
75
  buildProjectApiPath(pid, `/files/${encodeURIComponent(path)}`),
76
76
  );
77
77
  if (!response.ok) {
78
- throw await createStudioSaveHttpError(response, `Failed to read ${path}`);
78
+ throw await createStudioSaveHttpError(response, `Failed to read ${path}`, { path });
79
79
  }
80
80
  const data = (await response.json()) as { content?: string };
81
81
  if (typeof data.content !== "string") {
@@ -133,14 +133,30 @@ export type ElementMatchSelection = Pick<
133
133
  | "sourceFile"
134
134
  | "compositionSrc"
135
135
  | "isCompositionHost"
136
- >;
136
+ > &
137
+ Partial<Pick<DomEditSelection, "handle">>;
138
+
139
+ function matchesByClipId(
140
+ selection: ElementMatchSelection,
141
+ element: TimelineElement,
142
+ file: string,
143
+ value: string | undefined,
144
+ clipIdScope: string | undefined,
145
+ ) {
146
+ if (!clipIdScope || !selection.handle) return false;
147
+ if (element.domId || element.hfId || element.selector) return false;
148
+ return element.id === value && (element.sourceFile || clipIdScope) === file;
149
+ }
137
150
 
138
151
  function matchesByDomId(
139
152
  selection: ElementMatchSelection,
140
153
  element: TimelineElement,
141
154
  selectionSourceFile: string,
155
+ clipIdScope?: string,
142
156
  ): boolean {
143
157
  if (!selection.id) return false;
158
+ if (matchesByClipId(selection, element, selectionSourceFile, selection.id, clipIdScope))
159
+ return true;
144
160
  return (
145
161
  element.domId === selection.id && (element.sourceFile || "index.html") === selectionSourceFile
146
162
  );
@@ -150,8 +166,11 @@ function matchesByHfId(
150
166
  selection: ElementMatchSelection,
151
167
  element: TimelineElement,
152
168
  selectionSourceFile: string,
169
+ clipIdScope?: string,
153
170
  ): boolean {
154
171
  if (!selection.hfId) return false;
172
+ if (matchesByClipId(selection, element, selectionSourceFile, selection.hfId, clipIdScope))
173
+ return true;
155
174
  return (
156
175
  element.hfId === selection.hfId && (element.sourceFile || "index.html") === selectionSourceFile
157
176
  );
@@ -174,9 +193,11 @@ function matchesBySelector(selection: ElementMatchSelection, element: TimelineEl
174
193
  );
175
194
  }
176
195
 
196
+ /** `clipIdScope` matches opaque picks to clip-id-only rows, which have no patch target: select/seek only. */
177
197
  export function findMatchingTimelineElementId(
178
198
  selection: ElementMatchSelection,
179
199
  elements: TimelineElement[],
200
+ clipIdScope?: string,
180
201
  ): string | null {
181
202
  const selectionSourceFile = selection.sourceFile || "index.html";
182
203
  // Priority matters, not just "any of the three": a composition-host
@@ -191,7 +212,7 @@ export function findMatchingTimelineElementId(
191
212
  // first; only fall back to the coarser compositionSrc-only match when
192
213
  // none of them identifies a specific element.
193
214
  const byId = selection.id
194
- ? elements.find((el) => matchesByDomId(selection, el, selectionSourceFile))
215
+ ? elements.find((el) => matchesByDomId(selection, el, selectionSourceFile, clipIdScope))
195
216
  : undefined;
196
217
  if (byId) return byId.key ?? byId.id;
197
218
 
@@ -199,7 +220,7 @@ export function findMatchingTimelineElementId(
199
220
  // whether it has a real DOM id — the only correlator for an element like
200
221
  // an ungroup child that has neither an authored id nor a selector.
201
222
  const byHfId = selection.hfId
202
- ? elements.find((el) => matchesByHfId(selection, el, selectionSourceFile))
223
+ ? elements.find((el) => matchesByHfId(selection, el, selectionSourceFile, clipIdScope))
203
224
  : undefined;
204
225
  if (byHfId) return byHfId.key ?? byHfId.id;
205
226
 
@@ -267,9 +288,11 @@ export function resolveTimelineIdForSelection(
267
288
  selection: DomEditSelection,
268
289
  elements: TimelineElement[],
269
290
  activeCompPath: string | null,
291
+ byClipId = false,
270
292
  ): string | null {
293
+ const clipIdScope = byClipId ? activeCompPath || "index.html" : undefined;
271
294
  return (
272
- findMatchingTimelineElementId(selection, elements) ??
295
+ findMatchingTimelineElementId(selection, elements, clipIdScope) ??
273
296
  findTimelineIdByAncestor(
274
297
  selection.element,
275
298
  elements,