sibujs 4.7.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 (81) hide show
  1. package/dist/browser.cjs +45 -4
  2. package/dist/browser.d.cts +23 -0
  3. package/dist/browser.d.ts +23 -0
  4. package/dist/browser.js +6 -5
  5. package/dist/build.cjs +513 -78
  6. package/dist/build.d.cts +22 -8
  7. package/dist/build.d.ts +22 -8
  8. package/dist/build.js +68 -21
  9. package/dist/cdn.dev.global.js +15 -13
  10. package/dist/cdn.full.dev.global.js +15 -13
  11. package/dist/cdn.full.global.js +14 -12
  12. package/dist/cdn.global.js +14 -12
  13. package/dist/chunk-3ACAAQIN.js +224 -0
  14. package/dist/{chunk-DKXRACVN.js → chunk-44MTL7ED.js} +6 -6
  15. package/dist/{chunk-3QWBSL5R.js → chunk-4WMSTZ7J.js} +8 -5
  16. package/dist/{chunk-H3SRKIYX.js → chunk-62BDYGAG.js} +8 -0
  17. package/dist/{chunk-BSY63EM6.js → chunk-C5PEWEGH.js} +20 -5
  18. package/dist/{chunk-BC2SECJD.js → chunk-C7AA2CZX.js} +1 -1
  19. package/dist/{chunk-SLM3IA34.js → chunk-CZPRSWSS.js} +1 -1
  20. package/dist/{chunk-FQRUXCEE.js → chunk-DSID757X.js} +1 -1
  21. package/dist/{chunk-ZVL7TY4K.js → chunk-EGUQLBHE.js} +22 -8
  22. package/dist/{chunk-2INLLLMZ.js → chunk-EXXSN3BW.js} +202 -26
  23. package/dist/{chunk-HURREPU2.js → chunk-FC6KCJSA.js} +87 -150
  24. package/dist/{chunk-Z3OHK6QT.js → chunk-GSGNX35Q.js} +5 -5
  25. package/dist/{chunk-XYV3EDB7.js → chunk-J3YQ457H.js} +37 -20
  26. package/dist/{chunk-VZSG24LS.js → chunk-JUTFX2RM.js} +18 -10
  27. package/dist/{chunk-RUSSKG6G.js → chunk-KJ3UKABJ.js} +1 -1
  28. package/dist/{chunk-UNWRJRKC.js → chunk-LI4W3U6C.js} +1 -1
  29. package/dist/{chunk-FNJXNGYZ.js → chunk-O6TRVMJI.js} +58 -6
  30. package/dist/{chunk-7LUJQAOJ.js → chunk-Q5J2LVKH.js} +1 -1
  31. package/dist/{chunk-4AWA2PVD.js → chunk-QGMSESDD.js} +10 -5
  32. package/dist/{chunk-XZR4PXRE.js → chunk-RGLPEBDE.js} +13 -10
  33. package/dist/{chunk-JWKYU5GV.js → chunk-TQQUN4WR.js} +1 -1
  34. package/dist/{chunk-WOLJZUFQ.js → chunk-UCNP3HVM.js} +12 -8
  35. package/dist/{chunk-WEQ3DMVL.js → chunk-V3LHZSU5.js} +1 -1
  36. package/dist/{chunk-UOL2ECCS.js → chunk-VWT3VXPL.js} +18 -12
  37. package/dist/{chunk-2BPG2XDA.js → chunk-ZVLHNEEL.js} +17 -35
  38. package/dist/{customElement-MmInOW1U.d.ts → customElement-pYDKUzWl.d.cts} +11 -3
  39. package/dist/{customElement-MmInOW1U.d.cts → customElement-pYDKUzWl.d.ts} +11 -3
  40. package/dist/data.cjs +9 -2
  41. package/dist/data.js +6 -6
  42. package/dist/devtools.cjs +1 -1
  43. package/dist/devtools.js +5 -5
  44. package/dist/ecosystem.cjs +400 -37
  45. package/dist/ecosystem.js +9 -8
  46. package/dist/extras.cjs +621 -252
  47. package/dist/extras.d.cts +2 -2
  48. package/dist/extras.d.ts +2 -2
  49. package/dist/extras.js +24 -23
  50. package/dist/index.cjs +464 -70
  51. package/dist/index.d.cts +28 -2
  52. package/dist/index.d.ts +28 -2
  53. package/dist/index.js +16 -12
  54. package/dist/motion.cjs +1 -1
  55. package/dist/motion.js +3 -3
  56. package/dist/patterns.cjs +10 -7
  57. package/dist/patterns.js +6 -6
  58. package/dist/performance.cjs +31 -2
  59. package/dist/performance.d.cts +12 -2
  60. package/dist/performance.d.ts +12 -2
  61. package/dist/performance.js +8 -6
  62. package/dist/plugins.cjs +558 -231
  63. package/dist/plugins.d.cts +8 -3
  64. package/dist/plugins.d.ts +8 -3
  65. package/dist/plugins.js +22 -28
  66. package/dist/{ssr-XOTUASDO.js → ssr-5OWAH3U2.js} +4 -2
  67. package/dist/{ssr-Bli9XRW5.d.ts → ssr-C8hgIAw7.d.cts} +6 -0
  68. package/dist/{ssr-Bli9XRW5.d.cts → ssr-C8hgIAw7.d.ts} +6 -0
  69. package/dist/ssr.cjs +457 -131
  70. package/dist/ssr.d.cts +55 -5
  71. package/dist/ssr.d.ts +55 -5
  72. package/dist/ssr.js +11 -9
  73. package/dist/testing.cjs +3 -3
  74. package/dist/testing.js +4 -4
  75. package/dist/ui.cjs +608 -240
  76. package/dist/ui.d.cts +1 -1
  77. package/dist/ui.d.ts +1 -1
  78. package/dist/ui.js +9 -8
  79. package/dist/widgets.cjs +1 -1
  80. package/dist/widgets.js +7 -7
  81. package/package.json +5 -4
