sibujs 4.6.0 → 4.8.0

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 (94) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +62 -8
  3. package/dist/browser.d.cts +23 -0
  4. package/dist/browser.d.ts +23 -0
  5. package/dist/browser.js +6 -5
  6. package/dist/build.cjs +2388 -1004
  7. package/dist/build.d.cts +147 -44
  8. package/dist/build.d.ts +147 -44
  9. package/dist/build.js +1410 -564
  10. package/dist/cdn.dev.global.js +14 -12
  11. package/dist/cdn.full.dev.global.js +15 -13
  12. package/dist/cdn.full.global.js +14 -12
  13. package/dist/cdn.global.js +12 -10
  14. package/dist/chunk-3ACAAQIN.js +224 -0
  15. package/dist/{chunk-7NCARGJW.js → chunk-44MTL7ED.js} +6 -6
  16. package/dist/{chunk-BAAG6ZTI.js → chunk-4WMSTZ7J.js} +8 -5
  17. package/dist/{chunk-H3SRKIYX.js → chunk-62BDYGAG.js} +8 -0
  18. package/dist/{chunk-DKGBBKOF.js → chunk-C5PEWEGH.js} +20 -5
  19. package/dist/{chunk-3ISI6ACU.js → chunk-C7AA2CZX.js} +1 -1
  20. package/dist/{chunk-UZQ6ALFS.js → chunk-CZPRSWSS.js} +1 -1
  21. package/dist/{chunk-D33YTSX5.js → chunk-DSID757X.js} +5 -4
  22. package/dist/{chunk-OXUY2A6L.js → chunk-EGUQLBHE.js} +22 -8
  23. package/dist/{chunk-2INLLLMZ.js → chunk-EXXSN3BW.js} +202 -26
  24. package/dist/{chunk-HURREPU2.js → chunk-FC6KCJSA.js} +87 -150
  25. package/dist/{chunk-HYXDKS4N.js → chunk-GSGNX35Q.js} +5 -5
  26. package/dist/{chunk-7GQCWFOE.js → chunk-J3YQ457H.js} +171 -85
  27. package/dist/{chunk-ORMZXBKQ.js → chunk-JUTFX2RM.js} +18 -10
  28. package/dist/{chunk-QE4TTDU3.js → chunk-KJ3UKABJ.js} +12 -11
  29. package/dist/{chunk-XRRZKZYX.js → chunk-LI4W3U6C.js} +1 -1
  30. package/dist/{chunk-47M47FOM.js → chunk-O6TRVMJI.js} +58 -6
  31. package/dist/{chunk-JSXPZCET.js → chunk-Q5J2LVKH.js} +1 -1
  32. package/dist/{chunk-5MT6SJ3P.js → chunk-QGMSESDD.js} +10 -5
  33. package/dist/{chunk-AIF3Z2T7.js → chunk-RGLPEBDE.js} +13 -10
  34. package/dist/{chunk-5Q4R7HCL.js → chunk-TQQUN4WR.js} +11 -2
  35. package/dist/{chunk-PK6FK2G2.js → chunk-UCNP3HVM.js} +183 -30
  36. package/dist/{chunk-XC4MEKGA.js → chunk-V3LHZSU5.js} +8 -2
  37. package/dist/{chunk-VVWPJ543.js → chunk-VWT3VXPL.js} +55 -20
  38. package/dist/{chunk-SXXVZMKZ.js → chunk-ZVLHNEEL.js} +17 -35
  39. package/dist/{contracts-DRIuclVT.d.cts → contracts-CLqzJnOV.d.ts} +28 -17
  40. package/dist/{contracts-DRIuclVT.d.ts → contracts-CTOJXu-x.d.cts} +28 -17
  41. package/dist/{customElement-MmInOW1U.d.ts → customElement-pYDKUzWl.d.cts} +11 -3
  42. package/dist/{customElement-MmInOW1U.d.cts → customElement-pYDKUzWl.d.ts} +11 -3
  43. package/dist/data.cjs +205 -39
  44. package/dist/data.d.cts +119 -3
  45. package/dist/data.d.ts +119 -3
  46. package/dist/data.js +6 -6
  47. package/dist/devtools.cjs +18 -5
  48. package/dist/devtools.js +5 -5
  49. package/dist/ecosystem.cjs +462 -58
  50. package/dist/ecosystem.d.cts +2 -1
  51. package/dist/ecosystem.d.ts +2 -1
  52. package/dist/ecosystem.js +9 -8
  53. package/dist/extras.cjs +852 -296
  54. package/dist/extras.d.cts +5 -4
  55. package/dist/extras.d.ts +5 -4
  56. package/dist/extras.js +24 -23
  57. package/dist/index.cjs +721 -176
  58. package/dist/index.d.cts +220 -169
  59. package/dist/index.d.ts +220 -169
  60. package/dist/index.js +16 -12
  61. package/dist/motion.cjs +12 -4
  62. package/dist/motion.js +3 -3
  63. package/dist/patterns.cjs +37 -21
  64. package/dist/patterns.d.cts +2 -1
  65. package/dist/patterns.d.ts +2 -1
  66. package/dist/patterns.js +6 -6
  67. package/dist/performance.cjs +48 -6
  68. package/dist/performance.d.cts +12 -2
  69. package/dist/performance.d.ts +12 -2
  70. package/dist/performance.js +8 -6
  71. package/dist/plugins.cjs +672 -261
  72. package/dist/plugins.d.cts +131 -13
  73. package/dist/plugins.d.ts +131 -13
  74. package/dist/plugins.js +83 -47
  75. package/dist/{ssr-XOTUASDO.js → ssr-5OWAH3U2.js} +4 -2
  76. package/dist/{ssr-Bli9XRW5.d.cts → ssr-C8hgIAw7.d.cts} +6 -0
  77. package/dist/{ssr-Bli9XRW5.d.ts → ssr-C8hgIAw7.d.ts} +6 -0
  78. package/dist/ssr.cjs +509 -142
  79. package/dist/ssr.d.cts +55 -5
  80. package/dist/ssr.d.ts +55 -5
  81. package/dist/ssr.js +11 -9
  82. package/dist/{tagFactory-DFstCLQV.d.cts → tagFactory-8qL9LCIx.d.cts} +58 -19
  83. package/dist/{tagFactory-DkaNVUNV.d.ts → tagFactory-BL2fymez.d.ts} +58 -19
  84. package/dist/testing.cjs +17 -4
  85. package/dist/testing.js +4 -4
  86. package/dist/types-CJFViL6Q.d.cts +26 -0
  87. package/dist/types-CJFViL6Q.d.ts +26 -0
  88. package/dist/ui.cjs +635 -254
  89. package/dist/ui.d.cts +3 -2
  90. package/dist/ui.d.ts +3 -2
  91. package/dist/ui.js +9 -8
  92. package/dist/widgets.cjs +22 -14
  93. package/dist/widgets.js +7 -7
  94. package/package.json +8 -5
