UNPKG

illustrator.js

Version:

JavaScript image processing library

43 lines (42 loc) 1.82 kB
"use strict"; var _LayerTools_toolsCache; Object.defineProperty(exports, "__esModule", { value: true }); exports.LayerTools = void 0; const tslib_1 = require("tslib"); const Tools = require("../toolbox/exports"); const IllustratorCollection_1 = require("../utils/IllustratorCollection"); class LayerTools { constructor(layer) { this.layer = layer; _LayerTools_toolsCache.set(this, new IllustratorCollection_1.IllustratorCollection()); } clearCache() { tslib_1.__classPrivateFieldGet(this, _LayerTools_toolsCache, "f").clear(); } delete(name) { return tslib_1.__classPrivateFieldGet(this, _LayerTools_toolsCache, "f").delete(name); } isCached(name) { return tslib_1.__classPrivateFieldGet(this, _LayerTools_toolsCache, "f").has(name); } get(nameOrConfig, cache) { const name = typeof nameOrConfig === "string" ? nameOrConfig : nameOrConfig.name; const shouldCache = !!(typeof nameOrConfig === "object" ? nameOrConfig.cache : cache); if (typeof name !== "string" || !name) throw new TypeError(`tool name must be a string, received ${typeof name}`); if (!shouldCache && tslib_1.__classPrivateFieldGet(this, _LayerTools_toolsCache, "f").has(name)) return tslib_1.__classPrivateFieldGet(this, _LayerTools_toolsCache, "f").get(name); if (!Tools[name]) throw new Error(`Unknown tool ${name}`); const toolConstructor = Tools[name]; const tool = new toolConstructor(this.layer); if (shouldCache) tslib_1.__classPrivateFieldGet(this, _LayerTools_toolsCache, "f").set(name, tool); return tool; } isValidTool(name) { return name in Tools; } } exports.LayerTools = LayerTools; _LayerTools_toolsCache = new WeakMap();