@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
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Process reactive bindings in HTML template
3
+ * Detects {{ $store.value }} patterns in attribute values
4
+ */
5
+ export declare function processReactiveBindings(html: string): ProcessedBindings;
6
+ /**
7
+ * Generate the client-side JavaScript for reactive bindings
8
+ */
9
+ export declare function generateBindingsRuntime(bindings: BindingInfo[], stores: Set<string>): string;
10
+ /**
11
+ * Process template with reactive bindings and generate runtime
12
+ */
13
+ export declare function processTemplateBindings(html: string): string;
14
+ declare interface BindingInfo {
15
+ elementId: string
16
+ attribute: string
17
+ expression: string
18
+ stores: string[]
19
+ }
20
+ declare interface ProcessedBindings {
21
+ html: string
22
+ bindings: BindingInfo[]
23
+ stores: Set<string>
24
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Process reactive directives in a template.
3
+ *
4
+ * Transforms `x-data`, `x-model`, `x-show`, etc. into client-side reactivity.
5
+ *
6
+ * @param template - The HTML template string
7
+ * @param context - Template context
8
+ * @param filePath - Source file path for error messages
9
+ * @returns Processed template with reactive runtime script
10
+ */
11
+ export declare function processReactiveDirectives(template: string, _context: Record<string, unknown>, _filePath: string): string;
12
+ /**
13
+ * Check if a template contains reactive directives
14
+ */
15
+ export declare function hasReactiveDirectives(template: string): boolean;
16
+ /**
17
+ * Reactive Directives Module
18
+ *
19
+ * Provides Alpine.js-style reactive state management for STX templates.
20
+ * Transforms `x-data`, `x-model`, `x-show`, `x-text`, `x-bind` into client-side reactivity.
21
+ *
22
+ * ## Supported Syntax
23
+ *
24
+ * ### x-data - Define reactive state
25
+ * ```html
26
+ * <div x-data="{ count: 0, name: '' }">
27
+ * <p x-text="count"></p>
28
+ * <button @click="count++">Increment</button>
29
+ * </div>
30
+ * ```
31
+ *
32
+ * ### x-model - Two-way binding
33
+ * ```html
34
+ * <input x-model="name" type="text">
35
+ * <textarea x-model="message"></textarea>
36
+ * <select x-model="selected">...</select>
37
+ * <input x-model="checked" type="checkbox">
38
+ * ```
39
+ *
40
+ * ### x-show / x-hide - Toggle visibility
41
+ * ```html
42
+ * <div x-show="isOpen">Visible when isOpen is true</div>
43
+ * <div x-hide="isLoading">Hidden when isLoading is true</div>
44
+ * ```
45
+ *
46
+ * ### x-text / x-html - Bind content
47
+ * ```html
48
+ * <span x-text="message"></span>
49
+ * <div x-html="htmlContent"></div>
50
+ * ```
51
+ *
52
+ * ### x-bind / :attr - Bind attributes
53
+ * ```html
54
+ * <button x-bind:disabled="isLoading">Submit</button>
55
+ * <div :class="{ active: isActive, hidden: !isVisible }">...</div>
56
+ * <img :src="imageUrl" :alt="imageAlt">
57
+ * ```
58
+ *
59
+ * ### x-ref - Element references
60
+ * ```html
61
+ * <input x-ref="input">
62
+ * <button @click="$refs.input.focus()">Focus</button>
63
+ * ```
64
+ *
65
+ * ### x-init - Run code on mount
66
+ * ```html
67
+ * <div x-data="{ items: [] }" x-init="items = await fetchItems()">
68
+ * ```
69
+ *
70
+ * @module reactive
71
+ */
72
+ // =============================================================================
73
+ // Types
74
+ // =============================================================================
75
+ export declare interface ReactiveScope {
76
+ id: string
77
+ selector: string
78
+ stateExpr: string
79
+ initExpr: string | null
80
+ bindings: ReactiveBinding[]
81
+ refs: Map<string, string>
82
+ }
83
+ export declare interface ReactiveBinding {
84
+ elementId: string
85
+ type: 'model' | 'show' | 'hide' | 'text' | 'html' | 'bind' | 'class' | 'style'
86
+ expression: string
87
+ attribute?: string
88
+ inputType?: string
89
+ transition?: TransitionConfig
90
+ }
91
+ export declare interface TransitionConfig {
92
+ enabled: boolean
93
+ enter?: string
94
+ enterStart?: string
95
+ enterEnd?: string
96
+ leave?: string
97
+ leaveStart?: string
98
+ leaveEnd?: string
99
+ duration?: number
100
+ }
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Set the current component instance for lifecycle hook registration.
3
+ */
4
+ export declare function setCurrentInstance(instance: ComponentInstance | null): void;
5
+ /**
6
+ * Get the current component instance.
7
+ */
8
+ export declare function getCurrentInstance(): ComponentInstance | null;
9
+ /**
10
+ * Create a new component instance.
11
+ */
12
+ export declare function createComponentInstance(): ComponentInstance;
13
+ /**
14
+ * Create a new reactive scope.
15
+ */
16
+ export declare function createScope(): ReactiveScope;
17
+ /**
18
+ * Create a reactive reference.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const count = ref(0)
23
+ * count.value++
24
+ * console.log(count.value) // 1
25
+ * ```
26
+ */
27
+ export declare function ref<T>(initialValue: T): Ref<T>;
28
+ /**
29
+ * Create a reactive object (proxy-based).
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const state = reactive({ count: 0, name: 'STX' })
34
+ * state.count++
35
+ * state.name = 'Vue-style STX'
36
+ * ```
37
+ */
38
+ export declare function reactive<T extends object>(target: T): T;
39
+ /**
40
+ * Create a computed value.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const count = ref(0)
45
+ * const doubled = computed(() => count.value * 2)
46
+ * console.log(doubled.value) // 0
47
+ * count.value = 5
48
+ * console.log(doubled.value) // 10
49
+ * ```
50
+ */
51
+ export declare function computed<T>(getter: () => T): Ref<T>;
52
+ /**
53
+ * Watch a reactive source and run a callback on changes.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const count = ref(0)
58
+ *
59
+ * watch(count, (newVal, oldVal) => {
60
+ * console.log(`Changed from ${oldVal} to ${newVal}`)
61
+ * })
62
+ *
63
+ * // With options
64
+ * watch(count, callback, { immediate: true, deep: true })
65
+ * ```
66
+ */
67
+ export declare function watch<T>(source: Ref<T> | (() => T), callback: WatchCallback<T>, options?: WatchOptions): () => void;
68
+ /**
69
+ * Watch multiple sources.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const count = ref(0)
74
+ * const name = ref('STX')
75
+ *
76
+ * watch([count, name], ([newCount, newName], [oldCount, oldName]) => {
77
+ * console.log(`Count: ${oldCount} -> ${newCount}`)
78
+ * console.log(`Name: ${oldName} -> ${newName}`)
79
+ * })
80
+ * ```
81
+ */
82
+ export declare function watchMultiple<T extends readonly Ref<unknown>[]>(sources: T, callback: (
83
+ newValues: { [K in keyof T]: T[K] extends Ref<infer V> ? V : never },
84
+ oldValues: { [K in keyof T]: T[K] extends Ref<infer V> ? V : never },
85
+ ) => void, options?: WatchOptions): () => void;
86
+ /**
87
+ * Automatically track reactive dependencies and re-run on changes.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const count = ref(0)
92
+ *
93
+ * watchEffect(() => {
94
+ * console.log(`Count is: ${count.value}`)
95
+ * })
96
+ * ```
97
+ */
98
+ export declare function watchEffect(effect: () => void | (() => void)): () => void;
99
+ /**
100
+ * Register a callback to run before component mounts.
101
+ */
102
+ export declare function onBeforeMount(callback: LifecycleHook): void;
103
+ /**
104
+ * Register a callback to run when component is mounted to DOM.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * onMounted(async () => {
109
+ * const data = await fetch('/api/data').then(r => r.json())
110
+ * items.value = data
111
+ * })
112
+ * ```
113
+ */
114
+ export declare function onMounted(callback: LifecycleHook): void;
115
+ /**
116
+ * Register a callback to run before component updates.
117
+ */
118
+ export declare function onBeforeUpdate(callback: LifecycleHook): void;
119
+ /**
120
+ * Register a callback to run after component updates.
121
+ */
122
+ export declare function onUpdated(callback: LifecycleHook): void;
123
+ /**
124
+ * Register a callback to run before component unmounts.
125
+ */
126
+ export declare function onBeforeUnmount(callback: LifecycleHook): void;
127
+ /**
128
+ * Register a callback to run after component unmounts.
129
+ * Use this for cleanup: removing event listeners, clearing timers, etc.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * let interval: number
134
+ *
135
+ * onMounted(() => {
136
+ * interval = setInterval(refresh, 5000)
137
+ * })
138
+ *
139
+ * onUnmounted(() => {
140
+ * clearInterval(interval)
141
+ * })
142
+ * ```
143
+ */
144
+ export declare function onUnmounted(callback: LifecycleHook): void;
145
+ /**
146
+ * Run all hooks of a specific type for an instance.
147
+ */
148
+ export declare function runHooks(instance: ComponentInstance, hookName: keyof ComponentInstance['hooks']): Promise<void>;
149
+ /**
150
+ * Mount a component instance.
151
+ */
152
+ export declare function mountInstance(instance: ComponentInstance): Promise<void>;
153
+ /**
154
+ * Update a component instance.
155
+ */
156
+ export declare function updateInstance(instance: ComponentInstance): Promise<void>;
157
+ /**
158
+ * Unmount a component instance.
159
+ */
160
+ export declare function unmountInstance(instance: ComponentInstance): Promise<void>;
161
+ /**
162
+ * Generate the client-side runtime script.
163
+ * This is injected into the page to enable reactivity.
164
+ */
165
+ export declare function generateClientRuntime(): string;
166
+ /**
167
+ * Vue-Style Reactivity Module
168
+ *
169
+ * Provides Vue 3 Composition API-style reactivity for STX templates.
170
+ * This module is designed to feel familiar to Vue developers while
171
+ * leveraging STX's template processing capabilities.
172
+ *
173
+ * ## Core Primitives
174
+ *
175
+ * - `ref()` - Create a reactive reference
176
+ * - `reactive()` - Create a reactive object
177
+ * - `computed()` - Create a computed value
178
+ * - `watch()` - Watch reactive sources
179
+ * - `watchEffect()` - Auto-track dependencies
180
+ *
181
+ * ## Lifecycle Hooks
182
+ *
183
+ * - `onBeforeMount()` - Before DOM insertion
184
+ * - `onMounted()` - Component in DOM
185
+ * - `onBeforeUpdate()` - Before re-render
186
+ * - `onUpdated()` - After re-render
187
+ * - `onBeforeUnmount()` - Before cleanup
188
+ * - `onUnmounted()` - After cleanup
189
+ *
190
+ * ## Usage
191
+ *
192
+ * ```html
193
+ * <script client>
194
+ * import { ref, onMounted, watch } from 'stx'
195
+ *
196
+ * const count = ref(0)
197
+ * const users = ref([])
198
+ *
199
+ * onMounted(async () => {
200
+ * users.value = await fetch('/api/users').then(r => r.json())
201
+ * })
202
+ *
203
+ * watch(count, (newVal, oldVal) => {
204
+ * console.log(`Count changed: ${oldVal} -> ${newVal}`)
205
+ * })
206
+ * </script>
207
+ *
208
+ * <button @click="count++">Count: {{ count }}</button>
209
+ * ```
210
+ *
211
+ * @module reactivity
212
+ */
213
+ /** Reactive reference wrapper */
214
+ export declare interface Ref<T> {
215
+ value: T
216
+ subscribe: (callback: (value: T, oldValue: T) => void) => () => void
217
+ }
218
+ /** Watch options */
219
+ export declare interface WatchOptions {
220
+ immediate?: boolean
221
+ deep?: boolean
222
+ flush?: 'pre' | 'post' | 'sync'
223
+ }
224
+ /** Component instance for tracking lifecycle */
225
+ export declare interface ComponentInstance {
226
+ isMounted: boolean
227
+ isUnmounted: boolean
228
+ hooks: {
229
+ beforeMount: LifecycleHook[]
230
+ mounted: LifecycleHook[]
231
+ beforeUpdate: LifecycleHook[]
232
+ updated: LifecycleHook[]
233
+ beforeUnmount: LifecycleHook[]
234
+ unmounted: LifecycleHook[]
235
+ }
236
+ effects: (() => void)[]
237
+ scope: ReactiveScope
238
+ }
239
+ /** Reactive scope for tracking dependencies */
240
+ export declare interface ReactiveScope {
241
+ refs: Map<symbol, Ref<unknown>>
242
+ effects: Set<() => void>
243
+ cleanups: (() => void)[]
244
+ }
245
+ /** Subscriber callback */
246
+ export type WatchCallback<T> = (newValue: T, oldValue: T | undefined) => void
247
+ /** Lifecycle hook callback */
248
+ export type LifecycleHook = () => void | Promise<void>
249
+ export {
250
+ ref as createRef,
251
+ reactive as createReactive,
252
+ computed as createComputed,
253
+ };
@@ -0,0 +1,232 @@
1
+ import path from 'node:path';
2
+ import type { PageMeta } from './head';
3
+ /**
4
+ * Redirect to a different route
5
+ *
6
+ * @param path - Path to redirect to
7
+ * @param options - Redirect options
8
+ * @returns Navigation result for the middleware system
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * export default defineMiddleware(async (ctx) => {
13
+ * if (!ctx.cookies.get('token')) {
14
+ * return navigateTo('/login')
15
+ * }
16
+ * })
17
+ * ```
18
+ */
19
+ export declare function navigateTo(path: string, options?: NavigateToOptions): NavigateToResult;
20
+ /**
21
+ * Abort navigation with an error
22
+ *
23
+ * @param error - Error message or error object
24
+ * @returns Navigation result for the middleware system
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * export default defineMiddleware(async (ctx) => {
29
+ * if (!hasPermission(ctx)) {
30
+ * return abortNavigation({ statusCode: 403, message: 'Forbidden' })
31
+ * }
32
+ * })
33
+ * ```
34
+ */
35
+ export declare function abortNavigation(error: string | NavigationError): AbortNavigationResult;
36
+ /**
37
+ * Define a route middleware
38
+ *
39
+ * @param handler - Middleware handler function
40
+ * @param options - Middleware options
41
+ * @returns Middleware definition
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // middleware/auth.ts - runs on both server and client
46
+ * export default defineMiddleware(async (ctx) => {
47
+ * const token = ctx.cookies.get('auth_token')
48
+ * if (!token) {
49
+ * return navigateTo('/login')
50
+ * }
51
+ * })
52
+ *
53
+ * // middleware/theme.ts - client only (can use localStorage)
54
+ * export default defineMiddleware(async (ctx) => {
55
+ * const theme = ctx.storage.get('theme')
56
+ * ctx.state.theme = theme || 'light'
57
+ * }, { mode: 'client' })
58
+ * ```
59
+ */
60
+ export declare function defineMiddleware(handler: RouteMiddlewareHandler, options?: MiddlewareOptions): RouteMiddlewareDefinition;
61
+ /**
62
+ * Create a cookie manager for server-side usage
63
+ */
64
+ export declare function createServerCookieManager(request: Request, responseHeaders: Headers): CookieManager;
65
+ /**
66
+ * Create a cookie manager for client-side usage
67
+ */
68
+ export declare function createClientCookieManager(): CookieManager;
69
+ /**
70
+ * Create a storage manager (localStorage wrapper)
71
+ */
72
+ export declare function createStorageManager(): StorageManager;
73
+ /**
74
+ * Register a middleware by name
75
+ */
76
+ export declare function registerMiddleware(name: string, middleware: RouteMiddlewareDefinition): void;
77
+ /**
78
+ * Get a middleware by name
79
+ */
80
+ export declare function getMiddleware(name: string): RouteMiddlewareDefinition | undefined;
81
+ /**
82
+ * Check if a middleware is registered
83
+ */
84
+ export declare function hasMiddleware(name: string): boolean;
85
+ /**
86
+ * Clear all registered middleware
87
+ */
88
+ export declare function clearMiddleware(): void;
89
+ /**
90
+ * Get all registered middleware names
91
+ */
92
+ export declare function getMiddlewareNames(): string[];
93
+ /**
94
+ * Load middleware from the middleware/ directory
95
+ */
96
+ export declare function loadMiddlewareFromDirectory(baseDir: string, middlewareDir?: string): Promise<void>;
97
+ /**
98
+ * Create a route location object
99
+ */
100
+ export declare function createRouteLocation(pathname: string, params: Record<string, string>, meta: PageMeta, search?: string): RouteLocation;
101
+ /**
102
+ * Create a middleware context
103
+ */
104
+ export declare function createMiddlewareContext(to: RouteLocation, from: RouteLocation | null, request?: Request): MiddlewareContext;
105
+ /**
106
+ * Run middleware chain for a route
107
+ *
108
+ * @param middlewareNames - Names of middleware to run
109
+ * @param context - Middleware context
110
+ * @returns Result of middleware execution
111
+ */
112
+ export declare function runMiddleware(middlewareNames: string | string[], context: MiddlewareContext): Promise<MiddlewareResult>;
113
+ /**
114
+ * Route location information
115
+ */
116
+ export declare interface RouteLocation {
117
+ path: string
118
+ params: Record<string, string>
119
+ query: Record<string, string>
120
+ fullPath: string
121
+ meta: PageMeta
122
+ }
123
+ /**
124
+ * Cookie manager for reading/writing cookies
125
+ */
126
+ export declare interface CookieManager {
127
+ get(name: string): string | undefined
128
+ set(name: string, value: string, options?: CookieOptions): void
129
+ delete(name: string): void
130
+ getAll(): Record<string, string>
131
+ }
132
+ /**
133
+ * Cookie options for setting cookies
134
+ */
135
+ export declare interface CookieOptions {
136
+ expires?: Date | number
137
+ path?: string
138
+ domain?: string
139
+ secure?: boolean
140
+ httpOnly?: boolean
141
+ sameSite?: 'strict' | 'lax' | 'none'
142
+ }
143
+ /**
144
+ * Safe localStorage wrapper (returns null on server)
145
+ */
146
+ export declare interface StorageManager {
147
+ get(key: string): string | null
148
+ set(key: string, value: string): void
149
+ remove(key: string): void
150
+ isAvailable(): boolean
151
+ }
152
+ /**
153
+ * Middleware context passed to handlers
154
+ */
155
+ export declare interface MiddlewareContext {
156
+ to: RouteLocation
157
+ from: RouteLocation | null
158
+ isClient: boolean
159
+ isServer: boolean
160
+ cookies: CookieManager
161
+ storage: StorageManager
162
+ state: Record<string, unknown>
163
+ request?: Request
164
+ responseHeaders: Headers
165
+ }
166
+ /**
167
+ * Middleware definition options
168
+ */
169
+ export declare interface MiddlewareOptions {
170
+ mode?: MiddlewareMode
171
+ }
172
+ /**
173
+ * Registered middleware definition
174
+ */
175
+ export declare interface RouteMiddlewareDefinition {
176
+ handler: RouteMiddlewareHandler
177
+ mode: MiddlewareMode
178
+ }
179
+ /**
180
+ * Navigation redirect result
181
+ */
182
+ export declare interface NavigateToResult {
183
+ type: 'redirect'
184
+ path: string
185
+ options: NavigateToOptions
186
+ }
187
+ /**
188
+ * Navigation abort result
189
+ */
190
+ export declare interface AbortNavigationResult {
191
+ type: 'abort'
192
+ error: NavigationError
193
+ }
194
+ /**
195
+ * Options for navigateTo()
196
+ */
197
+ export declare interface NavigateToOptions {
198
+ replace?: boolean
199
+ external?: boolean
200
+ redirectCode?: 301 | 302 | 303 | 307 | 308
201
+ }
202
+ /**
203
+ * Navigation error for abortNavigation()
204
+ */
205
+ export declare interface NavigationError {
206
+ statusCode: number
207
+ message: string
208
+ }
209
+ /**
210
+ * Result of running middleware chain
211
+ */
212
+ export declare interface MiddlewareResult {
213
+ passed: boolean
214
+ redirect?: NavigateToResult
215
+ abort?: AbortNavigationResult
216
+ state: Record<string, unknown>
217
+ responseHeaders: Headers
218
+ }
219
+ /**
220
+ * Middleware execution mode
221
+ */
222
+ export type MiddlewareMode = 'universal' | 'server' | 'client'
223
+ /**
224
+ * Middleware handler function
225
+ */
226
+ export type RouteMiddlewareHandler = (
227
+ context: MiddlewareContext
228
+ ) => void | Promise<void> | NavigationResult | Promise<NavigationResult | void>
229
+ /**
230
+ * Result from middleware (redirect or abort)
231
+ */
232
+ export type NavigationResult = NavigateToResult | AbortNavigationResult
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Creates a router from a pages directory
3
+ */
4
+ export declare function createRouter(baseDir: string, options?: RouterOptions): Route[];
5
+ /**
6
+ * Matches a URL pathname against routes
7
+ */
8
+ export declare function matchRoute(pathname: string, routes: Route[]): RouteMatch | null;
9
+ /**
10
+ * Gets route params from a URL
11
+ */
12
+ export declare function getRouteParams(pathname: string, routes: Route[]): Record<string, string> | null;
13
+ /**
14
+ * Pretty prints routes for console output
15
+ */
16
+ export declare function formatRoutes(routes: Route[], baseDir: string): string[];
17
+ export declare interface Route {
18
+ pattern: string
19
+ regex: RegExp
20
+ params: string[]
21
+ filePath: string
22
+ isDynamic: boolean
23
+ }
24
+ export declare interface RouteMatch {
25
+ route: Route
26
+ params: Record<string, string>
27
+ }
28
+ export declare interface RouterOptions {
29
+ pagesDir?: string
30
+ extensions?: string[]
31
+ }
package/dist/routes.d.ts CHANGED
@@ -22,13 +22,6 @@ export declare function processRouteDirectives(template: string): string;
22
22
  * Reset all routes (mainly for testing)
23
23
  */
24
24
  export declare function resetRoutes(): void;
25
- /**
26
- * Laravel-like named routes system for stx
27
- *
28
- * This provides the ability to define routes with names and generate URLs for them,
29
- * similar to Laravel's route naming and the route() helper.
30
- */
31
- /* eslint-disable no-new-func */
32
25
  declare interface RouteDefinition {
33
26
  path: string
34
27
  name?: string