@seanyeh77/ui 0.50.1 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +16 -16
- package/dist/components/DataTable/DataTable.js +8 -2
- package/dist/components/DataTable/DataTable.js.map +1 -1
- package/dist/components/FloorPlan/FloorPlan.d.ts +20 -0
- package/dist/components/FloorPlan/FloorPlan.js +79 -35
- package/dist/components/FloorPlan/FloorPlan.js.map +1 -1
- package/dist/components/ZoneMap/ZoneMap.d.ts +3 -0
- package/dist/components/ZoneMap/ZoneMap.js.map +1 -1
- package/dist/format-entry.d.ts +2 -2
- package/dist/format-entry.js +2 -2
- package/dist/format.d.ts +3 -1
- package/dist/format.js +16 -13
- package/dist/format.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/internal/tableTools.js.map +1 -1
- package/dist/internal/zone.js +13 -5
- package/dist/internal/zone.js.map +1 -1
- package/docs/FloorPlan.md +66 -7
- package/docs/Format.md +2 -1
- package/docs/ZoneMap.md +1 -0
- package/docs/agents.md +5 -5
- package/docs/guidelines.md +1 -1
- package/package.json +2 -2
package/dist/format-entry.js
CHANGED
|
@@ -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
|
|
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
|
|
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 ? "
|
|
166
|
-
if (o.compact) return `${v < 0 ? "
|
|
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
|
package/dist/format.js.map
CHANGED
|
@@ -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,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;EAAE,MAAM;EAAW,QAAQ;CAAU,CAC7G,CAAC,CAAC,OAAO,CAAC;AACZ;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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,KAA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,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";
|
|
@@ -42,7 +42,7 @@ import { LineBand, LineChart, LineChartProps, LineSeries, LineThreshold } from "
|
|
|
42
42
|
import { StatusBand, StatusBandProps, StatusLegend, StatusSegment } from "./components/StatusBand/StatusBand.js";
|
|
43
43
|
import { Meter, MeterProps } from "./components/Meter/Meter.js";
|
|
44
44
|
import { Zone, ZoneMap, ZoneMapProps } from "./components/ZoneMap/ZoneMap.js";
|
|
45
|
-
import { FloorPlan, FloorPlanEdge, FloorPlanGroup, FloorPlanProps, FloorPlanZone, MultiPolygon } from "./components/FloorPlan/FloorPlan.js";
|
|
45
|
+
import { FloorPlan, FloorPlanEdge, FloorPlanGroup, FloorPlanProps, FloorPlanView, FloorPlanZone, MultiPolygon } from "./components/FloorPlan/FloorPlan.js";
|
|
46
46
|
import { EventKind, EventTimeline, EventTimelineProps, TimelineEvent, TimelineKind } from "./components/EventTimeline/EventTimeline.js";
|
|
47
47
|
import { ConsoleExtra, ConsoleLayout, ConsoleLayoutProps } from "./components/ConsoleLayout/ConsoleLayout.js";
|
|
48
48
|
import { consoleZoom } from "./deprecated.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 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,IAA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;;AA4BA,SAAgB,cAAc,OAAiB,MAA0B;CACvE,MAAM,QAAQ,MAAc,EAAE,QAAQ,UAAU,GAAG,CAAC,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK;CAChF,OAAO;EAAC,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,EAAE;EAAK,IAAI,MAAM,UAAU,KAAK,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"}
|
|
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,E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AClG,IAAI,QAAQ,EAAE,cAAc,SAAS,IAAI,GAAG,EAAE,QAAQ;GACxD;GAEC,UAAA,EAAE;EACA,CAAA;CACC,CAAA;AAEZ;;AA4BA,SAAgB,cAAc,OAAiB,MAA0B;CACvE,MAAM,QAAQ,MAAc,EAAE,QAAQ,UAAU,GAAG,CAAC,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK;CAChF,OAAO;EAAC,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,EAAE;EAAK,IAAI,MAAM,UAAU,KAAK,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/internal/zone.js
CHANGED
|
@@ -13,24 +13,32 @@ function heatRange(zones, min, max) {
|
|
|
13
13
|
const hi = max ?? (values.length ? Math.max(...values) : 1);
|
|
14
14
|
return hi > lo ? [lo, hi] : [lo - 1, lo + 1];
|
|
15
15
|
}
|
|
16
|
+
/** A figure with its decimals; signed, a positive one gets 「+」. A value that rounds to zero has no sign (never 「-0.0」). */
|
|
17
|
+
function signedNumber(v, decimals, signed = false) {
|
|
18
|
+
const r = Number(v.toFixed(decimals));
|
|
19
|
+
const shown = r === 0 ? 0 : v;
|
|
20
|
+
return (signed && r > 0 ? "+" : "") + format.number(shown, decimals);
|
|
21
|
+
}
|
|
16
22
|
/** True when the zone has no data: a dashed outline, not selectable. */
|
|
17
23
|
const noData = (z) => z.value == null && !z.forecast;
|
|
18
24
|
/** The fill (token name or color), its CSS background, the text color for a fill that is not a data token, the state
|
|
19
|
-
* with 「⚠ 」 when it needs attention, the figure, the figure with its unit, and the accessible name
|
|
20
|
-
|
|
25
|
+
* with 「⚠ 」 when it needs attention, the figure, the figure with its unit, and the accessible name: name, figure,
|
|
26
|
+
* state, `extra`, detail, `after`. */
|
|
27
|
+
function zoneText(z, min, max, extra = [], after = []) {
|
|
21
28
|
const tone = z.tone ?? "normal";
|
|
22
29
|
const fill = z.fill ?? (z.value != null ? heatToken(z.value, min, max) : "surface-sub");
|
|
23
30
|
const bg = /^[a-z][a-z0-9-]*$/.test(fill) ? `var(--${fill})` : fill;
|
|
24
31
|
const stateWord = z.state ?? (z.forecast ? tr("預測") : tr("正常"));
|
|
25
32
|
const state = (tone === "normal" ? "" : "⚠ ") + stateWord;
|
|
26
|
-
const figure = z.value != null ?
|
|
33
|
+
const figure = z.value != null ? signedNumber(z.value, z.decimals ?? 1, z.signed) : "—";
|
|
27
34
|
const reading = figure + (z.unit ? " " + z.unit : "");
|
|
28
35
|
const label = [
|
|
29
36
|
z.name,
|
|
30
37
|
reading,
|
|
31
38
|
stateWord,
|
|
32
39
|
...extra,
|
|
33
|
-
z.detail
|
|
40
|
+
z.detail,
|
|
41
|
+
...after
|
|
34
42
|
].filter(Boolean).join(tr(","));
|
|
35
43
|
return {
|
|
36
44
|
tone,
|
|
@@ -43,6 +51,6 @@ function zoneText(z, min, max, extra = []) {
|
|
|
43
51
|
label
|
|
44
52
|
};
|
|
45
53
|
}
|
|
46
|
-
export { DATA_TOKEN, heatRange, noData, zoneText };
|
|
54
|
+
export { DATA_TOKEN, heatRange, noData, signedNumber, zoneText };
|
|
47
55
|
|
|
48
56
|
//# sourceMappingURL=zone.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zone.js","names":[],"sources":["../../src/internal/zone.ts"],"sourcesContent":["// What ZoneMap and FloorPlan share: the heat range, and a zone's fill, figure, state and accessible name.\nimport { format } from '../format';\nimport { tr } from '../i18n';\nimport { heatToken, textOn } from '../theme';\n\n/** The fields of a zone both maps read. */\ninterface ZoneText {\n name: string;\n value?: number | null;\n unit?: string;\n decimals?: number;\n fill?: string;\n tone?: 'normal' | 'warning' | 'danger';\n state?: string;\n forecast?: boolean;\n detail?: string;\n}\n\n/** Data tokens whose text color comes from CSS (it follows the theme); other fills are measured with textOn(). */\nexport const DATA_TOKEN = /^(heat-[1-7]|diverge-(neg|pos)(-strong)?|diverge-zero|chart-[1-4])$/;\n\n/** The heat range: min and max when given, else the zones' own smallest and largest value. One value alone (or all\n * equal) gets that value ± 1, so it lands in the middle of the scale. */\nexport function heatRange(zones: readonly { value?: number | null }[], min?: number, max?: number): [number, number] {\n const values = zones.map((z) => z.value).filter((v): v is number => v != null && Number.isFinite(v));\n const lo = min ?? (values.length ? Math.min(...values) : 0);\n const hi = max ?? (values.length ? Math.max(...values) : 1);\n return hi > lo ? [lo, hi] : [lo - 1, lo + 1];\n}\n\n/** True when the zone has no data: a dashed outline, not selectable. */\nexport const noData = (z: ZoneText): boolean => z.value == null && !z.forecast;\n\n/** The fill (token name or color), its CSS background, the text color for a fill that is not a data token, the state\n * with 「⚠ 」 when it needs attention, the figure, the figure with its unit, and the accessible name
|
|
1
|
+
{"version":3,"file":"zone.js","names":[],"sources":["../../src/internal/zone.ts"],"sourcesContent":["// What ZoneMap and FloorPlan share: the heat range, and a zone's fill, figure, state and accessible name.\nimport { format } from '../format';\nimport { tr } from '../i18n';\nimport { heatToken, textOn } from '../theme';\n\n/** The fields of a zone both maps read. */\ninterface ZoneText {\n name: string;\n value?: number | null;\n unit?: string;\n decimals?: number;\n signed?: boolean;\n fill?: string;\n tone?: 'normal' | 'warning' | 'danger';\n state?: string;\n forecast?: boolean;\n detail?: string;\n}\n\n/** Data tokens whose text color comes from CSS (it follows the theme); other fills are measured with textOn(). */\nexport const DATA_TOKEN = /^(heat-[1-7]|diverge-(neg|pos)(-strong)?|diverge-zero|chart-[1-4])$/;\n\n/** The heat range: min and max when given, else the zones' own smallest and largest value. One value alone (or all\n * equal) gets that value ± 1, so it lands in the middle of the scale. */\nexport function heatRange(zones: readonly { value?: number | null }[], min?: number, max?: number): [number, number] {\n const values = zones.map((z) => z.value).filter((v): v is number => v != null && Number.isFinite(v));\n const lo = min ?? (values.length ? Math.min(...values) : 0);\n const hi = max ?? (values.length ? Math.max(...values) : 1);\n return hi > lo ? [lo, hi] : [lo - 1, lo + 1];\n}\n\n/** A figure with its decimals; signed, a positive one gets 「+」. A value that rounds to zero has no sign (never 「-0.0」). */\nexport function signedNumber(v: number, decimals: number, signed = false): string {\n const r = Number(v.toFixed(decimals));\n const shown = r === 0 ? 0 : v;\n return (signed && r > 0 ? '+' : '') + format.number(shown, decimals);\n}\n\n/** True when the zone has no data: a dashed outline, not selectable. */\nexport const noData = (z: ZoneText): boolean => z.value == null && !z.forecast;\n\n/** The fill (token name or color), its CSS background, the text color for a fill that is not a data token, the state\n * with 「⚠ 」 when it needs attention, the figure, the figure with its unit, and the accessible name: name, figure,\n * state, `extra`, detail, `after`. */\nexport function zoneText(z: ZoneText, min: number, max: number, extra: string[] = [], after: string[] = []) {\n const tone = z.tone ?? 'normal';\n const fill = z.fill ?? (z.value != null ? heatToken(z.value, min, max) : 'surface-sub');\n const bg = /^[a-z][a-z0-9-]*$/.test(fill) ? `var(--${fill})` : fill;\n const stateWord = z.state ?? (z.forecast ? tr('預測') : tr('正常'));\n const state = (tone === 'normal' ? '' : '⚠ ') + stateWord;\n const figure = z.value != null ? signedNumber(z.value, z.decimals ?? 1, z.signed) : '—';\n const reading = figure + (z.unit ? ' ' + z.unit : '');\n const label = [z.name, reading, stateWord, ...extra, z.detail, ...after].filter(Boolean).join(tr(','));\n const color = DATA_TOKEN.test(fill) ? undefined : textOn(fill);\n return { tone, fill, bg, color, state, figure, reading, label };\n}\n"],"mappings":";;;;;;AAoBA,MAAa,aAAa;;;AAI1B,SAAgB,UAAU,OAA6C,KAAc,KAAgC;CACnH,MAAM,SAAS,MAAM,KAAK,MAAM,EAAE,KAAK,CAAC,CAAC,QAAQ,MAAmB,KAAK,QAAQ,OAAO,SAAS,CAAC,CAAC;CACnG,MAAM,KAAK,QAAQ,OAAO,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI;CACzD,MAAM,KAAK,QAAQ,OAAO,SAAS,KAAK,IAAI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, {
|
|
|
9
9
|
label: '機房平面圖',
|
|
10
10
|
value: sel,
|
|
11
11
|
onChange: setSel,
|
|
12
|
-
min: 20,
|
|
12
|
+
min: 20,
|
|
13
|
+
max: 30,
|
|
14
|
+
warn: 27,
|
|
15
|
+
limit: 30,
|
|
13
16
|
groups: [{ id: 'north', name: '北側機櫃列' }],
|
|
14
17
|
zones: [
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
{
|
|
19
|
+
id: 'a',
|
|
20
|
+
name: '冷通道 A',
|
|
21
|
+
value: 23.1,
|
|
22
|
+
unit: '°C',
|
|
23
|
+
outline: [
|
|
24
|
+
[
|
|
25
|
+
[
|
|
26
|
+
[2, 2],
|
|
27
|
+
[14, 2],
|
|
28
|
+
[14, 8],
|
|
29
|
+
[8, 8],
|
|
30
|
+
[8, 14],
|
|
31
|
+
[2, 14],
|
|
32
|
+
],
|
|
33
|
+
],
|
|
34
|
+
],
|
|
35
|
+
label: [5, 5],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'f',
|
|
39
|
+
name: '機櫃區 F',
|
|
40
|
+
value: 29.6,
|
|
41
|
+
unit: '°C',
|
|
42
|
+
tone: 'danger',
|
|
43
|
+
state: '超過上限',
|
|
44
|
+
group: 'north',
|
|
45
|
+
outline: [
|
|
46
|
+
[
|
|
47
|
+
[
|
|
48
|
+
[16, 17],
|
|
49
|
+
[26, 17],
|
|
50
|
+
[26, 22],
|
|
51
|
+
[16, 22],
|
|
52
|
+
],
|
|
53
|
+
],
|
|
54
|
+
],
|
|
55
|
+
label: [21, 19.5],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'e',
|
|
59
|
+
name: '走道 E',
|
|
60
|
+
value: 22.4,
|
|
61
|
+
unit: '°C',
|
|
62
|
+
emphasis: 'muted',
|
|
63
|
+
outline: [
|
|
64
|
+
[
|
|
65
|
+
[
|
|
66
|
+
[16, 14],
|
|
67
|
+
[38, 14],
|
|
68
|
+
[38, 16],
|
|
69
|
+
[16, 16],
|
|
70
|
+
],
|
|
71
|
+
],
|
|
72
|
+
],
|
|
73
|
+
label: [27, 15],
|
|
74
|
+
},
|
|
18
75
|
],
|
|
19
76
|
});
|
|
20
77
|
```
|
|
21
78
|
|
|
22
79
|
- 分區的欄位和 ZoneMap 的 `Zone` 相同(`tone`、`state`、`forecast`、`detail`、`fill`、`value: null` 是沒有資料),`area` 換成 `outline` 和 `label`。
|
|
23
80
|
- `outline` 是 MultiPolygon,單位公尺,y 向上是北:`[多邊形][環][點][x, y]`,每個多邊形的第一個環是外框,其餘是洞。元件自己翻轉 y、算出視角。
|
|
24
|
-
- `label`
|
|
81
|
+
- `label` 是標籤的位置,和 `outline` 同一個座標(公尺,y 向上),由呼叫端算好、一定要在外框裡:建議用 polylabel 算多邊形內離邊最遠的點(分成好幾塊時用面積最大的那塊)。
|
|
25
82
|
- 寬度小於 600 px 時圖很小,大部分標籤會被捨棄:旁邊附 DataTable 的清單檢視,列出同樣的分區。
|
|
26
83
|
- `warn`、`limit` 只畫在圖例上,數值由呼叫端給,元件不假設門檻。
|
|
84
|
+
- 差值(例如預測減實際)的分區加 `signed`:正數寫「+1.1 °C」,螢幕閱讀器也念出正負;四捨五入成 0 的不加符號。
|
|
27
85
|
|
|
28
86
|
## 細節
|
|
29
87
|
|
|
30
88
|
- 標籤:在分區裡放得下時寫名稱(16 px 半粗)、主數值(25 px Geist Mono,單位 16 px)和狀態(13 px 半粗);外框包圍盒長寬比大於 4 的細長分區,或完整標籤放不下時,改用一行膠囊(13 px,`surface` 底);膠囊也會和別的標籤重疊時不顯示。標籤一律同樣大小,放大後放得下的就會出現。
|
|
31
|
-
-
|
|
89
|
+
- 標籤的優先序:選取中的分區最先,接著 `labelPriority` 大的先(預設 0),再來 primary 在 muted 之前,各自面積小的先;被捨棄的分區仍然有游標提示,也在 Tab 順序裡。Tab 順序不受 `labelPriority` 和選取影響。
|
|
32
90
|
- `emphasis: 'muted'`:次要區域,填色是原色 40 % 混 `surface`,標籤 13 px 名稱加 16 px 數值,字用 `ink`;可以選,`tone` 的 4 px 內框和「⚠」照常顯示;螢幕閱讀器多念「次要」。有 muted 分區時圖例多一行「淡色=次要區域」。
|
|
33
91
|
- 填色、字色、4 px 注意內框、預測斜線、沒有資料的虛線框、數值和單位之間的空格,都和 ZoneMap 相同(見 `ui docs ZoneMap`)。
|
|
34
92
|
- 選取:`ink` 色 2 px 外框,在分區外 4 px。鍵盤焦點:`focus` 色 2 px 外框,緊貼分區外側,並顯示提示。
|
|
35
93
|
- `groups`:同一組的分區外面畫一圈 1.5 px `ink-muted` 細框(沿著整組的外形),左上角寫組名(13 px)。不計算也不顯示整組的數值。
|
|
36
94
|
- `shell`:建築外框,`surface-sub` 底加 `line-strong` 邊。`edges`:分區之間的邊界,1.5 px `ink-muted` 虛線。
|
|
95
|
+
- 視角:`defaultView`(`{ x, y, zoom }`,中心點的公尺座標,y 向上;`zoom` 1 是全景,最多 8)是一開始的視角;`onViewChange(view)` 在視角停下來時(拖曳、雙指放開、滾輪一格、按鍵或按鈕的動畫結束)給出新的視角。元件被卸載再掛上時(例如切到清單檢視再切回來),把最後一次的 `view` 存起來、當 `defaultView` 傳回去,就會停在原來的地方。
|
|
37
96
|
- 縮放與平移:滾輪、雙指縮放、拖曳平移;右下角「放大」「縮小」「重設視角」;鍵盤在圖上(包括分區上)按 + − 縮放、方向鍵平移。最多放大 8 倍,全景時不能平移。按鈕和鍵盤的變化有 200 ms 的動畫,`prefers-reduced-motion` 時直接跳過去。拖曳超過 4 px 不算點選。
|
|
38
97
|
- 鍵盤:每個分區是按鈕,Tab 順序和標籤的優先序相同;Enter 或空白鍵選取(`aria-pressed`)。螢幕閱讀器念「機櫃區 F,29.6 °C,超過上限,進氣 27.9 °C」。沒有資料的分區不能選。
|
|
39
|
-
- 提示:滑鼠停在分區上或鍵盤聚焦時顯示名稱、數值、狀態、`detail
|
|
98
|
+
- 提示:滑鼠停在分區上或鍵盤聚焦時顯示名稱、數值、狀態、`detail`,再加上 `tooltip` 的每一行(例如「濕度 48 %」);螢幕閱讀器在 `detail` 後面念這些行。
|
|
40
99
|
- 觸控:寬度小於 600 px 或觸控螢幕上,畫面上小於 48 px 的分區在標籤位置多一個 48 px 的圓形點擊範圍。圖上的手勢都交給地圖(`touch-action: none`),頁面要在圖外捲動。
|
|
41
100
|
- 大小:沒有 `fill` 時照外框的比例,高 240~640 px;放在 ConsoleLayout 的主視覺卡片裡時加 `fill`,撐滿卡片的高度(最少 240 px),和 ZoneMap 的 `fill` 相同。
|
|
42
101
|
- 標籤的寬度用固定的估算(中文 1 em、Geist Mono 0.6 em),網頁字型載入前後、伺服器渲染時排法都一樣。
|
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
|
|
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/ZoneMap.md
CHANGED
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.
|
|
69
|
-
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.
|
|
70
|
-
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.
|
|
68
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.52.0/fonts.css">
|
|
69
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.52.0/tokens.css">
|
|
70
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.52.0/styles.css">
|
|
71
71
|
<div id="root"></div>
|
|
72
|
-
<script src="https://seanyeh77.github.io/ui-design-system/dist/0.
|
|
72
|
+
<script src="https://seanyeh77.github.io/ui-design-system/dist/0.52.0/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.
|
|
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.0/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.52.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.
|
|
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.
|
package/docs/guidelines.md
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "0.52.0",
|
|
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.
|
|
61
|
+
"@seanyeh77/tokens": "^0.52.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "node scripts/theme-defaults.ts && tsdown && node scripts/postbuild.ts",
|