@fluixi/devtools 1.0.0-alpha.108 → 1.0.0-alpha.110

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.
Files changed (83) hide show
  1. package/dist/callsite.mjs +4 -63
  2. package/dist/change-view.mjs +6 -106
  3. package/dist/chunk-235BSS43.mjs +185 -0
  4. package/dist/chunk-2ACSNLS6.mjs +87 -0
  5. package/dist/chunk-2VDMQ3VF.mjs +520 -0
  6. package/dist/chunk-33U2S43X.mjs +121 -0
  7. package/dist/chunk-B3SAJ7QG.mjs +72 -0
  8. package/dist/chunk-BTCWJTXR.mjs +216 -0
  9. package/dist/chunk-CPZWLBCQ.mjs +35 -0
  10. package/dist/chunk-D25KZZBZ.mjs +212 -0
  11. package/dist/chunk-EBSROPWJ.mjs +314 -0
  12. package/dist/chunk-F664XLZL.mjs +743 -0
  13. package/dist/chunk-FY5K3QVT.mjs +35 -0
  14. package/dist/chunk-GDQXCOQB.mjs +43 -0
  15. package/dist/chunk-JLNWT36I.mjs +118 -0
  16. package/dist/chunk-JTHAZJJZ.mjs +780 -0
  17. package/dist/chunk-L6XQGNMW.mjs +106 -0
  18. package/dist/chunk-MN6O673L.mjs +90 -0
  19. package/dist/chunk-NDUBBBNL.mjs +70 -0
  20. package/dist/chunk-NT7YMK77.mjs +157 -0
  21. package/dist/chunk-NVULLJDH.mjs +120 -0
  22. package/dist/chunk-NWLSDERQ.mjs +68 -0
  23. package/dist/chunk-OPIGF5XB.mjs +184 -0
  24. package/dist/chunk-P5I7DWFX.mjs +292 -0
  25. package/dist/chunk-PSSBFXBD.mjs +155 -0
  26. package/dist/chunk-PTQ5VCYE.mjs +103 -0
  27. package/dist/chunk-UAEJ3N7F.mjs +76 -0
  28. package/dist/chunk-V6DKWEYD.mjs +67 -0
  29. package/dist/chunk-VO2V7AC5.mjs +80 -0
  30. package/dist/chunk-WGQH7RUW.mjs +25 -0
  31. package/dist/chunk-Z6KYHEKY.mjs +64 -0
  32. package/dist/copy.mjs +3 -39
  33. package/dist/describe.mjs +3 -31
  34. package/dist/detail-panel.cjs +2 -1
  35. package/dist/detail-panel.d.ts.map +1 -1
  36. package/dist/detail-panel.js +1 -0
  37. package/dist/detail-panel.mjs +6 -280
  38. package/dist/diff.mjs +4 -201
  39. package/dist/dom.mjs +7 -176
  40. package/dist/export.mjs +6 -207
  41. package/dist/float.mjs +5 -206
  42. package/dist/format.mjs +5 -151
  43. package/dist/graph-view.mjs +9 -875
  44. package/dist/highlight.mjs +6 -113
  45. package/dist/history.cjs +14 -2
  46. package/dist/history.d.ts +8 -1
  47. package/dist/history.d.ts.map +1 -1
  48. package/dist/history.js +15 -2
  49. package/dist/history.mjs +4 -70
  50. package/dist/hook.cjs +26 -1
  51. package/dist/hook.d.ts +4 -0
  52. package/dist/hook.d.ts.map +1 -1
  53. package/dist/hook.js +13 -0
  54. package/dist/hook.mjs +16 -1719
  55. package/dist/index.cjs +34 -5
  56. package/dist/index.mjs +106 -4673
  57. package/dist/inspector.mjs +11 -677
  58. package/dist/instrument.mjs +9 -486
  59. package/dist/kind-filter.mjs +6 -148
  60. package/dist/menu.mjs +4 -116
  61. package/dist/observe.cjs +15 -1
  62. package/dist/observe.d.ts +2 -0
  63. package/dist/observe.d.ts.map +1 -1
  64. package/dist/observe.js +3 -0
  65. package/dist/observe.mjs +14 -1510
  66. package/dist/palette.mjs +6 -28
  67. package/dist/path.mjs +3 -21
  68. package/dist/plugin.mjs +9 -57
  69. package/dist/plugins/context.mjs +6 -71
  70. package/dist/plugins/directives.mjs +8 -68
  71. package/dist/plugins/index.cjs +1 -1
  72. package/dist/plugins/index.mjs +13 -136
  73. package/dist/source.mjs +12 -93
  74. package/dist/timeline.cjs +5 -2
  75. package/dist/timeline.d.ts.map +1 -1
  76. package/dist/timeline.js +5 -1
  77. package/dist/timeline.mjs +7 -323
  78. package/dist/tree.mjs +11 -558
  79. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  80. package/dist/value-pane.mjs +6 -196
  81. package/dist/wire.cjs +1 -1
  82. package/dist/wire.mjs +6 -86
  83. package/package.json +3 -3
