@stacksjs/stx 0.1.16 → 0.2.3

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 (277) hide show
  1. package/dist/a11y.d.ts +109 -5
  2. package/dist/analytics.d.ts +40 -0
  3. package/dist/animation.d.ts +91 -1
  4. package/dist/app.d.ts +51 -0
  5. package/dist/ast.d.ts +286 -0
  6. package/dist/async-components.d.ts +101 -0
  7. package/dist/auth.d.ts +1 -3
  8. package/dist/browser-composables.d.ts +314 -0
  9. package/dist/build-optimizer.d.ts +126 -0
  10. package/dist/build-views.d.ts +37 -0
  11. package/dist/bundle-analyzer/collector.d.ts +66 -0
  12. package/dist/bundle-analyzer/index.d.ts +60 -0
  13. package/dist/bundle-analyzer/report.d.ts +39 -0
  14. package/dist/bundle-analyzer/treemap.d.ts +19 -0
  15. package/dist/bundle-analyzer.js +499 -0
  16. package/dist/caching.d.ts +7 -0
  17. package/dist/cli.js +10885 -1203
  18. package/dist/client/directive.d.ts +10 -0
  19. package/dist/client/index.d.ts +7 -0
  20. package/dist/client/router.d.ts +36 -0
  21. package/dist/client/stx-router.browser.d.ts +0 -0
  22. package/dist/client-script.d.ts +22 -0
  23. package/dist/component-hmr.d.ts +120 -0
  24. package/dist/components.d.ts +23 -1
  25. package/dist/composables/index.d.ts +277 -0
  26. package/dist/composables/use-battery.d.ts +46 -0
  27. package/dist/composables/use-broadcast-channel.d.ts +58 -0
  28. package/dist/composables/use-clipboard.d.ts +34 -0
  29. package/dist/composables/use-cookie.d.ts +70 -0
  30. package/dist/composables/use-device-orientation.d.ts +109 -0
  31. package/dist/composables/use-event-source.d.ts +77 -0
  32. package/dist/composables/use-eye-dropper.d.ts +107 -0
  33. package/dist/composables/use-fetch.d.ts +84 -0
  34. package/dist/composables/use-fullscreen.d.ts +47 -0
  35. package/dist/composables/use-geolocation.d.ts +62 -0
  36. package/dist/composables/use-idle.d.ts +84 -0
  37. package/dist/composables/use-intersection-observer.d.ts +81 -0
  38. package/dist/composables/use-keyboard.d.ts +100 -0
  39. package/dist/composables/use-media-query.d.ts +56 -0
  40. package/dist/composables/use-mouse.d.ts +64 -0
  41. package/dist/composables/use-mutation-observer.d.ts +101 -0
  42. package/dist/composables/use-network.d.ts +40 -0
  43. package/dist/composables/use-notification.d.ts +89 -0
  44. package/dist/composables/use-permissions.d.ts +109 -0
  45. package/dist/composables/use-resize-observer.d.ts +60 -0
  46. package/dist/composables/use-share.d.ts +70 -0
  47. package/dist/composables/use-speech.d.ts +117 -0
  48. package/dist/composables/use-storage.d.ts +64 -0
  49. package/dist/composables/use-text-selection.d.ts +97 -0
  50. package/dist/composables/use-wake-lock.d.ts +85 -0
  51. package/dist/composables/use-websocket.d.ts +69 -0
  52. package/dist/composables/use-window.d.ts +84 -0
  53. package/dist/composables.d.ts +268 -0
  54. package/dist/composition-api.d.ts +190 -0
  55. package/dist/computed.d.ts +137 -0
  56. package/dist/conditionals.d.ts +14 -2
  57. package/dist/config.d.ts +36 -3
  58. package/dist/craft-bridge.d.ts +319 -0
  59. package/dist/craft-compiler.d.ts +229 -0
  60. package/dist/craft-components.d.ts +411 -0
  61. package/dist/craft-entry.d.ts +5 -0
  62. package/dist/craft-ssr.d.ts +134 -0
  63. package/dist/craft.js +1553 -0
  64. package/dist/csp.d.ts +229 -0
  65. package/dist/database.d.ts +407 -0
  66. package/dist/database.js +5 -0
  67. package/dist/defer.d.ts +4 -0
  68. package/dist/deploy/config-generators.d.ts +75 -0
  69. package/dist/deploy/index.d.ts +84 -0
  70. package/dist/deploy/netlify.d.ts +109 -0
  71. package/dist/dev-server/crosswind.d.ts +54 -0
  72. package/dist/dev-server/index.d.ts +7 -0
  73. package/dist/dev-server/keyboard-shortcuts.d.ts +34 -0
  74. package/dist/dev-server/native-window.d.ts +40 -0
  75. package/dist/dev-server/port-utils.d.ts +27 -0
  76. package/dist/dev-server/terminal-colors.d.ts +60 -0
  77. package/dist/dev-server/theme-selector.d.ts +32 -0
  78. package/dist/dev-server/types.d.ts +92 -0
  79. package/dist/dev-server.d.ts +21 -0
  80. package/dist/devtools.d.ts +142 -0
  81. package/dist/directive-api.d.ts +111 -0
  82. package/dist/dynamic-components.d.ts +14 -0
  83. package/dist/edge-runtime.d.ts +200 -0
  84. package/dist/env.d.ts +9 -0
  85. package/dist/error-boundaries.d.ts +71 -0
  86. package/dist/error-handling.d.ts +1 -101
  87. package/dist/errors/codes.d.ts +99 -0
  88. package/dist/errors/formatter.d.ts +64 -0
  89. package/dist/errors/index.d.ts +56 -0
  90. package/dist/errors/logger.d.ts +74 -0
  91. package/dist/errors/sanitizer.d.ts +43 -0
  92. package/dist/errors/types.d.ts +79 -0
  93. package/dist/events.d.ts +106 -0
  94. package/dist/expressions.d.ts +86 -11
  95. package/dist/formatter.d.ts +4 -0
  96. package/dist/forms-validation.d.ts +173 -0
  97. package/dist/forms.d.ts +157 -8
  98. package/dist/head.d.ts +225 -0
  99. package/dist/heatmap.d.ts +125 -0
  100. package/dist/hot-reload.d.ts +87 -0
  101. package/dist/hydration-runtime.d.ts +47 -0
  102. package/dist/hydration.d.ts +161 -0
  103. package/dist/i18n.d.ts +240 -4
  104. package/dist/image-optimization/build-plugin.d.ts +53 -0
  105. package/dist/image-optimization/component.d.ts +46 -0
  106. package/dist/image-optimization/directive.d.ts +30 -0
  107. package/dist/image-optimization/index.d.ts +86 -0
  108. package/dist/image-optimization/processor.d.ts +112 -0
  109. package/dist/includes.d.ts +94 -9
  110. package/dist/index.d.ts +63 -3
  111. package/dist/index.js +11604 -1318
  112. package/dist/init.d.ts +32 -2
  113. package/dist/interactive.d.ts +14 -0
  114. package/dist/internal-markdown.d.ts +22 -0
  115. package/dist/jsx-runtime.d.ts +110 -0
  116. package/dist/keep-alive.d.ts +87 -0
  117. package/dist/lazy-loader.d.ts +122 -0
  118. package/dist/loading-indicator.d.ts +40 -0
  119. package/dist/loops.d.ts +22 -1
  120. package/dist/media/client/blur-up.d.ts +65 -0
  121. package/dist/media/client/index.d.ts +77 -0
  122. package/dist/media/client/lazy-load.d.ts +73 -0
  123. package/dist/media/client/upload-handler.d.ts +79 -0
  124. package/dist/media/image/component.d.ts +46 -0
  125. package/dist/media/image/directive.d.ts +9 -0
  126. package/dist/media/image/editing.d.ts +212 -0
  127. package/dist/media/image/index.d.ts +118 -0
  128. package/dist/media/image/placeholder.d.ts +78 -0
  129. package/dist/media/image/processor/cache.d.ts +32 -0
  130. package/dist/media/image/processor/index.d.ts +12 -0
  131. package/dist/media/image/processor/optimizer.d.ts +13 -0
  132. package/dist/media/image/processor/responsive.d.ts +17 -0
  133. package/dist/media/image/srcset.d.ts +158 -0
  134. package/dist/media/index.d.ts +295 -0
  135. package/dist/media/manager/embed.d.ts +25 -0
  136. package/dist/media/protected/component.d.ts +34 -0
  137. package/dist/media/protected/index.d.ts +34 -0
  138. package/dist/media/protected/signature.d.ts +72 -0
  139. package/dist/media/shared/cache.d.ts +54 -0
  140. package/dist/media/shared/hash.d.ts +24 -0
  141. package/dist/media/shared/index.d.ts +2 -0
  142. package/dist/media/types.d.ts +1051 -0
  143. package/dist/media/upload/component.d.ts +23 -0
  144. package/dist/media/upload/index.d.ts +1 -0
  145. package/dist/media/video/directive.d.ts +9 -0
  146. package/dist/media/video/index.d.ts +47 -0
  147. package/dist/media/video/processor/cache.d.ts +33 -0
  148. package/dist/media/video/processor/index.d.ts +21 -0
  149. package/dist/media/video/processor/streaming.d.ts +19 -0
  150. package/dist/media/video/processor/thumbnail.d.ts +28 -0
  151. package/dist/media/video/processor/transcoder.d.ts +9 -0
  152. package/dist/middleware.d.ts +42 -3
  153. package/dist/native-build.d.ts +74 -0
  154. package/dist/parser/directive-parser.d.ts +79 -0
  155. package/dist/parser/expression-parser.d.ts +59 -0
  156. package/dist/parser/index.d.ts +35 -0
  157. package/dist/parser/tokenizer.d.ts +81 -0
  158. package/dist/partial-hydration.d.ts +88 -0
  159. package/dist/performance-utils.d.ts +146 -3
  160. package/dist/plugin-system.d.ts +128 -0
  161. package/dist/plugin.d.ts +1 -0
  162. package/dist/precompiler.d.ts +108 -0
  163. package/dist/production-build.d.ts +199 -0
  164. package/dist/props.d.ts +199 -0
  165. package/dist/pwa/audit.d.ts +42 -0
  166. package/dist/pwa/directives.d.ts +29 -0
  167. package/dist/pwa/icons.d.ts +39 -0
  168. package/dist/pwa/index.d.ts +59 -0
  169. package/dist/pwa/inject.d.ts +22 -0
  170. package/dist/pwa/manifest.d.ts +104 -0
  171. package/dist/pwa/offline.d.ts +8 -0
  172. package/dist/pwa/precache.d.ts +29 -0
  173. package/dist/pwa/service-worker.d.ts +21 -0
  174. package/dist/pwa/workbox-strategies.d.ts +100 -0
  175. package/dist/pwa/workbox.d.ts +52 -0
  176. package/dist/pwa.d.ts +51 -0
  177. package/dist/pwa.js +8124 -0
  178. package/dist/reactive-bindings.d.ts +24 -0
  179. package/dist/reactive.d.ts +100 -0
  180. package/dist/reactivity.d.ts +253 -0
  181. package/dist/route-middleware.d.ts +232 -0
  182. package/dist/router.d.ts +31 -0
  183. package/dist/routes.d.ts +0 -7
  184. package/dist/runtime.d.ts +140 -0
  185. package/dist/safe-evaluator.d.ts +117 -3
  186. package/dist/scaffolding.d.ts +113 -0
  187. package/dist/seo.d.ts +120 -7
  188. package/dist/server-components.d.ts +134 -0
  189. package/dist/signals.d.ts +501 -0
  190. package/dist/slots.d.ts +63 -0
  191. package/dist/source-maps.d.ts +117 -0
  192. package/dist/ssg.d.ts +157 -0
  193. package/dist/ssg.js +6831 -0
  194. package/dist/ssr.d.ts +107 -0
  195. package/dist/state-management.d.ts +324 -0
  196. package/dist/stores-client.d.ts +70 -0
  197. package/dist/story/addons.d.ts +123 -0
  198. package/dist/story/analytics.d.ts +92 -0
  199. package/dist/story/auto-stories.d.ts +38 -0
  200. package/dist/story/bookmarks.d.ts +53 -0
  201. package/dist/story/bun-test.d.ts +44 -0
  202. package/dist/story/cli.d.ts +34 -0
  203. package/dist/story/collect/analyzer.d.ts +33 -0
  204. package/dist/story/collect/index.d.ts +27 -0
  205. package/dist/story/collect/parser.d.ts +17 -0
  206. package/dist/story/collect/scanner.d.ts +13 -0
  207. package/dist/story/collect/tree.d.ts +17 -0
  208. package/dist/story/commands/build.d.ts +14 -0
  209. package/dist/story/commands/dev.d.ts +16 -0
  210. package/dist/story/commands/index.d.ts +6 -0
  211. package/dist/story/commands/preview.d.ts +15 -0
  212. package/dist/story/compiled-output.d.ts +26 -0
  213. package/dist/story/composition.d.ts +47 -0
  214. package/dist/story/config-watcher.d.ts +26 -0
  215. package/dist/story/config.d.ts +26 -0
  216. package/dist/story/context.d.ts +21 -0
  217. package/dist/story/controls/index.d.ts +54 -0
  218. package/dist/story/crosswind.d.ts +29 -0
  219. package/dist/story/desktop-preview.d.ts +34 -0
  220. package/dist/story/docs-generator.d.ts +30 -0
  221. package/dist/story/errors.d.ts +47 -0
  222. package/dist/story/figma-export.d.ts +169 -0
  223. package/dist/story/generator.d.ts +21 -0
  224. package/dist/story/hmr.d.ts +64 -0
  225. package/dist/story/hot-swap.d.ts +35 -0
  226. package/dist/story/index.d.ts +51 -0
  227. package/dist/story/interactions.d.ts +52 -0
  228. package/dist/story/keyboard-shortcuts.d.ts +34 -0
  229. package/dist/story/output.d.ts +85 -0
  230. package/dist/story/performance.d.ts +76 -0
  231. package/dist/story/presets.d.ts +62 -0
  232. package/dist/story/props-validation.d.ts +45 -0
  233. package/dist/story/renderer.d.ts +53 -0
  234. package/dist/story/search-index.d.ts +47 -0
  235. package/dist/story/search.d.ts +45 -0
  236. package/dist/story/server.d.ts +21 -0
  237. package/dist/story/setup.d.ts +47 -0
  238. package/dist/story/snapshots.d.ts +65 -0
  239. package/dist/story/testing.d.ts +58 -0
  240. package/dist/story/theme.d.ts +68 -0
  241. package/dist/story/types.d.ts +249 -0
  242. package/dist/story/ui/code-panel.d.ts +42 -0
  243. package/dist/story/ui/controls-panel.d.ts +25 -0
  244. package/dist/story/ui/index.d.ts +4 -0
  245. package/dist/story/ui/navigation.d.ts +55 -0
  246. package/dist/story/ui/preview.d.ts +46 -0
  247. package/dist/story/visual-testing.d.ts +45 -0
  248. package/dist/streaming.d.ts +82 -2
  249. package/dist/suspense.d.ts +83 -0
  250. package/dist/teleport.d.ts +9 -0
  251. package/dist/testing.d.ts +289 -0
  252. package/dist/transitions.d.ts +87 -0
  253. package/dist/type-checker.d.ts +109 -0
  254. package/dist/types/component-types.d.ts +129 -0
  255. package/dist/types/config-types.d.ts +336 -0
  256. package/dist/types/context-types.d.ts +99 -0
  257. package/dist/types/csp-types.d.ts +79 -0
  258. package/dist/types/directive-types.d.ts +259 -0
  259. package/dist/types/index.d.ts +98 -0
  260. package/dist/types/pwa-types.d.ts +218 -0
  261. package/dist/types.d.ts +1 -315
  262. package/dist/typescript-templates.d.ts +178 -0
  263. package/dist/utils.d.ts +52 -6
  264. package/dist/validator.d.ts +77 -0
  265. package/dist/variable-extractor.d.ts +39 -0
  266. package/dist/view-composers.d.ts +154 -9
  267. package/dist/virtual-scrolling.d.ts +103 -0
  268. package/dist/visual-editor.d.ts +209 -0
  269. package/dist/visual-testing.d.ts +109 -0
  270. package/dist/visual-testing.js +126 -0
  271. package/dist/vue-template.d.ts +16 -0
  272. package/dist/web-components/css-scoping.d.ts +54 -0
  273. package/dist/web-components/index.d.ts +20 -0
  274. package/dist/web-components/reactive-generator.d.ts +72 -0
  275. package/dist/web-components.d.ts +222 -2
  276. package/dist/x-element.d.ts +35 -0
  277. package/package.json +41 -10
