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