reifyui 0.8.1 → 0.9.1
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 +356 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +74 -0
- package/dist/index.js +356 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +74 -0
- package/src/index.js +8 -0
- package/src/timeline/Timeline.jsx +330 -0
- package/styles/timeline.css +137 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reifyui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI \u2014 model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
package/src/index.d.ts
CHANGED
|
@@ -664,3 +664,77 @@ export const PanelGrid: ComponentType<PanelGridProps>;
|
|
|
664
664
|
/** Gravity applied to a layout you built yourself. Add a panel with `y: Infinity` to put it at
|
|
665
665
|
* the bottom, then pass the array through this to turn that into a real row. */
|
|
666
666
|
export function packLayout(layout: PanelLayoutItem[], cols?: number): PanelLayoutItem[];
|
|
667
|
+
|
|
668
|
+
/* ── Timeline ─────────────────────────────────────────────────────────────── */
|
|
669
|
+
|
|
670
|
+
export interface TimelineClip {
|
|
671
|
+
id?: string;
|
|
672
|
+
/** Seconds from the start of the lane. Ignored when the track is sequential (the default),
|
|
673
|
+
* where each clip begins where the previous one ended. */
|
|
674
|
+
start?: number;
|
|
675
|
+
/** Seconds. Omit or pass null when it has not been MEASURED yet: the clip is then drawn at a
|
|
676
|
+
* fixed placeholder width with a hatched fill, and carries no duration label. Never pass a
|
|
677
|
+
* guess — a width is a measurement here, and one invented width makes the ruler unreadable. */
|
|
678
|
+
duration?: number | null;
|
|
679
|
+
label?: string;
|
|
680
|
+
/** Tooltip. Falls back to `label`. */
|
|
681
|
+
title?: string;
|
|
682
|
+
/** Artwork filling the block — a poster frame, a waveform. */
|
|
683
|
+
poster?: string;
|
|
684
|
+
/** Shown centred when there is no poster. */
|
|
685
|
+
glyph?: ReactNode;
|
|
686
|
+
/** Small pill at the top left, e.g. an index. */
|
|
687
|
+
badge?: ReactNode;
|
|
688
|
+
/** 'failed' tints the block; any other value is yours to style as `.rui-tl-clip.is-<state>`. */
|
|
689
|
+
state?: string;
|
|
690
|
+
/** Border colour for this clip, as a CSS colour. */
|
|
691
|
+
accent?: string;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export interface TimelineTrack {
|
|
695
|
+
id: string;
|
|
696
|
+
label: string;
|
|
697
|
+
icon?: ReactNode;
|
|
698
|
+
clips?: TimelineClip[];
|
|
699
|
+
/** Default true: clips run back to back and `start` is ignored. False places each clip at its
|
|
700
|
+
* own `start`, for a lane that is a set of placed items rather than a sequence. */
|
|
701
|
+
sequential?: boolean;
|
|
702
|
+
/** Shown in the lane when it has no clips. Omit to leave the lane blank. */
|
|
703
|
+
emptyLabel?: string;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
export interface TimelineProps {
|
|
707
|
+
tracks?: TimelineTrack[];
|
|
708
|
+
/** Seconds. Draws the playhead. */
|
|
709
|
+
currentTime?: number;
|
|
710
|
+
/** Scrubbing the ruler or a lane's background calls this with a time in seconds. Omit and the
|
|
711
|
+
* timeline is read-only: no scrub target, no slider role. */
|
|
712
|
+
onSeek?: (seconds: number) => void;
|
|
713
|
+
onSelectClip?: (clip: TimelineClip, index: number) => void;
|
|
714
|
+
selectedClipId?: string | null;
|
|
715
|
+
/** Controls revealed on a clip on hover or focus. */
|
|
716
|
+
clipActions?: (clip: TimelineClip, index: number) => ReactNode;
|
|
717
|
+
/** Rendered just past the last clip of a lane — an add button, usually. */
|
|
718
|
+
laneAppend?: (track: TimelineTrack) => ReactNode;
|
|
719
|
+
/** localStorage key for the zoom level, so it survives a reload. */
|
|
720
|
+
zoomStorageKey?: string | null;
|
|
721
|
+
emptyLabel?: string;
|
|
722
|
+
className?: string;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/** Lanes of clips against a ruler, with a playhead and pointer-anchored zoom (Cmd/Ctrl+wheel,
|
|
726
|
+
* +/−, the buttons). One number — pixels per second — converts time to x for the ruler, the
|
|
727
|
+
* clips and the playhead alike, so they cannot disagree. Needs styles/timeline.css. */
|
|
728
|
+
export const Timeline: ComponentType<TimelineProps>;
|
|
729
|
+
|
|
730
|
+
/** The smallest tick step whose labels stay ~64px apart at this zoom. */
|
|
731
|
+
export function majorTickStep(pps: number): number;
|
|
732
|
+
/** A ruler label: m:ss, with tenths only when the step is sub-second. */
|
|
733
|
+
export function tickLabel(t: number, step?: number): string;
|
|
734
|
+
/** m:ss, and '' for anything unmeasured — never '0:00' for an unknown. */
|
|
735
|
+
export function timelineDurationLabel(seconds: number): string;
|
|
736
|
+
|
|
737
|
+
export const TL_MIN_PPS: number;
|
|
738
|
+
export const TL_MAX_PPS: number;
|
|
739
|
+
export const TL_DEFAULT_PPS: number;
|
|
740
|
+
export const TL_HEAD_W: number;
|
package/src/index.js
CHANGED
|
@@ -75,3 +75,11 @@ export { useTypewriter } from './hooks/useTypewriter.js';
|
|
|
75
75
|
// Needs styles/panels.css (+ form.css when a panel offers a retry).
|
|
76
76
|
export { Panel } from './components/Panel.jsx';
|
|
77
77
|
export { PanelGrid, packLayout } from './grid/PanelGrid.jsx';
|
|
78
|
+
|
|
79
|
+
// A timeline: lanes of clips against a ruler, with a playhead and pointer-anchored zoom. Product
|
|
80
|
+
// neutral — it takes {start, duration} and draws them, and never invents a width for a duration
|
|
81
|
+
// nobody measured. Needs styles/timeline.css.
|
|
82
|
+
export {
|
|
83
|
+
Timeline, majorTickStep, tickLabel, durationLabel as timelineDurationLabel,
|
|
84
|
+
TL_MIN_PPS, TL_MAX_PPS, TL_DEFAULT_PPS, TL_HEAD_W,
|
|
85
|
+
} from './timeline/Timeline.jsx';
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// A timeline: lanes of clips against a ruler, with a playhead.
|
|
2
|
+
//
|
|
3
|
+
// ONE NUMBER IS THE COORDINATE SYSTEM. `pps` — pixels per second — converts time to x everywhere:
|
|
4
|
+
// the ruler's ticks, a clip's width, the playhead's position, the scrub gesture's inverse. Two
|
|
5
|
+
// places computing the same conversion is how a ruler and the blocks under it come to disagree,
|
|
6
|
+
// which is the one thing a timeline cannot do and still be read.
|
|
7
|
+
//
|
|
8
|
+
// WHAT THIS COMPONENT KNOWS NOTHING ABOUT: video, audio, files, agents, or where a clip came
|
|
9
|
+
// from. It takes lanes of {start, duration} and draws them. Everything product-specific — what a
|
|
10
|
+
// clip means, what its artwork is, whether removing one is allowed — arrives as data or a
|
|
11
|
+
// callback. That is what lets the same component hold a film's cut, a job's phases, or a
|
|
12
|
+
// conversation's turns.
|
|
13
|
+
//
|
|
14
|
+
// TIME THAT IS NOT KNOWN IS NOT DRAWN AS TIME. A clip whose duration is null gets a fixed
|
|
15
|
+
// placeholder width and a hatched fill, never a guessed length: the whole value of drawing to
|
|
16
|
+
// scale is that the width is a measurement, and one invented width poisons every reading of the
|
|
17
|
+
// ruler above it.
|
|
18
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
19
|
+
|
|
20
|
+
export const TL_MIN_PPS = 4;
|
|
21
|
+
export const TL_MAX_PPS = 240;
|
|
22
|
+
export const TL_DEFAULT_PPS = 26;
|
|
23
|
+
/** The sticky lane-label gutter. Lanes start at this x. */
|
|
24
|
+
export const TL_HEAD_W = 76;
|
|
25
|
+
/** Width for a clip whose duration nobody has measured yet. */
|
|
26
|
+
const UNKNOWN_W = 46;
|
|
27
|
+
const MIN_CLIP_W = 26;
|
|
28
|
+
const LANE_H = 48;
|
|
29
|
+
|
|
30
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
31
|
+
|
|
32
|
+
/* ── ruler maths (pure) ─────────────────────────────────────────────────────────────────────── */
|
|
33
|
+
|
|
34
|
+
const TICK_STEPS = [0.1, 0.2, 0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600];
|
|
35
|
+
|
|
36
|
+
/** The smallest step whose labels stay ~64px apart at this zoom, so ticks thin out as you zoom
|
|
37
|
+
* out instead of collapsing into a grey bar. */
|
|
38
|
+
export function majorTickStep(pps) {
|
|
39
|
+
for (const s of TICK_STEPS) if (s * pps >= 64) return s;
|
|
40
|
+
return TICK_STEPS[TICK_STEPS.length - 1];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** m:ss, with tenths only when the step is sub-second — a label finer than the tick is noise. */
|
|
44
|
+
export function tickLabel(t, step = 1) {
|
|
45
|
+
const m = Math.floor(t / 60);
|
|
46
|
+
const s = t - m * 60;
|
|
47
|
+
const whole = Math.floor(s + 1e-6);
|
|
48
|
+
const base = `${m}:${String(whole).padStart(2, '0')}`;
|
|
49
|
+
if (step >= 1) return base;
|
|
50
|
+
const frac = Math.round((s - whole) * 10);
|
|
51
|
+
return frac > 0 ? `${base}.${frac}` : base;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** m:ss for a duration. Returns '' for anything unmeasured, never '0:00' — a zero that means
|
|
55
|
+
* "unknown" is the lie this component exists to avoid. */
|
|
56
|
+
export function durationLabel(seconds) {
|
|
57
|
+
if (!Number.isFinite(seconds) || seconds < 0) return '';
|
|
58
|
+
const m = Math.floor(seconds / 60);
|
|
59
|
+
const s = Math.round(seconds - m * 60);
|
|
60
|
+
return `${m}:${String(s).padStart(2, '0')}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Where each clip sits when a lane is a sequence rather than a set of placed items: each clip
|
|
64
|
+
* starts where the last one ended. Unmeasured clips advance by their drawn width so the lane
|
|
65
|
+
* stays honest about what follows them. */
|
|
66
|
+
function layout(clips, pps, sequential) {
|
|
67
|
+
let cursor = 0;
|
|
68
|
+
return clips.map((c) => {
|
|
69
|
+
const known = Number.isFinite(c.duration);
|
|
70
|
+
const w = known ? Math.max(MIN_CLIP_W, c.duration * pps) : UNKNOWN_W;
|
|
71
|
+
const x = sequential ? cursor * pps : (c.start || 0) * pps;
|
|
72
|
+
if (sequential) cursor += known ? c.duration : UNKNOWN_W / pps;
|
|
73
|
+
return { clip: c, x, w, known };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ── the component ──────────────────────────────────────────────────────────────────────────── */
|
|
78
|
+
|
|
79
|
+
export function Timeline({
|
|
80
|
+
tracks = [],
|
|
81
|
+
/** Seconds. Drives the playhead; pass it from whatever is playing. */
|
|
82
|
+
currentTime = 0,
|
|
83
|
+
/** Called with a time in seconds when the ruler or lane background is scrubbed. */
|
|
84
|
+
onSeek,
|
|
85
|
+
onSelectClip,
|
|
86
|
+
selectedClipId = null,
|
|
87
|
+
/** Rendered at the right of each clip on hover — e.g. remove, reorder. (clip, index) => node */
|
|
88
|
+
clipActions,
|
|
89
|
+
/** Rendered after the last clip of a lane, e.g. an add button. (track) => node */
|
|
90
|
+
laneAppend,
|
|
91
|
+
zoomStorageKey = null,
|
|
92
|
+
emptyLabel = 'Nothing here yet.',
|
|
93
|
+
className = '',
|
|
94
|
+
}) {
|
|
95
|
+
const scroller = useRef(null);
|
|
96
|
+
const [pps, setPps] = useState(() => {
|
|
97
|
+
if (zoomStorageKey && typeof window !== 'undefined') {
|
|
98
|
+
const n = parseFloat(window.localStorage.getItem(zoomStorageKey) || '');
|
|
99
|
+
if (Number.isFinite(n)) return clamp(n, TL_MIN_PPS, TL_MAX_PPS);
|
|
100
|
+
}
|
|
101
|
+
return TL_DEFAULT_PPS;
|
|
102
|
+
});
|
|
103
|
+
// Anchoring: keep the time under the pointer (or the viewport centre) still while zooming, so
|
|
104
|
+
// zoom feels like moving a lens rather than being teleported.
|
|
105
|
+
const anchor = useRef(null);
|
|
106
|
+
|
|
107
|
+
const rows = useMemo(
|
|
108
|
+
() => tracks.map((t) => ({ ...t, laid: layout(t.clips || [], pps, t.sequential !== false) })),
|
|
109
|
+
[tracks, pps]);
|
|
110
|
+
|
|
111
|
+
const contentSeconds = useMemo(() => {
|
|
112
|
+
let end = 0;
|
|
113
|
+
for (const t of rows) {
|
|
114
|
+
for (const { clip, x, w } of t.laid) {
|
|
115
|
+
void clip;
|
|
116
|
+
end = Math.max(end, (x + w) / pps);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return end;
|
|
120
|
+
}, [rows, pps]);
|
|
121
|
+
|
|
122
|
+
const setZoom = useCallback((next, clientX) => {
|
|
123
|
+
const v = clamp(next, TL_MIN_PPS, TL_MAX_PPS);
|
|
124
|
+
const el = scroller.current;
|
|
125
|
+
if (el) {
|
|
126
|
+
const rect = el.getBoundingClientRect();
|
|
127
|
+
const vx = clientX === undefined ? (rect.width + TL_HEAD_W) / 2 : clientX - rect.left;
|
|
128
|
+
anchor.current = { t: Math.max(0, (el.scrollLeft + vx - TL_HEAD_W) / pps), vx };
|
|
129
|
+
}
|
|
130
|
+
setPps(v);
|
|
131
|
+
if (zoomStorageKey && typeof window !== 'undefined') {
|
|
132
|
+
try { window.localStorage.setItem(zoomStorageKey, String(v)); } catch { /* private mode */ }
|
|
133
|
+
}
|
|
134
|
+
}, [pps, zoomStorageKey]);
|
|
135
|
+
|
|
136
|
+
/** The zoom at which the whole cut fills the lane, with a margin. */
|
|
137
|
+
const fitPps = useCallback((seconds) => {
|
|
138
|
+
const el = scroller.current;
|
|
139
|
+
if (!el || !(seconds > 0)) return null;
|
|
140
|
+
const room = el.clientWidth - TL_HEAD_W - 48;
|
|
141
|
+
if (room <= 0) return null;
|
|
142
|
+
return clamp(room / seconds, TL_MIN_PPS, TL_MAX_PPS);
|
|
143
|
+
}, []);
|
|
144
|
+
|
|
145
|
+
const fit = useCallback(() => {
|
|
146
|
+
const v = fitPps(contentSeconds);
|
|
147
|
+
if (v !== null) { setPps(v); if (scroller.current) scroller.current.scrollLeft = 0; }
|
|
148
|
+
}, [fitPps, contentSeconds]);
|
|
149
|
+
|
|
150
|
+
// FIT ONCE, when there is first something to fit. A 1 s clip at a fixed default is a 26 px
|
|
151
|
+
// sliver and reads as a broken control rather than a short shot; a 10 minute one runs off the
|
|
152
|
+
// panel. Fitting on the first content is the difference between a timeline that looks designed
|
|
153
|
+
// and one that looks unfinished — and it is done ONCE, not on every change, because re-fitting
|
|
154
|
+
// under someone who has just zoomed in is the control fighting them.
|
|
155
|
+
const fitted = useRef(false);
|
|
156
|
+
useLayoutEffect(() => {
|
|
157
|
+
if (fitted.current || !(contentSeconds > 0)) return;
|
|
158
|
+
if (zoomStorageKey && typeof window !== 'undefined'
|
|
159
|
+
&& window.localStorage.getItem(zoomStorageKey)) { fitted.current = true; return; }
|
|
160
|
+
const v = fitPps(contentSeconds);
|
|
161
|
+
if (v !== null) { fitted.current = true; setPps(v); }
|
|
162
|
+
}, [contentSeconds, fitPps, zoomStorageKey]);
|
|
163
|
+
|
|
164
|
+
useLayoutEffect(() => {
|
|
165
|
+
const a = anchor.current;
|
|
166
|
+
if (!a || !scroller.current) return;
|
|
167
|
+
anchor.current = null;
|
|
168
|
+
scroller.current.scrollLeft = Math.max(0, TL_HEAD_W + a.t * pps - a.vx);
|
|
169
|
+
}, [pps]);
|
|
170
|
+
|
|
171
|
+
// Cmd/Ctrl+wheel and trackpad pinch zoom around the pointer, the way every editor does.
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
const el = scroller.current;
|
|
174
|
+
if (!el) return undefined;
|
|
175
|
+
const onWheel = (e) => {
|
|
176
|
+
if (!(e.ctrlKey || e.metaKey)) return;
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
setZoom(pps * Math.exp(-e.deltaY * 0.0022), e.clientX);
|
|
179
|
+
};
|
|
180
|
+
el.addEventListener('wheel', onWheel, { passive: false });
|
|
181
|
+
return () => el.removeEventListener('wheel', onWheel);
|
|
182
|
+
}, [pps, setZoom]);
|
|
183
|
+
|
|
184
|
+
const timeAt = useCallback((clientX) => {
|
|
185
|
+
const el = scroller.current;
|
|
186
|
+
if (!el) return 0;
|
|
187
|
+
const rect = el.getBoundingClientRect();
|
|
188
|
+
return Math.max(0, (el.scrollLeft + (clientX - rect.left) - TL_HEAD_W) / pps);
|
|
189
|
+
}, [pps]);
|
|
190
|
+
|
|
191
|
+
// Scrubbing: press anywhere on the ruler and drag. Pointer capture means the gesture survives
|
|
192
|
+
// leaving the element, which is what makes a drag feel attached to the cursor.
|
|
193
|
+
const onScrub = useCallback((e) => {
|
|
194
|
+
if (!onSeek) return;
|
|
195
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
196
|
+
onSeek(timeAt(e.clientX));
|
|
197
|
+
const move = (ev) => onSeek(timeAt(ev.clientX));
|
|
198
|
+
const up = () => {
|
|
199
|
+
window.removeEventListener('pointermove', move);
|
|
200
|
+
window.removeEventListener('pointerup', up);
|
|
201
|
+
};
|
|
202
|
+
window.addEventListener('pointermove', move);
|
|
203
|
+
window.addEventListener('pointerup', up);
|
|
204
|
+
}, [onSeek, timeAt]);
|
|
205
|
+
|
|
206
|
+
const onKeyDown = useCallback((e) => {
|
|
207
|
+
if (e.key === '+' || e.key === '=') { e.preventDefault(); setZoom(pps * 1.35); }
|
|
208
|
+
if (e.key === '-' || e.key === '_') { e.preventDefault(); setZoom(pps / 1.35); }
|
|
209
|
+
}, [pps, setZoom]);
|
|
210
|
+
|
|
211
|
+
const major = majorTickStep(pps);
|
|
212
|
+
const minor = major / 5;
|
|
213
|
+
const laneW = Math.max(contentSeconds * pps + 120, 240);
|
|
214
|
+
const ticks = [];
|
|
215
|
+
for (let t = 0; t <= contentSeconds + major; t += major) ticks.push(t);
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<div className={`rui-tl ${className}`} onKeyDown={onKeyDown} tabIndex={-1}>
|
|
219
|
+
<div className="rui-tl-scroll" ref={scroller}>
|
|
220
|
+
<div className="rui-tl-inner" style={{ width: TL_HEAD_W + laneW }}>
|
|
221
|
+
|
|
222
|
+
{/* ── ruler ────────────────────────────────────────────────────────────────────── */}
|
|
223
|
+
<div className="rui-tl-row rui-tl-rulerrow">
|
|
224
|
+
<div className="rui-tl-head rui-tl-rulerhead" aria-hidden="true" />
|
|
225
|
+
<div
|
|
226
|
+
className="rui-tl-ruler"
|
|
227
|
+
style={{
|
|
228
|
+
width: laneW,
|
|
229
|
+
// Minor ticks are a repeating background rather than elements: at 600 s and a
|
|
230
|
+
// fine zoom that is thousands of nodes, and they carry no information a stripe
|
|
231
|
+
// does not.
|
|
232
|
+
backgroundImage:
|
|
233
|
+
'linear-gradient(90deg, var(--uic-line, #DDDFE6) 0 1px, transparent 1px),'
|
|
234
|
+
+ 'linear-gradient(90deg, var(--uic-line-soft, #EFF1F4) 0 1px, transparent 1px)',
|
|
235
|
+
backgroundSize: `${major * pps}px 9px, ${minor * pps}px 5px`,
|
|
236
|
+
}}
|
|
237
|
+
onPointerDown={onScrub}
|
|
238
|
+
role={onSeek ? 'slider' : undefined}
|
|
239
|
+
aria-label={onSeek ? 'Playhead' : undefined}
|
|
240
|
+
aria-valuemin={0}
|
|
241
|
+
aria-valuemax={Math.round(contentSeconds)}
|
|
242
|
+
aria-valuenow={Math.round(currentTime)}
|
|
243
|
+
tabIndex={onSeek ? 0 : undefined}
|
|
244
|
+
onKeyDown={onSeek ? (e) => {
|
|
245
|
+
const step = e.shiftKey ? 5 : 1;
|
|
246
|
+
if (e.key === 'ArrowLeft') { e.preventDefault(); onSeek(Math.max(0, currentTime - step)); }
|
|
247
|
+
if (e.key === 'ArrowRight') { e.preventDefault(); onSeek(currentTime + step); }
|
|
248
|
+
} : undefined}
|
|
249
|
+
>
|
|
250
|
+
{ticks.map((t) => (
|
|
251
|
+
<span key={t} className="rui-tl-ticklbl" style={{ left: t * pps }}>
|
|
252
|
+
{tickLabel(t, major)}
|
|
253
|
+
</span>
|
|
254
|
+
))}
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
{/* ── lanes ────────────────────────────────────────────────────────────────────── */}
|
|
259
|
+
{rows.length === 0 && <p className="rui-tl-empty">{emptyLabel}</p>}
|
|
260
|
+
|
|
261
|
+
{rows.map((track) => (
|
|
262
|
+
<div className="rui-tl-row" key={track.id}>
|
|
263
|
+
<div className="rui-tl-head" title={track.label}>
|
|
264
|
+
{track.icon}
|
|
265
|
+
<span className="rui-tl-headlbl">{track.label}</span>
|
|
266
|
+
</div>
|
|
267
|
+
<div className="rui-tl-lane" style={{ width: laneW, height: LANE_H }}
|
|
268
|
+
onPointerDown={(e) => { if (e.target === e.currentTarget) onScrub(e); }}>
|
|
269
|
+
{track.laid.length === 0 && track.emptyLabel && (
|
|
270
|
+
<p className="rui-tl-laneempty">{track.emptyLabel}</p>
|
|
271
|
+
)}
|
|
272
|
+
{track.laid.map(({ clip, x, w, known }, i) => (
|
|
273
|
+
<article
|
|
274
|
+
key={clip.id ?? i}
|
|
275
|
+
className={'rui-tl-clip'
|
|
276
|
+
+ (clip.state ? ` is-${clip.state}` : '')
|
|
277
|
+
+ (known ? '' : ' is-unmeasured')
|
|
278
|
+
+ (selectedClipId === clip.id ? ' is-selected' : '')}
|
|
279
|
+
style={{ left: x, width: w, ...(clip.accent ? { '--rui-tl-accent': clip.accent } : null) }}
|
|
280
|
+
title={clip.title || clip.label}
|
|
281
|
+
tabIndex={0}
|
|
282
|
+
onClick={() => onSelectClip?.(clip, i)}
|
|
283
|
+
onKeyDown={(e) => {
|
|
284
|
+
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onSelectClip?.(clip, i); }
|
|
285
|
+
}}
|
|
286
|
+
>
|
|
287
|
+
{clip.poster
|
|
288
|
+
? <img className="rui-tl-poster" src={clip.poster} alt="" loading="lazy" />
|
|
289
|
+
: <span className="rui-tl-blank" aria-hidden="true">{clip.glyph}</span>}
|
|
290
|
+
{clip.badge && <span className="rui-tl-badge">{clip.badge}</span>}
|
|
291
|
+
{/* A duration only when one was measured. See durationLabel. */}
|
|
292
|
+
{known && w > 44 && (
|
|
293
|
+
<span className="rui-tl-dur">{durationLabel(clip.duration)}</span>
|
|
294
|
+
)}
|
|
295
|
+
{clip.label && w > 96 && <span className="rui-tl-name">{clip.label}</span>}
|
|
296
|
+
{clipActions && <span className="rui-tl-acts">{clipActions(clip, i)}</span>}
|
|
297
|
+
</article>
|
|
298
|
+
))}
|
|
299
|
+
{laneAppend && (
|
|
300
|
+
<span className="rui-tl-append"
|
|
301
|
+
style={{ left: track.laid.reduce((n, l) => Math.max(n, l.x + l.w), 0) + 4 }}>
|
|
302
|
+
{laneAppend(track)}
|
|
303
|
+
</span>
|
|
304
|
+
)}
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
))}
|
|
308
|
+
|
|
309
|
+
{/* ── playhead ─────────────────────────────────────────────────────────────────────
|
|
310
|
+
Drawn last so it sits above the lanes, and only when there is a time to show. */}
|
|
311
|
+
{Number.isFinite(currentTime) && contentSeconds > 0 && (
|
|
312
|
+
<div className="rui-tl-playhead" style={{ left: TL_HEAD_W + currentTime * pps }}
|
|
313
|
+
aria-hidden="true">
|
|
314
|
+
<span className="rui-tl-playhead-grip" />
|
|
315
|
+
</div>
|
|
316
|
+
)}
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
<div className="rui-tl-zoom">
|
|
321
|
+
<button type="button" className="rui-tl-zoombtn" aria-label="Zoom out"
|
|
322
|
+
onClick={() => setZoom(pps / 1.35)} disabled={pps <= TL_MIN_PPS + 1e-6}>−</button>
|
|
323
|
+
<button type="button" className="rui-tl-zoombtn" aria-label="Zoom in"
|
|
324
|
+
onClick={() => setZoom(pps * 1.35)} disabled={pps >= TL_MAX_PPS - 1e-6}>+</button>
|
|
325
|
+
<button type="button" className="rui-tl-zoombtn rui-tl-fit" aria-label="Fit to width"
|
|
326
|
+
title="Fit to width" onClick={fit} disabled={!(contentSeconds > 0)}>⤢</button>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/* Timeline — lanes of clips against a ruler, with a playhead. Product-neutral: every colour is a
|
|
2
|
+
--uic-* token with a fallback that matches this library's own palette, so importing it without
|
|
3
|
+
a theme layer still looks like one design rather than several.
|
|
4
|
+
|
|
5
|
+
The layout rule that matters: the lane gutter is STICKY and the lanes scroll under it. A track
|
|
6
|
+
label that scrolls away takes the meaning of the row with it, and the first thing anyone does
|
|
7
|
+
with a timeline longer than the panel is scroll it. */
|
|
8
|
+
|
|
9
|
+
.rui-tl { position: relative; display: flex; flex-direction: column; min-height: 0; height: 100%; }
|
|
10
|
+
.rui-tl:focus { outline: none; }
|
|
11
|
+
|
|
12
|
+
.rui-tl-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior-x: contain; }
|
|
13
|
+
.rui-tl-inner { position: relative; min-width: 100%; padding-bottom: 6px; }
|
|
14
|
+
|
|
15
|
+
.rui-tl-row { display: flex; align-items: stretch; }
|
|
16
|
+
|
|
17
|
+
/* The gutter. Sticky, opaque, and above the lanes — a label showing through a clip is unreadable
|
|
18
|
+
exactly when the timeline is busiest. */
|
|
19
|
+
.rui-tl-head {
|
|
20
|
+
position: sticky; left: 0; z-index: 3; flex: 0 0 76px; width: 76px; box-sizing: border-box;
|
|
21
|
+
display: inline-flex; align-items: center; gap: 5px; padding: 0 8px;
|
|
22
|
+
background: var(--uic-surface, #FFFFFF);
|
|
23
|
+
border-right: 1px solid var(--uic-line, #DDDFE6);
|
|
24
|
+
font-size: 11px; letter-spacing: .03em; text-transform: uppercase;
|
|
25
|
+
color: var(--uic-mute, #6B7280);
|
|
26
|
+
}
|
|
27
|
+
.rui-tl-headlbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
28
|
+
|
|
29
|
+
/* ── ruler ─────────────────────────────────────────────────────────────────────────────────── */
|
|
30
|
+
.rui-tl-rulerrow { position: sticky; top: 0; z-index: 4; background: var(--uic-surface, #FFFFFF); }
|
|
31
|
+
.rui-tl-rulerhead { border-bottom: 1px solid var(--uic-line, #DDDFE6); }
|
|
32
|
+
.rui-tl-ruler {
|
|
33
|
+
position: relative; height: 22px; flex: 0 0 auto;
|
|
34
|
+
background-repeat: repeat-x, repeat-x;
|
|
35
|
+
background-position: left bottom, left bottom;
|
|
36
|
+
border-bottom: 1px solid var(--uic-line, #DDDFE6);
|
|
37
|
+
cursor: ew-resize; touch-action: none;
|
|
38
|
+
}
|
|
39
|
+
.rui-tl-ruler:focus-visible { outline: 2px solid var(--uic-brand, #6E55FF); outline-offset: -2px; }
|
|
40
|
+
.rui-tl-ticklbl {
|
|
41
|
+
position: absolute; top: 2px; padding-left: 4px; font-size: 10px; line-height: 1;
|
|
42
|
+
color: var(--uic-mute-2, #8E9199); font-variant-numeric: tabular-nums; white-space: nowrap;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* ── lanes ─────────────────────────────────────────────────────────────────────────────────── */
|
|
47
|
+
.rui-tl-lane {
|
|
48
|
+
position: relative; flex: 0 0 auto;
|
|
49
|
+
border-bottom: 1px solid var(--uic-line-soft, #EFF1F4);
|
|
50
|
+
/* Colour first, then the grid over it: a `background` shorthand after a background-image wipes
|
|
51
|
+
the image, which is how a lane loses its grid and nobody can see why. */
|
|
52
|
+
background-color: var(--uic-surface-2, #F7F8FA);
|
|
53
|
+
}
|
|
54
|
+
.rui-tl-laneempty {
|
|
55
|
+
margin: 0; padding: 0 10px; line-height: 48px; font-size: 12px;
|
|
56
|
+
color: var(--uic-mute-2, #8E9199); white-space: nowrap;
|
|
57
|
+
}
|
|
58
|
+
.rui-tl-empty { margin: 0; padding: 14px 10px; font-size: 12px; color: var(--uic-mute-2, #8E9199); }
|
|
59
|
+
|
|
60
|
+
/* ── a clip ────────────────────────────────────────────────────────────────────────────────── */
|
|
61
|
+
.rui-tl-clip {
|
|
62
|
+
position: absolute; top: 4px; bottom: 4px; overflow: hidden; isolation: isolate;
|
|
63
|
+
border: 1px solid var(--rui-tl-accent, var(--uic-line, #DDDFE6));
|
|
64
|
+
border-radius: 6px; background: var(--uic-surface, #FFFFFF);
|
|
65
|
+
cursor: pointer; padding: 0; text-align: left;
|
|
66
|
+
}
|
|
67
|
+
.rui-tl-clip:focus-visible { outline: 2px solid var(--uic-brand, #6E55FF); outline-offset: 1px; }
|
|
68
|
+
.rui-tl-clip.is-selected {
|
|
69
|
+
border-color: var(--uic-brand, #6E55FF);
|
|
70
|
+
box-shadow: 0 0 0 1px var(--uic-brand, #6E55FF);
|
|
71
|
+
}
|
|
72
|
+
.rui-tl-poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
|
|
73
|
+
.rui-tl-blank {
|
|
74
|
+
position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
|
|
75
|
+
color: var(--uic-mute-2, #8E9199);
|
|
76
|
+
}
|
|
77
|
+
/* Unmeasured: hatched, so "we do not know how long this is" is legible without colour being the
|
|
78
|
+
only carrier of it — and visibly different from a short clip, which is the confusion a plain
|
|
79
|
+
narrow block causes. */
|
|
80
|
+
.rui-tl-clip.is-unmeasured {
|
|
81
|
+
background-image: repeating-linear-gradient(45deg,
|
|
82
|
+
var(--uic-line-soft, #EFF1F4) 0 5px, transparent 5px 10px);
|
|
83
|
+
}
|
|
84
|
+
.rui-tl-clip.is-failed {
|
|
85
|
+
border-color: var(--uic-danger-soft, #F3C7C7);
|
|
86
|
+
background: var(--uic-danger-soft, #FCE9E9);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.rui-tl-badge, .rui-tl-dur {
|
|
90
|
+
position: absolute; z-index: 1; font-size: 10px; line-height: 1.5; padding: 0 4px;
|
|
91
|
+
border-radius: 4px; background: rgba(17, 24, 39, .62); color: #fff;
|
|
92
|
+
font-variant-numeric: tabular-nums; pointer-events: none;
|
|
93
|
+
}
|
|
94
|
+
.rui-tl-badge { top: 3px; left: 3px; font-weight: 600; }
|
|
95
|
+
.rui-tl-dur { bottom: 3px; right: 3px; }
|
|
96
|
+
.rui-tl-name {
|
|
97
|
+
position: absolute; bottom: 3px; left: 3px; z-index: 1; max-width: calc(100% - 46px);
|
|
98
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
99
|
+
font-size: 10px; padding: 0 4px; border-radius: 4px;
|
|
100
|
+
background: rgba(17, 24, 39, .62); color: #fff; pointer-events: none;
|
|
101
|
+
}
|
|
102
|
+
.rui-tl-acts {
|
|
103
|
+
position: absolute; top: 3px; right: 3px; z-index: 2; display: none; gap: 2px;
|
|
104
|
+
background: var(--uic-surface, #FFFFFF); border-radius: 5px; padding: 1px;
|
|
105
|
+
box-shadow: 0 1px 3px rgba(17, 24, 39, .18);
|
|
106
|
+
}
|
|
107
|
+
.rui-tl-clip:hover .rui-tl-acts, .rui-tl-clip:focus-within .rui-tl-acts { display: flex; }
|
|
108
|
+
|
|
109
|
+
.rui-tl-append { position: absolute; top: 4px; bottom: 4px; display: flex; align-items: center; }
|
|
110
|
+
|
|
111
|
+
/* ── playhead ──────────────────────────────────────────────────────────────────────────────── */
|
|
112
|
+
.rui-tl-playhead {
|
|
113
|
+
position: absolute; top: 0; bottom: 0; width: 1px; z-index: 5; pointer-events: none;
|
|
114
|
+
background: var(--uic-brand, #6E55FF);
|
|
115
|
+
}
|
|
116
|
+
.rui-tl-playhead-grip {
|
|
117
|
+
position: absolute; top: 0; left: -4px; width: 9px; height: 9px; border-radius: 2px;
|
|
118
|
+
background: var(--uic-brand, #6E55FF);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* ── zoom ──────────────────────────────────────────────────────────────────────────────────── */
|
|
122
|
+
.rui-tl-zoom {
|
|
123
|
+
position: absolute; right: 8px; bottom: 8px; z-index: 6; display: flex; gap: 3px;
|
|
124
|
+
background: var(--uic-surface, #FFFFFF); border: 1px solid var(--uic-line, #DDDFE6);
|
|
125
|
+
border-radius: 7px; padding: 2px; box-shadow: 0 1px 3px rgba(17, 24, 39, .1);
|
|
126
|
+
}
|
|
127
|
+
.rui-tl-zoombtn {
|
|
128
|
+
width: 22px; height: 22px; border: none; background: none; border-radius: 5px; cursor: pointer;
|
|
129
|
+
color: var(--uic-ink-2, #374151); font-size: 14px; line-height: 1; padding: 0;
|
|
130
|
+
}
|
|
131
|
+
.rui-tl-zoombtn:hover:not(:disabled) { background: var(--uic-line-soft, #EFF1F4); }
|
|
132
|
+
.rui-tl-zoombtn:disabled { opacity: .35; cursor: default; }
|
|
133
|
+
.rui-tl-fit { font-size: 12px; }
|
|
134
|
+
|
|
135
|
+
@media (prefers-reduced-motion: reduce) {
|
|
136
|
+
.rui-tl-scroll { scroll-behavior: auto; }
|
|
137
|
+
}
|