@stacksjs/stx 0.2.155 → 0.2.156

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 (240) hide show
  1. package/dist/a11y.d.ts +87 -46
  2. package/dist/animation.d.ts +96 -42
  3. package/dist/appearance-bootstrap.d.ts +49 -15
  4. package/dist/asset-roots.d.ts +32 -0
  5. package/dist/asset-roots.js +7 -0
  6. package/dist/assets.d.ts +9 -7
  7. package/dist/async-components.d.ts +78 -56
  8. package/dist/auth.d.ts +3 -0
  9. package/dist/build-externalize.d.ts +40 -0
  10. package/dist/build-externalize.js +63 -0
  11. package/dist/build-id.d.ts +22 -22
  12. package/dist/build-message.d.ts +73 -2
  13. package/dist/build-message.js +47 -8
  14. package/dist/builtins/attrs.d.ts +14 -0
  15. package/dist/builtins/drawer.d.ts +22 -0
  16. package/dist/builtins/icon.d.ts +16 -2
  17. package/dist/builtins/index.d.ts +5 -15
  18. package/dist/builtins/modal.d.ts +24 -0
  19. package/dist/builtins/safe-image.d.ts +42 -0
  20. package/dist/builtins/stx-image.d.ts +27 -0
  21. package/dist/builtins/stx-link.d.ts +9 -0
  22. package/dist/builtins/stx-loading-indicator.d.ts +11 -0
  23. package/dist/builtins/suspense.d.ts +28 -0
  24. package/dist/builtins/toast.d.ts +17 -0
  25. package/dist/builtins/transition-group.d.ts +25 -0
  26. package/dist/caching.d.ts +12 -15
  27. package/dist/cli.js +1798 -908
  28. package/dist/client/directive.d.ts +7 -0
  29. package/dist/client/index.d.ts +0 -1
  30. package/dist/client-script-bundler.d.ts +63 -5
  31. package/dist/client-script-bundler.js +30 -2
  32. package/dist/client-script.d.ts +102 -47
  33. package/dist/client-script.js +15 -3
  34. package/dist/codemod.d.ts +56 -0
  35. package/dist/codemod.js +192 -0
  36. package/dist/color-mode-boot.d.ts +83 -65
  37. package/dist/component-client-factories.d.ts +1 -6
  38. package/dist/component-processing.d.ts +58 -49
  39. package/dist/component-processing.js +1 -1
  40. package/dist/component-registry.d.ts +94 -31
  41. package/dist/component-renderer.d.ts +18 -0
  42. package/dist/composable-loader.d.ts +24 -0
  43. package/dist/composable-loader.js +12 -9
  44. package/dist/composables/index.d.ts +7 -0
  45. package/dist/composables/index.js +1 -0
  46. package/dist/composables/use-fetch.js +30 -2
  47. package/dist/composables/use-form.d.ts +91 -0
  48. package/dist/composables/use-form.js +112 -0
  49. package/dist/composables.d.ts +64 -60
  50. package/dist/computed.d.ts +86 -92
  51. package/dist/conditionals.d.ts +24 -8
  52. package/dist/conditionals.js +16 -0
  53. package/dist/config.d.ts +34 -21
  54. package/dist/config.js +35 -14
  55. package/dist/craft.js +1476 -768
  56. package/dist/crosswind-config.d.ts +58 -0
  57. package/dist/crosswind-config.js +40 -0
  58. package/dist/csp.d.ts +107 -41
  59. package/dist/defer.d.ts +24 -0
  60. package/dist/dev-server/crosswind.d.ts +35 -26
  61. package/dist/dev-server/crosswind.js +2 -18
  62. package/dist/dev-server/serve-app.js +4 -3
  63. package/dist/dev-server/terminal-colors.d.ts +32 -32
  64. package/dist/directive-api.d.ts +86 -43
  65. package/dist/document-shell.d.ts +54 -41
  66. package/dist/dynamic-components.d.ts +9 -0
  67. package/dist/error-boundaries.d.ts +47 -41
  68. package/dist/error-handling.d.ts +1 -1
  69. package/dist/errors/codes.d.ts +51 -43
  70. package/dist/errors/formatter.d.ts +58 -38
  71. package/dist/errors/index.d.ts +5 -61
  72. package/dist/errors/logger.d.ts +114 -40
  73. package/dist/errors/sanitizer.d.ts +53 -23
  74. package/dist/errors/types.d.ts +44 -31
  75. package/dist/events.d.ts +86 -25
  76. package/dist/expressions.d.ts +50 -42
  77. package/dist/forms-validation.d.ts +138 -123
  78. package/dist/forms-validation.js +1 -90
  79. package/dist/forms.d.ts +120 -66
  80. package/dist/forms.js +31 -11
  81. package/dist/fragment-container.d.ts +57 -0
  82. package/dist/fragment-container.js +109 -0
  83. package/dist/framework-composables.d.ts +32 -0
  84. package/dist/head.d.ts +156 -114
  85. package/dist/heatmap.d.ts +152 -72
  86. package/dist/html-masking.d.ts +40 -34
  87. package/dist/hydration-runtime.d.ts +20 -24
  88. package/dist/i18n.d.ts +93 -32
  89. package/dist/image-optimization/auto-sibling.d.ts +32 -4
  90. package/dist/includes.d.ts +69 -7
  91. package/dist/index.d.ts +66 -0
  92. package/dist/index.js +23 -0
  93. package/dist/internal-markdown.d.ts +12 -8
  94. package/dist/island-chunking.d.ts +30 -13
  95. package/dist/keep-alive.d.ts +72 -52
  96. package/dist/layout-types.d.ts +45 -0
  97. package/dist/layout-types.js +56 -0
  98. package/dist/lazy-module.d.ts +10 -0
  99. package/dist/loops.d.ts +66 -0
  100. package/dist/loops.js +47 -6
  101. package/dist/markdown.d.ts +0 -1
  102. package/dist/media/image/component.d.ts +25 -9
  103. package/dist/media/image/directive.d.ts +15 -1
  104. package/dist/media/image/placeholder.d.ts +20 -9
  105. package/dist/media/image/processor/cache.d.ts +40 -18
  106. package/dist/media/image/processor/index.d.ts +1 -10
  107. package/dist/media/image/processor/optimizer.d.ts +12 -1
  108. package/dist/media/image/processor/responsive.d.ts +16 -6
  109. package/dist/media/image/srcset.d.ts +47 -50
  110. package/dist/media/shared/cache.d.ts +51 -31
  111. package/dist/media/shared/hash.d.ts +7 -0
  112. package/dist/media/types.d.ts +1235 -754
  113. package/dist/media/video/directive.d.ts +15 -1
  114. package/dist/media/video/index.d.ts +39 -17
  115. package/dist/media/video/processor/cache.d.ts +42 -19
  116. package/dist/media/video/processor/index.d.ts +1 -18
  117. package/dist/media/video/processor/streaming.d.ts +17 -10
  118. package/dist/media/video/processor/thumbnail.d.ts +21 -15
  119. package/dist/media/video/processor/transcoder.d.ts +11 -1
  120. package/dist/method-spoofing.d.ts +7 -0
  121. package/dist/middleware.d.ts +60 -0
  122. package/dist/owned-routes.d.ts +42 -0
  123. package/dist/owned-routes.js +26 -0
  124. package/dist/page-meta.d.ts +38 -0
  125. package/dist/page-meta.js +16 -0
  126. package/dist/parser/directive-parser.d.ts +57 -45
  127. package/dist/parser/expression-parser.d.ts +33 -35
  128. package/dist/parser/index.d.ts +4 -39
  129. package/dist/parser/tokenizer.d.ts +61 -49
  130. package/dist/partial-hydration.d.ts +82 -50
  131. package/dist/performance-utils.d.ts +217 -124
  132. package/dist/placeholder.d.ts +18 -9
  133. package/dist/plugin-system.d.ts +264 -115
  134. package/dist/process.d.ts +11 -6
  135. package/dist/process.js +21 -4
  136. package/dist/production-builder.js +7 -0
  137. package/dist/prop-sentinels.d.ts +11 -11
  138. package/dist/public-env.d.ts +14 -0
  139. package/dist/pwa/directives.d.ts +12 -3
  140. package/dist/pwa/inject.d.ts +10 -0
  141. package/dist/pwa/precache.d.ts +22 -16
  142. package/dist/pwa/service-worker.d.ts +12 -0
  143. package/dist/pwa.js +1318 -610
  144. package/dist/reactive-bindings.d.ts +34 -11
  145. package/dist/reactive.d.ts +58 -30
  146. package/dist/reactive.js +56 -31
  147. package/dist/render.js +1 -0
  148. package/dist/route-middleware.d.ts +2 -35
  149. package/dist/route-types.d.ts +134 -0
  150. package/dist/route-types.js +24 -0
  151. package/dist/router.d.ts +5 -7
  152. package/dist/routes.d.ts +1 -3
  153. package/dist/runtime-globals.d.ts +147 -24
  154. package/dist/runtime-globals.js +16 -1
  155. package/dist/runtime-injection.d.ts +8 -0
  156. package/dist/runtime-injection.js +33 -24
  157. package/dist/script-emit.d.ts +30 -0
  158. package/dist/script-json.d.ts +36 -0
  159. package/dist/script-json.js +6 -0
  160. package/dist/script-validation.d.ts +21 -4
  161. package/dist/seo.d.ts +118 -47
  162. package/dist/server-bindings.d.ts +21 -0
  163. package/dist/sfc-template.d.ts +8 -8
  164. package/dist/signal-processing.d.ts +35 -15
  165. package/dist/signals-api.d.ts +117 -58
  166. package/dist/signals-api.js +7 -4
  167. package/dist/signals.d.ts +24 -17
  168. package/dist/signals.js +765 -60
  169. package/dist/site-builder/build.js +8 -0
  170. package/dist/site-url.d.ts +46 -0
  171. package/dist/site-url.js +70 -0
  172. package/dist/slots.d.ts +86 -20
  173. package/dist/source-signature.d.ts +45 -0
  174. package/dist/source-signature.js +20 -0
  175. package/dist/ssg.d.ts +285 -142
  176. package/dist/ssg.js +1268 -556
  177. package/dist/state-dir.d.ts +4 -4
  178. package/dist/state-management.d.ts +0 -12
  179. package/dist/state-management.js +8 -25
  180. package/dist/store-imports.d.ts +23 -0
  181. package/dist/store-imports.js +3 -0
  182. package/dist/store-loader.d.ts +10 -0
  183. package/dist/store-loader.js +10 -9
  184. package/dist/story/analytics.d.ts +138 -60
  185. package/dist/story/bookmarks.d.ts +87 -34
  186. package/dist/story/cli.d.ts +123 -69
  187. package/dist/story/collect/scanner.d.ts +4 -0
  188. package/dist/story/collect/tree.d.ts +8 -1
  189. package/dist/story/commands/build.d.ts +11 -6
  190. package/dist/story/commands/dev.d.ts +15 -8
  191. package/dist/story/commands/preview.d.ts +13 -7
  192. package/dist/story/config-watcher.d.ts +20 -13
  193. package/dist/story/config.d.ts +11 -8
  194. package/dist/story/context.d.ts +14 -8
  195. package/dist/story/hmr.d.ts +24 -26
  196. package/dist/story/hot-swap.d.ts +34 -23
  197. package/dist/story/keyboard-shortcuts.d.ts +23 -18
  198. package/dist/story/output.d.ts +46 -44
  199. package/dist/story/performance.d.ts +107 -45
  200. package/dist/story/presets.d.ts +107 -41
  201. package/dist/story/renderer.d.ts +41 -27
  202. package/dist/story/search.d.ts +23 -12
  203. package/dist/story/server.d.ts +21 -11
  204. package/dist/story/setup.d.ts +23 -15
  205. package/dist/story/testing.d.ts +65 -40
  206. package/dist/story/types.d.ts +262 -160
  207. package/dist/streaming.d.ts +119 -57
  208. package/dist/stx-virtual-ts.d.ts +165 -0
  209. package/dist/stx-virtual-ts.js +372 -0
  210. package/dist/stx.d.ts +78 -1
  211. package/dist/style-scoping.d.ts +17 -4
  212. package/dist/suspense.d.ts +67 -52
  213. package/dist/teleport.d.ts +22 -0
  214. package/dist/template-tag-balance.d.ts +22 -6
  215. package/dist/transitions.d.ts +66 -55
  216. package/dist/typecheck.d.ts +77 -0
  217. package/dist/typecheck.js +156 -0
  218. package/dist/types/component-types.d.ts +187 -122
  219. package/dist/types/config-types.d.ts +758 -297
  220. package/dist/types/context-types.d.ts +46 -24
  221. package/dist/types/csp-types.d.ts +70 -66
  222. package/dist/types/directive-types.d.ts +211 -155
  223. package/dist/types/index.d.ts +6 -109
  224. package/dist/types/pwa-types.d.ts +273 -148
  225. package/dist/types.d.ts +0 -1
  226. package/dist/typescript-templates.d.ts +11 -0
  227. package/dist/unresolved-identifiers.d.ts +24 -22
  228. package/dist/unresolved-identifiers.js +2 -0
  229. package/dist/utils.d.ts +24 -21
  230. package/dist/validator.d.ts +28 -26
  231. package/dist/variable-extractor.d.ts +48 -13
  232. package/dist/variable-extractor.js +27 -4
  233. package/dist/view-composers.d.ts +80 -81
  234. package/dist/virtual-scrolling.d.ts +101 -81
  235. package/dist/vue-template.d.ts +23 -0
  236. package/dist/web-components/css-scoping.d.ts +21 -11
  237. package/dist/web-components.d.ts +81 -58
  238. package/dist/x-element.d.ts +0 -1
  239. package/package.json +5 -5
  240. package/stx.d.ts +78 -1