package/dist/build.d.ts CHANGED
@@ -1,37 +1,78 @@
1
+ /** A version 3 source map, as bundlers accept it from a transform hook. */
2
+ interface SourceMapV3 {
3
+ version: 3;
4
+ file?: string;
5
+ sources: string[];
6
+ sourcesContent: string[];
7
+ names: string[];
8
+ mappings: string;
9
+ }
10
+
1
11
  /**
2
12
  * Official Vite plugin for SibuJS.
3
13
  * Provides optimized builds, automatic component detection, and development enhancements.
4
14
  */
15
+
5
16
  interface SibuVitePluginOptions {
6
17
  /** Enable HMR support for SibuJS components */
7
18
  hmr?: boolean;
8
- /** Enable automatic pure annotations for tree-shaking */
19
+ /**
20
+ * Annotate calls to side-effect-free sibujs factories (`tagFactory`,
21
+ * `context`, ...) as pure for tree-shaking. Only direct calls to names
22
+ * imported from sibujs are annotated. Default: true.
23
+ */
9
24
  pureAnnotations?: boolean;
10
25
  /** Component file patterns to watch */
11
26
  include?: string[];
12
27
  /** File patterns to exclude */
13
28
  exclude?: string[];
14
- /** Enable dev mode features (devtools, debug logging) */
29
+ /**
30
+ * Enable dev mode features (devtools, debug logging). When omitted it is
31
+ * derived from Vite's own command/mode (`vite build` is production unless
32
+ * `--mode development`; `vite serve` is development), falling back to
33
+ * `NODE_ENV` only when the plugin is driven outside Vite.
34
+ */
15
35
  devMode?: boolean;
16
- /** Enable static template optimization (default: true in production) */
36
+ /**
37
+ * Replace provably static tag-factory calls (`div({ class: "x" }, "text")`)
38
+ * with `staticTemplate(...)` markup. Default: **false**, in every mode.
39
+ *
40
+ * Off by default because it is not a win: `staticTemplate` parses its markup
41
+ * on every call, which is slower than the tag factory's `createElement` +
42
+ * `setAttribute` for the single-element calls that can be proven static, and
43
+ * the proof has to exclude every prop the factory treats specially (URL and
44
+ * style sanitizing, IDL-only booleans, event and ref props). The analysis is
45
+ * conservative and correct, but a correct pessimization is not a sane
46
+ * default. It previously defaulted to on and rewrote non-sibujs calls
47
+ * (`db.select({...})`) and the template compiler's output into invalid code.
48
+ */
17
49
  staticOptimize?: boolean;
18
- /** Compile html`` tagged templates to direct function calls (default: true in production) */
50
+ /**
51
+ * Compile `html` tagged templates (imported from sibujs) at build time.
52
+ * Default: true in production builds. Most templates become direct DOM
53
+ * construction; the rest are parsed at build time and rendered by the
54
+ * runtime's own executor, so no template is parsed in the browser (the sole
55
+ * exception is a template consisting of one invalid escape sequence).
56
+ */
19
57
  compileTemplates?: boolean;
20
58
  }
