mini-jsx-test-pb 0.1.5 → 0.1.6
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.
|
@@ -2,23 +2,39 @@ import {
|
|
|
2
2
|
effect
|
|
3
3
|
} from "./chunk-DIUGWQ3J.js";
|
|
4
4
|
|
|
5
|
+
// src/jsx/anchor.ts
|
|
6
|
+
function createAnchor(parent) {
|
|
7
|
+
const anchor = document.createComment("jsx");
|
|
8
|
+
parent.appendChild(anchor);
|
|
9
|
+
return anchor;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
// src/jsx/mount.ts
|
|
6
|
-
function
|
|
7
|
-
if (
|
|
8
|
-
if (Array.isArray(
|
|
9
|
-
|
|
10
|
-
return;
|
|
13
|
+
function normalize(value) {
|
|
14
|
+
if (value == null || value === true || value === false) return [];
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return value.flatMap(normalize);
|
|
11
17
|
}
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
if (value instanceof Node) return [value];
|
|
19
|
+
return [document.createTextNode(String(value))];
|
|
20
|
+
}
|
|
21
|
+
function removeNodes(nodes) {
|
|
22
|
+
for (const n of nodes) {
|
|
23
|
+
n.parentNode?.removeChild(n);
|
|
15
24
|
}
|
|
25
|
+
}
|
|
26
|
+
function mountChild(parent, child) {
|
|
16
27
|
if (typeof child === "function") {
|
|
17
|
-
const
|
|
18
|
-
|
|
28
|
+
const anchor = createAnchor(parent);
|
|
29
|
+
let mounted = [];
|
|
19
30
|
effect(() => {
|
|
20
|
-
const
|
|
21
|
-
|
|
31
|
+
const value = child();
|
|
32
|
+
const next = normalize(value);
|
|
33
|
+
removeNodes(mounted);
|
|
34
|
+
for (const n of next) {
|
|
35
|
+
parent.insertBefore(n, anchor);
|
|
36
|
+
}
|
|
37
|
+
mounted = next;
|
|
22
38
|
});
|
|
23
39
|
return;
|
|
24
40
|
}
|
|
@@ -26,7 +42,9 @@ function mountChild(parent, child) {
|
|
|
26
42
|
mountChild(parent, () => child.val);
|
|
27
43
|
return;
|
|
28
44
|
}
|
|
29
|
-
|
|
45
|
+
for (const node of normalize(child)) {
|
|
46
|
+
parent.appendChild(node);
|
|
47
|
+
}
|
|
30
48
|
}
|
|
31
49
|
|
|
32
50
|
// src/jsx/jsx.ts
|
package/dist/jsx-dev-runtime.js
CHANGED
package/dist/jsx-runtime.js
CHANGED