@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
@@ -3,22 +3,28 @@
3
3
  * and the `findElementForSelection` / `findElementForTimelineElement` lookups.
4
4
  */
5
5
  import type {
6
- DomEditContextOptions,
7
6
  DomEditSelection,
8
7
  DomEditViewport,
9
8
  TimelineElementDomTarget,
10
9
  TimelineElementDomTargetOptions,
11
10
  } from "./domEditingTypes";
12
11
  import {
13
- buildStableSelector,
14
- escapeCssString,
15
12
  getSelectorIndex,
16
13
  getSourceFileForElement,
17
14
  isHtmlElement,
18
15
  isElementVisibleThroughAncestors,
19
- normalizeTimelineCompositionSource,
20
16
  querySelectorAllSafely,
21
17
  } from "./domEditingDom";
18
+ import { selectionLookups, timelineElementLookup } from "./domEditSelectionRules";
19
+ import {
20
+ isDomLayerElement,
21
+ isInspectableLayerElement,
22
+ resolveAllVisualDomEditTargets,
23
+ resolveLayerSelector,
24
+ } from "@hyperframes/core/runtime/editing-port";
25
+
26
+ // One hit-test rule for Studio and the runtime that answers it for a frame Studio cannot script.
27
+ export { isDomLayerElement, isInspectableLayerElement };
22
28
 
23
29
  // ─── Visibility ──────────────────────────────────────────────────────────────
24
30
 
@@ -29,87 +35,10 @@ export function isElementComputedVisible(
29
35
  return isElementVisibleThroughAncestors(el, memo);
30
36
  }
31
37
 
32
- const VISUAL_LEAF_TAGS = new Set(["img", "video", "canvas", "svg", "audio"]);
33
-
34
- // fallow-ignore-next-line complexity
35
- function hasVisualPresence(el: HTMLElement): boolean {
36
- const win = el.ownerDocument.defaultView;
37
- if (!win) return false;
38
- const cs = win.getComputedStyle(el);
39
- if (cs.backgroundImage !== "none") return true;
40
- if (
41
- cs.backgroundColor &&
42
- cs.backgroundColor !== "transparent" &&
43
- cs.backgroundColor !== "rgba(0, 0, 0, 0)"
44
- )
45
- return true;
46
- if (cs.borderWidth && parseFloat(cs.borderWidth) > 0 && cs.borderStyle !== "none") return true;
47
- if (cs.boxShadow && cs.boxShadow !== "none") return true;
48
- return false;
49
- }
50
-
51
- function isEmptyVisualContainer(el: HTMLElement): boolean {
52
- const tag = el.tagName.toLowerCase();
53
- if (VISUAL_LEAF_TAGS.has(tag)) return false;
54
- if (hasVisualPresence(el)) return false;
55
-
56
- const { children } = el;
57
- if (children.length === 0) {
58
- return (el.textContent ?? "").trim().length === 0;
59
- }
60
-
61
- for (let i = 0; i < children.length; i += 1) {
62
- const child = children[i];
63
- if (!isHtmlElement(child)) continue;
64
- if (VISUAL_LEAF_TAGS.has(child.tagName.toLowerCase())) return false;
65
- if (isElementComputedVisible(child)) return false;
66
- }
67
-
68
- return true;
69
- }
70
-
71
- function hasRenderedBox(el: HTMLElement): boolean {
72
- const rect = el.getBoundingClientRect();
73
- if (rect.width <= 1 || rect.height <= 1) return false;
74
- if (!isElementComputedVisible(el)) return false;
75
- if (isEmptyVisualContainer(el)) return false;
76
- return true;
77
- }
78
-
79
38
  // ─── Visual scoring ──────────────────────────────────────────────────────────
80
39
 
81
40
  // ─── Layer patch target ──────────────────────────────────────────────────────
82
41
 
