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