Socket
Socket
Sign inDemoInstall

pressure

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.3 to 2.1.0

src/adapters/adapter_pointer.js

12

bower.json

@@ -5,6 +5,7 @@ {

"main": "dist/pressure.min.js",
"homepage": "https://github.com/stuyam/pressure",
"license": "MIT",
"authors": [
"Stuart Yamartino"
],
"license": "MIT",
"keywords": [

@@ -24,4 +25,7 @@ "forcetouch",

],
"homepage": "https://github.com/stuyam/pressure",
"moduleType": [],
"moduleType": [
"amd",
"globals",
"node"
],
"ignore": [

@@ -34,3 +38,3 @@ "**/.*",

],
"version": "2.0.3"
"version": "2.1.0"
}

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

// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016
// Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017
;(function(root, factory) {

@@ -55,14 +55,18 @@ if (typeof define === 'function' && define.amd) {

var type = Config.get('only', options);
// if on desktop and requesting Force Touch or not requesting 3D Touch
if (isDesktop && (type === 'desktop' || type !== 'mobile')) {
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
// for devices that support pointer events
if (supportsPointer && (type === 'pointer' || type === null)) {
this.adapter = new AdapterPointer(el, block, options).bindEvents();
}
// if on mobile and requesting 3D Touch or not requestion Force Touch
else if (isMobile && (type === 'mobile' || type !== 'desktop')) {
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
// for devices that support Force Touch
else if (supportsMouse && (type === 'mouse' || type === null)) {
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
}
// unsupported if it is requesting a type and your browser is of other type
else {
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
// for devices that support 3D Touch
else if (supportsTouch && (type === 'touch' || type === null)) {
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
}
// unsupported if it is requesting a type and your browser is of other type
else {
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
}
}

@@ -103,2 +107,3 @@

this.nativeSupport = false;
this.runningPolyfill = false;
this.runKey = Math.random();

@@ -156,3 +161,3 @@ }

this.add(isMobile ? 'touchstart' : 'mousedown', function (event) {
this.add(supportsTouch ? 'touchstart' : 'mousedown', function (event) {
return _this.runClosure('unsupported', event);

@@ -165,2 +170,3 @@ });

if (this.isPressed() === false) {
this.runningPolyfill = false;
this.setPressed(true);

@@ -195,17 +201,29 @@ this.runClosure('start', event);

value: function _endPress() {
if (this.isPressed()) {
this._endDeepPress();
if (this.runningPolyfill === false) {
if (this.isPressed()) {
this._endDeepPress();
this.setPressed(false);
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
} else {
this.setPressed(false);
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
}
}, {
key: 'deepPress',
value: function deepPress(force, event) {
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
}
}, {
key: 'runPolyfill',
value: function runPolyfill(event) {
this.increment = 10 / Config.get('polyfillSpeed', this.options);
this.increment = Config.get('polyfillSpeedUp', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedUp', this.options);
this.decrement = Config.get('polyfillSpeedDown', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedDown', this.options);
this.setPressed(true);
this.runClosure('start', event);
this.loopPolyfillForce(0, event);
if (this.runningPolyfill === false) {
this.loopPolyfillForce(0, event);
}
}

@@ -215,7 +233,25 @@ }, {

value: function loopPolyfillForce(force, event) {
if (this.isPressed() && this.nativeSupport === false) {
this.runClosure('change', force, event);
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
force = force + this.increment > 1 ? 1 : force + this.increment;
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
if (this.nativeSupport === false) {
if (this.isPressed()) {
this.runningPolyfill = true;
force = force + this.increment > 1 ? 1 : force + this.increment;
this.runClosure('change', force, event);
this.deepPress(force, event);
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
} else {
force = force - this.decrement < 0 ? 0 : force - this.decrement;
if (force < 0.5 && this.isDeepPressed()) {
this.setDeepPressed(false);
this.runClosure('endDeepPress');
}
if (force === 0) {
this.runningPolyfill = false;
this.setPressed(true);
this._endPress();
} else {
this.runClosure('change', force, event);
this.deepPress(force, event);
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
}
}
}

@@ -305,6 +341,6 @@ }

this.add('touchforcechange', this.start.bind(this));
this.add('touchstart', this.supportTest.bind(this, 0));
this.add('touchstart', this.support.bind(this, 0));
this.add('touchend', this._endPress.bind(this));
} else {
this.add('touchstart', this.startLegacyTest.bind(this));
this.add('touchstart', this.startLegacy.bind(this));
this.add('touchend', this._endPress.bind(this));

@@ -318,8 +354,11 @@ }

this._startPress(event);
this._changePress(this.selectTouch(event).force, event);
this.touch = this.selectTouch(event);
if (this.touch) {
this._changePress(this.touch.force, event);
}
}
}
}, {
key: 'supportTest',
value: function supportTest(iter, event) {
key: 'support',
value: function support(iter, event) {
var runKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.runKey;

@@ -330,3 +369,3 @@

iter++;
setTimeout(this.supportTest.bind(this, iter, event, runKey), 10);
setTimeout(this.support.bind(this, iter, event, runKey), 10);
} else {

@@ -338,4 +377,4 @@ this.fail(event, runKey);

}, {
key: 'startLegacyTest',
value: function startLegacyTest(event) {
key: 'startLegacy',
value: function startLegacy(event) {
this.initialForce = event.touches[0].force;

@@ -350,4 +389,4 @@ this.supportLegacyTest(0, event, this.runKey, this.initialForce);

}, {
key: 'supportLegacyTest',
value: function supportLegacyTest(iter, event, runKey, force) {
key: 'supportLegacy',
value: function supportLegacy(iter, event, runKey, force) {
if (force !== this.initialForce) {

@@ -395,3 +434,3 @@ this._startPress(event);

value: function returnTouch(touch, event) {
touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
this.deepPress(touch.force, event);
return touch;

@@ -404,2 +443,48 @@ }

/*
This adapter is for devices that support pointer events.
*/
var AdapterPointer = function (_Adapter3) {
_inherits(AdapterPointer, _Adapter3);
function AdapterPointer(el, block, options) {
_classCallCheck(this, AdapterPointer);
return _possibleConstructorReturn(this, (AdapterPointer.__proto__ || Object.getPrototypeOf(AdapterPointer)).call(this, el, block, options));
}
_createClass(AdapterPointer, [{
key: 'bindEvents',
value: function bindEvents() {
this.add('pointerdown', this.support.bind(this));
this.add('pointermove', this.change.bind(this));
this.add('pointerup', this._endPress.bind(this));
this.add('pointerleave', this._endPress.bind(this));
}
}, {
key: 'support',
value: function support(event) {
if (this.isPressed() === false) {
if (event.pressure === 0 || event.pressure === 0.5) {
this.fail(event, this.runKey);
} else {
this._startPress(event);
this._changePress(event.pressure, event);
}
}
}
}, {
key: 'change',
value: function change(event) {
if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) {
this._changePress(event.pressure, event);
this.deepPress(event.pressure, event);
}
}
}]);
return AdapterPointer;
}(Adapter);
// This class holds the states of the the Pressure config

@@ -414,8 +499,11 @@

// milliseconds it takes to go from 0 to 1 for the polyfill
polyfillSpeed: 1000,
polyfillSpeedUp: 1000,
// milliseconds it takes to go from 1 to 0 for the polyfill
polyfillSpeedDown: 0,
// 'true' prevents the selecting of text and images via css properties
preventSelect: true,
// 'mobile' or 'desktop' will make it run only on that type of device
// 'touch', 'mouse', or 'pointer' will make it run only on that type of device
only: null,

@@ -474,4 +562,5 @@

var isDesktop = false;
var isMobile = false;
var supportsMouse = false;
var supportsTouch = false;
var supportsPointer = false;
var supportsTouchForceChange = false;

@@ -481,4 +570,5 @@ if (typeof window !== 'undefined') {

// on the server, this is a no-op, like the rest of the library
isMobile = 'ontouchstart' in window.document;
isDesktop = !isMobile;
supportsTouch = 'ontouchstart' in window.document;
supportsMouse = 'onmousemove' in window.document && !supportsTouch;
supportsPointer = 'onpointermove' in window.document;
supportsTouchForceChange = 'ontouchforcechange' in window.document;

@@ -485,0 +575,0 @@ }

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

// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016
!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}();if(!e)throw new Error("Pressure jQuery requires jQuery to be loaded.");e.fn.pressure=function(e,t){return a(this,e,t),this},e.pressureConfig=function(e){l.set(e)},e.pressureMap=function(e,t,s,n,i){return f.apply(null,arguments)};var o=function(){function e(t,s,i){n(this,e),this.routeEvents(t,s,i),this.preventSelect(t,i)}return r(e,[{key:"routeEvents",value:function(e,t,s){var n=l.get("only",s);!p||"desktop"!==n&&"mobile"===n?!y||"mobile"!==n&&"desktop"===n?this.adapter=new u(e,t).bindUnsupportedEvent():this.adapter=new c(e,t,s).bindEvents():this.adapter=new h(e,t,s).bindEvents()}},{key:"preventSelect",value:function(e,t){l.get("preventSelect",t)&&(e.style.webkitTouchCallout="none",e.style.webkitUserSelect="none",e.style.khtmlUserSelect="none",e.style.MozUserSelect="none",e.style.msUserSelect="none",e.style.userSelect="none")}}]),e}(),u=function(){function e(t,s,i){n(this,e),this.el=t,this.block=s,this.options=i,this.pressed=!1,this.deepPressed=!1,this.nativeSupport=!1,this.runKey=Math.random()}return r(e,[{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"isPressed",value:function(){return this.pressed}},{key:"isDeepPressed",value:function(){return this.deepPressed}},{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"runClosure",value:function(e){e in this.block&&this.block[e].apply(this.el,Array.prototype.slice.call(arguments,1))}},{key:"fail",value:function(e,t){l.get("polyfill",this.options)?this.runKey===t&&this.runPolyfill(e):this.runClosure("unsupported",e)}},{key:"bindUnsupportedEvent",value:function(){var e=this;this.add(y?"touchstart":"mousedown",function(t){return e.runClosure("unsupported",t)})}},{key:"_startPress",value:function(e){this.isPressed()===!1&&(this.setPressed(!0),this.runClosure("start",e))}},{key:"_startDeepPress",value:function(e){this.isPressed()&&this.isDeepPressed()===!1&&(this.setDeepPressed(!0),this.runClosure("startDeepPress",e))}},{key:"_changePress",value:function(e,t){this.nativeSupport=!0,this.runClosure("change",e,t)}},{key:"_endDeepPress",value:function(){this.isPressed()&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress"))}},{key:"_endPress",value:function(){this.isPressed()&&(this._endDeepPress(),this.setPressed(!1),this.runClosure("end")),this.runKey=Math.random(),this.nativeSupport=!1}},{key:"runPolyfill",value:function(e){this.increment=10/l.get("polyfillSpeed",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.isPressed()&&this.nativeSupport===!1&&(this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.supportTest.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacyTest.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this._changePress(this.selectTouch(e).force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacyTest",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacyTest",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,n),10)):this.fail(t,s)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this._changePress(this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return e.force>=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),i}(u),l={polyfill:!0,polyfillSpeed:1e3,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i<n.length;i++)new o(n[i],t,s);else if(d(e))new o(e,t,s);else for(var i=0;i<e.length;i++)new o(e[i],t,s)},d=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":i(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":i(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},f=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n},p=!1,y=!1,b=!1;"undefined"!=typeof window&&(y="ontouchstart"in window.document,p=!y,b="ontouchforcechange"in window.document)});
// Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017
!function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):e.jQuery__pressure=t(e.jQuery)}(this,function(e){"use strict";function t(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}();if(!e)throw new Error("Pressure jQuery requires jQuery to be loaded.");e.fn.pressure=function(e,t){return a(this,e,t),this},e.pressureConfig=function(e){d.set(e)},e.pressureMap=function(e,t,s,n,i){return f.apply(null,arguments)};var o=function(){function e(t,s,i){n(this,e),this.routeEvents(t,s,i),this.preventSelect(t,i)}return r(e,[{key:"routeEvents",value:function(e,t,s){var n=d.get("only",s);!v||"pointer"!==n&&null!==n?!y||"mouse"!==n&&null!==n?!P||"touch"!==n&&null!==n?this.adapter=new u(e,t).bindUnsupportedEvent():this.adapter=new l(e,t,s).bindEvents():this.adapter=new h(e,t,s).bindEvents():this.adapter=new c(e,t,s).bindEvents()}},{key:"preventSelect",value:function(e,t){d.get("preventSelect",t)&&(e.style.webkitTouchCallout="none",e.style.webkitUserSelect="none",e.style.khtmlUserSelect="none",e.style.MozUserSelect="none",e.style.msUserSelect="none",e.style.userSelect="none")}}]),e}(),u=function(){function e(t,s,i){n(this,e),this.el=t,this.block=s,this.options=i,this.pressed=!1,this.deepPressed=!1,this.nativeSupport=!1,this.runningPolyfill=!1,this.runKey=Math.random()}return r(e,[{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"isPressed",value:function(){return this.pressed}},{key:"isDeepPressed",value:function(){return this.deepPressed}},{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"runClosure",value:function(e){e in this.block&&this.block[e].apply(this.el,Array.prototype.slice.call(arguments,1))}},{key:"fail",value:function(e,t){d.get("polyfill",this.options)?this.runKey===t&&this.runPolyfill(e):this.runClosure("unsupported",e)}},{key:"bindUnsupportedEvent",value:function(){var e=this;this.add(P?"touchstart":"mousedown",function(t){return e.runClosure("unsupported",t)})}},{key:"_startPress",value:function(e){this.isPressed()===!1&&(this.runningPolyfill=!1,this.setPressed(!0),this.runClosure("start",e))}},{key:"_startDeepPress",value:function(e){this.isPressed()&&this.isDeepPressed()===!1&&(this.setDeepPressed(!0),this.runClosure("startDeepPress",e))}},{key:"_changePress",value:function(e,t){this.nativeSupport=!0,this.runClosure("change",e,t)}},{key:"_endDeepPress",value:function(){this.isPressed()&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress"))}},{key:"_endPress",value:function(){this.runningPolyfill===!1?(this.isPressed()&&(this._endDeepPress(),this.setPressed(!1),this.runClosure("end")),this.runKey=Math.random(),this.nativeSupport=!1):this.setPressed(!1)}},{key:"deepPress",value:function(e,t){e>=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),i}(u),l=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,n),10)):this.fail(t,s)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this._changePress(this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return this.deepPress(e.force,t),e}}]),i}(u),c=function(e){function i(e,s,r){return n(this,i),t(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,s,r))}return s(i,e),r(i,[{key:"bindEvents",value:function(){this.add("pointerdown",this.support.bind(this)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&(0===e.pressure||.5===e.pressure?this.fail(e,this.runKey):(this._startPress(e),this._changePress(e.pressure,e)))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),i}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i<n.length;i++)new o(n[i],t,s);else if(p(e))new o(e,t,s);else for(var i=0;i<e.length;i++)new o(e[i],t,s)},p=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":i(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":i(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},f=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n},y=!1,P=!1,v=!1,b=!1;"undefined"!=typeof window&&(P="ontouchstart"in window.document,y="onmousemove"in window.document&&!P,v="onpointermove"in window.document,b="ontouchforcechange"in window.document)});

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

// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016
// Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017
;(function(root, factory) {

@@ -60,14 +60,18 @@ if (typeof define === 'function' && define.amd) {

var type = Config.get('only', options);
// if on desktop and requesting Force Touch or not requesting 3D Touch
if (isDesktop && (type === 'desktop' || type !== 'mobile')) {
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
// for devices that support pointer events
if (supportsPointer && (type === 'pointer' || type === null)) {
this.adapter = new AdapterPointer(el, block, options).bindEvents();
}
// if on mobile and requesting 3D Touch or not requestion Force Touch
else if (isMobile && (type === 'mobile' || type !== 'desktop')) {
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
// for devices that support Force Touch
else if (supportsMouse && (type === 'mouse' || type === null)) {
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
}
// unsupported if it is requesting a type and your browser is of other type
else {
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
// for devices that support 3D Touch
else if (supportsTouch && (type === 'touch' || type === null)) {
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();
}
// unsupported if it is requesting a type and your browser is of other type
else {
this.adapter = new Adapter(el, block).bindUnsupportedEvent();
}
}

@@ -108,2 +112,3 @@

this.nativeSupport = false;
this.runningPolyfill = false;
this.runKey = Math.random();

@@ -161,3 +166,3 @@ }

this.add(isMobile ? 'touchstart' : 'mousedown', function (event) {
this.add(supportsTouch ? 'touchstart' : 'mousedown', function (event) {
return _this.runClosure('unsupported', event);

@@ -170,2 +175,3 @@ });

if (this.isPressed() === false) {
this.runningPolyfill = false;
this.setPressed(true);

@@ -200,17 +206,29 @@ this.runClosure('start', event);

value: function _endPress() {
if (this.isPressed()) {
this._endDeepPress();
if (this.runningPolyfill === false) {
if (this.isPressed()) {
this._endDeepPress();
this.setPressed(false);
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
} else {
this.setPressed(false);
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
}
}, {
key: 'deepPress',
value: function deepPress(force, event) {
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
}
}, {
key: 'runPolyfill',
value: function runPolyfill(event) {
this.increment = 10 / Config.get('polyfillSpeed', this.options);
this.increment = Config.get('polyfillSpeedUp', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedUp', this.options);
this.decrement = Config.get('polyfillSpeedDown', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedDown', this.options);
this.setPressed(true);
this.runClosure('start', event);
this.loopPolyfillForce(0, event);
if (this.runningPolyfill === false) {
this.loopPolyfillForce(0, event);
}
}

@@ -220,7 +238,25 @@ }, {

value: function loopPolyfillForce(force, event) {
if (this.isPressed() && this.nativeSupport === false) {
this.runClosure('change', force, event);
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
force = force + this.increment > 1 ? 1 : force + this.increment;
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
if (this.nativeSupport === false) {
if (this.isPressed()) {
this.runningPolyfill = true;
force = force + this.increment > 1 ? 1 : force + this.increment;
this.runClosure('change', force, event);
this.deepPress(force, event);
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
} else {
force = force - this.decrement < 0 ? 0 : force - this.decrement;
if (force < 0.5 && this.isDeepPressed()) {
this.setDeepPressed(false);
this.runClosure('endDeepPress');
}
if (force === 0) {
this.runningPolyfill = false;
this.setPressed(true);
this._endPress();
} else {
this.runClosure('change', force, event);
this.deepPress(force, event);
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
}
}
}

@@ -310,6 +346,6 @@ }

this.add('touchforcechange', this.start.bind(this));
this.add('touchstart', this.supportTest.bind(this, 0));
this.add('touchstart', this.support.bind(this, 0));
this.add('touchend', this._endPress.bind(this));
} else {
this.add('touchstart', this.startLegacyTest.bind(this));
this.add('touchstart', this.startLegacy.bind(this));
this.add('touchend', this._endPress.bind(this));

@@ -323,8 +359,11 @@ }

this._startPress(event);
this._changePress(this.selectTouch(event).force, event);
this.touch = this.selectTouch(event);
if (this.touch) {
this._changePress(this.touch.force, event);
}
}
}
}, {
key: 'supportTest',
value: function supportTest(iter, event) {
key: 'support',
value: function support(iter, event) {
var runKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.runKey;

@@ -335,3 +374,3 @@

iter++;
setTimeout(this.supportTest.bind(this, iter, event, runKey), 10);
setTimeout(this.support.bind(this, iter, event, runKey), 10);
} else {

@@ -343,4 +382,4 @@ this.fail(event, runKey);

}, {
key: 'startLegacyTest',
value: function startLegacyTest(event) {
key: 'startLegacy',
value: function startLegacy(event) {
this.initialForce = event.touches[0].force;

@@ -355,4 +394,4 @@ this.supportLegacyTest(0, event, this.runKey, this.initialForce);

}, {
key: 'supportLegacyTest',
value: function supportLegacyTest(iter, event, runKey, force) {
key: 'supportLegacy',
value: function supportLegacy(iter, event, runKey, force) {
if (force !== this.initialForce) {

@@ -400,3 +439,3 @@ this._startPress(event);

value: function returnTouch(touch, event) {
touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
this.deepPress(touch.force, event);
return touch;

@@ -409,2 +448,48 @@ }

/*
This adapter is for devices that support pointer events.
*/
var AdapterPointer = function (_Adapter3) {
_inherits(AdapterPointer, _Adapter3);
function AdapterPointer(el, block, options) {
_classCallCheck(this, AdapterPointer);
return _possibleConstructorReturn(this, (AdapterPointer.__proto__ || Object.getPrototypeOf(AdapterPointer)).call(this, el, block, options));
}
_createClass(AdapterPointer, [{
key: 'bindEvents',
value: function bindEvents() {
this.add('pointerdown', this.support.bind(this));
this.add('pointermove', this.change.bind(this));
this.add('pointerup', this._endPress.bind(this));
this.add('pointerleave', this._endPress.bind(this));
}
}, {
key: 'support',
value: function support(event) {
if (this.isPressed() === false) {
if (event.pressure === 0 || event.pressure === 0.5) {
this.fail(event, this.runKey);
} else {
this._startPress(event);
this._changePress(event.pressure, event);
}
}
}
}, {
key: 'change',
value: function change(event) {
if (this.isPressed() && event.pressure > 0 && event.pressure !== 0.5) {
this._changePress(event.pressure, event);
this.deepPress(event.pressure, event);
}
}
}]);
return AdapterPointer;
}(Adapter);
// This class holds the states of the the Pressure config

@@ -419,8 +504,11 @@

// milliseconds it takes to go from 0 to 1 for the polyfill
polyfillSpeed: 1000,
polyfillSpeedUp: 1000,
// milliseconds it takes to go from 1 to 0 for the polyfill
polyfillSpeedDown: 0,
// 'true' prevents the selecting of text and images via css properties
preventSelect: true,
// 'mobile' or 'desktop' will make it run only on that type of device
// 'touch', 'mouse', or 'pointer' will make it run only on that type of device
only: null,

@@ -479,4 +567,5 @@

var isDesktop = false;
var isMobile = false;
var supportsMouse = false;
var supportsTouch = false;
var supportsPointer = false;
var supportsTouchForceChange = false;

@@ -486,4 +575,5 @@ if (typeof window !== 'undefined') {

// on the server, this is a no-op, like the rest of the library
isMobile = 'ontouchstart' in window.document;
isDesktop = !isMobile;
supportsTouch = 'ontouchstart' in window.document;
supportsMouse = 'onmousemove' in window.document && !supportsTouch;
supportsPointer = 'onpointermove' in window.document;
supportsTouchForceChange = 'ontouchforcechange' in window.document;

@@ -490,0 +580,0 @@ }

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

// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),o={set:function(e,t,s){a(e,t,s)},config:function(e){l.set(e)},map:function(e,t,s,n,i){return f.apply(null,arguments)}},r=function(){function e(t,n,i){s(this,e),this.routeEvents(t,n,i),this.preventSelect(t,i)}return i(e,[{key:"routeEvents",value:function(e,t,s){var n=l.get("only",s);!p||"desktop"!==n&&"mobile"===n?!y||"mobile"!==n&&"desktop"===n?this.adapter=new u(e,t).bindUnsupportedEvent():this.adapter=new c(e,t,s).bindEvents():this.adapter=new h(e,t,s).bindEvents()}},{key:"preventSelect",value:function(e,t){l.get("preventSelect",t)&&(e.style.webkitTouchCallout="none",e.style.webkitUserSelect="none",e.style.khtmlUserSelect="none",e.style.MozUserSelect="none",e.style.msUserSelect="none",e.style.userSelect="none")}}]),e}(),u=function(){function e(t,n,i){s(this,e),this.el=t,this.block=n,this.options=i,this.pressed=!1,this.deepPressed=!1,this.nativeSupport=!1,this.runKey=Math.random()}return i(e,[{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"isPressed",value:function(){return this.pressed}},{key:"isDeepPressed",value:function(){return this.deepPressed}},{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"runClosure",value:function(e){e in this.block&&this.block[e].apply(this.el,Array.prototype.slice.call(arguments,1))}},{key:"fail",value:function(e,t){l.get("polyfill",this.options)?this.runKey===t&&this.runPolyfill(e):this.runClosure("unsupported",e)}},{key:"bindUnsupportedEvent",value:function(){var e=this;this.add(y?"touchstart":"mousedown",function(t){return e.runClosure("unsupported",t)})}},{key:"_startPress",value:function(e){this.isPressed()===!1&&(this.setPressed(!0),this.runClosure("start",e))}},{key:"_startDeepPress",value:function(e){this.isPressed()&&this.isDeepPressed()===!1&&(this.setDeepPressed(!0),this.runClosure("startDeepPress",e))}},{key:"_changePress",value:function(e,t){this.nativeSupport=!0,this.runClosure("change",e,t)}},{key:"_endDeepPress",value:function(){this.isPressed()&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress"))}},{key:"_endPress",value:function(){this.isPressed()&&(this._endDeepPress(),this.setPressed(!1),this.runClosure("end")),this.runKey=Math.random(),this.nativeSupport=!1}},{key:"runPolyfill",value:function(e){this.increment=10/l.get("polyfillSpeed",this.options),this.setPressed(!0),this.runClosure("start",e),this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.isPressed()&&this.nativeSupport===!1&&(this.runClosure("change",e,t),e>=.5?this._startDeepPress(t):this._endDeepPress(),e=e+this.increment>1?1:e+this.increment,setTimeout(this.loopPolyfillForce.bind(this,e,t),10))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.supportTest.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacyTest.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this._changePress(this.selectTouch(e).force,e))}},{key:"supportTest",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.supportTest.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacyTest",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacyTest",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,n),10)):this.fail(t,s)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this._changePress(this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return e.force>=.5?this._startDeepPress(t):this._endDeepPress(),e}}]),o}(u),l={polyfill:!0,polyfillSpeed:1e3,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i<n.length;i++)new r(n[i],t,s);else if(d(e))new r(e,t,s);else for(var i=0;i<e.length;i++)new r(e[i],t,s)},d=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":n(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":n(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},f=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n},p=!1,y=!1,b=!1;return"undefined"!=typeof window&&(y="ontouchstart"in window.document,p=!y,b="ontouchforcechange"in window.document),o});
// Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Pressure=t()}(this,function(){"use strict";function e(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),o={set:function(e,t,s){a(e,t,s)},config:function(e){d.set(e)},map:function(e,t,s,n,i){return f.apply(null,arguments)}},r=function(){function e(t,n,i){s(this,e),this.routeEvents(t,n,i),this.preventSelect(t,i)}return i(e,[{key:"routeEvents",value:function(e,t,s){var n=d.get("only",s);!v||"pointer"!==n&&null!==n?!y||"mouse"!==n&&null!==n?!P||"touch"!==n&&null!==n?this.adapter=new u(e,t).bindUnsupportedEvent():this.adapter=new l(e,t,s).bindEvents():this.adapter=new h(e,t,s).bindEvents():this.adapter=new c(e,t,s).bindEvents()}},{key:"preventSelect",value:function(e,t){d.get("preventSelect",t)&&(e.style.webkitTouchCallout="none",e.style.webkitUserSelect="none",e.style.khtmlUserSelect="none",e.style.MozUserSelect="none",e.style.msUserSelect="none",e.style.userSelect="none")}}]),e}(),u=function(){function e(t,n,i){s(this,e),this.el=t,this.block=n,this.options=i,this.pressed=!1,this.deepPressed=!1,this.nativeSupport=!1,this.runningPolyfill=!1,this.runKey=Math.random()}return i(e,[{key:"setPressed",value:function(e){this.pressed=e}},{key:"setDeepPressed",value:function(e){this.deepPressed=e}},{key:"isPressed",value:function(){return this.pressed}},{key:"isDeepPressed",value:function(){return this.deepPressed}},{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"runClosure",value:function(e){e in this.block&&this.block[e].apply(this.el,Array.prototype.slice.call(arguments,1))}},{key:"fail",value:function(e,t){d.get("polyfill",this.options)?this.runKey===t&&this.runPolyfill(e):this.runClosure("unsupported",e)}},{key:"bindUnsupportedEvent",value:function(){var e=this;this.add(P?"touchstart":"mousedown",function(t){return e.runClosure("unsupported",t)})}},{key:"_startPress",value:function(e){this.isPressed()===!1&&(this.runningPolyfill=!1,this.setPressed(!0),this.runClosure("start",e))}},{key:"_startDeepPress",value:function(e){this.isPressed()&&this.isDeepPressed()===!1&&(this.setDeepPressed(!0),this.runClosure("startDeepPress",e))}},{key:"_changePress",value:function(e,t){this.nativeSupport=!0,this.runClosure("change",e,t)}},{key:"_endDeepPress",value:function(){this.isPressed()&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress"))}},{key:"_endPress",value:function(){this.runningPolyfill===!1?(this.isPressed()&&(this._endDeepPress(),this.setPressed(!1),this.runClosure("end")),this.runKey=Math.random(),this.nativeSupport=!1):this.setPressed(!1)}},{key:"deepPress",value:function(e,t){e>=.5?this._startDeepPress(t):this._endDeepPress()}},{key:"runPolyfill",value:function(e){this.increment=0===d.get("polyfillSpeedUp",this.options)?1:10/d.get("polyfillSpeedUp",this.options),this.decrement=0===d.get("polyfillSpeedDown",this.options)?1:10/d.get("polyfillSpeedDown",this.options),this.setPressed(!0),this.runClosure("start",e),this.runningPolyfill===!1&&this.loopPolyfillForce(0,e)}},{key:"loopPolyfillForce",value:function(e,t){this.nativeSupport===!1&&(this.isPressed()?(this.runningPolyfill=!0,e=e+this.increment>1?1:e+this.increment,this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10)):(e=e-this.decrement<0?0:e-this.decrement,e<.5&&this.isDeepPressed()&&(this.setDeepPressed(!1),this.runClosure("endDeepPress")),0===e?(this.runningPolyfill=!1,this.setPressed(!0),this._endPress()):(this.runClosure("change",e,t),this.deepPress(e,t),setTimeout(this.loopPolyfillForce.bind(this,e,t),10))))}}]),e}(),h=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("webkitmouseforcewillbegin",this._startPress.bind(this)),this.add("mousedown",this.support.bind(this)),this.add("webkitmouseforcechanged",this.change.bind(this)),this.add("webkitmouseforcedown",this._startDeepPress.bind(this)),this.add("webkitmouseforceup",this._endDeepPress.bind(this)),this.add("mouseleave",this._endPress.bind(this)),this.add("mouseup",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&this.fail(e,this.runKey)}},{key:"change",value:function(e){this.isPressed()&&e.webkitForce>0&&this._changePress(this.normalizeForce(e.webkitForce),e)}},{key:"normalizeForce",value:function(e){return this.reachOne(f(e,1,3,0,1))}},{key:"reachOne",value:function(e){return e>.995?1:e}}]),o}(u),l=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){b?(this.add("touchforcechange",this.start.bind(this)),this.add("touchstart",this.support.bind(this,0)),this.add("touchend",this._endPress.bind(this))):(this.add("touchstart",this.startLegacy.bind(this)),this.add("touchend",this._endPress.bind(this)))}},{key:"start",value:function(e){e.touches.length>0&&(this._startPress(e),this.touch=this.selectTouch(e),this.touch&&this._changePress(this.touch.force,e))}},{key:"support",value:function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.runKey;this.isPressed()===!1&&(e<=6?(e++,setTimeout(this.support.bind(this,e,t,s),10)):this.fail(t,s))}},{key:"startLegacy",value:function(e){this.initialForce=e.touches[0].force,this.supportLegacyTest(0,e,this.runKey,this.initialForce)}},{key:"supportLegacy",value:function(e,t,s,n){n!==this.initialForce?(this._startPress(t),this.loopForce(t)):e<=6?(e++,setTimeout(this.supportLegacyTest.bind(this,e,t,s,n),10)):this.fail(t,s)}},{key:"loopForce",value:function(e){this.isPressed()&&(this.touch=this.selectTouch(e),setTimeout(this.loopForce.bind(this,e),10),this._changePress(this.touch.force,e))}},{key:"selectTouch",value:function(e){if(1===e.touches.length)return this.returnTouch(e.touches[0],e);for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return this.returnTouch(e.touches[t],e)}},{key:"returnTouch",value:function(e,t){return this.deepPress(e.force,t),e}}]),o}(u),c=function(n){function o(t,n,i){return s(this,o),e(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,i))}return t(o,n),i(o,[{key:"bindEvents",value:function(){this.add("pointerdown",this.support.bind(this)),this.add("pointermove",this.change.bind(this)),this.add("pointerup",this._endPress.bind(this)),this.add("pointerleave",this._endPress.bind(this))}},{key:"support",value:function(e){this.isPressed()===!1&&(0===e.pressure||.5===e.pressure?this.fail(e,this.runKey):(this._startPress(e),this._changePress(e.pressure,e)))}},{key:"change",value:function(e){this.isPressed()&&e.pressure>0&&.5!==e.pressure&&(this._changePress(e.pressure,e),this.deepPress(e.pressure,e))}}]),o}(u),d={polyfill:!0,polyfillSpeedUp:1e3,polyfillSpeedDown:0,preventSelect:!0,only:null,get:function(e,t){return t.hasOwnProperty(e)?t[e]:this[e]},set:function(e){for(var t in e)e.hasOwnProperty(t)&&this.hasOwnProperty(t)&&"get"!=t&&"set"!=t&&(this[t]=e[t])}},a=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e||e instanceof String)for(var n=document.querySelectorAll(e),i=0;i<n.length;i++)new r(n[i],t,s);else if(p(e))new r(e,t,s);else for(var i=0;i<e.length;i++)new r(e[i],t,s)},p=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":n(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":n(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},f=function(e,t,s,n,i){return(e-t)*(i-n)/(s-t)+n},y=!1,P=!1,v=!1,b=!1;return"undefined"!=typeof window&&(P="ontouchstart"in window.document,y="onmousemove"in window.document&&!P,v="onpointermove"in window.document,b="ontouchforcechange"in window.document),o});

@@ -44,8 +44,9 @@ // Example of change method with a failure closure

Pressure.set(document.querySelectorAll('#el1'), block);
Pressure.set($('#el2'), block, {only: 'desktop', polyfill: true, polyfillSpeed: 5000});
Pressure.set('#el3', block, {only: 'mobile'});
Pressure.set($('#el2'), block, {only: 'mouse', polyfill: true, polyfillSpeedUp: 5000, polyfillSpeedDown: 2000});
Pressure.set('#el3', block, {only: 'touch'});
$('#el1-jquery').pressure(block);
$('#el2-jquery').pressure(block, {only: 'desktop'});
$('#el3-jquery').pressure(block, {only: 'mobile'});
$('#el2-jquery').pressure(block, {only: 'mouse'});
$('#el3-jquery').pressure(block, {only: 'touch'});
$('#el4-jquery').pressure(block, {only: 'pointer'});

@@ -52,0 +53,0 @@ $('img').pressure({

@@ -9,3 +9,3 @@ // include plug-ins

var babel = require('gulp-babel');
var HEADER_COMMENT = '// Pressure v2.0.3 | Created By Stuart Yamartino | MIT License | 2015 - 2016\n';
var HEADER_COMMENT = '// Pressure v2.1.0 | Created By Stuart Yamartino | MIT License | 2015 - 2017\n';
var DESTINATION = '.';

@@ -21,2 +21,3 @@

'./src/adapters/adapter_3d_touch.js',
'./src/adapters/adapter_pointer.js',
'./src/config.js',

@@ -52,2 +53,3 @@ './src/helpers.js',

'./src/adapters/adapter_3d_touch.js',
'./src/adapters/adapter_pointer.js',
'./src/config.js',

@@ -54,0 +56,0 @@ './src/helpers.js',

{
"name": "pressure",
"version": "2.0.3",
"version": "2.1.0",
"description": "Pressure is a lightweight JavaScript library for both Force Touch and 3D Touch through a single API.",

@@ -5,0 +5,0 @@ "main": "dist/pressure.min.js",

@@ -10,3 +10,3 @@ # Pressure.js

Head over to the [documentation](http://pressurejs.com/documentation.html) for installation instructions and more details on pressure.js.
Head over to the [documentation](http://pressurejs.com/documentation.html) for installation instructions, supported devices, and more details on pressure.js.

@@ -105,3 +105,3 @@ ## Install

###Polyfill Support
Using the "polyfill" keyword, you can disable polyfill support for the element. The polyfill is enabled by defauly and is useful if the device or browser does not support force or 3D touch, it will fall back to using time. For example instead of force from 0 to 1, it counts up from 0 to 1 over the course of one second, as long as you are holding the element. Try some of the examples on the main page on a devices that does not support force or 3D touch and see for yourself how it works.
Using the "polyfill" keyword, you can disable polyfill support for the element. The polyfill is enabled by default and is useful if the device or browser does not support pressure, it will fall back to using time. For example instead of force from 0 to 1, it counts up from 0 to 1 over the course of one second, as long as you are holding the element. Try some of the examples on the main page on a devices that does not support pressure and see for yourself how it works.
```javascript

@@ -118,4 +118,4 @@ Pressure.set('#example', {

###Polyfill Speed
If you are using the polyfill (on by default), you can see the "polyfillSpeed" speed to determine how fast the polyfill takes to go from 0 to 1. The value is an integer in milliseconds and the default is 1000 (1 second).
###Polyfill Speed Up
If you are using the polyfill (on by default), you can see the "polyfillSpeedUp" speed to determine how fast the polyfill takes to go from 0 to 1. The value is an integer in milliseconds and the default is 1000 (1 second).
```javascript

@@ -126,10 +126,22 @@ Pressure.set('#example', {

}
}, {polyfillSpeed: 5000});
}, {polyfillSpeedUp: 5000});
// takes 5 seconds to go from a force value of 0 to 1
// only on devices that do not support force touch or 3d touch
// only on devices that do not support pressure
```
### Only run on Force Touch trackpads (Desktop)
Set the option only to the type you want it to run on 'desktop' or 'mobile'
###Polyfill Speed Down
If you are using the polyfill (on by default), you can see the "polyfillSpeedDown" speed to determine how fast the polyfill takes to go from 1 to 0 when you let go. The value is an integer in milliseconds and the default is 0 (aka off).
```javascript
Pressure.set('#example', {
change: function(force, event){
this.innerHTML = force;
}
}, {polyfillSpeedDown: 2000});
// takes 2 seconds to go from a force value of 1 to 0
// only on devices that do not support pressure
```
### Only run on Force Touch trackpads (mouse)
Set the option only to the type you want it to run on 'mouse', 'touch', or 'pointer'. The names are the types of events that pressure will respond to.
```javascript
Pressure.set('#example',{

@@ -139,5 +151,5 @@ change: function(force, event){

},
}, {only: 'desktop'});
}, {only: 'mouse'});
```
### Only run on 3D Touch (Mobile)
### Only run on 3D Touch (touch)
```javascript

@@ -148,4 +160,12 @@ Pressure.set('#example',{

},
}, {only: 'mobile'});
}, {only: 'touch'});
```
### Only run on Pointer Supported Devices (pointer)
```javascript
Pressure.set('#example',{
change: function(force, event){
console.log(force);
},
}, {only: 'pointer'});
```

@@ -174,3 +194,4 @@ ### Change the preventSelect option

polyfill: true,
polyfillSpeed: 1000,
polyfillSpeedUp: 1000,
polyfillSpeedDown: 0,
preventDefault: true,

@@ -177,0 +198,0 @@ only: null

@@ -14,6 +14,6 @@ /*

this.add('touchforcechange', this.start.bind(this));
this.add('touchstart', this.supportTest.bind(this, 0));
this.add('touchstart', this.support.bind(this, 0));
this.add('touchend', this._endPress.bind(this));
} else {
this.add('touchstart', this.startLegacyTest.bind(this));
this.add('touchstart', this.startLegacy.bind(this));
this.add('touchend', this._endPress.bind(this));

@@ -26,11 +26,14 @@ }

this._startPress(event);
this._changePress(this.selectTouch(event).force, event);
this.touch = this.selectTouch(event);
if (this.touch) {
this._changePress(this.touch.force, event);
}
}
}
supportTest(iter, event, runKey = this.runKey){
support(iter, event, runKey = this.runKey){
if(this.isPressed() === false){
if(iter <= 6){
iter++;
setTimeout(this.supportTest.bind(this, iter, event, runKey), 10);
setTimeout(this.support.bind(this, iter, event, runKey), 10);
} else {

@@ -42,3 +45,3 @@ this.fail(event, runKey);

startLegacyTest(event){
startLegacy(event){
this.initialForce = event.touches[0].force;

@@ -51,3 +54,3 @@ this.supportLegacyTest(0, event, this.runKey, this.initialForce);

// more info from this issue https://github.com/yamartino/pressure/issues/15
supportLegacyTest(iter, event, runKey, force){
supportLegacy(iter, event, runKey, force){
if(force !== this.initialForce){

@@ -88,3 +91,3 @@ this._startPress(event);

returnTouch(touch, event){
touch.force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
this.deepPress(touch.force, event);
return touch;

@@ -91,0 +94,0 @@ }

@@ -14,2 +14,3 @@ /*

this.nativeSupport = false;
this.runningPolyfill = false;
this.runKey = Math.random();

@@ -56,3 +57,3 @@ }

bindUnsupportedEvent(){
this.add(isMobile ? 'touchstart' : 'mousedown', (event) => this.runClosure('unsupported', event));
this.add(supportsTouch ? 'touchstart' : 'mousedown', (event) => this.runClosure('unsupported', event));
}

@@ -62,2 +63,3 @@

if(this.isPressed() === false){
this.runningPolyfill = false;
this.setPressed(true);

@@ -88,24 +90,53 @@ this.runClosure('start', event);

_endPress(){
if(this.isPressed()){
this._endDeepPress();
if(this.runningPolyfill === false){
if(this.isPressed()){
this._endDeepPress();
this.setPressed(false);
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
} else {
this.setPressed(false);
this.runClosure('end');
}
this.runKey = Math.random();
this.nativeSupport = false;
}
deepPress(force, event){
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
}
runPolyfill(event){
this.increment = 10 / Config.get('polyfillSpeed', this.options);
this.increment = Config.get('polyfillSpeedUp', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedUp', this.options);
this.decrement = Config.get('polyfillSpeedDown', this.options) === 0 ? 1 : 10 / Config.get('polyfillSpeedDown', this.options);
this.setPressed(true);
this.runClosure('start', event);
this.loopPolyfillForce(0, event);
if(this.runningPolyfill === false){
this.loopPolyfillForce(0, event);
}
}
loopPolyfillForce(force, event){
if(this.isPressed() && this.nativeSupport === false) {
this.runClosure('change', force, event);
force >= 0.5 ? this._startDeepPress(event) : this._endDeepPress();
force = force + this.increment > 1 ? 1 : force + this.increment;
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
if(this.nativeSupport === false){
if(this.isPressed()) {
this.runningPolyfill = true;
force = force + this.increment > 1 ? 1 : force + this.increment;
this.runClosure('change', force, event);
this.deepPress(force, event);
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
} else {
force = force - this.decrement < 0 ? 0 : force - this.decrement;
if(force < 0.5 && this.isDeepPressed()){
this.setDeepPressed(false);
this.runClosure('endDeepPress');
}
if(force === 0){
this.runningPolyfill = false;
this.setPressed(true);
this._endPress();
} else {
this.runClosure('change', force, event);
this.deepPress(force, event);
setTimeout(this.loopPolyfillForce.bind(this, force, event), 10);
}
}
}

@@ -112,0 +143,0 @@ }

@@ -8,8 +8,11 @@ // This class holds the states of the the Pressure config

// milliseconds it takes to go from 0 to 1 for the polyfill
polyfillSpeed: 1000,
polyfillSpeedUp: 1000,
// milliseconds it takes to go from 1 to 0 for the polyfill
polyfillSpeedDown: 0,
// 'true' prevents the selecting of text and images via css properties
preventSelect: true,
// 'mobile' or 'desktop' will make it run only on that type of device
// 'touch', 'mouse', or 'pointer' will make it run only on that type of device
only: null,

@@ -16,0 +19,0 @@

@@ -10,8 +10,12 @@ class Element{

var type = Config.get('only', options);
// if on desktop and requesting Force Touch or not requesting 3D Touch
if(isDesktop && (type === 'desktop' || type !== 'mobile')){
// for devices that support pointer events
if(supportsPointer && (type === 'pointer' || type === null)){
this.adapter = new AdapterPointer(el, block, options).bindEvents();
}
// for devices that support Force Touch
else if(supportsMouse && (type === 'mouse' || type === null)){
this.adapter = new AdapterForceTouch(el, block, options).bindEvents();
}
// if on mobile and requesting 3D Touch or not requestion Force Touch
else if(isMobile && (type === 'mobile' || type !== 'desktop')){
// for devices that support 3D Touch
else if(supportsTouch && (type === 'touch' || type === null)){
this.adapter = new Adapter3DTouch(el, block, options).bindEvents();

@@ -18,0 +22,0 @@ }

@@ -36,4 +36,5 @@ //------------------- Helpers -------------------//

var isDesktop = false;
var isMobile = false;
var supportsMouse = false;
var supportsTouch = false;
var supportsPointer = false;
var supportsTouchForceChange = false;

@@ -43,5 +44,6 @@ if (typeof window !== 'undefined') {

// on the server, this is a no-op, like the rest of the library
isMobile = 'ontouchstart' in window.document;
isDesktop = !isMobile;
supportsTouch = 'ontouchstart' in window.document;
supportsMouse = 'onmousemove' in window.document && !supportsTouch;
supportsPointer = 'onpointermove' in window.document;
supportsTouchForceChange = 'ontouchforcechange' in window.document;
}

Sorry, the diff of this file is not supported yet

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