@stacksjs/stx 0.2.152 → 0.2.154

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 (88) hide show
  1. package/dist/animation.js +6 -6
  2. package/dist/app-shell.js +2 -1
  3. package/dist/browser-composables.d.ts +8 -0
  4. package/dist/build-id.d.ts +49 -0
  5. package/dist/build-id.js +20 -0
  6. package/dist/build-message.d.ts +10 -0
  7. package/dist/build-message.js +26 -0
  8. package/dist/builtins/attrs.js +6 -1
  9. package/dist/cli.js +1743 -1255
  10. package/dist/client-script-bundler.js +2 -4
  11. package/dist/client-script.d.ts +29 -0
  12. package/dist/client-script.js +142 -97
  13. package/dist/color-mode-boot.d.ts +46 -10
  14. package/dist/color-mode-boot.js +53 -13
  15. package/dist/component-client-factories.js +3 -2
  16. package/dist/component-renderer.js +10 -21
  17. package/dist/composables/index.d.ts +8 -1
  18. package/dist/composables/use-clipboard.d.ts +1 -5
  19. package/dist/composables/use-clipboard.js +57 -46
  20. package/dist/composables/use-color-mode.d.ts +19 -4
  21. package/dist/composables/use-color-mode.js +49 -28
  22. package/dist/composables/use-router.d.ts +28 -11
  23. package/dist/composables/use-router.js +63 -9
  24. package/dist/composables/use-storage.d.ts +14 -15
  25. package/dist/composables/use-storage.js +63 -2
  26. package/dist/config.js +22 -7
  27. package/dist/craft.js +1319 -841
  28. package/dist/dev-server/crosswind.js +8 -6
  29. package/dist/dev-server/serve-app.js +13 -7
  30. package/dist/dev-server/serve-markdown.js +4 -1
  31. package/dist/dev-server/serve-multi.js +32 -20
  32. package/dist/dev-server/types.d.ts +8 -1
  33. package/dist/document-shell.d.ts +120 -0
  34. package/dist/document-shell.js +161 -14
  35. package/dist/dynamic-components.js +123 -4
  36. package/dist/events.d.ts +26 -49
  37. package/dist/events.js +23 -9
  38. package/dist/expressions.d.ts +1 -1
  39. package/dist/expressions.js +3 -3
  40. package/dist/framework-composables.d.ts +41 -0
  41. package/dist/framework-composables.js +115 -0
  42. package/dist/head.js +5 -1
  43. package/dist/hot-reload.js +8 -2
  44. package/dist/includes.js +4 -4
  45. package/dist/index.d.ts +17 -0
  46. package/dist/index.js +9 -0
  47. package/dist/isolated-build.d.ts +12 -0
  48. package/dist/isolated-build.js +18 -0
  49. package/dist/plugin-system.d.ts +1 -1
  50. package/dist/process.js +46 -12
  51. package/dist/production-builder.js +3 -1
  52. package/dist/production-server.js +4 -1
  53. package/dist/prop-sentinels.d.ts +31 -0
  54. package/dist/prop-sentinels.js +7 -0
  55. package/dist/pwa.js +1258 -780
  56. package/dist/reactive.js +1 -1
  57. package/dist/reactivity.d.ts +0 -15
  58. package/dist/reactivity.js +15 -6
  59. package/dist/runtime-globals.d.ts +40 -2
  60. package/dist/runtime-globals.js +90 -0
  61. package/dist/runtime-injection.d.ts +51 -0
  62. package/dist/runtime-injection.js +13 -0
  63. package/dist/script-emit.d.ts +20 -0
  64. package/dist/script-emit.js +11 -0
  65. package/dist/script-validation.js +12 -7
  66. package/dist/signal-processing.js +25 -40
  67. package/dist/signals-api.d.ts +30 -0
  68. package/dist/signals-api.js +18 -0
  69. package/dist/signals.js +532 -85
  70. package/dist/site-builder/build.js +21 -7
  71. package/dist/site-builder/seo.js +19 -10
  72. package/dist/site-builder/theme.js +5 -4
  73. package/dist/site-builder/types.d.ts +1 -0
  74. package/dist/ssg.js +1255 -777
  75. package/dist/state-management.js +4 -1
  76. package/dist/store-loader.d.ts +0 -11
  77. package/dist/store-loader.js +27 -3
  78. package/dist/strict-lint.d.ts +9 -6
  79. package/dist/strict-lint.js +2 -21
  80. package/dist/stx.d.ts +125 -22
  81. package/dist/types/config-types.d.ts +1 -0
  82. package/dist/unresolved-identifiers.d.ts +50 -0
  83. package/dist/unresolved-identifiers.js +146 -0
  84. package/dist/utils.js +3 -3
  85. package/dist/variable-extractor.js +17 -1
  86. package/dist/x-element.js +1 -1
  87. package/package.json +5 -5
  88. package/stx.d.ts +125 -22
