@seanyeh77/ui 0.49.0 → 0.50.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.
@@ -1 +1 @@
1
- {"version":3,"file":"chart.js","names":[],"sources":["../../src/internal/chart.tsx"],"sourcesContent":["import * as React from 'react';\nimport { format } from '../format';\nimport { reduced, useMedia } from './util';\nimport type { KpiCardProps } from '../components/KpiCard/KpiCard';\n\n/** 0 → 1 with an ease-out over ms, restarted when target changes; 1 at once with reduced motion. */\nexport function useCountUp(target: unknown, ms: number): number {\n // Reduced motion from useMedia: false on the server and while hydrating, so the markup matches; then the final value.\n const still = useMedia('(prefers-reduced-motion: reduce)');\n const [t, setT] = React.useState(0);\n React.useEffect(() => {\n if (reduced()) return;\n let t0: number | null = null;\n let raf = 0;\n const step = (now: number) => {\n t0 ??= now;\n const x = Math.min(1, (now - t0) / ms);\n setT(1 - (1 - x) ** 3);\n if (x < 1) raf = requestAnimationFrame(step);\n };\n raf = requestAnimationFrame(step);\n return () => cancelAnimationFrame(raf);\n }, [target, ms]);\n return still ? 1 : t;\n}\n\n/** Decimals the axis labels need so that ticks a step apart read differently (0.5, 1, 1.5). */\nexport const tickDecimals = (top: number): number => Math.min(3, (String(+(top / 4).toPrecision(6)).split('.')[1] ?? '').length);\n\nexport type Point = [number, number];\n\n/** A smooth SVG path (Catmull-Rom as cubic Béziers) through the points. */\nexport function smoothPath(p: Point[]): string {\n const f = (q: Point) => q[0].toFixed(1) + ',' + q[1].toFixed(1);\n if (p.length < 2) return p.length ? 'M' + f(p[0]) : '';\n let d = 'M' + f(p[0]);\n for (let i = 0; i < p.length - 1; i++) {\n const p0 = p[i - 1] || p[i];\n const p1 = p[i];\n const p2 = p[i + 1];\n const p3 = p[i + 2] || p2;\n d += ` C${f([p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6])} ${f([p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6])} ${f(p2)}`;\n }\n return d;\n}\n\nconst CHART = ['var(--chart-1)', 'var(--chart-2)', 'var(--chart-3)', 'var(--chart-4)'];\n/** The color of series i. */\nexport const seriesColor = (i: number): string => CHART[i % CHART.length];\n/** Grid lines at these fractions of the axis maximum. */\nexport const TICKS = [0, 0.25, 0.5, 0.75, 1];\n\n/** KPI cards are the only place that abbreviates large numbers (format rules). */\nexport function kpiText(v: number, p: KpiCardProps, dec?: number): string {\n const big = p.compact !== false && Math.abs(p.value) >= 1e4;\n if (p.format === 'money') return format.money(v, { compact: big, currency: p.currency, like: p.value });\n if (p.format === 'percent') return format.number(v, dec || 1);\n return big ? format.compact(v, p.value) : format.number(v, dec);\n}\n\n/** Shrinks the KPI number (31 px down to 20 px) when the final value is wider than the card. */\nexport function useFitText(ref: React.RefObject<HTMLElement | null>, deps: React.DependencyList): void {\n React.useLayoutEffect(() => {\n const el = ref.current;\n if (!el) return;\n const fit = () => {\n el.style.fontSize = '';\n const base = parseFloat(getComputedStyle(el).fontSize) || 31;\n const sizer = el.querySelector<HTMLElement>('.ui-kpi-sizer');\n const unit = el.querySelector<HTMLElement>('.ui-kpi-unit');\n const need = (sizer ? sizer.scrollWidth : 0) + (unit ? unit.offsetWidth + 4 : 0);\n const have = el.clientWidth;\n const next = need > have && have > 0 ? Math.max(20, Math.floor((base * have) / need)) : null;\n el.style.fontSize = next ? next + 'px' : '';\n };\n fit();\n const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(fit) : null;\n ro?.observe((el.parentNode as Element | null) || el);\n return () => ro?.disconnect();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller lists what changes the text\n }, deps);\n}\n\ninterface ChartTipRow {\n name: React.ReactNode;\n value: React.ReactNode;\n color?: string;\n}\n\nexport function ChartTip({ title, rows, style }: { title?: React.ReactNode; rows: ChartTipRow[]; style?: React.CSSProperties }) {\n return (\n <div className=\"ui-chart-tip\" style={style}>\n {title ? <div className=\"ui-chart-tip-title\">{title}</div> : null}\n {rows.map((r, i) => (\n <div key={i} className=\"ui-chart-tip-row\">\n {r.color ? <span className=\"ui-chart-swatch\" style={{ background: r.color }} /> : null}\n <span className=\"ui-chart-tip-name\">{r.name}</span>\n <span className=\"ui-chart-tip-val\">{r.value}</span>\n </div>\n ))}\n </div>\n );\n}\n\n/** The y axis: tick values from lo to top, a step of 1, 2 or 5 times a power of ten (never 2.5: no 12.5 or 37.5),\n * 3 to 5 steps, the top the first tick at or above the largest value (128 萬 gets a 150 萬 axis, not 200 萬). Whole\n * steps unless the values need decimals (dec > 0) or the range is under 3. A given top that the steps do not divide\n * gets 4 equal steps. */\nexport function axisTicks(lo: number, hi: number, o: { top?: number; dec?: number } = {}): number[] {\n const range = (o.top ?? hi) - lo;\n if (!(range > 0)) return [lo, lo + 1];\n const whole = !o.dec && range >= 3;\n const raw = range / 5;\n let step = 0;\n for (let e = 10 ** Math.floor(Math.log10(raw)); !step; e *= 10)\n for (const m of [1, 2, 5]) {\n const s = m * e;\n if (s >= raw && (!whole || Number.isInteger(s)) && Math.ceil(range / s - 1e-9) <= 5) {\n step = s;\n break;\n }\n }\n let n = Math.max(1, Math.ceil(range / step - 1e-9));\n if (o.top != null && Math.abs(n * step - range) > step * 1e-6) {\n n = 4;\n step = range / 4;\n }\n // Rounded so 0.1 + 0.2 does not show as 0.30000000000000004.\n return Array.from({ length: n + 1 }, (_, i) => +(lo + i * step).toPrecision(12));\n}\n\n/** How a chart writes a value: 'number' (1,280,000) or 'compact' (128 萬, 1.5 億; 1.3M in English). */\nexport type ChartFormat = 'number' | 'compact';\n/** A tick or tooltip value as text, in the chart's format. */\nexport function chartNumber(v: number, fmt: ChartFormat | undefined, dec?: number): string {\n return fmt === 'compact' && Math.abs(v) >= 1e4 ? format.compact(v) : format.number(v, dec);\n}\n/** Decimals the ticks need so that neighbours read differently (0.5, 1, 1.5). */\nexport const ticksDecimals = (ticks: number[]): number => Math.min(3, Math.max(0, ...ticks.map((t) => (String(+t.toPrecision(6)).split('.')[1] ?? '').length)));\n\n/** The width (px) the y axis labels need: measured from the drawn labels (a font that loads late, text spacing a reader\n * adds), else estimated from their length where nothing is measured (jsdom). Measured again when the labels change\n * or the text's size does. */\nexport function useAxisWidth(ref: React.RefObject<HTMLElement | null>, labels: string[], scaleKey: number | string = ''): number {\n // Geist Mono 12 px: about 7.5 px a character; CJK (萬、億) about 12 px.\n const guess = Math.ceil(Math.max(0, ...labels.map((t) => [...t].reduce((w, c) => w + (c.charCodeAt(0) > 0x2e80 ? 12 : 7.5), 0))));\n const [w, setW] = React.useState(guess);\n // scaleKey: an SVG drawn at another width than its box is scaled, and so are its labels: measured again once it\n // has its real width.\n const key = labels.join('|') + '|' + scaleKey;\n React.useLayoutEffect(() => {\n const root = ref.current;\n if (!root) return;\n const read = () => {\n let m = 0;\n for (const el of root.querySelectorAll<Element>('.ui-chart-tick')) m = Math.max(m, el.getBoundingClientRect().width);\n // Always the last reading, never kept from an earlier one: the width depends only on the labels as drawn, not\n // on whether the fonts were ready at the first reading (the plot's width does not change the labels').\n setW(m > 0 ? Math.ceil(m) : guess);\n };\n read();\n const probe = root.querySelector('.ui-chart-tick');\n if (!probe || typeof ResizeObserver !== 'function') return;\n // SVG text has no box to observe: the root's size stands in (text spacing and zoom change it too), and fonts.\n const ro = new ResizeObserver(read);\n ro.observe(root);\n document.fonts?.ready.then(read).catch(() => {});\n return () => ro.disconnect();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- measured again when the labels change\n }, [key]);\n return w;\n}\n\n/** Rounds an axis maximum up to 2, 4, 5, 8 or 10 times a power of ten. */\nexport function niceMax(v: number): number {\n const e = 10 ** Math.floor(Math.log10(v || 1));\n const n = Math.ceil(v / e);\n return (n <= 2 ? 2 : n <= 4 ? 4 : n <= 5 ? 5 : n <= 8 ? 8 : 10) * e;\n}\n\n/** ← → (and Home, End) on a chart: the item to show next, or null for any other key. */\nexport function chartKey(e: React.KeyboardEvent, at: number, n: number): number | null {\n if (e.altKey || e.metaKey || e.ctrlKey || !n) return null;\n const i = Math.max(0, at);\n const to =\n e.key === 'ArrowRight' ? Math.min(n - 1, i + 1) : e.key === 'ArrowLeft' ? Math.max(0, i - 1) : e.key === 'Home' ? 0 : e.key === 'End' ? n - 1 : null;\n if (to != null) e.preventDefault();\n return to;\n}\n\n/** The chart's values as a table for screen readers (visually hidden): one row per item or point, the first cell its\n * name. Charts with arrow keys are role=\"application\", which some screen readers read only key by key; this table\n * reads like any other. */\nexport function ChartTable({ caption, head, rows }: { caption: string; head: string[]; rows: React.ReactNode[][] }) {\n if (!rows.length) return null;\n // ARIA table roles on divs: no native <table> (the system replaces it), and the hiding box keeps its 1 px width.\n return (\n <div className=\"ui-visually-hidden\" role=\"table\" aria-label={caption}>\n <div role=\"row\">\n {head.map((h, i) => (\n <span key={i} role=\"columnheader\">\n {h}\n </span>\n ))}\n </div>\n {rows.map((r, i) => (\n <div key={i} role=\"row\">\n <span role=\"rowheader\">{r[0]}</span>\n {r.slice(1).map((c, j) => (\n <span key={j} role=\"cell\">\n {c}\n </span>\n ))}\n </div>\n ))}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,WAAW,QAAiB,IAAoB;CAE9D,MAAM,QAAQ,SAAS,kCAAkC;CACzD,MAAM,CAAC,GAAG,QAAQ,MAAM,SAAS,CAAC;CAClC,MAAM,gBAAgB;EACpB,IAAI,QAAQ,GAAG;EACf,IAAI,KAAoB;EACxB,IAAI,MAAM;EACV,MAAM,QAAQ,QAAgB;GAC5B,OAAO;GACP,MAAM,IAAI,KAAK,IAAI,IAAI,MAAM,MAAM,EAAE;GACrC,KAAK,KAAK,IAAI,MAAM,CAAC;GACrB,IAAI,IAAI,GAAG,MAAM,sBAAsB,IAAI;EAC7C;EACA,MAAM,sBAAsB,IAAI;EAChC,aAAa,qBAAqB,GAAG;CACvC,GAAG,CAAC,QAAQ,EAAE,CAAC;CACf,OAAO,QAAQ,IAAI;AACrB;;AAQA,SAAgB,WAAW,GAAoB;CAC7C,MAAM,KAA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AEzB,OACE,qBAAC,OAAD;EAAK,WAAU;EAAqB,MAAK;EAAQ,cAAY;EAA7D,UAAA,CACE,oBAAC,OAAD;GAAK,MAAK;GACP,UAAA,KAAK,KAAK,GAAG,MACZ,oBAAC,QAAD;IAAc,MAAK;IAChB,UAAA;GACG,GAFK,CAEL,CACP;EACE,CAAA,GACJ,KAAK,KAAK,GAAG,MACZ,qBAAC,OAAD;GAAa,MAAK;GAAlB,UAAA,CACE,oBAAC,QAAD;IAAM,MAAK;IAAa,UAAA,EAAE;GAAS,CAAA,GAClC,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,MAClB,oBAAC,QAAD;IAAc,MAAK;IAChB,UAAA;GACG,GAFK,CAEL,CACP,CACE;EAPK,GAAA,CAOL,CACN,CACE;;AAET"}
1
+ {"version":3,"file":"chart.js","names":[],"sources":["../../src/internal/chart.tsx"],"sourcesContent":["import * as React from 'react';\nimport { format } from '../format';\nimport { cssZoom, reduced, useMedia } from './util';\nimport type { KpiCardProps } from '../components/KpiCard/KpiCard';\n\n/** 0 → 1 with an ease-out over ms, restarted when target changes; 1 at once with reduced motion. */\nexport function useCountUp(target: unknown, ms: number): number {\n // Reduced motion from useMedia: false on the server and while hydrating, so the markup matches; then the final value.\n const still = useMedia('(prefers-reduced-motion: reduce)');\n const [t, setT] = React.useState(0);\n React.useEffect(() => {\n if (reduced()) return;\n let t0: number | null = null;\n let raf = 0;\n const step = (now: number) => {\n t0 ??= now;\n const x = Math.min(1, (now - t0) / ms);\n setT(1 - (1 - x) ** 3);\n if (x < 1) raf = requestAnimationFrame(step);\n };\n raf = requestAnimationFrame(step);\n return () => cancelAnimationFrame(raf);\n }, [target, ms]);\n return still ? 1 : t;\n}\n\n/** Decimals the axis labels need so that ticks a step apart read differently (0.5, 1, 1.5). */\nexport const tickDecimals = (top: number): number => Math.min(3, (String(+(top / 4).toPrecision(6)).split('.')[1] ?? '').length);\n\nexport type Point = [number, number];\n\n/** A smooth SVG path (Catmull-Rom as cubic Béziers) through the points. */\nexport function smoothPath(p: Point[]): string {\n const f = (q: Point) => q[0].toFixed(1) + ',' + q[1].toFixed(1);\n if (p.length < 2) return p.length ? 'M' + f(p[0]) : '';\n let d = 'M' + f(p[0]);\n for (let i = 0; i < p.length - 1; i++) {\n const p0 = p[i - 1] || p[i];\n const p1 = p[i];\n const p2 = p[i + 1];\n const p3 = p[i + 2] || p2;\n d += ` C${f([p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6])} ${f([p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6])} ${f(p2)}`;\n }\n return d;\n}\n\nconst CHART = ['var(--chart-1)', 'var(--chart-2)', 'var(--chart-3)', 'var(--chart-4)'];\n/** The color of series i. */\nexport const seriesColor = (i: number): string => CHART[i % CHART.length];\n/** Grid lines at these fractions of the axis maximum. */\nexport const TICKS = [0, 0.25, 0.5, 0.75, 1];\n\n/** KPI cards are the only place that abbreviates large numbers (format rules). */\nexport function kpiText(v: number, p: KpiCardProps, dec?: number): string {\n const big = p.compact !== false && Math.abs(p.value) >= 1e4;\n if (p.format === 'money') return format.money(v, { compact: big, currency: p.currency, like: p.value });\n if (p.format === 'percent') return format.number(v, dec || 1);\n return big ? format.compact(v, p.value) : format.number(v, dec);\n}\n\n/** Shrinks the KPI number (31 px down to 20 px) when the final value is wider than the card. */\nexport function useFitText(ref: React.RefObject<HTMLElement | null>, deps: React.DependencyList): void {\n React.useLayoutEffect(() => {\n const el = ref.current;\n if (!el) return;\n const fit = () => {\n el.style.fontSize = '';\n const base = parseFloat(getComputedStyle(el).fontSize) || 31;\n const sizer = el.querySelector<HTMLElement>('.ui-kpi-sizer');\n const unit = el.querySelector<HTMLElement>('.ui-kpi-unit');\n const need = (sizer ? sizer.scrollWidth : 0) + (unit ? unit.offsetWidth + 4 : 0);\n const have = el.clientWidth;\n const next = need > have && have > 0 ? Math.max(20, Math.floor((base * have) / need)) : null;\n el.style.fontSize = next ? next + 'px' : '';\n };\n fit();\n const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(fit) : null;\n ro?.observe((el.parentNode as Element | null) || el);\n return () => ro?.disconnect();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller lists what changes the text\n }, deps);\n}\n\ninterface ChartTipRow {\n name: React.ReactNode;\n value: React.ReactNode;\n color?: string;\n}\n\nexport function ChartTip({ title, rows, style }: { title?: React.ReactNode; rows: ChartTipRow[]; style?: React.CSSProperties }) {\n return (\n <div className=\"ui-chart-tip\" style={style}>\n {title ? <div className=\"ui-chart-tip-title\">{title}</div> : null}\n {rows.map((r, i) => (\n <div key={i} className=\"ui-chart-tip-row\">\n {r.color ? <span className=\"ui-chart-swatch\" style={{ background: r.color }} /> : null}\n <span className=\"ui-chart-tip-name\">{r.name}</span>\n <span className=\"ui-chart-tip-val\">{r.value}</span>\n </div>\n ))}\n </div>\n );\n}\n\n/** The y axis: tick values from lo to top, a step of 1, 2 or 5 times a power of ten (never 2.5: no 12.5 or 37.5),\n * 3 to 5 steps, the top the first tick at or above the largest value (128 萬 gets a 150 萬 axis, not 200 萬). Whole\n * steps unless the values need decimals (dec > 0) or the range is under 3. A given top that the steps do not divide\n * gets 4 equal steps. */\nexport function axisTicks(lo: number, hi: number, o: { top?: number; dec?: number } = {}): number[] {\n const range = (o.top ?? hi) - lo;\n if (!(range > 0)) return [lo, lo + 1];\n const whole = !o.dec && range >= 3;\n const raw = range / 5;\n let step = 0;\n for (let e = 10 ** Math.floor(Math.log10(raw)); !step; e *= 10)\n for (const m of [1, 2, 5]) {\n const s = m * e;\n if (s >= raw && (!whole || Number.isInteger(s)) && Math.ceil(range / s - 1e-9) <= 5) {\n step = s;\n break;\n }\n }\n let n = Math.max(1, Math.ceil(range / step - 1e-9));\n if (o.top != null && Math.abs(n * step - range) > step * 1e-6) {\n n = 4;\n step = range / 4;\n }\n // Rounded so 0.1 + 0.2 does not show as 0.30000000000000004.\n return Array.from({ length: n + 1 }, (_, i) => +(lo + i * step).toPrecision(12));\n}\n\n/** How a chart writes a value: 'number' (1,280,000) or 'compact' (128 萬, 1.5 億; 1.3M in English). */\nexport type ChartFormat = 'number' | 'compact';\n/** A tick or tooltip value as text, in the chart's format. */\nexport function chartNumber(v: number, fmt: ChartFormat | undefined, dec?: number): string {\n return fmt === 'compact' && Math.abs(v) >= 1e4 ? format.compact(v) : format.number(v, dec);\n}\n/** Decimals the ticks need so that neighbours read differently (0.5, 1, 1.5). */\nexport const ticksDecimals = (ticks: number[]): number => Math.min(3, Math.max(0, ...ticks.map((t) => (String(+t.toPrecision(6)).split('.')[1] ?? '').length)));\n\n/** The width (px) the y axis labels need: measured from the drawn labels (a font that loads late, text spacing a reader\n * adds), else estimated from their length where nothing is measured (jsdom). Measured again when the labels change\n * or the text's size does. */\nexport function useAxisWidth(ref: React.RefObject<HTMLElement | null>, labels: string[], scaleKey: number | string = ''): number {\n // Geist Mono 12 px: about 7.5 px a character; CJK (萬、億) about 12 px.\n const guess = Math.ceil(Math.max(0, ...labels.map((t) => [...t].reduce((w, c) => w + (c.charCodeAt(0) > 0x2e80 ? 12 : 7.5), 0))));\n const [w, setW] = React.useState(guess);\n // scaleKey: an SVG drawn at another width than its box is scaled, and so are its labels: measured again once it\n // has its real width.\n const key = labels.join('|') + '|' + scaleKey;\n React.useLayoutEffect(() => {\n const root = ref.current;\n if (!root) return;\n const read = () => {\n let m = 0;\n for (const el of root.querySelectorAll<Element>('.ui-chart-tick')) m = Math.max(m, el.getBoundingClientRect().width);\n // Always the last reading, never kept from an earlier one: the width depends only on the labels as drawn, not\n // on whether the fonts were ready at the first reading (the plot's width does not change the labels').\n setW(m > 0 ? Math.ceil(m / cssZoom(root)) : guess);\n };\n read();\n const probe = root.querySelector('.ui-chart-tick');\n if (!probe || typeof ResizeObserver !== 'function') return;\n // SVG text has no box to observe: the root's size stands in (text spacing and zoom change it too), and fonts.\n const ro = new ResizeObserver(read);\n ro.observe(root);\n document.fonts?.ready.then(read).catch(() => {});\n return () => ro.disconnect();\n // eslint-disable-next-line react-hooks/exhaustive-deps -- measured again when the labels change\n }, [key]);\n return w;\n}\n\n/** Rounds an axis maximum up to 2, 4, 5, 8 or 10 times a power of ten. */\nexport function niceMax(v: number): number {\n const e = 10 ** Math.floor(Math.log10(v || 1));\n const n = Math.ceil(v / e);\n return (n <= 2 ? 2 : n <= 4 ? 4 : n <= 5 ? 5 : n <= 8 ? 8 : 10) * e;\n}\n\n/** ← → (and Home, End) on a chart: the item to show next, or null for any other key. */\nexport function chartKey(e: React.KeyboardEvent, at: number, n: number): number | null {\n if (e.altKey || e.metaKey || e.ctrlKey || !n) return null;\n const i = Math.max(0, at);\n const to =\n e.key === 'ArrowRight' ? Math.min(n - 1, i + 1) : e.key === 'ArrowLeft' ? Math.max(0, i - 1) : e.key === 'Home' ? 0 : e.key === 'End' ? n - 1 : null;\n if (to != null) e.preventDefault();\n return to;\n}\n\n/** The chart's values as a table for screen readers (visually hidden): one row per item or point, the first cell its\n * name. Charts with arrow keys are role=\"application\", which some screen readers read only key by key; this table\n * reads like any other. */\nexport function ChartTable({ caption, head, rows }: { caption: string; head: string[]; rows: React.ReactNode[][] }) {\n if (!rows.length) return null;\n // ARIA table roles on divs: no native <table> (the system replaces it), and the hiding box keeps its 1 px width.\n return (\n <div className=\"ui-visually-hidden\" role=\"table\" aria-label={caption}>\n <div role=\"row\">\n {head.map((h, i) => (\n <span key={i} role=\"columnheader\">\n {h}\n </span>\n ))}\n </div>\n {rows.map((r, i) => (\n <div key={i} role=\"row\">\n <span role=\"rowheader\">{r[0]}</span>\n {r.slice(1).map((c, j) => (\n <span key={j} role=\"cell\">\n {c}\n </span>\n ))}\n </div>\n ))}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,WAAW,QAAiB,IAAoB;CAE9D,MAAM,QAAQ,SAAS,kCAAkC;CACzD,MAAM,CAAC,GAAG,QAAQ,MAAM,SAAS,CAAC;CAClC,MAAM,gBAAgB;EACpB,IAAI,QAAQ,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AAE,WAAW,CAAC,GAAG,OAAO;CACrD,MAAM,IAAI,KAAK,IAAI,GAAG,EAAE;CACxB,MAAM,KACJ,EAAE,QAAQ,eAAe,KAAK,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,cAAc,KAAK,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,SAAS,IAAI,EAAE,QAAQ,QAAQ,IAAI,IAAI;CAClJ,IAAI,MAAM,MAAM,EAAE,eAAe;CACjC,OAAO;AACT;;;;AAKA,SAAgB,WAAW,EAAE,SAAS,MAAM,QAAwE;CAClH,IAAI,CAAC,KAAK,QAAQ,OAAO;CAEzB,OACE,qBAAC,OAAD;EAAK,WAAU;EAAqB,MAAK;EAAQ,cAAY;EAA7D,UAAA,CACE,oBAAC,OAAD;GAAK,MAAK;GACP,UAAA,KAAK,KAAK,GAAG,MACZ,oBAAC,QAAD;IAAc,MAAK;IAChB,UAAA;GACG,GAFK,CAEL,CACP;EACE,CAAA,GACJ,KAAK,KAAK,GAAG,MACZ,qBAAC,OAAD;GAAa,MAAK;GAAlB,UAAA,CACE,oBAAC,QAAD;IAAM,MAAK;IAAa,UAAA,EAAE;GAAS,CAAA,GAClC,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,MAClB,oBAAC,QAAD;IAAc,MAAK;IAChB,UAAA;GACG,GAFK,CAEL,CACP,CACE;EAPK,GAAA,CAOL,CACN,CACE;;AAET"}
@@ -28,6 +28,13 @@ function monoNums(text, nums) {
28
28
  children: nums[k]
29
29
  }, i) : t);