@@ -1,3 +1,27 @@
1
+ /**
2
+ * Template Validation
3
+ *
4
+ * Provides validation utilities for stx templates before processing.
5
+ * Checks for common syntax errors, structural issues, and potential security problems.
6
+ */
7
+ /**
8
+ * Template validation error
9
+ */
10
+ export interface TemplateValidationError {
11
+ type: 'syntax' | 'directive' | 'expression' | 'structure';
12
+ message: string;
13
+ line?: number;
14
+ column?: number;
15
+ suggestion?: string;
16
+ }
17
+ /**
18
+ * Template validation result
19
+ */
20
+ export interface TemplateValidationResult {
21
+ valid: boolean;
22
+ errors: TemplateValidationError[];
23
+ warnings: TemplateValidationError[];
24
+ }
1
25
  /**
2
26
  * Validate a template before processing
3
27
  *
@@ -27,7 +51,10 @@ export declare function validateTemplate(template: string): TemplateValidationRe
27
51
  * @param position - Character position
28
52
  * @returns Line and column numbers (1-indexed)
29
53
  */
30
- export declare function getPositionInfo(template: string, position: number): { line: number, column: number };
54
+ export declare function getPositionInfo(template: string, position: number): {
55
+ line: number;
56
+ column: number;
57
+ };
31
58
  /**
32
59
  * Validate a specific directive's syntax
33
60
  *
@@ -36,7 +63,6 @@ export declare function getPositionInfo(template: string, position: number): { l
36
63
  * @param params - Parameters passed to the directive
37
64
  * @returns Validation errors, if any
38
65
  */
