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.

138 lines 6.79 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."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import { ItemUtils } from "../../../Utils/ItemUtils"; import { Violation, ViolationState, ViolationInfoResult } from "./Violation"; import { Configuration } from "@aurigma/design-atoms-model/Configuration"; import { SafetyLineViolationMode } from "../../../Viewer/Interfaces"; import { PrintAreaBoundsType } from "@aurigma/design-atoms-model/Product/PrintAreaBoundsType"; import { Margin } from "@aurigma/design-atoms-model/Math/Margin"; var SafetyLineViolation = /** @class */ (function (_super) { __extends(SafetyLineViolation, _super); function SafetyLineViolation(_productHandler, _messages, _conf) { var _a, _b; var _this = _super.call(this) || this; _this._productHandler = _productHandler; _this._messages = _messages; _this._conf = _conf; _this._mode = (_b = (_a = _conf.safetyLines) === null || _a === void 0 ? void 0 : _a.mode) !== null && _b !== void 0 ? _b : SafetyLineViolationMode.InsideAll; return _this; } SafetyLineViolation.prototype.isAvailableFor = function (item) { return true; }; SafetyLineViolation.prototype.getViolationInfo = function (item) { var e_1, _a; var _this = this; var _b, _c; if (!ItemUtils.isTextItemHandlerReady(item, this._productHandler)) return ViolationInfoResult.none; if (!item.violationSettings.allowSafetyLines || ((_b = item.parentContainer) === null || _b === void 0 ? void 0 : _b.name) !== Configuration.MAIN_CONTAINER_NAME) return ViolationInfoResult.good; var printAreas = item.parentContainer.parentComponent.printAreas; var tolerance = (_c = this._conf.tolerance) !== null && _c !== void 0 ? _c : 0.001; var safetyLineRects = printAreas .selectMany(function (p) { return _this._getSafetyRectsFromPrintArea(p) .map(function (r) { return r.getExpanded(new Margin(tolerance)); }); }).toArray(); if (safetyLineRects.length === 0) return ViolationInfoResult.good; var itemBounds = ItemUtils.getItemBoundsForViolationCheck(this._productHandler.getHandler(item)); var isWarning = this._mode !== SafetyLineViolationMode.InsideAll; var breakCycle = false; try { for (var safetyLineRects_1 = __values(safetyLineRects), safetyLineRects_1_1 = safetyLineRects_1.next(); !safetyLineRects_1_1.done; safetyLineRects_1_1 = safetyLineRects_1.next()) { var sRect = safetyLineRects_1_1.value; switch (this._mode) { case SafetyLineViolationMode.InsideAll: if (!sRect.containsRectangle(itemBounds)) { isWarning = true; breakCycle = true; } break; case SafetyLineViolationMode.PartiallyInsideAny: if (sRect.containsRectangle(itemBounds)) { isWarning = false; breakCycle = true; } break; case SafetyLineViolationMode.InsideAny: if (sRect.containsRectangle(itemBounds)) { isWarning = false; } else if (sRect.intersectsWith(itemBounds)) { isWarning = true; breakCycle = true; } break; } if (breakCycle) break; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (safetyLineRects_1_1 && !safetyLineRects_1_1.done && (_a = safetyLineRects_1.return)) _a.call(safetyLineRects_1); } finally { if (e_1) throw e_1.error; } } var violationState = isWarning ? ViolationState.Warning : ViolationState.Good; var message = violationState === ViolationState.Warning ? this._messages.safetyLinesViolationWarning : null; return { state: violationState, message: message }; }; SafetyLineViolation.prototype._getSafetyRectsFromPrintArea = function (printArea) { var result = []; result.push.apply(result, __spread(printArea.safetyLines.toArray().map(function (sl) { return sl.getRectangle(printArea.bounds); }))); if (!printArea.bleed.isEmpty || !printArea.slug.isEmpty) result.push(printArea.getBounds(PrintAreaBoundsType.Trim)); return result; }; SafetyLineViolation.prototype.getStatePropertyName = function () { return SafetyLineViolation.statePropertyName; }; SafetyLineViolation.statePropertyName = "safetyLineViolationState"; return SafetyLineViolation; }(Violation)); export { SafetyLineViolation }; //# sourceMappingURL=SafetyLineViolation.js.map