@dawcore/components 0.0.24 → 0.0.25

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
@@ -898,42 +898,9 @@ DawPianoRollElement = __decorateClass([
898
898
  // src/elements/daw-playhead.ts
899
899
  import { LitElement as LitElement5, html as html3, css as css3 } from "lit";
900
900
  import { customElement as customElement5 } from "lit/decorators.js";
901
-
902
- // src/controllers/animation-controller.ts
903
- var AnimationController = class {
904
- constructor(host) {
905
- this._rafId = null;
906
- this._callback = null;
907
- host.addController(this);
908
- }
909
- start(callback) {
910
- this.stop();
911
- this._callback = callback;
912
- const loop = () => {
913
- this._callback?.();
914
- this._rafId = requestAnimationFrame(loop);
915
- };
916
- this._rafId = requestAnimationFrame(loop);
917
- }
918
- stop() {
919
- if (this._rafId !== null) {
920
- cancelAnimationFrame(this._rafId);
921
- this._rafId = null;
922
- }
923
- this._callback = null;
924
- }
925
- hostConnected() {
926
- }
927
- hostDisconnected() {
928
- this.stop();
929
- }
930
- };
931
-
932
- // src/elements/daw-playhead.ts
933
901
  var DawPlayheadElement = class extends LitElement5 {
934
902
  constructor() {
935
903
  super(...arguments);
936
- this._animation = new AnimationController(this);
937
904
  this._line = null;
938
905
  }
939
906
  render() {
@@ -942,52 +909,10 @@ var DawPlayheadElement = class extends LitElement5 {
942
909
  firstUpdated() {
943
910
  this._line = this.shadowRoot.querySelector("div");
944
911
  }
945
- startAnimation(getTime, sampleRate, samplesPerPixel) {
946
- this._animation.start(() => {
947
- const time = getTime();
948
- const px = time * sampleRate / samplesPerPixel;
949
- if (this._line) {
950
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
951
- }
952
- });
953
- }
954
- stopAnimation(time, sampleRate, samplesPerPixel) {
955
- this._animation.stop();
956
- const px = time * sampleRate / samplesPerPixel;
957
- if (this._line) {
958
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
959
- }
960
- }
961
- startBeatsAnimation(getTime, bpm, ppqn, ticksPerPixel) {
962
- const ticksPerSecond = bpm * ppqn / 60;
963
- this._animation.start(() => {
964
- const time = getTime();
965
- const px = time * ticksPerSecond / ticksPerPixel;
966
- if (this._line) {
967
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
968
- }
969
- });
970
- }
971
- stopBeatsAnimation(time, bpm, ppqn, ticksPerPixel) {
972
- this._animation.stop();
973
- const px = time * bpm * ppqn / (60 * ticksPerPixel);
974
- if (this._line) {
975
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
976
- }
977
- }
978
- startBeatsAnimationWithMap(getTime, secondsToTicks, ticksPerPixel) {
979
- this._animation.start(() => {
980
- const time = getTime();
981
- const tick = secondsToTicks(time);
982
- const px = tick / ticksPerPixel;
983
- if (this._line) {
984
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
985
- }
986
- });
987
- }
988
- stopBeatsAnimationWithMap(time, secondsToTicks, ticksPerPixel) {
989
- this._animation.stop();
990
- const px = secondsToTicks(time) / ticksPerPixel;
912
+ /** Position the playhead line at an absolute pixel offset on the timeline.
913
+ * The editor's PlaybackAnimationController drives this each frame — the
914
+ * playhead owns no animation loop or time math of its own. */
915
+ setPosition(px) {
991
916
  if (this._line) {
992
917
  this._line.style.transform = `translate3d(${px}px, 0, 0)`;
993
918
  }
@@ -1045,12 +970,102 @@ import { customElement as customElement7, state } from "lit/decorators.js";
1045
970
 
1046
971
  // src/elements/daw-transport-button.ts
1047
972
  import { LitElement as LitElement7, css as css4 } from "lit";
973
+
974
+ // src/utils/transport-capability.ts
975
+ function resolveTransportTarget(el) {
976
+ const transport = el.closest("daw-transport");
977
+ return transport?.target ?? null;
978
+ }
979
+ function targetSupports(target, methods) {
980
+ if (!target) return false;
981
+ return methods.every((m) => typeof target[m] === "function");
982
+ }
983
+ function targetUndetermined(target) {
984
+ if (!target) return true;
985
+ const name = target.localName;
986
+ return name.includes("-") && customElements.get(name) === void 0;
987
+ }
988
+ var warned = /* @__PURE__ */ new WeakMap();
989
+ function warnOnce(element, message) {
990
+ let messages = warned.get(element);
991
+ if (!messages) {
992
+ messages = /* @__PURE__ */ new Set();
993
+ warned.set(element, messages);
994
+ }
995
+ if (messages.has(message)) return;
996
+ messages.add(message);
997
+ console.warn(message);
998
+ }
999
+ function warnNoTargetOnce(element, suffix) {
1000
+ warnOnce(
1001
+ element,
1002
+ `[dawcore] <${element.tagName.toLowerCase()}> has no target. Check <daw-transport for="..."> references a valid element id.` + (suffix ?? "")
1003
+ );
1004
+ }
1005
+ function warnUnsupportedOnce(element, methods) {
1006
+ warnOnce(
1007
+ element,
1008
+ `[dawcore] <${element.tagName.toLowerCase()}> is disabled: its transport target does not implement ${methods.join(", ")}. See the transport compatibility table in the docs for which controls work with which targets.`
1009
+ );
1010
+ }
1011
+
1012
+ // src/elements/daw-transport-button.ts
1048
1013
  var DawTransportButton = class extends LitElement7 {
1014
+ constructor() {
1015
+ super(...arguments);
1016
+ this._onCapabilityPointerEnter = () => {
1017
+ this.requestUpdate();
1018
+ };
1019
+ this._onCapabilityPointerDown = () => {
1020
+ const target = this.target;
1021
+ if (!target) {
1022
+ if (this._requiredMethods.length > 0) {
1023
+ warnNoTargetOnce(this);
1024
+ }
1025
+ return;
1026
+ }
1027
+ if (!this.targetSupported) {
1028
+ warnUnsupportedOnce(this, this._requiredMethods);
1029
+ }
1030
+ };
1031
+ }
1049
1032
  get target() {
1050
- const transport = this.closest("daw-transport");
1051
- return transport?.target ?? null;
1033
+ return resolveTransportTarget(this);
1034
+ }
1035
+ get _requiredMethods() {
1036
+ return this.constructor.requiredTargetMethods;
1037
+ }
1038
+ /**
1039
+ * False when this control declares requirements its target doesn't meet.
1040
+ * An undetermined target (missing, or a not-yet-upgraded custom element)
1041
+ * gets the benefit of the doubt and stays enabled — click-time resolution
1042
+ * warns if it's still unusable.
1043
+ */
1044
+ get targetSupported() {
1045
+ const required = this._requiredMethods;
1046
+ if (required.length === 0) return true;
1047
+ const target = this.target;
1048
+ if (targetUndetermined(target)) return true;
1049
+ return targetSupports(target, required);
1050
+ }
1051
+ connectedCallback() {
1052
+ super.connectedCallback();
1053
+ this.addEventListener("pointerdown", this._onCapabilityPointerDown);
1054
+ this.addEventListener("pointerenter", this._onCapabilityPointerEnter);
1055
+ requestAnimationFrame(() => {
1056
+ if (!this.isConnected) return;
1057
+ this.requestUpdate();
1058
+ });
1059
+ }
1060
+ disconnectedCallback() {
1061
+ super.disconnectedCallback();
1062
+ this.removeEventListener("pointerdown", this._onCapabilityPointerDown);
1063
+ this.removeEventListener("pointerenter", this._onCapabilityPointerEnter);
1052
1064
  }
1053
1065
  };
1066
+ /** Methods the transport target must implement for this control to be
1067
+ * enabled. Empty = works with any target. */
1068
+ DawTransportButton.requiredTargetMethods = [];
1054
1069
  DawTransportButton.styles = css4`
1055
1070
  button {
1056
1071
  cursor: pointer;
@@ -3116,8 +3131,8 @@ var SpectrogramController = class {
3116
3131
  unregisterCanvas(canvasId) {
3117
3132
  this.orchestrator?.unregisterCanvas(canvasId);
3118
3133
  }
3119
- setViewport(state5) {
3120
- this.orchestrator?.setViewport(state5);
3134
+ setViewport(state7) {
3135
+ this.orchestrator?.setViewport(state7);
3121
3136
  }
3122
3137
  dispose() {
3123
3138
  if (this.orchestrator) {
@@ -3356,7 +3371,12 @@ var PointerHandler = class {
3356
3371
  if (h._engine) {
3357
3372
  h._engine.setSelection(0, 0);
3358
3373
  if (wasPlaying) {
3359
- h._engine.stop();
3374
+ h._inSeekTransition = true;
3375
+ try {
3376
+ h._engine.stop();
3377
+ } finally {
3378
+ h._inSeekTransition = false;
3379
+ }
3360
3380
  h._engine.play(time);
3361
3381
  h._startPlayhead();
3362
3382
  } else {
@@ -3697,6 +3717,57 @@ var ClipPointerHandler = class {
3697
3717
  }
3698
3718
  };
3699
3719
 
3720
+ // src/utils/time-display-format.ts
3721
+ var TIME_DISPLAY_FORMATS = [
3722
+ "hh:mm:ss.sss",
3723
+ "hh:mm:ss",
3724
+ "seconds"
3725
+ ];
3726
+ function isTimeDisplayFormat(value) {
3727
+ return TIME_DISPLAY_FORMATS.includes(value);
3728
+ }
3729
+ function clockFormat(totalSeconds, decimals) {
3730
+ const hours = Math.floor(totalSeconds / 3600);
3731
+ const minutes = Math.floor(totalSeconds / 60) % 60;
3732
+ const secsRem = totalSeconds % 60;
3733
+ let secs;
3734
+ if (decimals === 0) {
3735
+ secs = String(Math.min(Math.floor(secsRem + 1e-6), 59)).padStart(2, "0");
3736
+ } else {
3737
+ const factor = 10 ** decimals;
3738
+ const truncated = Math.min(Math.floor(secsRem * factor + 1e-6), 60 * factor - 1);
3739
+ secs = (truncated / factor).toFixed(decimals).padStart(decimals + 3, "0");
3740
+ }
3741
+ return String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0") + ":" + secs;
3742
+ }
3743
+ function formatDisplayTime(seconds, format) {
3744
+ const safe = Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
3745
+ switch (format) {
3746
+ case "seconds":
3747
+ return safe.toFixed(3);
3748
+ case "hh:mm:ss":
3749
+ return clockFormat(safe, 0);
3750
+ case "hh:mm:ss.sss":
3751
+ default:
3752
+ return clockFormat(safe, 3);
3753
+ }
3754
+ }
3755
+ function parseDisplayTime(value, format) {
3756
+ if (!value) return 0;
3757
+ let seconds = 0;
3758
+ if (format === "seconds") {
3759
+ seconds = parseFloat(value) || 0;
3760
+ } else {
3761
+ const parts = value.split(":");
3762
+ if (parts.length !== 3) return 0;
3763
+ const h = parseInt(parts[0], 10) || 0;
3764
+ const m = parseInt(parts[1], 10) || 0;
3765
+ const s = parseFloat(parts[2]) || 0;
3766
+ seconds = h * 3600 + m * 60 + s;
3767
+ }
3768
+ return Math.max(0, seconds);
3769
+ }
3770
+
3700
3771
  // src/interactions/file-loader.ts
3701
3772
  import { createClip, createTrack } from "@waveform-playlist/core";
3702
3773
  async function loadFiles(host, files) {
@@ -4015,9 +4086,9 @@ function splitAtPlayhead(host) {
4015
4086
  function canSplitAtTime(host, time) {
4016
4087
  const { engine } = host;
4017
4088
  if (!engine) return false;
4018
- const state5 = engine.getState();
4019
- if (!state5.selectedTrackId) return false;
4020
- const track = state5.tracks.find((t) => t.id === state5.selectedTrackId);
4089
+ const state7 = engine.getState();
4090
+ if (!state7.selectedTrackId) return false;
4091
+ const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
4021
4092
  if (!track) return false;
4022
4093
  const atSample = Math.round(time * host.effectiveSampleRate);
4023
4094
  const clip = findClipAtSample(track.clips, atSample);
@@ -4207,9 +4278,9 @@ var EffectsChainController = class {
4207
4278
  ...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
4208
4279
  };
4209
4280
  }
4210
- let state5;
4281
+ let state7;
4211
4282
  try {
4212
- state5 = await entry.instance.getState?.();
4283
+ state7 = await entry.instance.getState?.();
4213
4284
  } catch (err) {
4214
4285
  console.warn(
4215
4286
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4219,7 +4290,7 @@ var EffectsChainController = class {
4219
4290
  kind: "wam",
4220
4291
  ...sourceFields,
4221
4292
  bypassed: entry.bypassed,
4222
- ...state5 !== void 0 ? { state: state5 } : {}
4293
+ ...state7 !== void 0 ? { state: state7 } : {}
4223
4294
  };
4224
4295
  }
4225
4296
  return {
@@ -5391,6 +5462,75 @@ var ScrollSyncController = class {
5391
5462
  }
5392
5463
  };
5393
5464
 
5465
+ // src/controllers/animation-controller.ts
5466
+ var AnimationController = class {
5467
+ constructor(host) {
5468
+ this._rafId = null;
5469
+ this._callback = null;
5470
+ host.addController(this);
5471
+ }
5472
+ start(callback) {
5473
+ this.stop();
5474
+ this._callback = callback;
5475
+ const loop = () => {
5476
+ this._callback?.();
5477
+ this._rafId = requestAnimationFrame(loop);
5478
+ };
5479
+ this._rafId = requestAnimationFrame(loop);
5480
+ }
5481
+ stop() {
5482
+ if (this._rafId !== null) {
5483
+ cancelAnimationFrame(this._rafId);
5484
+ this._rafId = null;
5485
+ }
5486
+ this._callback = null;
5487
+ }
5488
+ hostConnected() {
5489
+ }
5490
+ hostDisconnected() {
5491
+ this.stop();
5492
+ }
5493
+ };
5494
+
5495
+ // src/controllers/playback-animation-controller.ts
5496
+ var PlaybackAnimationController = class {
5497
+ constructor(host, options) {
5498
+ this._running = false;
5499
+ this._lastDispatchedTime = null;
5500
+ this._host = host;
5501
+ this._options = options;
5502
+ this._animation = new AnimationController(host);
5503
+ }
5504
+ start(getTime) {
5505
+ this._running = true;
5506
+ this._animation.start(() => {
5507
+ const time = getTime();
5508
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
5509
+ this._dispatchTimeUpdate(time);
5510
+ });
5511
+ }
5512
+ stop(finalTime, opts) {
5513
+ const wasRunning = this._running;
5514
+ this._running = false;
5515
+ this._animation.stop();
5516
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(finalTime));
5517
+ if (opts?.dispatch === false) return;
5518
+ if (wasRunning || finalTime !== this._lastDispatchedTime) {
5519
+ this._dispatchTimeUpdate(finalTime);
5520
+ }
5521
+ }
5522
+ _dispatchTimeUpdate(time) {
5523
+ this._lastDispatchedTime = time;
5524
+ this._host.dispatchEvent(
5525
+ new CustomEvent("daw-timeupdate", {
5526
+ bubbles: true,
5527
+ composed: true,
5528
+ detail: { time }
5529
+ })
5530
+ );
5531
+ }
5532
+ };
5533
+
5394
5534
  // src/elements/daw-editor.ts
5395
5535
  var RULER_HEIGHT = 30;
5396
5536
  var NO_ADAPTER_ERROR = "No PlayoutAdapter set on <daw-editor>. Set editor.adapter before use.\n\n // Option 1: Native Web Audio (no Tone.js)\n npm install @dawcore/transport\n import { NativePlayoutAdapter } from '@dawcore/transport';\n editor.adapter = new NativePlayoutAdapter(new AudioContext());\n\n // Option 2: Tone.js (effects, MIDI synths)\n npm install @waveform-playlist/playout\n import { createToneAdapter } from '@waveform-playlist/playout';\n editor.adapter = createToneAdapter();";
@@ -5398,6 +5538,7 @@ var DawEditorElement = class extends LitElement11 {
5398
5538
  constructor() {
5399
5539
  super(...arguments);
5400
5540
  this._samplesPerPixel = 1024;
5541
+ this._timeFormat = "hh:mm:ss.sss";
5401
5542
  this.waveHeight = 128;
5402
5543
  this.timescale = false;
5403
5544
  this.mono = false;
@@ -5447,6 +5588,20 @@ var DawEditorElement = class extends LitElement11 {
5447
5588
  this._childObserver = null;
5448
5589
  this._audioResume = new AudioResumeController(this);
5449
5590
  this._recordingController = new RecordingController(this);
5591
+ // Closures (not direct references) — _timeToPixels/_getPlayhead are
5592
+ // declared later in the class body; class-field init order would read
5593
+ // `undefined` for a direct reference here.
5594
+ this._playbackAnimation = new PlaybackAnimationController(this, {
5595
+ timeToPixels: (time) => this._timeToPixels(time),
5596
+ getPlayhead: () => this._getPlayhead()
5597
+ });
5598
+ /**
5599
+ * True while a seek-while-playing stop+play transition is in flight.
5600
+ * Suppresses the transient settle dispatch from the engine 'stop' handler
5601
+ * (which would otherwise leak a backward-jumping daw-timeupdate at the
5602
+ * play-start position). Non-private: pointer-handler's seek path sets it.
5603
+ */
5604
+ this._inSeekTransition = false;
5450
5605
  this._spectrogramController = null;
5451
5606
  this._clipPointer = new ClipPointerHandler(this);
5452
5607
  this._pointer = new PointerHandler(this);
@@ -5652,6 +5807,14 @@ var DawEditorElement = class extends LitElement11 {
5652
5807
  /** Set in togglePauseRecording when Transport is paused alongside the
5653
5808
  * worklet, so resume can restart it. Cleared on resume and on stop. */
5654
5809
  this._wasPlayingDuringRecording = false;
5810
+ // --- Playback animation (single RAF loop: playhead + daw-timeupdate) ---
5811
+ /** Convert playback seconds to a timeline pixel offset for the active mode. */
5812
+ this._timeToPixels = (time) => {
5813
+ if (this.scaleMode === "beats") {
5814
+ return this._secondsToTicks(time) / this.ticksPerPixel;
5815
+ }
5816
+ return time * this.effectiveSampleRate / this.samplesPerPixel;
5817
+ };
5655
5818
  }
5656
5819
  get samplesPerPixel() {
5657
5820
  return this._samplesPerPixel;
@@ -5668,6 +5831,35 @@ var DawEditorElement = class extends LitElement11 {
5668
5831
  this._samplesPerPixel = clamped;
5669
5832
  this.requestUpdate("samplesPerPixel", old);
5670
5833
  }
5834
+ get timeFormat() {
5835
+ return this._timeFormat;
5836
+ }
5837
+ set timeFormat(value) {
5838
+ if (!isTimeDisplayFormat(value)) {
5839
+ console.warn(
5840
+ '[dawcore] timeFormat: invalid format "' + String(value) + '" ignored. Valid formats: ' + TIME_DISPLAY_FORMATS.join(", ")
5841
+ );
5842
+ if (this.hasAttribute("time-format") && this.getAttribute("time-format") !== this._timeFormat) {
5843
+ this.setAttribute("time-format", this._timeFormat);
5844
+ }
5845
+ return;
5846
+ }
5847
+ if (value === this._timeFormat) return;
5848
+ const old = this._timeFormat;
5849
+ this._timeFormat = value;
5850
+ this.requestUpdate("timeFormat", old);
5851
+ this.dispatchEvent(
5852
+ new CustomEvent("daw-time-format-change", {
5853
+ bubbles: true,
5854
+ composed: true,
5855
+ detail: { format: value }
5856
+ })
5857
+ );
5858
+ }
5859
+ /** Set the time display format. Sugar over the `timeFormat` property. */
5860
+ setTimeFormat(format) {
5861
+ this.timeFormat = format;
5862
+ }
5671
5863
  get spectrogramConfig() {
5672
5864
  return this._spectrogramConfig;
5673
5865
  }
@@ -6793,17 +6985,23 @@ var DawEditorElement = class extends LitElement11 {
6793
6985
  zoomLevels: [256, 512, 1024, 2048, 4096, 8192, this.samplesPerPixel].filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b)
6794
6986
  });
6795
6987
  let lastTracksVersion = -1;
6988
+ let lastMixerVersion = -1;
6796
6989
  engine.on("statechange", (engineState) => {
6797
6990
  this._isPlaying = engineState.isPlaying;
6798
6991
  this._duration = engineState.duration;
6799
6992
  this._selectedTrackId = engineState.selectedTrackId;
6800
- if (engineState.tracksVersion !== lastTracksVersion) {
6993
+ const structuralChange = engineState.tracksVersion !== lastTracksVersion;
6994
+ const mixerChange = engineState.mixerVersion !== lastMixerVersion;
6995
+ if (structuralChange || mixerChange) {
6801
6996
  lastTracksVersion = engineState.tracksVersion;
6997
+ lastMixerVersion = engineState.mixerVersion;
6802
6998
  const nextTracks = /* @__PURE__ */ new Map();
6803
6999
  for (const track of engineState.tracks) {
6804
7000
  nextTracks.set(track.id, track);
6805
7001
  }
6806
7002
  this._engineTracks = nextTracks;
7003
+ }
7004
+ if (structuralChange) {
6807
7005
  this._effectsManager?.rewireTrackChains();
6808
7006
  const audioTracks = engineState.tracks.filter((t) => {
6809
7007
  const desc = this._tracks.get(t.id);
@@ -7164,7 +7362,12 @@ var DawEditorElement = class extends LitElement11 {
7164
7362
  return;
7165
7363
  }
7166
7364
  if (this._isPlaying) {
7167
- this.stop();
7365
+ this._inSeekTransition = true;
7366
+ try {
7367
+ this.stop();
7368
+ } finally {
7369
+ this._inSeekTransition = false;
7370
+ }
7168
7371
  this.play(time);
7169
7372
  } else {
7170
7373
  this._engine.seek(time);
@@ -7223,6 +7426,14 @@ var DawEditorElement = class extends LitElement11 {
7223
7426
  }
7224
7427
  return this._currentTime;
7225
7428
  }
7429
+ /** Read-only: whether playback is running (HTMLMediaElement-adjacent). */
7430
+ get isPlaying() {
7431
+ return this._isPlaying;
7432
+ }
7433
+ /** Read-only: total content duration in seconds. */
7434
+ get duration() {
7435
+ return this._duration;
7436
+ }
7226
7437
  get isRecording() {
7227
7438
  return this._recordingController.isRecording;
7228
7439
  }
@@ -7313,33 +7524,15 @@ var DawEditorElement = class extends LitElement11 {
7313
7524
  `;
7314
7525
  });
7315
7526
  }
7316
- // --- Playhead ---
7317
7527
  _startPlayhead() {
7318
- const playhead = this._getPlayhead();
7319
- if (!playhead || !this._engine) return;
7528
+ if (!this._engine) return;
7320
7529
  const engine = this._engine;
7321
- const audibleTime = () => engine.getAudibleTime();
7322
- if (this.scaleMode === "beats") {
7323
- const secondsToTicksFn = (s) => this._secondsToTicks(s);
7324
- playhead.startBeatsAnimationWithMap(audibleTime, secondsToTicksFn, this.ticksPerPixel);
7325
- } else {
7326
- playhead.startAnimation(audibleTime, this.effectiveSampleRate, this.samplesPerPixel);
7327
- }
7530
+ this._playbackAnimation.start(() => engine.getAudibleTime());
7328
7531
  }
7329
7532
  _stopPlayhead() {
7330
- const playhead = this._getPlayhead();
7331
- if (!playhead) return;
7332
7533
  const t = this._currentTime;
7333
7534
  const visualTime = Number.isFinite(t) ? Math.max(0, t) : 0;
7334
- if (this.scaleMode === "beats") {
7335
- playhead.stopBeatsAnimationWithMap(
7336
- visualTime,
7337
- (s) => this._secondsToTicks(s),
7338
- this.ticksPerPixel
7339
- );
7340
- } else {
7341
- playhead.stopAnimation(visualTime, this.effectiveSampleRate, this.samplesPerPixel);
7342
- }
7535
+ this._playbackAnimation.stop(visualTime, { dispatch: !this._inSeekTransition });
7343
7536
  }
7344
7537
  _getPlayhead() {
7345
7538
  return this.shadowRoot?.querySelector("daw-playhead");
@@ -7684,6 +7877,9 @@ DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "mut
7684
7877
  __decorateClass([
7685
7878
  property9({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
7686
7879
  ], DawEditorElement.prototype, "samplesPerPixel", 1);
7880
+ __decorateClass([
7881
+ property9({ attribute: "time-format", reflect: true, noAccessor: true })
7882
+ ], DawEditorElement.prototype, "timeFormat", 1);
7687
7883
  __decorateClass([
7688
7884
  property9({ type: Number, attribute: "wave-height" })
7689
7885
  ], DawEditorElement.prototype, "waveHeight", 2);
@@ -7864,7 +8060,12 @@ var DawRecordButtonElement = class extends DawTransportButton {
7864
8060
  }
7865
8061
  render() {
7866
8062
  return html12`
7867
- <button part="button" ?data-recording=${this._isRecording} @click=${this._onClick}>
8063
+ <button
8064
+ part="button"
8065
+ ?disabled=${!this.targetSupported}
8066
+ ?data-recording=${this._isRecording}
8067
+ @click=${this._onClick}
8068
+ >
7868
8069
  <slot>Record</slot>
7869
8070
  </button>
7870
8071
  `;
@@ -7873,14 +8074,16 @@ var DawRecordButtonElement = class extends DawTransportButton {
7873
8074
  if (this._isRecording) return;
7874
8075
  const target = this.target;
7875
8076
  if (!target) {
7876
- console.warn(
7877
- '[dawcore] <daw-record-button> has no target. Check <daw-transport for="..."> references a valid <daw-editor> id.'
7878
- );
8077
+ warnNoTargetOnce(this);
7879
8078
  return;
7880
8079
  }
7881
8080
  target.startRecording(target.recordingStream);
7882
8081
  }
7883
8082
  };
8083
+ DawRecordButtonElement.requiredTargetMethods = [
8084
+ "startRecording",
8085
+ "stopRecording"
8086
+ ];
7884
8087
  DawRecordButtonElement.styles = [
7885
8088
  DawTransportButton.styles,
7886
8089
  css12`
@@ -8257,6 +8460,198 @@ __decorateClass([
8257
8460
  DawSpectrogramElement = __decorateClass([
8258
8461
  customElement17("daw-spectrogram")
8259
8462
  ], DawSpectrogramElement);
8463
+
8464
+ // src/elements/daw-time-display.ts
8465
+ import { LitElement as LitElement15, html as html14, css as css14 } from "lit";
8466
+ import { customElement as customElement18, state as state5 } from "lit/decorators.js";
8467
+ var DawTimeDisplayElement = class extends LitElement15 {
8468
+ constructor() {
8469
+ super(...arguments);
8470
+ this._time = null;
8471
+ this._format = "hh:mm:ss.sss";
8472
+ this._onTimeUpdate = (e) => {
8473
+ if (e.target !== this.target) return;
8474
+ if (this._time === null) {
8475
+ const timeFormat = e.target.timeFormat;
8476
+ if (isTimeDisplayFormat(timeFormat)) this._format = timeFormat;
8477
+ }
8478
+ this._time = e.detail.time;
8479
+ };
8480
+ this._onFormatChange = (e) => {
8481
+ if (e.target !== this.target) return;
8482
+ const detail = e.detail;
8483
+ if (isTimeDisplayFormat(detail.format)) {
8484
+ this._format = detail.format;
8485
+ }
8486
+ };
8487
+ }
8488
+ get target() {
8489
+ return resolveTransportTarget(this);
8490
+ }
8491
+ connectedCallback() {
8492
+ super.connectedCallback();
8493
+ document.addEventListener("daw-timeupdate", this._onTimeUpdate);
8494
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8495
+ requestAnimationFrame(() => this._syncFromTarget());
8496
+ }
8497
+ disconnectedCallback() {
8498
+ super.disconnectedCallback();
8499
+ document.removeEventListener("daw-timeupdate", this._onTimeUpdate);
8500
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8501
+ }
8502
+ _syncFromTarget() {
8503
+ if (!this.isConnected) return;
8504
+ const target = this.target;
8505
+ if (!target || typeof target.currentTime !== "number") {
8506
+ warnNoTargetOnce(
8507
+ this,
8508
+ " The display recovers automatically once the target dispatches daw-timeupdate."
8509
+ );
8510
+ return;
8511
+ }
8512
+ this._time = target.currentTime;
8513
+ const fmt = target.timeFormat;
8514
+ if (isTimeDisplayFormat(fmt)) {
8515
+ this._format = fmt;
8516
+ }
8517
+ }
8518
+ render() {
8519
+ const text = this._time === null ? "--:--:--" : formatDisplayTime(this._time, this._format);
8520
+ return html14`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
8521
+ }
8522
+ };
8523
+ DawTimeDisplayElement.styles = css14`
8524
+ span {
8525
+ display: inline-block;
8526
+ font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
8527
+ font-variant-numeric: tabular-nums;
8528
+ color: var(--daw-controls-text, #e0d4c8);
8529
+ background: var(--daw-controls-background, #1a1a2e);
8530
+ border: 1px solid currentColor;
8531
+ padding: 4px 8px;
8532
+ }
8533
+ `;
8534
+ __decorateClass([
8535
+ state5()
8536
+ ], DawTimeDisplayElement.prototype, "_time", 2);
8537
+ __decorateClass([
8538
+ state5()
8539
+ ], DawTimeDisplayElement.prototype, "_format", 2);
8540
+ DawTimeDisplayElement = __decorateClass([
8541
+ customElement18("daw-time-display")
8542
+ ], DawTimeDisplayElement);
8543
+
8544
+ // src/elements/daw-time-format.ts
8545
+ import { LitElement as LitElement16, html as html15, css as css15 } from "lit";
8546
+ import { customElement as customElement19, state as state6 } from "lit/decorators.js";
8547
+ var DawTimeFormatElement = class extends LitElement16 {
8548
+ constructor() {
8549
+ super(...arguments);
8550
+ this._format = "hh:mm:ss.sss";
8551
+ this._onFormatChange = (e) => {
8552
+ if (e.target !== this.target) return;
8553
+ const detail = e.detail;
8554
+ if (isTimeDisplayFormat(detail.format)) {
8555
+ this._format = detail.format;
8556
+ }
8557
+ };
8558
+ this._onPointerEnter = () => {
8559
+ this.requestUpdate();
8560
+ };
8561
+ this._onPointerDown = () => {
8562
+ const target = this.target;
8563
+ if (!target) {
8564
+ warnNoTargetOnce(this);
8565
+ return;
8566
+ }
8567
+ if (!this._targetSupported) {
8568
+ warnUnsupportedOnce(this, ["setTimeFormat"]);
8569
+ }
8570
+ };
8571
+ }
8572
+ get target() {
8573
+ return resolveTransportTarget(this);
8574
+ }
8575
+ /**
8576
+ * False when the target doesn't implement setTimeFormat. An undetermined
8577
+ * target (missing, or a not-yet-upgraded custom element) gets the benefit
8578
+ * of the doubt and stays enabled — interaction-time resolution warns if
8579
+ * it's still unusable.
8580
+ */
8581
+ get _targetSupported() {
8582
+ const target = this.target;
8583
+ if (targetUndetermined(target)) return true;
8584
+ return targetSupports(target, ["setTimeFormat"]);
8585
+ }
8586
+ connectedCallback() {
8587
+ super.connectedCallback();
8588
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8589
+ this.addEventListener("pointerdown", this._onPointerDown);
8590
+ this.addEventListener("pointerenter", this._onPointerEnter);
8591
+ requestAnimationFrame(() => {
8592
+ if (!this.isConnected) return;
8593
+ const target = this.target;
8594
+ if (target && isTimeDisplayFormat(target.timeFormat)) {
8595
+ this._format = target.timeFormat;
8596
+ }
8597
+ this.requestUpdate();
8598
+ });
8599
+ }
8600
+ disconnectedCallback() {
8601
+ super.disconnectedCallback();
8602
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8603
+ this.removeEventListener("pointerdown", this._onPointerDown);
8604
+ this.removeEventListener("pointerenter", this._onPointerEnter);
8605
+ }
8606
+ updated() {
8607
+ const select = this.shadowRoot?.querySelector("select");
8608
+ if (select && select.value !== this._format) {
8609
+ select.value = this._format;
8610
+ }
8611
+ }
8612
+ _onSelectChange(e) {
8613
+ const value = e.target.value;
8614
+ const target = this.target;
8615
+ if (!target) {
8616
+ warnNoTargetOnce(this);
8617
+ return;
8618
+ }
8619
+ target.setTimeFormat?.(value);
8620
+ }
8621
+ render() {
8622
+ return html15`
8623
+ <select
8624
+ aria-label="Time format"
8625
+ ?disabled=${!this._targetSupported}
8626
+ @change=${this._onSelectChange}
8627
+ >
8628
+ ${TIME_DISPLAY_FORMATS.map(
8629
+ (f) => html15`<option value=${f} ?selected=${f === this._format}>${f}</option>`
8630
+ )}
8631
+ </select>
8632
+ `;
8633
+ }
8634
+ };
8635
+ DawTimeFormatElement.styles = css15`
8636
+ select {
8637
+ cursor: pointer;
8638
+ background: var(--daw-controls-background, #1a1a2e);
8639
+ color: var(--daw-controls-text, #e0d4c8);
8640
+ border: 1px solid currentColor;
8641
+ padding: 4px 8px;
8642
+ font: inherit;
8643
+ }
8644
+ select:disabled {
8645
+ opacity: 0.4;
8646
+ cursor: default;
8647
+ }
8648
+ `;
8649
+ __decorateClass([
8650
+ state6()
8651
+ ], DawTimeFormatElement.prototype, "_format", 2);
8652
+ DawTimeFormatElement = __decorateClass([
8653
+ customElement19("daw-time-format")
8654
+ ], DawTimeFormatElement);
8260
8655
  export {
8261
8656
  AudioResumeController,
8262
8657
  ClipPointerHandler,
@@ -8273,17 +8668,28 @@ export {
8273
8668
  DawSelectionElement,
8274
8669
  DawSpectrogramElement,
8275
8670
  DawStopButtonElement,
8671
+ DawTimeDisplayElement,
8672
+ DawTimeFormatElement,
8276
8673
  DawTrackControlsElement,
8277
8674
  DawTrackElement,
8278
8675
  DawTransportButton,
8279
8676
  DawTransportElement,
8280
8677
  DawWaveformElement,
8678
+ PlaybackAnimationController,
8281
8679
  RecordingController,
8282
8680
  SpectrogramController,
8681
+ TIME_DISPLAY_FORMATS,
8283
8682
  createEffectInstance,
8683
+ formatDisplayTime,
8284
8684
  getEffectDefinitions,
8285
8685
  isDomClip,
8686
+ isTimeDisplayFormat,
8687
+ parseDisplayTime,
8286
8688
  registerEffect,
8287
- splitAtPlayhead
8689
+ resolveTransportTarget,
8690
+ splitAtPlayhead,
8691
+ targetSupports,
8692
+ warnOnce,
8693
+ warnUnsupportedOnce
8288
8694
  };
8289
8695
  //# sourceMappingURL=index.mjs.map