reifyui 0.11.2 → 0.11.4
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/chart.cjs +66 -2
- package/dist/chart.cjs.map +1 -1
- package/dist/chart.d.ts +8 -0
- package/dist/chart.js +66 -2
- package/dist/chart.js.map +1 -1
- package/dist/slides.cjs +29 -6
- package/dist/slides.cjs.map +1 -1
- package/dist/slides.js +29 -6
- package/dist/slides.js.map +1 -1
- package/package.json +6 -5
- package/src/chart/Chart.jsx +9 -2
- package/src/chart/index.d.ts +8 -0
- package/src/chart/index.js +2 -0
- package/src/chart/safe.js +66 -0
- package/src/slides/elements.jsx +34 -5
package/dist/chart.cjs
CHANGED
|
@@ -31,13 +31,77 @@ var chart_exports = {};
|
|
|
31
31
|
__export(chart_exports, {
|
|
32
32
|
Chart: () => Chart,
|
|
33
33
|
chartTokens: () => chartTokens,
|
|
34
|
+
safeChartOption: () => safeChartOption,
|
|
35
|
+
safeHref: () => safeHref,
|
|
34
36
|
useChartTokens: () => useChartTokens
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(chart_exports);
|
|
37
39
|
|
|
38
40
|
// src/chart/Chart.jsx
|
|
39
41
|
var import_react = require("react");
|
|
42
|
+
|
|
43
|
+
// src/chart/safe.js
|
|
44
|
+
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
45
|
+
function safeHref(v) {
|
|
46
|
+
return typeof v === "string" && SAFE_HREF.test(v.replace(/[\u0000- \u007f]/g, "")) ? v : "";
|
|
47
|
+
}
|
|
48
|
+
var ESC = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
49
|
+
var esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
|
|
50
|
+
var isPlain = (v) => {
|
|
51
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
52
|
+
const p = Object.getPrototypeOf(v);
|
|
53
|
+
return p === Object.prototype || p === null;
|
|
54
|
+
};
|
|
55
|
+
function safeChartOption(option) {
|
|
56
|
+
if (!isPlain(option) && !Array.isArray(option)) return option;
|
|
57
|
+
const seen = /* @__PURE__ */ new Map();
|
|
58
|
+
const escaped = /* @__PURE__ */ new Set();
|
|
59
|
+
const walk = (n) => {
|
|
60
|
+
if (Array.isArray(n)) {
|
|
61
|
+
if (seen.has(n)) return seen.get(n);
|
|
62
|
+
const out2 = [];
|
|
63
|
+
seen.set(n, out2);
|
|
64
|
+
for (const x of n) out2.push(walk(x));
|
|
65
|
+
return out2;
|
|
66
|
+
}
|
|
67
|
+
if (!isPlain(n)) return n;
|
|
68
|
+
if (seen.has(n)) return seen.get(n);
|
|
69
|
+
const out = {};
|
|
70
|
+
seen.set(n, out);
|
|
71
|
+
for (const k of Object.keys(n)) {
|
|
72
|
+
const v = n[k];
|
|
73
|
+
if ((k === "link" || k === "sublink") && typeof v === "string") {
|
|
74
|
+
if (safeHref(v)) out[k] = v;
|
|
75
|
+
} else if (k === "tooltip") {
|
|
76
|
+
out[k] = tooltip(v);
|
|
77
|
+
} else if (k === "dataView" && isPlain(v)) {
|
|
78
|
+
out[k] = dataView(walk(v));
|
|
79
|
+
} else {
|
|
80
|
+
out[k] = walk(v);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
};
|
|
85
|
+
const tooltip = (v) => {
|
|
86
|
+
if (v === true) return { renderMode: "richText" };
|
|
87
|
+
if (Array.isArray(v)) return v.map((t) => isPlain(t) ? { ...walk(t), renderMode: "richText" } : walk(t));
|
|
88
|
+
return isPlain(v) ? { ...walk(v), renderMode: "richText" } : walk(v);
|
|
89
|
+
};
|
|
90
|
+
const dataView = (d) => {
|
|
91
|
+
if (escaped.has(d)) return d;
|
|
92
|
+
escaped.add(d);
|
|
93
|
+
if (typeof d.title === "string") d.title = esc(d.title);
|
|
94
|
+
if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => typeof s === "string" ? esc(s) : s);
|
|
95
|
+
return d;
|
|
96
|
+
};
|
|
97
|
+
return walk(option);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/chart/Chart.jsx
|
|
40
101
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
102
|
+
function applyOption(chart, option, notMerge) {
|
|
103
|
+
chart.setOption(safeChartOption(option), notMerge);
|
|
104
|
+
}
|
|
41
105
|
function Chart(props) {
|
|
42
106
|
const { option, renderer = "canvas", notMerge = true, onInit, label, fallback = null, className = "" } = props;
|
|
43
107
|
const host = (0, import_react.useRef)(null);
|
|
@@ -57,7 +121,7 @@ function Chart(props) {
|
|
|
57
121
|
inst.current = chart;
|
|
58
122
|
const { option: opt, notMerge: nm, onInit: cb } = latest.current;
|
|
59
123
|
if (opt) {
|
|
60
|
-
chart
|
|
124
|
+
applyOption(chart, opt, nm);
|
|
61
125
|
applied.current = opt;
|
|
62
126
|
}
|
|
63
127
|
if (cb) cb(chart);
|
|
@@ -77,7 +141,7 @@ function Chart(props) {
|
|
|
77
141
|
}, [renderer]);
|
|
78
142
|
(0, import_react.useEffect)(() => {
|
|
79
143
|
if (!inst.current || !option || applied.current === option) return;
|
|
80
|
-
inst.current
|
|
144
|
+
applyOption(inst.current, option, notMerge);
|
|
81
145
|
applied.current = option;
|
|
82
146
|
}, [option, notMerge]);
|
|
83
147
|
(0, import_react.useEffect)(() => {
|
package/dist/chart.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chart/index.js","../src/chart/Chart.jsx","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// The chart entry — IMPORT VIA SUBPATH ONLY ('reifyui/chart'), never from the root index.\n//\n// echarts is an optional peer and loads lazily inside Chart. A root re-export would put it in the\n// dependency graph of every consumer, so an app that renders a Button and no chart would have to\n// resolve a charting library to build. Same rule, same reason, as 'reifyui/slides'.\nexport { Chart } from './Chart.jsx';\n// The theme as strings a chart option can hold — series colours, axis ink, tooltip chrome. CSS\n// variables do not reach inside a canvas; these do.\nexport { chartTokens } from './tokens.js';\nexport { useChartTokens } from './useChartTokens.js';\n","// Chart — an ECharts option, drawn. That is the whole component.\n//\n// It deliberately knows nothing about series, axes or data shape: the option IS the contract, so\n// anything ECharts can draw, this draws, and the thing that decides what a chart should look like\n// (a person, or an agent writing the option) is not limited by a props table. What it does own is\n// the part every hand-rolled wrapper gets wrong: creating the instance once, disposing it on\n// unmount, and resizing it when its box changes — a chart inside a resizable panel that never\n// hears about the resize is the most common broken dashboard there is.\n//\n// echarts is an OPTIONAL peer, loaded lazily here, which is why this lives at `reifyui/chart` and\n// not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports\n// a Button must not resolve a charting library.\nimport { useEffect, useRef, useState } from 'react';\n\n/**\n * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a\n * useMemo — a fresh object every render redraws the chart every render\n * renderer 'canvas' (default) or 'svg'; svg stays crisp when the page is printed or scaled\n * notMerge replace the previous option rather than merging into it (default true: a redraw\n * after new data should not inherit last query's series)\n * onInit the instance, once, for the things only the instance can do (export an image)\n * label the chart's accessible name; a canvas has no text for a screen reader to find\n * fallback drawn instead when the chart code cannot be loaded at all\n */\nexport function Chart(props) {\n const { option, renderer = 'canvas', notMerge = true, onInit, label, fallback = null, className = '' } = props;\n const host = useRef(null);\n const inst = useRef(null);\n const applied = useRef(null); // the option the instance is currently showing\n const [failed, setFailed] = useState(false);\n // Read through refs inside the init effect so a new option or callback does not tear the\n // instance down and rebuild it.\n const latest = useRef({ option, notMerge, onInit });\n latest.current = { option, notMerge, onInit };\n\n useEffect(() => {\n let dead = false;\n (async () => {\n try {\n const mod = await import('echarts');\n const echarts = typeof mod.init === 'function' ? mod : (mod.default || mod);\n if (dead || !host.current) return;\n const chart = echarts.init(host.current, null, { renderer });\n inst.current = chart;\n const { option: opt, notMerge: nm, onInit: cb } = latest.current;\n if (opt) { chart.setOption(opt, nm); applied.current = opt; }\n if (cb) cb(chart);\n } catch {\n if (!dead) setFailed(true); // no chart code: say so, never draw a fake one\n }\n })();\n return () => {\n dead = true;\n try { inst.current?.dispose(); } catch { /* already gone with the DOM */ }\n inst.current = null;\n applied.current = null;\n };\n }, [renderer]);\n\n // `applied` keeps this from redrawing the option the init above just drew — the instance\n // arrives asynchronously, so both paths run on the first render that has one.\n useEffect(() => {\n if (!inst.current || !option || applied.current === option) return;\n inst.current.setOption(option, notMerge);\n applied.current = option;\n }, [option, notMerge]);\n\n useEffect(() => {\n const el = host.current;\n if (!el || typeof ResizeObserver !== 'function') return undefined;\n let frame = 0;\n const ro = new ResizeObserver(() => {\n // One resize per frame: a drag on a panel corner fires the observer on every pointer move.\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => inst.current?.resize());\n });\n ro.observe(el);\n return () => { cancelAnimationFrame(frame); ro.disconnect(); };\n }, []);\n\n if (failed) return <div className={['uic-chart', 'is-unavailable', className].filter(Boolean).join(' ')}>{fallback}</div>;\n return (\n <div\n ref={host}\n className={['uic-chart', className].filter(Boolean).join(' ')}\n role={label ? 'img' : undefined}\n aria-label={label}\n />\n );\n}\n","// The theme, as values a chart library can use.\n//\n// A chart draws into a canvas, where CSS custom properties do not reach: series colours, axis\n// labels and tooltip chrome all arrive as strings in an option object. Without this, every app\n// hardcodes hex in its chart code and the charts are the one part of the product that does not\n// follow the theme. Reading the same --uic-* tokens the stylesheets read keeps them together.\n\n// Same policy as the `var(--uic-x, …)` fallbacks in the stylesheets: a host that never loaded a\n// token layer still gets the library's own light palette rather than whatever the chart library\n// defaults to. Values are themes/light.css verbatim.\nconst FALLBACK = {\n cat: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948'],\n ink: '#111317', ink2: '#3A3D45', mute: '#5B5D66',\n line: '#DDDFE6', lineSoft: '#EFF1F4', surface: '#FFFFFF',\n brand: '#285AFF', ok: '#16a34a', warn: '#F59E0B', bad: '#b91c1c',\n font: 'inherit',\n};\n\nfunction read(style, name, fallback) {\n const v = style.getPropertyValue(name).trim();\n return v || fallback;\n}\n\n/**\n * Resolve the chart tokens in effect for `el` — pass the element the chart lives in, so a panel\n * inside a dark region resolves the dark values even when the page is light.\n *\n * `palette` is a categorical scale: assign it IN ORDER, one colour per series, and never cycle\n * it. Past eight series, colour has stopped being an encoding — fold the tail into one \"other\"\n * series or split the chart. On a light surface three of the eight sit below 3:1 against white,\n * so identity must not rest on colour alone: keep the legend, or label the series directly.\n */\nexport function chartTokens(el) {\n const target = (el && el.nodeType === 1 ? el : null)\n || (typeof document !== 'undefined' ? document.documentElement : null);\n if (!target || typeof getComputedStyle !== 'function') return { ...FALLBACK, palette: FALLBACK.cat };\n const s = getComputedStyle(target);\n return {\n palette: FALLBACK.cat.map((hex, i) => read(s, `--uic-cat-${i + 1}`, hex)),\n ink: read(s, '--uic-ink', FALLBACK.ink),\n ink2: read(s, '--uic-ink-2', FALLBACK.ink2),\n mute: read(s, '--uic-mute', FALLBACK.mute),\n line: read(s, '--uic-line', FALLBACK.line),\n lineSoft: read(s, '--uic-line-soft', FALLBACK.lineSoft),\n surface: read(s, '--uic-surface', FALLBACK.surface),\n brand: read(s, '--uic-brand', FALLBACK.brand),\n ok: read(s, '--uic-ok', FALLBACK.ok),\n warn: read(s, '--uic-warn', FALLBACK.warn),\n bad: read(s, '--uic-fail-ink', FALLBACK.bad),\n font: read(s, '--uic-font', FALLBACK.font),\n };\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { chartTokens } from './tokens.js';\n\n/**\n * chartTokens(), re-read when the theme changes.\n *\n * A chart's colours are baked into its option at build time, so flipping light↔dark leaves every\n * chart on the page painted for the theme that is gone until something re-renders it. There is no\n * event for \"the tokens changed\", so this watches the two things that change them: the attributes\n * a theme is switched with (a class or data-* on <html>/<body>), and the OS preference.\n *\n * Returns [tokens, ref] — put the ref on the element the chart lives in, or leave it unused and\n * the document's own tokens are read.\n */\nexport function useChartTokens() {\n const ref = useRef(null);\n const [tokens, setTokens] = useState(() => chartTokens(null));\n const reread = useCallback(() => setTokens(chartTokens(ref.current)), []);\n\n useEffect(() => {\n reread();\n if (typeof MutationObserver !== 'function') return undefined;\n const obs = new MutationObserver(reread);\n const opts = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };\n obs.observe(document.documentElement, opts);\n if (document.body) obs.observe(document.body, opts);\n const mq = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n mq?.addEventListener?.('change', reread);\n return () => { obs.disconnect(); mq?.removeEventListener?.('change', reread); };\n }, [reread]);\n\n return [tokens, ref];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,mBAA4C;AAoEvB;AAxDd,SAAS,MAAM,OAAO;AAC3B,QAAM,EAAE,QAAQ,WAAW,UAAU,WAAW,MAAM,QAAQ,OAAO,WAAW,MAAM,YAAY,GAAG,IAAI;AACzG,QAAM,WAAO,qBAAO,IAAI;AACxB,QAAM,WAAO,qBAAO,IAAI;AACxB,QAAM,cAAU,qBAAO,IAAI;AAC3B,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAS,KAAK;AAG1C,QAAM,aAAS,qBAAO,EAAE,QAAQ,UAAU,OAAO,CAAC;AAClD,SAAO,UAAU,EAAE,QAAQ,UAAU,OAAO;AAE5C,8BAAU,MAAM;AACd,QAAI,OAAO;AACX,KAAC,YAAY;AACX,UAAI;AACF,cAAM,MAAM,MAAM,OAAO,SAAS;AAClC,cAAM,UAAU,OAAO,IAAI,SAAS,aAAa,MAAO,IAAI,WAAW;AACvE,YAAI,QAAQ,CAAC,KAAK,QAAS;AAC3B,cAAM,QAAQ,QAAQ,KAAK,KAAK,SAAS,MAAM,EAAE,SAAS,CAAC;AAC3D,aAAK,UAAU;AACf,cAAM,EAAE,QAAQ,KAAK,UAAU,IAAI,QAAQ,GAAG,IAAI,OAAO;AACzD,YAAI,KAAK;AAAE,gBAAM,UAAU,KAAK,EAAE;AAAG,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c,SAAS,IAAI;AAAA,EAC3C;AACF;;;ACnDA,IAAAA,gBAAyD;AAclD,SAAS,iBAAiB;AAC/B,QAAM,UAAM,sBAAO,IAAI;AACvB,QAAM,CAAC,QAAQ,SAAS,QAAI,wBAAS,MAAM,YAAY,IAAI,CAAC;AAC5D,QAAM,aAAS,2BAAY,MAAM,UAAU,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AAExE,+BAAU,MAAM;AACd,WAAO;AACP,QAAI,OAAO,qBAAqB,WAAY,QAAO;AACnD,UAAM,MAAM,IAAI,iBAAiB,MAAM;AACvC,UAAM,OAAO,EAAE,YAAY,MAAM,iBAAiB,CAAC,SAAS,SAAS,YAAY,EAAE;AACnF,QAAI,QAAQ,SAAS,iBAAiB,IAAI;AAC1C,QAAI,SAAS,KAAM,KAAI,QAAQ,SAAS,MAAM,IAAI;AAClD,UAAM,KAAK,OAAO,eAAe,aAAa,WAAW,8BAA8B,IAAI;AAC3F,QAAI,mBAAmB,UAAU,MAAM;AACvC,WAAO,MAAM;AAAE,UAAI,WAAW;AAAG,UAAI,sBAAsB,UAAU,MAAM;AAAA,IAAG;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,CAAC,QAAQ,GAAG;AACrB;","names":["import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/chart/index.js","../src/chart/Chart.jsx","../src/chart/safe.js","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// The chart entry — IMPORT VIA SUBPATH ONLY ('reifyui/chart'), never from the root index.\n//\n// echarts is an optional peer and loads lazily inside Chart. A root re-export would put it in the\n// dependency graph of every consumer, so an app that renders a Button and no chart would have to\n// resolve a charting library to build. Same rule, same reason, as 'reifyui/slides'.\nexport { Chart } from './Chart.jsx';\n// What the chart does to every option before ECharts sees it, for a host that sets options on the instance itself.\nexport { safeChartOption, safeHref } from './safe.js';\n// The theme as strings a chart option can hold — series colours, axis ink, tooltip chrome. CSS\n// variables do not reach inside a canvas; these do.\nexport { chartTokens } from './tokens.js';\nexport { useChartTokens } from './useChartTokens.js';\n","// Chart — an ECharts option, drawn. That is the whole component.\n//\n// It deliberately knows nothing about series, axes or data shape: the option IS the contract, so\n// anything ECharts can draw, this draws, and the thing that decides what a chart should look like\n// (a person, or an agent writing the option) is not limited by a props table. What it does own is\n// the part every hand-rolled wrapper gets wrong: creating the instance once, disposing it on\n// unmount, and resizing it when its box changes — a chart inside a resizable panel that never\n// hears about the resize is the most common broken dashboard there is.\n//\n// echarts is an OPTIONAL peer, loaded lazily here, which is why this lives at `reifyui/chart` and\n// not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports\n// a Button must not resolve a charting library.\nimport { useEffect, useRef, useState } from 'react';\nimport { safeChartOption } from './safe.js';\n\n// Every option reaches ECharts through here, made inert first (safe.js): a tooltip draws text, a link is http(s) or\n// mailto, the data view's words are escaped. An option a host sets on the instance it got from onInit is its own.\nexport function applyOption(chart, option, notMerge) {\n chart.setOption(safeChartOption(option), notMerge);\n}\n\n/**\n * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a\n * useMemo — a fresh object every render redraws the chart every render\n * renderer 'canvas' (default) or 'svg'; svg stays crisp when the page is printed or scaled\n * notMerge replace the previous option rather than merging into it (default true: a redraw\n * after new data should not inherit last query's series)\n * onInit the instance, once, for the things only the instance can do (export an image)\n * label the chart's accessible name; a canvas has no text for a screen reader to find\n * fallback drawn instead when the chart code cannot be loaded at all\n */\nexport function Chart(props) {\n const { option, renderer = 'canvas', notMerge = true, onInit, label, fallback = null, className = '' } = props;\n const host = useRef(null);\n const inst = useRef(null);\n const applied = useRef(null); // the option the instance is currently showing\n const [failed, setFailed] = useState(false);\n // Read through refs inside the init effect so a new option or callback does not tear the\n // instance down and rebuild it.\n const latest = useRef({ option, notMerge, onInit });\n latest.current = { option, notMerge, onInit };\n\n useEffect(() => {\n let dead = false;\n (async () => {\n try {\n const mod = await import('echarts');\n const echarts = typeof mod.init === 'function' ? mod : (mod.default || mod);\n if (dead || !host.current) return;\n const chart = echarts.init(host.current, null, { renderer });\n inst.current = chart;\n const { option: opt, notMerge: nm, onInit: cb } = latest.current;\n if (opt) { applyOption(chart, opt, nm); applied.current = opt; }\n if (cb) cb(chart);\n } catch {\n if (!dead) setFailed(true); // no chart code: say so, never draw a fake one\n }\n })();\n return () => {\n dead = true;\n try { inst.current?.dispose(); } catch { /* already gone with the DOM */ }\n inst.current = null;\n applied.current = null;\n };\n }, [renderer]);\n\n // `applied` keeps this from redrawing the option the init above just drew — the instance\n // arrives asynchronously, so both paths run on the first render that has one.\n useEffect(() => {\n if (!inst.current || !option || applied.current === option) return;\n applyOption(inst.current, option, notMerge);\n applied.current = option;\n }, [option, notMerge]);\n\n useEffect(() => {\n const el = host.current;\n if (!el || typeof ResizeObserver !== 'function') return undefined;\n let frame = 0;\n const ro = new ResizeObserver(() => {\n // One resize per frame: a drag on a panel corner fires the observer on every pointer move.\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => inst.current?.resize());\n });\n ro.observe(el);\n return () => { cancelAnimationFrame(frame); ro.disconnect(); };\n }, []);\n\n if (failed) return <div className={['uic-chart', 'is-unavailable', className].filter(Boolean).join(' ')}>{fallback}</div>;\n return (\n <div\n ref={host}\n className={['uic-chart', className].filter(Boolean).join(' ')}\n role={label ? 'img' : undefined}\n aria-label={label}\n />\n );\n}\n","// An ECharts option can come from anywhere (a person, a saved dashboard, an agent writing it), so the chart keeps it\n// inert before ECharts sees it (found 2026-11-10). ECharts writes some option strings into the page as HTML or opens\n// them as URLs:\n// - a tooltip's content (its formatter, series and data names) in the default HTML render mode;\n// - a title's link / sublink and a sunburst or treemap node's link, opened in a window that keeps the page's origin;\n// - the data view's title and button labels (toolbox.feature.dataView.title / lang).\n// So every tooltip draws in the chart itself (renderMode 'richText': text, never markup), a link is kept only when it is\n// http(s) or mailto, and the data view's words are escaped. The option passed in is never changed: plain objects and\n// arrays are copied, anything else (functions, typed arrays, dates, gradient objects) is passed through as it is.\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:)/i;\n\nexport function safeHref(v) {\n return typeof v === 'string' && SAFE_HREF.test(v.replace(/[\\u0000- \\u007f]/g, '')) ? v : '';\n}\n\nconst ESC = { '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' };\nconst esc = (s) => String(s).replace(/[&<>\"']/g, (c) => ESC[c]);\n\nconst isPlain = (v) => {\n if (!v || typeof v !== 'object' || Array.isArray(v)) return false;\n const p = Object.getPrototypeOf(v);\n return p === Object.prototype || p === null;\n};\n\nexport function safeChartOption(option) {\n if (!isPlain(option) && !Array.isArray(option)) return option;\n const seen = new Map();\n const escaped = new Set();\n const walk = (n) => {\n if (Array.isArray(n)) {\n if (seen.has(n)) return seen.get(n);\n const out = []; seen.set(n, out);\n for (const x of n) out.push(walk(x));\n return out;\n }\n if (!isPlain(n)) return n;\n if (seen.has(n)) return seen.get(n);\n const out = {}; seen.set(n, out);\n for (const k of Object.keys(n)) {\n const v = n[k];\n if ((k === 'link' || k === 'sublink') && typeof v === 'string') {\n if (safeHref(v)) out[k] = v;\n } else if (k === 'tooltip') {\n out[k] = tooltip(v);\n } else if (k === 'dataView' && isPlain(v)) {\n out[k] = dataView(walk(v));\n } else {\n out[k] = walk(v);\n }\n }\n return out;\n };\n const tooltip = (v) => {\n if (v === true) return { renderMode: 'richText' };\n if (Array.isArray(v)) return v.map((t) => (isPlain(t) ? { ...walk(t), renderMode: 'richText' } : walk(t)));\n return isPlain(v) ? { ...walk(v), renderMode: 'richText' } : walk(v);\n };\n const dataView = (d) => {\n if (escaped.has(d)) return d; // the same data view reached twice: escape once\n escaped.add(d);\n if (typeof d.title === 'string') d.title = esc(d.title);\n if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => (typeof s === 'string' ? esc(s) : s));\n return d;\n };\n return walk(option);\n}\n","// The theme, as values a chart library can use.\n//\n// A chart draws into a canvas, where CSS custom properties do not reach: series colours, axis\n// labels and tooltip chrome all arrive as strings in an option object. Without this, every app\n// hardcodes hex in its chart code and the charts are the one part of the product that does not\n// follow the theme. Reading the same --uic-* tokens the stylesheets read keeps them together.\n\n// Same policy as the `var(--uic-x, …)` fallbacks in the stylesheets: a host that never loaded a\n// token layer still gets the library's own light palette rather than whatever the chart library\n// defaults to. Values are themes/light.css verbatim.\nconst FALLBACK = {\n cat: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948'],\n ink: '#111317', ink2: '#3A3D45', mute: '#5B5D66',\n line: '#DDDFE6', lineSoft: '#EFF1F4', surface: '#FFFFFF',\n brand: '#285AFF', ok: '#16a34a', warn: '#F59E0B', bad: '#b91c1c',\n font: 'inherit',\n};\n\nfunction read(style, name, fallback) {\n const v = style.getPropertyValue(name).trim();\n return v || fallback;\n}\n\n/**\n * Resolve the chart tokens in effect for `el` — pass the element the chart lives in, so a panel\n * inside a dark region resolves the dark values even when the page is light.\n *\n * `palette` is a categorical scale: assign it IN ORDER, one colour per series, and never cycle\n * it. Past eight series, colour has stopped being an encoding — fold the tail into one \"other\"\n * series or split the chart. On a light surface three of the eight sit below 3:1 against white,\n * so identity must not rest on colour alone: keep the legend, or label the series directly.\n */\nexport function chartTokens(el) {\n const target = (el && el.nodeType === 1 ? el : null)\n || (typeof document !== 'undefined' ? document.documentElement : null);\n if (!target || typeof getComputedStyle !== 'function') return { ...FALLBACK, palette: FALLBACK.cat };\n const s = getComputedStyle(target);\n return {\n palette: FALLBACK.cat.map((hex, i) => read(s, `--uic-cat-${i + 1}`, hex)),\n ink: read(s, '--uic-ink', FALLBACK.ink),\n ink2: read(s, '--uic-ink-2', FALLBACK.ink2),\n mute: read(s, '--uic-mute', FALLBACK.mute),\n line: read(s, '--uic-line', FALLBACK.line),\n lineSoft: read(s, '--uic-line-soft', FALLBACK.lineSoft),\n surface: read(s, '--uic-surface', FALLBACK.surface),\n brand: read(s, '--uic-brand', FALLBACK.brand),\n ok: read(s, '--uic-ok', FALLBACK.ok),\n warn: read(s, '--uic-warn', FALLBACK.warn),\n bad: read(s, '--uic-fail-ink', FALLBACK.bad),\n font: read(s, '--uic-font', FALLBACK.font),\n };\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { chartTokens } from './tokens.js';\n\n/**\n * chartTokens(), re-read when the theme changes.\n *\n * A chart's colours are baked into its option at build time, so flipping light↔dark leaves every\n * chart on the page painted for the theme that is gone until something re-renders it. There is no\n * event for \"the tokens changed\", so this watches the two things that change them: the attributes\n * a theme is switched with (a class or data-* on <html>/<body>), and the OS preference.\n *\n * Returns [tokens, ref] — put the ref on the element the chart lives in, or leave it unused and\n * the document's own tokens are read.\n */\nexport function useChartTokens() {\n const ref = useRef(null);\n const [tokens, setTokens] = useState(() => chartTokens(null));\n const reread = useCallback(() => setTokens(chartTokens(ref.current)), []);\n\n useEffect(() => {\n reread();\n if (typeof MutationObserver !== 'function') return undefined;\n const obs = new MutationObserver(reread);\n const opts = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };\n obs.observe(document.documentElement, opts);\n if (document.body) obs.observe(document.body, opts);\n const mq = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n mq?.addEventListener?.('change', reread);\n return () => { obs.disconnect(); mq?.removeEventListener?.('change', reread); };\n }, [reread]);\n\n return [tokens, ref];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,mBAA4C;;;ACH5C,IAAM,YAAY;AAEX,SAAS,SAAS,GAAG;AAC1B,SAAO,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,QAAQ,qBAAqB,EAAE,CAAC,IAAI,IAAI;AAC3F;AAEA,IAAM,MAAM,EAAE,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,UAAU,KAAK,QAAQ;AAClF,IAAM,MAAM,CAAC,MAAM,OAAO,CAAC,EAAE,QAAQ,YAAY,CAAC,MAAM,IAAI,C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UAAU,KAAK,GAAG,mBAAmB,SAAS,QAAQ;AAAA,IACtD,SAAS,KAAK,GAAG,iBAAiB,SAAS,OAAO;AAAA,IAClD,OAAO,KAAK,GAAG,eAAe,SAAS,KAAK;AAAA,IAC5C,IAAI,KAAK,GAAG,YAAY,SAAS,EAAE;AAAA,IACnC,MAAM,KAAK,GAAG,cAAc,SAAS,IAAI;AAAA,IACzC,KAAK,KAAK,GAAG,kBAAkB,SAAS,GAAG;AAAA,IAC3C,MAAM,KAAK,GAAG,cAAc,SAAS,IAAI;AAAA,EAC3C;AACF;;;ACnDA,IAAAC,gBAAyD;AAclD,SAAS,iBAAiB;AAC/B,QAAM,UAAM,sBAAO,IAAI;AACvB,QAAM,CAAC,QAAQ,SAAS,QAAI,wBAAS,MAAM,YAAY,IAAI,CAAC;AAC5D,QAAM,aAAS,2BAAY,MAAM,UAAU,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AAExE,+BAAU,MAAM;AACd,WAAO;AACP,QAAI,OAAO,qBAAqB,WAAY,QAAO;AACnD,UAAM,MAAM,IAAI,iBAAiB,MAAM;AACvC,UAAM,OAAO,EAAE,YAAY,MAAM,iBAAiB,CAAC,SAAS,SAAS,YAAY,EAAE;AACnF,QAAI,QAAQ,SAAS,iBAAiB,IAAI;AAC1C,QAAI,SAAS,KAAM,KAAI,QAAQ,SAAS,MAAM,IAAI;AAClD,UAAM,KAAK,OAAO,eAAe,aAAa,WAAW,8BAA8B,IAAI;AAC3F,QAAI,mBAAmB,UAAU,MAAM;AACvC,WAAO,MAAM;AAAE,UAAI,WAAW;AAAG,UAAI,sBAAsB,UAAU,MAAM;AAAA,IAAG;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,CAAC,QAAQ,GAAG;AACrB;","names":["out","import_react"]}
|
package/dist/chart.d.ts
CHANGED
|
@@ -55,3 +55,11 @@ export function chartTokens(el?: Element | null): ChartTokens;
|
|
|
55
55
|
/** chartTokens(), re-read when the theme changes (a class/data-* flip on <html> or <body>, or the
|
|
56
56
|
* OS preference). Put the returned ref on the element the chart lives in. */
|
|
57
57
|
export function useChartTokens(): [ChartTokens, RefObject<HTMLElement | null>];
|
|
58
|
+
|
|
59
|
+
/** A copy of an option with what ECharts would write as HTML or open as a URL made inert: every tooltip draws text
|
|
60
|
+
* (renderMode 'richText'), a link or sublink is kept only for http(s) or mailto, and the data view's title and labels
|
|
61
|
+
* are escaped. Chart applies it to every option; call it yourself before setOption on the instance from onInit. */
|
|
62
|
+
export function safeChartOption<T>(option: T): T;
|
|
63
|
+
/** The value when it is an http(s) or mailto URL, else ''. */
|
|
64
|
+
export function safeHref(value: unknown): string;
|
|
65
|
+
|
package/dist/chart.js
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
// src/chart/Chart.jsx
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// src/chart/safe.js
|
|
5
|
+
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
6
|
+
function safeHref(v) {
|
|
7
|
+
return typeof v === "string" && SAFE_HREF.test(v.replace(/[\u0000- \u007f]/g, "")) ? v : "";
|
|
8
|
+
}
|
|
9
|
+
var ESC = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
10
|
+
var esc = (s) => String(s).replace(/[&<>"']/g, (c) => ESC[c]);
|
|
11
|
+
var isPlain = (v) => {
|
|
12
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
13
|
+
const p = Object.getPrototypeOf(v);
|
|
14
|
+
return p === Object.prototype || p === null;
|
|
15
|
+
};
|
|
16
|
+
function safeChartOption(option) {
|
|
17
|
+
if (!isPlain(option) && !Array.isArray(option)) return option;
|
|
18
|
+
const seen = /* @__PURE__ */ new Map();
|
|
19
|
+
const escaped = /* @__PURE__ */ new Set();
|
|
20
|
+
const walk = (n) => {
|
|
21
|
+
if (Array.isArray(n)) {
|
|
22
|
+
if (seen.has(n)) return seen.get(n);
|
|
23
|
+
const out2 = [];
|
|
24
|
+
seen.set(n, out2);
|
|
25
|
+
for (const x of n) out2.push(walk(x));
|
|
26
|
+
return out2;
|
|
27
|
+
}
|
|
28
|
+
if (!isPlain(n)) return n;
|
|
29
|
+
if (seen.has(n)) return seen.get(n);
|
|
30
|
+
const out = {};
|
|
31
|
+
seen.set(n, out);
|
|
32
|
+
for (const k of Object.keys(n)) {
|
|
33
|
+
const v = n[k];
|
|
34
|
+
if ((k === "link" || k === "sublink") && typeof v === "string") {
|
|
35
|
+
if (safeHref(v)) out[k] = v;
|
|
36
|
+
} else if (k === "tooltip") {
|
|
37
|
+
out[k] = tooltip(v);
|
|
38
|
+
} else if (k === "dataView" && isPlain(v)) {
|
|
39
|
+
out[k] = dataView(walk(v));
|
|
40
|
+
} else {
|
|
41
|
+
out[k] = walk(v);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
};
|
|
46
|
+
const tooltip = (v) => {
|
|
47
|
+
if (v === true) return { renderMode: "richText" };
|
|
48
|
+
if (Array.isArray(v)) return v.map((t) => isPlain(t) ? { ...walk(t), renderMode: "richText" } : walk(t));
|
|
49
|
+
return isPlain(v) ? { ...walk(v), renderMode: "richText" } : walk(v);
|
|
50
|
+
};
|
|
51
|
+
const dataView = (d) => {
|
|
52
|
+
if (escaped.has(d)) return d;
|
|
53
|
+
escaped.add(d);
|
|
54
|
+
if (typeof d.title === "string") d.title = esc(d.title);
|
|
55
|
+
if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => typeof s === "string" ? esc(s) : s);
|
|
56
|
+
return d;
|
|
57
|
+
};
|
|
58
|
+
return walk(option);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/chart/Chart.jsx
|
|
3
62
|
import { jsx } from "react/jsx-runtime";
|
|
63
|
+
function applyOption(chart, option, notMerge) {
|
|
64
|
+
chart.setOption(safeChartOption(option), notMerge);
|
|
65
|
+
}
|
|
4
66
|
function Chart(props) {
|
|
5
67
|
const { option, renderer = "canvas", notMerge = true, onInit, label, fallback = null, className = "" } = props;
|
|
6
68
|
const host = useRef(null);
|
|
@@ -20,7 +82,7 @@ function Chart(props) {
|
|
|
20
82
|
inst.current = chart;
|
|
21
83
|
const { option: opt, notMerge: nm, onInit: cb } = latest.current;
|
|
22
84
|
if (opt) {
|
|
23
|
-
chart
|
|
85
|
+
applyOption(chart, opt, nm);
|
|
24
86
|
applied.current = opt;
|
|
25
87
|
}
|
|
26
88
|
if (cb) cb(chart);
|
|
@@ -40,7 +102,7 @@ function Chart(props) {
|
|
|
40
102
|
}, [renderer]);
|
|
41
103
|
useEffect(() => {
|
|
42
104
|
if (!inst.current || !option || applied.current === option) return;
|
|
43
|
-
inst.current
|
|
105
|
+
applyOption(inst.current, option, notMerge);
|
|
44
106
|
applied.current = option;
|
|
45
107
|
}, [option, notMerge]);
|
|
46
108
|
useEffect(() => {
|
|
@@ -133,6 +195,8 @@ function useChartTokens() {
|
|
|
133
195
|
export {
|
|
134
196
|
Chart,
|
|
135
197
|
chartTokens,
|
|
198
|
+
safeChartOption,
|
|
199
|
+
safeHref,
|
|
136
200
|
useChartTokens
|
|
137
201
|
};
|
|
138
202
|
//# sourceMappingURL=chart.js.map
|
package/dist/chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chart/Chart.jsx","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// Chart — an ECharts option, drawn. That is the whole component.\n//\n// It deliberately knows nothing about series, axes or data shape: the option IS the contract, so\n// anything ECharts can draw, this draws, and the thing that decides what a chart should look like\n// (a person, or an agent writing the option) is not limited by a props table. What it does own is\n// the part every hand-rolled wrapper gets wrong: creating the instance once, disposing it on\n// unmount, and resizing it when its box changes — a chart inside a resizable panel that never\n// hears about the resize is the most common broken dashboard there is.\n//\n// echarts is an OPTIONAL peer, loaded lazily here, which is why this lives at `reifyui/chart` and\n// not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports\n// a Button must not resolve a charting library.\nimport { useEffect, useRef, useState } from 'react';\n\n/**\n * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a\n * useMemo — a fresh object every render redraws the chart every render\n * renderer 'canvas' (default) or 'svg'; svg stays crisp when the page is printed or scaled\n * notMerge replace the previous option rather than merging into it (default true: a redraw\n * after new data should not inherit last query's series)\n * onInit the instance, once, for the things only the instance can do (export an image)\n * label the chart's accessible name; a canvas has no text for a screen reader to find\n * fallback drawn instead when the chart code cannot be loaded at all\n */\nexport function Chart(props) {\n const { option, renderer = 'canvas', notMerge = true, onInit, label, fallback = null, className = '' } = props;\n const host = useRef(null);\n const inst = useRef(null);\n const applied = useRef(null); // the option the instance is currently showing\n const [failed, setFailed] = useState(false);\n // Read through refs inside the init effect so a new option or callback does not tear the\n // instance down and rebuild it.\n const latest = useRef({ option, notMerge, onInit });\n latest.current = { option, notMerge, onInit };\n\n useEffect(() => {\n let dead = false;\n (async () => {\n try {\n const mod = await import('echarts');\n const echarts = typeof mod.init === 'function' ? mod : (mod.default || mod);\n if (dead || !host.current) return;\n const chart = echarts.init(host.current, null, { renderer });\n inst.current = chart;\n const { option: opt, notMerge: nm, onInit: cb } = latest.current;\n if (opt) { chart.setOption(opt, nm); applied.current = opt; }\n if (cb) cb(chart);\n } catch {\n if (!dead) setFailed(true); // no chart code: say so, never draw a fake one\n }\n })();\n return () => {\n dead = true;\n try { inst.current?.dispose(); } catch { /* already gone with the DOM */ }\n inst.current = null;\n applied.current = null;\n };\n }, [renderer]);\n\n // `applied` keeps this from redrawing the option the init above just drew — the instance\n // arrives asynchronously, so both paths run on the first render that has one.\n useEffect(() => {\n if (!inst.current || !option || applied.current === option) return;\n inst.current.setOption(option, notMerge);\n applied.current = option;\n }, [option, notMerge]);\n\n useEffect(() => {\n const el = host.current;\n if (!el || typeof ResizeObserver !== 'function') return undefined;\n let frame = 0;\n const ro = new ResizeObserver(() => {\n // One resize per frame: a drag on a panel corner fires the observer on every pointer move.\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => inst.current?.resize());\n });\n ro.observe(el);\n return () => { cancelAnimationFrame(frame); ro.disconnect(); };\n }, []);\n\n if (failed) return <div className={['uic-chart', 'is-unavailable', className].filter(Boolean).join(' ')}>{fallback}</div>;\n return (\n <div\n ref={host}\n className={['uic-chart', className].filter(Boolean).join(' ')}\n role={label ? 'img' : undefined}\n aria-label={label}\n />\n );\n}\n","// The theme, as values a chart library can use.\n//\n// A chart draws into a canvas, where CSS custom properties do not reach: series colours, axis\n// labels and tooltip chrome all arrive as strings in an option object. Without this, every app\n// hardcodes hex in its chart code and the charts are the one part of the product that does not\n// follow the theme. Reading the same --uic-* tokens the stylesheets read keeps them together.\n\n// Same policy as the `var(--uic-x, …)` fallbacks in the stylesheets: a host that never loaded a\n// token layer still gets the library's own light palette rather than whatever the chart library\n// defaults to. Values are themes/light.css verbatim.\nconst FALLBACK = {\n cat: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948'],\n ink: '#111317', ink2: '#3A3D45', mute: '#5B5D66',\n line: '#DDDFE6', lineSoft: '#EFF1F4', surface: '#FFFFFF',\n brand: '#285AFF', ok: '#16a34a', warn: '#F59E0B', bad: '#b91c1c',\n font: 'inherit',\n};\n\nfunction read(style, name, fallback) {\n const v = style.getPropertyValue(name).trim();\n return v || fallback;\n}\n\n/**\n * Resolve the chart tokens in effect for `el` — pass the element the chart lives in, so a panel\n * inside a dark region resolves the dark values even when the page is light.\n *\n * `palette` is a categorical scale: assign it IN ORDER, one colour per series, and never cycle\n * it. Past eight series, colour has stopped being an encoding — fold the tail into one \"other\"\n * series or split the chart. On a light surface three of the eight sit below 3:1 against white,\n * so identity must not rest on colour alone: keep the legend, or label the series directly.\n */\nexport function chartTokens(el) {\n const target = (el && el.nodeType === 1 ? el : null)\n || (typeof document !== 'undefined' ? document.documentElement : null);\n if (!target || typeof getComputedStyle !== 'function') return { ...FALLBACK, palette: FALLBACK.cat };\n const s = getComputedStyle(target);\n return {\n palette: FALLBACK.cat.map((hex, i) => read(s, `--uic-cat-${i + 1}`, hex)),\n ink: read(s, '--uic-ink', FALLBACK.ink),\n ink2: read(s, '--uic-ink-2', FALLBACK.ink2),\n mute: read(s, '--uic-mute', FALLBACK.mute),\n line: read(s, '--uic-line', FALLBACK.line),\n lineSoft: read(s, '--uic-line-soft', FALLBACK.lineSoft),\n surface: read(s, '--uic-surface', FALLBACK.surface),\n brand: read(s, '--uic-brand', FALLBACK.brand),\n ok: read(s, '--uic-ok', FALLBACK.ok),\n warn: read(s, '--uic-warn', FALLBACK.warn),\n bad: read(s, '--uic-fail-ink', FALLBACK.bad),\n font: read(s, '--uic-font', FALLBACK.font),\n };\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { chartTokens } from './tokens.js';\n\n/**\n * chartTokens(), re-read when the theme changes.\n *\n * A chart's colours are baked into its option at build time, so flipping light↔dark leaves every\n * chart on the page painted for the theme that is gone until something re-renders it. There is no\n * event for \"the tokens changed\", so this watches the two things that change them: the attributes\n * a theme is switched with (a class or data-* on <html>/<body>), and the OS preference.\n *\n * Returns [tokens, ref] — put the ref on the element the chart lives in, or leave it unused and\n * the document's own tokens are read.\n */\nexport function useChartTokens() {\n const ref = useRef(null);\n const [tokens, setTokens] = useState(() => chartTokens(null));\n const reread = useCallback(() => setTokens(chartTokens(ref.current)), []);\n\n useEffect(() => {\n reread();\n if (typeof MutationObserver !== 'function') return undefined;\n const obs = new MutationObserver(reread);\n const opts = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };\n obs.observe(document.documentElement, opts);\n if (document.body) obs.observe(document.body, opts);\n const mq = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n mq?.addEventListener?.('change', reread);\n return () => { obs.disconnect(); mq?.removeEventListener?.('change', reread); };\n }, [reread]);\n\n return [tokens, ref];\n}\n"],"mappings":";AAYA,SAAS,WAAW,QAAQ,gBAAgB;AAoEvB;AAxDd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YAAY,EAAE;AACnF,QAAI,QAAQ,SAAS,iBAAiB,IAAI;AAC1C,QAAI,SAAS,KAAM,KAAI,QAAQ,SAAS,MAAM,IAAI;AAClD,UAAM,KAAK,OAAO,eAAe,aAAa,WAAW,8BAA8B,IAAI;AAC3F,QAAI,mBAAmB,UAAU,MAAM;AACvC,WAAO,MAAM;AAAE,UAAI,WAAW;AAAG,UAAI,sBAAsB,UAAU,MAAM;AAAA,IAAG;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,CAAC,QAAQ,GAAG;AACrB;","names":["useEffect","useRef","useState","useRef","useState","useEffect"]}
|
|
1
|
+
{"version":3,"sources":["../src/chart/Chart.jsx","../src/chart/safe.js","../src/chart/tokens.js","../src/chart/useChartTokens.js"],"sourcesContent":["// Chart — an ECharts option, drawn. That is the whole component.\n//\n// It deliberately knows nothing about series, axes or data shape: the option IS the contract, so\n// anything ECharts can draw, this draws, and the thing that decides what a chart should look like\n// (a person, or an agent writing the option) is not limited by a props table. What it does own is\n// the part every hand-rolled wrapper gets wrong: creating the instance once, disposing it on\n// unmount, and resizing it when its box changes — a chart inside a resizable panel that never\n// hears about the resize is the most common broken dashboard there is.\n//\n// echarts is an OPTIONAL peer, loaded lazily here, which is why this lives at `reifyui/chart` and\n// not in the root index — the same reason `reifyui/slides` is its own entry. An app that imports\n// a Button must not resolve a charting library.\nimport { useEffect, useRef, useState } from 'react';\nimport { safeChartOption } from './safe.js';\n\n// Every option reaches ECharts through here, made inert first (safe.js): a tooltip draws text, a link is http(s) or\n// mailto, the data view's words are escaped. An option a host sets on the instance it got from onInit is its own.\nexport function applyOption(chart, option, notMerge) {\n chart.setOption(safeChartOption(option), notMerge);\n}\n\n/**\n * option the ECharts option. Applied whenever the REFERENCE changes, so build it in a\n * useMemo — a fresh object every render redraws the chart every render\n * renderer 'canvas' (default) or 'svg'; svg stays crisp when the page is printed or scaled\n * notMerge replace the previous option rather than merging into it (default true: a redraw\n * after new data should not inherit last query's series)\n * onInit the instance, once, for the things only the instance can do (export an image)\n * label the chart's accessible name; a canvas has no text for a screen reader to find\n * fallback drawn instead when the chart code cannot be loaded at all\n */\nexport function Chart(props) {\n const { option, renderer = 'canvas', notMerge = true, onInit, label, fallback = null, className = '' } = props;\n const host = useRef(null);\n const inst = useRef(null);\n const applied = useRef(null); // the option the instance is currently showing\n const [failed, setFailed] = useState(false);\n // Read through refs inside the init effect so a new option or callback does not tear the\n // instance down and rebuild it.\n const latest = useRef({ option, notMerge, onInit });\n latest.current = { option, notMerge, onInit };\n\n useEffect(() => {\n let dead = false;\n (async () => {\n try {\n const mod = await import('echarts');\n const echarts = typeof mod.init === 'function' ? mod : (mod.default || mod);\n if (dead || !host.current) return;\n const chart = echarts.init(host.current, null, { renderer });\n inst.current = chart;\n const { option: opt, notMerge: nm, onInit: cb } = latest.current;\n if (opt) { applyOption(chart, opt, nm); applied.current = opt; }\n if (cb) cb(chart);\n } catch {\n if (!dead) setFailed(true); // no chart code: say so, never draw a fake one\n }\n })();\n return () => {\n dead = true;\n try { inst.current?.dispose(); } catch { /* already gone with the DOM */ }\n inst.current = null;\n applied.current = null;\n };\n }, [renderer]);\n\n // `applied` keeps this from redrawing the option the init above just drew — the instance\n // arrives asynchronously, so both paths run on the first render that has one.\n useEffect(() => {\n if (!inst.current || !option || applied.current === option) return;\n applyOption(inst.current, option, notMerge);\n applied.current = option;\n }, [option, notMerge]);\n\n useEffect(() => {\n const el = host.current;\n if (!el || typeof ResizeObserver !== 'function') return undefined;\n let frame = 0;\n const ro = new ResizeObserver(() => {\n // One resize per frame: a drag on a panel corner fires the observer on every pointer move.\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => inst.current?.resize());\n });\n ro.observe(el);\n return () => { cancelAnimationFrame(frame); ro.disconnect(); };\n }, []);\n\n if (failed) return <div className={['uic-chart', 'is-unavailable', className].filter(Boolean).join(' ')}>{fallback}</div>;\n return (\n <div\n ref={host}\n className={['uic-chart', className].filter(Boolean).join(' ')}\n role={label ? 'img' : undefined}\n aria-label={label}\n />\n );\n}\n","// An ECharts option can come from anywhere (a person, a saved dashboard, an agent writing it), so the chart keeps it\n// inert before ECharts sees it (found 2026-11-10). ECharts writes some option strings into the page as HTML or opens\n// them as URLs:\n// - a tooltip's content (its formatter, series and data names) in the default HTML render mode;\n// - a title's link / sublink and a sunburst or treemap node's link, opened in a window that keeps the page's origin;\n// - the data view's title and button labels (toolbox.feature.dataView.title / lang).\n// So every tooltip draws in the chart itself (renderMode 'richText': text, never markup), a link is kept only when it is\n// http(s) or mailto, and the data view's words are escaped. The option passed in is never changed: plain objects and\n// arrays are copied, anything else (functions, typed arrays, dates, gradient objects) is passed through as it is.\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:)/i;\n\nexport function safeHref(v) {\n return typeof v === 'string' && SAFE_HREF.test(v.replace(/[\\u0000- \\u007f]/g, '')) ? v : '';\n}\n\nconst ESC = { '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' };\nconst esc = (s) => String(s).replace(/[&<>\"']/g, (c) => ESC[c]);\n\nconst isPlain = (v) => {\n if (!v || typeof v !== 'object' || Array.isArray(v)) return false;\n const p = Object.getPrototypeOf(v);\n return p === Object.prototype || p === null;\n};\n\nexport function safeChartOption(option) {\n if (!isPlain(option) && !Array.isArray(option)) return option;\n const seen = new Map();\n const escaped = new Set();\n const walk = (n) => {\n if (Array.isArray(n)) {\n if (seen.has(n)) return seen.get(n);\n const out = []; seen.set(n, out);\n for (const x of n) out.push(walk(x));\n return out;\n }\n if (!isPlain(n)) return n;\n if (seen.has(n)) return seen.get(n);\n const out = {}; seen.set(n, out);\n for (const k of Object.keys(n)) {\n const v = n[k];\n if ((k === 'link' || k === 'sublink') && typeof v === 'string') {\n if (safeHref(v)) out[k] = v;\n } else if (k === 'tooltip') {\n out[k] = tooltip(v);\n } else if (k === 'dataView' && isPlain(v)) {\n out[k] = dataView(walk(v));\n } else {\n out[k] = walk(v);\n }\n }\n return out;\n };\n const tooltip = (v) => {\n if (v === true) return { renderMode: 'richText' };\n if (Array.isArray(v)) return v.map((t) => (isPlain(t) ? { ...walk(t), renderMode: 'richText' } : walk(t)));\n return isPlain(v) ? { ...walk(v), renderMode: 'richText' } : walk(v);\n };\n const dataView = (d) => {\n if (escaped.has(d)) return d; // the same data view reached twice: escape once\n escaped.add(d);\n if (typeof d.title === 'string') d.title = esc(d.title);\n if (Array.isArray(d.lang)) d.lang = d.lang.map((s) => (typeof s === 'string' ? esc(s) : s));\n return d;\n };\n return walk(option);\n}\n","// The theme, as values a chart library can use.\n//\n// A chart draws into a canvas, where CSS custom properties do not reach: series colours, axis\n// labels and tooltip chrome all arrive as strings in an option object. Without this, every app\n// hardcodes hex in its chart code and the charts are the one part of the product that does not\n// follow the theme. Reading the same --uic-* tokens the stylesheets read keeps them together.\n\n// Same policy as the `var(--uic-x, …)` fallbacks in the stylesheets: a host that never loaded a\n// token layer still gets the library's own light palette rather than whatever the chart library\n// defaults to. Values are themes/light.css verbatim.\nconst FALLBACK = {\n cat: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948'],\n ink: '#111317', ink2: '#3A3D45', mute: '#5B5D66',\n line: '#DDDFE6', lineSoft: '#EFF1F4', surface: '#FFFFFF',\n brand: '#285AFF', ok: '#16a34a', warn: '#F59E0B', bad: '#b91c1c',\n font: 'inherit',\n};\n\nfunction read(style, name, fallback) {\n const v = style.getPropertyValue(name).trim();\n return v || fallback;\n}\n\n/**\n * Resolve the chart tokens in effect for `el` — pass the element the chart lives in, so a panel\n * inside a dark region resolves the dark values even when the page is light.\n *\n * `palette` is a categorical scale: assign it IN ORDER, one colour per series, and never cycle\n * it. Past eight series, colour has stopped being an encoding — fold the tail into one \"other\"\n * series or split the chart. On a light surface three of the eight sit below 3:1 against white,\n * so identity must not rest on colour alone: keep the legend, or label the series directly.\n */\nexport function chartTokens(el) {\n const target = (el && el.nodeType === 1 ? el : null)\n || (typeof document !== 'undefined' ? document.documentElement : null);\n if (!target || typeof getComputedStyle !== 'function') return { ...FALLBACK, palette: FALLBACK.cat };\n const s = getComputedStyle(target);\n return {\n palette: FALLBACK.cat.map((hex, i) => read(s, `--uic-cat-${i + 1}`, hex)),\n ink: read(s, '--uic-ink', FALLBACK.ink),\n ink2: read(s, '--uic-ink-2', FALLBACK.ink2),\n mute: read(s, '--uic-mute', FALLBACK.mute),\n line: read(s, '--uic-line', FALLBACK.line),\n lineSoft: read(s, '--uic-line-soft', FALLBACK.lineSoft),\n surface: read(s, '--uic-surface', FALLBACK.surface),\n brand: read(s, '--uic-brand', FALLBACK.brand),\n ok: read(s, '--uic-ok', FALLBACK.ok),\n warn: read(s, '--uic-warn', FALLBACK.warn),\n bad: read(s, '--uic-fail-ink', FALLBACK.bad),\n font: read(s, '--uic-font', FALLBACK.font),\n };\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { chartTokens } from './tokens.js';\n\n/**\n * chartTokens(), re-read when the theme changes.\n *\n * A chart's colours are baked into its option at build time, so flipping light↔dark leaves every\n * chart on the page painted for the theme that is gone until something re-renders it. There is no\n * event for \"the tokens changed\", so this watches the two things that change them: the attributes\n * a theme is switched with (a class or data-* on <html>/<body>), and the OS preference.\n *\n * Returns [tokens, ref] — put the ref on the element the chart lives in, or leave it unused and\n * the document's own tokens are read.\n */\nexport function useChartTokens() {\n const ref = useRef(null);\n const [tokens, setTokens] = useState(() => chartTokens(null));\n const reread = useCallback(() => setTokens(chartTokens(ref.current)), []);\n\n useEffect(() => {\n reread();\n if (typeof MutationObserver !== 'function') return undefined;\n const obs = new MutationObserver(reread);\n const opts = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };\n obs.observe(document.documentElement, opts);\n if (document.body) obs.observe(document.body, opts);\n const mq = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;\n mq?.addEventListener?.('change', reread);\n return () => { obs.disconnect(); mq?.removeEventListener?.('change', reread); };\n }, [reread]);\n\n return [tokens, ref];\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,SAAS,MAAM,IAAI;AAClD,UAAM,KAAK,OAAO,eAAe,aAAa,WAAW,8BAA8B,IAAI;AAC3F,QAAI,mBAAmB,UAAU,MAAM;AACvC,WAAO,MAAM;AAAE,UAAI,WAAW;AAAG,UAAI,sBAAsB,UAAU,MAAM;AAAA,IAAG;AAAA,EAChF,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,CAAC,QAAQ,GAAG;AACrB;","names":["out","useEffect","useRef","useState","useRef","useState","useEffect"]}
|
package/dist/slides.cjs
CHANGED
|
@@ -45,6 +45,25 @@ var import_react2 = require("react");
|
|
|
45
45
|
// src/slides/elements.jsx
|
|
46
46
|
var import_react = require("react");
|
|
47
47
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
|
+
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
49
|
+
function safeHref(v) {
|
|
50
|
+
return typeof v === "string" && SAFE_HREF.test(v.replace(/[\u0000-\u0020\u007f]/g, "")) ? v : "";
|
|
51
|
+
}
|
|
52
|
+
function safeChartSpec(spec) {
|
|
53
|
+
const out = JSON.parse(JSON.stringify(spec));
|
|
54
|
+
const walk = (n) => {
|
|
55
|
+
if (Array.isArray(n)) {
|
|
56
|
+
n.forEach(walk);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!n || typeof n !== "object") return;
|
|
60
|
+
for (const k of ["link", "sublink"]) if (k in n && !safeHref(n[k])) delete n[k];
|
|
61
|
+
Object.values(n).forEach(walk);
|
|
62
|
+
};
|
|
63
|
+
walk(out);
|
|
64
|
+
for (const t of [].concat(out.tooltip || [])) if (t && typeof t === "object") t.renderMode = "richText";
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
48
67
|
var ROLE_STYLE = {
|
|
49
68
|
title: { fontSize: 72, fontWeight: 800, lineHeight: 1.1, fontFamily: "var(--sl-head)" },
|
|
50
69
|
subtitle: { fontSize: 36, fontWeight: 500, lineHeight: 1.25, color: "var(--sl-mute)" },
|
|
@@ -66,8 +85,8 @@ function runSpans(runs) {
|
|
|
66
85
|
style.padding = "0 6px";
|
|
67
86
|
style.borderRadius = 4;
|
|
68
87
|
}
|
|
69
|
-
const link = (r.marks || []).find((m) => typeof m === "object" && m.link);
|
|
70
|
-
if (link) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: link.link, style: { ...style, color: "var(--sl-brand)" }, children: node }, i);
|
|
88
|
+
const link = (r.marks || []).find((m) => typeof m === "object" && safeHref(m.link));
|
|
89
|
+
if (link) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: safeHref(link.link), style: { ...style, color: "var(--sl-brand)" }, children: node }, i);
|
|
71
90
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style, children: node }, i);
|
|
72
91
|
});
|
|
73
92
|
}
|
|
@@ -121,7 +140,7 @@ function ChartEl({ el }) {
|
|
|
121
140
|
const echarts = (await import("echarts")).default || await import("echarts");
|
|
122
141
|
if (dead || !ref.current) return;
|
|
123
142
|
chart = echarts.init(ref.current, null, { renderer: "svg" });
|
|
124
|
-
if (el.content?.spec) chart.setOption(el.content.spec);
|
|
143
|
+
if (el.content?.spec) chart.setOption(safeChartSpec(el.content.spec));
|
|
125
144
|
} catch {
|
|
126
145
|
}
|
|
127
146
|
})();
|
|
@@ -232,12 +251,16 @@ function CodeEl({ el }) {
|
|
|
232
251
|
background: "#0B1020"
|
|
233
252
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { ref, className: `language-${el.content?.lang || "plaintext"}` }) });
|
|
234
253
|
}
|
|
254
|
+
var EMBED_POLICY = `<meta http-equiv="Content-Security-Policy" content="default-src https: data:; style-src 'unsafe-inline' https: data:; script-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'"><style>html,body{margin:0;padding:0;background:transparent;overflow:hidden}</style>`;
|
|
235
255
|
function EmbedEl({ el }) {
|
|
236
256
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
237
|
-
"
|
|
257
|
+
"iframe",
|
|
238
258
|
{
|
|
239
|
-
|
|
240
|
-
|
|
259
|
+
title: "Embedded content",
|
|
260
|
+
sandbox: "",
|
|
261
|
+
referrerPolicy: "no-referrer",
|
|
262
|
+
srcDoc: EMBED_POLICY + (el.content?.html || ""),
|
|
263
|
+
style: { border: 0, width: "100%", height: "100%", display: "block", pointerEvents: "none" }
|
|
241
264
|
}
|
|
242
265
|
);
|
|
243
266
|
}
|