@hyperframes/studio 0.9.39 → 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-CY6KnWXa.js → codec-B_mpbc4w.js} +1 -1
- package/dist/assets/{hyperframes-player-B9-CuG_h.js → hyperframes-player-Dvi3I_mv.js} +1 -1
- package/dist/assets/{index-_pkzoYYF.js → index-B5ExwsOp.js} +146 -146
- package/dist/assets/{index-Bjz2UaYv.js → index-BrFm9Y5k.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-Dr7nKUUu.js → pausedVideoDecoder-MHQ57yZ6.js} +1 -1
- package/dist/{chunk-NBULUIWH.js → chunk-4QQMX4BX.js} +17 -8
- package/dist/{chunk-ATDO3YLX.js → chunk-GVW7AU57.js} +190 -254
- package/dist/{chunk-44VRMER6.js → chunk-VHV2ZDKY.js} +17 -97
- package/dist/{domEditingLayers-FRVHP6IB.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 +24 -165
- 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 +26 -10
- package/src/player/lib/previewElements.test.ts +167 -0
- package/src/player/lib/previewElements.ts +226 -0
- 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
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import type { EditingElementDescription } from "@hyperframes/core/runtime/editing-port";
|
|
5
|
+
import {
|
|
6
|
+
describePreviewElements,
|
|
7
|
+
previewElementSelectorIndex,
|
|
8
|
+
previewElementSourceFile,
|
|
9
|
+
previewElementsAtPoint,
|
|
10
|
+
readPreviewElement,
|
|
11
|
+
type PreviewElement,
|
|
12
|
+
} from "./previewElements";
|
|
13
|
+
import { AGENT_PROBE_MS, previewComputedStyles } from "./previewChannel";
|
|
14
|
+
import {
|
|
15
|
+
getSelectorIndex,
|
|
16
|
+
getSourceFileForElement,
|
|
17
|
+
setCompositionSourceMap,
|
|
18
|
+
} from "../../components/editor/domEditingDom";
|
|
19
|
+
import { detachedFakeIframe, serveEditingRequests } from "../hooks/timelinePlayerTestHarness";
|
|
20
|
+
|
|
21
|
+
const closers: Array<() => void> = [];
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
closers.splice(0).forEach((close) => close());
|
|
24
|
+
setCompositionSourceMap(new Map());
|
|
25
|
+
document.body.innerHTML = "";
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** A frame Studio cannot read; `answer` is its runtime, or it has none. */
|
|
29
|
+
function opaqueFrame(answer?: (kind: string, params: unknown) => unknown) {
|
|
30
|
+
const frame: Record<string, unknown> = { postMessage: () => {} };
|
|
31
|
+
const iframe = detachedFakeIframe(frame);
|
|
32
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
33
|
+
Object.defineProperty(frame, "document", {
|
|
34
|
+
get: () => {
|
|
35
|
+
throw new DOMException("blocked", "SecurityError");
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const handed = vi.fn(answer ?? (() => null));
|
|
39
|
+
if (answer) closers.push(serveEditingRequests(frame, handed));
|
|
40
|
+
return { iframe, handed };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const NO_SOURCE = { file: null, compositionId: null, originalCompositionId: null };
|
|
44
|
+
|
|
45
|
+
const LOAD = "0123456789abcdef";
|
|
46
|
+
const h = (n: number) => `${LOAD}:${n}`;
|
|
47
|
+
|
|
48
|
+
function described(n: number, extra: Partial<EditingElementDescription> = {}) {
|
|
49
|
+
return {
|
|
50
|
+
handle: h(n),
|
|
51
|
+
parent: null,
|
|
52
|
+
tag: "div",
|
|
53
|
+
id: null,
|
|
54
|
+
selector: null,
|
|
55
|
+
matchesBefore: null,
|
|
56
|
+
source: NO_SOURCE,
|
|
57
|
+
locked: false,
|
|
58
|
+
attributes: [["data-hf-id", `hf-${n}`]],
|
|
59
|
+
inlineStyles: { left: "4px" },
|
|
60
|
+
text: "",
|
|
61
|
+
children: [{ text: "Hi" }, { handle: h(n + 1) }],
|
|
62
|
+
rect: { x: 1, y: 2, width: 3, height: 4 },
|
|
63
|
+
truncated: false,
|
|
64
|
+
...extra,
|
|
65
|
+
} as EditingElementDescription;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("readPreviewElement", () => {
|
|
69
|
+
it("takes a description with the wire shape and refuses anything off it", () => {
|
|
70
|
+
expect(readPreviewElement(described(1))).toEqual(described(1));
|
|
71
|
+
for (const bad of [
|
|
72
|
+
null,
|
|
73
|
+
[],
|
|
74
|
+
described(1, { handle: 1 as never }),
|
|
75
|
+
described(1, { handle: "1" }),
|
|
76
|
+
described(1, { handle: `${LOAD}:0` }),
|
|
77
|
+
described(1, { handle: `${LOAD.toUpperCase()}:1` }),
|
|
78
|
+
described(1, { parent: "x" }),
|
|
79
|
+
described(1, { tag: 1 as never }),
|
|
80
|
+
described(1, { source: { file: 1 } as never }),
|
|
81
|
+
described(1, { locked: "yes" as never }),
|
|
82
|
+
described(1, { attributes: [["a"]] as never }),
|
|
83
|
+
described(1, { inlineStyles: { left: 4 } as never }),
|
|
84
|
+
described(1, { children: [{ node: {} }] as never }),
|
|
85
|
+
described(1, { matchesBefore: [{ source: NO_SOURCE, count: -1 }] }),
|
|
86
|
+
described(1, { rect: { x: Number.NaN, y: 0, width: 0, height: 0 } }),
|
|
87
|
+
described(1, { truncated: undefined as never }),
|
|
88
|
+
]) {
|
|
89
|
+
expect(readPreviewElement(bad)).toBeNull();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("element requests over an opaque frame's port", () => {
|
|
95
|
+
it("asks for the stack under a point and keeps only well-formed entries", async () => {
|
|
96
|
+
const hit = { handle: h(1), tag: "p", rect: { x: 1, y: 2, width: 3, height: 4 } };
|
|
97
|
+
const bad = [
|
|
98
|
+
{ ...hit, handle: "x" },
|
|
99
|
+
{ ...hit, tag: 1 },
|
|
100
|
+
{ ...hit, rect: { x: 1 } },
|
|
101
|
+
];
|
|
102
|
+
const { iframe, handed } = opaqueFrame(() => ({ elements: [hit, ...bad] }));
|
|
103
|
+
expect(await previewElementsAtPoint(iframe, 10, 20)).toEqual([hit]);
|
|
104
|
+
expect(handed).toHaveBeenCalledWith("elements-at-point", { x: 10, y: 20 });
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("describes handles in order, with null for a gone element or a mismatched entry", async () => {
|
|
108
|
+
let reply: unknown = { elements: [described(2), null, described(9)] };
|
|
109
|
+
const { iframe, handed } = opaqueFrame(() => reply);
|
|
110
|
+
const asked = [h(2), h(3), h(4)];
|
|
111
|
+
expect(await describePreviewElements(iframe, asked)).toEqual([described(2), null, null]);
|
|
112
|
+
expect(handed).toHaveBeenCalledWith("describe", { handles: asked });
|
|
113
|
+
reply = { elements: [described(2)] };
|
|
114
|
+
expect(await describePreviewElements(iframe, [h(2), h(3)])).toBeNull();
|
|
115
|
+
handed.mockClear();
|
|
116
|
+
expect(await describePreviewElements(iframe, [])).toBeNull();
|
|
117
|
+
expect(await describePreviewElements(iframe, Array(257).fill(h(1)))).toBeNull();
|
|
118
|
+
expect(handed).not.toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("gives up after the agent probe when the frame's runtime has no editing agent", async () => {
|
|
122
|
+
const { iframe } = opaqueFrame();
|
|
123
|
+
const started = Date.now();
|
|
124
|
+
const answers = await Promise.all([
|
|
125
|
+
previewComputedStyles(iframe, "#a", ["color"]),
|
|
126
|
+
previewElementsAtPoint(iframe, 1, 1),
|
|
127
|
+
describePreviewElements(iframe, [h(1)]),
|
|
128
|
+
]);
|
|
129
|
+
expect(answers).toEqual([null, null, null]);
|
|
130
|
+
expect(Date.now() - started).toBeLessThan(AGENT_PROBE_MS + 500);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("source file and selector index from a description", () => {
|
|
135
|
+
it("answers what Studio reads off the frame's own element", () => {
|
|
136
|
+
setCompositionSourceMap(new Map([["card", "cards.html"]]));
|
|
137
|
+
document.body.innerHTML = `
|
|
138
|
+
<div class="tile"></div>
|
|
139
|
+
<div data-composition-file="cards.html"><div class="tile"></div></div>
|
|
140
|
+
<div data-composition-id="card__hf2" data-hf-original-composition-id="card">
|
|
141
|
+
<div class="tile"></div><div class="tile"></div>
|
|
142
|
+
</div>`;
|
|
143
|
+
const target = document.querySelectorAll<HTMLElement>(".tile")[3]!;
|
|
144
|
+
const element = readPreviewElement(
|
|
145
|
+
described(7, {
|
|
146
|
+
selector: ".tile",
|
|
147
|
+
source: { file: null, compositionId: "card__hf2", originalCompositionId: "card" },
|
|
148
|
+
// As the runtime counts the matches before it: one per distinct source.
|
|
149
|
+
matchesBefore: [
|
|
150
|
+
{ source: NO_SOURCE, count: 1 },
|
|
151
|
+
{ source: { ...NO_SOURCE, file: "cards.html" }, count: 1 },
|
|
152
|
+
{
|
|
153
|
+
source: { file: null, compositionId: "card__hf2", originalCompositionId: "card" },
|
|
154
|
+
count: 1,
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
}),
|
|
158
|
+
) as PreviewElement;
|
|
159
|
+
const { sourceFile } = getSourceFileForElement(target, "index.html");
|
|
160
|
+
expect(previewElementSourceFile(element, "index.html")).toBe(sourceFile);
|
|
161
|
+
expect(sourceFile).toBe("cards.html");
|
|
162
|
+
const index = getSelectorIndex(document, target, ".tile", sourceFile, "index.html");
|
|
163
|
+
expect(previewElementSelectorIndex(element, "index.html")).toBe(index);
|
|
164
|
+
expect(index).toBe(2);
|
|
165
|
+
expect(previewElementSelectorIndex({ ...element, matchesBefore: null }, null)).toBeUndefined();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elements of a preview frame Studio cannot script, by the handles its runtime gives them. A handle
|
|
3
|
+
* names an element for one load of the frame; after the frame loads again, describe it afresh.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
EDITING_ELEMENT_HANDLE,
|
|
7
|
+
MAX_DESCRIBE_HANDLES,
|
|
8
|
+
MAX_ELEMENT_ENTRIES,
|
|
9
|
+
MAX_ELEMENT_VALUE,
|
|
10
|
+
MAX_GEOMETRY_CHILDREN,
|
|
11
|
+
type EditingElementBox,
|
|
12
|
+
type EditingElementDescription,
|
|
13
|
+
type EditingElementGeometry,
|
|
14
|
+
type EditingElementHit,
|
|
15
|
+
type EditingElementMatch,
|
|
16
|
+
type EditingElementSource,
|
|
17
|
+
} from "@hyperframes/core/runtime/editing-port";
|
|
18
|
+
import { resolveElementSourceFile } from "../../components/editor/domEditingDom";
|
|
19
|
+
import { previewRequest } from "./previewChannel";
|
|
20
|
+
|
|
21
|
+
declare const checked: unique symbol;
|
|
22
|
+
/** A description that passed `readPreviewElement`. Only that function makes one. */
|
|
23
|
+
export type PreviewElement = EditingElementDescription & { readonly [checked]: true };
|
|
24
|
+
export type PreviewElementHit = EditingElementHit & { readonly [checked]: true };
|
|
25
|
+
|
|
26
|
+
type Fields = Record<string, unknown>;
|
|
27
|
+
const isFields = (value: unknown): value is Fields =>
|
|
28
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
|
+
const isHandle = (value: unknown) =>
|
|
30
|
+
typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
|
|
31
|
+
const isText = (value: unknown) => typeof value === "string";
|
|
32
|
+
const isTextOrNull = (value: unknown) => value === null || typeof value === "string";
|
|
33
|
+
const isCount = (value: unknown) => Number.isSafeInteger(value) && (value as number) >= 0;
|
|
34
|
+
|
|
35
|
+
const isSource = (value: unknown): value is EditingElementSource =>
|
|
36
|
+
isFields(value) &&
|
|
37
|
+
isTextOrNull(value.file) &&
|
|
38
|
+
isTextOrNull(value.compositionId) &&
|
|
39
|
+
isTextOrNull(value.originalCompositionId);
|
|
40
|
+
|
|
41
|
+
const isTextRecord = (value: unknown) => isFields(value) && Object.values(value).every(isText);
|
|
42
|
+
|
|
43
|
+
function hasPlainFields(value: Fields): boolean {
|
|
44
|
+
const { matchesBefore, attributes, children } = value;
|
|
45
|
+
const groupsOk =
|
|
46
|
+
matchesBefore === null ||
|
|
47
|
+
(Array.isArray(matchesBefore) &&
|
|
48
|
+
matchesBefore.every((g) => isFields(g) && isSource(g.source) && isCount(g.count)));
|
|
49
|
+
const attributesOk =
|
|
50
|
+
Array.isArray(attributes) &&
|
|
51
|
+
attributes.every((a) => Array.isArray(a) && a.length === 2 && a.every(isText));
|
|
52
|
+
const childrenOk =
|
|
53
|
+
Array.isArray(children) &&
|
|
54
|
+
children.every((c) => isFields(c) && (isHandle(c.handle) || isText(c.text)));
|
|
55
|
+
return groupsOk && attributesOk && childrenOk && typeof value.truncated === "boolean";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const isRect = (value: unknown) =>
|
|
59
|
+
isFields(value) && [value.x, value.y, value.width, value.height].every(Number.isFinite);
|
|
60
|
+
|
|
61
|
+
function readHit(value: unknown): PreviewElementHit | null {
|
|
62
|
+
if (!isFields(value) || !isHandle(value.handle) || !isText(value.tag)) return null;
|
|
63
|
+
return isRect(value.rect) ? (value as unknown as PreviewElementHit) : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Frame data checked against `EditingElementDescription`; null when any field is off. */
|
|
67
|
+
export function readPreviewElement(value: unknown): PreviewElement | null {
|
|
68
|
+
if (!readHit(value) || !isFields(value)) return null;
|
|
69
|
+
if (value.parent !== null && !isHandle(value.parent)) return null;
|
|
70
|
+
if (!isTextOrNull(value.id) || !isTextOrNull(value.selector)) return null;
|
|
71
|
+
if (!isSource(value.source) || typeof value.locked !== "boolean") return null;
|
|
72
|
+
if (!isTextRecord(value.inlineStyles) || !isText(value.text)) return null;
|
|
73
|
+
return hasPlainFields(value) ? (value as unknown as PreviewElement) : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The elements under a frame viewport point, topmost first; null when the runtime cannot answer. */
|
|
77
|
+
export async function previewElementsAtPoint(
|
|
78
|
+
iframe: HTMLIFrameElement,
|
|
79
|
+
x: number,
|
|
80
|
+
y: number,
|
|
81
|
+
): Promise<PreviewElementHit[] | null> {
|
|
82
|
+
const reply = await previewRequest(iframe, "elements-at-point", { x, y });
|
|
83
|
+
const elements: unknown = reply?.elements;
|
|
84
|
+
if (!Array.isArray(elements)) return null;
|
|
85
|
+
return elements.map(readHit).filter((element) => element !== null);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function previewPointerTargets(
|
|
89
|
+
iframe: HTMLIFrameElement,
|
|
90
|
+
rootFractionX: number,
|
|
91
|
+
rootFractionY: number,
|
|
92
|
+
): Promise<{ target: PreviewElementHit | null; stack: PreviewElementHit[] } | null> {
|
|
93
|
+
const params = { x: rootFractionX, y: rootFractionY };
|
|
94
|
+
const reply = await previewRequest(iframe, "pointer-targets", params);
|
|
95
|
+
const stack: unknown = reply?.stack;
|
|
96
|
+
if (!reply || !Array.isArray(stack)) return null;
|
|
97
|
+
return { target: readHit(reply.target), stack: stack.map(readHit).filter((hit) => hit !== null) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* One entry per handle, in order: null for an element the frame no longer has. The whole answer is
|
|
102
|
+
* null when the runtime cannot answer, or when there are no handles or more than the runtime takes.
|
|
103
|
+
*/
|
|
104
|
+
export async function describePreviewElements(
|
|
105
|
+
iframe: HTMLIFrameElement,
|
|
106
|
+
handles: readonly string[],
|
|
107
|
+
): Promise<Array<PreviewElement | null> | null> {
|
|
108
|
+
if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
|
|
109
|
+
const reply = await previewRequest(iframe, "describe", { handles: [...handles] });
|
|
110
|
+
const elements: unknown = reply?.elements;
|
|
111
|
+
if (!Array.isArray(elements) || elements.length !== handles.length) return null;
|
|
112
|
+
return elements.map((entry, index) => {
|
|
113
|
+
const element = readPreviewElement(entry);
|
|
114
|
+
return element?.handle === handles[index] ? element : null;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Each handle's ancestors, parent first; null for an element the frame no longer has. */
|
|
119
|
+
export async function previewAncestors(
|
|
120
|
+
iframe: HTMLIFrameElement,
|
|
121
|
+
handles: readonly string[],
|
|
122
|
+
): Promise<Array<string[] | null> | null> {
|
|
123
|
+
if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
|
|
124
|
+
const reply = await previewRequest(iframe, "ancestors", { handles: [...handles] });
|
|
125
|
+
const chains: unknown = reply?.ancestors;
|
|
126
|
+
if (!Array.isArray(chains) || chains.length !== handles.length) return null;
|
|
127
|
+
return chains.map((chain) =>
|
|
128
|
+
Array.isArray(chain) && chain.every(isHandle) ? (chain as string[]) : null,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The frame's matches for `selector` in document order; null when the runtime cannot answer. */
|
|
133
|
+
export async function queryPreviewElements(
|
|
134
|
+
iframe: HTMLIFrameElement,
|
|
135
|
+
selector: string,
|
|
136
|
+
): Promise<{ matches: EditingElementMatch[]; truncated: boolean } | null> {
|
|
137
|
+
const reply = await previewRequest(iframe, "query", { selector });
|
|
138
|
+
const matches: unknown = reply?.matches;
|
|
139
|
+
if (!Array.isArray(matches) || typeof reply?.truncated !== "boolean") return null;
|
|
140
|
+
const ok = matches.every((m) => isFields(m) && isHandle(m.handle) && isSource(m.source));
|
|
141
|
+
return ok ? { matches: matches as EditingElementMatch[], truncated: reply.truncated } : null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** `getSourceFileForElement` for the frame's own element. */
|
|
145
|
+
export function previewElementSourceFile(
|
|
146
|
+
element: PreviewElement,
|
|
147
|
+
activeCompositionPath: string | null,
|
|
148
|
+
): string {
|
|
149
|
+
return resolveElementSourceFile(element.source, activeCompositionPath);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** `getSelectorIndex` for the frame's own element; undefined when the runtime could not count. */
|
|
153
|
+
export function previewElementSelectorIndex(
|
|
154
|
+
element: PreviewElement,
|
|
155
|
+
activeCompositionPath: string | null,
|
|
156
|
+
): number | undefined {
|
|
157
|
+
if (!element.selector?.startsWith(".") || !element.matchesBefore) return undefined;
|
|
158
|
+
const file = previewElementSourceFile(element, activeCompositionPath);
|
|
159
|
+
return element.matchesBefore
|
|
160
|
+
.filter((group) => resolveElementSourceFile(group.source, activeCompositionPath) === file)
|
|
161
|
+
.reduce((sum, group) => sum + group.count, 0);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isPoint = (value: unknown) =>
|
|
165
|
+
isFields(value) && Number.isFinite(value.x) && Number.isFinite(value.y);
|
|
166
|
+
const isSizeOrNull = (value: unknown) =>
|
|
167
|
+
value === null || (Number.isFinite(value) && (value as number) > 0);
|
|
168
|
+
|
|
169
|
+
const CORNERS = ["nw", "ne", "se", "sw"] as const;
|
|
170
|
+
const isCorners = (value: unknown) =>
|
|
171
|
+
value === null || (isFields(value) && CORNERS.every((corner) => isPoint(value[corner])));
|
|
172
|
+
|
|
173
|
+
const isSourceBox = (value: unknown) =>
|
|
174
|
+
value === null ||
|
|
175
|
+
(isFields(value) &&
|
|
176
|
+
Number.isFinite(value.width) &&
|
|
177
|
+
Number.isFinite(value.height) &&
|
|
178
|
+
isSizeOrNull(value.declaredWidth) &&
|
|
179
|
+
isSizeOrNull(value.declaredHeight));
|
|
180
|
+
|
|
181
|
+
const isClipPath = (value: unknown) =>
|
|
182
|
+
value === null || (isText(value) && (value as string).length <= MAX_ELEMENT_VALUE);
|
|
183
|
+
|
|
184
|
+
const isBox = (value: unknown): value is EditingElementBox =>
|
|
185
|
+
isFields(value) &&
|
|
186
|
+
isRect(value.rect) &&
|
|
187
|
+
Number.isFinite(value.angle) &&
|
|
188
|
+
isCorners(value.corners) &&
|
|
189
|
+
isSourceBox(value.source) &&
|
|
190
|
+
isClipPath(value.clipPath);
|
|
191
|
+
|
|
192
|
+
const readGeometry = (value: unknown): EditingElementGeometry | null => {
|
|
193
|
+
if (!isBox(value) || !isFields(value) || typeof value.visible !== "boolean") return null;
|
|
194
|
+
const { members } = value;
|
|
195
|
+
const membersOk =
|
|
196
|
+
members === null ||
|
|
197
|
+
(Array.isArray(members) && members.length <= MAX_ELEMENT_ENTRIES && members.every(isRect));
|
|
198
|
+
return membersOk ? (value as unknown as EditingElementGeometry) : null;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export interface PreviewGeometry {
|
|
202
|
+
/** One entry per handle, in order: null for an element the frame no longer has. */
|
|
203
|
+
elements: Array<EditingElementGeometry | null>;
|
|
204
|
+
/** The `children` element's descendants, when it has 1 to MAX_GEOMETRY_CHILDREN; else empty. */
|
|
205
|
+
children: EditingElementBox[] | null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Overlay geometry for `handles`, and `children`'s descendant boxes; null when the runtime cannot answer. */
|
|
209
|
+
export async function previewGeometry(
|
|
210
|
+
iframe: HTMLIFrameElement,
|
|
211
|
+
handles: readonly string[],
|
|
212
|
+
children?: string,
|
|
213
|
+
): Promise<PreviewGeometry | null> {
|
|
214
|
+
if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
|
|
215
|
+
const params = { handles: [...handles], ...(children ? { children } : {}) };
|
|
216
|
+
const reply = await previewRequest(iframe, "geometry", params);
|
|
217
|
+
const elements: unknown = reply?.elements;
|
|
218
|
+
if (!Array.isArray(elements) || elements.length !== handles.length) return null;
|
|
219
|
+
const boxes: unknown = reply?.children;
|
|
220
|
+
const childrenOk =
|
|
221
|
+
Array.isArray(boxes) && boxes.length <= MAX_GEOMETRY_CHILDREN && boxes.every(isBox);
|
|
222
|
+
return {
|
|
223
|
+
elements: elements.map(readGeometry),
|
|
224
|
+
children: children && childrenOk ? (boxes as EditingElementBox[]) : null,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"total":
|
|
2
|
+
"total": 223,
|
|
3
3
|
"files": {
|
|
4
4
|
"packages/studio/src/captions/components/CaptionOverlay.tsx": 5,
|
|
5
5
|
"packages/studio/src/captions/components/CaptionTimeline.tsx": 11,
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"packages/studio/src/components/editor/SnapGuideOverlay.tsx": 3,
|
|
19
19
|
"packages/studio/src/components/editor/Transform3DCube.tsx": 5,
|
|
20
20
|
"packages/studio/src/components/editor/colorValue.ts": 3,
|
|
21
|
-
"packages/studio/src/components/editor/domEditingElement.ts": 1,
|
|
22
21
|
"packages/studio/src/components/editor/gradientValue.ts": 6,
|
|
23
22
|
"packages/studio/src/components/editor/panelTokens.ts": 4,
|
|
24
23
|
"packages/studio/src/components/editor/propertyPanelColor.tsx": 7,
|
|
@@ -103,19 +103,6 @@ export function isManualGeometryStyleProperty(property: string): boolean {
|
|
|
103
103
|
return property === "left" || property === "top" || property === "width" || property === "height";
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
export function getEventTargetElement(target: EventTarget | null): HTMLElement | null {
|
|
107
|
-
if (!target || typeof target !== "object") return null;
|
|
108
|
-
const maybeNode = target as {
|
|
109
|
-
nodeType?: number;
|
|
110
|
-
parentElement?: Element | null;
|
|
111
|
-
};
|
|
112
|
-
if (maybeNode.nodeType === 1) return target as HTMLElement;
|
|
113
|
-
if (maybeNode.nodeType === 3 && maybeNode.parentElement) {
|
|
114
|
-
return maybeNode.parentElement as HTMLElement;
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
106
|
export function shouldIgnoreHistoryShortcut(target: EventTarget | null): boolean {
|
|
120
107
|
return isTypingTarget(target);
|
|
121
108
|
}
|
|
@@ -138,7 +138,7 @@ describe("getPreviewTargetFromPointer", () => {
|
|
|
138
138
|
stubRect(headline, domRect(44, 44, 220, 48));
|
|
139
139
|
doc.elementsFromPoint = () => [headline, mask, block, scene];
|
|
140
140
|
|
|
141
|
-
expect(getPreviewTargetFromPointer(iframe, 80, 64
|
|
141
|
+
expect(getPreviewTargetFromPointer(iframe, 80, 64)).toBe(headline);
|
|
142
142
|
iframe.remove();
|
|
143
143
|
});
|
|
144
144
|
|
|
@@ -156,12 +156,12 @@ describe("getPreviewTargetFromPointer", () => {
|
|
|
156
156
|
return [headline, scene];
|
|
157
157
|
};
|
|
158
158
|
// First call runs the once-per-document inheritance probe, a body mutation.
|
|
159
|
-
expect(getPreviewTargetFromPointer(iframe, 80, 64
|
|
159
|
+
expect(getPreviewTargetFromPointer(iframe, 80, 64)).toBe(headline);
|
|
160
160
|
const observer = new MutationObserver(() => {});
|
|
161
161
|
observer.observe(doc, { subtree: true, childList: true, attributes: true });
|
|
162
162
|
|
|
163
|
-
expect(getPreviewTargetFromPointer(iframe, 80, 64
|
|
164
|
-
expect(getAllPreviewTargetsFromPointer(iframe, 80, 64
|
|
163
|
+
expect(getPreviewTargetFromPointer(iframe, 80, 64)).toBe(headline);
|
|
164
|
+
expect(getAllPreviewTargetsFromPointer(iframe, 80, 64)).toEqual([headline]);
|
|
165
165
|
const mutations = observer.takeRecords();
|
|
166
166
|
observer.disconnect();
|
|
167
167
|
|
|
@@ -197,7 +197,7 @@ describe("getPreviewTargetFromPointer", () => {
|
|
|
197
197
|
stubRect(overlay, domRect(0, 0, 360, 260));
|
|
198
198
|
doc.elementsFromPoint = () => [overlay, overlayParent, headline, scene];
|
|
199
199
|
|
|
200
|
-
expect(getPreviewTargetFromPointer(iframe, 80, 64
|
|
200
|
+
expect(getPreviewTargetFromPointer(iframe, 80, 64)).toBe(headline);
|
|
201
201
|
|
|
202
202
|
iframe.remove();
|
|
203
203
|
});
|
|
@@ -227,7 +227,7 @@ describe("getPreviewTargetFromPointer", () => {
|
|
|
227
227
|
stubRect(clickableChild, domRect(40, 40, 80, 24));
|
|
228
228
|
doc.elementsFromPoint = () => [clickableChild, overlayParent, scene];
|
|
229
229
|
|
|
230
|
-
expect(getPreviewTargetFromPointer(iframe, 60, 50
|
|
230
|
+
expect(getPreviewTargetFromPointer(iframe, 60, 50)).toBe(clickableChild);
|
|
231
231
|
|
|
232
232
|
iframe.remove();
|
|
233
233
|
});
|
|
@@ -256,7 +256,7 @@ describe("getPreviewTargetFromPointer", () => {
|
|
|
256
256
|
|
|
257
257
|
// Before the fix the video was full-bleed-excluded and the picker fell through
|
|
258
258
|
// to the backdrop (or null). It must now return the video itself.
|
|
259
|
-
expect(getPreviewTargetFromPointer(iframe, 200, 150
|
|
259
|
+
expect(getPreviewTargetFromPointer(iframe, 200, 150)).toBe(hero);
|
|
260
260
|
|
|
261
261
|
iframe.remove();
|
|
262
262
|
});
|
|
@@ -281,7 +281,7 @@ describe("getPreviewTargetFromPointer", () => {
|
|
|
281
281
|
stubRect(headline, domRect(40, 40, 160, 48));
|
|
282
282
|
doc.elementsFromPoint = () => [headline, wrapper, scene];
|
|
283
283
|
|
|
284
|
-
expect(getPreviewTargetFromPointer(iframe, 80, 64
|
|
284
|
+
expect(getPreviewTargetFromPointer(iframe, 80, 64)).toBe(headline);
|
|
285
285
|
|
|
286
286
|
iframe.remove();
|
|
287
287
|
});
|