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.

102 lines 5.54 kB
import { Path } from "@aurigma/design-atoms-model"; import { Configuration } from "@aurigma/design-atoms-model/Configuration"; import { PdfBox } from "@aurigma/design-atoms-model/Product"; import { PrintAreaBoundsType } from "@aurigma/design-atoms-model/Product/PrintAreaBoundsType"; import { toTextWhizzPath } from "@aurigma/design-atoms-text/Utils"; import { ItemUtils } from "../../../Utils/ItemUtils"; import { Violation, ViolationInfoResult, ViolationState } from "./Violation"; export class BleedViolation extends Violation { constructor(_productHandler, _messages, _conf, _textWhizz) { super(); this._productHandler = _productHandler; this._messages = _messages; this._conf = _conf; this._textWhizz = _textWhizz; } getStatePropertyName() { return BleedViolation.statePropertyName; } isAvailableFor(item) { return true; } getViolationInfo(item) { var _a; if (!ItemUtils.isTextItemHandlerReady(item, this._productHandler)) return ViolationInfoResult.none; if (!item.violationSettings.allowBleedArea || ((_a = item.parentContainer) === null || _a === void 0 ? void 0 : _a.name) !== Configuration.MAIN_CONTAINER_NAME) { return ViolationInfoResult.good; } const itemBounds = ItemUtils.getItemBoundsForViolationCheck(this._productHandler.getHandler(item)); const printAreas = item.parentContainer.parentComponent.printAreas; let bleedViolation = ViolationState.Good; for (const printArea of printAreas) { const trimSafetyLine = printArea.safetyLines.firstOrDefault(s => s.pdfBox === PdfBox.Trim); const bleedSafetyLine = printArea.safetyLines.firstOrDefault(s => s.pdfBox === PdfBox.Bleed); if ((trimSafetyLine == null || bleedSafetyLine == null) && printArea.bleed.isEmpty) continue; if (printArea.isRectangle) { bleedViolation = this._checkRectanglePrintArea(printArea, trimSafetyLine, bleedSafetyLine, itemBounds); } else { bleedViolation = this._checkNotRectanglePrintArea(printArea, itemBounds); } if (bleedViolation === ViolationState.Warning || bleedViolation === ViolationState.Bad) { break; } } const message = bleedViolation === ViolationState.Warning ? this._messages.bleedViolationWarning : null; return { state: bleedViolation, message: message }; } _checkRectanglePrintArea(printArea, trimSafetyLine, bleedSafetyLine, itemBounds) { var _a; const trimRect = printArea.bleed.isEmpty ? trimSafetyLine.getRectangle(printArea.bounds) : printArea.getBounds(PrintAreaBoundsType.Trim); const bleedRect = printArea.bleed.isEmpty ? bleedSafetyLine.getRectangle(printArea.bounds) : printArea.getBounds(PrintAreaBoundsType.Bleed); const tolerance = (_a = this._conf.tolerance) !== null && _a !== void 0 ? _a : 0.001; if (itemBounds.left < trimRect.left - tolerance && itemBounds.left > bleedRect.left + tolerance) { return ViolationState.Warning; } else if (itemBounds.top < trimRect.top - tolerance && itemBounds.top > bleedRect.top + tolerance) { return ViolationState.Warning; } else if (itemBounds.right > trimRect.right + tolerance && itemBounds.right < bleedRect.right - tolerance) { return ViolationState.Warning; } else if (itemBounds.bottom > trimRect.bottom + tolerance && itemBounds.bottom < bleedRect.bottom - tolerance) { return ViolationState.Warning; } else { return ViolationState.Good; } } _checkNotRectanglePrintArea(printArea, itemBounds) { var _a, _b, _c; if (((_a = this._textWhizz) === null || _a === void 0 ? void 0 : _a.module) == null) return ViolationState.None; const TWPath = this._textWhizz.module.Path; const twItemBoundsShape = toTextWhizzPath(this._textWhizz.module, Path.rectangle(itemBounds.left, itemBounds.top, itemBounds.width, itemBounds.height)); const twPrintAreaShape = toTextWhizzPath(this._textWhizz.module, printArea.shape); const twPrintAreaShapeWithOffset = toTextWhizzPath(this._textWhizz.module, printArea.shape); twPrintAreaShapeWithOffset.offsetContour((_c = (_b = printArea.bleed) === null || _b === void 0 ? void 0 : _b.top) !== null && _c !== void 0 ? _c : 0); const intersectWith = !TWPath.intersect(twItemBoundsShape, twPrintAreaShape).isEmpty(); const ring = TWPath.subtract(twPrintAreaShapeWithOffset, twPrintAreaShape); const intersectRing = !TWPath.intersect(twItemBoundsShape, ring).isEmpty(); const outOfBounds = !TWPath.subtract(twItemBoundsShape, twPrintAreaShapeWithOffset).isEmpty(); const isInside = TWPath.subtract(twItemBoundsShape, twPrintAreaShape).isEmpty(); if (intersectWith && intersectRing && outOfBounds) { return ViolationState.Good; } else if (isInside && !intersectRing) { return ViolationState.Good; } else { return ViolationState.Warning; } } } BleedViolation.statePropertyName = "bleedViolationState"; //# sourceMappingURL=BleedViolation.js.map