@doeixd/machine 1.0.2 → 1.1.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 (51) hide show
  1. package/README.md +48 -0
  2. package/dist/cjs/development/core.js +11 -9
  3. package/dist/cjs/development/core.js.map +3 -3
  4. package/dist/cjs/development/delegate.js +89 -0
  5. package/dist/cjs/development/delegate.js.map +7 -0
  6. package/dist/cjs/development/index.js +385 -167
  7. package/dist/cjs/development/index.js.map +4 -4
  8. package/dist/cjs/development/minimal.js +163 -0
  9. package/dist/cjs/development/minimal.js.map +7 -0
  10. package/dist/cjs/development/react.js +11 -9
  11. package/dist/cjs/development/react.js.map +3 -3
  12. package/dist/cjs/production/core.js +1 -1
  13. package/dist/cjs/production/delegate.js +1 -0
  14. package/dist/cjs/production/index.js +3 -3
  15. package/dist/cjs/production/minimal.js +1 -0
  16. package/dist/cjs/production/react.js +1 -1
  17. package/dist/esm/development/core.js +11 -9
  18. package/dist/esm/development/core.js.map +3 -3
  19. package/dist/esm/development/delegate.js +68 -0
  20. package/dist/esm/development/delegate.js.map +7 -0
  21. package/dist/esm/development/index.js +391 -167
  22. package/dist/esm/development/index.js.map +4 -4
  23. package/dist/esm/development/minimal.js +140 -0
  24. package/dist/esm/development/minimal.js.map +7 -0
  25. package/dist/esm/development/react.js +11 -9
  26. package/dist/esm/development/react.js.map +3 -3
  27. package/dist/esm/production/core.js +1 -1
  28. package/dist/esm/production/delegate.js +1 -0
  29. package/dist/esm/production/index.js +3 -3
  30. package/dist/esm/production/minimal.js +1 -0
  31. package/dist/esm/production/react.js +1 -1
  32. package/dist/types/base.d.ts +56 -0
  33. package/dist/types/base.d.ts.map +1 -0
  34. package/dist/types/delegate.d.ts +101 -0
  35. package/dist/types/delegate.d.ts.map +1 -0
  36. package/dist/types/higher-order.d.ts +2 -1
  37. package/dist/types/higher-order.d.ts.map +1 -1
  38. package/dist/types/index.d.ts +4 -49
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/dist/types/minimal.d.ts +95 -0
  41. package/dist/types/minimal.d.ts.map +1 -0
  42. package/dist/types/types.d.ts +63 -0
  43. package/dist/types/types.d.ts.map +1 -0
  44. package/package.json +25 -1
  45. package/src/base.ts +62 -0
  46. package/src/delegate.ts +267 -0
  47. package/src/higher-order.ts +2 -2
  48. package/src/index.ts +15 -55
  49. package/src/middleware.ts +1049 -1050
  50. package/src/minimal.ts +269 -0
  51. package/src/types.ts +85 -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") {
@@ -160,6 +164,17 @@ function snapshotOwnTransitions(source) {
160
164
  return Object.fromEntries(entries);
161
165
  }
162
166
 
167
+ // src/base.ts
168
+ var MachineBase = class {
169
+ /**
170
+ * Initializes a new machine instance with its starting context.
171
+ * @param context - The initial state of the machine.
172
+ */
173
+ constructor(context) {
174
+ this.context = context;
175
+ }
176
+ };
177
+
163
178
  // src/generators.ts
