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.

52 lines 2.75 kB
import { NotImplementedException } from "@aurigma/design-atoms-model/Exception"; import { BaseItemsCommand } from "./BaseItemsCommand"; import { RectangleF, RotatedRectangleF } from "@aurigma/design-atoms-model/Math"; import { fitRectangleToRectangle } from "../../Utils/Math"; import { ResizeRectangleType } from "@aurigma/design-atoms-interfaces"; export class PlaceItemsToAreaCommand extends BaseItemsCommand { constructor(productHandler, historyArgs, args, _canvas = null) { super(productHandler, historyArgs, args); this._canvas = _canvas; } async _executeCommandBody() { var _a, _b, _c, _d; const targetItems = this._getTargetItems(this._args.items, this._args.query, this._args.queryOptions); const itemsBounds = (_a = this._args.itemsRect) !== null && _a !== void 0 ? _a : RectangleF.getOverallBounds(targetItems.map(i => this._productHandler.getHandler(i).bounds)); const targetBounds = fitRectangleToRectangle(itemsBounds, this._args.rect, ResizeRectangleType.Fit); const itemsRotatedRect = RotatedRectangleF.fromRectangleF(itemsBounds); const targetRotatedRect = RotatedRectangleF.fromRectangleF(targetBounds); const noShowMap = new Map(); const visibleMap = new Map(); const transformItem = async (item) => { noShowMap.set(item.id, item.visualizationPermissions.noShow); item.visualizationPermissions.noShow = false; visibleMap.set(item.id, item.visible); item.visible = true; const handler = this._productHandler.getHandler(item); handler.update(); await handler.waitUpdate(); handler.startTransform(); handler.transformRectangle(itemsRotatedRect, targetRotatedRect); }; await Promise.all(targetItems.map(transformItem)); targetItems.map(this._productHandler.getHandler).forEach((i) => { i.onResized(); i.endTransform(true, true); }); const restoreItemVisualParameters = (item) => { item.visualizationPermissions.noShow = noShowMap.get(item.id); item.visible = visibleMap.get(item.id); }; targetItems.forEach(restoreItemVisualParameters); (_b = this._canvas) === null || _b === void 0 ? void 0 : _b.updateTexts(); (_c = this._canvas) === null || _c === void 0 ? void 0 : _c.updateSelection(); (_d = this._canvas) === null || _d === void 0 ? void 0 : _d.redraw(); } redo() { throw new NotImplementedException(); } undo() { throw new NotImplementedException(); } } //# sourceMappingURL=PlaceItemsToAreaCommand.js.map