@shane_il/pulse 0.1.2 → 0.2.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,110 +1,145 @@
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 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) {
6
6
  return {
7
- type: j,
7
+ type: $,
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 ot(t) {
14
+ return t == null || typeof t == "boolean" ? null : typeof t == "string" || typeof t == "number" ? q(t) : t;
15
15
  }
16
- function z(t) {
16
+ function Q(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(...Q(s));
21
21
  else {
22
- const n = nt(s);
22
+ const n = ot(s);
23
23
  n !== null && e.push(n);
24
24
  }
25
25
  return e;
26
26
  }
27
- function W(t, e, ...s) {
27
+ function X(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 = Q(s);
32
+ return { type: t, props: e, children: r, key: n };
33
33
  }
34
- function st(t) {
34
+ function rt(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 a(u, d) {
45
+ const S = s[u];
46
+ if (!S)
47
+ throw new Error(`[pulse] Unknown action: "${u}"`);
48
+ const b = S(e, d);
49
+ b !== e && (e = b, c());
50
+ }
51
+ function l(u, d) {
52
+ if (u === "__devtools_replace__") {
53
+ e = d, c();
54
+ return;
55
+ }
56
+ const S = s[u];
57
+ if (!S)
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 P = 0;
67
+ function C() {
68
+ if (P < r.length) {
69
+ const f = r[P++];
70
+ f(b, C);
71
+ } else {
72
+ const f = S(b.prevState, b.payload);
73
+ b.nextState = f, f !== e && (e = f, c());
74
+ }
49
75
  }
76
+ C();
50
77
  }
51
- function c(i) {
52
- return n.add(i), () => {
53
- n.delete(i);
78
+ const i = r && r.length > 0 ? l : a;
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 ct(t) {
98
+ N.add(t), U || (U = !0, queueMicrotask(it));
66
99
  }
67
- function ot() {
68
- const t = [...V];
69
- V.clear(), I = !1;
100
+ function it() {
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 mt() {
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 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) {
81
116
  return function(n) {
82
- const o = t || {};
83
- function r(c) {
117
+ const r = t || {};
118
+ function o(c) {
84
119
  const a = {};
85
- for (const l in o) {
86
- const { store: i, selector: u } = o[l];
87
- a[l] = u(i.getState());
120
+ for (const l in r) {
121
+ const { store: i, selector: p } = r[l];
122
+ a[l] = p(i.getState());
88
123
  }
89
124
  return n({ ...a, ...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[J] = !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 at {
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
+ 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");
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) {
@@ -117,36 +152,37 @@ class it {
117
152
  });
118
153
  this.unsubscribers.push(l);
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
+ I.onMount && I.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 (!ut(c, this.prevSelected[n])) {
135
171
  s = !0;
136
172
  break;
137
173
  }
138
174
  }
139
- s && rt(this._renderCallback);
175
+ s && ct(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
+ I.onUnmount && I.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 ut(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,234 +209,234 @@ const y = {
173
209
  MOVE: "MOVE",
174
210
  CHILDREN: "CHILDREN"
175
211
  };
176
- function k(t, e) {
212
+ function T(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 === $)
219
+ return t.props.nodeValue !== e.props.nodeValue ? [{ type: m.TEXT, oldVNode: t, newVNode: e }] : [];
220
+ const s = [], n = ft(t.props, e.props);
221
+ n && s.push({ type: m.UPDATE, target: t, propPatches: n });
222
+ const r = pt(t.children, e.children);
223
+ return r.length && s.push({ type: m.CHILDREN, parent: t, childPatches: r }), s;
224
+ }
225
+ function ft(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 A(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 z(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 pt(t, e) {
249
+ var y;
250
+ process.env.NODE_ENV !== "production" && (z(t, "old"), z(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; ) {
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];
253
+ for (; n <= r && o <= c; ) {
218
254
  if (a == null) {
219
255
  a = t[++n];
220
256
  continue;
221
257
  }
222
258
  if (l == null) {
223
- l = t[--o];
259
+ l = 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))
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))
231
267
  s.push({
232
- type: y.MOVE,
268
+ type: m.MOVE,
233
269
  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))
270
+ anchor: t[r + 1] || null,
271
+ childPatches: T(a, p)
272
+ }), a = t[++n], p = e[--c];
273
+ else if (A(l, i))
238
274
  s.push({
239
- type: y.MOVE,
275
+ type: m.MOVE,
240
276
  vnode: l,
241
277
  anchor: a,
242
- childPatches: k(l, i)
243
- }), l = t[--o], i = e[++r];
278
+ childPatches: T(l, i)
279
+ }), l = 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: T(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) {
320
+ function R(t) {
321
+ if (t.type === $) {
286
322
  const s = document.createTextNode(t.props.nodeValue);
287
323
  return t._dom = s, s;
288
324
  }
289
- if (t.type === et) {
325
+ if (t.type === st) {
290
326
  const s = document.createDocumentFragment();
291
327
  for (const n of t.children)
292
- s.appendChild(N(n));
328
+ s.appendChild(R(n));
293
329
  return t._dom = s, s;
294
330
  }
295
331
  const e = document.createElement(t.type);
296
- ft(e, {}, t.props);
332
+ ht(e, {}, t.props);
297
333
  for (const s of t.children)
298
- e.appendChild(N(s));
334
+ e.appendChild(R(s));
299
335
  return t._dom = e, e;
300
336
  }
301
- function ft(t, e, s) {
337
+ function ht(t, e, s) {
302
338
  for (const n in e)
303
- n === "children" || n === "key" || n in s || B(t, n, e[n]);
339
+ n === "children" || n === "key" || n in s || Z(t, n, e[n]);
304
340
  for (const n in s)
305
- n === "children" || n === "key" || e[n] !== s[n] && K(t, n, s[n], e[n]);
341
+ n === "children" || n === "key" || e[n] !== s[n] && Y(t, n, s[n], e[n]);
306
342
  }
307
- function K(t, e, s, n) {
343
+ function Y(t, e, s, n) {
308
344
  if (e.startsWith("on")) {
309
- const o = e.slice(2).toLowerCase();
310
- n && t.removeEventListener(o, n), s && t.addEventListener(o, s);
345
+ const r = e.slice(2).toLowerCase();
346
+ n && t.removeEventListener(r, n), s && t.addEventListener(r, s);
311
347
  } else if (e === "className")
312
348
  t.className = s || "";
313
349
  else if (e === "style" && typeof s == "object") {
314
350
  if (typeof n == "object" && n)
315
- for (const o in n)
316
- o in s || (t.style[o] = "");
351
+ for (const r in n)
352
+ r in s || (t.style[r] = "");
317
353
  Object.assign(t.style, s);
318
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);
319
355
  }
320
- function B(t, e, s) {
356
+ function Z(t, e, s) {
321
357
  e.startsWith("on") ? t.removeEventListener(e.slice(2).toLowerCase(), s) : e === "className" ? t.className = "" : t.removeAttribute(e);
322
358
  }
323
- 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);
359
+ function x(t, e) {
360
+ var s, n, r;
361
+ for (const o of e)
362
+ switch (o.type) {
363
+ case m.CREATE: {
364
+ const c = R(o.newVNode);
365
+ (s = o.anchor) != null && s._dom ? t.insertBefore(c, o.anchor._dom) : t.appendChild(c);
330
366
  break;
331
367
  }
332
- case y.REMOVE: {
333
- const c = r.target._dom;
368
+ case m.REMOVE: {
369
+ const c = o.target._dom;
334
370
  c != null && c.parentNode && c.parentNode.removeChild(c);
335
371
  break;
336
372
  }
337
- case y.REPLACE: {
338
- const c = N(r.newVNode), a = r.oldVNode._dom;
373
+ case m.REPLACE: {
374
+ const c = R(o.newVNode), a = o.oldVNode._dom;
339
375
  a != null && a.parentNode && a.parentNode.replaceChild(c, a);
340
376
  break;
341
377
  }
342
- case y.UPDATE: {
343
- const c = r.target._dom, { set: a, remove: l } = r.propPatches;
378
+ case m.UPDATE: {
379
+ const c = o.target._dom, { set: a, remove: l } = o.propPatches;
344
380
  for (const i of l)
345
- B(c, i, r.target.props[i]);
381
+ Z(c, i, o.target.props[i]);
346
382
  for (const i in a)
347
- K(c, i, a[i], r.target.props[i]);
383
+ Y(c, i, a[i], o.target.props[i]);
348
384
  break;
349
385
  }
350
- case y.TEXT: {
351
- const c = r.oldVNode._dom;
352
- c && (c.nodeValue = r.newVNode.props.nodeValue);
386
+ case m.TEXT: {
387
+ const c = o.oldVNode._dom;
388
+ c && (c.nodeValue = o.newVNode.props.nodeValue);
353
389
  break;
354
390
  }
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);
391
+ case m.MOVE: {
392
+ 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);
358
394
  break;
359
395
  }
360
- case y.CHILDREN: {
361
- const c = r.parent._dom;
362
- c && r.childPatches.length && R(c, r.childPatches);
396
+ case m.CHILDREN: {
397
+ const c = o.parent._dom;
398
+ c && o.childPatches.length && x(c, o.childPatches);
363
399
  break;
364
400
  }
365
401
  }
366
402
  }
367
- const M = /* @__PURE__ */ new WeakMap();
368
- function dt(t, e) {
369
- const s = M.get(e);
403
+ const j = /* @__PURE__ */ new WeakMap();
404
+ function yt(t, e) {
405
+ const s = j.get(e);
370
406
  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);
407
+ const n = w(t, e), r = [];
408
+ M(s.vTree, r);
409
+ const o = T(s.vTree, n);
410
+ x(e, o);
375
411
  const c = [];
376
- n && C(n, c);
412
+ n && M(n, c);
377
413
  const a = new Set(c);
378
- for (const i of o)
414
+ for (const i of r)
379
415
  a.has(i) || i.unmount();
380
- const l = new Set(o);
416
+ const l = new Set(r);
381
417
  for (const i of c)
382
- l.has(i) || i.mount(e, () => L(i, e));
383
- M.set(e, { vTree: n });
418
+ l.has(i) || i.mount(e, () => W(i, e));
419
+ j.set(e, { vTree: n });
384
420
  } else {
385
- const n = T(t, e);
421
+ const n = w(t, e);
386
422
  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 });
423
+ const r = R(n);
424
+ e.appendChild(r);
425
+ const o = [];
426
+ M(n, o);
427
+ for (const c of o)
428
+ c.mount(e, () => W(c, e));
429
+ j.set(e, { vTree: n });
394
430
  }
395
431
  }
396
- function T(t, e) {
432
+ function w(t, e) {
397
433
  var s;
398
434
  if (t == null) return null;
399
435
  if (typeof t.type == "function") {
400
- if (t.type[H]) {
401
- const o = t.type._lifecycle;
436
+ if (t.type[J]) {
437
+ const r = t.type._lifecycle;
402
438
  try {
403
- const r = new it(t.type, t.props), c = t.type(t.props), l = T(c, e) ?? D("");
439
+ const o = new at(t.type, t.props), c = t.type(t.props), l = w(c, e) ?? q("");
404
440
  if (l._instance) {
405
441
  const i = {
406
442
  type: "div",
@@ -408,224 +444,244 @@ function T(t, e) {
408
444
  children: [l],
409
445
  key: t.key
410
446
  };
411
- return i._instance = r, r.lastVTree = i, i;
447
+ return i._instance = o, o.lastVTree = i, i;
412
448
  }
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);
449
+ return l._instance = o, o.lastVTree = l, l;
450
+ } catch (o) {
451
+ if (r != null && r.onError) {
452
+ const c = r.onError({ error: o, props: t.props });
453
+ return w(c, e);
418
454
  }
419
- throw r;
455
+ throw o;
420
456
  }
421
457
  }
422
458
  const n = t.type({ ...t.props, children: t.children });
423
- return T(n, e);
459
+ return w(n, e);
424
460
  }
425
- return (s = t.children) != null && s.length && (t.children = t.children.map((n) => T(n, e)).filter((n) => n != null)), t;
461
+ return (s = t.children) != null && s.length && (t.children = t.children.map((n) => w(n, e)).filter((n) => n != null)), t;
426
462
  }
427
- function L(t, e) {
428
- var o, r;
463
+ function W(t, e) {
464
+ var r, o;
429
465
  if (!t._renderCallback) return;
430
466
  const s = t.connectedFn, n = s._lifecycle;
431
467
  try {
432
468
  const c = s(t.props);
433
- let l = T(c, e) ?? D(""), i;
469
+ let l = w(c, e) ?? q(""), i;
434
470
  if (l._instance && l._instance !== t ? (i = {
435
471
  type: "div",
436
472
  props: { style: { display: "contents" } },
437
473
  children: [l],
438
474
  key: null
439
475
  }, 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);
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);
443
479
  }
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();
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();
451
487
  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));
488
+ const u = new Set(p);
489
+ for (const d of y)
490
+ u.has(d) || d.mount(e, () => W(d, e));
455
491
  n != null && n.onUpdate && n.onUpdate({
456
492
  dom: i == null ? void 0 : i._dom,
457
493
  props: t.props
458
494
  }), t.updateSelected();
459
495
  } catch (c) {
460
496
  if (n != null && n.onError) {
461
- const a = n.onError({ error: c, props: t.props }), l = T(a, e);
497
+ const a = n.onError({ error: c, props: t.props }), l = w(a, e);
462
498
  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);
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);
466
502
  }
467
503
  const i = [];
468
- A(t.lastVTree, i, t);
469
- for (const u of i) u.unmount();
504
+ L(t.lastVTree, i, t);
505
+ for (const p of i) p.unmount();
470
506
  t.lastVTree = l, t.updateSelected();
471
507
  } else
472
508
  throw c;
473
509
  }
474
510
  }
475
- function F(t, e) {
511
+ function H(t, e) {
476
512
  if (!(!t || !t.children))
477
513
  for (let s = 0; s < t.children.length; s++) {
478
514
  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);
515
+ n._instance && n._instance !== e && n._instance.lastVTree && n._instance.lastVTree !== n && (t.children[s] = n._instance.lastVTree), H(t.children[s], e);
480
516
  }
481
517
  }
482
- function C(t, e) {
518
+ function M(t, e) {
483
519
  if (t && (t._instance && e.push(t._instance), t.children))
484
520
  for (const s of t.children)
485
- C(s, e);
521
+ M(s, e);
486
522
  }
487
- function A(t, e, s) {
523
+ function L(t, e, s) {
488
524
  if (t && (t._instance && t._instance !== s && e.push(t._instance), t.children))
489
525
  for (const n of t.children)
490
- A(n, e, s);
526
+ L(n, e, s);
491
527
  }
492
- function P(t) {
528
+ function F(t) {
493
529
  return t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t || "/";
494
530
  }
495
- function $(t) {
531
+ function B(t) {
496
532
  const e = {};
497
533
  if (!t) return e;
498
534
  const s = t.startsWith("?") ? t.slice(1) : t;
499
- return s && new URLSearchParams(s).forEach((o, r) => {
500
- e[r] = o;
535
+ return s && new URLSearchParams(s).forEach((r, o) => {
536
+ e[o] = r;
501
537
  }), e;
502
538
  }
503
- function G(t, e) {
504
- const s = P(t), n = P(e);
539
+ function v(t, e) {
540
+ const s = F(t), n = F(e);
505
541
  if (n === "*")
506
542
  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;
543
+ const r = s === "/" ? [""] : s.split("/").slice(1), o = n === "/" ? [""] : n.split("/").slice(1);
544
+ if (o.length > 0 && o[o.length - 1] === "*") {
545
+ const l = o.slice(0, -1);
546
+ if (r.length < l.length) return null;
511
547
  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])
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])
517
553
  return null;
518
554
  }
519
- const u = o.slice(l.length).join("/");
520
- return i["*"] = u, { params: i };
555
+ const p = r.slice(l.length).join("/");
556
+ return i["*"] = p, { params: i };
521
557
  }
522
- if (o.length !== r.length) return null;
558
+ if (r.length !== o.length) return null;
523
559
  const a = {};
524
- for (let l = 0; l < r.length; l++) {
525
- const i = r[l];
560
+ for (let l = 0; l < o.length; l++) {
561
+ const i = o[l];
526
562
  if (i.startsWith(":"))
527
- a[i.slice(1)] = o[l];
528
- else if (i !== o[l])
563
+ a[i.slice(1)] = r[l];
564
+ else if (i !== r[l])
529
565
  return null;
530
566
  }
531
567
  return { params: a };
532
568
  }
533
- function X(t, e) {
569
+ function G(t, e) {
534
570
  for (const s of e) {
535
- const n = G(t, s.path);
571
+ const n = v(t, s.path);
536
572
  if (n)
537
573
  return { pattern: s.path, params: n.params };
538
574
  }
539
575
  return null;
540
576
  }
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({
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({
543
579
  state: {
544
- path: r,
580
+ path: o,
545
581
  params: (a == null ? void 0 : a.params) ?? {},
546
582
  query: c,
547
583
  matched: (a == null ? void 0 : a.pattern) ?? null
548
584
  },
549
585
  actions: {
550
- _sync: (d, E) => E
586
+ _sync: (f, _) => _
551
587
  }
552
588
  });
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);
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);
555
591
  return {
556
- path: S,
557
- params: (b == null ? void 0 : b.params) ?? {},
558
- query: _,
559
- matched: (b == null ? void 0 : b.pattern) ?? null
592
+ path: V,
593
+ params: (g == null ? void 0 : g.params) ?? {},
594
+ query: E,
595
+ matched: (g == null ? void 0 : g.pattern) ?? null
560
596
  };
561
597
  }
562
- function u(d) {
563
- const E = i(d);
564
- window.history.pushState(null, "", d), l.dispatch("_sync", E);
598
+ function p(f) {
599
+ const _ = i(f);
600
+ window.history.pushState(null, "", f), l.dispatch("_sync", _);
565
601
  }
566
- function h(d) {
567
- const E = i(d);
568
- window.history.replaceState(null, "", d), l.dispatch("_sync", E);
602
+ function y(f) {
603
+ const _ = i(f);
604
+ window.history.replaceState(null, "", f), l.dispatch("_sync", _);
569
605
  }
570
- function p() {
606
+ function h() {
571
607
  window.history.back();
572
608
  }
573
- function f() {
609
+ function u() {
574
610
  window.history.forward();
575
611
  }
576
- function m() {
577
- const d = i(
612
+ function d() {
613
+ const f = i(
578
614
  window.location.pathname + window.location.search
579
615
  );
580
- l.dispatch("_sync", d);
616
+ l.dispatch("_sync", f);
581
617
  }
582
- window.addEventListener("popstate", m);
583
- function x() {
584
- window.removeEventListener("popstate", m);
618
+ window.addEventListener("popstate", d);
619
+ function S() {
620
+ window.removeEventListener("popstate", d);
585
621
  }
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;
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;
591
627
  });
592
- function J(d) {
593
- const { to: E, children: S, ...w } = d;
594
- return W(
628
+ function P(f) {
629
+ const { to: _, children: V, ...O } = f;
630
+ return X(
595
631
  "a",
596
632
  {
597
- ...w,
598
- href: E,
599
- onClick: (_) => {
600
- _.metaKey || _.ctrlKey || _.shiftKey || _.button !== 0 || (_.preventDefault(), u(E));
633
+ ...O,
634
+ href: _,
635
+ onClick: (E) => {
636
+ E.metaKey || E.ctrlKey || E.shiftKey || E.button !== 0 || (E.preventDefault(), p(_));
601
637
  }
602
638
  },
603
- ...S || []
639
+ ...V || []
604
640
  );
605
641
  }
606
- function Y(d) {
607
- return h(d.to), null;
642
+ function C(f) {
643
+ return y(f.to), null;
608
644
  }
609
645
  return {
610
646
  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
647
+ navigate: p,
648
+ redirect: y,
649
+ back: h,
650
+ forward: u,
651
+ destroy: S,
652
+ Route: b,
653
+ Link: P,
654
+ Redirect: C
655
+ };
656
+ }
657
+ function Et() {
658
+ return (t, e) => {
659
+ const s = `[pulse] ${t.actionName}`;
660
+ console.group(s), console.log("prev state", t.prevState), console.log("payload", t.payload), e(), console.log("next state", t.nextState), console.groupEnd();
661
+ };
662
+ }
663
+ function gt(t, e) {
664
+ const s = (e == null ? void 0 : e.maxEntries) ?? 1 / 0;
665
+ return (n, r) => {
666
+ r(), t.push({
667
+ actionName: n.actionName,
668
+ payload: n.payload,
669
+ prevState: n.prevState,
670
+ nextState: n.nextState ?? n.prevState,
671
+ timestamp: Date.now()
672
+ }), t.length > s && t.splice(0, t.length - s);
619
673
  };
620
674
  }
621
675
  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
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
630
686
  };
631
687
  //# sourceMappingURL=pulse.js.map