83
- const DOM_LAYER_IGNORED_TAGS = new Set([
84
- "base",
85
- "br",
86
- "canvas",
87
- "link",
88
- "meta",
89
- "script",
90
- "source",
91
- "style",
92
- "template",
93
- "track",
94
- "wbr",
95
- ]);
96
-
97
- /**
98
- * Is the element rendered at all? The half of `getDomLayerPatchTarget` that a
99
- * plain style write can flip, and the only half that reads computed style.
100
- * Exported so a caller memoizing a layer walk can give it its own (short)
101
- * cache lifetime — see `domEditLayerWalkCache`.
102
- */
103
- export function isInspectableLayerElement(el: HTMLElement): boolean {
104
- const tagName = el.tagName.toLowerCase();
105
- if (DOM_LAYER_IGNORED_TAGS.has(tagName)) return false;
106
-
107
- const computed = el.ownerDocument.defaultView?.getComputedStyle(el);
108
- if (computed?.display === "none" || computed?.visibility === "hidden") return false;
109
-
110
- return true;
111
- }
112
-
113
42
  /**
114
43
  * How the element is ADDRESSED — its selector, that selector's occurrence index
115
44
  * within the source file, and the file itself. Independent of whether the
@@ -117,17 +46,6 @@ export function isInspectableLayerElement(el: HTMLElement): boolean {
117
46
  * when an identity attribute changes or the document's population of elements
118
47
  * sharing the selector does.
119
48
  */
120
- /**
121
- * The selector an element is addressed by, or undefined when it cannot be a
122
- * layer at all. Sole owner of that rule: `isDomLayerElement` answers the same
123
- * question without paying for the occurrence index, and a second copy of the
124
- * conditions would go stale the first time one of them changed.
125
- */
126
- function resolveLayerSelector(el: HTMLElement): string | undefined {
127
- if (el.hasAttribute("data-composition-id")) return undefined;
128
- return buildStableSelector(el);
129
- }
130
-
131
49
  export function resolveDomLayerIdentity(
132
50
  el: HTMLElement,
133
51
  activeCompositionPath: string | null,
@@ -151,105 +69,12 @@ export function resolveDomLayerIdentity(
151
69
  };
152
70
  }
153
71
 
154
- export function getDomLayerPatchTarget(
155
- el: HTMLElement,
156
- activeCompositionPath: string | null,
157
- ): Pick<DomEditSelection, "id" | "hfId" | "selector" | "selectorIndex" | "sourceFile"> | null {
158
- return isInspectableLayerElement(el) ? resolveDomLayerIdentity(el, activeCompositionPath) : null;
159
- }
160
-
161
- /**
162
- * Is `el` a layer at all? Exactly the condition under which
163
- * `getDomLayerPatchTarget` returns non-null, for callers that want the yes/no
164
- * and throw the target away.
165
- *
166
- * Worth its own function because the target carries the selector's OCCURRENCE
167
- * INDEX, and resolving that is a whole-document query — which the yes/no does
168
- * not depend on. Counting an element's layer children asked for one per child.
169
- */
170
- export function isDomLayerElement(el: HTMLElement): boolean {
171
- return isInspectableLayerElement(el) && resolveLayerSelector(el) !== undefined;
172
- }
173
-
174
- // ─── Clip ancestor / selection candidate ─────────────────────────────────────
175
-
176
- function getPreferredClipAncestor(startEl: HTMLElement): HTMLElement | null {
177
- let current: HTMLElement | null = startEl;
178
- while (current) {
179
- if (current.classList.contains("clip")) {
180
- const isCompositionHost =
181
- current.hasAttribute("data-composition-src") ||
182
- current.hasAttribute("data-composition-file");
183
- if (!isCompositionHost || current === startEl) return current;
184
- }
185
- current = current.parentElement;
186
- }
187
- return null;
188
- }
189
-
190
- export function getSelectionCandidate(
191
- startEl: HTMLElement,
192
- options: DomEditContextOptions,
193
- ): HTMLElement {
194
- if (options.preferClipAncestor) {
195
- const clipAncestor = getPreferredClipAncestor(startEl);
196
- if (clipAncestor) {
197
- return clipAncestor;
198
- }
199
- }
200
-
201
- return startEl;
202
- }
203
-
204
72
  // ─── Visual target resolution ─────────────────────────────────────────────────
205
73
 
