@video-editor/ui 0.0.1-beta.20 → 0.0.1-beta.23

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.
@@ -0,0 +1,915 @@
1
+ import { defineComponent as ue, createElementBlock as k, openBlock as x, withModifiers as se, normalizeStyle as S, createStaticVNode as ze, createElementVNode as c, Fragment as le, renderList as de, normalizeClass as De, createCommentVNode as ee, toDisplayString as E, renderSlot as X, computed as I, withDirectives as He, vShow as Oe, ref as F, watch as xe, toRef as Ze, onMounted as Ae, onBeforeUnmount as Ye, createVNode as _e, unref as L, withCtx as je } from "vue";
2
+ const We = /* @__PURE__ */ ue({
3
+ name: "TimelinePlayhead",
4
+ __name: "TimelinePlayhead",
5
+ props: {
6
+ left: {}
7
+ },
8
+ emits: ["dragStart"],
9
+ setup(s, { emit: f }) {
10
+ const i = f;
11
+ return (u, m) => (x(), k("div", {
12
+ class: "ve-playhead",
13
+ style: S({ left: `${s.left}px` }),
14
+ onMousedown: m[0] || (m[0] = se((T) => i("dragStart", T), ["stop", "prevent"]))
15
+ }, [...m[1] || (m[1] = [
16
+ ze('<svg class="ve-playhead__icon" width="12" height="18" viewBox="0 0 12 18" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-8e647d40><g filter="url(#ve_playhead_drop_shadow)" data-v-8e647d40><path d="M2 3C2 1.89543 2.89543 1 4 1H8C9.10457 1 10 1.89543 10 3V11.0925C10 11.6692 9.75104 12.2178 9.31701 12.5976L7.31701 14.3476C6.56296 15.0074 5.43704 15.0074 4.68299 14.3476L2.68299 12.5976C2.24896 12.2178 2 11.6692 2 11.0925V3Z" fill="white" data-v-8e647d40></path><path d="M4 1.5H8C8.82843 1.5 9.5 2.17157 9.5 3V11.0928C9.49991 11.5252 9.31275 11.9369 8.9873 12.2217L6.9873 13.9717C6.42191 14.466 5.57809 14.466 5.0127 13.9717L3.0127 12.2217C2.68725 11.9369 2.50009 11.5252 2.5 11.0928V3C2.5 2.17157 3.17157 1.5 4 1.5Z" stroke="currentColor" data-v-8e647d40></path></g><defs data-v-8e647d40><filter id="ve_playhead_drop_shadow" x="0" y="0" width="12" height="17.8428" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB" data-v-8e647d40><feFlood flood-opacity="0" result="BackgroundImageFix" data-v-8e647d40></feFlood><feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha" data-v-8e647d40></feColorMatrix><feOffset dy="1" data-v-8e647d40></feOffset><feGaussianBlur stdDeviation="1" data-v-8e647d40></feGaussianBlur><feComposite in2="hardAlpha" operator="out" data-v-8e647d40></feComposite><feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0" data-v-8e647d40></feColorMatrix><feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" data-v-8e647d40></feBlend><feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" data-v-8e647d40></feBlend></filter></defs></svg><div class="ve-playhead__line" data-v-8e647d40></div>', 2)
17
+ ])], 36));
18
+ }
19
+ }), ce = (s, f) => {
20
+ const i = s.__vccOpts || s;
21
+ for (const [u, m] of f)
22
+ i[u] = m;
23
+ return i;
24
+ }, Ue = /* @__PURE__ */ ce(We, [["__scopeId", "data-v-8e647d40"]]), Ke = { class: "ve-ruler" }, qe = { class: "ve-ruler__ticks" }, Je = {
25
+ key: 0,
26
+ class: "ve-ruler__label"
27
+ }, Qe = /* @__PURE__ */ ue({
28
+ name: "TimelineRuler",
29
+ __name: "TimelineRuler",
30
+ props: {
31
+ ticks: {}
32
+ },
33
+ setup(s) {
34
+ return (f, i) => (x(), k("div", Ke, [
35
+ c("div", qe, [
36
+ (x(!0), k(le, null, de(s.ticks, (u) => (x(), k("div", {
37
+ key: u.timeMs,
38
+ class: De(["ve-ruler__tick", { "ve-ruler__tick--major": u.isMajor }]),
39
+ style: S({
40
+ left: `${u.position}px`,
41
+ transform: "translateX(-50%)"
42
+ })
43
+ }, [
44
+ i[0] || (i[0] = c("div", { class: "ve-ruler__line" }, null, -1)),
45
+ u.isMajor && u.label ? (x(), k("div", Je, E(u.label), 1)) : ee("", !0)
46
+ ], 6))), 128))
47
+ ])
48
+ ]));
49
+ }
50
+ }), Le = /* @__PURE__ */ ce(Qe, [["__scopeId", "data-v-30f91636"]]), et = { class: "ve-toolbar" }, tt = { class: "ve-toolbar__group" }, nt = ["disabled"], at = { class: "ve-toolbar__group" }, st = { class: "ve-zoom" }, it = { class: "ve-toolbar__group" }, rt = ["disabled"], ot = { class: "ve-toolbar__time" }, lt = /* @__PURE__ */ ue({
51
+ name: "TimelineToolbar",
52
+ __name: "TimelineToolbar",
53
+ props: {
54
+ zoom: {},
55
+ minZoom: { default: 0.25 },
56
+ maxZoom: { default: 10 },
57
+ currentTime: { default: 0 },
58
+ duration: { default: 0 },
59
+ formatTime: { type: Function, default: (s) => `${(s / 1e3).toFixed(2)}s` }
60
+ },
61
+ emits: ["zoomIn", "zoomOut"],
62
+ setup(s, { emit: f }) {
63
+ const i = f;
64
+ return (u, m) => (x(), k("div", et, [
65
+ c("div", tt, [
66
+ X(u.$slots, "left-actions", {}, () => [
67
+ c("button", {
68
+ class: "ve-btn",
69
+ type: "button",
70
+ disabled: s.zoom <= s.minZoom,
71
+ onClick: m[0] || (m[0] = (T) => i("zoomOut"))
72
+ }, " - ", 8, nt)
73
+ ], !0)
74
+ ]),
75
+ c("div", at, [
76
+ X(u.$slots, "center", {}, () => [
77
+ c("div", st, E((s.zoom * 100).toFixed(0)) + "% ", 1)
78
+ ], !0)
79
+ ]),
80
+ c("div", it, [
81
+ X(u.$slots, "right-actions", {}, () => [
82
+ c("button", {
83
+ class: "ve-btn",
84
+ type: "button",
85
+ disabled: s.zoom >= s.maxZoom,
86
+ onClick: m[1] || (m[1] = (T) => i("zoomIn"))
87
+ }, " + ", 8, rt)
88
+ ], !0)
89
+ ]),
90
+ c("div", ot, [
91
+ X(u.$slots, "time", {
92
+ currentTime: s.currentTime,
93
+ duration: s.duration
94
+ }, () => [
95
+ c("span", null, E(s.formatTime?.(s.currentTime || 0)), 1),
96
+ m[2] || (m[2] = c("span", { class: "ve-toolbar__time-divider" }, "/", -1)),
97
+ c("span", null, E(s.formatTime?.(s.duration || 0)), 1)
98
+ ], !0)
99
+ ])
100
+ ]));
101
+ }
102
+ }), dt = /* @__PURE__ */ ce(lt, [["__scopeId", "data-v-85ddeb0f"]]), ut = { class: "ve-track__body" }, ct = ["onMousedown", "onClick"], mt = { class: "ve-segment__content" }, vt = { class: "ve-segment__title" }, gt = { class: "ve-segment__time" }, ft = {
103
+ key: 0,
104
+ class: "ve-segment__selection"
105
+ }, ht = ["onMousedown"], pt = ["onMousedown"], kt = ["onClick"], xt = ["onClick"], _t = /* @__PURE__ */ ue({
106
+ name: "TimelineTracks",
107
+ __name: "TimelineTracks",
108
+ props: {
109
+ tracks: {},
110
+ trackHeight: {},
111
+ trackGap: {},
112
+ selectedSegmentId: {},
113
+ dragPreview: {},
114
+ resizePreview: {}
115
+ },
116
+ emits: ["segment-click", "segment-mousedown", "resize-start", "add-segment"],
117
+ setup(s, { emit: f }) {
118
+ const i = s, u = f;
119
+ function m(d, l) {
120
+ u("segment-click", d, l);
121
+ }
122
+ function T(d, l) {
123
+ u("segment-mousedown", d, l);
124
+ }
125
+ function C(d, l, t) {
126
+ u("resize-start", d, l, t);
127
+ }
128
+ function h(d, l, t, o) {
129
+ u("add-segment", { track: d, startTime: l, endTime: t, event: o });
130
+ }
131
+ const $ = I(() => i.tracks.map((d) => {
132
+ const l = [];
133
+ if (d.segments.length > 0 && d.segments[0].segment.start > 0) {
134
+ const t = d.segments[0];
135
+ l.push({
136
+ id: `start-${t.segment.id}`,
137
+ left: 0,
138
+ width: t.left,
139
+ startTime: 0,
140
+ endTime: t.segment.start
141
+ });
142
+ }
143
+ if (d.segments.length >= 1)
144
+ for (let t = 0; t < d.segments.length - 1; t++) {
145
+ const o = d.segments[t], M = d.segments[t + 1];
146
+ M.segment.start > o.segment.end && l.push({
147
+ id: `${o.segment.id}-${M.segment.id}`,
148
+ left: o.left + o.width,
149
+ width: M.left - (o.left + o.width),
150
+ startTime: o.segment.end,
151
+ endTime: M.segment.start
152
+ });
153
+ }
154
+ return {
155
+ trackId: d.track.id,
156
+ gaps: l
157
+ };
158
+ }));
159
+ function v(d) {
160
+ return $.value.find((l) => l.trackId === d)?.gaps || [];
161
+ }
162
+ return (d, l) => (x(), k("div", {
163
+ class: "ve-timeline__tracks",
164
+ style: S({ gap: `${s.trackGap}px`, paddingTop: `${s.trackGap}px` })
165
+ }, [
166
+ (x(!0), k(le, null, de(s.tracks, (t) => (x(), k("div", {
167
+ key: t.track.id,
168
+ class: De(["ve-track", {
169
+ "ve-track--main": t.track.isMain,
170
+ "ve-track--has-selection": t.segments.some((o) => o.isSelected)
171
+ }]),
172
+ style: S({ height: `${s.trackHeight}px` })
173
+ }, [
174
+ X(d.$slots, "track", {
175
+ track: t.track,
176
+ index: t.trackIndex,
177
+ segments: t.segments,
178
+ height: s.trackHeight
179
+ }, () => [
180
+ c("div", ut, [
181
+ (x(!0), k(le, null, de(t.segments, (o) => He((x(), k("div", {
182
+ key: o.segment.id,
183
+ class: De(["ve-segment", {
184
+ "ve-segment--selected": o.isSelected
185
+ }]),
186
+ style: S({
187
+ left: `${o.left}px`,
188
+ width: `${o.width}px`,
189
+ backgroundColor: o.segment.color || t.track.color || "#222226"
190
+ }),
191
+ onMousedown: se((M) => T(o, M), ["prevent", "stop"]),
192
+ onClick: se((M) => m(o, M), ["stop"])
193
+ }, [
194
+ X(d.$slots, "segment", {
195
+ layout: o,
196
+ segment: o.segment,
197
+ track: o.track,
198
+ isSelected: o.isSelected
199
+ }, () => [
200
+ c("div", mt, [
201
+ c("div", vt, E(o.segment.type || "segment"), 1),
202
+ c("div", gt, E((o.segment.start / 1e3).toFixed(2)) + "s - " + E((o.segment.end / 1e3).toFixed(2)) + "s ", 1)
203
+ ])
204
+ ], !0),
205
+ o.isSelected ? (x(), k("div", ft, [
206
+ c("div", {
207
+ class: "ve-segment__handle ve-segment__handle--left",
208
+ onMousedown: se((M) => C(o, "start", M), ["stop"])
209
+ }, [...l[0] || (l[0] = [
210
+ ze('<div class="ve-segment__handle-dots" data-v-902b9363><div class="ve-segment__handle-dot" data-v-902b9363></div><div class="ve-segment__handle-dot" data-v-902b9363></div><div class="ve-segment__handle-dot" data-v-902b9363></div><div class="ve-segment__handle-dot" data-v-902b9363></div></div>', 1)
211
+ ])], 40, ht),
212
+ c("div", {
213
+ class: "ve-segment__handle ve-segment__handle--right",
214
+ onMousedown: se((M) => C(o, "end", M), ["stop"])
215
+ }, [...l[1] || (l[1] = [
216
+ ze('<div class="ve-segment__handle-dots" data-v-902b9363><div class="ve-segment__handle-dot" data-v-902b9363></div><div class="ve-segment__handle-dot" data-v-902b9363></div><div class="ve-segment__handle-dot" data-v-902b9363></div><div class="ve-segment__handle-dot" data-v-902b9363></div></div>', 1)
217
+ ])], 40, pt)
218
+ ])) : ee("", !0)
219
+ ], 46, ct)), [
220
+ [Oe, s.dragPreview?.segment.id !== o.segment.id && s.resizePreview?.segment.id !== o.segment.id]
221
+ ])), 128)),
222
+ (x(!0), k(le, null, de(v(t.track.id), (o) => (x(), k("div", {
223
+ key: o.id,
224
+ class: "ve-track__gap-add",
225
+ style: S({ left: `${o.left}px`, width: `${o.width}px` }),
226
+ onClick: se((M) => h(t.track, o.startTime, o.endTime, M), ["stop"])
227
+ }, [...l[2] || (l[2] = [
228
+ c("div", { class: "ve-track__gap-add-icon" }, [
229
+ c("svg", {
230
+ width: "16",
231
+ height: "16",
232
+ viewBox: "0 0 24 24",
233
+ fill: "none",
234
+ xmlns: "http://www.w3.org/2000/svg"
235
+ }, [
236
+ c("path", {
237
+ d: "M12 5V19",
238
+ stroke: "currentColor",
239
+ "stroke-width": "1",
240
+ "stroke-linecap": "round",
241
+ "stroke-linejoin": "round"
242
+ }),
243
+ c("path", {
244
+ d: "M5 12H19",
245
+ stroke: "currentColor",
246
+ "stroke-width": "1",
247
+ "stroke-linecap": "round",
248
+ "stroke-linejoin": "round"
249
+ })
250
+ ])
251
+ ], -1)
252
+ ])], 12, kt))), 128)),
253
+ t.track.isMain ? (x(), k("div", {
254
+ key: 0,
255
+ class: "ve-track__add-button",
256
+ style: S({
257
+ left: t.segments.length > 0 ? `${t.segments[t.segments.length - 1].left + t.segments[t.segments.length - 1].width}px` : "0px"
258
+ }),
259
+ onClick: se((o) => h(t.track, t.segments.length > 0 ? t.segments[t.segments.length - 1].segment.end : 0, void 0, o), ["stop"])
260
+ }, [...l[3] || (l[3] = [
261
+ c("svg", {
262
+ width: "16",
263
+ height: "16",
264
+ viewBox: "0 0 24 24",
265
+ fill: "none",
266
+ xmlns: "http://www.w3.org/2000/svg"
267
+ }, [
268
+ c("path", {
269
+ d: "M12 5V19",
270
+ stroke: "currentColor",
271
+ "stroke-width": "1",
272
+ "stroke-linecap": "round",
273
+ "stroke-linejoin": "round"
274
+ }),
275
+ c("path", {
276
+ d: "M5 12H19",
277
+ stroke: "currentColor",
278
+ "stroke-width": "1",
279
+ "stroke-linecap": "round",
280
+ "stroke-linejoin": "round"
281
+ })
282
+ ], -1)
283
+ ])], 12, xt)) : ee("", !0)
284
+ ])
285
+ ], !0)
286
+ ], 6))), 128))
287
+ ], 4));
288
+ }
289
+ }), Tt = /* @__PURE__ */ ce(_t, [["__scopeId", "data-v-902b9363"]]);
290
+ function Mt(s, f, i, u) {
291
+ function m(C) {
292
+ if (!s.value || !f.value.length)
293
+ return null;
294
+ const h = s.value.getBoundingClientRect(), $ = C - h.top, v = i.value + u.value, d = u.value;
295
+ if ($ < d / 2)
296
+ return { isGap: !0, insertIndex: 0 };
297
+ for (let l = 0; l < f.value.length; l++) {
298
+ const t = (l + 1) * v - d / 2, o = (l + 1) * v + d / 2;
299
+ if ($ >= t && $ < o)
300
+ return { isGap: !0, insertIndex: l + 1 };
301
+ }
302
+ return null;
303
+ }
304
+ function T(C) {
305
+ if (!s.value || !f.value.length)
306
+ return -1;
307
+ const h = s.value.getBoundingClientRect(), $ = C - h.top, v = i.value + u.value;
308
+ return $ < 0 ? -1 : Math.min(
309
+ f.value.length - 1,
310
+ Math.max(0, Math.floor($ / v))
311
+ );
312
+ }
313
+ return {
314
+ detectTrackGap: m,
315
+ resolveTrackIndexFromClientY: T
316
+ };
317
+ }
318
+ function wt(s, f, i) {
319
+ return {
320
+ snapGuides: I(() => {
321
+ if (!s.value)
322
+ return [];
323
+ const m = /* @__PURE__ */ new Set(), T = s.value.startTime, C = s.value.endTime, h = 100;
324
+ return ("value" in f ? f.value : f).forEach((v) => {
325
+ v.segments.forEach((d) => {
326
+ d.id !== s.value?.segment.id && (Math.abs(d.start - T) < h && m.add(d.start), Math.abs(d.end - T) < h && m.add(d.end), Math.abs(d.start - C) < h && m.add(d.start), Math.abs(d.end - C) < h && m.add(d.end));
327
+ });
328
+ }), Array.from(m).map((v) => ({
329
+ time: v,
330
+ left: v * i.value
331
+ }));
332
+ })
333
+ };
334
+ }
335
+ function bt(s) {
336
+ const {
337
+ tracks: f,
338
+ tracksRef: i,
339
+ trackHeightPx: u,
340
+ trackGapPx: m,
341
+ pixelsPerMs: T,
342
+ disableInteraction: C,
343
+ snap: h,
344
+ onDragStart: $,
345
+ onDrag: v,
346
+ onDragEnd: d
347
+ } = s, l = F(null), t = F(null), { detectTrackGap: o, resolveTrackIndexFromClientY: M } = Mt(
348
+ i,
349
+ f,
350
+ u,
351
+ m
352
+ ), { snapGuides: me } = wt(
353
+ t,
354
+ f,
355
+ T
356
+ );
357
+ function ve(p, j) {
358
+ C.value || (l.value = {
359
+ layout: p,
360
+ initialX: j.clientX,
361
+ initialY: j.clientY,
362
+ moved: !1
363
+ });
364
+ }
365
+ function ge(p, j, V, R) {
366
+ const { layout: g, initialX: Te, initialY: Me } = p, fe = j - Te, W = V - Me, U = Math.abs(fe) > 5 || Math.abs(W) > 5;
367
+ if (!p.moved && U) {
368
+ p.moved = !0;
369
+ const P = {
370
+ segment: g.segment,
371
+ track: g.track,
372
+ trackIndex: g.trackIndex,
373
+ segmentIndex: g.segmentIndex,
374
+ startTime: g.segment.start,
375
+ endTime: g.segment.end,
376
+ targetTrackIndex: g.trackIndex,
377
+ targetTrackId: g.track.id,
378
+ isNewTrack: !1,
379
+ visualTrackIndex: g.trackIndex,
380
+ isValidTarget: !0,
381
+ mouseDeltaY: 0
382
+ };
383
+ $(P);
384
+ }
385
+ const K = g.segment.end - g.segment.start, q = g.segment.type || g.track.type, te = M(V), D = te >= 0 ? te : g.trackIndex, Y = f.value[D];
386
+ let w, ne, J, N = !1, ie, G = !0;
387
+ if (Y && Y.type === q) {
388
+ const P = o(V);
389
+ P ? (N = !0, ie = P.insertIndex, w = P.insertIndex, ne = P.insertIndex, J = g.track.id, G = !0) : (w = D, ne = D, J = Y.id, G = !0);
390
+ } else if (!i.value)
391
+ w = g.trackIndex, ne = D, J = g.track.id, G = !1;
392
+ else {
393
+ const P = i.value.getBoundingClientRect(), $e = V - P.top, he = u.value + m.value, Ce = D * he + u.value / 2, pe = $e < Ce;
394
+ N = !0, ie = pe ? D : D + 1, w = ie, ne = D, J = g.track.id, G = !0;
395
+ }
396
+ const be = h(g.segment.start + fe / Math.max(T.value, 1e-4)), Q = Math.max(0, be), Ie = Q + K, oe = {
397
+ segment: g.segment,
398
+ track: g.track,
399
+ trackIndex: g.trackIndex,
400
+ segmentIndex: g.segmentIndex,
401
+ startTime: Q,
402
+ endTime: Ie,
403
+ targetTrackIndex: w,
404
+ targetTrackId: J,
405
+ isNewTrack: N,
406
+ newTrackInsertIndex: ie,
407
+ visualTrackIndex: ne,
408
+ isValidTarget: G,
409
+ mouseDeltaY: W
410
+ };
411
+ p.moved && (t.value = oe, R === "drag" ? v(oe) : R === "end" && d(oe));
412
+ }
413
+ function Z(p) {
414
+ l.value && ge(l.value, p.clientX, p.clientY, "drag");
415
+ }
416
+ function z(p) {
417
+ l.value && (ge(l.value, p.clientX, p.clientY, "end"), l.value = null, t.value = null);
418
+ }
419
+ return {
420
+ // State
421
+ draggingState: l,
422
+ dragPreview: t,
423
+ snapGuides: me,
424
+ // Methods
425
+ startDrag: ve,
426
+ handleDragMove: Z,
427
+ handleDragEnd: z
428
+ };
429
+ }
430
+ const It = { class: "ve-timeline" }, $t = { class: "ve-segment__content" }, St = { class: "ve-segment__title" }, Ct = { class: "ve-segment__time" }, zt = { class: "ve-segment__content" }, Dt = { class: "ve-segment__title" }, yt = { class: "ve-segment__time" }, Rt = 120, Ge = 10, Ft = /* @__PURE__ */ ue({
431
+ name: "VideoTimeline",
432
+ __name: "index",
433
+ props: {
434
+ tracks: {},
435
+ currentTime: {},
436
+ duration: {},
437
+ zoom: {},
438
+ minZoom: { default: 0.25 },
439
+ maxZoom: { default: 10 },
440
+ snapStep: { default: 0 },
441
+ trackHeight: { default: 56 },
442
+ trackGap: { default: 8 },
443
+ rulerHeight: { default: 28 },
444
+ minSegmentDuration: { default: 60 },
445
+ selectedSegmentId: { default: null },
446
+ disableInteraction: { type: Boolean, default: !1 },
447
+ fps: { default: 30 }
448
+ },
449
+ emits: ["update:currentTime", "update:zoom", "segmentClick", "segmentDragStart", "segmentDrag", "segmentDragEnd", "segmentResizeStart", "segmentResize", "segmentResizeEnd", "backgroundClick", "add-segment"],
450
+ setup(s, { emit: f }) {
451
+ const i = s, u = f, m = F(null), T = F(null), C = F(null), h = F(0);
452
+ let $ = null;
453
+ const v = F(N(i.zoom ?? i.minZoom)), d = F(!1);
454
+ xe(() => i.zoom, (e) => {
455
+ typeof e == "number" && (v.value = N(e));
456
+ }), xe(v, (e) => u("update:zoom", e));
457
+ const l = I(() => typeof i.duration == "number" ? Math.max(i.duration, 0) : Math.max(
458
+ 0,
459
+ ...i.tracks.flatMap(
460
+ (a) => a.segments.map((n) => n.end)
461
+ )
462
+ ));
463
+ xe(l, (e, a) => {
464
+ if (!a || !e || a <= 0 || e <= 0 || !d.value || !h.value)
465
+ return;
466
+ const n = h.value * v.value / a;
467
+ if (!Number.isFinite(n) || n <= 0)
468
+ return;
469
+ const r = N(n * e / h.value);
470
+ Math.abs(r - v.value) > 1e-6 && (v.value = r);
471
+ });
472
+ const t = I(() => {
473
+ const e = Math.max(l.value, 1);
474
+ return Math.max(h.value, 1) * v.value / e;
475
+ }), o = I(() => {
476
+ const e = l.value * t.value, a = Number.isFinite(e) ? Math.max(e, 0) : 0;
477
+ return Math.max(Math.ceil(a), Math.ceil(h.value || 0));
478
+ }), M = I(() => {
479
+ const e = Math.max(t.value, 1e-4), n = (o.value || h.value || 0) / e;
480
+ return Math.max(l.value, n);
481
+ }), me = I(() => i.currentTime * t.value), ve = I(() => be(M.value, t.value)), ge = I(() => 1e3 / Math.max(i.fps || 30, 1)), Z = I(() => i.trackHeight), z = I(() => i.trackGap), p = I(() => i.rulerHeight), j = I(() => i.tracks.map((e, a) => ({
482
+ track: e,
483
+ trackIndex: a,
484
+ segments: e.segments.map((n, r) => {
485
+ const _ = Math.max((n.end - n.start) * t.value, 6), b = n.start * t.value;
486
+ return {
487
+ track: e,
488
+ trackIndex: a,
489
+ segment: n,
490
+ segmentIndex: r,
491
+ left: b,
492
+ width: _,
493
+ isSelected: i.selectedSegmentId === n.id
494
+ };
495
+ })
496
+ }))), {
497
+ draggingState: V,
498
+ dragPreview: R,
499
+ snapGuides: g,
500
+ startDrag: Te,
501
+ handleDragMove: Me,
502
+ handleDragEnd: fe
503
+ } = bt({
504
+ tracks: Ze(i, "tracks"),
505
+ tracksRef: C,
506
+ trackHeightPx: Z,
507
+ trackGapPx: z,
508
+ pixelsPerMs: t,
509
+ disableInteraction: Ze(i, "disableInteraction"),
510
+ snap: Q,
511
+ onDragStart: (e) => {
512
+ u("segmentDragStart", e);
513
+ },
514
+ onDrag: (e) => {
515
+ u("segmentDrag", e);
516
+ },
517
+ onDragEnd: (e) => {
518
+ u("segmentDragEnd", e);
519
+ }
520
+ }), W = F(null), U = I(() => R.value), K = I(() => W.value), q = F(null), te = F(!1), D = F(!1), Y = F(!1), w = I(() => {
521
+ if (!R.value)
522
+ return null;
523
+ const e = R.value, n = j.value.find((y) => y.track.id === e.track.id)?.segments.find((y) => y.segment.id === e.segment.id);
524
+ if (!n)
525
+ return null;
526
+ const r = (e.startTime - e.segment.start) * t.value, b = p.value + e.trackIndex * (Z.value + z.value) + z.value + e.mouseDeltaY;
527
+ return {
528
+ ...n,
529
+ left: n.left + r,
530
+ top: b
531
+ };
532
+ }), ne = I(() => {
533
+ if (!R.value)
534
+ return 0;
535
+ const e = R.value;
536
+ return e.isNewTrack && e.newTrackInsertIndex === 0 ? p.value + z.value : p.value + e.targetTrackIndex * (Z.value + z.value) + z.value;
537
+ });
538
+ Ae(() => {
539
+ m.value && ($ = new ResizeObserver((e) => {
540
+ const a = e[0];
541
+ h.value = a?.contentRect.width || m.value?.clientWidth || 0;
542
+ }), $.observe(m.value), h.value = m.value.clientWidth || 0), window.addEventListener("mousemove", pe), window.addEventListener("mouseup", ye), ie();
543
+ }), Ye(() => {
544
+ $?.disconnect(), $ = null, window.removeEventListener("mousemove", pe), window.removeEventListener("mouseup", ye);
545
+ }), xe(v, () => {
546
+ J();
547
+ });
548
+ function J() {
549
+ const e = m.value;
550
+ if (!e)
551
+ return;
552
+ const a = e.clientWidth / 2, n = i.currentTime * t.value - a;
553
+ e.scrollLeft = Math.max(0, n);
554
+ }
555
+ function N(e) {
556
+ return Number.isFinite(e) ? Math.min(Math.max(e, i.minZoom), i.maxZoom) : i.minZoom;
557
+ }
558
+ function ie() {
559
+ if (d.value)
560
+ return;
561
+ if (i.zoom !== void 0) {
562
+ d.value = !0;
563
+ return;
564
+ }
565
+ if (!h.value || l.value <= 0)
566
+ return;
567
+ const e = N(1 / 3);
568
+ v.value = e, d.value = !0;
569
+ }
570
+ function G(e) {
571
+ const a = Math.max(e, 0), n = Math.floor(a / 1e3), r = Math.floor(n / 60).toString().padStart(2, "0"), _ = (n % 60).toString().padStart(2, "0"), b = Math.floor(a % 1e3 / 10).toString().padStart(2, "0");
572
+ return `${r}:${_}.${b}`;
573
+ }
574
+ function we(e) {
575
+ const a = Math.max(e, 0), n = Math.floor(a / 1e3), r = Math.floor(n / 60).toString().padStart(2, "0"), _ = (n % 60).toString().padStart(2, "0");
576
+ return `${r}:${_}`;
577
+ }
578
+ function be(e, a) {
579
+ if (!e || !a)
580
+ return [];
581
+ const n = Pe(a, i.fps || 30), r = Math.max(1, Math.round(n.mainMs / n.minorMs)), _ = Math.max(e, 1), b = Math.ceil(_ / n.minorMs), y = [];
582
+ for (let B = 0; B <= b; B += 1) {
583
+ const H = Math.min(_, B * n.minorMs), O = H * a, A = B % r === 0;
584
+ y.push({
585
+ position: O,
586
+ timeMs: H,
587
+ isMajor: A,
588
+ label: A ? Ve(H, i.fps || 30, n) : void 0
589
+ });
590
+ }
591
+ return y;
592
+ }
593
+ function Q(e) {
594
+ const a = i.snapStep, n = a && a > 0 ? a : ge.value;
595
+ return Math.max(Math.round(e / n) * n, 0);
596
+ }
597
+ function Ie(e) {
598
+ if (!T.value)
599
+ return;
600
+ if (Y.value) {
601
+ Y.value = !1;
602
+ return;
603
+ }
604
+ const a = T.value.getBoundingClientRect(), n = e.clientX - a.left, r = Q(n / Math.max(t.value, 1e-4));
605
+ u("update:currentTime", r), u("backgroundClick", e), D.value = !0;
606
+ }
607
+ function oe(e) {
608
+ i.disableInteraction || (e.preventDefault(), te.value = !0, D.value = !0, P(e.clientX), J());
609
+ }
610
+ function P(e) {
611
+ if (!T.value)
612
+ return;
613
+ const a = T.value.getBoundingClientRect(), n = e - a.left, r = Q(n / Math.max(t.value, 1e-4));
614
+ u("update:currentTime", r);
615
+ }
616
+ function $e(e, a, n) {
617
+ if (i.disableInteraction)
618
+ return;
619
+ n.stopPropagation(), n.preventDefault(), q.value = {
620
+ layout: e,
621
+ edge: a,
622
+ initialX: n.clientX
623
+ };
624
+ const r = {
625
+ segment: e.segment,
626
+ track: e.track,
627
+ trackIndex: e.trackIndex,
628
+ segmentIndex: e.segmentIndex,
629
+ startTime: e.segment.start,
630
+ endTime: e.segment.end,
631
+ edge: a
632
+ };
633
+ W.value = r, u("segmentResizeStart", r);
634
+ }
635
+ function he(e, a, n) {
636
+ const { layout: r, edge: _, initialX: b } = e, B = (a - b) / Math.max(t.value, 1e-4), H = Math.max(i.minSegmentDuration, 10);
637
+ let O = r.segment.start, A = r.segment.end;
638
+ if (_ === "start")
639
+ O = Q(Math.max(0, r.segment.start + B)), r.segment.end - O < H && (O = r.segment.end - H);
640
+ else {
641
+ A = Q(Math.max(r.segment.start + H, r.segment.end + B));
642
+ const { sourceDurationMs: ae, fromTime: ke } = r.segment;
643
+ if (typeof ae == "number" && Number.isFinite(ae) && ae > 0 && typeof ke == "number" && Number.isFinite(ke) && ke >= 0) {
644
+ const Ne = Math.max(0, ae - ke), Ee = O + Ne;
645
+ A > Ee && (A = Ee);
646
+ }
647
+ }
648
+ const re = {
649
+ segment: r.segment,
650
+ track: r.track,
651
+ trackIndex: r.trackIndex,
652
+ segmentIndex: r.segmentIndex,
653
+ startTime: O,
654
+ endTime: A,
655
+ edge: _
656
+ };
657
+ W.value = re, n === "drag" ? u("segmentResize", re) : n === "end" && u("segmentResizeEnd", re);
658
+ }
659
+ function Se(e, a) {
660
+ V.value?.layout.segment.id === e.segment.id && V.value.moved || u("segmentClick", e, a);
661
+ }
662
+ function Ce({ track: e, startTime: a, endTime: n, event: r }) {
663
+ const _ = j.value.find((b) => b.track.id === e.id);
664
+ _ && u("add-segment", { track: _.track, startTime: a, endTime: n, event: r });
665
+ }
666
+ function pe(e) {
667
+ if (te.value) {
668
+ P(e.clientX);
669
+ return;
670
+ }
671
+ if (q.value) {
672
+ he(q.value, e.clientX, "drag");
673
+ return;
674
+ }
675
+ Me(e);
676
+ }
677
+ function ye(e) {
678
+ if (te.value) {
679
+ te.value = !1, D.value = !1, P(e.clientX), Y.value = !0;
680
+ return;
681
+ }
682
+ if (q.value) {
683
+ he(q.value, e.clientX, "end"), q.value = null, W.value = null, D.value = !1, Y.value = !0;
684
+ return;
685
+ }
686
+ if (V.value)
687
+ if (V.value.moved)
688
+ Y.value = !0;
689
+ else {
690
+ const { layout: a } = V.value;
691
+ Se(a, e);
692
+ }
693
+ fe(e), D.value = !1;
694
+ }
695
+ function Re() {
696
+ v.value = N(v.value * 1.25);
697
+ }
698
+ function Fe() {
699
+ v.value = N(v.value / 1.25);
700
+ }
701
+ function Pe(e, a) {
702
+ const r = 1e3 / (Number.isFinite(a) && a > 0 ? a : 30), _ = e * r, b = Be(r), y = Xe(r), B = _ >= Ge ? [...y, ...b] : b;
703
+ let H = null, O = 1 / 0;
704
+ for (const A of B) {
705
+ const re = A.mainMs * e;
706
+ if (re < Ge)
707
+ continue;
708
+ const ae = Math.abs(re - Rt);
709
+ ae < O && (H = A, O = ae);
710
+ }
711
+ return H || B[B.length - 1] || y[y.length - 1];
712
+ }
713
+ function Be(e) {
714
+ return [600, 300, 180, 120, 60, 30, 20, 15, 10, 5, 3, 2, 1].map((n) => {
715
+ const r = n * 1e3;
716
+ return {
717
+ mainMs: r,
718
+ minorMs: Math.max(r / 10, e),
719
+ mode: "time",
720
+ label: "time"
721
+ };
722
+ });
723
+ }
724
+ function Xe(e) {
725
+ return [
726
+ {
727
+ mainMs: Math.max(e * 2, 1),
728
+ minorMs: Math.max(e, 1),
729
+ mode: "frame",
730
+ label: "frame"
731
+ },
732
+ {
733
+ mainMs: Math.max(e * 10, 1),
734
+ minorMs: Math.max(e * 2, 1),
735
+ mode: "frame",
736
+ label: "frame"
737
+ },
738
+ {
739
+ mainMs: 1e3,
740
+ minorMs: Math.max(e * 10, 1),
741
+ mode: "frame",
742
+ label: "frame"
743
+ }
744
+ ];
745
+ }
746
+ function Ve(e, a, n) {
747
+ if (n.label === "frame") {
748
+ const r = Number.isFinite(a) && a > 0 ? a : 30, _ = 1e3 / r, y = Math.round(e / _) % r;
749
+ return y === 0 ? we(e) : `${y}f`;
750
+ }
751
+ return we(e);
752
+ }
753
+ return (e, a) => (x(), k("div", It, [
754
+ X(e.$slots, "toolbar", {
755
+ zoom: v.value,
756
+ canZoomIn: v.value < s.maxZoom,
757
+ canZoomOut: v.value > s.minZoom,
758
+ zoomIn: Re,
759
+ zoomOut: Fe,
760
+ currentTime: s.currentTime,
761
+ duration: l.value,
762
+ formatTime: G
763
+ }, () => [
764
+ _e(dt, {
765
+ zoom: v.value,
766
+ "min-zoom": s.minZoom,
767
+ "max-zoom": s.maxZoom,
768
+ "current-time": s.currentTime,
769
+ duration: l.value,
770
+ "format-time": G,
771
+ onZoomIn: Re,
772
+ onZoomOut: Fe
773
+ }, null, 8, ["zoom", "min-zoom", "max-zoom", "current-time", "duration"])
774
+ ], !0),
775
+ c("div", {
776
+ ref_key: "viewportRef",
777
+ ref: m,
778
+ class: "ve-timeline__viewport",
779
+ onClick: Ie
780
+ }, [
781
+ c("div", {
782
+ ref_key: "contentRef",
783
+ ref: T,
784
+ class: "ve-timeline__content",
785
+ style: S({ width: `${o.value}px` })
786
+ }, [
787
+ X(e.$slots, "ruler", {
788
+ ticks: ve.value,
789
+ pixelsPerMs: t.value
790
+ }, () => [
791
+ _e(Le, {
792
+ ticks: ve.value,
793
+ style: S({ height: `${p.value}px` })
794
+ }, null, 8, ["ticks", "style"])
795
+ ], !0),
796
+ X(e.$slots, "playhead", {
797
+ left: me.value,
798
+ currentTime: s.currentTime
799
+ }, () => [
800
+ _e(Ue, {
801
+ class: "top-0",
802
+ left: me.value,
803
+ onDragStart: oe
804
+ }, null, 8, ["left"])
805
+ ], !0),
806
+ c("div", {
807
+ ref_key: "tracksRef",
808
+ ref: C
809
+ }, [
810
+ _e(Tt, {
811
+ tracks: j.value,
812
+ "track-height": Z.value,
813
+ "track-gap": z.value,
814
+ "selected-segment-id": i.selectedSegmentId,
815
+ "drag-preview": L(R),
816
+ "resize-preview": W.value,
817
+ onSegmentClick: Se,
818
+ onSegmentMousedown: L(Te),
819
+ onResizeStart: $e,
820
+ onAddSegment: Ce
821
+ }, {
822
+ segment: je(({ layout: n, segment: r, track: _, isSelected: b }) => [
823
+ X(e.$slots, "segment", {
824
+ layout: n,
825
+ segment: r,
826
+ track: _,
827
+ isSelected: b
828
+ }, () => [
829
+ c("div", $t, [
830
+ c("div", St, E(r.type || "segment"), 1),
831
+ c("div", Ct, E(G(r.start)) + " - " + E(G(r.end)), 1)
832
+ ])
833
+ ], !0)
834
+ ]),
835
+ _: 3
836
+ }, 8, ["tracks", "track-height", "track-gap", "selected-segment-id", "drag-preview", "resize-preview", "onSegmentMousedown"])
837
+ ], 512),
838
+ w.value ? (x(), k("div", {
839
+ key: 0,
840
+ class: "ve-segment ve-segment--dragging",
841
+ style: S({
842
+ left: `${w.value.left}px`,
843
+ width: `${w.value.width}px`,
844
+ top: `${w.value.top}px`,
845
+ height: `${Z.value}px`,
846
+ backgroundColor: w.value.segment.color || "var(--ve-primary)"
847
+ })
848
+ }, [
849
+ X(e.$slots, "segment", {
850
+ layout: w.value,
851
+ segment: w.value.segment,
852
+ track: w.value.track,
853
+ isSelected: w.value.isSelected
854
+ }, () => [
855
+ c("div", zt, [
856
+ c("div", Dt, E(w.value.segment.type || "segment"), 1),
857
+ c("div", yt, E(G(w.value.segment.start)) + " - " + E(G(w.value.segment.end)), 1)
858
+ ])
859
+ ], !0)
860
+ ], 4)) : ee("", !0),
861
+ U.value && !U.value.isNewTrack ? (x(), k("div", {
862
+ key: 1,
863
+ class: "ve-segment ve-segment--placeholder",
864
+ style: S({
865
+ left: `${U.value.startTime * t.value}px`,
866
+ width: `${(U.value.endTime - U.value.startTime) * t.value}px`,
867
+ top: `${ne.value}px`,
868
+ height: `${Z.value}px`
869
+ })
870
+ }, [
871
+ c("div", {
872
+ class: "ve-segment--placeholder-inner",
873
+ style: S({
874
+ backgroundColor: U.value.segment.color || "var(--ve-primary)"
875
+ })
876
+ }, null, 4)
877
+ ], 4)) : ee("", !0),
878
+ K.value ? (x(), k("div", {
879
+ key: 2,
880
+ class: "ve-segment ve-segment--preview",
881
+ style: S({
882
+ left: `${K.value.startTime * t.value}px`,
883
+ width: `${(K.value.endTime - K.value.startTime) * t.value}px`,
884
+ top: `${p.value + K.value.trackIndex * (Z.value + z.value) + z.value}px`,
885
+ height: `${Z.value}px`,
886
+ backgroundColor: K.value.segment.color || "var(--ve-primary)"
887
+ })
888
+ }, null, 4)) : ee("", !0),
889
+ L(R) && L(g).length ? (x(!0), k(le, { key: 3 }, de(L(g), (n) => (x(), k("div", {
890
+ key: `snap-${n.time}`,
891
+ class: "ve-snap-guide",
892
+ style: S({
893
+ left: `${n.left}px`,
894
+ top: `${p.value}px`,
895
+ height: `calc(100% - ${p.value}px)`
896
+ })
897
+ }, null, 4))), 128)) : ee("", !0),
898
+ L(R) && L(R).isNewTrack ? (x(), k("div", {
899
+ key: 4,
900
+ class: "ve-new-track-line",
901
+ style: S({
902
+ top: `${p.value + L(R).targetTrackIndex * (Z.value + z.value)}px`,
903
+ left: "0",
904
+ right: "0"
905
+ })
906
+ }, null, 4)) : ee("", !0)
907
+ ], 4)
908
+ ], 512)
909
+ ]));
910
+ }
911
+ }), Zt = /* @__PURE__ */ ce(Ft, [["__scopeId", "data-v-4e3078d5"]]);
912
+ export {
913
+ Zt as V,
914
+ ce as _
915
+ };