donut-theme-plugin
Version:
a vue3 plugin-adapter for element-plus theme-chalk by js-object
24 lines (23 loc) • 1.13 kB
JavaScript
const y = (s) => typeof s == "object" && s !== null, a = (s, n, t) => {
t = Math.max(Math.min(Number(t), 1), 0);
const c = parseInt(s.substring(1, 3), 16), r = parseInt(s.substring(3, 5), 16), e = parseInt(s.substring(5, 7), 16), b = parseInt(n.substring(1, 3), 16), o = parseInt(n.substring(3, 5), 16), u = parseInt(n.substring(5, 7), 16), l = Math.round(c * (1 - t) + b * t), m = Math.round(r * (1 - t) + o * t), f = Math.round(e * (1 - t) + u * t), $ = `0${(l || 0).toString(16)}`.slice(-2), g = `0${(m || 0).toString(16)}`.slice(-2), p = `0${(f || 0).toString(16)}`.slice(-2);
return `#${$}${g}${p}`;
}, i = Symbol(), d = (s, n) => {
if (n && y(n)) {
s.provide(i, n);
const t = document.documentElement;
Object.keys(n).forEach((c) => {
const r = `--el-color-${c}`, e = n[c];
t.style.setProperty(r, e), [3, 5, 7, 8, 9].forEach((o) => {
const u = a(e, "#ffffff", o / 10);
t.style.setProperty(`${r}-light-${o}`, u);
});
const b = a(e, "#000000", 0.2);
t.style.setProperty(`${r}-dark-2`, b);
});
}
};
export {
i as ThemeInjectKey,
d as ThemePlugin
};