@seanyeh77/ui 0.51.0 → 0.52.1

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.
@@ -989,6 +989,12 @@
989
989
  .ui-dt-body .ui-dt-cell.is-num {
990
990
  white-space: normal;
991
991
  }
992
+ /* A number with a second line starts at the left like every value in the card, on its name's line: the table's
993
+ right alignment and the stack's 6 px padding are for rows, not cards. */
994
+ .ui-dt-body .ui-dt-cell.is-num .ui-dt-stack {
995
+ align-items: flex-start;
996
+ padding-block: 0;
997
+ }
992
998
  .ui-dt-body .ui-dt-cell[data-label]:not(.is-m-title, .is-m-status)::before {
993
999
  content: attr(data-label);
994
1000
  position: absolute;
@@ -1,3 +1,3 @@
1
- import { Decimals, format } from "./format.js";
1
+ import { Decimals, format, plainMinus } from "./format.js";
2
2
  import { CountUnit, addMessages, setLocale, tr } from "./i18n.js";
3
- export { type CountUnit, type Decimals, addMessages, format, setLocale, tr as t };
3
+ export { type CountUnit, type Decimals, addMessages, format, plainMinus, setLocale, tr as t };
@@ -1,3 +1,3 @@
1
- import { format } from "./format.js";
1
+ import { format, plainMinus } from "./format.js";
2
2
  import { addMessages, setLocale, tr } from "./i18n.js";
3
- export { addMessages, format, setLocale, tr as t };
3
+ export { addMessages, format, plainMinus, setLocale, tr as t };
package/dist/format.d.ts CHANGED
@@ -20,13 +20,15 @@ declare function month(d: Date): string;
20
20
  declare function firstDay(): number;
21
21
  /** Narrow weekday names, starting from firstDay(). */
22
22
  declare function weekdays(): string[];
23
+ /** Text for the clipboard: 「−」 back to the hyphen 「-」, which spreadsheets and scripts parse as a minus sign. */
24
+ export declare const plainMinus: (s: string) => string;
23
25
  /** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */
24
26
  declare function number(v: number, dec?: Decimals): string;
25
27
  declare function percent(v: number, dec?: number): string;
26
28
  /** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.
27
29
  * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */
28
30
  declare function compact(v: number, like?: number): string;
29
- /** zh-TW with TWD: NT$ 1,280 (a no-break space after NT$), negatives -NT$ 1,280. Other locales and currencies: Intl's own symbol and order. */
31
+ /** zh-TW with TWD: NT$ 1,280 (a no-break space after NT$), negatives −NT$ 1,280 (U+2212). Other locales and currencies: Intl's own symbol and order. */
30
32
  declare function money(v: number, o?: {
31
33
  currency?: string;
32
34
  compact?: boolean;
package/dist/format.js CHANGED
@@ -87,20 +87,23 @@ function weekdays() {
87
87
  const f = new Intl.DateTimeFormat(I18N.locale, { weekday: "narrow" });
88
88
  return Array.from({ length: 7 }, (_, i) => f.format(new Date(2026, 10, 1 + (fd + i) % 7)));
89
89
  }
90
+ const minus = (s) => s.replace(/[-\u2212]/g, "−");
91
+ /** Text for the clipboard: 「−」 back to the hyphen 「-」, which spreadsheets and scripts parse as a minus sign. */
92
+ const plainMinus = (s) => s.replace(/\u2212/g, "-");
90
93
  /** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */
91
94
  function number(v, dec) {
92
95
  const dd = typeof dec === "number" ? dec : dec ? DECIMALS[dec] : 0;
93
- return new Intl.NumberFormat(I18N.locale, {
96
+ return minus(new Intl.NumberFormat(I18N.locale, {
94
97
  minimumFractionDigits: dd,
95
98
  maximumFractionDigits: dd
96
- }).format(v);
99
+ }).format(v));
97
100
  }
98
101
  function percent(v, dec = 1) {
99
- return new Intl.NumberFormat(I18N.locale, {
102
+ return minus(new Intl.NumberFormat(I18N.locale, {
100
103
  style: "percent",
101
104
  minimumFractionDigits: dec,
102
105
  maximumFractionDigits: dec
103
- }).format(v / 100);
106
+ }).format(v / 100));
104
107
  }
105
108
  /** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.
106
109
  * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */
@@ -119,7 +122,7 @@ function compact(v, like) {
119
122
  1
120
123
  ];
121
124
  const finalStr = new Intl.NumberFormat(I18N.locale, { maximumFractionDigits: maxDec }).format(a / div);
122
- const sign = v < 0 ? "-" : "";
125
+ const sign = v < 0 ? "−" : "";
123
126
  if (like === void 0) return `${sign}${finalStr}\u00a0${unit}`;
124
127
  const digits = (finalStr.split(".")[1] || "").length;
125
128
  return `${sign}${new Intl.NumberFormat(I18N.locale, {
@@ -131,7 +134,7 @@ function compact(v, like) {
131
134
  notation: "compact",
132
135
  maximumFractionDigits: 1
133
136
  });
134
- if (like === void 0) return nf.format(v);
137
+ if (like === void 0) return minus(nf.format(v));
135
138
  const parts = nf.formatToParts(ref);
136
139
  let num = "";
137
140
  let dec = "";
@@ -156,21 +159,21 @@ function compact(v, like) {
156
159
  }
157
160
  return pt.value;
158
161
  }).join("");
159
- return (v < 0 && ref >= 0 ? "-" : "") + body;
162
+ return minus((v < 0 && ref >= 0 ? "-" : "") + body);
160
163
  }
161
- /** zh-TW with TWD: NT$ 1,280 (a no-break space after NT$), negatives -NT$ 1,280. Other locales and currencies: Intl's own symbol and order. */
164
+ /** zh-TW with TWD: NT$ 1,280 (a no-break space after NT$), negatives −NT$ 1,280 (U+2212). Other locales and currencies: Intl's own symbol and order. */
162
165
  function money(v, o = {}) {
163
166
  const cur = o.currency || I18N.currency;
164
167
  const body = o.compact ? compact(Math.abs(v), o.like !== void 0 ? Math.abs(o.like) : void 0) : number(Math.abs(v), "money");
165
- if (isZhTW() && cur === "TWD") return `${v < 0 ? "-" : ""}NT$\u00a0${body}`;
166
- if (o.compact) return `${v < 0 ? "-" : ""}${body}\u00a0${cur}`;
167
- return new Intl.NumberFormat(I18N.locale, {
168
+ if (isZhTW() && cur === "TWD") return `${v < 0 ? "−" : ""}NT$\u00a0${body}`;
169
+ if (o.compact) return `${v < 0 ? "−" : ""}${body}\u00a0${cur}`;
170
+ return minus(new Intl.NumberFormat(I18N.locale, {
168
171
  style: "currency",
169
172
  currency: cur,
170
173
  currencyDisplay: cur === "TWD" ? "symbol" : "narrowSymbol",
171
174
  minimumFractionDigits: 0,
172
175
  maximumFractionDigits: cur === "TWD" || cur === "JPY" ? 0 : 2
173
- }).format(v);
176
+ }).format(v));
174
177
  }
175
178
  /** Bytes to 「186 KB」「54.9 MB」「1.2 GB」, with a no-break space (U+00A0) so the unit never wraps away. */
176
179
  function fileSize(b) {
@@ -243,6 +246,6 @@ function parseDate(s) {
243
246
  }
244
247
  const sameDay = (a, b) => !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
245
248
  const dayAdd = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
246
- export { dayAdd, fileSize, fmtDate, format, parseDate, sameDay };
249
+ export { dayAdd, fileSize, fmtDate, format, parseDate, plainMinus, sameDay };
247
250
 
248
251
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { I18N, isZhTW, tr } from './i18n';\n\n/* Dates and numbers for the current locale (setLocale). zh-TW follows the design system's rules\n (2026/11/04(三), 24-hour clock, NT$ 1,280, 萬 and 億 in KPI cards); other locales use Intl's conventions. */\n\nexport type Decimals = number | 'money' | 'percent' | 'size' | 'count';\n\nconst DECIMALS = { money: 0, percent: 1, size: 1, count: 0 } as const;\n\nconst pad2 = (n: number): string => String(n).padStart(2, '0');\n\nfunction locale(): string {\n return I18N.locale;\n}\n\n/** zh-TW: 2026/11/04(三). Other locales: their short date with weekday. */\nfunction date(d: Date | null | undefined, o: { weekday?: boolean; long?: boolean } = {}): string {\n if (!d) return '';\n const wd = o.weekday !== false;\n if (o.long) return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long', day: 'numeric', weekday: wd ? 'long' : undefined }).format(d);\n if (isZhTW()) return fmtDate(d) + (wd ? `(${new Intl.DateTimeFormat('zh-TW', { weekday: 'narrow' }).format(d)})` : '');\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: '2-digit', day: '2-digit', weekday: wd ? 'short' : undefined }).format(d);\n}\n\n/** zh-TW: 24-hour 15:57. Other locales: their own clock. */\nfunction time(d: Date | null | undefined): string {\n if (!d) return '';\n return new Intl.DateTimeFormat(\n I18N.locale,\n isZhTW() ? { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' } : { hour: 'numeric', minute: '2-digit' },\n ).format(d);\n}\n\nfunction dateTime(d: Date | null | undefined, o?: { weekday?: boolean }): string {\n if (!d) return '';\n // zh-TW: the full-width 「)」 already leaves half a character of room, so no space after it: 2026/11/04(三)13:00.\n const day = date(d, o);\n return isZhTW() && day.endsWith(')') ? day + time(d) : `${day} ${time(d)}`;\n}\n\n/** Whole local calendar days from d to now: 1 for any time yesterday, whatever the hour. */\nfunction dayDiff(d: Date, now: Date): number {\n // Through UTC dates of the local day, so a 23-hour or 25-hour day (daylight saving) still counts as one.\n const day = (x: Date) => Date.UTC(x.getFullYear(), x.getMonth(), x.getDate());\n return Math.round((day(now) - day(d)) / 86400000);\n}\n\n/** Under 1 hour: 「現在」 or 「5 分鐘前」. The same calendar day: 「2 小時前」. An earlier day: by calendar days, 「昨天」\n * for any time yesterday (also 30 minutes before midnight seen after it, once an hour has passed), 「3 天前」 up to 6\n * days. 7 calendar days or more, or more than 60 s in the future: the full date and time. Up to 60 s in the future (one\n * clock running a little ahead of the other) reads like the last minute. Pass now to test. */\nfunction relative(d: Date | null | undefined, now: Date = new Date()): string {\n if (!d) return '';\n const s = (now.getTime() - d.getTime()) / 1000;\n const days = dayDiff(d, now);\n const rt = new Intl.RelativeTimeFormat(I18N.locale, { numeric: 'auto' });\n if (s >= -60 && s < 60) return rt.format(0, 'second');\n if (s < 0 || days >= 7) return dateTime(d);\n if (s < 3600) return rt.format(-Math.floor(s / 60), 'minute');\n if (days === 0) return rt.format(-Math.floor(s / 3600), 'hour');\n return rt.format(-days, 'day');\n}\n\nfunction month(d: Date): string {\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long' }).format(d);\n}\n\n/** Week starts on Sunday for zh-TW; other locales use Intl's week info when the browser has it. */\nfunction firstDay(): number {\n if (isZhTW()) return 0;\n try {\n const l = new Intl.Locale(I18N.locale) as Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } };\n const w = l.getWeekInfo ? l.getWeekInfo() : l.weekInfo;\n if (w?.firstDay) return w.firstDay % 7;\n } catch {\n /* older browsers have no week info */\n }\n return 0;\n}\n\n/** Narrow weekday names, starting from firstDay(). */\nfunction weekdays(): string[] {\n const fd = firstDay();\n const f = new Intl.DateTimeFormat(I18N.locale, { weekday: 'narrow' });\n // 2026/11/01 is a Sunday.\n return Array.from({ length: 7 }, (_, i) => f.format(new Date(2026, 10, 1 + ((fd + i) % 7))));\n}\n\n/** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */\nfunction number(v: number, dec?: Decimals): string {\n const dd = typeof dec === 'number' ? dec : dec ? DECIMALS[dec] : 0;\n return new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dd, maximumFractionDigits: dd }).format(v);\n}\n\nfunction percent(v: number, dec = 1): string {\n return new Intl.NumberFormat(I18N.locale, { style: 'percent', minimumFractionDigits: dec, maximumFractionDigits: dec }).format(v / 100);\n}\n\n/** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.\n * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */\nfunction compact(v: number, like?: number): string {\n const ref = like ?? v;\n if (Math.abs(ref) < 1e4) return number(v);\n if (/^zh/i.test(I18N.locale)) {\n const a = Math.abs(ref);\n // 99,999,999 rounds to 10,000.0 萬: write it as 1 億.\n const [unit, div, maxDec] = Math.round(a / 1e3) >= 1e5 ? (['億', 1e8, 2] as const) : (['萬', 1e4, 1] as const);\n const finalStr = new Intl.NumberFormat(I18N.locale, { maximumFractionDigits: maxDec }).format(a / div);\n const sign = v < 0 ? '-' : '';\n if (like === undefined) return `${sign}${finalStr}\\u00a0${unit}`;\n const digits = (finalStr.split('.')[1] || '').length;\n return `${sign}${new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Math.abs(v) / div)}\\u00a0${unit}`;\n }\n const nf = new Intl.NumberFormat(I18N.locale, { notation: 'compact', maximumFractionDigits: 1 });\n if (like === undefined) return nf.format(v);\n const parts = nf.formatToParts(ref);\n let num = '';\n let dec = '';\n for (const pt of parts) {\n if (pt.type === 'integer') num += pt.value;\n if (pt.type === 'fraction') {\n num += '.' + pt.value;\n dec = pt.value;\n }\n }\n const mant = parseFloat(num) || 1;\n const scale = 10 ** Math.round(Math.log10(Math.abs(ref) / mant));\n const inner = new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dec.length, maximumFractionDigits: dec.length }).format(Math.abs(v) / scale);\n let done = false;\n const body = parts\n .map((pt) => {\n if (pt.type === 'integer' || pt.type === 'group' || pt.type === 'decimal' || pt.type === 'fraction') {\n if (done) return '';\n done = true;\n return inner;\n }\n return pt.value;\n })\n .join('');\n return (v < 0 && ref >= 0 ? '-' : '') + body;\n}\n\n/** zh-TW with TWD: NT$ 1,280 (a no-break space after NT$), negatives -NT$ 1,280. Other locales and currencies: Intl's own symbol and order. */\nfunction money(v: number, o: { currency?: string; compact?: boolean; like?: number } = {}): string {\n const cur = o.currency || I18N.currency;\n const body = o.compact ? compact(Math.abs(v), o.like !== undefined ? Math.abs(o.like) : undefined) : number(Math.abs(v), 'money');\n if (isZhTW() && cur === 'TWD') return `${v < 0 ? '-' : ''}NT$\\u00a0${body}`;\n if (o.compact) return `${v < 0 ? '-' : ''}${body}\\u00a0${cur}`;\n return new Intl.NumberFormat(I18N.locale, {\n style: 'currency',\n currency: cur,\n // narrowSymbol writes TWD as a bare 「$」, which reads as dollars: keep 「NT$」 (docs: 英文介面顯示 NT$486,000).\n currencyDisplay: cur === 'TWD' ? 'symbol' : 'narrowSymbol',\n minimumFractionDigits: 0,\n maximumFractionDigits: cur === 'TWD' || cur === 'JPY' ? 0 : 2,\n }).format(v);\n}\n\n/** Bytes to 「186 KB」「54.9 MB」「1.2 GB」, with a no-break space (U+00A0) so the unit never wraps away. */\nexport function fileSize(b: number | null | undefined): string {\n if (b == null || Number.isNaN(b)) return '';\n // An empty file is 0 KB; anything else at least 1 KB.\n // Compare after rounding: 1,048,500 bytes rounds to 1,024 KB, so it is written 「1.0 MB」.\n if (Math.round(b / 1024) < 1024) return number(b === 0 ? 0 : Math.max(1, Math.round(b / 1024))) + '\\u00a0KB';\n if (Math.round((b / 1048576) * 10) < 10240) return number(b / 1048576, 1) + '\\u00a0MB';\n return number(b / 1073741824, 1) + '\\u00a0GB';\n}\n\n/** Seconds as a clock-style length: under 1 h 「46:42」「1:30」 (minutes not zero-padded), 1 h or more 「1:54:49」.\n * Rounded to the second. Negative, NaN or missing: 「—」. */\nfunction duration(seconds: number | null | undefined): string {\n if (seconds == null || Number.isNaN(seconds) || seconds < 0 || !Number.isFinite(seconds)) return '—';\n const t = Math.round(seconds);\n const h = Math.floor(t / 3600);\n const m = Math.floor((t % 3600) / 60);\n const s = t % 60;\n return h ? `${h}:${pad2(m)}:${pad2(s)}` : `${m}:${pad2(s)}`;\n}\n\n/** Shortens a path: keeps the first segment and the last two, 「src/…/hooks/ops.c:58」. */\nfunction path(p: string | null | undefined, o: { head?: number; tail?: number } = {}): string {\n const head = o.head ?? 1;\n const tail = o.tail ?? 2;\n const parts = String(p ?? '').split('/');\n return parts.length > head + tail ? `${parts.slice(0, head).join('/')}/…/${parts.slice(-tail).join('/')}` : String(p ?? '');\n}\n\n/** A part of a whole, as shown: 「1 / 1 個」「6 / 6 筆」, or 「1 / 5」 without a unit. Give screen readers\n * `fractionLabel` with it: they read the slash as 「斜線」. */\nfunction fraction(n: number, total: number, unit?: string): string {\n return tr(unit ? '{n} / {total} {unit}' : '{n} / {total}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** The same fraction as read aloud: 「1 個中的 1 個」「6 筆中的 6 筆」, or 「5 中的 1」 without a unit (English:\n * 「1 of 1」). For `aria-label`, or for visually hidden text beside the shown fraction. */\nfunction fractionLabel(n: number, total: number, unit?: string): string {\n return tr(unit ? '{total} {unit}中的 {n} {unit}' : '{total} 中的 {n}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** Every date, number, amount, size and path shown in the UI goes through these. */\nexport const format = {\n locale,\n date,\n time,\n dateTime,\n relative,\n month,\n weekdays,\n firstDay,\n number,\n percent,\n compact,\n money,\n fileSize,\n duration,\n path,\n fraction,\n fractionLabel,\n};\n\n/* Calendar helpers (local dates, no time). */\nexport const fmtDate = (d: Date | null | undefined): string => (d ? `${d.getFullYear()}/${pad2(d.getMonth() + 1)}/${pad2(d.getDate())}` : '');\n\nexport function parseDate(s: string | null | undefined): Date | null {\n const m = /^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})$/.exec(s || '');\n if (!m) return null;\n const d = new Date(+m[1], +m[2] - 1, +m[3]);\n return d.getMonth() === +m[2] - 1 ? d : null;\n}\n\nexport const sameDay = (a: Date | null | undefined, b: Date | null | undefined): boolean =>\n !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n\nexport const dayAdd = (d: Date, n: number): Date => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);\n"],"mappings":";;AAOA,MAAM,WAAW;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;CAAG,OAAO;AAAE;AAE3D,MAAM,QAAQ,MAAsB,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;AAE7D,SAAS,SAAiB;CACxB,OAAO,KAAK;AACd;;AAGA,SAAS,KAAK,GAA4B,IAA2C,CAAC,GAAW;CAC/F,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,KAAK,EAAE,YAAY;CACzB,IAAI,EAAE,MAAM,OAAO,IAAI,KAAK,eAAe,KAAK,QAAQ;EAAE,MAAM;EAAW,OAAO;EAAQ,KAAK;EAAW,SAAS,KAAK,SAAS,KAAA;CAAU,CAAC,CAAC,CAAC,OAAO,CA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W,OAAe,MAAuB;CACtE,OAAO,GAAG,OAAO,gCAAgC,kBAAkB;EAAE,GAAG,OAAO,CAAC;EAAG,OAAO,OAAO,KAAK;EAAG,MAAM,QAAQ;CAAG,CAAC;AAC7H;;AAGA,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,WAAW,MAAwC,IAAI,GAAG,EAAE,YAAY,EAAE,GAAG,KAAK,EAAE,SAAS,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,CAAC,MAAM;AAE1I,SAAgB,UAAU,GAA2C;CACnE,MAAM,IAAI,kCAAkC,KAAK,KAAK,EAAE;CACxD,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;CAC1C,OAAO,EAAE,SAAS,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI;AAC1C;AAEA,MAAa,WAAW,GAA4B,MAClD,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,MAAM,EAAE,YAAY,KAAK,EAAE,SAAS,MAAM,EAAE,SAAS,KAAK,EAAE,QAAQ,MAAM,EAAE,QAAQ;AAElH,MAAa,UAAU,GAAS,MAAoB,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,IAAI,CAAC"}
1
+ {"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { I18N, isZhTW, tr } from './i18n';\n\n/* Dates and numbers for the current locale (setLocale). zh-TW follows the design system's rules\n (2026/11/04(三), 24-hour clock, NT$ 1,280, 萬 and 億 in KPI cards); other locales use Intl's conventions. */\n\nexport type Decimals = number | 'money' | 'percent' | 'size' | 'count';\n\nconst DECIMALS = { money: 0, percent: 1, size: 1, count: 0 } as const;\n\nconst pad2 = (n: number): string => String(n).padStart(2, '0');\n\nfunction locale(): string {\n return I18N.locale;\n}\n\n/** zh-TW: 2026/11/04(三). Other locales: their short date with weekday. */\nfunction date(d: Date | null | undefined, o: { weekday?: boolean; long?: boolean } = {}): string {\n if (!d) return '';\n const wd = o.weekday !== false;\n if (o.long) return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long', day: 'numeric', weekday: wd ? 'long' : undefined }).format(d);\n if (isZhTW()) return fmtDate(d) + (wd ? `(${new Intl.DateTimeFormat('zh-TW', { weekday: 'narrow' }).format(d)})` : '');\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: '2-digit', day: '2-digit', weekday: wd ? 'short' : undefined }).format(d);\n}\n\n/** zh-TW: 24-hour 15:57. Other locales: their own clock. */\nfunction time(d: Date | null | undefined): string {\n if (!d) return '';\n return new Intl.DateTimeFormat(\n I18N.locale,\n isZhTW() ? { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' } : { hour: 'numeric', minute: '2-digit' },\n ).format(d);\n}\n\nfunction dateTime(d: Date | null | undefined, o?: { weekday?: boolean }): string {\n if (!d) return '';\n // zh-TW: the full-width 「)」 already leaves half a character of room, so no space after it: 2026/11/04(三)13:00.\n const day = date(d, o);\n return isZhTW() && day.endsWith(')') ? day + time(d) : `${day} ${time(d)}`;\n}\n\n/** Whole local calendar days from d to now: 1 for any time yesterday, whatever the hour. */\nfunction dayDiff(d: Date, now: Date): number {\n // Through UTC dates of the local day, so a 23-hour or 25-hour day (daylight saving) still counts as one.\n const day = (x: Date) => Date.UTC(x.getFullYear(), x.getMonth(), x.getDate());\n return Math.round((day(now) - day(d)) / 86400000);\n}\n\n/** Under 1 hour: 「現在」 or 「5 分鐘前」. The same calendar day: 「2 小時前」. An earlier day: by calendar days, 「昨天」\n * for any time yesterday (also 30 minutes before midnight seen after it, once an hour has passed), 「3 天前」 up to 6\n * days. 7 calendar days or more, or more than 60 s in the future: the full date and time. Up to 60 s in the future (one\n * clock running a little ahead of the other) reads like the last minute. Pass now to test. */\nfunction relative(d: Date | null | undefined, now: Date = new Date()): string {\n if (!d) return '';\n const s = (now.getTime() - d.getTime()) / 1000;\n const days = dayDiff(d, now);\n const rt = new Intl.RelativeTimeFormat(I18N.locale, { numeric: 'auto' });\n if (s >= -60 && s < 60) return rt.format(0, 'second');\n if (s < 0 || days >= 7) return dateTime(d);\n if (s < 3600) return rt.format(-Math.floor(s / 60), 'minute');\n if (days === 0) return rt.format(-Math.floor(s / 3600), 'hour');\n return rt.format(-days, 'day');\n}\n\nfunction month(d: Date): string {\n return new Intl.DateTimeFormat(I18N.locale, { year: 'numeric', month: 'long' }).format(d);\n}\n\n/** Week starts on Sunday for zh-TW; other locales use Intl's week info when the browser has it. */\nfunction firstDay(): number {\n if (isZhTW()) return 0;\n try {\n const l = new Intl.Locale(I18N.locale) as Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } };\n const w = l.getWeekInfo ? l.getWeekInfo() : l.weekInfo;\n if (w?.firstDay) return w.firstDay % 7;\n } catch {\n /* older browsers have no week info */\n }\n return 0;\n}\n\n/** Narrow weekday names, starting from firstDay(). */\nfunction weekdays(): string[] {\n const fd = firstDay();\n const f = new Intl.DateTimeFormat(I18N.locale, { weekday: 'narrow' });\n // 2026/11/01 is a Sunday.\n return Array.from({ length: 7 }, (_, i) => f.format(new Date(2026, 10, 1 + ((fd + i) % 7))));\n}\n\n/** The minus sign of shown numbers: U+2212 「−」, not the hyphen 「-」 (it reads as 「minus」 and lines up with 「+」).\n * A formatted number has no other hyphen, so every one is the sign. Copied text goes back to 「-」 (plainMinus), so\n * spreadsheets and scripts still read it as a number. */\nexport const MINUS = '\\u2212';\nconst minus = (s: string): string => s.replace(/[-\\u2212]/g, MINUS);\n/** Text for the clipboard: 「−」 back to the hyphen 「-」, which spreadsheets and scripts parse as a minus sign. */\nexport const plainMinus = (s: string): string => s.replace(/\\u2212/g, '-');\n\n/** Decimals by unit: money 0, percent 1, size 1, count 0; pass a number to force it. */\nfunction number(v: number, dec?: Decimals): string {\n const dd = typeof dec === 'number' ? dec : dec ? DECIMALS[dec] : 0;\n return minus(new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dd, maximumFractionDigits: dd }).format(v));\n}\n\nfunction percent(v: number, dec = 1): string {\n return minus(new Intl.NumberFormat(I18N.locale, { style: 'percent', minimumFractionDigits: dec, maximumFractionDigits: dec }).format(v / 100));\n}\n\n/** Only KPI cards abbreviate: 1,284 萬 in zh-TW (萬、億), 12.8M in English.\n * like: format v with the unit and decimals that `like` gets, so a counting KPI keeps its width. */\nfunction compact(v: number, like?: number): string {\n const ref = like ?? v;\n if (Math.abs(ref) < 1e4) return number(v);\n if (/^zh/i.test(I18N.locale)) {\n const a = Math.abs(ref);\n // 99,999,999 rounds to 10,000.0 萬: write it as 1 億.\n const [unit, div, maxDec] = Math.round(a / 1e3) >= 1e5 ? (['億', 1e8, 2] as const) : (['萬', 1e4, 1] as const);\n const finalStr = new Intl.NumberFormat(I18N.locale, { maximumFractionDigits: maxDec }).format(a / div);\n const sign = v < 0 ? MINUS : '';\n if (like === undefined) return `${sign}${finalStr}\\u00a0${unit}`;\n const digits = (finalStr.split('.')[1] || '').length;\n return `${sign}${new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Math.abs(v) / div)}\\u00a0${unit}`;\n }\n const nf = new Intl.NumberFormat(I18N.locale, { notation: 'compact', maximumFractionDigits: 1 });\n if (like === undefined) return minus(nf.format(v));\n const parts = nf.formatToParts(ref);\n let num = '';\n let dec = '';\n for (const pt of parts) {\n if (pt.type === 'integer') num += pt.value;\n if (pt.type === 'fraction') {\n num += '.' + pt.value;\n dec = pt.value;\n }\n }\n const mant = parseFloat(num) || 1;\n const scale = 10 ** Math.round(Math.log10(Math.abs(ref) / mant));\n const inner = new Intl.NumberFormat(I18N.locale, { minimumFractionDigits: dec.length, maximumFractionDigits: dec.length }).format(Math.abs(v) / scale);\n let done = false;\n const body = parts\n .map((pt) => {\n if (pt.type === 'integer' || pt.type === 'group' || pt.type === 'decimal' || pt.type === 'fraction') {\n if (done) return '';\n done = true;\n return inner;\n }\n return pt.value;\n })\n .join('');\n return minus((v < 0 && ref >= 0 ? '-' : '') + body);\n}\n\n/** zh-TW with TWD: NT$ 1,280 (a no-break space after NT$), negatives −NT$ 1,280 (U+2212). Other locales and currencies: Intl's own symbol and order. */\nfunction money(v: number, o: { currency?: string; compact?: boolean; like?: number } = {}): string {\n const cur = o.currency || I18N.currency;\n const body = o.compact ? compact(Math.abs(v), o.like !== undefined ? Math.abs(o.like) : undefined) : number(Math.abs(v), 'money');\n if (isZhTW() && cur === 'TWD') return `${v < 0 ? MINUS : ''}NT$\\u00a0${body}`;\n if (o.compact) return `${v < 0 ? MINUS : ''}${body}\\u00a0${cur}`;\n return minus(\n new Intl.NumberFormat(I18N.locale, {\n style: 'currency',\n currency: cur,\n // narrowSymbol writes TWD as a bare 「$」, which reads as dollars: keep 「NT$」 (docs: 英文介面顯示 NT$486,000).\n currencyDisplay: cur === 'TWD' ? 'symbol' : 'narrowSymbol',\n minimumFractionDigits: 0,\n maximumFractionDigits: cur === 'TWD' || cur === 'JPY' ? 0 : 2,\n }).format(v),\n );\n}\n\n/** Bytes to 「186 KB」「54.9 MB」「1.2 GB」, with a no-break space (U+00A0) so the unit never wraps away. */\nexport function fileSize(b: number | null | undefined): string {\n if (b == null || Number.isNaN(b)) return '';\n // An empty file is 0 KB; anything else at least 1 KB.\n // Compare after rounding: 1,048,500 bytes rounds to 1,024 KB, so it is written 「1.0 MB」.\n if (Math.round(b / 1024) < 1024) return number(b === 0 ? 0 : Math.max(1, Math.round(b / 1024))) + '\\u00a0KB';\n if (Math.round((b / 1048576) * 10) < 10240) return number(b / 1048576, 1) + '\\u00a0MB';\n return number(b / 1073741824, 1) + '\\u00a0GB';\n}\n\n/** Seconds as a clock-style length: under 1 h 「46:42」「1:30」 (minutes not zero-padded), 1 h or more 「1:54:49」.\n * Rounded to the second. Negative, NaN or missing: 「—」. */\nfunction duration(seconds: number | null | undefined): string {\n if (seconds == null || Number.isNaN(seconds) || seconds < 0 || !Number.isFinite(seconds)) return '—';\n const t = Math.round(seconds);\n const h = Math.floor(t / 3600);\n const m = Math.floor((t % 3600) / 60);\n const s = t % 60;\n return h ? `${h}:${pad2(m)}:${pad2(s)}` : `${m}:${pad2(s)}`;\n}\n\n/** Shortens a path: keeps the first segment and the last two, 「src/…/hooks/ops.c:58」. */\nfunction path(p: string | null | undefined, o: { head?: number; tail?: number } = {}): string {\n const head = o.head ?? 1;\n const tail = o.tail ?? 2;\n const parts = String(p ?? '').split('/');\n return parts.length > head + tail ? `${parts.slice(0, head).join('/')}/…/${parts.slice(-tail).join('/')}` : String(p ?? '');\n}\n\n/** A part of a whole, as shown: 「1 / 1 個」「6 / 6 筆」, or 「1 / 5」 without a unit. Give screen readers\n * `fractionLabel` with it: they read the slash as 「斜線」. */\nfunction fraction(n: number, total: number, unit?: string): string {\n return tr(unit ? '{n} / {total} {unit}' : '{n} / {total}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** The same fraction as read aloud: 「1 個中的 1 個」「6 筆中的 6 筆」, or 「5 中的 1」 without a unit (English:\n * 「1 of 1」). For `aria-label`, or for visually hidden text beside the shown fraction. */\nfunction fractionLabel(n: number, total: number, unit?: string): string {\n return tr(unit ? '{total} {unit}中的 {n} {unit}' : '{total} 中的 {n}', { n: number(n), total: number(total), unit: unit ?? '' });\n}\n\n/** Every date, number, amount, size and path shown in the UI goes through these. */\nexport const format = {\n locale,\n date,\n time,\n dateTime,\n relative,\n month,\n weekdays,\n firstDay,\n number,\n percent,\n compact,\n money,\n fileSize,\n duration,\n path,\n fraction,\n fractionLabel,\n};\n\n/* Calendar helpers (local dates, no time). */\nexport const fmtDate = (d: Date | null | undefined): string => (d ? `${d.getFullYear()}/${pad2(d.getMonth() + 1)}/${pad2(d.getDate())}` : '');\n\nexport function parseDate(s: string | null | undefined): Date | null {\n const m = /^(\\d{4})\\/(\\d{1,2})\\/(\\d{1,2})$/.exec(s || '');\n if (!m) return null;\n const d = new Date(+m[1], +m[2] - 1, +m[3]);\n return d.getMonth() === +m[2] - 1 ? d : null;\n}\n\nexport const sameDay = (a: Date | null | undefined, b: Date | null | undefined): boolean =>\n !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n\nexport const dayAdd = (d: Date, n: number): Date => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);\n"],"mappings":";;AAOA,MAAM,WAAW;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;CAAG,OAAO;AAAE;AAE3D,MAAM,QAAQ,MAAsB,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;AAE7D,SAAS,SAAiB;CACxB,OAAO,KAAK;AACd;;AAGA,SAAS,KAAK,GAA4B,IAA2C,CAAC,GAAW;CAC/F,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,KAAK,EAAE,YAAY;CACzB,IAAI,EAAE,MAAM,OAAO,IAAI,KAAK,eAAe,KAAK,QAAQ;EAAE,MAAM;EAAW,OAAO;EAAQ,KAAK;EAAW,SAAS,KAAK,SAAS,KAAA;CAAU,CAAC,CAAC,CAAC,OAAO,CAAC;CACtJ,IAAI,OAAO,GAAG,OAAO,QAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,eAAe,SAAS,EAAE,SAAS,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK;CACnH,OAAO,IAAI,KAAK,eAAe,KAAK,QAAQ;EAAE,MAAM;EAAW,OAAO;EAAW,KAAK;EAAW,SAAS,KAAK,UAAU,KAAA;CAAU,CAAC,CAAC,CAAC,OAAO,CAAC;AAChJ;;AAGA,SAAS,KAAK,GAAoC;CAChD,IAAI,CAAC,GAAG,OAAO;CACf,OAAO,IAAI,KAAK,eACd,KAAK,QACL,OAAO,IAAI;EAAE,MAAM;EAAW,QAAQ;EAAW,WAAW;CAAM,IAAI;E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AAE,GAAG,KAAK,EAAE,SAAS,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,CAAC,MAAM;AAE1I,SAAgB,UAAU,GAA2C;CACnE,MAAM,IAAI,kCAAkC,KAAK,KAAK,EAAE;CACxD,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;CAC1C,OAAO,EAAE,SAAS,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI;AAC1C;AAEA,MAAa,WAAW,GAA4B,MAClD,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,MAAM,EAAE,YAAY,KAAK,EAAE,SAAS,MAAM,EAAE,SAAS,KAAK,EAAE,QAAQ,MAAM,EAAE,QAAQ;AAElH,MAAa,UAAU,GAAS,MAAoB,IAAI,KAAK,EAAE,YAAY,GAAG,EAAE,SAAS,GAAG,EAAE,QAAQ,IAAI,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Decimals, format } from "./format.js";
1
+ import { Decimals, format, plainMinus } from "./format.js";
2
2
  import { AppShell, AppShellProps } from "./components/AppShell/AppShell.js";
3
3
  import { IconName } from "./icons/names.js";
4
4
  import { Grid, GridProps, GridRatio, Page, PageProps } from "./components/Grid/Grid.js";
@@ -94,4 +94,4 @@ import { MOTION } from "./motion.js";
94
94
  import { ThemeSetting, divergeToken, heatToken, initTheme, pickedAccent, resetAccent, setAccent, setTheme, storedAccent, storedTheme, textOn, themePreset, themeScript } from "./theme.js";
95
95
  import { announce } from "./announce.js";
96
96
  import { Workbench, WorkbenchApi, WorkbenchHandle, WorkbenchLayout, WorkbenchProps, WorkbenchRegion, WorkbenchView, useWorkbench } from "./components/Workbench/Workbench.js";
97
- export { AccentPicker, type AccentPickerProps, ActionBar, type ActionBarAction, type ActionBarProps, AiMark, type AiMarkProps, Alert, type AlertProps, type AlertTone, AppShell, type AppShellProps, Badge, type BadgePreset, type BadgeProps, type BadgeStatus, type BadgeTone, BarChart, type BarChartProps, type BarDatum, Breadcrumb, type BreadcrumbItem, type BreadcrumbProps, Button, type ButtonProps, Calendar, type CalendarProps, Card, type CardProps, Checkbox, type CheckboxProps, type CodeLanguage, type CodeLink, CodeText, type CodeTextProps, CodeView, type CodeViewHandle, type CodeViewProps, CommandPalette, type CommandPaletteProps, type ConsoleExtra, ConsoleLayout, type ConsoleLayoutProps, type CountUnit, type CustomIcon, type DangerConfirm, DangerZone, type DangerZoneProps, DataTable, type DataTableColumn, type DataTableFilter, type DataTableProps, type DataTableView, DatePicker, type DatePickerProps, type DateRange, DateRangePicker, type DateRangePickerProps, type DayState, type Decimals, DetailList, type DetailListItem, type DetailListProps, Dialog, type DialogProps, Drawer, type DrawerProps, EmptyState, type EmptyStateProps, ErrorPage, type ErrorPageProps, type EventKind, EventTimeline, type EventTimelineProps, type FieldProps, type FilePicker, type FilePickerOptions, FileUpload, type FileUploadProps, type FilterOption, type FilterValue, FloorPlan, type FloorPlanEdge, type FloorPlanGroup, type FloorPlanProps, type FloorPlanView, type FloorPlanZone, type FormErrors, FormGrid, type FormGridProps, GraphDefs, GraphLegend, type GraphLegendItem, type GraphLegendProps, Grid, type GridProps, type GridRatio, Icon, IconButton, type IconButtonHint, type IconButtonProps, type IconName, type IconProps, type IconSource, InlineCode, type InlineCodeProps, KpiCard, type KpiCardProps, LayerGraph, type LayerGraphEdge, type LayerGraphNode, type LayerGraphProps, type LineBand, LineChart, type LineChartProps, type LineSeries, type LineThreshold, Link, type LinkProps, LoadingBar, type LoadingBarProps, LocaleProvider, type LocaleProviderProps, LoginCard, type LoginCardProps, MOTION, Markdown, type MarkdownProps, Menu, type MenuItem, type MenuProps, Meter, type MeterProps, type MobileTab, MobileTabBar, type MobileTabBarProps, type MultiPolygon, MultiSelect, type MultiSelectOption, type MultiSelectProps, type NavBrand, type NavItem, type NavSection, NotificationBell, type NotificationBellProps, type NotificationItem, type OnRef, type OpenChangeReason, type OpenStateProps, Page, PageHeader, type PageHeaderAction, type PageHeaderProps, type PageProps, type PaletteItem, type PaletteKind, Popover, type PopoverProps, ProgressBar, type ProgressBarProps, ProgressRing, type ProgressRingProps, type ProjectOption, type ProjectStatus, ProjectSwitcher, type ProjectSwitcherProps, RadioGroup, type RadioGroupProps, type RadioOption, type RangeValue, type RefHref, RelativeTime, type RelativeTimeProps, type Row, type RowKey, SearchField, type SearchFieldProps, Section, SectionGroup, type SectionGroupProps, SectionGroupToggle, type SectionGroupToggleProps, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedItem, type SegmentedOption, Select, type SelectOption, type SelectProps, type SettingsCategory, SettingsLayout, type SettingsLayoutProps, SettingsRow, type SettingsRowProps, SettingsSection, type SettingsSectionProps, SideNav, type SideNavProps, Skeleton, type SkeletonProps, SplitPane, type SplitPaneProps, StatusBand, type StatusBandProps, StatusLegend, type StatusSegment, Suggestion, type SuggestionProps, Switch, type SwitchProps, TOAST_DURATION, type TabItem, Tabs, type TabsProps, Tag, type TagProps, Term, type TermDef, type TermProps, type TermsMark, TextArea, type TextAreaProps, TextField, type TextFieldProps, ThemePicker, type ThemePickerProps, type ThemePreset, type ThemeSetting, TimeControl, type TimeControlProps, type TimelineEvent, type TimelineKind, Toast, type ToastAction, type ToastOptions, type ToastProps, type ToastTone, Toaster, type ToasterProps, type Token, type TokenClass, type Tokenizer, Tooltip, type TooltipProps, TopBar, type TopBarProps, type Total, Tour, type TourProps, type TourStep, TreeList, type TreeListProps, type TreeMark, type TreeNode, type UploadFile, type UseFormErrors, Workbench, type WorkbenchApi, type WorkbenchHandle, type WorkbenchLayout, type WorkbenchProps, type WorkbenchRegion, type WorkbenchView, type Zone, ZoneMap, type ZoneMapProps, addMessages, announce, consoleZoom, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, pickedAccent, preloadIcons, resetAccent, safeHref, setAccent, setLocale, setTheme, storedAccent, storedTheme, subscribeLocale, tr as t, textOn, themePreset, themeScript, toast, useFilePicker, useFormErrors, useLocale, useToast, useTour, useWorkbench };
97
+ export { AccentPicker, type AccentPickerProps, ActionBar, type ActionBarAction, type ActionBarProps, AiMark, type AiMarkProps, Alert, type AlertProps, type AlertTone, AppShell, type AppShellProps, Badge, type BadgePreset, type BadgeProps, type BadgeStatus, type BadgeTone, BarChart, type BarChartProps, type BarDatum, Breadcrumb, type BreadcrumbItem, type BreadcrumbProps, Button, type ButtonProps, Calendar, type CalendarProps, Card, type CardProps, Checkbox, type CheckboxProps, type CodeLanguage, type CodeLink, CodeText, type CodeTextProps, CodeView, type CodeViewHandle, type CodeViewProps, CommandPalette, type CommandPaletteProps, type ConsoleExtra, ConsoleLayout, type ConsoleLayoutProps, type CountUnit, type CustomIcon, type DangerConfirm, DangerZone, type DangerZoneProps, DataTable, type DataTableColumn, type DataTableFilter, type DataTableProps, type DataTableView, DatePicker, type DatePickerProps, type DateRange, DateRangePicker, type DateRangePickerProps, type DayState, type Decimals, DetailList, type DetailListItem, type DetailListProps, Dialog, type DialogProps, Drawer, type DrawerProps, EmptyState, type EmptyStateProps, ErrorPage, type ErrorPageProps, type EventKind, EventTimeline, type EventTimelineProps, type FieldProps, type FilePicker, type FilePickerOptions, FileUpload, type FileUploadProps, type FilterOption, type FilterValue, FloorPlan, type FloorPlanEdge, type FloorPlanGroup, type FloorPlanProps, type FloorPlanView, type FloorPlanZone, type FormErrors, FormGrid, type FormGridProps, GraphDefs, GraphLegend, type GraphLegendItem, type GraphLegendProps, Grid, type GridProps, type GridRatio, Icon, IconButton, type IconButtonHint, type IconButtonProps, type IconName, type IconProps, type IconSource, InlineCode, type InlineCodeProps, KpiCard, type KpiCardProps, LayerGraph, type LayerGraphEdge, type LayerGraphNode, type LayerGraphProps, type LineBand, LineChart, type LineChartProps, type LineSeries, type LineThreshold, Link, type LinkProps, LoadingBar, type LoadingBarProps, LocaleProvider, type LocaleProviderProps, LoginCard, type LoginCardProps, MOTION, Markdown, type MarkdownProps, Menu, type MenuItem, type MenuProps, Meter, type MeterProps, type MobileTab, MobileTabBar, type MobileTabBarProps, type MultiPolygon, MultiSelect, type MultiSelectOption, type MultiSelectProps, type NavBrand, type NavItem, type NavSection, NotificationBell, type NotificationBellProps, type NotificationItem, type OnRef, type OpenChangeReason, type OpenStateProps, Page, PageHeader, type PageHeaderAction, type PageHeaderProps, type PageProps, type PaletteItem, type PaletteKind, Popover, type PopoverProps, ProgressBar, type ProgressBarProps, ProgressRing, type ProgressRingProps, type ProjectOption, type ProjectStatus, ProjectSwitcher, type ProjectSwitcherProps, RadioGroup, type RadioGroupProps, type RadioOption, type RangeValue, type RefHref, RelativeTime, type RelativeTimeProps, type Row, type RowKey, SearchField, type SearchFieldProps, Section, SectionGroup, type SectionGroupProps, SectionGroupToggle, type SectionGroupToggleProps, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedItem, type SegmentedOption, Select, type SelectOption, type SelectProps, type SettingsCategory, SettingsLayout, type SettingsLayoutProps, SettingsRow, type SettingsRowProps, SettingsSection, type SettingsSectionProps, SideNav, type SideNavProps, Skeleton, type SkeletonProps, SplitPane, type SplitPaneProps, StatusBand, type StatusBandProps, StatusLegend, type StatusSegment, Suggestion, type SuggestionProps, Switch, type SwitchProps, TOAST_DURATION, type TabItem, Tabs, type TabsProps, Tag, type TagProps, Term, type TermDef, type TermProps, type TermsMark, TextArea, type TextAreaProps, TextField, type TextFieldProps, ThemePicker, type ThemePickerProps, type ThemePreset, type ThemeSetting, TimeControl, type TimeControlProps, type TimelineEvent, type TimelineKind, Toast, type ToastAction, type ToastOptions, type ToastProps, type ToastTone, Toaster, type ToasterProps, type Token, type TokenClass, type Tokenizer, Tooltip, type TooltipProps, TopBar, type TopBarProps, type Total, Tour, type TourProps, type TourStep, TreeList, type TreeListProps, type TreeMark, type TreeNode, type UploadFile, type UseFormErrors, Workbench, type WorkbenchApi, type WorkbenchHandle, type WorkbenchLayout, type WorkbenchProps, type WorkbenchRegion, type WorkbenchView, type Zone, ZoneMap, type ZoneMapProps, addMessages, announce, consoleZoom, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, pickedAccent, plainMinus, preloadIcons, resetAccent, safeHref, setAccent, setLocale, setTheme, storedAccent, storedTheme, subscribeLocale, tr as t, textOn, themePreset, themeScript, toast, useFilePicker, useFormErrors, useLocale, useToast, useTour, useWorkbench };
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ import { SplitPane } from "./components/SplitPane/SplitPane.js";
24
24
  import { Drawer } from "./components/Drawer/Drawer.js";
25
25
  import { EmptyState } from "./components/EmptyState/EmptyState.js";
26
26
  import { ErrorPage } from "./components/ErrorPage/ErrorPage.js";
27
- import { format } from "./format.js";
27
+ import { format, plainMinus } from "./format.js";
28
28
  import { FileUpload } from "./components/FileUpload/FileUpload.js";
29
29
  import { useFilePicker } from "./components/FileUpload/useFilePicker.js";
30
30
  import { FormGrid } from "./components/FormGrid/FormGrid.js";
@@ -88,4 +88,4 @@ import { MOTION } from "./motion.js";
88
88
  import { divergeToken, heatToken, initTheme, pickedAccent, resetAccent, setAccent, setTheme, storedAccent, storedTheme, textOn, themePreset, themeScript } from "./theme.js";
89
89
  import { announce } from "./announce.js";
90
90
  import { Workbench, useWorkbench } from "./components/Workbench/Workbench.js";
91
- export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, ConsoleLayout, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, EventTimeline, FileUpload, FloorPlan, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, Link, LoadingBar, LocaleProvider, LoginCard, MOTION, Markdown, Menu, Meter, MobileTabBar, MultiSelect, NotificationBell, Page, PageHeader, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, RelativeTime, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsRow, SettingsSection, SideNav, Skeleton, SplitPane, StatusBand, StatusLegend, Suggestion, Switch, TOAST_DURATION, Tabs, Tag, Term, TextArea, TextField, ThemePicker, TimeControl, Toast, Toaster, Tooltip, TopBar, Tour, TreeList, Workbench, ZoneMap, addMessages, announce, consoleZoom, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, pickedAccent, preloadIcons, resetAccent, safeHref, setAccent, setLocale, setTheme, storedAccent, storedTheme, subscribeLocale, tr as t, textOn, themePreset, themeScript, toast, useFilePicker, useFormErrors, useLocale, useToast, useTour, useWorkbench };
91
+ export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, ConsoleLayout, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, EventTimeline, FileUpload, FloorPlan, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, Link, LoadingBar, LocaleProvider, LoginCard, MOTION, Markdown, Menu, Meter, MobileTabBar, MultiSelect, NotificationBell, Page, PageHeader, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, RelativeTime, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsRow, SettingsSection, SideNav, Skeleton, SplitPane, StatusBand, StatusLegend, Suggestion, Switch, TOAST_DURATION, Tabs, Tag, Term, TextArea, TextField, ThemePicker, TimeControl, Toast, Toaster, Tooltip, TopBar, Tour, TreeList, Workbench, ZoneMap, addMessages, announce, consoleZoom, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, pickedAccent, plainMinus, preloadIcons, resetAccent, safeHref, setAccent, setLocale, setTheme, storedAccent, storedTheme, subscribeLocale, tr as t, textOn, themePreset, themeScript, toast, useFilePicker, useFormErrors, useLocale, useToast, useTour, useWorkbench };
@@ -1 +1 @@
1
- {"version":3,"file":"tableTools.js","names":["phCopy","phCornersOut"],"sources":["../../src/internal/tableTools.tsx"],"sourcesContent":["import * as React from 'react';\nimport { tr } from '../i18n';\nimport { CHECK } from '../icons/Icon';\nimport { Dialog } from '../components/Dialog/Dialog';\nimport { IconButton } from '../components/IconButton/IconButton';\nimport { announce } from '../announce';\nimport { copyText, cx } from './util';\nimport { includeIcons } from '../icons/store';\nimport phCopy from '../icons/ph/copy';\nimport phCornersOut from '../icons/ph/corners-out';\n\nincludeIcons(phCopy, phCornersOut);\n\n/* What Markdown tables and DataTable share: the column border that drags, the 「放大表格」 dialog, and the\n 「複製成 Markdown」 icon. One implementation, so both tables behave and look the same. */\n\n/** The narrowest a dragged column gets (px); a DataTable column also never gets narrower than its heading. */\nexport const MIN_COL = 48;\n/** One ← or → on a column border (px). */\nexport const COL_STEP = 16;\n\n/** The right border of a header cell, dragged to set the column's width. ← → 16 px, Enter or a double-click back\n * to the widths by content. A click without dragging (one pointer, WCAG 2.5.7) steps the width up: 1.5 times, twice,\n * then back to the width by content. Hidden on touch screens (CSS), where 「放大表格」 shows the whole table instead. */\nexport function ColResize(p: {\n /** The column's name: the border is called 「調整「名稱」欄寬」. */\n name: string;\n /** Its width now (px), for aria-valuenow. */\n width: number;\n /** The narrowest it may get (px). */\n min?: number;\n /** The width when a drag or a key starts: the set width, or the drawn one. */\n start: () => number;\n /** A new width (px), from a drag, a key or a click. */\n onWidth: (px: number) => void;\n /** Back to the width by content (Enter, a double-click, the last click step). */\n onReset: () => void;\n /** A drag starts (true) or ends (false). */\n onDragging?: (on: boolean) => void;\n}) {\n const [on, setOn] = React.useState(false);\n const from = React.useRef<{ x: number; w: number; moved: boolean } | null>(null);\n // The click steps: the width they started from and the last one set, so a drag or a key in between starts over.\n const steps = React.useRef<{ base: number; n: number; last: number } | null>(null);\n const min = p.min ?? MIN_COL;\n const set = (w: number) => p.onWidth(Math.max(min, Math.round(w)));\n const drag = (v: boolean) => {\n setOn(v);\n p.onDragging?.(v);\n };\n const step = () => {\n const cur = steps.current && Math.abs(steps.current.last - p.width) <= 1 ? steps.current : { base: p.start(), n: 0, last: -1 };\n const n = cur.n + 1;\n if (n >= STEPS.length + 1) {\n steps.current = null;\n p.onReset();\n announce(tr('已還原「{name}」欄寬', { name: p.name }));\n return;\n }\n const w = Math.max(min, Math.round(cur.base * STEPS[n - 1]));\n steps.current = { base: cur.base, n, last: w };\n p.onWidth(w);\n announce(tr('「{name}」欄寬 {n} px', { name: p.name, n: w }));\n };\n return (\n <span\n className={cx('ui-col-resize', on && 'is-dragging')}\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={tr('調整「{name}」欄寬', { name: p.name })}\n aria-description={tr('拖曳或按 ← → 調整;按一下依序加寬,按 Enter 還原')}\n aria-valuenow={Math.round(p.width)}\n aria-valuemin={min}\n tabIndex={0}\n onClick={(e) => e.stopPropagation()}\n onPointerDown={(e) => {\n if (e.button !== 0) return;\n e.preventDefault();\n e.stopPropagation();\n e.currentTarget.setPointerCapture?.(e.pointerId);\n from.current = { x: e.clientX, w: p.start(), moved: false };\n drag(true);\n }}\n onPointerMove={(e) => {\n const f = from.current;\n if (!f) return;\n // A few px of jitter in a click is not a drag.\n if (!f.moved && Math.abs(e.clientX - f.x) < DRAG_MIN) return;\n f.moved = true;\n steps.current = null;\n set(f.w + e.clientX - f.x);\n }}\n onPointerUp={() => {\n const clicked = from.current && !from.current.moved;\n from.current = null;\n drag(false);\n if (clicked) step();\n }}\n onPointerCancel={() => {\n from.current = null;\n drag(false);\n }}\n onDoubleClick={(e) => {\n e.stopPropagation();\n steps.current = null;\n p.onReset();\n }}\n onKeyDown={(e) => {\n if (e.altKey || e.metaKey || e.ctrlKey) return;\n if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {\n e.preventDefault();\n e.stopPropagation();\n steps.current = null;\n set(p.start() + (e.key === 'ArrowRight' ? COL_STEP : -COL_STEP));\n } else if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n steps.current = null;\n p.onReset();\n }\n }}\n />\n );\n}\n\n// A click on a column border: the width it started from times these, then back to the width by content.\nconst STEPS = [1.5, 2];\n// A pointer that moves less than this (px) between down and up clicked.\nconst DRAG_MIN = 4;\n\n/** The 「放大表格」 icon: 32 px, no border, at a Markdown table's top right; in a DataTable's toolbar (inToolbar) it is a\n * toolbar button like 「複製成 Markdown」. */\nexport function ZoomButton({ onClick, inToolbar }: { onClick: () => void; inToolbar?: boolean }) {\n return <IconButton className={inToolbar ? 'ui-dt-zoombtn' : 'ui-table-zoom'} icon=\"corners-out\" label={tr('放大表格')} onClick={onClick} />;\n}\n\n/** The whole table in a wide dialog (at most 1200 px). A plain click on a link inside (a function, a path) closes the\n * dialog after the link has done its job; Ctrl, ⌘, Shift or the middle button open a new tab and keep it open. */\nexport function TableDialog(p: { open: boolean; onClose: () => void; title?: string; children: React.ReactNode }) {\n if (!p.open) return null;\n return (\n <Dialog open onOpenChange={(o) => !o && p.onClose()} title={p.title || tr('表格')} className=\"ui-table-dialog\">\n <div\n className=\"ui-table-dialog-body\"\n onClick={(e) => {\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;\n const link = (e.target as Element).closest('a[href], [role=\"link\"], .ui-code.is-link, .ui-md-link');\n if (link && e.currentTarget.contains(link)) p.onClose();\n }}\n >\n {p.children}\n </div>\n </Dialog>\n );\n}\n\n/** The 「複製成 Markdown」 icon: copies the text, turns into a check for 2 s and says 「已複製」, as CodeView's copy. */\nexport function CopyMarkdownButton(p: { text: () => string; onCopyError?: () => void; className?: string }) {\n const [done, setDone] = React.useState(false);\n const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n return (\n <IconButton\n className={cx('ui-table-copy', done && 'is-copied', p.className)}\n icon={done ? CHECK : 'copy'}\n label={done ? tr('已複製') : tr('複製成 Markdown')}\n onClick={() =>\n copyText(p.text()).then(\n () => {\n setDone(true);\n announce(tr('已複製'));\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setDone(false), 2000);\n },\n () => p.onCopyError?.(),\n )\n }\n />\n );\n}\n\n/** A table as GitHub Markdown: | in a cell is escaped, line breaks become spaces. */\nexport function markdownTable(heads: string[], rows: string[][]): string {\n const cell = (s: string) => s.replace(/\\r?\\n/g, ' ').replace(/\\|/g, '\\\\|').trim();\n return [`| ${heads.map(cell).join(' | ')} |`, `|${heads.map(() => '---').join('|')}|`, ...rows.map((r) => `| ${r.map(cell).join(' | ')} |`)].join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;AAWA,aAAaA,cAAQC,mBAAY;;;;AAajC,SAAgB,UAAU,GAevB;CACD,MAAM,CAAC,IAAI,SAAS,MAAM,SAAS,KAAK;CACxC,MAAM,OAAO,MAAM,OAAwD,IAAI;CAE/E,MAAM,QAAQ,MAAM,OAAyD,IAAI;CACjF,MAAM,MAAM,EAAE,OAAA;CACd,MAAM,OAAO,MAAc,EAAE,QAAQ,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC;CACjE,MAAM,QAAQ,MAAe;EAC3B,MAAM,CAAC;EACP,EAAE,aAAa,CAAC;CAClB;CACA,MAAM,aAAa;EACjB,MAAM,MAAM,MAAM,WAAW,KAAK,IAAI,MAAM,QAAQ,OAAO,EAAE,KAAK,KAAK,IAAI,MAAM,UAAU;GAAE,MAAM,EAAE,MAAM;GAAG,GAAG;GAAG,MAAM;EAAG;EAC7H,MAAM,IAAI,IAAI,IAAI;EAClB,IAAI,KAAK,MAAM,SAAS,GAAG;GACzB,MAAM,UAAU;GAChB,EAAE,QAAQ;GACV,SAAS,GAAG,iBAAiB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;GAC9C;EACF;EACA,MAAM,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,IAAI,OAAO,MAAM,IAAI,EAAE,CAAC;EAC3D,MAAM,UAAU;GAAE,MAAM,IAAI;GAAM;GAAG,MAAM;EAAE;EAC7C,EAAE,QAAQ,CAAC;EACX,SAAS,GAA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K,KAAK,EAAE,GAAG;CAAC,CAAC,CAAC,KAAK,IAAI;AACxJ"}
1
+ {"version":3,"file":"tableTools.js","names":["phCopy","phCornersOut"],"sources":["../../src/internal/tableTools.tsx"],"sourcesContent":["import * as React from 'react';\nimport { tr } from '../i18n';\nimport { CHECK } from '../icons/Icon';\nimport { Dialog } from '../components/Dialog/Dialog';\nimport { IconButton } from '../components/IconButton/IconButton';\nimport { announce } from '../announce';\nimport { copyText, cx } from './util';\nimport { plainMinus } from '../format';\nimport { includeIcons } from '../icons/store';\nimport phCopy from '../icons/ph/copy';\nimport phCornersOut from '../icons/ph/corners-out';\n\nincludeIcons(phCopy, phCornersOut);\n\n/* What Markdown tables and DataTable share: the column border that drags, the 「放大表格」 dialog, and the\n 「複製成 Markdown」 icon. One implementation, so both tables behave and look the same. */\n\n/** The narrowest a dragged column gets (px); a DataTable column also never gets narrower than its heading. */\nexport const MIN_COL = 48;\n/** One ← or → on a column border (px). */\nexport const COL_STEP = 16;\n\n/** The right border of a header cell, dragged to set the column's width. ← → 16 px, Enter or a double-click back\n * to the widths by content. A click without dragging (one pointer, WCAG 2.5.7) steps the width up: 1.5 times, twice,\n * then back to the width by content. Hidden on touch screens (CSS), where 「放大表格」 shows the whole table instead. */\nexport function ColResize(p: {\n /** The column's name: the border is called 「調整「名稱」欄寬」. */\n name: string;\n /** Its width now (px), for aria-valuenow. */\n width: number;\n /** The narrowest it may get (px). */\n min?: number;\n /** The width when a drag or a key starts: the set width, or the drawn one. */\n start: () => number;\n /** A new width (px), from a drag, a key or a click. */\n onWidth: (px: number) => void;\n /** Back to the width by content (Enter, a double-click, the last click step). */\n onReset: () => void;\n /** A drag starts (true) or ends (false). */\n onDragging?: (on: boolean) => void;\n}) {\n const [on, setOn] = React.useState(false);\n const from = React.useRef<{ x: number; w: number; moved: boolean } | null>(null);\n // The click steps: the width they started from and the last one set, so a drag or a key in between starts over.\n const steps = React.useRef<{ base: number; n: number; last: number } | null>(null);\n const min = p.min ?? MIN_COL;\n const set = (w: number) => p.onWidth(Math.max(min, Math.round(w)));\n const drag = (v: boolean) => {\n setOn(v);\n p.onDragging?.(v);\n };\n const step = () => {\n const cur = steps.current && Math.abs(steps.current.last - p.width) <= 1 ? steps.current : { base: p.start(), n: 0, last: -1 };\n const n = cur.n + 1;\n if (n >= STEPS.length + 1) {\n steps.current = null;\n p.onReset();\n announce(tr('已還原「{name}」欄寬', { name: p.name }));\n return;\n }\n const w = Math.max(min, Math.round(cur.base * STEPS[n - 1]));\n steps.current = { base: cur.base, n, last: w };\n p.onWidth(w);\n announce(tr('「{name}」欄寬 {n} px', { name: p.name, n: w }));\n };\n return (\n <span\n className={cx('ui-col-resize', on && 'is-dragging')}\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={tr('調整「{name}」欄寬', { name: p.name })}\n aria-description={tr('拖曳或按 ← → 調整;按一下依序加寬,按 Enter 還原')}\n aria-valuenow={Math.round(p.width)}\n aria-valuemin={min}\n tabIndex={0}\n onClick={(e) => e.stopPropagation()}\n onPointerDown={(e) => {\n if (e.button !== 0) return;\n e.preventDefault();\n e.stopPropagation();\n e.currentTarget.setPointerCapture?.(e.pointerId);\n from.current = { x: e.clientX, w: p.start(), moved: false };\n drag(true);\n }}\n onPointerMove={(e) => {\n const f = from.current;\n if (!f) return;\n // A few px of jitter in a click is not a drag.\n if (!f.moved && Math.abs(e.clientX - f.x) < DRAG_MIN) return;\n f.moved = true;\n steps.current = null;\n set(f.w + e.clientX - f.x);\n }}\n onPointerUp={() => {\n const clicked = from.current && !from.current.moved;\n from.current = null;\n drag(false);\n if (clicked) step();\n }}\n onPointerCancel={() => {\n from.current = null;\n drag(false);\n }}\n onDoubleClick={(e) => {\n e.stopPropagation();\n steps.current = null;\n p.onReset();\n }}\n onKeyDown={(e) => {\n if (e.altKey || e.metaKey || e.ctrlKey) return;\n if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {\n e.preventDefault();\n e.stopPropagation();\n steps.current = null;\n set(p.start() + (e.key === 'ArrowRight' ? COL_STEP : -COL_STEP));\n } else if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n steps.current = null;\n p.onReset();\n }\n }}\n />\n );\n}\n\n// A click on a column border: the width it started from times these, then back to the width by content.\nconst STEPS = [1.5, 2];\n// A pointer that moves less than this (px) between down and up clicked.\nconst DRAG_MIN = 4;\n\n/** The 「放大表格」 icon: 32 px, no border, at a Markdown table's top right; in a DataTable's toolbar (inToolbar) it is a\n * toolbar button like 「複製成 Markdown」. */\nexport function ZoomButton({ onClick, inToolbar }: { onClick: () => void; inToolbar?: boolean }) {\n return <IconButton className={inToolbar ? 'ui-dt-zoombtn' : 'ui-table-zoom'} icon=\"corners-out\" label={tr('放大表格')} onClick={onClick} />;\n}\n\n/** The whole table in a wide dialog (at most 1200 px). A plain click on a link inside (a function, a path) closes the\n * dialog after the link has done its job; Ctrl, ⌘, Shift or the middle button open a new tab and keep it open. */\nexport function TableDialog(p: { open: boolean; onClose: () => void; title?: string; children: React.ReactNode }) {\n if (!p.open) return null;\n return (\n <Dialog open onOpenChange={(o) => !o && p.onClose()} title={p.title || tr('表格')} className=\"ui-table-dialog\">\n <div\n className=\"ui-table-dialog-body\"\n onClick={(e) => {\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;\n const link = (e.target as Element).closest('a[href], [role=\"link\"], .ui-code.is-link, .ui-md-link');\n if (link && e.currentTarget.contains(link)) p.onClose();\n }}\n >\n {p.children}\n </div>\n </Dialog>\n );\n}\n\n/** The 「複製成 Markdown」 icon: copies the text, turns into a check for 2 s and says 「已複製」, as CodeView's copy. */\nexport function CopyMarkdownButton(p: { text: () => string; onCopyError?: () => void; className?: string }) {\n const [done, setDone] = React.useState(false);\n const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n React.useEffect(() => () => clearTimeout(timer.current), []);\n return (\n <IconButton\n className={cx('ui-table-copy', done && 'is-copied', p.className)}\n icon={done ? CHECK : 'copy'}\n label={done ? tr('已複製') : tr('複製成 Markdown')}\n onClick={() =>\n copyText(plainMinus(p.text())).then(\n () => {\n setDone(true);\n announce(tr('已複製'));\n clearTimeout(timer.current);\n timer.current = setTimeout(() => setDone(false), 2000);\n },\n () => p.onCopyError?.(),\n )\n }\n />\n );\n}\n\n/** A table as GitHub Markdown: | in a cell is escaped, line breaks become spaces. */\nexport function markdownTable(heads: string[], rows: string[][]): string {\n const cell = (s: string) => s.replace(/\\r?\\n/g, ' ').replace(/\\|/g, '\\\\|').trim();\n return [`| ${heads.map(cell).join(' | ')} |`, `|${heads.map(() => '---').join('|')}|`, ...rows.map((r) => `| ${r.map(cell).join(' | ')} |`)].join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;AAYA,aAAaA,cAAQC,mBAAY;;;;AAajC,SAAgB,UAAU,GAevB;CACD,MAAM,CAAC,IAAI,SAAS,MAAM,SAAS,KAAK;CACxC,MAAM,OAAO,MAAM,OAAwD,IAAI;CAE/E,MAAM,QAAQ,MAAM,OAAyD,IAAI;CACjF,MAAM,MAAM,EAAE,OAAA;CACd,MAAM,OAAO,MAAc,EAAE,QAAQ,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC;CACjE,MAAM,QAAQ,MAAe;EAC3B,MAAM,CAAC;EACP,EAAE,aAAa,CAAC;CAClB;CACA,MAAM,aAAa;EACjB,MAAM,MAAM,MAAM,WAAW,KAAK,IAAI,MAAM,QAAQ,OAAO,EAAE,KAAK,KAAK,IAAI,MAAM,UAAU;GAAE,MAAM,EAAE,MAAM;GAAG,GAAG;GAAG,MAAM;EAAG;EAC7H,MAAM,IAAI,IAAI,IAAI;EAClB,IAAI,KAAK,MAAM,SAAS,GAAG;GACzB,MAAM,UAAU;GAChB,EAAE,QAAQ;GACV,SAAS,GAAG,iBAAiB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;GAC9C;EACF;EACA,MAAM,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,IAAI,OAAO,MAAM,IAAI,EAAE,CAA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AAK,CAAC,CAAC,KAAK,GAAG,EAAE;EAAI,GAAG,KAAK,KAAK,MAAM,KAAK,EAAE,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,EAAE,GAAG;CAAC,CAAC,CAAC,KAAK,IAAI;AACxJ"}
package/dist/styles.css CHANGED
@@ -4590,6 +4590,12 @@ div.ui-toast[role='status'] {
4590
4590
  .ui-dt-body .ui-dt-cell.is-num {
4591
4591
  white-space: normal;
4592
4592
  }
4593
+ /* A number with a second line starts at the left like every value in the card, on its name's line: the table's
4594
+ right alignment and the stack's 6 px padding are for rows, not cards. */
4595
+ .ui-dt-body .ui-dt-cell.is-num .ui-dt-stack {
4596
+ align-items: flex-start;
4597
+ padding-block: 0;
4598
+ }
4593
4599
  .ui-dt-body .ui-dt-cell[data-label]:not(.is-m-title, .is-m-status)::before {
4594
4600
  content: attr(data-label);
4595
4601
  position: absolute;
package/docs/DataTable.md CHANGED
@@ -36,7 +36,7 @@ const columns: DataTableColumn<Import>[] = [
36
36
 
37
37
  預設就有:主要文字欄占剩下的寬度、其他欄貼合內容;一列工具列(摘要分段、搜尋、「篩選」「排序」「⋯」和 `action`,放不下時摘要自己一列);手機上變成卡片清單。
38
38
 
39
- - 清單頁的「新增」(一個 `primary`)給 `action`,在工具列最右端;Card 的 `title`、`label` 怎麼給見 guidelines 的「常見頁面」。
39
+ - 清單頁的「新增」(一個 `primary`)給 `action`,在工具列最右端;Card 的 `title`、`label` 怎麼給見 guidelines 的「常見頁面」。`action` 的字用短的動詞(「新增」,不寫「新增手動帳戶」):表格寬度小於 480 px 時工具列只有一列、不換行,長字會把按鈕擠出畫面;要說是什麼,寫在頁面標題或 `label`。
40
40
  - 主要的文字欄放第一欄:它占剩下的寬度,也是手機卡片的標題和列的名稱。每列給 `id`。
41
41
  - 數字給 `numeric: true` 加 `unit`(傳數字 `1234`,不傳 `'1,234 筆'`);金額用 `format: 'money'`;長度(秒)用 `format: 'duration'`;日期用 `format: 'date' | 'dateTime' | 'relative'`。ID、代碼、雜湊和路徑的欄位給 `mono: true`。
42
42
  - 失敗的列:原因寫在 `secondary`(第二行),「重試」放 `rowActions`,可勾選時 `bulkActions` 也放。進行中的列:`doing` 的 Badge,進度文字(「匯入中 42%」)寫在 `secondary`,格子裡不放 ProgressBar。
package/docs/Format.md CHANGED
@@ -27,7 +27,8 @@ t('已選 {n} 筆', { n: 3 });
27
27
  - 檔案大小:未滿 1 MB 寫整數 KB(「186 KB」),以上寫一位小數的 MB 或 GB(「54.9 MB」)。`UI.format.fileSize(bytes)`。
28
28
  - 數字和單位之間是不換行空格(U+00A0):`fileSize`、`compact`(萬、億)和 `money`(「NT$」後面)都是,窄畫面不會斷成「100」「MB」兩行。元件收的字串(說明、提示、事件文字)也自動把「數字 單位」之間的空格換成不換行空格;比對字串的測試用 `\u00a0`。
29
29
  - 長度(影片、錄音、工作耗時):未滿 1 小時寫 `46:42`、`1:30`(分鐘不補 0),1 小時以上寫 `1:54:49`;傳入秒數,四捨五入到秒;負數、`NaN` 或沒有值時寫「—」。`UI.format.duration(seconds)`。表格欄位用 `format: 'duration'`。
30
- - 金額:`NT$ 1,280`,負數用減號 `-NT$ 1,280`。`UI.format.money(v)`。
30
+ - 金額:`NT$ 1,280`,負數 `−NT$ 1,280`。`UI.format.money(v)`。
31
+ - 負數:所有數字格式(`number`、`percent`、`compact`、`money`)的負號都是減號「−」(U+2212),不是連字號「-」;螢幕閱讀器念「負」或「minus」。放到剪貼簿、檔案或給程式讀的文字先經過 `UI.plainMinus(text)` 換回「-」,試算表才認得是數字(DataTable 的複製和選取後複製會自己換)。
31
32
  - 小數位數依單位:金額 0 位、百分比 1 位、容量(GB、MB)1 位、數量 0 位。`UI.format.number(v, 'money' | 'percent' | 'size' | 'count')`。
32
33
  - 分數和進度:畫面上寫「1 / 1 個」「6 / 6 筆」,`UI.format.fraction(n, total, unit?)`;螢幕閱讀器會把「/」念成「斜線」,所以同時給 `UI.format.fractionLabel(n, total, unit?)`,念「1 個中的 1 個」「6 筆中的 6 筆」(沒有單位時「5 中的 1」,英文「1 of 5」)。用法:顯示的文字加 `aria-hidden="true"`,旁邊放一個 `ui-visually-hidden` 的 `fractionLabel`;或整個元素用 `aria-label={fractionLabel(...)}`。
33
34
 
package/docs/agents.md CHANGED
@@ -65,11 +65,11 @@ export default [ui.configs.recommended];
65
65
  ```html
66
66
  <meta charset="utf-8">
67
67
  <meta name="viewport" content="width=device-width, initial-scale=1">
68
- <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.51.0/fonts.css">
69
- <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.51.0/tokens.css">
70
- <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.51.0/styles.css">
68
+ <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.52.1/fonts.css">
69
+ <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.52.1/tokens.css">
70
+ <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.52.1/styles.css">
71
71
  <div id="root"></div>
72
- <script src="https://seanyeh77.github.io/ui-design-system/dist/0.51.0/bundle.js"></script>
72
+ <script src="https://seanyeh77.github.io/ui-design-system/dist/0.52.1/bundle.js"></script>
73
73
  <script>
74
74
  const h = React.createElement;
75
75
  UI.initTheme();
@@ -77,6 +77,6 @@ export default [ui.configs.recommended];
77
77
  </script>
78
78
  ```
79
79
 
80
- Pin a version as above: `/dist/<version>/` never changes; `/dist/` always serves the latest release. jsDelivr has the same files (`https://cdn.jsdelivr.net/npm/@seanyeh77/ui@0.51.0/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.51.0/fonts.css`). Without a bundler, `@seanyeh77/ui/dist/fonts.css` cannot resolve its import: load the tokens package's `fonts.css` or the pinned site URL.
80
+ Pin a version as above: `/dist/<version>/` never changes; `/dist/` always serves the latest release. jsDelivr has the same files (`https://cdn.jsdelivr.net/npm/@seanyeh77/ui@0.52.1/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.52.1/fonts.css`). Without a bundler, `@seanyeh77/ui/dist/fonts.css` cannot resolve its import: load the tokens package's `fonts.css` or the pinned site URL.
81
81
 
82
82
  Scope: web UI, and the tokens of SeanYeh's Slidev decks (`initTheme({ preset: 'teaching' })`, see `theme.md`). Slide layout, Notion documents and teaching diagrams follow the separate `teaching-materials-style` skill.
@@ -60,7 +60,7 @@
60
60
  ## 格式
61
61
 
62
62
  - 日期 `2026/11/04(三)`,年份一律顯示,加星期;時間 24 小時制,接在「)」後面不加空格(`2026/11/04(三)13:00`);一週內用相對時間(「2 小時前」,`RelativeTime` 會自己更新)。