package/dist/build.d.cts CHANGED
@@ -48,9 +48,11 @@ interface SibuVitePluginOptions {
48
48
  */
49
49
  staticOptimize?: boolean;
50
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.
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).
54
56
  */
55
57
  compileTemplates?: boolean;
56
58
  }
@@ -97,12 +99,24 @@ declare function createViteConfig(options?: {
97
99
  */
98
100
  interface SibuWebpackPluginOptions {
99
101
  /**
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
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
103
118
  * (`__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)`.
119
+ * options; the option is kept so existing configs keep compiling.
106
120
  */
107
121
  pureAnnotations?: boolean;
108
122
  /**
package/dist/build.d.ts CHANGED
@@ -48,9 +48,11 @@ interface SibuVitePluginOptions {
48
48
  */
49
49
  staticOptimize?: boolean;
50
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.
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).
54
56
  */
55
57
  compileTemplates?: boolean;
56
58
  }
@@ -97,12 +99,24 @@ declare function createViteConfig(options?: {
97
99
  */
98
100
  interface SibuWebpackPluginOptions {
99
101
  /**
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
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
103
118
  * (`__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)`.
119
+ * options; the option is kept so existing configs keep compiling.
106
120
  */
107
121
  pureAnnotations?: boolean;
108
122
  /**
package/dist/build.js CHANGED
@@ -1,24 +1,26 @@
1
1
  import {
2
2
  index_exports
3
- } from "./chunk-XYV3EDB7.js";
4
- import "./chunk-7LUJQAOJ.js";
5
- import "./chunk-HURREPU2.js";
6
- import "./chunk-SLM3IA34.js";
7
- import "./chunk-BC2SECJD.js";
8
- import "./chunk-UOL2ECCS.js";
9
- import "./chunk-FNJXNGYZ.js";
10
- import "./chunk-RUSSKG6G.js";
3
+ } from "./chunk-J3YQ457H.js";
4
+ import "./chunk-Q5J2LVKH.js";
5
+ import "./chunk-FC6KCJSA.js";
6
+ import "./chunk-CZPRSWSS.js";
7
+ import "./chunk-C7AA2CZX.js";
8
+ import "./chunk-62BDYGAG.js";
9
+ import "./chunk-VWT3VXPL.js";
10
+ import "./chunk-O6TRVMJI.js";
11
+ import "./chunk-3ACAAQIN.js";
12
+ import "./chunk-KJ3UKABJ.js";
13
+ import "./chunk-7ZHH77QA.js";
14
+ import "./chunk-V3LHZSU5.js";
11
15
  import {
12
16
  isEventHandlerAttr,
13
17
  isHtmlContentAttribute,
14
18
  isUrlAttribute
15
- } from "./chunk-2INLLLMZ.js";
16
- import "./chunk-7ZHH77QA.js";
17
- import "./chunk-WEQ3DMVL.js";
19
+ } from "./chunk-EXXSN3BW.js";
18
20
  import "./chunk-7XHATCIH.js";
19
21
  import "./chunk-5HZXGZ6T.js";
20
- import "./chunk-FQRUXCEE.js";
21
- import "./chunk-JWKYU5GV.js";
22
+ import "./chunk-DSID757X.js";
23
+ import "./chunk-TQQUN4WR.js";
22
24
  import "./chunk-NYNYSPK7.js";
23
25
 
24
26
  // src/build/sourceEdit.ts
@@ -1174,6 +1176,11 @@ function generateBody(roots, h) {
1174
1176
  const q = jsStringLiteral;
1175
1177
  const P = h.prefix;
1176
1178
  function genElement(el) {
1179
+ const tag = el.tag.toLowerCase();
1180
+ if (tag === "meta" || tag === "link") return null;
1181
+ for (const attr of el.attrs) {
1182
+ if ((attr.t === 0 || attr.t === 4) && attr.name.toLowerCase() === "srcdoc") return null;
1183
+ }
1177
1184
  const v = `e${n++}`;
1178
1185
  h.tags.add(el.tag);
1179
1186
  if (el.svg) h.svg = true;
@@ -1265,6 +1272,9 @@ function helperSource(h) {
1265
1272
  out.push(
1266
1273
  `function ${P}on(el, name, handler) {
1267
1274
  if (typeof handler === "function") el.addEventListener(name, handler);
1275
+ else if (typeof __SIBU_DEV__ !== "undefined" && __SIBU_DEV__) {
1276
+ console.warn(\`[SibuJS] html: on:\${name} handler is not a function (got \${typeof handler}). Event listener was not attached.\`);
1277
+ }
1268
1278
  }`
1269
1279
  );
1270
1280
  }
@@ -1272,7 +1282,10 @@ function helperSource(h) {
1272
1282
  out.push(
1273
1283
  `function ${P}child(el, value) {
1274
1284
  if (typeof value === "function") {
1275
- el.appendChild(${P}Fragment([value]));
1285
+ const frag = ${P}Fragment([value]);
1286
+ const ph = frag.firstChild;
1287
+ el.appendChild(frag);
1288
+ ${P}registerDisposer(el, () => ${P}dispose(ph));
1276
1289
  } else if (value instanceof Node) {
1277
1290
  el.appendChild(value);
1278
1291
  } else if (Array.isArray(value)) {
@@ -1292,13 +1305,22 @@ function helperSource(h) {
1292
1305
  function importSource(h) {
1293
1306
  const P = h.prefix;
1294
1307
  const core = [];
1295
- if (h.used.has("child")) core.push(`Fragment as ${P}Fragment`);
1296
- if (h.used.has("attr")) core.push(`registerDisposer as ${P}registerDisposer`);
1308
+ if (h.used.has("child")) core.push(`Fragment as ${P}Fragment`, `dispose as ${P}dispose`);
1309
+ if (h.used.has("attr") || h.used.has("child")) core.push(`registerDisposer as ${P}registerDisposer`);
1310
+ if (h.used.has("run")) core.push(`__renderParsedTemplate as ${P}run`);
1297
1311
  const lines = [];
1298
1312
  if (core.length > 0) lines.push(`import { ${core.join(", ")} } from "sibujs";`);
1299
1313
  if (h.used.has("attr")) lines.push(`import { bindAttrs as ${P}bindAttrs } from "sibujs/ui";`);
1300
1314
  return lines.join("\n");
1301
1315
  }
1316
+ function collectTags(children, h) {
1317
+ for (const child of children) {
1318
+ if (child.t !== 0) continue;
1319
+ h.tags.add(child.el.tag);
1320
+ if (child.el.svg) h.svg = true;
1321
+ collectTags(child.el.children, h);
1322
+ }
1323
+ }
1302
1324
  function planHtmlTemplates(code) {
1303
1325
  const plan = {
1304
1326
  edits: [],
@@ -1326,24 +1348,44 @@ function planHtmlTemplates(code) {
1326
1348
  const strings = [];
1327
1349
  for (const qs of tmpl.quasis) {
1328
1350
  const cooked = cookEscapes(code.slice(qs.start, qs.end));
1329
- if (cooked === null) return null;
1351
+ if (cooked === null) {
1352
+ if (tmpl.quasis.length === 1) return null;
1353
+ strings.push("undefined");
1354
+ continue;
1355
+ }
1330
1356
  strings.push(cooked);
1331
1357
  }
1358
+ const name = `${h.prefix}t${functions.length}`;
1359
+ const params = tmpl.exprs.map((_, i) => `v${i}`).join(", ");
1332
1360
  let roots;
1333
1361
  try {
1334
1362
  roots = parseTemplate(strings);
1335
1363
  } catch (err) {
1336
- if (err instanceof RuntimeParseError) return null;
1364
+ if (err instanceof RuntimeParseError) {
1365
+ const message = `html: dynamic \${...} expressions are not allowed inside <${err.message}> (raw-text context). Build the content separately and append it as a Node.`;
1366
+ functions.push(`function ${name}(${params}) {
1367
+ throw new Error(${jsStringLiteral(message)});
1368
+ }`);
1369
+ return name;
1370
+ }
1337
1371
  throw err;
1338
1372
  }
1339
1373
  const scratch = { prefix: h.prefix, used: /* @__PURE__ */ new Set(), tags: /* @__PURE__ */ new Set(), svg: false };
1340
1374
  const body = generateBody(roots, scratch);
1341
- if (body === null) return null;
1375
+ if (body === null) {
1376
+ const tree = JSON.stringify(roots).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
1377
+ h.used.add("run");
1378
+ collectTags(roots, h);
1379
+ functions.push(
1380
+ `function ${name}(${params}) {
1381
+ return ${h.prefix}run(${name}.tree || (${name}.tree = ${tree}), [${params}]);
1382
+ }`
1383
+ );
1384
+ return name;
1385
+ }
1342
1386
  for (const u of scratch.used) h.used.add(u);
1343
1387
  for (const t of scratch.tags) h.tags.add(t);
1344
1388
  if (scratch.svg) h.svg = true;
1345
- const name = `${h.prefix}t${functions.length}`;
1346
- const params = tmpl.exprs.map((_, i) => `v${i}`).join(", ");
1347
1389
  functions.push(`function ${name}(${params}) {
1348
1390
  ${body}
1349
1391
  }`);
@@ -1621,6 +1663,11 @@ function sibuWebpackPlugin(options = {}) {
1621
1663
  return {
1622
1664
  name: "SibuWebpackPlugin",
1623
1665
  apply(compiler) {
1666
+ if (options.pureAnnotations === true) {
1667
+ console.warn(
1668
+ '[SibuWebpackPlugin] `pureAnnotations` is not applied by the plugin: webpack needs a loader file. Create sibu-pure-loader.cjs containing `module.exports = require("sibujs/build").createPureAnnotationsLoader();` and add a module rule `{ test: /\\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: "./sibu-pure-loader.cjs" }`.'
1669
+ );
1670
+ }
1624
1671
  compiler.hooks?.compilation?.tap("SibuWebpackPlugin", (compilation) => {
1625
1672
  const comp = compilation;
1626
1673
  if (comp.hooks?.optimizeModules) {