@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
62 lines • 3.17 kB
JavaScript
import { Path } from "@aurigma/design-atoms-model";
import { Configuration } from "@aurigma/design-atoms-model/Configuration";
import { toTextWhizzPath } from "@aurigma/design-atoms-text/Utils";
import { ItemUtils } from "../../../Utils/ItemUtils";
import { Violation, ViolationInfoResult, ViolationState } from "./Violation";
export class OutOfPrintAreaViolation extends Violation {
constructor(_productHandler, _messages, _conf, _textWhizz) {
super();
this._productHandler = _productHandler;
this._messages = _messages;
this._conf = _conf;
this._textWhizz = _textWhizz;
}
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 outOfPrintAreaViolation = ViolationState.Good;
for (const printArea of printAreas) {
outOfPrintAreaViolation = this._checkPrintArea(printArea, itemBounds);
if (outOfPrintAreaViolation === ViolationState.Bad || outOfPrintAreaViolation === ViolationState.Warning) {
break;
}
}
const message = outOfPrintAreaViolation === ViolationState.Warning ? this._messages.outOfPrintAreaViolationWarning : null;
return { state: outOfPrintAreaViolation, message: message };
}
_checkPrintArea(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 twPrintAreaShape = toTextWhizzPath(this._textWhizz.module, printArea.shape);
const twItemBoundsShape = toTextWhizzPath(this._textWhizz.module, Path.rectangle(itemBounds.left, itemBounds.top, itemBounds.width, itemBounds.height));
twPrintAreaShape.offsetContour((_c = (_b = printArea.bleed) === null || _b === void 0 ? void 0 : _b.top) !== null && _c !== void 0 ? _c : 0);
const isInside = TWPath.subtract(twItemBoundsShape, twPrintAreaShape).isEmpty();
const isOutside = TWPath.intersect(twPrintAreaShape, twItemBoundsShape).isEmpty();
if (isInside) {
return ViolationState.Good;
}
else if (isOutside) {
return ViolationState.Bad;
}
else {
return ViolationState.Warning;
}
}
getStatePropertyName() {
return OutOfPrintAreaViolation.statePropertyName;
}
}
OutOfPrintAreaViolation.statePropertyName = "outOfPrintAreaViolationState";
//# sourceMappingURL=OutOfPrintAreaViolation.js.map