@hyperframes/studio 0.9.38 → 0.9.39
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-Dz2VdhdD.js → codec-CY6KnWXa.js} +1 -1
- package/dist/assets/{hyperframes-player-BkaWdGLq.js → hyperframes-player-B9-CuG_h.js} +1 -1
- package/dist/assets/{index-BJTCbv8z.css → index-4VGEAZyf.css} +1 -1
- package/dist/assets/{index-DONaC7VF.js → index-Bjz2UaYv.js} +1 -1
- package/dist/assets/{index-DsNxqAwr.js → index-_pkzoYYF.js} +145 -145
- package/dist/assets/{pausedVideoDecoder-BGN2jKrN.js → pausedVideoDecoder-Dr7nKUUu.js} +1 -1
- package/dist/{chunk-63DH4LRB.js → chunk-44VRMER6.js} +2 -11
- package/dist/{chunk-45KKBU63.js → chunk-ATDO3YLX.js} +1 -1
- package/dist/chunk-FQ3VRKMC.js +148 -0
- package/dist/{chunk-YKBN653R.js → chunk-NBULUIWH.js} +252 -1
- package/dist/{domEditingLayers-7Q56QAU5.js → domEditingLayers-FRVHP6IB.js} +2 -2
- package/dist/index.d.ts +3 -85
- package/dist/index.html +2 -2
- package/dist/index.js +321 -341
- package/dist/keys-CaWcxUST.d.ts +86 -0
- package/dist/keys.d.ts +1 -0
- package/dist/keys.js +11 -0
- package/dist/player.js +2 -2
- package/dist/styles.css +1 -1
- package/package.json +12 -8
- package/src/components/editor/DomEditGestureReadout.test.tsx +204 -20
- package/src/components/editor/DomEditGestureReadout.tsx +36 -18
- package/src/components/editor/InlineTextToolbar.tsx +2 -2
- package/src/components/editor/domEditGestureReadoutPlacement.ts +144 -0
- package/src/components/editor/domEditGestureReadoutState.ts +18 -8
- package/src/components/editor/domEditingDom.ts +2 -15
- package/src/components/editor/useDomEditCompositionRect.ts +13 -4
- package/src/components/editor/useDomEditOverlayGestures.ts +1 -1
- package/src/components/editor/usePreviewCompositionRect.test.tsx +39 -0
- package/src/hooks/elementPickerStyles.ts +53 -0
- package/src/hooks/useElementPicker.test.ts +83 -3
- package/src/hooks/useElementPicker.ts +27 -66
- package/src/keys.test.ts +53 -0
- package/src/keys.ts +11 -0
- package/src/player/components/Player.tsx +2 -0
- package/src/player/components/studioKeyDefaults.ts +68 -0
- package/src/player/components/studioShortcuts.ts +2 -67
- package/src/player/hooks/playbackAdapterResolution.ts +15 -0
- package/src/player/hooks/previewMessageRouter.manifest.test.ts +67 -0
- package/src/player/hooks/previewMessageRouter.ts +38 -8
- package/src/player/hooks/timelinePlayerTestHarness.ts +26 -1
- package/src/player/hooks/useShadowPreviewReload.ts +4 -1
- package/src/player/hooks/useTimelinePlayer.ts +5 -9
- package/src/player/lib/bridgePlayback.ts +156 -0
- package/src/player/lib/previewChannel.test.ts +260 -0
- package/src/player/lib/previewChannel.ts +100 -0
- package/src/player/sceneSwap.test.ts +12 -0
- package/src/player/sceneSwap.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.39",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"import": "./dist/player.js",
|
|
28
28
|
"types": "./dist/player.d.ts"
|
|
29
29
|
},
|
|
30
|
+
"./keys": {
|
|
31
|
+
"import": "./dist/keys.js",
|
|
32
|
+
"types": "./dist/keys.d.ts"
|
|
33
|
+
},
|
|
30
34
|
"./tailwind-preset": {
|
|
31
35
|
"import": "./dist/styles/tailwind-preset.js",
|
|
32
36
|
"types": "./dist/styles/tailwind-preset.d.ts"
|
|
@@ -60,12 +64,12 @@
|
|
|
60
64
|
"dockview-react": "8.3.1",
|
|
61
65
|
"gsap": "^3.13.0",
|
|
62
66
|
"mediabunny": "^1.65.2",
|
|
63
|
-
"@hyperframes/
|
|
64
|
-
"@hyperframes/
|
|
65
|
-
"@hyperframes/
|
|
66
|
-
"@hyperframes/
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/
|
|
67
|
+
"@hyperframes/parsers": "0.9.39",
|
|
68
|
+
"@hyperframes/sdk": "0.9.39",
|
|
69
|
+
"@hyperframes/player": "0.9.39",
|
|
70
|
+
"@hyperframes/shader-transitions": "0.9.39",
|
|
71
|
+
"@hyperframes/studio-server": "0.9.39",
|
|
72
|
+
"@hyperframes/core": "0.9.39"
|
|
69
73
|
},
|
|
70
74
|
"devDependencies": {
|
|
71
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -82,7 +86,7 @@
|
|
|
82
86
|
"vite": "^6.4.2",
|
|
83
87
|
"vitest": "^4.1.11",
|
|
84
88
|
"zustand": "^5.0.0",
|
|
85
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.39"
|
|
86
90
|
},
|
|
87
91
|
"peerDependencies": {
|
|
88
92
|
"react": "19",
|
|
@@ -3,7 +3,11 @@ import React, { act, type ComponentProps } from "react";
|
|
|
3
3
|
import { createRoot, type Root } from "react-dom/client";
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { DomEditGestureReadout } from "./DomEditGestureReadout";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createGestureReadout,
|
|
8
|
+
updateGestureReadout,
|
|
9
|
+
updateGestureReadoutAngle,
|
|
10
|
+
} from "./domEditGestureReadoutState";
|
|
7
11
|
|
|
8
12
|
const frames = vi.hoisted(() => ({ update: () => {} }));
|
|
9
13
|
vi.mock("./overlayFrameLoop", () => ({
|
|
@@ -23,7 +27,16 @@ afterEach(() => {
|
|
|
23
27
|
vi.clearAllMocks();
|
|
24
28
|
});
|
|
25
29
|
|
|
26
|
-
function mount(
|
|
30
|
+
function mount(
|
|
31
|
+
kind: "drag" | "resize" | "rotate",
|
|
32
|
+
{
|
|
33
|
+
overlayWidth = 500,
|
|
34
|
+
height = 60,
|
|
35
|
+
stageHeight = 400,
|
|
36
|
+
angle = undefined as number | undefined,
|
|
37
|
+
localAngle = undefined as number | undefined,
|
|
38
|
+
} = {},
|
|
39
|
+
) {
|
|
27
40
|
const host = document.createElement("div");
|
|
28
41
|
const overlay = document.createElement("div");
|
|
29
42
|
const iframe = document.createElement("iframe");
|
|
@@ -40,9 +53,8 @@ function mount(kind: "drag" | "resize" | "rotate") {
|
|
|
40
53
|
let x = 70.25;
|
|
41
54
|
let y = 40.75;
|
|
42
55
|
const width = 100;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
iframe.getBoundingClientRect = () => new DOMRect(20, 30, 500, 400);
|
|
56
|
+
overlay.getBoundingClientRect = () => new DOMRect(20, 30, overlayWidth, 400);
|
|
57
|
+
iframe.getBoundingClientRect = () => new DOMRect(20, 30, overlayWidth, stageHeight);
|
|
46
58
|
composition.getBoundingClientRect = () => new DOMRect(0, 0, 1000, 800);
|
|
47
59
|
element.getBoundingClientRect = () => new DOMRect(x, y, width, height);
|
|
48
60
|
Object.defineProperties(element, {
|
|
@@ -59,6 +71,7 @@ function mount(kind: "drag" | "resize" | "rotate") {
|
|
|
59
71
|
height: height / 2,
|
|
60
72
|
editScaleX: 0.5,
|
|
61
73
|
editScaleY: 0.5,
|
|
74
|
+
angle,
|
|
62
75
|
}),
|
|
63
76
|
},
|
|
64
77
|
};
|
|
@@ -72,10 +85,11 @@ function mount(kind: "drag" | "resize" | "rotate") {
|
|
|
72
85
|
height: height / 2,
|
|
73
86
|
editScaleX: 0.5,
|
|
74
87
|
editScaleY: 0.5,
|
|
88
|
+
angle: localAngle ?? angle,
|
|
75
89
|
},
|
|
76
90
|
text,
|
|
77
91
|
);
|
|
78
|
-
update(kind === "resize" ? "100
|
|
92
|
+
update(kind === "resize" ? "W 100 · H 60" : kind === "rotate" ? "↻ 0°" : undefined);
|
|
79
93
|
root = createRoot(host);
|
|
80
94
|
act(() =>
|
|
81
95
|
root?.render(
|
|
@@ -113,6 +127,13 @@ function mount(kind: "drag" | "resize" | "rotate") {
|
|
|
113
127
|
};
|
|
114
128
|
}
|
|
115
129
|
|
|
130
|
+
/** The chip's fields as [name, figure] pairs. */
|
|
131
|
+
const fields = (label: Element) =>
|
|
132
|
+
[...label.querySelectorAll(":scope > span.flex")].map((field) => [
|
|
133
|
+
field.children[0]?.textContent,
|
|
134
|
+
field.children[1]?.textContent,
|
|
135
|
+
]);
|
|
136
|
+
|
|
116
137
|
describe("gesture readout", () => {
|
|
117
138
|
it("adds no layout reads while drawing and stays hidden on a plain press", () => {
|
|
118
139
|
const view = mount("drag");
|
|
@@ -125,7 +146,10 @@ describe("gesture readout", () => {
|
|
|
125
146
|
view.move(120, 70);
|
|
126
147
|
view.draw();
|
|
127
148
|
view.draw();
|
|
128
|
-
expect(view.label
|
|
149
|
+
expect(fields(view.label)).toEqual([
|
|
150
|
+
["X", "120"],
|
|
151
|
+
["Y", "70"],
|
|
152
|
+
]);
|
|
129
153
|
expect(measure).not.toHaveBeenCalled();
|
|
130
154
|
for (const measurement of view.measurements) expect(measurement).not.toHaveBeenCalled();
|
|
131
155
|
measure.mockRestore();
|
|
@@ -134,10 +158,16 @@ describe("gesture readout", () => {
|
|
|
134
158
|
it("shows rounded composition coordinates during a move, accounting for preview zoom", () => {
|
|
135
159
|
const view = mount("drag");
|
|
136
160
|
view.draw();
|
|
137
|
-
expect(view.label
|
|
161
|
+
expect(fields(view.label)).toEqual([
|
|
162
|
+
["X", "70"],
|
|
163
|
+
["Y", "41"],
|
|
164
|
+
]);
|
|
138
165
|
view.move(120.25, 70.75);
|
|
139
166
|
view.draw();
|
|
140
|
-
expect(view.label
|
|
167
|
+
expect(fields(view.label)).toEqual([
|
|
168
|
+
["X", "120"],
|
|
169
|
+
["Y", "71"],
|
|
170
|
+
]);
|
|
141
171
|
expect(view.doc.querySelector("[data-dom-edit-gesture-readout]")).toBeNull();
|
|
142
172
|
view.end();
|
|
143
173
|
expect(view.label.style.display).toBe("none");
|
|
@@ -145,33 +175,187 @@ describe("gesture readout", () => {
|
|
|
145
175
|
it("shows the actual size draft during resize and hides on release", () => {
|
|
146
176
|
const view = mount("resize");
|
|
147
177
|
view.draw();
|
|
148
|
-
expect(view.label
|
|
149
|
-
|
|
178
|
+
expect(fields(view.label)).toEqual([
|
|
179
|
+
["W", "100"],
|
|
180
|
+
["H", "60"],
|
|
181
|
+
]);
|
|
182
|
+
view.update("W 144 · H 87");
|
|
150
183
|
view.draw();
|
|
151
|
-
expect(view.label
|
|
184
|
+
expect(fields(view.label)).toEqual([
|
|
185
|
+
["W", "144"],
|
|
186
|
+
["H", "87"],
|
|
187
|
+
]);
|
|
152
188
|
view.end();
|
|
153
189
|
expect(view.label.style.display).toBe("none");
|
|
154
190
|
});
|
|
155
191
|
it("reads the live angle during rotation and hides on cancellation", () => {
|
|
156
192
|
const view = mount("rotate");
|
|
157
|
-
view.update("32°");
|
|
193
|
+
view.update("↻ 32°");
|
|
158
194
|
view.draw();
|
|
159
|
-
expect(view.label
|
|
160
|
-
view.update("-46°");
|
|
195
|
+
expect(fields(view.label)).toEqual([["↻", "32°"]]);
|
|
196
|
+
view.update("↻ -46°");
|
|
161
197
|
view.draw();
|
|
162
|
-
expect(view.label
|
|
198
|
+
expect(fields(view.label)).toEqual([["↻", "-46°"]]);
|
|
163
199
|
view.end();
|
|
164
200
|
expect(view.label.style.display).toBe("none");
|
|
165
201
|
});
|
|
202
|
+
it("sits below the element, centred, clear of the text toolbar above it", () => {
|
|
203
|
+
const view = mount("drag");
|
|
204
|
+
view.move(300, 200);
|
|
205
|
+
view.draw();
|
|
206
|
+
expect(view.label.style.left).toBe("175px");
|
|
207
|
+
expect(view.label.style.top).toBe("138px");
|
|
208
|
+
expect(view.label.style.transform).toBe("translateX(-50%)");
|
|
209
|
+
});
|
|
210
|
+
it("goes beside the element when there is no room below it", () => {
|
|
211
|
+
const view = mount("drag");
|
|
212
|
+
view.move(300, 700);
|
|
213
|
+
view.draw();
|
|
214
|
+
expect(view.label.style.left).toBe("208px");
|
|
215
|
+
expect(view.label.style.top).toBe("349px");
|
|
216
|
+
expect(view.label.style.transform).toBe("none");
|
|
217
|
+
view.move(880, 700);
|
|
218
|
+
view.draw();
|
|
219
|
+
expect(view.label.style.left).toBe("432px");
|
|
220
|
+
expect(view.label.style.transform).toBe("translateX(-100%)");
|
|
221
|
+
});
|
|
222
|
+
it("goes above the toolbar's band when neither below nor either side has room", () => {
|
|
223
|
+
const view = mount("drag", { overlayWidth: 150 });
|
|
224
|
+
view.move(100, 700);
|
|
225
|
+
view.draw();
|
|
226
|
+
expect(view.label.style.top).toBe("266px");
|
|
227
|
+
expect(view.label.style.transform).toBe("translateX(-50%)");
|
|
228
|
+
});
|
|
229
|
+
it("is not placed below an element whose toolbar has dropped below it", () => {
|
|
230
|
+
const view = mount("drag");
|
|
231
|
+
view.move(300, 10);
|
|
232
|
+
view.draw();
|
|
233
|
+
expect(view.label.style.transform).toBe("translateX(-100%)");
|
|
234
|
+
expect(view.label.style.left).toBe("142px");
|
|
235
|
+
});
|
|
236
|
+
it("keeps its side for the whole gesture while that side still fits", () => {
|
|
237
|
+
const view = mount("drag");
|
|
238
|
+
view.move(300, 700);
|
|
239
|
+
view.draw();
|
|
240
|
+
expect(view.label.style.transform).toBe("none");
|
|
241
|
+
view.move(300, 200);
|
|
242
|
+
view.draw();
|
|
243
|
+
expect(view.label.style.left).toBe("208px");
|
|
244
|
+
expect(view.label.style.top).toBe("99px");
|
|
245
|
+
view.move(900, 200);
|
|
246
|
+
view.draw();
|
|
247
|
+
expect(view.label.style.transform).toBe("translateX(-50%)");
|
|
248
|
+
});
|
|
166
249
|
it("clamps the label inside the visible overlay at either edge", () => {
|
|
167
250
|
const view = mount("drag");
|
|
168
251
|
view.move(900, -100);
|
|
169
252
|
view.draw();
|
|
170
|
-
expect(view.label.style.
|
|
171
|
-
expect(view.label.style.top).toBe("4px");
|
|
253
|
+
expect(view.label.style.top).toBe("40px");
|
|
172
254
|
view.move(-900, 900);
|
|
173
255
|
view.draw();
|
|
174
|
-
expect(view.label.style.left).toBe("
|
|
175
|
-
expect(view.label.style.top).toBe("
|
|
256
|
+
expect(view.label.style.left).toBe("78px");
|
|
257
|
+
expect(view.label.style.top).toBe("364px");
|
|
258
|
+
});
|
|
259
|
+
it("while rotating, places from the rotated box and keeps the angle apart from the size", () => {
|
|
260
|
+
const view = mount("rotate");
|
|
261
|
+
const readout = view.gestureRef.current?.readout;
|
|
262
|
+
updateGestureReadoutAngle(readout, 90);
|
|
263
|
+
expect(readout?.rect.width).toBe(50);
|
|
264
|
+
expect(readout?.rect.angle).toBe(90);
|
|
265
|
+
updateGestureReadoutAngle(readout, 0);
|
|
266
|
+
expect(readout?.rect.angle).toBe(0);
|
|
267
|
+
expect(readout?.text).toBe("↻ 0°");
|
|
268
|
+
});
|
|
269
|
+
it("clears an element that was already rotated when it is dragged", () => {
|
|
270
|
+
const view = mount("drag", { angle: 90 });
|
|
271
|
+
view.move(300, 200);
|
|
272
|
+
view.draw();
|
|
273
|
+
expect(view.label.style.top).toBe("148px");
|
|
274
|
+
});
|
|
275
|
+
it("uses the painted angle, not the element's own, under a rotated parent", () => {
|
|
276
|
+
const counter = mount("drag", { angle: 0, localAngle: -90 });
|
|
277
|
+
counter.move(300, 200);
|
|
278
|
+
counter.draw();
|
|
279
|
+
expect(counter.label.style.top).toBe("138px");
|
|
280
|
+
const parentOnly = mount("drag", { angle: 90, localAngle: 0 });
|
|
281
|
+
parentOnly.move(300, 200);
|
|
282
|
+
parentOnly.draw();
|
|
283
|
+
expect(parentOnly.label.style.top).toBe("148px");
|
|
284
|
+
});
|
|
285
|
+
it("turns the painted angle by the change in the element's own angle while rotating", () => {
|
|
286
|
+
const view = mount("rotate", { angle: 90, localAngle: 0 });
|
|
287
|
+
const readout = view.gestureRef.current?.readout;
|
|
288
|
+
updateGestureReadoutAngle(readout, 30, 0);
|
|
289
|
+
expect(readout?.rect.angle).toBe(120);
|
|
290
|
+
expect(readout?.text).toBe("↻ 30°");
|
|
291
|
+
});
|
|
292
|
+
it("clears an element that was already rotated when it is resized", () => {
|
|
293
|
+
const view = mount("resize", { angle: 90 });
|
|
294
|
+
view.move(300, 200);
|
|
295
|
+
view.draw();
|
|
296
|
+
expect(view.label.style.top).toBe("148px");
|
|
297
|
+
});
|
|
298
|
+
it("never puts a side chip off the stage, left or right, even when that side was kept", () => {
|
|
299
|
+
const first = mount("drag");
|
|
300
|
+
first.move(-900, 700);
|
|
301
|
+
first.draw();
|
|
302
|
+
expect(first.label.style.transform).toBe("translateX(-50%)");
|
|
303
|
+
const second = mount("drag");
|
|
304
|
+
second.move(1800, 700);
|
|
305
|
+
second.draw();
|
|
306
|
+
expect(second.label.style.transform).toBe("translateX(-50%)");
|
|
307
|
+
const keptRight = mount("drag");
|
|
308
|
+
keptRight.move(300, 700);
|
|
309
|
+
keptRight.draw();
|
|
310
|
+
expect(keptRight.label.style.transform).toBe("none");
|
|
311
|
+
keptRight.move(-900, 700);
|
|
312
|
+
keptRight.draw();
|
|
313
|
+
expect(keptRight.label.style.transform).toBe("translateX(-50%)");
|
|
314
|
+
const keptLeft = mount("drag");
|
|
315
|
+
keptLeft.move(880, 700);
|
|
316
|
+
keptLeft.draw();
|
|
317
|
+
expect(keptLeft.label.style.transform).toBe("translateX(-100%)");
|
|
318
|
+
keptLeft.move(1800, 700);
|
|
319
|
+
keptLeft.draw();
|
|
320
|
+
expect(keptLeft.label.style.transform).toBe("translateX(-50%)");
|
|
321
|
+
});
|
|
322
|
+
const inside = (label: HTMLElement, top: number, bottom: number) => {
|
|
323
|
+
const y = Number.parseFloat(label.style.top);
|
|
324
|
+
expect(y).toBeGreaterThanOrEqual(top);
|
|
325
|
+
expect(y + 32).toBeLessThanOrEqual(bottom);
|
|
326
|
+
};
|
|
327
|
+
it("stays inside the stage when the element touches the bottom edge", () => {
|
|
328
|
+
const view = mount("drag");
|
|
329
|
+
view.move(300, 740);
|
|
330
|
+
view.draw();
|
|
331
|
+
inside(view.label, 4, 396);
|
|
332
|
+
});
|
|
333
|
+
it("stays inside the stage when the element touches the top edge", () => {
|
|
334
|
+
const view = mount("drag");
|
|
335
|
+
view.move(300, 0);
|
|
336
|
+
view.draw();
|
|
337
|
+
inside(view.label, 4, 396);
|
|
338
|
+
});
|
|
339
|
+
it("stays inside the stage for an element as tall as the stage", () => {
|
|
340
|
+
const view = mount("drag", { height: 800 });
|
|
341
|
+
view.move(300, 0);
|
|
342
|
+
view.draw();
|
|
343
|
+
inside(view.label, 4, 396);
|
|
344
|
+
const narrow = mount("drag", { height: 800, overlayWidth: 150 });
|
|
345
|
+
narrow.move(100, 0);
|
|
346
|
+
narrow.draw();
|
|
347
|
+
inside(narrow.label, 4, 396);
|
|
348
|
+
});
|
|
349
|
+
it("lands below the preview toolbar when the element is larger than the stage", () => {
|
|
350
|
+
const view = mount("drag", { height: 800, overlayWidth: 150 });
|
|
351
|
+
view.move(100, 0);
|
|
352
|
+
view.draw();
|
|
353
|
+
expect(Number.parseFloat(view.label.style.top)).toBeGreaterThanOrEqual(40);
|
|
354
|
+
});
|
|
355
|
+
it("bounds the chip by the stage, not the larger canvas area around it", () => {
|
|
356
|
+
const view = mount("drag", { stageHeight: 300 });
|
|
357
|
+
view.move(300, 500);
|
|
358
|
+
view.draw();
|
|
359
|
+
inside(view.label, 4, 296);
|
|
176
360
|
});
|
|
177
361
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useRef, type RefObject } from "react";
|
|
2
2
|
import { useMountEffect } from "../../hooks/useMountEffect";
|
|
3
|
+
import { placeChip } from "./domEditGestureReadoutPlacement";
|
|
3
4
|
import type { GestureState } from "./domEditOverlayGestures";
|
|
4
5
|
import { subscribeOverlayFrame } from "./overlayFrameLoop";
|
|
5
6
|
|
|
@@ -11,22 +12,39 @@ interface DomEditGestureReadoutProps {
|
|
|
11
12
|
iframeRef: RefObject<HTMLIFrameElement | null>;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
function positionGestureReadout(
|
|
15
|
+
function positionGestureReadout(
|
|
16
|
+
label: HTMLDivElement,
|
|
17
|
+
gesture: ReadoutGesture,
|
|
18
|
+
text: string,
|
|
19
|
+
): void {
|
|
15
20
|
const readout = gesture.readout;
|
|
16
21
|
if (!readout) return;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const placed = placeChip(readout, text);
|
|
23
|
+
readout.side = placed.side;
|
|
24
|
+
label.style.left = `${placed.left}px`;
|
|
25
|
+
label.style.top = `${placed.top}px`;
|
|
26
|
+
label.style.transform = placed.transform;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function renderFields(label: HTMLDivElement, text: string): void {
|
|
30
|
+
const fields = text.split(" · ").flatMap((field, index) => {
|
|
31
|
+
const [name = "", ...value] = field.split(" ");
|
|
32
|
+
const cells = document.createElement("span");
|
|
33
|
+
cells.className = "flex items-baseline gap-1.5";
|
|
34
|
+
const key = document.createElement("span");
|
|
35
|
+
key.className = "text-text-4";
|
|
36
|
+
key.textContent = name;
|
|
37
|
+
const figure = document.createElement("span");
|
|
38
|
+
figure.className = "min-w-[4ch] text-right font-medium";
|
|
39
|
+
figure.textContent = value.join(" ");
|
|
40
|
+
cells.append(key, figure);
|
|
41
|
+
if (index === 0) return [cells];
|
|
42
|
+
const divider = document.createElement("span");
|
|
43
|
+
divider.className = "h-3.5 w-px bg-border";
|
|
44
|
+
return [divider, cells];
|
|
45
|
+
});
|
|
46
|
+
label.replaceChildren(...fields);
|
|
47
|
+
label.dataset.readoutText = text;
|
|
30
48
|
}
|
|
31
49
|
|
|
32
50
|
export function DomEditGestureReadout({ gestureRef }: DomEditGestureReadoutProps) {
|
|
@@ -41,9 +59,9 @@ export function DomEditGestureReadout({ gestureRef }: DomEditGestureReadoutProps
|
|
|
41
59
|
label.style.display = "none";
|
|
42
60
|
return;
|
|
43
61
|
}
|
|
44
|
-
if (label.
|
|
45
|
-
label.style.display = "
|
|
46
|
-
positionGestureReadout(label, gesture);
|
|
62
|
+
if (label.dataset.readoutText !== text) renderFields(label, text);
|
|
63
|
+
label.style.display = "flex";
|
|
64
|
+
positionGestureReadout(label, gesture, text);
|
|
47
65
|
}),
|
|
48
66
|
);
|
|
49
67
|
return (
|
|
@@ -51,7 +69,7 @@ export function DomEditGestureReadout({ gestureRef }: DomEditGestureReadoutProps
|
|
|
51
69
|
ref={labelRef}
|
|
52
70
|
aria-hidden="true"
|
|
53
71
|
data-dom-edit-gesture-readout="true"
|
|
54
|
-
className="pointer-events-none absolute z-50
|
|
72
|
+
className="pointer-events-none absolute z-50 flex h-8 items-center gap-2 rounded-lg border border-border bg-raised px-3 text-xs whitespace-nowrap text-studio-text tabular-nums shadow-[0_8px_24px_rgba(0,0,0,0.55)]"
|
|
55
73
|
style={{ display: "none" }}
|
|
56
74
|
/>
|
|
57
75
|
);
|
|
@@ -24,9 +24,9 @@ import type { InlineTextEditSession } from "../../hooks/useInlineTextEdit";
|
|
|
24
24
|
const READ_PROPERTIES = ["color", "font-weight", "font-style", "text-decoration-line"];
|
|
25
25
|
|
|
26
26
|
/** Enough above the text to clear it, without leaving the element behind. */
|
|
27
|
-
const GAP_PX = 10;
|
|
27
|
+
export const GAP_PX = 10;
|
|
28
28
|
/** h-6 controls + p-1 + the border. Used only to keep an above-toolbar onscreen. */
|
|
29
|
-
const TOOLBAR_HEIGHT_PX = 34;
|
|
29
|
+
export const TOOLBAR_HEIGHT_PX = 34;
|
|
30
30
|
const DEFAULT_COLOR = "#ffffff";
|
|
31
31
|
|
|
32
32
|
interface ToolbarPlacement {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { GestureReadoutSide, GestureReadoutState } from "./domEditGestureReadoutState";
|
|
2
|
+
import type { OverlayRect } from "./domEditOverlayGeometry";
|
|
3
|
+
import { GAP_PX as TOOLBAR_GAP_PX, TOOLBAR_HEIGHT_PX } from "./InlineTextToolbar";
|
|
4
|
+
|
|
5
|
+
const GAP_PX = 8;
|
|
6
|
+
const EDGE_PX = 4;
|
|
7
|
+
const SNAP_TOOLBAR_BAND_PX = 36;
|
|
8
|
+
const SNAP_TOOLBAR_WIDTH_PX = 180;
|
|
9
|
+
const CHIP_HEIGHT_PX = 32;
|
|
10
|
+
const CHAR_PX = 8;
|
|
11
|
+
const CHIP_PADDING_PX = 36;
|
|
12
|
+
|
|
13
|
+
const SIDES: readonly GestureReadoutSide[] = ["below", "right", "left", "above"];
|
|
14
|
+
|
|
15
|
+
interface Box {
|
|
16
|
+
minX: number;
|
|
17
|
+
minY: number;
|
|
18
|
+
maxX: number;
|
|
19
|
+
maxY: number;
|
|
20
|
+
toolbarBottom: number;
|
|
21
|
+
toolbarLeft: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Spot {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
fits: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ChipPlacement {
|
|
31
|
+
side: GestureReadoutSide;
|
|
32
|
+
left: number;
|
|
33
|
+
top: number;
|
|
34
|
+
transform: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function visibleBox(readout: GestureReadoutState): Box {
|
|
38
|
+
const bounds = readout.basis.overlayRect;
|
|
39
|
+
const stage = readout.basis.iframeRect;
|
|
40
|
+
const stageLeft = stage.left - bounds.left;
|
|
41
|
+
const stageTop = stage.top - bounds.top;
|
|
42
|
+
const minY = Math.max(0, -bounds.top, stageTop) + EDGE_PX;
|
|
43
|
+
const maxX =
|
|
44
|
+
Math.min(bounds.width, readout.viewportWidth - bounds.left, stageLeft + stage.width) - EDGE_PX;
|
|
45
|
+
return {
|
|
46
|
+
minX: Math.max(0, -bounds.left, stageLeft) + EDGE_PX,
|
|
47
|
+
minY,
|
|
48
|
+
toolbarBottom: minY + SNAP_TOOLBAR_BAND_PX,
|
|
49
|
+
toolbarLeft: maxX - SNAP_TOOLBAR_WIDTH_PX,
|
|
50
|
+
maxX,
|
|
51
|
+
maxY:
|
|
52
|
+
Math.min(bounds.height, readout.viewportHeight - bounds.top, stageTop + stage.height) -
|
|
53
|
+
EDGE_PX,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function clearOfToolbar(box: Box, right: number, top: number): boolean {
|
|
58
|
+
return right <= box.toolbarLeft || top >= box.toolbarBottom;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function paintedBox(rect: OverlayRect): OverlayRect {
|
|
62
|
+
const radians = ((rect.angle ?? 0) * Math.PI) / 180;
|
|
63
|
+
const cos = Math.abs(Math.cos(radians));
|
|
64
|
+
const sin = Math.abs(Math.sin(radians));
|
|
65
|
+
const width = rect.width * cos + rect.height * sin;
|
|
66
|
+
const height = rect.width * sin + rect.height * cos;
|
|
67
|
+
return {
|
|
68
|
+
...rect,
|
|
69
|
+
left: rect.left + (rect.width - width) / 2,
|
|
70
|
+
top: rect.top + (rect.height - height) / 2,
|
|
71
|
+
width,
|
|
72
|
+
height,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function fitsBeside(box: Box, x0: number, x1: number, top: number): boolean {
|
|
77
|
+
const inside =
|
|
78
|
+
x0 >= box.minX && x1 <= box.maxX && top >= box.minY && top + CHIP_HEIGHT_PX <= box.maxY;
|
|
79
|
+
return inside && clearOfToolbar(box, x1, top);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function chipSpots(
|
|
83
|
+
readout: GestureReadoutState,
|
|
84
|
+
box: Box,
|
|
85
|
+
width: number,
|
|
86
|
+
): Record<GestureReadoutSide, Spot> {
|
|
87
|
+
const rect = paintedBox(readout.rect);
|
|
88
|
+
const right = rect.left + rect.width;
|
|
89
|
+
const bottom = rect.top + rect.height;
|
|
90
|
+
const centre = rect.left + rect.width / 2;
|
|
91
|
+
const middle = rect.top + rect.height / 2 - CHIP_HEIGHT_PX / 2;
|
|
92
|
+
const toolbarBelow =
|
|
93
|
+
readout.basis.overlayRect.top + rect.top - TOOLBAR_GAP_PX < TOOLBAR_HEIGHT_PX;
|
|
94
|
+
const toolbarBand = toolbarBelow ? 0 : TOOLBAR_GAP_PX + TOOLBAR_HEIGHT_PX;
|
|
95
|
+
return {
|
|
96
|
+
below: {
|
|
97
|
+
x: centre,
|
|
98
|
+
y: bottom + GAP_PX,
|
|
99
|
+
fits: !toolbarBelow && bottom + GAP_PX + CHIP_HEIGHT_PX <= box.maxY,
|
|
100
|
+
},
|
|
101
|
+
right: {
|
|
102
|
+
x: right + GAP_PX,
|
|
103
|
+
y: middle,
|
|
104
|
+
fits: fitsBeside(box, right + GAP_PX, right + GAP_PX + width, middle),
|
|
105
|
+
},
|
|
106
|
+
left: {
|
|
107
|
+
x: rect.left - GAP_PX,
|
|
108
|
+
y: middle,
|
|
109
|
+
fits: fitsBeside(box, rect.left - GAP_PX - width, rect.left - GAP_PX, middle),
|
|
110
|
+
},
|
|
111
|
+
above: { x: centre, y: rect.top - GAP_PX - toolbarBand - CHIP_HEIGHT_PX, fits: true },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function chooseSide(
|
|
116
|
+
kept: GestureReadoutSide | undefined,
|
|
117
|
+
spots: Record<GestureReadoutSide, Spot>,
|
|
118
|
+
): GestureReadoutSide {
|
|
119
|
+
if (kept && spots[kept].fits) return kept;
|
|
120
|
+
return SIDES.find((side) => spots[side].fits) ?? "above";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const TRANSFORMS: Record<GestureReadoutSide, string> = {
|
|
124
|
+
below: "translateX(-50%)",
|
|
125
|
+
above: "translateX(-50%)",
|
|
126
|
+
left: "translateX(-100%)",
|
|
127
|
+
right: "none",
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export function placeChip(readout: GestureReadoutState, text: string): ChipPlacement {
|
|
131
|
+
const box = visibleBox(readout);
|
|
132
|
+
const width = text.length * CHAR_PX + CHIP_PADDING_PX;
|
|
133
|
+
const spots = chipSpots(readout, box, width);
|
|
134
|
+
const side = chooseSide(readout.side, spots);
|
|
135
|
+
const spot = spots[side];
|
|
136
|
+
const centred = TRANSFORMS[side] === "translateX(-50%)";
|
|
137
|
+
const left = centred
|
|
138
|
+
? Math.max(box.minX + width / 2, Math.min(box.maxX - width / 2, spot.x))
|
|
139
|
+
: spot.x;
|
|
140
|
+
const chipRight = side === "right" ? left + width : side === "left" ? left : left + width / 2;
|
|
141
|
+
const floor = clearOfToolbar(box, chipRight, box.minY) ? box.minY : box.toolbarBottom;
|
|
142
|
+
const top = Math.min(box.maxY - CHIP_HEIGHT_PX, Math.max(floor, spot.y));
|
|
143
|
+
return { side, left, top, transform: TRANSFORMS[side] };
|
|
144
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computeOverlayRootScale, type OverlayRootScale } from "./domEditOverlayBasis";
|
|
2
2
|
import type { OverlayRect } from "./domEditOverlayGeometry";
|
|
3
|
+
export type GestureReadoutSide = "below" | "right" | "left" | "above";
|
|
3
4
|
|
|
4
5
|
export interface GestureReadoutState {
|
|
5
6
|
basis: OverlayRootScale;
|
|
@@ -7,6 +8,8 @@ export interface GestureReadoutState {
|
|
|
7
8
|
viewportHeight: number;
|
|
8
9
|
text: string;
|
|
9
10
|
rect: OverlayRect;
|
|
11
|
+
baseRect: OverlayRect;
|
|
12
|
+
side?: GestureReadoutSide;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
export function createGestureReadout(
|
|
@@ -23,27 +26,34 @@ export function createGestureReadout(
|
|
|
23
26
|
viewportHeight: window.innerHeight,
|
|
24
27
|
text: "",
|
|
25
28
|
rect,
|
|
29
|
+
baseRect: rect,
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
function setReadout(readout: GestureReadoutState, rect: OverlayRect, text?: string): void {
|
|
34
|
+
const { basis } = readout;
|
|
35
|
+
const x = (rect.left - (basis.iframeRect.left - basis.overlayRect.left)) / basis.rootScaleX;
|
|
36
|
+
const y = (rect.top - (basis.iframeRect.top - basis.overlayRect.top)) / basis.rootScaleY;
|
|
37
|
+
readout.text = text ?? `X ${Math.round(x)} · Y ${Math.round(y)}`;
|
|
38
|
+
readout.rect = rect;
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
export function updateGestureReadout(
|
|
30
42
|
readout: GestureReadoutState | undefined,
|
|
31
43
|
rect: OverlayRect,
|
|
32
44
|
text?: string,
|
|
33
45
|
): void {
|
|
34
|
-
if (
|
|
35
|
-
const { basis } = readout;
|
|
36
|
-
const x = (rect.left - (basis.iframeRect.left - basis.overlayRect.left)) / basis.rootScaleX;
|
|
37
|
-
const y = (rect.top - (basis.iframeRect.top - basis.overlayRect.top)) / basis.rootScaleY;
|
|
38
|
-
readout.text = text ?? `Canvas X ${Math.round(x)} · Y ${Math.round(y)}`;
|
|
39
|
-
readout.rect = rect;
|
|
46
|
+
if (readout) setReadout(readout, { ...rect, angle: readout.baseRect.angle }, text);
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
export function updateGestureReadoutAngle(
|
|
43
50
|
readout: GestureReadoutState | undefined,
|
|
44
51
|
angle: number,
|
|
52
|
+
startAngle = 0,
|
|
45
53
|
): void {
|
|
46
|
-
if (readout)
|
|
54
|
+
if (!readout) return;
|
|
55
|
+
const turned = (readout.baseRect.angle ?? 0) + angle - startAngle;
|
|
56
|
+
setReadout(readout, { ...readout.baseRect, angle: turned }, `↻ ${Math.round(angle)}°`);
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
export function updateGestureReadoutSize(
|
|
@@ -51,5 +61,5 @@ export function updateGestureReadoutSize(
|
|
|
51
61
|
rect: OverlayRect,
|
|
52
62
|
size: { width: number; height: number },
|
|
53
63
|
): void {
|
|
54
|
-
updateGestureReadout(readout, rect,
|
|
64
|
+
updateGestureReadout(readout, rect, `W ${Math.round(size.width)} · H ${Math.round(size.height)}`);
|
|
55
65
|
}
|