@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.
121 lines • 5.91 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Exception } from "../../Exception";
import { EffectParameters } from "./NDEffectParameters";
import { Collection } from "../../Collection";
import { ColorDictionaryEntry } from "./ColorDictionaryEntry";
var RecolorEffectParameters = /** @class */ (function (_super) {
__extends(RecolorEffectParameters, _super);
function RecolorEffectParameters() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.defaultColorReplacements = new Map();
_this.currentColorReplacements = new Map();
return _this;
}
Object.defineProperty(RecolorEffectParameters.prototype, "defaultColorReplacementValues", {
get: function () {
return Array.from(this.defaultColorReplacements.values());
},
enumerable: true,
configurable: true
});
Object.defineProperty(RecolorEffectParameters.prototype, "defaultColorReplacementKeys", {
get: function () {
return Array.from(this.defaultColorReplacements.keys());
},
enumerable: true,
configurable: true
});
Object.defineProperty(RecolorEffectParameters.prototype, "currentColorReplacementValues", {
get: function () {
return Array.from(this.currentColorReplacements.values());
},
enumerable: true,
configurable: true
});
Object.defineProperty(RecolorEffectParameters.prototype, "currentColorReplacementKeys", {
get: function () {
return Array.from(this.currentColorReplacements.keys());
},
enumerable: true,
configurable: true
});
RecolorEffectParameters.prototype.setReplacementColor = function (color, index) {
var keyColor = this.currentColorReplacementValues[index];
if (keyColor != null) {
this.currentColorReplacements.set(keyColor, color);
}
else {
throw new Exception("Key with index: " + index + " not found in colorReplacementDictionary!");
}
};
RecolorEffectParameters.prototype.equals = function (recolorParams) {
var _this = this;
var _a;
if (recolorParams == null)
return false;
var replacementKeysIsEqual = recolorParams.currentColorReplacementKeys.every(function (color, index) {
return color.equals(_this.currentColorReplacementKeys[index]);
});
var replacementValueIsEqual = recolorParams.currentColorReplacementValues.every(function (color, index) {
return color.equals(_this.currentColorReplacementValues[index]);
});
var defaultKeysIsEqual = recolorParams.defaultColorReplacementKeys.every(function (color, index) { return color.equals(_this.defaultColorReplacementKeys[index]); });
var defaultValuesIsEqual = recolorParams.defaultColorReplacementValues.every(function (color, index) {
return color.equals(_this.defaultColorReplacementValues[index]);
});
var reducedColorImageSourceIsEqual = (_a = this.reducedColorImageSource) === null || _a === void 0 ? void 0 : _a.equals(recolorParams.reducedColorImageSource);
return (replacementKeysIsEqual &&
replacementValueIsEqual &&
defaultKeysIsEqual &&
defaultValuesIsEqual &&
reducedColorImageSourceIsEqual);
};
RecolorEffectParameters.prototype.toJSON = function () {
var _a;
return {
defaultColorReplacements: this._dictionaryToEntriesJSON(this.defaultColorReplacements),
currentColorReplacements: this._dictionaryToEntriesJSON(this.currentColorReplacements),
reducedColorImageSource: (_a = this.reducedColorImageSource) === null || _a === void 0 ? void 0 : _a.toJSON(),
};
};
RecolorEffectParameters.prototype._dictionaryToEntriesJSON = function (dictionary) {
var result = new Collection();
dictionary.forEach(function (value, key) {
return result.add(new ColorDictionaryEntry(key, value));
});
return result;
};
RecolorEffectParameters.prototype.clone = function () {
var _a;
var recolorEffectParameters = new RecolorEffectParameters();
var defaultColorReplacementDictionary = new Map();
this.defaultColorReplacements.forEach(function (key, color) {
return defaultColorReplacementDictionary.set(key.clone(), color.clone());
});
var colorReplacementDictionary = new Map();
this.currentColorReplacements.forEach(function (key, color) {
return colorReplacementDictionary.set(key.clone(), color.clone());
});
recolorEffectParameters.currentColorReplacements =
defaultColorReplacementDictionary;
recolorEffectParameters.currentColorReplacements =
colorReplacementDictionary;
recolorEffectParameters.reducedColorImageSource = (_a = this.reducedColorImageSource) === null || _a === void 0 ? void 0 : _a.clone();
return recolorEffectParameters;
};
return RecolorEffectParameters;
}(EffectParameters));
export { RecolorEffectParameters };
//# sourceMappingURL=RecolorEffectParameters.js.map