206
74
  export function resolveVisualDomEditSelectionTarget(
207
75
  elementsFromPoint: Iterable<Element | null | undefined>,
208
- options: Pick<DomEditContextOptions, "activeCompositionPath">,
209
76
  ): HTMLElement | null {
210
- const candidates = resolveAllVisualDomEditTargets(elementsFromPoint, options);
211
- return candidates[0] ?? null;
212
- }
213
-
214
- /**
215
- * Returns all independently-selectable elements at the given point, in paint
216
- * order (topmost first). Used for click-cycling through stacked layers.
217
- *
218
- * Each entry in the returned array is an independent "layer" — an element
219
- * that is not an ancestor of an earlier entry. This gives one result per
220
- * z-stacked element rather than one per DOM node.
221
- */
222
- export function resolveAllVisualDomEditTargets(
223
- elementsFromPoint: Iterable<Element | null | undefined>,
224
- options: Pick<DomEditContextOptions, "activeCompositionPath">,
225
- ): HTMLElement[] {
226
- const raw: HTMLElement[] = [];
227
-
228
- for (const entry of elementsFromPoint) {
229
- if (!isHtmlElement(entry)) continue;
230
- if (hasRenderedBox(entry) && getDomLayerPatchTarget(entry, options.activeCompositionPath)) {
231
- raw.push(entry);
232
- }
233
- }
234
-
235
- if (raw.length === 0) return [];
236
-
237
- // First pass: for each contiguous ancestor-descendant run, keep only the
238
- // deepest (most specific) element, matching the original single-pick logic.
239
- const layers: HTMLElement[] = [];
240
- let best = raw[0];
241
- for (let i = 1; i < raw.length; i++) {
242
- const el = raw[i];
243
- if (best.contains(el)) {
244
- best = el; // go deeper in this subtree
245
- } else {
246
- layers.push(best);
247
- best = el;
248
- }
249
- }
250
- layers.push(best);
251
-
252
- return layers;
77
+ return resolveAllVisualDomEditTargets(elementsFromPoint)[0] ?? null;
253
78
  }
254
79
 
255
80
  // ─── Raster detection ────────────────────────────────────────────────────────
@@ -295,23 +120,11 @@ export function findElementForSelection(
295
120
  (!selection.sourceFile ||
296
121
  getSourceFileForElement(candidate, activeCompositionPath).sourceFile ===
297
122
  selection.sourceFile);
298
- const findAll = (selector: string): HTMLElement[] =>
299
- querySelectorAllSafely(doc, selector).filter(sourceMatches);
300
-
301
- if (selection.hfId) {
302
- const byHfId = findAll(`[data-hf-id="${escapeCssString(selection.hfId)}"]`)[0];
303
- if (byHfId) return byHfId;
123
+ for (const { selector, index } of selectionLookups(selection)) {
124
+ const found = querySelectorAllSafely(doc, selector).filter(sourceMatches)[index];
125
+ if (found) return found;
304
126
  }
305
-
306
- if (selection.id) {
307
- // Flattened sub-compositions can repeat authored ids. getElementById returns
308
- // only the first document match, so filter every id match by source first.
309
- const byId = findAll(`[id="${escapeCssString(selection.id)}"]`)[0];
310
- if (byId) return byId;
311
- }
312
-
313
- if (!selection.selector) return null;
314
- return findAll(selection.selector)[selection.selectorIndex ?? 0] ?? null;
127
+ return null;
315
128
  }
316
129
 
317
130
  // The selected node while mounted, else its copy in the selection's own file (ids repeat across files), else any copy.
@@ -327,49 +140,15 @@ export function findPreviewNode(
327
140
  );
328
141
  }
329
142
 
