humn 1.6.0 → 1.6.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 CHANGED
@@ -1,33 +1,33 @@
1
- let $ = null, O = null;
2
- const j = () => $;
3
- function D(e) {
1
+ let O = null, j = null;
2
+ const D = () => O;
3
+ function F(e) {
4
4
  const t = e?.__humnCortexes;
5
5
  t && (t.forEach((n) => n._listeners.delete(e)), t.clear());
6
6
  }
7
- const v = (e) => {
8
- $ = e;
9
- }, K = () => O, H = (e) => {
7
+ const I = (e) => {
10
8
  O = e;
11
- }, _ = /* @__PURE__ */ new Set();
12
- let M = !1;
13
- function q(e) {
14
- _.add(e), F();
9
+ }, x = () => j, v = (e) => {
10
+ j = e;
11
+ }, C = /* @__PURE__ */ new Set();
12
+ let k = !1;
13
+ function J(e) {
14
+ C.add(e), W();
15
15
  }
16
- function F() {
17
- M || (M = !0, queueMicrotask(G));
16
+ function W() {
17
+ k || (k = !0, queueMicrotask(Q));
18
18
  }
19
- function G() {
20
- M = !1;
21
- const e = Array.from(_);
22
- _.clear(), e.forEach((t) => t()), _.size > 0 && F();
19
+ function Q() {
20
+ k = !1;
21
+ const e = Array.from(C);
22
+ C.clear(), e.forEach((t) => t()), C.size > 0 && W();
23
23
  }
24
- class He {
24
+ class Te {
25
25
  /**
26
26
  * Creates an instance of Cortex.
27
27
  * @param {CortexConfig<MemoryType, SynapsesType>} config
28
28
  */
29
29
  constructor({ memory: t, synapses: n }) {
30
- const o = { ...t };
30
+ const i = { ...t };
31
31
  this._persistenceMap = /* @__PURE__ */ new Map();
32
32
  for (const [s, c] of Object.entries(t))
33
33
  if (c && typeof c == "object" && c.__humn_persist) {
@@ -35,13 +35,13 @@ class He {
35
35
  this._persistenceMap.set(s, u);
36
36
  try {
37
37
  const a = localStorage.getItem(u);
38
- a !== null ? o[s] = JSON.parse(a) : o[s] = c.initial;
38
+ a !== null ? i[s] = JSON.parse(a) : i[s] = c.initial;
39
39
  } catch {
40
- o[s] = c.initial;
40
+ i[s] = c.initial;
41
41
  }
42
42
  }
43
- this._memory = o, this._listeners = /* @__PURE__ */ new Map();
44
- const r = () => this._memory, i = (s) => {
43
+ this._memory = i, this._listeners = /* @__PURE__ */ new Map();
44
+ const o = () => this._memory, r = (s) => {
45
45
  let c, u = /* @__PURE__ */ new Set();
46
46
  if (typeof s == "function") {
47
47
  const a = this._createMutationDraft(this._memory, u), f = s(a.memory);
@@ -59,50 +59,50 @@ class He {
59
59
  }
60
60
  }), this._notifyRelevantListeners(u);
61
61
  };
62
- this.synapses = n(i, r);
62
+ this.synapses = n(r, o);
63
63
  }
64
64
  /**
65
65
  * Creates a copy-on-write mutation draft that tracks changed paths without
66
66
  * cloning the whole store before every mutative update.
67
67
  */
68
68
  _createMutationDraft(t, n) {
69
- const o = /* @__PURE__ */ new WeakMap(), r = ({ parent: s, parentProp: c, target: u }) => {
70
- const a = o.get(u);
69
+ const i = /* @__PURE__ */ new WeakMap(), o = ({ parent: s, parentProp: c, target: u }) => {
70
+ const a = i.get(u);
71
71
  if (a) return a;
72
72
  const f = Array.isArray(u) ? u.slice() : { ...u };
73
- return o.set(u, f), s && (r(s)[c] = f), f;
74
- }, i = (s, c = "", u = null, a = null) => new Proxy(s, {
73
+ return i.set(u, f), s && (o(s)[c] = f), f;
74
+ }, r = (s, c = "", u = null, a = null) => new Proxy(s, {
75
75
  deleteProperty: (d, l) => {
76
- const g = r({ parent: u, parentProp: a, target: d });
77
- return delete g[l], typeof l != "symbol" && n.add(c ? `${c}.${l}` : String(l)), !0;
76
+ const b = o({ parent: u, parentProp: a, target: d });
77
+ return delete b[l], typeof l != "symbol" && n.add(c ? `${c}.${l}` : String(l)), !0;
78
78
  },
79
79
  get: (d, l) => {
80
- const h = (o.get(d) || d)[l];
80
+ const h = (i.get(d) || d)[l];
81
81
  if (typeof l == "symbol" || l === "__proto__" || typeof h != "object" || h === null) return h;
82
- const z = c ? `${c}.${l}` : String(l);
83
- return i(
82
+ const G = c ? `${c}.${l}` : String(l);
83
+ return r(
84
84
  h,
85
- z,
85
+ G,
86
86
  { parent: u, parentProp: a, target: d },
87
87
  l
88
88
  );
89
89
  },
90
- set: (d, l, g) => {
91
- const h = r({ parent: u, parentProp: a, target: d });
92
- return h[l] = g, typeof l != "symbol" && n.add(c ? `${c}.${l}` : String(l)), !0;
90
+ set: (d, l, b) => {
91
+ const h = o({ parent: u, parentProp: a, target: d });
92
+ return h[l] = b, typeof l != "symbol" && n.add(c ? `${c}.${l}` : String(l)), !0;
93
93
  }
94
94
  });
95
95
  return {
96
- getNextState: () => o.get(t) || t,
97
- memory: i(t)
96
+ getNextState: () => i.get(t) || t,
97
+ memory: r(t)
98
98
  };
99
99
  }
100
100
  /**
101
101
  * Only notify listeners that read properties which changed
102
102
  */
103
103
  _notifyRelevantListeners(t) {
104
- Array.from(this._listeners.entries()).forEach(([o, r]) => {
105
- Array.from(r).some((s) => Array.from(t).some((c) => s === c || s.startsWith(c + ".") || c.startsWith(s + "."))) && q(o);
104
+ Array.from(this._listeners.entries()).forEach(([i, o]) => {
105
+ Array.from(o).some((s) => Array.from(t).some((c) => s === c || s.startsWith(c + ".") || c.startsWith(s + "."))) && J(i);
106
106
  });
107
107
  }
108
108
  /**
@@ -113,14 +113,14 @@ class He {
113
113
  * `state.user.name`, it will only re-render when `state.user.name` changes,
114
114
  * not when `state.count` changes.
115
115
  */
116
- _createAccessTrackingProxy(t, n, o = "") {
116
+ _createAccessTrackingProxy(t, n, i = "") {
117
117
  return typeof t != "object" || t === null ? t : new Proxy(t, {
118
- get: (r, i) => {
119
- if (typeof i == "symbol" || i === "__proto__")
120
- return r[i];
121
- const s = o ? `${o}.${i}` : i;
118
+ get: (o, r) => {
119
+ if (typeof r == "symbol" || r === "__proto__")
120
+ return o[r];
121
+ const s = i ? `${i}.${r}` : r;
122
122
  n.add(s);
123
- const c = r[i];
123
+ const c = o[r];
124
124
  return typeof c == "object" && c !== null ? this._createAccessTrackingProxy(c, n, s) : c;
125
125
  }
126
126
  });
@@ -129,7 +129,7 @@ class He {
129
129
  * @returns {UnwrappedMemory<MemoryType>}
130
130
  */
131
131
  get memory() {
132
- const t = j();
132
+ const t = D();
133
133
  if (!t) return this._memory;
134
134
  this._listeners.has(t) || this._listeners.set(t, /* @__PURE__ */ new Set()), t.__humnCortexes || (t.__humnCortexes = /* @__PURE__ */ new Set()), t.__humnCortexes.add(this);
135
135
  const n = this._listeners.get(t);
@@ -137,91 +137,91 @@ class He {
137
137
  }
138
138
  }
139
139
  let y = null;
140
- const L = /* @__PURE__ */ new Set();
141
- function J(e) {
140
+ const H = /* @__PURE__ */ new Set();
141
+ function Y(e) {
142
142
  let t = 5381, n = e.length;
143
143
  for (; n; )
144
144
  t = t * 33 ^ e.charCodeAt(--n);
145
145
  return (t >>> 0).toString(36);
146
146
  }
147
- function Q(e) {
147
+ function X(e) {
148
148
  return e.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").trim();
149
149
  }
150
- function Le(e, ...t) {
151
- let n = "", o = !1;
152
- Array.isArray(e) && e.raw ? n = e.reduce((c, u, a) => c + u + (t[a] || ""), "") : (n = e, o = t[0] === !0);
153
- let r = Q(n);
154
- if (!r) return "";
155
- o && (r = r.replace(
150
+ function Re(e, ...t) {
151
+ let n = "", i = !1;
152
+ Array.isArray(e) && e.raw ? n = e.reduce((c, u, a) => c + u + (t[a] || ""), "") : (n = e, i = t[0] === !0);
153
+ let o = X(n);
154
+ if (!o) return "";
155
+ i && (o = o.replace(
156
156
  /(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi,
157
157
  "$1$2$3&, $3"
158
158
  ));
159
- const i = J(r), s = `humn-${i}`;
160
- return L.has(i) || (y || (y = document.createElement("style"), y.id = "humn-styles", document.head.appendChild(y)), y.textContent += `.${s} {
161
- ${r}
159
+ const r = Y(o), s = `humn-${r}`;
160
+ return H.has(r) || (y || (y = document.createElement("style"), y.id = "humn-styles", document.head.appendChild(y)), y.textContent += `.${s} {
161
+ ${o}
162
162
  }
163
- `, L.add(i)), s;
163
+ `, H.add(r)), s;
164
164
  }
165
- const Te = (e, t = {}, n = []) => {
166
- const r = (Array.isArray(n) ? n : [n]).flat().filter((i) => i != null && i !== !1 && i !== "");
165
+ const $e = (e, t = {}, n = []) => {
166
+ const o = (Array.isArray(n) ? n : [n]).flat().filter((r) => r != null && r !== !1 && r !== "");
167
167
  return {
168
168
  tag: e,
169
169
  props: t,
170
- children: r
170
+ children: o
171
171
  };
172
172
  };
173
- function Y(e) {
173
+ function Z(e) {
174
174
  if (typeof e != "object" || e === null) return e;
175
175
  const t = Array.isArray(e.children) ? e.children : [];
176
176
  return {
177
177
  tag: e.tag,
178
178
  props: { ...e.props },
179
- children: t.map(Y)
179
+ children: t.map(Z)
180
180
  };
181
181
  }
182
- function Re(e) {
183
- const t = K();
182
+ function Oe(e) {
183
+ const t = x();
184
184
  t && t.mounts.push(e);
185
185
  }
186
- function $e(e) {
187
- const t = K();
186
+ function je(e) {
187
+ const t = x();
188
188
  t && t.cleanups.push(e);
189
189
  }
190
- function W(e, t) {
190
+ function B(e, t) {
191
191
  try {
192
192
  e();
193
193
  } catch (n) {
194
194
  console.error(t, n);
195
195
  }
196
196
  }
197
- function N(e, t) {
198
- const n = { mounts: [], cleanups: [] }, o = K(), r = j();
199
- D(t), v(t), H(n);
197
+ function w(e, t) {
198
+ const n = { mounts: [], cleanups: [] }, i = x(), o = D();
199
+ F(t), I(t), v(n);
200
200
  try {
201
- const i = e.tag(e.props);
202
- return e.hooks = n, i;
201
+ const r = e.tag(e.props);
202
+ return e.hooks = n, r;
203
203
  } finally {
204
- H(o), v(r);
204
+ v(i), I(o);
205
205
  }
206
206
  }
207
- function b(e) {
208
- e && (D(e.instance?.update), e.instance && (e.instance.isMounted = !1, e.instance.parent = null, e.instance.vNode = null), e.hooks?.cleanups && e.hooks.cleanups.forEach(
209
- (t) => W(t, "Error in cleanup hook:")
210
- ), e.child && b(e.child), e.children && e.children.forEach(b));
207
+ function g(e) {
208
+ e && (F(e.instance?.update), e.instance && (e.instance.isMounted = !1, e.instance.parent = null, e.instance.vNode = null), e.hooks?.cleanups && e.hooks.cleanups.forEach(
209
+ (t) => B(t, "Error in cleanup hook:")
210
+ ), e.child && g(e.child), e.children && e.children.forEach(g));
211
211
  }
212
- function X(e) {
212
+ function P(e) {
213
213
  e?.mounts?.length && setTimeout(
214
214
  () => e.mounts.forEach(
215
- (t) => W(t, "Error in mount hook:")
215
+ (t) => B(t, "Error in mount hook:")
216
216
  ),
217
217
  0
218
218
  );
219
219
  }
220
- function Z({ newHooks: e, oldHooks: t }) {
220
+ function N({ newHooks: e, oldHooks: t }) {
221
221
  }
222
- const T = /* @__PURE__ */ new WeakMap();
222
+ const L = /* @__PURE__ */ new WeakMap();
223
223
  function p(e) {
224
- const t = T.get(e);
224
+ const t = L.get(e);
225
225
  if (t) return t;
226
226
  const n = {
227
227
  asyncPending: /* @__PURE__ */ new Map(),
@@ -230,56 +230,56 @@ function p(e) {
230
230
  debounceTimers: /* @__PURE__ */ new Map(),
231
231
  listeners: /* @__PURE__ */ new Map()
232
232
  };
233
- return T.set(e, n), n;
233
+ return L.set(e, n), n;
234
234
  }
235
- const P = /* @__PURE__ */ new Set([
235
+ const V = /* @__PURE__ */ new Set([
236
236
  "prevent",
237
237
  "stop",
238
238
  "once",
239
239
  "capture",
240
240
  "passive"
241
241
  ]);
242
- function V(e) {
243
- const [t, ...n] = e.split("|"), o = n.filter(
244
- (r) => P.has(r)
242
+ function ee(e) {
243
+ const [t, ...n] = e.split("|"), i = n.filter(
244
+ (o) => V.has(o)
245
245
  );
246
- return { eventKey: t, modifiers: o };
246
+ return { eventKey: t, modifiers: i };
247
247
  }
248
248
  function m({
249
249
  element: e,
250
250
  eventName: t,
251
251
  listener: n,
252
- options: o = !1,
253
- propKey: r
252
+ options: i = !1,
253
+ propKey: o
254
254
  }) {
255
- const { listeners: i } = p(e);
256
- C(e, r), e.addEventListener(t, n, o), i.set(r, { eventName: t, listener: n, options: o });
255
+ const { listeners: r } = p(e);
256
+ E(e, o), e.addEventListener(t, n, i), r.set(o, { eventName: t, listener: n, options: i });
257
257
  }
258
- function C(e, t) {
259
- const { listeners: n } = p(e), o = n.get(t);
260
- if (!o) return;
261
- const { eventName: r, listener: i, options: s } = o;
262
- e.removeEventListener(r, i, s), n.delete(t);
258
+ function E(e, t) {
259
+ const { listeners: n } = p(e), i = n.get(t);
260
+ if (!i) return;
261
+ const { eventName: o, listener: r, options: s } = i;
262
+ e.removeEventListener(o, r, s), n.delete(t);
263
263
  }
264
- const ee = /* @__PURE__ */ new Set(["onenter", "onescape", "onkeys", "oncommit"]), te = [
264
+ const te = /* @__PURE__ */ new Set(["onenter", "onescape", "onkeys", "oncommit"]), ne = [
265
265
  "__compositionstart",
266
266
  "__compositionend",
267
267
  "__keyhelper",
268
268
  "__oncommitblur"
269
269
  ];
270
- function ne(e) {
271
- return ee.has(e);
270
+ function ie(e) {
271
+ return te.has(e);
272
272
  }
273
- function B(e) {
273
+ function U(e) {
274
274
  const { debounceTimers: t } = p(e), n = t.get("oninputdebounced");
275
- n && clearTimeout(n), t.delete("oninputdebounced"), C(e, "oninputdebounced");
275
+ n && clearTimeout(n), t.delete("oninputdebounced"), E(e, "oninputdebounced");
276
276
  }
277
- function oe(e, t) {
277
+ function re(e, t) {
278
278
  if (!t.oninputdebounced) {
279
- B(e);
279
+ U(e);
280
280
  return;
281
281
  }
282
- const { debounceTimers: n } = p(e), o = Number(t.debounce), r = Number.isFinite(o) ? o : 250;
282
+ const { debounceTimers: n } = p(e), i = Number(t.debounce), o = Number.isFinite(i) ? i : 250;
283
283
  m({
284
284
  element: e,
285
285
  eventName: "input",
@@ -292,22 +292,22 @@ function oe(e, t) {
292
292
  currentTarget: e,
293
293
  target: e
294
294
  });
295
- }, r);
295
+ }, o);
296
296
  n.set("oninputdebounced", u);
297
297
  },
298
298
  propKey: "oninputdebounced"
299
299
  });
300
300
  }
301
- function re(e, t) {
302
- if (!ce(t)) {
303
- se(e);
301
+ function oe(e, t) {
302
+ if (!ue(t)) {
303
+ ce(e);
304
304
  return;
305
305
  }
306
- const n = p(e), o = ue({ element: e, newProps: t, runtime: n }), r = le({ newProps: t, runtime: n }), i = () => n.composition.set("active", !0), s = () => n.composition.set("active", !1);
306
+ const n = p(e), i = le({ element: e, newProps: t, runtime: n }), o = ae({ newProps: t, runtime: n }), r = () => n.composition.set("active", !0), s = () => n.composition.set("active", !1);
307
307
  m({
308
308
  element: e,
309
309
  eventName: "compositionstart",
310
- listener: i,
310
+ listener: r,
311
311
  propKey: "__compositionstart"
312
312
  }), m({
313
313
  element: e,
@@ -317,155 +317,155 @@ function re(e, t) {
317
317
  }), m({
318
318
  element: e,
319
319
  eventName: "keydown",
320
- listener: o,
320
+ listener: i,
321
321
  propKey: "__keyhelper"
322
322
  }), m({
323
323
  element: e,
324
324
  eventName: "blur",
325
- listener: r,
325
+ listener: o,
326
326
  propKey: "__oncommitblur"
327
327
  });
328
328
  }
329
- function ie({ element: e, handler: t, newProps: n, propKey: o }) {
330
- const { asyncPending: r } = p(e);
329
+ function se({ element: e, handler: t, newProps: n, propKey: i }) {
330
+ const { asyncPending: o } = p(e);
331
331
  m({
332
332
  element: e,
333
333
  eventName: "click",
334
334
  listener: async (s) => {
335
- if (!(n.disabledwhilepending && r.get("click")))
335
+ if (!(n.disabledwhilepending && o.get("click")))
336
336
  try {
337
- r.set("click", !0), n.disabledwhilepending && (e.disabled = !0), await t(s);
337
+ o.set("click", !0), n.disabledwhilepending && (e.disabled = !0), await t(s);
338
338
  } finally {
339
- r.set("click", !1), n.disabledwhilepending && (e.disabled = !1);
339
+ o.set("click", !1), n.disabledwhilepending && (e.disabled = !1);
340
340
  }
341
341
  },
342
- propKey: o
342
+ propKey: i
343
343
  });
344
344
  }
345
- function se(e) {
346
- te.forEach(
347
- (t) => C(e, t)
345
+ function ce(e) {
346
+ ne.forEach(
347
+ (t) => E(e, t)
348
348
  );
349
349
  }
350
- function ce(e) {
350
+ function ue(e) {
351
351
  return !!(e.onenter || e.onescape || e.onkeys || e.oncommit);
352
352
  }
353
- function ue({ element: e, newProps: t, runtime: n }) {
354
- return (o) => {
355
- const r = n.composition.get("active") === !0;
356
- if (me(o, r)) return;
357
- const i = fe(o);
358
- o.key === "Enter" && t.onenter && t.onenter(o), o.key === "Escape" && t.onescape && t.onescape(o), t.onkeys && ae(o, i, t.onkeys), !(o.key !== "Enter" || !t.oncommit) && (n.commitLocks.set("enter", !0), t.oncommit(o), setTimeout(() => n.commitLocks.delete("enter"), 0));
353
+ function le({ element: e, newProps: t, runtime: n }) {
354
+ return (i) => {
355
+ const o = n.composition.get("active") === !0;
356
+ if (pe(i, o)) return;
357
+ const r = de(i);
358
+ i.key === "Enter" && t.onenter && t.onenter(i), i.key === "Escape" && t.onescape && t.onescape(i), t.onkeys && fe(i, r, t.onkeys), !(i.key !== "Enter" || !t.oncommit) && (n.commitLocks.set("enter", !0), t.oncommit(i), setTimeout(() => n.commitLocks.delete("enter"), 0));
359
359
  };
360
360
  }
361
- function le({ newProps: e, runtime: t }) {
361
+ function ae({ newProps: e, runtime: t }) {
362
362
  return (n) => {
363
363
  e.oncommit && (t.commitLocks.get("enter") || e.oncommit(n));
364
364
  };
365
365
  }
366
- function ae(e, t, n) {
367
- Object.entries(n).forEach(([o, r]) => {
368
- de(o) === t && r(e);
366
+ function fe(e, t, n) {
367
+ Object.entries(n).forEach(([i, o]) => {
368
+ he(i) === t && o(e);
369
369
  });
370
370
  }
371
- function fe(e) {
371
+ function de(e) {
372
372
  const t = [];
373
373
  return e.ctrlKey && t.push("ctrl"), e.metaKey && t.push("meta"), e.altKey && t.push("alt"), e.shiftKey && t.push("shift"), t.push(e.key.toLowerCase()), t.sort().join("+");
374
374
  }
375
- function de(e = "") {
376
- return e.split("+").map((t) => t.trim().toLowerCase()).filter(Boolean).map((t) => he(t)).sort().join("+");
375
+ function he(e = "") {
376
+ return e.split("+").map((t) => t.trim().toLowerCase()).filter(Boolean).map((t) => me(t)).sort().join("+");
377
377
  }
378
- function he(e) {
378
+ function me(e) {
379
379
  return e !== "mod" ? e : navigator.platform.includes("Mac") ? "meta" : "ctrl";
380
380
  }
381
- function me(e, t) {
381
+ function pe(e, t) {
382
382
  return e.isComposing || t === !0;
383
383
  }
384
- function U(e, t = {}, n = {}) {
384
+ function z(e, t = {}, n = {}) {
385
385
  if (!e) return;
386
- const o = { ...n, ...t };
387
- for (const r in o)
388
- pe({ element: e, key: r, newProps: t, oldProps: n });
389
- oe(e, t), re(e, t);
390
- }
391
- function pe({ element: e, key: t, newProps: n, oldProps: o }) {
392
- const r = o[t], i = n[t];
393
- if (i == null) {
394
- ye({ element: e, key: t });
386
+ const i = { ...n, ...t };
387
+ for (const o in i)
388
+ ye({ element: e, key: o, newProps: t, oldProps: n });
389
+ re(e, t), oe(e, t);
390
+ }
391
+ function ye({ element: e, key: t, newProps: n, oldProps: i }) {
392
+ const o = i[t], r = n[t];
393
+ if (r == null) {
394
+ ge({ element: e, key: t });
395
395
  return;
396
396
  }
397
397
  if (t === "value" || t === "checked") {
398
- ge({ element: e, key: t, value: i });
398
+ _e({ element: e, key: t, value: r });
399
399
  return;
400
400
  }
401
- if (!(r === i && t !== "onclickasync")) {
401
+ if (!(o === r && t !== "onclickasync")) {
402
402
  if (t.startsWith("on")) {
403
- _e({ element: e, handler: i, key: t, newProps: n });
403
+ be({ element: e, handler: r, key: t, newProps: n });
404
404
  return;
405
405
  }
406
406
  if (t !== "debounce") {
407
407
  if (t === "disabled") {
408
- e.disabled = i === !0 || i === "true";
408
+ e.disabled = r === !0 || r === "true";
409
409
  return;
410
410
  }
411
- e.setAttribute(t, i);
411
+ e.setAttribute(t, r);
412
412
  }
413
413
  }
414
414
  }
415
- function ye({ element: e, key: t }) {
416
- t.startsWith("on") && C(e, t), t === "oninputdebounced" && B(e), e.removeAttribute(t);
415
+ function ge({ element: e, key: t }) {
416
+ t.startsWith("on") && E(e, t), t === "oninputdebounced" && U(e), e.removeAttribute(t);
417
417
  }
418
- function ge({ element: e, key: t, value: n }) {
418
+ function _e({ element: e, key: t, value: n }) {
419
419
  e[t] !== n && (e[t] = n);
420
420
  }
421
- function _e({ element: e, handler: t, key: n, newProps: o }) {
422
- const { eventKey: r, modifiers: i } = V(n), s = r.slice(2).toLowerCase();
423
- if (ne(r) || r === "oninputdebounced") return;
424
- if (r === "onclickasync") {
425
- ie({ element: e, handler: t, newProps: o, propKey: n });
421
+ function be({ element: e, handler: t, key: n, newProps: i }) {
422
+ const { eventKey: o, modifiers: r } = ee(n), s = o.slice(2).toLowerCase();
423
+ if (ie(o) || o === "oninputdebounced") return;
424
+ if (o === "onclickasync") {
425
+ se({ element: e, handler: t, newProps: i, propKey: n });
426
426
  return;
427
427
  }
428
428
  m({
429
429
  element: e,
430
430
  eventName: s,
431
- listener: (u) => (i.includes("prevent") && u.preventDefault(), i.includes("stop") && u.stopPropagation(), t(u)),
431
+ listener: (u) => (r.includes("prevent") && u.preventDefault(), r.includes("stop") && u.stopPropagation(), t(u)),
432
432
  options: {
433
- capture: i.includes("capture"),
434
- once: i.includes("once"),
435
- passive: i.includes("passive")
433
+ capture: r.includes("capture"),
434
+ once: r.includes("once"),
435
+ passive: r.includes("passive")
436
436
  },
437
437
  propKey: n
438
438
  });
439
439
  }
440
- const S = "http://www.w3.org/2000/svg", x = "http://www.w3.org/1998/Math/MathML";
441
- function A(e) {
442
- return e.namespaceURI === S && e.tagName !== "foreignObject" ? S : e.namespaceURI === x ? x : null;
440
+ const M = "http://www.w3.org/2000/svg", S = "http://www.w3.org/1998/Math/MathML";
441
+ function T(e) {
442
+ return e.namespaceURI === M && e.tagName !== "foreignObject" ? M : e.namespaceURI === S ? S : null;
443
443
  }
444
- function E(e, t, n = null, o = 0) {
444
+ function A(e, t, n = null, i = 0) {
445
445
  if (typeof e == "string" || typeof e == "number")
446
446
  return document.createTextNode(String(e));
447
447
  if (typeof e.tag == "function")
448
- return be({ index: o, namespace: t, parent: n, vNode: e });
449
- const r = e.tag, i = ke(r, t), s = i ? document.createElementNS(i, r) : document.createElement(r);
450
- return e.el = s, U(s, e.props), Ee({ element: s, namespace: i, tag: r, vNode: e }), s;
448
+ return Ce({ index: i, namespace: t, parent: n, vNode: e });
449
+ const o = e.tag, r = ke(o, t), s = r ? document.createElementNS(r, o) : document.createElement(o);
450
+ return e.el = s, z(s, e.props), Ee({ element: s, namespace: r, tag: o, vNode: e }), s;
451
451
  }
452
- function be({ index: e, namespace: t, parent: n, vNode: o }) {
452
+ function Ce({ index: e, namespace: t, parent: n, vNode: i }) {
453
453
  if (n)
454
- return k({ index: e, newVNode: o, oldVNode: null, parent: n }), o.el;
455
- const r = document.createDocumentFragment();
456
- return k({
454
+ return _({ index: e, newVNode: i, oldVNode: null, parent: n }), i.el;
455
+ const o = document.createDocumentFragment();
456
+ return _({
457
457
  index: 0,
458
- newVNode: o,
458
+ newVNode: i,
459
459
  oldVNode: null,
460
- parent: r
461
- }), o.el || r.firstChild;
462
- }
463
- function Ee({ element: e, namespace: t, tag: n, vNode: o }) {
464
- const r = n === "foreignObject" ? null : t;
465
- o.children.forEach((i) => {
466
- const s = E(
467
- i,
460
+ parent: o
461
+ }), i.el || o.firstChild;
462
+ }
463
+ function Ee({ element: e, namespace: t, tag: n, vNode: i }) {
464
+ const o = n === "foreignObject" ? null : t;
465
+ i.children.forEach((r) => {
466
+ const s = A(
468
467
  r,
468
+ o,
469
469
  e,
470
470
  e.childNodes.length
471
471
  );
@@ -473,99 +473,96 @@ function Ee({ element: e, namespace: t, tag: n, vNode: o }) {
473
473
  });
474
474
  }
475
475
  function ke(e, t) {
476
- return e === "svg" ? S : e === "math" ? x : t;
476
+ return e === "svg" ? M : e === "math" ? S : t;
477
477
  }
478
478
  function R(e) {
479
479
  return e && e.some((t) => t?.props?.key != null);
480
480
  }
481
- function Ce({
481
+ function Me({
482
482
  oldChildren: e,
483
483
  newChildren: t,
484
484
  parent: n,
485
- patchNode: o,
486
- runUnmount: r
485
+ patchNode: i,
486
+ runUnmount: o
487
487
  }) {
488
488
  if (R(t) || R(e)) {
489
- Se({
489
+ Ae({
490
490
  oldChildren: e,
491
491
  newChildren: t,
492
492
  parent: n,
493
- patchNode: o,
494
- runUnmount: r
493
+ patchNode: i,
494
+ runUnmount: o
495
495
  });
496
496
  return;
497
497
  }
498
- Me({ oldChildren: e, newChildren: t, parent: n, patchNode: o });
498
+ Se({ oldChildren: e, newChildren: t, parent: n, patchNode: i });
499
499
  }
500
- function Me({
500
+ function Se({
501
501
  oldChildren: e,
502
502
  newChildren: t,
503
503
  parent: n,
504
- patchNode: o
504
+ patchNode: i
505
505
  }) {
506
- const r = Math.max(t.length, e.length);
507
- for (let i = 0; i < r; i++)
508
- o(n, t[i], e[i], i);
506
+ const o = Math.max(t.length, e.length);
507
+ for (let r = 0; r < o; r++)
508
+ i(n, t[r], e[r], r);
509
509
  }
510
- function Se({
510
+ function Ae({
511
511
  oldChildren: e,
512
512
  newChildren: t,
513
513
  parent: n,
514
- patchNode: o,
515
- runUnmount: r
514
+ patchNode: i,
515
+ runUnmount: o
516
516
  }) {
517
- const i = xe(e);
517
+ const r = xe(e);
518
518
  t.forEach((s, c) => {
519
- const u = w(s, c), a = i[u];
519
+ const u = q(s, c), a = r[u];
520
520
  if (a) {
521
- Ae({
521
+ Ke({
522
522
  existingChild: a,
523
523
  index: c,
524
524
  newChild: s,
525
525
  parent: n,
526
- patchNode: o
527
- }), delete i[u];
526
+ patchNode: i
527
+ }), delete r[u];
528
528
  return;
529
529
  }
530
- Ke({ index: c, newChild: s, parent: n });
531
- }), Ie({ keyedChildren: i, parent: n, runUnmount: r });
530
+ Ie({ index: c, newChild: s, parent: n, patchNode: i });
531
+ }), ve({ keyedChildren: r, parent: n, runUnmount: o });
532
532
  }
533
533
  function xe(e) {
534
534
  const t = {};
535
- return e.forEach((n, o) => {
536
- const r = w(n, o);
537
- t[r] = { index: o, vNode: n };
535
+ return e.forEach((n, i) => {
536
+ const o = q(n, i);
537
+ t[o] = { index: i, vNode: n };
538
538
  }), t;
539
539
  }
540
- function w(e, t) {
540
+ function q(e, t) {
541
541
  return e?.props?.key != null ? e.props.key : t;
542
542
  }
543
- function Ae({
543
+ function Ke({
544
544
  existingChild: e,
545
545
  index: t,
546
546
  newChild: n,
547
- parent: o,
548
- patchNode: r
547
+ parent: i,
548
+ patchNode: o
549
549
  }) {
550
- const i = e.vNode;
551
- r(o, n, i, t);
552
- const s = n.el || i.el, c = o.childNodes[t];
553
- s && c !== s && o.insertBefore(s, c);
554
- }
555
- function Ke({ index: e, newChild: t, parent: n }) {
556
- const o = E(t, A(n)), r = n.childNodes[e];
557
- if (r) {
558
- n.insertBefore(o, r);
559
- return;
560
- }
561
- n.appendChild(o);
562
- }
563
- function Ie({ keyedChildren: e, parent: t, runUnmount: n }) {
564
- Object.values(e).forEach(({ vNode: o }) => {
565
- !o.el || o.el.parentNode !== t || (n(o), t.removeChild(o.el));
550
+ const r = e.vNode;
551
+ o(i, n, r, t);
552
+ const s = n.el || r.el, c = i.childNodes[t];
553
+ s && c !== s && i.insertBefore(s, c);
554
+ }
555
+ function Ie({ index: e, newChild: t, parent: n, patchNode: i }) {
556
+ i(n, t, null, e);
557
+ const o = t.el, r = n.childNodes[e];
558
+ o && r && r !== o && n.insertBefore(o, r);
559
+ }
560
+ function ve({ keyedChildren: e, parent: t, runUnmount: n }) {
561
+ Object.values(e).forEach(({ vNode: i }) => {
562
+ !i.el || i.el.parentNode !== t || (n(i), t.removeChild(i.el));
566
563
  });
567
564
  }
568
- function ve() {
565
+ function He() {
569
566
  const e = {
570
567
  index: 0,
571
568
  parent: null,
@@ -581,7 +578,7 @@ function ve() {
581
578
  props: e.vNode.props,
582
579
  tag: e.vNode.tag
583
580
  };
584
- k({
581
+ _({
585
582
  index: e.index,
586
583
  newVNode: t,
587
584
  oldVNode: e.vNode,
@@ -589,73 +586,93 @@ function ve() {
589
586
  });
590
587
  }, e;
591
588
  }
592
- function k({ index: e, newVNode: t, oldVNode: n, parent: o }) {
593
- const r = n?.instance?.vNode || n, i = r?.instance || ve(), s = !r;
594
- t.instance = i, i.index = e, i.isMounted = !0, i.parent = o;
595
- const c = N(t, i.update);
596
- t.child = c, I(o, c, r?.child, e), t.el = typeof c == "object" && c !== null ? c.el : o.childNodes[e], s && X(t.hooks), s || Z({
589
+ function _({ index: e, newVNode: t, oldVNode: n, parent: i }) {
590
+ const o = n?.instance?.vNode || n, r = o?.instance || He(), s = !o;
591
+ t.instance = r, r.index = e, r.isMounted = !0, r.parent = i;
592
+ const c = w(t, r.update);
593
+ t.child = c, K(i, c, o?.child, e), t.el = typeof c == "object" && c !== null ? c.el : i.childNodes[e], s && P(t.hooks), s || N({
597
594
  newHooks: t.hooks,
598
- oldHooks: r.hooks
599
- }), s || (t.hooks = r.hooks), i.vNode = t;
595
+ oldHooks: o.hooks
596
+ }), s || (t.hooks = o.hooks), r.vNode = t;
597
+ }
598
+ function $(e) {
599
+ return typeof e?.tag == "function";
600
600
  }
601
- function I(e, t, n, o = 0) {
601
+ function Le(e, t) {
602
+ return $(e) && $(t) && e.tag !== t.tag;
603
+ }
604
+ function K(e, t, n, i = 0) {
602
605
  if (t == null) {
603
- const i = n.el || e.childNodes[o];
604
- b(n), i && e.removeChild(i);
606
+ const r = n?.el || e.childNodes[i];
607
+ g(n), r && r.parentNode === e && e.removeChild(r);
608
+ return;
609
+ }
610
+ if (Le(t, n)) {
611
+ const r = n.el || n.child?.el || e.childNodes[i];
612
+ g(n);
613
+ const s = document.createDocumentFragment();
614
+ _({ index: 0, newVNode: t, oldVNode: null, parent: s }), t.instance.parent = e, t.instance.index = i;
615
+ const c = t.el || s.firstChild;
616
+ if (r && r.parentNode === e)
617
+ e.replaceChild(c, r);
618
+ else {
619
+ const u = e.childNodes[i];
620
+ u && u.parentNode === e ? e.replaceChild(c, u) : e.appendChild(c);
621
+ }
605
622
  return;
606
623
  }
607
624
  if (typeof t.tag == "function") {
608
- k({ index: o, newVNode: t, oldVNode: n, parent: e });
625
+ _({ index: i, newVNode: t, oldVNode: n, parent: e });
609
626
  return;
610
627
  }
611
628
  if (n == null) {
612
- e.appendChild(E(t, A(e)));
629
+ e.appendChild(A(t, T(e)));
613
630
  return;
614
631
  }
615
632
  if (typeof t != typeof n || typeof t != "string" && t.tag !== n.tag) {
616
- const i = n.el || e.childNodes[o];
617
- i && e.replaceChild(E(t, A(e)), i);
633
+ const r = n.el || e.childNodes[i];
634
+ r && e.replaceChild(A(t, T(e)), r);
618
635
  return;
619
636
  }
620
637
  if (typeof t == "string" || typeof t == "number") {
621
638
  if (t !== n) {
622
- const i = e.childNodes[o];
623
- i ? i.nodeValue = String(t) : e.appendChild(document.createTextNode(String(t)));
639
+ const r = e.childNodes[i];
640
+ r ? r.nodeValue = String(t) : e.appendChild(document.createTextNode(String(t)));
624
641
  }
625
642
  return;
626
643
  }
627
- const r = n.el || e.childNodes[o];
628
- r && (t.el = r, U(r, t.props, n.props), Ce({
644
+ const o = n.el || e.childNodes[i];
645
+ o && (t.el = o, z(o, t.props, n.props), Me({
629
646
  oldChildren: n.children,
630
647
  newChildren: t.children,
631
- parent: r,
632
- patchNode: I,
633
- runUnmount: b
648
+ parent: o,
649
+ patchNode: K,
650
+ runUnmount: g
634
651
  }));
635
652
  }
636
- const Oe = (e, t) => {
653
+ const De = (e, t) => {
637
654
  let n = null;
638
655
  (() => {
639
- const r = {
656
+ const o = {
640
657
  tag: t,
641
658
  props: {},
642
659
  children: []
643
660
  };
644
- I(e, r, n), n = r;
661
+ K(e, o, n), n = o;
645
662
  })();
646
- }, je = (e, t = {}) => ({
663
+ }, Fe = (e, t = {}) => ({
647
664
  __humn_persist: !0,
648
665
  initial: e,
649
666
  config: t
650
667
  });
651
668
  export {
652
- He as Cortex,
653
- Y as cloneVNode,
654
- Le as css,
655
- Te as h,
656
- Oe as mount,
657
- $e as onCleanup,
658
- Re as onMount,
659
- je as persist
669
+ Te as Cortex,
670
+ Z as cloneVNode,
671
+ Re as css,
672
+ $e as h,
673
+ De as mount,
674
+ je as onCleanup,
675
+ Oe as onMount,
676
+ Fe as persist
660
677
  };
661
678
  //# sourceMappingURL=humn.js.map