sibujs 1.5.0 → 2.0.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 (207) hide show
  1. package/dist/browser.cjs +238 -69
  2. package/dist/browser.d.cts +5 -0
  3. package/dist/browser.d.ts +5 -0
  4. package/dist/browser.js +6 -6
  5. package/dist/build.cjs +916 -292
  6. package/dist/build.js +15 -13
  7. package/dist/cdn.global.js +17 -16
  8. package/dist/chunk-2RA7SHDA.js +65 -0
  9. package/dist/chunk-2UPRY23K.js +80 -0
  10. package/dist/chunk-3JHCYHWN.js +125 -0
  11. package/dist/{chunk-VAPYJN4X.js → chunk-3LR7GLWQ.js} +93 -23
  12. package/dist/{chunk-RJ46C3CS.js → chunk-3NSGB5JN.js} +71 -20
  13. package/dist/{chunk-XUEEGU5O.js → chunk-52YJLLRO.js} +16 -4
  14. package/dist/{chunk-XHK6BDAJ.js → chunk-54EDRCEF.js} +25 -8
  15. package/dist/chunk-7JDB7I65.js +1327 -0
  16. package/dist/{chunk-WZSPOOER.js → chunk-CC65Y57T.js} +8 -5
  17. package/dist/{chunk-23VV7YD3.js → chunk-DFPFITST.js} +25 -30
  18. package/dist/{chunk-BGN5ZMP4.js → chunk-GTBNNBJ6.js} +14 -2
  19. package/dist/chunk-HB24TBAF.js +121 -0
  20. package/dist/{chunk-CZUGLNJS.js → chunk-ITX6OO3F.js} +3 -3
  21. package/dist/{chunk-BGTHZHJ5.js → chunk-JA6667UN.js} +188 -44
  22. package/dist/{chunk-7GRNSCFT.js → chunk-JXMMDLBY.js} +306 -183
  23. package/dist/{chunk-3X2YG6YM.js → chunk-JYD2PWXH.js} +59 -28
  24. package/dist/{chunk-SFKNRVCU.js → chunk-KLRMB5ZS.js} +135 -79
  25. package/dist/{chunk-5X6PP2UK.js → chunk-LMLD24FC.js} +2 -2
  26. package/dist/{chunk-M4NLBH4I.js → chunk-LYTCUZ7H.js} +3 -2
  27. package/dist/{chunk-BMPL52BF.js → chunk-MIUAXB7K.js} +118 -66
  28. package/dist/{chunk-JCDUJN2F.js → chunk-ND2664SF.js} +486 -153
  29. package/dist/{chunk-VQDZK23A.js → chunk-O2MNQFLP.js} +181 -66
  30. package/dist/{chunk-NHUC2QWH.js → chunk-R73P76YZ.js} +1 -1
  31. package/dist/{chunk-2BYQDGN3.js → chunk-SAHNHTFC.js} +234 -63
  32. package/dist/chunk-UCS6AMJ7.js +79 -0
  33. package/dist/{chunk-K4G4ZQNR.js → chunk-VLPPXTYG.js} +84 -38
  34. package/dist/{chunk-OUZZEE4S.js → chunk-WOMYAHHI.js} +17 -11
  35. package/dist/{customElement-BL3Uo8dL.d.cts → customElement-CPfIrbvg.d.cts} +14 -10
  36. package/dist/{customElement-BL3Uo8dL.d.ts → customElement-CPfIrbvg.d.ts} +14 -10
  37. package/dist/data.cjs +410 -99
  38. package/dist/data.d.cts +20 -2
  39. package/dist/data.d.ts +20 -2
  40. package/dist/data.js +11 -9
  41. package/dist/devtools.cjs +513 -223
  42. package/dist/devtools.d.cts +1 -1
  43. package/dist/devtools.d.ts +1 -1
  44. package/dist/devtools.js +12 -6
  45. package/dist/ecosystem.cjs +475 -144
  46. package/dist/ecosystem.d.cts +9 -7
  47. package/dist/ecosystem.d.ts +9 -7
  48. package/dist/ecosystem.js +12 -11
  49. package/dist/extras.cjs +3355 -1541
  50. package/dist/extras.d.cts +9 -9
  51. package/dist/extras.d.ts +9 -9
  52. package/dist/extras.js +58 -45
  53. package/dist/index.cjs +920 -292
  54. package/dist/index.d.cts +71 -8
  55. package/dist/index.d.ts +71 -8
  56. package/dist/index.js +28 -16
  57. package/dist/{introspect-BumjnBKr.d.cts → introspect-BWNjNw64.d.cts} +22 -2
  58. package/dist/{introspect-CZrlcaYy.d.ts → introspect-cY2pg9pW.d.ts} +22 -2
  59. package/dist/motion.cjs +77 -34
  60. package/dist/motion.js +4 -4
  61. package/dist/patterns.cjs +335 -69
  62. package/dist/patterns.d.cts +11 -12
  63. package/dist/patterns.d.ts +11 -12
  64. package/dist/patterns.js +7 -7
  65. package/dist/performance.cjs +279 -108
  66. package/dist/performance.d.cts +23 -16
  67. package/dist/performance.d.ts +23 -16
  68. package/dist/performance.js +13 -8
  69. package/dist/plugin-D30wlGW5.d.cts +71 -0
  70. package/dist/plugin-D30wlGW5.d.ts +71 -0
  71. package/dist/plugins.cjs +635 -260
  72. package/dist/plugins.d.cts +10 -3
  73. package/dist/plugins.d.ts +10 -3
  74. package/dist/plugins.js +106 -38
  75. package/dist/{ssr-Do_SiVoL.d.cts → ssr-CrVNy6Pa.d.cts} +9 -15
  76. package/dist/{ssr-Do_SiVoL.d.ts → ssr-CrVNy6Pa.d.ts} +9 -15
  77. package/dist/{ssr-4PBXAOO3.js → ssr-FXD2PPMC.js} +4 -3
  78. package/dist/ssr.cjs +642 -222
  79. package/dist/ssr.d.cts +26 -6
  80. package/dist/ssr.d.ts +26 -6
  81. package/dist/ssr.js +12 -11
  82. package/dist/{tagFactory-DaJ0YWX6.d.cts → tagFactory-S17H2qxu.d.cts} +9 -1
  83. package/dist/{tagFactory-DaJ0YWX6.d.ts → tagFactory-S17H2qxu.d.ts} +9 -1
  84. package/dist/testing.cjs +252 -63
  85. package/dist/testing.d.cts +17 -4
  86. package/dist/testing.d.ts +17 -4
  87. package/dist/testing.js +100 -44
  88. package/dist/ui.cjs +463 -137
  89. package/dist/ui.d.cts +1 -1
  90. package/dist/ui.d.ts +1 -1
  91. package/dist/ui.js +20 -17
  92. package/dist/widgets.cjs +977 -94
  93. package/dist/widgets.d.cts +104 -2
  94. package/dist/widgets.d.ts +104 -2
  95. package/dist/widgets.js +9 -7
  96. package/package.json +8 -2
  97. package/dist/chunk-32DY64NT.js +0 -282
  98. package/dist/chunk-3AIRKM3B.js +0 -1263
  99. package/dist/chunk-3ARAQO7B.js +0 -398
  100. package/dist/chunk-3CRQALYP.js +0 -877
  101. package/dist/chunk-4EI4AG32.js +0 -482
  102. package/dist/chunk-4MYMUBRS.js +0 -21
  103. package/dist/chunk-5ZYQ6KDD.js +0 -154
  104. package/dist/chunk-6BMPXPUW.js +0 -26
  105. package/dist/chunk-6HLLIF3K.js +0 -398
  106. package/dist/chunk-6LSNVCS2.js +0 -937
  107. package/dist/chunk-6SA3QQES.js +0 -61
  108. package/dist/chunk-77L6NL3X.js +0 -1097
  109. package/dist/chunk-7BF6TK55.js +0 -1097
  110. package/dist/chunk-7TQKR4PP.js +0 -294
  111. package/dist/chunk-7V26P53V.js +0 -712
  112. package/dist/chunk-AZ3ISID5.js +0 -298
  113. package/dist/chunk-B7SWRFUT.js +0 -332
  114. package/dist/chunk-BTU3TJDS.js +0 -365
  115. package/dist/chunk-BW3WT46K.js +0 -937
  116. package/dist/chunk-C6KFWOFV.js +0 -616
  117. package/dist/chunk-CHF5OHIA.js +0 -61
  118. package/dist/chunk-CHJ27IGK.js +0 -26
  119. package/dist/chunk-CMBFNA7L.js +0 -27
  120. package/dist/chunk-DAHRH4ON.js +0 -331
  121. package/dist/chunk-DKOHBI74.js +0 -924
  122. package/dist/chunk-DTCOOBMX.js +0 -725
  123. package/dist/chunk-EBGIRKQY.js +0 -616
  124. package/dist/chunk-EUZND3CB.js +0 -27
  125. package/dist/chunk-EVCZO745.js +0 -365
  126. package/dist/chunk-EWFVA3TJ.js +0 -282
  127. package/dist/chunk-F3FA4F32.js +0 -292
  128. package/dist/chunk-FGOEVHY3.js +0 -60
  129. package/dist/chunk-G3BOQPVO.js +0 -365
  130. package/dist/chunk-GCOK2LC3.js +0 -282
  131. package/dist/chunk-GJPXRJ45.js +0 -37
  132. package/dist/chunk-HGMJFBC7.js +0 -654
  133. package/dist/chunk-JAKHTMQU.js +0 -1000
  134. package/dist/chunk-JCI5M6U6.js +0 -956
  135. package/dist/chunk-K5ZUMYVS.js +0 -89
  136. package/dist/chunk-KQPDEVVS.js +0 -398
  137. package/dist/chunk-L6JRBDNS.js +0 -60
  138. package/dist/chunk-LA6KQEDU.js +0 -712
  139. package/dist/chunk-MB6QFH3I.js +0 -2776
  140. package/dist/chunk-MDVXJWFN.js +0 -304
  141. package/dist/chunk-MEZVEBPN.js +0 -2008
  142. package/dist/chunk-MK4ERFYL.js +0 -2249
  143. package/dist/chunk-MLKGABMK.js +0 -9
  144. package/dist/chunk-MQ5GOYPH.js +0 -2249
  145. package/dist/chunk-MYRV7VDM.js +0 -742
  146. package/dist/chunk-N6IZB6KJ.js +0 -567
  147. package/dist/chunk-NEKUBFPT.js +0 -60
  148. package/dist/chunk-NMRUZALC.js +0 -1097
  149. package/dist/chunk-NYVAC6P5.js +0 -37
  150. package/dist/chunk-NZIIMDWI.js +0 -84
  151. package/dist/chunk-OF7UZIVB.js +0 -725
  152. package/dist/chunk-P3XWXJZU.js +0 -282
  153. package/dist/chunk-P6W3STU4.js +0 -2249
  154. package/dist/chunk-PBHF5WKN.js +0 -616
  155. package/dist/chunk-PDZQY43A.js +0 -616
  156. package/dist/chunk-PTQJDMRT.js +0 -146
  157. package/dist/chunk-PZEGYCF5.js +0 -61
  158. package/dist/chunk-QBMDLBU2.js +0 -975
  159. package/dist/chunk-QWZG56ET.js +0 -2744
  160. package/dist/chunk-RQGQSLQK.js +0 -725
  161. package/dist/chunk-SDLZDHKP.js +0 -107
  162. package/dist/chunk-TDGZL5CU.js +0 -365
  163. package/dist/chunk-TNQWPPE6.js +0 -37
  164. package/dist/chunk-TSOKIX5Z.js +0 -654
  165. package/dist/chunk-UHNL42EF.js +0 -2730
  166. package/dist/chunk-UNXCEF6S.js +0 -21
  167. package/dist/chunk-V2XTI523.js +0 -347
  168. package/dist/chunk-VAU366PN.js +0 -2241
  169. package/dist/chunk-VMVDTCXB.js +0 -712
  170. package/dist/chunk-VQNQZCWJ.js +0 -61
  171. package/dist/chunk-VRW3FULF.js +0 -725
  172. package/dist/chunk-WADYRCO2.js +0 -304
  173. package/dist/chunk-WILQZRO4.js +0 -282
  174. package/dist/chunk-WR5D4EGH.js +0 -26
  175. package/dist/chunk-WUHJISPP.js +0 -298
  176. package/dist/chunk-XYU6TZOW.js +0 -182
  177. package/dist/chunk-Y6GP4QGG.js +0 -276
  178. package/dist/chunk-YECR7UIA.js +0 -347
  179. package/dist/chunk-YUTWTI4B.js +0 -654
  180. package/dist/chunk-Z65KYU7I.js +0 -26
  181. package/dist/chunk-Z6POF5YC.js +0 -975
  182. package/dist/chunk-ZBJP6WFL.js +0 -482
  183. package/dist/chunk-ZD6OAMTH.js +0 -277
  184. package/dist/chunk-ZWKZCBO6.js +0 -317
  185. package/dist/contracts-DDrwxvJ-.d.cts +0 -245
  186. package/dist/contracts-DDrwxvJ-.d.ts +0 -245
  187. package/dist/contracts-DOrhwbke.d.cts +0 -245
  188. package/dist/contracts-DOrhwbke.d.ts +0 -245
  189. package/dist/contracts-xo5ckdRP.d.cts +0 -240
  190. package/dist/contracts-xo5ckdRP.d.ts +0 -240
  191. package/dist/customElement-BKQfbSZQ.d.cts +0 -262
  192. package/dist/customElement-BKQfbSZQ.d.ts +0 -262
  193. package/dist/customElement-D2DJp_xn.d.cts +0 -313
  194. package/dist/customElement-D2DJp_xn.d.ts +0 -313
  195. package/dist/customElement-yz8uyk-0.d.cts +0 -308
  196. package/dist/customElement-yz8uyk-0.d.ts +0 -308
  197. package/dist/introspect-Cb0zgpi2.d.cts +0 -477
  198. package/dist/introspect-Y2xNXGSf.d.ts +0 -477
  199. package/dist/plugin-Bek4RhJY.d.cts +0 -43
  200. package/dist/plugin-Bek4RhJY.d.ts +0 -43
  201. package/dist/ssr-3RXHP5ES.js +0 -38
  202. package/dist/ssr-6GIMY5MX.js +0 -38
  203. package/dist/ssr-BA6sxxUd.d.cts +0 -135
  204. package/dist/ssr-BA6sxxUd.d.ts +0 -135
  205. package/dist/ssr-WKUPVSSK.js +0 -36
  206. package/dist/tagFactory-Dl8QCLga.d.cts +0 -23
  207. package/dist/tagFactory-Dl8QCLga.d.ts +0 -23
