Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,48 @@
|
||||
// Generated, do not edit. sha256:ee03300e55aca9bafacba37ec01daf41bd49c8f2f20ec64a315107a3b816d0b3
|
||||
let chartingPromise = null;
|
||||
|
||||
export function loadCharting(libs, { failed = (src) => `Cannot load ${src}.` } = {}) {
|
||||
if (chartingPromise) return chartingPromise;
|
||||
const c = libs;
|
||||
const addScript = src => new Promise((resolve, reject) => {
|
||||
const s = document.createElement('script');
|
||||
s.src = src; s.async = false;
|
||||
s.onload = resolve; s.onerror = () => reject(new Error(failed(src)));
|
||||
document.head.appendChild(s);
|
||||
});
|
||||
chartingPromise = (async () => {
|
||||
if (!window.Chart) await addScript(c.CHARTJS);
|
||||
if (!window.Hammer) await addScript(c.HAMMER);
|
||||
await addScript(c.ZOOM);
|
||||
return window.Chart;
|
||||
})();
|
||||
chartingPromise.catch(() => { chartingPromise = null; });
|
||||
return chartingPromise;
|
||||
}
|
||||
|
||||
export function hexToRgb(hex) {
|
||||
const s = String(hex || '').trim().replace(/^#/, '');
|
||||
const full = s.length === 3 ? s.split('').map(c => c + c).join('') : s;
|
||||
if (!/^[0-9a-fA-F]{6}$/.test(full)) return null;
|
||||
return { r: parseInt(full.slice(0, 2), 16), g: parseInt(full.slice(2, 4), 16), b: parseInt(full.slice(4, 6), 16) };
|
||||
}
|
||||
|
||||
export function tintSeries(hex, count, { min = 0.28, max = 1 } = {}) {
|
||||
const n = Math.max(0, Math.floor(count) || 0);
|
||||
if (n === 0) return [];
|
||||
const rgb = hexToRgb(hex) || { r: 128, g: 128, b: 128 };
|
||||
const step = n === 1 ? 0 : (max - min) / (n - 1);
|
||||
return Array.from({ length: n }, (_, i) => `rgba(${rgb.r},${rgb.g},${rgb.b},${Math.round((max - i * step) * 1000) / 1000})`);
|
||||
}
|
||||
|
||||
export function readPalette() {
|
||||
const cs = getComputedStyle(document.documentElement);
|
||||
const v = n => cs.getPropertyValue(n).trim();
|
||||
const accent = v('--accent');
|
||||
return {
|
||||
text: v('--text-primary'), textSec: v('--text-sec'), textTer: v('--text-ter'), grid: v('--border'),
|
||||
accent, accentSoft: v('--accent-soft'), pos: v('--pos'), neg: v('--neg'), surface: v('--bg-elevated'),
|
||||
tooltipBg: v('--bg-overlay'), borderMid: v('--border-mid'),
|
||||
series: (n) => tintSeries(accent, n, { min: 0.45 }),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user