sibujs 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1630 -0
  3. package/dist/browser.cjs +815 -0
  4. package/dist/browser.d.cts +174 -0
  5. package/dist/browser.d.ts +174 -0
  6. package/dist/browser.js +458 -0
  7. package/dist/build.cjs +4970 -0
  8. package/dist/build.d.cts +630 -0
  9. package/dist/build.d.ts +630 -0
  10. package/dist/build.js +2478 -0
  11. package/dist/cdn.global.js +115 -0
  12. package/dist/chunk-27QC4FPL.js +67 -0
  13. package/dist/chunk-2ABBWCGC.js +65 -0
  14. package/dist/chunk-2MUNQYZ7.js +26 -0
  15. package/dist/chunk-2PSPKNUI.js +1711 -0
  16. package/dist/chunk-35CDLDX5.js +1758 -0
  17. package/dist/chunk-36MU4CFV.js +41 -0
  18. package/dist/chunk-3FIQOFI6.js +182 -0
  19. package/dist/chunk-3GHNC2BN.js +28 -0
  20. package/dist/chunk-3HLWWEPU.js +909 -0
  21. package/dist/chunk-3IVI3J54.js +252 -0
  22. package/dist/chunk-3KZ72WNW.js +944 -0
  23. package/dist/chunk-4AU64SQV.js +182 -0
  24. package/dist/chunk-4MOK7HAR.js +84 -0
  25. package/dist/chunk-4QK6FBDH.js +1429 -0
  26. package/dist/chunk-566Z7HXB.js +737 -0
  27. package/dist/chunk-5CRBB7XP.js +358 -0
  28. package/dist/chunk-5G67D3IZ.js +168 -0
  29. package/dist/chunk-5NCPAWBE.js +99 -0
  30. package/dist/chunk-5O2RKXR3.js +1444 -0
  31. package/dist/chunk-6BTBDO6A.js +633 -0
  32. package/dist/chunk-6IWEHW57.js +43 -0
  33. package/dist/chunk-6JGMNCD6.js +282 -0
  34. package/dist/chunk-6QRLJNXR.js +1425 -0
  35. package/dist/chunk-7HM5UE5T.js +270 -0
  36. package/dist/chunk-7JOLTGUH.js +58 -0
  37. package/dist/chunk-7MCWJCQK.js +909 -0
  38. package/dist/chunk-7RIIFP3E.js +1758 -0
  39. package/dist/chunk-7UASYN3G.js +254 -0
  40. package/dist/chunk-7W2WYHDI.js +741 -0
  41. package/dist/chunk-7Y35RDSJ.js +872 -0
  42. package/dist/chunk-A65GFJBL.js +65 -0
  43. package/dist/chunk-AD6ZIEDK.js +67 -0
  44. package/dist/chunk-AK5Y72F3.js +1426 -0
  45. package/dist/chunk-APOMMWH4.js +282 -0
  46. package/dist/chunk-ARZVTWIQ.js +1750 -0
  47. package/dist/chunk-AWWBM2BI.js +664 -0
  48. package/dist/chunk-AX5VEQTY.js +58 -0
  49. package/dist/chunk-AYTXVOW3.js +1708 -0
  50. package/dist/chunk-BG4A246G.js +1746 -0
  51. package/dist/chunk-BNFJJA2L.js +1425 -0
  52. package/dist/chunk-BPKPBVU5.js +59 -0
  53. package/dist/chunk-BPKPPSXC.js +282 -0
  54. package/dist/chunk-BPWKKK7F.js +1711 -0
  55. package/dist/chunk-CCKX6YTC.js +1735 -0
  56. package/dist/chunk-CIF5Z3MP.js +58 -0
  57. package/dist/chunk-CSXYU7IO.js +457 -0
  58. package/dist/chunk-D6JD4FDC.js +26 -0
  59. package/dist/chunk-E7NGA7X2.js +59 -0
  60. package/dist/chunk-EEPPJKAE.js +443 -0
  61. package/dist/chunk-EJMYGAGQ.js +717 -0
  62. package/dist/chunk-EL6Z5MDY.js +55 -0
  63. package/dist/chunk-EP7VRLEB.js +41 -0
  64. package/dist/chunk-ETMEC6FH.js +99 -0
  65. package/dist/chunk-EZ2WHYVL.js +65 -0
  66. package/dist/chunk-EZRVMSZK.js +67 -0
  67. package/dist/chunk-F2TRGINX.js +254 -0
  68. package/dist/chunk-F5JCIH3Q.js +642 -0
  69. package/dist/chunk-FGK3JKMN.js +909 -0
  70. package/dist/chunk-FQWPKSTD.js +1437 -0
  71. package/dist/chunk-FWHVLMCI.js +26 -0
  72. package/dist/chunk-GBEYQRO2.js +303 -0
  73. package/dist/chunk-GBLES3NK.js +248 -0
  74. package/dist/chunk-GQVGUQW6.js +1436 -0
  75. package/dist/chunk-HCV2T76T.js +457 -0
  76. package/dist/chunk-HS7ZKVPR.js +182 -0
  77. package/dist/chunk-HXDVV7HZ.js +909 -0
  78. package/dist/chunk-IB23VMO3.js +1746 -0
  79. package/dist/chunk-IEMZ7RTT.js +99 -0
  80. package/dist/chunk-IPGRSN42.js +1750 -0
  81. package/dist/chunk-IVMOK2QN.js +1750 -0
  82. package/dist/chunk-JCLGQO7T.js +443 -0
  83. package/dist/chunk-JDXL7KDB.js +1436 -0
  84. package/dist/chunk-JIIFW636.js +270 -0
  85. package/dist/chunk-JWGEEH7H.js +944 -0
  86. package/dist/chunk-K2BESAG7.js +1688 -0
  87. package/dist/chunk-K2U5YGF4.js +877 -0
  88. package/dist/chunk-K45FQ4Y4.js +175 -0
  89. package/dist/chunk-K7BPE427.js +1432 -0
  90. package/dist/chunk-KL3266RS.js +26 -0
  91. package/dist/chunk-KNN4P7DZ.js +84 -0
  92. package/dist/chunk-KP2DZH5Q.js +254 -0
  93. package/dist/chunk-KZHAJSQR.js +1636 -0
  94. package/dist/chunk-LBKGHMQV.js +1750 -0
  95. package/dist/chunk-LBTEPL7A.js +1731 -0
  96. package/dist/chunk-LEBBPTDB.js +1444 -0
  97. package/dist/chunk-LLH63WVQ.js +98 -0
  98. package/dist/chunk-LWVR2C4G.js +1711 -0
  99. package/dist/chunk-M3MDTVV2.js +896 -0
  100. package/dist/chunk-M5GNLDEO.js +303 -0
  101. package/dist/chunk-MFHVGKET.js +267 -0
  102. package/dist/chunk-MGWSG3PM.js +358 -0
  103. package/dist/chunk-MJNB47HB.js +19 -0
  104. package/dist/chunk-MLKGABMK.js +9 -0
  105. package/dist/chunk-MQWTY3JY.js +944 -0
  106. package/dist/chunk-MZZOQHNI.js +642 -0
  107. package/dist/chunk-NIHWGZS4.js +1426 -0
  108. package/dist/chunk-NSVVHQK5.js +41 -0
  109. package/dist/chunk-NVI2WE7D.js +443 -0
  110. package/dist/chunk-O7QBO3PH.js +58 -0
  111. package/dist/chunk-OAUPQBO2.js +270 -0
  112. package/dist/chunk-OB2LMD7C.js +297 -0
  113. package/dist/chunk-OHEYBWQU.js +58 -0
  114. package/dist/chunk-OI6OXUHJ.js +443 -0
  115. package/dist/chunk-OX2VMRMV.js +633 -0
  116. package/dist/chunk-P4FYE5TX.js +866 -0
  117. package/dist/chunk-P5KFWM4H.js +98 -0
  118. package/dist/chunk-PUMLE7RJ.js +1711 -0
  119. package/dist/chunk-Q4MFANBF.js +282 -0
  120. package/dist/chunk-QLEKZMMU.js +282 -0
  121. package/dist/chunk-RGGNGVO3.js +98 -0
  122. package/dist/chunk-RKJDRVV6.js +443 -0
  123. package/dist/chunk-S5BHU353.js +43 -0
  124. package/dist/chunk-SHQUSFH7.js +1426 -0
  125. package/dist/chunk-SMB4DBMD.js +182 -0
  126. package/dist/chunk-SNYHQP3D.js +743 -0
  127. package/dist/chunk-T24L3TBF.js +1717 -0
  128. package/dist/chunk-TAQNSOKT.js +692 -0
  129. package/dist/chunk-TDNY4SUA.js +41 -0
  130. package/dist/chunk-TNNF56IQ.js +1750 -0
  131. package/dist/chunk-TR7E6LYX.js +457 -0
  132. package/dist/chunk-URWUFH45.js +98 -0
  133. package/dist/chunk-UUSIH3XH.js +1429 -0
  134. package/dist/chunk-UYFNXLKR.js +1436 -0
  135. package/dist/chunk-V6F7KUWD.js +270 -0
  136. package/dist/chunk-VCZLXRMR.js +254 -0
  137. package/dist/chunk-VDHXSSBT.js +1426 -0
  138. package/dist/chunk-VM4QMKVK.js +254 -0
  139. package/dist/chunk-VWGYKYL2.js +737 -0
  140. package/dist/chunk-VX2OFBJN.js +1426 -0
  141. package/dist/chunk-VXVIE6DG.js +84 -0
  142. package/dist/chunk-W4OH7HG4.js +40 -0
  143. package/dist/chunk-WBVJX4GZ.js +98 -0
  144. package/dist/chunk-WDU2ZV4I.js +1426 -0
  145. package/dist/chunk-X6VUCICU.js +457 -0
  146. package/dist/chunk-XAY7FM7Y.js +618 -0
  147. package/dist/chunk-XJZ5Z2CM.js +642 -0
  148. package/dist/chunk-XKVFQTJJ.js +254 -0
  149. package/dist/chunk-XRLFASCY.js +22 -0
  150. package/dist/chunk-XYU6TZOW.js +182 -0
  151. package/dist/chunk-Y745CBVB.js +944 -0
  152. package/dist/chunk-YLBJSXYY.js +944 -0
  153. package/dist/chunk-YQJIKVPZ.js +1429 -0
  154. package/dist/chunk-YRM2VCZF.js +457 -0
  155. package/dist/chunk-YS33KBVJ.js +944 -0
  156. package/dist/chunk-Z27DZPDG.js +41 -0
  157. package/dist/chunk-ZXQ5NAEN.js +32 -0
  158. package/dist/contracts-B552GopR.d.cts +245 -0
  159. package/dist/contracts-B552GopR.d.ts +245 -0
  160. package/dist/contracts-Bg1ECISC.d.cts +245 -0
  161. package/dist/contracts-Bg1ECISC.d.ts +245 -0
  162. package/dist/contracts-CMriKJ6P.d.cts +245 -0
  163. package/dist/contracts-CMriKJ6P.d.ts +245 -0
  164. package/dist/contracts-DOrhwbke.d.cts +245 -0
  165. package/dist/contracts-DOrhwbke.d.ts +245 -0
  166. package/dist/data.cjs +1373 -0
  167. package/dist/data.d.cts +434 -0
  168. package/dist/data.d.ts +434 -0
  169. package/dist/data.js +945 -0
  170. package/dist/devtools.cjs +1357 -0
  171. package/dist/devtools.d.cts +473 -0
  172. package/dist/devtools.d.ts +473 -0
  173. package/dist/devtools.js +1084 -0
  174. package/dist/ecosystem.cjs +1046 -0
  175. package/dist/ecosystem.d.cts +247 -0
  176. package/dist/ecosystem.d.ts +247 -0
  177. package/dist/ecosystem.js +369 -0
  178. package/dist/extras.cjs +8457 -0
  179. package/dist/extras.d.cts +2356 -0
  180. package/dist/extras.d.ts +2356 -0
  181. package/dist/extras.js +5152 -0
  182. package/dist/index.cjs +2648 -0
  183. package/dist/index.d.cts +869 -0
  184. package/dist/index.d.ts +869 -0
  185. package/dist/index.js +386 -0
  186. package/dist/motion.cjs +604 -0
  187. package/dist/motion.d.cts +146 -0
  188. package/dist/motion.d.ts +146 -0
  189. package/dist/motion.js +346 -0
  190. package/dist/patterns.cjs +815 -0
  191. package/dist/patterns.d.cts +163 -0
  192. package/dist/patterns.d.ts +163 -0
  193. package/dist/patterns.js +296 -0
  194. package/dist/performance.cjs +927 -0
  195. package/dist/performance.d.cts +416 -0
  196. package/dist/performance.d.ts +416 -0
  197. package/dist/performance.js +654 -0
  198. package/dist/plugins.cjs +2487 -0
  199. package/dist/plugins.d.cts +393 -0
  200. package/dist/plugins.d.ts +393 -0
  201. package/dist/plugins.js +1504 -0
  202. package/dist/signal-BnWpq6WB.d.cts +5 -0
  203. package/dist/signal-BnWpq6WB.d.ts +5 -0
  204. package/dist/src/components/ErrorBoundary.d.ts +15 -0
  205. package/dist/src/components/ErrorBoundary.js +119 -0
  206. package/dist/src/core/catch.d.ts +11 -0
  207. package/dist/src/core/catch.js +28 -0
  208. package/dist/src/core/each.d.ts +13 -0
  209. package/dist/src/core/each.js +68 -0
  210. package/dist/src/core/for.d.ts +12 -0
  211. package/dist/src/core/for.js +67 -0
  212. package/dist/src/core/html.d.ts +137 -0
  213. package/dist/src/core/html.js +155 -0
  214. package/dist/src/core/htmlIf.d.ts +11 -0
  215. package/dist/src/core/htmlIf.js +18 -0
  216. package/dist/src/core/lazy.d.ts +7 -0
  217. package/dist/src/core/lazy.js +16 -0
  218. package/dist/src/core/mount.d.ts +7 -0
  219. package/dist/src/core/mount.js +12 -0
  220. package/dist/src/core/slots.d.ts +3 -0
  221. package/dist/src/core/slots.js +3 -0
  222. package/dist/src/core/suspense.d.ts +10 -0
  223. package/dist/src/core/suspense.js +33 -0
  224. package/dist/src/core/tagFactory.d.ts +13 -0
  225. package/dist/src/core/tagFactory.js +86 -0
  226. package/dist/src/core/test.d.ts +11 -0
  227. package/dist/src/core/test.js +28 -0
  228. package/dist/src/core/types.d.ts +2 -0
  229. package/dist/src/core/types.js +1 -0
  230. package/dist/src/core/useComputed.d.ts +6 -0
  231. package/dist/src/core/useComputed.js +30 -0
  232. package/dist/src/core/useEffect.d.ts +6 -0
  233. package/dist/src/core/useEffect.js +23 -0
  234. package/dist/src/core/useState.d.ts +10 -0
  235. package/dist/src/core/useState.js +34 -0
  236. package/dist/src/core/useStore.d.ts +19 -0
  237. package/dist/src/core/useStore.js +53 -0
  238. package/dist/src/core/useWatch.d.ts +8 -0
  239. package/dist/src/core/useWatch.js +23 -0
  240. package/dist/src/plugins/i18n.d.ts +6 -0
  241. package/dist/src/plugins/i18n.js +16 -0
  242. package/dist/src/plugins/router.d.ts +188 -0
  243. package/dist/src/plugins/router.js +1178 -0
  244. package/dist/src/reactivity/bindAttribute.d.ts +5 -0
  245. package/dist/src/reactivity/bindAttribute.js +31 -0
  246. package/dist/src/reactivity/bindChildNode.d.ts +10 -0
  247. package/dist/src/reactivity/bindChildNode.js +46 -0
  248. package/dist/src/reactivity/bindTextNode.d.ts +10 -0
  249. package/dist/src/reactivity/bindTextNode.js +27 -0
  250. package/dist/src/reactivity/signal.d.ts +3 -0
  251. package/dist/src/reactivity/signal.js +1 -0
  252. package/dist/src/reactivity/track.d.ts +18 -0
  253. package/dist/src/reactivity/track.js +73 -0
  254. package/dist/src/reactivity/useComputed.d.ts +6 -0
  255. package/dist/src/reactivity/useComputed.js +30 -0
  256. package/dist/src/reactivity/useEffect.d.ts +6 -0
  257. package/dist/src/reactivity/useEffect.js +23 -0
  258. package/dist/src/reactivity/useState.d.ts +10 -0
  259. package/dist/src/reactivity/useState.js +34 -0
  260. package/dist/src/reactivity/useStore.d.ts +19 -0
  261. package/dist/src/reactivity/useStore.js +53 -0
  262. package/dist/src/reactivity/useWatch.d.ts +8 -0
  263. package/dist/src/reactivity/useWatch.js +23 -0
  264. package/dist/src/utils/sanitize.d.ts +1 -0
  265. package/dist/src/utils/sanitize.js +8 -0
  266. package/dist/ssr-27FOM46T.js +35 -0
  267. package/dist/ssr-GFUTTSJD.js +22 -0
  268. package/dist/ssr-K7DCR6BZ.js +35 -0
  269. package/dist/ssr-O6LFMRFP.js +35 -0
  270. package/dist/ssr-QZEVGMMK.js +35 -0
  271. package/dist/ssr-SGVBCAGC.js +35 -0
  272. package/dist/ssr-UB2IXCYX.js +35 -0
  273. package/dist/ssr-XBZQNV4O.js +22 -0
  274. package/dist/ssr-Y76FSXDU.js +35 -0
  275. package/dist/ssr-YQJ4AYBD.js +35 -0
  276. package/dist/ssr.cjs +1757 -0
  277. package/dist/ssr.d.cts +478 -0
  278. package/dist/ssr.d.ts +478 -0
  279. package/dist/ssr.js +743 -0
  280. package/dist/tagFactory-CZPO4RXF.d.cts +34 -0
  281. package/dist/tagFactory-CZPO4RXF.d.ts +34 -0
  282. package/dist/tagFactory-CgImPVMY.d.cts +22 -0
  283. package/dist/tagFactory-CgImPVMY.d.ts +22 -0
  284. package/dist/tagFactory-Cw1iv5if.d.cts +22 -0
  285. package/dist/tagFactory-Cw1iv5if.d.ts +22 -0
  286. package/dist/tagFactory-DeAXq9ef.d.cts +30 -0
  287. package/dist/tagFactory-DeAXq9ef.d.ts +30 -0
  288. package/dist/tagFactory-SkY0a7L1.d.cts +22 -0
  289. package/dist/tagFactory-SkY0a7L1.d.ts +22 -0
  290. package/dist/testing.cjs +1919 -0
  291. package/dist/testing.d.cts +491 -0
  292. package/dist/testing.d.ts +491 -0
  293. package/dist/testing.js +1862 -0
  294. package/dist/ui.cjs +1497 -0
  295. package/dist/ui.d.cts +264 -0
  296. package/dist/ui.d.ts +264 -0
  297. package/dist/ui.js +900 -0
  298. package/dist/widgets.cjs +919 -0
  299. package/dist/widgets.d.cts +165 -0
  300. package/dist/widgets.d.ts +165 -0
  301. package/dist/widgets.js +545 -0
  302. package/package.json +134 -0