@@ -1,742 +0,0 @@
1
- import {
2
- div,
3
- span
4
- } from "./chunk-P3XWXJZU.js";
5
- import {
6
- sanitizeUrl
7
- } from "./chunk-CMBFNA7L.js";
8
- import {
9
- effect
10
- } from "./chunk-VQNQZCWJ.js";
11
- import {
12
- batch,
13
- signal
14
- } from "./chunk-NZIIMDWI.js";
15
-
16
- // src/platform/head.ts
17
- var HEAD_URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
18
- function sanitizeHeadAttr(key, value) {
19
- if (HEAD_URL_ATTRS.has(key)) return sanitizeUrl(value);
20
- return value;
21
- }
22
- function isDangerousMetaRefresh(metaProps) {
23
- const httpEquiv = metaProps["http-equiv"];
24
- if (typeof httpEquiv !== "string") return false;
25
- if (httpEquiv.toLowerCase() !== "refresh") return false;
26
- const content = metaProps.content;
27
- if (typeof content !== "string") return false;
28
- const normalized = content.replace(/[\x00-\x20\x7f-\x9f]+/g, "").toLowerCase();
29
- return normalized.includes("url=javascript:") || normalized.includes("url=data:") || normalized.includes("url=vbscript:") || normalized.includes("url=blob:");
30
- }
31
- var SAFE_HEAD_ATTR_NAME = /^[A-Za-z_:][-A-Za-z0-9_.:]*$/;
32
- function isEventHandlerAttr(name) {
33
- if (name.length < 3) return false;
34
- const lower = name.toLowerCase();
35
- return lower[0] === "o" && lower[1] === "n" && lower.charCodeAt(2) >= 97 && lower.charCodeAt(2) <= 122;
36
- }
37
- function isSafeHeadAttr(name) {
38
- if (!SAFE_HEAD_ATTR_NAME.test(name)) return false;
39
- if (isEventHandlerAttr(name)) return false;
40
- return true;
41
- }
42
- function escapeScriptJsonLocal(json) {
43
- return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
44
- }
45
- function Head(props) {
46
- const anchor = document.createComment("sibu-head");
47
- const managedElements = [];
48
- const effectCleanups = [];
49
- const cleanup = () => {
50
- for (const el of managedElements) {
51
- if (el.parentNode) el.parentNode.removeChild(el);
52
- }
53
- managedElements.length = 0;
54
- for (const cleanupFn of effectCleanups) cleanupFn();
55
- effectCleanups.length = 0;
56
- };
57
- const apply = () => {
58
- cleanup();
59
- if (props.title) {
60
- if (typeof props.title === "function") {
61
- const cleanupFn = effect(() => {
62
- document.title = props.title();
63
- });
64
- effectCleanups.push(cleanupFn);
65
- } else {
66
- document.title = props.title;
67
- }
68
- }
69
- if (props.meta) {
70
- for (const metaProps of props.meta) {
71
- if (isDangerousMetaRefresh(metaProps)) continue;
72
- const el = document.createElement("meta");
73
- for (const [key, value] of Object.entries(metaProps)) {
74
- if (!isSafeHeadAttr(key)) continue;
75
- if (typeof value === "function") {
76
- const cleanupFn = effect(() => {
77
- el.setAttribute(key, sanitizeHeadAttr(key, value()));
78
- });
79
- effectCleanups.push(cleanupFn);
80
- } else {
81
- el.setAttribute(key, sanitizeHeadAttr(key, value));
82
- }
83
- }
84
- document.head.appendChild(el);
85
- managedElements.push(el);
86
- }
87
- }
88
- if (props.link) {
89
- for (const linkProps of props.link) {
90
- const el = document.createElement("link");
91
- for (const [key, value] of Object.entries(linkProps)) {
92
- if (!isSafeHeadAttr(key)) continue;
93
- el.setAttribute(key, sanitizeHeadAttr(key, value));
94
- }
95
- document.head.appendChild(el);
96
- managedElements.push(el);
97
- }
98
- }
99
- if (props.script) {
100
- for (const scriptProps of props.script) {
101
- const el = document.createElement("script");
102
- for (const [key, value] of Object.entries(scriptProps)) {
103
- if (!isSafeHeadAttr(key)) continue;
104
- el.setAttribute(key, sanitizeHeadAttr(key, value));
105
- }
106
- document.head.appendChild(el);
107
- managedElements.push(el);
108
- }
109
- }
110
- if (props.base) {
111
- const existing = document.head.querySelector("base");
112
- if (existing) existing.remove();
113
- const el = document.createElement("base");
114
- if (props.base.href) {
115
- const safeHref = sanitizeUrl(props.base.href);
116
- if (safeHref) el.href = safeHref;
117
- }
118
- if (props.base.target) el.target = props.base.target;
119
- document.head.appendChild(el);
120
- managedElements.push(el);
121
- }
122
- };
123
- apply();
124
- return anchor;
125
- }
126
- function setStructuredData(data) {
127
- const existing = document.head.querySelector('script[type="application/ld+json"][data-sibu]');
128
- if (existing) existing.remove();
129
- const script = document.createElement("script");
130
- script.type = "application/ld+json";
131
- script.setAttribute("data-sibu", "true");
132
- script.textContent = escapeScriptJsonLocal(JSON.stringify(data));
133
- document.head.appendChild(script);
134
- }
135
- function setCanonical(url) {
136
- let link = document.head.querySelector('link[rel="canonical"]');
137
- if (!link) {
138
- link = document.createElement("link");
139
- link.rel = "canonical";
140
- document.head.appendChild(link);
141
- }
142
- link.href = sanitizeUrl(url);
143
- }
144
-
145
- // src/platform/worker.ts
146
- function worker(workerFn2) {
147
- const [result, setResult] = signal(null);
148
- const [error, setError] = signal(null);
149
- const [loading, setLoading] = signal(false);
150
- let worker2 = null;
151
- try {
152
- if (typeof Worker === "undefined") {
153
- throw new Error("Web Workers are not supported in this environment");
154
- }
155
- const fnBody = workerFn2.toString();
156
- const blob = new Blob([`self.onmessage = ${fnBody};`], { type: "application/javascript" });
157
- const url = URL.createObjectURL(blob);
158
- worker2 = new Worker(url);
159
- URL.revokeObjectURL(url);
160
- worker2.onmessage = (e) => {
161
- setResult(e.data);
162
- setLoading(false);
163
- };
164
- worker2.onerror = (e) => {
165
- setError(new Error(e.message || "Worker error"));
166
- setLoading(false);
167
- };
168
- } catch (err) {
169
- setError(err instanceof Error ? err : new Error(String(err)));
170
- }
171
- function post(data) {
172
- if (!worker2) return;
173
- setLoading(true);
174
- setError(null);
175
- setResult(null);
176
- worker2.postMessage(data);
177
- }
178
- function terminate() {
179
- if (!worker2) return;
180
- worker2.terminate();
181
- worker2 = null;
182
- setLoading(false);
183
- }
184
- return { post, result, error, loading, terminate };
185
- }
186
- function workerFn(fn) {
187
- const [loading, setLoading] = signal(false);
188
- let worker2 = null;
189
- try {
190
- if (typeof Worker === "undefined") {
191
- throw new Error("Web Workers are not supported in this environment");
192
- }
193
- const fnStr = fn.toString();
194
- const blob = new Blob(
195
- [
196
- `self.onmessage = function(e) {
197
- var fn = ${fnStr};
198
- var result = fn.apply(null, e.data);
199
- postMessage(result);
200
- };`
201
- ],
202
- { type: "application/javascript" }
203
- );
204
- const url = URL.createObjectURL(blob);
205
- worker2 = new Worker(url);
206
- URL.revokeObjectURL(url);
207
- } catch {
208
- }
209
- function run(...args) {
210
- return new Promise((resolve, reject) => {
211
- if (!worker2) {
212
- reject(new Error("Worker is not available"));
213
- return;
214
- }
215
- setLoading(true);
216
- worker2.onmessage = (e) => {
217
- setLoading(false);
218
- resolve(e.data);
219
- };
220
- worker2.onerror = (e) => {
221
- setLoading(false);
222
- reject(new Error(e.message || "Worker error"));
223
- };
224
- worker2.postMessage(args);
225
- });
226
- }
227
- function terminate() {
228
- if (!worker2) return;
229
- worker2.terminate();
230
- worker2 = null;
231
- setLoading(false);
232
- }
233
- return { run, loading, terminate };
234
- }
235
- function createWorkerPool(workerFn2, poolSize) {
236
- const size = poolSize || typeof navigator !== "undefined" && navigator.hardwareConcurrency || 4;
237
- const workers = [];
238
- let currentIndex = 0;
239
- let alive = true;
240
- try {
241
- if (typeof Worker === "undefined") {
242
- throw new Error("Web Workers are not supported in this environment");
243
- }
244
- const fnBody = workerFn2.toString();
245
- const blob = new Blob([`self.onmessage = ${fnBody};`], { type: "application/javascript" });
246
- const url = URL.createObjectURL(blob);
247
- for (let i = 0; i < size; i++) {
248
- workers.push(new Worker(url));
249
- }
250
- URL.revokeObjectURL(url);
251
- } catch {
252
- }
253
- function execute(data) {
254
- return new Promise((resolve, reject) => {
255
- if (!alive || workers.length === 0) {
256
- reject(new Error("Worker pool is not available"));
257
- return;
258
- }
259
- const worker2 = workers[currentIndex % workers.length];
260
- currentIndex++;
261
- worker2.onmessage = (e) => {
262
- resolve(e.data);
263
- };
264
- worker2.onerror = (e) => {
265
- reject(new Error(e.message || "Worker error"));
266
- };
267
- worker2.postMessage(data);
268
- });
269
- }
270
- function terminate() {
271
- alive = false;
272
- for (const w of workers) {
273
- w.terminate();
274
- }
275
- workers.length = 0;
276
- }
277
- return { execute, terminate };
278
- }
279
-
280
- // src/platform/wasm.ts
281
- var moduleCache = /* @__PURE__ */ new Map();
282
- var instanceCache = /* @__PURE__ */ new Map();
283
- function wasm(source, config = {}) {
284
- const [instance, setInstance] = signal(null);
285
- const [loading, setLoading] = signal(true);
286
- const [error, setError] = signal(null);
287
- const cacheKey = config.cacheKey || (typeof source === "string" ? source : void 0);
288
- async function load() {
289
- setLoading(true);
290
- setError(null);
291
- setInstance(null);
292
- try {
293
- const wasmInstance = await loadWasmModule(source, config.imports, cacheKey);
294
- setInstance(wasmInstance.exports);
295
- } catch (err) {
296
- setError(err instanceof Error ? err : new Error(String(err)));
297
- } finally {
298
- setLoading(false);
299
- }
300
- }
301
- load();
302
- return {
303
- instance,
304
- loading,
305
- error,
306
- ready: () => instance() !== null,
307
- reload: load
308
- };
309
- }
310
- async function loadWasmModule(source, imports, cacheKey) {
311
- const key = cacheKey || (typeof source === "string" ? source : void 0);
312
- if (key) {
313
- const cachedInstance = instanceCache.get(key);
314
- if (cachedInstance) {
315
- return cachedInstance;
316
- }
317
- }
318
- let module;
319
- const cachedModule = key ? moduleCache.get(key) : void 0;
320
- if (cachedModule) {
321
- module = cachedModule;
322
- } else {
323
- let bytes;
324
- if (typeof source === "string") {
325
- if (typeof WebAssembly.instantiateStreaming === "function") {
326
- const response2 = fetch(source);
327
- const result = await WebAssembly.instantiateStreaming(response2, imports || {});
328
- if (key) {
329
- moduleCache.set(key, result.module);
330
- instanceCache.set(key, result.instance);
331
- }
332
- return result.instance;
333
- }
334
- const response = await fetch(source);
335
- bytes = await response.arrayBuffer();
336
- } else if (source instanceof Uint8Array) {
337
- bytes = source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
338
- } else {
339
- bytes = source;
340
- }
341
- module = await WebAssembly.compile(bytes);
342
- if (key) moduleCache.set(key, module);
343
- }
344
- const instance = await WebAssembly.instantiate(module, imports || {});
345
- if (key) instanceCache.set(key, instance);
346
- return instance;
347
- }
348
- async function preloadWasm(url) {
349
- if (moduleCache.has(url)) return;
350
- let module;
351
- if (typeof WebAssembly.compileStreaming === "function") {
352
- module = await WebAssembly.compileStreaming(fetch(url));
353
- } else {
354
- const response = await fetch(url);
355
- const bytes = await response.arrayBuffer();
356
- module = await WebAssembly.compile(bytes);
357
- }
358
- moduleCache.set(url, module);
359
- }
360
- function createWasmBridge(instance) {
361
- const exports = instance.exports;
362
- const memory = exports.memory || instance.exports.memory;
363
- return {
364
- exports: instance.exports,
365
- memory,
366
- alloc(size) {
367
- if (!exports.malloc) throw new Error("WASM module does not export malloc");
368
- return exports.malloc(size);
369
- },
370
- free(ptr) {
371
- if (!exports.free) throw new Error("WASM module does not export free");
372
- exports.free(ptr);
373
- },
374
- writeString(str) {
375
- const encoder = new TextEncoder();
376
- const bytes = encoder.encode(str);
377
- if (!exports.malloc) throw new Error("WASM module does not export malloc");
378
- const ptr = exports.malloc(bytes.length);
379
- new Uint8Array(memory.buffer, ptr, bytes.length).set(bytes);
380
- return { ptr, len: bytes.length };
381
- },
382
- readString(ptr, len) {
383
- const decoder = new TextDecoder();
384
- return decoder.decode(new Uint8Array(memory.buffer, ptr, len));
385
- },
386
- writeArray(arr) {
387
- if (!exports.malloc) throw new Error("WASM module does not export malloc");
388
- const ptr = exports.malloc(arr.length * 8);
389
- new Float64Array(memory.buffer, ptr, arr.length).set(Array.from(arr));
390
- return { ptr, len: arr.length };
391
- },
392
- readF64Array(ptr, len) {
393
- return new Float64Array(memory.buffer, ptr, len);
394
- }
395
- };
396
- }
397
- function clearWasmCache() {
398
- moduleCache.clear();
399
- instanceCache.clear();
400
- }
401
- function isWasmCached(key) {
402
- return moduleCache.has(key);
403
- }
404
-
405
- // src/platform/microfrontend.ts
406
- var moduleCache2 = /* @__PURE__ */ new Map();
407
- function createMicroApp(config) {
408
- const host = config.container ?? document.createElement("div");
409
- host.setAttribute("data-micro-app", config.name);
410
- let root;
411
- if (config.shadow) {
412
- root = host.attachShadow({ mode: "open" });
413
- } else {
414
- root = host;
415
- }
416
- let mounted = false;
417
- function mount(component) {
418
- if (root instanceof ShadowRoot) {
419
- root.innerHTML = "";
420
- } else {
421
- while (root.firstChild) {
422
- root.removeChild(root.firstChild);
423
- }
424
- }
425
- const el = component();
426
- root.appendChild(el);
427
- mounted = true;
428
- }
429
- function unmount() {
430
- if (!mounted) return;
431
- if (root instanceof ShadowRoot) {
432
- root.innerHTML = "";
433
- } else {
434
- while (root.firstChild) {
435
- root.removeChild(root.firstChild);
436
- }
437
- }
438
- mounted = false;
439
- }
440
- return { mount, unmount, element: host };
441
- }
442
- function loadRemoteModule(url) {
443
- const cached = moduleCache2.get(url);
444
- if (cached) return cached;
445
- const promise = import(
446
- /* @vite-ignore */
447
- url
448
- );
449
- moduleCache2.set(url, promise);
450
- promise.catch(() => {
451
- moduleCache2.delete(url);
452
- });
453
- return promise;
454
- }
455
- function defineRemoteComponent(name, loader) {
456
- let cached = null;
457
- return function RemoteComponent() {
458
- if (cached) {
459
- return cached();
460
- }
461
- const container = div({
462
- class: "sibu-remote",
463
- "data-remote-component": name
464
- });
465
- container.appendChild(span({ class: "sibu-remote-loading", nodes: "Loading..." }));
466
- loader().then((mod) => {
467
- cached = mod.default;
468
- const rendered = cached();
469
- container.replaceChildren(rendered);
470
- }).catch((err) => {
471
- const message = err instanceof Error ? err.message : String(err);
472
- container.replaceChildren(
473
- div({
474
- class: "sibu-remote-error",
475
- nodes: `Failed to load remote component "${name}": ${message}`
476
- })
477
- );
478
- });
479
- return container;
480
- };
481
- }
482
- function createSharedScope(initialState) {
483
- const signals = /* @__PURE__ */ new Map();
484
- const subscribers = /* @__PURE__ */ new Map();
485
- for (const key of Object.keys(initialState)) {
486
- const [get2, set2] = signal(initialState[key]);
487
- signals.set(key, { get: get2, set: set2 });
488
- subscribers.set(key, /* @__PURE__ */ new Set());
489
- }
490
- function ensureSignal(key) {
491
- if (!signals.has(key)) {
492
- const [get2, set2] = signal(void 0);
493
- signals.set(key, { get: get2, set: set2 });
494
- subscribers.set(key, /* @__PURE__ */ new Set());
495
- }
496
- }
497
- function get(key) {
498
- ensureSignal(key);
499
- return signals.get(key)?.get();
500
- }
501
- function set(key, value) {
502
- ensureSignal(key);
503
- signals.get(key)?.set(value);
504
- const subs = subscribers.get(key);
505
- if (subs) {
506
- for (const cb of subs) {
507
- cb(value);
508
- }
509
- }
510
- }
511
- function subscribe(key, callback) {
512
- ensureSignal(key);
513
- const subs = subscribers.get(key);
514
- if (!subs) {
515
- return () => {
516
- };
517
- }
518
- subs.add(callback);
519
- return () => {
520
- subs.delete(callback);
521
- };
522
- }
523
- return { get, set, subscribe };
524
- }
525
-
526
- // src/platform/serviceWorker.ts
527
- function serviceWorker(scriptUrl, options) {
528
- const [registration, setRegistration] = signal(null);
529
- const [isReady, setIsReady] = signal(false);
530
- const [isUpdateAvailable, setIsUpdateAvailable] = signal(false);
531
- const [error, setError] = signal(null);
532
- if ("serviceWorker" in navigator) {
533
- navigator.serviceWorker.register(scriptUrl, options).then((reg) => {
534
- setRegistration(reg);
535
- setIsReady(true);
536
- reg.addEventListener("updatefound", () => {
537
- const newWorker = reg.installing;
538
- if (newWorker) {
539
- newWorker.addEventListener("statechange", () => {
540
- if (newWorker.state === "installed" && navigator.serviceWorker.controller) {
541
- setIsUpdateAvailable(true);
542
- }
543
- });
544
- }
545
- });
546
- }).catch((err) => {
547
- setError(err instanceof Error ? err : new Error(String(err)));
548
- });
549
- }
550
- async function update() {
551
- const reg = registration();
552
- if (reg) {
553
- await reg.update();
554
- }
555
- }
556
- async function unregister() {
557
- const reg = registration();
558
- if (reg) {
559
- const result = await reg.unregister();
560
- if (result) {
561
- setRegistration(null);
562
- setIsReady(false);
563
- }
564
- return result;
565
- }
566
- return false;
567
- }
568
- return { registration, isReady, isUpdateAvailable, error, update, unregister };
569
- }
570
-
571
- // src/platform/staticSiteGenerator.ts
572
- async function generateStaticSite(options) {
573
- const { routes, renderFn } = options;
574
- const pages = [];
575
- const errors = [];
576
- for (const route of routes) {
577
- try {
578
- const html = await renderFn(route);
579
- pages.push({ path: route, html });
580
- } catch (err) {
581
- errors.push({
582
- path: route,
583
- error: err instanceof Error ? err : new Error(String(err))
584
- });
585
- }
586
- }
587
- return { pages, errors };
588
- }
589
-
590
- // src/platform/incrementalRegeneration.ts
591
- function createISR(options) {
592
- const { revalidateAfter, fetcher, initialData } = options;
593
- const [data, setData] = signal(initialData);
594
- const [timestamp, setTimestamp] = signal(initialData !== void 0 ? Date.now() : 0);
595
- const isStale = () => {
596
- const ts = timestamp();
597
- if (ts === 0) return true;
598
- return Date.now() - ts >= revalidateAfter;
599
- };
600
- const revalidate = async () => {
601
- const result = await fetcher();
602
- setData(result);
603
- setTimestamp(Date.now());
604
- };
605
- if (initialData === void 0) {
606
- revalidate();
607
- }
608
- const intervalId = setInterval(() => {
609
- revalidate();
610
- }, revalidateAfter);
611
- const dispose = () => {
612
- clearInterval(intervalId);
613
- };
614
- return { data, isStale, revalidate, dispose };
615
- }
616
-
617
- // src/platform/routeActions.ts
618
- function createAction(actionFn) {
619
- const [data, setData] = signal(void 0);
620
- const [error, setError] = signal(void 0);
621
- const [loading, setLoading] = signal(false);
622
- const submit = async (input) => {
623
- batch(() => {
624
- setLoading(true);
625
- setError(void 0);
626
- });
627
- try {
628
- const result = await actionFn(input);
629
- batch(() => {
630
- setData(result);
631
- setLoading(false);
632
- });
633
- return result;
634
- } catch (err) {
635
- const actionError = err instanceof Error ? err : new Error(String(err));
636
- batch(() => {
637
- setError(actionError);
638
- setLoading(false);
639
- });
640
- throw actionError;
641
- }
642
- };
643
- return { data, error, loading, submit };
644
- }
645
-
646
- // src/platform/scrollRestoration.ts
647
- function scrollRestoration(options) {
648
- const mode = options?.mode ?? "auto";
649
- const positions = /* @__PURE__ */ new Map();
650
- let popstateHandler = null;
651
- let currentKey = null;
652
- const save = (key) => {
653
- positions.set(key, {
654
- x: window.scrollX,
655
- y: window.scrollY
656
- });
657
- currentKey = key;
658
- };
659
- const restore = (key) => {
660
- const pos = positions.get(key);
661
- if (pos) {
662
- window.scrollTo(pos.x, pos.y);
663
- }
664
- currentKey = key;
665
- };
666
- const getPosition = (key) => {
667
- return positions.get(key);
668
- };
669
- if (mode === "auto") {
670
- popstateHandler = () => {
671
- if (currentKey) {
672
- save(currentKey);
673
- }
674
- };
675
- window.addEventListener("popstate", popstateHandler);
676
- }
677
- const dispose = () => {
678
- if (popstateHandler) {
679
- window.removeEventListener("popstate", popstateHandler);
680
- popstateHandler = null;
681
- }
682
- positions.clear();
683
- };
684
- return { save, restore, getPosition, dispose };
685
- }
686
-
687
- // src/platform/routeMiddleware.ts
688
- function composeMiddleware(...fns) {
689
- return async (context, next) => {
690
- let index = -1;
691
- const dispatch = async (i) => {
692
- if (i <= index) {
693
- throw new Error("next() called multiple times");
694
- }
695
- index = i;
696
- if (i < fns.length) {
697
- await fns[i](context, () => dispatch(i + 1));
698
- } else {
699
- await next();
700
- }
701
- };
702
- await dispatch(0);
703
- };
704
- }
705
- function createMiddlewareChain() {
706
- const middlewares = [];
707
- const use = (fn) => {
708
- middlewares.push(fn);
709
- };
710
- const run = async (context) => {
711
- const composed = composeMiddleware(...middlewares);
712
- await composed(context, () => {
713
- });
714
- };
715
- return { use, run };
716
- }
717
-
718
- export {
719
- Head,
720
- setStructuredData,
721
- setCanonical,
722
- worker,
723
- workerFn,
724
- createWorkerPool,
725
- wasm,
726
- loadWasmModule,
727
- preloadWasm,
728
- createWasmBridge,
729
- clearWasmCache,
730
- isWasmCached,
731
- createMicroApp,
732
- loadRemoteModule,
733
- defineRemoteComponent,
734
- createSharedScope,
735
- serviceWorker,
736
- generateStaticSite,
737
- createISR,
738
- createAction,
739
- scrollRestoration,
740
- composeMiddleware,
741
- createMiddlewareChain
742
- };