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.js CHANGED
@@ -3875,14 +3875,18 @@ function packLayout(layout2, cols = 12) {
3875
3875
 
3876
3876
  // src/timeline/Timeline.jsx
3877
3877
  import { useCallback as useCallback9, useEffect as useEffect16, useLayoutEffect as useLayoutEffect2, useMemo as useMemo4, useRef as useRef12, useState as useState15 } from "react";
3878
- import { jsx as jsx25, jsxs as jsxs22 } from "react/jsx-runtime";
3878
+ import { Fragment as Fragment9, jsx as jsx25, jsxs as jsxs22 } from "react/jsx-runtime";
3879
3879
  var TL_MIN_PPS = 4;
3880
- var TL_MAX_PPS = 240;
3880
+ var TL_MAX_PPS = 400;
3881
3881
  var TL_DEFAULT_PPS = 26;
3882
- var TL_HEAD_W = 76;
3882
+ var TL_HEAD_W = 84;
3883
+ var TL_SNAP_PX = 6;
3884
+ var TL_MIN_CLIP_S = 0.1;
3885
+ var CLICK_SLOP = 3;
3886
+ var LANE_H = 56;
3887
+ var CLIP_INSET = 4;
3883
3888
  var UNKNOWN_W = 46;
3884
- var MIN_CLIP_W = 26;
3885
- var LANE_H = 48;
3889
+ var MIN_CLIP_W = 18;
3886
3890
  var clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
3887
3891
  var TICK_STEPS = [0.1, 0.2, 0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600];
3888
3892
  function majorTickStep(pps) {
@@ -3904,33 +3908,55 @@ function durationLabel(seconds) {
3904
3908
  const s = Math.round(seconds - m * 60);
3905
3909
  return `${m}:${String(s).padStart(2, "0")}`;
3906
3910
  }
3911
+ function exactLabel(seconds) {
3912
+ if (!Number.isFinite(seconds)) return "\u2014";
3913
+ const m = Math.floor(Math.max(0, seconds) / 60);
3914
+ const s = Math.max(0, seconds) - m * 60;
3915
+ return `${m}:${s < 10 ? "0" : ""}${s.toFixed(1)}`;
3916
+ }
3907
3917
  function layout(clips, pps, sequential) {
3908
3918
  let cursor = 0;
3909
- return clips.map((c) => {
3919
+ return clips.map((c, i) => {
3910
3920
  const known = Number.isFinite(c.duration);
3911
3921
  const w = known ? Math.max(MIN_CLIP_W, c.duration * pps) : UNKNOWN_W;
3912
- const x = sequential ? cursor * pps : (c.start || 0) * pps;
3922
+ const t0 = sequential ? cursor : c.start || 0;
3913
3923
  if (sequential) cursor += known ? c.duration : UNKNOWN_W / pps;
3914
- return { clip: c, x, w, known };
3924
+ return { clip: c, i, t0, x: t0 * pps, w, known };
3915
3925
  });
3916
3926
  }
3927
+ function snapTo(t, targets, tol) {
3928
+ let best = null;
3929
+ let bestD = tol;
3930
+ for (const s of targets) {
3931
+ const d = Math.abs(s - t);
3932
+ if (d <= bestD) {
3933
+ bestD = d;
3934
+ best = s;
3935
+ }
3936
+ }
3937
+ return best === null ? { value: t, guide: null } : { value: best, guide: best };
3938
+ }
3917
3939
  function Timeline({
3918
3940
  tracks = [],
3919
- /** Seconds. Drives the playhead; pass it from whatever is playing. */
3920
3941
  currentTime = 0,
3921
- /** Called with a time in seconds when the ruler or lane background is scrubbed. */
3922
3942
  onSeek,
3923
3943
  onSelectClip,
3924
3944
  selectedClipId = null,
3925
- /** Rendered at the right of each clip on hover — e.g. remove, reorder. (clip, index) => node */
3926
- clipActions,
3927
- /** Rendered after the last clip of a lane, e.g. an add button. (track) => node */
3945
+ /** (clip, edge:'start'|'end', newDurationSeconds, track). Fires once, on release. */
3946
+ onTrim,
3947
+ /** (clip, atSecondsFromClipStart, track). */
3948
+ onSplit,
3949
+ /** Sequential lane: (clip, toIndex, track). Placed lane: (clip, newStartSeconds, track). */
3950
+ onMoveClip,
3951
+ onDeleteClip,
3928
3952
  laneAppend,
3929
3953
  zoomStorageKey = null,
3954
+ snapStorageKey = null,
3930
3955
  emptyLabel = "Nothing here yet.",
3931
3956
  className = ""
3932
3957
  }) {
3933
3958
  const scroller = useRef12(null);
3959
+ const innerRef = useRef12(null);
3934
3960
  const [pps, setPps] = useState15(() => {
3935
3961
  if (zoomStorageKey && typeof window !== "undefined") {
3936
3962
  const n = parseFloat(window.localStorage.getItem(zoomStorageKey) || "");
@@ -3938,21 +3964,31 @@ function Timeline({
3938
3964
  }
3939
3965
  return TL_DEFAULT_PPS;
3940
3966
  });
3967
+ const [snapping, setSnapping] = useState15(() => snapStorageKey && typeof window !== "undefined" ? window.localStorage.getItem(snapStorageKey) !== "0" : true);
3968
+ const gesture = useRef12(null);
3969
+ const [drag, setDrag] = useState15(null);
3941
3970
  const anchor = useRef12(null);
3942
3971
  const rows = useMemo4(
3943
- () => tracks.map((t) => ({ ...t, laid: layout(t.clips || [], pps, t.sequential !== false) })),
3972
+ () => tracks.map((t) => ({
3973
+ ...t,
3974
+ sequential: t.sequential !== false,
3975
+ laid: layout(t.clips || [], pps, t.sequential !== false)
3976
+ })),
3944
3977
  [tracks, pps]
3945
3978
  );
3946
3979
  const contentSeconds = useMemo4(() => {
3947
3980
  let end = 0;
3948
- for (const t of rows) {
3949
- for (const { clip, x, w } of t.laid) {
3950
- void clip;
3951
- end = Math.max(end, (x + w) / pps);
3952
- }
3953
- }
3981
+ for (const t of rows) for (const l of t.laid) end = Math.max(end, l.t0 + l.w / pps);
3954
3982
  return end;
3955
3983
  }, [rows, pps]);
3984
+ const snapTimes = useMemo4(() => {
3985
+ const out = [0, currentTime];
3986
+ for (const t of rows) for (const l of t.laid) {
3987
+ out.push(l.t0);
3988
+ out.push(l.t0 + l.w / pps);
3989
+ }
3990
+ return out;
3991
+ }, [rows, pps, currentTime]);
3956
3992
  const setZoom = useCallback9((next, clientX) => {
3957
3993
  const v = clamp(next, TL_MIN_PPS, TL_MAX_PPS);
3958
3994
  const el = scroller.current;
@@ -3969,6 +4005,32 @@ function Timeline({
3969
4005
  }
3970
4006
  }
3971
4007
  }, [pps, zoomStorageKey]);
4008
+ const fitPps = useCallback9((seconds) => {
4009
+ const el = scroller.current;
4010
+ if (!el || !(seconds > 0)) return null;
4011
+ const room = el.clientWidth - TL_HEAD_W - 56;
4012
+ return room > 0 ? clamp(room / seconds, TL_MIN_PPS, TL_MAX_PPS) : null;
4013
+ }, []);
4014
+ const fit = useCallback9(() => {
4015
+ const v = fitPps(contentSeconds);
4016
+ if (v !== null) {
4017
+ setPps(v);
4018
+ if (scroller.current) scroller.current.scrollLeft = 0;
4019
+ }
4020
+ }, [fitPps, contentSeconds]);
4021
+ const fitted = useRef12(false);
4022
+ useLayoutEffect2(() => {
4023
+ if (fitted.current || !(contentSeconds > 0)) return;
4024
+ if (zoomStorageKey && typeof window !== "undefined" && window.localStorage.getItem(zoomStorageKey)) {
4025
+ fitted.current = true;
4026
+ return;
4027
+ }
4028
+ const v = fitPps(contentSeconds);
4029
+ if (v !== null) {
4030
+ fitted.current = true;
4031
+ setPps(v);
4032
+ }
4033
+ }, [contentSeconds, fitPps, zoomStorageKey]);
3972
4034
  useLayoutEffect2(() => {
3973
4035
  const a = anchor.current;
3974
4036
  if (!a || !scroller.current) return;
@@ -3987,40 +4049,201 @@ function Timeline({
3987
4049
  return () => el.removeEventListener("wheel", onWheel);
3988
4050
  }, [pps, setZoom]);
3989
4051
  const timeAt = useCallback9((clientX) => {
3990
- const el = scroller.current;
4052
+ const el = innerRef.current;
3991
4053
  if (!el) return 0;
3992
- const rect = el.getBoundingClientRect();
3993
- return Math.max(0, (el.scrollLeft + (clientX - rect.left) - TL_HEAD_W) / pps);
4054
+ return Math.max(0, (clientX - el.getBoundingClientRect().left - TL_HEAD_W) / pps);
3994
4055
  }, [pps]);
3995
- const onScrub = useCallback9((e) => {
3996
- if (!onSeek) return;
3997
- e.currentTarget.setPointerCapture?.(e.pointerId);
3998
- onSeek(timeAt(e.clientX));
3999
- const move = (ev) => onSeek(timeAt(ev.clientX));
4056
+ const beginGesture = useCallback9((e, spec) => {
4057
+ e.preventDefault();
4058
+ e.stopPropagation();
4059
+ gesture.current = { ...spec, startX: e.clientX, active: false, value: null };
4060
+ const move = (ev) => {
4061
+ const cur = gesture.current;
4062
+ if (!cur) return;
4063
+ if (!cur.active && Math.abs(ev.clientX - cur.startX) < CLICK_SLOP) return;
4064
+ cur.active = true;
4065
+ let t = timeAt(ev.clientX);
4066
+ let guide = null;
4067
+ if (snapping && !ev.altKey && cur.kind !== "scrub") {
4068
+ const r = snapTo(t, cur.snapTimes || snapTimes, TL_SNAP_PX / pps);
4069
+ t = r.value;
4070
+ guide = r.guide;
4071
+ }
4072
+ cur.value = t;
4073
+ if (cur.kind === "scrub") onSeek?.(t);
4074
+ else setDrag(cur.preview ? { ...cur.preview(t), guide } : { guide });
4075
+ };
4000
4076
  const up = () => {
4001
4077
  window.removeEventListener("pointermove", move);
4002
4078
  window.removeEventListener("pointerup", up);
4079
+ document.body.classList.remove("rui-tl-gesturing");
4080
+ const cur = gesture.current;
4081
+ gesture.current = null;
4082
+ setDrag(null);
4083
+ if (cur?.active && cur.value !== null) cur.commit?.(cur.value);
4084
+ else cur?.click?.();
4003
4085
  };
4086
+ document.body.classList.add("rui-tl-gesturing");
4004
4087
  window.addEventListener("pointermove", move);
4005
4088
  window.addEventListener("pointerup", up);
4006
- }, [onSeek, timeAt]);
4089
+ }, [timeAt, snapping, snapTimes, pps, onSeek]);
4090
+ const onScrub = useCallback9((e) => {
4091
+ if (!onSeek) return;
4092
+ onSeek(timeAt(e.clientX));
4093
+ beginGesture(e, { kind: "scrub" });
4094
+ }, [onSeek, timeAt, beginGesture]);
4095
+ const splitTarget = useMemo4(() => {
4096
+ if (!onSplit) return null;
4097
+ for (const track of rows) {
4098
+ for (const l of track.laid) {
4099
+ if (!l.known) continue;
4100
+ if (currentTime > l.t0 + TL_MIN_CLIP_S && currentTime < l.t0 + l.clip.duration - TL_MIN_CLIP_S) {
4101
+ return { track, l };
4102
+ }
4103
+ }
4104
+ }
4105
+ return null;
4106
+ }, [rows, currentTime, onSplit]);
4107
+ const doSplit = useCallback9(() => {
4108
+ if (!splitTarget) return;
4109
+ onSplit(splitTarget.l.clip, currentTime - splitTarget.l.t0, splitTarget.track);
4110
+ }, [splitTarget, currentTime, onSplit]);
4111
+ const selected = useMemo4(() => {
4112
+ for (const track of rows) for (const l of track.laid) {
4113
+ if (l.clip.id === selectedClipId) return { track, l };
4114
+ }
4115
+ return null;
4116
+ }, [rows, selectedClipId]);
4007
4117
  const onKeyDown = useCallback9((e) => {
4118
+ const tag = e.target?.tagName;
4119
+ if (tag === "INPUT" || tag === "TEXTAREA" || e.target?.isContentEditable) return;
4008
4120
  if (e.key === "+" || e.key === "=") {
4009
4121
  e.preventDefault();
4010
4122
  setZoom(pps * 1.35);
4011
- }
4012
- if (e.key === "-" || e.key === "_") {
4123
+ } else if (e.key === "-" || e.key === "_") {
4013
4124
  e.preventDefault();
4014
4125
  setZoom(pps / 1.35);
4126
+ } else if (e.key === "b" || e.key === "B") {
4127
+ e.preventDefault();
4128
+ doSplit();
4129
+ } else if ((e.key === "Delete" || e.key === "Backspace") && selected && onDeleteClip) {
4130
+ e.preventDefault();
4131
+ onDeleteClip(selected.l.clip, selected.track);
4015
4132
  }
4016
- }, [pps, setZoom]);
4133
+ }, [pps, setZoom, doSplit, selected, onDeleteClip]);
4134
+ const toggleSnap = useCallback9(() => {
4135
+ setSnapping((v) => {
4136
+ const next = !v;
4137
+ if (snapStorageKey && typeof window !== "undefined") {
4138
+ try {
4139
+ window.localStorage.setItem(snapStorageKey, next ? "1" : "0");
4140
+ } catch {
4141
+ }
4142
+ }
4143
+ return next;
4144
+ });
4145
+ }, [snapStorageKey]);
4017
4146
  const major = majorTickStep(pps);
4018
4147
  const minor = major / 5;
4019
- const laneW = Math.max(contentSeconds * pps + 120, 240);
4148
+ const laneW = Math.max(contentSeconds * pps + 140, 320);
4020
4149
  const ticks = [];
4021
4150
  for (let t = 0; t <= contentSeconds + major; t += major) ticks.push(t);
4022
- return /* @__PURE__ */ jsxs22("div", { className: `rui-tl ${className}`, onKeyDown, tabIndex: -1, children: [
4023
- /* @__PURE__ */ jsx25("div", { className: "rui-tl-scroll", ref: scroller, children: /* @__PURE__ */ jsxs22("div", { className: "rui-tl-inner", style: { width: TL_HEAD_W + laneW }, children: [
4151
+ return /* @__PURE__ */ jsxs22("div", { className: `rui-tl ${className}`, onKeyDown, tabIndex: 0, children: [
4152
+ /* @__PURE__ */ jsxs22("div", { className: "rui-tl-bar", children: [
4153
+ onSplit && /* @__PURE__ */ jsxs22(
4154
+ "button",
4155
+ {
4156
+ type: "button",
4157
+ className: "rui-tl-btn",
4158
+ onClick: doSplit,
4159
+ disabled: !splitTarget,
4160
+ title: splitTarget ? "Split at the playhead (B)" : "Move the playhead inside a clip to split it",
4161
+ children: [
4162
+ /* @__PURE__ */ jsxs22(
4163
+ "svg",
4164
+ {
4165
+ width: "13",
4166
+ height: "13",
4167
+ viewBox: "0 0 24 24",
4168
+ fill: "none",
4169
+ stroke: "currentColor",
4170
+ strokeWidth: "2",
4171
+ strokeLinecap: "round",
4172
+ "aria-hidden": "true",
4173
+ children: [
4174
+ /* @__PURE__ */ jsx25("circle", { cx: "6", cy: "6", r: "3" }),
4175
+ /* @__PURE__ */ jsx25("circle", { cx: "6", cy: "18", r: "3" }),
4176
+ /* @__PURE__ */ jsx25("line", { x1: "20", y1: "4", x2: "8.12", y2: "15.88" }),
4177
+ /* @__PURE__ */ jsx25("line", { x1: "14.47", y1: "14.48", x2: "20", y2: "20" }),
4178
+ /* @__PURE__ */ jsx25("line", { x1: "8.12", y1: "8.12", x2: "12", y2: "12" })
4179
+ ]
4180
+ }
4181
+ ),
4182
+ /* @__PURE__ */ jsx25("span", { children: "Split" })
4183
+ ]
4184
+ }
4185
+ ),
4186
+ onDeleteClip && /* @__PURE__ */ jsx25(
4187
+ "button",
4188
+ {
4189
+ type: "button",
4190
+ className: "rui-tl-btn",
4191
+ disabled: !selected,
4192
+ onClick: () => selected && onDeleteClip(selected.l.clip, selected.track),
4193
+ title: selected ? "Remove the selected clip" : "Select a clip to remove it",
4194
+ children: "Remove"
4195
+ }
4196
+ ),
4197
+ /* @__PURE__ */ jsx25(
4198
+ "button",
4199
+ {
4200
+ type: "button",
4201
+ className: `rui-tl-btn${snapping ? " is-on" : ""}`,
4202
+ onClick: toggleSnap,
4203
+ "aria-pressed": snapping,
4204
+ title: "Snap to clip edges and the playhead. Hold Alt while dragging to bypass.",
4205
+ children: "Snap"
4206
+ }
4207
+ ),
4208
+ /* @__PURE__ */ jsx25("span", { className: "rui-tl-time", "aria-label": "Playhead position", children: exactLabel(currentTime) }),
4209
+ /* @__PURE__ */ jsx25("span", { className: "rui-tl-spacer" }),
4210
+ /* @__PURE__ */ jsx25(
4211
+ "button",
4212
+ {
4213
+ type: "button",
4214
+ className: "rui-tl-btn rui-tl-icon",
4215
+ onClick: () => setZoom(pps / 1.35),
4216
+ disabled: pps <= TL_MIN_PPS + 1e-6,
4217
+ "aria-label": "Zoom out",
4218
+ title: "Zoom out (\u2212)",
4219
+ children: "\u2212"
4220
+ }
4221
+ ),
4222
+ /* @__PURE__ */ jsx25(
4223
+ "button",
4224
+ {
4225
+ type: "button",
4226
+ className: "rui-tl-btn rui-tl-icon",
4227
+ onClick: () => setZoom(pps * 1.35),
4228
+ disabled: pps >= TL_MAX_PPS - 1e-6,
4229
+ "aria-label": "Zoom in",
4230
+ title: "Zoom in (+)",
4231
+ children: "+"
4232
+ }
4233
+ ),
4234
+ /* @__PURE__ */ jsx25(
4235
+ "button",
4236
+ {
4237
+ type: "button",
4238
+ className: "rui-tl-btn",
4239
+ onClick: fit,
4240
+ disabled: !(contentSeconds > 0),
4241
+ title: "Fit the whole timeline in the panel",
4242
+ children: "Fit"
4243
+ }
4244
+ )
4245
+ ] }),
4246
+ /* @__PURE__ */ jsx25("div", { className: "rui-tl-scroll", ref: scroller, children: /* @__PURE__ */ jsxs22("div", { className: "rui-tl-inner", ref: innerRef, style: { width: TL_HEAD_W + laneW }, children: [
4024
4247
  /* @__PURE__ */ jsxs22("div", { className: "rui-tl-row rui-tl-rulerrow", children: [
4025
4248
  /* @__PURE__ */ jsx25("div", { className: "rui-tl-head rui-tl-rulerhead", "aria-hidden": "true" }),
4026
4249
  /* @__PURE__ */ jsx25(
@@ -4029,9 +4252,8 @@ function Timeline({
4029
4252
  className: "rui-tl-ruler",
4030
4253
  style: {
4031
4254
  width: laneW,
4032
- // Minor ticks are a repeating background rather than elements: at 600 s and a
4033
- // fine zoom that is thousands of nodes, and they carry no information a stripe
4034
- // does not.
4255
+ // Minor ticks are a repeating background, not elements: ten minutes at a fine zoom
4256
+ // is thousands of nodes carrying no information a stripe does not.
4035
4257
  backgroundImage: "linear-gradient(90deg, var(--uic-line, #DDDFE6) 0 1px, transparent 1px),linear-gradient(90deg, var(--uic-line-soft, #EFF1F4) 0 1px, transparent 1px)",
4036
4258
  backgroundSize: `${major * pps}px 9px, ${minor * pps}px 5px`
4037
4259
  },
@@ -4073,35 +4295,27 @@ function Timeline({
4073
4295
  },
4074
4296
  children: [
4075
4297
  track.laid.length === 0 && track.emptyLabel && /* @__PURE__ */ jsx25("p", { className: "rui-tl-laneempty", children: track.emptyLabel }),
4076
- track.laid.map(({ clip, x, w, known }, i) => /* @__PURE__ */ jsxs22(
4077
- "article",
4298
+ track.laid.map((l) => /* @__PURE__ */ jsx25(
4299
+ Clip,
4078
4300
  {
4079
- className: "rui-tl-clip" + (clip.state ? ` is-${clip.state}` : "") + (known ? "" : " is-unmeasured") + (selectedClipId === clip.id ? " is-selected" : ""),
4080
- style: { left: x, width: w, ...clip.accent ? { "--rui-tl-accent": clip.accent } : null },
4081
- title: clip.title || clip.label,
4082
- tabIndex: 0,
4083
- onClick: () => onSelectClip?.(clip, i),
4084
- onKeyDown: (e) => {
4085
- if (e.key === "Enter" || e.key === " ") {
4086
- e.preventDefault();
4087
- onSelectClip?.(clip, i);
4088
- }
4089
- },
4090
- children: [
4091
- clip.poster ? /* @__PURE__ */ jsx25("img", { className: "rui-tl-poster", src: clip.poster, alt: "", loading: "lazy" }) : /* @__PURE__ */ jsx25("span", { className: "rui-tl-blank", "aria-hidden": "true", children: clip.glyph }),
4092
- clip.badge && /* @__PURE__ */ jsx25("span", { className: "rui-tl-badge", children: clip.badge }),
4093
- known && w > 44 && /* @__PURE__ */ jsx25("span", { className: "rui-tl-dur", children: durationLabel(clip.duration) }),
4094
- clip.label && w > 96 && /* @__PURE__ */ jsx25("span", { className: "rui-tl-name", children: clip.label }),
4095
- clipActions && /* @__PURE__ */ jsx25("span", { className: "rui-tl-acts", children: clipActions(clip, i) })
4096
- ]
4301
+ l,
4302
+ track,
4303
+ pps,
4304
+ selected: selectedClipId === l.clip.id,
4305
+ drag,
4306
+ onSelect: () => onSelectClip?.(l.clip, l.i),
4307
+ beginGesture,
4308
+ onTrim,
4309
+ onMoveClip,
4310
+ snapTimes
4097
4311
  },
4098
- clip.id ?? i
4312
+ l.clip.id ?? l.i
4099
4313
  )),
4100
4314
  laneAppend && /* @__PURE__ */ jsx25(
4101
4315
  "span",
4102
4316
  {
4103
4317
  className: "rui-tl-append",
4104
- style: { left: track.laid.reduce((n, l) => Math.max(n, l.x + l.w), 0) + 4 },
4318
+ style: { left: track.laid.reduce((n, x) => Math.max(n, x.x + x.w), 0) + 6 },
4105
4319
  children: laneAppend(track)
4106
4320
  }
4107
4321
  )
@@ -4109,7 +4323,15 @@ function Timeline({
4109
4323
  }
4110
4324
  )
4111
4325
  ] }, track.id)),
4112
- Number.isFinite(currentTime) && contentSeconds > 0 && /* @__PURE__ */ jsx25(
4326
+ drag?.guide != null && /* @__PURE__ */ jsx25(
4327
+ "div",
4328
+ {
4329
+ className: "rui-tl-guide",
4330
+ style: { left: TL_HEAD_W + drag.guide * pps },
4331
+ "aria-hidden": "true"
4332
+ }
4333
+ ),
4334
+ Number.isFinite(currentTime) && /* @__PURE__ */ jsx25(
4113
4335
  "div",
4114
4336
  {
4115
4337
  className: "rui-tl-playhead",
@@ -4117,34 +4339,126 @@ function Timeline({
4117
4339
  "aria-hidden": "true",
4118
4340
  children: /* @__PURE__ */ jsx25("span", { className: "rui-tl-playhead-grip" })
4119
4341
  }
4120
- )
4121
- ] }) }),
4122
- /* @__PURE__ */ jsxs22("div", { className: "rui-tl-zoom", children: [
4123
- /* @__PURE__ */ jsx25(
4124
- "button",
4125
- {
4126
- type: "button",
4127
- className: "rui-tl-zoombtn",
4128
- "aria-label": "Zoom out",
4129
- onClick: () => setZoom(pps / 1.35),
4130
- disabled: pps <= TL_MIN_PPS + 1e-6,
4131
- children: "\u2212"
4132
- }
4133
4342
  ),
4134
- /* @__PURE__ */ jsx25(
4135
- "button",
4136
- {
4137
- type: "button",
4138
- className: "rui-tl-zoombtn",
4139
- "aria-label": "Zoom in",
4140
- onClick: () => setZoom(pps * 1.35),
4141
- disabled: pps >= TL_MAX_PPS - 1e-6,
4142
- children: "+"
4143
- }
4144
- )
4145
- ] })
4343
+ drag?.annotation && /* @__PURE__ */ jsx25("div", { className: "rui-tl-annot", style: { left: TL_HEAD_W + (drag.annotAt || 0) * pps }, children: drag.annotation })
4344
+ ] }) })
4146
4345
  ] });
4147
4346
  }
4347
+ function Clip({
4348
+ l,
4349
+ track,
4350
+ pps,
4351
+ selected,
4352
+ drag,
4353
+ onSelect,
4354
+ beginGesture,
4355
+ onTrim,
4356
+ onMoveClip,
4357
+ snapTimes
4358
+ }) {
4359
+ const { clip, x, w, known, t0, i } = l;
4360
+ const live = drag?.clipId === clip.id ? drag : null;
4361
+ const width = live?.width ?? w;
4362
+ const left = live?.left ?? x;
4363
+ const tileW = Math.round((LANE_H - CLIP_INSET * 2) * (16 / 9));
4364
+ const startTrim = (e, edge) => {
4365
+ if (!onTrim || !known) return;
4366
+ beginGesture(e, {
4367
+ kind: "trim",
4368
+ snapTimes,
4369
+ preview: (t) => {
4370
+ const dur = edge === "end" ? clamp(t - t0, TL_MIN_CLIP_S, clip.duration) : clamp(t0 + clip.duration - t, TL_MIN_CLIP_S, clip.duration);
4371
+ const nextW = dur * pps;
4372
+ const nextLeft = edge === "end" ? x : x + (w - nextW);
4373
+ return {
4374
+ clipId: clip.id,
4375
+ width: nextW,
4376
+ left: nextLeft,
4377
+ annotation: `${exactLabel(dur)} \xB7 ${edge === "end" ? "out" : "in"}`,
4378
+ annotAt: (nextLeft + nextW) / pps
4379
+ };
4380
+ },
4381
+ commit: (t) => {
4382
+ const dur = edge === "end" ? clamp(t - t0, TL_MIN_CLIP_S, clip.duration) : clamp(t0 + clip.duration - t, TL_MIN_CLIP_S, clip.duration);
4383
+ if (Math.abs(dur - clip.duration) > 1e-3) onTrim(clip, edge, dur, track);
4384
+ }
4385
+ });
4386
+ };
4387
+ const startMove = (e) => {
4388
+ if (!onMoveClip) {
4389
+ onSelect();
4390
+ return;
4391
+ }
4392
+ const half = (known ? clip.duration : 0) / 2;
4393
+ beginGesture(e, {
4394
+ kind: "move",
4395
+ snapTimes,
4396
+ preview: (t) => {
4397
+ const at = Math.max(0, t - half);
4398
+ return { clipId: clip.id, left: at * pps, annotation: exactLabel(at), annotAt: at };
4399
+ },
4400
+ commit: (t) => {
4401
+ const at = Math.max(0, t - half);
4402
+ if (track.sequential) {
4403
+ let idx = 0;
4404
+ for (const other of track.laid) {
4405
+ if (other.clip.id === clip.id) continue;
4406
+ if (at + half > other.t0 + other.w / pps / 2) idx += 1;
4407
+ }
4408
+ if (idx !== i) onMoveClip(clip, idx, track);
4409
+ } else if (Math.abs(at - t0) > 1e-3) {
4410
+ onMoveClip(clip, at, track);
4411
+ }
4412
+ },
4413
+ click: onSelect
4414
+ });
4415
+ };
4416
+ return /* @__PURE__ */ jsxs22(
4417
+ "article",
4418
+ {
4419
+ className: "rui-tl-clip" + (clip.state ? ` is-${clip.state}` : "") + (known ? "" : " is-unmeasured") + (selected ? " is-selected" : "") + (live ? " is-live" : ""),
4420
+ style: { left, width, ...clip.accent ? { "--rui-tl-accent": clip.accent } : null },
4421
+ title: clip.title || clip.label,
4422
+ tabIndex: 0,
4423
+ onPointerDown: startMove,
4424
+ onKeyDown: (e) => {
4425
+ if (e.key === "Enter" || e.key === " ") {
4426
+ e.preventDefault();
4427
+ onSelect();
4428
+ }
4429
+ },
4430
+ children: [
4431
+ clip.poster ? /* @__PURE__ */ jsx25("span", { className: "rui-tl-strip", style: {
4432
+ backgroundImage: `url("${String(clip.poster).replace(/"/g, '\\"')}")`,
4433
+ backgroundSize: `${tileW}px 100%`
4434
+ } }) : /* @__PURE__ */ jsx25("span", { className: "rui-tl-blank", "aria-hidden": "true", children: clip.glyph }),
4435
+ clip.badge && /* @__PURE__ */ jsx25("span", { className: "rui-tl-badge", children: clip.badge }),
4436
+ known && width > 46 && /* @__PURE__ */ jsx25("span", { className: "rui-tl-dur", children: durationLabel(clip.duration) }),
4437
+ clip.label && width > 104 && /* @__PURE__ */ jsx25("span", { className: "rui-tl-name", children: clip.label }),
4438
+ onTrim && known && /* @__PURE__ */ jsxs22(Fragment9, { children: [
4439
+ /* @__PURE__ */ jsx25(
4440
+ "span",
4441
+ {
4442
+ className: "rui-tl-trim l",
4443
+ onPointerDown: (e) => startTrim(e, "start"),
4444
+ role: "separator",
4445
+ "aria-label": `Trim the start of ${clip.label || "this clip"}`
4446
+ }
4447
+ ),
4448
+ /* @__PURE__ */ jsx25(
4449
+ "span",
4450
+ {
4451
+ className: "rui-tl-trim r",
4452
+ onPointerDown: (e) => startTrim(e, "end"),
4453
+ role: "separator",
4454
+ "aria-label": `Trim the end of ${clip.label || "this clip"}`
4455
+ }
4456
+ )
4457
+ ] })
4458
+ ]
4459
+ }
4460
+ );
4461
+ }
4148
4462
  export {
4149
4463
  AssistantTurn,
4150
4464
  AuthForm,