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.

330 lines 15.9 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import { RotatedRectangleF, PointF } from "@aurigma/design-atoms-model/Math"; import { Container, RenderingType } from "@aurigma/design-atoms-model/Product"; import { Item } from "@aurigma/design-atoms-model/Product/Items"; import { ISize } from "../Utils/Math"; import { SurfaceHandler } from "./SurfaceHandler"; import { CoordinatesConvertUtils } from "../Utils/CoordinatesConvertUtils"; import { QuerySelector } from "./QuerySelector"; var ProductHandler = /** @class */ (function () { function ProductHandler(_viewer, _eventManager) { var _this = this; this._viewer = _viewer; this._eventManager = _eventManager; this.getHandler = function (item) { return _this._viewer.getHandler(item); }; } Object.defineProperty(ProductHandler.prototype, "currentSurface", { get: function () { return this._viewer.surface; }, set: function (surface) { this._viewer.surface = surface; }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "contentAngle", { get: function () { return this._viewer.contentAngle; }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "regionForCurrentContainer", { get: function () { var userEditContainer = this._viewer.userEditContainer; return userEditContainer != null ? userEditContainer.region : null; }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "product", { get: function () { var currentSurface = this.currentSurface; if (currentSurface == null) return null; return currentSurface.parentProduct; }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "selectedItems", { get: function () { return this._viewer.canvas.getSelectedItemHandlers().toArray().map(function (i) { return i.item; }); }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "userEditContainer", { get: function () { return this._viewer.userEditContainer; }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "userEditPrintArea", { get: function () { return this._viewer.getUserEditPrintArea(); }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "suppressOutOfRegionManipulation", { get: function () { return this._viewer.canvas.suppressOutOfRegionManipulation; }, enumerable: true, configurable: true }); Object.defineProperty(ProductHandler.prototype, "interactiveContainers", { /** * Gets or sets interactive containers of the Product. * @remarks Interactive containers allows to define product containers which items can be selected by user. * If this property is null or empty then items from any containers can be selected by user. */ get: function () { return this._interactiveContainers; }, set: function (value) { if (this._interactiveContainers == value) return; this._interactiveContainers = value; this._eventManager.interactiveContainersChangedEvent.notify(this._interactiveContainers); }, enumerable: true, configurable: true }); ProductHandler.prototype.queryItems = function (selectors, queryOptions) { var _a, _b, _c; if (selectors == null) return []; var ignoreMockups = !((_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.includeMockups) !== null && _a !== void 0 ? _a : false); var flatGroupItems = (_b = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.flatGroupItems) !== null && _b !== void 0 ? _b : false; var includePlaceholderContents = (_c = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.includePlaceholderContents) !== null && _c !== void 0 ? _c : false; var getAllItemsOptions = { ignoreMockups: ignoreMockups, flatGroupItems: flatGroupItems, includePlaceholderContents: includePlaceholderContents }; var items = this._viewer.productHandler.product.getAllItems(getAllItemsOptions); var querySelector = new QuerySelector(); var result = querySelector.process(items, selectors); return result; }; ProductHandler.prototype.redraw = function () { var _a, _b; (_b = (_a = this._viewer) === null || _a === void 0 ? void 0 : _a.canvas) === null || _b === void 0 ? void 0 : _b.redraw(); }; ProductHandler.prototype.beginMultiCall = function () { if (this._viewer == null || this._viewer.canvas == null || this._viewer.canvas.service == null) return; this._viewer.canvas.service.beginMultiCall(); }; ProductHandler.prototype.endMultiCall = function () { if (this._viewer == null || this._viewer.canvas == null || this._viewer.canvas.service == null) return; this._viewer.canvas.service.endMultiCall(); }; ProductHandler.prototype.waitUpdate = function () { var _a; return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, ((_a = this._viewer.canvas) === null || _a === void 0 ? void 0 : _a.waitUpdate())]; case 1: return [2 /*return*/, _b.sent()]; } }); }); }; ProductHandler.prototype.getProductColors = function (initialProduct) { var e_1, _a; var items = initialProduct.getAllItems(); var allColors = []; try { for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) { var item = items_1_1.value; var handler = this._viewer.getHandler(item); allColors.push.apply(allColors, __spread(handler.getColors())); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1); } finally { if (e_1) throw e_1.error; } } return allColors; }; ProductHandler.prototype.checkSelectionByHitTest = function (x, y) { var point = CoordinatesConvertUtils.pageToWorkspacePoint(new PointF(x, y), this._viewer); var isHit = this._viewer.canvas.isSelectionByHitTest(point); return isHit; }; ProductHandler.prototype.getPrintAreaVisualSize = function (targetContainer, printArea) { var printAreaBounds = this.getPrintAreaBounds(targetContainer, printArea); return this.getVisualSize(printAreaBounds); }; ProductHandler.prototype.getVisualSize = function (size) { var angle = this._viewer.contentAngle; if (angle === 0) return ISize.from(size); var boundsRect = new RotatedRectangleF(0, 0, size.width, size.height); boundsRect.rotateAt(angle, new PointF()); return ISize.from(boundsRect.bounds); }; ProductHandler.prototype.getPrintAreaBounds = function (container, printArea) { var targetContainer = container !== null && container !== void 0 ? container : this._viewer.userEditContainer; var targetPrintArea = printArea !== null && printArea !== void 0 ? printArea : this._viewer.getUserEditPrintArea(); return targetContainer.region != null ? targetContainer.region : targetPrintArea.bounds; }; ProductHandler.prototype.isInteractive = function (object) { if (object instanceof Container) { if (this._interactiveContainers == null || this._interactiveContainers.length == 0) return true; return this._interactiveContainers.includes(object); } else if (object instanceof Item) { return this.isInteractive(object.parentContainer); } throw new Error("Unexpected object type in isInteractive"); }; ProductHandler.prototype.updateSelection = function () { if (this._viewer.canvas == null) return; this._viewer.canvas.updateSelection(); }; ProductHandler.prototype.updateMaskedContainers = function () { var _this = this; if (this._viewer.canvas == null) return; var canvas = this._viewer.canvas; var itemHandlersToKeepSelected = []; canvas.getSelectedItemHandlers().forEach(function (element) { if (_this.userEditContainer == element.item.parentContainer) itemHandlersToKeepSelected.push(element); }); canvas.setSelectedItemHandlers(itemHandlersToKeepSelected); var allContainers = this.currentSurface.containers; var maskedContainers = []; var channelContainers = allContainers.where(function (c) { return c.renderingType !== RenderingType.Normal; }).toArray(); if (this.userEditContainer != null) { maskedContainers = channelContainers.slice(channelContainers.findIndex(function (c) { return _this.userEditContainer.id === c.id; }) + 1, channelContainers.length); } else { maskedContainers = channelContainers; } this._maskedContainers = maskedContainers; this._eventManager.maskedContainersChangedEvent.notify(this._maskedContainers); }; ProductHandler.prototype.isMasked = function (container) { if (this._maskedContainers == null || this._maskedContainers.length == 0) return false; return this._maskedContainers.includes(container); }; ProductHandler.prototype.exitEditMode = function () { var _a; (_a = this._viewer) === null || _a === void 0 ? void 0 : _a.exitEditMode(); }; ProductHandler.prototype.isItemSelected = function (item) { var handler = this.getHandler(item); return this._viewer.canvas.isItemHandlerSelected(handler); }; ProductHandler.prototype.applyLayout = function (product, surfaceFilterFunc) { return __awaiter(this, void 0, void 0, function () { var handlerFactory, applying; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!product) product = this.product; handlerFactory = this._viewer.canvas.handlerFactory; applying = product.surfaces.toArray().map(function (surface, i) { var skipSurface = false; if (surfaceFilterFunc) skipSurface = surfaceFilterFunc(i, surface); if (skipSurface) return null; return SurfaceHandler.applyLayout(handlerFactory, _this._viewer.canvas, surface); }).filter(function (promise) { return !!promise; }); return [4 /*yield*/, Promise.all(applying)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; return ProductHandler; }()); export { ProductHandler }; //# sourceMappingURL=ProductHandler.js.map