164
179
  function run(flow, initial) {
165
180
  const generator = flow(initial);
@@ -182,8 +197,8 @@ function yieldMachine(m) {
182
197
  return m;
183
198
  }
184
199
  function runSequence(initial, flows) {
185
- return flows.reduce((machine, flow) => {
186
- return run(flow, machine);
200
+ return flows.reduce((machine2, flow) => {
201
+ return run(flow, machine2);
187
202
  }, initial);
188
203
  }
189
204
  function createFlow(flow) {
@@ -438,13 +453,13 @@ function createEnsemble(store, factories, getDiscriminant) {
438
453
  const getCurrentMachine = () => {
439
454
  const context = store.getContext();
440
455
  const currentStateName = getDiscriminant(context);
441
- const factory = factories[currentStateName];
442
- if (!factory) {
456
+ const factory2 = factories[currentStateName];
457
+ if (!factory2) {
443
458
  throw new Error(
444
459
  `[Ensemble] Invalid state: No factory found for state "${String(currentStateName)}".`
445
460
  );
446
461
  }
447
- return factory(context);
462
+ return factory2(context);
448
463
  };
449
464
  const actions = new Proxy({}, {
450
465
  get(_target, prop) {
@@ -590,13 +605,13 @@ function createMultiMachine(MachineClass, store) {
590
605
  function createMutableMachine(sharedContext, factories, getDiscriminant) {
591
606
  const getCurrentMachine = () => {
592
607
  const currentStateName = getDiscriminant(sharedContext);
593
- const factory = factories[currentStateName];
594
- if (!factory) {
608
+ const factory2 = factories[currentStateName];
609
+ if (!factory2) {
595
610
  throw new Error(
596
611
  `[MutableMachine] Invalid state: No factory for state "${String(currentStateName)}".`
597
612
  );
598
613
  }
599
- return factory(sharedContext);
614
+ return factory2(sharedContext);
600
615
  };
601
616
  return new Proxy(sharedContext, {
602
617
  get(target, prop, _receiver) {
@@ -748,18 +763,18 @@ function createParallelMachine(m1, m2) {
748
763
 
749
764
  // src/middleware/core.ts
750
765
  var CANCEL = Symbol("CANCEL");
751
- function createMiddleware(machine, hooks, options = {}) {
766
+ function createMiddleware(machine2, hooks, options = {}) {
752
767
  const { continueOnError = false, logErrors = true, onError } = options;
753
- const wrappedMachine = { ...machine };
754
- for (const prop in machine) {
755
- if (!Object.prototype.hasOwnProperty.call(machine, prop)) continue;
756
- if (prop !== "context" && typeof machine[prop] !== "function") {
757
- 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];
758
773
  }
759
774
  }
760
- for (const prop in machine) {
761
- if (!Object.prototype.hasOwnProperty.call(machine, prop)) continue;
762
- const value = machine[prop];
775
+ for (const prop in machine2) {
776
+ if (!Object.prototype.hasOwnProperty.call(machine2, prop)) continue;
777
+ const value = machine2[prop];
763
778
  if (typeof value === "function" && prop !== "context") {
764
779
  wrappedMachine[prop] = function(...args) {
765
780
  const transitionName = prop;
@@ -785,23 +800,23 @@ function createMiddleware(machine, hooks, options = {}) {
785
800
  }
786
801
  throw error;
787
802
  }
788
- const ensureMiddlewareProperties = (machine2) => {
789
- if (machine2 && typeof machine2 === "object" && machine2.context) {
803
+ const ensureMiddlewareProperties = (machine3) => {
804
+ if (machine3 && typeof machine3 === "object" && machine3.context) {
790
805
  for (const prop2 in wrappedMachine) {
791
806
  if (!Object.prototype.hasOwnProperty.call(wrappedMachine, prop2)) continue;
792
- if (prop2 !== "context" && !(prop2 in machine2)) {
793
- machine2[prop2] = wrappedMachine[prop2];
807
+ if (prop2 !== "context" && !(prop2 in machine3)) {
808
+ machine3[prop2] = wrappedMachine[prop2];
794
809
  }
795
810
  }
796
- for (const prop2 in machine2) {
797
- if (!Object.prototype.hasOwnProperty.call(machine2, prop2)) continue;
798
- const value2 = machine2[prop2];
811
+ for (const prop2 in machine3) {
812
+ if (!Object.prototype.hasOwnProperty.call(machine3, prop2)) continue;
813
+ const value2 = machine3[prop2];
799
814
  if (typeof value2 === "function" && prop2 !== "context" && wrappedMachine[prop2]) {
800
- machine2[prop2] = wrappedMachine[prop2];
815
+ machine3[prop2] = wrappedMachine[prop2];
801
816
  }
802
817
  }
803
818
  }
804
- return machine2;
819
+ return machine3;
805
820
  };
806
821
  if (nextMachine && typeof nextMachine.then === "function") {
807
822
  const asyncResult = nextMachine.then((resolvedMachine) => {
@@ -904,9 +919,9 @@ function createMiddleware(machine, hooks, options = {}) {
904
919
  }
905
920
  return wrappedMachine;
906
921
  }
907
- function withLogging(machine, options = {}) {
922
+ function withLogging(machine2, options = {}) {
908
923
  const { logger = console.log, includeArgs = false, includeContext = true } = options;
909
- return createMiddleware(machine, {
924
+ return createMiddleware(machine2, {
910
925
  before: ({ transitionName, args }) => {
911
926
  const message = includeArgs ? `→ ${transitionName} [${args.join(", ")}]` : `→ ${transitionName}`;
912
927
  logger(message);
@@ -920,9 +935,9 @@ function withLogging(machine, options = {}) {
920
935
  }
921
936
  });
922
937
  }
923
- function withAnalytics(machine, track, options = {}) {
938
+ function withAnalytics(machine2, track, options = {}) {
924
939
  const { eventPrefix = "state_transition", includePrevContext = false, includeArgs = false } = options;
925
- return createMiddleware(machine, {
940
+ return createMiddleware(machine2, {
926
941
  after: ({ transitionName, prevContext, nextContext, args }) => {
927
942
  const event = `${eventPrefix}.${transitionName}`;
928
943
  const data = { transition: transitionName };
@@ -933,8 +948,8 @@ function withAnalytics(machine, track, options = {}) {
933
948
  }
934
949
  });
935
950
  }
936
- function withValidation(machine, validator) {
937
- return createMiddleware(machine, {
951
+ function withValidation(machine2, validator) {
952
+ return createMiddleware(machine2, {
938
953
  before: (ctx) => {
939
954
  const result = validator(ctx);
940
955
  if (result === false) {
@@ -943,8 +958,8 @@ function withValidation(machine, validator) {
943
958
  }
944
959
  });
945
960
  }
946
- function withPermissions(machine, checker) {
947
- return createMiddleware(machine, {
961
+ function withPermissions(machine2, checker) {
962
+ return createMiddleware(machine2, {
948
963
  before: (ctx) => {
949
964
  if (!checker(ctx)) {
950
965
  throw new Error(`Unauthorized transition: ${ctx.transitionName}`);
@@ -952,9 +967,9 @@ function withPermissions(machine, checker) {
952
967
  }
953
968
  });
954
969
  }
955
- function withErrorReporting(machine, reporter, options = {}) {
970
+ function withErrorReporting(machine2, reporter, options = {}) {
956
971
  const { includeArgs = false } = options;
957
- return createMiddleware(machine, {
972
+ return createMiddleware(machine2, {
958
973
  error: (errorCtx) => {
959
974
  const formattedCtx = {
960
975
  transition: errorCtx.transitionName,
@@ -965,9 +980,9 @@ function withErrorReporting(machine, reporter, options = {}) {
965
980
  }
966
981
  });
967
982
  }
968
- function withPerformanceMonitoring(machine, tracker) {
983
+ function withPerformanceMonitoring(machine2, tracker) {
969
984
  const startTimes = /* @__PURE__ */ new Map();
970
- return createMiddleware(machine, {
985
+ return createMiddleware(machine2, {
971
986
  before: (ctx) => {
972
987
  startTimes.set(ctx.transitionName, Date.now());
973
988
  },
@@ -986,7 +1001,7 @@ function withPerformanceMonitoring(machine, tracker) {
986
1001
  }
987
1002
  });
988
1003
  }
989
- function withRetry(machine, options = {}) {
1004
+ function withRetry(machine2, options = {}) {
990
1005
  var _a, _b;
991
1006
  const {
992
1007
  maxAttempts = (_a = options.maxRetries) != null ? _a : 3,
@@ -995,10 +1010,10 @@ function withRetry(machine, options = {}) {
995
1010
  backoffMultiplier = 2,
996
1011
  onRetry
997
1012
  } = options;
998
- const wrappedMachine = { ...machine };
999
- for (const prop in machine) {
1000
- if (!Object.prototype.hasOwnProperty.call(machine, prop)) continue;
1001
- 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];
1002
1017
  if (typeof value === "function" && prop !== "context") {
1003
1018
  wrappedMachine[prop] = async function(...args) {
1004
1019
  let lastError;
@@ -1026,15 +1041,15 @@ function withRetry(machine, options = {}) {
1026
1041
  return wrappedMachine;
1027
1042
  }
1028
1043
  function createCustomMiddleware(hooks, options) {
1029
- return (machine) => createMiddleware(machine, hooks, options);
1044
+ return (machine2) => createMiddleware(machine2, hooks, options);
1030
1045
  }
1031
1046
 
1032
1047
  // src/middleware/history.ts
1033
- function withHistory(machine, options = {}) {
1048
+ function withHistory(machine2, options = {}) {
1034
1049
  const { maxSize, serializer, onEntry } = options;
1035
1050
  const history = [];
1036
1051
  let entryId = 0;
1037
- const instrumentedMachine = createMiddleware(machine, {
1052
+ const instrumentedMachine = createMiddleware(machine2, {
1038
1053
  before: ({ transitionName, args }) => {
1039
1054
  const entry = {
1040
1055
  id: `entry-${entryId++}`,
@@ -1066,7 +1081,7 @@ function withHistory(machine, options = {}) {
1066
1081
  }
1067
1082
 
1068
1083
  // src/middleware/snapshot.ts
1069
- function withSnapshot(machine, options = {}) {
1084
+ function withSnapshot(machine2, options = {}) {
1070
1085
  const {
1071
1086
  maxSize,
1072
1087
  serializer,
@@ -1075,7 +1090,7 @@ function withSnapshot(machine, options = {}) {
1075
1090
  } = options;
1076
1091
  const snapshots = [];
1077
1092
  let snapshotId = 0;
1078
- const instrumentedMachine = createMiddleware(machine, {
1093
+ const instrumentedMachine = createMiddleware(machine2, {
1079
1094
  after: ({ transitionName, prevContext, nextContext }) => {
1080
1095
  if (onlyOnChange && JSON.stringify(prevContext) === JSON.stringify(nextContext)) {
1081
1096
  return;
@@ -1110,8 +1125,8 @@ function withSnapshot(machine, options = {}) {
1110
1125
  });
1111
1126
  const restoreSnapshot = (context) => {
1112
1127
  const transitions = Object.fromEntries(
1113
- Object.entries(machine).filter(
1114
- ([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"
1115
1130
  )
1116
1131
  );
1117
1132
  return Object.assign({ context }, transitions);
@@ -1127,13 +1142,13 @@ function withSnapshot(machine, options = {}) {
1127
1142
  }
1128
1143
 
1129
1144
  // src/middleware/time-travel.ts
1130
- function withTimeTravel(machine, options = {}) {
1145
+ function withTimeTravel(machine2, options = {}) {
1131
1146
  const { maxSize, serializer, onRecord } = options;
1132
1147
  const history = [];
1133
1148
  const snapshots = [];
1134
1149
  let historyId = 0;
1135
1150
  let snapshotId = 0;
1136
- const instrumentedMachine = createMiddleware(machine, {
1151
+ const instrumentedMachine = createMiddleware(machine2, {
1137
1152
  before: ({ transitionName, args }) => {
1138
1153
  const entry = {
1139
1154
  id: `entry-${historyId++}`,
@@ -1179,8 +1194,8 @@ function withTimeTravel(machine, options = {}) {
1179
1194
  });
1180
1195
  const restoreSnapshot = (context) => {
1181
1196
  const transitions = Object.fromEntries(
1182
- Object.entries(machine).filter(
1183
- ([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"
1184
1199
  )
1185
1200
  );
1186
1201
  return Object.assign({ context }, transitions);
@@ -1198,8 +1213,8 @@ function withTimeTravel(machine, options = {}) {
1198
1213
  const freshMachine = Object.assign(
1199
1214
  { context: currentContext },
1200
1215
  Object.fromEntries(
1201
- Object.entries(machine).filter(
1202
- ([key]) => key !== "context" && typeof machine[key] === "function"
1216
+ Object.entries(machine2).filter(
1217
+ ([key]) => key !== "context" && typeof machine2[key] === "function"
1203
1218
  )
1204
1219
  )
1205
1220
  );
@@ -1235,15 +1250,15 @@ function withTimeTravel(machine, options = {}) {
1235
1250
  }
1236
1251
 
1237
1252
  // src/middleware/composition.ts
1238
- function compose(machine, ...middlewares) {
1239
- return middlewares.reduce((acc, middleware) => middleware(acc), machine);
1253
+ function compose(machine2, ...middlewares) {
1254
+ return middlewares.reduce((acc, middleware) => middleware(acc), machine2);
1240
1255
  }
1241
- function composeTyped(machine, ...middlewares) {
1242
- return middlewares.reduce((acc, middleware) => middleware(acc), machine);
1256
+ function composeTyped(machine2, ...middlewares) {
1257
+ return middlewares.reduce((acc, middleware) => middleware(acc), machine2);
1243
1258
  }
1244
1259
  var MiddlewareChainBuilder = class _MiddlewareChainBuilder {
1245
- constructor(machine) {
1246
- this.machine = machine;
1260
+ constructor(machine2) {
1261
+ this.machine = machine2;
1247
1262
  }
1248
1263
  /**
1249
1264
  * Add a middleware to the composition chain.
@@ -1261,12 +1276,12 @@ var MiddlewareChainBuilder = class _MiddlewareChainBuilder {
1261
1276
  return this.machine;
1262
1277
  }
1263
1278
  };
1264
- function chain(machine) {
1265
- return new MiddlewareChainBuilder(machine);
1279
+ function chain(machine2) {
1280
+ return new MiddlewareChainBuilder(machine2);
1266
1281
  }
1267
1282
  function when(middleware, predicate) {
1268
- const conditional = function(machine) {
1269
- return predicate(machine) ? middleware(machine) : machine;
1283
+ const conditional = function(machine2) {
1284
+ return predicate(machine2) ? middleware(machine2) : machine2;
1270
1285
  };
1271
1286
  conditional.middleware = middleware;
1272
1287
  conditional.when = predicate;
@@ -1278,7 +1293,7 @@ function inDevelopment(middleware) {
1278
1293
  });
1279
1294
  }
1280
1295
  function whenContext(key, value, middleware) {
1281
- return when(middleware, (machine) => machine.context[key] === value);
1296
+ return when(middleware, (machine2) => machine2.context[key] === value);
1282
1297
  }
1283
1298
  function createMiddlewareRegistry() {
1284
1299
  const registry = /* @__PURE__ */ new Map();
@@ -1324,7 +1339,7 @@ function createMiddlewareRegistry() {
1324
1339
  * Apply a selection of registered middlewares to a machine.
1325
1340
  * Middlewares are applied in priority order (lowest to highest).
1326
1341
  */
1327
- apply(machine, middlewareNames) {
1342
+ apply(machine2, middlewareNames) {
1328
1343
  const middlewares = middlewareNames.map((name) => {
1329
1344
  const entry = registry.get(name);
1330
1345
  if (!entry) {
@@ -1335,14 +1350,14 @@ function createMiddlewareRegistry() {
1335
1350
  var _a, _b;
1336
1351
  return ((_a = a.priority) != null ? _a : 0) - ((_b = b.priority) != null ? _b : 0);
1337
1352
  });
1338
- return composeTyped(machine, ...middlewares.map((m) => m.middleware));
1353
+ return composeTyped(machine2, ...middlewares.map((m) => m.middleware));
1339
1354
  },
1340
1355
  /**
1341
1356
  * Apply all registered middlewares to a machine in priority order.
1342
1357
  */
1343
- applyAll(machine) {
1358
+ applyAll(machine2) {
1344
1359
  const middlewares = this.list();
1345
- return composeTyped(machine, ...middlewares.map((m) => m.middleware));
1360
+ return composeTyped(machine2, ...middlewares.map((m) => m.middleware));
1346
1361
  }
1347
1362
  };
1348
1363
  }
@@ -1352,8 +1367,8 @@ function createPipeline(config = {}) {
1352
1367
  logErrors = true,
1353
1368
  onError
1354
1369
  } = config;
1355
- return (machine, ...middlewares) => {
1356
- let currentMachine = machine;
1370
+ return (machine2, ...middlewares) => {
1371
+ let currentMachine = machine2;
1357
1372
  const errors = [];
1358
1373
  let success = true;
1359
1374
  for (let i = 0; i < middlewares.length; i++) {
@@ -1387,16 +1402,16 @@ function createPipeline(config = {}) {
1387
1402
  };
1388
1403
  }
1389
1404
  function combine(...middlewares) {
1390
- return (machine) => composeTyped(machine, ...middlewares);
1405
+ return (machine2) => composeTyped(machine2, ...middlewares);
1391
1406
  }
1392
1407
  function branch(branches, fallback) {
1393
- return (machine) => {
1408
+ return (machine2) => {
1394
1409
  for (const [predicate, middleware] of branches) {
1395
- if (predicate(machine)) {
1396
- return middleware(machine);
1410
+ if (predicate(machine2)) {
1411
+ return middleware(machine2);
1397
1412
  }
1398
1413
  }
1399
- return fallback ? fallback(machine) : machine;
1414
+ return fallback ? fallback(machine2) : machine2;
1400
1415
  };
1401
1416
  }
1402
1417
  function isMiddlewareFn(value) {
@@ -1441,85 +1456,85 @@ function isPipelineConfig(value) {
1441
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);
1442
1457
  }
1443
1458
  var MiddlewareBuilder = class {
1444
- constructor(machine) {
1445
- this.machine = machine;
1459
+ constructor(machine2) {
1460
+ this.machine = machine2;
1446
1461
  this.middlewares = [];
1447
1462
  }
1448
1463
  /**
1449
1464
  * Add logging middleware with type-safe configuration.
1450
1465
  */
1451
1466
  withLogging(options) {
1452
- this.middlewares.push((machine) => withLogging(machine, options));
1467
+ this.middlewares.push((machine2) => withLogging(machine2, options));
1453
1468
  return this;
1454
1469
  }
1455
1470
  /**
1456
1471
  * Add analytics middleware with type-safe configuration.
1457
1472
  */
1458
1473
  withAnalytics(track, options) {
1459
- this.middlewares.push((machine) => withAnalytics(machine, track, options));
1474
+ this.middlewares.push((machine2) => withAnalytics(machine2, track, options));
1460
1475
  return this;
1461
1476
  }
1462
1477
  /**
1463
1478
  * Add validation middleware with type-safe configuration.
1464
1479
  */
1465
1480
  withValidation(validator, _options) {
1466
- this.middlewares.push((machine) => withValidation(machine, validator));
1481
+ this.middlewares.push((machine2) => withValidation(machine2, validator));
1467
1482
  return this;
1468
1483
  }
1469
1484
  /**
1470
1485
  * Add permission checking middleware with type-safe configuration.
1471
1486
  */
1472
1487
  withPermissions(checker) {
1473
- this.middlewares.push((machine) => withPermissions(machine, checker));
1488
+ this.middlewares.push((machine2) => withPermissions(machine2, checker));
1474
1489
  return this;
1475
1490
  }
1476
1491
  /**
1477
1492
  * Add error reporting middleware with type-safe configuration.
1478
1493
  */
1479
1494
  withErrorReporting(reporter, options) {
1480
- this.middlewares.push((machine) => withErrorReporting(machine, reporter, options));
1495
+ this.middlewares.push((machine2) => withErrorReporting(machine2, reporter, options));
1481
1496
  return this;
1482
1497
  }
1483
1498
  /**
1484
1499
  * Add performance monitoring middleware with type-safe configuration.
1485
1500
  */
1486
1501
  withPerformanceMonitoring(tracker, _options) {
1487
- this.middlewares.push((machine) => withPerformanceMonitoring(machine, tracker));
1502
+ this.middlewares.push((machine2) => withPerformanceMonitoring(machine2, tracker));
1488
1503
  return this;
1489
1504
  }
1490
1505
  /**
1491
1506
  * Add retry middleware with type-safe configuration.
1492
1507
  */
1493
1508
  withRetry(options) {
1494
- this.middlewares.push((machine) => withRetry(machine, options));
1509
+ this.middlewares.push((machine2) => withRetry(machine2, options));
1495
1510
  return this;
1496
1511
  }
1497
1512
  /**
1498
1513
  * Add history tracking middleware with type-safe configuration.
1499
1514
  */
1500
1515
  withHistory(options) {
1501
- this.middlewares.push((machine) => withHistory(machine, options));
1516
+ this.middlewares.push((machine2) => withHistory(machine2, options));
1502
1517
  return this;
1503
1518
  }
1504
1519
  /**
1505
1520
  * Add snapshot tracking middleware with type-safe configuration.
1506
1521
  */
1507
1522
  withSnapshot(options) {
1508
- this.middlewares.push((machine) => withSnapshot(machine, options));
1523
+ this.middlewares.push((machine2) => withSnapshot(machine2, options));
1509
1524
  return this;
1510
1525
  }
1511
1526
  /**
1512
1527
  * Add time travel middleware with type-safe configuration.
1513
1528
  */
1514
1529
  withTimeTravel(options) {
1515
- this.middlewares.push((machine) => withTimeTravel(machine, options));
1530
+ this.middlewares.push((machine2) => withTimeTravel(machine2, options));
1516
1531
  return this;
1517
1532
  }
1518
1533
  /**
1519
1534
  * Add debugging middleware (combination of history, snapshot, and time travel).
1520
1535
  */
1521
1536
  withDebugging() {
1522
- this.middlewares.push((machine) => withDebugging(machine));
1537
+ this.middlewares.push((machine2) => withDebugging(machine2));
1523
1538
  return this;
1524
1539
  }
1525
1540
  /**
@@ -1560,13 +1575,13 @@ var MiddlewareBuilder = class {
1560
1575
  return this;
1561
1576
  }
1562
1577
  };
1563
- function middlewareBuilder(machine) {
1564
- return new MiddlewareBuilder(machine);
1578
+ function middlewareBuilder(machine2) {
1579
+ return new MiddlewareBuilder(machine2);
1565
1580
  }
1566
1581
  function createMiddlewareFactory(defaultOptions = {}) {
1567
1582
  return {
1568
- create: (machine) => {
1569
- const builder = middlewareBuilder(machine);
1583
+ create: (machine2) => {
1584
+ const builder = middlewareBuilder(machine2);
1570
1585
  if (defaultOptions.logging) {
1571
1586
  builder.withLogging(defaultOptions.logging);
1572
1587
  }
@@ -1592,8 +1607,8 @@ function createMiddlewareFactory(defaultOptions = {}) {
1592
1607
  }
1593
1608
  };
1594
1609
  }
1595
- function withDebugging(machine) {
1596
- return withTimeTravel(withSnapshot(withHistory(machine)));
1610
+ function withDebugging(machine2) {
1611
+ return withTimeTravel(withSnapshot(withHistory(machine2)));
1597
1612
  }
1598
1613
 
1599
1614
  // src/mixins.ts
@@ -1629,8 +1644,8 @@ function MachineUnion(...machines) {
1629
1644
  return result;
1630
1645
  };
1631
1646
  };
1632
- for (const machine of machines) {
1633
- const descriptors = getAllPropertyDescriptors(machine.prototype);
1647
+ for (const machine2 of machines) {
1648
+ const descriptors = getAllPropertyDescriptors(machine2.prototype);
1634
1649
  for (const [key, descriptor] of Object.entries(descriptors)) {
1635
1650
  if (key === "constructor") continue;
1636
1651
  if (typeof descriptor.value === "function") {
@@ -1695,14 +1710,14 @@ function machineExclude(source, ...excluded) {
1695
1710
  }
1696
1711
 
1697
1712
  // src/utils.ts
1698
- function isState(machine, machineClass) {
1699
- return machine instanceof machineClass;
1713
+ function isState(machine2, machineClass) {
1714
+ return machine2 instanceof machineClass;
1700
1715
  }
1701
1716
  function createEvent(type, ...args) {
1702
1717
  return { type, args };
1703
1718
  }
1704
- function mergeContext(machine, partialContext) {
1705
- return setContext(machine, (ctx) => ({ ...ctx, ...partialContext }));
1719
+ function mergeContext(machine2, partialContext) {
1720
+ return setContext(machine2, (ctx) => ({ ...ctx, ...partialContext }));
1706
1721
  }
1707
1722
  async function pipeTransitions(initialMachine, ...transitions) {
1708
1723
  let current = initialMachine;
@@ -1711,13 +1726,13 @@ async function pipeTransitions(initialMachine, ...transitions) {
1711
1726
  }
1712
1727
  return current;
1713
1728
  }
1714
- function logState(machine, label) {
1729
+ function logState(machine2, label) {
1715
1730
  if (label) {
1716
- console.log(label, machine.context);
1731
+ console.log(label, machine2.context);
1717
1732
  } else {
1718
- console.log(machine.context);
1733
+ console.log(machine2.context);
1719
1734
  }
1720
- return machine;
1735
+ return machine2;
1721
1736
  }
1722
1737
  function createTransition(getTransitions, transformer) {
1723
1738
  return function(...args) {
@@ -1725,11 +1740,11 @@ function createTransition(getTransitions, transformer) {
1725
1740
  return createMachine(nextContext, getTransitions());
1726
1741
  };
1727
1742
  }
1728
- function call(fn, machine, ...args) {
1729
- return fn.apply(machine, args);
1743
+ function call(fn, machine2, ...args) {
1744
+ return fn.apply(machine2, args);
1730
1745
  }
1731
- function bindTransitions(machine) {
1732
- return new Proxy(machine, {
1746
+ function bindTransitions(machine2) {
1747
+ return new Proxy(machine2, {
1733
1748
  get(target, prop) {
1734
1749
  const value = target[prop];
1735
1750
  if (typeof value === "function") {
@@ -1746,8 +1761,8 @@ function bindTransitions(machine) {
1746
1761
  });
1747
1762
  }
1748
1763
  var BoundMachine = class _BoundMachine {
1749
- constructor(machine) {
1750
- this.wrappedMachine = machine;
1764
+ constructor(machine2) {
1765
+ this.wrappedMachine = machine2;
1751
1766
  return new Proxy(this, {
1752
1767
  get: (target, prop) => {
1753
1768
  if (prop === "wrappedMachine") {
@@ -1781,15 +1796,15 @@ function createTransitionFactory() {
1781
1796
  };
1782
1797
  };
1783
1798
  }
1784
- function createTransitionExtender(machine) {
1799
+ function createTransitionExtender(machine2) {
1785
1800
  return {
1786
- machine,
1801
+ machine: machine2,
1787
1802
  addTransition: function(name, transformer) {
1788
1803
  const transitionFn = function(...args) {
1789
1804
  const nextContext = transformer(this.context, ...args);
1790
1805
  return createMachine(nextContext, this);
1791
1806
  };
1792
- const newMachine = extendTransitions(machine, { [name]: transitionFn });
1807
+ const newMachine = extendTransitions(machine2, { [name]: transitionFn });
1793
1808
  return createTransitionExtender(newMachine);
1794
1809
  }
1795
1810
  };
@@ -1828,7 +1843,7 @@ function createMatcher(...cases) {
1828
1843
  }
1829
1844
  const isProxy = new Proxy({}, {
1830
1845
  get(_target, prop) {
1831
- return function isGuard(machine) {
1846
+ return function isGuard(machine2) {
1832
1847
  const caseConfig = nameToCase.get(prop);
1833
1848
  if (!caseConfig) {
1834
1849
  const available = Array.from(nameToCase.keys()).join(", ");
@@ -1836,7 +1851,7 @@ function createMatcher(...cases) {
1836
1851
  `Unknown matcher case: "${prop}". Available cases: ${available}`
1837
1852
  );
1838
1853
  }
1839
- return caseConfig.predicate(machine);
1854
+ return caseConfig.predicate(machine2);
1840
1855
  };
1841
1856
  }
1842
1857
  });
@@ -1860,7 +1875,7 @@ function createMatcher(...cases) {
1860
1875
  }
1861
1876
  });
1862
1877
  const exhaustive = { __exhaustive: true };
1863
- function when2(machine) {
1878
+ function when2(machine2) {
1864
1879
  return {
1865
1880
  is(...handlers) {
1866
1881
  if (handlers.length === 0) {
@@ -1879,8 +1894,8 @@ function createMatcher(...cases) {
1879
1894
  if (!caseConfig) {
1880
1895
  throw new Error(`Internal error: Unknown matcher case in handler: ${caseName}`);
1881
1896
  }
1882
- if (caseConfig.predicate(machine)) {
1883
- return caseHandler.handler(machine);
1897
+ if (caseConfig.predicate(machine2)) {
1898
+ return caseHandler.handler(machine2);
1884
1899
  }
1885
1900
  }
1886
1901
  const handledCases = actualHandlers.map((h) => h.__name).join(", ");
@@ -1894,9 +1909,9 @@ This may occur if predicates don't cover all runtime possibilities.`
1894
1909
  }
1895
1910
  };
1896
1911
  }
1897
- function simpleMatcher(machine) {
1912
+ function simpleMatcher(machine2) {
1898
1913
  for (const [name, _, predicate] of cases) {
1899
- if (predicate(machine)) {
1914
+ if (predicate(machine2)) {
1900
1915
  return name;
1901
1916
  }
1902
1917
  }
@@ -2065,15 +2080,15 @@ var _Actor = class _Actor {
2065
2080
  // Global inspector
2066
2081
  _Actor._inspector = null;
2067
2082
  var Actor = _Actor;
2068
- function createActor(machine) {
2069
- return new Actor(machine);
2083
+ function createActor(machine2) {
2084
+ return new Actor(machine2);
2070
2085
  }
2071
- function spawn(machine) {
2072
- return createActor(machine);
2086
+ function spawn(machine2) {
2087
+ return createActor(machine2);
2073
2088
  }
2074
2089
  function fromPromise(promiseFn) {
2075
2090
  const initial = { status: "pending", data: void 0, error: void 0 };
2076
- const machine = createMachine(
2091
+ const machine2 = createMachine(
2077
2092
  initial,
2078
2093
  (next2) => ({
2079
2094
  resolve(data) {
@@ -2084,13 +2099,13 @@ function fromPromise(promiseFn) {
2084
2099
  }
2085
2100
  })
2086
2101
  );
2087
- const actor = createActor(machine);
2102
+ const actor = createActor(machine2);
2088
2103
  promiseFn().then((data) => actor.send.resolve(data)).catch((err) => actor.send.reject(err));
2089
2104
  return actor;
2090
2105
  }
2091
2106
  function fromObservable(observable) {
2092
2107
  const initial = { status: "active", value: void 0, error: void 0 };
2093
- const machine = createMachine(
2108
+ const machine2 = createMachine(
2094
2109
  initial,
2095
2110
  (next2) => ({
2096
2111
  next(value) {
@@ -2104,7 +2119,7 @@ function fromObservable(observable) {
2104
2119
  }
2105
2120
  })
2106
2121
  );
2107
- const actor = createActor(machine);
2122
+ const actor = createActor(machine2);
2108
2123
  observable.subscribe(
2109
2124
  (val) => actor.send.next(val),
2110
2125
  (err) => actor.send.error(err),
@@ -2139,19 +2154,231 @@ function createContextBoundMachine(initialContext, transformers) {
2139
2154
  boundTransitions
2140
2155
  );
2141
2156
  }
2142
- function callWithContext(machine, transitionName, ...args) {
2143
- const fn = machine[transitionName];
2144
- const contextOnly = { context: machine.context };
2157
+ function callWithContext(machine2, transitionName, ...args) {
2158
+ const fn = machine2[transitionName];
2159
+ const contextOnly = { context: machine2.context };
2145
2160
  return fn.apply(contextOnly, args);
2146
2161
  }
2147
- function isContextBound(machine) {
2148
- const firstTransition = Object.values(machine).find(
2162
+ function isContextBound(machine2) {
2163
+ const firstTransition = Object.values(machine2).find(
2149
2164
  (v) => typeof v === "function"
2150
2165
  );
2151
2166
  if (!firstTransition) return false;
2152
2167
  return firstTransition.__contextBound === true;
2153
2168
  }
2154
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
+ function isState2(machine2, tagValue) {
2196
+ return machine2.tag === tagValue;
2197
+ }
2198
+ function freeze(obj) {
2199
+ Object.freeze(obj);
2200
+ if (typeof Object.values === "function") {
2201
+ for (const value of Object.values(obj)) {
2202
+ if (value && typeof value === "object") {
2203
+ freeze(value);
2204
+ }
2205
+ }
2206
+ }
2207
+ return obj;
2208
+ }
2209
+
2210
+ // src/minimal.ts
2211
+ function machine(context, factory2) {
2212
+ const next2 = (newContext) => machine(newContext, factory2);
2213
+ const transitions = factory2(context, next2);
2214
+ return Object.assign({}, context, transitions);
2215
+ }
2216
+ function match(state2, cases) {
2217
+ const handler = cases[state2.tag];
2218
+ return handler(state2);
2219
+ }
2220
+ var LIFECYCLE = Symbol("lifecycle");
2221
+ function runnable(initialMachine, lifecycles) {
2222
+ const result = { ...initialMachine };
2223
+ result[LIFECYCLE] = lifecycles;
2224
+ return result;
2225
+ }
2226
+ function run2(initial) {
2227
+ let current = initial;
2228
+ let cleanup = null;
2229
+ const listeners = /* @__PURE__ */ new Set();
2230
+ const notify = () => {
2231
+ listeners.forEach((fn) => fn(current));
2232
+ };
2233
+ const enter = () => {
2234
+ if (cleanup) {
2235
+ cleanup();
2236
+ cleanup = null;
2237
+ }
2238
+ const lifecycles = current[LIFECYCLE];
2239
+ const tagValue = current.tag;
2240
+ const lifecycle = lifecycles == null ? void 0 : lifecycles[tagValue];
2241
+ if (lifecycle == null ? void 0 : lifecycle.onEnter) {
2242
+ cleanup = lifecycle.onEnter(send);
2243
+ }
2244
+ };
2245
+ const send = (event, ...args) => {
2246
+ const transition = current[event];
2247
+ if (typeof transition === "function") {
2248
+ const nextValue = transition(...args);
2249
+ if (nextValue && typeof nextValue === "object" && "tag" in nextValue) {
2250
+ const nextMachine = nextValue;
2251
+ if (!nextMachine[LIFECYCLE] && current[LIFECYCLE]) {
2252
+ nextMachine[LIFECYCLE] = current[LIFECYCLE];
2253
+ }
2254
+ current = nextMachine;
2255
+ enter();
2256
+ notify();
2257
+ }
2258
+ }
2259
+ };
2260
+ enter();
2261
+ return {
2262
+ get: () => current,
2263
+ send,
2264
+ stop: () => {
2265
+ if (cleanup) {
2266
+ cleanup();
2267
+ cleanup = null;
2268
+ }
2269
+ listeners.clear();
2270
+ },
2271
+ subscribe: (listener) => {
2272
+ listeners.add(listener);
2273
+ return () => listeners.delete(listener);
2274
+ }
2275
+ };
2276
+ }
2277
+ function withChildren(parent, children) {
2278
+ const result = { ...parent };
2279
+ for (const key of Object.keys(children)) {
2280
+ const child = children[key];
2281
+ const childProxy = new Proxy(child, {
2282
+ get(target, prop) {
2283
+ const value = target[prop];
2284
+ if (typeof value === "function") {
2285
+ return (...args) => {
2286
+ const nextChild = value(...args);
2287
+ return withChildren(
2288
+ { ...parent },
2289
+ { ...children, [key]: nextChild }
2290
+ );
2291
+ };
2292
+ }
2293
+ return value;
2294
+ }
2295
+ });
2296
+ result[key] = childProxy;
2297
+ }
2298
+ return result;
2299
+ }
2300
+ function factory() {
2301
+ return (transitionFactory) => (context) => machine(context, transitionFactory);
2302
+ }
2303
+ function union() {
2304
+ return (factories) => {
2305
+ const resultFactory = (context) => {
2306
+ const factoryFn = factories[context.tag];
2307
+ return machine(context, (ctx, _next) => factoryFn(ctx, resultFactory));
2308
+ };
2309
+ return resultFactory;
2310
+ };
2311
+ }
2312
+
2313
+ // src/delegate.ts
2314
+ var delegate_exports = {};
2315
+ __export(delegate_exports, {
2316
+ createDelegate: () => createDelegate,
2317
+ delegate: () => delegate,
2318
+ delegateAll: () => delegateAll,
2319
+ renameMap: () => renameMap
2320
+ });
2321
+ function delegate(ctx, key, next2, options) {
2322
+ const child = ctx[key];
2323
+ const delegated = {};
2324
+ const allTransitions = Object.keys(child).filter(
2325
+ (k) => typeof child[k] === "function"
2326
+ );
2327
+ let transitionMap;
2328
+ if (!options) {
2329
+ transitionMap = Object.fromEntries(allTransitions.map((t) => [t, t]));
2330
+ } else if ("pick" in options) {
2331
+ transitionMap = Object.fromEntries(
2332
+ options.pick.filter((t) => allTransitions.includes(t)).map((t) => [t, t])
2333
+ );
2334
+ } else if ("omit" in options) {
2335
+ const omitSet = new Set(options.omit);
2336
+ transitionMap = Object.fromEntries(
2337
+ allTransitions.filter((t) => !omitSet.has(t)).map((t) => [t, t])
2338
+ );
2339
+ } else if ("rename" in options) {
2340
+ transitionMap = Object.fromEntries(
2341
+ Object.entries(options.rename).filter(
2342
+ ([childName]) => allTransitions.includes(childName)
2343
+ )
2344
+ );
2345
+ } else {
2346
+ transitionMap = {};
2347
+ }
2348
+ for (const [childName, parentName] of Object.entries(transitionMap)) {
2349
+ const childTransition = child[childName];
2350
+ delegated[parentName] = (...args) => {
2351
+ const nextChild = childTransition.apply(child, args);
2352
+ return next2({ ...ctx, [key]: nextChild });
2353
+ };
2354
+ }
2355
+ return delegated;
2356
+ }
2357
+ function createDelegate(ctx, next2) {
2358
+ return (key, options) => delegate(ctx, key, next2, options);
2359
+ }
2360
+ function delegateAll(ctx, keys, next2, prefix = false) {
2361
+ const result = {};
2362
+ for (const key of keys) {
2363
+ const child = ctx[key];
2364
+ const transitions = Object.keys(child).filter(
2365
+ (k) => typeof child[k] === "function"
2366
+ );
2367
+ for (const transitionName of transitions) {
2368
+ const parentName = prefix ? `${String(key)}_${transitionName}` : transitionName;
2369
+ const childTransition = child[transitionName];
2370
+ result[parentName] = (...args) => {
2371
+ const nextChild = childTransition.apply(child, args);
2372
+ return next2({ ...ctx, [key]: nextChild });
2373
+ };
2374
+ }
2375
+ }
2376
+ return result;
2377
+ }
2378
+ function renameMap() {
2379
+ return (mapping) => mapping;
2380
+ }
2381
+
2155
2382
  // src/index.ts
2156
2383
  function createMachine(context, fnsOrFactory) {
2157
2384
  if (typeof fnsOrFactory === "function") {
@@ -2164,8 +2391,8 @@ function createMachine(context, fnsOrFactory) {
2164
2391
  }
2165
2392
  const stored = getStoredTransitions(fnsOrFactory);
2166
2393
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;
2167
- const machine = Object.assign({ context }, transitions);
2168
- return attachTransitions(machine, transitions);
2394
+ const machine2 = Object.assign({ context }, transitions);
2395
+ return attachTransitions(machine2, transitions);
2169
2396
  }
2170
2397
  function createAsyncMachine(context, fnsOrFactory) {
2171
2398
  if (typeof fnsOrFactory === "function") {
@@ -2178,8 +2405,8 @@ function createAsyncMachine(context, fnsOrFactory) {
2178
2405
  }
2179
2406
  const stored = getStoredTransitions(fnsOrFactory);
2180
2407
  const transitions = stored != null ? stored : "context" in fnsOrFactory ? snapshotOwnTransitions(fnsOrFactory) : fnsOrFactory;
2181
- const machine = Object.assign({ context }, transitions);
2182
- return attachTransitions(machine, transitions);
2408
+ const machine2 = Object.assign({ context }, transitions);
2409
+ return attachTransitions(machine2, transitions);
2183
2410
  }
2184
2411
  function createMachineFactory() {
2185
2412
  return (transformers) => {
@@ -2197,23 +2424,23 @@ function createMachineFactory() {
2197
2424
  };
2198
2425
  };
2199
2426
  }
2200
- function setContext(machine, newContextOrFn) {
2427
+ function setContext(machine2, newContextOrFn) {
2201
2428
  var _a;
2202
- const currentContext = machine.context;
2203
- const transitions = (_a = getStoredTransitions(machine)) != null ? _a : snapshotOwnTransitions(machine);
2429
+ const currentContext = machine2.context;
2430
+ const transitions = (_a = getStoredTransitions(machine2)) != null ? _a : snapshotOwnTransitions(machine2);
2204
2431
  const newContext = typeof newContextOrFn === "function" ? newContextOrFn(currentContext) : newContextOrFn;
2205
2432
  return createMachine(newContext, transitions);
2206
2433
  }
2207
2434
  function createContext(context) {
2208
2435
  return { context };
2209
2436
  }
2210
- function overrideTransitions(machine, overrides) {
2211
- const { context, ...originalTransitions } = machine;
2437
+ function overrideTransitions(machine2, overrides) {
2438
+ const { context, ...originalTransitions } = machine2;
2212
2439
  const newTransitions = { ...originalTransitions, ...overrides };
2213
2440
  return createMachine(context, newTransitions);
2214
2441
  }
2215
- function extendTransitions(machine, newTransitions) {
2216
- const { context, ...originalTransitions } = machine;
2442
+ function extendTransitions(machine2, newTransitions) {
2443
+ const { context, ...originalTransitions } = machine2;
2217
2444
  const combinedTransitions = { ...originalTransitions, ...newTransitions };
2218
2445
  return createMachine(context, combinedTransitions);
2219
2446
  }
@@ -2234,16 +2461,16 @@ function createMachineBuilder(templateMachine) {
2234
2461
  return createMachine(newContext, transitions);
2235
2462
  };
2236
2463
  }
2237
- function matchMachine(machine, discriminantKey, handlers) {
2238
- const discriminant = machine.context[discriminantKey];
2464
+ function matchMachine(machine2, discriminantKey, handlers) {
2465
+ const discriminant = machine2.context[discriminantKey];
2239
2466
  const handler = handlers[discriminant];
2240
2467
  if (!handler) {
2241
2468
  throw new Error(`No handler found for state: ${String(discriminant)}`);
2242
2469
  }
2243
- return handler(machine.context);
2470
+ return handler(machine2.context);
2244
2471
  }
2245
- function hasState(machine, key, value) {
2246
- return machine.context[key] === value;
2472
+ function hasState(machine2, key, value) {
2473
+ return machine2.context[key] === value;
2247
2474
  }
2248
2475
  function runMachine(initial, onChange) {
2249
2476
  let current = initial;
@@ -2290,15 +2517,6 @@ function runMachine(initial, onChange) {
2290
2517
  }
2291
2518
  };
2292
2519
  }
2293
- var MachineBase = class {
2294
- /**
2295
- * Initializes a new machine instance with its starting context.
2296
- * @param context - The initial state of the machine.
2297
- */
2298
- constructor(context) {
2299
- this.context = context;
2300
- }
2301
- };
2302
2520
  function next(m, update) {
2303
2521
  return setContext(m, (ctx) => update(ctx));
2304
2522
  }