@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,897 @@
1
+ import { commit, computeLaneStep, computeMove, computeNudge, computeTrim, differing, splitTargets, trimToTime } from "./edits.jsx";
2
+ import { NLE_METRICS, clampScroll, hitTest, layoutLanes, nearest, snapTargets, timeOf, trackSpan, visibleTimes, xOf, zoomLimits } from "./layout.jsx";
3
+ import { applyNlePatch, contentEnd, createNleDoc, frameOf, laneById, laneClips, normRange, quantize } from "./model.jsx";
4
+ function _define_property(obj, key, value) {
5
+ if (key in obj) Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ else obj[key] = value;
12
+ return obj;
13
+ }
14
+ const NLE_KEYS = [
15
+ [
16
+ '← →',
17
+ 'playhead one frame (shift: one second)'
18
+ ],
19
+ [
20
+ 'alt+← → , .',
21
+ 'nudge the selection one frame (shift: ten); a main clip swaps with its neighbour'
22
+ ],
23
+ [
24
+ 'alt+↑ ↓',
25
+ 'move the selected clip to the lane above / below'
26
+ ],
27
+ [
28
+ '↑ ↓',
29
+ 'select the clip under the playhead in the lane above / below'
30
+ ],
31
+ [
32
+ 'tab / shift+tab',
33
+ 'select the next / previous clip'
34
+ ],
35
+ [
36
+ 's, ctrl+b',
37
+ 'split at the playhead'
38
+ ],
39
+ [
40
+ '[ ]',
41
+ 'trim the selected clip’s start / end to the playhead'
42
+ ],
43
+ [
44
+ 'delete, backspace',
45
+ 'delete (the main lane closes the gap)'
46
+ ],
47
+ [
48
+ 'insert, n',
49
+ 'ask to add at the playhead'
50
+ ],
51
+ [
52
+ 'i o, alt+x',
53
+ 'range in / out, clear'
54
+ ],
55
+ [
56
+ '= -, shift+z',
57
+ 'zoom in / out, fit'
58
+ ],
59
+ [
60
+ 'home end',
61
+ 'playhead to the start / end'
62
+ ],
63
+ [
64
+ 'm',
65
+ 'ask for a marker at the playhead'
66
+ ],
67
+ [
68
+ 'ctrl+z, ctrl+shift+z, ctrl+y',
69
+ 'undo, redo (asked of the app)'
70
+ ],
71
+ [
72
+ 'ctrl+d, ctrl+c, ctrl+v',
73
+ 'duplicate, copy, paste (asked of the app)'
74
+ ],
75
+ [
76
+ 'escape',
77
+ 'clear the selection'
78
+ ]
79
+ ];
80
+ const MOVE_SLOP = 4;
81
+ const DOUBLE_MS = 350;
82
+ class NleEngine {
83
+ apply(patch) {
84
+ var _patch_view, _patch_view1;
85
+ applyNlePatch(this.doc, patch);
86
+ if ((null == (_patch_view = patch.view) ? void 0 : _patch_view.zoom) !== void 0) this.vp.zoom = patch.view.zoom;
87
+ if ((null == (_patch_view1 = patch.view) ? void 0 : _patch_view1.scroll) !== void 0) this.vp.scroll = patch.view.scroll;
88
+ if (patch.view) this.fitted = true;
89
+ if (!this.drag) this.overlay = {
90
+ preview: null,
91
+ keyPreview: null,
92
+ snap: null,
93
+ dropLane: null
94
+ };
95
+ this.relayout();
96
+ if (!this.fitted && this.vp.width > 0 && contentEnd(this.doc) > 0) this.fit(false);
97
+ this.invalidate();
98
+ }
99
+ resize(width, height) {
100
+ this.vp.width = width;
101
+ this.vp.height = height;
102
+ if (!this.fitted && width > 0 && contentEnd(this.doc) > 0) this.fit(false);
103
+ this.clamp();
104
+ this.invalidate();
105
+ }
106
+ setDirection(dir) {
107
+ this.vp.dir = dir;
108
+ this.invalidate();
109
+ }
110
+ relayout() {
111
+ if (this.layoutVersion === this.doc.version) return;
112
+ this.layout = layoutLanes(this.doc, this.metrics);
113
+ this.layoutVersion = this.doc.version;
114
+ }
115
+ fit(announce = true) {
116
+ const end = contentEnd(this.doc);
117
+ const [x0, x1] = trackSpan(this.vp, this.metrics);
118
+ if (x1 - x0 <= 0 || end <= 0) return;
119
+ this.vp.zoom = (x1 - x0) / (1.05 * end);
120
+ this.vp.scroll = 0;
121
+ this.fitted = true;
122
+ this.clamp();
123
+ if (announce) this.announceView();
124
+ this.invalidate();
125
+ }
126
+ zoomAt(factor, x) {
127
+ const t = timeOf(x, this.vp, this.metrics);
128
+ const [min, max] = zoomLimits(this.vp, contentEnd(this.doc), this.metrics);
129
+ this.vp.zoom = Math.min(max, Math.max(min, this.vp.zoom * factor));
130
+ this.vp.scroll = t - (x - trackSpan(this.vp, this.metrics)[0]) / this.vp.zoom;
131
+ this.fitted = true;
132
+ this.clamp();
133
+ this.announceView();
134
+ this.invalidate();
135
+ }
136
+ scrollBy(dxPx, dyPx) {
137
+ this.vp.scroll += dxPx / this.vp.zoom;
138
+ this.vp.scrollY += dyPx;
139
+ this.clamp();
140
+ this.announceView();
141
+ this.invalidate();
142
+ }
143
+ clamp() {
144
+ this.relayout();
145
+ clampScroll(this.vp, contentEnd(this.doc), this.layout, this.metrics);
146
+ }
147
+ announceView() {
148
+ this.emit('nleview', {
149
+ zoom: this.vp.zoom,
150
+ scroll: this.vp.scroll,
151
+ scrollY: this.vp.scrollY
152
+ });
153
+ }
154
+ select(ids) {
155
+ const same = ids.length === this.doc.selection.length && ids.every((id, i)=>this.doc.selection[i] === id);
156
+ if (same) return;
157
+ this.doc.selection = ids;
158
+ this.doc.version++;
159
+ this.emit('nleselect', {
160
+ ids: ids.slice()
161
+ });
162
+ this.invalidate();
163
+ }
164
+ seek(time, scrubbing) {
165
+ const t = quantize(this.doc, Math.max(0, Math.min(time, Math.max(contentEnd(this.doc), this.doc.duration))));
166
+ this.doc.playhead = t;
167
+ this.doc.version++;
168
+ this.emit('nleseek', {
169
+ time: t,
170
+ scrubbing
171
+ });
172
+ this.reveal(t);
173
+ this.invalidate();
174
+ }
175
+ reveal(t) {
176
+ const [t0, t1] = visibleTimes(this.vp, this.metrics);
177
+ const margin = (t1 - t0) * 0.05;
178
+ if (t < t0) this.vp.scroll = Math.max(0, t - margin);
179
+ else {
180
+ if (!(t > t1)) return;
181
+ this.vp.scroll = t - (t1 - t0) + margin;
182
+ }
183
+ this.clamp();
184
+ this.announceView();
185
+ }
186
+ setRange(range) {
187
+ this.doc.range = range ? normRange(range) : null;
188
+ this.doc.version++;
189
+ this.emit('nlerange', {
190
+ range: this.doc.range
191
+ });
192
+ this.invalidate();
193
+ }
194
+ edgeFor(p) {
195
+ return 'touch' === p.type ? this.metrics.touchEdge : this.metrics.edge;
196
+ }
197
+ within() {
198
+ return this.metrics.snap / this.vp.zoom;
199
+ }
200
+ pointerDown(p) {
201
+ this.relayout();
202
+ this.pointers.set(p.id, p);
203
+ if (2 === this.pointers.size && [
204
+ ...this.pointers.values()
205
+ ].every((q)=>'touch' === q.type)) {
206
+ this.overlay = {
207
+ preview: null,
208
+ keyPreview: null,
209
+ snap: null,
210
+ dropLane: null
211
+ };
212
+ const [a, b] = [
213
+ ...this.pointers.values()
214
+ ];
215
+ const mid = (a.x + b.x) / 2;
216
+ this.drag = {
217
+ kind: 'pinch',
218
+ ids: [
219
+ a.id,
220
+ b.id
221
+ ],
222
+ dist: Math.max(10, Math.abs(a.x - b.x)),
223
+ zoom: this.vp.zoom,
224
+ time: timeOf(mid, this.vp, this.metrics)
225
+ };
226
+ this.invalidate();
227
+ return;
228
+ }
229
+ if (this.pointers.size > 1) return;
230
+ const hit = hitTest(this.doc, this.layout, this.vp, p.x, p.y, this.edgeFor(p), this.metrics);
231
+ const additive = Boolean(p.ctrl || p.shift);
232
+ if ('ruler' === hit.kind) {
233
+ const range = this.doc.range;
234
+ const reach = this.edgeFor(p);
235
+ if (range && Math.abs(xOf(range.start, this.vp, this.metrics) - p.x) <= reach) {
236
+ this.drag = {
237
+ kind: 'range',
238
+ anchor: range.end,
239
+ edge: 'start'
240
+ };
241
+ return;
242
+ }
243
+ if (range && Math.abs(xOf(range.end, this.vp, this.metrics) - p.x) <= reach) {
244
+ this.drag = {
245
+ kind: 'range',
246
+ anchor: range.start,
247
+ edge: 'end'
248
+ };
249
+ return;
250
+ }
251
+ if (p.shift || p.alt) {
252
+ const t = this.snapped(hit.time, new Set());
253
+ this.drag = {
254
+ kind: 'range',
255
+ anchor: t,
256
+ edge: 'new'
257
+ };
258
+ this.setRange({
259
+ start: t,
260
+ end: t
261
+ });
262
+ return;
263
+ }
264
+ this.drag = {
265
+ kind: 'scrub'
266
+ };
267
+ this.seek(this.snapped(hit.time, new Set()), true);
268
+ return;
269
+ }
270
+ if ('head' === hit.kind) return;
271
+ if ('clip' === hit.kind && this.editable && ('blade' === this.tool || p.alt)) {
272
+ if (hit.clip.locked || hit.lane.lane.locked) return;
273
+ const t = quantize(this.doc, this.snapped(timeOf(p.x, this.vp, this.metrics), new Set([
274
+ hit.clip.id
275
+ ])));
276
+ if (t > hit.clip.start && t < hit.clip.start + hit.clip.duration) this.emit('nleedit', {
277
+ op: 'split',
278
+ via: 'pointer',
279
+ splits: [
280
+ {
281
+ id: hit.clip.id,
282
+ time: t
283
+ }
284
+ ]
285
+ });
286
+ return;
287
+ }
288
+ this.drag = {
289
+ kind: 'pending',
290
+ hit,
291
+ x: p.x,
292
+ y: p.y,
293
+ pointer: p,
294
+ additive
295
+ };
296
+ }
297
+ pointerMove(p) {
298
+ if (!this.pointers.has(p.id)) return;
299
+ this.pointers.set(p.id, p);
300
+ const drag = this.drag;
301
+ if (!drag) return;
302
+ if ('pinch' === drag.kind) {
303
+ const a = this.pointers.get(drag.ids[0]);
304
+ const b = this.pointers.get(drag.ids[1]);
305
+ if (!a || !b) return;
306
+ const dist = Math.max(10, Math.abs(a.x - b.x));
307
+ const mid = (a.x + b.x) / 2;
308
+ const [min, max] = zoomLimits(this.vp, contentEnd(this.doc), this.metrics);
309
+ this.vp.zoom = Math.min(max, Math.max(min, drag.zoom * dist / drag.dist));
310
+ this.vp.scroll = drag.time - (mid - trackSpan(this.vp, this.metrics)[0]) / this.vp.zoom;
311
+ this.fitted = true;
312
+ this.clamp();
313
+ this.announceView();
314
+ this.invalidate();
315
+ return;
316
+ }
317
+ if ('pending' === drag.kind) {
318
+ if (Math.abs(p.x - drag.x) < MOVE_SLOP && Math.abs(p.y - drag.y) < MOVE_SLOP) return;
319
+ this.startDrag(drag, p);
320
+ this.pointerMove(p);
321
+ return;
322
+ }
323
+ if ('scrub' === drag.kind) return void this.seek(this.snapped(timeOf(p.x, this.vp, this.metrics), new Set()), true);
324
+ if ('range' === drag.kind) {
325
+ const t = this.snapped(timeOf(p.x, this.vp, this.metrics), new Set());
326
+ this.setRange({
327
+ start: drag.anchor,
328
+ end: t
329
+ });
330
+ return;
331
+ }
332
+ if ('pan' === drag.kind) {
333
+ this.vp.scroll = drag.scroll - (p.x - drag.x) / this.vp.zoom;
334
+ this.vp.scrollY = drag.scrollY - (p.y - drag.y);
335
+ this.clamp();
336
+ this.announceView();
337
+ this.invalidate();
338
+ return;
339
+ }
340
+ const dt = (p.x - drag.x0) / this.vp.zoom;
341
+ if ('move' === drag.kind) {
342
+ var _ref;
343
+ const box = this.laneUnder(p.y);
344
+ drag.lane = null != box ? box : drag.lane;
345
+ drag.result = computeMove(this.doc, {
346
+ lead: drag.lead,
347
+ ids: drag.ids,
348
+ dt,
349
+ lane: drag.lane,
350
+ targets: this.snapping ? snapTargets(this.doc, new Set(drag.ids)) : null,
351
+ within: this.within()
352
+ });
353
+ const lead = drag.result.changes.get(drag.lead);
354
+ this.overlay = {
355
+ preview: drag.result.changes,
356
+ keyPreview: null,
357
+ snap: drag.result.snap,
358
+ dropLane: null != (_ref = null == lead ? void 0 : lead.lane) ? _ref : null
359
+ };
360
+ } else if ('trim' === drag.kind) {
361
+ drag.result = computeTrim(this.doc, {
362
+ id: drag.id,
363
+ edge: drag.edge,
364
+ dt,
365
+ targets: this.snapping ? snapTargets(this.doc, new Set([
366
+ drag.id
367
+ ])) : null,
368
+ within: this.within()
369
+ });
370
+ this.overlay = {
371
+ preview: drag.result.changes,
372
+ keyPreview: null,
373
+ snap: drag.result.snap,
374
+ dropLane: null
375
+ };
376
+ } else if ('keys' === drag.kind) {
377
+ drag.times = new Map();
378
+ let shift = dt;
379
+ drag.snap = null;
380
+ const lead = this.doc.keys.get(drag.ids[0]);
381
+ if (lead && this.snapping) {
382
+ const t = nearest(snapTargets(this.doc, new Set()), lead.time + dt, this.within());
383
+ if (null !== t) {
384
+ shift = t - lead.time;
385
+ drag.snap = t;
386
+ }
387
+ }
388
+ for (const id of drag.ids){
389
+ const key = this.doc.keys.get(id);
390
+ if (key) drag.times.set(id, quantize(this.doc, Math.max(0, key.time + shift)));
391
+ }
392
+ this.overlay = {
393
+ preview: null,
394
+ keyPreview: drag.times,
395
+ snap: drag.snap,
396
+ dropLane: null
397
+ };
398
+ }
399
+ this.autoScroll(p.x);
400
+ this.invalidate();
401
+ }
402
+ pointerUp(p) {
403
+ this.pointers.delete(p.id);
404
+ const drag = this.drag;
405
+ if ((null == drag ? void 0 : drag.kind) === 'pinch') {
406
+ if (0 === this.pointers.size) this.drag = null;
407
+ return;
408
+ }
409
+ this.drag = null;
410
+ if (!drag) return;
411
+ if ('pending' === drag.kind) return void this.tap(drag, p);
412
+ if ('scrub' === drag.kind) return void this.emit('nleseek', {
413
+ time: this.doc.playhead,
414
+ scrubbing: false
415
+ });
416
+ if ('move' === drag.kind || 'trim' === drag.kind) {
417
+ const changes = differing(this.doc, drag.result.changes);
418
+ this.overlay = {
419
+ preview: null,
420
+ keyPreview: null,
421
+ snap: null,
422
+ dropLane: null
423
+ };
424
+ if (changes.length) {
425
+ commit(this.doc, changes);
426
+ this.relayout();
427
+ this.emit('nleedit', {
428
+ op: drag.kind,
429
+ via: 'pointer',
430
+ changes
431
+ });
432
+ }
433
+ this.invalidate();
434
+ return;
435
+ }
436
+ if ('keys' === drag.kind) {
437
+ const keys = [];
438
+ for (const [id, time] of drag.times){
439
+ const key = this.doc.keys.get(id);
440
+ if (key && Math.abs(key.time - time) > 1e-6) keys.push({
441
+ id,
442
+ time
443
+ });
444
+ }
445
+ this.overlay = {
446
+ preview: null,
447
+ keyPreview: null,
448
+ snap: null,
449
+ dropLane: null
450
+ };
451
+ if (keys.length) this.commitKeys(keys, 'pointer');
452
+ this.invalidate();
453
+ }
454
+ }
455
+ pointerCancel(p) {
456
+ this.pointers.delete(p.id);
457
+ this.drag = null;
458
+ this.overlay = {
459
+ preview: null,
460
+ keyPreview: null,
461
+ snap: null,
462
+ dropLane: null
463
+ };
464
+ this.invalidate();
465
+ }
466
+ autoScroll(x) {
467
+ const [x0, x1] = trackSpan(this.vp, this.metrics);
468
+ const band = 24;
469
+ if (x < x0 + band) this.scrollBy(-Math.min(12, x0 + band - x), 0);
470
+ else if (x > x1 - band) this.scrollBy(Math.min(12, x - (x1 - band)), 0);
471
+ }
472
+ cursorAt(x, y) {
473
+ this.relayout();
474
+ const hit = hitTest(this.doc, this.layout, this.vp, x, y, this.metrics.edge, this.metrics);
475
+ if ('ruler' === hit.kind) return 'text';
476
+ if ('clip' === hit.kind) {
477
+ if ('blade' === this.tool) return 'crosshair';
478
+ return 'body' === hit.part ? 'grab' : 'ew-resize';
479
+ }
480
+ if ('key' === hit.kind) return 'pointer';
481
+ return 'default';
482
+ }
483
+ laneUnder(y) {
484
+ const cy = y + this.vp.scrollY;
485
+ for (const box of this.layout.lanes)if (cy >= box.y && cy < box.y + box.h) return box.lane.id;
486
+ return null;
487
+ }
488
+ snapped(t, exclude) {
489
+ var _nearest;
490
+ if (!this.snapping) return t;
491
+ return null != (_nearest = nearest(snapTargets(this.doc, exclude, {
492
+ playhead: false
493
+ }), t, this.within())) ? _nearest : t;
494
+ }
495
+ startDrag(pending, p) {
496
+ const hit = pending.hit;
497
+ const touch = 'touch' === pending.pointer.type;
498
+ if ('clip' === hit.kind && this.editable) {
499
+ const lane = laneById(this.doc, hit.clip.lane);
500
+ const fixed = hit.clip.locked || (null == lane ? void 0 : lane.locked);
501
+ const selected = this.doc.selection.includes(hit.clip.id);
502
+ if (!fixed && (!touch || selected || 'body' !== hit.part)) {
503
+ if ('body' !== hit.part) {
504
+ this.select([
505
+ hit.clip.id
506
+ ]);
507
+ this.drag = {
508
+ kind: 'trim',
509
+ id: hit.clip.id,
510
+ edge: hit.part,
511
+ x0: pending.x,
512
+ result: {
513
+ changes: new Map(),
514
+ snap: null
515
+ }
516
+ };
517
+ return;
518
+ }
519
+ if (!selected) this.select(pending.additive ? [
520
+ ...this.doc.selection,
521
+ hit.clip.id
522
+ ] : [
523
+ hit.clip.id
524
+ ]);
525
+ const ids = this.doc.selection.filter((id)=>this.doc.clips.has(id));
526
+ this.drag = {
527
+ kind: 'move',
528
+ lead: hit.clip.id,
529
+ ids,
530
+ x0: pending.x,
531
+ result: {
532
+ changes: new Map(),
533
+ snap: null
534
+ },
535
+ lane: hit.clip.lane
536
+ };
537
+ return;
538
+ }
539
+ }
540
+ if ('key' === hit.kind && this.editable && !hit.lane.lane.locked && (!touch || this.doc.selection.includes(hit.key.id))) {
541
+ if (!this.doc.selection.includes(hit.key.id)) this.select([
542
+ hit.key.id
543
+ ]);
544
+ const ids = this.doc.selection.filter((id)=>this.doc.keys.has(id));
545
+ this.drag = {
546
+ kind: 'keys',
547
+ ids,
548
+ x0: pending.x,
549
+ times: new Map(),
550
+ snap: null
551
+ };
552
+ return;
553
+ }
554
+ this.drag = {
555
+ kind: 'pan',
556
+ x: pending.x,
557
+ y: pending.y,
558
+ scroll: this.vp.scroll,
559
+ scrollY: this.vp.scrollY
560
+ };
561
+ }
562
+ tap(pending, p) {
563
+ const hit = pending.hit;
564
+ const double = null !== this.lastTap && p.time - this.lastTap.time < DOUBLE_MS && Math.abs(p.x - this.lastTap.x) < 12 && Math.abs(p.y - this.lastTap.y) < 12;
565
+ this.lastTap = double ? null : {
566
+ x: p.x,
567
+ y: p.y,
568
+ time: p.time
569
+ };
570
+ if ('clip' === hit.kind) {
571
+ const id = hit.clip.id;
572
+ if (double) return void this.emit('nleopen', {
573
+ id
574
+ });
575
+ if (pending.additive) this.select(this.doc.selection.includes(id) ? this.doc.selection.filter((x)=>x !== id) : [
576
+ ...this.doc.selection,
577
+ id
578
+ ]);
579
+ else this.select([
580
+ id
581
+ ]);
582
+ return;
583
+ }
584
+ if ('key' === hit.kind) {
585
+ const id = hit.key.id;
586
+ this.select(pending.additive ? [
587
+ ...this.doc.selection,
588
+ id
589
+ ] : [
590
+ id
591
+ ]);
592
+ return;
593
+ }
594
+ if ('lane' === hit.kind) {
595
+ if (double && this.editable && !hit.lane.lane.locked) return void this.emit('nleadd', {
596
+ lane: hit.lane.lane.id,
597
+ time: quantize(this.doc, this.snapped(hit.time, new Set())),
598
+ via: 'pointer'
599
+ });
600
+ if (!pending.additive) this.select([]);
601
+ if ('touch' !== pending.pointer.type || !double) this.seek(this.snapped(hit.time, new Set()), false);
602
+ }
603
+ }
604
+ wheel(w) {
605
+ this.relayout();
606
+ if (w.ctrl) return void this.zoomAt(Math.exp(0.0025 * -w.dy), w.x);
607
+ const overflow = this.layout.total > this.vp.height - this.metrics.rulerHeight;
608
+ if (w.shift) this.scrollBy(w.dy || w.dx, 0);
609
+ else if (Math.abs(w.dx) > Math.abs(w.dy)) this.scrollBy(w.dx, 0);
610
+ else if (overflow) this.scrollBy(0, w.dy);
611
+ else this.scrollBy(w.dy, 0);
612
+ }
613
+ key(k) {
614
+ this.relayout();
615
+ const key = 1 === k.key.length ? k.key.toLowerCase() : k.key;
616
+ const frame = frameOf(this.doc);
617
+ const sel = this.doc.selection;
618
+ const clips = sel.filter((id)=>this.doc.clips.has(id));
619
+ const keys = sel.filter((id)=>this.doc.keys.has(id));
620
+ const command = (name)=>{
621
+ this.emit('nlecommand', {
622
+ name,
623
+ time: this.doc.playhead
624
+ });
625
+ return true;
626
+ };
627
+ if (k.ctrl) {
628
+ if ('z' === key) return command(k.shift ? 'redo' : 'undo');
629
+ if ('y' === key) return command('redo');
630
+ if ('d' === key) return command('duplicate');
631
+ if ('c' === key) return command('copy');
632
+ if ('v' === key) return command('paste');
633
+ if ('b' === key) return this.splitAtPlayhead();
634
+ if ('=' === key || '+' === key) return this.zoomAt(1.25, this.playheadX()), true;
635
+ if ('-' === key) return this.zoomAt(0.8, this.playheadX()), true;
636
+ if ('0' === key) return this.fit(), true;
637
+ return false;
638
+ }
639
+ if (k.alt && ('ArrowLeft' === key || 'ArrowRight' === key)) return this.nudge('ArrowLeft' === key ? -1 : 1, k.shift);
640
+ if (',' === key || '.' === key) return this.nudge(',' === key ? -1 : 1, k.shift);
641
+ if (k.alt && ('ArrowUp' === key || 'ArrowDown' === key)) {
642
+ if (1 !== clips.length || !this.editable) return true;
643
+ const changes = differing(this.doc, computeLaneStep(this.doc, clips[0], 'ArrowUp' === key ? -1 : 1));
644
+ if (changes.length) this.commitClips('move', changes, 'keyboard');
645
+ return true;
646
+ }
647
+ if (k.alt && 'x' === key) return this.setRange(null), true;
648
+ switch(key){
649
+ case 'ArrowLeft':
650
+ case 'ArrowRight':
651
+ {
652
+ const step = (k.shift ? 1 : frame) * ('ArrowLeft' === key ? -1 : 1);
653
+ this.seek(this.doc.playhead + step, false);
654
+ return true;
655
+ }
656
+ case 'ArrowUp':
657
+ case 'ArrowDown':
658
+ return this.selectInLane('ArrowUp' === key ? -1 : 1), true;
659
+ case 'Tab':
660
+ return this.selectNext(k.shift ? -1 : 1), true;
661
+ case 'Home':
662
+ return this.seek(0, false), true;
663
+ case 'End':
664
+ return this.seek(contentEnd(this.doc), false), true;
665
+ case 's':
666
+ return this.splitAtPlayhead();
667
+ case '[':
668
+ case ']':
669
+ {
670
+ if (1 !== clips.length || !this.editable) return true;
671
+ const changes = differing(this.doc, trimToTime(this.doc, clips[0], '[' === key ? 'start' : 'end', this.doc.playhead).changes);
672
+ if (changes.length) this.commitClips('trim', changes, 'keyboard');
673
+ return true;
674
+ }
675
+ case 'Delete':
676
+ case 'Backspace':
677
+ {
678
+ if (!this.editable || !sel.length) return true;
679
+ const ids = sel.filter((id)=>{
680
+ var _this_doc_clips_get;
681
+ const item = null != (_this_doc_clips_get = this.doc.clips.get(id)) ? _this_doc_clips_get : this.doc.keys.get(id);
682
+ const lane = item ? laneById(this.doc, item.lane) : void 0;
683
+ return item && !(null == lane ? void 0 : lane.locked) && !item.locked;
684
+ });
685
+ if (!ids.length) return true;
686
+ const ripple = ids.some((id)=>{
687
+ var _laneById;
688
+ const clip = this.doc.clips.get(id);
689
+ return clip ? (null == (_laneById = laneById(this.doc, clip.lane)) ? void 0 : _laneById.kind) === 'main' : false;
690
+ });
691
+ this.emit('nleedit', {
692
+ op: 'delete',
693
+ via: 'keyboard',
694
+ ids,
695
+ ripple
696
+ });
697
+ return true;
698
+ }
699
+ case 'Insert':
700
+ case 'n':
701
+ {
702
+ var _ref, _ref1;
703
+ var _this_doc_lanes_find, _this_doc_lanes_;
704
+ if (!this.editable) return true;
705
+ const first = clips[0] ? this.doc.clips.get(clips[0]) : void 0;
706
+ const lane = null != (_ref = null != (_ref1 = null == first ? void 0 : first.lane) ? _ref1 : null == (_this_doc_lanes_find = this.doc.lanes.find((l)=>'main' === l.kind && !l.locked)) ? void 0 : _this_doc_lanes_find.id) ? _ref : null == (_this_doc_lanes_ = this.doc.lanes[0]) ? void 0 : _this_doc_lanes_.id;
707
+ if (lane) this.emit('nleadd', {
708
+ lane,
709
+ time: this.doc.playhead,
710
+ via: 'keyboard'
711
+ });
712
+ return true;
713
+ }
714
+ case 'i':
715
+ var _ref2;
716
+ var _this_doc_range;
717
+ return this.setRange({
718
+ start: this.doc.playhead,
719
+ end: Math.max(this.doc.playhead, null != (_ref2 = null == (_this_doc_range = this.doc.range) ? void 0 : _this_doc_range.end) ? _ref2 : contentEnd(this.doc))
720
+ }), true;
721
+ case 'o':
722
+ var _ref3;
723
+ var _this_doc_range1;
724
+ return this.setRange({
725
+ start: Math.min(this.doc.playhead, null != (_ref3 = null == (_this_doc_range1 = this.doc.range) ? void 0 : _this_doc_range1.start) ? _ref3 : 0),
726
+ end: this.doc.playhead
727
+ }), true;
728
+ case '=':
729
+ case '+':
730
+ return this.zoomAt(1.25, this.playheadX()), true;
731
+ case '-':
732
+ return this.zoomAt(0.8, this.playheadX()), true;
733
+ case 'z':
734
+ if (k.shift) return this.fit(), true;
735
+ return false;
736
+ case 'm':
737
+ return command('marker');
738
+ case 'Escape':
739
+ if (sel.length) this.select([]);
740
+ else command('escape');
741
+ return true;
742
+ default:
743
+ if (keys.length && ('ArrowLeft' === key || 'ArrowRight' === key)) return true;
744
+ return false;
745
+ }
746
+ }
747
+ playheadX() {
748
+ return xOf(this.doc.playhead, this.vp, this.metrics);
749
+ }
750
+ nudge(direction, big) {
751
+ if (!this.editable) return true;
752
+ const frames = direction * (big ? 10 : 1);
753
+ const sel = this.doc.selection;
754
+ const keyIds = sel.filter((id)=>this.doc.keys.has(id));
755
+ if (keyIds.length) {
756
+ const step = frameOf(this.doc) * frames;
757
+ this.commitKeys(keyIds.map((id)=>({
758
+ id,
759
+ time: quantize(this.doc, Math.max(0, this.doc.keys.get(id).time + step))
760
+ })), 'keyboard');
761
+ return true;
762
+ }
763
+ const changes = differing(this.doc, computeNudge(this.doc, sel.filter((id)=>this.doc.clips.has(id)), frames));
764
+ if (changes.length) this.commitClips('move', changes, 'keyboard');
765
+ return true;
766
+ }
767
+ commitClips(op, changes, via) {
768
+ commit(this.doc, changes);
769
+ this.relayout();
770
+ this.emit('nleedit', {
771
+ op,
772
+ via,
773
+ changes
774
+ });
775
+ this.invalidate();
776
+ }
777
+ commitKeys(keys, via) {
778
+ for (const { id, time } of keys){
779
+ const key = this.doc.keys.get(id);
780
+ if (key) this.doc.keys.set(id, {
781
+ ...key,
782
+ time
783
+ });
784
+ }
785
+ this.doc.keyIndex = null;
786
+ this.doc.version++;
787
+ this.emit('nleedit', {
788
+ op: 'keys',
789
+ via,
790
+ keys
791
+ });
792
+ this.invalidate();
793
+ }
794
+ splitAtPlayhead() {
795
+ if (!this.editable) return true;
796
+ const time = this.doc.playhead;
797
+ const ids = splitTargets(this.doc, time);
798
+ if (ids.length) this.emit('nleedit', {
799
+ op: 'split',
800
+ via: 'keyboard',
801
+ splits: ids.map((id)=>({
802
+ id,
803
+ time
804
+ }))
805
+ });
806
+ return true;
807
+ }
808
+ selectNext(step) {
809
+ const all = this.layout.lanes.flatMap((box)=>laneClips(this.doc, box.lane.id));
810
+ all.sort((a, b)=>a.start - b.start);
811
+ if (!all.length) return;
812
+ const current = this.doc.selection[this.doc.selection.length - 1];
813
+ const i = all.findIndex((c)=>c.id === current);
814
+ const next = all[i < 0 ? step > 0 ? 0 : all.length - 1 : (i + step + all.length) % all.length];
815
+ this.select([
816
+ next.id
817
+ ]);
818
+ }
819
+ selectInLane(step) {
820
+ var _this_doc_selection_;
821
+ const lanes = this.layout.lanes.filter((b)=>'keys' !== b.lane.kind);
822
+ if (!lanes.length) return;
823
+ const current = this.doc.clips.get(null != (_this_doc_selection_ = this.doc.selection[0]) ? _this_doc_selection_ : '');
824
+ let i = current ? lanes.findIndex((b)=>b.lane.id === current.lane) + step : step > 0 ? 0 : lanes.length - 1;
825
+ const t = this.doc.playhead;
826
+ for(; i >= 0 && i < lanes.length; i += step){
827
+ const list = laneClips(this.doc, lanes[i].lane.id);
828
+ if (!list.length) continue;
829
+ let best = list[0];
830
+ for (const clip of list){
831
+ if (t >= clip.start && t <= clip.start + clip.duration) {
832
+ best = clip;
833
+ break;
834
+ }
835
+ if (Math.abs(clip.start - t) < Math.abs(best.start - t)) best = clip;
836
+ }
837
+ this.select([
838
+ best.id
839
+ ]);
840
+ return;
841
+ }
842
+ }
843
+ get busy() {
844
+ return null !== this.drag && 'pending' !== this.drag.kind;
845
+ }
846
+ constructor(emit, invalidate, metrics = {}){
847
+ _define_property(this, "emit", void 0);
848
+ _define_property(this, "invalidate", void 0);
849
+ _define_property(this, "doc", void 0);
850
+ _define_property(this, "vp", void 0);
851
+ _define_property(this, "metrics", void 0);
852
+ _define_property(this, "tool", void 0);
853
+ _define_property(this, "snapping", void 0);
854
+ _define_property(this, "editable", void 0);
855
+ _define_property(this, "layout", void 0);
856
+ _define_property(this, "overlay", void 0);
857
+ _define_property(this, "drag", void 0);
858
+ _define_property(this, "pointers", void 0);
859
+ _define_property(this, "lastTap", void 0);
860
+ _define_property(this, "fitted", void 0);
861
+ _define_property(this, "layoutVersion", void 0);
862
+ this.emit = emit;
863
+ this.invalidate = invalidate;
864
+ this.doc = createNleDoc();
865
+ this.vp = {
866
+ width: 0,
867
+ height: 0,
868
+ zoom: 40,
869
+ scroll: 0,
870
+ scrollY: 0,
871
+ dir: 'ltr'
872
+ };
873
+ this.tool = 'select';
874
+ this.snapping = true;
875
+ this.editable = true;
876
+ this.layout = {
877
+ lanes: [],
878
+ total: 0
879
+ };
880
+ this.overlay = {
881
+ preview: null,
882
+ keyPreview: null,
883
+ snap: null,
884
+ dropLane: null
885
+ };
886
+ this.drag = null;
887
+ this.pointers = new Map();
888
+ this.lastTap = null;
889
+ this.fitted = false;
890
+ this.layoutVersion = -1;
891
+ this.metrics = {
892
+ ...NLE_METRICS,
893
+ ...metrics
894
+ };
895
+ }
896
+ }
897
+ export { NLE_KEYS, NleEngine };