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

creepyface

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

creepyface - npm Package Compare versions

Comparing version 3.0.2 to 3.2.0

65

dist/creepyface.cjs.js

@@ -234,3 +234,5 @@ 'use strict';

timeToDefault: userOptions.timeToDefault || 1000,
debug: userOptions.debug || function () {}
onDebug: userOptions.onDebug || function () {},
onAttach: userOptions.onAttach || function () {},
onDetach: userOptions.onDetach || function () {}
};

@@ -327,5 +329,6 @@ }

var subscribed = preload(img, options).then(function () {
options.onAttach();
return creepy(img, options).subscribe(function (data) {
setSrc(data.src);
options.debug(data);
options.onDebug(data);
});

@@ -338,2 +341,3 @@ });

setSrc(options.src);
options.onDetach();
});

@@ -344,18 +348,45 @@ };

var watchElement = (function (node, onAdded, onRemoved) {
var wasAdded = !!node.parentNode;
if (wasAdded) onAdded();
if (!window.MutationObserver) return function () {};
var observer = new window.MutationObserver(function (mutations) {
if (!node.parentNode && wasAdded) {
onRemoved();
wasAdded = false;
} else if (node.parentNode && !wasAdded) {
onAdded();
wasAdded = true;
}
});
observer.observe(document, { childList: true, subtree: true });
return function () {
return observer.disconnect();
var isReady = function isReady(is) {
return is ? onAdded() : onRemoved();
};
var IntersectionObserver = window.IntersectionObserver;
var MutationObserver = window.MutationObserver;
if (IntersectionObserver) {
var observer = new IntersectionObserver(function (changes) {
if (changes.length > 0) {
isReady(changes[0].isIntersecting);
}
}, {});
observer.observe(node);
return function () {
return observer.disconnect();
};
} else if (MutationObserver) {
var wasInDOM = document.body && document.body.contains(node);
if (wasInDOM) isReady(true);
var _observer = new MutationObserver(function (mutations) {
var isInDOM = document.body && document.body.contains(node);
if (!isInDOM && wasInDOM) {
isReady(false);
wasInDOM = false;
} else if (isInDOM && !wasInDOM) {
isReady(true);
wasInDOM = true;
}
});
_observer.observe(document, { childList: true, subtree: true });
return function () {
return _observer.disconnect();
};
} else {
if (document.body && document.body.contains(node)) isReady(true);
node.addEventListener('DOMNodeInserted', function () {
return isReady(true);
}, false);
node.addEventListener('DOMNodeRemoved', function () {
return isReady(false);
}, false);
return function () {};
}
});

@@ -362,0 +393,0 @@ /* global HTMLElement */

@@ -230,3 +230,5 @@ import loadImages from 'image-promise';

timeToDefault: userOptions.timeToDefault || 1000,
debug: userOptions.debug || function () {}
onDebug: userOptions.onDebug || function () {},
onAttach: userOptions.onAttach || function () {},
onDetach: userOptions.onDetach || function () {}
};

@@ -323,5 +325,6 @@ }

var subscribed = preload(img, options).then(function () {
options.onAttach();
return creepy(img, options).subscribe(function (data) {
setSrc(data.src);
options.debug(data);
options.onDebug(data);
});

@@ -334,2 +337,3 @@ });

setSrc(options.src);
options.onDetach();
});

@@ -340,18 +344,45 @@ };

