UNPKG

@aurigma/design-atoms-model

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

58 lines 2.12 kB
import { ArgumentException } from "../Exception"; import * as Utils from "../Utils/Utils"; export class Color { constructor(value) { this._previewFromServer = false; this.preview = null; this.profileId = null; if (value == null) return; if (!Utils.isNullOrEmptyOrWhiteSpace(value.preview)) this._previewFromServer = true; if (typeof value != "string") this._init(value); } get previewFromServer() { return this._previewFromServer; } needUpdate(defaultRgbProfileId) { const isRgb = this.type === "RgbColor"; const isNonDefaultRgb = isRgb && this.profileId != null && this.profileId !== defaultRgbProfileId; return (!isRgb || isNonDefaultRgb) && !this.previewFromServer; } equals(color, ignorePreview = false) { return color.profileId === this.profileId && (ignorePreview || color.preview === this.preview); } getData() { const data = { preview: this.preview, profileId: this.profileId, type: this.type }; return data; } _init(colorObject) { if (!Utils.isNullOrEmptyOrWhiteSpace(colorObject.preview)) this.preview = colorObject.preview; if (!Utils.isNullOrEmptyOrWhiteSpace(colorObject.profileId)) this.profileId = colorObject.profileId; } _validateString(value) { if (Utils.isNullOrEmptyOrWhiteSpace(value)) throw new ArgumentException(`Value must be a non-empty string`); } _validateNumber(value, min = 0, max = 255) { if (typeof value != "number") throw new ArgumentException("Value must be a number"); if (value < min || value > max) throw new ArgumentException(`Value must be in range [${min}, ${max}]`); } static equals(a, b) { if (a == null && b == null) return true; if (a != null) return a.equals(b); return false; } } //# sourceMappingURL=Color.js.map