@xmachines/docs 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/api/@xmachines/play/README.md +130 -0
  4. package/api/@xmachines/play/type-aliases/PlayEvent.md +81 -0
  5. package/api/@xmachines/play-actor/README.md +247 -0
  6. package/api/@xmachines/play-actor/classes/AbstractActor.md +520 -0
  7. package/api/@xmachines/play-actor/interfaces/Routable.md +29 -0
  8. package/api/@xmachines/play-actor/interfaces/ViewMetadata.md +17 -0
  9. package/api/@xmachines/play-actor/interfaces/Viewable.md +12 -0
  10. package/api/@xmachines/play-catalog/README.md +331 -0
  11. package/api/@xmachines/play-catalog/functions/defineCatalog.md +98 -0
  12. package/api/@xmachines/play-catalog/functions/defineComponents.md +134 -0
  13. package/api/@xmachines/play-catalog/type-aliases/Catalog.md +48 -0
  14. package/api/@xmachines/play-catalog/type-aliases/ComponentsFor.md +20 -0
  15. package/api/@xmachines/play-catalog/type-aliases/InferComponentProps.md +65 -0
  16. package/api/@xmachines/play-catalog/type-aliases/NoExtraKeys.md +17 -0
  17. package/api/@xmachines/play-react/README.md +423 -0
  18. package/api/@xmachines/play-react/classes/PlayErrorBoundary.md +613 -0
  19. package/api/@xmachines/play-react/functions/useSignalEffect.md +68 -0
  20. package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryProps.md +15 -0
  21. package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryState.md +14 -0
  22. package/api/@xmachines/play-react/interfaces/PlayRendererProps.md +15 -0
  23. package/api/@xmachines/play-react/variables/PlayRenderer.md +64 -0
  24. package/api/@xmachines/play-react-router/README.md +198 -0
  25. package/api/@xmachines/play-react-router/classes/ReactRouterBridge.md +321 -0
  26. package/api/@xmachines/play-react-router/classes/RouteMap.md +137 -0
  27. package/api/@xmachines/play-react-router/functions/PlayRouterProvider.md +19 -0
  28. package/api/@xmachines/play-react-router/functions/createRouteMapFromTree.md +35 -0
  29. package/api/@xmachines/play-react-router/interfaces/PlayRouteEvent.md +119 -0
  30. package/api/@xmachines/play-react-router/interfaces/PlayRouterProviderProps.md +14 -0
  31. package/api/@xmachines/play-react-router/interfaces/RouteMapping.md +17 -0
  32. package/api/@xmachines/play-react-router/interfaces/RouterBridge.md +104 -0
  33. package/api/@xmachines/play-react-router-demo/README.md +137 -0
  34. package/api/@xmachines/play-router/README.md +502 -0
  35. package/api/@xmachines/play-router/classes/BaseRouteMap.md +142 -0
  36. package/api/@xmachines/play-router/classes/RouterBridgeBase.md +300 -0
  37. package/api/@xmachines/play-router/functions/buildRouteTree.md +27 -0
  38. package/api/@xmachines/play-router/functions/connectRouter.md +67 -0
  39. package/api/@xmachines/play-router/functions/crawlMachine.md +92 -0
  40. package/api/@xmachines/play-router/functions/createBrowserHistory.md +47 -0
  41. package/api/@xmachines/play-router/functions/createRouteMap.md +53 -0
  42. package/api/@xmachines/play-router/functions/createRouter.md +76 -0
  43. package/api/@xmachines/play-router/functions/detectDuplicateRoutes.md +32 -0
  44. package/api/@xmachines/play-router/functions/extractMachineRoutes.md +64 -0
  45. package/api/@xmachines/play-router/functions/extractRoute.md +45 -0
  46. package/api/@xmachines/play-router/functions/findRouteById.md +37 -0
  47. package/api/@xmachines/play-router/functions/findRouteByPath.md +39 -0
  48. package/api/@xmachines/play-router/functions/getNavigableRoutes.md +35 -0
  49. package/api/@xmachines/play-router/functions/getRoutableRoutes.md +39 -0
  50. package/api/@xmachines/play-router/functions/routeExists.md +26 -0
  51. package/api/@xmachines/play-router/functions/validateRouteFormat.md +29 -0
  52. package/api/@xmachines/play-router/functions/validateStateExists.md +29 -0
  53. package/api/@xmachines/play-router/interfaces/BaseRouteMapping.md +27 -0
  54. package/api/@xmachines/play-router/interfaces/BrowserHistory.md +172 -0
  55. package/api/@xmachines/play-router/interfaces/BrowserWindow.md +69 -0
  56. package/api/@xmachines/play-router/interfaces/ConnectRouterOptions.md +13 -0
  57. package/api/@xmachines/play-router/interfaces/PlayRouteEvent.md +119 -0
  58. package/api/@xmachines/play-router/interfaces/RouteInfo.md +19 -0
  59. package/api/@xmachines/play-router/interfaces/RouteMap.md +56 -0
  60. package/api/@xmachines/play-router/interfaces/RouteNode.md +21 -0
  61. package/api/@xmachines/play-router/interfaces/RouteObject.md +21 -0
  62. package/api/@xmachines/play-router/interfaces/RouteTree.md +20 -0
  63. package/api/@xmachines/play-router/interfaces/RouterBridge.md +104 -0
  64. package/api/@xmachines/play-router/interfaces/StateVisit.md +15 -0
  65. package/api/@xmachines/play-router/interfaces/VanillaRouter.md +28 -0
  66. package/api/@xmachines/play-router/type-aliases/RouteMetadata.md +11 -0
  67. package/api/@xmachines/play-router-demo/README.md +137 -0
  68. package/api/@xmachines/play-signals/README.md +176 -0
  69. package/api/@xmachines/play-signals/interfaces/ComputedOptions.md +34 -0
  70. package/api/@xmachines/play-signals/interfaces/SignalComputed.md +49 -0
  71. package/api/@xmachines/play-signals/interfaces/SignalOptions.md +35 -0
  72. package/api/@xmachines/play-signals/interfaces/SignalState.md +68 -0
  73. package/api/@xmachines/play-signals/interfaces/SignalWatcher.md +97 -0
  74. package/api/@xmachines/play-signals/namespaces/Signal/README.md +22 -0
  75. package/api/@xmachines/play-signals/namespaces/Signal/classes/Computed.md +52 -0
  76. package/api/@xmachines/play-signals/namespaces/Signal/classes/State.md +72 -0
  77. package/api/@xmachines/play-signals/namespaces/Signal/interfaces/Options.md +19 -0
  78. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/README.md +21 -0
  79. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/classes/Watcher.md +85 -0
  80. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/currentComputed.md +13 -0
  81. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/hasSinks.md +19 -0
  82. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/hasSources.md +19 -0
  83. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/introspectSinks.md +19 -0
  84. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/introspectSources.md +19 -0
  85. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/untrack.md +25 -0
  86. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/variables/unwatched.md +9 -0
  87. package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/variables/watched.md +9 -0
  88. package/api/@xmachines/play-signals/namespaces/Signal/variables/isComputed.md +19 -0
  89. package/api/@xmachines/play-signals/namespaces/Signal/variables/isState.md +19 -0
  90. package/api/@xmachines/play-signals/namespaces/Signal/variables/isWatcher.md +19 -0
  91. package/api/@xmachines/play-signals/type-aliases/WatcherNotify.md +32 -0
  92. package/api/@xmachines/play-solid/README.md +311 -0
  93. package/api/@xmachines/play-solid/interfaces/PlayRendererProps.md +15 -0
  94. package/api/@xmachines/play-solid/variables/PlayRenderer.md +70 -0
  95. package/api/@xmachines/play-solid-router/README.md +666 -0
  96. package/api/@xmachines/play-solid-router/classes/RouteMap.md +150 -0
  97. package/api/@xmachines/play-solid-router/classes/SolidRouterBridge.md +347 -0
  98. package/api/@xmachines/play-solid-router/functions/PlayRouterProvider.md +19 -0
  99. package/api/@xmachines/play-solid-router/functions/createRouteMap.md +32 -0
  100. package/api/@xmachines/play-solid-router/interfaces/AbstractActor.md +486 -0
  101. package/api/@xmachines/play-solid-router/interfaces/PlayRouteEvent.md +119 -0
  102. package/api/@xmachines/play-solid-router/interfaces/PlayRouterProviderProps.md +14 -0
  103. package/api/@xmachines/play-solid-router/interfaces/RouteMapping.md +14 -0
  104. package/api/@xmachines/play-solid-router/interfaces/RouterBridge.md +104 -0
  105. package/api/@xmachines/play-solid-router/type-aliases/RoutableActor.md +9 -0
  106. package/api/@xmachines/play-solid-router/type-aliases/SolidRouterHooks.md +51 -0
  107. package/api/@xmachines/play-solid-router-demo/README.md +127 -0
  108. package/api/@xmachines/play-tanstack-react-router/README.md +226 -0
  109. package/api/@xmachines/play-tanstack-react-router/classes/RouteMap.md +137 -0
  110. package/api/@xmachines/play-tanstack-react-router/classes/TanStackReactRouterBridge.md +348 -0
  111. package/api/@xmachines/play-tanstack-react-router/functions/PlayRouterProvider.md +19 -0
  112. package/api/@xmachines/play-tanstack-react-router/functions/createRouteMap.md +53 -0
  113. package/api/@xmachines/play-tanstack-react-router/functions/createRouteMapFromTree.md +35 -0
  114. package/api/@xmachines/play-tanstack-react-router/functions/extractParams.md +38 -0
  115. package/api/@xmachines/play-tanstack-react-router/functions/extractQueryParams.md +33 -0
  116. package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouteEvent.md +119 -0
  117. package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouterProviderProps.md +14 -0
  118. package/api/@xmachines/play-tanstack-react-router/interfaces/RouteMapping.md +17 -0
  119. package/api/@xmachines/play-tanstack-react-router/interfaces/RouteNavigateEvent.md +26 -0
  120. package/api/@xmachines/play-tanstack-react-router/interfaces/RouterBridge.md +104 -0
  121. package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterInstance.md +9 -0
  122. package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterLike.md +78 -0
  123. package/api/@xmachines/play-tanstack-react-router/variables/extractMachineRoutes.md +64 -0
  124. package/api/@xmachines/play-tanstack-react-router-demo/README.md +126 -0
  125. package/api/@xmachines/play-tanstack-solid-router/README.md +285 -0
  126. package/api/@xmachines/play-tanstack-solid-router/classes/RouteMap.md +150 -0
  127. package/api/@xmachines/play-tanstack-solid-router/classes/SolidRouterBridge.md +343 -0
  128. package/api/@xmachines/play-tanstack-solid-router/functions/PlayRouterProvider.md +19 -0
  129. package/api/@xmachines/play-tanstack-solid-router/functions/createRouteMap.md +32 -0
  130. package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouteEvent.md +119 -0
  131. package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouterProviderProps.md +14 -0
  132. package/api/@xmachines/play-tanstack-solid-router/interfaces/RouteMapping.md +23 -0
  133. package/api/@xmachines/play-tanstack-solid-router/interfaces/RouterBridge.md +104 -0
  134. package/api/@xmachines/play-tanstack-solid-router/type-aliases/RoutableActor.md +9 -0
  135. package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterInstance.md +9 -0
  136. package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterLike.md +78 -0
  137. package/api/@xmachines/play-tanstack-solid-router-demo/README.md +126 -0
  138. package/api/@xmachines/play-vue/README.md +292 -0
  139. package/api/@xmachines/play-vue/interfaces/PlayRendererProps.md +14 -0
  140. package/api/@xmachines/play-vue/variables/PlayRenderer.md +9 -0
  141. package/api/@xmachines/play-vue-router/README.md +604 -0
  142. package/api/@xmachines/play-vue-router/classes/RouteMap.md +209 -0
  143. package/api/@xmachines/play-vue-router/classes/VueBaseRouteMap.md +201 -0
  144. package/api/@xmachines/play-vue-router/classes/VueRouterBridge.md +360 -0
  145. package/api/@xmachines/play-vue-router/functions/createRouteMap.md +19 -0
  146. package/api/@xmachines/play-vue-router/interfaces/PlayRouteEvent.md +119 -0
  147. package/api/@xmachines/play-vue-router/interfaces/RouteMapping.md +15 -0
  148. package/api/@xmachines/play-vue-router/interfaces/RouterBridge.md +104 -0
  149. package/api/@xmachines/play-vue-router/type-aliases/RoutableActor.md +9 -0
  150. package/api/@xmachines/play-vue-router/variables/PlayRouterProvider.md +67 -0
  151. package/api/@xmachines/play-vue-router-demo/README.md +133 -0
  152. package/api/@xmachines/play-xstate/README.md +512 -0
  153. package/api/@xmachines/play-xstate/classes/PlayerActor.md +527 -0
  154. package/api/@xmachines/play-xstate/functions/buildRouteUrl.md +43 -0
  155. package/api/@xmachines/play-xstate/functions/composeGuards.md +79 -0
  156. package/api/@xmachines/play-xstate/functions/composeGuardsOr.md +67 -0
  157. package/api/@xmachines/play-xstate/functions/definePlayer.md +127 -0
  158. package/api/@xmachines/play-xstate/functions/deriveRoute.md +109 -0
  159. package/api/@xmachines/play-xstate/functions/eventMatches.md +40 -0
  160. package/api/@xmachines/play-xstate/functions/formatPlayRouteTransitions.md +54 -0
  161. package/api/@xmachines/play-xstate/functions/hasContext.md +42 -0
  162. package/api/@xmachines/play-xstate/functions/isAbsoluteRoute.md +41 -0
  163. package/api/@xmachines/play-xstate/functions/mergeViewProps.md +26 -0
  164. package/api/@xmachines/play-xstate/functions/negateGuard.md +61 -0
  165. package/api/@xmachines/play-xstate/functions/stateMatches.md +25 -0
  166. package/api/@xmachines/play-xstate/functions/validateComponentBinding.md +39 -0
  167. package/api/@xmachines/play-xstate/functions/validateViewProps.md +80 -0
  168. package/api/@xmachines/play-xstate/interfaces/CatalogEntry.md +16 -0
  169. package/api/@xmachines/play-xstate/interfaces/PlayerConfig.md +24 -0
  170. package/api/@xmachines/play-xstate/interfaces/PlayerOptions.md +26 -0
  171. package/api/@xmachines/play-xstate/interfaces/RouteContext.md +22 -0
  172. package/api/@xmachines/play-xstate/type-aliases/Catalog.md +21 -0
  173. package/api/@xmachines/play-xstate/type-aliases/ComposedGuard.md +14 -0
  174. package/api/@xmachines/play-xstate/type-aliases/Guard.md +34 -0
  175. package/api/@xmachines/play-xstate/type-aliases/GuardArray.md +20 -0
  176. package/api/@xmachines/play-xstate/type-aliases/PlayerFactory.md +29 -0
  177. package/api/@xmachines/play-xstate/type-aliases/RouteMachineConfig.md +45 -0
  178. package/api/@xmachines/play-xstate/type-aliases/RouteStateNode.md +51 -0
  179. package/api/@xmachines/play-xstate/type-aliases/ValidationResult.md +17 -0
  180. package/api/@xmachines/play-xstate/type-aliases/ViewMergeContext.md +35 -0
  181. package/api/@xmachines/shared/README.md +379 -0
  182. package/api/@xmachines/shared/functions/defineXmVitestConfig.md +29 -0
  183. package/api/@xmachines/shared/functions/xmAliases.md +24 -0
  184. package/api/README.md +25 -0
  185. package/api/llms.txt +26 -0
  186. package/examples/README.md +63 -0
  187. package/examples/basic-state-machine.md +70 -0
  188. package/examples/form-validation.md +167 -0
  189. package/examples/multi-router-integration.md +277 -0
  190. package/examples/routing-patterns.md +260 -0
  191. package/examples/traffic-light.md +99 -0
  192. package/guides/README.md +29 -0
  193. package/guides/getting-started.md +223 -0
  194. package/guides/installation.md +323 -0
  195. package/index.d.ts +3 -0
  196. package/index.js +4 -0
  197. package/package.json +54 -0
