@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,775 @@
|
|
|
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
|
+
const SCALE_STOPS = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
|
|
8
|
+
function getStopPixelsPerSecond(stopIndex, fps) {
|
|
9
|
+
const safeFps = fps > 0 ? fps : 24;
|
|
10
|
+
switch (stopIndex) {
|
|
11
|
+
case 0:
|
|
12
|
+
return 10 / 6;
|
|
13
|
+
case 1:
|
|
14
|
+
return 25 / 6;
|
|
15
|
+
case 2:
|
|
16
|
+
return 40 / 6;
|
|
17
|
+
case 3:
|
|
18
|
+
return 10;
|
|
19
|
+
case 4:
|
|
20
|
+
return 20;
|
|
21
|
+
case 5:
|
|
22
|
+
return 40;
|
|
23
|
+
case 6:
|
|
24
|
+
return 80;
|
|
25
|
+
case 7:
|
|
26
|
+
return 10 * safeFps;
|
|
27
|
+
case 8:
|
|
28
|
+
return 20 * safeFps;
|
|
29
|
+
case 9:
|
|
30
|
+
return 50 * safeFps;
|
|
31
|
+
case 10:
|
|
32
|
+
return 100 * safeFps;
|
|
33
|
+
default:
|
|
34
|
+
return 40;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function clampTrackScale(scale) {
|
|
38
|
+
if (!Number.isFinite(scale)) {
|
|
39
|
+
return 50;
|
|
40
|
+
}
|
|
41
|
+
return Math.max(0, Math.min(100, scale));
|
|
42
|
+
}
|
|
43
|
+
function getPixelsPerSecond(scale, fps = 24) {
|
|
44
|
+
const clamped = clampTrackScale(scale);
|
|
45
|
+
const exactIndex = clamped / 10;
|
|
46
|
+
const lowIndex = Math.floor(exactIndex);
|
|
47
|
+
const highIndex = Math.min(SCALE_STOPS.length - 1, Math.ceil(exactIndex));
|
|
48
|
+
if (lowIndex === highIndex) {
|
|
49
|
+
return getStopPixelsPerSecond(lowIndex, fps);
|
|
50
|
+
}
|
|
51
|
+
const ratio = exactIndex - lowIndex;
|
|
52
|
+
const lowPps = getStopPixelsPerSecond(lowIndex, fps);
|
|
53
|
+
const highPps = getStopPixelsPerSecond(highIndex, fps);
|
|
54
|
+
return lowPps + (highPps - lowPps) * ratio;
|
|
55
|
+
}
|
|
56
|
+
function getGridSize(scale, fps = 24) {
|
|
57
|
+
const clamped = clampTrackScale(scale);
|
|
58
|
+
const safeFps = fps > 0 ? fps : 24;
|
|
59
|
+
const pps = getPixelsPerSecond(clamped, safeFps);
|
|
60
|
+
if (clamped < 30) {
|
|
61
|
+
return pps * 6;
|
|
62
|
+
}
|
|
63
|
+
if (clamped < 70) {
|
|
64
|
+
return pps;
|
|
65
|
+
}
|
|
66
|
+
return pps / safeFps;
|
|
67
|
+
}
|
|
68
|
+
function getFramePixel(scale, fps = 24) {
|
|
69
|
+
const safeFps = fps > 0 ? fps : 24;
|
|
70
|
+
return getPixelsPerSecond(scale, safeFps) / safeFps;
|
|
71
|
+
}
|
|
72
|
+
function msToPx(ms, pixelsPerSecond) {
|
|
73
|
+
return ms / 1e3 * pixelsPerSecond;
|
|
74
|
+
}
|
|
75
|
+
function pxToMs(px, pixelsPerSecond) {
|
|
76
|
+
if (pixelsPerSecond <= 0) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
return px / pixelsPerSecond * 1e3;
|
|
80
|
+
}
|
|
81
|
+
function frameToSeconds(frame, fps) {
|
|
82
|
+
return fps <= 0 ? 0 : frame / fps;
|
|
83
|
+
}
|
|
84
|
+
function secondsToFrame(seconds, fps) {
|
|
85
|
+
return fps <= 0 ? 0 : Math.round(seconds * fps);
|
|
86
|
+
}
|
|
87
|
+
function msToFrame(ms, fps) {
|
|
88
|
+
return fps <= 0 ? 0 : Math.round(ms / 1e3 * fps);
|
|
89
|
+
}
|
|
90
|
+
function frameToMs(frame, fps) {
|
|
91
|
+
return fps <= 0 ? 0 : frame / fps * 1e3;
|
|
92
|
+
}
|
|
93
|
+
function pxToFrame(px, scale, fps) {
|
|
94
|
+
const framePixel = getFramePixel(scale, fps);
|
|
95
|
+
if (framePixel <= 0) {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
return Math.round(px / framePixel);
|
|
99
|
+
}
|
|
100
|
+
function scaleToPixelsPerSecond(scale, fps = 30) {
|
|
101
|
+
return getPixelsPerSecond(scale, fps);
|
|
102
|
+
}
|
|
103
|
+
const DEFAULT_EDIT_POLICIES = {
|
|
104
|
+
allowOverlap: false,
|
|
105
|
+
allowCrossTrackType: false,
|
|
106
|
+
removeEmptyTracks: true,
|
|
107
|
+
orderAudioToBottom: true
|
|
108
|
+
};
|
|
109
|
+
function isMagnetTrack(track, magnetEnabled) {
|
|
110
|
+
return Boolean(track?.main === true && magnetEnabled);
|
|
111
|
+
}
|
|
112
|
+
function calculateMagnetArrangement(track, dragClipStartMs, dragClipDurationMs, cursorX, targetTrackLayout, excludeClipId) {
|
|
113
|
+
const existingClips = track.clips.filter((clip) => clip.id !== excludeClipId).sort((left, right) => left.startMs - right.startMs);
|
|
114
|
+
let insertPosition = 0;
|
|
115
|
+
if (targetTrackLayout?.clips.length) {
|
|
116
|
+
for (let index = 0; index < existingClips.length; index += 1) {
|
|
117
|
+
const clip = existingClips[index];
|
|
118
|
+
const clipLayout = targetTrackLayout.clips.find((item) => item.clip.id === clip.id);
|
|
119
|
+
if (!clipLayout) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const clipStartX = clipLayout.leftPx;
|
|
123
|
+
const clipEndX = clipLayout.leftPx + clipLayout.widthPx;
|
|
124
|
+
const clipMidX = (clipStartX + clipEndX) / 2;
|
|
125
|
+
if (cursorX >= clipStartX && cursorX <= clipEndX) {
|
|
126
|
+
insertPosition = cursorX <= clipMidX ? index : index + 1;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (cursorX < clipStartX) {
|
|
130
|
+
insertPosition = index;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
insertPosition = index + 1;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
for (let index = 0; index < existingClips.length; index += 1) {
|
|
137
|
+
const clip = existingClips[index];
|
|
138
|
+
const clipMidTime = (clip.startMs + clip.endMs) / 2;
|
|
139
|
+
if (dragClipStartMs >= clip.startMs && dragClipStartMs <= clip.endMs) {
|
|
140
|
+
insertPosition = dragClipStartMs <= clipMidTime ? index : index + 1;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (dragClipStartMs < clip.startMs) {
|
|
144
|
+
insertPosition = index;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
insertPosition = index + 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const newArrangement = [];
|
|
151
|
+
const affectedClips = [];
|
|
152
|
+
let currentTimeMs = 0;
|
|
153
|
+
for (let index = 0; index < insertPosition; index += 1) {
|
|
154
|
+
const clip = existingClips[index];
|
|
155
|
+
const durationMs = Math.max(0, clip.endMs - clip.startMs);
|
|
156
|
+
newArrangement.push({
|
|
157
|
+
...clip,
|
|
158
|
+
startMs: currentTimeMs,
|
|
159
|
+
endMs: currentTimeMs + durationMs
|
|
160
|
+
});
|
|
161
|
+
if (clip.startMs !== currentTimeMs) {
|
|
162
|
+
affectedClips.push({
|
|
163
|
+
clipId: clip.id,
|
|
164
|
+
originalStartMs: clip.startMs,
|
|
165
|
+
originalEndMs: clip.endMs,
|
|
166
|
+
newStartMs: currentTimeMs,
|
|
167
|
+
newEndMs: currentTimeMs + durationMs
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
currentTimeMs += durationMs;
|
|
171
|
+
}
|
|
172
|
+
currentTimeMs += Math.max(0, dragClipDurationMs);
|
|
173
|
+
for (let index = insertPosition; index < existingClips.length; index += 1) {
|
|
174
|
+
const clip = existingClips[index];
|
|
175
|
+
const durationMs = Math.max(0, clip.endMs - clip.startMs);
|
|
176
|
+
newArrangement.push({
|
|
177
|
+
...clip,
|
|
178
|
+
startMs: currentTimeMs,
|
|
179
|
+
endMs: currentTimeMs + durationMs
|
|
180
|
+
});
|
|
181
|
+
if (clip.startMs !== currentTimeMs) {
|
|
182
|
+
affectedClips.push({
|
|
183
|
+
clipId: clip.id,
|
|
184
|
+
originalStartMs: clip.startMs,
|
|
185
|
+
originalEndMs: clip.endMs,
|
|
186
|
+
newStartMs: currentTimeMs,
|
|
187
|
+
newEndMs: currentTimeMs + durationMs
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
currentTimeMs += durationMs;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
insertPosition,
|
|
194
|
+
newArrangement,
|
|
195
|
+
affectedClips
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function detectMagnetState(options) {
|
|
199
|
+
if (options.isNewTrack) {
|
|
200
|
+
return { isMagnetMode: false, reason: "new-track" };
|
|
201
|
+
}
|
|
202
|
+
const targetTrack = options.tracks[options.targetTrackIndex];
|
|
203
|
+
if (!targetTrack) {
|
|
204
|
+
return { isMagnetMode: false, reason: "invalid-track" };
|
|
205
|
+
}
|
|
206
|
+
if (!isMagnetTrack(targetTrack, options.magnetEnabled)) {
|
|
207
|
+
return {
|
|
208
|
+
isMagnetMode: false,
|
|
209
|
+
reason: options.magnetEnabled ? "non-magnet-track" : "magnet-disabled"
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const dragClipStartMs = options.pixelToMs(options.targetX);
|
|
213
|
+
const excludeClipId = options.sourceTrackIndex === options.targetTrackIndex ? options.sourceClipId : void 0;
|
|
214
|
+
const arrangement = calculateMagnetArrangement(
|
|
215
|
+
targetTrack,
|
|
216
|
+
dragClipStartMs,
|
|
217
|
+
options.dragClipDurationMs,
|
|
218
|
+
options.cursorX,
|
|
219
|
+
options.tracksLayout[options.targetTrackIndex],
|
|
220
|
+
excludeClipId
|
|
221
|
+
);
|
|
222
|
+
return {
|
|
223
|
+
isMagnetMode: true,
|
|
224
|
+
magnetState: {
|
|
225
|
+
isEnabled: true,
|
|
226
|
+
targetTrackIndex: options.targetTrackIndex,
|
|
227
|
+
insertPosition: arrangement.insertPosition,
|
|
228
|
+
dragClipDurationMs: options.dragClipDurationMs,
|
|
229
|
+
affectedClips: arrangement.affectedClips,
|
|
230
|
+
previewArrangement: arrangement.newArrangement
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function getMagnetPreviewTransforms(magnetState, dragClipId, msToPixel, targetTrackLayout) {
|
|
235
|
+
if (!targetTrackLayout?.clips.length) {
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
const arranged = [];
|
|
239
|
+
let currentTimeMs = 0;
|
|
240
|
+
for (let index = 0; index <= magnetState.previewArrangement.length; index += 1) {
|
|
241
|
+
if (index === magnetState.insertPosition) {
|
|
242
|
+
arranged.push({
|
|
243
|
+
id: dragClipId,
|
|
244
|
+
startMs: currentTimeMs,
|
|
245
|
+
isDragClip: true
|
|
246
|
+
});
|
|
247
|
+
currentTimeMs += magnetState.dragClipDurationMs;
|
|
248
|
+
}
|
|
249
|
+
if (index < magnetState.previewArrangement.length) {
|
|
250
|
+
const clip = magnetState.previewArrangement[index];
|
|
251
|
+
const durationMs = Math.max(0, clip.endMs - clip.startMs);
|
|
252
|
+
arranged.push({
|
|
253
|
+
id: clip.id,
|
|
254
|
+
startMs: currentTimeMs,
|
|
255
|
+
isDragClip: false
|
|
256
|
+
});
|
|
257
|
+
currentTimeMs += durationMs;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const transforms = [];
|
|
261
|
+
for (const item of arranged) {
|
|
262
|
+
if (item.isDragClip) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const originalLayout = targetTrackLayout.clips.find((layoutClip) => layoutClip.clip.id === item.id);
|
|
266
|
+
if (!originalLayout) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
transforms.push({
|
|
270
|
+
clipId: item.id,
|
|
271
|
+
offsetX: msToPixel(item.startMs) - originalLayout.leftPx
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return transforms;
|
|
275
|
+
}
|
|
276
|
+
function checkTrackOverlap(tracks, targetTrackIndex, startMs, endMs, excludeClipId, policies = DEFAULT_EDIT_POLICIES, magnetEnabled = false) {
|
|
277
|
+
if (policies.allowOverlap) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
const targetTrack = tracks[targetTrackIndex];
|
|
281
|
+
if (!targetTrack || isMagnetTrack(targetTrack, magnetEnabled)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
for (const clip of targetTrack.clips) {
|
|
285
|
+
if (excludeClipId && clip.id === excludeClipId) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (startMs < clip.endMs && endMs > clip.startMs) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
function resolveTargetTrack(tracks, tracksLayout, y, dragClip, options) {
|
|
295
|
+
const policies = options.policies ?? DEFAULT_EDIT_POLICIES;
|
|
296
|
+
const clipDurationMs = Math.max(0, dragClip.endMs - dragClip.startMs);
|
|
297
|
+
const targetStartMs = Math.max(0, options.targetStartMs);
|
|
298
|
+
const targetEndMs = targetStartMs + clipDurationMs;
|
|
299
|
+
const sourceTrack = options.sourceTrackIndex !== void 0 ? tracks[options.sourceTrackIndex] : void 0;
|
|
300
|
+
for (let index = 0; index < tracksLayout.length; index += 1) {
|
|
301
|
+
const layoutTrack = tracksLayout[index];
|
|
302
|
+
const actualTrack = tracks[index];
|
|
303
|
+
if (!actualTrack) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (y < layoutTrack.startY || y > layoutTrack.endY) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
const midY = (layoutTrack.startY + layoutTrack.endY) / 2;
|
|
310
|
+
const newTrackFallback = {
|
|
311
|
+
isNewTrack: true,
|
|
312
|
+
insertIndex: y < midY ? index : index + 1
|
|
313
|
+
};
|
|
314
|
+
if (actualTrack.locked === true) {
|
|
315
|
+
return newTrackFallback;
|
|
316
|
+
}
|
|
317
|
+
if (!policies.allowCrossTrackType && layoutTrack.type !== dragClip.type) {
|
|
318
|
+
return newTrackFallback;
|
|
319
|
+
}
|
|
320
|
+
if (policies.canDrop && !policies.canDrop({
|
|
321
|
+
clip: dragClip,
|
|
322
|
+
sourceTrack,
|
|
323
|
+
targetTrack: actualTrack,
|
|
324
|
+
startMs: targetStartMs,
|
|
325
|
+
endMs: targetEndMs
|
|
326
|
+
})) {
|
|
327
|
+
return newTrackFallback;
|
|
328
|
+
}
|
|
329
|
+
if (isMagnetTrack(actualTrack, options.magnetEnabled)) {
|
|
330
|
+
return { isNewTrack: false, insertIndex: index };
|
|
331
|
+
}
|
|
332
|
+
if (checkTrackOverlap(
|
|
333
|
+
tracks,
|
|
334
|
+
index,
|
|
335
|
+
targetStartMs,
|
|
336
|
+
targetEndMs,
|
|
337
|
+
dragClip.id,
|
|
338
|
+
policies,
|
|
339
|
+
options.magnetEnabled
|
|
340
|
+
)) {
|
|
341
|
+
return newTrackFallback;
|
|
342
|
+
}
|
|
343
|
+
return { isNewTrack: false, insertIndex: index };
|
|
344
|
+
}
|
|
345
|
+
if (tracksLayout.length === 0 || y < tracksLayout[0].startY) {
|
|
346
|
+
return { isNewTrack: true, insertIndex: 0 };
|
|
347
|
+
}
|
|
348
|
+
const lastTrack = tracksLayout[tracksLayout.length - 1];
|
|
349
|
+
if (y > lastTrack.endY) {
|
|
350
|
+
return { isNewTrack: true, insertIndex: tracksLayout.length };
|
|
351
|
+
}
|
|
352
|
+
for (let index = 0; index < tracksLayout.length - 1; index += 1) {
|
|
353
|
+
if (y > tracksLayout[index].endY && y < tracksLayout[index + 1].startY) {
|
|
354
|
+
return { isNewTrack: true, insertIndex: index + 1 };
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return { isNewTrack: true, insertIndex: tracksLayout.length };
|
|
358
|
+
}
|
|
359
|
+
function collectSnapPoints(providers, ctx) {
|
|
360
|
+
const points = [
|
|
361
|
+
{
|
|
362
|
+
timeMs: 0,
|
|
363
|
+
x: 0,
|
|
364
|
+
source: "timeline-start",
|
|
365
|
+
kind: "start"
|
|
366
|
+
}
|
|
367
|
+
];
|
|
368
|
+
for (const provider of providers) {
|
|
369
|
+
const supplied = provider.getSnapPoints(ctx);
|
|
370
|
+
for (const point of supplied) {
|
|
371
|
+
points.push(point);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return points;
|
|
375
|
+
}
|
|
376
|
+
function findBestSnap(targetLeftPx, durationMs, points, pixelsPerSecond, thresholdPx = 10) {
|
|
377
|
+
const durationPx = msToPx(Math.max(0, durationMs), pixelsPerSecond);
|
|
378
|
+
const targetRightPx = targetLeftPx + durationPx;
|
|
379
|
+
let best = null;
|
|
380
|
+
let minDistance = thresholdPx;
|
|
381
|
+
for (const point of points) {
|
|
382
|
+
const startDistance = Math.abs(targetLeftPx - point.x);
|
|
383
|
+
if (startDistance < minDistance) {
|
|
384
|
+
minDistance = startDistance;
|
|
385
|
+
best = {
|
|
386
|
+
leftPx: Math.max(0, point.x),
|
|
387
|
+
startMs: Math.max(0, point.timeMs),
|
|
388
|
+
guidelineX: point.x,
|
|
389
|
+
point,
|
|
390
|
+
edge: "start"
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const endDistance = Math.abs(targetRightPx - point.x);
|
|
394
|
+
if (endDistance < minDistance) {
|
|
395
|
+
const snappedLeftPx = point.x - durationPx;
|
|
396
|
+
if (snappedLeftPx >= -1e-3) {
|
|
397
|
+
const clampedLeftPx = Math.max(0, snappedLeftPx);
|
|
398
|
+
minDistance = endDistance;
|
|
399
|
+
best = {
|
|
400
|
+
leftPx: clampedLeftPx,
|
|
401
|
+
startMs: Math.max(0, Math.round(pxToMs(clampedLeftPx, pixelsPerSecond))),
|
|
402
|
+
guidelineX: point.x,
|
|
403
|
+
point,
|
|
404
|
+
edge: "end"
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return best;
|
|
410
|
+
}
|
|
411
|
+
function normalizeKeyName(key) {
|
|
412
|
+
const lower = key.toLowerCase();
|
|
413
|
+
if (lower === " ") {
|
|
414
|
+
return "space";
|
|
415
|
+
}
|
|
416
|
+
if (lower === "esc") {
|
|
417
|
+
return "escape";
|
|
418
|
+
}
|
|
419
|
+
if (lower === "del") {
|
|
420
|
+
return "delete";
|
|
421
|
+
}
|
|
422
|
+
return lower;
|
|
423
|
+
}
|
|
424
|
+
function parseKeyChord(chord) {
|
|
425
|
+
const parts = chord.split("+").map((part) => part.trim().toLowerCase()).filter(Boolean);
|
|
426
|
+
const parsed = {
|
|
427
|
+
mod: false,
|
|
428
|
+
ctrl: false,
|
|
429
|
+
meta: false,
|
|
430
|
+
shift: false,
|
|
431
|
+
alt: false,
|
|
432
|
+
key: ""
|
|
433
|
+
};
|
|
434
|
+
for (const part of parts) {
|
|
435
|
+
if (part === "mod") {
|
|
436
|
+
parsed.mod = true;
|
|
437
|
+
} else if (part === "ctrl" || part === "control") {
|
|
438
|
+
parsed.ctrl = true;
|
|
439
|
+
} else if (part === "meta" || part === "cmd" || part === "command") {
|
|
440
|
+
parsed.meta = true;
|
|
441
|
+
} else if (part === "shift") {
|
|
442
|
+
parsed.shift = true;
|
|
443
|
+
} else if (part === "alt" || part === "option") {
|
|
444
|
+
parsed.alt = true;
|
|
445
|
+
} else {
|
|
446
|
+
parsed.key = normalizeKeyName(part);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return parsed;
|
|
450
|
+
}
|
|
451
|
+
function normalizeChordCanonical(chord) {
|
|
452
|
+
const parsed = parseKeyChord(chord);
|
|
453
|
+
const tokens = [];
|
|
454
|
+
if (parsed.mod)
|
|
455
|
+
tokens.push("mod");
|
|
456
|
+
if (parsed.ctrl)
|
|
457
|
+
tokens.push("ctrl");
|
|
458
|
+
if (parsed.meta)
|
|
459
|
+
tokens.push("meta");
|
|
460
|
+
if (parsed.shift)
|
|
461
|
+
tokens.push("shift");
|
|
462
|
+
if (parsed.alt)
|
|
463
|
+
tokens.push("alt");
|
|
464
|
+
if (parsed.key)
|
|
465
|
+
tokens.push(parsed.key);
|
|
466
|
+
return tokens.join("+");
|
|
467
|
+
}
|
|
468
|
+
function matchesKeyChord(event, chord) {
|
|
469
|
+
const parsed = parseKeyChord(chord);
|
|
470
|
+
if (!parsed.key || normalizeKeyName(event.key) !== parsed.key) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
if (parsed.mod) {
|
|
474
|
+
if (!(event.metaKey || event.ctrlKey)) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
} else {
|
|
478
|
+
if (Boolean(event.ctrlKey) !== parsed.ctrl) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
if (Boolean(event.metaKey) !== parsed.meta) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (Boolean(event.shiftKey) !== parsed.shift) {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
if (Boolean(event.altKey) !== parsed.alt) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
function isEditableElement(target) {
|
|
494
|
+
if (!target || typeof target !== "object") {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
const el = target;
|
|
498
|
+
if (el.isContentEditable) {
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
return el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.tagName === "SELECT";
|
|
502
|
+
}
|
|
503
|
+
class InteractionManager {
|
|
504
|
+
context;
|
|
505
|
+
plugins;
|
|
506
|
+
handlers;
|
|
507
|
+
snapProviders;
|
|
508
|
+
keymap;
|
|
509
|
+
activeSession;
|
|
510
|
+
shortcutsEnabled;
|
|
511
|
+
constructor(context) {
|
|
512
|
+
this.plugins = /* @__PURE__ */ new Map();
|
|
513
|
+
this.handlers = [];
|
|
514
|
+
this.snapProviders = [];
|
|
515
|
+
this.keymap = /* @__PURE__ */ new Map();
|
|
516
|
+
this.activeSession = null;
|
|
517
|
+
this.shortcutsEnabled = true;
|
|
518
|
+
this.context = {
|
|
519
|
+
...context,
|
|
520
|
+
getSnapProviders: () => this.snapProviders
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
getContext() {
|
|
524
|
+
return this.context;
|
|
525
|
+
}
|
|
526
|
+
getSnapProviders() {
|
|
527
|
+
return this.snapProviders;
|
|
528
|
+
}
|
|
529
|
+
setShortcutsEnabled(enabled) {
|
|
530
|
+
this.shortcutsEnabled = enabled;
|
|
531
|
+
}
|
|
532
|
+
isShortcutsEnabled() {
|
|
533
|
+
return this.shortcutsEnabled;
|
|
534
|
+
}
|
|
535
|
+
setKeyBinding(chord, binding) {
|
|
536
|
+
const canonical = normalizeChordCanonical(chord);
|
|
537
|
+
if (binding === null) {
|
|
538
|
+
this.keymap.delete(canonical);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
this.keymap.set(canonical, binding);
|
|
542
|
+
}
|
|
543
|
+
use(plugin) {
|
|
544
|
+
if (this.plugins.has(plugin.name)) {
|
|
545
|
+
this.remove(plugin.name);
|
|
546
|
+
}
|
|
547
|
+
const disposers = [];
|
|
548
|
+
if (plugin.commands) {
|
|
549
|
+
for (const [type, spec] of Object.entries(plugin.commands)) {
|
|
550
|
+
disposers.push(this.context.commands.register(type, spec));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (plugin.interactions) {
|
|
554
|
+
for (const handler of plugin.interactions) {
|
|
555
|
+
this.handlers.push(handler);
|
|
556
|
+
disposers.push(() => {
|
|
557
|
+
const idx = this.handlers.indexOf(handler);
|
|
558
|
+
if (idx !== -1) {
|
|
559
|
+
this.handlers.splice(idx, 1);
|
|
560
|
+
}
|
|
561
|
+
if (this.activeSession?.handlerId === handler.id) {
|
|
562
|
+
this.cancelActiveSession();
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
this.handlers.sort((left, right) => right.priority - left.priority);
|
|
567
|
+
}
|
|
568
|
+
if (plugin.snapProviders) {
|
|
569
|
+
for (const provider of plugin.snapProviders) {
|
|
570
|
+
this.snapProviders.push(provider);
|
|
571
|
+
disposers.push(() => {
|
|
572
|
+
const idx = this.snapProviders.indexOf(provider);
|
|
573
|
+
if (idx !== -1) {
|
|
574
|
+
this.snapProviders.splice(idx, 1);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (plugin.keymap) {
|
|
580
|
+
for (const [chord, binding] of Object.entries(plugin.keymap)) {
|
|
581
|
+
const canonical = normalizeChordCanonical(chord);
|
|
582
|
+
const hadPrev = this.keymap.has(canonical);
|
|
583
|
+
const prevBinding = this.keymap.get(canonical);
|
|
584
|
+
this.setKeyBinding(chord, binding);
|
|
585
|
+
disposers.push(() => {
|
|
586
|
+
if (hadPrev && prevBinding !== void 0) {
|
|
587
|
+
this.keymap.set(canonical, prevBinding);
|
|
588
|
+
} else {
|
|
589
|
+
this.keymap.delete(canonical);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (plugin.setup) {
|
|
595
|
+
const cleanup = plugin.setup(this.context);
|
|
596
|
+
if (typeof cleanup === "function") {
|
|
597
|
+
disposers.push(cleanup);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
this.plugins.set(plugin.name, { plugin, disposers });
|
|
601
|
+
return () => {
|
|
602
|
+
this.remove(plugin.name);
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
remove(name) {
|
|
606
|
+
const entry = this.plugins.get(name);
|
|
607
|
+
if (!entry) {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
this.plugins.delete(name);
|
|
611
|
+
for (let index = entry.disposers.length - 1; index >= 0; index -= 1) {
|
|
612
|
+
entry.disposers[index]();
|
|
613
|
+
}
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
hasPlugin(name) {
|
|
617
|
+
return this.plugins.has(name);
|
|
618
|
+
}
|
|
619
|
+
hasActiveSession() {
|
|
620
|
+
return this.activeSession !== null;
|
|
621
|
+
}
|
|
622
|
+
handlePointerDown(event) {
|
|
623
|
+
if (this.activeSession) {
|
|
624
|
+
this.cancelActiveSession();
|
|
625
|
+
}
|
|
626
|
+
for (const handler of this.handlers) {
|
|
627
|
+
if (!handler.onPointerDown) {
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const session = handler.onPointerDown(event, this.context);
|
|
631
|
+
if (session) {
|
|
632
|
+
this.activeSession = {
|
|
633
|
+
handlerId: handler.id,
|
|
634
|
+
session
|
|
635
|
+
};
|
|
636
|
+
this.context.renderer.lockUserSelect?.();
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
handlePointerMove(event) {
|
|
643
|
+
if (!this.activeSession) {
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
this.activeSession.session.onMove?.(event);
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
handlePointerUp(event) {
|
|
650
|
+
if (!this.activeSession) {
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
const { session } = this.activeSession;
|
|
654
|
+
this.activeSession = null;
|
|
655
|
+
this.context.renderer.restoreUserSelect?.();
|
|
656
|
+
session.onEnd?.(event);
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
cancelActiveSession() {
|
|
660
|
+
if (!this.activeSession) {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
const { session } = this.activeSession;
|
|
664
|
+
this.activeSession = null;
|
|
665
|
+
this.context.renderer.restoreUserSelect?.();
|
|
666
|
+
session.onCancel?.();
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
handleWheel(event) {
|
|
670
|
+
for (const handler of this.handlers) {
|
|
671
|
+
if (handler.onWheel?.(event, this.context) === true) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
handleDragOver(event) {
|
|
678
|
+
for (const handler of this.handlers) {
|
|
679
|
+
if (handler.onDragOver?.(event, this.context) === true) {
|
|
680
|
+
return true;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
handleDragLeave() {
|
|
686
|
+
for (const handler of this.handlers) {
|
|
687
|
+
handler.onDragLeave?.(this.context);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
handleDrop(event) {
|
|
691
|
+
for (const handler of this.handlers) {
|
|
692
|
+
if (handler.onDrop?.(event, this.context) === true) {
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
handleKeyDown(event) {
|
|
699
|
+
if (isEditableElement(event.target)) {
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
if (event.key === "Escape" && this.activeSession) {
|
|
703
|
+
this.cancelActiveSession();
|
|
704
|
+
event.preventDefault();
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
for (const handler of this.handlers) {
|
|
708
|
+
if (handler.onKeyDown?.(event, this.context) === true) {
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (!this.shortcutsEnabled) {
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
const entries = Array.from(this.keymap.entries());
|
|
716
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
717
|
+
const [chord, binding] = entries[index];
|
|
718
|
+
if (!matchesKeyChord(event, chord)) {
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
if (typeof binding === "string") {
|
|
722
|
+
event.preventDefault();
|
|
723
|
+
this.context.commands.execute(binding);
|
|
724
|
+
return true;
|
|
725
|
+
}
|
|
726
|
+
const handled = binding(event, this.context);
|
|
727
|
+
if (handled !== false) {
|
|
728
|
+
event.preventDefault();
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
handleKeyUp(event) {
|
|
735
|
+
for (const handler of this.handlers) {
|
|
736
|
+
if (handler.onKeyUp?.(event, this.context) === true) {
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
destroy() {
|
|
743
|
+
this.cancelActiveSession();
|
|
744
|
+
const names = Array.from(this.plugins.keys());
|
|
745
|
+
for (let index = names.length - 1; index >= 0; index -= 1) {
|
|
746
|
+
this.remove(names[index]);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
export {
|
|
751
|
+
DEFAULT_EDIT_POLICIES as D,
|
|
752
|
+
InteractionManager as I,
|
|
753
|
+
checkTrackOverlap as a,
|
|
754
|
+
clampTrackScale as b,
|
|
755
|
+
calculateMagnetArrangement as c,
|
|
756
|
+
collectSnapPoints as d,
|
|
757
|
+
detectMagnetState as e,
|
|
758
|
+
findBestSnap as f,
|
|
759
|
+
frameToMs as g,
|
|
760
|
+
frameToSeconds as h,
|
|
761
|
+
getFramePixel as i,
|
|
762
|
+
getGridSize as j,
|
|
763
|
+
getMagnetPreviewTransforms as k,
|
|
764
|
+
getPixelsPerSecond as l,
|
|
765
|
+
isMagnetTrack as m,
|
|
766
|
+
matchesKeyChord as n,
|
|
767
|
+
msToFrame as o,
|
|
768
|
+
msToPx as p,
|
|
769
|
+
pxToFrame as q,
|
|
770
|
+
pxToMs as r,
|
|
771
|
+
resolveTargetTrack as s,
|
|
772
|
+
scaleToPixelsPerSecond as t,
|
|
773
|
+
secondsToFrame as u
|
|
774
|
+
};
|
|
775
|
+
//# sourceMappingURL=interactionManager-JoPxZ8st.js.map
|