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