@stacksjs/stx 0.2.179 → 0.2.180

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.
package/dist/stx.d.ts CHANGED
@@ -586,9 +586,36 @@ declare function $watch<T>(
586
586
  // Toast notifications
587
587
  // ============================================================================
588
588
 
589
+ /*
590
+ * Every option `addToast` reads (#1932).
591
+ *
592
+ * `title`, `id` and `dark` shipped in the runtime for #1913 and none of them
593
+ * reached here, so the feature built to unblock a migration could not be called
594
+ * from a typechecked file — `stx typecheck` rejected the exact snippet that
595
+ * issue was closed with.
596
+ *
597
+ * `test/signals/toast-declaration-drift.test.ts` now reads the option names out
598
+ * of the runtime and fails if this list falls behind again. Adding an option
599
+ * here without the runtime reading it fails too: a documented option that does
600
+ * nothing is the quieter half of the same problem.
601
+ */
589
602
  interface StxToastOptions {
590
603
  /** Auto-dismiss duration in ms. 0 = persistent. Default: 3000 */
591
604
  duration?: number
605
+ /** Heading rendered above the message, in bold. */
606
+ title?: string
607
+ /**
608
+ * Semantic key. A second toast with the same id REPLACES the first in place
609
+ * rather than stacking, and `dismiss(id)` ends it — so a persistent
610
+ * "Publishing…" toast and the call that clears it need not thread the numeric
611
+ * handle between them.
612
+ */
613
+ id?: string | number
614
+ /**
615
+ * Force the dark or light palette. Omitted, it follows the document — the
616
+ * `dark` class, then `data-theme` / `data-color-mode`, then the OS setting.
617
+ */
618
+ dark?: boolean
592
619
  }
593
620
 
594
621
  interface StxToast {
@@ -600,8 +627,15 @@ interface StxToast {
600
627
  info: (message: string, options?: StxToastOptions) => number
601
628
  /** Show a warning toast (yellow) */
602
629
  warning: (message: string, options?: StxToastOptions) => number
603
- /** Dismiss a toast by id, or all toasts if no id is given */
604
- dismiss: (id?: number) => void
630
+ /**
631
+ * Dismiss a toast, or all of them if nothing is given.
632
+ *
633
+ * Takes the semantic `id` the toast was created with, or the numeric handle
634
+ * these methods return. The runtime branches on which it got, so a caller does
635
+ * not have to know which kind it is holding — this used to accept `number`
636
+ * only, which made replace-by-id unreachable from a typechecked call site.
637
+ */
638
+ dismiss: (id?: string | number) => void
605
639
  }
606
640
 
607
641
  declare const toast: StxToast
package/dist/utils.d.ts CHANGED
@@ -23,6 +23,7 @@ export declare function isJavaScriptScript(attrs: string): boolean;
23
23
  * Default: ALL scripts are TypeScript unless explicitly marked as JS
24
24
  */
25
25
  export declare function shouldTranspileTypeScript(attrs: string): boolean;
26
+ export declare function getSharedTranspiler(options: ConstructorParameters<typeof Bun.Transpiler>[0]): Bun.Transpiler;
26
27
  /**
27
28
  * Transpile TypeScript code to JavaScript using Bun (sync version)
28
29
  */
package/dist/utils.js CHANGED
@@ -64,6 +64,23 @@ export function isJavaScriptScript(attrs) {
64
64
  export function shouldTranspileTypeScript(attrs) {
65
65
  return !isJavaScriptScript(attrs);
66
66
  }
67
+ const transpilerPool = new Map;
68
+ export function getSharedTranspiler(options) {
69
+ let key;
70
+ try {
71
+ key = JSON.stringify(options);
72
+ } catch {
73
+ return new Bun.Transpiler(options);
74
+ }
75
+ const pooled = transpilerPool.get(key);
76
+ if (pooled)
77
+ return pooled;
78
+ if (transpilerPool.size >= 16)
79
+ transpilerPool.clear();
80
+ const transpiler = new Bun.Transpiler(options);
81
+ transpilerPool.set(key, transpiler);
82
+ return transpiler;
83
+ }
67
84
  export function transpileTypeScript(code) {
68
85
  try {
69
86
  let processedCode = code.replace(/^\s*import\s+\w+\s+from\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm, "");
@@ -84,7 +101,7 @@ export function transpileTypeScript(code) {
84
101
  placeholders.push(match);
85
102
  return `"__STX_EXPR_${idx}__"`;
86
103
  });
87
- let result = new Bun.Transpiler({
104
+ let result = getSharedTranspiler({
88
105
  loader: "ts",
89
106
  target: "browser",
90
107
  define: getPublicEnvDefine()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.179",
4
+ "version": "0.2.180",
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.179",
121
- "@stacksjs/sanitizer": "0.2.179",
120
+ "@stacksjs/desktop": "0.2.180",
121
+ "@stacksjs/sanitizer": "0.2.180",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.179",
123
+ "bun-plugin-stx": "0.2.180",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.179",
125
+ "stx-router": "0.2.180",
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
@@ -586,9 +586,36 @@ declare function $watch<T>(
586
586
  // Toast notifications
587
587
  // ============================================================================
588
588
 
589
+ /*
590
+ * Every option `addToast` reads (#1932).
591
+ *
592
+ * `title`, `id` and `dark` shipped in the runtime for #1913 and none of them
593
+ * reached here, so the feature built to unblock a migration could not be called
594
+ * from a typechecked file — `stx typecheck` rejected the exact snippet that
595
+ * issue was closed with.
596
+ *
597
+ * `test/signals/toast-declaration-drift.test.ts` now reads the option names out
598
+ * of the runtime and fails if this list falls behind again. Adding an option
599
+ * here without the runtime reading it fails too: a documented option that does
600
+ * nothing is the quieter half of the same problem.
601
+ */
589
602
  interface StxToastOptions {
590
603
  /** Auto-dismiss duration in ms. 0 = persistent. Default: 3000 */
591
604
  duration?: number
605
+ /** Heading rendered above the message, in bold. */
606
+ title?: string
607
+ /**
608
+ * Semantic key. A second toast with the same id REPLACES the first in place
609
+ * rather than stacking, and `dismiss(id)` ends it — so a persistent
610
+ * "Publishing…" toast and the call that clears it need not thread the numeric
611
+ * handle between them.
612
+ */
613
+ id?: string | number
614
+ /**
615
+ * Force the dark or light palette. Omitted, it follows the document — the
616
+ * `dark` class, then `data-theme` / `data-color-mode`, then the OS setting.
617
+ */
618
+ dark?: boolean
592
619
  }
593
620
 
594
621
  interface StxToast {
@@ -600,8 +627,15 @@ interface StxToast {
600
627
  info: (message: string, options?: StxToastOptions) => number
601
628
  /** Show a warning toast (yellow) */
602
629
  warning: (message: string, options?: StxToastOptions) => number
603
- /** Dismiss a toast by id, or all toasts if no id is given */
604
- dismiss: (id?: number) => void
630
+ /**
631
+ * Dismiss a toast, or all of them if nothing is given.
632
+ *
633
+ * Takes the semantic `id` the toast was created with, or the numeric handle
634
+ * these methods return. The runtime branches on which it got, so a caller does
635
+ * not have to know which kind it is holding — this used to accept `number`
636
+ * only, which made replace-by-id unreachable from a typechecked call site.
637
+ */
638
+ dismiss: (id?: string | number) => void
605
639
  }
606
640
 
607
641
  declare const toast: StxToast