sibujs 4.6.0 → 4.7.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 (79) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +18 -5
  3. package/dist/browser.js +4 -4
  4. package/dist/build.cjs +1956 -1007
  5. package/dist/build.d.cts +133 -44
  6. package/dist/build.d.ts +133 -44
  7. package/dist/build.js +1368 -569
  8. package/dist/cdn.dev.global.js +12 -12
  9. package/dist/cdn.full.dev.global.js +11 -11
  10. package/dist/cdn.full.global.js +10 -10
  11. package/dist/cdn.global.js +12 -12
  12. package/dist/{chunk-SXXVZMKZ.js → chunk-2BPG2XDA.js} +5 -5
  13. package/dist/{chunk-BAAG6ZTI.js → chunk-3QWBSL5R.js} +4 -4
  14. package/dist/{chunk-5MT6SJ3P.js → chunk-4AWA2PVD.js} +2 -2
  15. package/dist/{chunk-JSXPZCET.js → chunk-7LUJQAOJ.js} +1 -1
  16. package/dist/{chunk-3ISI6ACU.js → chunk-BC2SECJD.js} +1 -1
  17. package/dist/{chunk-DKGBBKOF.js → chunk-BSY63EM6.js} +2 -2
  18. package/dist/{chunk-7NCARGJW.js → chunk-DKXRACVN.js} +3 -3
  19. package/dist/{chunk-47M47FOM.js → chunk-FNJXNGYZ.js} +1 -1
  20. package/dist/{chunk-D33YTSX5.js → chunk-FQRUXCEE.js} +5 -4
  21. package/dist/{chunk-5Q4R7HCL.js → chunk-JWKYU5GV.js} +11 -2
  22. package/dist/{chunk-QE4TTDU3.js → chunk-RUSSKG6G.js} +12 -11
  23. package/dist/{chunk-UZQ6ALFS.js → chunk-SLM3IA34.js} +1 -1
  24. package/dist/{chunk-XRRZKZYX.js → chunk-UNWRJRKC.js} +1 -1
  25. package/dist/{chunk-VVWPJ543.js → chunk-UOL2ECCS.js} +40 -11
  26. package/dist/{chunk-ORMZXBKQ.js → chunk-VZSG24LS.js} +3 -3
  27. package/dist/{chunk-XC4MEKGA.js → chunk-WEQ3DMVL.js} +8 -2
  28. package/dist/{chunk-PK6FK2G2.js → chunk-WOLJZUFQ.js} +176 -27
  29. package/dist/{chunk-7GQCWFOE.js → chunk-XYV3EDB7.js} +143 -74
  30. package/dist/{chunk-AIF3Z2T7.js → chunk-XZR4PXRE.js} +3 -3
  31. package/dist/{chunk-HYXDKS4N.js → chunk-Z3OHK6QT.js} +4 -4
  32. package/dist/{chunk-OXUY2A6L.js → chunk-ZVL7TY4K.js} +2 -2
  33. package/dist/{contracts-DRIuclVT.d.ts → contracts-CLqzJnOV.d.ts} +28 -17
  34. package/dist/{contracts-DRIuclVT.d.cts → contracts-CTOJXu-x.d.cts} +28 -17
  35. package/dist/data.cjs +198 -39
  36. package/dist/data.d.cts +119 -3
  37. package/dist/data.d.ts +119 -3
  38. package/dist/data.js +5 -5
  39. package/dist/devtools.cjs +18 -5
  40. package/dist/devtools.js +4 -4
  41. package/dist/ecosystem.cjs +64 -23
  42. package/dist/ecosystem.d.cts +2 -1
  43. package/dist/ecosystem.d.ts +2 -1
  44. package/dist/ecosystem.js +7 -7
  45. package/dist/extras.cjs +236 -49
  46. package/dist/extras.d.cts +3 -2
  47. package/dist/extras.d.ts +3 -2
  48. package/dist/extras.js +20 -20
  49. package/dist/index.cjs +259 -108
  50. package/dist/index.d.cts +193 -168
  51. package/dist/index.d.ts +193 -168
  52. package/dist/index.js +10 -10
  53. package/dist/motion.cjs +12 -4
  54. package/dist/motion.js +3 -3
  55. package/dist/patterns.cjs +28 -15
  56. package/dist/patterns.d.cts +2 -1
  57. package/dist/patterns.d.ts +2 -1
  58. package/dist/patterns.js +5 -5
  59. package/dist/performance.cjs +18 -5
  60. package/dist/performance.js +4 -4
  61. package/dist/plugins.cjs +118 -34
  62. package/dist/plugins.d.cts +124 -11
  63. package/dist/plugins.d.ts +124 -11
  64. package/dist/plugins.js +68 -26
  65. package/dist/ssr.cjs +54 -13
  66. package/dist/ssr.js +7 -7
  67. package/dist/{tagFactory-DFstCLQV.d.cts → tagFactory-8qL9LCIx.d.cts} +58 -19
  68. package/dist/{tagFactory-DkaNVUNV.d.ts → tagFactory-BL2fymez.d.ts} +58 -19
  69. package/dist/testing.cjs +15 -2
  70. package/dist/testing.js +2 -2
  71. package/dist/types-CJFViL6Q.d.cts +26 -0
  72. package/dist/types-CJFViL6Q.d.ts +26 -0
  73. package/dist/ui.cjs +28 -15
  74. package/dist/ui.d.cts +2 -1
  75. package/dist/ui.d.ts +2 -1
  76. package/dist/ui.js +7 -7
  77. package/dist/widgets.cjs +22 -14
  78. package/dist/widgets.js +6 -6
  79. package/package.json +4 -2
