@webmusic/kernel 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +2 -0
  3. package/README.md +103 -64
  4. package/dist/audio-context.cjs.map +1 -1
  5. package/dist/build-receipt.json +3 -3
  6. package/dist/chunk-27LH6QLZ.cjs +277 -0
  7. package/dist/chunk-27LH6QLZ.cjs.map +1 -0
  8. package/dist/chunk-3INDOVUC.cjs.map +1 -1
  9. package/dist/chunk-3RR2VIKA.js +393 -0
  10. package/dist/chunk-3RR2VIKA.js.map +1 -0
  11. package/dist/chunk-3YTKIKKX.cjs +378 -0
  12. package/dist/chunk-3YTKIKKX.cjs.map +1 -0
  13. package/dist/chunk-4RG4WQKC.js +360 -0
  14. package/dist/chunk-4RG4WQKC.js.map +1 -0
  15. package/dist/chunk-5AHVQXTF.cjs +620 -0
  16. package/dist/chunk-5AHVQXTF.cjs.map +1 -0
  17. package/dist/chunk-624KWJWZ.js +170 -0
  18. package/dist/chunk-624KWJWZ.js.map +1 -0
  19. package/dist/chunk-6HGFEKD3.cjs +851 -0
  20. package/dist/chunk-6HGFEKD3.cjs.map +1 -0
  21. package/dist/chunk-7ZTZZ5PN.cjs.map +1 -1
  22. package/dist/chunk-ALWV4P7D.js +726 -0
  23. package/dist/chunk-ALWV4P7D.js.map +1 -0
  24. package/dist/chunk-BADJJ6DV.cjs +143 -0
  25. package/dist/chunk-BADJJ6DV.cjs.map +1 -0
  26. package/dist/chunk-C3LMS36L.cjs +393 -0
  27. package/dist/chunk-C3LMS36L.cjs.map +1 -0
  28. package/dist/chunk-C3YWUZW3.cjs.map +1 -1
  29. package/dist/chunk-CR6OUWBJ.cjs +726 -0
  30. package/dist/chunk-CR6OUWBJ.cjs.map +1 -0
  31. package/dist/chunk-CYWDZLWC.js +2141 -0
  32. package/dist/chunk-CYWDZLWC.js.map +1 -0
  33. package/dist/chunk-DDOGX2D5.js +378 -0
  34. package/dist/chunk-DDOGX2D5.js.map +1 -0
  35. package/dist/chunk-DVN6E5U3.js +620 -0
  36. package/dist/chunk-DVN6E5U3.js.map +1 -0
  37. package/dist/chunk-EURMRU2S.js +208 -0
  38. package/dist/chunk-EURMRU2S.js.map +1 -0
  39. package/dist/chunk-EXDCK2VL.cjs +20 -0
  40. package/dist/chunk-EXDCK2VL.cjs.map +1 -0
  41. package/dist/chunk-G5EIUP52.js +114 -0
  42. package/dist/chunk-G5EIUP52.js.map +1 -0
  43. package/dist/chunk-GB4DGKLZ.js +143 -0
  44. package/dist/chunk-GB4DGKLZ.js.map +1 -0
  45. package/dist/chunk-GPOEAYOW.js +2147 -0
  46. package/dist/chunk-GPOEAYOW.js.map +1 -0
  47. package/dist/chunk-I4YMA5VM.cjs +120 -0
  48. package/dist/chunk-I4YMA5VM.cjs.map +1 -0
  49. package/dist/chunk-IVWHMDCB.cjs +4383 -0
  50. package/dist/chunk-IVWHMDCB.cjs.map +1 -0
  51. package/dist/chunk-JFCBJMA7.cjs +2147 -0
  52. package/dist/chunk-JFCBJMA7.cjs.map +1 -0
  53. package/dist/chunk-JLVSAZ3K.cjs +813 -0
  54. package/dist/chunk-JLVSAZ3K.cjs.map +1 -0
  55. package/dist/chunk-K7FYH6UG.cjs +208 -0
  56. package/dist/chunk-K7FYH6UG.cjs.map +1 -0
  57. package/dist/chunk-L4MYCETM.cjs +970 -0
  58. package/dist/chunk-L4MYCETM.cjs.map +1 -0
  59. package/dist/chunk-MNCMYNYL.js +970 -0
  60. package/dist/chunk-MNCMYNYL.js.map +1 -0
  61. package/dist/chunk-NT2BZ3QM.js +120 -0
  62. package/dist/chunk-NT2BZ3QM.js.map +1 -0
  63. package/dist/chunk-O7SA5GLC.js +277 -0
  64. package/dist/chunk-O7SA5GLC.js.map +1 -0
  65. package/dist/chunk-OCKAHITL.cjs +548 -0
  66. package/dist/chunk-OCKAHITL.cjs.map +1 -0
  67. package/dist/chunk-OTXYWCLA.js +206 -0
  68. package/dist/chunk-OTXYWCLA.js.map +1 -0
  69. package/dist/chunk-P6ZA63J7.js +548 -0
  70. package/dist/chunk-P6ZA63J7.js.map +1 -0
  71. package/dist/chunk-QLF3BOST.js +20 -0
  72. package/dist/chunk-QLF3BOST.js.map +1 -0
  73. package/dist/chunk-RCWFRZDR.js +4383 -0
  74. package/dist/chunk-RCWFRZDR.js.map +1 -0
  75. package/dist/chunk-RZBLPM3L.cjs +206 -0
  76. package/dist/chunk-RZBLPM3L.cjs.map +1 -0
  77. package/dist/chunk-TA3TNJZU.cjs +360 -0
  78. package/dist/chunk-TA3TNJZU.cjs.map +1 -0
  79. package/dist/chunk-TZSRPTQL.cjs +2141 -0
  80. package/dist/chunk-TZSRPTQL.cjs.map +1 -0
  81. package/dist/chunk-UMTPJ76S.cjs.map +1 -1
  82. package/dist/chunk-UY77FXDW.js +813 -0
  83. package/dist/chunk-UY77FXDW.js.map +1 -0
  84. package/dist/chunk-VFU3S7OC.js +851 -0
  85. package/dist/chunk-VFU3S7OC.js.map +1 -0
  86. package/dist/chunk-VY6WWZSW.cjs.map +1 -1
  87. package/dist/chunk-WN5DZOVT.cjs +170 -0
  88. package/dist/chunk-WN5DZOVT.cjs.map +1 -0
  89. package/dist/chunk-WOPW6WLR.cjs.map +1 -1
  90. package/dist/chunk-XBSIYUHM.cjs +114 -0
  91. package/dist/chunk-XBSIYUHM.cjs.map +1 -0
  92. package/dist/chunk-ZMU72HJS.cjs.map +1 -1
  93. package/dist/context-DSa0ymyN.d.cts +664 -0
  94. package/dist/context-DaxfAg3b.d.ts +664 -0
  95. package/dist/effect-chain-Cu03O5Y0.d.ts +91 -0
  96. package/dist/effect-chain-Do75T7uK.d.cts +91 -0
  97. package/dist/effect.cjs +16 -1
  98. package/dist/effect.cjs.map +1 -1
  99. package/dist/effect.d.cts +56 -14
  100. package/dist/effect.d.ts +56 -14
  101. package/dist/effect.js +16 -1
  102. package/dist/elements.cjs +37 -2
  103. package/dist/elements.cjs.map +1 -1
  104. package/dist/elements.d.cts +197 -8
  105. package/dist/elements.d.ts +197 -8
  106. package/dist/elements.js +36 -1
  107. package/dist/events.cjs.map +1 -1
  108. package/dist/index.cjs +555 -8
  109. package/dist/index.cjs.map +1 -1
  110. package/dist/index.d.cts +16 -4
  111. package/dist/index.d.ts +16 -4
  112. package/dist/index.js +566 -19
  113. package/dist/message.cjs +104 -0
  114. package/dist/message.cjs.map +1 -0
  115. package/dist/message.d.cts +738 -0
  116. package/dist/message.d.ts +738 -0
  117. package/dist/message.js +104 -0
  118. package/dist/meter.cjs.map +1 -1
  119. package/dist/module-control-C25BMtH7.d.ts +61 -0
  120. package/dist/module-control-yH6nTJM9.d.cts +61 -0
  121. package/dist/module-plugin-BnPmq1VP.d.ts +198 -0
  122. package/dist/module-plugin-CHb-5W0Y.d.cts +198 -0
  123. package/dist/module.cjs +263 -0
  124. package/dist/module.cjs.map +1 -0
  125. package/dist/module.d.cts +1112 -0
  126. package/dist/module.d.ts +1112 -0
  127. package/dist/module.js +263 -0
  128. package/dist/parameter-DwQzFmBR.d.cts +172 -0
  129. package/dist/parameter-DwQzFmBR.d.ts +172 -0
  130. package/dist/player.cjs.map +1 -1
  131. package/dist/processor-worklet.cjs +18 -0
  132. package/dist/processor-worklet.cjs.map +1 -0
  133. package/dist/processor-worklet.d.cts +166 -0
  134. package/dist/processor-worklet.d.ts +166 -0
  135. package/dist/processor-worklet.js +18 -0
  136. package/dist/processor-worklet.js.map +1 -0
  137. package/dist/processor.cjs +51 -0
  138. package/dist/processor.cjs.map +1 -0
  139. package/dist/processor.d.cts +397 -0
  140. package/dist/processor.d.ts +397 -0
  141. package/dist/processor.js +51 -0
  142. package/dist/processor.js.map +1 -0
  143. package/dist/project-types-BU4awMnL.d.ts +323 -0
  144. package/dist/project-types-DufCV8Ma.d.cts +323 -0
  145. package/dist/ring-C-i9N90a.d.cts +139 -0
  146. package/dist/ring-DkcMt2Eg.d.ts +139 -0
  147. package/dist/sequence.cjs +68 -0
  148. package/dist/sequence.cjs.map +1 -0
  149. package/dist/sequence.d.cts +303 -0
  150. package/dist/sequence.d.ts +303 -0
  151. package/dist/sequence.js +68 -0
  152. package/dist/sequence.js.map +1 -0
  153. package/dist/session.cjs +16 -0
  154. package/dist/session.cjs.map +1 -0
  155. package/dist/session.d.cts +407 -0
  156. package/dist/session.d.ts +407 -0
  157. package/dist/session.js +16 -0
  158. package/dist/session.js.map +1 -0
  159. package/dist/tick.cjs.map +1 -1
  160. package/dist/transport.cjs +50 -2
  161. package/dist/transport.cjs.map +1 -1
  162. package/dist/transport.d.cts +145 -1
  163. package/dist/transport.d.ts +145 -1
  164. package/dist/transport.js +51 -3
  165. package/dist/worker.cjs.map +1 -1
  166. package/package.json +61 -10
  167. package/dist/chunk-53YD73OY.js +0 -162
  168. package/dist/chunk-53YD73OY.js.map +0 -1
  169. package/dist/chunk-54JYWB5X.cjs +0 -1051
  170. package/dist/chunk-54JYWB5X.cjs.map +0 -1
  171. package/dist/chunk-BR63OD53.cjs +0 -1
  172. package/dist/chunk-BR63OD53.cjs.map +0 -1
  173. package/dist/chunk-ON64FRCF.js +0 -1051
  174. package/dist/chunk-ON64FRCF.js.map +0 -1
  175. package/dist/chunk-SM5YPDDI.cjs +0 -162
  176. package/dist/chunk-SM5YPDDI.cjs.map +0 -1
  177. package/dist/chunk-TEM2I2NN.js +0 -1
  178. package/dist/chunk-VVZX7DQ6.cjs +0 -254
  179. package/dist/chunk-VVZX7DQ6.cjs.map +0 -1
  180. package/dist/chunk-WNFGDB7B.js +0 -254
  181. package/dist/chunk-WNFGDB7B.js.map +0 -1
  182. package/dist/sync.cjs +0 -12
  183. package/dist/sync.cjs.map +0 -1
  184. package/dist/sync.d.cts +0 -307
  185. package/dist/sync.d.ts +0 -307
  186. package/dist/sync.js +0 -12
  187. /package/dist/{chunk-TEM2I2NN.js.map → message.js.map} +0 -0
  188. /package/dist/{sync.js.map → module.js.map} +0 -0
