mini-jsx-test-pb 0.1.1 → 0.1.3
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/dist/index.d.ts +1 -3
- package/dist/index.js +33 -7
- package/package.json +1 -1
- package/dist/chunk-2FID3L6G.js +0 -89
- package/dist/jsx-dev-runtime.d.ts +0 -3
- package/dist/jsx-dev-runtime.js +0 -11
- package/dist/jsx-runtime.d.ts +0 -4
- package/dist/jsx-runtime.js +0 -15
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/reactivity/state.ts
|
|
2
|
+
var activeEffect = null;
|
|
3
|
+
function State(initial) {
|
|
4
|
+
let value = initial;
|
|
5
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
6
|
+
return {
|
|
7
|
+
get val() {
|
|
8
|
+
if (activeEffect) {
|
|
9
|
+
subscribers.add(activeEffect);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
},
|
|
13
|
+
set val(next) {
|
|
14
|
+
if (Object.is(value, next)) return;
|
|
15
|
+
value = next;
|
|
16
|
+
subscribers.forEach((fn) => fn());
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function setActiveEffect(effect2) {
|
|
21
|
+
activeEffect = effect2;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/reactivity/effect.ts
|
|
25
|
+
function effect(fn) {
|
|
26
|
+
const runner = () => {
|
|
27
|
+
setActiveEffect(runner);
|
|
28
|
+
fn();
|
|
29
|
+
setActiveEffect(null);
|
|
30
|
+
};
|
|
31
|
+
runner();
|
|
32
|
+
}
|
|
6
33
|
export {
|
|
7
34
|
State,
|
|
8
|
-
effect
|
|
9
|
-
h
|
|
35
|
+
effect
|
|
10
36
|
};
|
package/package.json
CHANGED
package/dist/chunk-2FID3L6G.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// src/state.ts
|
|
2
|
-
var activeEffect = null;
|
|
3
|
-
function State(initial) {
|
|
4
|
-
let value = initial;
|
|
5
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
6
|
-
return {
|
|
7
|
-
get val() {
|
|
8
|
-
if (activeEffect) {
|
|
9
|
-
subscribers.add(activeEffect);
|
|
10
|
-
}
|
|
11
|
-
return value;
|
|
12
|
-
},
|
|
13
|
-
set val(next) {
|
|
14
|
-
if (Object.is(value, next)) return;
|
|
15
|
-
value = next;
|
|
16
|
-
subscribers.forEach((fn) => fn());
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function setActiveEffect(effect2) {
|
|
21
|
-
activeEffect = effect2;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/effect.ts
|
|
25
|
-
function effect(fn) {
|
|
26
|
-
const runner = () => {
|
|
27
|
-
setActiveEffect(runner);
|
|
28
|
-
fn();
|
|
29
|
-
setActiveEffect(null);
|
|
30
|
-
};
|
|
31
|
-
runner();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/mount.ts
|
|
35
|
-
function mountChild(parent, child) {
|
|
36
|
-
if (child == null || child === true || child === false) return;
|
|
37
|
-
if (Array.isArray(child)) {
|
|
38
|
-
for (const c of child) mountChild(parent, c);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (child instanceof Node) {
|
|
42
|
-
parent.appendChild(child);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (typeof child === "function") {
|
|
46
|
-
const text = document.createTextNode("");
|
|
47
|
-
parent.appendChild(text);
|
|
48
|
-
effect(() => {
|
|
49
|
-
const v = child();
|
|
50
|
-
text.nodeValue = v == null ? "" : String(v);
|
|
51
|
-
});
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (typeof child === "object" && child && "val" in child) {
|
|
55
|
-
mountChild(parent, () => child.val);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
parent.appendChild(document.createTextNode(String(child)));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// src/jsx.ts
|
|
62
|
-
function h(type, props, ...rest) {
|
|
63
|
-
if (typeof type === "function") {
|
|
64
|
-
return type(props ?? {});
|
|
65
|
-
}
|
|
66
|
-
const el = document.createElement(type);
|
|
67
|
-
if (props) {
|
|
68
|
-
for (const key in props) {
|
|
69
|
-
if (key === "children") continue;
|
|
70
|
-
const value = props[key];
|
|
71
|
-
if (key.startsWith("on")) {
|
|
72
|
-
el.addEventListener(key.slice(2).toLowerCase(), value);
|
|
73
|
-
} else {
|
|
74
|
-
el.setAttribute(key, String(value));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const children = rest.length > 0 ? rest : props?.children != null ? Array.isArray(props.children) ? props.children : [props.children] : [];
|
|
79
|
-
for (const child of children) {
|
|
80
|
-
mountChild(el, child);
|
|
81
|
-
}
|
|
82
|
-
return el;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export {
|
|
86
|
-
State,
|
|
87
|
-
effect,
|
|
88
|
-
h
|
|
89
|
-
};
|
package/dist/jsx-dev-runtime.js
DELETED
package/dist/jsx-runtime.d.ts
DELETED
package/dist/jsx-runtime.js
DELETED