UNPKG

antd-color-editor

Version:

An open-source color editor for designing color system

76 lines (74 loc) 2.98 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/utils/colorUtils.ts var colorUtils_exports = {}; __export(colorUtils_exports, { hctToHex: () => hctToHex, hexToHct: () => hexToHct, toCtsString: () => toCtsString, toHctString: () => toHctString }); module.exports = __toCommonJS(colorUtils_exports); var import_material_color_utilities = require("@material/material-color-utilities"); var import_chroma_js = __toESM(require("chroma-js")); var hexToHct = (hex) => { const hclColor = import_material_color_utilities.Hct.fromInt((0, import_material_color_utilities.argbFromHex)(hex)); return [hclColor.hue, hclColor.chroma, hclColor.tone]; }; var hctToHex = (hct) => { const hctColor = import_material_color_utilities.Hct.from(hct[0], hct[1], hct[2]); return (0, import_material_color_utilities.hexFromArgb)(hctColor.toInt()); }; var toHctString = (hex, alpha) => { if (alpha) { const [r, g, b, a] = (0, import_chroma_js.default)(hex).rgba(); const newHex = import_chroma_js.default.rgb(r, g, b).hex(); const hctColor = hexToHct(newHex); return `hcta(${hctColor.map((c) => Math.round(c)).join(",")},${a})`; } else { const hctColor = hexToHct(hex); return `hct(${hctColor.map((c) => Math.round(c)).join(",")})`; } }; var toCtsString = (color1, color2, alpha) => { let text; if (alpha) { text = "cts(--)"; } else { text = import_chroma_js.default.contrast(color1, color2).toFixed(2); text = "cts(" + text + ")"; } return text; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { hctToHex, hexToHct, toCtsString, toHctString });