39
- // eslint-disable-next-line pickier/no-unused-vars
40
66
  export declare function validateDirective(directiveName: string, content: string, params: string[]): TemplateValidationError[];
41
67
  /**
42
68
  * Check if a template has any directives
@@ -52,27 +78,3 @@ export declare function hasDirectives(template: string): boolean;
52
78
  * @returns Array of directive names (without @ prefix)
53
79
  */
54
80
  export declare function extractDirectiveNames(template: string): string[];
55
- /**
56
- * Template Validation
57
- *
58
- * Provides validation utilities for stx templates before processing.
59
- * Checks for common syntax errors, structural issues, and potential security problems.
60
- */
61
- /**
62
- * Template validation error
63
- */
64
- export declare interface TemplateValidationError {
65
- type: 'syntax' | 'directive' | 'expression' | 'structure'
66
- message: string
67
- line?: number
68
- column?: number
69
- suggestion?: string
70
- }
71
- /**
72
- * Template validation result
73
- */
74
- export declare interface TemplateValidationResult {
75
- valid: boolean
76
- errors: TemplateValidationError[]
77
- warnings: TemplateValidationError[]
78
- }
@@ -13,6 +13,47 @@ export declare function stripTypeScript(scriptContent: string): string;
13
13
  * Bun and Node.
14
14
  */
