UNPKG

wtc-utility-helpers

Version:

Javascript helpers, perfect for non-jquery projects.

3 lines (2 loc) 2.54 kB
function e(e,t){return Math.random()*(t-e)+e}function t(t,n){return Math.round(e(t,n))}function n(e,t,n){return(1-n)*e+n*t}function o(e,t,n){return Math.min(Math.max(n,e),t)}function r(e,t=!0){let n,o,r=e.length;for(!1===t&&([...e]=e);0!==r;)o=Math.floor(Math.random()*r),r-=1,n=e[r],e[r]=e[o],e[o]=n;return e}function l(e,t,n=!0,o=!0){window.dispatchEvent(new CustomEvent(e,{bubbles:n,cancelable:o,detail:t}))}function i(e,t=!0){const n={top:0,left:0};if(!1===t)n.top=e.offsetTop,n.left=e.offsetLeft;else{const t=e.getBoundingClientRect(),o=window.pageYOffset,r=window.pageXOffset,l=document.body.clientTop||0,i=document.body.clientLeft||0;n.top+=Math.round(t.top+o-l),n.left+=Math.round(t.left+r-i)}return n}function f(e,t,n=!0){let o=!1;return e.parentNode===t&&(o=!0),!0===n&&!1===o&&e.parentNode&&(o=o(e.parentNode,t)),o}function a(e){return[...e.parentNode.children].filter(t=>t!==e)}function u(e,t=!0,n){return n||(n=[]),!0===t&&e.parentNode===document.body||e.parentNode&&(n.splice(0,0,[e.parentNode]),u(e.parentNode,t,n)),n}function s(e){let t=[];for(;e.parentNode;){if(e.id){t.unshift("#"+e.id);break}t.unshift(e==e.ownerDocument.documentElement?e.tagName:e.tagName+":nth-child("+c+")"),e=e.parentNode}return t.join(" > ")}function d(e){if(_els=e,e instanceof Node&&(_els=[e]),_els&&_els.length)for(let e=0;e<_els.length;e++){let t=_els[e];t instanceof Node&&(t.innerHTML=t.innerHTML.replace(/\s(?=[^\s]*$)/g,"&nbsp;"))}}function p(e){let t=[];if("object"==typeof e&&"FORM"==e.nodeName)for(let n=0;n<e.elements.length;n++){let o=e.elements[n];if(o.name&&!o.disabled&&"file"!=o.type&&"reset"!=o.type&&"submit"!=o.type&&"button"!=o.type)if("select-multiple"==o.type)for(let r=0;r<e.elements[n].options.length;r++)o.options[r].selected&&(t[t.length]={name:o.name,value:o.options[r].value});else("checkbox"!=o.type&&"radio"!=o.type||o.checked)&&(t[t.length]={name:o.name,value:o.value})}return t}function m(e){let{src:t}=e,n=function(e,t){if(null==e)return{};var n,o,r={},l=Object.keys(e);for(o=0;o<l.length;o++)t.indexOf(n=l[o])>=0||(r[n]=e[n]);return r}(e,["src"]);return new Promise((e,o)=>{const r=new Image;r.onload=()=>e(r),r.onerror=o;for(let[e,t]of Object.entries(n))r[e]=t;r.src=t})}export{m as asyncImageLoadfunction,o as clampfunction,l as fireCustomEvent,d as fixWidows,e as floatRandomBetween,u as getAncestors,i as getElementPosition,s as getSelectorForElement,a as getSiblings,f as isChildOf,n as lerp,t as randomBetween,p as serializeArray,r as shuffleArray}; //# sourceMappingURL=wtc-utility-helpers.modern.js.map