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