@g9tm/lynxcontrols-studio 0.0.0-stage → 2.8.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.
Files changed (76) hide show
  1. package/README.md +184 -2
  2. package/catalog/cards/G9NleTimeline.md +17 -0
  3. package/catalog/cards/G9Surface.md +16 -0
  4. package/catalog/cards/G9TransformBox.md +17 -0
  5. package/catalog/catalog.json +2255 -0
  6. package/catalog/index.md +7 -0
  7. package/dist/.tsbuildinfo +1 -0
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.jsx +3 -0
  11. package/dist/nle-timeline/core.d.ts +5 -0
  12. package/dist/nle-timeline/core.d.ts.map +1 -0
  13. package/dist/nle-timeline/core.js +4 -0
  14. package/dist/nle-timeline/core.jsx +4 -0
  15. package/dist/nle-timeline/edits.d.ts +65 -0
  16. package/dist/nle-timeline/edits.d.ts.map +1 -0
  17. package/dist/nle-timeline/edits.js +344 -0
  18. package/dist/nle-timeline/edits.js.map +1 -0
  19. package/dist/nle-timeline/edits.jsx +342 -0
  20. package/dist/nle-timeline/engine.d.ts +159 -0
  21. package/dist/nle-timeline/engine.d.ts.map +1 -0
  22. package/dist/nle-timeline/engine.js +899 -0
  23. package/dist/nle-timeline/engine.js.map +1 -0
  24. package/dist/nle-timeline/engine.jsx +897 -0
  25. package/dist/nle-timeline/index.d.ts +6 -0
  26. package/dist/nle-timeline/index.d.ts.map +1 -0
  27. package/dist/nle-timeline/index.jsx +5 -0
  28. package/dist/nle-timeline/layout.d.ts +116 -0
  29. package/dist/nle-timeline/layout.d.ts.map +1 -0
  30. package/dist/nle-timeline/layout.js +310 -0
  31. package/dist/nle-timeline/layout.js.map +1 -0
  32. package/dist/nle-timeline/layout.jsx +308 -0
  33. package/dist/nle-timeline/model.d.ts +140 -0
  34. package/dist/nle-timeline/model.d.ts.map +1 -0
  35. package/dist/nle-timeline/model.js +155 -0
  36. package/dist/nle-timeline/model.js.map +1 -0
  37. package/dist/nle-timeline/model.jsx +153 -0
  38. package/dist/nle-timeline/nle.d.ts +72 -0
  39. package/dist/nle-timeline/nle.d.ts.map +1 -0
  40. package/dist/nle-timeline/nle.jsx +92 -0
  41. package/dist/surface/core.d.ts +2 -0
  42. package/dist/surface/core.d.ts.map +1 -0
  43. package/dist/surface/core.js +1 -0
  44. package/dist/surface/core.jsx +1 -0
  45. package/dist/surface/index.d.ts +3 -0
  46. package/dist/surface/index.d.ts.map +1 -0
  47. package/dist/surface/index.jsx +2 -0
  48. package/dist/surface/protocol.d.ts +40 -0
  49. package/dist/surface/protocol.d.ts.map +1 -0
  50. package/dist/surface/protocol.js +19 -0
  51. package/dist/surface/protocol.js.map +1 -0
  52. package/dist/surface/protocol.jsx +17 -0
  53. package/dist/surface/surface.d.ts +53 -0
  54. package/dist/surface/surface.d.ts.map +1 -0
  55. package/dist/surface/surface.jsx +62 -0
  56. package/dist/transform-box/core.d.ts +3 -0
  57. package/dist/transform-box/core.d.ts.map +1 -0
  58. package/dist/transform-box/core.js +2 -0
  59. package/dist/transform-box/core.jsx +2 -0
  60. package/dist/transform-box/engine.d.ts +152 -0
  61. package/dist/transform-box/engine.d.ts.map +1 -0
  62. package/dist/transform-box/engine.js +636 -0
  63. package/dist/transform-box/engine.js.map +1 -0
  64. package/dist/transform-box/engine.jsx +634 -0
  65. package/dist/transform-box/geometry.d.ts +129 -0
  66. package/dist/transform-box/geometry.d.ts.map +1 -0
  67. package/dist/transform-box/geometry.js +506 -0
  68. package/dist/transform-box/geometry.js.map +1 -0
  69. package/dist/transform-box/geometry.jsx +504 -0
  70. package/dist/transform-box/index.d.ts +4 -0
  71. package/dist/transform-box/index.d.ts.map +1 -0
  72. package/dist/transform-box/index.jsx +3 -0
  73. package/dist/transform-box/transform-box.d.ts +65 -0
  74. package/dist/transform-box/transform-box.d.ts.map +1 -0
  75. package/dist/transform-box/transform-box.jsx +104 -0
  76. package/package.json +56 -4