package/dist/build.d.cts CHANGED
@@ -1,37 +1,76 @@
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) to direct DOM
52
+ * construction. Default: true in production builds. A template the compiler
53
+ * cannot reproduce exactly is left to the runtime parser.
54
+ */
19
55
  compileTemplates?: boolean;
20
56
  }
57
+ /** The subset of Vite's config environment / resolved config the plugin reads. */
58
+ interface ViteModeInfo {
59
+ command?: string;
60
+ mode?: string;
61
+ }
21
62
  /**
22
63
  * Vite plugin configuration for SibuJS projects.
23
64
  * 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
65
  */
28
66
  declare function sibuVitePlugin(options?: SibuVitePluginOptions): {
29
67
  name: string;
30
68
  enforce?: "pre" | "post";
31
- config?: () => Record<string, unknown>;
69
+ config?: (userConfig?: unknown, env?: ViteModeInfo) => Record<string, unknown>;
70
+ configResolved?: (config: ViteModeInfo) => void;
32
71
  transform?: (code: string, id: string) => {
33
72
  code: string;
34
- map?: unknown;
73
+ map: SourceMapV3;
35
74
  } | null;
36
75
  handleHotUpdate?: (ctx: {
37
76
  file: string;
@@ -57,9 +96,21 @@ declare function createViteConfig(options?: {
57
96
  * Provides build optimization, pure annotations, and development enhancements.
58
97
  */
59
98
  interface SibuWebpackPluginOptions {
60
- /** Enable automatic pure annotations for tree-shaking */
99
+ /**
100
+ * Accepted for API compatibility; the plugin itself no longer injects a
101
+ * loader. Webpack loaders must be resolvable modules, and the rule this
102
+ * plugin used to push named a loader that does not exist
103
+ * (`__sibu_inline_loader__`), which failed every build with the default
104
+ * options. To get pure annotations, reference a loader file that returns
105
+ * `createPureAnnotationsLoader()(source)`.
106
+ */
61
107
  pureAnnotations?: boolean;
62
- /** Enable dev mode features (devtools, debug logging) */
108
+ /**
109
+ * Enable dev mode features (devtools, debug logging). When omitted it is
110
+ * derived from webpack's own resolved `mode`: `development` is dev,
111
+ * `production` and an unset mode (webpack's default is production) are not,
112
+ * and `mode: "none"` falls back to `NODE_ENV`.
113
+ */
63
114
  devMode?: boolean;
64
115
  }
65
116
  /**
@@ -68,7 +119,7 @@ interface SibuWebpackPluginOptions {
68
119
  *
69
120
  * Usage:
70
121
  * ```js
71
- * const { sibuWebpackPlugin } = require('sibu/src/build/webpack');
122
+ * const { sibuWebpackPlugin } = require('sibujs/build');
72
123
  * module.exports = {
73
124
  * plugins: [sibuWebpackPlugin()],
74
125
  * };
@@ -99,7 +150,14 @@ declare function sibuWebpackPlugin(options?: SibuWebpackPluginOptions): {
99
150
  };
100
151
  /**
101
152
  * Create a standalone webpack loader function for pure annotation injection.
102
- * Can be used directly in webpack module rules.
153
+ *
154
+ * Webpack resolves loaders by path, so wrap it in a loader module and point a
155
+ * rule at that file:
156
+ * ```js
157
+ * // sibu-pure-loader.cjs
158
+ * const { createPureAnnotationsLoader } = require("sibujs/build");
159
+ * module.exports = createPureAnnotationsLoader();
160
+ * ```
103
161
  */
104
162
  declare function createPureAnnotationsLoader(): (source: string) => string;
105
163
  /**
@@ -107,7 +165,7 @@ declare function createPureAnnotationsLoader(): (source: string) => string;
107
165
  *
108
166
  * Usage:
109
167
  * ```js
110
- * const { createWebpackConfig } = require('sibu/src/build/webpack');
168
+ * const { createWebpackConfig } = require('sibujs/build');
111
169
  * module.exports = createWebpackConfig({
112
170
  * entry: './src/index.ts',
113
171
  * mode: 'production',
@@ -133,7 +191,7 @@ declare function createWebpackConfig(options?: {
133
191
  *
134
192
  * Usage (in a script tag):
135
193
  * ```html
136
- * <script src="https://unpkg.com/sibu@latest/dist/cdn.global.js"></script>
194
+ * <script src="https://unpkg.com/sibujs@latest/dist/cdn.global.js"></script>
137
195
  * <script>
138
196
  * const { div, span, mount, signal } = window.Sibu;
139
197
  * // Use SibuJS without a bundler
@@ -180,7 +238,7 @@ declare const cdnUrls: {
180
238
  * @example
181
239
  * ```ts
182
240
  * cdnUrls.scriptTag('jsdelivr', '1.0.0')
183
- * // => '<script src="https://cdn.jsdelivr.net/npm/sibu@1.0.0/dist/cdn.global.js"></script>'
241
+ * // => '<script src="https://cdn.jsdelivr.net/npm/sibujs@1.0.0/dist/cdn.global.js"></script>'
184
242
  * ```
185
243
  */
186
244
  scriptTag: (provider?: "unpkg" | "jsdelivr" | "skypack", version?: string) => string;
@@ -190,7 +248,7 @@ declare const cdnUrls: {
190
248
  * Useful for browser-native ES modules without a bundler.
191
249
  *
192
250
  * Import maps allow browsers to resolve bare module specifiers like
193
- * `import { div } from 'sibu'` without a build step.
251
+ * `import { div } from 'sibujs'` without a build step.
194
252
  *
195
253
  * @param baseUrl - Base URL for module resolution (defaults to jsDelivr)
196
254
  * @returns An import map object with serialization helpers
@@ -202,7 +260,7 @@ declare const cdnUrls: {
202
260
  *
203
261
  * // Now you can use bare specifiers in module scripts:
204
262
  * // <script type="module">
205
- * // import { div, mount } from 'sibu';
263
+ * // import { div, mount } from 'sibujs';
206
264
  * // </script>
207
265
  * ```
208
266
  */
@@ -225,7 +283,7 @@ declare function generateImportMap(baseUrl?: string): {
225
283
  *
226
284
  * @example
227
285
  * ```ts
228
- * import { generateTsConfig } from 'sibu/src/build/declarations';
286
+ * import { generateTsConfig } from 'sibujs/build';
229
287
  * import { writeFileSync } from 'fs';
230
288
  *
231
289
  * const config = generateTsConfig({ outDir: './dist' });
@@ -253,7 +311,7 @@ declare function generateTsConfig(options?: {
253
311
  *
254
312
  * @example
255
313
  * ```ts
256
- * import { validateTsConfig } from 'sibu/src/build/declarations';
314
+ * import { validateTsConfig } from 'sibujs/build';
257
315
  * import { readFileSync } from 'fs';
258
316
  *
259
317
  * const tsconfig = JSON.parse(readFileSync('tsconfig.json', 'utf-8'));
@@ -479,7 +537,31 @@ declare function generateTypeStubs(): Record<string, string>;
479
537
 
480
538
  /**
481
539
  * Static analysis utilities for SibuJS build-time optimizations.
482
- * Detects tagFactory calls that can be converted to template cloning.
540
+ * Detects tag-factory calls that can be converted to template cloning.
541
+ *
542
+ * A candidate is replaced by `staticTemplate("<markup>")`, so the analysis
543
+ * must PROVE that parsing the markup yields exactly the element the tag
544
+ * factory would have built. The earlier regex version proved nothing: it
545
+ * matched method calls (`db.select({...})`), text inside strings and
546
+ * comments, silently dropped shorthand and spread props while still calling
547
+ * the call static, treated `"a" + x` as a literal, and rendered `false` as
548
+ * `disabled="false"`. Every one of those is a production-only bug.
549
+ *
550
+ * The rule now is: optimize only what is provably equivalent, and leave
551
+ * everything else untouched. Concretely a call qualifies only when
552
+ * - the callee is a tag factory imported from "sibujs" (by any local alias),
553
+ * called directly — never `obj.tag(...)` — and the name is not declared
554
+ * or used anywhere in the file in a way that could shadow the import (a
555
+ * local `function div() {}`, a `div() {}` method, a parameter, ...);
556
+ * - the tag is in `STATIC_TAGS` (no table/select/pre/textarea parsing
557
+ * quirks, no URL- or script-bearing elements);
558
+ * - the arguments are `({...})`, `({...}, "text")`, `("text")` or
559
+ * `("class", "text")`, where the object literal holds only plain or quoted
560
+ * keys with string / number / `true` / `false` / `null` / `undefined`
561
+ * literal values — no shorthand, spread, computed keys, methods, or
562
+ * expressions of any kind;
563
+ * - every attribute goes through a tag-factory path that is a plain
564
+ * `setAttribute` for that value (see `attributeHtml`).
483
565
  */
484
566
  interface StaticAnalysisResult {
485
567
  /** Whether any static patterns were found */
@@ -499,14 +581,17 @@ interface StaticAnalysisResult {
499
581
  }>;
500
582
  }
501
583
  /**
502
- * Analyze source code for static tagFactory patterns that can be
503
- * converted to template cloning at build time.
584
+ * Analyze source code for static tag-factory calls that can be converted to
585
+ * template cloning at build time.
504
586
  *
505
- * Detects patterns like:
587
+ * Detects calls like:
506
588
  * div({ class: "card", id: "main" }, "Hello")
507
589
  *
508
590
  * And identifies them as candidates for:
509
591
  * staticTemplate('<div class="card" id="main">Hello</div>')
592
+ *
593
+ * Only calls to tag factories imported from "sibujs" in this file are
594
+ * considered, and only when every argument is provably static.
510
595
  */
511
596
  declare function analyzeStaticTemplates(code: string): StaticAnalysisResult;
512
597
 
@@ -516,35 +601,39 @@ declare function analyzeStaticTemplates(code: string): StaticAnalysisResult;
516
601
  * Transforms:
517
602
  * html`<div class=${cls}><span>${() => count()}</span></div>`
518
603
  *
519
- * Into direct tagFactory calls:
520
- * div({ class: __v[0], nodes: [span({ nodes: __v[1] })] })
604
+ * Into a module-level construction function plus a call that passes the
605
+ * template's expressions in their original order:
521
606
  *
522
- * This eliminates the runtime template parser entirely, removing the ~1.5x
523
- * overhead of the html`` authoring style vs direct function calls.
607
+ * __sibujs$t0((cls), (() => count()))
608
+ * ...
609
+ * function __sibujs$t0(v0, v1) { ...direct DOM construction... }
524
610
  *
525
- * The runtime parser remains available as a fallback for users who don't
526
- * use a build step.
611
+ * A compiled template builds exactly the DOM the runtime `html` parser would;
612
+ * any template the compiler cannot reproduce exactly is left to the runtime.
613
+ * The contract, the parser port and the list of templates left to the runtime
614
+ * are documented in templateCompiler.ts.
527
615
  */
528
616
  interface CompileResult {
529
- /** The transformed source code, or null if no templates found */
617
+ /** The transformed source code, or null if nothing was compiled */
530
618
  code: string | null;
531
- /** Set of HTML tag names used (need to be imported from sibu) */
619
+ /** Tag names of the elements the compiled templates create */
532
620
  usedTags: Set<string>;
533
- /** Whether any SVG tags were used (needs tagFactory + SVG_NS import) */
621
+ /** Whether any compiled template creates SVG-namespace elements */
534
622
  usesSvg: boolean;
535
623
  /** Number of templates compiled */
536
624
  compiledCount: number;
625
+ /** Number of sibujs `html` templates deliberately left to the runtime parser */
626
+ skippedCount: number;
537
627
  }
538
628
  /**
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])
629
+ * Compile the sibujs `html` tagged templates in a module to direct DOM
630
+ * construction. The returned code is self-contained: it carries the aliased
631
+ * imports and helpers the compiled templates need, appended at the end of the
632
+ * module (imports are hoisted, and appending keeps every original line where
633
+ * it was — each compiled template also keeps the line breaks it spanned).
546
634
  *
547
- * This eliminates the runtime template parser entirely.
635
+ * Returns `code: null` when nothing was compiled — including when the file
636
+ * cannot be scanned with confidence.
548
637
  */
549
638
  declare function compileHtmlTemplates(code: string): CompileResult;
550
639
 
@@ -595,8 +684,8 @@ declare function buildRouteEntries(files: string[], chunkPrefix: string): RouteE
595
684
  * @example
596
685
  * ```ts
597
686
  * // vite.config.ts
598
- * import { sibuVitePlugin } from "sibu/build";
599
- * import { sibuRouteSplitting } from "sibu/build";
687
+ * import { sibuVitePlugin } from "sibujs/build";
688
+ * import { sibuRouteSplitting } from "sibujs/build";
600
689
  *
601
690
  * export default {
602
691
  * plugins: [sibuVitePlugin(), sibuRouteSplitting()],
@@ -604,7 +693,7 @@ declare function buildRouteEntries(files: string[], chunkPrefix: string): RouteE
604
693
  *
605
694
  * // In your app:
606
695
  * import { routes } from "virtual:sibu-routes";
607
- * import { setRoutes } from "sibu/plugins";
696
+ * import { setRoutes } from "sibujs/plugins";
608
697
  * setRoutes(routes);
609
698
  * ```
610
699
  */
package/dist/build.d.ts CHANGED
@@ -1,37 +1,76 @@
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) to direct DOM
52
+ * construction. Default: true in production builds. A template the compiler
53
+ * cannot reproduce exactly is left to the runtime parser.
54
+ */
19
55
  compileTemplates?: boolean;
20
56
  }
57
+ /** The subset of Vite's config environment / resolved config the plugin reads. */
58
+ interface ViteModeInfo {
59
+ command?: string;
60
+ mode?: string;
61
+ }
21
62
  /**
22
63
  * Vite plugin configuration for SibuJS projects.
23
64
  * 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
65
  */
28
66
  declare function sibuVitePlugin(options?: SibuVitePluginOptions): {
29
67
  name: string;
30
68
  enforce?: "pre" | "post";
31
- config?: () => Record<string, unknown>;
69
+ config?: (userConfig?: unknown, env?: ViteModeInfo) => Record<string, unknown>;
70
+ configResolved?: (config: ViteModeInfo) => void;
32
71
  transform?: (code: string, id: string) => {
33
72
  code: string;
34
- map?: unknown;
73
+ map: SourceMapV3;
35
74
  } | null;
36
75
  handleHotUpdate?: (ctx: {
37
76
  file: string;
@@ -57,9 +96,21 @@ declare function createViteConfig(options?: {
57
96
  * Provides build optimization, pure annotations, and development enhancements.
58
97
  */
59
98
  interface SibuWebpackPluginOptions {
60
- /** Enable automatic pure annotations for tree-shaking */
99
+ /**
100
+ * Accepted for API compatibility; the plugin itself no longer injects a
101
+ * loader. Webpack loaders must be resolvable modules, and the rule this
102
+ * plugin used to push named a loader that does not exist
103
+ * (`__sibu_inline_loader__`), which failed every build with the default
104
+ * options. To get pure annotations, reference a loader file that returns
105
+ * `createPureAnnotationsLoader()(source)`.
106
+ */
61
107
  pureAnnotations?: boolean;
62
- /** Enable dev mode features (devtools, debug logging) */
108
+ /**
109
+ * Enable dev mode features (devtools, debug logging). When omitted it is
110
+ * derived from webpack's own resolved `mode`: `development` is dev,
111
+ * `production` and an unset mode (webpack's default is production) are not,
112
+ * and `mode: "none"` falls back to `NODE_ENV`.
113
+ */
63
114
  devMode?: boolean;
64
115
  }
65
116
  /**
@@ -68,7 +119,7 @@ interface SibuWebpackPluginOptions {
68
119
  *
69
120
  * Usage:
70
121
  * ```js
71
- * const { sibuWebpackPlugin } = require('sibu/src/build/webpack');
122
+ * const { sibuWebpackPlugin } = require('sibujs/build');
72
123
  * module.exports = {
73
124
  * plugins: [sibuWebpackPlugin()],
74
125
  * };
@@ -99,7 +150,14 @@ declare function sibuWebpackPlugin(options?: SibuWebpackPluginOptions): {
99
150
  };
100
151
  /**
101
152
  * Create a standalone webpack loader function for pure annotation injection.
102
- * Can be used directly in webpack module rules.
153
+ *
154
+ * Webpack resolves loaders by path, so wrap it in a loader module and point a
155
+ * rule at that file:
156
+ * ```js
157
+ * // sibu-pure-loader.cjs
158
+ * const { createPureAnnotationsLoader } = require("sibujs/build");
159
+ * module.exports = createPureAnnotationsLoader();
160
+ * ```
103
161
  */
104
162
  declare function createPureAnnotationsLoader(): (source: string) => string;
105
163
  /**
@@ -107,7 +165,7 @@ declare function createPureAnnotationsLoader(): (source: string) => string;
107
165
  *
108
166
  * Usage:
109
167
  * ```js
110
- * const { createWebpackConfig } = require('sibu/src/build/webpack');
168
+ * const { createWebpackConfig } = require('sibujs/build');
111
169
  * module.exports = createWebpackConfig({
112
170
  * entry: './src/index.ts',
113
171
  * mode: 'production',
@@ -133,7 +191,7 @@ declare function createWebpackConfig(options?: {
133
191
  *
134
192
  * Usage (in a script tag):
135
193
  * ```html
136
- * <script src="https://unpkg.com/sibu@latest/dist/cdn.global.js"></script>
194
+ * <script src="https://unpkg.com/sibujs@latest/dist/cdn.global.js"></script>
137
195
  * <script>
138
196
  * const { div, span, mount, signal } = window.Sibu;
139
197
  * // Use SibuJS without a bundler
@@ -180,7 +238,7 @@ declare const cdnUrls: {
180
238
  * @example
181
239
  * ```ts
182
240
  * cdnUrls.scriptTag('jsdelivr', '1.0.0')
183
- * // => '<script src="https://cdn.jsdelivr.net/npm/sibu@1.0.0/dist/cdn.global.js"></script>'
241
+ * // => '<script src="https://cdn.jsdelivr.net/npm/sibujs@1.0.0/dist/cdn.global.js"></script>'
184
242
  * ```
185
243
  */
186
244
  scriptTag: (provider?: "unpkg" | "jsdelivr" | "skypack", version?: string) => string;
@@ -190,7 +248,7 @@ declare const cdnUrls: {
190
248
  * Useful for browser-native ES modules without a bundler.
191
249
  *
192
250
  * Import maps allow browsers to resolve bare module specifiers like
193
- * `import { div } from 'sibu'` without a build step.
251
+ * `import { div } from 'sibujs'` without a build step.
194
252
  *
195
253
  * @param baseUrl - Base URL for module resolution (defaults to jsDelivr)
196
254
  * @returns An import map object with serialization helpers
@@ -202,7 +260,7 @@ declare const cdnUrls: {
202
260
  *
203
261
  * // Now you can use bare specifiers in module scripts:
204
262
  * // <script type="module">
205
- * // import { div, mount } from 'sibu';
263
+ * // import { div, mount } from 'sibujs';
206
264
  * // </script>
207
265
  * ```
208
266
  */
@@ -225,7 +283,7 @@ declare function generateImportMap(baseUrl?: string): {
225
283
  *
226
284
  * @example
227
285
  * ```ts
228
- * import { generateTsConfig } from 'sibu/src/build/declarations';
286
+ * import { generateTsConfig } from 'sibujs/build';
229
287
  * import { writeFileSync } from 'fs';
230
288
  *
231
289
  * const config = generateTsConfig({ outDir: './dist' });
@@ -253,7 +311,7 @@ declare function generateTsConfig(options?: {
253
311
  *
254
312
  * @example
255
313
  * ```ts
256
- * import { validateTsConfig } from 'sibu/src/build/declarations';
314
+ * import { validateTsConfig } from 'sibujs/build';
257
315
  * import { readFileSync } from 'fs';
258
316
  *
259
317
  * const tsconfig = JSON.parse(readFileSync('tsconfig.json', 'utf-8'));
@@ -479,7 +537,31 @@ declare function generateTypeStubs(): Record<string, string>;
479
537
 
480
538
  /**
481
539
  * Static analysis utilities for SibuJS build-time optimizations.
482
- * Detects tagFactory calls that can be converted to template cloning.
540
+ * Detects tag-factory calls that can be converted to template cloning.
541
+ *
542
+ * A candidate is replaced by `staticTemplate("<markup>")`, so the analysis
543
+ * must PROVE that parsing the markup yields exactly the element the tag
544
+ * factory would have built. The earlier regex version proved nothing: it
545
+ * matched method calls (`db.select({...})`), text inside strings and
546
+ * comments, silently dropped shorthand and spread props while still calling
547
+ * the call static, treated `"a" + x` as a literal, and rendered `false` as
548
+ * `disabled="false"`. Every one of those is a production-only bug.
549
+ *
550
+ * The rule now is: optimize only what is provably equivalent, and leave
551
+ * everything else untouched. Concretely a call qualifies only when
552
+ * - the callee is a tag factory imported from "sibujs" (by any local alias),
553
+ * called directly — never `obj.tag(...)` — and the name is not declared
554
+ * or used anywhere in the file in a way that could shadow the import (a
555
+ * local `function div() {}`, a `div() {}` method, a parameter, ...);
556
+ * - the tag is in `STATIC_TAGS` (no table/select/pre/textarea parsing
557
+ * quirks, no URL- or script-bearing elements);
558
+ * - the arguments are `({...})`, `({...}, "text")`, `("text")` or
559
+ * `("class", "text")`, where the object literal holds only plain or quoted
560
+ * keys with string / number / `true` / `false` / `null` / `undefined`
561
+ * literal values — no shorthand, spread, computed keys, methods, or
562
+ * expressions of any kind;
563
+ * - every attribute goes through a tag-factory path that is a plain
564
+ * `setAttribute` for that value (see `attributeHtml`).
483
565
  */
484
566
  interface StaticAnalysisResult {
485
567
  /** Whether any static patterns were found */
@@ -499,14 +581,17 @@ interface StaticAnalysisResult {
499
581
  }>;
500
582
  }
501
583
  /**
502
- * Analyze source code for static tagFactory patterns that can be
503
- * converted to template cloning at build time.
584
+ * Analyze source code for static tag-factory calls that can be converted to
585
+ * template cloning at build time.
504
586
  *
505
- * Detects patterns like:
587
+ * Detects calls like:
506
588
  * div({ class: "card", id: "main" }, "Hello")
507
589
  *
508
590
  * And identifies them as candidates for:
509
591
  * staticTemplate('<div class="card" id="main">Hello</div>')
592
+ *
593
+ * Only calls to tag factories imported from "sibujs" in this file are
594
+ * considered, and only when every argument is provably static.
510
595
  */
511
596
  declare function analyzeStaticTemplates(code: string): StaticAnalysisResult;
512
597
 
@@ -516,35 +601,39 @@ declare function analyzeStaticTemplates(code: string): StaticAnalysisResult;
516
601
  * Transforms:
517
602
  * html`<div class=${cls}><span>${() => count()}</span></div>`
518
603
  *
519
- * Into direct tagFactory calls:
520
- * div({ class: __v[0], nodes: [span({ nodes: __v[1] })] })
604
+ * Into a module-level construction function plus a call that passes the
605
+ * template's expressions in their original order:
521
606
  *
522
- * This eliminates the runtime template parser entirely, removing the ~1.5x
523
- * overhead of the html`` authoring style vs direct function calls.
607
+ * __sibujs$t0((cls), (() => count()))
608
+ * ...
609
+ * function __sibujs$t0(v0, v1) { ...direct DOM construction... }
524
610
  *
525
- * The runtime parser remains available as a fallback for users who don't
526
- * use a build step.
611
+ * A compiled template builds exactly the DOM the runtime `html` parser would;
612
+ * any template the compiler cannot reproduce exactly is left to the runtime.
613
+ * The contract, the parser port and the list of templates left to the runtime
614
+ * are documented in templateCompiler.ts.
527
615
  */
528
616
  interface CompileResult {
529
- /** The transformed source code, or null if no templates found */
617
+ /** The transformed source code, or null if nothing was compiled */
530
618
  code: string | null;
531
- /** Set of HTML tag names used (need to be imported from sibu) */
619
+ /** Tag names of the elements the compiled templates create */
532
620
  usedTags: Set<string>;
533
- /** Whether any SVG tags were used (needs tagFactory + SVG_NS import) */
621
+ /** Whether any compiled template creates SVG-namespace elements */
534
622
  usesSvg: boolean;
535
623
  /** Number of templates compiled */
536
624
  compiledCount: number;
625
+ /** Number of sibujs `html` templates deliberately left to the runtime parser */
626
+ skippedCount: number;
537
627
  }
538
628
  /**
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])
629
+ * Compile the sibujs `html` tagged templates in a module to direct DOM
630
+ * construction. The returned code is self-contained: it carries the aliased
631
+ * imports and helpers the compiled templates need, appended at the end of the
632
+ * module (imports are hoisted, and appending keeps every original line where
633
+ * it was — each compiled template also keeps the line breaks it spanned).
546
634
  *
547
- * This eliminates the runtime template parser entirely.
635
+ * Returns `code: null` when nothing was compiled — including when the file
636
+ * cannot be scanned with confidence.
548
637
  */
549
638
  declare function compileHtmlTemplates(code: string): CompileResult;
550
639
 
@@ -595,8 +684,8 @@ declare function buildRouteEntries(files: string[], chunkPrefix: string): RouteE
595
684
  * @example
596
685
  * ```ts
597
686
  * // vite.config.ts
598
- * import { sibuVitePlugin } from "sibu/build";
599
- * import { sibuRouteSplitting } from "sibu/build";
687
+ * import { sibuVitePlugin } from "sibujs/build";
688
+ * import { sibuRouteSplitting } from "sibujs/build";
600
689
  *
601
690
  * export default {
602
691
  * plugins: [sibuVitePlugin(), sibuRouteSplitting()],
@@ -604,7 +693,7 @@ declare function buildRouteEntries(files: string[], chunkPrefix: string): RouteE
604
693
  *
605
694
  * // In your app:
606
695
  * import { routes } from "virtual:sibu-routes";
607
- * import { setRoutes } from "sibu/plugins";
696
+ * import { setRoutes } from "sibujs/plugins";
608
697
  * setRoutes(routes);
609
698
  * ```
610
699
  */