@hyperframes/studio 0.8.230 → 0.8.231
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-Dv5Ew1Dr.js → hyperframes-player-ClW2l0Vl.js} +1 -1
- package/dist/assets/{index-hiL49K7x.js → index-CGfRmZQd.js} +1 -1
- package/dist/assets/{index-BvqtI0ko.js → index-DxWNzvQJ.js} +153 -153
- package/dist/index.d.ts +40 -0
- package/dist/index.html +1 -1
- package/dist/index.js +530 -432
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.tsx +7 -14
- package/src/captions/keyboard.test.ts +12 -1
- package/src/captions/keyboard.ts +8 -8
- package/src/components/EditorShell.tsx +2 -1
- package/src/components/TimelineToolbar.tsx +2 -3
- package/src/components/editor/InspectorHeaderActions.tsx +3 -1
- package/src/components/editor/PropertyPanelFlatHeader.tsx +3 -1
- package/src/components/editor/SnapToolbar.tsx +3 -3
- package/src/components/editor/domEditNudge.test.ts +17 -1
- package/src/components/editor/domEditNudge.ts +16 -13
- package/src/components/editor/marqueeCommit.ts +2 -1
- package/src/hooks/appHotkeysDispatch.ts +94 -107
- package/src/hooks/linkShortcuts.test.ts +20 -0
- package/src/hooks/linkShortcuts.ts +11 -11
- package/src/hooks/useAppHotkeys.test.ts +143 -0
- package/src/hooks/useAppHotkeys.ts +1 -4
- package/src/hooks/useAutomationSelectionKeyboard.ts +7 -18
- package/src/hooks/useKeyframeKeyboard.ts +2 -3
- package/src/hooks/useTimelineDeleteOps.ts +2 -1
- package/src/player/components/BeatStrip.tsx +2 -1
- package/src/player/components/ClipContextMenu.tsx +3 -3
- package/src/player/components/TimelineClipFades.tsx +2 -1
- package/src/player/components/clipMenuLinkItems.tsx +5 -4
- package/src/player/components/studioCombo.test.ts +99 -0
- package/src/player/components/studioCombo.ts +108 -0
- package/src/player/components/studioShortcuts.test.tsx +16 -1
- package/src/player/components/studioShortcuts.ts +85 -29
- package/src/player/components/timelineClipDragGestureLifecycle.ts +2 -1
- package/src/player/components/timelineEditing.ts +2 -2
- package/src/player/components/useTimelineClipDrag.ts +2 -1
- package/src/player/components/useTimelineKeyboardActor.ts +7 -18
- package/src/player/components/useTimelineKeyframeHandlers.ts +2 -1
- package/src/player/components/useTimelineRangeSelection.ts +3 -2
- package/src/player/hooks/usePlaybackKeyboard.test.ts +87 -4
- package/src/player/hooks/usePlaybackKeyboard.ts +78 -82
- package/src/player/hooks/useTimelinePlayer.test.ts +19 -13
- package/src/player/lib/playbackShortcuts.ts +13 -16
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
} from "../lib/playbackShortcuts";
|
|
16
16
|
import { canvasNudgeKeysClaimed } from "../../utils/canvasNudgeGate";
|
|
17
17
|
import { usePlayerStore } from "../store/playerStore";
|
|
18
|
-
import {
|
|
18
|
+
import { matchesKey, type StudioKeyAction } from "../components/studioShortcuts";
|
|
19
|
+
import { resolveCanvasNudgeDelta } from "../../components/editor/domEditNudge";
|
|
19
20
|
import { stepFrameTime } from "../lib/time";
|
|
20
21
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
21
22
|
import type { PlaybackAdapter } from "../lib/playbackTypes";
|
|
@@ -32,26 +33,61 @@ interface UsePlaybackKeyboardParams {
|
|
|
32
33
|
seek: (time: number, options?: { keepPlaying?: boolean }) => void;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
const FRAME_STEPS = {
|
|
37
|
+
frameBack: -1,
|
|
38
|
+
frameForward: 1,
|
|
39
|
+
frameBackTen: -10,
|
|
40
|
+
frameForwardTen: 10,
|
|
41
|
+
} as const;
|
|
42
|
+
const PLAYBACK_ACTIONS = [
|
|
43
|
+
"playPause",
|
|
44
|
+
...(Object.keys(FRAME_STEPS) as Array<keyof typeof FRAME_STEPS>),
|
|
45
|
+
"mute",
|
|
46
|
+
"loop",
|
|
47
|
+
"pause",
|
|
48
|
+
"shuttleBack",
|
|
49
|
+
"shuttleForward",
|
|
50
|
+
"inPoint",
|
|
51
|
+
"clearInPoint",
|
|
52
|
+
"outPoint",
|
|
53
|
+
"clearOutPoint",
|
|
54
|
+
"seekToIn",
|
|
55
|
+
"seekToOut",
|
|
56
|
+
] as const satisfies readonly StudioKeyAction[];
|
|
57
|
+
type PlaybackAction = (typeof PLAYBACK_ACTIONS)[number];
|
|
58
|
+
|
|
59
|
+
const playbackActionOf = (e: KeyboardEvent): PlaybackAction | undefined =>
|
|
60
|
+
PLAYBACK_ACTIONS.find((action) => matchesKey(e, action));
|
|
61
|
+
|
|
62
|
+
function ignoresPlaybackKey(e: KeyboardEvent): boolean {
|
|
63
|
+
const captionState = useCaptionStore.getState();
|
|
64
|
+
return shouldIgnorePlaybackShortcutEvent(e, {
|
|
65
|
+
isCaptionEditMode: captionState.isEditMode,
|
|
66
|
+
selectedCaptionSegmentCount: captionState.selectedSegmentIds.size,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
35
70
|
function handleWorkAreaKey(
|
|
36
71
|
e: KeyboardEvent,
|
|
37
|
-
|
|
72
|
+
action: PlaybackAction,
|
|
38
73
|
getAdapter: () => PlaybackAdapter | null,
|
|
39
74
|
seek: UsePlaybackKeyboardParams["seek"],
|
|
40
75
|
): boolean {
|
|
41
|
-
if (razorClaimsKey(e, key)) return false;
|
|
42
|
-
const keys = getStudioKeys();
|
|
43
76
|
const store = usePlayerStore.getState();
|
|
44
77
|
const time = () => getAdapter()?.getTime() ?? store.currentTime;
|
|
45
78
|
const end = () => store.outPoint ?? getAdapter()?.getDuration() ?? store.duration;
|
|
46
|
-
const actions: Record<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
79
|
+
const actions: Partial<Record<PlaybackAction, () => void>> = {
|
|
80
|
+
inPoint: () => store.setInPoint(time()),
|
|
81
|
+
clearInPoint: () => store.setInPoint(null),
|
|
82
|
+
outPoint: () => store.setOutPoint(time()),
|
|
83
|
+
clearOutPoint: () => store.setOutPoint(null),
|
|
84
|
+
seekToIn: () => seek(store.inPoint ?? 0, { keepPlaying: true }),
|
|
85
|
+
seekToOut: () => seek(end(), { keepPlaying: true }),
|
|
51
86
|
};
|
|
52
|
-
|
|
87
|
+
const run = actions[action];
|
|
88
|
+
if (!run || razorClaimsKey(e)) return false;
|
|
53
89
|
e.preventDefault();
|
|
54
|
-
|
|
90
|
+
run();
|
|
55
91
|
return true;
|
|
56
92
|
}
|
|
57
93
|
|
|
@@ -66,7 +102,7 @@ export function usePlaybackKeyboard({
|
|
|
66
102
|
pause,
|
|
67
103
|
seek,
|
|
68
104
|
}: UsePlaybackKeyboardParams) {
|
|
69
|
-
const
|
|
105
|
+
const heldPauseRef = useRef(new Set<string>());
|
|
70
106
|
const playbackKeyDownRef = useRef<(e: KeyboardEvent) => void>(() => {});
|
|
71
107
|
const playbackKeyUpRef = useRef<(e: KeyboardEvent) => void>(() => {});
|
|
72
108
|
|
|
@@ -111,87 +147,47 @@ export function usePlaybackKeyboard({
|
|
|
111
147
|
}
|
|
112
148
|
}, [play, pause]);
|
|
113
149
|
|
|
114
|
-
// Pre-existing dispatcher, already over the complexity gate before this
|
|
115
|
-
// branch's one-line "a" fix touched it. A real fix is a dispatch-table
|
|
116
|
-
// rewrite, out of scope here; the branch this PR changed is its own function.
|
|
117
|
-
// fallow-ignore-next-line complexity
|
|
118
150
|
const handlePlaybackKeyDown = useCallback(
|
|
119
151
|
(e: KeyboardEvent) => {
|
|
120
|
-
if (e.defaultPrevented) return;
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
selectedCaptionSegmentCount: captionState.selectedSegmentIds.size,
|
|
126
|
-
})
|
|
127
|
-
) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const key = e.key.toLowerCase();
|
|
131
|
-
const keys = getStudioKeys();
|
|
132
|
-
pressedKeysRef.current.add(key);
|
|
133
|
-
if (e.code === "Space") {
|
|
134
|
-
e.preventDefault();
|
|
135
|
-
togglePlay();
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
152
|
+
if (e.defaultPrevented || ignoresPlaybackKey(e)) return;
|
|
153
|
+
const action = playbackActionOf(e);
|
|
154
|
+
if (action === "pause") heldPauseRef.current.add(e.code || e.key);
|
|
155
|
+
if (!action) return;
|
|
156
|
+
const isFrameStep = action in FRAME_STEPS;
|
|
138
157
|
// A nudgeable canvas selection owns the arrow keys (DomEditOverlay moves
|
|
139
158
|
// the element); frame-stepping would double-handle the same keystroke.
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
stepFrames(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
state.setLoopEnabled(!state.loopEnabled);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (key === keys.pause) {
|
|
166
|
-
e.preventDefault();
|
|
167
|
-
pause();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (key === keys.shuttleBack) {
|
|
171
|
-
e.preventDefault();
|
|
172
|
-
if (pressedKeysRef.current.has(keys.pause)) {
|
|
173
|
-
stepFrames(-1);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
shuttle("backward");
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (key === keys.shuttleForward) {
|
|
180
|
-
e.preventDefault();
|
|
181
|
-
if (pressedKeysRef.current.has(keys.pause)) {
|
|
182
|
-
stepFrames(1);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
shuttle("forward");
|
|
159
|
+
if (isFrameStep && canvasNudgeKeysClaimed() && resolveCanvasNudgeDelta(e)) return;
|
|
160
|
+
if (e.repeat && action !== "playPause" && !isFrameStep) return;
|
|
161
|
+
const shuttleOrStep = (direction: -1 | 1) =>
|
|
162
|
+
heldPauseRef.current.size > 0
|
|
163
|
+
? stepFrames(direction)
|
|
164
|
+
: shuttle(direction < 0 ? "backward" : "forward");
|
|
165
|
+
const player = usePlayerStore.getState();
|
|
166
|
+
const run: Partial<Record<PlaybackAction, () => void>> = {
|
|
167
|
+
playPause: togglePlay,
|
|
168
|
+
frameBack: () => stepFrames(FRAME_STEPS.frameBack),
|
|
169
|
+
frameForward: () => stepFrames(FRAME_STEPS.frameForward),
|
|
170
|
+
frameBackTen: () => stepFrames(FRAME_STEPS.frameBackTen),
|
|
171
|
+
frameForwardTen: () => stepFrames(FRAME_STEPS.frameForwardTen),
|
|
172
|
+
mute: () => player.setAudioMuted(!player.audioMuted),
|
|
173
|
+
loop: () => player.setLoopEnabled(!player.loopEnabled),
|
|
174
|
+
pause,
|
|
175
|
+
shuttleBack: () => shuttleOrStep(-1),
|
|
176
|
+
shuttleForward: () => shuttleOrStep(1),
|
|
177
|
+
};
|
|
178
|
+
const act = run[action];
|
|
179
|
+
if (!act) {
|
|
180
|
+
handleWorkAreaKey(e, action, getAdapter, seek);
|
|
186
181
|
return;
|
|
187
182
|
}
|
|
188
|
-
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
act();
|
|
189
185
|
},
|
|
190
186
|
[pause, shuttle, stepFrames, togglePlay, getAdapter, seek],
|
|
191
187
|
);
|
|
192
188
|
|
|
193
189
|
const handlePlaybackKeyUp = useCallback((e: KeyboardEvent) => {
|
|
194
|
-
|
|
190
|
+
heldPauseRef.current.delete(e.code || e.key);
|
|
195
191
|
}, []);
|
|
196
192
|
|
|
197
193
|
playbackKeyDownRef.current = handlePlaybackKeyDown;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setStudioKeys } from "../components/studioShortcuts";
|
|
1
2
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
3
|
import { Window } from "happy-dom";
|
|
3
4
|
import {
|
|
@@ -48,8 +49,10 @@ function mockTargetMatching(selectorNeedle: string): EventTarget {
|
|
|
48
49
|
function mockKeyboardEvent(
|
|
49
50
|
code: string,
|
|
50
51
|
overrides: Partial<Pick<KeyboardEvent, "altKey" | "ctrlKey" | "metaKey" | "target">> = {},
|
|
51
|
-
): Pick<KeyboardEvent, "altKey" | "ctrlKey" | "metaKey" | "code" | "target"> {
|
|
52
|
+
): Pick<KeyboardEvent, "key" | "altKey" | "ctrlKey" | "metaKey" | "shiftKey" | "code" | "target"> {
|
|
52
53
|
return {
|
|
54
|
+
key: code,
|
|
55
|
+
shiftKey: false,
|
|
53
56
|
altKey: false,
|
|
54
57
|
ctrlKey: false,
|
|
55
58
|
metaKey: false,
|
|
@@ -556,18 +559,6 @@ describe("shouldIgnorePlaybackShortcutTarget", () => {
|
|
|
556
559
|
});
|
|
557
560
|
|
|
558
561
|
describe("shouldIgnorePlaybackShortcutEvent", () => {
|
|
559
|
-
it("ignores modified playback shortcuts so browser and app chords can handle them", () => {
|
|
560
|
-
expect(
|
|
561
|
-
shouldIgnorePlaybackShortcutEvent(mockKeyboardEvent("ArrowLeft", { altKey: true })),
|
|
562
|
-
).toBe(true);
|
|
563
|
-
expect(shouldIgnorePlaybackShortcutEvent(mockKeyboardEvent("KeyK", { ctrlKey: true }))).toBe(
|
|
564
|
-
true,
|
|
565
|
-
);
|
|
566
|
-
expect(shouldIgnorePlaybackShortcutEvent(mockKeyboardEvent("KeyL", { metaKey: true }))).toBe(
|
|
567
|
-
true,
|
|
568
|
-
);
|
|
569
|
-
});
|
|
570
|
-
|
|
571
562
|
it("defers Arrow frame shortcuts while caption edit mode has selected words", () => {
|
|
572
563
|
const captionSelection = { isCaptionEditMode: true, selectedCaptionSegmentCount: 1 };
|
|
573
564
|
|
|
@@ -582,6 +573,21 @@ describe("shouldIgnorePlaybackShortcutEvent", () => {
|
|
|
582
573
|
);
|
|
583
574
|
});
|
|
584
575
|
|
|
576
|
+
it("defers a remapped frame key, not the arrows, while caption words are selected", () => {
|
|
577
|
+
setStudioKeys({ frameBack: "," });
|
|
578
|
+
const captionSelection = { isCaptionEditMode: true, selectedCaptionSegmentCount: 1 };
|
|
579
|
+
expect(
|
|
580
|
+
shouldIgnorePlaybackShortcutEvent(
|
|
581
|
+
{ ...mockKeyboardEvent("Comma"), key: "," },
|
|
582
|
+
captionSelection,
|
|
583
|
+
),
|
|
584
|
+
).toBe(true);
|
|
585
|
+
expect(
|
|
586
|
+
shouldIgnorePlaybackShortcutEvent(mockKeyboardEvent("ArrowLeft"), captionSelection),
|
|
587
|
+
).toBe(false);
|
|
588
|
+
setStudioKeys(null);
|
|
589
|
+
});
|
|
590
|
+
|
|
585
591
|
it("allows Arrow frame shortcuts when captions are not selected", () => {
|
|
586
592
|
expect(
|
|
587
593
|
shouldIgnorePlaybackShortcutEvent(mockKeyboardEvent("ArrowRight"), {
|
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { ownsPlainKeys } from "../../utils/typingTarget";
|
|
10
|
-
import {
|
|
10
|
+
import type { ComboEvent } from "../components/studioCombo";
|
|
11
|
+
import { matchesKey } from "../components/studioShortcuts";
|
|
11
12
|
import { usePlayerStore } from "../store/playerStore";
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
+
const FRAME_STEP_ACTIONS = [
|
|
15
|
+
"frameBack",
|
|
16
|
+
"frameForward",
|
|
17
|
+
"frameBackTen",
|
|
18
|
+
"frameForwardTen",
|
|
19
|
+
] as const;
|
|
14
20
|
|
|
15
21
|
const PLAYBACK_SHORTCUT_IGNORED_SELECTOR = [
|
|
16
22
|
"button",
|
|
@@ -61,10 +67,7 @@ interface PlaybackShortcutCaptionState {
|
|
|
61
67
|
selectedCaptionSegmentCount: number;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
type PlaybackShortcutEvent = Pick<
|
|
65
|
-
KeyboardEvent,
|
|
66
|
-
"altKey" | "ctrlKey" | "metaKey" | "code" | "target"
|
|
67
|
-
>;
|
|
70
|
+
type PlaybackShortcutEvent = ComboEvent & Pick<KeyboardEvent, "target">;
|
|
68
71
|
|
|
69
72
|
export function shouldIgnorePlaybackShortcutEvent(
|
|
70
73
|
event: PlaybackShortcutEvent,
|
|
@@ -73,11 +76,10 @@ export function shouldIgnorePlaybackShortcutEvent(
|
|
|
73
76
|
selectedCaptionSegmentCount: 0,
|
|
74
77
|
},
|
|
75
78
|
): boolean {
|
|
76
|
-
if (event.metaKey || event.ctrlKey || event.altKey) return true;
|
|
77
79
|
if (shouldIgnorePlaybackShortcutTarget(event.target)) return true;
|
|
78
80
|
if (isModalDialogOpen()) return true;
|
|
79
81
|
return (
|
|
80
|
-
|
|
82
|
+
FRAME_STEP_ACTIONS.some((action) => matchesKey(event, action)) &&
|
|
81
83
|
captionState.isCaptionEditMode &&
|
|
82
84
|
captionState.selectedCaptionSegmentCount > 0
|
|
83
85
|
);
|
|
@@ -86,12 +88,7 @@ export function shouldIgnorePlaybackShortcutEvent(
|
|
|
86
88
|
/** JKL shuttle speeds (×1, ×2, ×4). */
|
|
87
89
|
export const SHUTTLE_SPEEDS = [1, 2, 4] as const;
|
|
88
90
|
|
|
89
|
-
/**
|
|
90
|
-
export function razorClaimsKey(e: KeyboardEvent
|
|
91
|
-
return (
|
|
92
|
-
key === getStudioKey("exitRazor") &&
|
|
93
|
-
!e.shiftKey &&
|
|
94
|
-
!e.altKey &&
|
|
95
|
-
usePlayerStore.getState().activeTool === "razor"
|
|
96
|
-
);
|
|
91
|
+
/** The exit-razor combo while the razor is armed: the razor owns it, playback must leave it alone. */
|
|
92
|
+
export function razorClaimsKey(e: KeyboardEvent): boolean {
|
|
93
|
+
return matchesKey(e, "exitRazor") && usePlayerStore.getState().activeTool === "razor";
|
|
97
94
|
}
|