@fluixi/core 1.0.0-alpha.100

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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +334 -0
  3. package/dist/cdn/core.global.js +2 -0
  4. package/dist/cli/generate.cjs +5639 -0
  5. package/dist/cli/generate.d.ts +7 -0
  6. package/dist/cli/generate.d.ts.map +1 -0
  7. package/dist/cli/generate.js +2580 -0
  8. package/dist/cli/generate.mjs +5644 -0
  9. package/dist/cli/index.cjs +5639 -0
  10. package/dist/cli/index.d.ts +7 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +2580 -0
  13. package/dist/cli/index.mjs +5644 -0
  14. package/dist/cli/run.cjs +64 -0
  15. package/dist/cli/run.d.ts +3 -0
  16. package/dist/cli/run.d.ts.map +1 -0
  17. package/dist/cli/run.js +62 -0
  18. package/dist/cli/run.mjs +40 -0
  19. package/dist/fluixi.d.ts +5 -0
  20. package/dist/src/cdn/chunk-RKBFEFZP.mjs +987 -0
  21. package/dist/src/cdn/core.cjs +1592 -0
  22. package/dist/src/cdn/core.d.ts +16 -0
  23. package/dist/src/cdn/core.d.ts.map +1 -0
  24. package/dist/src/cdn/core.js +15 -0
  25. package/dist/src/cdn/core.mjs +714 -0
  26. package/dist/src/cdn/router-V2THK27H.mjs +74 -0
  27. package/dist/src/index.cjs +1711 -0
  28. package/dist/src/index.d.ts +4 -0
  29. package/dist/src/index.d.ts.map +1 -0
  30. package/dist/src/index.js +11 -0
  31. package/dist/src/index.mjs +1833 -0
  32. package/dist/src/jsx-dev-runtime.cjs +26 -0
  33. package/dist/src/jsx-dev-runtime.d.ts +2 -0
  34. package/dist/src/jsx-dev-runtime.d.ts.map +1 -0
  35. package/dist/src/jsx-dev-runtime.js +1 -0
  36. package/dist/src/jsx-dev-runtime.mjs +24 -0
  37. package/dist/src/jsx-runtime.cjs +26 -0
  38. package/dist/src/jsx-runtime.d.ts +7 -0
  39. package/dist/src/jsx-runtime.d.ts.map +1 -0
  40. package/dist/src/jsx-runtime.js +8 -0
  41. package/dist/src/jsx-runtime.mjs +24 -0
  42. package/dist/src/lib/client/chunk-FDOPDB6Z.mjs +53 -0
  43. package/dist/src/lib/client/index.cjs +1210 -0
  44. package/dist/src/lib/client/index.d.ts +51 -0
  45. package/dist/src/lib/client/index.d.ts.map +1 -0
  46. package/dist/src/lib/client/index.js +174 -0
  47. package/dist/src/lib/client/index.mjs +293 -0
  48. package/dist/src/lib/client/router-4PTBPZLQ.mjs +891 -0
  49. package/dist/src/lib/context/context.cjs +81 -0
  50. package/dist/src/lib/context/context.d.ts +73 -0
  51. package/dist/src/lib/context/context.d.ts.map +1 -0
  52. package/dist/src/lib/context/context.js +93 -0
  53. package/dist/src/lib/context/context.mjs +64 -0
  54. package/dist/src/lib/context/index.cjs +83 -0
  55. package/dist/src/lib/context/index.d.ts +3 -0
  56. package/dist/src/lib/context/index.d.ts.map +1 -0
  57. package/dist/src/lib/context/index.js +1 -0
  58. package/dist/src/lib/context/index.mjs +64 -0
  59. package/dist/src/lib/control-flow.cjs +35 -0
  60. package/dist/src/lib/control-flow.d.ts +4 -0
  61. package/dist/src/lib/control-flow.d.ts.map +1 -0
  62. package/dist/src/lib/control-flow.js +1 -0
  63. package/dist/src/lib/control-flow.mjs +25 -0
  64. package/dist/src/lib/core.cjs +1710 -0
  65. package/dist/src/lib/core.d.ts +91 -0
  66. package/dist/src/lib/core.d.ts.map +1 -0
  67. package/dist/src/lib/core.js +158 -0
  68. package/dist/src/lib/core.mjs +1833 -0
  69. package/dist/src/lib/env/index.cjs +44 -0
  70. package/dist/src/lib/env/index.d.ts +26 -0
  71. package/dist/src/lib/env/index.d.ts.map +1 -0
  72. package/dist/src/lib/env/index.js +31 -0
  73. package/dist/src/lib/env/index.mjs +23 -0
  74. package/dist/src/lib/i18n/index.cjs +123 -0
  75. package/dist/src/lib/i18n/index.d.ts +110 -0
  76. package/dist/src/lib/i18n/index.d.ts.map +1 -0
  77. package/dist/src/lib/i18n/index.js +164 -0
  78. package/dist/src/lib/i18n/index.mjs +103 -0
  79. package/dist/src/lib/index.cjs +598 -0
  80. package/dist/src/lib/index.d.ts +81 -0
  81. package/dist/src/lib/index.d.ts.map +1 -0
  82. package/dist/src/lib/index.js +130 -0
  83. package/dist/src/lib/index.mjs +688 -0
  84. package/dist/src/lib/isomorphic.cjs +90 -0
  85. package/dist/src/lib/isomorphic.d.ts +114 -0
  86. package/dist/src/lib/isomorphic.d.ts.map +1 -0
  87. package/dist/src/lib/isomorphic.js +132 -0
  88. package/dist/src/lib/isomorphic.mjs +69 -0
  89. package/dist/src/lib/jsx-runtime/index.cjs +21 -0
  90. package/dist/src/lib/jsx-runtime/index.d.ts +13 -0
  91. package/dist/src/lib/jsx-runtime/index.d.ts.map +1 -0
  92. package/dist/src/lib/jsx-runtime/index.js +13 -0
  93. package/dist/src/lib/jsx-runtime/index.mjs +4 -0
  94. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -0
  95. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts +2 -0
  96. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts.map +1 -0
  97. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.js +1 -0
  98. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -0
  99. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -0
  100. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +35 -0
  101. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -0
  102. package/dist/src/lib/plugins/fluixi-routes-plugin.js +118 -0
  103. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -0
  104. package/dist/src/lib/plugins/index.cjs +311 -0
  105. package/dist/src/lib/plugins/index.d.ts +6 -0
  106. package/dist/src/lib/plugins/index.d.ts.map +1 -0
  107. package/dist/src/lib/plugins/index.js +7 -0
  108. package/dist/src/lib/plugins/index.mjs +279 -0
  109. package/dist/src/lib/plugins/route-codegen.cjs +73 -0
  110. package/dist/src/lib/plugins/route-codegen.d.ts +12 -0
  111. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -0
  112. package/dist/src/lib/plugins/route-codegen.js +80 -0
  113. package/dist/src/lib/plugins/route-codegen.mjs +52 -0
  114. package/dist/src/lib/plugins/route-scanner.cjs +189 -0
  115. package/dist/src/lib/plugins/route-scanner.d.ts +38 -0
  116. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -0
  117. package/dist/src/lib/plugins/route-scanner.js +215 -0
  118. package/dist/src/lib/plugins/route-scanner.mjs +158 -0
  119. package/dist/src/lib/plugins/vite.cjs +27 -0
  120. package/dist/src/lib/plugins/vite.d.ts +3 -0
  121. package/dist/src/lib/plugins/vite.d.ts.map +1 -0
  122. package/dist/src/lib/plugins/vite.js +1 -0
  123. package/dist/src/lib/plugins/vite.mjs +6 -0
  124. package/dist/src/lib/render/await.cjs +38 -0
  125. package/dist/src/lib/render/await.d.ts +26 -0
  126. package/dist/src/lib/render/await.d.ts.map +1 -0
  127. package/dist/src/lib/render/await.js +45 -0
  128. package/dist/src/lib/render/await.mjs +17 -0
  129. package/dist/src/lib/render/component.cjs +221 -0
  130. package/dist/src/lib/render/component.d.ts +296 -0
  131. package/dist/src/lib/render/component.d.ts.map +1 -0
  132. package/dist/src/lib/render/component.js +514 -0
  133. package/dist/src/lib/render/component.mjs +214 -0
  134. package/dist/src/lib/render/deferred.cjs +175 -0
  135. package/dist/src/lib/render/deferred.d.ts +36 -0
  136. package/dist/src/lib/render/deferred.d.ts.map +1 -0
  137. package/dist/src/lib/render/deferred.js +141 -0
  138. package/dist/src/lib/render/deferred.mjs +158 -0
  139. package/dist/src/lib/render/index.cjs +573 -0
  140. package/dist/src/lib/render/index.d.ts +98 -0
  141. package/dist/src/lib/render/index.d.ts.map +1 -0
  142. package/dist/src/lib/render/index.js +180 -0
  143. package/dist/src/lib/render/index.mjs +590 -0
  144. package/dist/src/lib/render/lazy.cjs +67 -0
  145. package/dist/src/lib/render/lazy.d.ts +49 -0
  146. package/dist/src/lib/render/lazy.d.ts.map +1 -0
  147. package/dist/src/lib/render/lazy.js +105 -0
  148. package/dist/src/lib/render/lazy.mjs +50 -0
  149. package/dist/src/lib/render/suspense.cjs +141 -0
  150. package/dist/src/lib/render/suspense.d.ts +65 -0
  151. package/dist/src/lib/render/suspense.d.ts.map +1 -0
  152. package/dist/src/lib/render/suspense.js +196 -0
  153. package/dist/src/lib/render/suspense.mjs +136 -0
  154. package/dist/src/lib/render/versions.cjs +35 -0
  155. package/dist/src/lib/render/versions.d.ts +2 -0
  156. package/dist/src/lib/render/versions.d.ts.map +1 -0
  157. package/dist/src/lib/render/versions.js +21 -0
  158. package/dist/src/lib/render/versions.mjs +14 -0
  159. package/dist/src/lib/router/data.cjs +228 -0
  160. package/dist/src/lib/router/data.d.ts +142 -0
  161. package/dist/src/lib/router/data.d.ts.map +1 -0
  162. package/dist/src/lib/router/data.js +258 -0
  163. package/dist/src/lib/router/data.mjs +214 -0
  164. package/dist/src/lib/router/index.cjs +921 -0
  165. package/dist/src/lib/router/index.d.ts +274 -0
  166. package/dist/src/lib/router/index.d.ts.map +1 -0
  167. package/dist/src/lib/router/index.js +904 -0
  168. package/dist/src/lib/router/index.mjs +938 -0
  169. package/dist/src/lib/router/scroll.cjs +79 -0
  170. package/dist/src/lib/router/scroll.d.ts +19 -0
  171. package/dist/src/lib/router/scroll.d.ts.map +1 -0
  172. package/dist/src/lib/router/scroll.js +68 -0
  173. package/dist/src/lib/router/scroll.mjs +58 -0
  174. package/dist/src/lib/router/transition.cjs +75 -0
  175. package/dist/src/lib/router/transition.d.ts +81 -0
  176. package/dist/src/lib/router/transition.d.ts.map +1 -0
  177. package/dist/src/lib/router/transition.js +136 -0
  178. package/dist/src/lib/router/transition.mjs +54 -0
  179. package/dist/src/lib/server/hydration.cjs +169 -0
  180. package/dist/src/lib/server/hydration.d.ts +198 -0
  181. package/dist/src/lib/server/hydration.d.ts.map +1 -0
  182. package/dist/src/lib/server/hydration.js +345 -0
  183. package/dist/src/lib/server/hydration.mjs +148 -0
  184. package/dist/src/lib/server/index.cjs +406 -0
  185. package/dist/src/lib/server/index.d.ts +115 -0
  186. package/dist/src/lib/server/index.d.ts.map +1 -0
  187. package/dist/src/lib/server/index.js +164 -0
  188. package/dist/src/lib/server/index.mjs +384 -0
  189. package/dist/src/lib/server/reactive.cjs +197 -0
  190. package/dist/src/lib/server/reactive.d.ts +239 -0
  191. package/dist/src/lib/server/reactive.d.ts.map +1 -0
  192. package/dist/src/lib/server/reactive.js +413 -0
  193. package/dist/src/lib/server/reactive.mjs +176 -0
  194. package/dist/src/lib/storage/cache.cjs +51 -0
  195. package/dist/src/lib/storage/cache.d.ts +18 -0
  196. package/dist/src/lib/storage/cache.d.ts.map +1 -0
  197. package/dist/src/lib/storage/cache.js +42 -0
  198. package/dist/src/lib/storage/cache.mjs +30 -0
  199. package/dist/src/lib/storage/index.cjs +246 -0
  200. package/dist/src/lib/storage/index.d.ts +83 -0
  201. package/dist/src/lib/storage/index.d.ts.map +1 -0
  202. package/dist/src/lib/storage/index.js +179 -0
  203. package/dist/src/lib/storage/index.mjs +231 -0
  204. package/dist/src/lib/storage/persisted.cjs +91 -0
  205. package/dist/src/lib/storage/persisted.d.ts +53 -0
  206. package/dist/src/lib/storage/persisted.d.ts.map +1 -0
  207. package/dist/src/lib/storage/persisted.js +75 -0
  208. package/dist/src/lib/storage/persisted.mjs +70 -0
  209. package/dist/src/lib/theme/color-scheme.cjs +281 -0
  210. package/dist/src/lib/theme/color-scheme.d.ts +61 -0
  211. package/dist/src/lib/theme/color-scheme.d.ts.map +1 -0
  212. package/dist/src/lib/theme/color-scheme.js +120 -0
  213. package/dist/src/lib/theme/color-scheme.mjs +265 -0
  214. package/dist/src/lib/theme/index.cjs +267 -0
  215. package/dist/src/lib/theme/index.d.ts +78 -0
  216. package/dist/src/lib/theme/index.d.ts.map +1 -0
  217. package/dist/src/lib/theme/index.js +135 -0
  218. package/dist/src/lib/theme/index.mjs +251 -0
  219. package/dist/src/lib/theme/provider.cjs +346 -0
  220. package/dist/src/lib/theme/provider.d.ts +34 -0
  221. package/dist/src/lib/theme/provider.d.ts.map +1 -0
  222. package/dist/src/lib/theme/provider.js +60 -0
  223. package/dist/src/lib/theme/provider.mjs +332 -0
  224. package/dist/src/lib/utils/index.cjs +209 -0
  225. package/dist/src/lib/utils/index.d.ts +286 -0
  226. package/dist/src/lib/utils/index.d.ts.map +1 -0
  227. package/dist/src/lib/utils/index.js +434 -0
  228. package/dist/src/lib/utils/index.mjs +188 -0
  229. package/dist/src/routes.cjs +37 -0
  230. package/dist/src/routes.d.ts +22 -0
  231. package/dist/src/routes.d.ts.map +1 -0
  232. package/dist/src/routes.js +20 -0
  233. package/dist/src/routes.mjs +17 -0
  234. package/dist/src/server.cjs +405 -0
  235. package/dist/src/server.d.ts +63 -0
  236. package/dist/src/server.d.ts.map +1 -0
  237. package/dist/src/server.js +62 -0
  238. package/dist/src/server.mjs +382 -0
  239. package/dist/src/utils.cjs +21 -0
  240. package/dist/src/utils.d.ts +10 -0
  241. package/dist/src/utils.d.ts.map +1 -0
  242. package/dist/src/utils.js +9 -0
  243. package/dist/src/utils.mjs +4 -0
  244. package/dist/src/version.generated.cjs +26 -0
  245. package/dist/src/version.generated.d.ts +3 -0
  246. package/dist/src/version.generated.d.ts.map +1 -0
  247. package/dist/src/version.generated.js +3 -0
  248. package/dist/src/version.generated.mjs +5 -0
  249. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  250. package/package.json +164 -0
  251. package/src/index.ts +19 -0
  252. package/types/fluixi.d.ts +5 -0
  253. package/types/vinxi.d.ts +50 -0