package/dist/ssr.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ import path from 'node:path';
2
+ import type { StxOptions } from './types';
3
+ /**
4
+ * Render a STX template with server-side data
5
+ *
6
+ * @param template - Template path relative to viewsDir, or inline template string
7
+ * @param data - Data to pass to the template
8
+ * @param options - Render options
9
+ */
10
+ export declare function render(template: string, data?: Record<string, unknown>, options?: {
11
+ viewsDir?: string
12
+ layoutsDir?: string
13
+ stxOptions?: StxOptions
14
+ ctx?: RequestContext
15
+ }): Promise<Response>;
16
+ /**
17
+ * Create a STX server application
18
+ */
19
+ export declare function createApp(config?: AppConfig): void;
20
+ /** Session data store */
21
+ export declare interface SessionData {
22
+
23
+ }
24
+ /** Session interface */
25
+ export declare interface Session {
26
+ id: string
27
+ data: SessionData
28
+ get(key: string): T | undefined
29
+ set(key: string, value: unknown): void
30
+ delete(key: string): void
31
+ clear(): void
32
+ has(key: string): boolean
33
+ flash(key: string, value?: unknown): unknown | undefined
34
+ regenerate(): void
35
+ destroy(): void
36
+ }
37
+ /** Pluggable session store interface for production-ready backends (Redis, DB, etc.) */
38
+ export declare interface SessionStore {
39
+ get(sessionId: string): Promise<SessionData | null>
40
+ set(sessionId: string, data: SessionData, ttlSeconds: number): Promise<void>
41
+ delete(sessionId: string): Promise<void>
42
+ }
43
+ /** Request context passed to route handlers */
44
+ export declare interface RequestContext {
45
+ request: Request
46
+ url: URL
47
+ params: Record<string, string>
48
+ query: Record<string, string>
49
+ session: Session
50
+ csrfToken: string
51
+ formData: () => Promise<Record<string, string | File>>
52
+ json: <T = unknown>() => Promise<T>
53
+ cookies: Record<string, string>
54
+ setCookie: (name: string, value: string, options?: CookieOptions) => void
55
+ responseHeaders: Headers
56
+ flash: (key: string, value: unknown) => void
57
+ getFlash: (key: string) => unknown
58
+ errors: ValidationErrors
59
+ old: (key: string) => string
60
+ isAuthenticated: () => boolean
61
+ user: () => unknown
62
+ }
63
+ /** Cookie options */
64
+ export declare interface CookieOptions {
65
+ maxAge?: number
66
+ expires?: Date
67
+ path?: string
68
+ domain?: string
69
+ secure?: boolean
70
+ httpOnly?: boolean
71
+ sameSite?: 'Strict' | 'Lax' | 'None'
72
+ }
73
+ /** Validation errors */
74
+ export declare interface ValidationErrors {
75
+
76
+ }
77
+ /** App configuration */
78
+ export declare interface AppConfig {
79
+ viewsDir?: string
80
+ layoutsDir?: string
81
+ defaultLayout?: string
82
+ sessionSecret?: string
83
+ sessionCookieName?: string
84
+ sessionTtl?: number
85
+ stxOptions?: StxOptions
86
+ csrfCookieName?: string
87
+ csrfEnabled?: boolean
88
+ sessionStore?: SessionStore
89
+ }
90
+ /** Route definition */
91
+ declare interface Route {
92
+ method: string
93
+ pattern: string
94
+ handler: RouteHandler
95
+ middleware: Middleware[]
96
+ }
97
+ /** Route handler */
98
+ export type RouteHandler = (ctx: RequestContext) => Response | Promise<Response>
99
+ /** Middleware function */
100
+ export type Middleware = (ctx: RequestContext, next: () => Promise<Response>) => Response | Promise<Response>
101
+ /** Default in-memory session store. Use a custom SessionStore (Redis, DB) for production. */
102
+ export declare class MemorySessionStore implements SessionStore {
103
+ private store: any;
104
+ get(sessionId: string): Promise<SessionData | null>;
105
+ set(sessionId: string, data: SessionData, ttlSeconds: number): Promise<void>;
106
+ delete(sessionId: string): Promise<void>;
107
+ }
@@ -0,0 +1,324 @@
1
+ /**
2
+ * Register a store globally.
3
+ */
4
+ export declare function registerStore<T>(name: string, store: Store<T>): void;
5
+ /**
6
+ * Get a registered store.
7
+ */
8
+ export declare function getStore<T>(name: string): Store<T> | undefined;
9
+ /**
10
+ * Check if a store is registered.
11
+ */
12
+ export declare function hasStore(name: string): boolean;
13
+ /**
14
+ * Get all registered store names.
15
+ */
16
+ export declare function getStoreNames(): string[];
17
+ /**
18
+ * Clear all registered stores.
19
+ */
20
+ export declare function clearStores(): void;
21
+ /**
22
+ * Create a reactive store.
23
+ */
24
+ export declare function createStore<T>(initialValue: T, options?: StoreOptions<T>): Store<T>;
25
+ /**
26
+ * Create a readonly store from a getter function.
27
+ */
28
+ export declare function createReadonlyStore<T>(getter: () => T, options?: { name?: string }): Omit<Store<T>, 'set' | 'update' | 'reset'>;
29
+ /**
30
+ * Create a computed value derived from stores.
31
+ */
32
+ export declare function computed<T, S extends readonly Store<any>[]>(stores: S, compute: (...values: { [K in keyof S]: S[K] extends Store<infer V> ? V : never }) => T, options?: ComputedOptions): Store<T>;
33
+ /**
34
+ * Create a typed action for a store.
35
+ */
36
+ export declare function createAction<T, P extends unknown[], R>(store: Store<T>, name: string, handler: (state: T, ...params: P) => T | Promise<T>): (...params: P) => R extends Promise<unknown> ? Promise<void> : void;
37
+ /**
38
+ * Create multiple actions for a store.
39
+ */
40
+ export declare function createActions<T, A extends Record<string, (state: T, ...args: any[]) => T>>(store: Store<T>, actions: A): { [K in keyof A]: A[K] extends (state: T, ...args: infer P) => T ? (...args: P) => void : never };
41
+ /**
42
+ * Create a selector that derives a value from a store.
43
+ */
44
+ export declare function createSelector<T, R>(store: Store<T>, selector: (state: T) => R, options?: { equals?: (a: R, b: R) => boolean }): Store<R>;
45
+ /**
46
+ * Create a selector with memoization.
47
+ */
48
+ export declare function createMemoizedSelector<T, R>(store: Store<T>, selector: (state: T) => R, deps: (state: T) => unknown[]): Store<R>;
49
+ /**
50
+ * Logging middleware for debugging.
51
+ */
52
+ export declare function loggerMiddleware<T>(name?: string): StoreMiddleware<T>;
53
+ /**
54
+ * Validation middleware.
55
+ */
56
+ export declare function validationMiddleware<T>(validate: (value: T) => boolean | string): StoreMiddleware<T>;
57
+ /**
58
+ * Immer-like middleware for immutable updates.
59
+ */
60
+ export declare function immerMiddleware<T extends object>(): StoreMiddleware<T>;
61
+ /**
62
+ * Throttle middleware.
63
+ */
64
+ export declare function throttleMiddleware<T>(ms: number): StoreMiddleware<T>;
65
+ /**
66
+ * Use a store in a template context.
67
+ * Returns a reactive reference that auto-updates.
68
+ */
69
+ export declare function useStore<T>(nameOrStore: string | Store<T>): T;
70
+ /**
71
+ * Create a store directive for use in templates.
72
+ */
73
+ export declare function createStoreDirective(storeName: string): {
74
+ name: string
75
+ hasEndTag: boolean
76
+ handler: () => string
77
+ };
78
+ /**
79
+ * Serialize all stores for SSR hydration.
80
+ */
81
+ export declare function serializeStores(): string;
82
+ /**
83
+ * Hydrate stores from serialized state.
84
+ */
85
+ export declare function hydrateStores(serialized: string): void;
86
+ /**
87
+ * Generate hydration script for SSR.
88
+ */
89
+ export declare function generateHydrationScript(): string;
90
+ /**
91
+ * Initialize DevTools integration.
92
+ */
93
+ export declare function initDevTools(): void;
94
+ /**
95
+ * Define a store with state, getters, and actions.
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // stores/counter.ts
100
+ * import { defineStore } from 'stx'
101
+ *
102
+ * export const counterStore = defineStore('counter', {
103
+ * state: {
104
+ * count: 0,
105
+ * name: 'Counter'
106
+ * },
107
+ * getters: {
108
+ * doubleCount: (state) => state.count * 2,
109
+ * displayName: (state) => `${state.name}: ${state.count}`
110
+ * },
111
+ * actions: {
112
+ * increment() { this.count++ },
113
+ * decrement() { this.count-- },
114
+ * incrementBy(amount: number) { this.count += amount },
115
+ * async fetchCount() {
116
+ * const response = await fetch('/api/count')
117
+ * this.count = await response.json()
118
+ * }
119
+ * },
120
+ * persist: true // or { storage: 'local', key: 'my-counter' }
121
+ * })
122
+ * ```
123
+ *
124
+ * Usage in components:
125
+ * ```html
126
+ * <script client>
127
+ * import { counterStore } from '@stores'
128
+ *
129
+ * // Access state
130
+ * console.log(counterStore.count) // 0
131
+ *
132
+ * // Use getters
133
+ * console.log(counterStore.doubleCount) // 0
134
+ *
135
+ * // Call actions
136
+ * counterStore.increment()
137
+ * counterStore.incrementBy(5)
138
+ *
139
+ * // Subscribe to changes
140
+ * counterStore.$subscribe((state) => {
141
+ * console.log('Count changed:', state.count)
142
+ * })
143
+ *
144
+ * // Reset to initial state
145
+ * counterStore.$reset()
146
+ * </script>
147
+ * ```
148
+ */
149
+ export declare function defineStore<S extends object, G extends Record<string, (state: S) => any> = Record<string, never>, A extends Record<string, (...args: any[]) => any> = Record<string, never>>(id: string, options: DefineStoreOptions<S, G, A>): DefinedStoreWithGettersAndActions<S, G, A>;
150
+ /**
151
+ * Get a defined store by name.
152
+ * Used internally by the @stores import transformation.
153
+ */
154
+ export declare function getDefinedStore<S extends object = any>(name: string): DefinedStoreWithGettersAndActions<S, any, any> | undefined;
155
+ /**
156
+ * Get all defined store names.
157
+ */
158
+ export declare function getDefinedStoreNames(): string[];
159
+ /**
160
+ * Check if a store is defined.
161
+ */
162
+ export declare function hasDefinedStore(name: string): boolean;
163
+ /**
164
+ * Generate client-side runtime code for store imports.
165
+ * Uses the stx runtime to avoid exposing window.* to developers.
166
+ */
167
+ export declare function generateStoreImportRuntime(): string;
168
+ /**
169
+ * Transform import statements from @stores to runtime code.
170
+ *
171
+ * Transforms:
172
+ * ```js
173
+ * import { appStore, chatStore } from '@stores'
174
+ * ```
175
+ *
176
+ * Into:
177
+ * ```js
178
+ * const appStore = stx.useStore('appStore');
179
+ * const chatStore = stx.useStore('chatStore');
180
+ * ```
181
+ *
182
+ * The stx runtime is injected automatically and abstracts away window.* access.
183
+ */
184
+ export declare function transformStoreImports(code: string): string;
185
+ /**
186
+ * Generate store registration code for the client.
187
+ *
188
+ * @example
189
+ * ```js
190
+ * // In your stores file (e.g., stores/index.ts)
191
+ * import { defineStore, registerStoresClient } from 'stx'
192
+ *
193
+ * export const appStore = defineStore('app', { ... })
194
+ * export const chatStore = defineStore('chat', { ... })
195
+ *
196
+ * // Register for client-side @stores imports
197
+ * if (typeof window !== 'undefined') {
198
+ * registerStoresClient({ appStore, chatStore })
199
+ * }
200
+ * ```
201
+ */
202
+ export declare function registerStoresClient(stores: Record<string, DefinedStoreWithGettersAndActions<any, any, any>>): void;
203
+ /** Store options */
204
+ export declare interface StoreOptions<T> {
205
+ name?: string
206
+ persist?: PersistOptions
207
+ devtools?: boolean
208
+ middleware?: StoreMiddleware<T>[]
209
+ equals?: (a: T, b: T) => boolean
210
+ }
211
+ /** Persistence options */
212
+ export declare interface PersistOptions {
213
+ storage?: 'local' | 'session' | 'memory'
214
+ key?: string
215
+ serialize?: (value: unknown) => string
216
+ deserialize?: (value: string) => unknown
217
+ paths?: string[]
218
+ debounce?: number
219
+ }
220
+ /** Store interface */
221
+ export declare interface Store<T> {
222
+ get: () => T
223
+ set: (value: T | ((prev: T) => T)) => void
224
+ subscribe: (subscriber: Subscriber<T>) => Unsubscribe
225
+ update: (updater: Partial<T> | ((prev: T) => Partial<T>)) => void
226
+ reset: () => void
227
+ name?: string
228
+ destroy: () => void
229
+ }
230
+ /** Computed options */
231
+ export declare interface ComputedOptions {
232
+ equals?: <T>(a: T, b: T) => boolean
233
+ }
234
+ /** Action definition */
235
+ export declare interface ActionDefinition<T, P extends unknown[], R> {
236
+ name: string
237
+ handler: (store: Store<T>, ...params: P) => R
238
+ }
239
+ /** Global store state */
240
+ export declare interface GlobalState {
241
+ stores: Map<string, Store<unknown>>
242
+ subscriptions: Map<string, Set<Subscriber<unknown>>>
243
+ }
244
+ /**
245
+ * Store definition options for defineStore
246
+ */
247
+ export declare interface DefineStoreOptions<S, G extends Record<string, (state: S) => any>, A extends Record<string, (...args: any[]) => any>> {
248
+ state: S | (() => S)
249
+ getters?: G
250
+ actions?: A
251
+ persist?: PersistOptions | boolean
252
+ devtools?: boolean
253
+ }
254
+ /**
255
+ * Store instance returned by defineStore
256
+ */
257
+ export declare interface DefinedStore<S, G extends Record<string, (state: S) => any>, A extends Record<string, (...args: any[]) => any>> {
258
+ $state: S
259
+ $subscribe: (callback: Subscriber<S>) => Unsubscribe
260
+ $reset: () => void
261
+ $patch: (partial: Partial<S> | ((state: S) => void)) => void
262
+ _store: Store<S>
263
+ $id: string
264
+ }
265
+ /**
266
+ * State Management Module
267
+ *
268
+ * Provides reactive state management for stx templates with support for
269
+ * both simple stores and complex global state management.
270
+ *
271
+ * ## Features
272
+ *
273
+ * 1. **Reactive Stores** - Simple observable stores with auto-subscriptions
274
+ * 2. **Computed Values** - Derived state that auto-updates
275
+ * 3. **Actions** - Structured state mutations
276
+ * 4. **Persistence** - LocalStorage/SessionStorage integration
277
+ * 5. **DevTools** - State inspection and time-travel debugging
278
+ * 6. **Server State** - Sync state between server and client
279
+ *
280
+ * ## Usage
281
+ *
282
+ * ```typescript
283
+ * import { createStore, computed, action } from 'stx/state-management'
284
+ *
285
+ * const counter = createStore({ count: 0 })
286
+ *
287
+ * // Subscribe to changes
288
+ * counter.subscribe(state => console.log(state.count))
289
+ *
290
+ * // Update state
291
+ * counter.set({ count: counter.get().count + 1 })
292
+ * ```
293
+ *
294
+ * In templates:
295
+ * ```html
296
+ * <script>
297
+ * import { useStore } from 'stx/state-management'
298
+ * const { count } = useStore('counter')
299
+ * </script>
300
+ * <p>Count: {{ count }}</p>
301
+ * ```
302
+ *
303
+ * @module state-management
304
+ */
305
+ /** Subscription callback */
306
+ export type Subscriber<T> = (value: T, previousValue: T | undefined) => void
307
+ /** Unsubscribe function */
308
+ export type Unsubscribe = () => void
309
+ /** Store middleware */
310
+ export type StoreMiddleware<T> = (
311
+ set: (value: T) => void,
312
+ get: () => T,
313
+ store: Store<T>
314
+ ) => (nextSet: (value: T) => void) => (value: T) => void
315
+ // Type helper for getters
316
+ declare type StoreGetters<S, G extends Record<string, (state: S) => any>> = {
317
+ [K in keyof G]: ReturnType<G[K]>
318
+ }
319
+ // Type helper for actions
320
+ declare type StoreActions<A extends Record<string, (...args: any[]) => any>> = {
321
+ [K in keyof A]: A[K]
322
+ }
323
+ // Full store type combining state, getters, and actions
324
+ export type DefinedStoreWithGettersAndActions<S, G extends Record<string, (state: S) => any>, A extends Record<string, (...args: any[]) => any>> = DefinedStore<S, G, A> & StoreGetters<S, G> & StoreActions<A>
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Define a reactive store with state, getters, and actions.
3
+ */
4
+ export declare function defineStore<S extends object, G extends Record<string, (state: S) => any> = Record<string, never>, A extends Record<string, (...args: any[]) => any> = Record<string, never>>(id: string, options: StoreOptions<S, G, A>): Store<S> & { [K in keyof G]: ReturnType<G[K]> } & { [K in keyof A]: A[K] };
5
+ /**
6
+ * Register multiple stores at once.
7
+ */
8
+ export declare function registerStores(stores: Record<string, any>): void;
9
+ /**
10
+ * Get a store by name.
11
+ */
12
+ export declare function getStore<T = any>(name: string): T | undefined;
13
+ /**
14
+ * Wait for a store to be available.
15
+ */
16
+ export declare function waitForStore<T = any>(name: string, timeout?: any): Promise<T>;
17
+ /**
18
+ * STX Stores - Client Runtime
19
+ *
20
+ * This module provides the client-side store functionality for STX applications.
21
+ * It enables clean imports like: import { appStore } from '@stores'
22
+ *
23
+ * @example
24
+ * ```html
25
+ * <!-- In your layout or main template -->
26
+ * <script src="/js/stx-stores.js"></script>
27
+ *
28
+ * <!-- In your stores definition file -->
29
+ * <script>
30
+ * const { defineStore, registerStores } = window.STX;
31
+ *
32
+ * const appStore = defineStore('app', {
33
+ * state: { count: 0 },
34
+ * actions: {
35
+ * increment() { this.count++ }
36
+ * }
37
+ * });
38
+ *
39
+ * registerStores({ appStore });
40
+ * </script>
41
+ *
42
+ * <!-- In your components -->
43
+ * <script client>
44
+ * import { appStore } from '@stores'
45
+ * appStore.increment()
46
+ * </script>
47
+ * ```
48
+ */
49
+ // Type definitions
50
+ export declare interface Subscriber<T> {
51
+ (value: T, previousValue?: T): void
52
+ }
53
+ export declare interface PersistOptions {
54
+ storage?: 'local' | 'session' | 'memory'
55
+ key?: string
56
+ }
57
+ export declare interface StoreOptions<S, G, A> {
58
+ state: S | (() => S)
59
+ getters?: G
60
+ actions?: A
61
+ persist?: PersistOptions | boolean
62
+ }
63
+ export declare interface Store<S> {
64
+ $state: S
65
+ $subscribe: (callback: Subscriber<S>) => Unsubscribe
66
+ $reset: () => void
67
+ $patch: (partial: Partial<S> | ((state: S) => void)) => void
68
+ $id: string
69
+ }
70
+ export type Unsubscribe = () => void
@@ -0,0 +1,123 @@
1
+ import type { ServerStoryFile, StoryContext } from './types';
2
+ /**
3
+ * Register an addon
4
+ */
5
+ export declare function registerAddon(addon: StoryAddon): void;
6
+ /**
7
+ * Unregister an addon
8
+ */
9
+ export declare function unregisterAddon(id: string): boolean;
10
+ /**
11
+ * Get all registered addons
12
+ */
13
+ export declare function getAddons(): StoryAddon[];
14
+ /**
15
+ * Get an addon by ID
16
+ */
17
+ export declare function getAddon(id: string): StoryAddon | undefined;
18
+ /**
19
+ * Initialize all addons
20
+ */
21
+ export declare function initializeAddons(ctx: StoryContext): Promise<void>;
22
+ /**
23
+ * Apply all decorators to a story
24
+ */
25
+ export declare function applyDecorators(story: ServerStoryFile, ctx: AddonContext): ServerStoryFile;
26
+ /**
27
+ * Get all addon panels
28
+ */
29
+ export declare function getAddonPanels(): AddonPanel[];
30
+ /**
31
+ * Get all toolbar items
32
+ */
33
+ export declare function getToolbarItems(): ToolbarItem[];
34
+ /**
35
+ * Register all built-in addons
36
+ */
37
+ export declare function registerBuiltinAddons(): void;
38
+ /**
39
+ * Actions addon - logs component events
40
+ */
41
+ export declare const actionsAddon: StoryAddon;
42
+ /**
43
+ * Viewport addon - responsive preview sizes
44
+ */
45
+ export declare const viewportAddon: StoryAddon;
46
+ /**
47
+ * Backgrounds addon - change preview background
48
+ */
49
+ export declare const backgroundsAddon: StoryAddon;
50
+ /**
51
+ * Docs addon - auto-generated documentation
52
+ */
53
+ export declare const docsAddon: StoryAddon;
54
+ /**
55
+ * Measure addon - spacing/sizing overlay
56
+ */
57
+ export declare const measureAddon: StoryAddon;
58
+ /**
59
+ * Outline addon - component boundaries
60
+ */
61
+ export declare const outlineAddon: StoryAddon;
62
+ /**
63
+ * i18n addon - test with different locales
64
+ */
65
+ export declare const i18nAddon: StoryAddon;
66
+ /**
67
+ * Performance addon - render timing metrics
68
+ */
69
+ export declare const performanceAddon: StoryAddon;
70
+ /**
71
+ * State addon - component state inspector
72
+ */
73
+ export declare const stateAddon: StoryAddon;
74
+ /**
75
+ * A11y addon - accessibility audit panel
76
+ */
77
+ export declare const a11yAddon: StoryAddon;
78
+ /**
79
+ * Addon panel configuration
80
+ */
81
+ export declare interface AddonPanel {
82
+ id: string
83
+ title: string
84
+ icon?: string
85
+ render: (ctx: AddonContext) => string
86
+ }
87
+ /**
88
+ * Toolbar item configuration
89
+ */
90
+ export declare interface ToolbarItem {
91
+ id: string
92
+ title: string
93
+ icon?: string
94
+ render: (ctx: AddonContext) => string
95
+ onClick?: string
96
+ }
97
+ /**
98
+ * Addon context passed to render functions
99
+ */
100
+ export declare interface AddonContext {
101
+ story?: ServerStoryFile
102
+ variantId?: string
103
+ storyContext: StoryContext
104
+ state: Record<string, any>
105
+ }
106
+ /**
107
+ * Addon definition
108
+ */
109
+ export declare interface StoryAddon {
110
+ name: string
111
+ id: string
112
+ panel?: AddonPanel
113
+ decorator?: StoryDecorator
114
+ toolbar?: ToolbarItem[]
115
+ init?: (ctx: StoryContext) => void | Promise<void>
116
+ }
117
+ /**
118
+ * Story decorator function
119
+ */
120
+ export type StoryDecorator = (
121
+ story: ServerStoryFile,
122
+ ctx: AddonContext,
123
+ ) => ServerStoryFile