UNPKG

illustrator.js

Version:

JavaScript image processing library

60 lines (59 loc) 2.7 kB
"use strict"; var _IllustratorColor_instances, _IllustratorColor_data, _IllustratorColor_parse; Object.defineProperty(exports, "__esModule", { value: true }); exports.IllustratorColor = void 0; const tslib_1 = require("tslib"); class IllustratorColor { constructor(swatches, data) { this.swatches = swatches; this.data = data; _IllustratorColor_instances.add(this); _IllustratorColor_data.set(this, void 0); tslib_1.__classPrivateFieldGet(this, _IllustratorColor_instances, "m", _IllustratorColor_parse).call(this, data.color); } hex() { return tslib_1.__classPrivateFieldGet(this, _IllustratorColor_data, "f").hex.padStart(6, "0"); } int() { return tslib_1.__classPrivateFieldGet(this, _IllustratorColor_data, "f").int; } rgba() { return `rgba(${tslib_1.__classPrivateFieldGet(this, _IllustratorColor_data, "f").rgba.slice(0, 4).join(", ")})`; } rgb() { return `rgb(${tslib_1.__classPrivateFieldGet(this, _IllustratorColor_data, "f").rgba.slice(0, 3).join(", ")})`; } get name() { return this.data.name; } } exports.IllustratorColor = IllustratorColor; _IllustratorColor_data = new WeakMap(), _IllustratorColor_instances = new WeakSet(), _IllustratorColor_parse = function _IllustratorColor_parse(color) { void color; throw new Error("Not implemented"); // if (typeof color === "string") { // if (["rgb(", "rgba(", "cmyk(", "hsl(", "hsla("].some(pattern => color.indexOf(pattern) === 0)) { // if (color.startsWith("rgb(") || color.startsWith("rgba(")) { // const points = color.split(",").map(m => { // let val = m.trim(); // if (val.includes("%")) val = `0.${val.replace("%", "")}`; // return parseFloat(val); // }).slice(0, 4); // this.#data.rgba = points; // this.#data.hex = `#${(points[0] << 16 + points[1] << 8 + points[2]).toString(16).toUpperCase()}`; // if (points[3]) { // const alpha = (255 + 0x10000).toString(16).substring(-2).toUpperCase(); // this.#data.hex += alpha; // } // this.#data.int = parseInt(this.#data.hex.replace("#", ""), 16); // } // else if (color.startsWith("hsl(") || color.startsWith("hsla(")) { } // else { } // } // } else if (Array.isArray(color)) { // } else if (typeof color === "number") { // this.#data.int = color; // const hex = color.toString(16); // this.#data.hex = `#${hex.padStart(6, "0")}`; // } };