@seanyeh77/ui 0.46.0 → 0.47.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/Badge/Badge.d.ts +4 -4
- package/dist/components/Badge/Badge.js +7 -1
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Breadcrumb/Breadcrumb.js +1 -0
- package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/components/DataTable/DataTable.js +12 -3
- package/dist/components/DataTable/DataTable.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.js +19 -1
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/InlineCode/InlineCode.js +1 -1
- package/dist/components/InlineCode/InlineCode.js.map +1 -1
- package/dist/components/KpiCard/KpiCard.d.ts +2 -2
- package/dist/components/KpiCard/KpiCard.js +1 -1
- package/dist/components/KpiCard/KpiCard.js.map +1 -1
- package/dist/components/LayerGraph/LayerGraph.js +5 -5
- package/dist/components/LayerGraph/LayerGraph.js.map +1 -1
- package/dist/components/MultiSelect/MultiSelect.js +1 -0
- package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/components/SettingsLayout/SettingsLayout.js +3 -1
- package/dist/components/SettingsLayout/SettingsLayout.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +8 -2
- package/dist/components/TextField/TextField.js +59 -13
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/css/Alert.css +9 -1
- package/dist/css/DataTable.css +27 -2
- package/dist/css/EmptyState.css +4 -4
- package/dist/css/EventTimeline.css +3 -1
- package/dist/css/LayerGraph.css +1 -1
- package/dist/css/LoadingBar.css +4 -1
- package/dist/css/MobileTabBar.css +6 -4
- package/dist/css/SettingsLayout.css +1 -0
- package/dist/css/Tabs.css +15 -2
- package/dist/css/base.css +86 -3
- package/dist/css/end.css +3 -1
- package/dist/i18n.js +1 -0
- package/dist/i18n.js.map +1 -1
- package/dist/icons/Icon.d.ts +2 -1
- package/dist/icons/Icon.js +4 -3
- package/dist/icons/Icon.js.map +1 -1
- package/dist/icons/store.d.ts +3 -1
- package/dist/icons/store.js +17 -12
- package/dist/icons/store.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/internal/util.js +4 -3
- package/dist/internal/util.js.map +1 -1
- package/dist/styles.css +248 -109
- package/dist/theme.d.ts +7 -0
- package/dist/theme.js +39 -15
- package/dist/theme.js.map +1 -1
- package/docs/Badge.md +2 -1
- package/docs/EmptyState.md +1 -1
- package/docs/EventTimeline.md +1 -1
- package/docs/Graph.md +1 -1
- package/docs/KpiCard.md +1 -1
- package/docs/LoadingBar.md +1 -1
- package/docs/MobileTabBar.md +1 -1
- package/docs/MultiSelect.md +1 -1
- package/docs/Tabs.md +10 -9
- package/docs/TextField.md +2 -0
- package/docs/agents.md +6 -6
- package/docs/theme.md +5 -2
- package/package.json +2 -2
package/dist/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":[],"sources":["../src/theme.ts"],"sourcesContent":["import { ensureAnnouncer } from './announce';\nimport { DEFAULT_ACCENT, GROUNDS, PRESETS, type ThemePreset } from './generated/themeDefaults';\nimport { installFocusMain } from './internal/focusMain';\nimport { readStored, writeStored } from './internal/stored';\nimport { reduced } from './internal/util';\n\n/* Theme and accent color. 'auto' follows prefers-color-scheme; colors cross-fade for 300 ms on a change.\n The choice is kept in localStorage, so initTheme() on the next visit restores it. A preset (data-theme-preset on\n <html>, or initTheme({ preset })) replaces light and dark: the teaching preset is light only. The accent comes from\n tokens.css until the person picks one (setAccent); only then are inline --accent variables written. */\n\nexport type ThemeSetting = 'auto' | 'light' | 'dark';\nexport type { ThemePreset };\nexport { DEFAULT_ACCENT };\n\nexport const THEME_KEY = 'ui-theme';\nexport const ACCENT_KEY = 'ui-accent';\nconst PRESET_ATTR = 'data-theme-preset';\n\nconst isSetting = (v: string | null): v is ThemeSetting => v === 'auto' || v === 'light' || v === 'dark';\nconst hasDom = () => typeof window !== 'undefined' && typeof document !== 'undefined';\n\n/** A stored theme setting as text to the setting, 'auto' for anything else. */\nexport const parseTheme = (raw: string): ThemeSetting => (isSetting(raw) ? raw : 'auto');\n\n/** The stored theme setting, 'auto' when there is none (and on the server). */\nexport function storedTheme(): ThemeSetting {\n return hasDom() ? parseTheme(readStored(THEME_KEY) ?? '') : 'auto';\n}\n\n/** The preset on <html data-theme-preset>, or null (the light and dark themes). */\nexport function themePreset(): ThemePreset | null {\n if (typeof document === 'undefined') return null;\n const v = document.documentElement.getAttribute(PRESET_ATTR);\n return v && Object.hasOwn(PRESETS, v) ? (v as ThemePreset) : null;\n}\n\nfunction resolveTheme(t: ThemeSetting): 'light' | 'dark' {\n if (t !== 'auto') return t;\n return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n}\n\nlet fadeTimer: ReturnType<typeof setTimeout> | undefined;\n\n/** Switches the theme on <html data-theme> and remembers it. Under a preset the setting is remembered but the\n * preset stays (the teaching preset is light only). */\nexport function setTheme(t: ThemeSetting): void {\n if (!hasDom()) return;\n const root = document.documentElement;\n if (!reduced()) {\n root.classList.add('ui-theme-fade');\n clearTimeout(fadeTimer);\n fadeTimer = setTimeout(() => root.classList.remove('ui-theme-fade'), 320);\n }\n root.setAttribute('data-theme', themePreset() ?? resolveTheme(t));\n root.setAttribute('data-theme-setting', t);\n writeStored(THEME_KEY, t);\n // The accent's text and soft colors depend on the theme.\n applyAccent();\n}\n\n/** Swatches whose color changed so they read as text on every ground: a stored old value moves to the new one. */\nconst RENAMED_SWATCHES: Record<string, string> = {\n '#8a4fd6': '#864ad1',\n '#c2407a': '#ba3873',\n '#cd3a2f': '#c53228',\n '#b85a0e': '#ab5101',\n '#1a844a': '#077b42',\n '#0e827d': '#027874',\n};\n\n/** A stored accent as text to #rrggbb, an old swatch value moved to its current one; null for anything else. */\nexport function parseAccent(raw: string): string | null {\n const v = raw.trim().toLowerCase();\n if (!/^#[0-9a-f]{6}$/.test(v)) return null;\n return RENAMED_SWATCHES[v] ?? v;\n}\n\n/** The accent the person picked (stored), with an old swatch value moved to its current one (and stored again);\n * null when they picked none, so tokens.css decides. */\nexport function pickedAccent(): string | null {\n if (!hasDom()) return null;\n const raw = readStored(ACCENT_KEY);\n const v = raw ? parseAccent(raw) : null;\n if (v && v !== raw) writeStored(ACCENT_KEY, v);\n return v;\n}\n\n/** The accent in use: the picked one, else the preset's accent, else the default (DEFAULT_ACCENT). */\nexport function storedAccent(): string {\n return pickedAccent() ?? defaultAccent();\n}\n\n/** The accent tokens.css gives when nothing is picked: the preset's, else DEFAULT_ACCENT. */\nexport function defaultAccent(): string {\n const p = themePreset();\n return p ? PRESETS[p].accent : DEFAULT_ACCENT;\n}\n\nconst hexRgb = (x: string): number[] => [1, 3, 5].map((i) => parseInt(x.slice(i, i + 2), 16));\n\n/** A CSS color as #rrggbb: #rgb, #rgba, #rrggbb, #rrggbbaa (alpha dropped), rgb() and rgba() with commas or spaces.\n * null for anything else (a name, a var(), an empty value). Bundlers shorten #ffffff to #fff in tokens.css, so the\n * short form must read the same. */\nexport function toHex(c: string): string | null {\n const v = c.trim().toLowerCase();\n const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])[0-9a-f]?$/.exec(v);\n if (short) return '#' + short[1] + short[1] + short[2] + short[2] + short[3] + short[3];\n const long = /^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(v);\n if (long) return '#' + long[1];\n const fn = /^rgba?\\(\\s*([\\d.]+)[\\s,]+([\\d.]+)[\\s,]+([\\d.]+)(?:\\s*[,/]\\s*[\\d.]+%?)?\\s*\\)$/.exec(v);\n if (fn) {\n const n = fn.slice(1, 4).map(Number);\n if (n.every((x) => x >= 0 && x <= 255)) return '#' + n.map((x) => Math.round(x).toString(16).padStart(2, '0')).join('');\n }\n return null;\n}\n\nfunction mixHex(a: string, b: string, t: number): string {\n const p = hexRgb(a);\n const q = hexRgb(b);\n return (\n '#' +\n p\n .map((v, i) =>\n Math.round(v + (q[i] - v) * t)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('')\n );\n}\n\nfunction lum(x: string): number {\n const w = [0.2126, 0.7152, 0.0722];\n return hexRgb(x)\n .map((v) => {\n v /= 255;\n return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;\n })\n .reduce((s, v, i) => s + v * w[i], 0);\n}\n\nfunction contrast(a: string, b: string): number {\n const x = lum(a);\n const y = lum(b);\n return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);\n}\n\n/** The accent's text color (accent-text, and the focus outline): the accent itself when it reads (4.5:1) on bg,\n * surface and every extra ground passed (setAccent passes surface-sub, surface-chrome and accent-soft); else, in\n * light, the accent mixed with black 4 % at a time, in dark with white 5 % at a time, until it reads on all of them. */\nexport function accentText(hex: string, dark: boolean, bg: string, surface: string, ...grounds: string[]): string {\n const all = [bg, surface, ...grounds].map(toHex);\n // A background that cannot be read: keep the accent itself rather than mixing it toward black or white blindly.\n if (all.some((g) => !g)) return hex;\n const reads = (c: string) => all.every((g) => contrast(c, g as string) >= 4.5);\n const toward = dark ? '#ffffff' : '#000000';\n const step = dark ? 0.05 : 0.04;\n let text = hex;\n for (let k = 1; k * step <= 1 && !reads(text); k++) text = mixHex(hex, toward, k * step);\n return text;\n}\n\nconst INK = GROUNDS.ink.light;\n\n/** The text on an accent fill (on-accent): white or the near-black ink (#171512), whichever contrasts more. */\nexport function onFill(fill: string): '#ffffff' | '#171512' {\n return contrast('#ffffff', fill) >= contrast(INK, fill) ? '#ffffff' : INK;\n}\n\n/** The accent's fill color (accent: buttons, switches, progress, selected marks): the accent itself when it reaches\n * 3:1 on bg, surface and every extra ground passed (setAccent passes surface-sub, surface-chrome and accent-soft) and\n * its on-accent text reaches 4.5:1 on it; else, in light, the accent mixed with black 4 % at a time, in dark with\n * white 5 % at a time, until both hold. The preset swatches pass in light as they are. */\nexport function accentFill(hex: string, dark: boolean, bg: string, surface: string, ...grounds: string[]): string {\n const all = [bg, surface, ...grounds].map(toHex);\n if (all.some((g) => !g)) return hex;\n const ok = (c: string) => all.every((g) => contrast(c, g as string) >= 3) && contrast(onFill(c), c) >= 4.5;\n const toward = dark ? '#ffffff' : '#000000';\n const step = dark ? 0.05 : 0.04;\n let fill = hex;\n for (let k = 1; k * step <= 1 && !ok(fill); k++) fill = mixHex(hex, toward, k * step);\n return fill;\n}\n\n/** The preset swatches of AccentPicker. In light (and the teaching preset) each one reads as text by itself (4.5:1 on\n * bg, surface, surface-sub, surface-chrome and its own accent-soft), so accentText returns it unchanged; white text\n * reads on it (4.5:1). In dark, accentText lightens it. Checked in tokens-contrast.test.tsx. */\nexport const ACCENT_SWATCHES: readonly (readonly [name: string, hex: string])[] = [\n ['藍', '#2457d6'],\n ['靛', '#5b4fd6'],\n ['紫', '#864ad1'],\n ['桃紅', '#ba3873'],\n ['紅', '#c53228'],\n ['橘', '#ab5101'],\n ['綠', '#077b42'],\n ['青', '#027874'],\n];\n\nconst ACCENT_VARS = ['--accent', '--accent-hover', '--accent-press', '--accent-soft', '--accent-text', '--on-accent', '--focus', '--focus-ring'];\n\n/** Derives every accent token from one color (自訂強調色的換算 in docs/theme.md) and writes them on <html>.\n * Returns false for anything but #rrggbb. quiet: apply without storing. */\nexport function setAccent(hex: string, quiet = false): boolean {\n if (!/^#[0-9a-fA-F]{6}$/.test(hex)) return false;\n if (!hasDom()) return true;\n hex = hex.toLowerCase();\n const root = document.documentElement;\n const dark = root.getAttribute('data-theme') === 'dark';\n const mode = dark ? 'dark' : 'light';\n const cs = getComputedStyle(root);\n // Read the theme's colors as #rrggbb (bundlers may have shortened #ffffff to #fff); the theme's defaults when unset.\n const surface = toHex(cs.getPropertyValue('--surface')) ?? GROUNDS.surface[mode];\n const bg = toHex(cs.getPropertyValue('--bg')) ?? GROUNDS.bg[mode];\n const sub = toHex(cs.getPropertyValue('--surface-sub')) ?? GROUNDS['surface-sub'][mode];\n const chrome = toHex(cs.getPropertyValue('--surface-chrome')) ?? GROUNDS['surface-chrome'][mode];\n const soft = dark ? mixHex(surface, hex, 0.22) : mixHex('#ffffff', hex, 0.12);\n // Text in the accent also sits on zebra rows, code blocks, the top bar and its own soft fill (a selected row).\n const text = accentText(hex, dark, bg, surface, sub, chrome, soft);\n // The fill reaches 3:1 on the same grounds (a checked box in a selected row); hover and press go away from the page:\n // darker in light, lighter in dark, so they keep 3:1 and their text.\n const fill = accentFill(hex, dark, bg, surface, sub, chrome, soft);\n const away = dark ? '#ffffff' : '#000000';\n const vars: Record<string, string> = {\n '--accent': fill,\n '--accent-hover': mixHex(fill, away, 0.12),\n '--accent-press': mixHex(fill, away, 0.22),\n '--accent-soft': soft,\n '--accent-text': text,\n '--on-accent': onFill(fill),\n // One focus style everywhere: a 2 px outline in the accent's text color, 3:1 or more on every ground.\n '--focus': text,\n // Old name of --focus, kept for pages written before it.\n '--focus-ring': text,\n };\n for (const [k, v] of Object.entries(vars)) root.style.setProperty(k, v);\n if (!quiet) writeStored(ACCENT_KEY, hex);\n return true;\n}\n\n/** Forgets the picked accent and removes the inline accent variables, so tokens.css (the theme or preset) decides. */\nexport function resetAccent(): void {\n if (!hasDom()) return;\n for (const k of ACCENT_VARS) document.documentElement.style.removeProperty(k);\n writeStored(ACCENT_KEY, null);\n}\n\n/** Applies the picked accent for the current theme, or removes the inline variables when none is picked. */\nfunction applyAccent(): void {\n const picked = pickedAccent();\n if (picked) setAccent(picked, true);\n else for (const k of ACCENT_VARS) document.documentElement.style.removeProperty(k);\n}\n\nlet following = false;\n\n/** Applies the stored theme and accent; call once when the page starts. preset: a preset of tokens.json (such as\n * 'teaching') that replaces light and dark, kept on <html data-theme-preset>; null removes it; without the option a\n * data-theme-preset already on <html> is kept. Pages do not set data-theme themselves. */\nexport function initTheme(options: { preset?: ThemePreset | null } = {}): void {\n if (!hasDom()) return;\n const root = document.documentElement;\n if (options.preset === null) root.removeAttribute(PRESET_ATTR);\n else if (options.preset) root.setAttribute(PRESET_ATTR, options.preset);\n setTheme(storedTheme());\n ensureAnnouncer();\n installFocusMain();\n if (following || typeof window.matchMedia !== 'function') return;\n following = true;\n window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {\n if (storedTheme() === 'auto') setTheme('auto');\n });\n}\n\n/** The text color for something drawn on a fill (a heat-scale zone, a status band): the near-black ink of the light\n * theme (#171512) or white, whichever contrasts more with the fill. `fill` is a color (#hex, rgb()) or a token name\n * such as 'heat-6', read from el (default: the root) so it follows the theme. Every step of heat-*, diverge-* and\n * chart-* reaches 4.5:1 with its pick. Unreadable colors give the near-black ink. */\nexport function textOn(fill: string, el?: Element): '#171512' | '#ffffff' {\n let c = fill.trim();\n if (/^[a-z][a-z0-9-]*$/.test(c) && typeof document !== 'undefined') c = getComputedStyle(el ?? document.documentElement).getPropertyValue('--' + c);\n const hex = toHex(c);\n if (!hex) return '#171512';\n return contrast(hex, '#171512') >= contrast(hex, '#ffffff') ? '#171512' : '#ffffff';\n}\n\n/** The heat-scale token for a value: min (or below) is heat-1, max (or above) is heat-7, evenly in between. */\nexport function heatToken(value: number, min: number, max: number): `heat-${1 | 2 | 3 | 4 | 5 | 6 | 7}` {\n const t = max > min ? (value - min) / (max - min) : 0;\n const step = Math.min(7, Math.max(1, Math.round(t * 6) + 1)) as 1 | 2 | 3 | 4 | 5 | 6 | 7;\n return `heat-${step}`;\n}\n\n/** The diverging-scale token for a difference: within ±zero it is diverge-zero; from ±strong on, the -strong step. */\nexport function divergeToken(\n diff: number,\n limits: { zero: number; strong: number },\n): 'diverge-neg-strong' | 'diverge-neg' | 'diverge-zero' | 'diverge-pos' | 'diverge-pos-strong' {\n const a = Math.abs(diff);\n if (a <= limits.zero) return 'diverge-zero';\n const strong = a >= limits.strong;\n return diff < 0 ? (strong ? 'diverge-neg-strong' : 'diverge-neg') : strong ? 'diverge-pos-strong' : 'diverge-pos';\n}\n"],"mappings":";;;;;;;AAeA,MAAa,YAAY;AACzB,MA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Y,CAAC;CACtB,gBAAgB;CAChB,iBAAiB;CACjB,IAAI,aAAa,OAAO,OAAO,eAAe,YAAY;CAC1D,YAAY;CACZ,OAAO,WAAW,8BAA8B,CAAC,CAAC,iBAAiB,gBAAgB;EACjF,IAAI,YAAY,MAAM,QAAQ,SAAS,MAAM;CAC/C,CAAC;AACH;;;;;AAMA,SAAgB,OAAO,MAAc,IAAqC;CACxE,IAAI,IAAI,KAAK,KAAK;CAClB,IAAI,oBAAoB,KAAK,CAAC,KAAK,OAAO,aAAa,aAAa,IAAI,iBAAiB,MAAM,SAAS,eAAe,CAAC,CAAC,iBAAiB,OAAO,CAAC;CAClJ,MAAM,MAAM,MAAM,CAAC;CACnB,IAAI,CAAC,KAAK,OAAO;CACjB,OAAO,SAAS,KAAK,SAAS,KAAK,SAAS,KAAK,SAAS,IAAI,YAAY;AAC5E;;AAGA,SAAgB,UAAU,OAAe,KAAa,KAAkD;CACtG,MAAM,IAAI,MAAM,OAAO,QAAQ,QAAQ,MAAM,OAAO;CAEpD,OAAO,QADM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CACxC;AACpB;;AAGA,SAAgB,aACd,MACA,QAC8F;CAC9F,MAAM,IAAI,KAAK,IAAI,IAAI;CACvB,IAAI,KAAK,OAAO,MAAM,OAAO;CAC7B,MAAM,SAAS,KAAK,OAAO;CAC3B,OAAO,OAAO,IAAK,SAAS,uBAAuB,gBAAiB,SAAS,uBAAuB;AACtG"}
|
|
1
|
+
{"version":3,"file":"theme.js","names":[],"sources":["../src/theme.ts"],"sourcesContent":["import { ensureAnnouncer } from './announce';\nimport { DEFAULT_ACCENT, GROUNDS, PRESETS, type ThemePreset } from './generated/themeDefaults';\nimport { installFocusMain } from './internal/focusMain';\nimport { readStored, writeStored } from './internal/stored';\nimport { reduced } from './internal/util';\n\n/* Theme and accent color. 'auto' follows prefers-color-scheme; colors cross-fade for 300 ms on a change.\n The choice is kept in localStorage, so initTheme() on the next visit restores it. A preset (data-theme-preset on\n <html>, or initTheme({ preset })) replaces light and dark: the teaching preset is light only. The accent comes from\n tokens.css until the person picks one (setAccent); only then are inline --accent variables written. */\n\nexport type ThemeSetting = 'auto' | 'light' | 'dark';\nexport type { ThemePreset };\nexport { DEFAULT_ACCENT };\n\nexport const THEME_KEY = 'ui-theme';\nexport const ACCENT_KEY = 'ui-accent';\n/** The picked accent's derived tokens, for themeScript. */\nconst ACCENT_VARS_KEY = 'ui-accent-vars';\nconst PRESET_ATTR = 'data-theme-preset';\n\nconst isSetting = (v: string | null): v is ThemeSetting => v === 'auto' || v === 'light' || v === 'dark';\nconst hasDom = () => typeof window !== 'undefined' && typeof document !== 'undefined';\n\n/** A stored theme setting as text to the setting, 'auto' for anything else. */\nexport const parseTheme = (raw: string): ThemeSetting => (isSetting(raw) ? raw : 'auto');\n\n/** The stored theme setting, 'auto' when there is none (and on the server). */\nexport function storedTheme(): ThemeSetting {\n return hasDom() ? parseTheme(readStored(THEME_KEY) ?? '') : 'auto';\n}\n\n/** The preset on <html data-theme-preset>, or null (the light and dark themes). */\nexport function themePreset(): ThemePreset | null {\n if (typeof document === 'undefined') return null;\n const v = document.documentElement.getAttribute(PRESET_ATTR);\n return v && Object.hasOwn(PRESETS, v) ? (v as ThemePreset) : null;\n}\n\nfunction resolveTheme(t: ThemeSetting): 'light' | 'dark' {\n if (t !== 'auto') return t;\n return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n}\n\nlet fadeTimer: ReturnType<typeof setTimeout> | undefined;\n\n/** Switches the theme on <html data-theme> and remembers it. Under a preset the setting is remembered but the\n * preset stays (the teaching preset is light only). */\nexport function setTheme(t: ThemeSetting): void {\n if (!hasDom()) return;\n const root = document.documentElement;\n if (!reduced()) {\n root.classList.add('ui-theme-fade');\n clearTimeout(fadeTimer);\n fadeTimer = setTimeout(() => root.classList.remove('ui-theme-fade'), 320);\n }\n root.setAttribute('data-theme', themePreset() ?? resolveTheme(t));\n root.setAttribute('data-theme-setting', t);\n writeStored(THEME_KEY, t);\n // The accent's text and soft colors depend on the theme.\n applyAccent();\n}\n\n/** Swatches whose color changed so they read as text on every ground: a stored old value moves to the new one. */\nconst RENAMED_SWATCHES: Record<string, string> = {\n '#8a4fd6': '#864ad1',\n '#c2407a': '#ba3873',\n '#cd3a2f': '#c53228',\n '#b85a0e': '#ab5101',\n '#1a844a': '#077b42',\n '#0e827d': '#027874',\n};\n\n/** A stored accent as text to #rrggbb, an old swatch value moved to its current one; null for anything else. */\nexport function parseAccent(raw: string): string | null {\n const v = raw.trim().toLowerCase();\n if (!/^#[0-9a-f]{6}$/.test(v)) return null;\n return RENAMED_SWATCHES[v] ?? v;\n}\n\n/** The accent the person picked (stored), with an old swatch value moved to its current one (and stored again);\n * null when they picked none, so tokens.css decides. */\nexport function pickedAccent(): string | null {\n if (!hasDom()) return null;\n const raw = readStored(ACCENT_KEY);\n const v = raw ? parseAccent(raw) : null;\n if (v && v !== raw) writeStored(ACCENT_KEY, v);\n return v;\n}\n\n/** The accent in use: the picked one, else the preset's accent, else the default (DEFAULT_ACCENT). */\nexport function storedAccent(): string {\n return pickedAccent() ?? defaultAccent();\n}\n\n/** The accent tokens.css gives when nothing is picked: the preset's, else DEFAULT_ACCENT. */\nexport function defaultAccent(): string {\n const p = themePreset();\n return p ? PRESETS[p].accent : DEFAULT_ACCENT;\n}\n\nconst hexRgb = (x: string): number[] => [1, 3, 5].map((i) => parseInt(x.slice(i, i + 2), 16));\n\n/** A CSS color as #rrggbb: #rgb, #rgba, #rrggbb, #rrggbbaa (alpha dropped), rgb() and rgba() with commas or spaces.\n * null for anything else (a name, a var(), an empty value). Bundlers shorten #ffffff to #fff in tokens.css, so the\n * short form must read the same. */\nexport function toHex(c: string): string | null {\n const v = c.trim().toLowerCase();\n const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])[0-9a-f]?$/.exec(v);\n if (short) return '#' + short[1] + short[1] + short[2] + short[2] + short[3] + short[3];\n const long = /^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(v);\n if (long) return '#' + long[1];\n const fn = /^rgba?\\(\\s*([\\d.]+)[\\s,]+([\\d.]+)[\\s,]+([\\d.]+)(?:\\s*[,/]\\s*[\\d.]+%?)?\\s*\\)$/.exec(v);\n if (fn) {\n const n = fn.slice(1, 4).map(Number);\n if (n.every((x) => x >= 0 && x <= 255)) return '#' + n.map((x) => Math.round(x).toString(16).padStart(2, '0')).join('');\n }\n return null;\n}\n\nfunction mixHex(a: string, b: string, t: number): string {\n const p = hexRgb(a);\n const q = hexRgb(b);\n return (\n '#' +\n p\n .map((v, i) =>\n Math.round(v + (q[i] - v) * t)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('')\n );\n}\n\nfunction lum(x: string): number {\n const w = [0.2126, 0.7152, 0.0722];\n return hexRgb(x)\n .map((v) => {\n v /= 255;\n return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;\n })\n .reduce((s, v, i) => s + v * w[i], 0);\n}\n\nfunction contrast(a: string, b: string): number {\n const x = lum(a);\n const y = lum(b);\n return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);\n}\n\n/** The accent's text color (accent-text, and the focus outline): the accent itself when it reads (4.5:1) on bg,\n * surface and every extra ground passed (setAccent passes surface-sub, surface-chrome and accent-soft); else, in\n * light, the accent mixed with black 4 % at a time, in dark with white 5 % at a time, until it reads on all of them. */\nexport function accentText(hex: string, dark: boolean, bg: string, surface: string, ...grounds: string[]): string {\n const all = [bg, surface, ...grounds].map(toHex);\n // A background that cannot be read: keep the accent itself rather than mixing it toward black or white blindly.\n if (all.some((g) => !g)) return hex;\n const reads = (c: string) => all.every((g) => contrast(c, g as string) >= 4.5);\n const toward = dark ? '#ffffff' : '#000000';\n const step = dark ? 0.05 : 0.04;\n let text = hex;\n for (let k = 1; k * step <= 1 && !reads(text); k++) text = mixHex(hex, toward, k * step);\n return text;\n}\n\nconst INK = GROUNDS.ink.light;\n\n/** The text on an accent fill (on-accent): white or the near-black ink (#171512), whichever contrasts more. */\nexport function onFill(fill: string): '#ffffff' | '#171512' {\n return contrast('#ffffff', fill) >= contrast(INK, fill) ? '#ffffff' : INK;\n}\n\n/** The accent's fill color (accent: buttons, switches, progress, selected marks): the accent itself when it reaches\n * 3:1 on bg, surface and every extra ground passed (setAccent passes surface-sub, surface-chrome and accent-soft) and\n * its on-accent text reaches 4.5:1 on it; else, in light, the accent mixed with black 4 % at a time, in dark with\n * white 5 % at a time, until both hold. The preset swatches pass in light as they are. */\nexport function accentFill(hex: string, dark: boolean, bg: string, surface: string, ...grounds: string[]): string {\n const all = [bg, surface, ...grounds].map(toHex);\n if (all.some((g) => !g)) return hex;\n const ok = (c: string) => all.every((g) => contrast(c, g as string) >= 3) && contrast(onFill(c), c) >= 4.5;\n const toward = dark ? '#ffffff' : '#000000';\n const step = dark ? 0.05 : 0.04;\n let fill = hex;\n for (let k = 1; k * step <= 1 && !ok(fill); k++) fill = mixHex(hex, toward, k * step);\n return fill;\n}\n\n/** The preset swatches of AccentPicker. In light (and the teaching preset) each one reads as text by itself (4.5:1 on\n * bg, surface, surface-sub, surface-chrome and its own accent-soft), so accentText returns it unchanged; white text\n * reads on it (4.5:1). In dark, accentText lightens it. Checked in tokens-contrast.test.tsx. */\nexport const ACCENT_SWATCHES: readonly (readonly [name: string, hex: string])[] = [\n ['藍', '#2457d6'],\n ['靛', '#5b4fd6'],\n ['紫', '#864ad1'],\n ['桃紅', '#ba3873'],\n ['紅', '#c53228'],\n ['橘', '#ab5101'],\n ['綠', '#077b42'],\n ['青', '#027874'],\n];\n\nconst ACCENT_VARS = ['--accent', '--accent-hover', '--accent-press', '--accent-soft', '--accent-text', '--on-accent', '--focus', '--focus-ring'];\n\n/** Every accent token for one color on one theme's grounds. */\nfunction accentVars(hex: string, dark: boolean, surface: string, bg: string, sub: string, chrome: string): Record<string, string> {\n const soft = dark ? mixHex(surface, hex, 0.22) : mixHex('#ffffff', hex, 0.12);\n // Text in the accent also sits on zebra rows, code blocks, the top bar and its own soft fill (a selected row).\n const text = accentText(hex, dark, bg, surface, sub, chrome, soft);\n // The fill reaches 3:1 on the same grounds (a checked box in a selected row); hover and press go away from the page:\n // darker in light, lighter in dark, so they keep 3:1 and their text.\n const fill = accentFill(hex, dark, bg, surface, sub, chrome, soft);\n const away = dark ? '#ffffff' : '#000000';\n return {\n '--accent': fill,\n '--accent-hover': mixHex(fill, away, 0.12),\n '--accent-press': mixHex(fill, away, 0.22),\n '--accent-soft': soft,\n '--accent-text': text,\n '--on-accent': onFill(fill),\n // One focus style everywhere: a 2 px outline in the accent's text color, 3:1 or more on every ground.\n '--focus': text,\n // Old name of --focus, kept for pages written before it.\n '--focus-ring': text,\n };\n}\n\n/** Derives every accent token from one color (自訂強調色的換算 in docs/theme.md) and writes them on <html>.\n * Returns false for anything but #rrggbb. quiet: apply without storing. */\nexport function setAccent(hex: string, quiet = false): boolean {\n if (!/^#[0-9a-fA-F]{6}$/.test(hex)) return false;\n if (!hasDom()) return true;\n hex = hex.toLowerCase();\n const root = document.documentElement;\n const dark = root.getAttribute('data-theme') === 'dark';\n const mode = dark ? 'dark' : 'light';\n const cs = getComputedStyle(root);\n // Read the theme's colors as #rrggbb (bundlers may have shortened #ffffff to #fff); the theme's defaults when unset.\n const surface = toHex(cs.getPropertyValue('--surface')) ?? GROUNDS.surface[mode];\n const bg = toHex(cs.getPropertyValue('--bg')) ?? GROUNDS.bg[mode];\n const sub = toHex(cs.getPropertyValue('--surface-sub')) ?? GROUNDS['surface-sub'][mode];\n const chrome = toHex(cs.getPropertyValue('--surface-chrome')) ?? GROUNDS['surface-chrome'][mode];\n const vars = accentVars(hex, dark, surface, bg, sub, chrome);\n for (const [k, v] of Object.entries(vars)) root.style.setProperty(k, v);\n if (!quiet) writeStored(ACCENT_KEY, hex);\n // The picked accent's tokens for themeScript, which applies them before the first paint: this theme as drawn, the\n // other from the theme defaults (a preset is light only).\n if (readStored(ACCENT_KEY) === hex) {\n const other = !dark;\n const o = other ? 'dark' : 'light';\n const cache: Record<string, unknown> = { hex, [mode]: vars };\n if (!themePreset()) cache[o] = accentVars(hex, other, GROUNDS.surface[o], GROUNDS.bg[o], GROUNDS['surface-sub'][o], GROUNDS['surface-chrome'][o]);\n writeStored(ACCENT_VARS_KEY, JSON.stringify(cache));\n }\n return true;\n}\n\n/** Forgets the picked accent and removes the inline accent variables, so tokens.css (the theme or preset) decides. */\nexport function resetAccent(): void {\n if (!hasDom()) return;\n for (const k of ACCENT_VARS) document.documentElement.style.removeProperty(k);\n writeStored(ACCENT_KEY, null);\n writeStored(ACCENT_VARS_KEY, null);\n}\n\n/** Applies the picked accent for the current theme, or removes the inline variables when none is picked. */\nfunction applyAccent(): void {\n const picked = pickedAccent();\n if (picked) setAccent(picked, true);\n else for (const k of ACCENT_VARS) document.documentElement.style.removeProperty(k);\n}\n\nlet following = false;\n\n/** Applies the stored theme and accent; call once when the page starts. preset: a preset of tokens.json (such as\n * 'teaching') that replaces light and dark, kept on <html data-theme-preset>; null removes it; without the option a\n * data-theme-preset already on <html> is kept. Pages do not set data-theme themselves. */\nexport function initTheme(options: { preset?: ThemePreset | null } = {}): void {\n if (!hasDom()) return;\n const root = document.documentElement;\n if (options.preset === null) root.removeAttribute(PRESET_ATTR);\n else if (options.preset) root.setAttribute(PRESET_ATTR, options.preset);\n setTheme(storedTheme());\n ensureAnnouncer();\n installFocusMain();\n if (following || typeof window.matchMedia !== 'function') return;\n following = true;\n window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {\n if (storedTheme() === 'auto') setTheme('auto');\n });\n}\n\n/** The text color for something drawn on a fill (a heat-scale zone, a status band): the near-black ink of the light\n * theme (#171512) or white, whichever contrasts more with the fill. `fill` is a color (#hex, rgb()) or a token name\n * such as 'heat-6', read from el (default: the root) so it follows the theme. Every step of heat-*, diverge-* and\n * chart-* reaches 4.5:1 with its pick. Unreadable colors give the near-black ink. */\nexport function textOn(fill: string, el?: Element): '#171512' | '#ffffff' {\n let c = fill.trim();\n if (/^[a-z][a-z0-9-]*$/.test(c) && typeof document !== 'undefined') c = getComputedStyle(el ?? document.documentElement).getPropertyValue('--' + c);\n const hex = toHex(c);\n if (!hex) return '#171512';\n return contrast(hex, '#171512') >= contrast(hex, '#ffffff') ? '#171512' : '#ffffff';\n}\n\n/** The heat-scale token for a value: min (or below) is heat-1, max (or above) is heat-7, evenly in between. */\nexport function heatToken(value: number, min: number, max: number): `heat-${1 | 2 | 3 | 4 | 5 | 6 | 7}` {\n const t = max > min ? (value - min) / (max - min) : 0;\n const step = Math.min(7, Math.max(1, Math.round(t * 6) + 1)) as 1 | 2 | 3 | 4 | 5 | 6 | 7;\n return `heat-${step}`;\n}\n\n/** The diverging-scale token for a difference: within ±zero it is diverge-zero; from ±strong on, the -strong step. */\nexport function divergeToken(\n diff: number,\n limits: { zero: number; strong: number },\n): 'diverge-neg-strong' | 'diverge-neg' | 'diverge-zero' | 'diverge-pos' | 'diverge-pos-strong' {\n const a = Math.abs(diff);\n if (a <= limits.zero) return 'diverge-zero';\n const strong = a >= limits.strong;\n return diff < 0 ? (strong ? 'diverge-neg-strong' : 'diverge-neg') : strong ? 'diverge-pos-strong' : 'diverge-pos';\n}\n\n/**\n * A small script for an inline <script> in <head> of a server-rendered page: applies the stored theme (data-theme,\n * data-theme-setting) and the picked accent before the first paint, so the page does not flash the light theme or the\n * default accent until initTheme runs. A preset goes on <html data-theme-preset> in the server's markup; the script\n * keeps it. Still call initTheme() at startup.\n */\nexport const themeScript = `(function(){try{var d=document.documentElement,s=localStorage,t=s.getItem('${THEME_KEY}');if(t!=='light'&&t!=='dark')t='auto';var p=d.getAttribute('${PRESET_ATTR}');var m=t!=='auto'?t:window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';d.setAttribute('data-theme',p||m);d.setAttribute('data-theme-setting',t);var a=s.getItem('${ACCENT_KEY}'),c=JSON.parse(s.getItem('${ACCENT_VARS_KEY}')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AAO,QAAQ,QAAQ,MAAM,OAAO;CAEpD,OAAO,QADM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CACxC;AACpB;;AAGA,SAAgB,aACd,MACA,QAC8F;CAC9F,MAAM,IAAI,KAAK,IAAI,IAAI;CACvB,IAAI,KAAK,OAAO,MAAM,OAAO;CAC7B,MAAM,SAAS,KAAK,OAAO;CAC3B,OAAO,OAAO,IAAK,SAAS,uBAAuB,gBAAiB,SAAS,uBAAuB;AACtG;;;;;;;AAQA,MAAa,cAAc,8EAA8E,UAAU,+DAA+D,YAAY,uMAAuM,WAAW,6BAA6B,gBAAgB"}
|
package/docs/Badge.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
- 只有要處理的狀態醒目:`warning`、`danger` 的文字上色加粗,其他文字是 `ink-muted` 一般粗細,顏色只在圓圈上。
|
|
15
15
|
- 狀態不只靠顏色:一定有文字,圓圈的形狀也不同(`fail` 是 ×,不是和 `done` 一樣的實心圓)。
|
|
16
16
|
- 字級跟著旁邊的文字(表格裡和其他格子一樣大,頁首和頁首的文字一樣大),不必另外設定。
|
|
17
|
-
- 常見狀態:已啟用 `<Badge tone="success">已啟用</Badge>`;已停用、已取消用 `status="closed"`
|
|
17
|
+
- 常見狀態:已啟用 `<Badge tone="success">已啟用</Badge>`;已停用、已取消用 `status="closed"` 加文字(「已停用」「已取消」);暫停、停權這類之後能恢復的用 `paused`(「已停權」加文字);連線用 `online`、`offline`。
|
|
18
18
|
|
|
19
19
|
## 預設狀態
|
|
20
20
|
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
| `done` | 完成 | `success` | 全滿 |
|
|
27
27
|
| `fail` | 失敗 | `danger` | 空心加 × |
|
|
28
28
|
| `closed` | 已關閉 | `neutral` | 空心加橫線 |
|
|
29
|
+
| `paused` | 已暫停 | `warning` | 空心加兩條直線 |
|
|
29
30
|
| `online` | 在線 | `success` | 全滿 |
|
|
30
31
|
| `offline` | 離線 | `neutral` | 空心加斜線 |
|
|
31
32
|
|
package/docs/EmptyState.md
CHANGED
package/docs/EventTimeline.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
## 細節
|
|
29
29
|
|
|
30
|
-
- 時間用 Geist Mono
|
|
30
|
+
- 時間用 Geist Mono 灰字(24 小時制),和說明同一個大小(同一列一種字級);做的人灰字、不拆開換行;日期 13 px 灰色粗體(自成一列)。
|
|
31
31
|
- 圖示 20 px、沒有底色,螢幕閱讀器念類型名稱。內建類型:`alert` warning 圖示、`warning-text` 色;`switch` 左右箭頭、`accent-text`;`ai` 星芒、灰;`manual` 人像、灰。
|
|
32
32
|
- `tone` 的顏色:`info` 用 `accent-text`,`success`、`warning`、`danger` 用各自的文字色。
|
|
33
33
|
- 沒有定義的 `kind` 顯示一個灰色圓點,開發模式會提醒加進 `kinds`。
|
package/docs/Graph.md
CHANGED
|
@@ -16,7 +16,7 @@ h('div', { className: 'ui-graph' },
|
|
|
16
16
|
- 線直角轉彎;推測的關係加 `is-inferred`(虛線),專案宣告的關係加 `is-declared`(長短交替的虛線)。
|
|
17
17
|
- 顏色只用 token:`graph-edge`、`graph-node`、`accent`、`accent-soft`。
|
|
18
18
|
- 圖放在卡片(`surface`)上;直接放在頁面底色上時,外層加 `style: { '--ui-graph-bg': 'var(--bg)' }`。
|
|
19
|
-
-
|
|
19
|
+
- 圖比外框寬時(手機)只把 `svg` 包在 `overflowX: 'auto'` 的容器裡(`tabIndex: 0`、`role: 'region'` 加 `aria-label`,鍵盤也能捲動),`GraphLegend` 放在容器外,捲動時圖例留在原處;一開始把選取的方框捲到中間(`scrollLeft = 方框中心 - 容器寬 / 2`),不要讓它被邊緣切掉。
|
|
20
20
|
|
|
21
21
|
## 細節
|
|
22
22
|
|
package/docs/KpiCard.md
CHANGED
|
@@ -21,7 +21,7 @@ KPI 卡片,放在 Dashboard 最上方,用 `Grid` 排成一列。本身就是
|
|
|
21
21
|
|
|
22
22
|
- 內距和 Card 一樣(`--space-4`,16 px),KPI 列和下面的 Card、表格的第一欄對齊同一條左緣。
|
|
23
23
|
- 數字 31 px、Geist Mono、等寬數字;單位寫在數字後面,用一般字體(「個」「人」「天」不用 Geist Mono),一半大小、`ink-muted`。
|
|
24
|
-
- 大數字縮寫只出現在 KPI 卡片:1 萬以上寫成「1,284 萬」(`compact={false}` 可以關掉);「萬」「億」和單位一樣是一般字體、一半大小、`ink-muted`,不和數字一樣大。金額顯示成「NT$ 1,284 萬」。`format="percent"` 只決定一位小數,% 用 `unit: '%'`
|
|
24
|
+
- 大數字縮寫只出現在 KPI 卡片:1 萬以上寫成「1,284 萬」(`compact={false}` 可以關掉);「萬」「億」和單位一樣是一般字體、一半大小、`ink-muted`,不和數字一樣大。金額顯示成「NT$ 1,284 萬」。`format="percent"` 只決定一位小數,% 用 `unit: '%'` 加上;`unit="%"` 沒給 `decimals` 時也是 1 位小數(2.1 寫「2.1 %」)。
|
|
25
25
|
- 數字進場時從 0 數上來(900 ms)。跳動途中用和最終值相同的單位和小數位數,寬度先保留給最終值,所以不會忽寬忽窄。
|
|
26
26
|
- 卡片太窄、最終數字放不下時,字級自動從 31 px 縮小,最小 20 px。
|
|
27
27
|
- 變化:▲/▼ 表示方向,加百分比,後面接灰色「較上週(改善)」或「較上週(變差)」:好壞除了顏色也用灰色文字寫出來(WCAG 1.4.1),箭頭只表示方向。給了 `decimals` 時變化也用同樣的小數位數(`decimals={1}` 寫「0.4 個百分點」,不寫「0.40」);沒給時百分比 1 位、百分點 2 位。`delta={0}` 沒有箭頭、不寫好壞,整行灰色。
|
package/docs/LoadingBar.md
CHANGED
package/docs/MobileTabBar.md
CHANGED
package/docs/MultiSelect.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- 能不能新增依情況決定:名稱、標籤這類使用者可以自由增加的才開 `creatable`;選項固定、使用者不該自己加的(例如狀態、權限)不要開。
|
|
12
12
|
- 框內顯示前 2 個標籤,其餘寫成「+n」(滑過可看全部,螢幕閱讀器念「另外 n 個:…」加上名稱);`maxChips` 可以改數量。
|
|
13
13
|
- 和其他欄位一樣 40 px 高(手機 48 px),有 `hint`、`required`、`disabled`、`name`;`label` 必填。
|
|
14
|
-
- 移除:每個標籤的 ×、Backspace 移除最後一個,選了 2
|
|
14
|
+
- 移除:每個標籤的 ×、Backspace 移除最後一個,選了 2 個以上時框的右端有「清除」移除全部(Tab 可以移到,Enter 清除);移除後念出「已移除 …」或「已清除…」。Esc 只關閉選單,選單沒開時交給外層(關閉 Drawer 或 Dialog),不會清掉已選的值。
|
|
15
15
|
- 有錯誤時給 `error`:紅框、框內右側的警告圖示,下方寫錯誤,出現時念一次。
|
|
16
16
|
|
|
17
17
|
## 細節
|
package/docs/Tabs.md
CHANGED
|
@@ -2,32 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
## 用法
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
分頁:同一頁裡切換內容不同的幾個檢視。同一份內容的兩三種顯示方式(圖/清單、預覽/原始碼)用 SegmentedControl;帶筆數的篩選摘要(全部/錯誤/要確認)一律用 DataTable 的 `summary`,不用 Tabs。
|
|
6
6
|
|
|
7
7
|
```tsx
|
|
8
8
|
<Tabs
|
|
9
|
-
label="
|
|
10
|
-
unit="筆"
|
|
9
|
+
label="專案"
|
|
11
10
|
value={tab}
|
|
12
11
|
onChange={setTab}
|
|
13
12
|
items={[
|
|
14
|
-
{ id: '
|
|
15
|
-
{ id: '
|
|
13
|
+
{ id: 'overview', label: '總覽' },
|
|
14
|
+
{ id: 'files', label: '檔案', count: 12, unit: '個' },
|
|
15
|
+
{ id: 'comments', label: '留言', count: 6, unit: '則' },
|
|
16
16
|
]}
|
|
17
17
|
/>
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
- 有 `count` 時後面一定帶單位:`unit` 給整排,某一項不同時在那一項給 `unit
|
|
20
|
+
- 有 `count` 時後面一定帶單位:`unit` 給整排,某一項不同時在那一項給 `unit`。有 `count` 沒有單位時,開發模式會在主控台提醒。
|
|
21
|
+
- 基準線一律跨滿容器的寬度;下面的內容從基準線下 `space-4`(16 px)開始。
|
|
21
22
|
- 外觀和 SegmentedControl 刻意不同:分頁是文字加底線(換內容),分段控制是灰底上的白塊(換顯示方式);不要用 CSS 把其中一個改成另一個的樣子。
|
|
22
23
|
- 分頁的字一律不換行;整排比外框寬時改成左右捲動。
|
|
23
24
|
- 內容切換:新內容的卡片依序浮起(外層加 `ui-rise-in`,並在切換時換 `key` 重新掛載)。
|
|
24
25
|
|
|
25
26
|
## 細節
|
|
26
27
|
|
|
27
|
-
- `count` 顯示在名稱右邊:一般字體的等寬數字、14 px、次要文字色、一般字重,選中時也一樣,讓名稱是主角。`hideUnit
|
|
28
|
-
-
|
|
28
|
+
- `count` 顯示在名稱右邊:一般字體的等寬數字、14 px、次要文字色、一般字重,選中時也一樣,讓名稱是主角。`hideUnit`:畫面上只寫數字,單位只給螢幕閱讀器和切換時的朗讀;DataTable 的 `summary` 用這個(畫面上是「全部 6 · 錯誤 4 · 要確認 2」,念成「全部 6 筆」)。`unit` 也可以傳函式,拿到數字後回傳單位,給有單複數的語言用:`unit: (n) => (n === 1 ? 'item' : 'items')`;傳字串時,數字是 1 而且語言有「1 <單位>」的翻譯(例如 `addMessages('en', { '1 項': '1 item' })`),就用那個。
|
|
29
|
+
- DataTable 的 `summary` 在手機上各項平均分配寬度,不換行。
|
|
29
30
|
- 左右捲動時選中的底線跟著捲,分頁不會互相重疊。還有分頁的那一側邊緣淡出(40 px),看得出可以往那邊捲;選中的分頁自動捲進畫面。
|
|
30
|
-
- 整排高 40 px(手機 48 px,觸控目標),和工具列上的按鈕、搜尋框一樣高;沒有底色,下緣一條 1 px `line`
|
|
31
|
+
- 整排高 40 px(手機 48 px,觸控目標),和工具列上的按鈕、搜尋框一樣高;沒有底色,下緣一條 1 px `line` 基準線。強制色彩模式(Windows 高對比)下,底線是 `Highlight`、基準線是 `CanvasText` 的框線。
|
|
31
32
|
- 選中的分頁:字變 `ink`、粗體,下方 2 px `accent-text` 底線(任何強調色都至少 3:1),換分頁時底線用水滴動畫滑過去;其他分頁 `ink-muted`,滑過時變 `ink`。
|
|
32
33
|
- DataTable 的 `summary` 例外:保留分段控制的樣子(`surface-sub` 灰底軌道、選中的 `surface` 白塊加 1 px `line-strong` 框),這是使用者為狀態摘要選的外觀。
|
|
33
34
|
- 切換動畫:水滴。靠近目標的一端先移動(120 ms),另一端慢 2.2 倍才跟上(440 ms),移動中略為變細,到位後恢復;全程是同一塊,邊緣清晰。
|
package/docs/TextField.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
- 自己給的 `aria-describedby`、`aria-invalid` 會保留,和提示或錯誤合在一起。
|
|
14
14
|
- 錯誤:`error` 給一句原因加修正方式(「Email 格式不正確,例如 name@example.com」)。離開欄位(blur)或送出表單時才設定,不在每次按鍵時設定;改正後立刻清掉。欄位多時用 `useFormErrors` 處理這些時機。
|
|
15
15
|
- 必填:`required` 會在標籤後加紅色星號(`danger`)。
|
|
16
|
+
- 金額、數量和網址的固定部分寫在框裡,不寫進標籤或 placeholder:`prefix="NT$"`(框的開頭)、`suffix="元"` 或 `".example.com"`(框的結尾)、`unit="GB"`(緊接在輸入的字後面)。三者都是灰字,螢幕閱讀器跟著說明念。
|
|
16
17
|
|
|
17
18
|
## 細節
|
|
18
19
|
|
|
@@ -20,3 +21,4 @@
|
|
|
20
21
|
- focus:2 px `focus` 實線外框(間隔 2 px),和其他控制項相同;邊框不變色。
|
|
21
22
|
- 錯誤時邊框變 `danger`,欄位內右側出現警示圖示,訊息用 `danger-text`。輸入框帶 `aria-invalid` 與 `aria-describedby`;錯誤訊息只在有錯誤時才放進頁面,是 `role="alert"` 的新節點,出現時念一次;同一句錯誤重新渲染不再念,換成另一句時念新的一句。說明(`hint`)是另一個節點,不會被念出。
|
|
22
23
|
- 停用:`surface-sub` 灰底、`ink-muted` 灰字、無邊框。
|
|
24
|
+
- 有 `prefix`、`suffix` 或 `unit` 時外框畫在外層,字和輸入框在同一個框裡(間距 8 px);focus 外框圍住整個框。`unit` 跟著輸入的字移動,沒有字時接在 placeholder 後面。
|
package/docs/agents.md
CHANGED
|
@@ -53,7 +53,7 @@ export default [ui.configs.recommended];
|
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
- `fonts.css` is about 500 KB of CSS (Noto Sans TC lists the characters of its 432 files). To keep it out of the CSS that blocks the first render, import `@seanyeh77/ui/fonts-latin.css` (Inter, Geist Mono; about 18 KB) instead and load the Chinese faces after the page with `import('@seanyeh77/ui/fonts-tc.css')` (a separate CSS file). Vite inlines font files under 4 KB; keep them as files with `build: { assetsInlineLimit: (f) => (f.endsWith('.woff2') ? false : undefined) }` in `vite.config`.
|
|
56
|
-
- ES modules only: TypeScript needs `moduleResolution` `bundler`, `node16` or `nodenext` (Vite and Next.js templates use `bundler`). React 19 is required. The module starts with `'use client'`; server code that only formats dates, numbers or text imports `@seanyeh77/ui/format`.
|
|
56
|
+
- ES modules only: TypeScript needs `moduleResolution` `bundler`, `node16` or `nodenext` (Vite and Next.js templates use `bundler`). React 19 is required. The module starts with `'use client'`; server code that only formats dates, numbers or text imports `@seanyeh77/ui/format`. Server-rendered pages put `themeScript` in an inline `<script>` in `<head>` so the stored theme and accent apply before the first paint (`theme.md`).
|
|
57
57
|
- The system's CSS is in the cascade layer `ui`: your unlayered CSS always wins. So delete the template's starter CSS (Vite's `index.css`, `App.css`) and put any reset in `@layer base { … }`. With Tailwind v4, start the main CSS with `@layer theme, base, ui, components, utilities;` (details in `theme.md`).
|
|
58
58
|
- The ESLint plugin depends only on ESLint and works with TypeScript 7. Templates that ship oxlint instead need `eslint` and an `eslint.config.js`, as above.
|
|
59
59
|
- pnpm may refuse a version published less than a day ago: `pnpm add @seanyeh77/ui@<version> --config.minimum-release-age=0`.
|
|
@@ -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.47.0/fonts.css">
|
|
69
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.0/tokens.css">
|
|
70
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.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.47.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.47.0/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.47.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/theme.md
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
主題設定有三個選項:自動(跟隨系統的 `prefers-color-scheme`)、淺色、深色。頁面載入時呼叫一次 `initTheme()`,由它在根元素設 `data-theme` 與 `color-scheme`(原生捲軸和表單控制項跟著變深);頁面不要自己設 `data-theme`。換主題用 `setTheme()`,換強調色用 `setAccent()`;自己做主題介面時,`storedTheme()`、`storedAccent()`、`pickedAccent()`(使用者有選才有值)讀目前的選擇,`resetAccent()` 回到 token 的預設。使用者沒選強調色時不寫 inline 變數,由 `tokens.css`(主題或 preset)決定。
|
|
11
11
|
|
|
12
|
+
Server render 的頁面(Next.js 等)在 `<head>` 放一段 inline script:`<script dangerouslySetInnerHTML={{ __html: themeScript }} />`(`themeScript` 從 `@seanyeh77/ui` 匯入,是一段字串)。它在第一次繪製前套上記住的主題和使用者選的強調色,頁面不會先閃一下淺色或預設強調色;用 preset 時在 server 的 `<html>` 寫 `data-theme-preset`,script 會保留。之後照常呼叫 `initTheme()`。
|
|
13
|
+
|
|
12
14
|
| 用途 | Token |
|
|
13
15
|
|---|---|
|
|
14
16
|
| 頁面底色 | `bg` |
|
|
@@ -115,8 +117,9 @@ import './ui.css';
|
|
|
115
117
|
- 線寬:Phosphor 的線寬固定,不另外調整;自訂的 24 × 24 線條圖示用 2 px(`icon-stroke`)。
|
|
116
118
|
- 用法:`h(UI.Icon, { name: 'house' })`,加 `filled: true` 用實心版;名稱照 Phosphor,內建 113 個,`npx @seanyeh77/ui-cli docs icons` 印出全部名稱(也接受 40 個 Lucide 名稱,例如 `trash-2`)。元件的 `icon` 屬性接受同樣的名稱,或自訂圖示的 24 px path。
|
|
117
119
|
- 自訂圖示 `d` 傳 SVG 標記字串(以 `<` 開頭)時會當成 HTML 直接放進 `<svg>`:只傳自己程式碼裡寫死的圖示,絕不傳使用者輸入或外部資料的字串。
|
|
118
|
-
- 載入:每個圖示是一個獨立的模組,有 build 的專案只打包頁面用到的圖示,用法不變。元件固定會顯示的圖示(下拉箭頭、關閉的 x
|
|
119
|
-
-
|
|
120
|
+
- 載入:每個圖示是一個獨立的模組,有 build 的專案只打包頁面用到的圖示,用法不變。元件固定會顯示的圖示(下拉箭頭、關閉的 x、勾號等)跟著元件一起打包,在瀏覽器裡第一次畫面就有。用 `name` 或 `icon` 指定的其他圖示在第一次顯示時才載入:載入前是同樣大小的空白方框(版面不會跳動),載入後同一個圖示之後都立即顯示。
|
|
121
|
+
- Server render 只畫 `preloadIcons` 載入過的圖示,其他(包括元件固定的圖示)是空白方框,hydrate 後立即補上:server 匯入整個套件、瀏覽器只打包用到的模組,兩邊有的圖示不同,只有這樣 hydrate 才不會不一致。
|
|
122
|
+
- 首屏的圖示想在第一次畫面就出現時,render 前先 `await preloadIcons(['house', 'gear'])`;有 server render 時 server 和瀏覽器(`hydrateRoot` 之前)都 await 同一組名稱,例如放在兩邊都 import 的模組。不呼叫也能用,只是晚一個網路來回。import `icons` 的頁面會帶入全部圖示,所以只在真的需要全部名稱時才 import。`bundle.js` 內含全部圖示,一律立即顯示。
|
|
120
123
|
|
|
121
124
|
## 外觀設定
|
|
122
125
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanyeh77/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.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.47.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "node scripts/theme-defaults.ts && tsdown && node scripts/postbuild.ts",
|