@shane_il/pulse 0.2.0 → 0.3.0

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/pulse.js CHANGED
@@ -1,37 +1,37 @@
1
- var et = Object.defineProperty;
2
- var nt = (t, e, s) => e in t ? et(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var k = (t, e, s) => nt(t, typeof e != "symbol" ? e + "" : e, s);
4
- const $ = Symbol("TEXT_NODE"), st = Symbol("FRAGMENT");
5
- function q(t) {
1
+ var st = Object.defineProperty;
2
+ var ot = (t, e, s) => e in t ? st(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
+ var T = (t, e, s) => ot(t, typeof e != "symbol" ? e + "" : e, s);
4
+ const G = Symbol("TEXT_NODE"), rt = Symbol("FRAGMENT");
5
+ function $(t) {
6
6
  return {
7
- type: $,
7
+ type: G,
8
8
  props: { nodeValue: String(t) },
9
9
  children: [],
10
10
  key: null
11
11
  };
12
12
  }
13
- function ot(t) {
14
- return t == null || typeof t == "boolean" ? null : typeof t == "string" || typeof t == "number" ? q(t) : t;
13
+ function ct(t) {
14
+ return t == null || typeof t == "boolean" ? null : typeof t == "string" || typeof t == "number" ? $(t) : t;
15
15
  }
16
- function Q(t) {
16
+ function J(t) {
17
17
  const e = [];
18
18
  for (const s of t)
19
19
  if (Array.isArray(s))
20
- e.push(...Q(s));
20
+ e.push(...J(s));
21
21
  else {
22
- const n = ot(s);
22
+ const n = ct(s);
23
23
  n !== null && e.push(n);
24
24
  }
25
25
  return e;
26
26
  }
27
- function X(t, e, ...s) {
27
+ function K(t, e, ...s) {
28
28
  e = e || {};
29
29
  const n = e.key ?? null;
30
30
  e.key !== void 0 && (e = { ...e }, delete e.key);
31
- const r = Q(s);
31
+ const r = J(s);
32
32
  return { type: t, props: e, children: r, key: n };
33
33
  }
34
- function rt(t) {
34
+ function it(t) {
35
35
  let e = t.state;
36
36
  const s = t.actions, n = /* @__PURE__ */ new Set(), r = t.middleware;
37
37
  function o() {
@@ -41,20 +41,20 @@ function rt(t) {
41
41
  for (const u of n)
42
42
  u(e);
43
43
  }
44
- function a(u, d) {
45
- const S = s[u];
46
- if (!S)
44
+ function l(u, d) {
45
+ const g = s[u];
46
+ if (!g)
47
47
  throw new Error(`[pulse] Unknown action: "${u}"`);
48
- const b = S(e, d);
48
+ const b = g(e, d);
49
49
  b !== e && (e = b, c());
50
50
  }
51
- function l(u, d) {
51
+ function a(u, d) {
52
52
  if (u === "__devtools_replace__") {
53
53
  e = d, c();
54
54
  return;
55
55
  }
56
- const S = s[u];
57
- if (!S)
56
+ const g = s[u];
57
+ if (!g)
58
58
  throw new Error(`[pulse] Unknown action: "${u}"`);
59
59
  const b = {
60
60
  store: h,
@@ -63,19 +63,19 @@ function rt(t) {
63
63
  prevState: e,
64
64
  nextState: void 0
65
65
  };
66
- let P = 0;
67
- function C() {
68
- if (P < r.length) {
69
- const f = r[P++];
70
- f(b, C);
66
+ let I = 0;
67
+ function x() {
68
+ if (I < r.length) {
69
+ const f = r[I++];
70
+ f(b, x);
71
71
  } else {
72
- const f = S(b.prevState, b.payload);
72
+ const f = g(b.prevState, b.payload);
73
73
  b.nextState = f, f !== e && (e = f, c());
74
74
  }
75
75
  }
76
- C();
76
+ x();
77
77
  }
78
- const i = r && r.length > 0 ? l : a;
78
+ const i = r && r.length > 0 ? a : l;
79
79
  function p(u) {
80
80
  return n.add(u), () => {
81
81
  n.delete(u);
@@ -94,48 +94,48 @@ function rt(t) {
94
94
  }
95
95
  let U = !1;
96
96
  const N = /* @__PURE__ */ new Set();
97
- function ct(t) {
98
- N.add(t), U || (U = !0, queueMicrotask(it));
97
+ function at(t) {
98
+ N.add(t), U || (U = !0, queueMicrotask(lt));
99
99
  }
100
- function it() {
100
+ function lt() {
101
101
  const t = [...N];
102
102
  N.clear(), U = !1;
103
103
  for (const e of t)
104
104
  e();
105
105
  }
106
- function mt() {
106
+ function _t() {
107
107
  const t = [...N];
108
108
  N.clear(), U = !1;
109
109
  for (const e of t)
110
110
  e();
111
111
  }
112
- const J = Symbol("PULSE_CONNECTED"), D = globalThis;
113
- D.__PULSE_HOOKS__ || (D.__PULSE_HOOKS__ = { onMount: null, onUnmount: null });
114
- const I = D.__PULSE_HOOKS__;
115
- function lt(t, e) {
112
+ const Y = Symbol("PULSE_CONNECTED"), H = globalThis;
113
+ H.__PULSE_HOOKS__ || (H.__PULSE_HOOKS__ = { onMount: null, onUnmount: null });
114
+ const M = H.__PULSE_HOOKS__;
115
+ function ut(t, e) {
116
116
  return function(n) {
117
117
  const r = t || {};
118
118
  function o(c) {
119
- const a = {};
120
- for (const l in r) {
121
- const { store: i, selector: p } = r[l];
122
- a[l] = p(i.getState());
119
+ const l = {};
120
+ for (const a in r) {
121
+ const { store: i, selector: p } = r[a];
122
+ l[a] = p(i.getState());
123
123
  }
124
- return n({ ...a, ...c });
124
+ return n({ ...l, ...c });
125
125
  }
126
- return o[J] = !0, o._bindings = r, o._innerComponent = n, e && (o._lifecycle = e), o.displayName = `Connected(${n.displayName || n.name || "Anonymous"})`, o;
126
+ return o[Y] = !0, o._bindings = r, o._innerComponent = n, e && (o._lifecycle = e), o.displayName = `Connected(${n.displayName || n.name || "Anonymous"})`, o;
127
127
  };
128
128
  }
129
- class at {
129
+ class ft {
130
130
  constructor(e, s) {
131
- k(this, "connectedFn");
132
- k(this, "props");
133
- k(this, "prevSelected");
134
- k(this, "unsubscribers");
135
- k(this, "lastVTree");
136
- k(this, "parentDom");
137
- k(this, "_renderCallback");
138
- k(this, "_mountCleanup");
131
+ T(this, "connectedFn");
132
+ T(this, "props");
133
+ T(this, "prevSelected");
134
+ T(this, "unsubscribers");
135
+ T(this, "lastVTree");
136
+ T(this, "parentDom");
137
+ T(this, "_renderCallback");
138
+ T(this, "_mountCleanup");
139
139
  this.connectedFn = e, this.props = s, this.prevSelected = {}, this.unsubscribers = [], this.lastVTree = null, this.parentDom = null, this._renderCallback = null, this._mountCleanup = null;
140
140
  }
141
141
  mount(e, s) {
@@ -143,14 +143,14 @@ class at {
143
143
  this.parentDom = e, this._renderCallback = s;
144
144
  const n = this.connectedFn._bindings;
145
145
  for (const c in n) {
146
- const { store: a, selector: l } = n[c];
147
- this.prevSelected[c] = l(a.getState());
146
+ const { store: l, selector: a } = n[c];
147
+ this.prevSelected[c] = a(l.getState());
148
148
  }
149
149
  for (const c in n) {
150
- const { store: a } = n[c], l = a.subscribe(() => {
150
+ const { store: l } = n[c], a = l.subscribe(() => {
151
151
  this._onStoreChange();
152
152
  });
153
- this.unsubscribers.push(l);
153
+ this.unsubscribers.push(a);
154
154
  }
155
155
  const r = this.connectedFn._lifecycle;
156
156
  if (r != null && r.onMount) {
@@ -160,19 +160,19 @@ class at {
160
160
  });
161
161
  typeof c == "function" && (this._mountCleanup = c);
162
162
  }
163
- I.onMount && I.onMount(this);
163
+ M.onMount && M.onMount(this);
164
164
  }
165
165
  _onStoreChange() {
166
166
  const e = this.connectedFn._bindings;
167
167
  let s = !1;
168
168
  for (const n in e) {
169
169
  const { store: r, selector: o } = e[n], c = o(r.getState());
170
- if (!ut(c, this.prevSelected[n])) {
170
+ if (!pt(c, this.prevSelected[n])) {
171
171
  s = !0;
172
172
  break;
173
173
  }
174
174
  }
175
- s && ct(this._renderCallback);
175
+ s && at(this._renderCallback);
176
176
  }
177
177
  updateSelected() {
178
178
  const e = this.connectedFn._bindings;
@@ -182,7 +182,7 @@ class at {
182
182
  }
183
183
  }
184
184
  unmount() {
185
- I.onUnmount && I.onUnmount(this), this._mountCleanup && (this._mountCleanup(), this._mountCleanup = null);
185
+ M.onUnmount && M.onUnmount(this), this._mountCleanup && (this._mountCleanup(), this._mountCleanup = null);
186
186
  const e = this.connectedFn._lifecycle;
187
187
  e != null && e.onDestroy && e.onDestroy({ props: this.props });
188
188
  for (const s of this.unsubscribers)
@@ -190,7 +190,7 @@ class at {
190
190
  this.unsubscribers = [], this._renderCallback = null;
191
191
  }
192
192
  }
193
- function ut(t, e) {
193
+ function pt(t, e) {
194
194
  if (Object.is(t, e)) return !0;
195
195
  if (typeof t != "object" || typeof e != "object" || t === null || e === null) return !1;
196
196
  const s = Object.keys(t), n = Object.keys(e);
@@ -209,20 +209,20 @@ const m = {
209
209
  MOVE: "MOVE",
210
210
  CHILDREN: "CHILDREN"
211
211
  };
212
- function T(t, e) {
212
+ function w(t, e) {
213
213
  if (e == null && t == null) return [];
214
214
  if (e == null) return [{ type: m.REMOVE, target: t }];
215
215
  if (t == null) return [{ type: m.CREATE, newVNode: e }];
216
216
  if (t.type !== e.type)
217
217
  return [{ type: m.REPLACE, oldVNode: t, newVNode: e }];
218
- if (e._dom = t._dom, t.type === $)
218
+ if (e._dom = t._dom, t.type === G)
219
219
  return t.props.nodeValue !== e.props.nodeValue ? [{ type: m.TEXT, oldVNode: t, newVNode: e }] : [];
220
- const s = [], n = ft(t.props, e.props);
220
+ const s = [], n = ht(t.props, e.props);
221
221
  n && s.push({ type: m.UPDATE, target: t, propPatches: n });
222
- const r = pt(t.children, e.children);
222
+ const r = dt(t.children, e.children);
223
223
  return r.length && s.push({ type: m.CHILDREN, parent: t, childPatches: r }), s;
224
224
  }
225
- function ft(t, e) {
225
+ function ht(t, e) {
226
226
  const s = {}, n = [];
227
227
  let r = !1;
228
228
  for (const o in e)
@@ -231,10 +231,10 @@ function ft(t, e) {
231
231
  o !== "children" && (o in e || (n.push(o), r = !0));
232
232
  return r ? { set: s, remove: n } : null;
233
233
  }
234
- function A(t, e) {
234
+ function P(t, e) {
235
235
  return t == null || e == null ? !1 : t.type === e.type && t.key === e.key;
236
236
  }
237
- function z(t, e) {
237
+ function X(t, e) {
238
238
  const s = /* @__PURE__ */ new Set();
239
239
  let n = 0, r = 0;
240
240
  for (const o of t)
@@ -245,38 +245,38 @@ function z(t, e) {
245
245
  `[pulse] Mixed keyed and unkeyed children in ${e} list (${n} keyed, ${r} unkeyed). Either all children should have keys or none should.`
246
246
  );
247
247
  }
248
- function pt(t, e) {
248
+ function dt(t, e) {
249
249
  var y;
250
- process.env.NODE_ENV !== "production" && (z(t, "old"), z(e, "new"));
250
+ process.env.NODE_ENV !== "production" && (X(t, "old"), X(e, "new"));
251
251
  const s = [];
252
- let n = 0, r = t.length - 1, o = 0, c = e.length - 1, a = t[n], l = t[r], i = e[o], p = e[c];
252
+ let n = 0, r = t.length - 1, o = 0, c = e.length - 1, l = t[n], a = t[r], i = e[o], p = e[c];
253
253
  for (; n <= r && o <= c; ) {
254
- if (a == null) {
255
- a = t[++n];
254
+ if (l == null) {
255
+ l = t[++n];
256
256
  continue;
257
257
  }
258
- if (l == null) {
259
- l = t[--r];
258
+ if (a == null) {
259
+ a = t[--r];
260
260
  continue;
261
261
  }
262
- if (A(a, i))
263
- s.push(...T(a, i)), a = t[++n], i = e[++o];
264
- else if (A(l, p))
265
- s.push(...T(l, p)), l = t[--r], p = e[--c];
266
- else if (A(a, p))
262
+ if (P(l, i))
263
+ s.push(...w(l, i)), l = t[++n], i = e[++o];
264
+ else if (P(a, p))
265
+ s.push(...w(a, p)), a = t[--r], p = e[--c];
266
+ else if (P(l, p))
267
267
  s.push({
268
268
  type: m.MOVE,
269
- vnode: a,
269
+ vnode: l,
270
270
  anchor: t[r + 1] || null,
271
- childPatches: T(a, p)
272
- }), a = t[++n], p = e[--c];
273
- else if (A(l, i))
271
+ childPatches: w(l, p)
272
+ }), l = t[++n], p = e[--c];
273
+ else if (P(a, i))
274
274
  s.push({
275
275
  type: m.MOVE,
276
- vnode: l,
277
- anchor: a,
278
- childPatches: T(l, i)
279
- }), l = t[--r], i = e[++o];
276
+ vnode: a,
277
+ anchor: l,
278
+ childPatches: w(a, i)
279
+ }), a = t[--r], i = e[++o];
280
280
  else
281
281
  break;
282
282
  }
@@ -295,7 +295,7 @@ function pt(t, e) {
295
295
  type: m.MOVE,
296
296
  vnode: d,
297
297
  anchor: t[n] || null,
298
- childPatches: T(d, i)
298
+ childPatches: w(d, i)
299
299
  }), t[u] = null, h.delete(i.key);
300
300
  } else
301
301
  s.push({
@@ -317,51 +317,79 @@ function pt(t, e) {
317
317
  t[h] != null && s.push({ type: m.REMOVE, target: t[h] });
318
318
  return s;
319
319
  }
320
- function R(t) {
321
- if (t.type === $) {
322
- const s = document.createTextNode(t.props.nodeValue);
323
- return t._dom = s, s;
320
+ const Z = "http://www.w3.org/2000/svg";
321
+ function A(t, e) {
322
+ if (t.type === G) {
323
+ const n = document.createTextNode(t.props.nodeValue);
324
+ return t._dom = n, n;
324
325
  }
325
- if (t.type === st) {
326
- const s = document.createDocumentFragment();
327
- for (const n of t.children)
328
- s.appendChild(R(n));
329
- return t._dom = s, s;
326
+ if (t.type === rt) {
327
+ const n = document.createDocumentFragment();
328
+ for (const r of t.children)
329
+ n.appendChild(A(r, e));
330
+ return t._dom = n, n;
330
331
  }
331
- const e = document.createElement(t.type);
332
- ht(e, {}, t.props);
333
- for (const s of t.children)
334
- e.appendChild(R(s));
335
- return t._dom = e, e;
336
- }
337
- function ht(t, e, s) {
332
+ t.type === "svg" ? e = Z : t.type === "foreignObject" && (e = void 0);
333
+ const s = e ? document.createElementNS(e, t.type) : document.createElement(t.type);
334
+ mt(s, {}, t.props);
335
+ for (const n of t.children)
336
+ s.appendChild(A(n, e));
337
+ return t._dom = s, s;
338
+ }
339
+ function mt(t, e, s) {
338
340
  for (const n in e)
339
- n === "children" || n === "key" || n in s || Z(t, n, e[n]);
341
+ n === "children" || n === "key" || n in s || tt(t, n, e[n]);
340
342
  for (const n in s)
341
- n === "children" || n === "key" || e[n] !== s[n] && Y(t, n, s[n], e[n]);
343
+ n === "children" || n === "key" || e[n] !== s[n] && v(t, n, s[n], e[n]);
342
344
  }
343
- function Y(t, e, s, n) {
345
+ function v(t, e, s, n) {
344
346
  if (e.startsWith("on")) {
345
347
  const r = e.slice(2).toLowerCase();
346
348
  n && t.removeEventListener(r, n), s && t.addEventListener(r, s);
347
- } else if (e === "className")
348
- t.className = s || "";
349
+ } else if (e === "className" || e === "class")
350
+ t instanceof SVGElement ? t.setAttribute("class", s || "") : t.className = s || "";
349
351
  else if (e === "style" && typeof s == "object") {
350
352
  if (typeof n == "object" && n)
351
353
  for (const r in n)
352
354
  r in s || (t.style[r] = "");
353
355
  Object.assign(t.style, s);
354
- } else e === "ref" ? typeof s == "function" && s(t) : s === !0 ? t.setAttribute(e, "") : s === !1 || s == null ? t.removeAttribute(e) : t.setAttribute(e, s);
356
+ } else if (e === "dangerouslySetInnerHTML")
357
+ s && typeof s.__html == "string" && (t.innerHTML = s.__html);
358
+ else if (e === "ref")
359
+ typeof s == "function" && s(t);
360
+ else if (e in t && !(t instanceof SVGElement))
361
+ try {
362
+ t[e] = s ?? "";
363
+ } catch {
364
+ t.setAttribute(e, s);
365
+ }
366
+ else s === !0 ? t.setAttribute(e, "") : s === !1 || s == null ? t.removeAttribute(e) : t.setAttribute(e, s);
367
+ }
368
+ function tt(t, e, s) {
369
+ if (e.startsWith("on"))
370
+ t.removeEventListener(e.slice(2).toLowerCase(), s);
371
+ else if (e === "dangerouslySetInnerHTML")
372
+ t.innerHTML = "";
373
+ else if (e === "className" || e === "class")
374
+ t instanceof SVGElement ? t.removeAttribute("class") : t.className = "";
375
+ else if (e in t && !(t instanceof SVGElement))
376
+ try {
377
+ t[e] = "";
378
+ } catch {
379
+ t.removeAttribute(e);
380
+ }
381
+ else
382
+ t.removeAttribute(e);
355
383
  }
356
- function Z(t, e, s) {
357
- e.startsWith("on") ? t.removeEventListener(e.slice(2).toLowerCase(), s) : e === "className" ? t.className = "" : t.removeAttribute(e);
384
+ function z(t) {
385
+ return t instanceof SVGElement ? Z : void 0;
358
386
  }
359
- function x(t, e) {
387
+ function R(t, e) {
360
388
  var s, n, r;
361
389
  for (const o of e)
362
390
  switch (o.type) {
363
391
  case m.CREATE: {
364
- const c = R(o.newVNode);
392
+ const c = A(o.newVNode, z(t));
365
393
  (s = o.anchor) != null && s._dom ? t.insertBefore(c, o.anchor._dom) : t.appendChild(c);
366
394
  break;
367
395
  }
@@ -371,16 +399,19 @@ function x(t, e) {
371
399
  break;
372
400
  }
373
401
  case m.REPLACE: {
374
- const c = R(o.newVNode), a = o.oldVNode._dom;
375
- a != null && a.parentNode && a.parentNode.replaceChild(c, a);
402
+ const c = o.oldVNode._dom, l = c == null ? void 0 : c.parentNode, a = A(
403
+ o.newVNode,
404
+ l ? z(l) : void 0
405
+ );
406
+ l && l.replaceChild(a, c);
376
407
  break;
377
408
  }
378
409
  case m.UPDATE: {
379
- const c = o.target._dom, { set: a, remove: l } = o.propPatches;
380
- for (const i of l)
381
- Z(c, i, o.target.props[i]);
382
- for (const i in a)
383
- Y(c, i, a[i], o.target.props[i]);
410
+ const c = o.target._dom, { set: l, remove: a } = o.propPatches;
411
+ for (const i of a)
412
+ tt(c, i, o.target.props[i]);
413
+ for (const i in l)
414
+ v(c, i, l[i], o.target.props[i]);
384
415
  break;
385
416
  }
386
417
  case m.TEXT: {
@@ -390,92 +421,95 @@ function x(t, e) {
390
421
  }
391
422
  case m.MOVE: {
392
423
  const c = o.vnode._dom;
393
- c && ((n = o.anchor) != null && n._dom ? t.insertBefore(c, o.anchor._dom) : t.appendChild(c)), (r = o.childPatches) != null && r.length && c && x(c, o.childPatches);
424
+ c && ((n = o.anchor) != null && n._dom ? t.insertBefore(c, o.anchor._dom) : t.appendChild(c)), (r = o.childPatches) != null && r.length && c && R(c, o.childPatches);
394
425
  break;
395
426
  }
396
427
  case m.CHILDREN: {
397
428
  const c = o.parent._dom;
398
- c && o.childPatches.length && x(c, o.childPatches);
429
+ c && o.childPatches.length && R(c, o.childPatches);
399
430
  break;
400
431
  }
401
432
  }
402
433
  }
403
- const j = /* @__PURE__ */ new WeakMap();
404
- function yt(t, e) {
405
- const s = j.get(e);
434
+ const F = /* @__PURE__ */ new WeakMap();
435
+ function Et(t, e) {
436
+ const s = F.get(e);
406
437
  if (s) {
407
- const n = w(t, e), r = [];
408
- M(s.vTree, r);
409
- const o = T(s.vTree, n);
410
- x(e, o);
438
+ const n = k(t, e), r = [];
439
+ C(s.vTree, r);
440
+ const o = w(s.vTree, n);
441
+ R(e, o);
411
442
  const c = [];
412
- n && M(n, c);
413
- const a = new Set(c);
443
+ n && C(n, c);
444
+ const l = new Set(c);
414
445
  for (const i of r)
415
- a.has(i) || i.unmount();
416
- const l = new Set(r);
446
+ l.has(i) || i.unmount();
447
+ const a = new Set(r);
417
448
  for (const i of c)
418
- l.has(i) || i.mount(e, () => W(i, e));
419
- j.set(e, { vTree: n });
449
+ a.has(i) || i.mount(e, () => D(i, e));
450
+ F.set(e, { vTree: n });
420
451
  } else {
421
- const n = w(t, e);
452
+ const n = k(t, e);
422
453
  if (!n) return;
423
- const r = R(n);
454
+ const r = A(n);
424
455
  e.appendChild(r);
425
456
  const o = [];
426
- M(n, o);
457
+ C(n, o);
427
458
  for (const c of o)
428
- c.mount(e, () => W(c, e));
429
- j.set(e, { vTree: n });
459
+ c.mount(e, () => D(c, e));
460
+ F.set(e, { vTree: n });
430
461
  }
431
462
  }
432
- function w(t, e) {
463
+ function k(t, e) {
433
464
  var s;
434
465
  if (t == null) return null;
435
466
  if (typeof t.type == "function") {
436
- if (t.type[J]) {
467
+ if (t.type[Y]) {
437
468
  const r = t.type._lifecycle;
438
469
  try {
439
- const o = new at(t.type, t.props), c = t.type(t.props), l = w(c, e) ?? q("");
440
- if (l._instance) {
470
+ const o = new ft(t.type, t.props), c = t.type(t.props), a = k(c, e) ?? $("");
471
+ if (a._instance) {
441
472
  const i = {
442
473
  type: "div",
443
474
  props: { style: { display: "contents" } },
444
- children: [l],
475
+ children: [a],
445
476
  key: t.key
446
477
  };
447
478
  return i._instance = o, o.lastVTree = i, i;
448
479
  }
449
- return l._instance = o, o.lastVTree = l, l;
480
+ return a._instance = o, o.lastVTree = a, a;
450
481
  } catch (o) {
451
482
  if (r != null && r.onError) {
452
- const c = r.onError({ error: o, props: t.props });
453
- return w(c, e);
483
+ const c = r.onError({
484
+ error: o,
485
+ props: t.props
486
+ });
487
+ return k(c, e);
454
488
  }
455
489
  throw o;
456
490
  }
457
491
  }
458
492
  const n = t.type({ ...t.props, children: t.children });
459
- return w(n, e);
493
+ return k(n, e);
460
494
  }
461
- return (s = t.children) != null && s.length && (t.children = t.children.map((n) => w(n, e)).filter((n) => n != null)), t;
495
+ return (s = t.children) != null && s.length && (t.children = t.children.map((n) => k(n, e)).filter((n) => n != null)), t;
462
496
  }
463
- function W(t, e) {
497
+ function D(t, e) {
464
498
  var r, o;
465
499
  if (!t._renderCallback) return;
466
500
  const s = t.connectedFn, n = s._lifecycle;
467
501
  try {
468
- const c = s(t.props);
469
- let l = w(c, e) ?? q(""), i;
470
- if (l._instance && l._instance !== t ? (i = {
502
+ const c = s(t.props), a = k(c, e) ?? $("");
503
+ let i;
504
+ if (a._instance && a._instance !== t ? (i = {
471
505
  type: "div",
472
506
  props: { style: { display: "contents" } },
473
- children: [l],
507
+ children: [a],
474
508
  key: null
475
- }, i._instance = t) : (l._instance = t, i = l), t.lastVTree) {
476
- H(t.lastVTree, t);
477
- const d = T(t.lastVTree, i), S = ((r = t.lastVTree._dom) == null ? void 0 : r.parentNode) || e;
478
- x(S, d), i._dom || (i._dom = t.lastVTree._dom);
509
+ }, i._instance = t) : (a._instance = t, i = a), t.lastVTree) {
510
+ W(t.lastVTree, t);
511
+ const d = w(t.lastVTree, i), g = ((r = t.lastVTree._dom) == null ? void 0 : r.parentNode) || e;
512
+ R(g, d), i._dom || (i._dom = t.lastVTree._dom);
479
513
  }
480
514
  const p = [];
481
515
  L(t.lastVTree, p, t);
@@ -487,45 +521,45 @@ function W(t, e) {
487
521
  t.lastVTree = i;
488
522
  const u = new Set(p);
489
523
  for (const d of y)
490
- u.has(d) || d.mount(e, () => W(d, e));
524
+ u.has(d) || d.mount(e, () => D(d, e));
491
525
  n != null && n.onUpdate && n.onUpdate({
492
526
  dom: i == null ? void 0 : i._dom,
493
527
  props: t.props
494
528
  }), t.updateSelected();
495
529
  } catch (c) {
496
530
  if (n != null && n.onError) {
497
- const a = n.onError({ error: c, props: t.props }), l = w(a, e);
498
- if (t.lastVTree && l) {
499
- H(t.lastVTree, t);
500
- const p = T(t.lastVTree, l), y = ((o = t.lastVTree._dom) == null ? void 0 : o.parentNode) || e;
501
- x(y, p), l._dom || (l._dom = t.lastVTree._dom);
531
+ const l = n.onError({ error: c, props: t.props }), a = k(l, e);
532
+ if (t.lastVTree && a) {
533
+ W(t.lastVTree, t);
534
+ const p = w(t.lastVTree, a), y = ((o = t.lastVTree._dom) == null ? void 0 : o.parentNode) || e;
535
+ R(y, p), a._dom || (a._dom = t.lastVTree._dom);
502
536
  }
503
537
  const i = [];
504
538
  L(t.lastVTree, i, t);
505
539
  for (const p of i) p.unmount();
506
- t.lastVTree = l, t.updateSelected();
540
+ t.lastVTree = a, t.updateSelected();
507
541
  } else
508
542
  throw c;
509
543
  }
510
544
  }
511
- function H(t, e) {
545
+ function W(t, e) {
512
546
  if (!(!t || !t.children))
513
547
  for (let s = 0; s < t.children.length; s++) {
514
548
  const n = t.children[s];
515
- n._instance && n._instance !== e && n._instance.lastVTree && n._instance.lastVTree !== n && (t.children[s] = n._instance.lastVTree), H(t.children[s], e);
549
+ n._instance && n._instance !== e && n._instance.lastVTree && n._instance.lastVTree !== n && (t.children[s] = n._instance.lastVTree), W(t.children[s], e);
516
550
  }
517
551
  }
518
- function M(t, e) {
552
+ function C(t, e) {
519
553
  if (t && (t._instance && e.push(t._instance), t.children))
520
554
  for (const s of t.children)
521
- M(s, e);
555
+ C(s, e);
522
556
  }
523
557
  function L(t, e, s) {
524
558
  if (t && (t._instance && t._instance !== s && e.push(t._instance), t.children))
525
559
  for (const n of t.children)
526
560
  L(n, e, s);
527
561
  }
528
- function F(t) {
562
+ function j(t) {
529
563
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t || "/";
530
564
  }
531
565
  function B(t) {
@@ -536,72 +570,74 @@ function B(t) {
536
570
  e[o] = r;
537
571
  }), e;
538
572
  }
539
- function v(t, e) {
540
- const s = F(t), n = F(e);
573
+ function et(t, e) {
574
+ const s = j(t), n = j(e);
541
575
  if (n === "*")
542
576
  return { params: { "*": s } };
543
577
  const r = s === "/" ? [""] : s.split("/").slice(1), o = n === "/" ? [""] : n.split("/").slice(1);
544
578
  if (o.length > 0 && o[o.length - 1] === "*") {
545
- const l = o.slice(0, -1);
546
- if (r.length < l.length) return null;
579
+ const a = o.slice(0, -1);
580
+ if (r.length < a.length) return null;
547
581
  const i = {};
548
- for (let y = 0; y < l.length; y++) {
549
- const h = l[y];
582
+ for (let y = 0; y < a.length; y++) {
583
+ const h = a[y];
550
584
  if (h.startsWith(":"))
551
585
  i[h.slice(1)] = r[y];
552
586
  else if (h !== r[y])
553
587
  return null;
554
588
  }
555
- const p = r.slice(l.length).join("/");
589
+ const p = r.slice(a.length).join("/");
556
590
  return i["*"] = p, { params: i };
557
591
  }
558
592
  if (r.length !== o.length) return null;
559
- const a = {};
560
- for (let l = 0; l < o.length; l++) {
561
- const i = o[l];
593
+ const l = {};
594
+ for (let a = 0; a < o.length; a++) {
595
+ const i = o[a];
562
596
  if (i.startsWith(":"))
563
- a[i.slice(1)] = r[l];
564
- else if (i !== r[l])
597
+ l[i.slice(1)] = r[a];
598
+ else if (i !== r[a])
565
599
  return null;
566
600
  }
567
- return { params: a };
601
+ return { params: l };
568
602
  }
569
- function G(t, e) {
603
+ function Q(t, e) {
570
604
  for (const s of e) {
571
- const n = v(t, s.path);
605
+ const n = et(t, s.path);
572
606
  if (n)
573
607
  return { pattern: s.path, params: n.params };
574
608
  }
575
609
  return null;
576
610
  }
577
- function _t(t) {
578
- const { routes: e, initialPath: s } = t, n = s ?? window.location.pathname, r = s ? "" : window.location.search, o = F(n), c = B(r), a = G(o, e), l = rt({
611
+ function St(t) {
612
+ const { routes: e, initialPath: s } = t, n = s ?? window.location.pathname, r = s ? "" : window.location.search, o = j(n), c = B(r), l = Q(o, e), a = it({
579
613
  state: {
580
614
  path: o,
581
- params: (a == null ? void 0 : a.params) ?? {},
615
+ params: (l == null ? void 0 : l.params) ?? {},
582
616
  query: c,
583
- matched: (a == null ? void 0 : a.pattern) ?? null
617
+ matched: (l == null ? void 0 : l.pattern) ?? null
584
618
  },
585
619
  actions: {
586
620
  _sync: (f, _) => _
587
621
  }
588
622
  });
589
623
  function i(f) {
590
- const _ = f.indexOf("?"), V = F(_ >= 0 ? f.slice(0, _) : f), O = _ >= 0 ? f.slice(_ + 1) : "", E = B(O), g = G(V, e);
624
+ const _ = f.indexOf("?"), V = j(
625
+ _ >= 0 ? f.slice(0, _) : f
626
+ ), O = _ >= 0 ? f.slice(_ + 1) : "", E = B(O), S = Q(V, e);
591
627
  return {
592
628
  path: V,
593
- params: (g == null ? void 0 : g.params) ?? {},
629
+ params: (S == null ? void 0 : S.params) ?? {},
594
630
  query: E,
595
- matched: (g == null ? void 0 : g.pattern) ?? null
631
+ matched: (S == null ? void 0 : S.pattern) ?? null
596
632
  };
597
633
  }
598
634
  function p(f) {
599
635
  const _ = i(f);
600
- window.history.pushState(null, "", f), l.dispatch("_sync", _);
636
+ window.history.pushState(null, "", f), a.dispatch("_sync", _);
601
637
  }
602
638
  function y(f) {
603
639
  const _ = i(f);
604
- window.history.replaceState(null, "", f), l.dispatch("_sync", _);
640
+ window.history.replaceState(null, "", f), a.dispatch("_sync", _);
605
641
  }
606
642
  function h() {
607
643
  window.history.back();
@@ -610,24 +646,22 @@ function _t(t) {
610
646
  window.history.forward();
611
647
  }
612
648
  function d() {
613
- const f = i(
614
- window.location.pathname + window.location.search
615
- );
616
- l.dispatch("_sync", f);
649
+ const f = i(window.location.pathname + window.location.search);
650
+ a.dispatch("_sync", f);
617
651
  }
618
652
  window.addEventListener("popstate", d);
619
- function S() {
653
+ function g() {
620
654
  window.removeEventListener("popstate", d);
621
655
  }
622
- const b = lt({
623
- _path: l.select((f) => f.path)
656
+ const b = ut({
657
+ _path: a.select((f) => f.path)
624
658
  })(function(_) {
625
- const { _path: V, path: O, component: E, children: g, ...tt } = _, K = v(V, O);
626
- return K ? E ? X(E, { ...tt, params: K.params }) : (g == null ? void 0 : g[0]) ?? null : null;
659
+ const { _path: V, path: O, component: E, children: S, ...nt } = _, q = et(V, O);
660
+ return q ? E ? K(E, { ...nt, params: q.params }) : (S == null ? void 0 : S[0]) ?? null : null;
627
661
  });
628
- function P(f) {
662
+ function I(f) {
629
663
  const { to: _, children: V, ...O } = f;
630
- return X(
664
+ return K(
631
665
  "a",
632
666
  {
633
667
  ...O,
@@ -639,28 +673,43 @@ function _t(t) {
639
673
  ...V || []
640
674
  );
641
675
  }
642
- function C(f) {
676
+ function x(f) {
643
677
  return y(f.to), null;
644
678
  }
645
679
  return {
646
- store: l,
680
+ store: a,
647
681
  navigate: p,
648
682
  redirect: y,
649
683
  back: h,
650
684
  forward: u,
651
- destroy: S,
685
+ destroy: g,
652
686
  Route: b,
653
- Link: P,
654
- Redirect: C
687
+ Link: I,
688
+ Redirect: x
655
689
  };
656
690
  }
657
- function Et() {
691
+ function gt() {
658
692
  return (t, e) => {
659
693
  const s = `[pulse] ${t.actionName}`;
660
694
  console.group(s), console.log("prev state", t.prevState), console.log("payload", t.payload), e(), console.log("next state", t.nextState), console.groupEnd();
661
695
  };
662
696
  }
663
- function gt(t, e) {
697
+ function bt(t, e) {
698
+ return async (...s) => {
699
+ e.start && t.dispatch(e.start);
700
+ try {
701
+ const n = await e.run(...s);
702
+ return t.dispatch(e.ok, n), n;
703
+ } catch (n) {
704
+ if (e.fail)
705
+ t.dispatch(e.fail, (n == null ? void 0 : n.message) ?? String(n));
706
+ else
707
+ throw n;
708
+ return;
709
+ }
710
+ };
711
+ }
712
+ function Tt(t, e) {
664
713
  const s = (e == null ? void 0 : e.maxEntries) ?? 1 / 0;
665
714
  return (n, r) => {
666
715
  r(), t.push({
@@ -673,15 +722,16 @@ function gt(t, e) {
673
722
  };
674
723
  }
675
724
  export {
676
- st as Fragment,
677
- gt as actionHistory,
678
- lt as connect,
679
- X as createElement,
680
- _t as createRouter,
681
- rt as createStore,
682
- mt as flushSync,
683
- X as h,
684
- Et as logger,
685
- yt as render
725
+ rt as Fragment,
726
+ Tt as actionHistory,
727
+ ut as connect,
728
+ bt as createAsyncAction,
729
+ K as createElement,
730
+ St as createRouter,
731
+ it as createStore,
732
+ _t as flushSync,
733
+ K as h,
734
+ gt as logger,
735
+ Et as render
686
736
  };
687
737
  //# sourceMappingURL=pulse.js.map