@mindflight/mindbrain-personal-studio 0.6.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/.env.example +50 -0
- package/README.md +134 -0
- package/bin/mindbrain-studio.mjs +20 -0
- package/build/client/_app/immutable/assets/2.BXRKVU9n.css +1 -0
- package/build/client/_app/immutable/assets/2.BXRKVU9n.css.br +0 -0
- package/build/client/_app/immutable/assets/2.BXRKVU9n.css.gz +0 -0
- package/build/client/_app/immutable/chunks/-OSExkSk.js +2 -0
- package/build/client/_app/immutable/chunks/-OSExkSk.js.br +0 -0
- package/build/client/_app/immutable/chunks/-OSExkSk.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BIHI7g3E.js +1 -0
- package/build/client/_app/immutable/chunks/BIHI7g3E.js.br +2 -0
- package/build/client/_app/immutable/chunks/BIHI7g3E.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BJB7pSge.js +1 -0
- package/build/client/_app/immutable/chunks/BJB7pSge.js.br +0 -0
- package/build/client/_app/immutable/chunks/BJB7pSge.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BNUkRZqg.js +1 -0
- package/build/client/_app/immutable/chunks/BNUkRZqg.js.br +0 -0
- package/build/client/_app/immutable/chunks/BNUkRZqg.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BP2JbIUZ.js +1 -0
- package/build/client/_app/immutable/chunks/BP2JbIUZ.js.br +0 -0
- package/build/client/_app/immutable/chunks/BP2JbIUZ.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BVrgUHq-.js +1 -0
- package/build/client/_app/immutable/chunks/BVrgUHq-.js.br +0 -0
- package/build/client/_app/immutable/chunks/BVrgUHq-.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js +1 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js.br +0 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BnkCgNCx.js +1 -0
- package/build/client/_app/immutable/chunks/BnkCgNCx.js.br +0 -0
- package/build/client/_app/immutable/chunks/BnkCgNCx.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C5KYKPa8.js +311 -0
- package/build/client/_app/immutable/chunks/C5KYKPa8.js.br +0 -0
- package/build/client/_app/immutable/chunks/C5KYKPa8.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CBDzfqXr.js +1 -0
- package/build/client/_app/immutable/chunks/CBDzfqXr.js.br +0 -0
- package/build/client/_app/immutable/chunks/CBDzfqXr.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Cp9dXlPT.js +1 -0
- package/build/client/_app/immutable/chunks/Cp9dXlPT.js.br +0 -0
- package/build/client/_app/immutable/chunks/Cp9dXlPT.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D0daF8Eh.js +2 -0
- package/build/client/_app/immutable/chunks/D0daF8Eh.js.br +0 -0
- package/build/client/_app/immutable/chunks/D0daF8Eh.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D4SoBmS0.js +1 -0
- package/build/client/_app/immutable/chunks/D4SoBmS0.js.br +0 -0
- package/build/client/_app/immutable/chunks/D4SoBmS0.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DpVrWha3.js +1 -0
- package/build/client/_app/immutable/chunks/DpVrWha3.js.br +0 -0
- package/build/client/_app/immutable/chunks/DpVrWha3.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DyXQogav.js +1 -0
- package/build/client/_app/immutable/chunks/DyXQogav.js.br +0 -0
- package/build/client/_app/immutable/chunks/DyXQogav.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Gs0cNFYG.js +1 -0
- package/build/client/_app/immutable/chunks/Gs0cNFYG.js.br +0 -0
- package/build/client/_app/immutable/chunks/Gs0cNFYG.js.gz +0 -0
- package/build/client/_app/immutable/chunks/NXeHtWpC.js +1 -0
- package/build/client/_app/immutable/chunks/NXeHtWpC.js.br +0 -0
- package/build/client/_app/immutable/chunks/NXeHtWpC.js.gz +0 -0
- package/build/client/_app/immutable/chunks/i0D5dc1Y.js +1 -0
- package/build/client/_app/immutable/chunks/i0D5dc1Y.js.br +0 -0
- package/build/client/_app/immutable/chunks/i0D5dc1Y.js.gz +0 -0
- package/build/client/_app/immutable/chunks/nnWk1BBo.js +1 -0
- package/build/client/_app/immutable/chunks/nnWk1BBo.js.br +0 -0
- package/build/client/_app/immutable/chunks/nnWk1BBo.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js +2 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js.br +0 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js +1 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js.br +2 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.C2sXq0eH.js +1 -0
- package/build/client/_app/immutable/nodes/0.C2sXq0eH.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.C2sXq0eH.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js +1 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.D0pSa9ko.js +9 -0
- package/build/client/_app/immutable/nodes/2.D0pSa9ko.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.D0pSa9ko.js.gz +0 -0
- package/build/client/_app/version.json +1 -0
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/client/robots.txt +3 -0
- package/build/client/robots.txt.br +0 -0
- package/build/client/robots.txt.gz +0 -0
- package/build/env.js +70 -0
- package/build/env.js.map +1 -0
- package/build/handler.js +26 -0
- package/build/handler.js.map +1 -0
- package/build/index.js +149 -0
- package/build/index.js.map +1 -0
- package/build/server/chunks/chunks/edgeLinkModes.js-CfRqrZtd.js +50 -0
- package/build/server/chunks/chunks/edgeLinkModes.js-CfRqrZtd.js.map +1 -0
- package/build/server/chunks/chunks/environment.js-Bf8x1V_n.js +16 -0
- package/build/server/chunks/chunks/environment.js-Bf8x1V_n.js.map +1 -0
- package/build/server/chunks/chunks/exports.js-DFR3riS9.js +217 -0
- package/build/server/chunks/chunks/exports.js-DFR3riS9.js.map +1 -0
- package/build/server/chunks/chunks/false.js-CRHihH2U.js +4 -0
- package/build/server/chunks/chunks/false.js-CRHihH2U.js.map +1 -0
- package/build/server/chunks/chunks/graphRepository.js-D2DARfVY.js +280 -0
- package/build/server/chunks/chunks/graphRepository.js-D2DARfVY.js.map +1 -0
- package/build/server/chunks/chunks/internal.js-D8EA_he2.js +119 -0
- package/build/server/chunks/chunks/internal.js-D8EA_he2.js.map +1 -0
- package/build/server/chunks/chunks/mindbrainClient.js-BFAJqRSL.js +108 -0
- package/build/server/chunks/chunks/mindbrainClient.js-BFAJqRSL.js.map +1 -0
- package/build/server/chunks/chunks/ontologyInspect.js-Dm3l7KgF.js +13 -0
- package/build/server/chunks/chunks/ontologyInspect.js-Dm3l7KgF.js.map +1 -0
- package/build/server/chunks/chunks/render-context.js-CTu5Wkzp.js +475 -0
- package/build/server/chunks/chunks/render-context.js-CTu5Wkzp.js.map +1 -0
- package/build/server/chunks/chunks/renderer.js-DsOhU1UZ.js +1243 -0
- package/build/server/chunks/chunks/renderer.js-DsOhU1UZ.js.map +1 -0
- package/build/server/chunks/chunks/root.js-DCnlE3XY.js +2815 -0
- package/build/server/chunks/chunks/root.js-DCnlE3XY.js.map +1 -0
- package/build/server/chunks/chunks/shared-server.js-DaWdgxVh.js +11 -0
- package/build/server/chunks/chunks/shared-server.js-DaWdgxVh.js.map +1 -0
- package/build/server/chunks/chunks/shared.js-DuDDTJVi.js +1338 -0
- package/build/server/chunks/chunks/shared.js-DuDDTJVi.js.map +1 -0
- package/build/server/chunks/chunks/utils.js-DGYJFmnf.js +39 -0
- package/build/server/chunks/chunks/utils.js-DGYJFmnf.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/brain/_...path_/_server.ts.js-MgPpKBks.js +82 -0
- package/build/server/chunks/entries/endpoints/api/brain/_...path_/_server.ts.js-MgPpKBks.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/brain/health/_server.ts.js-DnJQNmWV.js +19 -0
- package/build/server/chunks/entries/endpoints/api/brain/health/_server.ts.js-DnJQNmWV.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/_server.ts.js-Bxo7qHVz.js +37 -0
- package/build/server/chunks/entries/endpoints/api/graph/_server.ts.js-Bxo7qHVz.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/count/_server.ts.js-BajaLnqp.js +37 -0
- package/build/server/chunks/entries/endpoints/api/graph/count/_server.ts.js-BajaLnqp.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/ontologies/_server.ts.js-BFq2mbbX.js +146 -0
- package/build/server/chunks/entries/endpoints/api/graph/ontologies/_server.ts.js-BFq2mbbX.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/_server.ts.js-Dyfsc-VA.js +154 -0
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/_server.ts.js-Dyfsc-VA.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/projections/catalog/_server.ts.js-Ds1RymA0.js +351 -0
- package/build/server/chunks/entries/endpoints/api/projections/catalog/_server.ts.js-Ds1RymA0.js.map +1 -0
- package/build/server/chunks/entries/fallbacks/error.svelte.js-B7V4yZjo.js +51 -0
- package/build/server/chunks/entries/fallbacks/error.svelte.js-B7V4yZjo.js.map +1 -0
- package/build/server/chunks/entries/pages/_layout.svelte.js-CoC9BAeH.js +15 -0
- package/build/server/chunks/entries/pages/_layout.svelte.js-CoC9BAeH.js.map +1 -0
- package/build/server/chunks/entries/pages/_page.svelte.js-DMEbD3K6.js +891 -0
- package/build/server/chunks/entries/pages/_page.svelte.js-DMEbD3K6.js.map +1 -0
- package/build/server/chunks/handler-BjXBCd1c.js +1698 -0
- package/build/server/chunks/handler-BjXBCd1c.js.map +1 -0
- package/build/server/chunks/index.js-BJYcV8V7.js +4183 -0
- package/build/server/chunks/index.js-BJYcV8V7.js.map +1 -0
- package/build/server/chunks/manifest.js-Ddaot0P4.js +91 -0
- package/build/server/chunks/manifest.js-Ddaot0P4.js.map +1 -0
- package/build/server/chunks/nodes/0.js-87v83UX9.js +9 -0
- package/build/server/chunks/nodes/0.js-87v83UX9.js.map +1 -0
- package/build/server/chunks/nodes/1.js-BRigw_9J.js +9 -0
- package/build/server/chunks/nodes/1.js-BRigw_9J.js.map +1 -0
- package/build/server/chunks/nodes/2.js-D9-B_qyX.js +9 -0
- package/build/server/chunks/nodes/2.js-D9-B_qyX.js.map +1 -0
- package/build/shims.js +33 -0
- package/build/shims.js.map +1 -0
- package/fixtures/minimal-graph.sqlite +0 -0
- package/package.json +81 -0
- package/scripts/backend-sqlite.mjs +190 -0
- package/scripts/build-serenity-v6-concept-review-pack.mjs +493 -0
- package/scripts/build-serenity-v6-review-pack.mjs +479 -0
- package/scripts/create-serenity-production-v6.mjs +627 -0
- package/scripts/dev-sqlite.mjs +86 -0
- package/scripts/export-serenity-v6-backup.mjs +178 -0
- package/scripts/import-serenity-v6-user-decisions.mjs +543 -0
- package/scripts/lib/sqlite-runtime.mjs +197 -0
- package/scripts/materialize-serenity-v6-snapshots.mjs +675 -0
- package/scripts/publish-npm.mjs +134 -0
- package/scripts/seed-immeuble-projections.mjs +169 -0
- package/scripts/studio-sqlite.mjs +74 -0
|
@@ -0,0 +1,1243 @@
|
|
|
1
|
+
import { c as invalid_csp, d as await_invalid, f as get_render_context, u as uneval, l as lifecycle_outside_component, h as dynamic_element_invalid_tag } from './render-context.js-CTu5Wkzp.js';
|
|
2
|
+
|
|
3
|
+
var ssr_context = null;
|
|
4
|
+
function set_ssr_context(v) {
|
|
5
|
+
ssr_context = v;
|
|
6
|
+
}
|
|
7
|
+
function getContext(key) {
|
|
8
|
+
const context_map = get_or_init_context_map();
|
|
9
|
+
const result = (
|
|
10
|
+
/** @type {T} */
|
|
11
|
+
context_map.get(key)
|
|
12
|
+
);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
function setContext(key, context) {
|
|
16
|
+
get_or_init_context_map().set(key, context);
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
function get_or_init_context_map(name) {
|
|
20
|
+
if (ssr_context === null) {
|
|
21
|
+
lifecycle_outside_component();
|
|
22
|
+
}
|
|
23
|
+
return ssr_context.c ??= new Map(get_parent_context(ssr_context) || void 0);
|
|
24
|
+
}
|
|
25
|
+
function push(fn) {
|
|
26
|
+
ssr_context = { p: ssr_context, c: null, r: null };
|
|
27
|
+
}
|
|
28
|
+
function pop() {
|
|
29
|
+
ssr_context = /** @type {SSRContext} */
|
|
30
|
+
ssr_context.p;
|
|
31
|
+
}
|
|
32
|
+
function get_parent_context(ssr_context2) {
|
|
33
|
+
let parent = ssr_context2.p;
|
|
34
|
+
while (parent !== null) {
|
|
35
|
+
const context_map = parent.c;
|
|
36
|
+
if (context_map !== null) {
|
|
37
|
+
return context_map;
|
|
38
|
+
}
|
|
39
|
+
parent = parent.p;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
var is_array = Array.isArray;
|
|
44
|
+
var index_of = Array.prototype.indexOf;
|
|
45
|
+
var includes = Array.prototype.includes;
|
|
46
|
+
var array_from = Array.from;
|
|
47
|
+
var define_property = Object.defineProperty;
|
|
48
|
+
var get_descriptor = Object.getOwnPropertyDescriptor;
|
|
49
|
+
var object_prototype = Object.prototype;
|
|
50
|
+
var array_prototype = Array.prototype;
|
|
51
|
+
var get_prototype_of = Object.getPrototypeOf;
|
|
52
|
+
var is_extensible = Object.isExtensible;
|
|
53
|
+
var has_own_property = Object.prototype.hasOwnProperty;
|
|
54
|
+
const noop = () => {
|
|
55
|
+
};
|
|
56
|
+
function run_all(arr) {
|
|
57
|
+
for (var i = 0; i < arr.length; i++) {
|
|
58
|
+
arr[i]();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function deferred() {
|
|
62
|
+
var resolve;
|
|
63
|
+
var reject;
|
|
64
|
+
var promise = new Promise((res, rej) => {
|
|
65
|
+
resolve = res;
|
|
66
|
+
reject = rej;
|
|
67
|
+
});
|
|
68
|
+
return { promise, resolve, reject };
|
|
69
|
+
}
|
|
70
|
+
const DERIVED = 1 << 1;
|
|
71
|
+
const EFFECT = 1 << 2;
|
|
72
|
+
const RENDER_EFFECT = 1 << 3;
|
|
73
|
+
const MANAGED_EFFECT = 1 << 24;
|
|
74
|
+
const BLOCK_EFFECT = 1 << 4;
|
|
75
|
+
const BRANCH_EFFECT = 1 << 5;
|
|
76
|
+
const ROOT_EFFECT = 1 << 6;
|
|
77
|
+
const BOUNDARY_EFFECT = 1 << 7;
|
|
78
|
+
const CONNECTED = 1 << 9;
|
|
79
|
+
const CLEAN = 1 << 10;
|
|
80
|
+
const DIRTY = 1 << 11;
|
|
81
|
+
const MAYBE_DIRTY = 1 << 12;
|
|
82
|
+
const INERT = 1 << 13;
|
|
83
|
+
const DESTROYED = 1 << 14;
|
|
84
|
+
const REACTION_RAN = 1 << 15;
|
|
85
|
+
const DESTROYING = 1 << 25;
|
|
86
|
+
const EFFECT_TRANSPARENT = 1 << 16;
|
|
87
|
+
const EAGER_EFFECT = 1 << 17;
|
|
88
|
+
const HEAD_EFFECT = 1 << 18;
|
|
89
|
+
const EFFECT_PRESERVED = 1 << 19;
|
|
90
|
+
const USER_EFFECT = 1 << 20;
|
|
91
|
+
const WAS_MARKED = 1 << 16;
|
|
92
|
+
const REACTION_IS_UPDATING = 1 << 21;
|
|
93
|
+
const ASYNC = 1 << 22;
|
|
94
|
+
const ERROR_VALUE = 1 << 23;
|
|
95
|
+
const STATE_SYMBOL = /* @__PURE__ */ Symbol("$state");
|
|
96
|
+
const LEGACY_PROPS = /* @__PURE__ */ Symbol("legacy props");
|
|
97
|
+
const STALE_REACTION = new class StaleReactionError extends Error {
|
|
98
|
+
name = "StaleReactionError";
|
|
99
|
+
message = "The reaction that called `getAbortSignal()` was re-run or destroyed";
|
|
100
|
+
}();
|
|
101
|
+
const COMMENT_NODE = 8;
|
|
102
|
+
let controller = null;
|
|
103
|
+
function abort() {
|
|
104
|
+
controller?.abort(STALE_REACTION);
|
|
105
|
+
controller = null;
|
|
106
|
+
}
|
|
107
|
+
const HYDRATION_START = "[";
|
|
108
|
+
const HYDRATION_START_ELSE = "[!";
|
|
109
|
+
const HYDRATION_START_FAILED = "[?";
|
|
110
|
+
const HYDRATION_END = "]";
|
|
111
|
+
const HYDRATION_ERROR = {};
|
|
112
|
+
const ELEMENT_IS_NAMESPACED = 1;
|
|
113
|
+
const ELEMENT_PRESERVE_ATTRIBUTE_CASE = 1 << 1;
|
|
114
|
+
const ELEMENT_IS_INPUT = 1 << 2;
|
|
115
|
+
const UNINITIALIZED = /* @__PURE__ */ Symbol();
|
|
116
|
+
function unresolved_hydratable(key, stack) {
|
|
117
|
+
{
|
|
118
|
+
console.warn(`https://svelte.dev/e/unresolved_hydratable`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const BLOCK_OPEN = `<!--${HYDRATION_START}-->`;
|
|
122
|
+
const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`;
|
|
123
|
+
const EMPTY_COMMENT = `<!---->`;
|
|
124
|
+
const ATTR_REGEX = /[&"<]/g;
|
|
125
|
+
const CONTENT_REGEX = /[&<]/g;
|
|
126
|
+
function escape_html(value, is_attr) {
|
|
127
|
+
const str = String(value ?? "");
|
|
128
|
+
const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
|
|
129
|
+
pattern.lastIndex = 0;
|
|
130
|
+
let escaped = "";
|
|
131
|
+
let last = 0;
|
|
132
|
+
while (pattern.test(str)) {
|
|
133
|
+
const i = pattern.lastIndex - 1;
|
|
134
|
+
const ch = str[i];
|
|
135
|
+
escaped += str.substring(last, i) + (ch === "&" ? "&" : ch === '"' ? """ : "<");
|
|
136
|
+
last = i + 1;
|
|
137
|
+
}
|
|
138
|
+
return escaped + str.substring(last);
|
|
139
|
+
}
|
|
140
|
+
function r(e) {
|
|
141
|
+
var t, f, n = "";
|
|
142
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
143
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
144
|
+
var o = e.length;
|
|
145
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
146
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
147
|
+
return n;
|
|
148
|
+
}
|
|
149
|
+
function clsx$1() {
|
|
150
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
151
|
+
return n;
|
|
152
|
+
}
|
|
153
|
+
const replacements = {
|
|
154
|
+
translate: /* @__PURE__ */ new Map([
|
|
155
|
+
[true, "yes"],
|
|
156
|
+
[false, "no"]
|
|
157
|
+
])
|
|
158
|
+
};
|
|
159
|
+
function attr(name, value, is_boolean = false) {
|
|
160
|
+
if (name === "hidden" && value !== "until-found") {
|
|
161
|
+
is_boolean = true;
|
|
162
|
+
}
|
|
163
|
+
if (value == null || !value && is_boolean) return "";
|
|
164
|
+
const normalized = has_own_property.call(replacements, name) && replacements[name].get(value) || value;
|
|
165
|
+
const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;
|
|
166
|
+
return ` ${name}${assignment}`;
|
|
167
|
+
}
|
|
168
|
+
function clsx(value) {
|
|
169
|
+
if (typeof value === "object") {
|
|
170
|
+
return clsx$1(value);
|
|
171
|
+
} else {
|
|
172
|
+
return value ?? "";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const whitespace = [..." \n\r\f \v\uFEFF"];
|
|
176
|
+
function to_class(value, hash, directives) {
|
|
177
|
+
var classname = value == null ? "" : "" + value;
|
|
178
|
+
if (hash) {
|
|
179
|
+
classname = classname ? classname + " " + hash : hash;
|
|
180
|
+
}
|
|
181
|
+
if (directives) {
|
|
182
|
+
for (var key of Object.keys(directives)) {
|
|
183
|
+
if (directives[key]) {
|
|
184
|
+
classname = classname ? classname + " " + key : key;
|
|
185
|
+
} else if (classname.length) {
|
|
186
|
+
var len = key.length;
|
|
187
|
+
var a = 0;
|
|
188
|
+
while ((a = classname.indexOf(key, a)) >= 0) {
|
|
189
|
+
var b = a + len;
|
|
190
|
+
if ((a === 0 || whitespace.includes(classname[a - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
|
|
191
|
+
classname = (a === 0 ? "" : classname.substring(0, a)) + classname.substring(b + 1);
|
|
192
|
+
} else {
|
|
193
|
+
a = b;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return classname === "" ? null : classname;
|
|
200
|
+
}
|
|
201
|
+
function append_styles(styles, important = false) {
|
|
202
|
+
var separator = important ? " !important;" : ";";
|
|
203
|
+
var css = "";
|
|
204
|
+
for (var key of Object.keys(styles)) {
|
|
205
|
+
var value = styles[key];
|
|
206
|
+
if (value != null && value !== "") {
|
|
207
|
+
css += " " + key + ": " + value + separator;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return css;
|
|
211
|
+
}
|
|
212
|
+
function to_css_name(name) {
|
|
213
|
+
if (name[0] !== "-" || name[1] !== "-") {
|
|
214
|
+
return name.toLowerCase();
|
|
215
|
+
}
|
|
216
|
+
return name;
|
|
217
|
+
}
|
|
218
|
+
function to_style(value, styles) {
|
|
219
|
+
if (styles) {
|
|
220
|
+
var new_style = "";
|
|
221
|
+
var normal_styles;
|
|
222
|
+
var important_styles;
|
|
223
|
+
if (Array.isArray(styles)) {
|
|
224
|
+
normal_styles = styles[0];
|
|
225
|
+
important_styles = styles[1];
|
|
226
|
+
} else {
|
|
227
|
+
normal_styles = styles;
|
|
228
|
+
}
|
|
229
|
+
if (value) {
|
|
230
|
+
value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim();
|
|
231
|
+
var in_str = false;
|
|
232
|
+
var in_apo = 0;
|
|
233
|
+
var in_comment = false;
|
|
234
|
+
var reserved_names = [];
|
|
235
|
+
if (normal_styles) {
|
|
236
|
+
reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
|
|
237
|
+
}
|
|
238
|
+
if (important_styles) {
|
|
239
|
+
reserved_names.push(...Object.keys(important_styles).map(to_css_name));
|
|
240
|
+
}
|
|
241
|
+
var start_index = 0;
|
|
242
|
+
var name_index = -1;
|
|
243
|
+
const len = value.length;
|
|
244
|
+
for (var i = 0; i < len; i++) {
|
|
245
|
+
var c = value[i];
|
|
246
|
+
if (in_comment) {
|
|
247
|
+
if (c === "/" && value[i - 1] === "*") {
|
|
248
|
+
in_comment = false;
|
|
249
|
+
}
|
|
250
|
+
} else if (in_str) {
|
|
251
|
+
if (in_str === c) {
|
|
252
|
+
in_str = false;
|
|
253
|
+
}
|
|
254
|
+
} else if (c === "/" && value[i + 1] === "*") {
|
|
255
|
+
in_comment = true;
|
|
256
|
+
} else if (c === '"' || c === "'") {
|
|
257
|
+
in_str = c;
|
|
258
|
+
} else if (c === "(") {
|
|
259
|
+
in_apo++;
|
|
260
|
+
} else if (c === ")") {
|
|
261
|
+
in_apo--;
|
|
262
|
+
}
|
|
263
|
+
if (!in_comment && in_str === false && in_apo === 0) {
|
|
264
|
+
if (c === ":" && name_index === -1) {
|
|
265
|
+
name_index = i;
|
|
266
|
+
} else if (c === ";" || i === len - 1) {
|
|
267
|
+
if (name_index !== -1) {
|
|
268
|
+
var name = to_css_name(value.substring(start_index, name_index).trim());
|
|
269
|
+
if (!reserved_names.includes(name)) {
|
|
270
|
+
if (c !== ";") {
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
var property = value.substring(start_index, i).trim();
|
|
274
|
+
new_style += " " + property + ";";
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
start_index = i + 1;
|
|
278
|
+
name_index = -1;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (normal_styles) {
|
|
284
|
+
new_style += append_styles(normal_styles);
|
|
285
|
+
}
|
|
286
|
+
if (important_styles) {
|
|
287
|
+
new_style += append_styles(important_styles, true);
|
|
288
|
+
}
|
|
289
|
+
new_style = new_style.trim();
|
|
290
|
+
return new_style === "" ? null : new_style;
|
|
291
|
+
}
|
|
292
|
+
return value == null ? null : String(value);
|
|
293
|
+
}
|
|
294
|
+
const VOID_ELEMENT_NAMES = [
|
|
295
|
+
"area",
|
|
296
|
+
"base",
|
|
297
|
+
"br",
|
|
298
|
+
"col",
|
|
299
|
+
"command",
|
|
300
|
+
"embed",
|
|
301
|
+
"hr",
|
|
302
|
+
"img",
|
|
303
|
+
"input",
|
|
304
|
+
"keygen",
|
|
305
|
+
"link",
|
|
306
|
+
"meta",
|
|
307
|
+
"param",
|
|
308
|
+
"source",
|
|
309
|
+
"track",
|
|
310
|
+
"wbr"
|
|
311
|
+
];
|
|
312
|
+
function is_void(name) {
|
|
313
|
+
return VOID_ELEMENT_NAMES.includes(name) || name.toLowerCase() === "!doctype";
|
|
314
|
+
}
|
|
315
|
+
const DOM_BOOLEAN_ATTRIBUTES = [
|
|
316
|
+
"allowfullscreen",
|
|
317
|
+
"async",
|
|
318
|
+
"autofocus",
|
|
319
|
+
"autoplay",
|
|
320
|
+
"checked",
|
|
321
|
+
"controls",
|
|
322
|
+
"default",
|
|
323
|
+
"disabled",
|
|
324
|
+
"formnovalidate",
|
|
325
|
+
"indeterminate",
|
|
326
|
+
"inert",
|
|
327
|
+
"ismap",
|
|
328
|
+
"loop",
|
|
329
|
+
"multiple",
|
|
330
|
+
"muted",
|
|
331
|
+
"nomodule",
|
|
332
|
+
"novalidate",
|
|
333
|
+
"open",
|
|
334
|
+
"playsinline",
|
|
335
|
+
"readonly",
|
|
336
|
+
"required",
|
|
337
|
+
"reversed",
|
|
338
|
+
"seamless",
|
|
339
|
+
"selected",
|
|
340
|
+
"webkitdirectory",
|
|
341
|
+
"defer",
|
|
342
|
+
"disablepictureinpicture",
|
|
343
|
+
"disableremoteplayback"
|
|
344
|
+
];
|
|
345
|
+
function is_boolean_attribute(name) {
|
|
346
|
+
return DOM_BOOLEAN_ATTRIBUTES.includes(name);
|
|
347
|
+
}
|
|
348
|
+
const PASSIVE_EVENTS = ["touchstart", "touchmove"];
|
|
349
|
+
function is_passive_event(name) {
|
|
350
|
+
return PASSIVE_EVENTS.includes(name);
|
|
351
|
+
}
|
|
352
|
+
const RAW_TEXT_ELEMENTS = (
|
|
353
|
+
/** @type {const} */
|
|
354
|
+
["textarea", "script", "style", "title"]
|
|
355
|
+
);
|
|
356
|
+
function is_raw_text_element(name) {
|
|
357
|
+
return RAW_TEXT_ELEMENTS.includes(
|
|
358
|
+
/** @type {typeof RAW_TEXT_ELEMENTS[number]} */
|
|
359
|
+
name
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
const REGEX_VALID_TAG_NAME = /^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9.\-_\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]+)*$/u;
|
|
363
|
+
const INVALID_ATTR_NAME_CHAR_REGEX = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
|
|
364
|
+
function element(renderer, tag, attributes_fn = noop, children_fn = noop) {
|
|
365
|
+
renderer.push("<!---->");
|
|
366
|
+
{
|
|
367
|
+
if (!REGEX_VALID_TAG_NAME.test(tag)) {
|
|
368
|
+
dynamic_element_invalid_tag(tag);
|
|
369
|
+
}
|
|
370
|
+
renderer.push(`<${tag}`);
|
|
371
|
+
attributes_fn();
|
|
372
|
+
renderer.push(`>`);
|
|
373
|
+
if (!is_void(tag)) {
|
|
374
|
+
children_fn();
|
|
375
|
+
if (!is_raw_text_element(tag)) {
|
|
376
|
+
renderer.push(EMPTY_COMMENT);
|
|
377
|
+
}
|
|
378
|
+
renderer.push(`</${tag}>`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
renderer.push("<!---->");
|
|
382
|
+
}
|
|
383
|
+
function render(component, options = {}) {
|
|
384
|
+
if (options.csp?.hash && options.csp.nonce) {
|
|
385
|
+
invalid_csp();
|
|
386
|
+
}
|
|
387
|
+
return Renderer.render(
|
|
388
|
+
/** @type {Component<Props>} */
|
|
389
|
+
component,
|
|
390
|
+
options
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
function head(hash, renderer, fn) {
|
|
394
|
+
renderer.head((renderer2) => {
|
|
395
|
+
renderer2.push(`<!--${hash}-->`);
|
|
396
|
+
renderer2.child(fn);
|
|
397
|
+
renderer2.push(EMPTY_COMMENT);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
function attributes(attrs, css_hash, classes, styles, flags = 0) {
|
|
401
|
+
if (styles) {
|
|
402
|
+
attrs.style = to_style(attrs.style, styles);
|
|
403
|
+
}
|
|
404
|
+
if (attrs.class) {
|
|
405
|
+
attrs.class = clsx(attrs.class);
|
|
406
|
+
}
|
|
407
|
+
if (css_hash || classes) {
|
|
408
|
+
attrs.class = to_class(attrs.class, css_hash, classes);
|
|
409
|
+
}
|
|
410
|
+
let attr_str = "";
|
|
411
|
+
let name;
|
|
412
|
+
const is_html = (flags & ELEMENT_IS_NAMESPACED) === 0;
|
|
413
|
+
const lowercase = (flags & ELEMENT_PRESERVE_ATTRIBUTE_CASE) === 0;
|
|
414
|
+
const is_input = (flags & ELEMENT_IS_INPUT) !== 0;
|
|
415
|
+
for (name of Object.keys(attrs)) {
|
|
416
|
+
if (typeof attrs[name] === "function") continue;
|
|
417
|
+
if (name[0] === "$" && name[1] === "$") continue;
|
|
418
|
+
if (INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;
|
|
419
|
+
var value = attrs[name];
|
|
420
|
+
var lower = name.toLowerCase();
|
|
421
|
+
if (lowercase) name = lower;
|
|
422
|
+
if (lower.length > 2 && lower.startsWith("on")) continue;
|
|
423
|
+
if (is_input) {
|
|
424
|
+
if (name === "defaultvalue" || name === "defaultchecked") {
|
|
425
|
+
name = name === "defaultvalue" ? "value" : "checked";
|
|
426
|
+
if (attrs[name]) continue;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
attr_str += attr(name, value, is_html && is_boolean_attribute(name));
|
|
430
|
+
}
|
|
431
|
+
return attr_str;
|
|
432
|
+
}
|
|
433
|
+
function attr_class(value, hash, directives) {
|
|
434
|
+
var result = to_class(value, hash, directives);
|
|
435
|
+
return result ? ` class="${escape_html(result, true)}"` : "";
|
|
436
|
+
}
|
|
437
|
+
function attr_style(value, directives) {
|
|
438
|
+
var result = to_style(value, directives);
|
|
439
|
+
return result ? ` style="${escape_html(result, true)}"` : "";
|
|
440
|
+
}
|
|
441
|
+
function bind_props(props_parent, props_now) {
|
|
442
|
+
for (const key of Object.keys(props_now)) {
|
|
443
|
+
const initial_value = props_parent[key];
|
|
444
|
+
const value = props_now[key];
|
|
445
|
+
if (initial_value === void 0 && value !== void 0 && Object.getOwnPropertyDescriptor(props_parent, key)?.set) {
|
|
446
|
+
props_parent[key] = value;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function ensure_array_like(array_like_or_iterator) {
|
|
451
|
+
if (array_like_or_iterator) {
|
|
452
|
+
return array_like_or_iterator.length !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator);
|
|
453
|
+
}
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
function once(get_value) {
|
|
457
|
+
let value = (
|
|
458
|
+
/** @type {V} */
|
|
459
|
+
UNINITIALIZED
|
|
460
|
+
);
|
|
461
|
+
return () => {
|
|
462
|
+
if (value === UNINITIALIZED) {
|
|
463
|
+
value = get_value();
|
|
464
|
+
}
|
|
465
|
+
return value;
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function derived(fn) {
|
|
469
|
+
const get_value = ssr_context === null ? fn : once(fn);
|
|
470
|
+
let updated_value;
|
|
471
|
+
return function(new_value) {
|
|
472
|
+
if (arguments.length === 0) {
|
|
473
|
+
return updated_value ?? get_value();
|
|
474
|
+
}
|
|
475
|
+
updated_value = new_value;
|
|
476
|
+
return updated_value;
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
let text_encoder;
|
|
480
|
+
let crypto;
|
|
481
|
+
const obfuscated_import = (module_name) => import(
|
|
482
|
+
/* @vite-ignore */
|
|
483
|
+
module_name
|
|
484
|
+
);
|
|
485
|
+
async function sha256(data) {
|
|
486
|
+
text_encoder ??= new TextEncoder();
|
|
487
|
+
crypto ??= globalThis.crypto?.subtle?.digest ? globalThis.crypto : (
|
|
488
|
+
// @ts-ignore - we don't install node types in the prod build
|
|
489
|
+
// don't use import('node:crypto') directly because static analysers will think we rely on node when we don't
|
|
490
|
+
(await obfuscated_import("node:crypto")).webcrypto
|
|
491
|
+
);
|
|
492
|
+
const hash_buffer = await crypto.subtle.digest("SHA-256", text_encoder.encode(data));
|
|
493
|
+
return base64_encode(hash_buffer);
|
|
494
|
+
}
|
|
495
|
+
function base64_encode(bytes) {
|
|
496
|
+
if (globalThis.Buffer) {
|
|
497
|
+
return globalThis.Buffer.from(bytes).toString("base64");
|
|
498
|
+
}
|
|
499
|
+
let binary = "";
|
|
500
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
501
|
+
binary += String.fromCharCode(bytes[i]);
|
|
502
|
+
}
|
|
503
|
+
return btoa(binary);
|
|
504
|
+
}
|
|
505
|
+
class Renderer {
|
|
506
|
+
/**
|
|
507
|
+
* The contents of the renderer.
|
|
508
|
+
* @type {RendererItem[]}
|
|
509
|
+
*/
|
|
510
|
+
#out = [];
|
|
511
|
+
/**
|
|
512
|
+
* Any `onDestroy` callbacks registered during execution of this renderer.
|
|
513
|
+
* @type {(() => void)[] | undefined}
|
|
514
|
+
*/
|
|
515
|
+
#on_destroy = void 0;
|
|
516
|
+
/**
|
|
517
|
+
* Whether this renderer is a component body.
|
|
518
|
+
* @type {boolean}
|
|
519
|
+
*/
|
|
520
|
+
#is_component_body = false;
|
|
521
|
+
/**
|
|
522
|
+
* If set, this renderer is an error boundary. When async collection
|
|
523
|
+
* of the children fails, the failed snippet is rendered instead.
|
|
524
|
+
* @type {{
|
|
525
|
+
* failed: (renderer: Renderer, error: unknown, reset: () => void) => void;
|
|
526
|
+
* transformError: (error: unknown) => unknown;
|
|
527
|
+
* context: SSRContext | null;
|
|
528
|
+
* } | null}
|
|
529
|
+
*/
|
|
530
|
+
#boundary = null;
|
|
531
|
+
/**
|
|
532
|
+
* The type of string content that this renderer is accumulating.
|
|
533
|
+
* @type {RendererType}
|
|
534
|
+
*/
|
|
535
|
+
type;
|
|
536
|
+
/** @type {Renderer | undefined} */
|
|
537
|
+
#parent;
|
|
538
|
+
/**
|
|
539
|
+
* Asynchronous work associated with this renderer
|
|
540
|
+
* @type {Promise<void> | undefined}
|
|
541
|
+
*/
|
|
542
|
+
promise = void 0;
|
|
543
|
+
/**
|
|
544
|
+
* State which is associated with the content tree as a whole.
|
|
545
|
+
* It will be re-exposed, uncopied, on all children.
|
|
546
|
+
* @type {SSRState}
|
|
547
|
+
* @readonly
|
|
548
|
+
*/
|
|
549
|
+
global;
|
|
550
|
+
/**
|
|
551
|
+
* State that is local to the branch it is declared in.
|
|
552
|
+
* It will be shallow-copied to all children.
|
|
553
|
+
*
|
|
554
|
+
* @type {{ select_value: string | undefined }}
|
|
555
|
+
*/
|
|
556
|
+
local;
|
|
557
|
+
/**
|
|
558
|
+
* @param {SSRState} global
|
|
559
|
+
* @param {Renderer | undefined} [parent]
|
|
560
|
+
*/
|
|
561
|
+
constructor(global, parent) {
|
|
562
|
+
this.#parent = parent;
|
|
563
|
+
this.global = global;
|
|
564
|
+
this.local = parent ? { ...parent.local } : { select_value: void 0 };
|
|
565
|
+
this.type = parent ? parent.type : "body";
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* @param {(renderer: Renderer) => void} fn
|
|
569
|
+
*/
|
|
570
|
+
head(fn) {
|
|
571
|
+
const head2 = new Renderer(this.global, this);
|
|
572
|
+
head2.type = "head";
|
|
573
|
+
this.#out.push(head2);
|
|
574
|
+
head2.child(fn);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* @param {Array<Promise<void>>} blockers
|
|
578
|
+
* @param {(renderer: Renderer) => void} fn
|
|
579
|
+
*/
|
|
580
|
+
async_block(blockers, fn) {
|
|
581
|
+
this.#out.push(BLOCK_OPEN);
|
|
582
|
+
this.async(blockers, fn);
|
|
583
|
+
this.#out.push(BLOCK_CLOSE);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* @param {Array<Promise<void>>} blockers
|
|
587
|
+
* @param {(renderer: Renderer) => void} fn
|
|
588
|
+
*/
|
|
589
|
+
async(blockers, fn) {
|
|
590
|
+
let callback = fn;
|
|
591
|
+
if (blockers.length > 0) {
|
|
592
|
+
const context = ssr_context;
|
|
593
|
+
callback = (renderer) => {
|
|
594
|
+
return Promise.all(blockers).then(() => {
|
|
595
|
+
const previous_context = ssr_context;
|
|
596
|
+
try {
|
|
597
|
+
set_ssr_context(context);
|
|
598
|
+
return fn(renderer);
|
|
599
|
+
} finally {
|
|
600
|
+
set_ssr_context(previous_context);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
this.child(callback);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* @param {Array<() => void>} thunks
|
|
609
|
+
*/
|
|
610
|
+
run(thunks) {
|
|
611
|
+
const context = ssr_context;
|
|
612
|
+
let promise = Promise.resolve(thunks[0]());
|
|
613
|
+
const promises = [promise];
|
|
614
|
+
for (const fn of thunks.slice(1)) {
|
|
615
|
+
promise = promise.then(() => {
|
|
616
|
+
const previous_context = ssr_context;
|
|
617
|
+
set_ssr_context(context);
|
|
618
|
+
try {
|
|
619
|
+
return fn();
|
|
620
|
+
} finally {
|
|
621
|
+
set_ssr_context(previous_context);
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
promises.push(promise);
|
|
625
|
+
}
|
|
626
|
+
promise.catch(noop);
|
|
627
|
+
this.promise = promise;
|
|
628
|
+
return promises;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* @param {(renderer: Renderer) => MaybePromise<void>} fn
|
|
632
|
+
*/
|
|
633
|
+
child_block(fn) {
|
|
634
|
+
this.#out.push(BLOCK_OPEN);
|
|
635
|
+
this.child(fn);
|
|
636
|
+
this.#out.push(BLOCK_CLOSE);
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Create a child renderer. The child renderer inherits the state from the parent,
|
|
640
|
+
* but has its own content.
|
|
641
|
+
* @param {(renderer: Renderer) => MaybePromise<void>} fn
|
|
642
|
+
*/
|
|
643
|
+
child(fn) {
|
|
644
|
+
const child = new Renderer(this.global, this);
|
|
645
|
+
this.#out.push(child);
|
|
646
|
+
const parent = ssr_context;
|
|
647
|
+
set_ssr_context({
|
|
648
|
+
...ssr_context,
|
|
649
|
+
p: parent,
|
|
650
|
+
c: null,
|
|
651
|
+
r: child
|
|
652
|
+
});
|
|
653
|
+
const result = fn(child);
|
|
654
|
+
set_ssr_context(parent);
|
|
655
|
+
if (result instanceof Promise) {
|
|
656
|
+
result.catch(noop);
|
|
657
|
+
result.finally(() => set_ssr_context(null)).catch(noop);
|
|
658
|
+
if (child.global.mode === "sync") {
|
|
659
|
+
await_invalid();
|
|
660
|
+
}
|
|
661
|
+
child.promise = result;
|
|
662
|
+
}
|
|
663
|
+
return child;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Render children inside an error boundary. If the children throw and the API-level
|
|
667
|
+
* `transformError` transform handles the error (doesn't re-throw), the `failed` snippet is
|
|
668
|
+
* rendered instead. Otherwise the error propagates.
|
|
669
|
+
*
|
|
670
|
+
* @param {{ failed?: (renderer: Renderer, error: unknown, reset: () => void) => void }} props
|
|
671
|
+
* @param {(renderer: Renderer) => MaybePromise<void>} children_fn
|
|
672
|
+
*/
|
|
673
|
+
boundary(props, children_fn) {
|
|
674
|
+
const child = new Renderer(this.global, this);
|
|
675
|
+
this.#out.push(child);
|
|
676
|
+
const parent_context = ssr_context;
|
|
677
|
+
if (props.failed) {
|
|
678
|
+
child.#boundary = {
|
|
679
|
+
failed: props.failed,
|
|
680
|
+
transformError: this.global.transformError,
|
|
681
|
+
context: parent_context
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
set_ssr_context({
|
|
685
|
+
...ssr_context,
|
|
686
|
+
p: parent_context,
|
|
687
|
+
c: null,
|
|
688
|
+
r: child
|
|
689
|
+
});
|
|
690
|
+
try {
|
|
691
|
+
const result = children_fn(child);
|
|
692
|
+
set_ssr_context(parent_context);
|
|
693
|
+
if (result instanceof Promise) {
|
|
694
|
+
if (child.global.mode === "sync") {
|
|
695
|
+
await_invalid();
|
|
696
|
+
}
|
|
697
|
+
result.catch(noop);
|
|
698
|
+
child.promise = result;
|
|
699
|
+
}
|
|
700
|
+
} catch (error) {
|
|
701
|
+
set_ssr_context(parent_context);
|
|
702
|
+
const failed_snippet = props.failed;
|
|
703
|
+
if (!failed_snippet) throw error;
|
|
704
|
+
const result = this.global.transformError(error);
|
|
705
|
+
child.#out.length = 0;
|
|
706
|
+
child.#boundary = null;
|
|
707
|
+
if (result instanceof Promise) {
|
|
708
|
+
if (this.global.mode === "sync") {
|
|
709
|
+
await_invalid();
|
|
710
|
+
}
|
|
711
|
+
child.promise = /** @type {Promise<unknown>} */
|
|
712
|
+
result.then((transformed) => {
|
|
713
|
+
set_ssr_context(parent_context);
|
|
714
|
+
child.#out.push(Renderer.#serialize_failed_boundary(transformed));
|
|
715
|
+
failed_snippet(child, transformed, noop);
|
|
716
|
+
child.#out.push(BLOCK_CLOSE);
|
|
717
|
+
});
|
|
718
|
+
child.promise.catch(noop);
|
|
719
|
+
} else {
|
|
720
|
+
child.#out.push(Renderer.#serialize_failed_boundary(result));
|
|
721
|
+
failed_snippet(child, result, noop);
|
|
722
|
+
child.#out.push(BLOCK_CLOSE);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Create a component renderer. The component renderer inherits the state from the parent,
|
|
728
|
+
* but has its own content. It is treated as an ordering boundary for ondestroy callbacks.
|
|
729
|
+
* @param {(renderer: Renderer) => MaybePromise<void>} fn
|
|
730
|
+
* @param {Function} [component_fn]
|
|
731
|
+
* @returns {void}
|
|
732
|
+
*/
|
|
733
|
+
component(fn, component_fn) {
|
|
734
|
+
push();
|
|
735
|
+
const child = this.child(fn);
|
|
736
|
+
child.#is_component_body = true;
|
|
737
|
+
pop();
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* @param {Record<string, any>} attrs
|
|
741
|
+
* @param {(renderer: Renderer) => void} fn
|
|
742
|
+
* @param {string | undefined} [css_hash]
|
|
743
|
+
* @param {Record<string, boolean> | undefined} [classes]
|
|
744
|
+
* @param {Record<string, string> | undefined} [styles]
|
|
745
|
+
* @param {number | undefined} [flags]
|
|
746
|
+
* @param {boolean | undefined} [is_rich]
|
|
747
|
+
* @returns {void}
|
|
748
|
+
*/
|
|
749
|
+
select(attrs, fn, css_hash, classes, styles, flags, is_rich) {
|
|
750
|
+
const { value, ...select_attrs } = attrs;
|
|
751
|
+
this.push(`<select${attributes(select_attrs, css_hash, classes, styles, flags)}>`);
|
|
752
|
+
this.child((renderer) => {
|
|
753
|
+
renderer.local.select_value = value;
|
|
754
|
+
fn(renderer);
|
|
755
|
+
});
|
|
756
|
+
this.push(`${is_rich ? "<!>" : ""}</select>`);
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* @param {Record<string, any>} attrs
|
|
760
|
+
* @param {string | number | boolean | ((renderer: Renderer) => void)} body
|
|
761
|
+
* @param {string | undefined} [css_hash]
|
|
762
|
+
* @param {Record<string, boolean> | undefined} [classes]
|
|
763
|
+
* @param {Record<string, string> | undefined} [styles]
|
|
764
|
+
* @param {number | undefined} [flags]
|
|
765
|
+
* @param {boolean | undefined} [is_rich]
|
|
766
|
+
*/
|
|
767
|
+
option(attrs, body, css_hash, classes, styles, flags, is_rich) {
|
|
768
|
+
this.#out.push(`<option${attributes(attrs, css_hash, classes, styles, flags)}`);
|
|
769
|
+
const close = (renderer, value, { head: head2, body: body2 }) => {
|
|
770
|
+
if (has_own_property.call(attrs, "value")) {
|
|
771
|
+
value = attrs.value;
|
|
772
|
+
}
|
|
773
|
+
if (value === this.local.select_value) {
|
|
774
|
+
renderer.#out.push(' selected=""');
|
|
775
|
+
}
|
|
776
|
+
renderer.#out.push(`>${body2}${is_rich ? "<!>" : ""}</option>`);
|
|
777
|
+
if (head2) {
|
|
778
|
+
renderer.head((child) => child.push(head2));
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
if (typeof body === "function") {
|
|
782
|
+
this.child((renderer) => {
|
|
783
|
+
const r2 = new Renderer(this.global, this);
|
|
784
|
+
body(r2);
|
|
785
|
+
if (this.global.mode === "async") {
|
|
786
|
+
return r2.#collect_content_async().then((content) => {
|
|
787
|
+
close(renderer, content.body.replaceAll("<!---->", ""), content);
|
|
788
|
+
});
|
|
789
|
+
} else {
|
|
790
|
+
const content = r2.#collect_content();
|
|
791
|
+
close(renderer, content.body.replaceAll("<!---->", ""), content);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
} else {
|
|
795
|
+
close(this, body, { body: escape_html(body) });
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* @param {(renderer: Renderer) => void} fn
|
|
800
|
+
*/
|
|
801
|
+
title(fn) {
|
|
802
|
+
const path = this.get_path();
|
|
803
|
+
const close = (head2) => {
|
|
804
|
+
this.global.set_title(head2, path);
|
|
805
|
+
};
|
|
806
|
+
this.child((renderer) => {
|
|
807
|
+
const r2 = new Renderer(renderer.global, renderer);
|
|
808
|
+
fn(r2);
|
|
809
|
+
if (renderer.global.mode === "async") {
|
|
810
|
+
return r2.#collect_content_async().then((content) => {
|
|
811
|
+
close(content.head);
|
|
812
|
+
});
|
|
813
|
+
} else {
|
|
814
|
+
const content = r2.#collect_content();
|
|
815
|
+
close(content.head);
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* @param {string | (() => Promise<string>)} content
|
|
821
|
+
*/
|
|
822
|
+
push(content) {
|
|
823
|
+
if (typeof content === "function") {
|
|
824
|
+
this.child(async (renderer) => renderer.push(await content()));
|
|
825
|
+
} else {
|
|
826
|
+
this.#out.push(content);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* @param {() => void} fn
|
|
831
|
+
*/
|
|
832
|
+
on_destroy(fn) {
|
|
833
|
+
(this.#on_destroy ??= []).push(fn);
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* @returns {number[]}
|
|
837
|
+
*/
|
|
838
|
+
get_path() {
|
|
839
|
+
return this.#parent ? [...this.#parent.get_path(), this.#parent.#out.indexOf(this)] : [];
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* @deprecated this is needed for legacy component bindings
|
|
843
|
+
*/
|
|
844
|
+
copy() {
|
|
845
|
+
const copy = new Renderer(this.global, this.#parent);
|
|
846
|
+
copy.#out = this.#out.map((item) => item instanceof Renderer ? item.copy() : item);
|
|
847
|
+
copy.promise = this.promise;
|
|
848
|
+
return copy;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* @param {Renderer} other
|
|
852
|
+
* @deprecated this is needed for legacy component bindings
|
|
853
|
+
*/
|
|
854
|
+
subsume(other) {
|
|
855
|
+
if (this.global.mode !== other.global.mode) {
|
|
856
|
+
throw new Error(
|
|
857
|
+
"invariant: A renderer cannot switch modes. If you're seeing this, there's a compiler bug. File an issue!"
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
this.local = other.local;
|
|
861
|
+
this.#out = other.#out.map((item, i) => {
|
|
862
|
+
const current = this.#out[i];
|
|
863
|
+
if (current instanceof Renderer && item instanceof Renderer) {
|
|
864
|
+
current.subsume(item);
|
|
865
|
+
return current;
|
|
866
|
+
}
|
|
867
|
+
return item;
|
|
868
|
+
});
|
|
869
|
+
this.promise = other.promise;
|
|
870
|
+
this.type = other.type;
|
|
871
|
+
}
|
|
872
|
+
get length() {
|
|
873
|
+
return this.#out.length;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Creates the hydration comment that marks the start of a failed boundary.
|
|
877
|
+
* The error is JSON-serialized and embedded inside an HTML comment for the client
|
|
878
|
+
* to parse during hydration. The JSON is escaped to prevent `-->` or `<!--` sequences
|
|
879
|
+
* from breaking out of the comment (XSS). Uses unicode escapes which `JSON.parse()`
|
|
880
|
+
* handles transparently.
|
|
881
|
+
* @param {unknown} error
|
|
882
|
+
* @returns {string}
|
|
883
|
+
*/
|
|
884
|
+
static #serialize_failed_boundary(error) {
|
|
885
|
+
var json = JSON.stringify(error);
|
|
886
|
+
var escaped = json.replace(/>/g, "\\u003e").replace(/</g, "\\u003c");
|
|
887
|
+
return `<!--${HYDRATION_START_FAILED}${escaped}-->`;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Only available on the server and when compiling with the `server` option.
|
|
891
|
+
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
|
|
892
|
+
* @template {Record<string, any>} Props
|
|
893
|
+
* @param {Component<Props>} component
|
|
894
|
+
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} [options]
|
|
895
|
+
* @returns {RenderOutput}
|
|
896
|
+
*/
|
|
897
|
+
static render(component, options = {}) {
|
|
898
|
+
let sync;
|
|
899
|
+
const result = (
|
|
900
|
+
/** @type {RenderOutput} */
|
|
901
|
+
{}
|
|
902
|
+
);
|
|
903
|
+
Object.defineProperties(result, {
|
|
904
|
+
html: {
|
|
905
|
+
get: () => {
|
|
906
|
+
return (sync ??= Renderer.#render(component, options)).body;
|
|
907
|
+
}
|
|
908
|
+
},
|
|
909
|
+
head: {
|
|
910
|
+
get: () => {
|
|
911
|
+
return (sync ??= Renderer.#render(component, options)).head;
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
body: {
|
|
915
|
+
get: () => {
|
|
916
|
+
return (sync ??= Renderer.#render(component, options)).body;
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
hashes: {
|
|
920
|
+
value: {
|
|
921
|
+
script: ""
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
then: {
|
|
925
|
+
value: (
|
|
926
|
+
/**
|
|
927
|
+
* this is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function.
|
|
928
|
+
*
|
|
929
|
+
* @template TResult1
|
|
930
|
+
* @template [TResult2=never]
|
|
931
|
+
* @param { (value: SyncRenderOutput) => TResult1 } onfulfilled
|
|
932
|
+
* @param { (reason: unknown) => TResult2 } onrejected
|
|
933
|
+
*/
|
|
934
|
+
(onfulfilled, onrejected) => {
|
|
935
|
+
{
|
|
936
|
+
const result2 = sync ??= Renderer.#render(component, options);
|
|
937
|
+
const user_result = onfulfilled({
|
|
938
|
+
head: result2.head,
|
|
939
|
+
body: result2.body,
|
|
940
|
+
html: result2.body,
|
|
941
|
+
hashes: { script: [] }
|
|
942
|
+
});
|
|
943
|
+
return Promise.resolve(user_result);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
)
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
return result;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Collect all of the `onDestroy` callbacks registered during rendering. In an async context, this is only safe to call
|
|
953
|
+
* after awaiting `collect_async`.
|
|
954
|
+
*
|
|
955
|
+
* Child renderers are "porous" and don't affect execution order, but component body renderers
|
|
956
|
+
* create ordering boundaries. Within a renderer, callbacks run in order until hitting a component boundary.
|
|
957
|
+
* @returns {Iterable<() => void>}
|
|
958
|
+
*/
|
|
959
|
+
*#collect_on_destroy() {
|
|
960
|
+
for (const component of this.#traverse_components()) {
|
|
961
|
+
yield* component.#collect_ondestroy();
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Performs a depth-first search of renderers, yielding the deepest components first, then additional components as we backtrack up the tree.
|
|
966
|
+
* @returns {Iterable<Renderer>}
|
|
967
|
+
*/
|
|
968
|
+
*#traverse_components() {
|
|
969
|
+
for (const child of this.#out) {
|
|
970
|
+
if (typeof child !== "string") {
|
|
971
|
+
yield* child.#traverse_components();
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (this.#is_component_body) {
|
|
975
|
+
yield this;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* @returns {Iterable<() => void>}
|
|
980
|
+
*/
|
|
981
|
+
*#collect_ondestroy() {
|
|
982
|
+
if (this.#on_destroy) {
|
|
983
|
+
for (const fn of this.#on_destroy) {
|
|
984
|
+
yield fn;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
for (const child of this.#out) {
|
|
988
|
+
if (child instanceof Renderer && !child.#is_component_body) {
|
|
989
|
+
yield* child.#collect_ondestroy();
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Render a component. Throws if any of the children are performing asynchronous work.
|
|
995
|
+
*
|
|
996
|
+
* @template {Record<string, any>} Props
|
|
997
|
+
* @param {Component<Props>} component
|
|
998
|
+
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string }} options
|
|
999
|
+
* @returns {AccumulatedContent}
|
|
1000
|
+
*/
|
|
1001
|
+
static #render(component, options) {
|
|
1002
|
+
var previous_context = ssr_context;
|
|
1003
|
+
try {
|
|
1004
|
+
const renderer = Renderer.#open_render("sync", component, options);
|
|
1005
|
+
const content = renderer.#collect_content();
|
|
1006
|
+
return Renderer.#close_render(content, renderer);
|
|
1007
|
+
} finally {
|
|
1008
|
+
abort();
|
|
1009
|
+
set_ssr_context(previous_context);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Render a component.
|
|
1014
|
+
*
|
|
1015
|
+
* @template {Record<string, any>} Props
|
|
1016
|
+
* @param {Component<Props>} component
|
|
1017
|
+
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} options
|
|
1018
|
+
* @returns {Promise<AccumulatedContent & { hashes: { script: Sha256Source[] } }>}
|
|
1019
|
+
*/
|
|
1020
|
+
static async #render_async(component, options) {
|
|
1021
|
+
const previous_context = ssr_context;
|
|
1022
|
+
try {
|
|
1023
|
+
const renderer = Renderer.#open_render("async", component, options);
|
|
1024
|
+
const content = await renderer.#collect_content_async();
|
|
1025
|
+
const hydratables = await renderer.#collect_hydratables();
|
|
1026
|
+
if (hydratables !== null) {
|
|
1027
|
+
content.head = hydratables + content.head;
|
|
1028
|
+
}
|
|
1029
|
+
return Renderer.#close_render(content, renderer);
|
|
1030
|
+
} finally {
|
|
1031
|
+
set_ssr_context(previous_context);
|
|
1032
|
+
abort();
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Collect all of the code from the `out` array and return it as a string, or a promise resolving to a string.
|
|
1037
|
+
* @param {AccumulatedContent} content
|
|
1038
|
+
* @returns {AccumulatedContent}
|
|
1039
|
+
*/
|
|
1040
|
+
#collect_content(content = { head: "", body: "" }) {
|
|
1041
|
+
for (const item of this.#out) {
|
|
1042
|
+
if (typeof item === "string") {
|
|
1043
|
+
content[this.type] += item;
|
|
1044
|
+
} else if (item instanceof Renderer) {
|
|
1045
|
+
item.#collect_content(content);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return content;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Collect all of the code from the `out` array and return it as a string.
|
|
1052
|
+
* @param {AccumulatedContent} content
|
|
1053
|
+
* @returns {Promise<AccumulatedContent>}
|
|
1054
|
+
*/
|
|
1055
|
+
async #collect_content_async(content = { head: "", body: "" }) {
|
|
1056
|
+
await this.promise;
|
|
1057
|
+
for (const item of this.#out) {
|
|
1058
|
+
if (typeof item === "string") {
|
|
1059
|
+
content[this.type] += item;
|
|
1060
|
+
} else if (item instanceof Renderer) {
|
|
1061
|
+
if (item.#boundary) {
|
|
1062
|
+
const boundary_content = { head: "", body: "" };
|
|
1063
|
+
try {
|
|
1064
|
+
await item.#collect_content_async(boundary_content);
|
|
1065
|
+
content.head += boundary_content.head;
|
|
1066
|
+
content.body += boundary_content.body;
|
|
1067
|
+
} catch (error) {
|
|
1068
|
+
const { context, failed, transformError } = item.#boundary;
|
|
1069
|
+
set_ssr_context(context);
|
|
1070
|
+
let transformed = await transformError(error);
|
|
1071
|
+
const failed_renderer = new Renderer(item.global, item);
|
|
1072
|
+
failed_renderer.type = item.type;
|
|
1073
|
+
failed_renderer.#out.push(Renderer.#serialize_failed_boundary(transformed));
|
|
1074
|
+
failed(failed_renderer, transformed, noop);
|
|
1075
|
+
failed_renderer.#out.push(BLOCK_CLOSE);
|
|
1076
|
+
await failed_renderer.#collect_content_async(content);
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
await item.#collect_content_async(content);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return content;
|
|
1084
|
+
}
|
|
1085
|
+
async #collect_hydratables() {
|
|
1086
|
+
const ctx = get_render_context().hydratable;
|
|
1087
|
+
for (const [_, key] of ctx.unresolved_promises) {
|
|
1088
|
+
unresolved_hydratable(key, ctx.lookup.get(key)?.stack ?? "<missing stack trace>");
|
|
1089
|
+
}
|
|
1090
|
+
for (const comparison of ctx.comparisons) {
|
|
1091
|
+
await comparison;
|
|
1092
|
+
}
|
|
1093
|
+
return await this.#hydratable_block(ctx);
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* @template {Record<string, any>} Props
|
|
1097
|
+
* @param {'sync' | 'async'} mode
|
|
1098
|
+
* @param {import('svelte').Component<Props>} component
|
|
1099
|
+
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} options
|
|
1100
|
+
* @returns {Renderer}
|
|
1101
|
+
*/
|
|
1102
|
+
static #open_render(mode, component, options) {
|
|
1103
|
+
var previous_context = ssr_context;
|
|
1104
|
+
try {
|
|
1105
|
+
const renderer = new Renderer(
|
|
1106
|
+
new SSRState(
|
|
1107
|
+
mode,
|
|
1108
|
+
options.idPrefix ? options.idPrefix + "-" : "",
|
|
1109
|
+
options.csp,
|
|
1110
|
+
options.transformError
|
|
1111
|
+
)
|
|
1112
|
+
);
|
|
1113
|
+
const context = { p: null, c: options.context ?? null, r: renderer };
|
|
1114
|
+
set_ssr_context(context);
|
|
1115
|
+
renderer.push(BLOCK_OPEN);
|
|
1116
|
+
component(renderer, options.props ?? {});
|
|
1117
|
+
renderer.push(BLOCK_CLOSE);
|
|
1118
|
+
return renderer;
|
|
1119
|
+
} finally {
|
|
1120
|
+
set_ssr_context(previous_context);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* @param {AccumulatedContent} content
|
|
1125
|
+
* @param {Renderer} renderer
|
|
1126
|
+
* @returns {AccumulatedContent & { hashes: { script: Sha256Source[] } }}
|
|
1127
|
+
*/
|
|
1128
|
+
static #close_render(content, renderer) {
|
|
1129
|
+
for (const cleanup of renderer.#collect_on_destroy()) {
|
|
1130
|
+
cleanup();
|
|
1131
|
+
}
|
|
1132
|
+
let head2 = content.head + renderer.global.get_title();
|
|
1133
|
+
let body = content.body;
|
|
1134
|
+
for (const { hash, code } of renderer.global.css) {
|
|
1135
|
+
head2 += `<style id="${hash}">${code}</style>`;
|
|
1136
|
+
}
|
|
1137
|
+
return {
|
|
1138
|
+
head: head2,
|
|
1139
|
+
body,
|
|
1140
|
+
hashes: {
|
|
1141
|
+
script: renderer.global.csp.script_hashes
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* @param {HydratableContext} ctx
|
|
1147
|
+
*/
|
|
1148
|
+
async #hydratable_block(ctx) {
|
|
1149
|
+
if (ctx.lookup.size === 0) {
|
|
1150
|
+
return null;
|
|
1151
|
+
}
|
|
1152
|
+
let entries = [];
|
|
1153
|
+
let has_promises = false;
|
|
1154
|
+
for (const [k, v] of ctx.lookup) {
|
|
1155
|
+
if (v.promises) {
|
|
1156
|
+
has_promises = true;
|
|
1157
|
+
for (const p of v.promises) await p;
|
|
1158
|
+
}
|
|
1159
|
+
entries.push(`[${uneval(k)},${v.serialized}]`);
|
|
1160
|
+
}
|
|
1161
|
+
let prelude = `const h = (window.__svelte ??= {}).h ??= new Map();`;
|
|
1162
|
+
if (has_promises) {
|
|
1163
|
+
prelude = `const r = (v) => Promise.resolve(v);
|
|
1164
|
+
${prelude}`;
|
|
1165
|
+
}
|
|
1166
|
+
const body = `
|
|
1167
|
+
{
|
|
1168
|
+
${prelude}
|
|
1169
|
+
|
|
1170
|
+
for (const [k, v] of [
|
|
1171
|
+
${entries.join(",\n ")}
|
|
1172
|
+
]) {
|
|
1173
|
+
h.set(k, v);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
`;
|
|
1177
|
+
let csp_attr = "";
|
|
1178
|
+
if (this.global.csp.nonce) {
|
|
1179
|
+
csp_attr = ` nonce="${this.global.csp.nonce}"`;
|
|
1180
|
+
} else if (this.global.csp.hash) {
|
|
1181
|
+
const hash = await sha256(body);
|
|
1182
|
+
this.global.csp.script_hashes.push(`sha256-${hash}`);
|
|
1183
|
+
}
|
|
1184
|
+
return `
|
|
1185
|
+
<script${csp_attr}>${body}<\/script>`;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
class SSRState {
|
|
1189
|
+
/** @readonly @type {Csp & { script_hashes: Sha256Source[] }} */
|
|
1190
|
+
csp;
|
|
1191
|
+
/** @readonly @type {'sync' | 'async'} */
|
|
1192
|
+
mode;
|
|
1193
|
+
/** @readonly @type {() => string} */
|
|
1194
|
+
uid;
|
|
1195
|
+
/** @readonly @type {Set<{ hash: string; code: string }>} */
|
|
1196
|
+
css = /* @__PURE__ */ new Set();
|
|
1197
|
+
/**
|
|
1198
|
+
* `transformError` passed to `render`. Called when an error boundary catches an error.
|
|
1199
|
+
* Throws by default if unset in `render`.
|
|
1200
|
+
* @type {(error: unknown) => unknown}
|
|
1201
|
+
*/
|
|
1202
|
+
transformError;
|
|
1203
|
+
/** @type {{ path: number[], value: string }} */
|
|
1204
|
+
#title = { path: [], value: "" };
|
|
1205
|
+
/**
|
|
1206
|
+
* @param {'sync' | 'async'} mode
|
|
1207
|
+
* @param {string} id_prefix
|
|
1208
|
+
* @param {Csp} csp
|
|
1209
|
+
* @param {((error: unknown) => unknown) | undefined} [transformError]
|
|
1210
|
+
*/
|
|
1211
|
+
constructor(mode, id_prefix = "", csp = { hash: false }, transformError) {
|
|
1212
|
+
this.mode = mode;
|
|
1213
|
+
this.csp = { ...csp, script_hashes: [] };
|
|
1214
|
+
this.transformError = transformError ?? ((error) => {
|
|
1215
|
+
throw error;
|
|
1216
|
+
});
|
|
1217
|
+
let uid = 1;
|
|
1218
|
+
this.uid = () => `${id_prefix}s${uid++}`;
|
|
1219
|
+
}
|
|
1220
|
+
get_title() {
|
|
1221
|
+
return this.#title.value;
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Performs a depth-first (lexicographic) comparison using the path. Rejects sets
|
|
1225
|
+
* from earlier than or equal to the current value.
|
|
1226
|
+
* @param {string} value
|
|
1227
|
+
* @param {number[]} path
|
|
1228
|
+
*/
|
|
1229
|
+
set_title(value, path) {
|
|
1230
|
+
const current = this.#title.path;
|
|
1231
|
+
let i = 0;
|
|
1232
|
+
let l = Math.min(path.length, current.length);
|
|
1233
|
+
while (i < l && path[i] === current[i]) i += 1;
|
|
1234
|
+
if (path[i] === void 0) return;
|
|
1235
|
+
if (current[i] === void 0 || path[i] > current[i]) {
|
|
1236
|
+
this.#title.path = path;
|
|
1237
|
+
this.#title.value = value;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
export { attr as $, ASYNC as A, BLOCK_EFFECT as B, CONNECTED as C, DERIVED as D, ERROR_VALUE as E, DESTROYING as F, BOUNDARY_EFFECT as G, HYDRATION_START as H, INERT as I, index_of as J, STALE_REACTION as K, LEGACY_PROPS as L, MAYBE_DIRTY as M, noop as N, array_from as O, is_passive_event as P, setContext as Q, REACTION_RAN as R, STATE_SYMBOL as S, derived as T, UNINITIALIZED as U, HYDRATION_END as V, WAS_MARKED as W, HYDRATION_START_ELSE as X, HYDRATION_START_FAILED as Y, USER_EFFECT as Z, head as _, COMMENT_NODE as a, escape_html as a0, getContext as a1, attr_class as a2, ensure_array_like as a3, bind_props as a4, attr_style as a5, element as a6, HYDRATION_ERROR as b, array_prototype as c, define_property as d, DIRTY as e, get_prototype_of as f, get_descriptor as g, is_array as h, is_extensible as i, CLEAN as j, EFFECT as k, DESTROYED as l, EAGER_EFFECT as m, deferred as n, object_prototype as o, RENDER_EFFECT as p, MANAGED_EFFECT as q, render as r, ROOT_EFFECT as s, BRANCH_EFFECT as t, run_all as u, includes as v, REACTION_IS_UPDATING as w, EFFECT_PRESERVED as x, EFFECT_TRANSPARENT as y, HEAD_EFFECT as z };
|
|
1243
|
+
//# sourceMappingURL=renderer.js-DsOhU1UZ.js.map
|