15
15
  export declare function isModuleResolutionFailure(message: string): boolean;
16
+ /**
17
+ * Whether a script failed because it named something that does not exist.
18
+ *
19
+ * The same category as a module that will not resolve, and worth the same
20
+ * unconditional warning for the same reason: it is never the legitimate case
21
+ * the silence exists for. A page that uses only client APIs fails here on
22
+ * `document` or `window`, which is expected and quiet - but those are the
23
+ * *only* names it fails on, and a script that trips over anything else has a
24
+ * bug in it.
25
+ *
26
+ * A missing binding is particularly cruel because optional chaining does not
27
+ * help. `foo?.bar` guards an undefined *property*; an undefined *identifier* is
28
+ * a ReferenceError before the chain is reached, so a script that carefully
29
+ * writes `someContext?.value` still throws and still takes every variable in
30
+ * the file down with it. A page then renders its empty-state branch and reads
31
+ * as a correct answer rather than as a failure, which is exactly the shape that
32
+ * is expensive to find.
33
+ */
34
+ export declare function isMissingBindingFailure(message: string): boolean;
35
+ /**
36
+ * Extract variables from script content and add them to context
37
+ *
38
+ * @param scriptContent - The JavaScript/TypeScript code from a <script> tag
39
+ * @param context - The context object to populate with extracted variables
40
+ * @param filePath - Path to the file (for error messages)
41
+ */
42
+ export interface ExtractVariablesOptions {
43
+ /**
44
+ * Don't overwrite a context key that already has a value. Use this
45
+ * when extracting from a LAYOUT or PARTIAL `<script server>` so the
46
+ * child page's identifier wins — layouts can declare stubs/defaults
47
+ * (`const user = { avatarInitials: 'JD' }`) without clobbering the
48
+ * full object the page set on the same name.
49
+ *
50
+ * Off by default: page-level extraction (in render.ts) still
51
+ * overrides caller-supplied context values, matching pre-flag
52
+ * behaviour. Only the layout/partial extraction path in process.ts
53
+ * passes this flag on.
54
+ */
55
+ preserveExisting?: boolean;
56
+ }
16
57
  export declare function extractVariables(scriptContent: string, context: Record<string, unknown>, filePath: string, options?: ExtractVariablesOptions): Promise<void>;
17
58
  /**
18
59
  * Convert ES module syntax to CommonJS
@@ -55,7 +96,11 @@ export declare function convertToCommonJS(scriptContent: string, filePath?: stri
55
96
  * Returns null when the line is not a simple declaration, which leaves the
56
97
  * destructuring and multi-line paths below to handle it as before.
57
98
  */
58
- export declare function splitDeclaration(line: string): { type: string, name: string, value: string } | null;
99
+ export declare function splitDeclaration(line: string): {
100
+ type: string;
101
+ name: string;
102
+ value: string;
103
+ } | null;
59
104
  /**
60
105
  * Extract script content from an HTML template
61
106
  *
@@ -63,8 +108,8 @@ export declare function splitDeclaration(line: string): { type: string, name: st
63
108
  * @returns Object with script content and template without script tags
64
109
  */
65
110
  export declare function extractScriptFromTemplate(template: string): {
66
- scriptContent: string
67
- templateWithoutScript: string
111
+ scriptContent: string;
112
+ templateWithoutScript: string;
68
113
  };
69
114
  /**
70
115
  * Check if script content has any variables to extract
@@ -73,13 +118,3 @@ export declare function extractScriptFromTemplate(template: string): {
73
118
  * @returns Whether variables are present
74
119
  */
75
120
  export declare function hasVariables(scriptContent: string): boolean;
