@mog-sdk/node 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1322,8 +1322,8 @@ var init_mutation_result_handler = __esm({
1322
1322
  this.coordinatorRegistry = registry2;
1323
1323
  }
1324
1324
  /** Set the CellMetadataCache for sync render loop patching. */
1325
- setCellMetadataCache(cache) {
1326
- this.cellMetadataCache = cache;
1325
+ setCellMetadataCache(cache2) {
1326
+ this.cellMetadataCache = cache2;
1327
1327
  }
1328
1328
  // ===========================================================================
1329
1329
  // Public API
@@ -4788,10 +4788,10 @@ var init_compute_core = __esm({
4788
4788
  // Viewport Lifecycle
4789
4789
  // ===========================================================================
4790
4790
  /** Set the CellMetadataCache for sync render loop patching via MutationResultHandler. */
4791
- setCellMetadataCache(cache) {
4792
- this.cellMetadataCache = cache;
4791
+ setCellMetadataCache(cache2) {
4792
+ this.cellMetadataCache = cache2;
4793
4793
  if (this.mutationHandler) {
4794
- this.mutationHandler.setCellMetadataCache(cache);
4794
+ this.mutationHandler.setCellMetadataCache(cache2);
4795
4795
  }
4796
4796
  }
4797
4797
  /**
@@ -5314,8 +5314,8 @@ var init_compute_bridge_gen = __esm({
5314
5314
  tableClearSlicerSelection(slicer) {
5315
5315
  return this.core.transport.call("table_clear_slicer_selection", { slicer });
5316
5316
  }
5317
- tableSelectAllSlicerValues(slicer, cache) {
5318
- return this.core.transport.call("table_select_all_slicer_values", { slicer, cache });
5317
+ tableSelectAllSlicerValues(slicer, cache2) {
5318
+ return this.core.transport.call("table_select_all_slicer_values", { slicer, cache: cache2 });
5319
5319
  }
5320
5320
  tableSetSlicerSortOrder(slicer, order) {
5321
5321
  return this.core.transport.call("table_set_slicer_sort_order", { slicer, order });
@@ -6220,8 +6220,8 @@ var init_compute_bridge_gen = __esm({
6220
6220
  mapSlicerDisconnectionReason(reason) {
6221
6221
  return this.core.query(this.core.transport.call("compute_map_slicer_disconnection_reason", { docId: this.core.docId, reason }));
6222
6222
  }
6223
- getSlicerItemsFromCache(cache) {
6224
- return this.core.query(this.core.transport.call("compute_get_slicer_items_from_cache", { docId: this.core.docId, cache }));
6223
+ getSlicerItemsFromCache(cache2) {
6224
+ return this.core.query(this.core.transport.call("compute_get_slicer_items_from_cache", { docId: this.core.docId, cache: cache2 }));
6225
6225
  }
6226
6226
  isSlicerColumnConnected(sourceColumnId, tableColumns) {
6227
6227
  return this.core.query(this.core.transport.call("compute_is_slicer_column_connected", { docId: this.core.docId, sourceColumnId, tableColumns }));
@@ -6784,8 +6784,8 @@ var init_compute_bridge = __esm({
6784
6784
  initMutationHandler() {
6785
6785
  this.core.initMutationHandler();
6786
6786
  }
6787
- setCellMetadataCache(cache) {
6788
- this.core.setCellMetadataCache(cache);
6787
+ setCellMetadataCache(cache2) {
6788
+ this.core.setCellMetadataCache(cache2);
6789
6789
  }
6790
6790
  getMutationHandler() {
6791
6791
  return this.core.getMutationHandler();
@@ -8154,12 +8154,12 @@ function scaleLinear() {
8154
8154
  };
8155
8155
  return scale2;
8156
8156
  }
8157
- function generateTicks(start, stop, count = 10) {
8157
+ function generateTicks(start, stop2, count = 10) {
8158
8158
  if (count <= 0) return [];
8159
- if (start === stop) return [start];
8160
- const ascending = start <= stop;
8161
- const lo = ascending ? start : stop;
8162
- const hi = ascending ? stop : start;
8159
+ if (start === stop2) return [start];
8160
+ const ascending = start <= stop2;
8161
+ const lo = ascending ? start : stop2;
8162
+ const hi = ascending ? stop2 : start;
8163
8163
  const step = tickStep(lo, hi, count);
8164
8164
  if (!isFinite(step) || step === 0) return [];
8165
8165
  const tickStart = Math.ceil(lo / step) * step;
@@ -8171,8 +8171,8 @@ function generateTicks(start, stop, count = 10) {
8171
8171
  }
8172
8172
  return ascending ? ticks : ticks.slice().reverse();
8173
8173
  }
8174
- function tickStep(start, stop, count) {
8175
- const step0 = Math.abs(stop - start) / Math.max(0, count);
8174
+ function tickStep(start, stop2, count) {
8175
+ const step0 = Math.abs(stop2 - start) / Math.max(0, count);
8176
8176
  let step1 = Math.pow(10, Math.floor(Math.log10(step0)));
8177
8177
  const error = step0 / step1;
8178
8178
  if (error >= Math.sqrt(50)) {
@@ -8182,24 +8182,24 @@ function tickStep(start, stop, count) {
8182
8182
  } else if (error >= Math.sqrt(2)) {
8183
8183
  step1 *= 2;
8184
8184
  }
8185
- return stop < start ? -step1 : step1;
8185
+ return stop2 < start ? -step1 : step1;
8186
8186
  }
8187
- function niceLinear(start, stop, count = 10) {
8187
+ function niceLinear(start, stop2, count = 10) {
8188
8188
  let prestep = NaN;
8189
- let step = tickStep(start, stop, count);
8189
+ let step = tickStep(start, stop2, count);
8190
8190
  let iterations = 0;
8191
8191
  while (step !== prestep && iterations++ < 10) {
8192
8192
  prestep = step;
8193
8193
  const newStart = Math.floor(start / step) * step;
8194
- const newStop = Math.ceil(stop / step) * step;
8194
+ const newStop = Math.ceil(stop2 / step) * step;
8195
8195
  step = tickStep(newStart, newStop, count);
8196
8196
  }
8197
8197
  if (step > 0) {
8198
- return [Math.floor(start / step) * step, Math.ceil(stop / step) * step];
8198
+ return [Math.floor(start / step) * step, Math.ceil(stop2 / step) * step];
8199
8199
  } else if (step < 0) {
8200
- return [Math.ceil(start * step) / step, Math.floor(stop * step) / step];
8200
+ return [Math.ceil(start * step) / step, Math.floor(stop2 * step) / step];
8201
8201
  }
8202
- return [start, stop];
8202
+ return [start, stop2];
8203
8203
  }
8204
8204
  function createTickFormatter(_start, _stop, _count = 10, specifier) {
8205
8205
  if (specifier) {
@@ -16750,13 +16750,3340 @@ var init_rust_document = __esm({
16750
16750
  }
16751
16751
  });
16752
16752
 
16753
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dev/dist/xstate-dev.esm.js
16754
+ function getGlobal() {
16755
+ if (typeof globalThis !== "undefined") {
16756
+ return globalThis;
16757
+ }
16758
+ if (typeof self !== "undefined") {
16759
+ return self;
16760
+ }
16761
+ if (typeof window !== "undefined") {
16762
+ return window;
16763
+ }
16764
+ if (typeof global !== "undefined") {
16765
+ return global;
16766
+ }
16767
+ }
16768
+ function getDevTools() {
16769
+ const w = getGlobal();
16770
+ if (w.__xstate__) {
16771
+ return w.__xstate__;
16772
+ }
16773
+ return void 0;
16774
+ }
16775
+ var devToolsAdapter;
16776
+ var init_xstate_dev_esm = __esm({
16777
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dev/dist/xstate-dev.esm.js"() {
16778
+ "use strict";
16779
+ init_esm_shims();
16780
+ devToolsAdapter = (service) => {
16781
+ if (typeof window === "undefined") {
16782
+ return;
16783
+ }
16784
+ const devTools = getDevTools();
16785
+ if (devTools) {
16786
+ devTools.register(service);
16787
+ }
16788
+ };
16789
+ }
16790
+ });
16791
+
16792
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/raise-b47daa89.esm.js
16793
+ function createAfterEvent(delayRef, id) {
16794
+ return {
16795
+ type: `xstate.after.${delayRef}.${id}`
16796
+ };
16797
+ }
16798
+ function createDoneStateEvent(id, output) {
16799
+ return {
16800
+ type: `xstate.done.state.${id}`,
16801
+ output
16802
+ };
16803
+ }
16804
+ function createDoneActorEvent(invokeId, output) {
16805
+ return {
16806
+ type: `xstate.done.actor.${invokeId}`,
16807
+ output,
16808
+ actorId: invokeId
16809
+ };
16810
+ }
16811
+ function createErrorActorEvent(id, error) {
16812
+ return {
16813
+ type: `xstate.error.actor.${id}`,
16814
+ error,
16815
+ actorId: id
16816
+ };
16817
+ }
16818
+ function createInitEvent(input) {
16819
+ return {
16820
+ type: XSTATE_INIT,
16821
+ input
16822
+ };
16823
+ }
16824
+ function reportUnhandledError(err2) {
16825
+ setTimeout(() => {
16826
+ throw err2;
16827
+ });
16828
+ }
16829
+ function matchesState(parentStateId, childStateId) {
16830
+ const parentStateValue = toStateValue(parentStateId);
16831
+ const childStateValue = toStateValue(childStateId);
16832
+ if (typeof childStateValue === "string") {
16833
+ if (typeof parentStateValue === "string") {
16834
+ return childStateValue === parentStateValue;
16835
+ }
16836
+ return false;
16837
+ }
16838
+ if (typeof parentStateValue === "string") {
16839
+ return parentStateValue in childStateValue;
16840
+ }
16841
+ return Object.keys(parentStateValue).every((key) => {
16842
+ if (!(key in childStateValue)) {
16843
+ return false;
16844
+ }
16845
+ return matchesState(parentStateValue[key], childStateValue[key]);
16846
+ });
16847
+ }
16848
+ function toStatePath(stateId) {
16849
+ if (isArray(stateId)) {
16850
+ return stateId;
16851
+ }
16852
+ const result = [];
16853
+ let segment = "";
16854
+ for (let i = 0; i < stateId.length; i++) {
16855
+ const char = stateId.charCodeAt(i);
16856
+ switch (char) {
16857
+ // \
16858
+ case 92:
16859
+ segment += stateId[i + 1];
16860
+ i++;
16861
+ continue;
16862
+ // .
16863
+ case 46:
16864
+ result.push(segment);
16865
+ segment = "";
16866
+ continue;
16867
+ }
16868
+ segment += stateId[i];
16869
+ }
16870
+ result.push(segment);
16871
+ return result;
16872
+ }
16873
+ function toStateValue(stateValue) {
16874
+ if (isMachineSnapshot(stateValue)) {
16875
+ return stateValue.value;
16876
+ }
16877
+ if (typeof stateValue !== "string") {
16878
+ return stateValue;
16879
+ }
16880
+ const statePath = toStatePath(stateValue);
16881
+ return pathToStateValue(statePath);
16882
+ }
16883
+ function pathToStateValue(statePath) {
16884
+ if (statePath.length === 1) {
16885
+ return statePath[0];
16886
+ }
16887
+ const value = {};
16888
+ let marker = value;
16889
+ for (let i = 0; i < statePath.length - 1; i++) {
16890
+ if (i === statePath.length - 2) {
16891
+ marker[statePath[i]] = statePath[i + 1];
16892
+ } else {
16893
+ const previous = marker;
16894
+ marker = {};
16895
+ previous[statePath[i]] = marker;
16896
+ }
16897
+ }
16898
+ return value;
16899
+ }
16900
+ function mapValues(collection, iteratee) {
16901
+ const result = {};
16902
+ const collectionKeys = Object.keys(collection);
16903
+ for (let i = 0; i < collectionKeys.length; i++) {
16904
+ const key = collectionKeys[i];
16905
+ result[key] = iteratee(collection[key], key, collection, i);
16906
+ }
16907
+ return result;
16908
+ }
16909
+ function toArrayStrict(value) {
16910
+ if (isArray(value)) {
16911
+ return value;
16912
+ }
16913
+ return [value];
16914
+ }
16915
+ function toArray(value) {
16916
+ if (value === void 0) {
16917
+ return [];
16918
+ }
16919
+ return toArrayStrict(value);
16920
+ }
16921
+ function resolveOutput(mapper, context, event, self2) {
16922
+ if (typeof mapper === "function") {
16923
+ return mapper({
16924
+ context,
16925
+ event,
16926
+ self: self2
16927
+ });
16928
+ }
16929
+ return mapper;
16930
+ }
16931
+ function isArray(value) {
16932
+ return Array.isArray(value);
16933
+ }
16934
+ function isErrorActorEvent(event) {
16935
+ return event.type.startsWith("xstate.error.actor");
16936
+ }
16937
+ function toTransitionConfigArray(configLike) {
16938
+ return toArrayStrict(configLike).map((transitionLike) => {
16939
+ if (typeof transitionLike === "undefined" || typeof transitionLike === "string") {
16940
+ return {
16941
+ target: transitionLike
16942
+ };
16943
+ }
16944
+ return transitionLike;
16945
+ });
16946
+ }
16947
+ function normalizeTarget(target) {
16948
+ if (target === void 0 || target === TARGETLESS_KEY) {
16949
+ return void 0;
16950
+ }
16951
+ return toArray(target);
16952
+ }
16953
+ function toObserver(nextHandler, errorHandler, completionHandler) {
16954
+ const isObserver = typeof nextHandler === "object";
16955
+ const self2 = isObserver ? nextHandler : void 0;
16956
+ return {
16957
+ next: (isObserver ? nextHandler.next : nextHandler)?.bind(self2),
16958
+ error: (isObserver ? nextHandler.error : errorHandler)?.bind(self2),
16959
+ complete: (isObserver ? nextHandler.complete : completionHandler)?.bind(self2)
16960
+ };
16961
+ }
16962
+ function createInvokeId(stateNodeId, index) {
16963
+ return `${index}.${stateNodeId}`;
16964
+ }
16965
+ function resolveReferencedActor(machine, src) {
16966
+ const match = src.match(/^xstate\.invoke\.(\d+)\.(.*)/);
16967
+ if (!match) {
16968
+ return machine.implementations.actors[src];
16969
+ }
16970
+ const [, indexStr, nodeId] = match;
16971
+ const node = machine.getStateNodeById(nodeId);
16972
+ const invokeConfig = node.config.invoke;
16973
+ return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
16974
+ }
16975
+ function matchesEventDescriptor(eventType, descriptor) {
16976
+ if (descriptor === eventType) {
16977
+ return true;
16978
+ }
16979
+ if (descriptor === WILDCARD) {
16980
+ return true;
16981
+ }
16982
+ if (!descriptor.endsWith(".*")) {
16983
+ return false;
16984
+ }
16985
+ const partialEventTokens = descriptor.split(".");
16986
+ const eventTokens = eventType.split(".");
16987
+ for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
16988
+ const partialEventToken = partialEventTokens[tokenIndex];
16989
+ const eventToken = eventTokens[tokenIndex];
16990
+ if (partialEventToken === "*") {
16991
+ const isLastToken = tokenIndex === partialEventTokens.length - 1;
16992
+ return isLastToken;
16993
+ }
16994
+ if (partialEventToken !== eventToken) {
16995
+ return false;
16996
+ }
16997
+ }
16998
+ return true;
16999
+ }
17000
+ function createScheduledEventId(actorRef, id) {
17001
+ return `${actorRef.sessionId}.${id}`;
17002
+ }
17003
+ function createSystem(rootActor, options) {
17004
+ const children2 = /* @__PURE__ */ new Map();
17005
+ const keyedActors = /* @__PURE__ */ new Map();
17006
+ const reverseKeyedActors = /* @__PURE__ */ new WeakMap();
17007
+ const inspectionObservers = /* @__PURE__ */ new Set();
17008
+ const timerMap = {};
17009
+ const {
17010
+ clock,
17011
+ logger
17012
+ } = options;
17013
+ const scheduler = {
17014
+ schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
17015
+ const scheduledEvent = {
17016
+ source,
17017
+ target,
17018
+ event,
17019
+ delay,
17020
+ id,
17021
+ startedAt: Date.now()
17022
+ };
17023
+ const scheduledEventId = createScheduledEventId(source, id);
17024
+ system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
17025
+ const timeout = clock.setTimeout(() => {
17026
+ delete timerMap[scheduledEventId];
17027
+ delete system._snapshot._scheduledEvents[scheduledEventId];
17028
+ system._relay(source, target, event);
17029
+ }, delay);
17030
+ timerMap[scheduledEventId] = timeout;
17031
+ },
17032
+ cancel: (source, id) => {
17033
+ const scheduledEventId = createScheduledEventId(source, id);
17034
+ const timeout = timerMap[scheduledEventId];
17035
+ delete timerMap[scheduledEventId];
17036
+ delete system._snapshot._scheduledEvents[scheduledEventId];
17037
+ if (timeout !== void 0) {
17038
+ clock.clearTimeout(timeout);
17039
+ }
17040
+ },
17041
+ cancelAll: (actorRef) => {
17042
+ for (const scheduledEventId in system._snapshot._scheduledEvents) {
17043
+ const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
17044
+ if (scheduledEvent.source === actorRef) {
17045
+ scheduler.cancel(actorRef, scheduledEvent.id);
17046
+ }
17047
+ }
17048
+ }
17049
+ };
17050
+ const sendInspectionEvent = (event) => {
17051
+ if (!inspectionObservers.size) {
17052
+ return;
17053
+ }
17054
+ const resolvedInspectionEvent = {
17055
+ ...event,
17056
+ rootId: rootActor.sessionId
17057
+ };
17058
+ inspectionObservers.forEach((observer) => observer.next?.(resolvedInspectionEvent));
17059
+ };
17060
+ const system = {
17061
+ _snapshot: {
17062
+ _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
17063
+ },
17064
+ _bookId: () => `x:${idCounter++}`,
17065
+ _register: (sessionId, actorRef) => {
17066
+ children2.set(sessionId, actorRef);
17067
+ return sessionId;
17068
+ },
17069
+ _unregister: (actorRef) => {
17070
+ children2.delete(actorRef.sessionId);
17071
+ const systemId = reverseKeyedActors.get(actorRef);
17072
+ if (systemId !== void 0) {
17073
+ keyedActors.delete(systemId);
17074
+ reverseKeyedActors.delete(actorRef);
17075
+ }
17076
+ },
17077
+ get: (systemId) => {
17078
+ return keyedActors.get(systemId);
17079
+ },
17080
+ getAll: () => {
17081
+ return Object.fromEntries(keyedActors.entries());
17082
+ },
17083
+ _set: (systemId, actorRef) => {
17084
+ const existing = keyedActors.get(systemId);
17085
+ if (existing && existing !== actorRef) {
17086
+ throw new Error(`Actor with system ID '${systemId}' already exists.`);
17087
+ }
17088
+ keyedActors.set(systemId, actorRef);
17089
+ reverseKeyedActors.set(actorRef, systemId);
17090
+ },
17091
+ inspect: (observerOrFn) => {
17092
+ const observer = toObserver(observerOrFn);
17093
+ inspectionObservers.add(observer);
17094
+ return {
17095
+ unsubscribe() {
17096
+ inspectionObservers.delete(observer);
17097
+ }
17098
+ };
17099
+ },
17100
+ _sendInspectionEvent: sendInspectionEvent,
17101
+ _relay: (source, target, event) => {
17102
+ system._sendInspectionEvent({
17103
+ type: "@xstate.event",
17104
+ sourceRef: source,
17105
+ actorRef: target,
17106
+ event
17107
+ });
17108
+ target._send(event);
17109
+ },
17110
+ scheduler,
17111
+ getSnapshot: () => {
17112
+ return {
17113
+ _scheduledEvents: {
17114
+ ...system._snapshot._scheduledEvents
17115
+ }
17116
+ };
17117
+ },
17118
+ start: () => {
17119
+ const scheduledEvents = system._snapshot._scheduledEvents;
17120
+ system._snapshot._scheduledEvents = {};
17121
+ for (const scheduledId in scheduledEvents) {
17122
+ const {
17123
+ source,
17124
+ target,
17125
+ event,
17126
+ delay,
17127
+ id
17128
+ } = scheduledEvents[scheduledId];
17129
+ scheduler.schedule(source, target, event, delay, id);
17130
+ }
17131
+ },
17132
+ _clock: clock,
17133
+ _logger: logger
17134
+ };
17135
+ return system;
17136
+ }
17137
+ function createActor(logic, ...[options]) {
17138
+ return new Actor(logic, options);
17139
+ }
17140
+ function resolveCancel(_, snapshot, actionArgs, actionParams, {
17141
+ sendId
17142
+ }) {
17143
+ const resolvedSendId = typeof sendId === "function" ? sendId(actionArgs, actionParams) : sendId;
17144
+ return [snapshot, {
17145
+ sendId: resolvedSendId
17146
+ }, void 0];
17147
+ }
17148
+ function executeCancel(actorScope, params) {
17149
+ actorScope.defer(() => {
17150
+ actorScope.system.scheduler.cancel(actorScope.self, params.sendId);
17151
+ });
17152
+ }
17153
+ function cancel(sendId) {
17154
+ function cancel2(_args, _params) {
17155
+ }
17156
+ cancel2.type = "xstate.cancel";
17157
+ cancel2.sendId = sendId;
17158
+ cancel2.resolve = resolveCancel;
17159
+ cancel2.execute = executeCancel;
17160
+ return cancel2;
17161
+ }
17162
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
17163
+ id,
17164
+ systemId,
17165
+ src,
17166
+ input,
17167
+ syncSnapshot
17168
+ }) {
17169
+ const logic = typeof src === "string" ? resolveReferencedActor(snapshot.machine, src) : src;
17170
+ const resolvedId = typeof id === "function" ? id(actionArgs) : id;
17171
+ let actorRef;
17172
+ let resolvedInput = void 0;
17173
+ if (logic) {
17174
+ resolvedInput = typeof input === "function" ? input({
17175
+ context: snapshot.context,
17176
+ event: actionArgs.event,
17177
+ self: actorScope.self
17178
+ }) : input;
17179
+ actorRef = createActor(logic, {
17180
+ id: resolvedId,
17181
+ src,
17182
+ parent: actorScope.self,
17183
+ syncSnapshot,
17184
+ systemId,
17185
+ input: resolvedInput
17186
+ });
17187
+ }
17188
+ return [cloneMachineSnapshot(snapshot, {
17189
+ children: {
17190
+ ...snapshot.children,
17191
+ [resolvedId]: actorRef
17192
+ }
17193
+ }), {
17194
+ id,
17195
+ systemId,
17196
+ actorRef,
17197
+ src,
17198
+ input: resolvedInput
17199
+ }, void 0];
17200
+ }
17201
+ function executeSpawn(actorScope, {
17202
+ actorRef
17203
+ }) {
17204
+ if (!actorRef) {
17205
+ return;
17206
+ }
17207
+ actorScope.defer(() => {
17208
+ if (actorRef._processingStatus === ProcessingStatus.Stopped) {
17209
+ return;
17210
+ }
17211
+ actorRef.start();
17212
+ });
17213
+ }
17214
+ function spawnChild(...[src, {
17215
+ id,
17216
+ systemId,
17217
+ input,
17218
+ syncSnapshot = false
17219
+ } = {}]) {
17220
+ function spawnChild2(_args, _params) {
17221
+ }
17222
+ spawnChild2.type = "xstate.spawnChild";
17223
+ spawnChild2.id = id;
17224
+ spawnChild2.systemId = systemId;
17225
+ spawnChild2.src = src;
17226
+ spawnChild2.input = input;
17227
+ spawnChild2.syncSnapshot = syncSnapshot;
17228
+ spawnChild2.resolve = resolveSpawn;
17229
+ spawnChild2.execute = executeSpawn;
17230
+ return spawnChild2;
17231
+ }
17232
+ function resolveStop(_, snapshot, args, actionParams, {
17233
+ actorRef
17234
+ }) {
17235
+ const actorRefOrString = typeof actorRef === "function" ? actorRef(args, actionParams) : actorRef;
17236
+ const resolvedActorRef = typeof actorRefOrString === "string" ? snapshot.children[actorRefOrString] : actorRefOrString;
17237
+ let children2 = snapshot.children;
17238
+ if (resolvedActorRef) {
17239
+ children2 = {
17240
+ ...children2
17241
+ };
17242
+ delete children2[resolvedActorRef.id];
17243
+ }
17244
+ return [cloneMachineSnapshot(snapshot, {
17245
+ children: children2
17246
+ }), resolvedActorRef, void 0];
17247
+ }
17248
+ function unregisterRecursively(actorScope, actorRef) {
17249
+ const snapshot = actorRef.getSnapshot();
17250
+ if (snapshot && "children" in snapshot) {
17251
+ for (const child2 of Object.values(snapshot.children)) {
17252
+ unregisterRecursively(actorScope, child2);
17253
+ }
17254
+ }
17255
+ actorScope.system._unregister(actorRef);
17256
+ }
17257
+ function executeStop(actorScope, actorRef) {
17258
+ if (!actorRef) {
17259
+ return;
17260
+ }
17261
+ unregisterRecursively(actorScope, actorRef);
17262
+ if (actorRef._processingStatus !== ProcessingStatus.Running) {
17263
+ actorScope.stopChild(actorRef);
17264
+ return;
17265
+ }
17266
+ actorScope.defer(() => {
17267
+ actorScope.stopChild(actorRef);
17268
+ });
17269
+ }
17270
+ function stopChild(actorRef) {
17271
+ function stop2(_args, _params) {
17272
+ }
17273
+ stop2.type = "xstate.stopChild";
17274
+ stop2.actorRef = actorRef;
17275
+ stop2.resolve = resolveStop;
17276
+ stop2.execute = executeStop;
17277
+ return stop2;
17278
+ }
17279
+ function evaluateGuard(guard, context, event, snapshot) {
17280
+ const {
17281
+ machine
17282
+ } = snapshot;
17283
+ const isInline = typeof guard === "function";
17284
+ const resolved = isInline ? guard : machine.implementations.guards[typeof guard === "string" ? guard : guard.type];
17285
+ if (!isInline && !resolved) {
17286
+ throw new Error(`Guard '${typeof guard === "string" ? guard : guard.type}' is not implemented.'.`);
17287
+ }
17288
+ if (typeof resolved !== "function") {
17289
+ return evaluateGuard(resolved, context, event, snapshot);
17290
+ }
17291
+ const guardArgs = {
17292
+ context,
17293
+ event
17294
+ };
17295
+ const guardParams = isInline || typeof guard === "string" ? void 0 : "params" in guard ? typeof guard.params === "function" ? guard.params({
17296
+ context,
17297
+ event
17298
+ }) : guard.params : void 0;
17299
+ if (!("check" in resolved)) {
17300
+ return resolved(guardArgs, guardParams);
17301
+ }
17302
+ const builtinGuard = resolved;
17303
+ return builtinGuard.check(
17304
+ snapshot,
17305
+ guardArgs,
17306
+ resolved
17307
+ // this holds all params
17308
+ );
17309
+ }
17310
+ function isAtomicStateNode(stateNode) {
17311
+ return stateNode.type === "atomic" || stateNode.type === "final";
17312
+ }
17313
+ function getChildren(stateNode) {
17314
+ return Object.values(stateNode.states).filter((sn) => sn.type !== "history");
17315
+ }
17316
+ function getProperAncestors(stateNode, toStateNode) {
17317
+ const ancestors = [];
17318
+ if (toStateNode === stateNode) {
17319
+ return ancestors;
17320
+ }
17321
+ let m = stateNode.parent;
17322
+ while (m && m !== toStateNode) {
17323
+ ancestors.push(m);
17324
+ m = m.parent;
17325
+ }
17326
+ return ancestors;
17327
+ }
17328
+ function getAllStateNodes(stateNodes) {
17329
+ const nodeSet = new Set(stateNodes);
17330
+ const adjList = getAdjList(nodeSet);
17331
+ for (const s of nodeSet) {
17332
+ if (s.type === "compound" && (!adjList.get(s) || !adjList.get(s).length)) {
17333
+ getInitialStateNodesWithTheirAncestors(s).forEach((sn) => nodeSet.add(sn));
17334
+ } else {
17335
+ if (s.type === "parallel") {
17336
+ for (const child2 of getChildren(s)) {
17337
+ if (child2.type === "history") {
17338
+ continue;
17339
+ }
17340
+ if (!nodeSet.has(child2)) {
17341
+ const initialStates = getInitialStateNodesWithTheirAncestors(child2);
17342
+ for (const initialStateNode of initialStates) {
17343
+ nodeSet.add(initialStateNode);
17344
+ }
17345
+ }
17346
+ }
17347
+ }
17348
+ }
17349
+ }
17350
+ for (const s of nodeSet) {
17351
+ let m = s.parent;
17352
+ while (m) {
17353
+ nodeSet.add(m);
17354
+ m = m.parent;
17355
+ }
17356
+ }
17357
+ return nodeSet;
17358
+ }
17359
+ function getValueFromAdj(baseNode, adjList) {
17360
+ const childStateNodes = adjList.get(baseNode);
17361
+ if (!childStateNodes) {
17362
+ return {};
17363
+ }
17364
+ if (baseNode.type === "compound") {
17365
+ const childStateNode = childStateNodes[0];
17366
+ if (childStateNode) {
17367
+ if (isAtomicStateNode(childStateNode)) {
17368
+ return childStateNode.key;
17369
+ }
17370
+ } else {
17371
+ return {};
17372
+ }
17373
+ }
17374
+ const stateValue = {};
17375
+ for (const childStateNode of childStateNodes) {
17376
+ stateValue[childStateNode.key] = getValueFromAdj(childStateNode, adjList);
17377
+ }
17378
+ return stateValue;
17379
+ }
17380
+ function getAdjList(stateNodes) {
17381
+ const adjList = /* @__PURE__ */ new Map();
17382
+ for (const s of stateNodes) {
17383
+ if (!adjList.has(s)) {
17384
+ adjList.set(s, []);
17385
+ }
17386
+ if (s.parent) {
17387
+ if (!adjList.has(s.parent)) {
17388
+ adjList.set(s.parent, []);
17389
+ }
17390
+ adjList.get(s.parent).push(s);
17391
+ }
17392
+ }
17393
+ return adjList;
17394
+ }
17395
+ function getStateValue(rootNode, stateNodes) {
17396
+ const config = getAllStateNodes(stateNodes);
17397
+ return getValueFromAdj(rootNode, getAdjList(config));
17398
+ }
17399
+ function isInFinalState(stateNodeSet, stateNode) {
17400
+ if (stateNode.type === "compound") {
17401
+ return getChildren(stateNode).some((s) => s.type === "final" && stateNodeSet.has(s));
17402
+ }
17403
+ if (stateNode.type === "parallel") {
17404
+ return getChildren(stateNode).every((sn) => isInFinalState(stateNodeSet, sn));
17405
+ }
17406
+ return stateNode.type === "final";
17407
+ }
17408
+ function getCandidates(stateNode, receivedEventType) {
17409
+ const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter((eventDescriptor) => matchesEventDescriptor(receivedEventType, eventDescriptor)).sort((a, b) => b.length - a.length).flatMap((key) => stateNode.transitions.get(key));
17410
+ return candidates;
17411
+ }
17412
+ function getDelayedTransitions(stateNode) {
17413
+ const afterConfig = stateNode.config.after;
17414
+ if (!afterConfig) {
17415
+ return [];
17416
+ }
17417
+ const mutateEntryExit = (delay) => {
17418
+ const afterEvent = createAfterEvent(delay, stateNode.id);
17419
+ const eventType = afterEvent.type;
17420
+ stateNode.entry.push(raise(afterEvent, {
17421
+ id: eventType,
17422
+ delay
17423
+ }));
17424
+ stateNode.exit.push(cancel(eventType));
17425
+ return eventType;
17426
+ };
17427
+ const delayedTransitions = Object.keys(afterConfig).flatMap((delay) => {
17428
+ const configTransition = afterConfig[delay];
17429
+ const resolvedTransition = typeof configTransition === "string" ? {
17430
+ target: configTransition
17431
+ } : configTransition;
17432
+ const resolvedDelay = Number.isNaN(+delay) ? delay : +delay;
17433
+ const eventType = mutateEntryExit(resolvedDelay);
17434
+ return toArray(resolvedTransition).map((transition) => ({
17435
+ ...transition,
17436
+ event: eventType,
17437
+ delay: resolvedDelay
17438
+ }));
17439
+ });
17440
+ return delayedTransitions.map((delayedTransition) => {
17441
+ const {
17442
+ delay
17443
+ } = delayedTransition;
17444
+ return {
17445
+ ...formatTransition(stateNode, delayedTransition.event, delayedTransition),
17446
+ delay
17447
+ };
17448
+ });
17449
+ }
17450
+ function formatTransition(stateNode, descriptor, transitionConfig) {
17451
+ const normalizedTarget = normalizeTarget(transitionConfig.target);
17452
+ const reenter = transitionConfig.reenter ?? false;
17453
+ const target = resolveTarget(stateNode, normalizedTarget);
17454
+ const transition = {
17455
+ ...transitionConfig,
17456
+ actions: toArray(transitionConfig.actions),
17457
+ guard: transitionConfig.guard,
17458
+ target,
17459
+ source: stateNode,
17460
+ reenter,
17461
+ eventType: descriptor,
17462
+ toJSON: () => ({
17463
+ ...transition,
17464
+ source: `#${stateNode.id}`,
17465
+ target: target ? target.map((t) => `#${t.id}`) : void 0
17466
+ })
17467
+ };
17468
+ return transition;
17469
+ }
17470
+ function formatTransitions(stateNode) {
17471
+ const transitions = /* @__PURE__ */ new Map();
17472
+ if (stateNode.config.on) {
17473
+ for (const descriptor of Object.keys(stateNode.config.on)) {
17474
+ if (descriptor === NULL_EVENT) {
17475
+ throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
17476
+ }
17477
+ const transitionsConfig = stateNode.config.on[descriptor];
17478
+ transitions.set(descriptor, toTransitionConfigArray(transitionsConfig).map((t) => formatTransition(stateNode, descriptor, t)));
17479
+ }
17480
+ }
17481
+ if (stateNode.config.onDone) {
17482
+ const descriptor = `xstate.done.state.${stateNode.id}`;
17483
+ transitions.set(descriptor, toTransitionConfigArray(stateNode.config.onDone).map((t) => formatTransition(stateNode, descriptor, t)));
17484
+ }
17485
+ for (const invokeDef of stateNode.invoke) {
17486
+ if (invokeDef.onDone) {
17487
+ const descriptor = `xstate.done.actor.${invokeDef.id}`;
17488
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onDone).map((t) => formatTransition(stateNode, descriptor, t)));
17489
+ }
17490
+ if (invokeDef.onError) {
17491
+ const descriptor = `xstate.error.actor.${invokeDef.id}`;
17492
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onError).map((t) => formatTransition(stateNode, descriptor, t)));
17493
+ }
17494
+ if (invokeDef.onSnapshot) {
17495
+ const descriptor = `xstate.snapshot.${invokeDef.id}`;
17496
+ transitions.set(descriptor, toTransitionConfigArray(invokeDef.onSnapshot).map((t) => formatTransition(stateNode, descriptor, t)));
17497
+ }
17498
+ }
17499
+ for (const delayedTransition of stateNode.after) {
17500
+ let existing = transitions.get(delayedTransition.eventType);
17501
+ if (!existing) {
17502
+ existing = [];
17503
+ transitions.set(delayedTransition.eventType, existing);
17504
+ }
17505
+ existing.push(delayedTransition);
17506
+ }
17507
+ return transitions;
17508
+ }
17509
+ function formatRouteTransitions(rootStateNode) {
17510
+ const routeTransitions = [];
17511
+ const collectRoutes = (states) => {
17512
+ Object.values(states).forEach((sn) => {
17513
+ if (sn.config.route && sn.config.id) {
17514
+ const routeId = sn.config.id;
17515
+ const userGuard = sn.config.route.guard;
17516
+ const routeGuard = (args, params) => {
17517
+ if (args.event.to !== `#${routeId}`) {
17518
+ return false;
17519
+ }
17520
+ if (!userGuard) {
17521
+ return true;
17522
+ }
17523
+ if (typeof userGuard === "function") {
17524
+ return userGuard(args, params);
17525
+ }
17526
+ return true;
17527
+ };
17528
+ const transition = {
17529
+ ...sn.config.route,
17530
+ guard: routeGuard,
17531
+ target: `#${routeId}`
17532
+ };
17533
+ routeTransitions.push(formatTransition(rootStateNode, "xstate.route", transition));
17534
+ }
17535
+ if (sn.states) {
17536
+ collectRoutes(sn.states);
17537
+ }
17538
+ });
17539
+ };
17540
+ collectRoutes(rootStateNode.states);
17541
+ if (routeTransitions.length > 0) {
17542
+ rootStateNode.transitions.set("xstate.route", routeTransitions);
17543
+ }
17544
+ }
17545
+ function formatInitialTransition(stateNode, _target) {
17546
+ const resolvedTarget = typeof _target === "string" ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : void 0;
17547
+ if (!resolvedTarget && _target) {
17548
+ throw new Error(
17549
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
17550
+ `Initial state node "${_target}" not found on parent state node #${stateNode.id}`
17551
+ );
17552
+ }
17553
+ const transition = {
17554
+ source: stateNode,
17555
+ actions: !_target || typeof _target === "string" ? [] : toArray(_target.actions),
17556
+ eventType: null,
17557
+ reenter: false,
17558
+ target: resolvedTarget ? [resolvedTarget] : [],
17559
+ toJSON: () => ({
17560
+ ...transition,
17561
+ source: `#${stateNode.id}`,
17562
+ target: resolvedTarget ? [`#${resolvedTarget.id}`] : []
17563
+ })
17564
+ };
17565
+ return transition;
17566
+ }
17567
+ function resolveTarget(stateNode, targets) {
17568
+ if (targets === void 0) {
17569
+ return void 0;
17570
+ }
17571
+ return targets.map((target) => {
17572
+ if (typeof target !== "string") {
17573
+ return target;
17574
+ }
17575
+ if (isStateId(target)) {
17576
+ return stateNode.machine.getStateNodeById(target);
17577
+ }
17578
+ const isInternalTarget = target[0] === STATE_DELIMITER;
17579
+ if (isInternalTarget && !stateNode.parent) {
17580
+ return getStateNodeByPath(stateNode, target.slice(1));
17581
+ }
17582
+ const resolvedTarget = isInternalTarget ? stateNode.key + target : target;
17583
+ if (stateNode.parent) {
17584
+ try {
17585
+ const targetStateNode = getStateNodeByPath(stateNode.parent, resolvedTarget);
17586
+ return targetStateNode;
17587
+ } catch (err2) {
17588
+ throw new Error(`Invalid transition definition for state node '${stateNode.id}':
17589
+ ${err2.message}`);
17590
+ }
17591
+ } else {
17592
+ throw new Error(`Invalid target: "${target}" is not a valid target from the root node. Did you mean ".${target}"?`);
17593
+ }
17594
+ });
17595
+ }
17596
+ function resolveHistoryDefaultTransition(stateNode) {
17597
+ const normalizedTarget = normalizeTarget(stateNode.config.target);
17598
+ if (!normalizedTarget) {
17599
+ return stateNode.parent.initial;
17600
+ }
17601
+ return {
17602
+ target: normalizedTarget.map((t) => typeof t === "string" ? getStateNodeByPath(stateNode.parent, t) : t)
17603
+ };
17604
+ }
17605
+ function isHistoryNode(stateNode) {
17606
+ return stateNode.type === "history";
17607
+ }
17608
+ function getInitialStateNodesWithTheirAncestors(stateNode) {
17609
+ const states = getInitialStateNodes(stateNode);
17610
+ for (const initialState of states) {
17611
+ for (const ancestor of getProperAncestors(initialState, stateNode)) {
17612
+ states.add(ancestor);
17613
+ }
17614
+ }
17615
+ return states;
17616
+ }
17617
+ function getInitialStateNodes(stateNode) {
17618
+ const set = /* @__PURE__ */ new Set();
17619
+ function iter(descStateNode) {
17620
+ if (set.has(descStateNode)) {
17621
+ return;
17622
+ }
17623
+ set.add(descStateNode);
17624
+ if (descStateNode.type === "compound") {
17625
+ iter(descStateNode.initial.target[0]);
17626
+ } else if (descStateNode.type === "parallel") {
17627
+ for (const child2 of getChildren(descStateNode)) {
17628
+ iter(child2);
17629
+ }
17630
+ }
17631
+ }
17632
+ iter(stateNode);
17633
+ return set;
17634
+ }
17635
+ function getStateNode(stateNode, stateKey) {
17636
+ if (isStateId(stateKey)) {
17637
+ return stateNode.machine.getStateNodeById(stateKey);
17638
+ }
17639
+ if (!stateNode.states) {
17640
+ throw new Error(`Unable to retrieve child state '${stateKey}' from '${stateNode.id}'; no child states exist.`);
17641
+ }
17642
+ const result = stateNode.states[stateKey];
17643
+ if (!result) {
17644
+ throw new Error(`Child state '${stateKey}' does not exist on '${stateNode.id}'`);
17645
+ }
17646
+ return result;
17647
+ }
17648
+ function getStateNodeByPath(stateNode, statePath) {
17649
+ if (typeof statePath === "string" && isStateId(statePath)) {
17650
+ try {
17651
+ return stateNode.machine.getStateNodeById(statePath);
17652
+ } catch {
17653
+ }
17654
+ }
17655
+ const arrayStatePath = toStatePath(statePath).slice();
17656
+ let currentStateNode = stateNode;
17657
+ while (arrayStatePath.length) {
17658
+ const key = arrayStatePath.shift();
17659
+ if (!key.length) {
17660
+ break;
17661
+ }
17662
+ currentStateNode = getStateNode(currentStateNode, key);
17663
+ }
17664
+ return currentStateNode;
17665
+ }
17666
+ function getStateNodes(stateNode, stateValue) {
17667
+ if (typeof stateValue === "string") {
17668
+ const childStateNode = stateNode.states[stateValue];
17669
+ if (!childStateNode) {
17670
+ throw new Error(`State '${stateValue}' does not exist on '${stateNode.id}'`);
17671
+ }
17672
+ return [stateNode, childStateNode];
17673
+ }
17674
+ const childStateKeys = Object.keys(stateValue);
17675
+ const childStateNodes = childStateKeys.map((subStateKey) => getStateNode(stateNode, subStateKey)).filter(Boolean);
17676
+ return [stateNode.machine.root, stateNode].concat(childStateNodes, childStateKeys.reduce((allSubStateNodes, subStateKey) => {
17677
+ const subStateNode = getStateNode(stateNode, subStateKey);
17678
+ if (!subStateNode) {
17679
+ return allSubStateNodes;
17680
+ }
17681
+ const subStateNodes = getStateNodes(subStateNode, stateValue[subStateKey]);
17682
+ return allSubStateNodes.concat(subStateNodes);
17683
+ }, []));
17684
+ }
17685
+ function transitionAtomicNode(stateNode, stateValue, snapshot, event) {
17686
+ const childStateNode = getStateNode(stateNode, stateValue);
17687
+ const next = childStateNode.next(snapshot, event);
17688
+ if (!next || !next.length) {
17689
+ return stateNode.next(snapshot, event);
17690
+ }
17691
+ return next;
17692
+ }
17693
+ function transitionCompoundNode(stateNode, stateValue, snapshot, event) {
17694
+ const subStateKeys = Object.keys(stateValue);
17695
+ const childStateNode = getStateNode(stateNode, subStateKeys[0]);
17696
+ const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], snapshot, event);
17697
+ if (!next || !next.length) {
17698
+ return stateNode.next(snapshot, event);
17699
+ }
17700
+ return next;
17701
+ }
17702
+ function transitionParallelNode(stateNode, stateValue, snapshot, event) {
17703
+ const allInnerTransitions = [];
17704
+ for (const subStateKey of Object.keys(stateValue)) {
17705
+ const subStateValue = stateValue[subStateKey];
17706
+ if (!subStateValue) {
17707
+ continue;
17708
+ }
17709
+ const subStateNode = getStateNode(stateNode, subStateKey);
17710
+ const innerTransitions = transitionNode(subStateNode, subStateValue, snapshot, event);
17711
+ if (innerTransitions) {
17712
+ allInnerTransitions.push(...innerTransitions);
17713
+ }
17714
+ }
17715
+ if (!allInnerTransitions.length) {
17716
+ return stateNode.next(snapshot, event);
17717
+ }
17718
+ return allInnerTransitions;
17719
+ }
17720
+ function transitionNode(stateNode, stateValue, snapshot, event) {
17721
+ if (typeof stateValue === "string") {
17722
+ return transitionAtomicNode(stateNode, stateValue, snapshot, event);
17723
+ }
17724
+ if (Object.keys(stateValue).length === 1) {
17725
+ return transitionCompoundNode(stateNode, stateValue, snapshot, event);
17726
+ }
17727
+ return transitionParallelNode(stateNode, stateValue, snapshot, event);
17728
+ }
17729
+ function getHistoryNodes(stateNode) {
17730
+ return Object.keys(stateNode.states).map((key) => stateNode.states[key]).filter((sn) => sn.type === "history");
17731
+ }
17732
+ function isDescendant(childStateNode, parentStateNode) {
17733
+ let marker = childStateNode;
17734
+ while (marker.parent && marker.parent !== parentStateNode) {
17735
+ marker = marker.parent;
17736
+ }
17737
+ return marker.parent === parentStateNode;
17738
+ }
17739
+ function hasIntersection(s1, s2) {
17740
+ const set1 = new Set(s1);
17741
+ const set2 = new Set(s2);
17742
+ for (const item of set1) {
17743
+ if (set2.has(item)) {
17744
+ return true;
17745
+ }
17746
+ }
17747
+ for (const item of set2) {
17748
+ if (set1.has(item)) {
17749
+ return true;
17750
+ }
17751
+ }
17752
+ return false;
17753
+ }
17754
+ function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
17755
+ const filteredTransitions = /* @__PURE__ */ new Set();
17756
+ for (const t1 of enabledTransitions) {
17757
+ let t1Preempted = false;
17758
+ const transitionsToRemove = /* @__PURE__ */ new Set();
17759
+ for (const t2 of filteredTransitions) {
17760
+ if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
17761
+ if (isDescendant(t1.source, t2.source)) {
17762
+ transitionsToRemove.add(t2);
17763
+ } else {
17764
+ t1Preempted = true;
17765
+ break;
17766
+ }
17767
+ }
17768
+ }
17769
+ if (!t1Preempted) {
17770
+ for (const t3 of transitionsToRemove) {
17771
+ filteredTransitions.delete(t3);
17772
+ }
17773
+ filteredTransitions.add(t1);
17774
+ }
17775
+ }
17776
+ return Array.from(filteredTransitions);
17777
+ }
17778
+ function findLeastCommonAncestor(stateNodes) {
17779
+ const [head, ...tail] = stateNodes;
17780
+ for (const ancestor of getProperAncestors(head, void 0)) {
17781
+ if (tail.every((sn) => isDescendant(sn, ancestor))) {
17782
+ return ancestor;
17783
+ }
17784
+ }
17785
+ }
17786
+ function getEffectiveTargetStates(transition, historyValue) {
17787
+ if (!transition.target) {
17788
+ return [];
17789
+ }
17790
+ const targets = /* @__PURE__ */ new Set();
17791
+ for (const targetNode of transition.target) {
17792
+ if (isHistoryNode(targetNode)) {
17793
+ if (historyValue[targetNode.id]) {
17794
+ for (const node of historyValue[targetNode.id]) {
17795
+ targets.add(node);
17796
+ }
17797
+ } else {
17798
+ for (const node of getEffectiveTargetStates(resolveHistoryDefaultTransition(targetNode), historyValue)) {
17799
+ targets.add(node);
17800
+ }
17801
+ }
17802
+ } else {
17803
+ targets.add(targetNode);
17804
+ }
17805
+ }
17806
+ return [...targets];
17807
+ }
17808
+ function getTransitionDomain(transition, historyValue) {
17809
+ const targetStates = getEffectiveTargetStates(transition, historyValue);
17810
+ if (!targetStates) {
17811
+ return;
17812
+ }
17813
+ if (!transition.reenter && targetStates.every((target) => target === transition.source || isDescendant(target, transition.source))) {
17814
+ return transition.source;
17815
+ }
17816
+ const lca = findLeastCommonAncestor(targetStates.concat(transition.source));
17817
+ if (lca) {
17818
+ return lca;
17819
+ }
17820
+ if (transition.reenter) {
17821
+ return;
17822
+ }
17823
+ return transition.source.machine.root;
17824
+ }
17825
+ function computeExitSet(transitions, stateNodeSet, historyValue) {
17826
+ const statesToExit = /* @__PURE__ */ new Set();
17827
+ for (const t of transitions) {
17828
+ if (t.target?.length) {
17829
+ const domain = getTransitionDomain(t, historyValue);
17830
+ if (t.reenter && t.source === domain) {
17831
+ statesToExit.add(domain);
17832
+ }
17833
+ for (const stateNode of stateNodeSet) {
17834
+ if (isDescendant(stateNode, domain)) {
17835
+ statesToExit.add(stateNode);
17836
+ }
17837
+ }
17838
+ }
17839
+ }
17840
+ return [...statesToExit];
17841
+ }
17842
+ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
17843
+ if (prevStateNodes.length !== nextStateNodeSet.size) {
17844
+ return false;
17845
+ }
17846
+ for (const node of prevStateNodes) {
17847
+ if (!nextStateNodeSet.has(node)) {
17848
+ return false;
17849
+ }
17850
+ }
17851
+ return true;
17852
+ }
17853
+ function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
17854
+ return microstep([{
17855
+ target: [...getInitialStateNodes(root)],
17856
+ source: root,
17857
+ reenter: true,
17858
+ actions: [],
17859
+ eventType: null,
17860
+ toJSON: null
17861
+ }], preInitialState, actorScope, initEvent, true, internalQueue);
17862
+ }
17863
+ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
17864
+ const actions = [];
17865
+ if (!transitions.length) {
17866
+ return [currentSnapshot, actions];
17867
+ }
17868
+ const originalExecutor = actorScope.actionExecutor;
17869
+ actorScope.actionExecutor = (action) => {
17870
+ actions.push(action);
17871
+ originalExecutor(action);
17872
+ };
17873
+ try {
17874
+ const mutStateNodeSet = new Set(currentSnapshot._nodes);
17875
+ let historyValue = currentSnapshot.historyValue;
17876
+ const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
17877
+ let nextState = currentSnapshot;
17878
+ if (!isInitial) {
17879
+ [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
17880
+ }
17881
+ nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap((t) => t.actions), internalQueue, void 0);
17882
+ nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
17883
+ const nextStateNodes = [...mutStateNodeSet];
17884
+ if (nextState.status === "done") {
17885
+ nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap((state) => state.exit), internalQueue, void 0);
17886
+ }
17887
+ try {
17888
+ if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
17889
+ return [nextState, actions];
17890
+ }
17891
+ return [cloneMachineSnapshot(nextState, {
17892
+ _nodes: nextStateNodes,
17893
+ historyValue
17894
+ }), actions];
17895
+ } catch (e) {
17896
+ throw e;
17897
+ }
17898
+ } finally {
17899
+ actorScope.actionExecutor = originalExecutor;
17900
+ }
17901
+ }
17902
+ function getMachineOutput(snapshot, event, actorScope, rootNode, rootCompletionNode) {
17903
+ if (rootNode.output === void 0) {
17904
+ return;
17905
+ }
17906
+ const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output !== void 0 && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, snapshot.context, event, actorScope.self) : void 0);
17907
+ return resolveOutput(rootNode.output, snapshot.context, doneStateEvent, actorScope.self);
17908
+ }
17909
+ function enterStates(currentSnapshot, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
17910
+ let nextSnapshot = currentSnapshot;
17911
+ const statesToEnter = /* @__PURE__ */ new Set();
17912
+ const statesForDefaultEntry = /* @__PURE__ */ new Set();
17913
+ computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
17914
+ if (isInitial) {
17915
+ statesForDefaultEntry.add(currentSnapshot.machine.root);
17916
+ }
17917
+ const completedNodes = /* @__PURE__ */ new Set();
17918
+ for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
17919
+ mutStateNodeSet.add(stateNodeToEnter);
17920
+ const actions = [];
17921
+ actions.push(...stateNodeToEnter.entry);
17922
+ for (const invokeDef of stateNodeToEnter.invoke) {
17923
+ actions.push(spawnChild(invokeDef.src, {
17924
+ ...invokeDef,
17925
+ syncSnapshot: !!invokeDef.onSnapshot
17926
+ }));
17927
+ }
17928
+ if (statesForDefaultEntry.has(stateNodeToEnter)) {
17929
+ const initialActions = stateNodeToEnter.initial.actions;
17930
+ actions.push(...initialActions);
17931
+ }
17932
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map((invokeDef) => invokeDef.id));
17933
+ if (stateNodeToEnter.type === "final") {
17934
+ const parent = stateNodeToEnter.parent;
17935
+ let ancestorMarker = parent?.type === "parallel" ? parent : parent?.parent;
17936
+ let rootCompletionNode = ancestorMarker || stateNodeToEnter;
17937
+ if (parent?.type === "compound") {
17938
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== void 0 ? resolveOutput(stateNodeToEnter.output, nextSnapshot.context, event, actorScope.self) : void 0));
17939
+ }
17940
+ while (ancestorMarker?.type === "parallel" && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
17941
+ completedNodes.add(ancestorMarker);
17942
+ internalQueue.push(createDoneStateEvent(ancestorMarker.id));
17943
+ rootCompletionNode = ancestorMarker;
17944
+ ancestorMarker = ancestorMarker.parent;
17945
+ }
17946
+ if (ancestorMarker) {
17947
+ continue;
17948
+ }
17949
+ nextSnapshot = cloneMachineSnapshot(nextSnapshot, {
17950
+ status: "done",
17951
+ output: getMachineOutput(nextSnapshot, event, actorScope, nextSnapshot.machine.root, rootCompletionNode)
17952
+ });
17953
+ }
17954
+ }
17955
+ return nextSnapshot;
17956
+ }
17957
+ function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
17958
+ for (const t of transitions) {
17959
+ const domain = getTransitionDomain(t, historyValue);
17960
+ for (const s of t.target || []) {
17961
+ if (!isHistoryNode(s) && // if the target is different than the source then it will *definitely* be entered
17962
+ (t.source !== s || // we know that the domain can't lie within the source
17963
+ // if it's different than the source then it's outside of it and it means that the target has to be entered as well
17964
+ t.source !== domain || // reentering transitions always enter the target, even if it's the source itself
17965
+ t.reenter)) {
17966
+ statesToEnter.add(s);
17967
+ statesForDefaultEntry.add(s);
17968
+ }
17969
+ addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
17970
+ }
17971
+ const targetStates = getEffectiveTargetStates(t, historyValue);
17972
+ for (const s of targetStates) {
17973
+ const ancestors = getProperAncestors(s, domain);
17974
+ if (domain?.type === "parallel") {
17975
+ ancestors.push(domain);
17976
+ }
17977
+ addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, !t.source.parent && t.reenter ? void 0 : domain);
17978
+ }
17979
+ }
17980
+ }
17981
+ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEntry, statesToEnter) {
17982
+ if (isHistoryNode(stateNode)) {
17983
+ if (historyValue[stateNode.id]) {
17984
+ const historyStateNodes = historyValue[stateNode.id];
17985
+ for (const s of historyStateNodes) {
17986
+ statesToEnter.add(s);
17987
+ addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
17988
+ }
17989
+ for (const s of historyStateNodes) {
17990
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
17991
+ }
17992
+ } else {
17993
+ const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
17994
+ for (const s of historyDefaultTransition.target) {
17995
+ statesToEnter.add(s);
17996
+ if (historyDefaultTransition === stateNode.parent?.initial) {
17997
+ statesForDefaultEntry.add(stateNode.parent);
17998
+ }
17999
+ addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
18000
+ }
18001
+ for (const s of historyDefaultTransition.target) {
18002
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
18003
+ }
18004
+ }
18005
+ } else {
18006
+ if (stateNode.type === "compound") {
18007
+ const [initialState] = stateNode.initial.target;
18008
+ if (!isHistoryNode(initialState)) {
18009
+ statesToEnter.add(initialState);
18010
+ statesForDefaultEntry.add(initialState);
18011
+ }
18012
+ addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
18013
+ addProperAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
18014
+ } else {
18015
+ if (stateNode.type === "parallel") {
18016
+ for (const child2 of getChildren(stateNode).filter((sn) => !isHistoryNode(sn))) {
18017
+ if (![...statesToEnter].some((s) => isDescendant(s, child2))) {
18018
+ if (!isHistoryNode(child2)) {
18019
+ statesToEnter.add(child2);
18020
+ statesForDefaultEntry.add(child2);
18021
+ }
18022
+ addDescendantStatesToEnter(child2, historyValue, statesForDefaultEntry, statesToEnter);
18023
+ }
18024
+ }
18025
+ }
18026
+ }
18027
+ }
18028
+ }
18029
+ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, reentrancyDomain) {
18030
+ for (const anc of ancestors) {
18031
+ if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
18032
+ statesToEnter.add(anc);
18033
+ }
18034
+ if (anc.type === "parallel") {
18035
+ for (const child2 of getChildren(anc).filter((sn) => !isHistoryNode(sn))) {
18036
+ if (![...statesToEnter].some((s) => isDescendant(s, child2))) {
18037
+ statesToEnter.add(child2);
18038
+ addDescendantStatesToEnter(child2, historyValue, statesForDefaultEntry, statesToEnter);
18039
+ }
18040
+ }
18041
+ }
18042
+ }
18043
+ }
18044
+ function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
18045
+ addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
18046
+ }
18047
+ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
18048
+ let nextSnapshot = currentSnapshot;
18049
+ const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
18050
+ statesToExit.sort((a, b) => b.order - a.order);
18051
+ let changedHistory;
18052
+ for (const exitStateNode of statesToExit) {
18053
+ for (const historyNode of getHistoryNodes(exitStateNode)) {
18054
+ let predicate;
18055
+ if (historyNode.history === "deep") {
18056
+ predicate = (sn) => isAtomicStateNode(sn) && isDescendant(sn, exitStateNode);
18057
+ } else {
18058
+ predicate = (sn) => {
18059
+ return sn.parent === exitStateNode;
18060
+ };
18061
+ }
18062
+ changedHistory ??= {
18063
+ ...historyValue
18064
+ };
18065
+ changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
18066
+ }
18067
+ }
18068
+ for (const s of statesToExit) {
18069
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map((def) => stopChild(def.id))], internalQueue, void 0);
18070
+ mutStateNodeSet.delete(s);
18071
+ }
18072
+ return [nextSnapshot, changedHistory || historyValue];
18073
+ }
18074
+ function getAction(machine, actionType) {
18075
+ return machine.implementations.actions[actionType];
18076
+ }
18077
+ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
18078
+ const {
18079
+ machine
18080
+ } = currentSnapshot;
18081
+ let intermediateSnapshot = currentSnapshot;
18082
+ for (const action of actions) {
18083
+ const isInline = typeof action === "function";
18084
+ const resolvedAction = isInline ? action : (
18085
+ // the existing type of `.actions` assumes non-nullable `TExpressionAction`
18086
+ // it's fine to cast this here to get a common type and lack of errors in the rest of the code
18087
+ // our logic below makes sure that we call those 2 "variants" correctly
18088
+ getAction(machine, typeof action === "string" ? action : action.type)
18089
+ );
18090
+ const actionArgs = {
18091
+ context: intermediateSnapshot.context,
18092
+ event,
18093
+ self: actorScope.self,
18094
+ system: actorScope.system
18095
+ };
18096
+ const actionParams = isInline || typeof action === "string" ? void 0 : "params" in action ? typeof action.params === "function" ? action.params({
18097
+ context: intermediateSnapshot.context,
18098
+ event
18099
+ }) : action.params : void 0;
18100
+ if (!resolvedAction || !("resolve" in resolvedAction)) {
18101
+ actorScope.actionExecutor({
18102
+ type: typeof action === "string" ? action : typeof action === "object" ? action.type : action.name || "(anonymous)",
18103
+ info: actionArgs,
18104
+ params: actionParams,
18105
+ exec: resolvedAction
18106
+ });
18107
+ continue;
18108
+ }
18109
+ const builtinAction = resolvedAction;
18110
+ const [nextState, params, actions2] = builtinAction.resolve(
18111
+ actorScope,
18112
+ intermediateSnapshot,
18113
+ actionArgs,
18114
+ actionParams,
18115
+ resolvedAction,
18116
+ // this holds all params
18117
+ extra
18118
+ );
18119
+ intermediateSnapshot = nextState;
18120
+ if ("retryResolve" in builtinAction) {
18121
+ retries?.push([builtinAction, params]);
18122
+ }
18123
+ if ("execute" in builtinAction) {
18124
+ actorScope.actionExecutor({
18125
+ type: builtinAction.type,
18126
+ info: actionArgs,
18127
+ params,
18128
+ exec: builtinAction.execute.bind(null, actorScope, params)
18129
+ });
18130
+ }
18131
+ if (actions2) {
18132
+ intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions2, extra, retries);
18133
+ }
18134
+ }
18135
+ return intermediateSnapshot;
18136
+ }
18137
+ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
18138
+ const retries = deferredActorIds ? [] : void 0;
18139
+ const nextState = resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, {
18140
+ internalQueue,
18141
+ deferredActorIds
18142
+ }, retries);
18143
+ retries?.forEach(([builtinAction, params]) => {
18144
+ builtinAction.retryResolve(actorScope, nextState, params);
18145
+ });
18146
+ return nextState;
18147
+ }
18148
+ function macrostep(snapshot, event, actorScope, internalQueue) {
18149
+ let nextSnapshot = snapshot;
18150
+ const microsteps = [];
18151
+ function addMicrostep(step, event2, transitions) {
18152
+ actorScope.system._sendInspectionEvent({
18153
+ type: "@xstate.microstep",
18154
+ actorRef: actorScope.self,
18155
+ event: event2,
18156
+ snapshot: step[0],
18157
+ _transitions: transitions
18158
+ });
18159
+ microsteps.push(step);
18160
+ }
18161
+ if (event.type === XSTATE_STOP) {
18162
+ nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
18163
+ status: "stopped"
18164
+ });
18165
+ addMicrostep([nextSnapshot, []], event, []);
18166
+ return {
18167
+ snapshot: nextSnapshot,
18168
+ microsteps
18169
+ };
18170
+ }
18171
+ let nextEvent = event;
18172
+ if (nextEvent.type !== XSTATE_INIT) {
18173
+ const currentEvent = nextEvent;
18174
+ const isErr = isErrorActorEvent(currentEvent);
18175
+ const transitions = selectTransitions(currentEvent, nextSnapshot);
18176
+ if (isErr && !transitions.length) {
18177
+ nextSnapshot = cloneMachineSnapshot(snapshot, {
18178
+ status: "error",
18179
+ error: currentEvent.error
18180
+ });
18181
+ addMicrostep([nextSnapshot, []], currentEvent, []);
18182
+ return {
18183
+ snapshot: nextSnapshot,
18184
+ microsteps
18185
+ };
18186
+ }
18187
+ const step = microstep(
18188
+ transitions,
18189
+ snapshot,
18190
+ actorScope,
18191
+ nextEvent,
18192
+ false,
18193
+ // isInitial
18194
+ internalQueue
18195
+ );
18196
+ nextSnapshot = step[0];
18197
+ addMicrostep(step, currentEvent, transitions);
18198
+ }
18199
+ let shouldSelectEventlessTransitions = true;
18200
+ while (nextSnapshot.status === "active") {
18201
+ let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextSnapshot, nextEvent) : [];
18202
+ const previousState = enabledTransitions.length ? nextSnapshot : void 0;
18203
+ if (!enabledTransitions.length) {
18204
+ if (!internalQueue.length) {
18205
+ break;
18206
+ }
18207
+ nextEvent = internalQueue.shift();
18208
+ enabledTransitions = selectTransitions(nextEvent, nextSnapshot);
18209
+ }
18210
+ const step = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
18211
+ nextSnapshot = step[0];
18212
+ shouldSelectEventlessTransitions = nextSnapshot !== previousState;
18213
+ addMicrostep(step, nextEvent, enabledTransitions);
18214
+ }
18215
+ if (nextSnapshot.status !== "active") {
18216
+ stopChildren(nextSnapshot, nextEvent, actorScope);
18217
+ }
18218
+ return {
18219
+ snapshot: nextSnapshot,
18220
+ microsteps
18221
+ };
18222
+ }
18223
+ function stopChildren(nextState, event, actorScope) {
18224
+ return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map((child2) => stopChild(child2)), [], void 0);
18225
+ }
18226
+ function selectTransitions(event, nextState) {
18227
+ return nextState.machine.getTransitionData(nextState, event);
18228
+ }
18229
+ function selectEventlessTransitions(nextState, event) {
18230
+ const enabledTransitionSet = /* @__PURE__ */ new Set();
18231
+ const atomicStates = nextState._nodes.filter(isAtomicStateNode);
18232
+ for (const stateNode of atomicStates) {
18233
+ loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, void 0))) {
18234
+ if (!s.always) {
18235
+ continue;
18236
+ }
18237
+ for (const transition of s.always) {
18238
+ if (transition.guard === void 0 || evaluateGuard(transition.guard, nextState.context, event, nextState)) {
18239
+ enabledTransitionSet.add(transition);
18240
+ break loop;
18241
+ }
18242
+ }
18243
+ }
18244
+ }
18245
+ return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
18246
+ }
18247
+ function resolveStateValue(rootNode, stateValue) {
18248
+ const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
18249
+ return getStateValue(rootNode, [...allStateNodes]);
18250
+ }
18251
+ function isMachineSnapshot(value) {
18252
+ return !!value && typeof value === "object" && "machine" in value && "value" in value;
18253
+ }
18254
+ function createMachineSnapshot(config, machine) {
18255
+ return {
18256
+ status: config.status,
18257
+ output: config.output,
18258
+ error: config.error,
18259
+ machine,
18260
+ context: config.context,
18261
+ _nodes: config._nodes,
18262
+ value: getStateValue(machine.root, config._nodes),
18263
+ tags: new Set(config._nodes.flatMap((sn) => sn.tags)),
18264
+ children: config.children,
18265
+ historyValue: config.historyValue || {},
18266
+ matches: machineSnapshotMatches,
18267
+ hasTag: machineSnapshotHasTag,
18268
+ can: machineSnapshotCan,
18269
+ getMeta: machineSnapshotGetMeta,
18270
+ toJSON: machineSnapshotToJSON
18271
+ };
18272
+ }
18273
+ function cloneMachineSnapshot(snapshot, config = {}) {
18274
+ return createMachineSnapshot({
18275
+ ...snapshot,
18276
+ ...config
18277
+ }, snapshot.machine);
18278
+ }
18279
+ function serializeHistoryValue(historyValue) {
18280
+ if (typeof historyValue !== "object" || historyValue === null) {
18281
+ return {};
18282
+ }
18283
+ const result = {};
18284
+ for (const key in historyValue) {
18285
+ const value = historyValue[key];
18286
+ if (Array.isArray(value)) {
18287
+ result[key] = value.map((item) => ({
18288
+ id: item.id
18289
+ }));
18290
+ }
18291
+ }
18292
+ return result;
18293
+ }
18294
+ function getPersistedSnapshot(snapshot, options) {
18295
+ const {
18296
+ _nodes: nodes,
18297
+ tags,
18298
+ machine,
18299
+ children: children2,
18300
+ context,
18301
+ can: can2,
18302
+ hasTag: hasTag2,
18303
+ matches: matches2,
18304
+ getMeta: getMeta3,
18305
+ toJSON: toJSON2,
18306
+ ...jsonValues
18307
+ } = snapshot;
18308
+ const childrenJson = {};
18309
+ for (const id in children2) {
18310
+ const child2 = children2[id];
18311
+ childrenJson[id] = {
18312
+ snapshot: child2.getPersistedSnapshot(options),
18313
+ src: child2.src,
18314
+ systemId: child2.systemId,
18315
+ syncSnapshot: child2._syncSnapshot
18316
+ };
18317
+ }
18318
+ const persisted = {
18319
+ ...jsonValues,
18320
+ context: persistContext(context),
18321
+ children: childrenJson,
18322
+ historyValue: serializeHistoryValue(jsonValues.historyValue)
18323
+ };
18324
+ return persisted;
18325
+ }
18326
+ function persistContext(contextPart) {
18327
+ let copy;
18328
+ for (const key in contextPart) {
18329
+ const value = contextPart[key];
18330
+ if (value && typeof value === "object") {
18331
+ if ("sessionId" in value && "send" in value && "ref" in value) {
18332
+ copy ??= Array.isArray(contextPart) ? contextPart.slice() : {
18333
+ ...contextPart
18334
+ };
18335
+ copy[key] = {
18336
+ xstate$$type: $$ACTOR_TYPE,
18337
+ id: value.id
18338
+ };
18339
+ } else {
18340
+ const result = persistContext(value);
18341
+ if (result !== value) {
18342
+ copy ??= Array.isArray(contextPart) ? contextPart.slice() : {
18343
+ ...contextPart
18344
+ };
18345
+ copy[key] = result;
18346
+ }
18347
+ }
18348
+ }
18349
+ }
18350
+ return copy ?? contextPart;
18351
+ }
18352
+ function resolveRaise(_, snapshot, args, actionParams, {
18353
+ event: eventOrExpr,
18354
+ id,
18355
+ delay
18356
+ }, {
18357
+ internalQueue
18358
+ }) {
18359
+ const delaysMap = snapshot.machine.implementations.delays;
18360
+ if (typeof eventOrExpr === "string") {
18361
+ throw new Error(
18362
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
18363
+ `Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`
18364
+ );
18365
+ }
18366
+ const resolvedEvent = typeof eventOrExpr === "function" ? eventOrExpr(args, actionParams) : eventOrExpr;
18367
+ let resolvedDelay;
18368
+ if (typeof delay === "string") {
18369
+ const configDelay = delaysMap && delaysMap[delay];
18370
+ resolvedDelay = typeof configDelay === "function" ? configDelay(args, actionParams) : configDelay;
18371
+ } else {
18372
+ resolvedDelay = typeof delay === "function" ? delay(args, actionParams) : delay;
18373
+ }
18374
+ if (typeof resolvedDelay !== "number") {
18375
+ internalQueue.push(resolvedEvent);
18376
+ }
18377
+ return [snapshot, {
18378
+ event: resolvedEvent,
18379
+ id,
18380
+ delay: resolvedDelay
18381
+ }, void 0];
18382
+ }
18383
+ function executeRaise(actorScope, params) {
18384
+ const {
18385
+ event,
18386
+ delay,
18387
+ id
18388
+ } = params;
18389
+ if (typeof delay === "number") {
18390
+ actorScope.defer(() => {
18391
+ const self2 = actorScope.self;
18392
+ actorScope.system.scheduler.schedule(self2, self2, event, delay, id);
18393
+ });
18394
+ return;
18395
+ }
18396
+ }
18397
+ function raise(eventOrExpr, options) {
18398
+ function raise2(_args, _params) {
18399
+ }
18400
+ raise2.type = "xstate.raise";
18401
+ raise2.event = eventOrExpr;
18402
+ raise2.id = options?.id;
18403
+ raise2.delay = options?.delay;
18404
+ raise2.resolve = resolveRaise;
18405
+ raise2.execute = executeRaise;
18406
+ return raise2;
18407
+ }
18408
+ var Mailbox, STATE_DELIMITER, TARGETLESS_KEY, NULL_EVENT, STATE_IDENTIFIER, WILDCARD, XSTATE_INIT, XSTATE_ERROR, XSTATE_STOP, symbolObservable, idCounter, executingCustomAction, $$ACTOR_TYPE, ProcessingStatus, defaultOptions, Actor, isStateId, machineSnapshotMatches, machineSnapshotHasTag, machineSnapshotCan, machineSnapshotToJSON, machineSnapshotGetMeta;
18409
+ var init_raise_b47daa89_esm = __esm({
18410
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/raise-b47daa89.esm.js"() {
18411
+ "use strict";
18412
+ init_esm_shims();
18413
+ init_xstate_dev_esm();
18414
+ Mailbox = class {
18415
+ constructor(_process) {
18416
+ this._process = _process;
18417
+ this._active = false;
18418
+ this._current = null;
18419
+ this._last = null;
18420
+ }
18421
+ start() {
18422
+ this._active = true;
18423
+ this.flush();
18424
+ }
18425
+ clear() {
18426
+ if (this._current) {
18427
+ this._current.next = null;
18428
+ this._last = this._current;
18429
+ }
18430
+ }
18431
+ enqueue(event) {
18432
+ const enqueued = {
18433
+ value: event,
18434
+ next: null
18435
+ };
18436
+ if (this._current) {
18437
+ this._last.next = enqueued;
18438
+ this._last = enqueued;
18439
+ return;
18440
+ }
18441
+ this._current = enqueued;
18442
+ this._last = enqueued;
18443
+ if (this._active) {
18444
+ this.flush();
18445
+ }
18446
+ }
18447
+ flush() {
18448
+ while (this._current) {
18449
+ const consumed = this._current;
18450
+ this._process(consumed.value);
18451
+ this._current = consumed.next;
18452
+ }
18453
+ this._last = null;
18454
+ }
18455
+ };
18456
+ STATE_DELIMITER = ".";
18457
+ TARGETLESS_KEY = "";
18458
+ NULL_EVENT = "";
18459
+ STATE_IDENTIFIER = "#";
18460
+ WILDCARD = "*";
18461
+ XSTATE_INIT = "xstate.init";
18462
+ XSTATE_ERROR = "xstate.error";
18463
+ XSTATE_STOP = "xstate.stop";
18464
+ symbolObservable = (() => typeof Symbol === "function" && Symbol.observable || "@@observable")();
18465
+ idCounter = 0;
18466
+ executingCustomAction = false;
18467
+ $$ACTOR_TYPE = 1;
18468
+ ProcessingStatus = /* @__PURE__ */ (function(ProcessingStatus2) {
18469
+ ProcessingStatus2[ProcessingStatus2["NotStarted"] = 0] = "NotStarted";
18470
+ ProcessingStatus2[ProcessingStatus2["Running"] = 1] = "Running";
18471
+ ProcessingStatus2[ProcessingStatus2["Stopped"] = 2] = "Stopped";
18472
+ return ProcessingStatus2;
18473
+ })({});
18474
+ defaultOptions = {
18475
+ clock: {
18476
+ setTimeout: (fn, ms) => {
18477
+ return setTimeout(fn, ms);
18478
+ },
18479
+ clearTimeout: (id) => {
18480
+ return clearTimeout(id);
18481
+ }
18482
+ },
18483
+ logger: console.log.bind(console),
18484
+ devTools: false
18485
+ };
18486
+ Actor = class {
18487
+ /**
18488
+ * Creates a new actor instance for the given logic with the provided options,
18489
+ * if any.
18490
+ *
18491
+ * @param logic The logic to create an actor from
18492
+ * @param options Actor options
18493
+ */
18494
+ constructor(logic, options) {
18495
+ this.logic = logic;
18496
+ this._snapshot = void 0;
18497
+ this.clock = void 0;
18498
+ this.options = void 0;
18499
+ this.id = void 0;
18500
+ this.mailbox = new Mailbox(this._process.bind(this));
18501
+ this.observers = /* @__PURE__ */ new Set();
18502
+ this.eventListeners = /* @__PURE__ */ new Map();
18503
+ this.logger = void 0;
18504
+ this._processingStatus = ProcessingStatus.NotStarted;
18505
+ this._parent = void 0;
18506
+ this._syncSnapshot = void 0;
18507
+ this.ref = void 0;
18508
+ this._actorScope = void 0;
18509
+ this.systemId = void 0;
18510
+ this.sessionId = void 0;
18511
+ this.system = void 0;
18512
+ this._doneEvent = void 0;
18513
+ this.src = void 0;
18514
+ this._deferred = [];
18515
+ const resolvedOptions = {
18516
+ ...defaultOptions,
18517
+ ...options
18518
+ };
18519
+ const {
18520
+ clock,
18521
+ logger,
18522
+ parent,
18523
+ syncSnapshot,
18524
+ id,
18525
+ systemId,
18526
+ inspect
18527
+ } = resolvedOptions;
18528
+ this.system = parent ? parent.system : createSystem(this, {
18529
+ clock,
18530
+ logger
18531
+ });
18532
+ if (inspect && !parent) {
18533
+ this.system.inspect(toObserver(inspect));
18534
+ }
18535
+ this.sessionId = this.system._bookId();
18536
+ this.id = id ?? this.sessionId;
18537
+ this.logger = options?.logger ?? this.system._logger;
18538
+ this.clock = options?.clock ?? this.system._clock;
18539
+ this._parent = parent;
18540
+ this._syncSnapshot = syncSnapshot;
18541
+ this.options = resolvedOptions;
18542
+ this.src = resolvedOptions.src ?? logic;
18543
+ this.ref = this;
18544
+ this._actorScope = {
18545
+ self: this,
18546
+ id: this.id,
18547
+ sessionId: this.sessionId,
18548
+ logger: this.logger,
18549
+ defer: (fn) => {
18550
+ this._deferred.push(fn);
18551
+ },
18552
+ system: this.system,
18553
+ stopChild: (child2) => {
18554
+ if (child2._parent !== this) {
18555
+ throw new Error(`Cannot stop child actor ${child2.id} of ${this.id} because it is not a child`);
18556
+ }
18557
+ child2._stop();
18558
+ },
18559
+ emit: (emittedEvent) => {
18560
+ const listeners = this.eventListeners.get(emittedEvent.type);
18561
+ const wildcardListener = this.eventListeners.get("*");
18562
+ if (!listeners && !wildcardListener) {
18563
+ return;
18564
+ }
18565
+ const allListeners = [...listeners ? listeners.values() : [], ...wildcardListener ? wildcardListener.values() : []];
18566
+ for (const handler of allListeners) {
18567
+ try {
18568
+ handler(emittedEvent);
18569
+ } catch (err2) {
18570
+ reportUnhandledError(err2);
18571
+ }
18572
+ }
18573
+ },
18574
+ actionExecutor: (action) => {
18575
+ const exec = () => {
18576
+ this._actorScope.system._sendInspectionEvent({
18577
+ type: "@xstate.action",
18578
+ actorRef: this,
18579
+ action: {
18580
+ type: action.type,
18581
+ params: action.params
18582
+ }
18583
+ });
18584
+ if (!action.exec) {
18585
+ return;
18586
+ }
18587
+ const saveExecutingCustomAction = executingCustomAction;
18588
+ try {
18589
+ executingCustomAction = true;
18590
+ action.exec(action.info, action.params);
18591
+ } finally {
18592
+ executingCustomAction = saveExecutingCustomAction;
18593
+ }
18594
+ };
18595
+ if (this._processingStatus === ProcessingStatus.Running) {
18596
+ exec();
18597
+ } else {
18598
+ this._deferred.push(exec);
18599
+ }
18600
+ }
18601
+ };
18602
+ this.send = this.send.bind(this);
18603
+ this.system._sendInspectionEvent({
18604
+ type: "@xstate.actor",
18605
+ actorRef: this
18606
+ });
18607
+ if (systemId) {
18608
+ this.systemId = systemId;
18609
+ this.system._set(systemId, this);
18610
+ }
18611
+ this._initState(options?.snapshot ?? options?.state);
18612
+ if (systemId && this._snapshot.status !== "active") {
18613
+ this.system._unregister(this);
18614
+ }
18615
+ }
18616
+ _initState(persistedState) {
18617
+ try {
18618
+ this._snapshot = persistedState ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(persistedState, this._actorScope) : persistedState : this.logic.getInitialSnapshot(this._actorScope, this.options?.input);
18619
+ } catch (err2) {
18620
+ this._snapshot = {
18621
+ status: "error",
18622
+ output: void 0,
18623
+ error: err2
18624
+ };
18625
+ }
18626
+ }
18627
+ update(snapshot, event) {
18628
+ this._snapshot = snapshot;
18629
+ let deferredFn;
18630
+ while (deferredFn = this._deferred.shift()) {
18631
+ try {
18632
+ deferredFn();
18633
+ } catch (err2) {
18634
+ this._deferred.length = 0;
18635
+ this._snapshot = {
18636
+ ...snapshot,
18637
+ status: "error",
18638
+ error: err2
18639
+ };
18640
+ }
18641
+ }
18642
+ switch (this._snapshot.status) {
18643
+ case "active":
18644
+ for (const observer of this.observers) {
18645
+ try {
18646
+ observer.next?.(snapshot);
18647
+ } catch (err2) {
18648
+ reportUnhandledError(err2);
18649
+ }
18650
+ }
18651
+ break;
18652
+ case "done":
18653
+ for (const observer of this.observers) {
18654
+ try {
18655
+ observer.next?.(snapshot);
18656
+ } catch (err2) {
18657
+ reportUnhandledError(err2);
18658
+ }
18659
+ }
18660
+ this._stopProcedure();
18661
+ this._complete();
18662
+ this._doneEvent = createDoneActorEvent(this.id, this._snapshot.output);
18663
+ if (this._parent) {
18664
+ this.system._relay(this, this._parent, this._doneEvent);
18665
+ }
18666
+ break;
18667
+ case "error":
18668
+ this._error(this._snapshot.error);
18669
+ break;
18670
+ }
18671
+ this.system._sendInspectionEvent({
18672
+ type: "@xstate.snapshot",
18673
+ actorRef: this,
18674
+ event,
18675
+ snapshot
18676
+ });
18677
+ }
18678
+ /**
18679
+ * Subscribe an observer to an actor’s snapshot values.
18680
+ *
18681
+ * @remarks
18682
+ * The observer will receive the actor’s snapshot value when it is emitted.
18683
+ * The observer can be:
18684
+ *
18685
+ * - A plain function that receives the latest snapshot, or
18686
+ * - An observer object whose `.next(snapshot)` method receives the latest
18687
+ * snapshot
18688
+ *
18689
+ * @example
18690
+ *
18691
+ * ```ts
18692
+ * // Observer as a plain function
18693
+ * const subscription = actor.subscribe((snapshot) => {
18694
+ * console.log(snapshot);
18695
+ * });
18696
+ * ```
18697
+ *
18698
+ * @example
18699
+ *
18700
+ * ```ts
18701
+ * // Observer as an object
18702
+ * const subscription = actor.subscribe({
18703
+ * next(snapshot) {
18704
+ * console.log(snapshot);
18705
+ * },
18706
+ * error(err) {
18707
+ * // ...
18708
+ * },
18709
+ * complete() {
18710
+ * // ...
18711
+ * }
18712
+ * });
18713
+ * ```
18714
+ *
18715
+ * The return value of `actor.subscribe(observer)` is a subscription object
18716
+ * that has an `.unsubscribe()` method. You can call
18717
+ * `subscription.unsubscribe()` to unsubscribe the observer:
18718
+ *
18719
+ * @example
18720
+ *
18721
+ * ```ts
18722
+ * const subscription = actor.subscribe((snapshot) => {
18723
+ * // ...
18724
+ * });
18725
+ *
18726
+ * // Unsubscribe the observer
18727
+ * subscription.unsubscribe();
18728
+ * ```
18729
+ *
18730
+ * When the actor is stopped, all of its observers will automatically be
18731
+ * unsubscribed.
18732
+ *
18733
+ * @param observer - Either a plain function that receives the latest
18734
+ * snapshot, or an observer object whose `.next(snapshot)` method receives
18735
+ * the latest snapshot
18736
+ */
18737
+ subscribe(nextListenerOrObserver, errorListener, completeListener) {
18738
+ const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
18739
+ if (this._processingStatus !== ProcessingStatus.Stopped) {
18740
+ this.observers.add(observer);
18741
+ } else {
18742
+ switch (this._snapshot.status) {
18743
+ case "done":
18744
+ try {
18745
+ observer.complete?.();
18746
+ } catch (err2) {
18747
+ reportUnhandledError(err2);
18748
+ }
18749
+ break;
18750
+ case "error": {
18751
+ const err2 = this._snapshot.error;
18752
+ if (!observer.error) {
18753
+ reportUnhandledError(err2);
18754
+ } else {
18755
+ try {
18756
+ observer.error(err2);
18757
+ } catch (err3) {
18758
+ reportUnhandledError(err3);
18759
+ }
18760
+ }
18761
+ break;
18762
+ }
18763
+ }
18764
+ }
18765
+ return {
18766
+ unsubscribe: () => {
18767
+ this.observers.delete(observer);
18768
+ }
18769
+ };
18770
+ }
18771
+ on(type, handler) {
18772
+ let listeners = this.eventListeners.get(type);
18773
+ if (!listeners) {
18774
+ listeners = /* @__PURE__ */ new Set();
18775
+ this.eventListeners.set(type, listeners);
18776
+ }
18777
+ const wrappedHandler = handler.bind(void 0);
18778
+ listeners.add(wrappedHandler);
18779
+ return {
18780
+ unsubscribe: () => {
18781
+ listeners.delete(wrappedHandler);
18782
+ }
18783
+ };
18784
+ }
18785
+ select(selector, equalityFn = Object.is) {
18786
+ return {
18787
+ subscribe: (observerOrFn) => {
18788
+ const observer = toObserver(observerOrFn);
18789
+ const snapshot = this.getSnapshot();
18790
+ let previousSelected = selector(snapshot);
18791
+ return this.subscribe((snapshot2) => {
18792
+ const nextSelected = selector(snapshot2);
18793
+ if (!equalityFn(previousSelected, nextSelected)) {
18794
+ previousSelected = nextSelected;
18795
+ observer.next?.(nextSelected);
18796
+ }
18797
+ });
18798
+ },
18799
+ get: () => selector(this.getSnapshot())
18800
+ };
18801
+ }
18802
+ /** Starts the Actor from the initial state */
18803
+ start() {
18804
+ if (this._processingStatus === ProcessingStatus.Running) {
18805
+ return this;
18806
+ }
18807
+ if (this._syncSnapshot) {
18808
+ this.subscribe({
18809
+ next: (snapshot) => {
18810
+ if (snapshot.status === "active") {
18811
+ this.system._relay(this, this._parent, {
18812
+ type: `xstate.snapshot.${this.id}`,
18813
+ snapshot
18814
+ });
18815
+ }
18816
+ },
18817
+ error: () => {
18818
+ }
18819
+ });
18820
+ }
18821
+ this.system._register(this.sessionId, this);
18822
+ if (this.systemId) {
18823
+ this.system._set(this.systemId, this);
18824
+ }
18825
+ this._processingStatus = ProcessingStatus.Running;
18826
+ const initEvent = createInitEvent(this.options.input);
18827
+ this.system._sendInspectionEvent({
18828
+ type: "@xstate.event",
18829
+ sourceRef: this._parent,
18830
+ actorRef: this,
18831
+ event: initEvent
18832
+ });
18833
+ const status = this._snapshot.status;
18834
+ switch (status) {
18835
+ case "done":
18836
+ this.update(this._snapshot, initEvent);
18837
+ return this;
18838
+ case "error":
18839
+ this._error(this._snapshot.error);
18840
+ return this;
18841
+ }
18842
+ if (!this._parent) {
18843
+ this.system.start();
18844
+ }
18845
+ if (this.logic.start) {
18846
+ try {
18847
+ this.logic.start(this._snapshot, this._actorScope);
18848
+ } catch (err2) {
18849
+ this._snapshot = {
18850
+ ...this._snapshot,
18851
+ status: "error",
18852
+ error: err2
18853
+ };
18854
+ this._error(err2);
18855
+ return this;
18856
+ }
18857
+ }
18858
+ this.update(this._snapshot, initEvent);
18859
+ if (this.options.devTools) {
18860
+ this.attachDevTools();
18861
+ }
18862
+ this.mailbox.start();
18863
+ return this;
18864
+ }
18865
+ _process(event) {
18866
+ let nextState;
18867
+ let caughtError;
18868
+ try {
18869
+ nextState = this.logic.transition(this._snapshot, event, this._actorScope);
18870
+ } catch (err2) {
18871
+ caughtError = {
18872
+ err: err2
18873
+ };
18874
+ }
18875
+ if (caughtError) {
18876
+ const {
18877
+ err: err2
18878
+ } = caughtError;
18879
+ this._snapshot = {
18880
+ ...this._snapshot,
18881
+ status: "error",
18882
+ error: err2
18883
+ };
18884
+ this._error(err2);
18885
+ return;
18886
+ }
18887
+ this.update(nextState, event);
18888
+ if (event.type === XSTATE_STOP) {
18889
+ this._stopProcedure();
18890
+ this._complete();
18891
+ }
18892
+ }
18893
+ _stop() {
18894
+ if (this._processingStatus === ProcessingStatus.Stopped) {
18895
+ return this;
18896
+ }
18897
+ this.mailbox.clear();
18898
+ if (this._processingStatus === ProcessingStatus.NotStarted) {
18899
+ this._processingStatus = ProcessingStatus.Stopped;
18900
+ return this;
18901
+ }
18902
+ this.mailbox.enqueue({
18903
+ type: XSTATE_STOP
18904
+ });
18905
+ return this;
18906
+ }
18907
+ /** Stops the Actor and unsubscribe all listeners. */
18908
+ stop() {
18909
+ if (this._parent) {
18910
+ throw new Error("A non-root actor cannot be stopped directly.");
18911
+ }
18912
+ return this._stop();
18913
+ }
18914
+ _complete() {
18915
+ for (const observer of this.observers) {
18916
+ try {
18917
+ observer.complete?.();
18918
+ } catch (err2) {
18919
+ reportUnhandledError(err2);
18920
+ }
18921
+ }
18922
+ this.observers.clear();
18923
+ this.eventListeners.clear();
18924
+ }
18925
+ _reportError(err2) {
18926
+ if (!this.observers.size) {
18927
+ if (!this._parent) {
18928
+ reportUnhandledError(err2);
18929
+ }
18930
+ this.eventListeners.clear();
18931
+ return;
18932
+ }
18933
+ let reportError = false;
18934
+ for (const observer of this.observers) {
18935
+ const errorListener = observer.error;
18936
+ reportError ||= !errorListener;
18937
+ try {
18938
+ errorListener?.(err2);
18939
+ } catch (err22) {
18940
+ reportUnhandledError(err22);
18941
+ }
18942
+ }
18943
+ this.observers.clear();
18944
+ this.eventListeners.clear();
18945
+ if (reportError) {
18946
+ reportUnhandledError(err2);
18947
+ }
18948
+ }
18949
+ _error(err2) {
18950
+ this._stopProcedure();
18951
+ this._reportError(err2);
18952
+ if (this._parent) {
18953
+ this.system._relay(this, this._parent, createErrorActorEvent(this.id, err2));
18954
+ }
18955
+ }
18956
+ // TODO: atm children don't belong entirely to the actor so
18957
+ // in a way - it's not even super aware of them
18958
+ // so we can't stop them from here but we really should!
18959
+ // right now, they are being stopped within the machine's transition
18960
+ // but that could throw and leave us with "orphaned" active actors
18961
+ _stopProcedure() {
18962
+ if (this._processingStatus !== ProcessingStatus.Running) {
18963
+ return this;
18964
+ }
18965
+ this.system.scheduler.cancelAll(this);
18966
+ this.mailbox.clear();
18967
+ this.mailbox = new Mailbox(this._process.bind(this));
18968
+ this._processingStatus = ProcessingStatus.Stopped;
18969
+ this.system._unregister(this);
18970
+ return this;
18971
+ }
18972
+ /** @internal */
18973
+ _send(event) {
18974
+ if (this._processingStatus === ProcessingStatus.Stopped) {
18975
+ return;
18976
+ }
18977
+ this.mailbox.enqueue(event);
18978
+ }
18979
+ /**
18980
+ * Sends an event to the running Actor to trigger a transition.
18981
+ *
18982
+ * @param event The event to send
18983
+ */
18984
+ send(event) {
18985
+ this.system._relay(void 0, this, event);
18986
+ }
18987
+ attachDevTools() {
18988
+ const {
18989
+ devTools
18990
+ } = this.options;
18991
+ if (devTools) {
18992
+ const resolvedDevToolsAdapter = typeof devTools === "function" ? devTools : devToolsAdapter;
18993
+ resolvedDevToolsAdapter(this);
18994
+ }
18995
+ }
18996
+ toJSON() {
18997
+ return {
18998
+ xstate$$type: $$ACTOR_TYPE,
18999
+ id: this.id
19000
+ };
19001
+ }
19002
+ /**
19003
+ * Obtain the internal state of the actor, which can be persisted.
19004
+ *
19005
+ * @remarks
19006
+ * The internal state can be persisted from any actor, not only machines.
19007
+ *
19008
+ * Note that the persisted state is not the same as the snapshot from
19009
+ * {@link Actor.getSnapshot}. Persisted state represents the internal state of
19010
+ * the actor, while snapshots represent the actor's last emitted value.
19011
+ *
19012
+ * Can be restored with {@link ActorOptions.state}
19013
+ * @see https://stately.ai/docs/persistence
19014
+ */
19015
+ getPersistedSnapshot(options) {
19016
+ return this.logic.getPersistedSnapshot(this._snapshot, options);
19017
+ }
19018
+ [symbolObservable]() {
19019
+ return this;
19020
+ }
19021
+ /**
19022
+ * Read an actor’s snapshot synchronously.
19023
+ *
19024
+ * @remarks
19025
+ * The snapshot represent an actor's last emitted value.
19026
+ *
19027
+ * When an actor receives an event, its internal state may change. An actor
19028
+ * may emit a snapshot when a state transition occurs.
19029
+ *
19030
+ * Note that some actors, such as callback actors generated with
19031
+ * `fromCallback`, will not emit snapshots.
19032
+ * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
19033
+ * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
19034
+ */
19035
+ getSnapshot() {
19036
+ return this._snapshot;
19037
+ }
19038
+ };
19039
+ isStateId = (str) => str[0] === STATE_IDENTIFIER;
19040
+ machineSnapshotMatches = function matches(testValue) {
19041
+ return matchesState(testValue, this.value);
19042
+ };
19043
+ machineSnapshotHasTag = function hasTag(tag) {
19044
+ return this.tags.has(tag);
19045
+ };
19046
+ machineSnapshotCan = function can(event) {
19047
+ const transitionData = this.machine.getTransitionData(this, event);
19048
+ return !!transitionData?.length && // Check that at least one transition is not forbidden
19049
+ transitionData.some((t) => t.target !== void 0 || t.actions.length);
19050
+ };
19051
+ machineSnapshotToJSON = function toJSON() {
19052
+ const {
19053
+ _nodes: nodes,
19054
+ tags,
19055
+ machine,
19056
+ getMeta: getMeta3,
19057
+ toJSON: toJSON2,
19058
+ can: can2,
19059
+ hasTag: hasTag2,
19060
+ matches: matches2,
19061
+ ...jsonValues
19062
+ } = this;
19063
+ return {
19064
+ ...jsonValues,
19065
+ tags: Array.from(tags)
19066
+ };
19067
+ };
19068
+ machineSnapshotGetMeta = function getMeta2() {
19069
+ return this._nodes.reduce((acc, stateNode) => {
19070
+ if (stateNode.meta !== void 0) {
19071
+ acc[stateNode.id] = stateNode.meta;
19072
+ }
19073
+ return acc;
19074
+ }, {});
19075
+ };
19076
+ }
19077
+ });
19078
+
19079
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/actors/dist/xstate-actors.esm.js
19080
+ function fromTransition(transition, initialContext3) {
19081
+ return {
19082
+ config: transition,
19083
+ transition: (snapshot, event, actorScope) => {
19084
+ return {
19085
+ ...snapshot,
19086
+ context: transition(snapshot.context, event, actorScope)
19087
+ };
19088
+ },
19089
+ getInitialSnapshot: (_, input) => {
19090
+ return {
19091
+ status: "active",
19092
+ output: void 0,
19093
+ error: void 0,
19094
+ context: typeof initialContext3 === "function" ? initialContext3({
19095
+ input
19096
+ }) : initialContext3
19097
+ };
19098
+ },
19099
+ getPersistedSnapshot: (snapshot) => snapshot,
19100
+ restoreSnapshot: (snapshot) => snapshot
19101
+ };
19102
+ }
19103
+ function fromPromise(promiseCreator) {
19104
+ const logic = {
19105
+ config: promiseCreator,
19106
+ transition: (state, event, scope) => {
19107
+ if (state.status !== "active") {
19108
+ return state;
19109
+ }
19110
+ switch (event.type) {
19111
+ case XSTATE_PROMISE_RESOLVE: {
19112
+ const resolvedValue = event.data;
19113
+ return {
19114
+ ...state,
19115
+ status: "done",
19116
+ output: resolvedValue,
19117
+ input: void 0
19118
+ };
19119
+ }
19120
+ case XSTATE_PROMISE_REJECT:
19121
+ return {
19122
+ ...state,
19123
+ status: "error",
19124
+ error: event.data,
19125
+ input: void 0
19126
+ };
19127
+ case XSTATE_STOP: {
19128
+ controllerMap.get(scope.self)?.abort();
19129
+ controllerMap.delete(scope.self);
19130
+ return {
19131
+ ...state,
19132
+ status: "stopped",
19133
+ input: void 0
19134
+ };
19135
+ }
19136
+ default:
19137
+ return state;
19138
+ }
19139
+ },
19140
+ start: (state, {
19141
+ self: self2,
19142
+ system,
19143
+ emit: emit2
19144
+ }) => {
19145
+ if (state.status !== "active") {
19146
+ return;
19147
+ }
19148
+ const controller = new AbortController();
19149
+ controllerMap.set(self2, controller);
19150
+ const resolvedPromise = Promise.resolve(promiseCreator({
19151
+ input: state.input,
19152
+ system,
19153
+ self: self2,
19154
+ signal: controller.signal,
19155
+ emit: emit2
19156
+ }));
19157
+ resolvedPromise.then((response) => {
19158
+ if (self2.getSnapshot().status !== "active") {
19159
+ return;
19160
+ }
19161
+ controllerMap.delete(self2);
19162
+ system._relay(self2, self2, {
19163
+ type: XSTATE_PROMISE_RESOLVE,
19164
+ data: response
19165
+ });
19166
+ }, (errorData) => {
19167
+ if (self2.getSnapshot().status !== "active") {
19168
+ return;
19169
+ }
19170
+ controllerMap.delete(self2);
19171
+ system._relay(self2, self2, {
19172
+ type: XSTATE_PROMISE_REJECT,
19173
+ data: errorData
19174
+ });
19175
+ });
19176
+ },
19177
+ getInitialSnapshot: (_, input) => {
19178
+ return {
19179
+ status: "active",
19180
+ output: void 0,
19181
+ error: void 0,
19182
+ input
19183
+ };
19184
+ },
19185
+ getPersistedSnapshot: (snapshot) => snapshot,
19186
+ restoreSnapshot: (snapshot) => snapshot
19187
+ };
19188
+ return logic;
19189
+ }
19190
+ var XSTATE_PROMISE_RESOLVE, XSTATE_PROMISE_REJECT, controllerMap, emptyLogic;
19191
+ var init_xstate_actors_esm = __esm({
19192
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/actors/dist/xstate-actors.esm.js"() {
19193
+ "use strict";
19194
+ init_esm_shims();
19195
+ init_raise_b47daa89_esm();
19196
+ init_xstate_dev_esm();
19197
+ XSTATE_PROMISE_RESOLVE = "xstate.promise.resolve";
19198
+ XSTATE_PROMISE_REJECT = "xstate.promise.reject";
19199
+ controllerMap = /* @__PURE__ */ new WeakMap();
19200
+ emptyLogic = fromTransition((_) => void 0, void 0);
19201
+ }
19202
+ });
19203
+
19204
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/assign-128c3f01.esm.js
19205
+ function createSpawner(actorScope, {
19206
+ machine,
19207
+ context
19208
+ }, event, spawnedChildren) {
19209
+ const spawn = (src, options) => {
19210
+ if (typeof src === "string") {
19211
+ const logic = resolveReferencedActor(machine, src);
19212
+ if (!logic) {
19213
+ throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
19214
+ }
19215
+ const actorRef = createActor(logic, {
19216
+ id: options?.id,
19217
+ parent: actorScope.self,
19218
+ syncSnapshot: options?.syncSnapshot,
19219
+ input: typeof options?.input === "function" ? options.input({
19220
+ context,
19221
+ event,
19222
+ self: actorScope.self
19223
+ }) : options?.input,
19224
+ src,
19225
+ systemId: options?.systemId
19226
+ });
19227
+ spawnedChildren[actorRef.id] = actorRef;
19228
+ return actorRef;
19229
+ } else {
19230
+ const actorRef = createActor(src, {
19231
+ id: options?.id,
19232
+ parent: actorScope.self,
19233
+ syncSnapshot: options?.syncSnapshot,
19234
+ input: options?.input,
19235
+ src,
19236
+ systemId: options?.systemId
19237
+ });
19238
+ return actorRef;
19239
+ }
19240
+ };
19241
+ return (src, options) => {
19242
+ const actorRef = spawn(src, options);
19243
+ spawnedChildren[actorRef.id] = actorRef;
19244
+ actorScope.defer(() => {
19245
+ if (actorRef._processingStatus === ProcessingStatus.Stopped) {
19246
+ return;
19247
+ }
19248
+ actorRef.start();
19249
+ });
19250
+ return actorRef;
19251
+ };
19252
+ }
19253
+ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
19254
+ assignment
19255
+ }) {
19256
+ if (!snapshot.context) {
19257
+ throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
19258
+ }
19259
+ const spawnedChildren = {};
19260
+ const assignArgs = {
19261
+ context: snapshot.context,
19262
+ event: actionArgs.event,
19263
+ spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
19264
+ self: actorScope.self,
19265
+ system: actorScope.system
19266
+ };
19267
+ let partialUpdate = {};
19268
+ if (typeof assignment === "function") {
19269
+ partialUpdate = assignment(assignArgs, actionParams);
19270
+ } else {
19271
+ for (const key of Object.keys(assignment)) {
19272
+ const propAssignment = assignment[key];
19273
+ partialUpdate[key] = typeof propAssignment === "function" ? propAssignment(assignArgs, actionParams) : propAssignment;
19274
+ }
19275
+ }
19276
+ const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
19277
+ return [cloneMachineSnapshot(snapshot, {
19278
+ context: updatedContext,
19279
+ children: Object.keys(spawnedChildren).length ? {
19280
+ ...snapshot.children,
19281
+ ...spawnedChildren
19282
+ } : snapshot.children
19283
+ }), void 0, void 0];
19284
+ }
19285
+ function assign(assignment) {
19286
+ function assign2(_args, _params) {
19287
+ }
19288
+ assign2.type = "xstate.assign";
19289
+ assign2.assignment = assignment;
19290
+ assign2.resolve = resolveAssign;
19291
+ return assign2;
19292
+ }
19293
+ var init_assign_128c3f01_esm = __esm({
19294
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/assign-128c3f01.esm.js"() {
19295
+ "use strict";
19296
+ init_esm_shims();
19297
+ init_raise_b47daa89_esm();
19298
+ }
19299
+ });
19300
+
19301
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/StateMachine-bf2cec8d.esm.js
19302
+ function memo(object, key, fn) {
19303
+ let memoizedData = cache.get(object);
19304
+ if (!memoizedData) {
19305
+ memoizedData = {
19306
+ [key]: fn()
19307
+ };
19308
+ cache.set(object, memoizedData);
19309
+ } else if (!(key in memoizedData)) {
19310
+ memoizedData[key] = fn();
19311
+ }
19312
+ return memoizedData[key];
19313
+ }
19314
+ var cache, EMPTY_OBJECT, toSerializableAction, StateNode, STATE_IDENTIFIER2, StateMachine;
19315
+ var init_StateMachine_bf2cec8d_esm = __esm({
19316
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/StateMachine-bf2cec8d.esm.js"() {
19317
+ "use strict";
19318
+ init_esm_shims();
19319
+ init_raise_b47daa89_esm();
19320
+ init_assign_128c3f01_esm();
19321
+ cache = /* @__PURE__ */ new WeakMap();
19322
+ EMPTY_OBJECT = {};
19323
+ toSerializableAction = (action) => {
19324
+ if (typeof action === "string") {
19325
+ return {
19326
+ type: action
19327
+ };
19328
+ }
19329
+ if (typeof action === "function") {
19330
+ if ("resolve" in action) {
19331
+ return {
19332
+ type: action.type
19333
+ };
19334
+ }
19335
+ return {
19336
+ type: action.name
19337
+ };
19338
+ }
19339
+ return action;
19340
+ };
19341
+ StateNode = class _StateNode {
19342
+ constructor(config, options) {
19343
+ this.config = config;
19344
+ this.key = void 0;
19345
+ this.id = void 0;
19346
+ this.type = void 0;
19347
+ this.path = void 0;
19348
+ this.states = void 0;
19349
+ this.history = void 0;
19350
+ this.entry = void 0;
19351
+ this.exit = void 0;
19352
+ this.parent = void 0;
19353
+ this.machine = void 0;
19354
+ this.meta = void 0;
19355
+ this.output = void 0;
19356
+ this.order = -1;
19357
+ this.description = void 0;
19358
+ this.tags = [];
19359
+ this.transitions = void 0;
19360
+ this.always = void 0;
19361
+ this.parent = options._parent;
19362
+ this.key = options._key;
19363
+ this.machine = options._machine;
19364
+ this.path = this.parent ? this.parent.path.concat(this.key) : [];
19365
+ this.id = this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
19366
+ this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? "compound" : this.config.history ? "history" : "atomic");
19367
+ this.description = this.config.description;
19368
+ this.order = this.machine.idMap.size;
19369
+ this.machine.idMap.set(this.id, this);
19370
+ this.states = this.config.states ? mapValues(this.config.states, (stateConfig, key) => {
19371
+ const stateNode = new _StateNode(stateConfig, {
19372
+ _parent: this,
19373
+ _key: key,
19374
+ _machine: this.machine
19375
+ });
19376
+ return stateNode;
19377
+ }) : EMPTY_OBJECT;
19378
+ if (this.type === "compound" && !this.config.initial) {
19379
+ throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);
19380
+ }
19381
+ this.history = this.config.history === true ? "shallow" : this.config.history || false;
19382
+ this.entry = toArray(this.config.entry).slice();
19383
+ this.exit = toArray(this.config.exit).slice();
19384
+ this.meta = this.config.meta;
19385
+ this.output = this.type === "final" || !this.parent ? this.config.output : void 0;
19386
+ this.tags = toArray(config.tags).slice();
19387
+ }
19388
+ /** @internal */
19389
+ _initialize() {
19390
+ this.transitions = formatTransitions(this);
19391
+ if (this.config.always) {
19392
+ this.always = toTransitionConfigArray(this.config.always).map((t) => formatTransition(this, NULL_EVENT, t));
19393
+ }
19394
+ Object.keys(this.states).forEach((key) => {
19395
+ this.states[key]._initialize();
19396
+ });
19397
+ }
19398
+ /** The well-structured state node definition. */
19399
+ get definition() {
19400
+ return {
19401
+ id: this.id,
19402
+ key: this.key,
19403
+ version: this.machine.version,
19404
+ type: this.type,
19405
+ initial: this.initial ? {
19406
+ target: this.initial.target,
19407
+ source: this,
19408
+ actions: this.initial.actions.map(toSerializableAction),
19409
+ eventType: null,
19410
+ reenter: false,
19411
+ toJSON: () => ({
19412
+ target: this.initial.target.map((t) => `#${t.id}`),
19413
+ source: `#${this.id}`,
19414
+ actions: this.initial.actions.map(toSerializableAction),
19415
+ eventType: null
19416
+ })
19417
+ } : void 0,
19418
+ history: this.history,
19419
+ states: mapValues(this.states, (state) => {
19420
+ return state.definition;
19421
+ }),
19422
+ on: this.on,
19423
+ transitions: [...this.transitions.values()].flat().map((t) => ({
19424
+ ...t,
19425
+ actions: t.actions.map(toSerializableAction)
19426
+ })),
19427
+ entry: this.entry.map(toSerializableAction),
19428
+ exit: this.exit.map(toSerializableAction),
19429
+ meta: this.meta,
19430
+ order: this.order || -1,
19431
+ output: this.output,
19432
+ invoke: this.invoke,
19433
+ description: this.description,
19434
+ tags: this.tags
19435
+ };
19436
+ }
19437
+ /** @internal */
19438
+ toJSON() {
19439
+ return this.definition;
19440
+ }
19441
+ /** The logic invoked as actors by this state node. */
19442
+ get invoke() {
19443
+ return memo(this, "invoke", () => toArray(this.config.invoke).map((invokeConfig, i) => {
19444
+ const {
19445
+ src,
19446
+ systemId
19447
+ } = invokeConfig;
19448
+ const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
19449
+ const sourceName = typeof src === "string" ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
19450
+ return {
19451
+ ...invokeConfig,
19452
+ src: sourceName,
19453
+ id: resolvedId,
19454
+ systemId,
19455
+ toJSON() {
19456
+ const {
19457
+ onDone,
19458
+ onError,
19459
+ ...invokeDefValues
19460
+ } = invokeConfig;
19461
+ return {
19462
+ ...invokeDefValues,
19463
+ type: "xstate.invoke",
19464
+ src: sourceName,
19465
+ id: resolvedId
19466
+ };
19467
+ }
19468
+ };
19469
+ }));
19470
+ }
19471
+ /** The mapping of events to transitions. */
19472
+ get on() {
19473
+ return memo(this, "on", () => {
19474
+ const transitions = this.transitions;
19475
+ return [...transitions].flatMap(([descriptor, t]) => t.map((t2) => [descriptor, t2])).reduce((map, [descriptor, transition]) => {
19476
+ map[descriptor] = map[descriptor] || [];
19477
+ map[descriptor].push(transition);
19478
+ return map;
19479
+ }, {});
19480
+ });
19481
+ }
19482
+ get after() {
19483
+ return memo(this, "delayedTransitions", () => getDelayedTransitions(this));
19484
+ }
19485
+ get initial() {
19486
+ return memo(this, "initial", () => formatInitialTransition(this, this.config.initial));
19487
+ }
19488
+ /** @internal */
19489
+ next(snapshot, event) {
19490
+ const eventType = event.type;
19491
+ const actions = [];
19492
+ let selectedTransition;
19493
+ const candidates = memo(this, `candidates-${eventType}`, () => getCandidates(this, eventType));
19494
+ for (const candidate of candidates) {
19495
+ const {
19496
+ guard
19497
+ } = candidate;
19498
+ const resolvedContext = snapshot.context;
19499
+ let guardPassed = false;
19500
+ try {
19501
+ guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, snapshot);
19502
+ } catch (err2) {
19503
+ const guardType = typeof guard === "string" ? guard : typeof guard === "object" ? guard.type : void 0;
19504
+ throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ""}in transition for event '${eventType}' in state node '${this.id}':
19505
+ ${err2.message}`);
19506
+ }
19507
+ if (guardPassed) {
19508
+ actions.push(...candidate.actions);
19509
+ selectedTransition = candidate;
19510
+ break;
19511
+ }
19512
+ }
19513
+ return selectedTransition ? [selectedTransition] : void 0;
19514
+ }
19515
+ /** All the event types accepted by this state node and its descendants. */
19516
+ get events() {
19517
+ return memo(this, "events", () => {
19518
+ const {
19519
+ states
19520
+ } = this;
19521
+ const events = new Set(this.ownEvents);
19522
+ if (states) {
19523
+ for (const stateId of Object.keys(states)) {
19524
+ const state = states[stateId];
19525
+ if (state.states) {
19526
+ for (const event of state.events) {
19527
+ events.add(`${event}`);
19528
+ }
19529
+ }
19530
+ }
19531
+ }
19532
+ return Array.from(events);
19533
+ });
19534
+ }
19535
+ /**
19536
+ * All the events that have transitions directly from this state node.
19537
+ *
19538
+ * Excludes any inert events.
19539
+ */
19540
+ get ownEvents() {
19541
+ const keys = Object.keys(Object.fromEntries(this.transitions));
19542
+ const events = new Set(keys.filter((descriptor) => {
19543
+ return this.transitions.get(descriptor).some((transition) => !(!transition.target && !transition.actions.length && !transition.reenter));
19544
+ }));
19545
+ return Array.from(events);
19546
+ }
19547
+ };
19548
+ STATE_IDENTIFIER2 = "#";
19549
+ StateMachine = class _StateMachine {
19550
+ constructor(config, implementations) {
19551
+ this.config = config;
19552
+ this.version = void 0;
19553
+ this.schemas = void 0;
19554
+ this.implementations = void 0;
19555
+ this.__xstatenode = true;
19556
+ this.idMap = /* @__PURE__ */ new Map();
19557
+ this.root = void 0;
19558
+ this.id = void 0;
19559
+ this.states = void 0;
19560
+ this.events = void 0;
19561
+ this.id = config.id || "(machine)";
19562
+ this.implementations = {
19563
+ actors: implementations?.actors ?? {},
19564
+ actions: implementations?.actions ?? {},
19565
+ delays: implementations?.delays ?? {},
19566
+ guards: implementations?.guards ?? {}
19567
+ };
19568
+ this.version = this.config.version;
19569
+ this.schemas = this.config.schemas;
19570
+ this.transition = this.transition.bind(this);
19571
+ this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
19572
+ this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
19573
+ this.restoreSnapshot = this.restoreSnapshot.bind(this);
19574
+ this.start = this.start.bind(this);
19575
+ this.root = new StateNode(config, {
19576
+ _key: this.id,
19577
+ _machine: this
19578
+ });
19579
+ this.root._initialize();
19580
+ formatRouteTransitions(this.root);
19581
+ this.states = this.root.states;
19582
+ this.events = this.root.events;
19583
+ }
19584
+ /**
19585
+ * Clones this state machine with the provided implementations.
19586
+ *
19587
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`) to
19588
+ * recursively merge with the existing options.
19589
+ * @returns A new `StateMachine` instance with the provided implementations.
19590
+ */
19591
+ provide(implementations) {
19592
+ const {
19593
+ actions,
19594
+ guards,
19595
+ actors,
19596
+ delays
19597
+ } = this.implementations;
19598
+ return new _StateMachine(this.config, {
19599
+ actions: {
19600
+ ...actions,
19601
+ ...implementations.actions
19602
+ },
19603
+ guards: {
19604
+ ...guards,
19605
+ ...implementations.guards
19606
+ },
19607
+ actors: {
19608
+ ...actors,
19609
+ ...implementations.actors
19610
+ },
19611
+ delays: {
19612
+ ...delays,
19613
+ ...implementations.delays
19614
+ }
19615
+ });
19616
+ }
19617
+ resolveState(config) {
19618
+ const resolvedStateValue = resolveStateValue(this.root, config.value);
19619
+ const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
19620
+ return createMachineSnapshot({
19621
+ _nodes: [...nodeSet],
19622
+ context: config.context || {},
19623
+ children: {},
19624
+ status: isInFinalState(nodeSet, this.root) ? "done" : config.status || "active",
19625
+ output: config.output,
19626
+ error: config.error,
19627
+ historyValue: config.historyValue
19628
+ }, this);
19629
+ }
19630
+ /**
19631
+ * Determines the next snapshot given the current `snapshot` and received
19632
+ * `event`. Calculates a full macrostep from all microsteps.
19633
+ *
19634
+ * @param snapshot The current snapshot
19635
+ * @param event The received event
19636
+ */
19637
+ transition(snapshot, event, actorScope) {
19638
+ return macrostep(snapshot, event, actorScope, []).snapshot;
19639
+ }
19640
+ /**
19641
+ * Determines the next state given the current `state` and `event`. Calculates
19642
+ * a microstep.
19643
+ *
19644
+ * @param state The current state
19645
+ * @param event The received event
19646
+ */
19647
+ microstep(snapshot, event, actorScope) {
19648
+ return macrostep(snapshot, event, actorScope, []).microsteps.map(([s]) => s);
19649
+ }
19650
+ getTransitionData(snapshot, event) {
19651
+ return transitionNode(this.root, snapshot.value, snapshot, event) || [];
19652
+ }
19653
+ /**
19654
+ * The initial state _before_ evaluating any microsteps. This "pre-initial"
19655
+ * state is provided to initial actions executed in the initial state.
19656
+ *
19657
+ * @internal
19658
+ */
19659
+ _getPreInitialState(actorScope, initEvent, internalQueue) {
19660
+ const {
19661
+ context
19662
+ } = this.config;
19663
+ const preInitial = createMachineSnapshot({
19664
+ context: typeof context !== "function" && context ? context : {},
19665
+ _nodes: [this.root],
19666
+ children: {},
19667
+ status: "active"
19668
+ }, this);
19669
+ if (typeof context === "function") {
19670
+ const assignment = ({
19671
+ spawn,
19672
+ event,
19673
+ self: self2
19674
+ }) => context({
19675
+ spawn,
19676
+ input: event.input,
19677
+ self: self2
19678
+ });
19679
+ return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, void 0);
19680
+ }
19681
+ return preInitial;
19682
+ }
19683
+ /**
19684
+ * Returns the initial `State` instance, with reference to `self` as an
19685
+ * `ActorRef`.
19686
+ */
19687
+ getInitialSnapshot(actorScope, input) {
19688
+ const initEvent = createInitEvent(input);
19689
+ const internalQueue = [];
19690
+ const preInitialState = this._getPreInitialState(actorScope, initEvent, internalQueue);
19691
+ const [nextState] = initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
19692
+ const {
19693
+ snapshot: macroState
19694
+ } = macrostep(nextState, initEvent, actorScope, internalQueue);
19695
+ return macroState;
19696
+ }
19697
+ start(snapshot) {
19698
+ Object.values(snapshot.children).forEach((child2) => {
19699
+ if (child2.getSnapshot().status === "active") {
19700
+ child2.start();
19701
+ }
19702
+ });
19703
+ }
19704
+ getStateNodeById(stateId) {
19705
+ const fullPath = toStatePath(stateId);
19706
+ const relativePath = fullPath.slice(1);
19707
+ const resolvedStateId = isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER2.length) : fullPath[0];
19708
+ const stateNode = this.idMap.get(resolvedStateId);
19709
+ if (!stateNode) {
19710
+ throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
19711
+ }
19712
+ return getStateNodeByPath(stateNode, relativePath);
19713
+ }
19714
+ get definition() {
19715
+ return this.root.definition;
19716
+ }
19717
+ toJSON() {
19718
+ return this.definition;
19719
+ }
19720
+ getPersistedSnapshot(snapshot, options) {
19721
+ return getPersistedSnapshot(snapshot, options);
19722
+ }
19723
+ restoreSnapshot(snapshot, _actorScope) {
19724
+ const children2 = {};
19725
+ const snapshotChildren = snapshot.children;
19726
+ Object.keys(snapshotChildren).forEach((actorId) => {
19727
+ const actorData = snapshotChildren[actorId];
19728
+ const childState = actorData.snapshot;
19729
+ const src = actorData.src;
19730
+ const logic = typeof src === "string" ? resolveReferencedActor(this, src) : src;
19731
+ if (!logic) {
19732
+ return;
19733
+ }
19734
+ const actorRef = createActor(logic, {
19735
+ id: actorId,
19736
+ parent: _actorScope.self,
19737
+ syncSnapshot: actorData.syncSnapshot,
19738
+ snapshot: childState,
19739
+ src,
19740
+ systemId: actorData.systemId
19741
+ });
19742
+ children2[actorId] = actorRef;
19743
+ });
19744
+ function resolveHistoryReferencedState(root, referenced) {
19745
+ if (referenced instanceof StateNode) {
19746
+ return referenced;
19747
+ }
19748
+ try {
19749
+ return root.machine.getStateNodeById(referenced.id);
19750
+ } catch {
19751
+ }
19752
+ }
19753
+ function reviveHistoryValue(root, historyValue) {
19754
+ if (!historyValue || typeof historyValue !== "object") {
19755
+ return {};
19756
+ }
19757
+ const revived = {};
19758
+ for (const key in historyValue) {
19759
+ const arr = historyValue[key];
19760
+ for (const item of arr) {
19761
+ const resolved = resolveHistoryReferencedState(root, item);
19762
+ if (!resolved) {
19763
+ continue;
19764
+ }
19765
+ revived[key] ??= [];
19766
+ revived[key].push(resolved);
19767
+ }
19768
+ }
19769
+ return revived;
19770
+ }
19771
+ const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
19772
+ const restoredSnapshot = createMachineSnapshot({
19773
+ ...snapshot,
19774
+ children: children2,
19775
+ _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value))),
19776
+ historyValue: revivedHistoryValue
19777
+ }, this);
19778
+ const seen = /* @__PURE__ */ new Set();
19779
+ function reviveContext(contextPart, children3) {
19780
+ if (seen.has(contextPart)) {
19781
+ return;
19782
+ }
19783
+ seen.add(contextPart);
19784
+ for (const key in contextPart) {
19785
+ const value = contextPart[key];
19786
+ if (value && typeof value === "object") {
19787
+ if ("xstate$$type" in value && value.xstate$$type === $$ACTOR_TYPE) {
19788
+ contextPart[key] = children3[value.id];
19789
+ continue;
19790
+ }
19791
+ reviveContext(value, children3);
19792
+ }
19793
+ }
19794
+ }
19795
+ reviveContext(restoredSnapshot.context, children2);
19796
+ return restoredSnapshot;
19797
+ }
19798
+ };
19799
+ }
19800
+ });
19801
+
19802
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/log-678e6837.esm.js
19803
+ function resolveEmit(_, snapshot, args, actionParams, {
19804
+ event: eventOrExpr
19805
+ }) {
19806
+ const resolvedEvent = typeof eventOrExpr === "function" ? eventOrExpr(args, actionParams) : eventOrExpr;
19807
+ return [snapshot, {
19808
+ event: resolvedEvent
19809
+ }, void 0];
19810
+ }
19811
+ function executeEmit(actorScope, {
19812
+ event
19813
+ }) {
19814
+ actorScope.defer(() => actorScope.emit(event));
19815
+ }
19816
+ function emit(eventOrExpr) {
19817
+ function emit2(_args, _params) {
19818
+ }
19819
+ emit2.type = "xstate.emit";
19820
+ emit2.event = eventOrExpr;
19821
+ emit2.resolve = resolveEmit;
19822
+ emit2.execute = executeEmit;
19823
+ return emit2;
19824
+ }
19825
+ function resolveSendTo(actorScope, snapshot, args, actionParams, {
19826
+ to,
19827
+ event: eventOrExpr,
19828
+ id,
19829
+ delay
19830
+ }, extra) {
19831
+ const delaysMap = snapshot.machine.implementations.delays;
19832
+ if (typeof eventOrExpr === "string") {
19833
+ throw new Error(
19834
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
19835
+ `Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`
19836
+ );
19837
+ }
19838
+ const resolvedEvent = typeof eventOrExpr === "function" ? eventOrExpr(args, actionParams) : eventOrExpr;
19839
+ let resolvedDelay;
19840
+ if (typeof delay === "string") {
19841
+ const configDelay = delaysMap && delaysMap[delay];
19842
+ resolvedDelay = typeof configDelay === "function" ? configDelay(args, actionParams) : configDelay;
19843
+ } else {
19844
+ resolvedDelay = typeof delay === "function" ? delay(args, actionParams) : delay;
19845
+ }
19846
+ const resolvedTarget = typeof to === "function" ? to(args, actionParams) : to;
19847
+ let targetActorRef;
19848
+ if (typeof resolvedTarget === "string") {
19849
+ if (resolvedTarget === SpecialTargets.Parent) {
19850
+ targetActorRef = actorScope.self._parent;
19851
+ } else if (resolvedTarget === SpecialTargets.Internal) {
19852
+ targetActorRef = actorScope.self;
19853
+ } else if (resolvedTarget.startsWith("#_")) {
19854
+ targetActorRef = snapshot.children[resolvedTarget.slice(2)];
19855
+ } else {
19856
+ targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
19857
+ }
19858
+ if (!targetActorRef) {
19859
+ throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
19860
+ }
19861
+ } else {
19862
+ targetActorRef = resolvedTarget || actorScope.self;
19863
+ }
19864
+ return [snapshot, {
19865
+ to: targetActorRef,
19866
+ targetId: typeof resolvedTarget === "string" ? resolvedTarget : void 0,
19867
+ event: resolvedEvent,
19868
+ id,
19869
+ delay: resolvedDelay
19870
+ }, void 0];
19871
+ }
19872
+ function retryResolveSendTo(_, snapshot, params) {
19873
+ if (typeof params.to === "string") {
19874
+ params.to = snapshot.children[params.to];
19875
+ }
19876
+ }
19877
+ function executeSendTo(actorScope, params) {
19878
+ actorScope.defer(() => {
19879
+ const {
19880
+ to,
19881
+ event,
19882
+ delay,
19883
+ id
19884
+ } = params;
19885
+ if (typeof delay === "number") {
19886
+ actorScope.system.scheduler.schedule(actorScope.self, to, event, delay, id);
19887
+ return;
19888
+ }
19889
+ actorScope.system._relay(
19890
+ actorScope.self,
19891
+ // at this point, in a deferred task, it should already be mutated by retryResolveSendTo
19892
+ // if it initially started as a string
19893
+ to,
19894
+ event.type === XSTATE_ERROR ? createErrorActorEvent(actorScope.self.id, event.data) : event
19895
+ );
19896
+ });
19897
+ }
19898
+ function sendTo(to, eventOrExpr, options) {
19899
+ function sendTo2(_args, _params) {
19900
+ }
19901
+ sendTo2.type = "xstate.sendTo";
19902
+ sendTo2.to = to;
19903
+ sendTo2.event = eventOrExpr;
19904
+ sendTo2.id = options?.id;
19905
+ sendTo2.delay = options?.delay;
19906
+ sendTo2.resolve = resolveSendTo;
19907
+ sendTo2.retryResolve = retryResolveSendTo;
19908
+ sendTo2.execute = executeSendTo;
19909
+ return sendTo2;
19910
+ }
19911
+ function sendParent(event, options) {
19912
+ return sendTo(SpecialTargets.Parent, event, options);
19913
+ }
19914
+ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
19915
+ collect
19916
+ }) {
19917
+ const actions = [];
19918
+ const enqueue = function enqueue2(action) {
19919
+ actions.push(action);
19920
+ };
19921
+ enqueue.assign = (...args2) => {
19922
+ actions.push(assign(...args2));
19923
+ };
19924
+ enqueue.cancel = (...args2) => {
19925
+ actions.push(cancel(...args2));
19926
+ };
19927
+ enqueue.raise = (...args2) => {
19928
+ actions.push(raise(...args2));
19929
+ };
19930
+ enqueue.sendTo = (...args2) => {
19931
+ actions.push(sendTo(...args2));
19932
+ };
19933
+ enqueue.sendParent = (...args2) => {
19934
+ actions.push(sendParent(...args2));
19935
+ };
19936
+ enqueue.spawnChild = (...args2) => {
19937
+ actions.push(spawnChild(...args2));
19938
+ };
19939
+ enqueue.stopChild = (...args2) => {
19940
+ actions.push(stopChild(...args2));
19941
+ };
19942
+ enqueue.emit = (...args2) => {
19943
+ actions.push(emit(...args2));
19944
+ };
19945
+ collect({
19946
+ context: args.context,
19947
+ event: args.event,
19948
+ enqueue,
19949
+ check: (guard) => evaluateGuard(guard, snapshot.context, args.event, snapshot),
19950
+ self: actorScope.self,
19951
+ system: actorScope.system
19952
+ }, actionParams);
19953
+ return [snapshot, void 0, actions];
19954
+ }
19955
+ function enqueueActions(collect) {
19956
+ function enqueueActions2(_args, _params) {
19957
+ }
19958
+ enqueueActions2.type = "xstate.enqueueActions";
19959
+ enqueueActions2.collect = collect;
19960
+ enqueueActions2.resolve = resolveEnqueueActions;
19961
+ return enqueueActions2;
19962
+ }
19963
+ function resolveLog(_, snapshot, actionArgs, actionParams, {
19964
+ value,
19965
+ label
19966
+ }) {
19967
+ return [snapshot, {
19968
+ value: typeof value === "function" ? value(actionArgs, actionParams) : value,
19969
+ label
19970
+ }, void 0];
19971
+ }
19972
+ function executeLog({
19973
+ logger
19974
+ }, {
19975
+ value,
19976
+ label
19977
+ }) {
19978
+ if (label) {
19979
+ logger(label, value);
19980
+ } else {
19981
+ logger(value);
19982
+ }
19983
+ }
19984
+ function log(value = ({
19985
+ context,
19986
+ event
19987
+ }) => ({
19988
+ context,
19989
+ event
19990
+ }), label) {
19991
+ function log2(_args, _params) {
19992
+ }
19993
+ log2.type = "xstate.log";
19994
+ log2.value = value;
19995
+ log2.label = label;
19996
+ log2.resolve = resolveLog;
19997
+ log2.execute = executeLog;
19998
+ return log2;
19999
+ }
20000
+ var SpecialTargets;
20001
+ var init_log_678e6837_esm = __esm({
20002
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/log-678e6837.esm.js"() {
20003
+ "use strict";
20004
+ init_esm_shims();
20005
+ init_raise_b47daa89_esm();
20006
+ init_assign_128c3f01_esm();
20007
+ SpecialTargets = /* @__PURE__ */ (function(SpecialTargets2) {
20008
+ SpecialTargets2["Parent"] = "#_parent";
20009
+ SpecialTargets2["Internal"] = "#_internal";
20010
+ return SpecialTargets2;
20011
+ })({});
20012
+ }
20013
+ });
20014
+
20015
+ // ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/xstate.esm.js
20016
+ function createMachine(config, implementations) {
20017
+ return new StateMachine(config, implementations);
20018
+ }
20019
+ function setup({
20020
+ schemas,
20021
+ actors,
20022
+ actions,
20023
+ guards,
20024
+ delays
20025
+ }) {
20026
+ return {
20027
+ assign,
20028
+ sendTo,
20029
+ raise,
20030
+ log,
20031
+ cancel,
20032
+ stopChild,
20033
+ enqueueActions,
20034
+ emit,
20035
+ spawnChild,
20036
+ createStateConfig: (config) => config,
20037
+ createAction: (fn) => fn,
20038
+ createMachine: (config) => createMachine({
20039
+ ...config,
20040
+ schemas
20041
+ }, {
20042
+ actors,
20043
+ actions,
20044
+ guards,
20045
+ delays
20046
+ }),
20047
+ extend: (extended) => setup({
20048
+ schemas,
20049
+ actors,
20050
+ actions: {
20051
+ ...actions,
20052
+ ...extended.actions
20053
+ },
20054
+ guards: {
20055
+ ...guards,
20056
+ ...extended.guards
20057
+ },
20058
+ delays: {
20059
+ ...delays,
20060
+ ...extended.delays
20061
+ }
20062
+ })
20063
+ };
20064
+ }
20065
+ var init_xstate_esm = __esm({
20066
+ "../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/xstate.esm.js"() {
20067
+ "use strict";
20068
+ init_esm_shims();
20069
+ init_xstate_actors_esm();
20070
+ init_raise_b47daa89_esm();
20071
+ init_raise_b47daa89_esm();
20072
+ init_StateMachine_bf2cec8d_esm();
20073
+ init_assign_128c3f01_esm();
20074
+ init_assign_128c3f01_esm();
20075
+ init_log_678e6837_esm();
20076
+ init_xstate_dev_esm();
20077
+ }
20078
+ });
20079
+
16753
20080
  // ../../kernel/src/document/document-lifecycle-machine.ts
