@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.
- package/LICENSE +21 -0
- package/README.md +334 -0
- package/dist/cdn/core.global.js +2 -0
- package/dist/cli/generate.cjs +5639 -0
- package/dist/cli/generate.d.ts +7 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/cli/generate.js +2580 -0
- package/dist/cli/generate.mjs +5644 -0
- package/dist/cli/index.cjs +5639 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2580 -0
- package/dist/cli/index.mjs +5644 -0
- package/dist/cli/run.cjs +64 -0
- package/dist/cli/run.d.ts +3 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +62 -0
- package/dist/cli/run.mjs +40 -0
- package/dist/fluixi.d.ts +5 -0
- package/dist/src/cdn/chunk-RKBFEFZP.mjs +987 -0
- package/dist/src/cdn/core.cjs +1592 -0
- package/dist/src/cdn/core.d.ts +16 -0
- package/dist/src/cdn/core.d.ts.map +1 -0
- package/dist/src/cdn/core.js +15 -0
- package/dist/src/cdn/core.mjs +714 -0
- package/dist/src/cdn/router-V2THK27H.mjs +74 -0
- package/dist/src/index.cjs +1711 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.mjs +1833 -0
- package/dist/src/jsx-dev-runtime.cjs +26 -0
- package/dist/src/jsx-dev-runtime.d.ts +2 -0
- package/dist/src/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/src/jsx-dev-runtime.js +1 -0
- package/dist/src/jsx-dev-runtime.mjs +24 -0
- package/dist/src/jsx-runtime.cjs +26 -0
- package/dist/src/jsx-runtime.d.ts +7 -0
- package/dist/src/jsx-runtime.d.ts.map +1 -0
- package/dist/src/jsx-runtime.js +8 -0
- package/dist/src/jsx-runtime.mjs +24 -0
- package/dist/src/lib/client/chunk-FDOPDB6Z.mjs +53 -0
- package/dist/src/lib/client/index.cjs +1210 -0
- package/dist/src/lib/client/index.d.ts +51 -0
- package/dist/src/lib/client/index.d.ts.map +1 -0
- package/dist/src/lib/client/index.js +174 -0
- package/dist/src/lib/client/index.mjs +293 -0
- package/dist/src/lib/client/router-4PTBPZLQ.mjs +891 -0
- package/dist/src/lib/context/context.cjs +81 -0
- package/dist/src/lib/context/context.d.ts +73 -0
- package/dist/src/lib/context/context.d.ts.map +1 -0
- package/dist/src/lib/context/context.js +93 -0
- package/dist/src/lib/context/context.mjs +64 -0
- package/dist/src/lib/context/index.cjs +83 -0
- package/dist/src/lib/context/index.d.ts +3 -0
- package/dist/src/lib/context/index.d.ts.map +1 -0
- package/dist/src/lib/context/index.js +1 -0
- package/dist/src/lib/context/index.mjs +64 -0
- package/dist/src/lib/control-flow.cjs +35 -0
- package/dist/src/lib/control-flow.d.ts +4 -0
- package/dist/src/lib/control-flow.d.ts.map +1 -0
- package/dist/src/lib/control-flow.js +1 -0
- package/dist/src/lib/control-flow.mjs +25 -0
- package/dist/src/lib/core.cjs +1710 -0
- package/dist/src/lib/core.d.ts +91 -0
- package/dist/src/lib/core.d.ts.map +1 -0
- package/dist/src/lib/core.js +158 -0
- package/dist/src/lib/core.mjs +1833 -0
- package/dist/src/lib/env/index.cjs +44 -0
- package/dist/src/lib/env/index.d.ts +26 -0
- package/dist/src/lib/env/index.d.ts.map +1 -0
- package/dist/src/lib/env/index.js +31 -0
- package/dist/src/lib/env/index.mjs +23 -0
- package/dist/src/lib/i18n/index.cjs +123 -0
- package/dist/src/lib/i18n/index.d.ts +110 -0
- package/dist/src/lib/i18n/index.d.ts.map +1 -0
- package/dist/src/lib/i18n/index.js +164 -0
- package/dist/src/lib/i18n/index.mjs +103 -0
- package/dist/src/lib/index.cjs +598 -0
- package/dist/src/lib/index.d.ts +81 -0
- package/dist/src/lib/index.d.ts.map +1 -0
- package/dist/src/lib/index.js +130 -0
- package/dist/src/lib/index.mjs +688 -0
- package/dist/src/lib/isomorphic.cjs +90 -0
- package/dist/src/lib/isomorphic.d.ts +114 -0
- package/dist/src/lib/isomorphic.d.ts.map +1 -0
- package/dist/src/lib/isomorphic.js +132 -0
- package/dist/src/lib/isomorphic.mjs +69 -0
- package/dist/src/lib/jsx-runtime/index.cjs +21 -0
- package/dist/src/lib/jsx-runtime/index.d.ts +13 -0
- package/dist/src/lib/jsx-runtime/index.d.ts.map +1 -0
- package/dist/src/lib/jsx-runtime/index.js +13 -0
- package/dist/src/lib/jsx-runtime/index.mjs +4 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts +2 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.js +1 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +35 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +118 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -0
- package/dist/src/lib/plugins/index.cjs +311 -0
- package/dist/src/lib/plugins/index.d.ts +6 -0
- package/dist/src/lib/plugins/index.d.ts.map +1 -0
- package/dist/src/lib/plugins/index.js +7 -0
- package/dist/src/lib/plugins/index.mjs +279 -0
- package/dist/src/lib/plugins/route-codegen.cjs +73 -0
- package/dist/src/lib/plugins/route-codegen.d.ts +12 -0
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -0
- package/dist/src/lib/plugins/route-codegen.js +80 -0
- package/dist/src/lib/plugins/route-codegen.mjs +52 -0
- package/dist/src/lib/plugins/route-scanner.cjs +189 -0
- package/dist/src/lib/plugins/route-scanner.d.ts +38 -0
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -0
- package/dist/src/lib/plugins/route-scanner.js +215 -0
- package/dist/src/lib/plugins/route-scanner.mjs +158 -0
- package/dist/src/lib/plugins/vite.cjs +27 -0
- package/dist/src/lib/plugins/vite.d.ts +3 -0
- package/dist/src/lib/plugins/vite.d.ts.map +1 -0
- package/dist/src/lib/plugins/vite.js +1 -0
- package/dist/src/lib/plugins/vite.mjs +6 -0
- package/dist/src/lib/render/await.cjs +38 -0
- package/dist/src/lib/render/await.d.ts +26 -0
- package/dist/src/lib/render/await.d.ts.map +1 -0
- package/dist/src/lib/render/await.js +45 -0
- package/dist/src/lib/render/await.mjs +17 -0
- package/dist/src/lib/render/component.cjs +221 -0
- package/dist/src/lib/render/component.d.ts +296 -0
- package/dist/src/lib/render/component.d.ts.map +1 -0
- package/dist/src/lib/render/component.js +514 -0
- package/dist/src/lib/render/component.mjs +214 -0
- package/dist/src/lib/render/deferred.cjs +175 -0
- package/dist/src/lib/render/deferred.d.ts +36 -0
- package/dist/src/lib/render/deferred.d.ts.map +1 -0
- package/dist/src/lib/render/deferred.js +141 -0
- package/dist/src/lib/render/deferred.mjs +158 -0
- package/dist/src/lib/render/index.cjs +573 -0
- package/dist/src/lib/render/index.d.ts +98 -0
- package/dist/src/lib/render/index.d.ts.map +1 -0
- package/dist/src/lib/render/index.js +180 -0
- package/dist/src/lib/render/index.mjs +590 -0
- package/dist/src/lib/render/lazy.cjs +67 -0
- package/dist/src/lib/render/lazy.d.ts +49 -0
- package/dist/src/lib/render/lazy.d.ts.map +1 -0
- package/dist/src/lib/render/lazy.js +105 -0
- package/dist/src/lib/render/lazy.mjs +50 -0
- package/dist/src/lib/render/suspense.cjs +141 -0
- package/dist/src/lib/render/suspense.d.ts +65 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -0
- package/dist/src/lib/render/suspense.js +196 -0
- package/dist/src/lib/render/suspense.mjs +136 -0
- package/dist/src/lib/render/versions.cjs +35 -0
- package/dist/src/lib/render/versions.d.ts +2 -0
- package/dist/src/lib/render/versions.d.ts.map +1 -0
- package/dist/src/lib/render/versions.js +21 -0
- package/dist/src/lib/render/versions.mjs +14 -0
- package/dist/src/lib/router/data.cjs +228 -0
- package/dist/src/lib/router/data.d.ts +142 -0
- package/dist/src/lib/router/data.d.ts.map +1 -0
- package/dist/src/lib/router/data.js +258 -0
- package/dist/src/lib/router/data.mjs +214 -0
- package/dist/src/lib/router/index.cjs +921 -0
- package/dist/src/lib/router/index.d.ts +274 -0
- package/dist/src/lib/router/index.d.ts.map +1 -0
- package/dist/src/lib/router/index.js +904 -0
- package/dist/src/lib/router/index.mjs +938 -0
- package/dist/src/lib/router/scroll.cjs +79 -0
- package/dist/src/lib/router/scroll.d.ts +19 -0
- package/dist/src/lib/router/scroll.d.ts.map +1 -0
- package/dist/src/lib/router/scroll.js +68 -0
- package/dist/src/lib/router/scroll.mjs +58 -0
- package/dist/src/lib/router/transition.cjs +75 -0
- package/dist/src/lib/router/transition.d.ts +81 -0
- package/dist/src/lib/router/transition.d.ts.map +1 -0
- package/dist/src/lib/router/transition.js +136 -0
- package/dist/src/lib/router/transition.mjs +54 -0
- package/dist/src/lib/server/hydration.cjs +169 -0
- package/dist/src/lib/server/hydration.d.ts +198 -0
- package/dist/src/lib/server/hydration.d.ts.map +1 -0
- package/dist/src/lib/server/hydration.js +345 -0
- package/dist/src/lib/server/hydration.mjs +148 -0
- package/dist/src/lib/server/index.cjs +406 -0
- package/dist/src/lib/server/index.d.ts +115 -0
- package/dist/src/lib/server/index.d.ts.map +1 -0
- package/dist/src/lib/server/index.js +164 -0
- package/dist/src/lib/server/index.mjs +384 -0
- package/dist/src/lib/server/reactive.cjs +197 -0
- package/dist/src/lib/server/reactive.d.ts +239 -0
- package/dist/src/lib/server/reactive.d.ts.map +1 -0
- package/dist/src/lib/server/reactive.js +413 -0
- package/dist/src/lib/server/reactive.mjs +176 -0
- package/dist/src/lib/storage/cache.cjs +51 -0
- package/dist/src/lib/storage/cache.d.ts +18 -0
- package/dist/src/lib/storage/cache.d.ts.map +1 -0
- package/dist/src/lib/storage/cache.js +42 -0
- package/dist/src/lib/storage/cache.mjs +30 -0
- package/dist/src/lib/storage/index.cjs +246 -0
- package/dist/src/lib/storage/index.d.ts +83 -0
- package/dist/src/lib/storage/index.d.ts.map +1 -0
- package/dist/src/lib/storage/index.js +179 -0
- package/dist/src/lib/storage/index.mjs +231 -0
- package/dist/src/lib/storage/persisted.cjs +91 -0
- package/dist/src/lib/storage/persisted.d.ts +53 -0
- package/dist/src/lib/storage/persisted.d.ts.map +1 -0
- package/dist/src/lib/storage/persisted.js +75 -0
- package/dist/src/lib/storage/persisted.mjs +70 -0
- package/dist/src/lib/theme/color-scheme.cjs +281 -0
- package/dist/src/lib/theme/color-scheme.d.ts +61 -0
- package/dist/src/lib/theme/color-scheme.d.ts.map +1 -0
- package/dist/src/lib/theme/color-scheme.js +120 -0
- package/dist/src/lib/theme/color-scheme.mjs +265 -0
- package/dist/src/lib/theme/index.cjs +267 -0
- package/dist/src/lib/theme/index.d.ts +78 -0
- package/dist/src/lib/theme/index.d.ts.map +1 -0
- package/dist/src/lib/theme/index.js +135 -0
- package/dist/src/lib/theme/index.mjs +251 -0
- package/dist/src/lib/theme/provider.cjs +346 -0
- package/dist/src/lib/theme/provider.d.ts +34 -0
- package/dist/src/lib/theme/provider.d.ts.map +1 -0
- package/dist/src/lib/theme/provider.js +60 -0
- package/dist/src/lib/theme/provider.mjs +332 -0
- package/dist/src/lib/utils/index.cjs +209 -0
- package/dist/src/lib/utils/index.d.ts +286 -0
- package/dist/src/lib/utils/index.d.ts.map +1 -0
- package/dist/src/lib/utils/index.js +434 -0
- package/dist/src/lib/utils/index.mjs +188 -0
- package/dist/src/routes.cjs +37 -0
- package/dist/src/routes.d.ts +22 -0
- package/dist/src/routes.d.ts.map +1 -0
- package/dist/src/routes.js +20 -0
- package/dist/src/routes.mjs +17 -0
- package/dist/src/server.cjs +405 -0
- package/dist/src/server.d.ts +63 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +62 -0
- package/dist/src/server.mjs +382 -0
- package/dist/src/utils.cjs +21 -0
- package/dist/src/utils.d.ts +10 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +9 -0
- package/dist/src/utils.mjs +4 -0
- package/dist/src/version.generated.cjs +26 -0
- package/dist/src/version.generated.d.ts +3 -0
- package/dist/src/version.generated.d.ts.map +1 -0
- package/dist/src/version.generated.js +3 -0
- package/dist/src/version.generated.mjs +5 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +164 -0
- package/src/index.ts +19 -0
- package/types/fluixi.d.ts +5 -0
- package/types/vinxi.d.ts +50 -0
|
@@ -0,0 +1,987 @@
|
|
|
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
|
+
createRoot,
|
|
22
|
+
getOwner as getOwner2,
|
|
23
|
+
onCleanup,
|
|
24
|
+
runWithOwner,
|
|
25
|
+
untrack as untrack2,
|
|
26
|
+
flush
|
|
27
|
+
} from "@fluixi/reactive/signal";
|
|
28
|
+
|
|
29
|
+
// src/lib/router/transition.ts
|
|
30
|
+
function supportsViewTransitions() {
|
|
31
|
+
return typeof document !== "undefined" && typeof document.startViewTransition === "function";
|
|
32
|
+
}
|
|
33
|
+
function prefersReducedMotion() {
|
|
34
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function shouldAnimate(mode) {
|
|
44
|
+
return mode !== "none" && supportsViewTransitions() && !prefersReducedMotion();
|
|
45
|
+
}
|
|
46
|
+
function prepareComponents(components) {
|
|
47
|
+
const pending = [];
|
|
48
|
+
for (const component of components) {
|
|
49
|
+
const preload = component?.preload;
|
|
50
|
+
if (typeof preload === "function") {
|
|
51
|
+
try {
|
|
52
|
+
const result = preload();
|
|
53
|
+
if (result && typeof result.then === "function") {
|
|
54
|
+
pending.push(result.catch(() => void 0));
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return pending.length ? Promise.all(pending).then(() => void 0) : null;
|
|
61
|
+
}
|
|
62
|
+
function runTransition(mode, commit) {
|
|
63
|
+
if (!shouldAnimate(mode)) {
|
|
64
|
+
return Promise.resolve(commit()).then(() => void 0);
|
|
65
|
+
}
|
|
66
|
+
const start = document.startViewTransition;
|
|
67
|
+
try {
|
|
68
|
+
const transition = start.call(document, () => commit());
|
|
69
|
+
transition.finished?.catch(() => void 0);
|
|
70
|
+
transition.ready?.catch(() => void 0);
|
|
71
|
+
return transition.updateCallbackDone.catch(() => void 0);
|
|
72
|
+
} catch {
|
|
73
|
+
return Promise.resolve(commit()).then(() => void 0);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/lib/router/index.ts
|
|
78
|
+
import {
|
|
79
|
+
insert,
|
|
80
|
+
createComponent as createComponent2,
|
|
81
|
+
createNativeElement,
|
|
82
|
+
setAttribute
|
|
83
|
+
} from "@fluixi/dom";
|
|
84
|
+
import { createContext as createContext2, useContext as useContext2 } from "@fluixi/reactive/signal";
|
|
85
|
+
import { get } from "@fluixi/utils/object";
|
|
86
|
+
import { deepEqual } from "@fluixi/utils/compare";
|
|
87
|
+
|
|
88
|
+
// src/lib/router/scroll.ts
|
|
89
|
+
var STORE = "fx:scroll";
|
|
90
|
+
var KEEP = 100;
|
|
91
|
+
function keepScroll(initial) {
|
|
92
|
+
const read2 = () => {
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(sessionStorage.getItem(STORE) ?? "{}");
|
|
95
|
+
} catch {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const positions = read2();
|
|
100
|
+
const write = () => {
|
|
101
|
+
const keys = Object.keys(positions);
|
|
102
|
+
for (const key of keys.slice(0, Math.max(0, keys.length - KEEP))) delete positions[key];
|
|
103
|
+
try {
|
|
104
|
+
sessionStorage.setItem(STORE, JSON.stringify(positions));
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
let current = initial.key;
|
|
109
|
+
const save = () => {
|
|
110
|
+
if (current === void 0) return;
|
|
111
|
+
delete positions[current];
|
|
112
|
+
positions[current] = window.scrollY;
|
|
113
|
+
write();
|
|
114
|
+
};
|
|
115
|
+
const restoration = history.scrollRestoration;
|
|
116
|
+
history.scrollRestoration = "manual";
|
|
117
|
+
window.addEventListener("pagehide", save);
|
|
118
|
+
const to = (top) => window.scrollTo({ top, left: 0, behavior: "instant" });
|
|
119
|
+
const toHash = (hash) => {
|
|
120
|
+
if (!hash || hash === "#") return false;
|
|
121
|
+
const target = document.getElementById(decodeURIComponent(hash.slice(1)));
|
|
122
|
+
target?.scrollIntoView({ behavior: "instant" });
|
|
123
|
+
return target !== null;
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
leave: save,
|
|
127
|
+
arrive(location, from) {
|
|
128
|
+
current = location.key;
|
|
129
|
+
if (location.action === "pop" || from === void 0) {
|
|
130
|
+
const y = location.key === void 0 ? void 0 : positions[location.key];
|
|
131
|
+
if (y !== void 0) to(y);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (location.action === "replace" && location.pathname === from.pathname) return;
|
|
135
|
+
if (!toHash(location.hash)) to(0);
|
|
136
|
+
},
|
|
137
|
+
dispose() {
|
|
138
|
+
window.removeEventListener("pagehide", save);
|
|
139
|
+
history.scrollRestoration = restoration;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/lib/router/index.ts
|
|
145
|
+
import {
|
|
146
|
+
createRouter as createCoreRouter,
|
|
147
|
+
createBrowserHistory,
|
|
148
|
+
matchRoutes,
|
|
149
|
+
matchPath
|
|
150
|
+
} from "@fluixi/router";
|
|
151
|
+
|
|
152
|
+
// src/lib/router/data.ts
|
|
153
|
+
import {
|
|
154
|
+
createResource,
|
|
155
|
+
createSignal
|
|
156
|
+
} from "@fluixi/reactive/signal";
|
|
157
|
+
import { currentResourceCache } from "@fluixi/reactive/signal";
|
|
158
|
+
|
|
159
|
+
// src/lib/context/context.ts
|
|
160
|
+
import { asProvider } from "@fluixi/dom";
|
|
161
|
+
import {
|
|
162
|
+
createContext as createReactiveContext,
|
|
163
|
+
getOwner,
|
|
164
|
+
useContext as useReactiveContext
|
|
165
|
+
} from "@fluixi/reactive/signal";
|
|
166
|
+
function createContext(defaultValue, name) {
|
|
167
|
+
const context = createReactiveContext(defaultValue, name);
|
|
168
|
+
const Provider = (props) => (
|
|
169
|
+
// Children stay a getter: the reactive Provider reads them after stamping the value on
|
|
170
|
+
// its owner. Reading `props.children` here would render them, and any <Outlet/> in them,
|
|
171
|
+
// before the context exists.
|
|
172
|
+
context.Provider({
|
|
173
|
+
value: props.value,
|
|
174
|
+
get children() {
|
|
175
|
+
return props.children;
|
|
176
|
+
},
|
|
177
|
+
debug: props.debug
|
|
178
|
+
})
|
|
179
|
+
);
|
|
180
|
+
return {
|
|
181
|
+
id: context.id,
|
|
182
|
+
Provider: asProvider(Provider),
|
|
183
|
+
defaultValue
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function useContext(context) {
|
|
187
|
+
const value = useReactiveContext(context);
|
|
188
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
189
|
+
}
|
|
190
|
+
function createProvider(context, value, props) {
|
|
191
|
+
const resolved = typeof value === "function" ? value() : value;
|
|
192
|
+
return context.Provider({
|
|
193
|
+
value: resolved,
|
|
194
|
+
get children() {
|
|
195
|
+
return props.children;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function composeProviders(providers, props) {
|
|
200
|
+
const outermost = providers.reduceRight(
|
|
201
|
+
(inner, [context, value]) => ({
|
|
202
|
+
get children() {
|
|
203
|
+
return createProvider(context, value, inner);
|
|
204
|
+
}
|
|
205
|
+
}),
|
|
206
|
+
props
|
|
207
|
+
);
|
|
208
|
+
return outermost.children;
|
|
209
|
+
}
|
|
210
|
+
function requireContext(context, message) {
|
|
211
|
+
for (let owner = getOwner(); owner; owner = owner.parent) {
|
|
212
|
+
if (owner.contexts?.has(context.id)) return useContext(context);
|
|
213
|
+
}
|
|
214
|
+
throw new Error(message ?? `[fluixi] No Provider for ${context.id.description ?? "this context"} above this component.`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/lib/router/data.ts
|
|
218
|
+
var revalidationListeners = /* @__PURE__ */ new Set();
|
|
219
|
+
function onRevalidate(listener) {
|
|
220
|
+
revalidationListeners.add(listener);
|
|
221
|
+
return () => void revalidationListeners.delete(listener);
|
|
222
|
+
}
|
|
223
|
+
var reloadMounted = () => {
|
|
224
|
+
for (const listener of [...revalidationListeners]) listener();
|
|
225
|
+
};
|
|
226
|
+
function cache(fn, name, options = {}) {
|
|
227
|
+
const { ttl = Infinity, staleWhileRevalidate = true } = options;
|
|
228
|
+
return (...args) => {
|
|
229
|
+
const store = options.cache ?? currentResourceCache();
|
|
230
|
+
const key = name + ":" + JSON.stringify(args);
|
|
231
|
+
const fetchFresh = () => {
|
|
232
|
+
const running = store.inflight.get(key);
|
|
233
|
+
if (running) return running;
|
|
234
|
+
const promise = Promise.resolve(fn(...args)).then(
|
|
235
|
+
(value) => {
|
|
236
|
+
store.set(key, { value, timestamp: Date.now() });
|
|
237
|
+
store.inflight.delete(key);
|
|
238
|
+
return value;
|
|
239
|
+
},
|
|
240
|
+
(error) => {
|
|
241
|
+
store.inflight.delete(key);
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
store.inflight.set(key, promise);
|
|
246
|
+
return promise;
|
|
247
|
+
};
|
|
248
|
+
const hit = store.get(key);
|
|
249
|
+
if (hit && (ttl === Infinity || Date.now() - hit.timestamp <= ttl)) return Promise.resolve(hit.value);
|
|
250
|
+
if (hit && staleWhileRevalidate) {
|
|
251
|
+
fetchFresh().then(reloadMounted, () => void 0);
|
|
252
|
+
return Promise.resolve(hit.value);
|
|
253
|
+
}
|
|
254
|
+
return fetchFresh();
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function revalidate(key, store) {
|
|
258
|
+
const names = typeof key === "string" ? [key] : Array.isArray(key) ? key : null;
|
|
259
|
+
drop(names ?? key, store ?? currentResourceCache());
|
|
260
|
+
if (names && !store) tellOtherTabs(names);
|
|
261
|
+
}
|
|
262
|
+
function drop(what, store) {
|
|
263
|
+
const matches = Array.isArray(what) ? (k) => what.some((n) => k === n || k.startsWith(n + ":")) : what;
|
|
264
|
+
for (const k of [...store.keys()]) if (matches(k)) store.delete(k);
|
|
265
|
+
reloadMounted();
|
|
266
|
+
}
|
|
267
|
+
var TABS_KEY = "fluixi:revalidate";
|
|
268
|
+
function tellOtherTabs(names) {
|
|
269
|
+
try {
|
|
270
|
+
localStorage.setItem(TABS_KEY, JSON.stringify({ names, at: Date.now() + Math.random() }));
|
|
271
|
+
} catch {
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (typeof window !== "undefined") {
|
|
275
|
+
window.addEventListener("storage", (event) => {
|
|
276
|
+
if (event.key !== TABS_KEY || !event.newValue) return;
|
|
277
|
+
try {
|
|
278
|
+
const names = JSON.parse(event.newValue).names;
|
|
279
|
+
if (Array.isArray(names) && names.every((n) => typeof n === "string")) drop(names, currentResourceCache());
|
|
280
|
+
} catch {
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
globalThis[/* @__PURE__ */ Symbol.for("fluixi.revalidate")] = (names) => revalidate(names);
|
|
285
|
+
function createAsync(fetcher, source) {
|
|
286
|
+
const [data] = createResource(source || (() => true), fetcher);
|
|
287
|
+
return data;
|
|
288
|
+
}
|
|
289
|
+
var submissionState = /* @__PURE__ */ new Map();
|
|
290
|
+
function getSubmissionSignal(url) {
|
|
291
|
+
if (!submissionState.has(url)) {
|
|
292
|
+
submissionState.set(
|
|
293
|
+
url,
|
|
294
|
+
createSignal(void 0)
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
return submissionState.get(url);
|
|
298
|
+
}
|
|
299
|
+
var submissionsState = /* @__PURE__ */ new Map();
|
|
300
|
+
function getSubmissionsSignal(url) {
|
|
301
|
+
if (!submissionsState.has(url)) submissionsState.set(url, createSignal([]));
|
|
302
|
+
return submissionsState.get(url);
|
|
303
|
+
}
|
|
304
|
+
function action(fn, name, options = {}) {
|
|
305
|
+
const actionUrl = name || fn.name || "action";
|
|
306
|
+
const submit = async (...args) => {
|
|
307
|
+
const input = args.length > 1 ? args : args[0];
|
|
308
|
+
const [, setSubmission] = getSubmissionSignal(actionUrl);
|
|
309
|
+
const [, setSubmissions] = getSubmissionsSignal(actionUrl);
|
|
310
|
+
let entry;
|
|
311
|
+
const drop2 = () => setSubmissions((list) => list.filter((s) => s !== entry));
|
|
312
|
+
const settle = (next) => {
|
|
313
|
+
setSubmissions((list) => list.map((s) => s === entry ? next : s));
|
|
314
|
+
entry = next;
|
|
315
|
+
};
|
|
316
|
+
const clear = () => {
|
|
317
|
+
setSubmission(void 0);
|
|
318
|
+
drop2();
|
|
319
|
+
};
|
|
320
|
+
const retry = () => {
|
|
321
|
+
drop2();
|
|
322
|
+
return submit(...args);
|
|
323
|
+
};
|
|
324
|
+
entry = {
|
|
325
|
+
input,
|
|
326
|
+
pending: true,
|
|
327
|
+
clear,
|
|
328
|
+
retry
|
|
329
|
+
};
|
|
330
|
+
setSubmission(entry);
|
|
331
|
+
setSubmissions((list) => [...list, entry]);
|
|
332
|
+
try {
|
|
333
|
+
const result = await fn(...args);
|
|
334
|
+
setSubmission({
|
|
335
|
+
input,
|
|
336
|
+
result,
|
|
337
|
+
pending: false,
|
|
338
|
+
clear,
|
|
339
|
+
retry
|
|
340
|
+
});
|
|
341
|
+
drop2();
|
|
342
|
+
const stale = typeof options.invalidates === "function" ? options.invalidates(result) : options.invalidates;
|
|
343
|
+
for (const key of stale ?? []) revalidate(key);
|
|
344
|
+
return result;
|
|
345
|
+
} catch (error) {
|
|
346
|
+
const failed = {
|
|
347
|
+
input,
|
|
348
|
+
error,
|
|
349
|
+
pending: false,
|
|
350
|
+
clear,
|
|
351
|
+
retry
|
|
352
|
+
};
|
|
353
|
+
setSubmission(failed);
|
|
354
|
+
settle(failed);
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
submit.url = actionUrl;
|
|
359
|
+
submit.with = (args) => action((...a) => fn(args, ...a), name, options);
|
|
360
|
+
return submit;
|
|
361
|
+
}
|
|
362
|
+
function useSubmission(actionFn) {
|
|
363
|
+
const [submission] = getSubmissionSignal(actionFn.url);
|
|
364
|
+
return submission;
|
|
365
|
+
}
|
|
366
|
+
function useSubmissions(actionFn) {
|
|
367
|
+
const [submissions] = getSubmissionsSignal(actionFn.url);
|
|
368
|
+
return submissions;
|
|
369
|
+
}
|
|
370
|
+
function useAction(actionFn) {
|
|
371
|
+
return actionFn;
|
|
372
|
+
}
|
|
373
|
+
var RouteDataContext = createContext(void 0, "route-data");
|
|
374
|
+
var RouteDataProvider = RouteDataContext.Provider;
|
|
375
|
+
|
|
376
|
+
// src/lib/router/index.ts
|
|
377
|
+
import {
|
|
378
|
+
createMemoryHistory,
|
|
379
|
+
createBrowserHistory as createBrowserHistory2,
|
|
380
|
+
matchRoutes as matchRoutes2,
|
|
381
|
+
matchPath as matchPath2
|
|
382
|
+
} from "@fluixi/router";
|
|
383
|
+
|
|
384
|
+
// src/lib/render/lazy.ts
|
|
385
|
+
import { createComponent } from "@fluixi/dom";
|
|
386
|
+
import {
|
|
387
|
+
untrack,
|
|
388
|
+
createMemo,
|
|
389
|
+
createResource as createResource2
|
|
390
|
+
} from "@fluixi/reactive/signal";
|
|
391
|
+
function fromChunk(value) {
|
|
392
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
393
|
+
try {
|
|
394
|
+
value["$lazy"] = true;
|
|
395
|
+
} catch {
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
400
|
+
function lazy(loader, options) {
|
|
401
|
+
let resolved;
|
|
402
|
+
let promise;
|
|
403
|
+
let component;
|
|
404
|
+
function load() {
|
|
405
|
+
if (!promise) {
|
|
406
|
+
promise = loader().then((mod) => resolved = mod.default);
|
|
407
|
+
}
|
|
408
|
+
return promise;
|
|
409
|
+
}
|
|
410
|
+
if (options?.preload) load();
|
|
411
|
+
const LazyWrapper = ((props) => {
|
|
412
|
+
if (resolved) {
|
|
413
|
+
const C = resolved;
|
|
414
|
+
return fromChunk(untrack(() => C(props)));
|
|
415
|
+
}
|
|
416
|
+
if (!component) {
|
|
417
|
+
const [resource] = createResource2(() => load(), { transport: false });
|
|
418
|
+
component = resource;
|
|
419
|
+
if (resource.error) throw resource.error;
|
|
420
|
+
}
|
|
421
|
+
return createMemo(() => {
|
|
422
|
+
const C = component();
|
|
423
|
+
return C ? fromChunk(createComponent(C, props)) : void 0;
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
LazyWrapper.preload = () => load().then(() => void 0);
|
|
427
|
+
LazyWrapper.$lazy = true;
|
|
428
|
+
LazyWrapper.loader = loader;
|
|
429
|
+
return LazyWrapper;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// src/lib/router/index.ts
|
|
433
|
+
import { runWithOwner as runWithOwner2 } from "@fluixi/reactive/signal";
|
|
434
|
+
var RouterContext = createContext2(void 0, "router");
|
|
435
|
+
var OutletContext = createContext2(void 0, "outlet");
|
|
436
|
+
var LevelParamsContext = createContext2(void 0, "route-params");
|
|
437
|
+
var RouteDataContext2 = createContext2(void 0, "route-data");
|
|
438
|
+
function renderLayer(m, depth, base) {
|
|
439
|
+
let data;
|
|
440
|
+
const loader = m.route.data;
|
|
441
|
+
if (typeof loader === "function") {
|
|
442
|
+
let cancelled = false;
|
|
443
|
+
onCleanup(() => {
|
|
444
|
+
cancelled = true;
|
|
445
|
+
});
|
|
446
|
+
const owner = getOwner2();
|
|
447
|
+
const router = useContext2(RouterContext);
|
|
448
|
+
let watching = false;
|
|
449
|
+
const trackDeps = (deps) => {
|
|
450
|
+
if (watching || cancelled) return;
|
|
451
|
+
watching = true;
|
|
452
|
+
runWithOwner(owner, () => {
|
|
453
|
+
let first = true;
|
|
454
|
+
createEffect(() => {
|
|
455
|
+
deps();
|
|
456
|
+
if (first) first = false;
|
|
457
|
+
else untrack2(() => void refetch());
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
let readsLocation;
|
|
462
|
+
const [resource, { refetch }] = createResource3(() => {
|
|
463
|
+
const params = untrack2(base.params);
|
|
464
|
+
const location = untrack2(base.location);
|
|
465
|
+
readsLocation = false;
|
|
466
|
+
const result = loader(
|
|
467
|
+
{
|
|
468
|
+
params: () => params,
|
|
469
|
+
location: () => {
|
|
470
|
+
readsLocation = true;
|
|
471
|
+
return location;
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
owner,
|
|
475
|
+
() => cancelled,
|
|
476
|
+
trackDeps
|
|
477
|
+
);
|
|
478
|
+
return router ? router.trackLoad(result) : result;
|
|
479
|
+
});
|
|
480
|
+
onCleanup(
|
|
481
|
+
onRevalidate(() => {
|
|
482
|
+
if (untrack2(() => base.matched()[depth]?.route) !== m.route) return;
|
|
483
|
+
void refetch();
|
|
484
|
+
})
|
|
485
|
+
);
|
|
486
|
+
let loadedFor = untrack2(() => JSON.stringify(base.matched()[depth]?.params ?? {}));
|
|
487
|
+
let searchedFor = untrack2(() => base.location().search);
|
|
488
|
+
createEffect(() => {
|
|
489
|
+
const now = base.matched()[depth];
|
|
490
|
+
const search = base.location().search;
|
|
491
|
+
if (now?.route !== m.route) return;
|
|
492
|
+
const params = JSON.stringify(now.params ?? {});
|
|
493
|
+
const paramsMoved = params !== loadedFor;
|
|
494
|
+
const searchMoved = readsLocation !== false && search !== searchedFor;
|
|
495
|
+
loadedFor = params;
|
|
496
|
+
searchedFor = search;
|
|
497
|
+
if (paramsMoved || searchMoved) untrack2(() => void refetch());
|
|
498
|
+
});
|
|
499
|
+
data = () => {
|
|
500
|
+
const error = resource.error;
|
|
501
|
+
if (error !== void 0 && error !== null) throw error;
|
|
502
|
+
const r = resource;
|
|
503
|
+
if (r.state === "refreshing") return r.latest;
|
|
504
|
+
return resource();
|
|
505
|
+
};
|
|
506
|
+
Object.defineProperty(data, "loading", { get: () => resource.loading });
|
|
507
|
+
Object.defineProperty(data, "state", { get: () => resource.state });
|
|
508
|
+
}
|
|
509
|
+
const buildPage = () => RouteDataContext2.Provider({
|
|
510
|
+
value: data,
|
|
511
|
+
get children() {
|
|
512
|
+
return LevelParamsContext.Provider({
|
|
513
|
+
value: m.params,
|
|
514
|
+
get children() {
|
|
515
|
+
return OutletContext.Provider({
|
|
516
|
+
value: { depth, ...base },
|
|
517
|
+
get children() {
|
|
518
|
+
return createComponent2(m.component, {});
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
if (!data) return { view: buildPage(), ready: () => true };
|
|
526
|
+
const res = data;
|
|
527
|
+
const isLoading = () => {
|
|
528
|
+
const state = res.state;
|
|
529
|
+
return state === void 0 ? res.loading : state === "pending" || state === "unresolved";
|
|
530
|
+
};
|
|
531
|
+
const [ready, setReady] = createSignal2(untrack2(() => !isLoading()));
|
|
532
|
+
createEffect(() => setReady(!isLoading()));
|
|
533
|
+
return { view: createMemo2(() => ready() ? buildPage() : null), ready };
|
|
534
|
+
}
|
|
535
|
+
function renderChild(ctx) {
|
|
536
|
+
const childIdx = ctx.depth + 1;
|
|
537
|
+
const [childComp, setChildComp] = createSignal2(
|
|
538
|
+
untrack2(() => ctx.matched()[childIdx]?.component)
|
|
539
|
+
);
|
|
540
|
+
createEffect(() => {
|
|
541
|
+
const c = ctx.matched()[childIdx]?.component;
|
|
542
|
+
if (untrack2(childComp) !== c) setChildComp(() => c);
|
|
543
|
+
});
|
|
544
|
+
const owner = getOwner2();
|
|
545
|
+
let shown = null;
|
|
546
|
+
let pending = null;
|
|
547
|
+
const drop2 = (layer) => layer?.dispose();
|
|
548
|
+
onCleanup(() => {
|
|
549
|
+
drop2(shown);
|
|
550
|
+
drop2(pending);
|
|
551
|
+
shown = pending = null;
|
|
552
|
+
});
|
|
553
|
+
const incoming = createMemo2(() => {
|
|
554
|
+
const component = childComp();
|
|
555
|
+
if (!component) return null;
|
|
556
|
+
const m = untrack2(() => ctx.matched())[childIdx];
|
|
557
|
+
return runWithOwner(
|
|
558
|
+
owner,
|
|
559
|
+
() => createRoot((dispose) => ({
|
|
560
|
+
...renderLayer(m, childIdx, { matched: ctx.matched, params: ctx.params, location: ctx.location }),
|
|
561
|
+
dispose
|
|
562
|
+
}))
|
|
563
|
+
);
|
|
564
|
+
});
|
|
565
|
+
return createMemo2(() => {
|
|
566
|
+
const next = incoming();
|
|
567
|
+
if (!next) {
|
|
568
|
+
drop2(shown);
|
|
569
|
+
drop2(pending);
|
|
570
|
+
shown = pending = null;
|
|
571
|
+
return ctx.notFound ? ctx.notFound() : null;
|
|
572
|
+
}
|
|
573
|
+
if (next === shown) return shown.view;
|
|
574
|
+
if (pending && pending !== next) drop2(pending);
|
|
575
|
+
pending = next;
|
|
576
|
+
if (shown && !next.ready()) return shown.view;
|
|
577
|
+
drop2(shown);
|
|
578
|
+
shown = next;
|
|
579
|
+
pending = null;
|
|
580
|
+
return shown.view;
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
function renderNotFound(notFound) {
|
|
584
|
+
if (notFound == null) return buildDefaultNotFound();
|
|
585
|
+
return typeof notFound === "function" ? createComponent2(notFound, {}) : notFound;
|
|
586
|
+
}
|
|
587
|
+
function buildDefaultNotFound() {
|
|
588
|
+
const el = createNativeElement("div");
|
|
589
|
+
setAttribute(el, "class", "fx-not-found");
|
|
590
|
+
setAttribute(el, "role", "main");
|
|
591
|
+
setAttribute(
|
|
592
|
+
el,
|
|
593
|
+
"style",
|
|
594
|
+
"min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif"
|
|
595
|
+
);
|
|
596
|
+
const h1 = createNativeElement("h1");
|
|
597
|
+
setAttribute(h1, "style", "margin:0;font-size:2.5rem;font-weight:700");
|
|
598
|
+
insert(h1, "404");
|
|
599
|
+
const p = createNativeElement("p");
|
|
600
|
+
setAttribute(p, "style", "margin:0;opacity:.7");
|
|
601
|
+
insert(p, "This page could not be found.");
|
|
602
|
+
el.appendChild(h1);
|
|
603
|
+
el.appendChild(p);
|
|
604
|
+
return el;
|
|
605
|
+
}
|
|
606
|
+
var pendingTransitionMode;
|
|
607
|
+
function Router(props) {
|
|
608
|
+
const history2 = props.history ?? createBrowserHistory();
|
|
609
|
+
const router = createCoreRouter({
|
|
610
|
+
routes: props.routes,
|
|
611
|
+
base: props.base,
|
|
612
|
+
history: history2
|
|
613
|
+
});
|
|
614
|
+
const [state, setState] = createSignal2(router.state());
|
|
615
|
+
const [navigating, setNavigating] = createSignal2(false);
|
|
616
|
+
const [loads, setLoads] = createSignal2(0);
|
|
617
|
+
let navigationId = 0;
|
|
618
|
+
const scroll = history2.window ? keepScroll(router.state().location) : void 0;
|
|
619
|
+
let arriving = scroll ? { id: 0, location: router.state().location, from: void 0 } : null;
|
|
620
|
+
const [arrived, setArrived] = createSignal2(0);
|
|
621
|
+
const takeMode = () => {
|
|
622
|
+
const mode = pendingTransitionMode ?? (props.transition ?? "auto");
|
|
623
|
+
pendingTransitionMode = void 0;
|
|
624
|
+
return mode;
|
|
625
|
+
};
|
|
626
|
+
const unsub = router.subscribe((next) => {
|
|
627
|
+
const id = ++navigationId;
|
|
628
|
+
const mode = takeMode();
|
|
629
|
+
setNavigating(true);
|
|
630
|
+
if (scroll) {
|
|
631
|
+
scroll.leave();
|
|
632
|
+
arriving = { id, location: next.location, from: untrack2(state).location };
|
|
633
|
+
}
|
|
634
|
+
const prepared = prepareComponents(
|
|
635
|
+
(next.match?.matched ?? []).map((m) => m.component).filter(Boolean)
|
|
636
|
+
);
|
|
637
|
+
const commit = () => {
|
|
638
|
+
setState(next);
|
|
639
|
+
const flushed = flush();
|
|
640
|
+
if (id === navigationId) setNavigating(false);
|
|
641
|
+
if (scroll) setArrived(id);
|
|
642
|
+
return flushed;
|
|
643
|
+
};
|
|
644
|
+
if (!prepared) {
|
|
645
|
+
void runTransition(mode, commit);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
void prepared.then(() => {
|
|
649
|
+
if (id !== navigationId) return;
|
|
650
|
+
return runTransition(mode, commit);
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
onCleanup(() => {
|
|
654
|
+
unsub();
|
|
655
|
+
scroll?.dispose();
|
|
656
|
+
router.destroy();
|
|
657
|
+
navigationId++;
|
|
658
|
+
});
|
|
659
|
+
const matched = createMemo2(
|
|
660
|
+
() => (state().match?.matched ?? []).filter((m) => m.component)
|
|
661
|
+
);
|
|
662
|
+
const ctx = {
|
|
663
|
+
router,
|
|
664
|
+
location: createMemo2(() => state().location),
|
|
665
|
+
params: createMemo2(() => state().match?.params ?? {}),
|
|
666
|
+
isRouting: () => navigating() || loads() > 0,
|
|
667
|
+
// Counted by the promise, not by an owner: a load a newer navigation superseded still
|
|
668
|
+
// settles and uncounts itself, and a resource seeded from the server never calls it.
|
|
669
|
+
trackLoad(result) {
|
|
670
|
+
if (result && typeof result.finally === "function") {
|
|
671
|
+
setLoads((n) => n + 1);
|
|
672
|
+
void result.finally(() => setLoads((n) => n - 1)).catch(() => {
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
return result;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
if (scroll) {
|
|
679
|
+
const nextFrame = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (fn) => setTimeout(fn, 0);
|
|
680
|
+
createEffect(() => {
|
|
681
|
+
const id = arrived();
|
|
682
|
+
if (ctx.isRouting()) return;
|
|
683
|
+
const next = arriving;
|
|
684
|
+
if (!next || next.id !== id || id !== navigationId) return;
|
|
685
|
+
arriving = null;
|
|
686
|
+
nextFrame(() => {
|
|
687
|
+
if (id === navigationId) scroll.arrive(next.location, next.from);
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
const root = {
|
|
692
|
+
depth: -1,
|
|
693
|
+
matched,
|
|
694
|
+
params: ctx.params,
|
|
695
|
+
location: ctx.location,
|
|
696
|
+
// Only the root carries this: renderChild shows it when the URL matched nothing.
|
|
697
|
+
notFound: () => renderNotFound(props.notFound)
|
|
698
|
+
};
|
|
699
|
+
let rootView;
|
|
700
|
+
return RouterContext.Provider({
|
|
701
|
+
value: ctx,
|
|
702
|
+
get children() {
|
|
703
|
+
return rootView ??= renderChild(root);
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
function Outlet() {
|
|
708
|
+
const ctx = useContext2(OutletContext);
|
|
709
|
+
if (!ctx) return null;
|
|
710
|
+
return renderChild(ctx);
|
|
711
|
+
}
|
|
712
|
+
function useIsRouting(options = {}) {
|
|
713
|
+
const routing = useContext2(RouterContext)?.isRouting ?? (() => false);
|
|
714
|
+
const delay = options.delay ?? 0;
|
|
715
|
+
if (delay <= 0) return routing;
|
|
716
|
+
const [late, setLate] = createSignal2(false);
|
|
717
|
+
createEffect(() => {
|
|
718
|
+
if (!routing()) {
|
|
719
|
+
setLate(false);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const timer = setTimeout(() => setLate(true), delay);
|
|
723
|
+
onCleanup(() => clearTimeout(timer));
|
|
724
|
+
});
|
|
725
|
+
return () => routing() && late();
|
|
726
|
+
}
|
|
727
|
+
function Redirect(props) {
|
|
728
|
+
const ctx = useContext2(RouterContext);
|
|
729
|
+
if (ctx && typeof window !== "undefined") {
|
|
730
|
+
let cancelled = false;
|
|
731
|
+
onCleanup(() => cancelled = true);
|
|
732
|
+
queueMicrotask(() => {
|
|
733
|
+
if (!cancelled) ctx.router.navigate(props.to, { replace: props.replace !== false });
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
var _ssrRouterStub = {
|
|
739
|
+
router: { navigate: () => {
|
|
740
|
+
} },
|
|
741
|
+
location: () => ({ pathname: "", search: "", hash: "", query: {} }),
|
|
742
|
+
params: () => ({}),
|
|
743
|
+
isRouting: () => false,
|
|
744
|
+
trackLoad: (result) => result
|
|
745
|
+
};
|
|
746
|
+
function useRouter() {
|
|
747
|
+
const ctx = useContext2(RouterContext);
|
|
748
|
+
if (ctx) return ctx;
|
|
749
|
+
if (typeof window === "undefined") return _ssrRouterStub;
|
|
750
|
+
throw new Error("[router] useRouter must be used within <Router>");
|
|
751
|
+
}
|
|
752
|
+
function useParams() {
|
|
753
|
+
const params = useRouter().params;
|
|
754
|
+
return createMemo2(() => params(), {}, {
|
|
755
|
+
equals: (a, b) => JSON.stringify(a) === JSON.stringify(b)
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
function useLevelParams() {
|
|
759
|
+
return useContext2(LevelParamsContext) ?? {};
|
|
760
|
+
}
|
|
761
|
+
function useParam(key) {
|
|
762
|
+
const params = useParams();
|
|
763
|
+
return createMemo2(() => params()[key]);
|
|
764
|
+
}
|
|
765
|
+
function useParamSelector(selector, equals) {
|
|
766
|
+
const params = useParams();
|
|
767
|
+
return createMemo2(
|
|
768
|
+
() => selector(params()),
|
|
769
|
+
void 0,
|
|
770
|
+
equals ? { equals } : void 0
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
function useMatch(path) {
|
|
774
|
+
const location = useLocation();
|
|
775
|
+
return createMemo2(
|
|
776
|
+
() => matchPath(typeof path === "function" ? path() : path, location.pathname)
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
function useSearchParams() {
|
|
780
|
+
const location = useLocation();
|
|
781
|
+
const navigate = useNavigate();
|
|
782
|
+
const params = createMemo2(() => location.query);
|
|
783
|
+
const setParams = (next, options) => {
|
|
784
|
+
const current = new URLSearchParams(location.search);
|
|
785
|
+
for (const [k, v] of Object.entries(next)) {
|
|
786
|
+
if (v === null) current.delete(k);
|
|
787
|
+
else current.set(k, v);
|
|
788
|
+
}
|
|
789
|
+
const search = current.toString();
|
|
790
|
+
navigate(location.pathname + (search ? `?${search}` : ""), options);
|
|
791
|
+
};
|
|
792
|
+
return [params, setParams];
|
|
793
|
+
}
|
|
794
|
+
function select(source, key) {
|
|
795
|
+
const equals = (a, b) => deepEqual(a, b);
|
|
796
|
+
if (key !== void 0) {
|
|
797
|
+
return createMemo2(
|
|
798
|
+
() => get(source(), key),
|
|
799
|
+
void 0,
|
|
800
|
+
{ equals }
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
return createMemo2(source, void 0, { equals });
|
|
804
|
+
}
|
|
805
|
+
function useLocation() {
|
|
806
|
+
const { location } = useRouter();
|
|
807
|
+
return new Proxy({}, {
|
|
808
|
+
get: (_t, key) => location()[key],
|
|
809
|
+
has: (_t, key) => key in location(),
|
|
810
|
+
ownKeys: () => Reflect.ownKeys(location()),
|
|
811
|
+
getOwnPropertyDescriptor: (_t, key) => Object.getOwnPropertyDescriptor(location(), key)
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
function useLinkNavigation(options = {}) {
|
|
815
|
+
const ctx = useContext2(RouterContext);
|
|
816
|
+
return (event) => {
|
|
817
|
+
if (!ctx || event.defaultPrevented || event.button !== 0) return;
|
|
818
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
819
|
+
const target = event.target;
|
|
820
|
+
const anchor = target?.closest?.("a");
|
|
821
|
+
if (!anchor || !anchor.getAttribute("href")) return;
|
|
822
|
+
if (anchor.target && anchor.target !== "_self") return;
|
|
823
|
+
if (anchor.hasAttribute("download")) return;
|
|
824
|
+
if (/(^|\s)external(\s|$)/.test(anchor.getAttribute("rel") ?? "")) return;
|
|
825
|
+
const url = new URL(anchor.href);
|
|
826
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
827
|
+
if (url.origin !== window.location.origin) return;
|
|
828
|
+
if (url.hash && url.pathname === window.location.pathname && url.search === window.location.search) return;
|
|
829
|
+
if (options.shouldNavigate && !options.shouldNavigate(url, anchor)) return;
|
|
830
|
+
event.preventDefault();
|
|
831
|
+
pendingTransitionMode = options.transition;
|
|
832
|
+
ctx.router.navigate(url.pathname + url.search + url.hash, { replace: options.replace });
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function useNavigate() {
|
|
836
|
+
const { router } = useRouter();
|
|
837
|
+
return (to, options) => {
|
|
838
|
+
pendingTransitionMode = options?.transition;
|
|
839
|
+
router.navigate(to, options);
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function useRouteData() {
|
|
843
|
+
const acc = useContext2(RouteDataContext2);
|
|
844
|
+
return acc ?? (() => void 0);
|
|
845
|
+
}
|
|
846
|
+
var read = (v) => typeof v === "function" ? v() : v;
|
|
847
|
+
var LINK_OWN_PROPS = /* @__PURE__ */ new Set([
|
|
848
|
+
"href",
|
|
849
|
+
"slot",
|
|
850
|
+
"class",
|
|
851
|
+
"className",
|
|
852
|
+
"active",
|
|
853
|
+
"activeClass",
|
|
854
|
+
"replace",
|
|
855
|
+
"children"
|
|
856
|
+
]);
|
|
857
|
+
function Link(props) {
|
|
858
|
+
const ctx = useContext2(RouterContext);
|
|
859
|
+
const navigate = () => ctx.router.navigate(read(props.href) ?? "", { replace: read(props.replace) });
|
|
860
|
+
const a = createNativeElement("a");
|
|
861
|
+
setAttribute(a, "href", read(props.href) ?? "");
|
|
862
|
+
if (props.slot) setAttribute(a, "slot", read(props.slot));
|
|
863
|
+
for (const k of Object.keys(props)) {
|
|
864
|
+
if (LINK_OWN_PROPS.has(k)) continue;
|
|
865
|
+
const v = props[k];
|
|
866
|
+
if (typeof v === "function") {
|
|
867
|
+
if (/^on[A-Z]/.test(k)) continue;
|
|
868
|
+
const read2 = v;
|
|
869
|
+
const apply = () => {
|
|
870
|
+
const value = read2();
|
|
871
|
+
if (value == null || value === false) a.removeAttribute?.(k);
|
|
872
|
+
else setAttribute(a, k, String(value));
|
|
873
|
+
};
|
|
874
|
+
if (typeof a.addEventListener === "function") createEffect(apply);
|
|
875
|
+
else apply();
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
if (v != null) setAttribute(a, k, String(v));
|
|
879
|
+
}
|
|
880
|
+
if (typeof a.addEventListener === "function") {
|
|
881
|
+
a.addEventListener("click", (e) => {
|
|
882
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
883
|
+
if (!ctx) return;
|
|
884
|
+
e.preventDefault();
|
|
885
|
+
navigate();
|
|
886
|
+
});
|
|
887
|
+
} else {
|
|
888
|
+
const base = read(props.className ?? props.class) ?? "";
|
|
889
|
+
if (base) setAttribute(a, "class", base);
|
|
890
|
+
}
|
|
891
|
+
if (typeof a.addEventListener === "function") {
|
|
892
|
+
createEffect(() => {
|
|
893
|
+
const href = read(props.href) ?? "";
|
|
894
|
+
a.setAttribute("href", href);
|
|
895
|
+
const base = read(props.className ?? props.class) ?? "";
|
|
896
|
+
const activeClass = read(props.activeClass) ?? "";
|
|
897
|
+
const active = read(props.active) ?? ctx?.location().pathname === href;
|
|
898
|
+
a.className = [base, active ? activeClass : ""].filter(Boolean).join(" ");
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
const linkChildren = props.children;
|
|
902
|
+
if (linkChildren != null) insert(a, linkChildren);
|
|
903
|
+
return a;
|
|
904
|
+
}
|
|
905
|
+
var A = Link;
|
|
906
|
+
function ActionForm(props) {
|
|
907
|
+
const action2 = props.action;
|
|
908
|
+
const cls = props.className ?? props.class;
|
|
909
|
+
const url = action2.url ?? "";
|
|
910
|
+
const form = createNativeElement("form");
|
|
911
|
+
setAttribute(form, "method", "post");
|
|
912
|
+
if (url) setAttribute(form, "action", url);
|
|
913
|
+
if (cls) setAttribute(form, "class", cls);
|
|
914
|
+
for (const k of Object.keys(props)) {
|
|
915
|
+
if (k === "action" || k === "children" || k === "class" || k === "className") continue;
|
|
916
|
+
const v = props[k];
|
|
917
|
+
if (v != null && typeof v !== "function") setAttribute(form, k, String(v));
|
|
918
|
+
}
|
|
919
|
+
if (typeof form.addEventListener === "function") {
|
|
920
|
+
form.addEventListener("submit", (e) => {
|
|
921
|
+
e.preventDefault();
|
|
922
|
+
const data = {};
|
|
923
|
+
new FormData(form).forEach((v, k) => {
|
|
924
|
+
data[k] = v;
|
|
925
|
+
});
|
|
926
|
+
Promise.resolve(action2(data)).catch(() => {
|
|
927
|
+
});
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
const children = props.children;
|
|
931
|
+
if (children != null) insert(form, children);
|
|
932
|
+
return form;
|
|
933
|
+
}
|
|
934
|
+
async function preloadRoutes(routes, pathname) {
|
|
935
|
+
const match = matchRoutes(routes, pathname);
|
|
936
|
+
if (!match) return;
|
|
937
|
+
const loads = [];
|
|
938
|
+
for (const m of match.matched) {
|
|
939
|
+
const c = m.component;
|
|
940
|
+
if (c && typeof c.preload === "function") loads.push(c.preload());
|
|
941
|
+
}
|
|
942
|
+
await Promise.all(loads);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
export {
|
|
946
|
+
__reExport,
|
|
947
|
+
lazy,
|
|
948
|
+
createContext,
|
|
949
|
+
useContext,
|
|
950
|
+
createProvider,
|
|
951
|
+
composeProviders,
|
|
952
|
+
requireContext,
|
|
953
|
+
supportsViewTransitions,
|
|
954
|
+
prefersReducedMotion,
|
|
955
|
+
cache,
|
|
956
|
+
revalidate,
|
|
957
|
+
createAsync,
|
|
958
|
+
action,
|
|
959
|
+
useSubmission,
|
|
960
|
+
useSubmissions,
|
|
961
|
+
useAction,
|
|
962
|
+
Router,
|
|
963
|
+
Outlet,
|
|
964
|
+
useIsRouting,
|
|
965
|
+
Redirect,
|
|
966
|
+
useRouter,
|
|
967
|
+
useParams,
|
|
968
|
+
useLevelParams,
|
|
969
|
+
useParam,
|
|
970
|
+
useParamSelector,
|
|
971
|
+
useMatch,
|
|
972
|
+
useSearchParams,
|
|
973
|
+
select,
|
|
974
|
+
useLocation,
|
|
975
|
+
useLinkNavigation,
|
|
976
|
+
useNavigate,
|
|
977
|
+
useRouteData,
|
|
978
|
+
Link,
|
|
979
|
+
A,
|
|
980
|
+
ActionForm,
|
|
981
|
+
preloadRoutes,
|
|
982
|
+
createMemoryHistory,
|
|
983
|
+
createBrowserHistory2 as createBrowserHistory,
|
|
984
|
+
matchRoutes2 as matchRoutes,
|
|
985
|
+
matchPath2 as matchPath,
|
|
986
|
+
runWithOwner2 as runWithOwner
|
|
987
|
+
};
|