@doeixd/machine 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +48 -0
  2. package/dist/cjs/development/core.js.map +1 -1
  3. package/dist/cjs/development/delegate.js +89 -0
  4. package/dist/cjs/development/delegate.js.map +7 -0
  5. package/dist/cjs/development/index.js +383 -158
  6. package/dist/cjs/development/index.js.map +4 -4
  7. package/dist/cjs/development/minimal.js +172 -0
  8. package/dist/cjs/development/minimal.js.map +7 -0
  9. package/dist/cjs/development/react.js.map +1 -1
  10. package/dist/cjs/production/delegate.js +1 -0
  11. package/dist/cjs/production/index.js +3 -3
  12. package/dist/cjs/production/minimal.js +1 -0
  13. package/dist/esm/development/core.js.map +1 -1
  14. package/dist/esm/development/delegate.js +68 -0
  15. package/dist/esm/development/delegate.js.map +7 -0
  16. package/dist/esm/development/index.js +389 -158
  17. package/dist/esm/development/index.js.map +4 -4
  18. package/dist/esm/development/minimal.js +149 -0
  19. package/dist/esm/development/minimal.js.map +7 -0
  20. package/dist/esm/development/react.js.map +1 -1
  21. package/dist/esm/production/delegate.js +1 -0
  22. package/dist/esm/production/index.js +3 -3
  23. package/dist/esm/production/minimal.js +1 -0
  24. package/dist/types/delegate.d.ts +101 -0
  25. package/dist/types/delegate.d.ts.map +1 -0
  26. package/dist/types/index.d.ts +3 -0
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/minimal.d.ts +95 -0
  29. package/dist/types/minimal.d.ts.map +1 -0
  30. package/dist/types/types.d.ts +110 -0
  31. package/dist/types/types.d.ts.map +1 -0
  32. package/package.json +25 -1
  33. package/src/delegate.ts +267 -0
  34. package/src/index.ts +13 -0
  35. package/src/middleware.ts +1049 -1050
  36. package/src/minimal.ts +269 -0
  37. package/src/types.ts +129 -0
