UNPKG

@huluvu424242/honey-slideshow

Version:

Text to Speech component wich is reading texts from DOM elements.

197 lines (196 loc) 6.89 kB
var GestureController = /** @class */ (function () { function GestureController() { this.gestureId = 0; this.requestedStart = new Map(); this.disabledGestures = new Map(); this.disabledScroll = new Set(); } /** * Creates a gesture delegate based on the GestureConfig passed */ GestureController.prototype.createGesture = function (config) { return new GestureDelegate(this, this.newID(), config.name, config.priority || 0, !!config.disableScroll); }; /** * Creates a blocker that will block any other gesture events from firing. Set in the ion-gesture component. */ GestureController.prototype.createBlocker = function (opts) { if (opts === void 0) { opts = {}; } return new BlockerDelegate(this, this.newID(), opts.disable, !!opts.disableScroll); }; GestureController.prototype.start = function (gestureName, id, priority) { if (!this.canStart(gestureName)) { this.requestedStart.delete(id); return false; } this.requestedStart.set(id, priority); return true; }; GestureController.prototype.capture = function (gestureName, id, priority) { if (!this.start(gestureName, id, priority)) { return false; } var requestedStart = this.requestedStart; var maxPriority = -10000; requestedStart.forEach(function (value) { maxPriority = Math.max(maxPriority, value); }); if (maxPriority === priority) { this.capturedId = id; requestedStart.clear(); var event = new CustomEvent('ionGestureCaptured', { detail: { gestureName: gestureName } }); document.dispatchEvent(event); return true; } requestedStart.delete(id); return false; }; GestureController.prototype.release = function (id) { this.requestedStart.delete(id); if (this.capturedId === id) { this.capturedId = undefined; } }; GestureController.prototype.disableGesture = function (gestureName, id) { var set = this.disabledGestures.get(gestureName); if (set === undefined) { set = new Set(); this.disabledGestures.set(gestureName, set); } set.add(id); }; GestureController.prototype.enableGesture = function (gestureName, id) { var set = this.disabledGestures.get(gestureName); if (set !== undefined) { set.delete(id); } }; GestureController.prototype.disableScroll = function (id) { this.disabledScroll.add(id); if (this.disabledScroll.size === 1) { document.body.classList.add(BACKDROP_NO_SCROLL); } }; GestureController.prototype.enableScroll = function (id) { this.disabledScroll.delete(id); if (this.disabledScroll.size === 0) { document.body.classList.remove(BACKDROP_NO_SCROLL); } }; GestureController.prototype.canStart = function (gestureName) { if (this.capturedId !== undefined) { // a gesture already captured return false; } if (this.isDisabled(gestureName)) { return false; } return true; }; GestureController.prototype.isCaptured = function () { return this.capturedId !== undefined; }; GestureController.prototype.isScrollDisabled = function () { return this.disabledScroll.size > 0; }; GestureController.prototype.isDisabled = function (gestureName) { var disabled = this.disabledGestures.get(gestureName); if (disabled && disabled.size > 0) { return true; } return false; }; GestureController.prototype.newID = function () { this.gestureId++; return this.gestureId; }; return GestureController; }()); var GestureDelegate = /** @class */ (function () { function GestureDelegate(ctrl, id, name, priority, disableScroll) { this.id = id; this.name = name; this.disableScroll = disableScroll; this.priority = priority * 1000000 + id; this.ctrl = ctrl; } GestureDelegate.prototype.canStart = function () { if (!this.ctrl) { return false; } return this.ctrl.canStart(this.name); }; GestureDelegate.prototype.start = function () { if (!this.ctrl) { return false; } return this.ctrl.start(this.name, this.id, this.priority); }; GestureDelegate.prototype.capture = function () { if (!this.ctrl) { return false; } var captured = this.ctrl.capture(this.name, this.id, this.priority); if (captured && this.disableScroll) { this.ctrl.disableScroll(this.id); } return captured; }; GestureDelegate.prototype.release = function () { if (this.ctrl) { this.ctrl.release(this.id); if (this.disableScroll) { this.ctrl.enableScroll(this.id); } } }; GestureDelegate.prototype.destroy = function () { this.release(); this.ctrl = undefined; }; return GestureDelegate; }()); var BlockerDelegate = /** @class */ (function () { function BlockerDelegate(ctrl, id, disable, disableScroll) { this.id = id; this.disable = disable; this.disableScroll = disableScroll; this.ctrl = ctrl; } BlockerDelegate.prototype.block = function () { if (!this.ctrl) { return; } if (this.disable) { for (var _i = 0, _a = this.disable; _i < _a.length; _i++) { var gesture = _a[_i]; this.ctrl.disableGesture(gesture, this.id); } } if (this.disableScroll) { this.ctrl.disableScroll(this.id); } }; BlockerDelegate.prototype.unblock = function () { if (!this.ctrl) { return; } if (this.disable) { for (var _i = 0, _a = this.disable; _i < _a.length; _i++) { var gesture = _a[_i]; this.ctrl.enableGesture(gesture, this.id); } } if (this.disableScroll) { this.ctrl.enableScroll(this.id); } }; BlockerDelegate.prototype.destroy = function () { this.unblock(); this.ctrl = undefined; }; return BlockerDelegate; }()); var BACKDROP_NO_SCROLL = 'backdrop-no-scroll'; var GESTURE_CONTROLLER = new GestureController(); export { GESTURE_CONTROLLER as G };