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 CHANGED
@@ -17,6 +17,4 @@ declare function State<T>(initial: T): {
17
17
 
18
18
  declare function effect(fn: Effect): void;
19
19
 
20
- declare function h(type: any, props: any, ...rest: any[]): any;
21
-
22
- export { State, effect, h };
20
+ export { State, effect };
package/dist/index.js CHANGED
@@ -1,10 +1,36 @@
1
- import {
2
- State,
3
- effect,
4
- h
5
- } from "./chunk-2FID3L6G.js";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-jsx-test-pb",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -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
- };
@@ -1,3 +0,0 @@
1
- declare function jsxDEV(type: any, props: any): any;
2
-
3
- export { jsxDEV };
@@ -1,11 +0,0 @@
1
- import {
2
- h
3
- } from "./chunk-2FID3L6G.js";
4
-
5
- // src/jsx-dev-runtime.ts
6
- function jsxDEV(type, props) {
7
- return h(type, props);
8
- }
9
- export {
10
- jsxDEV
11
- };
@@ -1,4 +0,0 @@
1
- declare function jsx(type: any, props: any): any;
2
- declare function jsxs(type: any, props: any): any;
3
-
4
- export { jsx, jsxs };
@@ -1,15 +0,0 @@
1
- import {
2
- h
3
- } from "./chunk-2FID3L6G.js";
4
-
5
- // src/jsx-runtime.ts
6
- function jsx(type, props) {
7
- return h(type, props);
8
- }
9
- function jsxs(type, props) {
10
- return h(type, props);
11
- }
12
- export {
13
- jsx,
14
- jsxs
15
- };