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,725 +0,0 @@
1
- import {
2
- renderToString
3
- } from "./chunk-WUHJISPP.js";
4
-
5
- // src/plugins/modular.ts
6
- function createModuleRegistry() {
7
- const modules = /* @__PURE__ */ new Map();
8
- function resolveInternal(name, stack) {
9
- const entry = modules.get(name);
10
- if (!entry) {
11
- throw new Error(`[ModuleRegistry] Module "${name}" is not registered.`);
12
- }
13
- if (entry.loaded) {
14
- return entry.value;
15
- }
16
- if (stack.has(name)) {
17
- const cycle = [...stack, name].join(" -> ");
18
- throw new Error(`[ModuleRegistry] Circular dependency detected: ${cycle}`);
19
- }
20
- stack.add(name);
21
- for (const dep of entry.deps) {
22
- resolveInternal(dep, stack);
23
- }
24
- stack.delete(name);
25
- entry.value = entry.factory();
26
- entry.loaded = true;
27
- return entry.value;
28
- }
29
- return {
30
- /** Register a module with its factory function and optional dependencies */
31
- register(name, factory, deps = []) {
32
- modules.set(name, { factory, deps, loaded: false });
33
- },
34
- /** Resolve a module, loading its dependencies first */
35
- resolve(name) {
36
- return resolveInternal(name, /* @__PURE__ */ new Set());
37
- },
38
- /** Check if a module is registered */
39
- has(name) {
40
- return modules.has(name);
41
- },
42
- /** List all registered module names */
43
- list() {
44
- return Array.from(modules.keys());
45
- },
46
- /** Get the full dependency graph (transitive) for a module */
47
- deps(name) {
48
- const entry = modules.get(name);
49
- if (!entry) {
50
- throw new Error(`[ModuleRegistry] Module "${name}" is not registered.`);
51
- }
52
- const visited = /* @__PURE__ */ new Set();
53
- const result = [];
54
- function walk(modName) {
55
- const mod = modules.get(modName);
56
- if (!mod) return;
57
- for (const dep of mod.deps) {
58
- if (!visited.has(dep)) {
59
- visited.add(dep);
60
- walk(dep);
61
- result.push(dep);
62
- }
63
- }
64
- }
65
- walk(name);
66
- return result;
67
- },
68
- /** Reset all loaded modules back to unloaded state (useful for testing) */
69
- reset() {
70
- for (const entry of modules.values()) {
71
- entry.loaded = false;
72
- entry.value = void 0;
73
- }
74
- }
75
- };
76
- }
77
- function createBundle(modules) {
78
- const cache = /* @__PURE__ */ new Map();
79
- const bundle = {};
80
- for (const key of Object.keys(modules)) {
81
- Object.defineProperty(bundle, key, {
82
- get() {
83
- if (cache.has(key)) {
84
- return cache.get(key);
85
- }
86
- const value = modules[key]();
87
- cache.set(key, value);
88
- return value;
89
- },
90
- enumerable: true,
91
- configurable: false
92
- });
93
- }
94
- return bundle;
95
- }
96
- function lazyModule(loader) {
97
- let cached;
98
- let loadedFlag = false;
99
- const handle = {
100
- get loaded() {
101
- return loadedFlag;
102
- },
103
- async get() {
104
- if (loadedFlag && cached !== void 0) {
105
- return cached;
106
- }
107
- cached = await loader();
108
- loadedFlag = true;
109
- return cached;
110
- }
111
- };
112
- return handle;
113
- }
114
- var packageInfo = {
115
- name: "sibu",
116
- version: "1.0.0",
117
- entryPoints: {
118
- main: "./index.ts",
119
- core: "./src/core/html.ts",
120
- hooks: "./src/core/signals/signal.ts",
121
- router: "./src/plugins/router.ts",
122
- i18n: "./src/plugins/i18n.ts",
123
- testing: "./src/testing/index.ts",
124
- ssr: "./src/core/ssr.ts"
125
- },
126
- /**
127
- * Generate a package.json `exports` map for Node.js subpath exports.
128
- * Maps each entry point to its import, require, and types paths.
129
- */
130
- generateExportsMap() {
131
- const exportsMap = {};
132
- for (const [name, sourcePath] of Object.entries(this.entryPoints)) {
133
- const distPath = sourcePath.replace(/^\.\//, "./dist/").replace(/\.ts$/, "");
134
- const subpath = name === "main" ? "." : `./${name}`;
135
- exportsMap[subpath] = {
136
- import: `${distPath}.mjs`,
137
- require: `${distPath}.cjs`,
138
- types: `${distPath}.d.ts`
139
- };
140
- }
141
- return exportsMap;
142
- }
143
- };
144
-
145
- // src/plugins/ecosystem.ts
146
- function createTestHarness() {
147
- let container;
148
- return {
149
- /** Set up a clean DOM container before each test */
150
- setup() {
151
- container = document.createElement("div");
152
- container.setAttribute("data-sibu-test", "true");
153
- document.body.appendChild(container);
154
- return container;
155
- },
156
- /** Tear down the DOM container after each test */
157
- teardown() {
158
- if (container?.parentNode) {
159
- container.parentNode.removeChild(container);
160
- }
161
- },
162
- /** Render a component into the test container */
163
- render(component) {
164
- const el = typeof component === "function" ? component() : component;
165
- container.appendChild(el);
166
- return el;
167
- },
168
- /** Get the test container */
169
- getContainer() {
170
- return container;
171
- },
172
- /** Wait for reactive updates to settle */
173
- async flush() {
174
- await new Promise((r) => setTimeout(r, 0));
175
- await new Promise((r) => requestAnimationFrame(() => r()));
176
- },
177
- /** Query within the container */
178
- query(selector) {
179
- return container.querySelector(selector);
180
- },
181
- /** Query all matching elements within the container */
182
- queryAll(selector) {
183
- return Array.from(container.querySelectorAll(selector));
184
- },
185
- /** Simulate a click event */
186
- click(el) {
187
- el.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
188
- },
189
- /** Simulate input value change */
190
- input(el, value) {
191
- el.value = value;
192
- el.dispatchEvent(new Event("input", { bubbles: true }));
193
- }
194
- };
195
- }
196
- var bundlerMetadata = {
197
- name: "sibu",
198
- sideEffects: false,
199
- modules: {
200
- core: ["html", "mount", "each", "slots", "fragment", "catch", "portal", "directives"],
201
- hooks: ["signal", "effect", "derived", "watch", "store", "ref", "memo", "memoFn", "array", "deepSignal"],
202
- plugins: ["router", "i18n"],
203
- components: ["ErrorBoundary", "Loading"],
204
- ssr: ["ssr"],
205
- advanced: ["globalStore", "machine", "optimistic", "timeTravel", "scheduler", "plugin"]
206
- },
207
- /** Generate import map for module resolution */
208
- generateImportMap(base = "/node_modules/sibu/") {
209
- const map = {};
210
- for (const [category, modules] of Object.entries(this.modules)) {
211
- for (const mod of modules) {
212
- const dir = category === "hooks" ? "core" : category;
213
- map[`sibu/${mod}`] = `${base}src/${dir}/${mod}.js`;
214
- }
215
- }
216
- return map;
217
- }
218
- };
219
- function healthCheck() {
220
- const checks = [];
221
- const hasDOM = typeof document !== "undefined";
222
- checks.push({
223
- name: "DOM Environment",
224
- passed: hasDOM,
225
- message: hasDOM ? "DOM is available" : "No DOM environment (SSR mode)"
226
- });
227
- const hasRAF = typeof requestAnimationFrame !== "undefined";
228
- checks.push({
229
- name: "requestAnimationFrame",
230
- passed: hasRAF,
231
- message: hasRAF ? "Available" : "Not available (polyfill may be needed)"
232
- });
233
- const hasMO = typeof MutationObserver !== "undefined";
234
- checks.push({
235
- name: "MutationObserver",
236
- passed: hasMO,
237
- message: hasMO ? "Available" : "Not available (lifecycle hooks may not work)"
238
- });
239
- const allPassed = checks.every((c) => c.passed);
240
- return {
241
- status: allPassed ? "ok" : "warning",
242
- checks
243
- };
244
- }
245
- var env = {
246
- /** True when running in a browser with a DOM */
247
- isBrowser: typeof window !== "undefined" && typeof document !== "undefined",
248
- /** True when running in Node.js */
249
- isNode: typeof process !== "undefined" && !!process.versions?.node,
250
- /** True when running inside a Web Worker */
251
- isWorker: typeof self !== "undefined" && typeof self.importScripts === "function",
252
- /** True when running inside Deno */
253
- isDeno: typeof globalThis.Deno !== "undefined",
254
- /** True when running inside Bun */
255
- isBun: typeof globalThis.Bun !== "undefined",
256
- /** True when no window object is available (server-side rendering) */
257
- isSSR: typeof window === "undefined",
258
- /** True when NODE_ENV is not "production" */
259
- isDev: typeof process !== "undefined" && process.env?.NODE_ENV !== "production",
260
- /** True when NODE_ENV is "test" or VITEST is set */
261
- isTest: typeof process !== "undefined" && (process.env?.NODE_ENV === "test" || process.env?.VITEST === "true")
262
- };
263
-
264
- // src/plugins/versioning.ts
265
- var VERSION = "1.0.0";
266
- function parseSemVer(version) {
267
- const trimmed = version.trim().replace(/^v/i, "");
268
- const prereleaseIndex = trimmed.indexOf("-");
269
- let main;
270
- let prerelease;
271
- if (prereleaseIndex !== -1) {
272
- main = trimmed.slice(0, prereleaseIndex);
273
- prerelease = trimmed.slice(prereleaseIndex + 1);
274
- } else {
275
- main = trimmed;
276
- }
277
- const parts = main.split(".");
278
- const major = parseInt(parts[0], 10);
279
- const minor = parseInt(parts[1] || "0", 10);
280
- const patch = parseInt(parts[2] || "0", 10);
281
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) {
282
- throw new Error(`[Versioning] Invalid semver string: "${version}"`);
283
- }
284
- const result = { major, minor, patch };
285
- if (prerelease !== void 0) {
286
- result.prerelease = prerelease;
287
- }
288
- return result;
289
- }
290
- function compareSemVer(a, b) {
291
- const va = typeof a === "string" ? parseSemVer(a) : a;
292
- const vb = typeof b === "string" ? parseSemVer(b) : b;
293
- if (va.major !== vb.major) return va.major > vb.major ? 1 : -1;
294
- if (va.minor !== vb.minor) return va.minor > vb.minor ? 1 : -1;
295
- if (va.patch !== vb.patch) return va.patch > vb.patch ? 1 : -1;
296
- if (va.prerelease === void 0 && vb.prerelease === void 0) return 0;
297
- if (va.prerelease === void 0) return 1;
298
- if (vb.prerelease === void 0) return -1;
299
- const aParts = va.prerelease.split(".");
300
- const bParts = vb.prerelease.split(".");
301
- const len = Math.max(aParts.length, bParts.length);
302
- for (let i = 0; i < len; i++) {
303
- if (i >= aParts.length) return -1;
304
- if (i >= bParts.length) return 1;
305
- const aId = aParts[i];
306
- const bId = bParts[i];
307
- const aNum = parseInt(aId, 10);
308
- const bNum = parseInt(bId, 10);
309
- const aIsNum = !Number.isNaN(aNum) && String(aNum) === aId;
310
- const bIsNum = !Number.isNaN(bNum) && String(bNum) === bId;
311
- if (aIsNum && bIsNum) {
312
- if (aNum !== bNum) return aNum > bNum ? 1 : -1;
313
- } else if (aIsNum) {
314
- return -1;
315
- } else if (bIsNum) {
316
- return 1;
317
- } else {
318
- if (aId < bId) return -1;
319
- if (aId > bId) return 1;
320
- }
321
- }
322
- return 0;
323
- }
324
- function satisfies(version, range) {
325
- const v = parseSemVer(version);
326
- const trimmed = range.trim();
327
- if (trimmed.includes("||")) {
328
- return trimmed.split("||").some((part) => satisfies(version, part.trim()));
329
- }
330
- if (/\s+/.test(trimmed) && !trimmed.startsWith("^") && !trimmed.startsWith("~")) {
331
- const parts = trimmed.split(/\s+/);
332
- return parts.every((part) => satisfies(version, part));
333
- }
334
- if (trimmed.startsWith("^")) {
335
- const target2 = parseSemVer(trimmed.slice(1));
336
- if (v.major !== target2.major) return false;
337
- if (target2.major === 0) {
338
- if (v.minor !== target2.minor) return false;
339
- if (target2.minor === 0) {
340
- return v.patch === target2.patch;
341
- }
342
- return v.patch >= target2.patch;
343
- }
344
- return compareSemVer(v, target2) >= 0;
345
- }
346
- if (trimmed.startsWith("~")) {
347
- const target2 = parseSemVer(trimmed.slice(1));
348
- return v.major === target2.major && v.minor === target2.minor && v.patch >= target2.patch;
349
- }
350
- if (trimmed.startsWith(">=")) {
351
- const target2 = parseSemVer(trimmed.slice(2));
352
- return compareSemVer(v, target2) >= 0;
353
- }
354
- if (trimmed.startsWith("<=")) {
355
- const target2 = parseSemVer(trimmed.slice(2));
356
- return compareSemVer(v, target2) <= 0;
357
- }
358
- if (trimmed.startsWith(">") && !trimmed.startsWith(">=")) {
359
- const target2 = parseSemVer(trimmed.slice(1));
360
- return compareSemVer(v, target2) > 0;
361
- }
362
- if (trimmed.startsWith("<") && !trimmed.startsWith("<=")) {
363
- const target2 = parseSemVer(trimmed.slice(1));
364
- return compareSemVer(v, target2) < 0;
365
- }
366
- const exactStr = trimmed.startsWith("=") ? trimmed.slice(1) : trimmed;
367
- const target = parseSemVer(exactStr);
368
- return compareSemVer(v, target) === 0;
369
- }
370
- function createMigrationRunner(config) {
371
- const storageKey = config.storageKey || "__sibu_migration_version__";
372
- const sortedMigrations = [...config.migrations].sort((a, b) => compareSemVer(a.version, b.version));
373
- function getStorage() {
374
- try {
375
- return typeof localStorage !== "undefined" ? localStorage : null;
376
- } catch {
377
- return null;
378
- }
379
- }
380
- return {
381
- /** Get the last applied migration version from storage */
382
- getAppliedVersion() {
383
- const storage = getStorage();
384
- if (!storage) return null;
385
- return storage.getItem(storageKey);
386
- },
387
- /** Get pending migrations that haven't been applied */
388
- getPending() {
389
- const appliedVersion = this.getAppliedVersion();
390
- if (!appliedVersion) {
391
- return sortedMigrations.filter((m) => compareSemVer(m.version, config.currentVersion) <= 0);
392
- }
393
- return sortedMigrations.filter(
394
- (m) => compareSemVer(m.version, appliedVersion) > 0 && compareSemVer(m.version, config.currentVersion) <= 0
395
- );
396
- },
397
- /** Run all pending migrations in order */
398
- async migrate() {
399
- const pending = this.getPending();
400
- const applied = [];
401
- const errors = [];
402
- for (const migration of pending) {
403
- try {
404
- await migration.up();
405
- applied.push(migration.version);
406
- const storage = getStorage();
407
- if (storage) {
408
- storage.setItem(storageKey, migration.version);
409
- }
410
- } catch (e) {
411
- errors.push({
412
- version: migration.version,
413
- error: e instanceof Error ? e : new Error(String(e))
414
- });
415
- break;
416
- }
417
- }
418
- return { applied, errors };
419
- },
420
- /** Rollback to a specific version */
421
- async rollback(targetVersion) {
422
- const appliedVersion = this.getAppliedVersion();
423
- const rolledBack = [];
424
- if (!appliedVersion) {
425
- return { rolledBack };
426
- }
427
- const toRollback = sortedMigrations.filter((m) => compareSemVer(m.version, targetVersion) > 0 && compareSemVer(m.version, appliedVersion) <= 0).reverse();
428
- for (const migration of toRollback) {
429
- if (!migration.down) {
430
- throw new Error(
431
- `[Versioning] Migration ${migration.version} ("${migration.description}") does not have a down() function and cannot be rolled back.`
432
- );
433
- }
434
- await migration.down();
435
- rolledBack.push(migration.version);
436
- }
437
- const storage = getStorage();
438
- if (storage) {
439
- if (targetVersion === "0.0.0") {
440
- storage.removeItem(storageKey);
441
- } else {
442
- storage.setItem(storageKey, targetVersion);
443
- }
444
- }
445
- return { rolledBack };
446
- }
447
- };
448
- }
449
- function checkCompatibility(frameworkVersion, requiredRange) {
450
- const compatible = satisfies(frameworkVersion, requiredRange);
451
- if (compatible) {
452
- return {
453
- compatible: true,
454
- message: `Framework version ${frameworkVersion} is compatible with required range "${requiredRange}".`
455
- };
456
- }
457
- const fv = parseSemVer(frameworkVersion);
458
- const rangeTarget = extractRangeTarget(requiredRange);
459
- let message = `Framework version ${frameworkVersion} is NOT compatible with required range "${requiredRange}".`;
460
- if (rangeTarget) {
461
- const tv = parseSemVer(rangeTarget);
462
- if (fv.major < tv.major) {
463
- message += ` A major upgrade is required (${fv.major}.x -> ${tv.major}.x).`;
464
- } else if (fv.major > tv.major) {
465
- message += " The framework version is ahead of the required range. Consider updating the dependency requirement.";
466
- }
467
- }
468
- return { compatible, message };
469
- }
470
- function extractRangeTarget(range) {
471
- const match = range.match(/[\d]+\.[\d]+\.[\d]+(?:-[\w.]+)?/);
472
- return match ? match[0] : null;
473
- }
474
-
475
- // src/plugins/startup.ts
476
- function preloadCritical(resources) {
477
- if (typeof document === "undefined") return;
478
- for (const resource of resources) {
479
- const existing = document.querySelector(`link[rel="preload"][href="${resource.href}"]`);
480
- if (existing) continue;
481
- const link = document.createElement("link");
482
- link.rel = "preload";
483
- link.href = resource.href;
484
- link.setAttribute("as", resource.as);
485
- if (resource.type) {
486
- link.type = resource.type;
487
- }
488
- if (resource.crossOrigin) {
489
- link.crossOrigin = resource.crossOrigin;
490
- }
491
- document.head.appendChild(link);
492
- }
493
- }
494
- function prerenderRoutes(routes, options) {
495
- const maxCacheSize = options?.maxCacheSize ?? 50;
496
- const cacheTTL = options?.cacheTTL ?? 0;
497
- const cache = /* @__PURE__ */ new Map();
498
- function isValid(entry) {
499
- if (cacheTTL === 0) return true;
500
- return Date.now() - entry.timestamp < cacheTTL;
501
- }
502
- function evictOldest() {
503
- if (cache.size < maxCacheSize) return;
504
- let oldestKey = null;
505
- let oldestTime = Infinity;
506
- for (const [key, entry] of cache) {
507
- if (entry.timestamp < oldestTime) {
508
- oldestTime = entry.timestamp;
509
- oldestKey = key;
510
- }
511
- }
512
- if (oldestKey) cache.delete(oldestKey);
513
- }
514
- for (const route of routes) {
515
- evictOldest();
516
- const html = renderToString(route.component());
517
- cache.set(route.path, { html, timestamp: Date.now() });
518
- }
519
- return {
520
- /** Get cached HTML for a route, or undefined if not cached or expired */
521
- get(path) {
522
- const entry = cache.get(path);
523
- if (!entry) return void 0;
524
- if (!isValid(entry)) {
525
- cache.delete(path);
526
- return void 0;
527
- }
528
- return entry.html;
529
- },
530
- /** Check if a route has been prerendered and is still valid */
531
- has(path) {
532
- const entry = cache.get(path);
533
- if (!entry) return false;
534
- if (!isValid(entry)) {
535
- cache.delete(path);
536
- return false;
537
- }
538
- return true;
539
- },
540
- /** Invalidate a cached route */
541
- invalidate(path) {
542
- cache.delete(path);
543
- },
544
- /** Clear all cached routes */
545
- clear() {
546
- cache.clear();
547
- },
548
- /** Get cache statistics */
549
- stats() {
550
- if (cacheTTL > 0) {
551
- for (const [key, entry] of cache) {
552
- if (!isValid(entry)) {
553
- cache.delete(key);
554
- }
555
- }
556
- }
557
- return {
558
- size: cache.size,
559
- routes: Array.from(cache.keys())
560
- };
561
- }
562
- };
563
- }
564
- function createSSRCache(config) {
565
- const maxSize = config?.maxSize ?? 100;
566
- const defaultTTL = config?.defaultTTL ?? 6e4;
567
- const cache = /* @__PURE__ */ new Map();
568
- let hits = 0;
569
- let misses = 0;
570
- function isValid(entry) {
571
- if (entry.ttl === 0) return true;
572
- return Date.now() - entry.timestamp < entry.ttl;
573
- }
574
- function evictOldest() {
575
- if (cache.size < maxSize) return;
576
- let oldestKey = null;
577
- let oldestTime = Infinity;
578
- for (const [key, entry] of cache) {
579
- if (entry.timestamp < oldestTime) {
580
- oldestTime = entry.timestamp;
581
- oldestKey = key;
582
- }
583
- }
584
- if (oldestKey) cache.delete(oldestKey);
585
- }
586
- return {
587
- /** Get cached HTML for a key, or undefined if not cached or expired */
588
- get(key) {
589
- const entry = cache.get(key);
590
- if (!entry) {
591
- misses++;
592
- return void 0;
593
- }
594
- if (!isValid(entry)) {
595
- cache.delete(key);
596
- misses++;
597
- return void 0;
598
- }
599
- hits++;
600
- return entry.html;
601
- },
602
- /** Cache an HTML string with an optional TTL override */
603
- set(key, html, ttl) {
604
- evictOldest();
605
- cache.set(key, {
606
- html,
607
- timestamp: Date.now(),
608
- ttl: ttl ?? defaultTTL
609
- });
610
- },
611
- /** Check if a key exists in the cache and is still valid */
612
- has(key) {
613
- const entry = cache.get(key);
614
- if (!entry) return false;
615
- if (!isValid(entry)) {
616
- cache.delete(key);
617
- return false;
618
- }
619
- return true;
620
- },
621
- /** Invalidate a cached entry */
622
- invalidate(key) {
623
- cache.delete(key);
624
- },
625
- /** Clear all cached entries and reset statistics */
626
- clear() {
627
- cache.clear();
628
- hits = 0;
629
- misses = 0;
630
- },
631
- /** Get cache statistics including hit/miss counts */
632
- stats() {
633
- return { size: cache.size, hits, misses };
634
- }
635
- };
636
- }
637
- function deferNonCritical(tasks) {
638
- if (tasks.length === 0) return;
639
- const schedule = typeof requestIdleCallback !== "undefined" ? requestIdleCallback : (cb) => setTimeout(cb, 1);
640
- const queue = [...tasks];
641
- let index = 0;
642
- function processNext(deadline) {
643
- while (index < queue.length) {
644
- if (deadline && deadline.timeRemaining() < 1) {
645
- schedule(processNext);
646
- return;
647
- }
648
- try {
649
- queue[index]();
650
- } catch (e) {
651
- if (typeof console !== "undefined") {
652
- console.error("[Startup] Deferred task failed:", e);
653
- }
654
- }
655
- index++;
656
- }
657
- }
658
- schedule(processNext);
659
- }
660
- function createBootSequence() {
661
- const criticalTasks = [];
662
- const deferredTasks = [];
663
- return {
664
- /** Add a critical task that runs immediately during boot */
665
- critical(name, task) {
666
- criticalTasks.push({ name, task });
667
- },
668
- /** Add a deferred task that runs after all critical tasks complete */
669
- defer(name, task) {
670
- deferredTasks.push({ name, task });
671
- },
672
- /** Execute the boot sequence: critical tasks first, then deferred */
673
- async boot() {
674
- const timing = {};
675
- const errors = [];
676
- for (const entry of criticalTasks) {
677
- const start = Date.now();
678
- try {
679
- await entry.task();
680
- } catch (e) {
681
- errors.push({
682
- name: entry.name,
683
- error: e instanceof Error ? e : new Error(String(e))
684
- });
685
- }
686
- timing[entry.name] = Date.now() - start;
687
- }
688
- for (const entry of deferredTasks) {
689
- const start = Date.now();
690
- try {
691
- await entry.task();
692
- } catch (e) {
693
- errors.push({
694
- name: entry.name,
695
- error: e instanceof Error ? e : new Error(String(e))
696
- });
697
- }
698
- timing[entry.name] = Date.now() - start;
699
- }
700
- return { timing, errors };
701
- }
702
- };
703
- }
704
-
705
- export {
706
- createModuleRegistry,
707
- createBundle,
708
- lazyModule,
709
- packageInfo,
710
- createTestHarness,
711
- bundlerMetadata,
712
- healthCheck,
713
- env,
714
- VERSION,
715
- parseSemVer,
716
- compareSemVer,
717
- satisfies,
718
- createMigrationRunner,
719
- checkCompatibility,
720
- preloadCritical,
721
- prerenderRoutes,
722
- createSSRCache,
723
- deferNonCritical,
724
- createBootSequence
725
- };