@demlik/tea 0.7.0 → 0.8.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/chart/index.d.ts +72 -789
- package/dist/chart/index.js +4 -232
- package/dist/chart/index.js.map +1 -1
- package/dist/chart/inspect/index.d.ts +85 -0
- package/dist/chart/inspect/index.js +5 -0
- package/dist/chart/inspect/index.js.map +1 -0
- package/dist/chart/inspect/react.d.ts +112 -0
- package/dist/chart/inspect/react.js +11 -0
- package/dist/chart/inspect/react.js.map +1 -0
- package/dist/chart/inspect/styles.css +286 -0
- package/dist/chart/lane/index.d.ts +361 -0
- package/dist/chart/lane/index.js +9 -0
- package/dist/chart/lane/index.js.map +1 -0
- package/dist/chart/lane/react.d.ts +83 -0
- package/dist/chart/lane/react.js +559 -0
- package/dist/chart/lane/react.js.map +1 -0
- package/dist/chart/lane/styles.css +498 -0
- package/dist/chart/report/index.d.ts +116 -0
- package/dist/chart/report/index.js +32 -0
- package/dist/chart/report/index.js.map +1 -0
- package/dist/chunk-5KJKJOFC.js +758 -0
- package/dist/chunk-5KJKJOFC.js.map +1 -0
- package/dist/chunk-E6GEDSF4.js +307 -0
- package/dist/chunk-E6GEDSF4.js.map +1 -0
- package/dist/chunk-JER5O7PQ.js +416 -0
- package/dist/chunk-JER5O7PQ.js.map +1 -0
- package/dist/chunk-UOC2PL46.js +13 -0
- package/dist/chunk-UOC2PL46.js.map +1 -0
- package/dist/chunk-WRAA7GVZ.js +209 -0
- package/dist/chunk-WRAA7GVZ.js.map +1 -0
- package/dist/chunk-ZCL7SCBK.js +685 -0
- package/dist/chunk-ZCL7SCBK.js.map +1 -0
- package/dist/chunk-ZD6PNZBK.js +457 -0
- package/dist/chunk-ZD6PNZBK.js.map +1 -0
- package/dist/devtools/index.js +2 -207
- package/dist/devtools/index.js.map +1 -1
- package/dist/fold-Blbhru48.d.ts +435 -0
- package/dist/graph-CcjWZVrd.d.ts +923 -0
- package/dist/machine-viz/index.d.ts +18 -1
- package/dist/machine-viz/index.js +2 -8
- package/dist/machine-viz/index.js.map +1 -1
- package/dist/reducer-BqyoVyBG.d.ts +447 -0
- package/dist/run-BVeqJDBF.d.ts +713 -0
- package/dist/samples-DCt6nF8H.d.ts +59 -0
- package/package.json +24 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/machine-viz/mermaid-id.ts
|
|
2
|
+
function safeId(raw) {
|
|
3
|
+
const cleaned = raw.replace(/[^A-Za-z0-9_]/g, "_");
|
|
4
|
+
if (cleaned === "") return "_empty";
|
|
5
|
+
return /^[0-9]/.test(cleaned) ? `s_${cleaned}` : cleaned;
|
|
6
|
+
}
|
|
7
|
+
function safeLabel(raw) {
|
|
8
|
+
return raw.replace(/["\n\r;:]/g, " ").trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { safeId, safeLabel };
|
|
12
|
+
//# sourceMappingURL=chunk-UOC2PL46.js.map
|
|
13
|
+
//# sourceMappingURL=chunk-UOC2PL46.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/machine-viz/mermaid-id.ts"],"names":[],"mappings":";AAsBO,SAAS,OAAO,GAAA,EAAqB;AAC1C,EAAA,MAAM,OAAA,GAAU,GAAA,CAAI,OAAA,CAAQ,gBAAA,EAAkB,GAAG,CAAA;AACjD,EAAA,IAAI,OAAA,KAAY,IAAI,OAAO,QAAA;AAC3B,EAAA,OAAO,SAAS,IAAA,CAAK,OAAO,CAAA,GAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA,GAAK,OAAA;AACnD;AAQO,SAAS,UAAU,GAAA,EAAqB;AAC7C,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,YAAA,EAAc,GAAG,EAAE,IAAA,EAAK;AAC7C","file":"chunk-UOC2PL46.js","sourcesContent":["// ═══════════════════════════════════════════════════════════════════════════\n// MERMAID SANITIZING — the two functions every drawing in this package shares.\n//\n// Mermaid state ids must be identifier-safe, and a transition label must not\n// contain the characters that terminate it. Both `machine-viz`'s `toMermaid`\n// (which draws a COMPILED machine) and `chart`'s `chartMermaid` (which draws\n// the CHART) need exactly this, and a state name like `human:cp-approval` —\n// real, from `src/chart/__fixtures__/lane.ts` — breaks the diagram in both.\n//\n// So it lives here, in a module with NO imports: `machine-viz/index.ts` pulls\n// in the whole substrate (`formOf` from `../index`), and `chart/compile.ts`\n// must not acquire that dependency merely to sanitize a string.\n// ═══════════════════════════════════════════════════════════════════════════\n\n/**\n * Sanitize a discriminant string into a Mermaid-safe node identifier.\n *\n * Any run of non-identifier characters becomes `_`; a leading digit is\n * prefixed so the id is always a valid Mermaid token; the empty string gets a\n * stable placeholder. Deterministic and idempotent — `safeId(safeId(x))` is\n * `safeId(x)`, so a diagram may sanitize the same name at several sites.\n */\nexport function safeId(raw: string): string {\n const cleaned = raw.replace(/[^A-Za-z0-9_]/g, \"_\");\n if (cleaned === \"\") return \"_empty\";\n return /^[0-9]/.test(cleaned) ? `s_${cleaned}` : cleaned;\n}\n\n/**\n * Sanitize text used as a Mermaid edge/transition label (the part after `:`).\n *\n * Strips the characters that terminate or confuse a label: newlines, the `:`\n * that separates label from target, and Mermaid's `\"`/`;` delimiters.\n */\nexport function safeLabel(raw: string): string {\n return raw.replace(/[\"\\n\\r;:]/g, \" \").trim();\n}\n"]}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { typeOf, indexPath, unionKeys, keyPath } from './chunk-EWJP3YYP.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useEffect, useState, useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
function MsgLog({ history, className }) {
|
|
6
|
+
return /* @__PURE__ */ jsx("div", { className: `tea-dt-log${className ? ` ${className}` : ""}`, children: history.map((r, i) => /* @__PURE__ */ jsxs(
|
|
7
|
+
"div",
|
|
8
|
+
{
|
|
9
|
+
className: `tea-dt-row tea-dt-${r.kind ?? "msg"}`,
|
|
10
|
+
children: [
|
|
11
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-t", children: r.ts }),
|
|
12
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-m", children: r.text })
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
`${r.ts}-${i}`
|
|
16
|
+
)) });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/devtools/state-diff.ts
|
|
20
|
+
function diffState(expected, actual) {
|
|
21
|
+
const out = [];
|
|
22
|
+
walk(expected, actual, "state", out);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
function walk(expected, actual, path, out) {
|
|
26
|
+
if (Object.is(expected, actual)) return;
|
|
27
|
+
const te = typeOf(expected);
|
|
28
|
+
const ta = typeOf(actual);
|
|
29
|
+
if (te === "undefined") {
|
|
30
|
+
out.push({ path, kind: "added", expected, actual });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (ta === "undefined") {
|
|
34
|
+
out.push({ path, kind: "removed", expected, actual });
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (te !== ta) {
|
|
38
|
+
out.push({ path, kind: "changed", expected, actual });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (te === "array") {
|
|
42
|
+
const ae = expected;
|
|
43
|
+
const aa = actual;
|
|
44
|
+
const len = Math.max(ae.length, aa.length);
|
|
45
|
+
for (let i = 0; i < len; i++) {
|
|
46
|
+
walk(ae[i], aa[i], indexPath(path, i), out);
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (te === "object") {
|
|
51
|
+
const oe = expected;
|
|
52
|
+
const oa = actual;
|
|
53
|
+
for (const key of unionKeys(oe, oa)) {
|
|
54
|
+
walk(oe[key], oa[key], keyPath(path, key), out);
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
out.push({ path, kind: "changed", expected, actual });
|
|
59
|
+
}
|
|
60
|
+
function fmtValue(v) {
|
|
61
|
+
if (v === void 0) return "undefined";
|
|
62
|
+
if (typeof v === "number" && Number.isNaN(v)) return "NaN";
|
|
63
|
+
if (typeof v === "bigint") return `${v}n`;
|
|
64
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
65
|
+
if (typeof v === "function" || typeof v === "symbol") return String(v);
|
|
66
|
+
try {
|
|
67
|
+
return JSON.stringify(v) ?? String(v);
|
|
68
|
+
} catch {
|
|
69
|
+
return String(v);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function formatDiff(changes) {
|
|
73
|
+
return changes.map(formatChange).join("\n");
|
|
74
|
+
}
|
|
75
|
+
function formatChange(c) {
|
|
76
|
+
switch (c.kind) {
|
|
77
|
+
case "changed":
|
|
78
|
+
return `~ ${c.path}: ${fmtValue(c.expected)} \u2192 ${fmtValue(c.actual)}`;
|
|
79
|
+
case "removed":
|
|
80
|
+
return `- ${c.path}: ${fmtValue(c.expected)}`;
|
|
81
|
+
case "added":
|
|
82
|
+
return `+ ${c.path}: ${fmtValue(c.actual)}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function changeRow(c) {
|
|
86
|
+
switch (c.kind) {
|
|
87
|
+
case "changed":
|
|
88
|
+
return /* @__PURE__ */ jsxs("div", { className: "tea-dt-diff-row tea-dt-diff-changed", children: [
|
|
89
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-mark", children: "~" }),
|
|
90
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-path", children: c.path }),
|
|
91
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-old", children: fmtValue(c.expected) }),
|
|
92
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-arrow", children: "\u2192" }),
|
|
93
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-new", children: fmtValue(c.actual) })
|
|
94
|
+
] }, c.path);
|
|
95
|
+
case "removed":
|
|
96
|
+
return /* @__PURE__ */ jsxs("div", { className: "tea-dt-diff-row tea-dt-diff-removed", children: [
|
|
97
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-mark", children: "-" }),
|
|
98
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-path", children: c.path }),
|
|
99
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-old", children: fmtValue(c.expected) })
|
|
100
|
+
] }, c.path);
|
|
101
|
+
case "added":
|
|
102
|
+
return /* @__PURE__ */ jsxs("div", { className: "tea-dt-diff-row tea-dt-diff-added", children: [
|
|
103
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-mark", children: "+" }),
|
|
104
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-path", children: c.path }),
|
|
105
|
+
/* @__PURE__ */ jsx("span", { className: "tea-dt-diff-new", children: fmtValue(c.actual) })
|
|
106
|
+
] }, c.path);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function StateDiff({ expected, actual, className }) {
|
|
110
|
+
const changes = diffState(expected, actual);
|
|
111
|
+
return /* @__PURE__ */ jsx(
|
|
112
|
+
"div",
|
|
113
|
+
{
|
|
114
|
+
className: `tea-dt-diff${className ? ` ${className}` : ""}`,
|
|
115
|
+
title: changes.length === 0 ? "no changes" : formatDiff(changes),
|
|
116
|
+
children: changes.length === 0 ? /* @__PURE__ */ jsx("div", { className: "tea-dt-diff-empty", children: "no changes" }) : changes.map(changeRow)
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
function escapeHtml(s) {
|
|
121
|
+
return s.replace(
|
|
122
|
+
/[&<>"]/g,
|
|
123
|
+
(c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function fmtJson(obj, indent = 0) {
|
|
127
|
+
if (obj === null) return '<span class="tea-dt-b">null</span>';
|
|
128
|
+
if (typeof obj === "number") return `<span class="tea-dt-n">${obj}</span>`;
|
|
129
|
+
if (typeof obj === "boolean") return `<span class="tea-dt-b">${obj}</span>`;
|
|
130
|
+
if (typeof obj === "string")
|
|
131
|
+
return `<span class="tea-dt-s">"${escapeHtml(obj)}"</span>`;
|
|
132
|
+
if (Array.isArray(obj)) {
|
|
133
|
+
if (obj.length === 0) return '<span class="tea-dt-br">[]</span>';
|
|
134
|
+
return '<span class="tea-dt-br">[</span>' + obj.map((v) => fmtJson(v, indent + 1)).join('<span class="tea-dt-br">, </span>') + '<span class="tea-dt-br">]</span>';
|
|
135
|
+
}
|
|
136
|
+
if (typeof obj === "object") {
|
|
137
|
+
const keys = Object.keys(obj);
|
|
138
|
+
if (keys.length === 0) return '<span class="tea-dt-br">{}</span>';
|
|
139
|
+
const pad = " ".repeat(indent + 1);
|
|
140
|
+
const lines = keys.map((k, i) => {
|
|
141
|
+
const v = obj[k];
|
|
142
|
+
const comma = i < keys.length - 1 ? '<span class="tea-dt-br">,</span>' : "";
|
|
143
|
+
return `${pad}<span class="tea-dt-k">${escapeHtml(k)}</span><span class="tea-dt-br">:</span> ${fmtJson(v, indent + 1)}${comma}`;
|
|
144
|
+
});
|
|
145
|
+
return [
|
|
146
|
+
'<span class="tea-dt-br">{</span>',
|
|
147
|
+
...lines,
|
|
148
|
+
`${" ".repeat(indent)}<span class="tea-dt-br">}</span>`
|
|
149
|
+
].join("<br/>");
|
|
150
|
+
}
|
|
151
|
+
return escapeHtml(String(obj));
|
|
152
|
+
}
|
|
153
|
+
function StateInspector({
|
|
154
|
+
state,
|
|
155
|
+
flashKey,
|
|
156
|
+
className
|
|
157
|
+
}) {
|
|
158
|
+
const boxRef = useRef(null);
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (flashKey === void 0 || !boxRef.current) return;
|
|
161
|
+
boxRef.current.classList.remove("tea-dt-flash");
|
|
162
|
+
void boxRef.current.offsetWidth;
|
|
163
|
+
boxRef.current.classList.add("tea-dt-flash");
|
|
164
|
+
}, [flashKey]);
|
|
165
|
+
return /* @__PURE__ */ jsx(
|
|
166
|
+
"div",
|
|
167
|
+
{
|
|
168
|
+
ref: boxRef,
|
|
169
|
+
className: `tea-dt-state${className ? ` ${className}` : ""}`,
|
|
170
|
+
children: /* @__PURE__ */ jsx(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
className: "tea-dt-json",
|
|
174
|
+
dangerouslySetInnerHTML: { __html: fmtJson(state) }
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function nowTs() {
|
|
181
|
+
return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: false }).slice(3);
|
|
182
|
+
}
|
|
183
|
+
function useMsgHistory(dispatch, opts = {}) {
|
|
184
|
+
const max = opts.max ?? 60;
|
|
185
|
+
const now = opts.now ?? nowTs;
|
|
186
|
+
const derive = opts.derive ?? ((msg) => {
|
|
187
|
+
const tag = msg && typeof msg === "object" && "type" in msg ? String(msg.type) : String(msg);
|
|
188
|
+
return { ts: now(), kind: "msg", text: tag };
|
|
189
|
+
});
|
|
190
|
+
const [history, setHistory] = useState([]);
|
|
191
|
+
const dispatchRef = useRef(dispatch);
|
|
192
|
+
dispatchRef.current = dispatch;
|
|
193
|
+
const deriveRef = useRef(derive);
|
|
194
|
+
deriveRef.current = derive;
|
|
195
|
+
const wrapped = useCallback(
|
|
196
|
+
(msg) => {
|
|
197
|
+
const entry = deriveRef.current(msg);
|
|
198
|
+
setHistory((prev) => [entry, ...prev].slice(0, max));
|
|
199
|
+
void dispatchRef.current(msg);
|
|
200
|
+
},
|
|
201
|
+
[max]
|
|
202
|
+
);
|
|
203
|
+
const clear = useCallback(() => setHistory([]), []);
|
|
204
|
+
return [history, wrapped, clear];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export { MsgLog, StateDiff, StateInspector, diffState, formatDiff, useMsgHistory };
|
|
208
|
+
//# sourceMappingURL=chunk-WRAA7GVZ.js.map
|
|
209
|
+
//# sourceMappingURL=chunk-WRAA7GVZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/devtools/msg-log.tsx","../src/devtools/state-diff.ts","../src/devtools/state-diff-view.tsx","../src/devtools/state-inspector.tsx","../src/devtools/use-msg-history.ts"],"names":["jsxs","jsx","useRef"],"mappings":";;;;AAcO,SAAS,MAAA,CAAO,EAAE,OAAA,EAAS,SAAA,EAAU,EAAgB;AAC1D,EAAA,uBACE,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAW,CAAA,UAAA,EAAa,YAAY,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA,GAAK,EAAE,CAAA,CAAA,EAC1D,QAAA,EAAA,OAAA,CAAQ,GAAA,CAAI,CAAC,GAAG,CAAA,qBACf,IAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MAEC,SAAA,EAAW,CAAA,kBAAA,EAAqB,CAAA,CAAE,IAAA,IAAQ,KAAK,CAAA,CAAA;AAAA,MAE/C,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,UAAA,EAAY,QAAA,EAAA,CAAA,CAAE,EAAA,EAAG,CAAA;AAAA,wBACjC,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,UAAA,EAAY,YAAE,IAAA,EAAK;AAAA;AAAA,KAAA;AAAA,IAJ9B,CAAA,EAAG,CAAA,CAAE,EAAE,CAAA,CAAA,EAAI,CAAC,CAAA;AAAA,GAMpB,CAAA,EACH,CAAA;AAEJ;;;ACsCO,SAAS,SAAA,CAAU,UAAmB,MAAA,EAAgC;AAC3E,EAAA,MAAM,MAAqB,EAAC;AAC5B,EAAA,IAAA,CAAK,QAAA,EAAU,MAAA,EAAQ,OAAA,EAAS,GAAG,CAAA;AACnC,EAAA,OAAO,GAAA;AACT;AAEA,SAAS,IAAA,CACP,QAAA,EACA,MAAA,EACA,IAAA,EACA,GAAA,EACM;AAGN,EAAA,IAAI,MAAA,CAAO,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AO,QAAQ,CAAA;AACnC,EAAA,WAAA,CAAY,OAAA,GAAU,QAAA;AACtB,EAAA,MAAM,SAAA,GAAYA,OAAO,MAAM,CAAA;AAC/B,EAAA,SAAA,CAAU,OAAA,GAAU,MAAA;AAEpB,EAAA,MAAM,OAAA,GAAU,WAAA;AAAA,IACd,CAAC,GAAA,KAAW;AACV,MAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,OAAA,CAAQ,GAAG,CAAA;AACnC,MAAA,UAAA,CAAW,CAAC,IAAA,KAAS,CAAC,KAAA,EAAO,GAAG,IAAI,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,GAAG,CAAC,CAAA;AAGnD,MAAA,KAAK,WAAA,CAAY,QAAQ,GAAG,CAAA;AAAA,IAC9B,CAAA;AAAA,IACA,CAAC,GAAG;AAAA,GACN;AAEA,EAAA,MAAM,KAAA,GAAQ,YAAY,MAAM,UAAA,CAAW,EAAE,CAAA,EAAG,EAAE,CAAA;AAElD,EAAA,OAAO,CAAC,OAAA,EAAS,OAAA,EAAS,KAAK,CAAA;AACjC","file":"chunk-WRAA7GVZ.js","sourcesContent":["export type MsgLogEntry = {\n /** Display timestamp (whatever format you produced). */\n ts: string;\n /** Visual category — drives the row icon. Defaults to \"msg\" via CSS. */\n kind?: \"msg\" | \"sub\" | \"cmd\" | \"ok\" | \"fail\";\n /** Row text — usually the Msg tag plus a short detail. */\n text: string;\n};\n\nexport interface MsgLogProps {\n history: readonly MsgLogEntry[];\n className?: string;\n}\n\nexport function MsgLog({ history, className }: MsgLogProps) {\n return (\n <div className={`tea-dt-log${className ? ` ${className}` : \"\"}`}>\n {history.map((r, i) => (\n <div\n key={`${r.ts}-${i}`}\n className={`tea-dt-row tea-dt-${r.kind ?? \"msg\"}`}\n >\n <span className=\"tea-dt-t\">{r.ts}</span>\n <span className=\"tea-dt-m\">{r.text}</span>\n </div>\n ))}\n </div>\n );\n}\n","// ---------------------------------------------------------------------------\n// state-diff — the RICHER cousin of trace-replay's first-divergence walk.\n//\n// `../trace-replay` answers \"did the state drift, and where FIRST?\" — it stops\n// at the first differing cell because a regression check only needs to point at\n// one. This module answers the fuller devtools question: \"show me EVERY cell\n// that differs,\" classified as added / removed / changed, ready to render.\n//\n// Same substrate, same path grammar (root `state`, `foo[2]` for arrays,\n// `foo.bar` for objects, sorted-union key order, `Object.is` leaf equality) so\n// a path printed here is the SAME string trace-replay would print for that\n// cell. The two tools are deliberately consistent: a `divergence.path` from a\n// replay result indexes straight into this module's `StateChange[]`.\n//\n// Pure + zero-dep on purpose — runs in Node, in tests, in a Worker. The React\n// view (`./state-diff.tsx`) is the only React-touching layer.\n// ---------------------------------------------------------------------------\n\nimport {\n indexPath,\n keyPath,\n typeOf,\n unionKeys,\n} from \"../trace-replay/state-walk\";\n\n/**\n * A single differing cell between two states.\n *\n * - `kind: \"added\"` — the path exists in `actual` but not `expected`\n * (`expected` is `undefined`).\n * - `kind: \"removed\"` — the path exists in `expected` but not `actual`\n * (`actual` is `undefined`).\n * - `kind: \"changed\"` — the path exists on both sides with differing leaf\n * values (or differing kinds, e.g. object vs array).\n */\nexport interface StateChange {\n /** Access path from the state root, e.g. `state.items[1].status`. */\n path: string;\n /** How the cell differs between the two states. */\n kind: \"added\" | \"removed\" | \"changed\";\n /** The value on the `expected` side (`undefined` when `added`). */\n expected: unknown;\n /** The value on the `actual` side (`undefined` when `removed`). */\n actual: unknown;\n}\n\n/**\n * Deep-walk two states and return EVERY differing cell, in deterministic\n * pre-order (the node before its children; children in array-index order, then\n * sorted-union key order for objects). The empty array means the two states are\n * deeply equal.\n *\n * Equality + path grammar match `../trace-replay`'s `firstDivergence` exactly:\n * - `Object.is` leaf equality, so `NaN` equals `NaN` and `+0` ≠ `-0`.\n * - arrays index by `[i]`; a length mismatch is NOT reported at the array\n * node — instead each surplus/missing element surfaces as its own\n * added/removed child, which is what a devtools list wants to show.\n * - objects walk the sorted union of both sides' keys; a key on only one\n * side becomes an `added`/`removed` child.\n * - the root path is `\"state\"`.\n *\n * Scope is JSON-shaped state (the same substrate trace-replay targets):\n * primitives, null/undefined, arrays, plain objects. A differing kind at a node\n * (object vs array, number vs string) is reported as a single `changed` at that\n * node — the walk does not descend into mismatched kinds.\n */\nexport function diffState(expected: unknown, actual: unknown): StateChange[] {\n const out: StateChange[] = [];\n walk(expected, actual, \"state\", out);\n return out;\n}\n\nfunction walk(\n expected: unknown,\n actual: unknown,\n path: string,\n out: StateChange[],\n): void {\n // Identity / primitive fast path. Equal cells contribute nothing. `Object.is`\n // so NaN equals NaN and +0 ≠ -0 — same intent as trace-replay's leaf check.\n if (Object.is(expected, actual)) return;\n\n const te = typeOf(expected);\n const ta = typeOf(actual);\n\n // A present/absent pair at this node is an add or a remove — the structural\n // signal a viewer color-codes differently from a value change.\n if (te === \"undefined\") {\n out.push({ path, kind: \"added\", expected, actual });\n return;\n }\n if (ta === \"undefined\") {\n out.push({ path, kind: \"removed\", expected, actual });\n return;\n }\n\n // Different kinds at a present node (object vs array, number vs string,\n // value vs null) — one `changed` at the node; do not descend into mismatched\n // shapes, mirroring trace-replay's \"this node IS the divergence\".\n if (te !== ta) {\n out.push({ path, kind: \"changed\", expected, actual });\n return;\n }\n\n if (te === \"array\") {\n const ae = expected as unknown[];\n const aa = actual as unknown[];\n // Walk the union of indices so surplus elements on EITHER side surface as\n // their own added/removed children (vs trace-replay, which reports a length\n // mismatch at the array node and stops). A viewer wants the per-element\n // detail.\n const len = Math.max(ae.length, aa.length);\n for (let i = 0; i < len; i++) {\n walk(ae[i], aa[i], indexPath(path, i), out);\n }\n return;\n }\n\n if (te === \"object\") {\n const oe = expected as Record<string, unknown>;\n const oa = actual as Record<string, unknown>;\n // Sorted union of keys — deterministic regardless of insertion order, so\n // two states with the same data in different key order produce no changes,\n // and the reported order is reproducible run-to-run.\n for (const key of unionKeys(oe, oa)) {\n walk(oe[key], oa[key], keyPath(path, key), out);\n }\n return;\n }\n\n // Two present primitives (string/number/boolean/bigint/symbol) or two\n // differing nulls that failed the Object.is fast path — a leaf change.\n out.push({ path, kind: \"changed\", expected, actual });\n}\n\n/** Render a single value compactly for a diff cell. Strings get quotes so\n * `\"3\"` is visibly distinct from `3`; everything else is JSON-ish, with the\n * `undefined`/`NaN`/`BigInt` cases JSON.stringify mishandles spelled out.\n * Exported (though not re-exported from `./index`) so the React `<StateDiff>`\n * view renders each cell with this exact formatter rather than a copy. */\nexport function fmtValue(v: unknown): string {\n if (v === undefined) return \"undefined\";\n if (typeof v === \"number\" && Number.isNaN(v)) return \"NaN\";\n if (typeof v === \"bigint\") return `${v}n`;\n if (typeof v === \"string\") return JSON.stringify(v);\n if (typeof v === \"function\" || typeof v === \"symbol\") return String(v);\n try {\n return JSON.stringify(v) ?? String(v);\n } catch {\n // Circular / non-serializable — fall back to a coarse tag.\n return String(v);\n }\n}\n\n/**\n * Pretty multi-line text for a {@link diffState} result. One `±`-prefixed line\n * per change, in the array's (pre-order, deterministic) order:\n *\n * - `~ state.total: 121.5 → 135` (changed: old → new)\n * - `- state.coupon: \"X\"` (removed: only the old value)\n * - `+ state.tax: 8` (added: only the new value)\n *\n * Deterministic given a deterministic `changes` array. An empty array yields\n * the empty string.\n */\nexport function formatDiff(changes: StateChange[]): string {\n return changes.map(formatChange).join(\"\\n\");\n}\n\n/** One `±`-prefixed line for a single change. Split out so the `map` callback\n * is total (Biome's useIterableCallbackReturn) without a dead default branch. */\nfunction formatChange(c: StateChange): string {\n switch (c.kind) {\n case \"changed\":\n return `~ ${c.path}: ${fmtValue(c.expected)} → ${fmtValue(c.actual)}`;\n case \"removed\":\n return `- ${c.path}: ${fmtValue(c.expected)}`;\n case \"added\":\n return `+ ${c.path}: ${fmtValue(c.actual)}`;\n }\n}\n","import {\n diffState,\n fmtValue,\n formatDiff,\n type StateChange,\n} from \"./state-diff\";\n\nexport interface StateDiffProps {\n /**\n * The baseline / \"before\" state — what you expected. In a regression view\n * this is a trace's recorded `finalState`; in a time-travel view it's the\n * previous model.\n */\n expected: unknown;\n /**\n * The \"after\" state to compare against `expected` — the recomputed or\n * current model.\n */\n actual: unknown;\n /** Optional className appended to the container. Use to override layout. */\n className?: string;\n}\n\n/** Per-kind row glyph + value rendering. Lives here (not CSS ::before like the\n * MsgLog rows) because the diff prints the path AND the value(s), so the glyph\n * is part of structured content the screen reader should read in order. */\nfunction changeRow(c: StateChange) {\n // `path` is unique within one diff (each cell appears at most once), so it is\n // a stable React key without needing the array index.\n switch (c.kind) {\n case \"changed\":\n return (\n <div key={c.path} className=\"tea-dt-diff-row tea-dt-diff-changed\">\n <span className=\"tea-dt-diff-mark\">~</span>\n <span className=\"tea-dt-diff-path\">{c.path}</span>\n <span className=\"tea-dt-diff-old\">{fmtValue(c.expected)}</span>\n <span className=\"tea-dt-diff-arrow\">→</span>\n <span className=\"tea-dt-diff-new\">{fmtValue(c.actual)}</span>\n </div>\n );\n case \"removed\":\n return (\n <div key={c.path} className=\"tea-dt-diff-row tea-dt-diff-removed\">\n <span className=\"tea-dt-diff-mark\">-</span>\n <span className=\"tea-dt-diff-path\">{c.path}</span>\n <span className=\"tea-dt-diff-old\">{fmtValue(c.expected)}</span>\n </div>\n );\n case \"added\":\n return (\n <div key={c.path} className=\"tea-dt-diff-row tea-dt-diff-added\">\n <span className=\"tea-dt-diff-mark\">+</span>\n <span className=\"tea-dt-diff-path\">{c.path}</span>\n <span className=\"tea-dt-diff-new\">{fmtValue(c.actual)}</span>\n </div>\n );\n }\n}\n\n/**\n * Presentational diff of two states. Renders {@link diffState}'s output as a\n * color-coded list (added / removed / changed), reusing the devtools `tea-dt-*`\n * class convention so it inherits the same design tokens as `<StateInspector>`\n * and `<MsgLog>` (see ./styles.css). No state, no subscription — pass the two\n * states as props, exactly like the rest of /devtools.\n *\n * When the states are deeply equal the list is empty; a tiny \"no changes\" hint\n * renders so an operator can tell \"equal\" from \"not yet computed\".\n */\nexport function StateDiff({ expected, actual, className }: StateDiffProps) {\n const changes = diffState(expected, actual);\n return (\n <div\n className={`tea-dt-diff${className ? ` ${className}` : \"\"}`}\n // The plain-text diff is the accessible/copyable fallback for the\n // color-coded rows — same content `formatDiff` produces in Node/tests.\n title={changes.length === 0 ? \"no changes\" : formatDiff(changes)}\n >\n {changes.length === 0 ? (\n <div className=\"tea-dt-diff-empty\">no changes</div>\n ) : (\n changes.map(changeRow)\n )}\n </div>\n );\n}\n","import { useEffect, useRef } from \"react\";\n\nfunction escapeHtml(s: string): string {\n return s.replace(\n /[&<>\"]/g,\n (c) =>\n ({ \"&\": \"&\", \"<\": \"<\", \">\": \">\", '\"': \""\" })[c] as string,\n );\n}\n\nfunction fmtJson(obj: unknown, indent = 0): string {\n if (obj === null) return '<span class=\"tea-dt-b\">null</span>';\n if (typeof obj === \"number\") return `<span class=\"tea-dt-n\">${obj}</span>`;\n if (typeof obj === \"boolean\") return `<span class=\"tea-dt-b\">${obj}</span>`;\n if (typeof obj === \"string\")\n return `<span class=\"tea-dt-s\">\"${escapeHtml(obj)}\"</span>`;\n if (Array.isArray(obj)) {\n if (obj.length === 0) return '<span class=\"tea-dt-br\">[]</span>';\n return (\n '<span class=\"tea-dt-br\">[</span>' +\n obj\n .map((v) => fmtJson(v, indent + 1))\n .join('<span class=\"tea-dt-br\">, </span>') +\n '<span class=\"tea-dt-br\">]</span>'\n );\n }\n if (typeof obj === \"object\") {\n const keys = Object.keys(obj as object);\n if (keys.length === 0) return '<span class=\"tea-dt-br\">{}</span>';\n const pad = \" \".repeat(indent + 1);\n const lines = keys.map((k, i) => {\n const v = (obj as Record<string, unknown>)[k];\n const comma =\n i < keys.length - 1 ? '<span class=\"tea-dt-br\">,</span>' : \"\";\n return `${pad}<span class=\"tea-dt-k\">${escapeHtml(k)}</span><span class=\"tea-dt-br\">:</span> ${fmtJson(v, indent + 1)}${comma}`;\n });\n return [\n '<span class=\"tea-dt-br\">{</span>',\n ...lines,\n `${\" \".repeat(indent)}<span class=\"tea-dt-br\">}</span>`,\n ].join(\"<br/>\");\n }\n return escapeHtml(String(obj));\n}\n\nexport interface StateInspectorProps {\n /**\n * The machine state to display. Render-derived shape — pass whatever you\n * want surfaced to the inspector (often a hand-picked subset of the model).\n */\n state: unknown;\n /**\n * When this number changes, the inspector flashes. Pass `model.msgCount` or\n * any other monotonic counter you already have. Omit to disable flashing.\n */\n flashKey?: number;\n /**\n * Optional className appended to the container. Use to override layout.\n */\n className?: string;\n}\n\nexport function StateInspector({\n state,\n flashKey,\n className,\n}: StateInspectorProps) {\n const boxRef = useRef<HTMLDivElement>(null);\n useEffect(() => {\n if (flashKey === undefined || !boxRef.current) return;\n boxRef.current.classList.remove(\"tea-dt-flash\");\n void boxRef.current.offsetWidth;\n boxRef.current.classList.add(\"tea-dt-flash\");\n }, [flashKey]);\n\n return (\n <div\n ref={boxRef}\n className={`tea-dt-state${className ? ` ${className}` : \"\"}`}\n >\n <div\n className=\"tea-dt-json\"\n // biome-ignore lint/security/noDangerouslySetInnerHtml: formatter output\n dangerouslySetInnerHTML={{ __html: fmtJson(state) }}\n />\n </div>\n );\n}\n","import { useCallback, useRef, useState } from \"react\";\nimport type { MsgLogEntry } from \"./msg-log\";\n\nfunction nowTs(): string {\n return new Date().toLocaleTimeString(\"en-GB\", { hour12: false }).slice(3);\n}\n\n/**\n * Wrap a `dispatch` so every Msg it sees lands in a bounded history buffer.\n *\n * `derive` lets you map a Msg to a richer entry (e.g. assign `kind: \"sub\"` to\n * subscription-triggered messages). Default: every msg becomes a `\"msg\"` row\n * tagged with `msg.type` (or `String(msg)` if it has no `type`). The substrate\n * uses `type` as the Msg discriminant — using `_tag` here would render every\n * Msg as `[object Object]` in the inspector.\n *\n * `max` caps the buffer — oldest entries fall off (LIFO, newest first).\n *\n * `now` is the timestamp source for the default `derive`. Defaults to\n * `nowTs` (real wall-clock). Tests inject a deterministic shim so\n * snapshots don't drift; production code never sets it.\n */\nexport function useMsgHistory<M>(\n dispatch: (msg: M) => void | Promise<void>,\n opts: {\n max?: number;\n derive?: (msg: M) => MsgLogEntry;\n now?: () => string;\n } = {},\n): readonly [readonly MsgLogEntry[], (msg: M) => void, () => void] {\n const max = opts.max ?? 60;\n const now = opts.now ?? nowTs;\n const derive =\n opts.derive ??\n ((msg: M): MsgLogEntry => {\n const tag =\n msg && typeof msg === \"object\" && \"type\" in msg\n ? String((msg as { type: unknown }).type)\n : String(msg);\n return { ts: now(), kind: \"msg\", text: tag };\n });\n\n const [history, setHistory] = useState<readonly MsgLogEntry[]>([]);\n // Stable ref to `dispatch` so the wrapper identity stays stable across\n // renders — important when this is passed to keyboard handlers and the like.\n const dispatchRef = useRef(dispatch);\n dispatchRef.current = dispatch;\n const deriveRef = useRef(derive);\n deriveRef.current = derive;\n\n const wrapped = useCallback(\n (msg: M) => {\n const entry = deriveRef.current(msg);\n setHistory((prev) => [entry, ...prev].slice(0, max));\n // Fire-and-forget — `dispatch` may return a Promise; we don't await it\n // here because callers historically treat dispatch as void.\n void dispatchRef.current(msg);\n },\n [max],\n );\n\n const clear = useCallback(() => setHistory([]), []);\n\n return [history, wrapped, clear] as const;\n}\n"]}
|