@@ -1,1051 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
- var _chunk3INDOVUCcjs = require('./chunk-3INDOVUC.cjs');
5
-
6
-
7
- var _chunkSM5YPDDIcjs = require('./chunk-SM5YPDDI.cjs');
8
-
9
-
10
-
11
-
12
-
13
-
14
- var _chunk7ZTZZ5PNcjs = require('./chunk-7ZTZZ5PN.cjs');
15
-
16
- // src/sync.ts
17
- var MAX_CONSECUTIVE_DRIFT_JOINS = 3;
18
- var MIRROR_RATE_TOLERANCE = 0.02;
19
- var MASTER_RECONCILE_INTERVAL_MS = 250;
20
- var _master, _followers, _now, _leadIn, _driftTolerance, _driftIntervalMs, _ticker, _tickOptions, _ticksPerDriftCheck, _ticksPerMasterReconcile, _tickCount, _loop, _wrapping, _generation, _revision, _lastCommandRevision, _pendingCommands, _observers, _lastSnapshot, _pendingTransitions, _commandActive, _queuedCommands, _intent, _disposed, _onOperationError, _TransportGroup_instances, dispatch_fn, publish_fn, setLoop_fn, play_fn, pause_fn, stop_fn, seek_fn, setRate_fn, wrapLocal_fn, localPosition_fn, joinFollowers_fn, applyFollowerRate_fn, resetDriftConvergence_fn, onTick_fn, reconcileMasterStop_fn, handleMasterStopped_fn, checkLoop_fn, wrap_fn, startDriftMonitor_fn, stopDriftMonitor_fn, isCurrent_fn, reportOperationError_fn, settleMasterStopped_fn, settleFailedResume_fn, assertActive_fn, observeReconciliation_fn, queueJoin_fn, enqueueCommand_fn, finishCommand_fn, readSettledMasterPosition_fn, reconcileStaleSeek_fn, reapplySynchronousIntent_fn, applyPause_fn, applyStop_fn, rollbackFailedPlay_fn;
21
- var TransportGroup = class {
22
- constructor(master, now, options = {}) {
23
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _TransportGroup_instances);
24
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _master);
25
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _followers, []);
26
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _now);
27
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _leadIn);
28
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _driftTolerance);
29
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _driftIntervalMs);
30
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ticker, null);
31
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _tickOptions);
32
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ticksPerDriftCheck);
33
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ticksPerMasterReconcile);
34
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _tickCount, 0);
35
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _loop, null);
36
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _wrapping, false);
37
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _generation, 0);
38
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _revision, 0);
39
- /** Last submitted command, excluding background reconciliation revisions. */
40
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lastCommandRevision, 0);
41
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _pendingCommands, /* @__PURE__ */ new Set());
42
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _observers, /* @__PURE__ */ new Set());
43
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lastSnapshot);
44
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _pendingTransitions, 0);
45
- /** Serializes transport commands so late async settlements cannot reorder state. */
46
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _commandActive, false);
47
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _queuedCommands, []);
48
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _intent, "paused");
49
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed, false);
50
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _onOperationError);
51
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _master, master);
52
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _now, now);
53
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _leadIn, _nullishCoalesce(options.leadInSeconds, () => ( 0.06)));
54
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _driftTolerance, _nullishCoalesce(options.driftToleranceSeconds, () => ( 0.03)));
55
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _driftIntervalMs, _nullishCoalesce(options.driftCheckIntervalMs, () => ( 250)));
56
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _onOperationError, options.onOperationError);
57
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tickOptions, { intervalMs: 25, ...options.tick });
58
- assertFiniteNonNegative("leadInSeconds", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn));
59
- assertFiniteNonNegative("driftToleranceSeconds", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftTolerance));
60
- assertFiniteNonNegative("driftCheckIntervalMs", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs));
61
- const tickInterval = _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickOptions).intervalMs, () => ( 25));
62
- if (!Number.isSafeInteger(tickInterval) || tickInterval < 1 || tickInterval > _chunk3INDOVUCcjs.MAX_TIMER_DELAY_MS) {
63
- throw new RangeError(
64
- `tick.intervalMs must be a positive safe integer no greater than ${_chunk3INDOVUCcjs.MAX_TIMER_DELAY_MS}.`
65
- );
66
- }
67
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticksPerDriftCheck, Math.max(1, Math.round(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs) / tickInterval)));
68
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticksPerMasterReconcile, Math.max(1, Math.ceil(MASTER_RECONCILE_INTERVAL_MS / tickInterval)));
69
- if (options.loop) {
70
- assertValidLoop(options.loop);
71
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _loop, { ...options.loop });
72
- }
73
- }
74
- /** The group timeline: a read-through to the master's own clock. */
75
- get clock() {
76
- return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).clock;
77
- }
78
- /** Current position on the master axis. */
79
- get position() {
80
- return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).position;
81
- }
82
- /** Read one coherent state on the master's stable position axis. */
83
- get snapshot() {
84
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot)) {
85
- return Object.freeze({ ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot), revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision), pending: false, disposed: true });
86
- }
87
- const referenceTime = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this);
88
- const clock = this.clock;
89
- const loop = this.loop;
90
- const snapshot = Object.freeze({
91
- revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision),
92
- referenceTime,
93
- position: clock.positionAt(referenceTime),
94
- rate: clock.rate,
95
- paused: clock.paused,
96
- holding: clock.holding && clock.state.originTime > referenceTime,
97
- loop: loop ? Object.freeze(loop) : null,
98
- pending: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).size > 0 || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0,
99
- disposed: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)
100
- });
101
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSnapshot, snapshot);
102
- return snapshot;
103
- }
104
- /** Register before synchronously delivering the initial snapshot. Observer
105
- * failures are contained. Unsubscribe never stops borrowed playback. */
106
- subscribe(listener) {
107
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
108
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).add(listener);
109
- try {
110
- listener({ type: "snapshot", snapshot: this.snapshot });
111
- } catch (e) {
112
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).delete(listener);
113
- }
114
- return () => {
115
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).delete(listener);
116
- };
117
- }
118
- /** Submit a command and await its actual participant settlement. Failures
119
- * reject and emit an error; superseded work cannot claim a committed result.
120
- * Pause/stop take effect synchronously and await any late-start reconciliation.
121
- * Call this authority exclusively while coordinating a session. */
122
- dispatch(command) {
123
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, command, true);
124
- }
125
- /**
126
- * Register a follower. While the group is playing, the follower joins the
127
- * running timeline on the next scheduled join.
128
- */
129
- addFollower(transport, options = {}) {
130
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
131
- const offset = _nullishCoalesce(options.offsetSeconds, () => ( 0));
132
- assertFiniteNonNegative("offsetSeconds", offset);
133
- const scale = _nullishCoalesce(options.positionScale, () => ( 1));
134
- if (!Number.isFinite(scale) || scale <= 0) throw new RangeError("positionScale must be finite and > 0.");
135
- if (scale !== 1 && !transport.setRate) throw new Error("A scaled follower must support setRate.");
136
- if (options.loop) assertValidLoop(options.loop);
137
- const record = {
138
- transport,
139
- offset,
140
- scale,
141
- loop: options.loop ? { ...options.loop } : null,
142
- joinAt: 0,
143
- consecutiveDriftJoins: 0,
144
- driftJoinsSuppressed: false
145
- };
146
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).push(record);
147
- if (!this.clock.paused) {
148
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, observeReconciliation_fn).call(this, "follower join", () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, queueJoin_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation), "follower join", [record]));
149
- }
150
- }
151
- /**
152
- * Remove a follower from the group (the transport itself is left as-is,
153
- * still playing if it was; the caller owns its lifecycle from here).
154
- * Returns false when the transport was not a member.
155
- */
156
- removeFollower(transport) {
157
- const index = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).findIndex((record) => record.transport === transport);
158
- if (index < 0) return false;
159
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).splice(index, 1);
160
- return true;
161
- }
162
- /** Number of registered followers. */
163
- get followerCount() {
164
- return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).length;
165
- }
166
- /**
167
- * Set (or clear) a loop region on the master axis, live. The wrap runs
168
- * through {@link seek}, so it inherits the shared re-entry origin; the
169
- * boundary is detected by a worker-backed tick watcher, so the wrap
170
- * instant may trail the boundary by the watcher/preparation delay and lead-in.
171
- * Browser throttling means this is not a bounded timing guarantee.
172
- */
173
- setLoop(loop) {
174
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
175
- if (loop) assertValidLoop(loop);
176
- void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "loop", loop }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "loop", error));
177
- }
178
- get loop() {
179
- return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) ? { ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) } : null;
180
- }
181
- /**
182
- * Start master and followers on one shared origin. The group proposes
183
- * `now + leadInSeconds` to the master; one that supports scheduled starts
184
- * arms there and every follower joins at that very instant. A master that
185
- * ignores the proposal starts immediately and followers join a lead-in
186
- * later, offset-matched to its anchor.
187
- */
188
- async play() {
189
- await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "play" }, false);
190
- }
191
- pause() {
192
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
193
- void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "pause" }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "pause", error));
194
- }
195
- stop() {
196
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
197
- void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "stop" }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "stop", error));
198
- }
199
- /**
200
- * Seek master and followers to a master-axis position. While playing, the
201
- * group proposes a shared re-entry origin exactly as {@link play} does
202
- * and re-joins the followers there, so all sides come back in together.
203
- * Loop wraps run through this path and inherit the same shared origin.
204
- */
205
- async seek(position) {
206
- await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "seek", position }, false);
207
- }
208
- /**
209
- * Set the playback rate on the master and every follower. Followers
210
- * re-join immediately on the shared clock. NOTE: the group does not clamp
211
- * the rate beyond finite-and-positive — a domain wrapper owns any shared
212
- * range its transports require.
213
- */
214
- setRate(rate) {
215
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
216
- validateCommand({ type: "rate", rate });
217
- void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "rate", rate }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "rate", error));
218
- }
219
- dispose() {
220
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
221
- try {
222
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSnapshot, this.snapshot);
223
- } catch (e2) {
224
- }
225
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed, true);
226
- ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._;
227
- ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
228
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "disposed");
229
- const ticker = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker);
230
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticker, null);
231
- const errors = [];
232
- const releases = [() => _optionalChain([ticker, 'optionalAccess', _2 => _2.dispose, 'call', _3 => _3()])];
233
- for (const record of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)) {
234
- releases.push(() => _optionalChain([record, 'access', _4 => _4.transport, 'access', _5 => _5.dispose, 'optionalCall', _6 => _6()]));
235
- }
236
- releases.push(() => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _7 => _7.dispose, 'optionalCall', _8 => _8()]));
237
- for (const release of releases) {
238
- try {
239
- release();
240
- } catch (error) {
241
- errors.push(error);
242
- }
243
- }
244
- let snapshot;
245
- try {
246
- snapshot = this.snapshot;
247
- } catch (e3) {
248
- }
249
- if (snapshot) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "snapshot", snapshot });
250
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).clear();
251
- if (errors.length > 0) throw errors[0];
252
- }
253
- /**
254
- * One drift check: every follower is measured against the master clock,
255
- * and each one out of tolerance is re-joined on the shared clock (the
256
- * same scheduled-start dance as {@link play}). Returns the largest
257
- * absolute drift observed (0 with no followers or while holding off).
258
- */
259
- checkDrift() {
260
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
261
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0) return 0;
262
- const now = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this);
263
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).reconcile) {
264
- const verdict = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).reconcile(now);
265
- if (verdict === "stalled" && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") {
266
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, handleMasterStopped_fn).call(this);
267
- return 0;
268
- }
269
- }
270
- let worst = 0;
271
- const stragglers = [];
272
- for (const record of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)) {
273
- if (now < record.joinAt) continue;
274
- const expected = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, this.clock.positionAt(now));
275
- const followerClock = record.transport.clock;
276
- if (_optionalChain([followerClock, 'optionalAccess', _9 => _9.holding]) && now < followerClock.state.originTime) continue;
277
- const followerPosition = followerClock ? followerClock.positionAt(now) : record.transport.position;
278
- const followerRunning = followerClock ? !followerClock.paused : record.transport.running !== false;
279
- let localDrift = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrapLocal_fn).call(this, record, followerPosition) - expected;
280
- if (record.loop && followerPosition >= record.loop.startSeconds && expected >= record.loop.startSeconds) {
281
- const period = record.loop.endSeconds - record.loop.startSeconds;
282
- localDrift = ((localDrift + period / 2) % period + period) % period - period / 2;
283
- }
284
- const drift = localDrift / record.scale;
285
- if (Math.abs(drift) > Math.abs(worst)) worst = drift;
286
- if (!followerRunning) continue;
287
- const rateMismatch = followerClock !== void 0 && followerClock.rate !== this.clock.rate * record.scale;
288
- if (Math.abs(drift) <= _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftTolerance) && !rateMismatch) {
289
- record.consecutiveDriftJoins = 0;
290
- record.driftJoinsSuppressed = false;
291
- continue;
292
- }
293
- if (record.driftJoinsSuppressed) continue;
294
- record.consecutiveDriftJoins += 1;
295
- if (record.consecutiveDriftJoins > MAX_CONSECUTIVE_DRIFT_JOINS) {
296
- record.driftJoinsSuppressed = true;
297
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "drift re-join", new Error(
298
- `TransportGroup: ${record.consecutiveDriftJoins} consecutive drift corrections failed to converge (drift ${drift.toFixed(4)}s, master rate ${this.clock.rate}). The follower cannot follow the master rate; automatic re-joins are paused until they agree again.`
299
- ));
300
- continue;
301
- }
302
- stragglers.push(record);
303
- }
304
- if (stragglers.length > 0) {
305
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, observeReconciliation_fn).call(this, "drift re-join", () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, queueJoin_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation), "drift re-join", stragglers));
306
- }
307
- return worst;
308
- }
309
- };
310
- _master = new WeakMap();
311
- _followers = new WeakMap();
312
- _now = new WeakMap();
313
- _leadIn = new WeakMap();
314
- _driftTolerance = new WeakMap();
315
- _driftIntervalMs = new WeakMap();
316
- _ticker = new WeakMap();
317
- _tickOptions = new WeakMap();
318
- _ticksPerDriftCheck = new WeakMap();
319
- _ticksPerMasterReconcile = new WeakMap();
320
- _tickCount = new WeakMap();
321
- _loop = new WeakMap();
322
- _wrapping = new WeakMap();
323
- _generation = new WeakMap();
324
- _revision = new WeakMap();
325
- _lastCommandRevision = new WeakMap();
326
- _pendingCommands = new WeakMap();
327
- _observers = new WeakMap();
328
- _lastSnapshot = new WeakMap();
329
- _pendingTransitions = new WeakMap();
330
- _commandActive = new WeakMap();
331
- _queuedCommands = new WeakMap();
332
- _intent = new WeakMap();
333
- _disposed = new WeakMap();
334
- _onOperationError = new WeakMap();
335
- _TransportGroup_instances = new WeakSet();
336
- dispatch_fn = function(input, strict) {
337
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
338
- validateCommand(input);
339
- const command = Object.freeze(input.type === "loop" ? { ...input, loop: input.loop ? Object.freeze({ ...input.loop }) : null } : { ...input });
340
- const revision = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._;
341
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastCommandRevision, revision);
342
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).add(revision);
343
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "invalidate", revision, command, snapshot: this.snapshot });
344
- let operation = void 0;
345
- try {
346
- if (revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) {
347
- switch (command.type) {
348
- case "play":
349
- operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, play_fn).call(this, strict);
350
- break;
351
- case "pause":
352
- operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, pause_fn).call(this);
353
- break;
354
- case "stop":
355
- operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stop_fn).call(this);
356
- break;
357
- case "seek":
358
- operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, seek_fn).call(this, command.position, strict);
359
- break;
360
- case "rate":
361
- operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setRate_fn).call(this, command.rate, strict, revision);
362
- break;
363
- case "loop":
364
- operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setLoop_fn).call(this, command.loop);
365
- break;
366
- }
367
- }
368
- } catch (error) {
369
- operation = Promise.reject(error);
370
- }
371
- return Promise.resolve(operation).then(() => {
372
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).delete(revision);
373
- const snapshot = this.snapshot;
374
- const commit = Object.freeze({
375
- revision,
376
- command,
377
- status: revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) ? "committed" : "superseded",
378
- snapshot
379
- });
380
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "commit", commit, snapshot });
381
- return commit;
382
- }, (error) => {
383
- if (strict && revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
384
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).delete(revision);
385
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "error", revision, command, error, snapshot: this.snapshot });
386
- throw error;
387
- });
388
- };
389
- publish_fn = function(event) {
390
- for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers)]) {
391
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).has(listener)) continue;
392
- try {
393
- listener(event);
394
- } catch (e4) {
395
- }
396
- if (event.snapshot.revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) break;
397
- }
398
- };
399
- setLoop_fn = function(loop) {
400
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
401
- if (loop) assertValidLoop(loop);
402
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _loop, loop ? { ...loop } : null);
403
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") {
404
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, startDriftMonitor_fn).call(this);
405
- } else {
406
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
407
- }
408
- };
409
- play_fn = async function(strict) {
410
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
411
- const generation = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
412
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
413
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "playing");
414
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
415
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
416
- try {
417
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
418
- await _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).play(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this) + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn));
419
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
420
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
421
- return;
422
- }
423
- if (strict && this.clock.paused) throw new Error("Master transport did not start.");
424
- await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict);
425
- if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, startDriftMonitor_fn).call(this);
426
- } catch (error) {
427
- if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
428
- throw error;
429
- } finally {
430
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
431
- }
432
- });
433
- };
434
- pause_fn = function() {
435
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
436
- const hadPendingTransition = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0;
437
- ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
438
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "paused");
439
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
440
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
441
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
442
- if (hadPendingTransition) {
443
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => {
444
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
445
- });
446
- }
447
- };
448
- stop_fn = function() {
449
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
450
- const hadPendingTransition = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0;
451
- ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
452
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "stopped");
453
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
454
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
455
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyStop_fn).call(this);
456
- if (hadPendingTransition) {
457
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => {
458
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyStop_fn).call(this);
459
- });
460
- }
461
- };
462
- seek_fn = async function(position, strict) {
463
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
464
- assertFiniteNonNegative("position", position);
465
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
466
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
467
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
468
- try {
469
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
470
- const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
471
- const wasRunning = !this.clock.paused;
472
- await _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).seekPosition(
473
- position,
474
- wasRunning ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this) + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn) : void 0
475
- );
476
- const settled = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, readSettledMasterPosition_fn).call(this);
477
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
478
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reconcileStaleSeek_fn).call(this, settled);
479
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
480
- return;
481
- }
482
- if (this.clock.paused) {
483
- if (wasRunning && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") {
484
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleFailedResume_fn).call(this);
485
- if (strict) throw new Error("Master transport stayed paused after seek.");
486
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reconcileStaleSeek_fn).call(this, settled);
487
- return;
488
- }
489
- for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
490
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
491
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
492
- record.transport.pause();
493
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
494
- record.transport.seek(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, settled));
495
- }
496
- } else {
497
- await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict);
498
- }
499
- } finally {
500
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
501
- }
502
- });
503
- };
504
- setRate_fn = function(rate, strict, revision, queued = false) {
505
- if (strict && !queued) {
506
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
507
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
508
- try {
509
- if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
510
- await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setRate_fn).call(this, rate, strict, revision, true);
511
- } finally {
512
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
513
- }
514
- });
515
- }
516
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
517
- if (!Number.isFinite(rate) || rate <= 0) {
518
- throw new RangeError(`rate must be finite and > 0, got ${rate}.`);
519
- }
520
- const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
521
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
522
- try {
523
- _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _10 => _10.setRate, 'optionalCall', _11 => _11(rate)]);
524
- } catch (error) {
525
- if (strict) throw error;
526
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "master rate match", error);
527
- }
528
- if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
529
- if (strict && this.clock.rate !== rate) throw new Error("Master transport did not accept the requested rate.");
530
- for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
531
- if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
532
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
533
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyFollowerRate_fn).call(this, record, rate, strict);
534
- }
535
- if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
536
- if (!this.clock.paused) {
537
- return queued ? _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict) : _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, queueJoin_fn).call(this, generation, "rate re-join", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict);
538
- }
539
- };
540
- wrapLocal_fn = function(record, position) {
541
- const loop = record.loop;
542
- if (!loop || position < loop.endSeconds) return position;
543
- return loop.startSeconds + (position - loop.startSeconds) % (loop.endSeconds - loop.startSeconds);
544
- };
545
- localPosition_fn = function(record, masterPosition) {
546
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrapLocal_fn).call(this, record, record.offset + masterPosition * record.scale);
547
- };
548
- joinFollowers_fn = async function(generation, targets, strict = false) {
549
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
550
- const members = [...targets];
551
- for (const record of members) {
552
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
553
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) record.transport.pause();
554
- }
555
- const clock = this.clock;
556
- if (clock.paused) return;
557
- const now = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this);
558
- const armedOrigin = clock.holding ? clock.state.originTime : -Infinity;
559
- const when = armedOrigin > now ? armedOrigin : now + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn);
560
- const position = clock.positionAt(when);
561
- const starts = [];
562
- for (const record of members) {
563
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
564
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
565
- try {
566
- record.joinAt = when;
567
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyFollowerRate_fn).call(this, record, clock.rate, strict);
568
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
569
- record.transport.seek(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, position));
570
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
571
- starts.push(record.transport.play(when));
572
- } catch (error) {
573
- starts.push(Promise.reject(error));
574
- break;
575
- }
576
- }
577
- const settled = await Promise.allSettled(starts);
578
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
579
- const failure = settled.find((result) => result.status === "rejected");
580
- if (_optionalChain([failure, 'optionalAccess', _12 => _12.status]) === "rejected") throw failure.reason;
581
- if (strict && _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
582
- for (const record of members) {
583
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
584
- const followerClock = record.transport.clock;
585
- const running = followerClock ? !followerClock.paused : record.transport.running;
586
- if (running === false) throw new Error("Follower transport did not start.");
587
- }
588
- }
589
- };
590
- /**
591
- * Hand a follower a rate, skipping the call when it already runs at it.
592
- * A follower with a clock is asked directly; for one without, the last
593
- * applied value is remembered. Best-effort by contract: `setRate` is
594
- * optional on {@link SyncFollowerTransport}, and a transport that has one
595
- * may still clamp or refuse it — the convergence check below is what
596
- * surfaces a mismatch neither side can resolve.
597
- */
598
- applyFollowerRate_fn = function(record, rate, strict = false) {
599
- rate *= record.scale;
600
- if (!record.transport.setRate) {
601
- if (strict && (_nullishCoalesce(_optionalChain([record, 'access', _13 => _13.transport, 'access', _14 => _14.clock, 'optionalAccess', _15 => _15.rate]), () => ( 1))) !== rate) {
602
- throw new Error("Follower transport cannot accept the requested rate.");
603
- }
604
- return;
605
- }
606
- if (!Number.isFinite(rate) || rate <= 0) return;
607
- const current = _nullishCoalesce(_optionalChain([record, 'access', _16 => _16.transport, 'access', _17 => _17.clock, 'optionalAccess', _18 => _18.rate]), () => ( record.lastRate));
608
- if (current === rate) return;
609
- try {
610
- record.transport.setRate(rate);
611
- if (strict && record.transport.clock && record.transport.clock.rate !== rate) {
612
- throw new Error("Follower transport did not accept the requested rate.");
613
- }
614
- record.lastRate = rate;
615
- } catch (error) {
616
- if (strict) throw error;
617
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "follower rate match", error);
618
- }
619
- };
620
- /** Re-arm drift corrections; any explicit command counts as a fresh start. */
621
- resetDriftConvergence_fn = function() {
622
- for (const record of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)) {
623
- record.consecutiveDriftJoins = 0;
624
- record.driftJoinsSuppressed = false;
625
- }
626
- };
627
- /**
628
- * One watcher drives every concern off a kernel tick source (worker-backed
629
- * where the platform allows, so background-tab throttling does not starve
630
- * it): clocked master-stop reconciliation and the loop boundary every
631
- * tick, drift every `driftCheckIntervalMs` worth of ticks. A clockless
632
- * adapter is sampled at the default drift cadence when drift is disabled.
633
- */
634
- onTick_fn = function() {
635
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
636
- const revision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision);
637
- try {
638
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs) === 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickCount) % _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticksPerMasterReconcile) === 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing" && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) === 0) {
639
- _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _19 => _19.reconcile, 'optionalCall', _20 => _20(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this))]);
640
- }
641
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reconcileMasterStop_fn).call(this);
642
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, checkLoop_fn).call(this);
643
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tickCount, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickCount) + 1);
644
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs) > 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickCount) % _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticksPerDriftCheck) === 0) {
645
- this.checkDrift();
646
- }
647
- } catch (error) {
648
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
649
- if (revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
650
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "transport monitor", error);
651
- }
652
- };
653
- /**
654
- * The master can stop on its own (a score player finishing at its natural
655
- * end pauses and rewinds its clock, racing the group's boundary watcher
656
- * tick-for-tick). A self-stopped clock while the group means to play
657
- * either wraps (loop active — the loop's continuation intent outranks the
658
- * master's own finish) or settles into the paused state.
659
- */
660
- reconcileMasterStop_fn = function() {
661
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) !== "playing" || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0) return;
662
- if (!this.clock.paused) return;
663
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, handleMasterStopped_fn).call(this);
664
- };
665
- handleMasterStopped_fn = function() {
666
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping)) {
667
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrap_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).startSeconds);
668
- } else {
669
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
670
- }
671
- };
672
- checkLoop_fn = function() {
673
- const loop = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop);
674
- if (!loop || this.clock.paused || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0) return;
675
- if (this.clock.positionAt(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this)) >= loop.endSeconds) {
676
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrap_fn).call(this, loop.startSeconds);
677
- }
678
- };
679
- /**
680
- * Wrap to the loop start. A running master re-joins inside seek(); a
681
- * master that stopped on its own (natural finish at or past the loop end)
682
- * is restarted afterwards. A failed wrap settles into the paused state
683
- * instead of retrying every tick, and is reported as 'loop wrap'.
684
- */
685
- wrap_fn = function(startSeconds) {
686
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _wrapping, true);
687
- const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
688
- const wrapCommandRevision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) + 1;
689
- const stillCurrent = () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastCommandRevision) === wrapCommandRevision;
690
- void this.seek(startSeconds).then(() => {
691
- if (stillCurrent() && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing" && this.clock.paused) {
692
- return this.play();
693
- }
694
- }).catch((error) => {
695
- if (!stillCurrent()) return;
696
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "loop wrap", error);
697
- if (stillCurrent() && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
698
- }).finally(() => {
699
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _wrapping, false);
700
- });
701
- };
702
- startDriftMonitor_fn = function() {
703
- _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker), () => ( _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticker, _chunk3INDOVUCcjs.createTickSource.call(void 0, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickOptions)))));
704
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker).start(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, onTick_fn).call(this));
705
- };
706
- stopDriftMonitor_fn = function() {
707
- _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker), 'optionalAccess', _21 => _21.stop, 'call', _22 => _22()]);
708
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tickCount, 0);
709
- };
710
- isCurrent_fn = function(generation) {
711
- return !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) && generation === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
712
- };
713
- reportOperationError_fn = function(operation, error) {
714
- var _a;
715
- let snapshot;
716
- try {
717
- snapshot = this.snapshot;
718
- } catch (e5) {
719
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot)) {
720
- snapshot = Object.freeze({
721
- ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot),
722
- revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision),
723
- paused: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) !== "playing",
724
- holding: false,
725
- pending: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).size > 0 || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0,
726
- disposed: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)
727
- });
728
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSnapshot, snapshot);
729
- }
730
- }
731
- if (snapshot) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "operation-error", operation, error, snapshot });
732
- try {
733
- (_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onOperationError)) == null ? void 0 : _a.call(this, operation, error);
734
- } catch (e6) {
735
- }
736
- };
737
- /**
738
- * The master stopped although the group meant to be playing (a swallowed
739
- * restart failure, or the master ending on its own): pause the followers
740
- * and settle, exactly as an explicit pause() would.
741
- */
742
- settleMasterStopped_fn = function() {
743
- this.pause();
744
- };
745
- settleFailedResume_fn = function() {
746
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
747
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "resume after seek", new Error("TransportGroup: the master transport stayed paused after a mid-playback seek."));
748
- };
749
- assertActive_fn = function() {
750
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) throw new Error("TransportGroup has been disposed.");
751
- };
752
- observeReconciliation_fn = function(operation, apply) {
753
- const revision = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._;
754
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).add(revision);
755
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "reconcile", operation, phase: "invalidate", snapshot: this.snapshot });
756
- const pending = revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) ? apply() : Promise.resolve();
757
- void pending.catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, operation, error)).finally(() => {
758
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).delete(revision);
759
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "reconcile", operation, phase: "settled", snapshot: this.snapshot });
760
- });
761
- };
762
- /**
763
- * Queue an independent re-join as a visible transition. Public pause/stop
764
- * calls can then schedule one final reconciliation behind it, preventing
765
- * a late follower play() settlement from reviving playback.
766
- */
767
- queueJoin_fn = function(generation, operation, targets, strict = false) {
768
- const revision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision);
769
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
770
- return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
771
- try {
772
- await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, targets, strict);
773
- } finally {
774
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
775
- }
776
- }).catch((error) => {
777
- if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) && revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
778
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, operation, error);
779
- if (strict) throw error;
780
- });
781
- };
782
- /**
783
- * Run the first idle command immediately so master.play() remains inside
784
- * the browser's transient user-activation stack. Only commands that
785
- * actually have an async predecessor wait in the FIFO.
786
- */
787
- enqueueCommand_fn = function(operation) {
788
- return new Promise((resolve, reject) => {
789
- const run = () => {
790
- let result;
791
- try {
792
- result = operation();
793
- } catch (error) {
794
- reject(error);
795
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, finishCommand_fn).call(this);
796
- return;
797
- }
798
- Promise.resolve(result).then(
799
- (value) => {
800
- resolve(value);
801
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, finishCommand_fn).call(this);
802
- },
803
- (error) => {
804
- reject(error);
805
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, finishCommand_fn).call(this);
806
- }
807
- );
808
- };
809
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _commandActive)) {
810
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _queuedCommands).push(run);
811
- } else {
812
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _commandActive, true);
813
- run();
814
- }
815
- });
816
- };
817
- finishCommand_fn = function() {
818
- const next = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _queuedCommands).shift();
819
- if (next) {
820
- next();
821
- } else {
822
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _commandActive, false);
823
- }
824
- };
825
- /** Read the master's actual post-seek position (it may clamp). */
826
- readSettledMasterPosition_fn = function() {
827
- const position = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).position;
828
- if (!Number.isFinite(position) || position < 0) {
829
- throw new RangeError("Master transport returned an invalid position after seek.");
830
- }
831
- return position;
832
- };
833
- /** Preserve the completed seek position when pause superseded it. */
834
- reconcileStaleSeek_fn = function(position) {
835
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) !== "paused") return;
836
- const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
837
- for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
838
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
839
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
840
- record.transport.seek(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, position));
841
- }
842
- };
843
- /** Re-apply pause/stop after an older async master command settles late. */
844
- reapplySynchronousIntent_fn = function() {
845
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
846
- if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "paused") {
847
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
848
- } else if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "stopped") {
849
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyStop_fn).call(this);
850
- }
851
- };
852
- applyPause_fn = function() {
853
- const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
854
- const errors = [];
855
- for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
856
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
857
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
858
- try {
859
- record.transport.pause();
860
- } catch (error) {
861
- errors.push(error);
862
- }
863
- }
864
- if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
865
- try {
866
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).pause();
867
- } catch (error) {
868
- errors.push(error);
869
- }
870
- }
871
- if (errors.length > 0) throw errors[0];
872
- };
873
- applyStop_fn = function() {
874
- const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
875
- const errors = [];
876
- for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
877
- if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
878
- if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
879
- try {
880
- record.transport.stop();
881
- } catch (error) {
882
- errors.push(error);
883
- }
884
- }
885
- if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
886
- try {
887
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).stop();
888
- } catch (error) {
889
- errors.push(error);
890
- }
891
- }
892
- if (errors.length > 0) throw errors[0];
893
- };
894
- rollbackFailedPlay_fn = function() {
895
- ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
896
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "paused");
897
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
898
- try {
899
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
900
- } catch (e7) {
901
- }
902
- };
903
- var _inner, _mirror, _now2, _tolerance, _lastSample, _lastChange, _reportedStep, _positiveSteps, _MirrorClockMaster_instances, resetSamples_fn;
904
- var MirrorClockMaster = class {
905
- constructor(inner, now, options = {}) {
906
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _MirrorClockMaster_instances);
907
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _inner);
908
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _mirror);
909
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _now2);
910
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _tolerance);
911
- /** Last sample for estimating the transport's slope. */
912
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lastSample, null);
913
- /** Last position change, retained across identical quantized samples. */
914
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lastChange, null);
915
- /** Largest observed positive step since the last command. */
916
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _reportedStep, 0);
917
- _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _positiveSteps, 0);
918
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _inner, inner);
919
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _now2, now);
920
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tolerance, _nullishCoalesce(options.reconcileToleranceSeconds, () => ( 0.03)));
921
- assertFiniteNonNegative("reconcileToleranceSeconds", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tolerance));
922
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _mirror, new (0, _chunkSM5YPDDIcjs.TransportClock)(now));
923
- }
924
- get clock() {
925
- return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror);
926
- }
927
- get position() {
928
- return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).position;
929
- }
930
- async play(when) {
931
- await _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).play(when);
932
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
933
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).start(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this), _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).position);
934
- }
935
- pause() {
936
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).pause();
937
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
938
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).pause(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this));
939
- }
940
- stop() {
941
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).stop();
942
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
943
- const now = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this);
944
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).pause(now);
945
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).seekTo(0, now);
946
- }
947
- async seekPosition(position, when) {
948
- await _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).seekPosition(position, when);
949
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
950
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).seekTo(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).position, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this));
951
- }
952
- setRate(rate) {
953
- _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner), 'access', _23 => _23.setRate, 'optionalCall', _24 => _24(rate)]);
954
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
955
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).setRate(rate, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this));
956
- }
957
- reconcile(now) {
958
- const actual = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner).position;
959
- if (!Number.isFinite(actual) || actual < 0) {
960
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
961
- return "ok";
962
- }
963
- const mirrorPosition = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).positionAt(now);
964
- const sample = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSample);
965
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSample, { position: actual, time: now });
966
- const changed = sample !== null && actual !== sample.position;
967
- const previousChange = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastChange);
968
- if (sample === null || changed) {
969
- if (changed && actual > sample.position) {
970
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _reportedStep, Math.max(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _reportedStep), actual - sample.position));
971
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _positiveSteps, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _positiveSteps) + 1);
972
- }
973
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastChange, { position: actual, time: now });
974
- }
975
- if (!changed && sample !== null && previousChange !== null && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _reportedStep) > 0 && (now - previousChange.time) * _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).rate > _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _reportedStep) + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tolerance) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).paused) {
976
- _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _MirrorClockMaster_instances, resetSamples_fn).call(this);
977
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).pause(now);
978
- return "stalled";
979
- }
980
- if (changed && previousChange !== null && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).paused) {
981
- const elapsed = now - previousChange.time;
982
- const advanced = actual - previousChange.position;
983
- if (elapsed > 0 && advanced > 0) {
984
- const measured = advanced / elapsed;
985
- const current = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).rate;
986
- if (Number.isFinite(measured) && measured > 0 && Math.abs(measured - current) > MIRROR_RATE_TOLERANCE * current && // The first boundary jump of a rounded position can look much
987
- // faster than the true rate. Wait for another step in that case.
988
- (measured < current || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _positiveSteps) >= 2 || advanced <= elapsed * current + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tolerance))) {
989
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).setRate(measured, now);
990
- }
991
- }
992
- }
993
- if (Math.abs(mirrorPosition - actual) > _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tolerance)) {
994
- _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _mirror).seekTo(actual, now);
995
- }
996
- return "ok";
997
- }
998
- dispose() {
999
- _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _inner), 'access', _25 => _25.dispose, 'optionalCall', _26 => _26()]);
1000
- }
1001
- };
1002
- _inner = new WeakMap();
1003
- _mirror = new WeakMap();
1004
- _now2 = new WeakMap();
1005
- _tolerance = new WeakMap();
1006
- _lastSample = new WeakMap();
1007
- _lastChange = new WeakMap();
1008
- _reportedStep = new WeakMap();
1009
- _positiveSteps = new WeakMap();
1010
- _MirrorClockMaster_instances = new WeakSet();
1011
- resetSamples_fn = function() {
1012
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSample, null);
1013
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastChange, null);
1014
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _reportedStep, 0);
1015
- _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _positiveSteps, 0);
1016
- };
1017
- function assertFiniteNonNegative(name, value) {
1018
- if (!Number.isFinite(value) || value < 0) {
1019
- throw new RangeError(`${name} must be finite and >= 0.`);
1020
- }
1021
- }
1022
- function assertValidLoop(loop) {
1023
- if (!Number.isFinite(loop.startSeconds) || loop.startSeconds < 0 || !Number.isFinite(loop.endSeconds) || !(loop.endSeconds > loop.startSeconds)) {
1024
- throw new RangeError("Loop bounds must be finite, non-negative, and endSeconds must be greater than startSeconds.");
1025
- }
1026
- }
1027
- function validateCommand(command) {
1028
- switch (command.type) {
1029
- case "play":
1030
- case "pause":
1031
- case "stop":
1032
- return;
1033
- case "seek":
1034
- assertFiniteNonNegative("position", command.position);
1035
- return;
1036
- case "rate":
1037
- if (!Number.isFinite(command.rate) || command.rate <= 0) throw new RangeError("rate must be finite and > 0.");
1038
- return;
1039
- case "loop":
1040
- if (command.loop) assertValidLoop(command.loop);
1041
- return;
1042
- default:
1043
- throw new TypeError("Unknown transport command.");
1044
- }
1045
- }
1046
-
1047
-
1048
-
1049
-
1050
- exports.TransportGroup = TransportGroup; exports.MirrorClockMaster = MirrorClockMaster;
1051
- //# sourceMappingURL=chunk-54JYWB5X.cjs.map