@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.js CHANGED
@@ -53,18 +53,29 @@ __export(index_exports, {
53
53
  DawSelectionElement: () => DawSelectionElement,
54
54
  DawSpectrogramElement: () => DawSpectrogramElement,
55
55
  DawStopButtonElement: () => DawStopButtonElement,
56
+ DawTimeDisplayElement: () => DawTimeDisplayElement,
57
+ DawTimeFormatElement: () => DawTimeFormatElement,
56
58
  DawTrackControlsElement: () => DawTrackControlsElement,
57
59
  DawTrackElement: () => DawTrackElement,
58
60
  DawTransportButton: () => DawTransportButton,
59
61
  DawTransportElement: () => DawTransportElement,
60
62
  DawWaveformElement: () => DawWaveformElement,
63
+ PlaybackAnimationController: () => PlaybackAnimationController,
61
64
  RecordingController: () => RecordingController,
62
65
  SpectrogramController: () => SpectrogramController,
66
+ TIME_DISPLAY_FORMATS: () => TIME_DISPLAY_FORMATS,
63
67
  createEffectInstance: () => createEffectInstance,
68
+ formatDisplayTime: () => formatDisplayTime,
64
69
  getEffectDefinitions: () => getEffectDefinitions,
65
70
  isDomClip: () => isDomClip,
71
+ isTimeDisplayFormat: () => isTimeDisplayFormat,
72
+ parseDisplayTime: () => parseDisplayTime,
66
73
  registerEffect: () => registerEffect,
67
- splitAtPlayhead: () => splitAtPlayhead
74
+ resolveTransportTarget: () => resolveTransportTarget,
75
+ splitAtPlayhead: () => splitAtPlayhead,
76
+ targetSupports: () => targetSupports,
77
+ warnOnce: () => warnOnce,
78
+ warnUnsupportedOnce: () => warnUnsupportedOnce
68
79
  });
69
80
  module.exports = __toCommonJS(index_exports);
70
81
 
