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.

203 lines 8.48 kB
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."); }; import { PointF, assign, RectangleF, EventObject } from "@aurigma/design-atoms-model"; import { toTextWhizzPath } from "@aurigma/design-atoms-text"; import { Button, InputType } from "../Input/InputManager/IInputManager"; var InteractiveZonesHandler = /** @class */ (function () { function InteractiveZonesHandler(_styles, _eventManagerEvent) { var _this = this; this._styles = _styles; this._eventManagerEvent = _eventManagerEvent; this._onSurfacePropertyChanged = function (sender, property) { if (property == "interactiveZones") { _this._activeZone = null; _this._highlightZone = null; _this._notifyStateChanged(); } }; this._onInput = function (params) { var _a, _b; var isRotating = (_b = (_a = _this._selectionHandler) === null || _a === void 0 ? void 0 : _a.isRotating) !== null && _b !== void 0 ? _b : false; if (params.type == InputType.Hover) { var pointerParams = params; var zone = _this._getZoneByPoint(pointerParams.workspace); _this.highlightZone = zone; if (pointerParams.button == Button.Primary && !isRotating) _this.activeZone = zone; } else if (params.type == InputType.PointerDown) { var pointerParams = params; if (pointerParams.button == Button.Primary && !isRotating) { var zone = _this._getZoneByPoint(pointerParams.workspace); _this.activeZone = zone; } } }; this._stateChangedEvent = new EventObject(); this._offset = new PointF(); } InteractiveZonesHandler.prototype.isReady = function () { return this._textWhizz != null; }; InteractiveZonesHandler.prototype.getZoneStyle = function (zone, isActive, isHover) { var _a; var style = (_a = this._styles[zone.styleKey]) !== null && _a !== void 0 ? _a : this._styles.default; var resultStyle = {}; var stylesArray = []; if (style.common) stylesArray.push(style.common); if (isActive && isHover && style.activeHighlighted) stylesArray.push(style.activeHighlighted); else if (isActive && style.active) stylesArray.push(style.active); else if (isHover && style.highlighted) stylesArray.push(style.highlighted); assign(resultStyle, stylesArray); return resultStyle; }; InteractiveZonesHandler.prototype.setOffset = function (offset) { this._offset = offset; }; InteractiveZonesHandler.prototype.setInputManager = function (inputManager) { if (this._inputManager != null) this._inputManager.removeOnInput(this._onInput); this._inputManager = inputManager; if (inputManager != null) this._inputManager.addOnInput(this._onInput); }; InteractiveZonesHandler.prototype.setSelectionHandler = function (selection) { this._selectionHandler = selection; }; InteractiveZonesHandler.prototype.setTextWhizz = function (textWhizz) { this._textWhizz = textWhizz; }; InteractiveZonesHandler.prototype.setStyles = function (styles) { this._styles = styles; }; InteractiveZonesHandler.prototype.getZoneBounds = function (zone) { var twPath = toTextWhizzPath(this._textWhizz, zone.path); var twRect = twPath.getBounds(); return new RectangleF(twRect.x, twRect.y, twRect.width, twRect.height); }; InteractiveZonesHandler.prototype.getSnapLines = function () { var _this = this; var result = []; this.interactiveZones.forEach(function (x) { if (!x.snappingEnabled) return; var bounds = _this.getZoneBounds(x); result.push(bounds); }); return result; }; Object.defineProperty(InteractiveZonesHandler.prototype, "stateChangedEvent", { get: function () { return this._stateChangedEvent; }, enumerable: true, configurable: true }); Object.defineProperty(InteractiveZonesHandler.prototype, "currentSurface", { get: function () { return this._currentSurface; }, set: function (value) { if (value === this._currentSurface) return; this._unsubscribeSurfaceEvents(); this._currentSurface = value; this._subscribeSurfaceEvents(); }, enumerable: true, configurable: true }); Object.defineProperty(InteractiveZonesHandler.prototype, "interactiveZones", { get: function () { var _a, _b; return (_b = (_a = this._currentSurface) === null || _a === void 0 ? void 0 : _a.interactiveZones) === null || _b === void 0 ? void 0 : _b.toArray(); }, enumerable: true, configurable: true }); Object.defineProperty(InteractiveZonesHandler.prototype, "activeZone", { get: function () { return this._activeZone; }, set: function (value) { if (this._activeZone === value) return; this._activeZone = value; this._notifyStateChanged(); }, enumerable: true, configurable: true }); Object.defineProperty(InteractiveZonesHandler.prototype, "highlightZone", { get: function () { return this._highlightZone; }, set: function (value) { if (this._highlightZone === value) return; this._highlightZone = value; this._notifyStateChanged(); }, enumerable: true, configurable: true }); InteractiveZonesHandler.prototype._notifyStateChanged = function () { var args = { active: this.activeZone, highlighted: this.highlightZone }; this._stateChangedEvent.notify(args); this._eventManagerEvent.fire(args); }; InteractiveZonesHandler.prototype._getZoneByPoint = function (point) { var e_1, _a; if (this._textWhizz == null) return null; var zones = this.interactiveZones; if (zones == null || zones.length == 0) return null; try { for (var zones_1 = __values(zones), zones_1_1 = zones_1.next(); !zones_1_1.done; zones_1_1 = zones_1.next()) { var zone = zones_1_1.value; var twPath = toTextWhizzPath(this._textWhizz, zone.path); var pt = point.clone().translate(-this._offset.x, -this._offset.y); if (twPath.isInside(pt.x, pt.y)) return zone; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (zones_1_1 && !zones_1_1.done && (_a = zones_1.return)) _a.call(zones_1); } finally { if (e_1) throw e_1.error; } } return null; }; InteractiveZonesHandler.prototype._unsubscribeSurfaceEvents = function () { if (this._currentSurface == null) return; this._currentSurface.removePropertyChanged(this._onSurfacePropertyChanged); }; InteractiveZonesHandler.prototype._subscribeSurfaceEvents = function () { if (this._currentSurface == null) return; this._currentSurface.addPropertyChanged(this._onSurfacePropertyChanged); }; InteractiveZonesHandler.prototype.propertyOf = function (name) { return name; }; return InteractiveZonesHandler; }()); export { InteractiveZonesHandler }; //# sourceMappingURL=InteractiveZonesHandler.js.map