-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbay.min.mjs
1 lines (1 loc) · 27 KB
/
bay.min.mjs
1
var __awaiter=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}l((i=i.apply(e,t||[])).next())}))};const bay=e=>{"use strict";if(window.bay)return;window.bay={};const t=(e,t)=>e.querySelectorAll(t),n="$bay",i="$el",r="data-bay-",a="this-attribute";let o="",s=[],l=[],d=new Map,c="";const u=[".passive",".capture",".once",".left",".middle",".right",".enter",".tab",".delete",".backspace",".esc",".space",".arrow-up",".arrow-down",".arrow-left",".arrow-right",".ctrl",".alt",".shift",".meta",".stop",".prevent",".self"];!function e(n){t(n,"template[shadowrootmode], template[shadowroot]").forEach((t=>{const n=t.getAttribute("shadowrootmode")||t.getAttribute("shadowroot"),i=t.parentNode.attachShadow({mode:n});i.appendChild(t.content),t.remove(),e(i)}))}(document);const h=document.createElement("textarea");function b(e){return"string"==typeof e?(h.textContent=e,h.innerHTML.replaceAll('"',""").replaceAll("'","'")):e}function p(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}function y(e,t){return new Proxy(e,{get(e,n){if("isProxy"===n)return!0;const i=e[n];return void 0===i?"":null!==i?(i.isProxy||"object"!=typeof i||(i instanceof Map?e[n]=function(e,t){return new Proxy(e,{get:(e,n)=>"set"===n?function(n,i){return e.set(n,b(i)),t&&t(),e}:["get","has","delete","clear"].includes(n)?function(...t){return e[n].apply(e,t)}:e[n]})}(i,t):i instanceof WeakMap?e[n]=function(e,t){return new Proxy(e,{get:(e,n)=>"set"===n?function(n,i){return e.set(n,b(i)),t&&t(),e}:["get","has","delete"].includes(n)?function(...t){return e[n].apply(e,t)}:e[n]})}(i,t):i instanceof Set?e[n]=function(e,t){return new Proxy(e,{get:(e,n)=>"add"===n?function(n){return e.add(b(n)),t&&t(),e}:["has","delete","clear"].includes(n)?function(...t){return e[n].apply(e,t)}:e[n]})}(i,t):i instanceof WeakSet?e[n]=function(e,t){return new Proxy(e,{get:(e,n)=>"add"===n?function(n){return e.add(b(n)),t&&t(),e}:["has","delete"].includes(n)?function(...t){return e[n].apply(e,t)}:e[n]})}(i,t):e[n]=y(i,t)),e[n]):void 0},set:(e,n,i)=>(e[n]=b(i),t&&t(),!0)})}let w,m;function f(){Object.entries(window.location).forEach((e=>{window.bay.route[`${e[0]}`]=e[1]})),window.bay.route.path=window.location.pathname,window.bay.route.params={};const e=new URLSearchParams(window.location.search);for(let[t,n]of e)window.bay.route.params[t]=n}function $(e){return([1e7].toString()+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))).replaceAll("-","").substring(0,e)}window.bay.emit=function(e,t){const n={detail:{name:e,data:t}};window.dispatchEvent(new CustomEvent("bay_emit",n)),window.dispatchEvent(new CustomEvent(e,n))},window.bay.receive=function(e,n,i,a){[...t(e,`[${r}${i}]`),...t(n,`[${r}${i}]`),...t(document,`[${r}${i}]`)].forEach((e=>{e.dispatchEvent(new CustomEvent(i,{detail:{name:i,data:a}}))}))},window.bay.global=y({},(()=>{w&&window.cancelAnimationFrame(w),w=window.requestAnimationFrame((()=>{window.dispatchEvent(new CustomEvent("bay_global_event"))}))})),window.bay.route=y({},(()=>{m&&window.cancelAnimationFrame(m),m=window.requestAnimationFrame((()=>{window.dispatchEvent(new CustomEvent("bay_route_event"))}))})),f(),window.addEventListener("popstate",(()=>{f()})),window.bay.router=function(e,t){const n=t.split("/"),i=e.split("/");let r=!0,a={};for(let e=0;e<n.length;e++)if(":"===n[e][0])a[n[e].slice(1)]=i[e];else if("*"!==n[e]&&n[e]!==i[e]){r=!1;break}return!!r&&a};const v=$(8);function g(e){[...document.querySelectorAll("[bay-hydrate]")].forEach(((e,t)=>{e.id="bay-hydrate-"+t;let n=e.querySelector("template").innerHTML,i=document.createElement("bay-hydrate-"+t);i.setAttribute("inner-html","#bay-hydrate-"+t),document.body.appendChild(i),window.bay.create("bay-hydrate-"+t,"<inner-html>"+n+"</inner-html>")})),[...t(e,"[bay]")].forEach(((e,t)=>{"dsd"===e.getAttribute("bay")&&e.setAttribute("bay",`dsd-${t}`),-1===s.indexOf(e.getAttribute("bay")||"")&&s.push(e)})),s.forEach((e=>{-1===l.indexOf(e.getAttribute("bay"))&&function(e){try{const n=e.getAttribute("bay")||"";let i=e.tagName.toLowerCase();if("template"===i)_(p(e.innerHTML),e,n),e.remove();else if("dsd-"===n.substring(0,4))o=n,e.shadowRoot?_(p(e.shadowRoot.innerHTML),e,i):(_(p(t(e,"template")[0].innerHTML),e,i),t(e,"template")[0].remove());else if("#"===n.substring(0,1)){o=n;const r=t(document,n)[0];if(!r)return void console.error(`Bay cannot find "${n}" selector.`);_(r.innerHTML,e,i),r.remove()}else fetch(n).then((e=>e.text())).then((t=>{_(t=E(t),e,i)})).catch((e=>{console.error("Error:",e)}))}catch(e){console.error(e)}}(e),l.push(e.getAttribute("bay"))}))}function A(t){return e?(Object.entries(e).forEach((([e,n])=>{if("string"==typeof n){let i=`%{${e}}`;t=t.replaceAll(i,n)}})),t):t}function E(e){return e=e.replace(/<template(.*?)>/g,"\x3c!--<template$1>--\x3e").replace(/<\/template>/g,"\x3c!--</template>--\x3e")}function L(e,t){[...e.querySelectorAll("include")].forEach((e=>{const n=e.attributes[0];n&&n.value&&fetch(n.value).then((e=>{if(!e.ok)throw new Error(`HTTP error ${e.status}: ${e.statusText}`);return e.text()})).then((n=>{for(n=E(n);n.indexOf("<style>")>-1;){const e=n.split("<style>")[1].split("</style>")[0];n=n.replaceAll(`<style>${e}</style>`,""),c+=e}n=n.replaceAll(/<!--[\s\S]*?-->/g,""),e.outerHTML=n,t()})).catch((e=>{console.error("Error fetching:",e)}))}))}function _(e,n,i){const r=new DOMParser,a="export default /*HTML*/`";let o;for(e=A(e=e.replaceAll(/<!--[\s\S]*?-->/g,"")),c="",e.startsWith(a)&&(e=(e=(e=(e=e.trim()).split(a)[1]).substring(0,e.length-2)).replaceAll("\\${","${").replaceAll("\\`","`"));e.indexOf("<style>")>-1;){const t=e.split("<style>")[1].split("</style>")[0];e=e.replaceAll(`<style>${t}</style>`,""),c+=t}function s(){o&&0===[...o.querySelectorAll("include")].length&&(customElements.get(i)||R(o,i,function(e){let n=[];const i=e=>{"bay"!==e.name&&"inner-html"!==e.name&&"fouc"!==e.name&&-1===n.indexOf(e.name)&&n.push(e.name)};return[...e.attributes].forEach((e=>i(e))),[...t(document,e.tagName.toLocaleLowerCase())].forEach((e=>{[...e.attributes].forEach((e=>i(e)))})),[...t(document,"template")].forEach((n=>{[...t(n.content,e.tagName.toLocaleLowerCase())].forEach((e=>{[...e.attributes].forEach((e=>i(e)))}))})),n}(n),c,!1))}e='<div id="bay-temporary-compile-element"></div>'+e,o=r.parseFromString(e,"text/html"),o.getElementById("bay-temporary-compile-element").remove(),L(o,s),s()}function x(e,t){e.forEach(((e,n)=>{var i,a;if(!t[n].isEqualNode(e)&&t[n]&&(i=e,[...(a=t[n]).attributes].forEach((e=>{"style"!==e.name&&(i.hasAttribute(e.name)||(a.removeAttribute(e.nodeName),N(a,e.nodeName)&&delete a[e.nodeName]))})),[...i.attributes].forEach((e=>{a.hasAttribute(e.nodeName)&&a.getAttribute(e.nodeName)===e.value||a.setAttribute(e.nodeName,e.value),N(a,e.nodeName)&&a[e.nodeName]!==e.value&&(a[e.nodeName]=e.value)}))),!e.hasAttribute(`${r}style`)&&!e.hasAttribute("style")){const e=t[n].style.width,i=t[n].style.height;t[n].removeAttribute("style"),e&&(t[n].style.width=e),i&&(t[n].style.height=i)}}))}function k(e,n){[...t(e,"*")].map(((e,t)=>{if(e.tagName.indexOf("-")>-1){!(""+e.textContent.trim()+e.innerHTML.trim())&&e.setAttribute("no-diff",!0)}})),[...t(e,"[no-diff]")].map(((e,i)=>{[...t(n,"[no-diff]")][i]&&(e.innerHTML=[...t(n,"[no-diff]")][i].innerHTML)}))}function q(e,t,i,a,o){t&&(e.newEvents="",t.forEach(((t,i)=>{[...t.attributes].forEach((a=>function(e,t,i,a,o){if(!i.closest(`[${o}]`))return;let s=t.name;if(s.startsWith(":")){let e=s.split(":")[1];s=s.replace(`:${e}`,`${r}${e}`)}if(s.indexOf(r)>-1){if(s.indexOf("-custom-")>-1&&(s=s.replace("custom-","")),s.indexOf(r+"style")>-1)i.style!==t.value&&(i.style=t.value);else{let o=t.value.replaceAll("window.bay",`${n}`);-1===e.newEvents.indexOf(n+".events=new Map();\n")&&(e.newEvents+=n+".events=new Map();\n");let l={};u.forEach((e=>{if(-1!==s.indexOf(e))switch(e){case".passive":l.passive=!0;break;case".capture":l.capture=!0;break;case".once":l.once=!0;break;case".enter":o="if (e.key !== 'Enter') return;"+o;break;case".tab":o="if (e.key !== 'Tab') return;"+o;break;case".delete":o="if (e.key !== 'Delete') return;"+o;break;case".backspace":o="if (e.key !== 'Backspace') return;"+o;break;case".esc":o="if (e.key !== 'Escape' && e.key !== 'Esc') return;"+o;break;case".space":o="if (e.key !== ' ' && e.key !== 'Spacebar') return;"+o;break;case".arrow-up":o="if (e.key !== 'ArrowUp') return;"+o;break;case".arrow-down":o="if (e.key !== 'ArrowDown') return;"+o;break;case".arrow-left":o="if (e.key !== 'ArrowLeft') return;"+o;break;case".arrow-right":o="if (e.key !== 'ArrowRight') return;"+o;break;case".ctrl":o="if (!e.ctrlKey) return;"+o;break;case".alt":o="if (!e.altKey) return;"+o;break;case".shift":o="if (!e.shiftKey) return;"+o;break;case".meta":o="if (!e.metaKey) return;"+o;break;case".self":o="if (e.target !== e.currentTarget) return;"+o;break;case".left":o="if (e.button !== 0) return;"+o;break;case".middle":o="if (e.button !== 1) return;"+o;break;case".right":o="if (e.button !== 2) return;"+o;break;case".stop":o="e.stopPropagation();"+o;break;case".prevent":o="e.preventDefault();"+o}})),e.newEvents+=`${n}.events.set('${s}-${a}',(e)=>{${o}});\n`;const d=`${e.uniqid}${a}${s}`;let c=s.split(r)[1];u.forEach((e=>{c=c.replace(e,"")})),e.eventHandlers.has(d)&&(i.removeEventListener(c,e.eventHandlers.get(d),l),e.eventHandlers.delete(d)),e.eventHandlers.set(d,(t=>{window.bay[e.uniqid].events&&window.bay[e.uniqid].events.has(`${s}-${a}`)&&window.bay[e.uniqid].events.get(`${s}-${a}`)(t)})),i.addEventListener(c,e.eventHandlers.get(d),l)}}}(e,a,t,i,o)))})),e.newEvents&&e.oldEvents!==e.newEvents&&(e.oldEvents=e.newEvents,function(e,t,n,i){__awaiter(this,void 0,void 0,(function*(){const r=URL.createObjectURL(new Blob([`${n}export default function($bay,$global,$route,$el,$parent,$bay_select_bind,$ref){"use strict";\n${t}};`],{type:"text/javascript"}));(yield import(r)).default.call(window.bay[e.uniqid].proxy,window.bay[e.uniqid],window.bay.global,window.bay.route,window.bay[e.uniqid].$el,window.bay[i]?window.bay[i].proxy:null,window.bay.apply_select,window.bay[e.uniqid].refs),URL.revokeObjectURL(r)}))}(e,e.newEvents,i,a)))}function T(e){e.debouncer&&window.cancelAnimationFrame(e.debouncer),e.debouncer=window.requestAnimationFrame((()=>{e.render()}))}function M(e){e.dsd||(e.tmp=window.bay[e.uniqid].template(),e.shadowDom.getElementById("bay").innerHTML=e.tmp),T(e),e.CSP?e.shadowDom.innerHTML="CSP issue, add blob: to script-src & style-src whitelist.":t(e.shadowDom,"[bay]")[0]&&g(e.shadowDom)}function H(e){return(new DOMParser).parseFromString(e,"text/html").body}function S(e){return 3===e.nodeType?"text":8===e.nodeType?"comment":e.tagName.toLowerCase()}function C(e){return e.childNodes&&e.childNodes.length>0?null:e.textContent}function O(e,t){const n=[...t.childNodes],i=[...e.childNodes];let r=n.length-i.length;if(r>0)for(;r>0;r--)n[n.length-r].parentNode.removeChild(n[n.length-r]);i.forEach(((e,i)=>{if(!n[i])return void t.appendChild(e.cloneNode(!0));if(S(e)!==S(n[i])){try{n[i].parentNode.replaceChild(e.cloneNode(!0),n[i])}catch(e){}return}const r=C(e);if(r&&r!==C(n[i])&&(n[i].textContent=r),n[i].childNodes.length>0&&e.childNodes.length<1)n[i].innerHTML="";else{if(n[i].childNodes.length<1&&e.childNodes.length>0){const t=document.createDocumentFragment();return O(e,t),void n[i].appendChild(t)}e.childNodes.length>0&&O(e,n[i])}}))}function N(e,t){return void 0!==e[t]&&"object"!=typeof e[t]}const D="<div id=\"show\" :style=\"${this.style()}\"><slot></slot></div><script update>$bay.getElementById('show').ontransitionend=()=>this.end();<\/script><script props>this.slide(this.open);<\/script><script mounted>this.slide(this.open);<\/script><script>this.opacity=0;this.display='none';this.slide=(open)=>{let opacity=0;if(open==='true'){opacity=1;this.display='block';};requestAnimationFrame(()=>{this.opacity=opacity;});};this.end=()=>{if(this.open==='false'){this.display='none';}};this.style=()=>{return `display:${this.display};opacity:${this.opacity};transition:opacity ${this.transition || '0s'};`;};<\/script>";function R(e,s,l,c,u){let h="",w=`data-${$(8)}`,m=null,A="",E="",L=[],_=!1,S=!1,C=!1,N=!1,R=!1,j=!1,P=[];try{c="*:not(:defined){opacity:0;max-width:0px;max-height:0px}*:not(:defined)*{opacity:0;max-width:0px;max-height:0px}.bay-hide{display:none}"+(c||""),m=e.body,function(e){[...e.querySelectorAll("define")].forEach((t=>{const n=t.getAttribute("this"),i=t.outerHTML;t.remove(),[...e.querySelectorAll(n)].forEach((e=>{e.outerHTML=i}))}))}(m),h=s;const U=document.createElement(`${s}-update`);m.appendChild(U),(m.innerHTML.indexOf("$global.")>-1||m.innerHTML.indexOf("$global[")>-1)&&(_=!0),(m.innerHTML.indexOf("$route.")>-1||m.innerHTML.indexOf("$route[")>-1||m.innerHTML.indexOf("</router>")>-1||m.innerHTML.indexOf("</route>")>-1||m.innerHTML.indexOf("$bay.update_route")>-1)&&(S=!0),m.innerHTML.indexOf("</route>")>-1&&(c=(c||"")+"[bay-route]>*{pointer-events:none}"),m.innerHTML.indexOf("$prop")>-1&&(C=!0),m.innerHTML.indexOf("$bay.on(")>-1&&(j=!0),m.innerHTML.indexOf("</show>")>-1&&bay.create(`show-${v}`,D,["open","transition"]);const F="element, index, array";let B="";const I=(e,n)=>{if(!t(e,n)[0]){const i=e.getAttribute("array")||[],r=e.getAttribute("params")||F,a=e.getAttribute("join")||"",o=e.getAttribute("duration")||!1,s=[...e.attributes][0]?[...e.attributes][0].nodeValue:"",l=e.nextElementSibling?e.nextElementSibling.tagName.toLowerCase():"";let d="`}return ''})()}";const c=e.hasAttribute("break")?"break;":"",u=0===e.innerHTML.length,h=e.attributes.length?e.attributes[0].name:"",b=`<${n}>`,p=`</${n}>`,y=[...e.attributes];!function(e){for(;e.attributes.length>0;)e.removeAttribute(e.attributes[0].name)}(e);let w=e.outerHTML;const f=(t,n)=>{e.outerHTML=w.replace(b,t).replace(p,n)};switch(n){case"dsd":e.remove();break;case"noscript":m.innerHTML=m.innerHTML.replaceAll(b,"").replaceAll(p,"");break;case"map":f(`\${ Array.isArray(${i}) ? ${i}.${n}((${r})=>{return \``,`\`}).join('${a}') : ''}`);break;case"for":const g=`bay_${n}_${$(8)}`;i.length?f(`\${(()=>{let ${g}=''; Array.isArray(${i}) ? ${i}.forEach((${r})=>{${g}+=\``,`\`}) : '';return ${g};})()}`):f(`\${(()=>{let ${g}=''; ${n} (${s}) { ${g} += \``,`\`};return ${g};})() }`);break;case"if":"else-if"!==l&&"else"!==l||(d="`}"),f(`\${(()=>{ ${n} (${s}) {return \``,d);break;case"else-if":"else-if"!==l&&"else"!==l||(d="`}"),f(` else if (${s}) {return \``,d);break;case"else":f(` ${n} {return \``,d);break;case"show":o?f(`<show-${v} class="bay-show" open="\${${s}}" transition="${o} ease-in-out">`,`</show-${v}>`):f(`<div class="\${(${s})?'bay-show':'bay-show bay-hide'}">`,"</div>");break;case"switch":f(`\${(()=>{let bay_switch=''; ${n} (${s}) { `," };return bay_switch;})() }");break;case"case":u?f(`${n} ${s}:`," "+c):f(`${n} ${s}: bay_switch += \``,"`; "+c);break;case"default":f(`${n}: bay_switch += \``,"`;");break;case"inner-html":N=!0,f("${ (()=>{$bay_inner_html+=`","`;return ''})()}"),e.remove();break;case"route":let A="";y.forEach((e=>{A+=` ${e.name}="${e.value}"`})),f(`<a bay-route :click="e.preventDefault();history.pushState({},'',e.target.getAttribute('href'));window.bay.update_route();"${A}>`,"</a>");break;case"router":f(`\${(()=>{let $path=window.bay.router(window.bay.route.path,'${s}');if($path){return \``,d);break;case"script":switch(h){case"imports":E+=e.innerText.trim()+"\n",e.remove();break;case"update":f("${/*update*/(()=>{setTimeout(()=>{","}, 0);return ``})()}");break;case"props":f("${/*props updates*/(()=>{$props=()=>{","};return ``})()}");break;case"render":f("${/*render*/(()=>{","})()}");break;case"slotchange":f("${/*slotchange updates*/(()=>{$slotchange=(e)=>{$details=e.detail;\n","};return ``})()}");break;case"mounted":B+=`$bay['$mounted']=()=>{${e.innerText}};`,e.remove();break;default:const i=t(m,n)[0];B+=i.innerText,e.remove()}e&&e.parentNode&&(e.outerHTML=w,e.remove())}}};function W(e){e.forEach((e=>{if(e.children.length>0&&W([...e.children]),e.hasAttribute("bay-map")||e.hasAttribute("bay-for")){let t=e.hasAttribute("bay-map")?"map":"for",n=e.getAttribute("this")||"",i=e.getAttribute("params")||"",r=e.getAttribute("bay-map")||e.getAttribute("bay-for")||e.getAttribute("array")||"[]",a=e.getAttribute("join")||"";e.removeAttribute("params"),e.removeAttribute("bay-map"),e.removeAttribute("bay-for"),e.removeAttribute("this"),e.removeAttribute("array"),e.removeAttribute("join");let o=e.outerHTML,s="";if("map"===t)s=`<!--iteration\${ Array.isArray(${r}) ? ${r}.map((${i})=>{return \`${o}\`}).join('${a}') : ''}iteration-->`;else{const e=`bay_for_${$(8)}`;s=n?`<!--iteration\${ (()=>{let ${e}=''; for (${n}) { ${e} += \`${o}\`};return ${e};})()}iteration-->`:`<!--iteration\${(()=>{let ${e}=''; Array.isArray(${r}) ? ${r}.forEach((${i})=>{${e}+=\`${o}\`}) : '';return ${e};})()}iteration-->`}e.outerHTML=s}}))}["dsd","noscript","map","for","if","else-if","else","show","switch","case","default","inner-html","route","router","script"].forEach((e=>{for(;[...t(m,e)].length>0;){[...t(m,e)].forEach((t=>I(t,e)))}})),[...t(m,"*")].forEach((e=>{[...e.attributes].forEach((t=>{const n="bind"===t.name,i="custom:"===t.name.substring(0,7),o="input"===e.tagName.toLowerCase(),s="textarea"===e.tagName.toLowerCase();if(function(e,t){if("src"===t||"href"===t)return!1;const n=document.createElement(e);return n.setAttribute(t,"test_value"),"boolean"==typeof n[t]}(e.tagName.toLowerCase(),t.name)&&e.setAttribute(t.name,"true"),t.name===a){let n=`${a}="${t.value}"`;P.push({original:n,new:`\${(() => {return ${t.value} || ''})()}`}),e.setAttribute(w,"")}if(":"===t.name.substring(0,1)||i){let n="";i&&(n="custom-"),e.setAttribute(`${r}${n}${t.name.split(":")[1]}`,t.value),e.removeAttribute(t.name),e.setAttribute(w,"")}else n&&"select"===e.tagName.toLowerCase()?(e.setAttribute(`${r}custom-select-${v}`,`$bay_select_bind(e, ${t.value})`),e.removeAttribute(t.name),e.innerHTML=`\${${t.value}.map((item)=>{return \`<option \${(()=>{return Object.entries(item).map((o)=> \`\${o[0]}="\${o[1]}"\` ).join(' ')})()}>\${item.text}</option>\`}).join('')}`,R=!0,e.setAttribute(w,"")):n&&(o||s)?(e.setAttribute(`${r}input`,`${t.value} = e.target.value`),e.removeAttribute(t.name),e.setAttribute("value",`\${${t.value}}`),e.setAttribute(w,"")):"bind:"===t.name.substring(0,5)&&(o||s)&&(e.setAttribute(`${r}${t.name.split(":")[1]}`,`${t.value} = e.target.value`),e.removeAttribute(t.name),e.setAttribute("value",`\${${t.value}}`),e.setAttribute(w,""))})),e.tagName.indexOf("-")>-1&&[...e.attributes].forEach((t=>{let n=t.value;0===n.indexOf("${")&&0===n.lastIndexOf("${")&&n.endsWith("}")&&(n=n.replace("${","${$bay.encode(JSON.stringify("),n=[...n].reverse().join(""),n=n.replace("}","}))"),n=[...n].reverse().join("")),e.setAttribute(t.name,n)}))})),R&&(window.bay.apply_select=(e,t)=>{[...e.target.options].forEach(((e,n)=>{t[n].selected?(e.selected=!0,e.setAttribute("selected","true")):(e.selected=!1,e.removeAttribute("selected"))})),e.target.onchange=e=>{[...e.target.options].forEach(((e,n)=>{e.selected?t[n].selected=!0:t[n].selected=!1}))}}),W([...t(m,"[bay-map], [bay-for]")]),m.outerHTML=m.outerHTML.replaceAll("<!--iteration","\x3c!--iteration").replaceAll("iteration-->","iteration--\x3e"),function(e){[...e.querySelectorAll("define")].forEach((e=>{e.outerHTML=e.innerHTML}))}(m),A=B,L=l}catch(K){console.error(K)}if(h){class J extends HTMLElement{constructor(){super(),this.mounted=!1,this.tmp=`${m.innerHTML}`,this.uniqid=$(8),this.CSP=!1,this.dsd=!1,this.debouncer=!1,this.prefixes=[],this.eventHandlers=new Map;const e=this.getAttribute("inner-html");if(e?t(document,e)[0]?this.inner_el=t(document,e)[0]:console.error("inner-html target "+e+" not found."):this.inner_el=this,document.addEventListener("securitypolicyviolation",(e=>{e.preventDefault(),(e.violatedDirective.indexOf("script-src")>-1||e.violatedDirective.indexOf("style-src")>-1)&&"blob"===e.blockedURI&&(console.warn("blob: needed in script-src/style-src CSP"),this.CSP=!0)})),this.shadowRoot){this.shadowDom=this.shadowRoot;const e=document.createElement("div");e.id="bay",[...this.shadowDom.children].map((t=>e.appendChild(t))),this.shadowRoot.appendChild(e),this.dsd=!0}else{this.attachShadow({mode:"open"}),this.shadowDom=this.shadowRoot;let e=document.createElement("template");e.innerHTML='<div id="bay"></div>',this.shadowDom.appendChild(e.content.cloneNode(!0))}this.shadowDom.proxy=y({},(()=>{T(this)})),this.shadowRootHTML=t(this.shadowDom,"#bay")[0],window.bay[this.uniqid]=this.shadowDom,[...l].forEach((e=>{this.shadowDom.proxy[e.att]=e.value})),window.bay[this.uniqid][i]=this,this.oldEvents="",this.shadowDom.refs=e=>{let t=[...this.shadowDom.querySelectorAll(`[ref="${e}"]`),...document.querySelectorAll(`${s} [ref="${e}"]`),...document.querySelectorAll(`#${s} [ref="${e}"]`),...this.inner_el.querySelectorAll(`[ref="${e}"]`)];if(t.length>1)return t;if(1===t.length)return t[0];{let t=document.createElement("error");return t.innerHTML=`$refs("${e}") not mounted"`,t}},A||(A="/* No script tag found */"),this.shadowDom.uniqid=this.uniqid;const r=this.getRootNode();this.parent_uniqid="",r.host&&(this.parent_uniqid=r.host.uniqid),this.update_evt=new CustomEvent(`bay_local_update_event_${this.uniqid}`);let a="";this.tmp.indexOf("/*props updates*/")>-1&&(a="let $props;\nwindow.addEventListener(`bay_local_update_event_${$bay_uniqid}`,()=>$props());\n");this.tmp.indexOf("/*slotchange updates*/")>-1&&(a="let $slotchange=()=>{};\nlet $details={'element':'','changed':''};\nwindow.addEventListener(`bay_slotchange_event_${$bay_uniqid}`,(e)=>$slotchange(e));\n"),window.bay[this.uniqid].decode=p,window.bay[this.uniqid].encode=b,window.bay.update_route=f,S&&(window.bay[this.uniqid].update_route=window.bay.update_route);let o="";C&&(o="const $prop = prop => JSON.parse($bay.decode(prop));\n"),window.bay[this.uniqid].addEventListener("slotchange",(e=>{this.local_evt=new CustomEvent(`bay_slotchange_event_${this.uniqid}`,{detail:{element:e.target,changed:"slotchange"}}),window.dispatchEvent(this.local_evt)})),t(this,"*").forEach((e=>{new MutationObserver((t=>{t.forEach((t=>{"attributes"===t.type?(this.local_evt=new CustomEvent(`bay_slotchange_event_${this.uniqid}`,{detail:{element:e,changed:"attributes"}}),window.dispatchEvent(this.local_evt)):"childList"===t.type&&(this.local_evt=new CustomEvent(`bay_slotchange_event_${this.uniqid}`,{detail:{element:e,changed:"childList"}}),window.dispatchEvent(this.local_evt))}))})).observe(e,{attributes:!0,childList:!0})}));let h=`// ${s};\n`,w="",v="",g="";N&&(w="let $bay_inner_html='';\n",v=" $bay_inner_html=''; ",g="\n$bay.inner_html=()=>{return $bay_inner_html;};");let L="";j&&(L="$bay.on=(name,callback)=>{window.addEventListener(name,e=>callback(e));};\n"),window.bay[this.uniqid].emit=window.bay.emit,window.bay[this.uniqid].receive=window.bay.receive;let _=`${L}function bay_receive_fn(e){$bay.receive($bay,$el,e.detail.name,e.detail.data);}\nwindow.removeEventListener('bay_emit',bay_receive_fn);\nwindow.addEventListener('bay_emit',bay_receive_fn);\n`;this.prefixes=[h,w,a,"",o,_];const x=this.prefixes.join("")+p(A).replace(/(^[ \t]*\n)/gm,"");let k=p(this.tmp).replace(/(^[ \t]*\n)/gm,"");P.forEach((e=>{k=k.replaceAll(e.original,e.new)})),k=k.replaceAll("\x3c!--iteration","").replaceAll("iteration--\x3e","");let q="";if(c&&(q=p(c).replaceAll('"${',"${").replaceAll("'${","${").replaceAll('}"',"}").replaceAll("}'","}").replaceAll(" ","").replaceAll("\n","")),function(e,t,n,i,r,a){__awaiter(this,void 0,void 0,(function*(){if(d.has(n))yield import(d.get(n)).then((t=>{t.default.call(window.bay[e.uniqid].proxy,e.uniqid,window.bay[e.uniqid],window.bay.global,window.bay.route,window.bay[e.uniqid].$el,window.bay[r]?window.bay[r].proxy:null,window.bay[e.uniqid].refs),M(e)}));else{const o=URL.createObjectURL(new Blob([`${a}export default function ($bay_uniqid,$bay,$global,$route,$el,$parent,$ref) {"use strict";\n${i}};`],{type:"text/javascript"}));d.set(n,o),yield import(o).then((n=>{n.default.call(window.bay[e.uniqid].proxy,e.uniqid,window.bay[e.uniqid],window.bay.global,window.bay.route,window.bay[e.uniqid].$el,window.bay[r]?window.bay[r].proxy:null,window.bay[e.uniqid].refs),M(e),t&&URL.revokeObjectURL(o)}))}}))}(this,u,s,`${x}\n${n}.template=()=>{${v}return \`${k}\`;};\n${n}.styles=()=>{return \`${q}\`;};${g}`,this.parent_uniqid,E),this.hasAdopted=!1,"adoptedStyleSheets"in document&&(this.hasAdopted=!0),this.hasAdopted)this.sheet=new CSSStyleSheet,this.sheet.replaceSync(q),this.shadowDom.adoptedStyleSheets=[this.sheet];else{const e=new Blob([q],{type:"text/css"}),t=URL.createObjectURL(e),n=document.createElement("link");n.rel="stylesheet",n.href=t,this.shadowDom.appendChild(n),n.id="bay-style";const i=document.createElement("link");i.id="bay-style-update",i.href=t,i.rel="stylesheet",this.shadowDom.appendChild(i),this.styleLinkUpdate=i}}render(){if(this.CSP)this.shadowDom.innerHTML="";else if(this.tmp&&this.shadowRootHTML.innerHTML&&"function"==typeof window.bay[this.uniqid].template)try{if(N&&function(e,n){if(!n)return;if("function"!=typeof window.bay[e].inner_html)return;window.bay[e].template();const i=H(window.bay[e].inner_html());k(i,n),O(i,n),x([...t(i,"*")],[...t(n,"*")])}(this.uniqid,this.inner_el),function(e,n){const i=H(window.bay[e].template());k(i,n),O(i,n),x([...t(i,"*")],[...t(n,"*")])}(this.uniqid,this.shadowRootHTML),q(this,N?[...t(this.inner_el,"*"),...t(this.shadowRootHTML,"*")]:[...t(this.shadowRootHTML,"*")],E,this.parent_uniqid,w),function(e){const t=window.bay[e.uniqid].styles();if(e.oldStyles!==t)if(e.oldStyles=t,e.hasAdopted)e.sheet.replaceSync(t);else{const n=new Blob([t],{type:"text/css"}),i=URL.createObjectURL(n);e.styleLinkUpdate.href=i,URL.revokeObjectURL(i)}}(this),R){const e=`[${r}custom-select-${v}]`;let n=[];n=N?[...t(this.inner_el,e),...t(this.shadowRootHTML,e)]:[...t(this.shadowRootHTML,e)],n.forEach((e=>{e.dispatchEvent(new CustomEvent(`select-${v}`))}))}!1===this.mounted&&window.bay[this.uniqid].$mounted&&(this.mounted=!0,requestAnimationFrame((()=>{window.bay[this.uniqid].$mounted()}))),t(this.shadowDom,"[bay]")[0]&&g(this.shadowDom),t(this.shadowDom,"[bay-hydrate]")[0]&&g(this.shadowDom),N&&(t(this.inner_el,"[bay]")[0]&&g(this.inner_el),t(this.inner_el,"[bay-hydrate]")[0]&&g(this.inner_el)),this.hasAttribute("fouc")&&this.removeAttribute("fouc")}catch(e){console.error(e)}}connectedCallback(){try{_&&window.addEventListener("bay_global_event",(e=>{T(this)})),S&&window.addEventListener("bay_route_event",(e=>{T(this)}))}catch(e){console.error(e)}}static get observedAttributes(){return L}attributeChangedCallback(e,t,n){t!==n&&(this.shadowDom.proxy[e]=n,window.dispatchEvent(this.update_evt))}}customElements.define(h,J)}else console.error("Something went wrong loading file "+o+".")}window.addEventListener("load",(()=>{g(document)})),bay.refresh=()=>{g(document)},window.bay.refresh=bay.refresh,bay.create=function(e,t,n){const i=new DOMParser,r=n||[];for(t=A(t=(t=E(t)).replaceAll(/<!--[\s\S]*?-->/g,"")),c="";t.indexOf("<style>")>-1;){const e=t.split("<style>")[1].split("</style>")[0];t=t.replaceAll(`<style>${e}</style>`,""),c+=e}t='<div id="bay-temporary-compile-element"></div>'+t;let a=i.parseFromString(t,"text/html");function o(){a&&0===[...a.querySelectorAll("include")].length&&(customElements.get(e.toLowerCase())||R(a,e.toLowerCase(),r,c,!0))}a.getElementById("bay-temporary-compile-element").remove(),L(a,o),o()},window.bay.create=bay.create};export default bay;