package/dist/callsite.mjs CHANGED
@@ -1,66 +1,7 @@
1
- // src/callsite.ts
2
- var EXTENSION = ["chrome-extension://", "moz-extension://", "safari-web-extension://", "extension://"];
3
- var INTERNAL = [
4
- "/packages/reactive/",
5
- "/packages/dom/",
6
- "/packages/core/",
7
- "/packages/devtools/",
8
- "/packages/web-components/",
9
- "/packages/auth/",
10
- "/packages/oauth2/",
11
- "/packages/session/",
12
- "/packages/router/",
13
- "/packages/head/",
14
- "/packages/start/",
15
- "/packages/server/",
16
- "/packages/template-runtime/",
17
- "/@fluixi/",
18
- "node_modules",
19
- "fluixi-devtools",
20
- ...EXTENSION
21
- ];
22
- var REPORTING = [
23
- "/packages/reactive/src/lib/signal/graph/",
24
- "/packages/devtools/",
25
- "fluixi-devtools",
26
- // Not a fallback either: naming the agent as where a node came from is worse than nothing.
27
- ...EXTENSION
28
- ];
29
- var FRAME = /(?:at\s+(?:[^(]*\()?)([^()\s]+):(\d+):(\d+)\)?$/;
30
- var isInternal = (frame) => INTERNAL.some((part) => frame.includes(part));
31
- function locate(frame, origin) {
32
- const match = FRAME.exec(frame);
33
- if (!match) return void 0;
34
- let file = match[1];
35
- if (origin && file.startsWith(origin)) file = file.slice(origin.length);
36
- file = file.replace(/^\/@fs\//, "/").replace(/\?.*$/, "").replace(/^\//, "");
37
- return file ? { file, line: Number(match[2]), column: Number(match[3]) } : void 0;
38
- }
39
- function callSite(stack, origin) {
40
- if (!stack) return void 0;
41
- let fallback;
42
- for (const line of stack.split("\n")) {
43
- const frame = line.trim();
44
- if (!frame.startsWith("at ")) continue;
45
- if (!isInternal(frame)) {
46
- const location = locate(frame, origin);
47
- if (location) return { location, external: false };
48
- continue;
49
- }
50
- if (!fallback && !REPORTING.some((part) => frame.includes(part))) fallback = locate(frame, origin);
51
- }
52
- return fallback ? { location: { ...fallback, external: true }, external: true } : void 0;
53
- }
54
- function currentCallSite(origin) {
55
- const errors = Error;
56
- const limit = errors.stackTraceLimit;
57
- errors.stackTraceLimit = 50;
58
- try {
59
- return callSite(new Error().stack, origin);
60
- } finally {
61
- errors.stackTraceLimit = limit;
62
- }
63
- }
1
+ import {
2
+ callSite,
3
+ currentCallSite
4
+ } from "./chunk-NWLSDERQ.mjs";
64
5
  export {
65
6
  callSite,
66
7
  currentCallSite
@@ -1,109 +1,9 @@
1
- // src/copy.ts
2
- function confirmOn(button, said = "copied") {
3
- if (!button) return;
4
- const was = button.textContent;
5
- button.textContent = said;
6
- setTimeout(() => {
7
- button.textContent = was;
8
- }, 1200);
9
- }
10
- function fallback(text, button) {
11
- try {
12
- const doc = button?.ownerDocument ?? document;
13
- const area = doc.createElement("textarea");
14
- area.value = text;
15
- area.setAttribute("readonly", "");
16
- area.style.position = "fixed";
17
- area.style.opacity = "0";
18
- doc.body.appendChild(area);
19
- area.select();
20
- doc.execCommand("copy");
21
- area.remove();
22
- confirmOn(button);
23
- return true;
24
- } catch {
25
- return false;
26
- }
27
- }
28
- async function copyText(text, button) {
29
- const clipboard = globalThis.navigator?.clipboard;
30
- if (clipboard?.writeText) {
31
- try {
32
- await clipboard.writeText(text);
33
- confirmOn(button);
34
- return true;
35
- } catch {
36
- }
37
- }
38
- return fallback(text, button);
39
- }
40
-
41
- // src/change-view.ts
42
- var escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
43
- var SIGN = { added: "+", removed: "−", changed: "~" };
44
- function pretty(json) {
45
- if (!json) return void 0;
46
- try {
47
- return JSON.stringify(JSON.parse(json), null, 2);
48
- } catch {
49
- return void 0;
50
- }
51
- }
52
- function sideOf(text, json, cls) {
53
- const block = pretty(json);
54
- if (!block) return `<span class="ch-${cls}">${escape(text ?? "")}</span>`;
55
- return `<div class="ch-block ch-${cls}"><button type="button" class="ch-copy" title="Copy" data-copy="${escape(block)}">copy</button><pre class="ch-json">${escape(block)}</pre></div>`;
56
- }
57
- function changeRows(change, limit = Infinity) {
58
- if (!change?.entries?.length) return "";
59
- const shown = change.entries.slice(0, limit);
60
- const hidden = change.entries.length - shown.length + (change.more ?? 0);
61
- const rows = shown.map((entry) => {
62
- const from = sideOf(entry.from, entry.fromJson, "from");
63
- const to = sideOf(entry.to, entry.toJson, "to");
64
- const sides = entry.op === "changed" ? `${from}<span class="ch-arrow">→</span>${to}` : entry.op === "added" ? to : from;
65
- const stacked = entry.fromJson || entry.toJson ? " ch-stacked" : "";
66
- return `<div class="ch-row ch-${entry.op}${stacked}"><span class="ch-sign">${SIGN[entry.op] ?? "·"}</span><span class="ch-key">${escape(entry.key)}</span><span class="ch-sides">${sides}</span></div>`;
67
- }).join("");
68
- const size = change.length ? `<div class="ch-size">${change.length.from} → ${change.length.to} items</div>` : "";
69
- return `<div class="ch-list">${size}${rows}${hidden > 0 ? `<div class="ch-more">and ${hidden} more</div>` : ""}</div>`;
70
- }
71
- function handleCopyClick(event) {
72
- const button = event.target?.closest?.(".ch-copy");
73
- if (!button) return false;
74
- void copyText(button.dataset.copy ?? "", button);
75
- return true;
76
- }
77
- var CHANGE_CSS = `
78
- .ch-list { margin-top: 4px; font-family: ui-monospace, monospace; font-size: 11px; }
79
- .ch-size { color: var(--fx-muted, #8a90a2); margin-bottom: 2px; }
80
- .ch-row { display: flex; gap: 6px; align-items: baseline; padding: 1px 0; }
81
- .ch-row.ch-stacked { align-items: flex-start; padding: 3px 0; }
82
- .ch-sign { flex: none; width: 9px; text-align: center; }
83
- .ch-added .ch-sign { color: var(--state, #34d399); }
84
- .ch-removed .ch-sign { color: var(--fx-write, #fb7185); }
85
- .ch-changed .ch-sign { color: var(--effect, #fbbf24); }
86
- .ch-key { flex: none; color: var(--fx-muted, #8a90a2); }
87
- .ch-sides { min-width: 0; flex: 1; overflow-wrap: anywhere; }
88
- .ch-stacked .ch-sides { display: flex; flex-direction: column; gap: 2px; }
89
- .ch-from { color: var(--fx-muted, #8a90a2); }
90
- .ch-row:not(.ch-stacked) .ch-from { text-decoration: line-through; }
91
- .ch-arrow { color: var(--fx-muted, #8a90a2); margin: 0 4px; }
92
- .ch-to { color: var(--fx-label, #e7e9ee); }
93
- .ch-more { color: var(--fx-muted, #8a90a2); margin-top: 2px; }
94
- /* In the corner: an object can be tall, and a button under it is a scroll away. */
95
- .ch-block { position: relative; border-radius: 4px; border: 1px solid var(--fx-line, #ffffff14); }
96
- .ch-block.ch-from { opacity: .72; }
97
- .ch-json { margin: 0; padding: 5px 7px; overflow-x: auto; white-space: pre; font: inherit; }
98
- .ch-copy {
99
- position: absolute; top: 3px; right: 3px; padding: 1px 6px; cursor: pointer;
100
- font: inherit; font-size: 9.5px; opacity: 0; transition: opacity .12s;
101
- border: 1px solid var(--fx-line, #ffffff26); border-radius: 3px;
102
- background: var(--fx-panel, #14161c); color: var(--fx-muted, #8a90a2);
103
- }
104
- .ch-block:hover .ch-copy, .ch-copy:focus { opacity: 1; }
105
- .ch-copy:hover { color: var(--fx-label, #e7e9ee); }
106
- `;
1
+ import {
2
+ CHANGE_CSS,
3
+ changeRows,
4
+ handleCopyClick
5
+ } from "./chunk-UAEJ3N7F.mjs";
6
+ import "./chunk-GDQXCOQB.mjs";
107
7
  export {
108
8
  CHANGE_CSS,
109
9
  changeRows,
@@ -0,0 +1,185 @@
1
+ import {
2
+ CHANGE_CSS,
3
+ changeRows,
4
+ handleCopyClick
5
+ } from "./chunk-UAEJ3N7F.mjs";
6
+
7
+ // src/detail-panel.ts
8
+ var escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
9
+ var clock = (t) => {
10
+ const d = new Date(t);
11
+ const pad = (n, w = 2) => String(n).padStart(w, "0");
12
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}`;
13
+ };
14
+ var VERBS = {
15
+ write: "written",
16
+ ran: "ran",
17
+ created: "made",
18
+ disposed: "gone",
19
+ mark: "marked"
20
+ };
21
+ var MIN_W = 320;
22
+ var MIN_H = 200;
23
+ function draggable(handle, onMove) {
24
+ handle.addEventListener("pointerdown", (event) => {
25
+ if (event.button !== 0) return;
26
+ if (event.target.closest("button")) return;
27
+ event.preventDefault();
28
+ event.stopPropagation();
29
+ handle.setPointerCapture(event.pointerId);
30
+ let lastX = event.clientX;
31
+ let lastY = event.clientY;
32
+ const move = (e) => {
33
+ onMove(e.clientX - lastX, e.clientY - lastY);
34
+ lastX = e.clientX;
35
+ lastY = e.clientY;
36
+ };
37
+ const stop = () => {
38
+ handle.removeEventListener("pointermove", move);
39
+ handle.removeEventListener("pointerup", stop);
40
+ handle.removeEventListener("pointercancel", stop);
41
+ handle.removeEventListener("lostpointercapture", stop);
42
+ if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
43
+ };
44
+ handle.addEventListener("pointermove", move);
45
+ handle.addEventListener("pointerup", stop);
46
+ handle.addEventListener("pointercancel", stop);
47
+ handle.addEventListener("lostpointercapture", stop);
48
+ });
49
+ }
50
+ function createDetailPanel(host, options = {}) {
51
+ const panel = host.ownerDocument.createElement("div");
52
+ panel.className = "dp-panel";
53
+ panel.hidden = true;
54
+ panel.innerHTML = '<div class="dp-bar"><span class="dp-title"></span><button type="button" class="dp-close" title="Close" aria-label="Close">✕</button></div><div class="dp-body"></div><div class="dp-grip" title="Drag to resize"></div>';
55
+ host.appendChild(panel);
56
+ const title = panel.querySelector(".dp-title");
57
+ const body = panel.querySelector(".dp-body");
58
+ const bar = panel.querySelector(".dp-bar");
59
+ const grip = panel.querySelector(".dp-grip");
60
+ let x = 0;
61
+ let y = 0;
62
+ let width = 520;
63
+ let height = 380;
64
+ let open = false;
65
+ const place = () => {
66
+ panel.style.left = `${Math.round(x)}px`;
67
+ panel.style.top = `${Math.round(y)}px`;
68
+ panel.style.width = `${Math.round(width)}px`;
69
+ panel.style.height = `${Math.round(height)}px`;
70
+ };
71
+ draggable(bar, (dx, dy) => {
72
+ const view = panel.ownerDocument.defaultView;
73
+ x = Math.max(0, Math.min((view?.innerWidth ?? width) - 60, x + dx));
74
+ y = Math.max(0, Math.min((view?.innerHeight ?? height) - 30, y + dy));
75
+ place();
76
+ });
77
+ draggable(grip, (dx, dy) => {
78
+ width = Math.max(MIN_W, width + dx);
79
+ height = Math.max(MIN_H, height + dy);
80
+ place();
81
+ });
82
+ panel.querySelector(".dp-close")?.addEventListener("click", () => close());
83
+ body.addEventListener("click", (e) => {
84
+ if (handleCopyClick(e)) return;
85
+ const row = e.target.closest(".dp-node");
86
+ if (row?.dataset.id) options.onPick?.(Number(row.dataset.id));
87
+ });
88
+ function close() {
89
+ open = false;
90
+ panel.hidden = true;
91
+ }
92
+ return {
93
+ open(commit, graph) {
94
+ const nameOf = (e) => graph.get(e.id)?.label ?? e.label ?? `#${e.id}`;
95
+ const cause = commit.cause;
96
+ title.textContent = cause ? `${nameOf(cause)} · ${clock(commit.t)}` : `${commit.commit === 0 ? "first render" : `commit ${commit.commit}`} · ${clock(commit.t)}`;
97
+ const headline = cause && cause.from !== void 0 && cause.to !== void 0 ? `<div class="dp-change"><span class="ch-from">${escape(cause.from)}</span><span class="ch-arrow">→</span><span class="ch-to">${escape(cause.to)}</span></div>` : "";
98
+ const groups = ["write", "ran", "created", "disposed"].map((kind) => {
99
+ const rows = commit.events.filter((e) => e.kind === kind && e !== cause);
100
+ if (!rows.length) return "";
101
+ const seen = /* @__PURE__ */ new Map();
102
+ for (const event of rows) {
103
+ const found = seen.get(event.id);
104
+ if (found) found.count++;
105
+ else seen.set(event.id, { name: nameOf(event), count: 1 });
106
+ }
107
+ const items = [...seen].map(
108
+ ([id, { name, count }]) => `<button type="button" class="dp-node" data-id="${id}">${escape(name)}${count > 1 ? ` ×${count}` : ""}</button>`
109
+ ).join("");
110
+ return `<div class="dp-group"><div class="dp-verb">${VERBS[kind]}</div><div class="dp-nodes">${items}</div></div>`;
111
+ }).join("");
112
+ const node = cause ? graph.get(cause.id) : void 0;
113
+ const where = (t) => {
114
+ if (!t.source) return "";
115
+ const file = (t.source.file ?? "").split("/").pop() ?? "";
116
+ const out = t.source.compiled;
117
+ const tail = out && out.line !== t.source.line ? ` · out ${out.line}` : "";
118
+ return ` — ${file}:${t.source.line ?? ""}${tail}`;
119
+ };
120
+ const targets = node?.targets?.length ? `<div class="dp-group"><div class="dp-verb">updates</div><div class="dp-targets">${node.targets.map(
121
+ (t) => `<div>${escape(t.name ? `${t.name} of ${t.element}` : t.element)}<span class="dp-where">${escape(where(t))}</span></div>`
122
+ ).join("")}</div></div>` : "";
123
+ body.innerHTML = headline + changeRows(cause?.change) + groups + targets;
124
+ if (!open) {
125
+ const view = panel.ownerDocument.defaultView;
126
+ x = Math.max(12, ((view?.innerWidth ?? 900) - width) / 2);
127
+ y = Math.max(12, ((view?.innerHeight ?? 600) - height) / 3);
128
+ place();
129
+ }
130
+ open = true;
131
+ panel.hidden = false;
132
+ },
133
+ close,
134
+ get isOpen() {
135
+ return open;
136
+ },
137
+ destroy() {
138
+ panel.remove();
139
+ }
140
+ };
141
+ }
142
+ var DETAIL_PANEL_CSS = `
143
+ .dp-panel {
144
+ position: fixed; z-index: 40; display: flex; flex-direction: column;
145
+ border: 1px solid var(--fx-line, #ffffff26); border-radius: 8px;
146
+ background: var(--fx-panel, #14161c); color: var(--fx-label, #e7e9ee);
147
+ box-shadow: 0 12px 40px rgba(0, 0, 0, .45); overflow: hidden;
148
+ }
149
+ .dp-panel[hidden] { display: none; }
150
+ .dp-bar {
151
+ display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px;
152
+ cursor: move; user-select: none;
153
+ border-bottom: 1px solid var(--fx-line, #ffffff1f);
154
+ }
155
+ .dp-title { font-family: ui-monospace, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
156
+ .dp-close {
157
+ margin-left: auto; width: 22px; height: 20px; padding: 0; cursor: pointer; font: inherit; font-size: 11px;
158
+ border: 1px solid var(--fx-line, #ffffff1f); border-radius: 4px;
159
+ background: transparent; color: var(--fx-muted, #8a90a2);
160
+ }
161
+ .dp-close:hover { color: var(--fx-label, #e7e9ee); }
162
+ .dp-body { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; }
163
+ .dp-change { font-family: ui-monospace, monospace; font-size: 12px; overflow-wrap: anywhere; }
164
+ .dp-group { margin-top: 10px; }
165
+ .dp-verb { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--fx-muted, #8a90a2); }
166
+ .dp-nodes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
167
+ .dp-node {
168
+ padding: 2px 7px; cursor: pointer; font: inherit; font-family: ui-monospace, monospace; font-size: 11px;
169
+ border: 1px solid var(--fx-line, #ffffff1f); border-radius: 999px;
170
+ background: transparent; color: var(--fx-label, #e7e9ee);
171
+ }
172
+ .dp-node:hover { border-color: var(--fx-accent, #5eead4); }
173
+ .dp-targets { margin-top: 4px; font-family: ui-monospace, monospace; font-size: 11px; color: var(--fx-label, #e7e9ee); }
174
+ .dp-where { color: var(--fx-muted, #8a90a2); }
175
+ /* Bottom-right, where every desktop puts it. */
176
+ .dp-grip {
177
+ position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize;
178
+ background: linear-gradient(135deg, transparent 50%, var(--fx-line, #ffffff40) 50%);
179
+ }
180
+ ${CHANGE_CSS}`;
181
+
182
+ export {
183
+ createDetailPanel,
184
+ DETAIL_PANEL_CSS
185
+ };
@@ -0,0 +1,87 @@
1
+ // src/history.ts
2
+ var OFF = {
3
+ wrote() {
4
+ },
5
+ ran() {
6
+ },
7
+ created() {
8
+ },
9
+ disposed() {
10
+ },
11
+ marked() {
12
+ },
13
+ take: () => [],
14
+ dropped: 0,
15
+ clear() {
16
+ }
17
+ };
18
+ function createHistory(limit) {
19
+ if (limit <= 0) return OFF;
20
+ let events = [];
21
+ let seq = 0;
22
+ let commit = 0;
23
+ let dropped = 0;
24
+ let held = false;
25
+ const push = (event) => {
26
+ events.push({ ...event, seq: seq++, t: Date.now(), commit });
27
+ if (events.length > limit) {
28
+ dropped += events.length - limit;
29
+ events = events.slice(-limit);
30
+ }
31
+ };
32
+ return {
33
+ wrote(id, by, detail) {
34
+ if (by === void 0) {
35
+ if (held) held = false;
36
+ else commit++;
37
+ }
38
+ push({ kind: "write", id, by, ...detail });
39
+ },
40
+ ran(id, by) {
41
+ push({ kind: "ran", id, by });
42
+ },
43
+ created(id, by, label) {
44
+ push({ kind: "created", id, by, label });
45
+ },
46
+ disposed(id, label) {
47
+ push({ kind: "disposed", id, label });
48
+ },
49
+ marked(label) {
50
+ commit++;
51
+ held = true;
52
+ push({ kind: "mark", id: -1, label });
53
+ },
54
+ take() {
55
+ const taken = events;
56
+ events = [];
57
+ return taken;
58
+ },
59
+ get dropped() {
60
+ return dropped;
61
+ },
62
+ clear() {
63
+ events = [];
64
+ dropped = 0;
65
+ }
66
+ };
67
+ }
68
+ function toCommits(events) {
69
+ const byNumber = /* @__PURE__ */ new Map();
70
+ for (const event of events) {
71
+ const bucket = byNumber.get(event.commit);
72
+ if (bucket) bucket.push(event);
73
+ else byNumber.set(event.commit, [event]);
74
+ }
75
+ return [...byNumber.entries()].sort((a, b) => a[0] - b[0]).map(([commit, group]) => ({
76
+ commit,
77
+ t: group[0].t,
78
+ events: group,
79
+ cause: group.find((e) => e.kind === "write" && e.by === void 0),
80
+ mark: group.find((e) => e.kind === "mark")
81
+ }));
82
+ }
83
+
84
+ export {
85
+ createHistory,
86
+ toCommits
87
+ };