@vitavision/workbench 0.0.0-bootstrap.0 → 0.1.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/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +89 -0
- package/dist/index.d.ts +671 -0
- package/dist/index.js +1469 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -3
- package/src/components/AppShell.tsx +141 -0
- package/src/components/FileDrop.tsx +223 -0
- package/src/components/PlaybackBar.tsx +303 -0
- package/src/components/SplitPane.tsx +306 -0
- package/src/components/Toaster.tsx +149 -0
- package/src/components/TreeView.tsx +244 -0
- package/src/components/dropFiles.ts +131 -0
- package/src/components/playhead.ts +158 -0
- package/src/components/splitSize.ts +160 -0
- package/src/components/toastStore.ts +128 -0
- package/src/components/treeModel.ts +188 -0
- package/src/components/usePlayback.ts +105 -0
- package/src/index.ts +67 -0
- package/src/styles.css +7 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Notifications, as a store any module can write to.
|
|
3
|
+
*
|
|
4
|
+
* A toast is raised from wherever the news is — a file loader, a worker's error handler, a
|
|
5
|
+
* bake that finished — which is rarely a component with a context in reach. So `toast()` is
|
|
6
|
+
* a plain function over a module-level store, and `<Toaster />`, mounted once, is its only
|
|
7
|
+
* reader. The store holds no timers and touches no DOM: auto-dismissal belongs to the
|
|
8
|
+
* `Toaster`, which is what knows whether a reader is hovering it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A toast's kind: a fact (`info`), a completed action (`success`), a caveat (`warn`), a failure (`error`). */
|
|
12
|
+
export type ToastTone = "info" | "success" | "warn" | "error";
|
|
13
|
+
|
|
14
|
+
/** What `toast()` takes. */
|
|
15
|
+
export interface ToastOptions {
|
|
16
|
+
/** One line: what happened. */
|
|
17
|
+
title: string;
|
|
18
|
+
/** More detail, and what to do about it. */
|
|
19
|
+
description?: string | undefined;
|
|
20
|
+
/** Defaults to `info`. */
|
|
21
|
+
tone?: ToastTone | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* How long it stays, in milliseconds, while not hovered or focused. Defaults to 5000
|
|
24
|
+
* (8000 for `error`); `Infinity` keeps it until dismissed.
|
|
25
|
+
*/
|
|
26
|
+
duration?: number | undefined;
|
|
27
|
+
/** Replace the toast with this id instead of adding one — for progress that updates in place. */
|
|
28
|
+
id?: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A toast in the store. */
|
|
32
|
+
export interface ToastRecord {
|
|
33
|
+
/** Identifies the toast to `dismiss` and to `id` replacement. */
|
|
34
|
+
id: string;
|
|
35
|
+
/** One line: what happened. */
|
|
36
|
+
title: string;
|
|
37
|
+
/** More detail, if any. */
|
|
38
|
+
description: string | undefined;
|
|
39
|
+
/** Its kind. */
|
|
40
|
+
tone: ToastTone;
|
|
41
|
+
/** Milliseconds before it dismisses itself (`Infinity`: never). */
|
|
42
|
+
duration: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A toast store: what `toast()` writes to and `<Toaster />` reads. Every member may be called
|
|
47
|
+
* detached.
|
|
48
|
+
*/
|
|
49
|
+
export interface ToastStore {
|
|
50
|
+
/** Add a toast (or replace the one with `options.id`), returning its id. */
|
|
51
|
+
readonly toast: (options: ToastOptions) => string;
|
|
52
|
+
/** Remove one toast, or every toast when `id` is omitted. */
|
|
53
|
+
readonly dismiss: (id?: string) => void;
|
|
54
|
+
/** The toasts, oldest first. The same array until the store changes. */
|
|
55
|
+
readonly getSnapshot: () => readonly ToastRecord[];
|
|
56
|
+
/** Be told when the toasts change; returns the unsubscribe function. */
|
|
57
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const DEFAULT_DURATION = 5000;
|
|
61
|
+
const ERROR_DURATION = 8000;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A new, empty toast store. The package keeps one (behind `toast()` and the default
|
|
65
|
+
* `<Toaster />`); create another only to isolate a region or a test.
|
|
66
|
+
*
|
|
67
|
+
* @returns The store.
|
|
68
|
+
*/
|
|
69
|
+
export function createToastStore(): ToastStore {
|
|
70
|
+
let toasts: readonly ToastRecord[] = [];
|
|
71
|
+
let sequence = 0;
|
|
72
|
+
const listeners = new Set<() => void>();
|
|
73
|
+
const commit = (next: readonly ToastRecord[]) => {
|
|
74
|
+
toasts = next;
|
|
75
|
+
for (const listener of [...listeners]) listener();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
toast: (options) => {
|
|
80
|
+
const tone = options.tone ?? "info";
|
|
81
|
+
sequence += 1;
|
|
82
|
+
const record: ToastRecord = {
|
|
83
|
+
id: options.id ?? `toast-${sequence}`,
|
|
84
|
+
title: options.title,
|
|
85
|
+
description: options.description,
|
|
86
|
+
tone,
|
|
87
|
+
duration: options.duration ?? (tone === "error" ? ERROR_DURATION : DEFAULT_DURATION),
|
|
88
|
+
};
|
|
89
|
+
const existing = toasts.findIndex((t) => t.id === record.id);
|
|
90
|
+
commit(existing === -1 ? [...toasts, record] : toasts.map((t, i) => (i === existing ? record : t)));
|
|
91
|
+
return record.id;
|
|
92
|
+
},
|
|
93
|
+
dismiss: (id) => {
|
|
94
|
+
if (id === undefined) {
|
|
95
|
+
if (toasts.length > 0) commit([]);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (toasts.some((t) => t.id === id)) commit(toasts.filter((t) => t.id !== id));
|
|
99
|
+
},
|
|
100
|
+
getSnapshot: () => toasts,
|
|
101
|
+
subscribe: (listener) => {
|
|
102
|
+
listeners.add(listener);
|
|
103
|
+
return () => {
|
|
104
|
+
listeners.delete(listener);
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The store behind `toast()` and a `<Toaster />` given no `store`. */
|
|
111
|
+
export const defaultToastStore: ToastStore = createToastStore();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Raise a notification, from anywhere — shown by the mounted `<Toaster />`.
|
|
115
|
+
*
|
|
116
|
+
* `toast({ title: "Scenario loaded", tone: "success" })`. Pass `id` to update a toast in
|
|
117
|
+
* place (a progress message that becomes a result). `toast.dismiss(id)` removes one early,
|
|
118
|
+
* `toast.dismiss()` all of them.
|
|
119
|
+
*
|
|
120
|
+
* @param options - The message, its tone and its duration.
|
|
121
|
+
* @returns The toast's id.
|
|
122
|
+
*/
|
|
123
|
+
export const toast: ((options: ToastOptions) => string) & {
|
|
124
|
+
/** Remove one toast, or every toast when `id` is omitted. */
|
|
125
|
+
dismiss: (id?: string) => void;
|
|
126
|
+
} = Object.assign((options: ToastOptions) => defaultToastStore.toast(options), {
|
|
127
|
+
dismiss: (id?: string) => defaultToastStore.dismiss(id),
|
|
128
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The model behind `TreeView`: which rows are visible, where each sits in its set, and what
|
|
3
|
+
* each key does (the WAI-ARIA tree pattern).
|
|
4
|
+
*
|
|
5
|
+
* Kept out of the component so the keyboard contract — the part a tree most often gets
|
|
6
|
+
* subtly wrong — is tested as a function from (rows, focus, key) to an action.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
|
|
11
|
+
/** One node of a `TreeView`. */
|
|
12
|
+
export interface TreeNode {
|
|
13
|
+
/** Identifies the node to `selectedId`, `onSelect` and `expanded`. Unique in the tree. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** The node's name: shown, read out, and matched by type-ahead. */
|
|
16
|
+
label: string;
|
|
17
|
+
/** A leading icon (decorative) — typically a lucide icon at `size-3.5`. */
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
/** Child nodes. A node with a (possibly empty) array is a parent; without, a leaf. */
|
|
20
|
+
children?: readonly TreeNode[] | undefined;
|
|
21
|
+
/** A quiet trailing annotation — a type, a count, a frame name. Shown in mono. */
|
|
22
|
+
meta?: ReactNode;
|
|
23
|
+
/** Shown and focusable, but not selectable. */
|
|
24
|
+
disabled?: boolean | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A node as it is laid out: one visible row of the tree. */
|
|
28
|
+
export interface TreeRow {
|
|
29
|
+
/** The node. */
|
|
30
|
+
node: TreeNode;
|
|
31
|
+
/** Depth, from 1 at the root (`aria-level`). */
|
|
32
|
+
level: number;
|
|
33
|
+
/** The parent's id, or `null` at the root. */
|
|
34
|
+
parentId: string | null;
|
|
35
|
+
/** 1-based position among its siblings (`aria-posinset`). */
|
|
36
|
+
posInSet: number;
|
|
37
|
+
/** How many siblings, itself included (`aria-setsize`). */
|
|
38
|
+
setSize: number;
|
|
39
|
+
/** Whether the node has a children array. */
|
|
40
|
+
isParent: boolean;
|
|
41
|
+
/** Whether the node is a parent and expanded. */
|
|
42
|
+
isExpanded: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The rows a reader can see: every root, and the children of every expanded parent, in
|
|
47
|
+
* document order.
|
|
48
|
+
*
|
|
49
|
+
* @param nodes - The roots.
|
|
50
|
+
* @param expanded - The ids of the expanded parents.
|
|
51
|
+
* @returns The visible rows, in order.
|
|
52
|
+
*/
|
|
53
|
+
export function visibleRows(nodes: readonly TreeNode[], expanded: ReadonlySet<string>): TreeRow[] {
|
|
54
|
+
const rows: TreeRow[] = [];
|
|
55
|
+
const walk = (siblings: readonly TreeNode[], level: number, parentId: string | null) => {
|
|
56
|
+
siblings.forEach((node, index) => {
|
|
57
|
+
const isParent = node.children !== undefined;
|
|
58
|
+
const isExpanded = isParent && expanded.has(node.id);
|
|
59
|
+
rows.push({
|
|
60
|
+
node,
|
|
61
|
+
level,
|
|
62
|
+
parentId,
|
|
63
|
+
posInSet: index + 1,
|
|
64
|
+
setSize: siblings.length,
|
|
65
|
+
isParent,
|
|
66
|
+
isExpanded,
|
|
67
|
+
});
|
|
68
|
+
if (isExpanded && node.children) walk(node.children, level + 1, node.id);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
walk(nodes, 1, null);
|
|
72
|
+
return rows;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Every parent's id — the expanded set for "everything open".
|
|
77
|
+
*
|
|
78
|
+
* @param nodes - The roots.
|
|
79
|
+
* @returns The ids of every node with a children array, at any depth.
|
|
80
|
+
*/
|
|
81
|
+
export function parentIds(nodes: readonly TreeNode[]): string[] {
|
|
82
|
+
const ids: string[] = [];
|
|
83
|
+
const walk = (siblings: readonly TreeNode[]) => {
|
|
84
|
+
for (const node of siblings) {
|
|
85
|
+
if (node.children === undefined) continue;
|
|
86
|
+
ids.push(node.id);
|
|
87
|
+
walk(node.children);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
walk(nodes);
|
|
91
|
+
return ids;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The ancestors of a node, root first — what must be expanded for it to be visible.
|
|
96
|
+
*
|
|
97
|
+
* @param nodes - The roots.
|
|
98
|
+
* @param id - The node.
|
|
99
|
+
* @returns The ancestor ids, root first; empty for a root or an id not in the tree.
|
|
100
|
+
*/
|
|
101
|
+
export function ancestorIds(nodes: readonly TreeNode[], id: string): string[] {
|
|
102
|
+
const walk = (siblings: readonly TreeNode[], path: string[]): string[] | null => {
|
|
103
|
+
for (const node of siblings) {
|
|
104
|
+
if (node.id === id) return path;
|
|
105
|
+
if (node.children) {
|
|
106
|
+
const found = walk(node.children, [...path, node.id]);
|
|
107
|
+
if (found) return found;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
};
|
|
112
|
+
return walk(nodes, []) ?? [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What a key press on a tree asks for. */
|
|
116
|
+
export type TreeKeyAction =
|
|
117
|
+
| { type: "focus"; id: string }
|
|
118
|
+
| { type: "expand"; id: string }
|
|
119
|
+
| { type: "collapse"; id: string }
|
|
120
|
+
| { type: "select"; id: string }
|
|
121
|
+
| { type: "expand-siblings"; ids: string[] };
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The tree's keyboard (the WAI-ARIA tree pattern), as a pure function.
|
|
125
|
+
*
|
|
126
|
+
* ↓/↑ move to the next/previous visible row; → expands a closed parent, or moves into an
|
|
127
|
+
* open one's first child; ← collapses an open parent, or moves to the parent; Home/End go to
|
|
128
|
+
* the first/last visible row; Enter and Space select; `*` expands every sibling of the
|
|
129
|
+
* focused row; a printable character moves to the next row whose label starts with it
|
|
130
|
+
* (type-ahead, wrapping).
|
|
131
|
+
*
|
|
132
|
+
* @param rows - The visible rows, from `visibleRows`.
|
|
133
|
+
* @param focusedId - The row with focus.
|
|
134
|
+
* @param key - `KeyboardEvent.key`.
|
|
135
|
+
* @returns The action, or `null` when the key does nothing here.
|
|
136
|
+
*/
|
|
137
|
+
export function treeKeyAction(rows: readonly TreeRow[], focusedId: string, key: string): TreeKeyAction | null {
|
|
138
|
+
const index = rows.findIndex((row) => row.node.id === focusedId);
|
|
139
|
+
const row = rows[index];
|
|
140
|
+
if (row === undefined) return null;
|
|
141
|
+
const focus = (target: TreeRow | undefined): TreeKeyAction | null =>
|
|
142
|
+
target === undefined || target === row ? null : { type: "focus", id: target.node.id };
|
|
143
|
+
|
|
144
|
+
switch (key) {
|
|
145
|
+
case "ArrowDown":
|
|
146
|
+
return focus(rows[index + 1]);
|
|
147
|
+
case "ArrowUp":
|
|
148
|
+
return focus(rows[index - 1]);
|
|
149
|
+
case "Home":
|
|
150
|
+
return focus(rows[0]);
|
|
151
|
+
case "End":
|
|
152
|
+
return focus(rows[rows.length - 1]);
|
|
153
|
+
case "ArrowRight":
|
|
154
|
+
if (!row.isParent) return null;
|
|
155
|
+
if (!row.isExpanded) return { type: "expand", id: row.node.id };
|
|
156
|
+
// An open parent's first child is the next row, if it has one.
|
|
157
|
+
return rows[index + 1]?.parentId === row.node.id ? focus(rows[index + 1]) : null;
|
|
158
|
+
case "ArrowLeft":
|
|
159
|
+
if (row.isExpanded) return { type: "collapse", id: row.node.id };
|
|
160
|
+
return row.parentId === null
|
|
161
|
+
? null
|
|
162
|
+
: focus(rows.find((candidate) => candidate.node.id === row.parentId));
|
|
163
|
+
case "Enter":
|
|
164
|
+
case " ":
|
|
165
|
+
return row.node.disabled ? null : { type: "select", id: row.node.id };
|
|
166
|
+
case "*": {
|
|
167
|
+
const ids = rows
|
|
168
|
+
.filter((candidate) => candidate.parentId === row.parentId && candidate.isParent && !candidate.isExpanded)
|
|
169
|
+
.map((candidate) => candidate.node.id);
|
|
170
|
+
return ids.length === 0 ? null : { type: "expand-siblings", ids };
|
|
171
|
+
}
|
|
172
|
+
default:
|
|
173
|
+
return typeAhead(rows, index, key);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The next row after `from` (wrapping) whose label starts with `key`, for a single printable character. */
|
|
178
|
+
function typeAhead(rows: readonly TreeRow[], from: number, key: string): TreeKeyAction | null {
|
|
179
|
+
if (key.length !== 1 || key.trim() === "") return null;
|
|
180
|
+
const needle = key.toLocaleLowerCase();
|
|
181
|
+
for (let offset = 1; offset <= rows.length; offset += 1) {
|
|
182
|
+
const candidate = rows[(from + offset) % rows.length];
|
|
183
|
+
if (candidate?.node.label.toLocaleLowerCase().startsWith(needle)) {
|
|
184
|
+
return offset === rows.length ? null : { type: "focus", id: candidate.node.id };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The React side of the playhead: subscribing to it, and driving it in real time.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useEffect, useEffectEvent, useSyncExternalStore } from "react";
|
|
6
|
+
|
|
7
|
+
import { advance, type Playhead } from "./playhead";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The playhead's current sample index, re-rendering the calling component when it changes.
|
|
11
|
+
*
|
|
12
|
+
* Use it only where the index is *displayed* (the playback bar, a readout). A render loop
|
|
13
|
+
* reads `playhead.get()` in its own frame callback instead, and re-renders nothing.
|
|
14
|
+
*
|
|
15
|
+
* @param playhead - The store.
|
|
16
|
+
* @returns The current sample index.
|
|
17
|
+
*/
|
|
18
|
+
export function usePlayhead(playhead: Playhead): number {
|
|
19
|
+
return useSyncExternalStore(playhead.subscribe, playhead.get, playhead.get);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The playhead's timeline — `count` and `dt` — re-rendering when `setTimeline` changes it.
|
|
24
|
+
*
|
|
25
|
+
* @param playhead - The store.
|
|
26
|
+
* @returns The number of samples and the seconds between them.
|
|
27
|
+
*/
|
|
28
|
+
export function usePlayheadTimeline(playhead: Playhead): { count: number; dt: number } {
|
|
29
|
+
const count = useSyncExternalStore(playhead.subscribe, () => playhead.count, () => playhead.count);
|
|
30
|
+
const dt = useSyncExternalStore(playhead.subscribe, () => playhead.dt, () => playhead.dt);
|
|
31
|
+
return { count, dt };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Options of `usePlaybackClock`. */
|
|
35
|
+
export interface PlaybackClockOptions {
|
|
36
|
+
/** The store to advance. */
|
|
37
|
+
playhead: Playhead;
|
|
38
|
+
/** Whether the clock runs. */
|
|
39
|
+
playing: boolean;
|
|
40
|
+
/** Playback rate: 1 is real time. Defaults to 1. */
|
|
41
|
+
speed?: number | undefined;
|
|
42
|
+
/** Wrap from the last sample to the first instead of stopping. Defaults to false. */
|
|
43
|
+
loop?: boolean | undefined;
|
|
44
|
+
/** Called once when a non-looping timeline reaches its last sample; set `playing` false here. */
|
|
45
|
+
onEnd?: (() => void) | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The longest wall-clock gap one frame may advance by, in milliseconds. A tab in the
|
|
48
|
+
* background gets no animation frames, and without this cap the first frame back would
|
|
49
|
+
* jump by the whole time away. Defaults to 100.
|
|
50
|
+
*/
|
|
51
|
+
maxFrameMs?: number | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Advance a playhead in real time × `speed` while `playing`, from `requestAnimationFrame`.
|
|
56
|
+
*
|
|
57
|
+
* Position is accumulated fractionally, so slow playback of a finely sampled timeline still
|
|
58
|
+
* moves; the store only ever holds the integer index. A seek from elsewhere (the scrubber, a
|
|
59
|
+
* marker) is picked up on the next frame. Starting a non-looping timeline that sits on its
|
|
60
|
+
* last sample rewinds it to 0 first. `speed`, `loop` and `onEnd` may change while playing
|
|
61
|
+
* without restarting the clock.
|
|
62
|
+
*
|
|
63
|
+
* Renders nothing and re-renders nothing: call it once, in the component that owns the
|
|
64
|
+
* `playing` state.
|
|
65
|
+
*
|
|
66
|
+
* @param options - The playhead and the transport state.
|
|
67
|
+
*/
|
|
68
|
+
export function usePlaybackClock({
|
|
69
|
+
playhead,
|
|
70
|
+
playing,
|
|
71
|
+
speed = 1,
|
|
72
|
+
loop = false,
|
|
73
|
+
onEnd,
|
|
74
|
+
maxFrameMs = 100,
|
|
75
|
+
}: PlaybackClockOptions): void {
|
|
76
|
+
const step = useEffectEvent((position: number, elapsedMs: number) => {
|
|
77
|
+
const delta = (Math.min(elapsedMs, maxFrameMs) / 1000) * (speed / playhead.dt);
|
|
78
|
+
return advance(position, delta, playhead.count, loop);
|
|
79
|
+
});
|
|
80
|
+
const end = useEffectEvent(() => onEnd?.());
|
|
81
|
+
const rewindIfAtEnd = useEffectEvent(() => {
|
|
82
|
+
if (!loop && playhead.count > 0 && playhead.get() >= playhead.count - 1) playhead.set(0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!playing) return;
|
|
87
|
+
rewindIfAtEnd();
|
|
88
|
+
let position = playhead.get();
|
|
89
|
+
let last: number | null = null;
|
|
90
|
+
let frame = requestAnimationFrame(function tick(now: number) {
|
|
91
|
+
// A seek since the last frame (scrubber, marker, step button) wins over the clock.
|
|
92
|
+
if (Math.floor(position) !== playhead.get()) position = playhead.get();
|
|
93
|
+
const result = last === null ? { position, ended: false } : step(position, now - last);
|
|
94
|
+
last = now;
|
|
95
|
+
position = result.position;
|
|
96
|
+
playhead.set(Math.floor(position));
|
|
97
|
+
if (result.ended) {
|
|
98
|
+
end();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
frame = requestAnimationFrame(tick);
|
|
102
|
+
});
|
|
103
|
+
return () => cancelAnimationFrame(frame);
|
|
104
|
+
}, [playing, playhead]);
|
|
105
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@vitavision/workbench` — the building blocks of a studio app on `@vitavision/ui`: the
|
|
3
|
+
* shell and its split panes, a tree navigator, a playback transport over a sampled timeline,
|
|
4
|
+
* file opening, and notifications.
|
|
5
|
+
*
|
|
6
|
+
* Import `@vitavision/workbench/styles.css` after `@vitavision/ui/styles.css`.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export { AppShell, type AppShellProps, type SidePanelSize } from "./components/AppShell";
|
|
12
|
+
export { SplitPane, type SplitPaneProps } from "./components/SplitPane";
|
|
13
|
+
export {
|
|
14
|
+
type PaneSize,
|
|
15
|
+
type SizedPane,
|
|
16
|
+
type SplitOrientation,
|
|
17
|
+
clampSize,
|
|
18
|
+
resolveLimits,
|
|
19
|
+
resolveSize,
|
|
20
|
+
type SplitLimits,
|
|
21
|
+
} from "./components/splitSize";
|
|
22
|
+
|
|
23
|
+
export { TreeView, type TreeViewProps } from "./components/TreeView";
|
|
24
|
+
export {
|
|
25
|
+
type TreeKeyAction,
|
|
26
|
+
type TreeNode,
|
|
27
|
+
type TreeRow,
|
|
28
|
+
ancestorIds,
|
|
29
|
+
parentIds,
|
|
30
|
+
treeKeyAction,
|
|
31
|
+
visibleRows,
|
|
32
|
+
} from "./components/treeModel";
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
DEFAULT_SPEEDS,
|
|
36
|
+
PlaybackBar,
|
|
37
|
+
type PlaybackBarProps,
|
|
38
|
+
type PlaybackMarker,
|
|
39
|
+
} from "./components/PlaybackBar";
|
|
40
|
+
export {
|
|
41
|
+
type AdvanceResult,
|
|
42
|
+
advance,
|
|
43
|
+
clampIndex,
|
|
44
|
+
createPlayhead,
|
|
45
|
+
formatSeconds,
|
|
46
|
+
type Playhead,
|
|
47
|
+
} from "./components/playhead";
|
|
48
|
+
export {
|
|
49
|
+
type PlaybackClockOptions,
|
|
50
|
+
usePlaybackClock,
|
|
51
|
+
usePlayhead,
|
|
52
|
+
usePlayheadTimeline,
|
|
53
|
+
} from "./components/usePlayback";
|
|
54
|
+
|
|
55
|
+
export { FileDrop, type FileDropProps } from "./components/FileDrop";
|
|
56
|
+
export { acceptsFile, collectDroppedFiles, type DropEntry } from "./components/dropFiles";
|
|
57
|
+
|
|
58
|
+
export { Toaster, type ToasterProps } from "./components/Toaster";
|
|
59
|
+
export {
|
|
60
|
+
createToastStore,
|
|
61
|
+
defaultToastStore,
|
|
62
|
+
toast,
|
|
63
|
+
type ToastOptions,
|
|
64
|
+
type ToastRecord,
|
|
65
|
+
type ToastStore,
|
|
66
|
+
type ToastTone,
|
|
67
|
+
} from "./components/toastStore";
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Nothing to style: this file exists so Tailwind v4 finds this package's class names.
|
|
3
|
+
* `@source` resolves against the stylesheet that declares it, and this file is exported from
|
|
4
|
+
* `src/` (which ships), so it scans the package's sources. Import it after
|
|
5
|
+
* `@vitavision/ui/styles.css`.
|
|
6
|
+
*/
|
|
7
|
+
@source "./";
|