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.

55 lines 2.83 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 __()); }; })(); import { Violation, ViolationState, ViolationInfoResult } from "./Violation"; import { ItemUtils } from "../../../Utils/ItemUtils"; import { rectangleEquals } from "../../../Utils/Math"; import { RectangleF } from "@aurigma/design-atoms-model/Math"; import { Configuration } from "@aurigma/design-atoms-model/Configuration"; var RegionViolation = /** @class */ (function (_super) { __extends(RegionViolation, _super); function RegionViolation(_productHandler, _messages) { var _this = _super.call(this) || this; _this._productHandler = _productHandler; _this._messages = _messages; _this._isItemOutOfRegion = function (item) { if (item.parentContainer == null || item.parentContainer.region == null) return false; var itemBounds = ItemUtils.getItemBoundsForViolationCheck(_this._productHandler.getHandler(item)); var region = item.parentContainer.region.clone(); return !rectangleEquals(RectangleF.intersect(region, itemBounds), itemBounds); }; return _this; } RegionViolation.prototype.isAvailableFor = function (item) { return true; }; RegionViolation.prototype.getViolationInfo = function (item) { var _a; if (!ItemUtils.isTextItemHandlerReady(item, this._productHandler)) return ViolationInfoResult.none; if (!item.violationSettings.allowRegion || ((_a = item.parentContainer) === null || _a === void 0 ? void 0 : _a.name) !== Configuration.MAIN_CONTAINER_NAME) return ViolationInfoResult.good; var violationState = this._isItemOutOfRegion(item) ? ViolationState.Warning : ViolationState.Good; var message = violationState === ViolationState.Warning ? this._messages.regionViolationWarning : null; return { state: violationState, message: message }; }; RegionViolation.prototype.getStatePropertyName = function () { return RegionViolation.statePropertyName; }; RegionViolation.statePropertyName = "regionViolationState"; return RegionViolation; }(Violation)); export { RegionViolation }; //# sourceMappingURL=RegionViolation.js.map