@hyperframes/studio 0.9.40 → 0.9.41
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.
- package/dist/assets/{codec-BPK_2CLL.js → codec-B_mpbc4w.js} +1 -1
- package/dist/assets/{hyperframes-player-D7qTTDIp.js → hyperframes-player-Dvi3I_mv.js} +1 -1
- package/dist/assets/{index-CdA00Ybn.js → index-B5ExwsOp.js} +146 -146
- package/dist/assets/{index-QS-DuxAU.js → index-BrFm9Y5k.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-Byzz98Gb.js → pausedVideoDecoder-MHQ57yZ6.js} +1 -1
- package/dist/{chunk-KF6YVXJP.js → chunk-4QQMX4BX.js} +6 -3
- package/dist/{chunk-VZ5MD32A.js → chunk-GVW7AU57.js} +190 -254
- package/dist/{chunk-AV2PV7NE.js → chunk-VHV2ZDKY.js} +4 -40
- package/dist/{domEditingLayers-4KRREI5C.js → domEditingLayers-SA5KLSSS.js} +4 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.html +1 -1
- package/dist/index.js +898 -551
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/components/editor/DomEditOverlay.tsx +3 -15
- package/src/components/editor/clickAfterPreventedPress.test.tsx +17 -1
- package/src/components/editor/domEditOverlayBasis.ts +7 -2
- package/src/components/editor/domEditOverlayCrop.test.ts +1 -1
- package/src/components/editor/domEditOverlayCrop.ts +17 -3
- package/src/components/editor/domEditOverlayGeometry.ts +64 -139
- package/src/components/editor/domEditSelectionRules.ts +138 -0
- package/src/components/editor/domEditing.test.ts +6 -28
- package/src/components/editor/domEditingDom.preview.test.ts +3 -3
- package/src/components/editor/domEditingDom.ts +3 -76
- package/src/components/editor/domEditingElement.ts +19 -240
- package/src/components/editor/domEditingGroups.ts +0 -31
- package/src/components/editor/domEditingLayers.ts +95 -100
- package/src/components/editor/domEditingRootLayer.ts +35 -30
- package/src/components/editor/domEditingTypes.ts +4 -0
- package/src/components/editor/previewGestureStarts.ts +73 -10
- package/src/components/editor/previewOverlayRects.test.ts +316 -0
- package/src/components/editor/previewOverlayRects.ts +123 -0
- package/src/components/editor/previewPointerTargets.test.ts +260 -0
- package/src/components/editor/previewSelection.test.ts +481 -0
- package/src/components/editor/previewSelection.ts +472 -0
- package/src/components/editor/probeSourceElement.ts +19 -1
- package/src/components/editor/propertyPanelFill.tsx +5 -1
- package/src/components/editor/useDomEditOverlayRects.ts +80 -1
- package/src/components/editor/useInlineTextEditing.tsx +1 -6
- package/src/hooks/domSelectionTestHarness.ts +1 -1
- package/src/hooks/useDomEditSession.test.tsx +23 -1
- package/src/hooks/useDomEditSession.ts +2 -1
- package/src/hooks/useDomSelection.ts +61 -47
- package/src/hooks/useGsapSelectionHandlers.test.tsx +17 -0
- package/src/hooks/useGsapSelectionHandlers.ts +2 -1
- package/src/hooks/usePreviewInteraction.test.ts +10 -2
- package/src/hooks/usePreviewInteraction.ts +5 -4
- package/src/hooks/useStudioSelectionPublisher.test.tsx +50 -0
- package/src/hooks/useStudioSelectionPublisher.ts +9 -7
- package/src/player/lib/previewChannel.ts +4 -3
- package/src/player/lib/previewElements.ts +112 -3
- package/src/styles/hex-baseline.json +1 -2
- package/src/utils/studioHelpers.ts +0 -13
- package/src/utils/studioPreviewHelpers.test.ts +8 -8
- package/src/utils/studioPreviewHelpers.ts +26 -242
- package/src/components/editor/domEditOverlayTransform.ts +0 -126
|
@@ -42,7 +42,7 @@ it("keeps a provider-backed video selectable and listed with its logical opacity
|
|
|
42
42
|
const { video, canvas, root } = preview("0.65");
|
|
43
43
|
expect(getComputedStyle(video).opacity).toBe("0");
|
|
44
44
|
expect(isElementVisibleThroughAncestors(video)).toBe(true);
|
|
45
|
-
expect(resolveVisualDomEditSelectionTarget([canvas, video]
|
|
45
|
+
expect(resolveVisualDomEditSelectionTarget([canvas, video])).toBe(video);
|
|
46
46
|
expect(collectDomEditLayerItems(root, options).map((item) => item.element)).toEqual([video]);
|
|
47
47
|
const selected = await resolveDomEditSelection(video, options);
|
|
48
48
|
expect(selected?.computedStyles.opacity).toBe("0.65");
|
|
@@ -53,7 +53,7 @@ it("keeps a provider-backed video selectable and listed with its logical opacity
|
|
|
53
53
|
it("keeps authored zero opacity invisible and reports zero to the inspector", async () => {
|
|
54
54
|
const { video, canvas } = preview("0");
|
|
55
55
|
expect(isElementVisibleThroughAncestors(video)).toBe(false);
|
|
56
|
-
expect(resolveVisualDomEditSelectionTarget([canvas, video]
|
|
56
|
+
expect(resolveVisualDomEditSelectionTarget([canvas, video])).toBeNull();
|
|
57
57
|
expect(getCuratedComputedStyles(video).opacity).toBe("0");
|
|
58
58
|
const selected = await resolveDomEditSelection(video, options);
|
|
59
59
|
expect(selected?.computedStyles.opacity).toBe("0");
|
|
@@ -64,7 +64,7 @@ it("still respects a hidden ancestor when the preview frame itself is visible",
|
|
|
64
64
|
const { video, root } = preview("0.65");
|
|
65
65
|
root.style.opacity = "0";
|
|
66
66
|
expect(isElementVisibleThroughAncestors(video)).toBe(false);
|
|
67
|
-
expect(resolveVisualDomEditSelectionTarget([video]
|
|
67
|
+
expect(resolveVisualDomEditSelectionTarget([video])).toBeNull();
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
it("does not treat an unrelated preceding canvas as the video's visible frame", () => {
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* No imports from other domEditing* modules — safe to import from anywhere.
|
|
5
5
|
*/
|
|
6
6
|
import { getLogicalOpacity } from "@hyperframes/core/studio-preview-mark";
|
|
7
|
-
import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading";
|
|
8
7
|
import {
|
|
9
8
|
buildStableSelector,
|
|
10
9
|
escapeCssString,
|
|
11
10
|
getPreferredClassSelector,
|
|
11
|
+
isElementVisibleThroughAncestors,
|
|
12
12
|
readElementSource,
|
|
13
13
|
type EditingElementSource,
|
|
14
14
|
} from "@hyperframes/core/runtime/editing-port";
|
|
@@ -45,65 +45,8 @@ export function isEditableTextLeaf(el: HTMLElement): boolean {
|
|
|
45
45
|
export { getLogicalOpacity };
|
|
46
46
|
// One addressing rule for Studio and the runtime that describes elements to it.
|
|
47
47
|
export { buildStableSelector, escapeCssString };
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* rule; the walk below only decides which nodes to ask it about. */
|
|
51
|
-
function elementRendersItself(win: Window, el: HTMLElement): boolean {
|
|
52
|
-
const computed = win.getComputedStyle(el);
|
|
53
|
-
if (computed.display === "none" || computed.visibility === "hidden") return false;
|
|
54
|
-
const opacity = Number.parseFloat(getLogicalOpacity(el, computed));
|
|
55
|
-
return !(
|
|
56
|
-
Number.isFinite(opacity) &&
|
|
57
|
-
opacity <= 0.01 &&
|
|
58
|
-
!el.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Does `el` render, given everything above it?
|
|
64
|
-
*
|
|
65
|
-
* `memo` is for a caller asking this about MANY elements in one synchronous
|
|
66
|
-
* pass. Answers are a function of the node and its ancestors, and siblings
|
|
67
|
-
* share almost all of their chain, so memoizing per node turns a walk per
|
|
68
|
-
* element into one style read per node in the tree. It is only ever valid for
|
|
69
|
-
* the length of one pass — the DOM cannot change under a pass, and every read
|
|
70
|
-
* here is a read — so the caller creates it and drops it, and nothing survives
|
|
71
|
-
* to be invalidated. Omitted, every call walks the chain itself.
|
|
72
|
-
*
|
|
73
|
-
* The ANSWER is what it always was. Which nodes get a style read is not: this
|
|
74
|
-
* resolves top-down and stops at the first node that is out, where the previous
|
|
75
|
-
* version resolved bottom-up and stopped at the first one that is out going the
|
|
76
|
-
* other way. Same boolean for every input, a different (and, for a subtree
|
|
77
|
-
* hidden near the root, smaller) set of reads.
|
|
78
|
-
*/
|
|
79
|
-
export function isElementVisibleThroughAncestors(
|
|
80
|
-
el: HTMLElement,
|
|
81
|
-
memo?: Map<HTMLElement, boolean>,
|
|
82
|
-
): boolean {
|
|
83
|
-
const win = el.ownerDocument.defaultView;
|
|
84
|
-
if (!win) return true;
|
|
85
|
-
// Up to the first node already answered for, then back down: a node's answer
|
|
86
|
-
// needs its ancestors' first, and the topmost unanswered node is where the
|
|
87
|
-
// chain of unknowns starts.
|
|
88
|
-
const pending: HTMLElement[] = [];
|
|
89
|
-
let inherited = true;
|
|
90
|
-
for (let node: HTMLElement | null = el; node; node = node.parentElement) {
|
|
91
|
-
const answered = memo?.get(node);
|
|
92
|
-
if (answered !== undefined) {
|
|
93
|
-
inherited = answered;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
pending.push(node);
|
|
97
|
-
}
|
|
98
|
-
for (let i = pending.length - 1; i >= 0; i -= 1) {
|
|
99
|
-
const node = pending[i]!;
|
|
100
|
-
// Once an ancestor is out, its descendants are out with it, and asking the
|
|
101
|
-
// platform about them would be a style read for an answer already known.
|
|
102
|
-
inherited = inherited && elementRendersItself(win, node);
|
|
103
|
-
memo?.set(node, inherited);
|
|
104
|
-
}
|
|
105
|
-
return inherited;
|
|
106
|
-
}
|
|
48
|
+
// One visibility rule for Studio and the runtime that measures overlay geometry for it.
|
|
49
|
+
export { isElementVisibleThroughAncestors };
|
|
107
50
|
|
|
108
51
|
// ─── Style accessors ──────────────────────────────────────────────────────────
|
|
109
52
|
|
|
@@ -140,22 +83,6 @@ export function getDataAttributes(el: HTMLElement): Record<string, string> {
|
|
|
140
83
|
return attrs;
|
|
141
84
|
}
|
|
142
85
|
|
|
143
|
-
// ─── DOM traversal ────────────────────────────────────────────────────────────
|
|
144
|
-
|
|
145
|
-
export function findClosestByAttribute(
|
|
146
|
-
el: HTMLElement,
|
|
147
|
-
attributeNames: string[],
|
|
148
|
-
): HTMLElement | null {
|
|
149
|
-
let current: HTMLElement | null = el;
|
|
150
|
-
while (current) {
|
|
151
|
-
const candidate = current;
|
|
152
|
-
if (attributeNames.some((attribute) => candidate.hasAttribute(attribute))) {
|
|
153
|
-
return candidate;
|
|
154
|
-
}
|
|
155
|
-
current = current.parentElement;
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
86
|
// ─── Composition source resolution ───────────────────────────────────────────
|
|
160
87
|
|
|
161
88
|
// The runtime INLINES subcompositions and strips the source-file linkage from the
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
}
|