@@ -0,0 +1,99 @@
1
+ # Traffic Light State Machine
2
+
3
+ Multi-state machine with automatic transitions demonstrating cyclic state flows.
4
+
5
+ ## Use Case
6
+
7
+ This example models a traffic light with a red → green → yellow → red cycle. It demonstrates how to handle multiple states with cyclic transitions, making it useful for:
8
+
9
+ - Traffic light controllers
10
+ - Multi-step workflows with repeating cycles
11
+ - Game state loops (menu → playing → game over → menu)
12
+ - Carousel or slideshow controls
13
+
14
+ ## Complete Code
15
+
16
+ ```typescript
17
+ import { createMachine } from "xstate";
18
+
19
+ // Define states
20
+ type TrafficState = "red" | "yellow" | "green";
21
+
22
+ // Define events
23
+ type TrafficEvent = { type: "TIMER" };
24
+
25
+ // Create machine
26
+ const trafficMachine = createMachine<TrafficState, TrafficEvent>({
27
+ id: "traffic",
28
+ initial: "red",
29
+ states: {
30
+ red: {
31
+ on: {
32
+ TIMER: "green",
33
+ },
34
+ },
35
+ green: {
36
+ on: {
37
+ TIMER: "yellow",
38
+ },
39
+ },
40
+ yellow: {
41
+ on: {
42
+ TIMER: "red",
43
+ },
44
+ },
45
+ },
46
+ });
47
+
48
+ // Usage with timer
49
+ let state = trafficMachine.initialState;
50
+ console.log(state); // 'red'
51
+
52
+ // Simulate automatic transitions
53
+ setInterval(() => {
54
+ state = trafficMachine.transition(state, { type: "TIMER" });
55
+ console.log(`Light changed to: ${state}`);
56
+ }, 3000); // Change every 3 seconds
57
+ ```
58
+
59
+ ## Code Explanation
60
+
61
+ 1. **Multiple states** - Defines three distinct states (`'red'`, `'yellow'`, `'green'`) instead of just two, showing how state machines scale beyond binary toggles.
62
+
63
+ 2. **Cyclic transitions** - Each state transitions to the next state in the cycle when receiving a `TIMER` event, creating a continuous loop.
64
+
65
+ 3. **Timer integration** - Uses `setInterval` to automatically trigger state transitions, demonstrating how external timing mechanisms integrate with state machines.
66
+
67
+ 4. **Deterministic behavior** - No matter how many cycles complete, the state is always predictable based on the number of `TIMER` events received.
68
+
69
+ ## Key Concepts
70
+
71
+ - **Multi-state machines**: Not limited to two states - model complex workflows with many states
72
+ - **Cyclic transitions**: States can form loops, returning to previous states in a predictable pattern
73
+ - **External triggers**: State machines react to external events like timers, user actions, or network responses
74
+ - **Deterministic**: Same sequence of events always produces the same sequence of states
75
+
76
+ ## Variations
77
+
78
+ **Different timing per state:**
79
+
80
+ ```typescript
81
+ const timings = { red: 5000, green: 4000, yellow: 2000 };
82
+ let state = trafficMachine.initialState;
83
+
84
+ function scheduleNext() {
85
+ setTimeout(() => {
86
+ state = trafficMachine.transition(state, { type: "TIMER" });
87
+ console.log(`Light: ${state}`);
88
+ scheduleNext();
89
+ }, timings[state]);
90
+ }
91
+
92
+ scheduleNext();
93
+ ```
94
+
95
+ ## Next Steps
96
+
97
+ - **[Form Validation Example](form-validation.md)** - Learn about guards and conditional transitions
98
+ - **[Basic State Machine](basic-state-machine.md)** - Return to foundational concepts
99
+ - **[API Documentation](/docs/api/xmachines/play/readme)** - Explore advanced features like actions and context
@@ -0,0 +1,29 @@
1
+ # XMachines Guides
2
+
3
+ Entry points for current XMachines Play architecture and package documentation.
4
+
5
+ ## Start Here
6
+
7
+ - [Root README](../../README.md) - Monorepo overview and architecture invariants
8
+ - [Examples Index](../examples/README.md) - Runnable and conceptual usage patterns
9
+
10
+ ## Router Adapter Guides
11
+
12
+ Use these READMEs for the current RouterBridge-first integrations:
13
+
14
+ - [@xmachines/play-router](../../packages/play-router/README.md) - Route extraction, route maps, and `RouterBridgeBase`
15
+ - [@xmachines/play-tanstack-react-router](../../packages/play-tanstack-react-router/README.md) - TanStack React adapter
16
+ - [@xmachines/play-react-router](../../packages/play-react-router/README.md) - `react-router` v7 data-router adapter
17
+ - [@xmachines/play-tanstack-solid-router](../../packages/play-tanstack-solid-router/README.md) - TanStack Solid adapter
18
+ - [@xmachines/play-solid-router](../../packages/play-solid-router/README.md) - SolidJS Router adapter
19
+ - [@xmachines/play-vue-router](../../packages/play-vue-router/README.md) - Vue Router adapter
20
+
21
+ ## Core Runtime Guides
22
+
23
+ - [@xmachines/play-xstate](../../packages/play-xstate/README.md) - `definePlayer`, routing transitions, and actor lifecycle
24
+ - [@xmachines/play-react](../../packages/play-react/README.md) - React rendering from actor-driven view state
25
+ - [@xmachines/play-catalog](../../packages/play-catalog/README.md) - Catalog and schema contracts
26
+
27
+ ## API Reference
28
+
29
+ - [/docs/api](/docs/api) - Generated API docs for all public packages
@@ -0,0 +1,223 @@
1
+ # Getting Started
2
+
3
+ Welcome to XMachines! This guide will help you understand what XMachines is and get you up and running with your first state machine.
4
+
5
+ ## What is XMachines?
6
+
7
+ XMachines is a TypeScript implementation of the Universal Player Architecture—a state machine library that strictly separates business logic from infrastructure. It enables logic-driven applications where state machines control routing, views, and navigation through standardized TC39 Signals.
8
+
9
+ At its core, XMachines is built on the actor model, following the principle that **business logic must be the single source of truth** for navigation, state, and UI structure. Infrastructure reflects actor state—it never decides.
10
+
11
+ Unlike traditional frameworks where your logic adapts to the framework, XMachines inverts this relationship. Your state machines own the application behavior, and the infrastructure (routers, view renderers, React components) passively observes and reflects the current state through signals. This results in complete runtime agnosticism—your logic has zero framework dependencies.
12
+
13
+ ## Why XMachines?
14
+
15
+ **Type Safety with TypeScript**
16
+
17
+ - Full type inference from state machine catalog through to components
18
+ - Catch navigation errors and state bugs at compile time
19
+ - Zod validation for UI schemas and state structures
20
+
21
+ **Predictable State Management**
22
+
23
+ - State machines make application behavior explicit and testable
24
+ - Actor model ensures clear message passing patterns
25
+ - Guard enforcement prevents invalid state transitions
26
+
27
+ **Platform Flexibility**
28
+
29
+ - Runtime-agnostic core packages work in browser, Node, or Deno
30
+ - Choose only the packages you need for your platform
31
+ - Framework integrations (React, TanStack Router) are optional adapters
32
+
33
+ **Modular Architecture**
34
+
35
+ - 8 focused packages that work together seamlessly
36
+ - `@xmachines/play` foundation works with any infrastructure
37
+ - Mix and match adapters based on your stack
38
+
39
+ ## Quick Start
40
+
41
+ ### Installation
42
+
43
+ First, install XMachines packages. See the complete [Installation →](installation.md) guide for all package managers and environments.
44
+
45
+ ```bash
46
+ npm install @xmachines/play @xmachines/play-xstate
47
+ ```
48
+
49
+ ### Import and Create Your First Machine
50
+
51
+ ```typescript
52
+ import { createMachine } from "@xmachines/play-xstate";
53
+
54
+ // Define a simple traffic light machine
55
+ const trafficLightMachine = createMachine({
56
+ id: "trafficLight",
57
+ initial: "red",
58
+ states: {
59
+ red: {
60
+ on: { TIMER: "green" },
61
+ },
62
+ green: {
63
+ on: { TIMER: "yellow" },
64
+ },
65
+ yellow: {
66
+ on: { TIMER: "red" },
67
+ },
68
+ },
69
+ });
70
+ ```
71
+
72
+ ### Create an Actor and Transition States
73
+
74
+ ```typescript
75
+ import { createActor } from "@xmachines/play-actor";
76
+
77
+ // Instantiate the machine as an actor
78
+ const actor = createActor(trafficLightMachine);
79
+
80
+ // Start the actor
81
+ actor.start();
82
+
83
+ // Check initial state
84
+ console.log(actor.getSnapshot().value); // "red"
85
+
86
+ // Send events to transition states
87
+ actor.send({ type: "TIMER" });
88
+ console.log(actor.getSnapshot().value); // "green"
89
+
90
+ actor.send({ type: "TIMER" });
91
+ console.log(actor.getSnapshot().value); // "yellow"
92
+ ```
93
+
94
+ ### Observe State Changes with Signals
95
+
96
+ ```typescript
97
+ import { signal, computed } from "@xmachines/play-signals";
98
+
99
+ // Create a signal to track actor state
100
+ const currentState = signal(actor.getSnapshot().value);
101
+
102
+ // Subscribe to actor changes
103
+ actor.subscribe((snapshot) => {
104
+ currentState.value = snapshot.value;
105
+ });
106
+
107
+ // Create computed values
108
+ const canProceed = computed(() => currentState.value === "green");
109
+
110
+ console.log(canProceed.value); // true when light is green
111
+ ```
112
+
113
+ ## Your First Machine: Toggle Example
114
+
115
+ Here's a complete working example that demonstrates the core concepts:
116
+
117
+ ```typescript
118
+ import { createMachine } from "@xmachines/play-xstate";
119
+ import { createActor } from "@xmachines/play-actor";
120
+ import { signal } from "@xmachines/play-signals";
121
+
122
+ // Define the machine configuration
123
+ const toggleMachine = createMachine(
124
+ {
125
+ id: "toggle",
126
+ initial: "inactive",
127
+ context: {
128
+ count: 0,
129
+ },
130
+ states: {
131
+ inactive: {
132
+ on: {
133
+ TOGGLE: {
134
+ target: "active",
135
+ actions: "incrementCount",
136
+ },
137
+ },
138
+ },
139
+ active: {
140
+ on: {
141
+ TOGGLE: {
142
+ target: "inactive",
143
+ actions: "incrementCount",
144
+ },
145
+ },
146
+ },
147
+ },
148
+ },
149
+ {
150
+ actions: {
151
+ incrementCount: ({ context }) => ({
152
+ count: context.count + 1,
153
+ }),
154
+ },
155
+ },
156
+ );
157
+
158
+ // Create and start the actor
159
+ const toggleActor = createActor(toggleMachine);
160
+ toggleActor.start();
161
+
162
+ // Bind to a signal for reactive updates
163
+ const state = signal(toggleActor.getSnapshot());
164
+
165
+ toggleActor.subscribe((snapshot) => {
166
+ state.value = snapshot;
167
+ });
168
+
169
+ // Use the machine
170
+ toggleActor.send({ type: "TOGGLE" });
171
+ console.log(state.value.value); // "active"
172
+ console.log(state.value.context.count); // 1
173
+
174
+ toggleActor.send({ type: "TOGGLE" });
175
+ console.log(state.value.value); // "inactive"
176
+ console.log(state.value.context.count); // 2
177
+ ```
178
+
179
+ ### Understanding the Parts
180
+
181
+ **States**: Discrete modes your application can be in (`inactive`, `active`)
182
+
183
+ **Events**: Messages that trigger transitions (`TOGGLE`)
184
+
185
+ **Transitions**: Rules that define which events move between which states (`on: { TOGGLE: 'active' }`)
186
+
187
+ **Context**: Extended state data that persists across transitions (`count: 0`)
188
+
189
+ **Actions**: Side effects or context updates executed during transitions (`incrementCount`)
190
+
191
+ **Actor**: Runtime instance of a machine that processes events and emits state changes
192
+
193
+ **Signals**: Reactive primitives (TC39 Signals) that enable infrastructure to observe state changes without coupling
194
+
195
+ ## Next Steps
196
+
197
+ Now that you understand the basics, explore these resources:
198
+
199
+ **Core Documentation**
200
+
201
+ - [Core Concepts](/docs/api/guides/core-concepts) - Deep dive into architecture and patterns
202
+ - [Package Overview](/docs/api/guides/package-overview) - Choose the right packages for your needs
203
+ - [API Reference](/docs/api/xmachines/play/readme) - Detailed API documentation
204
+
205
+ **Platform Guides**
206
+
207
+ - [React Integration](/docs/api/xmachines/play-react/readme) - Use XMachines with React
208
+ - [Router Integration](/docs/api/xmachines/play-tanstack-react-router/readme) - Logic-driven routing with TanStack Router
209
+ - [UI Schemas](/docs/api/xmachines/play-ui/readme) - Define UI structure from state
210
+
211
+ **Examples**
212
+
213
+ - [Examples Directory](/examples) - More code examples and usage patterns
214
+ - Working dashboard demo (coming soon)
215
+
216
+ **Architecture**
217
+
218
+ - [RFC Specification](/rfc) - Complete architectural specification
219
+ - [Architecture Docs](/architecture) - System design and technical decisions
220
+
221
+ ---
222
+
223
+ **Ready to install?** → [Installation Guide](installation.md)
@@ -0,0 +1,323 @@
1
+ # Installation
2
+
3
+ This guide covers installing XMachines packages in your project across different package managers and environments.
4
+
5
+ ## Prerequisites
6
+
7
+ Before installing XMachines, ensure you have:
8
+
9
+ - **Node.js 22+** (or compatible runtime)
10
+ - **Package manager**: npm, pnpm, or yarn
11
+ - **TypeScript** (optional but recommended for full type safety)
12
+
13
+ ## Installing XMachines
14
+
15
+ Choose your preferred package manager:
16
+
17
+ ### npm
18
+
19
+ ```bash
20
+ npm install @xmachines/play @xmachines/play-xstate @xmachines/play-actor @xmachines/play-signals
21
+ ```
22
+
23
+ ### pnpm
24
+
25
+ ```bash
26
+ pnpm add @xmachines/play @xmachines/play-xstate @xmachines/play-actor @xmachines/play-signals
27
+ ```
28
+
29
+ ### yarn
30
+
31
+ ```bash
32
+ yarn add @xmachines/play @xmachines/play-xstate @xmachines/play-actor @xmachines/play-signals
33
+ ```
34
+
35
+ ## Package Selection Guide
36
+
37
+ XMachines consists of 8 modular packages. Choose the packages based on your needs:
38
+
39
+ ### Core Packages (Required)
40
+
41
+ **@xmachines/play**
42
+
43
+ - Foundation package with core protocols and contracts
44
+ - Required by all other packages
45
+
46
+ **@xmachines/play-actor**
47
+
48
+ - Abstract actor base class extending XState Actor
49
+ - Required for instantiating state machines
50
+
51
+ **@xmachines/play-signals**
52
+
53
+ - TC39 Signals polyfill for reactive updates
54
+ - Required for reactive state observation
55
+
56
+ **@xmachines/play-xstate**
57
+
58
+ - XState v5 logic adapter with catalog binding
59
+ - Required for state machine definitions
60
+
61
+ **Minimal installation:**
62
+
63
+ ```bash
64
+ npm install @xmachines/play @xmachines/play-xstate @xmachines/play-actor @xmachines/play-signals
65
+ ```
66
+
67
+ ### UI and Routing (Optional)
68
+
69
+ **@xmachines/play-ui**
70
+
71
+ - UI schema protocol with Zod validation
72
+ - Install if: Building declarative UI structures from state
73
+
74
+ **@xmachines/play-router**
75
+
76
+ - Route tree protocol and machine crawler
77
+ - Install if: Implementing logic-driven routing
78
+
79
+ **@xmachines/play-tanstack-react-router**
80
+
81
+ - TanStack Router adapter with signal observation
82
+ - Install if: Using TanStack Router for navigation
83
+
84
+ **@xmachines/play-react**
85
+
86
+ - React view renderer with JSON-Render
87
+ - Install if: Building React applications
88
+
89
+ **@xmachines/play-catalog**
90
+
91
+ - State machine catalog and registry patterns
92
+ - Install if: Managing multiple machines with type inference
93
+
94
+ ### Complete Installation
95
+
96
+ For full-featured development with React and routing:
97
+
98
+ ```bash
99
+ npm install @xmachines/play @xmachines/play-xstate @xmachines/play-actor @xmachines/play-signals @xmachines/play-ui @xmachines/play-router @xmachines/play-tanstack-react-router @xmachines/play-react @xmachines/play-catalog
100
+ ```
101
+
102
+ **See also:** [Package Overview](/docs/api/guides/package-overview) for detailed descriptions of each package.
103
+
104
+ ## Environment-Specific Setup
105
+
106
+ ### Browser (Vite, Webpack, or other bundlers)
107
+
108
+ No special configuration needed. ESM imports work out of the box:
109
+
110
+ ```typescript
111
+ import { createMachine } from "@xmachines/play-xstate";
112
+ import { createActor } from "@xmachines/play-actor";
113
+ import { signal } from "@xmachines/play-signals";
114
+ ```
115
+
116
+ Most modern bundlers (Vite, Webpack 5+, Rollup) handle ESM packages automatically.
117
+
118
+ ### Node.js
119
+
120
+ XMachines uses ESM (ECMAScript Modules) exclusively. Ensure your project is configured for ESM:
121
+
122
+ **Option 1: Set `"type": "module"` in package.json**
123
+
124
+ ```json
125
+ {
126
+ "type": "module",
127
+ "dependencies": {
128
+ "@xmachines/play": "^1.0.0"
129
+ }
130
+ }
131
+ ```
132
+
133
+ **Option 2: Use `.mjs` file extensions**
134
+
135
+ Alternatively, name your files with `.mjs` extension:
136
+
137
+ ```bash
138
+ node my-app.mjs
139
+ ```
140
+
141
+ **Import example:**
142
+
143
+ ```typescript
144
+ import { createMachine } from "@xmachines/play-xstate";
145
+ import { createActor } from "@xmachines/play-actor";
146
+
147
+ const machine = createMachine({
148
+ id: "example",
149
+ initial: "idle",
150
+ states: {
151
+ idle: { on: { START: "running" } },
152
+ running: { on: { STOP: "idle" } },
153
+ },
154
+ });
155
+
156
+ const actor = createActor(machine);
157
+ actor.start();
158
+ ```
159
+
160
+ ### Deno
161
+
162
+ XMachines works with Deno via npm specifiers:
163
+
164
+ ```typescript
165
+ import { createMachine } from "npm:@xmachines/play-xstate";
166
+ import { createActor } from "npm:@xmachines/play-actor";
167
+ import { signal } from "npm:@xmachines/play-signals";
168
+ ```
169
+
170
+ Alternatively, use a CDN like esm.sh:
171
+
172
+ ```typescript
173
+ import { createMachine } from "https://esm.sh/@xmachines/play-xstate";
174
+ ```
175
+
176
+ ### TypeScript
177
+
178
+ XMachines is written in TypeScript and includes built-in type definitions. No separate `@types` package is needed.
179
+
180
+ **Recommended tsconfig.json settings:**
181
+
182
+ ```json
183
+ {
184
+ "compilerOptions": {
185
+ "target": "ESNext",
186
+ "module": "ESNext",
187
+ "moduleResolution": "bundler",
188
+ "strict": true,
189
+ "esModuleInterop": true,
190
+ "skipLibCheck": false,
191
+ "resolveJsonModule": true
192
+ }
193
+ }
194
+ ```
195
+
196
+ **Key settings:**
197
+
198
+ - **`moduleResolution: "bundler"`** (recommended) or `"node16"` for Node.js projects
199
+ - **`strict: true`** enables full type checking
200
+ - **`target: "ESNext"`** leverages modern JavaScript features
201
+
202
+ **Type inference:**
203
+
204
+ XMachines provides full type inference from machine catalog through to components:
205
+
206
+ ```typescript
207
+ import { createMachine } from "@xmachines/play-xstate";
208
+
209
+ const machine = createMachine({
210
+ id: "typed",
211
+ initial: "idle",
212
+ context: { count: 0 },
213
+ states: {
214
+ idle: { on: { START: "running" } },
215
+ running: { on: { STOP: "idle" } },
216
+ },
217
+ });
218
+
219
+ // TypeScript infers exact state types
220
+ type States = typeof machine.states; // "idle" | "running"
221
+ ```
222
+
223
+ ## Verifying Installation
224
+
225
+ Test your installation with this simple script:
226
+
227
+ **test.ts** (or test.js with `"type": "module"`):
228
+
229
+ ```typescript
230
+ import { createMachine } from "@xmachines/play-xstate";
231
+ import { createActor } from "@xmachines/play-actor";
232
+
233
+ const machine = createMachine({
234
+ id: "test",
235
+ initial: "ready",
236
+ states: {
237
+ ready: {},
238
+ },
239
+ });
240
+
241
+ const actor = createActor(machine);
242
+ actor.start();
243
+
244
+ console.log("✓ XMachines installed successfully");
245
+ console.log("Current state:", actor.getSnapshot().value);
246
+ ```
247
+
248
+ **Run the test:**
249
+
250
+ ```bash
251
+ # TypeScript (requires tsx or ts-node)
252
+ npx tsx test.ts
253
+
254
+ # Or compile first
255
+ npx tsc test.ts && node test.js
256
+
257
+ # JavaScript (with "type": "module")
258
+ node test.js
259
+ ```
260
+
261
+ **Expected output:**
262
+
263
+ ```
264
+ ✓ XMachines installed successfully
265
+ Current state: ready
266
+ ```
267
+
268
+ ## Troubleshooting
269
+
270
+ ### Module Not Found
271
+
272
+ **Error:** `Cannot find module '@xmachines/play-xstate'`
273
+
274
+ **Solutions:**
275
+
276
+ - Verify package is installed: `npm list @xmachines/play-xstate`
277
+ - Re-install dependencies: `npm install`
278
+ - Check `node_modules/@xmachines/` directory exists
279
+
280
+ ### ESM Import Errors
281
+
282
+ **Error:** `SyntaxError: Cannot use import statement outside a module`
283
+
284
+ **Solutions:**
285
+
286
+ - Add `"type": "module"` to package.json
287
+ - Or rename files to `.mjs` extension
288
+ - Or use dynamic import: `const { createMachine } = await import('@xmachines/play-xstate')`
289
+
290
+ ### Type Errors
291
+
292
+ **Error:** `Could not find a declaration file for module '@xmachines/play-xstate'`
293
+
294
+ **Solutions:**
295
+
296
+ - Types are built-in; no `@types` package needed
297
+ - Check TypeScript version (4.5+ required)
298
+ - Verify `moduleResolution` in tsconfig.json is set correctly
299
+ - Try `npm install` again to ensure types are properly linked
300
+
301
+ ### Version Mismatches
302
+
303
+ **Error:** Type incompatibilities between packages
304
+
305
+ **Solution:**
306
+ Install all XMachines packages with matching major versions:
307
+
308
+ ```bash
309
+ npm install @xmachines/play@latest @xmachines/play-xstate@latest @xmachines/play-actor@latest @xmachines/play-signals@latest
310
+ ```
311
+
312
+ ## Next Steps
313
+
314
+ Now that XMachines is installed, you're ready to build your first state machine:
315
+
316
+ - **[Getting Started →](getting-started.md)** - Build your first state machine
317
+ - **[Core Concepts](/docs/api/guides/core-concepts)** - Understand the architecture
318
+ - **[Package Overview](/docs/api/guides/package-overview)** - Deep dive into each package
319
+ - **[Examples](/examples)** - See XMachines in action
320
+
321
+ ---
322
+
323
+ **Need help?** Check the [Architecture Documentation](/architecture) or [API Reference](/docs/api) for detailed information.
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const url: string;
2
+
3
+ export default url;
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Public URL for the docs package entry.
3
+ */
4
+ export default import.meta.url;