@danielgindi/dom-utils 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/dom-utils 1.0.10
2
+ * @danielgindi/dom-utils 1.0.11
3
3
  * git://github.com/danielgindi/dom-utils.git
4
4
  */
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/dom-utils 1.0.10
2
+ * @danielgindi/dom-utils 1.0.11
3
3
  * git://github.com/danielgindi/dom-utils.git
4
4
  */
5
5
  "use strict";const e=function(e,t){for(let[n,r]of Object.entries(t))e.style[n]=null==r?"":String(r)},t=function(e,t,n,r,o){return function(){let l,i,s,d,a=arguments.length<=0?void 0:arguments[0];if(e?(l=arguments.length<=1?void 0:arguments[1],i=!!(arguments.length<=2?void 0:arguments[2]),s=!!(arguments.length<=3?void 0:arguments[3]),d=!!(arguments.length<=4?void 0:arguments[4])):(i=!!(arguments.length<=1?void 0:arguments[1]),s=!!(arguments.length<=2?void 0:arguments[2]),d=!!(arguments.length<=3?void 0:arguments[3])),a===window)return a.document.documentElement[`client${n}`];if(9===a.nodeType){const e=a.documentElement,t=a.body;return Math.max(t[`scroll${n}`],e[`scroll${n}`],t[`offset${n}`],e[`offset${n}`],e[`client${n}`])}{let c,p,u=!1,f=!1;if(!e&&"getBoundingClientRect"in a&&(c=a.getBoundingClientRect()[t],u=!0,f=!0),(void 0===c||d||u!==i||f!==s)&&(p=e?getComputedStyle(a,l):getComputedStyle(a)),void 0===c){let e=p[t];"auto"===e?(c=a[`client${n}`],u=!0):c=parseFloat(e),"border-box"===p.boxSizing&&(u=!0,f=!0)}if(i!==u){let e=parseFloat(p[`padding-${r}`]||0)+parseFloat(p[`padding-${o}`]||0);i?c+=e:c-=e}if(s!==f){let e=parseFloat(p[`border-${r}-width`]||0)+parseFloat(p[`border-${o}-width`]||0);s?c+=e:c-=e}return c<0&&(c=0),d&&(c+=parseFloat(p[`margin-${r}`]||0)+parseFloat(p[`margin-${o}`]||0)),c}}},n=(e,t,n,r)=>function(t,o){let l=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],s=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(t===window)return;if(9===t.nodeType)return;const d=getComputedStyle(t);let a=!1;if("border-box"===d.boxSizing&&(a=!0),l=!!l,i=!!i,s=!!s,s&&(o-=(parseFloat(d[`margin-${n}`])||0)+(parseFloat(d[`margin-${r}`])||0)),l!==a){let e=parseFloat(d[`padding-${n}`]||0)+parseFloat(d[`padding-${r}`]||0);l?o-=e:o+=e}if(i!==a){let e=(parseFloat(d[`border-${n}-width`])||0)+(parseFloat(d[`border-${r}-width`])||0);i?o-=e:o+=e}o<0&&(o=0),t.style[e]=o+"px"},r=t(!1,"width","Width","left","right"),o=t(!1,"height","Height","top","bottom"),l=t(!0,"width","Width","left","right"),i=t(!0,"height","Height","top","bottom"),s=n("width",0,"left","right"),d=n("height",0,"top","bottom"),a=e=>{if(!e)return;let t=e.endsWith("ms");return parseFloat(e)*(t?1:1e3)},c=e=>/^-?(0?\.)?\d+m?s$/.test(e),p=e=>{let t=e.split(/\s+/),n=t[0],r=t[1],o=t[2],l=t[3];return c(o)?{delay:a(o),duration:a(r),name:n}:{delay:a(l),duration:a(r),name:n,timingFunction:o}};var u=Object.freeze({__proto__:null,anchoredPosition:function(e,t,n,o,l){let i,s,d,a;if(o||(o={width:r(e,!0,!0),height:r(e,!0,!0)}),"start"!==t&&"end"!==t||(null==l&&(l="rtl"===getComputedStyle(e).direction),t="start"===t?l?"right":"left":l?"left":"right"),"right"===t)i=o.width,d=0;else if("center"===t)i=o.width/2,d=i;else if("left"===t)i=0,d=o.width;else if(t&&"string"==typeof t&&"%"===t.charAt(t.length-1)){let n=(parseFloat(t)||0)/100;i=o.width*n,d=o.width*-n,null==l&&(l="rtl"===getComputedStyle(e).direction),l&&(i=o.width-i,d=o.width-i)}else i=parseFloat(t)||0,d=-i;if("bottom"===n)s=o.height,a=0;else if("center"===n)s=o.height/2,a=s;else if("top"===n)s=0,a=o.height;else if(n&&"string"==typeof n&&"%"===n.charAt(n.length-1)){let e=(parseFloat(n)||0)/100;s=o.height*e,a=o.height*-e}else s=parseFloat(n)||0,a=-s;return{left:i,top:s,right:d,bottom:a,xSpec:t,ySpec:n}},getCssProps:function(e,t){const n=getComputedStyle(e);let r={};for(let o of t){let t=n[o];("width"===o||"height"===o)&&"auto"===t&&e instanceof HTMLElement&&(t=e["offset"+o.substr(0,1).toUpperCase()+o.substr(1)],"border-box"!==n.boxSizing&&("width"===o?(t-=parseFloat(n.paddingLeft||0),t-=parseFloat(n.paddingRight||0),t-=parseFloat(n.borderLeftWidth||0),t-=parseFloat(n.borderRightWidth||0)):(t-=parseFloat(n.paddingTop||0),t-=parseFloat(n.paddingBottom||0),t-=parseFloat(n.borderTopWidth||0),t-=parseFloat(n.borderBottomWidth||0)),t<0&&(t=0)),t+="px"),r[o]=t}return r},getElementHeight:o,getElementOffset:e=>{if(!e.getClientRects().length)return{top:0,left:0};let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView;return{top:t.top+n.pageYOffset,left:t.left+n.pageXOffset}},getElementWidth:r,getPseudoElementHeight:i,getPseudoElementWidth:l,isTimeString:c,parseSingleTransition:p,parseTransition:e=>e?(e.match(/([^,()]|\([^)]*\))+/g)??[]).map((e=>e.trim())).filter((e=>e.length>0)).map(p):[],setCssProps:e,setElementHeight:d,setElementWidth:s,timeToMs:a});const f=function(t,n){for(let[r,o]of Object.entries(n))null!=o&&("innerHTML"===r?t.innerHTML=String(o):"css"===r&&"style"in t?e(t,o):r in t&&"style"!==r?t[r]=o:t.setAttribute(r,String(o)))};var h=Object.freeze({__proto__:null,closestUntil:function(e,t,n){if("closest"in e&&!n)return e.closest(t);const r=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(r.call(e,t))return e;if(n&&e===n)return null;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null},createElement:function(e,t,n){let r=document.createElement(e);if(t&&"object"==typeof t&&f(r,t),n)if(n instanceof Node)r.appendChild(n);else if(Array.isArray(n))for(let e of n)r.appendChild(e);return r},next:function(e,t){if(!e)return null;const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.nextElementSibling||e.nextSibling}while(null!==e&&1===e.nodeType);return null},prev:function(e,t){if(!e)return null;const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.previousElementSibling||e.previousSibling}while(null!==e&&1===e.nodeType);return null},setElementAttrs:f,unwrapChildren:function(e){let t=e.parentNode;for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}});let g=null;const m=()=>{try{document.createElement("div").querySelector(":scope > div"),g=!0}catch(e){g=!1}};var v=Object.freeze({__proto__:null,after:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(0!==n.length)if("after"in e)e.after(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t)}},append:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(0!==n.length)if("append"in e)e.append(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.appendChild(t)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.appendChild(t)}},before:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(0!==n.length)if("before"in e)e.before(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.parentNode.insertBefore(t,e)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.parentNode.insertBefore(t,e)}},closest:function(e,t){if("closest"in e)return e.closest(t);const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null},getRootNode:function(e){if(!e)return null;if("getRootNode"in e)return e.getRootNode();for(;e.parentNode;)e=e.parentNode;return e},prepend:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(0!==n.length)if("prepend"in e)e.prepend(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}},remove:function(e){e&&("remove"in e?e.remove():e.parentNode&&e.parentNode.removeChild(e))},scopedSelector:function(e,t){if(null===g&&m(),!0===g)return e.querySelector(t.replace(/((?:^|,)\s*)/g,"$1:scope "));{let n=e.id;const r="ID_"+Date.now();e.id=r,t=t.replace(/((?:^|,)\s*)/g,"$1#"+r);try{return e.querySelector(t)}finally{this.id=n}}},scopedSelectorAll:function(e,t){if(null===g&&m(),!0===g)return e.querySelectorAll(t.replace(/((?:^|,)\s*)/g,"$1:scope "));{let n=e.id;const r="ID_"+Date.now();e.id=r,t=t.replace(/((?:^|,)\s*)/g,"$1#"+r);try{return e.querySelectorAll(t)}finally{this.id=n}}},toggleClass:function(e,t,n){let r=e.classList;return void 0===n?r.contains(t)?(r.remove(t),!1):(r.add(t),!0):n?(r.add(t),!0):(r.remove(t),!1)}}),y=Object.freeze({__proto__:null,default:class{constructor(){this._events=[]}add(e,t,n,r){let o=t.split("."),l=o[0],i=o[1];e.addEventListener(l,n,r||!1);let s=!0===r||"object"==typeof r&&!0===r.capture;return this._events.push({el:e,name:l,namespace:i,handler:n,useCapture:s}),this}remove(e,t,n,r){let o=t?t.split("."):"",l=o[0],i=o[1],s=!0===r||"object"==typeof r&&!0===r.capture,d=[],a=[];if(e||l||i||n||void 0!==r)for(let t of this._events)e&&t.el!==e||l&&t.name!==l||i&&t.namespace!==i||n&&t.handler!==n||void 0!==r&&t.useCapture!==s?d.push(t):a.push(t);else a=this._events;this._events=d;for(let e of a)e.el.removeEventListener(e.name,e.handler,e.useCapture);return this}}}),b=Object.freeze({__proto__:null,bindTouchTap:function(e,t){let n=null,r=null;const o=t=>{if(null!==n)return;let o=t.changedTouches[0];n=o.identifier,r=o?{x:o.pageX,y:o.pageY}:{x:t.pageX,y:t.pageY},e.addEventListener("touchend",l),e.addEventListener("touchcancel",i)},l=e=>{if(null===n)return;let o=null;if(e.changedTouches){if(null!=n)for(let t of e.changedTouches)if(t.identifier===n){o=t;break}o||(o=e.changedTouches[0])}let l=o?{x:o.pageX,y:o.pageY}:{x:e.pageX,y:e.pageY},i=r;if(n=null,r=null,null!==t.distance){let e=t.distance||1;if(Math.hypot(Math.abs(l.x-i.x),Math.abs(l.y-i.y))>=e)return!1}t.handler&&t.handler(e)},i=()=>{n=null,r=null,e.removeEventListener("touchend",l),e.removeEventListener("touchcancel",i)};return e.addEventListener("touchstart",o),{unbind:()=>{e.removeEventListener("touchstart",o),e.removeEventListener("touchend",l),e.removeEventListener("touchcancel",i)}}}});let S;const C=()=>{const e=document.createElement("div");e.dir="rtl",Object.assign(e.style,{direction:"rtl",fontSize:"14px",width:"1px",height:"1px",position:"absolute",top:"-1000px",overflow:"scroll"}),e.textContent="A",document.body.appendChild(e);let t="reverse";return e.scrollLeft>0?t="default":(e.scrollLeft=1,0===Math.floor(e.scrollLeft)&&(t="negative")),e.parentNode.removeChild(e),t};function w(e,t,n){if(void 0===n&&(n="rtl"===getComputedStyle(e).direction),!0===n&&void 0===S&&(S=C()),!n)return t;switch(S){case"negative":return t-e.scrollWidth+e.clientWidth;case"reverse":return e.scrollWidth-t-e.clientWidth;default:return t}}function x(e,t){if(void 0===t&&(t="rtl"===getComputedStyle(e).direction),!0===t&&void 0===S&&(S=C()),!t)return e.scrollLeft;switch(S){case"negative":return e.scrollLeft+e.scrollWidth-e.clientWidth;case"reverse":return e.scrollWidth-e.scrollLeft-e.clientWidth;default:return e.scrollLeft}}function E(e,t,n){return void 0===n&&(n="rtl"===getComputedStyle(e).direction),w(e,n?e.scrollWidth-e.clientWidth-t:t,n)}var N=Object.freeze({__proto__:null,calculateNativeScrollLeftForHorz:E,calculateNativeScrollLeftForLeft:w,getScrollHorz:function(e,t){return void 0===t&&(t="rtl"===getComputedStyle(e).direction),t?e.scrollWidth-e.clientWidth-x(e,t):x(e,t)},getScrollLeft:x,setScrollHorz:function(e,t,n){e.scrollLeft=E(e,t,n)},setScrollLeft:function(e,t,n){e.scrollLeft=w(e,t,n)}});exports.Css=u,exports.Dom=h,exports.DomCompat=v,exports.DomEventsSink=y,exports.ScrollHelper=N,exports.Touches=b;
