@toneflix/studio 0.1.0 → 0.2.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.
@@ -1,81 +0,0 @@
1
- /** Default look of the timeline. Hosts restyle it through the `--tfs-*` variables. */
2
- export const STYLES = `
3
- .tfs {
4
- --tfs-bg: #121214;
5
- --tfs-lane: #18181b;
6
- --tfs-lane-alt: #1c1c20;
7
- --tfs-line: rgba(255, 255, 255, 0.07);
8
- --tfs-beat: rgba(255, 255, 255, 0.05);
9
- --tfs-bar: rgba(255, 255, 255, 0.13);
10
- --tfs-header: #1f1f23;
11
- --tfs-text: #e8e8ea;
12
- --tfs-muted: #9a9aa2;
13
- --tfs-clip: #4f9cf9;
14
- --tfs-select: #ffd34d;
15
- --tfs-playhead: #ff5a5f;
16
- --tfs-range: rgba(255, 211, 77, 0.16);
17
- --tfs-ruler-height: 28px;
18
- position: relative;
19
- width: 100%;
20
- height: 100%;
21
- overflow: hidden;
22
- background: var(--tfs-bg);
23
- color: var(--tfs-text);
24
- font: 12px/1.3 system-ui, sans-serif;
25
- user-select: none;
26
- -webkit-user-select: none;
27
- outline: none;
28
- }
29
- .tfs-scroll { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; }
30
- .tfs-content { position: relative; min-height: 100%; }
31
- .tfs-ruler-row { position: sticky; top: 0; z-index: 6; display: flex; height: var(--tfs-ruler-height); }
32
- .tfs-corner { position: sticky; left: 0; z-index: 7; flex: none; background: var(--tfs-header); border-bottom: 1px solid var(--tfs-line); border-right: 1px solid var(--tfs-line); }
33
- .tfs-ruler { position: relative; flex: none; background: var(--tfs-header); border-bottom: 1px solid var(--tfs-line); cursor: text; overflow: hidden; }
34
- .tfs-ruler-label { position: absolute; top: 4px; padding-left: 4px; color: var(--tfs-muted); font-size: 11px; white-space: nowrap; border-left: 1px solid var(--tfs-bar); height: calc(var(--tfs-ruler-height) - 4px); pointer-events: none; }
35
- .tfs-row { position: relative; display: flex; border-bottom: 1px solid var(--tfs-line); }
36
- .tfs-row:nth-child(odd of .tfs-row) .tfs-lane { background-color: var(--tfs-lane-alt); }
37
- .tfs-header { position: sticky; left: 0; z-index: 5; flex: none; box-sizing: border-box; background: var(--tfs-header); border-right: 1px solid var(--tfs-line); overflow: hidden; }
38
- .tfs-header-default { display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 12px; }
39
- .tfs-header-default i { width: 4px; align-self: stretch; margin: 10px 0; border-radius: 2px; background: var(--clip, var(--tfs-clip)); }
40
- .tfs-header-default span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
41
- .tfs-lane { position: relative; flex: none; background-color: var(--tfs-lane); touch-action: pan-x pan-y; }
42
- .tfs--grid .tfs-lane {
43
- background-image: linear-gradient(to right, var(--tfs-bar) 1px, transparent 1px), linear-gradient(to right, var(--tfs-beat) 1px, transparent 1px);
44
- background-size: var(--tfs-bar-px) 100%, var(--tfs-beat-px) 100%;
45
- }
46
- .tfs-row--new .tfs-lane { background: repeating-linear-gradient(45deg, transparent 0 8px, var(--tfs-line) 8px 16px); }
47
- .tfs-clip {
48
- position: absolute; top: 2px; bottom: 2px; box-sizing: border-box; overflow: hidden;
49
- border-radius: 6px; border: 1px solid color-mix(in srgb, var(--clip, var(--tfs-clip)) 65%, transparent);
50
- background: color-mix(in srgb, var(--clip, var(--tfs-clip)) 22%, var(--tfs-lane));
51
- cursor: grab; touch-action: none;
52
- }
53
- .tfs-clip + .tfs-clip { box-shadow: -3px 0 6px -2px rgba(0, 0, 0, 0.55); }
54
- .tfs-clip:focus-visible { outline: 2px solid var(--tfs-select); outline-offset: -2px; }
55
- .tfs-clip.tfs-clip--selected { border-color: var(--tfs-select); box-shadow: inset 0 0 0 1px var(--tfs-select), -3px 0 6px -2px rgba(0, 0, 0, 0.55); }
56
- .tfs-clip--dragging { cursor: grabbing; opacity: 0.92; }
57
- .tfs-clip-head { position: absolute; left: 0; right: 0; top: 0; height: 16px; padding: 1px 8px; box-sizing: border-box; font-size: 11px; color: var(--tfs-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: color-mix(in srgb, var(--clip, var(--tfs-clip)) 35%, transparent); pointer-events: none; }
58
- .tfs-wave { position: absolute; left: 0; right: 0; top: 16px; bottom: 0; pointer-events: none; }
59
- .tfs-wave canvas { position: absolute; top: 0; height: 100%; }
60
- .tfs-trim { position: absolute; top: 0; bottom: 0; width: 8px; z-index: 2; cursor: ew-resize; }
61
- .tfs-trim--start { left: 0; }
62
- .tfs-trim--end { right: 0; }
63
- .tfs-fade { position: absolute; top: 1px; width: 10px; height: 10px; margin-left: -5px; z-index: 3; box-sizing: border-box; border-radius: 2px; background: var(--tfs-text); opacity: 0; cursor: col-resize; }
64
- .tfs-clip:hover .tfs-fade, .tfs-clip--selected .tfs-fade { opacity: 0.85; }
65
- .tfs--readonly .tfs-trim, .tfs--readonly .tfs-fade { display: none; }
66
- .tfs--readonly .tfs-clip { cursor: default; }
67
- .tfs-overlay { position: absolute; top: 0; bottom: 0; z-index: 4; pointer-events: none; }
68
- .tfs-playhead { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--tfs-playhead); }
69
- .tfs-playhead::before { content: ''; position: absolute; top: 0; left: -5px; border: 5px solid transparent; border-top: 7px solid var(--tfs-playhead); }
70
- .tfs-range { position: absolute; background: var(--tfs-range); border-left: 1px solid var(--tfs-select); border-right: 1px solid var(--tfs-select); }
71
- .tfs-snap { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--tfs-select); opacity: 0.7; }
72
- `;
73
- /** Add the default styles to a document once. */
74
- export const injectStyles = (doc) => {
75
- if (doc.getElementById('tfs-styles'))
76
- return;
77
- const style = doc.createElement('style');
78
- style.id = 'tfs-styles';
79
- style.textContent = STYLES;
80
- doc.head.prepend(style);
81
- };
@@ -1,148 +0,0 @@
1
- import { Emitter } from '../emitter.ts';
2
- import { Grid, type GridOptions } from '../grid.ts';
3
- import { History } from '../history.ts';
4
- import { TimelineModel } from '../model.ts';
5
- import type { Peaks } from '../peaks.ts';
6
- import { type Source, type TimeRange, type TimelineState, type Track } from '../types.ts';
7
- export interface TimelineOptions {
8
- /** Share a model, for example to drive several views */
9
- model?: TimelineModel;
10
- /** The editor's undo history, when the timeline isn't the only thing in it */
11
- history?: History;
12
- grid?: Partial<GridOptions>;
13
- /** Show bars and beats on the lanes and ruler */
14
- showGrid?: boolean;
15
- /** Zoom, in pixels per second */
16
- pxPerSecond?: number;
17
- minPxPerSecond?: number;
18
- maxPxPerSecond?: number;
19
- trackHeight?: number;
20
- /** Width of the track header column; 0 hides it */
21
- headerWidth?: number;
22
- readonly?: boolean;
23
- /** Snap to other clips' edges and the playhead when grid snapping is off */
24
- snapToClips?: boolean;
25
- /** Scroll to keep the playhead on screen */
26
- follow?: boolean;
27
- /** Handle the editing shortcuts (delete, split, undo…) while the timeline has focus */
28
- keyboard?: boolean;
29
- /** Colours for tracks without their own */
30
- palette?: string[];
31
- /** Fill a track's header cell. Return a function to clean it up. */
32
- renderHeader?: (track: Track, cell: HTMLElement) => void | (() => void);
33
- /** Makes the track a clip lands on when dragged below the last one; leave out to stop at the last */
34
- createTrack?: () => Track;
35
- }
36
- export interface TimelineEvents extends Record<string, unknown> {
37
- change: {
38
- state: TimelineState;
39
- label: string;
40
- final: boolean;
41
- };
42
- select: {
43
- clips: string[];
44
- };
45
- range: {
46
- range: TimeRange | null;
47
- };
48
- seek: {
49
- time: number;
50
- };
51
- zoom: {
52
- pxPerSecond: number;
53
- };
54
- }
55
- /**
56
- * A multitrack timeline: lanes of clips that drag freely by the body, overlap,
57
- * move between lanes, trim, fade, split and snap, with one undo history.
58
- */
59
- export declare class StudioTimeline extends Emitter<TimelineEvents> {
60
- readonly model: TimelineModel;
61
- readonly grid: Grid;
62
- readonly root: HTMLDivElement;
63
- private doc;
64
- private scroller;
65
- private content;
66
- private corner;
67
- private ruler;
68
- private rows;
69
- private overlay;
70
- private playhead;
71
- private rangeEl;
72
- private snapEl;
73
- private trackRows;
74
- private clipViews;
75
- private selected;
76
- private currentRange;
77
- private gesture;
78
- private frame;
79
- private resize?;
80
- private unsubscribe;
81
- private options;
82
- private pps;
83
- private playheadTime;
84
- constructor(container: HTMLElement, options?: TimelineOptions);
85
- get state(): TimelineState;
86
- get history(): History;
87
- get pxPerSecond(): number;
88
- get time(): number;
89
- get selection(): string[];
90
- get range(): TimeRange | null;
91
- /** Replace the tracks and clips without an undo step. */
92
- load(state: TimelineState): void;
93
- /** Tell the timeline a source's length, and its peaks once known. */
94
- setSource(source: Source, peaks?: Peaks): void;
95
- setGrid(options: Partial<GridOptions> & {
96
- show?: boolean;
97
- }): void;
98
- setOptions(options: Partial<Pick<TimelineOptions, 'readonly' | 'follow' | 'snapToClips' | 'trackHeight' | 'keyboard'>>): void;
99
- select(ids: Iterable<string>): void;
100
- setRange(range: TimeRange | null): void;
101
- /** Move the playhead. While following, the view scrolls to keep it in sight. */
102
- setTime(time: number): void;
103
- /** Zoom to a number of pixels per second, keeping `anchor` (a time) still on screen. */
104
- setZoom(pxPerSecond: number, anchor?: number): void;
105
- /** Zoom so every clip fits on screen. */
106
- fit(): void;
107
- /** The timeline time under a point on screen. */
108
- timeAt(clientX: number): number;
109
- undo(): boolean;
110
- redo(): boolean;
111
- /**
112
- * Split the selected clips at a time, or every clip under it when none are
113
- * selected. Only the left pieces stay selected, so the right ones drag alone.
114
- */
115
- split(time?: number): void;
116
- deleteSelected(): void;
117
- duplicateSelected(): void;
118
- /** Move the selected clips by a time and a number of lanes. */
119
- nudge(seconds: number, lanes?: number): void;
120
- destroy(): void;
121
- private schedule;
122
- private render;
123
- private renderTracks;
124
- private fillHeader;
125
- private trackColor;
126
- private renderClips;
127
- /** Draw waveforms for what is on screen. */
128
- private paint;
129
- private renderRuler;
130
- private renderRange;
131
- private placePlayhead;
132
- private listen;
133
- private laneAt;
134
- private onPointerDown;
135
- private onPointerMove;
136
- private dragMove;
137
- private onPointerUp;
138
- private endRange;
139
- private cancelGesture;
140
- private seek;
141
- /** Grid snap when it is on, otherwise a pull towards nearby clip edges and the playhead. */
142
- private snapShift;
143
- private snapTime;
144
- private showSnap;
145
- private autoScroll;
146
- private onWheel;
147
- private onKey;
148
- }