keits 0.0.4 → 0.1.0
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 +93 -79
- package/dist/dev/api.js +8 -3
- package/dist/dev/forms.js +6 -4
- package/dist/dev/index.js +26 -35
- package/dist/dev/router.js +24 -7
- package/dist/dev/shared/{computed-3UO-KiH1.js → computed-DrF8O8b4.js} +1 -1
- package/dist/dev/shared/{element-CQPqagu1.js → element-DXwmUAnz.js} +30 -76
- package/dist/dev/shared/{graph-D6-x_CWC.js → graph-SIvYLXSv.js} +62 -3
- package/dist/dev/shared/hydrate-C8cOsDDH.js +588 -0
- package/dist/dev/shared/mount-CDB2HgN5.js +23 -0
- package/dist/dev/shared/namespaces-Cz82B0Pr.js +84 -0
- package/dist/dev/shared/{owner-Dmge21OW.js → owner-BuwIoI4j.js} +12 -2
- package/dist/dev/shared/render-context-k2uu_dM_.js +34 -0
- package/dist/dev/shared/render-effect-Uk9dDmuU.js +32 -0
- package/dist/dev/shared/{resource-CbXVATvq.js → resource-DlgzdtcG.js} +24 -33
- package/dist/dev/shared/{signal-BOXkY-Iv.js → signal-B3xOKbVm.js} +1 -1
- package/dist/dev/shared/{store-BzUN1qE5.js → store-0vEg2bQV.js} +7 -3
- package/dist/dev/shared/unsafe-keys-CB1P22No.js +8 -0
- package/dist/dev/static.js +76 -0
- package/dist/dev/svg.js +2 -1
- package/dist/dev/testing.js +216 -0
- package/dist/dev/vite.js +141 -0
- package/dist/prod/api.js +76 -71
- package/dist/prod/forms.js +63 -60
- package/dist/prod/index.js +56 -64
- package/dist/prod/router.js +86 -73
- package/dist/prod/shared/{computed-CAPpOLCY.js → computed-BjqJ6Pps.js} +1 -1
- package/dist/prod/shared/element-DCit4-3e.js +129 -0
- package/dist/prod/shared/{graph-C_aA46c6.js → graph-CR2WKbwr.js} +107 -63
- package/dist/prod/shared/hydrate-kKnJbkV7.js +480 -0
- package/dist/prod/shared/mount-DbeKIoyD.js +18 -0
- package/dist/prod/shared/namespaces-BSRrBJIU.js +71 -0
- package/dist/prod/shared/owner-DBi3odT4.js +67 -0
- package/dist/prod/shared/render-context-DF8lr1uu.js +30 -0
- package/dist/prod/shared/render-effect-UFDi2Pfh.js +25 -0
- package/dist/prod/shared/resource-Ch5tVseZ.js +91 -0
- package/dist/prod/shared/signal-BDMlfa0Z.js +16 -0
- package/dist/prod/shared/store-CvW0DbmK.js +110 -0
- package/dist/prod/shared/unsafe-keys-C5PMlerl.js +7 -0
- package/dist/prod/static.js +48 -0
- package/dist/prod/svg.js +3 -2
- package/dist/prod/testing.js +144 -0
- package/dist/prod/vite.js +106 -0
- package/dist/types/async/render-context.d.ts +10 -0
- package/dist/types/core/effect.d.ts +1 -0
- package/dist/types/core/graph.d.ts +11 -0
- package/dist/types/core/owner.d.ts +1 -0
- package/dist/types/core/unsafe-keys.d.ts +2 -0
- package/dist/types/dom/hooks.d.ts +4 -0
- package/dist/types/dom/types.d.ts +5 -0
- package/dist/types/router/index.d.ts +1 -0
- package/dist/types/router/match.d.ts +1 -0
- package/dist/types/router/types.d.ts +1 -0
- package/dist/types/static/head.d.ts +36 -0
- package/dist/types/static/hydrate.d.ts +3 -0
- package/dist/types/static/index.d.ts +4 -0
- package/dist/types/static/island.d.ts +14 -0
- package/dist/types/static/json.d.ts +1 -0
- package/dist/types/static/render.d.ts +11 -0
- package/dist/types/static/server-dom.d.ts +100 -0
- package/dist/types/testing/index.d.ts +62 -0
- package/dist/types/vite/index.d.ts +24 -0
- package/package.json +34 -7
- package/dist/dev/shared/render-effect-kOGnLNbL.js +0 -26
- package/dist/prod/shared/element-DGyQ01Vs.js +0 -164
- package/dist/prod/shared/owner-6BFHIPR9.js +0 -59
- package/dist/prod/shared/render-effect-DjaUT3Cn.js +0 -23
- package/dist/prod/shared/resource-CNC2DBO3.js +0 -109
- package/dist/prod/shared/signal-DGrl3r9T.js +0 -16
- package/dist/prod/shared/store-Dcscpk_h.js +0 -109
|
@@ -12,6 +12,7 @@ var mounts = [];
|
|
|
12
12
|
var lastWritten = null;
|
|
13
13
|
var unhandledErrors = [];
|
|
14
14
|
var staticDepth = 0;
|
|
15
|
+
var staticRoots = 0;
|
|
15
16
|
function track(source) {
|
|
16
17
|
const observer = currentObserver;
|
|
17
18
|
if (observer === null || source.seenBy === currentRunId) return;
|
|
@@ -26,6 +27,9 @@ function track(source) {
|
|
|
26
27
|
function isTracking() {
|
|
27
28
|
return currentObserver !== null;
|
|
28
29
|
}
|
|
30
|
+
function getObserver() {
|
|
31
|
+
return currentObserver;
|
|
32
|
+
}
|
|
29
33
|
function notify(source) {
|
|
30
34
|
if (source.observers.length === 0) return;
|
|
31
35
|
lastWritten = source;
|
|
@@ -213,6 +217,32 @@ function adopt(node) {
|
|
|
213
217
|
const owner = currentOwner;
|
|
214
218
|
node.owner = owner;
|
|
215
219
|
if (owner !== null) (owner.children ??= []).push(node);
|
|
220
|
+
giveKey(node);
|
|
221
|
+
}
|
|
222
|
+
var keying = 0;
|
|
223
|
+
function startKeys() {
|
|
224
|
+
keying++;
|
|
225
|
+
}
|
|
226
|
+
function stopKeys() {
|
|
227
|
+
keying--;
|
|
228
|
+
}
|
|
229
|
+
function nextKey() {
|
|
230
|
+
const owner = currentOwner;
|
|
231
|
+
if (keying === 0 || owner === null || owner.key === void 0) return null;
|
|
232
|
+
const index = owner.keyCount ?? 0;
|
|
233
|
+
owner.keyCount = index + 1;
|
|
234
|
+
return `${owner.key}.${index}`;
|
|
235
|
+
}
|
|
236
|
+
function giveKey(node) {
|
|
237
|
+
const key = nextKey();
|
|
238
|
+
if (key !== null) {
|
|
239
|
+
node.key = key;
|
|
240
|
+
node.keyCount = 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function insideHydratable(from = currentOwner) {
|
|
244
|
+
for (let owner = from; owner !== null; owner = owner.owner) if (owner.kind === 3 && owner.hydratable) return true;
|
|
245
|
+
return false;
|
|
216
246
|
}
|
|
217
247
|
function getOwner() {
|
|
218
248
|
return currentOwner;
|
|
@@ -235,7 +265,7 @@ function addCleanup(fn) {
|
|
|
235
265
|
return true;
|
|
236
266
|
}
|
|
237
267
|
function addMount(fn) {
|
|
238
|
-
if (
|
|
268
|
+
if (isStaticRender()) return;
|
|
239
269
|
queueMount(currentOwner, fn);
|
|
240
270
|
}
|
|
241
271
|
function queueMount(owner, fn) {
|
|
@@ -279,6 +309,7 @@ function cleanNode(node) {
|
|
|
279
309
|
const cleanups = node.cleanups;
|
|
280
310
|
node.children = null;
|
|
281
311
|
node.cleanups = null;
|
|
312
|
+
if (node.key !== void 0) node.keyCount = 0;
|
|
282
313
|
if (children !== null) for (let i = children.length - 1; i >= 0; i--) dispose(children[i]);
|
|
283
314
|
if (cleanups !== null) for (let i = cleanups.length - 1; i >= 0; i--) try {
|
|
284
315
|
cleanups[i]();
|
|
@@ -311,7 +342,35 @@ function handleError(error, owner) {
|
|
|
311
342
|
unhandledErrors.push(error);
|
|
312
343
|
}
|
|
313
344
|
function isStaticRender() {
|
|
314
|
-
|
|
345
|
+
if (staticDepth > 0) return true;
|
|
346
|
+
if (staticRoots === 0) return false;
|
|
347
|
+
for (let owner = currentOwner; owner !== null; owner = owner.owner) if (owner.kind === 3 && owner.static) return true;
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
function staticRoot(fn) {
|
|
351
|
+
const root = {
|
|
352
|
+
kind: 3,
|
|
353
|
+
owner: null,
|
|
354
|
+
children: null,
|
|
355
|
+
cleanups: null,
|
|
356
|
+
disposed: false,
|
|
357
|
+
handler: null,
|
|
358
|
+
static: true
|
|
359
|
+
};
|
|
360
|
+
staticRoots++;
|
|
361
|
+
let ended = false;
|
|
362
|
+
const end = () => {
|
|
363
|
+
if (ended) return;
|
|
364
|
+
ended = true;
|
|
365
|
+
staticRoots--;
|
|
366
|
+
batch(() => dispose(root));
|
|
367
|
+
};
|
|
368
|
+
try {
|
|
369
|
+
return batch(() => runWithOwner(root, () => fn(end)));
|
|
370
|
+
} catch (error) {
|
|
371
|
+
end();
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
315
374
|
}
|
|
316
375
|
function withStaticRender(fn) {
|
|
317
376
|
staticDepth++;
|
|
@@ -321,4 +380,4 @@ function withStaticRender(fn) {
|
|
|
321
380
|
staticDepth--;
|
|
322
381
|
}
|
|
323
382
|
}
|
|
324
|
-
export {
|
|
383
|
+
export { updateIfNeeded as C, untrack as S, runWithOwner as _, deferMounts as a, stopKeys as b, getOwner as c, insideHydratable as d, isStaticRender as f, runEffect as g, notify as h, batch as i, giveKey as l, nextKey as m, addMount as n, dispose as o, isTracking as p, adopt as r, getObserver as s, addCleanup as t, handleError as u, startKeys as v, withStaticRender as w, track as x, staticRoot as y };
|
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { b as stopKeys, c as getOwner, d as insideHydratable, m as nextKey, v as startKeys, y as staticRoot } from "./graph-SIvYLXSv.js";
|
|
2
|
+
import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
|
|
3
|
+
import { a as onCleanup, i as keyedRoot } from "./owner-BuwIoI4j.js";
|
|
4
|
+
import { a as provide, i as createContext, o as useContext, r as setHydratedValue, t as RenderContext } from "./render-context-k2uu_dM_.js";
|
|
5
|
+
import { i as defaultHooks, n as insert, o as setHooks, r as claimsPaused, t as SVG_NS } from "./namespaces-Cz82B0Pr.js";
|
|
6
|
+
// src/static/json.ts
|
|
7
|
+
function scriptJson(value) {
|
|
8
|
+
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
9
|
+
}
|
|
10
|
+
// src/static/head.ts
|
|
11
|
+
var HeadContext = createContext(null);
|
|
12
|
+
function head(tags) {
|
|
13
|
+
const registry = useContext(HeadContext) ?? (typeof document === "undefined" ? null : browserRegistry());
|
|
14
|
+
if (registry === null) return;
|
|
15
|
+
const token = {};
|
|
16
|
+
renderEffect(() => registry.set(token, collect(tags)));
|
|
17
|
+
onCleanup(() => registry.remove(token));
|
|
18
|
+
}
|
|
19
|
+
var read = (value) => typeof value === "function" ? value() : value;
|
|
20
|
+
var quote = (value) => `"${value.replace(/["\\]/g, "\\$&")}"`;
|
|
21
|
+
function collect(tags) {
|
|
22
|
+
const out = [];
|
|
23
|
+
const meta = (attribute, name, content) => {
|
|
24
|
+
if (content !== void 0) out.push({
|
|
25
|
+
key: `${attribute}:${name}`,
|
|
26
|
+
tag: "meta",
|
|
27
|
+
attrs: {
|
|
28
|
+
[attribute]: name,
|
|
29
|
+
content
|
|
30
|
+
},
|
|
31
|
+
selector: `meta[${attribute}=${quote(name)}]`
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const title = read(tags.title);
|
|
35
|
+
if (title !== void 0) out.push({
|
|
36
|
+
key: "title",
|
|
37
|
+
tag: "title",
|
|
38
|
+
attrs: {},
|
|
39
|
+
text: title,
|
|
40
|
+
selector: "title"
|
|
41
|
+
});
|
|
42
|
+
meta("name", "description", read(tags.description));
|
|
43
|
+
meta("name", "robots", read(tags.robots));
|
|
44
|
+
const canonical = read(tags.canonical);
|
|
45
|
+
if (canonical !== void 0) out.push({
|
|
46
|
+
key: "link:canonical",
|
|
47
|
+
tag: "link",
|
|
48
|
+
attrs: {
|
|
49
|
+
rel: "canonical",
|
|
50
|
+
href: canonical
|
|
51
|
+
},
|
|
52
|
+
selector: "link[rel=\"canonical\"]"
|
|
53
|
+
});
|
|
54
|
+
for (const [name, value] of Object.entries(tags.og ?? {})) meta("property", `og:${name}`, read(value));
|
|
55
|
+
for (const [name, value] of Object.entries(tags.twitter ?? {})) meta("name", `twitter:${name}`, read(value));
|
|
56
|
+
for (const item of tags.meta ?? []) if (item.property !== void 0) meta("property", item.property, read(item.content));
|
|
57
|
+
else if (item.name !== void 0) meta("name", item.name, read(item.content));
|
|
58
|
+
for (const attrs of tags.link ?? []) out.push({
|
|
59
|
+
key: `link:${attrs.rel}:${attrs.href}`,
|
|
60
|
+
tag: "link",
|
|
61
|
+
attrs: { ...attrs },
|
|
62
|
+
selector: `link[rel=${quote(attrs.rel)}][href=${quote(attrs.href)}]`
|
|
63
|
+
});
|
|
64
|
+
const data = typeof tags.jsonLd === "function" ? tags.jsonLd() : tags.jsonLd;
|
|
65
|
+
if (data !== void 0) out.push({
|
|
66
|
+
key: "jsonld",
|
|
67
|
+
tag: "script",
|
|
68
|
+
attrs: { type: "application/ld+json" },
|
|
69
|
+
text: scriptJson(data),
|
|
70
|
+
selector: "script[type=\"application/ld+json\"]"
|
|
71
|
+
});
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
function createHeadRegistry(changed = () => {}) {
|
|
75
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
76
|
+
const registry = {
|
|
77
|
+
set(token, tags) {
|
|
78
|
+
tokens.set(token, tags);
|
|
79
|
+
changed(registry.winners());
|
|
80
|
+
},
|
|
81
|
+
remove(token) {
|
|
82
|
+
tokens.delete(token);
|
|
83
|
+
changed(registry.winners());
|
|
84
|
+
},
|
|
85
|
+
winners() {
|
|
86
|
+
const result = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const tags of tokens.values()) for (const tag of tags) result.set(tag.key, tag);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return registry;
|
|
92
|
+
}
|
|
93
|
+
var browser = null;
|
|
94
|
+
function browserRegistry() {
|
|
95
|
+
if (browser !== null) return browser;
|
|
96
|
+
const applied = /* @__PURE__ */ new Map();
|
|
97
|
+
const originalTitle = document.title;
|
|
98
|
+
browser = createHeadRegistry((winners) => {
|
|
99
|
+
for (const [key, element] of applied) {
|
|
100
|
+
if (winners.has(key)) continue;
|
|
101
|
+
if (element === null) document.title = originalTitle;
|
|
102
|
+
else element.remove();
|
|
103
|
+
applied.delete(key);
|
|
104
|
+
}
|
|
105
|
+
for (const [key, tag] of winners) {
|
|
106
|
+
if (tag.tag === "title") {
|
|
107
|
+
if (document.title !== tag.text) document.title = tag.text ?? "";
|
|
108
|
+
applied.set(key, null);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
let previous = applied.get(key) ?? null;
|
|
112
|
+
if (previous !== null && !previous.isConnected) previous = null;
|
|
113
|
+
let element = previous ?? document.head.querySelector(tag.selector);
|
|
114
|
+
if (element === null) {
|
|
115
|
+
element = document.createElement(tag.tag);
|
|
116
|
+
document.head.append(element);
|
|
117
|
+
}
|
|
118
|
+
for (const [name, value] of Object.entries(tag.attrs)) if (element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
119
|
+
if (tag.text !== void 0 && element.textContent !== tag.text) element.textContent = tag.text;
|
|
120
|
+
applied.set(key, element);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return browser;
|
|
124
|
+
}
|
|
125
|
+
// src/static/server-dom.ts
|
|
126
|
+
var ServerNode = class {
|
|
127
|
+
parentNode = null;
|
|
128
|
+
previousSibling = null;
|
|
129
|
+
nextSibling = null;
|
|
130
|
+
remove() {
|
|
131
|
+
this.parentNode?.removeChild(this);
|
|
132
|
+
}
|
|
133
|
+
before(...nodes) {
|
|
134
|
+
const parent = this.parentNode;
|
|
135
|
+
if (parent !== null) for (const node of nodes) parent.insertBefore(toNode(node), this);
|
|
136
|
+
}
|
|
137
|
+
after(...nodes) {
|
|
138
|
+
const parent = this.parentNode;
|
|
139
|
+
const next = this.nextSibling;
|
|
140
|
+
if (parent !== null) for (const node of nodes) parent.insertBefore(toNode(node), next);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var ServerParent = class extends ServerNode {
|
|
144
|
+
firstChild = null;
|
|
145
|
+
lastChild = null;
|
|
146
|
+
insertBefore(node, before) {
|
|
147
|
+
if (node instanceof ServerFragment) {
|
|
148
|
+
while (node.firstChild !== null) this.insertBefore(node.firstChild, before);
|
|
149
|
+
return node;
|
|
150
|
+
}
|
|
151
|
+
node.remove();
|
|
152
|
+
node.parentNode = this;
|
|
153
|
+
node.nextSibling = before;
|
|
154
|
+
node.previousSibling = before === null ? this.lastChild : before.previousSibling;
|
|
155
|
+
if (node.previousSibling === null) this.firstChild = node;
|
|
156
|
+
else node.previousSibling.nextSibling = node;
|
|
157
|
+
if (before === null) this.lastChild = node;
|
|
158
|
+
else before.previousSibling = node;
|
|
159
|
+
return node;
|
|
160
|
+
}
|
|
161
|
+
appendChild(node) {
|
|
162
|
+
return this.insertBefore(node, null);
|
|
163
|
+
}
|
|
164
|
+
append(...nodes) {
|
|
165
|
+
for (const node of nodes) this.insertBefore(toNode(node), null);
|
|
166
|
+
}
|
|
167
|
+
removeChild(node) {
|
|
168
|
+
if (node.previousSibling === null) this.firstChild = node.nextSibling;
|
|
169
|
+
else node.previousSibling.nextSibling = node.nextSibling;
|
|
170
|
+
if (node.nextSibling === null) this.lastChild = node.previousSibling;
|
|
171
|
+
else node.nextSibling.previousSibling = node.previousSibling;
|
|
172
|
+
node.parentNode = node.previousSibling = node.nextSibling = null;
|
|
173
|
+
return node;
|
|
174
|
+
}
|
|
175
|
+
get textContent() {
|
|
176
|
+
let text = "";
|
|
177
|
+
for (let child = this.firstChild; child !== null; child = child.nextSibling) text += child.textContent;
|
|
178
|
+
return text;
|
|
179
|
+
}
|
|
180
|
+
set textContent(value) {
|
|
181
|
+
while (this.firstChild !== null) this.removeChild(this.firstChild);
|
|
182
|
+
if (value !== "") this.appendChild(new ServerText(value));
|
|
183
|
+
}
|
|
184
|
+
printChildren(out, rawText) {
|
|
185
|
+
for (let child = this.firstChild; child !== null; child = child.nextSibling) child.print(out, rawText);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var ServerFragment = class extends ServerParent {
|
|
189
|
+
nodeType = 11;
|
|
190
|
+
print(out, rawText) {
|
|
191
|
+
this.printChildren(out, rawText);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var ServerText = class extends ServerNode {
|
|
195
|
+
nodeType = 3;
|
|
196
|
+
data;
|
|
197
|
+
constructor(data) {
|
|
198
|
+
super();
|
|
199
|
+
this.data = data;
|
|
200
|
+
}
|
|
201
|
+
get textContent() {
|
|
202
|
+
return this.data;
|
|
203
|
+
}
|
|
204
|
+
print(out, rawText) {
|
|
205
|
+
out.push(rawText ? escapeRawText(this.data) : escapeText(this.data));
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var ServerComment = class extends ServerNode {
|
|
209
|
+
nodeType = 8;
|
|
210
|
+
data;
|
|
211
|
+
constructor(data) {
|
|
212
|
+
super();
|
|
213
|
+
this.data = data;
|
|
214
|
+
}
|
|
215
|
+
get textContent() {
|
|
216
|
+
return "";
|
|
217
|
+
}
|
|
218
|
+
print() {}
|
|
219
|
+
};
|
|
220
|
+
var ServerRawHTML = class extends ServerNode {
|
|
221
|
+
nodeType = 3;
|
|
222
|
+
html;
|
|
223
|
+
constructor(html) {
|
|
224
|
+
super();
|
|
225
|
+
this.html = html;
|
|
226
|
+
}
|
|
227
|
+
get textContent() {
|
|
228
|
+
return "";
|
|
229
|
+
}
|
|
230
|
+
print(out) {
|
|
231
|
+
out.push(this.html);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var VOID = /* @__PURE__ */ new Set([
|
|
235
|
+
"area",
|
|
236
|
+
"base",
|
|
237
|
+
"br",
|
|
238
|
+
"col",
|
|
239
|
+
"embed",
|
|
240
|
+
"hr",
|
|
241
|
+
"img",
|
|
242
|
+
"input",
|
|
243
|
+
"link",
|
|
244
|
+
"meta",
|
|
245
|
+
"source",
|
|
246
|
+
"track",
|
|
247
|
+
"wbr"
|
|
248
|
+
]);
|
|
249
|
+
var RAW_TEXT = /* @__PURE__ */ new Set(["script", "style"]);
|
|
250
|
+
var SAFE_NAME = /^[^\s"'<>/=\u0000-\u001f\u007f]+$/;
|
|
251
|
+
var RENAMED = {
|
|
252
|
+
className: "class",
|
|
253
|
+
htmlFor: "for",
|
|
254
|
+
httpEquiv: "http-equiv",
|
|
255
|
+
acceptCharset: "accept-charset"
|
|
256
|
+
};
|
|
257
|
+
var ServerElement = class extends ServerParent {
|
|
258
|
+
nodeType = 1;
|
|
259
|
+
localName;
|
|
260
|
+
namespaceURI;
|
|
261
|
+
classList;
|
|
262
|
+
style;
|
|
263
|
+
#attributes = /* @__PURE__ */ new Map();
|
|
264
|
+
#state = {};
|
|
265
|
+
constructor(tag, namespace) {
|
|
266
|
+
super();
|
|
267
|
+
if (!SAFE_NAME.test(tag)) throw new Error(`[keits/static] "${tag}" is not a valid tag name.`);
|
|
268
|
+
this.localName = namespace === null ? tag.toLowerCase() : tag;
|
|
269
|
+
this.namespaceURI = namespace;
|
|
270
|
+
this.classList = new ServerClassList(this);
|
|
271
|
+
this.style = new ServerStyle(this);
|
|
272
|
+
}
|
|
273
|
+
getAttribute(name) {
|
|
274
|
+
return this.#attributes.get(this.#name(name)) ?? null;
|
|
275
|
+
}
|
|
276
|
+
hasAttribute(name) {
|
|
277
|
+
return this.#attributes.has(this.#name(name));
|
|
278
|
+
}
|
|
279
|
+
setAttribute(name, value) {
|
|
280
|
+
if (!SAFE_NAME.test(name)) throw new Error(`[keits/static] "${name}" is not a valid attribute name.`);
|
|
281
|
+
this.#attributes.set(this.#name(name), String(value));
|
|
282
|
+
}
|
|
283
|
+
removeAttribute(name) {
|
|
284
|
+
this.#attributes.delete(this.#name(name));
|
|
285
|
+
}
|
|
286
|
+
toggleAttribute(name, force) {
|
|
287
|
+
const on = force ?? !this.hasAttribute(name);
|
|
288
|
+
if (on) this.setAttribute(name, "");
|
|
289
|
+
else this.removeAttribute(name);
|
|
290
|
+
return on;
|
|
291
|
+
}
|
|
292
|
+
#name(name) {
|
|
293
|
+
return this.namespaceURI === null ? name.toLowerCase() : name;
|
|
294
|
+
}
|
|
295
|
+
get value() {
|
|
296
|
+
return this.#state.value ?? "";
|
|
297
|
+
}
|
|
298
|
+
set value(value) {
|
|
299
|
+
this.#state.value = value;
|
|
300
|
+
}
|
|
301
|
+
get checked() {
|
|
302
|
+
return this.#state.checked === true;
|
|
303
|
+
}
|
|
304
|
+
set checked(value) {
|
|
305
|
+
this.#state.checked = value;
|
|
306
|
+
}
|
|
307
|
+
get selected() {
|
|
308
|
+
return this.#state.selected === true;
|
|
309
|
+
}
|
|
310
|
+
set selected(value) {
|
|
311
|
+
this.#state.selected = value;
|
|
312
|
+
}
|
|
313
|
+
get textContent() {
|
|
314
|
+
return super.textContent;
|
|
315
|
+
}
|
|
316
|
+
set textContent(value) {
|
|
317
|
+
super.textContent = value == null ? "" : String(value);
|
|
318
|
+
}
|
|
319
|
+
set className(value) {
|
|
320
|
+
this.setAttribute("class", value);
|
|
321
|
+
}
|
|
322
|
+
set htmlFor(value) {
|
|
323
|
+
this.setAttribute(RENAMED.htmlFor, value);
|
|
324
|
+
}
|
|
325
|
+
set draggable(value) {
|
|
326
|
+
this.setAttribute("draggable", String(value));
|
|
327
|
+
}
|
|
328
|
+
set spellcheck(value) {
|
|
329
|
+
this.setAttribute("spellcheck", String(value));
|
|
330
|
+
}
|
|
331
|
+
print(out) {
|
|
332
|
+
out.push(`<${this.localName}`);
|
|
333
|
+
for (const [name, value] of this.#attributes) out.push(value === "" ? ` ${name}` : ` ${name}="${escapeAttribute(value)}"`);
|
|
334
|
+
out.push(">");
|
|
335
|
+
if (this.namespaceURI === null && VOID.has(this.localName)) return;
|
|
336
|
+
this.printChildren(out, this.namespaceURI === null && RAW_TEXT.has(this.localName));
|
|
337
|
+
out.push(`</${this.localName}>`);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var ServerClassList = class {
|
|
341
|
+
#element;
|
|
342
|
+
constructor(element) {
|
|
343
|
+
this.#element = element;
|
|
344
|
+
}
|
|
345
|
+
#names() {
|
|
346
|
+
return (this.#element.getAttribute("class") ?? "").split(/\s+/).filter(Boolean);
|
|
347
|
+
}
|
|
348
|
+
#write(names) {
|
|
349
|
+
if (names.length === 0) this.#element.removeAttribute("class");
|
|
350
|
+
else this.#element.setAttribute("class", names.join(" "));
|
|
351
|
+
}
|
|
352
|
+
contains(name) {
|
|
353
|
+
return this.#names().includes(name);
|
|
354
|
+
}
|
|
355
|
+
add(...names) {
|
|
356
|
+
const current = this.#names();
|
|
357
|
+
for (const name of names) if (!current.includes(name)) current.push(name);
|
|
358
|
+
this.#write(current);
|
|
359
|
+
}
|
|
360
|
+
remove(...names) {
|
|
361
|
+
this.#write(this.#names().filter((name) => !names.includes(name)));
|
|
362
|
+
}
|
|
363
|
+
toggle(name, force) {
|
|
364
|
+
const on = force ?? !this.contains(name);
|
|
365
|
+
if (on) this.add(name);
|
|
366
|
+
else this.remove(name);
|
|
367
|
+
return on;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
var ServerStyle = class {
|
|
371
|
+
#element;
|
|
372
|
+
#properties = /* @__PURE__ */ new Map();
|
|
373
|
+
constructor(element) {
|
|
374
|
+
this.#element = element;
|
|
375
|
+
}
|
|
376
|
+
getPropertyValue(name) {
|
|
377
|
+
return this.#properties.get(name) ?? "";
|
|
378
|
+
}
|
|
379
|
+
setProperty(name, value) {
|
|
380
|
+
if (value === "") this.#properties.delete(name);
|
|
381
|
+
else this.#properties.set(name, value);
|
|
382
|
+
this.#sync();
|
|
383
|
+
}
|
|
384
|
+
removeProperty(name) {
|
|
385
|
+
const previous = this.getPropertyValue(name);
|
|
386
|
+
this.#properties.delete(name);
|
|
387
|
+
this.#sync();
|
|
388
|
+
return previous;
|
|
389
|
+
}
|
|
390
|
+
get cssText() {
|
|
391
|
+
return [...this.#properties].map(([name, value]) => `${name}: ${value};`).join(" ");
|
|
392
|
+
}
|
|
393
|
+
set cssText(text) {
|
|
394
|
+
this.#properties.clear();
|
|
395
|
+
for (const part of text.split(";")) {
|
|
396
|
+
const colon = part.indexOf(":");
|
|
397
|
+
if (colon > 0) this.#properties.set(part.slice(0, colon).trim(), part.slice(colon + 1).trim());
|
|
398
|
+
}
|
|
399
|
+
this.#sync();
|
|
400
|
+
}
|
|
401
|
+
get display() {
|
|
402
|
+
return this.getPropertyValue("display");
|
|
403
|
+
}
|
|
404
|
+
set display(value) {
|
|
405
|
+
this.setProperty("display", value);
|
|
406
|
+
}
|
|
407
|
+
#sync() {
|
|
408
|
+
if (this.#properties.size === 0) this.#element.removeAttribute("style");
|
|
409
|
+
else this.#element.setAttribute("style", this.cssText);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
function toNode(node) {
|
|
413
|
+
return typeof node === "string" ? new ServerText(node) : node;
|
|
414
|
+
}
|
|
415
|
+
function escapeText(text) {
|
|
416
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
417
|
+
}
|
|
418
|
+
function escapeAttribute(text) {
|
|
419
|
+
return escapeText(text).replace(/"/g, """);
|
|
420
|
+
}
|
|
421
|
+
function escapeRawText(text) {
|
|
422
|
+
return text.replace(/<\/(script|style)/gi, "<\\/$1");
|
|
423
|
+
}
|
|
424
|
+
var serverHooks = {
|
|
425
|
+
element(tag, namespace) {
|
|
426
|
+
const element = new ServerElement(tag, namespace === "http://www.w3.org/2000/svg" ? SVG_NS : namespace);
|
|
427
|
+
const key = nextKey();
|
|
428
|
+
if (key !== null && insideHydratable()) element.setAttribute("data-k", key);
|
|
429
|
+
return element;
|
|
430
|
+
},
|
|
431
|
+
text: (value) => new ServerText(value),
|
|
432
|
+
marker: () => new ServerComment(""),
|
|
433
|
+
fragment: () => new ServerFragment(),
|
|
434
|
+
html: (markup) => {
|
|
435
|
+
const fragment = new ServerFragment();
|
|
436
|
+
fragment.appendChild(new ServerRawHTML(markup));
|
|
437
|
+
return fragment;
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
function printNode(node) {
|
|
441
|
+
const out = [];
|
|
442
|
+
node.print(out, false);
|
|
443
|
+
return out.join("");
|
|
444
|
+
}
|
|
445
|
+
// src/static/render.ts
|
|
446
|
+
var active = 0;
|
|
447
|
+
var previousHooks = null;
|
|
448
|
+
async function renderToString(app, options = {}) {
|
|
449
|
+
if (active++ === 0) previousHooks = setHooks(serverHooks);
|
|
450
|
+
startKeys();
|
|
451
|
+
const loading = /* @__PURE__ */ new Set();
|
|
452
|
+
const data = {};
|
|
453
|
+
const tracker = {
|
|
454
|
+
wait(promise) {
|
|
455
|
+
loading.add(promise);
|
|
456
|
+
const done = () => loading.delete(promise);
|
|
457
|
+
promise.then(done, done);
|
|
458
|
+
},
|
|
459
|
+
store(key, value, owner) {
|
|
460
|
+
if (insideHydratable(owner)) data[key] = value;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const headTags = createHeadRegistry();
|
|
464
|
+
let dispose = () => {};
|
|
465
|
+
try {
|
|
466
|
+
const page = staticRoot((end) => {
|
|
467
|
+
dispose = end;
|
|
468
|
+
const root = serverHooks.fragment();
|
|
469
|
+
provide(RenderContext, tracker, () => provide(HeadContext, headTags, () => {
|
|
470
|
+
const owner = getOwner();
|
|
471
|
+
owner.key = "0";
|
|
472
|
+
owner.keyCount = 0;
|
|
473
|
+
if (options.hydrate) owner.hydratable = true;
|
|
474
|
+
insert(root, app());
|
|
475
|
+
}));
|
|
476
|
+
return root;
|
|
477
|
+
});
|
|
478
|
+
const timeout = options.timeout ?? 1e4;
|
|
479
|
+
const deadline = Date.now() + timeout;
|
|
480
|
+
while (loading.size > 0) await within(Promise.all(loading), deadline - Date.now(), timeout);
|
|
481
|
+
return {
|
|
482
|
+
html: printNode(page),
|
|
483
|
+
head: printHead(headTags.winners()),
|
|
484
|
+
data: printData(data)
|
|
485
|
+
};
|
|
486
|
+
} finally {
|
|
487
|
+
dispose();
|
|
488
|
+
stopKeys();
|
|
489
|
+
if (--active === 0) setHooks(previousHooks);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function within(promise, ms, timeout) {
|
|
493
|
+
return new Promise((resolve, reject) => {
|
|
494
|
+
const timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`[keits/static] Data was still loading after ${timeout} ms: the page could not be rendered.`)), Math.max(0, ms));
|
|
495
|
+
promise.then((value) => (clearTimeout(timer), resolve(value)), (error) => (clearTimeout(timer), reject(error)));
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function printHead(tags) {
|
|
499
|
+
let html = "";
|
|
500
|
+
for (const tag of tags.values()) {
|
|
501
|
+
const attrs = Object.entries(tag.attrs).map(([name, value]) => {
|
|
502
|
+
if (!SAFE_NAME.test(name)) throw new Error(`[keits/static] "${name}" is not a valid attribute name.`);
|
|
503
|
+
return ` ${name}="${escapeAttribute(value)}"`;
|
|
504
|
+
}).join("");
|
|
505
|
+
if (tag.tag === "title") html += `<title>${escapeText(tag.text ?? "")}</title>`;
|
|
506
|
+
else if (tag.tag === "script") html += `<script${attrs}>${tag.text ?? ""}<\/script>`;
|
|
507
|
+
else html += `<${tag.tag}${attrs}>`;
|
|
508
|
+
}
|
|
509
|
+
return html;
|
|
510
|
+
}
|
|
511
|
+
function printData(data) {
|
|
512
|
+
if (Object.keys(data).length === 0) return "";
|
|
513
|
+
return `<script type="application/json" id="keits-data">${scriptJson(data)}<\/script>`;
|
|
514
|
+
}
|
|
515
|
+
// src/static/hydrate.ts
|
|
516
|
+
var claims = null;
|
|
517
|
+
var sent = null;
|
|
518
|
+
function lookup(key) {
|
|
519
|
+
if (sent === null) {
|
|
520
|
+
const script = [...document.querySelectorAll("script[type=\"application/json\"]#keits-data")].pop() ?? null;
|
|
521
|
+
sent = script === null ? {} : JSON.parse(script.textContent ?? "{}");
|
|
522
|
+
}
|
|
523
|
+
return Object.hasOwn(sent, key) ? { value: sent[key] } : void 0;
|
|
524
|
+
}
|
|
525
|
+
function resetHydrationData() {
|
|
526
|
+
sent = null;
|
|
527
|
+
}
|
|
528
|
+
var claimHooks = {
|
|
529
|
+
...defaultHooks,
|
|
530
|
+
element(tag, namespace) {
|
|
531
|
+
const key = nextKey();
|
|
532
|
+
if (claims !== null && key !== null && !claimsPaused()) {
|
|
533
|
+
const found = claims.byKey.get(key);
|
|
534
|
+
if (found !== void 0 && found.localName === (namespace === null ? tag.toLowerCase() : tag)) {
|
|
535
|
+
claims.byKey.delete(key);
|
|
536
|
+
found.removeAttribute("data-k");
|
|
537
|
+
clearUnclaimable(found);
|
|
538
|
+
return found;
|
|
539
|
+
}
|
|
540
|
+
claims.mismatch ??= found === void 0 ? `no <${tag}> with key ${key}` : `<${found.localName}> instead of <${tag}> at key ${key}`;
|
|
541
|
+
}
|
|
542
|
+
return defaultHooks.element(tag, namespace);
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
function clearUnclaimable(parent) {
|
|
546
|
+
for (let child = parent.firstChild; child !== null;) {
|
|
547
|
+
const next = child.nextSibling;
|
|
548
|
+
if (!(child.nodeType === 1 && child.hasAttribute("data-k"))) parent.removeChild(child);
|
|
549
|
+
child = next;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function hydrate(app, container, key = "0") {
|
|
553
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
554
|
+
for (const element of container.querySelectorAll("[data-k]")) byKey.set(element.getAttribute("data-k"), element);
|
|
555
|
+
const current = {
|
|
556
|
+
byKey,
|
|
557
|
+
mismatch: null
|
|
558
|
+
};
|
|
559
|
+
setHydratedValue(lookup);
|
|
560
|
+
const previousClaims = claims;
|
|
561
|
+
const previousHooks = setHooks(claimHooks);
|
|
562
|
+
claims = current;
|
|
563
|
+
startKeys();
|
|
564
|
+
let dispose;
|
|
565
|
+
try {
|
|
566
|
+
clearUnclaimable(container);
|
|
567
|
+
dispose = keyedRoot(key, false, (end) => (insert(container, app()), end));
|
|
568
|
+
} finally {
|
|
569
|
+
stopKeys();
|
|
570
|
+
claims = previousClaims;
|
|
571
|
+
setHooks(previousHooks);
|
|
572
|
+
}
|
|
573
|
+
const leftover = container.querySelector("[data-k]");
|
|
574
|
+
if (current.mismatch === null && leftover === null) return dispose;
|
|
575
|
+
{
|
|
576
|
+
const reason = current.mismatch ?? `the server rendered <${leftover.localName}> (key ${leftover.getAttribute("data-k")}) but the app didn't`;
|
|
577
|
+
console.warn(`[keits] Hydration mismatch: ${reason}. Rendering it again in the browser instead.`);
|
|
578
|
+
}
|
|
579
|
+
dispose();
|
|
580
|
+
container.textContent = "";
|
|
581
|
+
startKeys();
|
|
582
|
+
try {
|
|
583
|
+
return keyedRoot(key, false, (end) => (insert(container, app()), end));
|
|
584
|
+
} finally {
|
|
585
|
+
stopKeys();
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
export { head as i, resetHydrationData as n, renderToString as r, hydrate as t };
|