@hyperframes/studio 0.9.15 → 0.9.17
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/{hyperframes-player-bkb0-LEY.js → hyperframes-player-CL-Qh_Bx.js} +1 -1
- package/dist/assets/{index-RUPGNyct.css → index-CNZk2EFC.css} +1 -1
- package/dist/assets/{index-DfsIam9M.js → index-DkiYRx1f.js} +137 -137
- package/dist/assets/{index-D5zessN9.js → index-DyvmaiBB.js} +1 -1
- package/dist/index.d.ts +17 -7
- package/dist/index.html +2 -2
- package/dist/index.js +112 -55
- package/dist/styles.css +1 -1
- package/package.json +8 -8
- package/src/components/editor/DomEditOverlay.tsx +3 -1
- package/src/components/editor/MarqueeOverlay.tsx +12 -4
- package/src/components/editor/marqueeCommit.test.tsx +137 -4
- package/src/components/editor/marqueeCommit.ts +30 -16
- package/src/components/editor/previewReadOnly.overlay.test.tsx +1 -1
- package/src/editorGesturesExports.test.tsx +10 -4
- package/src/hooks/useDomSelection.test.ts +90 -9
- package/src/hooks/useDomSelection.ts +21 -9
- package/src/hooks/useDomSelectionTypes.ts +5 -1
- package/src/hooks/useStudioUrlState.ts +3 -2
- package/src/hooks/useTimelineSelectionPreviewSync.test.tsx +6 -2
- package/src/hooks/useTimelineSelectionPreviewSync.ts +3 -2
- package/src/index.ts +6 -1
- package/src/player/components/TimelineCanvas.tsx +11 -3
- package/src/player/components/TimelineProvider.tsx +2 -2
- package/src/player/components/timelineMarquee.test.ts +68 -0
- package/src/player/components/timelineMarquee.ts +17 -5
- package/src/player/components/timelineMarqueeCommit.ts +74 -0
- package/src/player/components/useTimelineRangeSelection.test.tsx +98 -4
- package/src/player/components/useTimelineRangeSelection.ts +53 -103
- package/src/styles/theme.css +1 -0
- package/src/utils/marqueeGeometry.test.ts +18 -1
- package/src/utils/marqueeGeometry.ts +20 -0
- package/src/utils/studioUrlState.test.ts +1 -1
|
@@ -8,15 +8,18 @@ import {
|
|
|
8
8
|
import type { TimelineElement } from "../store/playerStore";
|
|
9
9
|
import { liveTime, usePlayerStore } from "../store/playerStore";
|
|
10
10
|
import { getTimelineScrubTime } from "./timelineLayout";
|
|
11
|
+
import { getMarqueeRect, isMarqueeDrag, isTimelineRulerPress } from "./timelineMarquee";
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
commitMarqueeSelection,
|
|
14
|
+
snapshotSelection,
|
|
15
|
+
type MarqueeDragState,
|
|
16
|
+
} from "./timelineMarqueeCommit";
|
|
17
|
+
import {
|
|
18
|
+
resolveMarqueeMode,
|
|
19
|
+
type MarqueeBand,
|
|
20
|
+
type MarqueeModifiers,
|
|
21
|
+
type MarqueeSelectionMode,
|
|
22
|
+
} from "../../utils/marqueeGeometry";
|
|
20
23
|
import type { TimelineRowGeometry } from "./timelineLayout";
|
|
21
24
|
import type { TimelineClipIndex } from "../lib/timelineClipIndex";
|
|
22
25
|
|
|
@@ -39,69 +42,7 @@ interface UseTimelineRangeSelectionInput {
|
|
|
39
42
|
sessionEpoch: number;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
originX: number;
|
|
44
|
-
originY: number;
|
|
45
|
-
/** Pre-drag selection, restored on Escape-cancel. */
|
|
46
|
-
baseIds: Set<string>;
|
|
47
|
-
basePrimary: string | null;
|
|
48
|
-
/** Union new hits with baseIds (shift/cmd/ctrl at pointerdown). */
|
|
49
|
-
additive: boolean;
|
|
50
|
-
/** True once the pointer travelled past the click threshold. */
|
|
51
|
-
active: boolean;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function snapshotSelection(): { ids: Set<string>; primary: string | null } {
|
|
55
|
-
const s = usePlayerStore.getState();
|
|
56
|
-
const ids = new Set(s.selectedElementIds);
|
|
57
|
-
if (s.selectedElementId) ids.add(s.selectedElementId);
|
|
58
|
-
return { ids, primary: s.selectedElementId };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function toMarqueeClips(elements: TimelineElement[]): MarqueeClipInput[] {
|
|
62
|
-
return elements.map((el) => ({
|
|
63
|
-
id: el.key ?? el.id,
|
|
64
|
-
start: el.start,
|
|
65
|
-
duration: el.duration,
|
|
66
|
-
track: el.track,
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Compute the live selection for a marquee rect and commit it to the store.
|
|
72
|
-
* Shift held mid-drag (or cmd/ctrl at pointerdown) unions the new hits with the
|
|
73
|
-
* pre-drag selection (marquee.baseIds / basePrimary).
|
|
74
|
-
*/
|
|
75
|
-
function commitMarqueeSelection(
|
|
76
|
-
rect: Rect,
|
|
77
|
-
additive: boolean,
|
|
78
|
-
marquee: MarqueeDragState,
|
|
79
|
-
clipIndex: TimelineClipIndex,
|
|
80
|
-
rowGeometry: TimelineRowGeometry,
|
|
81
|
-
pps: number,
|
|
82
|
-
contentOrigin: number,
|
|
83
|
-
): void {
|
|
84
|
-
const candidates = getMarqueeClipCandidates({
|
|
85
|
-
clipIndex,
|
|
86
|
-
rowGeometry,
|
|
87
|
-
marquee: rect,
|
|
88
|
-
pps,
|
|
89
|
-
contentOrigin,
|
|
90
|
-
});
|
|
91
|
-
const { ids, primaryId } = computeMarqueeSelection({
|
|
92
|
-
clips: toMarqueeClips([...candidates]),
|
|
93
|
-
rowGeometry,
|
|
94
|
-
pps,
|
|
95
|
-
contentOrigin,
|
|
96
|
-
marquee: rect,
|
|
97
|
-
baseSelection: additive ? marquee.baseIds : undefined,
|
|
98
|
-
});
|
|
99
|
-
const store = usePlayerStore.getState();
|
|
100
|
-
// Primary FIRST: setSelectedElementId collapses the multi-select set, so the set
|
|
101
|
-
// must be written after it or the marquee selection would be wiped every frame.
|
|
102
|
-
store.setSelectedElementId(primaryId ?? (additive ? marquee.basePrimary : null));
|
|
103
|
-
store.setSelectedElementIds(ids);
|
|
104
|
-
}
|
|
45
|
+
type MarqueePointer = { clientX: number; clientY: number } & MarqueeModifiers;
|
|
105
46
|
|
|
106
47
|
function canStartPointerGesture(
|
|
107
48
|
event: React.PointerEvent,
|
|
@@ -166,13 +107,10 @@ export function useTimelineRangeSelection({
|
|
|
166
107
|
|
|
167
108
|
// Marquee (rubber-band) multi-select on the empty timeline body.
|
|
168
109
|
const marqueeRef = useRef<MarqueeDragState | null>(null);
|
|
169
|
-
const [marqueeRect, setMarqueeRect] = useState<
|
|
170
|
-
// Edge auto-scroll
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
const marqueePointerRef = useRef<{ clientX: number; clientY: number; shiftKey: boolean } | null>(
|
|
174
|
-
null,
|
|
175
|
-
);
|
|
110
|
+
const [marqueeRect, setMarqueeRect] = useState<MarqueeBand | null>(null);
|
|
111
|
+
// Edge auto-scroll: the last client-space pointer and modifiers, re-applied each
|
|
112
|
+
// RAF frame while the view scrolls, so the marquee can extend past the visible area.
|
|
113
|
+
const marqueePointerRef = useRef<MarqueePointer | null>(null);
|
|
176
114
|
const marqueeScrollRaf = useRef(0);
|
|
177
115
|
|
|
178
116
|
/** Pointer position → canvas/content coordinates (same space as clip rects). */
|
|
@@ -194,7 +132,7 @@ export function useTimelineRangeSelection({
|
|
|
194
132
|
// view scrolls naturally extends the rect toward the newly revealed area.
|
|
195
133
|
// Shared by the pointermove handler and the edge auto-scroll stepper.
|
|
196
134
|
const applyMarqueeAtClient = useCallback(
|
|
197
|
-
(clientX: number, clientY: number,
|
|
135
|
+
(clientX: number, clientY: number, modifiers: MarqueeModifiers) => {
|
|
198
136
|
const marquee = marqueeRef.current;
|
|
199
137
|
if (!marquee || !isGestureSessionCurrent()) return;
|
|
200
138
|
const point = toContentPoint(clientX, clientY);
|
|
@@ -204,13 +142,13 @@ export function useTimelineRangeSelection({
|
|
|
204
142
|
}
|
|
205
143
|
marquee.active = true;
|
|
206
144
|
const rect = getMarqueeRect(marquee.originX, marquee.originY, point.x, point.y);
|
|
207
|
-
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
145
|
+
// Live selection: every clip the box currently covers. Shift held mid-drag
|
|
146
|
+
// (or cmd/ctrl at pointerdown) adds to the prior selection; Alt removes.
|
|
147
|
+
const mode = resolveMarqueeMode(modifiers, marquee.mode);
|
|
148
|
+
setMarqueeRect({ ...rect, mode });
|
|
211
149
|
commitMarqueeSelection(
|
|
212
150
|
rect,
|
|
213
|
-
|
|
151
|
+
mode,
|
|
214
152
|
marquee,
|
|
215
153
|
clipIndex,
|
|
216
154
|
rowGeometryRef.current,
|
|
@@ -246,13 +184,13 @@ export function useTimelineRangeSelection({
|
|
|
246
184
|
|
|
247
185
|
// Re-run at the SAME client point: toContentPoint folds in the new scroll, so
|
|
248
186
|
// the marquee's moving corner tracks the revealed content.
|
|
249
|
-
applyMarqueeAtClient(pointer.clientX, pointer.clientY, pointer
|
|
187
|
+
applyMarqueeAtClient(pointer.clientX, pointer.clientY, pointer);
|
|
250
188
|
marqueeScrollRaf.current = requestAnimationFrame(stepMarqueeAutoScroll);
|
|
251
189
|
}, [scrollRef, applyMarqueeAtClient, isGestureSessionCurrent]);
|
|
252
190
|
|
|
253
191
|
const syncMarqueeAutoScroll = useCallback(
|
|
254
|
-
(clientX: number, clientY: number,
|
|
255
|
-
marqueePointerRef.current = { clientX, clientY,
|
|
192
|
+
(clientX: number, clientY: number, modifiers: MarqueeModifiers) => {
|
|
193
|
+
marqueePointerRef.current = { clientX, clientY, ...modifiers };
|
|
256
194
|
const action = resolveTimelineAutoScrollLoopAction(
|
|
257
195
|
scrollRef.current,
|
|
258
196
|
clientX,
|
|
@@ -298,17 +236,20 @@ export function useTimelineRangeSelection({
|
|
|
298
236
|
[isDragging, seekFromX],
|
|
299
237
|
);
|
|
300
238
|
|
|
301
|
-
const beginMarquee = useCallback(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
239
|
+
const beginMarquee = useCallback(
|
|
240
|
+
(point: { x: number; y: number }, mode: MarqueeSelectionMode) => {
|
|
241
|
+
const base = snapshotSelection();
|
|
242
|
+
marqueeRef.current = {
|
|
243
|
+
originX: point.x,
|
|
244
|
+
originY: point.y,
|
|
245
|
+
baseIds: base.ids,
|
|
246
|
+
basePrimary: base.primary,
|
|
247
|
+
mode,
|
|
248
|
+
active: false,
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
[],
|
|
252
|
+
);
|
|
312
253
|
|
|
313
254
|
const handlePointerDown = useCallback(
|
|
314
255
|
(e: React.PointerEvent) => {
|
|
@@ -335,7 +276,7 @@ export function useTimelineRangeSelection({
|
|
|
335
276
|
}
|
|
336
277
|
// Empty body press → pending marquee. A plain click (no drag past the
|
|
337
278
|
// threshold) deselects on pointerup; a drag draws the marquee. Never scrubs.
|
|
338
|
-
beginMarquee(point, e.metaKey || e.ctrlKey);
|
|
279
|
+
beginMarquee(point, e.metaKey || e.ctrlKey ? "add" : "replace");
|
|
339
280
|
},
|
|
340
281
|
[beginRangeSelection, beginScrub, beginMarquee, scrollRef, setShowPopover, toContentPoint],
|
|
341
282
|
);
|
|
@@ -398,10 +339,10 @@ export function useTimelineRangeSelection({
|
|
|
398
339
|
}
|
|
399
340
|
const marquee = marqueeRef.current;
|
|
400
341
|
if (marquee) {
|
|
401
|
-
applyMarqueeAtClient(e.clientX, e.clientY, e
|
|
342
|
+
applyMarqueeAtClient(e.clientX, e.clientY, e);
|
|
402
343
|
// Edge auto-scroll: once the drag is live, scroll when the pointer nears
|
|
403
344
|
// a viewport edge so the marquee can extend past the visible area.
|
|
404
|
-
if (marquee.active) syncMarqueeAutoScroll(e.clientX, e.clientY, e
|
|
345
|
+
if (marquee.active) syncMarqueeAutoScroll(e.clientX, e.clientY, e);
|
|
405
346
|
return;
|
|
406
347
|
}
|
|
407
348
|
if (!isDragging.current) return;
|
|
@@ -475,20 +416,29 @@ export function useTimelineRangeSelection({
|
|
|
475
416
|
const handlePointerUp = useCallback(
|
|
476
417
|
(e?: React.PointerEvent) => {
|
|
477
418
|
if (!canFinishPointerGesture(e)) return;
|
|
419
|
+
const marquee = marqueeRef.current;
|
|
420
|
+
// The modifiers held at release decide, as on the canvas.
|
|
421
|
+
if (e && marquee?.active) applyMarqueeAtClient(e.clientX, e.clientY, e);
|
|
478
422
|
activePointerIdRef.current = null;
|
|
479
423
|
gestureEpochRef.current = null;
|
|
480
424
|
if (isRangeSelecting.current) {
|
|
481
425
|
finishRangeSelection();
|
|
482
426
|
return;
|
|
483
427
|
}
|
|
484
|
-
const marquee = marqueeRef.current;
|
|
485
428
|
if (marquee) {
|
|
486
429
|
finishMarquee(marquee);
|
|
487
430
|
return;
|
|
488
431
|
}
|
|
489
432
|
if (isDragging.current) finishScrub();
|
|
490
433
|
},
|
|
491
|
-
[
|
|
434
|
+
[
|
|
435
|
+
canFinishPointerGesture,
|
|
436
|
+
finishRangeSelection,
|
|
437
|
+
finishMarquee,
|
|
438
|
+
finishScrub,
|
|
439
|
+
isDragging,
|
|
440
|
+
applyMarqueeAtClient,
|
|
441
|
+
],
|
|
492
442
|
);
|
|
493
443
|
|
|
494
444
|
const cancelActiveGesture = useCallback(
|
package/src/styles/theme.css
CHANGED
|
@@ -196,6 +196,7 @@
|
|
|
196
196
|
--timeline-accent-hover: var(--color-on-hover);
|
|
197
197
|
--timeline-accent-button-bg: var(--color-on);
|
|
198
198
|
--timeline-danger: color-mix(in oklab, var(--color-danger) 70%, transparent);
|
|
199
|
+
--timeline-danger-fill: color-mix(in oklab, var(--color-danger) 10%, transparent);
|
|
199
200
|
--timeline-info-bg: rgba(59, 130, 246, 0.12);
|
|
200
201
|
--timeline-info-border: rgba(59, 130, 246, 0.4);
|
|
201
202
|
--timeline-dialog-bg: var(--color-raised);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { rectsOverlap } from "./marqueeGeometry";
|
|
2
|
+
import { rectsOverlap, resolveMarqueeMode } from "./marqueeGeometry";
|
|
3
3
|
|
|
4
4
|
describe("rectsOverlap", () => {
|
|
5
5
|
it("overlapping rects", () => {
|
|
@@ -38,3 +38,20 @@ describe("rectsOverlap", () => {
|
|
|
38
38
|
).toBe(true);
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
|
+
|
|
42
|
+
describe("resolveMarqueeMode", () => {
|
|
43
|
+
it("replaces with no modifier, adds with Shift, subtracts with Alt", () => {
|
|
44
|
+
expect(resolveMarqueeMode({ shiftKey: false, altKey: false })).toBe("replace");
|
|
45
|
+
expect(resolveMarqueeMode({ shiftKey: true, altKey: false })).toBe("add");
|
|
46
|
+
expect(resolveMarqueeMode({ shiftKey: false, altKey: true })).toBe("subtract");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("lets Alt win over Shift", () => {
|
|
50
|
+
expect(resolveMarqueeMode({ shiftKey: true, altKey: true })).toBe("subtract");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("keeps the base mode when no modifier is held", () => {
|
|
54
|
+
expect(resolveMarqueeMode({ shiftKey: false, altKey: false }, "add")).toBe("add");
|
|
55
|
+
expect(resolveMarqueeMode({ shiftKey: false, altKey: true }, "add")).toBe("subtract");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -13,3 +13,23 @@ export function rectsOverlap(a: Rect, b: Rect): boolean {
|
|
|
13
13
|
a.top + a.height > b.top
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
export type MarqueeSelectionMode = "replace" | "add" | "subtract";
|
|
18
|
+
|
|
19
|
+
export interface MarqueeBand extends Rect {
|
|
20
|
+
mode: MarqueeSelectionMode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MarqueeModifiers {
|
|
24
|
+
shiftKey: boolean;
|
|
25
|
+
altKey: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function resolveMarqueeMode(
|
|
29
|
+
modifiers: MarqueeModifiers,
|
|
30
|
+
base: MarqueeSelectionMode = "replace",
|
|
31
|
+
): MarqueeSelectionMode {
|
|
32
|
+
if (modifiers.altKey) return "subtract";
|
|
33
|
+
if (modifiers.shiftKey) return "add";
|
|
34
|
+
return base;
|
|
35
|
+
}
|
|
@@ -218,7 +218,7 @@ describe("studio url state", () => {
|
|
|
218
218
|
await act(async () => {
|
|
219
219
|
await Promise.resolve();
|
|
220
220
|
});
|
|
221
|
-
expect(applyMarqueeSelection).toHaveBeenCalledWith([primary, member],
|
|
221
|
+
expect(applyMarqueeSelection).toHaveBeenCalledWith([primary, member], "replace");
|
|
222
222
|
harness.unmount();
|
|
223
223
|
});
|
|
224
224
|
|