-
Notifications
You must be signed in to change notification settings - Fork 3
/
pointer3k.min.js
1 lines (1 loc) · 1.92 KB
/
pointer3k.min.js
1
"use strict";(function(){let t,n,e,o;let i,s,c,d;const p={points:{pointA:{cx:window.innerWidth/2,cy:window.innerHeight/2}}};window.Pointer3k=function(n){if(typeof n==="string"||Number.isInteger(n)){return window.Pointer3k.points[n]}else if(typeof n=="boolean"){d=n}else{n=n||p;t=Object.keys(n.points);e=n.points||{};i=n.console;s=n.initialPos||{pageX:window.innerWidth/2,pageY:window.innerHeight/2};c=n.listener||"mousemove";d=true;if(i){r();l(t)}r(s);window.addEventListener(c,function(t){if(d){r(t)}})}};function r(o){o=o||{};for(let i=0;i<t.length;i++){const s=t[i];let c;let d=e[s].cx=="center"?p.points["pointA"].cx:e[s].cx;let r=e[s].cy=="center"?p.points["pointA"].cy:e[s].cy;let l=(o.pageX||0)-d;let g=(o.pageY||0)-r;let y=Math.atan2(g,l);let f=(y*(180/Math.PI)+360)%360;let u=Math.hypot(l,g);c={cx:d,cy:r,x:l,y:g,rad:y,deg:f,dist:u};n=Object.keys(c);e[s]=c;a(c,i)}window.Pointer3k.points=e}function l(t){if(i){const e=document.createElement("div");if(!document.querySelector(".js-pgProps")){e.classList.add("js-pgProps");e.style.position="fixed";e.style.background="rgba(0, 0, 0, 0.7)";e.style.color="white";e.style.fontSize="9px";e.style.fontFamily="Arial";e.style.width=140+"px";e.style.top=0;e.style.right=0;document.body.appendChild(e)}if(document.querySelectorAll(".js-pgPoint").length<t.length){for(var n=0;n<t.length;n++){const o=t[n];const i=Object.keys(window.Pointer3k.points[o]);const s=document.createElement("div");const c=document.createElement("label");s.classList.add("js-pgPoint");c.innerHTML=o;c.style.padding="2px 5px";s.appendChild(c);for(let d=0;d<i.length;d++){const t=document.createElement("div");const n=i[d];t.classList.add("js-pgProp");t.style.padding="2px 5px 2px 15px";t.innerHTML=n+":"+window.Pointer3k.points[n];s.appendChild(t)}e.appendChild(s)}}o=document.querySelectorAll(".js-pgProp")}}function a(t,e){if(o){for(var i=0;i<n.length;i++){const s=e*n.length+i;const c=o[s];const d=n[i];const p=t[d];c.innerHTML=d+":"+p}}}})();