@celljs/ta-glance 4.30.0 → 4.32.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/web/index.js CHANGED
@@ -1,1082 +1,1269 @@
1
- // web-src/glance-util.ts
2
- function percent(before, after) {
3
- if (!before) {
4
- return "";
1
+ // ../ta-protocol/esm/common/glance-json.js
2
+ var GlanceJson;
3
+ (function(GlanceJson2) {
4
+ const TRIES = 40;
5
+ const CONTROLS = { "\n": "\\n", "\r": "\\r", "\t": "\\t" };
6
+ const CURLY = "“”";
7
+ const FULL_WIDTH = { ":": ":", ",": "," };
8
+ const WORDS = { true: "true", false: "false", null: "null", True: "true", False: "false", None: "null" };
9
+ function parse(text) {
10
+ const source = text.trim().replace(/,\s*([}\]])/g, "$1");
11
+ if (!source) {
12
+ return;
13
+ }
14
+ try {
15
+ return JSON.parse(source);
16
+ } catch (_a) {
17
+ const balanced = balance(source);
18
+ if (!balanced.open.length && !balanced.inString) {
19
+ try {
20
+ return JSON.parse(balanced.text.replace(/,\s*([}\]])/g, "$1"));
21
+ } catch (_b) {}
22
+ }
23
+ }
24
+ let end = source.length;
25
+ for (let tries = 0;tries < TRIES && end > 0; tries++) {
26
+ const closed = close(source.slice(0, end));
27
+ if (closed !== undefined) {
28
+ try {
29
+ return JSON.parse(closed);
30
+ } catch (_c) {}
31
+ }
32
+ end = Math.max(source.lastIndexOf(",", end - 1), source.lastIndexOf("{", end - 1) + 1, source.lastIndexOf("[", end - 1) + 1);
33
+ }
34
+ return;
35
+ }
36
+ GlanceJson2.parse = parse;
37
+ function close(text) {
38
+ const balanced = balance(text);
39
+ if (!balanced || !balanced.open.length && !balanced.inString && balanced.text === text) {
40
+ return;
41
+ }
42
+ const { open, inString, escaped } = balanced;
43
+ let body = balanced.text;
44
+ if (inString) {
45
+ body = `${escaped ? body.slice(0, -1) : body}"`;
46
+ }
47
+ body = body.replace(/[\s,:]+$/, "");
48
+ if (open[open.length - 1] === "}" && /[{,]\s*"(?:[^"\\]|\\.)*"$/.test(body)) {
49
+ body = body.replace(/,?\s*"(?:[^"\\]|\\.)*"$/, "");
50
+ }
51
+ return body + open.reverse().join("");
52
+ }
53
+ function balance(text) {
54
+ var _a, _b;
55
+ var _c, _d, _e;
56
+ const open = [];
57
+ let inString = false;
58
+ let quote = "";
59
+ let escaped = false;
60
+ let last = "";
61
+ let out = "";
62
+ for (let index = 0;index < text.length; index++) {
63
+ const char = text[index];
64
+ if (inString) {
65
+ if (escaped) {
66
+ escaped = false;
67
+ if (char === "'") {
68
+ out = `${out.slice(0, -1)}'`;
69
+ continue;
70
+ }
71
+ } else if (char === "\\") {
72
+ escaped = true;
73
+ } else if (quote === "'") {
74
+ if (char === "'" && ends(text, index)) {
75
+ inString = false;
76
+ last = '"';
77
+ out += '"';
78
+ } else if (char === '"') {
79
+ out += "\\\"";
80
+ } else if (char < " ") {
81
+ out += (_c = CONTROLS[char]) !== null && _c !== undefined ? _c : `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
82
+ } else {
83
+ out += char;
84
+ }
85
+ continue;
86
+ } else if (char === '"' || char === CURLY[1]) {
87
+ if (char === '"' && !ends(text, index)) {
88
+ out += "\\\"";
89
+ continue;
90
+ }
91
+ if (char === CURLY[1] && !ends(text, index)) {
92
+ out += char;
93
+ continue;
94
+ }
95
+ inString = false;
96
+ last = '"';
97
+ out += '"';
98
+ continue;
99
+ } else if (char < " ") {
100
+ out += (_d = CONTROLS[char]) !== null && _d !== undefined ? _d : `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
101
+ continue;
102
+ }
103
+ out += char;
104
+ continue;
105
+ }
106
+ if (char <= " ") {
107
+ out += char;
108
+ continue;
109
+ }
110
+ if (char === "/" && (text[index + 1] === "/" || text[index + 1] === "*")) {
111
+ const end = text[index + 1] === "/" ? text.indexOf(`
112
+ `, index) : text.indexOf("*/", index + 2);
113
+ index = end < 0 ? text.length : text[index + 1] === "/" ? end - 1 : end + 1;
114
+ continue;
115
+ }
116
+ const number = (_a = /^-?\d+(?:\.\d*)?(?:[eE][+-]?\d*)?/.exec(text.slice(index, index + 64))) === null || _a === undefined ? undefined : _a[0];
117
+ if (number) {
118
+ if (/["}\]\w.]/.test(last)) {
119
+ out += ",";
120
+ }
121
+ out += number;
122
+ last = "0";
123
+ index += number.length - 1;
124
+ continue;
125
+ }
126
+ const word = (_b = /^[A-Za-z_$][\w$]*/.exec(text.slice(index, index + 64))) === null || _b === undefined ? undefined : _b[0];
127
+ const starts = char === '"' || char === "'" || CURLY.includes(char) || char === "{" || char === "[" || !!word;
128
+ if (starts && /["}\]\w.]/.test(last)) {
129
+ out += ",";
130
+ }
131
+ if (char === '"' || char === "'" || CURLY.includes(char)) {
132
+ inString = true;
133
+ quote = char === "'" ? "'" : '"';
134
+ out += '"';
135
+ continue;
136
+ }
137
+ if (word) {
138
+ const cut = index + word.length === text.length && Object.keys(WORDS).some((each) => each !== word && each.startsWith(word));
139
+ if (!cut) {
140
+ out += (_e = WORDS[word]) !== null && _e !== undefined ? _e : `"${word}"`;
141
+ last = '"';
142
+ }
143
+ index += word.length - 1;
144
+ continue;
145
+ }
146
+ if (FULL_WIDTH[char]) {
147
+ out += FULL_WIDTH[char];
148
+ last = FULL_WIDTH[char];
149
+ continue;
150
+ }
151
+ if (char === "{" || char === "[") {
152
+ open.push(char === "{" ? "}" : "]");
153
+ } else if (char === "}" || char === "]") {
154
+ if (open[open.length - 1] !== char) {
155
+ continue;
156
+ }
157
+ open.pop();
158
+ }
159
+ last = char;
160
+ out += char;
161
+ }
162
+ return { text: out, open, inString, escaped };
163
+ }
164
+ function ends(text, index) {
165
+ for (let next = index + 1;next < text.length; next++) {
166
+ const char = text[next];
167
+ if (char > " ") {
168
+ return ",:}]/:,".includes(char) || (char === '"' || char === "'" || CURLY.includes(char)) && /[\r\n]/.test(text.slice(index + 1, next));
169
+ }
170
+ }
171
+ return true;
5
172
  }
6
- const change = Math.round((after - before) / Math.abs(before) * 100);
7
- return `${change > 0 ? "+" : ""}${change}%`;
173
+ })(GlanceJson || (GlanceJson = {}));
174
+
175
+ // ../ta-protocol/esm/common/glance-protocol.js
176
+ var LANGUAGE = "ta-glance";
177
+ var ALIASES = ["glance", "glance-choice", "glance-card", "ta_glance", "taglance", "ta-glance-card", "ta-card"];
178
+
179
+ // ../ta-protocol/esm/common/figure-protocol.js
180
+ var TaFigure;
181
+ (function(TaFigure2) {
182
+ TaFigure2.DEFAULT_LANGUAGE = "ta-plot";
183
+ function markdown(value) {
184
+ if (typeof value === "string") {
185
+ return value.trim() || undefined;
186
+ }
187
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
188
+ return;
189
+ }
190
+ const keys = Object.keys(value);
191
+ const wrapped = keys.length === 1 && /^ta-[a-z0-9-]+$/.test(keys[0]);
192
+ const language = wrapped ? keys[0] : TaFigure2.DEFAULT_LANGUAGE;
193
+ const spec = wrapped ? value[language] : value;
194
+ return spec && typeof spec === "object" && Object.keys(spec).length ? `\`\`\`${language}
195
+ ${JSON.stringify(spec)}
196
+ \`\`\`` : undefined;
197
+ }
198
+ TaFigure2.markdown = markdown;
199
+ })(TaFigure || (TaFigure = {}));
200
+
201
+ // ../ta-protocol/esm/common/glance-mermaid.js
202
+ var SYNTAX = /[()[\]{}"<>|;#&@]/;
203
+ var NODE = /(^|[\s;&>|-])([\w\u00c0-\uffff]+)(?:\[(?!["[(/\\])(.*?)\]|\((?!["([])(.*?)\)|\{(?!["{])(.*?)\})(?=\s*(?:$|;|&|-|=|\.|~|<|:::))/g;
204
+ var GlanceMermaid;
205
+ (function(GlanceMermaid2) {
206
+ function repair(source) {
207
+ const body = source.trim().replace(/^\x60{3,}\s*mermaid[^\n]*\n/i, "").replace(/\n\x60{3,}\s*$/, "");
208
+ if (!/^\s*(?:graph|flowchart)\b/i.test(body)) {
209
+ return body;
210
+ }
211
+ return body.split(`
212
+ `).map((line) => line.replace(NODE, (whole, before, name, square, round, curly) => {
213
+ var _a, _b;
214
+ const label = (_b = (_a = square !== null && square !== undefined ? square : round) !== null && _a !== undefined ? _a : curly) !== null && _b !== undefined ? _b : "";
215
+ const open = square !== undefined ? "[" : round !== undefined ? "(" : "{";
216
+ const close = square !== undefined ? "]" : round !== undefined ? ")" : "}";
217
+ const shown = label.replace(/\\n/g, "<br/>");
218
+ if (!SYNTAX.test(shown.replace(/<br\s*\/?>/gi, ""))) {
219
+ return shown === label ? whole : before + name + open + shown + close;
220
+ }
221
+ return `${before + name + open}"${shown.replace(/"/g, "#quot;")}"${close}`;
222
+ })).join(`
223
+ `);
224
+ }
225
+ GlanceMermaid2.repair = repair;
226
+ })(GlanceMermaid || (GlanceMermaid = {}));
227
+
228
+ // ../ta-protocol/esm/common/glance-spec.js
229
+ var ITEMS = 12;
230
+ var FOLDED = 40;
231
+ var POINTS = 24;
232
+ var SERIES = 4;
233
+ var BLOCKS = 8;
234
+ var OPTIONS = 8;
235
+ var TEXT = 400;
236
+ var MARKDOWN = 8000;
237
+ var BOARD_COLUMNS = 6;
238
+ var CELLS = 24;
239
+ var BOARD_ROWS = 8;
240
+ var CELL_LINES = 6;
241
+ var STATUSES = ["done", "partial", "failed", "blocked", "info"];
242
+ var QUIET = ["done", "info"];
243
+ var TONES = ["good", "bad", "warn", "neutral"];
244
+ var STEPS = ["done", "doing", "todo", "failed", "skipped"];
245
+ var NOTES = ["risk", "todo", "info"];
246
+ var CHECKS = 3;
247
+ function passed(list, least) {
248
+ return list.length >= least && list.every((item) => item.tone === "good");
8
249
  }
9
- function range(values) {
10
- const low = Math.min(...values);
11
- const high = Math.max(...values);
12
- if (!values.length) {
13
- return { low: 0, high: 1 };
250
+ function object(value) {
251
+ return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
252
+ }
253
+ function text(value, max = TEXT) {
254
+ if (typeof value === "number" && Number.isFinite(value)) {
255
+ return String(value);
14
256
  }
15
- if (low === high) {
16
- return { low: low - 1, high: high + 1 };
257
+ if (typeof value !== "string") {
258
+ return;
17
259
  }
18
- const margin = (high - low) * 0.08;
19
- return { low: low - margin, high: high + margin };
260
+ const trimmed = value.trim();
261
+ return trimmed ? trimmed.slice(0, max) : undefined;
20
262
  }
21
- function points(values, count, { low, high }, width, height) {
22
- const step = count > 1 ? width / (count - 1) : 0;
23
- return values.map((value, index) => [count > 1 ? index * step : width / 2, height - (value - low) / (high - low) * height]);
263
+ function number(value) {
264
+ const parsed = typeof value === "string" ? Number.parseFloat(value.replace(/[^\d.eE+-]/g, "")) : value;
265
+ return typeof parsed === "number" && Number.isFinite(parsed) ? parsed : undefined;
24
266
  }
25
- function share(part, total) {
26
- const value = total > 0 ? part / total * 100 : 0;
27
- return value > 0 && value < 1 ? "<1%" : `${Math.round(value)}%`;
267
+ function oneOf(value, values) {
268
+ const lower = typeof value === "string" ? value.trim().toLowerCase() : undefined;
269
+ return values.find((candidate) => candidate === lower);
28
270
  }
29
- function wordy(value) {
30
- return !/\d/.test(value) || /[,;。、]|[,;]\s/.test(value) || value.length > 12;
271
+ function items(value, read, max = ITEMS) {
272
+ if (!Array.isArray(value)) {
273
+ return [];
274
+ }
275
+ const out = [];
276
+ for (const item of value) {
277
+ const made = read(item);
278
+ if (made !== undefined) {
279
+ out.push(made);
280
+ }
281
+ if (out.length === max) {
282
+ break;
283
+ }
284
+ }
285
+ return out;
31
286
  }
32
- function plain(text) {
33
- return text.replace(/\*\*|`/g, "").trim();
287
+ function icon(value) {
288
+ if (typeof value !== "string") {
289
+ return;
290
+ }
291
+ const words = value.trim().replace(/^lucide[:\-_\s]*/i, "").split(/[-_\s.:]+/).filter(Boolean);
292
+ const name = words.map((word) => word[0].toUpperCase() + word.slice(1)).join("");
293
+ return /^[A-Z][A-Za-z0-9]{0,39}$/.test(name) ? name : undefined;
34
294
  }
35
- function showsStatus(card) {
36
- return card.status === "done" ? !!card.title : !(card.status === "blocked" && card.blocks.some((block) => block.type === "options"));
295
+ function withIcon(value) {
296
+ const name = icon(value === null || value === undefined ? undefined : value.icon);
297
+ return name ? { icon: name } : {};
37
298
  }
38
-
39
- // web-src/react.ts
40
- var React;
41
- function bind(react) {
42
- React = react;
299
+ function strings(value, max = ITEMS) {
300
+ return items(value, (item) => {
301
+ var _a, _b;
302
+ var _c, _d;
303
+ return (_d = (_c = text(item)) !== null && _c !== undefined ? _c : text((_a = object(item)) === null || _a === undefined ? undefined : _a.label)) !== null && _d !== undefined ? _d : text((_b = object(item)) === null || _b === undefined ? undefined : _b.text);
304
+ }, max);
43
305
  }
44
-
45
- // web-src/card-charts.tsx
46
- var WIDTH = 300;
47
- var HEIGHT = 100;
48
- function count(value) {
49
- return Math.abs(value) >= 1000 ? value.toLocaleString() : String(Number(value.toFixed(2)));
306
+ function numbers(value, max = POINTS) {
307
+ return items(value, number, max);
50
308
  }
51
- function glanceCharts({ Text }) {
52
- function Polyline({
53
- values,
54
- count: count2,
55
- scale,
56
- area,
57
- index
58
- }) {
59
- const at = points(values, count2, scale, WIDTH, HEIGHT);
60
- const line = at.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
61
- const last = at[at.length - 1];
62
- return /* @__PURE__ */ React.createElement("g", {
63
- className: "tag-series",
64
- "data-index": index
65
- }, area && at.length > 1 && /* @__PURE__ */ React.createElement("polygon", {
66
- className: "tag-series-area",
67
- points: `0,${HEIGHT} ${line} ${last[0].toFixed(1)},${HEIGHT}`
68
- }), /* @__PURE__ */ React.createElement("polyline", {
69
- points: line,
70
- fill: "none",
71
- vectorEffect: "non-scaling-stroke"
72
- }));
73
- }
74
- function Sparkline({ values }) {
75
- return /* @__PURE__ */ React.createElement("svg", {
76
- className: "tag-spark",
77
- viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
78
- preserveAspectRatio: "none",
79
- "aria-hidden": "true"
80
- }, /* @__PURE__ */ React.createElement(Polyline, {
81
- values,
82
- count: values.length,
83
- scale: range(values),
84
- area: true,
85
- index: 0
86
- }));
87
- }
88
- function Line({ block }) {
89
- const size = Math.max(block.labels.length, ...block.series.map((line) => line.values.length));
90
- const scale = range(block.series.flatMap((line) => line.values));
91
- const unit = block.unit ? ` ${block.unit}` : "";
92
- const marks = [...new Set(size >= 5 ? [0, Math.round((size - 1) / 2), size - 1] : [0, size - 1])].filter((index) => block.labels[index] !== undefined);
93
- const where = (index) => size > 1 ? index / (size - 1) * 100 : 50;
94
- return /* @__PURE__ */ React.createElement("div", {
95
- className: "tag-line"
96
- }, /* @__PURE__ */ React.createElement("div", {
97
- className: "tag-section-head tag-legend"
98
- }, block.series.map((line, index) => {
99
- const first = line.values[0];
100
- const last = line.values[line.values.length - 1];
101
- const change = line.values.length > 1 ? percent(first, last) : "";
102
- const better = block.better === "higher" ? last > first : last < first;
103
- const tone = !block.better || last === first ? "neutral" : better ? "good" : "bad";
104
- return /* @__PURE__ */ React.createElement("span", {
105
- key: index,
106
- className: "tag-line-key",
107
- "data-index": index
108
- }, /* @__PURE__ */ React.createElement("i", null), line.label && /* @__PURE__ */ React.createElement(Text, {
109
- text: line.label
110
- }), /* @__PURE__ */ React.createElement("b", null, count(last), unit), change && /* @__PURE__ */ React.createElement("span", {
111
- className: "tag-delta",
112
- "data-tone": tone
113
- }, change));
114
- })), /* @__PURE__ */ React.createElement("div", {
115
- className: "tag-plot"
116
- }, /* @__PURE__ */ React.createElement("div", {
117
- className: "tag-plot-area"
118
- }, /* @__PURE__ */ React.createElement("svg", {
119
- viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
120
- preserveAspectRatio: "none",
121
- "aria-hidden": "true"
122
- }, [0, HEIGHT / 2, HEIGHT].map((y) => /* @__PURE__ */ React.createElement("line", {
123
- key: y,
124
- className: "tag-grid",
125
- x1: 0,
126
- x2: WIDTH,
127
- y1: y,
128
- y2: y,
129
- vectorEffect: "non-scaling-stroke"
130
- })), block.series.map((line, index) => /* @__PURE__ */ React.createElement(Polyline, {
131
- key: index,
132
- values: line.values,
133
- count: size,
134
- scale,
135
- area: index === 0 && block.series.length === 1,
136
- index
137
- }))), block.series.map((line, index) => {
138
- const [x, y] = points(line.values, size, scale, WIDTH, HEIGHT)[line.values.length - 1];
139
- return /* @__PURE__ */ React.createElement("i", {
140
- key: index,
141
- className: "tag-plot-dot",
142
- "data-index": index,
143
- style: { left: `${x / WIDTH * 100}%`, top: `${y / HEIGHT * 100}%` }
144
- });
145
- })), /* @__PURE__ */ React.createElement("div", {
146
- className: "tag-plot-axis",
147
- "aria-hidden": "true"
148
- }, /* @__PURE__ */ React.createElement("span", null, count(Math.max(...block.series.flatMap((line) => line.values)))), /* @__PURE__ */ React.createElement("span", null, count(Math.min(...block.series.flatMap((line) => line.values))))), marks.length > 0 && /* @__PURE__ */ React.createElement("div", {
149
- className: "tag-plot-labels"
150
- }, marks.map((index) => /* @__PURE__ */ React.createElement("span", {
151
- key: index,
152
- "data-at": index === 0 ? "start" : index === size - 1 ? "end" : "middle",
153
- style: { left: `${where(index)}%` }
154
- }, block.labels[index])))));
155
- }
156
- function Share({ block }) {
157
- const total = block.items.reduce((sum, item) => sum + item.value, 0);
158
- const unit = block.unit ? ` ${block.unit}` : "";
159
- return /* @__PURE__ */ React.createElement("div", {
160
- className: "tag-share"
161
- }, /* @__PURE__ */ React.createElement("div", {
162
- className: "tag-share-bar",
163
- "aria-hidden": "true"
164
- }, block.items.map((item, index) => /* @__PURE__ */ React.createElement("i", {
165
- key: index,
166
- "data-index": index,
167
- style: { flexGrow: item.value }
168
- }))), /* @__PURE__ */ React.createElement("div", {
169
- className: "tag-share-keys"
170
- }, block.items.map((item, index) => /* @__PURE__ */ React.createElement("div", {
171
- key: index,
172
- className: "tag-share-key",
173
- "data-index": index
174
- }, /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("span", {
175
- className: "tag-share-label"
176
- }, /* @__PURE__ */ React.createElement(Text, {
177
- text: item.label
178
- })), /* @__PURE__ */ React.createElement("span", {
179
- className: "tag-share-value"
180
- }, count(item.value), unit), /* @__PURE__ */ React.createElement("b", null, share(item.value, total))))));
181
- }
182
- return { Sparkline, Line, Share };
309
+ function amount(entry) {
310
+ const value = object(entry);
311
+ const label = text(value === null || value === undefined ? undefined : value.label);
312
+ const shown = number(value === null || value === undefined ? undefined : value.value);
313
+ return label && shown !== undefined ? { label, value: shown } : undefined;
183
314
  }
184
-
185
- // ../ta-protocol/esm/common/language.js
186
- var TaLanguageUtil;
187
- (function(TaLanguageUtil2) {
188
- TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
189
- TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
190
- function of(tag) {
191
- const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
192
- if (/^zh(\b|-)/.test(said)) {
193
- return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
194
- }
195
- return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
196
- }
197
- TaLanguageUtil2.of = of;
198
- function server(env = typeof process === "undefined" ? {} : process.env) {
199
- return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
315
+ function series(entry) {
316
+ var _a, _b;
317
+ const value = object(entry);
318
+ const values = numbers(Array.isArray(entry) ? entry : (_a = value === null || value === undefined ? undefined : value.values) !== null && _a !== undefined ? _a : value === null || value === undefined ? undefined : value.data);
319
+ const label = text((_b = value === null || value === undefined ? undefined : value.label) !== null && _b !== undefined ? _b : value === null || value === undefined ? undefined : value.name);
320
+ return values.length ? { values, ...label ? { label } : {} } : undefined;
321
+ }
322
+ function stat(item) {
323
+ const value = object(item);
324
+ const label = text(value === null || value === undefined ? undefined : value.label);
325
+ const shown = text(value === null || value === undefined ? undefined : value.value);
326
+ if (!label || shown === undefined) {
327
+ return;
200
328
  }
201
- TaLanguageUtil2.server = server;
202
- function pick(language, words) {
203
- return words[of(language)];
329
+ const tone = oneOf(value === null || value === undefined ? undefined : value.tone, TONES);
330
+ const delta = text(value === null || value === undefined ? undefined : value.delta);
331
+ const trend = numbers(value === null || value === undefined ? undefined : value.trend);
332
+ return { label, value: shown, ...tone ? { tone } : {}, ...delta ? { delta } : {}, ...withIcon(value), ...trend.length > 1 ? { trend } : {} };
333
+ }
334
+ function change(item) {
335
+ var _a, _b, _c;
336
+ const value = object(item);
337
+ const path = text((_b = (_a = value === null || value === undefined ? undefined : value.path) !== null && _a !== undefined ? _a : value === null || value === undefined ? undefined : value.file) !== null && _b !== undefined ? _b : item);
338
+ if (!path) {
339
+ return;
204
340
  }
205
- TaLanguageUtil2.pick = pick;
206
- function say(words) {
207
- return words[server()];
341
+ const kind = (_c = oneOf(value === null || value === undefined ? undefined : value.kind, ["add", "edit", "delete"])) !== null && _c !== undefined ? _c : "edit";
342
+ const add = number(value === null || value === undefined ? undefined : value.add);
343
+ const del = number(value === null || value === undefined ? undefined : value.del);
344
+ const note = text(value === null || value === undefined ? undefined : value.note);
345
+ return {
346
+ path,
347
+ kind,
348
+ ...add !== undefined ? { add: Math.max(0, Math.round(add)) } : {},
349
+ ...del !== undefined ? { del: Math.max(0, Math.round(del)) } : {},
350
+ ...note ? { note } : {}
351
+ };
352
+ }
353
+ function step(item, partial) {
354
+ var _a, _b, _c, _d;
355
+ const value = object(item);
356
+ const shown = text((_c = (_b = (_a = value === null || value === undefined ? undefined : value.text) !== null && _a !== undefined ? _a : value === null || value === undefined ? undefined : value.label) !== null && _b !== undefined ? _b : value === null || value === undefined ? undefined : value.title) !== null && _c !== undefined ? _c : item);
357
+ return shown ? { text: shown, status: (_d = oneOf(value === null || value === undefined ? undefined : value.status, STEPS)) !== null && _d !== undefined ? _d : partial ? "todo" : "done" } : undefined;
358
+ }
359
+ function option(item) {
360
+ var _a;
361
+ const value = object(item);
362
+ const label = text((_a = value === null || value === undefined ? undefined : value.label) !== null && _a !== undefined ? _a : item);
363
+ if (!label) {
364
+ return;
208
365
  }
209
- TaLanguageUtil2.say = say;
210
- function chinese(language) {
211
- return of(language).startsWith("zh");
366
+ const detail = text(value === null || value === undefined ? undefined : value.detail);
367
+ return {
368
+ label,
369
+ ...detail ? { detail } : {},
370
+ pros: strings(value === null || value === undefined ? undefined : value.pros, 4),
371
+ cons: strings(value === null || value === undefined ? undefined : value.cons, 4),
372
+ ...(value === null || value === undefined ? undefined : value.recommended) === true ? { recommended: true } : {},
373
+ ...withIcon(value)
374
+ };
375
+ }
376
+ function note(item) {
377
+ var _a, _b;
378
+ const value = object(item);
379
+ const shown = text((_a = value === null || value === undefined ? undefined : value.text) !== null && _a !== undefined ? _a : item);
380
+ return shown ? { text: shown, tone: (_b = oneOf(value === null || value === undefined ? undefined : value.tone, NOTES)) !== null && _b !== undefined ? _b : "info", ...withIcon(value) } : undefined;
381
+ }
382
+ function listItem(entry) {
383
+ var _a, _b;
384
+ const value = object(entry);
385
+ const shown = (_b = (_a = text(entry)) !== null && _a !== undefined ? _a : text(value === null || value === undefined ? undefined : value.text)) !== null && _b !== undefined ? _b : text(value === null || value === undefined ? undefined : value.label);
386
+ return shown ? { text: shown, ...withIcon(value) } : undefined;
387
+ }
388
+ function pair(value, max) {
389
+ const [first, second] = Array.isArray(value) ? value.map(number) : [];
390
+ return first !== undefined && second !== undefined && first >= 1 && second >= 1 ? [Math.min(Math.round(first), max[0]), Math.min(Math.round(second), max[1])] : undefined;
391
+ }
392
+ function cellLines(value) {
393
+ const written = typeof value === "string" ? value.split(`
394
+ `) : value;
395
+ return items(written, (line) => text(line, 80), CELL_LINES);
396
+ }
397
+ function cell(entry) {
398
+ var _a, _b, _c, _d, _e;
399
+ if (typeof entry === "string" || typeof entry === "number") {
400
+ return { lines: cellLines(String(entry)) };
212
401
  }
213
- TaLanguageUtil2.chinese = chinese;
214
- function cjk(language) {
215
- return of(language) !== "en-US";
402
+ const value = object(entry);
403
+ if (!value) {
404
+ return;
216
405
  }
217
- TaLanguageUtil2.cjk = cjk;
218
- function list(language, items) {
219
- return items.join(cjk(language) ? "、" : ", ");
406
+ const title = text((_b = (_a = value.title) !== null && _a !== undefined ? _a : value.label) !== null && _b !== undefined ? _b : value.name, 40);
407
+ const corner = text((_c = value.corner) !== null && _c !== undefined ? _c : value.tag, 16);
408
+ const tone = oneOf(value.tone, TONES);
409
+ const at = pair(value.at, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]);
410
+ const span = pair(value.span, [BOARD_ROWS, BOARD_COLUMNS]);
411
+ return {
412
+ lines: cellLines((_e = (_d = value.lines) !== null && _d !== undefined ? _d : value.items) !== null && _e !== undefined ? _e : value.text),
413
+ ...title ? { title } : {},
414
+ ...corner ? { corner } : {},
415
+ ...tone && tone !== "neutral" ? { tone } : {},
416
+ ...value.mark === true ? { mark: true } : {},
417
+ ...at ? { at } : {},
418
+ ...span && span[0] * span[1] > 1 ? { span } : {}
419
+ };
420
+ }
421
+ function boardColumns(cells) {
422
+ const area = cells.reduce((sum, one) => sum + (one.span ? one.span[0] * one.span[1] : 1), 0);
423
+ return area <= 4 ? area : Math.ceil(Math.sqrt(area));
424
+ }
425
+ function within(one, cols) {
426
+ const { at, span, ...rest } = one;
427
+ const kept = at && at[0] <= BOARD_ROWS && at[1] <= cols ? at : undefined;
428
+ const room = cols - (kept ? kept[1] : 1) + 1;
429
+ const taken = span ? [span[0], Math.min(span[1], room)] : undefined;
430
+ return { ...rest, ...kept ? { at: kept } : {}, ...taken && taken[0] * taken[1] > 1 ? { span: taken } : {} };
431
+ }
432
+ function point(item) {
433
+ var _a, _b, _c, _d;
434
+ const value = object(item);
435
+ const head = text((_a = value === null || value === undefined ? undefined : value.title) !== null && _a !== undefined ? _a : value === null || value === undefined ? undefined : value.label);
436
+ const body = text((_d = (_c = (_b = value === null || value === undefined ? undefined : value.detail) !== null && _b !== undefined ? _b : value === null || value === undefined ? undefined : value.note) !== null && _c !== undefined ? _c : value === null || value === undefined ? undefined : value.text) !== null && _d !== undefined ? _d : value === null || value === undefined ? undefined : value.description);
437
+ if (!value || !head) {
438
+ return note(value ? { text: body } : item);
220
439
  }
221
- TaLanguageUtil2.list = list;
222
- })(TaLanguageUtil || (TaLanguageUtil = {}));
223
-
224
- // web-src/i18n.ts
225
- var EN = {
226
- status: { done: "Done", partial: "Partly done", failed: "Failed", blocked: "Needs you", info: "" },
227
- before: "Before",
228
- after: "After",
229
- recommended: "Recommended",
230
- choose: "Choose",
231
- chosen: "Chosen",
232
- pick: "I choose: {label}",
233
- several: "Choose any",
234
- submit: "Send",
235
- listJoin: ", ",
236
- details: "Details",
237
- hide: "Hide",
238
- more: "{count} more",
239
- files: "{count} files",
240
- writing: "Drawing the summary…",
241
- spokenChoices: "You can choose: {labels}.",
242
- spokenRecommended: "I suggest {label}.",
243
- spokenFailed: "{text}: failed.",
244
- spokenJoin: ", "
245
- };
246
- var ZH = {
247
- status: { done: "已完成", partial: "部分完成", failed: "失败", blocked: "需要你", info: "" },
248
- before: "之前",
249
- after: "之后",
250
- recommended: "推荐",
251
- choose: "选这个",
252
- chosen: "已选",
253
- pick: "我选:{label}",
254
- several: "可多选",
255
- submit: "发送",
256
- listJoin: "、",
257
- details: "详情",
258
- hide: "收起",
259
- more: "还有 {count} 项",
260
- files: "{count} 个文件",
261
- writing: "正在整理摘要…",
262
- spokenChoices: "可以选:{labels}。",
263
- spokenRecommended: "推荐{label}。",
264
- spokenFailed: "{text}失败了。",
265
- spokenJoin: "、"
266
- };
267
- var ZH_TW = {
268
- status: { done: "已完成", partial: "部分完成", failed: "失敗", blocked: "需要你", info: "" },
269
- before: "之前",
270
- after: "之後",
271
- recommended: "推薦",
272
- choose: "選這個",
273
- chosen: "已選",
274
- pick: "我選:{label}",
275
- several: "可多選",
276
- submit: "送出",
277
- listJoin: "、",
278
- details: "詳情",
279
- hide: "收起",
280
- more: "還有 {count} 項",
281
- files: "{count} 個檔案",
282
- writing: "正在整理摘要…",
283
- spokenChoices: "可以選:{labels}。",
284
- spokenRecommended: "推薦{label}。",
285
- spokenFailed: "{text}失敗了。",
286
- spokenJoin: "、"
287
- };
288
- var JA = {
289
- status: { done: "完了", partial: "部分完了", failed: "失敗", blocked: "要対応", info: "" },
290
- before: "前",
291
- after: "後",
292
- recommended: "オススメ",
293
- choose: "これを選ぶ",
294
- chosen: "選択済み",
295
- pick: "私が選んだ:{label}",
296
- several: "複数選択可",
297
- submit: "送信",
298
- listJoin: "、",
299
- details: "詳細",
300
- hide: "隠す",
301
- more: "ほか {count} 件",
302
- files: "{count} 個のファイル",
303
- writing: "サマリーを作成中…",
304
- spokenChoices: "選択肢:{labels}。",
305
- spokenRecommended: "オススメは{label}です。",
306
- spokenFailed: "{text}は失敗しました。",
307
- spokenJoin: "、"
440
+ return { text: body ? `**${head}** ${body}` : head, tone: "info" };
441
+ }
442
+ function isPath(value) {
443
+ return !/[,。;!?、]/.test(value) && (!/\s/.test(value) || /[\\/]/.test(value));
444
+ }
445
+ var LABELS = { before: "Before", after: "After" };
446
+ function block(item, partial, labels) {
447
+ var _a;
448
+ const made = blockOf(item, partial, labels);
449
+ const fold = (_a = object(item)) === null || _a === undefined ? undefined : _a.fold;
450
+ const words = fold === true ? "" : text(fold, 40);
451
+ return made && words !== undefined ? { ...made, fold: words } : made;
452
+ }
453
+ var KINDS = {
454
+ metrics: "stats",
455
+ metric: "stats",
456
+ kpi: "stats",
457
+ kpis: "stats",
458
+ numbers: "stats",
459
+ stat: "stats",
460
+ files: "changes",
461
+ diff: "changes",
462
+ change: "changes",
463
+ checklist: "steps",
464
+ todo: "steps",
465
+ todos: "steps",
466
+ tasks: "steps",
467
+ plan: "steps",
468
+ progress: "steps",
469
+ timeline: "steps",
470
+ step: "steps",
471
+ comparison: "compare",
472
+ bar: "bars",
473
+ chart: "bars",
474
+ pie: "share",
475
+ donut: "share",
476
+ trend: "line",
477
+ path: "flow",
478
+ process: "flow",
479
+ pipeline: "flow",
480
+ mermaid: "diagram",
481
+ graph: "diagram",
482
+ choices: "options",
483
+ choice: "options",
484
+ poll: "options",
485
+ question: "options",
486
+ list: "notes",
487
+ bullets: "notes",
488
+ points: "notes",
489
+ risks: "notes",
490
+ warnings: "notes",
491
+ note: "notes",
492
+ text: "notes",
493
+ summary: "notes",
494
+ callout: "notes",
495
+ suggestions: "next",
496
+ actions: "next",
497
+ buttons: "next",
498
+ followups: "next",
499
+ markdown: "details",
500
+ detail: "details",
501
+ plot: "figure",
502
+ grid: "board",
503
+ matrix: "board",
504
+ palaces: "board",
505
+ houses: "board",
506
+ paipan: "board"
308
507
  };
309
- var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
310
- var GlanceWords;
311
- ((GlanceWords) => {
312
- function of(language) {
313
- return TaLanguageUtil.pick(language, WORDS);
314
- }
315
- GlanceWords.of = of;
316
- function picked(answer2, labels) {
317
- const said = answer2.trim();
318
- return labels.find((label) => said === label || said === format(EN.pick, { label }) || said === format(ZH.pick, { label }));
319
- }
320
- GlanceWords.picked = picked;
321
- const PICKS = Object.values(WORDS).map((words) => words.pick.replace("{label}", ""));
322
- function answer(words, picks) {
323
- if (picks.length === 1) {
324
- return format(words.pick, { label: picks[0].labels.join(words.listJoin) });
508
+ function mended(value, named, type) {
509
+ var _a, _b, _c, _d, _e, _f, _g;
510
+ const list = [value.items, value.list, value.entries, value[named], value[type]].find(Array.isArray);
511
+ const words = (_b = (_a = text(value.text)) !== null && _a !== undefined ? _a : text(value.content)) !== null && _b !== undefined ? _b : text(value.body);
512
+ return {
513
+ ...value,
514
+ ...list ? { items: list } : type === "notes" && words ? { items: [words] } : {},
515
+ markdown: (_e = (_d = (_c = value.markdown) !== null && _c !== undefined ? _c : value.content) !== null && _d !== undefined ? _d : value.text) !== null && _e !== undefined ? _e : value.body,
516
+ mermaid: (_g = (_f = value.mermaid) !== null && _f !== undefined ? _f : value.code) !== null && _g !== undefined ? _g : value.source
517
+ };
518
+ }
519
+ function blockOf(item, partial, labels) {
520
+ var _a, _b, _c, _d, _e, _f;
521
+ const raw = object(item);
522
+ const named = typeof (raw === null || raw === undefined ? undefined : raw.type) === "string" ? raw.type.trim().toLowerCase().replace(/[\s_]+/g, "-") : undefined;
523
+ const kind = named && typeof (raw === null || raw === undefined ? undefined : raw.mermaid) === "string" ? "diagram" : named && ((_a = KINDS[named]) !== null && _a !== undefined ? _a : named);
524
+ const value = raw && named && kind ? mended(raw, named, kind) : raw;
525
+ const type = kind;
526
+ const unit = text(value === null || value === undefined ? undefined : value.unit, 16);
527
+ switch (type) {
528
+ case "stats": {
529
+ const list = items(value === null || value === undefined ? undefined : value.items, stat).slice(0, 6);
530
+ return list.length ? { type, items: list, ...passed(list, CHECKS) ? { checks: true } : {} } : undefined;
325
531
  }
326
- return [format(words.pick, { label: "" }).trim(), ...picks.map((pick) => `${pick.key} ${pick.labels.join(words.listJoin)}`)].join(`
327
- `);
328
- }
329
- GlanceWords.answer = answer;
330
- function chosen(answer2, labels, key) {
331
- const lines = answer2.trim().split(`
332
- `).map((line) => line.trim());
333
- let said;
334
- if (key !== undefined) {
335
- const line = lines.find((each) => each.startsWith(key));
336
- if (line === undefined) {
337
- return [];
532
+ case "changes": {
533
+ const raw2 = Array.isArray(value === null || value === undefined ? undefined : value.items) ? value.items : [];
534
+ const pathless = (entry) => {
535
+ var _a2, _b2;
536
+ var _c2;
537
+ return typeof entry === "string" ? !isPath(entry) : !!object(entry) && !text((_c2 = (_a2 = object(entry)) === null || _a2 === undefined ? undefined : _a2.path) !== null && _c2 !== undefined ? _c2 : (_b2 = object(entry)) === null || _b2 === undefined ? undefined : _b2.file);
538
+ };
539
+ if (raw2.length && raw2.every(pathless)) {
540
+ const list2 = items(raw2, point);
541
+ return list2.length ? { type: "notes", items: list2 } : undefined;
338
542
  }
339
- said = line.slice(key.length).trim();
340
- } else {
341
- said = lines.join(" ");
342
- const prefix = PICKS.find((each) => each && said.startsWith(each));
343
- said = (prefix ? said.slice(prefix.length) : said).trim();
543
+ const list = items(value === null || value === undefined ? undefined : value.items, change, FOLDED);
544
+ return list.length ? { type, items: list } : undefined;
344
545
  }
345
- const parts = said.split(/\s*(?:、|,\s|,)\s*/);
346
- return labels.filter((label) => said === label || parts.includes(label));
347
- }
348
- GlanceWords.chosen = chosen;
349
- function format(text, values) {
350
- return text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
351
- }
352
- GlanceWords.format = format;
353
- })(GlanceWords ||= {});
354
-
355
- // web-src/card-options.tsx
356
- function formKey(ask, index) {
357
- return ask.question ? plain(ask.question) : `${index + 1}.`;
358
- }
359
- function glanceOptions(pi, { Reply, Answer, Text, Icon, has }) {
360
- const FormOf = React.createContext(undefined);
361
- function useForm(card, words, send, answer) {
362
- const asks = React.useMemo(() => card?.blocks.filter((block) => block.type === "options") ?? [], [card]);
363
- const [tapped, setTapped] = React.useState({});
364
- const [sent, setSent] = React.useState(false);
365
- if (!(asks.length > 1 || asks.some((ask) => ask.multi))) {
366
- return;
546
+ case "steps": {
547
+ const list = items(value === null || value === undefined ? undefined : value.items, (entry) => step(entry, partial));
548
+ return list.length ? { type, items: list } : undefined;
367
549
  }
368
- const done = sent || answer !== undefined;
369
- const picks = asks.map((ask, index) => {
370
- const labels = ask.items.map((item) => item.label);
371
- if (!sent && answer !== undefined) {
372
- return GlanceWords.chosen(answer, labels, asks.length > 1 ? formKey(ask, index) : undefined);
373
- }
374
- const picked = tapped[index] ?? ask.items.filter((item) => item.recommended).map((item) => item.label);
375
- return labels.filter((label) => picked.includes(label)).slice(0, ask.multi ? undefined : 1);
376
- });
377
- return {
378
- asks,
379
- picks,
380
- done,
381
- toggle(index, label) {
382
- const now = picks[index];
383
- const next = asks[index].multi ? now.includes(label) ? now.filter((each) => each !== label) : [...now, label] : [label];
384
- setTapped({ ...tapped, [index]: next });
385
- },
386
- submit() {
387
- if (!send || done || picks.some((each) => !each.length)) {
388
- return;
389
- }
390
- setSent(true);
391
- const text = GlanceWords.answer(words, asks.map((ask, index) => ({ key: formKey(ask, index), labels: picks[index] })));
392
- send(text).catch((error) => {
393
- setSent(false);
394
- pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
395
- });
550
+ case "compare": {
551
+ const list = items(value === null || value === undefined ? undefined : value.items, (entry) => {
552
+ const measure = object(entry);
553
+ const label = text(measure === null || measure === undefined ? undefined : measure.label);
554
+ const before = number(measure === null || measure === undefined ? undefined : measure.before);
555
+ const after = number(measure === null || measure === undefined ? undefined : measure.after);
556
+ return label && before !== undefined && after !== undefined ? { label, before, after } : undefined;
557
+ });
558
+ const better = (_b = oneOf(value === null || value === undefined ? undefined : value.better, ["lower", "higher"])) !== null && _b !== undefined ? _b : "lower";
559
+ if (list.length) {
560
+ return { type, better, items: list, ...unit ? { unit } : {} };
396
561
  }
397
- };
398
- }
399
- function Options({ block, words, closed }) {
400
- const [tapped, setChosen] = React.useState();
401
- const send = React.useContext(Reply);
402
- const form = React.useContext(FormOf);
403
- const answer = React.useContext(Answer);
404
- const ask = form ? form.asks.indexOf(block) : -1;
405
- const inForm = !!form && ask >= 0;
406
- const said = answer.text === undefined ? undefined : GlanceWords.picked(answer.text, block.items.map((item) => item.label));
407
- const chosen = inForm ? form.picks[ask] : [tapped ?? said].filter((label) => label !== undefined);
408
- const done = inForm ? form.done : chosen.length > 0 || answer.text !== undefined;
409
- const pending = answer.known && closed && !done && (!inForm || ask === 0);
410
- const choose = (label) => {
411
- if (!send) {
562
+ const rows = items(value === null || value === undefined ? undefined : value.items, (entry) => {
563
+ const measure = object(entry);
564
+ const label = text(measure === null || measure === undefined ? undefined : measure.label);
565
+ const before = text(measure === null || measure === undefined ? undefined : measure.before);
566
+ const after = text(measure === null || measure === undefined ? undefined : measure.after);
567
+ return label && (before || after) ? [label, before !== null && before !== undefined ? before : "", after !== null && after !== undefined ? after : ""] : undefined;
568
+ });
569
+ return rows.length ? { type: "table", columns: ["", labels.before, labels.after], rows } : undefined;
570
+ }
571
+ case "bars": {
572
+ const list = items(value === null || value === undefined ? undefined : value.items, amount, FOLDED);
573
+ return list.length ? { type, items: list, ...unit ? { unit } : {} } : undefined;
574
+ }
575
+ case "line": {
576
+ const points = items(value === null || value === undefined ? undefined : value.items, amount, POINTS);
577
+ const lines = points.length ? [{ values: points.map((point2) => point2.value) }] : Array.isArray(value === null || value === undefined ? undefined : value.series) ? items(value.series, series, SERIES) : [series(value)].filter((line) => !!line);
578
+ const labels2 = points.length ? points.map((point2) => point2.label) : strings(value === null || value === undefined ? undefined : value.labels, POINTS);
579
+ const better = oneOf(value === null || value === undefined ? undefined : value.better, ["lower", "higher"]);
580
+ const drawn = lines.filter((line) => partial || line.values.length > 1);
581
+ return drawn.length ? { type, labels: labels2, series: drawn, ...unit ? { unit } : {}, ...better ? { better } : {} } : undefined;
582
+ }
583
+ case "share": {
584
+ const list = items(value === null || value === undefined ? undefined : value.items, amount, 6).filter((part) => part.value > 0);
585
+ return list.length ? { type, items: list, ...unit ? { unit } : {} } : undefined;
586
+ }
587
+ case "flow": {
588
+ const list = items(value === null || value === undefined ? undefined : value.items, listItem);
589
+ return list.length ? { type, items: list } : undefined;
590
+ }
591
+ case "diagram": {
592
+ const mermaid = text(value === null || value === undefined ? undefined : value.mermaid, MARKDOWN);
593
+ return mermaid ? { type, mermaid: GlanceMermaid.repair(mermaid) } : undefined;
594
+ }
595
+ case "table": {
596
+ const columns = items(value === null || value === undefined ? undefined : value.columns, (column) => {
597
+ var _a2;
598
+ return (_a2 = text(column)) !== null && _a2 !== undefined ? _a2 : typeof column === "string" ? "" : undefined;
599
+ }, 6);
600
+ const rows = items(value === null || value === undefined ? undefined : value.rows, (row) => Array.isArray(row) ? columns.map((_, index) => {
601
+ var _a2;
602
+ return (_a2 = text(row[index])) !== null && _a2 !== undefined ? _a2 : "";
603
+ }) : undefined, FOLDED);
604
+ return columns.length && rows.length ? { type, columns, rows } : undefined;
605
+ }
606
+ case "board": {
607
+ const cells = items((_c = value === null || value === undefined ? undefined : value.cells) !== null && _c !== undefined ? _c : value === null || value === undefined ? undefined : value.items, cell, CELLS);
608
+ if (!cells.length) {
412
609
  return;
413
610
  }
414
- if (inForm) {
415
- form.toggle(ask, label);
611
+ const written = number((_d = value === null || value === undefined ? undefined : value.cols) !== null && _d !== undefined ? _d : value === null || value === undefined ? undefined : value.columns);
612
+ const cols = Math.min(BOARD_COLUMNS, Math.max(1, Math.round(written !== null && written !== undefined ? written : boardColumns(cells))));
613
+ return { type, cols, cells: cells.map((one) => within(one, cols)) };
614
+ }
615
+ case "options": {
616
+ const list = items(value === null || value === undefined ? undefined : value.items, option).slice(0, OPTIONS);
617
+ const question = text(value === null || value === undefined ? undefined : value.question);
618
+ return list.length ? { type, items: list, ...question ? { question } : {}, ...(value === null || value === undefined ? undefined : value.multi) === true ? { multi: true } : {} } : undefined;
619
+ }
620
+ case "notes": {
621
+ const list = items(value === null || value === undefined ? undefined : value.items, note).sort((a, b) => NOTES.indexOf(a.tone) - NOTES.indexOf(b.tone));
622
+ return list.length ? { type, items: list } : undefined;
623
+ }
624
+ case "next": {
625
+ const list = items(value === null || value === undefined ? undefined : value.items, listItem).slice(0, 3);
626
+ return list.length ? { type, items: list } : undefined;
627
+ }
628
+ case "figure": {
629
+ const own = Object.fromEntries(Object.entries(raw !== null && raw !== undefined ? raw : {}).filter(([key]) => key !== "type" && key !== "fold"));
630
+ const markdown = TaFigure.markdown((_f = (_e = own.figure) !== null && _e !== undefined ? _e : own.markdown) !== null && _f !== undefined ? _f : own);
631
+ return markdown ? { type, markdown } : undefined;
632
+ }
633
+ case "details": {
634
+ const markdown = text(value === null || value === undefined ? undefined : value.markdown, MARKDOWN);
635
+ const title = text(value === null || value === undefined ? undefined : value.title);
636
+ return markdown ? { type, markdown, ...title ? { title } : {} } : undefined;
637
+ }
638
+ default: {
639
+ const list = items(value === null || value === undefined ? undefined : value.items, point);
640
+ if (list.length) {
641
+ return { type: "notes", items: list };
642
+ }
643
+ const markdown = text(value === null || value === undefined ? undefined : value.markdown, MARKDOWN);
644
+ if (!markdown) {
416
645
  return;
417
646
  }
418
- setChosen(label);
419
- send(GlanceWords.format(words.pick, { label })).catch((error) => {
420
- setChosen(undefined);
421
- pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
422
- });
423
- };
424
- return /* @__PURE__ */ React.createElement("div", {
425
- className: "tag-options-block",
426
- "data-pending": pending || undefined
427
- }, (block.question || block.multi) && /* @__PURE__ */ React.createElement("div", {
428
- className: "tag-question"
429
- }, block.question && /* @__PURE__ */ React.createElement(Text, {
430
- text: block.question
431
- }), block.multi && /* @__PURE__ */ React.createElement("span", {
432
- className: "tag-several"
433
- }, words.several)), inForm ? /* @__PURE__ */ React.createElement("div", {
434
- className: "tag-picks"
435
- }, block.items.map((item, index) => {
436
- const picked = chosen.includes(item.label);
437
- return /* @__PURE__ */ React.createElement("button", {
438
- key: index,
439
- type: "button",
440
- className: "tag-pick",
441
- "aria-pressed": picked,
442
- "data-multi": block.multi || undefined,
443
- "data-other": done && !picked || undefined,
444
- disabled: !closed || !send || done,
445
- onClick: () => choose(item.label)
446
- }, /* @__PURE__ */ React.createElement("span", {
447
- className: "tag-pick-mark"
448
- }, picked && /* @__PURE__ */ React.createElement(Icon, {
449
- name: "Check",
450
- size: 11
451
- })), /* @__PURE__ */ React.createElement("span", {
452
- className: "tag-option-main"
453
- }, /* @__PURE__ */ React.createElement("span", {
454
- className: "tag-option-head"
455
- }, has(item.icon) && /* @__PURE__ */ React.createElement("span", {
456
- className: "tag-item-icon"
457
- }, /* @__PURE__ */ React.createElement(Icon, {
458
- name: item.icon,
459
- size: 14
460
- })), /* @__PURE__ */ React.createElement("span", {
461
- className: "tag-option-label"
462
- }, /* @__PURE__ */ React.createElement(Text, {
463
- text: item.label
464
- })), item.recommended && /* @__PURE__ */ React.createElement("span", {
465
- className: "tag-badge"
466
- }, words.recommended)), item.detail && /* @__PURE__ */ React.createElement("span", {
467
- className: "tag-option-detail"
468
- }, /* @__PURE__ */ React.createElement(Text, {
469
- text: item.detail
470
- }))));
471
- })) : /* @__PURE__ */ React.createElement("div", {
472
- className: "tag-options"
473
- }, block.items.map((item, index) => {
474
- const picked = chosen.includes(item.label);
475
- return /* @__PURE__ */ React.createElement("div", {
476
- key: index,
477
- className: "tag-option",
478
- "data-recommended": item.recommended || undefined,
479
- "data-chosen": picked || undefined,
480
- "data-other": done && !picked || undefined
481
- }, /* @__PURE__ */ React.createElement("div", {
482
- className: "tag-option-main"
483
- }, /* @__PURE__ */ React.createElement("div", {
484
- className: "tag-option-head"
485
- }, has(item.icon) && /* @__PURE__ */ React.createElement("span", {
486
- className: "tag-item-icon"
487
- }, /* @__PURE__ */ React.createElement(Icon, {
488
- name: item.icon,
489
- size: 14
490
- })), /* @__PURE__ */ React.createElement("span", {
491
- className: "tag-option-label"
492
- }, /* @__PURE__ */ React.createElement(Text, {
493
- text: item.label
494
- })), item.recommended && /* @__PURE__ */ React.createElement("span", {
495
- className: "tag-badge"
496
- }, words.recommended)), item.detail && /* @__PURE__ */ React.createElement("div", {
497
- className: "tag-option-detail"
498
- }, /* @__PURE__ */ React.createElement(Text, {
499
- text: item.detail
500
- })), (item.pros.length > 0 || item.cons.length > 0) && /* @__PURE__ */ React.createElement("div", {
501
- className: "tag-points"
502
- }, item.pros.map((point, at) => /* @__PURE__ */ React.createElement("span", {
503
- key: `p${at}`,
504
- "data-tone": "good"
505
- }, /* @__PURE__ */ React.createElement(Text, {
506
- text: point
507
- }))), item.cons.map((point, at) => /* @__PURE__ */ React.createElement("span", {
508
- key: `c${at}`,
509
- "data-tone": "bad"
510
- }, /* @__PURE__ */ React.createElement(Text, {
511
- text: point
512
- }))))), /* @__PURE__ */ React.createElement("button", {
513
- type: "button",
514
- className: `ta-button tag-choose${item.recommended && !done && !inForm ? " ta-primary" : ""}`,
515
- "aria-pressed": inForm ? picked : undefined,
516
- disabled: !closed || !send || done,
517
- onClick: () => choose(item.label)
518
- }, picked && /* @__PURE__ */ React.createElement(Icon, {
519
- name: "Check",
520
- size: 13
521
- }), /* @__PURE__ */ React.createElement("span", null, picked ? words.chosen : words.choose)));
522
- })), inForm && ask === form.asks.length - 1 && !form.done && /* @__PURE__ */ React.createElement("div", {
523
- className: "tag-submit"
524
- }, /* @__PURE__ */ React.createElement("button", {
525
- type: "button",
526
- className: "ta-button ta-primary",
527
- disabled: !closed || !send || form.picks.some((each) => !each.length),
528
- onClick: () => form.submit()
529
- }, /* @__PURE__ */ React.createElement(Icon, {
530
- name: "Send",
531
- size: 13
532
- }), /* @__PURE__ */ React.createElement("span", null, words.submit))));
647
+ return markdown.length > TEXT || markdown.includes(`
648
+ `) ? { type: "details", markdown } : { type: "notes", items: [{ text: markdown, tone: "info" }] };
649
+ }
533
650
  }
534
- return { Options, FormOf, useForm };
535
651
  }
536
-
537
- // web-src/glance-json.ts
538
- var GlanceJson;
539
- ((GlanceJson) => {
540
- const TRIES = 40;
541
- const CONTROLS = { "\n": "\\n", "\r": "\\r", "\t": "\\t" };
542
- const CURLY = "“”";
543
- function parse(text) {
544
- const source = text.trim().replace(/,\s*([}\]])/g, "$1");
545
- if (!source) {
546
- return;
547
- }
548
- try {
549
- return JSON.parse(source);
550
- } catch {
551
- const balanced = balance(source);
552
- if (!balanced.open.length && !balanced.inString) {
553
- try {
554
- return JSON.parse(balanced.text.replace(/,\s*([}\]])/g, "$1"));
555
- } catch {}
556
- }
557
- }
558
- let end = source.length;
559
- for (let tries = 0;tries < TRIES && end > 0; tries++) {
560
- const closed = close(source.slice(0, end));
561
- if (closed !== undefined) {
562
- try {
563
- return JSON.parse(closed);
564
- } catch {}
565
- }
566
- end = Math.max(source.lastIndexOf(",", end - 1), source.lastIndexOf("{", end - 1) + 1, source.lastIndexOf("[", end - 1) + 1);
652
+ function loose(card) {
653
+ var _a, _b;
654
+ const out = [];
655
+ for (const [key, entries] of Object.entries(card)) {
656
+ const type = key === "files" ? "changes" : key;
657
+ if (Array.isArray(entries) && LISTS.includes(type)) {
658
+ out.push({ type, items: entries, ...type === "options" ? { question: card.question } : {} });
567
659
  }
568
- return;
569
660
  }
570
- GlanceJson.parse = parse;
571
- function close(text) {
572
- const balanced = balance(text);
573
- if (!balanced || !balanced.open.length && !balanced.inString && balanced.text === text) {
661
+ const words = (_b = (_a = text(card.summary)) !== null && _a !== undefined ? _a : text(card.text)) !== null && _b !== undefined ? _b : text(card.message);
662
+ return out.length || !words ? out : [{ type: "notes", items: [words] }];
663
+ }
664
+ var LISTS = ["stats", "changes", "steps", "flow", "options", "notes", "next"];
665
+ var PLACE = { stats: -1, notes: 1, next: 2, details: 3 };
666
+ function place(block2) {
667
+ var _a;
668
+ return block2.fold !== undefined ? 3 : (_a = PLACE[block2.type]) !== null && _a !== undefined ? _a : 0;
669
+ }
670
+ function placed(blocks) {
671
+ return blocks.map((block2, index) => ({ block: block2, index })).sort((a, b) => place(a.block) - place(b.block) || a.index - b.index).map((entry) => entry.block);
672
+ }
673
+ var GlanceSpec;
674
+ (function(GlanceSpec2) {
675
+ function read(value, partial = false, labels = LABELS) {
676
+ const card = Array.isArray(value) ? { blocks: value } : object(value);
677
+ if (!card) {
574
678
  return;
575
679
  }
576
- const { open, inString, escaped } = balanced;
577
- let body = balanced.text;
578
- if (inString) {
579
- body = `${escaped ? body.slice(0, -1) : body}"`;
580
- }
581
- body = body.replace(/[\s,:]+$/, "");
582
- if (open[open.length - 1] === "}" && /[{,]\s*"(?:[^"\\]|\\.)*"$/.test(body)) {
583
- body = body.replace(/,?\s*"(?:[^"\\]|\\.)*"$/, "");
680
+ const status = oneOf(card.status, STATUSES);
681
+ const title = text(card.title);
682
+ const written = Array.isArray(card.blocks) ? card.blocks : object(card.blocks) ? [card.blocks] : loose(card);
683
+ const blocks = placed(items(written, (entry) => block(entry, partial, labels)).slice(0, BLOCKS)).map((made) => made.type === "stats" && !made.checks && status && !QUIET.includes(status) && passed(made.items, 1) ? { ...made, checks: true } : made);
684
+ if (!blocks.length && !title) {
685
+ return;
584
686
  }
585
- return body + open.reverse().join("");
687
+ return { blocks, ...status ? { status } : {}, ...title ? { title } : {} };
586
688
  }
587
- function balance(text) {
588
- const open = [];
589
- let inString = false;
590
- let escaped = false;
591
- let last = "";
592
- let out = "";
593
- for (let index = 0;index < text.length; index++) {
594
- const char = text[index];
595
- if (inString) {
596
- if (escaped) {
597
- escaped = false;
598
- } else if (char === "\\") {
599
- escaped = true;
600
- } else if (char === '"' || char === CURLY[1]) {
601
- if (char === '"' && !ends(text, index)) {
602
- out += "\\\"";
603
- continue;
604
- }
605
- if (char === CURLY[1] && !ends(text, index)) {
606
- out += char;
607
- continue;
608
- }
609
- inString = false;
610
- last = '"';
611
- out += '"';
612
- continue;
613
- } else if (char < " ") {
614
- out += CONTROLS[char] ?? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
615
- continue;
616
- }
617
- out += char;
618
- continue;
619
- }
620
- if (char <= " ") {
621
- out += char;
622
- continue;
623
- }
624
- const starts = char === '"' || CURLY.includes(char) || char === "{" || char === "[";
625
- if (starts && /["}\]\w.]/.test(last)) {
626
- out += ",";
627
- }
628
- if (char === '"' || CURLY.includes(char)) {
629
- inString = true;
630
- out += '"';
631
- continue;
632
- }
633
- if (char === "{" || char === "[") {
634
- open.push(char === "{" ? "}" : "]");
635
- } else if (char === "}" || char === "]") {
636
- if (open[open.length - 1] !== char) {
637
- continue;
638
- }
639
- open.pop();
640
- }
641
- last = char;
642
- out += char;
643
- }
644
- return { text: out, open, inString, escaped };
689
+ GlanceSpec2.read = read;
690
+ })(GlanceSpec || (GlanceSpec = {}));
691
+
692
+ // web-src/react.ts
693
+ var React;
694
+ function bind(react) {
695
+ React = react;
696
+ }
697
+
698
+ // web-src/card-board.tsx
699
+ function glanceBoard({ Text }) {
700
+ function cellPlace(cell2) {
701
+ const [rows, cols] = cell2.span ?? [1, 1];
702
+ const line = (start, count) => start ? `${start} / span ${count}` : count > 1 ? `span ${count}` : undefined;
703
+ return { gridRow: line(cell2.at?.[0], rows), gridColumn: line(cell2.at?.[1], cols) };
645
704
  }
646
- function ends(text, index) {
647
- for (let next = index + 1;next < text.length; next++) {
648
- const char = text[next];
649
- if (char > " ") {
650
- return ",:}]".includes(char) || (char === '"' || CURLY.includes(char)) && /[\r\n]/.test(text.slice(index + 1, next));
651
- }
652
- }
653
- return true;
705
+ function Board({ block: block2 }) {
706
+ return /* @__PURE__ */ React.createElement("div", {
707
+ className: "tag-board",
708
+ "data-cols": block2.cols,
709
+ style: { gridTemplateColumns: `repeat(${block2.cols}, minmax(0, 1fr))` }
710
+ }, block2.cells.map((cell2, index) => /* @__PURE__ */ React.createElement("div", {
711
+ key: index,
712
+ className: "tag-cell",
713
+ "data-tone": cell2.tone,
714
+ "data-mark": cell2.mark || undefined,
715
+ "data-wide": cell2.span || undefined,
716
+ style: cellPlace(cell2)
717
+ }, (cell2.title || cell2.corner) && /* @__PURE__ */ React.createElement("div", {
718
+ className: "tag-cell-head"
719
+ }, cell2.title && /* @__PURE__ */ React.createElement("span", {
720
+ className: "tag-cell-title"
721
+ }, /* @__PURE__ */ React.createElement(Text, {
722
+ text: cell2.title
723
+ })), cell2.corner && /* @__PURE__ */ React.createElement("span", {
724
+ className: "tag-cell-corner"
725
+ }, /* @__PURE__ */ React.createElement(Text, {
726
+ text: cell2.corner
727
+ }))), cell2.lines.length > 0 && /* @__PURE__ */ React.createElement("div", {
728
+ className: "tag-cell-lines"
729
+ }, cell2.lines.map((line, row) => /* @__PURE__ */ React.createElement("span", {
730
+ key: row
731
+ }, /* @__PURE__ */ React.createElement(Text, {
732
+ text: line
733
+ })))))));
654
734
  }
655
- })(GlanceJson ||= {});
735
+ return { Board };
736
+ }
656
737
 
657
- // ../ta-protocol/esm/common/figure-protocol.js
658
- var TaFigure;
659
- (function(TaFigure2) {
660
- TaFigure2.DEFAULT_LANGUAGE = "ta-plot";
661
- function markdown(value) {
662
- if (typeof value === "string") {
663
- return value.trim() || undefined;
664
- }
665
- if (!value || typeof value !== "object" || Array.isArray(value)) {
666
- return;
667
- }
668
- const keys = Object.keys(value);
669
- const wrapped = keys.length === 1 && /^ta-[a-z0-9-]+$/.test(keys[0]);
670
- const language = wrapped ? keys[0] : TaFigure2.DEFAULT_LANGUAGE;
671
- const spec = wrapped ? value[language] : value;
672
- return spec && typeof spec === "object" && Object.keys(spec).length ? `\`\`\`${language}
673
- ${JSON.stringify(spec)}
674
- \`\`\`` : undefined;
675
- }
676
- TaFigure2.markdown = markdown;
677
- })(TaFigure || (TaFigure = {}));
678
-
679
- // web-src/glance-mermaid.ts
680
- var SYNTAX = /[()[\]{}"<>|;#&@]/;
681
- var NODE = /(^|[\s;&>|-])([\w\u00c0-\uffff]+)(?:\[(?!["[(/\\])(.*?)\]|\((?!["([])(.*?)\)|\{(?!["{])(.*?)\})(?=\s*(?:$|;|&|-|=|\.|~|<|:::))/g;
682
- var GlanceMermaid;
683
- ((GlanceMermaid) => {
684
- function repair(source) {
685
- const body = source.trim().replace(/^\x60{3,}\s*mermaid[^\n]*\n/i, "").replace(/\n\x60{3,}\s*$/, "");
686
- if (!/^\s*(?:graph|flowchart)\b/i.test(body)) {
687
- return body;
688
- }
689
- return body.split(`
690
- `).map((line) => line.replace(NODE, (whole, before, name, square, round, curly) => {
691
- const label = square ?? round ?? curly ?? "";
692
- const open = square !== undefined ? "[" : round !== undefined ? "(" : "{";
693
- const close = square !== undefined ? "]" : round !== undefined ? ")" : "}";
694
- const shown = label.replace(/\\n/g, "<br/>");
695
- if (!SYNTAX.test(shown.replace(/<br\s*\/?>/gi, ""))) {
696
- return shown === label ? whole : before + name + open + shown + close;
697
- }
698
- return `${before + name + open}"${shown.replace(/"/g, "#quot;")}"${close}`;
699
- })).join(`
700
- `);
701
- }
702
- GlanceMermaid.repair = repair;
703
- })(GlanceMermaid ||= {});
704
-
705
- // web-src/glance-spec.ts
706
- var ITEMS = 12;
707
- var FOLDED = 40;
708
- var POINTS = 24;
709
- var SERIES = 4;
710
- var BLOCKS = 8;
711
- var OPTIONS = 8;
712
- var TEXT = 400;
713
- var MARKDOWN = 8000;
714
- var STATUSES = ["done", "partial", "failed", "blocked", "info"];
715
- var QUIET = ["done", "info"];
716
- var TONES = ["good", "bad", "warn", "neutral"];
717
- var STEPS = ["done", "doing", "todo", "failed", "skipped"];
718
- var NOTES = ["risk", "todo", "info"];
719
- var CHECKS = 3;
720
- function passed(list, least) {
721
- return list.length >= least && list.every((item) => item.tone === "good");
722
- }
723
- function object(value) {
724
- return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
725
- }
726
- function text(value, max = TEXT) {
727
- if (typeof value === "number" && Number.isFinite(value)) {
728
- return String(value);
729
- }
730
- if (typeof value !== "string") {
731
- return;
738
+ // web-src/glance-util.ts
739
+ function percent(before, after) {
740
+ if (!before) {
741
+ return "";
732
742
  }
733
- const trimmed = value.trim();
734
- return trimmed ? trimmed.slice(0, max) : undefined;
735
- }
736
- function number(value) {
737
- const parsed = typeof value === "string" ? Number.parseFloat(value.replace(/[^\d.eE+-]/g, "")) : value;
738
- return typeof parsed === "number" && Number.isFinite(parsed) ? parsed : undefined;
739
- }
740
- function oneOf(value, values) {
741
- const lower = typeof value === "string" ? value.trim().toLowerCase() : undefined;
742
- return values.find((candidate) => candidate === lower);
743
+ const change2 = Math.round((after - before) / Math.abs(before) * 100);
744
+ return `${change2 > 0 ? "+" : ""}${change2}%`;
743
745
  }
744
- function items(value, read, max = ITEMS) {
745
- if (!Array.isArray(value)) {
746
- return [];
746
+ function range(values) {
747
+ const low = Math.min(...values);
748
+ const high = Math.max(...values);
749
+ if (!values.length) {
750
+ return { low: 0, high: 1 };
747
751
  }
748
- const out = [];
749
- for (const item of value) {
750
- const made = read(item);
751
- if (made !== undefined) {
752
- out.push(made);
753
- }
754
- if (out.length === max) {
755
- break;
756
- }
752
+ if (low === high) {
753
+ return { low: low - 1, high: high + 1 };
757
754
  }
758
- return out;
755
+ const margin = (high - low) * 0.08;
756
+ return { low: low - margin, high: high + margin };
759
757
  }
760
- function icon(value) {
761
- if (typeof value !== "string") {
762
- return;
763
- }
764
- const words = value.trim().replace(/^lucide[:\-_\s]*/i, "").split(/[-_\s.:]+/).filter(Boolean);
765
- const name = words.map((word) => word[0].toUpperCase() + word.slice(1)).join("");
766
- return /^[A-Z][A-Za-z0-9]{0,39}$/.test(name) ? name : undefined;
758
+ function points(values, count, { low, high }, width, height) {
759
+ const step2 = count > 1 ? width / (count - 1) : 0;
760
+ return values.map((value, index) => [count > 1 ? index * step2 : width / 2, height - (value - low) / (high - low) * height]);
767
761
  }
768
- function withIcon(value) {
769
- const name = icon(value?.icon);
770
- return name ? { icon: name } : {};
762
+ function share(part, total) {
763
+ const value = total > 0 ? part / total * 100 : 0;
764
+ return value > 0 && value < 1 ? "<1%" : `${Math.round(value)}%`;
771
765
  }
772
- function strings(value, max = ITEMS) {
773
- return items(value, (item) => text(item) ?? text(object(item)?.label) ?? text(object(item)?.text), max);
766
+ function wordy(value) {
767
+ return !/\d/.test(value) || /[,;。、]|[,;]\s/.test(value) || value.length > 12;
774
768
  }
775
- function numbers(value, max = POINTS) {
776
- return items(value, number, max);
769
+ function plain(text2) {
770
+ return text2.replace(/\*\*|`/g, "").trim();
777
771
  }
778
- function amount(entry) {
779
- const value = object(entry);
780
- const label = text(value?.label);
781
- const shown = number(value?.value);
782
- return label && shown !== undefined ? { label, value: shown } : undefined;
772
+ function showsStatus(card) {
773
+ return card.status === "done" ? !!card.title : !(card.status === "blocked" && card.blocks.some((block2) => block2.type === "options"));
783
774
  }
784
- function series(entry) {
785
- const value = object(entry);
786
- const values = numbers(Array.isArray(entry) ? entry : value?.values ?? value?.data);
787
- const label = text(value?.label ?? value?.name);
788
- return values.length ? { values, ...label ? { label } : {} } : undefined;
775
+
776
+ // web-src/card-charts.tsx
777
+ var WIDTH = 300;
778
+ var HEIGHT = 100;
779
+ function count(value) {
780
+ return Math.abs(value) >= 1000 ? value.toLocaleString() : String(Number(value.toFixed(2)));
789
781
  }
790
- function stat(item) {
791
- const value = object(item);
792
- const label = text(value?.label);
793
- const shown = text(value?.value);
794
- if (!label || shown === undefined) {
795
- return;
782
+ function glanceCharts({ Text }) {
783
+ function Polyline({
784
+ values,
785
+ count: count2,
786
+ scale,
787
+ area,
788
+ index
789
+ }) {
790
+ const at = points(values, count2, scale, WIDTH, HEIGHT);
791
+ const line = at.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
792
+ const last = at[at.length - 1];
793
+ return /* @__PURE__ */ React.createElement("g", {
794
+ className: "tag-series",
795
+ "data-index": index
796
+ }, area && at.length > 1 && /* @__PURE__ */ React.createElement("polygon", {
797
+ className: "tag-series-area",
798
+ points: `0,${HEIGHT} ${line} ${last[0].toFixed(1)},${HEIGHT}`
799
+ }), /* @__PURE__ */ React.createElement("polyline", {
800
+ points: line,
801
+ fill: "none",
802
+ vectorEffect: "non-scaling-stroke"
803
+ }));
796
804
  }
797
- const tone = oneOf(value?.tone, TONES);
798
- const delta = text(value?.delta);
799
- const trend = numbers(value?.trend);
800
- return { label, value: shown, ...tone ? { tone } : {}, ...delta ? { delta } : {}, ...withIcon(value), ...trend.length > 1 ? { trend } : {} };
801
- }
802
- function change(item) {
803
- const value = object(item);
804
- const path = text(value?.path ?? value?.file ?? item);
805
- if (!path) {
806
- return;
805
+ function Sparkline({ values }) {
806
+ return /* @__PURE__ */ React.createElement("svg", {
807
+ className: "tag-spark",
808
+ viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
809
+ preserveAspectRatio: "none",
810
+ "aria-hidden": "true"
811
+ }, /* @__PURE__ */ React.createElement(Polyline, {
812
+ values,
813
+ count: values.length,
814
+ scale: range(values),
815
+ area: true,
816
+ index: 0
817
+ }));
807
818
  }
808
- const kind = oneOf(value?.kind, ["add", "edit", "delete"]) ?? "edit";
809
- const add = number(value?.add);
810
- const del = number(value?.del);
811
- const note = text(value?.note);
812
- return {
813
- path,
814
- kind,
815
- ...add !== undefined ? { add: Math.max(0, Math.round(add)) } : {},
816
- ...del !== undefined ? { del: Math.max(0, Math.round(del)) } : {},
817
- ...note ? { note } : {}
818
- };
819
- }
820
- function step(item, partial) {
821
- const value = object(item);
822
- const shown = text(value?.text ?? value?.label ?? value?.title ?? item);
823
- return shown ? { text: shown, status: oneOf(value?.status, STEPS) ?? (partial ? "todo" : "done") } : undefined;
824
- }
825
- function option(item) {
826
- const value = object(item);
827
- const label = text(value?.label ?? item);
828
- if (!label) {
829
- return;
819
+ function Line({ block: block2 }) {
820
+ const size = Math.max(block2.labels.length, ...block2.series.map((line) => line.values.length));
821
+ const scale = range(block2.series.flatMap((line) => line.values));
822
+ const unit = block2.unit ? ` ${block2.unit}` : "";
823
+ const marks = [...new Set(size >= 5 ? [0, Math.round((size - 1) / 2), size - 1] : [0, size - 1])].filter((index) => block2.labels[index] !== undefined);
824
+ const where = (index) => size > 1 ? index / (size - 1) * 100 : 50;
825
+ return /* @__PURE__ */ React.createElement("div", {
826
+ className: "tag-line"
827
+ }, /* @__PURE__ */ React.createElement("div", {
828
+ className: "tag-section-head tag-legend"
829
+ }, block2.series.map((line, index) => {
830
+ const first = line.values[0];
831
+ const last = line.values[line.values.length - 1];
832
+ const change2 = line.values.length > 1 ? percent(first, last) : "";
833
+ const better = block2.better === "higher" ? last > first : last < first;
834
+ const tone = !block2.better || last === first ? "neutral" : better ? "good" : "bad";
835
+ return /* @__PURE__ */ React.createElement("span", {
836
+ key: index,
837
+ className: "tag-line-key",
838
+ "data-index": index
839
+ }, /* @__PURE__ */ React.createElement("i", null), line.label && /* @__PURE__ */ React.createElement(Text, {
840
+ text: line.label
841
+ }), /* @__PURE__ */ React.createElement("b", null, count(last), unit), change2 && /* @__PURE__ */ React.createElement("span", {
842
+ className: "tag-delta",
843
+ "data-tone": tone
844
+ }, change2));
845
+ })), /* @__PURE__ */ React.createElement("div", {
846
+ className: "tag-plot"
847
+ }, /* @__PURE__ */ React.createElement("div", {
848
+ className: "tag-plot-area"
849
+ }, /* @__PURE__ */ React.createElement("svg", {
850
+ viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
851
+ preserveAspectRatio: "none",
852
+ "aria-hidden": "true"
853
+ }, [0, HEIGHT / 2, HEIGHT].map((y) => /* @__PURE__ */ React.createElement("line", {
854
+ key: y,
855
+ className: "tag-grid",
856
+ x1: 0,
857
+ x2: WIDTH,
858
+ y1: y,
859
+ y2: y,
860
+ vectorEffect: "non-scaling-stroke"
861
+ })), block2.series.map((line, index) => /* @__PURE__ */ React.createElement(Polyline, {
862
+ key: index,
863
+ values: line.values,
864
+ count: size,
865
+ scale,
866
+ area: index === 0 && block2.series.length === 1,
867
+ index
868
+ }))), block2.series.map((line, index) => {
869
+ const [x, y] = points(line.values, size, scale, WIDTH, HEIGHT)[line.values.length - 1];
870
+ return /* @__PURE__ */ React.createElement("i", {
871
+ key: index,
872
+ className: "tag-plot-dot",
873
+ "data-index": index,
874
+ style: { left: `${x / WIDTH * 100}%`, top: `${y / HEIGHT * 100}%` }
875
+ });
876
+ })), /* @__PURE__ */ React.createElement("div", {
877
+ className: "tag-plot-axis",
878
+ "aria-hidden": "true"
879
+ }, /* @__PURE__ */ React.createElement("span", null, count(Math.max(...block2.series.flatMap((line) => line.values)))), /* @__PURE__ */ React.createElement("span", null, count(Math.min(...block2.series.flatMap((line) => line.values))))), marks.length > 0 && /* @__PURE__ */ React.createElement("div", {
880
+ className: "tag-plot-labels"
881
+ }, marks.map((index) => /* @__PURE__ */ React.createElement("span", {
882
+ key: index,
883
+ "data-at": index === 0 ? "start" : index === size - 1 ? "end" : "middle",
884
+ style: { left: `${where(index)}%` }
885
+ }, block2.labels[index])))));
830
886
  }
831
- const detail = text(value?.detail);
832
- return {
833
- label,
834
- ...detail ? { detail } : {},
835
- pros: strings(value?.pros, 4),
836
- cons: strings(value?.cons, 4),
837
- ...value?.recommended === true ? { recommended: true } : {},
838
- ...withIcon(value)
839
- };
840
- }
841
- function note(item) {
842
- const value = object(item);
843
- const shown = text(value?.text ?? item);
844
- return shown ? { text: shown, tone: oneOf(value?.tone, NOTES) ?? "info", ...withIcon(value) } : undefined;
845
- }
846
- function listItem(entry) {
847
- const value = object(entry);
848
- const shown = text(entry) ?? text(value?.text) ?? text(value?.label);
849
- return shown ? { text: shown, ...withIcon(value) } : undefined;
850
- }
851
- function point(item) {
852
- const value = object(item);
853
- const head = text(value?.title ?? value?.label);
854
- const body = text(value?.detail ?? value?.note ?? value?.text ?? value?.description);
855
- if (!value || !head) {
856
- return note(value ? { text: body } : item);
887
+ function Share({ block: block2 }) {
888
+ const total = block2.items.reduce((sum, item) => sum + item.value, 0);
889
+ const unit = block2.unit ? ` ${block2.unit}` : "";
890
+ return /* @__PURE__ */ React.createElement("div", {
891
+ className: "tag-share"
892
+ }, /* @__PURE__ */ React.createElement("div", {
893
+ className: "tag-share-bar",
894
+ "aria-hidden": "true"
895
+ }, block2.items.map((item, index) => /* @__PURE__ */ React.createElement("i", {
896
+ key: index,
897
+ "data-index": index,
898
+ style: { flexGrow: item.value }
899
+ }))), /* @__PURE__ */ React.createElement("div", {
900
+ className: "tag-share-keys"
901
+ }, block2.items.map((item, index) => /* @__PURE__ */ React.createElement("div", {
902
+ key: index,
903
+ className: "tag-share-key",
904
+ "data-index": index
905
+ }, /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("span", {
906
+ className: "tag-share-label"
907
+ }, /* @__PURE__ */ React.createElement(Text, {
908
+ text: item.label
909
+ })), /* @__PURE__ */ React.createElement("span", {
910
+ className: "tag-share-value"
911
+ }, count(item.value), unit), /* @__PURE__ */ React.createElement("b", null, share(item.value, total))))));
857
912
  }
858
- return { text: body ? `**${head}** ${body}` : head, tone: "info" };
859
- }
860
- function isPath(value) {
861
- return !/[,。;!?、]/.test(value) && (!/\s/.test(value) || /[\\/]/.test(value));
862
- }
863
- var LABELS = { before: "Before", after: "After" };
864
- function block(item, partial, labels) {
865
- const made = blockOf(item, partial, labels);
866
- const fold = object(item)?.fold;
867
- const words = fold === true ? "" : text(fold, 40);
868
- return made && words !== undefined ? { ...made, fold: words } : made;
869
- }
870
- var KINDS = {
871
- metrics: "stats",
872
- metric: "stats",
873
- kpi: "stats",
874
- kpis: "stats",
875
- numbers: "stats",
876
- stat: "stats",
877
- files: "changes",
878
- diff: "changes",
879
- change: "changes",
880
- checklist: "steps",
881
- todo: "steps",
882
- todos: "steps",
883
- tasks: "steps",
884
- plan: "steps",
885
- progress: "steps",
886
- timeline: "steps",
887
- step: "steps",
888
- comparison: "compare",
889
- bar: "bars",
890
- chart: "bars",
891
- pie: "share",
892
- donut: "share",
893
- trend: "line",
894
- path: "flow",
895
- process: "flow",
896
- pipeline: "flow",
897
- mermaid: "diagram",
898
- graph: "diagram",
899
- choices: "options",
900
- choice: "options",
901
- poll: "options",
902
- question: "options",
903
- list: "notes",
904
- bullets: "notes",
905
- points: "notes",
906
- risks: "notes",
907
- warnings: "notes",
908
- note: "notes",
909
- text: "notes",
910
- summary: "notes",
911
- callout: "notes",
912
- suggestions: "next",
913
- actions: "next",
914
- buttons: "next",
915
- followups: "next",
916
- markdown: "details",
917
- detail: "details",
918
- plot: "figure"
919
- };
920
- function mended(value, named, type) {
921
- const list = [value.items, value.list, value.entries, value[named], value[type]].find(Array.isArray);
922
- const words = text(value.text) ?? text(value.content) ?? text(value.body);
923
- return {
924
- ...value,
925
- ...list ? { items: list } : type === "notes" && words ? { items: [words] } : {},
926
- markdown: value.markdown ?? value.content ?? value.text ?? value.body,
927
- mermaid: value.mermaid ?? value.code ?? value.source
928
- };
913
+ return { Sparkline, Line, Share };
929
914
  }
930
- function blockOf(item, partial, labels) {
931
- const raw = object(item);
932
- const named = typeof raw?.type === "string" ? raw.type.trim().toLowerCase().replace(/[\s_]+/g, "-") : undefined;
933
- const kind = named && typeof raw?.mermaid === "string" ? "diagram" : named && (KINDS[named] ?? named);
934
- const value = raw && named && kind ? mended(raw, named, kind) : raw;
935
- const type = kind;
936
- const unit = text(value?.unit, 16);
937
- switch (type) {
938
- case "stats": {
939
- const list = items(value?.items, stat).slice(0, 6);
940
- return list.length ? { type, items: list, ...passed(list, CHECKS) ? { checks: true } : {} } : undefined;
941
- }
942
- case "changes": {
943
- const raw2 = Array.isArray(value?.items) ? value.items : [];
944
- const pathless = (entry) => typeof entry === "string" ? !isPath(entry) : !!object(entry) && !text(object(entry)?.path ?? object(entry)?.file);
945
- if (raw2.length && raw2.every(pathless)) {
946
- const list2 = items(raw2, point);
947
- return list2.length ? { type: "notes", items: list2 } : undefined;
948
- }
949
- const list = items(value?.items, change, FOLDED);
950
- return list.length ? { type, items: list } : undefined;
951
- }
952
- case "steps": {
953
- const list = items(value?.items, (entry) => step(entry, partial));
954
- return list.length ? { type, items: list } : undefined;
955
- }
956
- case "compare": {
957
- const list = items(value?.items, (entry) => {
958
- const measure = object(entry);
959
- const label = text(measure?.label);
960
- const before = number(measure?.before);
961
- const after = number(measure?.after);
962
- return label && before !== undefined && after !== undefined ? { label, before, after } : undefined;
963
- });
964
- const better = oneOf(value?.better, ["lower", "higher"]) ?? "lower";
965
- if (list.length) {
966
- return { type, better, items: list, ...unit ? { unit } : {} };
967
- }
968
- const rows = items(value?.items, (entry) => {
969
- const measure = object(entry);
970
- const label = text(measure?.label);
971
- const before = text(measure?.before);
972
- const after = text(measure?.after);
973
- return label && (before || after) ? [label, before ?? "", after ?? ""] : undefined;
974
- });
975
- return rows.length ? { type: "table", columns: ["", labels.before, labels.after], rows } : undefined;
976
- }
977
- case "bars": {
978
- const list = items(value?.items, amount, FOLDED);
979
- return list.length ? { type, items: list, ...unit ? { unit } : {} } : undefined;
980
- }
981
- case "line": {
982
- const points2 = items(value?.items, amount, POINTS);
983
- const lines = points2.length ? [{ values: points2.map((point2) => point2.value) }] : Array.isArray(value?.series) ? items(value.series, series, SERIES) : [series(value)].filter((line) => !!line);
984
- const labels2 = points2.length ? points2.map((point2) => point2.label) : strings(value?.labels, POINTS);
985
- const better = oneOf(value?.better, ["lower", "higher"]);
986
- const drawn = lines.filter((line) => partial || line.values.length > 1);
987
- return drawn.length ? { type, labels: labels2, series: drawn, ...unit ? { unit } : {}, ...better ? { better } : {} } : undefined;
988
- }
989
- case "share": {
990
- const list = items(value?.items, amount, 6).filter((part) => part.value > 0);
991
- return list.length ? { type, items: list, ...unit ? { unit } : {} } : undefined;
992
- }
993
- case "flow": {
994
- const list = items(value?.items, listItem);
995
- return list.length ? { type, items: list } : undefined;
996
- }
997
- case "diagram": {
998
- const mermaid = text(value?.mermaid, MARKDOWN);
999
- return mermaid ? { type, mermaid: GlanceMermaid.repair(mermaid) } : undefined;
1000
- }
1001
- case "table": {
1002
- const columns = items(value?.columns, (column) => text(column) ?? (typeof column === "string" ? "" : undefined), 6);
1003
- const rows = items(value?.rows, (row) => Array.isArray(row) ? columns.map((_, index) => text(row[index]) ?? "") : undefined, FOLDED);
1004
- return columns.length && rows.length ? { type, columns, rows } : undefined;
1005
- }
1006
- case "options": {
1007
- const list = items(value?.items, option).slice(0, OPTIONS);
1008
- const question = text(value?.question);
1009
- return list.length ? { type, items: list, ...question ? { question } : {}, ...value?.multi === true ? { multi: true } : {} } : undefined;
1010
- }
1011
- case "notes": {
1012
- const list = items(value?.items, note).sort((a, b) => NOTES.indexOf(a.tone) - NOTES.indexOf(b.tone));
1013
- return list.length ? { type, items: list } : undefined;
1014
- }
1015
- case "next": {
1016
- const list = items(value?.items, listItem).slice(0, 3);
1017
- return list.length ? { type, items: list } : undefined;
1018
- }
1019
- case "figure": {
1020
- const own = Object.fromEntries(Object.entries(raw ?? {}).filter(([key]) => key !== "type" && key !== "fold"));
1021
- const markdown = TaFigure.markdown(own.figure ?? own.markdown ?? own);
1022
- return markdown ? { type, markdown } : undefined;
915
+
916
+ // ../ta-protocol/esm/common/language.js
917
+ var TaLanguageUtil;
918
+ (function(TaLanguageUtil2) {
919
+ TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
920
+ TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
921
+ function of(tag) {
922
+ const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
923
+ if (/^zh(\b|-)/.test(said)) {
924
+ return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
1023
925
  }
1024
- case "details": {
1025
- const markdown = text(value?.markdown, MARKDOWN);
1026
- const title = text(value?.title);
1027
- return markdown ? { type, markdown, ...title ? { title } : {} } : undefined;
926
+ return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
927
+ }
928
+ TaLanguageUtil2.of = of;
929
+ function server(env = typeof process === "undefined" ? {} : process.env) {
930
+ return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
931
+ }
932
+ TaLanguageUtil2.server = server;
933
+ function pick(language, words) {
934
+ return words[of(language)];
935
+ }
936
+ TaLanguageUtil2.pick = pick;
937
+ function say(words) {
938
+ return words[server()];
939
+ }
940
+ TaLanguageUtil2.say = say;
941
+ function chinese(language) {
942
+ return of(language).startsWith("zh");
943
+ }
944
+ TaLanguageUtil2.chinese = chinese;
945
+ function cjk(language) {
946
+ return of(language) !== "en-US";
947
+ }
948
+ TaLanguageUtil2.cjk = cjk;
949
+ function list(language, items2) {
950
+ return items2.join(cjk(language) ? "、" : ", ");
951
+ }
952
+ TaLanguageUtil2.list = list;
953
+ })(TaLanguageUtil || (TaLanguageUtil = {}));
954
+
955
+ // web-src/i18n.ts
956
+ var EN = {
957
+ status: { done: "Done", partial: "Partly done", failed: "Failed", blocked: "Needs you", info: "" },
958
+ before: "Before",
959
+ after: "After",
960
+ recommended: "Recommended",
961
+ choose: "Choose",
962
+ chosen: "Chosen",
963
+ pick: "I choose: {label}",
964
+ several: "Choose any",
965
+ submit: "Send",
966
+ listJoin: ", ",
967
+ details: "Details",
968
+ hide: "Hide",
969
+ more: "{count} more",
970
+ files: "{count} files",
971
+ writing: "Drawing the summary…",
972
+ spokenChoices: "You can choose: {labels}.",
973
+ spokenRecommended: "I suggest {label}.",
974
+ spokenFailed: "{text}: failed.",
975
+ spokenJoin: ", "
976
+ };
977
+ var ZH = {
978
+ status: { done: "已完成", partial: "部分完成", failed: "失败", blocked: "需要你", info: "" },
979
+ before: "之前",
980
+ after: "之后",
981
+ recommended: "推荐",
982
+ choose: "选这个",
983
+ chosen: "已选",
984
+ pick: "我选:{label}",
985
+ several: "可多选",
986
+ submit: "发送",
987
+ listJoin: "、",
988
+ details: "详情",
989
+ hide: "收起",
990
+ more: "还有 {count} 项",
991
+ files: "{count} 个文件",
992
+ writing: "正在整理摘要…",
993
+ spokenChoices: "可以选:{labels}。",
994
+ spokenRecommended: "推荐{label}。",
995
+ spokenFailed: "{text}失败了。",
996
+ spokenJoin: "、"
997
+ };
998
+ var ZH_TW = {
999
+ status: { done: "已完成", partial: "部分完成", failed: "失敗", blocked: "需要你", info: "" },
1000
+ before: "之前",
1001
+ after: "之後",
1002
+ recommended: "推薦",
1003
+ choose: "選這個",
1004
+ chosen: "已選",
1005
+ pick: "我選:{label}",
1006
+ several: "可多選",
1007
+ submit: "送出",
1008
+ listJoin: "、",
1009
+ details: "詳情",
1010
+ hide: "收起",
1011
+ more: "還有 {count} 項",
1012
+ files: "{count} 個檔案",
1013
+ writing: "正在整理摘要…",
1014
+ spokenChoices: "可以選:{labels}。",
1015
+ spokenRecommended: "推薦{label}。",
1016
+ spokenFailed: "{text}失敗了。",
1017
+ spokenJoin: "、"
1018
+ };
1019
+ var JA = {
1020
+ status: { done: "完了", partial: "部分完了", failed: "失敗", blocked: "要対応", info: "" },
1021
+ before: "前",
1022
+ after: "後",
1023
+ recommended: "オススメ",
1024
+ choose: "これを選ぶ",
1025
+ chosen: "選択済み",
1026
+ pick: "私が選んだ:{label}",
1027
+ several: "複数選択可",
1028
+ submit: "送信",
1029
+ listJoin: "、",
1030
+ details: "詳細",
1031
+ hide: "隠す",
1032
+ more: "ほか {count} 件",
1033
+ files: "{count} 個のファイル",
1034
+ writing: "サマリーを作成中…",
1035
+ spokenChoices: "選択肢:{labels}。",
1036
+ spokenRecommended: "オススメは{label}です。",
1037
+ spokenFailed: "{text}は失敗しました。",
1038
+ spokenJoin: "、"
1039
+ };
1040
+ var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
1041
+ var GlanceWords;
1042
+ ((GlanceWords) => {
1043
+ function of(language) {
1044
+ return TaLanguageUtil.pick(language, WORDS);
1045
+ }
1046
+ GlanceWords.of = of;
1047
+ function picked(answer2, labels) {
1048
+ const said = answer2.trim();
1049
+ return labels.find((label) => said === label || said === format(EN.pick, { label }) || said === format(ZH.pick, { label }));
1050
+ }
1051
+ GlanceWords.picked = picked;
1052
+ const PICKS = Object.values(WORDS).map((words) => words.pick.replace("{label}", ""));
1053
+ function answer(words, picks) {
1054
+ if (picks.length === 1) {
1055
+ return format(words.pick, { label: picks[0].labels.join(words.listJoin) });
1028
1056
  }
1029
- default: {
1030
- const list = items(value?.items, point);
1031
- if (list.length) {
1032
- return { type: "notes", items: list };
1033
- }
1034
- const markdown = text(value?.markdown, MARKDOWN);
1035
- if (!markdown) {
1036
- return;
1057
+ return [format(words.pick, { label: "" }).trim(), ...picks.map((pick) => `${pick.key} ${pick.labels.join(words.listJoin)}`)].join(`
1058
+ `);
1059
+ }
1060
+ GlanceWords.answer = answer;
1061
+ function chosen(answer2, labels, key) {
1062
+ const lines = answer2.trim().split(`
1063
+ `).map((line) => line.trim());
1064
+ let said;
1065
+ if (key !== undefined) {
1066
+ const line = lines.find((each) => each.startsWith(key));
1067
+ if (line === undefined) {
1068
+ return [];
1037
1069
  }
1038
- return markdown.length > TEXT || markdown.includes(`
1039
- `) ? { type: "details", markdown } : { type: "notes", items: [{ text: markdown, tone: "info" }] };
1070
+ said = line.slice(key.length).trim();
1071
+ } else {
1072
+ said = lines.join(" ");
1073
+ const prefix = PICKS.find((each) => each && said.startsWith(each));
1074
+ said = (prefix ? said.slice(prefix.length) : said).trim();
1040
1075
  }
1076
+ const parts = said.split(/\s*(?:、|,\s|,)\s*/);
1077
+ return labels.filter((label) => said === label || parts.includes(label));
1041
1078
  }
1042
- }
1043
- function loose(card) {
1044
- const out = [];
1045
- for (const [key, entries] of Object.entries(card)) {
1046
- const type = key === "files" ? "changes" : key;
1047
- if (Array.isArray(entries) && LISTS.includes(type)) {
1048
- out.push({ type, items: entries, ...type === "options" ? { question: card.question } : {} });
1049
- }
1079
+ GlanceWords.chosen = chosen;
1080
+ function format(text2, values) {
1081
+ return text2.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
1050
1082
  }
1051
- const words = text(card.summary) ?? text(card.text) ?? text(card.message);
1052
- return out.length || !words ? out : [{ type: "notes", items: [words] }];
1053
- }
1054
- var LISTS = ["stats", "changes", "steps", "flow", "options", "notes", "next"];
1055
- var PLACE = { stats: -1, notes: 1, next: 2, details: 3 };
1056
- function place(block2) {
1057
- return block2.fold !== undefined ? 3 : PLACE[block2.type] ?? 0;
1058
- }
1059
- function placed(blocks) {
1060
- return blocks.map((block2, index) => ({ block: block2, index })).sort((a, b) => place(a.block) - place(b.block) || a.index - b.index).map((entry) => entry.block);
1083
+ GlanceWords.format = format;
1084
+ })(GlanceWords ||= {});
1085
+
1086
+ // web-src/card-options.tsx
1087
+ function formKey(ask, index) {
1088
+ return ask.question ? plain(ask.question) : `${index + 1}.`;
1061
1089
  }
1062
- var GlanceSpec;
1063
- ((GlanceSpec) => {
1064
- function read(value, partial = false, labels = LABELS) {
1065
- const card = Array.isArray(value) ? { blocks: value } : object(value);
1066
- if (!card) {
1067
- return;
1068
- }
1069
- const status = oneOf(card.status, STATUSES);
1070
- const title = text(card.title);
1071
- const written = Array.isArray(card.blocks) ? card.blocks : object(card.blocks) ? [card.blocks] : loose(card);
1072
- const blocks = placed(items(written, (entry) => block(entry, partial, labels)).slice(0, BLOCKS)).map((made) => made.type === "stats" && !made.checks && status && !QUIET.includes(status) && passed(made.items, 1) ? { ...made, checks: true } : made);
1073
- if (!blocks.length && !title) {
1090
+ function glanceOptions(pi, { Reply, Answer, Text, Icon, has }) {
1091
+ const FormOf = React.createContext(undefined);
1092
+ function useForm(card, words, send, answer) {
1093
+ const asks = React.useMemo(() => card?.blocks.filter((block2) => block2.type === "options") ?? [], [card]);
1094
+ const [tapped, setTapped] = React.useState({});
1095
+ const [sent, setSent] = React.useState(false);
1096
+ if (!(asks.length > 1 || asks.some((ask) => ask.multi))) {
1074
1097
  return;
1075
1098
  }
1076
- return { blocks, ...status ? { status } : {}, ...title ? { title } : {} };
1099
+ const done = sent || answer !== undefined;
1100
+ const picks = asks.map((ask, index) => {
1101
+ const labels = ask.items.map((item) => item.label);
1102
+ if (!sent && answer !== undefined) {
1103
+ return GlanceWords.chosen(answer, labels, asks.length > 1 ? formKey(ask, index) : undefined);
1104
+ }
1105
+ const picked = tapped[index] ?? ask.items.filter((item) => item.recommended).map((item) => item.label);
1106
+ return labels.filter((label) => picked.includes(label)).slice(0, ask.multi ? undefined : 1);
1107
+ });
1108
+ return {
1109
+ asks,
1110
+ picks,
1111
+ done,
1112
+ toggle(index, label) {
1113
+ const now = picks[index];
1114
+ const next = asks[index].multi ? now.includes(label) ? now.filter((each) => each !== label) : [...now, label] : [label];
1115
+ setTapped({ ...tapped, [index]: next });
1116
+ },
1117
+ submit() {
1118
+ if (!send || done || picks.some((each) => !each.length)) {
1119
+ return;
1120
+ }
1121
+ setSent(true);
1122
+ const text2 = GlanceWords.answer(words, asks.map((ask, index) => ({ key: formKey(ask, index), labels: picks[index] })));
1123
+ send(text2).catch((error) => {
1124
+ setSent(false);
1125
+ pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
1126
+ });
1127
+ }
1128
+ };
1129
+ }
1130
+ function Options({ block: block2, words, closed }) {
1131
+ const [tapped, setChosen] = React.useState();
1132
+ const send = React.useContext(Reply);
1133
+ const form = React.useContext(FormOf);
1134
+ const answer = React.useContext(Answer);
1135
+ const ask = form ? form.asks.indexOf(block2) : -1;
1136
+ const inForm = !!form && ask >= 0;
1137
+ const said = answer.text === undefined ? undefined : GlanceWords.picked(answer.text, block2.items.map((item) => item.label));
1138
+ const chosen = inForm ? form.picks[ask] : [tapped ?? said].filter((label) => label !== undefined);
1139
+ const done = inForm ? form.done : chosen.length > 0 || answer.text !== undefined;
1140
+ const pending = answer.known && closed && !done && (!inForm || ask === 0);
1141
+ const choose = (label) => {
1142
+ if (!send) {
1143
+ return;
1144
+ }
1145
+ if (inForm) {
1146
+ form.toggle(ask, label);
1147
+ return;
1148
+ }
1149
+ setChosen(label);
1150
+ send(GlanceWords.format(words.pick, { label })).catch((error) => {
1151
+ setChosen(undefined);
1152
+ pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
1153
+ });
1154
+ };
1155
+ return /* @__PURE__ */ React.createElement("div", {
1156
+ className: "tag-options-block",
1157
+ "data-pending": pending || undefined
1158
+ }, (block2.question || block2.multi) && /* @__PURE__ */ React.createElement("div", {
1159
+ className: "tag-question"
1160
+ }, block2.question && /* @__PURE__ */ React.createElement(Text, {
1161
+ text: block2.question
1162
+ }), block2.multi && /* @__PURE__ */ React.createElement("span", {
1163
+ className: "tag-several"
1164
+ }, words.several)), inForm ? /* @__PURE__ */ React.createElement("div", {
1165
+ className: "tag-picks"
1166
+ }, block2.items.map((item, index) => {
1167
+ const picked = chosen.includes(item.label);
1168
+ return /* @__PURE__ */ React.createElement("button", {
1169
+ key: index,
1170
+ type: "button",
1171
+ className: "tag-pick",
1172
+ "aria-pressed": picked,
1173
+ "data-multi": block2.multi || undefined,
1174
+ "data-other": done && !picked || undefined,
1175
+ disabled: !closed || !send || done,
1176
+ onClick: () => choose(item.label)
1177
+ }, /* @__PURE__ */ React.createElement("span", {
1178
+ className: "tag-pick-mark"
1179
+ }, picked && /* @__PURE__ */ React.createElement(Icon, {
1180
+ name: "Check",
1181
+ size: 11
1182
+ })), /* @__PURE__ */ React.createElement("span", {
1183
+ className: "tag-option-main"
1184
+ }, /* @__PURE__ */ React.createElement("span", {
1185
+ className: "tag-option-head"
1186
+ }, has(item.icon) && /* @__PURE__ */ React.createElement("span", {
1187
+ className: "tag-item-icon"
1188
+ }, /* @__PURE__ */ React.createElement(Icon, {
1189
+ name: item.icon,
1190
+ size: 14
1191
+ })), /* @__PURE__ */ React.createElement("span", {
1192
+ className: "tag-option-label"
1193
+ }, /* @__PURE__ */ React.createElement(Text, {
1194
+ text: item.label
1195
+ })), item.recommended && /* @__PURE__ */ React.createElement("span", {
1196
+ className: "tag-badge"
1197
+ }, words.recommended)), item.detail && /* @__PURE__ */ React.createElement("span", {
1198
+ className: "tag-option-detail"
1199
+ }, /* @__PURE__ */ React.createElement(Text, {
1200
+ text: item.detail
1201
+ }))));
1202
+ })) : /* @__PURE__ */ React.createElement("div", {
1203
+ className: "tag-options"
1204
+ }, block2.items.map((item, index) => {
1205
+ const picked = chosen.includes(item.label);
1206
+ return /* @__PURE__ */ React.createElement("div", {
1207
+ key: index,
1208
+ className: "tag-option",
1209
+ "data-recommended": item.recommended || undefined,
1210
+ "data-chosen": picked || undefined,
1211
+ "data-other": done && !picked || undefined
1212
+ }, /* @__PURE__ */ React.createElement("div", {
1213
+ className: "tag-option-main"
1214
+ }, /* @__PURE__ */ React.createElement("div", {
1215
+ className: "tag-option-head"
1216
+ }, has(item.icon) && /* @__PURE__ */ React.createElement("span", {
1217
+ className: "tag-item-icon"
1218
+ }, /* @__PURE__ */ React.createElement(Icon, {
1219
+ name: item.icon,
1220
+ size: 14
1221
+ })), /* @__PURE__ */ React.createElement("span", {
1222
+ className: "tag-option-label"
1223
+ }, /* @__PURE__ */ React.createElement(Text, {
1224
+ text: item.label
1225
+ })), item.recommended && /* @__PURE__ */ React.createElement("span", {
1226
+ className: "tag-badge"
1227
+ }, words.recommended)), item.detail && /* @__PURE__ */ React.createElement("div", {
1228
+ className: "tag-option-detail"
1229
+ }, /* @__PURE__ */ React.createElement(Text, {
1230
+ text: item.detail
1231
+ })), (item.pros.length > 0 || item.cons.length > 0) && /* @__PURE__ */ React.createElement("div", {
1232
+ className: "tag-points"
1233
+ }, item.pros.map((point2, at) => /* @__PURE__ */ React.createElement("span", {
1234
+ key: `p${at}`,
1235
+ "data-tone": "good"
1236
+ }, /* @__PURE__ */ React.createElement(Text, {
1237
+ text: point2
1238
+ }))), item.cons.map((point2, at) => /* @__PURE__ */ React.createElement("span", {
1239
+ key: `c${at}`,
1240
+ "data-tone": "bad"
1241
+ }, /* @__PURE__ */ React.createElement(Text, {
1242
+ text: point2
1243
+ }))))), /* @__PURE__ */ React.createElement("button", {
1244
+ type: "button",
1245
+ className: `ta-button tag-choose${item.recommended && !done && !inForm ? " ta-primary" : ""}`,
1246
+ "aria-pressed": inForm ? picked : undefined,
1247
+ disabled: !closed || !send || done,
1248
+ onClick: () => choose(item.label)
1249
+ }, picked && /* @__PURE__ */ React.createElement(Icon, {
1250
+ name: "Check",
1251
+ size: 13
1252
+ }), /* @__PURE__ */ React.createElement("span", null, picked ? words.chosen : words.choose)));
1253
+ })), inForm && ask === form.asks.length - 1 && !form.done && /* @__PURE__ */ React.createElement("div", {
1254
+ className: "tag-submit"
1255
+ }, /* @__PURE__ */ React.createElement("button", {
1256
+ type: "button",
1257
+ className: "ta-button ta-primary",
1258
+ disabled: !closed || !send || form.picks.some((each) => !each.length),
1259
+ onClick: () => form.submit()
1260
+ }, /* @__PURE__ */ React.createElement(Icon, {
1261
+ name: "Send",
1262
+ size: 13
1263
+ }), /* @__PURE__ */ React.createElement("span", null, words.submit))));
1077
1264
  }
1078
- GlanceSpec.read = read;
1079
- })(GlanceSpec ||= {});
1265
+ return { Options, FormOf, useForm };
1266
+ }
1080
1267
 
1081
1268
  // web-src/card.tsx
1082
1269
  var MARKS = /[*_`[\]$\\]/;
@@ -1410,13 +1597,14 @@ function glanceCard(pi) {
1410
1597
  text: column
1411
1598
  }))))), /* @__PURE__ */ React.createElement("tbody", null, block2.rows.slice(0, more.limit).map((row, index) => /* @__PURE__ */ React.createElement("tr", {
1412
1599
  key: index
1413
- }, row.map((cell, column) => /* @__PURE__ */ React.createElement("td", {
1600
+ }, row.map((cell2, column) => /* @__PURE__ */ React.createElement("td", {
1414
1601
  key: column,
1415
1602
  "data-label": plain(block2.columns[column] ?? "") || undefined
1416
1603
  }, /* @__PURE__ */ React.createElement(Clamp, {
1417
- text: cell
1604
+ text: cell2
1418
1605
  })))))))), more.toggle);
1419
1606
  }
1607
+ const { Board } = glanceBoard({ Text });
1420
1608
  const { Options, FormOf, useForm } = glanceOptions(pi, { Reply, Answer, Text, Icon, has });
1421
1609
  const NOTE_ICON = { risk: "CircleAlert", info: "Info", todo: "CircleArrowRight" };
1422
1610
  function Notes({ block: block2 }) {
@@ -1517,6 +1705,10 @@ ${block2.mermaid}
1517
1705
  block: block2,
1518
1706
  words
1519
1707
  });
1708
+ case "board":
1709
+ return /* @__PURE__ */ React.createElement(Board, {
1710
+ block: block2
1711
+ });
1520
1712
  case "options":
1521
1713
  return /* @__PURE__ */ React.createElement(Options, {
1522
1714
  block: block2,
@@ -1628,10 +1820,6 @@ ${code}
1628
1820
  };
1629
1821
  }
1630
1822
 
1631
- // web-src/glance-protocol.ts
1632
- var LANGUAGE = "ta-glance";
1633
- var ALIASES = ["glance", "glance-choice", "glance-card", "ta_glance", "taglance", "ta-glance-card", "ta-card"];
1634
-
1635
1823
  // web-src/glance-speech.ts
1636
1824
  var GlanceSpeech;
1637
1825
  ((GlanceSpeech) => {
@@ -1894,6 +2082,29 @@ var STYLE = `
1894
2082
  .tag-share-value { color: var(--ta-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
1895
2083
  .tag-share-key > b { min-width: 2.6em; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
1896
2084
 
2085
+ /* A board: a chart in a grid (nine palaces, twelve houses round a middle, four pillars), hairlines between its cells,
2086
+ * every row as tall as its tallest; a name on top, a tag in its corner, short lines under; the cell that matters in a
2087
+ * tint of the accent; a middle that takes several cells centred. One column: each cell a row, its name beside its lines */
2088
+ .tag-board { display: grid; grid-auto-rows: minmax(min-content, 1fr); gap: 1px; border: 1px solid var(--ta-border); border-radius: 8px; overflow: hidden; background: var(--ta-border); font-size: var(--tag-small); line-height: 1.4; }
2089
+ .tag-cell { --tag-tone: var(--ta-text); display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 7px 9px; background: var(--ta-card); }
2090
+ @container tag-card (max-width: 400px) { .tag-cell { padding: 6px 7px; } }
2091
+ .tag-cell[data-tone='good'] { --tag-tone: var(--ta-green); }
2092
+ .tag-cell[data-tone='bad'] { --tag-tone: var(--ta-red); }
2093
+ .tag-cell[data-tone='warn'] { --tag-tone: var(--ta-yellow); }
2094
+ .tag-cell[data-mark] { background: color-mix(in srgb, var(--ta-accent) 9%, var(--ta-card)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ta-accent) 45%, transparent); }
2095
+ .tag-cell[data-wide] { justify-content: center; align-items: center; text-align: center; background: var(--ta-raised); }
2096
+ /* Name and tag share a line while they fit; in a narrow cell the tag goes under the name rather than break it */
2097
+ .tag-cell-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; min-width: 0; }
2098
+ .tag-cell[data-wide] > .tag-cell-head { justify-content: center; }
2099
+ .tag-cell-title { flex: 1 1 auto; min-width: 0; white-space: nowrap; font-weight: 600; font-size: var(--tag-text); line-height: var(--tag-lh); color: var(--tag-tone); }
2100
+ .tag-cell[data-wide] .tag-cell-title { flex: none; }
2101
+ .tag-cell-corner { flex: none; padding: 0 5px; border-radius: 4px; font-size: var(--tag-tiny); line-height: 1.5; color: var(--ta-secondary); background: var(--ta-raised); white-space: nowrap; }
2102
+ .tag-cell[data-wide] .tag-cell-corner { background: var(--ta-card); }
2103
+ .tag-cell-lines { display: flex; flex-direction: column; color: var(--ta-body); }
2104
+ .tag-board[data-cols='1'] .tag-cell { flex-direction: row; align-items: baseline; gap: 12px; }
2105
+ .tag-board[data-cols='1'] .tag-cell-head { flex: 0 0 6.5em; }
2106
+ .tag-board[data-cols='1'] .tag-cell-lines { flex: 1; flex-direction: row; flex-wrap: wrap; gap: 2px 12px; }
2107
+
1897
2108
  /* A path: nodes and arrows; an arrow keeps to the node after it, so that no line ends with one */
1898
2109
  .tag-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; }
1899
2110
  .tag-flow-step { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; }