package/dist/lib.es6.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/dom-utils 1.0.10
2
+ * @danielgindi/dom-utils 1.0.11
3
3
  * git://github.com/danielgindi/dom-utils.git
4
4
  */
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/dom-utils 1.0.10
2
+ * @danielgindi/dom-utils 1.0.11
3
3
  * git://github.com/danielgindi/dom-utils.git
4
4
  */
5
5
  const e=function(e,t){for(let[n,r]of Object.entries(t))e.style[n]=null==r?"":String(r)},t=function(e,t,n,r,o){return(...l)=>{let i,s,d,a,c=l[0];if(e?(i=l[1],s=!!l[2],d=!!l[3],a=!!l[4]):(s=!!l[1],d=!!l[2],a=!!l[3]),c===window)return c.document.documentElement[`client${n}`];if(9===c.nodeType){const e=c.documentElement,t=c.body;return Math.max(t[`scroll${n}`],e[`scroll${n}`],t[`offset${n}`],e[`offset${n}`],e[`client${n}`])}{let l,p,u=!1,f=!1;if(!e&&"getBoundingClientRect"in c&&(l=c.getBoundingClientRect()[t],u=!0,f=!0),(void 0===l||a||u!==s||f!==d)&&(p=e?getComputedStyle(c,i):getComputedStyle(c)),void 0===l){let e=p[t];"auto"===e?(l=c[`client${n}`],u=!0):l=parseFloat(e),"border-box"===p.boxSizing&&(u=!0,f=!0)}if(s!==u){let e=parseFloat(p[`padding-${r}`]||0)+parseFloat(p[`padding-${o}`]||0);s?l+=e:l-=e}if(d!==f){let e=parseFloat(p[`border-${r}-width`]||0)+parseFloat(p[`border-${o}-width`]||0);d?l+=e:l-=e}return l<0&&(l=0),a&&(l+=parseFloat(p[`margin-${r}`]||0)+parseFloat(p[`margin-${o}`]||0)),l}}},n=(e,t,n,r)=>(t,o,l=!1,i=!1,s=!1)=>{if(t===window)return;if(9===t.nodeType)return;const d=getComputedStyle(t);let a=!1;if("border-box"===d.boxSizing&&(a=!0),l=!!l,i=!!i,(s=!!s)&&(o-=(parseFloat(d[`margin-${n}`])||0)+(parseFloat(d[`margin-${r}`])||0)),l!==a){let e=parseFloat(d[`padding-${n}`]||0)+parseFloat(d[`padding-${r}`]||0);l?o-=e:o+=e}if(i!==a){let e=(parseFloat(d[`border-${n}-width`])||0)+(parseFloat(d[`border-${r}-width`])||0);i?o-=e:o+=e}o<0&&(o=0),t.style[e]=o+"px"},r=t(!1,"width","Width","left","right"),o=t(!1,"height","Height","top","bottom"),l=t(!0,"width","Width","left","right"),i=t(!0,"height","Height","top","bottom"),s=n("width",0,"left","right"),d=n("height",0,"top","bottom"),a=e=>{if(!e)return;let t=e.endsWith("ms");return parseFloat(e)*(t?1:1e3)},c=e=>/^-?(0?\.)?\d+m?s$/.test(e),p=e=>{let t=e.split(/\s+/),n=t[0],r=t[1],o=t[2],l=t[3];return c(o)?{delay:a(o),duration:a(r),name:n}:{delay:a(l),duration:a(r),name:n,timingFunction:o}};var u=Object.freeze({__proto__:null,anchoredPosition:function(e,t,n,o,l){let i,s,d,a;if(o||(o={width:r(e,!0,!0),height:r(e,!0,!0)}),"start"!==t&&"end"!==t||(null==l&&(l="rtl"===getComputedStyle(e).direction),t="start"===t?l?"right":"left":l?"left":"right"),"right"===t)i=o.width,d=0;else if("center"===t)i=o.width/2,d=i;else if("left"===t)i=0,d=o.width;else if(t&&"string"==typeof t&&"%"===t.charAt(t.length-1)){let n=(parseFloat(t)||0)/100;i=o.width*n,d=o.width*-n,null==l&&(l="rtl"===getComputedStyle(e).direction),l&&(i=o.width-i,d=o.width-i)}else i=parseFloat(t)||0,d=-i;if("bottom"===n)s=o.height,a=0;else if("center"===n)s=o.height/2,a=s;else if("top"===n)s=0,a=o.height;else if(n&&"string"==typeof n&&"%"===n.charAt(n.length-1)){let e=(parseFloat(n)||0)/100;s=o.height*e,a=o.height*-e}else s=parseFloat(n)||0,a=-s;return{left:i,top:s,right:d,bottom:a,xSpec:t,ySpec:n}},getCssProps:function(e,t){const n=getComputedStyle(e);let r={};for(let o of t){let t=n[o];("width"===o||"height"===o)&&"auto"===t&&e instanceof HTMLElement&&(t=e["offset"+o.substr(0,1).toUpperCase()+o.substr(1)],"border-box"!==n.boxSizing&&("width"===o?(t-=parseFloat(n.paddingLeft||0),t-=parseFloat(n.paddingRight||0),t-=parseFloat(n.borderLeftWidth||0),t-=parseFloat(n.borderRightWidth||0)):(t-=parseFloat(n.paddingTop||0),t-=parseFloat(n.paddingBottom||0),t-=parseFloat(n.borderTopWidth||0),t-=parseFloat(n.borderBottomWidth||0)),t<0&&(t=0)),t+="px"),r[o]=t}return r},getElementHeight:o,getElementOffset:e=>{if(!e.getClientRects().length)return{top:0,left:0};let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView;return{top:t.top+n.pageYOffset,left:t.left+n.pageXOffset}},getElementWidth:r,getPseudoElementHeight:i,getPseudoElementWidth:l,isTimeString:c,parseSingleTransition:p,parseTransition:e=>e?(e.match(/([^,()]|\([^)]*\))+/g)??[]).map((e=>e.trim())).filter((e=>e.length>0)).map(p):[],setCssProps:e,setElementHeight:d,setElementWidth:s,timeToMs:a});const f=function(t,n){for(let[r,o]of Object.entries(n))null!=o&&("innerHTML"===r?t.innerHTML=String(o):"css"===r&&"style"in t?e(t,o):r in t&&"style"!==r?t[r]=o:t.setAttribute(r,String(o)))};var h=Object.freeze({__proto__:null,closestUntil:function(e,t,n){if("closest"in e&&!n)return e.closest(t);const r=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(r.call(e,t))return e;if(n&&e===n)return null;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null},createElement:function(e,t,n){let r=document.createElement(e);if(t&&"object"==typeof t&&f(r,t),n)if(n instanceof Node)r.appendChild(n);else if(Array.isArray(n))for(let e of n)r.appendChild(e);return r},next:function(e,t){if(!e)return null;const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.nextElementSibling||e.nextSibling}while(null!==e&&1===e.nodeType);return null},prev:function(e,t){if(!e)return null;const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.previousElementSibling||e.previousSibling}while(null!==e&&1===e.nodeType);return null},setElementAttrs:f,unwrapChildren:function(e){let t=e.parentNode;for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}});let g=null;const m=()=>{try{document.createElement("div").querySelector(":scope > div"),g=!0}catch(e){g=!1}};var y=Object.freeze({__proto__:null,after:function(e,...t){if(0!==t.length)if("after"in e)e.after(...t);else if(1===t.length){let n=t[0];n=n instanceof Node?n:document.createTextNode(String(n)),e.nextSibling?e.parentNode.insertBefore(n,e.nextSibling):e.parentNode.appendChild(n)}else{let n=document.createDocumentFragment();for(const e of t){const t=e instanceof Node;n.appendChild(t?e:document.createTextNode(String(e)))}e.nextSibling?e.parentNode.insertBefore(n,e.nextSibling):e.parentNode.appendChild(n)}},append:function(e,...t){if(0!==t.length)if("append"in e)e.append(...t);else if(1===t.length){let n=t[0];n=n instanceof Node?n:document.createTextNode(String(n)),e.appendChild(n)}else{let n=document.createDocumentFragment();for(const e of t){const t=e instanceof Node;n.appendChild(t?e:document.createTextNode(String(e)))}e.appendChild(n)}},before:function(e,...t){if(0!==t.length)if("before"in e)e.before(...t);else if(1===t.length){let n=t[0];n=n instanceof Node?n:document.createTextNode(String(n)),e.parentNode.insertBefore(n,e)}else{let n=document.createDocumentFragment();for(const e of t){const t=e instanceof Node;n.appendChild(t?e:document.createTextNode(String(e)))}e.parentNode.insertBefore(n,e)}},closest:function(e,t){if("closest"in e)return e.closest(t);const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null},getRootNode:function(e){if(!e)return null;if("getRootNode"in e)return e.getRootNode();for(;e.parentNode;)e=e.parentNode;return e},prepend:function(e,...t){if(0!==t.length)if("prepend"in e)e.prepend(...t);else if(1===t.length){let n=t[0];n=n instanceof Node?n:document.createTextNode(String(n)),e.firstChild?e.insertBefore(n,e.firstChild):e.appendChild(n)}else{let n=document.createDocumentFragment();for(const e of t){const t=e instanceof Node;n.appendChild(t?e:document.createTextNode(String(e)))}e.firstChild?e.insertBefore(n,e.firstChild):e.appendChild(n)}},remove:function(e){e&&("remove"in e?e.remove():e.parentNode&&e.parentNode.removeChild(e))},scopedSelector:function(e,t){if(null===g&&m(),!0===g)return e.querySelector(t.replace(/((?:^|,)\s*)/g,"$1:scope "));{let n=e.id;const r="ID_"+Date.now();e.id=r,t=t.replace(/((?:^|,)\s*)/g,"$1#"+r);try{return e.querySelector(t)}finally{this.id=n}}},scopedSelectorAll:function(e,t){if(null===g&&m(),!0===g)return e.querySelectorAll(t.replace(/((?:^|,)\s*)/g,"$1:scope "));{let n=e.id;const r="ID_"+Date.now();e.id=r,t=t.replace(/((?:^|,)\s*)/g,"$1#"+r);try{return e.querySelectorAll(t)}finally{this.id=n}}},toggleClass:function(e,t,n){let r=e.classList;return void 0===n?r.contains(t)?(r.remove(t),!1):(r.add(t),!0):n?(r.add(t),!0):(r.remove(t),!1)}}),v=Object.freeze({__proto__:null,default:class{constructor(){this._events=[]}add(e,t,n,r){let o=t.split("."),l=o[0],i=o[1];e.addEventListener(l,n,r||!1);let s=!0===r||"object"==typeof r&&!0===r.capture;return this._events.push({el:e,name:l,namespace:i,handler:n,useCapture:s}),this}remove(e,t,n,r){let o=t?t.split("."):"",l=o[0],i=o[1],s=!0===r||"object"==typeof r&&!0===r.capture,d=[],a=[];if(e||l||i||n||void 0!==r)for(let t of this._events)e&&t.el!==e||l&&t.name!==l||i&&t.namespace!==i||n&&t.handler!==n||void 0!==r&&t.useCapture!==s?d.push(t):a.push(t);else a=this._events;this._events=d;for(let e of a)e.el.removeEventListener(e.name,e.handler,e.useCapture);return this}}}),b=Object.freeze({__proto__:null,bindTouchTap:function(e,t){let n=null,r=null;const o=t=>{if(null!==n)return;let o=t.changedTouches[0];n=o.identifier,r=o?{x:o.pageX,y:o.pageY}:{x:t.pageX,y:t.pageY},e.addEventListener("touchend",l),e.addEventListener("touchcancel",i)},l=e=>{if(null===n)return;let o=null;if(e.changedTouches){if(null!=n)for(let t of e.changedTouches)if(t.identifier===n){o=t;break}o||(o=e.changedTouches[0])}let l=o?{x:o.pageX,y:o.pageY}:{x:e.pageX,y:e.pageY},i=r;if(n=null,r=null,null!==t.distance){let e=t.distance||1;if(Math.hypot(Math.abs(l.x-i.x),Math.abs(l.y-i.y))>=e)return!1}t.handler&&t.handler(e)},i=()=>{n=null,r=null,e.removeEventListener("touchend",l),e.removeEventListener("touchcancel",i)};return e.addEventListener("touchstart",o),{unbind:()=>{e.removeEventListener("touchstart",o),e.removeEventListener("touchend",l),e.removeEventListener("touchcancel",i)}}}});let S;const C=()=>{const e=document.createElement("div");e.dir="rtl",Object.assign(e.style,{direction:"rtl",fontSize:"14px",width:"1px",height:"1px",position:"absolute",top:"-1000px",overflow:"scroll"}),e.textContent="A",document.body.appendChild(e);let t="reverse";return e.scrollLeft>0?t="default":(e.scrollLeft=1,0===Math.floor(e.scrollLeft)&&(t="negative")),e.parentNode.removeChild(e),t};function E(e,t,n){if(void 0===n&&(n="rtl"===getComputedStyle(e).direction),!0===n&&void 0===S&&(S=C()),!n)return t;switch(S){case"negative":return t-e.scrollWidth+e.clientWidth;case"reverse":return e.scrollWidth-t-e.clientWidth;default:return t}}function w(e,t){if(void 0===t&&(t="rtl"===getComputedStyle(e).direction),!0===t&&void 0===S&&(S=C()),!t)return e.scrollLeft;switch(S){case"negative":return e.scrollLeft+e.scrollWidth-e.clientWidth;case"reverse":return e.scrollWidth-e.scrollLeft-e.clientWidth;default:return e.scrollLeft}}function x(e,t,n){return void 0===n&&(n="rtl"===getComputedStyle(e).direction),E(e,n?e.scrollWidth-e.clientWidth-t:t,n)}var N=Object.freeze({__proto__:null,calculateNativeScrollLeftForHorz:x,calculateNativeScrollLeftForLeft:E,getScrollHorz:function(e,t){return void 0===t&&(t="rtl"===getComputedStyle(e).direction),t?e.scrollWidth-e.clientWidth-w(e,t):w(e,t)},getScrollLeft:w,setScrollHorz:function(e,t,n){e.scrollLeft=x(e,t,n)},setScrollLeft:function(e,t,n){e.scrollLeft=E(e,t,n)}});export{u as Css,h as Dom,y as DomCompat,v as DomEventsSink,N as ScrollHelper,b as Touches};
