UNPKG

@aurigma/design-atoms

Version:

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

98 lines 5.3 kB
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 __()); }; })(); var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import { Violation, ViolationState, ViolationInfoResult } from "./Violation"; import { Configuration } from "@aurigma/design-atoms-model/Configuration"; import { ItemUtils } from "../../../Utils/ItemUtils"; import { PrintAreaBoundsType } from "@aurigma/design-atoms-model/Product/PrintAreaBoundsType"; import { PdfBox } from "@aurigma/design-atoms-model/Product"; var BleedViolation = /** @class */ (function (_super) { __extends(BleedViolation, _super); function BleedViolation(_productHandler, _messages, _conf) { var _this = _super.call(this) || this; _this._productHandler = _productHandler; _this._messages = _messages; _this._conf = _conf; return _this; } BleedViolation.prototype.isAvailableFor = function (item) { return true; }; BleedViolation.prototype.getViolationInfo = function (item) { var e_1, _a; var _b, _c; if (!ItemUtils.isTextItemHandlerReady(item, this._productHandler)) return ViolationInfoResult.none; if (!item.violationSettings.allowBleedArea || ((_b = item.parentContainer) === null || _b === void 0 ? void 0 : _b.name) !== Configuration.MAIN_CONTAINER_NAME) { return ViolationInfoResult.good; } var itemBounds = ItemUtils.getItemBoundsForViolationCheck(this._productHandler.getHandler(item)); var printAreas = item.parentContainer.parentComponent.printAreas; var bleedViolation = false; try { for (var printAreas_1 = __values(printAreas), printAreas_1_1 = printAreas_1.next(); !printAreas_1_1.done; printAreas_1_1 = printAreas_1.next()) { var printArea = printAreas_1_1.value; var trimSafetyLine = printArea.safetyLines.firstOrDefault(function (s) { return s.pdfBox === PdfBox.Trim; }); var bleedSafetyLine = printArea.safetyLines.firstOrDefault(function (s) { return s.pdfBox === PdfBox.Bleed; }); if ((trimSafetyLine == null || bleedSafetyLine == null) && printArea.bleed.isEmpty) continue; var trimRect = printArea.bleed.isEmpty ? trimSafetyLine.getRectangle(printArea.bounds) : printArea.getBounds(PrintAreaBoundsType.Trim); var bleedRect = printArea.bleed.isEmpty ? bleedSafetyLine.getRectangle(printArea.bounds) : printArea.getBounds(PrintAreaBoundsType.Bleed); var tolerance = (_c = this._conf.tolerance) !== null && _c !== void 0 ? _c : 0.001; if (itemBounds.left < trimRect.left - tolerance && itemBounds.left > bleedRect.left + tolerance) bleedViolation = true; else if (itemBounds.top < trimRect.top - tolerance && itemBounds.top > bleedRect.top + tolerance) bleedViolation = true; else if (itemBounds.right > trimRect.right + tolerance && itemBounds.right < bleedRect.right - tolerance) bleedViolation = true; else if (itemBounds.bottom > trimRect.bottom + tolerance && itemBounds.bottom < bleedRect.bottom - tolerance) bleedViolation = true; if (!bleedViolation) break; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (printAreas_1_1 && !printAreas_1_1.done && (_a = printAreas_1.return)) _a.call(printAreas_1); } finally { if (e_1) throw e_1.error; } } var violationState = bleedViolation ? ViolationState.Warning : ViolationState.Good; var message = violationState === ViolationState.Warning ? this._messages.bleedViolationWarning : null; return { state: violationState, message: message }; }; BleedViolation.prototype.getStatePropertyName = function () { return BleedViolation.statePropertyName; }; BleedViolation.statePropertyName = "bleedViolationState"; return BleedViolation; }(Violation)); export { BleedViolation }; //# sourceMappingURL=BleedViolation.js.map