Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pressure

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pressure - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

3

bower.json

@@ -27,3 +27,4 @@ {

"tests"
]
],
"version": "0.0.3"
}

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

var HEADER_COMMENT = '// Pressure v0.0.2 | Created By Stuart Yamartino | MIT License | 2015-2016 \n';
var HEADER_COMMENT = '// Pressure v0.0.3 | Created By Stuart Yamartino | MIT License | 2015-2016 \n';
var DESTINATION = '.';

@@ -14,0 +14,0 @@

{
"name": "pressure",
"version": "0.0.2",
"version": "0.0.3",
"description": "Pressure is a JavaScript library for handling both Force Touch and 3D Touch through a single API",

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

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

// Pressure v0.0.2 | Created By Stuart Yamartino | MIT License | 2015-2016
// Pressure v0.0.3 | Created By Stuart Yamartino | MIT License | 2015-2016
;(function(window) {

@@ -39,11 +39,6 @@ 'use strict';

// the interpolate method allows for interpolating a value between two values based on two input values
// the map method allows for interpolating a value from one range of values to another
// example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map
interpolate: function interpolate(x, in_min, in_max, out_min, out_max) {
map: function map(x, in_min, in_max, out_min, out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
},
// map is an alias for the above 'interpolate' method
map: function map() {
return this.interpolate.apply(this, arguments);
}

@@ -50,0 +45,0 @@ };

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

// Pressure v0.0.2 | Created By Stuart Yamartino | MIT License | 2015-2016
!function(e){"use strict";function t(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function n(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 o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),r=e!==!1?e.document:!1,u={set:function(e,t,n){p(e,t,null,n)},setForceTouch:function(e,t,n){p(e,t,"force",n)},set3DTouch:function(e,t,n){p(e,t,"3d",n)},interpolate:function(e,t,n,s,o){return(e-t)*(o-s)/(n-t)+s},map:function(){return this.interpolate.apply(this,arguments)}},c=function(){function e(t,n,s){o(this,e),this.element=t,this.block=n,this.type=s}return i(e,[{key:"routeEvents",value:function(){f.mobile!==!1||"force"!==this.type&&"3d"===this.type?f.mobile!==!0||"3d"!==this.type&&"force"===this.type?this.failEvents():this.touch3DAdapter():this.touchForceAdapter()}},{key:"touchForceAdapter",value:function(){var e=new h(new d(this));e.handle()}},{key:"touch3DAdapter",value:function(){var e=new h(new l(this));e.handle()}},{key:"failEvents",value:function(){var e=this;f.mobile?this.element.addEventListener("touchstart",function(){return y(e.block,"unsupported",e.element)},!1):this.element.addEventListener("mousedown",function(){return y(e.block,"unsupported",e.element)},!1)}}]),e}(),h=function(){function e(t){o(this,e),this.adapter=t}return i(e,[{key:"handle",value:function(){this.adapter.support(),this.adapter.start(),this.adapter.change(),this.adapter.end(),this.adapter.startDeepPress(),this.adapter.endDeepPress()}}]),e}(),a=function(){function e(t){o(this,e),this.element=t,this.el=t.element,this.block=t.block,this.down=!1,this.deepDown=!1}return i(e,[{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"remove",value:function(e,t){this.el.removeEventListener(e,t)}},{key:"_dispatch",value:function(){f.forPressure?this.remove("webkitmouseforcewillbegin",this._touchForceEnabled):(f.didFail(),y(this.block,"unsupported",this.el))}},{key:"_setDown",value:function(){this.down=!0}},{key:"_setUp",value:function(){this.down=!1}},{key:"_setDeepDown",value:function(){this.deepDown=!0}},{key:"_setDeepUp",value:function(){this.deepDown=!1}}]),e}(),l=function(e){function t(e){o(this,t);var s=n(this,Object.getPrototypeOf(t).call(this,e));return s.startDeepPressSetEnabled=!1,s.endDeepPressSetEnabled=!1,s}return s(t,e),i(t,[{key:"support",value:function(){this.supportMethod=this._middleMan.bind(this),this.add("touchstart",this.supportMethod)}},{key:"_middleMan",value:function(e){this._setDown(),this._dispatch(0,e)}},{key:"_dispatch",value:function(e,t){f.hasRun===!1?t.touches[0].force>0?(f.didSucceed("3d"),this.remove("touchstart",this.supportMethod),y(this.block,"start",this.el),this._changeLogic(t)):10>=e&&this.down===!0?(e+=1,setTimeout(this._dispatch.bind(this),10,e,t)):this.down===!0&&(f.didFail(),y(this.block,"unsupported",this.el)):f.forPressure?this.remove("touchstart",this.supportMethod):y(this.block,"unsupported",this.el)}},{key:"start",value:function(){var e=this;this.add("touchstart",function(){f.forPressure&&(e._setDown(),y(e.block,"start",e.el))})}},{key:"change",value:function(){this.add("touchstart",this._changeLogic.bind(this))}},{key:"_changeLogic",value:function(e){f.forPressure&&(this._setDown(),this.touch=this._selectTouch(e),this.touch&&this._fetchForce(e))}},{key:"end",value:function(){var e=this;this.add("touchend",function(){f.forPressure&&(e._setUp(),y(e.block,"end",e.el),e.deepDown===!0&&(y(e.block,"endDeepPress",e.el),e._setDeepUp()))})}},{key:"startDeepPress",value:function(){this.startDeepPressSetEnabled=!0}},{key:"endDeepPress",value:function(){this.endDeepPressSetEnabled=!0}},{key:"_callStartDeepPress",value:function(){this.startDeepPressSetEnabled===!0&&this.deepDown===!1&&y(this.block,"startDeepPress",this.el),this._setDeepDown()}},{key:"_callEndDeepPress",value:function(){this.endDeepPressSetEnabled===!0&&this.deepDown===!0&&y(this.block,"endDeepPress",this.el),this._setDeepUp()}},{key:"_fetchForce",value:function(e){this.down&&(this.touch=this._selectTouch(e),setTimeout(this._fetchForce.bind(this),10,e),y(this.block,"change",this.el,this.touch.force,e))}},{key:"_selectTouch",value:function(e){if(1===e.touches.length)return e.touches[0].force>=.5?this._callStartDeepPress():this._callEndDeepPress(),e.touches[0];for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return e.touches[t].force>=.5?this._callStartDeepPress():this._callEndDeepPress(),e.touches[t]}}]),t}(a),d=function(e){function t(e){o(this,t);var s=n(this,Object.getPrototypeOf(t).call(this,e));return s._preventDefaultForceTouch(),s}return s(t,e),i(t,[{key:"support",value:function(){this.add("webkitmouseforcewillbegin",this._touchForceEnabled),this.add("mousedown",this._dispatch.bind(this))}},{key:"_touchForceEnabled",value:function(e){e.preventDefault(),f.didSucceed("force")}},{key:"_dispatch",value:function(){f.forPressure===!1?(f.didFail(),y(this.block,"unsupported",this.el)):this.remove("webkitmouseforcewillbegin",this._touchForceEnabled)}},{key:"start",value:function(){var e=this;this.add("mousedown",function(){f.forPressure&&(e._setDown(),y(e.block,"start",e.el))})}},{key:"change",value:function(){var e=this;this.add("webkitmouseforcechanged",function(t){f.forPressure&&0!==t.webkitForce&&y(e.block,"change",e.el,e._normalizeForce(t.webkitForce),t)})}},{key:"end",value:function(){var e=this;this.add("mouseup",function(){f.forPressure&&(e._setUp(),y(e.block,"end",e.el))}),this.add("mouseleave",function(){f.forPressure&&(e.down===!0&&(y(e.block,"end",e.el),y(e.block,"endDeepPress",e.el)),e._setUp())})}},{key:"startDeepPress",value:function(){var e=this;this.add("webkitmouseforcedown",function(){f.forPressure&&(e._setDeepDown(),y(e.block,"startDeepPress",e.el))})}},{key:"endDeepPress",value:function(){var e=this;this.add("webkitmouseforceup",function(){f.forPressure&&(e._setDeepUp(),y(e.block,"endDeepPress",e.el))})}},{key:"_preventDefaultForceTouch",value:function(){this.add("webkitmouseforcewillbegin",function(e){f.forPressure&&e.preventDefault()})}},{key:"_normalizeForce",value:function(e){return(e-1)/2}}]),t}(a),f={hasRun:!1,forPressure:!1,type:!1,didFail:function(){this.hasRun=!0,this.forPressure=!1},didSucceed:function(e){this.hasRun=!0,this.forPressure=!0,this.type=e}},p=function(e,t,n){var s=arguments.length<=3||void 0===arguments[3]?!0:arguments[3];if("string"==typeof e||e instanceof String)for(var o=r.querySelectorAll(e),i=0;i<o.length;i++)b(o[i],t,n,s);else if(v(e))b(e,t,n,s);else for(var i=0;i<e.length;i++)b(e[i],t,n,s)},b=function(e,t,n,s){s&&(e.style.webkitUserSelect="none");var o=new c(e,t,n);o.routeEvents()},v=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":t(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":t(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},y=function(e,t,n){e.hasOwnProperty(t)&&e[t].apply(n||this,Array.prototype.slice.call(arguments,3))};if(f.mobile="ontouchstart"in r,e===!1)throw new Error("Pressure requires a window with a document");"object"===("undefined"==typeof module?"undefined":t(module))&&"object"===t(module.exports)?module.exports=u:e.Pressure=u}("undefined"!=typeof window?window:!1);
// Pressure v0.0.3 | Created By Stuart Yamartino | MIT License | 2015-2016
!function(e){"use strict";function t(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function n(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 o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),r=e!==!1?e.document:!1,u={set:function(e,t,n){p(e,t,null,n)},setForceTouch:function(e,t,n){p(e,t,"force",n)},set3DTouch:function(e,t,n){p(e,t,"3d",n)},map:function(e,t,n,s,o){return(e-t)*(o-s)/(n-t)+s}},c=function(){function e(t,n,s){o(this,e),this.element=t,this.block=n,this.type=s}return i(e,[{key:"routeEvents",value:function(){f.mobile!==!1||"force"!==this.type&&"3d"===this.type?f.mobile!==!0||"3d"!==this.type&&"force"===this.type?this.failEvents():this.touch3DAdapter():this.touchForceAdapter()}},{key:"touchForceAdapter",value:function(){var e=new h(new d(this));e.handle()}},{key:"touch3DAdapter",value:function(){var e=new h(new l(this));e.handle()}},{key:"failEvents",value:function(){var e=this;f.mobile?this.element.addEventListener("touchstart",function(){return y(e.block,"unsupported",e.element)},!1):this.element.addEventListener("mousedown",function(){return y(e.block,"unsupported",e.element)},!1)}}]),e}(),h=function(){function e(t){o(this,e),this.adapter=t}return i(e,[{key:"handle",value:function(){this.adapter.support(),this.adapter.start(),this.adapter.change(),this.adapter.end(),this.adapter.startDeepPress(),this.adapter.endDeepPress()}}]),e}(),a=function(){function e(t){o(this,e),this.element=t,this.el=t.element,this.block=t.block,this.down=!1,this.deepDown=!1}return i(e,[{key:"add",value:function(e,t){this.el.addEventListener(e,t,!1)}},{key:"remove",value:function(e,t){this.el.removeEventListener(e,t)}},{key:"_dispatch",value:function(){f.forPressure?this.remove("webkitmouseforcewillbegin",this._touchForceEnabled):(f.didFail(),y(this.block,"unsupported",this.el))}},{key:"_setDown",value:function(){this.down=!0}},{key:"_setUp",value:function(){this.down=!1}},{key:"_setDeepDown",value:function(){this.deepDown=!0}},{key:"_setDeepUp",value:function(){this.deepDown=!1}}]),e}(),l=function(e){function t(e){o(this,t);var s=n(this,Object.getPrototypeOf(t).call(this,e));return s.startDeepPressSetEnabled=!1,s.endDeepPressSetEnabled=!1,s}return s(t,e),i(t,[{key:"support",value:function(){this.supportMethod=this._middleMan.bind(this),this.add("touchstart",this.supportMethod)}},{key:"_middleMan",value:function(e){this._setDown(),this._dispatch(0,e)}},{key:"_dispatch",value:function(e,t){f.hasRun===!1?t.touches[0].force>0?(f.didSucceed("3d"),this.remove("touchstart",this.supportMethod),y(this.block,"start",this.el),this._changeLogic(t)):10>=e&&this.down===!0?(e+=1,setTimeout(this._dispatch.bind(this),10,e,t)):this.down===!0&&(f.didFail(),y(this.block,"unsupported",this.el)):f.forPressure?this.remove("touchstart",this.supportMethod):y(this.block,"unsupported",this.el)}},{key:"start",value:function(){var e=this;this.add("touchstart",function(){f.forPressure&&(e._setDown(),y(e.block,"start",e.el))})}},{key:"change",value:function(){this.add("touchstart",this._changeLogic.bind(this))}},{key:"_changeLogic",value:function(e){f.forPressure&&(this._setDown(),this.touch=this._selectTouch(e),this.touch&&this._fetchForce(e))}},{key:"end",value:function(){var e=this;this.add("touchend",function(){f.forPressure&&(e._setUp(),y(e.block,"end",e.el),e.deepDown===!0&&(y(e.block,"endDeepPress",e.el),e._setDeepUp()))})}},{key:"startDeepPress",value:function(){this.startDeepPressSetEnabled=!0}},{key:"endDeepPress",value:function(){this.endDeepPressSetEnabled=!0}},{key:"_callStartDeepPress",value:function(){this.startDeepPressSetEnabled===!0&&this.deepDown===!1&&y(this.block,"startDeepPress",this.el),this._setDeepDown()}},{key:"_callEndDeepPress",value:function(){this.endDeepPressSetEnabled===!0&&this.deepDown===!0&&y(this.block,"endDeepPress",this.el),this._setDeepUp()}},{key:"_fetchForce",value:function(e){this.down&&(this.touch=this._selectTouch(e),setTimeout(this._fetchForce.bind(this),10,e),y(this.block,"change",this.el,this.touch.force,e))}},{key:"_selectTouch",value:function(e){if(1===e.touches.length)return e.touches[0].force>=.5?this._callStartDeepPress():this._callEndDeepPress(),e.touches[0];for(var t=0;t<e.touches.length;t++)if(e.touches[t].target===this.el)return e.touches[t].force>=.5?this._callStartDeepPress():this._callEndDeepPress(),e.touches[t]}}]),t}(a),d=function(e){function t(e){o(this,t);var s=n(this,Object.getPrototypeOf(t).call(this,e));return s._preventDefaultForceTouch(),s}return s(t,e),i(t,[{key:"support",value:function(){this.add("webkitmouseforcewillbegin",this._touchForceEnabled),this.add("mousedown",this._dispatch.bind(this))}},{key:"_touchForceEnabled",value:function(e){e.preventDefault(),f.didSucceed("force")}},{key:"_dispatch",value:function(){f.forPressure===!1?(f.didFail(),y(this.block,"unsupported",this.el)):this.remove("webkitmouseforcewillbegin",this._touchForceEnabled)}},{key:"start",value:function(){var e=this;this.add("mousedown",function(){f.forPressure&&(e._setDown(),y(e.block,"start",e.el))})}},{key:"change",value:function(){var e=this;this.add("webkitmouseforcechanged",function(t){f.forPressure&&0!==t.webkitForce&&y(e.block,"change",e.el,e._normalizeForce(t.webkitForce),t)})}},{key:"end",value:function(){var e=this;this.add("mouseup",function(){f.forPressure&&(e._setUp(),y(e.block,"end",e.el))}),this.add("mouseleave",function(){f.forPressure&&(e.down===!0&&(y(e.block,"end",e.el),y(e.block,"endDeepPress",e.el)),e._setUp())})}},{key:"startDeepPress",value:function(){var e=this;this.add("webkitmouseforcedown",function(){f.forPressure&&(e._setDeepDown(),y(e.block,"startDeepPress",e.el))})}},{key:"endDeepPress",value:function(){var e=this;this.add("webkitmouseforceup",function(){f.forPressure&&(e._setDeepUp(),y(e.block,"endDeepPress",e.el))})}},{key:"_preventDefaultForceTouch",value:function(){this.add("webkitmouseforcewillbegin",function(e){f.forPressure&&e.preventDefault()})}},{key:"_normalizeForce",value:function(e){return(e-1)/2}}]),t}(a),f={hasRun:!1,forPressure:!1,type:!1,didFail:function(){this.hasRun=!0,this.forPressure=!1},didSucceed:function(e){this.hasRun=!0,this.forPressure=!0,this.type=e}},p=function(e,t,n){var s=arguments.length<=3||void 0===arguments[3]?!0:arguments[3];if("string"==typeof e||e instanceof String)for(var o=r.querySelectorAll(e),i=0;i<o.length;i++)b(o[i],t,n,s);else if(v(e))b(e,t,n,s);else for(var i=0;i<e.length;i++)b(e[i],t,n,s)},b=function(e,t,n,s){s&&(e.style.webkitUserSelect="none");var o=new c(e,t,n);o.routeEvents()},v=function(e){return"object"===("undefined"==typeof HTMLElement?"undefined":t(HTMLElement))?e instanceof HTMLElement:e&&"object"===("undefined"==typeof e?"undefined":t(e))&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},y=function(e,t,n){e.hasOwnProperty(t)&&e[t].apply(n||this,Array.prototype.slice.call(arguments,3))};if(f.mobile="ontouchstart"in r,e===!1)throw new Error("Pressure requires a window with a document");"object"===("undefined"==typeof module?"undefined":t(module))&&"object"===t(module.exports)?module.exports=u:e.Pressure=u}("undefined"!=typeof window?window:!1);

@@ -1,4 +0,63 @@

# pressure
# pressure.js
Pressure is a JavaScript library that makes dealing with Apple's Force Touch and 3D Touch simple. Force Touch for new Macs and 3D Touch for the new iPhone 6s and 6s Plus, all bundled under one roof with a simple API that makes working with them painless.
Pressure gives you a handle on browsers that do and don't support Force or 3D touch so you can plan for the users experince if they don't support it.
Head over to the [documentation](http://yamartino.github.com/pressure) website for installation instructions and how to use pressure.js
## Install
download pressure.min.js or pressure.js files from GitHub or install with npm or bower
#### npm
```
npm install pressure --save
```
#### bower
```
bower install pressure --save
```
## Setup
Use pressure in the global space:
```javascript
Pressure.set('#id-name', {
change: function(force){
this.innerHTML = forcel
}
});
```
OR use it with browserify or CommonJS like setups:
```javascript
var Pressure = require('pressure');
Pressure.set('#id-name', {
change: function(force){
this.innerHTML = forcel
}
});
```
## Usage
NOTE: the "this" keyword in each of the callback methods will be the element itself that has force applied to it
```javascript
Pressure.set('#element', {
start: function(){
// this is called on force start
},
end: function(){
// this is called on force end
},
startDeepPress: function(){
// this is called on "force click" / "deep press", aka once the force is greater than 0.5
},
endDeepPress: function(){
// this is called when the "force click" / "deep press" end
},
change: function(force, event){
// this is called every time there is a change in pressure
// force will always be a value from 0 to 1 on mobile and desktop
},
unsupported: function(){
// this is called once there is a touch on the element and the device or browser does not support Force or 3D touch
}
});
```

@@ -21,13 +21,8 @@ //--------------------- Public API Section ---------------------//

// the interpolate method allows for interpolating a value between two values based on two input values
// the map method allows for interpolating a value from one range of values to another
// example from the Arduino documentation: https://www.arduino.cc/en/Reference/Map
interpolate(x, in_min, in_max, out_min, out_max){
map(x, in_min, in_max, out_min, out_max){
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
},
// map is an alias for the above 'interpolate' method
map(){
return this.interpolate(...arguments);
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc