@devicechain/widget-sdk 1.5.0 → 1.6.0-rc.1
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/AGENTS.md +40 -0
- package/README.md +33 -0
- package/dist/chunks/{chunk-25TE35L2.js → chunk-KKUMZN7N.js} +6 -5
- package/dist/chunks/chunk-KKUMZN7N.js.map +7 -0
- package/dist/chunks/{chunk-G6I5HKQM.js → chunk-MYW73WDC.js} +1 -1
- package/dist/chunks/chunk-MYW73WDC.js.map +7 -0
- package/dist/chunks/{chunk-IG6DBHKZ.js → chunk-R5MVRXBO.js} +3 -3
- package/dist/chunks/{chunk-IG6DBHKZ.js.map → chunk-R5MVRXBO.js.map} +1 -1
- package/dist/chunks/{chunk-6AJHBKU3.js → chunk-ZCOHPFPW.js} +2 -2
- package/dist/chunks/{chunk-6AJHBKU3.js.map → chunk-ZCOHPFPW.js.map} +1 -1
- package/dist/chunks/{echart-engine-FO4HQ22H.js → echart-engine-HYUPSQUL.js} +1 -1
- package/dist/chunks/echart-engine-HYUPSQUL.js.map +7 -0
- package/dist/chunks/{export-menu-727YDRIA.js → export-menu-VFLUUFWM.js} +8 -6
- package/dist/chunks/export-menu-VFLUUFWM.js.map +7 -0
- package/dist/echarts.js +48 -41
- package/dist/echarts.js.map +2 -2
- package/dist/empty-state.js +31 -15
- package/dist/empty-state.js.map +2 -2
- package/dist/freshness.d.ts +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +2 -2
- package/dist/strict-csp.js +1 -1
- package/package.json +4 -3
- package/dist/chunks/chunk-25TE35L2.js.map +0 -7
- package/dist/chunks/chunk-G6I5HKQM.js.map +0 -7
- package/dist/chunks/echart-engine-FO4HQ22H.js.map +0 -7
- package/dist/chunks/export-menu-727YDRIA.js.map +0 -7
package/dist/echarts.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
formatValue,
|
|
6
6
|
parseThresholds,
|
|
7
7
|
thresholdBands
|
|
8
|
-
} from "./chunks/chunk-
|
|
8
|
+
} from "./chunks/chunk-R5MVRXBO.js";
|
|
9
9
|
import {
|
|
10
10
|
isAlarmLevel,
|
|
11
11
|
levelColor,
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
severityFallbackColors,
|
|
14
14
|
useRegisterWidgetImage,
|
|
15
15
|
useWidgetThemeRoot
|
|
16
|
-
} from "./chunks/chunk-
|
|
16
|
+
} from "./chunks/chunk-MYW73WDC.js";
|
|
17
17
|
import {
|
|
18
18
|
strictCspEnabled
|
|
19
|
-
} from "./chunks/chunk-
|
|
19
|
+
} from "./chunks/chunk-ZCOHPFPW.js";
|
|
20
20
|
|
|
21
21
|
// src/chart/echart.tsx
|
|
22
22
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -24,7 +24,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
24
24
|
var engine;
|
|
25
25
|
var engineLoading;
|
|
26
26
|
function loadEngine() {
|
|
27
|
-
engineLoading ?? (engineLoading = import("./chunks/echart-engine-
|
|
27
|
+
engineLoading ?? (engineLoading = import("./chunks/echart-engine-HYUPSQUL.js").then(
|
|
28
28
|
(m) => engine = m,
|
|
29
29
|
(err) => {
|
|
30
30
|
engineLoading = void 0;
|
|
@@ -216,7 +216,7 @@ function buildLineOption(samples, theme, options = {}, size) {
|
|
|
216
216
|
// Strict-CSP host mode (configureStrictCsp): drawn on the canvas, because the HTML tooltip's
|
|
217
217
|
// rows carry `style=""` attributes a policy without `style-src 'unsafe-inline'` refuses.
|
|
218
218
|
...strictCspEnabled() ? { renderMode: "richText" } : {},
|
|
219
|
-
valueFormatter: (v) => typeof v === "number" ? `${formatValue(v, precision)}${suffix}` : String(v ?? "
|
|
219
|
+
valueFormatter: (v) => typeof v === "number" ? `${formatValue(v, precision)}${suffix}` : String(v ?? "—")
|
|
220
220
|
},
|
|
221
221
|
legend: names.length > 1 ? { textStyle: { color: theme.mutedForeground, fontSize: axisFont }, top: 0 } : void 0,
|
|
222
222
|
xAxis: {
|
|
@@ -285,7 +285,7 @@ function buildGaugeOption(value, theme, options = {}, size) {
|
|
|
285
285
|
const labelFont = clamp(Math.round(s / 20), Math.round(8 * scale), Math.round(13 * scale));
|
|
286
286
|
const showAxisLabels = s >= GAUGE_AXIS_LABELS_MIN_SIDE;
|
|
287
287
|
const unitSuffix = options.unit ? ` ${options.unit}` : "";
|
|
288
|
-
const readout = value == null ? "
|
|
288
|
+
const readout = value == null ? "—" : `${formatValue(value, options.precision)}${unitSuffix}`;
|
|
289
289
|
const valueFont = fitValueFont({ width: s * 0.7, height: s * 0.25 }, readout.length, {
|
|
290
290
|
floor: Math.round(FIT_MIN_FONT_PX * scale)
|
|
291
291
|
});
|
|
@@ -318,7 +318,7 @@ function buildGaugeOption(value, theme, options = {}, size) {
|
|
|
318
318
|
color: theme.foreground,
|
|
319
319
|
fontSize: valueFont,
|
|
320
320
|
offsetCenter: [0, `${GAUGE_READOUT_OFFSET * 100}%`],
|
|
321
|
-
formatter: (v) => value == null ? "
|
|
321
|
+
formatter: (v) => value == null ? "—" : `${formatValue(v, options.precision)}${unitSuffix}`
|
|
322
322
|
},
|
|
323
323
|
data: [{ value: value ?? min }]
|
|
324
324
|
}
|
|
@@ -374,7 +374,7 @@ function buildCompassOption(value, theme, options, size) {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
// src/chart/chart-theme.ts
|
|
377
|
-
import {
|
|
377
|
+
import { useSyncExternalStore } from "react";
|
|
378
378
|
var FALLBACK = {
|
|
379
379
|
foreground: "hsl(240 10% 3.9%)",
|
|
380
380
|
mutedForeground: "hsl(240 3.8% 46.1%)",
|
|
@@ -402,43 +402,50 @@ function resolveChartTheme(el) {
|
|
|
402
402
|
severity: severityColorsAt(el, style)
|
|
403
403
|
};
|
|
404
404
|
}
|
|
405
|
-
var
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
405
|
+
var themeStores = /* @__PURE__ */ new WeakMap();
|
|
406
|
+
function createThemeStore(root) {
|
|
407
|
+
let theme = null;
|
|
408
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
409
|
+
let observer = null;
|
|
410
|
+
const recompute = () => {
|
|
411
|
+
theme = resolveChartTheme(root);
|
|
412
|
+
};
|
|
413
|
+
return {
|
|
414
|
+
getSnapshot: () => {
|
|
415
|
+
if (!theme) recompute();
|
|
416
|
+
return theme;
|
|
417
|
+
},
|
|
418
|
+
subscribe: (listener) => {
|
|
419
|
+
if (!observer) {
|
|
420
|
+
recompute();
|
|
421
|
+
observer = new MutationObserver(() => {
|
|
422
|
+
recompute();
|
|
423
|
+
for (const notify of listeners) notify();
|
|
424
|
+
});
|
|
425
|
+
for (let element = root; element; element = element.parentElement) {
|
|
426
|
+
observer.observe(element, { attributes: true, attributeFilter: ["class", "style"] });
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
listeners.add(listener);
|
|
430
|
+
return () => {
|
|
431
|
+
listeners.delete(listener);
|
|
432
|
+
if (listeners.size === 0 && observer) {
|
|
433
|
+
observer.disconnect();
|
|
434
|
+
observer = null;
|
|
435
|
+
theme = null;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
430
438
|
}
|
|
431
439
|
};
|
|
432
440
|
}
|
|
433
|
-
function getThemeSnapshot() {
|
|
434
|
-
if (!sharedTheme) recomputeTheme();
|
|
435
|
-
return sharedTheme;
|
|
436
|
-
}
|
|
437
441
|
function useChartTheme() {
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
+
const root = useWidgetThemeRoot() ?? document.documentElement;
|
|
443
|
+
let store = themeStores.get(root);
|
|
444
|
+
if (!store) {
|
|
445
|
+
store = createThemeStore(root);
|
|
446
|
+
themeStores.set(root, store);
|
|
447
|
+
}
|
|
448
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
442
449
|
}
|
|
443
450
|
export {
|
|
444
451
|
EChart,
|
package/dist/echarts.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/chart/echart.tsx", "../src/chart/chart-options.ts", "../src/chart/chart-theme.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// A thin React wrapper over Apache ECharts (ADR-039 chart engine).\n//\n// \uD83D\uDD34 ECHARTS IS NOT IMPORTED HERE. The engine (ECharts + zrender, ~170 KB gzip, the largest single\n// dependency of a board) lives in echart-engine.ts and is loaded on demand, ONCE, as one chunk:\n// the first <EChart> to mount fetches it, and a host that wants the first frame complete fetches\n// it first with loadChartEngine (preloadWidgets does, for a board that holds a chart). Only TYPES\n// come from echarts here, and they are erased.\n//\n// The public surface is unchanged: <EChart option> is still a synchronous component. Once the\n// engine is here, a mount initialises the chart exactly as it always did; before it is, the\n// component renders its (empty) container and draws as soon as the engine arrives. A failed load\n// is THROWN, so the widget's error boundary shows it rather than an empty box that looks like a\n// chart with nothing to say, and it is NOT remembered: the next mount (the boundary's Reset)\n// fetches again, and nothing retries on its own.\n//\n// The wrapper owns the imperative lifecycle: init on mount, setOption on change, resize with the\n// container, dispose on unmount.\n\nimport type * as echarts from 'echarts/core';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { useRegisterWidgetImage } from '../context';\n\ntype Engine = typeof import('./echart-engine');\n\nlet engine: Engine | undefined;\nlet engineLoading: Promise<Engine> | undefined;\n\n// Memoized while in flight or loaded; a rejection is forgotten, so the next caller fetches again.\nfunction loadEngine(): Promise<Engine> {\n engineLoading ??= import('./echart-engine').then(\n (m) => (engine = m),\n (err: unknown) => {\n engineLoading = undefined;\n throw err;\n },\n );\n return engineLoading;\n}\n\n/**\n * Fetches the chart engine that <EChart> draws with, so the charts a host renders after awaiting\n * it draw on their first frame. Optional: an <EChart> that mounts first loads the engine itself.\n * Rejects if the engine cannot be fetched; a later call (or mount) fetches it again.\n */\nexport function loadChartEngine(): Promise<void> {\n return loadEngine().then(() => undefined);\n}\n\n// markLine / markArea are registered on first use (see echart-markers.ts for why). Until they\n// are, a chart that asks for them draws without them, and EChart re-applies its option once\n// they arrive -- a beat later on the first threshold chart of a page, never silently absent.\nlet markersReady = false;\nlet markersLoading: Promise<void> | undefined;\n\nexport function loadThresholdMarkers(): Promise<void> {\n markersLoading ??= loadEngine()\n .then((e) => e.registerThresholdMarkers())\n .then(\n () => {\n markersReady = true;\n },\n (err: unknown) => {\n markersLoading = undefined; // a failed chunk load is retried by the next chart that needs it\n throw err;\n },\n );\n return markersLoading;\n}\n\n// True when any series of the option carries a markLine or markArea.\nexport function optionUsesMarkers(option: EChartOption): boolean {\n const series = (option as { series?: unknown }).series;\n const list = Array.isArray(series) ? series : series ? [series] : [];\n return list.some((s) => {\n const m = s as { markLine?: unknown; markArea?: unknown } | null;\n return typeof m === 'object' && m !== null && (m.markLine != null || m.markArea != null);\n });\n}\n\n// A resolved ECharts option object (the shape echarts.setOption accepts). Widgets\n// build these with the pure builders in chart-options.ts.\nexport type EChartOption = echarts.EChartsCoreOption;\n\nexport interface EChartProps {\n option: EChartOption;\n className?: string;\n style?: React.CSSProperties;\n}\n\n// EChart fills its parent; the dashboard canvas sizes the parent, and a\n// ResizeObserver keeps the chart matched to it.\nexport function EChart({ option, className, style }: EChartProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const chartRef = useRef<echarts.ECharts | null>(null);\n const [loaded, setLoaded] = useState(engine);\n const [failed, setFailed] = useState<{ error: unknown }>();\n const [markersLoaded, setMarkersLoaded] = useState(markersReady);\n const needsMarkers = optionUsesMarkers(option) && !markersLoaded;\n\n // Offer the chart's image to the frame it is drawn in (its \"Download image\") once the engine is\n // here and the chart exists: a PNG at twice the on-screen resolution, on the background the frame\n // hands over, since the canvas itself is transparent.\n useRegisterWidgetImage(\n loaded\n ? ({ backgroundColor }) => {\n // A canvas-drawn tooltip (strict-CSP mode) is part of the picture: hide it first.\n chartRef.current?.dispatchAction({ type: 'hideTip' });\n return chartRef.current?.getDataURL({ type: 'png', pixelRatio: 2, backgroundColor });\n }\n : undefined,\n );\n\n // The engine, when this is the first chart to mount and nobody preloaded it.\n useEffect(() => {\n if (loaded) return;\n let live = true;\n loadEngine().then(\n (e) => live && setLoaded(e),\n (error: unknown) => live && setFailed({ error }),\n );\n return () => {\n live = false;\n };\n }, [loaded]);\n\n useEffect(() => {\n if (!needsMarkers) return;\n let live = true;\n loadThresholdMarkers().then(\n () => live && setMarkersLoaded(true),\n // Loud, not silent: the chart still draws, without its threshold lines.\n (err: unknown) => console.error('EChart: the threshold markers failed to load', err),\n );\n return () => {\n live = false;\n };\n }, [needsMarkers]);\n\n // Init + teardown once for the element's lifetime (from the moment the engine is here).\n useEffect(() => {\n const el = containerRef.current;\n if (!el || !loaded) return;\n\n const chart = loaded.init(el);\n chartRef.current = chart;\n\n const observer = new ResizeObserver(() => chart.resize());\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n chart.dispose();\n chartRef.current = null;\n };\n }, [loaded]);\n\n // Re-apply the option whenever it changes. notMerge:true so a shrinking series\n // (rolling window) doesn't leave stale points behind.\n useEffect(() => {\n chartRef.current?.setOption(option, { notMerge: true });\n }, [option, markersLoaded, loaded]);\n\n // To the widget's error boundary: a chart that cannot draw says so.\n if (failed) throw failed.error;\n\n // `data-echart` marks the chart's box, so a host (and the readability gate) can tell a chart\n // that has drawn (ECharts stamps `_echarts_instance_` on it) from one still waiting.\n return (\n <div ref={containerRef} data-echart=\"\" className={className} style={{ width: '100%', height: '100%', ...style }} />\n );\n}\n", "// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// Pure ECharts option builders. Kept free of React/DOM so the data\u2192chart mapping\n// is unit-testable without a canvas: a widget resolves a ChartTheme + samples and\n// hands the result straight to <EChart>.\n\nimport type { MeasurementSample } from '@devicechain/dashboards';\n\nimport { FIT_MIN_FONT_PX, fitValueFont } from '../fit-text';\nimport { formatValue } from '../format';\nimport type { ElementSize } from '../hooks';\nimport { strictCspEnabled } from '../strict-csp';\nimport { isAlarmLevel, levelColor, type AlarmLevel } from '../severity';\nimport { bandAt, parseThresholds, thresholdBands, type Threshold } from '../thresholds';\n\nimport type { ChartTheme } from './chart-theme';\nimport type { EChartOption } from './echart';\n\n// distinctNames returns the measurement names present in `samples`, in first-seen\n// order \u2014 used when a chart's datasource doesn't pin an explicit series list.\nfunction distinctNames(samples: MeasurementSample[]): string[] {\n const seen: string[] = [];\n for (const s of samples) {\n if (!seen.includes(s.name)) seen.push(s.name);\n }\n return seen;\n}\n\n// A severity colour with an alpha, for a band drawn UNDER the data (markArea). The theme's\n// severity colours are comma-form hsl(), so the alpha form is a string edit.\nexport function severityFill(theme: ChartTheme, level: AlarmLevel, alpha: number): string {\n return theme.severity[level].replace(/^hsl\\(/, 'hsla(').replace(/\\)$/, `, ${alpha})`);\n}\n\n// Opacity of a threshold band behind a line: enough to read as a zone, faint enough that the\n// line and its grid stay the subject. A `normal` band has no fill at all.\nconst BAND_ALPHA = 0.14;\n\nconst clamp = (v: number, lo: number, hi: number): number => Math.max(lo, Math.min(hi, v));\n\n// gauge/line fonts and tick counts scale with the smaller container dimension so a\n// widget stays legible when resized. A zero/absent size (before first measure, or\n// in a non-DOM test) falls back to a nominal medium size.\nfunction shortSide(size?: ElementSize): number {\n const s = Math.min(size?.width ?? 0, size?.height ?? 0);\n return s > 0 ? s : 200;\n}\n\nexport interface LineChartOptions {\n // Measurement names to plot, one series each. Empty \u2192 every name seen in the\n // window (first-seen order).\n measurements?: string[];\n // Unit suffix: named on the y-axis and appended to every tooltip value.\n unit?: string;\n // Decimal places for axis labels and tooltip values; unset uses the default rounding.\n precision?: number;\n // Severity thresholds, drawn as a labelled line each plus a faint band between them.\n // Any order: the builder sorts them.\n thresholds?: readonly Threshold[];\n // The board's density scale (useWidgetScale().scale): multiplies the axis-font clamp. Default 1.\n scale?: number;\n // Instants (ISO-8601, oldest first) after which nothing is known until the next sample: the live\n // feed was interrupted (MeasurementStreamState.gaps). Every line breaks at each one instead of\n // joining the samples on either side.\n gaps?: readonly string[];\n // The value axis's ends, as the author chose them. Each is a bound the axis REACHES, never a\n // clip: a reading or a threshold beyond it widens the axis to take it in, so a fixed end can\n // frame the data but never hide any. Unset (or not finite), that end is ECharts' own, as before.\n // Both set and not ascending, neither applies (the descriptor refuses such a pair).\n min?: number;\n max?: number;\n}\n\n// breakAtGaps puts an empty point -- which ECharts draws as a break in the line -- at each gap\n// that falls between two of a series' points. Points are in sample order (chronological).\nfunction breakAtGaps(points: Array<[string, number]>, gaps: readonly number[]): Array<[string, number | null]> {\n let g = 0;\n return points.flatMap((point, i): Array<[string, number | null]> => {\n // The last gap before this point; past the end of `gaps` the comparison is false.\n let gap = Number.NaN;\n while (gaps[g] < Date.parse(point[0])) gap = gaps[g++];\n return i > 0 && !Number.isNaN(gap) ? [[new Date(gap).toISOString(), null], point] : [point];\n });\n}\n\n// The markLine / markArea for a chart's thresholds, attached to the first series (the markers\n// belong to a series in ECharts, and every series shares the one y-axis).\nfunction thresholdMarks(theme: ChartTheme, thresholds: readonly Threshold[], unit: string | undefined, precision: number | undefined, fontSize: number) {\n const suffix = unit ? ` ${unit}` : '';\n // A `normal` threshold is still drawn: it is where the value RETURNS to normal, which an\n // operator wants to see. It is drawn in the muted text colour, the same ink as the axis\n // labels, which reads in light and dark and says \"boundary\" without saying \"alarm\".\n const ink = (t: Threshold) => levelColor(theme.severity, t.level) ?? theme.mutedForeground;\n const markLine = {\n silent: true,\n symbol: 'none',\n animation: false,\n data: thresholds.map((t) => ({\n yAxis: t.value,\n name: t.label ?? String(t.value),\n lineStyle: { color: ink(t), type: 'dashed' as const, width: 1.5 },\n label: {\n show: true,\n position: 'insideEndTop' as const,\n color: ink(t),\n fontSize,\n formatter: () => t.label ?? `${formatValue(t.value, precision)}${suffix}`,\n },\n })),\n };\n const markArea = {\n silent: true,\n animation: false,\n data: thresholdBands(thresholds, -Infinity, Infinity)\n .filter((b) => isAlarmLevel(b.level))\n .map((b) => [\n { yAxis: b.from, itemStyle: { color: severityFill(theme, b.level as AlarmLevel, BAND_ALPHA) } },\n { yAxis: b.to },\n ]),\n };\n return { markLine, markArea };\n}\n\n// One end of a line chart's value axis: `low` is the min end, otherwise the max end. `data` is\n// ECharts' own extent at that end (not finite with no data). With no author end, a threshold\n// beyond the data fixes the end at the threshold and otherwise ECharts keeps its auto range\n// (null). With one, the end is the furthest of the author's end, the threshold and the data, so\n// nothing drawn falls off the axis.\nfunction axisEnd(low: boolean, data: number, fixed: number | undefined, threshold: number | undefined): number | null {\n const beyond = (a: number, b: number): boolean => (low ? a < b : a > b);\n if (fixed === undefined) return threshold !== undefined && beyond(threshold, data) ? threshold : null;\n let end = fixed;\n if (Number.isFinite(data) && beyond(data, end)) end = data;\n if (threshold !== undefined && beyond(threshold, end)) end = threshold;\n return end;\n}\n\n// buildLineOption maps a rolling window of samples to a multi-series time chart,\n// one line per measurement name, coloured from the theme's chart palette.\nexport function buildLineOption(\n samples: MeasurementSample[],\n theme: ChartTheme,\n options: LineChartOptions = {},\n size?: ElementSize,\n): EChartOption {\n const names = options.measurements?.length ? options.measurements : distinctNames(samples);\n const scale = options.scale ?? 1;\n const axisFont = clamp(Math.round(shortSide(size) / 22), Math.round(8 * scale), Math.round(12 * scale));\n\n // Re-parsed (validated + sorted): the builder is public, and a caller may hand it a list\n // that never went through parseThresholds. Every rule below assumes ascending order.\n const thresholds = parseThresholds(options.thresholds ?? []);\n const lowest = thresholds.length > 0 ? thresholds[0].value : 0;\n const highest = thresholds.length > 0 ? thresholds[thresholds.length - 1].value : 0;\n const marks = thresholds.length > 0 ? thresholdMarks(theme, thresholds, options.unit, options.precision, axisFont) : undefined;\n const suffix = options.unit ? ` ${options.unit}` : '';\n const precision = options.precision;\n const gaps = (options.gaps ?? []).map(Date.parse).filter((g) => !Number.isNaN(g));\n const finite = (v: number | undefined): number | undefined => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);\n let fixedMin = finite(options.min);\n let fixedMax = finite(options.max);\n if (fixedMin !== undefined && fixedMax !== undefined && fixedMin >= fixedMax) fixedMin = fixedMax = undefined;\n\n const series = names.map((name, i) => {\n const color = theme.series[i % theme.series.length];\n return {\n ...(i === 0 ? marks : undefined),\n name,\n type: 'line' as const,\n showSymbol: false,\n lineStyle: { color },\n itemStyle: { color },\n data: breakAtGaps(\n samples\n .filter((s) => s.name === name && s.value != null && s.occurredTime != null)\n .map((s): [string, number] => [s.occurredTime as string, s.value as number]),\n gaps,\n ),\n };\n });\n\n return {\n animation: false,\n textStyle: { color: theme.foreground, fontSize: axisFont },\n grid: { left: 8, right: 12, top: names.length > 1 || options.unit ? 28 : 12, bottom: 8, containLabel: true },\n tooltip: {\n trigger: 'axis',\n // Strict-CSP host mode (configureStrictCsp): drawn on the canvas, because the HTML tooltip's\n // rows carry `style=\"\"` attributes a policy without `style-src 'unsafe-inline'` refuses.\n ...(strictCspEnabled() ? { renderMode: 'richText' as const } : {}),\n valueFormatter: (v: unknown) => (typeof v === 'number' ? `${formatValue(v, precision)}${suffix}` : String(v ?? '\u2014')),\n },\n legend:\n names.length > 1 ? { textStyle: { color: theme.mutedForeground, fontSize: axisFont }, top: 0 } : undefined,\n xAxis: {\n type: 'time',\n axisLine: { lineStyle: { color: theme.border } },\n axisLabel: { color: theme.mutedForeground, fontSize: axisFont, hideOverlap: true },\n },\n yAxis: {\n type: 'value',\n // The unit rides the axis once, at its head, rather than on every tick.\n name: options.unit,\n nameTextStyle: { color: theme.mutedForeground, fontSize: axisFont, align: 'left' as const },\n splitLine: { lineStyle: { color: theme.border } },\n axisLabel: {\n color: theme.mutedForeground,\n fontSize: axisFont,\n // Rounded only when the author asked; otherwise ECharts' own tick rounding applies.\n ...(precision != null ? { formatter: (v: number) => formatValue(v, precision) } : {}),\n },\n // A threshold outside the data's range must still be on the chart: extend the range to\n // take it in. Only then -- a returned number FIXES that end of the axis (no nice\n // rounding, no zero baseline), so a threshold inside the data returns null and leaves\n // ECharts' own auto range exactly as it is without thresholds. An author's end (min/max)\n // is the same kind of bound: the axis reaches it, and goes past it only for a reading or a\n // threshold beyond it.\n ...(thresholds.length > 0 || fixedMin !== undefined || fixedMax !== undefined\n ? {\n min: (e: { min: number }) => axisEnd(true, e.min, fixedMin, thresholds.length > 0 ? lowest : undefined),\n max: (e: { max: number }) => axisEnd(false, e.max, fixedMax, thresholds.length > 0 ? highest : undefined),\n }\n : {}),\n },\n series,\n };\n}\n\nexport interface GaugeChartOptions {\n min?: number;\n max?: number;\n unit?: string;\n // Decimal places for the readout; unset uses the default rounding.\n precision?: number;\n // Severity thresholds, drawn as coloured bands on the arc (any order).\n thresholds?: readonly Threshold[];\n // The board's density scale: multiplies the label-font clamp and the readout's floor. Default 1.\n scale?: number;\n // Where the number is drawn. 'canvas' (the default) paints it inside the dial, as the builder\n // always has, so a widget that renders only the chart keeps its readout. 'none' leaves the dial\n // bare for a caller that draws the number itself as DOM text in gaugeReadoutBox, which the\n // readability gate can measure (the built-in gauge does).\n readout?: 'canvas' | 'none';\n // Where the needle is with no value. 'min' (the default) rests it at the scale's minimum, as the\n // builder always has. 'none' draws no needle, so an empty dial cannot be read as a reading of\n // its minimum (the built-in gauge, whose readout already says there is no value, asks for it).\n emptyNeedle?: 'min' | 'none';\n}\n\n// The dial's geometry as fractions of its box: where its centre sits and how much of the short\n// side's half it fills. The DOM readout is placed from the same numbers (gaugeReadoutBox).\nconst GAUGE_CENTER_Y = 0.58;\nconst GAUGE_RADIUS = 0.95;\n// How far below the hub the readout sits, as a fraction of the radius.\nconst GAUGE_READOUT_OFFSET = 0.3;\n\n// The box (px, relative to the chart) the gauge's DOM readout is centred in and fitted to: under\n// the hub and inside the dial, where the canvas detail used to be drawn. A zero size (before the\n// first measure) takes the nominal one the builder assumes.\nexport function gaugeReadoutBox(size?: ElementSize): { centerX: number; centerY: number; width: number; height: number } {\n const s = shortSide(size);\n const w = (size?.width ?? 0) > 0 ? size!.width : s;\n const h = (size?.height ?? 0) > 0 ? size!.height : s;\n return {\n centerX: w / 2,\n centerY: GAUGE_CENTER_Y * h + GAUGE_READOUT_OFFSET * GAUGE_RADIUS * (s / 2),\n width: s * 0.7,\n height: s * 0.25,\n };\n}\n\n// Below this short side (px) the gauge drops its axis labels: at that size they would be\n// drawn at the 8 px floor, which is noise rather than a scale.\nexport const GAUGE_AXIS_LABELS_MIN_SIDE = 120;\n\n// The arc's colour stops: ECharts wants [[endFraction, colour], ...] ending at 1. A neutral\n// stretch (below the lowest threshold, or a `normal` band) takes the track colour. With no bands: one track.\nfunction gaugeArcColors(bands: ReturnType<typeof thresholdBands>, min: number, max: number, theme: ChartTheme): [number, string][] {\n if (bands.length === 0) return [[1, theme.border]];\n return bands.map((b, i): [number, string] => [\n i === bands.length - 1 ? 1 : (b.to - min) / (max - min),\n levelColor(theme.severity, b.level) ?? theme.border,\n ]);\n}\n\n// buildGaugeOption maps a single latest value to a gauge. A null value (nothing\n// received yet) shows an em dash and rests the needle at the minimum. Ticks, fonts,\n// and the arc width scale with the widget size so it stays legible when resized\n// (ECharts' default gauge crams ~10 labels at fixed fonts on a small canvas).\nexport function buildGaugeOption(\n value: number | null,\n theme: ChartTheme,\n options: GaugeChartOptions = {},\n size?: ElementSize,\n): EChartOption {\n const min = options.min ?? 0;\n const max = options.max ?? 100;\n const thresholds = parseThresholds(options.thresholds ?? []); // validated + sorted, as above\n const bands = thresholdBands(thresholds, min, max);\n // Banded only when a COLOURED band actually lands on the arc: thresholds that all sit above\n // `max`, or only `normal` bands, leave a plain neutral track, which keeps the progress arc\n // like any other gauge.\n const banded = bands.some((b) => isAlarmLevel(b.level));\n // The needle takes the colour of the band the value sits in; with no bands, below the\n // lowest, or in a `normal` band it keeps the chart accent.\n const accent = levelColor(theme.severity, bandAt(thresholds, value)?.level) ?? theme.series[0];\n\n const s = shortSide(size);\n const arcWidth = clamp(Math.round(s / 26), 4, 12);\n const scale = options.scale ?? 1;\n const labelFont = clamp(Math.round(s / 20), Math.round(8 * scale), Math.round(13 * scale));\n const showAxisLabels = s >= GAUGE_AXIS_LABELS_MIN_SIDE;\n const unitSuffix = options.unit ? ` ${options.unit}` : '';\n // The readout is fitted to the dial's inner box and its own length, like every big number.\n const readout = value == null ? '\u2014' : `${formatValue(value, options.precision)}${unitSuffix}`;\n const valueFont = fitValueFont({ width: s * 0.7, height: s * 0.25 }, readout.length, {\n floor: Math.round(FIT_MIN_FONT_PX * scale),\n });\n return {\n animation: false,\n series: [\n {\n type: 'gauge',\n min,\n max,\n splitNumber: s < 160 ? 4 : 5, // fewer ticks than the default 10 \u2192 no cram\n radius: `${GAUGE_RADIUS * 100}%`,\n center: ['50%', `${GAUGE_CENTER_Y * 100}%`],\n // The progress arc would paint over the bands, so with bands the needle alone marks the value.\n progress: { show: !banded, width: arcWidth, itemStyle: { color: accent } },\n pointer: {\n show: value != null || options.emptyNeedle !== 'none',\n itemStyle: { color: accent },\n length: '55%',\n width: clamp(Math.round(s / 50), 2, 6),\n },\n anchor: { show: false },\n axisLine: { lineStyle: { width: arcWidth, color: gaugeArcColors(bands, min, max, theme) } },\n axisTick: { show: false },\n splitLine: { length: arcWidth, lineStyle: { color: theme.border, width: 1 } },\n axisLabel: { show: showAxisLabels, color: theme.mutedForeground, fontSize: labelFont, distance: arcWidth + 2 },\n detail:\n options.readout === 'none'\n ? { show: false }\n : {\n valueAnimation: false,\n color: theme.foreground,\n fontSize: valueFont,\n offsetCenter: [0, `${GAUGE_READOUT_OFFSET * 100}%`],\n formatter: (v: number) => (value == null ? '\u2014' : `${formatValue(v, options.precision)}${unitSuffix}`),\n },\n data: [{ value: value ?? min }],\n },\n ],\n };\n}\n\n// A heading in degrees folded onto [0, 360): 370 is 10 and -90 is 270, because a compass has no\n// \"beyond a full turn\" and a bearing sensor may well report either. 360 is 0, never 360, and a\n// value that is not a finite number has no heading at all (undefined), not a plausible one.\nexport function wrapHeading(value: number | null | undefined): number | undefined {\n if (value == null || !Number.isFinite(value)) return undefined;\n return ((value % 360) + 360) % 360;\n}\n\nexport interface CompassChartOptions {\n // The four point labels in N, E, S, W order (a locale writes West as \"O\", so the caller owns them).\n cardinals: readonly [string, string, string, string];\n thresholds?: readonly Threshold[];\n // The board's density scale; multiplies the label-font clamp. Default 1.\n scale?: number;\n}\n\n// buildCompassOption draws a full turn on the registered gauge series: north at the top, the\n// angle running clockwise, so 90 is east. The needle takes the colour of the band the (wrapped)\n// heading is in and the chart accent in a `normal` band or none. The degrees themselves are DOM\n// text beside it (compass.tsx). With no reading the needle rests at north.\nexport function buildCompassOption(\n value: number | null,\n theme: ChartTheme,\n options: CompassChartOptions,\n size?: ElementSize,\n): EChartOption {\n const heading = wrapHeading(value);\n const thresholds = parseThresholds(options.thresholds ?? []);\n const bands = thresholdBands(thresholds, 0, 360);\n const accent = levelColor(theme.severity, bandAt(thresholds, heading ?? null)?.level) ?? theme.series[0];\n const s = shortSide(size);\n const scale = options.scale ?? 1;\n const arcWidth = clamp(Math.round(s / 30), 3, 10);\n const labelFont = clamp(Math.round(s / 11), Math.round(10 * scale), Math.round(20 * scale));\n const [north, east, south, west] = options.cardinals;\n const points: Record<number, string> = { 0: north, 90: east, 180: south, 270: west };\n return {\n animation: false,\n series: [\n {\n type: 'gauge',\n min: 0,\n max: 360,\n startAngle: 90,\n endAngle: -270,\n splitNumber: 4,\n radius: '92%',\n center: ['50%', '50%'],\n progress: { show: false },\n pointer: { itemStyle: { color: accent }, length: '62%', width: clamp(Math.round(s / 36), 3, 8) },\n anchor: { show: true, size: clamp(Math.round(s / 24), 5, 12), itemStyle: { color: accent } },\n axisLine: { lineStyle: { width: arcWidth, color: gaugeArcColors(bands, 0, 360, theme) } },\n axisTick: { show: s >= GAUGE_AXIS_LABELS_MIN_SIDE, splitNumber: 3, length: arcWidth, lineStyle: { color: theme.border, width: 1 } },\n splitLine: { length: arcWidth * 1.6, lineStyle: { color: theme.mutedForeground, width: 2 } },\n // Only the four points are labelled; 360 is the same tick as 0, so it stays blank.\n axisLabel: {\n show: true,\n color: theme.foreground,\n fontSize: labelFont,\n distance: arcWidth * 1.6 + 6,\n formatter: (v: number) => points[v] ?? '',\n },\n detail: { show: false },\n data: [{ value: heading ?? 0 }],\n },\n ],\n };\n}\n", "// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// The chart colour theme: concrete colours resolved from the host's CSS custom properties,\n// because an ECharts canvas cannot resolve `var(--x)`. Pure DOM + React, no echarts import,\n// but it lives on the `/echarts` subpath with the rest of the chart helpers so the SDK root\n// stays chart-free.\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { useWidgetThemeRoot } from '../context';\nimport { severityColorsAt, severityFallbackColors, type AlarmLevel } from '../severity';\n\n// Concrete colors for an ECharts canvas, resolved from the CSS variables in scope\n// at a given element (charts can't use CSS vars directly).\nexport interface ChartTheme {\n foreground: string;\n mutedForeground: string;\n border: string;\n series: string[];\n // The four coloured threshold levels, concrete (comma-form `hsl(h, s%, l%)`, which every\n // canvas colour parser accepts and which severityFill can add an alpha to). `normal` has\n // none: it renders in the widget's own neutral (see severity.ts).\n severity: Record<AlarmLevel, string>;\n}\n\n// Fallbacks used when a variable is absent (e.g. jsdom, or a host that hasn't set\n// the token) so a chart still renders in sensible default colors.\nconst FALLBACK: ChartTheme = {\n foreground: 'hsl(240 10% 3.9%)',\n mutedForeground: 'hsl(240 3.8% 46.1%)',\n border: 'hsl(240 5.9% 90%)',\n series: [\n 'hsl(220 70% 50%)',\n 'hsl(160 60% 45%)',\n 'hsl(30 80% 55%)',\n 'hsl(280 65% 60%)',\n 'hsl(340 75% 55%)',\n ],\n severity: severityFallbackColors(),\n};\n\nfunction readVar(style: CSSStyleDeclaration, name: string, fallback: string): string {\n const raw = style.getPropertyValue(`--${name}`).trim();\n return raw ? `hsl(${raw})` : fallback;\n}\n\n// resolveChartTheme reads the theme tokens in scope at `el` into concrete colors\n// for ECharts. Reading at the element (not the document root) means a widget\n// nested under a re-themed subtree picks up the local override.\nexport function resolveChartTheme(el: Element): ChartTheme {\n const style = getComputedStyle(el);\n return {\n foreground: readVar(style, 'foreground', FALLBACK.foreground),\n mutedForeground: readVar(style, 'muted-foreground', FALLBACK.mutedForeground),\n border: readVar(style, 'border', FALLBACK.border),\n series: FALLBACK.series.map((fallback, i) => readVar(style, `chart-${i + 1}`, fallback)),\n severity: severityColorsAt(el, style),\n };\n}\n\n// --- shared chart-theme store ------------------------------------------------\n//\n// Charts need concrete colors resolved from the CSS-variable theme. Rather than\n// have every chart widget mount its own MutationObserver on <html> and recompute\n// the same theme, one page-wide observer resolves it once per change and every\n// widget reads the shared, memoized value via useSyncExternalStore \u2014 so a busy\n// dashboard pays O(1), not O(number of charts), per theme toggle.\n\nlet sharedTheme: ChartTheme | null = null;\nconst themeListeners = new Set<() => void>();\nlet themeObserver: MutationObserver | null = null;\n\nfunction recomputeTheme(): void {\n sharedTheme = resolveChartTheme(document.documentElement);\n}\n\nfunction subscribeTheme(listener: () => void): () => void {\n if (!themeObserver) {\n recomputeTheme();\n themeObserver = new MutationObserver(() => {\n recomputeTheme();\n for (const l of themeListeners) l();\n });\n themeObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['class', 'style'],\n });\n }\n themeListeners.add(listener);\n return () => {\n themeListeners.delete(listener);\n if (themeListeners.size === 0 && themeObserver) {\n themeObserver.disconnect();\n themeObserver = null;\n sharedTheme = null;\n }\n };\n}\n\nfunction getThemeSnapshot(): ChartTheme {\n if (!sharedTheme) recomputeTheme();\n return sharedTheme as ChartTheme;\n}\n\n// useChartTheme returns the current chart colors and re-renders the caller when\n// the document theme changes (a light/dark class or inline-style swap on <html>).\nexport function useChartTheme(): ChartTheme {\n const shared = useSyncExternalStore(subscribeTheme, getThemeSnapshot, getThemeSnapshot);\n // A host that scopes its tokens to a container says so (WidgetThemeRoot); its tokens are\n // fixed for the container's life, so they are read once there rather than observed.\n const root = useWidgetThemeRoot();\n const scoped = useMemo(() => (root ? resolveChartTheme(root) : null), [root]);\n return scoped ?? shared;\n}\n\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,WAAW,QAAQ,gBAAgB;AAsJxC;AAhJJ,IAAI;AACJ,IAAI;AAGJ,SAAS,aAA8B;AACrC,oCAAkB,OAAO,oCAAiB,EAAE;AAAA,IAC1C,CAAC,MAAO,SAAS;AAAA,IACjB,CAAC,QAAiB;AAChB,sBAAgB;AAChB,YAAM;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,kBAAiC;AAC/C,SAAO,WAAW,EAAE,KAAK,MAAM,MAAS;AAC1C;AAKA,IAAI,eAAe;AACnB,IAAI;AAEG,SAAS,uBAAsC;AACpD,sCAAmB,WAAW,EAC3B,KAAK,CAAC,MAAM,EAAE,yBAAyB,CAAC,EACxC;AAAA,IACC,MAAM;AACJ,qBAAe;AAAA,IACjB;AAAA,IACA,CAAC,QAAiB;AAChB,uBAAiB;AACjB,YAAM;AAAA,IACR;AAAA,EACF;AACF,SAAO;AACT;AAGO,SAAS,kBAAkB,QAA+B;AAC/D,QAAM,SAAU,OAAgC;AAChD,QAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC;AACnE,SAAO,KAAK,KAAK,CAAC,MAAM;AACtB,UAAM,IAAI;AACV,WAAO,OAAO,MAAM,YAAY,MAAM,SAAS,EAAE,YAAY,QAAQ,EAAE,YAAY;AAAA,EACrF,CAAC;AACH;AAcO,SAAS,OAAO,EAAE,QAAQ,WAAW,MAAM,GAAgB;AAChE,QAAM,eAAe,OAAuB,IAAI;AAChD,QAAM,WAAW,OAA+B,IAAI;AACp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AC9B,gBAAc,kBAAkB,SAAS,eAAe;AAC1D;AAEA,SAAS,eAAe,UAAkC;AACxD,MAAI,CAAC,eAAe;AAClB,mBAAe;AACf,oBAAgB,IAAI,iBAAiB,MAAM;AACzC,qBAAe;AACf,iBAAW,KAAK,eAAgB,GAAE;AAAA,IACpC,CAAC;AACD,kBAAc,QAAQ,SAAS,iBAAiB;AAAA,MAC9C,YAAY;AAAA,MACZ,iBAAiB,CAAC,SAAS,OAAO;AAAA,IACpC,CAAC;AAAA,EACH;AACA,iBAAe,IAAI,QAAQ;AAC3B,SAAO,MAAM;AACX,mBAAe,OAAO,QAAQ;AAC9B,QAAI,eAAe,SAAS,KAAK,eAAe;AAC9C,oBAAc,WAAW;AACzB,sBAAgB;AAChB,oBAAc;AAAA,IAChB;AAAA,EACF;AACF;AAEA,SAAS,mBAA+B;AACtC,MAAI,CAAC,YAAa,gBAAe;AACjC,SAAO;AACT;AAIO,SAAS,gBAA4B;AAC1C,QAAM,SAAS,qBAAqB,gBAAgB,kBAAkB,gBAAgB;AAGtF,QAAM,OAAO,mBAAmB;AAChC,QAAM,SAAS,QAAQ,MAAO,OAAO,kBAAkB,IAAI,IAAI,MAAO,CAAC,IAAI,CAAC;AAC5E,SAAO,UAAU;AACnB;",
|
|
4
|
+
"sourcesContent": ["// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// A thin React wrapper over Apache ECharts (ADR-039 chart engine).\n//\n// 🔴 ECHARTS IS NOT IMPORTED HERE. The engine (ECharts + zrender, ~170 KB gzip, the largest single\n// dependency of a board) lives in echart-engine.ts and is loaded on demand, ONCE, as one chunk:\n// the first <EChart> to mount fetches it, and a host that wants the first frame complete fetches\n// it first with loadChartEngine (preloadWidgets does, for a board that holds a chart). Only TYPES\n// come from echarts here, and they are erased.\n//\n// The public surface is unchanged: <EChart option> is still a synchronous component. Once the\n// engine is here, a mount initialises the chart exactly as it always did; before it is, the\n// component renders its (empty) container and draws as soon as the engine arrives. A failed load\n// is THROWN, so the widget's error boundary shows it rather than an empty box that looks like a\n// chart with nothing to say, and it is NOT remembered: the next mount (the boundary's Reset)\n// fetches again, and nothing retries on its own.\n//\n// The wrapper owns the imperative lifecycle: init on mount, setOption on change, resize with the\n// container, dispose on unmount.\n\nimport type * as echarts from 'echarts/core';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { useRegisterWidgetImage } from '../context';\n\ntype Engine = typeof import('./echart-engine');\n\nlet engine: Engine | undefined;\nlet engineLoading: Promise<Engine> | undefined;\n\n// Memoized while in flight or loaded; a rejection is forgotten, so the next caller fetches again.\nfunction loadEngine(): Promise<Engine> {\n engineLoading ??= import('./echart-engine').then(\n (m) => (engine = m),\n (err: unknown) => {\n engineLoading = undefined;\n throw err;\n },\n );\n return engineLoading;\n}\n\n/**\n * Fetches the chart engine that <EChart> draws with, so the charts a host renders after awaiting\n * it draw on their first frame. Optional: an <EChart> that mounts first loads the engine itself.\n * Rejects if the engine cannot be fetched; a later call (or mount) fetches it again.\n */\nexport function loadChartEngine(): Promise<void> {\n return loadEngine().then(() => undefined);\n}\n\n// markLine / markArea are registered on first use (see echart-markers.ts for why). Until they\n// are, a chart that asks for them draws without them, and EChart re-applies its option once\n// they arrive -- a beat later on the first threshold chart of a page, never silently absent.\nlet markersReady = false;\nlet markersLoading: Promise<void> | undefined;\n\nexport function loadThresholdMarkers(): Promise<void> {\n markersLoading ??= loadEngine()\n .then((e) => e.registerThresholdMarkers())\n .then(\n () => {\n markersReady = true;\n },\n (err: unknown) => {\n markersLoading = undefined; // a failed chunk load is retried by the next chart that needs it\n throw err;\n },\n );\n return markersLoading;\n}\n\n// True when any series of the option carries a markLine or markArea.\nexport function optionUsesMarkers(option: EChartOption): boolean {\n const series = (option as { series?: unknown }).series;\n const list = Array.isArray(series) ? series : series ? [series] : [];\n return list.some((s) => {\n const m = s as { markLine?: unknown; markArea?: unknown } | null;\n return typeof m === 'object' && m !== null && (m.markLine != null || m.markArea != null);\n });\n}\n\n// A resolved ECharts option object (the shape echarts.setOption accepts). Widgets\n// build these with the pure builders in chart-options.ts.\nexport type EChartOption = echarts.EChartsCoreOption;\n\nexport interface EChartProps {\n option: EChartOption;\n className?: string;\n style?: React.CSSProperties;\n}\n\n// EChart fills its parent; the dashboard canvas sizes the parent, and a\n// ResizeObserver keeps the chart matched to it.\nexport function EChart({ option, className, style }: EChartProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const chartRef = useRef<echarts.ECharts | null>(null);\n const [loaded, setLoaded] = useState(engine);\n const [failed, setFailed] = useState<{ error: unknown }>();\n const [markersLoaded, setMarkersLoaded] = useState(markersReady);\n const needsMarkers = optionUsesMarkers(option) && !markersLoaded;\n\n // Offer the chart's image to the frame it is drawn in (its \"Download image\") once the engine is\n // here and the chart exists: a PNG at twice the on-screen resolution, on the background the frame\n // hands over, since the canvas itself is transparent.\n useRegisterWidgetImage(\n loaded\n ? ({ backgroundColor }) => {\n // A canvas-drawn tooltip (strict-CSP mode) is part of the picture: hide it first.\n chartRef.current?.dispatchAction({ type: 'hideTip' });\n return chartRef.current?.getDataURL({ type: 'png', pixelRatio: 2, backgroundColor });\n }\n : undefined,\n );\n\n // The engine, when this is the first chart to mount and nobody preloaded it.\n useEffect(() => {\n if (loaded) return;\n let live = true;\n loadEngine().then(\n (e) => live && setLoaded(e),\n (error: unknown) => live && setFailed({ error }),\n );\n return () => {\n live = false;\n };\n }, [loaded]);\n\n useEffect(() => {\n if (!needsMarkers) return;\n let live = true;\n loadThresholdMarkers().then(\n () => live && setMarkersLoaded(true),\n // Loud, not silent: the chart still draws, without its threshold lines.\n (err: unknown) => console.error('EChart: the threshold markers failed to load', err),\n );\n return () => {\n live = false;\n };\n }, [needsMarkers]);\n\n // Init + teardown once for the element's lifetime (from the moment the engine is here).\n useEffect(() => {\n const el = containerRef.current;\n if (!el || !loaded) return;\n\n const chart = loaded.init(el);\n chartRef.current = chart;\n\n const observer = new ResizeObserver(() => chart.resize());\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n chart.dispose();\n chartRef.current = null;\n };\n }, [loaded]);\n\n // Re-apply the option whenever it changes. notMerge:true so a shrinking series\n // (rolling window) doesn't leave stale points behind.\n useEffect(() => {\n chartRef.current?.setOption(option, { notMerge: true });\n }, [option, markersLoaded, loaded]);\n\n // To the widget's error boundary: a chart that cannot draw says so.\n if (failed) throw failed.error;\n\n // `data-echart` marks the chart's box, so a host (and the readability gate) can tell a chart\n // that has drawn (ECharts stamps `_echarts_instance_` on it) from one still waiting.\n return (\n <div ref={containerRef} data-echart=\"\" className={className} style={{ width: '100%', height: '100%', ...style }} />\n );\n}\n", "// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// Pure ECharts option builders. Kept free of React/DOM so the data→chart mapping\n// is unit-testable without a canvas: a widget resolves a ChartTheme + samples and\n// hands the result straight to <EChart>.\n\nimport type { MeasurementSample } from '@devicechain/dashboards';\n\nimport { FIT_MIN_FONT_PX, fitValueFont } from '../fit-text';\nimport { formatValue } from '../format';\nimport type { ElementSize } from '../hooks';\nimport { strictCspEnabled } from '../strict-csp';\nimport { isAlarmLevel, levelColor, type AlarmLevel } from '../severity';\nimport { bandAt, parseThresholds, thresholdBands, type Threshold } from '../thresholds';\n\nimport type { ChartTheme } from './chart-theme';\nimport type { EChartOption } from './echart';\n\n// distinctNames returns the measurement names present in `samples`, in first-seen\n// order — used when a chart's datasource doesn't pin an explicit series list.\nfunction distinctNames(samples: MeasurementSample[]): string[] {\n const seen: string[] = [];\n for (const s of samples) {\n if (!seen.includes(s.name)) seen.push(s.name);\n }\n return seen;\n}\n\n// A severity colour with an alpha, for a band drawn UNDER the data (markArea). The theme's\n// severity colours are comma-form hsl(), so the alpha form is a string edit.\nexport function severityFill(theme: ChartTheme, level: AlarmLevel, alpha: number): string {\n return theme.severity[level].replace(/^hsl\\(/, 'hsla(').replace(/\\)$/, `, ${alpha})`);\n}\n\n// Opacity of a threshold band behind a line: enough to read as a zone, faint enough that the\n// line and its grid stay the subject. A `normal` band has no fill at all.\nconst BAND_ALPHA = 0.14;\n\nconst clamp = (v: number, lo: number, hi: number): number => Math.max(lo, Math.min(hi, v));\n\n// gauge/line fonts and tick counts scale with the smaller container dimension so a\n// widget stays legible when resized. A zero/absent size (before first measure, or\n// in a non-DOM test) falls back to a nominal medium size.\nfunction shortSide(size?: ElementSize): number {\n const s = Math.min(size?.width ?? 0, size?.height ?? 0);\n return s > 0 ? s : 200;\n}\n\nexport interface LineChartOptions {\n // Measurement names to plot, one series each. Empty → every name seen in the\n // window (first-seen order).\n measurements?: string[];\n // Unit suffix: named on the y-axis and appended to every tooltip value.\n unit?: string;\n // Decimal places for axis labels and tooltip values; unset uses the default rounding.\n precision?: number;\n // Severity thresholds, drawn as a labelled line each plus a faint band between them.\n // Any order: the builder sorts them.\n thresholds?: readonly Threshold[];\n // The board's density scale (useWidgetScale().scale): multiplies the axis-font clamp. Default 1.\n scale?: number;\n // Instants (ISO-8601, oldest first) after which nothing is known until the next sample: the live\n // feed was interrupted (MeasurementStreamState.gaps). Every line breaks at each one instead of\n // joining the samples on either side.\n gaps?: readonly string[];\n // The value axis's ends, as the author chose them. Each is a bound the axis REACHES, never a\n // clip: a reading or a threshold beyond it widens the axis to take it in, so a fixed end can\n // frame the data but never hide any. Unset (or not finite), that end is ECharts' own, as before.\n // Both set and not ascending, neither applies (the descriptor refuses such a pair).\n min?: number;\n max?: number;\n}\n\n// breakAtGaps puts an empty point -- which ECharts draws as a break in the line -- at each gap\n// that falls between two of a series' points. Points are in sample order (chronological).\nfunction breakAtGaps(points: Array<[string, number]>, gaps: readonly number[]): Array<[string, number | null]> {\n let g = 0;\n return points.flatMap((point, i): Array<[string, number | null]> => {\n // The last gap before this point; past the end of `gaps` the comparison is false.\n let gap = Number.NaN;\n while (gaps[g] < Date.parse(point[0])) gap = gaps[g++];\n return i > 0 && !Number.isNaN(gap) ? [[new Date(gap).toISOString(), null], point] : [point];\n });\n}\n\n// The markLine / markArea for a chart's thresholds, attached to the first series (the markers\n// belong to a series in ECharts, and every series shares the one y-axis).\nfunction thresholdMarks(theme: ChartTheme, thresholds: readonly Threshold[], unit: string | undefined, precision: number | undefined, fontSize: number) {\n const suffix = unit ? ` ${unit}` : '';\n // A `normal` threshold is still drawn: it is where the value RETURNS to normal, which an\n // operator wants to see. It is drawn in the muted text colour, the same ink as the axis\n // labels, which reads in light and dark and says \"boundary\" without saying \"alarm\".\n const ink = (t: Threshold) => levelColor(theme.severity, t.level) ?? theme.mutedForeground;\n const markLine = {\n silent: true,\n symbol: 'none',\n animation: false,\n data: thresholds.map((t) => ({\n yAxis: t.value,\n name: t.label ?? String(t.value),\n lineStyle: { color: ink(t), type: 'dashed' as const, width: 1.5 },\n label: {\n show: true,\n position: 'insideEndTop' as const,\n color: ink(t),\n fontSize,\n formatter: () => t.label ?? `${formatValue(t.value, precision)}${suffix}`,\n },\n })),\n };\n const markArea = {\n silent: true,\n animation: false,\n data: thresholdBands(thresholds, -Infinity, Infinity)\n .filter((b) => isAlarmLevel(b.level))\n .map((b) => [\n { yAxis: b.from, itemStyle: { color: severityFill(theme, b.level as AlarmLevel, BAND_ALPHA) } },\n { yAxis: b.to },\n ]),\n };\n return { markLine, markArea };\n}\n\n// One end of a line chart's value axis: `low` is the min end, otherwise the max end. `data` is\n// ECharts' own extent at that end (not finite with no data). With no author end, a threshold\n// beyond the data fixes the end at the threshold and otherwise ECharts keeps its auto range\n// (null). With one, the end is the furthest of the author's end, the threshold and the data, so\n// nothing drawn falls off the axis.\nfunction axisEnd(low: boolean, data: number, fixed: number | undefined, threshold: number | undefined): number | null {\n const beyond = (a: number, b: number): boolean => (low ? a < b : a > b);\n if (fixed === undefined) return threshold !== undefined && beyond(threshold, data) ? threshold : null;\n let end = fixed;\n if (Number.isFinite(data) && beyond(data, end)) end = data;\n if (threshold !== undefined && beyond(threshold, end)) end = threshold;\n return end;\n}\n\n// buildLineOption maps a rolling window of samples to a multi-series time chart,\n// one line per measurement name, coloured from the theme's chart palette.\nexport function buildLineOption(\n samples: MeasurementSample[],\n theme: ChartTheme,\n options: LineChartOptions = {},\n size?: ElementSize,\n): EChartOption {\n const names = options.measurements?.length ? options.measurements : distinctNames(samples);\n const scale = options.scale ?? 1;\n const axisFont = clamp(Math.round(shortSide(size) / 22), Math.round(8 * scale), Math.round(12 * scale));\n\n // Re-parsed (validated + sorted): the builder is public, and a caller may hand it a list\n // that never went through parseThresholds. Every rule below assumes ascending order.\n const thresholds = parseThresholds(options.thresholds ?? []);\n const lowest = thresholds.length > 0 ? thresholds[0].value : 0;\n const highest = thresholds.length > 0 ? thresholds[thresholds.length - 1].value : 0;\n const marks = thresholds.length > 0 ? thresholdMarks(theme, thresholds, options.unit, options.precision, axisFont) : undefined;\n const suffix = options.unit ? ` ${options.unit}` : '';\n const precision = options.precision;\n const gaps = (options.gaps ?? []).map(Date.parse).filter((g) => !Number.isNaN(g));\n const finite = (v: number | undefined): number | undefined => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);\n let fixedMin = finite(options.min);\n let fixedMax = finite(options.max);\n if (fixedMin !== undefined && fixedMax !== undefined && fixedMin >= fixedMax) fixedMin = fixedMax = undefined;\n\n const series = names.map((name, i) => {\n const color = theme.series[i % theme.series.length];\n return {\n ...(i === 0 ? marks : undefined),\n name,\n type: 'line' as const,\n showSymbol: false,\n lineStyle: { color },\n itemStyle: { color },\n data: breakAtGaps(\n samples\n .filter((s) => s.name === name && s.value != null && s.occurredTime != null)\n .map((s): [string, number] => [s.occurredTime as string, s.value as number]),\n gaps,\n ),\n };\n });\n\n return {\n animation: false,\n textStyle: { color: theme.foreground, fontSize: axisFont },\n grid: { left: 8, right: 12, top: names.length > 1 || options.unit ? 28 : 12, bottom: 8, containLabel: true },\n tooltip: {\n trigger: 'axis',\n // Strict-CSP host mode (configureStrictCsp): drawn on the canvas, because the HTML tooltip's\n // rows carry `style=\"\"` attributes a policy without `style-src 'unsafe-inline'` refuses.\n ...(strictCspEnabled() ? { renderMode: 'richText' as const } : {}),\n valueFormatter: (v: unknown) => (typeof v === 'number' ? `${formatValue(v, precision)}${suffix}` : String(v ?? '—')),\n },\n legend:\n names.length > 1 ? { textStyle: { color: theme.mutedForeground, fontSize: axisFont }, top: 0 } : undefined,\n xAxis: {\n type: 'time',\n axisLine: { lineStyle: { color: theme.border } },\n axisLabel: { color: theme.mutedForeground, fontSize: axisFont, hideOverlap: true },\n },\n yAxis: {\n type: 'value',\n // The unit rides the axis once, at its head, rather than on every tick.\n name: options.unit,\n nameTextStyle: { color: theme.mutedForeground, fontSize: axisFont, align: 'left' as const },\n splitLine: { lineStyle: { color: theme.border } },\n axisLabel: {\n color: theme.mutedForeground,\n fontSize: axisFont,\n // Rounded only when the author asked; otherwise ECharts' own tick rounding applies.\n ...(precision != null ? { formatter: (v: number) => formatValue(v, precision) } : {}),\n },\n // A threshold outside the data's range must still be on the chart: extend the range to\n // take it in. Only then -- a returned number FIXES that end of the axis (no nice\n // rounding, no zero baseline), so a threshold inside the data returns null and leaves\n // ECharts' own auto range exactly as it is without thresholds. An author's end (min/max)\n // is the same kind of bound: the axis reaches it, and goes past it only for a reading or a\n // threshold beyond it.\n ...(thresholds.length > 0 || fixedMin !== undefined || fixedMax !== undefined\n ? {\n min: (e: { min: number }) => axisEnd(true, e.min, fixedMin, thresholds.length > 0 ? lowest : undefined),\n max: (e: { max: number }) => axisEnd(false, e.max, fixedMax, thresholds.length > 0 ? highest : undefined),\n }\n : {}),\n },\n series,\n };\n}\n\nexport interface GaugeChartOptions {\n min?: number;\n max?: number;\n unit?: string;\n // Decimal places for the readout; unset uses the default rounding.\n precision?: number;\n // Severity thresholds, drawn as coloured bands on the arc (any order).\n thresholds?: readonly Threshold[];\n // The board's density scale: multiplies the label-font clamp and the readout's floor. Default 1.\n scale?: number;\n // Where the number is drawn. 'canvas' (the default) paints it inside the dial, as the builder\n // always has, so a widget that renders only the chart keeps its readout. 'none' leaves the dial\n // bare for a caller that draws the number itself as DOM text in gaugeReadoutBox, which the\n // readability gate can measure (the built-in gauge does).\n readout?: 'canvas' | 'none';\n // Where the needle is with no value. 'min' (the default) rests it at the scale's minimum, as the\n // builder always has. 'none' draws no needle, so an empty dial cannot be read as a reading of\n // its minimum (the built-in gauge, whose readout already says there is no value, asks for it).\n emptyNeedle?: 'min' | 'none';\n}\n\n// The dial's geometry as fractions of its box: where its centre sits and how much of the short\n// side's half it fills. The DOM readout is placed from the same numbers (gaugeReadoutBox).\nconst GAUGE_CENTER_Y = 0.58;\nconst GAUGE_RADIUS = 0.95;\n// How far below the hub the readout sits, as a fraction of the radius.\nconst GAUGE_READOUT_OFFSET = 0.3;\n\n// The box (px, relative to the chart) the gauge's DOM readout is centred in and fitted to: under\n// the hub and inside the dial, where the canvas detail used to be drawn. A zero size (before the\n// first measure) takes the nominal one the builder assumes.\nexport function gaugeReadoutBox(size?: ElementSize): { centerX: number; centerY: number; width: number; height: number } {\n const s = shortSide(size);\n const w = (size?.width ?? 0) > 0 ? size!.width : s;\n const h = (size?.height ?? 0) > 0 ? size!.height : s;\n return {\n centerX: w / 2,\n centerY: GAUGE_CENTER_Y * h + GAUGE_READOUT_OFFSET * GAUGE_RADIUS * (s / 2),\n width: s * 0.7,\n height: s * 0.25,\n };\n}\n\n// Below this short side (px) the gauge drops its axis labels: at that size they would be\n// drawn at the 8 px floor, which is noise rather than a scale.\nexport const GAUGE_AXIS_LABELS_MIN_SIDE = 120;\n\n// The arc's colour stops: ECharts wants [[endFraction, colour], ...] ending at 1. A neutral\n// stretch (below the lowest threshold, or a `normal` band) takes the track colour. With no bands: one track.\nfunction gaugeArcColors(bands: ReturnType<typeof thresholdBands>, min: number, max: number, theme: ChartTheme): [number, string][] {\n if (bands.length === 0) return [[1, theme.border]];\n return bands.map((b, i): [number, string] => [\n i === bands.length - 1 ? 1 : (b.to - min) / (max - min),\n levelColor(theme.severity, b.level) ?? theme.border,\n ]);\n}\n\n// buildGaugeOption maps a single latest value to a gauge. A null value (nothing\n// received yet) shows an em dash and rests the needle at the minimum. Ticks, fonts,\n// and the arc width scale with the widget size so it stays legible when resized\n// (ECharts' default gauge crams ~10 labels at fixed fonts on a small canvas).\nexport function buildGaugeOption(\n value: number | null,\n theme: ChartTheme,\n options: GaugeChartOptions = {},\n size?: ElementSize,\n): EChartOption {\n const min = options.min ?? 0;\n const max = options.max ?? 100;\n const thresholds = parseThresholds(options.thresholds ?? []); // validated + sorted, as above\n const bands = thresholdBands(thresholds, min, max);\n // Banded only when a COLOURED band actually lands on the arc: thresholds that all sit above\n // `max`, or only `normal` bands, leave a plain neutral track, which keeps the progress arc\n // like any other gauge.\n const banded = bands.some((b) => isAlarmLevel(b.level));\n // The needle takes the colour of the band the value sits in; with no bands, below the\n // lowest, or in a `normal` band it keeps the chart accent.\n const accent = levelColor(theme.severity, bandAt(thresholds, value)?.level) ?? theme.series[0];\n\n const s = shortSide(size);\n const arcWidth = clamp(Math.round(s / 26), 4, 12);\n const scale = options.scale ?? 1;\n const labelFont = clamp(Math.round(s / 20), Math.round(8 * scale), Math.round(13 * scale));\n const showAxisLabels = s >= GAUGE_AXIS_LABELS_MIN_SIDE;\n const unitSuffix = options.unit ? ` ${options.unit}` : '';\n // The readout is fitted to the dial's inner box and its own length, like every big number.\n const readout = value == null ? '—' : `${formatValue(value, options.precision)}${unitSuffix}`;\n const valueFont = fitValueFont({ width: s * 0.7, height: s * 0.25 }, readout.length, {\n floor: Math.round(FIT_MIN_FONT_PX * scale),\n });\n return {\n animation: false,\n series: [\n {\n type: 'gauge',\n min,\n max,\n splitNumber: s < 160 ? 4 : 5, // fewer ticks than the default 10 → no cram\n radius: `${GAUGE_RADIUS * 100}%`,\n center: ['50%', `${GAUGE_CENTER_Y * 100}%`],\n // The progress arc would paint over the bands, so with bands the needle alone marks the value.\n progress: { show: !banded, width: arcWidth, itemStyle: { color: accent } },\n pointer: {\n show: value != null || options.emptyNeedle !== 'none',\n itemStyle: { color: accent },\n length: '55%',\n width: clamp(Math.round(s / 50), 2, 6),\n },\n anchor: { show: false },\n axisLine: { lineStyle: { width: arcWidth, color: gaugeArcColors(bands, min, max, theme) } },\n axisTick: { show: false },\n splitLine: { length: arcWidth, lineStyle: { color: theme.border, width: 1 } },\n axisLabel: { show: showAxisLabels, color: theme.mutedForeground, fontSize: labelFont, distance: arcWidth + 2 },\n detail:\n options.readout === 'none'\n ? { show: false }\n : {\n valueAnimation: false,\n color: theme.foreground,\n fontSize: valueFont,\n offsetCenter: [0, `${GAUGE_READOUT_OFFSET * 100}%`],\n formatter: (v: number) => (value == null ? '—' : `${formatValue(v, options.precision)}${unitSuffix}`),\n },\n data: [{ value: value ?? min }],\n },\n ],\n };\n}\n\n// A heading in degrees folded onto [0, 360): 370 is 10 and -90 is 270, because a compass has no\n// \"beyond a full turn\" and a bearing sensor may well report either. 360 is 0, never 360, and a\n// value that is not a finite number has no heading at all (undefined), not a plausible one.\nexport function wrapHeading(value: number | null | undefined): number | undefined {\n if (value == null || !Number.isFinite(value)) return undefined;\n return ((value % 360) + 360) % 360;\n}\n\nexport interface CompassChartOptions {\n // The four point labels in N, E, S, W order (a locale writes West as \"O\", so the caller owns them).\n cardinals: readonly [string, string, string, string];\n thresholds?: readonly Threshold[];\n // The board's density scale; multiplies the label-font clamp. Default 1.\n scale?: number;\n}\n\n// buildCompassOption draws a full turn on the registered gauge series: north at the top, the\n// angle running clockwise, so 90 is east. The needle takes the colour of the band the (wrapped)\n// heading is in and the chart accent in a `normal` band or none. The degrees themselves are DOM\n// text beside it (compass.tsx). With no reading the needle rests at north.\nexport function buildCompassOption(\n value: number | null,\n theme: ChartTheme,\n options: CompassChartOptions,\n size?: ElementSize,\n): EChartOption {\n const heading = wrapHeading(value);\n const thresholds = parseThresholds(options.thresholds ?? []);\n const bands = thresholdBands(thresholds, 0, 360);\n const accent = levelColor(theme.severity, bandAt(thresholds, heading ?? null)?.level) ?? theme.series[0];\n const s = shortSide(size);\n const scale = options.scale ?? 1;\n const arcWidth = clamp(Math.round(s / 30), 3, 10);\n const labelFont = clamp(Math.round(s / 11), Math.round(10 * scale), Math.round(20 * scale));\n const [north, east, south, west] = options.cardinals;\n const points: Record<number, string> = { 0: north, 90: east, 180: south, 270: west };\n return {\n animation: false,\n series: [\n {\n type: 'gauge',\n min: 0,\n max: 360,\n startAngle: 90,\n endAngle: -270,\n splitNumber: 4,\n radius: '92%',\n center: ['50%', '50%'],\n progress: { show: false },\n pointer: { itemStyle: { color: accent }, length: '62%', width: clamp(Math.round(s / 36), 3, 8) },\n anchor: { show: true, size: clamp(Math.round(s / 24), 5, 12), itemStyle: { color: accent } },\n axisLine: { lineStyle: { width: arcWidth, color: gaugeArcColors(bands, 0, 360, theme) } },\n axisTick: { show: s >= GAUGE_AXIS_LABELS_MIN_SIDE, splitNumber: 3, length: arcWidth, lineStyle: { color: theme.border, width: 1 } },\n splitLine: { length: arcWidth * 1.6, lineStyle: { color: theme.mutedForeground, width: 2 } },\n // Only the four points are labelled; 360 is the same tick as 0, so it stays blank.\n axisLabel: {\n show: true,\n color: theme.foreground,\n fontSize: labelFont,\n distance: arcWidth * 1.6 + 6,\n formatter: (v: number) => points[v] ?? '',\n },\n detail: { show: false },\n data: [{ value: heading ?? 0 }],\n },\n ],\n };\n}\n", "// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// The chart colour theme: concrete colours resolved from the host's CSS custom properties,\n// because an ECharts canvas cannot resolve `var(--x)`. Pure DOM + React, no echarts import,\n// but it lives on the `/echarts` subpath with the rest of the chart helpers so the SDK root\n// stays chart-free.\n\nimport { useSyncExternalStore } from 'react';\n\nimport { useWidgetThemeRoot } from '../context';\nimport { severityColorsAt, severityFallbackColors, type AlarmLevel } from '../severity';\n\n// Concrete colors for an ECharts canvas, resolved from the CSS variables in scope\n// at a given element (charts can't use CSS vars directly).\nexport interface ChartTheme {\n foreground: string;\n mutedForeground: string;\n border: string;\n series: string[];\n // The four coloured threshold levels, concrete (comma-form `hsl(h, s%, l%)`, which every\n // canvas colour parser accepts and which severityFill can add an alpha to). `normal` has\n // none: it renders in the widget's own neutral (see severity.ts).\n severity: Record<AlarmLevel, string>;\n}\n\n// Fallbacks used when a variable is absent (e.g. jsdom, or a host that hasn't set\n// the token) so a chart still renders in sensible default colors.\nconst FALLBACK: ChartTheme = {\n foreground: 'hsl(240 10% 3.9%)',\n mutedForeground: 'hsl(240 3.8% 46.1%)',\n border: 'hsl(240 5.9% 90%)',\n series: [\n 'hsl(220 70% 50%)',\n 'hsl(160 60% 45%)',\n 'hsl(30 80% 55%)',\n 'hsl(280 65% 60%)',\n 'hsl(340 75% 55%)',\n ],\n severity: severityFallbackColors(),\n};\n\nfunction readVar(style: CSSStyleDeclaration, name: string, fallback: string): string {\n const raw = style.getPropertyValue(`--${name}`).trim();\n return raw ? `hsl(${raw})` : fallback;\n}\n\n// resolveChartTheme reads the theme tokens in scope at `el` into concrete colors\n// for ECharts. Reading at the element (not the document root) means a widget\n// nested under a re-themed subtree picks up the local override.\nexport function resolveChartTheme(el: Element): ChartTheme {\n const style = getComputedStyle(el);\n return {\n foreground: readVar(style, 'foreground', FALLBACK.foreground),\n mutedForeground: readVar(style, 'muted-foreground', FALLBACK.mutedForeground),\n border: readVar(style, 'border', FALLBACK.border),\n series: FALLBACK.series.map((fallback, i) => readVar(style, `chart-${i + 1}`, fallback)),\n severity: severityColorsAt(el, style),\n };\n}\n\n// One store per theme root: charts in the same embed share a snapshot and observer.\n// Weak keys allow an unmounted embed's container and store to be collected.\nconst themeStores = new WeakMap<Element, ReturnType<typeof createThemeStore>>();\n\nfunction createThemeStore(root: Element) {\n let theme: ChartTheme | null = null;\n const listeners = new Set<() => void>();\n let observer: MutationObserver | null = null;\n const recompute = () => { theme = resolveChartTheme(root); };\n\n return {\n getSnapshot: (): ChartTheme => {\n if (!theme) recompute();\n return theme as ChartTheme;\n },\n subscribe: (listener: () => void): (() => void) => {\n if (!observer) {\n recompute();\n observer = new MutationObserver(() => {\n recompute();\n for (const notify of listeners) notify();\n });\n // A host can override tokens locally or inherit a palette from an ancestor.\n // Observe only those elements, never unrelated descendants of the page.\n for (let element: Element | null = root; element; element = element.parentElement) {\n observer.observe(element, { attributes: true, attributeFilter: ['class', 'style'] });\n }\n }\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0 && observer) {\n observer.disconnect();\n observer = null;\n theme = null;\n }\n };\n },\n };\n}\n\n// Resolve live colors at the host's container, or at <html> for the default theme.\nexport function useChartTheme(): ChartTheme {\n const root = useWidgetThemeRoot() ?? document.documentElement;\n let store = themeStores.get(root);\n if (!store) {\n store = createThemeStore(root);\n themeStores.set(root, store);\n }\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,WAAW,QAAQ,gBAAgB;AAsJxC;AAhJJ,IAAI;AACJ,IAAI;AAGJ,SAAS,aAA8B;AACrC,oCAAkB,OAAO,oCAAiB,EAAE;AAAA,IAC1C,CAAC,MAAO,SAAS;AAAA,IACjB,CAAC,QAAiB;AAChB,sBAAgB;AAChB,YAAM;AAAA,IACR;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,kBAAiC;AAC/C,SAAO,WAAW,EAAE,KAAK,MAAM,MAAS;AAC1C;AAKA,IAAI,eAAe;AACnB,IAAI;AAEG,SAAS,uBAAsC;AACpD,sCAAmB,WAAW,EAC3B,KAAK,CAAC,MAAM,EAAE,yBAAyB,CAAC,EACxC;AAAA,IACC,MAAM;AACJ,qBAAe;AAAA,IACjB;AAAA,IACA,CAAC,QAAiB;AAChB,uBAAiB;AACjB,YAAM;AAAA,IACR;AAAA,EACF;AACF,SAAO;AACT;AAGO,SAAS,kBAAkB,QAA+B;AAC/D,QAAM,SAAU,OAAgC;AAChD,QAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC;AACnE,SAAO,KAAK,KAAK,CAAC,MAAM;AACtB,UAAM,IAAI;AACV,WAAO,OAAO,MAAM,YAAY,MA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|
fontVar,
|
|
4
4
|
spaceVar,
|
|
5
5
|
viewerLocale
|
|
6
|
-
} from "./chunks/chunk-
|
|
6
|
+
} from "./chunks/chunk-KKUMZN7N.js";
|
|
7
7
|
import {
|
|
8
8
|
useWidgetBodySize
|
|
9
|
-
} from "./chunks/chunk-
|
|
10
|
-
import "./chunks/chunk-
|
|
9
|
+
} from "./chunks/chunk-MYW73WDC.js";
|
|
10
|
+
import "./chunks/chunk-ZCOHPFPW.js";
|
|
11
11
|
|
|
12
12
|
// src/empty-state.tsx
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -29,25 +29,39 @@ var WIDGET_EMPTY_STRINGS = {
|
|
|
29
29
|
unbound: { title: "Sin dispositivo elegido", detail: "Elija un dispositivo para que este widget muestre sus datos." },
|
|
30
30
|
notReported: {
|
|
31
31
|
title: "Este dispositivo no lo informa",
|
|
32
|
-
detail: (m) => `El perfil de este dispositivo no incluye ${m ? `"${m}"` : "esta
|
|
32
|
+
detail: (m) => `El perfil de este dispositivo no incluye ${m ? `"${m}"` : "esta medición"}, por lo que no la informará.`
|
|
33
33
|
},
|
|
34
34
|
noData: {
|
|
35
35
|
title: "Sin datos en este rango",
|
|
36
|
-
detail: (m) => `No se
|
|
36
|
+
detail: (m) => `No se informó nada${m ? ` de "${m}"` : ""} en el rango de tiempo elegido.`
|
|
37
37
|
},
|
|
38
38
|
forbidden: { title: "Sin acceso", detail: "No tiene acceso a estos datos." },
|
|
39
|
-
error: { title: "Datos no disponibles", detail: "El origen de datos no respondi
|
|
39
|
+
error: { title: "Datos no disponibles", detail: "El origen de datos no respondió." }
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
+
var ZH_EMPTY_STRINGS = {
|
|
43
|
+
unbound: { title: "尚未选择设备", detail: "请选择设备以在此组件中显示其数据。" },
|
|
44
|
+
notReported: {
|
|
45
|
+
title: "此设备不报告该测量项",
|
|
46
|
+
detail: (m) => `此设备的配置文件未包含${m ? `“${m}”` : "此测量项"},因此不会报告其数据。`
|
|
47
|
+
},
|
|
48
|
+
noData: {
|
|
49
|
+
title: "此范围内暂无数据",
|
|
50
|
+
detail: (m) => `所选时间范围内未收到${m ? `“${m}”的` : ""}数据。`
|
|
51
|
+
},
|
|
52
|
+
forbidden: { title: "无访问权限", detail: "您无权访问这些数据。" },
|
|
53
|
+
error: { title: "数据不可用", detail: "数据源未响应。" }
|
|
54
|
+
};
|
|
42
55
|
function widgetEmptyStrings(locale = viewerLocale()) {
|
|
43
|
-
|
|
56
|
+
const language = locale?.toLowerCase().split("-")[0];
|
|
57
|
+
return language === "es" ? WIDGET_EMPTY_STRINGS.es : language === "zh" ? ZH_EMPTY_STRINGS : WIDGET_EMPTY_STRINGS.en;
|
|
44
58
|
}
|
|
45
59
|
var GLYPH = {
|
|
46
|
-
unbound: "
|
|
47
|
-
"not-reported": "
|
|
48
|
-
"no-data": "
|
|
49
|
-
forbidden: "
|
|
50
|
-
error: "
|
|
60
|
+
unbound: "○",
|
|
61
|
+
"not-reported": "∅",
|
|
62
|
+
"no-data": "∅",
|
|
63
|
+
forbidden: "⊘",
|
|
64
|
+
error: "…"
|
|
51
65
|
};
|
|
52
66
|
var DETAIL_MIN = { width: 150, height: 84 };
|
|
53
67
|
var HINT_MIN = { width: 150, height: 100 };
|
|
@@ -90,11 +104,13 @@ function WidgetEmptyState({ kind, measurement, hint, detail, locale }) {
|
|
|
90
104
|
);
|
|
91
105
|
}
|
|
92
106
|
var LAST_VALUE_STRINGS = {
|
|
93
|
-
en: { lastValue: (value, age) => `Last value ${value}
|
|
94
|
-
es: { lastValue: (value, age) =>
|
|
107
|
+
en: { lastValue: (value, age) => `Last value ${value} · ${age}` },
|
|
108
|
+
es: { lastValue: (value, age) => `Último valor ${value} · ${age}` }
|
|
95
109
|
};
|
|
110
|
+
var ZH_LAST_VALUE_STRINGS = { lastValue: (value, age) => `上次读数 ${value} · ${age}` };
|
|
96
111
|
function lastValueHint(value, age, locale = viewerLocale()) {
|
|
97
|
-
|
|
112
|
+
const language = locale?.toLowerCase().split("-")[0];
|
|
113
|
+
return (language === "es" ? LAST_VALUE_STRINGS.es : language === "zh" ? ZH_LAST_VALUE_STRINGS : LAST_VALUE_STRINGS.en).lastValue(value, age);
|
|
98
114
|
}
|
|
99
115
|
export {
|
|
100
116
|
LAST_VALUE_STRINGS,
|
package/dist/empty-state.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/empty-state.tsx"],
|
|
4
|
-
"sourcesContent": ["// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// An EXPLAINED empty state: the body a widget shows when it has nothing to draw, saying which of the\n// few reasons it is. A bare dash or a blank card cannot tell \"nobody picked a device\" from \"this\n// device never reports that\" from \"the device is quiet right now\", and a board that does not say\n// looks broken. The kinds are:\n//\n// unbound no device (or slot binding) is chosen: the author's job\n// not-reported the device's active profile does not declare this measurement: it will never report it\n// no-data declared, but nothing arrived in the window; `hint` can say what the last value was\n// forbidden the platform refused the read for this viewer\n// error the source failed to answer\n//\n// Styling is deliberately NEUTRAL (ISA-101): the muted foreground, a quiet glyph, no severity hue and no\n// warning symbol. Alarm colour means an alarm on a board, so a state that is not one never borrows it.\n// It sizes by the frame's content column: a small widget keeps the title, a roomy one adds the\n// explanation and the hint.\n\nimport type { CSSProperties } from 'react';\n\nimport { useWidgetBodySize } from './context';\nimport { viewerLocale } from './freshness';\nimport { css } from './theme';\nimport { fontVar, spaceVar } from './tokens';\n\nexport type WidgetEmptyKind = 'unbound' | 'not-reported' | 'no-data' | 'forbidden' | 'error';\n\nexport interface WidgetEmptyStrings {\n unbound: { title: string; detail: string };\n notReported: { title: string; detail: (measurement: string | undefined) => string };\n noData: { title: string; detail: (measurement: string | undefined) => string };\n forbidden: { title: string; detail: string };\n error: { title: string; detail: string };\n}\n\nexport const WIDGET_EMPTY_STRINGS: Record<'en' | 'es', WidgetEmptyStrings> = {\n en: {\n unbound: { title: 'No device chosen', detail: 'Choose a device for this widget to show its data.' },\n notReported: {\n title: 'Not reported by this device',\n detail: (m) => `This device's profile does not include ${m ? `\"${m}\"` : 'this measurement'}, so it will not report it.`,\n },\n noData: {\n title: 'No data in this range',\n detail: (m) => `Nothing was reported${m ? ` for \"${m}\"` : ''} in the selected time range.`,\n },\n forbidden: { title: 'No access', detail: 'You do not have access to this data.' },\n error: { title: 'Data unavailable', detail: 'The data source did not answer.' },\n },\n es: {\n unbound: { title: 'Sin dispositivo elegido', detail: 'Elija un dispositivo para que este widget muestre sus datos.' },\n notReported: {\n title: 'Este dispositivo no lo informa',\n detail: (m) => `El perfil de este dispositivo no incluye ${m ? `\"${m}\"` : 'esta
|
|
5
|
-
"mappings": ";;;;;;;;;;;;
|
|
4
|
+
"sourcesContent": ["// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// An EXPLAINED empty state: the body a widget shows when it has nothing to draw, saying which of the\n// few reasons it is. A bare dash or a blank card cannot tell \"nobody picked a device\" from \"this\n// device never reports that\" from \"the device is quiet right now\", and a board that does not say\n// looks broken. The kinds are:\n//\n// unbound no device (or slot binding) is chosen: the author's job\n// not-reported the device's active profile does not declare this measurement: it will never report it\n// no-data declared, but nothing arrived in the window; `hint` can say what the last value was\n// forbidden the platform refused the read for this viewer\n// error the source failed to answer\n//\n// Styling is deliberately NEUTRAL (ISA-101): the muted foreground, a quiet glyph, no severity hue and no\n// warning symbol. Alarm colour means an alarm on a board, so a state that is not one never borrows it.\n// It sizes by the frame's content column: a small widget keeps the title, a roomy one adds the\n// explanation and the hint.\n\nimport type { CSSProperties } from 'react';\n\nimport { useWidgetBodySize } from './context';\nimport { viewerLocale } from './freshness';\nimport { css } from './theme';\nimport { fontVar, spaceVar } from './tokens';\n\nexport type WidgetEmptyKind = 'unbound' | 'not-reported' | 'no-data' | 'forbidden' | 'error';\n\nexport interface WidgetEmptyStrings {\n unbound: { title: string; detail: string };\n notReported: { title: string; detail: (measurement: string | undefined) => string };\n noData: { title: string; detail: (measurement: string | undefined) => string };\n forbidden: { title: string; detail: string };\n error: { title: string; detail: string };\n}\n\nexport const WIDGET_EMPTY_STRINGS: Record<'en' | 'es', WidgetEmptyStrings> = {\n en: {\n unbound: { title: 'No device chosen', detail: 'Choose a device for this widget to show its data.' },\n notReported: {\n title: 'Not reported by this device',\n detail: (m) => `This device's profile does not include ${m ? `\"${m}\"` : 'this measurement'}, so it will not report it.`,\n },\n noData: {\n title: 'No data in this range',\n detail: (m) => `Nothing was reported${m ? ` for \"${m}\"` : ''} in the selected time range.`,\n },\n forbidden: { title: 'No access', detail: 'You do not have access to this data.' },\n error: { title: 'Data unavailable', detail: 'The data source did not answer.' },\n },\n es: {\n unbound: { title: 'Sin dispositivo elegido', detail: 'Elija un dispositivo para que este widget muestre sus datos.' },\n notReported: {\n title: 'Este dispositivo no lo informa',\n detail: (m) => `El perfil de este dispositivo no incluye ${m ? `\"${m}\"` : 'esta medición'}, por lo que no la informará.`,\n },\n noData: {\n title: 'Sin datos en este rango',\n detail: (m) => `No se informó nada${m ? ` de \"${m}\"` : ''} en el rango de tiempo elegido.`,\n },\n forbidden: { title: 'Sin acceso', detail: 'No tiene acceso a estos datos.' },\n error: { title: 'Datos no disponibles', detail: 'El origen de datos no respondió.' },\n },\n};\n\n// Additional catalogs stay internal so the published record keeps its original key type.\nconst ZH_EMPTY_STRINGS: WidgetEmptyStrings = {\n unbound: { title: '尚未选择设备', detail: '请选择设备以在此组件中显示其数据。' },\n notReported: {\n title: '此设备不报告该测量项',\n detail: (m) => `此设备的配置文件未包含${m ? `“${m}”` : '此测量项'},因此不会报告其数据。`,\n },\n noData: {\n title: '此范围内暂无数据',\n detail: (m) => `所选时间范围内未收到${m ? `“${m}”的` : ''}数据。`,\n },\n forbidden: { title: '无访问权限', detail: '您无权访问这些数据。' },\n error: { title: '数据不可用', detail: '数据源未响应。' },\n};\n\nexport function widgetEmptyStrings(locale: string | undefined = viewerLocale()): WidgetEmptyStrings {\n const language = locale?.toLowerCase().split('-')[0];\n return language === 'es' ? WIDGET_EMPTY_STRINGS.es : language === 'zh' ? ZH_EMPTY_STRINGS : WIDGET_EMPTY_STRINGS.en;\n}\n\n// The glyph per kind. Quiet and non-alarming; the access refusal keeps the circle-slash the board's\n// other settled panes use.\nconst GLYPH: Record<WidgetEmptyKind, string> = {\n unbound: '○',\n 'not-reported': '∅',\n 'no-data': '∅',\n forbidden: '⊘',\n error: '…',\n};\n\n// The sizes (px of the content column) at which the explanation and the hint make room for the title.\nconst DETAIL_MIN = { width: 150, height: 84 };\nconst HINT_MIN = { width: 150, height: 100 };\nconst GLYPH_MIN_HEIGHT = 56;\n\nexport interface WidgetEmptyStateProps {\n kind: WidgetEmptyKind;\n // The measurement the widget was asked for, named in the explanation.\n measurement?: string;\n // One line after the explanation: for no-data, the last value known and when (\"Last value 21.4 °C · 3 hr. ago\").\n hint?: string;\n // Replaces the stock explanation (an error's own message, say).\n detail?: string;\n locale?: string;\n}\n\nexport function WidgetEmptyState({ kind, measurement, hint, detail, locale }: WidgetEmptyStateProps) {\n const size = useWidgetBodySize();\n const words = widgetEmptyStrings(locale);\n const copy =\n kind === 'unbound'\n ? { title: words.unbound.title, detail: words.unbound.detail }\n : kind === 'not-reported'\n ? { title: words.notReported.title, detail: words.notReported.detail(measurement) }\n : kind === 'no-data'\n ? { title: words.noData.title, detail: words.noData.detail(measurement) }\n : kind === 'forbidden'\n ? words.forbidden\n : words.error;\n // Unmeasured (first frame, jsdom) shows everything.\n const measured = size.width > 0 && size.height > 0;\n const room = (min: { width: number; height: number }) => !measured || (size.width >= min.width && size.height >= min.height);\n const text = detail ?? copy.detail;\n const lines: CSSProperties = { overflowWrap: 'anywhere' };\n return (\n <div\n role=\"status\"\n data-empty-state={kind}\n title={`${copy.title}. ${text}`}\n style={{\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: spaceVar(1),\n width: '100%',\n height: '100%',\n boxSizing: 'border-box',\n padding: spaceVar(2),\n textAlign: 'center',\n overflow: 'hidden',\n color: css('muted-foreground'),\n }}\n >\n {!measured || size.height >= GLYPH_MIN_HEIGHT ? (\n <div aria-hidden=\"true\" style={{ fontSize: fontVar('lg'), lineHeight: 1 }}>\n {GLYPH[kind]}\n </div>\n ) : null}\n <div data-empty-title=\"\" style={{ ...lines, fontSize: fontVar('sm'), fontWeight: 600 }}>\n {copy.title}\n </div>\n {room(DETAIL_MIN) ? (\n <div data-empty-detail=\"\" style={{ ...lines, fontSize: fontVar('xs'), opacity: 0.85 }}>\n {text}\n </div>\n ) : null}\n {hint && room(HINT_MIN) ? (\n <div data-empty-hint=\"\" style={{ ...lines, fontSize: fontVar('xs'), fontVariantNumeric: 'tabular-nums' }}>\n {hint}\n </div>\n ) : null}\n </div>\n );\n}\n\n// The words of the hint, in the widget packages' languages.\nexport interface LastValueStrings {\n lastValue: (value: string, age: string) => string;\n}\n\nexport const LAST_VALUE_STRINGS: Record<'en' | 'es', LastValueStrings> = {\n en: { lastValue: (value, age) => `Last value ${value} · ${age}` },\n es: { lastValue: (value, age) => `Último valor ${value} · ${age}` },\n};\n\nconst ZH_LAST_VALUE_STRINGS: LastValueStrings = { lastValue: (value, age) => `上次读数 ${value} · ${age}` };\n\nexport function lastValueHint(value: string, age: string, locale: string | undefined = viewerLocale()): string {\n const language = locale?.toLowerCase().split('-')[0];\n return (language === 'es' ? LAST_VALUE_STRINGS.es : language === 'zh' ? ZH_LAST_VALUE_STRINGS : LAST_VALUE_STRINGS.en).lastValue(value, age);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAkII,SAoBI,KApBJ;AA9FG,IAAM,uBAAgE;AAAA,EAC3E,IAAI;AAAA,IACF,SAAS,EAAE,OAAO,oBAAoB,QAAQ,oDAAoD;AAAA,IAClG,aAAa;AAAA,MACX,OAAO;AAAA,MACP,QAAQ,CAAC,MAAM,0CAA0C,IAAI,IAAI,CAAC,MAAM,kBAAkB;AAAA,I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Label: string;
|
|
11
11
|
}
|
|
12
|
-
export declare const FRESHNESS_STRINGS: Record<'en' | 'es', FreshnessStrings>;
|
|
12
|
+
export declare const FRESHNESS_STRINGS: Record<'en' | 'es' | 'zh-CN', FreshnessStrings>;
|
|
13
13
|
export declare function freshnessStrings(locale?: string | undefined): FreshnessStrings;
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
tokenPx,
|
|
21
21
|
tokenStyle,
|
|
22
22
|
viewerLocale
|
|
23
|
-
} from "./chunks/chunk-
|
|
23
|
+
} from "./chunks/chunk-KKUMZN7N.js";
|
|
24
24
|
import {
|
|
25
25
|
FIT_MIN_FONT_PX,
|
|
26
26
|
bandAt,
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
parseThresholds,
|
|
34
34
|
stickyChars,
|
|
35
35
|
thresholdBands
|
|
36
|
-
} from "./chunks/chunk-
|
|
36
|
+
} from "./chunks/chunk-R5MVRXBO.js";
|
|
37
37
|
import {
|
|
38
38
|
ALARM_LEVELS,
|
|
39
39
|
SEVERITY_LEVELS,
|
|
@@ -67,12 +67,12 @@ import {
|
|
|
67
67
|
useWidgetThemeRoot,
|
|
68
68
|
useWidgetTimeRange,
|
|
69
69
|
useWidgetTimeZone
|
|
70
|
-
} from "./chunks/chunk-
|
|
70
|
+
} from "./chunks/chunk-MYW73WDC.js";
|
|
71
71
|
import {
|
|
72
72
|
configureStrictCsp,
|
|
73
73
|
plainTooltipText,
|
|
74
74
|
strictCspEnabled
|
|
75
|
-
} from "./chunks/chunk-
|
|
75
|
+
} from "./chunks/chunk-ZCOHPFPW.js";
|
|
76
76
|
|
|
77
77
|
// src/define-widget.ts
|
|
78
78
|
function defineWidget(definition) {
|
|
@@ -847,13 +847,14 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime,
|
|
|
847
847
|
);
|
|
848
848
|
}
|
|
849
849
|
function ExportSlot(props) {
|
|
850
|
+
const locale = viewerLocale();
|
|
850
851
|
const host = useRef3(null);
|
|
851
852
|
const latest = useRef3(props);
|
|
852
853
|
latest.current = props;
|
|
853
854
|
useEffect4(() => {
|
|
854
855
|
let live = true;
|
|
855
856
|
let unmount;
|
|
856
|
-
import("./chunks/export-menu-
|
|
857
|
+
import("./chunks/export-menu-VFLUUFWM.js").then(
|
|
857
858
|
(m) => {
|
|
858
859
|
if (live && host.current) unmount = m.mountExportButton(host.current, EXPORT_BUTTON_SIZE, () => latest.current);
|
|
859
860
|
},
|
|
@@ -863,7 +864,7 @@ function ExportSlot(props) {
|
|
|
863
864
|
live = false;
|
|
864
865
|
unmount?.();
|
|
865
866
|
};
|
|
866
|
-
}, []);
|
|
867
|
+
}, [locale]);
|
|
867
868
|
return /* @__PURE__ */ jsx2(
|
|
868
869
|
"div",
|
|
869
870
|
{
|