var watchElement = (function (node, onAdded, onRemoved) {
var wasAdded = !!node.parentNode;
if (wasAdded) onAdded();
if (!window.MutationObserver) return function () {};
var observer = new window.MutationObserver(function (mutations) {
if (!node.parentNode && wasAdded) {
onRemoved();
wasAdded = false;
} else if (node.parentNode && !wasAdded) {
onAdded();
wasAdded = true;
}
});
observer.observe(document, { childList: true, subtree: true });
return function () {
return observer.disconnect();
var isReady = function isReady(is) {
return is ? onAdded() : onRemoved();
};
var IntersectionObserver = window.IntersectionObserver;
var MutationObserver = window.MutationObserver;
if (IntersectionObserver) {
var observer = new IntersectionObserver(function (changes) {
if (changes.length > 0) {
isReady(changes[0].isIntersecting);
}
}, {});
observer.observe(node);
return function () {
return observer.disconnect();
};
} else if (MutationObserver) {
var wasInDOM = document.body && document.body.contains(node);
if (wasInDOM) isReady(true);
var _observer = new MutationObserver(function (mutations) {
var isInDOM = document.body && document.body.contains(node);
if (!isInDOM && wasInDOM) {
isReady(false);
wasInDOM = false;
} else if (isInDOM && !wasInDOM) {
isReady(true);
wasInDOM = true;
}
});
_observer.observe(document, { childList: true, subtree: true });
return function () {
return _observer.disconnect();
};
} else {
if (document.body && document.body.contains(node)) isReady(true);
node.addEventListener('DOMNodeInserted', function () {
return isReady(true);
}, false);
node.addEventListener('DOMNodeRemoved', function () {
return isReady(false);
}, false);
return function () {};
}
});

@@ -358,0 +389,0 @@ /* global HTMLElement */

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

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.creepyFace=t()}(this,function(){"use strict";function n(t){if(!t)return Promise.reject();if("string"==typeof t){var e=t;(t=new Image).src=e}else{if(void 0!==t.length){var r=[].map.call(t,function(t){return n(t).catch(function(n){return n})});return Promise.all(r).then(function(n){var t=n.filter(function(n){return n.naturalWidth});return t.length===n.length?t:Promise.reject({loaded:t,errored:n.filter(function(n){return!n.naturalWidth})})})}if("IMG"!==t.tagName)return Promise.reject()}var o=new Promise(function(n,e){function r(){t.naturalWidth?n(t):e(t),t.removeEventListener("load",r),t.removeEventListener("error",r)}t.naturalWidth?n(t):t.complete?e(t):(t.addEventListener("load",r),t.addEventListener("error",r))});return o.image=t,o}function t(n){n.forEach(function(n){n.style.position="fixed",n.style.height="0px";var t=document.body;t&&(t.appendChild(n),setTimeout(function(){return t.removeChild(n)},1e3))})}function e(n,e){return a(s(e)).then(function(e){n.creepyFaceReachableImages=e,f&&t(e)})}function r(n){return function(t){var e;return e=/^data\-/.test(t.name),void 0===n?e:e&&n.test(t.name.slice(5))}}function o(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}function i(n){var t=l(n),e=t.src,r=void 0===e?{}:e,o=t.fieldofvision,i=t.timetodefault,u={src:n.getAttribute("src")};return i&&(u.timeToDefault=parseFloat(i)),o&&(u.fieldOfVision=parseFloat(o)),r.hover&&(u.hover=r.hover),r.look&&(u.looks=T(r.look)),u}function u(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Object.assign({},i(n),t);if(!e.src)throw new Error("A default URL must be specified");return{fieldOfVision:e.fieldOfVision||150,src:e.src,hover:e.hover||"",points:e.points||O([h,M]),looks:e.looks||[],timeToDefault:e.timeToDefault||1e3,debug:e.debug||function(){}}}function c(n,t){var e=function(){},r=X(n,function(){e=W(n,t)},function(){e()});return function(){r(),e()}}var a=n,f="undefined"!=typeof navigator&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),s=function(n){var t=n.looks.map(function(n){return n.src});return n.src&&t.push(n.src),n.hover&&t.push(n.hover),t},l=function(n,t){var e={};return void 0===(t=t||{}).separator&&(t.separator="-"),Array.prototype.slice.call(n.attributes).filter(r(t.pattern)).forEach(function(n){n.name.slice(5).split(t.separator).reduce(function(t,e,r,o){return"data"===e?t:(r===o.length-1?t[e]=n.value:t[e]=t[e]||{},t[e])},e)}),e},d=function(){function n(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),v=function(){function n(t){o(this,n),this.subscriber=function(n){return function(){}},this.subscriber=t}return d(n,[{key:"subscribe",value:function(n){var t={next:n},e=this.subscriber(t);return"function"==typeof e?{unsubscribe:e}:e}}]),n}(),h=new v(function(n){var t=function(t){return n.next([t.clientX,t.clientY])};return document.addEventListener("mousemove",t,!0),function(){return document.removeEventListener("mousemove",t,!0)}}),m=function(n,t){return n.map(function(n,e){return n-t[e]})},p=function(n,t){return n.map(function(n,e){return n+t[e]})},b=function(n){return n?n<0?-1:1:0},y=function(n){return n*Math.PI/180},g=function(n){return 180*n/Math.PI},w=function(n,t){return(t+n%t)%t},x=function(n){return g(w(Math.atan2(n[1],n[0]),2*Math.PI))},E=function(n,t){return[n[0]*Math.cos(y(t))-n[1]*Math.sin(y(t)),n[0]*Math.sin(y(t))+n[1]*Math.cos(y(t))]},M=new v(function(n){var t=function(t){var e=[0,0],r=!0,o=!1,i=void 0;try{for(var u,c=t.touches[Symbol.iterator]();!(r=(u=c.next()).done);r=!0){var a=u.value;e=p(e,[a.clientX,a.clientY])}}catch(n){o=!0,i=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw i}}n.next(e)};return document.addEventListener("touchmove",t,!0),function(){return document.removeEventListener("touchmove",t,!0)}}),O=function(n){return new v(function(t){var e=t.next.bind(t),r=n.map(function(n){return n.subscribe(e)});return function(){return r.forEach(function(n){return n.unsubscribe()})}})},T=function(n){var t=[],e=!0,r=!1,o=void 0;try{for(var i,u=Object.keys(n)[Symbol.iterator]();!(e=(i=u.next()).done);e=!0){var c=i.value,a=n[c];a&&t.push({angle:parseFloat(c),src:a})}}catch(n){r=!0,o=n}finally{try{!e&&u.return&&u.return()}finally{if(r)throw o}}return t},j=function(n){var t=n.getBoundingClientRect();return{y:t.top+window.pageYOffset+t.height/2,x:t.left+window.pageXOffset+t.width/2}},k=function(n){var t=j(n);return[t.x,t.y]},L=function(n,t){return x(E(m(p([window.scrollX,window.scrollY],t),k(n)),90))},P=function(){function n(n,t){var e=[],r=!0,o=!1,i=void 0;try{for(var u,c=n[Symbol.iterator]();!(r=(u=c.next()).done)&&(e.push(u.value),!t||e.length!==t);r=!0);}catch(n){o=!0,i=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw i}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return n(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),F=function(n){return Math.abs(n)>180?n-360*b(n):n},I=function(n){return function(t,e){return Math.abs(F(t.angle-n))-Math.abs(F(e.angle-n))}},A=function(n,t){return t.slice(0).sort(I(n))[0]},N=function(n,t,e){return n>=t&&n<=e},D=function(n,t){var e=n.left,r=n.top,o=n.right,i=n.bottom,u=P(t,2),c=u[0],a=u[1];return N(c,e,o)&&N(a,r,i)},S=function(n,t){var e=P(t,2),r=e[0],o=e[1];return document.elementFromPoint?document.elementFromPoint(r,o)===n:D(n.getBoundingClientRect(),[r,o])},C=function(n,t,e,r){var o=r.looks,i=r.hover,u=r.fieldOfVision,c=r.src;if(i&&S(n,t))c=i;else{var a=A(e,o);a&&Math.abs(F(a.angle-e))<u/2&&(c=a.src)}return c},R=function(n,t,e){function r(){var f=Date.now()-c;f<t&&f>=0?o=setTimeout(r,t-f):(o=null,e||(a=n.apply(u,i),u=i=null))}var o,i,u,c,a;null==t&&(t=100);var f=function(){u=this,i=arguments,c=Date.now();var f=e&&!o;return o||(o=setTimeout(r,t)),f&&(a=n.apply(u,i),u=i=null),a};return f.clear=function(){o&&(clearTimeout(o),o=null)},f},V=function(n,t){return new v(function(e){var r=R(function(){return e.next({src:t.src,options:t})},t.timeToDefault);return t.points.subscribe(function(o){var i=L(n,o),u=C(n,o,i,t);e.next({point:o,angle:i,src:u,options:t}),r()})})},W=function(n,t){var r=u(n,t),o=function(t){n.src=t},i=e(n,r).then(function(){return V(n,r).subscribe(function(n){o(n.src),r.debug(n)})});return function(){return i.then(function(n){n.unsubscribe(),o(r.src)})}},X=function(n,t,e){var r=!!n.parentNode;if(r&&t(),!window.MutationObserver)return function(){};var o=new window.MutationObserver(function(o){!n.parentNode&&r?(e(),r=!1):n.parentNode&&!r&&(t(),r=!0)});return o.observe(document,{childList:!0,subtree:!0}),function(){return o.disconnect()}},Y=function(n){return!(!n||"object"!=typeof n)&&("object"==typeof window&&"object"==typeof window.Node?n instanceof window.Node:"number"==typeof n.nodeType&&"string"==typeof n.nodeName)};return function(n){return Y(n)?[n]:"string"==typeof n?[].slice.call(document.querySelectorAll(n)):void 0}("img[data-creepy]").forEach(function(n){n instanceof HTMLImageElement&&c(n)}),c});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.creepyFace=t()}(this,function(){"use strict";function n(t){if(!t)return Promise.reject();if("string"==typeof t){var e=t;(t=new Image).src=e}else{if(void 0!==t.length){var r=[].map.call(t,function(t){return n(t).catch(function(n){return n})});return Promise.all(r).then(function(n){var t=n.filter(function(n){return n.naturalWidth});return t.length===n.length?t:Promise.reject({loaded:t,errored:n.filter(function(n){return!n.naturalWidth})})})}if("IMG"!==t.tagName)return Promise.reject()}var o=new Promise(function(n,e){function r(){t.naturalWidth?n(t):e(t),t.removeEventListener("load",r),t.removeEventListener("error",r)}t.naturalWidth?n(t):t.complete?e(t):(t.addEventListener("load",r),t.addEventListener("error",r))});return o.image=t,o}function t(n){n.forEach(function(n){n.style.position="fixed",n.style.height="0px";var t=document.body;t&&(t.appendChild(n),setTimeout(function(){return t.removeChild(n)},1e3))})}function e(n,e){return a(s(e)).then(function(e){n.creepyFaceReachableImages=e,f&&t(e)})}function r(n){return function(t){var e;return e=/^data\-/.test(t.name),void 0===n?e:e&&n.test(t.name.slice(5))}}function o(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}function i(n){var t=l(n),e=t.src,r=void 0===e?{}:e,o=t.fieldofvision,i=t.timetodefault,u={src:n.getAttribute("src")};return i&&(u.timeToDefault=parseFloat(i)),o&&(u.fieldOfVision=parseFloat(o)),r.hover&&(u.hover=r.hover),r.look&&(u.looks=O(r.look)),u}function u(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Object.assign({},i(n),t);if(!e.src)throw new Error("A default URL must be specified");return{fieldOfVision:e.fieldOfVision||150,src:e.src,hover:e.hover||"",points:e.points||D([h,x]),looks:e.looks||[],timeToDefault:e.timeToDefault||1e3,onDebug:e.onDebug||function(){},onAttach:e.onAttach||function(){},onDetach:e.onDetach||function(){}}}function c(n,t){var e=function(){},r=X(n,function(){e=W(n,t)},function(){e()});return function(){r(),e()}}var a=n,f="undefined"!=typeof navigator&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),s=function(n){var t=n.looks.map(function(n){return n.src});return n.src&&t.push(n.src),n.hover&&t.push(n.hover),t},l=function(n,t){var e={};return void 0===(t=t||{}).separator&&(t.separator="-"),Array.prototype.slice.call(n.attributes).filter(r(t.pattern)).forEach(function(n){n.name.slice(5).split(t.separator).reduce(function(t,e,r,o){return"data"===e?t:(r===o.length-1?t[e]=n.value:t[e]=t[e]||{},t[e])},e)}),e},d=function(){function n(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),v=function(){function n(t){o(this,n),this.subscriber=function(n){return function(){}},this.subscriber=t}return d(n,[{key:"subscribe",value:function(n){var t={next:n},e=this.subscriber(t);return"function"==typeof e?{unsubscribe:e}:e}}]),n}(),h=new v(function(n){var t=function(t){return n.next([t.clientX,t.clientY])};return document.addEventListener("mousemove",t,!0),function(){return document.removeEventListener("mousemove",t,!0)}}),m=function(n,t){return n.map(function(n,e){return n-t[e]})},b=function(n,t){return n.map(function(n,e){return n+t[e]})},p=function(n){return n?n<0?-1:1:0},y=function(n){return n*Math.PI/180},g=function(n){return 180*n/Math.PI},w=function(n,t){return(t+n%t)%t},E=function(n){return g(w(Math.atan2(n[1],n[0]),2*Math.PI))},M=function(n,t){return[n[0]*Math.cos(y(t))-n[1]*Math.sin(y(t)),n[0]*Math.sin(y(t))+n[1]*Math.cos(y(t))]},x=new v(function(n){var t=function(t){var e=[0,0],r=!0,o=!1,i=void 0;try{for(var u,c=t.touches[Symbol.iterator]();!(r=(u=c.next()).done);r=!0){var a=u.value;e=b(e,[a.clientX,a.clientY])}}catch(n){o=!0,i=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw i}}n.next(e)};return document.addEventListener("touchmove",t,!0),function(){return document.removeEventListener("touchmove",t,!0)}}),D=function(n){return new v(function(t){var e=t.next.bind(t),r=n.map(function(n){return n.subscribe(e)});return function(){return r.forEach(function(n){return n.unsubscribe()})}})},O=function(n){var t=[],e=!0,r=!1,o=void 0;try{for(var i,u=Object.keys(n)[Symbol.iterator]();!(e=(i=u.next()).done);e=!0){var c=i.value,a=n[c];a&&t.push({angle:parseFloat(c),src:a})}}catch(n){r=!0,o=n}finally{try{!e&&u.return&&u.return()}finally{if(r)throw o}}return t},L=function(n){var t=n.getBoundingClientRect();return{y:t.top+window.pageYOffset+t.height/2,x:t.left+window.pageXOffset+t.width/2}},T=function(n){var t=L(n);return[t.x,t.y]},j=function(n,t){return E(M(m(b([window.scrollX,window.scrollY],t),T(n)),90))},k=function(){function n(n,t){var e=[],r=!0,o=!1,i=void 0;try{for(var u,c=n[Symbol.iterator]();!(r=(u=c.next()).done)&&(e.push(u.value),!t||e.length!==t);r=!0);}catch(n){o=!0,i=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw i}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return n(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),I=function(n){return Math.abs(n)>180?n-360*p(n):n},P=function(n){return function(t,e){return Math.abs(I(t.angle-n))-Math.abs(I(e.angle-n))}},A=function(n,t){return t.slice(0).sort(P(n))[0]},F=function(n,t,e){return n>=t&&n<=e},N=function(n,t){var e=n.left,r=n.top,o=n.right,i=n.bottom,u=k(t,2),c=u[0],a=u[1];return F(c,e,o)&&F(a,r,i)},S=function(n,t){var e=k(t,2),r=e[0],o=e[1];return document.elementFromPoint?document.elementFromPoint(r,o)===n:N(n.getBoundingClientRect(),[r,o])},C=function(n,t,e,r){var o=r.looks,i=r.hover,u=r.fieldOfVision,c=r.src;if(i&&S(n,t))c=i;else{var a=A(e,o);a&&Math.abs(I(a.angle-e))<u/2&&(c=a.src)}return c},R=function(n,t,e){function r(){var f=Date.now()-c;f<t&&f>=0?o=setTimeout(r,t-f):(o=null,e||(a=n.apply(u,i),u=i=null))}var o,i,u,c,a;null==t&&(t=100);var f=function(){u=this,i=arguments,c=Date.now();var f=e&&!o;return o||(o=setTimeout(r,t)),f&&(a=n.apply(u,i),u=i=null),a};return f.clear=function(){o&&(clearTimeout(o),o=null)},f},V=function(n,t){return new v(function(e){var r=R(function(){return e.next({src:t.src,options:t})},t.timeToDefault);return t.points.subscribe(function(o){var i=j(n,o),u=C(n,o,i,t);e.next({point:o,angle:i,src:u,options:t}),r()})})},W=function(n,t){var r=u(n,t),o=function(t){n.src=t},i=e(n,r).then(function(){return r.onAttach(),V(n,r).subscribe(function(n){o(n.src),r.onDebug(n)})});return function(){return i.then(function(n){n.unsubscribe(),o(r.src),r.onDetach()})}},X=function(n,t,e){var r=function(n){return n?t():e()},o=window.IntersectionObserver,i=window.MutationObserver;if(o){var u=new o(function(n){n.length>0&&r(n[0].isIntersecting)},{});return u.observe(n),function(){return u.disconnect()}}if(i){var c=document.body&&document.body.contains(n);c&&r(!0);var a=new i(function(t){var e=document.body&&document.body.contains(n);!e&&c?(r(!1),c=!1):e&&!c&&(r(!0),c=!0)});return a.observe(document,{childList:!0,subtree:!0}),function(){return a.disconnect()}}return document.body&&document.body.contains(n)&&r(!0),n.addEventListener("DOMNodeInserted",function(){return r(!0)},!1),n.addEventListener("DOMNodeRemoved",function(){return r(!1)},!1),function(){}},Y=function(n){return!(!n||"object"!=typeof n)&&("object"==typeof window&&"object"==typeof window.Node?n instanceof window.Node:"number"==typeof n.nodeType&&"string"==typeof n.nodeName)};return function(n){return Y(n)?[n]:"string"==typeof n?[].slice.call(document.querySelectorAll(n)):void 0}("img[data-creepy]").forEach(function(n){n instanceof HTMLImageElement&&c(n)}),c});
{
"name": "creepyface",
"version": "3.0.2",
"version": "3.2.0",
"author": "Alejandro Tardín <alejandro@tardin.com>",

@@ -5,0 +5,0 @@ "license": "MIT",

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