reifyui 0.9.0 → 0.10.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/index.cjs +399 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +400 -86
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/timeline/Timeline.jsx +381 -104
- package/styles/timeline.css +72 -12
package/dist/index.cjs
CHANGED
|
@@ -4116,12 +4116,16 @@ function packLayout(layout2, cols = 12) {
|
|
|
4116
4116
|
var import_react26 = require("react");
|
|
4117
4117
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
4118
4118
|
var TL_MIN_PPS = 4;
|
|
4119
|
-
var TL_MAX_PPS =
|
|
4119
|
+
var TL_MAX_PPS = 400;
|
|
4120
4120
|
var TL_DEFAULT_PPS = 26;
|
|
4121
|
-
var TL_HEAD_W =
|
|
4121
|
+
var TL_HEAD_W = 84;
|
|
4122
|
+
var TL_SNAP_PX = 6;
|
|
4123
|
+
var TL_MIN_CLIP_S = 0.1;
|
|
4124
|
+
var CLICK_SLOP = 3;
|
|
4125
|
+
var LANE_H = 56;
|
|
4126
|
+
var CLIP_INSET = 4;
|
|
4122
4127
|
var UNKNOWN_W = 46;
|
|
4123
|
-
var MIN_CLIP_W =
|
|
4124
|
-
var LANE_H = 48;
|
|
4128
|
+
var MIN_CLIP_W = 18;
|
|
4125
4129
|
var clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
4126
4130
|
var TICK_STEPS = [0.1, 0.2, 0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600];
|
|
4127
4131
|
function majorTickStep(pps) {
|
|
@@ -4143,33 +4147,55 @@ function durationLabel(seconds) {
|
|
|
4143
4147
|
const s = Math.round(seconds - m * 60);
|
|
4144
4148
|
return `${m}:${String(s).padStart(2, "0")}`;
|
|
4145
4149
|
}
|
|
4150
|
+
function exactLabel(seconds) {
|
|
4151
|
+
if (!Number.isFinite(seconds)) return "\u2014";
|
|
4152
|
+
const m = Math.floor(Math.max(0, seconds) / 60);
|
|
4153
|
+
const s = Math.max(0, seconds) - m * 60;
|
|
4154
|
+
return `${m}:${s < 10 ? "0" : ""}${s.toFixed(1)}`;
|
|
4155
|
+
}
|
|
4146
4156
|
function layout(clips, pps, sequential) {
|
|
4147
4157
|
let cursor = 0;
|
|
4148
|
-
return clips.map((c) => {
|
|
4158
|
+
return clips.map((c, i) => {
|
|
4149
4159
|
const known = Number.isFinite(c.duration);
|
|
4150
4160
|
const w = known ? Math.max(MIN_CLIP_W, c.duration * pps) : UNKNOWN_W;
|
|
4151
|
-
const
|
|
4161
|
+
const t0 = sequential ? cursor : c.start || 0;
|
|
4152
4162
|
if (sequential) cursor += known ? c.duration : UNKNOWN_W / pps;
|
|
4153
|
-
return { clip: c, x, w, known };
|
|
4163
|
+
return { clip: c, i, t0, x: t0 * pps, w, known };
|
|
4154
4164
|
});
|
|
4155
4165
|
}
|
|
4166
|
+
function snapTo(t, targets, tol) {
|
|
4167
|
+
let best = null;
|
|
4168
|
+
let bestD = tol;
|
|
4169
|
+
for (const s of targets) {
|
|
4170
|
+
const d = Math.abs(s - t);
|
|
4171
|
+
if (d <= bestD) {
|
|
4172
|
+
bestD = d;
|
|
4173
|
+
best = s;
|
|
4174
|
+
}
|
|
4175
|
+
}
|
|
4176
|
+
return best === null ? { value: t, guide: null } : { value: best, guide: best };
|
|
4177
|
+
}
|
|
4156
4178
|
function Timeline({
|
|
4157
4179
|
tracks = [],
|
|
4158
|
-
/** Seconds. Drives the playhead; pass it from whatever is playing. */
|
|
4159
4180
|
currentTime = 0,
|
|
4160
|
-
/** Called with a time in seconds when the ruler or lane background is scrubbed. */
|
|
4161
4181
|
onSeek,
|
|
4162
4182
|
onSelectClip,
|
|
4163
4183
|
selectedClipId = null,
|
|
4164
|
-
/**
|
|
4165
|
-
|
|
4166
|
-
/**
|
|
4184
|
+
/** (clip, edge:'start'|'end', newDurationSeconds, track). Fires once, on release. */
|
|
4185
|
+
onTrim,
|
|
4186
|
+
/** (clip, atSecondsFromClipStart, track). */
|
|
4187
|
+
onSplit,
|
|
4188
|
+
/** Sequential lane: (clip, toIndex, track). Placed lane: (clip, newStartSeconds, track). */
|
|
4189
|
+
onMoveClip,
|
|
4190
|
+
onDeleteClip,
|
|
4167
4191
|
laneAppend,
|
|
4168
4192
|
zoomStorageKey = null,
|
|
4193
|
+
snapStorageKey = null,
|
|
4169
4194
|
emptyLabel = "Nothing here yet.",
|
|
4170
4195
|
className = ""
|
|
4171
4196
|
}) {
|
|
4172
4197
|
const scroller = (0, import_react26.useRef)(null);
|
|
4198
|
+
const innerRef = (0, import_react26.useRef)(null);
|
|
4173
4199
|
const [pps, setPps] = (0, import_react26.useState)(() => {
|
|
4174
4200
|
if (zoomStorageKey && typeof window !== "undefined") {
|
|
4175
4201
|
const n = parseFloat(window.localStorage.getItem(zoomStorageKey) || "");
|
|
@@ -4177,21 +4203,31 @@ function Timeline({
|
|
|
4177
4203
|
}
|
|
4178
4204
|
return TL_DEFAULT_PPS;
|
|
4179
4205
|
});
|
|
4206
|
+
const [snapping, setSnapping] = (0, import_react26.useState)(() => snapStorageKey && typeof window !== "undefined" ? window.localStorage.getItem(snapStorageKey) !== "0" : true);
|
|
4207
|
+
const gesture = (0, import_react26.useRef)(null);
|
|
4208
|
+
const [drag, setDrag] = (0, import_react26.useState)(null);
|
|
4180
4209
|
const anchor = (0, import_react26.useRef)(null);
|
|
4181
4210
|
const rows = (0, import_react26.useMemo)(
|
|
4182
|
-
() => tracks.map((t) => ({
|
|
4211
|
+
() => tracks.map((t) => ({
|
|
4212
|
+
...t,
|
|
4213
|
+
sequential: t.sequential !== false,
|
|
4214
|
+
laid: layout(t.clips || [], pps, t.sequential !== false)
|
|
4215
|
+
})),
|
|
4183
4216
|
[tracks, pps]
|
|
4184
4217
|
);
|
|
4185
4218
|
const contentSeconds = (0, import_react26.useMemo)(() => {
|
|
4186
4219
|
let end = 0;
|
|
4187
|
-
for (const t of rows)
|
|
4188
|
-
for (const { clip, x, w } of t.laid) {
|
|
4189
|
-
void clip;
|
|
4190
|
-
end = Math.max(end, (x + w) / pps);
|
|
4191
|
-
}
|
|
4192
|
-
}
|
|
4220
|
+
for (const t of rows) for (const l of t.laid) end = Math.max(end, l.t0 + l.w / pps);
|
|
4193
4221
|
return end;
|
|
4194
4222
|
}, [rows, pps]);
|
|
4223
|
+
const snapTimes = (0, import_react26.useMemo)(() => {
|
|
4224
|
+
const out = [0, currentTime];
|
|
4225
|
+
for (const t of rows) for (const l of t.laid) {
|
|
4226
|
+
out.push(l.t0);
|
|
4227
|
+
out.push(l.t0 + l.w / pps);
|
|
4228
|
+
}
|
|
4229
|
+
return out;
|
|
4230
|
+
}, [rows, pps, currentTime]);
|
|
4195
4231
|
const setZoom = (0, import_react26.useCallback)((next, clientX) => {
|
|
4196
4232
|
const v = clamp(next, TL_MIN_PPS, TL_MAX_PPS);
|
|
4197
4233
|
const el = scroller.current;
|
|
@@ -4208,6 +4244,32 @@ function Timeline({
|
|
|
4208
4244
|
}
|
|
4209
4245
|
}
|
|
4210
4246
|
}, [pps, zoomStorageKey]);
|
|
4247
|
+
const fitPps = (0, import_react26.useCallback)((seconds) => {
|
|
4248
|
+
const el = scroller.current;
|
|
4249
|
+
if (!el || !(seconds > 0)) return null;
|
|
4250
|
+
const room = el.clientWidth - TL_HEAD_W - 56;
|
|
4251
|
+
return room > 0 ? clamp(room / seconds, TL_MIN_PPS, TL_MAX_PPS) : null;
|
|
4252
|
+
}, []);
|
|
4253
|
+
const fit = (0, import_react26.useCallback)(() => {
|
|
4254
|
+
const v = fitPps(contentSeconds);
|
|
4255
|
+
if (v !== null) {
|
|
4256
|
+
setPps(v);
|
|
4257
|
+
if (scroller.current) scroller.current.scrollLeft = 0;
|
|
4258
|
+
}
|
|
4259
|
+
}, [fitPps, contentSeconds]);
|
|
4260
|
+
const fitted = (0, import_react26.useRef)(false);
|
|
4261
|
+
(0, import_react26.useLayoutEffect)(() => {
|
|
4262
|
+
if (fitted.current || !(contentSeconds > 0)) return;
|
|
4263
|
+
if (zoomStorageKey && typeof window !== "undefined" && window.localStorage.getItem(zoomStorageKey)) {
|
|
4264
|
+
fitted.current = true;
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
4267
|
+
const v = fitPps(contentSeconds);
|
|
4268
|
+
if (v !== null) {
|
|
4269
|
+
fitted.current = true;
|
|
4270
|
+
setPps(v);
|
|
4271
|
+
}
|
|
4272
|
+
}, [contentSeconds, fitPps, zoomStorageKey]);
|
|
4211
4273
|
(0, import_react26.useLayoutEffect)(() => {
|
|
4212
4274
|
const a = anchor.current;
|
|
4213
4275
|
if (!a || !scroller.current) return;
|
|
@@ -4226,40 +4288,201 @@ function Timeline({
|
|
|
4226
4288
|
return () => el.removeEventListener("wheel", onWheel);
|
|
4227
4289
|
}, [pps, setZoom]);
|
|
4228
4290
|
const timeAt = (0, import_react26.useCallback)((clientX) => {
|
|
4229
|
-
const el =
|
|
4291
|
+
const el = innerRef.current;
|
|
4230
4292
|
if (!el) return 0;
|
|
4231
|
-
|
|
4232
|
-
return Math.max(0, (el.scrollLeft + (clientX - rect.left) - TL_HEAD_W) / pps);
|
|
4293
|
+
return Math.max(0, (clientX - el.getBoundingClientRect().left - TL_HEAD_W) / pps);
|
|
4233
4294
|
}, [pps]);
|
|
4234
|
-
const
|
|
4235
|
-
|
|
4236
|
-
e.
|
|
4237
|
-
|
|
4238
|
-
const move = (ev) =>
|
|
4295
|
+
const beginGesture = (0, import_react26.useCallback)((e, spec) => {
|
|
4296
|
+
e.preventDefault();
|
|
4297
|
+
e.stopPropagation();
|
|
4298
|
+
gesture.current = { ...spec, startX: e.clientX, active: false, value: null };
|
|
4299
|
+
const move = (ev) => {
|
|
4300
|
+
const cur = gesture.current;
|
|
4301
|
+
if (!cur) return;
|
|
4302
|
+
if (!cur.active && Math.abs(ev.clientX - cur.startX) < CLICK_SLOP) return;
|
|
4303
|
+
cur.active = true;
|
|
4304
|
+
let t = timeAt(ev.clientX);
|
|
4305
|
+
let guide = null;
|
|
4306
|
+
if (snapping && !ev.altKey && cur.kind !== "scrub") {
|
|
4307
|
+
const r = snapTo(t, cur.snapTimes || snapTimes, TL_SNAP_PX / pps);
|
|
4308
|
+
t = r.value;
|
|
4309
|
+
guide = r.guide;
|
|
4310
|
+
}
|
|
4311
|
+
cur.value = t;
|
|
4312
|
+
if (cur.kind === "scrub") onSeek?.(t);
|
|
4313
|
+
else setDrag(cur.preview ? { ...cur.preview(t), guide } : { guide });
|
|
4314
|
+
};
|
|
4239
4315
|
const up = () => {
|
|
4240
4316
|
window.removeEventListener("pointermove", move);
|
|
4241
4317
|
window.removeEventListener("pointerup", up);
|
|
4318
|
+
document.body.classList.remove("rui-tl-gesturing");
|
|
4319
|
+
const cur = gesture.current;
|
|
4320
|
+
gesture.current = null;
|
|
4321
|
+
setDrag(null);
|
|
4322
|
+
if (cur?.active && cur.value !== null) cur.commit?.(cur.value);
|
|
4323
|
+
else cur?.click?.();
|
|
4242
4324
|
};
|
|
4325
|
+
document.body.classList.add("rui-tl-gesturing");
|
|
4243
4326
|
window.addEventListener("pointermove", move);
|
|
4244
4327
|
window.addEventListener("pointerup", up);
|
|
4245
|
-
}, [
|
|
4328
|
+
}, [timeAt, snapping, snapTimes, pps, onSeek]);
|
|
4329
|
+
const onScrub = (0, import_react26.useCallback)((e) => {
|
|
4330
|
+
if (!onSeek) return;
|
|
4331
|
+
onSeek(timeAt(e.clientX));
|
|
4332
|
+
beginGesture(e, { kind: "scrub" });
|
|
4333
|
+
}, [onSeek, timeAt, beginGesture]);
|
|
4334
|
+
const splitTarget = (0, import_react26.useMemo)(() => {
|
|
4335
|
+
if (!onSplit) return null;
|
|
4336
|
+
for (const track of rows) {
|
|
4337
|
+
for (const l of track.laid) {
|
|
4338
|
+
if (!l.known) continue;
|
|
4339
|
+
if (currentTime > l.t0 + TL_MIN_CLIP_S && currentTime < l.t0 + l.clip.duration - TL_MIN_CLIP_S) {
|
|
4340
|
+
return { track, l };
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
return null;
|
|
4345
|
+
}, [rows, currentTime, onSplit]);
|
|
4346
|
+
const doSplit = (0, import_react26.useCallback)(() => {
|
|
4347
|
+
if (!splitTarget) return;
|
|
4348
|
+
onSplit(splitTarget.l.clip, currentTime - splitTarget.l.t0, splitTarget.track);
|
|
4349
|
+
}, [splitTarget, currentTime, onSplit]);
|
|
4350
|
+
const selected = (0, import_react26.useMemo)(() => {
|
|
4351
|
+
for (const track of rows) for (const l of track.laid) {
|
|
4352
|
+
if (l.clip.id === selectedClipId) return { track, l };
|
|
4353
|
+
}
|
|
4354
|
+
return null;
|
|
4355
|
+
}, [rows, selectedClipId]);
|
|
4246
4356
|
const onKeyDown = (0, import_react26.useCallback)((e) => {
|
|
4357
|
+
const tag = e.target?.tagName;
|
|
4358
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || e.target?.isContentEditable) return;
|
|
4247
4359
|
if (e.key === "+" || e.key === "=") {
|
|
4248
4360
|
e.preventDefault();
|
|
4249
4361
|
setZoom(pps * 1.35);
|
|
4250
|
-
}
|
|
4251
|
-
if (e.key === "-" || e.key === "_") {
|
|
4362
|
+
} else if (e.key === "-" || e.key === "_") {
|
|
4252
4363
|
e.preventDefault();
|
|
4253
4364
|
setZoom(pps / 1.35);
|
|
4365
|
+
} else if (e.key === "b" || e.key === "B") {
|
|
4366
|
+
e.preventDefault();
|
|
4367
|
+
doSplit();
|
|
4368
|
+
} else if ((e.key === "Delete" || e.key === "Backspace") && selected && onDeleteClip) {
|
|
4369
|
+
e.preventDefault();
|
|
4370
|
+
onDeleteClip(selected.l.clip, selected.track);
|
|
4254
4371
|
}
|
|
4255
|
-
}, [pps, setZoom]);
|
|
4372
|
+
}, [pps, setZoom, doSplit, selected, onDeleteClip]);
|
|
4373
|
+
const toggleSnap = (0, import_react26.useCallback)(() => {
|
|
4374
|
+
setSnapping((v) => {
|
|
4375
|
+
const next = !v;
|
|
4376
|
+
if (snapStorageKey && typeof window !== "undefined") {
|
|
4377
|
+
try {
|
|
4378
|
+
window.localStorage.setItem(snapStorageKey, next ? "1" : "0");
|
|
4379
|
+
} catch {
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
return next;
|
|
4383
|
+
});
|
|
4384
|
+
}, [snapStorageKey]);
|
|
4256
4385
|
const major = majorTickStep(pps);
|
|
4257
4386
|
const minor = major / 5;
|
|
4258
|
-
const laneW = Math.max(contentSeconds * pps +
|
|
4387
|
+
const laneW = Math.max(contentSeconds * pps + 140, 320);
|
|
4259
4388
|
const ticks = [];
|
|
4260
4389
|
for (let t = 0; t <= contentSeconds + major; t += major) ticks.push(t);
|
|
4261
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: `rui-tl ${className}`, onKeyDown, tabIndex:
|
|
4262
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.
|
|
4390
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: `rui-tl ${className}`, onKeyDown, tabIndex: 0, children: [
|
|
4391
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-bar", children: [
|
|
4392
|
+
onSplit && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4393
|
+
"button",
|
|
4394
|
+
{
|
|
4395
|
+
type: "button",
|
|
4396
|
+
className: "rui-tl-btn",
|
|
4397
|
+
onClick: doSplit,
|
|
4398
|
+
disabled: !splitTarget,
|
|
4399
|
+
title: splitTarget ? "Split at the playhead (B)" : "Move the playhead inside a clip to split it",
|
|
4400
|
+
children: [
|
|
4401
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4402
|
+
"svg",
|
|
4403
|
+
{
|
|
4404
|
+
width: "13",
|
|
4405
|
+
height: "13",
|
|
4406
|
+
viewBox: "0 0 24 24",
|
|
4407
|
+
fill: "none",
|
|
4408
|
+
stroke: "currentColor",
|
|
4409
|
+
strokeWidth: "2",
|
|
4410
|
+
strokeLinecap: "round",
|
|
4411
|
+
"aria-hidden": "true",
|
|
4412
|
+
children: [
|
|
4413
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("circle", { cx: "6", cy: "6", r: "3" }),
|
|
4414
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("circle", { cx: "6", cy: "18", r: "3" }),
|
|
4415
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("line", { x1: "20", y1: "4", x2: "8.12", y2: "15.88" }),
|
|
4416
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("line", { x1: "14.47", y1: "14.48", x2: "20", y2: "20" }),
|
|
4417
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("line", { x1: "8.12", y1: "8.12", x2: "12", y2: "12" })
|
|
4418
|
+
]
|
|
4419
|
+
}
|
|
4420
|
+
),
|
|
4421
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { children: "Split" })
|
|
4422
|
+
]
|
|
4423
|
+
}
|
|
4424
|
+
),
|
|
4425
|
+
onDeleteClip && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4426
|
+
"button",
|
|
4427
|
+
{
|
|
4428
|
+
type: "button",
|
|
4429
|
+
className: "rui-tl-btn",
|
|
4430
|
+
disabled: !selected,
|
|
4431
|
+
onClick: () => selected && onDeleteClip(selected.l.clip, selected.track),
|
|
4432
|
+
title: selected ? "Remove the selected clip" : "Select a clip to remove it",
|
|
4433
|
+
children: "Remove"
|
|
4434
|
+
}
|
|
4435
|
+
),
|
|
4436
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4437
|
+
"button",
|
|
4438
|
+
{
|
|
4439
|
+
type: "button",
|
|
4440
|
+
className: `rui-tl-btn${snapping ? " is-on" : ""}`,
|
|
4441
|
+
onClick: toggleSnap,
|
|
4442
|
+
"aria-pressed": snapping,
|
|
4443
|
+
title: "Snap to clip edges and the playhead. Hold Alt while dragging to bypass.",
|
|
4444
|
+
children: "Snap"
|
|
4445
|
+
}
|
|
4446
|
+
),
|
|
4447
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-time", "aria-label": "Playhead position", children: exactLabel(currentTime) }),
|
|
4448
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-spacer" }),
|
|
4449
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4450
|
+
"button",
|
|
4451
|
+
{
|
|
4452
|
+
type: "button",
|
|
4453
|
+
className: "rui-tl-btn rui-tl-icon",
|
|
4454
|
+
onClick: () => setZoom(pps / 1.35),
|
|
4455
|
+
disabled: pps <= TL_MIN_PPS + 1e-6,
|
|
4456
|
+
"aria-label": "Zoom out",
|
|
4457
|
+
title: "Zoom out (\u2212)",
|
|
4458
|
+
children: "\u2212"
|
|
4459
|
+
}
|
|
4460
|
+
),
|
|
4461
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4462
|
+
"button",
|
|
4463
|
+
{
|
|
4464
|
+
type: "button",
|
|
4465
|
+
className: "rui-tl-btn rui-tl-icon",
|
|
4466
|
+
onClick: () => setZoom(pps * 1.35),
|
|
4467
|
+
disabled: pps >= TL_MAX_PPS - 1e-6,
|
|
4468
|
+
"aria-label": "Zoom in",
|
|
4469
|
+
title: "Zoom in (+)",
|
|
4470
|
+
children: "+"
|
|
4471
|
+
}
|
|
4472
|
+
),
|
|
4473
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4474
|
+
"button",
|
|
4475
|
+
{
|
|
4476
|
+
type: "button",
|
|
4477
|
+
className: "rui-tl-btn",
|
|
4478
|
+
onClick: fit,
|
|
4479
|
+
disabled: !(contentSeconds > 0),
|
|
4480
|
+
title: "Fit the whole timeline in the panel",
|
|
4481
|
+
children: "Fit"
|
|
4482
|
+
}
|
|
4483
|
+
)
|
|
4484
|
+
] }),
|
|
4485
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-scroll", ref: scroller, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-inner", ref: innerRef, style: { width: TL_HEAD_W + laneW }, children: [
|
|
4263
4486
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-row rui-tl-rulerrow", children: [
|
|
4264
4487
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-head rui-tl-rulerhead", "aria-hidden": "true" }),
|
|
4265
4488
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
@@ -4268,9 +4491,8 @@ function Timeline({
|
|
|
4268
4491
|
className: "rui-tl-ruler",
|
|
4269
4492
|
style: {
|
|
4270
4493
|
width: laneW,
|
|
4271
|
-
// Minor ticks are a repeating background
|
|
4272
|
-
//
|
|
4273
|
-
// does not.
|
|
4494
|
+
// Minor ticks are a repeating background, not elements: ten minutes at a fine zoom
|
|
4495
|
+
// is thousands of nodes carrying no information a stripe does not.
|
|
4274
4496
|
backgroundImage: "linear-gradient(90deg, var(--uic-line, #DDDFE6) 0 1px, transparent 1px),linear-gradient(90deg, var(--uic-line-soft, #EFF1F4) 0 1px, transparent 1px)",
|
|
4275
4497
|
backgroundSize: `${major * pps}px 9px, ${minor * pps}px 5px`
|
|
4276
4498
|
},
|
|
@@ -4312,35 +4534,27 @@ function Timeline({
|
|
|
4312
4534
|
},
|
|
4313
4535
|
children: [
|
|
4314
4536
|
track.laid.length === 0 && track.emptyLabel && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("p", { className: "rui-tl-laneempty", children: track.emptyLabel }),
|
|
4315
|
-
track.laid.map((
|
|
4316
|
-
|
|
4537
|
+
track.laid.map((l) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4538
|
+
Clip,
|
|
4317
4539
|
{
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
},
|
|
4329
|
-
children: [
|
|
4330
|
-
clip.poster ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("img", { className: "rui-tl-poster", src: clip.poster, alt: "", loading: "lazy" }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-blank", "aria-hidden": "true", children: clip.glyph }),
|
|
4331
|
-
clip.badge && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-badge", children: clip.badge }),
|
|
4332
|
-
known && w > 44 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-dur", children: durationLabel(clip.duration) }),
|
|
4333
|
-
clip.label && w > 96 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-name", children: clip.label }),
|
|
4334
|
-
clipActions && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-acts", children: clipActions(clip, i) })
|
|
4335
|
-
]
|
|
4540
|
+
l,
|
|
4541
|
+
track,
|
|
4542
|
+
pps,
|
|
4543
|
+
selected: selectedClipId === l.clip.id,
|
|
4544
|
+
drag,
|
|
4545
|
+
onSelect: () => onSelectClip?.(l.clip, l.i),
|
|
4546
|
+
beginGesture,
|
|
4547
|
+
onTrim,
|
|
4548
|
+
onMoveClip,
|
|
4549
|
+
snapTimes
|
|
4336
4550
|
},
|
|
4337
|
-
clip.id ?? i
|
|
4551
|
+
l.clip.id ?? l.i
|
|
4338
4552
|
)),
|
|
4339
4553
|
laneAppend && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4340
4554
|
"span",
|
|
4341
4555
|
{
|
|
4342
4556
|
className: "rui-tl-append",
|
|
4343
|
-
style: { left: track.laid.reduce((n,
|
|
4557
|
+
style: { left: track.laid.reduce((n, x) => Math.max(n, x.x + x.w), 0) + 6 },
|
|
4344
4558
|
children: laneAppend(track)
|
|
4345
4559
|
}
|
|
4346
4560
|
)
|
|
@@ -4348,7 +4562,15 @@ function Timeline({
|
|
|
4348
4562
|
}
|
|
4349
4563
|
)
|
|
4350
4564
|
] }, track.id)),
|
|
4351
|
-
|
|
4565
|
+
drag?.guide != null && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4566
|
+
"div",
|
|
4567
|
+
{
|
|
4568
|
+
className: "rui-tl-guide",
|
|
4569
|
+
style: { left: TL_HEAD_W + drag.guide * pps },
|
|
4570
|
+
"aria-hidden": "true"
|
|
4571
|
+
}
|
|
4572
|
+
),
|
|
4573
|
+
Number.isFinite(currentTime) && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4352
4574
|
"div",
|
|
4353
4575
|
{
|
|
4354
4576
|
className: "rui-tl-playhead",
|
|
@@ -4356,32 +4578,124 @@ function Timeline({
|
|
|
4356
4578
|
"aria-hidden": "true",
|
|
4357
4579
|
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-playhead-grip" })
|
|
4358
4580
|
}
|
|
4359
|
-
)
|
|
4360
|
-
] }) }),
|
|
4361
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "rui-tl-zoom", children: [
|
|
4362
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4363
|
-
"button",
|
|
4364
|
-
{
|
|
4365
|
-
type: "button",
|
|
4366
|
-
className: "rui-tl-zoombtn",
|
|
4367
|
-
"aria-label": "Zoom out",
|
|
4368
|
-
onClick: () => setZoom(pps / 1.35),
|
|
4369
|
-
disabled: pps <= TL_MIN_PPS + 1e-6,
|
|
4370
|
-
children: "\u2212"
|
|
4371
|
-
}
|
|
4372
4581
|
),
|
|
4373
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4374
|
-
|
|
4375
|
-
{
|
|
4376
|
-
type: "button",
|
|
4377
|
-
className: "rui-tl-zoombtn",
|
|
4378
|
-
"aria-label": "Zoom in",
|
|
4379
|
-
onClick: () => setZoom(pps * 1.35),
|
|
4380
|
-
disabled: pps >= TL_MAX_PPS - 1e-6,
|
|
4381
|
-
children: "+"
|
|
4382
|
-
}
|
|
4383
|
-
)
|
|
4384
|
-
] })
|
|
4582
|
+
drag?.annotation && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "rui-tl-annot", style: { left: TL_HEAD_W + (drag.annotAt || 0) * pps }, children: drag.annotation })
|
|
4583
|
+
] }) })
|
|
4385
4584
|
] });
|
|
4386
4585
|
}
|
|
4586
|
+
function Clip({
|
|
4587
|
+
l,
|
|
4588
|
+
track,
|
|
4589
|
+
pps,
|
|
4590
|
+
selected,
|
|
4591
|
+
drag,
|
|
4592
|
+
onSelect,
|
|
4593
|
+
beginGesture,
|
|
4594
|
+
onTrim,
|
|
4595
|
+
onMoveClip,
|
|
4596
|
+
snapTimes
|
|
4597
|
+
}) {
|
|
4598
|
+
const { clip, x, w, known, t0, i } = l;
|
|
4599
|
+
const live = drag?.clipId === clip.id ? drag : null;
|
|
4600
|
+
const width = live?.width ?? w;
|
|
4601
|
+
const left = live?.left ?? x;
|
|
4602
|
+
const tileW = Math.round((LANE_H - CLIP_INSET * 2) * (16 / 9));
|
|
4603
|
+
const startTrim = (e, edge) => {
|
|
4604
|
+
if (!onTrim || !known) return;
|
|
4605
|
+
beginGesture(e, {
|
|
4606
|
+
kind: "trim",
|
|
4607
|
+
snapTimes,
|
|
4608
|
+
preview: (t) => {
|
|
4609
|
+
const dur = edge === "end" ? clamp(t - t0, TL_MIN_CLIP_S, clip.duration) : clamp(t0 + clip.duration - t, TL_MIN_CLIP_S, clip.duration);
|
|
4610
|
+
const nextW = dur * pps;
|
|
4611
|
+
const nextLeft = edge === "end" ? x : x + (w - nextW);
|
|
4612
|
+
return {
|
|
4613
|
+
clipId: clip.id,
|
|
4614
|
+
width: nextW,
|
|
4615
|
+
left: nextLeft,
|
|
4616
|
+
annotation: `${exactLabel(dur)} \xB7 ${edge === "end" ? "out" : "in"}`,
|
|
4617
|
+
annotAt: (nextLeft + nextW) / pps
|
|
4618
|
+
};
|
|
4619
|
+
},
|
|
4620
|
+
commit: (t) => {
|
|
4621
|
+
const dur = edge === "end" ? clamp(t - t0, TL_MIN_CLIP_S, clip.duration) : clamp(t0 + clip.duration - t, TL_MIN_CLIP_S, clip.duration);
|
|
4622
|
+
if (Math.abs(dur - clip.duration) > 1e-3) onTrim(clip, edge, dur, track);
|
|
4623
|
+
}
|
|
4624
|
+
});
|
|
4625
|
+
};
|
|
4626
|
+
const startMove = (e) => {
|
|
4627
|
+
if (!onMoveClip) {
|
|
4628
|
+
onSelect();
|
|
4629
|
+
return;
|
|
4630
|
+
}
|
|
4631
|
+
const half = (known ? clip.duration : 0) / 2;
|
|
4632
|
+
beginGesture(e, {
|
|
4633
|
+
kind: "move",
|
|
4634
|
+
snapTimes,
|
|
4635
|
+
preview: (t) => {
|
|
4636
|
+
const at = Math.max(0, t - half);
|
|
4637
|
+
return { clipId: clip.id, left: at * pps, annotation: exactLabel(at), annotAt: at };
|
|
4638
|
+
},
|
|
4639
|
+
commit: (t) => {
|
|
4640
|
+
const at = Math.max(0, t - half);
|
|
4641
|
+
if (track.sequential) {
|
|
4642
|
+
let idx = 0;
|
|
4643
|
+
for (const other of track.laid) {
|
|
4644
|
+
if (other.clip.id === clip.id) continue;
|
|
4645
|
+
if (at + half > other.t0 + other.w / pps / 2) idx += 1;
|
|
4646
|
+
}
|
|
4647
|
+
if (idx !== i) onMoveClip(clip, idx, track);
|
|
4648
|
+
} else if (Math.abs(at - t0) > 1e-3) {
|
|
4649
|
+
onMoveClip(clip, at, track);
|
|
4650
|
+
}
|
|
4651
|
+
},
|
|
4652
|
+
click: onSelect
|
|
4653
|
+
});
|
|
4654
|
+
};
|
|
4655
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4656
|
+
"article",
|
|
4657
|
+
{
|
|
4658
|
+
className: "rui-tl-clip" + (clip.state ? ` is-${clip.state}` : "") + (known ? "" : " is-unmeasured") + (selected ? " is-selected" : "") + (live ? " is-live" : ""),
|
|
4659
|
+
style: { left, width, ...clip.accent ? { "--rui-tl-accent": clip.accent } : null },
|
|
4660
|
+
title: clip.title || clip.label,
|
|
4661
|
+
tabIndex: 0,
|
|
4662
|
+
onPointerDown: startMove,
|
|
4663
|
+
onKeyDown: (e) => {
|
|
4664
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4665
|
+
e.preventDefault();
|
|
4666
|
+
onSelect();
|
|
4667
|
+
}
|
|
4668
|
+
},
|
|
4669
|
+
children: [
|
|
4670
|
+
clip.poster ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-strip", style: {
|
|
4671
|
+
backgroundImage: `url("${String(clip.poster).replace(/"/g, '\\"')}")`,
|
|
4672
|
+
backgroundSize: `${tileW}px 100%`
|
|
4673
|
+
} }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-blank", "aria-hidden": "true", children: clip.glyph }),
|
|
4674
|
+
clip.badge && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-badge", children: clip.badge }),
|
|
4675
|
+
known && width > 46 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-dur", children: durationLabel(clip.duration) }),
|
|
4676
|
+
clip.label && width > 104 && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "rui-tl-name", children: clip.label }),
|
|
4677
|
+
onTrim && known && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
4678
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4679
|
+
"span",
|
|
4680
|
+
{
|
|
4681
|
+
className: "rui-tl-trim l",
|
|
4682
|
+
onPointerDown: (e) => startTrim(e, "start"),
|
|
4683
|
+
role: "separator",
|
|
4684
|
+
"aria-label": `Trim the start of ${clip.label || "this clip"}`
|
|
4685
|
+
}
|
|
4686
|
+
),
|
|
4687
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4688
|
+
"span",
|
|
4689
|
+
{
|
|
4690
|
+
className: "rui-tl-trim r",
|
|
4691
|
+
onPointerDown: (e) => startTrim(e, "end"),
|
|
4692
|
+
role: "separator",
|
|
4693
|
+
"aria-label": `Trim the end of ${clip.label || "this clip"}`
|
|
4694
|
+
}
|
|
4695
|
+
)
|
|
4696
|
+
] })
|
|
4697
|
+
]
|
|
4698
|
+
}
|
|
4699
|
+
);
|
|
4700
|
+
}
|
|
4387
4701
|
//# sourceMappingURL=index.cjs.map
|