76
- /**
77
- * Extract variables from script content and add them to context
78
- *
79
- * @param scriptContent - The JavaScript/TypeScript code from a <script> tag
80
- * @param context - The context object to populate with extracted variables
81
- * @param filePath - Path to the file (for error messages)
82
- */
83
- export declare interface ExtractVariablesOptions {
84
- preserveExisting?: boolean
85
- }
@@ -213,6 +213,11 @@ export function stripTypeScript(scriptContent) {
213
213
  export function isModuleResolutionFailure(message) {
214
214
  return /cannot find module|could not resolve|module not found|failed to resolve/i.test(message);
215
215
  }
216
+ export function isMissingBindingFailure(message) {
217
+ if (!/is not defined|can't find variable/i.test(message))
218
+ return !1;
219
+ return !/\b(document|window|navigator|localStorage|sessionStorage|self)\b/.test(message);
220
+ }
216
221
  export async function extractVariables(scriptContent, context, filePath, options = {}) {
217
222
  if (!scriptContent.trim())
218
223
  return;
@@ -313,6 +318,13 @@ export async function extractVariables(scriptContent, context, filePath, options
313
318
  if (config.title !== void 0 || config.description !== void 0)
314
319
  useSeoMeta({ title: config.title, description: config.description });
315
320
  }
321
+ function defineClientPayload(payload) {
322
+ if (!payload || typeof payload !== "object")
323
+ return;
324
+ const declared = context.__stxClientPayload ?? {};
325
+ Object.assign(declared, payload);
326
+ context.__stxClientPayload = declared;
327
+ }
316
328
  const useRoute = () => {
317
329
  const serveCtx = context.__stxServeContext, search = context.__stxServeSearch ?? serveCtx?.search ?? "", path = serveCtx?.path ?? "";
318
330
  return {
@@ -464,11 +476,11 @@ export async function extractVariables(scriptContent, context, filePath, options
464
476
  scriptContextKeys.push(filteredContextKeys[i]);
465
477
  scriptContextValues.push(filteredContextValues[i]);
466
478
  }
467
- const result = await Function("module", "exports", "require", "props", "$props", "defineProps", "withDefaults", "state", "derived", "effect", "batch", "onMount", "onDestroy", "definePageMeta", "useRoute", "useRouter", "useHead", "useSeoMeta", "ref", "reactive", "computed", "watch", "onMounted", "onUnmounted", "nextTick", "defineEmits", "defineExpose", "defineSlots", "provide", "inject", "useColorMode", "useDark", "useMediaQuery", "useScrollLock", "usePreferredDark", "usePreferredLight", "usePreferredReducedMotion", "usePreferredContrast", "window", "document", "console", "confirm", "alert", "fetch", "params", ...propArgNames, ...scriptContextKeys, `return (async () => {
479
+ const result = await Function("module", "exports", "require", "props", "$props", "defineProps", "withDefaults", "defineClientPayload", "state", "derived", "effect", "batch", "onMount", "onDestroy", "definePageMeta", "useRoute", "useRouter", "useHead", "useSeoMeta", "ref", "reactive", "computed", "watch", "onMounted", "onUnmounted", "nextTick", "defineEmits", "defineExpose", "defineSlots", "provide", "inject", "useColorMode", "useDark", "useMediaQuery", "useScrollLock", "usePreferredDark", "usePreferredLight", "usePreferredReducedMotion", "usePreferredContrast", "window", "document", "console", "confirm", "alert", "fetch", "params", ...propArgNames, ...scriptContextKeys, `return (async () => {
468
480
  ${convertedScript}
469
481
  ${reSyncCode}
470
482
  return module.exports
471
- })()`)(module, exports, requireFn, propsObj, $props, defineProps, withDefaults, state, derived, effect, batch, onMount, onDestroy, definePageMeta, useRoute, useRouter, useHead, useSeoMeta, ref, reactive, computed, watch, onMounted, onUnmounted, nextTick, defineEmits, defineExpose, defineSlots, provide, inject, useColorMode, useDark, useMediaQuery, useScrollLock, usePreferredDark, usePreferredLight, usePreferredReducedMotion, usePreferredContrast, windowProxy, mockDocument, mockConsole, mockWindow.confirm, mockWindow.alert, mockWindow.fetch, paramsObj, ...propArgValues, ...scriptContextValues);
483
+ })()`)(module, exports, requireFn, propsObj, $props, defineProps, withDefaults, defineClientPayload, state, derived, effect, batch, onMount, onDestroy, definePageMeta, useRoute, useRouter, useHead, useSeoMeta, ref, reactive, computed, watch, onMounted, onUnmounted, nextTick, defineEmits, defineExpose, defineSlots, provide, inject, useColorMode, useDark, useMediaQuery, useScrollLock, usePreferredDark, usePreferredLight, usePreferredReducedMotion, usePreferredContrast, windowProxy, mockDocument, mockConsole, mockWindow.confirm, mockWindow.alert, mockWindow.fetch, paramsObj, ...propArgValues, ...scriptContextValues);
472
484
  if (options.preserveExisting) {
473
485
  for (const [key, value] of Object.entries(result))
474
486
  if (!(key in context) || context[key] === void 0)
@@ -482,6 +494,8 @@ export async function extractVariables(scriptContent, context, filePath, options
482
494
  const msg = primaryError instanceof Error ? primaryError.message : String(primaryError);
483
495
  if (isModuleResolutionFailure(msg))
484
496
  console.warn(`[stx] server <script> in ${filePath ?? "<unknown>"} imports a module that does not resolve, so every variable in that script is undefined. Cause: ${msg}`);
497
+ else if (isMissingBindingFailure(msg))
498
+ console.warn(`[stx] server <script> in ${filePath ?? "<unknown>"} names something that does not exist, so every variable in that script is undefined. Optional chaining does not help here: an undefined identifier throws before the chain is reached. Cause: ${msg}`);
485
499
  else if (process.env.STX_DEBUG)
486
500
  console.warn(`[stx] server <script> did not execute in ${filePath ?? "<unknown>"} \u2014 falling back to static extraction. Cause: ${msg}`);
487
501
  try {
@@ -1111,8 +1125,17 @@ function isValueComplete(value) {
1111
1125
  }
1112
1126
  return depth.paren === 0 && depth.bracket === 0 && depth.brace === 0 && inString === null;
1113
1127
  }
1128
+ function findFunctionBodyBrace(functionLine) {
1129
+ const parenPos = functionLine.indexOf("(");
1130
+ if (parenPos === -1)
1131
+ return functionLine.indexOf("{");
1132
+ const paramsEnd = findMatchingDelimiter(functionLine, "(", ")", parenPos);
1133
+ if (paramsEnd === -1)
1134
+ return -1;
1135
+ return functionLine.indexOf("{", paramsEnd);
1136
+ }
1114
1137
  function needsMultilineFunctionReading(functionLine) {
1115
- const bracePos = functionLine.indexOf("{");
1138
+ const bracePos = findFunctionBodyBrace(functionLine);
1116
1139
  if (bracePos === -1)
1117
1140
  return !0;
1118
1141
  return findMatchingDelimiter(functionLine, "{", "}", bracePos) === -1;
@@ -1139,7 +1162,7 @@ ${lines[i]}`;
1139
1162
  function readMultilineFunction(lines, startIndex, initialFunction) {
1140
1163
  let functionCode = initialFunction, i = startIndex + 1;
1141
1164
  while (i < lines.length) {
1142
- const bracePos = functionCode.indexOf("{");
1165
+ const bracePos = findFunctionBodyBrace(functionCode);
1143
1166
  if (bracePos !== -1) {
1144
1167
  if (findMatchingDelimiter(functionCode, "{", "}", bracePos) !== -1)
1145
1168
  break;
@@ -1,3 +1,83 @@
1
+ /**
2
+ * View Composers Module
3
+ *
4
+ * Similar to Laravel's View Composers, this module allows registering callbacks
5
+ * that automatically run whenever a specific view (or views matching a pattern)
6
+ * is rendered. Use this to inject data into templates without manually passing
7
+ * it every time.
8
+ *
9
+ * ## Use Cases
10
+ *
11
+ * - Inject user data into all views
12
+ * - Add navigation data to layout templates
13
+ * - Load settings for specific page types
14
+ * - Populate dropdown options across forms
15
+ *
16
+ * ## Registration Methods
17
+ *
18
+ * ### Exact Match
19
+ * ```typescript
20
+ * import { composer } from 'stx'
21
+ *
22
+ * // Match by exact view name
23
+ * composer('dashboard', async (context) => {
24
+ * context.stats = await fetchDashboardStats()
25
+ * })
26
+ *
27
+ * // Match by full file path
28
+ * composer('/views/admin/users.stx', (context) => {
29
+ * context.roles = ['admin', 'editor', 'viewer']
30
+ * })
31
+ * ```
32
+ *
33
+ * ### Pattern Match
34
+ * ```typescript
35
+ * import { composerPattern } from 'stx'
36
+ *
37
+ * // Match all admin views
38
+ * composerPattern(/^admin/, (context) => {
39
+ * context.isAdmin = true
40
+ * })
41
+ *
42
+ * // Match with string pattern (converted to RegExp)
43
+ * composerPattern('.*\\.settings\\.', (context) => {
44
+ * context.settingsMenu = loadSettingsMenu()
45
+ * })
46
+ * ```
47
+ *
48
+ * ## Execution Order
49
+ *
50
+ * 1. Exact match composers (by full file path)
51
+ * 2. Exact match composers (by view name only)
52
+ * 3. Pattern match composers (in registration order)
53
+ *
54
+ * All composers for a matching view run in sequence.
55
+ * Async composers are awaited before the next runs.
56
+ *
57
+ * ## Important Notes
58
+ *
59
+ * - Composers modify the context object directly (no return value needed)
60
+ * - Composers are global and persist for the application lifetime
61
+ * - Use `clearComposers()` to reset in tests
62
+ *
63
+ * @module view-composers
64
+ */
65
+ /**
66
+ * Callback function type for view composers.
67
+ *
68
+ * @param context - The template context object (modify this directly)
69
+ * @param filePath - Full path to the template file being rendered
70
+ * @returns void or a Promise that resolves to void
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const myComposer: ViewComposerCallback = async (context, filePath) => {
75
+ * context.user = await getCurrentUser()
76
+ * context.viewPath = filePath
77
+ * }
78
+ * ```
79
+ */
80
+ export type ViewComposerCallback = (context: Record<string, any>, filePath: string) => void | Promise<void>;
1
81
  /**
2
82
  * Register a composer for a specific view.
3
83
  *
@@ -89,84 +169,3 @@ export declare function runComposers(filePath: string, context: Record<string, a
89
169
  * ```
90
170
  */
91
171
  export declare function clearComposers(): void;
92
- /**
93
- * View Composers Module
94
- *
95
- * Similar to Laravel's View Composers, this module allows registering callbacks
96
- * that automatically run whenever a specific view (or views matching a pattern)
97
- * is rendered. Use this to inject data into templates without manually passing
98
- * it every time.
99
- *
100
- * ## Use Cases
101
- *
102
- * - Inject user data into all views
103
- * - Add navigation data to layout templates
104
- * - Load settings for specific page types
105
- * - Populate dropdown options across forms
106
- *
107
- * ## Registration Methods
108
- *
109
- * ### Exact Match
110
- * ```typescript
111
- * import { composer } from 'stx'
112
- *
113
- * // Match by exact view name
114
- * composer('dashboard', async (context) => {
115
- * context.stats = await fetchDashboardStats()
116
- * })
117
- *
118
- * // Match by full file path
119
- * composer('/views/admin/users.stx', (context) => {
120
- * context.roles = ['admin', 'editor', 'viewer']
121
- * })
122
- * ```
123
- *
124
- * ### Pattern Match
125
- * ```typescript
126
- * import { composerPattern } from 'stx'
127
- *
128
- * // Match all admin views
129
- * composerPattern(/^admin/, (context) => {
130
- * context.isAdmin = true
131
- * })
132
- *
133
- * // Match with string pattern (converted to RegExp)
134
- * composerPattern('.*\\.settings\\.', (context) => {
135
- * context.settingsMenu = loadSettingsMenu()
136
- * })
137
- * ```
138
- *
139
- * ## Execution Order
140
- *
141
- * 1. Exact match composers (by full file path)
142
- * 2. Exact match composers (by view name only)
143
- * 3. Pattern match composers (in registration order)
144
- *
145
- * All composers for a matching view run in sequence.
146
- * Async composers are awaited before the next runs.
147
- *
148
- * ## Important Notes
149
- *
150
- * - Composers modify the context object directly (no return value needed)
151
- * - Composers are global and persist for the application lifetime
152
- * - Use `clearComposers()` to reset in tests
153
- *
154
- * @module view-composers
155
- */
156
- /**
157
- * Callback function type for view composers.
158
- *
159
- * @param context - The template context object (modify this directly)
160
- * @param filePath - Full path to the template file being rendered
161
- * @returns void or a Promise that resolves to void
162
- *
163
- * @example
164
- * ```typescript
165
- * const myComposer: ViewComposerCallback = async (context, filePath) => {
166
- * context.user = await getCurrentUser()
167
- * context.viewPath = filePath
168
- * }
169
- * ```
170
- */
171
- // eslint-disable-next-line pickier/no-unused-vars
172
- export type ViewComposerCallback = (context: Record<string, any>, filePath: string) => void | Promise<void>;
@@ -1,3 +1,69 @@
1
+ /**
2
+ * Virtual Scrolling Module
3
+ *
4
+ * Provides efficient rendering of large lists using windowing/virtualization.
5
+ * Only renders items that are visible in the viewport, dramatically improving
6
+ * performance for lists with thousands of items.
7
+ *
8
+ * @example
9
+ * ```html
10
+ * @virtualList(items, { itemHeight: 50, containerHeight: 400 })
11
+ * <div class="item">{{ item.name }}</div>
12
+ * @endvirtualList
13
+ * ```
14
+ */
15
+ export interface VirtualListOptions {
16
+ /** Height of each item in pixels */
17
+ itemHeight: number;
18
+ /** Height of the container in pixels */
19
+ containerHeight: number;
20
+ /** Number of items to render outside the visible area (buffer) */
21
+ overscan?: number;
22
+ /** Unique key property for items */
23
+ keyProperty?: string;
24
+ /** Enable dynamic item heights */
25
+ dynamicHeight?: boolean;
26
+ /** Estimated item height for dynamic heights */
27
+ estimatedItemHeight?: number;
28
+ /** Scroll behavior: 'auto' | 'smooth' */
29
+ scrollBehavior?: 'auto' | 'smooth';
30
+ /** Direction: 'vertical' | 'horizontal' */
31
+ direction?: 'vertical' | 'horizontal';
32
+ /** CSS class for the container */
33
+ containerClass?: string;
34
+ /** CSS class for the viewport */
35
+ viewportClass?: string;
36
+ /** CSS class for each item wrapper */
37
+ itemClass?: string;
38
+ }
39
+ export interface VirtualListState {
40
+ /** Start index of visible items */
41
+ startIndex: number;
42
+ /** End index of visible items */
43
+ endIndex: number;
44
+ /** Current scroll position */
45
+ scrollTop: number;
46
+ /** Total height of all items */
47
+ totalHeight: number;
48
+ /** Visible items */
49
+ visibleItems: unknown[];
50
+ /** Item heights cache for dynamic heights */
51
+ itemHeights: Map<number, number>;
52
+ }
53
+ export interface VirtualScrollInstance {
54
+ /** Scroll to a specific index */
55
+ scrollToIndex: (index: number, behavior?: ScrollBehavior) => void;
56
+ /** Scroll to a specific offset */
57
+ scrollToOffset: (offset: number, behavior?: ScrollBehavior) => void;
58
+ /** Get current scroll state */
59
+ getState: () => VirtualListState;
60
+ /** Force recalculation of visible items */
61
+ refresh: () => void;
62
+ /** Update items */
63
+ setItems: (items: unknown[]) => void;
64
+ /** Destroy the instance */
65
+ destroy: () => void;
66
+ }
1
67
  /**
2
68
  * Creates a virtual scroll instance for a list of items
3
69
  */
@@ -14,94 +80,48 @@ export declare function generateVirtualListCSS(): string;
14
80
  * Hook to create a reactive virtual list
15
81
  */
16
82
  export declare function useVirtualList<T>(items: () => T[], options: VirtualListOptions): {
17
- visibleItems: () => T[]
18
- totalHeight: () => number
19
- containerProps: () => Record<string, unknown>
20
- itemProps: (index: number) => Record<string, unknown>
21
- scrollToIndex: (index: number) => void
83
+ visibleItems: () => T[];
84
+ totalHeight: () => number;
85
+ containerProps: () => Record<string, unknown>;
86
+ itemProps: (index: number) => Record<string, unknown>;
87
+ scrollToIndex: (index: number) => void;
22
88
  };
89
+ export interface InfiniteScrollOptions extends VirtualListOptions {
90
+ /** Threshold in pixels before end to trigger load more */
91
+ threshold?: number;
92
+ /** Callback when more items should be loaded */
93
+ onLoadMore?: () => Promise<void>;
94
+ /** Whether more items are available */
95
+ hasMore?: boolean;
96
+ /** Loading state */
97
+ isLoading?: boolean;
98
+ }
23
99
  /**
24
100
  * Process @infiniteList directives for infinite scrolling
25
101
  */
26
102
  export declare function processInfiniteListDirectives(template: string, context?: Record<string, unknown>, _filePath?: string): string;
103
+ export interface VirtualGridOptions {
104
+ /** Number of columns */
105
+ columns: number;
106
+ /** Row height in pixels */
107
+ rowHeight: number;
108
+ /** Container height in pixels */
109
+ containerHeight: number;
110
+ /** Gap between items */
111
+ gap?: number;
112
+ /** Overscan rows */
113
+ overscan?: number;
114
+ }
27
115
  /**
28
116
  * Process @virtualGrid directives for grid virtualization
29
117
  */
30
118
  export declare function processVirtualGridDirectives(template: string, context?: Record<string, unknown>, _filePath?: string): string;
31
- /* eslint-disable prefer-const, style/max-statements-per-line, no-super-linear-backtracking, regexp/no-unused-capturing-group */
32
- /**
33
- * Virtual Scrolling Module
34
- *
35
- * Provides efficient rendering of large lists using windowing/virtualization.
36
- * Only renders items that are visible in the viewport, dramatically improving
37
- * performance for lists with thousands of items.
38
- *
39
- * @example
40
- * ```html
41
- * @virtualList(items, { itemHeight: 50, containerHeight: 400 })
42
- * <div class="item">{{ item.name }}</div>
43
- * @endvirtualList
44
- * ```
45
- */
46
- // ============================================================================
47
- // Types
48
- // ============================================================================
49
- export declare interface VirtualListOptions {
50
- itemHeight: number
51
- containerHeight: number
52
- overscan?: number
53
- keyProperty?: string
54
- dynamicHeight?: boolean
55
- estimatedItemHeight?: number
56
- scrollBehavior?: 'auto' | 'smooth'
57
- direction?: 'vertical' | 'horizontal'
58
- containerClass?: string
59
- viewportClass?: string
60
- itemClass?: string
61
- }
62
- export declare interface VirtualListState {
63
- startIndex: number
64
- endIndex: number
65
- scrollTop: number
66
- totalHeight: number
67
- visibleItems: unknown[]
68
- itemHeights: Map<number, number>
69
- }
70
- export declare interface VirtualScrollInstance {
71
- scrollToIndex: (index: number, behavior?: ScrollBehavior) => void
72
- scrollToOffset: (offset: number, behavior?: ScrollBehavior) => void
73
- getState: () => VirtualListState
74
- refresh: () => void
75
- setItems: (items: unknown[]) => void
76
- destroy: () => void
77
- }
78
- // ============================================================================
79
- // Infinite Scroll Support
80
- // ============================================================================
81
- export declare interface InfiniteScrollOptions extends VirtualListOptions {
82
- threshold?: number
83
- onLoadMore?: () => Promise<void>
84
- hasMore?: boolean
85
- isLoading?: boolean
86
- }
87
- // ============================================================================
88
- // Grid Virtualization
89
- // ============================================================================
90
- export declare interface VirtualGridOptions {
91
- columns: number
92
- rowHeight: number
93
- containerHeight: number
94
- gap?: number
95
- overscan?: number
96
- }
97
- // ============================================================================
98
- // Exports
99
- // ============================================================================
100
- export default {
101
- createVirtualList,
102
- processVirtualListDirectives,
103
- processInfiniteListDirectives,
104
- processVirtualGridDirectives,
105
- generateVirtualListCSS,
106
- useVirtualList,
119
+ declare const _default: {
120
+ createVirtualList: typeof createVirtualList;
121
+ processVirtualListDirectives: typeof processVirtualListDirectives;
122
+ processInfiniteListDirectives: typeof processInfiniteListDirectives;
123
+ processVirtualGridDirectives: typeof processVirtualGridDirectives;
124
+ generateVirtualListCSS: typeof generateVirtualListCSS;
125
+ useVirtualList: typeof useVirtualList;
107
126
  };
127
+ export default _default;
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Vue Template Directive Transformer
3
+ *
4
+ * Pre-processing transform that converts Vue template syntax into existing stx directives.
5
+ * This runs early in the processing pipeline, before any directive processing,
6
+ * allowing users to write Vue-style templates that leverage stx's existing infrastructure.
7
+ *
8
+ * Supported Vue directives:
9
+ * - v-if, v-else-if, v-else → @if/@elseif/@else/@endif
10
+ * - v-for → @foreach/@endforeach
11
+ * - v-show → @show attribute
12
+ * - v-model → @model (native) or :modelValue + @update:modelValue (components)
13
+ * - v-bind: / : → @bind: attribute
14
+ * - v-on: / @ (in Vue context) → @ event directives
15
+ * - v-html → {!! expr !!}
16
+ * - v-text → {{ expr }}
17
+ * - v-pre → data-stx-skip
18
+ * - v-once → @once/@endonce wrapper
19
+ * - v-cloak → preserved, removed by runtime
20
+ * - v-memo → data-stx-memo attribute
21
+ *
22
+ * @module vue-template
23
+ */
1
24
  /**
2
25
  * Check if template contains any Vue-style directives.
3
26
  * Quick check to avoid unnecessary processing.
@@ -1,3 +1,22 @@
1
+ /**
2
+ * CSS Scoping for Web Components
3
+ *
4
+ * Provides utilities for scoping CSS styles to specific components
5
+ * to prevent style leakage in Shadow DOM and for component isolation.
6
+ */
7
+ /**
8
+ * Options for CSS scoping
9
+ */
10
+ export interface CssScopingOptions {
11
+ /** Prefix to add to selectors */
12
+ prefix?: string;
13
+ /** Whether to preserve :host selectors */
14
+ preserveHost?: boolean;
15
+ /** Whether to scope keyframe names */
16
+ scopeKeyframes?: boolean;
17
+ /** Whether to scope CSS custom properties */
18
+ scopeCustomProperties?: boolean;
19
+ }
1
20
  /**
2
21
  * Generate a unique component ID based on hash
3
22
  */
@@ -24,8 +43,8 @@ export declare function scopeCss(css: string, componentId: string, options?: Css
24
43
  * @returns Object with CSS content and template without style tags
25
44
  */
26
45
  export declare function extractStyleFromTemplate(template: string): {
27
- css: string
28
- templateWithoutStyle: string
46
+ css: string;
47
+ templateWithoutStyle: string;
29
48
  };
30
49
  /**
31
50
  * Inject scoped CSS into a template
@@ -43,12 +62,3 @@ export declare function injectScopedCss(template: string, scopedCss: string, pos
43
62
  * @returns CSS suitable for Shadow DOM
44
63
  */
45
64
  export declare function generateShadowDomCss(css: string): string;
46
- /**
47
- * Options for CSS scoping
48
- */
49
- export declare interface CssScopingOptions {
50
- prefix?: string
51
- preserveHost?: boolean
52
- scopeKeyframes?: boolean
53
- scopeCustomProperties?: boolean
54
- }