@dawcore/components 0.0.34 → 0.0.35

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-annotation.ts
13
+ import { LitElement } from "lit";
14
+ import { customElement, property } from "lit/decorators.js";
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
+
12
825
  // src/elements/daw-clip.ts
13
- import { LitElement } from "lit";
14
- import { customElement, property } from "lit/decorators.js";
15
- var DawClipElement = class extends LitElement {
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) {
@@ -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;
@@ -2161,7 +2974,7 @@ var DawTrackControlsElement = class extends LitElement9 {
2161
2974
  const volPercent = Math.round(this.volume * 100);
2162
2975
  const panPercent = Math.round(Math.abs(this.pan) * 100);
2163
2976
  const panDisplay = this.pan === 0 ? "C" : (this.pan > 0 ? "R" : "L") + panPercent;
2164
- return html8`
2977
+ return html9`
2165
2978
  <div class="header">
2166
2979
  <span class="name" title=${this.trackName}>${this.trackName || "Untitled"}</span>
2167
2980
  <button class="remove-btn" @click=${this._onRemoveClick} title="Remove track">
@@ -2211,7 +3024,7 @@ var DawTrackControlsElement = class extends LitElement9 {
2211
3024
  `;
2212
3025
  }
2213
3026
  };
2214
- DawTrackControlsElement.styles = css7`
3027
+ DawTrackControlsElement.styles = css8`
2215
3028
  :host {
2216
3029
  display: flex;
2217
3030
  flex-direction: column;
@@ -2363,33 +3176,33 @@ DawTrackControlsElement.styles = css7`
2363
3176
  }
2364
3177
  `;
2365
3178
  __decorateClass([
2366
- property7({ attribute: false })
3179
+ property10({ attribute: false })
2367
3180
  ], DawTrackControlsElement.prototype, "trackId", 2);
2368
3181
  __decorateClass([
2369
- property7({ attribute: false })
3182
+ property10({ attribute: false })
2370
3183
  ], DawTrackControlsElement.prototype, "trackName", 2);
2371
3184
  __decorateClass([
2372
- property7({ type: Number, attribute: false })
3185
+ property10({ type: Number, attribute: false })
2373
3186
  ], DawTrackControlsElement.prototype, "volume", 2);
2374
3187
  __decorateClass([
2375
- property7({ type: Number, attribute: false })
3188
+ property10({ type: Number, attribute: false })
2376
3189
  ], DawTrackControlsElement.prototype, "pan", 2);
2377
3190
  __decorateClass([
2378
- property7({ type: Boolean, attribute: false })
3191
+ property10({ type: Boolean, attribute: false })
2379
3192
  ], DawTrackControlsElement.prototype, "muted", 2);
2380
3193
  __decorateClass([
2381
- property7({ type: Boolean, attribute: false })
3194
+ property10({ type: Boolean, attribute: false })
2382
3195
  ], DawTrackControlsElement.prototype, "soloed", 2);
2383
3196
  DawTrackControlsElement = __decorateClass([
2384
- customElement11("daw-track-controls")
3197
+ customElement14("daw-track-controls")
2385
3198
  ], DawTrackControlsElement);
2386
3199
 
2387
3200
  // 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";
3201
+ import { LitElement as LitElement13, html as html10, css as css9 } from "lit";
3202
+ import { customElement as customElement15, property as property11 } from "lit/decorators.js";
2390
3203
  import { MIN_PIXELS_PER_UNIT } from "@waveform-playlist/core";
2391
3204
  var MAX_CANVAS_WIDTH4 = 1e3;
2392
- var DawGridElement = class extends LitElement10 {
3205
+ var DawGridElement = class extends LitElement13 {
2393
3206
  constructor() {
2394
3207
  super(...arguments);
2395
3208
  this.ticksPerPixel = 24;
@@ -2417,7 +3230,7 @@ var DawGridElement = class extends LitElement10 {
2417
3230
  }
2418
3231
  }
2419
3232
  render() {
2420
- if (!this._tickData) return html9``;
3233
+ if (!this._tickData) return html10``;
2421
3234
  const totalWidth = this.length;
2422
3235
  const dpr = typeof devicePixelRatio !== "undefined" ? devicePixelRatio : 1;
2423
3236
  const indices = getVisibleChunkIndices(
@@ -2426,11 +3239,11 @@ var DawGridElement = class extends LitElement10 {
2426
3239
  this.visibleStart,
2427
3240
  this.visibleEnd
2428
3241
  );
2429
- return html9`
3242
+ return html10`
2430
3243
  <div class="container" style="width: ${totalWidth}px; height: ${this.height}px;">
2431
3244
  ${indices.map((i) => {
2432
3245
  const width = Math.min(MAX_CANVAS_WIDTH4, totalWidth - i * MAX_CANVAS_WIDTH4);
2433
- return html9`
3246
+ return html10`
2434
3247
  <canvas
2435
3248
  data-index=${i}
2436
3249
  width=${width * dpr}
@@ -2491,7 +3304,7 @@ var DawGridElement = class extends LitElement10 {
2491
3304
  }
2492
3305
  }
2493
3306
  };
2494
- DawGridElement.styles = css8`
3307
+ DawGridElement.styles = css9`
2495
3308
  :host {
2496
3309
  display: block;
2497
3310
  position: absolute;
@@ -2509,33 +3322,33 @@ DawGridElement.styles = css8`
2509
3322
  }
2510
3323
  `;
2511
3324
  __decorateClass([
2512
- property8({ type: Number, attribute: false })
3325
+ property11({ type: Number, attribute: false })
2513
3326
  ], DawGridElement.prototype, "ticksPerPixel", 2);
2514
3327
  __decorateClass([
2515
- property8({ attribute: false })
3328
+ property11({ attribute: false })
2516
3329
  ], DawGridElement.prototype, "meterEntries", 2);
2517
3330
  __decorateClass([
2518
- property8({ type: Number, attribute: false })
3331
+ property11({ type: Number, attribute: false })
2519
3332
  ], DawGridElement.prototype, "ppqn", 2);
2520
3333
  __decorateClass([
2521
- property8({ type: Number, attribute: false })
3334
+ property11({ type: Number, attribute: false })
2522
3335
  ], DawGridElement.prototype, "visibleStart", 2);
2523
3336
  __decorateClass([
2524
- property8({ type: Number, attribute: false })
3337
+ property11({ type: Number, attribute: false })
2525
3338
  ], DawGridElement.prototype, "visibleEnd", 2);
2526
3339
  __decorateClass([
2527
- property8({ type: Number, attribute: false })
3340
+ property11({ type: Number, attribute: false })
2528
3341
  ], DawGridElement.prototype, "length", 2);
2529
3342
  __decorateClass([
2530
- property8({ type: Number, attribute: false })
3343
+ property11({ type: Number, attribute: false })
2531
3344
  ], DawGridElement.prototype, "height", 2);
2532
3345
  DawGridElement = __decorateClass([
2533
- customElement12("daw-grid")
3346
+ customElement15("daw-grid")
2534
3347
  ], DawGridElement);
2535
3348
 
2536
3349
  // src/styles/theme.ts
2537
- import { css as css9 } from "lit";
2538
- var hostStyles = css9`
3350
+ import { css as css10 } from "lit";
3351
+ var hostStyles = css10`
2539
3352
  :host {
2540
3353
  --daw-wave-color: #c49a6c;
2541
3354
  --daw-progress-color: #63c75f;
@@ -2551,7 +3364,7 @@ var hostStyles = css9`
2551
3364
  --daw-clip-header-text: #e0d4c8;
2552
3365
  }
