@wil-works/evoke-charts 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ import { y as CHART_PALETTES } from "./schema-CM4hKlpc.js";
2
+ //#region src/motion.js
3
+ /**
4
+ * 系统级「减弱动态效果」是否开启
5
+ * 命中时调用方应跳过进场 / 补间 / 惯性,直接出终态图;
6
+ * SSR 或无 matchMedia 的老环境按「不减弱」处理,绝不抛错。
7
+ */
8
+ function prefersReducedMotion() {
9
+ try {
10
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
11
+ return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ /**
17
+ * 分段错峰:把全局 progress 映射为第 index 个条目的局部 progress
18
+ *
19
+ * count 个条目里,第 index 个从 stagger * index/(count-1) 处起步,所有条目都在
20
+ * progress = 1 时收齐;stagger = 0(或 count = 1)即全部同步,返回原 progress。
21
+ * 局部进度自带 1/(1-stagger) 的压缩,条目越多、错峰越均匀。
22
+ */
23
+ function staggerProgress(progress, index, count, stagger) {
24
+ const p = Number.isFinite(progress) ? progress : 1;
25
+ const s = Number.isFinite(stagger) ? Math.max(0, Math.min(1, stagger)) : 0;
26
+ if (!(s > 0) || !(count > 1)) return p;
27
+ const start = s * ((Number.isFinite(index) ? Math.max(0, Math.min(count - 1, index)) : 0) / (count - 1));
28
+ return Math.max(0, Math.min(1, (p - start) / (1 - s)));
29
+ }
30
+ //#endregion
31
+ //#region \0plugin-vue:export-helper
32
+ var _plugin_vue_export_helper_default = (sfc, props) => {
33
+ const target = sfc.__vccOpts || sfc;
34
+ for (const [key, val] of props) target[key] = val;
35
+ return target;
36
+ };
37
+ var PALETTE_EVENT = "ev-theme-change";
38
+ var STYLE_ID = "data-ev-series-palette";
39
+ var paletteStyleEl = null;
40
+ function dispatchPaletteChange(dark) {
41
+ if (typeof document === "undefined") return;
42
+ const isDark = typeof dark === "boolean" ? dark : document.documentElement.classList.contains("dark");
43
+ document.documentElement.dispatchEvent(new CustomEvent(PALETTE_EVENT, {
44
+ bubbles: true,
45
+ detail: { dark: isDark }
46
+ }));
47
+ }
48
+ function removeInlineSlots() {
49
+ if (typeof document === "undefined") return;
50
+ for (let i = 1; i <= 8; i++) document.documentElement.style.removeProperty(`--ev-color-series-${i}`);
51
+ }
52
+ function ensurePaletteStyleEl() {
53
+ if (typeof document === "undefined") return null;
54
+ if (!paletteStyleEl || !paletteStyleEl.isConnected) {
55
+ paletteStyleEl = document.createElement("style");
56
+ paletteStyleEl.setAttribute(STYLE_ID, "");
57
+ document.head.appendChild(paletteStyleEl);
58
+ }
59
+ return paletteStyleEl;
60
+ }
61
+ function normalizeSlots(colors) {
62
+ const out = {};
63
+ if (!Array.isArray(colors)) return out;
64
+ colors.slice(0, 8).forEach((color, i) => {
65
+ if (color) out[`--ev-color-series-${i + 1}`] = color;
66
+ });
67
+ return out;
68
+ }
69
+ /**
70
+ * 应用一套数据色板
71
+ * @param {string | string[] | { light: string[], dark: string[] }} palette
72
+ * 色系 id:按内置注册表取色;数组:写入内联槽位(明暗共用);
73
+ * { light, dark }:注入样式表,随 html.dark 自动换挡
74
+ * @param {{ dark?: boolean, target?: HTMLElement }} [options]
75
+ * dark 手动指定当前暗色态(默认探测 html.dark);target 改写注入目标
76
+ * @returns {boolean} 是否写入成功
77
+ */
78
+ function applySeriesPalette(palette, options = {}) {
79
+ if (typeof document === "undefined") return false;
80
+ const el = options.target ?? document.documentElement;
81
+ if (!el || !palette) return false;
82
+ if (typeof palette === "string") {
83
+ const found = CHART_PALETTES.find((p) => p.id === palette);
84
+ if (!found) return false;
85
+ return applySeriesPalette((typeof options.dark === "boolean" ? options.dark : document.documentElement.classList.contains("dark")) ? found.dark : found.light, options);
86
+ }
87
+ if (Array.isArray(palette)) {
88
+ paletteStyleEl?.remove();
89
+ paletteStyleEl = null;
90
+ for (const [name, value] of Object.entries(normalizeSlots(palette))) el.style.setProperty(name, value);
91
+ dispatchPaletteChange(options.dark);
92
+ return true;
93
+ }
94
+ const { light, dark } = palette;
95
+ if (!Array.isArray(light) && !Array.isArray(dark)) return false;
96
+ removeInlineSlots();
97
+ const styleEl = ensurePaletteStyleEl();
98
+ if (styleEl) {
99
+ const vars = (colors) => colors.map((c, i) => `--ev-color-series-${i + 1}: ${c}`).join(";");
100
+ styleEl.textContent = `${light ? `:root { ${vars(light)}; }` : ""}${dark ? ` html.dark { ${vars(dark)}; }` : ""}`;
101
+ }
102
+ dispatchPaletteChange(options.dark);
103
+ return true;
104
+ }
105
+ /**
106
+ * 清除配色方案覆写(内联槽位 + 注入样式表),回到内置成套色板
107
+ */
108
+ function clearSeriesPalette(options = {}) {
109
+ if (typeof document === "undefined") return false;
110
+ paletteStyleEl?.remove();
111
+ paletteStyleEl = null;
112
+ removeInlineSlots();
113
+ dispatchPaletteChange(options.dark);
114
+ return true;
115
+ }
116
+ //#endregion
117
+ export { staggerProgress as a, prefersReducedMotion as i, clearSeriesPalette as n, _plugin_vue_export_helper_default as r, applySeriesPalette as t };