Socket
Socket
Sign inDemoInstall

pointer-event

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

19

package.json
{
"name": "pointer-event",
"version": "1.0.0",
"version": "1.0.1",
"title": "PointerEvent",

@@ -14,9 +14,10 @@ "description": "Event Controller for mouse and touch interfaces",

"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"anim-event": "^1.0.16",
"babel-core": "^6.26.3",
"babel-core": "^7.0.0-bridge.0",
"babel-loader": "^7.1.5",
"babel-preset-es2015": "^6.24.1",
"cross-env": "^5.2.0",
"jasmine-core": "^3.2.1",
"log4js": "^3.0.5",
"cross-env": "^7.0.3",
"jasmine-core": "^3.7.1",
"log4js": "^6.3.0",
"node-static-alias": "^1.1.2",

@@ -26,5 +27,5 @@ "pre-proc": "^1.0.2",

"stats-filelist": "^1.0.1",
"test-page-loader": "^1.0.7",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0"
"test-page-loader": "^1.0.8",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},

@@ -31,0 +32,0 @@ "scripts": {

@@ -5,6 +5,8 @@ /* ================================================

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/*

@@ -14,16 +16,14 @@ * PointerEvent

*
* Copyright (c) 2018 anseki
* Copyright (c) 2021 anseki
* Licensed under the MIT license.
*/
import AnimEvent from 'anim-event';
var MOUSE_EMU_INTERVAL = 400; // Avoid mouse events emulation
// [DEBUG]
var traceLog = [];
// [/DEBUG]
var traceLog = []; // [/DEBUG]
// Support options for addEventListener
var passiveSupported = false;
try {

@@ -35,4 +35,5 @@ window.addEventListener('test', null, Object.defineProperty({}, 'passive', {

}));
} catch (error) {} /* ignore */
} catch (error) {
/* ignore */
}
/**

@@ -46,2 +47,4 @@ * addEventListener with specific option.

*/
function addEventListenerWithOptions(target, type, listener, options) {

@@ -52,3 +55,2 @@ // When `passive` is not supported, consider that the `useCapture` is supported instead of

}
/**

@@ -60,2 +62,4 @@ * Get Touch instance in list.

*/
function getTouchById(touches, id) {

@@ -69,5 +73,5 @@ if (touches != null && id != null) {

}
return null;
}
/**

@@ -77,7 +81,9 @@ * @param {Object} xy - Something that might have clientX and clientY.

*/
function hasXY(xy) {
return xy && typeof xy.clientX === 'number' && typeof xy.clientY === 'number';
}
} // Gecko, Trident pick drag-event of some elements such as img, a, etc.
// Gecko, Trident pick drag-event of some elements such as img, a, etc.
function dragstart(event) {

@@ -87,3 +93,3 @@ event.preventDefault();

var PointerEvent = function () {
var PointerEvent = /*#__PURE__*/function () {
/**

@@ -102,10 +108,14 @@ * Create a `PointerEvent` instance.

this.curTouchId = null;
this.lastPointerXY = { clientX: 0, clientY: 0 };
this.lastTouchTime = 0;
this.lastPointerXY = {
clientX: 0,
clientY: 0
};
this.lastTouchTime = 0; // Options
// Options
this.options = { // Default
this.options = {
// Default
preventDefault: true,
stopPropagation: true
};
if (options) {

@@ -119,3 +129,2 @@ ['preventDefault', 'stopPropagation'].forEach(function (option) {

}
/**

@@ -128,15 +137,18 @@ * @param {function} startHandler - This is called with pointerXY when it starts. This returns boolean.

_createClass(PointerEvent, [{
key: 'regStartHandler',
key: "regStartHandler",
value: function regStartHandler(startHandler) {
var that = this;
that.startHandlers[++that.lastHandlerId] = function (event) {
traceLog.push('<startListener>', 'type:' + event.type); // [DEBUG/]
traceLog.push('curPointerClass:' + that.curPointerClass + (that.curPointerClass === 'touch' ? '(#' + that.curTouchId + ')' : '')); // [DEBUG/]
traceLog.push('<startListener>', "type:".concat(event.type)); // [DEBUG/]
traceLog.push("curPointerClass:".concat(that.curPointerClass).concat(that.curPointerClass === 'touch' ? "(#".concat(that.curTouchId, ")") : '')); // [DEBUG/]
var pointerClass = event.type === 'mousedown' ? 'mouse' : 'touch',
now = Date.now();
var pointerXY = void 0,
touchId = void 0;
var pointerXY, touchId;
if (pointerClass === 'touch') {
that.lastTouchTime = now; // Avoid mouse events emulation
pointerXY = event.changedTouches[0];

@@ -147,13 +159,17 @@ touchId = event.changedTouches[0].identifier;

if (now - that.lastTouchTime < MOUSE_EMU_INTERVAL) {
console.warn('Event "' + event.type + '" was ignored.'); // [DEBUG/]
console.warn("Event \"".concat(event.type, "\" was ignored.")); // [DEBUG/]
traceLog.push('CANCEL', '</startListener>'); // [DEBUG/]
return;
}
pointerXY = event;
}
if (!hasXY(pointerXY)) {
throw new Error('No clientX/clientY');
}
} // It is new one even if those are 'mouse' or ID is same, then cancel current one.
// It is new one even if those are 'mouse' or ID is same, then cancel current one.
if (that.curPointerClass) {

@@ -166,9 +182,12 @@ that.cancel();

that.curTouchId = pointerClass === 'touch' ? touchId : null;
traceLog.push('curPointerClass:' + that.curPointerClass + (that.curPointerClass === 'touch' ? '(#' + that.curTouchId + ')' : '')); // [DEBUG/]
traceLog.push("curPointerClass:".concat(that.curPointerClass).concat(that.curPointerClass === 'touch' ? "(#".concat(that.curTouchId, ")") : '')); // [DEBUG/]
that.lastPointerXY.clientX = pointerXY.clientX;
that.lastPointerXY.clientY = pointerXY.clientY;
traceLog.push('lastPointerXY:(' + that.lastPointerXY.clientX + ',' + that.lastPointerXY.clientY + ')'); // [DEBUG/]
traceLog.push("lastPointerXY:(".concat(that.lastPointerXY.clientX, ",").concat(that.lastPointerXY.clientY, ")")); // [DEBUG/]
if (that.options.preventDefault) {
event.preventDefault();
}
if (that.options.stopPropagation) {

@@ -178,7 +197,8 @@ event.stopPropagation();

}
traceLog.push('</startListener>'); // [DEBUG/]
};
return that.lastHandlerId;
}
/**

@@ -190,7 +210,6 @@ * @param {number} handlerId - An ID which was returned by regStartHandler.

}, {
key: 'unregStartHandler',
key: "unregStartHandler",
value: function unregStartHandler(handlerId) {
delete this.startHandlers[handlerId];
}
/**

@@ -203,13 +222,22 @@ * @param {Element} element - A target element.

}, {
key: 'addStartHandler',
key: "addStartHandler",
value: function addStartHandler(element, handlerId) {
if (!this.startHandlers[handlerId]) {
throw new Error('Invalid handlerId: ' + handlerId);
throw new Error("Invalid handlerId: ".concat(handlerId));
}
addEventListenerWithOptions(element, 'mousedown', this.startHandlers[handlerId], { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchstart', this.startHandlers[handlerId], { capture: false, passive: false });
addEventListenerWithOptions(element, 'dragstart', dragstart, { capture: false, passive: false });
addEventListenerWithOptions(element, 'mousedown', this.startHandlers[handlerId], {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'touchstart', this.startHandlers[handlerId], {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'dragstart', dragstart, {
capture: false,
passive: false
});
return handlerId;
}
/**

@@ -222,7 +250,8 @@ * @param {Element} element - A target element.

}, {
key: 'removeStartHandler',
key: "removeStartHandler",
value: function removeStartHandler(element, handlerId) {
if (!this.startHandlers[handlerId]) {
throw new Error('Invalid handlerId: ' + handlerId);
throw new Error("Invalid handlerId: ".concat(handlerId));
}
element.removeEventListener('mousedown', this.startHandlers[handlerId], false);

@@ -233,3 +262,2 @@ element.removeEventListener('touchstart', this.startHandlers[handlerId], false);

}
/**

@@ -242,14 +270,18 @@ * @param {Element} element - A target element.

}, {
key: 'addMoveHandler',
key: "addMoveHandler",
value: function addMoveHandler(element, moveHandler) {
var that = this;
AnimEvent.add = function (listener) {
return listener;
}; // Disable AnimEvent [DEBUG/]
var wrappedHandler = AnimEvent.add(function (event) {
traceLog.push('<moveListener>', 'type:' + event.type); // [DEBUG/]
traceLog.push('curPointerClass:' + that.curPointerClass + (that.curPointerClass === 'touch' ? '(#' + that.curTouchId + ')' : '')); // [DEBUG/]
var pointerClass = event.type === 'mousemove' ? 'mouse' : 'touch';
traceLog.push('<moveListener>', "type:".concat(event.type)); // [DEBUG/]
// Avoid mouse events emulation
traceLog.push("curPointerClass:".concat(that.curPointerClass).concat(that.curPointerClass === 'touch' ? "(#".concat(that.curTouchId, ")") : '')); // [DEBUG/]
var pointerClass = event.type === 'mousemove' ? 'mouse' : 'touch'; // Avoid mouse events emulation
if (pointerClass === 'touch') {

@@ -261,5 +293,8 @@ that.lastTouchTime = Date.now();

var pointerXY = pointerClass === 'touch' ? getTouchById(event.changedTouches, that.curTouchId) : event;
if (pointerClass === 'touch' && !pointerXY) {
traceLog.push('NOT-FOUND-TOUCH(#' + that.curTouchId + ')');
traceLog.push("NOT-FOUND-TOUCH(#".concat(that.curTouchId, ")"));
} // [DEBUG/]
if (hasXY(pointerXY)) {

@@ -272,5 +307,7 @@ if (pointerXY.clientX !== that.lastPointerXY.clientX || pointerXY.clientY !== that.lastPointerXY.clientY) {

}
if (that.options.preventDefault) {
event.preventDefault();
}
if (that.options.stopPropagation) {

@@ -281,9 +318,15 @@ event.stopPropagation();

}
traceLog.push('</moveListener>'); // [DEBUG/]
});
addEventListenerWithOptions(element, 'mousemove', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchmove', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'mousemove', wrappedHandler, {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'touchmove', wrappedHandler, {
capture: false,
passive: false
});
that.curMoveHandler = moveHandler;
}
/**

@@ -295,9 +338,10 @@ * @param {{clientX, clientY}} [pointerXY] - This might be MouseEvent, Touch of TouchEvent or Object.

}, {
key: 'move',
key: "move",
value: function move(pointerXY) {
traceLog.push('<move>'); // [DEBUG/]
if (hasXY(pointerXY)) {
this.lastPointerXY.clientX = pointerXY.clientX;
this.lastPointerXY.clientY = pointerXY.clientY;
traceLog.push('lastPointerXY:(' + this.lastPointerXY.clientX + ',' + this.lastPointerXY.clientY + ')'); // [DEBUG/]
traceLog.push("lastPointerXY:(".concat(this.lastPointerXY.clientX, ",").concat(this.lastPointerXY.clientY, ")")); // [DEBUG/]
} else {

@@ -307,8 +351,9 @@ // [DEBUG/]

}
if (this.curMoveHandler) {
this.curMoveHandler(this.lastPointerXY);
}
traceLog.push('</move>'); // [DEBUG/]
}
/**

@@ -321,11 +366,13 @@ * @param {Element} element - A target element.

}, {
key: 'addEndHandler',
key: "addEndHandler",
value: function addEndHandler(element, endHandler) {
var that = this;
function wrappedHandler(event) {
traceLog.push('<endListener>', 'type:' + event.type); // [DEBUG/]
traceLog.push('curPointerClass:' + that.curPointerClass + (that.curPointerClass === 'touch' ? '(#' + that.curTouchId + ')' : '')); // [DEBUG/]
var pointerClass = event.type === 'mouseup' ? 'mouse' : 'touch';
traceLog.push('<endListener>', "type:".concat(event.type)); // [DEBUG/]
// Avoid mouse events emulation
traceLog.push("curPointerClass:".concat(that.curPointerClass).concat(that.curPointerClass === 'touch' ? "(#".concat(that.curTouchId, ")") : '')); // [DEBUG/]
var pointerClass = event.type === 'mouseup' ? 'mouse' : 'touch'; // Avoid mouse events emulation
if (pointerClass === 'touch') {

@@ -336,20 +383,28 @@ that.lastTouchTime = Date.now();

if (pointerClass === that.curPointerClass) {
var pointerXY = pointerClass === 'touch' ? getTouchById(event.changedTouches, that.curTouchId) || (
// It might have been removed from `touches` even if it is not in `changedTouches`.
var pointerXY = pointerClass === 'touch' ? getTouchById(event.changedTouches, that.curTouchId) || ( // It might have been removed from `touches` even if it is not in `changedTouches`.
getTouchById(event.touches, that.curTouchId) ? null : {}) : // `{}` means matching
event;
if (pointerClass === 'touch' && (!pointerXY || pointerXY.identifier == null)) {
traceLog.push('CHECKED:event.touches');
} // [DEBUG/]
if (pointerClass === 'touch' && !pointerXY) {
traceLog.push('NOT-FOUND-TOUCH(#' + that.curTouchId + ')');
traceLog.push("NOT-FOUND-TOUCH(#".concat(that.curTouchId, ")"));
} // [DEBUG/]
if (pointerXY) {
if (!hasXY(pointerXY)) {
console.log('No pointerXY in event "' + event.type + '".');
console.log("No pointerXY in event \"".concat(event.type, "\"."));
} // [DEBUG/]
that.end(pointerXY);
if (that.options.preventDefault) {
event.preventDefault();
}
if (that.options.stopPropagation) {

@@ -360,9 +415,16 @@ event.stopPropagation();

}
traceLog.push('</endListener>'); // [DEBUG/]
}
addEventListenerWithOptions(element, 'mouseup', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchend', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'mouseup', wrappedHandler, {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'touchend', wrappedHandler, {
capture: false,
passive: false
});
that.curEndHandler = endHandler;
}
/**

@@ -374,9 +436,10 @@ * @param {{clientX, clientY}} [pointerXY] - This might be MouseEvent, Touch of TouchEvent or Object.

}, {
key: 'end',
key: "end",
value: function end(pointerXY) {
traceLog.push('<end>'); // [DEBUG/]
if (hasXY(pointerXY)) {
this.lastPointerXY.clientX = pointerXY.clientX;
this.lastPointerXY.clientY = pointerXY.clientY;
traceLog.push('lastPointerXY:(' + this.lastPointerXY.clientX + ',' + this.lastPointerXY.clientY + ')'); // [DEBUG/]
traceLog.push("lastPointerXY:(".concat(this.lastPointerXY.clientX, ",").concat(this.lastPointerXY.clientY, ")")); // [DEBUG/]
} else {

@@ -386,10 +449,12 @@ // [DEBUG/]

}
if (this.curEndHandler) {
this.curEndHandler(this.lastPointerXY);
}
this.curPointerClass = this.curTouchId = null;
traceLog.push('curPointerClass:' + this.curPointerClass); // [DEBUG/]
traceLog.push("curPointerClass:".concat(this.curPointerClass)); // [DEBUG/]
traceLog.push('</end>'); // [DEBUG/]
}
/**

@@ -402,8 +467,11 @@ * @param {Element} element - A target element.

}, {
key: 'addCancelHandler',
key: "addCancelHandler",
value: function addCancelHandler(element, cancelHandler) {
var that = this;
function wrappedHandler(event) {
traceLog.push('<cancelListener>', 'type:' + event.type); // [DEBUG/]
traceLog.push('curPointerClass:' + that.curPointerClass + (that.curPointerClass === 'touch' ? '(#' + that.curTouchId + ')' : '')); // [DEBUG/]
traceLog.push('<cancelListener>', "type:".concat(event.type)); // [DEBUG/]
traceLog.push("curPointerClass:".concat(that.curPointerClass).concat(that.curPointerClass === 'touch' ? "(#".concat(that.curTouchId, ")") : '')); // [DEBUG/]
/*

@@ -417,11 +485,15 @@ Now, this is fired by touchcancel only, but it might be fired even if curPointerClass is mouse.

if (that.curPointerClass != null) {
var pointerXY = getTouchById(event.changedTouches, that.curTouchId) || (
// It might have been removed from `touches` even if it is not in `changedTouches`.
var pointerXY = getTouchById(event.changedTouches, that.curTouchId) || ( // It might have been removed from `touches` even if it is not in `changedTouches`.
getTouchById(event.touches, that.curTouchId) ? null : {}); // `{}` means matching
if (!pointerXY || pointerXY.identifier == null) {
traceLog.push('CHECKED:event.touches');
} // [DEBUG/]
if (!pointerXY) {
traceLog.push('NOT-FOUND-TOUCH(#' + that.curTouchId + ')');
traceLog.push("NOT-FOUND-TOUCH(#".concat(that.curTouchId, ")"));
} // [DEBUG/]
if (pointerXY) {

@@ -431,8 +503,12 @@ that.cancel();

}
traceLog.push('</cancelListener>'); // [DEBUG/]
}
addEventListenerWithOptions(element, 'touchcancel', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchcancel', wrappedHandler, {
capture: false,
passive: false
});
that.curCancelHandler = cancelHandler;
}
/**

@@ -443,14 +519,17 @@ * @returns {void}

}, {
key: 'cancel',
key: "cancel",
value: function cancel() {
traceLog.push('<cancel>'); // [DEBUG/]
if (this.curCancelHandler) {
this.curCancelHandler();
}
this.curPointerClass = this.curTouchId = null;
traceLog.push('curPointerClass:' + this.curPointerClass); // [DEBUG/]
traceLog.push("curPointerClass:".concat(this.curPointerClass)); // [DEBUG/]
traceLog.push('</cancel>'); // [DEBUG/]
}
}], [{
key: 'addEventListenerWithOptions',
key: "addEventListenerWithOptions",
get: function get() {

@@ -462,11 +541,8 @@ return addEventListenerWithOptions;

return PointerEvent;
}();
}(); // [DEBUG]
// [DEBUG]
PointerEvent.traceLog = traceLog;
PointerEvent.MOUSE_EMU_INTERVAL = MOUSE_EMU_INTERVAL;
// [/DEBUG]
PointerEvent.MOUSE_EMU_INTERVAL = MOUSE_EMU_INTERVAL; // [/DEBUG]
export default PointerEvent;

@@ -5,6 +5,8 @@ /* ================================================

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/*

@@ -14,13 +16,11 @@ * PointerEvent

*
* Copyright (c) 2018 anseki
* Copyright (c) 2021 anseki
* Licensed under the MIT license.
*/
import AnimEvent from 'anim-event';
var MOUSE_EMU_INTERVAL = 400; // Avoid mouse events emulation
// Support options for addEventListener
var passiveSupported = false;
// Support options for addEventListener
var passiveSupported = false;
try {

@@ -32,4 +32,5 @@ window.addEventListener('test', null, Object.defineProperty({}, 'passive', {

}));
} catch (error) {} /* ignore */
} catch (error) {
/* ignore */
}
/**

@@ -43,2 +44,4 @@ * addEventListener with specific option.

*/
function addEventListenerWithOptions(target, type, listener, options) {

@@ -49,3 +52,2 @@ // When `passive` is not supported, consider that the `useCapture` is supported instead of

}
/**

@@ -57,2 +59,4 @@ * Get Touch instance in list.

*/
function getTouchById(touches, id) {

@@ -66,5 +70,5 @@ if (touches != null && id != null) {

}
return null;
}
/**

@@ -74,7 +78,9 @@ * @param {Object} xy - Something that might have clientX and clientY.

*/
function hasXY(xy) {
return xy && typeof xy.clientX === 'number' && typeof xy.clientY === 'number';
}
} // Gecko, Trident pick drag-event of some elements such as img, a, etc.
// Gecko, Trident pick drag-event of some elements such as img, a, etc.
function dragstart(event) {

@@ -84,3 +90,3 @@ event.preventDefault();

var PointerEvent = function () {
var PointerEvent = /*#__PURE__*/function () {
/**

@@ -99,10 +105,14 @@ * Create a `PointerEvent` instance.

this.curTouchId = null;
this.lastPointerXY = { clientX: 0, clientY: 0 };
this.lastTouchTime = 0;
this.lastPointerXY = {
clientX: 0,
clientY: 0
};
this.lastTouchTime = 0; // Options
// Options
this.options = { // Default
this.options = {
// Default
preventDefault: true,
stopPropagation: true
};
if (options) {

@@ -116,3 +126,2 @@ ['preventDefault', 'stopPropagation'].forEach(function (option) {

}
/**

@@ -125,13 +134,14 @@ * @param {function} startHandler - This is called with pointerXY when it starts. This returns boolean.

_createClass(PointerEvent, [{
key: 'regStartHandler',
key: "regStartHandler",
value: function regStartHandler(startHandler) {
var that = this;
that.startHandlers[++that.lastHandlerId] = function (event) {
var pointerClass = event.type === 'mousedown' ? 'mouse' : 'touch',
now = Date.now();
var pointerXY = void 0,
touchId = void 0;
var pointerXY, touchId;
if (pointerClass === 'touch') {
that.lastTouchTime = now; // Avoid mouse events emulation
pointerXY = event.changedTouches[0];

@@ -144,9 +154,11 @@ touchId = event.changedTouches[0].identifier;

}
pointerXY = event;
}
if (!hasXY(pointerXY)) {
throw new Error('No clientX/clientY');
}
} // It is new one even if those are 'mouse' or ID is same, then cancel current one.
// It is new one even if those are 'mouse' or ID is same, then cancel current one.
if (that.curPointerClass) {

@@ -161,5 +173,7 @@ that.cancel();

that.lastPointerXY.clientY = pointerXY.clientY;
if (that.options.preventDefault) {
event.preventDefault();
}
if (that.options.stopPropagation) {

@@ -170,5 +184,5 @@ event.stopPropagation();

};
return that.lastHandlerId;
}
/**

@@ -180,7 +194,6 @@ * @param {number} handlerId - An ID which was returned by regStartHandler.

}, {
key: 'unregStartHandler',
key: "unregStartHandler",
value: function unregStartHandler(handlerId) {
delete this.startHandlers[handlerId];
}
/**

@@ -193,13 +206,22 @@ * @param {Element} element - A target element.

}, {
key: 'addStartHandler',
key: "addStartHandler",
value: function addStartHandler(element, handlerId) {
if (!this.startHandlers[handlerId]) {
throw new Error('Invalid handlerId: ' + handlerId);
throw new Error("Invalid handlerId: ".concat(handlerId));
}
addEventListenerWithOptions(element, 'mousedown', this.startHandlers[handlerId], { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchstart', this.startHandlers[handlerId], { capture: false, passive: false });
addEventListenerWithOptions(element, 'dragstart', dragstart, { capture: false, passive: false });
addEventListenerWithOptions(element, 'mousedown', this.startHandlers[handlerId], {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'touchstart', this.startHandlers[handlerId], {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'dragstart', dragstart, {
capture: false,
passive: false
});
return handlerId;
}
/**

@@ -212,7 +234,8 @@ * @param {Element} element - A target element.

}, {
key: 'removeStartHandler',
key: "removeStartHandler",
value: function removeStartHandler(element, handlerId) {
if (!this.startHandlers[handlerId]) {
throw new Error('Invalid handlerId: ' + handlerId);
throw new Error("Invalid handlerId: ".concat(handlerId));
}
element.removeEventListener('mousedown', this.startHandlers[handlerId], false);

@@ -223,3 +246,2 @@ element.removeEventListener('touchstart', this.startHandlers[handlerId], false);

}
/**

@@ -232,9 +254,8 @@ * @param {Element} element - A target element.

}, {
key: 'addMoveHandler',
key: "addMoveHandler",
value: function addMoveHandler(element, moveHandler) {
var that = this;
var wrappedHandler = AnimEvent.add(function (event) {
var pointerClass = event.type === 'mousemove' ? 'mouse' : 'touch';
var pointerClass = event.type === 'mousemove' ? 'mouse' : 'touch'; // Avoid mouse events emulation
// Avoid mouse events emulation
if (pointerClass === 'touch') {

@@ -246,2 +267,3 @@ that.lastTouchTime = Date.now();

var pointerXY = pointerClass === 'touch' ? getTouchById(event.changedTouches, that.curTouchId) : event;
if (hasXY(pointerXY)) {

@@ -251,5 +273,7 @@ if (pointerXY.clientX !== that.lastPointerXY.clientX || pointerXY.clientY !== that.lastPointerXY.clientY) {

}
if (that.options.preventDefault) {
event.preventDefault();
}
if (that.options.stopPropagation) {

@@ -261,7 +285,12 @@ event.stopPropagation();

});
addEventListenerWithOptions(element, 'mousemove', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchmove', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'mousemove', wrappedHandler, {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'touchmove', wrappedHandler, {
capture: false,
passive: false
});
that.curMoveHandler = moveHandler;
}
/**

@@ -273,3 +302,3 @@ * @param {{clientX, clientY}} [pointerXY] - This might be MouseEvent, Touch of TouchEvent or Object.

}, {
key: 'move',
key: "move",
value: function move(pointerXY) {

@@ -280,2 +309,3 @@ if (hasXY(pointerXY)) {

}
if (this.curMoveHandler) {

@@ -285,3 +315,2 @@ this.curMoveHandler(this.lastPointerXY);

}
/**

@@ -294,9 +323,9 @@ * @param {Element} element - A target element.

}, {
key: 'addEndHandler',
key: "addEndHandler",
value: function addEndHandler(element, endHandler) {
var that = this;
function wrappedHandler(event) {
var pointerClass = event.type === 'mouseup' ? 'mouse' : 'touch';
var pointerClass = event.type === 'mouseup' ? 'mouse' : 'touch'; // Avoid mouse events emulation
// Avoid mouse events emulation
if (pointerClass === 'touch') {

@@ -307,11 +336,13 @@ that.lastTouchTime = Date.now();

if (pointerClass === that.curPointerClass) {
var pointerXY = pointerClass === 'touch' ? getTouchById(event.changedTouches, that.curTouchId) || (
// It might have been removed from `touches` even if it is not in `changedTouches`.
var pointerXY = pointerClass === 'touch' ? getTouchById(event.changedTouches, that.curTouchId) || ( // It might have been removed from `touches` even if it is not in `changedTouches`.
getTouchById(event.touches, that.curTouchId) ? null : {}) : // `{}` means matching
event;
if (pointerXY) {
that.end(pointerXY);
if (that.options.preventDefault) {
event.preventDefault();
}
if (that.options.stopPropagation) {

@@ -323,7 +354,13 @@ event.stopPropagation();

}
addEventListenerWithOptions(element, 'mouseup', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchend', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'mouseup', wrappedHandler, {
capture: false,
passive: false
});
addEventListenerWithOptions(element, 'touchend', wrappedHandler, {
capture: false,
passive: false
});
that.curEndHandler = endHandler;
}
/**

@@ -335,3 +372,3 @@ * @param {{clientX, clientY}} [pointerXY] - This might be MouseEvent, Touch of TouchEvent or Object.

}, {
key: 'end',
key: "end",
value: function end(pointerXY) {

@@ -342,8 +379,9 @@ if (hasXY(pointerXY)) {

}
if (this.curEndHandler) {
this.curEndHandler(this.lastPointerXY);
}
this.curPointerClass = this.curTouchId = null;
}
/**

@@ -356,5 +394,6 @@ * @param {Element} element - A target element.

}, {
key: 'addCancelHandler',
key: "addCancelHandler",
value: function addCancelHandler(element, cancelHandler) {
var that = this;
function wrappedHandler(event) {

@@ -365,9 +404,8 @@ /*

// const pointerClass = 'touch';
that.lastTouchTime = Date.now(); // Avoid mouse events emulation
if (that.curPointerClass != null) {
var pointerXY = getTouchById(event.changedTouches, that.curTouchId) || (
// It might have been removed from `touches` even if it is not in `changedTouches`.
var pointerXY = getTouchById(event.changedTouches, that.curTouchId) || ( // It might have been removed from `touches` even if it is not in `changedTouches`.
getTouchById(event.touches, that.curTouchId) ? null : {}); // `{}` means matching
if (pointerXY) {

@@ -378,6 +416,9 @@ that.cancel();

}
addEventListenerWithOptions(element, 'touchcancel', wrappedHandler, { capture: false, passive: false });
addEventListenerWithOptions(element, 'touchcancel', wrappedHandler, {
capture: false,
passive: false
});
that.curCancelHandler = cancelHandler;
}
/**

@@ -388,3 +429,3 @@ * @returns {void}

}, {
key: 'cancel',
key: "cancel",
value: function cancel() {

@@ -394,6 +435,7 @@ if (this.curCancelHandler) {

}
this.curPointerClass = this.curTouchId = null;
}
}], [{
key: 'addEventListenerWithOptions',
key: "addEventListenerWithOptions",
get: function get() {

@@ -400,0 +442,0 @@ return addEventListenerWithOptions;

@@ -1,2 +0,2 @@

/*! PointerEvent v1.0.0 (c) anseki https://github.com/anseki/pointer-event */
var PointerEvent=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);var r=500,o=[],i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return setTimeout(e,1e3/60)},a=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame||function(e){return clearTimeout(e)},u=Date.now(),l=void 0;function c(){var e=void 0,t=void 0;l&&(a.call(window,l),l=null),o.forEach(function(t){var n;(n=t.event)&&(t.event=null,t.listener(n),e=!0)}),e?(u=Date.now(),t=!0):Date.now()-u<r&&(t=!0),t&&(l=i.call(window,c))}function s(e){var t=-1;return o.some(function(n,r){return n.listener===e&&(t=r,!0)}),t}var d={add:function(e){var t=void 0;return-1===s(e)?(o.push(t={listener:e}),function(e){t.event=e,l||c()}):null},remove:function(e){var t;(t=s(e))>-1&&(o.splice(t,1),!o.length&&l&&(a.call(window,l),l=null))}},f=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var h=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){h=!0}}))}catch(e){}function v(e,t,n,r){e.addEventListener(t,n,h?r:r.capture)}function p(e,t){if(null!=e&&null!=t)for(var n=0;n<e.length;n++)if(e[n].identifier===t)return e[n];return null}function m(e){return e&&"number"==typeof e.clientX&&"number"==typeof e.clientY}function w(e){e.preventDefault()}var y=function(){function e(t){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.startHandlers={},this.lastHandlerId=0,this.curPointerClass=null,this.curTouchId=null,this.lastPointerXY={clientX:0,clientY:0},this.lastTouchTime=0,this.options={preventDefault:!0,stopPropagation:!0},t&&["preventDefault","stopPropagation"].forEach(function(e){"boolean"==typeof t[e]&&(n.options[e]=t[e])})}return f(e,[{key:"regStartHandler",value:function(e){var t=this;return t.startHandlers[++t.lastHandlerId]=function(n){var r="mousedown"===n.type?"mouse":"touch",o=Date.now(),i=void 0,a=void 0;if("touch"===r)t.lastTouchTime=o,i=n.changedTouches[0],a=n.changedTouches[0].identifier;else{if(o-t.lastTouchTime<400)return;i=n}if(!m(i))throw new Error("No clientX/clientY");t.curPointerClass&&t.cancel(),e.call(t,i)&&(t.curPointerClass=r,t.curTouchId="touch"===r?a:null,t.lastPointerXY.clientX=i.clientX,t.lastPointerXY.clientY=i.clientY,t.options.preventDefault&&n.preventDefault(),t.options.stopPropagation&&n.stopPropagation())},t.lastHandlerId}},{key:"unregStartHandler",value:function(e){delete this.startHandlers[e]}},{key:"addStartHandler",value:function(e,t){if(!this.startHandlers[t])throw new Error("Invalid handlerId: "+t);return v(e,"mousedown",this.startHandlers[t],{capture:!1,passive:!1}),v(e,"touchstart",this.startHandlers[t],{capture:!1,passive:!1}),v(e,"dragstart",w,{capture:!1,passive:!1}),t}},{key:"removeStartHandler",value:function(e,t){if(!this.startHandlers[t])throw new Error("Invalid handlerId: "+t);return e.removeEventListener("mousedown",this.startHandlers[t],!1),e.removeEventListener("touchstart",this.startHandlers[t],!1),e.removeEventListener("dragstart",w,!1),t}},{key:"addMoveHandler",value:function(e,t){var n=this,r=d.add(function(e){var t="mousemove"===e.type?"mouse":"touch";if("touch"===t&&(n.lastTouchTime=Date.now()),t===n.curPointerClass){var r="touch"===t?p(e.changedTouches,n.curTouchId):e;m(r)&&(r.clientX===n.lastPointerXY.clientX&&r.clientY===n.lastPointerXY.clientY||n.move(r),n.options.preventDefault&&e.preventDefault(),n.options.stopPropagation&&e.stopPropagation())}});v(e,"mousemove",r,{capture:!1,passive:!1}),v(e,"touchmove",r,{capture:!1,passive:!1}),n.curMoveHandler=t}},{key:"move",value:function(e){m(e)&&(this.lastPointerXY.clientX=e.clientX,this.lastPointerXY.clientY=e.clientY),this.curMoveHandler&&this.curMoveHandler(this.lastPointerXY)}},{key:"addEndHandler",value:function(e,t){var n=this;function r(e){var t="mouseup"===e.type?"mouse":"touch";if("touch"===t&&(n.lastTouchTime=Date.now()),t===n.curPointerClass){var r="touch"===t?p(e.changedTouches,n.curTouchId)||(p(e.touches,n.curTouchId)?null:{}):e;r&&(n.end(r),n.options.preventDefault&&e.preventDefault(),n.options.stopPropagation&&e.stopPropagation())}}v(e,"mouseup",r,{capture:!1,passive:!1}),v(e,"touchend",r,{capture:!1,passive:!1}),n.curEndHandler=t}},{key:"end",value:function(e){m(e)&&(this.lastPointerXY.clientX=e.clientX,this.lastPointerXY.clientY=e.clientY),this.curEndHandler&&this.curEndHandler(this.lastPointerXY),this.curPointerClass=this.curTouchId=null}},{key:"addCancelHandler",value:function(e,t){var n=this;v(e,"touchcancel",function(e){n.lastTouchTime=Date.now(),null!=n.curPointerClass&&(p(e.changedTouches,n.curTouchId)||!p(e.touches,n.curTouchId))&&n.cancel()},{capture:!1,passive:!1}),n.curCancelHandler=t}},{key:"cancel",value:function(){this.curCancelHandler&&this.curCancelHandler(),this.curPointerClass=this.curTouchId=null}}],[{key:"addEventListenerWithOptions",get:function(){return v}}]),e}();t.default=y}]).default;
/*! PointerEvent v1.0.1 (c) anseki https://github.com/anseki/pointer-event */
var PointerEvent=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);var r=[],o=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return setTimeout(e,1e3/60)},a=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame||function(e){return clearTimeout(e)},i=Date.now(),u=void 0;function l(){var e=void 0,t=void 0;u&&(a.call(window,u),u=null),r.forEach((function(t){var n;(n=t.event)&&(t.event=null,t.listener(n),e=!0)})),e?(i=Date.now(),t=!0):Date.now()-i<500&&(t=!0),t&&(u=o.call(window,l))}function c(e){var t=-1;return r.some((function(n,r){return n.listener===e&&(t=r,!0)})),t}var s={add:function(e){var t=void 0;return-1===c(e)?(r.push(t={listener:e}),function(e){t.event=e,u||l()}):null},remove:function(e){var t;(t=c(e))>-1&&(r.splice(t,1),!r.length&&u&&(a.call(window,u),u=null))}};function d(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var f=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){f=!0}}))}catch(e){}function h(e,t,n,r){e.addEventListener(t,n,f?r:r.capture)}function v(e,t){if(null!=e&&null!=t)for(var n=0;n<e.length;n++)if(e[n].identifier===t)return e[n];return null}function p(e){return e&&"number"==typeof e.clientX&&"number"==typeof e.clientY}function m(e){e.preventDefault()}var w=function(){function e(t){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.startHandlers={},this.lastHandlerId=0,this.curPointerClass=null,this.curTouchId=null,this.lastPointerXY={clientX:0,clientY:0},this.lastTouchTime=0,this.options={preventDefault:!0,stopPropagation:!0},t&&["preventDefault","stopPropagation"].forEach((function(e){"boolean"==typeof t[e]&&(n.options[e]=t[e])}))}var t,n,r;return t=e,r=[{key:"addEventListenerWithOptions",get:function(){return h}}],(n=[{key:"regStartHandler",value:function(e){var t=this;return t.startHandlers[++t.lastHandlerId]=function(n){var r,o,a="mousedown"===n.type?"mouse":"touch",i=Date.now();if("touch"===a)t.lastTouchTime=i,r=n.changedTouches[0],o=n.changedTouches[0].identifier;else{if(i-t.lastTouchTime<400)return;r=n}if(!p(r))throw new Error("No clientX/clientY");t.curPointerClass&&t.cancel(),e.call(t,r)&&(t.curPointerClass=a,t.curTouchId="touch"===a?o:null,t.lastPointerXY.clientX=r.clientX,t.lastPointerXY.clientY=r.clientY,t.options.preventDefault&&n.preventDefault(),t.options.stopPropagation&&n.stopPropagation())},t.lastHandlerId}},{key:"unregStartHandler",value:function(e){delete this.startHandlers[e]}},{key:"addStartHandler",value:function(e,t){if(!this.startHandlers[t])throw new Error("Invalid handlerId: ".concat(t));return h(e,"mousedown",this.startHandlers[t],{capture:!1,passive:!1}),h(e,"touchstart",this.startHandlers[t],{capture:!1,passive:!1}),h(e,"dragstart",m,{capture:!1,passive:!1}),t}},{key:"removeStartHandler",value:function(e,t){if(!this.startHandlers[t])throw new Error("Invalid handlerId: ".concat(t));return e.removeEventListener("mousedown",this.startHandlers[t],!1),e.removeEventListener("touchstart",this.startHandlers[t],!1),e.removeEventListener("dragstart",m,!1),t}},{key:"addMoveHandler",value:function(e,t){var n=this,r=s.add((function(e){var t="mousemove"===e.type?"mouse":"touch";if("touch"===t&&(n.lastTouchTime=Date.now()),t===n.curPointerClass){var r="touch"===t?v(e.changedTouches,n.curTouchId):e;p(r)&&(r.clientX===n.lastPointerXY.clientX&&r.clientY===n.lastPointerXY.clientY||n.move(r),n.options.preventDefault&&e.preventDefault(),n.options.stopPropagation&&e.stopPropagation())}}));h(e,"mousemove",r,{capture:!1,passive:!1}),h(e,"touchmove",r,{capture:!1,passive:!1}),n.curMoveHandler=t}},{key:"move",value:function(e){p(e)&&(this.lastPointerXY.clientX=e.clientX,this.lastPointerXY.clientY=e.clientY),this.curMoveHandler&&this.curMoveHandler(this.lastPointerXY)}},{key:"addEndHandler",value:function(e,t){var n=this;function r(e){var t="mouseup"===e.type?"mouse":"touch";if("touch"===t&&(n.lastTouchTime=Date.now()),t===n.curPointerClass){var r="touch"===t?v(e.changedTouches,n.curTouchId)||(v(e.touches,n.curTouchId)?null:{}):e;r&&(n.end(r),n.options.preventDefault&&e.preventDefault(),n.options.stopPropagation&&e.stopPropagation())}}h(e,"mouseup",r,{capture:!1,passive:!1}),h(e,"touchend",r,{capture:!1,passive:!1}),n.curEndHandler=t}},{key:"end",value:function(e){p(e)&&(this.lastPointerXY.clientX=e.clientX,this.lastPointerXY.clientY=e.clientY),this.curEndHandler&&this.curEndHandler(this.lastPointerXY),this.curPointerClass=this.curTouchId=null}},{key:"addCancelHandler",value:function(e,t){var n=this;h(e,"touchcancel",(function(e){n.lastTouchTime=Date.now(),null!=n.curPointerClass&&(v(e.changedTouches,n.curTouchId)||!v(e.touches,n.curTouchId))&&n.cancel()}),{capture:!1,passive:!1}),n.curCancelHandler=t}},{key:"cancel",value:function(){this.curCancelHandler&&this.curCancelHandler(),this.curPointerClass=this.curTouchId=null}}])&&d(t.prototype,n),r&&d(t,r),e}();t.default=w}]).default;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc