@seanyeh77/ui 0.34.0 → 0.36.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 +14 -14
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +28 -6
- package/dist/index.js +70 -15
- package/dist/index.js.map +1 -1
- package/dist/styles.css +37 -0
- package/dist/tokens.css +28 -0
- package/docs/CodeView.md +11 -3
- package/docs/DataColors.md +46 -0
- package/docs/LineChart.md +1 -1
- package/docs/Tag.md +9 -0
- package/docs/guidelines.md +6 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -584,9 +584,14 @@ interface CodeViewProps<L extends CodeLink = CodeLink> {
|
|
|
584
584
|
/** The reader clicked a line, or moved to one with ↑ ↓ (also Home, End, PageUp, PageDown, [ ]): `how` says which.
|
|
585
585
|
* Dragging to select text is not a move and does not call it. Given this, ↑ ↓ move by line even without links. */
|
|
586
586
|
onLine?: (line: number, how: 'click' | 'key') => void;
|
|
587
|
-
/** Marks
|
|
588
|
-
*
|
|
589
|
-
|
|
587
|
+
/** Marks a line, or a range of lines (`{ from, to }`, both included), for a moment, apart from `target` (both can
|
|
588
|
+
* show), e.g. while the pointer rests on an item that points at it. Scrolled with the least movement so the whole
|
|
589
|
+
* range is in view; a range taller than the view puts its first line at the top. Focus and selected text stay.
|
|
590
|
+
* null or undefined: none. */
|
|
591
|
+
peek?: number | {
|
|
592
|
+
from: number;
|
|
593
|
+
to: number;
|
|
594
|
+
} | null;
|
|
590
595
|
className?: string;
|
|
591
596
|
/** focusTarget() moves keyboard and screen-reader focus to the target line. */
|
|
592
597
|
ref?: React.Ref<CodeViewHandle>;
|
|
@@ -1267,7 +1272,7 @@ interface LineSeries {
|
|
|
1267
1272
|
values: number[];
|
|
1268
1273
|
}
|
|
1269
1274
|
interface LineChartProps {
|
|
1270
|
-
/** Up to
|
|
1275
|
+
/** Up to 4 series (chart-1 to chart-4); a legend with each name appears for 2 or more. */
|
|
1271
1276
|
series: LineSeries[];
|
|
1272
1277
|
/** One label per point on the x axis. */
|
|
1273
1278
|
labels: string[];
|
|
@@ -1625,10 +1630,15 @@ interface SegmentedControlProps<V extends string = string> {
|
|
|
1625
1630
|
export declare function SegmentedControl<V extends string = string>({ items, value, onChange, label, iconOnly, className }: SegmentedControlProps<V>): React.JSX.Element;
|
|
1626
1631
|
interface TagProps {
|
|
1627
1632
|
children?: React.ReactNode;
|
|
1633
|
+
/** `plain` (default): small gray text. `forecast`: marks a value as forecast, not measured (accent-soft fill), e.g.
|
|
1634
|
+
* 「預測」 beside it or on a striped `ui-forecast` area. `demo`: a whole page of sample values (warning-soft fill,
|
|
1635
|
+
* bold), e.g. 「示範資料」 beside the brand; one per page. */
|
|
1636
|
+
variant?: 'plain' | 'forecast' | 'demo';
|
|
1628
1637
|
className?: string;
|
|
1629
1638
|
}
|
|
1630
|
-
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead.
|
|
1631
|
-
|
|
1639
|
+
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two filled kinds say
|
|
1640
|
+
* where numbers come from: forecast and demo. */
|
|
1641
|
+
export declare function Tag({ children, variant, className }: TagProps): React.JSX.Element;
|
|
1632
1642
|
interface TermProps {
|
|
1633
1643
|
/** The word or label that needs explaining. */
|
|
1634
1644
|
children?: React.ReactNode;
|
|
@@ -1693,6 +1703,18 @@ export declare function setTheme(t: ThemeSetting): void;
|
|
|
1693
1703
|
export declare function setAccent(hex: string, quiet?: boolean): boolean;
|
|
1694
1704
|
/** Applies the stored theme and accent; call once when the page starts. */
|
|
1695
1705
|
export declare function initTheme(): void;
|
|
1706
|
+
/** The text color for something drawn on a fill (a heat-scale zone, a status band): the near-black ink of the light
|
|
1707
|
+
* theme (#171512) or white, whichever contrasts more with the fill. `fill` is a color (#hex, rgb()) or a token name
|
|
1708
|
+
* such as 'heat-6', read from el (default: the root) so it follows the theme. Every step of heat-*, diverge-* and
|
|
1709
|
+
* chart-* reaches 4.5:1 with its pick. Unreadable colors give the near-black ink. */
|
|
1710
|
+
export declare function textOn(fill: string, el?: Element): '#171512' | '#ffffff';
|
|
1711
|
+
/** The heat-scale token for a value: min (or below) is heat-1, max (or above) is heat-7, evenly in between. */
|
|
1712
|
+
export declare function heatToken(value: number, min: number, max: number): `heat-${1 | 2 | 3 | 4 | 5 | 6 | 7}`;
|
|
1713
|
+
/** The diverging-scale token for a difference: within ±zero it is diverge-zero; from ±strong on, the -strong step. */
|
|
1714
|
+
export declare function divergeToken(diff: number, limits: {
|
|
1715
|
+
zero: number;
|
|
1716
|
+
strong: number;
|
|
1717
|
+
}): 'diverge-neg-strong' | 'diverge-neg' | 'diverge-zero' | 'diverge-pos' | 'diverge-pos-strong';
|
|
1696
1718
|
interface ThemePickerProps {
|
|
1697
1719
|
/** Controlled value. Without it, the picker reads and sets the stored theme itself. */
|
|
1698
1720
|
value?: ThemeSetting;
|
package/dist/index.js
CHANGED
|
@@ -1473,6 +1473,29 @@ function initTheme() {
|
|
|
1473
1473
|
if (storedTheme() === "auto") setTheme("auto");
|
|
1474
1474
|
});
|
|
1475
1475
|
}
|
|
1476
|
+
/** The text color for something drawn on a fill (a heat-scale zone, a status band): the near-black ink of the light
|
|
1477
|
+
* theme (#171512) or white, whichever contrasts more with the fill. `fill` is a color (#hex, rgb()) or a token name
|
|
1478
|
+
* such as 'heat-6', read from el (default: the root) so it follows the theme. Every step of heat-*, diverge-* and
|
|
1479
|
+
* chart-* reaches 4.5:1 with its pick. Unreadable colors give the near-black ink. */
|
|
1480
|
+
function textOn(fill, el) {
|
|
1481
|
+
let c = fill.trim();
|
|
1482
|
+
if (/^[a-z][a-z0-9-]*$/.test(c) && typeof document !== "undefined") c = getComputedStyle(el ?? document.documentElement).getPropertyValue("--" + c);
|
|
1483
|
+
const hex = toHex(c);
|
|
1484
|
+
if (!hex) return "#171512";
|
|
1485
|
+
return contrast(hex, "#171512") >= contrast(hex, "#ffffff") ? "#171512" : "#ffffff";
|
|
1486
|
+
}
|
|
1487
|
+
/** The heat-scale token for a value: min (or below) is heat-1, max (or above) is heat-7, evenly in between. */
|
|
1488
|
+
function heatToken(value, min, max) {
|
|
1489
|
+
const t = max > min ? (value - min) / (max - min) : 0;
|
|
1490
|
+
return `heat-${Math.min(7, Math.max(1, Math.round(t * 6) + 1))}`;
|
|
1491
|
+
}
|
|
1492
|
+
/** The diverging-scale token for a difference: within ±zero it is diverge-zero; from ±strong on, the -strong step. */
|
|
1493
|
+
function divergeToken(diff, limits) {
|
|
1494
|
+
const a = Math.abs(diff);
|
|
1495
|
+
if (a <= limits.zero) return "diverge-zero";
|
|
1496
|
+
const strong = a >= limits.strong;
|
|
1497
|
+
return diff < 0 ? strong ? "diverge-neg-strong" : "diverge-neg" : strong ? "diverge-pos-strong" : "diverge-pos";
|
|
1498
|
+
}
|
|
1476
1499
|
// src/components/AccentPicker/AccentPicker.tsx
|
|
1477
1500
|
const SWATCHES = [
|
|
1478
1501
|
["藍", "#2457d6"],
|
|
@@ -1892,7 +1915,8 @@ function smoothPath(p) {
|
|
|
1892
1915
|
const CHART = [
|
|
1893
1916
|
"var(--chart-1)",
|
|
1894
1917
|
"var(--chart-2)",
|
|
1895
|
-
"var(--chart-3)"
|
|
1918
|
+
"var(--chart-3)",
|
|
1919
|
+
"var(--chart-4)"
|
|
1896
1920
|
];
|
|
1897
1921
|
/** The color of series i. */
|
|
1898
1922
|
const seriesColor = (i) => CHART[i % CHART.length];
|
|
@@ -2728,14 +2752,38 @@ function selectedCode(pre) {
|
|
|
2728
2752
|
const rows = [...frag.querySelectorAll("[role=\"listitem\"]")];
|
|
2729
2753
|
return rows.length ? rows.map((x) => x.textContent ?? "").join("\n") : frag.textContent ?? "";
|
|
2730
2754
|
}
|
|
2731
|
-
/**
|
|
2732
|
-
function
|
|
2733
|
-
|
|
2734
|
-
|
|
2755
|
+
/** The nearest box that scrolls el's content: el itself, a parent with overflow auto or scroll, or the page (null). */
|
|
2756
|
+
function scroller(el) {
|
|
2757
|
+
for (let n = el; n && n !== document.body && n !== document.documentElement; n = n.parentElement) {
|
|
2758
|
+
const o = getComputedStyle(n).overflowY;
|
|
2759
|
+
if ((o === "auto" || o === "scroll" || o === "overlay") && n.scrollHeight > n.clientHeight) return n;
|
|
2760
|
+
}
|
|
2761
|
+
return null;
|
|
2762
|
+
}
|
|
2763
|
+
/** Scrolls the lines first…last into view with the least movement; when they are taller than the view, the first
|
|
2764
|
+
* line goes to the top. Nothing moves when they are already in view. */
|
|
2765
|
+
function showRange(first, last, pre) {
|
|
2766
|
+
const box = scroller(pre);
|
|
2767
|
+
const view = box ? (() => {
|
|
2768
|
+
const top = box.getBoundingClientRect().top + box.clientTop;
|
|
2769
|
+
return {
|
|
2770
|
+
top,
|
|
2771
|
+
bottom: top + box.clientHeight
|
|
2772
|
+
};
|
|
2773
|
+
})() : {
|
|
2735
2774
|
top: 0,
|
|
2736
2775
|
bottom: window.innerHeight
|
|
2737
2776
|
};
|
|
2738
|
-
|
|
2777
|
+
const top = first.getBoundingClientRect().top;
|
|
2778
|
+
const bottom = last.getBoundingClientRect().bottom;
|
|
2779
|
+
let by = 0;
|
|
2780
|
+
if (bottom - top > view.bottom - view.top) by = top - view.top;
|
|
2781
|
+
else if (top < view.top) by = top - view.top;
|
|
2782
|
+
else if (bottom > view.bottom) by = bottom - view.bottom;
|
|
2783
|
+
by = Math.round(by);
|
|
2784
|
+
if (!by) return;
|
|
2785
|
+
if (box) box.scrollTop += by;
|
|
2786
|
+
else window.scrollBy(0, by);
|
|
2739
2787
|
}
|
|
2740
2788
|
/** Each line's words from `terms`: only in comments and strings, never where a name link or a path is. With 'first',
|
|
2741
2789
|
* each word once per file, at its first place. */
|
|
@@ -2901,11 +2949,17 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2901
2949
|
const el = b?.querySelector(".is-target");
|
|
2902
2950
|
if (b && el && b.scrollHeight > b.clientHeight && !selectedIn(b)) b.scrollTop += el.getBoundingClientRect().top - b.getBoundingClientRect().top - b.clientHeight / 2 + el.offsetHeight / 2;
|
|
2903
2951
|
}, [ta, code]);
|
|
2952
|
+
const [pFrom, pTo] = peek == null ? [NaN, NaN] : typeof peek === "number" ? [peek, peek] : [Math.min(peek.from, peek.to), Math.max(peek.from, peek.to)];
|
|
2904
2953
|
React.useEffect(() => {
|
|
2905
|
-
if (
|
|
2906
|
-
const
|
|
2907
|
-
if (
|
|
2908
|
-
|
|
2954
|
+
if (Number.isNaN(pFrom)) return;
|
|
2955
|
+
const pre = body.current;
|
|
2956
|
+
if (!pre) return;
|
|
2957
|
+
const rows = [...pre.querySelectorAll("[data-n]")].filter((el) => {
|
|
2958
|
+
const n = Number(el.dataset.n);
|
|
2959
|
+
return n >= pFrom && n <= pTo;
|
|
2960
|
+
});
|
|
2961
|
+
if (rows.length) showRange(rows[0], rows[rows.length - 1], pre);
|
|
2962
|
+
}, [pFrom, pTo]);
|
|
2909
2963
|
const digits = String(start + lines.length - 1).length;
|
|
2910
2964
|
const prose = (cls, text, inLink) => !inLink && (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef, nav ? -1 : void 0) : breakable(text);
|
|
2911
2965
|
const piece = (cls, text, key, inLink, at = 0, words) => {
|
|
@@ -2992,7 +3046,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2992
3046
|
const on = ta != null && tb != null && n >= ta && n <= tb;
|
|
2993
3047
|
rows.push(/* @__PURE__ */ jsxs("div", {
|
|
2994
3048
|
role: "listitem",
|
|
2995
|
-
className: cx("ui-cv-line", on && "is-target",
|
|
3049
|
+
className: cx("ui-cv-line", on && "is-target", n >= pFrom && n <= pTo && "is-peek"),
|
|
2996
3050
|
"data-n": n,
|
|
2997
3051
|
"aria-current": on && n === ta ? "location" : void 0,
|
|
2998
3052
|
tabIndex: on && n === ta ? -1 : void 0,
|
|
@@ -9668,10 +9722,11 @@ function SegmentedControl({ items, value, onChange, label, iconOnly = false, cla
|
|
|
9668
9722
|
});
|
|
9669
9723
|
}
|
|
9670
9724
|
// src/components/Tag/Tag.tsx
|
|
9671
|
-
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead.
|
|
9672
|
-
|
|
9725
|
+
/** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two filled kinds say
|
|
9726
|
+
* where numbers come from: forecast and demo. */
|
|
9727
|
+
function Tag({ children, variant = "plain", className }) {
|
|
9673
9728
|
return /* @__PURE__ */ jsx("span", {
|
|
9674
|
-
className: cx("ui-tag", className),
|
|
9729
|
+
className: cx("ui-tag", variant !== "plain" && "is-" + variant, className),
|
|
9675
9730
|
children
|
|
9676
9731
|
});
|
|
9677
9732
|
}
|
|
@@ -11987,6 +12042,6 @@ function Workbench({ ref, ...p }) {
|
|
|
11987
12042
|
})
|
|
11988
12043
|
});
|
|
11989
12044
|
}
|
|
11990
|
-
export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Markdown, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, Workbench, addMessages, announce, focusMain, format, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, useTour, useWorkbench };
|
|
12045
|
+
export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Markdown, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, Workbench, addMessages, announce, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, textOn, useTour, useWorkbench };
|
|
11991
12046
|
|
|
11992
12047
|
//# sourceMappingURL=index.js.map
|