winbox-ui-next
Version:
We Design Vue 2.0: A Vue.js 3 UI Library
110 lines (109 loc) • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports[Symbol.toStringTag] = "Module";
var seemly = require("seemly");
function deriveDefaultValue(modes, showAlpha) {
const mode = modes[0];
switch (mode) {
case "hex":
return showAlpha ? "#2055f4FF" : "#2055f4";
case "rgb":
return showAlpha ? "rgba(32, 85, 244, 1)" : "rgb(32, 85, 244)";
case "hsl":
return showAlpha ? "hsla(255, 91%, 54%, 1)" : "hsl(255, 91%, 54%)";
case "hsv":
return showAlpha ? "hsva(0, 0%, 0%, 1)" : "hsv(0, 0%, 0%)";
}
return "##2055f4";
}
function getModeFromValue(color) {
if (color === null)
return null;
if (/^ *#/.test(color))
return "hex";
if (color.includes("rgb"))
return "rgb";
if (color.includes("hsl"))
return "hsl";
if (color.includes("hsv"))
return "hsv";
return null;
}
function normalizeHue(hue) {
hue = Math.round(hue);
return hue >= 360 ? 359 : hue < 0 ? 0 : hue;
}
function normalizeAlpha(alpha) {
alpha = Math.round(alpha * 100) / 100;
return alpha > 1 ? 1 : alpha < 0 ? 0 : alpha;
}
const convert = {
rgb: {
hex(value) {
return seemly.toHexaString(seemly.rgba(value));
},
hsl(value) {
const [r, g, b, a] = seemly.rgba(value);
return seemly.toHslaString([...seemly.rgb2hsl(r, g, b), a]);
},
hsv(value) {
const [r, g, b, a] = seemly.rgba(value);
return seemly.toHsvaString([...seemly.rgb2hsv(r, g, b), a]);
}
},
hex: {
rgb(value) {
return seemly.toRgbaString(seemly.rgba(value));
},
hsl(value) {
const [r, g, b, a] = seemly.rgba(value);
return seemly.toHslaString([...seemly.rgb2hsl(r, g, b), a]);
},
hsv(value) {
const [r, g, b, a] = seemly.rgba(value);
return seemly.toHsvaString([...seemly.rgb2hsv(r, g, b), a]);
}
},
hsl: {
hex(value) {
const [h, s, l, a] = seemly.hsla(value);
return seemly.toHexaString([...seemly.hsl2rgb(h, s, l), a]);
},
rgb(value) {
const [h, s, l, a] = seemly.hsla(value);
return seemly.toRgbaString([...seemly.hsl2rgb(h, s, l), a]);
},
hsv(value) {
const [h, s, l, a] = seemly.hsla(value);
return seemly.toHsvaString([...seemly.hsl2hsv(h, s, l), a]);
}
},
hsv: {
hex(value) {
const [h, s, v, a] = seemly.hsva(value);
return seemly.toHexaString([...seemly.hsv2rgb(h, s, v), a]);
},
rgb(value) {
const [h, s, v, a] = seemly.hsva(value);
return seemly.toRgbaString([...seemly.hsv2rgb(h, s, v), a]);
},
hsl(value) {
const [h, s, v, a] = seemly.hsva(value);
return seemly.toHslaString([...seemly.hsv2hsl(h, s, v), a]);
}
}
};
function convertColor(value, mode, originalMode) {
originalMode = originalMode || getModeFromValue(value);
if (!originalMode)
return null;
if (originalMode === mode)
return value;
const conversions = convert[originalMode];
return conversions[mode](value);
}
exports.convertColor = convertColor;
exports.deriveDefaultValue = deriveDefaultValue;
exports.getModeFromValue = getModeFromValue;
exports.normalizeAlpha = normalizeAlpha;
exports.normalizeHue = normalizeHue;