30
30
  }
31
+ /** The CSS zoom in effect on an element (ConsoleLayout zooms large screens up to 1.5×): 1 where there is none or the
32
+ * browser cannot tell. getBoundingClientRect() and pointer positions are in screen px; divide a length taken from them
33
+ * by this to get the CSS px that widths, positions and scrollTop inside the element use. */
34
+ function cssZoom(el) {
35
+ const z = el?.currentCSSZoom;
36
+ return typeof z === "number" && z > 0 ? z : 1;
37
+ }
31
38
  function reduced() {
32
39
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
33
40
  }
@@ -121,6 +128,6 @@ function nodeText(node) {
121
128
  function keepUnits(text) {
122
129
  return text.replace(/(\d) (?=°|%|‰|[A-Za-zµΩ]{1,4}(?![A-Za-z])|[\u3400-\u9fff])/g, "$1\xA0").replace(/((?:^|[^\w$])(?:[A-Z]{2}\$|[$€£¥₩])) (?=[-−]?\d)/g, "$1\xA0");
123
130
  }
124
- export { IS_MAC, SHORTCUT, TOUCH_ONLY, browserKey, copyText, cx, digits, idPart, keepUnits, monoNums, nodeText, reduced, resizeObserver, seenOnly, useFontLoads, useMedia, useNarrow };
131
+ export { IS_MAC, SHORTCUT, TOUCH_ONLY, browserKey, copyText, cssZoom, cx, digits, idPart, keepUnits, monoNums, nodeText, reduced, resizeObserver, seenOnly, useFontLoads, useMedia, useNarrow };
125
132
 
126
133
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","names":[],"sources":["../../src/internal/util.tsx"],"sourcesContent":["import * as React from 'react';\n\n/** A value (a row or node id, a file path) as part of an element id: no spaces, so aria-owns, aria-controls and\n * aria-labelledby, which split their value at spaces, still find it. */\nexport const idPart = (s: string): string => encodeURIComponent(s);\n\n/** Joins the truthy class names. */\nexport function cx(...names: unknown[]): string {\n return names.filter(Boolean).join(' ');\n}\n\n// Text that is only seen: drawn by CSS (::before), so it is neither in the page's text (copy, innerText, text-reading\n// tools) nor read aloud. The readable version goes beside it, visually hidden. Numbers keep Geist Mono.\nexport function seenOnly(text: string, nums: string[]): React.ReactNode[] {\n return splitMarks(text).map(([t, k], i) => <span key={i} className={cx('ui-seen', k >= 0 && 'ui-num')} data-text={k >= 0 ? nums[k] : t} />);\n}\n\n// A translated sentence cut at its number marks (\\u0001, \\u0002, \\u0003): [text, -1] or [mark, its index].\nfunction splitMarks(text: string): [string, number][] {\n return (\n text\n // eslint-disable-next-line no-control-regex -- the marks are control characters on purpose\n .split(/(\\u0001|\\u0002|\\u0003)/)\n .filter(Boolean)\n .map((t) => [t, ['\\u0001', '\\u0002', '\\u0003'].indexOf(t)])\n );\n}\n\n// Puts the numbers of a translated sentence in Geist Mono and leaves the words in the text font.\n// The sentence marks each number with \\u0001, \\u0002 or \\u0003 in the order of nums.\nexport function monoNums(text: string, nums: React.ReactNode[]): React.ReactNode[] {\n return splitMarks(text).map(([t, k], i) =>\n k >= 0 ? (\n <span key={i} className=\"ui-num\">\n {nums[k]}\n </span>\n ) : (\n t\n ),\n );\n}\n\n/** localStorage get (no value) or set; null when storage is blocked. */\nexport function store(key: string, value?: string): string | null {\n try {\n if (value === undefined) return localStorage.getItem(key);\n localStorage.setItem(key, value);\n } catch {\n /* storage blocked (private mode, sandboxed frame) */\n }\n return null;\n}\n\nexport function reduced(): boolean {\n return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nconst nav = typeof navigator !== 'undefined' ? (navigator as Navigator & { userAgentData?: { platform?: string } }) : undefined;\nexport const IS_MAC = /mac|iphone|ipad/i.test(nav?.userAgentData?.platform || nav?.platform || nav?.userAgent || '');\n/** A touch screen as the main input (phones, tablets): no keyboard to press a shortcut with, no hover. Phones and\n * tablets report (pointer: coarse); (hover: none) alone is not used, since Chromium keeps it after touch emulation is\n * turned off and a mouse would then lose its Tooltips. */\nexport const TOUCH_ONLY = '(pointer: coarse)';\nexport const SHORTCUT = IS_MAC ? '⌘K' : 'Ctrl K';\n\n/** Matches a media query and follows changes. false on the server and in the first browser render while hydrating,\n * so the markup matches; then the real match. */\nexport function useMedia(query: string): boolean {\n const sub = React.useCallback(\n (f: () => void) => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {};\n const m = window.matchMedia(query);\n m.addEventListener('change', f);\n return () => m.removeEventListener('change', f);\n },\n [query],\n );\n const get = React.useCallback(() => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(query).matches, [query]);\n return React.useSyncExternalStore(sub, get, serverFalse);\n}\nconst serverFalse = () => false;\n\n/** A ResizeObserver, or null where there is none (jsdom, old browsers): the first measure then stays. */\nexport function resizeObserver(cb: ResizeObserverCallback): ResizeObserver | null {\n return typeof ResizeObserver === 'function' ? new ResizeObserver(cb) : null;\n}\n\n// Web fonts that finished loading since this module ran: text measured on a canvas before then used the fallback font.\nlet fontLoads = 0;\nconst fontListeners = new Set<() => void>();\nif (typeof document !== 'undefined' && typeof document.fonts?.addEventListener === 'function') {\n document.fonts.addEventListener('loadingdone', () => {\n fontLoads++;\n for (const f of fontListeners) f();\n });\n}\nconst subFonts = (f: () => void) => {\n fontListeners.add(f);\n return () => fontListeners.delete(f);\n};\nconst getFonts = () => fontLoads;\nconst serverZero = () => 0;\n\n/** A number that goes up each time web fonts finish loading (document.fonts `loadingdone`). Layout worked out from text\n * measured on a canvas depends on it, so it is worked out again with the loaded fonts instead of keeping the fallback\n * font's widths. 0 on the server and while hydrating. */\nexport function useFontLoads(): number {\n return React.useSyncExternalStore(subFonts, getFonts, serverZero);\n}\n\n/** True under 600 px, the same width where cards stack. */\nexport function useNarrow(): boolean {\n return useMedia('(max-width: 599px)');\n}\n\nexport async function copyText(text: string): Promise<void> {\n if (navigator.clipboard?.writeText) {\n try {\n return await navigator.clipboard.writeText(text);\n } catch {\n /* fall back below (insecure context, denied permission) */\n }\n }\n const t = document.createElement('textarea');\n t.value = text;\n t.setAttribute('readonly', '');\n t.style.position = 'fixed';\n t.style.opacity = '0';\n document.body.appendChild(t);\n t.select();\n try {\n if (!document.execCommand('copy')) throw new Error('copy failed');\n } finally {\n document.body.removeChild(t);\n }\n}\n\n/** Text with every number in Geist Mono and the words in the text font, for labels that mix both (「第 1 週」). */\nexport function digits(text: string, numbers = /(\\d[\\d,.:/]*)/): React.ReactNode[] {\n return text.split(numbers).map((t, i) =>\n i % 2 ? (\n <span key={i} className=\"ui-num\">\n {t}\n </span>\n ) : (\n t\n ),\n );\n}\n\n/** Alt, Meta or Ctrl held: the key belongs to the browser or the system (Alt+← goes back a page), not to the widget. */\nexport const browserKey = (e: { altKey: boolean; metaKey: boolean; ctrlKey: boolean }): boolean => e.altKey || e.metaKey || e.ctrlKey;\n\n/** The words in a React node, as a screen reader would read them: strings and numbers, through elements' children. */\nexport function nodeText(node: React.ReactNode): string {\n if (node == null || typeof node === 'boolean') return '';\n if (typeof node === 'string' || typeof node === 'number') return String(node);\n if (Array.isArray(node)) return node.map(nodeText).join('');\n if (React.isValidElement(node)) {\n const props = node.props as { 'aria-label'?: string; label?: unknown; children?: React.ReactNode };\n if (typeof props['aria-label'] === 'string') return props['aria-label'];\n return nodeText(props.children) || (typeof props.label === 'string' ? props.label : '');\n }\n return '';\n}\n\n/** A number and its unit never break apart: the space between them becomes a no-break space (U+00A0), so\n * 「100 MB」「29 °C」「3 筆」 do not wrap as 「100 / MB」 on a phone, nor a currency before the number (「NT$ 1,280」).\n * Leaves every other space alone. */\nexport function keepUnits(text: string): string {\n return text\n .replace(/(\\d) (?=°|%|‰|[A-Za-zµΩ]{1,4}(?![A-Za-z])|[\\u3400-\\u9fff])/g, '$1\\u00a0')\n .replace(/((?:^|[^\\w$])(?:[A-Z]{2}\\$|[$€£¥₩])) (?=[-−]?\\d)/g, '$1\\u00a0');\n}\n"],"mappings":";;;;;;AAIA,MAAa,UAAU,MAAsB,mBAAmB,CAAC;;AAGjE,SAAgB,GAAG,GAAG,OAA0B;CAC9C,OAAO,MAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAIA,SAAgB,SAAS,MAAc,MAAmC;CACxE,OAAO,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,MAAM,oBAAC,QAAD;EAAc,WAAW,GAAG,WAAW,KAAK,KAAK,QAAQ;EAAG,aAAW,KAAK,IAAI,KAAK,KAAK;CAAI,GAAnF,CAAmF,CAAC;AAC5I;AAGA,SAAS,WAAW,MAAkC;CACpD,OACE,KAEG,MAAM,wBAA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I,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE;CAC1D,IAAI,MAAM,eAAe,IAAI,GAAG;EAC9B,MAAM,QAAQ,KAAK;EACnB,IAAI,OAAO,MAAM,kBAAkB,UAAU,OAAO,MAAM;EAC1D,OAAO,SAAS,MAAM,QAAQ,MAAM,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ;CACtF;CACA,OAAO;AACT;;;;AAKA,SAAgB,UAAU,MAAsB;CAC9C,OAAO,KACJ,QAAQ,+DAA+D,QAAU,CAAC,CAClF,QAAQ,qDAAqD,QAAU;AAC5E"}
1
+ {"version":3,"file":"util.js","names":[],"sources":["../../src/internal/util.tsx"],"sourcesContent":["import * as React from 'react';\n\n/** A value (a row or node id, a file path) as part of an element id: no spaces, so aria-owns, aria-controls and\n * aria-labelledby, which split their value at spaces, still find it. */\nexport const idPart = (s: string): string => encodeURIComponent(s);\n\n/** Joins the truthy class names. */\nexport function cx(...names: unknown[]): string {\n return names.filter(Boolean).join(' ');\n}\n\n// Text that is only seen: drawn by CSS (::before), so it is neither in the page's text (copy, innerText, text-reading\n// tools) nor read aloud. The readable version goes beside it, visually hidden. Numbers keep Geist Mono.\nexport function seenOnly(text: string, nums: string[]): React.ReactNode[] {\n return splitMarks(text).map(([t, k], i) => <span key={i} className={cx('ui-seen', k >= 0 && 'ui-num')} data-text={k >= 0 ? nums[k] : t} />);\n}\n\n// A translated sentence cut at its number marks (\\u0001, \\u0002, \\u0003): [text, -1] or [mark, its index].\nfunction splitMarks(text: string): [string, number][] {\n return (\n text\n // eslint-disable-next-line no-control-regex -- the marks are control characters on purpose\n .split(/(\\u0001|\\u0002|\\u0003)/)\n .filter(Boolean)\n .map((t) => [t, ['\\u0001', '\\u0002', '\\u0003'].indexOf(t)])\n );\n}\n\n// Puts the numbers of a translated sentence in Geist Mono and leaves the words in the text font.\n// The sentence marks each number with \\u0001, \\u0002 or \\u0003 in the order of nums.\nexport function monoNums(text: string, nums: React.ReactNode[]): React.ReactNode[] {\n return splitMarks(text).map(([t, k], i) =>\n k >= 0 ? (\n <span key={i} className=\"ui-num\">\n {nums[k]}\n </span>\n ) : (\n t\n ),\n );\n}\n\n/** localStorage get (no value) or set; null when storage is blocked. */\nexport function store(key: string, value?: string): string | null {\n try {\n if (value === undefined) return localStorage.getItem(key);\n localStorage.setItem(key, value);\n } catch {\n /* storage blocked (private mode, sandboxed frame) */\n }\n return null;\n}\n\n/** The CSS zoom in effect on an element (ConsoleLayout zooms large screens up to 1.5×): 1 where there is none or the\n * browser cannot tell. getBoundingClientRect() and pointer positions are in screen px; divide a length taken from them\n * by this to get the CSS px that widths, positions and scrollTop inside the element use. */\nexport function cssZoom(el: Element | null | undefined): number {\n const z = (el as (Element & { currentCSSZoom?: number }) | null | undefined)?.currentCSSZoom;\n return typeof z === 'number' && z > 0 ? z : 1;\n}\n\nexport function reduced(): boolean {\n return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nconst nav = typeof navigator !== 'undefined' ? (navigator as Navigator & { userAgentData?: { platform?: string } }) : undefined;\nexport const IS_MAC = /mac|iphone|ipad/i.test(nav?.userAgentData?.platform || nav?.platform || nav?.userAgent || '');\n/** A touch screen as the main input (phones, tablets): no keyboard to press a shortcut with, no hover. Phones and\n * tablets report (pointer: coarse); (hover: none) alone is not used, since Chromium keeps it after touch emulation is\n * turned off and a mouse would then lose its Tooltips. */\nexport const TOUCH_ONLY = '(pointer: coarse)';\nexport const SHORTCUT = IS_MAC ? '⌘K' : 'Ctrl K';\n\n/** Matches a media query and follows changes. false on the server and in the first browser render while hydrating,\n * so the markup matches; then the real match. */\nexport function useMedia(query: string): boolean {\n const sub = React.useCallback(\n (f: () => void) => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {};\n const m = window.matchMedia(query);\n m.addEventListener('change', f);\n return () => m.removeEventListener('change', f);\n },\n [query],\n );\n const get = React.useCallback(() => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(query).matches, [query]);\n return React.useSyncExternalStore(sub, get, serverFalse);\n}\nconst serverFalse = () => false;\n\n/** A ResizeObserver, or null where there is none (jsdom, old browsers): the first measure then stays. */\nexport function resizeObserver(cb: ResizeObserverCallback): ResizeObserver | null {\n return typeof ResizeObserver === 'function' ? new ResizeObserver(cb) : null;\n}\n\n// Web fonts that finished loading since this module ran: text measured on a canvas before then used the fallback font.\nlet fontLoads = 0;\nconst fontListeners = new Set<() => void>();\nif (typeof document !== 'undefined' && typeof document.fonts?.addEventListener === 'function') {\n document.fonts.addEventListener('loadingdone', () => {\n fontLoads++;\n for (const f of fontListeners) f();\n });\n}\nconst subFonts = (f: () => void) => {\n fontListeners.add(f);\n return () => fontListeners.delete(f);\n};\nconst getFonts = () => fontLoads;\nconst serverZero = () => 0;\n\n/** A number that goes up each time web fonts finish loading (document.fonts `loadingdone`). Layout worked out from text\n * measured on a canvas depends on it, so it is worked out again with the loaded fonts instead of keeping the fallback\n * font's widths. 0 on the server and while hydrating. */\nexport function useFontLoads(): number {\n return React.useSyncExternalStore(subFonts, getFonts, serverZero);\n}\n\n/** True under 600 px, the same width where cards stack. */\nexport function useNarrow(): boolean {\n return useMedia('(max-width: 599px)');\n}\n\nexport async function copyText(text: string): Promise<void> {\n if (navigator.clipboard?.writeText) {\n try {\n return await navigator.clipboard.writeText(text);\n } catch {\n /* fall back below (insecure context, denied permission) */\n }\n }\n const t = document.createElement('textarea');\n t.value = text;\n t.setAttribute('readonly', '');\n t.style.position = 'fixed';\n t.style.opacity = '0';\n document.body.appendChild(t);\n t.select();\n try {\n if (!document.execCommand('copy')) throw new Error('copy failed');\n } finally {\n document.body.removeChild(t);\n }\n}\n\n/** Text with every number in Geist Mono and the words in the text font, for labels that mix both (「第 1 週」). */\nexport function digits(text: string, numbers = /(\\d[\\d,.:/]*)/): React.ReactNode[] {\n return text.split(numbers).map((t, i) =>\n i % 2 ? (\n <span key={i} className=\"ui-num\">\n {t}\n </span>\n ) : (\n t\n ),\n );\n}\n\n/** Alt, Meta or Ctrl held: the key belongs to the browser or the system (Alt+← goes back a page), not to the widget. */\nexport const browserKey = (e: { altKey: boolean; metaKey: boolean; ctrlKey: boolean }): boolean => e.altKey || e.metaKey || e.ctrlKey;\n\n/** The words in a React node, as a screen reader would read them: strings and numbers, through elements' children. */\nexport function nodeText(node: React.ReactNode): string {\n if (node == null || typeof node === 'boolean') return '';\n if (typeof node === 'string' || typeof node === 'number') return String(node);\n if (Array.isArray(node)) return node.map(nodeText).join('');\n if (React.isValidElement(node)) {\n const props = node.props as { 'aria-label'?: string; label?: unknown; children?: React.ReactNode };\n if (typeof props['aria-label'] === 'string') return props['aria-label'];\n return nodeText(props.children) || (typeof props.label === 'string' ? props.label : '');\n }\n return '';\n}\n\n/** A number and its unit never break apart: the space between them becomes a no-break space (U+00A0), so\n * 「100 MB」「29 °C」「3 筆」 do not wrap as 「100 / MB」 on a phone, nor a currency before the number (「NT$ 1,280」).\n * Leaves every other space alone. */\nexport function keepUnits(text: string): string {\n return text\n .replace(/(\\d) (?=°|%|‰|[A-Za-zµΩ]{1,4}(?![A-Za-z])|[\\u3400-\\u9fff])/g, '$1\\u00a0')\n .replace(/((?:^|[^\\w$])(?:[A-Z]{2}\\$|[$€£¥₩])) (?=[-−]?\\d)/g, '$1\\u00a0');\n}\n"],"mappings":";;;;;;AAIA,MAAa,UAAU,MAAsB,mBAAmB,CAAC;;AAGjE,SAAgB,GAAG,GAAG,OAA0B;CAC9C,OAAO,MAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAIA,SAAgB,SAAS,MAAc,MAAmC;CACxE,OAAO,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,MAAM,oBAAC,QAAD;EAAc,WAAW,GAAG,WAAW,KAAK,KAAK,QAAQ;EAAG,aAAW,KAAK,IAAI,KAAK,KAAK;CAAI,GAAnF,CAAmF,CAA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AU,EAAE,WAAW,EAAE;;AAG9H,SAAgB,SAAS,MAA+B;CACtD,IAAI,QAAQ,QAAQ,OAAO,SAAS,WAAW,OAAO;CACtD,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO,OAAO,IAAI;CAC5E,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE;CAC1D,IAAI,MAAM,eAAe,IAAI,GAAG;EAC9B,MAAM,QAAQ,KAAK;EACnB,IAAI,OAAO,MAAM,kBAAkB,UAAU,OAAO,MAAM;EAC1D,OAAO,SAAS,MAAM,QAAQ,MAAM,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ;CACtF;CACA,OAAO;AACT;;;;AAKA,SAAgB,UAAU,MAAsB;CAC9C,OAAO,KACJ,QAAQ,+DAA+D,QAAU,CAAC,CAClF,QAAQ,qDAAqD,QAAU;AAC5E"}
package/dist/styles.css CHANGED
@@ -6488,6 +6488,7 @@ div.ui-toast[role='status'] {
6488
6488
  as its content. */
6489
6489
  .ui-console-kpis > .ui-kpi {
6490
6490
  flex: 1 1 0;
6491
+ /* At least as wide as its content; the row wraps (the top bar's next line) when they do not all fit. */
6491
6492
  min-width: max-content;
6492
6493
  padding: 6px var(--space-4);
6493
6494
  border-radius: 0;
@@ -6498,11 +6499,11 @@ div.ui-toast[role='status'] {
6498
6499
  .ui-console-kpis > .ui-kpi:last-child {
6499
6500
  border-right: 1px solid var(--line);
6500
6501
  }
6501
- .ui-console.is-stacked .ui-console-kpis > .ui-kpi:first-child {
6502
+ /* Stacked, the KPIs are a grid under the title line: no lines between them, each starting at its column's edge. */
6503
+ .ui-console.is-stacked .ui-console-kpis > .ui-kpi {
6504
+ min-width: 0;
6505
+ padding: 0;
6502
6506
  border-left: 0;
6503
- padding-left: 0;
6504
- }
6505
- .ui-console.is-stacked .ui-console-kpis > .ui-kpi:last-child {
6506
6507
  border-right: 0;
6507
6508
  }
6508
6509
  /* DetailList */
@@ -9813,6 +9814,9 @@ button.ui-md-link.is-row {
9813
9814
  attention border, the forecast stripes, the selection outline (ink, 2 px, 4 px outside) and the label type follow
9814
9815
  ZoneMap. */
9815
9816
  .ui-floorplan {
9817
+ /* The containing block of the visually hidden hint: without it the hint escapes a scrolling card and makes the page
9818
+ scroll. */
9819
+ position: relative;
9816
9820
  display: flex;
9817
9821
  flex-direction: column;
9818
9822
  gap: var(--space-3);
@@ -10203,6 +10207,9 @@ button.ui-md-link.is-row {
10203
10207
  .ui-console-top {
10204
10208
  grid-column: 1 / -1;
10205
10209
  display: flex;
10210
+ /* Never wider than the layout: what does not fit goes to a second line (the main view gives up the height). */
10211
+ flex-wrap: wrap;
10212
+ row-gap: var(--space-2);
10206
10213
  align-items: center;
10207
10214
  justify-content: space-between;
10208
10215
  gap: var(--space-4);
@@ -10221,6 +10228,11 @@ button.ui-md-link.is-row {
10221
10228
  gap: var(--space-3);
10222
10229
  min-width: 0;
10223
10230
  }
10231
+ .ui-console-end {
10232
+ flex-wrap: wrap;
10233
+ justify-content: flex-end;
10234
+ margin-left: auto;
10235
+ }
10224
10236
  .ui-console-title {
10225
10237
  margin: 0;
10226
10238
  font-size: inherit;
@@ -10234,7 +10246,9 @@ button.ui-md-link.is-row {
10234
10246
  }
10235
10247
  .ui-console-kpis {
10236
10248
  display: flex;
10249
+ flex-wrap: wrap;
10237
10250
  align-items: stretch;
10251
+ max-width: 100%;
10238
10252
  }
10239
10253
  .ui-console-content {
10240
10254
  display: contents;
@@ -10248,6 +10262,9 @@ button.ui-md-link.is-row {
10248
10262
  flex-direction: column;
10249
10263
  }
10250
10264
  .ui-console-main > * {
10265
+ /* Scroll containers are positioned, so visually hidden text inside them is clipped with them instead of making the
10266
+ page scroll. */
10267
+ position: relative;
10251
10268
  flex: 1 1 auto;
10252
10269
  min-height: 0;
10253
10270
  overflow: auto;
@@ -10256,6 +10273,7 @@ button.ui-md-link.is-row {
10256
10273
  flex-direction: column;
10257
10274
  }
10258
10275
  .ui-console-side {
10276
+ position: relative;
10259
10277
  grid-column: 2;
10260
10278
  grid-row: 2 / 4;
10261
10279
  min-height: 0;
@@ -10268,9 +10286,22 @@ button.ui-md-link.is-row {
10268
10286
  padding: 12px;
10269
10287
  }
10270
10288
  .ui-console-side > * {
10289
+ /* Side cards keep their own height; the panel scrolls when they do not fit. */
10271
10290
  flex: none;
10272
10291
  }
10292
+ /* An extra card that does not fit: laid out at the panel's width, out of sight and at no height, so it is measured
10293
+ again when the panel grows. */
10294
+ .ui-console-extra.is-out {
10295
+ position: absolute;
10296
+ top: 0;
10297
+ left: 12px;
10298
+ right: 12px;
10299
+ height: 0;
10300
+ overflow: hidden;
10301
+ visibility: hidden;
10302
+ }
10273
10303
  .ui-console-bottom {
10304
+ position: relative;
10274
10305
  grid-column: 1;
10275
10306
  grid-row: 3;
10276
10307
  min-width: 0;
@@ -10278,7 +10309,9 @@ button.ui-md-link.is-row {
10278
10309
  display: flex;
10279
10310
  flex-direction: column;
10280
10311
  }
10281
- /* Phones: one scrolling column, top bar first, then the main view, side cards, bottom row and extra cards. */
10312
+ /* Stacked (narrower than stackedBelow, 1100 px by default): one scrolling column. The top bar keeps the title, status,
10313
+ clock and full screen on its first line and puts every KPI on the next ones; the main view; the side cards side by
10314
+ side where there is room; the bottom row; the extra cards the same way as the side cards. */
10282
10315
  .ui-console.is-stacked {
10283
10316
  height: auto;
10284
10317
  min-height: 100dvh;
@@ -10290,21 +10323,30 @@ button.ui-md-link.is-row {
10290
10323
  height: auto;
10291
10324
  }
10292
10325
  .ui-console.is-stacked .ui-console-top {
10293
- flex-wrap: wrap;
10294
10326
  padding: var(--space-3) var(--space-4);
10295
10327
  }
10328
+ .ui-console.is-stacked .ui-console-start {
10329
+ margin-right: auto;
10330
+ }
10296
10331
  .ui-console.is-stacked .ui-console-end {
10297
- flex-wrap: wrap;
10298
- row-gap: var(--space-2);
10332
+ display: contents;
10299
10333
  }
10300
10334
  .ui-console.is-stacked .ui-console-kpis {
10301
10335
  order: 1;
10336
+ display: grid;
10337
+ grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr));
10338
+ gap: var(--space-2) var(--space-4);
10302
10339
  width: 100%;
10303
- overflow-x: auto;
10304
10340
  }
10305
10341
  .ui-console.is-stacked .ui-console-main {
10306
10342
  min-height: 320px;
10307
10343
  }
10344
+ .ui-console-cards {
10345
+ display: grid;
10346
+ grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
10347
+ align-items: start;
10348
+ gap: 12px;
10349
+ }
10308
10350
  .ui-table-copy.is-copied {
10309
10351
  color: var(--success-text);
10310
10352
  }
@@ -19,22 +19,38 @@ h(UI.ConsoleLayout, {
19
19
 
20
20
  - 頂列的字都是 16 px、同一個顏色:`status` 傳一般文字(例如「AI 最佳化中」),不要用 Badge 或狀態色。
21
21
  - `kpis` 放 `KpiCard size="compact"`。
22
- - 卡片由頁面自己放(Card);主視覺裡的 ZoneMap 加 `fill` 撐滿卡片。
22
+ - 卡片由頁面自己放(Card);主視覺裡的 ZoneMap 或 FloorPlan 加 `fill` 撐滿卡片。
23
+ - 側欄的卡片保留自己的高度:不要給它們 `flex: 1` 或 `min-height: 0`,放不下時側欄自己捲動。
24
+ - 版面寬度小於 1100 px(`stackedBelow`)時排成一欄可以捲動的長頁;`mode` 可以固定成 `'console'` 或 `'stacked'`。
23
25
  - 1440 × 900 以上整個版面等比放大,最多 1.5 倍;以下不縮小。
24
26
 
25
27
  ## 細節
26
28
 
27
- - 頂列:左邊 `title`(整頁唯一的標題)和 `tags`(例如 `Tag icon="info"`「示範資料」);右邊依序是 `status`、`kpis`、`clock`、全螢幕按鈕。頂列的字都是 16 px、同一個顏色:`status` 傳一般文字(例如「AI 最佳化中」),不要用 Badge 或狀態色。
29
+ - 頂列:左邊 `title`(整頁唯一的標題)和 `tags`(例如 `Tag icon="info"`「示範資料」);右邊依序是 `status`、`kpis`、`clock`、全螢幕按鈕。放不下時右邊整組換到第二行,KPI 再放不下時自己換行;頂列不會比版面寬,主視覺讓出高度。
28
30
  - `kpis` 放 `KpiCard size="compact"`,在頂列裡去掉卡片底色和陰影,中間用 1 px 線分開。
29
31
  - `main`:主視覺,例如裝 ZoneMap 的 Card;填滿左邊的格子,放不下時在卡片裡捲動。卡片裡是由上而下排的欄,ZoneMap 加 `fill` 就會撐滿卡片剩下的高度。
30
32
  - `side`:側欄的卡片,由上到下,例如 TimeControl、EventTimeline。側欄 400 px(版面寬度小於 1280 px 時 360 px),放不下時側欄自己捲動。
31
33
  - `bottom`:主視覺下方一列,高度跟著內容,例如裝 LineChart 的 Card;主視覺拿剩下的高度。
32
- - `extras: [{ id, minHeight, node }]`:螢幕夠高才出現的卡片,加在側欄最後面。`minHeight` 比的是「邏輯高度」,也就是畫面高度 ÷ 放大倍數,例如 1040。
33
- - 放大:1440 × 900 以上整個版面等比放大,倍數 = 寬 ÷ 1440 和 高 ÷ 900 的較小者,最多 1.5 倍(`consoleZoom(w, h)`);以下維持原大小、不縮小。
34
+ - `extras: [{ id, node, minHeight? }]`:側欄放得下才出現的卡片,加在側欄最後面。依序量每張卡片自己的高度,放得進側欄剩下的空間才顯示,第一張放不下的和後面的都不顯示;側欄因此不用為了它們捲動。`minHeight`(選用)另外要求「邏輯高度」(畫面高度 ÷ 放大倍數)至少這麼高。沒顯示的卡片仍在畫面外排版、量高度,螢幕閱讀器和 Tab 都略過(`inert`)。
35
+ - 放大:1440 × 900 以上整個版面等比放大,倍數 = 寬 ÷ 1440 和 高 ÷ 900 的較小者,最多 1.5 倍;以下維持原大小、不縮小。寬是版面的寬,高是版面的高和視窗高度的較小者(版面被頁面撐高時不會因此放大);排成一欄時不放大。裡面的元件(FloorPlan、LineChart、DataTable、SplitPane 等)在放大後照常量尺寸。
34
36
  - 全螢幕按鈕(「全螢幕」/「離開全螢幕」)讓版面佔滿整個螢幕;瀏覽器沒有全螢幕功能時不顯示,`fullscreen={false}` 可以拿掉。
35
- - 手機(寬度小於 600 px):排成一欄可以捲動的長頁:頂列(KPI 換到第二行,可以左右捲動)、主視覺、側欄的卡片、底列、`extras` 的卡片全部顯示。
37
+ - 排成一欄(版面寬度小於 `stackedBelow`,預設 1100 px;或 `mode="stacked"`):可以捲動的長頁,不放大。頂列第一行是標題、`tags`、`status`、`clock`、全螢幕按鈕(寬度小於 600 px 時不顯示),KPI 全部排在下面幾行(每格至少 190 px);接著主視覺(最少 320 px 高)、側欄的卡片(每張至少 340 px 寬,放得下就並排)、底列、`extras` 的卡片(全部顯示,排法同側欄)。
38
+ - `mode="console"`:永遠是全螢幕版面,窄的時候主視覺會很窄;只在確定螢幕夠寬時用。
39
+ - 側欄、主視覺卡片和底列是定位過的捲動區:裡面只給螢幕閱讀器的文字(`.ui-visually-hidden`)跟著它們裁切,不會讓整頁多出捲動。
36
40
  - 卡片由頁面自己放(Card),版面本身只有頂列有底色和陰影。
37
- - 地標:`title` 是 `h1`;主視覺和底列在 `main` 裡,側欄是 `aside`(「側欄」);手機上頂列以下整欄都在 `main`。頁面不再另放 `h1` 或 `main`。
41
+ - 地標:`title` 是 `h1`;主視覺和底列在 `main` 裡,側欄是 `aside`(「側欄」);排成一欄時頂列以下整欄都在 `main`。頁面不再另放 `h1` 或 `main`。
42
+
43
+ ## 響應式的保證
44
+
45
+ 在 360~2560 px 寬、640~1440 px 高的視窗裡(元件測試逐一檢查這個範圍裡的 27 種大小):
46
+
47
+ - 頁面不會左右捲動;全螢幕版面時整頁也不會上下捲動。
48
+ - 頂列不會比版面寬。
49
+ - 卡片不會互相重疊;側欄的卡片不被切掉(放不下時側欄捲動)。
50
+ - 全螢幕版面的主視覺至少 700 px 寬(`stackedBelow` 預設 1100 px 的原因)。
51
+ - `extras` 只在放得下時出現。
52
+
53
+ 頁面自己改版面時(例如另加 `className` 改高度)保持同樣的保證:不要把根元素改成跟著內容長高的全螢幕版面,要長頁就用 `mode="stacked"`。
38
54
 
39
55
  ```js
40
56
  h(UI.ConsoleLayout, {
@@ -49,6 +65,6 @@ h(UI.ConsoleLayout, {
49
65
  main: h(UI.Card, { title: '設施分區' }, h(UI.ZoneMap, { label: '設施分區', zones: zones, fill: true })),
50
66
  side: [h(UI.Card, { key: 't' }, h(UI.TimeControl, timeProps)), h(UI.Card, { key: 'e', title: '事件' }, h(UI.EventTimeline, eventProps))],
51
67
  bottom: h(UI.Card, { title: '進氣溫度' }, h(UI.LineChart, chartProps)),
52
- extras: [{ id: 'meters', minHeight: 1040, node: h(UI.Card, { title: '各區進氣溫度' }, meters) }],
68
+ extras: [{ id: 'meters', node: h(UI.Card, { title: '各區進氣溫度' }, meters) }],
53
69
  });
54
70
  ```
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.49.0/fonts.css">
69
- <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.49.0/tokens.css">
70
- <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.49.0/styles.css">
68
+ <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.50.0/fonts.css">
69
+ <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.50.0/tokens.css">
70
+ <link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.50.0/styles.css">
71
71
  <div id="root"></div>
72
- <script src="https://seanyeh77.github.io/ui-design-system/dist/0.49.0/bundle.js"></script>
72
+ <script src="https://seanyeh77.github.io/ui-design-system/dist/0.50.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.49.0/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.49.0/fonts.css`). Without a bundler, `@seanyeh77/ui/dist/fonts.css` cannot resolve its import: load the tokens package's `fonts.css` or the pinned site URL.
80
+ Pin a version as above: `/dist/<version>/` never changes; `/dist/` always serves the latest release. jsDelivr has the same files (`https://cdn.jsdelivr.net/npm/@seanyeh77/ui@0.50.0/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.50.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.
@@ -4,7 +4,8 @@
4
4
 
5
5
  ## 版面
6
6
 
7
- - 用 `ConsoleLayout`:頂列左邊標題和「示範資料」,右邊狀態、KPI、時間、全螢幕按鈕;主視覺在左、側欄在右、圖表在主視覺下方;整頁不捲動,放不下時側欄自己捲動;螢幕夠高才多出的卡片加在側欄最後面;手機排成一欄的長頁。
7
+ - 用 `ConsoleLayout`:頂列左邊標題和「示範資料」,右邊狀態、KPI、時間、全螢幕按鈕;主視覺在左、側欄在右、圖表在主視覺下方;整頁不捲動,放不下時側欄自己捲動;側欄放得下才多出的卡片加在側欄最後面;版面寬度小於 1100 px(平板、手機)排成一欄的長頁。
8
+ - 側欄卡片保留自己的高度,不設 `flex: 1` 或 `min-height: 0`。各種視窗大小下版面保證什麼,見 ConsoleLayout 的「響應式的保證」(`ui docs ConsoleLayout --full`);頁面改了版面時,用同一組視窗大小自己檢查。
8
9
  - 字級:最小字 13 px,SVG 軸標 12 px。大螢幕依視窗等比放大:倍數 = 視窗寬 ÷ 1440 和 視窗高 ÷ 900 的較小者,下限 1、上限 1.5;1440 × 900 以下不縮小,改用斷點。
9
10
  - 頂列的 KPI 用 `KpiCard size="compact"`:數字 22 px,一行灰字目標;判定只在需要注意時取代目標那一行,用文字和狀態色,不加符號、不加底色。
10
11
  - 頂列的「示範資料」和狀態文字(例如「AI 最佳化中」)和旁邊的字同樣大小、同樣顏色,不另外上色。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seanyeh77/ui",
3
- "version": "0.49.0",
3
+ "version": "0.50.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.49.0"
61
+ "@seanyeh77/tokens": "^0.50.0"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "node scripts/theme-defaults.ts && tsdown && node scripts/postbuild.ts",