2553
3366
  `;
2554
- var clipStyles = css9`
3367
+ var clipStyles = css10`
2555
3368
  .clip-container {
2556
3369
  position: absolute;
2557
3370
  overflow: hidden;
@@ -3270,6 +4083,188 @@ var RecordingController = class {
3270
4083
  }
3271
4084
  };
3272
4085
 
4086
+ // src/controllers/annotation-controller.ts
4087
+ import { html as html11 } from "lit";
4088
+ var ANNOTATION_LANE_HEIGHT = 32;
4089
+ var AnnotationController = class {
4090
+ constructor(host) {
4091
+ this._tracks = [];
4092
+ this._removalObserver = null;
4093
+ /** Playback-following highlight per track, separate from each track's
4094
+ * `activeAnnotationId` (selection) so playback never disturbs selection.
4095
+ * Driven by daw-timeupdate, cleared on daw-stop, retained on pause.
4096
+ * Replaced immutably (a fresh Map) on every change. */
4097
+ this._playingIds = /* @__PURE__ */ new Map();
4098
+ this._onDataChange = () => {
4099
+ this.deriveSecondsCaches();
4100
+ this._host.requestUpdate();
4101
+ };
4102
+ /**
4103
+ * Update only on annotation-boundary crossings, not per animation frame.
4104
+ */
4105
+ this._onTimeUpdate = (e) => {
4106
+ const time = e.detail.time;
4107
+ let changed = false;
4108
+ const next = new Map(this._playingIds);
4109
+ for (const track of this._tracks) {
4110
+ const playingId = computePlayingAnnotationId(track.annotations, time);
4111
+ if (playingId !== (this._playingIds.get(track) ?? null)) {
4112
+ next.set(track, playingId);
4113
+ changed = true;
4114
+ }
4115
+ }
4116
+ if (!changed) return;
4117
+ this._playingIds = next;
4118
+ this._host.requestUpdate();
4119
+ };
4120
+ this._onStop = () => {
4121
+ if (this._playingIds.size === 0) return;
4122
+ this._playingIds = /* @__PURE__ */ new Map();
4123
+ this._host.requestUpdate();
4124
+ };
4125
+ this._host = host;
4126
+ host.addController(this);
4127
+ }
4128
+ get tracks() {
4129
+ return this._tracks;
4130
+ }
4131
+ /** Current playback-following highlight id for a track, or `null` when the
4132
+ * playhead isn't inside any of the track's annotations. */
4133
+ getPlayingAnnotationId(track) {
4134
+ return this._playingIds.get(track) ?? null;
4135
+ }
4136
+ get totalLaneHeight() {
4137
+ return this._tracks.length * ANNOTATION_LANE_HEIGHT;
4138
+ }
4139
+ /** Max annotation end (seconds) across registered tracks — 0 when none.
4140
+ * Lets the editor extend the timeline so annotations past the audio stay
4141
+ * reachable/scrollable. */
4142
+ get maxAnnotationEndSeconds() {
4143
+ return this._tracks.reduce(
4144
+ (max, track) => track.annotations.reduce((m, a) => Math.max(m, a.end), max),
4145
+ 0
4146
+ );
4147
+ }
4148
+ hostConnected() {
4149
+ this._host.addEventListener("daw-annotation-update", this._onDataChange);
4150
+ this._host.addEventListener("daw-annotation-select", this._onDataChange);
4151
+ this._host.addEventListener("daw-annotation-connected", this._onDataChange);
4152
+ this._host.addEventListener("daw-timeupdate", this._onTimeUpdate);
4153
+ this._host.addEventListener("daw-stop", this._onStop);
4154
+ this._removalObserver = new MutationObserver((mutations) => {
4155
+ let changed = false;
4156
+ for (const m of mutations) {
4157
+ for (const node of Array.from(m.removedNodes)) {
4158
+ if (!(node instanceof HTMLElement)) continue;
4159
+ if (node.tagName === "DAW-ANNOTATION-TRACK") {
4160
+ this._tracks = this._tracks.filter((t) => t !== node);
4161
+ changed = true;
4162
+ } else if (node.tagName === "DAW-ANNOTATION") {
4163
+ changed = true;
4164
+ }
4165
+ const nestedTracks = node.querySelectorAll?.("daw-annotation-track");
4166
+ if (nestedTracks) {
4167
+ for (const nested of nestedTracks) {
4168
+ this._tracks = this._tracks.filter((t) => t !== nested);
4169
+ changed = true;
4170
+ }
4171
+ }
4172
+ const nestedAnnotations = node.querySelectorAll?.("daw-annotation");
4173
+ if (nestedAnnotations && nestedAnnotations.length > 0) {
4174
+ changed = true;
4175
+ }
4176
+ }
4177
+ }
4178
+ if (changed) this._host.requestUpdate();
4179
+ });
4180
+ this._removalObserver.observe(this._host, { childList: true, subtree: true });
4181
+ }
4182
+ hostDisconnected() {
4183
+ this._host.removeEventListener("daw-annotation-update", this._onDataChange);
4184
+ this._host.removeEventListener("daw-annotation-select", this._onDataChange);
4185
+ this._host.removeEventListener("daw-annotation-connected", this._onDataChange);
4186
+ this._host.removeEventListener("daw-timeupdate", this._onTimeUpdate);
4187
+ this._host.removeEventListener("daw-stop", this._onStop);
4188
+ this._removalObserver?.disconnect();
4189
+ this._removalObserver = null;
4190
+ this._tracks = [];
4191
+ this._playingIds = /* @__PURE__ */ new Map();
4192
+ }
4193
+ handleTrackConnected(el) {
4194
+ if (this._tracks.includes(el)) return;
4195
+ this._tracks = [...this._tracks, el];
4196
+ this._host.requestUpdate();
4197
+ this.deriveSecondsCaches();
4198
+ }
4199
+ /**
4200
+ * Keep the seconds attributes (derived cache) of tick-based annotations in
4201
+ * sync with the host's tempo. Write-only-on-change: a write fires
4202
+ * daw-annotation-update → _onDataChange → this sweep again → values equal →
4203
+ * no write → the loop settles (idempotent).
4204
+ */
4205
+ deriveSecondsCaches() {
4206
+ for (const track of this._tracks) {
4207
+ for (const el of track.annotationElements) {
4208
+ if (!el.isTickBased) continue;
4209
+ const startSeconds = this._host._ticksToSeconds(el.startTick);
4210
+ const endSeconds = this._host._ticksToSeconds(el.endTick);
4211
+ if (el.start !== startSeconds) el.start = startSeconds;
4212
+ if (el.end !== endSeconds) el.end = endSeconds;
4213
+ }
4214
+ }
4215
+ }
4216
+ /** Pixel geometry for one annotation box. Tick-based annotations in beats
4217
+ * mode use CLIP-IDENTICAL tick math (round(tick / ticksPerPixel)) so they
4218
+ * align pixel-exactly with <daw-grid>; everything else uses the floor-based
4219
+ * seconds math (temporal mode reads the always-fresh seconds cache). */
4220
+ boxGeometry(a, spp, sampleRate, ticksPerPixel = null) {
4221
+ if (ticksPerPixel !== null && ticksPerPixel > 0 && a.startTick !== void 0 && a.endTick !== void 0) {
4222
+ const left2 = Math.round(a.startTick / ticksPerPixel);
4223
+ const width2 = Math.round(a.endTick / ticksPerPixel) - left2;
4224
+ return { left: left2, width: width2 };
4225
+ }
4226
+ const left = Math.floor(a.start * sampleRate / spp);
4227
+ const width = Math.floor(a.end * sampleRate / spp) - left;
4228
+ return { left, width };
4229
+ }
4230
+ /**
4231
+ * Lane templates for the editor's .timeline. onPointerDown is supplied by
4232
+ * the editor and dispatches into the drag interaction (Task 9).
4233
+ */
4234
+ renderLanes(spp, sampleRate, onPointerDown = () => {
4235
+ }, ticksPerPixel = null) {
4236
+ return this._tracks.map((track) => {
4237
+ const activeId = track.activeAnnotationId;
4238
+ const playingId = this._playingIds.get(track) ?? null;
4239
+ const elements = track.annotationElements;
4240
+ return html11`
4241
+ <div
4242
+ class="annotation-lane"
4243
+ style="height: ${ANNOTATION_LANE_HEIGHT}px;"
4244
+ @pointerdown=${(e) => onPointerDown(e, track)}
4245
+ >
4246
+ ${elements.map((el, i) => {
4247
+ const a = el.toAnnotationData();
4248
+ const geo = this.boxGeometry(a, spp, sampleRate, ticksPerPixel);
4249
+ const label = track.boxLabel === "none" ? "" : track.boxLabel === "id" ? el.id || String(i + 1) : a.lines.join(" ");
4250
+ return html11`
4251
+ <div
4252
+ class="annotation-box ${a.id === activeId ? "active" : ""} ${a.id === playingId ? "playing" : ""}"
4253
+ data-annotation-id=${a.id}
4254
+ style="left: ${geo.left}px; width: ${geo.width}px;"
4255
+ >
4256
+ ${track.editable ? html11`<div class="annotation-boundary" data-edge="start"></div>` : ""}
4257
+ <span class="annotation-box-text">${label}</span>
4258
+ ${track.editable ? html11`<div class="annotation-boundary" data-edge="end"></div>` : ""}
4259
+ </div>
4260
+ `;
4261
+ })}
4262
+ </div>
4263
+ `;
4264
+ });
4265
+ }
4266
+ };
4267
+
3273
4268
  // src/controllers/spectrogram-controller.ts
3274
4269
  import {
3275
4270
  SpectrogramOrchestrator
@@ -3330,8 +4325,8 @@ var SpectrogramController = class {
3330
4325
  unregisterCanvas(canvasId) {
3331
4326
  this.orchestrator?.unregisterCanvas(canvasId);
3332
4327
  }
3333
- setViewport(state8) {
3334
- this.orchestrator?.setViewport(state8);
4328
+ setViewport(state9) {
4329
+ this.orchestrator?.setViewport(state9);
3335
4330
  }
3336
4331
  dispose() {
3337
4332
  if (this.orchestrator) {
@@ -3994,6 +4989,148 @@ var ClipPointerHandler = class {
3994
4989
  }
3995
4990
  };
3996
4991
 
4992
+ // src/interactions/annotation-drag.ts
4993
+ import { updateAnnotationBoundaries as updateAnnotationBoundaries2, snapTickToGrid as snapTickToGrid3 } from "@waveform-playlist/core";
4994
+ import {
4995
+ ANNOTATION_LINK_THRESHOLD_TICKS as ANNOTATION_LINK_THRESHOLD_TICKS2,
4996
+ annotationMinDurationTicks as annotationMinDurationTicks2
4997
+ } from "@waveform-playlist/core";
4998
+ var AnnotationDragHandler = class {
4999
+ constructor(host) {
5000
+ this._drag = null;
5001
+ this.onPointerDown = (e, track) => {
5002
+ const target = e.target;
5003
+ const boundary = target.closest(".annotation-boundary");
5004
+ const box = target.closest(".annotation-box");
5005
+ if (!box) return;
5006
+ const annotationId = box.getAttribute("data-annotation-id") ?? "";
5007
+ const isBoundary = boundary !== null && track.editable;
5008
+ if (boundary !== null && !track.editable) {
5009
+ return;
5010
+ }
5011
+ e.stopPropagation();
5012
+ e.preventDefault();
5013
+ const elements = track.annotationElements;
5014
+ const el = elements.find((x) => x.annotationId === annotationId);
5015
+ if (!el) return;
5016
+ const mode = el.isTickBased ? "ticks" : "seconds";
5017
+ const snapshot = mode === "ticks" ? elements.map((x) => tickSpaceData(x, this._host)) : track.annotations;
5018
+ const index = snapshot.findIndex((a) => a.id === annotationId);
5019
+ if (index === -1) return;
5020
+ const edge = isBoundary ? boundary.getAttribute("data-edge") : null;
5021
+ const captureEl = isBoundary ? boundary : box;
5022
+ this._drag = {
5023
+ track,
5024
+ captureEl,
5025
+ pointerId: e.pointerId,
5026
+ startClientX: e.clientX,
5027
+ moved: false,
5028
+ edge,
5029
+ annotationId,
5030
+ mode,
5031
+ snapshot,
5032
+ // edgeTime holds ticks in 'ticks' mode, seconds in 'seconds' mode.
5033
+ edgeTime: edge === "start" ? snapshot[index].start : snapshot[index].end
5034
+ };
5035
+ try {
5036
+ captureEl.setPointerCapture(e.pointerId);
5037
+ } catch {
5038
+ }
5039
+ captureEl.addEventListener("pointermove", this._onPointerMove);
5040
+ captureEl.addEventListener("pointerup", this._onPointerUp);
5041
+ captureEl.addEventListener("pointercancel", this._onPointerCancel);
5042
+ };
5043
+ /** Non-private (underscore convention) so tests can drive moves directly. */
5044
+ this._onPointerMove = (e) => {
5045
+ const drag = this._drag;
5046
+ if (!drag || e.pointerId !== drag.pointerId) return;
5047
+ const deltaPx = e.clientX - drag.startClientX;
5048
+ if (Math.abs(deltaPx) >= DRAG_THRESHOLD) drag.moved = true;
5049
+ if (drag.edge === null || !drag.moved) return;
5050
+ const elements = drag.track.annotationElements;
5051
+ const index = drag.snapshot.findIndex((a) => a.id === drag.annotationId);
5052
+ if (index === -1) return;
5053
+ if (drag.mode === "ticks") {
5054
+ const deltaTicks = this._host.scaleMode === "beats" ? deltaPx * this._host.ticksPerPixel : this._host._secondsToTicks(
5055
+ this._host._ticksToSeconds(drag.edgeTime) + deltaPx * this._host._renderSpp / this._host.effectiveSampleRate
5056
+ ) - drag.edgeTime;
5057
+ let newTick = drag.edgeTime + deltaTicks;
5058
+ if (this._host.scaleMode === "beats" && this._host.snapTo !== "off") {
5059
+ newTick = snapTickToGrid3(
5060
+ newTick,
5061
+ this._host.snapTo,
5062
+ this._host._meterEntries,
5063
+ this._host.ppqn
5064
+ );
5065
+ }
5066
+ const clamp = this._host._annotationClampDuration;
5067
+ const updated2 = updateAnnotationBoundaries2(
5068
+ {
5069
+ annotationIndex: index,
5070
+ newTime: newTick,
5071
+ isDraggingStart: drag.edge === "start",
5072
+ annotations: drag.snapshot,
5073
+ duration: clamp === Infinity ? Infinity : this._host._secondsToTicks(clamp),
5074
+ linkEndpoints: drag.track.linkEndpoints
5075
+ },
5076
+ {
5077
+ linkThreshold: ANNOTATION_LINK_THRESHOLD_TICKS2,
5078
+ minDuration: annotationMinDurationTicks2(this._host.ppqn)
5079
+ }
5080
+ );
5081
+ applyTickBoundaryResults(elements, updated2, (t) => this._host._ticksToSeconds(t));
5082
+ return;
5083
+ }
5084
+ const deltaSeconds = deltaPx * this._host._renderSpp / this._host.effectiveSampleRate;
5085
+ const updated = updateAnnotationBoundaries2({
5086
+ annotationIndex: index,
5087
+ newTime: drag.edgeTime + deltaSeconds,
5088
+ isDraggingStart: drag.edge === "start",
5089
+ annotations: drag.snapshot,
5090
+ duration: this._host._annotationClampDuration,
5091
+ linkEndpoints: drag.track.linkEndpoints
5092
+ });
5093
+ applyBoundaryResults(elements, updated);
5094
+ };
5095
+ this._onPointerUp = (e) => {
5096
+ const drag = this._drag;
5097
+ if (!drag || e.pointerId !== drag.pointerId) return;
5098
+ if (!drag.moved && drag.edge === null) {
5099
+ const data = drag.track.annotations.find((a) => a.id === drag.annotationId);
5100
+ if (data) {
5101
+ drag.track.activeAnnotationId = drag.annotationId;
5102
+ this._host.seekTo(data.start);
5103
+ }
5104
+ }
5105
+ this._teardown();
5106
+ };
5107
+ this._onPointerCancel = (e) => {
5108
+ const drag = this._drag;
5109
+ if (!drag || e.pointerId !== drag.pointerId) return;
5110
+ const elements = drag.track.annotationElements;
5111
+ if (drag.mode === "ticks") {
5112
+ applyTickBoundaryResults(elements, drag.snapshot, (t) => this._host._ticksToSeconds(t));
5113
+ } else {
5114
+ applyBoundaryResults(elements, drag.snapshot);
5115
+ }
5116
+ this._teardown();
5117
+ };
5118
+ this._host = host;
5119
+ }
5120
+ _teardown() {
5121
+ const drag = this._drag;
5122
+ if (!drag) return;
5123
+ try {
5124
+ drag.captureEl.releasePointerCapture(drag.pointerId);
5125
+ } catch {
5126
+ }
5127
+ drag.captureEl.removeEventListener("pointermove", this._onPointerMove);
5128
+ drag.captureEl.removeEventListener("pointerup", this._onPointerUp);
5129
+ drag.captureEl.removeEventListener("pointercancel", this._onPointerCancel);
5130
+ this._drag = null;
5131
+ }
5132
+ };
5133
+
3997
5134
  // src/utils/time-display-format.ts
3998
5135
  var TIME_DISPLAY_FORMATS = [
3999
5136
  "hh:mm:ss.sss",
@@ -4380,9 +5517,9 @@ function splitAtPlayhead(host) {
4380
5517
  function canSplitAtTime(host, time) {
4381
5518
  const { engine } = host;
4382
5519
  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);
5520
+ const state9 = engine.getState();
5521
+ if (!state9.selectedTrackId) return false;
5522
+ const track = state9.tracks.find((t) => t.id === state9.selectedTrackId);
4386
5523
  if (!track) return false;
4387
5524
  const atSample = Math.round(time * host.effectiveSampleRate);
4388
5525
  const clip = findClipAtSample(track.clips, atSample);
@@ -4575,9 +5712,9 @@ var EffectsChainController = class {
4575
5712
  placeholder: true
4576
5713
  };
4577
5714
  }
4578
- let state8;
5715
+ let state9;
4579
5716
  try {
4580
- state8 = await entry.instance.getState?.();
5717
+ state9 = await entry.instance.getState?.();
4581
5718
  } catch (err) {
4582
5719
  console.warn(
4583
5720
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4587,7 +5724,7 @@ var EffectsChainController = class {
4587
5724
  kind: "wam",
4588
5725
  ...sourceFields,
4589
5726
  bypassed: entry.bypassed,
4590
- ...state8 !== void 0 ? { state: state8 } : {}
5727
+ ...state9 !== void 0 ? { state: state9 } : {}
4591
5728
  };
4592
5729
  }
4593
5730
  if (entry.placeholder) {
@@ -5887,6 +7024,7 @@ var PlaybackAnimationController = class {
5887
7024
  this._running = true;
5888
7025
  this._animation.start(() => {
5889
7026
  const time = getTime();
7027
+ if (!this._running) return;
5890
7028
  this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
5891
7029
  this._dispatchTimeUpdate(time);
5892
7030
  });
@@ -5923,7 +7061,7 @@ var TrackLoadCancelledError = class extends Error {
5923
7061
  this.name = "TrackLoadCancelledError";
5924
7062
  }
5925
7063
  };
5926
- var DawEditorElement = class extends LitElement11 {
7064
+ var DawEditorElement = class extends LitElement14 {
5927
7065
  constructor() {
5928
7066
  super(...arguments);
5929
7067
  this._samplesPerPixel = 1024;
@@ -5961,6 +7099,13 @@ var DawEditorElement = class extends LitElement11 {
5961
7099
  this._selectionStartTime = 0;
5962
7100
  this._selectionEndTime = 0;
5963
7101
  this._currentTime = 0;
7102
+ // Bounded-playback watermark for the current play(start, end) call
7103
+ // (selection/annotation playback). The adapter's own auto-stop at
7104
+ // endTime (e.g. native Transport's internal timer) tears down audio but
7105
+ // never notifies isPlaying/daw-stop back up — the _startPlayhead rAF
7106
+ // loop below is the sole place that detects reaching it, same pattern
7107
+ // as the whole-track _duration check.
7108
+ this._activePlayEndTime = null;
5964
7109
  this._externalAdapter = null;
5965
7110
  /** True after a disconnect disposed the consumer's adapter via the engine
5966
7111
  * — rebuild attempts fail loudly until a fresh adapter is set. */
@@ -5987,6 +7132,10 @@ var DawEditorElement = class extends LitElement11 {
5987
7132
  this._childObserver = null;
5988
7133
  this._audioResume = new AudioResumeController(this);
5989
7134
  this._recordingController = new RecordingController(this);
7135
+ this._annotations = new AnnotationController(this);
7136
+ /** Last engine BPM seen by the statechange handler — re-derives tick
7137
+ * annotation seconds caches only when it actually changes. */
7138
+ this._lastAnnotationBpm = null;
5990
7139
  // Closures (not direct references) — _timeToPixels/_getPlayhead are
5991
7140
  // declared later in the class body; class-field init order would read
5992
7141
  // `undefined` for a direct reference here.
@@ -6001,8 +7150,17 @@ var DawEditorElement = class extends LitElement11 {
6001
7150
  * play-start position). Non-private: pointer-handler's seek path sets it.
6002
7151
  */
6003
7152
  this._inSeekTransition = false;
7153
+ /**
7154
+ * True while `stop()` (the public API) is actively calling `this._engine.stop()`.
7155
+ * Suppresses the engine 'stop' handler's own `daw-stop` dispatch — `stop()`
7156
+ * dispatches its own, and without this guard a consumer-initiated stop would
7157
+ * fire `daw-stop` twice. See the engine 'stop' handler for the counterpart
7158
+ * engine-initiated case this flag does NOT suppress.
7159
+ */
7160
+ this._inConsumerStop = false;
6004
7161
  this._spectrogramController = null;
6005
7162
  this._clipPointer = new ClipPointerHandler(this);
7163
+ this._annotationDrag = new AnnotationDragHandler(this);
6006
7164
  this._pointer = new PointerHandler(this);
6007
7165
  this._viewport = (() => {
6008
7166
  const v = new ViewportController(this);
@@ -6026,6 +7184,18 @@ var DawEditorElement = class extends LitElement11 {
6026
7184
  * update for properties unrelated to the viewport.
6027
7185
  */
6028
7186
  this._lastSpectrogramViewport = null;
7187
+ // --- Annotation Events ---
7188
+ this._onAnnotationTrackConnected = (e) => {
7189
+ this._annotations.handleTrackConnected(e.detail.element);
7190
+ };
7191
+ this._onAnnotationSelect = (e) => {
7192
+ const annotation = e.detail.annotation;
7193
+ if (!annotation) return;
7194
+ const scrollArea = this.shadowRoot?.querySelector(".scroll-area");
7195
+ if (!scrollArea) return;
7196
+ const px = Math.floor(annotation.start * this.effectiveSampleRate / this._renderSpp);
7197
+ scrollArea.scrollLeft = Math.max(0, px - scrollArea.clientWidth / 2);
7198
+ };
6029
7199
  // --- Track Events ---
6030
7200
  this._onTrackConnected = (e) => {
6031
7201
  const trackId = e.detail?.trackId;
@@ -6669,6 +7839,12 @@ var DawEditorElement = class extends LitElement11 {
6669
7839
  }
6670
7840
  return ticks * 60 / (this.bpm * this.ppqn);
6671
7841
  }
7842
+ /** Clamp limit for annotation boundary edits. indefinite-playback removes the
7843
+ * end-of-timeline bound — annotations may extend past the audio (DAW-style
7844
+ * unbounded timeline); the shared boundary math treats Infinity as "no end cap". */
7845
+ get _annotationClampDuration() {
7846
+ return this.indefinitePlayback ? Infinity : this._duration;
7847
+ }
6672
7848
  get _totalWidth() {
6673
7849
  if (this.scaleMode === "beats") {
6674
7850
  const contentTicks = this._secondsToTicks(this._duration);
@@ -6676,8 +7852,9 @@ var DawEditorElement = class extends LitElement11 {
6676
7852
  const minTicks = 32 * num * this.ppqn;
6677
7853
  return Math.ceil(Math.max(contentTicks, minTicks) / this.ticksPerPixel);
6678
7854
  }
7855
+ const naturalDuration = Math.max(this._duration, this._annotations.maxAnnotationEndSeconds);
6679
7856
  const naturalWidth = Math.ceil(
6680
- this._duration * this.effectiveSampleRate / this.samplesPerPixel
7857
+ naturalDuration * this.effectiveSampleRate / this.samplesPerPixel
6681
7858
  );
6682
7859
  if (this.indefinitePlayback || this.fillViewport) {
6683
7860
  return Math.max(naturalWidth, this._viewport.containerWidth);
@@ -6729,6 +7906,11 @@ var DawEditorElement = class extends LitElement11 {
6729
7906
  this.addEventListener("daw-track-remove", this._onTrackRemoveRequest);
6730
7907
  this.addEventListener("daw-clip-connected", this._onClipConnected);
6731
7908
  this.addEventListener("daw-clip-update", this._onClipUpdate);
7909
+ this.addEventListener(
7910
+ "daw-annotation-track-connected",
7911
+ this._onAnnotationTrackConnected
7912
+ );
7913
+ this.addEventListener("daw-annotation-select", this._onAnnotationSelect);
6732
7914
  this._childObserver = new MutationObserver((mutations) => {
6733
7915
  for (const mutation of mutations) {
6734
7916
  for (const node of mutation.removedNodes) {
@@ -6766,6 +7948,11 @@ var DawEditorElement = class extends LitElement11 {
6766
7948
  this.removeEventListener("daw-track-remove", this._onTrackRemoveRequest);
6767
7949
  this.removeEventListener("daw-clip-connected", this._onClipConnected);
6768
7950
  this.removeEventListener("daw-clip-update", this._onClipUpdate);
7951
+ this.removeEventListener(
7952
+ "daw-annotation-track-connected",
7953
+ this._onAnnotationTrackConnected
7954
+ );
7955
+ this.removeEventListener("daw-annotation-select", this._onAnnotationSelect);
6769
7956
  this._childObserver?.disconnect();
6770
7957
  this._childObserver = null;
6771
7958
  this._trackElements.clear();
@@ -7602,6 +8789,10 @@ var DawEditorElement = class extends LitElement11 {
7602
8789
  });
7603
8790
  syncPeaksForChangedClips(this, audioTracks);
7604
8791
  }
8792
+ if (engineState.bpm !== this._lastAnnotationBpm) {
8793
+ this._lastAnnotationBpm = engineState.bpm;
8794
+ this._annotations.deriveSecondsCaches();
8795
+ }
7605
8796
  });
7606
8797
  engine.on("pause", () => {
7607
8798
  this._currentTime = engine.getCurrentTime();
@@ -7609,6 +8800,10 @@ var DawEditorElement = class extends LitElement11 {
7609
8800
  engine.on("stop", () => {
7610
8801
  this._currentTime = engine.getCurrentTime();
7611
8802
  this._stopPlayhead();
8803
+ this._activePlayEndTime = null;
8804
+ if (!this._inConsumerStop && !this._inSeekTransition && this.isConnected) {
8805
+ this.dispatchEvent(new CustomEvent("daw-stop", { bubbles: true, composed: true }));
8806
+ }
7612
8807
  });
7613
8808
  this._engine = engine;
7614
8809
  return engine;
@@ -7909,14 +9104,21 @@ var DawEditorElement = class extends LitElement11 {
7909
9104
  return clipEl;
7910
9105
  }
7911
9106
  // --- Playback ---
7912
- async play(startTime) {
9107
+ /**
9108
+ * Start playback, optionally seeking to `startTime` first. When `endTime`
9109
+ * is provided, playback stops at that time (selection/annotation playback).
9110
+ */
9111
+ async play(startTime, endTime) {
7913
9112
  try {
7914
9113
  const engine = await this._ensureEngine();
7915
9114
  await engine.init();
7916
- engine.play(startTime);
9115
+ this._activePlayEndTime = endTime ?? null;
7917
9116
  this._startPlayhead();
9117
+ engine.play(startTime, endTime);
7918
9118
  this.dispatchEvent(new CustomEvent("daw-play", { bubbles: true, composed: true }));
7919
9119
  } catch (err) {
9120
+ this._stopPlayhead();
9121
+ this._activePlayEndTime = null;
7920
9122
  console.warn("[dawcore] Playback failed: " + String(err));
7921
9123
  this.dispatchEvent(
7922
9124
  new CustomEvent("daw-error", {
@@ -7935,7 +9137,13 @@ var DawEditorElement = class extends LitElement11 {
7935
9137
  }
7936
9138
  stop() {
7937
9139
  if (!this._engine) return;
7938
- this._engine.stop();
9140
+ this._activePlayEndTime = null;
9141
+ this._inConsumerStop = true;
9142
+ try {
9143
+ this._engine.stop();
9144
+ } finally {
9145
+ this._inConsumerStop = false;
9146
+ }
7939
9147
  this._stopPlayhead();
7940
9148
  this.dispatchEvent(new CustomEvent("daw-stop", { bubbles: true, composed: true }));
7941
9149
  }
@@ -7989,6 +9197,7 @@ var DawEditorElement = class extends LitElement11 {
7989
9197
  );
7990
9198
  return;
7991
9199
  }
9200
+ this._activePlayEndTime = null;
7992
9201
  this._currentTime = target;
7993
9202
  this._startPlayhead();
7994
9203
  } else {
@@ -8156,16 +9365,16 @@ var DawEditorElement = class extends LitElement11 {
8156
9365
  const { left, width: w } = this._previewPosition(rs.startSample, audibleSamples);
8157
9366
  const hdrH = this.clipHeaders ? this.clipHeaderHeight : 0;
8158
9367
  const height = hdrH + chH * rs.peaks.length;
8159
- return html10`<div
9368
+ return html12`<div
8160
9369
  class="clip-container recording-preview"
8161
9370
  style="left:${left}px;top:0;width:${w}px;height:${height}px;"
8162
9371
  >
8163
- ${hdrH > 0 ? html10`<div class="clip-header" data-track-id=${trackId}>
9372
+ ${hdrH > 0 ? html12`<div class="clip-header" data-track-id=${trackId}>
8164
9373
  <span>${rs.clipName ?? "Recording\u2026"}</span>
8165
9374
  </div>` : ""}
