@brett_lamy/ui 5.1.0 → 5.3.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/dist/components/adaptive-pane.d.ts +12 -1
- package/dist/components/adaptive-pane.d.ts.map +1 -1
- package/dist/components/adaptive-pane.js +122 -19
- package/dist/components/avatar.d.ts +47 -5
- package/dist/components/avatar.d.ts.map +1 -1
- package/dist/components/avatar.js +101 -14
- package/dist/components/breadcrumb.d.ts +87 -0
- package/dist/components/breadcrumb.d.ts.map +1 -0
- package/dist/components/breadcrumb.js +312 -0
- package/dist/components/color-picker.js +15 -15
- package/dist/components/command-menu.js +13 -13
- package/dist/components/credenza.d.ts +5 -2
- package/dist/components/credenza.d.ts.map +1 -1
- package/dist/components/credenza.js +62 -60
- package/dist/components/date-picker.js +9 -9
- package/dist/components/edge-drawer.d.ts +7 -2
- package/dist/components/edge-drawer.d.ts.map +1 -1
- package/dist/components/edge-drawer.js +7 -4
- package/dist/components/filmstrip.d.ts +19 -0
- package/dist/components/filmstrip.d.ts.map +1 -0
- package/dist/components/filmstrip.js +59 -0
- package/dist/components/filter-input.js +4 -4
- package/dist/components/filter.js +62 -62
- package/dist/components/font-picker.d.ts +67 -0
- package/dist/components/font-picker.d.ts.map +1 -0
- package/dist/components/font-picker.js +373 -0
- package/dist/components/markdown-editor.d.ts +11 -0
- package/dist/components/markdown-editor.d.ts.map +1 -1
- package/dist/components/markdown-editor.js +72 -65
- package/dist/components/navigation-stack.d.ts.map +1 -1
- package/dist/components/navigation-stack.js +75 -65
- package/dist/components/number-morph.d.ts.map +1 -1
- package/dist/components/number-morph.js +5 -5
- package/dist/components/replay-preview.d.ts +2 -2
- package/dist/components/replay-preview.d.ts.map +1 -1
- package/dist/components/replay-preview.js +3 -3
- package/dist/components/result-table.js +10 -10
- package/dist/components/schema-tree.d.ts.map +1 -1
- package/dist/components/schema-tree.js +62 -131
- package/dist/components/segmented.d.ts +1 -1
- package/dist/components/segmented.d.ts.map +1 -1
- package/dist/components/segmented.js +1 -1
- package/dist/components/sidebar.d.ts.map +1 -1
- package/dist/components/sidebar.js +8 -4
- package/dist/components/split-view.d.ts +3 -1
- package/dist/components/split-view.d.ts.map +1 -1
- package/dist/components/split-view.js +211 -211
- package/dist/components/spreadsheet.d.ts +58 -0
- package/dist/components/spreadsheet.d.ts.map +1 -0
- package/dist/components/spreadsheet.js +804 -0
- package/dist/components/sql-console.d.ts.map +1 -1
- package/dist/components/sql-console.js +2 -1
- package/dist/components/sql-editor.js +8 -8
- package/dist/components/stl-viewer.d.ts +3 -0
- package/dist/components/stl-viewer.d.ts.map +1 -0
- package/dist/components/stl-viewer.js +2 -0
- package/dist/components/strudel-player.d.ts +3 -0
- package/dist/components/strudel-player.d.ts.map +1 -0
- package/dist/components/strudel-player.js +2 -0
- package/dist/components/strudel-rack.d.ts +3 -0
- package/dist/components/strudel-rack.d.ts.map +1 -0
- package/dist/components/strudel-rack.js +2 -0
- package/dist/components/strudel-syntax.d.ts +3 -0
- package/dist/components/strudel-syntax.d.ts.map +1 -0
- package/dist/components/strudel-syntax.js +2 -0
- package/dist/components/tabs.js +3 -3
- package/dist/components/tailscale-menu.d.ts +69 -0
- package/dist/components/tailscale-menu.d.ts.map +1 -0
- package/dist/components/tailscale-menu.js +202 -0
- package/dist/components/toggle-group.js +3 -3
- package/dist/components/tree.d.ts +82 -0
- package/dist/components/tree.d.ts.map +1 -0
- package/dist/components/tree.js +494 -0
- package/dist/components/video-preview.d.ts +46 -0
- package/dist/components/video-preview.d.ts.map +1 -0
- package/dist/components/video-preview.js +197 -0
- package/dist/components/video-timeline.d.ts +64 -0
- package/dist/components/video-timeline.d.ts.map +1 -0
- package/dist/components/video-timeline.js +479 -0
- package/dist/components/waveform.d.ts +23 -0
- package/dist/components/waveform.d.ts.map +1 -0
- package/dist/components/waveform.js +56 -0
- package/dist/ffmpeg-worker.js +118 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +48 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +145 -121
- package/dist/lib/csv.d.ts +28 -0
- package/dist/lib/csv.d.ts.map +1 -0
- package/dist/lib/csv.js +90 -0
- package/dist/lib/drawer-swipe.d.ts +31 -0
- package/dist/lib/drawer-swipe.d.ts.map +1 -0
- package/dist/lib/drawer-swipe.js +68 -0
- package/dist/lib/ffmpeg/index.d.ts +117 -0
- package/dist/lib/ffmpeg/index.d.ts.map +1 -0
- package/dist/lib/ffmpeg/index.js +204 -0
- package/dist/lib/ffmpeg/media.d.ts +39 -0
- package/dist/lib/ffmpeg/media.d.ts.map +1 -0
- package/dist/lib/ffmpeg/media.js +100 -0
- package/dist/lib/ffmpeg/react.d.ts +51 -0
- package/dist/lib/ffmpeg/react.d.ts.map +1 -0
- package/dist/lib/ffmpeg/react.js +113 -0
- package/dist/lib/google-fonts.d.ts +47 -0
- package/dist/lib/google-fonts.d.ts.map +1 -0
- package/dist/lib/google-fonts.generated.d.ts +2 -0
- package/dist/lib/google-fonts.generated.d.ts.map +1 -0
- package/dist/lib/google-fonts.generated.js +1925 -0
- package/dist/lib/google-fonts.js +112 -0
- package/dist/lib/icon.d.ts +6 -1
- package/dist/lib/icon.d.ts.map +1 -1
- package/dist/lib/icon.js +2 -0
- package/dist/lib/playback.d.ts +34 -0
- package/dist/lib/playback.d.ts.map +1 -0
- package/dist/lib/playback.js +79 -0
- package/dist/lib/spreadsheet-gpu.d.ts +9 -0
- package/dist/lib/spreadsheet-gpu.d.ts.map +1 -0
- package/dist/lib/spreadsheet-gpu.js +237 -0
- package/dist/lib/spreadsheet.d.ts +82 -0
- package/dist/lib/spreadsheet.d.ts.map +1 -0
- package/dist/lib/spreadsheet.js +162 -0
- package/dist/lib/syntax.d.ts +2 -6
- package/dist/lib/syntax.d.ts.map +1 -1
- package/dist/lib/syntax.js +53 -75
- package/dist/lib/tailscale-connect.d.ts +33 -0
- package/dist/lib/tailscale-connect.d.ts.map +1 -1
- package/dist/lib/tailscale-connect.js +221 -42
- package/dist/lib/tailscale-exit.d.ts +19 -0
- package/dist/lib/tailscale-exit.d.ts.map +1 -0
- package/dist/lib/tailscale-exit.js +14 -0
- package/dist/lib/tailscale-fake.d.ts +8 -0
- package/dist/lib/tailscale-fake.d.ts.map +1 -1
- package/dist/lib/tailscale-fake.js +51 -26
- package/dist/lib/tailscale-roots.d.ts +3 -0
- package/dist/lib/tailscale-roots.d.ts.map +1 -0
- package/dist/lib/tailscale-roots.js +4 -0
- package/dist/lib/tailscale.d.ts +23 -0
- package/dist/lib/tailscale.d.ts.map +1 -1
- package/dist/lib/tailscale.js +156 -94
- package/dist/lib/title-flight.d.ts +4 -0
- package/dist/lib/title-flight.d.ts.map +1 -1
- package/dist/lib/title-flight.js +15 -12
- package/dist/lib/tokens.generated.d.ts +2 -2
- package/dist/lib/tokens.generated.d.ts.map +1 -1
- package/dist/lib/tokens.generated.js +2 -2
- package/dist/lib/video-render.d.ts +38 -0
- package/dist/lib/video-render.d.ts.map +1 -0
- package/dist/lib/video-render.js +147 -0
- package/dist/lib/video-timeline.d.ts +154 -0
- package/dist/lib/video-timeline.d.ts.map +1 -0
- package/dist/lib/video-timeline.js +265 -0
- package/dist/lib/webgpu.d.ts +26 -0
- package/dist/lib/webgpu.d.ts.map +1 -0
- package/dist/lib/webgpu.js +28 -0
- package/dist/theme.css +3 -0
- package/package.json +8 -3
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn as e } from "../lib/utils.js";
|
|
3
|
+
import { Icon as t } from "../lib/icon.js";
|
|
4
|
+
import { useControllableState as n } from "../lib/controllable-state.js";
|
|
5
|
+
import { Toggle as r } from "./toggle.js";
|
|
6
|
+
import { clipDuration as i, clipEnd as a, findClip as o, formatTimecode as s, magneticIndex as c, moveClip as l, quantize as u, removeClips as d, snapTargets as f, snapTime as p, timelineDuration as m, trimClip as h, updateTrack as g } from "../lib/video-timeline.js";
|
|
7
|
+
import { usePlaybackState as _ } from "../lib/playback.js";
|
|
8
|
+
import { Fragment as ee, useEffect as te, useLayoutEffect as v, useRef as y, useState as b } from "react";
|
|
9
|
+
import { Fragment as ne, jsx as x, jsxs as S } from "react/jsx-runtime";
|
|
10
|
+
//#region src/components/video-timeline.tsx
|
|
11
|
+
var C = "application/x-bl-timeline-media", w = 132, re = 28, ie = 8, T = {
|
|
12
|
+
min: 2,
|
|
13
|
+
max: 600
|
|
14
|
+
}, ae = (e) => Math.max(T.min, Math.min(T.max, e)), oe = (e) => e.kind === "audio" ? 40 : e.magnetic ? 64 : 44;
|
|
15
|
+
function E(e, t) {
|
|
16
|
+
return ae(e > 0 ? (t - w - 24) / e : 60);
|
|
17
|
+
}
|
|
18
|
+
function se(e, t) {
|
|
19
|
+
let n = 1 / Math.max(1, t), r = [
|
|
20
|
+
n,
|
|
21
|
+
2 * n,
|
|
22
|
+
5 * n,
|
|
23
|
+
10 * n,
|
|
24
|
+
.5,
|
|
25
|
+
1,
|
|
26
|
+
2,
|
|
27
|
+
5,
|
|
28
|
+
10,
|
|
29
|
+
15,
|
|
30
|
+
30,
|
|
31
|
+
60,
|
|
32
|
+
120,
|
|
33
|
+
300,
|
|
34
|
+
600,
|
|
35
|
+
900,
|
|
36
|
+
1800,
|
|
37
|
+
3600
|
|
38
|
+
].find((t) => t * e >= 64) ?? 3600, i = r < .5 ? n : r === 2 || r === 30 || r === 120 ? r / 2 : r === 15 || r === 60 || r === 900 || r === 3600 ? r / 3 : r / 5;
|
|
39
|
+
return {
|
|
40
|
+
major: r,
|
|
41
|
+
minor: i * e >= 5 && i < r ? i : null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function ce(e, t, n) {
|
|
45
|
+
let r = Math.floor(e + 1e-6), i = `${r >= 3600 ? `${Math.floor(r / 3600)}:${String(Math.floor(r / 60) % 60).padStart(2, "0")}` : String(Math.floor(r / 60))}:${String(r % 60).padStart(2, "0")}`;
|
|
46
|
+
return t < 1 ? `${i}:${String(Math.round((e - r) * n)).padStart(2, "0")}` : i;
|
|
47
|
+
}
|
|
48
|
+
function D({ timeline: _, onChange: T, media: E = {}, clock: D, fps: O = 30, selection: k, defaultSelection: de = [], onSelectionChange: fe, zoom: pe, defaultZoom: me = 60, onZoomChange: he, snap: ge = !0, renderClip: A, clipClassName: _e, trackHeight: j = oe, onDropMedia: M, className: ve, style: ye }) {
|
|
49
|
+
let [N, be] = n(pe, me, he), [P, xe] = n(k && [...k], [...de], fe), F = y(null), I = y(null), L = y([]), R = y(/* @__PURE__ */ new Map()), z = y(null), [B, V] = b(null), [H, U] = b(null), [W, Se] = b({
|
|
50
|
+
w: 0,
|
|
51
|
+
left: 0
|
|
52
|
+
}), G = y(null), K = B?.preview ?? _, q = m(K), Ce = w + Math.max(q + 8, (W.w - w) / N) * N, J = !!T;
|
|
53
|
+
v(() => {
|
|
54
|
+
let e = () => {
|
|
55
|
+
let { time: e, playing: t } = D.getState(), n = e * N;
|
|
56
|
+
L.current.forEach((e) => e?.style.setProperty("--ph", `${n}px`));
|
|
57
|
+
let r = F.current;
|
|
58
|
+
if (r && t) {
|
|
59
|
+
let e = r.clientWidth - w;
|
|
60
|
+
(n < r.scrollLeft || n > r.scrollLeft + e - 24) && (r.scrollLeft = Math.max(0, n - 24));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return e(), D.subscribe(e);
|
|
64
|
+
}, [D, N]), v(() => {
|
|
65
|
+
let e = F.current;
|
|
66
|
+
if (!e) return;
|
|
67
|
+
let t = () => Se((t) => t.w === e.clientWidth && t.left === e.scrollLeft ? t : {
|
|
68
|
+
w: e.clientWidth,
|
|
69
|
+
left: e.scrollLeft
|
|
70
|
+
});
|
|
71
|
+
t(), e.addEventListener("scroll", t, { passive: !0 });
|
|
72
|
+
let n = typeof ResizeObserver > "u" ? null : new ResizeObserver(t);
|
|
73
|
+
return n?.observe(e), () => {
|
|
74
|
+
e.removeEventListener("scroll", t), n?.disconnect();
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
77
|
+
let Y = y(N);
|
|
78
|
+
Y.current = N;
|
|
79
|
+
let we = y(be);
|
|
80
|
+
we.current = be, v(() => {
|
|
81
|
+
let e = G.current, t = F.current;
|
|
82
|
+
!e || !t || (G.current = null, t.scrollLeft = Math.max(0, e.time * N - e.x));
|
|
83
|
+
}, [N]), te(() => {
|
|
84
|
+
let e = F.current;
|
|
85
|
+
if (!e) return;
|
|
86
|
+
let t = (t) => {
|
|
87
|
+
if (!t.ctrlKey && !t.metaKey) return;
|
|
88
|
+
t.preventDefault();
|
|
89
|
+
let n = e.getBoundingClientRect(), r = Math.max(0, t.clientX - n.left - w), i = Y.current;
|
|
90
|
+
G.current = {
|
|
91
|
+
time: (e.scrollLeft + r) / i,
|
|
92
|
+
x: r
|
|
93
|
+
}, we.current(ae(i * Math.exp(-t.deltaY * .01)));
|
|
94
|
+
};
|
|
95
|
+
return e.addEventListener("wheel", t, { passive: !1 }), () => e.removeEventListener("wheel", t);
|
|
96
|
+
}, []), v(() => {
|
|
97
|
+
let e = I.current;
|
|
98
|
+
if (!e) return;
|
|
99
|
+
let t = typeof devicePixelRatio == "number" ? devicePixelRatio : 1, n = e.clientWidth, r = e.clientHeight;
|
|
100
|
+
e.width = Math.max(1, Math.round(n * t)), e.height = Math.max(1, Math.round(r * t));
|
|
101
|
+
let i = e.getContext("2d");
|
|
102
|
+
if (!i) return;
|
|
103
|
+
i.setTransform(t, 0, 0, t, 0, 0), i.clearRect(0, 0, n, r);
|
|
104
|
+
let a = getComputedStyle(e);
|
|
105
|
+
i.fillStyle = a.color, i.font = `10px ${a.fontFamily}`, i.textBaseline = "top";
|
|
106
|
+
let { major: o, minor: s } = se(N, O), c = W.left / N, l = (W.left + n) / N;
|
|
107
|
+
if (s) {
|
|
108
|
+
i.globalAlpha = .4;
|
|
109
|
+
for (let e = Math.floor(c / s); e * s <= l; e++) i.fillRect(Math.round(e * s * N - W.left), r - 5, 1, 5);
|
|
110
|
+
}
|
|
111
|
+
i.globalAlpha = .85;
|
|
112
|
+
for (let e = Math.floor(c / o); e * o <= l + o; e++) {
|
|
113
|
+
let t = Math.round(e * o * N - W.left);
|
|
114
|
+
i.fillRect(t, r - 10, 1, 10), i.fillText(ce(e * o, o, O), t + 4, 6);
|
|
115
|
+
}
|
|
116
|
+
}, [
|
|
117
|
+
N,
|
|
118
|
+
O,
|
|
119
|
+
W
|
|
120
|
+
]);
|
|
121
|
+
let X = (e) => {
|
|
122
|
+
let t = F.current;
|
|
123
|
+
if (!t) return 0;
|
|
124
|
+
let n = t.getBoundingClientRect();
|
|
125
|
+
return Math.max(0, (e - n.left - w + t.scrollLeft) / N);
|
|
126
|
+
}, Te = (e) => {
|
|
127
|
+
for (let t of _.tracks) {
|
|
128
|
+
let n = R.current.get(t.id)?.getBoundingClientRect();
|
|
129
|
+
if (n && e >= n.top && e < n.bottom) return t;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}, Z = (e) => xe(e), Q = (e, t, n, r) => {
|
|
133
|
+
if (e.button !== 0) return;
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
let i = e.shiftKey || e.metaKey || e.ctrlKey;
|
|
136
|
+
i ? Z(P.includes(n.id) ? P.filter((e) => e !== n.id) : [...P, n.id]) : P.includes(n.id) || Z([n.id]), !(!J || t.locked) && (e.currentTarget.setPointerCapture(e.pointerId), z.current = {
|
|
137
|
+
kind: r,
|
|
138
|
+
id: n.id,
|
|
139
|
+
pointerId: e.pointerId,
|
|
140
|
+
x0: e.clientX,
|
|
141
|
+
y0: e.clientY,
|
|
142
|
+
orig: n,
|
|
143
|
+
origTrack: t,
|
|
144
|
+
preview: _,
|
|
145
|
+
ghost: n.start,
|
|
146
|
+
ghostTrack: t.id,
|
|
147
|
+
snap: null,
|
|
148
|
+
moved: !1,
|
|
149
|
+
additive: i
|
|
150
|
+
});
|
|
151
|
+
}, Ee = (e) => {
|
|
152
|
+
let t = z.current;
|
|
153
|
+
if (!t || t.pointerId !== e.pointerId) return;
|
|
154
|
+
let n = e.clientX - t.x0;
|
|
155
|
+
if (!t.moved && Math.abs(n) < 3 && Math.abs(e.clientY - t.y0) < 3) return;
|
|
156
|
+
t.moved || (t.moved = !0, D.pause());
|
|
157
|
+
let r = ge && !e.altKey, s = ie / N, d = r ? f(_, {
|
|
158
|
+
exclude: [t.id],
|
|
159
|
+
extra: [D.getState().time]
|
|
160
|
+
}) : [];
|
|
161
|
+
if (t.kind === "move") {
|
|
162
|
+
let a = i(t.orig), o = t.orig.start + n / N, f = null;
|
|
163
|
+
if (r) {
|
|
164
|
+
let e = p(o, d, s), t = p(o + a, d, s);
|
|
165
|
+
e.snapped && (!t.snapped || Math.abs(e.time - o) <= Math.abs(t.time - o - a)) ? (o = e.time, f = e.time) : t.snapped && (o = t.time - a, f = t.time);
|
|
166
|
+
}
|
|
167
|
+
o = Math.max(0, u(o, O));
|
|
168
|
+
let m = Te(e.clientY), h = m && m.kind === t.origTrack.kind && !m.locked ? m : _.tracks.find((e) => e.id === t.ghostTrack) ?? t.origTrack, g = h.magnetic ? l(_, t.id, {
|
|
169
|
+
trackId: h.id,
|
|
170
|
+
index: c(h, X(e.clientX), t.id)
|
|
171
|
+
}) : l(_, t.id, {
|
|
172
|
+
trackId: h.id,
|
|
173
|
+
start: o
|
|
174
|
+
});
|
|
175
|
+
Object.assign(t, {
|
|
176
|
+
preview: g,
|
|
177
|
+
ghost: h.magnetic ? Math.max(0, t.orig.start + n / N) : o,
|
|
178
|
+
ghostTrack: h.id,
|
|
179
|
+
snap: h.magnetic ? null : f
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
let e = (t.kind === "start" ? t.orig.start : a(t.orig)) + n / N, i = null;
|
|
183
|
+
if (r) {
|
|
184
|
+
let t = p(e, d, s);
|
|
185
|
+
t.snapped && (e = t.time, i = t.time);
|
|
186
|
+
}
|
|
187
|
+
e = u(e, O);
|
|
188
|
+
let c = E[t.orig.media], l = h(_, t.id, t.kind, e, {
|
|
189
|
+
mediaDuration: c && c.kind !== "image" ? c.duration : Infinity,
|
|
190
|
+
minDuration: 1 / O
|
|
191
|
+
}), f = o(l, t.id)?.clip;
|
|
192
|
+
f && D.seek(t.kind === "start" ? f.start : Math.max(f.start, a(f) - 1 / O)), Object.assign(t, {
|
|
193
|
+
preview: l,
|
|
194
|
+
snap: i
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
V({ ...t });
|
|
198
|
+
}, De = (e, t = !0) => {
|
|
199
|
+
let n = z.current;
|
|
200
|
+
!n || n.pointerId !== e.pointerId || (z.current = null, V(null), n.moved ? t && n.preview !== _ && JSON.stringify(n.preview) !== JSON.stringify(_) && T?.(n.preview) : !n.additive && P.length > 1 && Z([n.id]));
|
|
201
|
+
}, Oe = (e, t, n) => {
|
|
202
|
+
let r = P.includes(n.id) ? [...P] : [n.id];
|
|
203
|
+
if (e.key === "Enter") {
|
|
204
|
+
e.preventDefault(), Z(e.shiftKey ? [.../* @__PURE__ */ new Set([...P, n.id])] : [n.id]);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (e.key === "Escape") {
|
|
208
|
+
Z([]);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!(!J || t.locked)) {
|
|
212
|
+
if (e.key === "Delete" || e.key === "Backspace") e.preventDefault(), T?.(d(_, r)), Z([]);
|
|
213
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
let r = e.key === "ArrowLeft" ? -1 : 1;
|
|
216
|
+
if (t.magnetic) {
|
|
217
|
+
let e = o(_, n.id);
|
|
218
|
+
e && T?.(l(_, n.id, { index: Math.max(0, e.index + r) }));
|
|
219
|
+
} else T?.(l(_, n.id, { start: Math.max(0, u(n.start + r * (e.shiftKey ? 1 : 1 / O), O)) }));
|
|
220
|
+
requestAnimationFrame(() => document.querySelector(`[data-clip-id="${CSS.escape(n.id)}"]`)?.focus());
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}, $ = y(null), ke = (e) => {
|
|
224
|
+
e.button === 0 && (e.currentTarget.setPointerCapture(e.pointerId), $.current = e.pointerId, D.pause(), D.setScrubbing(!0), D.seek(u(X(e.clientX), O)));
|
|
225
|
+
}, Ae = (e) => {
|
|
226
|
+
$.current === e.pointerId && D.seek(u(X(e.clientX), O));
|
|
227
|
+
}, je = (e) => {
|
|
228
|
+
$.current === e.pointerId && ($.current = null, D.setScrubbing(!1));
|
|
229
|
+
}, Me = (e) => {
|
|
230
|
+
let t = e.shiftKey ? 1 : 1 / O, n = D.getState().time, r = e.key === "ArrowLeft" || e.key === "ArrowDown" ? n - t : e.key === "ArrowRight" || e.key === "ArrowUp" ? n + t : e.key === "Home" ? 0 : e.key === "End" ? D.getState().duration : e.key === "PageUp" ? n - 10 : e.key === "PageDown" ? n + 10 : null;
|
|
231
|
+
r != null && (e.preventDefault(), D.pause(), D.seek(u(r, O)));
|
|
232
|
+
}, Ne = (e, t) => {
|
|
233
|
+
let n = u(X(e.clientX), O);
|
|
234
|
+
return {
|
|
235
|
+
trackId: t.id,
|
|
236
|
+
time: n,
|
|
237
|
+
index: t.magnetic ? c(t, n) : void 0
|
|
238
|
+
};
|
|
239
|
+
}, Pe = (e, t) => {
|
|
240
|
+
if (!M || t.locked || !e.dataTransfer.types.includes("application/x-bl-timeline-media")) return;
|
|
241
|
+
e.preventDefault(), e.dataTransfer.dropEffect = "copy";
|
|
242
|
+
let n = Ne(e, t);
|
|
243
|
+
U((e) => e && e.trackId === n.trackId && e.time === n.time && e.index === n.index ? e : n);
|
|
244
|
+
}, Fe = (e, t) => {
|
|
245
|
+
let n = e.dataTransfer.getData(C);
|
|
246
|
+
U(null), !(!M || !n || t.locked) && (e.preventDefault(), M(n, Ne(e, t)));
|
|
247
|
+
}, Ie = (e) => (t) => {
|
|
248
|
+
t && (L.current[e] = t);
|
|
249
|
+
}, Le = (e, t) => e.name ?? (e.kind === "audio" ? `Audio ${t + 1}` : e.magnetic ? "Main" : `Video ${t + 1}`), Re = K.tracks.reduce((e, t) => e + j(t), 0), ze = H && K.tracks.find((e) => e.id === H.trackId);
|
|
250
|
+
return /* @__PURE__ */ x("div", {
|
|
251
|
+
"data-slot": "video-timeline",
|
|
252
|
+
role: "group",
|
|
253
|
+
"aria-label": "Timeline",
|
|
254
|
+
className: e("relative flex min-h-0 flex-col overflow-hidden bg-background text-foreground select-none", ve),
|
|
255
|
+
style: {
|
|
256
|
+
"--header": `${w}px`,
|
|
257
|
+
"--ruler": `${re}px`,
|
|
258
|
+
...ye
|
|
259
|
+
},
|
|
260
|
+
children: /* @__PURE__ */ x("div", {
|
|
261
|
+
ref: F,
|
|
262
|
+
className: "bl-scroll relative min-h-0 flex-1 overflow-auto overscroll-contain",
|
|
263
|
+
children: /* @__PURE__ */ S("div", {
|
|
264
|
+
className: "relative w-(--content)",
|
|
265
|
+
style: {
|
|
266
|
+
"--content": `${Ce}px`,
|
|
267
|
+
"--lanes": `${Re}px`
|
|
268
|
+
},
|
|
269
|
+
children: [
|
|
270
|
+
/* @__PURE__ */ S("div", {
|
|
271
|
+
className: "sticky top-0 z-30 flex h-(--ruler) w-full shadow-hairline-b",
|
|
272
|
+
children: [/* @__PURE__ */ x("div", {
|
|
273
|
+
className: "sticky left-0 z-10 box-border flex w-(--header) shrink-0 items-center border-r border-border bg-background px-3",
|
|
274
|
+
children: /* @__PURE__ */ x(le, {
|
|
275
|
+
clock: D,
|
|
276
|
+
fps: O
|
|
277
|
+
})
|
|
278
|
+
}), /* @__PURE__ */ S(ue, {
|
|
279
|
+
clock: D,
|
|
280
|
+
fps: O,
|
|
281
|
+
duration: q,
|
|
282
|
+
onPointerDown: ke,
|
|
283
|
+
onPointerMove: Ae,
|
|
284
|
+
onPointerUp: je,
|
|
285
|
+
onPointerCancel: je,
|
|
286
|
+
onKeyDown: Me,
|
|
287
|
+
children: [/* @__PURE__ */ x("canvas", {
|
|
288
|
+
ref: I,
|
|
289
|
+
"aria-hidden": !0,
|
|
290
|
+
className: "sticky left-(--header) block h-full w-[calc(var(--view)-var(--header))] text-muted-foreground",
|
|
291
|
+
style: { "--view": `${W.w}px` }
|
|
292
|
+
}), /* @__PURE__ */ x("div", {
|
|
293
|
+
ref: Ie(0),
|
|
294
|
+
"aria-hidden": !0,
|
|
295
|
+
className: "pointer-events-none absolute top-0 left-0 h-full translate-x-(--ph)",
|
|
296
|
+
children: /* @__PURE__ */ x("div", { className: "absolute -left-[5px] bottom-0 h-3 w-[11px] rounded-b-sm bg-destructive" })
|
|
297
|
+
})]
|
|
298
|
+
})]
|
|
299
|
+
}),
|
|
300
|
+
K.tracks.map((n, o) => {
|
|
301
|
+
let c = j(n);
|
|
302
|
+
return /* @__PURE__ */ S("div", {
|
|
303
|
+
role: "group",
|
|
304
|
+
"aria-label": Le(n, o),
|
|
305
|
+
className: "relative flex h-(--h) shadow-hairline-b",
|
|
306
|
+
style: { "--h": `${c}px` },
|
|
307
|
+
children: [/* @__PURE__ */ S("div", {
|
|
308
|
+
className: "sticky left-0 z-20 box-border flex w-(--header) shrink-0 items-center gap-0.5 border-r border-border bg-background ps-3 pe-1.5",
|
|
309
|
+
children: [
|
|
310
|
+
/* @__PURE__ */ x("span", {
|
|
311
|
+
className: "min-w-0 flex-1 truncate text-caption font-semibold text-foreground/70",
|
|
312
|
+
children: Le(n, o)
|
|
313
|
+
}),
|
|
314
|
+
n.kind === "video" ? /* @__PURE__ */ x(r, {
|
|
315
|
+
size: "sm",
|
|
316
|
+
"aria-label": "Hide track",
|
|
317
|
+
isSelected: !!n.hidden,
|
|
318
|
+
isDisabled: !J,
|
|
319
|
+
className: "size-6 min-w-6 rounded-md px-0",
|
|
320
|
+
onChange: (e) => T?.(g(_, n.id, { hidden: e })),
|
|
321
|
+
children: /* @__PURE__ */ x(t, {
|
|
322
|
+
name: "eye",
|
|
323
|
+
size: 14
|
|
324
|
+
})
|
|
325
|
+
}) : null,
|
|
326
|
+
/* @__PURE__ */ x(r, {
|
|
327
|
+
size: "sm",
|
|
328
|
+
"aria-label": "Mute track",
|
|
329
|
+
isSelected: !!n.muted,
|
|
330
|
+
isDisabled: !J,
|
|
331
|
+
className: "size-6 min-w-6 rounded-md px-0",
|
|
332
|
+
onChange: (e) => T?.(g(_, n.id, { muted: e })),
|
|
333
|
+
children: /* @__PURE__ */ x(t, {
|
|
334
|
+
name: "speaker",
|
|
335
|
+
size: 14
|
|
336
|
+
})
|
|
337
|
+
}),
|
|
338
|
+
/* @__PURE__ */ x(r, {
|
|
339
|
+
size: "sm",
|
|
340
|
+
"aria-label": "Lock track",
|
|
341
|
+
isSelected: !!n.locked,
|
|
342
|
+
isDisabled: !J,
|
|
343
|
+
className: "size-6 min-w-6 rounded-md px-0",
|
|
344
|
+
onChange: (e) => T?.(g(_, n.id, { locked: e })),
|
|
345
|
+
children: /* @__PURE__ */ x(t, {
|
|
346
|
+
name: "lock",
|
|
347
|
+
size: 14
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
]
|
|
351
|
+
}), /* @__PURE__ */ S("div", {
|
|
352
|
+
ref: (e) => {
|
|
353
|
+
e ? R.current.set(n.id, e) : R.current.delete(n.id);
|
|
354
|
+
},
|
|
355
|
+
className: e("relative min-w-0 flex-1", n.magnetic ? "bg-secondary/60" : "bg-secondary/30", n.locked && "opacity-60"),
|
|
356
|
+
onPointerDown: (e) => {
|
|
357
|
+
e.button === 0 && e.target === e.currentTarget && (Z([]), D.seek(u(X(e.clientX), O)));
|
|
358
|
+
},
|
|
359
|
+
onDragOver: (e) => Pe(e, n),
|
|
360
|
+
onDragLeave: () => U(null),
|
|
361
|
+
onDrop: (e) => Fe(e, n),
|
|
362
|
+
children: [n.clips.map((t) => {
|
|
363
|
+
let r = B?.kind === "move" && B.moved && B.id === t.id, o = (r ? B.ghost : t.start) * N, c = Math.max(4, i(t) * N), l = P.includes(t.id), u = E[t.media], d = t.label ?? u?.name ?? t.media, f = {
|
|
364
|
+
"--l": `${o}px`,
|
|
365
|
+
"--w": `${c}px`
|
|
366
|
+
};
|
|
367
|
+
return /* @__PURE__ */ S(ee, { children: [/* @__PURE__ */ x("div", {
|
|
368
|
+
"aria-hidden": !0,
|
|
369
|
+
"data-lifted": r || void 0,
|
|
370
|
+
className: "pointer-events-none absolute inset-y-1 left-(--l) w-(--w) rounded-md bg-background data-lifted:z-10",
|
|
371
|
+
style: f
|
|
372
|
+
}), /* @__PURE__ */ S("div", {
|
|
373
|
+
"data-clip-id": t.id,
|
|
374
|
+
role: "button",
|
|
375
|
+
tabIndex: 0,
|
|
376
|
+
"aria-pressed": l,
|
|
377
|
+
"aria-label": `${d}, ${s(t.start)} to ${s(a(t))}`,
|
|
378
|
+
"data-selected": l || void 0,
|
|
379
|
+
"data-lifted": r || void 0,
|
|
380
|
+
"data-kind": n.kind,
|
|
381
|
+
className: e("group/clip absolute inset-y-1 left-(--l) box-border w-(--w) cursor-grab overflow-hidden rounded-md border outline-none", _e?.(t, n) ?? (n.kind === "audio" ? "border-success/45 bg-success/18" : "border-primary/45 bg-primary/18"), "focus-visible:ring-2 focus-visible:ring-ring data-lifted:z-10 data-lifted:cursor-grabbing data-lifted:opacity-85 data-lifted:shadow-lg data-selected:border-foreground data-selected:ring-1 data-selected:ring-foreground"),
|
|
382
|
+
style: f,
|
|
383
|
+
onPointerDown: (e) => Q(e, n, t, "move"),
|
|
384
|
+
onPointerMove: Ee,
|
|
385
|
+
onPointerUp: (e) => De(e),
|
|
386
|
+
onPointerCancel: (e) => De(e, !1),
|
|
387
|
+
onKeyDown: (e) => Oe(e, n, t),
|
|
388
|
+
children: [
|
|
389
|
+
/* @__PURE__ */ x("div", {
|
|
390
|
+
className: "pointer-events-none absolute inset-0",
|
|
391
|
+
children: A ? A(t, n, {
|
|
392
|
+
width: c,
|
|
393
|
+
selected: l
|
|
394
|
+
}) : null
|
|
395
|
+
}),
|
|
396
|
+
t.transition ? /* @__PURE__ */ x("div", {
|
|
397
|
+
"aria-hidden": !0,
|
|
398
|
+
className: "pointer-events-none absolute inset-y-0 left-0 w-(--tw) bg-linear-to-r from-background/70 to-transparent",
|
|
399
|
+
style: { "--tw": `${t.transition * N}px` }
|
|
400
|
+
}) : null,
|
|
401
|
+
t.fadeIn ? /* @__PURE__ */ x("div", {
|
|
402
|
+
"aria-hidden": !0,
|
|
403
|
+
className: "pointer-events-none absolute top-0 left-0 h-full w-(--fw) bg-linear-to-br from-background/60 from-50% to-transparent to-50%",
|
|
404
|
+
style: { "--fw": `${t.fadeIn * N}px` }
|
|
405
|
+
}) : null,
|
|
406
|
+
t.fadeOut ? /* @__PURE__ */ x("div", {
|
|
407
|
+
"aria-hidden": !0,
|
|
408
|
+
className: "pointer-events-none absolute top-0 right-0 h-full w-(--fw) bg-linear-to-bl from-background/60 from-50% to-transparent to-50%",
|
|
409
|
+
style: { "--fw": `${t.fadeOut * N}px` }
|
|
410
|
+
}) : null,
|
|
411
|
+
/* @__PURE__ */ S("div", {
|
|
412
|
+
className: "pointer-events-none absolute inset-x-1.5 top-0.5 flex min-w-0 items-center gap-1 text-caption2 font-semibold text-foreground [text-shadow:0_1px_2px_var(--background)]",
|
|
413
|
+
children: [/* @__PURE__ */ x("span", {
|
|
414
|
+
className: "truncate",
|
|
415
|
+
children: d
|
|
416
|
+
}), (t.speed || 1) === 1 ? null : /* @__PURE__ */ S("span", {
|
|
417
|
+
className: "shrink-0 rounded-sm bg-background/70 px-1 tabular-nums",
|
|
418
|
+
children: [t.speed, "×"]
|
|
419
|
+
})]
|
|
420
|
+
}),
|
|
421
|
+
J && !n.locked ? /* @__PURE__ */ S(ne, { children: [/* @__PURE__ */ x("div", {
|
|
422
|
+
"aria-hidden": !0,
|
|
423
|
+
className: "absolute inset-y-0 left-0 z-10 w-2 cursor-ew-resize bg-foreground/0 group-hover/clip:bg-foreground/25 group-data-selected/clip:bg-foreground/70",
|
|
424
|
+
onPointerDown: (e) => Q(e, n, t, "start")
|
|
425
|
+
}), /* @__PURE__ */ x("div", {
|
|
426
|
+
"aria-hidden": !0,
|
|
427
|
+
className: "absolute inset-y-0 right-0 z-10 w-2 cursor-ew-resize bg-foreground/0 group-hover/clip:bg-foreground/25 group-data-selected/clip:bg-foreground/70",
|
|
428
|
+
onPointerDown: (e) => Q(e, n, t, "end")
|
|
429
|
+
})] }) : null
|
|
430
|
+
]
|
|
431
|
+
})] }, t.id);
|
|
432
|
+
}), ze?.id === n.id && H ? /* @__PURE__ */ x("div", {
|
|
433
|
+
"aria-hidden": !0,
|
|
434
|
+
className: "pointer-events-none absolute inset-y-0 left-(--dx) w-0.5 bg-primary",
|
|
435
|
+
style: { "--dx": `${(n.magnetic && H.index != null ? n.clips[H.index]?.start ?? m({ tracks: [n] }) : H.time) * N}px` }
|
|
436
|
+
}) : null]
|
|
437
|
+
})]
|
|
438
|
+
}, n.id);
|
|
439
|
+
}),
|
|
440
|
+
/* @__PURE__ */ S("div", {
|
|
441
|
+
"aria-hidden": !0,
|
|
442
|
+
className: "pointer-events-none absolute top-(--ruler) left-(--header) z-10 h-(--lanes) w-0",
|
|
443
|
+
children: [/* @__PURE__ */ x("div", {
|
|
444
|
+
ref: Ie(1),
|
|
445
|
+
className: "absolute inset-y-0 left-0 w-px translate-x-(--ph) bg-destructive"
|
|
446
|
+
}), B?.snap == null ? null : /* @__PURE__ */ x("div", {
|
|
447
|
+
className: "absolute inset-y-0 left-(--sx) w-px bg-warning",
|
|
448
|
+
style: { "--sx": `${B.snap * N}px` }
|
|
449
|
+
})]
|
|
450
|
+
})
|
|
451
|
+
]
|
|
452
|
+
})
|
|
453
|
+
})
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function le({ clock: e, fps: t }) {
|
|
457
|
+
let n = _(e, (e) => u(e.time, t));
|
|
458
|
+
return /* @__PURE__ */ x("span", {
|
|
459
|
+
className: "font-mono text-caption2 text-foreground/70 tabular-nums",
|
|
460
|
+
children: s(n, t)
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
function ue({ clock: e, fps: t, duration: n, children: r, ...i }) {
|
|
464
|
+
let a = _(e, (e) => u(e.time, t));
|
|
465
|
+
return /* @__PURE__ */ x("div", {
|
|
466
|
+
role: "slider",
|
|
467
|
+
tabIndex: 0,
|
|
468
|
+
"aria-label": "Playhead",
|
|
469
|
+
"aria-valuemin": 0,
|
|
470
|
+
"aria-valuemax": Math.round(n * 100) / 100,
|
|
471
|
+
"aria-valuenow": Math.round(a * 100) / 100,
|
|
472
|
+
"aria-valuetext": s(a, t),
|
|
473
|
+
className: "relative h-full flex-1 cursor-col-resize bg-background outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
|
|
474
|
+
...i,
|
|
475
|
+
children: r
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
//#endregion
|
|
479
|
+
export { D as VideoTimeline, E as fitTimelineZoom, se as rulerSteps, C as timelineMediaType, T as timelineZoomRange };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { VariantProps } from 'class-variance-authority';
|
|
3
|
+
export declare const waveformVariants: (props?: ({
|
|
4
|
+
tone?: "primary" | "muted" | "success" | "default" | null | undefined;
|
|
5
|
+
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
6
|
+
export interface WaveformProps extends VariantProps<typeof waveformVariants> {
|
|
7
|
+
/** The loudest |sample| of each slice, 0…1. */
|
|
8
|
+
peaks: ArrayLike<number>;
|
|
9
|
+
/** Slices per second. */
|
|
10
|
+
rate: number;
|
|
11
|
+
/** The media time at the left edge. Default 0. */
|
|
12
|
+
from?: number;
|
|
13
|
+
/** The media time at the right edge. Default: the end of the peaks. */
|
|
14
|
+
to?: number;
|
|
15
|
+
/** Scales the bars (a clip's volume). Default 1. */
|
|
16
|
+
gain?: number;
|
|
17
|
+
/** `mirror` grows from the middle; `bottom` rises from the floor. Default `mirror`. */
|
|
18
|
+
variant?: 'mirror' | 'bottom';
|
|
19
|
+
className?: string;
|
|
20
|
+
style?: CSSProperties;
|
|
21
|
+
}
|
|
22
|
+
export declare function Waveform({ peaks, rate, from, to, gain, variant, tone, className, style }: WaveformProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
//# sourceMappingURL=waveform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waveform.d.ts","sourceRoot":"","sources":["../../src/components/waveform.tsx"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AASlE,eAAO,MAAM,gBAAgB;;8EAU3B,CAAC;AAEH,MAAM,WAAW,aAAc,SAAQ,YAAY,CAAC,OAAO,gBAAgB,CAAC;IAC1E,+CAA+C;IAC/C,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAQ,EAAE,EAAE,EAAE,IAAQ,EAAE,OAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,aAAa,2CAoC1H"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn as e } from "../lib/utils.js";
|
|
3
|
+
import { useLayoutEffect as t, useRef as n } from "react";
|
|
4
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
5
|
+
import { cva as i } from "class-variance-authority";
|
|
6
|
+
//#region src/components/waveform.tsx
|
|
7
|
+
var a = i("relative block h-full w-full", {
|
|
8
|
+
variants: { tone: {
|
|
9
|
+
default: "text-foreground/55",
|
|
10
|
+
primary: "text-primary",
|
|
11
|
+
success: "text-success",
|
|
12
|
+
muted: "text-muted-foreground"
|
|
13
|
+
} },
|
|
14
|
+
defaultVariants: { tone: "default" }
|
|
15
|
+
});
|
|
16
|
+
function o({ peaks: i, rate: o, from: s = 0, to: c, gain: l = 1, variant: u = "mirror", tone: d, className: f, style: p }) {
|
|
17
|
+
let m = n(null), h = c ?? i.length / Math.max(1e-6, o);
|
|
18
|
+
return t(() => {
|
|
19
|
+
let e = m.current;
|
|
20
|
+
if (!e) return;
|
|
21
|
+
let t = () => {
|
|
22
|
+
let t = typeof devicePixelRatio == "number" ? devicePixelRatio : 1, n = Math.max(1, Math.round(e.clientWidth * t)), r = Math.max(1, Math.round(e.clientHeight * t));
|
|
23
|
+
e.width !== n && (e.width = n), e.height !== r && (e.height = r);
|
|
24
|
+
let a = e.getContext("2d");
|
|
25
|
+
if (!a) return;
|
|
26
|
+
a.clearRect(0, 0, n, r), a.fillStyle = getComputedStyle(e).color;
|
|
27
|
+
let c = h - s;
|
|
28
|
+
if (!(!(c > 0) || !i.length)) for (let e = 0; e < n; e++) {
|
|
29
|
+
let d = Math.floor((s + e / n * c) * o), f = Math.max(d + 1, Math.floor((s + (e + 1) / n * c) * o)), p = 0;
|
|
30
|
+
for (let e = Math.max(0, d); e < Math.min(i.length, f); e++) i[e] > p && (p = i[e]);
|
|
31
|
+
let m = Math.max(t, Math.min(1, p * l) * r);
|
|
32
|
+
u === "bottom" ? a.fillRect(e, r - m, 1, m) : a.fillRect(e, (r - m) / 2, 1, m);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
if (t(), typeof ResizeObserver > "u") return;
|
|
36
|
+
let n = new ResizeObserver(t);
|
|
37
|
+
return n.observe(e), () => n.disconnect();
|
|
38
|
+
}, [
|
|
39
|
+
i,
|
|
40
|
+
o,
|
|
41
|
+
s,
|
|
42
|
+
h,
|
|
43
|
+
l,
|
|
44
|
+
u,
|
|
45
|
+
d,
|
|
46
|
+
f
|
|
47
|
+
]), /* @__PURE__ */ r("canvas", {
|
|
48
|
+
ref: m,
|
|
49
|
+
"data-slot": "waveform",
|
|
50
|
+
"aria-hidden": !0,
|
|
51
|
+
className: e(a({ tone: d }), f),
|
|
52
|
+
style: p
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { o as Waveform, a as waveformVariants };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/* BL UI — FFmpeg worker. https://blamy.github.io/ui/#/ffmpeg
|
|
2
|
+
*
|
|
3
|
+
* Serve this file next to the FFmpeg wasm build (ffmpeg.js, ffmpeg_g.wasm, ffprobe.js, ffprobe_g.wasm; built from
|
|
4
|
+
* openclaw/ffmpeg-wasm by tools/ffmpeg-wasm) and point lib/ffmpeg at that directory. lib/ffmpeg starts it as a module
|
|
5
|
+
* worker and hands it one job at a time. A job runs a tool the way a command line would: a fresh FFmpeg (or FFprobe)
|
|
6
|
+
* instance with the job's arguments, its working directory holding the inputs: Blobs and Files mounted read-only with
|
|
7
|
+
* WORKERFS (nothing is copied into memory), bytes written as files. When it exits, the worker posts back the exit code,
|
|
8
|
+
* stdout, stderr and every file the run wrote; `-progress pipe:2` reports and log lines stream while it runs. The worker
|
|
9
|
+
* owns the Emscripten runtime and its threads, so a job is cancelled by terminating the worker.
|
|
10
|
+
*
|
|
11
|
+
* The page must be cross-origin isolated (COOP/COEP, with this file and the tool scripts served under the same
|
|
12
|
+
* embedder policy): the build uses threads, which need SharedArrayBuffer. Module script, no imports, no build step.
|
|
13
|
+
* MIT licensed, like the rest of BL UI; FFmpeg itself is LGPL-2.1-or-later. */
|
|
14
|
+
|
|
15
|
+
const tools = new Map();
|
|
16
|
+
|
|
17
|
+
/** The tool's module factory, imported once per location (a failed import is forgotten, so a later job retries). */
|
|
18
|
+
function load(base, tool) {
|
|
19
|
+
const url = new URL(`${tool}.js`, base).href;
|
|
20
|
+
if (!tools.has(url)) {
|
|
21
|
+
const p = import(url).then((m) => m.default);
|
|
22
|
+
p.catch(() => tools.delete(url));
|
|
23
|
+
tools.set(url, p);
|
|
24
|
+
}
|
|
25
|
+
return tools.get(url);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const PROGRESS_KEYS = /^(frame|fps|bitrate|total_size|out_time_us|out_time_ms|out_time|dup_frames|drop_frames|speed|progress|stream_\d+_\d+_q)$/;
|
|
29
|
+
|
|
30
|
+
/** Reads `-progress` lines; true when the line was one (so it stays out of the log). */
|
|
31
|
+
function progressReader(onReport) {
|
|
32
|
+
const fields = {};
|
|
33
|
+
return (line) => {
|
|
34
|
+
const m = /^([a-z0-9_]+)=(.*)$/.exec(line.trim());
|
|
35
|
+
if (!m || !PROGRESS_KEYS.test(m[1])) return false;
|
|
36
|
+
fields[m[1]] = m[2];
|
|
37
|
+
if (m[1] !== 'progress') return true;
|
|
38
|
+
const us = Number(fields.out_time_us ?? fields.out_time_ms);
|
|
39
|
+
const speed = parseFloat(fields.speed);
|
|
40
|
+
const frame = Number(fields.frame);
|
|
41
|
+
onReport({
|
|
42
|
+
time: Number.isFinite(us) && us >= 0 ? us / 1e6 : 0,
|
|
43
|
+
frame: Number.isFinite(frame) ? frame : undefined,
|
|
44
|
+
speed: Number.isFinite(speed) ? speed : undefined,
|
|
45
|
+
done: m[2] === 'end',
|
|
46
|
+
});
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The working directory: Blob inputs mounted (WORKERFS) and linked in by name, byte inputs written. */
|
|
52
|
+
function prepare(FS, inputs) {
|
|
53
|
+
FS.mkdir('/work');
|
|
54
|
+
const blobs = inputs.filter((i) => i.data instanceof Blob);
|
|
55
|
+
if (blobs.length) {
|
|
56
|
+
FS.mkdir('/in');
|
|
57
|
+
FS.mount(FS.filesystems.WORKERFS, { blobs: blobs.map((i) => ({ name: i.name, data: i.data })) }, '/in');
|
|
58
|
+
for (const i of blobs) FS.symlink(`/in/${i.name}`, `/work/${i.name}`);
|
|
59
|
+
}
|
|
60
|
+
for (const i of inputs) if (!(i.data instanceof Blob)) FS.writeFile(`/work/${i.name}`, new Uint8Array(i.data));
|
|
61
|
+
FS.chdir('/work');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Every regular file the run left in the working directory, inputs aside. */
|
|
65
|
+
function collect(FS, inputs) {
|
|
66
|
+
const skip = new Set(inputs.map((i) => i.name));
|
|
67
|
+
const files = {};
|
|
68
|
+
for (const name of FS.readdir('/work')) {
|
|
69
|
+
if (name === '.' || name === '..' || skip.has(name)) continue;
|
|
70
|
+
if (!FS.isFile(FS.lstat(`/work/${name}`).mode)) continue;
|
|
71
|
+
const bytes = FS.readFile(`/work/${name}`);
|
|
72
|
+
files[name] = bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength ? bytes.buffer : bytes.slice().buffer;
|
|
73
|
+
}
|
|
74
|
+
return files;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function run(job) {
|
|
78
|
+
const { id, base, tool, args, inputs, logs } = job;
|
|
79
|
+
const post = (message, transfer) => self.postMessage({ id, ...message }, transfer ?? []);
|
|
80
|
+
const stdout = [];
|
|
81
|
+
const stderr = [];
|
|
82
|
+
const progress = progressReader((p) => post({ type: 'progress', progress: p }));
|
|
83
|
+
let exit;
|
|
84
|
+
let abort;
|
|
85
|
+
const exited = new Promise((resolve, reject) => { exit = resolve; abort = reject; });
|
|
86
|
+
// MODULARIZE keeps the object passed in as the Module, so its FS is reachable even if startup throws.
|
|
87
|
+
const module = {
|
|
88
|
+
arguments: args,
|
|
89
|
+
thisProgram: tool,
|
|
90
|
+
print: (line) => stdout.push(line),
|
|
91
|
+
printErr: (line) => {
|
|
92
|
+
if (progress(line)) return;
|
|
93
|
+
stderr.push(line);
|
|
94
|
+
if (logs) post({ type: 'log', line });
|
|
95
|
+
},
|
|
96
|
+
onExit: (code) => exit(code),
|
|
97
|
+
// A crash (out of memory, a trap) ends the run without an exit code.
|
|
98
|
+
onAbort: (reason) => abort(new Error(`${tool} aborted: ${reason}`)),
|
|
99
|
+
preRun: [(m) => prepare(m.FS, inputs)],
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const factory = await load(base, tool);
|
|
103
|
+
await factory(module).catch((e) => {
|
|
104
|
+
// An exit during startup surfaces as Emscripten's ExitStatus.
|
|
105
|
+
if (e && e.name === 'ExitStatus') exit(e.status);
|
|
106
|
+
else throw e;
|
|
107
|
+
});
|
|
108
|
+
const code = await exited;
|
|
109
|
+
const files = code === 0 ? collect(module.FS, inputs) : {};
|
|
110
|
+
post({ type: 'done', exitCode: code, stdout: stdout.join('\n'), stderr: stderr.join('\n'), files }, Object.values(files));
|
|
111
|
+
} catch (e) {
|
|
112
|
+
post({ type: 'error', error: e instanceof Error ? e.message : String(e), stderr: stderr.join('\n') });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
self.addEventListener('message', (event) => {
|
|
117
|
+
if (event.data && event.data.type === 'run') void run(event.data);
|
|
118
|
+
});
|