2023-02-17 11:06:01 +01:00

100 lines
3.9 KiB
JavaScript

(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../../../../Utils/Utils"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Shape = void 0;
const Utils_1 = require("../../../../Utils/Utils");
const charKey = "character", charAltKey = "char", imageKey = "image", imageAltKey = "images", polygonKey = "polygon", polygonAltKey = "star";
class Shape {
constructor() {
this.options = {};
this.type = "circle";
}
get character() {
var _a;
return ((_a = this.options[charKey]) !== null && _a !== void 0 ? _a : this.options[charAltKey]);
}
set character(value) {
this.options[charAltKey] = this.options[charKey] = value;
}
get custom() {
return this.options;
}
set custom(value) {
this.options = value;
}
get image() {
var _a;
return ((_a = this.options[imageKey]) !== null && _a !== void 0 ? _a : this.options[imageAltKey]);
}
set image(value) {
this.options[imageAltKey] = this.options[imageKey] = value;
}
get images() {
return this.image;
}
set images(value) {
this.image = value;
}
get polygon() {
var _a;
return ((_a = this.options[polygonKey]) !== null && _a !== void 0 ? _a : this.options[polygonAltKey]);
}
set polygon(value) {
this.options[polygonAltKey] = this.options[polygonKey] = value;
}
get stroke() {
return [];
}
set stroke(_value) {
}
load(data) {
var _a, _b, _c;
if (!data) {
return;
}
const options = (_a = data.options) !== null && _a !== void 0 ? _a : data.custom;
if (options !== undefined) {
for (const shape in options) {
const item = options[shape];
if (item) {
this.options[shape] = (0, Utils_1.deepExtend)((_b = this.options[shape]) !== null && _b !== void 0 ? _b : {}, item);
}
}
}
this.loadShape(data.character, charKey, charAltKey, true);
this.loadShape(data.polygon, polygonKey, polygonAltKey, false);
this.loadShape((_c = data.image) !== null && _c !== void 0 ? _c : data.images, imageKey, imageAltKey, true);
if (data.type !== undefined) {
this.type = data.type;
}
}
loadShape(item, mainKey, altKey, altOverride) {
var _a, _b;
if (!item) {
return;
}
const isArray = item instanceof Array;
const emptyValue = isArray ? [] : {}, mainDifferentValues = isArray !== this.options[mainKey] instanceof Array, altDifferentValues = isArray !== this.options[altKey] instanceof Array;
if (mainDifferentValues) {
this.options[mainKey] = emptyValue;
}
if (altDifferentValues && altOverride) {
this.options[altKey] = emptyValue;
}
this.options[mainKey] = (0, Utils_1.deepExtend)((_a = this.options[mainKey]) !== null && _a !== void 0 ? _a : emptyValue, item);
if (!this.options[altKey] || altOverride) {
this.options[altKey] = (0, Utils_1.deepExtend)((_b = this.options[altKey]) !== null && _b !== void 0 ? _b : emptyValue, item);
}
}
}
exports.Shape = Shape;
});