passive-events-support
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";function e(){let e=!1;try{const t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}catch(e){}return e}window.passiveSupported=e(),function(t=null){const n=t||["scroll","wheel","touchstart","touchmove","touchenter","touchend","touchleave","mouseout","mouseleave","mouseup","mousedown","mousemove","mouseenter","mousewheel","mouseover"],o=EventTarget.prototype.addEventListener;EventTarget.prototype.addEventListener=function(...t){!n.includes(t[0])||t[2]&&void 0!==t[2].passive||(t[2]={...t[2]||{},...e()&&{passive:!t[1].toString().includes("preventDefault")}}),o.call(this,...t)}}(window.passiveEvents)})(); | ||
(()=>{"use strict";function e(){let e=!1;try{const t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}catch(e){}return e}window.passiveSupported=e(),function(t=null){const n=t||["scroll","wheel","touchstart","touchmove","touchenter","touchend","touchleave","mouseout","mouseleave","mouseup","mousedown","mousemove","mouseenter","mousewheel","mouseover"],o=EventTarget.prototype.addEventListener;EventTarget.prototype.addEventListener=function(...t){if(n.includes(t[0])&&(!t[2]||void 0===t[2].passive)){const n=t[1].toString(),[o,...s]=n.split("{"),i=o.replace(/(function|=>)/,"").trim(),u=s.join("{"),r=(i.match(/\(([^)]+)\)/)||[`(${i})`])[0].replace(/[()]/g,""),c=!(!r||!u.includes("preventDefault()")&&!u.includes(`(${r})`));t[2]={...t[2]||{},...e()&&{passive:!c}}}o.call(this,...t)}}(window.passiveEvents)})(); |
{ | ||
"name": "passive-events-support", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Passive Events Support", | ||
@@ -11,3 +11,3 @@ "main": "src/index.js", | ||
"repository": "git+https://github.com/ignasdamunskis/passive-events-support.git", | ||
"author": "Ignas Damunskis <ignas.damunskis@esl-asia.com>", | ||
"author": "Ignas Damunskis <ignas3run@gmail.com>", | ||
"license": "MIT", | ||
@@ -14,0 +14,0 @@ "bugs": { |
@@ -40,5 +40,15 @@ export function passiveSupported() { | ||
if (events.includes(args[0]) && (!args[2] || args[2].passive === undefined)) { | ||
const fn = args[1].toString() | ||
const [fnDeclaration, ...fnContents] = fn.split('{') | ||
const fnName = fnDeclaration.replace(/(function|=>)/, '').trim() | ||
const fnContent = fnContents.join('{') | ||
const fnEvent = (fnName.match(/\(([^)]+)\)/) || [`(${fnName})`])[0].replace(/[()]/g, '') | ||
const fnPrevented = !!(fnEvent && ( | ||
fnContent.includes('preventDefault()') || | ||
fnContent.includes(`(${fnEvent})`) | ||
)) | ||
args[2] = { | ||
...(args[2] || {}), | ||
...(passiveSupported() && { passive: !args[1].toString().includes('preventDefault') }) | ||
...(passiveSupported() && { passive: !fnPrevented }) | ||
} | ||
@@ -45,0 +55,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8802
7
52