package/dist/x-element.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function generateXElementRuntime() {
2
- return `<script data-stx-scoped data-stx-x-element-runtime>
2
+ return `<script data-stx-scoped data-stx-x-element-runtime data-stx-run="always">
3
3
  (function() {
4
4
  'use strict';
5
5
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.152",
4
+ "version": "0.2.154",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -117,12 +117,12 @@
117
117
  "dependencies": {
118
118
  "@cwcss/crosswind": "^0.2.14",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/desktop": "0.2.152",
121
- "@stacksjs/sanitizer": "0.2.152",
120
+ "@stacksjs/desktop": "0.2.154",
121
+ "@stacksjs/sanitizer": "0.2.154",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.152",
123
+ "bun-plugin-stx": "0.2.154",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.152",
125
+ "stx-router": "0.2.154",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.1.9",
128
128
  "ts-syntax-highlighter": "^0.2.1"
package/stx.d.ts CHANGED
@@ -82,23 +82,49 @@ declare function onMount(_fn: () => void | StxCleanup): void
82
82
  declare function onDestroy(_fn: () => void): void
83
83
  declare function onBeforeMount(_fn: () => void): void
84
84
  declare function onMounted(_fn: () => void | StxCleanup): void
85
- declare function onBeforeUpdate(_fn: () => void): void
86
- declare function onUpdated(_fn: () => void): void
87
85
  declare function onBeforeUnmount(_fn: () => void): void
88
86
  declare function onUnmounted(_fn: () => void): void
89
- declare function onErrorCaptured(_fn: (error: unknown, instance: HTMLElement | null, info: string) => boolean | void): void
87
+ // onBeforeUpdate / onUpdated / onErrorCaptured are NOT declared: they exist in
88
+ // reactivity.ts and composition-api.ts but have no client-runtime counterpart,
89
+ // so declaring them promised a global that resolved to undefined (#1804).
90
90
 
91
91
  // ============================================================================
92
92
  // Template refs
93
93
  // ============================================================================
94
94
 
95
+ /** Stable per-component id, unique across instances. */
96
+ declare function useId(_prefix?: string): string
97
+ /**
98
+ * Signal tracking a parent-driven `:prop="signal()"` attribute on the
99
+ * component's root element. One-way: parent to child.
100
+ */
101
+ declare function useReactiveProp<T = unknown>(
102
+ _name: string,
103
+ _defaultValue?: T,
104
+ _options?: { parse?: (_value: string) => T },
105
+ ): StxSignal<T>
95
106
  declare function useRef<T = HTMLElement>(_name: string): { current: T | null }
96
107
 
97
108
  // ============================================================================
98
109
  // Routing / navigation
99
110
  // ============================================================================
100
111
 
101
- declare function navigate(_url: string, _options?: { replace?: boolean }): void
112
+ interface StxNavigateOptions {
113
+ /** Replace the current history entry instead of pushing a new one. */
114
+ replace?: boolean
115
+ /** Bypass the SPA router and perform a full document load. */
116
+ reload?: boolean
117
+ }
118
+
119
+ /**
120
+ * Navigate via the SPA router.
121
+ *
122
+ * The second argument is deliberately NOT typed to also accept a boolean. The
123
+ * legacy positional `forceReload` boolean still works at runtime — it was the
124
+ * shape that actually shipped — but keeping it out of the type means nothing
125
+ * that type-checks today changes meaning (#1807).
126
+ */
127
+ declare function navigate(_url: string, _options?: StxNavigateOptions): void
102
128
  declare function goBack(): void
103
129
  declare function goForward(): void
104
130
  declare function useRoute(): {
@@ -108,11 +134,39 @@ declare function useRoute(): {
108
134
  hash: string
109
135
  }
110
136
  declare function setRouteParams(_params: Record<string, string>): void
137
+ /** How a search-param mutation is written to session history (#1825). */
138
+ interface StxSearchParamsCommitOptions {
139
+ /** Replace the current history entry instead of pushing a new one. */
140
+ replace?: boolean
141
+ }
142
+
143
+ /**
144
+ * Reactive access to the URL query string.
145
+ *
146
+ * The declaration was wrong in both directions (#1806): it promised `delete`
147
+ * and `has`, which did not exist at runtime, and omitted `setAll` and `data`,
148
+ * which did. `delete`/`has` are now implemented rather than dropped; `get`
149
+ * returns `undefined` for a missing key, not `null`, which is what the runtime
150
+ * and the docs have always said.
151
+ */
111
152
  declare function useSearchParams(): {
112
- get: (key: string) => string | null
113
- set: (key: string, value: string) => void
114
- delete: (key: string) => void
115
- has: (key: string) => boolean
153
+ /** The backing signal — read it to make a binding reactive to the query. */
154
+ data: StxSignal<Record<string, string>>
155
+ get: (_key: string) => string | undefined
156
+ has: (_key: string) => boolean
157
+ /** Set a param. Pushes a history entry unless `{ replace: true }` is passed. */
158
+ set: (_key: string, _value: string, _options?: StxSearchParamsCommitOptions) => void
159
+ /**
160
+ * Remove a param. Pushes a history entry unless `{ replace: true }` is passed.
161
+ *
162
+ * CONSUMING a one-shot param — an OAuth callback result, `?checkout=success`,
163
+ * a flash token — needs `{ replace: true }`. Under the default push, the URL
164
+ * that still carries the param becomes the previous history entry, so Back
165
+ * replays the callback and re-runs whatever consuming it triggered (#1825).
166
+ */
167
+ delete: (_key: string, _options?: StxSearchParamsCommitOptions) => void
168
+ /** Set several params. Pushes a history entry unless `{ replace: true }` is passed. */
169
+ setAll: (_values: Record<string, string>, _options?: StxSearchParamsCommitOptions) => void
116
170
  }
117
171
 
118
172
  // ============================================================================
@@ -160,7 +214,6 @@ declare function useEventListener(
160
214
  declare function useScrollLock(
161
215
  _target?: HTMLElement | null | { current?: HTMLElement | null, value?: HTMLElement | null } | (() => HTMLElement | null | undefined),
162
216
  ): StxSignal<boolean>
163
- declare function useMeta(_meta: Record<string, string>): void
164
217
  declare function useClickOutside(_target: HTMLElement | StxRef<HTMLElement | null> | string | null, _handler: (event: MouseEvent) => void): StxCleanup
165
218
  declare function useFocus(_target: HTMLElement | StxRef<HTMLElement | null> | string | null): { focused: StxSignal<boolean>, focus: () => void, blur: () => void }
166
219
 
@@ -209,6 +262,44 @@ declare function useAsync<T>(_fn: () => Promise<T>): {
209
262
  declare function useLocalStorage<T>(_key: string, _defaultValue: T): StxSignal<T>
210
263
  declare function useSessionStorage<T>(_key: string, _defaultValue: T): StxSignal<T>
211
264
 
265
+ /**
266
+ * Options accepted by the auto-imported `useCookie` global.
267
+ *
268
+ * This describes the CLIENT RUNTIME's cookie composable, which is what a bare
269
+ * `useCookie(...)` in a `<script client>` block resolves to. The module export
270
+ * `@stacksjs/stx/composables` accepts a slightly wider `expires` (Date, epoch ms
271
+ * or parseable string); the runtime calls `.toUTCString()` on it, so only a Date
272
+ * works there. See #1710.
273
+ */
274
+ interface StxCookieOptions {
275
+ /** Max age in seconds. */
276
+ maxAge?: number
277
+ /** Expiration date. */
278
+ expires?: Date
279
+ /** Cookie path. Defaults to '/'. */
280
+ path?: string
281
+ /** Cookie domain. */
282
+ domain?: string
283
+ /** Secure flag. Defaults to true when location.protocol is https:. */
284
+ secure?: boolean
285
+ /** SameSite attribute. Defaults to 'Lax'. */
286
+ sameSite?: 'Strict' | 'Lax' | 'None' | 'strict' | 'lax' | 'none'
287
+ /** Value returned when the cookie is absent. Defaults to ''. */
288
+ defaultValue?: string
289
+ /** Custom encoder. Defaults to encodeURIComponent. */
290
+ encode?: (_value: string) => string
291
+ /** Custom decoder. Defaults to decodeURIComponent. */
292
+ decode?: (_value: string) => string
293
+ }
294
+
295
+ /**
296
+ * Reactive binding to a single cookie (#1808).
297
+ *
298
+ * Returns a signal, like `useLocalStorage` — writes serialise straight to
299
+ * `document.cookie`, and `.set('')` deletes by emitting `max-age=0`.
300
+ */
301
+ declare function useCookie(_name: string, _options?: StxCookieOptions): StxSignal<string>
302
+
212
303
  // ============================================================================
213
304
  // WebSocket
214
305
  // ============================================================================
@@ -237,11 +328,19 @@ interface StxColorModeOptions {
237
328
  /** localStorage key holding the preference. @default 'stx-color-mode' */
238
329
  storageKey?: string
239
330
  /** Mode used when nothing valid is stored. @default 'auto' */
240
- initialMode?: 'light' | 'dark' | 'auto'
241
- /** Class applied to `<html>` when dark. @default 'dark' */
242
- darkClass?: string
243
- /** Attribute applied to `<html>` INSTEAD of the class, e.g. 'data-theme'. */
244
- attribute?: string
331
+ initialMode?: 'light' | 'dark' | 'auto' | 'system'
332
+ /**
333
+ * Class applied to `<html>` when dark. @default 'dark'
334
+ * Applied alongside `attribute`; pass `null` to opt out of the class.
335
+ */
336
+ darkClass?: string | null
337
+ /** Attribute set to the resolved mode on `<html>`, e.g. 'data-theme'. */
338
+ attribute?: string | null
339
+ /**
340
+ * Spelling written to storage for "follow the system".
341
+ * @default whatever is already stored, else 'auto'
342
+ */
343
+ autoValue?: 'auto' | 'system'
245
344
  /** Suppress CSS transitions across a mode switch. @default true */
246
345
  disableTransitions?: boolean
247
346
  }
@@ -257,7 +356,7 @@ declare function useColorMode(_options?: StxColorModeOptions): {
257
356
  /** User preference, which may be 'auto'. */
258
357
  readonly preference: 'light' | 'dark' | 'auto'
259
358
  readonly isDark: boolean
260
- set: (mode: 'light' | 'dark' | 'auto') => void
359
+ set: (mode: 'light' | 'dark' | 'auto' | 'system') => void
261
360
  toggle: () => void
262
361
  subscribe: (fn: (mode: 'light' | 'dark', preference: 'light' | 'dark' | 'auto') => void) => () => void
263
362
  }
@@ -309,6 +408,8 @@ interface StxSeoMetaConfig {
309
408
 
310
409
  declare function useHead(_config: StxHeadConfig): void
311
410
  declare function useSeoMeta(_config: StxSeoMetaConfig): void
411
+ /** No-op on the client; the real one runs at SSR/SSG time. */
412
+ declare function definePageMeta(_meta: Record<string, unknown>): void
312
413
 
313
414
  // ============================================================================
314
415
  // Vue-style reactivity (alternative API)
@@ -340,9 +441,9 @@ declare function defineExpose<T extends Record<string, any>>(_exposed: T): void
340
441
  declare function defineSlots<T extends Record<string, (..._args: any[]) => any> = Record<string, (..._args: any[]) => any>>(): T
341
442
  declare function provide<T>(_key: string | symbol, _value: T): void
342
443
  declare function inject<T>(_key: string | symbol, _defaultValue?: T): T | undefined
343
- declare function getCurrentInstance(): any
344
444
  declare function useSlots(): Record<string, any>
345
- declare function useAttrs(): Record<string, any>
445
+ // getCurrentInstance / useAttrs are NOT declared — composition-api.ts exports
446
+ // them for server use; no client-runtime counterpart exists (#1804).
346
447
  declare function $computed<T>(_getter: () => T): StxRef<T>
347
448
  declare function $watch<T>(
348
449
  _source: (() => T) | StxRef<T> | StxSignal<T>,
@@ -454,16 +555,18 @@ declare function defineStore<S extends Record<string, any>, G extends Record<str
454
555
  },
455
556
  ): () => S & G & A
456
557
  declare function useStore<T = any>(_id: string): T
457
- declare function createStore<T>(_setup: () => T, _options?: StxStoreOptions): () => T
458
- declare function action<T extends (..._args: any[]) => any>(_fn: T): T
459
- declare function createSelector<T, R>(_selector: (state: T) => R): (state: T) => R
558
+ declare function registerStoresClient(_stores: Record<string, unknown>): void
559
+ // createStore / createSelector are exported by state-management.ts for server
560
+ // use and `action` has no implementation anywhere; none reaches window.stx, so
561
+ // none is declared as an ambient global (#1804).
460
562
 
461
563
  // ============================================================================
462
564
  // JSX runtime (Vue/React style)
463
565
  // ============================================================================
464
566
 
465
- declare function h(_tag: string | Function, _props?: Record<string, any> | null, ..._children: any[]): any
466
- declare const Fragment: unique symbol
567
+ // h / Fragment belong to the JSX runtime (jsx-runtime.ts) and are resolved by
568
+ // the transform, not destructured off window.stx — so they are not ambient
569
+ // globals (#1804). Import them explicitly if you call them directly.
467
570
 
468
571
  // ============================================================================
469
572
  // window.stx registry