@zylem/ui 0.8.9 → 0.8.11

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.
Files changed (51) hide show
  1. package/dist/styles.css +1 -1
  2. package/package.json +12 -10
  3. package/src/components/Accordion/Accordion.tsx +10 -1
  4. package/src/components/AddTile/AddTile.css.ts +17 -0
  5. package/src/components/AddTile/AddTile.tsx +15 -7
  6. package/src/components/Callout/Callout.css.ts +45 -0
  7. package/src/components/Callout/Callout.tsx +32 -0
  8. package/src/components/Card/Card.css.ts +18 -0
  9. package/src/components/Card/Card.tsx +25 -2
  10. package/src/components/Dialog/Dialog.css.ts +69 -2
  11. package/src/components/Dialog/Dialog.tsx +35 -7
  12. package/src/components/DropdownMenu/DropdownMenu.css.ts +22 -0
  13. package/src/components/DropdownMenu/DropdownMenu.tsx +67 -20
  14. package/src/components/EmptyState/EmptyState.css.ts +9 -0
  15. package/src/components/EmptyState/EmptyState.tsx +3 -1
  16. package/src/components/FrameStrip/FrameStrip.css.ts +6 -0
  17. package/src/components/FrameStrip/FrameStrip.tsx +30 -2
  18. package/src/components/Menubar/Menubar.css.ts +52 -0
  19. package/src/components/Menubar/Menubar.tsx +77 -0
  20. package/src/components/Mixer/Knob.tsx +188 -0
  21. package/src/components/Mixer/Mixer.css.ts +246 -0
  22. package/src/components/Mixer/MixerStrip.tsx +150 -0
  23. package/src/components/NumberField/NumberField.tsx +5 -1
  24. package/src/components/Panel/Panel.tsx +6 -5
  25. package/src/components/PianoRoll/PianoRoll.css.ts +224 -0
  26. package/src/components/PianoRoll/PianoRoll.tsx +353 -0
  27. package/src/components/PianoRoll/piano-roll-math.ts +89 -0
  28. package/src/components/Property/Property.css.ts +1 -1
  29. package/src/components/Property/Property.tsx +3 -0
  30. package/src/components/Sidebar/Sidebar.css.ts +8 -0
  31. package/src/components/Sidebar/Sidebar.tsx +10 -2
  32. package/src/components/Slider/Slider.tsx +6 -0
  33. package/src/components/SpriteSizePicker/SpriteSizePicker.tsx +15 -4
  34. package/src/components/Tabs/Tabs.css.ts +48 -0
  35. package/src/components/Tabs/Tabs.tsx +41 -3
  36. package/src/components/TextField/TextField.tsx +49 -5
  37. package/src/components/TimelineLanes/TimelineLanes.css.ts +365 -0
  38. package/src/components/TimelineLanes/TimelineLanes.tsx +509 -0
  39. package/src/components/TimelineLanes/lanes-math.ts +182 -0
  40. package/src/components/Toast/Toast.css.ts +48 -0
  41. package/src/components/Toast/Toast.tsx +37 -0
  42. package/src/components/TrackHeader/TrackHeader.css.ts +162 -0
  43. package/src/components/TrackHeader/TrackHeader.tsx +145 -0
  44. package/src/components/TransportBar/TransportBar.css.ts +65 -0
  45. package/src/components/TransportBar/TransportBar.tsx +154 -0
  46. package/src/components/Waveform/Waveform.css.ts +77 -0
  47. package/src/components/Waveform/Waveform.tsx +195 -0
  48. package/src/components/Waveform/peaks.ts +49 -0
  49. package/src/components/index.ts +55 -1
  50. package/src/global/accordion.css.ts +23 -0
  51. package/src/styles.ts +11 -0