16754
- import { assign, fromPromise, setup } from "xstate";
16755
20081
  var initialContext, documentLifecycleMachine, documentLifecycleSelectors;
16756
20082
  var init_document_lifecycle_machine = __esm({
16757
20083
  "../../kernel/src/document/document-lifecycle-machine.ts"() {
16758
20084
  "use strict";
16759
20085
  init_esm_shims();
20086
+ init_xstate_esm();
16760
20087
  init_errors();
16761
20088
  initialContext = {
16762
20089
  docId: "",
@@ -17878,8 +21205,8 @@ function setSlicerSelection(slicer, values) {
17878
21205
  function clearSlicerSelection(slicer) {
17879
21206
  return getWasm().table_clear_slicer_selection(slicer);
17880
21207
  }
17881
- function selectAllSlicerValues(slicer, cache) {
17882
- return getWasm().table_select_all_slicer_values(slicer, cache);
21208
+ function selectAllSlicerValues(slicer, cache2) {
21209
+ return getWasm().table_select_all_slicer_values(slicer, cache2);
17883
21210
  }
17884
21211
  function slicerToFilterCriteria(slicer) {
17885
21212
  return getWasm().table_slicer_to_filter_criteria(slicer);
@@ -70042,7 +73369,6 @@ var init_wordart_bridge = __esm({
70042
73369
  });
70043
73370
 
70044
73371
  // ../../kernel/src/services/clipboard/clipboard-service.ts
70045
- import { assign as assign2, createActor, setup as setup2 } from "xstate";
70046
73372
  function getClipboardServiceSnapshot(state) {
70047
73373
  let clipboardState = "empty";
70048
73374
  if (state.matches("hasCopy")) clipboardState = "hasCopy";
@@ -70064,6 +73390,7 @@ var init_clipboard_service = __esm({
70064
73390
  "../../kernel/src/services/clipboard/clipboard-service.ts"() {
70065
73391
  "use strict";
70066
73392
  init_esm_shims();
73393
+ init_xstate_esm();
70067
73394
  init_primitives3();
70068
73395
  initialContext2 = {
70069
73396
  payload: null,
@@ -70072,13 +73399,13 @@ var init_clipboard_service = __esm({
70072
73399
  timestamp: null,
70073
73400
  error: null
70074
73401
  };
70075
- clipboardServiceMachine = setup2({
73402
+ clipboardServiceMachine = setup({
70076
73403
  types: {
70077
73404
  context: {},
70078
73405
  events: {}
70079
73406
  },
70080
73407
  actions: {
70081
- storeCopyData: assign2(({ event }) => {
73408
+ storeCopyData: assign(({ event }) => {
70082
73409
  if (event.type !== "COPY") return {};
70083
73410
  return {
70084
73411
  payload: event.payload,
@@ -70088,7 +73415,7 @@ var init_clipboard_service = __esm({
70088
73415
  error: null
70089
73416
  };
70090
73417
  }),
70091
- storeCutData: assign2(({ event }) => {
73418
+ storeCutData: assign(({ event }) => {
70092
73419
  if (event.type !== "CUT") return {};
70093
73420
  return {
70094
73421
  payload: event.payload,
@@ -70098,33 +73425,33 @@ var init_clipboard_service = __esm({
70098
73425
  error: null
70099
73426
  };
70100
73427
  }),
70101
- clearAfterCut: assign2(() => ({
73428
+ clearAfterCut: assign(() => ({
70102
73429
  payload: null,
70103
73430
  operation: null,
70104
73431
  isStale: false,
70105
73432
  timestamp: null,
70106
73433
  error: null
70107
73434
  })),
70108
- clearAll: assign2(() => ({
73435
+ clearAll: assign(() => ({
70109
73436
  payload: null,
70110
73437
  operation: null,
70111
73438
  isStale: false,
70112
73439
  timestamp: null,
70113
73440
  error: null
70114
73441
  })),
70115
- storeError: assign2(({ event }) => {
73442
+ storeError: assign(({ event }) => {
70116
73443
  if (event.type !== "PASTE_ERROR") return {};
70117
73444
  return {
70118
73445
  error: event.message
70119
73446
  };
70120
73447
  }),
70121
- clearError: assign2(() => ({
73448
+ clearError: assign(() => ({
70122
73449
  error: null
70123
73450
  })),
70124
- markStale: assign2(() => ({
73451
+ markStale: assign(() => ({
70125
73452
  isStale: true
70126
73453
  })),
70127
- markFresh: assign2(() => ({
73454
+ markFresh: assign(() => ({
70128
73455
  isStale: false
70129
73456
  }))
70130
73457
  },
@@ -72711,12 +76038,12 @@ var init_kernel_context = __esm({
72711
76038
  });
72712
76039
 
72713
76040
  // ../../kernel/src/document/document-lifecycle-system.ts
72714
- import { createActor as createActor2, fromPromise as fromPromise2 } from "xstate";
72715
76041
  var DeferredContext, DocumentLifecycleSystem;
72716
76042
  var init_document_lifecycle_system = __esm({
72717
76043
  "../../kernel/src/document/document-lifecycle-system.ts"() {
72718
76044
  "use strict";
72719
76045
  init_esm_shims();
76046
+ init_xstate_esm();
72720
76047
  init_document();
72721
76048
  init_document_lifecycle_machine();
72722
76049
  DeferredContext = new Proxy({}, {
@@ -72743,24 +76070,24 @@ var init_document_lifecycle_system = __esm({
72743
76070
  this.napiAddon = config?.napiAddon;
72744
76071
  const machineWithActors = documentLifecycleMachine.provide({
72745
76072
  actors: {
72746
- createEngine: fromPromise2(
76073
+ createEngine: fromPromise(
72747
76074
  async ({ input }) => this.executeCreateEngine(input)
72748
76075
  ),
72749
- wireContext: fromPromise2(
76076
+ wireContext: fromPromise(
72750
76077
  async ({ input }) => this.executeWireContext(input)
72751
76078
  ),
72752
- startBridge: fromPromise2(
76079
+ startBridge: fromPromise(
72753
76080
  async ({ input }) => this.executeStartBridge(input)
72754
76081
  ),
72755
- hydrateXlsx: fromPromise2(
76082
+ hydrateXlsx: fromPromise(
72756
76083
  async ({ input }) => this.executeHydrateXlsx(input)
72757
76084
  ),
72758
- disposeBridge: fromPromise2(
76085
+ disposeBridge: fromPromise(
72759
76086
  async ({ input }) => this.executeDisposeBridge(input)
72760
76087
  )
72761
76088
  }
72762
76089
  });
72763
- this.actor = createActor2(machineWithActors, {
76090
+ this.actor = createActor(machineWithActors, {
72764
76091
  inspect: (evt) => {
72765
76092
  if (typeof window !== "undefined")
72766
76093
  window.__OS_DEVTOOLS__?.reportActor("documentLifecycle", evt);
@@ -83548,18 +86875,18 @@ var WorksheetImpl = class {
83548
86875
  // ===========================================================================
83549
86876
  get cellMetadata() {
83550
86877
  if (!this._cellMetadata) {
83551
- const cache = createCellMetadataCache(this.workbook);
83552
- this._rawCellMetadataCache = cache;
83553
- this.ctx.computeBridge.setCellMetadataCache(cache);
86878
+ const cache2 = createCellMetadataCache(this.workbook);
86879
+ this._rawCellMetadataCache = cache2;
86880
+ this.ctx.computeBridge.setCellMetadataCache(cache2);
83554
86881
  this._cellMetadata = {
83555
- isProjectedPosition: (row, col) => cache.isProjectedPosition(row, col),
83556
- getProjectionSourcePosition: (row, col) => cache.getProjectionSourcePosition(row, col),
83557
- getProjectionRange: (row, col) => cache.getProjectionRange(row, col),
83558
- hasValidationErrors: (row, col) => cache.hasValidationErrors(row, col),
83559
- evaluateViewport: (sheetId, startRow, startCol, endRow, endCol) => cache.evaluateViewport(sheetId, startRow, startCol, endRow, endCol),
83560
- onChange: (callback) => cache.onChange(callback),
83561
- clear: () => cache.clear(),
83562
- destroy: () => cache.dispose()
86882
+ isProjectedPosition: (row, col) => cache2.isProjectedPosition(row, col),
86883
+ getProjectionSourcePosition: (row, col) => cache2.getProjectionSourcePosition(row, col),
86884
+ getProjectionRange: (row, col) => cache2.getProjectionRange(row, col),
86885
+ hasValidationErrors: (row, col) => cache2.hasValidationErrors(row, col),
86886
+ evaluateViewport: (sheetId, startRow, startCol, endRow, endCol) => cache2.evaluateViewport(sheetId, startRow, startCol, endRow, endCol),
86887
+ onChange: (callback) => cache2.onChange(callback),
86888
+ clear: () => cache2.clear(),
86889
+ destroy: () => cache2.dispose()
83563
86890
  };
83564
86891
  }
83565
86892
  return this._cellMetadata;
@@ -83727,8 +87054,8 @@ var WorkbookSheetsImpl = class {
83727
87054
  return new WorksheetImpl(newSheetId, ctx, workbook, resolvedName);
83728
87055
  }
83729
87056
  async remove(target) {
83730
- const { ctx, resolveTarget } = this.deps;
83731
- const sheetId = await resolveTarget(target);
87057
+ const { ctx, resolveTarget: resolveTarget2 } = this.deps;
87058
+ const sheetId = await resolveTarget2(target);
83732
87059
  const deleted = await removeSheet(ctx, sheetId);
83733
87060
  if (!deleted) {
83734
87061
  throw new KernelError(
@@ -83738,31 +87065,31 @@ var WorkbookSheetsImpl = class {
83738
87065
  }
83739
87066
  }
83740
87067
  async move(name, toIndex) {
83741
- const { ctx, resolveTarget } = this.deps;
83742
- const sheetId = await resolveTarget(name);
87068
+ const { ctx, resolveTarget: resolveTarget2 } = this.deps;
87069
+ const sheetId = await resolveTarget2(name);
83743
87070
  const moved = await moveSheet(ctx, sheetId, toIndex);
83744
87071
  if (!moved) {
83745
87072
  throw new KernelError("COMPUTE_ERROR", `Failed to move sheet "${name}" to index ${toIndex}.`);
83746
87073
  }
83747
87074
  }
83748
87075
  async rename(target, newName) {
83749
- const { ctx, resolveTarget, workbook } = this.deps;
83750
- const sheetId = await resolveTarget(target);
87076
+ const { ctx, resolveTarget: resolveTarget2, workbook } = this.deps;
87077
+ const sheetId = await resolveTarget2(target);
83751
87078
  await assertNameNotTaken(ctx, newName, sheetId);
83752
87079
  await renameSheet(ctx, sheetId, newName);
83753
87080
  await workbook.refreshSheetMetadata();
83754
87081
  }
83755
87082
  async setActive(target) {
83756
- const { resolveTarget, setActiveSheetId, getSheetName, workbook } = this.deps;
83757
- const sheetId = await resolveTarget(target);
87083
+ const { resolveTarget: resolveTarget2, setActiveSheetId, getSheetName, workbook } = this.deps;
87084
+ const sheetId = await resolveTarget2(target);
83758
87085
  const name = await getSheetName(sheetId);
83759
87086
  workbook._getOrCreateWorksheet(sheetId, name);
83760
87087
  setActiveSheetId(sheetId);
83761
87088
  await workbook.refreshSheetMetadata();
83762
87089
  }
83763
87090
  async copy(source, newName) {
83764
- const { ctx, resolveTarget, getSheetName, workbook } = this.deps;
83765
- const sourceId = await resolveTarget(source);
87091
+ const { ctx, resolveTarget: resolveTarget2, getSheetName, workbook } = this.deps;
87092
+ const sourceId = await resolveTarget2(source);
83766
87093
  const sourceName = await getSheetName(sourceId);
83767
87094
  const copyName = newName ?? `${sourceName ?? "Sheet"} (Copy)`;
83768
87095
  const newSheetId = await copySheet(ctx, sourceId, copyName);
@@ -83772,8 +87099,8 @@ var WorkbookSheetsImpl = class {
83772
87099
  return new WorksheetImpl(newSheetId, ctx, workbook, copyName);
83773
87100
  }
83774
87101
  async hide(target) {
83775
- const { ctx, resolveTarget, workbook } = this.deps;
83776
- const sheetId = await resolveTarget(target);
87102
+ const { ctx, resolveTarget: resolveTarget2, workbook } = this.deps;
87103
+ const sheetId = await resolveTarget2(target);
83777
87104
  const success = await setSheetHidden(ctx, sheetId, true);
83778
87105
  if (!success) {
83779
87106
  throw new KernelError(
@@ -83784,8 +87111,8 @@ var WorkbookSheetsImpl = class {
83784
87111
  await workbook.refreshSheetMetadata();
83785
87112
  }
83786
87113
  async show(target) {
83787
- const { ctx, resolveTarget, workbook } = this.deps;
83788
- const sheetId = await resolveTarget(target);
87114
+ const { ctx, resolveTarget: resolveTarget2, workbook } = this.deps;
87115
+ const sheetId = await resolveTarget2(target);
83789
87116
  const success = await setSheetHidden(ctx, sheetId, false);
83790
87117
  if (!success) {
83791
87118
  throw new KernelError("COMPUTE_ERROR", `Failed to show sheet.`);