nodality
Version:
A lightweight library for declarative UI elements.
2 lines • 24.9 kB
JavaScript
/*! For license information please see sideNavBar.esm.js.LICENSE.txt */
function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,s,i,a=[],l=!0,c=!1;try{if(s=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=s.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}(e,t)||n(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=n(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0,s=function(){};return{s,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw i}}}}function n(e,t){if(e){if("string"==typeof e)return o(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,t):void 0}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,i(n.key),n)}}function i(t){var r=function(t){if("object"!=e(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==e(r)?r:r+""}var a=function(){return e=function e(){var t,r,n,o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t=this,n=function(e){if(console.log("LOBJO IS"),console.log(e),e.transform||e.op&&e.op.transform){var t=e.transform;e.transform||(t=e.op.transform),t.duration||(t.duration="3s-ease-in-out"),o.setDefault=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0px";return 0===e.length?t+" ":e};var r=function(){var r="",n="",s="",i="",a="",l="",c="",u="",f="";if(0!==t.values.length){t.values.forEach((function(e){e.startsWith("tx:")&&(r=e.replace("tx:","")),e.startsWith("ty:")&&(n=e.replace("ty:","")),e.startsWith("tz:")?s=e.replace("tz:",""):e.startsWith("scale(")?i=e:e.startsWith("skew(")?a=e:e.startsWith("rotate(")?l=function(e){var t=e.match(/rotate\(([^)]+)\)/);if(!t)return e;var r=t[1].split(",").map((function(e){return e.trim()}));return 1===r.length?"rotate(".concat(r[0],")"):2===r.length?"rotateX(".concat(r[0],") rotateY(").concat(r[1],")"):3===r.length?"rotateX(".concat(r[0],") rotateY(").concat(r[1],") rotate(").concat(r[2],")"):e}(e):e.startsWith("perspective(")?c=e:e.startsWith("matrix(")?u=e:e.startsWith("opacity:")&&(f=e.replace("opacity:",""))})),r=o.setDefault(r),n=o.setDefault(n),s=o.setDefault(s);var p="";if("0px"!=n&&"0px"!=r&&"0px"!=s?p+="translate3d(".concat(r,", ").concat(n,", ").concat(s,")"):"0px"==n&&"0px"==r||(p+="translate(".concat(r,", ").concat(n,")")),i&&(p+=" ".concat(i)),l&&(p+=" ".concat(l)),a&&(p+=" ".concat(a)),c&&(p+=" ".concat(c)),u&&(p+=" ".concat(u)),p){if(e.op.transform.duration){var d=e.op.transform.duration.replace(/^(\d+)(s)-/,(function(e,t,r){return t/2+r+" "})),y="transform ".concat(d,", opacity ").concat(d);o.res.style.transition=y}else o.res.style.transition="transform 3s ease-in-out, opacity 3s ease-in-out";e.op.transform.static&&(o.res.style.transition=""),(o.blastTarget||o.res).style.transform=p,o.res.style.opacity=f}else alert("OPE")}};t.on?o.res.addEventListener(t.on,(function(){t.delay?setTimeout((function(){r()}),t.delay):r()})):window.addEventListener("load",(function(){t.delay?setTimeout((function(){r()}),t.delay):r()}));var n=function(){var e="";t.values.forEach((function(t){t.startsWith("tx:")?e+="translateX(0) ":t.startsWith("ty:")?e+="translateY(0) ":t.startsWith("tz:")?e+="translateZ(0) ":t.startsWith("scale(")?e+="scale(1) ":t.startsWith("skew(")?e+="skew(0, 0) ":t.startsWith("rotate(")?e+="rotate(0) ":t.startsWith("perspective(")?e+="perspective(0) ":t.startsWith("matrix(")&&(e+="matrix(1, 0, 0, 1, 0, 0) "),o.res.style.opacity="1"})),e&&(o.res.style.transform=e.trim())};if(t.on)o.res.addEventListener("mouseout",(function(){t.keep||n()}));else{var s=1e3*parseFloat(t.duration),i=t.closeAfter?t.closeAfter:0;setTimeout((function(){t.keep||n()}),s/2+i)}t.hardCSS&&(o.res.style.transform=t.hardCSS)}else alert("THIS FIRE WITH GRADIENT (invalid block"),console.log("INVALID BLOCKA"),console.log(e)},(r=i(r="reactOnTransform"))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n,this.state={isExpanded:!1,isMovedUp:!1,isMovedDown:!1}},n=[{key:"keySet",value:function(e){return this.temporaryVal=1,this.res.style[e.key]=e.value,this}},{key:"onScroll",value:function(e){var t=this;"opacity"===e.value?this.res.style.opacity=e.valMin:"scale"===e.value&&(this.res.style.transform="scale(".concat(e.valMax,")")),window.addEventListener("scroll",(function(){var r=t.smartRange(window.scrollY,{min:e.from,max:e.to},{min:e.valMin,max:e.valMax});"opacity"===e.value?t.res.style.opacity=r:"scale"===e.value&&(t.res.style.transform="scale(".concat(r,")"))}))}},{key:"setAny",value:function(e){this[Object.keys(e)[0]]=[Object.values(e)[0]]}},{key:"setID",value:function(e){this.id=e}},{key:"setPrevText",value:function(e){this.prevText=e}},{key:"getCSS",value:function(){return this.css}},{key:"getPX",value:function(e){return{xs:"0px",sm:"576px",md:"768px",lg:"992px",xl:"1200px",xxl:"1400px",mxxl:"1800px"}[e]||"Invalid breakpoint"}},{key:"respad",value:function(e){var t=this,r=function(){t.pad(e[0].values);for(var r=0;r<e.length;r++){var n=e[r].breakpoint;window.matchMedia("(min-width: ".concat(t.getPX(n))).matches&&t.pad(e[r].values)}};window.addEventListener("resize",r),r()}},{key:"resmar",value:function(e){var t=this,r=function(){t.mar(e[0].values);for(var r=0;r<e.length;r++){var n=e[r].breakpoint;window.matchMedia("(max-width: ".concat(t.getPX(n))).matches&&t.mar(e[r].values)}};window.addEventListener("resize",r),r()}},{key:"resprop",value:function(e){var t=this;console.log("RES STYLE"),console.log(e),this.prevStyles={};for(var r=0;r<this.res.style.length;r++){var n=this.res.style[r];this.prevStyles[n]=this.res.style[n],console.log("kio")}var o=function(){for(var r in t.prevStyles)t.res.style[r]=t.prevStyles[r];console.log("mkio");for(var n=0;n<e.length;n++){var o=e[n].breakpoint,s="(max-width: ".concat(o,")");if(console.log("testing media query:",s,window.matchMedia(s).matches),window.matchMedia(s).matches)for(var i in e[n])"breakpoint"!==i&&(console.log("ukio"),t.res.style[i]=e[n][i])}};window.addEventListener("resize",o),o()}},{key:"isNumber",value:function(e){return"number"==typeof e&&!isNaN(e)}},{key:"pad",value:function(e){for(var t=0;t<e.length;t++)for(var r=Object.keys(e[t]),n=0;n<r.length;n++)for(var o=r[n],s=e[t][o],i=0;i<o.length;i++)switch(o[i]){case"a":this.res.style.padding=this.isNumber(s)?"".concat(s,"px"):s;break;case"t":this.res.style.paddingTop=this.isNumber(s)?"".concat(s,"px"):s;break;case"l":this.res.style.paddingLeft=this.isNumber(s)?"".concat(s,"px"):s;break;case"r":this.res.style.paddingRight=this.isNumber(s)?"".concat(s,"px"):s;break;case"b":this.res.style.paddingBottom=this.isNumber(s)?"".concat(s,"px"):s}return this}},{key:"as",value:function(e){return this.res.style.alignSelf=e,this}},{key:"mar",value:function(e){for(var t=0;t<e.length;t++)for(var r=Object.keys(e[t]),n=0;n<r.length;n++)for(var o=r[n],s=e[t][o],i=0;i<o.length;i++){switch(o[i]){case"a":this.res.style.margin=this.isNumber(s)?"".concat(s,"px"):s;break;case"t":this.res.style.marginTop=this.isNumber(s)?"".concat(s,"px"):s;break;case"l":this.res.style.marginLeft=this.isNumber(s)?"".concat(s,"px"):s;break;case"r":this.res.style.marginRight=this.isNumber(s)?"".concat(s,"px"):s;break;case"b":this.res.style.marginBottom=this.isNumber(s)?"".concat(s,"px"):s}"auto"===o[i]&&(this.res.style.marginLeft="auto",this.res.style.marginRight="auto")}return this}},{key:"smartRange",value:function(e,t,r){e<t.min&&(e=t.min),e>t.max&&(e=t.max);var n=(e-t.min)/(t.max-t.min);t.min>t.max&&(n=(e-t.max)/(t.min-t.max));var o=(r.min-r.max)*n-r.min;if(o=Math.abs(o),r.min<r.max){var s=(r.max+Math.abs(r.min))*n;o=r.min+s}return o}},{key:"gpos",value:function(e){return this.res.style.gridColumn=e.col,this.res.style.gridRow=e.row,this}},{key:"fluidCopy",value:function(e){if(e instanceof Object){this.prevStylex=this.res.style,this.res=document.createElement("h1"),this.res.style.cssText=this.prevStylex.cssText;var t=document.createTextNode(this.text);return this.res.appendChild(t),this.res.style.fontSize=e.exact,this}if("S1"===e){this.prevStylex=this.res.style,this.res=document.createElement("h1"),this.res.style.cssText=this.prevStylex.cssText;var r=document.createTextNode(this.text);this.res.appendChild(r),this.res.style.fontSize="calc(1.625rem + 5.075vw)"}if("S2"===e){this.prevStylex=this.res.style,this.res=document.createElement("h2"),this.res.style.cssText=this.prevStylex.cssText;var n=document.createTextNode(this.text);this.res.appendChild(n),this.res.style.fontSize="calc(1.500rem + 4.3vw)"}if("S3"===e){this.prevStylex=this.res.style,this.res=document.createElement("h3"),this.res.style.cssText=this.prevStylex.cssText;var o=document.createTextNode(this.text);this.res.appendChild(o),this.res.style.fontSize="calc(1.375rem + 3.525vw)"}if("S4"===e){this.prevStylex=this.res.style,this.res=document.createElement("h4"),this.res.style.cssText=this.prevStylex.cssText;var s=document.createTextNode(this.text);this.res.appendChild(s),this.res.style.fontSize="calc(1.250rem + 2.75vw)"}if("S5"===e){this.prevStylex=this.res.style,this.res=document.createElement("h5"),this.res.style.cssText=this.prevStylex.cssText;var i=document.createTextNode(this.text);this.res.appendChild(i),this.res.style.fontSize="calc(1.125rem + 1.975vw)"}return"S6"===e&&(this.res.style.fontSize="calc(1rem + 0.5vw)"),this}},{key:"setIndex",value:function(e){this.index=e}},{key:"borderObj",value:function(e){var t,r=null!==(t=e.type)&&void 0!==t?t:"solid";return this.res.style.border="".concat(e.width," ").concat(r," ").concat(e.color),this.res.style.borderRadius=e.radius,this}},{key:"setPref",value:function(e){this.preffersId=e}},{key:"setClass",value:function(e){this.class=e}},{key:"setTags",value:function(e){this.openTag=e.open,this.closeTag=e.close,console.log("TAGS SET"),console.log(e)}},{key:"chainReact",value:function(e,n,o){var s=this;console.log("0P"),this.ap=!1,this.cta=0,this.once=!1;var i,a=r(e);try{for(a.s();!(i=a.n()).done;){var l=i.value;l.range||(l.range=["0px","999999px"])}}catch(e){a.e(e)}finally{a.f()}e.sort((function(e,t){return parseInt(e.range[0])-parseInt(t.range[0])}));var c=function(i){var a=window.visualViewport.width,l=[],c=[];s.resCopy=s.res,s.storedQueries=e.map((function(e){return e.target})).filter((function(e){return null!=e}));var u,f=r(e);try{for(f.s();!(u=f.n()).done;){var p=u.value;s.counterIndex++;var d=t(p.range,2),y=d[0],h=d[1],m=parseInt(y),v=parseInt(h),g=!0;if(p.target){g=!1;for(var b=0;b<p.target.length;b++)p.target[b]===n&&(g=!0)}a>=m&&a<=v&&g&&(l.push(p.log),c.push(p),p.op&&p.op.margin&&(s.useMargin=p.op.margin))}}catch(e){f.e(e)}finally{f.f()}if(o&&!o.includes("background")&&(s.res.style.background="",s.res.style.backgroundColor=""),s.res.style.textShadow="",o&&!o.includes("border")&&(s.res.style.border=""),o&&!o.includes("margin")&&(s.res.style.margin=""),s.res.style["-webkit-text-fill-color"]="",s.res.style["-webkit-text-stroke-color"]="",s.res.style["-webkit-text-stroke-width"]="",s.res.style.filter="",s.options.background&&(console.log(s.options.background),s.res.style.background=s.options.background),l.includes("gradient"),(l.includes("gradient")||l.includes("shadow"))&&(s.res.style.position="relative"),l.includes("blast")){var x,w=c.filter((function(e){return"blast"===e.log}))[0].op.color,k=null!==(x=c.filter((function(e){return"blast"===e.log}))[0].op.width)&&void 0!==x?x:"1px";"FlexRowLayoutElement"===s.getType()||"LayoutWrapperElement"===s.getType()?(s.res.style.border="".concat("number"==typeof k?k+"px":k," solid orange"),s.res.style.display="inline-block","FlexRowLayoutElement"===s.getType()&&(s.res.style.display="flex"),s.res.style.boxSizing="border-box",s.res.style.transformOrigin="center",s.blastTarget=s.res):(s.text&&(s.res.textContent=s.text),s.res.style["-webkit-text-fill-color"]="transparent",s.res.style["-webkit-text-stroke-color"]=w,s.res.style["-webkit-text-stroke-width"]="".concat(k))}if(l.includes("filter")){var S=c.filter((function(e){return"filter"===e.log}))[0].op.filter;s.res.style.filter=S}if(l.includes("background")&&(s.res.style.backgroundColor="green"),l.includes("gradient")&&("LayoutWrapperElement"!==s.getType()&&"FlexRowLayoutElement"!==s.getType()&&(s.res.style["-webkit-text-fill-color"]="transparent"),s.res.style.background=s.globalGradient,"LayoutWrapperElement"!==s.getType()&&"FlexRowLayoutElement"!==s.getType()&&(s.res.style["background-clip"]="text")),l.includes("shadow")){var T,E="",O=0;for(b=0;b<s.options.shadow.op.steps;b++){var C;E+="drop-shadow(".concat(O+=3,"px ").concat(O,"px ").concat(O,"px ").concat(null!==(C=s.options.shadow.color)&&void 0!==C?C:"gray",") ")}"FlexRowLayoutElement"===s.getType()||"LayoutWrapperElement"===s.getType()?s.res.style.boxShadow="".concat(O,"px ").concat(O,"px ").concat(O,"px ").concat(null!==(T=s.options.shadow.color)&&void 0!==T?T:"gray"):s.res.style.filter=E}if(l.includes("margin"))for(b=0;b<e.length;b++)if(e[b].op){var j=e[b].op.offsets;j&&void 0!==s.index&&(s.res.style.margin=j[Number(s.index)]+"px")}if(l.includes("spana")||l.includes("span")){if(s.res=s.resCopy,s.options.span){var L;for(L=Array.isArray(s.options.span)?s.options.span.filter((function(e){return"span"===e.op.name}))[0]:s.options.span,s.res.textContent="",b=0;b<L.op.parts.length;b++){var A=L.op.parts[b].style,I=new s.constructor(L.op.parts[b].text).setup({type:"span"}).set(A).render();s.res.appendChild(I)}}}else{var N=new s.constructor(s.prevText).set({}).render();s.prevText&&s.prevText.length>0&&i&&s.res.appendChild(N)}if(l.includes("animation")){if(s.options.animation&&!s.hasAnimated&&!s.options.animation.op.fireAt){console.warn(s.openTag),s.hasAnimated=!0;var W=s.options.animation.op;window.addEventListener("sidebar:open",(function(){s.res.animate(W.keyframesOpen,W.openOptions)})),window.addEventListener("sidebar:closed",(function(){s.res.animate(W.keyframesClose,W.closeOptions)})),s.res.animate(W.keyframesClose,{duration:0,fill:"forwards"}),s.openTag&&s.closeTag&&(window.addEventListener(s.openTag,(function(){s.res.animate(W.keyframesOpen,W.openOptions)})),window.addEventListener(s.closeTag,(function(){s.res.animate(W.keyframesClose,W.closeOptions)})))}if(s.options.animation&&s.options.animation.op.fireAt&&s.options.animation.op.fireAt.endsWith("px")){var R=s.options.animation.op;s.res.animate(R.keyframesClose,{duration:0,fill:"forwards"});var P=function(){window.scrollY>parseFloat(R.fireAt)&&(s.res.animate(R.keyframesOpen,R.openOptions),window.removeEventListener("scroll",P))};window.addEventListener("scroll",P)}if(s.options.animation&&s.options.animation.op.fireAt&&"inview"===s.options.animation.op.fireAt){var z=s.options.animation.op;s.res.animate(z.keyframesClose,{duration:0,fill:"forwards"}),new IntersectionObserver((function(e,t){e.forEach((function(e){e.isIntersecting&&(s.res.animate(z.keyframesOpen,z.openOptions),t.disconnect())}))})).observe(s.res)}}};this.options.animation||window.addEventListener("resize",(function(){return c()})),c()}},{key:"maxWidth",value:function(e){return this.res.style.maxWidth=e,this}},{key:"removeQuotesFromFirstWord",value:function(e){return e.replace(/"([^"]+)":/g,"$1:")}},{key:"arrayMargin",value:function(e,t){return e.includes("left")&&(this.res.style.marginLeft=t),e.includes("right")&&(this.res.style.marginRight=t),e.includes("top")&&(this.res.style.marginTop=t),e.includes("bottom")&&(this.res.style.marginBottom=t),e.includes("all")&&(this.res.style.margin=t),t||(this.res.style.marginBottom=e),this}}],n&&s(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function l(e){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l(e)}function c(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return u(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,a=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){a=!0,s=e},f:function(){try{i||null==r.return||r.return()}finally{if(a)throw s}}}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,p(n.key),n)}}function p(e){var t=function(e){if("object"!=l(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=l(r))return r;throw new TypeError("@ must return a primitive value.")}return String(e)}(e);return"symbol"==l(t)?t:t+""}function d(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(d=function(){return!!e})()}function y(e){return y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},y(e)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}var m=function(){function e(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),function(e,t,r){return t=y(t),function(e,t){if(t&&("object"==l(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,d()?Reflect.construct(t,r||[],y(e).constructor):t.apply(e,r))}(this,e)}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}(e,a),t=e,(r=[{key:"setup",value:function(e){return this.obj=e,this.setTags(this.obj.tags),this.animate=void 0===this.obj.animate||this.obj.animate,this.res=this.createSideNav(e),this.res.style.position="relative",this.res.style.zIndex=3,this.closed=!0,this}},{key:"toggleSideNav",value:function(e){var t=this;this.closed=!this.closed;var r=this.res.children[0];if(this.closed)if(r.style.overflowX="hidden",e.style.opacity=1,this.animate){this.ope=r.animate([{transform:"translateX(0)"},{transform:"translateX(100%)"}],{duration:300,fill:"forwards"}),this.ope.finished.then((function(){var e=new CustomEvent(t.obj.tags.close);window.dispatchEvent(e)}));var n,o=-1,s=c(r.children);try{for(s.s();!(n=s.n()).done;){var i=n.value;if(o+=1,this.masterEL[o]){var a,l=c(i.children);try{for(l.s();!(a=l.n()).done;){var u=a.value,f=this.masterEL[o].options.animation;f&&this.mappedIDS.includes(u.id)&&u.animate(f.op.keyframesClose,f.op.closeOptions)}}catch(e){l.e(e)}finally{l.f()}}}}catch(e){s.e(e)}finally{s.f()}}else r.style.display="none";else{r.style.overflowX="none";var p,d=-1,y=c(r.children);try{for(y.s();!(p=y.n()).done;){var h=p.value;d+=1;var m,v=c(h.children);try{for(v.s();!(m=v.n()).done;){var g=m.value;if(this.mappedIDS.includes(g.id)&&void 0!==this.masterEL[0]){var b=this.masterEL[d].options.animation;if(b){console.log("OPEN KEYFRAMES"),console.log(b.op.keyframesOpen);var x=b.op.openOptions;x.delay||(x.delay=1),x.duration||(x.duration=300),console.log(x),g.animate(b.op.keyframesOpen,x)}}}}catch(e){v.e(e)}finally{v.f()}}}catch(e){y.e(e)}finally{y.f()}e.style.opacity=0,this.animate?(r.style.display="flex",this.opeClose=r.animate([{transform:"translateX(100%)"},{transform:"translateX(0)"}],{duration:300,fill:"forwards"}),this.opeClose.finished.then((function(){var e=new CustomEvent(t.obj.tags.open);window.dispatchEvent(e)}))):r.style.display="flex"}}},{key:"createToggleButton",value:function(e){var t=document.createElement("button");return t.innerText="☰",t.style.padding="10px 20px",t.style.backgroundColor="transparent",t.style.color=null!=e?e:"#3498db",t.style.border="none",t.style.borderRadius="5px",t.style.cursor="pointer",t.style.zIndex=1,t.style.fontSize="1.6rem",this.obj.fixed&&(t.style.position="fixed"),t}},{key:"createCloseButton",value:function(e){var t=document.createElement("button");return t.innerText="×",t.style.fontSize="1.6rem",t.style.padding="10px 20px",t.style.backgroundColor="transparent",t.style.color=null!=e?e:"black",t.style.border="none",t.style.borderRadius="5px",t.style.cursor="pointer",t.style.zIndex=1,t.style.alignSelf="flex-end",t}},{key:"createSideNav",value:function(e){var t=this,r=document.createElement("div");r.style.display="flex",r.style.justifyContent="flex-end";var n=document.createElement("div");n.style.display="none",n.style.background=this.obj.background||"#1abc9c",n.style.height="100%",window.matchMedia("(max-device-width: 415px)").matches?n.style.width="100%":n.style.width=this.obj.width||"400px",n.style.position="fixed",n.style.right=0,this.animate&&(n.style.transform="translateX(100%)"),n.style.flexDirection="column",n.style.justifyContent="flex-start";var o=this.createToggleButton(this.obj.hamColour.opened),s=this.createCloseButton(this.obj.hamColour.closed);return o.addEventListener("click",(function(){return t.toggleSideNav(o)})),s.addEventListener("click",(function(){return t.toggleSideNav(o)})),n.appendChild(s),r.appendChild(n),r.appendChild(o),r}},{key:"items",value:function(e){this.masterEL=e.items.filter((function(e){return void 0!==e.link})),console.log("EXTRACT IDs"),console.log(e);var t=e.items.filter((function(e){return void 0===e.items})).map((function(e){return e.id}));if(this.mappedIDS=t,this.item=e,this.res.children[0].appendChild(e.render()),void 0!==this.masterEL[0]){console.log("ANNAX"),console.log(this.masterEL[0]);var r=this.masterEL[0].options.animation;if(r){var n,o=c(this.res.children[0].children);try{for(o.s();!(n=o.n()).done;){var s,i=c(n.value.children);try{for(i.s();!(s=i.n()).done;){var a=s.value;if(this.mappedIDS.includes(a.id)){var l=r.op.closeOptions;l.delay=0,console.log("ANNAX"),console.log("SETTING INITIAL STATE ZEROING THE DELAY"),console.log(r.op.keyframesClose),console.log(l),a.animate(r.op.keyframesClose,r.op.closeOptions)}}}catch(e){i.e(e)}finally{i.f()}}}catch(e){o.e(e)}finally{o.f()}}}return this}},{key:"toCode",value:function(){var e="new SideNav().setup(".concat(this.formatObj(this.obj),")");if(this.item){var t=this.item.toCode?this.item.toCode().join(""):this.formatObj(this.item);t=t.replace(/,\s*(\.set\(|\.add\()/g,"\n $1"),e+=".items(".concat(t,")")}return e}},{key:"formatObj",value:function(e){return JSON.stringify(e,null,2).replace(/"(\w+)"\s*:/g,"$1:")}},{key:"render",value:function(e){return e&&document.querySelector(e).appendChild(this.res),this.res}}])&&f(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r}();export{m as SideNav};