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.

77 lines 2.85 kB
export class SurfaceManager { constructor(_productHandler) { this._productHandler = _productHandler; } _switchSurface(spinIndex) { const product = this._productHandler.product; if (product == null) return; const surfaces = product.surfaces; if (surfaces.length <= 0) return; let surfaceIndex = surfaces.indexOf(this._productHandler.currentSurface); if (surfaceIndex === -1) { console.warn("Current surface is not found in product"); surfaceIndex = 0; } var newIndex, maxIndex = surfaces.length - 1; var minIndex = 0; if (spinIndex != null) newIndex = Math.max(Math.min(surfaceIndex + spinIndex, maxIndex), minIndex); else newIndex = surfaceIndex < maxIndex ? surfaceIndex + 1 : minIndex; this.switchToSurface(surfaces.get(newIndex)); } async switchToSurface(newSurface) { const product = this._productHandler.product; if (product == null) return; if (product.surfaces.length === 0) { console.warn("Surfaces are not found!"); return; } if (this._productHandler.currentSurface === newSurface) { return; } this._productHandler.currentSurface = newSurface; } async getNextSurface(spinIndex) { const product = this._productHandler.product; if (product == null) return; const surfaces = product.surfaces; if (surfaces.length <= 0) return null; let surfaceIndex = surfaces.indexOf(this._productHandler.currentSurface); if (surfaceIndex == -1) { console.warn("Current surface is not found in product"); surfaceIndex = 0; } let newIndex = surfaceIndex; if (spinIndex != null) { newIndex += spinIndex; } else { newIndex++; } return product.surfaces.get(newIndex); } switchToNextSurface() { this._switchSurface(); } async switchSurfaceForward() { this._switchSurface(1); } async switchSurfaceBackward() { this._switchSurface(-1); } } export var SurfaceSwitchCommand; (function (SurfaceSwitchCommand) { SurfaceSwitchCommand["switchToSurface"] = "switchToSurface"; SurfaceSwitchCommand["getNextSurface"] = "getNextSurface"; SurfaceSwitchCommand["switchToNextSurface"] = "switchToNextSurface"; SurfaceSwitchCommand["switchSurfaceForward"] = "switchSurfaceForward"; SurfaceSwitchCommand["switchSurfaceBackward"] = "switchSurfaceBackward"; })(SurfaceSwitchCommand || (SurfaceSwitchCommand = {})); //# sourceMappingURL=SurfaceManager.js.map