UNPKG

illustrator.js

Version:

JavaScript image processing library

58 lines (57 loc) 2.23 kB
"use strict"; var _ColorSwatches_data; Object.defineProperty(exports, "__esModule", { value: true }); exports.ColorSwatches = void 0; const tslib_1 = require("tslib"); const IllustratorCollection_1 = require("../utils/IllustratorCollection"); const IllustratorColor_1 = require("./IllustratorColor"); class ColorSwatches { constructor() { _ColorSwatches_data.set(this, new IllustratorCollection_1.IllustratorCollection()); } add(data) { if (!data.name || typeof data.name !== "string") throw new TypeError("name is required"); if (!data.color || typeof data.color !== "string") throw new TypeError("color is required"); data.force ?? (data.force = false); if (tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").has(data.name) && !data.force) return false; const color = new IllustratorColor_1.IllustratorColor(this, data); tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").set(data.name, color); return color; } remove(name) { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").delete(name); } get(name) { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").get(name); } has(name) { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").has(name); } clear() { tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").clear(); } count() { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").size; } random(amount) { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").random(amount); } names() { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").map((m) => m.name); } toArray() { return tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f").array(); } toJSON() { const data = {}; for (const [name, color] of tslib_1.__classPrivateFieldGet(this, _ColorSwatches_data, "f")) { data[name] = color; } return data; } } exports.ColorSwatches = ColorSwatches; _ColorSwatches_data = new WeakMap();