@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.84

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 (177) hide show
  1. package/dist/cdn/core.global.js +2 -1
  2. package/dist/cli/generate.cjs +4117 -292
  3. package/dist/cli/generate.mjs +4122 -292
  4. package/dist/cli/index.cjs +4117 -292
  5. package/dist/cli/index.mjs +4122 -292
  6. package/dist/cli/run.cjs +63 -1
  7. package/dist/cli/run.mjs +39 -1
  8. package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
  9. package/dist/src/cdn/core.cjs +1279 -1
  10. package/dist/src/cdn/core.d.ts +3 -3
  11. package/dist/src/cdn/core.js +3 -3
  12. package/dist/src/cdn/core.mjs +642 -1
  13. package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
  14. package/dist/src/index.cjs +1201 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +1 -11
  17. package/dist/src/index.mjs +1313 -1
  18. package/dist/src/jsx-dev-runtime.cjs +26 -1
  19. package/dist/src/jsx-dev-runtime.mjs +24 -1
  20. package/dist/src/jsx-runtime.cjs +26 -1
  21. package/dist/src/jsx-runtime.js +0 -9
  22. package/dist/src/jsx-runtime.mjs +24 -1
  23. package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
  24. package/dist/src/lib/client/index.cjs +870 -1
  25. package/dist/src/lib/client/index.d.ts +17 -6
  26. package/dist/src/lib/client/index.d.ts.map +1 -1
  27. package/dist/src/lib/client/index.js +26 -19
  28. package/dist/src/lib/client/index.mjs +222 -1
  29. package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
  30. package/dist/src/lib/context/context.cjs +118 -1
  31. package/dist/src/lib/context/context.d.ts +19 -37
  32. package/dist/src/lib/context/context.d.ts.map +1 -1
  33. package/dist/src/lib/context/context.js +8 -45
  34. package/dist/src/lib/context/context.mjs +99 -1
  35. package/dist/src/lib/context/index.cjs +120 -1
  36. package/dist/src/lib/context/index.mjs +99 -1
  37. package/dist/src/lib/control-flow.cjs +35 -1
  38. package/dist/src/lib/control-flow.mjs +25 -1
  39. package/dist/src/lib/core.cjs +1200 -1
  40. package/dist/src/lib/core.d.ts +0 -2
  41. package/dist/src/lib/core.d.ts.map +1 -1
  42. package/dist/src/lib/core.js +14 -48
  43. package/dist/src/lib/core.mjs +1313 -1
  44. package/dist/src/lib/env/index.cjs +60 -1
  45. package/dist/src/lib/env/index.d.ts +5 -5
  46. package/dist/src/lib/env/index.js +5 -5
  47. package/dist/src/lib/env/index.mjs +39 -1
  48. package/dist/src/lib/i18n/index.cjs +108 -1
  49. package/dist/src/lib/i18n/index.d.ts +31 -10
  50. package/dist/src/lib/i18n/index.d.ts.map +1 -1
  51. package/dist/src/lib/i18n/index.js +31 -10
  52. package/dist/src/lib/i18n/index.mjs +88 -1
  53. package/dist/src/lib/index.cjs +633 -1
  54. package/dist/src/lib/index.d.ts +0 -2
  55. package/dist/src/lib/index.d.ts.map +1 -1
  56. package/dist/src/lib/index.js +5 -11
  57. package/dist/src/lib/index.mjs +721 -1
  58. package/dist/src/lib/isomorphic.cjs +85 -1
  59. package/dist/src/lib/isomorphic.d.ts +41 -8
  60. package/dist/src/lib/isomorphic.d.ts.map +1 -1
  61. package/dist/src/lib/isomorphic.js +38 -5
  62. package/dist/src/lib/isomorphic.mjs +64 -1
  63. package/dist/src/lib/jsx-runtime/index.cjs +21 -1
  64. package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
  65. package/dist/src/lib/jsx-runtime/index.js +1 -11
  66. package/dist/src/lib/jsx-runtime/index.mjs +4 -1
  67. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
  68. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
  69. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
  70. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
  71. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
  72. package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
  73. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
  74. package/dist/src/lib/plugins/index.cjs +311 -8
  75. package/dist/src/lib/plugins/index.mjs +279 -8
  76. package/dist/src/lib/plugins/route-codegen.cjs +73 -8
  77. package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
  78. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
  79. package/dist/src/lib/plugins/route-codegen.js +4 -5
  80. package/dist/src/lib/plugins/route-codegen.mjs +52 -8
  81. package/dist/src/lib/plugins/route-scanner.cjs +189 -1
  82. package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
  83. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
  84. package/dist/src/lib/plugins/route-scanner.js +7 -8
  85. package/dist/src/lib/plugins/route-scanner.mjs +158 -1
  86. package/dist/src/lib/plugins/vite.cjs +27 -1
  87. package/dist/src/lib/plugins/vite.mjs +6 -1
  88. package/dist/src/lib/render/await.cjs +38 -1
  89. package/dist/src/lib/render/await.d.ts +18 -0
  90. package/dist/src/lib/render/await.d.ts.map +1 -1
  91. package/dist/src/lib/render/await.js +20 -2
  92. package/dist/src/lib/render/await.mjs +17 -1
  93. package/dist/src/lib/render/component.cjs +221 -1
  94. package/dist/src/lib/render/component.d.ts +3 -44
  95. package/dist/src/lib/render/component.d.ts.map +1 -1
  96. package/dist/src/lib/render/component.js +23 -55
  97. package/dist/src/lib/render/component.mjs +214 -1
  98. package/dist/src/lib/render/deferred.cjs +175 -1
  99. package/dist/src/lib/render/deferred.js +5 -5
  100. package/dist/src/lib/render/deferred.mjs +158 -1
  101. package/dist/src/lib/render/index.cjs +573 -1
  102. package/dist/src/lib/render/index.d.ts +3 -17
  103. package/dist/src/lib/render/index.d.ts.map +1 -1
  104. package/dist/src/lib/render/index.js +8 -22
  105. package/dist/src/lib/render/index.mjs +590 -1
  106. package/dist/src/lib/render/lazy.cjs +67 -1
  107. package/dist/src/lib/render/lazy.d.ts +22 -1
  108. package/dist/src/lib/render/lazy.d.ts.map +1 -1
  109. package/dist/src/lib/render/lazy.js +26 -5
  110. package/dist/src/lib/render/lazy.mjs +50 -1
  111. package/dist/src/lib/render/suspense.cjs +141 -1
  112. package/dist/src/lib/render/suspense.d.ts +40 -0
  113. package/dist/src/lib/render/suspense.d.ts.map +1 -1
  114. package/dist/src/lib/render/suspense.js +46 -6
  115. package/dist/src/lib/render/suspense.mjs +136 -1
  116. package/dist/src/lib/render/versions.cjs +35 -1
  117. package/dist/src/lib/render/versions.js +6 -6
  118. package/dist/src/lib/render/versions.mjs +14 -1
  119. package/dist/src/lib/router/data.cjs +230 -1
  120. package/dist/src/lib/router/data.d.ts +1 -13
  121. package/dist/src/lib/router/data.d.ts.map +1 -1
  122. package/dist/src/lib/router/data.js +0 -12
  123. package/dist/src/lib/router/data.mjs +214 -1
  124. package/dist/src/lib/router/index.cjs +627 -1
  125. package/dist/src/lib/router/index.d.ts +62 -10
  126. package/dist/src/lib/router/index.d.ts.map +1 -1
  127. package/dist/src/lib/router/index.js +85 -33
  128. package/dist/src/lib/router/index.mjs +639 -1
  129. package/dist/src/lib/server/hydration.cjs +169 -1
  130. package/dist/src/lib/server/hydration.d.ts +15 -55
  131. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  132. package/dist/src/lib/server/hydration.js +23 -62
  133. package/dist/src/lib/server/hydration.mjs +148 -1
  134. package/dist/src/lib/server/index.cjs +401 -11
  135. package/dist/src/lib/server/index.d.ts +30 -6
  136. package/dist/src/lib/server/index.d.ts.map +1 -1
  137. package/dist/src/lib/server/index.js +34 -11
  138. package/dist/src/lib/server/index.mjs +379 -11
  139. package/dist/src/lib/server/reactive.cjs +197 -1
  140. package/dist/src/lib/server/reactive.d.ts +18 -77
  141. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  142. package/dist/src/lib/server/reactive.js +19 -78
  143. package/dist/src/lib/server/reactive.mjs +176 -1
  144. package/dist/src/lib/theme/index.cjs +110 -1
  145. package/dist/src/lib/theme/index.d.ts +19 -4
  146. package/dist/src/lib/theme/index.d.ts.map +1 -1
  147. package/dist/src/lib/theme/index.js +17 -2
  148. package/dist/src/lib/theme/index.mjs +89 -1
  149. package/dist/src/lib/utils/index.cjs +209 -1
  150. package/dist/src/lib/utils/index.d.ts +0 -93
  151. package/dist/src/lib/utils/index.d.ts.map +1 -1
  152. package/dist/src/lib/utils/index.js +0 -93
  153. package/dist/src/lib/utils/index.mjs +188 -1
  154. package/dist/src/routes.cjs +37 -1
  155. package/dist/src/routes.d.ts +1 -1
  156. package/dist/src/routes.js +2 -2
  157. package/dist/src/routes.mjs +17 -1
  158. package/dist/src/server.cjs +400 -11
  159. package/dist/src/server.d.ts +0 -1
  160. package/dist/src/server.d.ts.map +1 -1
  161. package/dist/src/server.js +0 -1
  162. package/dist/src/server.mjs +377 -11
  163. package/dist/src/utils.cjs +21 -1
  164. package/dist/src/utils.d.ts +1 -1
  165. package/dist/src/utils.js +1 -1
  166. package/dist/src/utils.mjs +4 -1
  167. package/dist/src/version.generated.cjs +26 -1
  168. package/dist/src/version.generated.d.ts +1 -1
  169. package/dist/src/version.generated.js +2 -2
  170. package/dist/src/version.generated.mjs +5 -1
  171. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  172. package/package.json +17 -16
  173. package/src/index.ts +2 -14
  174. package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
  175. package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
  176. package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
  177. package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
