@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
65 lines • 2.73 kB
JavaScript
import { Violation, ViolationState, ViolationInfoResult } from "./Violation";
import { SurfaceContainer } from "@aurigma/design-atoms-model";
import { RectangleF } from "@aurigma/design-atoms-model/Math/RectangleF";
export class MaxArtworkAreaViolation extends Violation {
constructor(_productHandler, _messages) {
super();
this._productHandler = _productHandler;
this._messages = _messages;
}
isAvailableFor(item) {
return true;
}
getStatePropertyName() {
return MaxArtworkAreaViolation.statePropertyName;
}
getDataPropertyName() {
return MaxArtworkAreaViolation.dataPropertyName;
}
getViolationInfo(item) {
if (!(item.parentContainer instanceof SurfaceContainer)) {
return ViolationInfoResult.none;
}
const boundsList = item.parentContainer.items.toArray().map(containerItem => {
const handler = this._productHandler.getHandler(containerItem);
return handler.bounds;
});
if (boundsList.length === 0)
return ViolationInfoResult.good;
const constraints = item.parentContainer.constraints.maxArtworkSize;
if (constraints == null)
return ViolationInfoResult.none;
const overallBounds = RectangleF.getOverallBounds(boundsList);
const state = this._isExceedConstraints(overallBounds, constraints) ?
ViolationState.Bad : ViolationState.Good;
const message = state === ViolationState.Bad ? this._messages.maxArtworkSizeWarning : null;
return { state, message };
}
_isExceedConstraints(overallBounds, constraints) {
if (constraints.width == null || constraints.height == null) {
return false;
}
if (constraints.shapeType === 'ellipse') {
const ellipseWidth = overallBounds.width * Math.SQRT2;
const ellipseHeight = overallBounds.height * Math.SQRT2;
if (ellipseWidth > constraints.width) {
return true;
}
if (ellipseHeight > constraints.height) {
return true;
}
}
else if (constraints.shapeType === "rectangle") {
if (overallBounds.width > constraints.width) {
return true;
}
if (overallBounds.height > constraints.height) {
return true;
}
}
return false;
}
}
MaxArtworkAreaViolation.statePropertyName = "maxArtworkAreaViolationState";
MaxArtworkAreaViolation.dataPropertyName = "maxArtworkAreaViolationData";
//# sourceMappingURL=MaxArtworkAreaViolation.js.map