8166
9375
  ${rs.peaks.map((chPeaks, ch) => {
8167
9376
  const slicedPeaks = latencyPixels > 0 ? chPeaks.slice(latencyPixels * 2) : chPeaks;
8168
- return html10`
9377
+ return html12`
8169
9378
  <daw-waveform
8170
9379
  data-recording-track=${trackId}
8171
9380
  data-recording-channel=${ch}
@@ -8188,6 +9397,11 @@ var DawEditorElement = class extends LitElement11 {
8188
9397
  if (!this._engine) return;
8189
9398
  const engine = this._engine;
8190
9399
  this._playbackAnimation.start(() => {
9400
+ if (this._activePlayEndTime !== null && !this.isRecording && engine.getCurrentTime() >= this._activePlayEndTime) {
9401
+ this.stop();
9402
+ const t = this._currentTime;
9403
+ return Number.isFinite(t) ? Math.max(0, t) : 0;
9404
+ }
8191
9405
  if (!this.indefinitePlayback && !this.isRecording && engine.getCurrentTime() >= this._duration) {
8192
9406
  this.stop();
8193
9407
  const t = this._currentTime;
@@ -8255,9 +9469,9 @@ var DawEditorElement = class extends LitElement11 {
8255
9469
  });
8256
9470
  const showControls = this._showControls;
8257
9471
  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>` : ""}
9472
+ return html12`
9473
+ ${showRuler ? html12`<div class="header-row" style="height: ${RULER_HEIGHT}px;">
9474
+ ${showControls ? html12`<div class="ruler-gap"></div>` : ""}
8261
9475
  <div class="ruler-viewport" @pointerdown=${this._pointer.onPointerDown}>
8262
9476
  <div
8263
9477
  class="ruler-content"
@@ -8278,10 +9492,18 @@ var DawEditorElement = class extends LitElement11 {
8278
9492
  </div>
8279
9493
  </div>` : ""}
8280
9494
  <div class="body">
8281
- ${showControls ? html10`<div class="controls-viewport">
9495
+ ${showControls ? html12`<div class="controls-viewport">
8282
9496
  <div class="controls-column">
9497
+ ${this._annotations.tracks.map(
9498
+ (track) => html12`<div
9499
+ class="annotation-lane-spacer"
9500
+ style="height: ${ANNOTATION_LANE_HEIGHT}px;"
9501
+ >
9502
+ <span class="annotation-lane-name">${track.name}</span>
9503
+ </div>`
9504
+ )}
8283
9505
  ${orderedTracks.map(
8284
- (t) => html10`
9506
+ (t) => html12`
8285
9507
  <daw-track-controls
8286
9508
  style="height: ${t.trackHeight}px;"
8287
9509
  .trackId=${t.trackId}
@@ -8305,8 +9527,14 @@ var DawEditorElement = class extends LitElement11 {
8305
9527
  @dragleave=${this._onDragLeave}
8306
9528
  @drop=${this._onDrop}
8307
9529
  >
8308
- ${this.scaleMode === "beats" ? html10`<daw-grid
8309
- style="top: 0px;"
9530
+ ${this._annotations.renderLanes(
9531
+ spp,
9532
+ this.effectiveSampleRate,
9533
+ this._annotationDrag.onPointerDown,
9534
+ this.scaleMode === "beats" ? this.ticksPerPixel : null
9535
+ )}
9536
+ ${this.scaleMode === "beats" ? html12`<daw-grid
9537
+ style="top: ${this._annotations.totalLaneHeight}px;"
8310
9538
  .ticksPerPixel=${this.ticksPerPixel}
8311
9539
  .meterEntries=${this._meterEntries}
8312
9540
  .ppqn=${this.ppqn}
@@ -8315,11 +9543,11 @@ var DawEditorElement = class extends LitElement11 {
8315
9543
  .length=${this._totalWidth}
8316
9544
  .height=${orderedTracks.length > 0 ? orderedTracks.reduce((sum, t) => sum + t.trackHeight, 0) : this._emptyGridHeight}
8317
9545
  ></daw-grid>` : ""}
8318
- ${orderedTracks.length > 0 || this.scaleMode === "beats" || this.indefinitePlayback || this.fillViewport ? html10`<daw-selection .startPx=${selStartPx} .endPx=${selEndPx}></daw-selection>
9546
+ ${orderedTracks.length > 0 || this.scaleMode === "beats" || this.indefinitePlayback || this.fillViewport ? html12`<daw-selection .startPx=${selStartPx} .endPx=${selEndPx}></daw-selection>
8319
9547
  <daw-playhead></daw-playhead>` : ""}
8320
9548
  ${orderedTracks.map((t) => {
8321
9549
  const channelHeight = this.waveHeight;
8322
- return html10`
9550
+ return html12`
8323
9551
  <div
8324
9552
  class="track-row ${t.trackId === this._selectedTrackId ? "selected" : ""}"
8325
9553
  style="height: ${t.trackHeight}px;"
@@ -8385,12 +9613,12 @@ var DawEditorElement = class extends LitElement11 {
8385
9613
  const channels = segmentChannels ?? peakData?.data ?? [new Int16Array(0)];
8386
9614
  const hdrH = this.clipHeaders ? this.clipHeaderHeight : 0;
8387
9615
  const chH = this.waveHeight;
8388
- return html10` <div
9616
+ return html12` <div
8389
9617
  class="clip-container"
8390
9618
  style="left:${clipLeft}px;top:0;width:${width}px;height:${t.trackHeight}px;"
8391
9619
  data-clip-id=${clip.id}
8392
9620
  >
8393
- ${hdrH > 0 ? html10`<div
9621
+ ${hdrH > 0 ? html12`<div
8394
9622
  class="clip-header"
8395
9623
  data-clip-id=${clip.id}
8396
9624
  data-track-id=${t.trackId}
@@ -8398,7 +9626,7 @@ var DawEditorElement = class extends LitElement11 {
8398
9626
  >
8399
9627
  <span>${clip.name || t.descriptor?.name || ""}</span>
8400
9628
  </div>` : ""}
8401
- ${t.descriptor?.renderMode === "piano-roll" ? html10`<daw-piano-roll
9629
+ ${t.descriptor?.renderMode === "piano-roll" ? html12`<daw-piano-roll
8402
9630
  style="position:absolute;left:0;top:${hdrH}px;"
8403
9631
  .midiNotes=${clip.midiNotes ?? []}
8404
9632
  .length=${peakData?.length ?? width}
@@ -8411,7 +9639,7 @@ var DawEditorElement = class extends LitElement11 {
8411
9639
  .originX=${clipLeft}
8412
9640
  ?selected=${t.trackId === this._selectedTrackId}
8413
9641
  ></daw-piano-roll>` : t.descriptor?.renderMode === "spectrogram" ? channels.map(
8414
- (_chPeaks, chIdx) => html10`<daw-spectrogram
9642
+ (_chPeaks, chIdx) => html12`<daw-spectrogram
8415
9643
  style="position:absolute;left:0;top:${hdrH + chIdx * chH}px;height:${chH}px;width:${peakData?.length ?? width}px;"
8416
9644
  .clipId=${clip.id}
8417
9645
  .trackId=${t.trackId}
@@ -8426,7 +9654,7 @@ var DawEditorElement = class extends LitElement11 {
8426
9654
  .originX=${clipLeft}
8427
9655
  ></daw-spectrogram>`
8428
9656
  ) : channels.map(
8429
- (chPeaks, chIdx) => html10` <daw-waveform
9657
+ (chPeaks, chIdx) => html12` <daw-waveform
8430
9658
  style="position:absolute;left:0;top:${hdrH + chIdx * chH}px;"
8431
9659
  .peaks=${chPeaks}
8432
9660
  .length=${peakData?.length ?? width}
@@ -8440,7 +9668,7 @@ var DawEditorElement = class extends LitElement11 {
8440
9668
  .segments=${clipSegments}
8441
9669
  ></daw-waveform>`
8442
9670
  )}
8443
- ${this.interactiveClips ? html10` <div
9671
+ ${this.interactiveClips ? html12` <div
8444
9672
  class="clip-boundary"
8445
9673
  data-boundary-edge="left"
8446
9674
  data-clip-id=${clip.id}
@@ -8467,7 +9695,7 @@ var DawEditorElement = class extends LitElement11 {
8467
9695
  };
8468
9696
  DawEditorElement.styles = [
8469
9697
  hostStyles,
8470
- css10`
9698
+ css11`
8471
9699
  :host {
8472
9700
  display: flex;
8473
9701
  flex-direction: column;
@@ -8538,120 +9766,186 @@ DawEditorElement.styles = [
8538
9766
  outline: 2px dashed var(--daw-selection-color, rgba(99, 199, 95, 0.3));
8539
9767
  outline-offset: -2px;
8540
9768
  }
9769
+ .annotation-lane {
9770
+ position: relative;
9771
+ box-sizing: border-box;
9772
+ border-bottom: 1px solid var(--daw-annotation-lane-border, rgba(255, 255, 255, 0.08));
9773
+ background: var(--daw-annotation-lane-background, rgba(0, 0, 0, 0.15));
9774
+ user-select: none;
9775
+ -webkit-user-drag: none;
9776
+ }
9777
+ .annotation-lane-spacer {
9778
+ box-sizing: border-box;
9779
+ border-bottom: 1px solid var(--daw-annotation-lane-border, rgba(255, 255, 255, 0.08));
9780
+ display: flex;
9781
+ align-items: center;
9782
+ overflow: hidden;
9783
+ }
9784
+ .annotation-lane-name {
9785
+ padding: 0 10px;
9786
+ font-size: 11px;
9787
+ color: var(--daw-controls-text, #e0d4c8);
9788
+ opacity: 0.8;
9789
+ white-space: nowrap;
9790
+ overflow: hidden;
9791
+ text-overflow: ellipsis;
9792
+ }
9793
+ .annotation-box {
9794
+ position: absolute;
9795
+ top: 3px;
9796
+ bottom: 3px;
9797
+ overflow: hidden;
9798
+ display: flex;
9799
+ align-items: center;
9800
+ border: 1px solid var(--daw-annotation-box-border, #c49a6c);
9801
+ border-radius: 3px;
9802
+ background: var(--daw-annotation-box-background, rgba(196, 154, 108, 0.2));
9803
+ color: var(--daw-annotation-text-color, #e0d4c8);
9804
+ font-size: 11px;
9805
+ cursor: pointer;
9806
+ }
9807
+ .annotation-box.playing {
9808
+ box-shadow: inset 0 0 0 1px var(--daw-annotation-box-border, #c49a6c);
9809
+ background: var(--daw-annotation-playing-background, rgba(196, 154, 108, 0.32));
9810
+ }
9811
+ .annotation-box.active {
9812
+ background: var(--daw-annotation-active-background, rgba(196, 154, 108, 0.45));
9813
+ }
9814
+ .annotation-box-text {
9815
+ padding: 0 6px;
9816
+ white-space: nowrap;
9817
+ overflow: hidden;
9818
+ text-overflow: ellipsis;
9819
+ pointer-events: none;
9820
+ }
9821
+ .annotation-boundary {
9822
+ position: absolute;
9823
+ top: 0;
9824
+ bottom: 0;
9825
+ width: 6px;
9826
+ cursor: ew-resize;
9827
+ flex-shrink: 0;
9828
+ }
9829
+ .annotation-boundary[data-edge='start'] {
9830
+ left: 0;
9831
+ }
9832
+ .annotation-boundary[data-edge='end'] {
9833
+ right: 0;
9834
+ }
8541
9835
  `,
8542
9836
  clipStyles
8543
9837
  ];
8544
9838
  DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "muted", "soloed"]);
8545
9839
  __decorateClass([
8546
- property9({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
9840
+ property12({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
8547
9841
  ], DawEditorElement.prototype, "samplesPerPixel", 1);
8548
9842
  __decorateClass([
8549
- property9({ attribute: "time-format", reflect: true, noAccessor: true })
9843
+ property12({ attribute: "time-format", reflect: true, noAccessor: true })
8550
9844
  ], DawEditorElement.prototype, "timeFormat", 1);
8551
9845
  __decorateClass([
8552
- property9({ type: Number, attribute: "wave-height" })
9846
+ property12({ type: Number, attribute: "wave-height" })
8553
9847
  ], DawEditorElement.prototype, "waveHeight", 2);
8554
9848
  __decorateClass([
8555
- property9({ type: Boolean })
9849
+ property12({ type: Boolean })
8556
9850
  ], DawEditorElement.prototype, "timescale", 2);
8557
9851
  __decorateClass([
8558
- property9({ type: Boolean })
9852
+ property12({ type: Boolean })
8559
9853
  ], DawEditorElement.prototype, "mono", 2);
8560
9854
  __decorateClass([
8561
- property9({ type: Number, attribute: "bar-width" })
9855
+ property12({ type: Number, attribute: "bar-width" })
8562
9856
  ], DawEditorElement.prototype, "barWidth", 2);
8563
9857
  __decorateClass([
8564
- property9({ type: Number, attribute: "bar-gap" })
9858
+ property12({ type: Number, attribute: "bar-gap" })
8565
9859
  ], DawEditorElement.prototype, "barGap", 2);
8566
9860
  __decorateClass([
8567
- property9({ type: Boolean, attribute: "rounded-bars" })
9861
+ property12({ type: Boolean, attribute: "rounded-bars" })
8568
9862
  ], DawEditorElement.prototype, "roundedBars", 2);
8569
9863
  __decorateClass([
8570
- property9({ type: Boolean, attribute: "file-drop" })
9864
+ property12({ type: Boolean, attribute: "file-drop" })
8571
9865
  ], DawEditorElement.prototype, "fileDrop", 2);
8572
9866
  __decorateClass([
8573
- property9({ type: Boolean, attribute: "clip-headers" })
9867
+ property12({ type: Boolean, attribute: "clip-headers" })
8574
9868
  ], DawEditorElement.prototype, "clipHeaders", 2);
8575
9869
  __decorateClass([
8576
- property9({ type: Number, attribute: "clip-header-height" })
9870
+ property12({ type: Number, attribute: "clip-header-height" })
8577
9871
  ], DawEditorElement.prototype, "clipHeaderHeight", 2);
8578
9872
  __decorateClass([
8579
- property9({ type: Boolean, attribute: "interactive-clips" })
9873
+ property12({ type: Boolean, attribute: "interactive-clips" })
8580
9874
  ], DawEditorElement.prototype, "interactiveClips", 2);
8581
9875
  __decorateClass([
8582
- property9({ type: Boolean, attribute: "indefinite-playback" })
9876
+ property12({ type: Boolean, attribute: "indefinite-playback" })
8583
9877
  ], DawEditorElement.prototype, "indefinitePlayback", 2);
8584
9878
  __decorateClass([
8585
- property9({ type: Boolean, attribute: "fill-viewport" })
9879
+ property12({ type: Boolean, attribute: "fill-viewport" })
8586
9880
  ], DawEditorElement.prototype, "fillViewport", 2);
8587
9881
  __decorateClass([
8588
- property9({ attribute: false, noAccessor: true })
9882
+ property12({ attribute: false, noAccessor: true })
8589
9883
  ], DawEditorElement.prototype, "spectrogramConfig", 1);
8590
9884
  __decorateClass([
8591
- property9({ attribute: false, noAccessor: true })
9885
+ property12({ attribute: false, noAccessor: true })
8592
9886
  ], DawEditorElement.prototype, "spectrogramColorMap", 1);
8593
9887
  __decorateClass([
8594
- property9({ type: String, attribute: "scale-mode" })
9888
+ property12({ type: String, attribute: "scale-mode" })
8595
9889
  ], DawEditorElement.prototype, "scaleMode", 2);
8596
9890
  __decorateClass([
8597
- property9({ type: Number, attribute: "ticks-per-pixel", noAccessor: true })
9891
+ property12({ type: Number, attribute: "ticks-per-pixel", noAccessor: true })
8598
9892
  ], DawEditorElement.prototype, "ticksPerPixel", 1);
8599
9893
  __decorateClass([
8600
- property9({ type: Number, noAccessor: true })
9894
+ property12({ type: Number, noAccessor: true })
8601
9895
  ], DawEditorElement.prototype, "bpm", 1);
8602
9896
  __decorateClass([
8603
- property9({ attribute: false })
9897
+ property12({ attribute: false })
8604
9898
  ], DawEditorElement.prototype, "timeSignature", 2);
8605
9899
  __decorateClass([
8606
- property9({ attribute: false })
9900
+ property12({ attribute: false })
8607
9901
  ], DawEditorElement.prototype, "meterEntries", 2);
8608
9902
  __decorateClass([
8609
- property9({ type: Number, noAccessor: true })
9903
+ property12({ type: Number, noAccessor: true })
8610
9904
  ], DawEditorElement.prototype, "ppqn", 1);
8611
9905
  __decorateClass([
8612
- property9({ type: String, attribute: "snap-to" })
9906
+ property12({ type: String, attribute: "snap-to" })
8613
9907
  ], DawEditorElement.prototype, "snapTo", 2);
8614
9908
  __decorateClass([
8615
- property9({ attribute: false })
9909
+ property12({ attribute: false })
8616
9910
  ], DawEditorElement.prototype, "secondsToTicks", 2);
8617
9911
  __decorateClass([
8618
- property9({ attribute: false })
9912
+ property12({ attribute: false })
8619
9913
  ], DawEditorElement.prototype, "ticksToSeconds", 2);
8620
9914
  __decorateClass([
8621
- state3()
9915
+ state4()
8622
9916
  ], DawEditorElement.prototype, "_tracks", 2);
8623
9917
  __decorateClass([
8624
- state3()
9918
+ state4()
8625
9919
  ], DawEditorElement.prototype, "_engineTracks", 2);
8626
9920
  __decorateClass([
8627
- state3()
9921
+ state4()
8628
9922
  ], DawEditorElement.prototype, "_peaksData", 2);
8629
9923
  __decorateClass([
8630
- state3()
9924
+ state4()
8631
9925
  ], DawEditorElement.prototype, "_isPlaying", 2);
8632
9926
  __decorateClass([
8633
- state3()
9927
+ state4()
8634
9928
  ], DawEditorElement.prototype, "_duration", 2);
8635
9929
  __decorateClass([
8636
- state3()
9930
+ state4()
8637
9931
  ], DawEditorElement.prototype, "_selectedTrackId", 2);
8638
9932
  __decorateClass([
8639
- state3()
9933
+ state4()
8640
9934
  ], DawEditorElement.prototype, "_dragOver", 2);
8641
9935
  __decorateClass([
8642
- property9({ attribute: false })
9936
+ property12({ attribute: false })
8643
9937
  ], DawEditorElement.prototype, "adapter", 1);
8644
9938
  __decorateClass([
8645
- property9({ attribute: "eager-resume" })
9939
+ property12({ attribute: "eager-resume" })
8646
9940
  ], DawEditorElement.prototype, "eagerResume", 2);
8647
9941
  DawEditorElement = __decorateClass([
8648
- customElement13("daw-editor")
9942
+ customElement16("daw-editor")
8649
9943
  ], DawEditorElement);
8650
9944
 
8651
9945
  // 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 {
9946
+ import { LitElement as LitElement15, html as html13, css as css12 } from "lit";
9947
+ import { customElement as customElement17, property as property13 } from "lit/decorators.js";
9948
+ var DawSelectionElement = class extends LitElement15 {
8655
9949
  constructor() {
8656
9950
  super(...arguments);
8657
9951
  this.startPx = 0;
@@ -8660,11 +9954,11 @@ var DawSelectionElement = class extends LitElement12 {
8660
9954
  render() {
8661
9955
  const left = Math.min(this.startPx, this.endPx);
8662
9956
  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>`;
9957
+ if (width === 0) return html13``;
9958
+ return html13`<div style="left: ${left}px; width: ${width}px;"></div>`;
8665
9959
  }
8666
9960
  };
8667
- DawSelectionElement.styles = css11`
9961
+ DawSelectionElement.styles = css12`
8668
9962
  :host {
8669
9963
  position: absolute;
8670
9964
  top: 0;
@@ -8681,18 +9975,18 @@ DawSelectionElement.styles = css11`
8681
9975
  }
8682
9976
  `;
8683
9977
  __decorateClass([
8684
- property10({ type: Number, attribute: false })
9978
+ property13({ type: Number, attribute: false })
8685
9979
  ], DawSelectionElement.prototype, "startPx", 2);
8686
9980
  __decorateClass([
8687
- property10({ type: Number, attribute: false })
9981
+ property13({ type: Number, attribute: false })
8688
9982
  ], DawSelectionElement.prototype, "endPx", 2);
8689
9983
  DawSelectionElement = __decorateClass([
8690
- customElement14("daw-selection")
9984
+ customElement17("daw-selection")
8691
9985
  ], DawSelectionElement);
8692
9986
 
8693
9987
  // 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";
9988
+ import { html as html14, css as css13 } from "lit";
9989
+ import { customElement as customElement18, state as state5 } from "lit/decorators.js";
8696
9990
  var DawRecordButtonElement = class extends DawTransportButton {
8697
9991
  constructor() {
8698
9992
  super(...arguments);
@@ -8741,7 +10035,7 @@ var DawRecordButtonElement = class extends DawTransportButton {
8741
10035
  }
8742
10036
  }
8743
10037
  render() {
8744
- return html12`
10038
+ return html14`
8745
10039
  <button
8746
10040
  part="button"
8747
10041
  ?disabled=${!this.targetSupported}
@@ -8769,7 +10063,7 @@ DawRecordButtonElement.requiredTargetMethods = [
8769
10063
  ];
8770
10064
  DawRecordButtonElement.styles = [
8771
10065
  DawTransportButton.styles,
8772
- css12`
10066
+ css13`
8773
10067
  button[data-recording] {
8774
10068
  color: #d08070;
8775
10069
  border-color: #d08070;
@@ -8778,17 +10072,17 @@ DawRecordButtonElement.styles = [
8778
10072
  `
8779
10073
  ];
8780
10074
  __decorateClass([
8781
- state4()
10075
+ state5()
8782
10076
  ], DawRecordButtonElement.prototype, "_isRecording", 2);
8783
10077
  DawRecordButtonElement = __decorateClass([
8784
- customElement15("daw-record-button")
10078
+ customElement18("daw-record-button")
8785
10079
  ], DawRecordButtonElement);
8786
10080
 
8787
10081
  // 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";
10082
+ import { LitElement as LitElement16 } from "lit";
10083
+ import { customElement as customElement19, property as property14 } from "lit/decorators.js";
8790
10084
  import { handleKeyboardEvent } from "@waveform-playlist/core";
8791
- var DawKeyboardShortcutsElement = class extends LitElement13 {
10085
+ var DawKeyboardShortcutsElement = class extends LitElement16 {
8792
10086
  constructor() {
8793
10087
  super(...arguments);
8794
10088
  this.playback = false;
@@ -8987,23 +10281,23 @@ var DawKeyboardShortcutsElement = class extends LitElement13 {
8987
10281
  }
8988
10282
  };
8989
10283
  __decorateClass([
8990
- property11({ type: Boolean })
10284
+ property14({ type: Boolean })
8991
10285
  ], DawKeyboardShortcutsElement.prototype, "playback", 2);
8992
10286
  __decorateClass([
8993
- property11({ type: Boolean })
10287
+ property14({ type: Boolean })
8994
10288
  ], DawKeyboardShortcutsElement.prototype, "splitting", 2);
8995
10289
  __decorateClass([
8996
- property11({ type: Boolean })
10290
+ property14({ type: Boolean })
8997
10291
  ], DawKeyboardShortcutsElement.prototype, "undo", 2);
8998
10292
  DawKeyboardShortcutsElement = __decorateClass([
8999
- customElement16("daw-keyboard-shortcuts")
10293
+ customElement19("daw-keyboard-shortcuts")
9000
10294
  ], DawKeyboardShortcutsElement);
9001
10295
 
9002
10296
  // 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";
10297
+ import { LitElement as LitElement17, html as html15, css as css14 } from "lit";
10298
+ import { customElement as customElement20, property as property15 } from "lit/decorators.js";
9005
10299
  import { MAX_CANVAS_WIDTH as MAX_CANVAS_WIDTH5, buildSpectrogramCanvasId } from "@waveform-playlist/core";
9006
- var DawSpectrogramElement = class extends LitElement14 {
10300
+ var DawSpectrogramElement = class extends LitElement17 {
9007
10301
  constructor() {
9008
10302
  super(...arguments);
9009
10303
  this.clipId = "";
@@ -9139,10 +10433,10 @@ var DawSpectrogramElement = class extends LitElement14 {
9139
10433
  this._unregisterAllCanvases();
9140
10434
  }
9141
10435
  render() {
9142
- return html13`${this._canvases.map((c) => c)}`;
10436
+ return html15`${this._canvases.map((c) => c)}`;
9143
10437
  }
9144
10438
  };
9145
- DawSpectrogramElement.styles = css13`
10439
+ DawSpectrogramElement.styles = css14`
9146
10440
  :host {
9147
10441
  display: block;
9148
10442
  position: relative;
@@ -9157,46 +10451,46 @@ DawSpectrogramElement.styles = css13`
9157
10451
  }
9158
10452
  `;
9159
10453
  __decorateClass([
9160
- property12({ attribute: false })
10454
+ property15({ attribute: false })
9161
10455
  ], DawSpectrogramElement.prototype, "clipId", 2);
9162
10456
  __decorateClass([
9163
- property12({ attribute: false })
10457
+ property15({ attribute: false })
9164
10458
  ], DawSpectrogramElement.prototype, "trackId", 2);
9165
10459
  __decorateClass([
9166
- property12({ type: Number, attribute: false })
10460
+ property15({ type: Number, attribute: false })
9167
10461
  ], DawSpectrogramElement.prototype, "channelIndex", 2);
9168
10462
  __decorateClass([
9169
- property12({ type: Number, attribute: false })
10463
+ property15({ type: Number, attribute: false })
9170
10464
  ], DawSpectrogramElement.prototype, "length", 2);
9171
10465
  __decorateClass([
9172
- property12({ type: Number, attribute: false })
10466
+ property15({ type: Number, attribute: false })
9173
10467
  ], DawSpectrogramElement.prototype, "waveHeight", 2);
9174
10468
  __decorateClass([
9175
- property12({ type: Number, attribute: false, noAccessor: true })
10469
+ property15({ type: Number, attribute: false, noAccessor: true })
9176
10470
  ], DawSpectrogramElement.prototype, "samplesPerPixel", 1);
9177
10471
  __decorateClass([
9178
- property12({ type: Number, attribute: false, noAccessor: true })
10472
+ property15({ type: Number, attribute: false, noAccessor: true })
9179
10473
  ], DawSpectrogramElement.prototype, "sampleRate", 1);
9180
10474
  __decorateClass([
9181
- property12({ type: Number, attribute: false })
10475
+ property15({ type: Number, attribute: false })
9182
10476
  ], DawSpectrogramElement.prototype, "clipOffsetSeconds", 2);
9183
10477
  __decorateClass([
9184
- property12({ type: Number, attribute: false })
10478
+ property15({ type: Number, attribute: false })
9185
10479
  ], DawSpectrogramElement.prototype, "visibleStart", 2);
9186
10480
  __decorateClass([
9187
- property12({ type: Number, attribute: false })
10481
+ property15({ type: Number, attribute: false })
9188
10482
  ], DawSpectrogramElement.prototype, "visibleEnd", 2);
9189
10483
  __decorateClass([
9190
- property12({ type: Number, attribute: false })
10484
+ property15({ type: Number, attribute: false })
9191
10485
  ], DawSpectrogramElement.prototype, "originX", 2);
9192
10486
  DawSpectrogramElement = __decorateClass([
9193
- customElement17("daw-spectrogram")
10487
+ customElement20("daw-spectrogram")
9194
10488
  ], DawSpectrogramElement);
9195
10489
 
9196
10490
  // 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 {
10491
+ import { LitElement as LitElement18, html as html16, css as css15 } from "lit";
10492
+ import { customElement as customElement21, state as state6 } from "lit/decorators.js";
10493
+ var DawTimeDisplayElement = class extends LitElement18 {
9200
10494
  constructor() {
9201
10495
  super(...arguments);
9202
10496
  this._time = null;
@@ -9249,10 +10543,10 @@ var DawTimeDisplayElement = class extends LitElement15 {
9249
10543
  }
9250
10544
  render() {
9251
10545
  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>`;
10546
+ return html16`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
9253
10547
  }
9254
10548
  };
9255
- DawTimeDisplayElement.styles = css14`
10549
+ DawTimeDisplayElement.styles = css15`
9256
10550
  span {
9257
10551
  display: inline-block;
9258
10552
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
@@ -9264,19 +10558,19 @@ DawTimeDisplayElement.styles = css14`
9264
10558
  }
9265
10559
  `;
9266
10560
  __decorateClass([
9267
- state5()
10561
+ state6()
9268
10562
  ], DawTimeDisplayElement.prototype, "_time", 2);
9269
10563
  __decorateClass([
9270
- state5()
10564
+ state6()
9271
10565
  ], DawTimeDisplayElement.prototype, "_format", 2);
9272
10566
  DawTimeDisplayElement = __decorateClass([
9273
- customElement18("daw-time-display")
10567
+ customElement21("daw-time-display")
9274
10568
  ], DawTimeDisplayElement);
9275
10569
 
9276
10570
  // 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 {
10571
+ import { LitElement as LitElement19, html as html17, css as css16 } from "lit";
10572
+ import { customElement as customElement22, state as state7 } from "lit/decorators.js";
10573
+ var DawTimeFormatElement = class extends LitElement19 {
9280
10574
  constructor() {
9281
10575
  super(...arguments);
9282
10576
  this._format = "hh:mm:ss.sss";
@@ -9351,20 +10645,20 @@ var DawTimeFormatElement = class extends LitElement16 {
9351
10645
  target.setTimeFormat?.(value);
9352
10646
  }
9353
10647
  render() {
9354
- return html15`
10648
+ return html17`
9355
10649
  <select
9356
10650
  aria-label="Time format"
9357
10651
  ?disabled=${!this._targetSupported}
9358
10652
  @change=${this._onSelectChange}
9359
10653
  >
9360
10654
  ${TIME_DISPLAY_FORMATS.map(
9361
- (f) => html15`<option value=${f} ?selected=${f === this._format}>${f}</option>`
10655
+ (f) => html17`<option value=${f} ?selected=${f === this._format}>${f}</option>`
9362
10656
  )}
9363
10657
  </select>
9364
10658
  `;
9365
10659
  }
9366
10660
  };
9367
- DawTimeFormatElement.styles = css15`
10661
+ DawTimeFormatElement.styles = css16`
9368
10662
  select {
9369
10663
  cursor: pointer;
9370
10664
  background: var(--daw-controls-background, #1a1a2e);
@@ -9379,20 +10673,20 @@ DawTimeFormatElement.styles = css15`
9379
10673
  }
9380
10674
  `;
9381
10675
  __decorateClass([
9382
- state6()
10676
+ state7()
9383
10677
  ], DawTimeFormatElement.prototype, "_format", 2);
9384
10678
  DawTimeFormatElement = __decorateClass([
9385
- customElement19("daw-time-format")
10679
+ customElement22("daw-time-format")
9386
10680
  ], DawTimeFormatElement);
9387
10681
 
9388
10682
  // 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";
10683
+ import { LitElement as LitElement20, html as html18, css as css17 } from "lit";
10684
+ import { customElement as customElement23, property as property16, state as state8 } from "lit/decorators.js";
9391
10685
  import { repeat } from "lit/directives/repeat.js";
9392
10686
  import { MediaElementPlayout } from "@waveform-playlist/media-element-playout";
9393
10687
  var MIN_RATE = 0.25;
9394
10688
  var MAX_RATE = 4;
9395
- var DawPlayerElement = class extends LitElement17 {
10689
+ var DawPlayerElement = class extends LitElement20 {
9396
10690
  constructor() {
9397
10691
  super(...arguments);
9398
10692
  this.src = "";
@@ -9500,8 +10794,8 @@ var DawPlayerElement = class extends LitElement17 {
9500
10794
  const width = this._timelineWidth;
9501
10795
  const channels = this._channelPeaks.length;
9502
10796
  const channelHeight = channels > 0 ? this.waveHeight / channels : this.waveHeight;
9503
- return html16`
9504
- ${this.timescale ? html16`<daw-ruler
10797
+ return html18`
10798
+ ${this.timescale ? html18`<daw-ruler
9505
10799
  .samplesPerPixel=${this._channelSpp(width)}
9506
10800
  .sampleRate=${this._sampleRate}
9507
10801
  .duration=${this._engine.duration}
@@ -9515,7 +10809,7 @@ var DawPlayerElement = class extends LitElement17 {
9515
10809
  ${repeat(
9516
10810
  this._channelPeaks,
9517
10811
  (_p, i) => i,
9518
- (peaks) => html16`<daw-waveform
10812
+ (peaks) => html18`<daw-waveform
9519
10813
  .peaks=${peaks}
9520
10814
  .length=${width}
9521
10815
  .waveHeight=${channelHeight}
@@ -9678,7 +10972,7 @@ var DawPlayerElement = class extends LitElement17 {
9678
10972
  return this.shadowRoot?.querySelector(".waveform-area")?.clientWidth ?? 0;
9679
10973
  }
9680
10974
  };
9681
- DawPlayerElement.styles = css16`
10975
+ DawPlayerElement.styles = css17`
9682
10976
  :host {
9683
10977
  display: block;
9684
10978
  position: relative;
@@ -9691,41 +10985,45 @@ DawPlayerElement.styles = css16`
9691
10985
  }
9692
10986
  `;
9693
10987
  __decorateClass([
9694
- property13({ type: String })
10988
+ property16({ type: String })
9695
10989
  ], DawPlayerElement.prototype, "src", 2);
9696
10990
  __decorateClass([
9697
- property13({ type: String, attribute: "peaks-src" })
10991
+ property16({ type: String, attribute: "peaks-src" })
9698
10992
  ], DawPlayerElement.prototype, "peaksSrc", 2);
9699
10993
  __decorateClass([
9700
- property13({ type: Number, attribute: "wave-height" })
10994
+ property16({ type: Number, attribute: "wave-height" })
9701
10995
  ], DawPlayerElement.prototype, "waveHeight", 2);
9702
10996
  __decorateClass([
9703
- property13({ type: Boolean })
10997
+ property16({ type: Boolean })
9704
10998
  ], DawPlayerElement.prototype, "timescale", 2);
9705
10999
  __decorateClass([
9706
- property13({ type: Boolean })
11000
+ property16({ type: Boolean })
9707
11001
  ], DawPlayerElement.prototype, "mono", 2);
9708
11002
  __decorateClass([
9709
- property13({ type: Number, attribute: "bar-width" })
11003
+ property16({ type: Number, attribute: "bar-width" })
9710
11004
  ], DawPlayerElement.prototype, "barWidth", 2);
9711
11005
  __decorateClass([
9712
- property13({ type: Number, attribute: "bar-gap" })
11006
+ property16({ type: Number, attribute: "bar-gap" })
9713
11007
  ], DawPlayerElement.prototype, "barGap", 2);
9714
11008
  __decorateClass([
9715
- property13({ type: Boolean, attribute: "rounded-bars" })
11009
+ property16({ type: Boolean, attribute: "rounded-bars" })
9716
11010
  ], DawPlayerElement.prototype, "roundedBars", 2);
9717
11011
  __decorateClass([
9718
- property13({ type: Number, attribute: "playback-rate", noAccessor: true })
11012
+ property16({ type: Number, attribute: "playback-rate", noAccessor: true })
9719
11013
  ], DawPlayerElement.prototype, "playbackRate", 1);
9720
11014
  __decorateClass([
9721
- state7()
11015
+ state8()
9722
11016
  ], DawPlayerElement.prototype, "_channelPeaks", 2);
9723
11017
  DawPlayerElement = __decorateClass([
9724
- customElement20("daw-player")
11018
+ customElement23("daw-player")
9725
11019
  ], DawPlayerElement);
9726
11020
  export {
11021
+ ANNOTATION_LANE_HEIGHT,
9727
11022
  AudioResumeController,
9728
11023
  ClipPointerHandler,
11024
+ DawAnnotationElement,
11025
+ DawAnnotationListElement,
11026
+ DawAnnotationTrackElement,
9729
11027
  DawClipElement,
9730
11028
  DawEditorElement,
9731
11029
  DawGridElement,