@@ -0,0 +1,195 @@
1
+ import { createEffect, createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js';
2
+ import { clamp } from '../TimelineLanes/lanes-math';
3
+ import { computePeaks, peaksFromAudioBuffer } from './peaks';
4
+
5
+ export type { PeakSource } from './peaks';
6
+
7
+ export interface WaveformRegion {
8
+ /** Seconds. */
9
+ start: number;
10
+ end: number;
11
+ }
12
+
13
+ export interface WaveformProps {
14
+ /** Pre-computed peaks (0–1 per column); wins over `buffer`. */
15
+ peaks?: ArrayLike<number>;
16
+ /** Source audio; peaks are computed to match the drawn width. */
17
+ buffer?: { duration: number; numberOfChannels: number; getChannelData(channel: number): Float32Array };
18
+ /** Seconds the peaks span; defaults to `buffer.duration`. Needed for regions and the playhead. */
19
+ duration?: number;
20
+ /** Highlighted span with draggable edges. */
21
+ region?: WaveformRegion;
22
+ onRegionChange?: (region: WaveformRegion) => void;
23
+ onRegionCommit?: (region: WaveformRegion) => void;
24
+ /** Seconds. */
25
+ playhead?: number;
26
+ /** Any CSS color for the peaks. */
27
+ color?: string;
28
+ height?: number;
29
+ /** Click anywhere to seek. */
30
+ onSeek?: (seconds: number) => void;
31
+ disabled?: boolean;
32
+ class?: string;
33
+ }
34
+
35
+ /**
36
+ * Canvas waveform with an optional trim region and playhead. Peaks are
37
+ * redrawn on resize so the shape stays crisp at any width.
38
+ */
39
+ export function Waveform(props: WaveformProps) {
40
+ let canvas: HTMLCanvasElement | undefined;
41
+ let host: HTMLDivElement | undefined;
42
+ const [width, setWidth] = createSignal(0);
43
+ const height = () => props.height ?? 64;
44
+ const duration = () => props.duration ?? props.buffer?.duration ?? 0;
45
+
46
+ const peaks = createMemo(() => {
47
+ const bins = Math.max(1, Math.floor(width()));
48
+ if (props.peaks) {
49
+ const source = Float32Array.from(props.peaks as ArrayLike<number>);
50
+ return source.length === bins ? source : resample(source, bins);
51
+ }
52
+ if (props.buffer) return peaksFromAudioBuffer(props.buffer, bins);
53
+ return new Float32Array(bins);
54
+ });
55
+
56
+ onMount(() => {
57
+ if (!host) return;
58
+ setWidth(host.clientWidth);
59
+ if (typeof ResizeObserver === 'undefined') return;
60
+ const observer = new ResizeObserver((entries) => {
61
+ const entry = entries[0];
62
+ if (entry) setWidth(Math.floor(entry.contentRect.width));
63
+ });
64
+ observer.observe(host);
65
+ onCleanup(() => observer.disconnect());
66
+ });
67
+
68
+ createEffect(() => {
69
+ if (!canvas) return;
70
+ const w = width();
71
+ const h = height();
72
+ const data = peaks();
73
+ const color =
74
+ props.color ??
75
+ (getComputedStyle(canvas).getPropertyValue('--zylem-color-primary').trim() || '#61a6e8');
76
+ const ratio = typeof devicePixelRatio === 'number' ? devicePixelRatio : 1;
77
+ canvas.width = Math.max(1, Math.floor(w * ratio));
78
+ canvas.height = Math.max(1, Math.floor(h * ratio));
79
+ const context = canvas.getContext('2d');
80
+ if (!context) return;
81
+ context.setTransform(ratio, 0, 0, ratio, 0, 0);
82
+ context.clearRect(0, 0, w, h);
83
+ const mid = h / 2;
84
+ context.strokeStyle = 'rgba(205, 232, 255, 0.18)';
85
+ context.beginPath();
86
+ context.moveTo(0, mid + 0.5);
87
+ context.lineTo(w, mid + 0.5);
88
+ context.stroke();
89
+ context.fillStyle = color;
90
+ for (let x = 0; x < data.length; x += 1) {
91
+ const amplitude = Math.max(1, (data[x] ?? 0) * (mid - 2));
92
+ context.fillRect(x, mid - amplitude, 1, amplitude * 2);
93
+ }
94
+ });
95
+
96
+ const secondsAt = (clientX: number) => {
97
+ if (!host || duration() <= 0) return 0;
98
+ const rect = host.getBoundingClientRect();
99
+ return clamp(((clientX - rect.left) / rect.width) * duration(), 0, duration());
100
+ };
101
+ const percent = (seconds: number) => (duration() > 0 ? (seconds / duration()) * 100 : 0);
102
+
103
+ const beginRegionDrag = (edge: 'start' | 'end') => (event: PointerEvent) => {
104
+ const region = props.region;
105
+ if (props.disabled || !region || event.button !== 0) return;
106
+ event.preventDefault();
107
+ event.stopPropagation();
108
+ const target = event.currentTarget as HTMLElement;
109
+ target.setPointerCapture?.(event.pointerId);
110
+ let last = region;
111
+ const move = (moveEvent: PointerEvent) => {
112
+ const seconds = secondsAt(moveEvent.clientX);
113
+ last =
114
+ edge === 'start'
115
+ ? { start: Math.min(seconds, region.end - 0.01), end: region.end }
116
+ : { start: region.start, end: Math.max(seconds, region.start + 0.01) };
117
+ props.onRegionChange?.(last);
118
+ };
119
+ const stop = () => {
120
+ target.removeEventListener('pointermove', move);
121
+ target.removeEventListener('pointerup', stop);
122
+ target.removeEventListener('pointercancel', stop);
123
+ target.releasePointerCapture?.(event.pointerId);
124
+ props.onRegionCommit?.(last);
125
+ };
126
+ target.addEventListener('pointermove', move);
127
+ target.addEventListener('pointerup', stop);
128
+ target.addEventListener('pointercancel', stop);
129
+ };
130
+
131
+ return (
132
+ <div
133
+ ref={host}
134
+ class={props.class ? `zylem-waveform ${props.class}` : 'zylem-waveform'}
135
+ style={{ height: `${height()}px` }}
136
+ data-disabled={props.disabled ? '' : undefined}
137
+ onPointerDown={(event) => {
138
+ if (props.disabled || !props.onSeek || event.button !== 0) return;
139
+ props.onSeek(secondsAt(event.clientX));
140
+ }}
141
+ >
142
+ <canvas ref={canvas} class="zylem-waveform-canvas" aria-hidden="true" />
143
+ <Show when={props.region && duration() > 0}>
144
+ {(_) => {
145
+ const region = () => props.region!;
146
+ return (
147
+ <>
148
+ <div
149
+ class="zylem-waveform-shade"
150
+ style={{ left: 0, width: `${percent(region().start)}%` }}
151
+ />
152
+ <div
153
+ class="zylem-waveform-shade"
154
+ style={{ left: `${percent(region().end)}%`, right: 0 }}
155
+ />
156
+ <div
157
+ class="zylem-waveform-edge"
158
+ data-edge="start"
159
+ style={{ left: `${percent(region().start)}%` }}
160
+ onPointerDown={beginRegionDrag('start')}
161
+ role="slider"
162
+ aria-label="Trim start"
163
+ aria-valuenow={region().start}
164
+ aria-valuemin={0}
165
+ aria-valuemax={duration()}
166
+ />
167
+ <div
168
+ class="zylem-waveform-edge"
169
+ data-edge="end"
170
+ style={{ left: `${percent(region().end)}%` }}
171
+ onPointerDown={beginRegionDrag('end')}
172
+ role="slider"
173
+ aria-label="Trim end"
174
+ aria-valuenow={region().end}
175
+ aria-valuemin={0}
176
+ aria-valuemax={duration()}
177
+ />
178
+ </>
179
+ );
180
+ }}
181
+ </Show>
182
+ <Show when={props.playhead !== undefined && duration() > 0}>
183
+ <div
184
+ class="zylem-waveform-playhead"
185
+ style={{ left: `${percent(props.playhead ?? 0)}%` }}
186
+ aria-hidden="true"
187
+ />
188
+ </Show>
189
+ </div>
190
+ );
191
+ }
192
+
193
+ function resample(source: Float32Array, bins: number): Float32Array {
194
+ return computePeaks({ channels: [source] }, bins);
195
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Peak extraction for waveform drawing: folds PCM samples into `bins`
3
+ * columns, each the largest absolute sample in its slice, normalised so the
4
+ * loudest bin is 1 (silence stays 0).
5
+ */
6
+
7
+ export interface PeakSource {
8
+ /** One `Float32Array` per channel; channels are mixed by taking the max. */
9
+ channels: readonly Float32Array[];
10
+ }
11
+
12
+ export function computePeaks(source: PeakSource | Float32Array, bins: number): Float32Array {
13
+ const channels = source instanceof Float32Array ? [source] : source.channels;
14
+ const count = Math.max(1, Math.floor(bins));
15
+ const peaks = new Float32Array(count);
16
+ const length = channels[0]?.length ?? 0;
17
+ if (length === 0 || channels.length === 0) return peaks;
18
+ const perBin = length / count;
19
+ let loudest = 0;
20
+ for (let bin = 0; bin < count; bin += 1) {
21
+ const from = Math.floor(bin * perBin);
22
+ const to = Math.min(length, Math.max(from + 1, Math.floor((bin + 1) * perBin)));
23
+ let peak = 0;
24
+ for (const channel of channels) {
25
+ for (let i = from; i < to; i += 1) {
26
+ const value = Math.abs(channel[i] ?? 0);
27
+ if (value > peak) peak = value;
28
+ }
29
+ }
30
+ peaks[bin] = peak;
31
+ if (peak > loudest) loudest = peak;
32
+ }
33
+ if (loudest > 0 && loudest !== 1) {
34
+ for (let bin = 0; bin < count; bin += 1) peaks[bin] = peaks[bin]! / loudest;
35
+ }
36
+ return peaks;
37
+ }
38
+
39
+ /** Peaks from a Web Audio `AudioBuffer` without depending on its type here. */
40
+ export function peaksFromAudioBuffer(
41
+ buffer: { numberOfChannels: number; getChannelData(channel: number): Float32Array },
42
+ bins: number,
43
+ ): Float32Array {
44
+ const channels: Float32Array[] = [];
45
+ for (let channel = 0; channel < buffer.numberOfChannels; channel += 1) {
46
+ channels.push(buffer.getChannelData(channel));
47
+ }
48
+ return computePeaks({ channels }, bins);
49
+ }
@@ -38,6 +38,7 @@ export {
38
38
  TabsTrigger,
39
39
  TabsContent,
40
40
  type TabsProps,
41
+ type TabsTriggerProps,
41
42
  } from './Tabs/Tabs';
42
43
  export {
43
44
  Accordion,
@@ -47,17 +48,22 @@ export {
47
48
  export { Tooltip, type TooltipProps } from './Tooltip/Tooltip';
48
49
  export {
49
50
  DropdownMenu,
51
+ MenuItems,
50
52
  type DropdownMenuProps,
51
53
  type DropdownMenuItemConfig,
52
54
  } from './DropdownMenu/DropdownMenu';
55
+ export { Menubar, type MenubarProps, type MenubarMenuConfig } from './Menubar/Menubar';
53
56
  export {
54
57
  Dialog,
55
58
  ConfirmDialog,
56
59
  type DialogProps,
60
+ type DialogSize,
57
61
  type ConfirmDialogProps,
58
62
  } from './Dialog/Dialog';
59
63
  export { Progress, type ProgressProps } from './Progress/Progress';
60
64
  export { Badge, type BadgeProps, type BadgeTone } from './Badge/Badge';
65
+ export { Callout, type CalloutProps, type CalloutTone } from './Callout/Callout';
66
+ export { Toast, type ToastProps, type ToastTone } from './Toast/Toast';
61
67
  export { Separator, type SeparatorProps } from './Separator/Separator';
62
68
 
63
69
  // Composites
@@ -130,7 +136,7 @@ export {
130
136
  type ArtTool,
131
137
  type ToolButtonProps,
132
138
  } from './ToolButton/ToolButton';
133
- export { AddTile, type AddTileProps } from './AddTile/AddTile';
139
+ export { AddTile, type AddTileProps, type AddTileVariant } from './AddTile/AddTile';
134
140
  export {
135
141
  ColorPalette,
136
142
  Swatch,
@@ -163,3 +169,51 @@ export {
163
169
  type ToolboxGridProps,
164
170
  type ToolboxSize,
165
171
  } from './ToolboxButton/ToolboxButton';
172
+
173
+ // Timeline / Music (Creator director and music editors)
174
+ export {
175
+ TimelineLanes,
176
+ TimelineLane,
177
+ TimelineLaneGroup,
178
+ TimelineClip,
179
+ KeyframeMarker,
180
+ useTimeline,
181
+ type TimelineLanesProps,
182
+ type TimelineLaneProps,
183
+ type TimelineLaneGroupProps,
184
+ type TimelineClipProps,
185
+ type TimelineClipChange,
186
+ type TimelineContextValue,
187
+ type TimelineRange,
188
+ type KeyframeMarkerProps,
189
+ type TimeScale,
190
+ type TimeUnit,
191
+ type RulerTick,
192
+ type ClipBounds,
193
+ } from './TimelineLanes/TimelineLanes';
194
+ export {
195
+ snapTime,
196
+ resolveClipDrag,
197
+ rulerTicks,
198
+ majorTickTimes,
199
+ formatClock,
200
+ formatBeats,
201
+ } from './TimelineLanes/lanes-math';
202
+ export { TrackHeader, type TrackHeaderProps } from './TrackHeader/TrackHeader';
203
+ export { PianoRoll, type PianoRollProps, type PianoRollNote } from './PianoRoll/PianoRoll';
204
+ export {
205
+ pitchName,
206
+ isBlackKey,
207
+ resolveNoteDrag,
208
+ cellStart,
209
+ } from './PianoRoll/piano-roll-math';
210
+ export { Knob, arcPath, type KnobProps } from './Mixer/Knob';
211
+ export { MixerStrip, formatDb, formatPan, type MixerStripProps } from './Mixer/MixerStrip';
212
+ export { Waveform, type WaveformProps, type WaveformRegion } from './Waveform/Waveform';
213
+ export { computePeaks, peaksFromAudioBuffer, type PeakSource } from './Waveform/peaks';
214
+ export {
215
+ TransportBar,
216
+ formatTransportTime,
217
+ type TransportBarProps,
218
+ type TransportTimeSignature,
219
+ } from './TransportBar/TransportBar';
@@ -81,6 +81,29 @@ globalStyle('.accordion-content', {
81
81
  transition: 'height 0.3s ease',
82
82
  });
83
83
 
84
+ /**
85
+ * Stack layout: natural-height sections, no per-section scrolling. The
86
+ * accordion grows with its content and leaves scrolling to the parent.
87
+ */
88
+ globalStyle('.zylem-accordion--stack', {
89
+ height: 'auto',
90
+ flex: 'none',
91
+ });
92
+
93
+ globalStyle('.zylem-accordion--stack .accordion-item[data-expanded]', {
94
+ flex: 'none',
95
+ });
96
+
97
+ // The parent scrolls, so headers must not pin over the sections above them.
98
+ globalStyle('.zylem-accordion--stack .accordion-header', {
99
+ position: 'static',
100
+ });
101
+
102
+ globalStyle('.zylem-accordion--stack .accordion-content', {
103
+ flex: 'none',
104
+ overflow: 'visible',
105
+ });
106
+
84
107
  globalStyle('.accordion-trigger::after', {
85
108
  content: "'\\25BC'",
86
109
  position: 'relative',
package/src/styles.ts CHANGED
@@ -32,9 +32,12 @@ import './components/Slider/Slider.css';
32
32
  import './components/Tabs/Tabs.css';
33
33
  import './components/Tooltip/Tooltip.css';
34
34
  import './components/DropdownMenu/DropdownMenu.css';
35
+ import './components/Menubar/Menubar.css';
35
36
  import './components/Dialog/Dialog.css';
36
37
  import './components/Progress/Progress.css';
37
38
  import './components/Badge/Badge.css';
39
+ import './components/Callout/Callout.css';
40
+ import './components/Toast/Toast.css';
38
41
  import './components/Separator/Separator.css';
39
42
  import './components/WindowControls/WindowControls.css';
40
43
  import './components/TitleBar/TitleBar.css';
@@ -61,3 +64,11 @@ import './components/FrameStrip/FrameStrip.css';
61
64
  import './components/PlaybackControls/PlaybackControls.css';
62
65
  import './components/TimelineTrack/TimelineTrack.css';
63
66
  import './components/ToolboxButton/ToolboxButton.css';
67
+
68
+ // Timeline / Music surfaces (Creator director and music editors).
69
+ import './components/TimelineLanes/TimelineLanes.css';
70
+ import './components/TrackHeader/TrackHeader.css';
71
+ import './components/PianoRoll/PianoRoll.css';
72
+ import './components/Mixer/Mixer.css';
73
+ import './components/Waveform/Waveform.css';
74
+ import './components/TransportBar/TransportBar.css';