@celljs/ta-dash 0.0.0-stage → 4.42.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 ADDED
@@ -0,0 +1,1106 @@
1
+ // web-src/dash-protocol.ts
2
+ var LANGUAGE = "ta-dash";
3
+ var DashKeys;
4
+ ((DashKeys) => {
5
+ DashKeys.ALLOWED = "allowed";
6
+ DashKeys.RESULTS = "results";
7
+ })(DashKeys ||= {});
8
+ var DashLimits;
9
+ ((DashLimits) => {
10
+ DashLimits.SOURCES = 12;
11
+ DashLimits.TILES = 16;
12
+ DashLimits.RUN = 4000;
13
+ DashLimits.ROWS = 500;
14
+ DashLimits.BYTES = 48 * 1024;
15
+ DashLimits.TIMEOUT_MS = 60000;
16
+ DashLimits.OUTPUT = 4 * 1024 * 1024;
17
+ DashLimits.PARALLEL = 3;
18
+ DashLimits.RESULTS = 40;
19
+ DashLimits.APPROVED = 500;
20
+ DashLimits.REFRESH_MS = 15 * 60000;
21
+ DashLimits.MIN_REFRESH_MS = 60000;
22
+ })(DashLimits ||= {});
23
+
24
+ // web-src/dash-rows.ts
25
+ var ROW_KEYS = ["rows", "data", "results", "result", "items", "records", "values"];
26
+ function cell(value) {
27
+ if (value === null || value === undefined) {
28
+ return null;
29
+ }
30
+ if (typeof value === "number" || typeof value === "boolean") {
31
+ return Number.isFinite(value) || typeof value === "boolean" ? value : null;
32
+ }
33
+ if (typeof value === "string") {
34
+ return value.length > 500 ? value.slice(0, 500) : value;
35
+ }
36
+ const text = JSON.stringify(value);
37
+ return text.length > 500 ? text.slice(0, 500) : text;
38
+ }
39
+ function row(value) {
40
+ const source = value && typeof value === "object" && !Array.isArray(value) ? value : { value };
41
+ return Object.fromEntries(Object.entries(source).map(([key, entry]) => [key, cell(entry)]));
42
+ }
43
+ function fromJson(value) {
44
+ if (Array.isArray(value)) {
45
+ if (value.length > 1 && value.every(Array.isArray) && value[0].every((head) => typeof head === "string")) {
46
+ const [head, ...rest] = value;
47
+ return rest.map((entry) => Object.fromEntries(head.map((name, index) => [name, cell(entry[index])])));
48
+ }
49
+ return value.map(row);
50
+ }
51
+ if (value && typeof value === "object") {
52
+ const object = value;
53
+ const key = ROW_KEYS.find((name) => Array.isArray(object[name])) ?? Object.keys(object).find((name) => Array.isArray(object[name]) && object[name].some((entry) => entry && typeof entry === "object"));
54
+ return key ? fromJson(object[key]) : [row(object)];
55
+ }
56
+ return value === undefined ? undefined : [{ value: cell(value) }];
57
+ }
58
+ function split(line, delimiter) {
59
+ if (delimiter !== ",") {
60
+ return line.split(delimiter).map((entry) => entry.trim());
61
+ }
62
+ const cells = [];
63
+ let current = "";
64
+ let quoted = false;
65
+ for (let index = 0;index < line.length; index++) {
66
+ const char = line[index];
67
+ if (quoted) {
68
+ if (char === '"' && line[index + 1] === '"') {
69
+ current += '"';
70
+ index++;
71
+ } else if (char === '"') {
72
+ quoted = false;
73
+ } else {
74
+ current += char;
75
+ }
76
+ } else if (char === '"') {
77
+ quoted = true;
78
+ } else if (char === ",") {
79
+ cells.push(current.trim());
80
+ current = "";
81
+ } else {
82
+ current += char;
83
+ }
84
+ }
85
+ cells.push(current.trim());
86
+ return cells;
87
+ }
88
+ function typed(text) {
89
+ if (text === "" || /^null$/i.test(text)) {
90
+ return null;
91
+ }
92
+ const number = Number(text.replace(/,(?=\d{3}(\D|$))/g, ""));
93
+ return /^[-+]?[\d,]*\.?\d+(e[-+]?\d+)?$/i.test(text) && Number.isFinite(number) ? number : text;
94
+ }
95
+ function fromTable(text) {
96
+ const lines = text.split(/\r?\n/).filter((line) => line.trim() && !/^[-+|\s]+$/.test(line));
97
+ if (!lines.length) {
98
+ return [];
99
+ }
100
+ const first = lines[0];
101
+ const delimiter = first.includes("\t") ? "\t" : first.includes("|") ? "|" : first.includes(",") ? "," : first.includes(";") ? ";" : "\t";
102
+ const strip = (cells) => delimiter === "|" ? cells.filter((_, index, all) => !((index === 0 || index === all.length - 1) && all[index] === "")) : cells;
103
+ const head = strip(split(first, delimiter)).map((name, index) => name || `col${index + 1}`);
104
+ return lines.slice(1).map((line) => {
105
+ const cells = strip(split(line, delimiter));
106
+ return Object.fromEntries(head.map((name, index) => [name, typed(cells[index] ?? "")]));
107
+ });
108
+ }
109
+ var DashRows;
110
+ ((DashRows) => {
111
+ function parse(output) {
112
+ const text = output.trim();
113
+ let rows = [];
114
+ if (text) {
115
+ let json;
116
+ try {
117
+ json = fromJson(JSON.parse(text));
118
+ } catch {
119
+ const lines = text.split(/\r?\n/).filter((line) => line.trim());
120
+ try {
121
+ json = lines.length > 1 && lines.every((line) => line.trim().startsWith("{")) ? lines.map((line) => row(JSON.parse(line))) : undefined;
122
+ } catch {
123
+ json = undefined;
124
+ }
125
+ }
126
+ rows = json ?? (text.includes(`
127
+ `) ? fromTable(text) : [{ value: typed(text) }]);
128
+ }
129
+ return keep(rows);
130
+ }
131
+ DashRows.parse = parse;
132
+ function keep(rows) {
133
+ let cut = rows.length > DashLimits.ROWS;
134
+ let kept = rows.slice(0, DashLimits.ROWS);
135
+ while (kept.length > 1 && JSON.stringify(kept).length > DashLimits.BYTES) {
136
+ kept = kept.slice(0, Math.floor(kept.length * 0.7));
137
+ cut = true;
138
+ }
139
+ const columns = [];
140
+ for (const entry of kept) {
141
+ for (const key of Object.keys(entry)) {
142
+ if (!columns.includes(key)) {
143
+ columns.push(key);
144
+ }
145
+ }
146
+ }
147
+ return { columns, rows: kept, ...cut ? { cut } : {} };
148
+ }
149
+ DashRows.keep = keep;
150
+ function number(value) {
151
+ if (typeof value === "number") {
152
+ return Number.isFinite(value) ? value : undefined;
153
+ }
154
+ if (typeof value === "string" && value.trim()) {
155
+ const parsed = Number(value.replace(/,/g, ""));
156
+ return Number.isFinite(parsed) ? parsed : undefined;
157
+ }
158
+ return;
159
+ }
160
+ DashRows.number = number;
161
+ function firstNumeric(row2, columns) {
162
+ return row2 ? columns.find((column) => number(row2[column]) !== undefined) : undefined;
163
+ }
164
+ DashRows.firstNumeric = firstNumeric;
165
+ function format(value) {
166
+ return value.toLocaleString("en-US", { maximumFractionDigits: Math.abs(value) >= 100 ? 0 : 2 });
167
+ }
168
+ DashRows.format = format;
169
+ function show(value) {
170
+ if (value === null || value === undefined) {
171
+ return "";
172
+ }
173
+ return typeof value === "number" ? format(value) : String(value);
174
+ }
175
+ DashRows.show = show;
176
+ function thin(values, labels, max) {
177
+ if (values.length <= max) {
178
+ return { values, labels };
179
+ }
180
+ const size = values.length / max;
181
+ const out = [];
182
+ const names = [];
183
+ for (let index = 0;index < max; index++) {
184
+ const from = Math.floor(index * size);
185
+ const to = index === max - 1 ? values.length : Math.floor((index + 1) * size);
186
+ const part = values.slice(from, to);
187
+ out.push(index === max - 1 ? values[values.length - 1] : part.reduce((sum, value) => sum + value, 0) / part.length);
188
+ names.push(labels[to - 1] ?? "");
189
+ }
190
+ return { values: out.map((value) => Number(value.toFixed(4))), labels: names };
191
+ }
192
+ DashRows.thin = thin;
193
+ function tsv(result) {
194
+ const clean = (value) => value === null || value === undefined ? "" : String(value).replace(/[\t\r\n]+/g, " ");
195
+ return [result.columns.join("\t"), ...result.rows.map((entry) => result.columns.map((column) => clean(entry[column])).join("\t"))].join(`
196
+ `);
197
+ }
198
+ DashRows.tsv = tsv;
199
+ })(DashRows ||= {});
200
+
201
+ // web-src/dash-glance.ts
202
+ var POINTS = 24;
203
+ var BARS = 20;
204
+ var SHARES = 8;
205
+ var TABLE_ROWS = 40;
206
+ var TABLE_COLUMNS = 6;
207
+ var DashGlance;
208
+ ((DashGlance) => {
209
+ function stat(tile, result) {
210
+ const rows = result.rows;
211
+ const row2 = tile.row === "last" ? rows[rows.length - 1] : rows[0];
212
+ const field = tile.field ?? DashRows.firstNumeric(row2, result.columns);
213
+ const value = field ? DashRows.number(row2?.[field]) : undefined;
214
+ const unit = tile.unit ? ` ${tile.unit}` : "";
215
+ if (value === undefined) {
216
+ const said2 = field ? DashRows.show(row2?.[field]) : "";
217
+ return { value: said2 || "—" };
218
+ }
219
+ const shown = { value: `${DashRows.format(value)}${unit}`, raw: value };
220
+ const before = tile.compare ? DashRows.number(row2?.[tile.compare]) : undefined;
221
+ if (before !== undefined && before !== 0) {
222
+ const change = (value - before) / Math.abs(before) * 100;
223
+ shown.delta = `${change > 0 ? "+" : ""}${change.toFixed(Math.abs(change) >= 10 ? 0 : 1)}%`;
224
+ if (tile.better && change !== 0) {
225
+ shown.tone = tile.better === "higher" === change > 0 ? "good" : "bad";
226
+ }
227
+ }
228
+ if (tile.trend) {
229
+ const trend = rows.map((entry) => DashRows.number(entry[tile.trend])).filter((entry) => entry !== undefined);
230
+ if (trend.length >= 2) {
231
+ shown.trend = DashRows.thin(trend, trend.map(String), POINTS).values;
232
+ }
233
+ }
234
+ return shown;
235
+ }
236
+ DashGlance.stat = stat;
237
+ function block(tile, result) {
238
+ const rows = result.rows;
239
+ if (tile.type === "table") {
240
+ const columns = ((tile.columns?.length) ? tile.columns : result.columns).slice(0, TABLE_COLUMNS);
241
+ return rows.length && columns.length ? { type: "table", columns, rows: rows.slice(0, TABLE_ROWS).map((entry) => columns.map((column) => DashRows.show(entry[column]))) } : undefined;
242
+ }
243
+ const unit = tile.unit ? { unit: tile.unit } : {};
244
+ if (tile.type === "line") {
245
+ const labels = rows.map((entry) => DashRows.show(entry[tile.x]));
246
+ const series = tile.y.map((column) => {
247
+ const values = rows.map((entry) => DashRows.number(entry[column]) ?? 0);
248
+ const thinned = DashRows.thin(values, labels, POINTS);
249
+ return { label: column, values: thinned.values, labels: thinned.labels };
250
+ }).filter((line) => line.values.length);
251
+ return series.length ? {
252
+ type: "line",
253
+ ...unit,
254
+ ...tile.better ? { better: tile.better } : {},
255
+ labels: series[0].labels,
256
+ series: series.map(({ label, values }) => ({ label, values }))
257
+ } : undefined;
258
+ }
259
+ const items = rows.map((entry) => ({ label: DashRows.show(entry[tile.x]) || "—", value: DashRows.number(entry[tile.y[0]]) })).filter((item) => item.value !== undefined);
260
+ if (!items.length) {
261
+ return;
262
+ }
263
+ if (tile.type === "share") {
264
+ const sorted = [...items].sort((a, b) => b.value - a.value);
265
+ const head = sorted.slice(0, SHARES - 1);
266
+ const rest = sorted.slice(SHARES - 1).reduce((sum, item) => sum + item.value, 0);
267
+ return { type: "share", ...unit, items: rest > 0 && sorted.length > SHARES ? [...head, { label: "…", value: rest }] : sorted.slice(0, SHARES) };
268
+ }
269
+ return { type: "bars", ...unit, items: items.slice(0, BARS) };
270
+ }
271
+ DashGlance.block = block;
272
+ function markdown(block2) {
273
+ return `\`\`\`ta-glance
274
+ ${JSON.stringify({ status: "info", blocks: [block2] })}
275
+ \`\`\``;
276
+ }
277
+ DashGlance.markdown = markdown;
278
+ function said(tile, result) {
279
+ if (!result) {
280
+ return tile.label;
281
+ }
282
+ if (tile.type === "stat") {
283
+ return `${tile.label}: ${stat(tile, result).value}`;
284
+ }
285
+ const columns = tile.type === "table" ? tile.columns ?? result.columns : [tile.x, ...tile.y];
286
+ const lines = result.rows.slice(0, 12).map((entry) => columns.map((column) => DashRows.show(entry[column])).join(" | "));
287
+ return [`${tile.label} (${columns.join(" | ")}):`, ...lines, ...result.rows.length > 12 ? ["…"] : []].join(`
288
+ `);
289
+ }
290
+ DashGlance.said = said;
291
+ })(DashGlance ||= {});
292
+
293
+ // web-src/dash-spec.ts
294
+ function object(value) {
295
+ return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
296
+ }
297
+ function text(value, max = 200) {
298
+ if (typeof value === "number" && Number.isFinite(value)) {
299
+ return String(value);
300
+ }
301
+ return typeof value === "string" && value.trim() ? value.trim().slice(0, max) : undefined;
302
+ }
303
+ function names(value) {
304
+ const list = Array.isArray(value) ? value : value === undefined ? [] : [value];
305
+ return list.map((entry) => text(entry, 80)).filter((entry) => !!entry);
306
+ }
307
+ function refresh(value) {
308
+ if (value === "off" || value === false || value === 0) {
309
+ return 0;
310
+ }
311
+ const match = typeof value === "number" ? [String(value), String(value), "m"] : /^\s*(\d+(?:\.\d+)?)\s*([smhd]?)\s*$/i.exec(String(value ?? ""));
312
+ if (!match) {
313
+ return DashLimits.REFRESH_MS;
314
+ }
315
+ const unit = { s: 1000, m: 60000, h: 3600000, d: 86400000 }[(match[2] || "m").toLowerCase()];
316
+ return Math.max(DashLimits.MIN_REFRESH_MS, Math.round(Number(match[1]) * unit));
317
+ }
318
+ function tile(value, sources) {
319
+ const raw = object(value);
320
+ const source = text(raw?.source, 80) ?? (sources.length === 1 ? sources[0] : undefined);
321
+ if (!raw || !source || !sources.includes(source)) {
322
+ return;
323
+ }
324
+ const unit = text(raw.unit, 20);
325
+ const note = text(raw.note, 200);
326
+ const better = raw.better === "higher" || raw.better === "lower" ? raw.better : undefined;
327
+ const base = { label: text(raw.label, 80) ?? source, source, ...unit ? { unit } : {}, ...better ? { better } : {}, ...note ? { note } : {} };
328
+ switch (raw.type) {
329
+ case "stat": {
330
+ const field = text(raw.field, 80);
331
+ const compare = text(raw.compare, 80);
332
+ const trend = text(raw.trend, 80);
333
+ return {
334
+ ...base,
335
+ type: "stat",
336
+ row: raw.row === "last" ? "last" : "first",
337
+ ...field ? { field } : {},
338
+ ...compare ? { compare } : {},
339
+ ...trend ? { trend } : {}
340
+ };
341
+ }
342
+ case "line":
343
+ case "bars":
344
+ case "share": {
345
+ const x = text(raw.x, 80);
346
+ const y = names(raw.y);
347
+ return x && y.length ? { ...base, type: raw.type, x, y: raw.type === "line" ? y.slice(0, 4) : y.slice(0, 1) } : undefined;
348
+ }
349
+ case "table": {
350
+ const columns = names(raw.columns);
351
+ return { ...base, type: "table", ...columns.length ? { columns } : {} };
352
+ }
353
+ default:
354
+ return;
355
+ }
356
+ }
357
+ var DashSpec;
358
+ ((DashSpec) => {
359
+ function read(code) {
360
+ let value;
361
+ try {
362
+ value = JSON.parse(code);
363
+ } catch (error) {
364
+ throw new Error(error instanceof Error ? error.message : String(error));
365
+ }
366
+ const raw = object(value);
367
+ if (!raw) {
368
+ throw new Error("it is no JSON object");
369
+ }
370
+ const written = Array.isArray(raw.sources) ? raw.sources.map((entry) => [text(object(entry)?.name, 80), object(entry)?.run ?? object(entry)?.command]) : Object.entries(object(raw.sources) ?? {}).map(([name, entry]) => [text(name, 80), typeof entry === "string" ? entry : object(entry)?.run ?? object(entry)?.command]);
371
+ const sources = [];
372
+ for (const [name, run] of written) {
373
+ if (name && typeof run === "string" && run.trim() && run.length <= DashLimits.RUN && !sources.some((source) => source.name === name)) {
374
+ sources.push({ name, run: run.trim() });
375
+ }
376
+ }
377
+ if (!sources.length) {
378
+ throw new Error("it has no query (sources)");
379
+ }
380
+ const known = sources.slice(0, DashLimits.SOURCES);
381
+ const tiles = (Array.isArray(raw.tiles) ? raw.tiles : []).map((entry) => tile(entry, known.map((source) => source.name))).filter((entry) => !!entry).slice(0, DashLimits.TILES);
382
+ if (!tiles.length) {
383
+ throw new Error("it has no tile on one of its queries");
384
+ }
385
+ const title = text(raw.title, 80);
386
+ const cwd = text(raw.cwd, 1000);
387
+ return {
388
+ ...title ? { title } : {},
389
+ refresh: refresh(raw.refresh),
390
+ ...cwd ? { cwd } : {},
391
+ sources: known.filter((source) => tiles.some((entry) => entry.source === source.name)),
392
+ tiles
393
+ };
394
+ }
395
+ DashSpec.read = read;
396
+ })(DashSpec ||= {});
397
+
398
+ // ../ta-protocol/esm/common/language.js
399
+ var TaLanguageUtil;
400
+ (function(TaLanguageUtil2) {
401
+ TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
402
+ TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
403
+ function of(tag) {
404
+ const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
405
+ if (/^zh(\b|-)/.test(said)) {
406
+ return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
407
+ }
408
+ return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
409
+ }
410
+ TaLanguageUtil2.of = of;
411
+ function server(env = typeof process === "undefined" ? {} : process.env) {
412
+ return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
413
+ }
414
+ TaLanguageUtil2.server = server;
415
+ function pick(language, words) {
416
+ return words[of(language)];
417
+ }
418
+ TaLanguageUtil2.pick = pick;
419
+ function say(words) {
420
+ return words[server()];
421
+ }
422
+ TaLanguageUtil2.say = say;
423
+ function chinese(language) {
424
+ return of(language).startsWith("zh");
425
+ }
426
+ TaLanguageUtil2.chinese = chinese;
427
+ function cjk(language) {
428
+ return of(language) !== "en-US";
429
+ }
430
+ TaLanguageUtil2.cjk = cjk;
431
+ function list(language, items) {
432
+ return items.join(cjk(language) ? "、" : ", ");
433
+ }
434
+ TaLanguageUtil2.list = list;
435
+ })(TaLanguageUtil || (TaLanguageUtil = {}));
436
+
437
+ // web-src/i18n.ts
438
+ var EN = {
439
+ making: "Building the dashboard…",
440
+ failed: "This dashboard cannot be shown: {reason}",
441
+ refresh: "Refresh",
442
+ loading: "Fetching the numbers…",
443
+ updated: "Updated {ago}",
444
+ every: "every {time}",
445
+ byHand: "refreshed by hand",
446
+ now: "just now",
447
+ minutes: "{n} min ago",
448
+ hours: "{n} h ago",
449
+ days: "{n} d ago",
450
+ askTitle: "This dashboard runs {count} commands on your computer to get its numbers",
451
+ askHint: "Run them only if they just read data. Once allowed, it refreshes by itself while you look at it.",
452
+ allow: "Allow and run",
453
+ others: "Only the owner of this computer refreshes it: these are the numbers of {ago}.",
454
+ remote: "Its directory is on another machine: dashboards run only on this computer for now.",
455
+ offline: "Cannot reach your computer: its numbers come once it is back.",
456
+ query: "Query",
457
+ rows: "{count} rows",
458
+ cut: "first {count} rows kept",
459
+ took: "took {time}",
460
+ copyQuery: "Copy query",
461
+ copyData: "Copy data",
462
+ copied: "Copied",
463
+ explain: "Ask Ta",
464
+ explainText: `Explain this number of "{title}", and what is behind it:
465
+ {said}`,
466
+ noRows: "The query gave no rows.",
467
+ noValue: "No number in its rows",
468
+ error: "The query failed: {reason}",
469
+ toMotion: "Make it an animated explainer",
470
+ toMotionText: `Make the dashboard "{title}" a 30-second animated explainer with its numbers now:
471
+ {said}`,
472
+ untitled: "Dashboard"
473
+ };
474
+ var ZH = {
475
+ making: "正在搭看板…",
476
+ failed: "这个看板显示不出来:{reason}",
477
+ refresh: "刷新",
478
+ loading: "正在取数…",
479
+ updated: "{ago}更新",
480
+ every: "每 {time}",
481
+ byHand: "手动刷新",
482
+ now: "刚刚",
483
+ minutes: "{n} 分钟前",
484
+ hours: "{n} 小时前",
485
+ days: "{n} 天前",
486
+ askTitle: "这个看板要在你的电脑上运行 {count} 条命令来取数",
487
+ askHint: "确认它们只是读取数据再运行。允许后,你看着它时会自己按时刷新。",
488
+ allow: "允许并运行",
489
+ others: "只有这台电脑的主人能刷新,下面是{ago}的数据。",
490
+ remote: "它的目录在另一台机器上,看板暂时只在这台电脑上运行。",
491
+ offline: "连不上你的电脑,等它回来再取数。",
492
+ query: "查询",
493
+ rows: "{count} 行",
494
+ cut: "只保留了前 {count} 行",
495
+ took: "用时 {time}",
496
+ copyQuery: "复制查询",
497
+ copyData: "复制数据",
498
+ copied: "已复制",
499
+ explain: "问 Ta",
500
+ explainText: `解释一下「{title}」里的这个数,以及它背后的原因:
501
+ {said}`,
502
+ noRows: "查询没有返回数据。",
503
+ noValue: "数据里没有数字",
504
+ error: "查询失败:{reason}",
505
+ toMotion: "做成动画讲解",
506
+ toMotionText: `把看板「{title}」做成 30 秒的动画讲解,用现在的这些数字:
507
+ {said}`,
508
+ untitled: "看板"
509
+ };
510
+ var ZH_TW = {
511
+ making: "正在搭看板…",
512
+ failed: "這個看板顯示不出來:{reason}",
513
+ refresh: "重新整理",
514
+ loading: "正在取數…",
515
+ updated: "{ago}更新",
516
+ every: "每 {time}",
517
+ byHand: "手動重新整理",
518
+ now: "剛剛",
519
+ minutes: "{n} 分鐘前",
520
+ hours: "{n} 小時前",
521
+ days: "{n} 天前",
522
+ askTitle: "這個看板要在你的電腦上執行 {count} 條命令來取數",
523
+ askHint: "確認它們只是讀取資料再執行。允許後,你看著它時會自己按時重新整理。",
524
+ allow: "允許並執行",
525
+ others: "只有這台電腦的主人能重新整理,下面是{ago}的資料。",
526
+ remote: "它的目錄在另一台機器上,看板暫時只在這台電腦上執行。",
527
+ offline: "連不上你的電腦,等它回來再取數。",
528
+ query: "查詢",
529
+ rows: "{count} 列",
530
+ cut: "只保留了前 {count} 列",
531
+ took: "用時 {time}",
532
+ copyQuery: "複製查詢",
533
+ copyData: "複製資料",
534
+ copied: "已複製",
535
+ explain: "問 Ta",
536
+ explainText: `解釋一下「{title}」裡的這個數,以及它背後的原因:
537
+ {said}`,
538
+ noRows: "查詢沒有回傳資料。",
539
+ noValue: "資料裡沒有數字",
540
+ error: "查詢失敗:{reason}",
541
+ toMotion: "做成動畫講解",
542
+ toMotionText: `把看板「{title}」做成 30 秒的動畫講解,用現在的這些數字:
543
+ {said}`,
544
+ untitled: "看板"
545
+ };
546
+ var JA = {
547
+ making: "ダッシュボードを作成中…",
548
+ failed: "このダッシュボードは表示できません:{reason}",
549
+ refresh: "更新",
550
+ loading: "数値を取得中…",
551
+ updated: "{ago}に更新",
552
+ every: "{time}ごと",
553
+ byHand: "手動で更新",
554
+ now: "たった今",
555
+ minutes: "{n} 分前",
556
+ hours: "{n} 時間前",
557
+ days: "{n} 日前",
558
+ askTitle: "このダッシュボードは数値を取るため、あなたのパソコンで {count} 個のコマンドを実行します",
559
+ askHint: "データを読むだけのコマンドか確かめてから実行してください。許可すると、見ている間は自動で更新されます。",
560
+ allow: "許可して実行",
561
+ others: "更新できるのはこのパソコンの持ち主だけです。以下は{ago}の数値です。",
562
+ remote: "ディレクトリが別のマシンにあります。ダッシュボードは今のところこのパソコンでだけ動きます。",
563
+ offline: "パソコンにつながりません。戻ったら数値を取得します。",
564
+ query: "クエリ",
565
+ rows: "{count} 行",
566
+ cut: "先頭 {count} 行のみ保持",
567
+ took: "所要 {time}",
568
+ copyQuery: "クエリをコピー",
569
+ copyData: "データをコピー",
570
+ copied: "コピーしました",
571
+ explain: "Ta に聞く",
572
+ explainText: `「{title}」のこの数値と、その背景を説明してください:
573
+ {said}`,
574
+ noRows: "クエリは行を返しませんでした。",
575
+ noValue: "行に数値がありません",
576
+ error: "クエリが失敗しました:{reason}",
577
+ toMotion: "アニメーション解説にする",
578
+ toMotionText: `ダッシュボード「{title}」を、今の数値で 30 秒のアニメーション解説にしてください:
579
+ {said}`,
580
+ untitled: "ダッシュボード"
581
+ };
582
+ var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
583
+ var DashWords;
584
+ ((DashWords) => {
585
+ function of(language) {
586
+ return TaLanguageUtil.pick(language, WORDS);
587
+ }
588
+ DashWords.of = of;
589
+ function fill(text2, values) {
590
+ return text2.replace(/\{(\w+)\}/g, (all, name) => (name in values) ? String(values[name]) : all);
591
+ }
592
+ DashWords.fill = fill;
593
+ function ago(words, at, now = Date.now()) {
594
+ const minutes = Math.floor((now - at) / 60000);
595
+ if (minutes < 1) {
596
+ return words.now;
597
+ }
598
+ if (minutes < 60) {
599
+ return fill(words.minutes, { n: minutes });
600
+ }
601
+ const hours = Math.floor(minutes / 60);
602
+ return hours < 24 ? fill(words.hours, { n: hours }) : fill(words.days, { n: Math.floor(hours / 24) });
603
+ }
604
+ DashWords.ago = ago;
605
+ function span(ms) {
606
+ if (ms < 1000) {
607
+ return `${Math.max(1, Math.round(ms))} ms`;
608
+ }
609
+ if (ms < 60000) {
610
+ return `${Number((ms / 1000).toFixed(ms < 1e4 ? 1 : 0))} s`;
611
+ }
612
+ if (ms < 3600000) {
613
+ return `${Math.round(ms / 60000)} min`;
614
+ }
615
+ return ms < 86400000 ? `${Number((ms / 3600000).toFixed(1))} h` : `${Number((ms / 86400000).toFixed(1))} d`;
616
+ }
617
+ DashWords.span = span;
618
+ })(DashWords ||= {});
619
+
620
+ // web-src/react.ts
621
+ var React;
622
+ function bind(react) {
623
+ React = react;
624
+ }
625
+
626
+ // web-src/dash-view.tsx
627
+ var TICK_MS = 30000;
628
+ async function copy(text2) {
629
+ try {
630
+ await navigator.clipboard.writeText(text2);
631
+ return true;
632
+ } catch {
633
+ return false;
634
+ }
635
+ }
636
+ function dashView(pi) {
637
+ const Markdown = pi.ui.Markdown;
638
+ const useBusy = pi.ui.useBusy ?? (() => [false, async (action) => await action()]);
639
+ const icons = pi.ui.icons;
640
+ function Stat({ tile: tile2, result, words }) {
641
+ const shown = DashGlance.stat(tile2, result);
642
+ const trend = shown.trend;
643
+ let line = "";
644
+ if (trend && trend.length > 1) {
645
+ const min = Math.min(...trend);
646
+ const span = Math.max(...trend) - min || 1;
647
+ line = trend.map((value, index) => `${(index / (trend.length - 1) * 100).toFixed(1)},${(28 - (value - min) / span * 26).toFixed(1)}`).join(" ");
648
+ }
649
+ return /* @__PURE__ */ React.createElement("div", {
650
+ className: "tdash-stat"
651
+ }, /* @__PURE__ */ React.createElement("div", {
652
+ className: "tdash-value",
653
+ title: shown.value === "—" ? words.noValue : undefined
654
+ }, shown.value), shown.delta && /* @__PURE__ */ React.createElement("div", {
655
+ className: "tdash-delta",
656
+ "data-tone": shown.tone
657
+ }, shown.delta), line && /* @__PURE__ */ React.createElement("svg", {
658
+ className: "tdash-spark",
659
+ viewBox: "0 0 100 30",
660
+ preserveAspectRatio: "none",
661
+ "aria-hidden": "true"
662
+ }, /* @__PURE__ */ React.createElement("polyline", {
663
+ points: line,
664
+ fill: "none",
665
+ vectorEffect: "non-scaling-stroke"
666
+ })));
667
+ }
668
+ function Detail({
669
+ tile: tile2,
670
+ query,
671
+ answer,
672
+ words,
673
+ send,
674
+ title
675
+ }) {
676
+ const [copied, setCopied] = React.useState("");
677
+ const [waiting, run] = useBusy();
678
+ const result = answer?.result;
679
+ const facts = result ? [
680
+ DashWords.fill(words.updated, { ago: DashWords.ago(words, result.at) }),
681
+ DashWords.fill(words.took, { time: DashWords.span(result.ms) }),
682
+ ...result.error ? [] : [DashWords.fill(result.cut ? words.cut : words.rows, { count: result.rows.length })]
683
+ ] : [];
684
+ const did = (what) => {
685
+ setCopied(what);
686
+ setTimeout(() => setCopied(""), 1500);
687
+ };
688
+ const Copy = icons.Copy;
689
+ const Ask = icons.MessageCircle;
690
+ return /* @__PURE__ */ React.createElement("div", {
691
+ className: "tdash-detail",
692
+ onClick: (event) => event.stopPropagation()
693
+ }, /* @__PURE__ */ React.createElement("div", {
694
+ className: "tdash-detail-head"
695
+ }, words.query), /* @__PURE__ */ React.createElement("pre", {
696
+ className: "tdash-query"
697
+ }, query), facts.length > 0 && /* @__PURE__ */ React.createElement("div", {
698
+ className: "tdash-facts"
699
+ }, facts.join(" · ")), /* @__PURE__ */ React.createElement("div", {
700
+ className: "tdash-actions"
701
+ }, /* @__PURE__ */ React.createElement("button", {
702
+ type: "button",
703
+ className: waiting ? "ta-busy" : undefined,
704
+ onClick: () => void run(() => copy(query).then((ok) => ok && did("query")))
705
+ }, Copy && /* @__PURE__ */ React.createElement(Copy, {
706
+ size: 13
707
+ }), copied === "query" ? words.copied : words.copyQuery), result && !result.error && result.rows.length > 0 && /* @__PURE__ */ React.createElement("button", {
708
+ type: "button",
709
+ className: waiting ? "ta-busy" : undefined,
710
+ onClick: () => void run(() => copy(DashRows.tsv(result)).then((ok) => ok && did("data")))
711
+ }, Copy && /* @__PURE__ */ React.createElement(Copy, {
712
+ size: 13
713
+ }), copied === "data" ? words.copied : words.copyData), send && /* @__PURE__ */ React.createElement("button", {
714
+ type: "button",
715
+ className: waiting ? "ta-busy" : undefined,
716
+ onClick: () => void run(() => send(DashWords.fill(words.explainText, { title, said: DashGlance.said(tile2, result) })))
717
+ }, Ask && /* @__PURE__ */ React.createElement(Ask, {
718
+ size: 13
719
+ }), words.explain)));
720
+ }
721
+ function Tile({
722
+ tile: tile2,
723
+ index,
724
+ dash,
725
+ answer,
726
+ words,
727
+ open,
728
+ onOpen,
729
+ props,
730
+ title,
731
+ shared
732
+ }) {
733
+ const result = answer?.result;
734
+ const ago = result && !result.error ? DashWords.ago(words, result.at) : undefined;
735
+ const query = dash.sources.find((source) => source.name === tile2.source)?.run ?? "";
736
+ let body;
737
+ if (!result) {
738
+ body = /* @__PURE__ */ React.createElement("div", {
739
+ className: "tdash-pending"
740
+ }, answer ? "—" : words.loading);
741
+ } else if (result.error) {
742
+ body = /* @__PURE__ */ React.createElement("div", {
743
+ className: "tdash-error"
744
+ }, DashWords.fill(words.error, { reason: result.error }));
745
+ } else if (!result.rows.length) {
746
+ body = /* @__PURE__ */ React.createElement("div", {
747
+ className: "tdash-pending"
748
+ }, words.noRows);
749
+ } else if (tile2.type === "stat") {
750
+ body = /* @__PURE__ */ React.createElement(Stat, {
751
+ tile: tile2,
752
+ result,
753
+ words
754
+ });
755
+ } else {
756
+ const block = DashGlance.block(tile2, result);
757
+ body = block ? /* @__PURE__ */ React.createElement("div", {
758
+ className: "tdash-chart"
759
+ }, /* @__PURE__ */ React.createElement(Markdown, {
760
+ text: DashGlance.markdown(block)
761
+ })) : /* @__PURE__ */ React.createElement("div", {
762
+ className: "tdash-pending"
763
+ }, words.noValue);
764
+ }
765
+ const point = props.point;
766
+ const tap = () => {
767
+ if (point) {
768
+ point({ anchor: `tiles[${index}]`, label: tile2.label, source: JSON.stringify({ tile: tile2, query }) });
769
+ return;
770
+ }
771
+ onOpen();
772
+ };
773
+ return /* @__PURE__ */ React.createElement("div", {
774
+ className: "tdash-tile",
775
+ role: "button",
776
+ tabIndex: 0,
777
+ "aria-expanded": open,
778
+ "data-kind": tile2.type,
779
+ "data-open": open || undefined,
780
+ onKeyDown: (event) => {
781
+ if (event.target === event.currentTarget && (event.key === "Enter" || event.key === " ")) {
782
+ event.preventDefault();
783
+ tap();
784
+ }
785
+ },
786
+ onClick: tap
787
+ }, /* @__PURE__ */ React.createElement("div", {
788
+ className: "tdash-tile-head"
789
+ }, /* @__PURE__ */ React.createElement("span", {
790
+ className: "tdash-label"
791
+ }, tile2.label), ago && ago !== shared && /* @__PURE__ */ React.createElement("span", {
792
+ className: "tdash-ago"
793
+ }, ago)), body, tile2.note && /* @__PURE__ */ React.createElement("div", {
794
+ className: "tdash-note"
795
+ }, tile2.note), open && /* @__PURE__ */ React.createElement(Detail, {
796
+ tile: tile2,
797
+ query,
798
+ answer,
799
+ words,
800
+ title,
801
+ ...props.send ? { send: props.send } : {}
802
+ }));
803
+ }
804
+ function Board({ dash, props, words }) {
805
+ const [answer, setAnswer] = React.useState(undefined);
806
+ const [busy, setBusy] = React.useState(false);
807
+ const [failure, setFailure] = React.useState(undefined);
808
+ const [acting, run] = useBusy();
809
+ const [open, setOpen] = React.useState(undefined);
810
+ const [, setTick] = React.useState(0);
811
+ const card = React.useRef(null);
812
+ const visible = React.useRef(false);
813
+ const last = React.useRef(0);
814
+ const title = dash.title ?? words.untitled;
815
+ const code = props.code;
816
+ const conversation = props.conversation ?? null;
817
+ const load = React.useCallback(async (how, force = false) => {
818
+ setBusy(true);
819
+ try {
820
+ const next = await pi.callHost(how, code, conversation, ...how === "run" ? [force] : []);
821
+ setAnswer(next);
822
+ setFailure(undefined);
823
+ last.current = Date.now();
824
+ } catch (error) {
825
+ setFailure(error instanceof Error ? error.message : String(error));
826
+ } finally {
827
+ setBusy(false);
828
+ }
829
+ }, [code, conversation]);
830
+ React.useEffect(() => {
831
+ const element = card.current;
832
+ if (!element) {
833
+ return;
834
+ }
835
+ let first = true;
836
+ const observer = typeof IntersectionObserver === "undefined" ? undefined : new IntersectionObserver(([entry]) => {
837
+ visible.current = entry.isIntersecting;
838
+ if (entry.isIntersecting && first) {
839
+ first = false;
840
+ load("run");
841
+ }
842
+ });
843
+ if (observer) {
844
+ observer.observe(element);
845
+ } else {
846
+ visible.current = true;
847
+ load("run");
848
+ }
849
+ const timer = setInterval(() => {
850
+ setTick((tick) => tick + 1);
851
+ if (visible.current && document.visibilityState === "visible" && dash.refresh && Date.now() - last.current >= dash.refresh) {
852
+ load("run");
853
+ }
854
+ }, TICK_MS);
855
+ return () => {
856
+ observer?.disconnect();
857
+ clearInterval(timer);
858
+ };
859
+ }, [load, dash.refresh]);
860
+ const asked = Object.values(answer?.sources ?? {}).some((source) => source.state === "ask");
861
+ React.useEffect(() => {
862
+ if (!asked) {
863
+ return;
864
+ }
865
+ pi.storage.get(DashKeys.ALLOWED);
866
+ return pi.storage.onChange((changed) => {
867
+ if (changed.includes(DashKeys.ALLOWED)) {
868
+ load("run");
869
+ }
870
+ });
871
+ }, [asked, load]);
872
+ React.useEffect(() => {
873
+ const keys = Object.values(answer?.sources ?? {}).flatMap((source) => source.key ? [source.key] : []);
874
+ if (!keys.length) {
875
+ return;
876
+ }
877
+ return pi.storage.onChange((changed) => {
878
+ for (const key of changed.filter((entry) => keys.includes(entry))) {
879
+ pi.storage.get(key).then((result) => {
880
+ if (!result) {
881
+ return;
882
+ }
883
+ setAnswer((current) => {
884
+ if (!current) {
885
+ return current;
886
+ }
887
+ const sources = Object.fromEntries(Object.entries(current.sources).map(([name, source]) => [
888
+ name,
889
+ source.key === key && source.result?.at !== result.at ? { ...source, result } : source
890
+ ]));
891
+ return { ...current, sources };
892
+ });
893
+ });
894
+ }
895
+ });
896
+ }, [answer]);
897
+ const states = Object.values(answer?.sources ?? {});
898
+ const asking = dash.sources.filter((source) => answer?.sources[source.name]?.state === "ask");
899
+ const remote = states.some((source) => source.state === "remote");
900
+ const others = states.find((source) => source.state === "others");
901
+ const times = states.flatMap((source) => source.result && !source.result.error ? [source.result.at] : []);
902
+ const oldest = times.length ? Math.min(...times) : undefined;
903
+ const Refresh = icons.RefreshCw;
904
+ const Film = icons.Film;
905
+ const said = dash.tiles.map((tile2) => DashGlance.said(tile2, answer?.sources[tile2.source]?.result)).join(`
906
+ `);
907
+ return /* @__PURE__ */ React.createElement("div", {
908
+ className: "tdash-card",
909
+ ref: card
910
+ }, /* @__PURE__ */ React.createElement("div", {
911
+ className: "tdash-head"
912
+ }, /* @__PURE__ */ React.createElement("div", {
913
+ className: "tdash-title"
914
+ }, title), /* @__PURE__ */ React.createElement("div", {
915
+ className: "tdash-fresh"
916
+ }, oldest !== undefined && DashWords.fill(words.updated, { ago: DashWords.ago(words, oldest) }), oldest !== undefined && " · ", dash.refresh ? DashWords.fill(words.every, { time: DashWords.span(dash.refresh) }) : words.byHand), /* @__PURE__ */ React.createElement("button", {
917
+ type: "button",
918
+ className: "tdash-refresh",
919
+ "data-busy": busy || undefined,
920
+ "aria-label": words.refresh,
921
+ title: words.refresh,
922
+ disabled: busy,
923
+ onClick: () => void run(() => load("run", true))
924
+ }, Refresh ? /* @__PURE__ */ React.createElement(Refresh, {
925
+ size: 15
926
+ }) : words.refresh)), failure && /* @__PURE__ */ React.createElement("div", {
927
+ className: "tdash-banner"
928
+ }, answer ? failure : words.offline), remote && /* @__PURE__ */ React.createElement("div", {
929
+ className: "tdash-banner"
930
+ }, words.remote), others && /* @__PURE__ */ React.createElement("div", {
931
+ className: "tdash-banner"
932
+ }, DashWords.fill(words.others, { ago: oldest !== undefined ? DashWords.ago(words, oldest) : "—" })), asking.length > 0 && /* @__PURE__ */ React.createElement("div", {
933
+ className: "tdash-ask"
934
+ }, /* @__PURE__ */ React.createElement("div", {
935
+ className: "tdash-ask-title"
936
+ }, DashWords.fill(words.askTitle, { count: asking.length })), asking.map((source) => /* @__PURE__ */ React.createElement("pre", {
937
+ key: source.name,
938
+ className: "tdash-query"
939
+ }, source.run)), /* @__PURE__ */ React.createElement("div", {
940
+ className: "tdash-ask-hint"
941
+ }, words.askHint), /* @__PURE__ */ React.createElement("button", {
942
+ type: "button",
943
+ className: acting ? "tdash-allow ta-busy" : "tdash-allow",
944
+ disabled: busy,
945
+ onClick: () => void run(() => load("approve"))
946
+ }, words.allow)), /* @__PURE__ */ React.createElement("div", {
947
+ className: "tdash-grid"
948
+ }, dash.tiles.map((tile2, index) => /* @__PURE__ */ React.createElement(Tile, {
949
+ key: `${index}-${tile2.label}`,
950
+ tile: tile2,
951
+ index,
952
+ dash,
953
+ answer: answer?.sources[tile2.source],
954
+ words,
955
+ open: open === index,
956
+ onOpen: () => setOpen(open === index ? undefined : index),
957
+ props,
958
+ title,
959
+ shared: oldest !== undefined ? DashWords.ago(words, oldest) : undefined
960
+ }))), props.send && times.length > 0 && /* @__PURE__ */ React.createElement("div", {
961
+ className: "tdash-next"
962
+ }, /* @__PURE__ */ React.createElement("button", {
963
+ type: "button",
964
+ className: acting ? "ta-busy" : undefined,
965
+ onClick: () => void run(async () => props.send?.(DashWords.fill(words.toMotionText, { title, said })))
966
+ }, Film && /* @__PURE__ */ React.createElement(Film, {
967
+ size: 14
968
+ }), words.toMotion)));
969
+ }
970
+ return function DashView(props) {
971
+ const words = DashWords.of(pi.ui.language);
972
+ const read = React.useMemo(() => {
973
+ if (!props.closed) {
974
+ return;
975
+ }
976
+ try {
977
+ return { dash: DashSpec.read(props.code) };
978
+ } catch (error) {
979
+ return { error: error instanceof Error ? error.message : String(error) };
980
+ }
981
+ }, [props.code, props.closed]);
982
+ if (!read) {
983
+ return /* @__PURE__ */ React.createElement("div", {
984
+ className: "tdash-card tdash-making"
985
+ }, words.making);
986
+ }
987
+ if ("error" in read) {
988
+ return /* @__PURE__ */ React.createElement("div", {
989
+ className: "tdash-card tdash-failed"
990
+ }, DashWords.fill(words.failed, { reason: read.error ?? "" }));
991
+ }
992
+ return /* @__PURE__ */ React.createElement(Board, {
993
+ dash: read.dash,
994
+ props,
995
+ words
996
+ });
997
+ };
998
+ }
999
+
1000
+ // web-src/style.ts
1001
+ var STYLE = `
1002
+ /*
1003
+ * A dashboard of a reply (\`\`\`ta-dash): a head with when it was fetched, tiles in a grid, the query behind a tile once
1004
+ * tapped. One frame, the card's (AGENTS.md "A block has one frame"): a tile is a fill, a chart in it has no frame of its
1005
+ * own, the query is a fill on the tile, its buttons are chips.
1006
+ */
1007
+ .tdash-card {
1008
+ --tdash-s: var(--ta-font-scale, 1);
1009
+ margin: 2px 0 12px;
1010
+ padding: 12px;
1011
+ max-width: var(--ta-page-width);
1012
+ border: 1px solid var(--ta-border);
1013
+ border-radius: 12px;
1014
+ background: var(--ta-card);
1015
+ color: var(--ta-text);
1016
+ font-size: calc(13px * var(--tdash-s));
1017
+ line-height: 1.5;
1018
+ container-type: inline-size;
1019
+ }
1020
+ .ta-code-embedded > .tdash-card { margin: 0; padding: 0; max-width: none; border: 0; background: none; }
1021
+ .tdash-making, .tdash-failed { color: var(--ta-muted); }
1022
+ .tdash-head { display: flex; align-items: center; gap: 8px; margin: -2px -4px 10px 0; }
1023
+ .tdash-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1024
+ .tdash-fresh { flex: 1; min-width: 0; color: var(--ta-muted); font-size: calc(12px * var(--tdash-s)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1025
+ .tdash-refresh {
1026
+ flex: none; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
1027
+ border: 0; border-radius: 8px; background: transparent; color: var(--ta-muted); cursor: pointer;
1028
+ }
1029
+ .tdash-refresh:hover { color: var(--ta-text); background: var(--ta-hover); }
1030
+ .tdash-refresh[data-busy] svg { animation: tdash-spin 0.9s linear infinite; }
1031
+ @keyframes tdash-spin { to { transform: rotate(360deg); } }
1032
+ .tdash-banner { margin-bottom: 10px; color: var(--ta-muted); font-size: calc(12px * var(--tdash-s)); }
1033
+ .tdash-ask { margin-bottom: 10px; padding: 10px 12px; border-radius: 10px; background: var(--ta-raised); }
1034
+ .tdash-ask-title { font-weight: 600; margin-bottom: 6px; }
1035
+ .tdash-ask-hint { color: var(--ta-muted); font-size: calc(12px * var(--tdash-s)); margin: 6px 0 8px; }
1036
+ .tdash-allow {
1037
+ padding: 5px 14px; border: 0; border-radius: 8px; background: var(--ta-accent); color: #fff; font: inherit; cursor: pointer;
1038
+ }
1039
+ .tdash-allow:disabled { opacity: 0.6; }
1040
+ .tdash-query {
1041
+ margin: 4px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--ta-card); color: var(--ta-body, var(--ta-text));
1042
+ font-family: var(--ta-mono, ui-monospace, monospace); font-size: calc(11.5px * var(--tdash-s)); line-height: 1.55;
1043
+ white-space: pre-wrap; overflow-wrap: anywhere; max-height: 140px; overflow: auto;
1044
+ }
1045
+ .tdash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
1046
+ .tdash-tile {
1047
+ min-width: 0; padding: 10px 12px; border-radius: 10px; background: var(--ta-raised); cursor: pointer;
1048
+ transition: background 0.15s;
1049
+ }
1050
+ .tdash-tile:hover { background: var(--ta-hover); }
1051
+ .tdash-tile:focus-visible { outline: 2px solid var(--ta-border-focus); outline-offset: 1px; }
1052
+ .tdash-tile[data-open] { background: var(--ta-raised); cursor: default; }
1053
+ .tdash-tile:not([data-kind="stat"]) { grid-column: span 2; }
1054
+ /* Opened, a tile takes the whole row: its query reads in full, the tile beside it does not stretch to its height. */
1055
+ .tdash-tile[data-open] { grid-column: 1 / -1; }
1056
+ @container (max-width: 340px) { .tdash-tile:not([data-kind="stat"]) { grid-column: 1 / -1; } }
1057
+ .tdash-tile-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; }
1058
+ .tdash-label { flex: 1; min-width: 0; color: var(--ta-muted); font-size: calc(12px * var(--tdash-s)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1059
+ .tdash-ago { flex: none; color: var(--ta-muted); font-size: calc(11px * var(--tdash-s)); opacity: 0.8; }
1060
+ .tdash-stat { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
1061
+ .tdash-value { font-size: calc(22px * var(--tdash-s)); font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
1062
+ .tdash-delta { font-size: calc(12px * var(--tdash-s)); color: var(--ta-muted); font-variant-numeric: tabular-nums; }
1063
+ .tdash-delta[data-tone="good"] { color: var(--ta-green, #16a34a); }
1064
+ .tdash-delta[data-tone="bad"] { color: var(--ta-red, #dc2626); }
1065
+ .tdash-spark { flex-basis: 100%; width: 100%; height: 26px; margin-top: 4px; }
1066
+ .tdash-spark polyline { stroke: var(--ta-accent); stroke-width: 1.5; }
1067
+ .tdash-pending { color: var(--ta-muted); padding: 6px 0; }
1068
+ .tdash-error { color: var(--ta-red, #dc2626); font-size: calc(12px * var(--tdash-s)); word-break: break-word; }
1069
+ .tdash-note { margin-top: 4px; color: var(--ta-muted); font-size: calc(11.5px * var(--tdash-s)); }
1070
+ .tdash-detail { margin-top: 10px; cursor: default; }
1071
+ .tdash-detail-head { color: var(--ta-muted); font-size: calc(11.5px * var(--tdash-s)); }
1072
+ .tdash-facts { margin-top: 6px; color: var(--ta-muted); font-size: calc(11.5px * var(--tdash-s)); }
1073
+ .tdash-actions, .tdash-next { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
1074
+ .tdash-actions button, .tdash-next button {
1075
+ display: inline-flex; align-items: center; gap: 5px; height: calc(28px * var(--tdash-s)); padding: 0 12px 0 10px; border: 0; border-radius: 999px;
1076
+ background: var(--ta-chip); color: var(--ta-text); font: inherit; font-size: calc(12px * var(--tdash-s)); cursor: pointer;
1077
+ transition: background 0.15s;
1078
+ }
1079
+ .tdash-actions button { background: var(--ta-card); }
1080
+ .tdash-actions button svg, .tdash-next button svg { color: var(--ta-muted); }
1081
+ .tdash-actions button:hover, .tdash-next button:hover { background: var(--ta-hover-strong); }
1082
+ .tdash-next { margin-top: 10px; }
1083
+ `;
1084
+ function injectStyle() {
1085
+ const element = document.createElement("style");
1086
+ element.dataset.taPackage = "ta-dash";
1087
+ element.textContent = STYLE;
1088
+ document.head.appendChild(element);
1089
+ return () => element.remove();
1090
+ }
1091
+
1092
+ // web-src/index.tsx
1093
+ function activate(pi) {
1094
+ bind(pi.React);
1095
+ if (!pi.registerCodeRenderer) {
1096
+ return () => {
1097
+ return;
1098
+ };
1099
+ }
1100
+ const removeStyle = injectStyle();
1101
+ pi.registerCodeRenderer(LANGUAGE, dashView(pi), { pointable: true });
1102
+ return removeStyle;
1103
+ }
1104
+ export {
1105
+ activate as default
1106
+ };