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