@dawcore/components 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -9,10 +9,823 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  return result;
10
10
  };
11
11
 
12
- // src/elements/daw-clip.ts
12
+ // src/elements/daw-annotation.ts
13
13
  import { LitElement } from "lit";
14
14
  import { customElement, property } from "lit/decorators.js";
15
- var DawClipElement = class extends LitElement {
15
+ function isValidTick(value) {
16
+ return Number.isFinite(value) && Number.isInteger(value) && value >= 0;
17
+ }
18
+ var DawAnnotationElement = class extends LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this._start = 0;
22
+ this._end = 0;
23
+ this._startTick = null;
24
+ this._endTick = null;
25
+ this._warnedHalfTick = false;
26
+ this._generatedId = "annotation-" + crypto.randomUUID();
27
+ this._hasRendered = false;
28
+ }
29
+ get start() {
30
+ return this._start;
31
+ }
32
+ set start(value) {
33
+ if (!Number.isFinite(value) || value < 0) {
34
+ console.warn("[dawcore] daw-annotation start " + String(value) + " is invalid \u2014 ignored");
35
+ return;
36
+ }
37
+ const old = this._start;
38
+ this._start = value;
39
+ this.requestUpdate("start", old);
40
+ }
41
+ get end() {
42
+ return this._end;
43
+ }
44
+ set end(value) {
45
+ if (!Number.isFinite(value) || value < 0) {
46
+ console.warn("[dawcore] daw-annotation end " + String(value) + " is invalid \u2014 ignored");
47
+ return;
48
+ }
49
+ const old = this._end;
50
+ this._end = value;
51
+ this.requestUpdate("end", old);
52
+ }
53
+ get startTick() {
54
+ return this._startTick;
55
+ }
56
+ set startTick(value) {
57
+ const old = this._startTick;
58
+ if (value === null) {
59
+ this._startTick = null;
60
+ this.requestUpdate("startTick", old);
61
+ return;
62
+ }
63
+ if (!isValidTick(value)) {
64
+ console.warn(
65
+ "[dawcore] daw-annotation start-tick " + String(value) + " is invalid \u2014 ignored"
66
+ );
67
+ return;
68
+ }
69
+ this._startTick = value;
70
+ this.requestUpdate("startTick", old);
71
+ }
72
+ get endTick() {
73
+ return this._endTick;
74
+ }
75
+ set endTick(value) {
76
+ const old = this._endTick;
77
+ if (value === null) {
78
+ this._endTick = null;
79
+ this.requestUpdate("endTick", old);
80
+ return;
81
+ }
82
+ if (!isValidTick(value)) {
83
+ console.warn("[dawcore] daw-annotation end-tick " + String(value) + " is invalid \u2014 ignored");
84
+ return;
85
+ }
86
+ this._endTick = value;
87
+ this.requestUpdate("endTick", old);
88
+ }
89
+ /** Tick-based iff BOTH tick attributes are set (authority rule). */
90
+ get isTickBased() {
91
+ return this._startTick !== null && this._endTick !== null;
92
+ }
93
+ /** Stable identity: the id attribute when present, else a generated UUID. */
94
+ get annotationId() {
95
+ return this.id || this._generatedId;
96
+ }
97
+ toAnnotationData() {
98
+ const text = this.textContent?.trim() ?? "";
99
+ const data = {
100
+ id: this.annotationId,
101
+ start: this.start,
102
+ end: this.end,
103
+ lines: text.length > 0 ? text.split("\n") : [""]
104
+ };
105
+ if (this.isTickBased) {
106
+ data.startTick = this._startTick;
107
+ data.endTick = this._endTick;
108
+ }
109
+ return data;
110
+ }
111
+ // Light DOM — data container only.
112
+ createRenderRoot() {
113
+ return this;
114
+ }
115
+ connectedCallback() {
116
+ super.connectedCallback();
117
+ this.style.display = "none";
118
+ setTimeout(() => {
119
+ this.dispatchEvent(
120
+ new CustomEvent("daw-annotation-connected", {
121
+ bubbles: true,
122
+ composed: true,
123
+ detail: { annotationId: this.annotationId, element: this }
124
+ })
125
+ );
126
+ }, 0);
127
+ }
128
+ updated(changed) {
129
+ const halfTick = this._startTick !== null !== (this._endTick !== null);
130
+ if (halfTick && !this._warnedHalfTick) {
131
+ this._warnedHalfTick = true;
132
+ console.warn(
133
+ '[dawcore] daw-annotation "' + this.annotationId + '": only one of start-tick/end-tick is set \u2014 treated as seconds-based until both are present'
134
+ );
135
+ }
136
+ if (!this._hasRendered) {
137
+ this._hasRendered = true;
138
+ return;
139
+ }
140
+ if (changed.has("start") || changed.has("end") || changed.has("startTick") || changed.has("endTick")) {
141
+ this.dispatchEvent(
142
+ new CustomEvent("daw-annotation-update", {
143
+ bubbles: true,
144
+ composed: true,
145
+ detail: { annotationId: this.annotationId }
146
+ })
147
+ );
148
+ }
149
+ }
150
+ };
151
+ __decorateClass([
152
+ property({ type: Number, noAccessor: true, reflect: true })
153
+ ], DawAnnotationElement.prototype, "start", 1);
154
+ __decorateClass([
155
+ property({ type: Number, noAccessor: true, reflect: true })
156
+ ], DawAnnotationElement.prototype, "end", 1);
157
+ __decorateClass([
158
+ property({ type: Number, noAccessor: true, reflect: true, attribute: "start-tick" })
159
+ ], DawAnnotationElement.prototype, "startTick", 1);
160
+ __decorateClass([
161
+ property({ type: Number, noAccessor: true, reflect: true, attribute: "end-tick" })
162
+ ], DawAnnotationElement.prototype, "endTick", 1);
163
+ DawAnnotationElement = __decorateClass([
164
+ customElement("daw-annotation")
165
+ ], DawAnnotationElement);
166
+
167
+ // src/elements/daw-annotation-track.ts
168
+ import { LitElement as LitElement2 } from "lit";
169
+ import { customElement as customElement2, property as property2 } from "lit/decorators.js";
170
+ import {
171
+ updateAnnotationBoundaries,
172
+ resolveAnnotationShortcuts,
173
+ matchesKeyBinding,
174
+ ANNOTATION_LINK_THRESHOLD_TICKS,
175
+ annotationMinDurationTicks
176
+ } from "@waveform-playlist/core";
177
+ function applyBoundaryResults(elements, after) {
178
+ const byId = new Map(elements.map((el) => [el.annotationId, el]));
179
+ for (const next of after) {
180
+ const el = byId.get(next.id);
181
+ if (!el) continue;
182
+ if (el.start !== next.start) el.start = next.start;
183
+ if (el.end !== next.end) el.end = next.end;
184
+ }
185
+ }
186
+ function applyTickBoundaryResults(elements, after, ticksToSeconds) {
187
+ const byId = new Map(elements.map((el) => [el.annotationId, el]));
188
+ for (const next of after) {
189
+ const el = byId.get(next.id);
190
+ if (!el) continue;
191
+ if (el.isTickBased) {
192
+ const startTick = Math.round(next.start);
193
+ const endTick = Math.round(next.end);
194
+ if (el.startTick !== startTick) {
195
+ el.startTick = startTick;
196
+ el.start = ticksToSeconds(startTick);
197
+ }
198
+ if (el.endTick !== endTick) {
199
+ el.endTick = endTick;
200
+ el.end = ticksToSeconds(endTick);
201
+ }
202
+ } else {
203
+ const start = ticksToSeconds(next.start);
204
+ const end = ticksToSeconds(next.end);
205
+ if (el.start !== start) el.start = start;
206
+ if (el.end !== end) el.end = end;
207
+ }
208
+ }
209
+ }
210
+ function tickSpaceData(el, editor) {
211
+ const base = el.toAnnotationData();
212
+ if (el.isTickBased) {
213
+ return { ...base, start: base.startTick, end: base.endTick };
214
+ }
215
+ return {
216
+ ...base,
217
+ start: editor._secondsToTicks(base.start),
218
+ end: editor._secondsToTicks(base.end)
219
+ };
220
+ }
221
+ var DawAnnotationTrackElement = class extends LitElement2 {
222
+ constructor() {
223
+ super(...arguments);
224
+ this.editable = false;
225
+ this.linkEndpoints = false;
226
+ this.continuousPlay = false;
227
+ this.keyboardControls = false;
228
+ this.boxLabel = "text";
229
+ this.name = "";
230
+ // --- Selection (ephemeral UI state — deliberately NOT DOM data) ---
231
+ this._activeAnnotationId = null;
232
+ // --- Keyboard remapping (accessor pair: cache invalidation on set) ---
233
+ this._annotationShortcuts = null;
234
+ this._resolvedShortcuts = null;
235
+ // Capture phase: runs before <daw-keyboard-shortcuts>' bubble-phase listener,
236
+ // giving annotation shortcuts deterministic priority (spec rule).
237
+ this._onKeyDownCapture = (e) => {
238
+ if (!this.keyboardControls) return;
239
+ if (e.repeat) return;
240
+ const target = e.target;
241
+ if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
242
+ return;
243
+ }
244
+ const match = this._shortcutEntries().find((entry) => matchesKeyBinding(e, entry.binding));
245
+ if (!match) return;
246
+ const hasSelection = this._activeAnnotationId !== null;
247
+ if (match.action === "clearSelection" && !hasSelection) return;
248
+ if (DawAnnotationTrackElement._boundaryActions.has(match.action)) {
249
+ if (!this.editable || !hasSelection) return;
250
+ }
251
+ if (match.action === "playActive" && !hasSelection) return;
252
+ e.preventDefault();
253
+ e.stopImmediatePropagation();
254
+ try {
255
+ this._runShortcutAction(match.action);
256
+ } catch (err) {
257
+ console.warn("[dawcore] Annotation shortcut failed (key=" + e.key + "): " + String(err));
258
+ this.dispatchEvent(
259
+ new CustomEvent("daw-error", {
260
+ bubbles: true,
261
+ composed: true,
262
+ detail: { operation: "annotation-shortcut", key: e.key, error: err }
263
+ })
264
+ );
265
+ }
266
+ };
267
+ // --- Lifecycle ---
268
+ this._childObserver = null;
269
+ }
270
+ get activeAnnotationId() {
271
+ return this._activeAnnotationId;
272
+ }
273
+ set activeAnnotationId(value) {
274
+ if (value !== null && !this.annotationElements.some((el) => el.annotationId === value)) {
275
+ console.warn(
276
+ '[dawcore] daw-annotation-track: unknown annotation id "' + value + '" \u2014 selection ignored'
277
+ );
278
+ return;
279
+ }
280
+ if (value === this._activeAnnotationId) return;
281
+ this._activeAnnotationId = value;
282
+ const active = this._activeElement();
283
+ this.dispatchEvent(
284
+ new CustomEvent("daw-annotation-select", {
285
+ bubbles: true,
286
+ composed: true,
287
+ detail: { annotation: active ? active.toAnnotationData() : null }
288
+ })
289
+ );
290
+ }
291
+ // --- Child access ---
292
+ /** Child annotation elements, sorted by start time. */
293
+ get annotationElements() {
294
+ return Array.from(this.querySelectorAll(":scope > daw-annotation")).sort(
295
+ (a, b) => a.start - b.start
296
+ );
297
+ }
298
+ get annotations() {
299
+ return this.annotationElements.map((el) => el.toAnnotationData());
300
+ }
301
+ // --- Navigation methods (spec API) ---
302
+ selectNext() {
303
+ this._selectByOffset(1, 0);
304
+ }
305
+ selectPrevious() {
306
+ this._selectByOffset(-1, -1);
307
+ }
308
+ selectFirst() {
309
+ const list = this.annotationElements;
310
+ if (list.length > 0) this.activeAnnotationId = list[0].annotationId;
311
+ }
312
+ selectLast() {
313
+ const list = this.annotationElements;
314
+ if (list.length > 0) this.activeAnnotationId = list[list.length - 1].annotationId;
315
+ }
316
+ clearSelection() {
317
+ this.activeAnnotationId = null;
318
+ }
319
+ /** offset: +1 next / -1 previous; noSelectionIndex: 0 → first, -1 → last. */
320
+ _selectByOffset(offset, noSelectionIndex) {
321
+ const list = this.annotationElements;
322
+ if (list.length === 0) return;
323
+ const currentIndex = list.findIndex((el) => el.annotationId === this._activeAnnotationId);
324
+ const nextIndex = currentIndex === -1 ? (noSelectionIndex + list.length) % list.length : (currentIndex + offset + list.length) % list.length;
325
+ this.activeAnnotationId = list[nextIndex].annotationId;
326
+ }
327
+ // --- Playback (spec API) ---
328
+ playActive() {
329
+ const active = this._activeElement();
330
+ if (!active) return;
331
+ const editor = this._hostEditor();
332
+ if (!editor) {
333
+ console.warn(
334
+ "[dawcore] <daw-annotation-track> playActive: no parent <daw-editor> \u2014 call ignored"
335
+ );
336
+ return;
337
+ }
338
+ const data = active.toAnnotationData();
339
+ void editor.play(data.start, this.continuousPlay ? void 0 : data.end);
340
+ }
341
+ // --- Boundary editing (spec API) ---
342
+ moveStartBoundary(deltaMs) {
343
+ this._moveBoundary(deltaMs, true);
344
+ }
345
+ moveEndBoundary(deltaMs) {
346
+ this._moveBoundary(deltaMs, false);
347
+ }
348
+ _moveBoundary(deltaMs, isStart) {
349
+ if (!this.editable) {
350
+ console.warn(
351
+ "[dawcore] daw-annotation-track: boundary editing requires the editable attribute"
352
+ );
353
+ return;
354
+ }
355
+ const elements = this.annotationElements;
356
+ const index = elements.findIndex((el) => el.annotationId === this._activeAnnotationId);
357
+ if (index === -1) return;
358
+ const active = elements[index];
359
+ if (active.isTickBased) {
360
+ const editor = this._hostEditor();
361
+ if (!editor) {
362
+ console.warn(
363
+ "[dawcore] daw-annotation-track: tick-based boundary edits need a parent <daw-editor> for tempo conversion \u2014 call ignored"
364
+ );
365
+ return;
366
+ }
367
+ const tickData = elements.map((el) => tickSpaceData(el, editor));
368
+ const edgeTick = isStart ? tickData[index].start : tickData[index].end;
369
+ const edgeSeconds = editor._ticksToSeconds(edgeTick);
370
+ const deltaTicks = editor._secondsToTicks(edgeSeconds + deltaMs / 1e3) - editor._secondsToTicks(edgeSeconds);
371
+ const clamp = this._timelineDuration();
372
+ const updated2 = updateAnnotationBoundaries(
373
+ {
374
+ annotationIndex: index,
375
+ newTime: edgeTick + deltaTicks,
376
+ isDraggingStart: isStart,
377
+ annotations: tickData,
378
+ duration: clamp === Infinity ? Infinity : editor._secondsToTicks(clamp),
379
+ linkEndpoints: this.linkEndpoints
380
+ },
381
+ {
382
+ linkThreshold: ANNOTATION_LINK_THRESHOLD_TICKS,
383
+ minDuration: annotationMinDurationTicks(editor.ppqn)
384
+ }
385
+ );
386
+ applyTickBoundaryResults(elements, updated2, (t) => editor._ticksToSeconds(t));
387
+ return;
388
+ }
389
+ const data = elements.map((el) => el.toAnnotationData());
390
+ const edge = isStart ? data[index].start : data[index].end;
391
+ const updated = updateAnnotationBoundaries({
392
+ annotationIndex: index,
393
+ newTime: edge + deltaMs / 1e3,
394
+ isDraggingStart: isStart,
395
+ annotations: data,
396
+ duration: this._timelineDuration(),
397
+ linkEndpoints: this.linkEndpoints
398
+ });
399
+ applyBoundaryResults(elements, updated);
400
+ }
401
+ _timelineDuration() {
402
+ return this._hostEditor()?._annotationClampDuration ?? Infinity;
403
+ }
404
+ _activeElement() {
405
+ if (this._activeAnnotationId === null) return null;
406
+ return this.annotationElements.find((el) => el.annotationId === this._activeAnnotationId) ?? null;
407
+ }
408
+ _hostEditor() {
409
+ return this.closest("daw-editor");
410
+ }
411
+ get annotationShortcuts() {
412
+ return this._annotationShortcuts;
413
+ }
414
+ set annotationShortcuts(value) {
415
+ this._annotationShortcuts = value;
416
+ this._resolvedShortcuts = null;
417
+ }
418
+ _shortcutEntries() {
419
+ if (!this._resolvedShortcuts) {
420
+ this._resolvedShortcuts = resolveAnnotationShortcuts(this._annotationShortcuts);
421
+ }
422
+ return this._resolvedShortcuts;
423
+ }
424
+ _runShortcutAction(action) {
425
+ switch (action) {
426
+ case "selectPrevious":
427
+ this.selectPrevious();
428
+ break;
429
+ case "selectNext":
430
+ this.selectNext();
431
+ break;
432
+ case "selectFirst":
433
+ this.selectFirst();
434
+ break;
435
+ case "selectLast":
436
+ this.selectLast();
437
+ break;
438
+ case "clearSelection":
439
+ this.clearSelection();
440
+ break;
441
+ case "moveStartEarlier":
442
+ this.moveStartBoundary(-10);
443
+ break;
444
+ case "moveStartLater":
445
+ this.moveStartBoundary(10);
446
+ break;
447
+ case "moveEndEarlier":
448
+ this.moveEndBoundary(-10);
449
+ break;
450
+ case "moveEndLater":
451
+ this.moveEndBoundary(10);
452
+ break;
453
+ case "playActive":
454
+ this.playActive();
455
+ break;
456
+ }
457
+ }
458
+ createRenderRoot() {
459
+ return this;
460
+ }
461
+ connectedCallback() {
462
+ super.connectedCallback();
463
+ this.style.display = "none";
464
+ if (Object.prototype.hasOwnProperty.call(this, "annotationShortcuts")) {
465
+ const value = this["annotationShortcuts"];
466
+ delete this["annotationShortcuts"];
467
+ this.annotationShortcuts = value;
468
+ }
469
+ document.addEventListener("keydown", this._onKeyDownCapture, true);
470
+ setTimeout(() => {
471
+ this.dispatchEvent(
472
+ new CustomEvent("daw-annotation-track-connected", {
473
+ bubbles: true,
474
+ composed: true,
475
+ detail: { element: this }
476
+ })
477
+ );
478
+ }, 0);
479
+ this._childObserver = new MutationObserver(() => {
480
+ if (this._activeAnnotationId !== null && !this.annotationElements.some((el) => el.annotationId === this._activeAnnotationId)) {
481
+ this.activeAnnotationId = null;
482
+ }
483
+ });
484
+ this._childObserver.observe(this, { childList: true });
485
+ }
486
+ disconnectedCallback() {
487
+ super.disconnectedCallback();
488
+ document.removeEventListener("keydown", this._onKeyDownCapture, true);
489
+ this._childObserver?.disconnect();
490
+ this._childObserver = null;
491
+ }
492
+ };
493
+ DawAnnotationTrackElement._boundaryActions = /* @__PURE__ */ new Set([
494
+ "moveStartEarlier",
495
+ "moveStartLater",
496
+ "moveEndEarlier",
497
+ "moveEndLater"
498
+ ]);
499
+ __decorateClass([
500
+ property2({ type: Boolean, reflect: true })
501
+ ], DawAnnotationTrackElement.prototype, "editable", 2);
502
+ __decorateClass([
503
+ property2({ type: Boolean, reflect: true, attribute: "link-endpoints" })
504
+ ], DawAnnotationTrackElement.prototype, "linkEndpoints", 2);
505
+ __decorateClass([
506
+ property2({ type: Boolean, reflect: true, attribute: "continuous-play" })
507
+ ], DawAnnotationTrackElement.prototype, "continuousPlay", 2);
508
+ __decorateClass([
509
+ property2({ type: Boolean, reflect: true, attribute: "keyboard-controls" })
510
+ ], DawAnnotationTrackElement.prototype, "keyboardControls", 2);
511
+ __decorateClass([
512
+ property2({ reflect: true, attribute: "box-label" })
513
+ ], DawAnnotationTrackElement.prototype, "boxLabel", 2);
514
+ __decorateClass([
515
+ property2({ reflect: true })
516
+ ], DawAnnotationTrackElement.prototype, "name", 2);
517
+ DawAnnotationTrackElement = __decorateClass([
518
+ customElement2("daw-annotation-track")
519
+ ], DawAnnotationTrackElement);
520
+
521
+ // src/elements/daw-annotation-list.ts
522
+ import { LitElement as LitElement3, html, css, nothing } from "lit";
523
+ import { customElement as customElement3, property as property3, state } from "lit/decorators.js";
524
+ import { ticksToBarBeat } from "@waveform-playlist/core";
525
+
526
+ // src/utils/annotation-playing.ts
527
+ function computePlayingAnnotationId(annotations, time) {
528
+ const match = annotations.find((a) => a.start <= time && time < a.end);
529
+ return match?.id ?? null;
530
+ }
531
+
532
+ // src/elements/daw-annotation-list.ts
533
+ function formatAnnotationTime(seconds) {
534
+ const whole = Math.floor(seconds);
535
+ const ms = Math.round((seconds - whole) * 1e3);
536
+ const s = whole % 60;
537
+ const m = (whole - s) / 60;
538
+ return m + ":" + String(s).padStart(2, "0") + "." + String(ms).padStart(3, "0");
539
+ }
540
+ var DawAnnotationListElement = class extends LitElement3 {
541
+ constructor() {
542
+ super(...arguments);
543
+ this.for = "";
544
+ this.timeDisplay = "time";
545
+ this._editingId = null;
546
+ this._activeId = null;
547
+ /** Playback-following highlight, separate from `_activeId` (selection) so
548
+ * playback never disturbs selection/keyboard editing. Driven by
549
+ * daw-timeupdate, cleared on daw-stop, retained on pause. */
550
+ this._playingId = null;
551
+ this._observer = null;
552
+ this._observedTrack = null;
553
+ this._warnedMissing = false;
554
+ /** Warn once per resolved `for` target when bars mode can't find a host
555
+ * editor — reset alongside `_warnedMissing` on `for` change so a
556
+ * retargeted list can warn again for its new target. */
557
+ this._warnedNoEditorForBars = false;
558
+ /** Set around `_cancelEdit`'s `span.blur()` so the resulting synchronous
559
+ * blur event doesn't re-enter `_commitEdit` (cancel already restores the
560
+ * text and clears `_editingId` itself). */
561
+ this._cancelling = false;
562
+ this._onSelect = (e) => {
563
+ if (e.target !== this.track) return;
564
+ this._activeId = e.detail.annotation?.id ?? null;
565
+ this.requestUpdate();
566
+ void this.updateComplete.then(() => {
567
+ const row = this.shadowRoot?.querySelector(".annotation-row.active");
568
+ row?.scrollIntoView?.({ block: "center" });
569
+ });
570
+ };
571
+ /**
572
+ * Update only on annotation-boundary crossings, not per animation frame.
573
+ * `shouldUpdate()` suppresses the resulting render while a row is being
574
+ * edited (`_editingId`) — intentional, not bypassed here. A boundary
575
+ * crossed mid-edit is caught up on the NEXT crossing after the edit ends;
576
+ * the highlight is briefly stale in that window, which is acceptable
577
+ * (edits are rare and short-lived relative to playback).
578
+ */
579
+ this._onTimeUpdate = (e) => {
580
+ if (e.target !== this.track?.closest("daw-editor")) return;
581
+ const playingId = computePlayingAnnotationId(this.track?.annotations ?? [], e.detail.time);
582
+ if (playingId === this._playingId) return;
583
+ this._playingId = playingId;
584
+ this.requestUpdate();
585
+ void this.updateComplete.then(() => {
586
+ const row = this.shadowRoot?.querySelector(".annotation-row.playing");
587
+ row?.scrollIntoView?.({ block: "center" });
588
+ });
589
+ };
590
+ this._onStop = (e) => {
591
+ if (e.target !== this.track?.closest("daw-editor")) return;
592
+ if (this._playingId === null) return;
593
+ this._playingId = null;
594
+ this.requestUpdate();
595
+ };
596
+ }
597
+ get track() {
598
+ if (!this.for) return null;
599
+ const el = document.getElementById(this.for);
600
+ if (!el || el.tagName !== "DAW-ANNOTATION-TRACK") {
601
+ if (!this._warnedMissing) {
602
+ console.warn(
603
+ el ? '[dawcore] <daw-annotation-list for="' + this.for + '"> target is not a <daw-annotation-track>' : '[dawcore] <daw-annotation-list for="' + this.for + '"> target not found'
604
+ );
605
+ this._warnedMissing = true;
606
+ }
607
+ return null;
608
+ }
609
+ return el;
610
+ }
611
+ willUpdate(changed) {
612
+ if (changed.has("for")) {
613
+ this._warnedMissing = false;
614
+ this._warnedNoEditorForBars = false;
615
+ }
616
+ }
617
+ connectedCallback() {
618
+ super.connectedCallback();
619
+ document.addEventListener("daw-annotation-select", this._onSelect);
620
+ document.addEventListener("daw-timeupdate", this._onTimeUpdate);
621
+ document.addEventListener("daw-stop", this._onStop);
622
+ }
623
+ disconnectedCallback() {
624
+ super.disconnectedCallback();
625
+ document.removeEventListener("daw-annotation-select", this._onSelect);
626
+ document.removeEventListener("daw-timeupdate", this._onTimeUpdate);
627
+ document.removeEventListener("daw-stop", this._onStop);
628
+ this._observer?.disconnect();
629
+ this._observer = null;
630
+ this._observedTrack = null;
631
+ }
632
+ shouldUpdate() {
633
+ return this._editingId === null;
634
+ }
635
+ updated() {
636
+ this._ensureObserver();
637
+ this._syncRowText();
638
+ }
639
+ /**
640
+ * Text content is set imperatively, NOT bound as a Lit expression.
641
+ * contenteditable mutates the span's DOM directly as the user types —
642
+ * that ejects lit-html's ChildPart marker comments for any binding at
643
+ * that position, so a later Lit-driven re-render of the same row throws
644
+ * "ChildPart has no parentNode". Keeping the span's children entirely
645
+ * outside Lit's diffing sidesteps the crash; the (soon-to-commit) edited
646
+ * row is skipped via the _editingId check.
647
+ */
648
+ _syncRowText() {
649
+ const annotations = this.track?.annotations ?? [];
650
+ const spans = this.shadowRoot?.querySelectorAll(".annotation-row-text") ?? [];
651
+ spans.forEach((span) => {
652
+ const id = span.dataset.id;
653
+ if (id === void 0 || id === this._editingId) return;
654
+ const a = annotations.find((x) => x.id === id);
655
+ if (!a) return;
656
+ const text = a.lines.join(" ");
657
+ if (span.textContent !== text) span.textContent = text;
658
+ });
659
+ }
660
+ /** (Re)attach the MutationObserver when the resolved track changes. */
661
+ _ensureObserver() {
662
+ const track = this.track;
663
+ if (track === this._observedTrack) return;
664
+ this._observer?.disconnect();
665
+ this._observedTrack = track;
666
+ if (!track) return;
667
+ this._observer = new MutationObserver(() => this.requestUpdate());
668
+ this._observer.observe(track, {
669
+ childList: true,
670
+ subtree: true,
671
+ characterData: true,
672
+ attributes: true,
673
+ attributeFilter: ["start", "end", "id", "editable"]
674
+ });
675
+ }
676
+ _onRowClick(a) {
677
+ const track = this.track;
678
+ if (!track) return;
679
+ track.activeAnnotationId = a.id;
680
+ const editor = track.closest("daw-editor");
681
+ editor?.seekTo?.(a.start);
682
+ }
683
+ /** Formats a row's times span per `timeDisplay`. `'bars'` resolves the
684
+ * host editor once (shared across all rows in a render) and falls back
685
+ * to time display, warning once, when no editor is found. */
686
+ _formatTimes(a, editor) {
687
+ if (this.timeDisplay === "bars") {
688
+ if (editor) {
689
+ const isTickBased = a.startTick !== void 0 && a.endTick !== void 0;
690
+ const startTick = isTickBased ? a.startTick : editor._secondsToTicks(a.start);
691
+ const endTick = isTickBased ? a.endTick : editor._secondsToTicks(a.end);
692
+ const start = ticksToBarBeat(startTick, editor._meterEntries, editor.ppqn);
693
+ const end = ticksToBarBeat(endTick, editor._meterEntries, editor.ppqn);
694
+ return start.bar + "." + start.beat + " \u2013 " + end.bar + "." + end.beat;
695
+ }
696
+ if (!this._warnedNoEditorForBars) {
697
+ console.warn(
698
+ '[dawcore] <daw-annotation-list for="' + this.for + '" time-display="bars"> found no parent <daw-editor> \u2014 falling back to time display'
699
+ );
700
+ this._warnedNoEditorForBars = true;
701
+ }
702
+ }
703
+ return formatAnnotationTime(a.start) + " \u2013 " + formatAnnotationTime(a.end);
704
+ }
705
+ _annotationElement(id) {
706
+ return this.track?.annotationElements.find((el) => el.annotationId === id) ?? null;
707
+ }
708
+ _commitEdit(a, span) {
709
+ if (this._cancelling) return;
710
+ this._editingId = null;
711
+ const el = this._annotationElement(a.id);
712
+ if (el) el.textContent = span.textContent?.trim() ?? "";
713
+ this.requestUpdate();
714
+ }
715
+ _cancelEdit(a, span) {
716
+ this._editingId = null;
717
+ span.textContent = a.lines.join("\n");
718
+ this._cancelling = true;
719
+ try {
720
+ span.blur();
721
+ } finally {
722
+ this._cancelling = false;
723
+ }
724
+ this.requestUpdate();
725
+ }
726
+ render() {
727
+ const track = this.track;
728
+ const annotations = track?.annotations ?? [];
729
+ const editable = track?.editable ?? false;
730
+ const editor = this.timeDisplay === "bars" ? track?.closest("daw-editor") ?? null : null;
731
+ return html`
732
+ ${annotations.map(
733
+ (a) => html`
734
+ <div
735
+ class="annotation-row ${a.id === this._activeId ? "active" : ""} ${a.id === this._playingId ? "playing" : ""}"
736
+ @click=${(e) => {
737
+ if (this._editingId === a.id && this._activeId === a.id) return;
738
+ e.stopPropagation();
739
+ this._onRowClick(a);
740
+ }}
741
+ >
742
+ <span class="annotation-row-times"> ${this._formatTimes(a, editor)} </span>
743
+ <span
744
+ class="annotation-row-text"
745
+ data-id=${a.id}
746
+ contenteditable=${editable ? "true" : nothing}
747
+ @focus=${() => {
748
+ if (editable) this._editingId = a.id;
749
+ }}
750
+ @blur=${(e) => this._commitEdit(a, e.target)}
751
+ @keydown=${(e) => {
752
+ if (!editable) return;
753
+ e.stopPropagation();
754
+ if (e.key === "Enter") {
755
+ e.preventDefault();
756
+ e.target.blur();
757
+ } else if (e.key === "Escape") {
758
+ this._cancelEdit(a, e.target);
759
+ }
760
+ }}
761
+ ></span>
762
+ </div>
763
+ `
764
+ )}
765
+ `;
766
+ }
767
+ };
768
+ DawAnnotationListElement.styles = css`
769
+ :host {
770
+ display: block;
771
+ max-height: var(--daw-annotation-list-max-height, 240px);
772
+ overflow-y: auto;
773
+ background: var(--daw-annotation-list-background, #16213e);
774
+ color: var(--daw-annotation-text-color, #e0d4c8);
775
+ font-family: system-ui, sans-serif;
776
+ font-size: 13px;
777
+ }
778
+ .annotation-row {
779
+ display: flex;
780
+ gap: 10px;
781
+ align-items: baseline;
782
+ padding: 6px 10px;
783
+ border-bottom: 1px solid rgba(255, 255, 255, 0.06);
784
+ cursor: pointer;
785
+ }
786
+ .annotation-row.playing {
787
+ background: var(--daw-annotation-playing-background, rgba(196, 154, 108, 0.12));
788
+ box-shadow: inset 2px 0 0 var(--daw-annotation-box-border, #c49a6c);
789
+ }
790
+ .annotation-row.active {
791
+ background: var(--daw-annotation-active-background, rgba(196, 154, 108, 0.25));
792
+ }
793
+ .annotation-row-times {
794
+ font-variant-numeric: tabular-nums;
795
+ font-size: 11px;
796
+ opacity: 0.7;
797
+ white-space: nowrap;
798
+ }
799
+ .annotation-row-text {
800
+ flex: 1;
801
+ min-width: 0;
802
+ }
803
+ .annotation-row-text[contenteditable='true'] {
804
+ cursor: text;
805
+ outline-offset: 2px;
806
+ }
807
+ .annotation-row-text:empty::before {
808
+ content: '—';
809
+ opacity: 0.4;
810
+ }
811
+ `;
812
+ __decorateClass([
813
+ property3()
814
+ ], DawAnnotationListElement.prototype, "for", 2);
815
+ __decorateClass([
816
+ property3({ type: String, attribute: "time-display", reflect: true })
817
+ ], DawAnnotationListElement.prototype, "timeDisplay", 2);
818
+ __decorateClass([
819
+ state()
820
+ ], DawAnnotationListElement.prototype, "_editingId", 2);
821
+ DawAnnotationListElement = __decorateClass([
822
+ customElement3("daw-annotation-list")
823
+ ], DawAnnotationListElement);
824
+
825
+ // src/elements/daw-clip.ts
826
+ import { LitElement as LitElement4 } from "lit";
827
+ import { customElement as customElement4, property as property4 } from "lit/decorators.js";
828
+ var DawClipElement = class extends LitElement4 {
16
829
  constructor() {
17
830
  super(...arguments);
18
831
  this.src = "";
@@ -117,55 +930,55 @@ var DawClipElement = class extends LitElement {
117
930
  }
118
931
  };
119
932
  __decorateClass([
120
- property()
933
+ property4()
121
934
  ], DawClipElement.prototype, "src", 2);
122
935
  __decorateClass([
123
- property({ attribute: "peaks-src" })
936
+ property4({ attribute: "peaks-src" })
124
937
  ], DawClipElement.prototype, "peaksSrc", 2);
125
938
  __decorateClass([
126
- property({ type: Number })
939
+ property4({ type: Number })
127
940
  ], DawClipElement.prototype, "start", 2);
128
941
  __decorateClass([
129
- property({ type: Number })
942
+ property4({ type: Number })
130
943
  ], DawClipElement.prototype, "duration", 2);
131
944
  __decorateClass([
132
- property({ type: Number })
945
+ property4({ type: Number })
133
946
  ], DawClipElement.prototype, "offset", 2);
134
947
  __decorateClass([
135
- property({ type: Number })
948
+ property4({ type: Number })
136
949
  ], DawClipElement.prototype, "gain", 2);
137
950
  __decorateClass([
138
- property()
951
+ property4()
139
952
  ], DawClipElement.prototype, "name", 2);
140
953
  __decorateClass([
141
- property()
954
+ property4()
142
955
  ], DawClipElement.prototype, "color", 2);
143
956
  __decorateClass([
144
- property({ type: Number, attribute: "fade-in" })
957
+ property4({ type: Number, attribute: "fade-in" })
145
958
  ], DawClipElement.prototype, "fadeIn", 2);
146
959
  __decorateClass([
147
- property({ type: Number, attribute: "fade-out" })
960
+ property4({ type: Number, attribute: "fade-out" })
148
961
  ], DawClipElement.prototype, "fadeOut", 2);
149
962
  __decorateClass([
150
- property({ attribute: "fade-type" })
963
+ property4({ attribute: "fade-type" })
151
964
  ], DawClipElement.prototype, "fadeType", 2);
152
965
  __decorateClass([
153
- property({ attribute: false })
966
+ property4({ attribute: false })
154
967
  ], DawClipElement.prototype, "midiNotes", 2);
155
968
  __decorateClass([
156
- property({ type: Number, attribute: "midi-channel", noAccessor: true })
969
+ property4({ type: Number, attribute: "midi-channel", noAccessor: true })
157
970
  ], DawClipElement.prototype, "midiChannel", 1);
158
971
  __decorateClass([
159
- property({ type: Number, attribute: "midi-program", noAccessor: true })
972
+ property4({ type: Number, attribute: "midi-program", noAccessor: true })
160
973
  ], DawClipElement.prototype, "midiProgram", 1);
161
974
  DawClipElement = __decorateClass([
162
- customElement("daw-clip")
975
+ customElement4("daw-clip")
163
976
  ], DawClipElement);
164
977
 
165
978
  // src/elements/daw-track.ts
166
- import { LitElement as LitElement2 } from "lit";
167
- import { customElement as customElement2, property as property2 } from "lit/decorators.js";
168
- var DawTrackElement = class extends LitElement2 {
979
+ import { LitElement as LitElement5 } from "lit";
980
+ import { customElement as customElement5, property as property5 } from "lit/decorators.js";
981
+ var DawTrackElement = class extends LitElement5 {
169
982
  constructor() {
170
983
  super(...arguments);
171
984
  this.src = "";
@@ -303,36 +1116,36 @@ var DawTrackElement = class extends LitElement2 {
303
1116
  }
304
1117
  };
305
1118
  __decorateClass([
306
- property2()
1119
+ property5()
307
1120
  ], DawTrackElement.prototype, "src", 2);
308
1121
  __decorateClass([
309
- property2()
1122
+ property5()
310
1123
  ], DawTrackElement.prototype, "name", 2);
311
1124
  __decorateClass([
312
- property2({ type: Number })
1125
+ property5({ type: Number })
313
1126
  ], DawTrackElement.prototype, "volume", 2);
314
1127
  __decorateClass([
315
- property2({ type: Number })
1128
+ property5({ type: Number })
316
1129
  ], DawTrackElement.prototype, "pan", 2);
317
1130
  __decorateClass([
318
- property2({ type: Boolean })
1131
+ property5({ type: Boolean })
319
1132
  ], DawTrackElement.prototype, "muted", 2);
320
1133
  __decorateClass([
321
- property2({ type: Boolean })
1134
+ property5({ type: Boolean })
322
1135
  ], DawTrackElement.prototype, "soloed", 2);
323
1136
  __decorateClass([
324
- property2({ attribute: "render-mode", noAccessor: true })
1137
+ property5({ attribute: "render-mode", noAccessor: true })
325
1138
  ], DawTrackElement.prototype, "renderMode", 1);
326
1139
  __decorateClass([
327
- property2({ attribute: false })
1140
+ property5({ attribute: false })
328
1141
  ], DawTrackElement.prototype, "spectrogramConfig", 2);
329
1142
  DawTrackElement = __decorateClass([
330
- customElement2("daw-track")
1143
+ customElement5("daw-track")
331
1144
  ], DawTrackElement);
332
1145
 
333
1146
  // src/elements/daw-waveform.ts
334
- import { LitElement as LitElement3, html, css } from "lit";
335
- import { customElement as customElement3, property as property3 } from "lit/decorators.js";
1147
+ import { LitElement as LitElement6, html as html2, css as css2 } from "lit";
1148
+ import { customElement as customElement6, property as property6 } from "lit/decorators.js";
336
1149
 
337
1150
  // src/utils/peak-rendering.ts
338
1151
  function aggregatePeaks(data, bits, startIndex, endIndex) {
@@ -418,7 +1231,7 @@ function groupDirtyByChunk(dirtyPixels, step, barWidth) {
418
1231
  }
419
1232
  return dirtyByChunk;
420
1233
  }
421
- var DawWaveformElement = class extends LitElement3 {
1234
+ var DawWaveformElement = class extends LitElement6 {
422
1235
  constructor() {
423
1236
  super(...arguments);
424
1237
  this._peaks = new Int16Array(0);
@@ -624,11 +1437,11 @@ var DawWaveformElement = class extends LitElement3 {
624
1437
  render() {
625
1438
  const indices = this._getVisibleChunkIndices();
626
1439
  const dpr = typeof devicePixelRatio !== "undefined" ? devicePixelRatio : 1;
627
- return html`
1440
+ return html2`
628
1441
  <div class="container" style="width: ${this.length}px; height: ${this.waveHeight}px;">
629
1442
  ${indices.map((i) => {
630
1443
  const width = Math.min(MAX_CANVAS_WIDTH, this.length - i * MAX_CANVAS_WIDTH);
631
- return html`
1444
+ return html2`
632
1445
  <canvas
633
1446
  data-index=${i}
634
1447
  width=${width * dpr}
@@ -668,7 +1481,7 @@ var DawWaveformElement = class extends LitElement3 {
668
1481
  }
669
1482
  }
670
1483
  };
671
- DawWaveformElement.styles = css`
1484
+ DawWaveformElement.styles = css2`
672
1485
  :host {
673
1486
  display: block;
674
1487
  position: relative;
@@ -682,39 +1495,39 @@ DawWaveformElement.styles = css`
682
1495
  }
683
1496
  `;
684
1497
  __decorateClass([
685
- property3({ type: Number, attribute: false })
1498
+ property6({ type: Number, attribute: false })
686
1499
  ], DawWaveformElement.prototype, "length", 2);
687
1500
  __decorateClass([
688
- property3({ type: Number, attribute: false })
1501
+ property6({ type: Number, attribute: false })
689
1502
  ], DawWaveformElement.prototype, "waveHeight", 2);
690
1503
  __decorateClass([
691
- property3({ type: Number, attribute: false })
1504
+ property6({ type: Number, attribute: false })
692
1505
  ], DawWaveformElement.prototype, "barWidth", 2);
693
1506
  __decorateClass([
694
- property3({ type: Number, attribute: false })
1507
+ property6({ type: Number, attribute: false })
695
1508
  ], DawWaveformElement.prototype, "barGap", 2);
696
1509
  __decorateClass([
697
- property3({ type: Boolean, attribute: false })
1510
+ property6({ type: Boolean, attribute: false })
698
1511
  ], DawWaveformElement.prototype, "roundedBars", 2);
699
1512
  __decorateClass([
700
- property3({ type: Number, attribute: false })
1513
+ property6({ type: Number, attribute: false })
701
1514
  ], DawWaveformElement.prototype, "visibleStart", 2);
702
1515
  __decorateClass([
703
- property3({ type: Number, attribute: false })
1516
+ property6({ type: Number, attribute: false })
704
1517
  ], DawWaveformElement.prototype, "visibleEnd", 2);
705
1518
  __decorateClass([
706
- property3({ type: Number, attribute: false })
1519
+ property6({ type: Number, attribute: false })
707
1520
  ], DawWaveformElement.prototype, "originX", 2);
708
1521
  __decorateClass([
709
- property3({ attribute: false })
1522
+ property6({ attribute: false })
710
1523
  ], DawWaveformElement.prototype, "segments", 2);
711
1524
  DawWaveformElement = __decorateClass([
712
- customElement3("daw-waveform")
1525
+ customElement6("daw-waveform")
713
1526
  ], DawWaveformElement);
714
1527
 
715
1528
  // src/elements/daw-piano-roll.ts
716
- import { LitElement as LitElement4, html as html2, css as css2 } from "lit";
717
- import { customElement as customElement4, property as property4 } from "lit/decorators.js";
1529
+ import { LitElement as LitElement7, html as html3, css as css3 } from "lit";
1530
+ import { customElement as customElement7, property as property7 } from "lit/decorators.js";
718
1531
  var MAX_CANVAS_WIDTH2 = 1e3;
719
1532
  var LAYOUT_PROPS2 = /* @__PURE__ */ new Set([
720
1533
  "length",
@@ -725,7 +1538,7 @@ var LAYOUT_PROPS2 = /* @__PURE__ */ new Set([
725
1538
  "midiNotes",
726
1539
  "selected"
727
1540
  ]);
728
- var DawPianoRollElement = class extends LitElement4 {
1541
+ var DawPianoRollElement = class extends LitElement7 {
729
1542
  constructor() {
730
1543
  super(...arguments);
731
1544
  this.midiNotes = [];
@@ -857,7 +1670,7 @@ var DawPianoRollElement = class extends LitElement4 {
857
1670
  }
858
1671
  render() {
859
1672
  if (this.length <= 0)
860
- return html2`<div class="container" style="width: 0; height: ${this.waveHeight}px;"></div>`;
1673
+ return html3`<div class="container" style="width: 0; height: ${this.waveHeight}px;"></div>`;
861
1674
  const dpr = typeof devicePixelRatio !== "undefined" ? devicePixelRatio : 1;
862
1675
  const visibleIndices = getVisibleChunkIndices(
863
1676
  this.length,
@@ -866,12 +1679,12 @@ var DawPianoRollElement = class extends LitElement4 {
866
1679
  this.visibleEnd,
867
1680
  this.originX
868
1681
  );
869
- return html2`
1682
+ return html3`
870
1683
  <div class="container" style="width: ${this.length}px; height: ${this.waveHeight}px;">
871
1684
  ${visibleIndices.map((i) => {
872
1685
  const chunkLeft = i * MAX_CANVAS_WIDTH2;
873
1686
  const chunkWidth = Math.min(this.length - chunkLeft, MAX_CANVAS_WIDTH2);
874
- return html2`<canvas
1687
+ return html3`<canvas
875
1688
  data-index=${i}
876
1689
  width=${chunkWidth * dpr}
877
1690
  height=${this.waveHeight * dpr}
@@ -882,7 +1695,7 @@ var DawPianoRollElement = class extends LitElement4 {
882
1695
  `;
883
1696
  }
884
1697
  };
885
- DawPianoRollElement.styles = css2`
1698
+ DawPianoRollElement.styles = css3`
886
1699
  :host {
887
1700
  display: block;
888
1701
  position: relative;
@@ -899,49 +1712,49 @@ DawPianoRollElement.styles = css2`
899
1712
  }
900
1713
  `;
901
1714
  __decorateClass([
902
- property4({ attribute: false })
1715
+ property7({ attribute: false })
903
1716
  ], DawPianoRollElement.prototype, "midiNotes", 2);
904
1717
  __decorateClass([
905
- property4({ type: Number, attribute: false })
1718
+ property7({ type: Number, attribute: false })
906
1719
  ], DawPianoRollElement.prototype, "length", 2);
907
1720
  __decorateClass([
908
- property4({ type: Number, attribute: false })
1721
+ property7({ type: Number, attribute: false })
909
1722
  ], DawPianoRollElement.prototype, "waveHeight", 2);
910
1723
  __decorateClass([
911
- property4({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
1724
+ property7({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
912
1725
  ], DawPianoRollElement.prototype, "samplesPerPixel", 1);
913
1726
  __decorateClass([
914
- property4({ type: Number, attribute: "sample-rate", noAccessor: true })
1727
+ property7({ type: Number, attribute: "sample-rate", noAccessor: true })
915
1728
  ], DawPianoRollElement.prototype, "sampleRate", 1);
916
1729
  __decorateClass([
917
- property4({ type: Number, attribute: false })
1730
+ property7({ type: Number, attribute: false })
918
1731
  ], DawPianoRollElement.prototype, "clipOffsetSeconds", 2);
919
1732
  __decorateClass([
920
- property4({ type: Number, attribute: false })
1733
+ property7({ type: Number, attribute: false })
921
1734
  ], DawPianoRollElement.prototype, "visibleStart", 2);
922
1735
  __decorateClass([
923
- property4({ type: Number, attribute: false })
1736
+ property7({ type: Number, attribute: false })
924
1737
  ], DawPianoRollElement.prototype, "visibleEnd", 2);
925
1738
  __decorateClass([
926
- property4({ type: Number, attribute: false })
1739
+ property7({ type: Number, attribute: false })
927
1740
  ], DawPianoRollElement.prototype, "originX", 2);
928
1741
  __decorateClass([
929
- property4({ type: Boolean, reflect: true })
1742
+ property7({ type: Boolean, reflect: true })
930
1743
  ], DawPianoRollElement.prototype, "selected", 2);
931
1744
  DawPianoRollElement = __decorateClass([
932
- customElement4("daw-piano-roll")
1745
+ customElement7("daw-piano-roll")
933
1746
  ], DawPianoRollElement);
934
1747
 
935
1748
  // src/elements/daw-playhead.ts
936
- import { LitElement as LitElement5, html as html3, css as css3 } from "lit";
937
- import { customElement as customElement5 } from "lit/decorators.js";
938
- var DawPlayheadElement = class extends LitElement5 {
1749
+ import { LitElement as LitElement8, html as html4, css as css4 } from "lit";
1750
+ import { customElement as customElement8 } from "lit/decorators.js";
1751
+ var DawPlayheadElement = class extends LitElement8 {
939
1752
  constructor() {
940
1753
  super(...arguments);
941
1754
  this._line = null;
942
1755
  }
943
1756
  render() {
944
- return html3`<div></div>`;
1757
+ return html4`<div></div>`;
945
1758
  }
946
1759
  firstUpdated() {
947
1760
  this._line = this.shadowRoot.querySelector("div");
@@ -955,7 +1768,7 @@ var DawPlayheadElement = class extends LitElement5 {
955
1768
  }
956
1769
  }
957
1770
  };
958
- DawPlayheadElement.styles = css3`
1771
+ DawPlayheadElement.styles = css4`
959
1772
  :host {
960
1773
  position: absolute;
961
1774
  top: 0;
@@ -974,13 +1787,13 @@ DawPlayheadElement.styles = css3`
974
1787
  }
975
1788
  `;
976
1789
  DawPlayheadElement = __decorateClass([
977
- customElement5("daw-playhead")
1790
+ customElement8("daw-playhead")
978
1791
  ], DawPlayheadElement);
979
1792
 
980
1793
  // src/elements/daw-transport.ts
981
- import { LitElement as LitElement6 } from "lit";
982
- import { customElement as customElement6, property as property5 } from "lit/decorators.js";
983
- var DawTransportElement = class extends LitElement6 {
1794
+ import { LitElement as LitElement9 } from "lit";
1795
+ import { customElement as customElement9, property as property8 } from "lit/decorators.js";
1796
+ var DawTransportElement = class extends LitElement9 {
984
1797
  constructor() {
985
1798
  super(...arguments);
986
1799
  this.for = "";
@@ -995,18 +1808,18 @@ var DawTransportElement = class extends LitElement6 {
995
1808
  }
996
1809
  };
997
1810
  __decorateClass([
998
- property5()
1811
+ property8()
999
1812
  ], DawTransportElement.prototype, "for", 2);
1000
1813
  DawTransportElement = __decorateClass([
1001
- customElement6("daw-transport")
1814
+ customElement9("daw-transport")
1002
1815
  ], DawTransportElement);
1003
1816
 
1004
1817
  // src/elements/daw-play-button.ts
1005
- import { html as html4 } from "lit";
1006
- import { customElement as customElement7, state } from "lit/decorators.js";
1818
+ import { html as html5 } from "lit";
1819
+ import { customElement as customElement10, state as state2 } from "lit/decorators.js";
1007
1820
 
1008
1821
  // src/elements/daw-transport-button.ts
1009
- import { LitElement as LitElement7, css as css4 } from "lit";
1822
+ import { LitElement as LitElement10, css as css5 } from "lit";
1010
1823
 
1011
1824
  // src/utils/transport-capability.ts
1012
1825
  function resolveTransportTarget(el) {
@@ -1047,7 +1860,7 @@ function warnUnsupportedOnce(element, methods) {
1047
1860
  }
1048
1861
 
1049
1862
  // src/elements/daw-transport-button.ts
1050
- var DawTransportButton = class extends LitElement7 {
1863
+ var DawTransportButton = class extends LitElement10 {
1051
1864
  constructor() {
1052
1865
  super(...arguments);
1053
1866
  this._onCapabilityPointerEnter = () => {
@@ -1103,7 +1916,7 @@ var DawTransportButton = class extends LitElement7 {
1103
1916
  /** Methods the transport target must implement for this control to be
1104
1917
  * enabled. Empty = works with any target. */
1105
1918
  DawTransportButton.requiredTargetMethods = [];
1106
- DawTransportButton.styles = css4`
1919
+ DawTransportButton.styles = css5`
1107
1920
  button {
1108
1921
  cursor: pointer;
1109
1922
  background: var(--daw-controls-background, #1a1a2e);
@@ -1170,7 +1983,7 @@ var DawPlayButtonElement = class extends DawTransportButton {
1170
1983
  }
1171
1984
  }
1172
1985
  render() {
1173
- return html4`
1986
+ return html5`
1174
1987
  <button part="button" ?disabled=${this._isRecording} @click=${this._onClick}>
1175
1988
  <slot>Play</slot>
1176
1989
  </button>
@@ -1188,15 +2001,15 @@ var DawPlayButtonElement = class extends DawTransportButton {
1188
2001
  }
1189
2002
  };
1190
2003
  __decorateClass([
1191
- state()
2004
+ state2()
1192
2005
  ], DawPlayButtonElement.prototype, "_isRecording", 2);
1193
2006
  DawPlayButtonElement = __decorateClass([
1194
- customElement7("daw-play-button")
2007
+ customElement10("daw-play-button")
1195
2008
  ], DawPlayButtonElement);
1196
2009
 
1197
2010
  // src/elements/daw-pause-button.ts
1198
- import { html as html5, css as css5 } from "lit";
1199
- import { customElement as customElement8, state as state2 } from "lit/decorators.js";
2011
+ import { html as html6, css as css6 } from "lit";
2012
+ import { customElement as customElement11, state as state3 } from "lit/decorators.js";
1200
2013
  var DawPauseButtonElement = class extends DawTransportButton {
1201
2014
  constructor() {
1202
2015
  super(...arguments);
@@ -1258,7 +2071,7 @@ var DawPauseButtonElement = class extends DawTransportButton {
1258
2071
  }
1259
2072
  }
1260
2073
  render() {
1261
- return html5`
2074
+ return html6`
1262
2075
  <button part="button" ?data-paused=${this._isPaused} @click=${this._onClick}>
1263
2076
  <slot>Pause</slot>
1264
2077
  </button>
@@ -1281,7 +2094,7 @@ var DawPauseButtonElement = class extends DawTransportButton {
1281
2094
  };
1282
2095
  DawPauseButtonElement.styles = [
1283
2096
  DawTransportButton.styles,
1284
- css5`
2097
+ css6`
1285
2098
  button[data-paused] {
1286
2099
  background: rgba(255, 255, 255, 0.1);
1287
2100
  border-color: var(--daw-controls-text, #e0d4c8);
@@ -1289,21 +2102,21 @@ DawPauseButtonElement.styles = [
1289
2102
  `
1290
2103
  ];
1291
2104
  __decorateClass([
1292
- state2()
2105
+ state3()
1293
2106
  ], DawPauseButtonElement.prototype, "_isPaused", 2);
1294
2107
  __decorateClass([
1295
- state2()
2108
+ state3()
1296
2109
  ], DawPauseButtonElement.prototype, "_isRecording", 2);
1297
2110
  DawPauseButtonElement = __decorateClass([
1298
- customElement8("daw-pause-button")
2111
+ customElement11("daw-pause-button")
1299
2112
  ], DawPauseButtonElement);
1300
2113
 
1301
2114
  // src/elements/daw-stop-button.ts
1302
- import { html as html6 } from "lit";
1303
- import { customElement as customElement9 } from "lit/decorators.js";
2115
+ import { html as html7 } from "lit";
2116
+ import { customElement as customElement12 } from "lit/decorators.js";
1304
2117
  var DawStopButtonElement = class extends DawTransportButton {
1305
2118
  render() {
1306
- return html6`
2119
+ return html7`
1307
2120
  <button part="button" @click=${this._onClick}>
1308
2121
  <slot>Stop</slot>
1309
2122
  </button>
@@ -1337,12 +2150,12 @@ var DawStopButtonElement = class extends DawTransportButton {
1337
2150
  }
1338
2151
  };
1339
2152
  DawStopButtonElement = __decorateClass([
1340
- customElement9("daw-stop-button")
2153
+ customElement12("daw-stop-button")
1341
2154
  ], DawStopButtonElement);
1342
2155
 
1343
2156
  // src/elements/daw-editor.ts
1344
- import { LitElement as LitElement11, html as html10, css as css10 } from "lit";
1345
- import { customElement as customElement13, property as property9, state as state3 } from "lit/decorators.js";
2157
+ import { LitElement as LitElement14, html as html12, css as css11 } from "lit";
2158
+ import { customElement as customElement16, property as property12, state as state4 } from "lit/decorators.js";
1346
2159
 
1347
2160
  // src/types.ts
1348
2161
  function isDomClip(desc) {
@@ -1351,9 +2164,9 @@ function isDomClip(desc) {
1351
2164
 
1352
2165
  // src/elements/daw-editor.ts
1353
2166
  import {
1354
- createClip as createClip3,
2167
+ createClip as createClip2,
1355
2168
  createClipFromSeconds,
1356
- createTrack as createTrack2,
2169
+ createTrack,
1357
2170
  clipPixelWidth
1358
2171
  } from "@waveform-playlist/core";
1359
2172
 
@@ -1842,8 +2655,8 @@ var PeakPipeline = class {
1842
2655
  };
1843
2656
 
1844
2657
  // src/elements/daw-ruler.ts
1845
- import { LitElement as LitElement8, html as html7, css as css6 } from "lit";
1846
- import { customElement as customElement10, property as property6 } from "lit/decorators.js";
2658
+ import { LitElement as LitElement11, html as html8, css as css7 } from "lit";
2659
+ import { customElement as customElement13, property as property9 } from "lit/decorators.js";
1847
2660
 
1848
2661
  // src/utils/time-format.ts
1849
2662
  function formatTime(milliseconds) {
@@ -1922,7 +2735,7 @@ function getCachedMusicalTicks(params) {
1922
2735
 
1923
2736
  // src/elements/daw-ruler.ts
1924
2737
  var MAX_CANVAS_WIDTH3 = 1e3;
1925
- var DawRulerElement = class extends LitElement8 {
2738
+ var DawRulerElement = class extends LitElement11 {
1926
2739
  constructor() {
1927
2740
  super(...arguments);
1928
2741
  this.samplesPerPixel = 1024;
@@ -1966,17 +2779,17 @@ var DawRulerElement = class extends LitElement8 {
1966
2779
  }
1967
2780
  render() {
1968
2781
  const widthX = this.scaleMode === "beats" ? this.totalWidth : this._tickData?.widthX ?? 0;
1969
- if (widthX <= 0) return html7``;
2782
+ if (widthX <= 0) return html8``;
1970
2783
  const totalChunks = Math.ceil(widthX / MAX_CANVAS_WIDTH3);
1971
2784
  const indices = Array.from({ length: totalChunks }, (_, i) => i);
1972
2785
  const dpr = typeof devicePixelRatio !== "undefined" ? devicePixelRatio : 1;
1973
2786
  const beatsLabels = this.scaleMode === "beats" ? this._musicalTickData?.ticks.filter((t) => t.label) ?? [] : [];
1974
2787
  const temporalLabels = this.scaleMode !== "beats" ? this._tickData?.labels ?? [] : [];
1975
- return html7`
2788
+ return html8`
1976
2789
  <div class="container" style="width: ${widthX}px; height: ${this.rulerHeight}px;">
1977
2790
  ${indices.map((i) => {
1978
2791
  const width = Math.min(MAX_CANVAS_WIDTH3, widthX - i * MAX_CANVAS_WIDTH3);
1979
- return html7`
2792
+ return html8`
1980
2793
  <canvas
1981
2794
  data-index=${i}
1982
2795
  width=${width * dpr}
@@ -1986,13 +2799,13 @@ var DawRulerElement = class extends LitElement8 {
1986
2799
  `;
1987
2800
  })}
1988
2801
  ${this.scaleMode === "beats" ? beatsLabels.map(
1989
- (t) => html7`<span
2802
+ (t) => html8`<span
1990
2803
  class="label ${t.pixel > 0 ? "centered" : ""}"
1991
2804
  style="left: ${t.pixel > 0 ? t.pixel : t.pixel + 4}px;"
1992
2805
  >${t.label}</span
1993
2806
  >`
1994
2807
  ) : temporalLabels.map(
1995
- ({ pix, text }) => html7`<span class="label" style="left: ${pix + 4}px;">${text}</span>`
2808
+ ({ pix, text }) => html8`<span class="label" style="left: ${pix + 4}px;">${text}</span>`
1996
2809
  )}
1997
2810
  </div>
1998
2811
  `;
@@ -2043,7 +2856,7 @@ var DawRulerElement = class extends LitElement8 {
2043
2856
  }
2044
2857
  }
2045
2858
  };
2046
- DawRulerElement.styles = css6`
2859
+ DawRulerElement.styles = css7`
2047
2860
  :host {
2048
2861
  display: block;
2049
2862
  position: relative;
@@ -2069,40 +2882,40 @@ DawRulerElement.styles = css6`
2069
2882
  }
2070
2883
  `;
2071
2884
  __decorateClass([
2072
- property6({ type: Number, attribute: false })
2885
+ property9({ type: Number, attribute: false })
2073
2886
  ], DawRulerElement.prototype, "samplesPerPixel", 2);
2074
2887
  __decorateClass([
2075
- property6({ type: Number, attribute: false })
2888
+ property9({ type: Number, attribute: false })
2076
2889
  ], DawRulerElement.prototype, "sampleRate", 2);
2077
2890
  __decorateClass([
2078
- property6({ type: Number, attribute: false })
2891
+ property9({ type: Number, attribute: false })
2079
2892
  ], DawRulerElement.prototype, "duration", 2);
2080
2893
  __decorateClass([
2081
- property6({ type: Number, attribute: false })
2894
+ property9({ type: Number, attribute: false })
2082
2895
  ], DawRulerElement.prototype, "rulerHeight", 2);
2083
2896
  __decorateClass([
2084
- property6({ type: String, attribute: false })
2897
+ property9({ type: String, attribute: false })
2085
2898
  ], DawRulerElement.prototype, "scaleMode", 2);
2086
2899
  __decorateClass([
2087
- property6({ type: Number, attribute: false })
2900
+ property9({ type: Number, attribute: false })
2088
2901
  ], DawRulerElement.prototype, "ticksPerPixel", 2);
2089
2902
  __decorateClass([
2090
- property6({ attribute: false })
2903
+ property9({ attribute: false })
2091
2904
  ], DawRulerElement.prototype, "meterEntries", 2);
2092
2905
  __decorateClass([
2093
- property6({ type: Number, attribute: false })
2906
+ property9({ type: Number, attribute: false })
2094
2907
  ], DawRulerElement.prototype, "ppqn", 2);
2095
2908
  __decorateClass([
2096
- property6({ type: Number, attribute: false })
2909
+ property9({ type: Number, attribute: false })
2097
2910
  ], DawRulerElement.prototype, "totalWidth", 2);
2098
2911
  DawRulerElement = __decorateClass([
2099
- customElement10("daw-ruler")
2912
+ customElement13("daw-ruler")
2100
2913
  ], DawRulerElement);
2101
2914
 
2102
2915
  // src/elements/daw-track-controls.ts
2103
- import { LitElement as LitElement9, html as html8, css as css7 } from "lit";
2104
- import { customElement as customElement11, property as property7 } from "lit/decorators.js";
2105
- var DawTrackControlsElement = class extends LitElement9 {
2916
+ import { LitElement as LitElement12, html as html9, css as css8 } from "lit";
2917
+ import { customElement as customElement14, property as property10 } from "lit/decorators.js";
2918
+ var DawTrackControlsElement = class extends LitElement12 {
2106
2919
  constructor() {
2107
2920
  super(...arguments);
2108
2921
  this.trackId = null;
@@ -2111,6 +2924,9 @@ var DawTrackControlsElement = class extends LitElement9 {
2111
2924
  this.pan = 0;
2112
2925
  this.muted = false;
2113
2926
  this.soloed = false;
2927
+ this.reorderable = false;
2928
+ this.trackIndex = 0;
2929
+ this.trackCount = 1;
2114
2930
  this._onVolumeInput = (e) => {
2115
2931
  const value = Number(e.target.value);
2116
2932
  if (Number.isFinite(value)) this._dispatchControl("volume", value);
@@ -2135,6 +2951,23 @@ var DawTrackControlsElement = class extends LitElement9 {
2135
2951
  })
2136
2952
  );
2137
2953
  };
2954
+ this._onMoveUp = () => this._dispatchReorder(this.trackIndex - 1);
2955
+ this._onMoveDown = () => this._dispatchReorder(this.trackIndex + 1);
2956
+ this._onGripPointerDown = (e) => {
2957
+ if (!this.trackId) return;
2958
+ e.preventDefault();
2959
+ this.dispatchEvent(
2960
+ new CustomEvent("daw-track-reorder-grab", {
2961
+ bubbles: true,
2962
+ composed: true,
2963
+ detail: {
2964
+ trackId: this.trackId,
2965
+ pointerEvent: e,
2966
+ gripElement: e.currentTarget
2967
+ }
2968
+ })
2969
+ );
2970
+ };
2138
2971
  }
2139
2972
  firstUpdated() {
2140
2973
  requestAnimationFrame(() => {
@@ -2157,12 +2990,30 @@ var DawTrackControlsElement = class extends LitElement9 {
2157
2990
  })
2158
2991
  );
2159
2992
  }
2993
+ _dispatchReorder(toIndex) {
2994
+ if (!this.trackId) return;
2995
+ this.dispatchEvent(
2996
+ new CustomEvent("daw-track-reorder", {
2997
+ bubbles: true,
2998
+ composed: true,
2999
+ detail: { trackId: this.trackId, fromIndex: this.trackIndex, toIndex }
3000
+ })
3001
+ );
3002
+ }
2160
3003
  render() {
2161
3004
  const volPercent = Math.round(this.volume * 100);
2162
3005
  const panPercent = Math.round(Math.abs(this.pan) * 100);
2163
3006
  const panDisplay = this.pan === 0 ? "C" : (this.pan > 0 ? "R" : "L") + panPercent;
2164
- return html8`
3007
+ return html9`
2165
3008
  <div class="header">
3009
+ ${this.reorderable ? html9`<button
3010
+ class="grip"
3011
+ title="Drag to reorder track"
3012
+ aria-label="Drag to reorder track"
3013
+ @pointerdown=${this._onGripPointerDown}
3014
+ >
3015
+ ⠿
3016
+ </button>` : ""}
2166
3017
  <span class="name" title=${this.trackName}>${this.trackName || "Untitled"}</span>
2167
3018
  <button class="remove-btn" @click=${this._onRemoveClick} title="Remove track">
2168
3019
  &times;
@@ -2179,6 +3030,24 @@ var DawTrackControlsElement = class extends LitElement9 {
2179
3030
  <button class="btn ${this.soloed ? "active" : ""}" @click=${this._onSoloClick} title="Solo">
2180
3031
  S
2181
3032
  </button>
3033
+ ${this.reorderable ? html9`<button
3034
+ class="btn reorder-up"
3035
+ title="Move track up"
3036
+ aria-label="Move track up"
3037
+ ?disabled=${this.trackIndex <= 0}
3038
+ @click=${this._onMoveUp}
3039
+ >
3040
+ ▲
3041
+ </button>
3042
+ <button
3043
+ class="btn reorder-down"
3044
+ title="Move track down"
3045
+ aria-label="Move track down"
3046
+ ?disabled=${this.trackIndex >= this.trackCount - 1}
3047
+ @click=${this._onMoveDown}
3048
+ >
3049
+ ▼
3050
+ </button>` : ""}
2182
3051
  </div>
2183
3052
  <div class="slider-row vol-row">
2184
3053
  <span class="slider-label">
@@ -2211,7 +3080,7 @@ var DawTrackControlsElement = class extends LitElement9 {
2211
3080
  `;
2212
3081
  }
2213
3082
  };
2214
- DawTrackControlsElement.styles = css7`
3083
+ DawTrackControlsElement.styles = css8`
2215
3084
  :host {
2216
3085
  display: flex;
2217
3086
  flex-direction: column;
@@ -2255,6 +3124,20 @@ DawTrackControlsElement.styles = css7`
2255
3124
  opacity: 1;
2256
3125
  color: #d08070;
2257
3126
  }
3127
+ .grip {
3128
+ background: none;
3129
+ border: none;
3130
+ color: var(--daw-controls-text, #c49a6c);
3131
+ cursor: grab;
3132
+ padding: 0 2px;
3133
+ font-size: 12px;
3134
+ line-height: 1;
3135
+ opacity: 0.4;
3136
+ touch-action: none;
3137
+ }
3138
+ .grip:hover {
3139
+ opacity: 1;
3140
+ }
2258
3141
  .buttons {
2259
3142
  display: flex;
2260
3143
  gap: 3px;
@@ -2284,6 +3167,10 @@ DawTrackControlsElement.styles = css7`
2284
3167
  border-color: rgba(208, 128, 112, 0.5);
2285
3168
  color: #d08070;
2286
3169
  }
3170
+ .btn:disabled {
3171
+ opacity: 0.3;
3172
+ cursor: default;
3173
+ }
2287
3174
  .slider-row {
2288
3175
  display: flex;
2289
3176
  align-items: center;
@@ -2363,33 +3250,42 @@ DawTrackControlsElement.styles = css7`
2363
3250
  }
2364
3251
  `;
2365
3252
  __decorateClass([
2366
- property7({ attribute: false })
3253
+ property10({ attribute: false })
2367
3254
  ], DawTrackControlsElement.prototype, "trackId", 2);
2368
3255
  __decorateClass([
2369
- property7({ attribute: false })
3256
+ property10({ attribute: false })
2370
3257
  ], DawTrackControlsElement.prototype, "trackName", 2);
2371
3258
  __decorateClass([
2372
- property7({ type: Number, attribute: false })
3259
+ property10({ type: Number, attribute: false })
2373
3260
  ], DawTrackControlsElement.prototype, "volume", 2);
2374
3261
  __decorateClass([
2375
- property7({ type: Number, attribute: false })
3262
+ property10({ type: Number, attribute: false })
2376
3263
  ], DawTrackControlsElement.prototype, "pan", 2);
2377
3264
  __decorateClass([
2378
- property7({ type: Boolean, attribute: false })
3265
+ property10({ type: Boolean, attribute: false })
2379
3266
  ], DawTrackControlsElement.prototype, "muted", 2);
2380
3267
  __decorateClass([
2381
- property7({ type: Boolean, attribute: false })
3268
+ property10({ type: Boolean, attribute: false })
2382
3269
  ], DawTrackControlsElement.prototype, "soloed", 2);
3270
+ __decorateClass([
3271
+ property10({ type: Boolean, attribute: false })
3272
+ ], DawTrackControlsElement.prototype, "reorderable", 2);
3273
+ __decorateClass([
3274
+ property10({ type: Number, attribute: false })
3275
+ ], DawTrackControlsElement.prototype, "trackIndex", 2);
3276
+ __decorateClass([
3277
+ property10({ type: Number, attribute: false })
3278
+ ], DawTrackControlsElement.prototype, "trackCount", 2);
2383
3279
  DawTrackControlsElement = __decorateClass([
2384
- customElement11("daw-track-controls")
3280
+ customElement14("daw-track-controls")
2385
3281
  ], DawTrackControlsElement);
2386
3282
 
2387
3283
  // src/elements/daw-grid.ts
2388
- import { LitElement as LitElement10, html as html9, css as css8 } from "lit";
2389
- import { customElement as customElement12, property as property8 } from "lit/decorators.js";
3284
+ import { LitElement as LitElement13, html as html10, css as css9 } from "lit";
3285
+ import { customElement as customElement15, property as property11 } from "lit/decorators.js";
2390
3286
  import { MIN_PIXELS_PER_UNIT } from "@waveform-playlist/core";
2391
3287
  var MAX_CANVAS_WIDTH4 = 1e3;
2392
- var DawGridElement = class extends LitElement10 {
3288
+ var DawGridElement = class extends LitElement13 {
2393
3289
  constructor() {
2394
3290
  super(...arguments);
2395
3291
  this.ticksPerPixel = 24;
@@ -2417,7 +3313,7 @@ var DawGridElement = class extends LitElement10 {
2417
3313
  }
2418
3314
  }
2419
3315
  render() {
2420
- if (!this._tickData) return html9``;
3316
+ if (!this._tickData) return html10``;
2421
3317
  const totalWidth = this.length;
2422
3318
  const dpr = typeof devicePixelRatio !== "undefined" ? devicePixelRatio : 1;
2423
3319
  const indices = getVisibleChunkIndices(
@@ -2426,11 +3322,11 @@ var DawGridElement = class extends LitElement10 {
2426
3322
  this.visibleStart,
2427
3323
  this.visibleEnd
2428
3324
  );
2429
- return html9`
3325
+ return html10`
2430
3326
  <div class="container" style="width: ${totalWidth}px; height: ${this.height}px;">
2431
3327
  ${indices.map((i) => {
2432
3328
  const width = Math.min(MAX_CANVAS_WIDTH4, totalWidth - i * MAX_CANVAS_WIDTH4);
2433
- return html9`
3329
+ return html10`
2434
3330
  <canvas
2435
3331
  data-index=${i}
2436
3332
  width=${width * dpr}
@@ -2491,7 +3387,7 @@ var DawGridElement = class extends LitElement10 {
2491
3387
  }
2492
3388
  }
2493
3389
  };
2494
- DawGridElement.styles = css8`
3390
+ DawGridElement.styles = css9`
2495
3391
  :host {
2496
3392
  display: block;
2497
3393
  position: absolute;
@@ -2509,33 +3405,33 @@ DawGridElement.styles = css8`
2509
3405
  }
2510
3406
  `;
2511
3407
  __decorateClass([
2512
- property8({ type: Number, attribute: false })
3408
+ property11({ type: Number, attribute: false })
2513
3409
  ], DawGridElement.prototype, "ticksPerPixel", 2);
2514
3410
  __decorateClass([
2515
- property8({ attribute: false })
3411
+ property11({ attribute: false })
2516
3412
  ], DawGridElement.prototype, "meterEntries", 2);
2517
3413
  __decorateClass([
2518
- property8({ type: Number, attribute: false })
3414
+ property11({ type: Number, attribute: false })
2519
3415
  ], DawGridElement.prototype, "ppqn", 2);
2520
3416
  __decorateClass([
2521
- property8({ type: Number, attribute: false })
3417
+ property11({ type: Number, attribute: false })
2522
3418
  ], DawGridElement.prototype, "visibleStart", 2);
2523
3419
  __decorateClass([
2524
- property8({ type: Number, attribute: false })
3420
+ property11({ type: Number, attribute: false })
2525
3421
  ], DawGridElement.prototype, "visibleEnd", 2);
2526
3422
  __decorateClass([
2527
- property8({ type: Number, attribute: false })
3423
+ property11({ type: Number, attribute: false })
2528
3424
  ], DawGridElement.prototype, "length", 2);
2529
3425
  __decorateClass([
2530
- property8({ type: Number, attribute: false })
3426
+ property11({ type: Number, attribute: false })
2531
3427
  ], DawGridElement.prototype, "height", 2);
2532
3428
  DawGridElement = __decorateClass([
2533
- customElement12("daw-grid")
3429
+ customElement15("daw-grid")
2534
3430
  ], DawGridElement);
2535
3431
 
2536
3432
  // src/styles/theme.ts
2537
- import { css as css9 } from "lit";
2538
- var hostStyles = css9`
3433
+ import { css as css10 } from "lit";
3434
+ var hostStyles = css10`
2539
3435
  :host {
2540
3436
  --daw-wave-color: #c49a6c;
2541
3437
  --daw-progress-color: #63c75f;
@@ -2551,7 +3447,7 @@ var hostStyles = css9`
2551
3447
  --daw-clip-header-text: #e0d4c8;
2552
3448
  }
2553
3449
  `;
2554
- var clipStyles = css9`
3450
+ var clipStyles = css10`
2555
3451
  .clip-container {
2556
3452
  position: absolute;
2557
3453
  overflow: hidden;
@@ -3270,6 +4166,188 @@ var RecordingController = class {
3270
4166
  }
3271
4167
  };
3272
4168
 
4169
+ // src/controllers/annotation-controller.ts
4170
+ import { html as html11 } from "lit";
4171
+ var ANNOTATION_LANE_HEIGHT = 32;
4172
+ var AnnotationController = class {
4173
+ constructor(host) {
4174
+ this._tracks = [];
4175
+ this._removalObserver = null;
4176
+ /** Playback-following highlight per track, separate from each track's
4177
+ * `activeAnnotationId` (selection) so playback never disturbs selection.
4178
+ * Driven by daw-timeupdate, cleared on daw-stop, retained on pause.
4179
+ * Replaced immutably (a fresh Map) on every change. */
4180
+ this._playingIds = /* @__PURE__ */ new Map();
4181
+ this._onDataChange = () => {
4182
+ this.deriveSecondsCaches();
4183
+ this._host.requestUpdate();
4184
+ };
4185
+ /**
4186
+ * Update only on annotation-boundary crossings, not per animation frame.
4187
+ */
4188
+ this._onTimeUpdate = (e) => {
4189
+ const time = e.detail.time;
4190
+ let changed = false;
4191
+ const next = new Map(this._playingIds);
4192
+ for (const track of this._tracks) {
4193
+ const playingId = computePlayingAnnotationId(track.annotations, time);
4194
+ if (playingId !== (this._playingIds.get(track) ?? null)) {
4195
+ next.set(track, playingId);
4196
+ changed = true;
4197
+ }
4198
+ }
4199
+ if (!changed) return;
4200
+ this._playingIds = next;
4201
+ this._host.requestUpdate();
4202
+ };
4203
+ this._onStop = () => {
4204
+ if (this._playingIds.size === 0) return;
4205
+ this._playingIds = /* @__PURE__ */ new Map();
4206
+ this._host.requestUpdate();
4207
+ };
4208
+ this._host = host;
4209
+ host.addController(this);
4210
+ }
4211
+ get tracks() {
4212
+ return this._tracks;
4213
+ }
4214
+ /** Current playback-following highlight id for a track, or `null` when the
4215
+ * playhead isn't inside any of the track's annotations. */
4216
+ getPlayingAnnotationId(track) {
4217
+ return this._playingIds.get(track) ?? null;
4218
+ }
4219
+ get totalLaneHeight() {
4220
+ return this._tracks.length * ANNOTATION_LANE_HEIGHT;
4221
+ }
4222
+ /** Max annotation end (seconds) across registered tracks — 0 when none.
4223
+ * Lets the editor extend the timeline so annotations past the audio stay
4224
+ * reachable/scrollable. */
4225
+ get maxAnnotationEndSeconds() {
4226
+ return this._tracks.reduce(
4227
+ (max, track) => track.annotations.reduce((m, a) => Math.max(m, a.end), max),
4228
+ 0
4229
+ );
4230
+ }
4231
+ hostConnected() {
4232
+ this._host.addEventListener("daw-annotation-update", this._onDataChange);
4233
+ this._host.addEventListener("daw-annotation-select", this._onDataChange);
4234
+ this._host.addEventListener("daw-annotation-connected", this._onDataChange);
4235
+ this._host.addEventListener("daw-timeupdate", this._onTimeUpdate);
4236
+ this._host.addEventListener("daw-stop", this._onStop);
4237
+ this._removalObserver = new MutationObserver((mutations) => {
4238
+ let changed = false;
4239
+ for (const m of mutations) {
4240
+ for (const node of Array.from(m.removedNodes)) {
4241
+ if (!(node instanceof HTMLElement)) continue;
4242
+ if (node.tagName === "DAW-ANNOTATION-TRACK") {
4243
+ this._tracks = this._tracks.filter((t) => t !== node);
4244
+ changed = true;
4245
+ } else if (node.tagName === "DAW-ANNOTATION") {
4246
+ changed = true;
4247
+ }
4248
+ const nestedTracks = node.querySelectorAll?.("daw-annotation-track");
4249
+ if (nestedTracks) {
4250
+ for (const nested of nestedTracks) {
4251
+ this._tracks = this._tracks.filter((t) => t !== nested);
4252
+ changed = true;
4253
+ }
4254
+ }
4255
+ const nestedAnnotations = node.querySelectorAll?.("daw-annotation");
4256
+ if (nestedAnnotations && nestedAnnotations.length > 0) {
4257
+ changed = true;
4258
+ }
4259
+ }
4260
+ }
4261
+ if (changed) this._host.requestUpdate();
4262
+ });
4263
+ this._removalObserver.observe(this._host, { childList: true, subtree: true });
4264
+ }
4265
+ hostDisconnected() {
4266
+ this._host.removeEventListener("daw-annotation-update", this._onDataChange);
4267
+ this._host.removeEventListener("daw-annotation-select", this._onDataChange);
4268
+ this._host.removeEventListener("daw-annotation-connected", this._onDataChange);
4269
+ this._host.removeEventListener("daw-timeupdate", this._onTimeUpdate);
4270
+ this._host.removeEventListener("daw-stop", this._onStop);
4271
+ this._removalObserver?.disconnect();
4272
+ this._removalObserver = null;
4273
+ this._tracks = [];
4274
+ this._playingIds = /* @__PURE__ */ new Map();
4275
+ }
4276
+ handleTrackConnected(el) {
4277
+ if (this._tracks.includes(el)) return;
4278
+ this._tracks = [...this._tracks, el];
4279
+ this._host.requestUpdate();
4280
+ this.deriveSecondsCaches();
4281
+ }
4282
+ /**
4283
+ * Keep the seconds attributes (derived cache) of tick-based annotations in
4284
+ * sync with the host's tempo. Write-only-on-change: a write fires
4285
+ * daw-annotation-update → _onDataChange → this sweep again → values equal →
4286
+ * no write → the loop settles (idempotent).
4287
+ */
4288
+ deriveSecondsCaches() {
4289
+ for (const track of this._tracks) {
4290
+ for (const el of track.annotationElements) {
4291
+ if (!el.isTickBased) continue;
4292
+ const startSeconds = this._host._ticksToSeconds(el.startTick);
4293
+ const endSeconds = this._host._ticksToSeconds(el.endTick);
4294
+ if (el.start !== startSeconds) el.start = startSeconds;
4295
+ if (el.end !== endSeconds) el.end = endSeconds;
4296
+ }
4297
+ }
4298
+ }
4299
+ /** Pixel geometry for one annotation box. Tick-based annotations in beats
4300
+ * mode use CLIP-IDENTICAL tick math (round(tick / ticksPerPixel)) so they
4301
+ * align pixel-exactly with <daw-grid>; everything else uses the floor-based
4302
+ * seconds math (temporal mode reads the always-fresh seconds cache). */
4303
+ boxGeometry(a, spp, sampleRate, ticksPerPixel = null) {
4304
+ if (ticksPerPixel !== null && ticksPerPixel > 0 && a.startTick !== void 0 && a.endTick !== void 0) {
4305
+ const left2 = Math.round(a.startTick / ticksPerPixel);
4306
+ const width2 = Math.round(a.endTick / ticksPerPixel) - left2;
4307
+ return { left: left2, width: width2 };
4308
+ }
4309
+ const left = Math.floor(a.start * sampleRate / spp);
4310
+ const width = Math.floor(a.end * sampleRate / spp) - left;
4311
+ return { left, width };
4312
+ }
4313
+ /**
4314
+ * Lane templates for the editor's .timeline. onPointerDown is supplied by
4315
+ * the editor and dispatches into the drag interaction (Task 9).
4316
+ */
4317
+ renderLanes(spp, sampleRate, onPointerDown = () => {
4318
+ }, ticksPerPixel = null) {
4319
+ return this._tracks.map((track) => {
4320
+ const activeId = track.activeAnnotationId;
4321
+ const playingId = this._playingIds.get(track) ?? null;
4322
+ const elements = track.annotationElements;
4323
+ return html11`
4324
+ <div
4325
+ class="annotation-lane"
4326
+ style="height: ${ANNOTATION_LANE_HEIGHT}px;"
4327
+ @pointerdown=${(e) => onPointerDown(e, track)}
4328
+ >
4329
+ ${elements.map((el, i) => {
4330
+ const a = el.toAnnotationData();
4331
+ const geo = this.boxGeometry(a, spp, sampleRate, ticksPerPixel);
4332
+ const label = track.boxLabel === "none" ? "" : track.boxLabel === "id" ? el.id || String(i + 1) : a.lines.join(" ");
4333
+ return html11`
4334
+ <div
4335
+ class="annotation-box ${a.id === activeId ? "active" : ""} ${a.id === playingId ? "playing" : ""}"
4336
+ data-annotation-id=${a.id}
4337
+ style="left: ${geo.left}px; width: ${geo.width}px;"
4338
+ >
4339
+ ${track.editable ? html11`<div class="annotation-boundary" data-edge="start"></div>` : ""}
4340
+ <span class="annotation-box-text">${label}</span>
4341
+ ${track.editable ? html11`<div class="annotation-boundary" data-edge="end"></div>` : ""}
4342
+ </div>
4343
+ `;
4344
+ })}
4345
+ </div>
4346
+ `;
4347
+ });
4348
+ }
4349
+ };
4350
+
3273
4351
  // src/controllers/spectrogram-controller.ts
3274
4352
  import {
3275
4353
  SpectrogramOrchestrator
@@ -3330,8 +4408,8 @@ var SpectrogramController = class {
3330
4408
  unregisterCanvas(canvasId) {
3331
4409
  this.orchestrator?.unregisterCanvas(canvasId);
3332
4410
  }
3333
- setViewport(state8) {
3334
- this.orchestrator?.setViewport(state8);
4411
+ setViewport(state9) {
4412
+ this.orchestrator?.setViewport(state9);
3335
4413
  }
3336
4414
  dispose() {
3337
4415
  if (this.orchestrator) {
@@ -3956,41 +5034,356 @@ var ClipPointerHandler = class {
3956
5034
  wf.length = peakSlice.length;
3957
5035
  }
3958
5036
  }
3959
- return true;
5037
+ return true;
5038
+ }
5039
+ /** Restore clip container CSS AND waveform peaks to original values after
5040
+ * a trim visual preview. Peaks matter: the drag wrote re-extracted peak
5041
+ * arrays imperatively onto the <daw-waveform> elements (bypassing Lit), and
5042
+ * a cancelled/zero-delta trim makes no engine mutation — so no statechange
5043
+ * re-render will ever repair them. */
5044
+ _restoreTrimVisual() {
5045
+ if (this._clipContainer) {
5046
+ this._clipContainer.style.left = this._originalLeft + "px";
5047
+ this._clipContainer.style.width = this._originalWidth + "px";
5048
+ const waveforms = this._clipContainer.querySelectorAll("daw-waveform");
5049
+ for (const wf of waveforms) {
5050
+ wf.style.left = "0px";
5051
+ }
5052
+ this._updateWaveformPeaks(this._originalOffsetSamples, this._originalDurationSamples);
5053
+ }
5054
+ }
5055
+ _reset() {
5056
+ if (this._boundaryEl) {
5057
+ this._boundaryEl.classList.remove("dragging");
5058
+ this._boundaryEl = null;
5059
+ }
5060
+ this._mode = null;
5061
+ this._clipId = "";
5062
+ this._trackId = "";
5063
+ this._startPx = 0;
5064
+ this._isDragging = false;
5065
+ this._cumulativeDeltaSamples = 0;
5066
+ this._clipContainer = null;
5067
+ this._originalLeft = 0;
5068
+ this._originalWidth = 0;
5069
+ this._originalOffsetSamples = 0;
5070
+ this._originalDurationSamples = 0;
5071
+ this._originalStartSample = 0;
5072
+ }
5073
+ };
5074
+
5075
+ // src/interactions/annotation-drag.ts
5076
+ import { updateAnnotationBoundaries as updateAnnotationBoundaries2, snapTickToGrid as snapTickToGrid3 } from "@waveform-playlist/core";
5077
+ import {
5078
+ ANNOTATION_LINK_THRESHOLD_TICKS as ANNOTATION_LINK_THRESHOLD_TICKS2,
5079
+ annotationMinDurationTicks as annotationMinDurationTicks2
5080
+ } from "@waveform-playlist/core";
5081
+ var AnnotationDragHandler = class {
5082
+ constructor(host) {
5083
+ this._drag = null;
5084
+ this.onPointerDown = (e, track) => {
5085
+ const target = e.target;
5086
+ const boundary = target.closest(".annotation-boundary");
5087
+ const box = target.closest(".annotation-box");
5088
+ if (!box) return;
5089
+ const annotationId = box.getAttribute("data-annotation-id") ?? "";
5090
+ const isBoundary = boundary !== null && track.editable;
5091
+ if (boundary !== null && !track.editable) {
5092
+ return;
5093
+ }
5094
+ e.stopPropagation();
5095
+ e.preventDefault();
5096
+ const elements = track.annotationElements;
5097
+ const el = elements.find((x) => x.annotationId === annotationId);
5098
+ if (!el) return;
5099
+ const mode = el.isTickBased ? "ticks" : "seconds";
5100
+ const snapshot = mode === "ticks" ? elements.map((x) => tickSpaceData(x, this._host)) : track.annotations;
5101
+ const index = snapshot.findIndex((a) => a.id === annotationId);
5102
+ if (index === -1) return;
5103
+ const edge = isBoundary ? boundary.getAttribute("data-edge") : null;
5104
+ const captureEl = isBoundary ? boundary : box;
5105
+ this._drag = {
5106
+ track,
5107
+ captureEl,
5108
+ pointerId: e.pointerId,
5109
+ startClientX: e.clientX,
5110
+ moved: false,
5111
+ edge,
5112
+ annotationId,
5113
+ mode,
5114
+ snapshot,
5115
+ // edgeTime holds ticks in 'ticks' mode, seconds in 'seconds' mode.
5116
+ edgeTime: edge === "start" ? snapshot[index].start : snapshot[index].end
5117
+ };
5118
+ try {
5119
+ captureEl.setPointerCapture(e.pointerId);
5120
+ } catch {
5121
+ }
5122
+ captureEl.addEventListener("pointermove", this._onPointerMove);
5123
+ captureEl.addEventListener("pointerup", this._onPointerUp);
5124
+ captureEl.addEventListener("pointercancel", this._onPointerCancel);
5125
+ };
5126
+ /** Non-private (underscore convention) so tests can drive moves directly. */
5127
+ this._onPointerMove = (e) => {
5128
+ const drag = this._drag;
5129
+ if (!drag || e.pointerId !== drag.pointerId) return;
5130
+ const deltaPx = e.clientX - drag.startClientX;
5131
+ if (Math.abs(deltaPx) >= DRAG_THRESHOLD) drag.moved = true;
5132
+ if (drag.edge === null || !drag.moved) return;
5133
+ const elements = drag.track.annotationElements;
5134
+ const index = drag.snapshot.findIndex((a) => a.id === drag.annotationId);
5135
+ if (index === -1) return;
5136
+ if (drag.mode === "ticks") {
5137
+ const deltaTicks = this._host.scaleMode === "beats" ? deltaPx * this._host.ticksPerPixel : this._host._secondsToTicks(
5138
+ this._host._ticksToSeconds(drag.edgeTime) + deltaPx * this._host._renderSpp / this._host.effectiveSampleRate
5139
+ ) - drag.edgeTime;
5140
+ let newTick = drag.edgeTime + deltaTicks;
5141
+ if (this._host.scaleMode === "beats" && this._host.snapTo !== "off") {
5142
+ newTick = snapTickToGrid3(
5143
+ newTick,
5144
+ this._host.snapTo,
5145
+ this._host._meterEntries,
5146
+ this._host.ppqn
5147
+ );
5148
+ }
5149
+ const clamp = this._host._annotationClampDuration;
5150
+ const updated2 = updateAnnotationBoundaries2(
5151
+ {
5152
+ annotationIndex: index,
5153
+ newTime: newTick,
5154
+ isDraggingStart: drag.edge === "start",
5155
+ annotations: drag.snapshot,
5156
+ duration: clamp === Infinity ? Infinity : this._host._secondsToTicks(clamp),
5157
+ linkEndpoints: drag.track.linkEndpoints
5158
+ },
5159
+ {
5160
+ linkThreshold: ANNOTATION_LINK_THRESHOLD_TICKS2,
5161
+ minDuration: annotationMinDurationTicks2(this._host.ppqn)
5162
+ }
5163
+ );
5164
+ applyTickBoundaryResults(elements, updated2, (t) => this._host._ticksToSeconds(t));
5165
+ return;
5166
+ }
5167
+ const deltaSeconds = deltaPx * this._host._renderSpp / this._host.effectiveSampleRate;
5168
+ const updated = updateAnnotationBoundaries2({
5169
+ annotationIndex: index,
5170
+ newTime: drag.edgeTime + deltaSeconds,
5171
+ isDraggingStart: drag.edge === "start",
5172
+ annotations: drag.snapshot,
5173
+ duration: this._host._annotationClampDuration,
5174
+ linkEndpoints: drag.track.linkEndpoints
5175
+ });
5176
+ applyBoundaryResults(elements, updated);
5177
+ };
5178
+ this._onPointerUp = (e) => {
5179
+ const drag = this._drag;
5180
+ if (!drag || e.pointerId !== drag.pointerId) return;
5181
+ if (!drag.moved && drag.edge === null) {
5182
+ const data = drag.track.annotations.find((a) => a.id === drag.annotationId);
5183
+ if (data) {
5184
+ drag.track.activeAnnotationId = drag.annotationId;
5185
+ this._host.seekTo(data.start);
5186
+ }
5187
+ }
5188
+ this._teardown();
5189
+ };
5190
+ this._onPointerCancel = (e) => {
5191
+ const drag = this._drag;
5192
+ if (!drag || e.pointerId !== drag.pointerId) return;
5193
+ const elements = drag.track.annotationElements;
5194
+ if (drag.mode === "ticks") {
5195
+ applyTickBoundaryResults(elements, drag.snapshot, (t) => this._host._ticksToSeconds(t));
5196
+ } else {
5197
+ applyBoundaryResults(elements, drag.snapshot);
5198
+ }
5199
+ this._teardown();
5200
+ };
5201
+ this._host = host;
5202
+ }
5203
+ _teardown() {
5204
+ const drag = this._drag;
5205
+ if (!drag) return;
5206
+ try {
5207
+ drag.captureEl.releasePointerCapture(drag.pointerId);
5208
+ } catch {
5209
+ }
5210
+ drag.captureEl.removeEventListener("pointermove", this._onPointerMove);
5211
+ drag.captureEl.removeEventListener("pointerup", this._onPointerUp);
5212
+ drag.captureEl.removeEventListener("pointercancel", this._onPointerCancel);
5213
+ this._drag = null;
3960
5214
  }
3961
- /** Restore clip container CSS AND waveform peaks to original values after
3962
- * a trim visual preview. Peaks matter: the drag wrote re-extracted peak
3963
- * arrays imperatively onto the <daw-waveform> elements (bypassing Lit), and
3964
- * a cancelled/zero-delta trim makes no engine mutation — so no statechange
3965
- * re-render will ever repair them. */
3966
- _restoreTrimVisual() {
3967
- if (this._clipContainer) {
3968
- this._clipContainer.style.left = this._originalLeft + "px";
3969
- this._clipContainer.style.width = this._originalWidth + "px";
3970
- const waveforms = this._clipContainer.querySelectorAll("daw-waveform");
3971
- for (const wf of waveforms) {
3972
- wf.style.left = "0px";
5215
+ };
5216
+
5217
+ // src/interactions/track-reorder-handler.ts
5218
+ var TrackReorderHandler = class _TrackReorderHandler {
5219
+ constructor(host) {
5220
+ this._trackId = null;
5221
+ this._pointerId = -1;
5222
+ this._startY = 0;
5223
+ this._rows = [];
5224
+ this._lanes = [];
5225
+ // aligned with _rows indices; null = lane not found
5226
+ this._fromIndex = 0;
5227
+ this._targetIndex = 0;
5228
+ this._gripEl = null;
5229
+ this.onGrab = (trackId, e, gripEl) => {
5230
+ if (this._trackId !== null) return;
5231
+ const column = this._host.shadowRoot?.querySelector(".controls-column");
5232
+ if (!column) return;
5233
+ const rows = [...column.querySelectorAll("daw-track-controls")];
5234
+ this._rows = rows.map((el) => {
5235
+ const rect = el.getBoundingClientRect();
5236
+ return {
5237
+ el,
5238
+ top: rect.top,
5239
+ height: rect.height,
5240
+ trackId: el.trackId ?? ""
5241
+ };
5242
+ });
5243
+ this._fromIndex = this._rows.findIndex((r) => r.trackId === trackId);
5244
+ if (this._fromIndex === -1) {
5245
+ this._rows = [];
5246
+ return;
3973
5247
  }
3974
- this._updateWaveformPeaks(this._originalOffsetSamples, this._originalDurationSamples);
3975
- }
5248
+ this._trackId = trackId;
5249
+ this._targetIndex = this._fromIndex;
5250
+ this._pointerId = e.pointerId;
5251
+ this._startY = e.clientY;
5252
+ this._gripEl = gripEl;
5253
+ const timeline = this._host.shadowRoot?.querySelector(".timeline");
5254
+ const laneEls = timeline ? [...timeline.querySelectorAll(".track-row")] : [];
5255
+ this._lanes = this._rows.map((r) => {
5256
+ const el = laneEls.find((l) => l.getAttribute("data-track-id") === r.trackId) ?? null;
5257
+ if (!el) return null;
5258
+ const rect = el.getBoundingClientRect();
5259
+ return { el, top: rect.top, height: rect.height, trackId: r.trackId };
5260
+ });
5261
+ const draggedLane = this._lanes[this._fromIndex];
5262
+ if (draggedLane) {
5263
+ draggedLane.el.setAttribute("data-track-drag-source", "");
5264
+ draggedLane.el.style.zIndex = "10";
5265
+ draggedLane.el.style.position = "relative";
5266
+ }
5267
+ if (!_TrackReorderHandler._reducedMotion()) {
5268
+ for (let i = 0; i < this._rows.length; i++) {
5269
+ if (i !== this._fromIndex) this._rows[i].el.style.transition = "transform 150ms ease";
5270
+ const lane = this._lanes[i];
5271
+ if (lane) lane.el.style.transition = "transform 150ms ease";
5272
+ }
5273
+ }
5274
+ try {
5275
+ gripEl.setPointerCapture(e.pointerId);
5276
+ } catch {
5277
+ }
5278
+ gripEl.addEventListener("pointermove", this._onPointerMove);
5279
+ gripEl.addEventListener("pointerup", this._onPointerUp);
5280
+ gripEl.addEventListener("pointercancel", this._onPointerCancel);
5281
+ };
5282
+ this._onPointerMove = (e) => {
5283
+ if (e.pointerId !== this._pointerId || this._trackId === null) return;
5284
+ const dragged = this._rows[this._fromIndex];
5285
+ const dy = e.clientY - this._startY;
5286
+ dragged.el.style.transform = "translateY(" + dy + "px)";
5287
+ dragged.el.style.zIndex = "10";
5288
+ dragged.el.style.position = "relative";
5289
+ let target = this._fromIndex;
5290
+ for (let i = 0; i < this._rows.length; i++) {
5291
+ if (i === this._fromIndex) continue;
5292
+ const mid = this._rows[i].top + this._rows[i].height / 2;
5293
+ if (i < this._fromIndex && e.clientY < mid) {
5294
+ target = i;
5295
+ break;
5296
+ }
5297
+ if (i > this._fromIndex && e.clientY > mid) {
5298
+ target = i;
5299
+ }
5300
+ }
5301
+ this._targetIndex = target;
5302
+ for (let i = 0; i < this._rows.length; i++) {
5303
+ if (i === this._fromIndex) continue;
5304
+ const row = this._rows[i];
5305
+ let shift = 0;
5306
+ if (i > this._fromIndex && i <= target) shift = -dragged.height;
5307
+ else if (i < this._fromIndex && i >= target) shift = dragged.height;
5308
+ row.el.style.transform = shift === 0 ? "" : "translateY(" + shift + "px)";
5309
+ }
5310
+ const draggedLaneInfo = this._lanes[this._fromIndex];
5311
+ for (let i = 0; i < this._lanes.length; i++) {
5312
+ const lane = this._lanes[i];
5313
+ if (!lane || !draggedLaneInfo) continue;
5314
+ if (i === this._fromIndex) {
5315
+ let offset = 0;
5316
+ const targetLane = this._lanes[target];
5317
+ if (targetLane && target > this._fromIndex) {
5318
+ offset = targetLane.top + targetLane.height - (draggedLaneInfo.top + draggedLaneInfo.height);
5319
+ } else if (targetLane && target < this._fromIndex) {
5320
+ offset = targetLane.top - draggedLaneInfo.top;
5321
+ }
5322
+ lane.el.style.transform = offset === 0 ? "" : "translateY(" + offset + "px)";
5323
+ continue;
5324
+ }
5325
+ let laneShift = 0;
5326
+ if (i > this._fromIndex && i <= target) laneShift = -draggedLaneInfo.height;
5327
+ else if (i < this._fromIndex && i >= target) laneShift = draggedLaneInfo.height;
5328
+ lane.el.style.transform = laneShift === 0 ? "" : "translateY(" + laneShift + "px)";
5329
+ }
5330
+ };
5331
+ this._onPointerUp = (e) => {
5332
+ if (e.pointerId !== this._pointerId || this._trackId === null) return;
5333
+ const trackId = this._trackId;
5334
+ const target = this._targetIndex;
5335
+ const from = this._fromIndex;
5336
+ this._cleanup();
5337
+ if (target !== from) {
5338
+ this._host.reorderTrack(trackId, target);
5339
+ }
5340
+ };
5341
+ this._onPointerCancel = (e) => {
5342
+ if (e.pointerId !== this._pointerId) return;
5343
+ this._cleanup();
5344
+ };
5345
+ this._host = host;
3976
5346
  }
3977
- _reset() {
3978
- if (this._boundaryEl) {
3979
- this._boundaryEl.classList.remove("dragging");
3980
- this._boundaryEl = null;
5347
+ static _reducedMotion() {
5348
+ return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
5349
+ }
5350
+ /** Abort any in-progress drag and reset state. Called by the editor on
5351
+ * disconnect — without this, a drag interrupted by editor removal (with no
5352
+ * pointercancel delivered) would leave the handler wedged and silently
5353
+ * block every future grab. */
5354
+ cancel() {
5355
+ this._cleanup();
5356
+ }
5357
+ _cleanup() {
5358
+ for (const row of this._rows) {
5359
+ row.el.style.transform = "";
5360
+ row.el.style.zIndex = "";
5361
+ row.el.style.position = "";
5362
+ row.el.style.transition = "";
5363
+ }
5364
+ for (const lane of this._lanes) {
5365
+ if (!lane) continue;
5366
+ lane.el.style.transform = "";
5367
+ lane.el.style.transition = "";
5368
+ lane.el.style.zIndex = "";
5369
+ lane.el.style.position = "";
5370
+ lane.el.removeAttribute("data-track-drag-source");
5371
+ }
5372
+ this._lanes = [];
5373
+ const grip = this._gripEl;
5374
+ if (grip) {
5375
+ grip.removeEventListener("pointermove", this._onPointerMove);
5376
+ grip.removeEventListener("pointerup", this._onPointerUp);
5377
+ grip.removeEventListener("pointercancel", this._onPointerCancel);
5378
+ try {
5379
+ grip.releasePointerCapture(this._pointerId);
5380
+ } catch {
5381
+ }
3981
5382
  }
3982
- this._mode = null;
3983
- this._clipId = "";
3984
- this._trackId = "";
3985
- this._startPx = 0;
3986
- this._isDragging = false;
3987
- this._cumulativeDeltaSamples = 0;
3988
- this._clipContainer = null;
3989
- this._originalLeft = 0;
3990
- this._originalWidth = 0;
3991
- this._originalOffsetSamples = 0;
3992
- this._originalDurationSamples = 0;
3993
- this._originalStartSample = 0;
5383
+ this._gripEl = null;
5384
+ this._trackId = null;
5385
+ this._pointerId = -1;
5386
+ this._rows = [];
3994
5387
  }
3995
5388
  };
3996
5389
 
@@ -4046,7 +5439,6 @@ function parseDisplayTime(value, format) {
4046
5439
  }
4047
5440
 
4048
5441
  // src/interactions/file-loader.ts
4049
- import { createClip, createTrack } from "@waveform-playlist/core";
4050
5442
  async function loadFiles(host, files) {
4051
5443
  if (!files) {
4052
5444
  console.warn("[dawcore] loadFiles called with null/undefined");
@@ -4055,107 +5447,36 @@ async function loadFiles(host, files) {
4055
5447
  const fileArray = Array.from(files);
4056
5448
  const loaded = [];
4057
5449
  const failed = [];
5450
+ const dispatchLoadError = (file, error) => {
5451
+ failed.push({ file, error });
5452
+ if (host.isConnected) {
5453
+ host.dispatchEvent(
5454
+ new CustomEvent("daw-files-load-error", {
5455
+ bubbles: true,
5456
+ composed: true,
5457
+ detail: { file, error }
5458
+ })
5459
+ );
5460
+ }
5461
+ };
4058
5462
  for (const file of fileArray) {
4059
5463
  if (file.type && !file.type.startsWith("audio/")) {
4060
5464
  const error = new Error("Non-audio MIME type: " + file.type);
4061
- failed.push({ file, error });
4062
5465
  console.warn("[dawcore] Skipping non-audio file: " + file.name + " (" + file.type + ")");
4063
- if (host.isConnected) {
4064
- host.dispatchEvent(
4065
- new CustomEvent("daw-files-load-error", {
4066
- bubbles: true,
4067
- composed: true,
4068
- detail: { file, error }
4069
- })
4070
- );
4071
- }
5466
+ dispatchLoadError(file, error);
4072
5467
  continue;
4073
5468
  }
4074
5469
  const blobUrl = URL.createObjectURL(file);
5470
+ const name = file.name.replace(/\.\w+$/, "");
4075
5471
  try {
4076
- const audioBuffer = await host._fetchAndDecode(blobUrl);
4077
- URL.revokeObjectURL(blobUrl);
4078
- host._audioCache.delete(blobUrl);
4079
- host._resolvedSampleRate = audioBuffer.sampleRate;
4080
- const name = file.name.replace(/\.\w+$/, "");
4081
- const clip = createClip({
4082
- audioBuffer,
4083
- startSample: 0,
4084
- durationSamples: audioBuffer.length,
4085
- offsetSamples: 0,
4086
- gain: 1,
4087
- name,
4088
- sampleRate: audioBuffer.sampleRate,
4089
- sourceDurationSamples: audioBuffer.length
4090
- });
4091
- host._clipBuffers = new Map(host._clipBuffers).set(clip.id, audioBuffer);
4092
- host._clipOffsets = new Map(host._clipOffsets).set(clip.id, {
4093
- offsetSamples: clip.offsetSamples,
4094
- durationSamples: clip.durationSamples
4095
- });
4096
- const peakData = await host._peakPipeline.generatePeaks(
4097
- audioBuffer,
4098
- host.renderSamplesPerPixel,
4099
- host.mono,
4100
- clip.offsetSamples,
4101
- clip.durationSamples
4102
- );
4103
- host._peaksData = new Map(host._peaksData).set(clip.id, peakData);
4104
- const trackId = crypto.randomUUID();
4105
- const track = createTrack({ name, clips: [clip] });
4106
- track.id = trackId;
4107
- host._tracks = new Map(host._tracks).set(trackId, {
4108
- name,
4109
- src: "",
4110
- volume: 1,
4111
- pan: 0,
4112
- muted: false,
4113
- soloed: false,
4114
- renderMode: "waveform",
4115
- clips: [
4116
- {
4117
- kind: "drop",
4118
- src: "",
4119
- peaksSrc: "",
4120
- start: 0,
4121
- duration: audioBuffer.duration,
4122
- offset: 0,
4123
- gain: 1,
4124
- name,
4125
- fadeIn: 0,
4126
- fadeOut: 0,
4127
- fadeType: "linear",
4128
- midiNotes: null,
4129
- midiChannel: null,
4130
- midiProgram: null
4131
- }
4132
- ]
4133
- });
4134
- host._engineTracks = new Map(host._engineTracks).set(trackId, track);
4135
- host._recomputeDuration();
4136
- const engine = await host._ensureEngine();
4137
- engine.setTracks([...host._engineTracks.values()]);
4138
- loaded.push(trackId);
4139
- host.dispatchEvent(
4140
- new CustomEvent("daw-track-ready", {
4141
- bubbles: true,
4142
- composed: true,
4143
- detail: { trackId }
4144
- })
4145
- );
5472
+ const trackEl = await host.addTrack({ name, clips: [{ src: blobUrl, name }] });
5473
+ loaded.push(trackEl.trackId);
4146
5474
  } catch (err) {
4147
- URL.revokeObjectURL(blobUrl);
4148
5475
  console.warn("[dawcore] Failed to load file: " + file.name + " \u2014 " + String(err));
4149
- failed.push({ file, error: err });
4150
- if (host.isConnected) {
4151
- host.dispatchEvent(
4152
- new CustomEvent("daw-files-load-error", {
4153
- bubbles: true,
4154
- composed: true,
4155
- detail: { file, error: err }
4156
- })
4157
- );
4158
- }
5476
+ dispatchLoadError(file, err);
5477
+ } finally {
5478
+ URL.revokeObjectURL(blobUrl);
5479
+ host._audioCache.delete(blobUrl);
4159
5480
  }
4160
5481
  }
4161
5482
  return { loaded, failed };
@@ -4264,7 +5585,7 @@ function stringifyReason(reason) {
4264
5585
  }
4265
5586
 
4266
5587
  // src/interactions/recording-clip.ts
4267
- import { carveClipRange, createClip as createClip2 } from "@waveform-playlist/core";
5588
+ import { carveClipRange, createClip } from "@waveform-playlist/core";
4268
5589
  function addRecordedClip(host, trackId, buf, startSample, durSamples, offsetSamples = 0, clipName) {
4269
5590
  let trimmedBuf = buf;
4270
5591
  if (offsetSamples > 0 && offsetSamples < buf.length) {
@@ -4279,7 +5600,7 @@ function addRecordedClip(host, trackId, buf, startSample, durSamples, offsetSamp
4279
5600
  }
4280
5601
  trimmedBuf = trimmed;
4281
5602
  }
4282
- const clip = createClip2({
5603
+ const clip = createClip({
4283
5604
  audioBuffer: trimmedBuf,
4284
5605
  startSample,
4285
5606
  durationSamples: durSamples,
@@ -4380,9 +5701,9 @@ function splitAtPlayhead(host) {
4380
5701
  function canSplitAtTime(host, time) {
4381
5702
  const { engine } = host;
4382
5703
  if (!engine) return false;
4383
- const state8 = engine.getState();
4384
- if (!state8.selectedTrackId) return false;
4385
- const track = state8.tracks.find((t) => t.id === state8.selectedTrackId);
5704
+ const state9 = engine.getState();
5705
+ if (!state9.selectedTrackId) return false;
5706
+ const track = state9.tracks.find((t) => t.id === state9.selectedTrackId);
4386
5707
  if (!track) return false;
4387
5708
  const atSample = Math.round(time * host.effectiveSampleRate);
4388
5709
  const clip = findClipAtSample(track.clips, atSample);
@@ -4575,9 +5896,9 @@ var EffectsChainController = class {
4575
5896
  placeholder: true
4576
5897
  };
4577
5898
  }
4578
- let state8;
5899
+ let state9;
4579
5900
  try {
4580
- state8 = await entry.instance.getState?.();
5901
+ state9 = await entry.instance.getState?.();
4581
5902
  } catch (err) {
4582
5903
  console.warn(
4583
5904
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4587,7 +5908,7 @@ var EffectsChainController = class {
4587
5908
  kind: "wam",
4588
5909
  ...sourceFields,
4589
5910
  bypassed: entry.bypassed,
4590
- ...state8 !== void 0 ? { state: state8 } : {}
5911
+ ...state9 !== void 0 ? { state: state9 } : {}
4591
5912
  };
4592
5913
  }
4593
5914
  if (entry.placeholder) {
@@ -5887,6 +7208,7 @@ var PlaybackAnimationController = class {
5887
7208
  this._running = true;
5888
7209
  this._animation.start(() => {
5889
7210
  const time = getTime();
7211
+ if (!this._running) return;
5890
7212
  this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
5891
7213
  this._dispatchTimeUpdate(time);
5892
7214
  });
@@ -5923,7 +7245,7 @@ var TrackLoadCancelledError = class extends Error {
5923
7245
  this.name = "TrackLoadCancelledError";
5924
7246
  }
5925
7247
  };
5926
- var DawEditorElement = class extends LitElement11 {
7248
+ var DawEditorElement = class extends LitElement14 {
5927
7249
  constructor() {
5928
7250
  super(...arguments);
5929
7251
  this._samplesPerPixel = 1024;
@@ -5940,6 +7262,7 @@ var DawEditorElement = class extends LitElement11 {
5940
7262
  this.interactiveClips = false;
5941
7263
  this.indefinitePlayback = false;
5942
7264
  this.fillViewport = false;
7265
+ this.trackReordering = false;
5943
7266
  this._spectrogramConfig = null;
5944
7267
  this._spectrogramColorMap = null;
5945
7268
  this.scaleMode = "temporal";
@@ -5961,6 +7284,13 @@ var DawEditorElement = class extends LitElement11 {
5961
7284
  this._selectionStartTime = 0;
5962
7285
  this._selectionEndTime = 0;
5963
7286
  this._currentTime = 0;
7287
+ // Bounded-playback watermark for the current play(start, end) call
7288
+ // (selection/annotation playback). The adapter's own auto-stop at
7289
+ // endTime (e.g. native Transport's internal timer) tears down audio but
7290
+ // never notifies isPlaying/daw-stop back up — the _startPlayhead rAF
7291
+ // loop below is the sole place that detects reaching it, same pattern
7292
+ // as the whole-track _duration check.
7293
+ this._activePlayEndTime = null;
5964
7294
  this._externalAdapter = null;
5965
7295
  /** True after a disconnect disposed the consumer's adapter via the engine
5966
7296
  * — rebuild attempts fail loudly until a fresh adapter is set. */
@@ -5987,6 +7317,10 @@ var DawEditorElement = class extends LitElement11 {
5987
7317
  this._childObserver = null;
5988
7318
  this._audioResume = new AudioResumeController(this);
5989
7319
  this._recordingController = new RecordingController(this);
7320
+ this._annotations = new AnnotationController(this);
7321
+ /** Last engine BPM seen by the statechange handler — re-derives tick
7322
+ * annotation seconds caches only when it actually changes. */
7323
+ this._lastAnnotationBpm = null;
5990
7324
  // Closures (not direct references) — _timeToPixels/_getPlayhead are
5991
7325
  // declared later in the class body; class-field init order would read
5992
7326
  // `undefined` for a direct reference here.
@@ -6001,8 +7335,18 @@ var DawEditorElement = class extends LitElement11 {
6001
7335
  * play-start position). Non-private: pointer-handler's seek path sets it.
6002
7336
  */
6003
7337
  this._inSeekTransition = false;
7338
+ /**
7339
+ * True while `stop()` (the public API) is actively calling `this._engine.stop()`.
7340
+ * Suppresses the engine 'stop' handler's own `daw-stop` dispatch — `stop()`
7341
+ * dispatches its own, and without this guard a consumer-initiated stop would
7342
+ * fire `daw-stop` twice. See the engine 'stop' handler for the counterpart
7343
+ * engine-initiated case this flag does NOT suppress.
7344
+ */
7345
+ this._inConsumerStop = false;
6004
7346
  this._spectrogramController = null;
6005
7347
  this._clipPointer = new ClipPointerHandler(this);
7348
+ this._annotationDrag = new AnnotationDragHandler(this);
7349
+ this._trackReorderDrag = new TrackReorderHandler(this);
6006
7350
  this._pointer = new PointerHandler(this);
6007
7351
  this._viewport = (() => {
6008
7352
  const v = new ViewportController(this);
@@ -6026,6 +7370,18 @@ var DawEditorElement = class extends LitElement11 {
6026
7370
  * update for properties unrelated to the viewport.
6027
7371
  */
6028
7372
  this._lastSpectrogramViewport = null;
7373
+ // --- Annotation Events ---
7374
+ this._onAnnotationTrackConnected = (e) => {
7375
+ this._annotations.handleTrackConnected(e.detail.element);
7376
+ };
7377
+ this._onAnnotationSelect = (e) => {
7378
+ const annotation = e.detail.annotation;
7379
+ if (!annotation) return;
7380
+ const scrollArea = this.shadowRoot?.querySelector(".scroll-area");
7381
+ if (!scrollArea) return;
7382
+ const px = Math.floor(annotation.start * this.effectiveSampleRate / this._renderSpp);
7383
+ scrollArea.scrollLeft = Math.max(0, px - scrollArea.clientWidth / 2);
7384
+ };
6029
7385
  // --- Track Events ---
6030
7386
  this._onTrackConnected = (e) => {
6031
7387
  const trackId = e.detail?.trackId;
@@ -6034,6 +7390,10 @@ var DawEditorElement = class extends LitElement11 {
6034
7390
  console.warn("[dawcore] Invalid daw-track-connected event detail: " + String(e.detail));
6035
7391
  return;
6036
7392
  }
7393
+ if (this._tracks.has(trackId)) {
7394
+ this._trackElements.set(trackId, trackEl);
7395
+ return;
7396
+ }
6037
7397
  const descriptor = this._readTrackDescriptor(trackEl);
6038
7398
  this._tracks = new Map(this._tracks).set(trackId, descriptor);
6039
7399
  this._trackElements.set(trackId, trackEl);
@@ -6143,6 +7503,10 @@ var DawEditorElement = class extends LitElement11 {
6143
7503
  }
6144
7504
  return;
6145
7505
  }
7506
+ const loadedDesc = this._tracks.get(trackId);
7507
+ if (loadedDesc && loadedDesc.clips.some((c) => isDomClip(c) && c.clipId === clipEl.clipId)) {
7508
+ return;
7509
+ }
6146
7510
  const clipDesc = {
6147
7511
  kind: "dom",
6148
7512
  clipId: clipEl.clipId,
@@ -6207,6 +7571,13 @@ var DawEditorElement = class extends LitElement11 {
6207
7571
  );
6208
7572
  }
6209
7573
  };
7574
+ this._onTrackReorder = (e) => {
7575
+ this.reorderTrack(e.detail.trackId, e.detail.toIndex);
7576
+ };
7577
+ this._onTrackReorderGrab = (e) => {
7578
+ if (!this.trackReordering) return;
7579
+ this._trackReorderDrag.onGrab(e.detail.trackId, e.detail.pointerEvent, e.detail.gripElement);
7580
+ };
6210
7581
  // --- Recording ---
6211
7582
  this.recordingStream = null;
6212
7583
  /** Set in togglePauseRecording when Transport is paused alongside the
@@ -6220,6 +7591,11 @@ var DawEditorElement = class extends LitElement11 {
6220
7591
  }
6221
7592
  return time * this.effectiveSampleRate / this.samplesPerPixel;
6222
7593
  };
7594
+ /** Guards the statechange handler's engine→DOM sync (Task: reorder #612)
7595
+ * while the observer is pushing DOM order INTO the engine — the intermediate
7596
+ * statechange emissions during the transaction would otherwise bounce
7597
+ * half-applied orders back into the DOM. */
7598
+ this._inOrderSync = false;
6223
7599
  }
6224
7600
  get samplesPerPixel() {
6225
7601
  return this._samplesPerPixel;
@@ -6669,6 +8045,12 @@ var DawEditorElement = class extends LitElement11 {
6669
8045
  }
6670
8046
  return ticks * 60 / (this.bpm * this.ppqn);
6671
8047
  }
8048
+ /** Clamp limit for annotation boundary edits. indefinite-playback removes the
8049
+ * end-of-timeline bound — annotations may extend past the audio (DAW-style
8050
+ * unbounded timeline); the shared boundary math treats Infinity as "no end cap". */
8051
+ get _annotationClampDuration() {
8052
+ return this.indefinitePlayback ? Infinity : this._duration;
8053
+ }
6672
8054
  get _totalWidth() {
6673
8055
  if (this.scaleMode === "beats") {
6674
8056
  const contentTicks = this._secondsToTicks(this._duration);
@@ -6676,8 +8058,9 @@ var DawEditorElement = class extends LitElement11 {
6676
8058
  const minTicks = 32 * num * this.ppqn;
6677
8059
  return Math.ceil(Math.max(contentTicks, minTicks) / this.ticksPerPixel);
6678
8060
  }
8061
+ const naturalDuration = Math.max(this._duration, this._annotations.maxAnnotationEndSeconds);
6679
8062
  const naturalWidth = Math.ceil(
6680
- this._duration * this.effectiveSampleRate / this.samplesPerPixel
8063
+ naturalDuration * this.effectiveSampleRate / this.samplesPerPixel
6681
8064
  );
6682
8065
  if (this.indefinitePlayback || this.fillViewport) {
6683
8066
  return Math.max(naturalWidth, this._viewport.containerWidth);
@@ -6729,30 +8112,55 @@ var DawEditorElement = class extends LitElement11 {
6729
8112
  this.addEventListener("daw-track-remove", this._onTrackRemoveRequest);
6730
8113
  this.addEventListener("daw-clip-connected", this._onClipConnected);
6731
8114
  this.addEventListener("daw-clip-update", this._onClipUpdate);
8115
+ this.addEventListener(
8116
+ "daw-annotation-track-connected",
8117
+ this._onAnnotationTrackConnected
8118
+ );
8119
+ this.addEventListener("daw-annotation-select", this._onAnnotationSelect);
8120
+ this.addEventListener("daw-track-reorder", this._onTrackReorder);
8121
+ this.addEventListener("daw-track-reorder-grab", this._onTrackReorderGrab);
6732
8122
  this._childObserver = new MutationObserver((mutations) => {
8123
+ const removedTracks = /* @__PURE__ */ new Map();
8124
+ const removedClips = /* @__PURE__ */ new Set();
8125
+ const addedTrackIds = /* @__PURE__ */ new Set();
6733
8126
  for (const mutation of mutations) {
8127
+ for (const node of mutation.addedNodes) {
8128
+ if (!(node instanceof HTMLElement)) continue;
8129
+ if (node.tagName === "DAW-TRACK") {
8130
+ addedTrackIds.add(node.trackId);
8131
+ }
8132
+ node.querySelectorAll?.("daw-track").forEach((t) => {
8133
+ addedTrackIds.add(t.trackId);
8134
+ });
8135
+ }
6734
8136
  for (const node of mutation.removedNodes) {
6735
- if (node instanceof HTMLElement) {
6736
- if (node.tagName === "DAW-TRACK") {
6737
- this._onTrackRemoved(node.trackId);
6738
- } else if (node.tagName === "DAW-CLIP") {
6739
- this._onClipRemovedFromDom(node);
6740
- }
6741
- const nestedTracks = node.querySelectorAll?.("daw-track");
6742
- if (nestedTracks) {
6743
- for (const track of nestedTracks) {
6744
- this._onTrackRemoved(track.trackId);
6745
- }
6746
- }
6747
- const nestedClips = node.querySelectorAll?.("daw-clip");
6748
- if (nestedClips) {
6749
- for (const clip of nestedClips) {
6750
- this._onClipRemovedFromDom(clip);
6751
- }
6752
- }
8137
+ if (!(node instanceof HTMLElement)) continue;
8138
+ if (node.tagName === "DAW-TRACK") {
8139
+ removedTracks.set(node.trackId, node);
8140
+ } else if (node.tagName === "DAW-CLIP") {
8141
+ removedClips.add(node);
6753
8142
  }
8143
+ node.querySelectorAll?.("daw-track").forEach((t) => {
8144
+ removedTracks.set(t.trackId, t);
8145
+ });
8146
+ node.querySelectorAll?.("daw-clip").forEach((c) => {
8147
+ removedClips.add(c);
8148
+ });
8149
+ }
8150
+ }
8151
+ let orderMayHaveChanged = addedTrackIds.size > 0;
8152
+ for (const [trackId] of removedTracks) {
8153
+ if (addedTrackIds.has(trackId)) {
8154
+ orderMayHaveChanged = true;
8155
+ continue;
6754
8156
  }
8157
+ this._onTrackRemoved(trackId);
8158
+ }
8159
+ for (const clip of removedClips) {
8160
+ if (clip.isConnected) continue;
8161
+ this._onClipRemovedFromDom(clip);
6755
8162
  }
8163
+ if (orderMayHaveChanged) this._syncEngineOrderToDom();
6756
8164
  });
6757
8165
  this._childObserver.observe(this, { childList: true, subtree: true });
6758
8166
  }
@@ -6766,6 +8174,14 @@ var DawEditorElement = class extends LitElement11 {
6766
8174
  this.removeEventListener("daw-track-remove", this._onTrackRemoveRequest);
6767
8175
  this.removeEventListener("daw-clip-connected", this._onClipConnected);
6768
8176
  this.removeEventListener("daw-clip-update", this._onClipUpdate);
8177
+ this.removeEventListener(
8178
+ "daw-annotation-track-connected",
8179
+ this._onAnnotationTrackConnected
8180
+ );
8181
+ this.removeEventListener("daw-annotation-select", this._onAnnotationSelect);
8182
+ this.removeEventListener("daw-track-reorder", this._onTrackReorder);
8183
+ this.removeEventListener("daw-track-reorder-grab", this._onTrackReorderGrab);
8184
+ this._trackReorderDrag.cancel();
6769
8185
  this._childObserver?.disconnect();
6770
8186
  this._childObserver = null;
6771
8187
  this._trackElements.clear();
@@ -7040,7 +8456,7 @@ var DawEditorElement = class extends LitElement11 {
7040
8456
  let clip;
7041
8457
  if (waveformData) {
7042
8458
  const wdRate = waveformData.sample_rate;
7043
- clip = createClip3({
8459
+ clip = createClip2({
7044
8460
  audioBuffer,
7045
8461
  waveformData,
7046
8462
  startSample: Math.round(clipDesc.start * wdRate),
@@ -7132,7 +8548,7 @@ var DawEditorElement = class extends LitElement11 {
7132
8548
  const noteSpanSeconds = notes.length ? notes.reduce((max, n) => Math.max(max, n.time + n.duration), 0) : 0;
7133
8549
  const sourceDurationSamples = Math.ceil(Math.max(noteSpanSeconds, clipDesc.duration, 1) * sr);
7134
8550
  const requestedDurationSamples = clipDesc.duration > 0 ? Math.round(clipDesc.duration * sr) : sourceDurationSamples;
7135
- const clip = createClip3({
8551
+ const clip = createClip2({
7136
8552
  startSample: Math.round(clipDesc.start * sr),
7137
8553
  durationSamples: requestedDurationSamples,
7138
8554
  offsetSamples: Math.round(clipDesc.offset * sr),
@@ -7168,7 +8584,8 @@ var DawEditorElement = class extends LitElement11 {
7168
8584
  _commitTrackChange(trackId, updatedTrack) {
7169
8585
  this._recomputeDuration();
7170
8586
  if (this._engine?.updateTrack) this._engine.updateTrack(trackId, updatedTrack);
7171
- else if (this._engine) this._engine.setTracks([...this._engineTracks.values()]);
8587
+ else if (this._engine)
8588
+ this._engine.setTracks(this._getOrderedTracks().map(([, track]) => track));
7172
8589
  }
7173
8590
  _applyClipUpdate(trackId, clipId, clipEl) {
7174
8591
  const t = this._engineTracks.get(trackId);
@@ -7343,7 +8760,7 @@ var DawEditorElement = class extends LitElement11 {
7343
8760
  const waveformData = await waveformDataPromise;
7344
8761
  if (waveformData) {
7345
8762
  const wdRate = waveformData.sample_rate;
7346
- const clip2 = createClip3({
8763
+ const clip2 = createClip2({
7347
8764
  waveformData,
7348
8765
  startSample: Math.round(clipDesc.start * wdRate),
7349
8766
  durationSamples: Math.round((clipDesc.duration || waveformData.duration) * wdRate),
@@ -7369,7 +8786,7 @@ var DawEditorElement = class extends LitElement11 {
7369
8786
  this._peaksData = new Map(this._peaksData).set(clip2.id, peakData);
7370
8787
  this._raiseZoomFloor(waveformData.scale);
7371
8788
  if (this._tracks.has(trackId)) {
7372
- const previewTrack = createTrack2({
8789
+ const previewTrack = createTrack({
7373
8790
  name: descriptor.name,
7374
8791
  clips: [clip2],
7375
8792
  volume: descriptor.volume,
@@ -7446,7 +8863,7 @@ var DawEditorElement = class extends LitElement11 {
7446
8863
  trackWasRemoved ? "removed" : "disconnected"
7447
8864
  );
7448
8865
  }
7449
- const track = createTrack2({
8866
+ const track = createTrack({
7450
8867
  name: descriptor.name,
7451
8868
  clips,
7452
8869
  volume: descriptor.volume,
@@ -7467,7 +8884,7 @@ var DawEditorElement = class extends LitElement11 {
7467
8884
  this._maybeRegisterSpectrogramClipAudio(trackId, c);
7468
8885
  }
7469
8886
  const engine = await this._ensureEngine();
7470
- engine.setTracks([...this._engineTracks.values()]);
8887
+ engine.setTracks(this._getOrderedTracks().map(([, track2]) => track2));
7471
8888
  this.dispatchEvent(
7472
8889
  new CustomEvent("daw-track-ready", {
7473
8890
  bubbles: true,
@@ -7595,6 +9012,9 @@ var DawEditorElement = class extends LitElement11 {
7595
9012
  this._reconcileDescriptorsWithEngineTracks(engineState.tracks);
7596
9013
  }
7597
9014
  if (structuralChange) {
9015
+ if (!this._inOrderSync) {
9016
+ this._syncDomToEngineOrder(engineState.tracks);
9017
+ }
7598
9018
  this._effectsManager?.rewireTrackChains();
7599
9019
  const audioTracks = engineState.tracks.filter((t) => {
7600
9020
  const desc = this._tracks.get(t.id);
@@ -7602,6 +9022,10 @@ var DawEditorElement = class extends LitElement11 {
7602
9022
  });
7603
9023
  syncPeaksForChangedClips(this, audioTracks);
7604
9024
  }
9025
+ if (engineState.bpm !== this._lastAnnotationBpm) {
9026
+ this._lastAnnotationBpm = engineState.bpm;
9027
+ this._annotations.deriveSecondsCaches();
9028
+ }
7605
9029
  });
7606
9030
  engine.on("pause", () => {
7607
9031
  this._currentTime = engine.getCurrentTime();
@@ -7609,6 +9033,10 @@ var DawEditorElement = class extends LitElement11 {
7609
9033
  engine.on("stop", () => {
7610
9034
  this._currentTime = engine.getCurrentTime();
7611
9035
  this._stopPlayhead();
9036
+ this._activePlayEndTime = null;
9037
+ if (!this._inConsumerStop && !this._inSeekTransition && this.isConnected) {
9038
+ this.dispatchEvent(new CustomEvent("daw-stop", { bubbles: true, composed: true }));
9039
+ }
7612
9040
  });
7613
9041
  this._engine = engine;
7614
9042
  return engine;
@@ -7727,6 +9155,34 @@ var DawEditorElement = class extends LitElement11 {
7727
9155
  console.warn('[dawcore] removeTrack: no track found for id "' + trackId + '"');
7728
9156
  }
7729
9157
  }
9158
+ /**
9159
+ * Move a track to a new position in the vertical order (0-based index among
9160
+ * `<daw-track>` elements). Element-backed tracks move their DOM element —
9161
+ * the MutationObserver syncs the engine (single write path). Element-less
9162
+ * tracks (undo-resurrected) reorder the engine directly.
9163
+ */
9164
+ reorderTrack(trackId, toIndex) {
9165
+ if (!Number.isFinite(toIndex)) {
9166
+ console.warn("[dawcore] reorderTrack: invalid toIndex " + String(toIndex));
9167
+ return;
9168
+ }
9169
+ const el = this._trackElements.get(trackId);
9170
+ if (el) {
9171
+ const els = [...this.querySelectorAll("daw-track")];
9172
+ const from = els.indexOf(el);
9173
+ if (from === -1) return;
9174
+ const clamped = Math.max(0, Math.min(toIndex, els.length - 1));
9175
+ if (from === clamped) return;
9176
+ const anchor = els[clamped];
9177
+ if (clamped > from) anchor.after(el);
9178
+ else anchor.before(el);
9179
+ } else if (this._engineTracks.has(trackId)) {
9180
+ this._engine.reorderTrack(trackId, toIndex);
9181
+ this.requestUpdate();
9182
+ } else {
9183
+ console.warn('[dawcore] reorderTrack: no track found for id "' + trackId + '"');
9184
+ }
9185
+ }
7730
9186
  /**
7731
9187
  * Update reflected attributes on a track. For DOM-element tracks the changes
7732
9188
  * are written to the `<daw-track>` element (which fires `daw-track-update`);
@@ -7909,14 +9365,21 @@ var DawEditorElement = class extends LitElement11 {
7909
9365
  return clipEl;
7910
9366
  }
7911
9367
  // --- Playback ---
7912
- async play(startTime) {
9368
+ /**
9369
+ * Start playback, optionally seeking to `startTime` first. When `endTime`
9370
+ * is provided, playback stops at that time (selection/annotation playback).
9371
+ */
9372
+ async play(startTime, endTime) {
7913
9373
  try {
7914
9374
  const engine = await this._ensureEngine();
7915
9375
  await engine.init();
7916
- engine.play(startTime);
9376
+ this._activePlayEndTime = endTime ?? null;
7917
9377
  this._startPlayhead();
9378
+ engine.play(startTime, endTime);
7918
9379
  this.dispatchEvent(new CustomEvent("daw-play", { bubbles: true, composed: true }));
7919
9380
  } catch (err) {
9381
+ this._stopPlayhead();
9382
+ this._activePlayEndTime = null;
7920
9383
  console.warn("[dawcore] Playback failed: " + String(err));
7921
9384
  this.dispatchEvent(
7922
9385
  new CustomEvent("daw-error", {
@@ -7935,7 +9398,13 @@ var DawEditorElement = class extends LitElement11 {
7935
9398
  }
7936
9399
  stop() {
7937
9400
  if (!this._engine) return;
7938
- this._engine.stop();
9401
+ this._activePlayEndTime = null;
9402
+ this._inConsumerStop = true;
9403
+ try {
9404
+ this._engine.stop();
9405
+ } finally {
9406
+ this._inConsumerStop = false;
9407
+ }
7939
9408
  this._stopPlayhead();
7940
9409
  this.dispatchEvent(new CustomEvent("daw-stop", { bubbles: true, composed: true }));
7941
9410
  }
@@ -7989,6 +9458,7 @@ var DawEditorElement = class extends LitElement11 {
7989
9458
  );
7990
9459
  return;
7991
9460
  }
9461
+ this._activePlayEndTime = null;
7992
9462
  this._currentTime = target;
7993
9463
  this._startPlayhead();
7994
9464
  } else {
@@ -8156,16 +9626,16 @@ var DawEditorElement = class extends LitElement11 {
8156
9626
  const { left, width: w } = this._previewPosition(rs.startSample, audibleSamples);
8157
9627
  const hdrH = this.clipHeaders ? this.clipHeaderHeight : 0;
8158
9628
  const height = hdrH + chH * rs.peaks.length;
8159
- return html10`<div
9629
+ return html12`<div
8160
9630
  class="clip-container recording-preview"
8161
9631
  style="left:${left}px;top:0;width:${w}px;height:${height}px;"
8162
9632
  >
8163
- ${hdrH > 0 ? html10`<div class="clip-header" data-track-id=${trackId}>
9633
+ ${hdrH > 0 ? html12`<div class="clip-header" data-track-id=${trackId}>
8164
9634
  <span>${rs.clipName ?? "Recording\u2026"}</span>
8165
9635
  </div>` : ""}
8166
9636
  ${rs.peaks.map((chPeaks, ch) => {
8167
9637
  const slicedPeaks = latencyPixels > 0 ? chPeaks.slice(latencyPixels * 2) : chPeaks;
8168
- return html10`
9638
+ return html12`
8169
9639
  <daw-waveform
8170
9640
  data-recording-track=${trackId}
8171
9641
  data-recording-channel=${ch}
@@ -8188,6 +9658,11 @@ var DawEditorElement = class extends LitElement11 {
8188
9658
  if (!this._engine) return;
8189
9659
  const engine = this._engine;
8190
9660
  this._playbackAnimation.start(() => {
9661
+ if (this._activePlayEndTime !== null && !this.isRecording && engine.getCurrentTime() >= this._activePlayEndTime) {
9662
+ this.stop();
9663
+ const t = this._currentTime;
9664
+ return Number.isFinite(t) ? Math.max(0, t) : 0;
9665
+ }
8191
9666
  if (!this.indefinitePlayback && !this.isRecording && engine.getCurrentTime() >= this._duration) {
8192
9667
  this.stop();
8193
9668
  const t = this._currentTime;
@@ -8212,6 +9687,64 @@ var DawEditorElement = class extends LitElement11 {
8212
9687
  get _showRuler() {
8213
9688
  return (this._getOrderedTracks().length > 0 || this.scaleMode === "beats" || this.indefinitePlayback || this.fillViewport) && this.timescale;
8214
9689
  }
9690
+ /**
9691
+ * DOM → engine: make the engine's track order match the light-DOM
9692
+ * `<daw-track>` order. Single write path for reorders — editor-initiated
9693
+ * (buttons/drag move the element) and consumer-initiated (insertBefore)
9694
+ * mutations both land here via the MutationObserver. Element-less tracks
9695
+ * (undo-resurrected) keep their engine positions (stable sort).
9696
+ * Write-only-on-change: a no-op when orders already match, so the
9697
+ * engine→DOM direction (statechange handler) converges in one pass.
9698
+ */
9699
+ _syncEngineOrderToDom() {
9700
+ const engine = this._engine;
9701
+ if (!engine) return;
9702
+ const domOrder = [...this.querySelectorAll("daw-track")].map(
9703
+ (el) => el.trackId
9704
+ );
9705
+ const engineIds = engine.getState().tracks.map((t) => t.id);
9706
+ const target = [...engineIds].sort((a, b) => {
9707
+ const ai = domOrder.indexOf(a);
9708
+ const bi = domOrder.indexOf(b);
9709
+ if (ai === -1 || bi === -1) return 0;
9710
+ return ai - bi;
9711
+ });
9712
+ if (target.every((id, i) => id === engineIds[i])) return;
9713
+ this._inOrderSync = true;
9714
+ try {
9715
+ engine.beginTransaction();
9716
+ const current = [...engineIds];
9717
+ for (let i = 0; i < target.length; i++) {
9718
+ if (current[i] === target[i]) continue;
9719
+ engine.reorderTrack(target[i], i);
9720
+ const from = current.indexOf(target[i]);
9721
+ current.splice(from, 1);
9722
+ current.splice(i, 0, target[i]);
9723
+ }
9724
+ engine.commitTransaction();
9725
+ } finally {
9726
+ this._inOrderSync = false;
9727
+ }
9728
+ this.requestUpdate();
9729
+ }
9730
+ /**
9731
+ * Engine → DOM: after an engine-initiated order change (undo/redo), move
9732
+ * `<daw-track>` elements to match engine order. The resulting mutations fire
9733
+ * the observer's _syncEngineOrderToDom, which finds the orders equal and
9734
+ * no-ops — converges in one pass (write-only-on-change).
9735
+ */
9736
+ _syncDomToEngineOrder(tracks) {
9737
+ const els = [...this.querySelectorAll("daw-track")];
9738
+ if (els.length < 2) return;
9739
+ const byId = new Map(els.map((el) => [el.trackId, el]));
9740
+ const desired = tracks.map((t) => byId.get(t.id)).filter((el) => el != null);
9741
+ if (desired.length === 0) return;
9742
+ if (desired.every((el, i) => el === els[i])) return;
9743
+ if (els[0] !== desired[0]) els[0].before(desired[0]);
9744
+ for (let i = 1; i < desired.length; i++) {
9745
+ if (desired[i - 1].nextElementSibling !== desired[i]) desired[i - 1].after(desired[i]);
9746
+ }
9747
+ }
8215
9748
  _getOrderedTracks() {
8216
9749
  const domOrder = [...this.querySelectorAll("daw-track")].map(
8217
9750
  (el) => el.trackId
@@ -8255,9 +9788,9 @@ var DawEditorElement = class extends LitElement11 {
8255
9788
  });
8256
9789
  const showControls = this._showControls;
8257
9790
  const showRuler = this._showRuler;
8258
- return html10`
8259
- ${showRuler ? html10`<div class="header-row" style="height: ${RULER_HEIGHT}px;">
8260
- ${showControls ? html10`<div class="ruler-gap"></div>` : ""}
9791
+ return html12`
9792
+ ${showRuler ? html12`<div class="header-row" style="height: ${RULER_HEIGHT}px;">
9793
+ ${showControls ? html12`<div class="ruler-gap"></div>` : ""}
8261
9794
  <div class="ruler-viewport" @pointerdown=${this._pointer.onPointerDown}>
8262
9795
  <div
8263
9796
  class="ruler-content"
@@ -8278,10 +9811,18 @@ var DawEditorElement = class extends LitElement11 {
8278
9811
  </div>
8279
9812
  </div>` : ""}
8280
9813
  <div class="body">
8281
- ${showControls ? html10`<div class="controls-viewport">
9814
+ ${showControls ? html12`<div class="controls-viewport">
8282
9815
  <div class="controls-column">
9816
+ ${this._annotations.tracks.map(
9817
+ (track) => html12`<div
9818
+ class="annotation-lane-spacer"
9819
+ style="height: ${ANNOTATION_LANE_HEIGHT}px;"
9820
+ >
9821
+ <span class="annotation-lane-name">${track.name}</span>
9822
+ </div>`
9823
+ )}
8283
9824
  ${orderedTracks.map(
8284
- (t) => html10`
9825
+ (t, i) => html12`
8285
9826
  <daw-track-controls
8286
9827
  style="height: ${t.trackHeight}px;"
8287
9828
  .trackId=${t.trackId}
@@ -8290,6 +9831,9 @@ var DawEditorElement = class extends LitElement11 {
8290
9831
  .pan=${t.descriptor?.pan ?? 0}
8291
9832
  .muted=${t.descriptor?.muted ?? false}
8292
9833
  .soloed=${t.descriptor?.soloed ?? false}
9834
+ .reorderable=${this.trackReordering}
9835
+ .trackIndex=${i}
9836
+ .trackCount=${orderedTracks.length}
8293
9837
  ></daw-track-controls>
8294
9838
  `
8295
9839
  )}
@@ -8305,8 +9849,14 @@ var DawEditorElement = class extends LitElement11 {
8305
9849
  @dragleave=${this._onDragLeave}
8306
9850
  @drop=${this._onDrop}
8307
9851
  >
8308
- ${this.scaleMode === "beats" ? html10`<daw-grid
8309
- style="top: 0px;"
9852
+ ${this._annotations.renderLanes(
9853
+ spp,
9854
+ this.effectiveSampleRate,
9855
+ this._annotationDrag.onPointerDown,
9856
+ this.scaleMode === "beats" ? this.ticksPerPixel : null
9857
+ )}
9858
+ ${this.scaleMode === "beats" ? html12`<daw-grid
9859
+ style="top: ${this._annotations.totalLaneHeight}px;"
8310
9860
  .ticksPerPixel=${this.ticksPerPixel}
8311
9861
  .meterEntries=${this._meterEntries}
8312
9862
  .ppqn=${this.ppqn}
@@ -8315,11 +9865,11 @@ var DawEditorElement = class extends LitElement11 {
8315
9865
  .length=${this._totalWidth}
8316
9866
  .height=${orderedTracks.length > 0 ? orderedTracks.reduce((sum, t) => sum + t.trackHeight, 0) : this._emptyGridHeight}
8317
9867
  ></daw-grid>` : ""}
8318
- ${orderedTracks.length > 0 || this.scaleMode === "beats" || this.indefinitePlayback || this.fillViewport ? html10`<daw-selection .startPx=${selStartPx} .endPx=${selEndPx}></daw-selection>
9868
+ ${orderedTracks.length > 0 || this.scaleMode === "beats" || this.indefinitePlayback || this.fillViewport ? html12`<daw-selection .startPx=${selStartPx} .endPx=${selEndPx}></daw-selection>
8319
9869
  <daw-playhead></daw-playhead>` : ""}
8320
9870
  ${orderedTracks.map((t) => {
8321
9871
  const channelHeight = this.waveHeight;
8322
- return html10`
9872
+ return html12`
8323
9873
  <div
8324
9874
  class="track-row ${t.trackId === this._selectedTrackId ? "selected" : ""}"
8325
9875
  style="height: ${t.trackHeight}px;"
@@ -8385,12 +9935,12 @@ var DawEditorElement = class extends LitElement11 {
8385
9935
  const channels = segmentChannels ?? peakData?.data ?? [new Int16Array(0)];
8386
9936
  const hdrH = this.clipHeaders ? this.clipHeaderHeight : 0;
8387
9937
  const chH = this.waveHeight;
8388
- return html10` <div
9938
+ return html12` <div
8389
9939
  class="clip-container"
8390
9940
  style="left:${clipLeft}px;top:0;width:${width}px;height:${t.trackHeight}px;"
8391
9941
  data-clip-id=${clip.id}
8392
9942
  >
8393
- ${hdrH > 0 ? html10`<div
9943
+ ${hdrH > 0 ? html12`<div
8394
9944
  class="clip-header"
8395
9945
  data-clip-id=${clip.id}
8396
9946
  data-track-id=${t.trackId}
@@ -8398,7 +9948,7 @@ var DawEditorElement = class extends LitElement11 {
8398
9948
  >
8399
9949
  <span>${clip.name || t.descriptor?.name || ""}</span>
8400
9950
  </div>` : ""}
8401
- ${t.descriptor?.renderMode === "piano-roll" ? html10`<daw-piano-roll
9951
+ ${t.descriptor?.renderMode === "piano-roll" ? html12`<daw-piano-roll
8402
9952
  style="position:absolute;left:0;top:${hdrH}px;"
8403
9953
  .midiNotes=${clip.midiNotes ?? []}
8404
9954
  .length=${peakData?.length ?? width}
@@ -8411,7 +9961,7 @@ var DawEditorElement = class extends LitElement11 {
8411
9961
  .originX=${clipLeft}
8412
9962
  ?selected=${t.trackId === this._selectedTrackId}
8413
9963
  ></daw-piano-roll>` : t.descriptor?.renderMode === "spectrogram" ? channels.map(
8414
- (_chPeaks, chIdx) => html10`<daw-spectrogram
9964
+ (_chPeaks, chIdx) => html12`<daw-spectrogram
8415
9965
  style="position:absolute;left:0;top:${hdrH + chIdx * chH}px;height:${chH}px;width:${peakData?.length ?? width}px;"
8416
9966
  .clipId=${clip.id}
8417
9967
  .trackId=${t.trackId}
@@ -8426,7 +9976,7 @@ var DawEditorElement = class extends LitElement11 {
8426
9976
  .originX=${clipLeft}
8427
9977
  ></daw-spectrogram>`
8428
9978
  ) : channels.map(
8429
- (chPeaks, chIdx) => html10` <daw-waveform
9979
+ (chPeaks, chIdx) => html12` <daw-waveform
8430
9980
  style="position:absolute;left:0;top:${hdrH + chIdx * chH}px;"
8431
9981
  .peaks=${chPeaks}
8432
9982
  .length=${peakData?.length ?? width}
@@ -8440,7 +9990,7 @@ var DawEditorElement = class extends LitElement11 {
8440
9990
  .segments=${clipSegments}
8441
9991
  ></daw-waveform>`
8442
9992
  )}
8443
- ${this.interactiveClips ? html10` <div
9993
+ ${this.interactiveClips ? html12` <div
8444
9994
  class="clip-boundary"
8445
9995
  data-boundary-edge="left"
8446
9996
  data-clip-id=${clip.id}
@@ -8467,7 +10017,7 @@ var DawEditorElement = class extends LitElement11 {
8467
10017
  };
8468
10018
  DawEditorElement.styles = [
8469
10019
  hostStyles,
8470
- css10`
10020
+ css11`
8471
10021
  :host {
8472
10022
  display: flex;
8473
10023
  flex-direction: column;
@@ -8525,6 +10075,9 @@ DawEditorElement.styles = [
8525
10075
  .track-row.selected {
8526
10076
  background: rgba(99, 199, 95, 0.08);
8527
10077
  }
10078
+ .track-row[data-track-drag-source] {
10079
+ background: rgba(99, 199, 95, 0.08);
10080
+ }
8528
10081
  :host([scale-mode='beats']) .track-row {
8529
10082
  background: transparent;
8530
10083
  }
@@ -8538,120 +10091,189 @@ DawEditorElement.styles = [
8538
10091
  outline: 2px dashed var(--daw-selection-color, rgba(99, 199, 95, 0.3));
8539
10092
  outline-offset: -2px;
8540
10093
  }
10094
+ .annotation-lane {
10095
+ position: relative;
10096
+ box-sizing: border-box;
10097
+ border-bottom: 1px solid var(--daw-annotation-lane-border, rgba(255, 255, 255, 0.08));
10098
+ background: var(--daw-annotation-lane-background, rgba(0, 0, 0, 0.15));
10099
+ user-select: none;
10100
+ -webkit-user-drag: none;
10101
+ }
10102
+ .annotation-lane-spacer {
10103
+ box-sizing: border-box;
10104
+ border-bottom: 1px solid var(--daw-annotation-lane-border, rgba(255, 255, 255, 0.08));
10105
+ display: flex;
10106
+ align-items: center;
10107
+ overflow: hidden;
10108
+ }
10109
+ .annotation-lane-name {
10110
+ padding: 0 10px;
10111
+ font-size: 11px;
10112
+ color: var(--daw-controls-text, #e0d4c8);
10113
+ opacity: 0.8;
10114
+ white-space: nowrap;
10115
+ overflow: hidden;
10116
+ text-overflow: ellipsis;
10117
+ }
10118
+ .annotation-box {
10119
+ position: absolute;
10120
+ top: 3px;
10121
+ bottom: 3px;
10122
+ overflow: hidden;
10123
+ display: flex;
10124
+ align-items: center;
10125
+ border: 1px solid var(--daw-annotation-box-border, #c49a6c);
10126
+ border-radius: 3px;
10127
+ background: var(--daw-annotation-box-background, rgba(196, 154, 108, 0.2));
10128
+ color: var(--daw-annotation-text-color, #e0d4c8);
10129
+ font-size: 11px;
10130
+ cursor: pointer;
10131
+ }
10132
+ .annotation-box.playing {
10133
+ box-shadow: inset 0 0 0 1px var(--daw-annotation-box-border, #c49a6c);
10134
+ background: var(--daw-annotation-playing-background, rgba(196, 154, 108, 0.32));
10135
+ }
10136
+ .annotation-box.active {
10137
+ background: var(--daw-annotation-active-background, rgba(196, 154, 108, 0.45));
10138
+ }
10139
+ .annotation-box-text {
10140
+ padding: 0 6px;
10141
+ white-space: nowrap;
10142
+ overflow: hidden;
10143
+ text-overflow: ellipsis;
10144
+ pointer-events: none;
10145
+ }
10146
+ .annotation-boundary {
10147
+ position: absolute;
10148
+ top: 0;
10149
+ bottom: 0;
10150
+ width: 6px;
10151
+ cursor: ew-resize;
10152
+ flex-shrink: 0;
10153
+ }
10154
+ .annotation-boundary[data-edge='start'] {
10155
+ left: 0;
10156
+ }
10157
+ .annotation-boundary[data-edge='end'] {
10158
+ right: 0;
10159
+ }
8541
10160
  `,
8542
10161
  clipStyles
8543
10162
  ];
8544
10163
  DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "muted", "soloed"]);
8545
10164
  __decorateClass([
8546
- property9({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
10165
+ property12({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
8547
10166
  ], DawEditorElement.prototype, "samplesPerPixel", 1);
8548
10167
  __decorateClass([
8549
- property9({ attribute: "time-format", reflect: true, noAccessor: true })
10168
+ property12({ attribute: "time-format", reflect: true, noAccessor: true })
8550
10169
  ], DawEditorElement.prototype, "timeFormat", 1);
8551
10170
  __decorateClass([
8552
- property9({ type: Number, attribute: "wave-height" })
10171
+ property12({ type: Number, attribute: "wave-height" })
8553
10172
  ], DawEditorElement.prototype, "waveHeight", 2);
8554
10173
  __decorateClass([
8555
- property9({ type: Boolean })
10174
+ property12({ type: Boolean })
8556
10175
  ], DawEditorElement.prototype, "timescale", 2);
8557
10176
  __decorateClass([
8558
- property9({ type: Boolean })
10177
+ property12({ type: Boolean })
8559
10178
  ], DawEditorElement.prototype, "mono", 2);
8560
10179
  __decorateClass([
8561
- property9({ type: Number, attribute: "bar-width" })
10180
+ property12({ type: Number, attribute: "bar-width" })
8562
10181
  ], DawEditorElement.prototype, "barWidth", 2);
8563
10182
  __decorateClass([
8564
- property9({ type: Number, attribute: "bar-gap" })
10183
+ property12({ type: Number, attribute: "bar-gap" })
8565
10184
  ], DawEditorElement.prototype, "barGap", 2);
8566
10185
  __decorateClass([
8567
- property9({ type: Boolean, attribute: "rounded-bars" })
10186
+ property12({ type: Boolean, attribute: "rounded-bars" })
8568
10187
  ], DawEditorElement.prototype, "roundedBars", 2);
8569
10188
  __decorateClass([
8570
- property9({ type: Boolean, attribute: "file-drop" })
10189
+ property12({ type: Boolean, attribute: "file-drop" })
8571
10190
  ], DawEditorElement.prototype, "fileDrop", 2);
8572
10191
  __decorateClass([
8573
- property9({ type: Boolean, attribute: "clip-headers" })
10192
+ property12({ type: Boolean, attribute: "clip-headers" })
8574
10193
  ], DawEditorElement.prototype, "clipHeaders", 2);
8575
10194
  __decorateClass([
8576
- property9({ type: Number, attribute: "clip-header-height" })
10195
+ property12({ type: Number, attribute: "clip-header-height" })
8577
10196
  ], DawEditorElement.prototype, "clipHeaderHeight", 2);
8578
10197
  __decorateClass([
8579
- property9({ type: Boolean, attribute: "interactive-clips" })
10198
+ property12({ type: Boolean, attribute: "interactive-clips" })
8580
10199
  ], DawEditorElement.prototype, "interactiveClips", 2);
8581
10200
  __decorateClass([
8582
- property9({ type: Boolean, attribute: "indefinite-playback" })
10201
+ property12({ type: Boolean, attribute: "indefinite-playback" })
8583
10202
  ], DawEditorElement.prototype, "indefinitePlayback", 2);
8584
10203
  __decorateClass([
8585
- property9({ type: Boolean, attribute: "fill-viewport" })
10204
+ property12({ type: Boolean, attribute: "fill-viewport" })
8586
10205
  ], DawEditorElement.prototype, "fillViewport", 2);
8587
10206
  __decorateClass([
8588
- property9({ attribute: false, noAccessor: true })
10207
+ property12({ type: Boolean, attribute: "track-reordering" })
10208
+ ], DawEditorElement.prototype, "trackReordering", 2);
10209
+ __decorateClass([
10210
+ property12({ attribute: false, noAccessor: true })
8589
10211
  ], DawEditorElement.prototype, "spectrogramConfig", 1);
8590
10212
  __decorateClass([
8591
- property9({ attribute: false, noAccessor: true })
10213
+ property12({ attribute: false, noAccessor: true })
8592
10214
  ], DawEditorElement.prototype, "spectrogramColorMap", 1);
8593
10215
  __decorateClass([
8594
- property9({ type: String, attribute: "scale-mode" })
10216
+ property12({ type: String, attribute: "scale-mode" })
8595
10217
  ], DawEditorElement.prototype, "scaleMode", 2);
8596
10218
  __decorateClass([
8597
- property9({ type: Number, attribute: "ticks-per-pixel", noAccessor: true })
10219
+ property12({ type: Number, attribute: "ticks-per-pixel", noAccessor: true })
8598
10220
  ], DawEditorElement.prototype, "ticksPerPixel", 1);
8599
10221
  __decorateClass([
8600
- property9({ type: Number, noAccessor: true })
10222
+ property12({ type: Number, noAccessor: true })
8601
10223
  ], DawEditorElement.prototype, "bpm", 1);
8602
10224
  __decorateClass([
8603
- property9({ attribute: false })
10225
+ property12({ attribute: false })
8604
10226
  ], DawEditorElement.prototype, "timeSignature", 2);
8605
10227
  __decorateClass([
8606
- property9({ attribute: false })
10228
+ property12({ attribute: false })
8607
10229
  ], DawEditorElement.prototype, "meterEntries", 2);
8608
10230
  __decorateClass([
8609
- property9({ type: Number, noAccessor: true })
10231
+ property12({ type: Number, noAccessor: true })
8610
10232
  ], DawEditorElement.prototype, "ppqn", 1);
8611
10233
  __decorateClass([
8612
- property9({ type: String, attribute: "snap-to" })
10234
+ property12({ type: String, attribute: "snap-to" })
8613
10235
  ], DawEditorElement.prototype, "snapTo", 2);
8614
10236
  __decorateClass([
8615
- property9({ attribute: false })
10237
+ property12({ attribute: false })
8616
10238
  ], DawEditorElement.prototype, "secondsToTicks", 2);
8617
10239
  __decorateClass([
8618
- property9({ attribute: false })
10240
+ property12({ attribute: false })
8619
10241
  ], DawEditorElement.prototype, "ticksToSeconds", 2);
8620
10242
  __decorateClass([
8621
- state3()
10243
+ state4()
8622
10244
  ], DawEditorElement.prototype, "_tracks", 2);
8623
10245
  __decorateClass([
8624
- state3()
10246
+ state4()
8625
10247
  ], DawEditorElement.prototype, "_engineTracks", 2);
8626
10248
  __decorateClass([
8627
- state3()
10249
+ state4()
8628
10250
  ], DawEditorElement.prototype, "_peaksData", 2);
8629
10251
  __decorateClass([
8630
- state3()
10252
+ state4()
8631
10253
  ], DawEditorElement.prototype, "_isPlaying", 2);
8632
10254
  __decorateClass([
8633
- state3()
10255
+ state4()
8634
10256
  ], DawEditorElement.prototype, "_duration", 2);
8635
10257
  __decorateClass([
8636
- state3()
10258
+ state4()
8637
10259
  ], DawEditorElement.prototype, "_selectedTrackId", 2);
8638
10260
  __decorateClass([
8639
- state3()
10261
+ state4()
8640
10262
  ], DawEditorElement.prototype, "_dragOver", 2);
8641
10263
  __decorateClass([
8642
- property9({ attribute: false })
10264
+ property12({ attribute: false })
8643
10265
  ], DawEditorElement.prototype, "adapter", 1);
8644
10266
  __decorateClass([
8645
- property9({ attribute: "eager-resume" })
10267
+ property12({ attribute: "eager-resume" })
8646
10268
  ], DawEditorElement.prototype, "eagerResume", 2);
8647
10269
  DawEditorElement = __decorateClass([
8648
- customElement13("daw-editor")
10270
+ customElement16("daw-editor")
8649
10271
  ], DawEditorElement);
8650
10272
 
8651
10273
  // src/elements/daw-selection.ts
8652
- import { LitElement as LitElement12, html as html11, css as css11 } from "lit";
8653
- import { customElement as customElement14, property as property10 } from "lit/decorators.js";
8654
- var DawSelectionElement = class extends LitElement12 {
10274
+ import { LitElement as LitElement15, html as html13, css as css12 } from "lit";
10275
+ import { customElement as customElement17, property as property13 } from "lit/decorators.js";
10276
+ var DawSelectionElement = class extends LitElement15 {
8655
10277
  constructor() {
8656
10278
  super(...arguments);
8657
10279
  this.startPx = 0;
@@ -8660,11 +10282,11 @@ var DawSelectionElement = class extends LitElement12 {
8660
10282
  render() {
8661
10283
  const left = Math.min(this.startPx, this.endPx);
8662
10284
  const width = Math.abs(this.endPx - this.startPx);
8663
- if (width === 0) return html11``;
8664
- return html11`<div style="left: ${left}px; width: ${width}px;"></div>`;
10285
+ if (width === 0) return html13``;
10286
+ return html13`<div style="left: ${left}px; width: ${width}px;"></div>`;
8665
10287
  }
8666
10288
  };
8667
- DawSelectionElement.styles = css11`
10289
+ DawSelectionElement.styles = css12`
8668
10290
  :host {
8669
10291
  position: absolute;
8670
10292
  top: 0;
@@ -8681,18 +10303,18 @@ DawSelectionElement.styles = css11`
8681
10303
  }
8682
10304
  `;
8683
10305
  __decorateClass([
8684
- property10({ type: Number, attribute: false })
10306
+ property13({ type: Number, attribute: false })
8685
10307
  ], DawSelectionElement.prototype, "startPx", 2);
8686
10308
  __decorateClass([
8687
- property10({ type: Number, attribute: false })
10309
+ property13({ type: Number, attribute: false })
8688
10310
  ], DawSelectionElement.prototype, "endPx", 2);
8689
10311
  DawSelectionElement = __decorateClass([
8690
- customElement14("daw-selection")
10312
+ customElement17("daw-selection")
8691
10313
  ], DawSelectionElement);
8692
10314
 
8693
10315
  // src/elements/daw-record-button.ts
8694
- import { html as html12, css as css12 } from "lit";
8695
- import { customElement as customElement15, state as state4 } from "lit/decorators.js";
10316
+ import { html as html14, css as css13 } from "lit";
10317
+ import { customElement as customElement18, state as state5 } from "lit/decorators.js";
8696
10318
  var DawRecordButtonElement = class extends DawTransportButton {
8697
10319
  constructor() {
8698
10320
  super(...arguments);
@@ -8741,7 +10363,7 @@ var DawRecordButtonElement = class extends DawTransportButton {
8741
10363
  }
8742
10364
  }
8743
10365
  render() {
8744
- return html12`
10366
+ return html14`
8745
10367
  <button
8746
10368
  part="button"
8747
10369
  ?disabled=${!this.targetSupported}
@@ -8769,7 +10391,7 @@ DawRecordButtonElement.requiredTargetMethods = [
8769
10391
  ];
8770
10392
  DawRecordButtonElement.styles = [
8771
10393
  DawTransportButton.styles,
8772
- css12`
10394
+ css13`
8773
10395
  button[data-recording] {
8774
10396
  color: #d08070;
8775
10397
  border-color: #d08070;
@@ -8778,17 +10400,17 @@ DawRecordButtonElement.styles = [
8778
10400
  `
8779
10401
  ];
8780
10402
  __decorateClass([
8781
- state4()
10403
+ state5()
8782
10404
  ], DawRecordButtonElement.prototype, "_isRecording", 2);
8783
10405
  DawRecordButtonElement = __decorateClass([
8784
- customElement15("daw-record-button")
10406
+ customElement18("daw-record-button")
8785
10407
  ], DawRecordButtonElement);
8786
10408
 
8787
10409
  // src/elements/daw-keyboard-shortcuts.ts
8788
- import { LitElement as LitElement13 } from "lit";
8789
- import { customElement as customElement16, property as property11 } from "lit/decorators.js";
10410
+ import { LitElement as LitElement16 } from "lit";
10411
+ import { customElement as customElement19, property as property14 } from "lit/decorators.js";
8790
10412
  import { handleKeyboardEvent } from "@waveform-playlist/core";
8791
- var DawKeyboardShortcutsElement = class extends LitElement13 {
10413
+ var DawKeyboardShortcutsElement = class extends LitElement16 {
8792
10414
  constructor() {
8793
10415
  super(...arguments);
8794
10416
  this.playback = false;
@@ -8987,23 +10609,23 @@ var DawKeyboardShortcutsElement = class extends LitElement13 {
8987
10609
  }
8988
10610
  };
8989
10611
  __decorateClass([
8990
- property11({ type: Boolean })
10612
+ property14({ type: Boolean })
8991
10613
  ], DawKeyboardShortcutsElement.prototype, "playback", 2);
8992
10614
  __decorateClass([
8993
- property11({ type: Boolean })
10615
+ property14({ type: Boolean })
8994
10616
  ], DawKeyboardShortcutsElement.prototype, "splitting", 2);
8995
10617
  __decorateClass([
8996
- property11({ type: Boolean })
10618
+ property14({ type: Boolean })
8997
10619
  ], DawKeyboardShortcutsElement.prototype, "undo", 2);
8998
10620
  DawKeyboardShortcutsElement = __decorateClass([
8999
- customElement16("daw-keyboard-shortcuts")
10621
+ customElement19("daw-keyboard-shortcuts")
9000
10622
  ], DawKeyboardShortcutsElement);
9001
10623
 
9002
10624
  // src/elements/daw-spectrogram.ts
9003
- import { LitElement as LitElement14, html as html13, css as css13 } from "lit";
9004
- import { customElement as customElement17, property as property12 } from "lit/decorators.js";
10625
+ import { LitElement as LitElement17, html as html15, css as css14 } from "lit";
10626
+ import { customElement as customElement20, property as property15 } from "lit/decorators.js";
9005
10627
  import { MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH5, buildSpectrogramCanvasId } from "@waveform-playlist/core";
9006
- var DawSpectrogramElement = class extends LitElement14 {
10628
+ var DawSpectrogramElement = class extends LitElement17 {
9007
10629
  constructor() {
9008
10630
  super(...arguments);
9009
10631
  this.clipId = "";
@@ -9139,10 +10761,10 @@ var DawSpectrogramElement = class extends LitElement14 {
9139
10761
  this._unregisterAllCanvases();
9140
10762
  }
9141
10763
  render() {
9142
- return html13`${this._canvases.map((c) => c)}`;
10764
+ return html15`${this._canvases.map((c) => c)}`;
9143
10765
  }
9144
10766
  };
9145
- DawSpectrogramElement.styles = css13`
10767
+ DawSpectrogramElement.styles = css14`
9146
10768
  :host {
9147
10769
  display: block;
9148
10770
  position: relative;
@@ -9157,46 +10779,46 @@ DawSpectrogramElement.styles = css13`
9157
10779
  }
9158
10780
  `;
9159
10781
  __decorateClass([
9160
- property12({ attribute: false })
10782
+ property15({ attribute: false })
9161
10783
  ], DawSpectrogramElement.prototype, "clipId", 2);
9162
10784
  __decorateClass([
9163
- property12({ attribute: false })
10785
+ property15({ attribute: false })
9164
10786
  ], DawSpectrogramElement.prototype, "trackId", 2);
9165
10787
  __decorateClass([
9166
- property12({ type: Number, attribute: false })
10788
+ property15({ type: Number, attribute: false })
9167
10789
  ], DawSpectrogramElement.prototype, "channelIndex", 2);
9168
10790
  __decorateClass([
9169
- property12({ type: Number, attribute: false })
10791
+ property15({ type: Number, attribute: false })
9170
10792
  ], DawSpectrogramElement.prototype, "length", 2);
9171
10793
  __decorateClass([
9172
- property12({ type: Number, attribute: false })
10794
+ property15({ type: Number, attribute: false })
9173
10795
  ], DawSpectrogramElement.prototype, "waveHeight", 2);
9174
10796
  __decorateClass([
9175
- property12({ type: Number, attribute: false, noAccessor: true })
10797
+ property15({ type: Number, attribute: false, noAccessor: true })
9176
10798
  ], DawSpectrogramElement.prototype, "samplesPerPixel", 1);
9177
10799
  __decorateClass([
9178
- property12({ type: Number, attribute: false, noAccessor: true })
10800
+ property15({ type: Number, attribute: false, noAccessor: true })
9179
10801
  ], DawSpectrogramElement.prototype, "sampleRate", 1);
9180
10802
  __decorateClass([
9181
- property12({ type: Number, attribute: false })
10803
+ property15({ type: Number, attribute: false })
9182
10804
  ], DawSpectrogramElement.prototype, "clipOffsetSeconds", 2);
9183
10805
  __decorateClass([
9184
- property12({ type: Number, attribute: false })
10806
+ property15({ type: Number, attribute: false })
9185
10807
  ], DawSpectrogramElement.prototype, "visibleStart", 2);
9186
10808
  __decorateClass([
9187
- property12({ type: Number, attribute: false })
10809
+ property15({ type: Number, attribute: false })
9188
10810
  ], DawSpectrogramElement.prototype, "visibleEnd", 2);
9189
10811
  __decorateClass([
9190
- property12({ type: Number, attribute: false })
10812
+ property15({ type: Number, attribute: false })
9191
10813
  ], DawSpectrogramElement.prototype, "originX", 2);
9192
10814
  DawSpectrogramElement = __decorateClass([
9193
- customElement17("daw-spectrogram")
10815
+ customElement20("daw-spectrogram")
9194
10816
  ], DawSpectrogramElement);
9195
10817
 
9196
10818
  // src/elements/daw-time-display.ts
9197
- import { LitElement as LitElement15, html as html14, css as css14 } from "lit";
9198
- import { customElement as customElement18, state as state5 } from "lit/decorators.js";
9199
- var DawTimeDisplayElement = class extends LitElement15 {
10819
+ import { LitElement as LitElement18, html as html16, css as css15 } from "lit";
10820
+ import { customElement as customElement21, state as state6 } from "lit/decorators.js";
10821
+ var DawTimeDisplayElement = class extends LitElement18 {
9200
10822
  constructor() {
9201
10823
  super(...arguments);
9202
10824
  this._time = null;
@@ -9249,10 +10871,10 @@ var DawTimeDisplayElement = class extends LitElement15 {
9249
10871
  }
9250
10872
  render() {
9251
10873
  const text = this._time === null ? "--:--:--" : formatDisplayTime(this._time, this._format);
9252
- return html14`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
10874
+ return html16`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
9253
10875
  }
9254
10876
  };
9255
- DawTimeDisplayElement.styles = css14`
10877
+ DawTimeDisplayElement.styles = css15`
9256
10878
  span {
9257
10879
  display: inline-block;
9258
10880
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
@@ -9264,19 +10886,19 @@ DawTimeDisplayElement.styles = css14`
9264
10886
  }
9265
10887
  `;
9266
10888
  __decorateClass([
9267
- state5()
10889
+ state6()
9268
10890
  ], DawTimeDisplayElement.prototype, "_time", 2);
9269
10891
  __decorateClass([
9270
- state5()
10892
+ state6()
9271
10893
  ], DawTimeDisplayElement.prototype, "_format", 2);
9272
10894
  DawTimeDisplayElement = __decorateClass([
9273
- customElement18("daw-time-display")
10895
+ customElement21("daw-time-display")
9274
10896
  ], DawTimeDisplayElement);
9275
10897
 
9276
10898
  // src/elements/daw-time-format.ts
9277
- import { LitElement as LitElement16, html as html15, css as css15 } from "lit";
9278
- import { customElement as customElement19, state as state6 } from "lit/decorators.js";
9279
- var DawTimeFormatElement = class extends LitElement16 {
10899
+ import { LitElement as LitElement19, html as html17, css as css16 } from "lit";
10900
+ import { customElement as customElement22, state as state7 } from "lit/decorators.js";
10901
+ var DawTimeFormatElement = class extends LitElement19 {
9280
10902
  constructor() {
9281
10903
  super(...arguments);
9282
10904
  this._format = "hh:mm:ss.sss";
@@ -9351,20 +10973,20 @@ var DawTimeFormatElement = class extends LitElement16 {
9351
10973
  target.setTimeFormat?.(value);
9352
10974
  }
9353
10975
  render() {
9354
- return html15`
10976
+ return html17`
9355
10977
  <select
9356
10978
  aria-label="Time format"
9357
10979
  ?disabled=${!this._targetSupported}
9358
10980
  @change=${this._onSelectChange}
9359
10981
  >
9360
10982
  ${TIME_DISPLAY_FORMATS.map(
9361
- (f) => html15`<option value=${f} ?selected=${f === this._format}>${f}</option>`
10983
+ (f) => html17`<option value=${f} ?selected=${f === this._format}>${f}</option>`
9362
10984
  )}
9363
10985
  </select>
9364
10986
  `;
9365
10987
  }
9366
10988
  };
9367
- DawTimeFormatElement.styles = css15`
10989
+ DawTimeFormatElement.styles = css16`
9368
10990
  select {
9369
10991
  cursor: pointer;
9370
10992
  background: var(--daw-controls-background, #1a1a2e);
@@ -9379,20 +11001,20 @@ DawTimeFormatElement.styles = css15`
9379
11001
  }
9380
11002
  `;
9381
11003
  __decorateClass([
9382
- state6()
11004
+ state7()
9383
11005
  ], DawTimeFormatElement.prototype, "_format", 2);
9384
11006
  DawTimeFormatElement = __decorateClass([
9385
- customElement19("daw-time-format")
11007
+ customElement22("daw-time-format")
9386
11008
  ], DawTimeFormatElement);
9387
11009
 
9388
11010
  // src/elements/daw-player.ts
9389
- import { LitElement as LitElement17, html as html16, css as css16 } from "lit";
9390
- import { customElement as customElement20, property as property13, state as state7 } from "lit/decorators.js";
11011
+ import { LitElement as LitElement20, html as html18, css as css17 } from "lit";
11012
+ import { customElement as customElement23, property as property16, state as state8 } from "lit/decorators.js";
9391
11013
  import { repeat } from "lit/directives/repeat.js";
9392
11014
  import { MediaElementPlayout } from "@waveform-playlist/media-element-playout";
9393
11015
  var MIN_RATE = 0.25;
9394
11016
  var MAX_RATE = 4;
9395
- var DawPlayerElement = class extends LitElement17 {
11017
+ var DawPlayerElement = class extends LitElement20 {
9396
11018
  constructor() {
9397
11019
  super(...arguments);
9398
11020
  this.src = "";
@@ -9500,8 +11122,8 @@ var DawPlayerElement = class extends LitElement17 {
9500
11122
  const width = this._timelineWidth;
9501
11123
  const channels = this._channelPeaks.length;
9502
11124
  const channelHeight = channels > 0 ? this.waveHeight / channels : this.waveHeight;
9503
- return html16`
9504
- ${this.timescale ? html16`<daw-ruler
11125
+ return html18`
11126
+ ${this.timescale ? html18`<daw-ruler
9505
11127
  .samplesPerPixel=${this._channelSpp(width)}
9506
11128
  .sampleRate=${this._sampleRate}
9507
11129
  .duration=${this._engine.duration}
@@ -9515,7 +11137,7 @@ var DawPlayerElement = class extends LitElement17 {
9515
11137
  ${repeat(
9516
11138
  this._channelPeaks,
9517
11139
  (_p, i) => i,
9518
- (peaks) => html16`<daw-waveform
11140
+ (peaks) => html18`<daw-waveform
9519
11141
  .peaks=${peaks}
9520
11142
  .length=${width}
9521
11143
  .waveHeight=${channelHeight}
@@ -9678,7 +11300,7 @@ var DawPlayerElement = class extends LitElement17 {
9678
11300
  return this.shadowRoot?.querySelector(".waveform-area")?.clientWidth ?? 0;
9679
11301
  }
9680
11302
  };
9681
- DawPlayerElement.styles = css16`
11303
+ DawPlayerElement.styles = css17`
9682
11304
  :host {
9683
11305
  display: block;
9684
11306
  position: relative;
@@ -9691,41 +11313,45 @@ DawPlayerElement.styles = css16`
9691
11313
  }
9692
11314
  `;
9693
11315
  __decorateClass([
9694
- property13({ type: String })
11316
+ property16({ type: String })
9695
11317
  ], DawPlayerElement.prototype, "src", 2);
9696
11318
  __decorateClass([
9697
- property13({ type: String, attribute: "peaks-src" })
11319
+ property16({ type: String, attribute: "peaks-src" })
9698
11320
  ], DawPlayerElement.prototype, "peaksSrc", 2);
9699
11321
  __decorateClass([
9700
- property13({ type: Number, attribute: "wave-height" })
11322
+ property16({ type: Number, attribute: "wave-height" })
9701
11323
  ], DawPlayerElement.prototype, "waveHeight", 2);
9702
11324
  __decorateClass([
9703
- property13({ type: Boolean })
11325
+ property16({ type: Boolean })
9704
11326
  ], DawPlayerElement.prototype, "timescale", 2);
9705
11327
  __decorateClass([
9706
- property13({ type: Boolean })
11328
+ property16({ type: Boolean })
9707
11329
  ], DawPlayerElement.prototype, "mono", 2);
9708
11330
  __decorateClass([
9709
- property13({ type: Number, attribute: "bar-width" })
11331
+ property16({ type: Number, attribute: "bar-width" })
9710
11332
  ], DawPlayerElement.prototype, "barWidth", 2);
9711
11333
  __decorateClass([
9712
- property13({ type: Number, attribute: "bar-gap" })
11334
+ property16({ type: Number, attribute: "bar-gap" })
9713
11335
  ], DawPlayerElement.prototype, "barGap", 2);
9714
11336
  __decorateClass([
9715
- property13({ type: Boolean, attribute: "rounded-bars" })
11337
+ property16({ type: Boolean, attribute: "rounded-bars" })
9716
11338
  ], DawPlayerElement.prototype, "roundedBars", 2);
9717
11339
  __decorateClass([
9718
- property13({ type: Number, attribute: "playback-rate", noAccessor: true })
11340
+ property16({ type: Number, attribute: "playback-rate", noAccessor: true })
9719
11341
  ], DawPlayerElement.prototype, "playbackRate", 1);
9720
11342
  __decorateClass([
9721
- state7()
11343
+ state8()
9722
11344
  ], DawPlayerElement.prototype, "_channelPeaks", 2);
9723
11345
  DawPlayerElement = __decorateClass([
9724
- customElement20("daw-player")
11346
+ customElement23("daw-player")
9725
11347
  ], DawPlayerElement);
9726
11348
  export {
11349
+ ANNOTATION_LANE_HEIGHT,
9727
11350
  AudioResumeController,
9728
11351
  ClipPointerHandler,
11352
+ DawAnnotationElement,
11353
+ DawAnnotationListElement,
11354
+ DawAnnotationTrackElement,
9729
11355
  DawClipElement,
9730
11356
  DawEditorElement,
9731
11357
  DawGridElement,