forked from Dunks1980/bay.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbay.min.js
1 lines (1 loc) · 22.7 KB
/
bay.min.js
1
var __awaiter=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(a,o){function r(e){try{l(i.next(e))}catch(e){o(e)}}function s(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,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="data-bay-",i="this-attribute";let a="",o=[],r=[],s=new Map,l="";!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 d=document.createElement("textarea");function c(e){return"string"==typeof e?(d.textContent=e,d.innerHTML.replaceAll('"',""").replaceAll("'","'")):e}function u(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}function h(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,c(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,c(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(c(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(c(n)),t&&t(),e}:["has","delete"].includes(n)?function(...t){return e[n].apply(e,t)}:e[n]})}(i,t):e[n]=h(i,t)),e[n]):void 0},set:(e,n,i)=>(e[n]=c(i),t&&t(),!0)})}let b,w;function y(){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 p(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,`[data-bay-${i}]`),...t(n,`[data-bay-${i}]`),...t(document,`[data-bay-${i}]`)].forEach((e=>{e.dispatchEvent(new CustomEvent(i,{detail:{name:i,data:a}}))}))},window.bay.global=h({},(()=>{b&&window.cancelAnimationFrame(b),b=window.requestAnimationFrame((()=>{window.dispatchEvent(new CustomEvent("bay_global_event"))}))})),window.bay.route=h({},(()=>{w&&window.cancelAnimationFrame(w),w=window.requestAnimationFrame((()=>{window.dispatchEvent(new CustomEvent("bay_route_event"))}))})),y(),window.addEventListener("popstate",(()=>{y()})),window.bay.router=function(e,t){const n=t.split("/"),i=e.split("/");let a=!0,o={};for(let e=0;e<n.length;e++)if(":"===n[e][0])o[n[e].slice(1)]=i[e];else if("*"!==n[e]&&n[e]!==i[e]){a=!1;break}return!!a&&o};const m=p(8);function f(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===o.indexOf(e.getAttribute("bay")||"")&&o.push(e)})),o.forEach((e=>{-1===r.indexOf(e.getAttribute("bay"))&&function(e){try{const n=e.getAttribute("bay")||"";let i=e.tagName.toLowerCase();if("template"===i)g(u(e.innerHTML),e,n),e.remove();else if("dsd-"===n.substring(0,4))a=n,e.shadowRoot?g(u(e.shadowRoot.innerHTML),e,i):(g(u(t(e,"template")[0].innerHTML),e,i),t(e,"template")[0].remove());else if("#"===n.substring(0,1)){a=n;const o=t(document,n)[0];if(!o)return;g(o.innerHTML,e,i),o.remove()}else fetch(n).then((e=>e.text())).then((t=>{g(t,e,i)})).catch((e=>{}))}catch(e){}}(e),r.push(e.getAttribute("bay"))}))}function $(t){return e?(Object.entries(e).forEach((([e,n])=>{if("string"==typeof n){let i=`%{${e}}`;t=t.replaceAll(i,n)}})),t):t}function v(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.indexOf("<style>")>-1;){const e=n.split("<style>")[1].split("</style>")[0];n=n.replaceAll(`<style>${e}</style>`,""),l+=e}n=n.replaceAll(/<!--[\s\S]*?-->/g,""),e.outerHTML=n,t()})).catch((e=>{}))}))}function g(e,n,i){const a=new DOMParser,o="export default /*HTML*/`";let r;for(e=$(e=e.replaceAll(/<!--[\s\S]*?-->/g,"")),l="",e.startsWith(o)&&(e=(e=(e=(e=e.trim()).split(o)[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>`,""),l+=t}function s(){r&&0===[...r.querySelectorAll("include")].length&&(customElements.get(i)||C(r,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),l,!1))}e='<div id="bay-temporary-compile-element"></div>'+e,r=a.parseFromString(e,"text/html"),r.getElementById("bay-temporary-compile-element").remove(),v(r,s),s()}function E(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),H(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),H(a,e.nodeName)&&a[e.nodeName]!==e.value&&(a[e.nodeName]=e.value)}))),!e.hasAttribute("data-bay-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 _(e,t,i,a){t&&(e.newEvents="",t.forEach(((t,i)=>{[...t.attributes].forEach((a=>function(e,t,i,a){let o=t.name;if(o.startsWith(":")){let e=o.split(":")[1];o=o.replace(`:${e}`,`data-bay-${e}`)}if(o.indexOf(n)>-1){if(o.indexOf("-custom-")>-1&&(o=o.replace("custom-","")),o.indexOf("data-bay-style")>-1)i.style!==t.value&&(i.style=t.value);else{const r=t.value.replaceAll("window.bay","$bay");-1===e.newEvents.indexOf("$bay.events=new Map();\n")&&(e.newEvents+="$bay.events=new Map();\n"),e.newEvents+=`$bay.events.set('${o}-${a}',(e)=>{${r}});\n`;const s=t=>{window.bay[e.uniqid].events&&window.bay[e.uniqid].events.has(`${o}-${a}`)&&window.bay[e.uniqid].events.get(`${o}-${a}`)(t)},l=`${e.uniqid}${a}${o}`,d=o.split(n)[1];e.eventHandlers.has(l)&&(i.removeEventListener(d,e.eventHandlers.get(l)),e.eventHandlers.delete(l)),e.eventHandlers.set(l,s),i.addEventListener(d,e.eventHandlers.get(l))}}}(e,a,t,i)))})),e.newEvents&&e.oldEvents!==e.newEvents&&(e.oldEvents=e.newEvents,function(e,t,n,i){__awaiter(this,void 0,void 0,(function*(){const a=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(a)).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(a)}))}(e,e.newEvents,i,a)))}function L(e){e.debouncer&&window.cancelAnimationFrame(e.debouncer),e.debouncer=window.requestAnimationFrame((()=>{e.render()}))}function A(e){e.dsd||(e.tmp=window.bay[e.uniqid].template(),e.shadowDom.getElementById("bay").innerHTML=e.tmp),L(e),e.CSP?e.shadowDom.innerHTML="CSP issue, add blob: to script-src & style-src whitelist.":t(e.shadowDom,"[bay]")[0]&&f(e.shadowDom)}function x(e){return(new DOMParser).parseFromString(e,"text/html").body}function q(e){return 3===e.nodeType?"text":8===e.nodeType?"comment":e.tagName.toLowerCase()}function M(e){return e.childNodes&&e.childNodes.length>0?null:e.textContent}function T(e,t){const n=[...t.childNodes],i=[...e.childNodes];let a=n.length-i.length;if(a>0)for(;a>0;a--)n[n.length-a].parentNode.removeChild(n[n.length-a]);i.forEach(((e,i)=>{if(!n[i])return void t.appendChild(e.cloneNode(!0));if(q(e)!==q(n[i])){try{n[i].parentNode.replaceChild(e.cloneNode(!0),n[i])}catch(e){}return}const a=M(e);if(a&&a!==M(n[i])&&(n[i].textContent=a),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 T(e,t),void n[i].appendChild(t)}e.childNodes.length>0&&T(e,n[i])}}))}function H(e,t){return void 0!==e[t]&&"object"!=typeof e[t]}function C(e,n,a,o,r){let l="",d=null,b="",w="",$=[],v=!1,g=!1,q=!1,M=!1,H=!1,C=[];try{o="*:not(:defined){opacity:0;max-width:0px;max-height:0px}*:not(:defined)*{opacity:0;max-width:0px;max-height:0px}.bay-hide{display:none}"+(o||""),d=e.body,l=n;const r=document.createElement(`${n}-update`);d.appendChild(r),(d.innerHTML.indexOf("$global.")>-1||d.innerHTML.indexOf("$global[")>-1)&&(v=!0),(d.innerHTML.indexOf("$route.")>-1||d.innerHTML.indexOf("$route[")>-1||d.innerHTML.indexOf("</router>")>-1||d.innerHTML.indexOf("</route>")>-1||d.innerHTML.indexOf("$bay.update_route")>-1)&&(g=!0),d.innerHTML.indexOf("</route>")>-1&&(o=(o||"")+"[bay-route]>*{pointer-events:none}"),d.innerHTML.indexOf("$bay.on(")>-1&&(H=!0),d.innerHTML.indexOf("</show>")>-1&&bay.create(`show-${m}`,"<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>",["open","transition"]);const s="element, index, array";let c="";const u=(e,n)=>{if(!t(e,n)[0]){const i=e.getAttribute("array")||[],a=e.getAttribute("params")||s,o=e.getAttribute("join")||"",r=e.getAttribute("duration")||!1,l=[...e.attributes][0]?[...e.attributes][0].nodeValue:"",u=e.nextElementSibling?e.nextElementSibling.tagName.toLowerCase():"";let h="`}return ''})()}";const b=e.hasAttribute("break")?"break;":"",y=0===e.innerHTML.length,f=e.attributes.length?e.attributes[0].name:"",$=`<${n}>`,v=`</${n}>`,g=[...e.attributes];!function(e){for(;e.attributes.length>0;)e.removeAttribute(e.attributes[0].name)}(e);let E=e.outerHTML;const _=(t,n)=>{e.outerHTML=E.replace($,t).replace(v,n)};switch(n){case"dsd":e.remove();break;case"noscript":d.innerHTML=d.innerHTML.replaceAll($,"").replaceAll(v,"");break;case"map":_(`\${ ${i}.${n}((${a})=>{return \``,`\`}).join('${o}')}`);break;case"for":const s=`bay_${n}_${p(8)}`;i.length?_(`\${(()=>{let ${s}='';${i}.forEach((${a})=>{${s}+=\``,`\`});return ${s};})()}`):_(`\${(()=>{let ${s}=''; ${n} (${l}) { ${s} += \``,`\`};return ${s};})() }`);break;case"if":"else-if"!==u&&"else"!==u||(h="`}"),_(`\${(()=>{ ${n} (${l}) {return \``,h);break;case"else-if":"else-if"!==u&&"else"!==u||(h="`}"),_(` else if (${l}) {return \``,h);break;case"else":_(` ${n} {return \``,h);break;case"show":r?_(`<show-${m} class="bay-show" open="\${${l}}" transition="${r} ease-in-out">`,`</show-${m}>`):_(`<div class="\${(${l})?'bay-show':'bay-show bay-hide'}">`,"</div>");break;case"switch":_(`\${(()=>{let bay_switch=''; ${n} (${l}) { `," };return bay_switch;})() }");break;case"case":y?_(`${n} ${l}:`," "+b):_(`${n} ${l}: bay_switch += \``,"`; "+b);break;case"default":_(`${n}: bay_switch += \``,"`;");break;case"inner-html":q=!0,_("${ (()=>{$bay_inner_html+=`","`;return ''})()}"),e.remove();break;case"route":let L="";g.forEach((e=>{L+=` ${e.name}="${e.value}"`})),_(`<a bay-route :click="e.preventDefault();history.pushState({},'',e.target.getAttribute('href'));window.bay.update_route();"${L}>`,"</a>");break;case"router":_(`\${(()=>{let $path=window.bay.router(window.bay.route.path,'${l}');if($path){return \``,h);break;case"script":switch(f){case"imports":w+=e.innerText.trim()+"\n",e.remove();break;case"update":_("${/*update*/(()=>{setTimeout(()=>{","}, 0);return ``})()}");break;case"props":_("${/*props updates*/(()=>{$props=()=>{","};return ``})()}");break;case"render":_("${/*render*/(()=>{","})()}");break;case"slotchange":_("${/*slotchange updates*/(()=>{$slotchange=(e)=>{$details=e.detail;\n","};return ``})()}");break;case"mounted":c+=`$bay['$mounted']=()=>{${e.innerText}};`,e.remove();break;default:const i=t(d,n)[0];c+=i.innerText,e.remove();break}e&&e.parentNode&&(e.outerHTML=E,e.remove());break}}};["dsd","noscript","map","for","if","else-if","else","show","switch","case","default","inner-html","route","router","script"].forEach((e=>{for(;[...t(d,e)].length>0;){[...t(d,e)].forEach((t=>u(t,e)))}})),[...t(d,"*")].forEach((e=>{[...e.attributes].forEach((t=>{const n="bind"===t.name,a="custom:"===t.name.substring(0,7),o="input"===e.tagName.toLowerCase(),r="textarea"===e.tagName.toLowerCase();if(function(e,t){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===i){let e=`this-attribute="${t.value}"`;C.push({original:e,new:`\${(() => {return ${t.value} || ''})()}`})}if(":"===t.name.substring(0,1)||a){let n="";a&&(n="custom-"),e.setAttribute(`data-bay-${n}${t.name.split(":")[1]}`,t.value),e.removeAttribute(t.name)}else n&&"select"===e.tagName.toLowerCase()?(e.setAttribute(`data-bay-custom-select-${m}`,`$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('')}`,M=!0):n&&(o||r)?(e.setAttribute("data-bay-input",`${t.value} = e.target.value`),e.removeAttribute(t.name),e.setAttribute("value",`\${${t.value}}`)):"bind:"===t.name.substring(0,5)&&(o||r)&&(e.setAttribute(`data-bay-${t.name.split(":")[1]}`,`${t.value} = e.target.value`),e.removeAttribute(t.name),e.setAttribute("value",`\${${t.value}}`))}))})),M&&(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}))}}),b=c,$=a}catch(e){}if(l){class e extends HTMLElement{constructor(){super(),this.mounted=!1,this.tmp=`${d.innerHTML}`,this.uniqid=p(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]):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&&(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=h({},(()=>{L(this)})),this.shadowRootHTML=t(this.shadowDom,"#bay")[0],window.bay[this.uniqid]=this.shadowDom,[...a].forEach((e=>{this.shadowDom.proxy[e.att]=e.value})),window.bay[this.uniqid].$el=this,this.oldEvents="",this.shadowDom.refs=e=>{let t=[...this.shadowDom.querySelectorAll(`[ref="${e}"]`),...document.querySelectorAll(`${n} [ref="${e}"]`),...document.querySelectorAll(`#${n} [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}},b||(b="/* No script tag found */"),this.shadowDom.uniqid=this.uniqid;const i=this.getRootNode();this.parent_uniqid="",i.host&&(this.parent_uniqid=i.host.uniqid),this.update_evt=new CustomEvent(`bay_local_update_event_${this.uniqid}`);let l="";this.tmp.indexOf("/*props updates*/")>-1&&(l="let $props;\nwindow.addEventListener(`bay_local_update_event_${$bay_uniqid}`,()=>$props());\n");this.tmp.indexOf("/*slotchange updates*/")>-1&&(l="let $slotchange=()=>{};\nlet $details={'element':'','changed':''};\nwindow.addEventListener(`bay_slotchange_event_${$bay_uniqid}`,(e)=>$slotchange(e));\n"),window.bay[this.uniqid].decode=u,window.bay[this.uniqid].encode=c,window.bay.update_route=y,g&&(window.bay[this.uniqid].update_route=window.bay.update_route),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 m="",f="",$="";q&&(m="let $bay_inner_html='';\n",f=" $bay_inner_html=''; ",$="\n$bay.inner_html=()=>{return $bay_inner_html;};");let v="";H&&(v="$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 E=`${v}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=[m,l,"",E];const _=this.prefixes.join("")+u(b).replace(/(^[ \t]*\n)/gm,"");let x=u(this.tmp).replace(/(^[ \t]*\n)/gm,"");C.forEach((e=>{x=x.replaceAll(e.original,e.new)}));let M="";if(o&&(M=u(o).replaceAll('"${',"${").replaceAll("'${","${").replaceAll('}"',"}").replaceAll("}'","}").replaceAll(" ","").replaceAll("\n","")),function(e,t,n,i,a,o){__awaiter(this,void 0,void 0,(function*(){if(s.has(n))yield import(s.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[a]?window.bay[a].proxy:null,window.bay[e.uniqid].refs),A(e)}));else{const r=URL.createObjectURL(new Blob([`${o}export default function ($bay_uniqid,$bay,$global,$route,$el,$parent,$ref) {"use strict";\n${i}};`],{type:"text/javascript"}));s.set(n,r),yield import(r).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[a]?window.bay[a].proxy:null,window.bay[e.uniqid].refs),A(e),t&&URL.revokeObjectURL(r)}))}}))}(this,r,n,`${_}\n$bay.template=()=>{${f}return \`${x}\`;};\n$bay.styles=()=>{return \`${M}\`;};${$}`,this.parent_uniqid,w),this.hasAdopted=!1,"adoptedStyleSheets"in document&&(this.hasAdopted=!0),this.hasAdopted)this.sheet=new CSSStyleSheet,this.sheet.replaceSync(M),this.shadowDom.adoptedStyleSheets=[this.sheet];else{const e=new Blob([M],{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(q&&function(e,n){if(!n)return;if("function"!=typeof window.bay[e].inner_html)return;window.bay[e].template();const i=x(window.bay[e].inner_html());T(i,n),E([...t(i,"*")],[...t(n,"*")])}(this.uniqid,this.inner_el),function(e,n){const i=x(window.bay[e].template());T(i,n),E([...t(i,"*")],[...t(n,"*")])}(this.uniqid,this.shadowRootHTML),_(this,q?[...t(this.inner_el,"*"),...t(this.shadowRootHTML,"*")]:[...t(this.shadowRootHTML,"*")],w,this.parent_uniqid),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),M){const e=`[data-bay-custom-select-${m}]`;let n=[];n=q?[...t(this.inner_el,e),...t(this.shadowRootHTML,e)]:[...t(this.shadowRootHTML,e)],n.forEach((e=>{e.dispatchEvent(new CustomEvent(`select-${m}`))}))}!1===this.mounted&&window.bay[this.uniqid].$mounted&&(this.mounted=!0,requestAnimationFrame((()=>{window.bay[this.uniqid].$mounted()}))),t(this.shadowDom,"[bay]")[0]&&f(this.shadowDom),t(this.shadowDom,"[bay-hydrate]")[0]&&f(this.shadowDom),q&&(t(this.inner_el,"[bay]")[0]&&f(this.inner_el),t(this.inner_el,"[bay-hydrate]")[0]&&f(this.inner_el)),this.hasAttribute("fouc")&&this.removeAttribute("fouc")}catch(e){}}connectedCallback(){try{v&&window.addEventListener("bay_global_event",(e=>{L(this)})),g&&window.addEventListener("bay_route_event",(e=>{L(this)}))}catch(e){}}static get observedAttributes(){return $}attributeChangedCallback(e,t,n){t!==n&&(this.shadowDom.proxy[e]=n,window.dispatchEvent(this.update_evt))}}customElements.define(l,e)}}window.addEventListener("load",(()=>{f(document)})),bay.refresh=()=>{f(document)},window.bay.refresh=bay.refresh,bay.create=function(e,t,n){const i=new DOMParser,a=n||[];for(t=$(t=t.replaceAll(/<!--[\s\S]*?-->/g,"")),l="";t.indexOf("<style>")>-1;){const e=t.split("<style>")[1].split("</style>")[0];t=t.replaceAll(`<style>${e}</style>`,""),l+=e}t='<div id="bay-temporary-compile-element"></div>'+t;let o=i.parseFromString(t,"text/html");function r(){o&&0===[...o.querySelectorAll("include")].length&&(customElements.get(e.toLowerCase())||C(o,e.toLowerCase(),a,l,!0))}o.getElementById("bay-temporary-compile-element").remove(),v(o,r),r()},window.bay.create=bay.create};bay();