@@ -0,0 +1,1710 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/core.ts
21
+ var core_exports = {};
22
+ __export(core_exports, {
23
+ $component: () => $component,
24
+ Await: () => Await,
25
+ ClientOnly: () => import_dom16.ClientOnly,
26
+ ColorSchemeProvider: () => ColorSchemeProvider,
27
+ Dynamic: () => import_dom16.Dynamic,
28
+ ErrorBoundary: () => import_dom16.ErrorBoundary,
29
+ FRAMEWORK_NAME: () => FRAMEWORK_NAME,
30
+ For: () => import_dom16.For,
31
+ Index: () => import_dom16.Index,
32
+ Island: () => import_dom19.Island,
33
+ Link: () => Link,
34
+ Match: () => import_dom16.Match,
35
+ NoSsr: () => import_dom16.NoSsr,
36
+ Portal: () => import_dom16.Portal,
37
+ Router: () => Router,
38
+ Show: () => import_dom16.Show,
39
+ Store: () => import_store.Store,
40
+ Suspense: () => Suspense,
41
+ SuspenseList: () => SuspenseList,
42
+ Switch: () => import_dom16.Switch,
43
+ ThemeProvider: () => ThemeProvider,
44
+ VERSION: () => VERSION2,
45
+ addClass: () => import_dom18.addClass,
46
+ appendChildren: () => import_dom18.appendChildren,
47
+ batch: () => import_signal18.batch,
48
+ classMap: () => import_dom19.classMap,
49
+ cleanupDelegation: () => cleanupDelegation,
50
+ clientOnly: () => clientOnly,
51
+ closest: () => import_dom18.closest,
52
+ composeProviders: () => composeProviders,
53
+ createColorScheme: () => createColorScheme,
54
+ createComponent: () => createComponent,
55
+ createComputed: () => import_signal18.createComputed,
56
+ createContext: () => createContext3,
57
+ createDebounce: () => import_signal19.createDebounce,
58
+ createDebouncedResource: () => import_signal19.createDebouncedResource,
59
+ createDebouncedSignal: () => import_signal19.createDebouncedSignal,
60
+ createDeferred: () => import_signal18.createDeferred,
61
+ createEffect: () => import_signal18.createEffect,
62
+ createIsomorphicState: () => createIsomorphicState,
63
+ createIsomorphicStore: () => createIsomorphicStore,
64
+ createMemo: () => import_signal18.createMemo,
65
+ createProvider: () => createProvider,
66
+ createRenderEffect: () => import_signal18.createRenderEffect,
67
+ createResource: () => import_signal18.createResource,
68
+ createRoot: () => import_signal18.createRoot,
69
+ createSelector: () => import_signal19.createSelector,
70
+ createSignal: () => import_signal18.createSignal,
71
+ createStore: () => import_store.createStore,
72
+ createTheme: () => createTheme,
73
+ css: () => import_dom17.css,
74
+ default: () => core_default,
75
+ deferred: () => deferred,
76
+ delegate: () => import_dom18.delegate,
77
+ domCreateElement: () => import_dom18.createElement,
78
+ effect: () => import_signal18.effect,
79
+ env: () => env,
80
+ getAttribute: () => import_dom18.getAttribute,
81
+ getOffset: () => import_dom18.getOffset,
82
+ getOwner: () => import_signal18.getOwner,
83
+ getStyle: () => import_dom18.getStyle,
84
+ hasClass: () => import_dom18.hasClass,
85
+ html: () => import_dom17.html,
86
+ hydrateIslands: () => import_dom19.hydrateIslands,
87
+ initDelegation: () => initDelegation,
88
+ isClient: () => isClient,
89
+ isJSXElement: () => isJSXElement,
90
+ isLitResult: () => isLitResult,
91
+ isNode: () => isNode,
92
+ isRenderable: () => isRenderable,
93
+ isServer: () => import_dom12.isServer,
94
+ isVisible: () => import_dom18.isVisible,
95
+ lazy: () => lazy,
96
+ memo: () => import_signal18.memo,
97
+ mergeProps: () => import_dom19.mergeProps,
98
+ observeIntersection: () => import_dom18.observeIntersection,
99
+ observeResize: () => import_dom18.observeResize,
100
+ onCleanup: () => import_signal18.onCleanup,
101
+ onMount: () => onMount,
102
+ onUnmount: () => onUnmount,
103
+ portal: () => portal,
104
+ query: () => import_dom18.query,
105
+ queryAll: () => import_dom18.queryAll,
106
+ read: () => import_operators.readSignal,
107
+ reduce: () => import_operators.reduceSignal,
108
+ removeAttribute: () => import_dom18.removeAttribute,
109
+ removeChildren: () => import_dom18.removeChildren,
110
+ removeClass: () => import_dom18.removeClass,
111
+ render: () => render,
112
+ requireContext: () => requireContext,
113
+ resource: () => import_signal18.resource,
114
+ runWithOwner: () => import_signal18.runWithOwner,
115
+ scrollIntoView: () => import_dom18.scrollIntoView,
116
+ setAttribute: () => import_dom18.setAttribute,
117
+ setOwner: () => import_signal18.setOwner,
118
+ setStyles: () => import_dom18.setStyles,
119
+ signal: () => import_signal18.signal,
120
+ splitProps: () => import_dom19.splitProps,
121
+ styleMap: () => import_dom19.styleMap,
122
+ svg: () => import_dom17.svg,
123
+ toggleClass: () => import_dom18.toggleClass,
124
+ untrack: () => import_signal18.untrack,
125
+ untrackStore: () => import_store.untrackStore,
126
+ unwrap: () => import_store.unwrap,
127
+ useCallback: () => useCallback,
128
+ useColorScheme: () => useColorScheme,
129
+ useContext: () => useContext3,
130
+ useEffect: () => useEffect,
131
+ useEventListener: () => useEventListener,
132
+ useLocation: () => useLocation,
133
+ useMemo: () => useMemo,
134
+ useNavigate: () => useNavigate,
135
+ useParams: () => useParams,
136
+ useReducer: () => useReducer,
137
+ useRef: () => useRef,
138
+ useRouter: () => useRouter,
139
+ useTheme: () => useTheme,
140
+ waitForElement: () => import_dom18.waitForElement
141
+ });
142
+ module.exports = __toCommonJS(core_exports);
143
+ var import_signal18 = require("@fluixi/reactive/signal");
144
+ var import_signal19 = require("@fluixi/reactive/signal");
145
+ var import_operators = require("@fluixi/reactive/operators");
146
+
147
+ // src/lib/render/index.ts
148
+ var import_dom8 = require("@fluixi/dom");
149
+ var import_signal6 = require("@fluixi/reactive/signal");
150
+
151
+ // src/lib/render/versions.ts
152
+ var import_dom = require("@fluixi/dom");
153
+
154
+ // src/version.generated.ts
155
+ var VERSION = "1.0.0-alpha.100";
156
+
157
+ // src/lib/render/versions.ts
158
+ var import_dom2 = require("@fluixi/dom");
159
+ (0, import_dom.registerCoreVersion)(VERSION);
160
+
161
+ // src/lib/render/index.ts
162
+ var import_dom9 = require("@fluixi/dom");
163
+
164
+ // src/lib/render/component.ts
165
+ var import_dom3 = require("@fluixi/dom");
166
+ var import_dom4 = require("@fluixi/dom");
167
+ var import_signal = require("@fluixi/reactive/signal");
168
+ var _LIFECYCLE = /* @__PURE__ */ Symbol.for("fluixi-lifecycle");
169
+ function getOwnerLifecycle() {
170
+ const owner = (0, import_signal.getOwner)();
171
+ if (!owner) return null;
172
+ if (!owner[_LIFECYCLE]) {
173
+ const lc = { mounts: [], effects: [], scheduled: false };
174
+ owner[_LIFECYCLE] = lc;
175
+ }
176
+ return owner[_LIFECYCLE];
177
+ }
178
+ function scheduleLifecycleFlush(lc) {
179
+ if (lc.scheduled) return;
180
+ if ((0, import_dom3.isServer)()) {
181
+ lc.mounts = [];
182
+ lc.effects = [];
183
+ return;
184
+ }
185
+ lc.scheduled = true;
186
+ const owner = (0, import_signal.getOwner)();
187
+ queueMicrotask(() => {
188
+ if ((0, import_signal.isOwnerDisposed)(owner)) {
189
+ lc.mounts = [];
190
+ lc.effects = [];
191
+ return;
192
+ }
193
+ (0, import_signal.runWithOwner)(owner, () => {
194
+ for (const cb of lc.mounts) {
195
+ try {
196
+ const cleanup = cb();
197
+ if (typeof cleanup === "function") {
198
+ (0, import_signal.onCleanup)(cleanup);
199
+ }
200
+ } catch (e) {
201
+ console.error("Error in onMount callback:", e);
202
+ }
203
+ }
204
+ for (const cb of lc.effects) {
205
+ let cleanup;
206
+ (0, import_signal.createEffect)(() => {
207
+ if (cleanup) cleanup();
208
+ cleanup = cb();
209
+ });
210
+ (0, import_signal.onCleanup)(() => {
211
+ if (cleanup) cleanup();
212
+ });
213
+ }
214
+ lc.mounts = [];
215
+ lc.effects = [];
216
+ });
217
+ });
218
+ }
219
+ function createComponent(Comp, props) {
220
+ return (0, import_dom4.createComponent)(Comp, props);
221
+ }
222
+ function $component(value, props) {
223
+ const component = typeof value === "function" ? (0, import_signal.untrack)(() => value(props)) : value;
224
+ const nameable = component != null && (typeof component === "function" || typeof component === "object");
225
+ if (nameable) {
226
+ try {
227
+ component["$name"] = value.name;
228
+ } catch {
229
+ }
230
+ }
231
+ if (nameable && !(0, import_signal.isSignal)(component)) {
232
+ return (0, import_dom4.asComponent)(component);
233
+ }
234
+ return component;
235
+ }
236
+ function onMount(fn, reactive = true) {
237
+ if ((0, import_dom3.isServer)()) return;
238
+ const lc = getOwnerLifecycle();
239
+ if (lc) {
240
+ if (!reactive) {
241
+ if (!lc.scheduled) {
242
+ fn();
243
+ }
244
+ return;
245
+ }
246
+ lc.mounts.push(fn);
247
+ scheduleLifecycleFlush(lc);
248
+ } else {
249
+ if (!reactive) {
250
+ fn();
251
+ return;
252
+ }
253
+ (0, import_signal.createEffect)(() => {
254
+ const cleanup = (0, import_signal.untrack)(fn);
255
+ if (typeof cleanup === "function") {
256
+ (0, import_signal.onCleanup)(cleanup);
257
+ }
258
+ });
259
+ }
260
+ }
261
+ function onUnmount(fn) {
262
+ (0, import_signal.onCleanup)(fn);
263
+ }
264
+ function useEffect(callback) {
265
+ const lc = getOwnerLifecycle();
266
+ if (lc) {
267
+ lc.effects.push(callback);
268
+ scheduleLifecycleFlush(lc);
269
+ } else {
270
+ let cleanup;
271
+ (0, import_signal.createEffect)(() => {
272
+ if (cleanup) cleanup();
273
+ cleanup = callback();
274
+ });
275
+ (0, import_signal.onCleanup)(() => {
276
+ if (cleanup) cleanup();
277
+ });
278
+ }
279
+ }
280
+ function useMemo(fn) {
281
+ return (0, import_signal.createMemo)(fn);
282
+ }
283
+ function useRef(initialValue) {
284
+ const ref = { current: initialValue };
285
+ (0, import_signal.onCleanup)(() => {
286
+ ref.current = null;
287
+ });
288
+ return ref;
289
+ }
290
+ function useReducer(reducer, initialState) {
291
+ const [state, setState] = (0, import_signal.createSignal)(initialState);
292
+ const dispatch = (action2) => {
293
+ setState(reducer(state(), action2));
294
+ };
295
+ return [state, dispatch];
296
+ }
297
+ function useEventListener(target, event, handler, options) {
298
+ useEffect(() => {
299
+ const element = target && "current" in target ? target.current : target;
300
+ if (!element) return;
301
+ element.addEventListener(event, handler, options);
302
+ return () => {
303
+ element.removeEventListener(event, handler, options);
304
+ };
305
+ });
306
+ }
307
+ function useCallback(callback) {
308
+ return callback;
309
+ }
310
+
311
+ // src/lib/render/suspense.ts
312
+ var import_signal2 = require("@fluixi/reactive/signal");
313
+ var import_dom5 = require("@fluixi/dom");
314
+ function isNode(value) {
315
+ if (typeof window === "undefined") return false;
316
+ if (typeof Node === "function" && value instanceof Node) return true;
317
+ return !!(value && typeof value === "object" && typeof value.nodeType === "number");
318
+ }
319
+ function isLitResult(value) {
320
+ if (!value || typeof value !== "object") return false;
321
+ return !!(typeof value["_$litType$"] !== "undefined" || typeof value["_$litDirective$"] !== "undefined" || Array.isArray(value.strings) && Array.isArray(value.values));
322
+ }
323
+ function isPromise(value) {
324
+ return !!(value && typeof value === "object" && typeof value.then === "function" || value instanceof Promise);
325
+ }
326
+ function isJSXElement(value) {
327
+ return !!(value && typeof value === "object" && "type" in value && "props" in value);
328
+ }
329
+ var SuspenseListContext = (0, import_signal2.createContext)(void 0, "suspense-list");
330
+ function Suspense(props) {
331
+ return (0, import_dom5.createComponent)(SuspenseImpl, props);
332
+ }
333
+ function SuspenseImpl(props) {
334
+ const boundary = (0, import_signal2.createSuspenseBoundary)();
335
+ const listCtx = (0, import_signal2.useContext)(SuspenseListContext);
336
+ const listState = listCtx ? listCtx.register(boundary.inFallback) : void 0;
337
+ function instantiateOnce(val) {
338
+ if (val == null || typeof val === "boolean") return null;
339
+ if (typeof val === "function" && (0, import_dom5.isComponent)(val) && !(0, import_signal2.isSignal)(val)) return val();
340
+ return val;
341
+ }
342
+ const fallback = (0, import_dom5.runWithoutHydration)(() => instantiateOnce(props.fallback ?? null));
343
+ const children = (0, import_signal2.provideSuspense)(boundary, () => (0, import_signal2.readChildren)(() => props.children));
344
+ const track = (value, depth) => {
345
+ if (depth > 8) return;
346
+ if (Array.isArray(value)) {
347
+ for (const x of value) track(x, depth + 1);
348
+ } else if (typeof value === "function" && (0, import_signal2.isSignal)(value)) {
349
+ track(value(), depth + 1);
350
+ }
351
+ };
352
+ (0, import_signal2.provideSuspense)(boundary, () => {
353
+ (0, import_signal2.createRenderEffect)(() => track(children, 0));
354
+ });
355
+ const [resolved, setResolved] = (0, import_signal2.createSignal)(void 0);
356
+ const childIsPromise = isPromise(children);
357
+ if (childIsPromise) {
358
+ boundary.increment();
359
+ children.then(
360
+ (v) => {
361
+ setResolved(() => v);
362
+ boundary.decrement();
363
+ },
364
+ () => boundary.decrement()
365
+ );
366
+ }
367
+ return (0, import_signal2.createMemo)(() => {
368
+ const showFallback = listState ? listState.showFallback() : boundary.inFallback();
369
+ if (showFallback) return fallback;
370
+ if (childIsPromise) return resolved();
371
+ return children;
372
+ });
373
+ }
374
+ function SuspenseList(props) {
375
+ return (0, import_dom5.createComponent)(SuspenseListImpl, props);
376
+ }
377
+ function SuspenseListImpl(props) {
378
+ const { revealOrder = "together", tail } = props;
379
+ const registrations = [];
380
+ function coordinateReveal() {
381
+ if (revealOrder === "together") {
382
+ const allResolved = registrations.every((r) => !r.inFallback());
383
+ registrations.forEach((r) => {
384
+ r.setShowContent(allResolved);
385
+ r.setShowFallback(!allResolved);
386
+ });
387
+ } else {
388
+ const items = revealOrder === "backwards" ? [...registrations].reverse() : registrations;
389
+ let blocked = false;
390
+ for (const r of items) {
391
+ if (blocked || r.inFallback()) {
392
+ blocked = true;
393
+ r.setShowContent(false);
394
+ r.setShowFallback(tail !== "hidden");
395
+ } else {
396
+ r.setShowContent(true);
397
+ r.setShowFallback(false);
398
+ }
399
+ }
400
+ }
401
+ }
402
+ const coordinator = {
403
+ register: (inFallback) => {
404
+ const [showContent, setShowContent] = (0, import_signal2.createSignal)(true);
405
+ const [showFallback, setShowFallback] = (0, import_signal2.createSignal)(false);
406
+ registrations.push({ inFallback, setShowContent, setShowFallback });
407
+ (0, import_signal2.createEffect)(() => {
408
+ inFallback();
409
+ coordinateReveal();
410
+ });
411
+ return { showContent, showFallback };
412
+ }
413
+ };
414
+ return SuspenseListContext.Provider({
415
+ value: coordinator,
416
+ children: props.children
417
+ });
418
+ }
419
+ (0, import_dom5.asSuspense)(Suspense);
420
+ Object.defineProperty(Suspense, "__suspense", { value: true, enumerable: true });
421
+
422
+ // src/lib/render/lazy.ts
423
+ var import_dom6 = require("@fluixi/dom");
424
+ var import_signal3 = require("@fluixi/reactive/signal");
425
+ function fromChunk(value) {
426
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
427
+ try {
428
+ value["$lazy"] = true;
429
+ } catch {
430
+ }
431
+ }
432
+ return value;
433
+ }
434
+ function lazy(loader, options) {
435
+ let resolved;
436
+ let promise;
437
+ let component;
438
+ function load() {
439
+ if (!promise) {
440
+ promise = loader().then((mod) => resolved = mod.default);
441
+ }
442
+ return promise;
443
+ }
444
+ if (options?.preload) load();
445
+ const LazyWrapper = ((props) => {
446
+ if (resolved) {
447
+ const C = resolved;
448
+ return fromChunk((0, import_signal3.untrack)(() => C(props)));
449
+ }
450
+ if (!component) {
451
+ const [resource2] = (0, import_signal3.createResource)(() => load(), { transport: false });
452
+ component = resource2;
453
+ if (resource2.error) throw resource2.error;
454
+ }
455
+ return (0, import_signal3.createMemo)(() => {
456
+ const C = component();
457
+ return C ? fromChunk((0, import_dom6.createComponent)(C, props)) : void 0;
458
+ });
459
+ });
460
+ LazyWrapper.preload = () => load().then(() => void 0);
461
+ LazyWrapper.$lazy = true;
462
+ LazyWrapper.loader = loader;
463
+ return LazyWrapper;
464
+ }
465
+
466
+ // src/lib/render/deferred.ts
467
+ var import_dom7 = require("@fluixi/dom");
468
+ var import_signal4 = require("@fluixi/reactive/signal");
469
+ var import_utils = require("@fluixi/dom/utils");
470
+ function deferred(loader, options) {
471
+ const exportName = options.export ?? "default";
472
+ const Lazy = lazy(
473
+ () => loader().then((mod) => {
474
+ const component = mod[exportName];
475
+ if (typeof component !== "function") {
476
+ throw new Error(
477
+ `deferred(): module has no '${exportName}' export (got ${typeof component}).`
478
+ );
479
+ }
480
+ return { default: component };
481
+ }),
482
+ { fallback: options.fallback }
483
+ );
484
+ function Deferred(props) {
485
+ if (options.strategy.kind === "never") return (0, import_dom7.isServer)() ? Lazy(props) : null;
486
+ if ((0, import_dom7.isServer)() || options.strategy.kind === "eager") return Lazy(props);
487
+ const [ready, setReady] = (0, import_signal4.createSignal)(false);
488
+ const start = () => {
489
+ void Lazy.preload().then(() => setReady(true));
490
+ };
491
+ const anchor = options.strategy.kind === "visible" ? createAnchor() : void 0;
492
+ schedule(options.strategy, start, anchor);
493
+ return (0, import_signal4.createMemo)(() => ready() ? Lazy(props) : anchor ?? options.fallback ?? null, void 0, {
494
+ name: "deferred"
495
+ });
496
+ }
497
+ Deferred.preload = Lazy.preload;
498
+ return Deferred;
499
+ }
500
+ function createAnchor() {
501
+ const el = document.createElement("span");
502
+ el.setAttribute("data-fx-load", "visible");
503
+ el.style.display = "block";
504
+ return el;
505
+ }
506
+ function schedule(strategy, start, anchor) {
507
+ let fired = false;
508
+ const once = () => {
509
+ if (fired) return;
510
+ fired = true;
511
+ start();
512
+ };
513
+ switch (strategy.kind) {
514
+ case "idle": {
515
+ const ric = globalThis.requestIdleCallback;
516
+ if (ric) ric(once);
517
+ else setTimeout(once, 1);
518
+ return;
519
+ }
520
+ case "visible": {
521
+ if (!anchor || typeof IntersectionObserver === "undefined") {
522
+ once();
523
+ return;
524
+ }
525
+ const stop = (0, import_utils.observeIntersection)(
526
+ anchor,
527
+ (isIntersecting) => {
528
+ if (!isIntersecting) return;
529
+ stop();
530
+ once();
531
+ },
532
+ { rootMargin: strategy.rootMargin ?? "0px" }
533
+ );
534
+ return;
535
+ }
536
+ case "interaction": {
537
+ const handler = () => {
538
+ for (const event of strategy.events) {
539
+ document.removeEventListener(event, handler, true);
540
+ }
541
+ once();
542
+ };
543
+ for (const event of strategy.events) {
544
+ document.addEventListener(event, handler, { capture: true, passive: true });
545
+ }
546
+ return;
547
+ }
548
+ case "media": {
549
+ if (typeof matchMedia === "undefined") {
550
+ once();
551
+ return;
552
+ }
553
+ const query2 = matchMedia(strategy.query);
554
+ if (query2.matches) {
555
+ once();
556
+ return;
557
+ }
558
+ const onChange = (e) => {
559
+ if (!e.matches) return;
560
+ query2.removeEventListener("change", onChange);
561
+ once();
562
+ };
563
+ query2.addEventListener("change", onChange);
564
+ return;
565
+ }
566
+ /* c8 ignore next 3 */
567
+ default:
568
+ once();
569
+ }
570
+ }
571
+
572
+ // src/lib/render/await.ts
573
+ var import_signal5 = require("@fluixi/reactive/signal");
574
+ function Await(props) {
575
+ const fetcher = () => {
576
+ const v = props.value;
577
+ return typeof v === "function" ? v() : v;
578
+ };
579
+ const [data] = (0, import_signal5.createResource)(fetcher);
580
+ return () => {
581
+ if (data.loading) return props.fallback;
582
+ const child = props.children;
583
+ return typeof child === "function" ? child(data()) : child;
584
+ };
585
+ }
586
+
587
+ // src/lib/render/index.ts
588
+ function render(code, container, options = {}) {
589
+ (0, import_dom9.delegateEvents)(["click", "input", "change", "submit"]);
590
+ if ((0, import_dom8.isServer)()) {
591
+ throw new Error(
592
+ "render() is for client-side only. Use renderToString() on server."
593
+ );
594
+ }
595
+ if (!container) {
596
+ throw new Error("Container element is required");
597
+ }
598
+ let disposer;
599
+ (0, import_signal6.createRoot)((dispose) => {
600
+ disposer = dispose;
601
+ const result = typeof code === "function" ? code() : code;
602
+ container.textContent = "";
603
+ (0, import_dom2.stampVersions)(container);
604
+ (0, import_dom2.warnOnVersionSkew)();
605
+ (0, import_dom9.insert)(container, () => result);
606
+ });
607
+ return () => {
608
+ if (disposer) {
609
+ disposer();
610
+ disposer = void 0;
611
+ }
612
+ };
613
+ }
614
+ function isLitTemplateResult(value) {
615
+ return value && typeof value === "object" && (value["_$litType$"] !== void 0 || value["_$litDirective$"] !== void 0);
616
+ }
617
+ function portal(code, target, options = {}) {
618
+ const container = document.createElement("div");
619
+ container.setAttribute("data-portal", "true");
620
+ target.appendChild(container);
621
+ const dispose = render(code, container, options);
622
+ return () => {
623
+ dispose();
624
+ if (target.contains(container)) {
625
+ target.removeChild(container);
626
+ }
627
+ };
628
+ }
629
+ function isRenderable(value) {
630
+ if (value == null) return true;
631
+ if (typeof value === "function") return true;
632
+ if ((0, import_dom9.isDOMNode)(value)) return true;
633
+ if (isLitTemplateResult(value)) return true;
634
+ if (Array.isArray(value)) return true;
635
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
636
+ return true;
637
+ }
638
+ return false;
639
+ }
640
+ function initDelegation() {
641
+ if ((0, import_dom8.isServer)()) return;
642
+ (0, import_dom9.delegateEvents)(["click", "input", "change", "submit"]);
643
+ }
644
+ function cleanupDelegation() {
645
+ if ((0, import_dom8.isServer)()) return;
646
+ }
647
+
648
+ // src/lib/context/context.ts
649
+ var import_dom10 = require("@fluixi/dom");
650
+ var import_signal7 = require("@fluixi/reactive/signal");
651
+ function createContext3(defaultValue, name) {
652
+ const context = (0, import_signal7.createContext)(defaultValue, name);
653
+ const Provider = (props) => (
654
+ // Children stay a getter: the reactive Provider reads them after stamping the value on
655
+ // its owner. Reading `props.children` here would render them, and any <Outlet/> in them,
656
+ // before the context exists.
657
+ context.Provider({
658
+ value: props.value,
659
+ get children() {
660
+ return props.children;
661
+ },
662
+ debug: props.debug
663
+ })
664
+ );
665
+ return {
666
+ id: context.id,
667
+ Provider: (0, import_dom10.asProvider)(Provider),
668
+ defaultValue
669
+ };
670
+ }
671
+ function useContext3(context) {
672
+ const value = (0, import_signal7.useContext)(context);
673
+ return value !== void 0 ? value : context.defaultValue;
674
+ }
675
+ function createProvider(context, value, props) {
676
+ const resolved = typeof value === "function" ? value() : value;
677
+ return context.Provider({
678
+ value: resolved,
679
+ get children() {
680
+ return props.children;
681
+ }
682
+ });
683
+ }
684
+ function composeProviders(providers, props) {
685
+ const outermost = providers.reduceRight(
686
+ (inner, [context, value]) => ({
687
+ get children() {
688
+ return createProvider(context, value, inner);
689
+ }
690
+ }),
691
+ props
692
+ );
693
+ return outermost.children;
694
+ }
695
+ function requireContext(context, message) {
696
+ for (let owner = (0, import_signal7.getOwner)(); owner; owner = owner.parent) {
697
+ if (owner.contexts?.has(context.id)) return useContext3(context);
698
+ }
699
+ throw new Error(message ?? `[fluixi] No Provider for ${context.id.description ?? "this context"} above this component.`);
700
+ }
701
+
702
+ // src/lib/isomorphic.ts
703
+ var import_signal8 = require("@fluixi/reactive/signal");
704
+ var import_dom11 = require("@fluixi/dom");
705
+ var import_storage = require("@fluixi/storage");
706
+ var import_browser = require("@fluixi/storage/browser");
707
+ var REGISTRY_KEY = "__fluixi_iso_states__";
708
+ var SEED_PREFIX = "__iso:";
709
+ function registry() {
710
+ return globalThis[REGISTRY_KEY] ??= /* @__PURE__ */ new Map();
711
+ }
712
+ function readSeed(key) {
713
+ if (typeof window === "undefined") return void 0;
714
+ const data = (0, import_dom11.getServerData)();
715
+ return data ? data[SEED_PREFIX + key] : void 0;
716
+ }
717
+ function createIsomorphicState(key, options) {
718
+ const seed = readSeed(key);
719
+ const initial = seed !== void 0 ? seed : typeof window !== "undefined" && options.client ? options.client() : options.fallback;
720
+ const [value, set] = (0, import_signal8.createSignal)(initial, { name: key });
721
+ registry().set(key, { server: options.server, set });
722
+ return { value, set, key };
723
+ }
724
+ function createIsomorphicStore(key, options) {
725
+ const seeded = readSeed(key) !== void 0;
726
+ const base = createIsomorphicState(key, {
727
+ server: options.server,
728
+ fallback: options.fallback
729
+ });
730
+ const value = () => base.value() ?? options.fallback;
731
+ const persistWrite = (v) => {
732
+ const target = options.persist;
733
+ if (!target) return;
734
+ if (typeof target === "string" && typeof window === "undefined") return;
735
+ try {
736
+ const { storage, key: key2 } = typeof target === "string" ? { storage: (0, import_storage.createSyncStorage)({ adapter: (0, import_browser.localStorageAdapter)() }), key: target } : target;
737
+ storage.set(key2, v);
738
+ } catch {
739
+ }
740
+ };
741
+ const set = (v) => {
742
+ base.set(v);
743
+ persistWrite(v);
744
+ };
745
+ const setField = (k, val) => {
746
+ set({ ...value(), [k]: val });
747
+ };
748
+ const fields = {};
749
+ for (const k of Object.keys(options.fallback)) {
750
+ fields[k] = (0, import_signal8.createMemo)(() => value()[k], void 0, { name: `${key}.${String(k)}` });
751
+ }
752
+ let initPromise = null;
753
+ const ensureInit = () => {
754
+ if (seeded || !options.client) return Promise.resolve();
755
+ if (!initPromise) {
756
+ initPromise = Promise.resolve(options.client()).then((v) => {
757
+ set(v);
758
+ }).catch((e) => {
759
+ initPromise = null;
760
+ throw e;
761
+ });
762
+ }
763
+ return initPromise;
764
+ };
765
+ return { value, fields, set, setField, ensureInit, key, seeded };
766
+ }
767
+
768
+ // src/lib/env/index.ts
769
+ var import_dom12 = require("@fluixi/dom");
770
+ var import_dom13 = require("@fluixi/dom");
771
+ function isClient() {
772
+ return !(0, import_dom13.isServer)();
773
+ }
774
+ var env = {
775
+ get window() {
776
+ return typeof window !== "undefined" ? window : void 0;
777
+ },
778
+ get document() {
779
+ return typeof document !== "undefined" ? document : void 0;
780
+ }
781
+ };
782
+ function clientOnly(fn, fallback) {
783
+ return isClient() ? fn() : fallback;
784
+ }
785
+
786
+ // src/lib/theme/index.ts
787
+ var import_head = require("@fluixi/head");
788
+ var import_signal11 = require("@fluixi/reactive/signal");
789
+ var import_storage3 = require("@fluixi/storage");
790
+
791
+ // src/lib/storage/persisted.ts
792
+ var import_signal9 = require("@fluixi/reactive/signal");
793
+ var isAsync = (storage) => "encryption" in storage;
794
+ function persisted(storage, key, options = {}) {
795
+ const fallback = options.fallback ?? null;
796
+ const name = options.name ?? `storage:${storage.keyPrefix}${key}`;
797
+ const state = (0, import_signal9.signal)(isAsync(storage) ? fallback : storage.get(key) ?? fallback, { name });
798
+ const put = (value) => state.set(() => value);
799
+ const resolve = (next) => typeof next === "function" ? next((0, import_signal9.untrack)(state)) : next;
800
+ const writeOptions = (extra) => ({
801
+ ...options.ttl !== void 0 ? { ttl: options.ttl } : {},
802
+ ...options.encrypt ? { encrypt: true } : {},
803
+ ...extra
804
+ });
805
+ if (!isAsync(storage)) {
806
+ const off2 = storage.subscribe(key, (event) => {
807
+ if (event.type !== "set") return put(fallback);
808
+ if (event.value !== void 0) put(event.value);
809
+ });
810
+ if ((0, import_signal9.getOwner)()) (0, import_signal9.onCleanup)(off2);
811
+ return Object.assign(() => state(), {
812
+ set(next, extra) {
813
+ const value = resolve(next);
814
+ storage.set(key, value, writeOptions(extra));
815
+ put(value);
816
+ },
817
+ remove() {
818
+ storage.remove(key);
819
+ put(fallback);
820
+ }
821
+ });
822
+ }
823
+ let written = false;
824
+ const reread = () => storage.get(key).then(
825
+ (value) => put(value ?? fallback),
826
+ () => void 0
827
+ );
828
+ const off = storage.subscribe(key, (event) => {
829
+ if (event.type !== "set") return put(fallback);
830
+ if (event.value !== void 0) put(event.value);
831
+ else void reread();
832
+ });
833
+ if ((0, import_signal9.getOwner)()) (0, import_signal9.onCleanup)(off);
834
+ const ready = storage.get(key).then((value) => {
835
+ if (!written) put(value ?? fallback);
836
+ });
837
+ return Object.assign(() => state(), {
838
+ ready,
839
+ async set(next, extra) {
840
+ const previous = (0, import_signal9.untrack)(state);
841
+ const value = resolve(next);
842
+ written = true;
843
+ put(value);
844
+ try {
845
+ await storage.set(key, value, writeOptions(extra));
846
+ } catch (error) {
847
+ put(previous);
848
+ throw error;
849
+ }
850
+ },
851
+ async remove() {
852
+ written = true;
853
+ await storage.remove(key);
854
+ put(fallback);
855
+ }
856
+ });
857
+ }
858
+
859
+ // src/lib/storage/index.ts
860
+ var import_dom14 = require("@fluixi/dom");
861
+ var import_signal10 = require("@fluixi/reactive/signal");
862
+ var import_storage2 = require("@fluixi/storage");
863
+ var import_browser2 = require("@fluixi/storage/browser");
864
+ var import_server = require("@fluixi/storage/server");
865
+ var StorageContext = (0, import_signal10.createContext)(void 0, "storage");
866
+ var AsyncStorageContext = (0, import_signal10.createContext)(void 0, "asyncStorage");
867
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
868
+ var perRequest = /* @__PURE__ */ new WeakMap();
869
+ var perPage = /* @__PURE__ */ new Map();
870
+ function cached(scope, id, make) {
871
+ let adapter = scope.get(id);
872
+ if (!adapter) scope.set(id, adapter = make());
873
+ return adapter;
874
+ }
875
+ function requestRequired(scope) {
876
+ throw new import_storage2.StorageUnavailableError(
877
+ `useStorage({ scope: '${scope}' }) on the server needs a request: call it during a render, a loader or a server function, or provide a storage with <StorageProvider>.`
878
+ );
879
+ }
880
+ function adapterFor(scope, cookie = {}) {
881
+ const ctx = (0, import_dom14.getRequestContext)();
882
+ const options = { httpOnly: false, ...cookie };
883
+ switch (scope) {
884
+ case "local":
885
+ return (0, import_browser2.localStorageAdapter)();
886
+ case "session":
887
+ return (0, import_browser2.sessionStorageAdapter)();
888
+ case "request":
889
+ if (isBrowser()) return cached(perPage, "request", import_storage2.memoryStorage);
890
+ if (!ctx) requestRequired(scope);
891
+ return cached(perRequest.get(ctx) ?? perRequest.set(ctx, /* @__PURE__ */ new Map()).get(ctx), "request", import_server.requestStorage);
892
+ case "cookie": {
893
+ const id = `cookie:${JSON.stringify(options)}`;
894
+ if (isBrowser()) {
895
+ const { httpOnly: _ignored, ...browser } = options;
896
+ return cached(perPage, id, () => (0, import_browser2.documentCookieAdapter)(browser));
897
+ }
898
+ if (!ctx) requestRequired(scope);
899
+ const raw = ctx.event.request;
900
+ const target = raw && typeof raw === "object" ? raw : void 0;
901
+ return cached(
902
+ perRequest.get(ctx) ?? perRequest.set(ctx, /* @__PURE__ */ new Map()).get(ctx),
903
+ id,
904
+ () => (0, import_server.cookieStorage)({
905
+ ...options,
906
+ request: raw && typeof raw === "object" && ("headers" in raw || "getHeader" in raw) ? (0, import_server.toStorageRequest)(raw) : void 0,
907
+ response: {
908
+ appendHeader(name, value) {
909
+ if (!(0, import_dom14.appendResponseHeader)(name, value, target)) {
910
+ throw new import_storage2.StorageUnavailableError("The response headers were already sent, so this cookie cannot reach the browser. Write it before the page head goes out: in middleware, a loader, a server function or the render before its first chunk.");
911
+ }
912
+ }
913
+ }
914
+ })
915
+ );
916
+ }
917
+ }
918
+ }
919
+ function useStorage(options = {}) {
920
+ const { scope = "auto", cookie, ...storageOptions } = options;
921
+ if (scope === "auto") {
922
+ const provided = (0, import_signal10.useContext)(StorageContext);
923
+ if (provided) return options.namespace ? provided.namespace(options.namespace) : provided;
924
+ }
925
+ return (0, import_storage2.createSyncStorage)({ ...storageOptions, adapter: resolveAdapter(scope, cookie) });
926
+ }
927
+ function resolveAdapter(scope, cookie) {
928
+ if (scope !== "auto") return adapterFor(scope, cookie);
929
+ if (isBrowser()) return adapterFor("local");
930
+ if (!(0, import_dom14.getRequestContext)()) requestRequired(scope);
931
+ return adapterFor("request");
932
+ }
933
+
934
+ // src/lib/theme/index.ts
935
+ function systemMap(system) {
936
+ if (!system) return null;
937
+ if (system === true) return { dark: "dark", light: "light" };
938
+ return system;
939
+ }
940
+ var YEAR = 60 * 60 * 24 * 365;
941
+ function defaultStorage() {
942
+ try {
943
+ return useStorage({ scope: "cookie", cookie: { maxAge: YEAR, sameSite: "lax" } });
944
+ } catch (error) {
945
+ if (error instanceof import_storage3.StorageUnavailableError) return null;
946
+ throw error;
947
+ }
948
+ }
949
+ function storedLookup(storage, key) {
950
+ if (!storage) return null;
951
+ const full = storage.keyPrefix + key;
952
+ if (storage.scope === "cookie") {
953
+ return { from: "cookie", name: encodeURIComponent(full).replace(/[()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`) };
954
+ }
955
+ if (storage.scope === "local") return { from: "local", name: full };
956
+ return null;
957
+ }
958
+ function createTheme(options) {
959
+ const storageKey = options.storageKey ?? "theme";
960
+ const attribute = options.attribute ?? "data-theme";
961
+ const sys = systemMap(options.system);
962
+ const storage = options.storage === void 0 ? defaultStorage() : options.storage;
963
+ const valid = (t) => typeof t === "string" && options.themes.includes(t);
964
+ const fallback = sys && env.window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches ? sys.dark : sys ? sys.light : options.default;
965
+ const stored = storage ? persisted(storage, storageKey) : null;
966
+ const [unsaved, setUnsaved] = (0, import_signal11.createSignal)(null);
967
+ const value = () => {
968
+ const local = unsaved();
969
+ if (local !== null) return local;
970
+ const saved = stored?.();
971
+ return valid(saved) ? saved : fallback;
972
+ };
973
+ const [isLoading, setLoading] = (0, import_signal11.createSignal)(false);
974
+ const apply = (t) => {
975
+ env.document?.documentElement.setAttribute(attribute, t);
976
+ };
977
+ const set = (t) => {
978
+ if (!options.themes.includes(t)) return;
979
+ const prev = value();
980
+ try {
981
+ stored?.set(t);
982
+ setUnsaved(stored ? null : t);
983
+ } catch {
984
+ setUnsaved(() => t);
985
+ }
986
+ apply(t);
987
+ options.onChange?.(t, prev);
988
+ if (options.load) {
989
+ setLoading(true);
990
+ options.onLoading?.(t);
991
+ Promise.resolve(options.load(t)).finally(() => {
992
+ setLoading(false);
993
+ options.onLoaded?.(t);
994
+ });
995
+ }
996
+ };
997
+ const toggle = () => {
998
+ const i = options.themes.indexOf(value());
999
+ set(options.themes[(i + 1) % options.themes.length]);
1000
+ };
1001
+ const init = () => apply(value());
1002
+ const scriptBody = () => {
1003
+ const cfg = JSON.stringify({ s: storedLookup(storage, storageKey), a: attribute, d: options.default, sys, ts: options.themes }).replace(/</g, "\\u003c");
1004
+ return `(function(){try{var c=${cfg},t=null,s=c.s,r=null;if(s&&s.from==='local')r=localStorage.getItem(s.name);if(s&&s.from==='cookie')document.cookie.split('; ').forEach(function(p){var i=p.indexOf('=');if(p.slice(0,i)===s.name)r=decodeURIComponent(p.slice(i+1));});if(r){var e=JSON.parse(r);t=e&&e.v===1?e.value:e;}if(c.ts.indexOf(t)<0)t=null;if(!t&&c.sys)t=matchMedia('(prefers-color-scheme: dark)').matches?c.sys.dark:c.sys.light;if(!t)t=c.d;document.documentElement.setAttribute(c.a,t);}catch(e){}})();`;
1005
+ };
1006
+ const headScript = () => `<script>${scriptBody()}<\/script>`;
1007
+ if ((0, import_head.getActiveHead)()) {
1008
+ (0, import_head.useHead)({
1009
+ htmlAttrs: { [attribute]: () => value() },
1010
+ ...options.script === false ? {} : { script: [{ children: scriptBody() }] }
1011
+ });
1012
+ }
1013
+ return { value, isLoading, set, toggle, init, headScript };
1014
+ }
1015
+
1016
+ // src/lib/theme/color-scheme.ts
1017
+ var import_head2 = require("@fluixi/head");
1018
+ var import_signal12 = require("@fluixi/reactive/signal");
1019
+ var CHOICES = ["system", "light", "dark"];
1020
+ var DARK = "(prefers-color-scheme: dark)";
1021
+ function createColorScheme(options = {}) {
1022
+ const storageKey = options.storageKey ?? "color-scheme";
1023
+ const attribute = options.attribute ?? "data-theme";
1024
+ const systemAs = options.systemAs ?? "resolved";
1025
+ const storage = options.storage === void 0 ? defaultStorage() : options.storage;
1026
+ const saved = storage ? persisted(storage, storageKey) : null;
1027
+ const [unsaved, setUnsaved] = (0, import_signal12.createSignal)(null);
1028
+ const value = () => {
1029
+ const local = unsaved();
1030
+ if (local) return local;
1031
+ const stored = saved?.();
1032
+ return CHOICES.includes(stored) ? stored : "system";
1033
+ };
1034
+ const media = env.window?.matchMedia?.(DARK);
1035
+ const [osDark, setOsDark] = (0, import_signal12.createSignal)(media?.matches ?? false);
1036
+ if (media) {
1037
+ const onChange = () => setOsDark(media.matches);
1038
+ media.addEventListener?.("change", onChange);
1039
+ if ((0, import_signal12.getOwner)()) (0, import_signal12.onCleanup)(() => media.removeEventListener?.("change", onChange));
1040
+ }
1041
+ const resolved = () => {
1042
+ const choice = value();
1043
+ return choice === "system" ? osDark() ? "dark" : "light" : choice;
1044
+ };
1045
+ const shown = () => systemAs === "system" && value() === "system" ? "system" : resolved();
1046
+ const apply = () => {
1047
+ env.document?.documentElement.setAttribute(attribute, shown());
1048
+ };
1049
+ const set = (choice) => {
1050
+ if (!CHOICES.includes(choice)) return;
1051
+ if (!saved) setUnsaved(choice);
1052
+ else {
1053
+ try {
1054
+ saved.set(choice);
1055
+ setUnsaved(null);
1056
+ } catch {
1057
+ setUnsaved(choice);
1058
+ }
1059
+ }
1060
+ apply();
1061
+ options.onChange?.(choice);
1062
+ };
1063
+ const scriptBody = () => {
1064
+ const cfg = JSON.stringify({ s: storedLookup(storage, storageKey), a: attribute, sys: systemAs === "system", tc: options.themeColor ?? null, cs: options.colorSchemeMeta !== false }).replace(/</g, "\\u003c");
1065
+ return `(function(){try{var c=${cfg},t=null,s=c.s,r=null;if(s&&s.from==='local')r=localStorage.getItem(s.name);if(s&&s.from==='cookie')document.cookie.split('; ').forEach(function(p){var i=p.indexOf('=');if(p.slice(0,i)===s.name)r=decodeURIComponent(p.slice(i+1));});if(r){var e=JSON.parse(r);t=e&&e.v===1?e.value:e;}var chosen=t==='light'||t==='dark'?t:null;if(!chosen)t=c.sys?'system':(matchMedia('${DARK}').matches?'dark':'light');document.documentElement.setAttribute(c.a,t);if(chosen&&c.tc)document.querySelectorAll('meta[name="theme-color"]').forEach(function(m){m.setAttribute('content',c.tc[chosen]);m.removeAttribute('media');});if(chosen&&c.cs){var m=document.querySelector('meta[name="color-scheme"]');if(m)m.setAttribute('content',chosen);}}catch(e){}})();`;
1066
+ };
1067
+ if ((0, import_head2.getActiveHead)()) {
1068
+ const colors = options.themeColor;
1069
+ (0, import_head2.useHead)({
1070
+ htmlAttrs: { [attribute]: shown },
1071
+ ...colors ? {
1072
+ themeColor: () => value() === "system" ? [
1073
+ { color: colors.light, media: "(prefers-color-scheme: light)" },
1074
+ { color: colors.dark, media: DARK }
1075
+ ] : colors[resolved()]
1076
+ } : {},
1077
+ ...options.colorSchemeMeta === false ? {} : { colorScheme: () => value() === "system" ? "light dark" : resolved() },
1078
+ ...options.script === false ? {} : { script: [{ children: scriptBody() }] }
1079
+ });
1080
+ }
1081
+ if (env.document && (0, import_signal12.getOwner)()) (0, import_signal12.createEffect)(apply);
1082
+ return {
1083
+ value,
1084
+ resolved,
1085
+ set,
1086
+ toggle: () => set(resolved() === "dark" ? "light" : "dark"),
1087
+ init: apply,
1088
+ headScript: () => `<script>${scriptBody()}<\/script>`
1089
+ };
1090
+ }
1091
+
1092
+ // src/lib/theme/provider.ts
1093
+ var ThemesContext = createContext3(void 0, "themes");
1094
+ function ThemeProvider(props) {
1095
+ const outer = useContext3(ThemesContext);
1096
+ return ThemesContext.Provider({
1097
+ // A nested provider adds to the axes above it rather than hiding them.
1098
+ value: outer ? { ...outer, ...props.themes } : props.themes,
1099
+ get children() {
1100
+ return props.children;
1101
+ }
1102
+ });
1103
+ }
1104
+ function useTheme(name) {
1105
+ const themes = useContext3(ThemesContext);
1106
+ if (!themes || !(name in themes)) {
1107
+ throw new Error(`[fluixi] No theme named "${name}" above this component: provide it with <ThemeProvider> or <ColorSchemeProvider>.`);
1108
+ }
1109
+ return themes[name];
1110
+ }
1111
+ function ColorSchemeProvider(props) {
1112
+ const scheme = createColorScheme(props);
1113
+ return ThemeProvider({
1114
+ themes: { scheme },
1115
+ get children() {
1116
+ return props.children;
1117
+ }
1118
+ });
1119
+ }
1120
+ function useColorScheme() {
1121
+ return useTheme("scheme");
1122
+ }
1123
+
1124
+ // src/lib/router/index.ts
1125
+ var import_signal15 = require("@fluixi/reactive/signal");
1126
+
1127
+ // src/lib/router/transition.ts
1128
+ function supportsViewTransitions() {
1129
+ return typeof document !== "undefined" && typeof document.startViewTransition === "function";
1130
+ }
1131
+ function prefersReducedMotion() {
1132
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
1133
+ return false;
1134
+ }
1135
+ try {
1136
+ return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1137
+ } catch {
1138
+ return false;
1139
+ }
1140
+ }
1141
+ function shouldAnimate(mode) {
1142
+ return mode !== "none" && supportsViewTransitions() && !prefersReducedMotion();
1143
+ }
1144
+ function prepareComponents(components) {
1145
+ const pending = [];
1146
+ for (const component of components) {
1147
+ const preload = component?.preload;
1148
+ if (typeof preload === "function") {
1149
+ try {
1150
+ const result = preload();
1151
+ if (result && typeof result.then === "function") {
1152
+ pending.push(result.catch(() => void 0));
1153
+ }
1154
+ } catch {
1155
+ }
1156
+ }
1157
+ }
1158
+ return pending.length ? Promise.all(pending).then(() => void 0) : null;
1159
+ }
1160
+ function runTransition(mode, commit) {
1161
+ if (!shouldAnimate(mode)) {
1162
+ return Promise.resolve(commit()).then(() => void 0);
1163
+ }
1164
+ const start = document.startViewTransition;
1165
+ try {
1166
+ const transition = start.call(document, () => commit());
1167
+ transition.finished?.catch(() => void 0);
1168
+ transition.ready?.catch(() => void 0);
1169
+ return transition.updateCallbackDone.catch(() => void 0);
1170
+ } catch {
1171
+ return Promise.resolve(commit()).then(() => void 0);
1172
+ }
1173
+ }
1174
+
1175
+ // src/lib/router/index.ts
1176
+ var import_dom15 = require("@fluixi/dom");
1177
+ var import_signal16 = require("@fluixi/reactive/signal");
1178
+ var import_object = require("@fluixi/utils/object");
1179
+ var import_compare = require("@fluixi/utils/compare");
1180
+
1181
+ // src/lib/router/scroll.ts
1182
+ var STORE = "fx:scroll";
1183
+ var KEEP = 100;
1184
+ function keepScroll(initial) {
1185
+ const read3 = () => {
1186
+ try {
1187
+ return JSON.parse(sessionStorage.getItem(STORE) ?? "{}");
1188
+ } catch {
1189
+ return {};
1190
+ }
1191
+ };
1192
+ const positions = read3();
1193
+ const write = () => {
1194
+ const keys = Object.keys(positions);
1195
+ for (const key of keys.slice(0, Math.max(0, keys.length - KEEP))) delete positions[key];
1196
+ try {
1197
+ sessionStorage.setItem(STORE, JSON.stringify(positions));
1198
+ } catch {
1199
+ }
1200
+ };
1201
+ let current = initial.key;
1202
+ const save = () => {
1203
+ if (current === void 0) return;
1204
+ delete positions[current];
1205
+ positions[current] = window.scrollY;
1206
+ write();
1207
+ };
1208
+ const restoration = history.scrollRestoration;
1209
+ history.scrollRestoration = "manual";
1210
+ window.addEventListener("pagehide", save);
1211
+ const to = (top) => window.scrollTo({ top, left: 0, behavior: "instant" });
1212
+ const toHash = (hash) => {
1213
+ if (!hash || hash === "#") return false;
1214
+ const target = document.getElementById(decodeURIComponent(hash.slice(1)));
1215
+ target?.scrollIntoView({ behavior: "instant" });
1216
+ return target !== null;
1217
+ };
1218
+ return {
1219
+ leave: save,
1220
+ arrive(location, from) {
1221
+ current = location.key;
1222
+ if (location.action === "pop" || from === void 0) {
1223
+ const y = location.key === void 0 ? void 0 : positions[location.key];
1224
+ if (y !== void 0) to(y);
1225
+ return;
1226
+ }
1227
+ if (location.action === "replace" && location.pathname === from.pathname) return;
1228
+ if (!toHash(location.hash)) to(0);
1229
+ },
1230
+ dispose() {
1231
+ window.removeEventListener("pagehide", save);
1232
+ history.scrollRestoration = restoration;
1233
+ }
1234
+ };
1235
+ }
1236
+
1237
+ // src/lib/router/index.ts
1238
+ var import_router = require("@fluixi/router");
1239
+
1240
+ // src/lib/router/data.ts
1241
+ var import_signal13 = require("@fluixi/reactive/signal");
1242
+ var import_signal14 = require("@fluixi/reactive/signal");
1243
+ var revalidationListeners = /* @__PURE__ */ new Set();
1244
+ function onRevalidate(listener) {
1245
+ revalidationListeners.add(listener);
1246
+ return () => void revalidationListeners.delete(listener);
1247
+ }
1248
+ var reloadMounted = () => {
1249
+ for (const listener of [...revalidationListeners]) listener();
1250
+ };
1251
+ function revalidate(key, store) {
1252
+ const names = typeof key === "string" ? [key] : Array.isArray(key) ? key : null;
1253
+ drop(names ?? key, store ?? (0, import_signal14.currentResourceCache)());
1254
+ if (names && !store) tellOtherTabs(names);
1255
+ }
1256
+ function drop(what, store) {
1257
+ const matches = Array.isArray(what) ? (k) => what.some((n) => k === n || k.startsWith(n + ":")) : what;
1258
+ for (const k of [...store.keys()]) if (matches(k)) store.delete(k);
1259
+ reloadMounted();
1260
+ }
1261
+ var TABS_KEY = "fluixi:revalidate";
1262
+ function tellOtherTabs(names) {
1263
+ try {
1264
+ localStorage.setItem(TABS_KEY, JSON.stringify({ names, at: Date.now() + Math.random() }));
1265
+ } catch {
1266
+ }
1267
+ }
1268
+ if (typeof window !== "undefined") {
1269
+ window.addEventListener("storage", (event) => {
1270
+ if (event.key !== TABS_KEY || !event.newValue) return;
1271
+ try {
1272
+ const names = JSON.parse(event.newValue).names;
1273
+ if (Array.isArray(names) && names.every((n) => typeof n === "string")) drop(names, (0, import_signal14.currentResourceCache)());
1274
+ } catch {
1275
+ }
1276
+ });
1277
+ }
1278
+ globalThis[/* @__PURE__ */ Symbol.for("fluixi.revalidate")] = (names) => revalidate(names);
1279
+ var RouteDataContext = createContext3(void 0, "route-data");
1280
+ var RouteDataProvider = RouteDataContext.Provider;
1281
+
1282
+ // src/lib/router/index.ts
1283
+ var import_router2 = require("@fluixi/router");
1284
+ var import_signal17 = require("@fluixi/reactive/signal");
1285
+ var RouterContext = (0, import_signal16.createContext)(void 0, "router");
1286
+ var OutletContext = (0, import_signal16.createContext)(void 0, "outlet");
1287
+ var LevelParamsContext = (0, import_signal16.createContext)(void 0, "route-params");
1288
+ var RouteDataContext2 = (0, import_signal16.createContext)(void 0, "route-data");
1289
+ function renderLayer(m, depth, base) {
1290
+ let data;
1291
+ const loader = m.route.data;
1292
+ if (typeof loader === "function") {
1293
+ let cancelled = false;
1294
+ (0, import_signal15.onCleanup)(() => {
1295
+ cancelled = true;
1296
+ });
1297
+ const owner = (0, import_signal15.getOwner)();
1298
+ const router = (0, import_signal16.useContext)(RouterContext);
1299
+ let watching = false;
1300
+ const trackDeps = (deps) => {
1301
+ if (watching || cancelled) return;
1302
+ watching = true;
1303
+ (0, import_signal15.runWithOwner)(owner, () => {
1304
+ let first = true;
1305
+ (0, import_signal15.createEffect)(() => {
1306
+ deps();
1307
+ if (first) first = false;
1308
+ else (0, import_signal15.untrack)(() => void refetch());
1309
+ });
1310
+ });
1311
+ };
1312
+ let readsLocation;
1313
+ const [resource2, { refetch }] = (0, import_signal15.createResource)(() => {
1314
+ const params = (0, import_signal15.untrack)(base.params);
1315
+ const location = (0, import_signal15.untrack)(base.location);
1316
+ readsLocation = false;
1317
+ const result = loader(
1318
+ {
1319
+ params: () => params,
1320
+ location: () => {
1321
+ readsLocation = true;
1322
+ return location;
1323
+ }
1324
+ },
1325
+ owner,
1326
+ () => cancelled,
1327
+ trackDeps
1328
+ );
1329
+ return router ? router.trackLoad(result) : result;
1330
+ });
1331
+ (0, import_signal15.onCleanup)(
1332
+ onRevalidate(() => {
1333
+ if ((0, import_signal15.untrack)(() => base.matched()[depth]?.route) !== m.route) return;
1334
+ void refetch();
1335
+ })
1336
+ );
1337
+ let loadedFor = (0, import_signal15.untrack)(() => JSON.stringify(base.matched()[depth]?.params ?? {}));
1338
+ let searchedFor = (0, import_signal15.untrack)(() => base.location().search);
1339
+ (0, import_signal15.createEffect)(() => {
1340
+ const now = base.matched()[depth];
1341
+ const search = base.location().search;
1342
+ if (now?.route !== m.route) return;
1343
+ const params = JSON.stringify(now.params ?? {});
1344
+ const paramsMoved = params !== loadedFor;
1345
+ const searchMoved = readsLocation !== false && search !== searchedFor;
1346
+ loadedFor = params;
1347
+ searchedFor = search;
1348
+ if (paramsMoved || searchMoved) (0, import_signal15.untrack)(() => void refetch());
1349
+ });
1350
+ data = () => {
1351
+ const error = resource2.error;
1352
+ if (error !== void 0 && error !== null) throw error;
1353
+ const r = resource2;
1354
+ if (r.state === "refreshing") return r.latest;
1355
+ return resource2();
1356
+ };
1357
+ Object.defineProperty(data, "loading", { get: () => resource2.loading });
1358
+ Object.defineProperty(data, "state", { get: () => resource2.state });
1359
+ }
1360
+ const buildPage = () => RouteDataContext2.Provider({
1361
+ value: data,
1362
+ get children() {
1363
+ return LevelParamsContext.Provider({
1364
+ value: m.params,
1365
+ get children() {
1366
+ return OutletContext.Provider({
1367
+ value: { depth, ...base },
1368
+ get children() {
1369
+ return (0, import_dom15.createComponent)(m.component, {});
1370
+ }
1371
+ });
1372
+ }
1373
+ });
1374
+ }
1375
+ });
1376
+ if (!data) return { view: buildPage(), ready: () => true };
1377
+ const res = data;
1378
+ const isLoading = () => {
1379
+ const state = res.state;
1380
+ return state === void 0 ? res.loading : state === "pending" || state === "unresolved";
1381
+ };
1382
+ const [ready, setReady] = (0, import_signal15.createSignal)((0, import_signal15.untrack)(() => !isLoading()));
1383
+ (0, import_signal15.createEffect)(() => setReady(!isLoading()));
1384
+ return { view: (0, import_signal15.createMemo)(() => ready() ? buildPage() : null), ready };
1385
+ }
1386
+ function renderChild(ctx) {
1387
+ const childIdx = ctx.depth + 1;
1388
+ const [childComp, setChildComp] = (0, import_signal15.createSignal)(
1389
+ (0, import_signal15.untrack)(() => ctx.matched()[childIdx]?.component)
1390
+ );
1391
+ (0, import_signal15.createEffect)(() => {
1392
+ const c = ctx.matched()[childIdx]?.component;
1393
+ if ((0, import_signal15.untrack)(childComp) !== c) setChildComp(() => c);
1394
+ });
1395
+ const owner = (0, import_signal15.getOwner)();
1396
+ let shown = null;
1397
+ let pending = null;
1398
+ const drop2 = (layer) => layer?.dispose();
1399
+ (0, import_signal15.onCleanup)(() => {
1400
+ drop2(shown);
1401
+ drop2(pending);
1402
+ shown = pending = null;
1403
+ });
1404
+ const incoming = (0, import_signal15.createMemo)(() => {
1405
+ const component = childComp();
1406
+ if (!component) return null;
1407
+ const m = (0, import_signal15.untrack)(() => ctx.matched())[childIdx];
1408
+ return (0, import_signal15.runWithOwner)(
1409
+ owner,
1410
+ () => (0, import_signal15.createRoot)((dispose) => ({
1411
+ ...renderLayer(m, childIdx, { matched: ctx.matched, params: ctx.params, location: ctx.location }),
1412
+ dispose
1413
+ }))
1414
+ );
1415
+ });
1416
+ return (0, import_signal15.createMemo)(() => {
1417
+ const next = incoming();
1418
+ if (!next) {
1419
+ drop2(shown);
1420
+ drop2(pending);
1421
+ shown = pending = null;
1422
+ return ctx.notFound ? ctx.notFound() : null;
1423
+ }
1424
+ if (next === shown) return shown.view;
1425
+ if (pending && pending !== next) drop2(pending);
1426
+ pending = next;
1427
+ if (shown && !next.ready()) return shown.view;
1428
+ drop2(shown);
1429
+ shown = next;
1430
+ pending = null;
1431
+ return shown.view;
1432
+ });
1433
+ }
1434
+ function renderNotFound(notFound) {
1435
+ if (notFound == null) return buildDefaultNotFound();
1436
+ return typeof notFound === "function" ? (0, import_dom15.createComponent)(notFound, {}) : notFound;
1437
+ }
1438
+ function buildDefaultNotFound() {
1439
+ const el = (0, import_dom15.createNativeElement)("div");
1440
+ (0, import_dom15.setAttribute)(el, "class", "fx-not-found");
1441
+ (0, import_dom15.setAttribute)(el, "role", "main");
1442
+ (0, import_dom15.setAttribute)(
1443
+ el,
1444
+ "style",
1445
+ "min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif"
1446
+ );
1447
+ const h1 = (0, import_dom15.createNativeElement)("h1");
1448
+ (0, import_dom15.setAttribute)(h1, "style", "margin:0;font-size:2.5rem;font-weight:700");
1449
+ (0, import_dom15.insert)(h1, "404");
1450
+ const p = (0, import_dom15.createNativeElement)("p");
1451
+ (0, import_dom15.setAttribute)(p, "style", "margin:0;opacity:.7");
1452
+ (0, import_dom15.insert)(p, "This page could not be found.");
1453
+ el.appendChild(h1);
1454
+ el.appendChild(p);
1455
+ return el;
1456
+ }
1457
+ var pendingTransitionMode;
1458
+ function Router(props) {
1459
+ const history2 = props.history ?? (0, import_router.createBrowserHistory)();
1460
+ const router = (0, import_router.createRouter)({
1461
+ routes: props.routes,
1462
+ base: props.base,
1463
+ history: history2
1464
+ });
1465
+ const [state, setState] = (0, import_signal15.createSignal)(router.state());
1466
+ const [navigating, setNavigating] = (0, import_signal15.createSignal)(false);
1467
+ const [loads, setLoads] = (0, import_signal15.createSignal)(0);
1468
+ let navigationId = 0;
1469
+ const scroll = history2.window ? keepScroll(router.state().location) : void 0;
1470
+ let arriving = scroll ? { id: 0, location: router.state().location, from: void 0 } : null;
1471
+ const [arrived, setArrived] = (0, import_signal15.createSignal)(0);
1472
+ const takeMode = () => {
1473
+ const mode = pendingTransitionMode ?? (props.transition ?? "auto");
1474
+ pendingTransitionMode = void 0;
1475
+ return mode;
1476
+ };
1477
+ const unsub = router.subscribe((next) => {
1478
+ const id = ++navigationId;
1479
+ const mode = takeMode();
1480
+ setNavigating(true);
1481
+ if (scroll) {
1482
+ scroll.leave();
1483
+ arriving = { id, location: next.location, from: (0, import_signal15.untrack)(state).location };
1484
+ }
1485
+ const prepared = prepareComponents(
1486
+ (next.match?.matched ?? []).map((m) => m.component).filter(Boolean)
1487
+ );
1488
+ const commit = () => {
1489
+ setState(next);
1490
+ const flushed = (0, import_signal15.flush)();
1491
+ if (id === navigationId) setNavigating(false);
1492
+ if (scroll) setArrived(id);
1493
+ return flushed;
1494
+ };
1495
+ if (!prepared) {
1496
+ void runTransition(mode, commit);
1497
+ return;
1498
+ }
1499
+ void prepared.then(() => {
1500
+ if (id !== navigationId) return;
1501
+ return runTransition(mode, commit);
1502
+ });
1503
+ });
1504
+ (0, import_signal15.onCleanup)(() => {
1505
+ unsub();
1506
+ scroll?.dispose();
1507
+ router.destroy();
1508
+ navigationId++;
1509
+ });
1510
+ const matched = (0, import_signal15.createMemo)(
1511
+ () => (state().match?.matched ?? []).filter((m) => m.component)
1512
+ );
1513
+ const ctx = {
1514
+ router,
1515
+ location: (0, import_signal15.createMemo)(() => state().location),
1516
+ params: (0, import_signal15.createMemo)(() => state().match?.params ?? {}),
1517
+ isRouting: () => navigating() || loads() > 0,
1518
+ // Counted by the promise, not by an owner: a load a newer navigation superseded still
1519
+ // settles and uncounts itself, and a resource seeded from the server never calls it.
1520
+ trackLoad(result) {
1521
+ if (result && typeof result.finally === "function") {
1522
+ setLoads((n) => n + 1);
1523
+ void result.finally(() => setLoads((n) => n - 1)).catch(() => {
1524
+ });
1525
+ }
1526
+ return result;
1527
+ }
1528
+ };
1529
+ if (scroll) {
1530
+ const nextFrame = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (fn) => setTimeout(fn, 0);
1531
+ (0, import_signal15.createEffect)(() => {
1532
+ const id = arrived();
1533
+ if (ctx.isRouting()) return;
1534
+ const next = arriving;
1535
+ if (!next || next.id !== id || id !== navigationId) return;
1536
+ arriving = null;
1537
+ nextFrame(() => {
1538
+ if (id === navigationId) scroll.arrive(next.location, next.from);
1539
+ });
1540
+ });
1541
+ }
1542
+ const root = {
1543
+ depth: -1,
1544
+ matched,
1545
+ params: ctx.params,
1546
+ location: ctx.location,
1547
+ // Only the root carries this: renderChild shows it when the URL matched nothing.
1548
+ notFound: () => renderNotFound(props.notFound)
1549
+ };
1550
+ let rootView;
1551
+ return RouterContext.Provider({
1552
+ value: ctx,
1553
+ get children() {
1554
+ return rootView ??= renderChild(root);
1555
+ }
1556
+ });
1557
+ }
1558
+ var _ssrRouterStub = {
1559
+ router: { navigate: () => {
1560
+ } },
1561
+ location: () => ({ pathname: "", search: "", hash: "", query: {} }),
1562
+ params: () => ({}),
1563
+ isRouting: () => false,
1564
+ trackLoad: (result) => result
1565
+ };
1566
+ function useRouter() {
1567
+ const ctx = (0, import_signal16.useContext)(RouterContext);
1568
+ if (ctx) return ctx;
1569
+ if (typeof window === "undefined") return _ssrRouterStub;
1570
+ throw new Error("[router] useRouter must be used within <Router>");
1571
+ }
1572
+ function useParams() {
1573
+ const params = useRouter().params;
1574
+ return (0, import_signal15.createMemo)(() => params(), {}, {
1575
+ equals: (a, b) => JSON.stringify(a) === JSON.stringify(b)
1576
+ });
1577
+ }
1578
+ function useLocation() {
1579
+ const { location } = useRouter();
1580
+ return new Proxy({}, {
1581
+ get: (_t, key) => location()[key],
1582
+ has: (_t, key) => key in location(),
1583
+ ownKeys: () => Reflect.ownKeys(location()),
1584
+ getOwnPropertyDescriptor: (_t, key) => Object.getOwnPropertyDescriptor(location(), key)
1585
+ });
1586
+ }
1587
+ function useNavigate() {
1588
+ const { router } = useRouter();
1589
+ return (to, options) => {
1590
+ pendingTransitionMode = options?.transition;
1591
+ router.navigate(to, options);
1592
+ };
1593
+ }
1594
+ var read = (v) => typeof v === "function" ? v() : v;
1595
+ var LINK_OWN_PROPS = /* @__PURE__ */ new Set([
1596
+ "href",
1597
+ "slot",
1598
+ "class",
1599
+ "className",
1600
+ "active",
1601
+ "activeClass",
1602
+ "replace",
1603
+ "children"
1604
+ ]);
1605
+ function Link(props) {
1606
+ const ctx = (0, import_signal16.useContext)(RouterContext);
1607
+ const navigate = () => ctx.router.navigate(read(props.href) ?? "", { replace: read(props.replace) });
1608
+ const a = (0, import_dom15.createNativeElement)("a");
1609
+ (0, import_dom15.setAttribute)(a, "href", read(props.href) ?? "");
1610
+ if (props.slot) (0, import_dom15.setAttribute)(a, "slot", read(props.slot));
1611
+ for (const k of Object.keys(props)) {
1612
+ if (LINK_OWN_PROPS.has(k)) continue;
1613
+ const v = props[k];
1614
+ if (typeof v === "function") {
1615
+ if (/^on[A-Z]/.test(k)) continue;
1616
+ const read3 = v;
1617
+ const apply = () => {
1618
+ const value = read3();
1619
+ if (value == null || value === false) a.removeAttribute?.(k);
1620
+ else (0, import_dom15.setAttribute)(a, k, String(value));
1621
+ };
1622
+ if (typeof a.addEventListener === "function") (0, import_signal15.createEffect)(apply);
1623
+ else apply();
1624
+ continue;
1625
+ }
1626
+ if (v != null) (0, import_dom15.setAttribute)(a, k, String(v));
1627
+ }
1628
+ if (typeof a.addEventListener === "function") {
1629
+ a.addEventListener("click", (e) => {
1630
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
1631
+ if (!ctx) return;
1632
+ e.preventDefault();
1633
+ navigate();
1634
+ });
1635
+ } else {
1636
+ const base = read(props.className ?? props.class) ?? "";
1637
+ if (base) (0, import_dom15.setAttribute)(a, "class", base);
1638
+ }
1639
+ if (typeof a.addEventListener === "function") {
1640
+ (0, import_signal15.createEffect)(() => {
1641
+ const href = read(props.href) ?? "";
1642
+ a.setAttribute("href", href);
1643
+ const base = read(props.className ?? props.class) ?? "";
1644
+ const activeClass = read(props.activeClass) ?? "";
1645
+ const active = read(props.active) ?? ctx?.location().pathname === href;
1646
+ a.className = [base, active ? activeClass : ""].filter(Boolean).join(" ");
1647
+ });
1648
+ }
1649
+ const linkChildren = props.children;
1650
+ if (linkChildren != null) (0, import_dom15.insert)(a, linkChildren);
1651
+ return a;
1652
+ }
1653
+
1654
+ // src/lib/core.ts
1655
+ var import_dom17 = require("@fluixi/dom");
1656
+ var import_dom18 = require("@fluixi/dom");
1657
+ var import_dom19 = require("@fluixi/dom");
1658
+
1659
+ // src/lib/control-flow.ts
1660
+ var import_dom16 = require("@fluixi/dom");
1661
+
1662
+ // src/lib/core.ts
1663
+ var import_store = require("@fluixi/reactive/store");
1664
+ var VERSION2 = "0.0.1";
1665
+ var FRAMEWORK_NAME = "Fluixi";
1666
+ var core_default = {
1667
+ // Core
1668
+ createComponent,
1669
+ // render,
1670
+ onMount,
1671
+ onUnmount,
1672
+ createEffect: import_signal18.createEffect,
1673
+ createMemo: import_signal18.createMemo,
1674
+ createSignal: import_signal18.createSignal,
1675
+ createContext: createContext3,
1676
+ createRoot: import_signal18.createRoot,
1677
+ createDeferred: import_signal18.createDeferred,
1678
+ createComputed: import_signal18.createComputed,
1679
+ createRenderEffect: import_signal18.createRenderEffect,
1680
+ createSelector: import_signal19.createSelector,
1681
+ onCleanup: import_signal18.onCleanup,
1682
+ getOwner: import_signal18.getOwner,
1683
+ runWithOwner: import_signal18.runWithOwner,
1684
+ batch: import_signal18.batch,
1685
+ untrack: import_signal18.untrack,
1686
+ useContext: useContext3,
1687
+ setOwner: import_signal18.setOwner,
1688
+ // Control Flow
1689
+ // Show,
1690
+ // For,
1691
+ // Switch,
1692
+ // Match,
1693
+ // Portal,
1694
+ // Dynamic,
1695
+ // Context
1696
+ // Provider,
1697
+ // Resources
1698
+ // createResource,
1699
+ // Router
1700
+ // createRouter,
1701
+ Router,
1702
+ Link,
1703
+ useRouter,
1704
+ useNavigate,
1705
+ read: import_operators.readSignal,
1706
+ reduce: import_operators.reduceSignal,
1707
+ // Meta
1708
+ VERSION: VERSION2,
1709
+ FRAMEWORK_NAME
1710
+ };