@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
package/dist/player.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.41",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"dockview-react": "8.3.1",
|
|
65
65
|
"gsap": "^3.13.0",
|
|
66
66
|
"mediabunny": "^1.65.2",
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/
|
|
69
|
-
"@hyperframes/
|
|
70
|
-
"@hyperframes/
|
|
71
|
-
"@hyperframes/shader-transitions": "0.9.
|
|
72
|
-
"@hyperframes/studio-server": "0.9.
|
|
67
|
+
"@hyperframes/core": "0.9.41",
|
|
68
|
+
"@hyperframes/parsers": "0.9.41",
|
|
69
|
+
"@hyperframes/player": "0.9.41",
|
|
70
|
+
"@hyperframes/sdk": "0.9.41",
|
|
71
|
+
"@hyperframes/shader-transitions": "0.9.41",
|
|
72
|
+
"@hyperframes/studio-server": "0.9.41"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"vite": "^6.4.2",
|
|
87
87
|
"vitest": "^4.1.11",
|
|
88
88
|
"zustand": "^5.0.0",
|
|
89
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.41"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "19",
|
|
@@ -38,6 +38,7 @@ import { useMountEffect } from "../../hooks/useMountEffect";
|
|
|
38
38
|
import { countStudioManualEditSave as counted } from "./manualEditsDom";
|
|
39
39
|
import type { ZOrderAction, ZOrderPatch } from "./canvasContextMenuZOrder";
|
|
40
40
|
import { getPreviewTargetFromPointer } from "../../utils/studioPreviewHelpers";
|
|
41
|
+
import { pointerMayHitElement } from "./previewSelection";
|
|
41
42
|
import { logSelect } from "../../utils/selectDebug";
|
|
42
43
|
import { useOffCanvasIndicators } from "./useOffCanvasIndicators";
|
|
43
44
|
import { DomEditGestureReadout } from "./DomEditGestureReadout";
|
|
@@ -382,12 +383,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({
|
|
|
382
383
|
const candidate = resolveShiftClickCandidate({
|
|
383
384
|
cached: hoverSelectionRef.current,
|
|
384
385
|
elementAtPoint: shiftIframe
|
|
385
|
-
? getPreviewTargetFromPointer(
|
|
386
|
-
shiftIframe,
|
|
387
|
-
event.clientX,
|
|
388
|
-
event.clientY,
|
|
389
|
-
activeCompositionPathRef.current,
|
|
390
|
-
)
|
|
386
|
+
? getPreviewTargetFromPointer(shiftIframe, event.clientX, event.clientY)
|
|
391
387
|
: null,
|
|
392
388
|
});
|
|
393
389
|
// Not confident: fall through untouched — no preventDefault, no suppression —
|
|
@@ -421,15 +417,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({
|
|
|
421
417
|
// Confirm emptiness with a fresh SYNCHRONOUS hit-test before committing.
|
|
422
418
|
if (!hoverSelectionRef.current && onMarqueeSelectRef.current && compRect.width > 0) {
|
|
423
419
|
const iframe = iframeRef.current;
|
|
424
|
-
|
|
425
|
-
? getPreviewTargetFromPointer(
|
|
426
|
-
iframe,
|
|
427
|
-
event.clientX,
|
|
428
|
-
event.clientY,
|
|
429
|
-
activeCompositionPathRef.current,
|
|
430
|
-
)
|
|
431
|
-
: null;
|
|
432
|
-
if (freshTarget) return;
|
|
420
|
+
if (iframe && pointerMayHitElement(iframe, event.clientX, event.clientY)) return;
|
|
433
421
|
if (overlayRef.current) {
|
|
434
422
|
// Anywhere empty on the overlay starts one, not just inside the frame.
|
|
435
423
|
// An element dragged past the edge sits OUT there in the grey, and a
|
|
@@ -47,11 +47,12 @@ function mount() {
|
|
|
47
47
|
function render(
|
|
48
48
|
hoverSelection: DomEditSelection | null,
|
|
49
49
|
selection: DomEditSelection | null = null,
|
|
50
|
+
iframe = document.createElement("iframe"),
|
|
50
51
|
) {
|
|
51
52
|
act(() =>
|
|
52
53
|
root.render(
|
|
53
54
|
<DomEditOverlay
|
|
54
|
-
iframeRef={{ current:
|
|
55
|
+
iframeRef={{ current: iframe }}
|
|
55
56
|
activeCompositionPath={null}
|
|
56
57
|
selection={selection}
|
|
57
58
|
hoverSelection={hoverSelection}
|
|
@@ -120,3 +121,18 @@ it("a shift+click on a selected box that cannot move toggles it once", () => {
|
|
|
120
121
|
expect(onSelectionChange).toHaveBeenCalledTimes(1);
|
|
121
122
|
expect(onCanvasMouseDown).not.toHaveBeenCalled();
|
|
122
123
|
});
|
|
124
|
+
|
|
125
|
+
it("on a frame Studio cannot script, a press with no pointer answer yet selects, not starts a band", () => {
|
|
126
|
+
const { host } = mount();
|
|
127
|
+
const frame = {};
|
|
128
|
+
Object.defineProperty(frame, "document", {
|
|
129
|
+
get: () => {
|
|
130
|
+
throw new DOMException("blocked", "SecurityError");
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
const opaque = document.createElement("iframe");
|
|
134
|
+
Object.defineProperty(opaque, "contentWindow", { value: frame });
|
|
135
|
+
render(null, null, opaque);
|
|
136
|
+
press(host.firstElementChild!);
|
|
137
|
+
expect(onCanvasMouseDown).toHaveBeenCalledTimes(1);
|
|
138
|
+
});
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* Its own module because it is the one piece of that file every other piece
|
|
12
12
|
* depends on and nothing in it is about a single element's geometry.
|
|
13
13
|
*/
|
|
14
|
+
import { previewStageSize } from "../../player/lib/bridgePlayback";
|
|
15
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
14
16
|
|
|
15
17
|
/** iframe→overlay mapping basis shared by every overlay-geometry function. */
|
|
16
18
|
export interface OverlayRootScale {
|
|
@@ -52,7 +54,8 @@ function resolveRootDimensions(root: HTMLElement | null): { width: number; heigh
|
|
|
52
54
|
* instead of rootRect.width/height: when GSAP applies transforms (scale,
|
|
53
55
|
* translate) to the root, rootRect dimensions change but the composition's
|
|
54
56
|
* canonical size stays fixed, and using rootRect misaligns the overlay during
|
|
55
|
-
* animated playback.
|
|
57
|
+
* animated playback. A frame Studio cannot script is scaled by the size its
|
|
58
|
+
* runtime posts. Returns null when the geometry is unmeasurable.
|
|
56
59
|
*/
|
|
57
60
|
export function computeOverlayRootScale(
|
|
58
61
|
overlayEl: HTMLDivElement,
|
|
@@ -61,7 +64,9 @@ export function computeOverlayRootScale(
|
|
|
61
64
|
): OverlayRootScale | null {
|
|
62
65
|
const iframeRect = iframe.getBoundingClientRect();
|
|
63
66
|
const overlayRect = overlayEl.getBoundingClientRect();
|
|
64
|
-
const dims =
|
|
67
|
+
const dims = previewFrameOpaque(iframe)
|
|
68
|
+
? previewStageSize(iframe)
|
|
69
|
+
: resolveRootDimensions(findOverlayRootElement(doc));
|
|
65
70
|
if (!dims) return null;
|
|
66
71
|
return {
|
|
67
72
|
iframeRect,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
resolveCropInsetFromMoveDrag,
|
|
9
9
|
rotateDeltaIntoFrame,
|
|
10
10
|
} from "./domEditOverlayCrop";
|
|
11
|
-
import { individualRotateDegrees } from "
|
|
11
|
+
import { individualRotateDegrees } from "@hyperframes/core/runtime/editing-port";
|
|
12
12
|
|
|
13
13
|
describe("resolveCropInsetFromEdgeDrag", () => {
|
|
14
14
|
const startInsets = { top: 10, right: 20, bottom: 30, left: 40 };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
composeElementTransform,
|
|
3
|
+
type PlanarTransformOps,
|
|
4
|
+
} from "@hyperframes/core/runtime/editing-port";
|
|
2
5
|
import {
|
|
3
6
|
parseInsetClipPathSides,
|
|
4
7
|
type ClipPathInsetSides,
|
|
@@ -167,8 +170,19 @@ export function hugRectForElement(
|
|
|
167
170
|
rect: CropScreenRect & { editScaleX: number; editScaleY: number },
|
|
168
171
|
element: HTMLElement,
|
|
169
172
|
): CropScreenRect {
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
// A lifted clip shows the full element rect.
|
|
174
|
+
return isElementCropLifted(element)
|
|
175
|
+
? rect
|
|
176
|
+
: hugRectForClipPath(rect, readElementClipPath(element));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** `hugRectForElement` for a clip-path read elsewhere; null is one that could not be read. */
|
|
180
|
+
export function hugRectForClipPath(
|
|
181
|
+
rect: CropScreenRect & { editScaleX: number; editScaleY: number },
|
|
182
|
+
clipPath: string | null,
|
|
183
|
+
): CropScreenRect {
|
|
184
|
+
const insets = clipPath === null ? null : parseCropClipPath(clipPath);
|
|
185
|
+
// Uneditable clip — show the full element rect.
|
|
172
186
|
if (!insets || (insets.top <= 0 && insets.right <= 0 && insets.bottom <= 0 && insets.left <= 0))
|
|
173
187
|
return rect;
|
|
174
188
|
return cropRectFromInsets(rect, insets, rect.editScaleX, rect.editScaleY);
|
|
@@ -6,7 +6,14 @@ import {
|
|
|
6
6
|
} from "./domEditOverlayBasis";
|
|
7
7
|
import { isElementVisibleThroughAncestors } from "./domEditingDom";
|
|
8
8
|
import { hugRectForElement } from "./domEditOverlayCrop";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
elementCornerPoints,
|
|
11
|
+
readElementTransformSnapshot,
|
|
12
|
+
rotationDegreesFromMatrix,
|
|
13
|
+
ROTATION_GATE_EPSILON_DEG,
|
|
14
|
+
type EditingCorners,
|
|
15
|
+
type ElementTransformSnapshot,
|
|
16
|
+
} from "@hyperframes/core/runtime/editing-port";
|
|
10
17
|
import { type OverlayMeasurePass, readThroughPass } from "./domEditOverlayMeasurePass";
|
|
11
18
|
|
|
12
19
|
export const RESIZE_HANDLE_HIT_PX = 16;
|
|
@@ -134,95 +141,6 @@ export function toVisibleOverlayRects(
|
|
|
134
141
|
});
|
|
135
142
|
}
|
|
136
143
|
|
|
137
|
-
/**
|
|
138
|
-
* getComputedStyle(element).transform decomposed into a DOMMatrix, read ONCE.
|
|
139
|
-
* Shared by orientedOverlayRect's rotation gate and elementCornerOverlayPoints
|
|
140
|
-
* so a single measurement pass serves both — constructing this twice per frame
|
|
141
|
-
* (one read per consumer) was redundant work; see orientedOverlayRect below.
|
|
142
|
-
*/
|
|
143
|
-
interface ElementTransformSnapshot {
|
|
144
|
-
matrix: DOMMatrix;
|
|
145
|
-
cs: CSSStyleDeclaration;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* The transform from the element's own box to the composition's, ACCUMULATED
|
|
150
|
-
* over its ancestors rather than read from the element alone.
|
|
151
|
-
*
|
|
152
|
-
* What the user sees is the product of every transform between the element and
|
|
153
|
-
* the composition root, and an element is routinely a child of something
|
|
154
|
-
* scaled or rotated. Reading only its own transform drew the selection box at
|
|
155
|
-
* the element's untransformed size: a text layer inside a card carrying
|
|
156
|
-
* `scale(1.2)` got a box at 1/1.2 of the text, with the top-left correct (the
|
|
157
|
-
* caller anchors that to the real bounding rect) and the right and bottom
|
|
158
|
-
* edges falling short. The same read decides whether to draw the box rotated,
|
|
159
|
-
* so an element inside a rotated parent got an upright box too.
|
|
160
|
-
*
|
|
161
|
-
* Only the linear part matters here. Each transform's origin contributes
|
|
162
|
-
* translation, and the caller discards translation by matching the corners'
|
|
163
|
-
* bounding box to the element's real one, so composing the matrices alone is
|
|
164
|
-
* enough and there is no per-ancestor origin to unpick.
|
|
165
|
-
*
|
|
166
|
-
* The walk stops at the composition document's root. The canvas zoom lives on
|
|
167
|
-
* the iframe element in Studio's own document and is applied separately by
|
|
168
|
-
* `computeOverlayRootScale`; including it here would count it twice.
|
|
169
|
-
*/
|
|
170
|
-
function readElementTransformSnapshot(
|
|
171
|
-
win: Window,
|
|
172
|
-
element: HTMLElement,
|
|
173
|
-
pass?: OverlayMeasurePass,
|
|
174
|
-
): ElementTransformSnapshot | null {
|
|
175
|
-
const DOMMatrixCtor = (win as Window & typeof globalThis).DOMMatrix;
|
|
176
|
-
if (!DOMMatrixCtor) return null;
|
|
177
|
-
const cs = win.getComputedStyle(element);
|
|
178
|
-
// The corner math transforms points, so this algebra keeps the full matrix,
|
|
179
|
-
// translation included, where the crop frame's keeps only 2D components.
|
|
180
|
-
const ops: PlanarTransformOps<DOMMatrix> = {
|
|
181
|
-
identity: () => new DOMMatrixCtor(),
|
|
182
|
-
fromTransform: (value) => new DOMMatrixCtor(value),
|
|
183
|
-
fromRotate: (degrees) => new DOMMatrixCtor().rotateSelf(degrees),
|
|
184
|
-
compose: (outer, inner) => outer.multiply(inner),
|
|
185
|
-
};
|
|
186
|
-
try {
|
|
187
|
-
const matrix = composeElementTransform(
|
|
188
|
-
element,
|
|
189
|
-
ops,
|
|
190
|
-
(node) => (node === element ? cs : win.getComputedStyle(node)),
|
|
191
|
-
pass?.transform,
|
|
192
|
-
);
|
|
193
|
-
return matrix ? { matrix, cs } : null;
|
|
194
|
-
} catch {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* The element's live transform rotation, in DEGREES (screen/CSS convention, CW
|
|
201
|
-
* positive), decomposed from its transform matrix (rotation = atan2(b, a)).
|
|
202
|
-
* GSAP folds rotation and scale into the same matrix; this reads rotation only.
|
|
203
|
-
* Skew is ignored (does not affect atan2(b, a)).
|
|
204
|
-
*/
|
|
205
|
-
function rotationDegreesFromMatrix(matrix: DOMMatrix): number {
|
|
206
|
-
const a = Number.isFinite(matrix.a) ? matrix.a : 1;
|
|
207
|
-
const b = Number.isFinite(matrix.b) ? matrix.b : 0;
|
|
208
|
-
const c = Number.isFinite(matrix.c) ? matrix.c : 0;
|
|
209
|
-
const d = Number.isFinite(matrix.d) ? matrix.d : 1;
|
|
210
|
-
const fromX = (Math.atan2(b, a) * 180) / Math.PI;
|
|
211
|
-
const determinant = a * d - b * c;
|
|
212
|
-
// A reflection makes one basis direction read 180° away from the authored
|
|
213
|
-
// rotation. For cursor/handle orientation those directions are equivalent;
|
|
214
|
-
// choose the representative nearest zero instead of drawing a pure mirror's
|
|
215
|
-
// rotate handle on the opposite side of the element.
|
|
216
|
-
const fromY = (Math.atan2(-c, d) * 180) / Math.PI;
|
|
217
|
-
const deg = determinant < 0 && Math.abs(fromY) < Math.abs(fromX) ? fromY : fromX;
|
|
218
|
-
return Number.isFinite(deg) ? deg : 0;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/** Below this, orientedOverlayRect treats the element as unrotated and returns
|
|
222
|
-
* the AABB directly (see its doc comment) — tight enough to only swallow
|
|
223
|
-
* matrix-decomposition floating-point noise, never an actual rotation. */
|
|
224
|
-
const ROTATION_GATE_EPSILON_DEG = 1e-4;
|
|
225
|
-
|
|
226
144
|
function toOverlayRect(
|
|
227
145
|
overlayEl: HTMLDivElement,
|
|
228
146
|
iframe: HTMLIFrameElement,
|
|
@@ -233,7 +151,6 @@ function toOverlayRect(
|
|
|
233
151
|
const scale =
|
|
234
152
|
precomputedScale ?? computeOverlayRootScale(overlayEl, iframe, iframe.contentDocument);
|
|
235
153
|
if (!scale) return null;
|
|
236
|
-
const { iframeRect, overlayRect, rootScaleX, rootScaleY } = scale;
|
|
237
154
|
|
|
238
155
|
const elementRect = element.getBoundingClientRect();
|
|
239
156
|
const sourceBoundary = findSourceBoundary(element, pass);
|
|
@@ -245,13 +162,35 @@ function toOverlayRect(
|
|
|
245
162
|
sourceBoundary.getBoundingClientRect(),
|
|
246
163
|
)
|
|
247
164
|
: sourceBoundary?.getBoundingClientRect();
|
|
165
|
+
return frameRectToOverlay(scale, elementRect, {
|
|
166
|
+
width: sourceBoundaryRect?.width,
|
|
167
|
+
height: sourceBoundaryRect?.height,
|
|
168
|
+
declaredWidth: readPositiveDimension(sourceBoundary?.getAttribute("data-width") ?? null),
|
|
169
|
+
declaredHeight: readPositiveDimension(sourceBoundary?.getAttribute("data-height") ?? null),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
type FrameSource = {
|
|
174
|
+
width?: number;
|
|
175
|
+
height?: number;
|
|
176
|
+
declaredWidth: number | null;
|
|
177
|
+
declaredHeight: number | null;
|
|
178
|
+
} | null;
|
|
179
|
+
|
|
180
|
+
/** A client rect measured in the frame, and its source boundary's, in overlay coordinates. */
|
|
181
|
+
export function frameRectToOverlay(
|
|
182
|
+
scale: OverlayRootScale,
|
|
183
|
+
elementRect: { left: number; top: number; width: number; height: number },
|
|
184
|
+
source: FrameSource,
|
|
185
|
+
): OverlayRect {
|
|
186
|
+
const { iframeRect, overlayRect, rootScaleX, rootScaleY } = scale;
|
|
248
187
|
const editScale = resolveDomEditCoordinateScale({
|
|
249
188
|
rootScaleX,
|
|
250
189
|
rootScaleY,
|
|
251
|
-
sourceRectWidth:
|
|
252
|
-
sourceRectHeight:
|
|
253
|
-
sourceWidth:
|
|
254
|
-
sourceHeight:
|
|
190
|
+
sourceRectWidth: source?.width,
|
|
191
|
+
sourceRectHeight: source?.height,
|
|
192
|
+
sourceWidth: source?.declaredWidth,
|
|
193
|
+
sourceHeight: source?.declaredHeight,
|
|
255
194
|
});
|
|
256
195
|
|
|
257
196
|
return {
|
|
@@ -264,6 +203,23 @@ function toOverlayRect(
|
|
|
264
203
|
};
|
|
265
204
|
}
|
|
266
205
|
|
|
206
|
+
/** Corners measured in the frame's viewport px, in overlay coordinates. */
|
|
207
|
+
export function frameCornersToOverlay(
|
|
208
|
+
{ iframeRect, overlayRect, rootScaleX, rootScaleY }: OverlayRootScale,
|
|
209
|
+
corners: EditingCorners,
|
|
210
|
+
): Record<FixedCorner, { x: number; y: number }> {
|
|
211
|
+
const toOverlay = (pt: { x: number; y: number }): { x: number; y: number } => ({
|
|
212
|
+
x: iframeRect.left - overlayRect.left + pt.x * rootScaleX,
|
|
213
|
+
y: iframeRect.top - overlayRect.top + pt.y * rootScaleY,
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
nw: toOverlay(corners.nw),
|
|
217
|
+
ne: toOverlay(corners.ne),
|
|
218
|
+
se: toOverlay(corners.se),
|
|
219
|
+
sw: toOverlay(corners.sw),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
267
223
|
/** Which physical corner of the (possibly rotated) element a resize handle keeps
|
|
268
224
|
* fixed: NW grabs the top-left, so the bottom-right (se) is the anchor, etc. */
|
|
269
225
|
export type FixedCorner = "nw" | "ne" | "sw" | "se";
|
|
@@ -309,55 +265,15 @@ export function elementCornerOverlayPoints(
|
|
|
309
265
|
const win = iframe.contentWindow;
|
|
310
266
|
const doc = iframe.contentDocument;
|
|
311
267
|
if (!win || !doc) return null;
|
|
312
|
-
|
|
313
|
-
if (!DOMPointCtor) return null;
|
|
268
|
+
if (!(win as Window & typeof globalThis).DOMPoint) return null;
|
|
314
269
|
|
|
315
270
|
const scale = precomputedScale ?? computeOverlayRootScale(overlayEl, iframe, doc);
|
|
316
271
|
if (!scale) return null;
|
|
317
|
-
const { iframeRect, overlayRect, rootScaleX, rootScaleY } = scale;
|
|
318
272
|
|
|
319
|
-
// The element's local border box maps to viewport coords by the SAME transform
|
|
320
|
-
// matrix the browser used for its BCR. We recover the transform's screen-space
|
|
321
|
-
// action from the BCR: transformPoint(localCorner - origin) gives a corner
|
|
322
|
-
// RELATIVE to the transformed origin. We anchor those relative corners to the
|
|
323
|
-
// BCR by matching the AABB of the transformed corners to the real BCR — the
|
|
324
|
-
// constant offset cancels in the before/after difference the caller takes, but
|
|
325
|
-
// we resolve it fully here so callers can also read absolute overlay positions.
|
|
326
273
|
const transform = precomputedTransform ?? readElementTransformSnapshot(win, element);
|
|
327
274
|
if (!transform) return null;
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
const h = element.offsetHeight;
|
|
331
|
-
const originParts = cs.transformOrigin.split(" ").map((p) => Number.parseFloat(p));
|
|
332
|
-
const ox = Number.isFinite(originParts[0]!) ? originParts[0]! : w / 2;
|
|
333
|
-
const oy = Number.isFinite(originParts[1]!) ? originParts[1]! : h / 2;
|
|
334
|
-
const rel = (lx: number, ly: number): { x: number; y: number } => {
|
|
335
|
-
const p = matrix.transformPoint(new DOMPointCtor(lx - ox, ly - oy));
|
|
336
|
-
return { x: p.x, y: p.y };
|
|
337
|
-
};
|
|
338
|
-
const relCorners = {
|
|
339
|
-
nw: rel(0, 0),
|
|
340
|
-
ne: rel(w, 0),
|
|
341
|
-
se: rel(w, h),
|
|
342
|
-
sw: rel(0, h),
|
|
343
|
-
};
|
|
344
|
-
// Recover the absolute viewport position by matching to the element's BCR:
|
|
345
|
-
// the relative corners' AABB min corresponds to the BCR's top-left.
|
|
346
|
-
const xs = [relCorners.nw.x, relCorners.ne.x, relCorners.se.x, relCorners.sw.x];
|
|
347
|
-
const ys = [relCorners.nw.y, relCorners.ne.y, relCorners.se.y, relCorners.sw.y];
|
|
348
|
-
const bcr = element.getBoundingClientRect();
|
|
349
|
-
const dx = bcr.left - Math.min(...xs);
|
|
350
|
-
const dy = bcr.top - Math.min(...ys);
|
|
351
|
-
const toOverlay = (pt: { x: number; y: number }): { x: number; y: number } => ({
|
|
352
|
-
x: iframeRect.left - overlayRect.left + (pt.x + dx) * rootScaleX,
|
|
353
|
-
y: iframeRect.top - overlayRect.top + (pt.y + dy) * rootScaleY,
|
|
354
|
-
});
|
|
355
|
-
return {
|
|
356
|
-
nw: toOverlay(relCorners.nw),
|
|
357
|
-
ne: toOverlay(relCorners.ne),
|
|
358
|
-
se: toOverlay(relCorners.se),
|
|
359
|
-
sw: toOverlay(relCorners.sw),
|
|
360
|
-
};
|
|
275
|
+
const corners = elementCornerPoints(win, element, transform);
|
|
276
|
+
return corners && frameCornersToOverlay(scale, corners);
|
|
361
277
|
}
|
|
362
278
|
|
|
363
279
|
/**
|
|
@@ -397,11 +313,20 @@ export function orientedOverlayRect(
|
|
|
397
313
|
if (!base) return null;
|
|
398
314
|
|
|
399
315
|
const win = iframe.contentWindow;
|
|
400
|
-
const transform = win ? readElementTransformSnapshot(win, element, pass) : null;
|
|
316
|
+
const transform = win ? readElementTransformSnapshot(win, element, pass?.transform) : null;
|
|
401
317
|
const angle = transform ? rotationDegreesFromMatrix(transform.matrix) : 0;
|
|
402
318
|
if (Math.abs(angle) < ROTATION_GATE_EPSILON_DEG) return base;
|
|
403
319
|
|
|
404
320
|
const corners = elementCornerOverlayPoints(overlayEl, iframe, element, scale, transform);
|
|
321
|
+
return orientOverlayRect(base, angle, corners);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The oriented box whose corners are `corners`, at `angle`; `base` when they cannot describe one. */
|
|
325
|
+
export function orientOverlayRect(
|
|
326
|
+
base: OverlayRect,
|
|
327
|
+
angle: number,
|
|
328
|
+
corners: Record<FixedCorner, { x: number; y: number }> | null,
|
|
329
|
+
): OverlayRect {
|
|
405
330
|
if (!corners) return base;
|
|
406
331
|
// Unrotated edge lengths (in overlay px): nw→ne is the width, nw→sw the height.
|
|
407
332
|
const width = cornerEdgeLength(corners.nw, corners.ne);
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** Selection rules over an ancestor chain: one answer for live elements and for descriptions. */
|
|
2
|
+
import type { TimelineElementDomTarget, TimelineElementDomTargetOptions } from "./domEditingTypes";
|
|
3
|
+
import { escapeCssString, normalizeTimelineCompositionSource } from "./domEditingDom";
|
|
4
|
+
|
|
5
|
+
/** Reads one element of a chain: the target first, then each parent up to the document element. */
|
|
6
|
+
export interface SelectionChainReader<N> {
|
|
7
|
+
attr(node: N, name: string): string | null;
|
|
8
|
+
selector(node: N): string | undefined;
|
|
9
|
+
/** The document's `body` or root element, where the walk to an addressable element stops. */
|
|
10
|
+
isDocumentRoot(node: N): boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const OUT_OF_SCOPE = -1;
|
|
14
|
+
const hasClass = (value: string | null, name: string) =>
|
|
15
|
+
(value ?? "").split(/[\t\n\f\r ]+/).includes(name);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A `data-hf-group` wrapper is one unit until the user drills into it; inside the drilled-into
|
|
19
|
+
* group, clicks reach its children, or the next group nested in it. Returns the unit's index, null
|
|
20
|
+
* to resolve the target itself, or OUT_OF_SCOPE when the target is outside the drilled-into group.
|
|
21
|
+
*/
|
|
22
|
+
function groupUnitIndex<N>(
|
|
23
|
+
chain: readonly N[],
|
|
24
|
+
read: SelectionChainReader<N>,
|
|
25
|
+
activeGroupIndex: number | null,
|
|
26
|
+
): number | null {
|
|
27
|
+
const groups = chain.flatMap((node, index) =>
|
|
28
|
+
read.attr(node, "data-hf-group") === null ? [] : [index],
|
|
29
|
+
);
|
|
30
|
+
if (activeGroupIndex === null) return groups.at(-1) ?? null;
|
|
31
|
+
const at = groups.indexOf(activeGroupIndex);
|
|
32
|
+
if (at === -1) return OUT_OF_SCOPE;
|
|
33
|
+
return at > 0 ? groups[at - 1]! : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The nearest `.clip`; a composition host counts only as the target itself. */
|
|
37
|
+
function clipAncestorIndex<N>(chain: readonly N[], read: SelectionChainReader<N>): number | null {
|
|
38
|
+
for (let index = 0; index < chain.length; index += 1) {
|
|
39
|
+
const node = chain[index]!;
|
|
40
|
+
if (!hasClass(read.attr(node, "class"), "clip")) continue;
|
|
41
|
+
const isHost =
|
|
42
|
+
read.attr(node, "data-composition-src") !== null ||
|
|
43
|
+
read.attr(node, "data-composition-file") !== null;
|
|
44
|
+
if (!isHost || index === 0) return index;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Where a selection of `chain[0]` lands; `activeGroupIndex` is -1 for a drilled group not in `chain`. */
|
|
50
|
+
export function selectionTargetIndex<N>(
|
|
51
|
+
chain: readonly N[],
|
|
52
|
+
read: SelectionChainReader<N>,
|
|
53
|
+
options: { exactTarget?: boolean; preferClipAncestor?: boolean; activeGroupIndex: number | null },
|
|
54
|
+
): number | null {
|
|
55
|
+
let start = options.exactTarget ? 0 : groupUnitIndex(chain, read, options.activeGroupIndex);
|
|
56
|
+
if (start === OUT_OF_SCOPE) start = groupUnitIndex(chain, read, null);
|
|
57
|
+
start ??= options.preferClipAncestor ? (clipAncestorIndex(chain, read) ?? 0) : 0;
|
|
58
|
+
for (let index = start; index < chain.length; index += 1) {
|
|
59
|
+
const node = chain[index]!;
|
|
60
|
+
if (read.isDocumentRoot(node)) return null;
|
|
61
|
+
if (read.selector(node) || read.attr(node, "data-hf-id")?.trim()) return index;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function chainLocked<N>(
|
|
67
|
+
chain: readonly N[],
|
|
68
|
+
read: SelectionChainReader<N>,
|
|
69
|
+
index: number,
|
|
70
|
+
): boolean {
|
|
71
|
+
return chain.slice(index).some((node) => read.attr(node, "data-timeline-locked") !== null);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SelectionLookupTarget {
|
|
75
|
+
id?: string | null;
|
|
76
|
+
hfId?: string;
|
|
77
|
+
selector?: string;
|
|
78
|
+
selectorIndex?: number;
|
|
79
|
+
sourceFile?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The selectors tried in order, each with the index of its match among those from `sourceFile`. */
|
|
83
|
+
export function selectionLookups(
|
|
84
|
+
selection: SelectionLookupTarget,
|
|
85
|
+
): Array<{ selector: string; index: number }> {
|
|
86
|
+
const lookups: Array<{ selector: string; index: number }> = [];
|
|
87
|
+
if (selection.hfId) {
|
|
88
|
+
lookups.push({ selector: `[data-hf-id="${escapeCssString(selection.hfId)}"]`, index: 0 });
|
|
89
|
+
}
|
|
90
|
+
// Flattened sub-compositions can repeat authored ids, so an id is matched by attribute, per source.
|
|
91
|
+
if (selection.id) lookups.push({ selector: `[id="${escapeCssString(selection.id)}"]`, index: 0 });
|
|
92
|
+
if (selection.selector) {
|
|
93
|
+
lookups.push({ selector: selection.selector, index: selection.selectorIndex ?? 0 });
|
|
94
|
+
}
|
|
95
|
+
return lookups;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Where a timeline element is in the preview: `target` to look up, else, when `rootFallback`, the
|
|
100
|
+
* first composition root if it comes from `sourceFile`.
|
|
101
|
+
*/
|
|
102
|
+
export function timelineElementLookup(
|
|
103
|
+
element: TimelineElementDomTarget,
|
|
104
|
+
options: TimelineElementDomTargetOptions,
|
|
105
|
+
): { target: SelectionLookupTarget | null; sourceFile: string; rootFallback: boolean } {
|
|
106
|
+
const elementId = typeof element.id === "string" ? element.id : "";
|
|
107
|
+
const compositionSource =
|
|
108
|
+
normalizeTimelineCompositionSource(element.compositionSrc) ??
|
|
109
|
+
options.compIdToSrc?.get(elementId);
|
|
110
|
+
const sourceFile =
|
|
111
|
+
compositionSource ??
|
|
112
|
+
normalizeTimelineCompositionSource(element.sourceFile) ??
|
|
113
|
+
options.activeCompositionPath ??
|
|
114
|
+
"index.html";
|
|
115
|
+
const escapedElementId = escapeCssString(elementId);
|
|
116
|
+
const escapedCompositionSource = compositionSource ? escapeCssString(compositionSource) : null;
|
|
117
|
+
const selector =
|
|
118
|
+
element.selector ??
|
|
119
|
+
(compositionSource
|
|
120
|
+
? `[data-composition-src="${escapedCompositionSource}"],[data-composition-file="${escapedCompositionSource}"],[data-composition-id="${escapedElementId}"]`
|
|
121
|
+
: escapedElementId
|
|
122
|
+
? `[data-composition-id="${escapedElementId}"]`
|
|
123
|
+
: undefined);
|
|
124
|
+
|
|
125
|
+
const target =
|
|
126
|
+
selector || element.domId
|
|
127
|
+
? {
|
|
128
|
+
id: element.domId ?? undefined,
|
|
129
|
+
selector,
|
|
130
|
+
selectorIndex: element.selectorIndex,
|
|
131
|
+
sourceFile,
|
|
132
|
+
}
|
|
133
|
+
: null;
|
|
134
|
+
const hasExplicitDomTarget = Boolean(element.domId || element.selector || compositionSource);
|
|
135
|
+
const rootFallback =
|
|
136
|
+
!options.isMasterView && !hasExplicitDomTarget && Boolean(options.activeCompositionPath);
|
|
137
|
+
return { target, sourceFile, rootFallback };
|
|
138
|
+
}
|
|
@@ -240,11 +240,7 @@ describe("resolveVisualDomEditSelectionTarget", () => {
|
|
|
240
240
|
setElementRect(container, { width: 900, height: 520 });
|
|
241
241
|
setElementRect(headline, { left: 240, top: 160, width: 180, height: 36 });
|
|
242
242
|
|
|
243
|
-
expect(
|
|
244
|
-
resolveVisualDomEditSelectionTarget([container, headline], {
|
|
245
|
-
activeCompositionPath: "index.html",
|
|
246
|
-
}),
|
|
247
|
-
).toBe(headline);
|
|
243
|
+
expect(resolveVisualDomEditSelectionTarget([container, headline])).toBe(headline);
|
|
248
244
|
});
|
|
249
245
|
|
|
250
246
|
it("skips hidden and zero-size elements before picking a rendered candidate", () => {
|
|
@@ -260,11 +256,7 @@ describe("resolveVisualDomEditSelectionTarget", () => {
|
|
|
260
256
|
setElementRect(empty, { width: 0, height: 0 });
|
|
261
257
|
setElementRect(visible, { width: 120, height: 32 });
|
|
262
258
|
|
|
263
|
-
expect(
|
|
264
|
-
resolveVisualDomEditSelectionTarget([hidden, empty, visible], {
|
|
265
|
-
activeCompositionPath: "index.html",
|
|
266
|
-
}),
|
|
267
|
-
).toBe(visible);
|
|
259
|
+
expect(resolveVisualDomEditSelectionTarget([hidden, empty, visible])).toBe(visible);
|
|
268
260
|
});
|
|
269
261
|
|
|
270
262
|
it("skips transparent elements that still report a box", () => {
|
|
@@ -277,11 +269,7 @@ describe("resolveVisualDomEditSelectionTarget", () => {
|
|
|
277
269
|
setElementRect(transparent, { width: 120, height: 32 });
|
|
278
270
|
setElementRect(visible, { width: 120, height: 32 });
|
|
279
271
|
|
|
280
|
-
expect(
|
|
281
|
-
resolveVisualDomEditSelectionTarget([transparent, visible], {
|
|
282
|
-
activeCompositionPath: "index.html",
|
|
283
|
-
}),
|
|
284
|
-
).toBe(visible);
|
|
272
|
+
expect(resolveVisualDomEditSelectionTarget([transparent, visible])).toBe(visible);
|
|
285
273
|
});
|
|
286
274
|
|
|
287
275
|
it("falls back to the nearest stable editable ancestor when a visual child has no target", () => {
|
|
@@ -295,11 +283,7 @@ describe("resolveVisualDomEditSelectionTarget", () => {
|
|
|
295
283
|
setElementRect(card, { width: 400, height: 200 });
|
|
296
284
|
setElementRect(span, { left: 40, top: 40, width: 140, height: 28 });
|
|
297
285
|
|
|
298
|
-
expect(
|
|
299
|
-
resolveVisualDomEditSelectionTarget([span, card], {
|
|
300
|
-
activeCompositionPath: "index.html",
|
|
301
|
-
}),
|
|
302
|
-
).toBe(card);
|
|
286
|
+
expect(resolveVisualDomEditSelectionTarget([span, card])).toBe(card);
|
|
303
287
|
});
|
|
304
288
|
|
|
305
289
|
it("keeps explicit layer selection able to target containers", async () => {
|
|
@@ -313,9 +297,7 @@ describe("resolveVisualDomEditSelectionTarget", () => {
|
|
|
313
297
|
setElementRect(container, { width: 900, height: 520 });
|
|
314
298
|
setElementRect(headline, { left: 240, top: 160, width: 180, height: 36 });
|
|
315
299
|
|
|
316
|
-
const visualTarget = resolveVisualDomEditSelectionTarget([container, headline]
|
|
317
|
-
activeCompositionPath: "index.html",
|
|
318
|
-
});
|
|
300
|
+
const visualTarget = resolveVisualDomEditSelectionTarget([container, headline]);
|
|
319
301
|
const explicitSelection = await resolveDomEditSelection(container, {
|
|
320
302
|
activeCompositionPath: "index.html",
|
|
321
303
|
isMasterView: false,
|
|
@@ -341,11 +323,7 @@ describe("resolveVisualDomEditSelectionTarget", () => {
|
|
|
341
323
|
setElementRect(sfChrome, { left: 0, top: 0, width: 1920, height: 1080 });
|
|
342
324
|
setElementRect(subComp, { left: 0, top: 0, width: 1920, height: 1080 });
|
|
343
325
|
|
|
344
|
-
expect(
|
|
345
|
-
resolveVisualDomEditSelectionTarget([pipStudio, subComp, sfChrome], {
|
|
346
|
-
activeCompositionPath: "index.html",
|
|
347
|
-
}),
|
|
348
|
-
).toBe(pipStudio);
|
|
326
|
+
expect(resolveVisualDomEditSelectionTarget([pipStudio, subComp, sfChrome])).toBe(pipStudio);
|
|
349
327
|
});
|
|
350
328
|
});
|
|
351
329
|
|