@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.
196 lines • 8.41 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 { ModelComponent } from "./ModelComponent";
import { RectangleF } from "../Math/RectangleF";
import { Collection } from "../Collection";
import { Margin } from "../Math/Margin";
import { PrintAreaBoundsType } from "./PrintAreaBoundsType";
import { ArgumentException } from "../Exception";
import { equals } from "../Utils/Utils";
var PrintArea = /** @class */ (function (_super) {
__extends(PrintArea, _super);
function PrintArea(bounds, bleed, slug) {
var _this = _super.call(this) || this;
_this.parentSurface = null;
_this._safetyLines = new Collection();
_this._cropMarks = new Collection();
_this._onBoundsPropertyChanged = function (s, p) {
_this._propertyChanged.notify(_this, "bounds");
};
_this._onBleedPropertyChanged = function (s, p) {
_this._validateMargin(_this.bleed, "bleed");
_this._propertyChanged.notify(_this, "bleed");
};
_this._onSlugPropertyChanged = function (s, p) {
_this._validateMargin(_this.slug, "slug");
_this._propertyChanged.notify(_this, "slug");
};
_this._validateMargin(bleed, "bleed");
_this._validateMargin(slug, "slug");
_this._bounds = bounds !== null && bounds !== void 0 ? bounds : new RectangleF();
_this.bleed = bleed !== null && bleed !== void 0 ? bleed : new Margin();
_this.slug = slug !== null && slug !== void 0 ? slug : new Margin();
return _this;
}
Object.defineProperty(PrintArea.prototype, "bounds", {
//TODO next release
//private _background = new PrintAreaContainer();
//get background() {
// return this._background;
//}
//private _foreground = new PrintAreaContainer();`
//get foreground() {
// return this._foreground;
//}
get: function () {
return this._bounds;
},
set: function (value) {
if (this._bounds.equals(value))
return;
this._unsubscribeBoundsPropertyChanged();
this._bounds = value;
this._subscribeBoundsPropertyChanged();
this._propertyChanged.notify(this, "bounds");
},
enumerable: true,
configurable: true
});
Object.defineProperty(PrintArea.prototype, "safetyLines", {
get: function () {
return this._safetyLines;
},
set: function (value) {
if (this._safetyLines === value)
return;
this._safetyLines = value;
this._propertyChanged.notify(this, "safetyLines");
},
enumerable: true,
configurable: true
});
Object.defineProperty(PrintArea.prototype, "cropMarks", {
get: function () {
return this._cropMarks;
},
set: function (value) {
if (this._cropMarks === value)
return;
this._cropMarks = value;
this._propertyChanged.notify(this, "cropMarks");
},
enumerable: true,
configurable: true
});
Object.defineProperty(PrintArea.prototype, "bleed", {
get: function () {
return this._bleed;
},
set: function (value) {
if (equals(value, this._bleed))
return;
this._validateMargin(value, "bleed");
this._unsubscribeBleedPropertyChanged();
this._bleed = value;
this._subscribeBleedPropertyChanged();
this._propertyChanged.notify(this, "bleed");
},
enumerable: true,
configurable: true
});
Object.defineProperty(PrintArea.prototype, "slug", {
get: function () {
return this._slug;
},
set: function (value) {
if (equals(value, this._slug))
return;
this._validateMargin(value, "slug");
this._unsubscribeSlugPropertyChanged();
this._slug = value;
this._subscribeSlugPropertyChanged();
this._propertyChanged.notify(this, "slug");
},
enumerable: true,
configurable: true
});
PrintArea.prototype.getBounds = function (type) {
switch (type) {
case PrintAreaBoundsType.Bleed:
return this.bounds.getExpanded(this.bleed);
case PrintAreaBoundsType.Total:
return this.bounds.getExpanded(new Margin({
left: this.bleed.left + this.slug.left,
top: this.bleed.top + this.slug.top,
right: this.bleed.right + this.slug.right,
bottom: this.bleed.bottom + this.slug.bottom
}));
default:
return this.bounds.clone();
}
};
PrintArea.prototype._subscribeBoundsPropertyChanged = function () {
if (this._bounds != null)
this._bounds.addPropertyChanged(this._onBoundsPropertyChanged);
};
PrintArea.prototype._unsubscribeBoundsPropertyChanged = function () {
if (this._bounds != null)
this._bounds.removePropertyChanged(this._onBoundsPropertyChanged);
};
PrintArea.prototype._subscribeBleedPropertyChanged = function () {
if (this._bleed != null)
this._bleed.addPropertyChanged(this._onBleedPropertyChanged);
};
PrintArea.prototype._unsubscribeBleedPropertyChanged = function () {
if (this._bleed != null)
this._bleed.removePropertyChanged(this._onBleedPropertyChanged);
};
PrintArea.prototype._subscribeSlugPropertyChanged = function () {
if (this._slug != null)
this._slug.addPropertyChanged(this._onSlugPropertyChanged);
};
PrintArea.prototype._unsubscribeSlugPropertyChanged = function () {
if (this._slug != null)
this._slug.removePropertyChanged(this._onSlugPropertyChanged);
};
PrintArea.prototype._validateMargin = function (margin, marginName) {
if (margin != null && (margin.left < 0 || margin.top < 0 || margin.right < 0 || margin.bottom < 0))
throw new ArgumentException("PrintArea.ts: " + marginName + " margin members cannot be negative!");
};
PrintArea.prototype.getSimplifiedObject = function () {
var simplified = _super.prototype.getSimplifiedObject.call(this, ["parentSurface", "boundsWithMargins", "boundsWithBleed"]);
return simplified;
};
PrintArea.prototype._copy = function (source, destination, generateNewIds) {
var _a, _b;
_super.prototype._copy.call(this, source, destination, generateNewIds);
destination.bounds = source.bounds != null ? source.bounds.clone() : null;
destination.safetyLines.addRange(source.safetyLines.toArray().map(function (s) { return s.clone(); }));
destination.cropMarks.addRange(source.cropMarks.toArray().map(function (c) { return c.clone(); }));
destination.bleed = (_a = source.bleed) === null || _a === void 0 ? void 0 : _a.clone();
destination.slug = (_b = source.slug) === null || _b === void 0 ? void 0 : _b.clone();
};
PrintArea.prototype.clone = function (generateNewIds) {
if (generateNewIds === void 0) { generateNewIds = false; }
var printArea = new PrintArea();
this._copy(this, printArea, generateNewIds);
return printArea;
};
PrintArea.prototype.generateNewIds = function () {
this._generateNewId();
};
return PrintArea;
}(ModelComponent));
export { PrintArea };
//# sourceMappingURL=PrintArea.js.map