@howaboua/pi-durable-ui 0.11.0 → 0.13.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/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) 2026 Igor Warzocha
4
+ Copyright (c) 2026 Howaboua (Unicode chart rendering)
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/NOTICE CHANGED
@@ -8,3 +8,7 @@ The MIT license and copyright notice are preserved in LICENSE.
8
8
 
9
9
  Uses @pierre/diffs 1.4.3 as an external dependency, under Apache-2.0.
10
10
  No Pierre source is vendored in this package.
11
+
12
+ Unicode chart rendering carries the MIT-licensed pi-unicode-charts implementation.
13
+ Source: https://github.com/IgorWarzocha/howaboua-agent-stuff/tree/e1730759db35bf454d0c86c34a80e63129dd929f/packages/pi-unicode-charts
14
+ Copyright (c) 2026 Howaboua. The MIT license is preserved in LICENSE.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Interactive browser components backed by host-owned state, actions and streams. The root entry has no React, Git or Durable runtime import. Components run as trusted in-process code, not in a sandbox.
4
4
 
5
5
  ```sh
6
- npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.11.0/howaboua-pi-durable-ui-0.11.0.tgz
6
+ npm install @howaboua/pi-durable-ui@0.13.0
7
7
  ```
8
8
 
9
9
  ## Interactive components
@@ -120,6 +120,12 @@ Mounts receive `{ id, revision, signal, call }` and must return a cleanup functi
120
120
 
121
121
  The host owns authentication, revision selection, module loading, authorization and transport. `call` carries one JSON request and response. Abort prevents new calls and rejects stale responses. It does **not** cancel remote IO or undo remote side effects. This is trusted in-process code, not a sandbox.
122
122
 
123
+ ## Unicode charts
124
+
125
+ Use `@howaboua/pi-durable-ui/charts` to render completed assistant Markdown with `transformChartMarkdown(markdown, columns)`. Supply the width of the message view in monospace columns. Keep the original transcript and leave thinking text alone. Invalid and unfinished fences stay as Markdown. Enable `CHART_PROMPT` in the host prompt only where this display is active.
126
+
127
+ The `chart` fences support bar, line, scatter, sparkline and heatmap. Use `renderChart(spec, columns)` for the same Unicode output as plain lines.
128
+
123
129
  ## Diff rendering
124
130
 
125
131
  Install [Git](../git) 0.8.1, React and React DOM 19.3.0, and `@pierre/diffs` 1.6.1 for `/react/diff`. These are optional peers, not dependencies of the generic component API.
