humn 1.4.0 → 1.4.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/dist/humn.js +185 -165
- package/dist/humn.js.map +1 -1
- package/dist/humn.umd.js +2 -2
- package/dist/humn.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/humn.js
CHANGED
|
@@ -1,219 +1,239 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
},
|
|
5
|
-
|
|
1
|
+
let x = null, S = null;
|
|
2
|
+
const M = () => x, w = (e) => {
|
|
3
|
+
x = e;
|
|
4
|
+
}, A = () => S, E = (e) => {
|
|
5
|
+
S = e;
|
|
6
6
|
};
|
|
7
|
-
class
|
|
8
|
-
constructor({ memory:
|
|
9
|
-
const
|
|
7
|
+
class O {
|
|
8
|
+
constructor({ memory: t, synapses: n }) {
|
|
9
|
+
const c = { ...t };
|
|
10
10
|
this._persistenceMap = /* @__PURE__ */ new Map();
|
|
11
|
-
for (const [
|
|
12
|
-
const
|
|
13
|
-
this._persistenceMap.set(
|
|
11
|
+
for (const [o, s] of Object.entries(t)) if (s && typeof s == "object" && s.__humn_persist) {
|
|
12
|
+
const i = s.config?.key || o;
|
|
13
|
+
this._persistenceMap.set(o, i);
|
|
14
14
|
try {
|
|
15
|
-
const
|
|
16
|
-
o
|
|
15
|
+
const r = localStorage.getItem(i);
|
|
16
|
+
c[o] = r !== null ? JSON.parse(r) : s.initial;
|
|
17
17
|
} catch {
|
|
18
|
-
o
|
|
18
|
+
c[o] = s.initial;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
this._memory =
|
|
22
|
-
let s,
|
|
23
|
-
if (typeof
|
|
24
|
-
const
|
|
25
|
-
l && typeof l == "object" ? (s = { ...this._memory, ...l }, Object.keys(l).forEach((a) =>
|
|
26
|
-
} else s = { ...this._memory, ...
|
|
27
|
-
this._memory = s, this._persistenceMap.size > 0 && this._persistenceMap.forEach((
|
|
28
|
-
if (Array.from(
|
|
21
|
+
this._memory = c, this._listeners = /* @__PURE__ */ new Map(), this.synapses = n((o) => {
|
|
22
|
+
let s, i = /* @__PURE__ */ new Set();
|
|
23
|
+
if (typeof o == "function") {
|
|
24
|
+
const r = structuredClone(this._memory), l = o(this._createChangeTrackingProxy(r, i));
|
|
25
|
+
l && typeof l == "object" ? (s = { ...this._memory, ...l }, Object.keys(l).forEach((a) => i.add(a))) : s = r;
|
|
26
|
+
} else s = { ...this._memory, ...o }, i = new Set(Object.keys(o));
|
|
27
|
+
this._memory = s, this._persistenceMap.size > 0 && this._persistenceMap.forEach((r, l) => {
|
|
28
|
+
if (Array.from(i).some((a) => a === l || a.startsWith(l + "."))) try {
|
|
29
29
|
const a = this._memory[l];
|
|
30
|
-
localStorage.setItem(
|
|
30
|
+
localStorage.setItem(r, JSON.stringify(a));
|
|
31
31
|
} catch {
|
|
32
32
|
}
|
|
33
|
-
}), this._notifyRelevantListeners(
|
|
33
|
+
}), this._notifyRelevantListeners(i);
|
|
34
34
|
}, () => this._memory);
|
|
35
35
|
}
|
|
36
|
-
_createChangeTrackingProxy(
|
|
37
|
-
return new Proxy(
|
|
38
|
-
if (typeof s == "symbol" || s === "__proto__") return
|
|
39
|
-
const
|
|
40
|
-
return typeof
|
|
41
|
-
}, set: (
|
|
42
|
-
if (typeof s == "symbol" || s === "__proto__") return
|
|
43
|
-
const
|
|
44
|
-
return
|
|
36
|
+
_createChangeTrackingProxy(t, n, c = "") {
|
|
37
|
+
return new Proxy(t, { get: (o, s) => {
|
|
38
|
+
if (typeof s == "symbol" || s === "__proto__") return o[s];
|
|
39
|
+
const i = o[s], r = c ? `${c}.${s}` : s;
|
|
40
|
+
return typeof i == "object" && i !== null ? this._createChangeTrackingProxy(i, n, r) : i;
|
|
41
|
+
}, set: (o, s, i) => {
|
|
42
|
+
if (typeof s == "symbol" || s === "__proto__") return o[s] = i, !0;
|
|
43
|
+
const r = c ? `${c}.${s}` : s;
|
|
44
|
+
return n.add(r), o[s] = i, !0;
|
|
45
45
|
} });
|
|
46
46
|
}
|
|
47
|
-
_notifyRelevantListeners(
|
|
48
|
-
this._listeners.forEach((
|
|
49
|
-
Array.from(
|
|
47
|
+
_notifyRelevantListeners(t) {
|
|
48
|
+
this._listeners.forEach((n, c) => {
|
|
49
|
+
Array.from(n).some((o) => Array.from(t).some((s) => o === s || o.startsWith(s + ".") || s.startsWith(o + "."))) && c();
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
_createAccessTrackingProxy(
|
|
53
|
-
return typeof
|
|
54
|
-
if (typeof s == "symbol" || s === "__proto__") return
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
return typeof
|
|
52
|
+
_createAccessTrackingProxy(t, n, c = "") {
|
|
53
|
+
return typeof t != "object" || t === null ? t : new Proxy(t, { get: (o, s) => {
|
|
54
|
+
if (typeof s == "symbol" || s === "__proto__") return o[s];
|
|
55
|
+
const i = c ? `${c}.${s}` : s;
|
|
56
|
+
n.add(i);
|
|
57
|
+
const r = o[s];
|
|
58
|
+
return typeof r == "object" && r !== null ? this._createAccessTrackingProxy(r, n, i) : r;
|
|
59
59
|
} });
|
|
60
60
|
}
|
|
61
61
|
get memory() {
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
this._listeners.has(
|
|
65
|
-
const
|
|
66
|
-
return this._createAccessTrackingProxy(this._memory,
|
|
62
|
+
const t = M();
|
|
63
|
+
if (!t) return this._memory;
|
|
64
|
+
this._listeners.has(t) || this._listeners.set(t, /* @__PURE__ */ new Set());
|
|
65
|
+
const n = this._listeners.get(t);
|
|
66
|
+
return this._createAccessTrackingProxy(this._memory, n);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
let p = null;
|
|
70
70
|
const C = /* @__PURE__ */ new Set();
|
|
71
|
-
function
|
|
72
|
-
let
|
|
73
|
-
Array.isArray(
|
|
74
|
-
let
|
|
75
|
-
return
|
|
76
|
-
})(
|
|
77
|
-
if (!
|
|
78
|
-
|
|
79
|
-
const s = (function(
|
|
80
|
-
let l = 5381, a =
|
|
81
|
-
for (; a; ) l = 33 * l ^
|
|
71
|
+
function P(e, ...t) {
|
|
72
|
+
let n = "", c = !1;
|
|
73
|
+
Array.isArray(e) && e.raw ? n = e.reduce((r, l, a) => r + l + (t[a] || ""), "") : (n = e, c = t[0] === !0);
|
|
74
|
+
let o = (function(r) {
|
|
75
|
+
return r.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").trim();
|
|
76
|
+
})(n);
|
|
77
|
+
if (!o) return "";
|
|
78
|
+
c && (o = o.replace(/(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi, "$1$2$3&, $3"));
|
|
79
|
+
const s = (function(r) {
|
|
80
|
+
let l = 5381, a = r.length;
|
|
81
|
+
for (; a; ) l = 33 * l ^ r.charCodeAt(--a);
|
|
82
82
|
return (l >>> 0).toString(36);
|
|
83
|
-
})(
|
|
84
|
-
return C.has(s) || (p || (p = document.createElement("style"), p.id = "humn-styles", document.head.appendChild(p)), p.textContent += `.${
|
|
85
|
-
${
|
|
83
|
+
})(o), i = `humn-${s}`;
|
|
84
|
+
return C.has(s) || (p || (p = document.createElement("style"), p.id = "humn-styles", document.head.appendChild(p)), p.textContent += `.${i} {
|
|
85
|
+
${o}
|
|
86
86
|
}
|
|
87
|
-
`, C.add(s)),
|
|
87
|
+
`, C.add(s)), i;
|
|
88
88
|
}
|
|
89
|
-
const
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
|
|
89
|
+
const L = (e, t = {}, n = []) => ({ tag: e, props: t, children: (Array.isArray(n) ? n : [n]).flat().filter((c) => c != null && c !== !1 && c !== "") });
|
|
90
|
+
function I(e) {
|
|
91
|
+
const t = A();
|
|
92
|
+
t && t.mounts.push(e);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
|
|
94
|
+
function R(e) {
|
|
95
|
+
const t = A();
|
|
96
|
+
t && t.cleanups.push(e);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
98
|
+
function f(e, t) {
|
|
99
|
+
try {
|
|
100
|
+
e();
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
100
103
|
}
|
|
101
|
-
function
|
|
102
|
-
return
|
|
104
|
+
function g(e) {
|
|
105
|
+
return e.namespaceURI === _ && e.tagName !== "foreignObject" ? _ : e.namespaceURI === k ? k : null;
|
|
103
106
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
function N(e) {
|
|
108
|
+
return e && e.some((t) => t && t.props && t.props.key != null);
|
|
109
|
+
}
|
|
110
|
+
const _ = "http://www.w3.org/2000/svg", k = "http://www.w3.org/1998/Math/MathML";
|
|
111
|
+
function d(e, t) {
|
|
112
|
+
if (typeof e == "string" || typeof e == "number") return document.createTextNode(String(e));
|
|
113
|
+
if (typeof e.tag == "function") {
|
|
114
|
+
const s = j(e);
|
|
115
|
+
e.child = s;
|
|
116
|
+
const i = d(s, t);
|
|
117
|
+
return e.el = i, e.hooks?.mounts.length > 0 && setTimeout(() => {
|
|
118
|
+
e.hooks.mounts.forEach((r) => {
|
|
119
|
+
f(r);
|
|
120
|
+
});
|
|
121
|
+
}, 0), i;
|
|
112
122
|
}
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
}),
|
|
123
|
+
const n = e.tag;
|
|
124
|
+
n === "svg" ? t = _ : n === "math" && (t = k);
|
|
125
|
+
const c = t ? document.createElementNS(t, n) : document.createElement(n);
|
|
126
|
+
e.el = c, $(c, e.props);
|
|
127
|
+
const o = n === "foreignObject" ? null : t;
|
|
128
|
+
return e.children.forEach((s) => {
|
|
129
|
+
c.appendChild(d(s, o));
|
|
130
|
+
}), c;
|
|
121
131
|
}
|
|
122
|
-
function
|
|
123
|
-
if (!
|
|
124
|
-
const
|
|
125
|
-
for (const
|
|
126
|
-
const s =
|
|
127
|
-
if (
|
|
128
|
-
if (s !==
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
s &&
|
|
132
|
+
function $(e, t = {}, n = {}) {
|
|
133
|
+
if (!e) return;
|
|
134
|
+
const c = { ...n, ...t };
|
|
135
|
+
for (const o in c) {
|
|
136
|
+
const s = n[o], i = t[o];
|
|
137
|
+
if (i != null) if (o !== "value" && o !== "checked") {
|
|
138
|
+
if (s !== i) {
|
|
139
|
+
if (o.startsWith("on")) {
|
|
140
|
+
const r = o.slice(2).toLowerCase();
|
|
141
|
+
s && e.removeEventListener(r, s), e.addEventListener(r, i);
|
|
132
142
|
}
|
|
133
|
-
|
|
143
|
+
o === "disabled" ? e.disabled = i === !0 || i === "true" : e.setAttribute(o, i);
|
|
134
144
|
}
|
|
135
|
-
} else
|
|
136
|
-
else
|
|
145
|
+
} else e[o] !== i && (e[o] = i);
|
|
146
|
+
else e.removeAttribute(o);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
|
-
function
|
|
140
|
-
if (!(
|
|
141
|
-
const
|
|
142
|
-
for (let
|
|
149
|
+
function T(e, t, n) {
|
|
150
|
+
if (!(N(t) || N(n))) {
|
|
151
|
+
const c = Math.max(t.length, n.length);
|
|
152
|
+
for (let o = 0; o < c; o++) y(e, t[o], n[o], o);
|
|
143
153
|
return;
|
|
144
154
|
}
|
|
145
|
-
(function(
|
|
146
|
-
const
|
|
147
|
-
s.forEach((
|
|
148
|
-
const a = (
|
|
149
|
-
|
|
150
|
-
}),
|
|
151
|
-
const a = (
|
|
152
|
-
if (
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
155
|
+
(function(c, o, s) {
|
|
156
|
+
const i = {};
|
|
157
|
+
s.forEach((r, l) => {
|
|
158
|
+
const a = (r.props && r.props.key) != null ? r.props.key : l;
|
|
159
|
+
i[a] = { vNode: r, index: l };
|
|
160
|
+
}), o.forEach((r, l) => {
|
|
161
|
+
const a = (r.props && r.props.key) != null ? r.props.key : l, b = i[a];
|
|
162
|
+
if (b) {
|
|
163
|
+
const u = b.vNode;
|
|
164
|
+
y(c, r, u, l);
|
|
165
|
+
const h = r.el || u.el, v = c.childNodes[l];
|
|
166
|
+
h && v !== h && c.insertBefore(h, v), delete i[a];
|
|
157
167
|
} else {
|
|
158
|
-
const
|
|
159
|
-
|
|
168
|
+
const u = d(r, g(c)), h = c.childNodes[l];
|
|
169
|
+
h ? c.insertBefore(u, h) : c.appendChild(u);
|
|
160
170
|
}
|
|
161
|
-
}), Object.values(
|
|
162
|
-
|
|
171
|
+
}), Object.values(i).forEach(({ vNode: r }) => {
|
|
172
|
+
r.el && r.el.parentNode === c && (m(r), c.removeChild(r.el));
|
|
163
173
|
});
|
|
164
|
-
})(
|
|
174
|
+
})(e, t, n);
|
|
165
175
|
}
|
|
166
|
-
function
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
return
|
|
176
|
+
function j(e) {
|
|
177
|
+
const t = { mounts: [], cleanups: [] };
|
|
178
|
+
E(t);
|
|
179
|
+
const n = e.tag(e.props);
|
|
180
|
+
return E(null), e.hooks = t, n;
|
|
171
181
|
}
|
|
172
|
-
function
|
|
173
|
-
|
|
182
|
+
function m(e) {
|
|
183
|
+
e && (e.hooks && e.hooks.cleanups && e.hooks.cleanups.forEach((t) => {
|
|
184
|
+
f(t);
|
|
185
|
+
}), e.child && m(e.child), e.children && e.children.forEach(m));
|
|
174
186
|
}
|
|
175
|
-
function
|
|
176
|
-
if (
|
|
177
|
-
const s =
|
|
178
|
-
return
|
|
187
|
+
function y(e, t, n, c = 0) {
|
|
188
|
+
if (t == null) {
|
|
189
|
+
const s = n.el || e.childNodes[c];
|
|
190
|
+
return m(n), void (s && e.removeChild(s));
|
|
179
191
|
}
|
|
180
|
-
if (typeof
|
|
181
|
-
const s = !
|
|
182
|
-
return
|
|
183
|
-
|
|
184
|
-
|
|
192
|
+
if (typeof t.tag == "function") {
|
|
193
|
+
const s = !n, i = !!n?.hooks?.cleanups?.length, r = j(t);
|
|
194
|
+
return t.child = r, y(e, r, n ? n.child : void 0, c), t.el = r.el, s && t.hooks && t.hooks.mounts.length > 0 && setTimeout(() => {
|
|
195
|
+
t.hooks.mounts.forEach((l) => {
|
|
196
|
+
f(l);
|
|
197
|
+
});
|
|
198
|
+
}, 0), void (!s && i && (n.hooks.cleanups.forEach((l) => {
|
|
199
|
+
f(l);
|
|
200
|
+
}), t.hooks?.mounts?.length > 0 && setTimeout(() => {
|
|
201
|
+
t.hooks.mounts.forEach((l) => {
|
|
202
|
+
f(l);
|
|
203
|
+
});
|
|
204
|
+
}, 0)));
|
|
185
205
|
}
|
|
186
|
-
if (
|
|
187
|
-
if (typeof
|
|
188
|
-
const s =
|
|
189
|
-
return void (s &&
|
|
206
|
+
if (n == null) return void e.appendChild(d(t, g(e)));
|
|
207
|
+
if (typeof t != typeof n || typeof t != "string" && t.tag !== n.tag) {
|
|
208
|
+
const s = n.el || e.childNodes[c];
|
|
209
|
+
return void (s && e.replaceChild(d(t, g(e)), s));
|
|
190
210
|
}
|
|
191
|
-
if (typeof
|
|
192
|
-
if (
|
|
193
|
-
const s =
|
|
194
|
-
s ? s.nodeValue = String(
|
|
211
|
+
if (typeof t == "string" || typeof t == "number") {
|
|
212
|
+
if (t !== n) {
|
|
213
|
+
const s = e.childNodes[c];
|
|
214
|
+
s ? s.nodeValue = String(t) : e.appendChild(document.createTextNode(String(t)));
|
|
195
215
|
}
|
|
196
216
|
return;
|
|
197
217
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
218
|
+
const o = n.el || e.childNodes[c];
|
|
219
|
+
o && (t.el = o, $(o, t.props, n.props), T(o, t.children, n.children));
|
|
200
220
|
}
|
|
201
|
-
const
|
|
202
|
-
let
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
221
|
+
const W = (e, t) => {
|
|
222
|
+
let n = null;
|
|
223
|
+
const c = () => {
|
|
224
|
+
w(c);
|
|
225
|
+
const o = { tag: t, props: {}, children: [] };
|
|
226
|
+
y(e, o, n), w(null), n = o;
|
|
207
227
|
};
|
|
208
|
-
|
|
209
|
-
},
|
|
228
|
+
c();
|
|
229
|
+
}, B = (e, t = {}) => ({ __humn_persist: !0, initial: e, config: t });
|
|
210
230
|
export {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
231
|
+
O as Cortex,
|
|
232
|
+
P as css,
|
|
233
|
+
L as h,
|
|
234
|
+
W as mount,
|
|
235
|
+
R as onCleanup,
|
|
236
|
+
I as onMount,
|
|
237
|
+
B as persist
|
|
218
238
|
};
|
|
219
239
|
//# 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","../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 { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * Mapped type for the Memory configuration object.\n * Allows each property to be the raw value OR a persisted wrapper.\n * @template T\n * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput\n */\n\n/**\n * Deeply unwraps persisted values from the memory shape.\n * @template {object} T\n * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory\n */\n\n/**\n * @template T\n * @callback Getter\n * @returns {T}\n */\n\n/**\n * @template T\n * @callback Setter\n * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater\n * @returns {void}\n */\n\n/**\n * @template M, S\n * @callback SynapsesBuilder\n * @param {Setter<M>} set\n * @param {Getter<M>} get\n * @returns {S}\n */\n\n/**\n * @template M, S\n * @typedef {object} CortexConfig\n * @property {MemoryInput<M>} memory - The initial state configuration\n * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function\n */\n\n/**\n * The Cortex class manages the state of the application.\n *\n * @template {object} MemoryType The shape of the application state\n * @template {object} SynapsesType The shape of the actions/methods\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexConfig<MemoryType, SynapsesType>} config\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 && typeof value === 'object' && 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 /** @type {UnwrappedMemory<MemoryType>} */\n this._memory = liveMemory\n this._listeners = new Map()\n\n /** @type {Getter<UnwrappedMemory<MemoryType>>} */\n const get = () => this._memory\n\n /** @type {Setter<UnwrappedMemory<MemoryType>>} */\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 // Persistence logic\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 /** @type {SynapsesType} */\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 {UnwrappedMemory<MemoryType>}\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 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\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\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\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\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 const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (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 tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - 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(element, newProps = {}, oldProps = {}) {\n if (!element) 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 element.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 (element[key] !== newValue) {\n element[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) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.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 element = 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 (element && domChildAtIndex !== element) {\n parent.insertBefore(element, 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 newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\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, getNamespace(parent)))\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, getNamespace(parent)), 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 * Represents a value wrapped by the persist() function.\n * @template T\n * @typedef {object} Persisted\n * @property {T} initial\n * @property {boolean} __humn_persist\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 * @template T\n * @param {T} initial\n * @param {PersistConfig} [config]\n * @returns {Persisted<T>}\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","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","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","vNode","namespace","createTextNode","String","childVNode","renderComponent","child","el","hooks","setTimeout","element","createElementNS","patchProps","childNS","newProps","oldProps","allProps","oldValue","newValue","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","values","parentNode","runUnmount","removeChild","renderedVNode","newVNode","isNew","replaceChild","nodeValue","mount","Component","prevVNode","lifecycle","nextVNode","persist"],"mappings":"AAKA,IAAIA,IAAkB,MAClBC,IAAkB;AAMf,MAAMC,IAAc,MAAMF,GAMpBG,IAAeC,OAAAA;AAC1BJ,EAAAA,IAAkBI;AAAAA,GAOPC,IAAc,MAAMJ,GAMpBK,IAAeC,CAAAA,MAAAA;AAC1BN,EAAAA,IAAkBM;AAAAA;ACiBb,MAAMC,EAAAA;AAAAA,EAKX,cAAYC,QAAEA,GAAMC,UAAEA,EAAAA,GAAAA;AACpB,UAAMC,IAAa,EAAA,GAAKF,EAAAA;AACxBG,SAAKC,kBAAkB,oBAAIC;AAG3B,eAAK,CAAOC,GAAKC,CAAAA,KAAUC,OAAOC,QAAQT,GACxC,KAAIO,KAA0B,OAAVA,KAAU,YAAYA,EAAMG,gBAAgB;AAC9D,YAAMC,IAAaJ,EAAMK,QAAQN,O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,SAAS6B,eAAeC,OAAO6C,CAAAA,CAAAA,CAAAA;AAAAA,IAEtD;AACA;AAAA,EACF;AAGA,QAAMzC,IAAK+B,EAAS/B,MAAMb,EAAO8C,WAAWL,CAAAA;AAEvC5B,EAAAA,MAGLyC,EAASzC,KAAKA,GAEdK,EAAWL,GAAIyC,EAASnE,OAAOyD,EAASzD,KAAAA,GAExC8C,EAAkBpB,GAAIyC,EAASlE,UAAUwD,EAASxD,QAAAA;AACpD;AC7WY,MAACsE,IAAQ,CAAC5G,GAAQ6G;AAC5B,MAAIC,IAAY;AAEhB,QAAMC,IAAY,MAAA;AAChBpK,IAAAA,EAAYoK,CAAAA;AAEZ,UAAMC,IAAY,EAChB5E,KAAKyE,GACLxE,OAAO,CAAA,GACPC,UAAU,CAAA,EAAA;AAGZmD,IAAAA,EAAMzF,GAAQgH,GAAWF,CAAAA,GACzBnK,EAAY,OACZmK,IAAYE;AAAAA,EAAAA;AAGdD,EAAAA,EAAAA;AAAAA,GCRWE,IAAU,CAAC7I,GAASP,IAAS,QAAE,EAC1CF,gBAAAA,IACAS,SAAAA,GACAP;"}
|
|
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 { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * Mapped type for the Memory configuration object.\n * Allows each property to be the raw value OR a persisted wrapper.\n * @template T\n * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput\n */\n\n/**\n * Deeply unwraps persisted values from the memory shape.\n * @template {object} T\n * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory\n */\n\n/**\n * @template T\n * @callback Getter\n * @returns {T}\n */\n\n/**\n * @template T\n * @callback Setter\n * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater\n * @returns {void}\n */\n\n/**\n * @template M, S\n * @callback SynapsesBuilder\n * @param {Setter<M>} set\n * @param {Getter<M>} get\n * @returns {S}\n */\n\n/**\n * @template M, S\n * @typedef {object} CortexConfig\n * @property {MemoryInput<M>} memory - The initial state configuration\n * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function\n */\n\n/**\n * The Cortex class manages the state of the application.\n *\n * @template {object} MemoryType The shape of the application state\n * @template {object} SynapsesType The shape of the actions/methods\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexConfig<MemoryType, SynapsesType>} config\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 && typeof value === 'object' && 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 /** @type {UnwrappedMemory<MemoryType>} */\n this._memory = liveMemory\n this._listeners = new Map()\n\n /** @type {Getter<UnwrappedMemory<MemoryType>>} */\n const get = () => this._memory\n\n /** @type {Setter<UnwrappedMemory<MemoryType>>} */\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 // Persistence logic\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 /** @type {SynapsesType} */\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 {UnwrappedMemory<MemoryType>}\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 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\nfunction invokeHookSafely(fn, errorMessage) {\n try {\n fn()\n } catch (error) {\n console.error(errorMessage, error)\n }\n}\n\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\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\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\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 const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (vNode.hooks?.mounts.length > 0) {\n setTimeout(() => {\n vNode.hooks.mounts.forEach((fn) => {\n invokeHookSafely(fn, 'Error in mount hook:')\n })\n }, 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - 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(element, newProps = {}, oldProps = {}) {\n if (!element) 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 element.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 (element[key] !== newValue) {\n element[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) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.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 element = 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 (element && domChildAtIndex !== element) {\n parent.insertBefore(element, 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 newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\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) => {\n invokeHookSafely(fn, 'Error in cleanup hook:')\n })\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 const hasPreviousHooks = Boolean(oldVNode?.hooks?.cleanups?.length)\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) => {\n invokeHookSafely(fn, 'Error in mount hook:')\n })\n }, 0)\n }\n\n if (!isNew && hasPreviousHooks) {\n oldVNode.hooks.cleanups.forEach((fn) => {\n invokeHookSafely(fn, 'Error in cleanup hook:')\n })\n\n if (newVNode.hooks?.mounts?.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => {\n invokeHookSafely(fn, 'Error in mount hook:')\n })\n }, 0)\n }\n }\n\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, getNamespace(parent)))\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, getNamespace(parent)), 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 * Represents a value wrapped by the persist() function.\n * @template T\n * @typedef {object} Persisted\n * @property {T} initial\n * @property {boolean} __humn_persist\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 * @template T\n * @param {T} initial\n * @param {PersistConfig} [config]\n * @returns {Persisted<T>}\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","constructor","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","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","invokeHookSafely","errorMessage","error","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","vNode","namespace","createTextNode","String","childVNode","renderComponent","child","el","hooks","setTimeout","element","createElementNS","patchProps","childNS","newProps","oldProps","allProps","oldValue","newValue","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","values","parentNode","runUnmount","removeChild","renderedVNode","newVNode","isNew","hasPreviousHooks","Boolean","replaceChild","nodeValue","mount","Component","prevVNode","lifecycle","nextVNode","persist"],"mappings":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iD,EAAkBpB,GAAIyC,EAASrE,UAAU2D,EAAS3D,QAAAA;AACpD;AC5YY,MAAC2E,IAAQ,CAACjH,GAAQkH,MAAAA;AAC5B,MAAIC,IAAY;AAEhB,QAAMC,IAAY,MAAA;AAChB1K,IAAAA,EAAY0K;AAEZ,UAAMC,IAAY,EAChBjF,KAAK8E,GACL7E,OAAO,CAAA,GACPC,UAAU;AAGZsD,IAAAA,EAAM5F,GAAQqH,GAAWF,CAAAA,GACzBzK,EAAY,IAAA,GACZyK,IAAYE;AAAAA,EAAAA;AAGdD,EAAAA,EAAAA;AAAAA,GCRWE,IAAU,CAAClJ,GAASP,IAAS,QAAE,EAC1CF,gBAAAA,IACAS,SAAAA,GACAP;"}
|
package/dist/humn.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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,
|
|
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,w=null;const M=()=>h,E=t=>{h=t},x=()=>w,C=t=>{w=t};let p=null;const N=new Set;function d(t,e){try{t()}catch{}}function k(t){return t.namespaceURI===b&&t.tagName!=="foreignObject"?b:t.namespaceURI===v?v:null}function S(t){return t&&t.some(e=>e&&e.props&&e.props.key!=null)}const b="http://www.w3.org/2000/svg",v="http://www.w3.org/1998/Math/MathML";function m(t,e){if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.tag=="function"){const r=j(t);t.child=r;const c=m(r,e);return t.el=c,t.hooks?.mounts.length>0&&setTimeout(()=>{t.hooks.mounts.forEach(i=>{d(i)})},0),c}const o=t.tag;o==="svg"?e=b:o==="math"&&(e=v);const s=e?document.createElementNS(e,o):document.createElement(o);t.el=s,T(s,t.props);const n=o==="foreignObject"?null:e;return t.children.forEach(r=>{s.appendChild(m(r,n))}),s}function T(t,e={},o={}){if(!t)return;const s={...o,...e};for(const n in s){const r=o[n],c=e[n];if(c!=null)if(n!=="value"&&n!=="checked"){if(r!==c){if(n.startsWith("on")){const i=n.slice(2).toLowerCase();r&&t.removeEventListener(i,r),t.addEventListener(i,c)}n==="disabled"?t.disabled=c===!0||c==="true":t.setAttribute(n,c)}}else t[n]!==c&&(t[n]=c);else t.removeAttribute(n)}}function O(t,e,o){if(!(S(e)||S(o))){const s=Math.max(e.length,o.length);for(let n=0;n<s;n++)_(t,e[n],o[n],n);return}(function(s,n,r){const c={};r.forEach((i,l)=>{const u=(i.props&&i.props.key)!=null?i.props.key:l;c[u]={vNode:i,index:l}}),n.forEach((i,l)=>{const u=(i.props&&i.props.key)!=null?i.props.key:l,A=c[u];if(A){const y=A.vNode;_(s,i,y,l);const f=i.el||y.el,$=s.childNodes[l];f&&$!==f&&s.insertBefore(f,$),delete c[u]}else{const y=m(i,k(s)),f=s.childNodes[l];f?s.insertBefore(y,f):s.appendChild(y)}}),Object.values(c).forEach(({vNode:i})=>{i.el&&i.el.parentNode===s&&(g(i),s.removeChild(i.el))})})(t,e,o)}function j(t){const e={mounts:[],cleanups:[]};C(e);const o=t.tag(t.props);return C(null),t.hooks=e,o}function g(t){t&&(t.hooks&&t.hooks.cleanups&&t.hooks.cleanups.forEach(e=>{d(e)}),t.child&&g(t.child),t.children&&t.children.forEach(g))}function _(t,e,o,s=0){if(e==null){const r=o.el||t.childNodes[s];return g(o),void(r&&t.removeChild(r))}if(typeof e.tag=="function"){const r=!o,c=!!o?.hooks?.cleanups?.length,i=j(e);return e.child=i,_(t,i,o?o.child:void 0,s),e.el=i.el,r&&e.hooks&&e.hooks.mounts.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(l=>{d(l)})},0),void(!r&&c&&(o.hooks.cleanups.forEach(l=>{d(l)}),e.hooks?.mounts?.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(l=>{d(l)})},0)))}if(o==null)return void t.appendChild(m(e,k(t)));if(typeof e!=typeof o||typeof e!="string"&&e.tag!==o.tag){const r=o.el||t.childNodes[s];return void(r&&t.replaceChild(m(e,k(t)),r))}if(typeof e=="string"||typeof e=="number"){if(e!==o){const r=t.childNodes[s];r?r.nodeValue=String(e):t.appendChild(document.createTextNode(String(e)))}return}const n=o.el||t.childNodes[s];n&&(e.el=n,T(n,e.props,o.props),O(n,e.children,o.children))}a.Cortex=class{constructor({memory:t,synapses:e}){const o={...t};this._persistenceMap=new Map;for(const[s,n]of Object.entries(t))if(n&&typeof n=="object"&&n.__humn_persist){const r=n.config?.key||s;this._persistenceMap.set(s,r);try{const c=localStorage.getItem(r);o[s]=c!==null?JSON.parse(c):n.initial}catch{o[s]=n.initial}}this._memory=o,this._listeners=new Map,this.synapses=e(s=>{let n,r=new Set;if(typeof s=="function"){const c=structuredClone(this._memory),i=s(this._createChangeTrackingProxy(c,r));i&&typeof i=="object"?(n={...this._memory,...i},Object.keys(i).forEach(l=>r.add(l))):n=c}else n={...this._memory,...s},r=new Set(Object.keys(s));this._memory=n,this._persistenceMap.size>0&&this._persistenceMap.forEach((c,i)=>{if(Array.from(r).some(l=>l===i||l.startsWith(i+".")))try{const l=this._memory[i];localStorage.setItem(c,JSON.stringify(l))}catch{}}),this._notifyRelevantListeners(r)},()=>this._memory)}_createChangeTrackingProxy(t,e,o=""){return new Proxy(t,{get:(s,n)=>{if(typeof n=="symbol"||n==="__proto__")return s[n];const r=s[n],c=o?`${o}.${n}`:n;return typeof r=="object"&&r!==null?this._createChangeTrackingProxy(r,e,c):r},set:(s,n,r)=>{if(typeof n=="symbol"||n==="__proto__")return s[n]=r,!0;const c=o?`${o}.${n}`:n;return e.add(c),s[n]=r,!0}})}_notifyRelevantListeners(t){this._listeners.forEach((e,o)=>{Array.from(e).some(s=>Array.from(t).some(n=>s===n||s.startsWith(n+".")||n.startsWith(s+".")))&&o()})}_createAccessTrackingProxy(t,e,o=""){return typeof t!="object"||t===null?t:new Proxy(t,{get:(s,n)=>{if(typeof n=="symbol"||n==="__proto__")return s[n];const r=o?`${o}.${n}`:n;e.add(r);const c=s[n];return typeof c=="object"&&c!==null?this._createAccessTrackingProxy(c,e,r):c}})}get memory(){const t=M();if(!t)return this._memory;this._listeners.has(t)||this._listeners.set(t,new Set);const e=this._listeners.get(t);return this._createAccessTrackingProxy(this._memory,e)}},a.css=function(t,...e){let o="",s=!1;Array.isArray(t)&&t.raw?o=t.reduce((i,l,u)=>i+l+(e[u]||""),""):(o=t,s=e[0]===!0);let n=(function(i){return i.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim()})(o);if(!n)return"";s&&(n=n.replace(/(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi,"$1$2$3&, $3"));const r=(function(i){let l=5381,u=i.length;for(;u;)l=33*l^i.charCodeAt(--u);return(l>>>0).toString(36)})(n),c=`humn-${r}`;return N.has(r)||(p||(p=document.createElement("style"),p.id="humn-styles",document.head.appendChild(p)),p.textContent+=`.${c} {
|
|
2
2
|
${n}
|
|
3
3
|
}
|
|
4
|
-
`,
|
|
4
|
+
`,N.add(r)),c},a.h=(t,e={},o=[])=>({tag:t,props:e,children:(Array.isArray(o)?o:[o]).flat().filter(s=>s!=null&&s!==!1&&s!=="")}),a.mount=(t,e)=>{let o=null;const s=()=>{E(s);const n={tag:e,props:{},children:[]};_(t,n,o),E(null),o=n};s()},a.onCleanup=function(t){const e=x();e&&e.cleanups.push(t)},a.onMount=function(t){const e=x();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
|
package/dist/humn.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\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\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\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 const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (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 tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - 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(element, newProps = {}, oldProps = {}) {\n if (!element) 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 element.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 (element[key] !== newValue) {\n element[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) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.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 element = 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 (element && domChildAtIndex !== element) {\n parent.insertBefore(element, 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 newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\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, getNamespace(parent)))\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, getNamespace(parent)), 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 * Represents a value wrapped by the persist() function.\n * @template T\n * @typedef {object} Persisted\n * @property {T} initial\n * @property {boolean} __humn_persist\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 * @template T\n * @param {T} initial\n * @param {PersistConfig} [config]\n * @returns {Persisted<T>}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n","import { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * Mapped type for the Memory configuration object.\n * Allows each property to be the raw value OR a persisted wrapper.\n * @template T\n * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput\n */\n\n/**\n * Deeply unwraps persisted values from the memory shape.\n * @template {object} T\n * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory\n */\n\n/**\n * @template T\n * @callback Getter\n * @returns {T}\n */\n\n/**\n * @template T\n * @callback Setter\n * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater\n * @returns {void}\n */\n\n/**\n * @template M, S\n * @callback SynapsesBuilder\n * @param {Setter<M>} set\n * @param {Getter<M>} get\n * @returns {S}\n */\n\n/**\n * @template M, S\n * @typedef {object} CortexConfig\n * @property {MemoryInput<M>} memory - The initial state configuration\n * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function\n */\n\n/**\n * The Cortex class manages the state of the application.\n *\n * @template {object} MemoryType The shape of the application state\n * @template {object} SynapsesType The shape of the actions/methods\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexConfig<MemoryType, SynapsesType>} config\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 && typeof value === 'object' && 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 /** @type {UnwrappedMemory<MemoryType>} */\n this._memory = liveMemory\n this._listeners = new Map()\n\n /** @type {Getter<UnwrappedMemory<MemoryType>>} */\n const get = () => this._memory\n\n /** @type {Setter<UnwrappedMemory<MemoryType>>} */\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 // Persistence logic\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 /** @type {SynapsesType} */\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 {UnwrappedMemory<MemoryType>}\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 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","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","children","some","c","props","key","createElement","vNode","namespace","document","createTextNode","String","tag","childVNode","renderComponent","child","el","hooks","mounts","length","setTimeout","forEach","fn","element","createElementNS","patchProps","childNS","appendChild","newProps","oldProps","allProps","oldValue","newValue","startsWith","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","i","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","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","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,WAAAH,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,IAC1BJ,EAAkBI,CAAAA,EAOPC,EAAc,IAAMJ,EAMpBK,EAAeC,GAAAA,CAC1BN,EAAkBM,CAAAA,EC5BpB,IAAIC,EAAa,KACjB,MAAMC,EAAQ,IAAIC,ICElB,SAASC,EAAaC,EAAAA,CACpB,OAAIA,EAAOC,eAAiBC,GAAUF,EAAOG,UAAY,gBAChDD,EAELF,EAAOC,eAAiBG,EACnBA,EAEF,IACT,CAOO,SAASC,EAAQC,EAAAA,CACtB,OAAOA,GAAYA,EAASC,KAAMC,GAAMA,GAAKA,EAAEC,OAASD,EAAEC,MAAMC,KAAO,IAAPA,CAClE,CAEA,MAAMR,EAAS,6BACTE,EAAU,qCAOhB,SAASO,EAAcC,EAAOC,EAAAA,CAC5B,GAAqB,OAAVD,GAAU,UAA6B,OAAVA,GAAU,SAChD,OAAOE,SAASC,eAAeC,OAAOJ,CAAAA,CAAAA,EAGxC,GAAyB,OAAdA,EAAMK,KAAQ,WAAY,CACnC,MAAMC,EAAaC,EAAgBP,CAAAA,EACnCA,EAAMQ,MAAQF,EAEd,MAAMG,EAAKV,EAAcO,EAAYL,CAAAA,EAMrC,OAJAD,EAAMS,GAAKA,EACPT,EAAMU,OAAOC,OAAOC,OAA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I,KAAK9G,YAAYpC,CAAAA,GAG5BA,EAAWmJ,aAAe,IAAIH,CAAAA;AAAAA,MAC1BN,CAAAA;AAAAA;AAAAA,EAEJzI,EAAM2G,IAAIiC,CAAAA,GAZDG,CAeX,EErEChK,EAAAoK,EETgB,CAAC/H,EAAKR,EAAQ,CAAA,EAAIH,EAAW,CAAA,KAQrC,CACLW,MACAR,MAAAA,EACAH,UAViBqG,MAAMuB,QAAQ5H,GAAYA,EAAW,CAACA,CAAAA,GAItD2I,KAAAA,EACAC,OAAQ1I,GAAMA,GAAAA,MAAiCA,IAAjCA,IAAgDA,IAAM,EAANA,CAAAA,GFGlE5B,EAAAuK,MGboB,CAAC/B,EAAQgC,IAAAA,CAC5B,IAAIC,EAAY,KAEhB,MAAMC,EAAY,IAAA,CAChB/J,EAAY+J,GAEZ,MAAMC,EAAY,CAChBtI,IAAKmI,EACL3I,MAAO,CAAA,EACPH,SAAU,IAGZgD,EAAM8D,EAAQmC,EAAWF,CAAAA,EACzB9J,EAAY,IAAA,EACZ8J,EAAYE,CAAAA,EAGdD,EAAAA,CAAAA,EHJD1K,EAAA4K,UIJM,SAAmB7H,EAAAA,CACxB,MAAM8H,EAAWhK,EAAAA,EACbgK,GACFA,EAASpF,SAASqF,KAAK/H,CAAAA,CAE3B,EJDC/C,EAAA+K,QIfM,SAAiBhI,EAAAA,CACtB,MAAM8H,EAAWhK,IACbgK,GACFA,EAASlI,OAAOmI,KAAK/H,EAEzB,EJUC/C,EAAAgL,QAJsB,CAAC/D,EAASP,EAAS,MAAE,CAC1CF,kBACAS,QAAAA,EACAP,OAAAA,CAAAA,GACDtB,OAAA6F,eAAAjL,EAAAkL,OAAAC,YAAA,CAAA7E,MAAA,QAAA,CAAA,CAAA,CAAA"}
|
|
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\nfunction invokeHookSafely(fn, errorMessage) {\n try {\n fn()\n } catch (error) {\n console.error(errorMessage, error)\n }\n}\n\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\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\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\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 const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (vNode.hooks?.mounts.length > 0) {\n setTimeout(() => {\n vNode.hooks.mounts.forEach((fn) => {\n invokeHookSafely(fn, 'Error in mount hook:')\n })\n }, 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - 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(element, newProps = {}, oldProps = {}) {\n if (!element) 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 element.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 (element[key] !== newValue) {\n element[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) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.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 element = 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 (element && domChildAtIndex !== element) {\n parent.insertBefore(element, 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 newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\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) => {\n invokeHookSafely(fn, 'Error in cleanup hook:')\n })\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 const hasPreviousHooks = Boolean(oldVNode?.hooks?.cleanups?.length)\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) => {\n invokeHookSafely(fn, 'Error in mount hook:')\n })\n }, 0)\n }\n\n if (!isNew && hasPreviousHooks) {\n oldVNode.hooks.cleanups.forEach((fn) => {\n invokeHookSafely(fn, 'Error in cleanup hook:')\n })\n\n if (newVNode.hooks?.mounts?.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => {\n invokeHookSafely(fn, 'Error in mount hook:')\n })\n }, 0)\n }\n }\n\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, getNamespace(parent)))\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, getNamespace(parent)), 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 * Represents a value wrapped by the persist() function.\n * @template T\n * @typedef {object} Persisted\n * @property {T} initial\n * @property {boolean} __humn_persist\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 * @template T\n * @param {T} initial\n * @param {PersistConfig} [config]\n * @returns {Persisted<T>}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n","import { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * Mapped type for the Memory configuration object.\n * Allows each property to be the raw value OR a persisted wrapper.\n * @template T\n * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput\n */\n\n/**\n * Deeply unwraps persisted values from the memory shape.\n * @template {object} T\n * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory\n */\n\n/**\n * @template T\n * @callback Getter\n * @returns {T}\n */\n\n/**\n * @template T\n * @callback Setter\n * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater\n * @returns {void}\n */\n\n/**\n * @template M, S\n * @callback SynapsesBuilder\n * @param {Setter<M>} set\n * @param {Getter<M>} get\n * @returns {S}\n */\n\n/**\n * @template M, S\n * @typedef {object} CortexConfig\n * @property {MemoryInput<M>} memory - The initial state configuration\n * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function\n */\n\n/**\n * The Cortex class manages the state of the application.\n *\n * @template {object} MemoryType The shape of the application state\n * @template {object} SynapsesType The shape of the actions/methods\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexConfig<MemoryType, SynapsesType>} config\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 && typeof value === 'object' && 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 /** @type {UnwrappedMemory<MemoryType>} */\n this._memory = liveMemory\n this._listeners = new Map()\n\n /** @type {Getter<UnwrappedMemory<MemoryType>>} */\n const get = () => this._memory\n\n /** @type {Setter<UnwrappedMemory<MemoryType>>} */\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 // Persistence logic\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 /** @type {SynapsesType} */\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 {UnwrappedMemory<MemoryType>}\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 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","invokeHookSafely","fn","errorMessage","error","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","children","some","c","props","key","createElement","vNode","namespace","document","createTextNode","String","tag","childVNode","renderComponent","child","el","hooks","mounts","length","setTimeout","forEach","element","createElementNS","patchProps","childNS","appendChild","newProps","oldProps","allProps","oldValue","newValue","startsWith","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","i","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","Object","values","parentNode","runUnmount","removeChild","cleanups","renderedVNode","newVNode","isNew","hasPreviousHooks","Boolean","replaceChild","nodeValue","Cortex","constructor","memory","synapses","liveMemory","_persistenceMap","Map","value","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","err","_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","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,UAAA,OAAAC,OAAA,IAAAF,EAAAC,OAAAA,EAAA,OAAAE,QAAA,YAAAA,OAAAC,IAAAD,OAAA,CAAA,SAAA,EAAAH,GAAAA,GAAAD,EAAA,OAAAM,WAAA,IAAAA,WAAAN,GAAAO,MAAAC,KAAA,CAAA,EAAA,GAAAC,KAAA,SAAAP,GAAA,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,ICElB,SAASC,EAAiBC,EAAIC,EAAAA,CAC5B,GAAA,CACED,EAAAA,CACF,MAASE,CAET,CACF,CAEA,SAASC,EAAaC,EAAAA,CACpB,OAAIA,EAAOC,eAAiBC,GAAUF,EAAOG,UAAY,gBAChDD,EAELF,EAAOC,eAAiBG,EACnBA,EAEF,IACT,CAOO,SAASC,EAAQC,EAAAA,CACtB,OAAOA,GAAYA,EAASC,KAAMC,GAAMA,GAAKA,EAAEC,OAASD,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