@@ -0,0 +1,308 @@
1
+ import { laneClips, laneKeys } from "./model.jsx";
2
+ const NLE_METRICS = {
3
+ rulerHeight: 28,
4
+ headWidth: 72,
5
+ edge: 7,
6
+ touchEdge: 16,
7
+ snap: 8
8
+ };
9
+ const LANE_HEIGHT = {
10
+ main: 56,
11
+ free: 40,
12
+ audio: 40,
13
+ keys: 22
14
+ };
15
+ function layoutLanes(doc, metrics = NLE_METRICS) {
16
+ const lanes = [];
17
+ let y = metrics.rulerHeight;
18
+ for (const lane of doc.lanes){
19
+ var _lane_height;
20
+ if (lane.hidden) continue;
21
+ const h = null != (_lane_height = lane.height) ? _lane_height : LANE_HEIGHT[lane.kind];
22
+ lanes.push({
23
+ lane,
24
+ y,
25
+ h
26
+ });
27
+ y += h;
28
+ }
29
+ return {
30
+ lanes,
31
+ total: y - metrics.rulerHeight
32
+ };
33
+ }
34
+ function trackSpan(vp, metrics = NLE_METRICS) {
35
+ return 'rtl' === vp.dir ? [
36
+ 0,
37
+ vp.width - metrics.headWidth
38
+ ] : [
39
+ metrics.headWidth,
40
+ vp.width
41
+ ];
42
+ }
43
+ function xOf(t, vp, metrics = NLE_METRICS) {
44
+ return trackSpan(vp, metrics)[0] + (t - vp.scroll) * vp.zoom;
45
+ }
46
+ function timeOf(x, vp, metrics = NLE_METRICS) {
47
+ return vp.scroll + (x - trackSpan(vp, metrics)[0]) / vp.zoom;
48
+ }
49
+ function visibleTimes(vp, metrics = NLE_METRICS) {
50
+ const [x0, x1] = trackSpan(vp, metrics);
51
+ return [
52
+ vp.scroll,
53
+ vp.scroll + (x1 - x0) / vp.zoom
54
+ ];
55
+ }
56
+ function laneTop(box, vp) {
57
+ return box.y - vp.scrollY;
58
+ }
59
+ function laneAt(layout, y, vp, metrics = NLE_METRICS) {
60
+ if (y < metrics.rulerHeight) return null;
61
+ const cy = y + vp.scrollY;
62
+ for (const box of layout.lanes)if (cy >= box.y && cy < box.y + box.h) return box;
63
+ return null;
64
+ }
65
+ const maxDurCache = new WeakMap();
66
+ function laneMaxDuration(doc, laneId) {
67
+ let entry = maxDurCache.get(doc);
68
+ if (!entry || entry.version !== doc.version) {
69
+ entry = {
70
+ version: doc.version,
71
+ byLane: new Map()
72
+ };
73
+ maxDurCache.set(doc, entry);
74
+ }
75
+ let max = entry.byLane.get(laneId);
76
+ if (void 0 === max) {
77
+ max = 0;
78
+ for (const clip of laneClips(doc, laneId))max = Math.max(max, clip.duration);
79
+ entry.byLane.set(laneId, max);
80
+ }
81
+ return max;
82
+ }
83
+ function lowerBound(list, t) {
84
+ let lo = 0;
85
+ let hi = list.length;
86
+ while(lo < hi){
87
+ const mid = lo + hi >> 1;
88
+ if (list[mid].start < t) lo = mid + 1;
89
+ else hi = mid;
90
+ }
91
+ return lo;
92
+ }
93
+ function clipsInWindow(doc, laneId, t0, t1, out = []) {
94
+ const list = laneClips(doc, laneId);
95
+ const from = lowerBound(list, t0 - laneMaxDuration(doc, laneId));
96
+ for(let i = from; i < list.length; i++){
97
+ const clip = list[i];
98
+ if (clip.start > t1) break;
99
+ if (clip.start + clip.duration >= t0) out.push(clip);
100
+ }
101
+ return out;
102
+ }
103
+ function keysInWindow(doc, laneId, t0, t1, out = []) {
104
+ const list = laneKeys(doc, laneId);
105
+ let lo = 0;
106
+ let hi = list.length;
107
+ while(lo < hi){
108
+ const mid = lo + hi >> 1;
109
+ if (list[mid].time < t0) lo = mid + 1;
110
+ else hi = mid;
111
+ }
112
+ for(let i = lo; i < list.length; i++){
113
+ const key = list[i];
114
+ if (key.time > t1) break;
115
+ out.push(key);
116
+ }
117
+ return out;
118
+ }
119
+ function hitTest(doc, layout, vp, x, y, edge, metrics = NLE_METRICS) {
120
+ const [x0, x1] = trackSpan(vp, metrics);
121
+ if (x < x0 || x >= x1) return {
122
+ kind: 'head',
123
+ lane: laneAt(layout, y, vp, metrics)
124
+ };
125
+ const time = timeOf(x, vp, metrics);
126
+ if (y < metrics.rulerHeight) return {
127
+ kind: 'ruler',
128
+ time
129
+ };
130
+ const lane = laneAt(layout, y, vp, metrics);
131
+ if (!lane) return {
132
+ kind: 'lane',
133
+ lane: layout.lanes[layout.lanes.length - 1],
134
+ time
135
+ };
136
+ if ('keys' === lane.lane.kind) {
137
+ const near = edge / vp.zoom + 4 / vp.zoom;
138
+ let best = null;
139
+ for (const key of keysInWindow(doc, lane.lane.id, time - near, time + near))if (!best || Math.abs(key.time - time) < Math.abs(best.time - time)) best = key;
140
+ return best ? {
141
+ kind: 'key',
142
+ key: best,
143
+ lane
144
+ } : {
145
+ kind: 'lane',
146
+ lane,
147
+ time
148
+ };
149
+ }
150
+ const pad = edge / vp.zoom;
151
+ const found = clipsInWindow(doc, lane.lane.id, time - pad, time + pad);
152
+ let body = null;
153
+ for (const clip of found)if (time >= clip.start && time <= clip.start + clip.duration) body = clip;
154
+ if (body) {
155
+ const w = body.duration * vp.zoom;
156
+ const sx = xOf(body.start, vp, metrics);
157
+ const ex = sx + w;
158
+ const reach = Math.min(edge, w / 3);
159
+ if (x - sx <= reach) return {
160
+ kind: 'clip',
161
+ clip: body,
162
+ part: 'start',
163
+ lane
164
+ };
165
+ if (ex - x <= reach) return {
166
+ kind: 'clip',
167
+ clip: body,
168
+ part: 'end',
169
+ lane
170
+ };
171
+ return {
172
+ kind: 'clip',
173
+ clip: body,
174
+ part: 'body',
175
+ lane
176
+ };
177
+ }
178
+ for (const clip of found){
179
+ const sx = xOf(clip.start, vp, metrics);
180
+ const ex = xOf(clip.start + clip.duration, vp, metrics);
181
+ if (Math.abs(x - sx) <= edge) return {
182
+ kind: 'clip',
183
+ clip,
184
+ part: 'start',
185
+ lane
186
+ };
187
+ if (Math.abs(x - ex) <= edge) return {
188
+ kind: 'clip',
189
+ clip,
190
+ part: 'end',
191
+ lane
192
+ };
193
+ }
194
+ return {
195
+ kind: 'lane',
196
+ lane,
197
+ time
198
+ };
199
+ }
200
+ const STEPS = [
201
+ 0.1,
202
+ 0.2,
203
+ 0.5,
204
+ 1,
205
+ 2,
206
+ 5,
207
+ 10,
208
+ 15,
209
+ 30,
210
+ 60,
211
+ 120,
212
+ 300,
213
+ 600,
214
+ 900,
215
+ 1800,
216
+ 3600
217
+ ];
218
+ function rulerStep(zoom, fps, minPx = 72) {
219
+ const frame = fps > 0 ? 1 / fps : 0;
220
+ if (frame && frame * zoom >= minPx) return {
221
+ major: frame,
222
+ minor: frame
223
+ };
224
+ for (const step of STEPS)if (step * zoom >= minPx) {
225
+ const minor = step >= 60 ? step / 6 : step >= 10 ? step / 5 : step >= 1 ? step / (2 === step ? 4 : 5) : step / 2;
226
+ return {
227
+ major: step,
228
+ minor: frame && minor < frame ? frame : minor
229
+ };
230
+ }
231
+ return {
232
+ major: 7200,
233
+ minor: 1200
234
+ };
235
+ }
236
+ function pad2(n) {
237
+ return n < 10 ? `0${n}` : `${n}`;
238
+ }
239
+ function formatTime(t, step, fps) {
240
+ const sign = t < 0 ? '-' : '';
241
+ const abs = Math.abs(t) + 1e-6;
242
+ const total = Math.floor(abs);
243
+ const h = Math.floor(total / 3600);
244
+ const m = Math.floor(total % 3600 / 60);
245
+ const s = total % 60;
246
+ const base = h > 0 ? `${h}:${pad2(m)}:${pad2(s)}` : `${m}:${pad2(s)}`;
247
+ if (fps > 0 && step < 0.1 - 1e-9) return `${sign}${base}:${pad2(Math.floor((abs - total) * fps))}`;
248
+ if (step < 1 - 1e-9) return `${sign}${base}.${Math.floor((abs - total) * 10)}`;
249
+ return `${sign}${base}`;
250
+ }
251
+ function sortedUnique(times) {
252
+ times.sort((a, b)=>a - b);
253
+ const out = [];
254
+ for (const t of times)if (!out.length || Math.abs(out[out.length - 1] - t) > 1e-6) out.push(t);
255
+ return out;
256
+ }
257
+ function snapTargets(doc, exclude, opts = {}) {
258
+ const times = [
259
+ 0
260
+ ];
261
+ if (false !== opts.playhead) times.push(doc.playhead);
262
+ if (false !== opts.edges) {
263
+ for (const clip of doc.clips.values())if (!exclude.has(clip.id)) times.push(clip.start, clip.start + clip.duration);
264
+ }
265
+ if (false !== opts.beats) for (const b of doc.beats)times.push(b);
266
+ if (false !== opts.markers) for (const m of doc.markers)times.push(m.time);
267
+ if (false !== opts.range && doc.range) times.push(doc.range.start, doc.range.end);
268
+ if (doc.duration > 0) times.push(doc.duration);
269
+ return sortedUnique(times);
270
+ }
271
+ function nearest(targets, t, within) {
272
+ let lo = 0;
273
+ let hi = targets.length;
274
+ while(lo < hi){
275
+ const mid = lo + hi >> 1;
276
+ if (targets[mid] < t) lo = mid + 1;
277
+ else hi = mid;
278
+ }
279
+ let best = null;
280
+ for (const i of [
281
+ lo - 1,
282
+ lo
283
+ ]){
284
+ const v = targets[i];
285
+ if (void 0 !== v) {
286
+ if (Math.abs(v - t) <= within && (null === best || Math.abs(v - t) < Math.abs(best - t))) best = v;
287
+ }
288
+ }
289
+ return best;
290
+ }
291
+ function zoomLimits(vp, contentEnd, metrics = NLE_METRICS) {
292
+ const [x0, x1] = trackSpan(vp, metrics);
293
+ const span = Math.max(1, x1 - x0);
294
+ const min = Math.min(span / Math.max(1, 1.1 * contentEnd), 20);
295
+ return [
296
+ Math.max(0.5, Math.min(min, 2400)),
297
+ 2400
298
+ ];
299
+ }
300
+ function clampScroll(vp, contentEnd, layout, metrics = NLE_METRICS) {
301
+ const [x0, x1] = trackSpan(vp, metrics);
302
+ const visible = (x1 - x0) / vp.zoom;
303
+ const maxScroll = Math.max(0, contentEnd + 0.5 * visible - visible);
304
+ vp.scroll = Math.min(Math.max(vp.scroll, 0), maxScroll);
305
+ const maxY = Math.max(0, layout.total - (vp.height - metrics.rulerHeight));
306
+ vp.scrollY = Math.min(Math.max(vp.scrollY, 0), maxY);
307
+ }
308
+ export { LANE_HEIGHT, NLE_METRICS, clampScroll, clipsInWindow, formatTime, hitTest, keysInWindow, laneAt, laneMaxDuration, laneTop, layoutLanes, lowerBound, nearest, rulerStep, snapTargets, sortedUnique, timeOf, trackSpan, visibleTimes, xOf, zoomLimits };
@@ -0,0 +1,140 @@
1
+ /** `main`: magnetic (clips end to end from 0, no gaps). `free`: clips anywhere. `keys`: keyframe diamonds. `audio`: free, drawn as a waveform. */
2
+ export type NleLaneKind = 'main' | 'free' | 'keys' | 'audio';
3
+ /** A lane: main (magnetic), free, keys or audio. */
4
+ export interface NleLane {
5
+ readonly id: string;
6
+ readonly kind: NleLaneKind;
7
+ readonly label?: string;
8
+ /** CSS px; default by kind (main 56, free 40, audio 40, keys 22). */
9
+ readonly height?: number;
10
+ /** Nothing on it can be moved, trimmed or split. */
11
+ readonly locked?: boolean;
12
+ readonly muted?: boolean;
13
+ readonly hidden?: boolean;
14
+ /** A colour for its clips (any CSS colour). */
15
+ readonly color?: string;
16
+ }
17
+ /** A clip on a lane: its place in time, its source window, its speed, and the keys of its filmstrip and waveform. */
18
+ export interface NleClip {
19
+ readonly id: string;
20
+ readonly lane: string;
21
+ /** Seconds on the timeline. */
22
+ readonly start: number;
23
+ /** Seconds on the timeline. */
24
+ readonly duration: number;
25
+ readonly label?: string;
26
+ readonly color?: string;
27
+ /** Where the clip starts in its source (seconds of source); default 0. */
28
+ readonly sourceIn?: number;
29
+ /** The source's length (seconds); absent = unlimited (a still picture, a generator). Trims stop at it. */
30
+ readonly sourceDuration?: number;
31
+ /** Source seconds per timeline second; default 1. */
32
+ readonly speed?: number;
33
+ /** A key the host's `thumbs` resolver understands (draws a filmstrip). */
34
+ readonly thumbs?: string;
35
+ /** A key the host's `peaks` resolver understands (draws a waveform). */
36
+ readonly peaks?: string;
37
+ /** Width / height of one filmstrip tile; default 16/9. */
38
+ readonly thumbAspect?: number;
39
+ readonly locked?: boolean;
40
+ }
41
+ /** A keyframe on a keys lane. */
42
+ export interface NleKey {
43
+ readonly id: string;
44
+ readonly lane: string;
45
+ readonly time: number;
46
+ }
47
+ /** A named marker on the ruler. */
48
+ export interface NleMarker {
49
+ readonly id: string;
50
+ readonly time: number;
51
+ readonly label?: string;
52
+ readonly color?: string;
53
+ }
54
+ /** A time range (seconds), start before end. */
55
+ export interface NleRange {
56
+ readonly start: number;
57
+ readonly end: number;
58
+ }
59
+ /** A tempo grid: beats every 60 / bpm seconds from `offset`. */
60
+ export interface NleTempo {
61
+ readonly bpm: number;
62
+ readonly offset?: number;
63
+ }
64
+ /** A change of the data (invokeUIMethod `apply`, `port.apply`). Absent fields keep their value. */
65
+ export interface NlePatch {
66
+ /** Empties everything first. */
67
+ readonly reset?: boolean;
68
+ /** The film's length (seconds); the view scrolls to it. */
69
+ readonly duration?: number;
70
+ /** Frames per second: times are rounded to frames (0 = no rounding). Default 30. */
71
+ readonly fps?: number;
72
+ /** The lanes, top to bottom (replaces the list). */
73
+ readonly lanes?: readonly NleLane[];
74
+ /** Added or replaced by id. */
75
+ readonly clips?: readonly NleClip[];
76
+ readonly removeClips?: readonly string[];
77
+ readonly keys?: readonly NleKey[];
78
+ readonly removeKeys?: readonly string[];
79
+ /** Replaces the list. */
80
+ readonly markers?: readonly NleMarker[];
81
+ /** Beat times (seconds), or a tempo. Replaces the grid. */
82
+ readonly beats?: readonly number[] | NleTempo;
83
+ /** Every n-th beat is a bar line. Default 4. */
84
+ readonly beatsPerBar?: number;
85
+ readonly range?: NleRange | null;
86
+ readonly playhead?: number;
87
+ /** Clip and key ids. */
88
+ readonly selection?: readonly string[];
89
+ /** The view: px per second and the time at the track's start edge. */
90
+ readonly view?: {
91
+ readonly zoom?: number;
92
+ readonly scroll?: number;
93
+ };
94
+ }
95
+ /** The timeline's data, with the lane indexes the engine and the hosts read. */
96
+ export interface NleDoc {
97
+ duration: number;
98
+ fps: number;
99
+ lanes: NleLane[];
100
+ readonly clips: Map<string, NleClip>;
101
+ readonly keys: Map<string, NleKey>;
102
+ markers: NleMarker[];
103
+ beats: number[];
104
+ beatsPerBar: number;
105
+ range: NleRange | null;
106
+ playhead: number;
107
+ selection: string[];
108
+ /** Bumped on every change (the renderer's cache key). */
109
+ version: number;
110
+ /** Per-lane clips sorted by start; rebuilt when null. */
111
+ index: Map<string, NleClip[]> | null;
112
+ keyIndex: Map<string, NleKey[]> | null;
113
+ }
114
+ /** The frame rate when the doc gives none. */
115
+ export declare const NLE_DEFAULT_FPS = 30;
116
+ /** An empty timeline doc. */
117
+ export declare function createNleDoc(): NleDoc;
118
+ /** Beat times of a tempo up to `duration` (at most 20,000). */
119
+ export declare function beatsOfTempo(tempo: NleTempo, duration: number): number[];
120
+ /** Applies a patch (mutates `doc`). Returns the view part, which only the element uses. */
121
+ export declare function applyNlePatch(doc: NleDoc, patch: NlePatch): void;
122
+ /** A range with start before end, both at 0 or later. */
123
+ export declare function normRange(range: NleRange): NleRange;
124
+ /** The whole data as one patch (`reset: true`): what the port replays when the element mounts again. */
125
+ export declare function nleSnapshot(doc: NleDoc): NlePatch;
126
+ /** The lane's clips sorted by start (cached until the next clip or lane change). */
127
+ export declare function laneClips(doc: NleDoc, laneId: string): readonly NleClip[];
128
+ /** The keys of a lane by time (indexed once per doc version). */
129
+ export declare function laneKeys(doc: NleDoc, laneId: string): readonly NleKey[];
130
+ /** The lane with an id. */
131
+ export declare function laneById(doc: NleDoc, id: string): NleLane | undefined;
132
+ /** A clip can go from lane `a` to lane `b`: picture lanes (main, free) mix; audio stays audio. */
133
+ export declare function compatible(a: NleLane, b: NleLane): boolean;
134
+ /** The end of the last clip, keys and markers: the content's length. */
135
+ export declare function contentEnd(doc: NleDoc): number;
136
+ /** Rounds to the doc's frames. */
137
+ export declare function quantize(doc: NleDoc, t: number): number;
138
+ /** One frame's length (seconds) at the doc's fps. */
139
+ export declare function frameOf(doc: NleDoc): number;
140
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/nle-timeline/model.ts"],"names":[],"mappings":"AAKA,kJAAkJ;AAClJ,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE7D,oDAAoD;AACpD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC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() {
3
+ return {
4
+ duration: 0,
5
+ fps: NLE_DEFAULT_FPS,
6
+ lanes: [],
7
+ clips: new Map(),
8
+ keys: new Map(),
9
+ markers: [],
10
+ beats: [],
11
+ beatsPerBar: 4,
12
+ range: null,
13
+ playhead: 0,
14
+ selection: [],
15
+ version: 0,
16
+ index: null,
17
+ keyIndex: null
18
+ };
19
+ }
20
+ function beatsOfTempo(tempo, duration) {
21
+ var _tempo_offset, _tempo_offset1;
22
+ const out = [];
23
+ if (!(tempo.bpm > 0)) return out;
24
+ const step = 60 / tempo.bpm;
25
+ const end = Math.max(duration, 0);
26
+ for(let t = null != (_tempo_offset = tempo.offset) ? _tempo_offset : 0, i = 0; t <= end + 1e-9 && i < 20000; i++, t = (null != (_tempo_offset1 = tempo.offset) ? _tempo_offset1 : 0) + i * step)if (t >= 0) out.push(t);
27
+ return out;
28
+ }
29
+ function isTempo(beats) {
30
+ return !Array.isArray(beats) && 'number' == typeof beats.bpm;
31
+ }
32
+ function applyNlePatch(doc, patch) {
33
+ if (patch.reset) {
34
+ doc.duration = 0;
35
+ doc.fps = NLE_DEFAULT_FPS;
36
+ doc.lanes = [];
37
+ doc.clips.clear();
38
+ doc.keys.clear();
39
+ doc.markers = [];
40
+ doc.beats = [];
41
+ doc.beatsPerBar = 4;
42
+ doc.range = null;
43
+ doc.playhead = 0;
44
+ doc.selection = [];
45
+ }
46
+ if (void 0 !== patch.duration) doc.duration = Math.max(0, patch.duration);
47
+ if (void 0 !== patch.fps) doc.fps = Math.max(0, patch.fps);
48
+ if (patch.lanes) doc.lanes = patch.lanes.slice();
49
+ if (patch.clips) for (const clip of patch.clips)doc.clips.set(clip.id, clip);
50
+ if (patch.removeClips) for (const id of patch.removeClips)doc.clips.delete(id);
51
+ if (patch.keys) for (const key of patch.keys)doc.keys.set(key.id, key);
52
+ if (patch.removeKeys) for (const id of patch.removeKeys)doc.keys.delete(id);
53
+ if (patch.markers) doc.markers = patch.markers.slice().sort((a, b)=>a.time - b.time);
54
+ if (void 0 !== patch.beatsPerBar) doc.beatsPerBar = Math.max(1, Math.round(patch.beatsPerBar));
55
+ if (patch.beats) doc.beats = isTempo(patch.beats) ? beatsOfTempo(patch.beats, doc.duration) : patch.beats.slice().sort((a, b)=>a - b);
56
+ if (void 0 !== patch.range) doc.range = patch.range ? normRange(patch.range) : null;
57
+ if (void 0 !== patch.playhead) doc.playhead = Math.max(0, patch.playhead);
58
+ if (patch.selection) doc.selection = patch.selection.slice();
59
+ if (patch.removeClips || patch.removeKeys) {
60
+ var _patch_removeClips, _patch_removeKeys;
61
+ const gone = new Set([
62
+ ...null != (_patch_removeClips = patch.removeClips) ? _patch_removeClips : [],
63
+ ...null != (_patch_removeKeys = patch.removeKeys) ? _patch_removeKeys : []
64
+ ]);
65
+ doc.selection = doc.selection.filter((id)=>!gone.has(id));
66
+ }
67
+ if (patch.reset || patch.clips || patch.removeClips || patch.lanes) doc.index = null;
68
+ if (patch.reset || patch.keys || patch.removeKeys || patch.lanes) doc.keyIndex = null;
69
+ doc.version++;
70
+ }
71
+ function normRange(range) {
72
+ const start = Math.max(0, Math.min(range.start, range.end));
73
+ return {
74
+ start,
75
+ end: Math.max(start, Math.max(range.start, range.end))
76
+ };
77
+ }
78
+ function nleSnapshot(doc) {
79
+ return {
80
+ reset: true,
81
+ duration: doc.duration,
82
+ fps: doc.fps,
83
+ lanes: doc.lanes.slice(),
84
+ clips: [
85
+ ...doc.clips.values()
86
+ ],
87
+ keys: [
88
+ ...doc.keys.values()
89
+ ],
90
+ markers: doc.markers.slice(),
91
+ beats: doc.beats.slice(),
92
+ beatsPerBar: doc.beatsPerBar,
93
+ range: doc.range,
94
+ playhead: doc.playhead,
95
+ selection: doc.selection.slice()
96
+ };
97
+ }
98
+ function laneClips(doc, laneId) {
99
+ var _doc_index_get;
100
+ if (!doc.index) {
101
+ const index = new Map();
102
+ for (const clip of doc.clips.values()){
103
+ let list = index.get(clip.lane);
104
+ if (!list) {
105
+ list = [];
106
+ index.set(clip.lane, list);
107
+ }
108
+ list.push(clip);
109
+ }
110
+ for (const list of index.values())list.sort((a, b)=>a.start - b.start || (a.id < b.id ? -1 : 1));
111
+ doc.index = index;
112
+ }
113
+ return null != (_doc_index_get = doc.index.get(laneId)) ? _doc_index_get : EMPTY;
114
+ }
115
+ function laneKeys(doc, laneId) {
116
+ var _doc_keyIndex_get;
117
+ if (!doc.keyIndex) {
118
+ const index = new Map();
119
+ for (const key of doc.keys.values()){
120
+ let list = index.get(key.lane);
121
+ if (!list) {
122
+ list = [];
123
+ index.set(key.lane, list);
124
+ }
125
+ list.push(key);
126
+ }
127
+ for (const list of index.values())list.sort((a, b)=>a.time - b.time);
128
+ doc.keyIndex = index;
129
+ }
130
+ return null != (_doc_keyIndex_get = doc.keyIndex.get(laneId)) ? _doc_keyIndex_get : EMPTY_KEYS;
131
+ }
132
+ const EMPTY = [];
133
+ const EMPTY_KEYS = [];
134
+ function laneById(doc, id) {
135
+ for (const lane of doc.lanes)if (lane.id === id) return lane;
136
+ }
137
+ function compatible(a, b) {
138
+ if ('keys' === a.kind || 'keys' === b.kind) return false;
139
+ return 'audio' === a.kind === ('audio' === b.kind);
140
+ }
141
+ function contentEnd(doc) {
142
+ let end = doc.duration;
143
+ for (const clip of doc.clips.values())end = Math.max(end, clip.start + clip.duration);
144
+ return end;
145
+ }
146
+ function quantize(doc, t) {
147
+ if (!(doc.fps > 0)) return t;
148
+ return Math.round(t * doc.fps) / doc.fps;
149
+ }
150
+ function frameOf(doc) {
151
+ return doc.fps > 0 ? 1 / doc.fps : 1 / NLE_DEFAULT_FPS;
152
+ }
153
+ export { NLE_DEFAULT_FPS, applyNlePatch, beatsOfTempo, compatible, contentEnd, createNleDoc, frameOf, laneById, laneClips, laneKeys, nleSnapshot, normRange, quantize };
154
+
155
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nle-timeline/model.js","sources":["../../src/nle-timeline/model.ts"],"sourcesContent":["// The timeline's data (G9NleTimeline): lanes, clips, keys, markers, beats, a range, the playhead and the selection.\n// Generic: a clip is a span on a lane with an optional source window; the app gives the meaning. The same `applyNlePatch`\n// runs in the Lynx page (the port's copy, replayed when the element mounts again) and in the host element. Pure\n// TypeScript, no DOM, no Intl (Lynx rules).\n\n/** `main`: magnetic (clips end to end from 0, no gaps). `free`: clips anywhere. `keys`: keyframe diamonds. `audio`: free, drawn as a waveform. */\nexport type NleLaneKind = 'main' | 'free' | 'keys' | 'audio';\n\n/** A lane: main (magnetic), free, keys or audio. */\nexport interface NleLane {\n readonly id: string;\n readonly kind: NleLaneKind;\n readonly label?: string;\n /** CSS px; default by kind (main 56, free 40, audio 40, keys 22). */\n readonly height?: number;\n /** Nothing on it can be moved, trimmed or split. */\n readonly locked?: boolean;\n readonly muted?: boolean;\n readonly hidden?: boolean;\n /** A colour for its clips (any CSS colour). */\n readonly color?: string;\n}\n\n/** A clip on a lane: its place in time, its source window, its speed, and the keys of its filmstrip and waveform. */\nexport interface NleClip {\n readonly id: string;\n readonly lane: string;\n /** Seconds on the timeline. */\n readonly start: number;\n /** Seconds on the timeline. */\n readonly duration: number;\n readonly label?: string;\n readonly color?: string;\n /** Where the clip starts in its source (seconds of source); default 0. */\n readonly sourceIn?: number;\n /** The source's length (seconds); absent = unlimited (a still picture, a generator). Trims stop at it. */\n readonly sourceDuration?: number;\n /** Source seconds per timeline second; default 1. */\n readonly speed?: number;\n /** A key the host's `thumbs` resolver understands (draws a filmstrip). */\n readonly thumbs?: string;\n /** A key the host's `peaks` resolver understands (draws a waveform). */\n readonly peaks?: string;\n /** Width / height of one filmstrip tile; default 16/9. */\n readonly thumbAspect?: number;\n readonly locked?: boolean;\n}\n\n/** A keyframe on a keys lane. */\nexport interface NleKey {\n readonly id: string;\n readonly lane: string;\n readonly time: number;\n}\n\n/** A named marker on the ruler. */\nexport interface NleMarker {\n readonly id: string;\n readonly time: number;\n readonly label?: string;\n readonly color?: string;\n}\n\n/** A time range (seconds), start before end. */\nexport interface NleRange {\n readonly start: number;\n readonly end: number;\n}\n\n/** A tempo grid: beats every 60 / bpm seconds from `offset`. */\nexport interface NleTempo {\n readonly bpm: number;\n readonly offset?: number;\n}\n\n/** A change of the data (invokeUIMethod `apply`, `port.apply`). Absent fields keep their value. */\nexport interface NlePatch {\n /** Empties everything first. */\n readonly reset?: boolean;\n /** The film's length (seconds); the view scrolls to it. */\n readonly duration?: number;\n /** Frames per second: times are rounded to frames (0 = no rounding). Default 30. */\n readonly fps?: number;\n /** The lanes, top to bottom (replaces the list). */\n readonly lanes?: readonly NleLane[];\n /** Added or replaced by id. */\n readonly clips?: readonly NleClip[];\n readonly removeClips?: readonly string[];\n readonly keys?: readonly NleKey[];\n readonly removeKeys?: readonly string[];\n /** Replaces the list. */\n readonly markers?: readonly NleMarker[];\n /** Beat times (seconds), or a tempo. Replaces the grid. */\n readonly beats?: readonly number[] | NleTempo;\n /** Every n-th beat is a bar line. Default 4. */\n readonly beatsPerBar?: number;\n readonly range?: NleRange | null;\n readonly playhead?: number;\n /** Clip and key ids. */\n readonly selection?: readonly string[];\n /** The view: px per second and the time at the track's start edge. */\n readonly view?: { readonly zoom?: number; readonly scroll?: number };\n}\n\n/** The timeline's data, with the lane indexes the engine and the hosts read. */\nexport interface NleDoc {\n duration: number;\n fps: number;\n lanes: NleLane[];\n readonly clips: Map<string, NleClip>;\n readonly keys: Map<string, NleKey>;\n markers: NleMarker[];\n beats: number[];\n beatsPerBar: number;\n range: NleRange | null;\n playhead: number;\n selection: string[];\n /** Bumped on every change (the renderer's cache key). */\n version: number;\n /** Per-lane clips sorted by start; rebuilt when null. */\n index: Map<string, NleClip[]> | null;\n keyIndex: Map<string, NleKey[]> | null;\n}\n\n/** The frame rate when the doc gives none. */\nexport const NLE_DEFAULT_FPS = 30;\n\n/** An empty timeline doc. */\nexport function createNleDoc(): NleDoc {\n return {\n duration: 0,\n fps: NLE_DEFAULT_FPS,\n lanes: [],\n clips: new Map(),\n keys: new Map(),\n markers: [],\n beats: [],\n beatsPerBar: 4,\n range: null,\n playhead: 0,\n selection: [],\n version: 0,\n index: null,\n keyIndex: null,\n };\n}\n\n/** Beat times of a tempo up to `duration` (at most 20,000). */\nexport function beatsOfTempo(tempo: NleTempo, duration: number): number[] {\n const out: number[] = [];\n if (!(tempo.bpm > 0)) return out;\n const step = 60 / tempo.bpm;\n const end = Math.max(duration, 0);\n for (let t = tempo.offset ?? 0, i = 0; t <= end + 1e-9 && i < 20000; i++, t = (tempo.offset ?? 0) + i * step)\n if (t >= 0) out.push(t);\n return out;\n}\n\nfunction isTempo(beats: readonly number[] | NleTempo): beats is NleTempo {\n return !Array.isArray(beats) && typeof (beats as NleTempo).bpm === 'number';\n}\n\n/** Applies a patch (mutates `doc`). Returns the view part, which only the element uses. */\nexport function applyNlePatch(doc: NleDoc, patch: NlePatch): void {\n if (patch.reset) {\n doc.duration = 0;\n doc.fps = NLE_DEFAULT_FPS;\n doc.lanes = [];\n doc.clips.clear();\n doc.keys.clear();\n doc.markers = [];\n doc.beats = [];\n doc.beatsPerBar = 4;\n doc.range = null;\n doc.playhead = 0;\n doc.selection = [];\n }\n if (patch.duration !== undefined) doc.duration = Math.max(0, patch.duration);\n if (patch.fps !== undefined) doc.fps = Math.max(0, patch.fps);\n if (patch.lanes) doc.lanes = patch.lanes.slice();\n if (patch.clips) for (const clip of patch.clips) doc.clips.set(clip.id, clip);\n if (patch.removeClips) for (const id of patch.removeClips) doc.clips.delete(id);\n if (patch.keys) for (const key of patch.keys) doc.keys.set(key.id, key);\n if (patch.removeKeys) for (const id of patch.removeKeys) doc.keys.delete(id);\n if (patch.markers) doc.markers = patch.markers.slice().sort((a, b) => a.time - b.time);\n if (patch.beatsPerBar !== undefined) doc.beatsPerBar = Math.max(1, Math.round(patch.beatsPerBar));\n if (patch.beats)\n doc.beats = isTempo(patch.beats)\n ? beatsOfTempo(patch.beats, doc.duration)\n : patch.beats.slice().sort((a, b) => a - b);\n if (patch.range !== undefined) doc.range = patch.range ? normRange(patch.range) : null;\n if (patch.playhead !== undefined) doc.playhead = Math.max(0, patch.playhead);\n if (patch.selection) doc.selection = patch.selection.slice();\n if (patch.removeClips || patch.removeKeys) {\n const gone = new Set([...(patch.removeClips ?? []), ...(patch.removeKeys ?? [])]);\n doc.selection = doc.selection.filter((id) => !gone.has(id));\n }\n if (patch.reset || patch.clips || patch.removeClips || patch.lanes) doc.index = null;\n if (patch.reset || patch.keys || patch.removeKeys || patch.lanes) doc.keyIndex = null;\n doc.version++;\n}\n\n/** A range with start before end, both at 0 or later. */\nexport function normRange(range: NleRange): NleRange {\n const start = Math.max(0, Math.min(range.start, range.end));\n return { start, end: Math.max(start, Math.max(range.start, range.end)) };\n}\n\n/** The whole data as one patch (`reset: true`): what the port replays when the element mounts again. */\nexport function nleSnapshot(doc: NleDoc): NlePatch {\n return {\n reset: true,\n duration: doc.duration,\n fps: doc.fps,\n lanes: doc.lanes.slice(),\n clips: [...doc.clips.values()],\n keys: [...doc.keys.values()],\n markers: doc.markers.slice(),\n beats: doc.beats.slice(),\n beatsPerBar: doc.beatsPerBar,\n range: doc.range,\n playhead: doc.playhead,\n selection: doc.selection.slice(),\n };\n}\n\n/** The lane's clips sorted by start (cached until the next clip or lane change). */\nexport function laneClips(doc: NleDoc, laneId: string): readonly NleClip[] {\n if (!doc.index) {\n const index = new Map<string, NleClip[]>();\n for (const clip of doc.clips.values()) {\n let list = index.get(clip.lane);\n if (!list) {\n list = [];\n index.set(clip.lane, list);\n }\n list.push(clip);\n }\n for (const list of index.values()) list.sort((a, b) => a.start - b.start || (a.id < b.id ? -1 : 1));\n doc.index = index;\n }\n return doc.index.get(laneId) ?? EMPTY;\n}\n\n/** The keys of a lane by time (indexed once per doc version). */\nexport function laneKeys(doc: NleDoc, laneId: string): readonly NleKey[] {\n if (!doc.keyIndex) {\n const index = new Map<string, NleKey[]>();\n for (const key of doc.keys.values()) {\n let list = index.get(key.lane);\n if (!list) {\n list = [];\n index.set(key.lane, list);\n }\n list.push(key);\n }\n for (const list of index.values()) list.sort((a, b) => a.time - b.time);\n doc.keyIndex = index;\n }\n return doc.keyIndex.get(laneId) ?? EMPTY_KEYS;\n}\n\nconst EMPTY: readonly NleClip[] = [];\nconst EMPTY_KEYS: readonly NleKey[] = [];\n\n/** The lane with an id. */\nexport function laneById(doc: NleDoc, id: string): NleLane | undefined {\n for (const lane of doc.lanes) if (lane.id === id) return lane;\n return undefined;\n}\n\n/** A clip can go from lane `a` to lane `b`: picture lanes (main, free) mix; audio stays audio. */\nexport function compatible(a: NleLane, b: NleLane): boolean {\n if (a.kind === 'keys' || b.kind === 'keys') return false;\n return (a.kind === 'audio') === (b.kind === 'audio');\n}\n\n/** The end of the last clip, keys and markers: the content's length. */\nexport function contentEnd(doc: NleDoc): number {\n let end = doc.duration;\n for (const clip of doc.clips.values()) end = Math.max(end, clip.start + clip.duration);\n return end;\n}\n\n/** Rounds to the doc's frames. */\nexport function quantize(doc: NleDoc, t: number): number {\n if (!(doc.fps > 0)) return t;\n return Math.round(t * doc.fps) / doc.fps;\n}\n\n/** One frame's length (seconds) at the doc's fps. */\nexport function frameOf(doc: NleDoc): number {\n return doc.fps > 0 ? 1 / doc.fps : 1 / NLE_DEFAULT_FPS;\n}\n"],"names":["NLE_DEFAULT_FPS","createNleDoc","Map","beatsOfTempo","tempo","duration","_tempo_offset","_tempo_offset1","out","step","end","Math","t","i","isTempo","beats","Array","applyNlePatch","doc","patch","undefined","clip","id","key","a","b","normRange","_patch_removeClips","_patch_removeKeys","gone","Set","range","start","nleSnapshot","laneClips","laneId","_doc_index_get","index","list","EMPTY","laneKeys","_doc_keyIndex_get","EMPTY_KEYS","laneById","lane","compatible","contentEnd","quantize","frameOf"],"mappings":"AA6HO,MAAMA,kBAAkB;AAGxB,SAASC;IACd,OAAO;QACL,UAAU;QACV,KAAKD;QACL,OAAO,EAAE;QACT,OAAO,IAAIE;QACX,MAAM,IAAIA;QACV,SAAS,EAAE;QACX,OAAO,EAAE;QACT,aAAa;QACb,OAAO;QACP,UAAU;QACV,W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