@@ -0,0 +1,2 @@
1
+ import type { ChartPoint } from "./render.ts";
2
+ export declare function renderBraille(points: ChartPoint[], connect: boolean, width: number): string[];
@@ -0,0 +1,6 @@
1
+ export declare const PLOT_ROWS = 8;
2
+ export declare function formatNumber(value: number): string;
3
+ export declare function displayWidth(value: string): number;
4
+ export declare function truncate(value: string, width: number): string;
5
+ export declare function padEndWidth(value: string, width: number): string;
6
+ export declare function center(value: string, width: number): string;
@@ -0,0 +1,17 @@
1
+ export declare const CHART_TYPES: readonly ["bar", "line", "scatter", "sparkline", "heatmap"];
2
+ export type ChartType = (typeof CHART_TYPES)[number];
3
+ export interface ChartPoint {
4
+ label: string;
5
+ value: number;
6
+ }
7
+ export interface HeatmapRow {
8
+ label: string;
9
+ values: number[];
10
+ }
11
+ export interface ChartSpec {
12
+ type: ChartType;
13
+ title?: string;
14
+ points: ChartPoint[];
15
+ rows?: HeatmapRow[];
16
+ }
17
+ export declare function renderChart(spec: ChartSpec, availableWidth: number): string[];
@@ -0,0 +1,3 @@
1
+ export { type ChartSpec, type ChartType, renderChart } from "./chart/render.ts";
2
+ export declare const CHART_PROMPT: string;
3
+ export declare function transformChartMarkdown(markdown: string, availableWidth: number): string;
package/dist/charts.js ADDED
@@ -0,0 +1,489 @@
1
+ // packages/ui/src/chart/layout.ts
2
+ var PLOT_ROWS = 8;
3
+ function formatNumber(value) {
4
+ if (Math.abs(value) >= 1000)
5
+ return `${(value / 1000).toFixed(Math.abs(value) >= 1e4 ? 0 : 1).replace(/\.0$/u, "")}k`;
6
+ if (Number.isInteger(value))
7
+ return String(value);
8
+ const absolute = Math.abs(value);
9
+ if (absolute >= 1)
10
+ return value.toFixed(1).replace(/\.0$/u, "");
11
+ if (absolute >= 0.01)
12
+ return value.toFixed(2).replace(/0+$/u, "").replace(/\.$/u, "");
13
+ return value.toExponential(1).replace(/\.0e/u, "e");
14
+ }
15
+ function displayWidth(value) {
16
+ return Array.from(value).reduce((width, character) => {
17
+ const codePoint = character.codePointAt(0) ?? 0;
18
+ if (codePoint >= 768 && codePoint <= 879 || codePoint >= 65024 && codePoint <= 65039)
19
+ return width;
20
+ if (codePoint >= 4352 && (codePoint <= 4447 || codePoint === 9001 || codePoint === 9002 || codePoint >= 11904 && codePoint <= 42191 || codePoint >= 44032 && codePoint <= 55203 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65040 && codePoint <= 65049 || codePoint >= 65072 && codePoint <= 65135 || codePoint >= 65280 && codePoint <= 65376 || codePoint >= 65504 && codePoint <= 65510))
21
+ return width + 2;
22
+ return width + 1;
23
+ }, 0);
24
+ }
25
+ function truncate(value, width) {
26
+ if (displayWidth(value) <= width)
27
+ return value;
28
+ if (width <= 1)
29
+ return "…";
30
+ let output = "";
31
+ for (const character of value) {
32
+ if (displayWidth(`${output}${character}…`) > width)
33
+ break;
34
+ output += character;
35
+ }
36
+ return `${output}…`;
37
+ }
38
+ function padEndWidth(value, width) {
39
+ return `${value}${" ".repeat(Math.max(0, width - displayWidth(value)))}`;
40
+ }
41
+ function center(value, width) {
42
+ const remaining = Math.max(0, width - displayWidth(value));
43
+ return `${" ".repeat(Math.floor(remaining / 2))}${value}${" ".repeat(Math.ceil(remaining / 2))}`;
44
+ }
45
+
46
+ // packages/ui/src/chart/braille.ts
47
+ var BRAILLE_DOTS = [
48
+ [0, 0, 1],
49
+ [0, 1, 2],
50
+ [0, 2, 4],
51
+ [1, 0, 8],
52
+ [1, 1, 16],
53
+ [1, 2, 32],
54
+ [0, 3, 64],
55
+ [1, 3, 128]
56
+ ];
57
+ function renderBraille(points, connect, width) {
58
+ const yValues = points.map((point) => point.value);
59
+ const minimum = Math.min(...yValues);
60
+ const maximum = Math.max(...yValues);
61
+ const span = maximum - minimum;
62
+ if (!Number.isFinite(span))
63
+ return [];
64
+ const range = span || 1;
65
+ const middleRow = Math.floor(PLOT_ROWS / 2);
66
+ const tickLabels = [
67
+ formatNumber(maximum),
68
+ formatNumber(maximum - (maximum - minimum) * (middleRow / (PLOT_ROWS - 1))),
69
+ formatNumber(minimum)
70
+ ];
71
+ const yLabelWidth = Math.max(3, ...tickLabels.map((label) => displayWidth(label)));
72
+ const plotColumns = width - yLabelWidth - 3;
73
+ if (plotColumns < 4)
74
+ return [];
75
+ const dotWidth = plotColumns * 2;
76
+ const dotHeight = PLOT_ROWS * 4;
77
+ const dots = new Set;
78
+ const coordinates = points.map((point, index) => ({
79
+ x: points.length === 1 ? 0 : Math.round(index * (dotWidth - 1) / (points.length - 1)),
80
+ y: dotHeight - 1 - Math.round((point.value - minimum) / range * (dotHeight - 1))
81
+ }));
82
+ for (let index = 0;index < coordinates.length; index += 1) {
83
+ const point = coordinates[index];
84
+ if (!point)
85
+ continue;
86
+ if (connect && index > 0) {
87
+ const previous = coordinates[index - 1];
88
+ if (previous)
89
+ drawLine(previous.x, previous.y, point.x, point.y, dots);
90
+ } else {
91
+ drawPoint(point.x, point.y, dotWidth, dotHeight, dots);
92
+ }
93
+ }
94
+ const lines = [];
95
+ for (let row = 0;row < PLOT_ROWS; row += 1) {
96
+ const label = row === 0 ? tickLabels[0] ?? "" : row === middleRow ? tickLabels[1] ?? "" : row === PLOT_ROWS - 1 ? tickLabels[2] ?? "" : "";
97
+ let chart = "";
98
+ for (let column = 0;column < plotColumns; column += 1) {
99
+ let bits = 0;
100
+ for (const [dotX, dotY, bit] of BRAILLE_DOTS) {
101
+ if (dots.has(`${column * 2 + dotX},${row * 4 + dotY}`))
102
+ bits |= bit;
103
+ }
104
+ chart += String.fromCodePoint(10240 + bits);
105
+ }
106
+ lines.push(`${label.padStart(yLabelWidth)} ┤${chart}`);
107
+ }
108
+ lines.push(`${"".padStart(yLabelWidth)} └${"─".repeat(plotColumns)}`);
109
+ const first = truncate(points[0]?.label ?? "", Math.floor(plotColumns / 2));
110
+ const last = truncate(points[points.length - 1]?.label ?? "", Math.floor(plotColumns / 2));
111
+ const spacer = Math.max(1, plotColumns - displayWidth(first) - displayWidth(last));
112
+ lines.push(`${"".padStart(yLabelWidth + 2)}${first}${" ".repeat(spacer)}${last}`);
113
+ return lines;
114
+ }
115
+ function drawLine(x0, y0, x1, y1, dots) {
116
+ let x = x0;
117
+ let y = y0;
118
+ const dx = Math.abs(x1 - x0);
119
+ const sx = x0 < x1 ? 1 : -1;
120
+ const dy = -Math.abs(y1 - y0);
121
+ const sy = y0 < y1 ? 1 : -1;
122
+ let error = dx + dy;
123
+ while (true) {
124
+ dots.add(`${x},${y}`);
125
+ if (x === x1 && y === y1)
126
+ return;
127
+ const twice = 2 * error;
128
+ if (twice >= dy) {
129
+ error += dy;
130
+ x += sx;
131
+ }
132
+ if (twice <= dx) {
133
+ error += dx;
134
+ y += sy;
135
+ }
136
+ }
137
+ }
138
+ function drawPoint(x, y, width, height, dots) {
139
+ const startX = x >= width - 1 ? x - 1 : x;
140
+ const startY = y >= height - 1 ? y - 1 : y;
141
+ for (let offsetY = 0;offsetY < 2; offsetY += 1) {
142
+ for (let offsetX = 0;offsetX < 2; offsetX += 1) {
143
+ const dotX = startX + offsetX;
144
+ const dotY = startY + offsetY;
145
+ if (dotX < width && dotY < height)
146
+ dots.add(`${dotX},${dotY}`);
147
+ }
148
+ }
149
+ }
150
+
151
+ // packages/ui/src/chart/render.ts
152
+ var CHART_TYPES = [
153
+ "bar",
154
+ "line",
155
+ "scatter",
156
+ "sparkline",
157
+ "heatmap"
158
+ ];
159
+ var MINIMUM_WIDTH = 24;
160
+ var MAXIMUM_WIDTH = 80;
161
+ var SPARK_GLYPHS = "▁▂▃▄▅▆▇█";
162
+ var HEAT_GLYPHS = "░▒▓█";
163
+ function renderChart(spec, availableWidth) {
164
+ if (!Number.isFinite(availableWidth) || availableWidth < MINIMUM_WIDTH)
165
+ return [];
166
+ if (spec.type !== "heatmap" && spec.points.length === 0)
167
+ return [];
168
+ const width = Math.min(MAXIMUM_WIDTH, Math.floor(availableWidth));
169
+ const body = spec.type === "bar" ? renderBars(spec.points, width) : spec.type === "sparkline" ? renderSparkline(spec.points, width) : spec.type === "heatmap" ? renderHeatmap(spec.rows ?? [], width) : renderBraille(spec.points, spec.type === "line", width);
170
+ if (body.length === 0)
171
+ return [];
172
+ const lines = spec.title ? [spec.title, ...body] : body;
173
+ return lines.map((line) => truncate(line, width));
174
+ }
175
+ function renderBars(points, width) {
176
+ const values = points.map((point) => point.value);
177
+ const minimum = Math.min(0, ...values);
178
+ let maximum = Math.max(0, ...values);
179
+ const zeroOnly = minimum === maximum;
180
+ if (zeroOnly)
181
+ maximum = 1;
182
+ const range = maximum - minimum;
183
+ if (!Number.isFinite(range))
184
+ return [];
185
+ const zeroRow = Math.min(PLOT_ROWS - 1, Math.floor(PLOT_ROWS * (maximum / range)));
186
+ const tickRows = new Set(zeroOnly ? [zeroRow] : [0, PLOT_ROWS - 1, zeroRow]);
187
+ if (!zeroOnly && (zeroRow === 0 || zeroRow === PLOT_ROWS - 1)) {
188
+ tickRows.add(Math.floor(PLOT_ROWS / 2));
189
+ }
190
+ const tickLabels = Array.from({ length: PLOT_ROWS }, (_, row) => tickRows.has(row) ? formatNumber(barAxisValue(row, minimum, maximum, zeroRow)) : "");
191
+ const yLabelWidth = Math.max(3, ...tickLabels.map((label) => displayWidth(label)));
192
+ const plotWidth = width - yLabelWidth - 3;
193
+ if (plotWidth < points.length)
194
+ return [];
195
+ const gap = points.length * 2 - 1 <= plotWidth ? 1 : 0;
196
+ const barWidth = Math.max(1, Math.floor((plotWidth - gap * (points.length - 1)) / points.length));
197
+ const usedWidth = points.length * barWidth + gap * (points.length - 1);
198
+ const lines = [];
199
+ for (let row = 0;row < PLOT_ROWS; row += 1) {
200
+ const label = tickLabels[row] ?? "";
201
+ const bars = values.map((value) => barCell(value, row, barWidth, minimum, maximum)).join(" ".slice(0, gap));
202
+ lines.push(`${label.padStart(yLabelWidth)} ${row === zeroRow ? "┼" : "┤"}${bars}`);
203
+ }
204
+ lines.push(`${"".padStart(yLabelWidth)} └${"─".repeat(usedWidth)}`);
205
+ const labels = points.map((point) => center(truncate(point.label, barWidth), barWidth).padEnd(barWidth + gap)).join("");
206
+ lines.push(`${"".padStart(yLabelWidth + 2)}${labels.trimEnd()}`);
207
+ return lines;
208
+ }
209
+ function barCell(value, row, width, minimum, maximum) {
210
+ if (value === 0)
211
+ return " ".repeat(width);
212
+ const range = maximum - minimum;
213
+ const zeroPosition = PLOT_ROWS * (maximum / range);
214
+ const valuePosition = PLOT_ROWS * ((maximum - value) / range);
215
+ const start = Math.min(zeroPosition, valuePosition);
216
+ const end = Math.max(zeroPosition, valuePosition);
217
+ const overlapStart = Math.max(start, row);
218
+ const overlapEnd = Math.min(end, row + 1);
219
+ const fraction = overlapEnd - overlapStart;
220
+ if (fraction <= 0)
221
+ return " ".repeat(width);
222
+ const touchesTop = overlapStart <= row;
223
+ const touchesBottom = overlapEnd >= row + 1;
224
+ const glyph = fraction >= 0.875 ? "█" : touchesTop ? fraction < 0.375 ? "▔" : "▀" : touchesBottom ? SPARK_GLYPHS[Math.max(0, Math.ceil(fraction * 8) - 1)] ?? "▁" : (overlapStart + overlapEnd) / 2 < row + 0.5 ? "▀" : "▄";
225
+ return glyph.repeat(width);
226
+ }
227
+ function barAxisValue(row, minimum, maximum, zeroRow) {
228
+ if (row === zeroRow)
229
+ return 0;
230
+ if (row === 0)
231
+ return maximum;
232
+ if (row === PLOT_ROWS - 1)
233
+ return minimum;
234
+ return (maximum + minimum) / 2;
235
+ }
236
+ function renderSparkline(points, width) {
237
+ const values = points.map((point) => point.value);
238
+ const minimum = Math.min(...values);
239
+ const maximum = Math.max(...values);
240
+ const minimumLabel = formatNumber(minimum);
241
+ const maximumLabel = formatNumber(maximum);
242
+ const chartWidth = Math.max(4, width - displayWidth(minimumLabel) - displayWidth(maximumLabel) - 2);
243
+ const sampled = resample(values, chartWidth);
244
+ const range = maximum - minimum || 1;
245
+ if (!Number.isFinite(range))
246
+ return [];
247
+ const spark = sampled.map((value) => SPARK_GLYPHS[Math.min(7, Math.floor((value - minimum) / range * 8))] ?? "▁").join("");
248
+ return [`${minimumLabel} ${spark} ${maximumLabel}`];
249
+ }
250
+ function renderHeatmap(rows, width) {
251
+ const rowLabelWidth = Math.min(14, Math.max(3, ...rows.map((row) => displayWidth(row.label))));
252
+ const columns = Math.max(0, ...rows.map((row) => row.values.length));
253
+ const plotWidth = width - rowLabelWidth - 3;
254
+ if (columns === 0 || plotWidth < 1)
255
+ return [];
256
+ const allValues = rows.flatMap((row) => row.values);
257
+ if (allValues.length === 0)
258
+ return [];
259
+ const minimum = Math.min(...allValues);
260
+ const maximum = Math.max(...allValues);
261
+ const range = maximum - minimum || 1;
262
+ if (!Number.isFinite(range))
263
+ return [];
264
+ const visibleColumns = Math.min(columns, plotWidth);
265
+ const columnWidths = Array.from({ length: visibleColumns }, (_, index) => Math.floor(plotWidth / visibleColumns) + (index < plotWidth % visibleColumns ? 1 : 0));
266
+ const lines = rows.map((row) => {
267
+ const values = resample(row.values, visibleColumns);
268
+ const cells = values.map((value, index) => {
269
+ const glyph = HEAT_GLYPHS[Math.min(3, Math.floor((value - minimum) / range * 4))] ?? "░";
270
+ return glyph.repeat(columnWidths[index] ?? 1);
271
+ }).join("");
272
+ return `${padEndWidth(truncate(row.label, rowLabelWidth), rowLabelWidth)} │ ${cells}`;
273
+ });
274
+ lines.push(`${"".padStart(rowLabelWidth + 3)}${HEAT_GLYPHS} low → high`);
275
+ return lines;
276
+ }
277
+ function resample(values, limit) {
278
+ if (limit <= 1)
279
+ return values.length > 0 ? [values[0] ?? 0] : [];
280
+ if (values.length === 0)
281
+ return [];
282
+ if (values.length === 1)
283
+ return Array.from({ length: limit }, () => values[0] ?? 0);
284
+ return Array.from({ length: limit }, (_, index) => {
285
+ const sourcePosition = index * (values.length - 1) / (limit - 1);
286
+ const lowerIndex = Math.floor(sourcePosition);
287
+ const upperIndex = Math.ceil(sourcePosition);
288
+ const lower = values[lowerIndex] ?? values[values.length - 1] ?? 0;
289
+ const upper = values[upperIndex] ?? lower;
290
+ return lower + (upper - lower) * (sourcePosition - lowerIndex);
291
+ });
292
+ }
293
+
294
+ // packages/ui/src/charts.ts
295
+ var CHART_PROMPT = [
296
+ "Fenced `chart`→display-only Unicode; terminal-small. Use only if clearer than prose/table.",
297
+ "Syntax: `type: bar|line|scatter|sparkline|heatmap`; optional `title:`; `data:` rows e.g. `Label 42`."
298
+ ].join(`
299
+ `);
300
+ var MAX_POINTS = 64;
301
+ var MAX_HEATMAP_ROWS = 32;
302
+ var MAX_SOURCE_LENGTH = 12000;
303
+ function transformChartMarkdown(markdown, availableWidth) {
304
+ const newline = markdown.includes(`\r
305
+ `) ? `\r
306
+ ` : `
307
+ `;
308
+ const lines = markdown.split(/\r?\n/u);
309
+ const output = [];
310
+ for (let index = 0;index < lines.length; index += 1) {
311
+ const line = lines[index] ?? "";
312
+ const opening = parseOpeningFence(line);
313
+ if (!opening) {
314
+ output.push(line);
315
+ continue;
316
+ }
317
+ const close = findClosingFence(lines, index + 1, opening.fence);
318
+ if (close === undefined) {
319
+ output.push(lines.slice(index).join(newline));
320
+ break;
321
+ }
322
+ if (opening.language !== "chart") {
323
+ output.push(lines.slice(index, close + 1).join(newline));
324
+ index = close;
325
+ continue;
326
+ }
327
+ const source = lines.slice(index + 1, close).join(`
328
+ `);
329
+ const spec = parseChartSource(source);
330
+ const rendered = spec ? renderChart(spec, availableWidth) : [];
331
+ if (rendered.length === 0) {
332
+ output.push(lines.slice(index, close + 1).join(newline));
333
+ } else {
334
+ output.push(...rendered.map((renderedLine) => `${codeSpan(renderedLine)} `));
335
+ }
336
+ index = close;
337
+ }
338
+ return output.join(newline);
339
+ }
340
+ function parseChartSource(source) {
341
+ if (source.length > MAX_SOURCE_LENGTH)
342
+ return;
343
+ const sourceLines = source.split(/\r?\n/u);
344
+ let type;
345
+ let title;
346
+ const dataLines = [];
347
+ for (const sourceLine of sourceLines) {
348
+ const line = sourceLine.trim();
349
+ if (!line || line.startsWith("#"))
350
+ continue;
351
+ const typeMatch = /^type\s*:\s*([a-z]+)\s*$/iu.exec(line);
352
+ if (typeMatch) {
353
+ const parsedType = normalizeChartType(typeMatch[1]);
354
+ if (!parsedType)
355
+ return;
356
+ type = parsedType;
357
+ continue;
358
+ }
359
+ if (/^(?:bar|histogram|line|scatter|sparkline|heatmap)$/iu.test(line) && !type) {
360
+ type = normalizeChartType(line);
361
+ continue;
362
+ }
363
+ const titleMatch = /^title\s*:\s*(.*?)\s*$/iu.exec(line);
364
+ if (titleMatch) {
365
+ title = titleMatch[1]?.trim() || undefined;
366
+ continue;
367
+ }
368
+ if (/^data\s*:\s*$/iu.test(line)) {
369
+ continue;
370
+ }
371
+ if (/^(?:width|height|x[-_ ]?min|x[-_ ]?max|y[-_ ]?min|y[-_ ]?max)\s*:/iu.test(line)) {
372
+ continue;
373
+ }
374
+ dataLines.push(sourceLine);
375
+ }
376
+ if (!type)
377
+ type = "bar";
378
+ if (type === "heatmap") {
379
+ const rows = dataLines.map(parseHeatmapRow).filter((row) => row !== undefined);
380
+ return rows.length > 0 ? {
381
+ type,
382
+ ...title ? { title } : {},
383
+ points: [],
384
+ rows: rows.slice(0, MAX_HEATMAP_ROWS)
385
+ } : undefined;
386
+ }
387
+ if (type === "sparkline") {
388
+ const values = dataLines.flatMap((dataLine, lineIndex) => {
389
+ const fields = dataLine.trim().split(/[\s,|\t]+/u).filter(Boolean);
390
+ const numericFields = fields.map(parseNumber);
391
+ if (numericFields.every((value) => value !== undefined)) {
392
+ return numericFields.map((value, valueIndex) => ({
393
+ label: String(lineIndex + valueIndex + 1),
394
+ value
395
+ }));
396
+ }
397
+ const point = parsePoint(dataLine, lineIndex);
398
+ return point ? [point] : [];
399
+ });
400
+ return values.length > 0 ? {
401
+ type,
402
+ ...title ? { title } : {},
403
+ points: values.slice(0, MAX_POINTS)
404
+ } : undefined;
405
+ }
406
+ const points = dataLines.map(parsePoint).filter((point) => point !== undefined);
407
+ return points.length > 0 ? { type, ...title ? { title } : {}, points: points.slice(0, MAX_POINTS) } : undefined;
408
+ }
409
+ function normalizeChartType(value) {
410
+ const normalized = value?.trim().toLowerCase();
411
+ return normalized === "histogram" ? "bar" : CHART_TYPES.find((type) => type === normalized);
412
+ }
413
+ function parseOpeningFence(line) {
414
+ const match = /^(?: {0,3})(`{3,}|~{3,})[^\S\r\n]*(.*)$/u.exec(line);
415
+ if (!match?.[1])
416
+ return;
417
+ const fenceCharacter = match[1][0];
418
+ if (fenceCharacter !== "`" && fenceCharacter !== "~")
419
+ return;
420
+ const info = (match[2] ?? "").trim();
421
+ if (fenceCharacter === "`" && info.includes("`"))
422
+ return;
423
+ return {
424
+ fence: { character: fenceCharacter, length: match[1].length },
425
+ language: info.split(/\s+/u, 1)[0]?.toLowerCase() ?? ""
426
+ };
427
+ }
428
+ function findClosingFence(lines, start, fence) {
429
+ for (let index = start;index < lines.length; index += 1) {
430
+ const trimmed = (lines[index] ?? "").replace(/^ {0,3}/u, "").trimEnd();
431
+ if (trimmed.length < fence.length || trimmed.split("").some((character) => character !== fence.character)) {
432
+ continue;
433
+ }
434
+ return index;
435
+ }
436
+ return;
437
+ }
438
+ function parsePoint(sourceLine, index) {
439
+ const line = sourceLine.trim();
440
+ if (!line || /^[-|]+$/u.test(line))
441
+ return;
442
+ const delimited = line.split(/\s*[|,\t]\s*/u).filter(Boolean);
443
+ if (delimited.length >= 2) {
444
+ const value = parseNumber(delimited[delimited.length - 1]);
445
+ const label = delimited.slice(0, -1).join(" ").trim();
446
+ if (value !== undefined && label)
447
+ return { label, value };
448
+ }
449
+ const pair = /^(.*?)\s+(-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?%?)$/iu.exec(line);
450
+ if (pair?.[1] && pair[2]) {
451
+ const value = parseNumber(pair[2]);
452
+ if (value !== undefined)
453
+ return { label: pair[1].trim(), value };
454
+ }
455
+ const value = parseNumber(line);
456
+ return value === undefined ? undefined : { label: String(index + 1), value };
457
+ }
458
+ function parseHeatmapRow(sourceLine) {
459
+ const line = sourceLine.trim();
460
+ if (!line || /^[-|]+$/u.test(line))
461
+ return;
462
+ const fields = line.split(/\s*[|,\t]\s*/u).filter(Boolean);
463
+ const cells = fields.length >= 2 ? fields : line.split(/\s+/u);
464
+ if (cells.length < 2)
465
+ return;
466
+ const label = cells[0]?.trim();
467
+ if (!label)
468
+ return;
469
+ const values = cells.slice(1).map(parseNumber);
470
+ return values.every((value) => value !== undefined) ? { label, values } : undefined;
471
+ }
472
+ function parseNumber(value) {
473
+ if (!value)
474
+ return;
475
+ const number = Number(value.trim().replace(/%$/u, ""));
476
+ return Number.isFinite(number) ? number : undefined;
477
+ }
478
+ function codeSpan(line) {
479
+ const content = line || " ";
480
+ const longestBacktickRun = Math.max(0, ...Array.from(content.matchAll(/`+/gu), (match) => match[0].length));
481
+ const fence = "`".repeat(longestBacktickRun + 1);
482
+ const padding = content.startsWith("`") || content.endsWith("`") || content.startsWith(" ") || content.endsWith(" ") ? " " : "";
483
+ return `${fence}${padding}${content}${padding}${fence}`;
484
+ }
485
+ export {
486
+ CHART_PROMPT,
487
+ renderChart,
488
+ transformChartMarkdown
489
+ };
@@ -94,7 +94,7 @@ function DiffWorkerProvider({
94
94
  function parseDiffPatch(patch, cacheKey) {
95
95
  if (!patch.trim())
96
96
  return [];
97
- const files = parsePatchFiles(patch.trim(), cacheKey).flatMap((parsed) => parsed.files);
97
+ const files = parsePatchFiles(patch.trim(), cacheKey === undefined ? undefined : { cacheKeyPrefix: cacheKey }).flatMap((parsed) => parsed.files);
98
98
  return files;
99
99
  }
100
100
  function DiffPanel({ context }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-durable-ui",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,16 +27,20 @@
27
27
  "types": "./dist/index.d.ts",
28
28
  "import": "./dist/index.js"
29
29
  },
30
+ "./charts": {
31
+ "types": "./dist/charts.d.ts",
32
+ "import": "./dist/charts.js"
33
+ },
30
34
  "./react/diff": {
31
35
  "types": "./dist/react/diff.d.ts",
32
36
  "import": "./dist/react/diff.js"
33
37
  }
34
38
  },
35
39
  "peerDependencies": {
36
- "@howaboua/pi-durable-git": "0.11.0",
37
- "@pierre/diffs": "1.6.1",
38
- "react": "19.3.0",
39
- "react-dom": "19.3.0"
40
+ "@howaboua/pi-durable-git": "0.13.0",
41
+ "@pierre/diffs": "1.7.2",
42
+ "react": "19.3.1",
43
+ "react-dom": "19.3.1"
40
44
  },
41
45
  "peerDependenciesMeta": {
42
46
  "@howaboua/pi-durable-git": {