@@ -67,11 +67,13 @@ __export(src_exports, {
67
67
  createTransitionExtender: () => createTransitionExtender,
68
68
  createTransitionFactory: () => createTransitionFactory,
69
69
  customCase: () => customCase,
70
+ delegate: () => delegate_exports,
70
71
  delegateToChild: () => delegateToChild,
71
72
  describe: () => describe,
72
73
  discriminantCase: () => discriminantCase,
73
74
  extendTransitions: () => extendTransitions,
74
75
  forContext: () => forContext,
76
+ freeze: () => freeze,
75
77
  fromObservable: () => fromObservable,
76
78
  fromPromise: () => fromPromise,
77
79
  guard: () => guard,
@@ -98,6 +100,7 @@ __export(src_exports, {
98
100
  mergeContext: () => mergeContext,
99
101
  metadata: () => metadata,
100
102
  middlewareBuilder: () => middlewareBuilder,
103
+ minimal: () => minimal_exports,
101
104
  next: () => next,
102
105
  overrideTransitions: () => overrideTransitions,
103
106
  pipeTransitions: () => pipeTransitions,
@@ -113,6 +116,7 @@ __export(src_exports, {
113
116
  state: () => state,
114
117
  step: () => step,
115
118
  stepAsync: () => stepAsync,
119
+ tag: () => tag,
116
120
  toggle: () => toggle,
117
121
  transitionTo: () => transitionTo,
118
122
  when: () => when,
@@ -136,19 +140,19 @@ module.exports = __toCommonJS(src_exports);
136
140
 
137
141
  // src/internal-transitions.ts
138
142
  var TRANSITIONS_SYMBOL = Symbol.for("__machine_transitions__");
139
- function attachTransitions(machine, transitions) {
140
- Object.defineProperty(machine, TRANSITIONS_SYMBOL, {
143
+ function attachTransitions(machine2, transitions) {
144
+ Object.defineProperty(machine2, TRANSITIONS_SYMBOL, {
141
145
  value: transitions,
142
146
  enumerable: false,
143
147
  configurable: false
144
148
  });
145
- return machine;
149
+ return machine2;
146
150
  }
147
- function getStoredTransitions(machine) {
148
- if (!machine || typeof machine !== "object") {
151
+ function getStoredTransitions(machine2) {
152
+ if (!machine2 || typeof machine2 !== "object") {
149
153
  return void 0;
150
154
  }
151
- return machine[TRANSITIONS_SYMBOL];
155
+ return machine2[TRANSITIONS_SYMBOL];
152
156
  }
153
157
  function snapshotOwnTransitions(source) {
154
158
  if (!source || typeof source !== "object") {
@@ -193,8 +197,8 @@ function yieldMachine(m) {
193
197
  return m;
194
198
  }
195
199
  function runSequence(initial, flows) {
196
- return flows.reduce((machine, flow) => {
197
- return run(flow, machine);
200
+ return flows.reduce((machine2, flow) => {
201
+ return run(flow, machine2);
198
202
  }, initial);
199
203
  }
200
204
  function createFlow(flow) {
@@ -449,13 +453,13 @@ function createEnsemble(store, factories, getDiscriminant) {
449
453
  const getCurrentMachine = () => {
450
454
  const context = store.getContext();
451
455
  const currentStateName = getDiscriminant(context);
452
- const factory = factories[currentStateName];
453
- if (!factory) {
456
+ const factory2 = factories[currentStateName];
457
+ if (!factory2) {
454
458
  throw new Error(
455
459
  `[Ensemble] Invalid state: No factory found for state "${String(currentStateName)}".`
456
460
  );
457
461
  }
458
- return factory(context);
462
+ return factory2(context);
459
463
  };
460
464
  const actions = new Proxy({}, {
461
465
  get(_target, prop) {
@@ -601,13 +605,13 @@ function createMultiMachine(MachineClass, store) {
601
605
  function createMutableMachine(sharedContext, factories, getDiscriminant) {
602
606
  const getCurrentMachine = () => {
603
607
  const currentStateName = getDiscriminant(sharedContext);
604
- const factory = factories[currentStateName];
605
- if (!factory) {
608
+ const factory2 = factories[currentStateName];
609
+ if (!factory2) {
606
610
  throw new Error(
607
611
  `[MutableMachine] Invalid state: No factory for state "${String(currentStateName)}".`
608
612
  );
609
613
  }
610
- return factory(sharedContext);
614
+ return factory2(sharedContext);
611
615
  };
612
616
  return new Proxy(sharedContext, {
613
617
  get(target, prop, _receiver) {
@@ -759,18 +763,18 @@ function createParallelMachine(m1, m2) {
759
763
 
760
764
  // src/middleware/core.ts
761
765
  var CANCEL = Symbol("CANCEL");
762
- function createMiddleware(machine, hooks, options = {}) {
766
+ function createMiddleware(machine2, hooks, options = {}) {
763
767
  const { continueOnError = false, logErrors = true, onError } = options;
764
- const wrappedMachine = { ...machine };
765
- for (const prop in machine) {
766
- if (!Object.prototype.hasOwnProperty.call(machine, prop)) continue;
767
- if (prop !== "context" && typeof machine[prop] !== "function") {
768
- wrappedMachine[prop] = machine[prop];
768
+ const wrappedMachine = { ...machine2 };
769
+ for (const prop in machine2) {
770
+ if (!Object.prototype.hasOwnProperty.call(machine2, prop)) continue;
771
+ if (prop !== "context" && typeof machine2[prop] !== "function") {
772
+ wrappedMachine[prop] = machine2[prop];
769
773
  }
770
774
  }
771
- for (const prop in machine) {
772
- if (!Object.prototype.hasOwnProperty.call(machine, prop)) continue;
773
- const value = machine[prop];
775
+ for (const prop in machine2) {
776
+ if (!Object.prototype.hasOwnProperty.call(machine2, prop)) continue;
777
+ const value = machine2[prop];
774
778
  if (typeof value === "function" && prop !== "context") {
775
779
  wrappedMachine[prop] = function(...args) {
776
780
  const transitionName = prop;
@@ -796,23 +800,23 @@ function createMiddleware(machine, hooks, options = {}) {
796
800
  }
797
801
  throw error;
798
802
  }
799
- const ensureMiddlewareProperties = (machine2) => {
800
- if (machine2 && typeof machine2 === "object" && machine2.context) {
803
+ const ensureMiddlewareProperties = (machine3) => {
804
+ if (machine3 && typeof machine3 === "object" && machine3.context) {
801
805
  for (const prop2 in wrappedMachine) {
802
806
  if (!Object.prototype.hasOwnProperty.call(wrappedMachine, prop2)) continue;
803
- if (prop2 !== "context" && !(prop2 in machine2)) {
804
- machine2[prop2] = wrappedMachine[prop2];
807
+ if (prop2 !== "context" && !(prop2 in machine3)) {
808
+ machine3[prop2] = wrappedMachine[prop2];
805
809
  }
806
810
  }
807
- for (const prop2 in machine2) {
808
- if (!Object.prototype.hasOwnProperty.call(machine2, prop2)) continue;
809
- const value2 = machine2[prop2];
811
+ for (const prop2 in machine3) {
812
+ if (!Object.prototype.hasOwnProperty.call(machine3, prop2)) continue;
813
+ const value2 = machine3[prop2];
810
814
  if (typeof value2 === "function" && prop2 !== "context" && wrappedMachine[prop2]) {
811
- machine2[prop2] = wrappedMachine[prop2];
815
+ machine3[prop2] = wrappedMachine[prop2];
812
816
  }
813
817
  }
814
818
  }
815
- return machine2;
819
+ return machine3;
816
820
  };
817
821
  if (nextMachine && typeof nextMachine.then === "function") {
818
822
  const asyncResult = nextMachine.then((resolvedMachine) => {
@@ -915,9 +919,9 @@ function createMiddleware(machine, hooks, options = {}) {
915
919
  }
916
920
  return wrappedMachine;
917
921
  }
918
- function withLogging(machine, options = {}) {
922
+ function withLogging(machine2, options = {}) {
919
923
  const { logger = console.log, includeArgs = false, includeContext = true } = options;
920
- return createMiddleware(machine, {
924
+ return createMiddleware(machine2, {
921
925
  before: ({ transitionName, args }) => {
922
926
  const message = includeArgs ? `→ ${transitionName} [${args.join(", ")}]` : `→ ${transitionName}`;
923
927
  logger(message);
@@ -931,9 +935,9 @@ function withLogging(machine, options = {}) {
931
935
  }
932
936
  });
933
937
  }
934
- function withAnalytics(machine, track, options = {}) {
938
+ function withAnalytics(machine2, track, options = {}) {
935
939
  const { eventPrefix = "state_transition", includePrevContext = false, includeArgs = false } = options;
936
- return createMiddleware(machine, {
940
+ return createMiddleware(machine2, {
937
941
  after: ({ transitionName, prevContext, nextContext, args }) => {
938
942
  const event = `${eventPrefix}.${transitionName}`;
939
943
  const data = { transition: transitionName };
@@ -944,8 +948,8 @@ function withAnalytics(machine, track, options = {}) {
944
948
  }
945
949
  });
946
950
  }
947
- function withValidation(machine, validator) {
948
- return createMiddleware(machine, {
951
+ function withValidation(machine2, validator) {
952
+ return createMiddleware(machine2, {
949
953
  before: (ctx) => {
950
954
  const result = validator(ctx);
951
955
  if (result === false) {
@@ -954,8 +958,8 @@ function withValidation(machine, validator) {
954
958
  }
955
959
  });
956
960
  }
957
- function withPermissions(machine, checker) {
958
- return createMiddleware(machine, {
961
+ function withPermissions(machine2, checker) {
962
+ return createMiddleware(machine2, {
959
963
  before: (ctx) => {
960
964
  if (!checker(ctx)) {
961
965
  throw new Error(`Unauthorized transition: ${ctx.transitionName}`);
@@ -963,9 +967,9 @@ function withPermissions(machine, checker) {
963
967
  }
964
968
  });
965
969
  }
966
- function withErrorReporting(machine, reporter, options = {}) {
970
+ function withErrorReporting(machine2, reporter, options = {}) {
967
971
  const { includeArgs = false } = options;
968
- return createMiddleware(machine, {
972
+ return createMiddleware(machine2, {
969
973
  error: (errorCtx) => {
970
974
  const formattedCtx = {
971
975
  transition: errorCtx.transitionName,
@@ -976,9 +980,9 @@ function withErrorReporting(machine, reporter, options = {}) {
976
980
  }
977
981
  });
978
982
  }
979
- function withPerformanceMonitoring(machine, tracker) {
983
+ function withPerformanceMonitoring(machine2, tracker) {
980
984
  const startTimes = /* @__PURE__ */ new Map();
981
- return createMiddleware(machine, {
985
+ return createMiddleware(machine2, {
982
986
  before: (ctx) => {
983
987
  startTimes.set(ctx.transitionName, Date.now());
984
988
  },
@@ -997,7 +1001,7 @@ function withPerformanceMonitoring(machine, tracker) {
997
1001
  }
998
1002
  });
999
1003
  }
1000
- function withRetry(machine, options = {}) {
1004
+ function withRetry(machine2, options = {}) {
1001
1005
  var _a, _b;
1002
1006
  const {
1003
1007
  maxAttempts = (_a = options.maxRetries) != null ? _a : 3,
@@ -1006,10 +1010,10 @@ function withRetry(machine, options = {}) {
1006
1010
  backoffMultiplier = 2,
1007
1011
  onRetry
1008
1012
  } = options;
1009
- const wrappedMachine = { ...machine };
1010
- for (const prop in machine) {
1011
- if (!Object.prototype.hasOwnProperty.call(machine, prop)) continue;
1012
- const value = machine[prop];
1013
+ const wrappedMachine = { ...machine2 };
1014
+ for (const prop in machine2) {
1015
+ if (!Object.prototype.hasOwnProperty.call(machine2, prop)) continue;
1016
+ const value = machine2[prop];
1013
1017
  if (typeof value === "function" && prop !== "context") {
1014
1018
  wrappedMachine[prop] = async function(...args) {
1015
1019
  let lastError;
@@ -1037,15 +1041,15 @@ function withRetry(machine, options = {}) {
1037
1041
  return wrappedMachine;
1038
1042
  }
1039
1043
  function createCustomMiddleware(hooks, options) {
1040
- return (machine) => createMiddleware(machine, hooks, options);
1044
+ return (machine2) => createMiddleware(machine2, hooks, options);
1041
1045
  }
1042
1046
 
1043
1047
  // src/middleware/history.ts
1044
- function withHistory(machine, options = {}) {
1048
+ function withHistory(machine2, options = {}) {
1045
1049
  const { maxSize, serializer, onEntry } = options;
1046
1050
  const history = [];
1047
1051
  let entryId = 0;
1048
- const instrumentedMachine = createMiddleware(machine, {
1052
+ const instrumentedMachine = createMiddleware(machine2, {
1049
1053
  before: ({ transitionName, args }) => {
1050
1054
  const entry = {
1051
1055
  id: `entry-${entryId++}`,
@@ -1077,7 +1081,7 @@ function withHistory(machine, options = {}) {
1077
1081
  }
1078
1082
 
1079
1083
  // src/middleware/snapshot.ts
1080
- function withSnapshot(machine, options = {}) {
1084
+ function withSnapshot(machine2, options = {}) {
1081
1085
  const {
1082
1086
  maxSize,
1083
1087
  serializer,
@@ -1086,7 +1090,7 @@ function withSnapshot(machine, options = {}) {
1086
1090
  } = options;
1087
1091
  const snapshots = [];
1088
1092
  let snapshotId = 0;
1089
- const instrumentedMachine = createMiddleware(machine, {
1093
+ const instrumentedMachine = createMiddleware(machine2, {
1090
1094
  after: ({ transitionName, prevContext, nextContext }) => {
1091
1095
  if (onlyOnChange && JSON.stringify(prevContext) === JSON.stringify(nextContext)) {
1092
1096
  return;
@@ -1121,8 +1125,8 @@ function withSnapshot(machine, options = {}) {
1121
1125
  });
1122
1126
  const restoreSnapshot = (context) => {
1123
1127
  const transitions = Object.fromEntries(
1124
- Object.entries(machine).filter(
1125
- ([key]) => key !== "context" && key !== "snapshots" && key !== "clearSnapshots" && key !== "restoreSnapshot" && typeof machine[key] === "function"
1128
+ Object.entries(machine2).filter(
1129
+ ([key]) => key !== "context" && key !== "snapshots" && key !== "clearSnapshots" && key !== "restoreSnapshot" && typeof machine2[key] === "function"
1126
1130
  )
1127
1131
  );
1128
1132
  return Object.assign({ context }, transitions);
@@ -1138,13 +1142,13 @@ function withSnapshot(machine, options = {}) {
1138
1142
  }
1139
1143
 
1140
1144
  // src/middleware/time-travel.ts
1141
- function withTimeTravel(machine, options = {}) {
1145
+ function withTimeTravel(machine2, options = {}) {
1142
1146
  const { maxSize, serializer, onRecord } = options;
1143
1147
  const history = [];
1144
1148
  const snapshots = [];
1145
1149
  let historyId = 0;
1146
1150
  let snapshotId = 0;
1147
- const instrumentedMachine = createMiddleware(machine, {
1151
+ const instrumentedMachine = createMiddleware(machine2, {
1148
1152
  before: ({ transitionName, args }) => {
1149
1153
  const entry = {
1150
1154
  id: `entry-${historyId++}`,
@@ -1190,8 +1194,8 @@ function withTimeTravel(machine, options = {}) {
1190
1194
  });
1191
1195
  const restoreSnapshot = (context) => {
1192
1196
  const transitions = Object.fromEntries(
1193
- Object.entries(machine).filter(
1194
- ([key]) => key !== "context" && key !== "history" && key !== "snapshots" && key !== "clearHistory" && key !== "clearSnapshots" && key !== "restoreSnapshot" && key !== "clearTimeTravel" && key !== "replayFrom" && typeof machine[key] === "function"
1197
+ Object.entries(machine2).filter(
1198
+ ([key]) => key !== "context" && key !== "history" && key !== "snapshots" && key !== "clearHistory" && key !== "clearSnapshots" && key !== "restoreSnapshot" && key !== "clearTimeTravel" && key !== "replayFrom" && typeof machine2[key] === "function"
1195
1199
  )
1196
1200
  );
1197
1201
  return Object.assign({ context }, transitions);
@@ -1209,8 +1213,8 @@ function withTimeTravel(machine, options = {}) {
1209
1213
  const freshMachine = Object.assign(
1210
1214
  { context: currentContext },
1211
1215
  Object.fromEntries(
1212
- Object.entries(machine).filter(
1213
- ([key]) => key !== "context" && typeof machine[key] === "function"
1216
+ Object.entries(machine2).filter(
1217
+ ([key]) => key !== "context" && typeof machine2[key] === "function"
1214
1218
  )
1215
1219
  )
1216
1220
  );
@@ -1246,15 +1250,15 @@ function withTimeTravel(machine, options = {}) {
1246
1250
  }
1247
1251
 
1248
1252
  // src/middleware/composition.ts
1249
- function compose(machine, ...middlewares) {
1250
- return middlewares.reduce((acc, middleware) => middleware(acc), machine);
1253
+ function compose(machine2, ...middlewares) {
1254
+ return middlewares.reduce((acc, middleware) => middleware(acc), machine2);
1251
1255
  }
1252
- function composeTyped(machine, ...middlewares) {
1253
- return middlewares.reduce((acc, middleware) => middleware(acc), machine);
1256
+ function composeTyped(machine2, ...middlewares) {
1257
+ return middlewares.reduce((acc, middleware) => middleware(acc), machine2);
1254
1258
  }
1255
1259
  var MiddlewareChainBuilder = class _MiddlewareChainBuilder {
1256
- constructor(machine) {
1257
- this.machine = machine;
1260
+ constructor(machine2) {
1261
+ this.machine = machine2;
1258
1262
  }
1259
1263
  /**
1260
1264
  * Add a middleware to the composition chain.
@@ -1272,12 +1276,12 @@ var MiddlewareChainBuilder = class _MiddlewareChainBuilder {
1272
1276
  return this.machine;
1273
1277
  }
1274
1278
  };
1275
- function chain(machine) {
1276
- return new MiddlewareChainBuilder(machine);
1279
+ function chain(machine2) {
1280
+ return new MiddlewareChainBuilder(machine2);
1277
1281
  }
1278
1282
  function when(middleware, predicate) {
1279
- const conditional = function(machine) {
1280
- return predicate(machine) ? middleware(machine) : machine;
1283
+ const conditional = function(machine2) {
1284
+ return predicate(machine2) ? middleware(machine2) : machine2;
1281
1285
  };
1282
1286
  conditional.middleware = middleware;
1283
1287
  conditional.when = predicate;
@@ -1289,7 +1293,7 @@ function inDevelopment(middleware) {
1289
1293
  });
1290
1294
  }
1291
1295
  function whenContext(key, value, middleware) {
1292
- return when(middleware, (machine) => machine.context[key] === value);
1296
+ return when(middleware, (machine2) => machine2.context[key] === value);
1293
1297
  }
1294
1298
  function createMiddlewareRegistry() {
1295
1299
  const registry = /* @__PURE__ */ new Map();
@@ -1335,7 +1339,7 @@ function createMiddlewareRegistry() {
1335
1339
  * Apply a selection of registered middlewares to a machine.
1336
1340
  * Middlewares are applied in priority order (lowest to highest).
1337
1341
  */
1338
- apply(machine, middlewareNames) {
1342
+ apply(machine2, middlewareNames) {
1339
1343
  const middlewares = middlewareNames.map((name) => {
1340
1344
  const entry = registry.get(name);
1341
1345
  if (!entry) {
@@ -1346,14 +1350,14 @@ function createMiddlewareRegistry() {
1346
1350
  var _a, _b;
1347
1351
  return ((_a = a.priority) != null ? _a : 0) - ((_b = b.priority) != null ? _b : 0);
1348
1352
  });
1349
- return composeTyped(machine, ...middlewares.map((m) => m.middleware));
1353
+ return composeTyped(machine2, ...middlewares.map((m) => m.middleware));
1350
1354
  },
1351
1355
  /**
1352
1356
  * Apply all registered middlewares to a machine in priority order.
1353
1357
  */
1354
- applyAll(machine) {
1358
+ applyAll(machine2) {
1355
1359
  const middlewares = this.list();
1356
- return composeTyped(machine, ...middlewares.map((m) => m.middleware));
1360
+ return composeTyped(machine2, ...middlewares.map((m) => m.middleware));
1357
1361
  }
1358
1362
  };
1359
1363
  }
@@ -1363,8 +1367,8 @@ function createPipeline(config = {}) {
1363
1367
  logErrors = true,
1364
1368
  onError
1365
1369
  } = config;
1366
- return (machine, ...middlewares) => {
1367
- let currentMachine = machine;
1370
+ return (machine2, ...middlewares) => {
1371
+ let currentMachine = machine2;
1368
1372
  const errors = [];
1369
1373
  let success = true;
1370
1374
  for (let i = 0; i < middlewares.length; i++) {
@@ -1398,16 +1402,16 @@ function createPipeline(config = {}) {
1398
1402
  };
1399
1403
  }
1400
1404
  function combine(...middlewares) {
1401
- return (machine) => composeTyped(machine, ...middlewares);
1405
+ return (machine2) => composeTyped(machine2, ...middlewares);
1402
1406
  }
1403
1407
  function branch(branches, fallback) {
1404
- return (machine) => {
1408
+ return (machine2) => {
1405
1409
  for (const [predicate, middleware] of branches) {
1406
- if (predicate(machine)) {
1407
- return middleware(machine);
1410
+ if (predicate(machine2)) {
1411
+ return middleware(machine2);
1408
1412
  }
1409
1413
  }
1410
- return fallback ? fallback(machine) : machine;
1414
+ return fallback ? fallback(machine2) : machine2;
1411
1415
  };
1412
1416
  }
1413
1417
  function isMiddlewareFn(value) {
@@ -1452,85 +1456,85 @@ function isPipelineConfig(value) {
1452
1456
  return value === void 0 || value !== null && typeof value === "object" && ("continueOnError" in value ? typeof value.continueOnError === "boolean" : true) && ("logErrors" in value ? typeof value.logErrors === "boolean" : true) && ("onError" in value ? typeof value.onError === "function" || value.onError === void 0 : true);
1453
1457
  }
1454
1458
  var MiddlewareBuilder = class {
1455
- constructor(machine) {
1456
- this.machine = machine;
1459
+ constructor(machine2) {
1460
+ this.machine = machine2;
1457
1461
  this.middlewares = [];
1458
1462
  }
1459
1463
  /**
1460
1464
  * Add logging middleware with type-safe configuration.
1461
1465
  */
1462
1466
  withLogging(options) {
1463
- this.middlewares.push((machine) => withLogging(machine, options));
1467
+ this.middlewares.push((machine2) => withLogging(machine2, options));
1464
1468
  return this;
1465
1469
  }
1466
1470
  /**
1467
1471
  * Add analytics middleware with type-safe configuration.
1468
1472
  */
1469
1473
  withAnalytics(track, options) {
1470
- this.middlewares.push((machine) => withAnalytics(machine, track, options));
1474
+ this.middlewares.push((machine2) => withAnalytics(machine2, track, options));
1471
1475
  return this;
1472
1476
  }
1473
1477
  /**
1474
1478
  * Add validation middleware with type-safe configuration.
1475
1479
  */
1476
1480
  withValidation(validator, _options) {
1477
- this.middlewares.push((machine) => withValidation(machine, validator));
1481
+ this.middlewares.push((machine2) => withValidation(machine2, validator));
1478
1482
  return this;
1479
1483
  }
1480
1484
  /**
1481
1485
  * Add permission checking middleware with type-safe configuration.
1482
1486
  */
1483
1487
  withPermissions(checker) {
1484
- this.middlewares.push((machine) => withPermissions(machine, checker));
1488
+ this.middlewares.push((machine2) => withPermissions(machine2, checker));
1485
1489
  return this;
1486
1490
  }
1487
1491
  /**
1488
1492
  * Add error reporting middleware with type-safe configuration.
1489
1493
  */
1490
1494
  withErrorReporting(reporter, options) {
1491
- this.middlewares.push((machine) => withErrorReporting(machine, reporter, options));
1495
+ this.middlewares.push((machine2) => withErrorReporting(machine2, reporter, options));
1492
1496
  return this;
1493
1497
  }
1494
1498
  /**
1495
1499
  * Add performance monitoring middleware with type-safe configuration.
1496
1500
  */
1497
1501
  withPerformanceMonitoring(tracker, _options) {
1498
- this.middlewares.push((machine) => withPerformanceMonitoring(machine, tracker));
1502
+ this.middlewares.push((machine2) => withPerformanceMonitoring(machine2, tracker));
1499
1503
  return this;
1500
1504
  }
1501
1505
  /**
1502
1506
  * Add retry middleware with type-safe configuration.
1503
1507
  */
1504
1508
  withRetry(options) {
1505
- this.middlewares.push((machine) => withRetry(machine, options));
1509
+ this.middlewares.push((machine2) => withRetry(machine2, options));
1506
1510
  return this;
1507
1511
  }
1508
1512
  /**
1509
1513
  * Add history tracking middleware with type-safe configuration.
1510
1514
  */
1511
1515
  withHistory(options) {
1512
- this.middlewares.push((machine) => withHistory(machine, options));
1516
+ this.middlewares.push((machine2) => withHistory(machine2, options));
1513
1517
  return this;
1514
1518
  }
1515
1519
  /**
1516
1520
  * Add snapshot tracking middleware with type-safe configuration.
1517
1521
  */
1518
1522
  withSnapshot(options) {
1519
- this.middlewares.push((machine) => withSnapshot(machine, options));
1523
+ this.middlewares.push((machine2) => withSnapshot(machine2, options));
1520
1524
  return this;
1521
1525
  }
1522
1526
  /**
1523
1527
  * Add time travel middleware with type-safe configuration.
1524
1528
  */
1525
1529
  withTimeTravel(options) {
1526
- this.middlewares.push((machine) => withTimeTravel(machine, options));
1530
+ this.middlewares.push((machine2) => withTimeTravel(machine2, options));
1527
1531
  return this;
1528
1532
  }
1529
1533
  /**
1530
1534
  * Add debugging middleware (combination of history, snapshot, and time travel).
1531
1535
  */
1532
1536
  withDebugging() {
1533
- this.middlewares.push((machine) => withDebugging(machine));
1537
+ this.middlewares.push((machine2) => withDebugging(machine2));
1534
1538
  return this;
1535
1539
  }
1536
1540
  /**
@@ -1571,13 +1575,13 @@ var MiddlewareBuilder = class {
1571
1575
  return this;
1572
1576
  }
1573
1577
  };
1574
- function middlewareBuilder(machine) {
1575
- return new MiddlewareBuilder(machine);
1578
+ function middlewareBuilder(machine2) {
1579
+ return new MiddlewareBuilder(machine2);
1576
1580
  }
1577
1581
  function createMiddlewareFactory(defaultOptions = {}) {
1578
1582
  return {
1579
- create: (machine) => {
1580
- const builder = middlewareBuilder(machine);
1583
+ create: (machine2) => {
1584
+ const builder = middlewareBuilder(machine2);
1581
1585
  if (defaultOptions.logging) {
1582
1586
  builder.withLogging(defaultOptions.logging);
1583
1587
  }
@@ -1603,8 +1607,8 @@ function createMiddlewareFactory(defaultOptions = {}) {
1603
1607
  }
1604
1608
  };
1605
1609
  }
1606
- function withDebugging(machine) {
1607
- return withTimeTravel(withSnapshot(withHistory(machine)));
1610
+ function withDebugging(machine2) {
1611
+ return withTimeTravel(withSnapshot(withHistory(machine2)));
1608
1612
  }
1609
1613
 
1610
1614
  // src/mixins.ts
@@ -1640,8 +1644,8 @@ function MachineUnion(...machines) {
1640
1644
  return result;
1641
1645
  };
1642
1646
  };
1643
- for (const machine of machines) {
1644
- const descriptors = getAllPropertyDescriptors(machine.prototype);
1647
+ for (const machine2 of machines) {
1648
+ const descriptors = getAllPropertyDescriptors(machine2.prototype);
1645
1649
  for (const [key, descriptor] of Object.entries(descriptors)) {
1646
1650
  if (key === "constructor") continue;
1647
1651
  if (typeof descriptor.value === "function") {
@@ -1706,14 +1710,14 @@ function machineExclude(source, ...excluded) {
1706
1710
  }
1707
1711
 
1708
1712
  // src/utils.ts
1709
- function isState(machine, machineClass) {
1710
- return machine instanceof machineClass;
1713
+ function isState(machine2, machineClass) {
1714
+ return machine2 instanceof machineClass;
1711
1715
  }
1712
1716
  function createEvent(type, ...args) {
1713
1717
  return { type, args };
1714
1718
  }
1715
- function mergeContext(machine, partialContext) {
1716
- return setContext(machine, (ctx) => ({ ...ctx, ...partialContext }));
1719
+ function mergeContext(machine2, partialContext) {
1720
+ return setContext(machine2, (ctx) => ({ ...ctx, ...partialContext }));
1717
1721
  }
1718
1722
  async function pipeTransitions(initialMachine, ...transitions) {
1719
1723
  let current = initialMachine;
@@ -1722,13 +1726,13 @@ async function pipeTransitions(initialMachine, ...transitions) {
1722
1726
  }
1723
1727
  return current;
1724
1728
  }
1725
- function logState(machine, label) {
1729
+ function logState(machine2, label) {
1726
1730
  if (label) {
1727
- console.log(label, machine.context);
1731
+ console.log(label, machine2.context);
1728
1732
  } else {
1729
- console.log(machine.context);
1733
+ console.log(machine2.context);
1730
1734
  }
1731
- return machine;
1735
+ return machine2;
1732
1736
  }
1733
1737
  function createTransition(getTransitions, transformer) {
1734
1738
  return function(...args) {
@@ -1736,11 +1740,11 @@ function createTransition(getTransitions, transformer) {
1736
1740
  return createMachine(nextContext, getTransitions());
1737
1741
  };
1738
1742
  }
1739
- function call(fn, machine, ...args) {
1740
- return fn.apply(machine, args);
1743
+ function call(fn, machine2, ...args) {
1744
+ return fn.apply(machine2, args);
1741
1745
  }
1742
- function bindTransitions(machine) {
1743
- return new Proxy(machine, {
1746
+ function bindTransitions(machine2) {
1747
+ return new Proxy(machine2, {
1744
1748
  get(target, prop) {
1745
1749
  const value = target[prop];
1746
1750
  if (typeof value === "function") {
@@ -1757,8 +1761,8 @@ function bindTransitions(machine) {
1757
1761
  });
1758
1762
  }
1759
1763
  var BoundMachine = class _BoundMachine {
1760
- constructor(machine) {
1761
- this.wrappedMachine = machine;
1764
+ constructor(machine2) {
1765
+ this.wrappedMachine = machine2;
1762
1766
  return new Proxy(this, {
1763
1767
  get: (target, prop) => {
1764
1768
  if (prop === "wrappedMachine") {
@@ -1792,15 +1796,15 @@ function createTransitionFactory() {
1792
1796
  };
1793
1797
  };
1794
1798
  }
1795
- function createTransitionExtender(machine) {
1799
+ function createTransitionExtender(machine2) {
1796
1800
  return {
1797
- machine,
1801
+ machine: machine2,
1798
1802
  addTransition: function(name, transformer) {
1799
1803
  const transitionFn = function(...args) {
1800
1804
  const nextContext = transformer(this.context, ...args);
1801
1805
  return createMachine(nextContext, this);
1802
1806
  };
1803
- const newMachine = extendTransitions(machine, { [name]: transitionFn });
1807
+ const newMachine = extendTransitions(machine2, { [name]: transitionFn });
1804
1808
  return createTransitionExtender(newMachine);
1805
1809
  }
1806
1810
  };
@@ -1839,7 +1843,7 @@ function createMatcher(...cases) {
1839
1843
  }
1840
1844
  const isProxy = new Proxy({}, {
1841
1845
  get(_target, prop) {
1842
- return function isGuard(machine) {
1846
+ return function isGuard(machine2) {
1843
1847
  const caseConfig = nameToCase.get(prop);
1844
1848
  if (!caseConfig) {
1845
1849
  const available = Array.from(nameToCase.keys()).join(", ");
@@ -1847,7 +1851,7 @@ function createMatcher(...cases) {
1847
1851
  `Unknown matcher case: "${prop}". Available cases: ${available}`
1848
1852
  );
1849
1853
  }
1850
- return caseConfig.predicate(machine);
1854
+ return caseConfig.predicate(machine2);
1851
1855
  };
1852
1856
  }
1853
1857
  });
@@ -1871,7 +1875,7 @@ function createMatcher(...cases) {
1871
1875
  }
1872
1876
  });
1873
1877
  const exhaustive = { __exhaustive: true };
1874
- function when2(machine) {
1878
+ function when2(machine2) {
1875
1879
  return {
1876
1880
  is(...handlers) {
1877
1881
  if (handlers.length === 0) {
@@ -1890,8 +1894,8 @@ function createMatcher(...cases) {
1890
1894
  if (!caseConfig) {
1891
1895
  throw new Error(`Internal error: Unknown matcher case in handler: ${caseName}`);
1892
1896
  }
1893
- if (caseConfig.predicate(machine)) {
1894
- return caseHandler.handler(machine);
1897
+ if (caseConfig.predicate(machine2)) {
1898
+ return caseHandler.handler(machine2);
1895
1899
  }
1896
1900
  }
1897
1901
  const handledCases = actualHandlers.map((h) => h.__name).join(", ");
@@ -1905,9 +1909,9 @@ This may occur if predicates don't cover all runtime possibilities.`
1905
1909
  }
1906
1910
  };
1907
1911
  }
1908
- function simpleMatcher(machine) {
1912
+ function simpleMatcher(machine2) {
1909
1913
  for (const [name, _, predicate] of cases) {
1910
- if (predicate(machine)) {
1914
+ if (predicate(machine2)) {
1911
1915
  return name;
1912
1916
  }
1913
1917
  }
@@ -2076,15 +2080,15 @@ var _Actor = class _Actor {
2076
2080
  // Global inspector
2077
2081
  _Actor._inspector = null;
2078
2082
  var Actor = _Actor;
2079
- function createActor(machine) {
2080
- return new Actor(machine);
2083
+ function createActor(machine2) {
2084
+ return new Actor(machine2);
2081
2085
  }
2082
- function spawn(machine) {
2083
- return createActor(machine);
2086
+ function spawn(machine2) {
2087
+ return createActor(machine2);
2084
2088
  }
2085
2089
  function fromPromise(promiseFn) {
2086
2090
  const initial = { status: "pending", data: void 0, error: void 0 };
2087
- const machine = createMachine(
2091
+ const machine2 = createMachine(
2088
2092
  initial,
2089
2093
  (next2) => ({
2090
2094
  resolve(data) {
@@ -2095,13 +2099,13 @@ function fromPromise(promiseFn) {
2095
2099
  }
2096
2100
  })
2097
2101
  );
2098
- const actor = createActor(machine);
2102
+ const actor = createActor(machine2);
2099
2103
  promiseFn().then((data) => actor.send.resolve(data)).catch((err) => actor.send.reject(err));
2100
2104
  return actor;
2101
2105
  }
2102
2106
  function fromObservable(observable) {
2103
2107
  const initial = { status: "active", value: void 0, error: void 0 };
2104
- const machine = createMachine(
2108
+ const machine2 = createMachine(
2105
2109
  initial,
2106
2110
  (next2) => ({
2107
2111
  next(value) {
@@ -2115,7 +2119,7 @@ function fromObservable(observable) {
2115
2119
  }
2116
2120
  })
2117
2121
  );
2118
- const actor = createActor(machine);
2122
+ const actor = createActor(machine2);
2119
2123
  observable.subscribe(
2120
2124
  (val) => actor.send.next(val),
2121
2125
  (err) => actor.send.error(err),
@@ -2150,19 +2154,240 @@ function createContextBoundMachine(initialContext, transformers) {
2150
2154
  boundTransitions
2151
2155
  );
2152
2156
  }
2153
- function callWithContext(machine, transitionName, ...args) {
2154
- const fn = machine[transitionName];
2155
- const contextOnly = { context: machine.context };
2157
+ function callWithContext(machine2, transitionName, ...args) {
2158
+ const fn = machine2[transitionName];
2159
+ const contextOnly = { context: machine2.context };
2156
2160
  return fn.apply(contextOnly, args);
2157
2161
  }
2158
- function isContextBound(machine) {
2159
- const firstTransition = Object.values(machine).find(
2162
+ function isContextBound(machine2) {
2163
+ const firstTransition = Object.values(machine2).find(
2160
2164
  (v) => typeof v === "function"
2161
2165
  );
2162
2166
  if (!firstTransition) return false;
2163
2167
  return firstTransition.__contextBound === true;
2164
2168
  }
2165
2169
 
2170
+ // src/minimal.ts
2171
+ var minimal_exports = {};
2172
+ __export(minimal_exports, {
2173
+ factory: () => factory,
2174
+ freeze: () => freeze,
2175
+ isState: () => isState2,
2176
+ machine: () => machine,
2177
+ match: () => match,
2178
+ run: () => run2,
2179
+ runnable: () => runnable,
2180
+ tag: () => tag,
2181
+ union: () => union,
2182
+ withChildren: () => withChildren
2183
+ });
2184
+
2185
+ // src/types.ts
2186
+ function tag(nameOrObj, props) {
2187
+ if (typeof nameOrObj === "object") {
2188
+ return nameOrObj;
2189
+ }
2190
+ if (props) {
2191
+ return { ...props, tag: nameOrObj };
2192
+ }
2193
+ return { tag: nameOrObj };
2194
+ }
2195
+ ((tag2) => {
2196
+ function factory2(name) {
2197
+ if (name) {
2198
+ return (props) => tag2(name, props);
2199
+ }
2200
+ return (name2) => (props) => tag2(name2, props);
2201
+ }
2202
+ tag2.factory = factory2;
2203
+ })(tag || (tag = {}));
2204
+ function isState2(machine2, tagValue) {
2205
+ return machine2.tag === tagValue;
2206
+ }
2207
+ function freeze(obj) {
2208
+ Object.freeze(obj);
2209
+ if (typeof Object.values === "function") {
2210
+ for (const value of Object.values(obj)) {
2211
+ if (value && typeof value === "object") {
2212
+ freeze(value);
2213
+ }
2214
+ }
2215
+ }
2216
+ return obj;
2217
+ }
2218
+
2219
+ // src/minimal.ts
2220
+ function machine(context, factory2) {
2221
+ const next2 = (newContext) => machine(newContext, factory2);
2222
+ const transitions = factory2(context, next2);
2223
+ return Object.assign({}, context, transitions);
2224
+ }
2225
+ function match(state2, cases) {
2226
+ const handler = cases[state2.tag];
2227
+ return handler(state2);
2228
+ }
2229
+ var LIFECYCLE = Symbol("lifecycle");
2230
+ function runnable(initialMachine, lifecycles) {
2231
+ const result = { ...initialMachine };
2232
+ result[LIFECYCLE] = lifecycles;
2233
+ return result;
2234
+ }
2235
+ function run2(initial) {
2236
+ let current = initial;
2237
+ let cleanup = null;
2238
+ const listeners = /* @__PURE__ */ new Set();
2239
+ const notify = () => {
2240
+ listeners.forEach((fn) => fn(current));
2241
+ };
2242
+ const enter = () => {
2243
+ if (cleanup) {
2244
+ cleanup();
2245
+ cleanup = null;
2246
+ }
2247
+ const lifecycles = current[LIFECYCLE];
2248
+ const tagValue = current.tag;
2249
+ const lifecycle = lifecycles == null ? void 0 : lifecycles[tagValue];
2250
+ if (lifecycle == null ? void 0 : lifecycle.onEnter) {
2251
+ cleanup = lifecycle.onEnter(send);
2252
+ }
2253
+ };
2254
+ const send = (event, ...args) => {
2255
+ const transition = current[event];
2256
+ if (typeof transition === "function") {
2257
+ const nextValue = transition(...args);
2258
+ if (nextValue && typeof nextValue === "object" && "tag" in nextValue) {
2259
+ const nextMachine = nextValue;
2260
+ if (!nextMachine[LIFECYCLE] && current[LIFECYCLE]) {
2261
+ nextMachine[LIFECYCLE] = current[LIFECYCLE];
2262
+ }
2263
+ current = nextMachine;
2264
+ enter();
2265
+ notify();
2266
+ }
2267
+ }
2268
+ };
2269
+ enter();
2270
+ return {
2271
+ get: () => current,
2272
+ send,
2273
+ stop: () => {
2274
+ if (cleanup) {
2275
+ cleanup();
2276
+ cleanup = null;
2277
+ }
2278
+ listeners.clear();
2279
+ },
2280
+ subscribe: (listener) => {
2281
+ listeners.add(listener);
2282
+ return () => listeners.delete(listener);
2283
+ }
2284
+ };
2285
+ }
2286
+ function withChildren(parent, children) {
2287
+ const result = { ...parent };
2288
+ for (const key of Object.keys(children)) {
2289
+ const child = children[key];
2290
+ const childProxy = new Proxy(child, {
2291
+ get(target, prop) {
2292
+ const value = target[prop];
2293
+ if (typeof value === "function") {
2294
+ return (...args) => {
2295
+ const nextChild = value(...args);
2296
+ return withChildren(
2297
+ { ...parent },
2298
+ { ...children, [key]: nextChild }
2299
+ );
2300
+ };
2301
+ }
2302
+ return value;
2303
+ }
2304
+ });
2305
+ result[key] = childProxy;
2306
+ }
2307
+ return result;
2308
+ }
2309
+ function factory() {
2310
+ return (transitionFactory) => (context) => machine(context, transitionFactory);
2311
+ }
2312
+ function union() {
2313
+ return (factories) => {
2314
+ const resultFactory = (context) => {
2315
+ const factoryFn = factories[context.tag];
2316
+ return machine(context, (ctx, _next) => factoryFn(ctx, resultFactory));
2317
+ };
2318
+ return resultFactory;
2319
+ };
2320
+ }
2321
+
2322
+ // src/delegate.ts
2323
+ var delegate_exports = {};
2324
+ __export(delegate_exports, {
2325
+ createDelegate: () => createDelegate,
2326
+ delegate: () => delegate,
2327
+ delegateAll: () => delegateAll,
2328
+ renameMap: () => renameMap
2329
+ });
2330
+ function delegate(ctx, key, next2, options) {
2331
+ const child = ctx[key];
2332
+ const delegated = {};
2333
+ const allTransitions = Object.keys(child).filter(
2334
+ (k) => typeof child[k] === "function"
2335
+ );
2336
+ let transitionMap;
2337
+ if (!options) {
2338
+ transitionMap = Object.fromEntries(allTransitions.map((t) => [t, t]));
2339
+ } else if ("pick" in options) {
2340
+ transitionMap = Object.fromEntries(
2341
+ options.pick.filter((t) => allTransitions.includes(t)).map((t) => [t, t])
2342
+ );
2343
+ } else if ("omit" in options) {
2344
+ const omitSet = new Set(options.omit);
2345
+ transitionMap = Object.fromEntries(
2346
+ allTransitions.filter((t) => !omitSet.has(t)).map((t) => [t, t])
2347
+ );
2348
+ } else if ("rename" in options) {
2349
+ transitionMap = Object.fromEntries(
2350
+ Object.entries(options.rename).filter(
2351
+ ([childName]) => allTransitions.includes(childName)
2352
+ )
2353
+ );
2354
+ } else {
2355
+ transitionMap = {};
2356
+ }
2357
+ for (const [childName, parentName] of Object.entries(transitionMap)) {
2358
+ const childTransition = child[childName];
2359
+ delegated[parentName] = (...args) => {
2360
+ const nextChild = childTransition.apply(child, args);
2361
+ return next2({ ...ctx, [key]: nextChild });
2362
+ };
2363
+ }
2364
+ return delegated;
2365
+ }
2366
+ function createDelegate(ctx, next2) {
2367
+ return (key, options) => delegate(ctx, key, next2, options);
2368
+ }
2369
+ function delegateAll(ctx, keys, next2, prefix = false) {
2370
+ const result = {};
2371
+ for (const key of keys) {
2372
+ const child = ctx[key];
2373
+ const transitions = Object.keys(child).filter(
2374
+ (k) => typeof child[k] === "function"
2375
+ );
2376
+ for (const transitionName of transitions) {
2377
+ const parentName = prefix ? `${String(key)}_${transitionName}` : transitionName;
2378
+ const childTransition = child[transitionName];
2379
+ result[parentName] = (...args) => {
2380
+ const nextChild = childTransition.apply(child, args);
2381
+ return next2({ ...ctx, [key]: nextChild });
2382
+ };
2383
+ }
2384
+ }
2385
+ return result;
2386
+ }
2387
+ function renameMap() {
2388
+ return (mapping) => mapping;
2389
+ }
2390
+
2166
2391
  // src/index.ts
2167
2392
  function createMachine(context, fnsOrFactory) {
2168
2393
  if (typeof fnsOrFactory === "function") {
@@ -2175,8 +2400,8 @@ function createMachine(context, fnsOrFactory) {
2175
2400
  }
2176
2401
  const stored = getStoredTransitions(fnsOrFactory);
2177
2402
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;
2178
- const machine = Object.assign({ context }, transitions);
2179
- return attachTransitions(machine, transitions);
2403
+ const machine2 = Object.assign({ context }, transitions);
2404
+ return attachTransitions(machine2, transitions);
2180
2405
  }
2181
2406
  function createAsyncMachine(context, fnsOrFactory) {
2182
2407
  if (typeof fnsOrFactory === "function") {
@@ -2189,8 +2414,8 @@ function createAsyncMachine(context, fnsOrFactory) {
2189
2414
  }
2190
2415
  const stored = getStoredTransitions(fnsOrFactory);
2191
2416
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;
2192
- const machine = Object.assign({ context }, transitions);
2193
- return attachTransitions(machine, transitions);
2417
+ const machine2 = Object.assign({ context }, transitions);
2418
+ return attachTransitions(machine2, transitions);
2194
2419
  }
2195
2420
  function createMachineFactory() {
2196
2421
  return (transformers) => {
@@ -2208,23 +2433,23 @@ function createMachineFactory() {
2208
2433
  };
2209
2434
  };
2210
2435
  }
2211
- function setContext(machine, newContextOrFn) {
2436
+ function setContext(machine2, newContextOrFn) {
2212
2437
  var _a;
2213
- const currentContext = machine.context;
2214
- const transitions = (_a = getStoredTransitions(machine)) != null ? _a : snapshotOwnTransitions(machine);
2438
+ const currentContext = machine2.context;
2439
+ const transitions = (_a = getStoredTransitions(machine2)) != null ? _a : snapshotOwnTransitions(machine2);
2215
2440
  const newContext = typeof newContextOrFn === "function" ? newContextOrFn(currentContext) : newContextOrFn;
2216
2441
  return createMachine(newContext, transitions);
2217
2442
  }
2218
2443
  function createContext(context) {
2219
2444
  return { context };
2220
2445
  }
2221
- function overrideTransitions(machine, overrides) {
2222
- const { context, ...originalTransitions } = machine;
2446
+ function overrideTransitions(machine2, overrides) {
2447
+ const { context, ...originalTransitions } = machine2;
2223
2448
  const newTransitions = { ...originalTransitions, ...overrides };
2224
2449
  return createMachine(context, newTransitions);
2225
2450
  }
2226
- function extendTransitions(machine, newTransitions) {
2227
- const { context, ...originalTransitions } = machine;
2451
+ function extendTransitions(machine2, newTransitions) {
2452
+ const { context, ...originalTransitions } = machine2;
2228
2453
  const combinedTransitions = { ...originalTransitions, ...newTransitions };
2229
2454
  return createMachine(context, combinedTransitions);
2230
2455
  }
@@ -2245,16 +2470,16 @@ function createMachineBuilder(templateMachine) {
2245
2470
  return createMachine(newContext, transitions);
2246
2471
  };
2247
2472
  }
2248
- function matchMachine(machine, discriminantKey, handlers) {
2249
- const discriminant = machine.context[discriminantKey];
2473
+ function matchMachine(machine2, discriminantKey, handlers) {
2474
+ const discriminant = machine2.context[discriminantKey];
2250
2475
  const handler = handlers[discriminant];
2251
2476
  if (!handler) {
2252
2477
  throw new Error(`No handler found for state: ${String(discriminant)}`);
2253
2478
  }
2254
- return handler(machine.context);
2479
+ return handler(machine2.context);
2255
2480
  }
2256
- function hasState(machine, key, value) {
2257
- return machine.context[key] === value;
2481
+ function hasState(machine2, key, value) {
2482
+ return machine2.context[key] === value;
2258
2483
  }
2259
2484
  function runMachine(initial, onChange) {
2260
2485
  let current = initial;