59
+ /** The subset of Vite's config environment / resolved config the plugin reads. */
60
+ interface ViteModeInfo {
61
+ command?: string;
62
+ mode?: string;
63
+ }
21
64
  /**
22
65
  * Vite plugin configuration for SibuJS projects.
23
66
  * Returns a Vite-compatible plugin object.
24
- *
25
- * Note: This is a configuration helper. For full Vite plugin functionality,
26
- * users should install @sibu/vite-plugin (when available).
27
67
  */
28
68
  declare function sibuVitePlugin(options?: SibuVitePluginOptions): {
29
69
  name: string;
30
70
  enforce?: "pre" | "post";
31
- config?: () => Record<string, unknown>;
71
+ config?: (userConfig?: unknown, env?: ViteModeInfo) => Record<string, unknown>;
72
+ configResolved?: (config: ViteModeInfo) => void;
32
73
  transform?: (code: string, id: string) => {
33
74
  code: string;
34
- map?: unknown;
75
+ map: SourceMapV3;
35
76
  } | null;
36
77
  handleHotUpdate?: (ctx: {
37
78
  file: string;
@@ -57,9 +98,33 @@ declare function createViteConfig(options?: {
57
98
  * Provides build optimization, pure annotations, and development enhancements.
58
99
  */
59
100
  interface SibuWebpackPluginOptions {
60
- /** Enable automatic pure annotations for tree-shaking */
101
+ /**
102
+ * NOT applied by the plugin — pure annotations under webpack need a loader
103
+ * rule, and webpack loaders must be resolvable module files. Setting this to
104
+ * `true` logs how to add the one-line loader instead of silently doing
105
+ * nothing:
106
+ *
107
+ * ```js
108
+ * // sibu-pure-loader.cjs
109
+ * module.exports = require("sibujs/build").createPureAnnotationsLoader();
110
+ *
111
+ * // webpack.config.js
112
+ * module: {
113
+ * rules: [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: "./sibu-pure-loader.cjs" }],
114
+ * }
115
+ * ```
116
+ *
117
+ * The rule this plugin used to push named a loader that does not exist
118
+ * (`__sibu_inline_loader__`), which failed every build with the default
119
+ * options; the option is kept so existing configs keep compiling.
120
+ */
61
121
  pureAnnotations?: boolean;
62
- /** Enable dev mode features (devtools, debug logging) */
122
+ /**
123
+ * Enable dev mode features (devtools, debug logging). When omitted it is
124
+ * derived from webpack's own resolved `mode`: `development` is dev,
125
+ * `production` and an unset mode (webpack's default is production) are not,
126
+ * and `mode: "none"` falls back to `NODE_ENV`.
127
+ */
63
128
  devMode?: boolean;
64
129
  }
65
130
  /**
@@ -68,7 +133,7 @@ interface SibuWebpackPluginOptions {
68
133
  *
69
134
  * Usage:
70
135
  * ```js
71
- * const { sibuWebpackPlugin } = require('sibu/src/build/webpack');
136
+ * const { sibuWebpackPlugin } = require('sibujs/build');
72
137
  * module.exports = {
73
138
  * plugins: [sibuWebpackPlugin()],
74
139
  * };
@@ -99,7 +164,14 @@ declare function sibuWebpackPlugin(options?: SibuWebpackPluginOptions): {
99
164
  };
100
165
  /**
101
166
  * Create a standalone webpack loader function for pure annotation injection.
102
- * Can be used directly in webpack module rules.
167
+ *
168
+ * Webpack resolves loaders by path, so wrap it in a loader module and point a
169
+ * rule at that file:
170
+ * ```js
171
+ * // sibu-pure-loader.cjs
172
+ * const { createPureAnnotationsLoader } = require("sibujs/build");
173
+ * module.exports = createPureAnnotationsLoader();
174
+ * ```
103
175
  */
104
176
  declare function createPureAnnotationsLoader(): (source: string) => string;
105
177
  /**
@@ -107,7 +179,7 @@ declare function createPureAnnotationsLoader(): (source: string) => string;
107
179
  *
108
180
  * Usage:
109
181
  * ```js
110
- * const { createWebpackConfig } = require('sibu/src/build/webpack');
182
+ * const { createWebpackConfig } = require('sibujs/build');
111
183
  * module.exports = createWebpackConfig({
112
184
  * entry: './src/index.ts',
113
185
  * mode: 'production',
@@ -133,7 +205,7 @@ declare function createWebpackConfig(options?: {
133
205
  *
134
206
  * Usage (in a script tag):
135
207
  * ```html
136
- * <script src="https://unpkg.com/sibu@latest/dist/cdn.global.js"></script>
208
+ * <script src="https://unpkg.com/sibujs@latest/dist/cdn.global.js"></script>
137
209
  * <script>
138
210
  * const { div, span, mount, signal } = window.Sibu;
139
211
  * // Use SibuJS without a bundler
@@ -180,7 +252,7 @@ declare const cdnUrls: {
180
252
  * @example
181
253
  * ```ts
182
254
  * cdnUrls.scriptTag('jsdelivr', '1.0.0')
183
- * // => '<script src="https://cdn.jsdelivr.net/npm/sibu@1.0.0/dist/cdn.global.js"></script>'
255
+ * // => '<script src="https://cdn.jsdelivr.net/npm/sibujs@1.0.0/dist/cdn.global.js"></script>'
184
256
  * ```
185
257
  */
186
258
  scriptTag: (provider?: "unpkg" | "jsdelivr" | "skypack", version?: string) => string;
@@ -190,7 +262,7 @@ declare const cdnUrls: {
190
262
  * Useful for browser-native ES modules without a bundler.
191
263
  *
192
264
  * Import maps allow browsers to resolve bare module specifiers like
193
- * `import { div } from 'sibu'` without a build step.
265
+ * `import { div } from 'sibujs'` without a build step.
194
266
  *
195
267
  * @param baseUrl - Base URL for module resolution (defaults to jsDelivr)
196
268
  * @returns An import map object with serialization helpers
@@ -202,7 +274,7 @@ declare const cdnUrls: {
202
274
  *
203
275
  * // Now you can use bare specifiers in module scripts:
204
276
  * // <script type="module">
205
- * // import { div, mount } from 'sibu';
277
+ * // import { div, mount } from 'sibujs';
206
278
  * // </script>
207
279
  * ```
208
280
  */
@@ -225,7 +297,7 @@ declare function generateImportMap(baseUrl?: string): {
225
297
  *
226
298
  * @example
227
299
  * ```ts
228
- * import { generateTsConfig } from 'sibu/src/build/declarations';
300
+ * import { generateTsConfig } from 'sibujs/build';
229
301
  * import { writeFileSync } from 'fs';
230
302
  *
231
303
  * const config = generateTsConfig({ outDir: './dist' });
@@ -253,7 +325,7 @@ declare function generateTsConfig(options?: {
253
325
  *
254
326
  * @example
255
327
  * ```ts
256
- * import { validateTsConfig } from 'sibu/src/build/declarations';
328
+ * import { validateTsConfig } from 'sibujs/build';
257
329
  * import { readFileSync } from 'fs';
258
330
  *
259
331
  * const tsconfig = JSON.parse(readFileSync('tsconfig.json', 'utf-8'));
@@ -479,7 +551,31 @@ declare function generateTypeStubs(): Record<string, string>;
479
551
 
480
552
  /**
481
553
  * Static analysis utilities for SibuJS build-time optimizations.
482
- * Detects tagFactory calls that can be converted to template cloning.
554
+ * Detects tag-factory calls that can be converted to template cloning.
555
+ *
556
+ * A candidate is replaced by `staticTemplate("<markup>")`, so the analysis
557
+ * must PROVE that parsing the markup yields exactly the element the tag
558
+ * factory would have built. The earlier regex version proved nothing: it
559
+ * matched method calls (`db.select({...})`), text inside strings and
560
+ * comments, silently dropped shorthand and spread props while still calling
561
+ * the call static, treated `"a" + x` as a literal, and rendered `false` as
562
+ * `disabled="false"`. Every one of those is a production-only bug.
563
+ *
564
+ * The rule now is: optimize only what is provably equivalent, and leave
565
+ * everything else untouched. Concretely a call qualifies only when
566
+ * - the callee is a tag factory imported from "sibujs" (by any local alias),
567
+ * called directly — never `obj.tag(...)` — and the name is not declared
568
+ * or used anywhere in the file in a way that could shadow the import (a
569
+ * local `function div() {}`, a `div() {}` method, a parameter, ...);
570
+ * - the tag is in `STATIC_TAGS` (no table/select/pre/textarea parsing
571
+ * quirks, no URL- or script-bearing elements);
572
+ * - the arguments are `({...})`, `({...}, "text")`, `("text")` or
573
+ * `("class", "text")`, where the object literal holds only plain or quoted
574
+ * keys with string / number / `true` / `false` / `null` / `undefined`
575
+ * literal values — no shorthand, spread, computed keys, methods, or
576
+ * expressions of any kind;
577
+ * - every attribute goes through a tag-factory path that is a plain
578
+ * `setAttribute` for that value (see `attributeHtml`).
483
579
  */
484
580
  interface StaticAnalysisResult {
485
581
  /** Whether any static patterns were found */
@@ -499,14 +595,17 @@ interface StaticAnalysisResult {
499
595
  }>;
500
596
  }
501
597
  /**
502
- * Analyze source code for static tagFactory patterns that can be
503
- * converted to template cloning at build time.
598
+ * Analyze source code for static tag-factory calls that can be converted to
599
+ * template cloning at build time.
504
600
  *
505
- * Detects patterns like:
601
+ * Detects calls like:
506
602
  * div({ class: "card", id: "main" }, "Hello")
507
603
  *
508
604
  * And identifies them as candidates for:
509
605
  * staticTemplate('<div class="card" id="main">Hello</div>')
606
+ *
607
+ * Only calls to tag factories imported from "sibujs" in this file are
608
+ * considered, and only when every argument is provably static.
510
609
  */
511
610
  declare function analyzeStaticTemplates(code: string): StaticAnalysisResult;
512
611
 
@@ -516,35 +615,39 @@ declare function analyzeStaticTemplates(code: string): StaticAnalysisResult;
516
615
  * Transforms:
517
616
  * html`<div class=${cls}><span>${() => count()}</span></div>`
518
617
  *
519
- * Into direct tagFactory calls:
520
- * div({ class: __v[0], nodes: [span({ nodes: __v[1] })] })
618
+ * Into a module-level construction function plus a call that passes the
619
+ * template's expressions in their original order:
521
620
  *
522
- * This eliminates the runtime template parser entirely, removing the ~1.5x
523
- * overhead of the html`` authoring style vs direct function calls.
621
+ * __sibujs$t0((cls), (() => count()))
622
+ * ...
623
+ * function __sibujs$t0(v0, v1) { ...direct DOM construction... }
524
624
  *
525
- * The runtime parser remains available as a fallback for users who don't
526
- * use a build step.
625
+ * A compiled template builds exactly the DOM the runtime `html` parser would;
626
+ * any template the compiler cannot reproduce exactly is left to the runtime.
627
+ * The contract, the parser port and the list of templates left to the runtime
628
+ * are documented in templateCompiler.ts.
527
629
  */
528
630
  interface CompileResult {
529
- /** The transformed source code, or null if no templates found */
631
+ /** The transformed source code, or null if nothing was compiled */
530
632
  code: string | null;
531
- /** Set of HTML tag names used (need to be imported from sibu) */
633
+ /** Tag names of the elements the compiled templates create */
532
634
  usedTags: Set<string>;
533
- /** Whether any SVG tags were used (needs tagFactory + SVG_NS import) */
635
+ /** Whether any compiled template creates SVG-namespace elements */
534
636
  usesSvg: boolean;
535
637
  /** Number of templates compiled */
536
638
  compiledCount: number;
639
+ /** Number of sibujs `html` templates deliberately left to the runtime parser */
640
+ skippedCount: number;
537
641
  }
538
642
  /**
539
- * Compile all html`` tagged templates in source code to direct tagFactory calls.
540
- *
541
- * Transforms:
542
- * html`<div class=${cls}><span>${text}</span></div>`
543
- *
544
- * Into:
545
- * ((v) => div({ class: v[0], nodes: [span({ nodes: v[1] })] }))([cls, text])
643
+ * Compile the sibujs `html` tagged templates in a module to direct DOM
644
+ * construction. The returned code is self-contained: it carries the aliased
645
+ * imports and helpers the compiled templates need, appended at the end of the
646
+ * module (imports are hoisted, and appending keeps every original line where
647
+ * it was — each compiled template also keeps the line breaks it spanned).
546
648
  *
547
- * This eliminates the runtime template parser entirely.
649
+ * Returns `code: null` when nothing was compiled — including when the file
650
+ * cannot be scanned with confidence.
548
651
  */
549
652
  declare function compileHtmlTemplates(code: string): CompileResult;
550
653
 
@@ -595,8 +698,8 @@ declare function buildRouteEntries(files: string[], chunkPrefix: string): RouteE
595
698
  * @example
596
699
  * ```ts
597
700
  * // vite.config.ts
598
- * import { sibuVitePlugin } from "sibu/build";
599
- * import { sibuRouteSplitting } from "sibu/build";
701
+ * import { sibuVitePlugin } from "sibujs/build";
702
+ * import { sibuRouteSplitting } from "sibujs/build";
600
703
  *
601
704
  * export default {
602
705
  * plugins: [sibuVitePlugin(), sibuRouteSplitting()],
@@ -604,7 +707,7 @@ declare function buildRouteEntries(files: string[], chunkPrefix: string): RouteE
604
707
  *
605
708
  * // In your app:
606
709
  * import { routes } from "virtual:sibu-routes";
607
- * import { setRoutes } from "sibu/plugins";
710
+ * import { setRoutes } from "sibujs/plugins";
608
711
  * setRoutes(routes);
609
712
  * ```
610
713
  */