UNPKG

color-math

Version:
77 lines (62 loc) 2.35 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } import cloneDeepWith from 'lodash.clonedeepwith'; import * as Utils from '../utils'; import Loc from './Loc'; import ColorScale from '../ColorScale'; var Node = /*#__PURE__*/ function () { function Node($type, $loc) { _classCallCheck(this, Node); this.$type = $type; if ($loc) { this.$loc = $loc instanceof Loc ? $loc : new Loc($loc); } } _createClass(Node, [{ key: "getDto", value: function getDto() { var _this = this; var withLoc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; var dto = cloneDeepWith(this, function (obj) { if (obj !== _this) { if (obj instanceof Node) { return obj.getDto(withLoc); } else if (obj instanceof Loc) { return _this.$loc.toString(); } else if (Utils.isColor(obj)) { return Utils.formatColor(obj); } else if (obj instanceof ColorScale) { return String(obj); } } }); if (!withLoc) { delete dto.$loc; } return dto; } }, { key: "evaluate", value: function evaluate(e) { //if (this.$eval === void 0) { var value = this._evaluateInternal(e); if (value == null) { Utils.throwError("evaluation of '".concat(this.$type, "' is not supported by '").concat(e.$type, "'"), this.$loc); } this.$eval = value; //} return this.$eval; } }, { key: "_evaluateInternal", value: function _evaluateInternal() /*evaluator*/ { throw new Error('Not implemented'); } }]); return Node; }(); export { Node as default };