@seanyeh77/ui 0.37.0 → 0.39.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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-Mxi5pqut.js";
2
+ import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-C7iBqN3J.js";
3
3
  import * as React from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
@@ -109,7 +109,11 @@ const PH = {
109
109
  "sort-ascending": "<path d=\"M128,128a8,8,0,0,1-8,8H48a8,8,0,0,1,0-16h72A8,8,0,0,1,128,128ZM48,72H184a8,8,0,0,0,0-16H48a8,8,0,0,0,0,16Zm56,112H48a8,8,0,0,0,0,16h56a8,8,0,0,0,0-16Zm125.66-21.66a8,8,0,0,0-11.32,0L192,188.69V112a8,8,0,0,0-16,0v76.69l-26.34-26.35a8,8,0,0,0-11.32,11.32l40,40a8,8,0,0,0,11.32,0l40-40A8,8,0,0,0,229.66,162.34Z\"/>",
110
110
  "dots-six-vertical": "<path d=\"M104,60A12,12,0,1,1,92,48,12,12,0,0,1,104,60Zm60,12a12,12,0,1,0-12-12A12,12,0,0,0,164,72ZM92,116a12,12,0,1,0,12,12A12,12,0,0,0,92,116Zm72,0a12,12,0,1,0,12,12A12,12,0,0,0,164,116ZM92,184a12,12,0,1,0,12,12A12,12,0,0,0,92,184Zm72,0a12,12,0,1,0,12,12A12,12,0,0,0,164,184Z\"/>",
111
111
  "push-pin": "<path d=\"M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z\"/>",
112
- keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,144H32V64H224V192Zm-16-64a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,128Zm0-32a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,96ZM72,160a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16h8A8,8,0,0,1,72,160Zm96,0a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,160Zm40,0a8,8,0,0,1-8,8h-8a8,8,0,0,1,0-16h8A8,8,0,0,1,208,160Z\"/>"
112
+ keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,144H32V64H224V192Zm-16-64a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,128Zm0-32a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16H200A8,8,0,0,1,208,96ZM72,160a8,8,0,0,1-8,8H56a8,8,0,0,1,0-16h8A8,8,0,0,1,72,160Zm96,0a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,160Zm40,0a8,8,0,0,1-8,8h-8a8,8,0,0,1,0-16h8A8,8,0,0,1,208,160Z\"/>",
113
+ "arrows-left-right": "<path d=\"M213.66,181.66l-32,32a8,8,0,0,1-11.32-11.32L188.69,184H48a8,8,0,0,1,0-16H188.69l-18.35-18.34a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,213.66,181.66Zm-139.32-64a8,8,0,0,0,11.32-11.32L67.31,88H208a8,8,0,0,0,0-16H67.31L85.66,53.66A8,8,0,0,0,74.34,42.34l-32,32a8,8,0,0,0,0,11.32Z\"/>",
114
+ sparkle: "<path d=\"M197.58,129.06,146,110l-19-51.62a15.92,15.92,0,0,0-29.88,0L78,110l-51.62,19a15.92,15.92,0,0,0,0,29.88L78,178l19,51.62a15.92,15.92,0,0,0,29.88,0L146,178l51.62-19a15.92,15.92,0,0,0,0-29.88ZM137,164.22a8,8,0,0,0-4.74,4.74L112,223.85,91.78,169A8,8,0,0,0,87,164.22L32.15,144,87,123.78A8,8,0,0,0,91.78,119L112,64.15,132.22,119a8,8,0,0,0,4.74,4.74L191.85,144ZM144,40a8,8,0,0,1,8-8h16V16a8,8,0,0,1,16,0V32h16a8,8,0,0,1,0,16H184V64a8,8,0,0,1-16,0V48H152A8,8,0,0,1,144,40ZM248,88a8,8,0,0,1-8,8h-8v8a8,8,0,0,1-16,0V96h-8a8,8,0,0,1,0-16h8V72a8,8,0,0,1,16,0v8h8A8,8,0,0,1,248,88Z\"/>",
115
+ "trend-up": "<path d=\"M240,56v64a8,8,0,0,1-16,0V75.31l-82.34,82.35a8,8,0,0,1-11.32,0L96,123.31,29.66,189.66a8,8,0,0,1-11.32-11.32l72-72a8,8,0,0,1,11.32,0L136,140.69,212.69,64H168a8,8,0,0,1,0-16h64A8,8,0,0,1,240,56Z\"/>",
116
+ "corners-in": "<path d=\"M152,96V48a8,8,0,0,1,16,0V88h40a8,8,0,0,1,0,16H160A8,8,0,0,1,152,96ZM96,152H48a8,8,0,0,0,0,16H88v40a8,8,0,0,0,16,0V160A8,8,0,0,0,96,152Zm112,0H160a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V168h40a8,8,0,0,0,0-16ZM96,40a8,8,0,0,0-8,8V88H48a8,8,0,0,0,0,16H96a8,8,0,0,0,8-8V48A8,8,0,0,0,96,40Z\"/>"
113
117
  };