package/dist/lib.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/dom-utils 1.0.10
2
+ * @danielgindi/dom-utils 1.0.11
3
3
  * git://github.com/danielgindi/dom-utils.git
4
4
  */
5
5
  (function (global, factory) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/dom-utils 1.0.10
2
+ * @danielgindi/dom-utils 1.0.11
3
3
  * git://github.com/danielgindi/dom-utils.git
4
4
  */
5
5
  var e,t;e=this,t=function(e){"use strict";const t=function(e,t){for(let[n,o]of Object.entries(t))e.style[n]=null==o?"":String(o)},n=function(e,t,n,o,r){return function(){let l,i,d,s,a=arguments.length<=0?void 0:arguments[0];if(e?(l=arguments.length<=1?void 0:arguments[1],i=!!(arguments.length<=2?void 0:arguments[2]),d=!!(arguments.length<=3?void 0:arguments[3]),s=!!(arguments.length<=4?void 0:arguments[4])):(i=!!(arguments.length<=1?void 0:arguments[1]),d=!!(arguments.length<=2?void 0:arguments[2]),s=!!(arguments.length<=3?void 0:arguments[3])),a===window)return a.document.documentElement[`client${n}`];if(9===a.nodeType){const e=a.documentElement,t=a.body;return Math.max(t[`scroll${n}`],e[`scroll${n}`],t[`offset${n}`],e[`offset${n}`],e[`client${n}`])}{let c,f,p=!1,u=!1;if(!e&&"getBoundingClientRect"in a&&(c=a.getBoundingClientRect()[t],p=!0,u=!0),(void 0===c||s||p!==i||u!==d)&&(f=e?getComputedStyle(a,l):getComputedStyle(a)),void 0===c){let e=f[t];"auto"===e?(c=a[`client${n}`],p=!0):c=parseFloat(e),"border-box"===f.boxSizing&&(p=!0,u=!0)}if(i!==p){let e=parseFloat(f[`padding-${o}`]||0)+parseFloat(f[`padding-${r}`]||0);i?c+=e:c-=e}if(d!==u){let e=parseFloat(f[`border-${o}-width`]||0)+parseFloat(f[`border-${r}-width`]||0);d?c+=e:c-=e}return c<0&&(c=0),s&&(c+=parseFloat(f[`margin-${o}`]||0)+parseFloat(f[`margin-${r}`]||0)),c}}},o=(e,t,n,o)=>function(t,r){let l=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],d=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(t===window)return;if(9===t.nodeType)return;const s=getComputedStyle(t);let a=!1;if("border-box"===s.boxSizing&&(a=!0),l=!!l,i=!!i,d=!!d,d&&(r-=(parseFloat(s[`margin-${n}`])||0)+(parseFloat(s[`margin-${o}`])||0)),l!==a){let e=parseFloat(s[`padding-${n}`]||0)+parseFloat(s[`padding-${o}`]||0);l?r-=e:r+=e}if(i!==a){let e=(parseFloat(s[`border-${n}-width`])||0)+(parseFloat(s[`border-${o}-width`])||0);i?r-=e:r+=e}r<0&&(r=0),t.style[e]=r+"px"},r=n(!1,"width","Width","left","right"),l=n(!1,"height","Height","top","bottom"),i=n(!0,"width","Width","left","right"),d=n(!0,"height","Height","top","bottom"),s=o("width",0,"left","right"),a=o("height",0,"top","bottom"),c=e=>{if(!e)return;let t=e.endsWith("ms");return parseFloat(e)*(t?1:1e3)},f=e=>/^-?(0?\.)?\d+m?s$/.test(e),p=e=>{let t=e.split(/\s+/),n=t[0],o=t[1],r=t[2],l=t[3];return f(r)?{delay:c(r),duration:c(o),name:n}:{delay:c(l),duration:c(o),name:n,timingFunction:r}};var u=Object.freeze({__proto__:null,anchoredPosition:function(e,t,n,o,l){let i,d,s,a;if(o||(o={width:r(e,!0,!0),height:r(e,!0,!0)}),"start"!==t&&"end"!==t||(null==l&&(l="rtl"===getComputedStyle(e).direction),t="start"===t?l?"right":"left":l?"left":"right"),"right"===t)i=o.width,s=0;else if("center"===t)i=o.width/2,s=i;else if("left"===t)i=0,s=o.width;else if(t&&"string"==typeof t&&"%"===t.charAt(t.length-1)){let n=(parseFloat(t)||0)/100;i=o.width*n,s=o.width*-n,null==l&&(l="rtl"===getComputedStyle(e).direction),l&&(i=o.width-i,s=o.width-i)}else i=parseFloat(t)||0,s=-i;if("bottom"===n)d=o.height,a=0;else if("center"===n)d=o.height/2,a=d;else if("top"===n)d=0,a=o.height;else if(n&&"string"==typeof n&&"%"===n.charAt(n.length-1)){let e=(parseFloat(n)||0)/100;d=o.height*e,a=o.height*-e}else d=parseFloat(n)||0,a=-d;return{left:i,top:d,right:s,bottom:a,xSpec:t,ySpec:n}},getCssProps:function(e,t){const n=getComputedStyle(e);let o={};for(let r of t){let t=n[r];("width"===r||"height"===r)&&"auto"===t&&e instanceof HTMLElement&&(t=e["offset"+r.substr(0,1).toUpperCase()+r.substr(1)],"border-box"!==n.boxSizing&&("width"===r?(t-=parseFloat(n.paddingLeft||0),t-=parseFloat(n.paddingRight||0),t-=parseFloat(n.borderLeftWidth||0),t-=parseFloat(n.borderRightWidth||0)):(t-=parseFloat(n.paddingTop||0),t-=parseFloat(n.paddingBottom||0),t-=parseFloat(n.borderTopWidth||0),t-=parseFloat(n.borderBottomWidth||0)),t<0&&(t=0)),t+="px"),o[r]=t}return o},getElementHeight:l,getElementOffset:e=>{if(!e.getClientRects().length)return{top:0,left:0};let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView;return{top:t.top+n.pageYOffset,left:t.left+n.pageXOffset}},getElementWidth:r,getPseudoElementHeight:d,getPseudoElementWidth:i,isTimeString:f,parseSingleTransition:p,parseTransition:e=>e?(e.match(/([^,()]|\([^)]*\))+/g)??[]).map((e=>e.trim())).filter((e=>e.length>0)).map(p):[],setCssProps:t,setElementHeight:a,setElementWidth:s,timeToMs:c});const h=function(e,n){for(let[o,r]of Object.entries(n))null!=r&&("innerHTML"===o?e.innerHTML=String(r):"css"===o&&"style"in e?t(e,r):o in e&&"style"!==o?e[o]=r:e.setAttribute(o,String(r)))};var g=Object.freeze({__proto__:null,closestUntil:function(e,t,n){if("closest"in e&&!n)return e.closest(t);const o=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(o.call(e,t))return e;if(n&&e===n)return null;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null},createElement:function(e,t,n){let o=document.createElement(e);if(t&&"object"==typeof t&&h(o,t),n)if(n instanceof Node)o.appendChild(n);else if(Array.isArray(n))for(let e of n)o.appendChild(e);return o},next:function(e,t){if(!e)return null;const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.nextElementSibling||e.nextSibling}while(null!==e&&1===e.nodeType);return null},prev:function(e,t){if(!e)return null;const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.previousElementSibling||e.previousSibling}while(null!==e&&1===e.nodeType);return null},setElementAttrs:h,unwrapChildren:function(e){let t=e.parentNode;for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}});let m=null;const v=()=>{try{document.createElement("div").querySelector(":scope > div"),m=!0}catch(e){m=!1}};var y=Object.freeze({__proto__:null,after:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(0!==n.length)if("after"in e)e.after(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t)}},append:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(0!==n.length)if("append"in e)e.append(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.appendChild(t)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.appendChild(t)}},before:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(0!==n.length)if("before"in e)e.before(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.parentNode.insertBefore(t,e)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.parentNode.insertBefore(t,e)}},closest:function(e,t){if("closest"in e)return e.closest(t);const n=Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector;do{if(n.call(e,t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null},getRootNode:function(e){if(!e)return null;if("getRootNode"in e)return e.getRootNode();for(;e.parentNode;)e=e.parentNode;return e},prepend:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(0!==n.length)if("prepend"in e)e.prepend(...n);else if(1===n.length){let t=n[0];t=t instanceof Node?t:document.createTextNode(String(t)),e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}else{let t=document.createDocumentFragment();for(const e of n){const n=e instanceof Node;t.appendChild(n?e:document.createTextNode(String(e)))}e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}},remove:function(e){e&&("remove"in e?e.remove():e.parentNode&&e.parentNode.removeChild(e))},scopedSelector:function(e,t){if(null===m&&v(),!0===m)return e.querySelector(t.replace(/((?:^|,)\s*)/g,"$1:scope "));{let n=e.id;const o="ID_"+Date.now();e.id=o,t=t.replace(/((?:^|,)\s*)/g,"$1#"+o);try{return e.querySelector(t)}finally{this.id=n}}},scopedSelectorAll:function(e,t){if(null===m&&v(),!0===m)return e.querySelectorAll(t.replace(/((?:^|,)\s*)/g,"$1:scope "));{let n=e.id;const o="ID_"+Date.now();e.id=o,t=t.replace(/((?:^|,)\s*)/g,"$1#"+o);try{return e.querySelectorAll(t)}finally{this.id=n}}},toggleClass:function(e,t,n){let o=e.classList;return void 0===n?o.contains(t)?(o.remove(t),!1):(o.add(t),!0):n?(o.add(t),!0):(o.remove(t),!1)}}),b=Object.freeze({__proto__:null,default:class{constructor(){this._events=[]}add(e,t,n,o){let r=t.split("."),l=r[0],i=r[1];e.addEventListener(l,n,o||!1);let d=!0===o||"object"==typeof o&&!0===o.capture;return this._events.push({el:e,name:l,namespace:i,handler:n,useCapture:d}),this}remove(e,t,n,o){let r=t?t.split("."):"",l=r[0],i=r[1],d=!0===o||"object"==typeof o&&!0===o.capture,s=[],a=[];if(e||l||i||n||void 0!==o)for(let t of this._events)e&&t.el!==e||l&&t.name!==l||i&&t.namespace!==i||n&&t.handler!==n||void 0!==o&&t.useCapture!==d?s.push(t):a.push(t);else a=this._events;this._events=s;for(let e of a)e.el.removeEventListener(e.name,e.handler,e.useCapture);return this}}}),S=Object.freeze({__proto__:null,bindTouchTap:function(e,t){let n=null,o=null;const r=t=>{if(null!==n)return;let r=t.changedTouches[0];n=r.identifier,o=r?{x:r.pageX,y:r.pageY}:{x:t.pageX,y:t.pageY},e.addEventListener("touchend",l),e.addEventListener("touchcancel",i)},l=e=>{if(null===n)return;let r=null;if(e.changedTouches){if(null!=n)for(let t of e.changedTouches)if(t.identifier===n){r=t;break}r||(r=e.changedTouches[0])}let l=r?{x:r.pageX,y:r.pageY}:{x:e.pageX,y:e.pageY},i=o;if(n=null,o=null,null!==t.distance){let e=t.distance||1;if(Math.hypot(Math.abs(l.x-i.x),Math.abs(l.y-i.y))>=e)return!1}t.handler&&t.handler(e)},i=()=>{n=null,o=null,e.removeEventListener("touchend",l),e.removeEventListener("touchcancel",i)};return e.addEventListener("touchstart",r),{unbind:()=>{e.removeEventListener("touchstart",r),e.removeEventListener("touchend",l),e.removeEventListener("touchcancel",i)}}}});let C;const w=()=>{const e=document.createElement("div");e.dir="rtl",Object.assign(e.style,{direction:"rtl",fontSize:"14px",width:"1px",height:"1px",position:"absolute",top:"-1000px",overflow:"scroll"}),e.textContent="A",document.body.appendChild(e);let t="reverse";return e.scrollLeft>0?t="default":(e.scrollLeft=1,0===Math.floor(e.scrollLeft)&&(t="negative")),e.parentNode.removeChild(e),t};function E(e,t,n){if(void 0===n&&(n="rtl"===getComputedStyle(e).direction),!0===n&&void 0===C&&(C=w()),!n)return t;switch(C){case"negative":return t-e.scrollWidth+e.clientWidth;case"reverse":return e.scrollWidth-t-e.clientWidth;default:return t}}function x(e,t){if(void 0===t&&(t="rtl"===getComputedStyle(e).direction),!0===t&&void 0===C&&(C=w()),!t)return e.scrollLeft;switch(C){case"negative":return e.scrollLeft+e.scrollWidth-e.clientWidth;case"reverse":return e.scrollWidth-e.scrollLeft-e.clientWidth;default:return e.scrollLeft}}function N(e,t,n){return void 0===n&&(n="rtl"===getComputedStyle(e).direction),E(e,n?e.scrollWidth-e.clientWidth-t:t,n)}var F=Object.freeze({__proto__:null,calculateNativeScrollLeftForHorz:N,calculateNativeScrollLeftForLeft:E,getScrollHorz:function(e,t){return void 0===t&&(t="rtl"===getComputedStyle(e).direction),t?e.scrollWidth-e.clientWidth-x(e,t):x(e,t)},getScrollLeft:x,setScrollHorz:function(e,t,n){e.scrollLeft=N(e,t,n)},setScrollLeft:function(e,t,n){e.scrollLeft=E(e,t,n)}});e.Css=u,e.Dom=g,e.DomCompat=y,e.DomEventsSink=b,e.ScrollHelper=F,e.Touches=S},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).domutils={});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/dom-utils",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",
@@ -18,7 +18,6 @@
18
18
  "build": "npm run lint && node ./scripts/build.js",
19
19
  "lint": "eslint -f codeframe ./",
20
20
  "lint-fix": "eslint -f codeframe --fix ./",
21
- "postinstall": "husky install",
22
21
  "prepublishOnly": "npm run build",
23
22
  "prepare": "husky"
24
23
  },