humn 1.0.1 → 1.3.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Keeghan McGarry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,87 +1,75 @@
1
- # Humn (/ˈhjuː.mən/)
1
+ # humn
2
2
 
3
- [![NPM version](https://img.shields.io/npm/v/humn.svg)](https://www.npmjs.com/package/humn)
3
+ Humn is a minimal, human-centric reactive UI library with built-in state management. It's designed to be simple, intuitive, and powerful.
4
4
 
5
- > **The organic, human-centric UI library for the modern web.**
6
-
7
- **Humn** is a complete, reactive frontend library with built in state management designed to replace the likes of React/Svelte/Solid AND Zustand/Kea/Redux in your stack.
8
-
9
- It rejects the complexity of modern frameworks **no stale closures, no "Hook Rules", and no heavy compilers**. Humn decouples your application's **Cortex** (Logic/State) from its **Body** (View), creating applications that are easy to reason about, simple to test, and naturally reactive.
10
-
11
- ## Core Features
12
-
13
- - **🧬 Biological Architecture:** A strict separation of concerns. Your data lives in the `Cortex`; your UI is just a dumb projection of that memory.
14
- - **⚡ Zero-Build Reactive View:** Write standard JavaScript. Components are just functions that return virtual DOM nodes. No compilation required (unless you want it).
15
- - **🧠 Built-in Global State:** No need for Redux or Zustand. The `Cortex` is built-in, handling deep updates, async actions, and side effects out of the box.
16
- - **mutative syntax, immutable updates:** Write `state.count++`. We handle the immutability and render triggers for you.
17
- - **🎨 Scoped Styles:** Encapsulated CSS that lives alongside your components.
5
+ This package is the core `humn` library.
18
6
 
19
7
  ## Installation
20
8
 
21
9
  ```bash
22
10
  npm install humn
23
- # or yarn add humn
24
- # or pnpm install humn
11
+ npm install -D vite-plugin-humn
25
12
  ```
26
13
 
27
- ## The "Hello World" (That actually scales)
14
+ ## Quick Start
28
15
 
29
- Unlike other libraries, Humn encourages separating logic from the start.
16
+ Here's a simple counter example using `.humn` files.
30
17
 
31
- ### The Cortex (Logic)
18
+ ### 1. Create a Cortex (Store)
32
19
 
33
- ```JavaScript
20
+ The `Cortex` holds your application's state (`memory`) and the actions that can modify it (`synapses`).
34
21
 
35
- import { Cortex } from 'humn';
22
+ ```javascript
23
+ // store.js
24
+ import { Cortex } from 'humn'
36
25
 
37
- export const appStore = new Cortex({
26
+ export const counterStore = new Cortex({
38
27
  memory: {
39
28
  count: 0,
40
- user: 'Guest'
41
29
  },
42
- synapses: (set, get) => ({
43
- increment: () => set(state => { state.count++ }),
44
- login: (name) => set({ user: name })
45
- })
46
- });
30
+ synapses: (set) => ({
31
+ increment: () =>
32
+ set((state) => {
33
+ state.count++
34
+ }),
35
+ decrement: () =>
36
+ set((state) => {
37
+ state.count--
38
+ }),
39
+ }),
40
+ })
47
41
  ```
48
42
 
49
- ### The View (UI)
43
+ ### 2. Create a Component
50
44
 
51
- ```JavaScript
45
+ Components are defined in `.humn` files, which combine logic, template, and styles.
52
46
 
53
- import { h, mount } from 'humn-js';
54
- import { appStore } from './store';
47
+ ```html
48
+ <!-- App.humn -->
49
+ <script>
50
+ import { counterStore } from './store'
55
51
 
56
- const App = () => {
57
- // 1. Read Memory (Auto-subscribes)
58
- const { count, user } = appStore.memory;
59
- const { increment } = appStore.synapses;
52
+ const { count } = counterStore.memory
53
+ const { increment, decrement } = counterStore.synapses
54
+ </script>
60
55
 
61
- // 2. Return V-DOM
62
- return h('div', { class: 'container' }, [
63
- h('h1', {}, `Hello, ${user}`),
64
- h('p', {}, `Vital Signs: ${count}`),
65
- h('button', { onclick: increment }, 'Pulse')
66
- ]);
67
- };
68
-
69
- // 3. Mount
70
- mount(document.getElementById('root'), App);
56
+ <div>
57
+ <h1>Count: {count}</h1>
58
+ <button onclick="{increment}">+</button>
59
+ <button onclick="{decrement}">-</button>
60
+ </div>
71
61
  ```
72
62
 
73
- ## Roadmap
63
+ ### 3. Mount
64
+
65
+ ```javascript
66
+ // main.js
67
+ import { mount } from 'humn'
68
+ import App from './App.humn'
74
69
 
75
- - [x] **Cortex:** State management with dependency tracking.
76
- - [x] **Virtual DOM:** Lightweight `h()` function.
77
- - [x] **Reconciliation:** Keyed Diffing Algorithm.
78
- - [x] **Scoped Styles:** Runtime CSS-in-JS with `css` tag.
79
- - [x] **Lifecycle Hooks:** `onMount` and `onCleanup` for components (Needed for API calls/Timers).
80
- - [ ] **Global Store Persist:** Middleware to save Cortex state to `localStorage`.
81
- - [ ] **Humn Compiler:** `.humn` files for Svelte-like syntax.
82
- - [ ] **Async Components:** Handling `Promise` rendering (Suspense).
83
- - [ ] **DevTools:** Browser extension to inspect the Cortex Memory.
70
+ mount(document.getElementById('root'), App)
71
+ ```
84
72
 
85
- ## Contributing
73
+ ## Learn More
86
74
 
87
- We are building a library for humans, by humans. Please read CODING_STANDARDS.md before pushing code.
75
+ For a complete guide, including information on lifecycle hooks, scoped CSS, `.humn` files, and more, please see the [**full documentation in the docs**](../../docs/guides/getting-started.md).
package/dist/humn.js CHANGED
@@ -1,207 +1,211 @@
1
- let C = null, S = null;
2
- const x = () => C, g = (t) => {
3
- C = t;
4
- }, A = () => S, k = (t) => {
5
- S = t;
1
+ let C = null, x = null;
2
+ const S = () => C, g = (e) => {
3
+ C = e;
4
+ }, E = () => x, k = (e) => {
5
+ x = e;
6
6
  };
7
- class T {
8
- /**
9
- * Creates an instance of Cortex.
10
- * @param {CortexParams} CortexParams - The parameters for the Cortex.
11
- */
12
- constructor({ memory: e, synapses: s }) {
13
- this._memory = e, this._listeners = /* @__PURE__ */ new Set();
14
- const i = () => this._memory, c = (n) => {
15
- let r;
16
- if (typeof n == "function") {
17
- const o = structuredClone(this._memory);
18
- r = n(o) || o;
19
- } else
20
- r = { ...this._memory, ...n };
21
- this._memory = r, this._listeners.forEach((o) => o());
22
- };
23
- this.synapses = s(c, i);
7
+ class w {
8
+ constructor({ memory: t, synapses: o }) {
9
+ const i = { ...t };
10
+ this._persistenceMap = /* @__PURE__ */ new Map();
11
+ for (const [s, r] of Object.entries(t)) if (r && r.__humn_persist) {
12
+ const c = r.config.key || s;
13
+ this._persistenceMap.set(s, c);
14
+ try {
15
+ const n = localStorage.getItem(c);
16
+ i[s] = n !== null ? JSON.parse(n) : r.initial;
17
+ } catch {
18
+ i[s] = r.initial;
19
+ }
20
+ }
21
+ this._memory = i, this._listeners = /* @__PURE__ */ new Map(), this.synapses = o((s) => {
22
+ let r, c = /* @__PURE__ */ new Set();
23
+ if (typeof s == "function") {
24
+ const n = structuredClone(this._memory), l = s(this._createChangeTrackingProxy(n, c));
25
+ l && typeof l == "object" ? (r = { ...this._memory, ...l }, Object.keys(l).forEach((a) => c.add(a))) : r = n;
26
+ } else r = { ...this._memory, ...s }, c = new Set(Object.keys(s));
27
+ this._memory = r, this._persistenceMap.size > 0 && this._persistenceMap.forEach((n, l) => {
28
+ if (Array.from(c).some((a) => a === l || a.startsWith(l + "."))) try {
29
+ const a = this._memory[l];
30
+ localStorage.setItem(n, JSON.stringify(a));
31
+ } catch {
32
+ }
33
+ }), this._notifyRelevantListeners(c);
34
+ }, () => this._memory);
35
+ }
36
+ _createChangeTrackingProxy(t, o, i = "") {
37
+ return new Proxy(t, { get: (s, r) => {
38
+ if (typeof r == "symbol" || r === "__proto__") return s[r];
39
+ const c = s[r], n = i ? `${i}.${r}` : r;
40
+ return typeof c == "object" && c !== null ? this._createChangeTrackingProxy(c, o, n) : c;
41
+ }, set: (s, r, c) => {
42
+ if (typeof r == "symbol" || r === "__proto__") return s[r] = c, !0;
43
+ const n = i ? `${i}.${r}` : r;
44
+ return o.add(n), s[r] = c, !0;
45
+ } });
46
+ }
47
+ _notifyRelevantListeners(t) {
48
+ this._listeners.forEach((o, i) => {
49
+ Array.from(o).some((s) => Array.from(t).some((r) => s === r || s.startsWith(r + ".") || r.startsWith(s + "."))) && i();
50
+ });
51
+ }
52
+ _createAccessTrackingProxy(t, o, i = "") {
53
+ return typeof t != "object" || t === null ? t : new Proxy(t, { get: (s, r) => {
54
+ if (typeof r == "symbol" || r === "__proto__") return s[r];
55
+ const c = i ? `${i}.${r}` : r;
56
+ o.add(c);
57
+ const n = s[r];
58
+ return typeof n == "object" && n !== null ? this._createAccessTrackingProxy(n, o, c) : n;
59
+ } });
24
60
  }
25
- /**
26
- * Get the memory and register the current observer.
27
- * @returns {object} The current state
28
- */
29
61
  get memory() {
30
- const e = x();
31
- return e && this._listeners.add(e), this._memory;
62
+ const t = S();
63
+ if (!t) return this._memory;
64
+ this._listeners.has(t) || this._listeners.set(t, /* @__PURE__ */ new Set());
65
+ const o = this._listeners.get(t);
66
+ return o.clear(), this._createAccessTrackingProxy(this._memory, o);
32
67
  }
33
68
  }
34
- let h = null;
35
- const E = /* @__PURE__ */ new Set();
36
- function I(t) {
37
- let e = 5381, s = t.length;
38
- for (; s; )
39
- e = e * 33 ^ t.charCodeAt(--s);
40
- return (e >>> 0).toString(36);
41
- }
42
- function O(t) {
43
- return t.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").trim();
44
- }
45
- function K(t, ...e) {
46
- const s = t.reduce((r, o, l) => r + o + (e[l] || ""), ""), i = O(s);
47
- if (!i) return "";
48
- const c = I(i), n = `humn-${c}`;
49
- return E.has(c) || (h || (h = document.createElement("style"), h.id = "humn-styles", document.head.appendChild(h)), h.textContent += `.${n} {
50
- ${i}
69
+ let p = null;
70
+ const v = /* @__PURE__ */ new Set();
71
+ function T(e, ...t) {
72
+ let o = "", i = !1;
73
+ Array.isArray(e) && e.raw ? o = e.reduce((n, l, a) => n + l + (t[a] || ""), "") : (o = e, i = t[0] === !0);
74
+ let s = (function(n) {
75
+ return n.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").trim();
76
+ })(o);
77
+ if (!s) return "";
78
+ i && (s = s.replace(/(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi, "$1$2$3&, $3"));
79
+ const r = (function(n) {
80
+ let l = 5381, a = n.length;
81
+ for (; a; ) l = 33 * l ^ n.charCodeAt(--a);
82
+ return (l >>> 0).toString(36);
83
+ })(s), c = `humn-${r}`;
84
+ return v.has(r) || (p || (p = document.createElement("style"), p.id = "humn-styles", document.head.appendChild(p)), p.textContent += `.${c} {
85
+ ${s}
51
86
  }
52
- `, E.add(c)), n;
87
+ `, v.add(r)), c;
53
88
  }
54
- const $ = (t, e = {}, s = []) => {
55
- const c = (Array.isArray(s) ? s : [s]).flat().filter((n) => n != null && n !== !1 && n !== "");
56
- return {
57
- tag: t,
58
- props: e,
59
- children: c
60
- };
61
- };
62
- function B(t) {
63
- const e = A();
64
- e && e.mounts.push(t);
89
+ const j = (e, t = {}, o = []) => ({ tag: e, props: t, children: (Array.isArray(o) ? o : [o]).flat().filter((i) => i != null && i !== !1 && i !== "") });
90
+ function M(e) {
91
+ const t = E();
92
+ t && t.mounts.push(e);
65
93
  }
66
- function M(t) {
67
- const e = A();
68
- e && e.cleanups.push(t);
94
+ function P(e) {
95
+ const t = E();
96
+ t && t.cleanups.push(e);
69
97
  }
70
- function b(t) {
71
- return t && t.some((e) => e && e.props && e.props.key != null);
98
+ function b(e) {
99
+ return e && e.some((t) => t && t.props && t.props.key != null);
72
100
  }
73
- function a(t) {
74
- if (typeof t == "string" || typeof t == "number")
75
- return document.createTextNode(String(t));
76
- if (typeof t.tag == "function") {
77
- const s = d(t);
78
- t.child = s;
79
- const i = a(s);
80
- return t.el = i, t.hooks && t.hooks.mounts.length > 0 && setTimeout(() => t.hooks.mounts.forEach((c) => c()), 0), i;
101
+ function f(e) {
102
+ if (typeof e == "string" || typeof e == "number") return document.createTextNode(String(e));
103
+ if (typeof e.tag == "function") {
104
+ const o = A(e);
105
+ e.child = o;
106
+ const i = f(o);
107
+ return e.el = i, e.hooks && e.hooks.mounts.length > 0 && setTimeout(() => e.hooks.mounts.forEach((s) => s()), 0), i;
81
108
  }
82
- const e = document.createElement(t.tag);
83
- return t.el = e, _(e, t.props), t.children.forEach((s) => {
84
- e.appendChild(a(s));
85
- }), e;
109
+ const t = document.createElement(e.tag);
110
+ return e.el = t, N(t, e.props), e.children.forEach((o) => {
111
+ t.appendChild(f(o));
112
+ }), t;
86
113
  }
87
- function _(t, e = {}, s = {}) {
88
- if (!t) return;
89
- const i = { ...s, ...e };
90
- for (const c in i) {
91
- const n = s[c], r = e[c];
92
- if (r == null) {
93
- t.removeAttribute(c);
94
- continue;
95
- }
96
- if (c === "value" || c === "checked") {
97
- t[c] !== r && (t[c] = r);
98
- continue;
99
- }
100
- if (n !== r) {
101
- if (c.startsWith("on")) {
102
- const o = c.slice(2).toLowerCase();
103
- n && t.removeEventListener(o, n), t.addEventListener(o, r);
114
+ function N(e, t = {}, o = {}) {
115
+ if (!e) return;
116
+ const i = { ...o, ...t };
117
+ for (const s in i) {
118
+ const r = o[s], c = t[s];
119
+ if (c != null) if (s !== "value" && s !== "checked") {
120
+ if (r !== c) {
121
+ if (s.startsWith("on")) {
122
+ const n = s.slice(2).toLowerCase();
123
+ r && e.removeEventListener(n, r), e.addEventListener(n, c);
124
+ }
125
+ s === "disabled" ? e.disabled = c === !0 || c === "true" : e.setAttribute(s, c);
104
126
  }
105
- c === "disabled" ? t.disabled = r === !0 || r === "true" : t.setAttribute(c, r);
106
- }
127
+ } else e[s] !== c && (e[s] = c);
128
+ else e.removeAttribute(s);
107
129
  }
108
130
  }
109
- function L(t, e, s) {
110
- if (!(b(e) || b(s))) {
111
- const n = Math.max(e.length, s.length);
112
- for (let r = 0; r < n; r++)
113
- m(t, e[r], s[r], r);
131
+ function $(e, t, o) {
132
+ if (!(b(t) || b(o))) {
133
+ const i = Math.max(t.length, o.length);
134
+ for (let s = 0; s < i; s++) m(e, t[s], o[s], s);
114
135
  return;
115
136
  }
116
- const c = {};
117
- s.forEach((n, r) => {
118
- const o = (n.props && n.props.key) != null ? n.props.key : r;
119
- c[o] = { vNode: n, index: r };
120
- }), e.forEach((n, r) => {
121
- const o = (n.props && n.props.key) != null ? n.props.key : r, l = c[o];
122
- if (l) {
123
- const f = l.vNode;
124
- m(t, n, f, r);
125
- const u = n.el || f.el, y = t.childNodes[r];
126
- u && y !== u && t.insertBefore(u, y), delete c[o];
127
- } else {
128
- const f = a(n), u = t.childNodes[r];
129
- u ? t.insertBefore(f, u) : t.appendChild(f);
130
- }
131
- }), Object.values(c).forEach(({ vNode: n }) => {
132
- n.el && n.el.parentNode === t && t.removeChild(n.el);
133
- });
137
+ (function(i, s, r) {
138
+ const c = {};
139
+ r.forEach((n, l) => {
140
+ const a = (n.props && n.props.key) != null ? n.props.key : l;
141
+ c[a] = { vNode: n, index: l };
142
+ }), s.forEach((n, l) => {
143
+ const a = (n.props && n.props.key) != null ? n.props.key : l, y = c[a];
144
+ if (y) {
145
+ const u = y.vNode;
146
+ m(i, n, u, l);
147
+ const h = n.el || u.el, _ = i.childNodes[l];
148
+ h && _ !== h && i.insertBefore(h, _), delete c[a];
149
+ } else {
150
+ const u = f(n), h = i.childNodes[l];
151
+ h ? i.insertBefore(u, h) : i.appendChild(u);
152
+ }
153
+ }), Object.values(c).forEach(({ vNode: n }) => {
154
+ n.el && n.el.parentNode === i && (d(n), i.removeChild(n.el));
155
+ });
156
+ })(e, t, o);
134
157
  }
135
- function d(t) {
136
- const e = {
137
- mounts: [],
138
- cleanups: []
139
- };
140
- k(e);
141
- const s = t.tag(t.props);
142
- return k(null), t.hooks = e, s;
158
+ function A(e) {
159
+ const t = { mounts: [], cleanups: [] };
160
+ k(t);
161
+ const o = e.tag(e.props);
162
+ return k(null), e.hooks = t, o;
143
163
  }
144
- function p(t) {
145
- t && (t.hooks && t.hooks.cleanups && t.hooks.cleanups.forEach((e) => e()), t.child && p(t.child), t.children && t.children.forEach(p));
164
+ function d(e) {
165
+ e && (e.hooks && e.hooks.cleanups && e.hooks.cleanups.forEach((t) => t()), e.child && d(e.child), e.children && e.children.forEach(d));
146
166
  }
147
- function m(t, e, s, i = 0) {
148
- if (e == null) {
149
- const n = s.el || t.childNodes[i];
150
- p(s), n && t.removeChild(n);
151
- return;
152
- }
153
- if (typeof e.tag == "function") {
154
- const n = !s, r = d(e);
155
- e.child = r;
156
- const o = s ? s.child : void 0;
157
- m(t, r, o, i), e.el = r.el, n && e.hooks && e.hooks.mounts.length > 0 && setTimeout(() => {
158
- e.hooks.mounts.forEach((l) => l());
159
- }, 0);
160
- return;
167
+ function m(e, t, o, i = 0) {
168
+ if (t == null) {
169
+ const r = o.el || e.childNodes[i];
170
+ return d(o), void (r && e.removeChild(r));
161
171
  }
162
- if (s == null) {
163
- t.appendChild(a(e));
164
- return;
165
- }
166
- if (e == null) {
167
- const n = s.el || t.childNodes[i];
168
- n && t.removeChild(n);
169
- return;
172
+ if (typeof t.tag == "function") {
173
+ const r = !o, c = A(t);
174
+ return t.child = c, m(e, c, o ? o.child : void 0, i), t.el = c.el, void (r && t.hooks && t.hooks.mounts.length > 0 && setTimeout(() => {
175
+ t.hooks.mounts.forEach((n) => n());
176
+ }, 0));
170
177
  }
171
- if (typeof e != typeof s || typeof e != "string" && e.tag !== s.tag) {
172
- const n = s.el || t.childNodes[i];
173
- n && t.replaceChild(a(e), n);
174
- return;
178
+ if (o == null) return void e.appendChild(f(t));
179
+ if (typeof t != typeof o || typeof t != "string" && t.tag !== o.tag) {
180
+ const r = o.el || e.childNodes[i];
181
+ return void (r && e.replaceChild(f(t), r));
175
182
  }
176
- if (typeof e == "string" || typeof e == "number") {
177
- if (e !== s) {
178
- const n = t.childNodes[i];
179
- n ? n.nodeValue = String(e) : t.appendChild(document.createTextNode(String(e)));
183
+ if (typeof t == "string" || typeof t == "number") {
184
+ if (t !== o) {
185
+ const r = e.childNodes[i];
186
+ r ? r.nodeValue = String(t) : e.appendChild(document.createTextNode(String(t)));
180
187
  }
181
188
  return;
182
189
  }
183
- const c = s.el || t.childNodes[i];
184
- c && (e.el = c, _(c, e.props, s.props), L(c, e.children, s.children));
190
+ const s = o.el || e.childNodes[i];
191
+ s && (t.el = s, N(s, t.props, o.props), $(s, t.children, o.children));
185
192
  }
186
- const j = (t, e) => {
187
- let s = null;
193
+ const O = (e, t) => {
194
+ let o = null;
188
195
  const i = () => {
189
196
  g(i);
190
- const c = {
191
- tag: e,
192
- props: {},
193
- children: []
194
- };
195
- m(t, c, s), g(null), s = c;
197
+ const s = { tag: t, props: {}, children: [] };
198
+ m(e, s, o), g(null), o = s;
196
199
  };
197
200
  i();
198
- };
201
+ }, L = (e, t = {}) => ({ __humn_persist: !0, initial: e, config: t });
199
202
  export {
200
- T as Cortex,
201
- K as css,
202
- $ as h,
203
- j as mount,
204
- M as onCleanup,
205
- B as onMount
203
+ w as Cortex,
204
+ T as css,
205
+ j as h,
206
+ O as mount,
207
+ P as onCleanup,
208
+ M as onMount,
209
+ L as persist
206
210
  };
207
211
  //# sourceMappingURL=humn.js.map
package/dist/humn.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"humn.js","sources":["../src/observer.js","../src/cortex.js","../src/css.js","../src/h.js","../src/lifecycle.js","../src/patch.js","../src/mount.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null; // For Cortex/State dependency\nlet currentInstance = null; // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver;\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs;\n};\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance;\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst;\n};\n","import { getObserver } from \"./observer.js\";\n\n/**\n * @typedef {object} Synapses\n * @property {function} set - Function to update the memory\n * @property {function} get - Function to get the memory\n */\n\n/**\n * @typedef {object} CortexParams\n * @property {object} memory - The initial state\n * @property {function(function, function): object} synapses - The synapses function\n */\n\n/**\n * The Cortex class manages the state of the application.\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexParams} CortexParams - The parameters for the Cortex.\n */\n constructor({ memory, synapses }) {\n this._memory = memory;\n this._listeners = new Set();\n\n const get = () => this._memory;\n\n const set = (updater) => {\n let nextState;\n if (typeof updater === \"function\") {\n const clone = structuredClone(this._memory);\n const result = updater(clone);\n nextState = result || clone;\n } else {\n nextState = { ...this._memory, ...updater };\n }\n\n this._memory = nextState;\n this._listeners.forEach((render) => render());\n };\n\n this.synapses = synapses(set, get);\n }\n\n /**\n * Get the memory and register the current observer.\n * @returns {object} The current state\n */\n get memory() {\n const currentObserver = getObserver();\n if (currentObserver) this._listeners.add(currentObserver);\n return this._memory;\n }\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null;\nconst cache = new Set();\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381;\n let i = str.length;\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i);\n }\n return (hash >>> 0).toString(36);\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\") // Remove comments\n .replace(/\\s+/g, \" \") // Collapse newlines/tabs to single space\n .trim(); // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n */\nexport function css(strings, ...args) {\n const raw = strings.reduce((acc, str, i) => {\n return acc + str + (args[i] || \"\");\n }, \"\");\n\n const content = minify(raw);\n\n if (!content) return \"\";\n\n const hash = hashString(content);\n const className = `humn-${hash}`;\n\n if (cache.has(hash)) {\n return className;\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement(\"style\");\n styleSheet.id = \"humn-styles\";\n document.head.appendChild(styleSheet);\n }\n\n styleSheet.textContent += `.${className} { \n ${content} \n }\\n`;\n cache.add(hash);\n\n return className;\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children];\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat() \n .filter(c => c !== null && c !== undefined && c !== false && c !== '');\n\n return {\n tag,\n props,\n children: cleanChildren\n };\n};\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from \"./observer.js\";\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance();\n if (instance) {\n instance.mounts.push(fn);\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance();\n if (instance) {\n instance.cleanups.push(fn);\n }\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { setInstance } from \"./observer.js\";\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null);\n}\n\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h\").VNode | string | number} vNode - The virtual node.\n * @returns {Text | HTMLElement} The created DOM element.\n */\nfunction createElement(vNode) {\n if (typeof vNode === \"string\" || typeof vNode === \"number\") {\n return document.createTextNode(String(vNode));\n }\n\n if (typeof vNode.tag === \"function\") {\n const childVNode = renderComponent(vNode);\n vNode.child = childVNode;\n\n // Recursively create the DOM for the child\n const el = createElement(childVNode);\n vNode.el = el;\n\n // Queue Mount Hooks\n if (vNode.hooks && vNode.hooks.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0);\n }\n return el;\n }\n\n const el = document.createElement(vNode.tag);\n vNode.el = el;\n patchProps(el, vNode.props);\n\n vNode.children.forEach((child) => {\n el.appendChild(createElement(child));\n });\n\n return el;\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} el - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n */\nfunction patchProps(el, newProps = {}, oldProps = {}) {\n if (!el) return;\n\n const allProps = { ...oldProps, ...newProps };\n\n for (const key in allProps) {\n const oldValue = oldProps[key];\n const newValue = newProps[key];\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n el.removeAttribute(key);\n continue;\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === \"value\" || key === \"checked\") {\n if (el[key] !== newValue) {\n el[key] = newValue;\n }\n continue;\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue;\n\n // Handle Events\n if (key.startsWith(\"on\")) {\n const eventName = key.slice(2).toLowerCase();\n if (oldValue) el.removeEventListener(eventName, oldValue);\n el.addEventListener(eventName, newValue);\n }\n // Handle the disabled attribute\n if (key === \"disabled\") {\n el.disabled = newValue === true || newValue === \"true\";\n }\n // Handle standard attributes\n else {\n el.setAttribute(key, newValue);\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h\").VNode>} oldChildren - The old list of children.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren);\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length);\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i);\n }\n return;\n }\n\n // Keyed Diffing\n // Map existing children by Key\n const keyed = {};\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i;\n keyed[key] = { vNode: child, index: i };\n });\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i;\n const oldItem = keyed[key];\n\n if (oldItem) {\n // A. MATCH FOUND\n const oldVNode = oldItem.vNode;\n\n // Update the node's content (Recursion)\n patch(parent, newChild, oldVNode, i);\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const el = newChild.el || oldVNode.el;\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i];\n\n // If the element exists but is in the wrong place, move it\n if (el && domChildAtIndex !== el) {\n parent.insertBefore(el, domChildAtIndex);\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key];\n } else {\n // B. NO MATCH (New Item)\n const newEl = createElement(newChild);\n const domChildAtIndex = parent.childNodes[i];\n\n if (domChildAtIndex) {\n parent.insertBefore(newEl, domChildAtIndex);\n } else {\n parent.appendChild(newEl);\n }\n }\n });\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n parent.removeChild(vNode.el);\n }\n });\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h\").VNode} vNode - The component vNode.\n * @returns {import(\"./h\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n };\n\n // 2. Set Global Scope\n setInstance(hooks);\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props);\n\n // 4. Clear Global Scope\n setInstance(null);\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks;\n\n return renderedVNode;\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return;\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn());\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child);\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount);\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n // --- HANDLE UNMOUNTING (Cleanup Hooks) ---\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index];\n\n // Recursive Cleanup\n runUnmount(oldVNode);\n\n if (el) parent.removeChild(el);\n return;\n }\n\n // --- HANDLE COMPONENT (Functional VNode) ---\n if (typeof newVNode.tag === \"function\") {\n const isNew = !oldVNode;\n\n // 1. Render the component function\n const childVNode = renderComponent(newVNode);\n\n // 2. Store the result in the vNode (\"unwrap\" it)\n newVNode.child = childVNode;\n\n // 3. Recursively patch the result\n const oldChild = oldVNode ? oldVNode.child : undefined;\n patch(parent, childVNode, oldChild, index);\n\n // 4. Ensure VNode holds the DOM reference\n newVNode.el = childVNode.el;\n\n // 5. Run Mount Hooks (Next Tick)\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn());\n }, 0);\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return;\n }\n\n // Start - No old node? Create new.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode));\n return;\n }\n\n // Removal - No new node? Remove old.\n if (newVNode === undefined || newVNode === null) {\n // Try to find the element on the VNode, or fallback to index\n const el = oldVNode.el || parent.childNodes[index];\n if (el) parent.removeChild(el);\n return;\n }\n\n // Changed Type - (e.g. <div> becomes <span>) -> Replace whole node\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== \"string\" && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index];\n if (el) parent.replaceChild(createElement(newVNode), el);\n return;\n }\n\n // Text Update\n if (typeof newVNode === \"string\" || typeof newVNode === \"number\") {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index];\n if (el) {\n el.nodeValue = String(newVNode);\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)));\n }\n }\n return;\n }\n\n // Same Tag - Update Props & Children\n const el = oldVNode.el || parent.childNodes[index];\n\n if (!el) return;\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el;\n\n patchProps(el, newVNode.props, oldVNode.props);\n\n reconcileChildren(el, newVNode.children, oldVNode.children);\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from \"./observer.js\";\nimport { patch } from \"./patch.js\";\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null;\n\n const lifecycle = () => {\n setObserver(lifecycle);\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n };\n\n patch(target, nextVNode, prevVNode);\n setObserver(null);\n prevVNode = nextVNode;\n };\n\n lifecycle();\n};\n"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","get","set","updater","nextState","clone","render","styleSheet","cache","hashString","str","hash","i","minify","css","strings","args","raw","acc","content","className","h","tag","props","children","cleanChildren","c","onMount","fn","instance","onCleanup","hasKeys","createElement","vNode","childVNode","renderComponent","el","patchProps","child","newProps","oldProps","allProps","key","oldValue","newValue","eventName","reconcileChildren","parent","newChildren","oldChildren","maxLen","patch","keyed","newChild","oldItem","oldVNode","domChildAtIndex","newEl","hooks","renderedVNode","runUnmount","newVNode","index","isNew","oldChild","mount","target","Component","prevVNode","lifecycle","nextVNode"],"mappings":"AAKA,IAAIA,IAAkB,MAClBC,IAAkB;AAMf,MAAMC,IAAc,MAAMF,GAMpBG,IAAc,CAACC,MAAQ;AAClC,EAAAJ,IAAkBI;AACpB,GAMaC,IAAc,MAAMJ,GAMpBK,IAAc,CAACC,MAAS;AACnC,EAAAN,IAAkBM;AACpB;ACjBO,MAAMC,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlB,YAAY,EAAE,QAAAC,GAAQ,UAAAC,KAAY;AAChC,SAAK,UAAUD,GACf,KAAK,aAAa,oBAAI,IAAG;AAEzB,UAAME,IAAM,MAAM,KAAK,SAEjBC,IAAM,CAAC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,EAAO,WAAWe,CAAK;AACjD,IAAI1B,KAAIW,EAAO,aAAaf,EAAc6B,CAAQ,GAAGzB,CAAE;AACvD;AAAA,EACF;AAGA,MAAI,OAAOyB,KAAa,YAAY,OAAOA,KAAa,UAAU;AAChE,QAAIA,MAAaN,GAAU;AACzB,YAAMnB,IAAKW,EAAO,WAAWe,CAAK;AAClC,MAAI1B,IACFA,EAAG,YAAY,OAAOyB,CAAQ,IAG9Bd,EAAO,YAAY,SAAS,eAAe,OAAOc,CAAQ,CAAC,CAAC;AAAA,IAEhE;AACA;AAAA,EACF;AAGA,QAAMzB,IAAKmB,EAAS,MAAMR,EAAO,WAAWe,CAAK;AAEjD,EAAK1B,MAGLyB,EAAS,KAAKzB,GAEdC,EAAWD,GAAIyB,EAAS,OAAON,EAAS,KAAK,GAE7CT,EAAkBV,GAAIyB,EAAS,UAAUN,EAAS,QAAQ;AAC5D;ACrTY,MAACU,IAAQ,CAACC,GAAQC,MAAc;AAC1C,MAAIC,IAAY;AAEhB,QAAMC,IAAY,MAAM;AACtB,IAAA5E,EAAY4E,CAAS;AAErB,UAAMC,IAAY;AAAA,MAChB,KAAKH;AAAA,MACL,OAAO,CAAA;AAAA,MACP,UAAU,CAAA;AAAA,IAChB;AAEI,IAAAhB,EAAMe,GAAQI,GAAWF,CAAS,GAClC3E,EAAY,IAAI,GAChB2E,IAAYE;AAAA,EACd;AAEA,EAAAD,EAAS;AACX;"}
1
+ {"version":3,"file":"humn.js","sources":["../src/observer.js","../src/cortex.js","../src/css.js","../src/h.js","../src/lifecycle.js","../src/patch.js","../src/mount.js","../src/persist.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null // For Cortex/State dependency\nlet currentInstance = null // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs\n}\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst\n}\n","import { getObserver } from './observer.js'\nimport { isDev } from './metrics.js'\n\n/**\n * @typedef {object} Synapses\n * @property {function} set - Function to update the memory\n * @property {function} get - Function to get the memory\n */\n\n/**\n * @typedef {object} CortexParams\n * @property {object} memory - The initial state\n * @property {function(function, function): object} synapses - The synapses function\n */\n\n/**\n * The Cortex class manages the state of the application.\n * This uses a Proxy for fine-grained reactivity, ensuring only those components\n * which use the updated value get re-rendered.\n *\n * WHY: We use Proxies instead of simple getters/setters because it allows us to\n * detect access to nested properties dynamically without needing to declare\n * dependencies upfront. This \"magic\" auto-subscription is what makes Humn's\n * DX so clean.\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexParams} CortexParams - The parameters for the Cortex.\n */\n constructor({ memory, synapses }) {\n const liveMemory = { ...memory }\n this._persistenceMap = new Map()\n\n // Load in any existing values from local-storage\n for (const [key, value] of Object.entries(memory)) {\n if (value && value.__humn_persist) {\n const storageKey = value.config.key || key\n this._persistenceMap.set(key, storageKey)\n\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored !== null) {\n liveMemory[key] = JSON.parse(stored)\n } else {\n liveMemory[key] = value.initial\n }\n } catch (err) {\n if (isDev)\n console.warn(`Humn: Failed to load '${key}' from storage.`, err)\n liveMemory[key] = value.initial\n }\n }\n }\n\n this._memory = liveMemory\n this._listeners = new Map()\n\n const get = () => this._memory\n\n const set = (updater) => {\n let nextState\n let changedPaths = new Set()\n\n if (typeof updater === 'function') {\n const clone = structuredClone(this._memory)\n const proxy = this._createChangeTrackingProxy(clone, changedPaths)\n const result = updater(proxy)\n\n if (result && typeof result === 'object') {\n nextState = { ...this._memory, ...result }\n Object.keys(result).forEach((key) => changedPaths.add(key))\n } else {\n nextState = clone\n }\n } else {\n nextState = { ...this._memory, ...updater }\n changedPaths = new Set(Object.keys(updater))\n }\n\n this._memory = nextState\n\n // If we need to persist any of the values\n // we save them to localStorage here\n if (this._persistenceMap.size > 0) {\n this._persistenceMap.forEach((storageKey, stateKey) => {\n const isDirty = Array.from(changedPaths).some(\n (path) => path === stateKey || path.startsWith(stateKey + '.'),\n )\n\n if (isDirty) {\n try {\n const value = this._memory[stateKey]\n localStorage.setItem(storageKey, JSON.stringify(value))\n } catch (err) {\n if (isDev)\n console.error(`Humn: Failed to save '${stateKey}'.`, err)\n }\n }\n })\n }\n\n this._notifyRelevantListeners(changedPaths)\n }\n\n this.synapses = synapses(set, get)\n }\n\n /**\n * Creates a Proxy that tracks which properties are being mutated.\n * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.\n *\n * WHY: We need to know exactly which paths were changed so we can notify ONLY\n * the components that care about those specific paths. If we just knew \"something changed\",\n * we'd have to re-render the whole app (like Redux) or rely on manual optimization.\n */\n _createChangeTrackingProxy(obj, changedPaths, path = '') {\n return new Proxy(obj, {\n get: (target, prop) => {\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const value = target[prop]\n const fullPath = path ? `${path}.${prop}` : prop\n\n // Recursively proxy nested objects so we can trap their sets too\n if (typeof value === 'object' && value !== null) {\n return this._createChangeTrackingProxy(value, changedPaths, fullPath)\n }\n return value\n },\n set: (target, prop, value) => {\n if (typeof prop === 'symbol' || prop === '__proto__') {\n target[prop] = value\n return true\n }\n\n const fullPath = path ? `${path}.${prop}` : prop\n changedPaths.add(fullPath)\n\n target[prop] = value\n return true\n },\n })\n }\n\n /**\n * Only notify listeners that read properties which changed\n */\n _notifyRelevantListeners(changedPaths) {\n this._listeners.forEach((accessedPaths, renderFn) => {\n const shouldNotify = Array.from(accessedPaths).some((accessedPath) => {\n return Array.from(changedPaths).some((changedPath) => {\n // Check for exact match or parent/child relationship\n return (\n accessedPath === changedPath ||\n accessedPath.startsWith(changedPath + '.') ||\n changedPath.startsWith(accessedPath + '.')\n )\n })\n })\n\n if (shouldNotify) renderFn()\n })\n }\n\n /**\n * Creates a Proxy that tracks which properties are accessed during render\n *\n * WHY: This is the other half of the magic. By tracking what a component READS\n * during its render, we build a precise dependency graph. If a component reads\n * `state.user.name`, it will only re-render when `state.user.name` changes,\n * not when `state.count` changes.\n */\n _createAccessTrackingProxy(obj, accessedPaths, path = '') {\n if (typeof obj !== 'object' || obj === null) return obj\n\n return new Proxy(obj, {\n get: (target, prop) => {\n // We don't care about prototype and symbol properties\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const fullPath = path ? `${path}.${prop}` : prop\n accessedPaths.add(fullPath)\n\n const value = target[prop]\n\n // Recursively wrap nested objects\n if (typeof value === 'object' && value !== null)\n return this._createAccessTrackingProxy(value, accessedPaths, fullPath)\n\n return value\n },\n })\n }\n\n /**\n * Returns memory wrapped in a tracking Proxy\n */\n get memory() {\n const currentObserver = getObserver()\n\n if (!currentObserver) return this._memory\n\n if (!this._listeners.has(currentObserver))\n this._listeners.set(currentObserver, new Set())\n\n const accessedPaths = this._listeners.get(currentObserver)\n\n // This gives us fresh tracking each render\n accessedPaths.clear()\n\n return this._createAccessTrackingProxy(this._memory, accessedPaths)\n }\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null\nconst cache = new Set()\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381\n let i = str.length\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i)\n }\n return (hash >>> 0).toString(36)\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse newlines/tabs to single space\n .trim() // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n * Supports two signatures:\n * 1. Tagged Template: css`...`\n * 2. Function: css(string, isSingleRoot)\n */\nexport function css(stringsOrStr, ...args) {\n let raw = ''\n let isSingleRoot = false\n\n // Detect usage of Tagged Template vs Function Call\n if (Array.isArray(stringsOrStr) && stringsOrStr.raw) {\n raw = stringsOrStr.reduce((acc, str, i) => {\n return acc + str + (args[i] || '')\n }, '')\n } else {\n raw = stringsOrStr\n // If called as function, the first arg is our boolean flag\n isSingleRoot = args[0] === true\n }\n let content = minify(raw)\n\n if (!content) return ''\n\n if (isSingleRoot) {\n // Transforms selectors to apply to BOTH the root (using &) AND descendants.\n // e.g. \"div\" -> \"div&, div\"\n\n // Regex Breakdown:\n // 1. (^|[{};,]) -> Hard Start (Line start, brace, semi, comma)\n // 2. (\\s*) -> Whitespace\n // 3. (?!from|to) -> Negative Lookahead: Ignore 'from'/'to' (keyframes)\n // 4. ( ... )+ -> Compound Selector:\n // (?:[.#]?[\\w-]+ ... ) -> Matches tags (div), classes (.class), ids (#id)\n // 5. (?=\\s*\\{) -> Lookahead: Must be followed by {\n\n content = content.replace(\n /(^|[{};,])(\\s*)(?!from|to)((?:[.#]?[\\w-]+|\\[[^\\]]+\\]|:{1,2}[^:,{\\s]+)+)(?=\\s*\\{)/gi,\n '$1$2$3&, $3',\n )\n }\n\n const hash = hashString(content)\n const hashedClassName = `humn-${hash}`\n\n if (cache.has(hash)) {\n return hashedClassName\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement('style')\n styleSheet.id = 'humn-styles'\n document.head.appendChild(styleSheet)\n }\n\n styleSheet.textContent += `.${hashedClassName} { \n ${content} \n }\\n`\n cache.add(hash)\n\n return hashedClassName\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children]\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat()\n .filter((c) => c !== null && c !== undefined && c !== false && c !== '')\n\n return {\n tag,\n props,\n children: cleanChildren,\n }\n}\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from './observer.js'\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance()\n if (instance) {\n instance.mounts.push(fn)\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance()\n if (instance) {\n instance.cleanups.push(fn)\n }\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { track } from './metrics.js'\nimport { setInstance } from './observer.js'\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h.js\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null)\n}\n\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode - The virtual node.\n * @returns {Text | HTMLElement} The created DOM element.\n */\nfunction createElement(vNode) {\n if (typeof vNode === 'string' || typeof vNode === 'number') {\n return document.createTextNode(String(vNode))\n }\n\n if (typeof vNode.tag === 'function') {\n const childVNode = renderComponent(vNode)\n vNode.child = childVNode\n\n // Recursively create the DOM for the child\n const el = createElement(childVNode)\n vNode.el = el\n\n // Queue Mount Hooks\n if (vNode.hooks && vNode.hooks.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const el = document.createElement(vNode.tag)\n vNode.el = el\n patchProps(el, vNode.props)\n\n vNode.children.forEach((child) => {\n el.appendChild(createElement(child))\n })\n\n return el\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} el - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n *\n * WHY: We check against the LIVE DOM value for inputs (value/checked) to prevent\n * the \"cursor jumping\" bug. If we just blindly set the attribute, the browser\n * might reset the cursor position to the end of the input.\n */\nfunction patchProps(el, newProps = {}, oldProps = {}) {\n if (!el) return\n\n const allProps = { ...oldProps, ...newProps }\n\n for (const key in allProps) {\n const oldValue = oldProps[key]\n const newValue = newProps[key]\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n el.removeAttribute(key)\n track('patches')\n continue\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === 'value' || key === 'checked') {\n if (el[key] !== newValue) {\n el[key] = newValue\n track('patches')\n }\n continue\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue\n\n track('patches')\n\n // Handle Events\n if (key.startsWith('on')) {\n const eventName = key.slice(2).toLowerCase()\n if (oldValue) el.removeEventListener(eventName, oldValue)\n el.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n el.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n el.setAttribute(key, newValue)\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h.js\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h.js\").VNode>} oldChildren - The old list of children.\n *\n * WHY: This is the most complex part of the VDOM. We need to efficiently update\n * a list of items. Without keys, we just update index-by-index, which is fast\n * but causes issues if items are reordered (state gets mixed up).\n * With keys, we can track items as they move around, preserving their state\n * and minimizing DOM operations.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren)\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length)\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i)\n }\n return\n }\n\n reconcileKeyedChildren(parent, newChildren, oldChildren)\n}\n\n/**\n * Handles the complex logic of reconciling keyed children.\n *\n * WHY: When keys are present, we can't just iterate by index. We need to map\n * existing children by their key so we can find them even if they've moved.\n * This allows us to re-use DOM nodes (preserving focus/state) instead of\n * destroying and re-creating them.\n */\nfunction reconcileKeyedChildren(parent, newChildren, oldChildren) {\n // Map existing children by Key for O(1) lookup\n const keyed = {}\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i\n keyed[key] = { vNode: child, index: i }\n })\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i\n const existingChildMatch = keyed[key]\n\n if (existingChildMatch) {\n // A. MATCH FOUND - The item existed before\n const oldVNode = existingChildMatch.vNode\n\n // Update the node's content recursively\n patch(parent, newChild, oldVNode, i)\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const el = newChild.el || oldVNode.el\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i]\n\n // If the element exists but is in the wrong place, move it\n if (el && domChildAtIndex !== el) {\n parent.insertBefore(el, domChildAtIndex)\n track('patches')\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key]\n } else {\n // B. NO MATCH - This is a new item\n const newEl = createElement(newChild)\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newEl, domChildAtIndex)\n } else {\n parent.appendChild(newEl)\n }\n }\n })\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n runUnmount(vNode) // Clean up hooks\n parent.removeChild(vNode.el)\n track('elementsRemoved')\n }\n })\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h.js\").VNode} vNode - The component vNode.\n * @returns {import(\"./h.js\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n track('componentsRendered')\n\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n }\n\n // 2. Set Global Scope\n setInstance(hooks)\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props)\n\n // 4. Clear Global Scope\n setInstance(null)\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks\n\n return renderedVNode\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h.js\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn())\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child)\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount)\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h.js\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h.js\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n track('diffs')\n\n // Case 1: Removal - The new node is null/undefined, so we remove the old one.\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index]\n\n // Recursive Cleanup\n runUnmount(oldVNode)\n\n if (el) {\n parent.removeChild(el)\n track('elementsRemoved')\n }\n return\n }\n\n // Case 2: Component - If it's a function, we delegate to the component logic.\n if (typeof newVNode.tag === 'function') {\n const isNew = !oldVNode\n\n const childVNode = renderComponent(newVNode)\n newVNode.child = childVNode\n\n const oldChild = oldVNode ? oldVNode.child : undefined\n patch(parent, childVNode, oldChild, index)\n\n newVNode.el = childVNode.el\n\n // Run mount hooks on the next tick\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn())\n }, 0)\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return\n }\n\n // Case 3: Creation - No old node exists, so we create a new one.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode))\n return\n }\n\n // Case 4: Replacement - The node type changed (e.g. div -> span), so we replace it entirely.\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== 'string' && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index]\n if (el) {\n parent.replaceChild(createElement(newVNode), el)\n track('patches')\n }\n return\n }\n\n // Case 5: Text Update - It's a text node, so we just update the text content.\n if (typeof newVNode === 'string' || typeof newVNode === 'number') {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index]\n if (el) {\n el.nodeValue = String(newVNode)\n track('patches')\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)))\n }\n }\n return\n }\n\n // Case 6: Update - Same tag, so we update props and recurse into children.\n const el = oldVNode.el || parent.childNodes[index]\n\n if (!el) return\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el\n\n patchProps(el, newVNode.props, oldVNode.props)\n\n reconcileChildren(el, newVNode.children, oldVNode.children)\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from './observer.js'\nimport { patch } from './patch.js'\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null\n\n const lifecycle = () => {\n setObserver(lifecycle)\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n }\n\n patch(target, nextVNode, prevVNode)\n setObserver(null)\n prevVNode = nextVNode\n }\n\n lifecycle()\n}\n","/**\n * @typedef {object} HumnPersist\n * @property {boolean} __humn_persist\n * @property {any} initial\n * @property {PersistConfig} config\n */\n\n/**\n * @typedef {object} PersistConfig\n * @property {string} key\n */\n\n/**\n * Marks a section of the state for persistence in localStorage.\n *\n * @param {any} initial - The initial value of the state.\n * @param {PersistConfig} config - The configuration for persistence.\n * @returns {HumnPersist}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","liveMemory","this","_persistenceMap","Map","key","value","Object","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","err","_memory","_listeners","updater","nextState","changedPaths","Set","clone","structuredClone","result","_createChangeTrackingProxy","keys","forEach","add","size","stateKey","Array","from","some","path","startsWith","setItem","stringify","_notifyRelevantListeners","obj","Proxy","get","target","prop","fullPath","accessedPaths","renderFn","accessedPath","changedPath","_createAccessTrackingProxy","has","clear","styleSheet","cache","css","stringsOrStr","args","raw","isSingleRoot","isArray","reduce","acc","str","i","content","replace","trim","hash","length","charCodeAt","toString","hashedClassName","document","createElement","id","head","appendChild","textContent","h","tag","props","children","flat","filter","c","onMount","fn","instance","mounts","push","onCleanup","cleanups","hasKeys","vNode","createTextNode","String","childVNode","renderComponent","child","el","hooks","setTimeout","patchProps","newProps","oldProps","allProps","oldValue","newValue","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","parent","newChildren","oldChildren","maxLen","Math","max","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newEl","values","parentNode","runUnmount","removeChild","renderedVNode","newVNode","isNew","replaceChild","nodeValue","mount","Component","prevVNode","lifecycle","nextVNode","persist"],"mappings":"AAKA,IAAIA,IAAkB,MAClBC,IAAkB;AAMf,MAAMC,IAAc,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CAAAA;AACzB1B,MAAAA,IACFA,EAAG0C,YAAY9C,OAAO2C,CAAAA,IAItBrB,EAAOzC,YAAYJ,SAASsB,eAAeC,OAAO2C,CAAAA,CAAAA,CAAAA;AAAAA,IAEtD;AACA;AAAA,EACF;AAGA,QAAMvC,IAAK6B,EAAS7B,MAAMkB,EAAOa,WAAWL,CAAAA;AAEvC1B,EAAAA,MAGLuC,EAASvC,KAAKA,GAEdG,EAAWH,GAAIuC,EAAS1D,OAAOgD,EAAShD,QAExCoC,EAAkBjB,GAAIuC,EAASzD,UAAU+C,EAAS/C,QAAAA;AACpD;AClVY,MAAC6D,IAAQ,CAACpG,GAAQqG,MAAAA;AAC5B,MAAIC,IAAY;AAEhB,QAAMC,IAAY;AAChB5J,IAAAA,EAAY4J,CAAAA;AAEZ,UAAMC,IAAY,EAChBnE,KAAKgE,GACL/D,OAAO,CAAA,GACPC,UAAU,CAAA,EAAA;AAGZ0C,IAAAA,EAAMjF,GAAQwG,GAAWF,CAAAA,GACzB3J,EAAY,OACZ2J,IAAYE;AAAAA,EAAAA;AAGdD,EAAAA,EAAAA;AAAAA,GCVWE,IAAU,CAACrI,GAASP,IAAS,QAAE,EAC1CF,gBAAAA,IACAS,SAAAA,GACAP;"}
package/dist/humn.umd.js CHANGED
@@ -1,5 +1,5 @@
1
- (function(u,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u.Humn={}))})(this,(function(u){"use strict";let f=null,k=null;const I=()=>f,d=t=>{f=t},E=()=>k,b=t=>{k=t};class O{constructor({memory:e,synapses:s}){this._memory=e,this._listeners=new Set;const r=()=>this._memory,c=n=>{let i;if(typeof n=="function"){const o=structuredClone(this._memory);i=n(o)||o}else i={...this._memory,...n};this._memory=i,this._listeners.forEach(o=>o())};this.synapses=s(c,r)}get memory(){const e=I();return e&&this._listeners.add(e),this._memory}}let a=null;const C=new Set;function x(t){let e=5381,s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return(e>>>0).toString(36)}function L(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim()}function M(t,...e){const s=t.reduce((i,o,l)=>i+o+(e[l]||""),""),r=L(s);if(!r)return"";const c=x(r),n=`humn-${c}`;return C.has(c)||(a||(a=document.createElement("style"),a.id="humn-styles",document.head.appendChild(a)),a.textContent+=`.${n} {
2
- ${r}
1
+ (function(a,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):h((a=typeof globalThis<"u"?globalThis:a||self).Humn={})})(this,function(a){"use strict";let h=null,_=null;const T=()=>h,k=t=>{h=t},b=()=>_,v=t=>{_=t};let p=null;const x=new Set;function C(t){return t&&t.some(e=>e&&e.props&&e.props.key!=null)}function d(t){if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.tag=="function"){const n=S(t);t.child=n;const s=d(n);return t.el=s,t.hooks&&t.hooks.mounts.length>0&&setTimeout(()=>t.hooks.mounts.forEach(o=>o()),0),s}const e=document.createElement(t.tag);return t.el=e,E(e,t.props),t.children.forEach(n=>{e.appendChild(d(n))}),e}function E(t,e={},n={}){if(!t)return;const s={...n,...e};for(const o in s){const r=n[o],i=e[o];if(i!=null)if(o!=="value"&&o!=="checked"){if(r!==i){if(o.startsWith("on")){const c=o.slice(2).toLowerCase();r&&t.removeEventListener(c,r),t.addEventListener(c,i)}o==="disabled"?t.disabled=i===!0||i==="true":t.setAttribute(o,i)}}else t[o]!==i&&(t[o]=i);else t.removeAttribute(o)}}function $(t,e,n){if(!(C(e)||C(n))){const s=Math.max(e.length,n.length);for(let o=0;o<s;o++)g(t,e[o],n[o],o);return}(function(s,o,r){const i={};r.forEach((c,l)=>{const u=(c.props&&c.props.key)!=null?c.props.key:l;i[u]={vNode:c,index:l}}),o.forEach((c,l)=>{const u=(c.props&&c.props.key)!=null?c.props.key:l,N=i[u];if(N){const y=N.vNode;g(s,c,y,l);const f=c.el||y.el,A=s.childNodes[l];f&&A!==f&&s.insertBefore(f,A),delete i[u]}else{const y=d(c),f=s.childNodes[l];f?s.insertBefore(y,f):s.appendChild(y)}}),Object.values(i).forEach(({vNode:c})=>{c.el&&c.el.parentNode===s&&(m(c),s.removeChild(c.el))})})(t,e,n)}function S(t){const e={mounts:[],cleanups:[]};v(e);const n=t.tag(t.props);return v(null),t.hooks=e,n}function m(t){t&&(t.hooks&&t.hooks.cleanups&&t.hooks.cleanups.forEach(e=>e()),t.child&&m(t.child),t.children&&t.children.forEach(m))}function g(t,e,n,s=0){if(e==null){const r=n.el||t.childNodes[s];return m(n),void(r&&t.removeChild(r))}if(typeof e.tag=="function"){const r=!n,i=S(e);return e.child=i,g(t,i,n?n.child:void 0,s),e.el=i.el,void(r&&e.hooks&&e.hooks.mounts.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(c=>c())},0))}if(n==null)return void t.appendChild(d(e));if(typeof e!=typeof n||typeof e!="string"&&e.tag!==n.tag){const r=n.el||t.childNodes[s];return void(r&&t.replaceChild(d(e),r))}if(typeof e=="string"||typeof e=="number"){if(e!==n){const r=t.childNodes[s];r?r.nodeValue=String(e):t.appendChild(document.createTextNode(String(e)))}return}const o=n.el||t.childNodes[s];o&&(e.el=o,E(o,e.props,n.props),$(o,e.children,n.children))}a.Cortex=class{constructor({memory:t,synapses:e}){const n={...t};this._persistenceMap=new Map;for(const[s,o]of Object.entries(t))if(o&&o.__humn_persist){const r=o.config.key||s;this._persistenceMap.set(s,r);try{const i=localStorage.getItem(r);n[s]=i!==null?JSON.parse(i):o.initial}catch{n[s]=o.initial}}this._memory=n,this._listeners=new Map,this.synapses=e(s=>{let o,r=new Set;if(typeof s=="function"){const i=structuredClone(this._memory),c=s(this._createChangeTrackingProxy(i,r));c&&typeof c=="object"?(o={...this._memory,...c},Object.keys(c).forEach(l=>r.add(l))):o=i}else o={...this._memory,...s},r=new Set(Object.keys(s));this._memory=o,this._persistenceMap.size>0&&this._persistenceMap.forEach((i,c)=>{if(Array.from(r).some(l=>l===c||l.startsWith(c+".")))try{const l=this._memory[c];localStorage.setItem(i,JSON.stringify(l))}catch{}}),this._notifyRelevantListeners(r)},()=>this._memory)}_createChangeTrackingProxy(t,e,n=""){return new Proxy(t,{get:(s,o)=>{if(typeof o=="symbol"||o==="__proto__")return s[o];const r=s[o],i=n?`${n}.${o}`:o;return typeof r=="object"&&r!==null?this._createChangeTrackingProxy(r,e,i):r},set:(s,o,r)=>{if(typeof o=="symbol"||o==="__proto__")return s[o]=r,!0;const i=n?`${n}.${o}`:o;return e.add(i),s[o]=r,!0}})}_notifyRelevantListeners(t){this._listeners.forEach((e,n)=>{Array.from(e).some(s=>Array.from(t).some(o=>s===o||s.startsWith(o+".")||o.startsWith(s+".")))&&n()})}_createAccessTrackingProxy(t,e,n=""){return typeof t!="object"||t===null?t:new Proxy(t,{get:(s,o)=>{if(typeof o=="symbol"||o==="__proto__")return s[o];const r=n?`${n}.${o}`:o;e.add(r);const i=s[o];return typeof i=="object"&&i!==null?this._createAccessTrackingProxy(i,e,r):i}})}get memory(){const t=T();if(!t)return this._memory;this._listeners.has(t)||this._listeners.set(t,new Set);const e=this._listeners.get(t);return e.clear(),this._createAccessTrackingProxy(this._memory,e)}},a.css=function(t,...e){let n="",s=!1;Array.isArray(t)&&t.raw?n=t.reduce((c,l,u)=>c+l+(e[u]||""),""):(n=t,s=e[0]===!0);let o=(function(c){return c.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim()})(n);if(!o)return"";s&&(o=o.replace(/(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi,"$1$2$3&, $3"));const r=(function(c){let l=5381,u=c.length;for(;u;)l=33*l^c.charCodeAt(--u);return(l>>>0).toString(36)})(o),i=`humn-${r}`;return x.has(r)||(p||(p=document.createElement("style"),p.id="humn-styles",document.head.appendChild(p)),p.textContent+=`.${i} {
2
+ ${o}
3
3
  }
4
- `,C.add(c)),n}const j=(t,e={},s=[])=>{const c=(Array.isArray(s)?s:[s]).flat().filter(n=>n!=null&&n!==!1&&n!=="");return{tag:t,props:e,children:c}};function K(t){const e=E();e&&e.mounts.push(t)}function $(t){const e=E();e&&e.cleanups.push(t)}function S(t){return t&&t.some(e=>e&&e.props&&e.props.key!=null)}function m(t){if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.tag=="function"){const s=_(t);t.child=s;const r=m(s);return t.el=r,t.hooks&&t.hooks.mounts.length>0&&setTimeout(()=>t.hooks.mounts.forEach(c=>c()),0),r}const e=document.createElement(t.tag);return t.el=e,A(e,t.props),t.children.forEach(s=>{e.appendChild(m(s))}),e}function A(t,e={},s={}){if(!t)return;const r={...s,...e};for(const c in r){const n=s[c],i=e[c];if(i==null){t.removeAttribute(c);continue}if(c==="value"||c==="checked"){t[c]!==i&&(t[c]=i);continue}if(n!==i){if(c.startsWith("on")){const o=c.slice(2).toLowerCase();n&&t.removeEventListener(o,n),t.addEventListener(o,i)}c==="disabled"?t.disabled=i===!0||i==="true":t.setAttribute(c,i)}}}function B(t,e,s){if(!(S(e)||S(s))){const n=Math.max(e.length,s.length);for(let i=0;i<n;i++)y(t,e[i],s[i],i);return}const c={};s.forEach((n,i)=>{const o=(n.props&&n.props.key)!=null?n.props.key:i;c[o]={vNode:n,index:i}}),e.forEach((n,i)=>{const o=(n.props&&n.props.key)!=null?n.props.key:i,l=c[o];if(l){const p=l.vNode;y(t,n,p,i);const h=n.el||p.el,T=t.childNodes[i];h&&T!==h&&t.insertBefore(h,T),delete c[o]}else{const p=m(n),h=t.childNodes[i];h?t.insertBefore(p,h):t.appendChild(p)}}),Object.values(c).forEach(({vNode:n})=>{n.el&&n.el.parentNode===t&&t.removeChild(n.el)})}function _(t){const e={mounts:[],cleanups:[]};b(e);const s=t.tag(t.props);return b(null),t.hooks=e,s}function g(t){t&&(t.hooks&&t.hooks.cleanups&&t.hooks.cleanups.forEach(e=>e()),t.child&&g(t.child),t.children&&t.children.forEach(g))}function y(t,e,s,r=0){if(e==null){const n=s.el||t.childNodes[r];g(s),n&&t.removeChild(n);return}if(typeof e.tag=="function"){const n=!s,i=_(e);e.child=i;const o=s?s.child:void 0;y(t,i,o,r),e.el=i.el,n&&e.hooks&&e.hooks.mounts.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(l=>l())},0);return}if(s==null){t.appendChild(m(e));return}if(e==null){const n=s.el||t.childNodes[r];n&&t.removeChild(n);return}if(typeof e!=typeof s||typeof e!="string"&&e.tag!==s.tag){const n=s.el||t.childNodes[r];n&&t.replaceChild(m(e),n);return}if(typeof e=="string"||typeof e=="number"){if(e!==s){const n=t.childNodes[r];n?n.nodeValue=String(e):t.appendChild(document.createTextNode(String(e)))}return}const c=s.el||t.childNodes[r];c&&(e.el=c,A(c,e.props,s.props),B(c,e.children,s.children))}const H=(t,e)=>{let s=null;const r=()=>{d(r);const c={tag:e,props:{},children:[]};y(t,c,s),d(null),s=c};r()};u.Cortex=O,u.css=M,u.h=j,u.mount=H,u.onCleanup=$,u.onMount=K,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
4
+ `,x.add(r)),i},a.h=(t,e={},n=[])=>({tag:t,props:e,children:(Array.isArray(n)?n:[n]).flat().filter(s=>s!=null&&s!==!1&&s!=="")}),a.mount=(t,e)=>{let n=null;const s=()=>{k(s);const o={tag:e,props:{},children:[]};g(t,o,n),k(null),n=o};s()},a.onCleanup=function(t){const e=b();e&&e.cleanups.push(t)},a.onMount=function(t){const e=b();e&&e.mounts.push(t)},a.persist=(t,e={})=>({__humn_persist:!0,initial:t,config:e}),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
5
5
  //# sourceMappingURL=humn.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"humn.umd.js","sources":["../src/observer.js","../src/cortex.js","../src/css.js","../src/h.js","../src/lifecycle.js","../src/patch.js","../src/mount.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null; // For Cortex/State dependency\nlet currentInstance = null; // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver;\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs;\n};\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance;\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst;\n};\n","import { getObserver } from \"./observer.js\";\n\n/**\n * @typedef {object} Synapses\n * @property {function} set - Function to update the memory\n * @property {function} get - Function to get the memory\n */\n\n/**\n * @typedef {object} CortexParams\n * @property {object} memory - The initial state\n * @property {function(function, function): object} synapses - The synapses function\n */\n\n/**\n * The Cortex class manages the state of the application.\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexParams} CortexParams - The parameters for the Cortex.\n */\n constructor({ memory, synapses }) {\n this._memory = memory;\n this._listeners = new Set();\n\n const get = () => this._memory;\n\n const set = (updater) => {\n let nextState;\n if (typeof updater === \"function\") {\n const clone = structuredClone(this._memory);\n const result = updater(clone);\n nextState = result || clone;\n } else {\n nextState = { ...this._memory, ...updater };\n }\n\n this._memory = nextState;\n this._listeners.forEach((render) => render());\n };\n\n this.synapses = synapses(set, get);\n }\n\n /**\n * Get the memory and register the current observer.\n * @returns {object} The current state\n */\n get memory() {\n const currentObserver = getObserver();\n if (currentObserver) this._listeners.add(currentObserver);\n return this._memory;\n }\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null;\nconst cache = new Set();\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381;\n let i = str.length;\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i);\n }\n return (hash >>> 0).toString(36);\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\") // Remove comments\n .replace(/\\s+/g, \" \") // Collapse newlines/tabs to single space\n .trim(); // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n */\nexport function css(strings, ...args) {\n const raw = strings.reduce((acc, str, i) => {\n return acc + str + (args[i] || \"\");\n }, \"\");\n\n const content = minify(raw);\n\n if (!content) return \"\";\n\n const hash = hashString(content);\n const className = `humn-${hash}`;\n\n if (cache.has(hash)) {\n return className;\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement(\"style\");\n styleSheet.id = \"humn-styles\";\n document.head.appendChild(styleSheet);\n }\n\n styleSheet.textContent += `.${className} { \n ${content} \n }\\n`;\n cache.add(hash);\n\n return className;\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children];\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat() \n .filter(c => c !== null && c !== undefined && c !== false && c !== '');\n\n return {\n tag,\n props,\n children: cleanChildren\n };\n};\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from \"./observer.js\";\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance();\n if (instance) {\n instance.mounts.push(fn);\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance();\n if (instance) {\n instance.cleanups.push(fn);\n }\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { setInstance } from \"./observer.js\";\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null);\n}\n\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h\").VNode | string | number} vNode - The virtual node.\n * @returns {Text | HTMLElement} The created DOM element.\n */\nfunction createElement(vNode) {\n if (typeof vNode === \"string\" || typeof vNode === \"number\") {\n return document.createTextNode(String(vNode));\n }\n\n if (typeof vNode.tag === \"function\") {\n const childVNode = renderComponent(vNode);\n vNode.child = childVNode;\n\n // Recursively create the DOM for the child\n const el = createElement(childVNode);\n vNode.el = el;\n\n // Queue Mount Hooks\n if (vNode.hooks && vNode.hooks.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0);\n }\n return el;\n }\n\n const el = document.createElement(vNode.tag);\n vNode.el = el;\n patchProps(el, vNode.props);\n\n vNode.children.forEach((child) => {\n el.appendChild(createElement(child));\n });\n\n return el;\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} el - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n */\nfunction patchProps(el, newProps = {}, oldProps = {}) {\n if (!el) return;\n\n const allProps = { ...oldProps, ...newProps };\n\n for (const key in allProps) {\n const oldValue = oldProps[key];\n const newValue = newProps[key];\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n el.removeAttribute(key);\n continue;\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === \"value\" || key === \"checked\") {\n if (el[key] !== newValue) {\n el[key] = newValue;\n }\n continue;\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue;\n\n // Handle Events\n if (key.startsWith(\"on\")) {\n const eventName = key.slice(2).toLowerCase();\n if (oldValue) el.removeEventListener(eventName, oldValue);\n el.addEventListener(eventName, newValue);\n }\n // Handle the disabled attribute\n if (key === \"disabled\") {\n el.disabled = newValue === true || newValue === \"true\";\n }\n // Handle standard attributes\n else {\n el.setAttribute(key, newValue);\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h\").VNode>} oldChildren - The old list of children.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren);\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length);\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i);\n }\n return;\n }\n\n // Keyed Diffing\n // Map existing children by Key\n const keyed = {};\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i;\n keyed[key] = { vNode: child, index: i };\n });\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i;\n const oldItem = keyed[key];\n\n if (oldItem) {\n // A. MATCH FOUND\n const oldVNode = oldItem.vNode;\n\n // Update the node's content (Recursion)\n patch(parent, newChild, oldVNode, i);\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const el = newChild.el || oldVNode.el;\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i];\n\n // If the element exists but is in the wrong place, move it\n if (el && domChildAtIndex !== el) {\n parent.insertBefore(el, domChildAtIndex);\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key];\n } else {\n // B. NO MATCH (New Item)\n const newEl = createElement(newChild);\n const domChildAtIndex = parent.childNodes[i];\n\n if (domChildAtIndex) {\n parent.insertBefore(newEl, domChildAtIndex);\n } else {\n parent.appendChild(newEl);\n }\n }\n });\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n parent.removeChild(vNode.el);\n }\n });\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h\").VNode} vNode - The component vNode.\n * @returns {import(\"./h\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n };\n\n // 2. Set Global Scope\n setInstance(hooks);\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props);\n\n // 4. Clear Global Scope\n setInstance(null);\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks;\n\n return renderedVNode;\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return;\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn());\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child);\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount);\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n // --- HANDLE UNMOUNTING (Cleanup Hooks) ---\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index];\n\n // Recursive Cleanup\n runUnmount(oldVNode);\n\n if (el) parent.removeChild(el);\n return;\n }\n\n // --- HANDLE COMPONENT (Functional VNode) ---\n if (typeof newVNode.tag === \"function\") {\n const isNew = !oldVNode;\n\n // 1. Render the component function\n const childVNode = renderComponent(newVNode);\n\n // 2. Store the result in the vNode (\"unwrap\" it)\n newVNode.child = childVNode;\n\n // 3. Recursively patch the result\n const oldChild = oldVNode ? oldVNode.child : undefined;\n patch(parent, childVNode, oldChild, index);\n\n // 4. Ensure VNode holds the DOM reference\n newVNode.el = childVNode.el;\n\n // 5. Run Mount Hooks (Next Tick)\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn());\n }, 0);\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return;\n }\n\n // Start - No old node? Create new.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode));\n return;\n }\n\n // Removal - No new node? Remove old.\n if (newVNode === undefined || newVNode === null) {\n // Try to find the element on the VNode, or fallback to index\n const el = oldVNode.el || parent.childNodes[index];\n if (el) parent.removeChild(el);\n return;\n }\n\n // Changed Type - (e.g. <div> becomes <span>) -> Replace whole node\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== \"string\" && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index];\n if (el) parent.replaceChild(createElement(newVNode), el);\n return;\n }\n\n // Text Update\n if (typeof newVNode === \"string\" || typeof newVNode === \"number\") {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index];\n if (el) {\n el.nodeValue = String(newVNode);\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)));\n }\n }\n return;\n }\n\n // Same Tag - Update Props & Children\n const el = oldVNode.el || parent.childNodes[index];\n\n if (!el) return;\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el;\n\n patchProps(el, newVNode.props, oldVNode.props);\n\n reconcileChildren(el, newVNode.children, oldVNode.children);\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from \"./observer.js\";\nimport { patch } from \"./patch.js\";\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null;\n\n const lifecycle = () => {\n setObserver(lifecycle);\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n };\n\n patch(target, nextVNode, prevVNode);\n setObserver(null);\n prevVNode = nextVNode;\n };\n\n lifecycle();\n};\n"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","get","set","updater","nextState","clone","render","styleSheet","cache","hashString","str","hash","i","minify","css","strings","args","raw","acc","content","className","h","tag","props","children","cleanChildren","c","onMount","fn","instance","onCleanup","hasKeys","createElement","vNode","childVNode","renderComponent","el","patchProps","child","newProps","oldProps","allProps","key","oldValue","newValue","eventName","reconcileChildren","parent","newChildren","oldChildren","maxLen","patch","keyed","newChild","oldItem","oldVNode","domChildAtIndex","newEl","hooks","renderedVNode","runUnmount","newVNode","index","isNew","oldChild","mount","target","Component","prevVNode","lifecycle","nextVNode"],"mappings":"6NAKA,IAAIA,EAAkB,KAClBC,EAAkB,KAMf,MAAMC,EAAc,IAAMF,EAMpBG,EAAeC,GAAQ,CAClCJ,EAAkBI,CACpB,EAMaC,EAAc,IAAMJ,EAMpBK,EAAeC,GAAS,CACnCN,EAAkBM,CACpB,ECjBO,MAAMC,CAAO,CAKlB,YAAY,CAAE,OAAAC,EAAQ,SAAAC,GAAY,CAChC,KAAK,QAAUD,EACf,KAAK,WAAa,IAAI,IAEtB,MAAME,EAAM,IAAM,KAAK,QAEjBC,EAAOC,GAAY,CACvB,IAAIC,EACJ,GAAI,OAAOD,GAAY,WAAY,CACjC,MAAME,EAAQ,gBAAgB,KAAK,OAAO,EAE1CD,EADeD,EAAQE,CAAK,G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,MAAMC,EAAY,IAAM,CACtB5E,EAAY4E,CAAS,EAErB,MAAMC,EAAY,CAChB,IAAKH,EACL,MAAO,CAAA,EACP,SAAU,CAAA,CAChB,EAEIhB,EAAMe,EAAQI,EAAWF,CAAS,EAClC3E,EAAY,IAAI,EAChB2E,EAAYE,CACd,EAEAD,EAAS,CACX"}
1
+ {"version":3,"file":"humn.umd.js","sources":["../src/observer.js","../src/css.js","../src/patch.js","../src/persist.js","../src/cortex.js","../src/h.js","../src/mount.js","../src/lifecycle.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null // For Cortex/State dependency\nlet currentInstance = null // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs\n}\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null\nconst cache = new Set()\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381\n let i = str.length\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i)\n }\n return (hash >>> 0).toString(36)\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse newlines/tabs to single space\n .trim() // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n * Supports two signatures:\n * 1. Tagged Template: css`...`\n * 2. Function: css(string, isSingleRoot)\n */\nexport function css(stringsOrStr, ...args) {\n let raw = ''\n let isSingleRoot = false\n\n // Detect usage of Tagged Template vs Function Call\n if (Array.isArray(stringsOrStr) && stringsOrStr.raw) {\n raw = stringsOrStr.reduce((acc, str, i) => {\n return acc + str + (args[i] || '')\n }, '')\n } else {\n raw = stringsOrStr\n // If called as function, the first arg is our boolean flag\n isSingleRoot = args[0] === true\n }\n let content = minify(raw)\n\n if (!content) return ''\n\n if (isSingleRoot) {\n // Transforms selectors to apply to BOTH the root (using &) AND descendants.\n // e.g. \"div\" -> \"div&, div\"\n\n // Regex Breakdown:\n // 1. (^|[{};,]) -> Hard Start (Line start, brace, semi, comma)\n // 2. (\\s*) -> Whitespace\n // 3. (?!from|to) -> Negative Lookahead: Ignore 'from'/'to' (keyframes)\n // 4. ( ... )+ -> Compound Selector:\n // (?:[.#]?[\\w-]+ ... ) -> Matches tags (div), classes (.class), ids (#id)\n // 5. (?=\\s*\\{) -> Lookahead: Must be followed by {\n\n content = content.replace(\n /(^|[{};,])(\\s*)(?!from|to)((?:[.#]?[\\w-]+|\\[[^\\]]+\\]|:{1,2}[^:,{\\s]+)+)(?=\\s*\\{)/gi,\n '$1$2$3&, $3',\n )\n }\n\n const hash = hashString(content)\n const hashedClassName = `humn-${hash}`\n\n if (cache.has(hash)) {\n return hashedClassName\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement('style')\n styleSheet.id = 'humn-styles'\n document.head.appendChild(styleSheet)\n }\n\n styleSheet.textContent += `.${hashedClassName} { \n ${content} \n }\\n`\n cache.add(hash)\n\n return hashedClassName\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { track } from './metrics.js'\nimport { setInstance } from './observer.js'\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h.js\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null)\n}\n\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode - The virtual node.\n * @returns {Text | HTMLElement} The created DOM element.\n */\nfunction createElement(vNode) {\n if (typeof vNode === 'string' || typeof vNode === 'number') {\n return document.createTextNode(String(vNode))\n }\n\n if (typeof vNode.tag === 'function') {\n const childVNode = renderComponent(vNode)\n vNode.child = childVNode\n\n // Recursively create the DOM for the child\n const el = createElement(childVNode)\n vNode.el = el\n\n // Queue Mount Hooks\n if (vNode.hooks && vNode.hooks.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const el = document.createElement(vNode.tag)\n vNode.el = el\n patchProps(el, vNode.props)\n\n vNode.children.forEach((child) => {\n el.appendChild(createElement(child))\n })\n\n return el\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} el - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n *\n * WHY: We check against the LIVE DOM value for inputs (value/checked) to prevent\n * the \"cursor jumping\" bug. If we just blindly set the attribute, the browser\n * might reset the cursor position to the end of the input.\n */\nfunction patchProps(el, newProps = {}, oldProps = {}) {\n if (!el) return\n\n const allProps = { ...oldProps, ...newProps }\n\n for (const key in allProps) {\n const oldValue = oldProps[key]\n const newValue = newProps[key]\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n el.removeAttribute(key)\n track('patches')\n continue\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === 'value' || key === 'checked') {\n if (el[key] !== newValue) {\n el[key] = newValue\n track('patches')\n }\n continue\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue\n\n track('patches')\n\n // Handle Events\n if (key.startsWith('on')) {\n const eventName = key.slice(2).toLowerCase()\n if (oldValue) el.removeEventListener(eventName, oldValue)\n el.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n el.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n el.setAttribute(key, newValue)\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h.js\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h.js\").VNode>} oldChildren - The old list of children.\n *\n * WHY: This is the most complex part of the VDOM. We need to efficiently update\n * a list of items. Without keys, we just update index-by-index, which is fast\n * but causes issues if items are reordered (state gets mixed up).\n * With keys, we can track items as they move around, preserving their state\n * and minimizing DOM operations.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren)\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length)\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i)\n }\n return\n }\n\n reconcileKeyedChildren(parent, newChildren, oldChildren)\n}\n\n/**\n * Handles the complex logic of reconciling keyed children.\n *\n * WHY: When keys are present, we can't just iterate by index. We need to map\n * existing children by their key so we can find them even if they've moved.\n * This allows us to re-use DOM nodes (preserving focus/state) instead of\n * destroying and re-creating them.\n */\nfunction reconcileKeyedChildren(parent, newChildren, oldChildren) {\n // Map existing children by Key for O(1) lookup\n const keyed = {}\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i\n keyed[key] = { vNode: child, index: i }\n })\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i\n const existingChildMatch = keyed[key]\n\n if (existingChildMatch) {\n // A. MATCH FOUND - The item existed before\n const oldVNode = existingChildMatch.vNode\n\n // Update the node's content recursively\n patch(parent, newChild, oldVNode, i)\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const el = newChild.el || oldVNode.el\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i]\n\n // If the element exists but is in the wrong place, move it\n if (el && domChildAtIndex !== el) {\n parent.insertBefore(el, domChildAtIndex)\n track('patches')\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key]\n } else {\n // B. NO MATCH - This is a new item\n const newEl = createElement(newChild)\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newEl, domChildAtIndex)\n } else {\n parent.appendChild(newEl)\n }\n }\n })\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n runUnmount(vNode) // Clean up hooks\n parent.removeChild(vNode.el)\n track('elementsRemoved')\n }\n })\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h.js\").VNode} vNode - The component vNode.\n * @returns {import(\"./h.js\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n track('componentsRendered')\n\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n }\n\n // 2. Set Global Scope\n setInstance(hooks)\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props)\n\n // 4. Clear Global Scope\n setInstance(null)\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks\n\n return renderedVNode\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h.js\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn())\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child)\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount)\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h.js\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h.js\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n track('diffs')\n\n // Case 1: Removal - The new node is null/undefined, so we remove the old one.\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index]\n\n // Recursive Cleanup\n runUnmount(oldVNode)\n\n if (el) {\n parent.removeChild(el)\n track('elementsRemoved')\n }\n return\n }\n\n // Case 2: Component - If it's a function, we delegate to the component logic.\n if (typeof newVNode.tag === 'function') {\n const isNew = !oldVNode\n\n const childVNode = renderComponent(newVNode)\n newVNode.child = childVNode\n\n const oldChild = oldVNode ? oldVNode.child : undefined\n patch(parent, childVNode, oldChild, index)\n\n newVNode.el = childVNode.el\n\n // Run mount hooks on the next tick\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn())\n }, 0)\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return\n }\n\n // Case 3: Creation - No old node exists, so we create a new one.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode))\n return\n }\n\n // Case 4: Replacement - The node type changed (e.g. div -> span), so we replace it entirely.\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== 'string' && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index]\n if (el) {\n parent.replaceChild(createElement(newVNode), el)\n track('patches')\n }\n return\n }\n\n // Case 5: Text Update - It's a text node, so we just update the text content.\n if (typeof newVNode === 'string' || typeof newVNode === 'number') {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index]\n if (el) {\n el.nodeValue = String(newVNode)\n track('patches')\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)))\n }\n }\n return\n }\n\n // Case 6: Update - Same tag, so we update props and recurse into children.\n const el = oldVNode.el || parent.childNodes[index]\n\n if (!el) return\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el\n\n patchProps(el, newVNode.props, oldVNode.props)\n\n reconcileChildren(el, newVNode.children, oldVNode.children)\n}\n","/**\n * @typedef {object} HumnPersist\n * @property {boolean} __humn_persist\n * @property {any} initial\n * @property {PersistConfig} config\n */\n\n/**\n * @typedef {object} PersistConfig\n * @property {string} key\n */\n\n/**\n * Marks a section of the state for persistence in localStorage.\n *\n * @param {any} initial - The initial value of the state.\n * @param {PersistConfig} config - The configuration for persistence.\n * @returns {HumnPersist}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n","import { getObserver } from './observer.js'\nimport { isDev } from './metrics.js'\n\n/**\n * @typedef {object} Synapses\n * @property {function} set - Function to update the memory\n * @property {function} get - Function to get the memory\n */\n\n/**\n * @typedef {object} CortexParams\n * @property {object} memory - The initial state\n * @property {function(function, function): object} synapses - The synapses function\n */\n\n/**\n * The Cortex class manages the state of the application.\n * This uses a Proxy for fine-grained reactivity, ensuring only those components\n * which use the updated value get re-rendered.\n *\n * WHY: We use Proxies instead of simple getters/setters because it allows us to\n * detect access to nested properties dynamically without needing to declare\n * dependencies upfront. This \"magic\" auto-subscription is what makes Humn's\n * DX so clean.\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexParams} CortexParams - The parameters for the Cortex.\n */\n constructor({ memory, synapses }) {\n const liveMemory = { ...memory }\n this._persistenceMap = new Map()\n\n // Load in any existing values from local-storage\n for (const [key, value] of Object.entries(memory)) {\n if (value && value.__humn_persist) {\n const storageKey = value.config.key || key\n this._persistenceMap.set(key, storageKey)\n\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored !== null) {\n liveMemory[key] = JSON.parse(stored)\n } else {\n liveMemory[key] = value.initial\n }\n } catch (err) {\n if (isDev)\n console.warn(`Humn: Failed to load '${key}' from storage.`, err)\n liveMemory[key] = value.initial\n }\n }\n }\n\n this._memory = liveMemory\n this._listeners = new Map()\n\n const get = () => this._memory\n\n const set = (updater) => {\n let nextState\n let changedPaths = new Set()\n\n if (typeof updater === 'function') {\n const clone = structuredClone(this._memory)\n const proxy = this._createChangeTrackingProxy(clone, changedPaths)\n const result = updater(proxy)\n\n if (result && typeof result === 'object') {\n nextState = { ...this._memory, ...result }\n Object.keys(result).forEach((key) => changedPaths.add(key))\n } else {\n nextState = clone\n }\n } else {\n nextState = { ...this._memory, ...updater }\n changedPaths = new Set(Object.keys(updater))\n }\n\n this._memory = nextState\n\n // If we need to persist any of the values\n // we save them to localStorage here\n if (this._persistenceMap.size > 0) {\n this._persistenceMap.forEach((storageKey, stateKey) => {\n const isDirty = Array.from(changedPaths).some(\n (path) => path === stateKey || path.startsWith(stateKey + '.'),\n )\n\n if (isDirty) {\n try {\n const value = this._memory[stateKey]\n localStorage.setItem(storageKey, JSON.stringify(value))\n } catch (err) {\n if (isDev)\n console.error(`Humn: Failed to save '${stateKey}'.`, err)\n }\n }\n })\n }\n\n this._notifyRelevantListeners(changedPaths)\n }\n\n this.synapses = synapses(set, get)\n }\n\n /**\n * Creates a Proxy that tracks which properties are being mutated.\n * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.\n *\n * WHY: We need to know exactly which paths were changed so we can notify ONLY\n * the components that care about those specific paths. If we just knew \"something changed\",\n * we'd have to re-render the whole app (like Redux) or rely on manual optimization.\n */\n _createChangeTrackingProxy(obj, changedPaths, path = '') {\n return new Proxy(obj, {\n get: (target, prop) => {\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const value = target[prop]\n const fullPath = path ? `${path}.${prop}` : prop\n\n // Recursively proxy nested objects so we can trap their sets too\n if (typeof value === 'object' && value !== null) {\n return this._createChangeTrackingProxy(value, changedPaths, fullPath)\n }\n return value\n },\n set: (target, prop, value) => {\n if (typeof prop === 'symbol' || prop === '__proto__') {\n target[prop] = value\n return true\n }\n\n const fullPath = path ? `${path}.${prop}` : prop\n changedPaths.add(fullPath)\n\n target[prop] = value\n return true\n },\n })\n }\n\n /**\n * Only notify listeners that read properties which changed\n */\n _notifyRelevantListeners(changedPaths) {\n this._listeners.forEach((accessedPaths, renderFn) => {\n const shouldNotify = Array.from(accessedPaths).some((accessedPath) => {\n return Array.from(changedPaths).some((changedPath) => {\n // Check for exact match or parent/child relationship\n return (\n accessedPath === changedPath ||\n accessedPath.startsWith(changedPath + '.') ||\n changedPath.startsWith(accessedPath + '.')\n )\n })\n })\n\n if (shouldNotify) renderFn()\n })\n }\n\n /**\n * Creates a Proxy that tracks which properties are accessed during render\n *\n * WHY: This is the other half of the magic. By tracking what a component READS\n * during its render, we build a precise dependency graph. If a component reads\n * `state.user.name`, it will only re-render when `state.user.name` changes,\n * not when `state.count` changes.\n */\n _createAccessTrackingProxy(obj, accessedPaths, path = '') {\n if (typeof obj !== 'object' || obj === null) return obj\n\n return new Proxy(obj, {\n get: (target, prop) => {\n // We don't care about prototype and symbol properties\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const fullPath = path ? `${path}.${prop}` : prop\n accessedPaths.add(fullPath)\n\n const value = target[prop]\n\n // Recursively wrap nested objects\n if (typeof value === 'object' && value !== null)\n return this._createAccessTrackingProxy(value, accessedPaths, fullPath)\n\n return value\n },\n })\n }\n\n /**\n * Returns memory wrapped in a tracking Proxy\n */\n get memory() {\n const currentObserver = getObserver()\n\n if (!currentObserver) return this._memory\n\n if (!this._listeners.has(currentObserver))\n this._listeners.set(currentObserver, new Set())\n\n const accessedPaths = this._listeners.get(currentObserver)\n\n // This gives us fresh tracking each render\n accessedPaths.clear()\n\n return this._createAccessTrackingProxy(this._memory, accessedPaths)\n }\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children]\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat()\n .filter((c) => c !== null && c !== undefined && c !== false && c !== '')\n\n return {\n tag,\n props,\n children: cleanChildren,\n }\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from './observer.js'\nimport { patch } from './patch.js'\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null\n\n const lifecycle = () => {\n setObserver(lifecycle)\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n }\n\n patch(target, nextVNode, prevVNode)\n setObserver(null)\n prevVNode = nextVNode\n }\n\n lifecycle()\n}\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from './observer.js'\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance()\n if (instance) {\n instance.mounts.push(fn)\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance()\n if (instance) {\n instance.cleanups.push(fn)\n }\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","Humn","this","currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","styleSheet","cache","Set","hasKeys","children","some","c","props","key","createElement","vNode","document","createTextNode","String","tag","childVNode","renderComponent","child","el","hooks","mounts","length","setTimeout","forEach","fn","patchProps","appendChild","newProps","oldProps","allProps","oldValue","newValue","startsWith","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","parent","newChildren","oldChildren","maxLen","Math","max","i","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newEl","Object","values","parentNode","runUnmount","removeChild","cleanups","renderedVNode","newVNode","isNew","replaceChild","nodeValue","Cortex","constructor","memory","synapses","liveMemory","_persistenceMap","Map","value","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","_memory","_listeners","updater","nextState","changedPaths","clone","structuredClone","result","_createChangeTrackingProxy","keys","add","size","stateKey","Array","from","path","setItem","stringify","_notifyRelevantListeners","obj","Proxy","get","target","prop","fullPath","accessedPaths","renderFn","accessedPath","changedPath","_createAccessTrackingProxy","has","clear","css","stringsOrStr","args","raw","isSingleRoot","isArray","reduce","acc","str","content","replace","trim","hash","charCodeAt","toString","hashedClassName","id","head","textContent","h","flat","filter","mount","Component","prevVNode","lifecycle","nextVNode","onCleanup","instance","push","onMount","persist","defineProperty","Symbol","toStringTag"],"mappings":"CAAA,SAAAA,EAAAC,EAAAA,CAAA,OAAAC,SAAA,iBAAAC,OAAA,IAAAF,EAAAC,OAAAA,EAAA,OAAAE,QAAA,YAAAA,OAAAC,IAAAD,OAAA,CAAA,SAAA,EAAAH,CAAAA,EAAAA,GAAAD,EAAA,OAAAM,WAAA,IAAAA,WAAAN,GAAAO,MAAAC,KAAA,CAAA,CAAA,CAAA,GAAAC,KAAA,SAAAP,EAAAA,CAAA,aAKA,IAAIQ,EAAkB,KAClBC,EAAkB,KAMf,MAAMC,EAAc,IAAMF,EAMpBG,EAAeC,GAAAA,CAC1BJ,EAAkBI,CAAAA,EAOPC,EAAc,IAAMJ,EAMpBK,EAAeC,GAAAA,CAC1BN,EAAkBM,CAAAA,EC5BpB,IAAIC,EAAa,KACjB,MAAMC,EAAQ,IAAIC,ICOX,SAASC,EAAQC,EAAAA,CACtB,OAAOA,GAAYA,EAASC,KAAMC,GAAMA,GAAKA,EAAEC,OAASD,EAAEC,MAAMC,KAAO,IAAPA,CAClE,CAOA,SAASC,EAAcC,EAAAA,CACrB,GAAqB,OAAV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
12
12
  * The Cortex class manages the state of the application.
13
+ * This uses a Proxy for fine-grained reactivity, ensuring only those components
14
+ * which use the updated value get re-rendered.
15
+ *
16
+ * WHY: We use Proxies instead of simple getters/setters because it allows us to
17
+ * detect access to nested properties dynamically without needing to declare
18
+ * dependencies upfront. This "magic" auto-subscription is what makes Humn's
19
+ * DX so clean.
13
20
  */
14
21
  export declare class Cortex {
15
22
  /**
@@ -17,14 +24,36 @@ export declare class Cortex {
17
24
  * @param {CortexParams} CortexParams - The parameters for the Cortex.
18
25
  */
19
26
  constructor({ memory, synapses }: CortexParams);
27
+ _persistenceMap: Map<any, any>;
20
28
  _memory: any;
21
- _listeners: Set<any>;
29
+ _listeners: Map<any, any>;
22
30
  synapses: any;
23
31
  /**
24
- * Get the memory and register the current observer.
25
- * @returns {object} The current state
32
+ * Creates a Proxy that tracks which properties are being mutated.
33
+ * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.
34
+ *
35
+ * WHY: We need to know exactly which paths were changed so we can notify ONLY
36
+ * the components that care about those specific paths. If we just knew "something changed",
37
+ * we'd have to re-render the whole app (like Redux) or rely on manual optimization.
26
38
  */
27
- get memory(): object;
39
+ _createChangeTrackingProxy(obj: any, changedPaths: any, path?: string): any;
40
+ /**
41
+ * Only notify listeners that read properties which changed
42
+ */
43
+ _notifyRelevantListeners(changedPaths: any): void;
44
+ /**
45
+ * Creates a Proxy that tracks which properties are accessed during render
46
+ *
47
+ * WHY: This is the other half of the magic. By tracking what a component READS
48
+ * during its render, we build a precise dependency graph. If a component reads
49
+ * `state.user.name`, it will only re-render when `state.user.name` changes,
50
+ * not when `state.count` changes.
51
+ */
52
+ _createAccessTrackingProxy(obj: any, accessedPaths: any, path?: string): any;
53
+ /**
54
+ * Returns memory wrapped in a tracking Proxy
55
+ */
56
+ get memory(): any;
28
57
  }
29
58
 
30
59
  export declare type CortexParams = {
@@ -41,11 +70,20 @@ export declare type CortexParams = {
41
70
  /**
42
71
  * Scoped CSS Tag.
43
72
  * Wraps content in a unique class using Native CSS Nesting.
73
+ * Supports two signatures:
74
+ * 1. Tagged Template: css`...`
75
+ * 2. Function: css(string, isSingleRoot)
44
76
  */
45
- export declare function css(strings: any, ...args: any[]): string;
77
+ export declare function css(stringsOrStr: any, ...args: any[]): string;
46
78
 
47
79
  export declare function h(tag: string, props?: object, children?: VNode[] | VNode): VNode;
48
80
 
81
+ export declare type HumnPersist = {
82
+ __humn_persist: boolean;
83
+ initial: any;
84
+ config: PersistConfig;
85
+ };
86
+
49
87
  export declare function mount(target: HTMLElement, Component: Function): void;
50
88
 
51
89
  /**
@@ -60,6 +98,12 @@ export declare function onCleanup(fn: Function): void;
60
98
  */
61
99
  export declare function onMount(fn: Function): void;
62
100
 
101
+ export declare function persist(initial: any, config?: PersistConfig): HumnPersist;
102
+
103
+ export declare type PersistConfig = {
104
+ key: string;
105
+ };
106
+
63
107
  export declare type Synapses = {
64
108
  /**
65
109
  * - Function to update the memory
package/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "humn",
3
- "version": "1.0.1",
3
+ "version": "1.3.1",
4
4
  "description": "A minimal, human-centric reactive UI library with built in state management.",
5
+ "keywords": [
6
+ "reactive",
7
+ "ui",
8
+ "state",
9
+ "store",
10
+ "cortex"
11
+ ],
12
+ "homepage": "https://www.npmjs.com/package/humn",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/KeeghanM/humn.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Keeghan McGarry",
5
19
  "type": "module",
6
- "main": "./dist/humn.umd.js",
7
- "module": "./dist/humn.js",
8
- "types": "./dist/index.d.ts",
9
20
  "exports": {
10
21
  ".": {
11
22
  "types": "./dist/index.d.ts",
@@ -13,6 +24,9 @@
13
24
  "require": "./dist/humn.umd.js"
14
25
  }
15
26
  },
27
+ "main": "./dist/humn.umd.js",
28
+ "module": "./dist/humn.js",
29
+ "types": "./dist/index.d.ts",
16
30
  "files": [
17
31
  "dist",
18
32
  "README.md",
@@ -20,35 +34,26 @@
20
34
  ],
21
35
  "scripts": {
22
36
  "build": "vite build",
23
- "test": "vitest",
24
- "dev": "vite --port 3000 --open /playground/",
25
- "prepublishOnly": "npm run build"
26
- },
27
- "keywords": [
28
- "reactive",
29
- "ui",
30
- "state",
31
- "store",
32
- "cortex"
33
- ],
34
- "author": "Keeghan McGarry",
35
- "license": "MIT",
36
- "homepage": "https://www.npmjs.com/package/humn",
37
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/KeeghanM/humn"
37
+ "dev": "node --inspect ../../node_modules/vite/bin/vite.js --port 3000 --open /playground/",
38
+ "prepublishOnly": "npm run build",
39
+ "qa:test": "vitest run",
40
+ "qa:test:watch": "vitest watch"
41
41
  },
42
42
  "devDependencies": {
43
+ "@rollup/plugin-terser": "^0.4.4",
43
44
  "@semantic-release/changelog": "^6.0.3",
44
45
  "@semantic-release/git": "^10.0.1",
45
46
  "@semantic-release/github": "^12.0.2",
46
47
  "@semantic-release/npm": "^13.1.2",
47
48
  "@types/node": "^24.10.1",
48
49
  "conventional-changelog-conventionalcommits": "^9.1.0",
50
+ "jsdom": "^27.2.0",
49
51
  "semantic-release": "^25.0.2",
50
52
  "typescript": "^5.9.3",
51
53
  "vite": "^7.2.6",
52
- "vite-plugin-dts": "^4.5.4"
53
- }
54
+ "vite-plugin-dts": "^4.5.4",
55
+ "vite-plugin-humn": "*",
56
+ "vitest": "^4.0.15"
57
+ },
58
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
54
59
  }