mini-jsx-test-pb 0.1.0 → 0.1.2

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
@@ -1,5 +1,3 @@
1
- export { jsxDEV as h } from './jsx-dev-runtime.js';
2
-
3
1
  declare global {
4
2
  namespace JSX {
5
3
  interface IntrinsicElements {
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.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -11,19 +11,19 @@
11
11
  "import": "./dist/index.js"
12
12
  },
13
13
  "./jsx-runtime": {
14
- "types": "./dist/jsx-runtime.d.ts",
15
- "import": "./dist/jsx-runtime.js"
14
+ "types": "./dist/runtime.d.ts",
15
+ "import": "./dist/runtime.js"
16
16
  },
17
17
  "./jsx-dev-runtime": {
18
- "types": "./dist/jsx-dev-runtime.d.ts",
19
- "import": "./dist/jsx-dev-runtime.js"
18
+ "types": "./dist/dev-runtime.d.ts",
19
+ "import": "./dist/dev-runtime.js"
20
20
  }
21
21
  },
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
25
  "scripts": {
26
- "build": "tsup src/index.ts src/jsx-runtime.ts src/jsx-dev-runtime.ts --format esm --dts",
26
+ "build": "tsup src/index.ts src/runtime.ts src/dev-runtime.ts --format esm --dts",
27
27
  "dev": "tsup src/index.ts --format esm --dts --watch"
28
28
  },
29
29
  "devDependencies": {
@@ -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 h(type: any, props: any, ...rest: any[]): any;
2
-
3
- export { h as jsxDEV };
@@ -1,6 +0,0 @@
1
- import {
2
- h
3
- } from "./chunk-2FID3L6G.js";
4
- export {
5
- h as jsxDEV
6
- };
@@ -1 +0,0 @@
1
- export { jsxDEV as jsx, jsxDEV as jsxs } from './jsx-dev-runtime.js';
@@ -1,7 +0,0 @@
1
- import {
2
- h
3
- } from "./chunk-2FID3L6G.js";
4
- export {
5
- h as jsx,
6
- h as jsxs
7
- };