@flycut/timeline-kit 0.0.0-stage → 0.2.0
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/LICENSE +661 -0
- package/README.md +225 -2
- package/dist/chunks/TimelineEditor-N6_Yud4z.js +2046 -0
- package/dist/chunks/TimelineEditor-N6_Yud4z.js.map +1 -0
- package/dist/chunks/index-KK9cAE8q.js +661 -0
- package/dist/chunks/index-KK9cAE8q.js.map +1 -0
- package/dist/chunks/interactionManager-JoPxZ8st.js +775 -0
- package/dist/chunks/interactionManager-JoPxZ8st.js.map +1 -0
- package/dist/chunks/otio-6KO_Tfi1.js +510 -0
- package/dist/chunks/otio-6KO_Tfi1.js.map +1 -0
- package/dist/core.js +1673 -0
- package/dist/core.js.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/otio.js +313 -0
- package/dist/otio.js.map +1 -0
- package/dist/plugins.js +243 -0
- package/dist/plugins.js.map +1 -0
- package/dist/react.js +259 -0
- package/dist/react.js.map +1 -0
- package/dist/types/adapters/react/index.d.ts +45 -0
- package/dist/types/adapters/vue/index.d.ts +202 -0
- package/dist/types/src/adapters/otio.d.ts +7 -0
- package/dist/types/src/core-entry.d.ts +8 -0
- package/dist/types/src/editor/TimelineEditor.d.ts +96 -0
- package/dist/types/src/editor/index.d.ts +2 -0
- package/dist/types/src/editor/types.d.ts +30 -0
- package/dist/types/src/engine/hitTest.d.ts +23 -0
- package/dist/types/src/engine/index.d.ts +7 -0
- package/dist/types/src/engine/layout.d.ts +47 -0
- package/dist/types/src/engine/magnet.d.ts +46 -0
- package/dist/types/src/engine/placement.d.ts +13 -0
- package/dist/types/src/engine/snap.d.ts +28 -0
- package/dist/types/src/engine/timeScale.d.ts +12 -0
- package/dist/types/src/engine/virtualization.d.ts +11 -0
- package/dist/types/src/frameworks/slotBridge.d.ts +13 -0
- package/dist/types/src/index.d.ts +10 -0
- package/dist/types/src/model/demoDocument.d.ts +3 -0
- package/dist/types/src/model/index.d.ts +4 -0
- package/dist/types/src/model/operations.d.ts +77 -0
- package/dist/types/src/model/structuralSharing.d.ts +11 -0
- package/dist/types/src/model/types.d.ts +55 -0
- package/dist/types/src/otio-core/commands/create.d.ts +6 -0
- package/dist/types/src/otio-core/commands/helpers.d.ts +5 -0
- package/dist/types/src/otio-core/commands/insert.d.ts +2 -0
- package/dist/types/src/otio-core/commands/move.d.ts +2 -0
- package/dist/types/src/otio-core/commands/split.d.ts +2 -0
- package/dist/types/src/otio-core/commands/trim.d.ts +3 -0
- package/dist/types/src/otio-core/flycut-otio-draft.d.ts +239 -0
- package/dist/types/src/otio-core/guards.d.ts +5 -0
- package/dist/types/src/otio-core/index.d.ts +14 -0
- package/dist/types/src/otio-core/media/clipMetadata.d.ts +18 -0
- package/dist/types/src/otio-core/media/reference.d.ts +9 -0
- package/dist/types/src/otio-core/selectors/clip.d.ts +4 -0
- package/dist/types/src/otio-core/selectors/timeline.d.ts +5 -0
- package/dist/types/src/otio-core/selectors/track.d.ts +8 -0
- package/dist/types/src/otio-core/types.d.ts +61 -0
- package/dist/types/src/otio-entry.d.ts +2 -0
- package/dist/types/src/plugins/clipDragPlugin.d.ts +2 -0
- package/dist/types/src/plugins/clipTrimPlugin.d.ts +2 -0
- package/dist/types/src/plugins/externalDropPlugin.d.ts +13 -0
- package/dist/types/src/plugins/index.d.ts +17 -0
- package/dist/types/src/plugins/interactionManager.d.ts +33 -0
- package/dist/types/src/plugins/marqueeSelectPlugin.d.ts +2 -0
- package/dist/types/src/plugins/playheadPlugin.d.ts +2 -0
- package/dist/types/src/plugins/selectionPlugin.d.ts +2 -0
- package/dist/types/src/plugins/shortcutsPlugin.d.ts +7 -0
- package/dist/types/src/plugins/snapProviders.d.ts +9 -0
- package/dist/types/src/plugins/types.d.ts +110 -0
- package/dist/types/src/plugins/wheelPlugin.d.ts +2 -0
- package/dist/types/src/plugins-entry.d.ts +1 -0
- package/dist/types/src/renderer/domRenderer.d.ts +72 -0
- package/dist/types/src/renderer/index.d.ts +6 -0
- package/dist/types/src/renderer/ruler.d.ts +18 -0
- package/dist/types/src/renderer/styles.d.ts +1 -0
- package/dist/types/src/renderer/types.d.ts +65 -0
- package/dist/types/src/renderer/ui/icons.d.ts +7 -0
- package/dist/types/src/renderer/ui/sidebar.d.ts +14 -0
- package/dist/types/src/renderer/ui/toolbar.d.ts +16 -0
- package/dist/types/src/store/builtinCommands.d.ts +56 -0
- package/dist/types/src/store/commandBus.d.ts +18 -0
- package/dist/types/src/store/index.d.ts +4 -0
- package/dist/types/src/store/store.d.ts +53 -0
- package/dist/types/src/store/types.d.ts +59 -0
- package/dist/types/src/utils/trimOffset.d.ts +9 -0
- package/dist/vue.js +278 -0
- package/dist/vue.js.map +1 -0
- package/package.json +111 -4
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* timeline-kit
|
|
3
|
+
* Copyright (c) 2026 timeline-kit authors <x007xyzabc@gmail.com>
|
|
4
|
+
* Dual-licensed: AGPL-3.0-only (see LICENSE) or a commercial license.
|
|
5
|
+
* Commercial licensing: x007xyzabc@gmail.com
|
|
6
|
+
*/
|
|
7
|
+
import { s as resolveTargetTrack, r as pxToMs, e as detectMagnetState, d as collectSnapPoints, f as findBestSnap, k as getMagnetPreviewTransforms, p as msToPx, g as frameToMs, b as clampTrackScale, l as getPixelsPerSecond } from "./interactionManager-JoPxZ8st.js";
|
|
8
|
+
function getInsertGuidelineY(layout, insertIndex) {
|
|
9
|
+
if (layout.tracks.length === 0) {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
if (insertIndex <= 0) {
|
|
13
|
+
return layout.tracks[0].startY - 3;
|
|
14
|
+
}
|
|
15
|
+
const prevTrack = layout.tracks[Math.min(insertIndex - 1, layout.tracks.length - 1)];
|
|
16
|
+
return prevTrack.endY + 1;
|
|
17
|
+
}
|
|
18
|
+
function createClipDragPlugin() {
|
|
19
|
+
return {
|
|
20
|
+
name: "builtin:clip-drag",
|
|
21
|
+
interactions: [
|
|
22
|
+
{
|
|
23
|
+
id: "clip-drag",
|
|
24
|
+
priority: 70,
|
|
25
|
+
onPointerDown(event, ctx) {
|
|
26
|
+
if (event.hit.zone !== "clip-body" || event.button !== 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (event.metaKey || event.ctrlKey) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const clipId = event.hit.clipId;
|
|
33
|
+
if (!clipId) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const state = ctx.store.getState();
|
|
37
|
+
const sourceTrack = state.document.tracks[event.hit.trackIndex];
|
|
38
|
+
const sourceClip = sourceTrack?.clips[event.hit.clipIndex];
|
|
39
|
+
if (!sourceTrack || !sourceClip) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (sourceTrack.locked === true) {
|
|
43
|
+
ctx.commands.execute("selection:clear");
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
ctx.renderer.focusContainer?.();
|
|
47
|
+
if (state.selection.clipId !== clipId) {
|
|
48
|
+
ctx.commands.execute("selection:set", { clipIds: [clipId], clipId });
|
|
49
|
+
}
|
|
50
|
+
const layout = ctx.renderer.getLayout();
|
|
51
|
+
const layoutClip = layout.tracks[event.hit.trackIndex]?.clips[event.hit.clipIndex];
|
|
52
|
+
if (!layoutClip) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const originLeftPx = layoutClip.leftPx;
|
|
56
|
+
const originWidthPx = Math.max(layoutClip.widthPx, 32);
|
|
57
|
+
const startClientX = event.clientX;
|
|
58
|
+
const startClientY = event.clientY;
|
|
59
|
+
const durationMs = Math.max(0, sourceClip.endMs - sourceClip.startMs);
|
|
60
|
+
let pending = true;
|
|
61
|
+
let currentLeftPx = originLeftPx;
|
|
62
|
+
let snappedStartMs;
|
|
63
|
+
let previewedClipIds = [];
|
|
64
|
+
const clearMagnetPreviews = () => {
|
|
65
|
+
for (const previewId of previewedClipIds) {
|
|
66
|
+
if (previewId !== clipId) {
|
|
67
|
+
ctx.renderer.setClipPreview(previewId, null);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
previewedClipIds = [];
|
|
71
|
+
};
|
|
72
|
+
event.originalEvent.preventDefault();
|
|
73
|
+
return {
|
|
74
|
+
onMove(moveEvent) {
|
|
75
|
+
if (pending) {
|
|
76
|
+
const movedX = Math.abs(moveEvent.clientX - startClientX);
|
|
77
|
+
const movedY = Math.abs(moveEvent.clientY - startClientY);
|
|
78
|
+
if (movedX < 3 && movedY < 3) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
pending = false;
|
|
82
|
+
}
|
|
83
|
+
const activeState = ctx.store.getState();
|
|
84
|
+
const activeLayout = ctx.renderer.getLayout();
|
|
85
|
+
const policies = ctx.getPolicies();
|
|
86
|
+
const deltaX = moveEvent.clientX - startClientX;
|
|
87
|
+
const deltaY = moveEvent.clientY - startClientY;
|
|
88
|
+
let nextLeftPx = Math.max(0, originLeftPx + deltaX);
|
|
89
|
+
const targetTrackInfo = resolveTargetTrack(
|
|
90
|
+
activeState.document.tracks,
|
|
91
|
+
activeLayout.tracks,
|
|
92
|
+
moveEvent.hit.y,
|
|
93
|
+
sourceClip,
|
|
94
|
+
{
|
|
95
|
+
targetStartMs: pxToMs(nextLeftPx, activeLayout.pixelsPerSecond),
|
|
96
|
+
sourceTrackIndex: event.hit.trackIndex,
|
|
97
|
+
magnetEnabled: activeState.isMagnetEnabled,
|
|
98
|
+
policies
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
const magnetDetection = detectMagnetState({
|
|
102
|
+
tracks: activeState.document.tracks,
|
|
103
|
+
tracksLayout: activeLayout.tracks,
|
|
104
|
+
targetTrackIndex: targetTrackInfo.insertIndex,
|
|
105
|
+
isNewTrack: targetTrackInfo.isNewTrack,
|
|
106
|
+
targetX: nextLeftPx,
|
|
107
|
+
cursorX: moveEvent.hit.x,
|
|
108
|
+
dragClipDurationMs: durationMs,
|
|
109
|
+
sourceTrackIndex: event.hit.trackIndex,
|
|
110
|
+
sourceClipId: clipId,
|
|
111
|
+
pixelToMs: (px) => pxToMs(px, activeLayout.pixelsPerSecond),
|
|
112
|
+
magnetEnabled: activeState.isMagnetEnabled
|
|
113
|
+
});
|
|
114
|
+
snappedStartMs = void 0;
|
|
115
|
+
let verticalGuidelinePx = null;
|
|
116
|
+
if (!magnetDetection.magnetState) {
|
|
117
|
+
const snapPoints = collectSnapPoints(ctx.getSnapProviders(), {
|
|
118
|
+
layout: activeLayout,
|
|
119
|
+
currentFrame: activeState.currentFrame,
|
|
120
|
+
excludeClipIds: /* @__PURE__ */ new Set([clipId]),
|
|
121
|
+
targetLeftPx: nextLeftPx,
|
|
122
|
+
durationMs
|
|
123
|
+
});
|
|
124
|
+
const snapResult = findBestSnap(
|
|
125
|
+
nextLeftPx,
|
|
126
|
+
durationMs,
|
|
127
|
+
snapPoints,
|
|
128
|
+
activeLayout.pixelsPerSecond,
|
|
129
|
+
10
|
|
130
|
+
);
|
|
131
|
+
if (snapResult) {
|
|
132
|
+
nextLeftPx = snapResult.leftPx;
|
|
133
|
+
snappedStartMs = snapResult.startMs;
|
|
134
|
+
verticalGuidelinePx = snapResult.guidelineX;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
currentLeftPx = nextLeftPx;
|
|
138
|
+
ctx.renderer.setClipPreview(clipId, {
|
|
139
|
+
leftPx: nextLeftPx,
|
|
140
|
+
translateY: deltaY,
|
|
141
|
+
isDragging: true
|
|
142
|
+
});
|
|
143
|
+
clearMagnetPreviews();
|
|
144
|
+
if (magnetDetection.magnetState) {
|
|
145
|
+
const targetLayout = activeLayout.tracks[magnetDetection.magnetState.targetTrackIndex];
|
|
146
|
+
const transforms = getMagnetPreviewTransforms(
|
|
147
|
+
magnetDetection.magnetState,
|
|
148
|
+
clipId,
|
|
149
|
+
(ms) => msToPx(ms, activeLayout.pixelsPerSecond),
|
|
150
|
+
targetLayout
|
|
151
|
+
);
|
|
152
|
+
for (const transform of transforms) {
|
|
153
|
+
ctx.renderer.setClipPreview(transform.clipId, {
|
|
154
|
+
translateX: transform.offsetX
|
|
155
|
+
});
|
|
156
|
+
previewedClipIds.push(transform.clipId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (targetTrackInfo.isNewTrack) {
|
|
160
|
+
ctx.renderer.setOverlay({
|
|
161
|
+
verticalGuidelinePx,
|
|
162
|
+
horizontalGuidelinePx: getInsertGuidelineY(activeLayout, targetTrackInfo.insertIndex),
|
|
163
|
+
dragPreview: null
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
const targetLayout = activeLayout.tracks[targetTrackInfo.insertIndex];
|
|
167
|
+
ctx.renderer.setOverlay({
|
|
168
|
+
verticalGuidelinePx,
|
|
169
|
+
horizontalGuidelinePx: null,
|
|
170
|
+
dragPreview: targetLayout && !magnetDetection.magnetState ? {
|
|
171
|
+
leftPx: nextLeftPx,
|
|
172
|
+
topPx: targetLayout.startY,
|
|
173
|
+
widthPx: originWidthPx,
|
|
174
|
+
heightPx: targetLayout.height
|
|
175
|
+
} : null
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
onEnd(endEvent) {
|
|
180
|
+
clearMagnetPreviews();
|
|
181
|
+
ctx.renderer.clearAllClipPreviews();
|
|
182
|
+
ctx.renderer.clearOverlay();
|
|
183
|
+
if (pending) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const activeState = ctx.store.getState();
|
|
187
|
+
const activeLayout = ctx.renderer.getLayout();
|
|
188
|
+
const policies = ctx.getPolicies();
|
|
189
|
+
const startMs = snappedStartMs ?? Math.max(0, Math.round(pxToMs(currentLeftPx, activeLayout.pixelsPerSecond)));
|
|
190
|
+
const endMs = startMs + durationMs;
|
|
191
|
+
const targetInfo = resolveTargetTrack(
|
|
192
|
+
activeState.document.tracks,
|
|
193
|
+
activeLayout.tracks,
|
|
194
|
+
endEvent.hit.y,
|
|
195
|
+
sourceClip,
|
|
196
|
+
{
|
|
197
|
+
targetStartMs: startMs,
|
|
198
|
+
sourceTrackIndex: event.hit.trackIndex,
|
|
199
|
+
magnetEnabled: activeState.isMagnetEnabled,
|
|
200
|
+
policies
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
const magnetDetection = detectMagnetState({
|
|
204
|
+
tracks: activeState.document.tracks,
|
|
205
|
+
tracksLayout: activeLayout.tracks,
|
|
206
|
+
targetTrackIndex: targetInfo.insertIndex,
|
|
207
|
+
isNewTrack: targetInfo.isNewTrack,
|
|
208
|
+
targetX: currentLeftPx,
|
|
209
|
+
cursorX: endEvent.hit.x,
|
|
210
|
+
dragClipDurationMs: durationMs,
|
|
211
|
+
sourceTrackIndex: event.hit.trackIndex,
|
|
212
|
+
sourceClipId: clipId,
|
|
213
|
+
pixelToMs: (px) => pxToMs(px, activeLayout.pixelsPerSecond),
|
|
214
|
+
magnetEnabled: activeState.isMagnetEnabled
|
|
215
|
+
});
|
|
216
|
+
if (magnetDetection.magnetState) {
|
|
217
|
+
ctx.commands.execute("clip:magnet-move", {
|
|
218
|
+
sourceTrackIndex: event.hit.trackIndex,
|
|
219
|
+
sourceClipIndex: event.hit.clipIndex,
|
|
220
|
+
targetTrackIndex: magnetDetection.magnetState.targetTrackIndex,
|
|
221
|
+
insertPosition: magnetDetection.magnetState.insertPosition,
|
|
222
|
+
previewArrangement: magnetDetection.magnetState.previewArrangement,
|
|
223
|
+
dragClipDurationMs: magnetDetection.magnetState.dragClipDurationMs
|
|
224
|
+
});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
ctx.commands.execute("clip:move", {
|
|
228
|
+
sourceTrackIndex: event.hit.trackIndex,
|
|
229
|
+
sourceClipIndex: event.hit.clipIndex,
|
|
230
|
+
targetTrackIndex: targetInfo.insertIndex,
|
|
231
|
+
isNewTrack: targetInfo.isNewTrack,
|
|
232
|
+
startMs,
|
|
233
|
+
endMs,
|
|
234
|
+
clipType: sourceClip.type
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
onCancel() {
|
|
238
|
+
clearMagnetPreviews();
|
|
239
|
+
ctx.renderer.clearAllClipPreviews();
|
|
240
|
+
ctx.renderer.clearOverlay();
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const MIN_TRIM_VISUAL_PX = 24;
|
|
249
|
+
function createClipTrimPlugin() {
|
|
250
|
+
return {
|
|
251
|
+
name: "builtin:clip-trim",
|
|
252
|
+
interactions: [
|
|
253
|
+
{
|
|
254
|
+
id: "clip-trim",
|
|
255
|
+
priority: 80,
|
|
256
|
+
onPointerDown(event, ctx) {
|
|
257
|
+
if (event.hit.zone !== "trim-start" && event.hit.zone !== "trim-end") {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
const clipId = event.hit.clipId;
|
|
261
|
+
if (!clipId) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
const state = ctx.store.getState();
|
|
265
|
+
const track = state.document.tracks[event.hit.trackIndex];
|
|
266
|
+
const clip = track?.clips[event.hit.clipIndex];
|
|
267
|
+
if (!track || !clip || track.locked === true) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
const layout = ctx.renderer.getLayout();
|
|
271
|
+
const layoutClip = layout.tracks[event.hit.trackIndex]?.clips[event.hit.clipIndex];
|
|
272
|
+
if (!layoutClip) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
ctx.renderer.focusContainer?.();
|
|
276
|
+
ctx.commands.execute("selection:set", { clipIds: [clipId], clipId });
|
|
277
|
+
const edge = event.hit.zone === "trim-start" ? "start" : "end";
|
|
278
|
+
const originLeftPx = layoutClip.leftPx;
|
|
279
|
+
const originWidthPx = Math.max(layoutClip.widthPx, MIN_TRIM_VISUAL_PX);
|
|
280
|
+
const startClientX = event.clientX;
|
|
281
|
+
let currentLeftPx = originLeftPx;
|
|
282
|
+
let currentWidthPx = originWidthPx;
|
|
283
|
+
ctx.renderer.setClipPreview(clipId, {
|
|
284
|
+
leftPx: originLeftPx,
|
|
285
|
+
widthPx: originWidthPx,
|
|
286
|
+
isTrimming: true
|
|
287
|
+
});
|
|
288
|
+
event.originalEvent.preventDefault();
|
|
289
|
+
return {
|
|
290
|
+
onMove(moveEvent) {
|
|
291
|
+
const deltaX = moveEvent.clientX - startClientX;
|
|
292
|
+
if (edge === "start") {
|
|
293
|
+
const maxLeft = originLeftPx + originWidthPx - MIN_TRIM_VISUAL_PX;
|
|
294
|
+
const clampedLeft = Math.min(maxLeft, Math.max(0, originLeftPx + deltaX));
|
|
295
|
+
currentLeftPx = clampedLeft;
|
|
296
|
+
currentWidthPx = originWidthPx - (clampedLeft - originLeftPx);
|
|
297
|
+
ctx.renderer.setClipPreview(clipId, {
|
|
298
|
+
leftPx: currentLeftPx,
|
|
299
|
+
widthPx: currentWidthPx,
|
|
300
|
+
isTrimming: true
|
|
301
|
+
});
|
|
302
|
+
} else {
|
|
303
|
+
currentWidthPx = Math.max(MIN_TRIM_VISUAL_PX, originWidthPx + deltaX);
|
|
304
|
+
ctx.renderer.setClipPreview(clipId, {
|
|
305
|
+
widthPx: currentWidthPx,
|
|
306
|
+
isTrimming: true
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
onEnd() {
|
|
311
|
+
ctx.renderer.clearAllClipPreviews();
|
|
312
|
+
ctx.renderer.clearOverlay();
|
|
313
|
+
const activeLayout = ctx.renderer.getLayout();
|
|
314
|
+
const offsetPx = edge === "start" ? currentLeftPx - originLeftPx : currentWidthPx - originWidthPx;
|
|
315
|
+
const offsetMs = Math.round(pxToMs(offsetPx, activeLayout.pixelsPerSecond));
|
|
316
|
+
if (offsetMs !== 0) {
|
|
317
|
+
ctx.commands.execute("clip:trim", {
|
|
318
|
+
trackIndex: event.hit.trackIndex,
|
|
319
|
+
clipIndex: event.hit.clipIndex,
|
|
320
|
+
offsetMs,
|
|
321
|
+
edge
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
onCancel() {
|
|
326
|
+
ctx.renderer.clearAllClipPreviews();
|
|
327
|
+
ctx.renderer.clearOverlay();
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function createPlayheadPlugin() {
|
|
336
|
+
let repeatDelayTimer = null;
|
|
337
|
+
let repeatIntervalTimer = null;
|
|
338
|
+
let activeDirection = null;
|
|
339
|
+
const clearTimers = () => {
|
|
340
|
+
if (repeatDelayTimer !== null) {
|
|
341
|
+
clearTimeout(repeatDelayTimer);
|
|
342
|
+
repeatDelayTimer = null;
|
|
343
|
+
}
|
|
344
|
+
if (repeatIntervalTimer !== null) {
|
|
345
|
+
clearInterval(repeatIntervalTimer);
|
|
346
|
+
repeatIntervalTimer = null;
|
|
347
|
+
}
|
|
348
|
+
activeDirection = null;
|
|
349
|
+
};
|
|
350
|
+
const stepFrame = (ctx, delta) => {
|
|
351
|
+
const current = ctx.store.getState().currentFrame;
|
|
352
|
+
ctx.commands.execute("playhead:set", {
|
|
353
|
+
frame: Math.max(0, current + delta),
|
|
354
|
+
clampToDuration: true
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
const startRepeat = (ctx, direction) => {
|
|
358
|
+
if (activeDirection === direction && (repeatDelayTimer !== null || repeatIntervalTimer !== null)) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
clearTimers();
|
|
362
|
+
activeDirection = direction;
|
|
363
|
+
const step = direction === "left" ? -1 : 1;
|
|
364
|
+
stepFrame(ctx, step);
|
|
365
|
+
repeatDelayTimer = setTimeout(() => {
|
|
366
|
+
const fps = ctx.store.getState().document.fps || 24;
|
|
367
|
+
repeatIntervalTimer = setInterval(() => {
|
|
368
|
+
stepFrame(ctx, step);
|
|
369
|
+
}, Math.max(16, Math.round(1e3 / fps)));
|
|
370
|
+
repeatDelayTimer = null;
|
|
371
|
+
}, 450);
|
|
372
|
+
};
|
|
373
|
+
return {
|
|
374
|
+
name: "builtin:playhead",
|
|
375
|
+
interactions: [
|
|
376
|
+
{
|
|
377
|
+
id: "playhead-scrub",
|
|
378
|
+
priority: 100,
|
|
379
|
+
onPointerDown(event, ctx) {
|
|
380
|
+
if (event.hit.zone !== "playhead" && event.hit.zone !== "ruler") {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
ctx.commands.execute("playhead:set", {
|
|
384
|
+
frame: event.hit.frame,
|
|
385
|
+
clampToDuration: true
|
|
386
|
+
});
|
|
387
|
+
event.originalEvent.preventDefault();
|
|
388
|
+
return {
|
|
389
|
+
onMove(moveEvent) {
|
|
390
|
+
ctx.commands.execute("playhead:set", {
|
|
391
|
+
frame: moveEvent.hit.frame,
|
|
392
|
+
clampToDuration: true
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
},
|
|
397
|
+
onKeyDown(event, ctx) {
|
|
398
|
+
if (event.key === "ArrowLeft") {
|
|
399
|
+
event.preventDefault();
|
|
400
|
+
startRepeat(ctx, "left");
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
if (event.key === "ArrowRight") {
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
startRepeat(ctx, "right");
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
return false;
|
|
409
|
+
},
|
|
410
|
+
onKeyUp(event) {
|
|
411
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
412
|
+
clearTimers();
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
],
|
|
419
|
+
setup() {
|
|
420
|
+
return clearTimers;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function createSelectionPlugin() {
|
|
425
|
+
return {
|
|
426
|
+
name: "builtin:selection",
|
|
427
|
+
interactions: [
|
|
428
|
+
{
|
|
429
|
+
id: "selection",
|
|
430
|
+
priority: 20,
|
|
431
|
+
onPointerDown(event, ctx) {
|
|
432
|
+
if (event.hit.zone === "toolbar" || event.hit.zone === "sidebar") {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
if (event.hit.zone === "clip-body" && event.hit.clipId) {
|
|
436
|
+
const state = ctx.store.getState();
|
|
437
|
+
const track = state.document.tracks[event.hit.trackIndex];
|
|
438
|
+
if (track?.locked === true) {
|
|
439
|
+
ctx.commands.execute("selection:clear");
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
ctx.renderer.focusContainer?.();
|
|
443
|
+
const clickedId = event.hit.clipId;
|
|
444
|
+
if (event.metaKey || event.ctrlKey) {
|
|
445
|
+
const existing = state.selection.clipIds;
|
|
446
|
+
const hasId = existing.includes(clickedId);
|
|
447
|
+
const nextIds = hasId ? existing.filter((id) => id !== clickedId) : [...existing, clickedId];
|
|
448
|
+
ctx.commands.execute("selection:set", {
|
|
449
|
+
clipIds: nextIds,
|
|
450
|
+
clipId: nextIds[nextIds.length - 1] ?? null
|
|
451
|
+
});
|
|
452
|
+
} else {
|
|
453
|
+
ctx.commands.execute("selection:set", {
|
|
454
|
+
clipIds: [clickedId],
|
|
455
|
+
clipId: clickedId
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
return {};
|
|
459
|
+
}
|
|
460
|
+
if (event.hit.zone === "track-empty") {
|
|
461
|
+
ctx.renderer.focusContainer?.();
|
|
462
|
+
ctx.commands.execute("playhead:set", {
|
|
463
|
+
frame: event.hit.frame,
|
|
464
|
+
clampToDuration: true
|
|
465
|
+
});
|
|
466
|
+
ctx.commands.execute("selection:clear");
|
|
467
|
+
return {};
|
|
468
|
+
}
|
|
469
|
+
ctx.commands.execute("selection:clear");
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
]
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const DEFAULT_SHORTCUT_KEYMAP = {
|
|
477
|
+
"Mod+Z": "history:undo",
|
|
478
|
+
"Mod+Shift+Z": "history:redo",
|
|
479
|
+
"Ctrl+Y": "history:redo",
|
|
480
|
+
"Mod+B": "clip:split",
|
|
481
|
+
Delete: "clip:delete",
|
|
482
|
+
Backspace: "clip:delete"
|
|
483
|
+
};
|
|
484
|
+
function createShortcutsPlugin(options = {}) {
|
|
485
|
+
const mergedKeymap = {
|
|
486
|
+
...DEFAULT_SHORTCUT_KEYMAP,
|
|
487
|
+
...options.keymap ?? {}
|
|
488
|
+
};
|
|
489
|
+
return {
|
|
490
|
+
name: "builtin:shortcuts",
|
|
491
|
+
keymap: options.enabled === false ? {} : mergedKeymap
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
const playheadSnapProvider = {
|
|
495
|
+
id: "builtin:playhead",
|
|
496
|
+
getSnapPoints(ctx) {
|
|
497
|
+
const timeMs = frameToMs(ctx.currentFrame, ctx.layout.fps);
|
|
498
|
+
return [
|
|
499
|
+
{
|
|
500
|
+
timeMs,
|
|
501
|
+
x: msToPx(timeMs, ctx.layout.pixelsPerSecond),
|
|
502
|
+
source: "playhead",
|
|
503
|
+
kind: "playhead"
|
|
504
|
+
}
|
|
505
|
+
];
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
const clipEdgeSnapProvider = {
|
|
509
|
+
id: "builtin:clip-edges",
|
|
510
|
+
getSnapPoints(ctx) {
|
|
511
|
+
const points = [];
|
|
512
|
+
for (const track of ctx.layout.tracks) {
|
|
513
|
+
for (const clipLayout of track.clips) {
|
|
514
|
+
if (ctx.excludeClipIds.has(clipLayout.clip.id)) {
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
points.push({
|
|
518
|
+
timeMs: clipLayout.startMs,
|
|
519
|
+
x: clipLayout.leftPx,
|
|
520
|
+
source: "clip-edge",
|
|
521
|
+
clipId: clipLayout.clip.id,
|
|
522
|
+
kind: "start"
|
|
523
|
+
});
|
|
524
|
+
points.push({
|
|
525
|
+
timeMs: clipLayout.endMs,
|
|
526
|
+
x: clipLayout.leftPx + clipLayout.widthPx,
|
|
527
|
+
source: "clip-edge",
|
|
528
|
+
clipId: clipLayout.clip.id,
|
|
529
|
+
kind: "end"
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return points;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
function createGridSnapProvider(options = {}) {
|
|
537
|
+
const stepMs = Math.max(10, options.stepMs ?? 500);
|
|
538
|
+
const radiusSteps = Math.max(1, options.radiusSteps ?? 2);
|
|
539
|
+
return {
|
|
540
|
+
id: "builtin:grid",
|
|
541
|
+
getSnapPoints(ctx) {
|
|
542
|
+
if (options.enabled && !options.enabled()) {
|
|
543
|
+
return [];
|
|
544
|
+
}
|
|
545
|
+
const approxStartMs = pxToMs(ctx.targetLeftPx, ctx.layout.pixelsPerSecond);
|
|
546
|
+
const approxEndMs = approxStartMs + ctx.durationMs;
|
|
547
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
548
|
+
const addNearbyGrid = (targetMs) => {
|
|
549
|
+
const nearestStep = Math.round(targetMs / stepMs);
|
|
550
|
+
for (let offset = -radiusSteps; offset <= radiusSteps; offset += 1) {
|
|
551
|
+
const timeMs = Math.max(0, (nearestStep + offset) * stepMs);
|
|
552
|
+
candidates.add(timeMs);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
addNearbyGrid(approxStartMs);
|
|
556
|
+
addNearbyGrid(approxEndMs);
|
|
557
|
+
const points = [];
|
|
558
|
+
for (const timeMs of candidates) {
|
|
559
|
+
points.push({
|
|
560
|
+
timeMs,
|
|
561
|
+
x: msToPx(timeMs, ctx.layout.pixelsPerSecond),
|
|
562
|
+
source: "grid",
|
|
563
|
+
kind: "grid"
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
return points;
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function createWheelPlugin() {
|
|
571
|
+
let settleTimer = null;
|
|
572
|
+
const clearSettleTimer = () => {
|
|
573
|
+
if (settleTimer !== null) {
|
|
574
|
+
clearTimeout(settleTimer);
|
|
575
|
+
settleTimer = null;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
return {
|
|
579
|
+
name: "builtin:wheel",
|
|
580
|
+
interactions: [
|
|
581
|
+
{
|
|
582
|
+
id: "wheel-navigation",
|
|
583
|
+
priority: 50,
|
|
584
|
+
onWheel(event, ctx) {
|
|
585
|
+
if (event.hit.zone === "toolbar" || event.hit.zone === "sidebar" || event.hit.zone === "outside") {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
const metrics = ctx.renderer.getViewportMetrics();
|
|
589
|
+
if (event.ctrlKey || event.metaKey) {
|
|
590
|
+
event.originalEvent.preventDefault();
|
|
591
|
+
const state = ctx.store.getState();
|
|
592
|
+
const rawStep = -event.deltaY * 0.08;
|
|
593
|
+
const boundedStep = Math.sign(rawStep || (event.deltaY < 0 ? 1 : -1)) * Math.min(10, Math.max(1, Math.abs(rawStep)));
|
|
594
|
+
const nextScale = clampTrackScale(Math.round(state.trackScale + boundedStep));
|
|
595
|
+
if (nextScale === state.trackScale) {
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
const viewportOffsetX = event.hit.x + metrics.trackPaddingLeft - metrics.scrollLeft;
|
|
599
|
+
const anchorTimeMs = event.hit.timeMs;
|
|
600
|
+
ctx.commands.execute("scale:set", {
|
|
601
|
+
scale: nextScale,
|
|
602
|
+
renderHints: { zoomActive: true }
|
|
603
|
+
});
|
|
604
|
+
const nextPps = getPixelsPerSecond(nextScale, state.document.fps);
|
|
605
|
+
const nextAnchorPx = msToPx(anchorTimeMs, nextPps);
|
|
606
|
+
const nextScrollLeft = Math.max(0, nextAnchorPx + metrics.trackPaddingLeft - viewportOffsetX);
|
|
607
|
+
ctx.renderer.setScrollLeft(nextScrollLeft);
|
|
608
|
+
clearSettleTimer();
|
|
609
|
+
settleTimer = setTimeout(() => {
|
|
610
|
+
const latest = ctx.store.getState().renderHints;
|
|
611
|
+
ctx.store.setRenderHints({
|
|
612
|
+
zoomActive: false,
|
|
613
|
+
settleVersion: latest.settleVersion + 1
|
|
614
|
+
});
|
|
615
|
+
settleTimer = null;
|
|
616
|
+
}, 160);
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
if (event.shiftKey && Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
|
|
620
|
+
event.originalEvent.preventDefault();
|
|
621
|
+
ctx.renderer.setScrollLeft(Math.max(0, metrics.scrollLeft + event.deltaY));
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
],
|
|
628
|
+
setup() {
|
|
629
|
+
return clearSettleTimer;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function createDefaultPlugins(options = {}) {
|
|
634
|
+
const shortcutsOpts = typeof options.shortcuts === "boolean" ? { enabled: options.shortcuts } : options.shortcuts ?? {};
|
|
635
|
+
return [
|
|
636
|
+
{
|
|
637
|
+
name: "builtin:snap-defaults",
|
|
638
|
+
snapProviders: [playheadSnapProvider, clipEdgeSnapProvider]
|
|
639
|
+
},
|
|
640
|
+
createPlayheadPlugin(),
|
|
641
|
+
createClipTrimPlugin(),
|
|
642
|
+
createClipDragPlugin(),
|
|
643
|
+
createSelectionPlugin(),
|
|
644
|
+
createWheelPlugin(),
|
|
645
|
+
createShortcutsPlugin(shortcutsOpts)
|
|
646
|
+
];
|
|
647
|
+
}
|
|
648
|
+
export {
|
|
649
|
+
DEFAULT_SHORTCUT_KEYMAP as D,
|
|
650
|
+
createClipDragPlugin as a,
|
|
651
|
+
createClipTrimPlugin as b,
|
|
652
|
+
clipEdgeSnapProvider as c,
|
|
653
|
+
createDefaultPlugins as d,
|
|
654
|
+
createGridSnapProvider as e,
|
|
655
|
+
createPlayheadPlugin as f,
|
|
656
|
+
createSelectionPlugin as g,
|
|
657
|
+
createShortcutsPlugin as h,
|
|
658
|
+
createWheelPlugin as i,
|
|
659
|
+
playheadSnapProvider as p
|
|
660
|
+
};
|
|
661
|
+
//# sourceMappingURL=index-KK9cAE8q.js.map
|