sibujs 1.4.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 (190) hide show
  1. package/README.md +105 -119
  2. package/dist/browser.cjs +288 -80
  3. package/dist/browser.d.cts +19 -9
  4. package/dist/browser.d.ts +19 -9
  5. package/dist/browser.js +6 -6
  6. package/dist/build.cjs +1019 -313
  7. package/dist/build.d.cts +1 -1
  8. package/dist/build.d.ts +1 -1
  9. package/dist/build.js +15 -13
  10. package/dist/cdn.global.js +17 -16
  11. package/dist/chunk-2RA7SHDA.js +65 -0
  12. package/dist/chunk-2UPRY23K.js +80 -0
  13. package/dist/chunk-3JHCYHWN.js +125 -0
  14. package/dist/{chunk-ZWKZCBO6.js → chunk-3LR7GLWQ.js} +154 -33
  15. package/dist/{chunk-3AIRKM3B.js → chunk-3NSGB5JN.js} +115 -34
  16. package/dist/{chunk-3ARAQO7B.js → chunk-52YJLLRO.js} +29 -6
  17. package/dist/chunk-54EDRCEF.js +93 -0
  18. package/dist/chunk-7JDB7I65.js +1327 -0
  19. package/dist/{chunk-WZSPOOER.js → chunk-CC65Y57T.js} +8 -5
  20. package/dist/{chunk-23VV7YD3.js → chunk-DFPFITST.js} +25 -30
  21. package/dist/{chunk-WR5D4EGH.js → chunk-GTBNNBJ6.js} +14 -2
  22. package/dist/chunk-HB24TBAF.js +121 -0
  23. package/dist/{chunk-CZUGLNJS.js → chunk-ITX6OO3F.js} +3 -3
  24. package/dist/{chunk-JAKHTMQU.js → chunk-JA6667UN.js} +206 -46
  25. package/dist/{chunk-77L6NL3X.js → chunk-JXMMDLBY.js} +306 -183
  26. package/dist/{chunk-3X2YG6YM.js → chunk-JYD2PWXH.js} +59 -28
  27. package/dist/{chunk-F3FA4F32.js → chunk-KLRMB5ZS.js} +135 -79
  28. package/dist/{chunk-5X6PP2UK.js → chunk-LMLD24FC.js} +2 -2
  29. package/dist/{chunk-M4NLBH4I.js → chunk-LYTCUZ7H.js} +3 -2
  30. package/dist/{chunk-TSOKIX5Z.js → chunk-MIUAXB7K.js} +126 -74
  31. package/dist/{chunk-QWZG56ET.js → chunk-ND2664SF.js} +558 -190
  32. package/dist/{chunk-JCI5M6U6.js → chunk-O2MNQFLP.js} +261 -79
  33. package/dist/{chunk-EWFVA3TJ.js → chunk-R73P76YZ.js} +1 -1
  34. package/dist/{chunk-2BYQDGN3.js → chunk-SAHNHTFC.js} +234 -63
  35. package/dist/chunk-UCS6AMJ7.js +79 -0
  36. package/dist/{chunk-ZD6OAMTH.js → chunk-VLPPXTYG.js} +90 -35
  37. package/dist/{chunk-OUZZEE4S.js → chunk-WOMYAHHI.js} +17 -11
  38. package/dist/{contracts-xo5ckdRP.d.cts → contracts-ey_Qh8ef.d.cts} +7 -8
  39. package/dist/{contracts-xo5ckdRP.d.ts → contracts-ey_Qh8ef.d.ts} +7 -8
  40. package/dist/{customElement-D2DJp_xn.d.cts → customElement-CPfIrbvg.d.cts} +18 -9
  41. package/dist/{customElement-D2DJp_xn.d.ts → customElement-CPfIrbvg.d.ts} +18 -9
  42. package/dist/data.cjs +452 -100
  43. package/dist/data.d.cts +20 -2
  44. package/dist/data.d.ts +20 -2
  45. package/dist/data.js +11 -9
  46. package/dist/devtools.cjs +535 -247
  47. package/dist/devtools.d.cts +1 -1
  48. package/dist/devtools.d.ts +1 -1
  49. package/dist/devtools.js +34 -30
  50. package/dist/ecosystem.cjs +499 -143
  51. package/dist/ecosystem.d.cts +13 -11
  52. package/dist/ecosystem.d.ts +13 -11
  53. package/dist/ecosystem.js +12 -11
  54. package/dist/extras.cjs +3639 -1629
  55. package/dist/extras.d.cts +11 -11
  56. package/dist/extras.d.ts +11 -11
  57. package/dist/extras.js +58 -45
  58. package/dist/index.cjs +1023 -313
  59. package/dist/index.d.cts +128 -55
  60. package/dist/index.d.ts +128 -55
  61. package/dist/index.js +28 -16
  62. package/dist/{introspect-BumjnBKr.d.cts → introspect-BWNjNw64.d.cts} +22 -2
  63. package/dist/{introspect-CZrlcaYy.d.ts → introspect-cY2pg9pW.d.ts} +22 -2
  64. package/dist/motion.cjs +90 -36
  65. package/dist/motion.d.cts +1 -1
  66. package/dist/motion.d.ts +1 -1
  67. package/dist/motion.js +4 -4
  68. package/dist/patterns.cjs +414 -81
  69. package/dist/patterns.d.cts +53 -20
  70. package/dist/patterns.d.ts +53 -20
  71. package/dist/patterns.js +7 -7
  72. package/dist/performance.cjs +364 -108
  73. package/dist/performance.d.cts +29 -17
  74. package/dist/performance.d.ts +29 -17
  75. package/dist/performance.js +13 -6
  76. package/dist/plugin-D30wlGW5.d.cts +71 -0
  77. package/dist/plugin-D30wlGW5.d.ts +71 -0
  78. package/dist/plugins.cjs +652 -271
  79. package/dist/plugins.d.cts +13 -6
  80. package/dist/plugins.d.ts +13 -6
  81. package/dist/plugins.js +116 -50
  82. package/dist/{ssr-Do_SiVoL.d.cts → ssr-CrVNy6Pa.d.cts} +9 -15
  83. package/dist/{ssr-Do_SiVoL.d.ts → ssr-CrVNy6Pa.d.ts} +9 -15
  84. package/dist/{ssr-4PBXAOO3.js → ssr-FXD2PPMC.js} +4 -3
  85. package/dist/ssr.cjs +648 -219
  86. package/dist/ssr.d.cts +27 -7
  87. package/dist/ssr.d.ts +27 -7
  88. package/dist/ssr.js +12 -11
  89. package/dist/{tagFactory-DaJ0YWX6.d.ts → tagFactory-S17H2qxu.d.cts} +9 -1
  90. package/dist/{tagFactory-DaJ0YWX6.d.cts → tagFactory-S17H2qxu.d.ts} +9 -1
  91. package/dist/testing.cjs +252 -63
  92. package/dist/testing.d.cts +17 -4
  93. package/dist/testing.d.ts +17 -4
  94. package/dist/testing.js +100 -44
  95. package/dist/ui.cjs +576 -168
  96. package/dist/ui.d.cts +13 -16
  97. package/dist/ui.d.ts +13 -16
  98. package/dist/ui.js +20 -17
  99. package/dist/widgets.cjs +1001 -93
  100. package/dist/widgets.d.cts +104 -2
  101. package/dist/widgets.d.ts +104 -2
  102. package/dist/widgets.js +9 -7
  103. package/package.json +8 -2
  104. package/dist/chunk-32DY64NT.js +0 -282
  105. package/dist/chunk-3CRQALYP.js +0 -877
  106. package/dist/chunk-4EI4AG32.js +0 -482
  107. package/dist/chunk-4MYMUBRS.js +0 -21
  108. package/dist/chunk-6HLLIF3K.js +0 -398
  109. package/dist/chunk-6LSNVCS2.js +0 -937
  110. package/dist/chunk-6SA3QQES.js +0 -61
  111. package/dist/chunk-7BF6TK55.js +0 -1097
  112. package/dist/chunk-7TQKR4PP.js +0 -294
  113. package/dist/chunk-7V26P53V.js +0 -712
  114. package/dist/chunk-AZ3ISID5.js +0 -298
  115. package/dist/chunk-B7SWRFUT.js +0 -332
  116. package/dist/chunk-BGN5ZMP4.js +0 -26
  117. package/dist/chunk-BTU3TJDS.js +0 -365
  118. package/dist/chunk-BW3WT46K.js +0 -937
  119. package/dist/chunk-C6KFWOFV.js +0 -616
  120. package/dist/chunk-CHF5OHIA.js +0 -61
  121. package/dist/chunk-CHJ27IGK.js +0 -26
  122. package/dist/chunk-CMBFNA7L.js +0 -27
  123. package/dist/chunk-DAHRH4ON.js +0 -331
  124. package/dist/chunk-DKOHBI74.js +0 -924
  125. package/dist/chunk-DTCOOBMX.js +0 -725
  126. package/dist/chunk-EBGIRKQY.js +0 -616
  127. package/dist/chunk-EUZND3CB.js +0 -27
  128. package/dist/chunk-EVCZO745.js +0 -365
  129. package/dist/chunk-FGOEVHY3.js +0 -60
  130. package/dist/chunk-G3BOQPVO.js +0 -365
  131. package/dist/chunk-GCOK2LC3.js +0 -282
  132. package/dist/chunk-HGMJFBC7.js +0 -654
  133. package/dist/chunk-K5ZUMYVS.js +0 -89
  134. package/dist/chunk-KQPDEVVS.js +0 -398
  135. package/dist/chunk-L6JRBDNS.js +0 -60
  136. package/dist/chunk-LA6KQEDU.js +0 -712
  137. package/dist/chunk-MDVXJWFN.js +0 -304
  138. package/dist/chunk-MEZVEBPN.js +0 -2008
  139. package/dist/chunk-MK4ERFYL.js +0 -2249
  140. package/dist/chunk-MLKGABMK.js +0 -9
  141. package/dist/chunk-MQ5GOYPH.js +0 -2249
  142. package/dist/chunk-N6IZB6KJ.js +0 -567
  143. package/dist/chunk-NEKUBFPT.js +0 -60
  144. package/dist/chunk-NHUC2QWH.js +0 -282
  145. package/dist/chunk-NMRUZALC.js +0 -1097
  146. package/dist/chunk-NYVAC6P5.js +0 -37
  147. package/dist/chunk-OF7UZIVB.js +0 -725
  148. package/dist/chunk-P6W3STU4.js +0 -2249
  149. package/dist/chunk-PBHF5WKN.js +0 -616
  150. package/dist/chunk-PTQJDMRT.js +0 -146
  151. package/dist/chunk-PZEGYCF5.js +0 -61
  152. package/dist/chunk-QBMDLBU2.js +0 -975
  153. package/dist/chunk-RQGQSLQK.js +0 -725
  154. package/dist/chunk-SDLZDHKP.js +0 -107
  155. package/dist/chunk-TNQWPPE6.js +0 -37
  156. package/dist/chunk-UHNL42EF.js +0 -2730
  157. package/dist/chunk-UNXCEF6S.js +0 -21
  158. package/dist/chunk-V2XTI523.js +0 -347
  159. package/dist/chunk-VAU366PN.js +0 -2241
  160. package/dist/chunk-VMVDTCXB.js +0 -712
  161. package/dist/chunk-VRW3FULF.js +0 -725
  162. package/dist/chunk-WADYRCO2.js +0 -304
  163. package/dist/chunk-WILQZRO4.js +0 -282
  164. package/dist/chunk-WUHJISPP.js +0 -298
  165. package/dist/chunk-XYU6TZOW.js +0 -182
  166. package/dist/chunk-Y6GP4QGG.js +0 -276
  167. package/dist/chunk-YECR7UIA.js +0 -347
  168. package/dist/chunk-YUTWTI4B.js +0 -654
  169. package/dist/chunk-Z65KYU7I.js +0 -26
  170. package/dist/chunk-Z6POF5YC.js +0 -975
  171. package/dist/chunk-ZBJP6WFL.js +0 -482
  172. package/dist/contracts-DDrwxvJ-.d.cts +0 -245
  173. package/dist/contracts-DDrwxvJ-.d.ts +0 -245
  174. package/dist/contracts-DOrhwbke.d.cts +0 -245
  175. package/dist/contracts-DOrhwbke.d.ts +0 -245
  176. package/dist/customElement-BKQfbSZQ.d.cts +0 -262
  177. package/dist/customElement-BKQfbSZQ.d.ts +0 -262
  178. package/dist/customElement-yz8uyk-0.d.cts +0 -308
  179. package/dist/customElement-yz8uyk-0.d.ts +0 -308
  180. package/dist/introspect-Cb0zgpi2.d.cts +0 -477
  181. package/dist/introspect-Y2xNXGSf.d.ts +0 -477
  182. package/dist/plugin-Bek4RhJY.d.cts +0 -43
  183. package/dist/plugin-Bek4RhJY.d.ts +0 -43
  184. package/dist/ssr-3RXHP5ES.js +0 -38
  185. package/dist/ssr-6GIMY5MX.js +0 -38
  186. package/dist/ssr-BA6sxxUd.d.cts +0 -135
  187. package/dist/ssr-BA6sxxUd.d.ts +0 -135
  188. package/dist/ssr-WKUPVSSK.js +0 -36
  189. package/dist/tagFactory-Dl8QCLga.d.cts +0 -23
  190. package/dist/tagFactory-Dl8QCLga.d.ts +0 -23
@@ -1,725 +0,0 @@
1
- import {
2
- renderToString
3
- } from "./chunk-3X2YG6YM.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
- };