UNPKG

nodality

Version:

A lightweight library for declarative UI elements.

2 lines 22.7 kB
/*! For license information please see multiswitchers.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,i,s,a=[],l=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=i.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&&(s=r.return(),Object(s)!==s))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,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}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,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,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw s}}}}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 i(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,s(n.key),n)}}function s(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="",i="",s="",a="",l="",c="",u="",p="";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:")?i=e.replace("tz:",""):e.startsWith("scale(")?s=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:")&&(p=e.replace("opacity:",""))})),r=o.setDefault(r),n=o.setDefault(n),i=o.setDefault(i);var f="";if("0px"!=n&&"0px"!=r&&"0px"!=i?f+="translate3d(".concat(r,", ").concat(n,", ").concat(i,")"):"0px"==n&&"0px"==r||(f+="translate(".concat(r,", ").concat(n,")")),s&&(f+=" ".concat(s)),l&&(f+=" ".concat(l)),a&&(f+=" ".concat(a)),c&&(f+=" ".concat(c)),u&&(f+=" ".concat(u)),f){if(e.op.transform.duration){var h=e.op.transform.duration.replace(/^(\d+)(s)-/,(function(e,t,r){return t/2+r+" "})),y="transform ".concat(h,", opacity ").concat(h);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=f,o.res.style.opacity=p}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 i=1e3*parseFloat(t.duration),s=t.closeAfter?t.closeAfter:0;setTimeout((function(){t.keep||n()}),i/2+s)}t.hardCSS&&(o.res.style.transform=t.hardCSS)}else alert("THIS FIRE WITH GRADIENT (invalid block"),console.log("INVALID BLOCKA"),console.log(e)},(r=s(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,i="(max-width: ".concat(o,")");if(console.log("testing media query:",i,window.matchMedia(i).matches),window.matchMedia(i).matches)for(var s in e[n])"breakpoint"!==s&&(console.log("ukio"),t.res.style[s]=e[n][s])}};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],i=e[t][o],s=0;s<o.length;s++)switch(o[s]){case"a":this.res.style.padding=this.isNumber(i)?"".concat(i,"px"):i;break;case"t":this.res.style.paddingTop=this.isNumber(i)?"".concat(i,"px"):i;break;case"l":this.res.style.paddingLeft=this.isNumber(i)?"".concat(i,"px"):i;break;case"r":this.res.style.paddingRight=this.isNumber(i)?"".concat(i,"px"):i;break;case"b":this.res.style.paddingBottom=this.isNumber(i)?"".concat(i,"px"):i}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],i=e[t][o],s=0;s<o.length;s++){switch(o[s]){case"a":this.res.style.margin=this.isNumber(i)?"".concat(i,"px"):i;break;case"t":this.res.style.marginTop=this.isNumber(i)?"".concat(i,"px"):i;break;case"l":this.res.style.marginLeft=this.isNumber(i)?"".concat(i,"px"):i;break;case"r":this.res.style.marginRight=this.isNumber(i)?"".concat(i,"px"):i;break;case"b":this.res.style.marginBottom=this.isNumber(i)?"".concat(i,"px"):i}"auto"===o[s]&&(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 i=(r.max+Math.abs(r.min))*n;o=r.min+i}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 i=document.createTextNode(this.text);this.res.appendChild(i),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 s=document.createTextNode(this.text);this.res.appendChild(s),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 i=this;console.log("0P"),this.ap=!1,this.cta=0,this.once=!1;var s,a=r(e);try{for(a.s();!(s=a.n()).done;){var l=s.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(s){var a=window.visualViewport.width,l=[],c=[];i.resCopy=i.res,i.storedQueries=e.map((function(e){return e.target})).filter((function(e){return null!=e}));var u,p=r(e);try{for(p.s();!(u=p.n()).done;){var f=u.value;i.counterIndex++;var h=t(f.range,2),y=h[0],d=h[1],v=parseInt(y),m=parseInt(d),b=!0;if(f.target){b=!1;for(var g=0;g<f.target.length;g++)f.target[g]===n&&(b=!0)}a>=v&&a<=m&&b&&(l.push(f.log),c.push(f),f.op&&f.op.margin&&(i.useMargin=f.op.margin))}}catch(e){p.e(e)}finally{p.f()}if(o&&!o.includes("background")&&(i.res.style.background="",i.res.style.backgroundColor=""),i.res.style.textShadow="",o&&!o.includes("border")&&(i.res.style.border=""),o&&!o.includes("margin")&&(i.res.style.margin=""),i.res.style["-webkit-text-fill-color"]="",i.res.style["-webkit-text-stroke-color"]="",i.res.style["-webkit-text-stroke-width"]="",i.res.style.filter="",i.options.background&&(console.log(i.options.background),i.res.style.background=i.options.background),l.includes("gradient"),(l.includes("gradient")||l.includes("shadow"))&&(i.res.style.position="relative"),l.includes("blast")){var w,x=c.filter((function(e){return"blast"===e.log}))[0].op.color,k=null!==(w=c.filter((function(e){return"blast"===e.log}))[0].op.width)&&void 0!==w?w:"1px";"FlexRowLayoutElement"===i.getType()||"LayoutWrapperElement"===i.getType()?(i.res.style.border="".concat("number"==typeof k?k+"px":k," solid orange"),i.res.style.display="inline-block","FlexRowLayoutElement"===i.getType()&&(i.res.style.display="flex"),i.res.style.boxSizing="border-box",i.res.style.transformOrigin="center",i.blastTarget=i.res):(i.text&&(i.res.textContent=i.text),i.res.style["-webkit-text-fill-color"]="transparent",i.res.style["-webkit-text-stroke-color"]=x,i.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;i.res.style.filter=S}if(l.includes("background")&&(i.res.style.backgroundColor="green"),l.includes("gradient")&&("LayoutWrapperElement"!==i.getType()&&"FlexRowLayoutElement"!==i.getType()&&(i.res.style["-webkit-text-fill-color"]="transparent"),i.res.style.background=i.globalGradient,"LayoutWrapperElement"!==i.getType()&&"FlexRowLayoutElement"!==i.getType()&&(i.res.style["background-clip"]="text")),l.includes("shadow")){var O,T="",E=0;for(g=0;g<i.options.shadow.op.steps;g++){var j;T+="drop-shadow(".concat(E+=3,"px ").concat(E,"px ").concat(E,"px ").concat(null!==(j=i.options.shadow.color)&&void 0!==j?j:"gray",") ")}"FlexRowLayoutElement"===i.getType()||"LayoutWrapperElement"===i.getType()?i.res.style.boxShadow="".concat(E,"px ").concat(E,"px ").concat(E,"px ").concat(null!==(O=i.options.shadow.color)&&void 0!==O?O:"gray"):i.res.style.filter=T}if(l.includes("margin"))for(g=0;g<e.length;g++)if(e[g].op){var L=e[g].op.offsets;L&&void 0!==i.index&&(i.res.style.margin=L[Number(i.index)]+"px")}if(l.includes("spana")||l.includes("span")){if(i.res=i.resCopy,i.options.span){var C;for(C=Array.isArray(i.options.span)?i.options.span.filter((function(e){return"span"===e.op.name}))[0]:i.options.span,i.res.textContent="",g=0;g<C.op.parts.length;g++){var P=C.op.parts[g].style,A=new i.constructor(C.op.parts[g].text).setup({type:"span"}).set(P).render();i.res.appendChild(A)}}}else{var W=new i.constructor(i.prevText).set({}).render();i.prevText&&i.prevText.length>0&&s&&i.res.appendChild(W)}if(l.includes("animation")){if(i.options.animation&&!i.hasAnimated&&!i.options.animation.op.fireAt){console.warn(i.openTag),i.hasAnimated=!0;var N=i.options.animation.op;window.addEventListener("sidebar:open",(function(){i.res.animate(N.keyframesOpen,N.openOptions)})),window.addEventListener("sidebar:closed",(function(){i.res.animate(N.keyframesClose,N.closeOptions)})),i.res.animate(N.keyframesClose,{duration:0,fill:"forwards"}),i.openTag&&i.closeTag&&(window.addEventListener(i.openTag,(function(){i.res.animate(N.keyframesOpen,N.openOptions)})),window.addEventListener(i.closeTag,(function(){i.res.animate(N.keyframesClose,N.closeOptions)})))}if(i.options.animation&&i.options.animation.op.fireAt&&i.options.animation.op.fireAt.endsWith("px")){var R=i.options.animation.op;i.res.animate(R.keyframesClose,{duration:0,fill:"forwards"});var I=function(){window.scrollY>parseFloat(R.fireAt)&&(i.res.animate(R.keyframesOpen,R.openOptions),window.removeEventListener("scroll",I))};window.addEventListener("scroll",I)}if(i.options.animation&&i.options.animation.op.fireAt&&"inview"===i.options.animation.op.fireAt){var z=i.options.animation.op;i.res.animate(z.keyframesClose,{duration:0,fill:"forwards"}),new IntersectionObserver((function(e,t){e.forEach((function(e){e.isIntersecting&&(i.res.animate(z.keyframesOpen,z.openOptions),t.disconnect())}))})).observe(i.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&&i(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=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function p(e,t,r){return(t=h(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}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,h(n.key),n)}}function h(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("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==l(t)?t:t+""}function y(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(y=function(){return!!e})()}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}function v(e,t){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},v(e,t)}var m=function(){function e(){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(e,t,r){return t=d(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,y()?Reflect.construct(t,r||[],d(e).constructor):t.apply(e,r))}(this,e)).breakpoints=[],t.container=null,t.currentView=null,t.internalDiv=null,t.resizeListener=null,t}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&&v(e,t)}(e,a),t=e,r=[{key:"set",value:function(e){var t=e.breakpoints;if(this.options={breakpoints:t},!Array.isArray(t))throw new Error("Breakpoints should be an array of objects with 'at' and 'view' properties.");return this.breakpoints=t.map((function(e){if("string"!=typeof e.at||!(e.view.render()instanceof HTMLElement))throw new Error("Each breakpoint must have 'at' as a string and 'view' as an HTMLElement.");return u(u({},e),{},{at:parseInt(e.at,10)})})),this.breakpoints.sort((function(e,t){return e.at-t.at})),this}},{key:"toCode",value:function(){JSON.stringify(this.options.breakpoints.map((function(e){return e.view.toCode()})).flat(),null,4),JSON.stringify(this.options.breakpoints.map((function(e){return e.at})),null,4),JSON.stringify(this.options.breakpoints,null,4);for(var e="",t=0;t<this.options.breakpoints.length;t++)e+='{ at: "'.concat(this.options.breakpoints[t].at,'", view: ').concat(this.options.breakpoints[t].view.toCode()," }, \n");return["new Switcher().set({\n breakpoints: [\n ".concat(e,"\n ]\n })")]}},{key:"render",value:function(e){return this.internalDiv=document.createElement("div"),this.applyView(),this.resizeListener=this.applyView.bind(this),window.addEventListener("resize",this.resizeListener),void 0!==e&&document.querySelector(e).appendChild(this.internalDiv),this.internalDiv}},{key:"createRanges",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:99999,r=[],n=0;n<e.length;n++)r.push({from:e[n],to:n<e.length-1?e[n+1]-1:t});return r}},{key:"addRanges",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:99999;return e.map((function(e,n){var o=t[n],i=n<t.length-1?t[n+1]-1:r;return u(u({},e),{},{range:{from:o,to:i}})}))}},{key:"applyView",value:function(){var e=this;console.log("MAKE RANGES"),window.innerWidth,console.log(this.breakpoints),console.log(this.breakpoints.map((function(e){return e.at})));var t=this.breakpoints.map((function(e){return e.at})),r=this.breakpoints.map((function(e){return e.at})),n=(this.createRanges(r),this.addRanges(this.breakpoints,t));console.log(n),n.forEach((function(t){var r="(min-width: ".concat(t.range.from,"px) and (max-width: ").concat(t.range.to,"px)"),n=window.matchMedia(r);console.warn(r),n.matches&&(console.log("Viewport width is within the range: ".concat(t.range.from,"px to ").concat(t.range.to,"px")),e.currentView!==t.view.render()&&(e.internalDiv.innerHTML="",e.internalDiv.appendChild(t.view.render()),e.currentView=t.view.render()))})),console.log("MBO")}},{key:"destroy",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null),this.internalDiv&&this.container&&this.container.removeChild(this.internalDiv),this.container=null,this.currentView=null,this.internalDiv=null}}],r&&f(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r}();export{m as Switcher};