@shane_il/pulse 0.1.1 → 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.
@@ -0,0 +1,1147 @@
1
+ var oe = Object.defineProperty;
2
+ var se = (e, t, n) => t in e ? oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var b = (e, t, n) => se(e, typeof t != "symbol" ? t + "" : t, n);
4
+ let L = !1;
5
+ const A = /* @__PURE__ */ new Set();
6
+ function re(e) {
7
+ A.add(e), L || (L = !0, queueMicrotask(ie));
8
+ }
9
+ function ie() {
10
+ const e = [...A];
11
+ A.clear(), L = !1;
12
+ for (const t of e)
13
+ t();
14
+ }
15
+ const q = Symbol("PULSE_CONNECTED"), F = globalThis;
16
+ F.__PULSE_HOOKS__ || (F.__PULSE_HOOKS__ = { onMount: null, onUnmount: null });
17
+ const E = F.__PULSE_HOOKS__;
18
+ function ce(e, t) {
19
+ E.onMount = e, E.onUnmount = t;
20
+ }
21
+ function le(e, t) {
22
+ return function(o) {
23
+ const s = e || {};
24
+ function r(i) {
25
+ const a = {};
26
+ for (const u in s) {
27
+ const { store: c, selector: h } = s[u];
28
+ a[u] = h(c.getState());
29
+ }
30
+ return o({ ...a, ...i });
31
+ }
32
+ return r[q] = !0, r._bindings = s, r._innerComponent = o, r.displayName = `Connected(${o.displayName || o.name || "Anonymous"})`, r;
33
+ };
34
+ }
35
+ class ae {
36
+ constructor(t, n) {
37
+ b(this, "connectedFn");
38
+ b(this, "props");
39
+ b(this, "prevSelected");
40
+ b(this, "unsubscribers");
41
+ b(this, "lastVTree");
42
+ b(this, "parentDom");
43
+ b(this, "_renderCallback");
44
+ b(this, "_mountCleanup");
45
+ this.connectedFn = t, this.props = n, this.prevSelected = {}, this.unsubscribers = [], this.lastVTree = null, this.parentDom = null, this._renderCallback = null, this._mountCleanup = null;
46
+ }
47
+ mount(t, n) {
48
+ var r;
49
+ this.parentDom = t, this._renderCallback = n;
50
+ const o = this.connectedFn._bindings;
51
+ for (const i in o) {
52
+ const { store: a, selector: u } = o[i];
53
+ this.prevSelected[i] = u(a.getState());
54
+ }
55
+ for (const i in o) {
56
+ const { store: a } = o[i], u = a.subscribe(() => {
57
+ this._onStoreChange();
58
+ });
59
+ this.unsubscribers.push(u);
60
+ }
61
+ const s = this.connectedFn._lifecycle;
62
+ if (s != null && s.onMount) {
63
+ const i = s.onMount({
64
+ dom: (r = this.lastVTree) == null ? void 0 : r._dom,
65
+ props: this.props
66
+ });
67
+ typeof i == "function" && (this._mountCleanup = i);
68
+ }
69
+ E.onMount && E.onMount(this);
70
+ }
71
+ _onStoreChange() {
72
+ const t = this.connectedFn._bindings;
73
+ let n = !1;
74
+ for (const o in t) {
75
+ const { store: s, selector: r } = t[o], i = r(s.getState());
76
+ if (!pe(i, this.prevSelected[o])) {
77
+ n = !0;
78
+ break;
79
+ }
80
+ }
81
+ n && re(this._renderCallback);
82
+ }
83
+ updateSelected() {
84
+ const t = this.connectedFn._bindings;
85
+ for (const n in t) {
86
+ const { store: o, selector: s } = t[n];
87
+ this.prevSelected[n] = s(o.getState());
88
+ }
89
+ }
90
+ unmount() {
91
+ E.onUnmount && E.onUnmount(this), this._mountCleanup && (this._mountCleanup(), this._mountCleanup = null);
92
+ const t = this.connectedFn._lifecycle;
93
+ t != null && t.onDestroy && t.onDestroy({ props: this.props });
94
+ for (const n of this.unsubscribers)
95
+ n();
96
+ this.unsubscribers = [], this._renderCallback = null;
97
+ }
98
+ }
99
+ function pe(e, t) {
100
+ if (Object.is(e, t)) return !0;
101
+ if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
102
+ const n = Object.keys(e), o = Object.keys(t);
103
+ if (n.length !== o.length) return !1;
104
+ for (const s of n)
105
+ if (!Object.prototype.hasOwnProperty.call(t, s) || !Object.is(e[s], t[s]))
106
+ return !1;
107
+ return !0;
108
+ }
109
+ function G(e) {
110
+ let t = e.state;
111
+ const n = e.actions, o = /* @__PURE__ */ new Set(), s = e.middleware;
112
+ function r() {
113
+ return t;
114
+ }
115
+ function i() {
116
+ for (const f of o)
117
+ f(t);
118
+ }
119
+ function a(f, y) {
120
+ const S = n[f];
121
+ if (!S)
122
+ throw new Error(`[pulse] Unknown action: "${f}"`);
123
+ const x = S(t, y);
124
+ x !== t && (t = x, i());
125
+ }
126
+ function u(f, y) {
127
+ if (f === "__devtools_replace__") {
128
+ t = y, i();
129
+ return;
130
+ }
131
+ const S = n[f];
132
+ if (!S)
133
+ throw new Error(`[pulse] Unknown action: "${f}"`);
134
+ const x = {
135
+ store: l,
136
+ actionName: f,
137
+ payload: y,
138
+ prevState: t,
139
+ nextState: void 0
140
+ };
141
+ let w = 0;
142
+ function z() {
143
+ if (w < s.length) {
144
+ const C = s[w++];
145
+ C(x, z);
146
+ } else {
147
+ const C = S(x.prevState, x.payload);
148
+ x.nextState = C, C !== t && (t = C, i());
149
+ }
150
+ }
151
+ z();
152
+ }
153
+ const c = s && s.length > 0 ? u : a;
154
+ function h(f) {
155
+ return o.add(f), () => {
156
+ o.delete(f);
157
+ };
158
+ }
159
+ function g(f) {
160
+ return { store: l, selector: f };
161
+ }
162
+ const l = {
163
+ getState: r,
164
+ dispatch: c,
165
+ subscribe: h,
166
+ select: g
167
+ };
168
+ return e.name && (l.name = e.name), l;
169
+ }
170
+ function ue(e, t) {
171
+ return (o, s) => {
172
+ s(), e.push({
173
+ actionName: o.actionName,
174
+ payload: o.payload,
175
+ prevState: o.prevState,
176
+ nextState: o.nextState ?? o.prevState,
177
+ timestamp: Date.now()
178
+ }), e.length > 1 / 0 && e.splice(0, e.length - 1 / 0);
179
+ };
180
+ }
181
+ let fe = 1;
182
+ class de {
183
+ constructor() {
184
+ b(this, "stores", /* @__PURE__ */ new Map());
185
+ b(this, "components", /* @__PURE__ */ new Map());
186
+ b(this, "listeners", /* @__PURE__ */ new Set());
187
+ }
188
+ registerStore(t, n, o) {
189
+ const s = o || t.name || `store_${this.stores.size}`;
190
+ this.stores.set(s, { store: t, history: n, name: s }), t.subscribe(() => {
191
+ this.emit({ type: "action-dispatched", storeName: s });
192
+ }), this.emit({ type: "store-registered", storeName: s });
193
+ }
194
+ getStoreNames() {
195
+ return Array.from(this.stores.keys());
196
+ }
197
+ getStoreState(t) {
198
+ var n;
199
+ return (n = this.stores.get(t)) == null ? void 0 : n.store.getState();
200
+ }
201
+ getTrackedStore(t) {
202
+ return this.stores.get(t);
203
+ }
204
+ getHistory(t) {
205
+ var o;
206
+ if (t)
207
+ return ((o = this.stores.get(t)) == null ? void 0 : o.history) ?? [];
208
+ const n = [];
209
+ for (const s of this.stores.values())
210
+ n.push(...s.history);
211
+ return n.sort((s, r) => s.timestamp - r.timestamp);
212
+ }
213
+ trackComponent(t, n) {
214
+ const o = fe++;
215
+ return this.components.set(o, { id: o, displayName: t, storeNames: n }), this.emit({ type: "component-mounted", data: { id: o, displayName: t, storeNames: n } }), o;
216
+ }
217
+ untrackComponent(t) {
218
+ const n = this.components.get(t);
219
+ n && (this.components.delete(t), this.emit({ type: "component-unmounted", data: { id: t, displayName: n.displayName } }));
220
+ }
221
+ getComponents() {
222
+ return Array.from(this.components.values());
223
+ }
224
+ on(t) {
225
+ return this.listeners.add(t), () => {
226
+ this.listeners.delete(t);
227
+ };
228
+ }
229
+ emit(t) {
230
+ for (const n of this.listeners)
231
+ n(t);
232
+ }
233
+ }
234
+ function Ge(e, t) {
235
+ const n = [], o = ue(n), s = G({
236
+ ...t,
237
+ middleware: [o, ...t.middleware || []]
238
+ });
239
+ return e.registerStore(s, n, t.name), { store: s, history: n };
240
+ }
241
+ const B = Symbol("TEXT_NODE"), he = Symbol("FRAGMENT");
242
+ function H(e) {
243
+ return {
244
+ type: B,
245
+ props: { nodeValue: String(e) },
246
+ children: [],
247
+ key: null
248
+ };
249
+ }
250
+ function ye(e) {
251
+ return e == null || typeof e == "boolean" ? null : typeof e == "string" || typeof e == "number" ? H(e) : e;
252
+ }
253
+ function J(e) {
254
+ const t = [];
255
+ for (const n of e)
256
+ if (Array.isArray(n))
257
+ t.push(...J(n));
258
+ else {
259
+ const o = ye(n);
260
+ o !== null && t.push(o);
261
+ }
262
+ return t;
263
+ }
264
+ function p(e, t, ...n) {
265
+ t = t || {};
266
+ const o = t.key ?? null;
267
+ t.key !== void 0 && (t = { ...t }, delete t.key);
268
+ const s = J(n);
269
+ return { type: e, props: t, children: s, key: o };
270
+ }
271
+ const m = {
272
+ CREATE: "CREATE",
273
+ REMOVE: "REMOVE",
274
+ REPLACE: "REPLACE",
275
+ UPDATE: "UPDATE",
276
+ TEXT: "TEXT",
277
+ MOVE: "MOVE",
278
+ CHILDREN: "CHILDREN"
279
+ };
280
+ function _(e, t) {
281
+ if (t == null && e == null) return [];
282
+ if (t == null) return [{ type: m.REMOVE, target: e }];
283
+ if (e == null) return [{ type: m.CREATE, newVNode: t }];
284
+ if (e.type !== t.type)
285
+ return [{ type: m.REPLACE, oldVNode: e, newVNode: t }];
286
+ if (t._dom = e._dom, e.type === B)
287
+ return e.props.nodeValue !== t.props.nodeValue ? [{ type: m.TEXT, oldVNode: e, newVNode: t }] : [];
288
+ const n = [], o = me(e.props, t.props);
289
+ o && n.push({ type: m.UPDATE, target: e, propPatches: o });
290
+ const s = ge(e.children, t.children);
291
+ return s.length && n.push({ type: m.CHILDREN, parent: e, childPatches: s }), n;
292
+ }
293
+ function me(e, t) {
294
+ const n = {}, o = [];
295
+ let s = !1;
296
+ for (const r in t)
297
+ r !== "children" && e[r] !== t[r] && (n[r] = t[r], s = !0);
298
+ for (const r in e)
299
+ r !== "children" && (r in t || (o.push(r), s = !0));
300
+ return s ? { set: n, remove: o } : null;
301
+ }
302
+ function O(e, t) {
303
+ return e == null || t == null ? !1 : e.type === t.type && e.key === t.key;
304
+ }
305
+ function K(e, t) {
306
+ const n = /* @__PURE__ */ new Set();
307
+ let o = 0, s = 0;
308
+ for (const r of e)
309
+ r != null && (r.key != null ? (o++, n.has(r.key) && console.warn(
310
+ `[pulse] Duplicate key "${String(r.key)}" in ${t} children. Keys must be unique among siblings.`
311
+ ), n.add(r.key)) : s++);
312
+ o > 0 && s > 0 && console.warn(
313
+ `[pulse] Mixed keyed and unkeyed children in ${t} list (${o} keyed, ${s} unkeyed). Either all children should have keys or none should.`
314
+ );
315
+ }
316
+ function ge(e, t) {
317
+ var g;
318
+ process.env.NODE_ENV !== "production" && (K(e, "old"), K(t, "new"));
319
+ const n = [];
320
+ let o = 0, s = e.length - 1, r = 0, i = t.length - 1, a = e[o], u = e[s], c = t[r], h = t[i];
321
+ for (; o <= s && r <= i; ) {
322
+ if (a == null) {
323
+ a = e[++o];
324
+ continue;
325
+ }
326
+ if (u == null) {
327
+ u = e[--s];
328
+ continue;
329
+ }
330
+ if (O(a, c))
331
+ n.push(..._(a, c)), a = e[++o], c = t[++r];
332
+ else if (O(u, h))
333
+ n.push(..._(u, h)), u = e[--s], h = t[--i];
334
+ else if (O(a, h))
335
+ n.push({
336
+ type: m.MOVE,
337
+ vnode: a,
338
+ anchor: e[s + 1] || null,
339
+ childPatches: _(a, h)
340
+ }), a = e[++o], h = t[--i];
341
+ else if (O(u, c))
342
+ n.push({
343
+ type: m.MOVE,
344
+ vnode: u,
345
+ anchor: a,
346
+ childPatches: _(u, c)
347
+ }), u = e[--s], c = t[++r];
348
+ else
349
+ break;
350
+ }
351
+ if (o <= s && r <= i) {
352
+ const l = /* @__PURE__ */ new Map();
353
+ for (let f = o; f <= s; f++) {
354
+ const y = (g = e[f]) == null ? void 0 : g.key;
355
+ y != null && l.set(y, f);
356
+ }
357
+ for (; r <= i; ) {
358
+ c = t[r];
359
+ const f = c.key != null ? l.get(c.key) : void 0;
360
+ if (f !== void 0) {
361
+ const y = e[f];
362
+ n.push({
363
+ type: m.MOVE,
364
+ vnode: y,
365
+ anchor: e[o] || null,
366
+ childPatches: _(y, c)
367
+ }), e[f] = null, l.delete(c.key);
368
+ } else
369
+ n.push({
370
+ type: m.CREATE,
371
+ newVNode: c,
372
+ anchor: e[o] || null
373
+ });
374
+ r++;
375
+ }
376
+ for (let f = o; f <= s; f++)
377
+ e[f] != null && n.push({ type: m.REMOVE, target: e[f] });
378
+ }
379
+ if (o > s) {
380
+ const l = t[i + 1] || null;
381
+ for (let f = r; f <= i; f++)
382
+ n.push({ type: m.CREATE, newVNode: t[f], anchor: l });
383
+ } else if (r > i)
384
+ for (let l = o; l <= s; l++)
385
+ e[l] != null && n.push({ type: m.REMOVE, target: e[l] });
386
+ return n;
387
+ }
388
+ function v(e) {
389
+ if (e.type === B) {
390
+ const n = document.createTextNode(e.props.nodeValue);
391
+ return e._dom = n, n;
392
+ }
393
+ if (e.type === he) {
394
+ const n = document.createDocumentFragment();
395
+ for (const o of e.children)
396
+ n.appendChild(v(o));
397
+ return e._dom = n, n;
398
+ }
399
+ const t = document.createElement(e.type);
400
+ be(t, {}, e.props);
401
+ for (const n of e.children)
402
+ t.appendChild(v(n));
403
+ return e._dom = t, t;
404
+ }
405
+ function be(e, t, n) {
406
+ for (const o in t)
407
+ o === "children" || o === "key" || o in n || Y(e, o, t[o]);
408
+ for (const o in n)
409
+ o === "children" || o === "key" || t[o] !== n[o] && Q(e, o, n[o], t[o]);
410
+ }
411
+ function Q(e, t, n, o) {
412
+ if (t.startsWith("on")) {
413
+ const s = t.slice(2).toLowerCase();
414
+ o && e.removeEventListener(s, o), n && e.addEventListener(s, n);
415
+ } else if (t === "className")
416
+ e.className = n || "";
417
+ else if (t === "style" && typeof n == "object") {
418
+ if (typeof o == "object" && o)
419
+ for (const s in o)
420
+ s in n || (e.style[s] = "");
421
+ Object.assign(e.style, n);
422
+ } else t === "ref" ? typeof n == "function" && n(e) : n === !0 ? e.setAttribute(t, "") : n === !1 || n == null ? e.removeAttribute(t) : e.setAttribute(t, n);
423
+ }
424
+ function Y(e, t, n) {
425
+ t.startsWith("on") ? e.removeEventListener(t.slice(2).toLowerCase(), n) : t === "className" ? e.className = "" : e.removeAttribute(t);
426
+ }
427
+ function P(e, t) {
428
+ var n, o, s;
429
+ for (const r of t)
430
+ switch (r.type) {
431
+ case m.CREATE: {
432
+ const i = v(r.newVNode);
433
+ (n = r.anchor) != null && n._dom ? e.insertBefore(i, r.anchor._dom) : e.appendChild(i);
434
+ break;
435
+ }
436
+ case m.REMOVE: {
437
+ const i = r.target._dom;
438
+ i != null && i.parentNode && i.parentNode.removeChild(i);
439
+ break;
440
+ }
441
+ case m.REPLACE: {
442
+ const i = v(r.newVNode), a = r.oldVNode._dom;
443
+ a != null && a.parentNode && a.parentNode.replaceChild(i, a);
444
+ break;
445
+ }
446
+ case m.UPDATE: {
447
+ const i = r.target._dom, { set: a, remove: u } = r.propPatches;
448
+ for (const c of u)
449
+ Y(i, c, r.target.props[c]);
450
+ for (const c in a)
451
+ Q(i, c, a[c], r.target.props[c]);
452
+ break;
453
+ }
454
+ case m.TEXT: {
455
+ const i = r.oldVNode._dom;
456
+ i && (i.nodeValue = r.newVNode.props.nodeValue);
457
+ break;
458
+ }
459
+ case m.MOVE: {
460
+ const i = r.vnode._dom;
461
+ i && ((o = r.anchor) != null && o._dom ? e.insertBefore(i, r.anchor._dom) : e.appendChild(i)), (s = r.childPatches) != null && s.length && i && P(i, r.childPatches);
462
+ break;
463
+ }
464
+ case m.CHILDREN: {
465
+ const i = r.parent._dom;
466
+ i && r.childPatches.length && P(i, r.childPatches);
467
+ break;
468
+ }
469
+ }
470
+ }
471
+ const R = /* @__PURE__ */ new WeakMap();
472
+ function Se(e, t) {
473
+ const n = R.get(t);
474
+ if (n) {
475
+ const o = k(e, t), s = [];
476
+ I(n.vTree, s);
477
+ const r = _(n.vTree, o);
478
+ P(t, r);
479
+ const i = [];
480
+ o && I(o, i);
481
+ const a = new Set(i);
482
+ for (const c of s)
483
+ a.has(c) || c.unmount();
484
+ const u = new Set(s);
485
+ for (const c of i)
486
+ u.has(c) || c.mount(t, () => U(c, t));
487
+ R.set(t, { vTree: o });
488
+ } else {
489
+ const o = k(e, t);
490
+ if (!o) return;
491
+ const s = v(o);
492
+ t.appendChild(s);
493
+ const r = [];
494
+ I(o, r);
495
+ for (const i of r)
496
+ i.mount(t, () => U(i, t));
497
+ R.set(t, { vTree: o });
498
+ }
499
+ }
500
+ function k(e, t) {
501
+ var n;
502
+ if (e == null) return null;
503
+ if (typeof e.type == "function") {
504
+ if (e.type[q]) {
505
+ const s = e.type._lifecycle;
506
+ try {
507
+ const r = new ae(e.type, e.props), i = e.type(e.props), u = k(i, t) ?? H("");
508
+ if (u._instance) {
509
+ const c = {
510
+ type: "div",
511
+ props: { style: { display: "contents" } },
512
+ children: [u],
513
+ key: e.key
514
+ };
515
+ return c._instance = r, r.lastVTree = c, c;
516
+ }
517
+ return u._instance = r, r.lastVTree = u, u;
518
+ } catch (r) {
519
+ if (s != null && s.onError) {
520
+ const i = s.onError({ error: r, props: e.props });
521
+ return k(i, t);
522
+ }
523
+ throw r;
524
+ }
525
+ }
526
+ const o = e.type({ ...e.props, children: e.children });
527
+ return k(o, t);
528
+ }
529
+ return (n = e.children) != null && n.length && (e.children = e.children.map((o) => k(o, t)).filter((o) => o != null)), e;
530
+ }
531
+ function U(e, t) {
532
+ var s, r;
533
+ if (!e._renderCallback) return;
534
+ const n = e.connectedFn, o = n._lifecycle;
535
+ try {
536
+ const i = n(e.props);
537
+ let u = k(i, t) ?? H(""), c;
538
+ if (u._instance && u._instance !== e ? (c = {
539
+ type: "div",
540
+ props: { style: { display: "contents" } },
541
+ children: [u],
542
+ key: null
543
+ }, c._instance = e) : (u._instance = e, c = u), e.lastVTree) {
544
+ D(e.lastVTree, e);
545
+ const y = _(e.lastVTree, c), S = ((s = e.lastVTree._dom) == null ? void 0 : s.parentNode) || t;
546
+ P(S, y), c._dom || (c._dom = e.lastVTree._dom);
547
+ }
548
+ const h = [];
549
+ M(e.lastVTree, h, e);
550
+ const g = [];
551
+ M(c, g, e);
552
+ const l = new Set(g);
553
+ for (const y of h)
554
+ l.has(y) || y.unmount();
555
+ e.lastVTree = c;
556
+ const f = new Set(h);
557
+ for (const y of g)
558
+ f.has(y) || y.mount(t, () => U(y, t));
559
+ o != null && o.onUpdate && o.onUpdate({
560
+ dom: c == null ? void 0 : c._dom,
561
+ props: e.props
562
+ }), e.updateSelected();
563
+ } catch (i) {
564
+ if (o != null && o.onError) {
565
+ const a = o.onError({ error: i, props: e.props }), u = k(a, t);
566
+ if (e.lastVTree && u) {
567
+ D(e.lastVTree, e);
568
+ const h = _(e.lastVTree, u), g = ((r = e.lastVTree._dom) == null ? void 0 : r.parentNode) || t;
569
+ P(g, h), u._dom || (u._dom = e.lastVTree._dom);
570
+ }
571
+ const c = [];
572
+ M(e.lastVTree, c, e);
573
+ for (const h of c) h.unmount();
574
+ e.lastVTree = u, e.updateSelected();
575
+ } else
576
+ throw i;
577
+ }
578
+ }
579
+ function D(e, t) {
580
+ if (!(!e || !e.children))
581
+ for (let n = 0; n < e.children.length; n++) {
582
+ const o = e.children[n];
583
+ o._instance && o._instance !== t && o._instance.lastVTree && o._instance.lastVTree !== o && (e.children[n] = o._instance.lastVTree), D(e.children[n], t);
584
+ }
585
+ }
586
+ function I(e, t) {
587
+ if (e && (e._instance && t.push(e._instance), e.children))
588
+ for (const n of e.children)
589
+ I(n, t);
590
+ }
591
+ function M(e, t, n) {
592
+ if (e && (e._instance && e._instance !== n && t.push(e._instance), e.children))
593
+ for (const o of e.children)
594
+ M(o, t, n);
595
+ }
596
+ function W(e, t, n) {
597
+ const o = e.getTrackedStore(t);
598
+ if (!o)
599
+ throw new Error(`[pulse-devtools] Unknown store: "${t}"`);
600
+ const { store: s, history: r } = o;
601
+ if (n < 0 || n >= r.length)
602
+ throw new Error(
603
+ `[pulse-devtools] Index ${n} out of range (0..${r.length - 1})`
604
+ );
605
+ const i = r[n].nextState;
606
+ s.dispatch("__devtools_replace__", i), e.emit({ type: "time-travel", storeName: t, data: { entryIndex: n } });
607
+ }
608
+ function Je(e, t, n) {
609
+ const o = e.getTrackedStore(t);
610
+ if (!o)
611
+ throw new Error(`[pulse-devtools] Unknown store: "${t}"`);
612
+ const { store: s, history: r } = o;
613
+ if (n < 0 || n >= r.length)
614
+ throw new Error(
615
+ `[pulse-devtools] Index ${n} out of range (0..${r.length - 1})`
616
+ );
617
+ const i = r.slice(n), a = r[n].prevState;
618
+ s.dispatch("__devtools_replace__", a);
619
+ for (const u of i)
620
+ s.dispatch(u.actionName, u.payload);
621
+ e.emit({ type: "time-travel", storeName: t, data: { replayFrom: n } });
622
+ }
623
+ const d = {
624
+ base: "#1e1e2e",
625
+ surface0: "#313244",
626
+ surface1: "#45475a",
627
+ overlay0: "#6c7086",
628
+ text: "#cdd6f4",
629
+ subtext0: "#a6adc8",
630
+ blue: "#89b4fa",
631
+ green: "#a6e3a1",
632
+ yellow: "#f9e2af",
633
+ mauve: "#cba6f7",
634
+ teal: "#94e2d5",
635
+ peach: "#fab387"
636
+ }, xe = {
637
+ position: "fixed",
638
+ bottom: "0",
639
+ left: "0",
640
+ right: "0",
641
+ height: "320px",
642
+ backgroundColor: d.base,
643
+ color: d.text,
644
+ fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",
645
+ fontSize: "12px",
646
+ lineHeight: "1.5",
647
+ zIndex: "2147483647",
648
+ display: "flex",
649
+ flexDirection: "column",
650
+ borderTop: `2px solid ${d.mauve}`,
651
+ overflow: "hidden"
652
+ }, _e = {
653
+ display: "flex",
654
+ alignItems: "center",
655
+ backgroundColor: d.surface0,
656
+ borderBottom: `1px solid ${d.surface1}`,
657
+ padding: "0 8px",
658
+ height: "32px",
659
+ flexShrink: "0"
660
+ }, ke = (e) => ({
661
+ background: "none",
662
+ border: "none",
663
+ color: e ? d.mauve : d.subtext0,
664
+ fontFamily: "inherit",
665
+ fontSize: "12px",
666
+ padding: "6px 12px",
667
+ cursor: "pointer",
668
+ borderBottom: e ? `2px solid ${d.mauve}` : "2px solid transparent",
669
+ marginBottom: "-1px"
670
+ }), Ee = {
671
+ background: "none",
672
+ border: "none",
673
+ color: d.overlay0,
674
+ fontSize: "16px",
675
+ cursor: "pointer",
676
+ marginLeft: "auto",
677
+ padding: "4px 8px",
678
+ fontFamily: "inherit"
679
+ }, Te = {
680
+ flex: "1",
681
+ overflow: "auto",
682
+ padding: "8px 12px"
683
+ }, we = {
684
+ display: "flex",
685
+ height: "100%",
686
+ gap: "1px"
687
+ }, Ce = {
688
+ width: "200px",
689
+ flexShrink: "0",
690
+ borderRight: `1px solid ${d.surface1}`,
691
+ overflow: "auto",
692
+ padding: "4px 0"
693
+ }, Ne = {
694
+ flex: "1",
695
+ overflow: "auto",
696
+ padding: "8px"
697
+ }, ve = (e) => ({
698
+ padding: "4px 12px",
699
+ cursor: "pointer",
700
+ backgroundColor: e ? d.surface1 : "transparent",
701
+ color: e ? d.blue : d.text
702
+ }), X = {
703
+ color: d.mauve
704
+ }, V = {
705
+ color: d.green
706
+ }, Pe = {
707
+ color: d.yellow
708
+ }, Oe = {
709
+ color: d.peach
710
+ }, T = {
711
+ color: d.overlay0,
712
+ fontStyle: "italic"
713
+ }, Ve = (e) => ({
714
+ padding: "4px 8px",
715
+ cursor: "pointer",
716
+ backgroundColor: e ? d.surface1 : "transparent",
717
+ borderLeft: e ? `3px solid ${d.blue}` : "3px solid transparent",
718
+ display: "flex",
719
+ justifyContent: "space-between",
720
+ alignItems: "center"
721
+ }), Z = {
722
+ color: d.blue,
723
+ fontWeight: "bold"
724
+ }, Ie = {
725
+ color: d.overlay0,
726
+ fontSize: "10px"
727
+ }, Me = {
728
+ width: "100%",
729
+ accentColor: d.mauve,
730
+ margin: "4px 0 8px"
731
+ }, $e = {
732
+ width: "100%",
733
+ backgroundColor: d.surface0,
734
+ border: `1px solid ${d.surface1}`,
735
+ color: d.text,
736
+ padding: "4px 8px",
737
+ fontFamily: "inherit",
738
+ fontSize: "12px",
739
+ borderRadius: "4px",
740
+ outline: "none",
741
+ marginBottom: "8px",
742
+ boxSizing: "border-box"
743
+ }, Re = {
744
+ padding: "4px 8px",
745
+ borderBottom: `1px solid ${d.surface0}`
746
+ }, Le = {
747
+ color: d.teal,
748
+ fontWeight: "bold"
749
+ }, Ae = {
750
+ color: d.overlay0,
751
+ fontSize: "10px",
752
+ marginLeft: "8px"
753
+ }, ee = {
754
+ display: "inline-block",
755
+ backgroundColor: d.surface1,
756
+ color: d.subtext0,
757
+ padding: "1px 6px",
758
+ borderRadius: "8px",
759
+ fontSize: "10px",
760
+ marginLeft: "4px"
761
+ }, Fe = {
762
+ color: d.mauve,
763
+ fontWeight: "bold",
764
+ fontSize: "12px",
765
+ marginRight: "8px"
766
+ };
767
+ function j(e, t) {
768
+ if (e === null)
769
+ return p("span", { style: T }, "null");
770
+ if (e === void 0)
771
+ return p("span", { style: T }, "undefined");
772
+ if (typeof e == "string")
773
+ return p("span", { style: Pe }, `"${e}"`);
774
+ if (typeof e == "boolean")
775
+ return p("span", { style: Oe }, String(e));
776
+ if (typeof e == "number")
777
+ return p("span", { style: V }, String(e));
778
+ if (Array.isArray(e))
779
+ return e.length === 0 ? p("span", { style: V }, "[]") : t > 4 ? p("span", { style: T }, "[…]") : p(
780
+ "div",
781
+ { style: { paddingLeft: "12px" } },
782
+ ...e.map(
783
+ (n, o) => p(
784
+ "div",
785
+ { key: o },
786
+ p("span", { style: X }, `${o}: `),
787
+ j(n, t + 1)
788
+ )
789
+ )
790
+ );
791
+ if (typeof e == "object") {
792
+ const n = Object.keys(e);
793
+ return n.length === 0 ? p("span", { style: V }, "{}") : t > 4 ? p("span", { style: T }, "{…}") : p(
794
+ "div",
795
+ { style: { paddingLeft: "12px" } },
796
+ ...n.map(
797
+ (o) => p(
798
+ "div",
799
+ { key: o },
800
+ p("span", { style: X }, `${o}: `),
801
+ j(e[o], t + 1)
802
+ )
803
+ )
804
+ );
805
+ }
806
+ return p("span", { style: V }, String(e));
807
+ }
808
+ function Ue({
809
+ storeNames: e,
810
+ selectedStore: t,
811
+ storeStates: n,
812
+ onSelectStore: o
813
+ }) {
814
+ const s = t ? n[t] : null;
815
+ return p(
816
+ "div",
817
+ { style: we },
818
+ p(
819
+ "div",
820
+ { style: Ce },
821
+ ...e.map(
822
+ (r) => p("div", {
823
+ key: r,
824
+ style: ve(r === t),
825
+ onClick: () => o(r)
826
+ }, r)
827
+ )
828
+ ),
829
+ p(
830
+ "div",
831
+ { style: Ne },
832
+ t ? p(
833
+ "div",
834
+ null,
835
+ p(
836
+ "div",
837
+ { style: { marginBottom: "8px", color: d.subtext0 } },
838
+ "State of ",
839
+ p("span", { style: Z }, t)
840
+ ),
841
+ s != null ? j(s, 0) : p("span", { style: T }, "No state")
842
+ ) : p("span", { style: T }, "Select a store")
843
+ )
844
+ );
845
+ }
846
+ function De(e) {
847
+ const t = new Date(e), n = (o) => String(o).padStart(2, "0");
848
+ return `${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`;
849
+ }
850
+ function je({
851
+ actionLog: e,
852
+ timeTravelIndex: t,
853
+ filter: n,
854
+ onFilterChange: o,
855
+ onTravelTo: s,
856
+ onSliderChange: r
857
+ }) {
858
+ const i = n ? e.filter((a) => a.actionName.toLowerCase().includes(n.toLowerCase())) : e;
859
+ return p(
860
+ "div",
861
+ { style: { height: "100%", display: "flex", flexDirection: "column" } },
862
+ // Filter
863
+ p("input", {
864
+ style: $e,
865
+ placeholder: "Filter actions…",
866
+ value: n,
867
+ onInput: (a) => o(a.target.value)
868
+ }),
869
+ // Slider
870
+ e.length > 0 ? p(
871
+ "div",
872
+ { style: { flexShrink: "0" } },
873
+ p("input", {
874
+ type: "range",
875
+ style: Me,
876
+ min: "0",
877
+ max: String(e.length - 1),
878
+ value: String(t),
879
+ onInput: (a) => r(Number(a.target.value))
880
+ }),
881
+ p(
882
+ "div",
883
+ { style: { color: d.overlay0, fontSize: "10px", marginBottom: "4px" } },
884
+ `${t + 1} / ${e.length}`
885
+ )
886
+ ) : null,
887
+ // Action list
888
+ p(
889
+ "div",
890
+ { style: { flex: "1", overflow: "auto" } },
891
+ ...i.map((a, u) => {
892
+ const c = e.indexOf(a);
893
+ return p(
894
+ "div",
895
+ {
896
+ key: c,
897
+ style: Ve(c === t),
898
+ onClick: () => s(c)
899
+ },
900
+ p(
901
+ "span",
902
+ null,
903
+ p("span", { style: Z }, a.actionName),
904
+ a.payload !== void 0 ? p(
905
+ "span",
906
+ { style: { color: d.subtext0, marginLeft: "8px" } },
907
+ typeof a.payload == "object" ? JSON.stringify(a.payload) : String(a.payload)
908
+ ) : null
909
+ ),
910
+ p("span", { style: Ie }, De(a.timestamp))
911
+ );
912
+ }),
913
+ i.length === 0 ? p(
914
+ "div",
915
+ { style: { color: d.overlay0, padding: "8px" } },
916
+ e.length === 0 ? "No actions yet" : "No matching actions"
917
+ ) : null
918
+ )
919
+ );
920
+ }
921
+ function Be({
922
+ components: e
923
+ }) {
924
+ return e.length === 0 ? p(
925
+ "div",
926
+ { style: { color: d.overlay0, padding: "8px" } },
927
+ "No connected components mounted"
928
+ ) : p(
929
+ "div",
930
+ null,
931
+ ...e.map(
932
+ (t) => p(
933
+ "div",
934
+ { key: t.id, style: Re },
935
+ p("span", { style: Le }, t.displayName),
936
+ t.storeNames.length > 0 ? p(
937
+ "span",
938
+ { style: Ae },
939
+ t.storeNames.map(
940
+ (n) => p("span", { key: n, style: ee }, n)
941
+ )
942
+ ) : null
943
+ )
944
+ )
945
+ );
946
+ }
947
+ function He() {
948
+ return G({
949
+ state: {
950
+ open: !1,
951
+ activeTab: "stores",
952
+ selectedStore: null,
953
+ timeTravelIndex: -1,
954
+ storeNames: [],
955
+ storeStates: {},
956
+ actionLog: [],
957
+ filter: "",
958
+ components: []
959
+ },
960
+ actions: {
961
+ toggle: (e) => ({ ...e, open: !e.open }),
962
+ open: (e) => ({ ...e, open: !0 }),
963
+ close: (e) => ({ ...e, open: !1 }),
964
+ setTab: (e, t) => ({ ...e, activeTab: t }),
965
+ selectStore: (e, t) => ({ ...e, selectedStore: t }),
966
+ setFilter: (e, t) => ({ ...e, filter: t }),
967
+ setTimeTravelIndex: (e, t) => ({ ...e, timeTravelIndex: t }),
968
+ sync: (e, t) => ({ ...e, ...t })
969
+ }
970
+ });
971
+ }
972
+ function ze({
973
+ open: e,
974
+ activeTab: t,
975
+ selectedStore: n,
976
+ timeTravelIndex: o,
977
+ storeNames: s,
978
+ storeStates: r,
979
+ actionLog: i,
980
+ filter: a,
981
+ components: u,
982
+ panelActions: c
983
+ }) {
984
+ if (!e) return null;
985
+ const h = [
986
+ { id: "stores", label: "Stores" },
987
+ { id: "actions", label: "Actions" },
988
+ { id: "components", label: "Components" }
989
+ ];
990
+ let g;
991
+ return t === "stores" ? g = Ue({
992
+ storeNames: s,
993
+ selectedStore: n,
994
+ storeStates: r,
995
+ onSelectStore: c.selectStore
996
+ }) : t === "actions" ? g = je({
997
+ actionLog: i,
998
+ timeTravelIndex: o,
999
+ filter: a,
1000
+ onFilterChange: c.setFilter,
1001
+ onTravelTo: c.travelTo,
1002
+ onSliderChange: c.sliderChange
1003
+ }) : g = Be({ components: u }), p(
1004
+ "div",
1005
+ { style: xe },
1006
+ // Tab bar (all children keyed to avoid mixed key warnings)
1007
+ p(
1008
+ "div",
1009
+ { style: _e },
1010
+ p("span", { key: "title", style: Fe }, "Pulse"),
1011
+ ...h.map(
1012
+ (l) => p("button", {
1013
+ key: l.id,
1014
+ style: ke(l.id === t),
1015
+ onClick: () => c.setTab(l.id)
1016
+ }, l.label)
1017
+ ),
1018
+ p("span", { key: "badge", style: ee }, `${s.length} stores`),
1019
+ p("button", {
1020
+ key: "close",
1021
+ style: Ee,
1022
+ onClick: c.close
1023
+ }, "×")
1024
+ ),
1025
+ // Content
1026
+ p("div", { style: Te }, g)
1027
+ );
1028
+ }
1029
+ function Ke(e, t) {
1030
+ const n = He();
1031
+ t && t(n);
1032
+ let o = !1;
1033
+ function s() {
1034
+ if (!o) {
1035
+ o = !0;
1036
+ try {
1037
+ const l = e.getStoreNames(), f = {};
1038
+ for (const w of l)
1039
+ f[w] = e.getStoreState(w);
1040
+ const S = n.getState().selectedStore || l[0] || null, x = S ? e.getHistory(S) : [];
1041
+ n.dispatch("sync", {
1042
+ storeNames: l,
1043
+ storeStates: f,
1044
+ actionLog: x,
1045
+ timeTravelIndex: x.length > 0 ? x.length - 1 : -1,
1046
+ selectedStore: S,
1047
+ components: e.getComponents()
1048
+ });
1049
+ } finally {
1050
+ o = !1;
1051
+ }
1052
+ }
1053
+ }
1054
+ e.on((l) => {
1055
+ l.type === "component-mounted" || l.type === "component-unmounted" || s();
1056
+ });
1057
+ const r = {
1058
+ selectStore: (l) => {
1059
+ n.dispatch("selectStore", l);
1060
+ const f = e.getHistory(l);
1061
+ n.dispatch("sync", {
1062
+ actionLog: f,
1063
+ timeTravelIndex: f.length > 0 ? f.length - 1 : -1
1064
+ });
1065
+ },
1066
+ setTab: (l) => n.dispatch("setTab", l),
1067
+ setFilter: (l) => n.dispatch("setFilter", l),
1068
+ close: () => n.dispatch("close"),
1069
+ travelTo: (l) => {
1070
+ const f = n.getState().selectedStore;
1071
+ f && (W(e, f, l), n.dispatch("setTimeTravelIndex", l));
1072
+ },
1073
+ sliderChange: (l) => {
1074
+ const f = n.getState().selectedStore;
1075
+ f && (W(e, f, l), n.dispatch("setTimeTravelIndex", l));
1076
+ }
1077
+ }, i = le({
1078
+ open: n.select((l) => l.open),
1079
+ activeTab: n.select((l) => l.activeTab),
1080
+ selectedStore: n.select((l) => l.selectedStore),
1081
+ timeTravelIndex: n.select((l) => l.timeTravelIndex),
1082
+ storeNames: n.select((l) => l.storeNames),
1083
+ storeStates: n.select((l) => l.storeStates),
1084
+ actionLog: n.select((l) => l.actionLog),
1085
+ filter: n.select((l) => l.filter),
1086
+ components: n.select((l) => l.components)
1087
+ })((l) => ze({ ...l, panelActions: r }));
1088
+ let a = null;
1089
+ function u() {
1090
+ a || (a = document.createElement("div"), a.id = "pulse-devtools-root", document.body.appendChild(a), Se(p(i, null), a), s());
1091
+ }
1092
+ function c() {
1093
+ u(), n.dispatch("open");
1094
+ }
1095
+ function h() {
1096
+ n.dispatch("close");
1097
+ }
1098
+ function g() {
1099
+ u(), n.dispatch("toggle");
1100
+ }
1101
+ return { openPanel: c, closePanel: h, togglePanel: g, panelStore: n };
1102
+ }
1103
+ const $ = new de(), te = /* @__PURE__ */ new WeakSet();
1104
+ function We(e) {
1105
+ te.add(e);
1106
+ }
1107
+ ce(
1108
+ (e) => {
1109
+ const t = e.connectedFn._bindings || {}, n = Object.values(t).map((i) => i.store);
1110
+ if (n.length > 0 && n.every((i) => te.has(i)))
1111
+ return;
1112
+ const o = n.map((i) => i.name || "unnamed"), s = e.connectedFn.displayName || "Unknown", r = $.trackComponent(s, o);
1113
+ e._devtoolsId = r;
1114
+ },
1115
+ (e) => {
1116
+ const t = e._devtoolsId;
1117
+ t != null && $.untrackComponent(t);
1118
+ }
1119
+ );
1120
+ let N = null;
1121
+ function ne() {
1122
+ return N || (N = Ke($, We)), N;
1123
+ }
1124
+ function Qe() {
1125
+ ne().openPanel();
1126
+ }
1127
+ function Ye() {
1128
+ N && N.closePanel();
1129
+ }
1130
+ function Xe() {
1131
+ ne().togglePanel();
1132
+ }
1133
+ typeof window < "u" && (window.addEventListener("keydown", (e) => {
1134
+ e.ctrlKey && e.shiftKey && e.key === "P" && (e.preventDefault(), Xe());
1135
+ }), window.__PULSE_DEVTOOLS__ = $);
1136
+ export {
1137
+ de as PulseDevtools,
1138
+ We as _markInternalStore,
1139
+ Ye as closePanel,
1140
+ $ as devtools,
1141
+ Ge as instrumentStore,
1142
+ Qe as openPanel,
1143
+ Je as replayFrom,
1144
+ Xe as togglePanel,
1145
+ W as travelTo
1146
+ };
1147
+ //# sourceMappingURL=devtools.js.map