114
118
  const PH_FILL = {
115
119
  archive: "<path d=\"M224,48H32A16,16,0,0,0,16,64V88a16,16,0,0,0,16,16v88a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm-72,96H104a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm72-56H32V64H224V88Z\"/>",
@@ -209,7 +213,11 @@ const PH_FILL = {
209
213
  "sort-ascending": "<path d=\"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM72,72h96a8,8,0,0,1,0,16H72a8,8,0,0,1,0-16Zm40,112H72a8,8,0,0,1,0-16h40a8,8,0,0,1,0,16Zm8-48H72a8,8,0,0,1,0-16h48a8,8,0,0,1,0,16Zm77.66,29.66-24,24a8,8,0,0,1-11.32,0l-24-24a8,8,0,0,1,11.32-11.32L160,164.69V120a8,8,0,0,1,16,0v44.69l10.34-10.35a8,8,0,0,1,11.32,11.32Z\"/>",
210
214
  "dots-six-vertical": "<path d=\"M192,16H64A16,16,0,0,0,48,32V224a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V32A16,16,0,0,0,192,16ZM100,200a12,12,0,1,1,12-12A12,12,0,0,1,100,200Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,100,140Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,100,80Zm56,120a12,12,0,1,1,12-12A12,12,0,0,1,156,200Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,156,140Zm0-60a12,12,0,1,1,12-12A12,12,0,0,1,156,80Z\"/>",
211
215
  "push-pin": "<path d=\"M235.33,104l-53.47,53.65c4.56,12.67,6.45,33.89-13.19,60A15.93,15.93,0,0,1,157,224c-.38,0-.75,0-1.13,0a16,16,0,0,1-11.32-4.69L96.29,171,53.66,213.66a8,8,0,0,1-11.32-11.32L85,159.71l-48.3-48.3A16,16,0,0,1,38,87.63c25.42-20.51,49.75-16.48,60.4-13.14L152,20.7a16,16,0,0,1,22.63,0l60.69,60.68A16,16,0,0,1,235.33,104Z\"/>",
212
- keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48ZM64,168H48a8,8,0,0,1,0-16H64a8,8,0,0,1,0,16Zm96,0H96a8,8,0,0,1,0-16h64a8,8,0,0,1,0,16Zm48,0H192a8,8,0,0,1,0-16h16a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Z\"/>"
216
+ keyboard: "<path d=\"M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48ZM64,168H48a8,8,0,0,1,0-16H64a8,8,0,0,1,0,16Zm96,0H96a8,8,0,0,1,0-16h64a8,8,0,0,1,0,16Zm48,0H192a8,8,0,0,1,0-16h16a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Zm0-32H48a8,8,0,0,1,0-16H208a8,8,0,0,1,0,16Z\"/>",
217
+ "arrows-left-right": "<path d=\"M42.34,85.66a8,8,0,0,1,0-11.32l32-32A8,8,0,0,1,88,48V72H208a8,8,0,0,1,0,16H88v24a8,8,0,0,1-13.66,5.66Zm171.32,84.68-32-32A8,8,0,0,0,168,144v24H48a8,8,0,0,0,0,16H168v24a8,8,0,0,0,13.66,5.66l32-32A8,8,0,0,0,213.66,170.34Z\"/>",
218
+ sparkle: "<path d=\"M208,144a15.78,15.78,0,0,1-10.42,14.94L146,178l-19,51.62a15.92,15.92,0,0,1-29.88,0L78,178l-51.62-19a15.92,15.92,0,0,1,0-29.88L78,110l19-51.62a15.92,15.92,0,0,1,29.88,0L146,110l51.62,19A15.78,15.78,0,0,1,208,144ZM152,48h16V64a8,8,0,0,0,16,0V48h16a8,8,0,0,0,0-16H184V16a8,8,0,0,0-16,0V32H152a8,8,0,0,0,0,16Zm88,32h-8V72a8,8,0,0,0-16,0v8h-8a8,8,0,0,0,0,16h8v8a8,8,0,0,0,16,0V96h8a8,8,0,0,0,0-16Z\"/>",
219
+ "trend-up": "<path d=\"M240,56v64a8,8,0,0,1-13.66,5.66L200,99.31l-58.34,58.35a8,8,0,0,1-11.32,0L96,123.31,29.66,189.66a8,8,0,0,1-11.32-11.32l72-72a8,8,0,0,1,11.32,0L136,140.69,188.69,88,162.34,61.66A8,8,0,0,1,168,48h64A8,8,0,0,1,240,56Z\"/>",
220
+ "corners-in": "<path d=\"M152,96V48a8,8,0,0,1,13.66-5.66l48,48A8,8,0,0,1,208,104H160A8,8,0,0,1,152,96ZM96,152H48a8,8,0,0,0-5.66,13.66l48,48A8,8,0,0,0,104,208V160A8,8,0,0,0,96,152ZM99.06,40.61a8,8,0,0,0-8.72,1.73l-48,48A8,8,0,0,0,48,104H96a8,8,0,0,0,8-8V48A8,8,0,0,0,99.06,40.61ZM208,152H160a8,8,0,0,0-8,8v48a8,8,0,0,0,13.66,5.66l48-48A8,8,0,0,0,208,152Z\"/>"
213
221
  };
214
222
  /** Lucide names that map to a Phosphor icon. */
215
223
  const PH_ALIAS = {
@@ -6974,7 +6982,9 @@ function SectionGroupToggle({ className }) {
6974
6982
  // src/components/KpiCard/KpiCard.tsx
6975
6983
  /** One figure with its change and a sparkline. It is a card: put several in a grid, not inside another Card. */
6976
6984
  function KpiCard(props) {
6977
- const { label, value, unit, decimals = 0, delta, deltaUnit, good, spark, compareLabel, className } = props;
6985
+ const { label, value, unit, decimals = 0, delta, deltaUnit, good, spark, compareLabel, size = "default", verdict, target, className } = props;
6986
+ const compact = size === "compact";
6987
+ devWarn(compact && !!spark, "KpiCard", "size=\"compact\" 不畫迷你折線,spark 會被忽略。拿掉 spark,或改用一般大小。");
6978
6988
  devWarn(props.format === "percent" && !unit, "KpiCard", "format='percent' shows the number only; pass unit=\"%\" for the smaller % after it.");
6979
6989
  const t = useCountUp(value, 900);
6980
6990
  const valRef = React.useRef(null);
@@ -6992,14 +7002,14 @@ function KpiCard(props) {
6992
7002
  const isGood = good ?? up;
6993
7003
  const dTxt = hasDelta ? deltaUnit === "pt" ? tr("{n} 個百分點", { n: format.number(Math.abs(delta), 2) }) : format.percent(Math.abs(delta)) : "";
6994
7004
  let sparkD = null;
6995
- if (spark && spark.length > 1) {
7005
+ if (!compact && spark && spark.length > 1) {
6996
7006
  const mx = Math.max(...spark);
6997
7007
  const mn = Math.min(...spark);
6998
7008
  sparkD = smoothPath(spark.map((v, i) => [i * 160 / (spark.length - 1), 32 - (v - mn) / (mx - mn || 1) * 28]));
6999
7009
  }
7000
7010
  const showUnit = unit && props.format !== "money";
7001
7011
  return /* @__PURE__ */ jsxs("section", {
7002
- className: cx("ui-kpi", className),
7012
+ className: cx("ui-kpi", compact && "is-compact", className),
7003
7013
  children: [
7004
7014
  /* @__PURE__ */ jsx("div", {
7005
7015
  className: "ui-kpi-label",
@@ -7050,6 +7060,19 @@ function KpiCard(props) {
7050
7060
  className: "ui-kpi-note",
7051
7061
  children: compareLabel || tr("較上週")
7052
7062
  })]
7063
+ }) : null,
7064
+ verdict || target ? verdict && verdict.tone !== "success" ? /* @__PURE__ */ jsx("div", {
7065
+ className: "ui-kpi-target ui-kpi-verdict is-" + verdict.tone,
7066
+ children: target ? tr("{v}({t})", {
7067
+ v: verdict.text,
7068
+ t: target
7069
+ }) : verdict.text
7070
+ }) : /* @__PURE__ */ jsxs("div", {
7071
+ className: "ui-kpi-target",
7072
+ children: [verdict ? /* @__PURE__ */ jsx("span", {
7073
+ className: "ui-visually-hidden",
7074
+ children: verdict.text + tr(",")
7075
+ }) : null, target]
7053
7076
  }) : null
7054
7077
  ]
7055
7078
  });
@@ -8756,11 +8779,10 @@ function StatusLegend({ classes, label }) {
8756
8779
  });
8757
8780
  }
8758
8781
  // src/components/LineChart/LineChart.tsx
8759
- const W = 640;
8782
+ /** Plot geometry in px: y labels left of L, the 現在 label above T, the playhead handle below B. */
8760
8783
  const L = 40;
8761
- const R = 630;
8762
8784
  const T = 10;
8763
- const B = 210;
8785
+ const BELOW = 30;
8764
8786
  /** Runs of consecutive points that have values. */
8765
8787
  function runs(values, X, Y) {
8766
8788
  const out = [];
@@ -8777,16 +8799,32 @@ function runs(values, X, Y) {
8777
8799
  /** A trend over time: smooth lines, 5 grid lines, a guide and tooltip on hover. For monitoring it can also compare a
8778
8800
  * forecast with what happened (band, now, thresholds, marker) and replay with a playhead. */
8779
8801
  const colorOf = (s, i) => s?.color ? seriesColor(s.color - 1) : seriesColor(i);
8780
- function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelEvery = 1, band, now, thresholds, marker, playhead, onPlayheadChange, headline, status, empty, className }) {
8802
+ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelEvery = 1, band, now, thresholds, marker, playhead, onPlayheadChange, headline, status, empty, height = 240, className }) {
8781
8803
  const [hi, setHi] = React.useState(-1);
8804
+ const plot = React.useRef(null);
8805
+ const [W, setW] = React.useState(640);
8806
+ React.useLayoutEffect(() => {
8807
+ const el = plot.current;
8808
+ if (!el) return;
8809
+ const fit = () => {
8810
+ if (el.clientWidth > 0) setW(el.clientWidth);
8811
+ };
8812
+ fit();
8813
+ if (typeof ResizeObserver !== "function") return;
8814
+ const ro = new ResizeObserver(fit);
8815
+ ro.observe(el);
8816
+ return () => ro.disconnect();
8817
+ }, []);
8818
+ const R = W - 10;
8819
+ const B = height - BELOW;
8782
8820
  const stripes = "ui-stripes-" + React.useId().replace(/:/g, "");
8783
8821
  const dragging = React.useRef(false);
8784
8822
  const all = series.flatMap((s) => s.values.filter((v) => v != null));
8785
8823
  const top = max ?? niceMax(Math.max(min + 1, ...all, ...(thresholds ?? []).map((t) => t.value)) - min) + min;
8786
8824
  const n = labels.length || series[0]?.values.length || 0;
8787
- const step = 590 / Math.max(1, n - 1);
8825
+ const step = (R - L) / Math.max(1, n - 1);
8788
8826
  const X = (i) => L + i * step;
8789
- const Y = (v) => B - (v - min) / (top - min) * 200;
8827
+ const Y = (v) => B - (v - min) / (top - min) * (B - T);
8790
8828
  const ticks = TICKS.map((f) => min + f * (top - min));
8791
8829
  const suffix = unit ? " " + unit : "";
8792
8830
  const num = (v) => v == null ? "—" : format.number(v, decimals) + suffix;
@@ -8806,9 +8844,12 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8806
8844
  };
8807
8845
  const edge = {
8808
8846
  left: (L - step / 2) / W * 100 + "%",
8809
- right: (10 - step / 2) / W * 100 + "%"
8847
+ right: (W - R - step / 2) / W * 100 + "%"
8810
8848
  };
8811
8849
  const legend = series.length > 1 || band;
8850
+ const widest = Math.max(0, ...labels.map((lb) => lb.length)) * 7.5 + 12;
8851
+ const every = Math.max(labelEvery, Math.ceil(n * widest / Math.max(1, R - L) / labelEvery) * labelEvery);
8852
+ const markerLeft = marker ? X(marker.at) + 10 + [...marker.label].reduce((w, c) => w + (c.charCodeAt(0) > 11904 ? 14 : 8), 0) > W : false;
8812
8853
  const bandShapes = [];
8813
8854
  if (band) {
8814
8855
  const a = series[band.between[0]]?.values ?? [];
@@ -8861,6 +8902,7 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8861
8902
  }), s.name] }, i)), band ? /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", { className: cx("ui-chart-swatch", "is-band", "is-" + band.tone) }), band.label] }) : null]