@@ -957,42 +968,9 @@ DawPianoRollElement = __decorateClass([
957
968
  // src/elements/daw-playhead.ts
958
969
  var import_lit5 = require("lit");
959
970
  var import_decorators5 = require("lit/decorators.js");
960
-
961
- // src/controllers/animation-controller.ts
962
- var AnimationController = class {
963
- constructor(host) {
964
- this._rafId = null;
965
- this._callback = null;
966
- host.addController(this);
967
- }
968
- start(callback) {
969
- this.stop();
970
- this._callback = callback;
971
- const loop = () => {
972
- this._callback?.();
973
- this._rafId = requestAnimationFrame(loop);
974
- };
975
- this._rafId = requestAnimationFrame(loop);
976
- }
977
- stop() {
978
- if (this._rafId !== null) {
979
- cancelAnimationFrame(this._rafId);
980
- this._rafId = null;
981
- }
982
- this._callback = null;
983
- }
984
- hostConnected() {
985
- }
986
- hostDisconnected() {
987
- this.stop();
988
- }
989
- };
990
-
991
- // src/elements/daw-playhead.ts
992
971
  var DawPlayheadElement = class extends import_lit5.LitElement {
993
972
  constructor() {
994
973
  super(...arguments);
995
- this._animation = new AnimationController(this);
996
974
  this._line = null;
997
975
  }
998
976
  render() {
@@ -1001,52 +979,10 @@ var DawPlayheadElement = class extends import_lit5.LitElement {
1001
979
  firstUpdated() {
1002
980
  this._line = this.shadowRoot.querySelector("div");
1003
981
  }
1004
- startAnimation(getTime, sampleRate, samplesPerPixel) {
1005
- this._animation.start(() => {
1006
- const time = getTime();
1007
- const px = time * sampleRate / samplesPerPixel;
1008
- if (this._line) {
1009
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1010
- }
1011
- });
1012
- }
1013
- stopAnimation(time, sampleRate, samplesPerPixel) {
1014
- this._animation.stop();
1015
- const px = time * sampleRate / samplesPerPixel;
1016
- if (this._line) {
1017
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1018
- }
1019
- }
1020
- startBeatsAnimation(getTime, bpm, ppqn, ticksPerPixel) {
1021
- const ticksPerSecond = bpm * ppqn / 60;
1022
- this._animation.start(() => {
1023
- const time = getTime();
1024
- const px = time * ticksPerSecond / ticksPerPixel;
1025
- if (this._line) {
1026
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1027
- }
1028
- });
1029
- }
1030
- stopBeatsAnimation(time, bpm, ppqn, ticksPerPixel) {
1031
- this._animation.stop();
1032
- const px = time * bpm * ppqn / (60 * ticksPerPixel);
1033
- if (this._line) {
1034
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1035
- }
1036
- }
1037
- startBeatsAnimationWithMap(getTime, secondsToTicks, ticksPerPixel) {
1038
- this._animation.start(() => {
1039
- const time = getTime();
1040
- const tick = secondsToTicks(time);
1041
- const px = tick / ticksPerPixel;
1042
- if (this._line) {
1043
- this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1044
- }
1045
- });
1046
- }
1047
- stopBeatsAnimationWithMap(time, secondsToTicks, ticksPerPixel) {
1048
- this._animation.stop();
1049
- const px = secondsToTicks(time) / ticksPerPixel;
982
+ /** Position the playhead line at an absolute pixel offset on the timeline.
983
+ * The editor's PlaybackAnimationController drives this each frame — the
984
+ * playhead owns no animation loop or time math of its own. */
985
+ setPosition(px) {
1050
986
  if (this._line) {
1051
987
  this._line.style.transform = `translate3d(${px}px, 0, 0)`;
1052
988
  }
@@ -1104,12 +1040,102 @@ var import_decorators7 = require("lit/decorators.js");
1104
1040
 
1105
1041
  // src/elements/daw-transport-button.ts
1106
1042
  var import_lit7 = require("lit");
1043
+
1044
+ // src/utils/transport-capability.ts
1045
+ function resolveTransportTarget(el) {
1046
+ const transport = el.closest("daw-transport");
1047
+ return transport?.target ?? null;
1048
+ }
1049
+ function targetSupports(target, methods) {
1050
+ if (!target) return false;
1051
+ return methods.every((m) => typeof target[m] === "function");
1052
+ }
1053
+ function targetUndetermined(target) {
1054
+ if (!target) return true;
1055
+ const name = target.localName;
1056
+ return name.includes("-") && customElements.get(name) === void 0;
1057
+ }
1058
+ var warned = /* @__PURE__ */ new WeakMap();
1059
+ function warnOnce(element, message) {
1060
+ let messages = warned.get(element);
1061
+ if (!messages) {
1062
+ messages = /* @__PURE__ */ new Set();
1063
+ warned.set(element, messages);
1064
+ }
1065
+ if (messages.has(message)) return;
1066
+ messages.add(message);
1067
+ console.warn(message);
1068
+ }
1069
+ function warnNoTargetOnce(element, suffix) {
1070
+ warnOnce(
1071
+ element,
1072
+ `[dawcore] <${element.tagName.toLowerCase()}> has no target. Check <daw-transport for="..."> references a valid element id.` + (suffix ?? "")
1073
+ );
1074
+ }
1075
+ function warnUnsupportedOnce(element, methods) {
1076
+ warnOnce(
1077
+ element,
1078
+ `[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.`
1079
+ );
1080
+ }
1081
+
1082
+ // src/elements/daw-transport-button.ts
1107
1083
  var DawTransportButton = class extends import_lit7.LitElement {
1084
+ constructor() {
1085
+ super(...arguments);
1086
+ this._onCapabilityPointerEnter = () => {
1087
+ this.requestUpdate();
1088
+ };
1089
+ this._onCapabilityPointerDown = () => {
1090
+ const target = this.target;
1091
+ if (!target) {
1092
+ if (this._requiredMethods.length > 0) {
1093
+ warnNoTargetOnce(this);
1094
+ }
1095
+ return;
1096
+ }
1097
+ if (!this.targetSupported) {
1098
+ warnUnsupportedOnce(this, this._requiredMethods);
1099
+ }
1100
+ };
1101
+ }
1108
1102
  get target() {
1109
- const transport = this.closest("daw-transport");
1110
- return transport?.target ?? null;
1103
+ return resolveTransportTarget(this);
1104
+ }
1105
+ get _requiredMethods() {
1106
+ return this.constructor.requiredTargetMethods;
1107
+ }
1108
+ /**
1109
+ * False when this control declares requirements its target doesn't meet.
1110
+ * An undetermined target (missing, or a not-yet-upgraded custom element)
1111
+ * gets the benefit of the doubt and stays enabled — click-time resolution
1112
+ * warns if it's still unusable.
1113
+ */
1114
+ get targetSupported() {
1115
+ const required = this._requiredMethods;
1116
+ if (required.length === 0) return true;
1117
+ const target = this.target;
1118
+ if (targetUndetermined(target)) return true;
1119
+ return targetSupports(target, required);
1120
+ }
1121
+ connectedCallback() {
1122
+ super.connectedCallback();
1123
+ this.addEventListener("pointerdown", this._onCapabilityPointerDown);
1124
+ this.addEventListener("pointerenter", this._onCapabilityPointerEnter);
1125
+ requestAnimationFrame(() => {
1126
+ if (!this.isConnected) return;
1127
+ this.requestUpdate();
1128
+ });
1129
+ }
1130
+ disconnectedCallback() {
1131
+ super.disconnectedCallback();
1132
+ this.removeEventListener("pointerdown", this._onCapabilityPointerDown);
1133
+ this.removeEventListener("pointerenter", this._onCapabilityPointerEnter);
1111
1134
  }
1112
1135
  };
1136
+ /** Methods the transport target must implement for this control to be
1137
+ * enabled. Empty = works with any target. */
1138
+ DawTransportButton.requiredTargetMethods = [];
1113
1139
  DawTransportButton.styles = import_lit7.css`
1114
1140
  button {
1115
1141
  cursor: pointer;
@@ -3165,8 +3191,8 @@ var SpectrogramController = class {
3165
3191
  unregisterCanvas(canvasId) {
3166
3192
  this.orchestrator?.unregisterCanvas(canvasId);
3167
3193
  }
3168
- setViewport(state5) {
3169
- this.orchestrator?.setViewport(state5);
3194
+ setViewport(state7) {
3195
+ this.orchestrator?.setViewport(state7);
3170
3196
  }
3171
3197
  dispose() {
3172
3198
  if (this.orchestrator) {
@@ -3405,7 +3431,12 @@ var PointerHandler = class {
3405
3431
  if (h._engine) {
3406
3432
  h._engine.setSelection(0, 0);
3407
3433
  if (wasPlaying) {
3408
- h._engine.stop();
3434
+ h._inSeekTransition = true;
3435
+ try {
3436
+ h._engine.stop();
3437
+ } finally {
3438
+ h._inSeekTransition = false;
3439
+ }
3409
3440
  h._engine.play(time);
3410
3441
  h._startPlayhead();
3411
3442
  } else {
@@ -3746,6 +3777,57 @@ var ClipPointerHandler = class {
3746
3777
  }
3747
3778
  };
3748
3779
 
3780
+ // src/utils/time-display-format.ts
3781
+ var TIME_DISPLAY_FORMATS = [
3782
+ "hh:mm:ss.sss",
3783
+ "hh:mm:ss",
3784
+ "seconds"
3785
+ ];
3786
+ function isTimeDisplayFormat(value) {
3787
+ return TIME_DISPLAY_FORMATS.includes(value);
3788
+ }
3789
+ function clockFormat(totalSeconds, decimals) {
3790
+ const hours = Math.floor(totalSeconds / 3600);
3791
+ const minutes = Math.floor(totalSeconds / 60) % 60;
3792
+ const secsRem = totalSeconds % 60;
3793
+ let secs;
3794
+ if (decimals === 0) {
3795
+ secs = String(Math.min(Math.floor(secsRem + 1e-6), 59)).padStart(2, "0");
3796
+ } else {
3797
+ const factor = 10 ** decimals;
3798
+ const truncated = Math.min(Math.floor(secsRem * factor + 1e-6), 60 * factor - 1);
3799
+ secs = (truncated / factor).toFixed(decimals).padStart(decimals + 3, "0");
3800
+ }
3801
+ return String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0") + ":" + secs;
3802
+ }
3803
+ function formatDisplayTime(seconds, format) {
3804
+ const safe = Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
3805
+ switch (format) {
3806
+ case "seconds":
3807
+ return safe.toFixed(3);
3808
+ case "hh:mm:ss":
3809
+ return clockFormat(safe, 0);
3810
+ case "hh:mm:ss.sss":
3811
+ default:
3812
+ return clockFormat(safe, 3);
3813
+ }
3814
+ }
3815
+ function parseDisplayTime(value, format) {
3816
+ if (!value) return 0;
3817
+ let seconds = 0;
3818
+ if (format === "seconds") {
3819
+ seconds = parseFloat(value) || 0;
3820
+ } else {
3821
+ const parts = value.split(":");
3822
+ if (parts.length !== 3) return 0;
3823
+ const h = parseInt(parts[0], 10) || 0;
3824
+ const m = parseInt(parts[1], 10) || 0;
3825
+ const s = parseFloat(parts[2]) || 0;
3826
+ seconds = h * 3600 + m * 60 + s;
3827
+ }
3828
+ return Math.max(0, seconds);
3829
+ }
3830
+
3749
3831
  // src/interactions/file-loader.ts
3750
3832
  var import_core7 = require("@waveform-playlist/core");
3751
3833
  async function loadFiles(host, files) {
@@ -4064,9 +4146,9 @@ function splitAtPlayhead(host) {
4064
4146
  function canSplitAtTime(host, time) {
4065
4147
  const { engine } = host;
4066
4148
  if (!engine) return false;
4067
- const state5 = engine.getState();
4068
- if (!state5.selectedTrackId) return false;
4069
- const track = state5.tracks.find((t) => t.id === state5.selectedTrackId);
4149
+ const state7 = engine.getState();
4150
+ if (!state7.selectedTrackId) return false;
4151
+ const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
4070
4152
  if (!track) return false;
4071
4153
  const atSample = Math.round(time * host.effectiveSampleRate);
4072
4154
  const clip = findClipAtSample(track.clips, atSample);
@@ -4256,9 +4338,9 @@ var EffectsChainController = class {
4256
4338
  ...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
4257
4339
  };
4258
4340
  }
4259
- let state5;
4341
+ let state7;
4260
4342
  try {
4261
- state5 = await entry.instance.getState?.();
4343
+ state7 = await entry.instance.getState?.();
4262
4344
  } catch (err) {
4263
4345
  console.warn(
4264
4346
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4268,7 +4350,7 @@ var EffectsChainController = class {
4268
4350
  kind: "wam",
4269
4351
  ...sourceFields,
4270
4352
  bypassed: entry.bypassed,
4271
- ...state5 !== void 0 ? { state: state5 } : {}
4353
+ ...state7 !== void 0 ? { state: state7 } : {}
4272
4354
  };
4273
4355
  }
4274
4356
  return {
@@ -5440,6 +5522,75 @@ var ScrollSyncController = class {
5440
5522
  }
5441
5523
  };
5442
5524
 
5525
+ // src/controllers/animation-controller.ts
5526
+ var AnimationController = class {
5527
+ constructor(host) {
5528
+ this._rafId = null;
5529
+ this._callback = null;
5530
+ host.addController(this);
5531
+ }
5532
+ start(callback) {
5533
+ this.stop();
5534
+ this._callback = callback;
5535
+ const loop = () => {
5536
+ this._callback?.();
5537
+ this._rafId = requestAnimationFrame(loop);
5538
+ };
5539
+ this._rafId = requestAnimationFrame(loop);
5540
+ }
5541
+ stop() {
5542
+ if (this._rafId !== null) {
5543
+ cancelAnimationFrame(this._rafId);
5544
+ this._rafId = null;
5545
+ }
5546
+ this._callback = null;
5547
+ }
5548
+ hostConnected() {
5549
+ }
5550
+ hostDisconnected() {
5551
+ this.stop();
5552
+ }
5553
+ };
5554
+
5555
+ // src/controllers/playback-animation-controller.ts
5556
+ var PlaybackAnimationController = class {
5557
+ constructor(host, options) {
5558
+ this._running = false;
5559
+ this._lastDispatchedTime = null;
5560
+ this._host = host;
5561
+ this._options = options;
5562
+ this._animation = new AnimationController(host);
5563
+ }
5564
+ start(getTime) {
5565
+ this._running = true;
5566
+ this._animation.start(() => {
5567
+ const time = getTime();
5568
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
5569
+ this._dispatchTimeUpdate(time);
5570
+ });
5571
+ }
5572
+ stop(finalTime, opts) {
5573
+ const wasRunning = this._running;
5574
+ this._running = false;
5575
+ this._animation.stop();
5576
+ this._options.getPlayhead()?.setPosition(this._options.timeToPixels(finalTime));
5577
+ if (opts?.dispatch === false) return;
5578
+ if (wasRunning || finalTime !== this._lastDispatchedTime) {
5579
+ this._dispatchTimeUpdate(finalTime);
5580
+ }
5581
+ }
5582
+ _dispatchTimeUpdate(time) {
5583
+ this._lastDispatchedTime = time;
5584
+ this._host.dispatchEvent(
5585
+ new CustomEvent("daw-timeupdate", {
5586
+ bubbles: true,
5587
+ composed: true,
5588
+ detail: { time }
5589
+ })
5590
+ );
5591
+ }
5592
+ };
5593
+
5443
5594
  // src/elements/daw-editor.ts
5444
5595
  var import_meta = {};
5445
5596
  var RULER_HEIGHT = 30;
@@ -5448,6 +5599,7 @@ var DawEditorElement = class extends import_lit15.LitElement {
5448
5599
  constructor() {
5449
5600
  super(...arguments);
5450
5601
  this._samplesPerPixel = 1024;
5602
+ this._timeFormat = "hh:mm:ss.sss";
5451
5603
  this.waveHeight = 128;
5452
5604
  this.timescale = false;
5453
5605
  this.mono = false;
@@ -5497,6 +5649,20 @@ var DawEditorElement = class extends import_lit15.LitElement {
5497
5649
  this._childObserver = null;
5498
5650
  this._audioResume = new AudioResumeController(this);
5499
5651
  this._recordingController = new RecordingController(this);
5652
+ // Closures (not direct references) — _timeToPixels/_getPlayhead are
5653
+ // declared later in the class body; class-field init order would read
5654
+ // `undefined` for a direct reference here.
5655
+ this._playbackAnimation = new PlaybackAnimationController(this, {
5656
+ timeToPixels: (time) => this._timeToPixels(time),
5657
+ getPlayhead: () => this._getPlayhead()
5658
+ });
5659
+ /**
5660
+ * True while a seek-while-playing stop+play transition is in flight.
5661
+ * Suppresses the transient settle dispatch from the engine 'stop' handler
5662
+ * (which would otherwise leak a backward-jumping daw-timeupdate at the
5663
+ * play-start position). Non-private: pointer-handler's seek path sets it.
5664
+ */
5665
+ this._inSeekTransition = false;
5500
5666
  this._spectrogramController = null;
5501
5667
  this._clipPointer = new ClipPointerHandler(this);
5502
5668
  this._pointer = new PointerHandler(this);
@@ -5702,6 +5868,14 @@ var DawEditorElement = class extends import_lit15.LitElement {
5702
5868
  /** Set in togglePauseRecording when Transport is paused alongside the
5703
5869
  * worklet, so resume can restart it. Cleared on resume and on stop. */
5704
5870
  this._wasPlayingDuringRecording = false;
5871
+ // --- Playback animation (single RAF loop: playhead + daw-timeupdate) ---
5872
+ /** Convert playback seconds to a timeline pixel offset for the active mode. */
5873
+ this._timeToPixels = (time) => {
5874
+ if (this.scaleMode === "beats") {
5875
+ return this._secondsToTicks(time) / this.ticksPerPixel;
5876
+ }
5877
+ return time * this.effectiveSampleRate / this.samplesPerPixel;
5878
+ };
5705
5879
  }
5706
5880
  get samplesPerPixel() {
5707
5881
  return this._samplesPerPixel;
@@ -5718,6 +5892,35 @@ var DawEditorElement = class extends import_lit15.LitElement {
5718
5892
  this._samplesPerPixel = clamped;
5719
5893
  this.requestUpdate("samplesPerPixel", old);
5720
5894
  }
5895
+ get timeFormat() {
5896
+ return this._timeFormat;
5897
+ }
5898
+ set timeFormat(value) {
5899
+ if (!isTimeDisplayFormat(value)) {
5900
+ console.warn(
5901
+ '[dawcore] timeFormat: invalid format "' + String(value) + '" ignored. Valid formats: ' + TIME_DISPLAY_FORMATS.join(", ")
5902
+ );
5903
+ if (this.hasAttribute("time-format") && this.getAttribute("time-format") !== this._timeFormat) {
5904
+ this.setAttribute("time-format", this._timeFormat);
5905
+ }
5906
+ return;
5907
+ }
5908
+ if (value === this._timeFormat) return;
5909
+ const old = this._timeFormat;
5910
+ this._timeFormat = value;
5911
+ this.requestUpdate("timeFormat", old);
5912
+ this.dispatchEvent(
5913
+ new CustomEvent("daw-time-format-change", {
5914
+ bubbles: true,
5915
+ composed: true,
5916
+ detail: { format: value }
5917
+ })
5918
+ );
5919
+ }
5920
+ /** Set the time display format. Sugar over the `timeFormat` property. */
5921
+ setTimeFormat(format) {
5922
+ this.timeFormat = format;
5923
+ }
5721
5924
  get spectrogramConfig() {
5722
5925
  return this._spectrogramConfig;
5723
5926
  }
@@ -6843,17 +7046,23 @@ var DawEditorElement = class extends import_lit15.LitElement {
6843
7046
  zoomLevels: [256, 512, 1024, 2048, 4096, 8192, this.samplesPerPixel].filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b)
6844
7047
  });
6845
7048
  let lastTracksVersion = -1;
7049
+ let lastMixerVersion = -1;
6846
7050
  engine.on("statechange", (engineState) => {
6847
7051
  this._isPlaying = engineState.isPlaying;
6848
7052
  this._duration = engineState.duration;
6849
7053
  this._selectedTrackId = engineState.selectedTrackId;
6850
- if (engineState.tracksVersion !== lastTracksVersion) {
7054
+ const structuralChange = engineState.tracksVersion !== lastTracksVersion;
7055
+ const mixerChange = engineState.mixerVersion !== lastMixerVersion;
7056
+ if (structuralChange || mixerChange) {
6851
7057
  lastTracksVersion = engineState.tracksVersion;
7058
+ lastMixerVersion = engineState.mixerVersion;
6852
7059
  const nextTracks = /* @__PURE__ */ new Map();
6853
7060
  for (const track of engineState.tracks) {
6854
7061
  nextTracks.set(track.id, track);
6855
7062
  }
6856
7063
  this._engineTracks = nextTracks;
7064
+ }
7065
+ if (structuralChange) {
6857
7066
  this._effectsManager?.rewireTrackChains();
6858
7067
  const audioTracks = engineState.tracks.filter((t) => {
6859
7068
  const desc = this._tracks.get(t.id);
@@ -7214,7 +7423,12 @@ var DawEditorElement = class extends import_lit15.LitElement {
7214
7423
  return;
7215
7424
  }
7216
7425
  if (this._isPlaying) {
7217
- this.stop();
7426
+ this._inSeekTransition = true;
7427
+ try {
7428
+ this.stop();
7429
+ } finally {
7430
+ this._inSeekTransition = false;
7431
+ }
7218
7432
  this.play(time);
7219
7433
  } else {
7220
7434
  this._engine.seek(time);
@@ -7273,6 +7487,14 @@ var DawEditorElement = class extends import_lit15.LitElement {
7273
7487
  }
7274
7488
  return this._currentTime;
7275
7489
  }
7490
+ /** Read-only: whether playback is running (HTMLMediaElement-adjacent). */
7491
+ get isPlaying() {
7492
+ return this._isPlaying;
7493
+ }
7494
+ /** Read-only: total content duration in seconds. */
7495
+ get duration() {
7496
+ return this._duration;
7497
+ }
7276
7498
  get isRecording() {
7277
7499
  return this._recordingController.isRecording;
7278
7500
  }
@@ -7363,33 +7585,15 @@ var DawEditorElement = class extends import_lit15.LitElement {
7363
7585
  `;
7364
7586
  });
7365
7587
  }
7366
- // --- Playhead ---
7367
7588
  _startPlayhead() {
7368
- const playhead = this._getPlayhead();
7369
- if (!playhead || !this._engine) return;
7589
+ if (!this._engine) return;
7370
7590
  const engine = this._engine;
7371
- const audibleTime = () => engine.getAudibleTime();
7372
- if (this.scaleMode === "beats") {
7373
- const secondsToTicksFn = (s) => this._secondsToTicks(s);
7374
- playhead.startBeatsAnimationWithMap(audibleTime, secondsToTicksFn, this.ticksPerPixel);
7375
- } else {
7376
- playhead.startAnimation(audibleTime, this.effectiveSampleRate, this.samplesPerPixel);
7377
- }
7591
+ this._playbackAnimation.start(() => engine.getAudibleTime());
7378
7592
  }
7379
7593
  _stopPlayhead() {
7380
- const playhead = this._getPlayhead();
7381
- if (!playhead) return;
7382
7594
  const t = this._currentTime;
7383
7595
  const visualTime = Number.isFinite(t) ? Math.max(0, t) : 0;
7384
- if (this.scaleMode === "beats") {
7385
- playhead.stopBeatsAnimationWithMap(
7386
- visualTime,
7387
- (s) => this._secondsToTicks(s),
7388
- this.ticksPerPixel
7389
- );
7390
- } else {
7391
- playhead.stopAnimation(visualTime, this.effectiveSampleRate, this.samplesPerPixel);
7392
- }
7596
+ this._playbackAnimation.stop(visualTime, { dispatch: !this._inSeekTransition });
7393
7597
  }
7394
7598
  _getPlayhead() {
7395
7599
  return this.shadowRoot?.querySelector("daw-playhead");
@@ -7734,6 +7938,9 @@ DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "mut
7734
7938
  __decorateClass([
7735
7939
  (0, import_decorators13.property)({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
7736
7940
  ], DawEditorElement.prototype, "samplesPerPixel", 1);
7941
+ __decorateClass([
7942
+ (0, import_decorators13.property)({ attribute: "time-format", reflect: true, noAccessor: true })
7943
+ ], DawEditorElement.prototype, "timeFormat", 1);
7737
7944
  __decorateClass([
7738
7945
  (0, import_decorators13.property)({ type: Number, attribute: "wave-height" })
7739
7946
  ], DawEditorElement.prototype, "waveHeight", 2);
@@ -7914,7 +8121,12 @@ var DawRecordButtonElement = class extends DawTransportButton {
7914
8121
  }
7915
8122
  render() {
7916
8123
  return import_lit17.html`
7917
- <button part="button" ?data-recording=${this._isRecording} @click=${this._onClick}>
8124
+ <button
8125
+ part="button"
8126
+ ?disabled=${!this.targetSupported}
8127
+ ?data-recording=${this._isRecording}
8128
+ @click=${this._onClick}
8129
+ >
7918
8130
  <slot>Record</slot>
7919
8131
  </button>
7920
8132
  `;
@@ -7923,14 +8135,16 @@ var DawRecordButtonElement = class extends DawTransportButton {
7923
8135
  if (this._isRecording) return;
7924
8136
  const target = this.target;
7925
8137
  if (!target) {
7926
- console.warn(
7927
- '[dawcore] <daw-record-button> has no target. Check <daw-transport for="..."> references a valid <daw-editor> id.'
7928
- );
8138
+ warnNoTargetOnce(this);
7929
8139
  return;
7930
8140
  }
7931
8141
  target.startRecording(target.recordingStream);
7932
8142
  }
7933
8143
  };
8144
+ DawRecordButtonElement.requiredTargetMethods = [
8145
+ "startRecording",
8146
+ "stopRecording"
8147
+ ];
7934
8148
  DawRecordButtonElement.styles = [
7935
8149
  DawTransportButton.styles,
7936
8150
  import_lit17.css`
@@ -8307,6 +8521,198 @@ __decorateClass([
8307
8521
  DawSpectrogramElement = __decorateClass([
8308
8522
  (0, import_decorators17.customElement)("daw-spectrogram")
8309
8523
  ], DawSpectrogramElement);
8524
+
8525
+ // src/elements/daw-time-display.ts
8526
+ var import_lit20 = require("lit");
8527
+ var import_decorators18 = require("lit/decorators.js");
8528
+ var DawTimeDisplayElement = class extends import_lit20.LitElement {
8529
+ constructor() {
8530
+ super(...arguments);
8531
+ this._time = null;
8532
+ this._format = "hh:mm:ss.sss";
8533
+ this._onTimeUpdate = (e) => {
8534
+ if (e.target !== this.target) return;
8535
+ if (this._time === null) {
8536
+ const timeFormat = e.target.timeFormat;
8537
+ if (isTimeDisplayFormat(timeFormat)) this._format = timeFormat;
8538
+ }
8539
+ this._time = e.detail.time;
8540
+ };
8541
+ this._onFormatChange = (e) => {
8542
+ if (e.target !== this.target) return;
8543
+ const detail = e.detail;
8544
+ if (isTimeDisplayFormat(detail.format)) {
8545
+ this._format = detail.format;
8546
+ }
8547
+ };
8548
+ }
8549
+ get target() {
8550
+ return resolveTransportTarget(this);
8551
+ }
8552
+ connectedCallback() {
8553
+ super.connectedCallback();
8554
+ document.addEventListener("daw-timeupdate", this._onTimeUpdate);
8555
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8556
+ requestAnimationFrame(() => this._syncFromTarget());
8557
+ }
8558
+ disconnectedCallback() {
8559
+ super.disconnectedCallback();
8560
+ document.removeEventListener("daw-timeupdate", this._onTimeUpdate);
8561
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8562
+ }
8563
+ _syncFromTarget() {
8564
+ if (!this.isConnected) return;
8565
+ const target = this.target;
8566
+ if (!target || typeof target.currentTime !== "number") {
8567
+ warnNoTargetOnce(
8568
+ this,
8569
+ " The display recovers automatically once the target dispatches daw-timeupdate."
8570
+ );
8571
+ return;
8572
+ }
8573
+ this._time = target.currentTime;
8574
+ const fmt = target.timeFormat;
8575
+ if (isTimeDisplayFormat(fmt)) {
8576
+ this._format = fmt;
8577
+ }
8578
+ }
8579
+ render() {
8580
+ const text = this._time === null ? "--:--:--" : formatDisplayTime(this._time, this._format);
8581
+ return import_lit20.html`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
8582
+ }
8583
+ };
8584
+ DawTimeDisplayElement.styles = import_lit20.css`
8585
+ span {
8586
+ display: inline-block;
8587
+ font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
8588
+ font-variant-numeric: tabular-nums;
8589
+ color: var(--daw-controls-text, #e0d4c8);
8590
+ background: var(--daw-controls-background, #1a1a2e);
8591
+ border: 1px solid currentColor;
8592
+ padding: 4px 8px;
8593
+ }
8594
+ `;
8595
+ __decorateClass([
8596
+ (0, import_decorators18.state)()
8597
+ ], DawTimeDisplayElement.prototype, "_time", 2);
8598
+ __decorateClass([
8599
+ (0, import_decorators18.state)()
8600
+ ], DawTimeDisplayElement.prototype, "_format", 2);
8601
+ DawTimeDisplayElement = __decorateClass([
8602
+ (0, import_decorators18.customElement)("daw-time-display")
8603
+ ], DawTimeDisplayElement);
8604
+
8605
+ // src/elements/daw-time-format.ts
8606
+ var import_lit21 = require("lit");
8607
+ var import_decorators19 = require("lit/decorators.js");
8608
+ var DawTimeFormatElement = class extends import_lit21.LitElement {
8609
+ constructor() {
8610
+ super(...arguments);
8611
+ this._format = "hh:mm:ss.sss";
8612
+ this._onFormatChange = (e) => {
8613
+ if (e.target !== this.target) return;
8614
+ const detail = e.detail;
8615
+ if (isTimeDisplayFormat(detail.format)) {
8616
+ this._format = detail.format;
8617
+ }
8618
+ };
8619
+ this._onPointerEnter = () => {
8620
+ this.requestUpdate();
8621
+ };
8622
+ this._onPointerDown = () => {
8623
+ const target = this.target;
8624
+ if (!target) {
8625
+ warnNoTargetOnce(this);
8626
+ return;
8627
+ }
8628
+ if (!this._targetSupported) {
8629
+ warnUnsupportedOnce(this, ["setTimeFormat"]);
8630
+ }
8631
+ };
8632
+ }
8633
+ get target() {
8634
+ return resolveTransportTarget(this);
8635
+ }
8636
+ /**
8637
+ * False when the target doesn't implement setTimeFormat. An undetermined
8638
+ * target (missing, or a not-yet-upgraded custom element) gets the benefit
8639
+ * of the doubt and stays enabled — interaction-time resolution warns if
8640
+ * it's still unusable.
8641
+ */
8642
+ get _targetSupported() {
8643
+ const target = this.target;
8644
+ if (targetUndetermined(target)) return true;
8645
+ return targetSupports(target, ["setTimeFormat"]);
8646
+ }
8647
+ connectedCallback() {
8648
+ super.connectedCallback();
8649
+ document.addEventListener("daw-time-format-change", this._onFormatChange);
8650
+ this.addEventListener("pointerdown", this._onPointerDown);
8651
+ this.addEventListener("pointerenter", this._onPointerEnter);
8652
+ requestAnimationFrame(() => {
8653
+ if (!this.isConnected) return;
8654
+ const target = this.target;
8655
+ if (target && isTimeDisplayFormat(target.timeFormat)) {
8656
+ this._format = target.timeFormat;
8657
+ }
8658
+ this.requestUpdate();
8659
+ });
8660
+ }
8661
+ disconnectedCallback() {
8662
+ super.disconnectedCallback();
8663
+ document.removeEventListener("daw-time-format-change", this._onFormatChange);
8664
+ this.removeEventListener("pointerdown", this._onPointerDown);
8665
+ this.removeEventListener("pointerenter", this._onPointerEnter);
8666
+ }
8667
+ updated() {
8668
+ const select = this.shadowRoot?.querySelector("select");
8669
+ if (select && select.value !== this._format) {
8670
+ select.value = this._format;
8671
+ }
8672
+ }
8673
+ _onSelectChange(e) {
8674
+ const value = e.target.value;
8675
+ const target = this.target;
8676
+ if (!target) {
8677
+ warnNoTargetOnce(this);
8678
+ return;
8679
+ }
8680
+ target.setTimeFormat?.(value);
8681
+ }
8682
+ render() {
8683
+ return import_lit21.html`
8684
+ <select
8685
+ aria-label="Time format"
8686
+ ?disabled=${!this._targetSupported}
8687
+ @change=${this._onSelectChange}
8688
+ >
8689
+ ${TIME_DISPLAY_FORMATS.map(
8690
+ (f) => import_lit21.html`<option value=${f} ?selected=${f === this._format}>${f}</option>`
8691
+ )}
8692
+ </select>
8693
+ `;
8694
+ }
8695
+ };
8696
+ DawTimeFormatElement.styles = import_lit21.css`
8697
+ select {
8698
+ cursor: pointer;
8699
+ background: var(--daw-controls-background, #1a1a2e);
8700
+ color: var(--daw-controls-text, #e0d4c8);
8701
+ border: 1px solid currentColor;
8702
+ padding: 4px 8px;
8703
+ font: inherit;
8704
+ }
8705
+ select:disabled {
8706
+ opacity: 0.4;
8707
+ cursor: default;
8708
+ }
8709
+ `;
8710
+ __decorateClass([
8711
+ (0, import_decorators19.state)()
8712
+ ], DawTimeFormatElement.prototype, "_format", 2);
8713
+ DawTimeFormatElement = __decorateClass([
8714
+ (0, import_decorators19.customElement)("daw-time-format")
8715
+ ], DawTimeFormatElement);
8310
8716
  // Annotate the CommonJS export names for ESM import in node:
8311
8717
  0 && (module.exports = {
8312
8718
  AudioResumeController,
@@ -8324,17 +8730,28 @@ DawSpectrogramElement = __decorateClass([
8324
8730
  DawSelectionElement,
8325
8731
  DawSpectrogramElement,
8326
8732
  DawStopButtonElement,
8733
+ DawTimeDisplayElement,
8734
+ DawTimeFormatElement,
8327
8735
  DawTrackControlsElement,
8328
8736
  DawTrackElement,
8329
8737
  DawTransportButton,
8330
8738
  DawTransportElement,
8331
8739
  DawWaveformElement,
8740
+ PlaybackAnimationController,
8332
8741
  RecordingController,
8333
8742
  SpectrogramController,
8743
+ TIME_DISPLAY_FORMATS,
8334
8744
  createEffectInstance,
8745
+ formatDisplayTime,
8335
8746
  getEffectDefinitions,
8336
8747
  isDomClip,
8748
+ isTimeDisplayFormat,
8749
+ parseDisplayTime,
8337
8750
  registerEffect,
8338
- splitAtPlayhead
8751
+ resolveTransportTarget,
8752
+ splitAtPlayhead,
8753
+ targetSupports,
8754
+ warnOnce,
8755
+ warnUnsupportedOnce
8339
8756
  });
8340
8757
  //# sourceMappingURL=index.js.map