330
- // fallow-ignore-next-line complexity
331
143
  export function findElementForTimelineElement(
332
144
  doc: Document,
333
145
  element: TimelineElementDomTarget,
334
146
  options: TimelineElementDomTargetOptions,
335
147
  ): HTMLElement | null {
336
- const elementId = typeof element.id === "string" ? element.id : "";
337
- const compositionSource =
338
- normalizeTimelineCompositionSource(element.compositionSrc) ??
339
- options.compIdToSrc?.get(elementId);
340
- const sourceFile =
341
- compositionSource ??
342
- normalizeTimelineCompositionSource(element.sourceFile) ??
343
- options.activeCompositionPath ??
344
- "index.html";
345
- const escapedElementId = escapeCssString(elementId);
346
- const escapedCompositionSource = compositionSource ? escapeCssString(compositionSource) : null;
347
- const selector =
348
- element.selector ??
349
- (compositionSource
350
- ? `[data-composition-src="${escapedCompositionSource}"],[data-composition-file="${escapedCompositionSource}"],[data-composition-id="${escapedElementId}"]`
351
- : escapedElementId
352
- ? `[data-composition-id="${escapedElementId}"]`
353
- : undefined);
354
-
355
- if (selector || element.domId) {
356
- const targetElement = findElementForSelection(
357
- doc,
358
- {
359
- id: element.domId ?? undefined,
360
- selector,
361
- selectorIndex: element.selectorIndex,
362
- sourceFile,
363
- },
364
- options.activeCompositionPath,
365
- );
366
- if (targetElement) return targetElement;
367
- }
368
-
369
- const hasExplicitDomTarget = Boolean(element.domId || element.selector || compositionSource);
370
- if (options.isMasterView || hasExplicitDomTarget || !options.activeCompositionPath) {
371
- return null;
372
- }
148
+ const { target, sourceFile, rootFallback } = timelineElementLookup(element, options);
149
+ const found = target && findElementForSelection(doc, target, options.activeCompositionPath);
150
+ if (found) return found;
151
+ if (!rootFallback) return null;
373
152
 
374
153
  const root = doc.querySelector("[data-composition-id]");
375
154
  if (!isHtmlElement(root)) return null;
@@ -1,15 +1,5 @@
1
1
  import { isHtmlElement } from "./domEditingDom";
2
2
 
3
- // `data-hf-group` selection semantics: a group wrapper is selected as one unit
4
- // until the user drills into it; once drilled in, clicks resolve to its children
5
- // (or to the next nested group inside it). One level of drill-in at a time keeps
6
- // nested groups navigable.
7
-
8
- export type GroupCapture =
9
- | { kind: "unit"; element: HTMLElement } // select this group wrapper as one unit
10
- | { kind: "child" } // resolve the clicked element normally
11
- | { kind: "out-of-scope" }; // clicked outside the drilled-into group → select nothing
12
-
13
3
  // Layer-tree roots: the drilled-into group's element children, else the doc root.
14
4
  export function groupScopedLayerRoots(
15
5
  root: HTMLElement,
@@ -18,24 +8,3 @@ export function groupScopedLayerRoots(
18
8
  const els = activeGroupElement?.isConnected ? Array.from(activeGroupElement.children) : [root];
19
9
  return els.filter(isHtmlElement);
20
10
  }
21
-
22
- export function resolveGroupCapture(
23
- startEl: HTMLElement,
24
- activeGroupElement: HTMLElement | null,
25
- ): GroupCapture {
26
- const groups: HTMLElement[] = [];
27
- for (let n: HTMLElement | null = startEl; n; n = n.parentElement) {
28
- if (n.hasAttribute("data-hf-group")) groups.push(n);
29
- }
30
- const result = ((): GroupCapture => {
31
- if (!activeGroupElement) {
32
- const outermost = groups[groups.length - 1];
33
- return outermost ? { kind: "unit", element: outermost } : { kind: "child" };
34
- }
35
- const idx = groups.indexOf(activeGroupElement);
36
- if (idx === -1) return { kind: "out-of-scope" };
37
- const nestedInside = groups[idx - 1];
38
- return nestedInside ? { kind: "unit", element: nestedInside } : { kind: "child" };
39
- })();
40
- return result;
41
- }
@@ -1,5 +1,5 @@
1
1
  import { isClipHiddenByRuntime, PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
2
- import { knownSourceAnswer, probeSourceElement, type ProbeTarget } from "./probeSourceElement";
2
+ import { existsInSourceFile } from "./probeSourceElement";
3
3
  import { isAudibleVideoNode } from "../../player/lib/timelineElementHelpers";
4
4
  import type { PatchOperation } from "../../utils/sourcePatcher";
5
5
  import {
@@ -7,7 +7,12 @@ import {
7
7
  resolveEditingSections,
8
8
  type EditableElementFacts,
9
9
  } from "@hyperframes/core/editing";
10
- import { groupScopedLayerRoots, resolveGroupCapture } from "./domEditingGroups";
10
+ import { groupScopedLayerRoots } from "./domEditingGroups";
11
+ import {
12
+ chainLocked,
13
+ selectionTargetIndex,
14
+ type SelectionChainReader,
15
+ } from "./domEditSelectionRules";
11
16
  import type {
12
17
  DomEditCapabilities,
13
18
  DomEditContextOptions,
@@ -18,7 +23,6 @@ import type {
18
23
  import {
19
24
  buildElementLabel,
20
25
  buildStableSelector,
21
- findClosestByAttribute,
22
26
  getCuratedComputedStyles,
23
27
  getDataAttributes,
24
28
  getInlineStyles,
@@ -27,11 +31,7 @@ import {
27
31
  isEditableTextLeaf,
28
32
  isHtmlElement,
29
33
  } from "./domEditingDom";
30
- import {
31
- findElementForSelection,
32
- getSelectionCandidate,
33
- isDomLayerElement,
34
- } from "./domEditingElement";
34
+ import { findElementForSelection, isDomLayerElement } from "./domEditingElement";
35
35
  import { isCompositionRootLayer } from "./domEditingRootLayer";
36
36
  import { withSelectorIndexPass } from "../../utils/sourceScopedSelectorIndex";
37
37
  import { type DomEditLayerWalkCache, readDomEditLayerWalkEntry } from "./domEditLayerWalkCache";
@@ -206,7 +206,7 @@ export function buildTextFieldChildLocator(
206
206
  };
207
207
  }
208
208
 
209
- function capabilityFacts(geometry: {
209
+ export function capabilityFacts(geometry: {
210
210
  hasStableTarget: boolean;
211
211
  tag: string;
212
212
  inlineStyles: Record<string, string>;
@@ -248,7 +248,7 @@ export function domEditSelectionToFacts(
248
248
  hasEditableText: selection.textFields.length > 0,
249
249
  hasTimingStart: selection.dataAttributes.start != null,
250
250
  animationCount,
251
- hasAudio: isAudibleVideoNode(selection.element),
251
+ hasAudio: selection.hasAudio ?? isAudibleVideoNode(selection.element),
252
252
  };
253
253
  }
254
254
 
@@ -296,99 +296,94 @@ export async function resolveDomEditSelection(
296
296
  ): Promise<DomEditSelection | null> {
297
297
  if (!startEl) return null;
298
298
  const doc = startEl.ownerDocument;
299
-
300
- let capture = options.exactTarget
301
- ? ({ kind: "unit", element: startEl } as const)
302
- : resolveGroupCapture(startEl, options.activeGroupElement ?? null);
303
- if (capture.kind === "out-of-scope") {
304
- // Drill-in is non-sticky: clicking/hovering OUTSIDE the drilled-into group
305
- // exits it and resolves the target normally, rather than selecting nothing
306
- // (which felt like "can't select anything" once you'd drilled in).
307
- capture = resolveGroupCapture(startEl, null);
308
- }
309
- let current: HTMLElement | null =
310
- capture.kind === "unit" ? capture.element : getSelectionCandidate(startEl, options);
311
- while (current && current !== doc.body && current !== doc.documentElement) {
312
- const selector = buildStableSelector(current);
313
- const hfId = readHfId(current);
314
- if (!selector && !hfId) {
315
- current = current.parentElement;
316
- continue;
317
- }
318
-
319
- const { sourceFile, compositionPath } = getSourceFileForElement(
320
- current,
321
- options.activeCompositionPath,
322
- );
323
- const selectorIndex = selector
324
- ? getSelectorIndex(doc, current, selector, sourceFile, options.activeCompositionPath)
325
- : undefined;
326
- const compositionSrc =
327
- current.getAttribute("data-composition-src") ??
328
- current.getAttribute("data-composition-file") ??
329
- undefined;
330
- const inlineStyles = getInlineStyles(current);
331
- const computedStyles = getCuratedComputedStyles(current);
332
- const isCompositionRoot =
333
- (current.hasAttribute("data-composition-id") && !compositionSrc) ||
334
- isCompositionRootLayer(current, doc, computedStyles);
335
- const textFields = collectDomEditTextFields(current);
336
- const isInsideLocked = Boolean(findClosestByAttribute(current, ["data-timeline-locked"]));
337
- const probeTarget: ProbeTarget = {};
338
- if (current.id) probeTarget.id = current.id;
339
- if (hfId) probeTarget.hfId = hfId;
340
- if (selector) probeTarget.selector = selector;
341
- if (selectorIndex != null) probeTarget.selectorIndex = selectorIndex;
342
- let existsInSource = knownSourceAnswer(options.previous, current, sourceFile, probeTarget);
343
- const probe = existsInSource === undefined && !options.skipSourceProbe;
344
- if (probe && options.projectId && (current.id || selector || hfId)) {
345
- existsInSource = await probeSourceElement(options.projectId, sourceFile, probeTarget);
346
- }
347
- const capabilities = resolveEditingAffordances(
348
- capabilityFacts({
349
- hasStableTarget: Boolean(selector || hfId),
350
- tag: current.tagName.toLowerCase(),
351
- inlineStyles,
352
- computedStyles,
353
- isCompositionHost: Boolean(compositionSrc),
354
- isCompositionRoot,
355
- isInsideLockedComposition: isInsideLocked,
356
- isMasterView: options.isMasterView,
357
- existsInSource: existsInSource ?? true,
358
- }),
359
- ).capabilities;
360
- const rect = current.getBoundingClientRect();
361
-
362
- return {
363
- element: current,
364
- id: current.id || undefined,
365
- hfId,
366
- selector,
367
- selectorIndex,
368
- sourceFile,
369
- compositionPath,
370
- compositionSrc,
371
- isCompositionHost: Boolean(compositionSrc),
372
- isInsideLockedComposition: isInsideLocked,
373
- label: buildElementLabel(current),
374
- tagName: current.tagName.toLowerCase(),
375
- boundingBox: {
376
- x: rect.left,
377
- y: rect.top,
378
- width: rect.width,
379
- height: rect.height,
380
- },
381
- textContent: current.textContent?.trim() || null,
382
- dataAttributes: getDataAttributes(current),
299
+ const chain: HTMLElement[] = [];
300
+ for (let node: HTMLElement | null = startEl; node; node = node.parentElement) chain.push(node);
301
+ const read = liveChainReader(doc);
302
+ const active = options.activeGroupElement ?? null;
303
+ const index = selectionTargetIndex(chain, read, {
304
+ exactTarget: options.exactTarget,
305
+ preferClipAncestor: options.preferClipAncestor,
306
+ activeGroupIndex: active ? chain.indexOf(active) : null,
307
+ });
308
+ if (index === null) return null;
309
+ const current = chain[index]!;
310
+ const selector = buildStableSelector(current);
311
+ const hfId = readHfId(current);
312
+ const { sourceFile, compositionPath } = getSourceFileForElement(
313
+ current,
314
+ options.activeCompositionPath,
315
+ );
316
+ const selectorIndex = selector
317
+ ? getSelectorIndex(doc, current, selector, sourceFile, options.activeCompositionPath)
318
+ : undefined;
319
+ const compositionSrc =
320
+ current.getAttribute("data-composition-src") ??
321
+ current.getAttribute("data-composition-file") ??
322
+ undefined;
323
+ const inlineStyles = getInlineStyles(current);
324
+ const computedStyles = getCuratedComputedStyles(current);
325
+ const isCompositionRoot =
326
+ (current.hasAttribute("data-composition-id") && !compositionSrc) ||
327
+ isCompositionRootLayer(current, doc, computedStyles);
328
+ const textFields = collectDomEditTextFields(current);
329
+ const isInsideLocked = chainLocked(chain, read, index);
330
+ const existsInSource = await existsInSourceFile(
331
+ options.previous,
332
+ current,
333
+ sourceFile,
334
+ { id: current.id, hfId, selector, selectorIndex },
335
+ options,
336
+ );
337
+ const capabilities = resolveEditingAffordances(
338
+ capabilityFacts({
339
+ hasStableTarget: Boolean(selector || hfId),
340
+ tag: current.tagName.toLowerCase(),
383
341
  inlineStyles,
384
342
  computedStyles,
385
- textFields,
386
- capabilities,
387
- existsInSource,
388
- };
389
- }
343
+ isCompositionHost: Boolean(compositionSrc),
344
+ isCompositionRoot,
345
+ isInsideLockedComposition: isInsideLocked,
346
+ isMasterView: options.isMasterView,
347
+ existsInSource: existsInSource ?? true,
348
+ }),
349
+ ).capabilities;
350
+ const rect = current.getBoundingClientRect();
390
351
 
391
- return null;
352
+ return {
353
+ element: current,
354
+ id: current.id || undefined,
355
+ hfId,
356
+ selector,
357
+ selectorIndex,
358
+ sourceFile,
359
+ compositionPath,
360
+ compositionSrc,
361
+ isCompositionHost: Boolean(compositionSrc),
362
+ isInsideLockedComposition: isInsideLocked,
363
+ label: buildElementLabel(current),
364
+ tagName: current.tagName.toLowerCase(),
365
+ boundingBox: {
366
+ x: rect.left,
367
+ y: rect.top,
368
+ width: rect.width,
369
+ height: rect.height,
370
+ },
371
+ textContent: current.textContent?.trim() || null,
372
+ dataAttributes: getDataAttributes(current),
373
+ inlineStyles,
374
+ computedStyles,
375
+ textFields,
376
+ capabilities,
377
+ existsInSource,
378
+ };
379
+ }
380
+
381
+ function liveChainReader(doc: Document): SelectionChainReader<HTMLElement> {
382
+ return {
383
+ attr: (el, name) => el.getAttribute(name),
384
+ selector: buildStableSelector,
385
+ isDocumentRoot: (el) => el === doc.body || el === doc.documentElement,
386
+ };
392
387
  }
393
388
 
394
389
  export async function refreshDomEditSelection(