8862
8903
  }) : null,
8863
8904
  /* @__PURE__ */ jsxs("div", {
8905
+ ref: plot,
8864
8906
  className: cx("ui-chart-plot", replay && "is-replay"),
8865
8907
  tabIndex: n ? 0 : void 0,
8866
8908
  role: "group",
@@ -8892,8 +8934,9 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8892
8934
  },
8893
8935
  children: [
8894
8936
  /* @__PURE__ */ jsxs("svg", {
8895
- viewBox: `0 0 ${W} 240`,
8937
+ viewBox: `0 0 ${W} ${height}`,
8896
8938
  width: "100%",
8939
+ height,
8897
8940
  "aria-hidden": "true",
8898
8941
  children: [
8899
8942
  now != null && now < n - 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("pattern", {
@@ -8911,7 +8954,7 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8911
8954
  x: X(now),
8912
8955
  y: T,
8913
8956
  width: R - X(now),
8914
- height: 200,
8957
+ height: B - T,
8915
8958
  fill: `url(#${stripes})`
8916
8959
  })] }) : null,
8917
8960
  ticks.map((v, i) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
@@ -8939,7 +8982,7 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8939
8982
  y1: Y(t.value),
8940
8983
  y2: Y(t.value)
8941
8984
  }), /* @__PURE__ */ jsx("text", {
8942
- x: 628,
8985
+ x: R - 2,
8943
8986
  y: Y(t.value) - 5,
8944
8987
  textAnchor: "end",
8945
8988
  children: t.label
@@ -8976,9 +9019,9 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8976
9019
  r: 5.5,
8977
9020
  style: { stroke: colorOf(series[marker.series ?? series.length - 1], marker.series ?? series.length - 1) }
8978
9021
  }), /* @__PURE__ */ jsx("text", {
8979
- x: X(marker.at) + (marker.at > n * .7 ? -10 : 10),
9022
+ x: X(marker.at) + (markerLeft ? -10 : 10),
8980
9023
  y: Y(marker.value) + 20,
8981
- textAnchor: marker.at > n * .7 ? "end" : "start",
9024
+ textAnchor: markerLeft ? "end" : "start",
8982
9025
  children: marker.label
8983
9026
  })]