@@ -0,0 +1,1504 @@
1
+ import {
2
+ renderToString
3
+ } from "./chunk-VCZLXRMR.js";
4
+ import {
5
+ span
6
+ } from "./chunk-6JGMNCD6.js";
7
+ import "./chunk-MFHVGKET.js";
8
+ import "./chunk-ETMEC6FH.js";
9
+ import "./chunk-MJNB47HB.js";
10
+ import {
11
+ signal,
12
+ track
13
+ } from "./chunk-M5GNLDEO.js";
14
+ import "./chunk-MLKGABMK.js";
15
+
16
+ // src/plugins/i18n.ts
17
+ var [currentLocale, setLocaleInternal] = signal("en");
18
+ var locales = {};
19
+ function setLocale(locale) {
20
+ setLocaleInternal(locale);
21
+ }
22
+ function getLocale() {
23
+ return currentLocale();
24
+ }
25
+ function registerTranslations(locale, messages) {
26
+ locales[locale] = { ...locales[locale], ...messages };
27
+ }
28
+ function t(key, params) {
29
+ const locale = currentLocale();
30
+ const message = locales[locale]?.[key] || key;
31
+ return params ? message.replace(/\{(\w+)\}/g, (_, p) => String(params[p] ?? "")) : message;
32
+ }
33
+ function Trans(key, params) {
34
+ return span({
35
+ nodes: () => t(key, params)
36
+ });
37
+ }
38
+ function hasTranslation(key) {
39
+ const locale = currentLocale();
40
+ return key in (locales[locale] || {});
41
+ }
42
+ function getAvailableLocales() {
43
+ return Object.keys(locales);
44
+ }
45
+
46
+ // src/plugins/router.ts
47
+ var LRUCache = class {
48
+ constructor(maxSize = 100) {
49
+ this.cache = /* @__PURE__ */ new Map();
50
+ this.maxSize = Math.max(1, maxSize);
51
+ }
52
+ get(key) {
53
+ const value = this.cache.get(key);
54
+ if (value !== void 0) {
55
+ this.cache.delete(key);
56
+ this.cache.set(key, value);
57
+ }
58
+ return value;
59
+ }
60
+ set(key, value) {
61
+ if (this.cache.has(key)) {
62
+ this.cache.delete(key);
63
+ } else if (this.cache.size >= this.maxSize) {
64
+ const firstKey = this.cache.keys().next().value;
65
+ if (firstKey !== void 0) {
66
+ this.cache.delete(firstKey);
67
+ }
68
+ }
69
+ this.cache.set(key, value);
70
+ }
71
+ has(key) {
72
+ return this.cache.has(key);
73
+ }
74
+ delete(key) {
75
+ return this.cache.delete(key);
76
+ }
77
+ clear() {
78
+ this.cache.clear();
79
+ }
80
+ get size() {
81
+ return this.cache.size;
82
+ }
83
+ };
84
+ var NavigationController = class {
85
+ constructor() {
86
+ this.currentController = null;
87
+ }
88
+ async navigate(navigationFn) {
89
+ if (this.currentController) {
90
+ this.currentController.abort();
91
+ }
92
+ this.currentController = new AbortController();
93
+ const signal2 = this.currentController.signal;
94
+ try {
95
+ await navigationFn(signal2);
96
+ } catch (error) {
97
+ if (error instanceof Error && error.name === "AbortError") {
98
+ return;
99
+ }
100
+ throw error;
101
+ } finally {
102
+ if (this.currentController?.signal === signal2) {
103
+ this.currentController = null;
104
+ }
105
+ }
106
+ }
107
+ abort() {
108
+ if (this.currentController) {
109
+ this.currentController.abort();
110
+ this.currentController = null;
111
+ }
112
+ }
113
+ get isNavigating() {
114
+ return this.currentController !== null;
115
+ }
116
+ };
117
+ var RouteMatcher = class {
118
+ constructor(routes) {
119
+ this.routeTrie = /* @__PURE__ */ new Map();
120
+ this.namedRoutes = /* @__PURE__ */ new Map();
121
+ this.compiledPatterns = new LRUCache(50);
122
+ this.buildIndex(routes);
123
+ }
124
+ buildIndex(routes, parentPath = "") {
125
+ for (const route2 of routes) {
126
+ const fullPath = parentPath + route2.path;
127
+ this.routeTrie.set(fullPath, route2);
128
+ if (route2.name) {
129
+ this.namedRoutes.set(route2.name, route2);
130
+ }
131
+ if (route2.alias) {
132
+ const aliases = Array.isArray(route2.alias) ? route2.alias : [route2.alias];
133
+ for (const alias of aliases) {
134
+ this.routeTrie.set(parentPath + alias, route2);
135
+ }
136
+ }
137
+ if (route2.children?.length) {
138
+ this.buildIndex(route2.children, fullPath);
139
+ }
140
+ }
141
+ }
142
+ match(path) {
143
+ const exactMatch = this.routeTrie.get(path);
144
+ if (exactMatch) {
145
+ return { route: exactMatch, params: {}, matched: [exactMatch] };
146
+ }
147
+ for (const [routePath, route2] of this.routeTrie) {
148
+ const match = this.matchPattern(path, routePath);
149
+ if (match) {
150
+ return { route: route2, params: match.params, matched: [route2] };
151
+ }
152
+ }
153
+ return null;
154
+ }
155
+ findByName(name) {
156
+ return this.namedRoutes.get(name) || null;
157
+ }
158
+ matchPattern(path, routePath) {
159
+ if (routePath === "*" || routePath.endsWith("/*")) {
160
+ const basePath = routePath.slice(0, -2);
161
+ if (path.startsWith(basePath)) {
162
+ return { params: { pathMatch: path.slice(basePath.length) } };
163
+ }
164
+ return null;
165
+ }
166
+ let compiled = this.compiledPatterns.get(routePath);
167
+ if (!compiled) {
168
+ compiled = this.compileRoute(routePath);
169
+ this.compiledPatterns.set(routePath, compiled);
170
+ }
171
+ const match = path.match(compiled.regex);
172
+ if (match) {
173
+ const params = {};
174
+ compiled.keys.forEach((key, i) => {
175
+ if (match[i + 1] !== void 0) {
176
+ params[key] = decodeURIComponent(match[i + 1]);
177
+ }
178
+ });
179
+ return { params };
180
+ }
181
+ return null;
182
+ }
183
+ compileRoute(routePath) {
184
+ const keys = [];
185
+ const escapeRegex = (s) => s.replace(/[.+*?^${}()|[\]\\]/g, "\\$&");
186
+ const parts = routePath.split(/(\/:[^/]+\??)/);
187
+ let pattern = "";
188
+ for (const part of parts) {
189
+ if (part.startsWith("/:")) {
190
+ if (part.endsWith("?")) {
191
+ keys.push(part.slice(2, -1));
192
+ pattern += "(?:/([^/]+))?";
193
+ } else {
194
+ keys.push(part.slice(2));
195
+ pattern += "/([^/]+)";
196
+ }
197
+ } else {
198
+ pattern += escapeRegex(part);
199
+ }
200
+ }
201
+ return {
202
+ regex: new RegExp(`^${pattern}$`),
203
+ keys
204
+ };
205
+ }
206
+ rebuild(routes) {
207
+ this.routeTrie.clear();
208
+ this.namedRoutes.clear();
209
+ this.compiledPatterns.clear();
210
+ this.buildIndex(routes);
211
+ }
212
+ addRoute(route2, parentPath = "") {
213
+ const fullPath = parentPath + route2.path;
214
+ this.routeTrie.set(fullPath, route2);
215
+ if (route2.name) {
216
+ this.namedRoutes.set(route2.name, route2);
217
+ }
218
+ if (route2.children?.length) {
219
+ this.buildIndex(route2.children, fullPath);
220
+ }
221
+ }
222
+ removeRoute(path) {
223
+ this.routeTrie.delete(path);
224
+ this.compiledPatterns.clear();
225
+ for (const [name, route2] of this.namedRoutes) {
226
+ if (route2.path === path) {
227
+ this.namedRoutes.delete(name);
228
+ break;
229
+ }
230
+ }
231
+ }
232
+ };
233
+ var GuardManager = class {
234
+ constructor(timeout = 5e3) {
235
+ this.beforeEachGuards = [];
236
+ this.beforeResolveGuards = [];
237
+ this.afterEachHooks = [];
238
+ this.timeout = timeout;
239
+ }
240
+ async runBeforeEach(to, from, signal2) {
241
+ for (const guard of this.beforeEachGuards) {
242
+ if (signal2.aborted) throw new Error("Navigation aborted");
243
+ const result = await this.runGuard(guard, to, from, signal2);
244
+ if (result !== true) return result;
245
+ }
246
+ return true;
247
+ }
248
+ async runBeforeResolve(to, from, signal2) {
249
+ for (const guard of this.beforeResolveGuards) {
250
+ if (signal2.aborted) throw new Error("Navigation aborted");
251
+ const result = await this.runGuard(guard, to, from, signal2);
252
+ if (result !== true) return result;
253
+ }
254
+ return true;
255
+ }
256
+ runAfterEach(to, from) {
257
+ for (const hook of this.afterEachHooks) {
258
+ try {
259
+ hook(to, from);
260
+ } catch (error) {
261
+ console.error("[Router] AfterEach hook error:", error);
262
+ }
263
+ }
264
+ }
265
+ runGuard(guard, to, from, signal2) {
266
+ return new Promise((resolve, reject) => {
267
+ if (signal2.aborted) {
268
+ reject(new Error("Navigation aborted"));
269
+ return;
270
+ }
271
+ let resolved = false;
272
+ const next = (result) => {
273
+ if (resolved || signal2.aborted) return;
274
+ resolved = true;
275
+ if (result instanceof Error) {
276
+ reject(result);
277
+ } else if (result === false) {
278
+ resolve(false);
279
+ } else if (typeof result === "string") {
280
+ resolve(result);
281
+ } else {
282
+ resolve(true);
283
+ }
284
+ };
285
+ const abortHandler = () => {
286
+ if (!resolved) {
287
+ resolved = true;
288
+ reject(new Error("Navigation aborted"));
289
+ }
290
+ };
291
+ signal2.addEventListener("abort", abortHandler);
292
+ const timeoutId = setTimeout(() => {
293
+ if (!resolved) {
294
+ resolved = true;
295
+ signal2.removeEventListener("abort", abortHandler);
296
+ reject(new Error("Guard timeout"));
297
+ }
298
+ }, this.timeout);
299
+ try {
300
+ guard(to, from, next);
301
+ } catch (error) {
302
+ clearTimeout(timeoutId);
303
+ signal2.removeEventListener("abort", abortHandler);
304
+ if (!resolved) {
305
+ resolved = true;
306
+ reject(error instanceof Error ? error : new Error(String(error)));
307
+ }
308
+ }
309
+ Promise.resolve().then(() => {
310
+ if (resolved) {
311
+ clearTimeout(timeoutId);
312
+ signal2.removeEventListener("abort", abortHandler);
313
+ }
314
+ });
315
+ });
316
+ }
317
+ addBeforeEach(guard) {
318
+ this.beforeEachGuards.push(guard);
319
+ return () => {
320
+ const index = this.beforeEachGuards.indexOf(guard);
321
+ if (index > -1) this.beforeEachGuards.splice(index, 1);
322
+ };
323
+ }
324
+ addBeforeResolve(guard) {
325
+ this.beforeResolveGuards.push(guard);
326
+ return () => {
327
+ const index = this.beforeResolveGuards.indexOf(guard);
328
+ if (index > -1) this.beforeResolveGuards.splice(index, 1);
329
+ };
330
+ }
331
+ addAfterEach(hook) {
332
+ this.afterEachHooks.push(hook);
333
+ return () => {
334
+ const index = this.afterEachHooks.indexOf(hook);
335
+ if (index > -1) this.afterEachHooks.splice(index, 1);
336
+ };
337
+ }
338
+ clear() {
339
+ this.beforeEachGuards = [];
340
+ this.beforeResolveGuards = [];
341
+ this.afterEachHooks = [];
342
+ }
343
+ };
344
+ var ComponentLoader = class {
345
+ constructor(cacheSize = 50, retryDelay = 1e3) {
346
+ this.errorCache = /* @__PURE__ */ new Map();
347
+ this.loadingPromises = /* @__PURE__ */ new Map();
348
+ this.componentCache = new LRUCache(cacheSize);
349
+ this.retryDelay = retryDelay;
350
+ }
351
+ async loadComponent(route2, routePath) {
352
+ if (!("component" in route2)) {
353
+ throw new Error(`Route ${routePath} does not have a component`);
354
+ }
355
+ const comp = route2.component;
356
+ const cached = this.componentCache.get(routePath);
357
+ if (cached) return cached;
358
+ const existingPromise = this.loadingPromises.get(routePath);
359
+ if (existingPromise) return existingPromise;
360
+ const errorInfo = this.errorCache.get(routePath);
361
+ if (errorInfo && Date.now() - errorInfo.timestamp < this.retryDelay) {
362
+ throw new Error(`Component loading failed recently, retry in ${this.retryDelay}ms`);
363
+ }
364
+ const loadingPromise = this.doLoadComponent(comp, routePath);
365
+ this.loadingPromises.set(routePath, loadingPromise);
366
+ try {
367
+ const component = await loadingPromise;
368
+ this.componentCache.set(routePath, component);
369
+ this.errorCache.delete(routePath);
370
+ return component;
371
+ } catch (error) {
372
+ const currentError = this.errorCache.get(routePath) || { timestamp: 0, count: 0 };
373
+ this.errorCache.set(routePath, {
374
+ timestamp: Date.now(),
375
+ count: currentError.count + 1
376
+ });
377
+ throw error;
378
+ } finally {
379
+ this.loadingPromises.delete(routePath);
380
+ }
381
+ }
382
+ async doLoadComponent(comp, routePath) {
383
+ if (!this.isAsyncComponent(comp)) {
384
+ const result = comp();
385
+ if (!this.isElement(result)) {
386
+ throw new Error(`Component for route "${routePath}" must return Element, got ${typeof result}`);
387
+ }
388
+ return comp;
389
+ }
390
+ try {
391
+ const result = await comp();
392
+ const component = this.extractComponent(result, routePath);
393
+ const testElement = component();
394
+ if (!this.isElement(testElement)) {
395
+ throw new Error(`Component for route "${routePath}" must return Element, got ${typeof testElement}`);
396
+ }
397
+ return component;
398
+ } catch (error) {
399
+ throw new Error(
400
+ `Failed to load component for route "${routePath}": ${error instanceof Error ? error.message : String(error)}`
401
+ );
402
+ }
403
+ }
404
+ isAsyncComponent(comp) {
405
+ return comp.constructor.name === "AsyncFunction" || typeof comp === "function" && comp.toString().includes("import(");
406
+ }
407
+ isElement(value) {
408
+ return value instanceof Element;
409
+ }
410
+ extractComponent(result, routePath) {
411
+ if ("default" in result && typeof result.default === "function") {
412
+ return result.default;
413
+ }
414
+ if (typeof result === "function") {
415
+ return result;
416
+ }
417
+ if (this.isElement(result)) {
418
+ return () => result;
419
+ }
420
+ throw new Error(`Invalid component module for route "${routePath}"`);
421
+ }
422
+ clearErrors() {
423
+ this.errorCache.clear();
424
+ }
425
+ clearCache() {
426
+ this.componentCache.clear();
427
+ this.errorCache.clear();
428
+ this.loadingPromises.clear();
429
+ }
430
+ };
431
+ var SibuRouter = class {
432
+ constructor(routes, options = {}) {
433
+ // Event listeners cleanup
434
+ this.cleanup = [];
435
+ this.options = {
436
+ mode: "history",
437
+ base: "",
438
+ linkActiveClass: "router-link-active",
439
+ linkExactActiveClass: "router-link-exact-active",
440
+ fallback: true,
441
+ guardTimeout: 5e3,
442
+ cacheSize: 50,
443
+ errorRetryDelay: 1e3,
444
+ preloadStrategy: "none",
445
+ ...options
446
+ };
447
+ const [currentRouteState, setCurrentRouteState] = signal(this.createInitialRoute());
448
+ const [isReadyState, setIsReadyState] = signal(false);
449
+ this.currentRouteGetter = currentRouteState;
450
+ this.currentRouteSetter = setCurrentRouteState;
451
+ this.isReadyGetter = isReadyState;
452
+ this.isReadySetter = setIsReadyState;
453
+ this.matcher = new RouteMatcher(routes);
454
+ this.guards = new GuardManager(this.options.guardTimeout);
455
+ this.loader = new ComponentLoader(this.options.cacheSize, this.options.errorRetryDelay);
456
+ this.navigator = new NavigationController();
457
+ this.initialize();
458
+ }
459
+ initialize() {
460
+ if (this.options.mode === "history") {
461
+ const popstateHandler = () => this.handleLocationChange();
462
+ window.addEventListener("popstate", popstateHandler);
463
+ this.cleanup.push(() => window.removeEventListener("popstate", popstateHandler));
464
+ } else {
465
+ const hashHandler = () => this.handleLocationChange();
466
+ window.addEventListener("hashchange", hashHandler);
467
+ this.cleanup.push(() => window.removeEventListener("hashchange", hashHandler));
468
+ }
469
+ queueMicrotask(() => {
470
+ this.handleLocationChange();
471
+ this.isReadySetter(true);
472
+ });
473
+ }
474
+ createInitialRoute() {
475
+ return {
476
+ path: "/",
477
+ params: {},
478
+ query: {},
479
+ hash: "",
480
+ meta: {},
481
+ matched: []
482
+ };
483
+ }
484
+ handleLocationChange() {
485
+ const path = this.getCurrentPath();
486
+ const context = this.createRouteContext(path);
487
+ this.currentRouteSetter(context);
488
+ }
489
+ getCurrentPath() {
490
+ const { mode, base } = this.options;
491
+ if (mode === "hash") {
492
+ return window.location.hash.slice(1) || "/";
493
+ }
494
+ let path = window.location.pathname;
495
+ if (base && path.startsWith(base)) {
496
+ path = path.slice(base.length);
497
+ }
498
+ return (path || "/") + window.location.search + window.location.hash;
499
+ }
500
+ createRouteContext(fullPath) {
501
+ const [pathWithQuery, hash = ""] = fullPath.split("#");
502
+ const [path, queryString = ""] = pathWithQuery.split("?");
503
+ const query = Object.fromEntries(new URLSearchParams(queryString));
504
+ const match = this.matcher.match(path || "/");
505
+ const params = match?.params || {};
506
+ const meta = match?.route.meta || {};
507
+ const matched = match ? [match.route] : [];
508
+ return {
509
+ path: path || "/",
510
+ params,
511
+ query,
512
+ hash,
513
+ meta,
514
+ matched
515
+ };
516
+ }
517
+ // Public API
518
+ async navigate(to, options = {}) {
519
+ try {
520
+ await this.navigator.navigate(async (signal2) => {
521
+ const targetPath = this.resolvePath(to);
522
+ const from = this.currentRouteGetter();
523
+ const toContext = this.createRouteContext(targetPath);
524
+ if (this.isSameRoute(from, toContext)) {
525
+ throw new NavigationFailureError("duplicated", from, toContext);
526
+ }
527
+ await this.performNavigation(toContext, from, options, signal2);
528
+ });
529
+ return { success: true, route: this.currentRouteGetter() };
530
+ } catch (error) {
531
+ if (error instanceof NavigationFailureError) {
532
+ const failure2 = error.toFailure();
533
+ return { success: false, type: failure2.type, failure: failure2 };
534
+ }
535
+ const failure = {
536
+ type: "aborted",
537
+ from: this.currentRouteGetter(),
538
+ to: this.createRouteContext(this.resolvePath(to)),
539
+ error: error instanceof Error ? error : new Error(String(error))
540
+ };
541
+ return { success: false, type: failure.type, failure };
542
+ }
543
+ }
544
+ async performNavigation(to, from, options, signal2) {
545
+ const beforeEachResult = await this.guards.runBeforeEach(to, from, signal2);
546
+ if (beforeEachResult !== true) {
547
+ if (typeof beforeEachResult === "string") {
548
+ return this.performNavigation(this.createRouteContext(beforeEachResult), from, options, signal2);
549
+ }
550
+ throw new NavigationFailureError("aborted", from, to);
551
+ }
552
+ const match = this.matcher.match(to.path);
553
+ if (match) {
554
+ const { route: route2 } = match;
555
+ if ("beforeEnter" in route2 && route2.beforeEnter) {
556
+ const guards = Array.isArray(route2.beforeEnter) ? route2.beforeEnter : [route2.beforeEnter];
557
+ for (const guard of guards) {
558
+ if (signal2.aborted) throw new Error("Navigation aborted");
559
+ const result = await guard(to, from);
560
+ if (result !== true) {
561
+ if (typeof result === "string") {
562
+ return this.performNavigation(this.createRouteContext(result), from, options, signal2);
563
+ }
564
+ throw new NavigationFailureError("aborted", from, to);
565
+ }
566
+ }
567
+ }
568
+ if ("redirect" in route2) {
569
+ const redirectPath = typeof route2.redirect === "function" ? route2.redirect(to) : route2.redirect;
570
+ if (typeof redirectPath === "string" && /^https?:\/\/|^\/\//i.test(redirectPath)) {
571
+ console.warn(
572
+ `[SibuJS Router] Redirect to absolute URL "${redirectPath}" detected. Use relative paths for safer redirects.`
573
+ );
574
+ }
575
+ return this.performNavigation(this.createRouteContext(redirectPath), from, options, signal2);
576
+ }
577
+ }
578
+ const beforeResolveResult = await this.guards.runBeforeResolve(to, from, signal2);
579
+ if (beforeResolveResult !== true) {
580
+ if (typeof beforeResolveResult === "string") {
581
+ return this.performNavigation(this.createRouteContext(beforeResolveResult), from, options, signal2);
582
+ }
583
+ throw new NavigationFailureError("aborted", from, to);
584
+ }
585
+ this.updateHistory(to, options);
586
+ this.currentRouteSetter(to);
587
+ this.guards.runAfterEach(to, from);
588
+ this.handleScrollBehavior(to, from);
589
+ }
590
+ resolvePath(to) {
591
+ if (typeof to === "string") return to;
592
+ let path = to.path || "";
593
+ if (to.name && !path) {
594
+ const namedRoute = this.matcher.findByName(to.name);
595
+ if (namedRoute) {
596
+ path = namedRoute.path;
597
+ }
598
+ }
599
+ if (to.params) {
600
+ for (const [key, value] of Object.entries(to.params)) {
601
+ path = path.replace(`:${key}`, encodeURIComponent(value));
602
+ }
603
+ }
604
+ if (to.query && Object.keys(to.query).length > 0) {
605
+ path += `?${new URLSearchParams(to.query).toString()}`;
606
+ }
607
+ if (to.hash) {
608
+ path += `#${to.hash}`;
609
+ }
610
+ return path;
611
+ }
612
+ isSameRoute(from, to) {
613
+ return from.path === to.path && JSON.stringify(from.params) === JSON.stringify(to.params) && JSON.stringify(from.query) === JSON.stringify(to.query) && from.hash === to.hash;
614
+ }
615
+ updateHistory(to, options) {
616
+ const fullPath = this.options.base + to.path + (Object.keys(to.query).length ? `?${new URLSearchParams(to.query).toString()}` : "") + (to.hash ? `#${to.hash}` : "");
617
+ if (options.replace) {
618
+ history.replaceState(options.state || {}, "", fullPath);
619
+ } else {
620
+ history.pushState(options.state || {}, "", fullPath);
621
+ }
622
+ }
623
+ handleScrollBehavior(to, from) {
624
+ if (this.options.scrollBehavior) {
625
+ const scrollTo = this.options.scrollBehavior(to, from, null);
626
+ if (scrollTo) {
627
+ requestAnimationFrame(() => {
628
+ window.scrollTo(scrollTo.x, scrollTo.y);
629
+ });
630
+ }
631
+ }
632
+ }
633
+ // Component loading
634
+ async loadComponent(route2, routePath) {
635
+ return this.loader.loadComponent(route2, routePath);
636
+ }
637
+ // Guards API
638
+ beforeEach(guard) {
639
+ return this.guards.addBeforeEach(guard);
640
+ }
641
+ beforeResolve(guard) {
642
+ return this.guards.addBeforeResolve(guard);
643
+ }
644
+ afterEach(hook) {
645
+ return this.guards.addAfterEach(hook);
646
+ }
647
+ // Utility methods
648
+ push(to) {
649
+ return this.navigate(to);
650
+ }
651
+ replace(to) {
652
+ return this.navigate(to, { replace: true });
653
+ }
654
+ go(delta) {
655
+ history.go(delta);
656
+ }
657
+ back() {
658
+ history.back();
659
+ }
660
+ forward() {
661
+ history.forward();
662
+ }
663
+ // State getters
664
+ get currentRoute() {
665
+ return this.currentRouteGetter();
666
+ }
667
+ get isReady() {
668
+ return this.isReadyGetter();
669
+ }
670
+ get isNavigating() {
671
+ return this.navigator.isNavigating;
672
+ }
673
+ // Cleanup
674
+ destroy() {
675
+ this.navigator.abort();
676
+ for (const fn of this.cleanup) fn();
677
+ this.cleanup = [];
678
+ this.guards.clear();
679
+ this.loader.clearCache();
680
+ this.isReadySetter(false);
681
+ }
682
+ // Cache management
683
+ clearCache() {
684
+ this.loader.clearCache();
685
+ }
686
+ clearErrorCache() {
687
+ this.loader.clearErrors();
688
+ }
689
+ // Route management
690
+ updateRoutes(routes) {
691
+ this.matcher.rebuild(routes);
692
+ this.clearCache();
693
+ }
694
+ /**
695
+ * Add a route dynamically at runtime.
696
+ */
697
+ addRoute(route2, parentPath) {
698
+ this.matcher.addRoute(route2, parentPath);
699
+ this.clearCache();
700
+ }
701
+ /**
702
+ * Remove a route by path.
703
+ */
704
+ removeRoute(path) {
705
+ this.matcher.removeRoute(path);
706
+ this.clearCache();
707
+ }
708
+ /**
709
+ * Get the reactive route getter for tracking.
710
+ */
711
+ get routeGetter() {
712
+ return this.currentRouteGetter;
713
+ }
714
+ };
715
+ var NavigationFailureError = class extends Error {
716
+ constructor(type, from, to, error) {
717
+ super(`Navigation ${type}: from ${from.path} to ${to.path}`);
718
+ this.name = "NavigationFailureError";
719
+ this.type = type;
720
+ this.from = from;
721
+ this.to = to;
722
+ if (error) {
723
+ this.cause = error;
724
+ }
725
+ }
726
+ toFailure() {
727
+ return {
728
+ type: this.type,
729
+ from: this.from,
730
+ to: this.to,
731
+ error: this.cause instanceof Error ? this.cause : void 0
732
+ };
733
+ }
734
+ };
735
+ var globalRouter = null;
736
+ function createRouter(routesOrOptions, options = {}) {
737
+ if (globalRouter) {
738
+ globalRouter.destroy();
739
+ }
740
+ let routes;
741
+ if (Array.isArray(routesOrOptions)) {
742
+ routes = routesOrOptions;
743
+ } else {
744
+ options = routesOrOptions;
745
+ routes = [];
746
+ }
747
+ globalRouter = new SibuRouter(routes, options);
748
+ return globalRouter;
749
+ }
750
+ function setRoutes(routes) {
751
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
752
+ globalRouter.updateRoutes(routes);
753
+ }
754
+ function route() {
755
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
756
+ return globalRouter.currentRoute;
757
+ }
758
+ function router() {
759
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
760
+ return {
761
+ currentRoute: globalRouter.currentRoute,
762
+ isReady: globalRouter.isReady,
763
+ isNavigating: globalRouter.isNavigating,
764
+ push: (to) => globalRouter?.push(to),
765
+ replace: (to) => globalRouter?.replace(to),
766
+ go: (delta) => globalRouter?.go(delta),
767
+ back: () => globalRouter?.back(),
768
+ forward: () => globalRouter?.forward(),
769
+ beforeEach: (guard) => globalRouter?.beforeEach(guard),
770
+ beforeResolve: (guard) => globalRouter?.beforeResolve(guard),
771
+ afterEach: (hook) => globalRouter?.afterEach(hook)
772
+ };
773
+ }
774
+ function navigate(to, options) {
775
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
776
+ return globalRouter.navigate(to, options);
777
+ }
778
+ function push(to) {
779
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
780
+ return globalRouter.push(to);
781
+ }
782
+ function replace(to) {
783
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
784
+ return globalRouter.replace(to);
785
+ }
786
+ function go(delta) {
787
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
788
+ globalRouter.go(delta);
789
+ }
790
+ function back() {
791
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
792
+ globalRouter.back();
793
+ }
794
+ function forward() {
795
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
796
+ globalRouter.forward();
797
+ }
798
+ function beforeEach(guard) {
799
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
800
+ return globalRouter.beforeEach(guard);
801
+ }
802
+ function beforeResolve(guard) {
803
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
804
+ return globalRouter.beforeResolve(guard);
805
+ }
806
+ function afterEach(hook) {
807
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
808
+ return globalRouter.afterEach(hook);
809
+ }
810
+ var routeCleanups = [];
811
+ function Route() {
812
+ const anchor = document.createComment("route-outlet");
813
+ let currentNode = null;
814
+ let loadingNode = null;
815
+ let errorNode = null;
816
+ let isUpdating = false;
817
+ let currentPath = "";
818
+ const cleanupNodes = () => {
819
+ [currentNode, loadingNode, errorNode].forEach((node) => {
820
+ if (node?.parentNode) {
821
+ node.parentNode.removeChild(node);
822
+ }
823
+ });
824
+ currentNode = null;
825
+ loadingNode = null;
826
+ errorNode = null;
827
+ };
828
+ const showLoading = () => {
829
+ if (!loadingNode && anchor.parentNode) {
830
+ loadingNode = document.createElement("div");
831
+ loadingNode.className = "route-loading";
832
+ loadingNode.setAttribute("role", "status");
833
+ loadingNode.setAttribute("aria-label", "Loading route");
834
+ const spinner = document.createElement("div");
835
+ spinner.className = "route-loading-spinner";
836
+ spinner.setAttribute("aria-hidden", "true");
837
+ const text = document.createElement("span");
838
+ text.textContent = "Loading...";
839
+ text.className = "route-loading-text";
840
+ loadingNode.appendChild(spinner);
841
+ loadingNode.appendChild(text);
842
+ anchor.parentNode.insertBefore(loadingNode, anchor.nextSibling);
843
+ }
844
+ };
845
+ const hideLoading = () => {
846
+ if (loadingNode?.parentNode) {
847
+ loadingNode.parentNode.removeChild(loadingNode);
848
+ loadingNode = null;
849
+ }
850
+ };
851
+ const showError = (error) => {
852
+ if (!anchor.parentNode) return;
853
+ cleanupNodes();
854
+ errorNode = document.createElement("div");
855
+ errorNode.className = "route-error";
856
+ errorNode.setAttribute("role", "alert");
857
+ errorNode.setAttribute("aria-live", "assertive");
858
+ const title = document.createElement("h3");
859
+ title.textContent = "Route Error";
860
+ title.className = "route-error-title";
861
+ const message = document.createElement("p");
862
+ message.textContent = error.message || "Failed to load route component";
863
+ message.className = "route-error-message";
864
+ const retryButton = document.createElement("button");
865
+ retryButton.textContent = "Retry";
866
+ retryButton.className = "route-error-retry";
867
+ retryButton.type = "button";
868
+ retryButton.addEventListener("click", () => {
869
+ if (globalRouter) {
870
+ globalRouter.clearErrorCache();
871
+ update();
872
+ }
873
+ });
874
+ errorNode.appendChild(title);
875
+ errorNode.appendChild(message);
876
+ errorNode.appendChild(retryButton);
877
+ anchor.parentNode.insertBefore(errorNode, anchor.nextSibling);
878
+ };
879
+ let pendingUpdate = false;
880
+ const update = async () => {
881
+ if (!globalRouter) return;
882
+ if (isUpdating) {
883
+ pendingUpdate = true;
884
+ return;
885
+ }
886
+ const route2 = globalRouter.currentRoute;
887
+ if (route2.path === currentPath && currentNode) return;
888
+ isUpdating = true;
889
+ currentPath = route2.path;
890
+ try {
891
+ const match = globalRouter["matcher"].match(route2.path);
892
+ if (!match) {
893
+ cleanupNodes();
894
+ return;
895
+ }
896
+ const { route: routeDef } = match;
897
+ if ("redirect" in routeDef) {
898
+ const redirectPath = typeof routeDef.redirect === "function" ? routeDef.redirect(route2) : routeDef.redirect;
899
+ queueMicrotask(() => globalRouter?.navigate(redirectPath));
900
+ return;
901
+ }
902
+ if ("component" in routeDef) {
903
+ try {
904
+ const isAsync = routeDef.component.constructor.name === "AsyncFunction" || routeDef.component.toString().includes("import(");
905
+ if (isAsync) {
906
+ showLoading();
907
+ }
908
+ const component = await globalRouter.loadComponent(routeDef, route2.path);
909
+ const node = component();
910
+ if (node && anchor.parentNode && route2.path === currentPath) {
911
+ cleanupNodes();
912
+ anchor.parentNode.insertBefore(node, anchor.nextSibling);
913
+ currentNode = node;
914
+ }
915
+ } catch (error) {
916
+ hideLoading();
917
+ console.error("[Route] Component error:", error);
918
+ showError(error instanceof Error ? error : new Error(String(error)));
919
+ }
920
+ }
921
+ } catch (error) {
922
+ console.error("[Route] Update failed:", error);
923
+ showError(error instanceof Error ? error : new Error(String(error)));
924
+ } finally {
925
+ isUpdating = false;
926
+ if (pendingUpdate) {
927
+ pendingUpdate = false;
928
+ update();
929
+ }
930
+ }
931
+ };
932
+ let routeInitialized = false;
933
+ const originalUpdate = update;
934
+ const wrappedUpdate = async () => {
935
+ await originalUpdate();
936
+ routeInitialized = true;
937
+ };
938
+ track(wrappedUpdate);
939
+ if (!routeInitialized) {
940
+ queueMicrotask(() => {
941
+ if (!routeInitialized && anchor.parentNode) wrappedUpdate();
942
+ });
943
+ }
944
+ routeCleanups.push(cleanupNodes);
945
+ return anchor;
946
+ }
947
+ function RouterLink(props) {
948
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
949
+ const { to, replace: replace2 = false, activeClass, exactActiveClass, nodes, target, rel, ...attrs } = props;
950
+ const route2 = globalRouter.currentRoute;
951
+ const href = globalRouter["resolvePath"](to);
952
+ const isActive = route2.path.startsWith(href.split("?")[0].split("#")[0]);
953
+ const isExactActive = route2.path === href.split("?")[0].split("#")[0];
954
+ const link = document.createElement("a");
955
+ link.href = href;
956
+ if (target) {
957
+ link.target = target;
958
+ if (target === "_blank") {
959
+ link.rel = rel ? `${rel} noopener noreferrer` : "noopener noreferrer";
960
+ } else if (rel) {
961
+ link.rel = rel;
962
+ }
963
+ } else if (rel) {
964
+ link.rel = rel;
965
+ }
966
+ const classes = [];
967
+ const options = globalRouter["options"];
968
+ if (isActive) {
969
+ if (activeClass) classes.push(activeClass);
970
+ else if (options.linkActiveClass) classes.push(options.linkActiveClass);
971
+ }
972
+ if (isExactActive) {
973
+ if (exactActiveClass) classes.push(exactActiveClass);
974
+ else if (options.linkExactActiveClass) classes.push(options.linkExactActiveClass);
975
+ }
976
+ if (classes.length > 0) {
977
+ link.className = classes.join(" ");
978
+ }
979
+ Object.entries(attrs).forEach(([key, value]) => {
980
+ if (key.startsWith("on") || key === "href") return;
981
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
982
+ link.setAttribute(key, String(value));
983
+ }
984
+ });
985
+ if (typeof nodes === "string") {
986
+ link.textContent = nodes;
987
+ } else if (nodes instanceof Node) {
988
+ link.appendChild(nodes);
989
+ } else if (Array.isArray(nodes)) {
990
+ nodes.forEach((child) => {
991
+ if (typeof child === "string") {
992
+ link.appendChild(document.createTextNode(child));
993
+ } else if (child instanceof Node) {
994
+ link.appendChild(child);
995
+ }
996
+ });
997
+ }
998
+ link.addEventListener("click", (e) => {
999
+ if (target || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) {
1000
+ return;
1001
+ }
1002
+ e.preventDefault();
1003
+ globalRouter?.navigate(to, { replace: replace2 });
1004
+ });
1005
+ return link;
1006
+ }
1007
+ function Suspense(props) {
1008
+ const anchor = document.createComment("suspense-boundary");
1009
+ let currentNode = null;
1010
+ let fallbackNode = null;
1011
+ let isLoading = false;
1012
+ const cleanupNodes = () => {
1013
+ [currentNode, fallbackNode].forEach((node) => {
1014
+ if (node?.parentNode) {
1015
+ node.parentNode.removeChild(node);
1016
+ }
1017
+ });
1018
+ currentNode = null;
1019
+ fallbackNode = null;
1020
+ };
1021
+ const showFallback = () => {
1022
+ if (fallbackNode || !props.fallback || !anchor.parentNode) return;
1023
+ try {
1024
+ const fallback = typeof props.fallback === "function" ? props.fallback() : props.fallback;
1025
+ if (fallback instanceof HTMLElement) {
1026
+ fallbackNode = fallback;
1027
+ anchor.parentNode.insertBefore(fallbackNode, anchor.nextSibling);
1028
+ }
1029
+ } catch (error) {
1030
+ console.error("[Suspense] Fallback error:", error);
1031
+ }
1032
+ };
1033
+ const hideFallback = () => {
1034
+ if (fallbackNode?.parentNode) {
1035
+ fallbackNode.parentNode.removeChild(fallbackNode);
1036
+ fallbackNode = null;
1037
+ }
1038
+ };
1039
+ const render = async () => {
1040
+ if (isLoading) return;
1041
+ isLoading = true;
1042
+ try {
1043
+ const result = props.nodes();
1044
+ if (result instanceof Promise) {
1045
+ showFallback();
1046
+ const element = await result;
1047
+ if (anchor.parentNode) {
1048
+ cleanupNodes();
1049
+ anchor.parentNode.insertBefore(element, anchor.nextSibling);
1050
+ currentNode = element;
1051
+ }
1052
+ } else {
1053
+ if (anchor.parentNode) {
1054
+ cleanupNodes();
1055
+ anchor.parentNode.insertBefore(result, anchor.nextSibling);
1056
+ currentNode = result;
1057
+ }
1058
+ }
1059
+ } catch (error) {
1060
+ hideFallback();
1061
+ console.error("[Suspense] Nodes error:", error);
1062
+ if (anchor.parentNode) {
1063
+ const errorElement = document.createElement("div");
1064
+ errorElement.className = "suspense-error";
1065
+ errorElement.textContent = error instanceof Error ? error.message : "Failed to load";
1066
+ cleanupNodes();
1067
+ anchor.parentNode.insertBefore(errorElement, anchor.nextSibling);
1068
+ currentNode = errorElement;
1069
+ }
1070
+ } finally {
1071
+ isLoading = false;
1072
+ }
1073
+ };
1074
+ queueMicrotask(render);
1075
+ return anchor;
1076
+ }
1077
+ function lazy(importFn) {
1078
+ return importFn;
1079
+ }
1080
+ async function preloadRoute(to) {
1081
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
1082
+ const path = globalRouter["resolvePath"](to);
1083
+ const match = globalRouter["matcher"].match(path.split("?")[0].split("#")[0]);
1084
+ if (match && "component" in match.route) {
1085
+ try {
1086
+ await globalRouter.loadComponent(match.route, path);
1087
+ } catch (error) {
1088
+ console.warn("[Router] Preload failed:", error);
1089
+ }
1090
+ }
1091
+ }
1092
+ function hasRoute(name) {
1093
+ if (!globalRouter) return false;
1094
+ return globalRouter["matcher"].findByName(name) !== null;
1095
+ }
1096
+ function getRouteInfo(name) {
1097
+ if (!globalRouter) return null;
1098
+ return globalRouter["matcher"].findByName(name);
1099
+ }
1100
+ function buildURL(to) {
1101
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
1102
+ return globalRouter["resolvePath"](to);
1103
+ }
1104
+ function destroyRouter() {
1105
+ for (const fn of routeCleanups) fn();
1106
+ routeCleanups.length = 0;
1107
+ if (globalRouter) {
1108
+ globalRouter.destroy();
1109
+ globalRouter = null;
1110
+ }
1111
+ }
1112
+ if (typeof window !== "undefined") {
1113
+ window.addEventListener("beforeunload", () => {
1114
+ destroyRouter();
1115
+ });
1116
+ }
1117
+ function Outlet() {
1118
+ const anchor = document.createComment("route-outlet-nested");
1119
+ let currentNode = null;
1120
+ const update = async () => {
1121
+ if (!globalRouter) return;
1122
+ const route2 = globalRouter.currentRoute;
1123
+ if (route2.matched.length < 2) return;
1124
+ const childRoute = route2.matched[route2.matched.length - 1];
1125
+ if (!childRoute || !("component" in childRoute)) return;
1126
+ try {
1127
+ const component = await globalRouter.loadComponent(childRoute, route2.path);
1128
+ const node = component();
1129
+ if (node && anchor.parentNode) {
1130
+ if (currentNode?.parentNode) {
1131
+ currentNode.parentNode.removeChild(currentNode);
1132
+ }
1133
+ anchor.parentNode.insertBefore(node, anchor.nextSibling);
1134
+ currentNode = node;
1135
+ }
1136
+ } catch (error) {
1137
+ console.error("[Outlet] Failed to render child route:", error);
1138
+ }
1139
+ };
1140
+ track(update);
1141
+ if (!anchor.parentNode) {
1142
+ queueMicrotask(() => {
1143
+ if (anchor.parentNode) update();
1144
+ });
1145
+ }
1146
+ return anchor;
1147
+ }
1148
+ function addRoute(route2, parentPath) {
1149
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
1150
+ globalRouter.addRoute(route2, parentPath);
1151
+ }
1152
+ function removeRoute(path) {
1153
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
1154
+ globalRouter.removeRoute(path);
1155
+ }
1156
+ function routerState() {
1157
+ if (!globalRouter) throw new Error("Router not initialized. Call createRouter() first.");
1158
+ const router2 = globalRouter;
1159
+ return {
1160
+ currentPath: () => router2.currentRoute.path,
1161
+ params: () => router2.currentRoute.params,
1162
+ query: () => router2.currentRoute.query,
1163
+ hash: () => router2.currentRoute.hash,
1164
+ meta: () => router2.currentRoute.meta,
1165
+ isNavigating: router2.isNavigating,
1166
+ isReady: router2.isReady
1167
+ };
1168
+ }
1169
+ var routerPlugins = [];
1170
+ function routerPlugin(plugin) {
1171
+ routerPlugins.push(plugin);
1172
+ if (globalRouter?.isReady && plugin.onReady) {
1173
+ plugin.onReady();
1174
+ }
1175
+ let removeGuard = null;
1176
+ if (globalRouter && plugin.onNavigate) {
1177
+ removeGuard = globalRouter.afterEach((to, from) => {
1178
+ plugin.onNavigate?.(to, from);
1179
+ });
1180
+ }
1181
+ return () => {
1182
+ const idx = routerPlugins.indexOf(plugin);
1183
+ if (idx !== -1) routerPlugins.splice(idx, 1);
1184
+ removeGuard?.();
1185
+ };
1186
+ }
1187
+ var _routeTransitionOptions = null;
1188
+ function setRouteTransition(options) {
1189
+ _routeTransitionOptions = options;
1190
+ }
1191
+ function getRouteTransition() {
1192
+ return _routeTransitionOptions;
1193
+ }
1194
+ function createMemoryRouter(routes, _initialPath = "/") {
1195
+ const router2 = createRouter(routes, { mode: "hash" });
1196
+ return {
1197
+ router: router2,
1198
+ currentPath: () => router2.currentRoute.path,
1199
+ push: (path) => router2.push(path)
1200
+ };
1201
+ }
1202
+
1203
+ // src/plugins/routerSSR.ts
1204
+ function parseURL(url) {
1205
+ let remaining = url;
1206
+ let hash = "";
1207
+ let queryString = "";
1208
+ const hashIndex = remaining.indexOf("#");
1209
+ if (hashIndex !== -1) {
1210
+ hash = remaining.slice(hashIndex + 1);
1211
+ remaining = remaining.slice(0, hashIndex);
1212
+ }
1213
+ const queryIndex = remaining.indexOf("?");
1214
+ if (queryIndex !== -1) {
1215
+ queryString = remaining.slice(queryIndex + 1);
1216
+ remaining = remaining.slice(0, queryIndex);
1217
+ }
1218
+ const path = remaining || "/";
1219
+ const query = {};
1220
+ if (queryString) {
1221
+ const pairs = queryString.split("&");
1222
+ for (const pair of pairs) {
1223
+ if (!pair) continue;
1224
+ const eqIndex = pair.indexOf("=");
1225
+ if (eqIndex === -1) {
1226
+ query[decodeURIComponent(pair)] = "";
1227
+ } else {
1228
+ const key = decodeURIComponent(pair.slice(0, eqIndex));
1229
+ const value = decodeURIComponent(pair.slice(eqIndex + 1));
1230
+ query[key] = value;
1231
+ }
1232
+ }
1233
+ }
1234
+ return { path, query, hash };
1235
+ }
1236
+ function compilePattern(routePath) {
1237
+ const keys = [];
1238
+ let pattern = "";
1239
+ const segments = routePath.split("/");
1240
+ for (let i = 0; i < segments.length; i++) {
1241
+ const segment = segments[i];
1242
+ if (i > 0) pattern += "\\/";
1243
+ if (!segment) {
1244
+ continue;
1245
+ }
1246
+ if (segment === "*") {
1247
+ keys.push("pathMatch");
1248
+ pattern += "(.*)";
1249
+ continue;
1250
+ }
1251
+ const namedWildcardMatch = segment.match(/^:([^*]+)\*$/);
1252
+ if (namedWildcardMatch) {
1253
+ keys.push(namedWildcardMatch[1]);
1254
+ pattern += "(.*)";
1255
+ continue;
1256
+ }
1257
+ const optionalMatch = segment.match(/^:([^?]+)\?$/);
1258
+ if (optionalMatch) {
1259
+ keys.push(optionalMatch[1]);
1260
+ pattern = pattern.replace(/\\\/$/g, "");
1261
+ pattern += "(?:\\/([^\\/]+))?";
1262
+ continue;
1263
+ }
1264
+ const paramMatch = segment.match(/^:(.+)$/);
1265
+ if (paramMatch) {
1266
+ keys.push(paramMatch[1]);
1267
+ pattern += "([^\\/]+)";
1268
+ continue;
1269
+ }
1270
+ pattern += segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1271
+ }
1272
+ return {
1273
+ regex: new RegExp(`^${pattern}$`),
1274
+ keys
1275
+ };
1276
+ }
1277
+ function matchRoute(path, routes, parentPath = "", parentChain = []) {
1278
+ for (const route2 of routes) {
1279
+ const fullPath = normalizePath(`${parentPath}/${route2.path}`);
1280
+ if (route2.children && route2.children.length > 0) {
1281
+ const childResult = matchRoute(path, route2.children, fullPath, [...parentChain, route2]);
1282
+ if (childResult) {
1283
+ return childResult;
1284
+ }
1285
+ }
1286
+ const compiled = compilePattern(fullPath);
1287
+ const match = path.match(compiled.regex);
1288
+ if (match) {
1289
+ const params = {};
1290
+ for (let i = 0; i < compiled.keys.length; i++) {
1291
+ if (match[i + 1] !== void 0) {
1292
+ params[compiled.keys[i]] = decodeURIComponent(match[i + 1]);
1293
+ }
1294
+ }
1295
+ return {
1296
+ route: route2,
1297
+ params,
1298
+ matched: [...parentChain, route2]
1299
+ };
1300
+ }
1301
+ }
1302
+ return null;
1303
+ }
1304
+ function normalizePath(path) {
1305
+ let normalized = path.replace(/\/+/g, "/");
1306
+ if (!normalized.startsWith("/")) {
1307
+ normalized = `/${normalized}`;
1308
+ }
1309
+ if (normalized.length > 1 && normalized.endsWith("/")) {
1310
+ normalized = normalized.slice(0, -1);
1311
+ }
1312
+ return normalized;
1313
+ }
1314
+ var SSR_ROUTE_STATE_KEY = "__SIBU_ROUTE_STATE__";
1315
+ var MAX_REDIRECT_DEPTH = 10;
1316
+ function resolveServerRoute(url, routes) {
1317
+ return resolveServerRouteInternal(url, routes, 0);
1318
+ }
1319
+ function resolveServerRouteInternal(url, routes, depth) {
1320
+ const { path, query, hash } = parseURL(url);
1321
+ const normalizedPath = normalizePath(path);
1322
+ const match = matchRoute(normalizedPath, routes);
1323
+ if (!match) {
1324
+ return {
1325
+ route: {
1326
+ path: normalizedPath,
1327
+ params: {},
1328
+ query,
1329
+ hash,
1330
+ meta: {}
1331
+ },
1332
+ component: null
1333
+ };
1334
+ }
1335
+ const { route: matchedDef, params } = match;
1336
+ if (matchedDef.redirect) {
1337
+ if (depth >= MAX_REDIRECT_DEPTH) {
1338
+ return {
1339
+ route: {
1340
+ path: normalizedPath,
1341
+ params,
1342
+ query,
1343
+ hash,
1344
+ meta: matchedDef.meta || {},
1345
+ name: matchedDef.name
1346
+ },
1347
+ component: null,
1348
+ redirect: matchedDef.redirect
1349
+ };
1350
+ }
1351
+ if (typeof matchedDef.redirect === "string" && /^https?:\/\/|^\/\//i.test(matchedDef.redirect)) {
1352
+ console.warn(
1353
+ `[SibuJS Router SSR] Redirect to absolute URL "${matchedDef.redirect}" detected. Use relative paths for safer redirects.`
1354
+ );
1355
+ }
1356
+ return resolveServerRouteInternal(matchedDef.redirect, routes, depth + 1);
1357
+ }
1358
+ const routeState = {
1359
+ path: normalizedPath,
1360
+ params,
1361
+ query,
1362
+ hash,
1363
+ meta: matchedDef.meta || {},
1364
+ name: matchedDef.name
1365
+ };
1366
+ return {
1367
+ route: routeState,
1368
+ component: matchedDef.component || null,
1369
+ redirect: void 0
1370
+ };
1371
+ }
1372
+ function renderRouteToString(url, routes, _options) {
1373
+ const resolved = resolveServerRoute(url, routes);
1374
+ let html = "";
1375
+ if (resolved.component) {
1376
+ const element = resolved.component();
1377
+ html = renderToString(element);
1378
+ }
1379
+ return {
1380
+ html,
1381
+ state: resolved.route
1382
+ };
1383
+ }
1384
+ function renderRouteToDocument(url, routes, options) {
1385
+ const { html, state } = renderRouteToString(url, routes, options);
1386
+ const opts = options || {};
1387
+ const metaTags = (opts.meta || []).map(
1388
+ (attrs) => `<meta ${Object.entries(attrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ")} />`
1389
+ ).join("\n ");
1390
+ const linkTags = (opts.links || []).map(
1391
+ (attrs) => `<link ${Object.entries(attrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ")} />`
1392
+ ).join("\n ");
1393
+ const scriptTags = (opts.scripts || []).map((src) => `<script src="${escapeAttr(src)}"></script>`).join("\n ");
1394
+ const stateScript = serializeRouteState(state);
1395
+ return `<!DOCTYPE html>
1396
+ <html>
1397
+ <head>
1398
+ <meta charset="UTF-8" />
1399
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
1400
+ ${opts.title ? `<title>${escapeHtml(opts.title)}</title>` : ""}
1401
+ ${metaTags}
1402
+ ${linkTags}
1403
+ ${opts.headExtra || ""}
1404
+ </head>
1405
+ <body>
1406
+ <div id="app">${html}</div>
1407
+ ${stateScript}
1408
+ ${scriptTags}
1409
+ </body>
1410
+ </html>`;
1411
+ }
1412
+ function serializeRouteState(state) {
1413
+ const json = JSON.stringify(state).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
1414
+ return `<script>window.${SSR_ROUTE_STATE_KEY}=${json}</script>`;
1415
+ }
1416
+ function deserializeRouteState() {
1417
+ if (typeof window === "undefined") return void 0;
1418
+ return window[SSR_ROUTE_STATE_KEY];
1419
+ }
1420
+ function hydrateRouter(routes, options) {
1421
+ const serverState = deserializeRouteState();
1422
+ if (!serverState) {
1423
+ createRouter(routes);
1424
+ return;
1425
+ }
1426
+ createRouter(routes);
1427
+ const container = options?.container || document.getElementById("app");
1428
+ if (container && serverState.path) {
1429
+ const resolved = resolveServerRoute(serverState.path, routes);
1430
+ if (resolved.component) {
1431
+ import("./ssr-YQJ4AYBD.js").then(({ hydrate }) => {
1432
+ if (resolved.component) {
1433
+ hydrate(resolved.component, container);
1434
+ }
1435
+ });
1436
+ }
1437
+ }
1438
+ }
1439
+ function createSSRRouter(routes) {
1440
+ return {
1441
+ resolve(url) {
1442
+ return resolveServerRoute(url, routes);
1443
+ },
1444
+ renderToString(url) {
1445
+ return renderRouteToString(url, routes);
1446
+ },
1447
+ renderToDocument(url, options) {
1448
+ return renderRouteToDocument(url, routes, options);
1449
+ }
1450
+ };
1451
+ }
1452
+ function escapeHtml(str) {
1453
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1454
+ }
1455
+ function escapeAttr(str) {
1456
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1457
+ }
1458
+ export {
1459
+ Outlet,
1460
+ Route,
1461
+ RouterLink,
1462
+ SibuRouter,
1463
+ Suspense,
1464
+ Trans,
1465
+ addRoute,
1466
+ afterEach,
1467
+ back,
1468
+ beforeEach,
1469
+ beforeResolve,
1470
+ buildURL,
1471
+ createMemoryRouter,
1472
+ createRouter,
1473
+ createSSRRouter,
1474
+ deserializeRouteState,
1475
+ destroyRouter,
1476
+ forward,
1477
+ getAvailableLocales,
1478
+ getLocale,
1479
+ getRouteInfo,
1480
+ getRouteTransition,
1481
+ go,
1482
+ hasRoute,
1483
+ hasTranslation,
1484
+ hydrateRouter,
1485
+ lazy,
1486
+ navigate,
1487
+ preloadRoute,
1488
+ push,
1489
+ registerTranslations,
1490
+ removeRoute,
1491
+ renderRouteToDocument,
1492
+ renderRouteToString,
1493
+ replace,
1494
+ resolveServerRoute,
1495
+ route,
1496
+ router,
1497
+ routerPlugin,
1498
+ routerState,
1499
+ serializeRouteState,
1500
+ setLocale,
1501
+ setRouteTransition,
1502
+ setRoutes,
1503
+ t
1504
+ };