diff --git a/closure.log b/closure.log index b24117dc40..d895f9e9b7 100644 --- a/closure.log +++ b/closure.log @@ -717,336 +717,7 @@ Found : PolymerElement * @param {Polymer.Debouncer?} debouncer Debouncer object. ^^^^^^^^^^^^^^^^^ -/polymer.html_script_13.js:246: WARNING - Returned type does not match declared return type. -Expected : HTMLElement|null -Found : Element|null -More details: -The found type is a union that includes an unexpected type: Element - return node; - ^^^^^^^^^^^^ - -/polymer.html_script_13.js:258: WARNING - Returned type does not match declared return type. -Expected : HTMLElement|null -Found : Document|Element|ShadowRoot|Window -More details: -The found type is a union that includes an unexpected type: Window - return ev.composedPath()[0]; - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -/polymer.html_script_13.js:261: WARNING - Returned type does not match declared return type. -Expected : HTMLElement|null -Found : EventTarget|null -More details: -The found type is a union that includes an unexpected type: EventTarget - return ev.target; - ^^^^^^^^^^^^^^^^^ - -/polymer.html_script_13.js:283: WARNING - Property changedTouches never defined on ev of type Event - let t = ev.changedTouches[0]; - ^^^^^^^^^^^^^^^^^ - -/polymer.html_script_13.js:286: WARNING - Property touches never defined on ev of type Event - if (ev.touches.length === 1) { - ^^^^^^^^^^ - -/polymer.html_script_13.js:330: WARNING - Property changedTouches never defined on ev of type Event - let t = ev.changedTouches[0]; - ^^^^^^^^^^^^^^^^^ - -/polymer.html_script_13.js:371: WARNING - Missing return statement. Function expected to return boolean. - addListener: function(node, evType, handler) { - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -/polymer.html_script_13.js:372: WARNING - Dangerous use of the global THIS object - if (this.gestures[evType]) { - ^^^^ - -/polymer.html_script_13.js:373: WARNING - Dangerous use of the global THIS object - this._add(node, evType, handler); - ^^^^ - -/polymer.html_script_13.js:388: WARNING - Missing return statement. Function expected to return boolean. - removeListener: function(node, evType, handler) { - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -/polymer.html_script_13.js:389: WARNING - Dangerous use of the global THIS object - if (this.gestures[evType]) { - ^^^^ - -/polymer.html_script_13.js:390: WARNING - Dangerous use of the global THIS object - this._remove(node, evType, handler); - ^^^^ - -/polymer.html_script_13.js:401: WARNING - Bad type annotation. missing opening ( See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information. - * @param {function} handler Event handler function. - ^ - -/polymer.html_script_13.js:404: WARNING - Dangerous use of the global THIS object - let recognizer = this.gestures[evType]; - ^^^^ - -/polymer.html_script_13.js:422: WARNING - Dangerous use of the global THIS object - node.addEventListener(dep, this._handleNative); - ^^^^ - -/polymer.html_script_13.js:429: WARNING - Dangerous use of the global THIS object - this.setTouchAction(node, recognizer.touchAction); - ^^^^ - -/polymer.html_script_13.js:439: WARNING - Bad type annotation. missing opening ( See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information. - * @param {function} handler Event handler function. - ^ - -/polymer.html_script_13.js:442: WARNING - Dangerous use of the global THIS object - let recognizer = this.gestures[evType]; - ^^^^ - -/polymer.html_script_13.js:454: WARNING - Dangerous use of the global THIS object - node.removeEventListener(dep, this._handleNative); - ^^^^ - -/polymer.html_script_13.js:470: WARNING - Dangerous use of the global THIS object - this.recognizers.push(recog); - ^^^^ - -/polymer.html_script_13.js:472: WARNING - Dangerous use of the global THIS object - this.gestures[recog.emits[i]] = recog; - ^^^^ - -/polymer.html_script_13.js:482: WARNING - Dangerous use of the global THIS object - for (let i = 0, r; i < this.recognizers.length; i++) { - ^^^^ - -/polymer.html_script_13.js:483: WARNING - Dangerous use of the global THIS object - r = this.recognizers[i]; - ^^^^ - -/polymer.html_script_13.js:506: WARNING - Property style never defined on node of type Node - node.style.touchAction = value; - ^^^^^^^^^^ - -/polymer.html_script_13.js:539: WARNING - Dangerous use of the global THIS object - let recognizer = this._findRecognizerByEvent(evName); - ^^^^ - -/polymer.html_script_13.js:576: WARNING - Dangerous use of the global THIS object - untrackDocument(this.info); - ^^^^ - -/polymer.html_script_13.js:597: WARNING - Dangerous use of the global THIS object - trackDocument(this.info, movefn, upfn); - ^^^^ - -/polymer.html_script_13.js:598: WARNING - Dangerous use of the global THIS object - this._fire('down', t, e); - ^^^^ - -/polymer.html_script_13.js:601: WARNING - Dangerous use of the global THIS object - this._fire('down', Gestures._findOriginalTarget(e), e.changedTouches[0], e); - ^^^^ - -/polymer.html_script_13.js:604: WARNING - Dangerous use of the global THIS object - this._fire('up', Gestures._findOriginalTarget(e), e.changedTouches[0], e); - ^^^^ - -/polymer.html_script_13.js:636: WARNING - Dangerous use of the global THIS object - if (this.moves.length > TRACK_LENGTH) { - ^^^^ - -/polymer.html_script_13.js:637: WARNING - Dangerous use of the global THIS object - this.moves.shift(); - ^^^^ - -/polymer.html_script_13.js:639: WARNING - Dangerous use of the global THIS object - this.moves.push(move); - ^^^^ - -/polymer.html_script_13.js:647: WARNING - Dangerous use of the global THIS object - this.info.state = 'start'; - ^^^^ - -/polymer.html_script_13.js:648: WARNING - Dangerous use of the global THIS object - this.info.started = false; - ^^^^ - -/polymer.html_script_13.js:649: WARNING - Dangerous use of the global THIS object - this.info.moves = []; - ^^^^ - -/polymer.html_script_13.js:650: WARNING - Dangerous use of the global THIS object - this.info.x = 0; - ^^^^ - -/polymer.html_script_13.js:651: WARNING - Dangerous use of the global THIS object - this.info.y = 0; - ^^^^ - -/polymer.html_script_13.js:652: WARNING - Dangerous use of the global THIS object - this.info.prevent = false; - ^^^^ - -/polymer.html_script_13.js:653: WARNING - Dangerous use of the global THIS object - untrackDocument(this.info); - ^^^^ - -/polymer.html_script_13.js:657: WARNING - Dangerous use of the global THIS object - if (this.info.prevent) { - ^^^^ - -/polymer.html_script_13.js:660: WARNING - Dangerous use of the global THIS object - if (this.info.started) { - ^^^^ - -/polymer.html_script_13.js:663: WARNING - Dangerous use of the global THIS object - let dx = Math.abs(this.info.x - x); - ^^^^ - -/polymer.html_script_13.js:664: WARNING - Dangerous use of the global THIS object - let dy = Math.abs(this.info.y - y); - ^^^^ - -/polymer.html_script_13.js:702: WARNING - Dangerous use of the global THIS object - trackDocument(this.info, movefn, upfn); - ^^^^ - -/polymer.html_script_13.js:703: WARNING - Dangerous use of the global THIS object - this.info.x = e.clientX; - ^^^^ - -/polymer.html_script_13.js:704: WARNING - Dangerous use of the global THIS object - this.info.y = e.clientY; - ^^^^ - -/polymer.html_script_13.js:709: WARNING - Dangerous use of the global THIS object - this.info.x = ct.clientX; - ^^^^ - -/polymer.html_script_13.js:710: WARNING - Dangerous use of the global THIS object - this.info.y = ct.clientY; - ^^^^ - -/polymer.html_script_13.js:717: WARNING - Dangerous use of the global THIS object - if (this.hasMovedEnough(x, y)) { - ^^^^ - -/polymer.html_script_13.js:718: WARNING - Dangerous use of the global THIS object - if (this.info.state === 'start') { - ^^^^ - -/polymer.html_script_13.js:722: WARNING - Dangerous use of the global THIS object - this.info.addMove({x: x, y: y}); - ^^^^ - -/polymer.html_script_13.js:723: WARNING - Dangerous use of the global THIS object - this._fire(t, ct); - ^^^^ - -/polymer.html_script_13.js:724: WARNING - Dangerous use of the global THIS object - this.info.state = 'track'; - ^^^^ - -/polymer.html_script_13.js:725: WARNING - Dangerous use of the global THIS object - this.info.started = true; - ^^^^ - -/polymer.html_script_13.js:733: WARNING - Dangerous use of the global THIS object - if (this.info.started) { - ^^^^ - -/polymer.html_script_13.js:735: WARNING - Dangerous use of the global THIS object - this.info.state = 'end'; - ^^^^ - -/polymer.html_script_13.js:736: WARNING - Dangerous use of the global THIS object - this.info.addMove({x: ct.clientX, y: ct.clientY}); - ^^^^ - -/polymer.html_script_13.js:737: WARNING - Dangerous use of the global THIS object - this._fire(t, ct, e); - ^^^^ - -/polymer.html_script_13.js:742: WARNING - Dangerous use of the global THIS object - let secondlast = this.info.moves[this.info.moves.length - 2]; - ^^^^ - -/polymer.html_script_13.js:742: WARNING - Dangerous use of the global THIS object - let secondlast = this.info.moves[this.info.moves.length - 2]; - ^^^^ - -/polymer.html_script_13.js:743: WARNING - Dangerous use of the global THIS object - let lastmove = this.info.moves[this.info.moves.length - 1]; - ^^^^ - -/polymer.html_script_13.js:743: WARNING - Dangerous use of the global THIS object - let lastmove = this.info.moves[this.info.moves.length - 1]; - ^^^^ - -/polymer.html_script_13.js:744: WARNING - Dangerous use of the global THIS object - let dx = lastmove.x - this.info.x; - ^^^^ - -/polymer.html_script_13.js:745: WARNING - Dangerous use of the global THIS object - let dy = lastmove.y - this.info.y; - ^^^^ - -/polymer.html_script_13.js:752: WARNING - Dangerous use of the global THIS object - state: this.info.state, - ^^^^ - -/polymer.html_script_13.js:782: WARNING - Dangerous use of the global THIS object - this.info.x = NaN; - ^^^^ - -/polymer.html_script_13.js:783: WARNING - Dangerous use of the global THIS object - this.info.y = NaN; - ^^^^ - -/polymer.html_script_13.js:784: WARNING - Dangerous use of the global THIS object - this.info.prevent = false; - ^^^^ - -/polymer.html_script_13.js:787: WARNING - Dangerous use of the global THIS object - this.info.x = e.clientX; - ^^^^ - -/polymer.html_script_13.js:788: WARNING - Dangerous use of the global THIS object - this.info.y = e.clientY; - ^^^^ - -/polymer.html_script_13.js:793: WARNING - Dangerous use of the global THIS object - this.save(e); - ^^^^ - -/polymer.html_script_13.js:798: WARNING - Dangerous use of the global THIS object - this.forward(e); - ^^^^ - -/polymer.html_script_13.js:803: WARNING - Dangerous use of the global THIS object - this.save(e.changedTouches[0], e); - ^^^^ - -/polymer.html_script_13.js:806: WARNING - Dangerous use of the global THIS object - this.forward(e.changedTouches[0], e); - ^^^^ - -/polymer.html_script_13.js:810: WARNING - Dangerous use of the global THIS object - let dx = Math.abs(e.clientX - this.info.x); - ^^^^ - -/polymer.html_script_13.js:811: WARNING - Dangerous use of the global THIS object - let dy = Math.abs(e.clientY - this.info.y); - ^^^^ - -/polymer.html_script_13.js:816: WARNING - Dangerous use of the global THIS object - if (!this.info.prevent) { - ^^^^ - -/polymer.html_script_14.js:6: WARNING - All constants must be typed. The compiler could not infer the type of constant gestures. Please use an explicit type annotation. For more information, see: -https://github.com/google/closure-compiler/wiki/Using-NTI-(new-type-inference)#warnings-about-uninferred-constants - const gestures = Polymer.Gestures; - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -/polymer.html_script_14.js:28: WARNING - GestureEventListeners extends non-object type ?. +/polymer.html_script_14.js:31: WARNING - GestureEventListeners extends non-object type ?. class GestureEventListeners extends superClass { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1839,4 +1510,4 @@ externs/closure-types.js:759: WARNING - property toggle on interface Polymer_Arr Polymer_ArraySelectorMixin.prototype.toggle; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0 error(s), 410 warning(s), 71.8% typed +0 error(s), 331 warning(s), 72.6% typed diff --git a/lib/mixins/gesture-event-listeners.html b/lib/mixins/gesture-event-listeners.html index dcf163daef..3b6807f9e3 100644 --- a/lib/mixins/gesture-event-listeners.html +++ b/lib/mixins/gesture-event-listeners.html @@ -15,6 +15,9 @@ 'use strict'; + /** + * @const {Polymer.Gestures} + */ const gestures = Polymer.Gestures; /** diff --git a/lib/utils/gestures.html b/lib/utils/gestures.html index 4ee65c3b87..59bded2fd1 100644 --- a/lib/utils/gestures.html +++ b/lib/utils/gestures.html @@ -54,6 +54,23 @@ // Check for touch-only devices let IS_TOUCH_ONLY = navigator.userAgent.match(/iP(?:[oa]d|hone)|Android/); + let GestureRecognizer = function(){}; // eslint-disable-line no-unused-vars + GestureRecognizer.prototype.reset = function(){}; + /** @type {function(MouseEvent) | undefined} */ + GestureRecognizer.prototype.mousedown; + /** @type {(function(MouseEvent) | undefined)} */ + GestureRecognizer.prototype.mousemove; + /** @type {(function(MouseEvent) | undefined)} */ + GestureRecognizer.prototype.mouseup; + /** @type {(function(TouchEvent) | undefined)} */ + GestureRecognizer.prototype.touchstart; + /** @type {(function(TouchEvent) | undefined)} */ + GestureRecognizer.prototype.touchmove; + /** @type {(function(TouchEvent) | undefined)} */ + GestureRecognizer.prototype.touchend; + /** @type {(function(MouseEvent) | undefined)} */ + GestureRecognizer.prototype.click; + // touch will make synthetic mouse events // `preventDefault` on touchend will cancel them, // but this breaks `` focus and link clicks @@ -116,6 +133,10 @@ , unset); } + /** + * @param {MouseEvent} ev event to test for left mouse button down + * @return {boolean} has left mouse button down + */ function hasLeftMouseButton(ev) { let type = ev.type; // exit early if the event is not a mouse event @@ -152,10 +173,10 @@ let t = Gestures._findOriginalTarget(ev); // make sure the target of the event is an element so we can use getBoundingClientRect, // if not, just assume it is a synthetic click - if (t.nodeType !== Node.ELEMENT_NODE) { + if (!t.nodeType || /** @type {Element} */(t).nodeType !== Node.ELEMENT_NODE) { return true; } - let bcr = t.getBoundingClientRect(); + let bcr = /** @type {Element} */(t).getBoundingClientRect(); // use page x/y to account for scrolling let x = ev.pageX, y = ev.pageY; // ev is a synthetic click if the position is outside the bounding box of the target @@ -235,7 +256,7 @@ * @memberof Polymer.Gestures * @param {number} x Horizontal pixel coordinate * @param {number} y Vertical pixel coordinate - * @return {HTMLElement} Returns the deepest shadowRoot inclusive element + * @return {Element} Returns the deepest shadowRoot inclusive element * found at the screen position given. */ deepTargetFind: function(x, y) { @@ -263,12 +284,12 @@ * * @private * @param {Event} ev Event. - * @return {HTMLElement} Returns the event target. + * @return {EventTarget} Returns the event target. */ _findOriginalTarget: function(ev) { // shadowdom if (ev.composedPath) { - return ev.composedPath()[0]; + return /** @type {EventTarget} */(ev.composedPath()[0]); } // shadydom return ev.target; @@ -293,6 +314,7 @@ if (!ev[HANDLED_OBJ]) { ev[HANDLED_OBJ] = {}; if (type.slice(0, 5) === 'touch') { + ev = /** @type {TouchEvent} */(ev); // eslint-disable-line no-self-assign let t = ev.changedTouches[0]; if (type === 'touchstart') { // only handle the first finger @@ -337,7 +359,7 @@ /** * @private - * @param {Event} ev Event. + * @param {TouchEvent} ev Event. */ _handleTouchAction: function(ev) { let t = ev.changedTouches[0]; @@ -380,12 +402,14 @@ * @param {string} evType Gesture type: `down`, `up`, `track`, or `tap` * @param {Function} handler Event listener function to call * @return {boolean} Returns true if a gesture event listener was added. + * @this {Gestures} */ addListener: function(node, evType, handler) { if (this.gestures[evType]) { this._add(node, evType, handler); return true; } + return false; }, /** @@ -397,12 +421,14 @@ * @param {Function} handler Event listener function previously passed to * `addListener`. * @return {boolean} Returns true if a gesture event listener was removed. + * @this {Gestures} */ removeListener: function(node, evType, handler) { if (this.gestures[evType]) { this._remove(node, evType, handler); return true; } + return false; }, /** @@ -411,7 +437,8 @@ * @private * @param {HTMLElement} node Node on which to add the event. * @param {string} evType Event type to add. - * @param {function} handler Event handler function. + * @param {function(Event?)} handler Event handler function. + * @this {Gestures} */ _add: function(node, evType, handler) { let recognizer = this.gestures[evType]; @@ -449,7 +476,8 @@ * @private * @param {HTMLElement} node Node on which to remove the event. * @param {string} evType Event type to remove. - * @param {function} handler Event handler function. + * @param {function(Event?)} handler Event handler function. + * @this {Gestures} */ _remove: function(node, evType, handler) { let recognizer = this.gestures[evType]; @@ -477,7 +505,8 @@ * gesture event types. * * @memberof Polymer.Gestures - * @param {Object} recog Gesture recognizer descriptor + * @param {GestureRecognizer} recog Gesture recognizer descriptor + * @this {Gestures} */ register: function(recog) { this.recognizers.push(recog); @@ -490,6 +519,7 @@ * @private * @param {string} evName Event name. * @return {Object} Returns the gesture for the given event name. + * @this {Gestures} */ _findRecognizerByEvent: function(evName) { for (let i = 0, r; i < this.recognizers.length; i++) { @@ -511,7 +541,7 @@ * adding event listeners. * * @memberof Polymer.Gestures - * @param {Node} node Node to set touch action setting on + * @param {Element} node Node to set touch action setting on * @param {string} value Touch action value */ setTouchAction: function(node, value) { @@ -525,7 +555,7 @@ * Dispatches an event on the `target` element of `type` with the given * `detail`. * @private - * @param {HTMLElement} target The element on which to fire an event. + * @param {EventTarget} target The element on which to fire an event. * @param {string} type The type of event to fire. * @param {Object=} detail The detail object to populate on the event. */ @@ -547,6 +577,7 @@ * * @memberof Polymer.Gestures * @param {string} evName Event name. + * @this {Gestures} */ prevent: function(evName) { let recognizer = this._findRecognizerByEvent(evName); @@ -571,6 +602,8 @@ } }; + /* eslint-disable valid-jsdoc */ + Gestures.register({ name: 'downup', deps: ['mousedown', 'touchstart', 'touchend'], @@ -585,10 +618,15 @@ upfn: null }, + /** @this {GestureRecognizer} */ reset: function() { untrackDocument(this.info); }, + /** + * @this {GestureRecognizer} + * @param {MouseEvent} e + */ mousedown: function(e) { if (!hasLeftMouseButton(e)) { return; @@ -610,12 +648,26 @@ trackDocument(this.info, movefn, upfn); this._fire('down', t, e); }, + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchstart: function(e) { this._fire('down', Gestures._findOriginalTarget(e), e.changedTouches[0], e); }, + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchend: function(e) { this._fire('up', Gestures._findOriginalTarget(e), e.changedTouches[0], e); }, + /** + * @param {string} type + * @param {EventTarget} target + * @param {Event} event + * @param {Function} preventer + */ _fire: function(type, target, event, preventer) { Gestures._fire(target, type, { x: event.clientX, @@ -645,6 +697,7 @@ state: 'start', started: false, moves: [], + /** @this {GestureRecognizer} */ addMove: function(move) { if (this.moves.length > TRACK_LENGTH) { this.moves.shift(); @@ -656,6 +709,7 @@ prevent: false }, + /** @this {GestureRecognizer} */ reset: function() { this.info.state = 'start'; this.info.started = false; @@ -666,6 +720,12 @@ untrackDocument(this.info); }, + /** + * @this {GestureRecognizer} + * @param {number} x + * @param {number} y + * @return {boolean} + */ hasMovedEnough: function(x, y) { if (this.info.prevent) { return false; @@ -677,7 +737,10 @@ let dy = Math.abs(this.info.y - y); return (dx >= TRACK_DISTANCE || dy >= TRACK_DISTANCE); }, - + /** + * @this {GestureRecognizer} + * @param {MouseEvent} e + */ mousedown: function(e) { if (!hasLeftMouseButton(e)) { return; @@ -716,13 +779,19 @@ this.info.x = e.clientX; this.info.y = e.clientY; }, - + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchstart: function(e) { let ct = e.changedTouches[0]; this.info.x = ct.clientX; this.info.y = ct.clientY; }, - + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchmove: function(e) { let t = Gestures._findOriginalTarget(e); let ct = e.changedTouches[0]; @@ -738,7 +807,10 @@ this.info.started = true; } }, - + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchend: function(e) { let t = Gestures._findOriginalTarget(e); let ct = e.changedTouches[0]; @@ -751,6 +823,11 @@ } }, + /** + * @this {GestureRecognizer} + * @param {EventTarget} target + * @param {Touch} touch + */ _fire: function(target, touch) { let secondlast = this.info.moves[this.info.moves.length - 2]; let lastmove = this.info.moves[this.info.moves.length - 1]; @@ -761,7 +838,7 @@ ddx = lastmove.x - secondlast.x; ddy = lastmove.y - secondlast.y; } - return Gestures._fire(target, 'track', { + Gestures._fire(target, 'track', { state: this.info.state, x: touch.clientX, y: touch.clientY, @@ -791,34 +868,54 @@ y: NaN, prevent: false }, + /** @this {GestureRecognizer} */ reset: function() { this.info.x = NaN; this.info.y = NaN; this.info.prevent = false; }, + /** @this {GestureRecognizer} */ save: function(e) { this.info.x = e.clientX; this.info.y = e.clientY; }, - + /** + * @this {GestureRecognizer} + * @param {MouseEvent} e + */ mousedown: function(e) { if (hasLeftMouseButton(e)) { this.save(e); } }, + /** + * @this {GestureRecognizer} + * @param {MouseEvent} e + */ click: function(e) { if (hasLeftMouseButton(e)) { this.forward(e); } }, - + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchstart: function(e) { this.save(e.changedTouches[0], e); }, + /** + * @this {GestureRecognizer} + * @param {TouchEvent} e + */ touchend: function(e) { this.forward(e.changedTouches[0], e); }, - + /** + * @this {GestureRecognizer} + * @param {Event} e + * @param {Function} preventer + */ forward: function(e, preventer) { let dx = Math.abs(e.clientX - this.info.x); let dy = Math.abs(e.clientY - this.info.y); @@ -838,6 +935,8 @@ } }); + /* eslint-enable valid-jsdoc */ + /** @deprecated */ Gestures.findOriginalTarget = Gestures._findOriginalTarget;