sibujs 4.13.1 → 4.14.1
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/README.md +1 -1
- package/dist/browser.cjs +15 -2
- package/dist/browser.js +9 -7
- package/dist/build.cjs +880 -281
- package/dist/build.d.cts +68 -3
- package/dist/build.d.ts +68 -3
- package/dist/build.js +88 -30
- package/dist/cdn.dev.global.js +12 -12
- package/dist/cdn.full.dev.global.js +13 -13
- package/dist/cdn.full.global.js +12 -12
- package/dist/cdn.global.js +12 -12
- package/dist/{chunk-J6FW5TV6.js → chunk-3HEX6QJQ.js} +5 -3
- package/dist/chunk-3HZOSMPX.js +90 -0
- package/dist/{chunk-K4LNUT5L.js → chunk-3T7TWMSD.js} +8 -6
- package/dist/{chunk-ADZHPN2B.js → chunk-4XCWNGRY.js} +3 -3
- package/dist/{chunk-2NC56RGY.js → chunk-55TAOW5M.js} +2 -2
- package/dist/{chunk-G3Z2FEBR.js → chunk-B2NLNZ3E.js} +119 -26
- package/dist/{chunk-EXXSN3BW.js → chunk-B3HOT4TK.js} +1 -1
- package/dist/{chunk-QKFVMIAV.js → chunk-FCWOMATN.js} +11 -3
- package/dist/{chunk-QC3NP47A.js → chunk-FFXZ6ELZ.js} +10 -6
- package/dist/{chunk-TUCPL2HB.js → chunk-GIJ33UJZ.js} +1 -1
- package/dist/chunk-KTJC7QPA.js +195 -0
- package/dist/chunk-L2IPKGUJ.js +2596 -0
- package/dist/{chunk-4UTGDVSA.js → chunk-LAHX7XFG.js} +7 -14
- package/dist/{chunk-PBJYCE2Z.js → chunk-LJ2LR5P4.js} +5 -5
- package/dist/{chunk-AM6DZLBM.js → chunk-LJMX4SQ7.js} +2 -2
- package/dist/{chunk-5RIBLY2N.js → chunk-LUZXFMKH.js} +6 -6
- package/dist/{chunk-VFPLWUT7.js → chunk-LZKKMDQF.js} +151 -86
- package/dist/{chunk-J4X7ICH4.js → chunk-NIHGSXOX.js} +8 -6
- package/dist/chunk-NT3ZYB5S.js +167 -0
- package/dist/{chunk-2O6JJCUR.js → chunk-OLMZF4RU.js} +49 -8
- package/dist/{chunk-22OPSWMF.js → chunk-OPRQW4LI.js} +2 -2
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/{chunk-KC62VURU.js → chunk-RBRITLFL.js} +10 -8
- package/dist/{chunk-F2UWOZ6J.js → chunk-RVWJGWCL.js} +2 -2
- package/dist/{chunk-NYNYSPK7.js → chunk-S37PZD6I.js} +30 -45
- package/dist/chunk-TOV4PN3P.js +2015 -0
- package/dist/{chunk-C73VBPEF.js → chunk-TS6JDK7Y.js} +8 -8
- package/dist/{chunk-EU7T7EB3.js → chunk-TZNR6E6D.js} +4 -4
- package/dist/chunk-UYTYNCMZ.js +199 -0
- package/dist/{chunk-OIKD7YDY.js → chunk-VIAVYBNQ.js} +6 -5
- package/dist/{chunk-QZ47OZ25.js → chunk-WFMMSMA5.js} +8 -6
- package/dist/chunk-YIXMS546.js +1901 -0
- package/dist/{chunk-5XUGJM3J.js → chunk-YPLQQTWS.js} +1 -1
- package/dist/{chunk-CPQKWCJ2.js → chunk-ZKI4SDZ2.js} +16 -10
- package/dist/{chunk-YFTBCCVH.js → chunk-ZYK4NZZA.js} +5 -3
- package/dist/data.cjs +265 -35
- package/dist/data.d.cts +31 -1
- package/dist/data.d.ts +31 -1
- package/dist/data.js +16 -10
- package/dist/devtools.cjs +15 -2
- package/dist/devtools.js +9 -7
- package/dist/{dispose-GEIG2KOF.js → dispose-EIHHHDC7.js} +3 -1
- package/dist/ecosystem.cjs +62 -23
- package/dist/ecosystem.js +14 -12
- package/dist/extras.cjs +3562 -270
- package/dist/extras.d.cts +3 -3
- package/dist/extras.d.ts +3 -3
- package/dist/extras.js +39 -29
- package/dist/index.cjs +442 -253
- package/dist/index.d.cts +93 -283
- package/dist/index.d.ts +93 -283
- package/dist/index.js +26 -16
- package/dist/motion.cjs +12 -1
- package/dist/motion.js +6 -4
- package/dist/patterns.cjs +15 -2
- package/dist/patterns.js +10 -8
- package/dist/performance.cjs +36 -2
- package/dist/performance.d.cts +2 -2
- package/dist/performance.d.ts +2 -2
- package/dist/performance.js +14 -10
- package/dist/plugins.cjs +5267 -1807
- package/dist/plugins.d.cts +8 -834
- package/dist/plugins.d.ts +8 -834
- package/dist/plugins.js +64 -2329
- package/dist/prerenderServer-MXJEVWA3.js +350 -0
- package/dist/renderRoute-DP20XwMS.d.cts +86 -0
- package/dist/renderRoute-fxgsm2Ir.d.ts +86 -0
- package/dist/routeHead-CE9SV-cH.d.cts +995 -0
- package/dist/routeHead-DzVxPviY.d.ts +995 -0
- package/dist/{routeMiddleware-B1sp4P7a.d.ts → routeMiddleware-BySbueoE.d.ts} +0 -25
- package/dist/{routeMiddleware-CedQTsLK.d.cts → routeMiddleware-CijZD5eW.d.cts} +0 -25
- package/dist/{ssr-VBM6J5SJ.js → ssr-HHU3DAD2.js} +15 -6
- package/dist/ssr-JpGpHnpC.d.cts +841 -0
- package/dist/ssr-JpGpHnpC.d.ts +841 -0
- package/dist/ssr-dom.cjs +1904 -0
- package/dist/ssr-dom.d.cts +343 -0
- package/dist/ssr-dom.d.ts +343 -0
- package/dist/ssr-dom.js +19 -0
- package/dist/ssr.cjs +7677 -2069
- package/dist/ssr.d.cts +63 -5
- package/dist/ssr.d.ts +63 -5
- package/dist/ssr.js +136 -14
- package/dist/testing.cjs +6585 -87
- package/dist/testing.d.cts +80 -1
- package/dist/testing.d.ts +80 -1
- package/dist/testing.js +117 -4
- package/dist/ui.cjs +36 -2
- package/dist/ui.js +17 -14
- package/dist/widgets.cjs +14 -1
- package/dist/widgets.js +11 -9
- package/package.json +9 -2
- package/dist/chunk-2F4PSJ5Z.js +0 -765
- package/dist/chunk-7XHATCIH.js +0 -121
- package/dist/chunk-B36ADEIR.js +0 -21
- package/dist/ssr-Db0Sgdu3.d.cts +0 -245
- package/dist/ssr-Db0Sgdu3.d.ts +0 -245
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Route,
|
|
3
|
+
createRouter,
|
|
4
|
+
route
|
|
5
|
+
} from "./chunk-L2IPKGUJ.js";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_SETTLE_TIMEOUT,
|
|
8
|
+
assembleDocument,
|
|
9
|
+
collectServerHead,
|
|
10
|
+
renderToStringAsync
|
|
11
|
+
} from "./chunk-TOV4PN3P.js";
|
|
12
|
+
import {
|
|
13
|
+
assertRequestIsolation,
|
|
14
|
+
getRequestStore,
|
|
15
|
+
runInSSRContext
|
|
16
|
+
} from "./chunk-UYTYNCMZ.js";
|
|
17
|
+
import {
|
|
18
|
+
DEV
|
|
19
|
+
} from "./chunk-NT3ZYB5S.js";
|
|
20
|
+
|
|
21
|
+
// src/platform/renderRoute.ts
|
|
22
|
+
function deepest(matched, key) {
|
|
23
|
+
for (let i = matched.length - 1; i >= 0; i--) {
|
|
24
|
+
const value = matched[i][key];
|
|
25
|
+
if (value !== void 0) return value;
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
function encodeUrlPart(part) {
|
|
30
|
+
return part.replace(/%(?![0-9A-Fa-f]{2})|[^A-Za-z0-9\-._~!$&'()*+,;=:@/?%]/gu, (c) => {
|
|
31
|
+
try {
|
|
32
|
+
return encodeURIComponent(c);
|
|
33
|
+
} catch {
|
|
34
|
+
return "%EF%BF%BD";
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function before(work, deadline) {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const timer = setTimeout(() => resolve(false), Math.max(0, deadline - Date.now()));
|
|
41
|
+
const done = () => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
resolve(true);
|
|
44
|
+
};
|
|
45
|
+
work.then(done, done);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function emptyDiagnostics() {
|
|
49
|
+
return {
|
|
50
|
+
timedOut: false,
|
|
51
|
+
pending: [],
|
|
52
|
+
browserApis: [],
|
|
53
|
+
stateBytes: 0,
|
|
54
|
+
largestState: [],
|
|
55
|
+
droppedState: [],
|
|
56
|
+
durationMs: 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function renderRoute(routes, url, options = {}) {
|
|
60
|
+
try {
|
|
61
|
+
assertRequestIsolation("renderRoute()");
|
|
62
|
+
} catch (err) {
|
|
63
|
+
return Promise.reject(err);
|
|
64
|
+
}
|
|
65
|
+
return runInSSRContext(async () => {
|
|
66
|
+
const started = Date.now();
|
|
67
|
+
const deadline = started + (options.timeout ?? DEFAULT_SETTLE_TIMEOUT);
|
|
68
|
+
const router = createRouter(routes, { ...options.router, mode: "memory", url });
|
|
69
|
+
const wrap = (body, headHtml, state) => options.document ? assembleDocument(body, options.document, headHtml, state) : body;
|
|
70
|
+
const timedOut = (phase) => {
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
const pending = [
|
|
73
|
+
`${phase} (${now - started} ms)`,
|
|
74
|
+
...Array.from(getRequestStore()?.pending ?? [], (work) => `${work.label} (${now - work.since} ms)`)
|
|
75
|
+
];
|
|
76
|
+
const diagnostics = { ...emptyDiagnostics(), timedOut: true, pending, durationMs: now - started };
|
|
77
|
+
if (DEV) {
|
|
78
|
+
console.warn(
|
|
79
|
+
`[SibuJS SSR] ${url}: the route did not render within ${options.timeout ?? DEFAULT_SETTLE_TIMEOUT} ms; pending: ${pending.join(", ")}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
html: wrap("", "", ""),
|
|
84
|
+
head: "",
|
|
85
|
+
state: "",
|
|
86
|
+
stateData: null,
|
|
87
|
+
status: 503,
|
|
88
|
+
location: null,
|
|
89
|
+
route: null,
|
|
90
|
+
render: "default",
|
|
91
|
+
noindex: false,
|
|
92
|
+
failure: "timeout",
|
|
93
|
+
redirectBy: null,
|
|
94
|
+
diagnostics
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
if (!await before(router.whenNavigated(), deadline)) return timedOut("route:navigation");
|
|
99
|
+
const { result, redirectStatus, redirectBy } = router.initialOutcome;
|
|
100
|
+
const committed = route();
|
|
101
|
+
const matched = committed.matched;
|
|
102
|
+
const base = options.router?.base ?? "";
|
|
103
|
+
const head = () => collectServerHead();
|
|
104
|
+
if (result && !result.success) {
|
|
105
|
+
const reason = result.reason ?? "error";
|
|
106
|
+
const status2 = reason === "guard" ? options.rejectStatus ?? 403 : 500;
|
|
107
|
+
const headHtml = head();
|
|
108
|
+
return {
|
|
109
|
+
html: wrap("", headHtml, ""),
|
|
110
|
+
head: headHtml,
|
|
111
|
+
state: "",
|
|
112
|
+
stateData: null,
|
|
113
|
+
status: status2,
|
|
114
|
+
location: null,
|
|
115
|
+
route: null,
|
|
116
|
+
render: "default",
|
|
117
|
+
noindex: false,
|
|
118
|
+
failure: reason,
|
|
119
|
+
redirectBy: null,
|
|
120
|
+
diagnostics: { ...emptyDiagnostics(), durationMs: Date.now() - started }
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const search = new URLSearchParams();
|
|
124
|
+
for (const [key, values] of Object.entries(committed.queryAll)) for (const v of values) search.append(key, v);
|
|
125
|
+
const locationPath = encodeUrlPart(committed.path) + (search.size > 0 ? `?${search}` : "") + (committed.hash ? `#${encodeUrlPart(committed.hash)}` : "");
|
|
126
|
+
const routeInfo = {
|
|
127
|
+
path: committed.path,
|
|
128
|
+
params: { ...committed.params },
|
|
129
|
+
query: { ...committed.query },
|
|
130
|
+
hash: committed.hash,
|
|
131
|
+
name: matched.length > 0 ? matched[matched.length - 1].name ?? null : null
|
|
132
|
+
};
|
|
133
|
+
const headHtml0 = head();
|
|
134
|
+
const noindex = /<meta name="robots" content="[^"]*noindex/i.test(headHtml0);
|
|
135
|
+
if (redirectStatus !== null) {
|
|
136
|
+
return {
|
|
137
|
+
html: "",
|
|
138
|
+
head: headHtml0,
|
|
139
|
+
state: "",
|
|
140
|
+
stateData: null,
|
|
141
|
+
status: redirectStatus,
|
|
142
|
+
location: encodeUrlPart(base) + locationPath,
|
|
143
|
+
route: routeInfo,
|
|
144
|
+
render: "default",
|
|
145
|
+
noindex,
|
|
146
|
+
failure: null,
|
|
147
|
+
redirectBy,
|
|
148
|
+
diagnostics: { ...emptyDiagnostics(), durationMs: Date.now() - started }
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const leaf = matched[matched.length - 1];
|
|
152
|
+
const status = deepest(matched, "status") ?? (!leaf || leaf.path === "*" ? 404 : 200);
|
|
153
|
+
const render = deepest(matched, "render") ?? "default";
|
|
154
|
+
if (render === "client" || options.headOnly?.includes(render)) {
|
|
155
|
+
return {
|
|
156
|
+
html: wrap("", headHtml0, ""),
|
|
157
|
+
head: headHtml0,
|
|
158
|
+
state: "",
|
|
159
|
+
stateData: null,
|
|
160
|
+
status,
|
|
161
|
+
location: null,
|
|
162
|
+
route: routeInfo,
|
|
163
|
+
render,
|
|
164
|
+
noindex,
|
|
165
|
+
failure: null,
|
|
166
|
+
redirectBy: null,
|
|
167
|
+
diagnostics: { ...emptyDiagnostics(), durationMs: Date.now() - started }
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (!await before(router.whenReady(), deadline)) return timedOut("route:components");
|
|
171
|
+
const rendered = await renderToStringAsync(options.app ?? (() => Route()), {
|
|
172
|
+
...options,
|
|
173
|
+
timeout: Math.max(0, deadline - Date.now()),
|
|
174
|
+
log: options.log === true ? url : options.log
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
...rendered,
|
|
178
|
+
html: wrap(rendered.html, rendered.head, rendered.state),
|
|
179
|
+
status,
|
|
180
|
+
location: null,
|
|
181
|
+
route: routeInfo,
|
|
182
|
+
render,
|
|
183
|
+
noindex: /<meta name="robots" content="[^"]*noindex/i.test(rendered.head),
|
|
184
|
+
failure: null,
|
|
185
|
+
redirectBy: null
|
|
186
|
+
};
|
|
187
|
+
} finally {
|
|
188
|
+
router.destroy();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export {
|
|
194
|
+
renderRoute
|
|
195
|
+
};
|