{"version":3,"sources":["../../src/is.ts","../../src/element/util.ts"],"sourcesContent":["export function isStrictMode () : boolean\n{\n\treturn (function(this: unknown) { return !this; })();\n}\n\nexport function isEmpty (val : []|string|object) : boolean\n{\n\tif (val instanceof Object) \t{return isObjectEmpty(val);}\n\telse \t\t\t\t\t\t{return isArrayStringEmpty(val);}\n}\n\nexport function isArrayStringEmpty (arr : []|string) : boolean\n{\n\treturn arr.length === 0;\n}\n\nexport function isObjectEmpty (obj : object) : boolean\n{\n\treturn obj\n\t\t&& Object.keys(obj).length === 0\n\t\t&& Object.getPrototypeOf(obj) === Object.prototype;\n}\n\nexport function isIterable (val : unknown) : boolean\n{\n  return Symbol.iterator in Object(val);\n}\n\nexport function isString (val : unknown) : boolean\n{\n  return (typeof val === 'string' || val instanceof String);\n}\n\nexport function isTouchDevice () : boolean\n{\n\treturn window.matchMedia(\"(pointer: coarse)\").matches;\n}","import { isIterable, isString } from '../is';\n\n\n/**\n * https://stackoverflow.com/a/442474/10977967 \n * Doesn't work when scrollTop was altered \n */\nexport function getOffset (el : HTMLElement) : {top: number, left: number}\n{\n    var _x : number = 0;\n    var _y : number = 0;\n\n    while( !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) \n\t{\n        _x += el.offsetLeft - el.scrollLeft;\n        _y += el.offsetTop - el.scrollTop;\n        \n\t\tlet el_ = el.offsetParent;\n\t\tif (!el_) {break;} else {el = el_ as HTMLElement;}\n    }\n\n    return {top: _y, left: _x};\n}\n\n/**\n * Gets the computed CSS property value of the given element.\n */\nexport function getCssStyle(el: HTMLElement, prop: string) : string\n{\n    return window.getComputedStyle(el, null).getPropertyValue(prop);\n}\n\n/**\n * Gets the CSS font descriptor (e.g. \"bold 14px verdana\") of the given element.\n */\nexport function getCssFont(el: HTMLElement = document.body): string\n{\n  const fontWeight = getCssStyle(el, 'font-weight') || 'normal';\n  const fontSize = getCssStyle(el, 'font-size') || '16px';\n  const fontFamily = getCssStyle(el, 'font-family') || 'Times New Roman';\n  \n  return `${fontWeight} ${fontSize} ${fontFamily}`;\n}\n\nexport function getPositionAmongSiblings(el : HTMLElement) : number\n{\n\tvar pos : number = 0;\n\twhile( (el = el.previousSibling as HTMLElement) != null ) {pos++;}\t\t\n\treturn pos;\n}\n\nexport function elCreate(tagName : string, attrs : object = {}, innerHTML : string = '') : HTMLElement\n{\n\tvar el = document.createElement(tagName);\n\n\tfor (let [name, value] of Object.entries(attrs)) \n\t{\n\t\tel.setAttribute(name, value);\n\t}\n\n\tel.innerHTML = innerHTML;\n\t\n\treturn el;\n}\n\nexport function isOverflown(el : HTMLElement, heightTolerance : number = 0, widthTolerance : number = 0) : boolean\n{\t\n\tif (el === document.body)\n\t{\n\t\treturn window.innerHeight < el.scrollHeight;\n\t}\n\telse\n\t{\n\t\treturn (el.scrollHeight > (el.clientHeight + heightTolerance) || el.scrollWidth > (el.clientWidth + widthTolerance));\n\t}\n}\n\nexport function isScrollableY(el : HTMLElement) : boolean\n{\n    const overflowYStyle = window.getComputedStyle(el).overflowY;\n    const isOverflowHidden = overflowYStyle.indexOf('hidden') !== -1;\n\n    return el.scrollHeight > el.clientHeight && !isOverflowHidden;\n}\n\nexport function isScrollableX(el : HTMLElement) : boolean\n{\n    const overflowXStyle = window.getComputedStyle(el).overflowX;\n    const isOverflowHidden = overflowXStyle.indexOf('hidden') !== -1;\n\n    return el.scrollWidth > el.clientWidth && !isOverflowHidden;\n}\n\nexport function isScrollableXY(el : HTMLElement) : boolean\n{\n    return isScrollableY(el) && isScrollableX(el);\n}\n\nexport function htmlToElements(html : string, elNodesOnly : boolean = true) : HTMLCollection|NodeList\n{\n    var template = document.createElement('template');\n    template.innerHTML = html;\n\n\tif (elNodesOnly) {return template.content.children;}\n\telse \t\t     {return template.content.childNodes;}\n}\n\n/**\n * @param nodes - HTML strings or node/s\n * @param referenceEl - querySelector or HTML element\n */\nexport function insertNodes (nodes : string|Node[]|Node, referenceEl : HTMLElement|string, after : boolean = false) : void\n{\n\tlet refEl : HTMLElement|null =  null;\n\tif (isString(referenceEl)) {refEl = document.querySelector(referenceEl as string);}\n\t\n\tlet nodesArr : Node[] = [];\n\tif (isString(nodes)) \n\t{\n\t\tlet elemsNodeList : NodeList = htmlToElements(nodes as string, false) as NodeList;\t\t\n\t\tnodesArr = Array.from(elemsNodeList);\n\t}\n\telse if ( !isIterable(nodes) ) {nodesArr = [nodes as Node];}\n\t\n\tif (after) \t{refEl = refEl?.nextSibling as HTMLElement;}\n\t\n\tnodesArr.forEach( (n : Node) =>\n\t{\n\t\trefEl?.parentNode?.insertBefore(n, refEl);\n\t});\n}\n\nexport function switchElements(el1 : HTMLElement, el2 : HTMLElement) : void\n{\n    const afterNode2 = el2.nextElementSibling;\n    const parent = el2.parentNode;\n    el1.replaceWith(el2);\n    parent?.insertBefore(el1, afterNode2);\n}"],"mappings":";AAuBO,SAAS,WAAY,KAC5B;AACE,SAAO,OAAO,YAAY,OAAO,GAAG;AACtC;AAEO,SAAS,SAAU,KAC1B;AACE,SAAQ,OAAO,QAAQ,YAAY,eAAe;AACpD;;;ACxBO,SAAS,UAAW,IAC3B;AACI,MAAI,KAAc;AAClB,MAAI,KAAc;AAElB,SAAO,CAAC,MAAO,GAAG,UAAW,KAAK,CAAC,MAAO,GAAG,SAAU,GAC1D;AACO,UAAM,GAAG,aAAa,GAAG;AACzB,UAAM,GAAG,YAAY,GAAG;AAE9B,QAAI,MAAM,GAAG;AACb,QAAI,CAAC,KAAK;AAAC;AAAA,IAAM,OAAO;AAAC,WAAK;AAAA,IAAmB;AAAA,EAC/C;AAEA,SAAO,EAAC,KAAK,IAAI,MAAM,GAAE;AAC7B;AAKO,SAAS,YAAY,IAAiB,MAC7C;AACI,SAAO,OAAO,iBAAiB,IAAI,IAAI,EAAE,iBAAiB,IAAI;AAClE;AAKO,SAAS,WAAW,KAAkB,SAAS,MACtD;AACE,QAAM,aAAa,YAAY,IAAI,aAAa,KAAK;AACrD,QAAM,WAAW,YAAY,IAAI,WAAW,KAAK;AACjD,QAAM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