@miaskiewicz/turbo-dom 0.7.1 → 0.8.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/Cargo.lock +7 -7
- package/Cargo.toml +7 -5
- package/README.md +13 -8
- package/package.json +1 -1
- package/pkg/package.json +2 -2
- package/pkg/turbo_dom_parser_bg.wasm +0 -0
- package/pkg-web/package.json +2 -2
- package/pkg-web/turbo_dom_parser_bg.wasm +0 -0
- package/src/runtime/cascade.mjs +70 -54
- package/src/runtime/css-shorthand.mjs +1217 -734
- package/src/runtime/custom-elements.mjs +8 -2
- package/src/runtime/dom.mjs +148 -95
- package/src/runtime/events.mjs +106 -85
- package/src/runtime/html-serialize.mjs +28 -24
- package/src/runtime/selectors.mjs +353 -237
- package/src/runtime/stubs.mjs +9 -6
- package/turbo-dom-parser.darwin-arm64.node +0 -0
- package/turbo-dom-parser.linux-arm64-gnu.node +0 -0
- package/turbo-dom-parser.linux-x64-musl.node +0 -0
- package/turbo-dom-parser.win32-x64-msvc.node +0 -0
|
@@ -17,33 +17,37 @@ function escapeAttr(s) {
|
|
|
17
17
|
return s.replace(/&/g, '&').replace(/ /g, ' ').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// An element: its tag (HTML / SVG / MathML elements serialize their local name, other
|
|
21
|
+
// namespaces the qualified name; a createElementNS prefix is kept on all of them — Chrome
|
|
22
|
+
// 156: <h:br>, <svg:g>), attributes and children. Only HTML elements can be void or
|
|
23
|
+
// <template>, keyed on the local name.
|
|
24
|
+
function serializeElement(node, out) {
|
|
25
|
+
const ns = node.__ns, html = ns === '', local = node.localName;
|
|
26
|
+
const tag = node.__prefix !== undefined ? `${node.__prefix}:${local}`
|
|
27
|
+
: html || ns === 'svg' || ns === 'math' ? local : node.tagName;
|
|
28
|
+
out.push('<' + tag);
|
|
29
|
+
// __attrs is lazy: buffer-backed elements leave it undefined (store __attrIdx).
|
|
30
|
+
// Build from the SoA on first touch, matching every other __attrs read site.
|
|
31
|
+
const attrs = node.__attrs ?? (node.__attrs = node.__buildAttrs());
|
|
32
|
+
for (const a of attrs) {
|
|
33
|
+
const name = a.prefix ? `${a.prefix}:${a.name}` : a.name;
|
|
34
|
+
out.push(` ${name}="${escapeAttr(a.value)}"`);
|
|
35
|
+
}
|
|
36
|
+
out.push('>');
|
|
37
|
+
if (html && VOID.has(local)) return;
|
|
38
|
+
if (html && local === 'template' && node.content) {
|
|
39
|
+
serializeChildren(node.content, out);
|
|
40
|
+
} else {
|
|
41
|
+
serializeChildren(node, out);
|
|
42
|
+
}
|
|
43
|
+
out.push(`</${tag}>`);
|
|
44
|
+
}
|
|
45
|
+
|
|
20
46
|
function serializeNode(node, out) {
|
|
21
47
|
switch (node.nodeType) {
|
|
22
|
-
case 1:
|
|
23
|
-
|
|
24
|
-
// qualified name; a createElementNS prefix is kept on all of them (Chrome 156:
|
|
25
|
-
// <h:br>, <svg:g>). Only HTML elements can be void or <template>, keyed on the local name.
|
|
26
|
-
const ns = node.__ns, html = ns === '', local = node.localName;
|
|
27
|
-
const tag = node.__prefix !== undefined ? `${node.__prefix}:${local}`
|
|
28
|
-
: html || ns === 'svg' || ns === 'math' ? local : node.tagName;
|
|
29
|
-
out.push('<' + tag);
|
|
30
|
-
// __attrs is lazy: buffer-backed elements leave it undefined (store __attrIdx).
|
|
31
|
-
// Build from the SoA on first touch, matching every other __attrs read site.
|
|
32
|
-
const attrs = node.__attrs ?? (node.__attrs = node.__buildAttrs());
|
|
33
|
-
for (const a of attrs) {
|
|
34
|
-
const name = a.prefix ? `${a.prefix}:${a.name}` : a.name;
|
|
35
|
-
out.push(` ${name}="${escapeAttr(a.value)}"`);
|
|
36
|
-
}
|
|
37
|
-
out.push('>');
|
|
38
|
-
if (html && VOID.has(local)) break;
|
|
39
|
-
if (html && local === 'template' && node.content) {
|
|
40
|
-
serializeChildren(node.content, out);
|
|
41
|
-
} else {
|
|
42
|
-
serializeChildren(node, out);
|
|
43
|
-
}
|
|
44
|
-
out.push(`</${tag}>`);
|
|
48
|
+
case 1: // element
|
|
49
|
+
serializeElement(node, out);
|
|
45
50
|
break;
|
|
46
|
-
}
|
|
47
51
|
case 3: { // text
|
|
48
52
|
// raw text keys on the parent's prefix-free local name (Chrome 156: <h:script> escapes)
|
|
49
53
|
const parent = node.parentNode, parentTag = parent && parent.__prefix === undefined && parent.localName;
|