Urara-Blog/node_modules/.pnpm-store/v3/files/2b/d33bf760f46a3a0240db1a14779d802108c89cdbaf1b5a0d33df0163f177717ebef6d24c185c8695cca6e15120a72cea45b2c878c3e74555c1039d3f71258b
2022-08-14 01:14:53 +08:00

72 lines
2.1 KiB
Text

import { theme, rules, shortcuts, variants } from '@unocss/preset-wind';
import { preflights } from '@unocss/preset-mini';
import { parseCssColor, colorToString } from '@unocss/preset-mini/utils';
const mixComponent = (v1, v2, w) => `calc(${v2} + (${v1} - ${v2}) * ${w} / 100)`;
const mixColor = (color1, color2, weight) => {
const colors = [color1, color2];
const cssColors = [];
for (let c = 0; c < 2; ++c) {
const color = typeof colors[c] === "string" ? parseCssColor(colors[c]) : colors[c];
if (!color || !["rgb", "rgba"].includes(color.type))
return;
cssColors.push(color);
}
const newComponents = [];
for (let x = 0; x < 3; ++x)
newComponents.push(mixComponent(cssColors[0].components[x], cssColors[1].components[x], weight));
return {
type: "rgb",
components: newComponents,
alpha: mixComponent(cssColors[0].alpha ?? 1, cssColors[1].alpha ?? 1, weight)
};
};
const tint = (color, weight) => mixColor("#fff", color, weight);
const shade = (color, weight) => mixColor("#000", color, weight);
const shift = (color, weight) => {
const num = parseFloat(`${weight}`);
if (!Number.isNaN(num))
return num > 0 ? shade(color, weight) : tint(color, -num);
};
const fns = { tint, shade, shift };
const variantColorMix = (matcher) => {
const m = matcher.match(/^mix-(tint|shade|shift)-(-?\d{1,3})[-:]/);
if (m) {
return {
matcher: matcher.slice(m[0].length),
body: (body) => {
body.forEach((v) => {
if (v[1]) {
const color = parseCssColor(`${v[1]}`);
if (color) {
const mixed = fns[m[1]](color, m[2]);
if (mixed)
v[1] = colorToString(mixed);
}
}
});
return body;
}
};
}
};
const presetUno = (options = {}) => {
options.dark = options.dark ?? "class";
options.attributifyPseudo = options.attributifyPseudo ?? false;
return {
name: "@unocss/preset-uno",
theme,
rules,
shortcuts,
variants: [
...variants(options),
variantColorMix
],
options,
preflights,
prefix: options.prefix
};
};
export { presetUno as default, presetUno };