sibujs 4.5.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.
- package/README.md +1 -1
- package/dist/browser.cjs +326 -133
- package/dist/browser.d.cts +46 -14
- package/dist/browser.d.ts +46 -14
- package/dist/browser.js +8 -6
- package/dist/build.cjs +2094 -1033
- package/dist/build.d.cts +133 -44
- package/dist/build.d.ts +133 -44
- package/dist/build.js +1372 -574
- package/dist/cdn.dev.global.js +10 -10
- package/dist/cdn.full.dev.global.js +11 -11
- package/dist/cdn.full.global.js +10 -10
- package/dist/cdn.global.js +10 -10
- package/dist/{chunk-2DCGACUU.js → chunk-2BPG2XDA.js} +251 -66
- package/dist/{chunk-IXKSNWV5.js → chunk-2INLLLMZ.js} +1 -1
- package/dist/{chunk-4PMLNECI.js → chunk-3QWBSL5R.js} +98 -29
- package/dist/{chunk-KKLW7YWL.js → chunk-4AWA2PVD.js} +275 -144
- package/dist/chunk-5HZXGZ6T.js +24 -0
- package/dist/{chunk-PCT43HW3.js → chunk-7LUJQAOJ.js} +1 -1
- package/dist/{chunk-5DXA2J44.js → chunk-7XHATCIH.js} +5 -2
- package/dist/chunk-BC2SECJD.js +44 -0
- package/dist/{chunk-TBYTO6BS.js → chunk-BSY63EM6.js} +136 -80
- package/dist/{chunk-FTIR4QW2.js → chunk-DKXRACVN.js} +6 -8
- package/dist/{chunk-ONOHFDLG.js → chunk-FNJXNGYZ.js} +3 -3
- package/dist/{chunk-XZZOBQAY.js → chunk-FQRUXCEE.js} +6 -5
- package/dist/{chunk-NIOYEGBQ.js → chunk-HURREPU2.js} +27 -13
- package/dist/chunk-J6FW5TV6.js +233 -0
- package/dist/{chunk-UGRX3S57.js → chunk-JWKYU5GV.js} +22 -4
- package/dist/chunk-NYNYSPK7.js +318 -0
- package/dist/{chunk-RBTPLM32.js → chunk-RUSSKG6G.js} +13 -12
- package/dist/{chunk-7LN645I6.js → chunk-SLM3IA34.js} +3 -3
- package/dist/{chunk-R25EFXXC.js → chunk-TUCPL2HB.js} +3 -3
- package/dist/{chunk-B3WHI2QA.js → chunk-UNWRJRKC.js} +55 -31
- package/dist/{chunk-KEISJXBU.js → chunk-UOL2ECCS.js} +44 -17
- package/dist/{chunk-RJE2BNI4.js → chunk-VZSG24LS.js} +108 -45
- package/dist/{chunk-RIXRAYIU.js → chunk-WEQ3DMVL.js} +10 -4
- package/dist/{chunk-3JZ4L5TJ.js → chunk-WOLJZUFQ.js} +354 -90
- package/dist/{chunk-S373NSMK.js → chunk-XYV3EDB7.js} +283 -123
- package/dist/{chunk-VZKNK2V7.js → chunk-XZR4PXRE.js} +296 -38
- package/dist/{chunk-GW3SCCZG.js → chunk-Z3OHK6QT.js} +153 -110
- package/dist/{chunk-OMJJM3KM.js → chunk-ZVL7TY4K.js} +287 -130
- package/dist/{contracts-DBdg9J_a.d.ts → contracts-CLqzJnOV.d.ts} +36 -17
- package/dist/{contracts-DBdg9J_a.d.cts → contracts-CTOJXu-x.d.cts} +36 -17
- package/dist/{customElement-OB9CIsc5.d.cts → customElement-MmInOW1U.d.cts} +21 -0
- package/dist/{customElement-OB9CIsc5.d.ts → customElement-MmInOW1U.d.ts} +21 -0
- package/dist/data.cjs +410 -155
- package/dist/data.d.cts +166 -12
- package/dist/data.d.ts +166 -12
- package/dist/data.js +12 -9
- package/dist/devtools.cjs +98 -61
- package/dist/devtools.js +7 -8
- package/dist/dispose-GEIG2KOF.js +28 -0
- package/dist/ecosystem.cjs +372 -126
- package/dist/ecosystem.d.cts +20 -3
- package/dist/ecosystem.d.ts +20 -3
- package/dist/ecosystem.js +12 -12
- package/dist/extras.cjs +2366 -909
- package/dist/extras.d.cts +11 -9
- package/dist/extras.d.ts +11 -9
- package/dist/extras.js +39 -28
- package/dist/index.cjs +421 -158
- package/dist/index.d.cts +213 -171
- package/dist/index.d.ts +213 -171
- package/dist/index.js +24 -27
- package/dist/motion.cjs +118 -44
- package/dist/motion.js +5 -5
- package/dist/patterns.cjs +344 -53
- package/dist/patterns.d.cts +28 -9
- package/dist/patterns.d.ts +28 -9
- package/dist/patterns.js +8 -8
- package/dist/performance.cjs +325 -220
- package/dist/performance.d.cts +2 -2
- package/dist/performance.d.ts +2 -2
- package/dist/performance.js +8 -9
- package/dist/plugin-DVgSnTfK.d.cts +112 -0
- package/dist/plugin-DVgSnTfK.d.ts +112 -0
- package/dist/plugins.cjs +664 -233
- package/dist/plugins.d.cts +127 -14
- package/dist/plugins.d.ts +127 -14
- package/dist/plugins.js +96 -42
- package/dist/signal-EotCj4hS.d.cts +110 -0
- package/dist/signal-EotCj4hS.d.ts +110 -0
- package/dist/{ssr-BiPRdZ6n.d.cts → ssr-Bli9XRW5.d.cts} +5 -0
- package/dist/{ssr-BiPRdZ6n.d.ts → ssr-Bli9XRW5.d.ts} +5 -0
- package/dist/{ssr-Y7XOEPEN.js → ssr-XOTUASDO.js} +4 -5
- package/dist/ssr.cjs +229 -84
- package/dist/ssr.d.cts +9 -3
- package/dist/ssr.d.ts +9 -3
- package/dist/ssr.js +11 -12
- package/dist/{startup-BMpaiMhP.d.ts → startup-BLfSeL15.d.cts} +73 -22
- package/dist/{startup-BMpaiMhP.d.cts → startup-BLfSeL15.d.ts} +73 -22
- package/dist/tagFactory-8qL9LCIx.d.cts +156 -0
- package/dist/tagFactory-BL2fymez.d.ts +156 -0
- package/dist/testing.cjs +2503 -2191
- package/dist/testing.d.cts +56 -5
- package/dist/testing.d.ts +56 -5
- package/dist/testing.js +580 -307
- package/dist/types-CJFViL6Q.d.cts +26 -0
- package/dist/types-CJFViL6Q.d.ts +26 -0
- package/dist/ui.cjs +732 -329
- package/dist/ui.d.cts +41 -7
- package/dist/ui.d.ts +41 -7
- package/dist/ui.js +151 -56
- package/dist/widgets.cjs +267 -291
- package/dist/widgets.js +9 -10
- package/package.json +4 -2
- package/dist/chunk-2WLZ6757.js +0 -149
- package/dist/chunk-CCSJMTRN.js +0 -15
- package/dist/chunk-QKRPLZ2V.js +0 -108
- package/dist/chunk-VUF4ALSW.js +0 -60
- package/dist/chunk-WWV3SJ3L.js +0 -131
- package/dist/dispose-46BOMMQJ.js +0 -19
- package/dist/plugin-D30wlGW5.d.cts +0 -71
- package/dist/plugin-D30wlGW5.d.ts +0 -71
- package/dist/tagFactory-DVoDpHye.d.cts +0 -215
- package/dist/tagFactory-DVoDpHye.d.ts +0 -215
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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('
|
|
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
|
-
*
|
|
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('
|
|
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/
|
|
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/
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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
|
|
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
|
|
503
|
-
*
|
|
584
|
+
* Analyze source code for static tag-factory calls that can be converted to
|
|
585
|
+
* template cloning at build time.
|
|
504
586
|
*
|
|
505
|
-
* Detects
|
|
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
|
|
520
|
-
*
|
|
604
|
+
* Into a module-level construction function plus a call that passes the
|
|
605
|
+
* template's expressions in their original order:
|
|
521
606
|
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
607
|
+
* __sibujs$t0((cls), (() => count()))
|
|
608
|
+
* ...
|
|
609
|
+
* function __sibujs$t0(v0, v1) { ...direct DOM construction... }
|
|
524
610
|
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
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
|
|
617
|
+
/** The transformed source code, or null if nothing was compiled */
|
|
530
618
|
code: string | null;
|
|
531
|
-
/**
|
|
619
|
+
/** Tag names of the elements the compiled templates create */
|
|
532
620
|
usedTags: Set<string>;
|
|
533
|
-
/** Whether any
|
|
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
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
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
|
-
*
|
|
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 "
|
|
599
|
-
* import { sibuRouteSplitting } from "
|
|
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 "
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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('
|
|
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
|
-
*
|
|
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('
|
|
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/
|
|
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/
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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
|
|
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
|
|
503
|
-
*
|
|
584
|
+
* Analyze source code for static tag-factory calls that can be converted to
|
|
585
|
+
* template cloning at build time.
|
|
504
586
|
*
|
|
505
|
-
* Detects
|
|
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
|
|
520
|
-
*
|
|
604
|
+
* Into a module-level construction function plus a call that passes the
|
|
605
|
+
* template's expressions in their original order:
|
|
521
606
|
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
607
|
+
* __sibujs$t0((cls), (() => count()))
|
|
608
|
+
* ...
|
|
609
|
+
* function __sibujs$t0(v0, v1) { ...direct DOM construction... }
|
|
524
610
|
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
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
|
|
617
|
+
/** The transformed source code, or null if nothing was compiled */
|
|
530
618
|
code: string | null;
|
|
531
|
-
/**
|
|
619
|
+
/** Tag names of the elements the compiled templates create */
|
|
532
620
|
usedTags: Set<string>;
|
|
533
|
-
/** Whether any
|
|
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
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
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
|
-
*
|
|
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 "
|
|
599
|
-
* import { sibuRouteSplitting } from "
|
|
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 "
|
|
696
|
+
* import { setRoutes } from "sibujs/plugins";
|
|
608
697
|
* setRoutes(routes);
|
|
609
698
|
* ```
|
|
610
699
|
*/
|