@@ -0,0 +1,747 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+
15
+ // src/lib/router/index.ts
16
+ import {
17
+ createSignal as createSignal2,
18
+ createMemo as createMemo2,
19
+ createResource as createResource3,
20
+ createEffect,
21
+ getOwner,
22
+ onCleanup,
23
+ untrack as untrack2
24
+ } from "@fluixi/reactive/signal";
25
+ import {
26
+ insert,
27
+ createComponent as createComponent2,
28
+ createNativeElement,
29
+ setAttribute
30
+ } from "@fluixi/dom";
31
+ import { createContext as createContext2, useContext as useContext2 } from "@fluixi/reactive/signal";
32
+ import { get } from "@fluixi/utils/object";
33
+ import { deepEqual } from "@fluixi/utils/compare";
34
+ import {
35
+ createRouter as createCoreRouter,
36
+ createBrowserHistory,
37
+ matchRoutes,
38
+ matchPath
39
+ } from "@fluixi/router";
40
+ import {
41
+ createMemoryHistory,
42
+ createBrowserHistory as createBrowserHistory2,
43
+ matchRoutes as matchRoutes2,
44
+ matchPath as matchPath2
45
+ } from "@fluixi/router";
46
+
47
+ // src/lib/router/data.ts
48
+ import {
49
+ createResource,
50
+ createSignal
51
+ } from "@fluixi/reactive/signal";
52
+
53
+ // src/lib/server/hydration.ts
54
+ import { isServer as domIsServer } from "@fluixi/dom";
55
+ var hydrating = false;
56
+ var hydrationDataMap = /* @__PURE__ */ new Map();
57
+ function isHydrating() {
58
+ return hydrating;
59
+ }
60
+ function setHydrating(state) {
61
+ hydrating = state;
62
+ }
63
+ function setHydrationData(key, data) {
64
+ hydrationDataMap.set(key, data);
65
+ }
66
+ function getHydrationData(key) {
67
+ return hydrationDataMap.get(key);
68
+ }
69
+ function clearHydrationData() {
70
+ hydrationDataMap.clear();
71
+ }
72
+ function deserializeHydrationData() {
73
+ if (typeof window === "undefined") {
74
+ return false;
75
+ }
76
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
77
+ if (!script || script.getAttribute("type") !== "application/json") {
78
+ return false;
79
+ }
80
+ try {
81
+ const json = script.textContent || "{}";
82
+ const data = JSON.parse(json);
83
+ for (const [key, value] of Object.entries(data)) {
84
+ hydrationDataMap.set(key, value);
85
+ }
86
+ return true;
87
+ } catch (error) {
88
+ console.error("Failed to deserialize hydration data:", error);
89
+ return false;
90
+ }
91
+ }
92
+ function cleanupHydration() {
93
+ if (typeof window === "undefined") {
94
+ return;
95
+ }
96
+ const script = document.getElementById("__FLUIXI_HYDRATION__");
97
+ if (script) {
98
+ script.remove();
99
+ }
100
+ const walker = document.createTreeWalker(
101
+ document.body,
102
+ NodeFilter.SHOW_COMMENT,
103
+ null
104
+ );
105
+ const comments = [];
106
+ let node;
107
+ while (node = walker.nextNode()) {
108
+ const comment = node;
109
+ const text = comment.nodeValue || "";
110
+ if (text.startsWith("#") || text.startsWith("/")) {
111
+ comments.push(comment);
112
+ }
113
+ }
114
+ comments.forEach((comment) => comment.remove());
115
+ clearHydrationData();
116
+ }
117
+ if (typeof window !== "undefined") {
118
+ window.addEventListener("load", () => {
119
+ setTimeout(cleanupHydration, 100);
120
+ });
121
+ }
122
+ function isServerEnvironment() {
123
+ return domIsServer();
124
+ }
125
+
126
+ // src/lib/context/context.ts
127
+ import { asProvider } from "@fluixi/dom";
128
+ import { createContext as createReactiveContext, useContext as useReactiveContext } from "@fluixi/reactive/signal";
129
+ import {
130
+ readChildren
131
+ } from "@fluixi/reactive/signal";
132
+ var _warnedEagerProvider = false;
133
+ function warnEagerProvider() {
134
+ if (_warnedEagerProvider) return;
135
+ _warnedEagerProvider = true;
136
+ if (typeof process !== "undefined" && true) return;
137
+ console.warn(
138
+ "[fluixi] createProvider({ context, value, children }) reads `children` eagerly: the object literal materialises `children` BEFORE the context is stamped, so a routed <Outlet/> that has siblings inside the provider renders detached and its descendants see no context under SSR. Use the lazy form instead:\n createProvider(Context, value, props) // children stays a getter\n // or JSX: <Context.Provider value={...}>{props.children}</Context.Provider>"
139
+ );
140
+ }
141
+ function createProvider(a, value, childProps) {
142
+ const isLazyForm = !!a?.Provider;
143
+ const context = isLazyForm ? a : a.context;
144
+ const rawValue = isLazyForm ? value : a.value;
145
+ const debug = isLazyForm ? false : a.debug ?? false;
146
+ if (!isLazyForm) warnEagerProvider();
147
+ const resolvedValue = typeof rawValue === "function" ? rawValue() : rawValue;
148
+ const sourceProps = isLazyForm ? childProps : a;
149
+ return context.Provider({
150
+ value: resolvedValue,
151
+ get children() {
152
+ return sourceProps?.children;
153
+ },
154
+ debug
155
+ });
156
+ }
157
+ function createContextWithProvider(defaultValue) {
158
+ const context = createContext(defaultValue);
159
+ const provider = (props) => {
160
+ return createProvider(context, props.value, props);
161
+ };
162
+ return [context, provider];
163
+ }
164
+ function composeProviders(contexts, children) {
165
+ if (contexts.length === 0) {
166
+ return readChildren(() => children);
167
+ }
168
+ const [context, value] = contexts[0];
169
+ const remaining = contexts.slice(1);
170
+ return createProvider(context, value, {
171
+ get children() {
172
+ return composeProviders(remaining, children);
173
+ }
174
+ });
175
+ }
176
+ function createConsumer(context) {
177
+ return (props) => {
178
+ const value = useContext(context);
179
+ return props.children(value);
180
+ };
181
+ }
182
+ function useProvide(context, factory) {
183
+ const existing = useContext(context);
184
+ if (existing === context.defaultValue) {
185
+ return factory();
186
+ }
187
+ return existing;
188
+ }
189
+ function createContext(defaultValue, name) {
190
+ const context = createReactiveContext(defaultValue, name);
191
+ const Provider = (props) => {
192
+ if (props.debug === true) {
193
+ }
194
+ return context.Provider({
195
+ value: props.value,
196
+ get children() {
197
+ return props.children;
198
+ },
199
+ debug: props.debug
200
+ });
201
+ };
202
+ if (typeof Symbol !== "undefined" && Symbol.for) {
203
+ Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
204
+ }
205
+ Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
206
+ return {
207
+ id: context.id,
208
+ Provider: asProvider(Provider),
209
+ defaultValue
210
+ };
211
+ }
212
+ function useContext(context) {
213
+ const value = useReactiveContext(context);
214
+ return value !== void 0 ? value : context.defaultValue;
215
+ }
216
+
217
+ // src/lib/router/data.ts
218
+ var globalCache = /* @__PURE__ */ new Map();
219
+ var inflightRequests = /* @__PURE__ */ new Map();
220
+ function cache(fn, name) {
221
+ return async (...args) => {
222
+ const key = name + ":" + JSON.stringify(args);
223
+ if (isHydrating() || typeof window !== "undefined") {
224
+ const hydrated = getHydrationData(key);
225
+ if (hydrated !== void 0) {
226
+ return hydrated;
227
+ }
228
+ }
229
+ if (globalCache.has(key)) {
230
+ return globalCache.get(key);
231
+ }
232
+ if (inflightRequests.has(key)) {
233
+ return inflightRequests.get(key);
234
+ }
235
+ const promise = Promise.resolve(fn(...args)).then(
236
+ (val) => {
237
+ globalCache.set(key, val);
238
+ inflightRequests.delete(key);
239
+ if (isServerEnvironment()) {
240
+ setHydrationData(key, val);
241
+ }
242
+ return val;
243
+ },
244
+ (err) => {
245
+ inflightRequests.delete(key);
246
+ throw err;
247
+ }
248
+ );
249
+ inflightRequests.set(key, promise);
250
+ return promise;
251
+ };
252
+ }
253
+ var [revalidationVersion, setRevalidationVersion] = createSignal(0);
254
+ var revalidationKeys = /* @__PURE__ */ new Set();
255
+ function revalidate(key) {
256
+ const predicate = typeof key === "string" ? (k) => k.startsWith(key) : key;
257
+ for (const k of globalCache.keys()) {
258
+ if (predicate(k)) {
259
+ globalCache.delete(k);
260
+ revalidationKeys.add(k);
261
+ }
262
+ }
263
+ setRevalidationVersion((v) => v + 1);
264
+ }
265
+ function createAsync(fetcher, source) {
266
+ const [data] = createResource(source || (() => true), fetcher);
267
+ return data;
268
+ }
269
+ var submissionState = /* @__PURE__ */ new Map();
270
+ function getSubmissionSignal(url) {
271
+ if (!submissionState.has(url)) {
272
+ submissionState.set(
273
+ url,
274
+ createSignal(void 0)
275
+ );
276
+ }
277
+ return submissionState.get(url);
278
+ }
279
+ function action(fn, name) {
280
+ const actionUrl = name || fn.name || "action";
281
+ const submit = async (input) => {
282
+ const [, setSubmission] = getSubmissionSignal(actionUrl);
283
+ const clear = () => setSubmission(void 0);
284
+ const retry = () => submit(input);
285
+ setSubmission({
286
+ input,
287
+ // Approximate type for tracking
288
+ pending: true,
289
+ clear,
290
+ retry
291
+ });
292
+ try {
293
+ const result = await fn(input);
294
+ setSubmission({
295
+ input,
296
+ result,
297
+ pending: false,
298
+ clear,
299
+ retry
300
+ });
301
+ return result;
302
+ } catch (error) {
303
+ setSubmission({
304
+ input,
305
+ error,
306
+ pending: false,
307
+ clear,
308
+ retry
309
+ });
310
+ throw error;
311
+ }
312
+ };
313
+ submit.url = actionUrl;
314
+ submit.with = (args) => action((...a) => fn(args, ...a), name);
315
+ return submit;
316
+ }
317
+ function useSubmission(actionFn) {
318
+ const [submission] = getSubmissionSignal(actionFn.url);
319
+ return submission;
320
+ }
321
+ function useAction(actionFn) {
322
+ return actionFn;
323
+ }
324
+ var RouteDataContext = createContext(void 0, "route-data");
325
+ var RouteDataProvider = RouteDataContext.Provider;
326
+
327
+ // src/lib/render/lazy.ts
328
+ import { createComponent } from "@fluixi/dom";
329
+ import {
330
+ untrack,
331
+ createMemo,
332
+ createResource as createResource2
333
+ } from "@fluixi/reactive/signal";
334
+ function fromChunk(value) {
335
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
336
+ try {
337
+ value["$lazy"] = true;
338
+ } catch {
339
+ }
340
+ }
341
+ return value;
342
+ }
343
+ function lazy(loader, options) {
344
+ let resolved;
345
+ let promise;
346
+ let component;
347
+ function load() {
348
+ if (!promise) {
349
+ promise = loader().then((mod) => resolved = mod.default);
350
+ }
351
+ return promise;
352
+ }
353
+ if (options?.preload) load();
354
+ const LazyWrapper = ((props) => {
355
+ if (resolved) {
356
+ const C = resolved;
357
+ return fromChunk(untrack(() => C(props)));
358
+ }
359
+ if (!component) {
360
+ const [resource] = createResource2(() => load(), { transport: false });
361
+ component = resource;
362
+ if (resource.error) throw resource.error;
363
+ }
364
+ return createMemo(() => {
365
+ const C = component();
366
+ return C ? fromChunk(createComponent(C, props)) : void 0;
367
+ });
368
+ });
369
+ LazyWrapper.preload = () => load().then(() => void 0);
370
+ LazyWrapper.$lazy = true;
371
+ LazyWrapper.loader = loader;
372
+ return LazyWrapper;
373
+ }
374
+
375
+ // src/lib/router/index.ts
376
+ import { runWithOwner } from "@fluixi/reactive/signal";
377
+ var RouterContext = createContext2(void 0, "router");
378
+ var OutletContext = createContext2(void 0, "outlet");
379
+ var LevelParamsContext = createContext2(void 0, "route-params");
380
+ var RouteDataContext2 = createContext2(void 0, "route-data");
381
+ function renderLayer(m, depth, base) {
382
+ let data;
383
+ const loader = m.route.data;
384
+ if (typeof loader === "function") {
385
+ let cancelled = false;
386
+ onCleanup(() => {
387
+ cancelled = true;
388
+ });
389
+ const owner = getOwner();
390
+ const [resource] = createResource3(
391
+ () => loader({ params: base.params, location: base.location }, owner, () => cancelled)
392
+ );
393
+ data = resource;
394
+ }
395
+ const buildPage = () => RouteDataContext2.Provider({
396
+ value: data,
397
+ get children() {
398
+ return LevelParamsContext.Provider({
399
+ value: m.params,
400
+ get children() {
401
+ return OutletContext.Provider({
402
+ value: { depth, ...base },
403
+ get children() {
404
+ return createComponent2(m.component, {});
405
+ }
406
+ });
407
+ }
408
+ });
409
+ }
410
+ });
411
+ if (!data) return buildPage();
412
+ const res = data;
413
+ const isLoading = () => res.loading;
414
+ const [ready, setReady] = createSignal2(untrack2(() => !isLoading()));
415
+ createEffect(() => setReady(!isLoading()));
416
+ return createMemo2(() => ready() ? buildPage() : null);
417
+ }
418
+ function renderChild(ctx) {
419
+ const childIdx = ctx.depth + 1;
420
+ const [childComp, setChildComp] = createSignal2(
421
+ untrack2(() => ctx.matched()[childIdx]?.component)
422
+ );
423
+ createEffect(() => {
424
+ const c = ctx.matched()[childIdx]?.component;
425
+ setChildComp(() => c);
426
+ });
427
+ return createMemo2(() => {
428
+ const component = childComp();
429
+ if (!component) {
430
+ return ctx.notFound ? ctx.notFound() : null;
431
+ }
432
+ const m = untrack2(() => ctx.matched())[childIdx];
433
+ return renderLayer(m, childIdx, {
434
+ matched: ctx.matched,
435
+ params: ctx.params,
436
+ location: ctx.location
437
+ });
438
+ });
439
+ }
440
+ function renderNotFound(notFound) {
441
+ if (notFound == null) return buildDefaultNotFound();
442
+ return typeof notFound === "function" ? createComponent2(notFound, {}) : notFound;
443
+ }
444
+ function buildDefaultNotFound() {
445
+ const el = createNativeElement("div");
446
+ setAttribute(el, "class", "fx-not-found");
447
+ setAttribute(el, "role", "main");
448
+ setAttribute(
449
+ el,
450
+ "style",
451
+ "min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif"
452
+ );
453
+ const h1 = createNativeElement("h1");
454
+ setAttribute(h1, "style", "margin:0;font-size:2.5rem;font-weight:700");
455
+ insert(h1, "404");
456
+ const p = createNativeElement("p");
457
+ setAttribute(p, "style", "margin:0;opacity:.7");
458
+ insert(p, "This page could not be found.");
459
+ el.appendChild(h1);
460
+ el.appendChild(p);
461
+ return el;
462
+ }
463
+ function Router(props) {
464
+ const history = props.history ?? createBrowserHistory();
465
+ const router = createCoreRouter({
466
+ routes: props.routes,
467
+ base: props.base,
468
+ history
469
+ });
470
+ const [state, setState] = createSignal2(router.state());
471
+ const unsub = router.subscribe(setState);
472
+ onCleanup(() => {
473
+ unsub();
474
+ router.destroy();
475
+ });
476
+ const matched = createMemo2(
477
+ () => (state().match?.matched ?? []).filter((m) => m.component)
478
+ );
479
+ const ctx = {
480
+ router,
481
+ location: createMemo2(() => state().location),
482
+ params: createMemo2(() => state().match?.params ?? {})
483
+ };
484
+ const root = {
485
+ depth: -1,
486
+ matched,
487
+ params: ctx.params,
488
+ location: ctx.location,
489
+ // Only the root carries this: renderChild shows it when the URL matched nothing.
490
+ notFound: () => renderNotFound(props.notFound)
491
+ };
492
+ let rootView;
493
+ return RouterContext.Provider({
494
+ value: ctx,
495
+ get children() {
496
+ return rootView ??= renderChild(root);
497
+ }
498
+ });
499
+ }
500
+ function Outlet() {
501
+ const ctx = useContext2(OutletContext);
502
+ if (!ctx) return null;
503
+ return renderChild(ctx);
504
+ }
505
+ function Redirect(props) {
506
+ const ctx = useContext2(RouterContext);
507
+ if (ctx && typeof window !== "undefined") {
508
+ let cancelled = false;
509
+ onCleanup(() => cancelled = true);
510
+ queueMicrotask(() => {
511
+ if (!cancelled) ctx.router.navigate(props.to, { replace: props.replace !== false });
512
+ });
513
+ }
514
+ return null;
515
+ }
516
+ var _ssrRouterStub = {
517
+ router: { navigate: () => {
518
+ } },
519
+ location: () => ({ pathname: "", search: "", hash: "", query: {} }),
520
+ params: () => ({})
521
+ };
522
+ function useRouter() {
523
+ const ctx = useContext2(RouterContext);
524
+ if (ctx) return ctx;
525
+ if (typeof window === "undefined") return _ssrRouterStub;
526
+ throw new Error("[router] useRouter must be used within <Router>");
527
+ }
528
+ function useParams() {
529
+ const params = useRouter().params;
530
+ return createMemo2(() => params(), {}, {
531
+ equals: (a, b) => JSON.stringify(a) === JSON.stringify(b)
532
+ });
533
+ }
534
+ function useLevelParams() {
535
+ return useContext2(LevelParamsContext) ?? {};
536
+ }
537
+ function useParam(key) {
538
+ const params = useParams();
539
+ return createMemo2(() => params()[key]);
540
+ }
541
+ function useParamSelector(selector, equals) {
542
+ const params = useParams();
543
+ return createMemo2(
544
+ () => selector(params()),
545
+ void 0,
546
+ equals ? { equals } : void 0
547
+ );
548
+ }
549
+ function useMatch(path) {
550
+ const location = useLocation();
551
+ return createMemo2(
552
+ () => matchPath(typeof path === "function" ? path() : path, location.pathname)
553
+ );
554
+ }
555
+ function useSearchParams() {
556
+ const location = useLocation();
557
+ const navigate = useNavigate();
558
+ const params = createMemo2(() => location.query);
559
+ const setParams = (next, options) => {
560
+ const current = new URLSearchParams(location.search);
561
+ for (const [k, v] of Object.entries(next)) {
562
+ if (v === null) current.delete(k);
563
+ else current.set(k, v);
564
+ }
565
+ const search = current.toString();
566
+ navigate(location.pathname + (search ? `?${search}` : ""), options);
567
+ };
568
+ return [params, setParams];
569
+ }
570
+ function select(source, key) {
571
+ const equals = (a, b) => deepEqual(a, b);
572
+ if (key !== void 0) {
573
+ return createMemo2(
574
+ () => get(source(), key),
575
+ void 0,
576
+ { equals }
577
+ );
578
+ }
579
+ return createMemo2(source, void 0, { equals });
580
+ }
581
+ function useLocation() {
582
+ const { location } = useRouter();
583
+ return new Proxy({}, {
584
+ get: (_t, key) => location()[key],
585
+ has: (_t, key) => key in location(),
586
+ ownKeys: () => Reflect.ownKeys(location()),
587
+ getOwnPropertyDescriptor: (_t, key) => Object.getOwnPropertyDescriptor(location(), key)
588
+ });
589
+ }
590
+ function useLinkNavigation(options = {}) {
591
+ const ctx = useContext2(RouterContext);
592
+ return (event) => {
593
+ if (!ctx || event.defaultPrevented || event.button !== 0) return;
594
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
595
+ const target = event.target;
596
+ const anchor = target?.closest?.("a");
597
+ if (!anchor || !anchor.getAttribute("href")) return;
598
+ if (anchor.target && anchor.target !== "_self") return;
599
+ if (anchor.hasAttribute("download")) return;
600
+ if (/(^|\s)external(\s|$)/.test(anchor.getAttribute("rel") ?? "")) return;
601
+ const url = new URL(anchor.href);
602
+ if (url.protocol !== "http:" && url.protocol !== "https:") return;
603
+ if (url.origin !== window.location.origin) return;
604
+ if (url.hash && url.pathname === window.location.pathname && url.search === window.location.search) return;
605
+ if (options.shouldNavigate && !options.shouldNavigate(url, anchor)) return;
606
+ event.preventDefault();
607
+ ctx.router.navigate(url.pathname + url.search + url.hash, { replace: options.replace });
608
+ };
609
+ }
610
+ function useNavigate() {
611
+ const { router } = useRouter();
612
+ return (to, options) => router.navigate(to, options);
613
+ }
614
+ function useRouteData() {
615
+ const acc = useContext2(RouteDataContext2);
616
+ return acc ?? (() => void 0);
617
+ }
618
+ var read = (v) => typeof v === "function" ? v() : v;
619
+ var LINK_OWN_PROPS = /* @__PURE__ */ new Set([
620
+ "href",
621
+ "slot",
622
+ "class",
623
+ "className",
624
+ "active",
625
+ "activeClass",
626
+ "replace",
627
+ "children"
628
+ ]);
629
+ function Link(props) {
630
+ const ctx = useContext2(RouterContext);
631
+ const navigate = () => ctx?.router.navigate(read(props.href) ?? "", { replace: read(props.replace) });
632
+ const a = createNativeElement("a");
633
+ setAttribute(a, "href", read(props.href) ?? "");
634
+ if (props.slot) setAttribute(a, "slot", read(props.slot));
635
+ for (const k of Object.keys(props)) {
636
+ if (LINK_OWN_PROPS.has(k)) continue;
637
+ const v = props[k];
638
+ if (v != null && typeof v !== "function") setAttribute(a, k, String(v));
639
+ }
640
+ if (typeof a.addEventListener === "function") {
641
+ a.addEventListener("click", (e) => {
642
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
643
+ e.preventDefault();
644
+ navigate();
645
+ });
646
+ } else {
647
+ const base = read(props.className ?? props.class) ?? "";
648
+ if (base) setAttribute(a, "class", base);
649
+ }
650
+ if (typeof a.addEventListener === "function") {
651
+ createEffect(() => {
652
+ const href = read(props.href) ?? "";
653
+ a.setAttribute("href", href);
654
+ const base = read(props.className ?? props.class) ?? "";
655
+ const activeClass = read(props.activeClass) ?? "";
656
+ const active = read(props.active) ?? ctx?.location().pathname === href;
657
+ a.className = [base, active ? activeClass : ""].filter(Boolean).join(" ");
658
+ });
659
+ }
660
+ const linkChildren = props.children;
661
+ if (linkChildren != null) insert(a, linkChildren);
662
+ return a;
663
+ }
664
+ var A = Link;
665
+ function Form(props) {
666
+ const action2 = props.action;
667
+ const cls = props.className ?? props.class;
668
+ const url = action2.url ?? "";
669
+ const form = createNativeElement("form");
670
+ setAttribute(form, "method", "post");
671
+ if (url) setAttribute(form, "action", url);
672
+ if (cls) setAttribute(form, "class", cls);
673
+ for (const k of Object.keys(props)) {
674
+ if (k === "action" || k === "children" || k === "class" || k === "className") continue;
675
+ const v = props[k];
676
+ if (v != null && typeof v !== "function") setAttribute(form, k, String(v));
677
+ }
678
+ if (typeof form.addEventListener === "function") {
679
+ form.addEventListener("submit", (e) => {
680
+ e.preventDefault();
681
+ const data = {};
682
+ new FormData(form).forEach((v, k) => {
683
+ data[k] = v;
684
+ });
685
+ Promise.resolve(action2(data)).catch(() => {
686
+ });
687
+ });
688
+ }
689
+ const children = props.children;
690
+ if (children != null) insert(form, children);
691
+ return form;
692
+ }
693
+ async function preloadRoutes(routes, pathname) {
694
+ const match = matchRoutes(routes, pathname);
695
+ if (!match) return;
696
+ const loads = [];
697
+ for (const m of match.matched) {
698
+ const c = m.component;
699
+ if (c && typeof c.preload === "function") loads.push(c.preload());
700
+ }
701
+ await Promise.all(loads);
702
+ }
703
+
704
+ export {
705
+ __reExport,
706
+ lazy,
707
+ createProvider,
708
+ createContextWithProvider,
709
+ composeProviders,
710
+ createConsumer,
711
+ useProvide,
712
+ createContext,
713
+ useContext,
714
+ setHydrating,
715
+ deserializeHydrationData,
716
+ cleanupHydration,
717
+ cache,
718
+ revalidate,
719
+ createAsync,
720
+ action,
721
+ useSubmission,
722
+ useAction,
723
+ Router,
724
+ Outlet,
725
+ Redirect,
726
+ useRouter,
727
+ useParams,
728
+ useLevelParams,
729
+ useParam,
730
+ useParamSelector,
731
+ useMatch,
732
+ useSearchParams,
733
+ select,
734
+ useLocation,
735
+ useLinkNavigation,
736
+ useNavigate,
737
+ useRouteData,
738
+ Link,
739
+ A,
740
+ Form,
741
+ preloadRoutes,
742
+ createMemoryHistory,
743
+ createBrowserHistory2 as createBrowserHistory,
744
+ matchRoutes2 as matchRoutes,
745
+ matchPath2 as matchPath,
746
+ runWithOwner
747
+ };