@teyik0/furin 0.1.0-alpha.10
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/dist/adapter/bun.d.ts +3 -0
- package/dist/adapter/static.d.ts +3 -0
- package/dist/build/client.d.ts +25 -0
- package/dist/build/compile-entry.d.ts +35 -0
- package/dist/build/entry-template.d.ts +26 -0
- package/dist/build/hydrate.d.ts +24 -0
- package/dist/build/index.d.ts +7 -0
- package/dist/build/index.js +4716 -0
- package/dist/build/route-types.d.ts +21 -0
- package/dist/build/scan-server.d.ts +8 -0
- package/dist/build/server-routes-entry.d.ts +35 -0
- package/dist/build/shared.d.ts +11 -0
- package/dist/build/types.d.ts +76 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +4751 -0
- package/dist/client.d.ts +195 -0
- package/dist/client.js +20 -0
- package/dist/config.d.ts +50 -0
- package/dist/config.js +28 -0
- package/dist/context-logger.d.ts +28 -0
- package/dist/dev-page-plugin.d.ts +109 -0
- package/dist/error.d.ts +23 -0
- package/dist/furin.d.ts +52 -0
- package/dist/furin.js +3948 -0
- package/dist/internal.d.ts +33 -0
- package/dist/link.d.ts +454 -0
- package/dist/link.js +1790 -0
- package/dist/not-found.d.ts +19 -0
- package/dist/plugin/index.d.ts +20 -0
- package/dist/plugin/index.js +1408 -0
- package/dist/plugin/transform-client.d.ts +9 -0
- package/dist/render/assemble.d.ts +15 -0
- package/dist/render/boundaries.d.ts +79 -0
- package/dist/render/cache.d.ts +96 -0
- package/dist/render/default-screens.d.ts +11 -0
- package/dist/render/digest.d.ts +16 -0
- package/dist/render/element.d.ts +8 -0
- package/dist/render/index.d.ts +53 -0
- package/dist/render/loaders.d.ts +21 -0
- package/dist/render/shell.d.ts +29 -0
- package/dist/render/template.d.ts +6 -0
- package/dist/router.d.ts +96 -0
- package/dist/router.js +2693 -0
- package/dist/runtime-env.d.ts +3 -0
- package/dist/utils.d.ts +6 -0
- package/package.json +77 -0
- package/src/adapter/README.md +13 -0
- package/src/adapter/bun.ts +239 -0
- package/src/adapter/static.ts +341 -0
- package/src/build/client.ts +153 -0
- package/src/build/compile-entry.ts +129 -0
- package/src/build/entry-template.ts +126 -0
- package/src/build/hydrate.ts +250 -0
- package/src/build/index.ts +151 -0
- package/src/build/route-types.ts +89 -0
- package/src/build/scan-server.ts +110 -0
- package/src/build/server-routes-entry.ts +55 -0
- package/src/build/shared.ts +78 -0
- package/src/build/types.ts +85 -0
- package/src/cli/config.ts +68 -0
- package/src/cli/index.ts +115 -0
- package/src/client.ts +278 -0
- package/src/config.ts +66 -0
- package/src/context-logger.ts +74 -0
- package/src/dev-page-plugin.ts +434 -0
- package/src/env.d.ts +49 -0
- package/src/error.ts +32 -0
- package/src/furin.ts +383 -0
- package/src/internal.ts +51 -0
- package/src/link.tsx +1578 -0
- package/src/not-found.ts +40 -0
- package/src/plugin/index.ts +80 -0
- package/src/plugin/transform-client.ts +372 -0
- package/src/render/assemble.ts +66 -0
- package/src/render/boundaries.tsx +176 -0
- package/src/render/cache.ts +251 -0
- package/src/render/default-screens.tsx +299 -0
- package/src/render/digest.ts +71 -0
- package/src/render/element.tsx +119 -0
- package/src/render/index.ts +867 -0
- package/src/render/loaders.ts +127 -0
- package/src/render/shell.ts +187 -0
- package/src/render/template.ts +55 -0
- package/src/router.ts +779 -0
- package/src/runtime-env.ts +6 -0
- package/src/utils.ts +68 -0
package/dist/link.js
ADDED
|
@@ -0,0 +1,1790 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/utils.mjs
|
|
3
|
+
function formatDuration(ms) {
|
|
4
|
+
if (ms < 1000)
|
|
5
|
+
return `${Math.round(ms)}ms`;
|
|
6
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
7
|
+
}
|
|
8
|
+
function isClient() {
|
|
9
|
+
return typeof window !== "undefined";
|
|
10
|
+
}
|
|
11
|
+
function isDev() {
|
|
12
|
+
if (typeof process !== "undefined")
|
|
13
|
+
return true;
|
|
14
|
+
if (typeof window !== "undefined")
|
|
15
|
+
return true;
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function detectEnvironment() {
|
|
19
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
20
|
+
const defaultEnvironment = isDev() ? "development" : "production";
|
|
21
|
+
return {
|
|
22
|
+
environment: env.NODE_ENV || defaultEnvironment,
|
|
23
|
+
service: env.SERVICE_NAME || "app",
|
|
24
|
+
version: env.APP_VERSION,
|
|
25
|
+
commitHash: env.COMMIT_SHA || env.GITHUB_SHA || env.VERCEL_GIT_COMMIT_SHA || env.CF_PAGES_COMMIT_SHA,
|
|
26
|
+
region: env.VERCEL_REGION || env.AWS_REGION || env.FLY_REGION || env.CF_REGION
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var LEVEL_ORDER = {
|
|
30
|
+
debug: 0,
|
|
31
|
+
info: 1,
|
|
32
|
+
warn: 2,
|
|
33
|
+
error: 3
|
|
34
|
+
};
|
|
35
|
+
function isLevelEnabled(level, minLevel) {
|
|
36
|
+
return LEVEL_ORDER[level] >= LEVEL_ORDER[minLevel];
|
|
37
|
+
}
|
|
38
|
+
function getConsoleMethod(level) {
|
|
39
|
+
return level;
|
|
40
|
+
}
|
|
41
|
+
var colors = {
|
|
42
|
+
reset: "\x1B[0m",
|
|
43
|
+
bold: "\x1B[1m",
|
|
44
|
+
dim: "\x1B[2m",
|
|
45
|
+
red: "\x1B[31m",
|
|
46
|
+
green: "\x1B[32m",
|
|
47
|
+
yellow: "\x1B[33m",
|
|
48
|
+
blue: "\x1B[34m",
|
|
49
|
+
magenta: "\x1B[35m",
|
|
50
|
+
cyan: "\x1B[36m",
|
|
51
|
+
white: "\x1B[37m",
|
|
52
|
+
gray: "\x1B[90m"
|
|
53
|
+
};
|
|
54
|
+
var levelColorMap = {
|
|
55
|
+
error: colors.red,
|
|
56
|
+
warn: colors.yellow,
|
|
57
|
+
info: colors.cyan,
|
|
58
|
+
debug: colors.gray
|
|
59
|
+
};
|
|
60
|
+
function getLevelColor(level) {
|
|
61
|
+
return levelColorMap[level] ?? colors.white;
|
|
62
|
+
}
|
|
63
|
+
var cssColors = {
|
|
64
|
+
dim: "color: #6b7280",
|
|
65
|
+
red: "color: #ef4444; font-weight: bold",
|
|
66
|
+
green: "color: #22c55e",
|
|
67
|
+
yellow: "color: #f59e0b; font-weight: bold",
|
|
68
|
+
cyan: "color: #06b6d4; font-weight: bold",
|
|
69
|
+
gray: "color: #6b7280; font-weight: bold",
|
|
70
|
+
reset: "color: inherit; font-weight: normal"
|
|
71
|
+
};
|
|
72
|
+
var cssLevelColorMap = {
|
|
73
|
+
error: cssColors.red,
|
|
74
|
+
warn: cssColors.yellow,
|
|
75
|
+
info: cssColors.cyan,
|
|
76
|
+
debug: cssColors.gray
|
|
77
|
+
};
|
|
78
|
+
function getCssLevelColor(level) {
|
|
79
|
+
return cssLevelColorMap[level] ?? cssColors.reset;
|
|
80
|
+
}
|
|
81
|
+
function escapeFormatString(str) {
|
|
82
|
+
return str.replace(/%/g, "%%");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/logger-DnobymUQ.mjs
|
|
86
|
+
var DEFAULT_REPLACEMENT = "[REDACTED]";
|
|
87
|
+
var builtinPatterns = {
|
|
88
|
+
creditCard: {
|
|
89
|
+
pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
|
|
90
|
+
mask: (m) => `****${m.replace(/[\s-]/g, "").slice(-4)}`
|
|
91
|
+
},
|
|
92
|
+
email: {
|
|
93
|
+
pattern: /[\w.+-]+@[\w-]+\.[\w.]+/g,
|
|
94
|
+
mask: (m) => {
|
|
95
|
+
if (m.indexOf("@") < 1)
|
|
96
|
+
return "***@***";
|
|
97
|
+
const tld = m.slice(m.lastIndexOf("."));
|
|
98
|
+
return `${m[0]}***@***${tld}`;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
ipv4: {
|
|
102
|
+
pattern: /\b(?!0\.0\.0\.0\b)(?!127\.0\.0\.1\b)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,
|
|
103
|
+
mask: (m) => `***.***.***.${m.split(".").pop()}`
|
|
104
|
+
},
|
|
105
|
+
phone: {
|
|
106
|
+
pattern: /(?:\+\d{1,3}[\s.-]?)?\(?\d{1,4}\)?[\s.-]?\d{2,4}[\s.-]?\d{2,4}[\s.-]?\d{2,4}\b/g,
|
|
107
|
+
mask: (m) => {
|
|
108
|
+
const digits = m.replace(/[^\d]/g, "");
|
|
109
|
+
if (m.startsWith("+") && digits.length > 4) {
|
|
110
|
+
const ccMatch = m.match(/^\+\d{1,3}/);
|
|
111
|
+
return `${ccMatch ? ccMatch[0] : "+"}******${digits.slice(-2)}`;
|
|
112
|
+
}
|
|
113
|
+
if (digits.length > 2)
|
|
114
|
+
return `${"*".repeat(digits.length - 2)}${digits.slice(-2)}`;
|
|
115
|
+
return "***";
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
jwt: {
|
|
119
|
+
pattern: /\beyJ[\w-]*\.[\w-]*\.[\w-]*\b/g,
|
|
120
|
+
mask: () => "eyJ***.***"
|
|
121
|
+
},
|
|
122
|
+
bearer: {
|
|
123
|
+
pattern: /\bBearer\s+[\w\-.~+/]{8,}=*/gi,
|
|
124
|
+
mask: () => "Bearer ***"
|
|
125
|
+
},
|
|
126
|
+
iban: {
|
|
127
|
+
pattern: /\b[A-Z]{2}\d{2}[\s-]?[\dA-Z]{4}[\s-]?[\dA-Z]{4}[\s-]?[\dA-Z]{4}[\s-]?[\dA-Z]{0,4}[\s-]?[\dA-Z]{0,4}[\s-]?[\dA-Z]{0,4}\b/g,
|
|
128
|
+
mask: (m) => {
|
|
129
|
+
const clean = m.replace(/[\s-]/g, "");
|
|
130
|
+
return `${clean.slice(0, 4)}****${clean.slice(-3)}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function resolveRedactConfig(input) {
|
|
135
|
+
if (input === undefined || input === false)
|
|
136
|
+
return;
|
|
137
|
+
if (input === true)
|
|
138
|
+
return { _maskers: allBuiltinMaskers() };
|
|
139
|
+
if (input.builtins === false)
|
|
140
|
+
return input;
|
|
141
|
+
const maskers = Array.isArray(input.builtins) ? input.builtins.map((name) => builtinPatterns[name]).filter(Boolean).map((b) => [cloneRegex(b.pattern), b.mask]) : allBuiltinMaskers();
|
|
142
|
+
return {
|
|
143
|
+
...input,
|
|
144
|
+
_maskers: maskers
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function allBuiltinMaskers() {
|
|
148
|
+
return Object.values(builtinPatterns).map((b) => [cloneRegex(b.pattern), b.mask]);
|
|
149
|
+
}
|
|
150
|
+
function cloneRegex(re) {
|
|
151
|
+
return new RegExp(re.source, re.flags);
|
|
152
|
+
}
|
|
153
|
+
function redactEvent(event, config) {
|
|
154
|
+
const replacement = config.replacement ?? DEFAULT_REPLACEMENT;
|
|
155
|
+
if (config.paths?.length)
|
|
156
|
+
for (const path of config.paths)
|
|
157
|
+
redactPath(event, path.split("."), replacement);
|
|
158
|
+
if (config._maskers?.length)
|
|
159
|
+
applyMaskersToTree(event, config._maskers);
|
|
160
|
+
if (config.patterns?.length)
|
|
161
|
+
redactPatterns(event, config.patterns, replacement);
|
|
162
|
+
}
|
|
163
|
+
function redactPath(obj, segments, replacement) {
|
|
164
|
+
let current = obj;
|
|
165
|
+
for (let i = 0;i < segments.length - 1; i++) {
|
|
166
|
+
if (current === null || current === undefined || typeof current !== "object")
|
|
167
|
+
return;
|
|
168
|
+
current = current[segments[i]];
|
|
169
|
+
}
|
|
170
|
+
if (current === null || current === undefined || typeof current !== "object")
|
|
171
|
+
return;
|
|
172
|
+
const leaf = segments[segments.length - 1];
|
|
173
|
+
if (leaf in current)
|
|
174
|
+
current[leaf] = replacement;
|
|
175
|
+
}
|
|
176
|
+
function redactPatterns(obj, patterns, replacement) {
|
|
177
|
+
if (obj === null || obj === undefined)
|
|
178
|
+
return;
|
|
179
|
+
if (Array.isArray(obj)) {
|
|
180
|
+
for (let i = 0;i < obj.length; i++)
|
|
181
|
+
if (typeof obj[i] === "string")
|
|
182
|
+
obj[i] = applyPatterns(obj[i], patterns, replacement);
|
|
183
|
+
else if (typeof obj[i] === "object")
|
|
184
|
+
redactPatterns(obj[i], patterns, replacement);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (typeof obj === "object") {
|
|
188
|
+
const record = obj;
|
|
189
|
+
for (const key in record) {
|
|
190
|
+
const val = record[key];
|
|
191
|
+
if (typeof val === "string")
|
|
192
|
+
record[key] = applyPatterns(val, patterns, replacement);
|
|
193
|
+
else if (typeof val === "object")
|
|
194
|
+
redactPatterns(val, patterns, replacement);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function applyPatterns(value, patterns, replacement) {
|
|
199
|
+
let result = value;
|
|
200
|
+
for (const pattern of patterns) {
|
|
201
|
+
pattern.lastIndex = 0;
|
|
202
|
+
result = result.replace(pattern, replacement);
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
function applyMaskersToTree(obj, maskers) {
|
|
207
|
+
if (obj === null || obj === undefined)
|
|
208
|
+
return;
|
|
209
|
+
if (Array.isArray(obj)) {
|
|
210
|
+
for (let i = 0;i < obj.length; i++)
|
|
211
|
+
if (typeof obj[i] === "string")
|
|
212
|
+
obj[i] = applyMaskers(obj[i], maskers);
|
|
213
|
+
else if (typeof obj[i] === "object")
|
|
214
|
+
applyMaskersToTree(obj[i], maskers);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (typeof obj === "object") {
|
|
218
|
+
const record = obj;
|
|
219
|
+
for (const key in record) {
|
|
220
|
+
const val = record[key];
|
|
221
|
+
if (typeof val === "string")
|
|
222
|
+
record[key] = applyMaskers(val, maskers);
|
|
223
|
+
else if (typeof val === "object")
|
|
224
|
+
applyMaskersToTree(val, maskers);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function applyMaskers(value, maskers) {
|
|
229
|
+
let result = value;
|
|
230
|
+
for (const [pattern, mask] of maskers) {
|
|
231
|
+
pattern.lastIndex = 0;
|
|
232
|
+
result = result.replace(pattern, mask);
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
var _tsDate = /* @__PURE__ */ new Date;
|
|
237
|
+
function isoNow() {
|
|
238
|
+
_tsDate.setTime(Date.now());
|
|
239
|
+
return _tsDate.toISOString();
|
|
240
|
+
}
|
|
241
|
+
var globalEnv = {
|
|
242
|
+
service: "app",
|
|
243
|
+
environment: "development"
|
|
244
|
+
};
|
|
245
|
+
var globalPretty = isDev();
|
|
246
|
+
var globalSampling = {};
|
|
247
|
+
var globalStringify = true;
|
|
248
|
+
var globalDrain;
|
|
249
|
+
var globalRedact;
|
|
250
|
+
var globalEnabled = true;
|
|
251
|
+
var globalSilent = false;
|
|
252
|
+
var globalMinLevel = "debug";
|
|
253
|
+
function initLogger(config = {}) {
|
|
254
|
+
globalEnabled = config.enabled ?? true;
|
|
255
|
+
const detected = detectEnvironment();
|
|
256
|
+
globalEnv = {
|
|
257
|
+
service: config.env?.service ?? detected.service ?? "app",
|
|
258
|
+
environment: config.env?.environment ?? detected.environment ?? "development",
|
|
259
|
+
version: config.env?.version ?? detected.version,
|
|
260
|
+
commitHash: config.env?.commitHash ?? detected.commitHash,
|
|
261
|
+
region: config.env?.region ?? detected.region
|
|
262
|
+
};
|
|
263
|
+
globalPretty = config.pretty ?? isDev();
|
|
264
|
+
globalSampling = config.sampling ?? {};
|
|
265
|
+
globalStringify = config.stringify ?? true;
|
|
266
|
+
globalDrain = config.drain;
|
|
267
|
+
globalRedact = resolveRedactConfig(config.redact ?? !isDev());
|
|
268
|
+
globalSilent = config.silent ?? false;
|
|
269
|
+
globalMinLevel = config.minLevel ?? "debug";
|
|
270
|
+
if (globalSilent && !globalDrain && !config._suppressDrainWarning)
|
|
271
|
+
console.warn("[evlog] silent mode is enabled but no drain is configured. Events will be built and sampled but not output anywhere. Set a drain via initLogger({ drain }) or a framework hook (evlog:drain).");
|
|
272
|
+
}
|
|
273
|
+
function shouldSample(level) {
|
|
274
|
+
const { rates } = globalSampling;
|
|
275
|
+
if (!rates)
|
|
276
|
+
return true;
|
|
277
|
+
const percentage = level === "error" && rates.error === undefined ? 100 : rates[level] ?? 100;
|
|
278
|
+
if (percentage <= 0)
|
|
279
|
+
return false;
|
|
280
|
+
if (percentage >= 100)
|
|
281
|
+
return true;
|
|
282
|
+
return Math.random() * 100 < percentage;
|
|
283
|
+
}
|
|
284
|
+
function emitWideEvent(level, event, deferDrain = false, ownsEvent = false) {
|
|
285
|
+
if (!globalEnabled)
|
|
286
|
+
return null;
|
|
287
|
+
if (!ownsEvent) {
|
|
288
|
+
if (!isLevelEnabled(level, globalMinLevel))
|
|
289
|
+
return null;
|
|
290
|
+
if (!shouldSample(level))
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
let formatted;
|
|
294
|
+
if (ownsEvent) {
|
|
295
|
+
event.timestamp = isoNow();
|
|
296
|
+
event.level = level;
|
|
297
|
+
if (event.service === undefined)
|
|
298
|
+
event.service = globalEnv.service;
|
|
299
|
+
if (event.environment === undefined)
|
|
300
|
+
event.environment = globalEnv.environment;
|
|
301
|
+
if (globalEnv.version !== undefined && event.version === undefined)
|
|
302
|
+
event.version = globalEnv.version;
|
|
303
|
+
if (globalEnv.commitHash !== undefined && event.commitHash === undefined)
|
|
304
|
+
event.commitHash = globalEnv.commitHash;
|
|
305
|
+
if (globalEnv.region !== undefined && event.region === undefined)
|
|
306
|
+
event.region = globalEnv.region;
|
|
307
|
+
formatted = event;
|
|
308
|
+
} else
|
|
309
|
+
formatted = {
|
|
310
|
+
timestamp: isoNow(),
|
|
311
|
+
level,
|
|
312
|
+
...globalEnv,
|
|
313
|
+
...event
|
|
314
|
+
};
|
|
315
|
+
if (globalRedact)
|
|
316
|
+
redactEvent(formatted, globalRedact);
|
|
317
|
+
if (!globalSilent)
|
|
318
|
+
if (globalPretty)
|
|
319
|
+
prettyPrintWideEvent(formatted);
|
|
320
|
+
else if (globalStringify)
|
|
321
|
+
console[getConsoleMethod(level)](JSON.stringify(formatted));
|
|
322
|
+
else
|
|
323
|
+
console[getConsoleMethod(level)](formatted);
|
|
324
|
+
if (globalDrain && !deferDrain)
|
|
325
|
+
Promise.resolve(globalDrain({ event: formatted })).catch((err) => {
|
|
326
|
+
console.error("[evlog] drain failed:", err);
|
|
327
|
+
});
|
|
328
|
+
return formatted;
|
|
329
|
+
}
|
|
330
|
+
function emitTaggedLog(level, tag, message) {
|
|
331
|
+
if (!globalEnabled)
|
|
332
|
+
return;
|
|
333
|
+
if (globalPretty && !globalSilent) {
|
|
334
|
+
if (!isLevelEnabled(level, globalMinLevel))
|
|
335
|
+
return;
|
|
336
|
+
if (!shouldSample(level))
|
|
337
|
+
return;
|
|
338
|
+
if (isClient()) {
|
|
339
|
+
const levelColor = getCssLevelColor(level);
|
|
340
|
+
const timestamp = isoNow().slice(11, 23);
|
|
341
|
+
console.log(`%c${timestamp}%c %c[${escapeFormatString(tag)}]%c ${escapeFormatString(message)}`, cssColors.dim, cssColors.reset, levelColor, cssColors.reset);
|
|
342
|
+
} else {
|
|
343
|
+
const color = getLevelColor(level);
|
|
344
|
+
const timestamp = isoNow().slice(11, 23);
|
|
345
|
+
console.log(`${colors.dim}${timestamp}${colors.reset} ${color}[${tag}]${colors.reset} ${message}`);
|
|
346
|
+
}
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
emitWideEvent(level, {
|
|
350
|
+
tag,
|
|
351
|
+
message
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function formatValue(value) {
|
|
355
|
+
if (value === null || value === undefined)
|
|
356
|
+
return String(value);
|
|
357
|
+
if (typeof value === "object") {
|
|
358
|
+
const pairs = [];
|
|
359
|
+
for (const [k, v] of Object.entries(value))
|
|
360
|
+
if (v !== undefined && v !== null)
|
|
361
|
+
if (typeof v === "object")
|
|
362
|
+
pairs.push(`${k}=${JSON.stringify(v)}`);
|
|
363
|
+
else
|
|
364
|
+
pairs.push(`${k}=${v}`);
|
|
365
|
+
return pairs.join(" ");
|
|
366
|
+
}
|
|
367
|
+
return String(value);
|
|
368
|
+
}
|
|
369
|
+
function formatCost(cost) {
|
|
370
|
+
if (cost < 0.01)
|
|
371
|
+
return `$${cost.toFixed(6)}`;
|
|
372
|
+
if (cost < 1)
|
|
373
|
+
return `$${cost.toFixed(4)}`;
|
|
374
|
+
return `$${cost.toFixed(2)}`;
|
|
375
|
+
}
|
|
376
|
+
function buildAIEntries(ai) {
|
|
377
|
+
const entries = [];
|
|
378
|
+
const headerParts = [];
|
|
379
|
+
if (ai.model) {
|
|
380
|
+
let m = String(ai.model);
|
|
381
|
+
if (ai.provider)
|
|
382
|
+
m += ` (${ai.provider})`;
|
|
383
|
+
headerParts.push(m);
|
|
384
|
+
}
|
|
385
|
+
if (ai.calls)
|
|
386
|
+
headerParts.push(`${ai.calls} call${ai.calls > 1 ? "s" : ""}`);
|
|
387
|
+
if (ai.steps && ai.steps > 1)
|
|
388
|
+
headerParts.push(`${ai.steps} steps`);
|
|
389
|
+
entries.push({
|
|
390
|
+
key: "ai",
|
|
391
|
+
value: headerParts.join(" \xB7 ")
|
|
392
|
+
});
|
|
393
|
+
const inputTokens = ai.inputTokens;
|
|
394
|
+
const outputTokens = ai.outputTokens;
|
|
395
|
+
const totalTokens = ai.totalTokens;
|
|
396
|
+
if (inputTokens !== undefined && outputTokens !== undefined) {
|
|
397
|
+
let tokLine = `${inputTokens} in \u2192 ${outputTokens} out`;
|
|
398
|
+
if (totalTokens)
|
|
399
|
+
tokLine += ` (${totalTokens} total)`;
|
|
400
|
+
const extras = [];
|
|
401
|
+
if (ai.cacheReadTokens)
|
|
402
|
+
extras.push(`${ai.cacheReadTokens} cache read`);
|
|
403
|
+
if (ai.cacheWriteTokens)
|
|
404
|
+
extras.push(`${ai.cacheWriteTokens} cache write`);
|
|
405
|
+
if (ai.reasoningTokens)
|
|
406
|
+
extras.push(`${ai.reasoningTokens} reasoning`);
|
|
407
|
+
if (extras.length)
|
|
408
|
+
tokLine += ` \xB7 ${extras.join(" \xB7 ")}`;
|
|
409
|
+
entries.push({
|
|
410
|
+
key: "ai.tokens",
|
|
411
|
+
value: tokLine
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
const msFirst = ai.msToFirstChunk;
|
|
415
|
+
const msFinish = ai.msToFinish;
|
|
416
|
+
const tps = ai.tokensPerSecond;
|
|
417
|
+
if (msFirst !== undefined || msFinish !== undefined) {
|
|
418
|
+
const parts = [];
|
|
419
|
+
if (msFirst !== undefined)
|
|
420
|
+
parts.push(`${formatDuration(msFirst)} to first chunk`);
|
|
421
|
+
if (msFinish !== undefined)
|
|
422
|
+
parts.push(`${formatDuration(msFinish)} total`);
|
|
423
|
+
let streamLine = parts.join(" \u2192 ");
|
|
424
|
+
if (tps)
|
|
425
|
+
streamLine += ` \xB7 ${tps} tok/s`;
|
|
426
|
+
entries.push({
|
|
427
|
+
key: "ai.streaming",
|
|
428
|
+
value: streamLine
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
if (ai.estimatedCost !== undefined)
|
|
432
|
+
entries.push({
|
|
433
|
+
key: "ai.cost",
|
|
434
|
+
value: formatCost(ai.estimatedCost)
|
|
435
|
+
});
|
|
436
|
+
if (ai.totalDurationMs !== undefined)
|
|
437
|
+
entries.push({
|
|
438
|
+
key: "ai.totalDuration",
|
|
439
|
+
value: formatDuration(ai.totalDurationMs)
|
|
440
|
+
});
|
|
441
|
+
const toolCalls = ai.toolCalls;
|
|
442
|
+
const tools = ai.tools;
|
|
443
|
+
const hasInputs = toolCalls?.length ? typeof toolCalls[0] === "object" : false;
|
|
444
|
+
if (tools?.length) {
|
|
445
|
+
const children = tools.map((t, idx) => {
|
|
446
|
+
const mark = t.success ? "\u2713" : "\u2717";
|
|
447
|
+
let line = `${t.name} ${formatDuration(t.durationMs)} ${mark}`;
|
|
448
|
+
if (t.error)
|
|
449
|
+
line += ` ${t.error}`;
|
|
450
|
+
if (hasInputs && toolCalls && idx < toolCalls.length) {
|
|
451
|
+
const tc = toolCalls[idx];
|
|
452
|
+
const inputStr = typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input);
|
|
453
|
+
const truncated = inputStr.length > 100 ? `${inputStr.slice(0, 100)}\u2026` : inputStr;
|
|
454
|
+
line += ` ${truncated}`;
|
|
455
|
+
}
|
|
456
|
+
return line;
|
|
457
|
+
});
|
|
458
|
+
entries.push({
|
|
459
|
+
key: "ai.tools",
|
|
460
|
+
value: "",
|
|
461
|
+
children
|
|
462
|
+
});
|
|
463
|
+
} else if (toolCalls?.length)
|
|
464
|
+
if (hasInputs) {
|
|
465
|
+
const children = toolCalls.map((tc) => {
|
|
466
|
+
const inputStr = typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input);
|
|
467
|
+
const truncated = inputStr.length > 100 ? `${inputStr.slice(0, 100)}\u2026` : inputStr;
|
|
468
|
+
return `${tc.name}(${truncated})`;
|
|
469
|
+
});
|
|
470
|
+
entries.push({
|
|
471
|
+
key: "ai.tools",
|
|
472
|
+
value: "",
|
|
473
|
+
children
|
|
474
|
+
});
|
|
475
|
+
} else
|
|
476
|
+
entries.push({
|
|
477
|
+
key: "ai.tools",
|
|
478
|
+
value: toolCalls.join(", ")
|
|
479
|
+
});
|
|
480
|
+
const stepsUsage = ai.stepsUsage;
|
|
481
|
+
if (stepsUsage?.length) {
|
|
482
|
+
const allSameModel = stepsUsage.every((s) => s.model === stepsUsage[0].model);
|
|
483
|
+
const children = stepsUsage.map((s) => {
|
|
484
|
+
let line = `${allSameModel ? "" : `${s.model} `}${s.inputTokens} in \u2192 ${s.outputTokens} out`;
|
|
485
|
+
const stepTools = s.toolCalls;
|
|
486
|
+
if (stepTools?.length)
|
|
487
|
+
line += ` [${stepTools.join(", ")}]`;
|
|
488
|
+
return line;
|
|
489
|
+
});
|
|
490
|
+
entries.push({
|
|
491
|
+
key: "ai.steps",
|
|
492
|
+
value: "",
|
|
493
|
+
children
|
|
494
|
+
});
|
|
495
|
+
} else if (ai.steps && ai.steps > 1)
|
|
496
|
+
entries.push({
|
|
497
|
+
key: "ai.steps",
|
|
498
|
+
value: String(ai.steps)
|
|
499
|
+
});
|
|
500
|
+
const embedding = ai.embedding;
|
|
501
|
+
if (embedding) {
|
|
502
|
+
const parts = [];
|
|
503
|
+
if (embedding.model)
|
|
504
|
+
parts.push(String(embedding.model));
|
|
505
|
+
parts.push(`${embedding.tokens} tokens`);
|
|
506
|
+
if (embedding.dimensions)
|
|
507
|
+
parts.push(`${embedding.dimensions}d`);
|
|
508
|
+
if (embedding.count)
|
|
509
|
+
parts.push(`${embedding.count} items`);
|
|
510
|
+
entries.push({
|
|
511
|
+
key: "ai.embedding",
|
|
512
|
+
value: parts.join(" \xB7 ")
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (ai.finishReason)
|
|
516
|
+
entries.push({
|
|
517
|
+
key: "ai.finishReason",
|
|
518
|
+
value: String(ai.finishReason)
|
|
519
|
+
});
|
|
520
|
+
if (ai.error)
|
|
521
|
+
entries.push({
|
|
522
|
+
key: "ai.error",
|
|
523
|
+
value: String(ai.error)
|
|
524
|
+
});
|
|
525
|
+
if (ai.responseId)
|
|
526
|
+
entries.push({
|
|
527
|
+
key: "ai.responseId",
|
|
528
|
+
value: String(ai.responseId)
|
|
529
|
+
});
|
|
530
|
+
return entries;
|
|
531
|
+
}
|
|
532
|
+
function prettyPrintWideEvent(event) {
|
|
533
|
+
const { timestamp, level, service, environment, version, ...rest } = event;
|
|
534
|
+
const ts = timestamp.slice(11, 23);
|
|
535
|
+
const browser = isClient();
|
|
536
|
+
const parts = [];
|
|
537
|
+
const styles = [];
|
|
538
|
+
if (browser) {
|
|
539
|
+
const lc = getCssLevelColor(level);
|
|
540
|
+
parts.push(`%c${ts}%c %c${level.toUpperCase()}%c %c[${escapeFormatString(String(service))}]%c`);
|
|
541
|
+
styles.push(cssColors.dim, cssColors.reset, lc, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
542
|
+
} else {
|
|
543
|
+
const lc = getLevelColor(level);
|
|
544
|
+
parts.push(`${colors.dim}${ts}${colors.reset} ${lc}${level.toUpperCase()}${colors.reset} ${colors.cyan}[${service}]${colors.reset}`);
|
|
545
|
+
}
|
|
546
|
+
if (rest.method && rest.path) {
|
|
547
|
+
parts.push(browser ? ` ${escapeFormatString(String(rest.method))} ${escapeFormatString(String(rest.path))}` : ` ${rest.method} ${rest.path}`);
|
|
548
|
+
delete rest.method;
|
|
549
|
+
delete rest.path;
|
|
550
|
+
}
|
|
551
|
+
if (rest.status) {
|
|
552
|
+
const sc = browser ? rest.status >= 400 ? cssColors.red : cssColors.green : rest.status >= 400 ? colors.red : colors.green;
|
|
553
|
+
if (browser) {
|
|
554
|
+
parts.push(` %c${rest.status}%c`);
|
|
555
|
+
styles.push(sc, cssColors.reset);
|
|
556
|
+
} else
|
|
557
|
+
parts.push(` ${sc}${rest.status}${colors.reset}`);
|
|
558
|
+
delete rest.status;
|
|
559
|
+
}
|
|
560
|
+
if (rest.duration) {
|
|
561
|
+
if (browser) {
|
|
562
|
+
parts.push(` %c${escapeFormatString(`in ${rest.duration}`)}%c`);
|
|
563
|
+
styles.push(cssColors.dim, cssColors.reset);
|
|
564
|
+
} else
|
|
565
|
+
parts.push(` ${colors.dim}in ${rest.duration}${colors.reset}`);
|
|
566
|
+
delete rest.duration;
|
|
567
|
+
}
|
|
568
|
+
console.log(parts.join(""), ...styles);
|
|
569
|
+
const aiData = rest.ai;
|
|
570
|
+
if (aiData && typeof aiData === "object")
|
|
571
|
+
delete rest.ai;
|
|
572
|
+
const restEntries = Object.entries(rest).filter(([_, v]) => v !== undefined);
|
|
573
|
+
const aiEntries = aiData ? buildAIEntries(aiData) : [];
|
|
574
|
+
const allEntries = [...restEntries.map(([key, value]) => ({
|
|
575
|
+
key,
|
|
576
|
+
value: formatValue(value)
|
|
577
|
+
})), ...aiEntries];
|
|
578
|
+
for (let i = 0;i < allEntries.length; i++) {
|
|
579
|
+
const entry = allEntries[i];
|
|
580
|
+
const hasChildren = entry.children && entry.children.length > 0;
|
|
581
|
+
const prefix = i === allEntries.length - 1 && !hasChildren ? "\u2514\u2500" : "\u251C\u2500";
|
|
582
|
+
if (browser) {
|
|
583
|
+
const val = entry.value ? ` ${escapeFormatString(entry.value)}` : "";
|
|
584
|
+
console.log(` %c${prefix}%c %c${escapeFormatString(entry.key)}:%c${val}`, cssColors.dim, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
585
|
+
} else {
|
|
586
|
+
const val = entry.value ? ` ${entry.value}` : "";
|
|
587
|
+
console.log(` ${colors.dim}${prefix}${colors.reset} ${colors.cyan}${entry.key}:${colors.reset}${val}`);
|
|
588
|
+
}
|
|
589
|
+
if (hasChildren) {
|
|
590
|
+
const connector = i === allEntries.length - 1 ? " " : "\u2502";
|
|
591
|
+
for (let j = 0;j < entry.children.length; j++) {
|
|
592
|
+
const child = entry.children[j];
|
|
593
|
+
const childPrefix = j === entry.children.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
594
|
+
if (browser)
|
|
595
|
+
console.log(` %c${connector} ${childPrefix}%c ${escapeFormatString(child)}`, cssColors.dim, cssColors.reset);
|
|
596
|
+
else
|
|
597
|
+
console.log(` ${colors.dim}${connector} ${childPrefix}${colors.reset} ${child}`);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function createLogMethod(level) {
|
|
603
|
+
return function logMethod(tagOrEvent, message) {
|
|
604
|
+
if (typeof tagOrEvent === "string" && message !== undefined)
|
|
605
|
+
emitTaggedLog(level, tagOrEvent, message);
|
|
606
|
+
else if (typeof tagOrEvent === "object")
|
|
607
|
+
emitWideEvent(level, tagOrEvent);
|
|
608
|
+
else
|
|
609
|
+
emitTaggedLog(level, "log", String(tagOrEvent));
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
var _log = {
|
|
613
|
+
info: createLogMethod("info"),
|
|
614
|
+
error: createLogMethod("error"),
|
|
615
|
+
warn: createLogMethod("warn"),
|
|
616
|
+
debug: createLogMethod("debug")
|
|
617
|
+
};
|
|
618
|
+
if (typeof __EVLOG_CONFIG__ !== "undefined")
|
|
619
|
+
initLogger(__EVLOG_CONFIG__);
|
|
620
|
+
// src/link.tsx
|
|
621
|
+
import {
|
|
622
|
+
createContext,
|
|
623
|
+
createElement,
|
|
624
|
+
useCallback,
|
|
625
|
+
useContext,
|
|
626
|
+
useEffect,
|
|
627
|
+
useMemo,
|
|
628
|
+
useRef,
|
|
629
|
+
useState
|
|
630
|
+
} from "react";
|
|
631
|
+
|
|
632
|
+
// src/render/boundaries.tsx
|
|
633
|
+
import { Component, Fragment } from "react";
|
|
634
|
+
|
|
635
|
+
// src/error.ts
|
|
636
|
+
function getPublicErrorMessage(error) {
|
|
637
|
+
const branded = error;
|
|
638
|
+
if (branded?.__furinBrand === "FURIN_NOT_FOUND") {
|
|
639
|
+
return error.message;
|
|
640
|
+
}
|
|
641
|
+
return "Something went wrong";
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/not-found.ts
|
|
645
|
+
var NOT_FOUND_BRAND = "FURIN_NOT_FOUND";
|
|
646
|
+
|
|
647
|
+
class FurinNotFoundError extends Error {
|
|
648
|
+
__furinBrand = NOT_FOUND_BRAND;
|
|
649
|
+
data;
|
|
650
|
+
constructor(options) {
|
|
651
|
+
super(options?.message ?? "");
|
|
652
|
+
this.data = options?.data;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function isNotFoundError(err) {
|
|
656
|
+
return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/render/default-screens.tsx
|
|
660
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
661
|
+
var FONT_SANS = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
|
|
662
|
+
var FONT_MONO = 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace';
|
|
663
|
+
var COLOR_BG = "#000000";
|
|
664
|
+
var COLOR_TEXT = "#ffffff";
|
|
665
|
+
var COLOR_TEXT_DIM = "rgba(255, 255, 255, 0.7)";
|
|
666
|
+
var COLOR_TEXT_MUTED = "rgba(255, 255, 255, 0.45)";
|
|
667
|
+
var COLOR_GRID = "rgba(255, 255, 255, 0.04)";
|
|
668
|
+
var COLOR_BRACKET = "rgba(255, 255, 255, 0.55)";
|
|
669
|
+
var COLOR_DANGER_DIM = "rgba(239, 68, 68, 0.6)";
|
|
670
|
+
var PAGE_STYLE = {
|
|
671
|
+
alignItems: "center",
|
|
672
|
+
backgroundColor: COLOR_BG,
|
|
673
|
+
backgroundImage: `
|
|
674
|
+
linear-gradient(${COLOR_GRID} 1px, transparent 1px),
|
|
675
|
+
linear-gradient(90deg, ${COLOR_GRID} 1px, transparent 1px)
|
|
676
|
+
`,
|
|
677
|
+
backgroundSize: "32px 32px, 32px 32px",
|
|
678
|
+
boxSizing: "border-box",
|
|
679
|
+
color: COLOR_TEXT,
|
|
680
|
+
display: "flex",
|
|
681
|
+
fontFamily: FONT_SANS,
|
|
682
|
+
fontSize: "16px",
|
|
683
|
+
justifyContent: "center",
|
|
684
|
+
lineHeight: 1.5,
|
|
685
|
+
margin: 0,
|
|
686
|
+
minHeight: "100vh",
|
|
687
|
+
padding: "32px",
|
|
688
|
+
width: "100%"
|
|
689
|
+
};
|
|
690
|
+
var FRAME_STYLE = {
|
|
691
|
+
boxSizing: "border-box",
|
|
692
|
+
maxWidth: "880px",
|
|
693
|
+
position: "relative",
|
|
694
|
+
width: "100%"
|
|
695
|
+
};
|
|
696
|
+
var BRACKET_BASE = {
|
|
697
|
+
height: "40px",
|
|
698
|
+
position: "absolute",
|
|
699
|
+
width: "40px"
|
|
700
|
+
};
|
|
701
|
+
function CornerBracket({ corner }) {
|
|
702
|
+
const top = corner === "tl" || corner === "tr";
|
|
703
|
+
const left = corner === "tl" || corner === "bl";
|
|
704
|
+
const style = {
|
|
705
|
+
...BRACKET_BASE,
|
|
706
|
+
[top ? "top" : "bottom"]: 0,
|
|
707
|
+
[left ? "left" : "right"]: 0,
|
|
708
|
+
[`border${top ? "Top" : "Bottom"}`]: `2px solid ${COLOR_BRACKET}`,
|
|
709
|
+
[`border${left ? "Left" : "Right"}`]: `2px solid ${COLOR_BRACKET}`
|
|
710
|
+
};
|
|
711
|
+
return /* @__PURE__ */ jsxDEV("span", {
|
|
712
|
+
"aria-hidden": "true",
|
|
713
|
+
style
|
|
714
|
+
}, undefined, false, undefined, this);
|
|
715
|
+
}
|
|
716
|
+
var CARD_STYLE = {
|
|
717
|
+
boxSizing: "border-box",
|
|
718
|
+
margin: "0 auto",
|
|
719
|
+
maxWidth: "640px",
|
|
720
|
+
padding: "64px 24px",
|
|
721
|
+
textAlign: "center"
|
|
722
|
+
};
|
|
723
|
+
var BADGE_STYLE = {
|
|
724
|
+
border: `1px solid ${COLOR_DANGER_DIM}`,
|
|
725
|
+
color: COLOR_TEXT,
|
|
726
|
+
display: "inline-block",
|
|
727
|
+
fontFamily: FONT_SANS,
|
|
728
|
+
fontSize: "32px",
|
|
729
|
+
fontWeight: 600,
|
|
730
|
+
letterSpacing: "0.08em",
|
|
731
|
+
marginBottom: "16px",
|
|
732
|
+
padding: "12px 36px"
|
|
733
|
+
};
|
|
734
|
+
var NOT_FOUND_BADGE_STYLE = {
|
|
735
|
+
...BADGE_STYLE,
|
|
736
|
+
border: 0,
|
|
737
|
+
padding: 0
|
|
738
|
+
};
|
|
739
|
+
var HEADING_STYLE = {
|
|
740
|
+
color: COLOR_TEXT,
|
|
741
|
+
fontFamily: FONT_SANS,
|
|
742
|
+
fontSize: "24px",
|
|
743
|
+
fontWeight: 600,
|
|
744
|
+
margin: "0 0 24px 0"
|
|
745
|
+
};
|
|
746
|
+
var CODE_BOX_STYLE = {
|
|
747
|
+
color: COLOR_TEXT_DIM,
|
|
748
|
+
display: "inline-block",
|
|
749
|
+
fontFamily: FONT_MONO,
|
|
750
|
+
fontSize: "13px",
|
|
751
|
+
letterSpacing: "0.02em",
|
|
752
|
+
margin: "0 0 32px 0",
|
|
753
|
+
padding: "8px 0"
|
|
754
|
+
};
|
|
755
|
+
var CODE_LABEL_STYLE = {
|
|
756
|
+
color: COLOR_TEXT_MUTED,
|
|
757
|
+
marginRight: "10px",
|
|
758
|
+
textTransform: "uppercase"
|
|
759
|
+
};
|
|
760
|
+
var DESCRIPTION_WRAPPER_STYLE = {
|
|
761
|
+
color: COLOR_TEXT_DIM,
|
|
762
|
+
fontSize: "15px",
|
|
763
|
+
margin: "0 auto 40px auto",
|
|
764
|
+
maxWidth: "440px",
|
|
765
|
+
padding: 0,
|
|
766
|
+
textAlign: "center"
|
|
767
|
+
};
|
|
768
|
+
var ACTIONS_STYLE = {
|
|
769
|
+
display: "flex",
|
|
770
|
+
flexWrap: "wrap",
|
|
771
|
+
gap: "16px",
|
|
772
|
+
justifyContent: "center"
|
|
773
|
+
};
|
|
774
|
+
var BUTTON_BASE = {
|
|
775
|
+
border: 0,
|
|
776
|
+
cursor: "pointer",
|
|
777
|
+
display: "inline-flex",
|
|
778
|
+
fontFamily: FONT_SANS,
|
|
779
|
+
fontSize: "14px",
|
|
780
|
+
fontWeight: 500,
|
|
781
|
+
lineHeight: 1,
|
|
782
|
+
minWidth: "120px",
|
|
783
|
+
padding: "10px 16px",
|
|
784
|
+
textAlign: "center",
|
|
785
|
+
textDecoration: "none",
|
|
786
|
+
transition: "background-color 120ms ease, color 120ms ease, opacity 120ms ease",
|
|
787
|
+
appearance: "none",
|
|
788
|
+
alignItems: "center",
|
|
789
|
+
justifyContent: "center",
|
|
790
|
+
boxSizing: "border-box"
|
|
791
|
+
};
|
|
792
|
+
var BUTTON_PRIMARY = {
|
|
793
|
+
...BUTTON_BASE,
|
|
794
|
+
backgroundColor: COLOR_TEXT,
|
|
795
|
+
border: `1px solid ${COLOR_TEXT}`,
|
|
796
|
+
boxShadow: "0 10px 24px rgba(255, 255, 255, 0.08)",
|
|
797
|
+
color: COLOR_BG,
|
|
798
|
+
fontWeight: 600
|
|
799
|
+
};
|
|
800
|
+
var BUTTON_SECONDARY = {
|
|
801
|
+
...BUTTON_BASE,
|
|
802
|
+
backgroundColor: "transparent",
|
|
803
|
+
border: "1px solid rgba(255, 255, 255, 0.22)",
|
|
804
|
+
color: COLOR_TEXT_DIM
|
|
805
|
+
};
|
|
806
|
+
var DIVIDER_STYLE = {
|
|
807
|
+
backgroundColor: "rgba(255, 255, 255, 0.12)",
|
|
808
|
+
border: 0,
|
|
809
|
+
height: "1px",
|
|
810
|
+
margin: "0 0 40px 0",
|
|
811
|
+
width: "100%"
|
|
812
|
+
};
|
|
813
|
+
var RESET_CSS = `
|
|
814
|
+
html, body {
|
|
815
|
+
margin: 0;
|
|
816
|
+
padding: 0;
|
|
817
|
+
background-color: ${COLOR_BG};
|
|
818
|
+
overscroll-behavior: none;
|
|
819
|
+
}
|
|
820
|
+
`;
|
|
821
|
+
function ScreenFrame({ badge, children }) {
|
|
822
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
823
|
+
style: PAGE_STYLE,
|
|
824
|
+
children: [
|
|
825
|
+
/* @__PURE__ */ jsxDEV("style", {
|
|
826
|
+
dangerouslySetInnerHTML: { __html: RESET_CSS }
|
|
827
|
+
}, undefined, false, undefined, this),
|
|
828
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
829
|
+
style: FRAME_STYLE,
|
|
830
|
+
children: [
|
|
831
|
+
/* @__PURE__ */ jsxDEV(CornerBracket, {
|
|
832
|
+
corner: "tl"
|
|
833
|
+
}, undefined, false, undefined, this),
|
|
834
|
+
/* @__PURE__ */ jsxDEV(CornerBracket, {
|
|
835
|
+
corner: "tr"
|
|
836
|
+
}, undefined, false, undefined, this),
|
|
837
|
+
/* @__PURE__ */ jsxDEV(CornerBracket, {
|
|
838
|
+
corner: "bl"
|
|
839
|
+
}, undefined, false, undefined, this),
|
|
840
|
+
/* @__PURE__ */ jsxDEV(CornerBracket, {
|
|
841
|
+
corner: "br"
|
|
842
|
+
}, undefined, false, undefined, this),
|
|
843
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
844
|
+
style: CARD_STYLE,
|
|
845
|
+
children: [
|
|
846
|
+
badge,
|
|
847
|
+
/* @__PURE__ */ jsxDEV("hr", {
|
|
848
|
+
style: DIVIDER_STYLE
|
|
849
|
+
}, undefined, false, undefined, this),
|
|
850
|
+
children
|
|
851
|
+
]
|
|
852
|
+
}, undefined, true, undefined, this)
|
|
853
|
+
]
|
|
854
|
+
}, undefined, true, undefined, this)
|
|
855
|
+
]
|
|
856
|
+
}, undefined, true, undefined, this);
|
|
857
|
+
}
|
|
858
|
+
function DefaultErrorScreen({ message, digest, reset }) {
|
|
859
|
+
return /* @__PURE__ */ jsxDEV(ScreenFrame, {
|
|
860
|
+
badge: /* @__PURE__ */ jsxDEV("div", {
|
|
861
|
+
style: BADGE_STYLE,
|
|
862
|
+
children: "500 \u2014 ERROR"
|
|
863
|
+
}, undefined, false, undefined, this),
|
|
864
|
+
children: [
|
|
865
|
+
/* @__PURE__ */ jsxDEV("h1", {
|
|
866
|
+
style: HEADING_STYLE,
|
|
867
|
+
children: "Something went wrong"
|
|
868
|
+
}, undefined, false, undefined, this),
|
|
869
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
870
|
+
style: CODE_BOX_STYLE,
|
|
871
|
+
children: [
|
|
872
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
873
|
+
style: CODE_LABEL_STYLE,
|
|
874
|
+
children: "CODE:"
|
|
875
|
+
}, undefined, false, undefined, this),
|
|
876
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
877
|
+
children: digest
|
|
878
|
+
}, undefined, false, undefined, this)
|
|
879
|
+
]
|
|
880
|
+
}, undefined, true, undefined, this),
|
|
881
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
882
|
+
style: DESCRIPTION_WRAPPER_STYLE,
|
|
883
|
+
children: message ? message : "We encountered an unexpected error. Please try again or return to the home page."
|
|
884
|
+
}, undefined, false, undefined, this),
|
|
885
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
886
|
+
style: ACTIONS_STYLE,
|
|
887
|
+
children: [
|
|
888
|
+
/* @__PURE__ */ jsxDEV(Link, {
|
|
889
|
+
style: BUTTON_PRIMARY,
|
|
890
|
+
to: "/",
|
|
891
|
+
children: "Go Home"
|
|
892
|
+
}, undefined, false, undefined, this),
|
|
893
|
+
/* @__PURE__ */ jsxDEV("button", {
|
|
894
|
+
onClick: reset,
|
|
895
|
+
style: BUTTON_SECONDARY,
|
|
896
|
+
type: "button",
|
|
897
|
+
children: "Try again"
|
|
898
|
+
}, undefined, false, undefined, this)
|
|
899
|
+
]
|
|
900
|
+
}, undefined, true, undefined, this)
|
|
901
|
+
]
|
|
902
|
+
}, undefined, true, undefined, this);
|
|
903
|
+
}
|
|
904
|
+
function DefaultNotFoundScreen({ message }) {
|
|
905
|
+
return /* @__PURE__ */ jsxDEV(ScreenFrame, {
|
|
906
|
+
badge: /* @__PURE__ */ jsxDEV("div", {
|
|
907
|
+
style: NOT_FOUND_BADGE_STYLE,
|
|
908
|
+
children: "404 \u2014 NOT FOUND"
|
|
909
|
+
}, undefined, false, undefined, this),
|
|
910
|
+
children: [
|
|
911
|
+
/* @__PURE__ */ jsxDEV("h1", {
|
|
912
|
+
style: HEADING_STYLE,
|
|
913
|
+
children: "This page does not exist"
|
|
914
|
+
}, undefined, false, undefined, this),
|
|
915
|
+
/* @__PURE__ */ jsxDEV("p", {
|
|
916
|
+
style: DESCRIPTION_WRAPPER_STYLE,
|
|
917
|
+
children: message ? message : "The page you are looking for could not be found. It may have been moved or removed."
|
|
918
|
+
}, undefined, false, undefined, this),
|
|
919
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
920
|
+
style: ACTIONS_STYLE,
|
|
921
|
+
children: /* @__PURE__ */ jsxDEV(Link, {
|
|
922
|
+
style: BUTTON_PRIMARY,
|
|
923
|
+
to: "/",
|
|
924
|
+
children: "Go Home"
|
|
925
|
+
}, undefined, false, undefined, this)
|
|
926
|
+
}, undefined, false, undefined, this)
|
|
927
|
+
]
|
|
928
|
+
}, undefined, true, undefined, this);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// src/render/digest.ts
|
|
932
|
+
function computeErrorDigest(err) {
|
|
933
|
+
let message = "";
|
|
934
|
+
let stack = "";
|
|
935
|
+
if (err instanceof Error) {
|
|
936
|
+
message = err.message;
|
|
937
|
+
stack = err.stack ?? "";
|
|
938
|
+
} else if (typeof err === "string") {
|
|
939
|
+
message = err;
|
|
940
|
+
} else {
|
|
941
|
+
try {
|
|
942
|
+
message = JSON.stringify(err) ?? String(err);
|
|
943
|
+
} catch {
|
|
944
|
+
message = String(err);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
const input = `${message}
|
|
948
|
+
${stack}`;
|
|
949
|
+
const hash = cyrb53(input);
|
|
950
|
+
const hex = hash.toString(16).padStart(14, "0");
|
|
951
|
+
return hex.slice(0, 10);
|
|
952
|
+
}
|
|
953
|
+
function cyrb53(input) {
|
|
954
|
+
let h1 = 3735928559;
|
|
955
|
+
let h2 = 1103547991;
|
|
956
|
+
for (let i = 0;i < input.length; i++) {
|
|
957
|
+
const ch = input.charCodeAt(i);
|
|
958
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
959
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
960
|
+
}
|
|
961
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
962
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
963
|
+
return 4294967296 * (2097151 & h2) + (4294967295 & h1);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// src/render/boundaries.tsx
|
|
967
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
968
|
+
var DefaultErrorFallback = ({ error, reset }) => /* @__PURE__ */ jsxDEV2(DefaultErrorScreen, {
|
|
969
|
+
digest: error.digest,
|
|
970
|
+
message: error.message,
|
|
971
|
+
reset
|
|
972
|
+
}, undefined, false, undefined, this);
|
|
973
|
+
var DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV2(DefaultNotFoundScreen, {
|
|
974
|
+
message: error.message
|
|
975
|
+
}, undefined, false, undefined, this);
|
|
976
|
+
var SERVER_RESET_NOOP = () => {};
|
|
977
|
+
|
|
978
|
+
class FurinErrorBoundary extends Component {
|
|
979
|
+
state = {
|
|
980
|
+
digest: null,
|
|
981
|
+
epoch: 0,
|
|
982
|
+
error: null
|
|
983
|
+
};
|
|
984
|
+
static getDerivedStateFromError(error) {
|
|
985
|
+
return { digest: computeErrorDigest(error), error };
|
|
986
|
+
}
|
|
987
|
+
componentDidUpdate(prevProps) {
|
|
988
|
+
if (prevProps.resetKey !== this.props.resetKey && this.state.error) {
|
|
989
|
+
this.reset();
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
reset = () => {
|
|
993
|
+
this.setState((s) => ({ digest: null, epoch: s.epoch + 1, error: null }), () => {
|
|
994
|
+
this.props.onReset?.();
|
|
995
|
+
});
|
|
996
|
+
};
|
|
997
|
+
render() {
|
|
998
|
+
const { error, epoch, digest } = this.state;
|
|
999
|
+
if (error) {
|
|
1000
|
+
if (isNotFoundError(error)) {
|
|
1001
|
+
throw error;
|
|
1002
|
+
}
|
|
1003
|
+
const Fallback = this.props.fallback ?? DefaultErrorFallback;
|
|
1004
|
+
const finalDigest = digest ?? this.props.digest ?? computeErrorDigest(error);
|
|
1005
|
+
const message = this.props.fallback ? error.message : getPublicErrorMessage(error);
|
|
1006
|
+
return /* @__PURE__ */ jsxDEV2(Fallback, {
|
|
1007
|
+
error: { message, digest: finalDigest },
|
|
1008
|
+
reset: typeof window === "undefined" ? SERVER_RESET_NOOP : this.reset
|
|
1009
|
+
}, undefined, false, undefined, this);
|
|
1010
|
+
}
|
|
1011
|
+
return /* @__PURE__ */ jsxDEV2(Fragment, {
|
|
1012
|
+
children: this.props.children
|
|
1013
|
+
}, epoch, false, undefined, this);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
class FurinNotFoundBoundary extends Component {
|
|
1018
|
+
state = { epoch: 0, error: null };
|
|
1019
|
+
static getDerivedStateFromError(error) {
|
|
1020
|
+
return { error };
|
|
1021
|
+
}
|
|
1022
|
+
componentDidUpdate(prevProps) {
|
|
1023
|
+
if (prevProps.resetKey !== this.props.resetKey && this.state.error) {
|
|
1024
|
+
this.setState((s) => ({ error: null, epoch: s.epoch + 1 }));
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
render() {
|
|
1028
|
+
const { error, epoch } = this.state;
|
|
1029
|
+
if (error) {
|
|
1030
|
+
if (!isNotFoundError(error)) {
|
|
1031
|
+
throw error;
|
|
1032
|
+
}
|
|
1033
|
+
const Fallback = this.props.fallback ?? DefaultNotFoundFallback;
|
|
1034
|
+
return /* @__PURE__ */ jsxDEV2(Fallback, {
|
|
1035
|
+
error: { message: error.message, data: error.data }
|
|
1036
|
+
}, undefined, false, undefined, this);
|
|
1037
|
+
}
|
|
1038
|
+
return /* @__PURE__ */ jsxDEV2(Fragment, {
|
|
1039
|
+
children: this.props.children
|
|
1040
|
+
}, epoch, false, undefined, this);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/link.tsx
|
|
1045
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
1046
|
+
function buildHref(to, search, hash) {
|
|
1047
|
+
let url = to;
|
|
1048
|
+
if (search && Object.keys(search).length > 0) {
|
|
1049
|
+
const params = new URLSearchParams;
|
|
1050
|
+
for (const [k, v] of Object.entries(search)) {
|
|
1051
|
+
if (v != null) {
|
|
1052
|
+
params.set(k, String(v));
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
const qs = params.toString();
|
|
1056
|
+
if (qs) {
|
|
1057
|
+
url += `?${qs}`;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (hash) {
|
|
1061
|
+
url += `#${hash}`;
|
|
1062
|
+
}
|
|
1063
|
+
return url;
|
|
1064
|
+
}
|
|
1065
|
+
function applyRevalidateHeader(headers, invalidate) {
|
|
1066
|
+
const headerValue = headers.get("x-furin-revalidate");
|
|
1067
|
+
if (!headerValue) {
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
for (const entry of headerValue.split(",")) {
|
|
1071
|
+
const trimmed = entry.trim();
|
|
1072
|
+
if (!trimmed) {
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
if (trimmed.endsWith(":layout")) {
|
|
1076
|
+
invalidate(trimmed.slice(0, -":layout".length), "layout");
|
|
1077
|
+
} else {
|
|
1078
|
+
invalidate(trimmed, "page");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
function shouldAutoRefreshPath(currentPath, invalidations) {
|
|
1083
|
+
const normalizedCurrent = currentPath.split("?")[0] ?? currentPath;
|
|
1084
|
+
return invalidations.some(({ path, type }) => {
|
|
1085
|
+
if (type === "page") {
|
|
1086
|
+
return path === normalizedCurrent;
|
|
1087
|
+
}
|
|
1088
|
+
const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
|
|
1089
|
+
return normalizedCurrent === path || normalizedCurrent.startsWith(prefix);
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
var RouterContext = createContext(null);
|
|
1093
|
+
function useRouter() {
|
|
1094
|
+
return useContext(RouterContext) ?? {
|
|
1095
|
+
basePath: "",
|
|
1096
|
+
currentHref: "/",
|
|
1097
|
+
navigate: (href) => {
|
|
1098
|
+
window.location.href = href;
|
|
1099
|
+
return Promise.resolve();
|
|
1100
|
+
},
|
|
1101
|
+
prefetch: () => {},
|
|
1102
|
+
invalidatePrefetch: () => {},
|
|
1103
|
+
refresh: () => {
|
|
1104
|
+
window.location.reload();
|
|
1105
|
+
return Promise.resolve();
|
|
1106
|
+
},
|
|
1107
|
+
isNavigating: false,
|
|
1108
|
+
defaultPreload: "intent",
|
|
1109
|
+
defaultPreloadDelay: 50,
|
|
1110
|
+
defaultPreloadStaleTime: 30000
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
function shouldRefetch(entry) {
|
|
1114
|
+
return Date.now() - entry.createdAt > entry.staleTime;
|
|
1115
|
+
}
|
|
1116
|
+
var HASH_FRAGMENT_RE = /#.*$/;
|
|
1117
|
+
function stripHashFromHref(href) {
|
|
1118
|
+
return href.replace(HASH_FRAGMENT_RE, "");
|
|
1119
|
+
}
|
|
1120
|
+
function classifySpaResponse(status, data) {
|
|
1121
|
+
if (!data) {
|
|
1122
|
+
return { kind: "bail" };
|
|
1123
|
+
}
|
|
1124
|
+
if ((status >= 200 && status < 300 || status === 404) && data.__furinStatus === 404) {
|
|
1125
|
+
const notFound = data.__furinNotFound;
|
|
1126
|
+
return { kind: "not-found", error: notFound ?? {} };
|
|
1127
|
+
}
|
|
1128
|
+
if (status >= 200 && status < 300) {
|
|
1129
|
+
return { kind: "ok" };
|
|
1130
|
+
}
|
|
1131
|
+
return { kind: "bail" };
|
|
1132
|
+
}
|
|
1133
|
+
function pickDeepestNotFound(boundaries) {
|
|
1134
|
+
if (!boundaries) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
for (let i = boundaries.length - 1;i >= 0; i--) {
|
|
1138
|
+
const seg = boundaries[i];
|
|
1139
|
+
if (seg?.notFound) {
|
|
1140
|
+
return seg.notFound;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
var DefaultClientNotFoundFallback = ({ error }) => createElement(DefaultNotFoundScreen, { message: error.message });
|
|
1146
|
+
function buildNotFoundPageElement(boundaries, error) {
|
|
1147
|
+
const Fallback = pickDeepestNotFound(boundaries) ?? DefaultClientNotFoundFallback;
|
|
1148
|
+
return createElement(Fallback, { error });
|
|
1149
|
+
}
|
|
1150
|
+
function buildRouterTree(context, pageElement, options) {
|
|
1151
|
+
return /* @__PURE__ */ jsxDEV3(FurinErrorBoundary, {
|
|
1152
|
+
...options,
|
|
1153
|
+
children: /* @__PURE__ */ jsxDEV3(RouterContext.Provider, {
|
|
1154
|
+
value: context,
|
|
1155
|
+
children: pageElement
|
|
1156
|
+
}, undefined, false, undefined, this)
|
|
1157
|
+
}, undefined, false, undefined, this);
|
|
1158
|
+
}
|
|
1159
|
+
function wrapPageBoundaries(inner, segment, options) {
|
|
1160
|
+
if (!segment) {
|
|
1161
|
+
return inner;
|
|
1162
|
+
}
|
|
1163
|
+
let wrapped = inner;
|
|
1164
|
+
if (segment.notFound) {
|
|
1165
|
+
wrapped = /* @__PURE__ */ jsxDEV3(FurinNotFoundBoundary, {
|
|
1166
|
+
fallback: segment.notFound,
|
|
1167
|
+
resetKey: options?.resetKey,
|
|
1168
|
+
children: wrapped
|
|
1169
|
+
}, undefined, false, undefined, this);
|
|
1170
|
+
}
|
|
1171
|
+
if (segment.error) {
|
|
1172
|
+
wrapped = /* @__PURE__ */ jsxDEV3(FurinErrorBoundary, {
|
|
1173
|
+
fallback: segment.error,
|
|
1174
|
+
onReset: options?.onReset,
|
|
1175
|
+
resetKey: options?.resetKey,
|
|
1176
|
+
children: wrapped
|
|
1177
|
+
}, undefined, false, undefined, this);
|
|
1178
|
+
}
|
|
1179
|
+
return wrapped;
|
|
1180
|
+
}
|
|
1181
|
+
function buildPageElement(match, root, data, options) {
|
|
1182
|
+
let element = createElement(match.component, data);
|
|
1183
|
+
const allLayouts = [];
|
|
1184
|
+
let current = match.pageRoute;
|
|
1185
|
+
while (current) {
|
|
1186
|
+
if (current.layout) {
|
|
1187
|
+
allLayouts.unshift(current.layout);
|
|
1188
|
+
}
|
|
1189
|
+
current = current.parent;
|
|
1190
|
+
}
|
|
1191
|
+
const layouts = root ? allLayouts.slice(1) : allLayouts;
|
|
1192
|
+
const byDepth = new Map;
|
|
1193
|
+
for (const segment of match.segmentBoundaries ?? []) {
|
|
1194
|
+
byDepth.set(segment.depth, segment);
|
|
1195
|
+
}
|
|
1196
|
+
for (let i = layouts.length - 1;i >= 0; i--) {
|
|
1197
|
+
element = wrapPageBoundaries(element, byDepth.get(i + 1), options);
|
|
1198
|
+
const Layout = layouts[i];
|
|
1199
|
+
if (Layout) {
|
|
1200
|
+
element = createElement(Layout, { ...data }, element);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
element = wrapPageBoundaries(element, byDepth.get(0), options);
|
|
1204
|
+
if (root?.layout) {
|
|
1205
|
+
element = createElement(root.layout, { ...data }, element);
|
|
1206
|
+
}
|
|
1207
|
+
return element;
|
|
1208
|
+
}
|
|
1209
|
+
function handleScrollRestoration(href, navigationToken, navVersion) {
|
|
1210
|
+
const destUrl = new URL(href, window.location.origin);
|
|
1211
|
+
if (destUrl.hash) {
|
|
1212
|
+
const id = decodeURIComponent(destUrl.hash.slice(1));
|
|
1213
|
+
const scrollToHashTarget = () => {
|
|
1214
|
+
if (navVersion.current !== navigationToken) {
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const element = document.getElementById(id);
|
|
1218
|
+
if (element) {
|
|
1219
|
+
element.scrollIntoView({ behavior: "instant", block: "start" });
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
window.requestAnimationFrame(() => {
|
|
1223
|
+
scrollToHashTarget();
|
|
1224
|
+
if (document.getElementById(id)) {
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
window.requestAnimationFrame(() => {
|
|
1228
|
+
scrollToHashTarget();
|
|
1229
|
+
});
|
|
1230
|
+
});
|
|
1231
|
+
} else {
|
|
1232
|
+
window.scrollTo({ top: 0, behavior: "instant" });
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
var SCROLL_STORAGE_KEY = "__furin_scroll__";
|
|
1236
|
+
function getHistoryKey(state) {
|
|
1237
|
+
return state?._furinKey;
|
|
1238
|
+
}
|
|
1239
|
+
function generateHistoryKey() {
|
|
1240
|
+
return Math.random().toString(36).slice(2, 9);
|
|
1241
|
+
}
|
|
1242
|
+
function saveScrollPosition(key) {
|
|
1243
|
+
try {
|
|
1244
|
+
const raw = sessionStorage.getItem(SCROLL_STORAGE_KEY);
|
|
1245
|
+
const positions = raw ? JSON.parse(raw) : {};
|
|
1246
|
+
positions[key] = window.scrollY;
|
|
1247
|
+
const keys = Object.keys(positions);
|
|
1248
|
+
if (keys.length > 50) {
|
|
1249
|
+
delete positions[keys[0]];
|
|
1250
|
+
}
|
|
1251
|
+
sessionStorage.setItem(SCROLL_STORAGE_KEY, JSON.stringify(positions));
|
|
1252
|
+
} catch {}
|
|
1253
|
+
}
|
|
1254
|
+
function restoreScrollPosition(key, token, version) {
|
|
1255
|
+
try {
|
|
1256
|
+
const raw = sessionStorage.getItem(SCROLL_STORAGE_KEY);
|
|
1257
|
+
const positions = raw ? JSON.parse(raw) : {};
|
|
1258
|
+
const y = positions[key] ?? 0;
|
|
1259
|
+
window.requestAnimationFrame(() => {
|
|
1260
|
+
window.requestAnimationFrame(() => {
|
|
1261
|
+
if (version.current !== token) {
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
window.scrollTo({ top: y, behavior: "instant" });
|
|
1265
|
+
});
|
|
1266
|
+
});
|
|
1267
|
+
} catch {
|
|
1268
|
+
window.scrollTo({ top: 0, behavior: "instant" });
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function isStaleDeployResponse(res) {
|
|
1272
|
+
const serverBuildId = res.headers.get("x-furin-build-id");
|
|
1273
|
+
if (!serverBuildId) {
|
|
1274
|
+
return false;
|
|
1275
|
+
}
|
|
1276
|
+
const metaEl = typeof document === "undefined" ? null : document.querySelector('meta[name="furin-build-id"]');
|
|
1277
|
+
const clientBuildId = metaEl?.content;
|
|
1278
|
+
return Boolean(clientBuildId && serverBuildId !== clientBuildId);
|
|
1279
|
+
}
|
|
1280
|
+
async function parsePageResponse(res, basePath) {
|
|
1281
|
+
let finalHref;
|
|
1282
|
+
if (res.redirected) {
|
|
1283
|
+
const final = new URL(res.url);
|
|
1284
|
+
finalHref = toLogical(final.pathname, basePath) + final.search;
|
|
1285
|
+
}
|
|
1286
|
+
const html = await res.text();
|
|
1287
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
1288
|
+
const dataEl = doc.getElementById("__FURIN_DATA__");
|
|
1289
|
+
const data = dataEl ? JSON.parse(dataEl.textContent || "{}") : null;
|
|
1290
|
+
return { data, finalHref, title: doc.title };
|
|
1291
|
+
}
|
|
1292
|
+
function toLogical(physicalPathname, basePath) {
|
|
1293
|
+
if (basePath && physicalPathname.startsWith(basePath) && (physicalPathname.length === basePath.length || physicalPathname[basePath.length] === "/")) {
|
|
1294
|
+
return physicalPathname.slice(basePath.length) || "/";
|
|
1295
|
+
}
|
|
1296
|
+
return physicalPathname;
|
|
1297
|
+
}
|
|
1298
|
+
function RouterProvider({
|
|
1299
|
+
routes,
|
|
1300
|
+
root,
|
|
1301
|
+
initialMatch,
|
|
1302
|
+
initialData,
|
|
1303
|
+
initialDigest,
|
|
1304
|
+
initialNotFound,
|
|
1305
|
+
autoRefresh = true,
|
|
1306
|
+
basePath = "",
|
|
1307
|
+
defaultPreload = "intent",
|
|
1308
|
+
defaultPreloadDelay = 50,
|
|
1309
|
+
defaultPreloadStaleTime = 30000,
|
|
1310
|
+
prefetchCacheSize = 50
|
|
1311
|
+
}) {
|
|
1312
|
+
const [state, setState] = useState(() => ({
|
|
1313
|
+
match: initialMatch,
|
|
1314
|
+
data: initialData,
|
|
1315
|
+
notFound: initialNotFound
|
|
1316
|
+
}));
|
|
1317
|
+
const [isNavigating, setIsNavigating] = useState(false);
|
|
1318
|
+
const [currentHref, setCurrentHref] = useState(() => {
|
|
1319
|
+
if (typeof window === "undefined") {
|
|
1320
|
+
return "/";
|
|
1321
|
+
}
|
|
1322
|
+
return toLogical(window.location.pathname, basePath) + window.location.search;
|
|
1323
|
+
});
|
|
1324
|
+
const prefetchCache = useRef(new Map);
|
|
1325
|
+
const navVersion = useRef(0);
|
|
1326
|
+
const currentMatchRef = useRef(initialMatch);
|
|
1327
|
+
const rootBoundaries = useMemo(() => {
|
|
1328
|
+
for (const route of routes) {
|
|
1329
|
+
const depth0 = route.segmentBoundaries?.find((b) => b.depth === 0);
|
|
1330
|
+
if (depth0) {
|
|
1331
|
+
return [depth0];
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
return;
|
|
1335
|
+
}, [routes]);
|
|
1336
|
+
const fetchPageState = useCallback(async (logicalHref) => {
|
|
1337
|
+
try {
|
|
1338
|
+
const physicalHref = basePath + logicalHref;
|
|
1339
|
+
const url = new URL(physicalHref, window.location.origin);
|
|
1340
|
+
const logicalPathname = toLogical(url.pathname, basePath);
|
|
1341
|
+
const match = routes.find((r) => r.regex.test(logicalPathname));
|
|
1342
|
+
if (!match) {
|
|
1343
|
+
const res2 = await fetch(physicalHref);
|
|
1344
|
+
if (isStaleDeployResponse(res2)) {
|
|
1345
|
+
window.location.href = physicalHref;
|
|
1346
|
+
return null;
|
|
1347
|
+
}
|
|
1348
|
+
const { data: data2, finalHref: finalHref2, title: title2 } = await parsePageResponse(res2, basePath);
|
|
1349
|
+
const kind2 = classifySpaResponse(res2.status, data2);
|
|
1350
|
+
if (kind2.kind !== "not-found") {
|
|
1351
|
+
return null;
|
|
1352
|
+
}
|
|
1353
|
+
const { __furinStatus: _s, __furinNotFound: _n, ...cleanData } = data2 ?? {};
|
|
1354
|
+
return {
|
|
1355
|
+
match: currentMatchRef.current,
|
|
1356
|
+
data: cleanData,
|
|
1357
|
+
title: title2,
|
|
1358
|
+
finalHref: finalHref2,
|
|
1359
|
+
notFound: kind2.error,
|
|
1360
|
+
notFoundBoundaries: rootBoundaries
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
const [res, loadedMod] = await Promise.all([fetch(physicalHref), match.load()]);
|
|
1364
|
+
if (isStaleDeployResponse(res)) {
|
|
1365
|
+
window.location.href = physicalHref;
|
|
1366
|
+
return null;
|
|
1367
|
+
}
|
|
1368
|
+
const { data, finalHref, title } = await parsePageResponse(res, basePath);
|
|
1369
|
+
const kind = classifySpaResponse(res.status, data);
|
|
1370
|
+
if (kind.kind === "bail") {
|
|
1371
|
+
_log.warn({ action: "navigate_server_error", href: physicalHref, status: res.status });
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
const loadedMatch = {
|
|
1375
|
+
...match,
|
|
1376
|
+
component: loadedMod.default.component,
|
|
1377
|
+
pageRoute: loadedMod.default._route
|
|
1378
|
+
};
|
|
1379
|
+
if (kind.kind === "not-found") {
|
|
1380
|
+
const { __furinStatus, __furinNotFound, ...cleanData } = data ?? {};
|
|
1381
|
+
return {
|
|
1382
|
+
match: loadedMatch,
|
|
1383
|
+
data: cleanData,
|
|
1384
|
+
title,
|
|
1385
|
+
finalHref,
|
|
1386
|
+
notFound: kind.error
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
return { match: loadedMatch, data: data ?? {}, title, finalHref };
|
|
1390
|
+
} catch (err) {
|
|
1391
|
+
_log.error({ action: "navigate_failed", href: basePath + logicalHref, error: String(err) });
|
|
1392
|
+
return null;
|
|
1393
|
+
}
|
|
1394
|
+
}, [routes, basePath, rootBoundaries]);
|
|
1395
|
+
const invalidatePrefetch = useCallback((path, type = "page") => {
|
|
1396
|
+
const normalizedPath = stripHashFromHref(path);
|
|
1397
|
+
if (type === "page") {
|
|
1398
|
+
for (const key of [...prefetchCache.current.keys()]) {
|
|
1399
|
+
if (stripHashFromHref(key) === normalizedPath) {
|
|
1400
|
+
prefetchCache.current.delete(key);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
const prefix = normalizedPath === "/" || normalizedPath.endsWith("/") ? normalizedPath : `${normalizedPath}/`;
|
|
1406
|
+
for (const key of [...prefetchCache.current.keys()]) {
|
|
1407
|
+
const normalizedKey = stripHashFromHref(key);
|
|
1408
|
+
if (normalizedKey === normalizedPath || normalizedKey.startsWith(prefix)) {
|
|
1409
|
+
prefetchCache.current.delete(key);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}, []);
|
|
1413
|
+
const prefetch = useCallback((href, opts) => {
|
|
1414
|
+
const staleTime = opts?.staleTime ?? defaultPreloadStaleTime;
|
|
1415
|
+
const existing = prefetchCache.current.get(href);
|
|
1416
|
+
if (existing && !shouldRefetch(existing)) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
prefetchCache.current.set(href, {
|
|
1420
|
+
promise: fetchPageState(href),
|
|
1421
|
+
createdAt: Date.now(),
|
|
1422
|
+
staleTime
|
|
1423
|
+
});
|
|
1424
|
+
if (prefetchCache.current.size > prefetchCacheSize) {
|
|
1425
|
+
const oldest = prefetchCache.current.keys().next().value;
|
|
1426
|
+
prefetchCache.current.delete(oldest);
|
|
1427
|
+
}
|
|
1428
|
+
}, [fetchPageState, defaultPreloadStaleTime, prefetchCacheSize]);
|
|
1429
|
+
const navigate = useCallback(async (logicalHref, opts) => {
|
|
1430
|
+
prefetch(logicalHref);
|
|
1431
|
+
const myVersion = ++navVersion.current;
|
|
1432
|
+
setIsNavigating(true);
|
|
1433
|
+
try {
|
|
1434
|
+
const newState = await prefetchCache.current.get(logicalHref)?.promise;
|
|
1435
|
+
if (navVersion.current !== myVersion) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
if (!newState) {
|
|
1439
|
+
_log.warn({
|
|
1440
|
+
action: "navigate_fallback",
|
|
1441
|
+
href: logicalHref,
|
|
1442
|
+
reason: "prefetch_returned_null"
|
|
1443
|
+
});
|
|
1444
|
+
window.location.href = basePath + logicalHref;
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
currentMatchRef.current = newState.match;
|
|
1448
|
+
setState(newState);
|
|
1449
|
+
if (newState.title) {
|
|
1450
|
+
document.title = newState.title;
|
|
1451
|
+
}
|
|
1452
|
+
const effectiveLogical = newState.finalHref ?? logicalHref;
|
|
1453
|
+
const physicalEffective = basePath + effectiveLogical;
|
|
1454
|
+
if (opts?.replace) {
|
|
1455
|
+
window.history.replaceState({
|
|
1456
|
+
...history.state ?? {},
|
|
1457
|
+
_furinKey: getHistoryKey(history.state) ?? generateHistoryKey()
|
|
1458
|
+
}, "", physicalEffective);
|
|
1459
|
+
} else {
|
|
1460
|
+
const currentKey = getHistoryKey(history.state);
|
|
1461
|
+
if (currentKey) {
|
|
1462
|
+
saveScrollPosition(currentKey);
|
|
1463
|
+
}
|
|
1464
|
+
window.history.pushState({ _furinKey: generateHistoryKey() }, "", physicalEffective);
|
|
1465
|
+
}
|
|
1466
|
+
const effectiveUrl = new URL(physicalEffective, window.location.origin);
|
|
1467
|
+
const logicalPath = toLogical(effectiveUrl.pathname, basePath);
|
|
1468
|
+
setCurrentHref(logicalPath + effectiveUrl.search);
|
|
1469
|
+
if (opts?.resetScroll ?? true) {
|
|
1470
|
+
handleScrollRestoration(physicalEffective, myVersion, navVersion);
|
|
1471
|
+
}
|
|
1472
|
+
} finally {
|
|
1473
|
+
if (navVersion.current === myVersion) {
|
|
1474
|
+
setIsNavigating(false);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}, [prefetch, basePath]);
|
|
1478
|
+
const refresh = useCallback(async (opts) => {
|
|
1479
|
+
const logicalPath = toLogical(window.location.pathname, basePath);
|
|
1480
|
+
const logicalHref = logicalPath + window.location.search;
|
|
1481
|
+
invalidatePrefetch(logicalHref, "page");
|
|
1482
|
+
await navigate(logicalHref, { replace: true, resetScroll: opts?.resetScroll ?? false });
|
|
1483
|
+
}, [navigate, invalidatePrefetch, basePath]);
|
|
1484
|
+
useEffect(() => {
|
|
1485
|
+
if (typeof window !== "undefined") {
|
|
1486
|
+
window.__FURIN_HMR_REFRESH__ = refresh;
|
|
1487
|
+
return () => {
|
|
1488
|
+
window.__FURIN_HMR_REFRESH__ = undefined;
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
}, [refresh]);
|
|
1492
|
+
const handlePopState = useCallback(async () => {
|
|
1493
|
+
const destKey = getHistoryKey(history.state);
|
|
1494
|
+
const logicalPath = toLogical(window.location.pathname, basePath);
|
|
1495
|
+
const logicalHref = logicalPath + window.location.search;
|
|
1496
|
+
const myVersion = ++navVersion.current;
|
|
1497
|
+
setIsNavigating(true);
|
|
1498
|
+
try {
|
|
1499
|
+
const cached = prefetchCache.current.get(logicalHref);
|
|
1500
|
+
let newState;
|
|
1501
|
+
if (cached && !shouldRefetch(cached)) {
|
|
1502
|
+
newState = await cached.promise;
|
|
1503
|
+
} else {
|
|
1504
|
+
newState = await fetchPageState(logicalHref);
|
|
1505
|
+
}
|
|
1506
|
+
if (navVersion.current !== myVersion) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
if (!newState) {
|
|
1510
|
+
_log.warn({
|
|
1511
|
+
action: "popstate_fallback",
|
|
1512
|
+
href: logicalHref,
|
|
1513
|
+
reason: "fetchPageState_returned_null"
|
|
1514
|
+
});
|
|
1515
|
+
window.location.reload();
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
currentMatchRef.current = newState.match;
|
|
1519
|
+
setState(newState);
|
|
1520
|
+
if (newState.title) {
|
|
1521
|
+
document.title = newState.title;
|
|
1522
|
+
}
|
|
1523
|
+
const effectiveLogical = newState.finalHref ?? logicalHref;
|
|
1524
|
+
if (newState.finalHref) {
|
|
1525
|
+
window.history.replaceState(history.state, "", basePath + effectiveLogical);
|
|
1526
|
+
}
|
|
1527
|
+
setCurrentHref(effectiveLogical);
|
|
1528
|
+
if (destKey) {
|
|
1529
|
+
restoreScrollPosition(destKey, myVersion, navVersion);
|
|
1530
|
+
} else {
|
|
1531
|
+
window.scrollTo({ top: 0, behavior: "instant" });
|
|
1532
|
+
}
|
|
1533
|
+
} finally {
|
|
1534
|
+
if (navVersion.current === myVersion) {
|
|
1535
|
+
setIsNavigating(false);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}, [fetchPageState, basePath]);
|
|
1539
|
+
useEffect(() => {
|
|
1540
|
+
const prevScrollRestoration = history.scrollRestoration;
|
|
1541
|
+
history.scrollRestoration = "manual";
|
|
1542
|
+
if (!getHistoryKey(history.state)) {
|
|
1543
|
+
history.replaceState({ ...history.state ?? {}, _furinKey: generateHistoryKey() }, "");
|
|
1544
|
+
}
|
|
1545
|
+
return () => {
|
|
1546
|
+
history.scrollRestoration = prevScrollRestoration;
|
|
1547
|
+
};
|
|
1548
|
+
}, []);
|
|
1549
|
+
useEffect(() => {
|
|
1550
|
+
window.addEventListener("popstate", handlePopState);
|
|
1551
|
+
return () => window.removeEventListener("popstate", handlePopState);
|
|
1552
|
+
}, [handlePopState]);
|
|
1553
|
+
useEffect(() => {
|
|
1554
|
+
if (typeof window === "undefined") {
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
const originalFetch = window.fetch;
|
|
1558
|
+
const wrapped = async (...args) => {
|
|
1559
|
+
const response = await originalFetch.apply(window, args);
|
|
1560
|
+
const invalidated = [];
|
|
1561
|
+
applyRevalidateHeader(response.headers, (path, type = "page") => {
|
|
1562
|
+
invalidatePrefetch(path, type);
|
|
1563
|
+
invalidated.push({ path, type });
|
|
1564
|
+
});
|
|
1565
|
+
if (autoRefresh && invalidated.length > 0) {
|
|
1566
|
+
const currentPath = window.location.pathname + window.location.search;
|
|
1567
|
+
if (shouldAutoRefreshPath(currentPath, invalidated)) {
|
|
1568
|
+
refresh();
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
return response;
|
|
1572
|
+
};
|
|
1573
|
+
Object.assign(wrapped, originalFetch);
|
|
1574
|
+
window.fetch = wrapped;
|
|
1575
|
+
return () => {
|
|
1576
|
+
window.fetch = originalFetch;
|
|
1577
|
+
};
|
|
1578
|
+
}, [invalidatePrefetch, refresh, autoRefresh]);
|
|
1579
|
+
let pageElement;
|
|
1580
|
+
if (state.notFound || !state.match) {
|
|
1581
|
+
pageElement = buildNotFoundPageElement(state.notFoundBoundaries ?? state.match?.segmentBoundaries ?? rootBoundaries, state.notFound ?? {});
|
|
1582
|
+
} else {
|
|
1583
|
+
pageElement = buildPageElement(state.match, root, state.data, {
|
|
1584
|
+
onReset: refresh,
|
|
1585
|
+
resetKey: currentHref
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
return buildRouterTree({
|
|
1589
|
+
basePath,
|
|
1590
|
+
currentHref,
|
|
1591
|
+
navigate,
|
|
1592
|
+
prefetch,
|
|
1593
|
+
refresh,
|
|
1594
|
+
invalidatePrefetch,
|
|
1595
|
+
isNavigating,
|
|
1596
|
+
defaultPreload,
|
|
1597
|
+
defaultPreloadDelay,
|
|
1598
|
+
defaultPreloadStaleTime
|
|
1599
|
+
}, pageElement, {
|
|
1600
|
+
digest: initialDigest,
|
|
1601
|
+
onReset: refresh,
|
|
1602
|
+
resetKey: currentHref
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
function computeLinkView({
|
|
1606
|
+
to,
|
|
1607
|
+
search,
|
|
1608
|
+
hash,
|
|
1609
|
+
children,
|
|
1610
|
+
activeProps,
|
|
1611
|
+
inactiveProps
|
|
1612
|
+
}, router) {
|
|
1613
|
+
const logicalHref = buildHref(to, search, hash);
|
|
1614
|
+
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
1615
|
+
const href = router.basePath + logicalHref;
|
|
1616
|
+
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
1617
|
+
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
1618
|
+
const extraProps = {
|
|
1619
|
+
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
1620
|
+
...activeProps ? activeProps({ isActive }) : {}
|
|
1621
|
+
};
|
|
1622
|
+
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
1623
|
+
}
|
|
1624
|
+
function LinkInteractive({
|
|
1625
|
+
to,
|
|
1626
|
+
search,
|
|
1627
|
+
hash,
|
|
1628
|
+
preload,
|
|
1629
|
+
preloadDelay,
|
|
1630
|
+
preloadStaleTime,
|
|
1631
|
+
replace,
|
|
1632
|
+
disabled,
|
|
1633
|
+
resetScroll,
|
|
1634
|
+
activeProps,
|
|
1635
|
+
inactiveProps,
|
|
1636
|
+
onClick,
|
|
1637
|
+
onMouseEnter,
|
|
1638
|
+
onMouseLeave,
|
|
1639
|
+
onFocus,
|
|
1640
|
+
children,
|
|
1641
|
+
...anchorProps
|
|
1642
|
+
}) {
|
|
1643
|
+
const router = useRouter();
|
|
1644
|
+
const anchorRef = useRef(null);
|
|
1645
|
+
const intentTimerRef = useRef(null);
|
|
1646
|
+
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
|
|
1647
|
+
const effectivePreload = preload ?? router.defaultPreload;
|
|
1648
|
+
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
1649
|
+
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
1650
|
+
const triggerPrefetch = useCallback(() => {
|
|
1651
|
+
router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
1652
|
+
}, [router, logicalHref, effectiveStaleTime]);
|
|
1653
|
+
useEffect(() => {
|
|
1654
|
+
if (effectivePreload === "render") {
|
|
1655
|
+
triggerPrefetch();
|
|
1656
|
+
}
|
|
1657
|
+
}, [effectivePreload, triggerPrefetch]);
|
|
1658
|
+
useEffect(() => {
|
|
1659
|
+
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
1663
|
+
if (entry?.isIntersecting) {
|
|
1664
|
+
triggerPrefetch();
|
|
1665
|
+
observer.disconnect();
|
|
1666
|
+
}
|
|
1667
|
+
}, { rootMargin: "200px" });
|
|
1668
|
+
observer.observe(anchorRef.current);
|
|
1669
|
+
return () => observer.disconnect();
|
|
1670
|
+
}, [effectivePreload, triggerPrefetch]);
|
|
1671
|
+
const isInternal = (url) => {
|
|
1672
|
+
try {
|
|
1673
|
+
return new URL(url, window.location.origin).origin === window.location.origin;
|
|
1674
|
+
} catch {
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
const handleClick = (e) => {
|
|
1679
|
+
onClick?.(e);
|
|
1680
|
+
if (e.defaultPrevented || disabled) {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
if (anchorProps.target && anchorProps.target !== "_self") {
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
if (!isInternal(href)) {
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
e.preventDefault();
|
|
1693
|
+
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
1694
|
+
};
|
|
1695
|
+
const handleMouseEnter = (e) => {
|
|
1696
|
+
onMouseEnter?.(e);
|
|
1697
|
+
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
1698
|
+
intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
const handleMouseLeave = (e) => {
|
|
1702
|
+
onMouseLeave?.(e);
|
|
1703
|
+
if (intentTimerRef.current !== null) {
|
|
1704
|
+
clearTimeout(intentTimerRef.current);
|
|
1705
|
+
intentTimerRef.current = null;
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
const handleFocus = (e) => {
|
|
1709
|
+
onFocus?.(e);
|
|
1710
|
+
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
1711
|
+
triggerPrefetch();
|
|
1712
|
+
}
|
|
1713
|
+
};
|
|
1714
|
+
return createElement("a", {
|
|
1715
|
+
ref: anchorRef,
|
|
1716
|
+
href,
|
|
1717
|
+
onClick: handleClick,
|
|
1718
|
+
onMouseEnter: handleMouseEnter,
|
|
1719
|
+
onMouseLeave: handleMouseLeave,
|
|
1720
|
+
onFocus: handleFocus,
|
|
1721
|
+
...isActive ? { "data-status": "active" } : {},
|
|
1722
|
+
...anchorProps,
|
|
1723
|
+
...extraProps,
|
|
1724
|
+
...disabled ? { "aria-disabled": true } : {}
|
|
1725
|
+
}, resolvedChildren);
|
|
1726
|
+
}
|
|
1727
|
+
var SSR_FALLBACK_ROUTER = {
|
|
1728
|
+
basePath: "",
|
|
1729
|
+
currentHref: "/",
|
|
1730
|
+
navigate: () => Promise.resolve(),
|
|
1731
|
+
prefetch: () => {},
|
|
1732
|
+
invalidatePrefetch: () => {},
|
|
1733
|
+
refresh: () => Promise.resolve(),
|
|
1734
|
+
isNavigating: false,
|
|
1735
|
+
defaultPreload: "intent",
|
|
1736
|
+
defaultPreloadDelay: 50,
|
|
1737
|
+
defaultPreloadStaleTime: 30000
|
|
1738
|
+
};
|
|
1739
|
+
function renderLinkElement(props, router) {
|
|
1740
|
+
const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
|
|
1741
|
+
const {
|
|
1742
|
+
to: _to,
|
|
1743
|
+
search: _search,
|
|
1744
|
+
hash: _hash,
|
|
1745
|
+
children: _children,
|
|
1746
|
+
activeProps: _ap,
|
|
1747
|
+
inactiveProps: _ip,
|
|
1748
|
+
disabled,
|
|
1749
|
+
preload: _p,
|
|
1750
|
+
preloadDelay: _pd,
|
|
1751
|
+
preloadStaleTime: _ps,
|
|
1752
|
+
replace: _r,
|
|
1753
|
+
resetScroll: _rs,
|
|
1754
|
+
onClick: _oc,
|
|
1755
|
+
onMouseEnter: _ome,
|
|
1756
|
+
onMouseLeave: _oml,
|
|
1757
|
+
onFocus: _of,
|
|
1758
|
+
...anchorProps
|
|
1759
|
+
} = props;
|
|
1760
|
+
return createElement("a", {
|
|
1761
|
+
href,
|
|
1762
|
+
...isActive ? { "data-status": "active" } : {},
|
|
1763
|
+
...anchorProps,
|
|
1764
|
+
...extraProps,
|
|
1765
|
+
...disabled ? { "aria-disabled": true } : {}
|
|
1766
|
+
}, resolvedChildren);
|
|
1767
|
+
}
|
|
1768
|
+
function Link(props) {
|
|
1769
|
+
if (typeof window === "undefined") {
|
|
1770
|
+
return createElement(RouterContext.Consumer, {
|
|
1771
|
+
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
return createElement(LinkInteractive, props);
|
|
1775
|
+
}
|
|
1776
|
+
export {
|
|
1777
|
+
useRouter,
|
|
1778
|
+
shouldRefetch,
|
|
1779
|
+
shouldAutoRefreshPath,
|
|
1780
|
+
pickDeepestNotFound,
|
|
1781
|
+
classifySpaResponse,
|
|
1782
|
+
buildRouterTree,
|
|
1783
|
+
buildPageElement,
|
|
1784
|
+
buildNotFoundPageElement,
|
|
1785
|
+
buildHref,
|
|
1786
|
+
applyRevalidateHeader,
|
|
1787
|
+
RouterProvider,
|
|
1788
|
+
RouterContext,
|
|
1789
|
+
Link
|
|
1790
|
+
};
|