creepyface
Advanced tools
Comparing version 8.0.2 to 8.0.3-alpha.0
export type Degrees = number | ||
export type Point = [number, number] | ||
export type Cancel = () => void | ||
export type Cancel = (keepSrc?: boolean) => void | ||
export type SimpleCancel = () => void | ||
export type Consumer<T> = (t: T) => void | ||
export type PointProvider = (consumer: Consumer<Point | null>) => Cancel | ||
export type PointProvider = (consumer: Consumer<Point | null>) => SimpleCancel | ||
export type PointMapper = ( | ||
@@ -8,0 +9,0 @@ point: Point | null, |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).creepyface=n()}(this,function(){"use strict";function n(n,e){var t,r=Object.keys(n);return Object.getOwnPropertySymbols&&(t=Object.getOwnPropertySymbols(n),e&&(t=t.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),r.push.apply(r,t)),r}function s(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?n(Object(o),!0).forEach(function(e){var n,t;n=r,e=o[t=e],t in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function t(e){return e=e?parseFloat(e):NaN,isNaN(e)?void 0:e}function d(e){return{hover:e.getAttribute("data-src-hover")||void 0,looks:function(e){for(var n=/data-src-look-(\d+)/i,t=[],r=0;r<e.attributes.length;r++){var o=e.attributes[r],i=n.exec(o.name);i&&t.push({angle:parseFloat(i[1]),src:o.value})}return t.length?t:void 0}(e),points:e.getAttribute("data-points")||void 0,timeToDefault:t(e.getAttribute("data-timetodefault")),fieldOfVision:t(e.getAttribute("data-fieldofvision"))}}function p(){}function i(e,n){return[e[0]+n[0],e[1]+n[1]]}function c(e){return e*Math.PI/180}function u(e){return n=Math.atan2(e[1],e[0]),180*(((e=2*Math.PI)+n%e)%e)/Math.PI;var n}function h(c,u,a,f){var l,s=!1,d=0;function p(){l&&clearTimeout(l)}function e(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=this,o=Date.now()-d;function i(){d=Date.now(),a.apply(r,n)}s||(f&&!l&&i(),p(),void 0===f&&c<o?i():!0!==u&&(l=setTimeout(f?function(){l=void 0}:i,void 0===f?c-o:c)))}return"boolean"!=typeof u&&(f=a,a=u,u=void 0),e.cancel=function(){p(),s=!0},e}function r(e){return{provider:e,mapper:1<arguments.length&&void 0!==arguments[1]?arguments[1]:function(e){return e},registrations:[]}}function a(e){var n=o[e];return n||(console.error("No point provider registered as '".concat(e,"'.")),null)}var o={mouse:r(function(n){function e(e){return n([e.clientX,e.clientY])}return window.addEventListener("mousemove",e,!0),function(){return window.removeEventListener("mousemove",e,!0)}}),finger:r(function(o){function e(e){for(var n=[0,0],t=0;t<e.touches.length;t++)var r=e.touches[t],n=i(n,[r.clientX,r.clientY]);o(n)}return window.addEventListener("touchmove",e,!0),function(){return window.removeEventListener("touchmove",e,!0)}})},f=[o.mouse,o.finger],l=h(50,function(t,e){var n=e.registrations,r=e.mapper;return n.forEach(function(e){var n=e.consumer,e=e.img;return n(r(t,e))})});function v(o,i,e){var n=function(e){if(!e||"pointer"===e)return f;var n=[];return e.split(",").map(a).forEach(function(e){e&&n.push(e)}),0===n.length?f:n}(e).map(function(n){var e=n.registrations,t=n.provider,r={consumer:i,img:o};return e.push(r),1===e.length&&(n.cancel=t(function(e){return l(e,n)})),function(){e.splice(e.indexOf(r),1),0===e.length&&(n.cancel&&n.cancel(),delete n.cancel)}});return function(){return n.forEach(function(e){return e()})}}function g(o,i){var c=[];o.forEach(function(e){var n,t,r;n=e,t=function(e){c.push(e),c.length===o.length&&i(c)},(r=new Image).src=n,r.onload=r.onerror=function(){r.naturalWidth||console.error("Creepyface was unable to load ".concat(n)),r.onload=null,r.onerror=null,t(r)}})}function m(e,n){return u((t=i([window.scrollX,window.scrollY],n),o=(r=e).getBoundingClientRect(),n=o.left,e=o.top,r=o.width,o=o.height,o=[n+window.pageXOffset+r/2,e+window.pageYOffset+o/2],t=[t[0]-o[0],t[1]-o[1]],o=90,[t[0]*Math.cos(c(o))-t[1]*Math.sin(c(o)),t[0]*Math.sin(c(o))+t[1]*Math.cos(c(o))]));var t,r,o}function b(e){return 180<Math.abs(e)?e-360*(e<0?-1:1):e}function w(e,n){return n.slice(0).sort((t=e,function(e,n){return Math.abs(b(e.angle-t))-Math.abs(b(n.angle-t))}))[0];var t}function y(e,n,t){return n<=e&&e<=t}function O(e,n,t){return!t.optimizePerformance&&document.elementFromPoint?document.elementFromPoint(n[0],n[1])===e:(r=e.getBoundingClientRect(),o=[n[0],n[1]],t=r.left,e=r.top,n=r.right,r=r.bottom,y(o[0],t,n)&&y(o[1],e,r));var r,o}function P(u,e){function n(){return delete u.__creepyfaceCancel}var t,r,o,i,c,a,f=function(e,n){if(n=1<arguments.length&&void 0!==n?n:{},n=s(s({},d(e)),n),!(e=e.getAttribute("src")))throw new Error("A default URL must be specified");return{src:e,hover:n.hover||"",points:n.points,looks:n.looks||[],timeToDefault:void 0!==n.timeToDefault?n.timeToDefault:1e3,fieldOfVision:n.fieldOfVision||150,optimizePerformance:n.optimizePerformance,onDebug:n.onDebug||p,onAttach:n.onAttach||p,onDetach:n.onDetach||p}}(u,e),l=(t=u,i=n,c=!(o=function(){function r(e,n,t){u.src=e,f.onDebug({src:e,point:n,angle:t,options:f})}function n(e){if(!e)return r(f.src);var n=m(u,e),t=function(e,n,t,r){var o=r.looks,i=r.hover,c=r.fieldOfVision;if(i&&O(e,n,r))return i;if(0<o.length){o=w(t,o);if(Math.abs(b(o.angle-t))<=c/2)return o.src}return r.src}(u,e,n,f);r(t,e,n),0<f.timeToDefault&&i()}var e,t,o,i=(e=f.timeToDefault,t=function(){return r(f.src)},void 0===o?h(e,t,!1):h(e,o,!1!==t)),c=v(u,n,f.points);return f.onAttach({setPointProvider:function(e){c(),c=v(u,n,e)}}),function(){i.cancel(),c(),u.src=f.src,f.onDetach()}}),a=function(){c=!0},g(((r=(e=r=f).looks.map(function(e){return e.src})).push(e.src),e.hover&&r.push(e.hover),r),function(e){if(!c){if(e.some(function(e){return!e.naturalWidth}))return i();t.__creepyfaceReachableImages=e;var n=o();a=function(){n(),delete t.__creepyfaceReachableImages}}}),function(){return a()});return u.__creepyfaceCancel=function(){l(),n()}}return P.cancel=function(e){e=e.__creepyfaceCancel;e&&e()},P.registerPointProvider=function(e,n,t){return o[e]=r(n,t)},"undefined"!=typeof window&&document.addEventListener("DOMContentLoaded",function(){for(var e=document.querySelectorAll("img[data-creepy],img[data-creepyface]"),n=0;n<e.length;n++)P(e[n])}),P}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).creepyface=n()}(this,function(){"use strict";function n(n,e){var t,r=Object.keys(n);return Object.getOwnPropertySymbols&&(t=Object.getOwnPropertySymbols(n),e&&(t=t.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),r.push.apply(r,t)),r}function s(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?n(Object(o),!0).forEach(function(e){var n,t;n=r,e=o[t=e],t in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function t(e){return e=e?parseFloat(e):NaN,isNaN(e)?void 0:e}function d(e){return{hover:e.getAttribute("data-src-hover")||void 0,looks:function(e){for(var n=/data-src-look-(\d+)/i,t=[],r=0;r<e.attributes.length;r++){var o=e.attributes[r],i=n.exec(o.name);i&&t.push({angle:parseFloat(i[1]),src:o.value})}return t.length?t:void 0}(e),points:e.getAttribute("data-points")||void 0,timeToDefault:t(e.getAttribute("data-timetodefault")),fieldOfVision:t(e.getAttribute("data-fieldofvision"))}}function p(){}function i(e,n){return[e[0]+n[0],e[1]+n[1]]}function c(e){return e*Math.PI/180}function u(e){return n=Math.atan2(e[1],e[0]),180*(((e=2*Math.PI)+n%e)%e)/Math.PI;var n}function h(c,u,a,f){var l,s=!1,d=0;function p(){l&&clearTimeout(l)}function e(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=this,o=Date.now()-d;function i(){d=Date.now(),a.apply(r,n)}s||(f&&!l&&i(),p(),void 0===f&&c<o?i():!0!==u&&(l=setTimeout(f?function(){l=void 0}:i,void 0===f?c-o:c)))}return"boolean"!=typeof u&&(f=a,a=u,u=void 0),e.cancel=function(){p(),s=!0},e}function r(e){return{provider:e,mapper:1<arguments.length&&void 0!==arguments[1]?arguments[1]:function(e){return e},registrations:[]}}function a(e){var n=o[e];return n||(console.error("No point provider registered as '".concat(e,"'.")),null)}var o={mouse:r(function(n){function e(e){return n([e.clientX,e.clientY])}return window.addEventListener("mousemove",e,!0),function(){return window.removeEventListener("mousemove",e,!0)}}),finger:r(function(o){function e(e){for(var n=[0,0],t=0;t<e.touches.length;t++)var r=e.touches[t],n=i(n,[r.clientX,r.clientY]);o(n)}return window.addEventListener("touchmove",e,!0),function(){return window.removeEventListener("touchmove",e,!0)}})},f=[o.mouse,o.finger],l=h(50,function(t,e){var n=e.registrations,r=e.mapper;return n.forEach(function(e){var n=e.consumer,e=e.img;return n(r(t,e))})});function v(o,i,e){var n=function(e){if(!e||"pointer"===e)return f;var n=[];return e.split(",").map(a).forEach(function(e){e&&n.push(e)}),0===n.length?f:n}(e).map(function(n){var e=n.registrations,t=n.provider,r={consumer:i,img:o};return e.push(r),1===e.length&&(n.cancel=t(function(e){return l(e,n)})),function(){e.splice(e.indexOf(r),1),0===e.length&&(n.cancel&&n.cancel(),delete n.cancel)}});return function(){return n.forEach(function(e){return e()})}}function g(o,i){var c=[];o.forEach(function(e){var n,t,r;n=e,t=function(e){c.push(e),c.length===o.length&&i(c)},(r=new Image).src=n,r.onload=r.onerror=function(){r.naturalWidth||console.error("Creepyface was unable to load ".concat(n)),r.onload=null,r.onerror=null,t(r)}})}function m(e,n){return u((t=i([window.scrollX,window.scrollY],n),o=(r=e).getBoundingClientRect(),n=o.left,e=o.top,r=o.width,o=o.height,o=[n+window.pageXOffset+r/2,e+window.pageYOffset+o/2],t=[t[0]-o[0],t[1]-o[1]],o=90,[t[0]*Math.cos(c(o))-t[1]*Math.sin(c(o)),t[0]*Math.sin(c(o))+t[1]*Math.cos(c(o))]));var t,r,o}function b(e){return 180<Math.abs(e)?e-360*(e<0?-1:1):e}function w(e,n){return n.slice(0).sort((t=e,function(e,n){return Math.abs(b(e.angle-t))-Math.abs(b(n.angle-t))}))[0];var t}function y(e,n,t){return n<=e&&e<=t}function O(e,n,t){return!t.optimizePerformance&&document.elementFromPoint?document.elementFromPoint(n[0],n[1])===e:(r=e.getBoundingClientRect(),o=[n[0],n[1]],t=r.left,e=r.top,n=r.right,r=r.bottom,y(o[0],t,n)&&y(o[1],e,r));var r,o}function P(u,e){function n(){return delete u.__creepyfaceCancel}var t,r,o,i,c,a,f=function(e,n){if(n=1<arguments.length&&void 0!==n?n:{},n=s(s({},d(e)),n),!(e=e.getAttribute("src")))throw new Error("A default URL must be specified");return{src:e,hover:n.hover||"",points:n.points,looks:n.looks||[],timeToDefault:void 0!==n.timeToDefault?n.timeToDefault:1e3,fieldOfVision:n.fieldOfVision||150,optimizePerformance:n.optimizePerformance,onDebug:n.onDebug||p,onAttach:n.onAttach||p,onDetach:n.onDetach||p}}(u,e),l=(t=u,i=n,c=!(o=function(){function r(e,n,t){u.src=e,f.onDebug({src:e,point:n,angle:t,options:f})}function n(e){if(!e)return r(f.src);var n=m(u,e),t=function(e,n,t,r){var o=r.looks,i=r.hover,c=r.fieldOfVision;if(i&&O(e,n,r))return i;if(0<o.length){o=w(t,o);if(Math.abs(b(o.angle-t))<=c/2)return o.src}return r.src}(u,e,n,f);r(t,e,n),0<f.timeToDefault&&i()}var e,t,o,i=(e=f.timeToDefault,t=function(){return r(f.src)},void 0===o?h(e,t,!1):h(e,o,!1!==t)),c=v(u,n,f.points);return f.onAttach({setPointProvider:function(e){c(),c=v(u,n,e)}}),function(e){i.cancel(),c(),e||(u.src=f.src),f.onDetach()}}),a=function(){c=!0},g(((r=(e=r=f).looks.map(function(e){return e.src})).push(e.src),e.hover&&r.push(e.hover),r),function(e){if(!c){if(e.some(function(e){return!e.naturalWidth}))return i();t.__creepyfaceReachableImages=e;var n=o();a=function(e){n(e),delete t.__creepyfaceReachableImages}}}),function(e){return a(e)});return u.__creepyfaceCancel=function(e){l(e),n()}}return P.cancel=function(e){e=e.__creepyfaceCancel;e&&e()},P.registerPointProvider=function(e,n,t){return o[e]=r(n,t)},"undefined"!=typeof window&&document.addEventListener("DOMContentLoaded",function(){for(var e=document.querySelectorAll("img[data-creepy],img[data-creepyface]"),n=0;n<e.length;n++)P(e[n])}),P}); | ||
//# sourceMappingURL=creepyface.umd.js.map |
{ | ||
"name": "creepyface", | ||
"version": "8.0.2", | ||
"version": "8.0.3-alpha.0", | ||
"main": "dist/creepyface.umd.js", | ||
@@ -63,3 +63,3 @@ "types": "dist/creepyface.d.ts", | ||
}, | ||
"gitHead": "5e55aba3cae334c8063d7c8991e771cf017dbe14" | ||
"gitHead": "f8809baeface4ebfe42cc32ecfbfe685403a28f8" | ||
} |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
37476
84
1