sibujs 1.0.0-beta.1
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/LICENSE +21 -0
- package/README.md +1630 -0
- package/dist/browser.cjs +815 -0
- package/dist/browser.d.cts +174 -0
- package/dist/browser.d.ts +174 -0
- package/dist/browser.js +458 -0
- package/dist/build.cjs +4970 -0
- package/dist/build.d.cts +630 -0
- package/dist/build.d.ts +630 -0
- package/dist/build.js +2478 -0
- package/dist/cdn.global.js +115 -0
- package/dist/chunk-27QC4FPL.js +67 -0
- package/dist/chunk-2ABBWCGC.js +65 -0
- package/dist/chunk-2MUNQYZ7.js +26 -0
- package/dist/chunk-2PSPKNUI.js +1711 -0
- package/dist/chunk-35CDLDX5.js +1758 -0
- package/dist/chunk-36MU4CFV.js +41 -0
- package/dist/chunk-3FIQOFI6.js +182 -0
- package/dist/chunk-3GHNC2BN.js +28 -0
- package/dist/chunk-3HLWWEPU.js +909 -0
- package/dist/chunk-3IVI3J54.js +252 -0
- package/dist/chunk-3KZ72WNW.js +944 -0
- package/dist/chunk-4AU64SQV.js +182 -0
- package/dist/chunk-4MOK7HAR.js +84 -0
- package/dist/chunk-4QK6FBDH.js +1429 -0
- package/dist/chunk-566Z7HXB.js +737 -0
- package/dist/chunk-5CRBB7XP.js +358 -0
- package/dist/chunk-5G67D3IZ.js +168 -0
- package/dist/chunk-5NCPAWBE.js +99 -0
- package/dist/chunk-5O2RKXR3.js +1444 -0
- package/dist/chunk-6BTBDO6A.js +633 -0
- package/dist/chunk-6IWEHW57.js +43 -0
- package/dist/chunk-6JGMNCD6.js +282 -0
- package/dist/chunk-6QRLJNXR.js +1425 -0
- package/dist/chunk-7HM5UE5T.js +270 -0
- package/dist/chunk-7JOLTGUH.js +58 -0
- package/dist/chunk-7MCWJCQK.js +909 -0
- package/dist/chunk-7RIIFP3E.js +1758 -0
- package/dist/chunk-7UASYN3G.js +254 -0
- package/dist/chunk-7W2WYHDI.js +741 -0
- package/dist/chunk-7Y35RDSJ.js +872 -0
- package/dist/chunk-A65GFJBL.js +65 -0
- package/dist/chunk-AD6ZIEDK.js +67 -0
- package/dist/chunk-AK5Y72F3.js +1426 -0
- package/dist/chunk-APOMMWH4.js +282 -0
- package/dist/chunk-ARZVTWIQ.js +1750 -0
- package/dist/chunk-AWWBM2BI.js +664 -0
- package/dist/chunk-AX5VEQTY.js +58 -0
- package/dist/chunk-AYTXVOW3.js +1708 -0
- package/dist/chunk-BG4A246G.js +1746 -0
- package/dist/chunk-BNFJJA2L.js +1425 -0
- package/dist/chunk-BPKPBVU5.js +59 -0
- package/dist/chunk-BPKPPSXC.js +282 -0
- package/dist/chunk-BPWKKK7F.js +1711 -0
- package/dist/chunk-CCKX6YTC.js +1735 -0
- package/dist/chunk-CIF5Z3MP.js +58 -0
- package/dist/chunk-CSXYU7IO.js +457 -0
- package/dist/chunk-D6JD4FDC.js +26 -0
- package/dist/chunk-E7NGA7X2.js +59 -0
- package/dist/chunk-EEPPJKAE.js +443 -0
- package/dist/chunk-EJMYGAGQ.js +717 -0
- package/dist/chunk-EL6Z5MDY.js +55 -0
- package/dist/chunk-EP7VRLEB.js +41 -0
- package/dist/chunk-ETMEC6FH.js +99 -0
- package/dist/chunk-EZ2WHYVL.js +65 -0
- package/dist/chunk-EZRVMSZK.js +67 -0
- package/dist/chunk-F2TRGINX.js +254 -0
- package/dist/chunk-F5JCIH3Q.js +642 -0
- package/dist/chunk-FGK3JKMN.js +909 -0
- package/dist/chunk-FQWPKSTD.js +1437 -0
- package/dist/chunk-FWHVLMCI.js +26 -0
- package/dist/chunk-GBEYQRO2.js +303 -0
- package/dist/chunk-GBLES3NK.js +248 -0
- package/dist/chunk-GQVGUQW6.js +1436 -0
- package/dist/chunk-HCV2T76T.js +457 -0
- package/dist/chunk-HS7ZKVPR.js +182 -0
- package/dist/chunk-HXDVV7HZ.js +909 -0
- package/dist/chunk-IB23VMO3.js +1746 -0
- package/dist/chunk-IEMZ7RTT.js +99 -0
- package/dist/chunk-IPGRSN42.js +1750 -0
- package/dist/chunk-IVMOK2QN.js +1750 -0
- package/dist/chunk-JCLGQO7T.js +443 -0
- package/dist/chunk-JDXL7KDB.js +1436 -0
- package/dist/chunk-JIIFW636.js +270 -0
- package/dist/chunk-JWGEEH7H.js +944 -0
- package/dist/chunk-K2BESAG7.js +1688 -0
- package/dist/chunk-K2U5YGF4.js +877 -0
- package/dist/chunk-K45FQ4Y4.js +175 -0
- package/dist/chunk-K7BPE427.js +1432 -0
- package/dist/chunk-KL3266RS.js +26 -0
- package/dist/chunk-KNN4P7DZ.js +84 -0
- package/dist/chunk-KP2DZH5Q.js +254 -0
- package/dist/chunk-KZHAJSQR.js +1636 -0
- package/dist/chunk-LBKGHMQV.js +1750 -0
- package/dist/chunk-LBTEPL7A.js +1731 -0
- package/dist/chunk-LEBBPTDB.js +1444 -0
- package/dist/chunk-LLH63WVQ.js +98 -0
- package/dist/chunk-LWVR2C4G.js +1711 -0
- package/dist/chunk-M3MDTVV2.js +896 -0
- package/dist/chunk-M5GNLDEO.js +303 -0
- package/dist/chunk-MFHVGKET.js +267 -0
- package/dist/chunk-MGWSG3PM.js +358 -0
- package/dist/chunk-MJNB47HB.js +19 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-MQWTY3JY.js +944 -0
- package/dist/chunk-MZZOQHNI.js +642 -0
- package/dist/chunk-NIHWGZS4.js +1426 -0
- package/dist/chunk-NSVVHQK5.js +41 -0
- package/dist/chunk-NVI2WE7D.js +443 -0
- package/dist/chunk-O7QBO3PH.js +58 -0
- package/dist/chunk-OAUPQBO2.js +270 -0
- package/dist/chunk-OB2LMD7C.js +297 -0
- package/dist/chunk-OHEYBWQU.js +58 -0
- package/dist/chunk-OI6OXUHJ.js +443 -0
- package/dist/chunk-OX2VMRMV.js +633 -0
- package/dist/chunk-P4FYE5TX.js +866 -0
- package/dist/chunk-P5KFWM4H.js +98 -0
- package/dist/chunk-PUMLE7RJ.js +1711 -0
- package/dist/chunk-Q4MFANBF.js +282 -0
- package/dist/chunk-QLEKZMMU.js +282 -0
- package/dist/chunk-RGGNGVO3.js +98 -0
- package/dist/chunk-RKJDRVV6.js +443 -0
- package/dist/chunk-S5BHU353.js +43 -0
- package/dist/chunk-SHQUSFH7.js +1426 -0
- package/dist/chunk-SMB4DBMD.js +182 -0
- package/dist/chunk-SNYHQP3D.js +743 -0
- package/dist/chunk-T24L3TBF.js +1717 -0
- package/dist/chunk-TAQNSOKT.js +692 -0
- package/dist/chunk-TDNY4SUA.js +41 -0
- package/dist/chunk-TNNF56IQ.js +1750 -0
- package/dist/chunk-TR7E6LYX.js +457 -0
- package/dist/chunk-URWUFH45.js +98 -0
- package/dist/chunk-UUSIH3XH.js +1429 -0
- package/dist/chunk-UYFNXLKR.js +1436 -0
- package/dist/chunk-V6F7KUWD.js +270 -0
- package/dist/chunk-VCZLXRMR.js +254 -0
- package/dist/chunk-VDHXSSBT.js +1426 -0
- package/dist/chunk-VM4QMKVK.js +254 -0
- package/dist/chunk-VWGYKYL2.js +737 -0
- package/dist/chunk-VX2OFBJN.js +1426 -0
- package/dist/chunk-VXVIE6DG.js +84 -0
- package/dist/chunk-W4OH7HG4.js +40 -0
- package/dist/chunk-WBVJX4GZ.js +98 -0
- package/dist/chunk-WDU2ZV4I.js +1426 -0
- package/dist/chunk-X6VUCICU.js +457 -0
- package/dist/chunk-XAY7FM7Y.js +618 -0
- package/dist/chunk-XJZ5Z2CM.js +642 -0
- package/dist/chunk-XKVFQTJJ.js +254 -0
- package/dist/chunk-XRLFASCY.js +22 -0
- package/dist/chunk-XYU6TZOW.js +182 -0
- package/dist/chunk-Y745CBVB.js +944 -0
- package/dist/chunk-YLBJSXYY.js +944 -0
- package/dist/chunk-YQJIKVPZ.js +1429 -0
- package/dist/chunk-YRM2VCZF.js +457 -0
- package/dist/chunk-YS33KBVJ.js +944 -0
- package/dist/chunk-Z27DZPDG.js +41 -0
- package/dist/chunk-ZXQ5NAEN.js +32 -0
- package/dist/contracts-B552GopR.d.cts +245 -0
- package/dist/contracts-B552GopR.d.ts +245 -0
- package/dist/contracts-Bg1ECISC.d.cts +245 -0
- package/dist/contracts-Bg1ECISC.d.ts +245 -0
- package/dist/contracts-CMriKJ6P.d.cts +245 -0
- package/dist/contracts-CMriKJ6P.d.ts +245 -0
- package/dist/contracts-DOrhwbke.d.cts +245 -0
- package/dist/contracts-DOrhwbke.d.ts +245 -0
- package/dist/data.cjs +1373 -0
- package/dist/data.d.cts +434 -0
- package/dist/data.d.ts +434 -0
- package/dist/data.js +945 -0
- package/dist/devtools.cjs +1357 -0
- package/dist/devtools.d.cts +473 -0
- package/dist/devtools.d.ts +473 -0
- package/dist/devtools.js +1084 -0
- package/dist/ecosystem.cjs +1046 -0
- package/dist/ecosystem.d.cts +247 -0
- package/dist/ecosystem.d.ts +247 -0
- package/dist/ecosystem.js +369 -0
- package/dist/extras.cjs +8457 -0
- package/dist/extras.d.cts +2356 -0
- package/dist/extras.d.ts +2356 -0
- package/dist/extras.js +5152 -0
- package/dist/index.cjs +2648 -0
- package/dist/index.d.cts +869 -0
- package/dist/index.d.ts +869 -0
- package/dist/index.js +386 -0
- package/dist/motion.cjs +604 -0
- package/dist/motion.d.cts +146 -0
- package/dist/motion.d.ts +146 -0
- package/dist/motion.js +346 -0
- package/dist/patterns.cjs +815 -0
- package/dist/patterns.d.cts +163 -0
- package/dist/patterns.d.ts +163 -0
- package/dist/patterns.js +296 -0
- package/dist/performance.cjs +927 -0
- package/dist/performance.d.cts +416 -0
- package/dist/performance.d.ts +416 -0
- package/dist/performance.js +654 -0
- package/dist/plugins.cjs +2487 -0
- package/dist/plugins.d.cts +393 -0
- package/dist/plugins.d.ts +393 -0
- package/dist/plugins.js +1504 -0
- package/dist/signal-BnWpq6WB.d.cts +5 -0
- package/dist/signal-BnWpq6WB.d.ts +5 -0
- package/dist/src/components/ErrorBoundary.d.ts +15 -0
- package/dist/src/components/ErrorBoundary.js +119 -0
- package/dist/src/core/catch.d.ts +11 -0
- package/dist/src/core/catch.js +28 -0
- package/dist/src/core/each.d.ts +13 -0
- package/dist/src/core/each.js +68 -0
- package/dist/src/core/for.d.ts +12 -0
- package/dist/src/core/for.js +67 -0
- package/dist/src/core/html.d.ts +137 -0
- package/dist/src/core/html.js +155 -0
- package/dist/src/core/htmlIf.d.ts +11 -0
- package/dist/src/core/htmlIf.js +18 -0
- package/dist/src/core/lazy.d.ts +7 -0
- package/dist/src/core/lazy.js +16 -0
- package/dist/src/core/mount.d.ts +7 -0
- package/dist/src/core/mount.js +12 -0
- package/dist/src/core/slots.d.ts +3 -0
- package/dist/src/core/slots.js +3 -0
- package/dist/src/core/suspense.d.ts +10 -0
- package/dist/src/core/suspense.js +33 -0
- package/dist/src/core/tagFactory.d.ts +13 -0
- package/dist/src/core/tagFactory.js +86 -0
- package/dist/src/core/test.d.ts +11 -0
- package/dist/src/core/test.js +28 -0
- package/dist/src/core/types.d.ts +2 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/core/useComputed.d.ts +6 -0
- package/dist/src/core/useComputed.js +30 -0
- package/dist/src/core/useEffect.d.ts +6 -0
- package/dist/src/core/useEffect.js +23 -0
- package/dist/src/core/useState.d.ts +10 -0
- package/dist/src/core/useState.js +34 -0
- package/dist/src/core/useStore.d.ts +19 -0
- package/dist/src/core/useStore.js +53 -0
- package/dist/src/core/useWatch.d.ts +8 -0
- package/dist/src/core/useWatch.js +23 -0
- package/dist/src/plugins/i18n.d.ts +6 -0
- package/dist/src/plugins/i18n.js +16 -0
- package/dist/src/plugins/router.d.ts +188 -0
- package/dist/src/plugins/router.js +1178 -0
- package/dist/src/reactivity/bindAttribute.d.ts +5 -0
- package/dist/src/reactivity/bindAttribute.js +31 -0
- package/dist/src/reactivity/bindChildNode.d.ts +10 -0
- package/dist/src/reactivity/bindChildNode.js +46 -0
- package/dist/src/reactivity/bindTextNode.d.ts +10 -0
- package/dist/src/reactivity/bindTextNode.js +27 -0
- package/dist/src/reactivity/signal.d.ts +3 -0
- package/dist/src/reactivity/signal.js +1 -0
- package/dist/src/reactivity/track.d.ts +18 -0
- package/dist/src/reactivity/track.js +73 -0
- package/dist/src/reactivity/useComputed.d.ts +6 -0
- package/dist/src/reactivity/useComputed.js +30 -0
- package/dist/src/reactivity/useEffect.d.ts +6 -0
- package/dist/src/reactivity/useEffect.js +23 -0
- package/dist/src/reactivity/useState.d.ts +10 -0
- package/dist/src/reactivity/useState.js +34 -0
- package/dist/src/reactivity/useStore.d.ts +19 -0
- package/dist/src/reactivity/useStore.js +53 -0
- package/dist/src/reactivity/useWatch.d.ts +8 -0
- package/dist/src/reactivity/useWatch.js +23 -0
- package/dist/src/utils/sanitize.d.ts +1 -0
- package/dist/src/utils/sanitize.js +8 -0
- package/dist/ssr-27FOM46T.js +35 -0
- package/dist/ssr-GFUTTSJD.js +22 -0
- package/dist/ssr-K7DCR6BZ.js +35 -0
- package/dist/ssr-O6LFMRFP.js +35 -0
- package/dist/ssr-QZEVGMMK.js +35 -0
- package/dist/ssr-SGVBCAGC.js +35 -0
- package/dist/ssr-UB2IXCYX.js +35 -0
- package/dist/ssr-XBZQNV4O.js +22 -0
- package/dist/ssr-Y76FSXDU.js +35 -0
- package/dist/ssr-YQJ4AYBD.js +35 -0
- package/dist/ssr.cjs +1757 -0
- package/dist/ssr.d.cts +478 -0
- package/dist/ssr.d.ts +478 -0
- package/dist/ssr.js +743 -0
- package/dist/tagFactory-CZPO4RXF.d.cts +34 -0
- package/dist/tagFactory-CZPO4RXF.d.ts +34 -0
- package/dist/tagFactory-CgImPVMY.d.cts +22 -0
- package/dist/tagFactory-CgImPVMY.d.ts +22 -0
- package/dist/tagFactory-Cw1iv5if.d.cts +22 -0
- package/dist/tagFactory-Cw1iv5if.d.ts +22 -0
- package/dist/tagFactory-DeAXq9ef.d.cts +30 -0
- package/dist/tagFactory-DeAXq9ef.d.ts +30 -0
- package/dist/tagFactory-SkY0a7L1.d.cts +22 -0
- package/dist/tagFactory-SkY0a7L1.d.ts +22 -0
- package/dist/testing.cjs +1919 -0
- package/dist/testing.d.cts +491 -0
- package/dist/testing.d.ts +491 -0
- package/dist/testing.js +1862 -0
- package/dist/ui.cjs +1497 -0
- package/dist/ui.d.cts +264 -0
- package/dist/ui.d.ts +264 -0
- package/dist/ui.js +900 -0
- package/dist/widgets.cjs +919 -0
- package/dist/widgets.d.cts +165 -0
- package/dist/widgets.d.ts +165 -0
- package/dist/widgets.js +545 -0
- package/package.json +134 -0
package/dist/ssr.cjs
ADDED
|
@@ -0,0 +1,1757 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// ssr.ts
|
|
21
|
+
var ssr_exports = {};
|
|
22
|
+
__export(ssr_exports, {
|
|
23
|
+
Head: () => Head,
|
|
24
|
+
clearWasmCache: () => clearWasmCache,
|
|
25
|
+
collectStream: () => collectStream,
|
|
26
|
+
composeMiddleware: () => composeMiddleware,
|
|
27
|
+
createAction: () => createAction,
|
|
28
|
+
createISR: () => createISR,
|
|
29
|
+
createMicroApp: () => createMicroApp,
|
|
30
|
+
createMiddlewareChain: () => createMiddlewareChain,
|
|
31
|
+
createSharedScope: () => createSharedScope,
|
|
32
|
+
createWasmBridge: () => createWasmBridge,
|
|
33
|
+
createWorkerPool: () => createWorkerPool,
|
|
34
|
+
defineRemoteComponent: () => defineRemoteComponent,
|
|
35
|
+
deserializeState: () => deserializeState,
|
|
36
|
+
generateStaticSite: () => generateStaticSite,
|
|
37
|
+
hydrate: () => hydrate,
|
|
38
|
+
hydrateIslands: () => hydrateIslands,
|
|
39
|
+
hydrateProgressively: () => hydrateProgressively,
|
|
40
|
+
isWasmCached: () => isWasmCached,
|
|
41
|
+
island: () => island,
|
|
42
|
+
loadRemoteModule: () => loadRemoteModule,
|
|
43
|
+
loadWasmModule: () => loadWasmModule,
|
|
44
|
+
preloadWasm: () => preloadWasm,
|
|
45
|
+
renderToDocument: () => renderToDocument,
|
|
46
|
+
renderToReadableStream: () => renderToReadableStream,
|
|
47
|
+
renderToStream: () => renderToStream,
|
|
48
|
+
renderToString: () => renderToString,
|
|
49
|
+
renderToSuspenseStream: () => renderToSuspenseStream,
|
|
50
|
+
resetSSRState: () => resetSSRState,
|
|
51
|
+
scrollRestoration: () => scrollRestoration,
|
|
52
|
+
serializeState: () => serializeState,
|
|
53
|
+
serviceWorker: () => serviceWorker,
|
|
54
|
+
setCanonical: () => setCanonical,
|
|
55
|
+
setStructuredData: () => setStructuredData,
|
|
56
|
+
ssrSuspense: () => ssrSuspense,
|
|
57
|
+
suspenseSwapScript: () => suspenseSwapScript,
|
|
58
|
+
wasm: () => wasm,
|
|
59
|
+
worker: () => worker,
|
|
60
|
+
workerFn: () => workerFn
|
|
61
|
+
});
|
|
62
|
+
module.exports = __toCommonJS(ssr_exports);
|
|
63
|
+
|
|
64
|
+
// src/platform/ssr.ts
|
|
65
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
66
|
+
"area",
|
|
67
|
+
"base",
|
|
68
|
+
"br",
|
|
69
|
+
"col",
|
|
70
|
+
"embed",
|
|
71
|
+
"hr",
|
|
72
|
+
"img",
|
|
73
|
+
"input",
|
|
74
|
+
"link",
|
|
75
|
+
"meta",
|
|
76
|
+
"param",
|
|
77
|
+
"source",
|
|
78
|
+
"track",
|
|
79
|
+
"wbr"
|
|
80
|
+
]);
|
|
81
|
+
function renderToString(element) {
|
|
82
|
+
if (element instanceof DocumentFragment) {
|
|
83
|
+
return Array.from(element.childNodes).map((child) => renderToString(child)).join("");
|
|
84
|
+
}
|
|
85
|
+
if (element.nodeType === 3) {
|
|
86
|
+
return escapeHtml(element.textContent || "");
|
|
87
|
+
}
|
|
88
|
+
if (element.nodeType === 8) {
|
|
89
|
+
const content = (element.textContent || "").replace(/-->/g, "-->");
|
|
90
|
+
return `<!--${content}-->`;
|
|
91
|
+
}
|
|
92
|
+
if (!(element instanceof HTMLElement)) {
|
|
93
|
+
return element.textContent || "";
|
|
94
|
+
}
|
|
95
|
+
const tag = element.tagName.toLowerCase();
|
|
96
|
+
let html2 = `<${tag}`;
|
|
97
|
+
for (const attr of Array.from(element.attributes)) {
|
|
98
|
+
html2 += ` ${attr.name}="${escapeAttr(attr.value)}"`;
|
|
99
|
+
}
|
|
100
|
+
if (element.dataset && !element.dataset.sibuHydrate) {
|
|
101
|
+
html2 += ` data-sibu-ssr="true"`;
|
|
102
|
+
}
|
|
103
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
104
|
+
return `${html2} />`;
|
|
105
|
+
}
|
|
106
|
+
html2 += ">";
|
|
107
|
+
for (const child of Array.from(element.childNodes)) {
|
|
108
|
+
html2 += renderToString(child);
|
|
109
|
+
}
|
|
110
|
+
html2 += `</${tag}>`;
|
|
111
|
+
return html2;
|
|
112
|
+
}
|
|
113
|
+
function hydrate(component, container) {
|
|
114
|
+
const clientTree = component();
|
|
115
|
+
hydrateNode(container.firstElementChild, clientTree);
|
|
116
|
+
container.setAttribute("data-sibu-hydrated", "true");
|
|
117
|
+
}
|
|
118
|
+
function hydrateNode(serverNode, clientNode) {
|
|
119
|
+
if (!serverNode) return;
|
|
120
|
+
const serverChildren = Array.from(serverNode.children);
|
|
121
|
+
const clientChildren = Array.from(clientNode.children);
|
|
122
|
+
for (let i2 = 0; i2 < Math.min(serverChildren.length, clientChildren.length); i2++) {
|
|
123
|
+
hydrateNode(serverChildren[i2], clientChildren[i2]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function renderToDocument(component, options = {}) {
|
|
127
|
+
const content = renderToString(component());
|
|
128
|
+
const metaTags = (options.meta || []).map(
|
|
129
|
+
(attrs) => `<meta ${Object.entries(attrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ")} />`
|
|
130
|
+
).join("\n ");
|
|
131
|
+
const linkTags = (options.links || []).map(
|
|
132
|
+
(attrs) => `<link ${Object.entries(attrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ")} />`
|
|
133
|
+
).join("\n ");
|
|
134
|
+
const scriptTags = (options.scripts || []).map((src) => `<script src="${escapeAttr(src)}"></script>`).join("\n ");
|
|
135
|
+
const bodyAttrs = options.bodyAttrs ? " " + Object.entries(options.bodyAttrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ") : "";
|
|
136
|
+
return `<!DOCTYPE html>
|
|
137
|
+
<html>
|
|
138
|
+
<head>
|
|
139
|
+
<meta charset="UTF-8" />
|
|
140
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
141
|
+
${options.title ? `<title>${escapeHtml(options.title)}</title>` : ""}
|
|
142
|
+
${metaTags}
|
|
143
|
+
${linkTags}
|
|
144
|
+
${options.headExtra || ""}
|
|
145
|
+
</head>
|
|
146
|
+
<body${bodyAttrs}>
|
|
147
|
+
<div id="app">${content}</div>
|
|
148
|
+
${scriptTags}
|
|
149
|
+
</body>
|
|
150
|
+
</html>`;
|
|
151
|
+
}
|
|
152
|
+
async function* renderToStream(element) {
|
|
153
|
+
if (element instanceof DocumentFragment) {
|
|
154
|
+
for (const child of Array.from(element.childNodes)) {
|
|
155
|
+
yield* renderToStream(child);
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (element.nodeType === 3) {
|
|
160
|
+
yield escapeHtml(element.textContent || "");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (element.nodeType === 8) {
|
|
164
|
+
yield `<!--${element.textContent || ""}-->`;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (!(element instanceof HTMLElement)) {
|
|
168
|
+
yield element.textContent || "";
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const tag = element.tagName.toLowerCase();
|
|
172
|
+
let openTag = `<${tag}`;
|
|
173
|
+
for (const attr of Array.from(element.attributes)) {
|
|
174
|
+
openTag += ` ${attr.name}="${escapeAttr(attr.value)}"`;
|
|
175
|
+
}
|
|
176
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
177
|
+
yield `${openTag} />`;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
yield `${openTag}>`;
|
|
181
|
+
for (const child of Array.from(element.childNodes)) {
|
|
182
|
+
yield* renderToStream(child);
|
|
183
|
+
}
|
|
184
|
+
yield `</${tag}>`;
|
|
185
|
+
}
|
|
186
|
+
async function collectStream(stream) {
|
|
187
|
+
let result = "";
|
|
188
|
+
for await (const chunk of stream) {
|
|
189
|
+
result += chunk;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
function renderToReadableStream(element) {
|
|
194
|
+
const generator = renderToStream(element);
|
|
195
|
+
return new ReadableStream({
|
|
196
|
+
async pull(controller) {
|
|
197
|
+
const { value, done } = await generator.next();
|
|
198
|
+
if (done) {
|
|
199
|
+
controller.close();
|
|
200
|
+
} else {
|
|
201
|
+
controller.enqueue(value);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
cancel() {
|
|
205
|
+
generator.return(void 0);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function island(id, component) {
|
|
210
|
+
const el = component();
|
|
211
|
+
el.setAttribute("data-sibu-island", id);
|
|
212
|
+
return el;
|
|
213
|
+
}
|
|
214
|
+
function hydrateIslands(container, islands) {
|
|
215
|
+
const markers = container.querySelectorAll("[data-sibu-island]");
|
|
216
|
+
for (const marker2 of Array.from(markers)) {
|
|
217
|
+
const id = marker2.getAttribute("data-sibu-island") ?? "";
|
|
218
|
+
const factory = islands[id];
|
|
219
|
+
if (!factory) continue;
|
|
220
|
+
const clientTree = factory();
|
|
221
|
+
hydrateNode(marker2, clientTree);
|
|
222
|
+
marker2.setAttribute("data-sibu-hydrated", "true");
|
|
223
|
+
}
|
|
224
|
+
container.setAttribute("data-sibu-hydrated", "partial");
|
|
225
|
+
}
|
|
226
|
+
function hydrateProgressively(container, islands, options) {
|
|
227
|
+
const markers = container.querySelectorAll("[data-sibu-island]");
|
|
228
|
+
const cleanups = [];
|
|
229
|
+
for (const marker2 of Array.from(markers)) {
|
|
230
|
+
const id = marker2.getAttribute("data-sibu-island") ?? "";
|
|
231
|
+
const factory = islands[id];
|
|
232
|
+
if (!factory) continue;
|
|
233
|
+
const observer = new IntersectionObserver(
|
|
234
|
+
(entries) => {
|
|
235
|
+
for (const entry of entries) {
|
|
236
|
+
if (entry.isIntersecting) {
|
|
237
|
+
const clientTree = factory();
|
|
238
|
+
hydrateNode(marker2, clientTree);
|
|
239
|
+
marker2.setAttribute("data-sibu-hydrated", "true");
|
|
240
|
+
observer.disconnect();
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
{ rootMargin: "200px", ...options }
|
|
246
|
+
);
|
|
247
|
+
observer.observe(marker2);
|
|
248
|
+
cleanups.push(() => observer.disconnect());
|
|
249
|
+
}
|
|
250
|
+
container.setAttribute("data-sibu-hydrated", "progressive");
|
|
251
|
+
return () => {
|
|
252
|
+
for (const cleanup2 of cleanups) cleanup2();
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
var suspenseIdCounter = 0;
|
|
256
|
+
function resetSSRState() {
|
|
257
|
+
suspenseIdCounter = 0;
|
|
258
|
+
}
|
|
259
|
+
function ssrSuspense(props) {
|
|
260
|
+
const id = `sibu-sus-${suspenseIdCounter++}`;
|
|
261
|
+
const fallbackEl = props.fallback();
|
|
262
|
+
const wrapper = document.createElement("div");
|
|
263
|
+
wrapper.setAttribute("data-sibu-suspense-id", id);
|
|
264
|
+
wrapper.appendChild(fallbackEl);
|
|
265
|
+
const promise = props.content().then((resolvedEl) => ({
|
|
266
|
+
id,
|
|
267
|
+
html: renderToString(resolvedEl)
|
|
268
|
+
}));
|
|
269
|
+
return { element: wrapper, promise };
|
|
270
|
+
}
|
|
271
|
+
function suspenseSwapScript(id) {
|
|
272
|
+
const safeId = id.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
273
|
+
return `<script>(function(){var t=document.getElementById("sibu-resolved-${safeId}");var f=document.querySelector('[data-sibu-suspense-id="${safeId}"]');if(t&&f){while(t.firstChild)f.appendChild(t.firstChild);t.remove();f.removeAttribute("data-sibu-suspense-id");}})()</script>`;
|
|
274
|
+
}
|
|
275
|
+
async function* renderToSuspenseStream(element, pendingBoundaries = []) {
|
|
276
|
+
yield* renderToStream(element);
|
|
277
|
+
if (pendingBoundaries.length > 0) {
|
|
278
|
+
const resolved = await Promise.all(pendingBoundaries);
|
|
279
|
+
for (const { id, html: html2 } of resolved) {
|
|
280
|
+
yield `<div hidden id="sibu-resolved-${id}">${html2}</div>`;
|
|
281
|
+
yield suspenseSwapScript(id);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
var SSR_DATA_ATTR = "__SIBU_SSR_DATA__";
|
|
286
|
+
function serializeState(state) {
|
|
287
|
+
const json = JSON.stringify(state).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
288
|
+
return `<script>window.${SSR_DATA_ATTR}=${json}</script>`;
|
|
289
|
+
}
|
|
290
|
+
function deserializeState() {
|
|
291
|
+
if (typeof window === "undefined") return void 0;
|
|
292
|
+
return window[SSR_DATA_ATTR];
|
|
293
|
+
}
|
|
294
|
+
function escapeHtml(str) {
|
|
295
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
296
|
+
}
|
|
297
|
+
function escapeAttr(str) {
|
|
298
|
+
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// src/reactivity/track.ts
|
|
302
|
+
var subscriberStack = [];
|
|
303
|
+
var currentSubscriber = null;
|
|
304
|
+
var signalSubscribers = /* @__PURE__ */ new WeakMap();
|
|
305
|
+
var SUBS = "__s";
|
|
306
|
+
var notifyDepth = 0;
|
|
307
|
+
var pendingQueue = [];
|
|
308
|
+
var pendingSet = /* @__PURE__ */ new Set();
|
|
309
|
+
var suspendDepth = 0;
|
|
310
|
+
var trackingSuspended = false;
|
|
311
|
+
function track(effectFn, subscriber) {
|
|
312
|
+
if (!subscriber) subscriber = effectFn;
|
|
313
|
+
cleanup(subscriber);
|
|
314
|
+
subscriberStack.push(subscriber);
|
|
315
|
+
currentSubscriber = subscriber;
|
|
316
|
+
effectFn();
|
|
317
|
+
subscriberStack.pop();
|
|
318
|
+
currentSubscriber = subscriberStack[subscriberStack.length - 1] || null;
|
|
319
|
+
return () => cleanup(subscriber);
|
|
320
|
+
}
|
|
321
|
+
function suspendTracking() {
|
|
322
|
+
if (suspendDepth === 0) {
|
|
323
|
+
subscriberStack.push(null);
|
|
324
|
+
currentSubscriber = null;
|
|
325
|
+
trackingSuspended = true;
|
|
326
|
+
}
|
|
327
|
+
suspendDepth++;
|
|
328
|
+
}
|
|
329
|
+
function resumeTracking() {
|
|
330
|
+
suspendDepth--;
|
|
331
|
+
if (suspendDepth === 0) {
|
|
332
|
+
subscriberStack.pop();
|
|
333
|
+
currentSubscriber = subscriberStack[subscriberStack.length - 1] || null;
|
|
334
|
+
trackingSuspended = false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function recordDependency(signal2) {
|
|
338
|
+
if (!currentSubscriber) return;
|
|
339
|
+
let deps = currentSubscriber._deps;
|
|
340
|
+
if (!deps) {
|
|
341
|
+
deps = /* @__PURE__ */ new Set();
|
|
342
|
+
currentSubscriber._deps = deps;
|
|
343
|
+
}
|
|
344
|
+
if (!deps.has(signal2)) {
|
|
345
|
+
deps.add(signal2);
|
|
346
|
+
let subs = signal2[SUBS];
|
|
347
|
+
if (!subs) {
|
|
348
|
+
subs = /* @__PURE__ */ new Set();
|
|
349
|
+
signalSubscribers.set(signal2, subs);
|
|
350
|
+
signal2[SUBS] = subs;
|
|
351
|
+
}
|
|
352
|
+
subs.add(currentSubscriber);
|
|
353
|
+
if (subs.size === 1) {
|
|
354
|
+
signal2.__f = currentSubscriber;
|
|
355
|
+
} else if (signal2.__f !== void 0) {
|
|
356
|
+
signal2.__f = void 0;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function queueSignalNotification(signal2) {
|
|
361
|
+
const subs = signal2[SUBS];
|
|
362
|
+
if (!subs) return;
|
|
363
|
+
for (const sub2 of subs) {
|
|
364
|
+
if (sub2._c) {
|
|
365
|
+
propagateDirty(sub2);
|
|
366
|
+
} else if (!pendingSet.has(sub2)) {
|
|
367
|
+
pendingSet.add(sub2);
|
|
368
|
+
pendingQueue.push(sub2);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function drainNotificationQueue() {
|
|
373
|
+
if (notifyDepth > 0) return;
|
|
374
|
+
notifyDepth++;
|
|
375
|
+
try {
|
|
376
|
+
let i2 = 0;
|
|
377
|
+
while (i2 < pendingQueue.length) {
|
|
378
|
+
pendingQueue[i2]();
|
|
379
|
+
i2++;
|
|
380
|
+
}
|
|
381
|
+
} finally {
|
|
382
|
+
pendingQueue.length = 0;
|
|
383
|
+
pendingSet.clear();
|
|
384
|
+
notifyDepth--;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function propagateDirty(sub2) {
|
|
388
|
+
sub2();
|
|
389
|
+
let sig = sub2._sig;
|
|
390
|
+
let suspended = false;
|
|
391
|
+
if (sig && sig._g) {
|
|
392
|
+
const sDeps = sub2._deps;
|
|
393
|
+
if (sDeps && sDeps.size === 1) {
|
|
394
|
+
suspendTracking();
|
|
395
|
+
suspended = true;
|
|
396
|
+
const s2 = sig;
|
|
397
|
+
s2._d = false;
|
|
398
|
+
s2._v = s2._g();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
while (sig) {
|
|
402
|
+
const first = sig.__f;
|
|
403
|
+
if (first) {
|
|
404
|
+
if (first._c) {
|
|
405
|
+
const nSig = first._sig;
|
|
406
|
+
nSig._d = true;
|
|
407
|
+
if (suspended && nSig._g) {
|
|
408
|
+
const fDeps = first._deps;
|
|
409
|
+
if (fDeps && fDeps.size === 1) {
|
|
410
|
+
nSig._d = false;
|
|
411
|
+
nSig._v = nSig._g();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
sig = nSig;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (!pendingSet.has(first)) {
|
|
418
|
+
pendingSet.add(first);
|
|
419
|
+
pendingQueue.push(first);
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
const subs = sig[SUBS];
|
|
424
|
+
if (!subs) break;
|
|
425
|
+
let nextSig;
|
|
426
|
+
for (const s2 of subs) {
|
|
427
|
+
if (s2._c) {
|
|
428
|
+
s2();
|
|
429
|
+
const nSig = s2._sig;
|
|
430
|
+
if (nSig && !nextSig) {
|
|
431
|
+
nextSig = nSig;
|
|
432
|
+
} else if (nSig) {
|
|
433
|
+
propagateDirty(s2);
|
|
434
|
+
}
|
|
435
|
+
} else if (!pendingSet.has(s2)) {
|
|
436
|
+
pendingSet.add(s2);
|
|
437
|
+
pendingQueue.push(s2);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
sig = nextSig;
|
|
441
|
+
}
|
|
442
|
+
if (suspended) resumeTracking();
|
|
443
|
+
}
|
|
444
|
+
function notifySubscribers(signal2) {
|
|
445
|
+
const first = signal2.__f;
|
|
446
|
+
if (first) {
|
|
447
|
+
if (notifyDepth > 0) {
|
|
448
|
+
if (first._c) {
|
|
449
|
+
propagateDirty(first);
|
|
450
|
+
} else if (!pendingSet.has(first)) {
|
|
451
|
+
pendingSet.add(first);
|
|
452
|
+
pendingQueue.push(first);
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
notifyDepth++;
|
|
457
|
+
try {
|
|
458
|
+
if (first._c) {
|
|
459
|
+
propagateDirty(first);
|
|
460
|
+
} else {
|
|
461
|
+
first();
|
|
462
|
+
}
|
|
463
|
+
let i2 = 0;
|
|
464
|
+
while (i2 < pendingQueue.length) {
|
|
465
|
+
pendingQueue[i2]();
|
|
466
|
+
i2++;
|
|
467
|
+
}
|
|
468
|
+
} finally {
|
|
469
|
+
pendingQueue.length = 0;
|
|
470
|
+
pendingSet.clear();
|
|
471
|
+
notifyDepth--;
|
|
472
|
+
}
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const subs = signal2[SUBS];
|
|
476
|
+
if (!subs || subs.size === 0) return;
|
|
477
|
+
if (notifyDepth > 0) {
|
|
478
|
+
for (const sub2 of subs) {
|
|
479
|
+
if (sub2._c) {
|
|
480
|
+
propagateDirty(sub2);
|
|
481
|
+
} else if (!pendingSet.has(sub2)) {
|
|
482
|
+
pendingSet.add(sub2);
|
|
483
|
+
pendingQueue.push(sub2);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
notifyDepth++;
|
|
489
|
+
try {
|
|
490
|
+
let directCount = 0;
|
|
491
|
+
for (const sub2 of subs) {
|
|
492
|
+
pendingQueue[directCount++] = sub2;
|
|
493
|
+
}
|
|
494
|
+
for (let i3 = 0; i3 < directCount; i3++) {
|
|
495
|
+
if (pendingQueue[i3]._c) {
|
|
496
|
+
propagateDirty(pendingQueue[i3]);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
for (let i3 = 0; i3 < directCount; i3++) {
|
|
500
|
+
if (!pendingQueue[i3]._c) {
|
|
501
|
+
if (!pendingSet.has(pendingQueue[i3])) {
|
|
502
|
+
pendingQueue[i3]();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
let i2 = directCount;
|
|
507
|
+
while (i2 < pendingQueue.length) {
|
|
508
|
+
pendingQueue[i2]();
|
|
509
|
+
i2++;
|
|
510
|
+
}
|
|
511
|
+
} finally {
|
|
512
|
+
pendingQueue.length = 0;
|
|
513
|
+
pendingSet.clear();
|
|
514
|
+
notifyDepth--;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function cleanup(subscriber) {
|
|
518
|
+
const deps = subscriber._deps;
|
|
519
|
+
if (!deps || deps.size === 0) return;
|
|
520
|
+
for (const signal2 of deps) {
|
|
521
|
+
const subs = signal2[SUBS];
|
|
522
|
+
if (subs) {
|
|
523
|
+
subs.delete(subscriber);
|
|
524
|
+
if (signal2.__f === subscriber) {
|
|
525
|
+
signal2.__f = void 0;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
deps.clear();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// src/core/dev.ts
|
|
533
|
+
function isDev() {
|
|
534
|
+
return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : true;
|
|
535
|
+
}
|
|
536
|
+
function devAssert(condition, message) {
|
|
537
|
+
if (isDev() && !condition) {
|
|
538
|
+
throw new Error(`[Sibu] ${message}`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/core/ssr-context.ts
|
|
543
|
+
var ssrMode = false;
|
|
544
|
+
function isSSR() {
|
|
545
|
+
return ssrMode;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// src/core/signals/effect.ts
|
|
549
|
+
function effect(effectFn) {
|
|
550
|
+
devAssert(typeof effectFn === "function", "effect: argument must be a function.");
|
|
551
|
+
if (isSSR()) return () => {
|
|
552
|
+
};
|
|
553
|
+
let runCount = 0;
|
|
554
|
+
let cleanupHandle = () => {
|
|
555
|
+
};
|
|
556
|
+
const hook = globalThis.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
|
|
557
|
+
const subscriber = () => {
|
|
558
|
+
cleanupHandle();
|
|
559
|
+
runCount++;
|
|
560
|
+
if (hook) hook.emit("effect:run", { effectFn, runCount });
|
|
561
|
+
cleanupHandle = track(effectFn, subscriber);
|
|
562
|
+
};
|
|
563
|
+
cleanupHandle = track(effectFn, subscriber);
|
|
564
|
+
runCount = 1;
|
|
565
|
+
if (hook) hook.emit("effect:create", { effectFn });
|
|
566
|
+
return () => {
|
|
567
|
+
if (hook) hook.emit("effect:destroy", { effectFn });
|
|
568
|
+
cleanupHandle();
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/utils/sanitize.ts
|
|
573
|
+
function sanitize(value) {
|
|
574
|
+
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
575
|
+
}
|
|
576
|
+
function sanitizeUrl(url) {
|
|
577
|
+
const trimmed = url.replace(/[\x00-\x20\x7f-\x9f]+/g, "").trim();
|
|
578
|
+
if (!trimmed) return "";
|
|
579
|
+
const lower = trimmed.toLowerCase();
|
|
580
|
+
if (lower.startsWith("javascript:") || lower.startsWith("data:") || lower.startsWith("vbscript:") || lower.startsWith("blob:")) {
|
|
581
|
+
return "";
|
|
582
|
+
}
|
|
583
|
+
return trimmed;
|
|
584
|
+
}
|
|
585
|
+
var URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "cite", "poster", "background", "srcset"]);
|
|
586
|
+
function isUrlAttribute(attr) {
|
|
587
|
+
return URL_ATTRIBUTES.has(attr);
|
|
588
|
+
}
|
|
589
|
+
function sanitizeAttribute(attr, value) {
|
|
590
|
+
if (isUrlAttribute(attr)) {
|
|
591
|
+
return sanitizeUrl(value);
|
|
592
|
+
}
|
|
593
|
+
return sanitize(value);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// src/platform/head.ts
|
|
597
|
+
var HEAD_URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "content"]);
|
|
598
|
+
function sanitizeHeadAttr(key, value) {
|
|
599
|
+
if (HEAD_URL_ATTRS.has(key)) return sanitizeUrl(value);
|
|
600
|
+
return value;
|
|
601
|
+
}
|
|
602
|
+
var managedElements = [];
|
|
603
|
+
function Head(props) {
|
|
604
|
+
const anchor = document.createComment("sibu-head");
|
|
605
|
+
const cleanup2 = () => {
|
|
606
|
+
for (const el of managedElements) {
|
|
607
|
+
if (el.parentNode) el.parentNode.removeChild(el);
|
|
608
|
+
}
|
|
609
|
+
managedElements.length = 0;
|
|
610
|
+
};
|
|
611
|
+
const apply = () => {
|
|
612
|
+
cleanup2();
|
|
613
|
+
if (props.title) {
|
|
614
|
+
if (typeof props.title === "function") {
|
|
615
|
+
effect(() => {
|
|
616
|
+
document.title = props.title();
|
|
617
|
+
});
|
|
618
|
+
} else {
|
|
619
|
+
document.title = props.title;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (props.meta) {
|
|
623
|
+
for (const metaProps of props.meta) {
|
|
624
|
+
const el = document.createElement("meta");
|
|
625
|
+
for (const [key, value] of Object.entries(metaProps)) {
|
|
626
|
+
if (typeof value === "function") {
|
|
627
|
+
effect(() => {
|
|
628
|
+
el.setAttribute(key, value());
|
|
629
|
+
});
|
|
630
|
+
} else {
|
|
631
|
+
el.setAttribute(key, value);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
document.head.appendChild(el);
|
|
635
|
+
managedElements.push(el);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (props.link) {
|
|
639
|
+
for (const linkProps of props.link) {
|
|
640
|
+
const el = document.createElement("link");
|
|
641
|
+
for (const [key, value] of Object.entries(linkProps)) {
|
|
642
|
+
el.setAttribute(key, sanitizeHeadAttr(key, value));
|
|
643
|
+
}
|
|
644
|
+
document.head.appendChild(el);
|
|
645
|
+
managedElements.push(el);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (props.script) {
|
|
649
|
+
for (const scriptProps of props.script) {
|
|
650
|
+
const el = document.createElement("script");
|
|
651
|
+
for (const [key, value] of Object.entries(scriptProps)) {
|
|
652
|
+
el.setAttribute(key, sanitizeHeadAttr(key, value));
|
|
653
|
+
}
|
|
654
|
+
document.head.appendChild(el);
|
|
655
|
+
managedElements.push(el);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (props.base) {
|
|
659
|
+
const existing = document.head.querySelector("base");
|
|
660
|
+
if (existing) existing.remove();
|
|
661
|
+
const el = document.createElement("base");
|
|
662
|
+
if (props.base.href) el.href = props.base.href;
|
|
663
|
+
if (props.base.target) el.target = props.base.target;
|
|
664
|
+
document.head.appendChild(el);
|
|
665
|
+
managedElements.push(el);
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
apply();
|
|
669
|
+
return anchor;
|
|
670
|
+
}
|
|
671
|
+
function setStructuredData(data2) {
|
|
672
|
+
const existing = document.head.querySelector('script[type="application/ld+json"][data-sibu]');
|
|
673
|
+
if (existing) existing.remove();
|
|
674
|
+
const script2 = document.createElement("script");
|
|
675
|
+
script2.type = "application/ld+json";
|
|
676
|
+
script2.setAttribute("data-sibu", "true");
|
|
677
|
+
script2.textContent = JSON.stringify(data2);
|
|
678
|
+
document.head.appendChild(script2);
|
|
679
|
+
managedElements.push(script2);
|
|
680
|
+
}
|
|
681
|
+
function setCanonical(url) {
|
|
682
|
+
let link2 = document.head.querySelector('link[rel="canonical"]');
|
|
683
|
+
if (!link2) {
|
|
684
|
+
link2 = document.createElement("link");
|
|
685
|
+
link2.rel = "canonical";
|
|
686
|
+
document.head.appendChild(link2);
|
|
687
|
+
managedElements.push(link2);
|
|
688
|
+
}
|
|
689
|
+
link2.href = sanitizeUrl(url);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// src/platform/staticSiteGenerator.ts
|
|
693
|
+
async function generateStaticSite(options) {
|
|
694
|
+
const { routes, renderFn } = options;
|
|
695
|
+
const pages = [];
|
|
696
|
+
const errors = [];
|
|
697
|
+
for (const route of routes) {
|
|
698
|
+
try {
|
|
699
|
+
const html2 = await renderFn(route);
|
|
700
|
+
pages.push({ path: route, html: html2 });
|
|
701
|
+
} catch (err) {
|
|
702
|
+
errors.push({
|
|
703
|
+
path: route,
|
|
704
|
+
error: err instanceof Error ? err : new Error(String(err))
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return { pages, errors };
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/reactivity/batch.ts
|
|
712
|
+
var batchDepth = 0;
|
|
713
|
+
var pendingSignals = /* @__PURE__ */ new Set();
|
|
714
|
+
function batch(fn) {
|
|
715
|
+
batchDepth++;
|
|
716
|
+
try {
|
|
717
|
+
fn();
|
|
718
|
+
} finally {
|
|
719
|
+
batchDepth--;
|
|
720
|
+
if (batchDepth === 0) {
|
|
721
|
+
flushBatch();
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
function enqueueBatchedSignal(signal2) {
|
|
726
|
+
if (batchDepth === 0) return false;
|
|
727
|
+
pendingSignals.add(signal2);
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
function flushBatch() {
|
|
731
|
+
const signals = Array.from(pendingSignals);
|
|
732
|
+
pendingSignals.clear();
|
|
733
|
+
for (const signal2 of signals) {
|
|
734
|
+
queueSignalNotification(signal2);
|
|
735
|
+
}
|
|
736
|
+
drainNotificationQueue();
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// src/core/signals/signal.ts
|
|
740
|
+
function signal(initial, options) {
|
|
741
|
+
const state = { value: initial };
|
|
742
|
+
const debugName = options?.name;
|
|
743
|
+
if (debugName) {
|
|
744
|
+
state.__name = debugName;
|
|
745
|
+
}
|
|
746
|
+
function get() {
|
|
747
|
+
recordDependency(state);
|
|
748
|
+
return state.value;
|
|
749
|
+
}
|
|
750
|
+
get.__signal = state;
|
|
751
|
+
if (debugName) get.__name = debugName;
|
|
752
|
+
function set(next) {
|
|
753
|
+
const newValue = typeof next === "function" ? next(state.value) : next;
|
|
754
|
+
if (Object.is(newValue, state.value)) return;
|
|
755
|
+
const oldValue = state.value;
|
|
756
|
+
state.value = newValue;
|
|
757
|
+
const hook2 = globalThis.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
|
|
758
|
+
if (hook2) hook2.emit("signal:update", { signal: state, name: debugName, oldValue, newValue });
|
|
759
|
+
if (!enqueueBatchedSignal(state)) {
|
|
760
|
+
notifySubscribers(state);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const hook = globalThis.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
|
|
764
|
+
if (hook) hook.emit("signal:create", { signal: state, name: debugName, getter: get, initial });
|
|
765
|
+
return [get, set];
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/platform/incrementalRegeneration.ts
|
|
769
|
+
function createISR(options) {
|
|
770
|
+
const { revalidateAfter, fetcher, initialData } = options;
|
|
771
|
+
const [data2, setData] = signal(initialData);
|
|
772
|
+
const [timestamp, setTimestamp] = signal(initialData !== void 0 ? Date.now() : 0);
|
|
773
|
+
const isStale = () => {
|
|
774
|
+
const ts = timestamp();
|
|
775
|
+
if (ts === 0) return true;
|
|
776
|
+
return Date.now() - ts >= revalidateAfter;
|
|
777
|
+
};
|
|
778
|
+
const revalidate = async () => {
|
|
779
|
+
const result = await fetcher();
|
|
780
|
+
setData(result);
|
|
781
|
+
setTimestamp(Date.now());
|
|
782
|
+
};
|
|
783
|
+
if (initialData === void 0) {
|
|
784
|
+
revalidate();
|
|
785
|
+
}
|
|
786
|
+
const intervalId = setInterval(() => {
|
|
787
|
+
revalidate();
|
|
788
|
+
}, revalidateAfter);
|
|
789
|
+
const dispose = () => {
|
|
790
|
+
clearInterval(intervalId);
|
|
791
|
+
};
|
|
792
|
+
return { data: data2, isStale, revalidate, dispose };
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/platform/routeActions.ts
|
|
796
|
+
function createAction(actionFn) {
|
|
797
|
+
const [data2, setData] = signal(void 0);
|
|
798
|
+
const [error, setError] = signal(void 0);
|
|
799
|
+
const [loading, setLoading] = signal(false);
|
|
800
|
+
const submit = async (input2) => {
|
|
801
|
+
batch(() => {
|
|
802
|
+
setLoading(true);
|
|
803
|
+
setError(void 0);
|
|
804
|
+
});
|
|
805
|
+
try {
|
|
806
|
+
const result = await actionFn(input2);
|
|
807
|
+
batch(() => {
|
|
808
|
+
setData(result);
|
|
809
|
+
setLoading(false);
|
|
810
|
+
});
|
|
811
|
+
return result;
|
|
812
|
+
} catch (err) {
|
|
813
|
+
const actionError = err instanceof Error ? err : new Error(String(err));
|
|
814
|
+
batch(() => {
|
|
815
|
+
setError(actionError);
|
|
816
|
+
setLoading(false);
|
|
817
|
+
});
|
|
818
|
+
throw actionError;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
return { data: data2, error, loading, submit };
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// src/platform/scrollRestoration.ts
|
|
825
|
+
function scrollRestoration(options) {
|
|
826
|
+
const mode = options?.mode ?? "auto";
|
|
827
|
+
const positions = /* @__PURE__ */ new Map();
|
|
828
|
+
let popstateHandler = null;
|
|
829
|
+
let currentKey = null;
|
|
830
|
+
const save = (key) => {
|
|
831
|
+
positions.set(key, {
|
|
832
|
+
x: window.scrollX,
|
|
833
|
+
y: window.scrollY
|
|
834
|
+
});
|
|
835
|
+
currentKey = key;
|
|
836
|
+
};
|
|
837
|
+
const restore = (key) => {
|
|
838
|
+
const pos = positions.get(key);
|
|
839
|
+
if (pos) {
|
|
840
|
+
window.scrollTo(pos.x, pos.y);
|
|
841
|
+
}
|
|
842
|
+
currentKey = key;
|
|
843
|
+
};
|
|
844
|
+
const getPosition = (key) => {
|
|
845
|
+
return positions.get(key);
|
|
846
|
+
};
|
|
847
|
+
if (mode === "auto") {
|
|
848
|
+
popstateHandler = () => {
|
|
849
|
+
if (currentKey) {
|
|
850
|
+
save(currentKey);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
window.addEventListener("popstate", popstateHandler);
|
|
854
|
+
}
|
|
855
|
+
const dispose = () => {
|
|
856
|
+
if (popstateHandler) {
|
|
857
|
+
window.removeEventListener("popstate", popstateHandler);
|
|
858
|
+
popstateHandler = null;
|
|
859
|
+
}
|
|
860
|
+
positions.clear();
|
|
861
|
+
};
|
|
862
|
+
return { save, restore, getPosition, dispose };
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// src/platform/routeMiddleware.ts
|
|
866
|
+
function composeMiddleware(...fns) {
|
|
867
|
+
return async (context, next) => {
|
|
868
|
+
let index = -1;
|
|
869
|
+
const dispatch = async (i2) => {
|
|
870
|
+
if (i2 <= index) {
|
|
871
|
+
throw new Error("next() called multiple times");
|
|
872
|
+
}
|
|
873
|
+
index = i2;
|
|
874
|
+
if (i2 < fns.length) {
|
|
875
|
+
await fns[i2](context, () => dispatch(i2 + 1));
|
|
876
|
+
} else {
|
|
877
|
+
await next();
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
await dispatch(0);
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function createMiddlewareChain() {
|
|
884
|
+
const middlewares = [];
|
|
885
|
+
const use2 = (fn) => {
|
|
886
|
+
middlewares.push(fn);
|
|
887
|
+
};
|
|
888
|
+
const run = async (context) => {
|
|
889
|
+
const composed = composeMiddleware(...middlewares);
|
|
890
|
+
await composed(context, () => {
|
|
891
|
+
});
|
|
892
|
+
};
|
|
893
|
+
return { use: use2, run };
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// src/reactivity/bindAttribute.ts
|
|
897
|
+
function bindAttribute(el, attr, getter) {
|
|
898
|
+
function commit() {
|
|
899
|
+
let value;
|
|
900
|
+
try {
|
|
901
|
+
value = getter();
|
|
902
|
+
} catch {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (typeof value === "boolean") {
|
|
906
|
+
if (attr in el && (attr === "checked" || attr === "disabled" || attr === "selected")) {
|
|
907
|
+
el[attr] = value;
|
|
908
|
+
} else if (value) {
|
|
909
|
+
el.setAttribute(attr, "");
|
|
910
|
+
} else {
|
|
911
|
+
el.removeAttribute(attr);
|
|
912
|
+
}
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
const str = sanitizeAttribute(attr, String(value));
|
|
916
|
+
if ((attr === "value" || attr === "checked") && attr in el) {
|
|
917
|
+
el[attr] = attr === "checked" ? Boolean(value) : str;
|
|
918
|
+
} else {
|
|
919
|
+
el.setAttribute(attr, str);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
const teardown = track(commit);
|
|
923
|
+
return teardown;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// src/reactivity/bindChildNode.ts
|
|
927
|
+
function bindChildNode(placeholder, getter) {
|
|
928
|
+
let lastNodes = [];
|
|
929
|
+
function commit() {
|
|
930
|
+
let result;
|
|
931
|
+
try {
|
|
932
|
+
result = getter();
|
|
933
|
+
} catch {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
for (const node of lastNodes) {
|
|
937
|
+
node.parentNode?.removeChild(node);
|
|
938
|
+
}
|
|
939
|
+
lastNodes = [];
|
|
940
|
+
if (result == null) return;
|
|
941
|
+
const parent = placeholder.parentNode;
|
|
942
|
+
if (!parent) return;
|
|
943
|
+
const anchor = placeholder.nextSibling;
|
|
944
|
+
const newNodes = [];
|
|
945
|
+
const insertItem = (item) => {
|
|
946
|
+
const node = item instanceof Node ? item : document.createTextNode(String(item));
|
|
947
|
+
parent.insertBefore(node, anchor);
|
|
948
|
+
newNodes.push(node);
|
|
949
|
+
};
|
|
950
|
+
if (Array.isArray(result)) {
|
|
951
|
+
for (const item of result) insertItem(item);
|
|
952
|
+
} else {
|
|
953
|
+
insertItem(result);
|
|
954
|
+
}
|
|
955
|
+
lastNodes = newNodes;
|
|
956
|
+
}
|
|
957
|
+
return track(commit);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
// src/core/rendering/dispose.ts
|
|
961
|
+
var elementDisposers = /* @__PURE__ */ new WeakMap();
|
|
962
|
+
var activeBindingCount = 0;
|
|
963
|
+
function registerDisposer(node, teardown) {
|
|
964
|
+
let disposers = elementDisposers.get(node);
|
|
965
|
+
if (!disposers) {
|
|
966
|
+
disposers = [];
|
|
967
|
+
elementDisposers.set(node, disposers);
|
|
968
|
+
}
|
|
969
|
+
disposers.push(teardown);
|
|
970
|
+
activeBindingCount++;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// src/core/rendering/tagFactory.ts
|
|
974
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
975
|
+
var kebabCache = /* @__PURE__ */ new Map();
|
|
976
|
+
function toKebab(prop) {
|
|
977
|
+
let cached = kebabCache.get(prop);
|
|
978
|
+
if (cached !== void 0) return cached;
|
|
979
|
+
cached = prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
980
|
+
kebabCache.set(prop, cached);
|
|
981
|
+
return cached;
|
|
982
|
+
}
|
|
983
|
+
function applyStyle(el, style2) {
|
|
984
|
+
if (!style2) return;
|
|
985
|
+
if (typeof style2 === "function") {
|
|
986
|
+
const teardown = track(() => {
|
|
987
|
+
el.setAttribute("style", style2());
|
|
988
|
+
});
|
|
989
|
+
registerDisposer(el, teardown);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (typeof style2 === "string") {
|
|
993
|
+
el.setAttribute("style", style2);
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
const htmlEl = el;
|
|
997
|
+
for (const prop in style2) {
|
|
998
|
+
const val = style2[prop];
|
|
999
|
+
const name = toKebab(prop);
|
|
1000
|
+
if (typeof val === "function") {
|
|
1001
|
+
const getter = val;
|
|
1002
|
+
const teardown = track(() => {
|
|
1003
|
+
htmlEl.style.setProperty(name, String(getter()));
|
|
1004
|
+
});
|
|
1005
|
+
registerDisposer(el, teardown);
|
|
1006
|
+
} else {
|
|
1007
|
+
htmlEl.style.setProperty(name, String(val));
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function applyClass(el, cls) {
|
|
1012
|
+
if (cls == null) return;
|
|
1013
|
+
if (typeof cls === "string") {
|
|
1014
|
+
el.setAttribute("class", cls);
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (typeof cls === "function") {
|
|
1018
|
+
const getter = cls;
|
|
1019
|
+
const teardown = track(() => {
|
|
1020
|
+
el.setAttribute("class", getter());
|
|
1021
|
+
});
|
|
1022
|
+
registerDisposer(el, teardown);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (typeof cls === "object") {
|
|
1026
|
+
const obj = cls;
|
|
1027
|
+
let hasReactive = false;
|
|
1028
|
+
for (const name in obj) {
|
|
1029
|
+
if (typeof obj[name] === "function") {
|
|
1030
|
+
hasReactive = true;
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
if (hasReactive) {
|
|
1035
|
+
const update = () => {
|
|
1036
|
+
let result = "";
|
|
1037
|
+
for (const name in obj) {
|
|
1038
|
+
const val = obj[name];
|
|
1039
|
+
const active = typeof val === "function" ? val() : val;
|
|
1040
|
+
if (active) result = result ? `${result} ${name}` : name;
|
|
1041
|
+
}
|
|
1042
|
+
el.setAttribute("class", result);
|
|
1043
|
+
};
|
|
1044
|
+
const teardown = track(update);
|
|
1045
|
+
registerDisposer(el, teardown);
|
|
1046
|
+
} else {
|
|
1047
|
+
let result = "";
|
|
1048
|
+
for (const name in obj) {
|
|
1049
|
+
if (obj[name]) result = result ? `${result} ${name}` : name;
|
|
1050
|
+
}
|
|
1051
|
+
el.setAttribute("class", result);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
function renderChild(child) {
|
|
1056
|
+
if (child == null) {
|
|
1057
|
+
return document.createTextNode("");
|
|
1058
|
+
}
|
|
1059
|
+
if (child instanceof Node) {
|
|
1060
|
+
return child;
|
|
1061
|
+
}
|
|
1062
|
+
return document.createTextNode(String(child));
|
|
1063
|
+
}
|
|
1064
|
+
function appendOneChild(el, child) {
|
|
1065
|
+
if (typeof child === "function") {
|
|
1066
|
+
const placeholder = document.createComment("bind:child");
|
|
1067
|
+
el.appendChild(placeholder);
|
|
1068
|
+
const teardown = bindChildNode(placeholder, child);
|
|
1069
|
+
registerDisposer(el, teardown);
|
|
1070
|
+
} else {
|
|
1071
|
+
el.appendChild(renderChild(child));
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
function appendChildren(el, nodes) {
|
|
1075
|
+
if (Array.isArray(nodes)) {
|
|
1076
|
+
for (let i2 = 0; i2 < nodes.length; i2++) {
|
|
1077
|
+
const c = nodes[i2];
|
|
1078
|
+
if (Array.isArray(c)) {
|
|
1079
|
+
for (let j = 0; j < c.length; j++) {
|
|
1080
|
+
appendOneChild(el, c[j]);
|
|
1081
|
+
}
|
|
1082
|
+
} else {
|
|
1083
|
+
appendOneChild(el, c);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
} else {
|
|
1087
|
+
appendOneChild(el, nodes);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
function isTagProps(value) {
|
|
1091
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Node);
|
|
1092
|
+
}
|
|
1093
|
+
var tagFactory = (tag, ns) => (first, second) => {
|
|
1094
|
+
let props;
|
|
1095
|
+
if (first === void 0) {
|
|
1096
|
+
props = {};
|
|
1097
|
+
} else if (isTagProps(first)) {
|
|
1098
|
+
props = first;
|
|
1099
|
+
} else if (second !== void 0) {
|
|
1100
|
+
props = { class: first, nodes: second };
|
|
1101
|
+
} else {
|
|
1102
|
+
props = { nodes: first };
|
|
1103
|
+
}
|
|
1104
|
+
const el = ns ? document.createElementNS(ns, tag) : document.createElement(tag);
|
|
1105
|
+
for (const key in props) {
|
|
1106
|
+
const value = props[key];
|
|
1107
|
+
if (value == null) continue;
|
|
1108
|
+
switch (key) {
|
|
1109
|
+
case "id":
|
|
1110
|
+
el.id = value;
|
|
1111
|
+
break;
|
|
1112
|
+
case "class":
|
|
1113
|
+
applyClass(el, value);
|
|
1114
|
+
break;
|
|
1115
|
+
case "style":
|
|
1116
|
+
applyStyle(el, value);
|
|
1117
|
+
break;
|
|
1118
|
+
case "ref":
|
|
1119
|
+
if (value && typeof value === "object" && "current" in value) {
|
|
1120
|
+
value.current = el;
|
|
1121
|
+
}
|
|
1122
|
+
break;
|
|
1123
|
+
case "on": {
|
|
1124
|
+
const handlers = value;
|
|
1125
|
+
const eventNames = [];
|
|
1126
|
+
for (const ev in handlers) {
|
|
1127
|
+
el.addEventListener(ev, handlers[ev]);
|
|
1128
|
+
eventNames.push(ev);
|
|
1129
|
+
}
|
|
1130
|
+
if (eventNames.length) {
|
|
1131
|
+
el.__sibu_events__ = eventNames;
|
|
1132
|
+
}
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
case "nodes":
|
|
1136
|
+
appendChildren(el, value);
|
|
1137
|
+
break;
|
|
1138
|
+
default:
|
|
1139
|
+
if (key.toLowerCase().startsWith("on")) break;
|
|
1140
|
+
if (typeof value === "function") {
|
|
1141
|
+
const teardown = bindAttribute(el, key, value);
|
|
1142
|
+
registerDisposer(el, teardown);
|
|
1143
|
+
} else if (typeof value === "boolean") {
|
|
1144
|
+
if (value) el.setAttribute(key, "");
|
|
1145
|
+
else el.removeAttribute(key);
|
|
1146
|
+
} else {
|
|
1147
|
+
el.setAttribute(key, sanitizeAttribute(key, String(value)));
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return el;
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
// src/core/rendering/html.ts
|
|
1155
|
+
var html = tagFactory("html");
|
|
1156
|
+
var head = tagFactory("head");
|
|
1157
|
+
var body = tagFactory("body");
|
|
1158
|
+
var title = tagFactory("title");
|
|
1159
|
+
var div = tagFactory("div");
|
|
1160
|
+
var span = tagFactory("span");
|
|
1161
|
+
var section = tagFactory("section");
|
|
1162
|
+
var article = tagFactory("article");
|
|
1163
|
+
var header = tagFactory("header");
|
|
1164
|
+
var footer = tagFactory("footer");
|
|
1165
|
+
var nav = tagFactory("nav");
|
|
1166
|
+
var main = tagFactory("main");
|
|
1167
|
+
var aside = tagFactory("aside");
|
|
1168
|
+
var address = tagFactory("address");
|
|
1169
|
+
var p = tagFactory("p");
|
|
1170
|
+
var h1 = tagFactory("h1");
|
|
1171
|
+
var h2 = tagFactory("h2");
|
|
1172
|
+
var h3 = tagFactory("h3");
|
|
1173
|
+
var h4 = tagFactory("h4");
|
|
1174
|
+
var h5 = tagFactory("h5");
|
|
1175
|
+
var h6 = tagFactory("h6");
|
|
1176
|
+
var blockquote = tagFactory("blockquote");
|
|
1177
|
+
var dd = tagFactory("dd");
|
|
1178
|
+
var dl = tagFactory("dl");
|
|
1179
|
+
var dt = tagFactory("dt");
|
|
1180
|
+
var figcaption = tagFactory("figcaption");
|
|
1181
|
+
var figure = tagFactory("figure");
|
|
1182
|
+
var hr = tagFactory("hr");
|
|
1183
|
+
var li = tagFactory("li");
|
|
1184
|
+
var ol = tagFactory("ol");
|
|
1185
|
+
var ul = tagFactory("ul");
|
|
1186
|
+
var pre = tagFactory("pre");
|
|
1187
|
+
var a = tagFactory("a");
|
|
1188
|
+
var abbr = tagFactory("abbr");
|
|
1189
|
+
var b = tagFactory("b");
|
|
1190
|
+
var bdi = tagFactory("bdi");
|
|
1191
|
+
var bdo = tagFactory("bdo");
|
|
1192
|
+
var br = tagFactory("br");
|
|
1193
|
+
var cite = tagFactory("cite");
|
|
1194
|
+
var code = tagFactory("code");
|
|
1195
|
+
var data = tagFactory("data");
|
|
1196
|
+
var dfn = tagFactory("dfn");
|
|
1197
|
+
var em = tagFactory("em");
|
|
1198
|
+
var i = tagFactory("i");
|
|
1199
|
+
var kbd = tagFactory("kbd");
|
|
1200
|
+
var mark = tagFactory("mark");
|
|
1201
|
+
var q = tagFactory("q");
|
|
1202
|
+
var rp = tagFactory("rp");
|
|
1203
|
+
var rt = tagFactory("rt");
|
|
1204
|
+
var ruby = tagFactory("ruby");
|
|
1205
|
+
var s = tagFactory("s");
|
|
1206
|
+
var samp = tagFactory("samp");
|
|
1207
|
+
var small = tagFactory("small");
|
|
1208
|
+
var strong = tagFactory("strong");
|
|
1209
|
+
var sub = tagFactory("sub");
|
|
1210
|
+
var sup = tagFactory("sup");
|
|
1211
|
+
var time = tagFactory("time");
|
|
1212
|
+
var u = tagFactory("u");
|
|
1213
|
+
var var_ = tagFactory("var");
|
|
1214
|
+
var area = tagFactory("area");
|
|
1215
|
+
var audio = tagFactory("audio");
|
|
1216
|
+
var img = tagFactory("img");
|
|
1217
|
+
var map = tagFactory("map");
|
|
1218
|
+
var track2 = tagFactory("track");
|
|
1219
|
+
var video = tagFactory("video");
|
|
1220
|
+
var embed = tagFactory("embed");
|
|
1221
|
+
var iframe = tagFactory("iframe");
|
|
1222
|
+
var object = tagFactory("object");
|
|
1223
|
+
var param = tagFactory("param");
|
|
1224
|
+
var picture = tagFactory("picture");
|
|
1225
|
+
var portal = tagFactory("portal");
|
|
1226
|
+
var source = tagFactory("source");
|
|
1227
|
+
var svg = tagFactory("svg", SVG_NS);
|
|
1228
|
+
var math = tagFactory("math");
|
|
1229
|
+
var canvas = tagFactory("canvas");
|
|
1230
|
+
var noscript = tagFactory("noscript");
|
|
1231
|
+
var script = tagFactory("script");
|
|
1232
|
+
var del = tagFactory("del");
|
|
1233
|
+
var ins = tagFactory("ins");
|
|
1234
|
+
var caption = tagFactory("caption");
|
|
1235
|
+
var col = tagFactory("col");
|
|
1236
|
+
var colgroup = tagFactory("colgroup");
|
|
1237
|
+
var table = tagFactory("table");
|
|
1238
|
+
var tbody = tagFactory("tbody");
|
|
1239
|
+
var td = tagFactory("td");
|
|
1240
|
+
var tfoot = tagFactory("tfoot");
|
|
1241
|
+
var th = tagFactory("th");
|
|
1242
|
+
var thead = tagFactory("thead");
|
|
1243
|
+
var tr = tagFactory("tr");
|
|
1244
|
+
var button = tagFactory("button");
|
|
1245
|
+
var datalist = tagFactory("datalist");
|
|
1246
|
+
var fieldset = tagFactory("fieldset");
|
|
1247
|
+
var form = tagFactory("form");
|
|
1248
|
+
var input = tagFactory("input");
|
|
1249
|
+
var label = tagFactory("label");
|
|
1250
|
+
var legend = tagFactory("legend");
|
|
1251
|
+
var meter = tagFactory("meter");
|
|
1252
|
+
var optgroup = tagFactory("optgroup");
|
|
1253
|
+
var option = tagFactory("option");
|
|
1254
|
+
var output = tagFactory("output");
|
|
1255
|
+
var progress = tagFactory("progress");
|
|
1256
|
+
var select = tagFactory("select");
|
|
1257
|
+
var textarea = tagFactory("textarea");
|
|
1258
|
+
var details = tagFactory("details");
|
|
1259
|
+
var dialog = tagFactory("dialog");
|
|
1260
|
+
var menu = tagFactory("menu");
|
|
1261
|
+
var summary = tagFactory("summary");
|
|
1262
|
+
var slot = tagFactory("slot");
|
|
1263
|
+
var template = tagFactory("template");
|
|
1264
|
+
var base = tagFactory("base");
|
|
1265
|
+
var link = tagFactory("link");
|
|
1266
|
+
var meta = tagFactory("meta");
|
|
1267
|
+
var style = tagFactory("style");
|
|
1268
|
+
var circle = tagFactory("circle", SVG_NS);
|
|
1269
|
+
var ellipse = tagFactory("ellipse", SVG_NS);
|
|
1270
|
+
var g = tagFactory("g", SVG_NS);
|
|
1271
|
+
var line = tagFactory("line", SVG_NS);
|
|
1272
|
+
var path = tagFactory("path", SVG_NS);
|
|
1273
|
+
var polygon = tagFactory("polygon", SVG_NS);
|
|
1274
|
+
var polyline = tagFactory("polyline", SVG_NS);
|
|
1275
|
+
var rect = tagFactory("rect", SVG_NS);
|
|
1276
|
+
var text = tagFactory("text", SVG_NS);
|
|
1277
|
+
var tspan = tagFactory("tspan", SVG_NS);
|
|
1278
|
+
var defs = tagFactory("defs", SVG_NS);
|
|
1279
|
+
var clipPath = tagFactory("clipPath", SVG_NS);
|
|
1280
|
+
var mask = tagFactory("mask", SVG_NS);
|
|
1281
|
+
var pattern = tagFactory("pattern", SVG_NS);
|
|
1282
|
+
var linearGradient = tagFactory("linearGradient", SVG_NS);
|
|
1283
|
+
var radialGradient = tagFactory("radialGradient", SVG_NS);
|
|
1284
|
+
var stop = tagFactory("stop", SVG_NS);
|
|
1285
|
+
var use = tagFactory("use", SVG_NS);
|
|
1286
|
+
var symbol = tagFactory("symbol", SVG_NS);
|
|
1287
|
+
var marker = tagFactory("marker", SVG_NS);
|
|
1288
|
+
var center = tagFactory("center");
|
|
1289
|
+
var font = tagFactory("font");
|
|
1290
|
+
var marquee = tagFactory("marquee");
|
|
1291
|
+
|
|
1292
|
+
// src/platform/microfrontend.ts
|
|
1293
|
+
var moduleCache = /* @__PURE__ */ new Map();
|
|
1294
|
+
function createMicroApp(config) {
|
|
1295
|
+
const host = config.container ?? document.createElement("div");
|
|
1296
|
+
host.setAttribute("data-micro-app", config.name);
|
|
1297
|
+
let root;
|
|
1298
|
+
if (config.shadow) {
|
|
1299
|
+
root = host.attachShadow({ mode: "open" });
|
|
1300
|
+
} else {
|
|
1301
|
+
root = host;
|
|
1302
|
+
}
|
|
1303
|
+
let mounted = false;
|
|
1304
|
+
function mount(component) {
|
|
1305
|
+
if (root instanceof ShadowRoot) {
|
|
1306
|
+
root.innerHTML = "";
|
|
1307
|
+
} else {
|
|
1308
|
+
while (root.firstChild) {
|
|
1309
|
+
root.removeChild(root.firstChild);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
const el = component();
|
|
1313
|
+
root.appendChild(el);
|
|
1314
|
+
mounted = true;
|
|
1315
|
+
}
|
|
1316
|
+
function unmount() {
|
|
1317
|
+
if (!mounted) return;
|
|
1318
|
+
if (root instanceof ShadowRoot) {
|
|
1319
|
+
root.innerHTML = "";
|
|
1320
|
+
} else {
|
|
1321
|
+
while (root.firstChild) {
|
|
1322
|
+
root.removeChild(root.firstChild);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
mounted = false;
|
|
1326
|
+
}
|
|
1327
|
+
return { mount, unmount, element: host };
|
|
1328
|
+
}
|
|
1329
|
+
function loadRemoteModule(url) {
|
|
1330
|
+
const cached = moduleCache.get(url);
|
|
1331
|
+
if (cached) return cached;
|
|
1332
|
+
const promise = import(
|
|
1333
|
+
/* @vite-ignore */
|
|
1334
|
+
url
|
|
1335
|
+
);
|
|
1336
|
+
moduleCache.set(url, promise);
|
|
1337
|
+
promise.catch(() => {
|
|
1338
|
+
moduleCache.delete(url);
|
|
1339
|
+
});
|
|
1340
|
+
return promise;
|
|
1341
|
+
}
|
|
1342
|
+
function defineRemoteComponent(name, loader) {
|
|
1343
|
+
let cached = null;
|
|
1344
|
+
return function RemoteComponent() {
|
|
1345
|
+
if (cached) {
|
|
1346
|
+
return cached();
|
|
1347
|
+
}
|
|
1348
|
+
const container = div({
|
|
1349
|
+
class: "sibu-remote",
|
|
1350
|
+
"data-remote-component": name
|
|
1351
|
+
});
|
|
1352
|
+
container.appendChild(span({ class: "sibu-remote-loading", nodes: "Loading..." }));
|
|
1353
|
+
loader().then((mod) => {
|
|
1354
|
+
cached = mod.default;
|
|
1355
|
+
const rendered = cached();
|
|
1356
|
+
container.replaceChildren(rendered);
|
|
1357
|
+
}).catch((err) => {
|
|
1358
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1359
|
+
container.replaceChildren(
|
|
1360
|
+
div({
|
|
1361
|
+
class: "sibu-remote-error",
|
|
1362
|
+
nodes: `Failed to load remote component "${name}": ${message}`
|
|
1363
|
+
})
|
|
1364
|
+
);
|
|
1365
|
+
});
|
|
1366
|
+
return container;
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
function createSharedScope(initialState) {
|
|
1370
|
+
const signals = /* @__PURE__ */ new Map();
|
|
1371
|
+
const subscribers = /* @__PURE__ */ new Map();
|
|
1372
|
+
for (const key of Object.keys(initialState)) {
|
|
1373
|
+
const [get2, set2] = signal(initialState[key]);
|
|
1374
|
+
signals.set(key, { get: get2, set: set2 });
|
|
1375
|
+
subscribers.set(key, /* @__PURE__ */ new Set());
|
|
1376
|
+
}
|
|
1377
|
+
function ensureSignal(key) {
|
|
1378
|
+
if (!signals.has(key)) {
|
|
1379
|
+
const [get2, set2] = signal(void 0);
|
|
1380
|
+
signals.set(key, { get: get2, set: set2 });
|
|
1381
|
+
subscribers.set(key, /* @__PURE__ */ new Set());
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
function get(key) {
|
|
1385
|
+
ensureSignal(key);
|
|
1386
|
+
return signals.get(key)?.get();
|
|
1387
|
+
}
|
|
1388
|
+
function set(key, value) {
|
|
1389
|
+
ensureSignal(key);
|
|
1390
|
+
signals.get(key)?.set(value);
|
|
1391
|
+
const subs = subscribers.get(key);
|
|
1392
|
+
if (subs) {
|
|
1393
|
+
for (const cb of subs) {
|
|
1394
|
+
cb(value);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
function subscribe(key, callback) {
|
|
1399
|
+
ensureSignal(key);
|
|
1400
|
+
const subs = subscribers.get(key);
|
|
1401
|
+
if (!subs) {
|
|
1402
|
+
return () => {
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
subs.add(callback);
|
|
1406
|
+
return () => {
|
|
1407
|
+
subs.delete(callback);
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
return { get, set, subscribe };
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
// src/platform/serviceWorker.ts
|
|
1414
|
+
function serviceWorker(scriptUrl, options) {
|
|
1415
|
+
const [registration, setRegistration] = signal(null);
|
|
1416
|
+
const [isReady, setIsReady] = signal(false);
|
|
1417
|
+
const [isUpdateAvailable, setIsUpdateAvailable] = signal(false);
|
|
1418
|
+
const [error, setError] = signal(null);
|
|
1419
|
+
if ("serviceWorker" in navigator) {
|
|
1420
|
+
navigator.serviceWorker.register(scriptUrl, options).then((reg) => {
|
|
1421
|
+
setRegistration(reg);
|
|
1422
|
+
setIsReady(true);
|
|
1423
|
+
reg.addEventListener("updatefound", () => {
|
|
1424
|
+
const newWorker = reg.installing;
|
|
1425
|
+
if (newWorker) {
|
|
1426
|
+
newWorker.addEventListener("statechange", () => {
|
|
1427
|
+
if (newWorker.state === "installed" && navigator.serviceWorker.controller) {
|
|
1428
|
+
setIsUpdateAvailable(true);
|
|
1429
|
+
}
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
}).catch((err) => {
|
|
1434
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
async function update() {
|
|
1438
|
+
const reg = registration();
|
|
1439
|
+
if (reg) {
|
|
1440
|
+
await reg.update();
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
async function unregister() {
|
|
1444
|
+
const reg = registration();
|
|
1445
|
+
if (reg) {
|
|
1446
|
+
const result = await reg.unregister();
|
|
1447
|
+
if (result) {
|
|
1448
|
+
setRegistration(null);
|
|
1449
|
+
setIsReady(false);
|
|
1450
|
+
}
|
|
1451
|
+
return result;
|
|
1452
|
+
}
|
|
1453
|
+
return false;
|
|
1454
|
+
}
|
|
1455
|
+
return { registration, isReady, isUpdateAvailable, error, update, unregister };
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// src/platform/worker.ts
|
|
1459
|
+
function worker(workerFn2) {
|
|
1460
|
+
const [result, setResult] = signal(null);
|
|
1461
|
+
const [error, setError] = signal(null);
|
|
1462
|
+
const [loading, setLoading] = signal(false);
|
|
1463
|
+
let worker2 = null;
|
|
1464
|
+
try {
|
|
1465
|
+
if (typeof Worker === "undefined") {
|
|
1466
|
+
throw new Error("Web Workers are not supported in this environment");
|
|
1467
|
+
}
|
|
1468
|
+
const fnBody = workerFn2.toString();
|
|
1469
|
+
const blob = new Blob([`self.onmessage = ${fnBody};`], { type: "application/javascript" });
|
|
1470
|
+
const url = URL.createObjectURL(blob);
|
|
1471
|
+
worker2 = new Worker(url);
|
|
1472
|
+
URL.revokeObjectURL(url);
|
|
1473
|
+
worker2.onmessage = (e) => {
|
|
1474
|
+
setResult(e.data);
|
|
1475
|
+
setLoading(false);
|
|
1476
|
+
};
|
|
1477
|
+
worker2.onerror = (e) => {
|
|
1478
|
+
setError(new Error(e.message || "Worker error"));
|
|
1479
|
+
setLoading(false);
|
|
1480
|
+
};
|
|
1481
|
+
} catch (err) {
|
|
1482
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1483
|
+
}
|
|
1484
|
+
function post(data2) {
|
|
1485
|
+
if (!worker2) return;
|
|
1486
|
+
setLoading(true);
|
|
1487
|
+
setError(null);
|
|
1488
|
+
setResult(null);
|
|
1489
|
+
worker2.postMessage(data2);
|
|
1490
|
+
}
|
|
1491
|
+
function terminate() {
|
|
1492
|
+
if (!worker2) return;
|
|
1493
|
+
worker2.terminate();
|
|
1494
|
+
worker2 = null;
|
|
1495
|
+
setLoading(false);
|
|
1496
|
+
}
|
|
1497
|
+
return { post, result, error, loading, terminate };
|
|
1498
|
+
}
|
|
1499
|
+
function workerFn(fn) {
|
|
1500
|
+
const [loading, setLoading] = signal(false);
|
|
1501
|
+
let worker2 = null;
|
|
1502
|
+
try {
|
|
1503
|
+
if (typeof Worker === "undefined") {
|
|
1504
|
+
throw new Error("Web Workers are not supported in this environment");
|
|
1505
|
+
}
|
|
1506
|
+
const fnStr = fn.toString();
|
|
1507
|
+
const blob = new Blob(
|
|
1508
|
+
[
|
|
1509
|
+
`self.onmessage = function(e) {
|
|
1510
|
+
var fn = ${fnStr};
|
|
1511
|
+
var result = fn.apply(null, e.data);
|
|
1512
|
+
postMessage(result);
|
|
1513
|
+
};`
|
|
1514
|
+
],
|
|
1515
|
+
{ type: "application/javascript" }
|
|
1516
|
+
);
|
|
1517
|
+
const url = URL.createObjectURL(blob);
|
|
1518
|
+
worker2 = new Worker(url);
|
|
1519
|
+
URL.revokeObjectURL(url);
|
|
1520
|
+
} catch {
|
|
1521
|
+
}
|
|
1522
|
+
function run(...args) {
|
|
1523
|
+
return new Promise((resolve, reject) => {
|
|
1524
|
+
if (!worker2) {
|
|
1525
|
+
reject(new Error("Worker is not available"));
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
setLoading(true);
|
|
1529
|
+
worker2.onmessage = (e) => {
|
|
1530
|
+
setLoading(false);
|
|
1531
|
+
resolve(e.data);
|
|
1532
|
+
};
|
|
1533
|
+
worker2.onerror = (e) => {
|
|
1534
|
+
setLoading(false);
|
|
1535
|
+
reject(new Error(e.message || "Worker error"));
|
|
1536
|
+
};
|
|
1537
|
+
worker2.postMessage(args);
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
function terminate() {
|
|
1541
|
+
if (!worker2) return;
|
|
1542
|
+
worker2.terminate();
|
|
1543
|
+
worker2 = null;
|
|
1544
|
+
setLoading(false);
|
|
1545
|
+
}
|
|
1546
|
+
return { run, loading, terminate };
|
|
1547
|
+
}
|
|
1548
|
+
function createWorkerPool(workerFn2, poolSize) {
|
|
1549
|
+
const size = poolSize || typeof navigator !== "undefined" && navigator.hardwareConcurrency || 4;
|
|
1550
|
+
const workers = [];
|
|
1551
|
+
let currentIndex = 0;
|
|
1552
|
+
let alive = true;
|
|
1553
|
+
try {
|
|
1554
|
+
if (typeof Worker === "undefined") {
|
|
1555
|
+
throw new Error("Web Workers are not supported in this environment");
|
|
1556
|
+
}
|
|
1557
|
+
const fnBody = workerFn2.toString();
|
|
1558
|
+
const blob = new Blob([`self.onmessage = ${fnBody};`], { type: "application/javascript" });
|
|
1559
|
+
const url = URL.createObjectURL(blob);
|
|
1560
|
+
for (let i2 = 0; i2 < size; i2++) {
|
|
1561
|
+
workers.push(new Worker(url));
|
|
1562
|
+
}
|
|
1563
|
+
URL.revokeObjectURL(url);
|
|
1564
|
+
} catch {
|
|
1565
|
+
}
|
|
1566
|
+
function execute(data2) {
|
|
1567
|
+
return new Promise((resolve, reject) => {
|
|
1568
|
+
if (!alive || workers.length === 0) {
|
|
1569
|
+
reject(new Error("Worker pool is not available"));
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
const worker2 = workers[currentIndex % workers.length];
|
|
1573
|
+
currentIndex++;
|
|
1574
|
+
worker2.onmessage = (e) => {
|
|
1575
|
+
resolve(e.data);
|
|
1576
|
+
};
|
|
1577
|
+
worker2.onerror = (e) => {
|
|
1578
|
+
reject(new Error(e.message || "Worker error"));
|
|
1579
|
+
};
|
|
1580
|
+
worker2.postMessage(data2);
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
function terminate() {
|
|
1584
|
+
alive = false;
|
|
1585
|
+
for (const w of workers) {
|
|
1586
|
+
w.terminate();
|
|
1587
|
+
}
|
|
1588
|
+
workers.length = 0;
|
|
1589
|
+
}
|
|
1590
|
+
return { execute, terminate };
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// src/platform/wasm.ts
|
|
1594
|
+
var moduleCache2 = /* @__PURE__ */ new Map();
|
|
1595
|
+
var instanceCache = /* @__PURE__ */ new Map();
|
|
1596
|
+
function wasm(source2, config = {}) {
|
|
1597
|
+
const [instance, setInstance] = signal(null);
|
|
1598
|
+
const [loading, setLoading] = signal(true);
|
|
1599
|
+
const [error, setError] = signal(null);
|
|
1600
|
+
const cacheKey = config.cacheKey || (typeof source2 === "string" ? source2 : void 0);
|
|
1601
|
+
async function load() {
|
|
1602
|
+
setLoading(true);
|
|
1603
|
+
setError(null);
|
|
1604
|
+
setInstance(null);
|
|
1605
|
+
try {
|
|
1606
|
+
const wasmInstance = await loadWasmModule(source2, config.imports, cacheKey);
|
|
1607
|
+
setInstance(wasmInstance.exports);
|
|
1608
|
+
} catch (err) {
|
|
1609
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1610
|
+
} finally {
|
|
1611
|
+
setLoading(false);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
load();
|
|
1615
|
+
return {
|
|
1616
|
+
instance,
|
|
1617
|
+
loading,
|
|
1618
|
+
error,
|
|
1619
|
+
ready: () => instance() !== null,
|
|
1620
|
+
reload: load
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
async function loadWasmModule(source2, imports, cacheKey) {
|
|
1624
|
+
const key = cacheKey || (typeof source2 === "string" ? source2 : void 0);
|
|
1625
|
+
if (key) {
|
|
1626
|
+
const cachedInstance = instanceCache.get(key);
|
|
1627
|
+
if (cachedInstance) {
|
|
1628
|
+
return cachedInstance;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
let module2;
|
|
1632
|
+
const cachedModule = key ? moduleCache2.get(key) : void 0;
|
|
1633
|
+
if (cachedModule) {
|
|
1634
|
+
module2 = cachedModule;
|
|
1635
|
+
} else {
|
|
1636
|
+
let bytes;
|
|
1637
|
+
if (typeof source2 === "string") {
|
|
1638
|
+
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
1639
|
+
const response2 = fetch(source2);
|
|
1640
|
+
const result = await WebAssembly.instantiateStreaming(response2, imports || {});
|
|
1641
|
+
if (key) {
|
|
1642
|
+
moduleCache2.set(key, result.module);
|
|
1643
|
+
instanceCache.set(key, result.instance);
|
|
1644
|
+
}
|
|
1645
|
+
return result.instance;
|
|
1646
|
+
}
|
|
1647
|
+
const response = await fetch(source2);
|
|
1648
|
+
bytes = await response.arrayBuffer();
|
|
1649
|
+
} else if (source2 instanceof Uint8Array) {
|
|
1650
|
+
bytes = source2.buffer.slice(source2.byteOffset, source2.byteOffset + source2.byteLength);
|
|
1651
|
+
} else {
|
|
1652
|
+
bytes = source2;
|
|
1653
|
+
}
|
|
1654
|
+
module2 = await WebAssembly.compile(bytes);
|
|
1655
|
+
if (key) moduleCache2.set(key, module2);
|
|
1656
|
+
}
|
|
1657
|
+
const instance = await WebAssembly.instantiate(module2, imports || {});
|
|
1658
|
+
if (key) instanceCache.set(key, instance);
|
|
1659
|
+
return instance;
|
|
1660
|
+
}
|
|
1661
|
+
async function preloadWasm(url) {
|
|
1662
|
+
if (moduleCache2.has(url)) return;
|
|
1663
|
+
let module2;
|
|
1664
|
+
if (typeof WebAssembly.compileStreaming === "function") {
|
|
1665
|
+
module2 = await WebAssembly.compileStreaming(fetch(url));
|
|
1666
|
+
} else {
|
|
1667
|
+
const response = await fetch(url);
|
|
1668
|
+
const bytes = await response.arrayBuffer();
|
|
1669
|
+
module2 = await WebAssembly.compile(bytes);
|
|
1670
|
+
}
|
|
1671
|
+
moduleCache2.set(url, module2);
|
|
1672
|
+
}
|
|
1673
|
+
function createWasmBridge(instance) {
|
|
1674
|
+
const exports2 = instance.exports;
|
|
1675
|
+
const memory = exports2.memory || instance.exports.memory;
|
|
1676
|
+
return {
|
|
1677
|
+
exports: instance.exports,
|
|
1678
|
+
memory,
|
|
1679
|
+
alloc(size) {
|
|
1680
|
+
if (!exports2.malloc) throw new Error("WASM module does not export malloc");
|
|
1681
|
+
return exports2.malloc(size);
|
|
1682
|
+
},
|
|
1683
|
+
free(ptr) {
|
|
1684
|
+
if (!exports2.free) throw new Error("WASM module does not export free");
|
|
1685
|
+
exports2.free(ptr);
|
|
1686
|
+
},
|
|
1687
|
+
writeString(str) {
|
|
1688
|
+
const encoder = new TextEncoder();
|
|
1689
|
+
const bytes = encoder.encode(str);
|
|
1690
|
+
if (!exports2.malloc) throw new Error("WASM module does not export malloc");
|
|
1691
|
+
const ptr = exports2.malloc(bytes.length);
|
|
1692
|
+
new Uint8Array(memory.buffer, ptr, bytes.length).set(bytes);
|
|
1693
|
+
return { ptr, len: bytes.length };
|
|
1694
|
+
},
|
|
1695
|
+
readString(ptr, len) {
|
|
1696
|
+
const decoder = new TextDecoder();
|
|
1697
|
+
return decoder.decode(new Uint8Array(memory.buffer, ptr, len));
|
|
1698
|
+
},
|
|
1699
|
+
writeArray(arr) {
|
|
1700
|
+
if (!exports2.malloc) throw new Error("WASM module does not export malloc");
|
|
1701
|
+
const ptr = exports2.malloc(arr.length * 8);
|
|
1702
|
+
new Float64Array(memory.buffer, ptr, arr.length).set(Array.from(arr));
|
|
1703
|
+
return { ptr, len: arr.length };
|
|
1704
|
+
},
|
|
1705
|
+
readF64Array(ptr, len) {
|
|
1706
|
+
return new Float64Array(memory.buffer, ptr, len);
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
function clearWasmCache() {
|
|
1711
|
+
moduleCache2.clear();
|
|
1712
|
+
instanceCache.clear();
|
|
1713
|
+
}
|
|
1714
|
+
function isWasmCached(key) {
|
|
1715
|
+
return moduleCache2.has(key);
|
|
1716
|
+
}
|
|
1717
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1718
|
+
0 && (module.exports = {
|
|
1719
|
+
Head,
|
|
1720
|
+
clearWasmCache,
|
|
1721
|
+
collectStream,
|
|
1722
|
+
composeMiddleware,
|
|
1723
|
+
createAction,
|
|
1724
|
+
createISR,
|
|
1725
|
+
createMicroApp,
|
|
1726
|
+
createMiddlewareChain,
|
|
1727
|
+
createSharedScope,
|
|
1728
|
+
createWasmBridge,
|
|
1729
|
+
createWorkerPool,
|
|
1730
|
+
defineRemoteComponent,
|
|
1731
|
+
deserializeState,
|
|
1732
|
+
generateStaticSite,
|
|
1733
|
+
hydrate,
|
|
1734
|
+
hydrateIslands,
|
|
1735
|
+
hydrateProgressively,
|
|
1736
|
+
isWasmCached,
|
|
1737
|
+
island,
|
|
1738
|
+
loadRemoteModule,
|
|
1739
|
+
loadWasmModule,
|
|
1740
|
+
preloadWasm,
|
|
1741
|
+
renderToDocument,
|
|
1742
|
+
renderToReadableStream,
|
|
1743
|
+
renderToStream,
|
|
1744
|
+
renderToString,
|
|
1745
|
+
renderToSuspenseStream,
|
|
1746
|
+
resetSSRState,
|
|
1747
|
+
scrollRestoration,
|
|
1748
|
+
serializeState,
|
|
1749
|
+
serviceWorker,
|
|
1750
|
+
setCanonical,
|
|
1751
|
+
setStructuredData,
|
|
1752
|
+
ssrSuspense,
|
|
1753
|
+
suspenseSwapScript,
|
|
1754
|
+
wasm,
|
|
1755
|
+
worker,
|
|
1756
|
+
workerFn
|
|
1757
|
+
});
|