63
- - 金額 `NT$ 1,280`;負數用減號;小數依單位(金額 0、百分比 1、容量 1 位);大數字只有 KPI 卡片和圖表的軸縮寫(萬、億)。
63
+ - 金額 `NT$ 1,280`;負數用減號「−」(U+2212,`−NT$ 1,280`、`−0.2 °C`,`format` 會自己換),複製出去的文字換回「-」(`plainMinus`);小數依單位(金額 0、百分比 1、容量 1 位);大數字只有 KPI 卡片和圖表的軸縮寫(萬、億)。
64
64
  - 數字是數字:表格給 `numeric` 加 `unit`、時間長度 `format: 'duration'`,不寫成「46 分」這種字串。檔案大小、時間長度用 `format.fileSize()`、`format.duration()`。
65
65
  - 日期和數字經過 `format`。介面文字直接寫繁體中文;頁面要支援好幾種語言時才經過 `t()`(和 `setLocale`、`addMessages` 一起從 `@seanyeh77/ui` 匯入)。
66
66
  - 句子裡的程式碼、路徑和 ID 用 `InlineCode`;含反引號的整段文字用 `CodeText`。元件收字串的說明、提示、錯誤和內文也把反引號裡的文字顯示成行內程式碼。路徑、行號、ID 這類指向某處的文字都是連結。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seanyeh77/ui",
3
- "version": "0.51.0",
3
+ "version": "0.52.1",
4
4
  "description": "SeanYeh's design system: typed React components on Base UI, styled with design tokens.",
5
5
  "license": "MIT",
6
6
  "author": "Hsiu-An Yeh",
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@base-ui/react": "^1.9.0",
61
- "@seanyeh77/tokens": "^0.51.0"
61
+ "@seanyeh77/tokens": "^0.52.1"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "node scripts/theme-defaults.ts && tsdown && node scripts/postbuild.ts",