8984
9027
  }) : null,
@@ -8999,7 +9042,10 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
8999
9042
  }),
9000
9043
  /* @__PURE__ */ jsx("div", {
9001
9044
  className: "ui-chart-hit",
9002
- style: edge,
9045
+ style: {
9046
+ ...edge,
9047
+ bottom: BELOW
9048
+ },
9003
9049
  children: labels.map((_, j) => /* @__PURE__ */ jsx("div", {
9004
9050
  onMouseEnter: () => !dragging.current && setHi(j),
9005
9051
  className: "ui-chart-col",
@@ -9048,7 +9094,7 @@ function LineChart({ series, labels, label, unit, decimals, max, min = 0, labelE
9048
9094
  marginLeft: edge.left,
9049
9095
  marginRight: edge.right
9050
9096
  },
9051
- children: labels.map((lb, j) => /* @__PURE__ */ jsx("span", { children: labelEvery > 1 && j % labelEvery ? "" : digits(lb) }, j))
9097
+ children: labels.map((lb, j) => /* @__PURE__ */ jsx("span", { children: every > 1 && j % every ? "" : digits(lb) }, j))
9052
9098
  }),
9053
9099
  status ? /* @__PURE__ */ jsx(StatusLegend, {
9054
9100
  classes: status.classes,
@@ -9168,6 +9214,288 @@ function Meter({ label, value, min, max, warn, limit, unit, decimals = 0, classN
9168
9214
  ]
9169
9215
  });
9170
9216
  }
9217
+ // src/components/ZoneMap/ZoneMap.tsx
9218
+ /** A floor plan of zones as rectangles on a grid, each filled by its value (heat scale) with its name, state, figure
9219
+ * and one detail line. Zones are buttons: Tab moves between them, Enter or Space selects. The selected zone has an
9220
+ * ink outline outside it; a zone needing attention has a 4 px warning or danger border and 「⚠」 in its state. */
9221
+ const DATA_TOKEN = /^(heat-[1-7]|diverge-(neg|pos)(-strong)?|diverge-zero|chart-[1-4])$/;
9222
+ function ZoneMap({ zones, label, columns = 4, rowHeight = 120, min = 20, max = 30, selectedId, onSelect, className }) {
9223
+ return /* @__PURE__ */ jsx("div", {
9224
+ className: cx("ui-zonemap", className),
9225
+ role: "group",
9226
+ "aria-label": label,
9227
+ style: {
9228
+ "--zone-cols": columns,
9229
+ gridAutoRows: rowHeight + "px"
9230
+ },
9231
+ children: zones.map((z) => {
9232
+ const place = z.area ? {
9233
+ gridRow: `${z.area.row} / span ${z.area.rows ?? 1}`,
9234
+ gridColumn: `${z.area.col} / span ${z.area.cols ?? 1}`
9235
+ } : void 0;
9236
+ if (z.value == null && !z.forecast) return /* @__PURE__ */ jsxs("div", {
9237
+ className: "ui-zone is-empty",
9238
+ style: place,
9239
+ children: [/* @__PURE__ */ jsx("span", {
9240
+ className: "ui-zone-name",
9241
+ children: z.name
9242
+ }), /* @__PURE__ */ jsx("span", {
9243
+ className: "ui-zone-detail",
9244
+ children: tr("沒有資料")
9245
+ })]
9246
+ }, z.id);
9247
+ const tone = z.tone ?? "normal";
9248
+ const fill = z.fill ?? (z.value != null ? heatToken(z.value, min, max) : "surface-sub");
9249
+ const bg = /^[a-z][a-z0-9-]*$/.test(fill) ? `var(--${fill})` : fill;
9250
+ const state = (tone === "normal" ? "" : "⚠ ") + (z.state ?? (z.forecast ? tr("預測") : tr("正常")));
9251
+ const figure = z.value != null ? format.number(z.value, z.decimals ?? 1) : "—";
9252
+ const on = selectedId === z.id;
9253
+ return /* @__PURE__ */ jsxs("button", {
9254
+ type: "button",
9255
+ className: cx("ui-zone", "is-" + tone, z.forecast && "ui-forecast", on && "is-selected"),
9256
+ "data-fill": fill,
9257
+ style: {
9258
+ ...place,
9259
+ background: bg,
9260
+ color: DATA_TOKEN.test(fill) ? void 0 : textOn(fill)
9261
+ },
9262
+ "aria-pressed": on,
9263
+ "aria-label": [
9264
+ z.name,
9265
+ figure + (z.unit ? " " + z.unit : ""),
9266
+ state.replace("⚠ ", ""),
9267
+ z.detail
9268
+ ].filter(Boolean).join(tr(",")),
9269
+ onClick: () => onSelect?.(z),
9270
+ children: [
9271
+ /* @__PURE__ */ jsxs("span", {
9272
+ className: "ui-zone-head",
9273
+ children: [/* @__PURE__ */ jsx("span", {
9274
+ className: "ui-zone-name",
9275
+ children: z.name
9276
+ }), /* @__PURE__ */ jsx("span", {
9277
+ className: "ui-zone-state",
9278
+ children: state
9279
+ })]
9280
+ }),
9281
+ /* @__PURE__ */ jsxs("span", {
9282
+ className: "ui-zone-value",
9283
+ children: [figure, z.unit ? /* @__PURE__ */ jsx("span", {
9284
+ className: "ui-zone-unit",
9285
+ children: z.unit
9286
+ }) : null]
9287
+ }),
9288
+ z.detail ? /* @__PURE__ */ jsx("span", {
9289
+ className: "ui-zone-detail",
9290
+ children: z.detail
9291
+ }) : null
9292
+ ]
9293
+ }, z.id);
9294
+ })
9295
+ });
9296
+ }
9297
+ // src/components/EventTimeline/EventTimeline.tsx
9298
+ const KIND = {
9299
+ alert: {
9300
+ icon: "warning",
9301
+ name: "告警"
9302
+ },
9303
+ switch: {
9304
+ icon: "arrows-left-right",
9305
+ name: "切換"
9306
+ },
9307
+ ai: {
9308
+ icon: "sparkle",
9309
+ name: "AI"
9310
+ },
9311
+ manual: {
9312
+ icon: "user",
9313
+ name: "人工"
9314
+ }
9315
+ };
9316
+ /** Events newest first, one row each: the time (Geist Mono), an icon for the kind, and what happened. */
9317
+ function EventTimeline({ events, label, empty, className }) {
9318
+ const list = [...events].sort((a, b) => b.time.getTime() - a.time.getTime());
9319
+ if (!list.length) return /* @__PURE__ */ jsx("p", {
9320
+ className: cx("ui-events-empty", className),
9321
+ children: empty ?? tr("沒有事件")
9322
+ });
9323
+ return /* @__PURE__ */ jsx("ol", {
9324
+ className: cx("ui-events", className),
9325
+ "aria-label": label,
9326
+ children: list.map((e, i) => /* @__PURE__ */ jsxs("li", {
9327
+ className: "is-" + e.kind,
9328
+ children: [
9329
+ /* @__PURE__ */ jsx("time", {
9330
+ className: "ui-events-time",
9331
+ dateTime: e.time.toISOString(),
9332
+ children: format.time(e.time)
9333
+ }),
9334
+ /* @__PURE__ */ jsx("span", {
9335
+ className: "ui-events-kind",
9336
+ role: "img",
9337
+ "aria-label": tr(KIND[e.kind].name),
9338
+ children: /* @__PURE__ */ jsx(Icon, {
9339
+ name: KIND[e.kind].icon,
9340
+ size: 20
9341
+ })
9342
+ }),
9343
+ /* @__PURE__ */ jsx("span", {
9344
+ className: "ui-events-text",
9345
+ children: e.text
9346
+ })
9347
+ ]
9348
+ }, e.id ?? i))
9349
+ });
9350
+ }
9351
+ // src/components/ConsoleLayout/ConsoleLayout.tsx
9352
+ /** Design size: at this size and up the layout zooms in. */
9353
+ const BASE_W = 1440;
9354
+ const BASE_H = 900;
9355
+ const MAX_ZOOM = 1.5;
9356
+ const PHONE = 600;
9357
+ /** Zoom for a screen of w × h px: 1 up to 1440 × 900, then grows with the screen, at most 1.5. */
9358
+ function consoleZoom(w, h) {
9359
+ return Math.max(1, Math.min(MAX_ZOOM, Math.min(w / BASE_W, h / BASE_H)));
9360
+ }
9361
+ /** A full-screen monitoring layout: a top bar (title, tags, then status, KPIs, clock and full screen on the right),
9362
+ * the main view with a side panel beside it and a bottom row under it, filling the screen without scrolling. From
9363
+ * 1440 × 900 up everything zooms with the screen (at most 1.5×). Phones (under 600 px) get one scrolling column. */
9364
+ function ConsoleLayout({ title, tags, status, kpis, clock, fullscreen = true, main, side, bottom, extras, className }) {
9365
+ const ref = React.useRef(null);
9366
+ const [size, setSize] = React.useState(null);
9367
+ const [full, setFull] = React.useState(false);
9368
+ const canFull = typeof document !== "undefined" && document.fullscreenEnabled === true;
9369
+ React.useLayoutEffect(() => {
9370
+ const el = ref.current;
9371
+ if (!el) return;
9372
+ const measure = () => setSize({
9373
+ w: el.clientWidth,
9374
+ h: el.clientHeight
9375
+ });
9376
+ measure();
9377
+ if (typeof ResizeObserver === "undefined") return;
9378
+ const ro = new ResizeObserver(measure);
9379
+ ro.observe(el);
9380
+ return () => ro.disconnect();
9381
+ }, []);
9382
+ React.useEffect(() => {
9383
+ const f = () => setFull(document.fullscreenElement != null && document.fullscreenElement === ref.current);
9384
+ document.addEventListener("fullscreenchange", f);
9385
+ return () => document.removeEventListener("fullscreenchange", f);
9386
+ }, []);
9387
+ const toggleFull = () => {
9388
+ const el = ref.current;
9389
+ if (!el) return;
9390
+ if (document.fullscreenElement) document.exitFullscreen().catch(() => void 0);
9391
+ else el.requestFullscreen().catch(() => void 0);
9392
+ };
9393
+ const phone = size != null && size.w < PHONE;
9394
+ const zoom = size && !phone ? consoleZoom(size.w, size.h) : 1;
9395
+ const logicalH = size ? size.h / zoom : 0;
9396
+ const shown = (extras ?? []).filter((x) => phone || logicalH >= x.minHeight);
9397
+ const frameStyle = size && !phone && zoom !== 1 ? {
9398
+ zoom,
9399
+ width: size.w / zoom,
9400
+ height: size.h / zoom
9401
+ } : void 0;
9402
+ const top = /* @__PURE__ */ jsxs("header", {
9403
+ className: "ui-console-top",
9404
+ children: [/* @__PURE__ */ jsxs("div", {
9405
+ className: "ui-console-start",
9406
+ children: [/* @__PURE__ */ jsx("h1", {
9407
+ className: "ui-console-title",
9408
+ children: title
9409
+ }), tags]
9410
+ }), /* @__PURE__ */ jsxs("div", {
9411
+ className: "ui-console-end",
9412
+ children: [
9413
+ status != null ? /* @__PURE__ */ jsx("span", {
9414
+ className: "ui-console-status",
9415
+ children: status
9416
+ }) : null,
9417
+ kpis != null ? /* @__PURE__ */ jsx("div", {
9418
+ className: "ui-console-kpis",
9419
+ children: kpis
9420
+ }) : null,
9421
+ clock != null ? /* @__PURE__ */ jsx("span", {
9422
+ className: "ui-console-clock",
9423
+ children: clock
9424
+ }) : null,
9425
+ fullscreen && canFull && !phone ? /* @__PURE__ */ jsx(IconButton, {
9426
+ label: full ? tr("離開全螢幕") : tr("全螢幕"),
9427
+ icon: full ? "corners-in" : "corners-out",
9428
+ onClick: toggleFull
9429
+ }) : null
9430
+ ]
9431
+ })]
9432
+ });
9433
+ return /* @__PURE__ */ jsx("div", {
9434
+ ref,
9435
+ className: cx("ui-console", phone && "is-stacked", className),
9436
+ children: /* @__PURE__ */ jsxs("div", {
9437
+ className: "ui-console-frame",
9438
+ style: frameStyle,
9439
+ children: [
9440
+ top,
9441
+ /* @__PURE__ */ jsx("main", {
9442
+ className: "ui-console-main",
9443
+ children: main
9444
+ }),
9445
+ phone ? /* @__PURE__ */ jsxs(Fragment, { children: [
9446
+ side,
9447
+ bottom,
9448
+ shown.map((x) => /* @__PURE__ */ jsx(React.Fragment, { children: x.node }, x.id))
9449
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("aside", {
9450
+ className: "ui-console-side",
9451
+ "aria-label": tr("側欄"),
9452
+ children: [side, shown.map((x) => /* @__PURE__ */ jsx(React.Fragment, { children: x.node }, x.id))]
9453
+ }), bottom != null ? /* @__PURE__ */ jsx("div", {
9454
+ className: "ui-console-bottom",
9455
+ children: bottom
9456
+ }) : null] })
9457
+ ]
9458
+ })
9459
+ });
9460
+ }
9461
+ // src/components/TimeControl/TimeControl.tsx
9462
+ /** The clock of a monitoring screen with replay: the time in 28 px Geist Mono, two lines on what is on show, and
9463
+ * 「回放」 (「停止回放」 while replaying) and 「回到現在」. Laid out as a column for a 400 px side panel. Moving within
9464
+ * the replay is LineChart's playhead. */
9465
+ function TimeControl({ time, replaying, onReplayChange, onNow, status, detail, className }) {
9466
+ return /* @__PURE__ */ jsxs("section", {
9467
+ className: cx("ui-timecontrol", className),
9468
+ "aria-label": tr("時間控制"),
9469
+ children: [
9470
+ /* @__PURE__ */ jsx("time", {
9471
+ className: "ui-timecontrol-clock",
9472
+ dateTime: time.toISOString(),
9473
+ "aria-live": "off",
9474
+ children: format.time(time)
9475
+ }),
9476
+ /* @__PURE__ */ jsx("p", {
9477
+ className: "ui-timecontrol-status",
9478
+ "aria-live": "polite",
9479
+ children: status
9480
+ }),
9481
+ detail ? /* @__PURE__ */ jsx("p", {
9482
+ className: "ui-timecontrol-detail",
9483
+ children: detail
9484
+ }) : null,
9485
+ /* @__PURE__ */ jsxs("div", {
9486
+ className: "ui-timecontrol-actions",
9487
+ children: [/* @__PURE__ */ jsx(Button, {
9488
+ onClick: () => onReplayChange(!replaying),
9489
+ children: replaying ? tr("停止回放") : tr("回放")
9490
+ }), /* @__PURE__ */ jsx(Button, {
9491
+ onClick: onNow,
9492
+ disabled: !replaying,
9493
+ children: tr("回到現在")
9494
+ })]
9495
+ })
9496
+ ]
9497
+ });
9498
+ }
9171
9499
  // src/components/LoadingBar/LoadingBar.tsx
9172
9500
  /** Loading with no known end: a drop moving along a thin bar. */
9173
9501
  function LoadingBar({ label, className }) {
@@ -10058,12 +10386,18 @@ function SegmentedControl({ items, value, onChange, label, iconOnly = false, cla
10058
10386
  });
10059
10387
  }
10060
10388
  // src/components/Tag/Tag.tsx
10061
- /** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two filled kinds say
10062
- * where numbers come from: forecast and demo. */
10389
+ /** What kind of thing an item is (「外部」「範本」): small gray text. Status uses Badge instead. Two kinds say where
10390
+ * numbers come from, with an icon and no fill: forecast and demo. */
10063
10391
  function Tag({ children, variant = "plain", className }) {
10064
- return /* @__PURE__ */ jsx("span", {
10392
+ return /* @__PURE__ */ jsxs("span", {
10065
10393
  className: cx("ui-tag", variant !== "plain" && "is-" + variant, className),
10066
- children
10394
+ children: [variant === "forecast" ? /* @__PURE__ */ jsx(Icon, {
10395
+ name: "trend-up",
10396
+ size: 16
10397
+ }) : variant === "demo" ? /* @__PURE__ */ jsx(Icon, {
10398
+ name: "info",
10399
+ size: 16
10400
+ }) : null, children]
10067
10401
  });
10068
10402
  }
10069
10403
  // src/components/TextArea/TextArea.tsx
@@ -12378,6 +12712,6 @@ function Workbench({ ref, ...p }) {
12378
12712
  })
12379
12713
  });
12380
12714
  }
12381
- 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, Meter, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, StatusBand, StatusLegend, 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 };
12715
+ export { AccentPicker, ActionBar, AiMark, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, ConsoleLayout, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, EventTimeline, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Markdown, Menu, Meter, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, SegmentedControl, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, StatusBand, StatusLegend, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, TimeControl, Toast, Tooltip, TopBar, Tour, TreeList, Workbench, ZoneMap, addMessages, announce, consoleZoom, divergeToken, focusMain, format, heatToken, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, textOn, useTour, useWorkbench };
12382
12716
 
12383
12717
  //# sourceMappingURL=index.js.map