/* dlite v0.19.0 */
const t=(t,e,n)=>{let r=t;const o=e.split(".");for(;o.length;){const t=o.shift();r[t]=o.length?r[t]?r[t]:{}:n,r=r[t]}},e=(t,e)=>e.split(".").reduce(((t,e)=>t&&t[e]),t),n=t=>"function"==typeof t,r=(t,e)=>t&&n(t[e]),o=t=>{const e=(new DOMParser).parseFromString(t,"text/html");return{head:e.head,body:e.body}},i=[["&lt;","<"],["&gt;",">"],["&amp;","&"]],s=(t,e=!1)=>Object.freeze(Array.from(t.attributes).map((t=>{return{[e?(n=t.name,n.replace(/[-_\s+]([a-z])/g,(t=>t[1].toUpperCase()))):t.name]:t.value};var n})).reduce(((t,e)=>({...t,...e})),{})),l=(t,e)=>{let n=!1,r=!1;const o=new WeakMap,i=()=>{n?r||(r=!0):e()},s={get(t,e,n){if("#"===e)return t;const r=Reflect.get(t,e,n);if((t=>null===t||!["function","object"].includes(typeof t))(r)||"constructor"===e)return r;const i=((t,e)=>{let n=o.get(t);if(n)return n;n=new Map,o.set(t,n);let r=n.get(e);return r||(r=Reflect.getOwnPropertyDescriptor(t,e),n.set(e,r)),r})(t,e);if(i&&!i.configurable){if(i.set&&!i.get)return;if(!1===i.writable)return r}return new Proxy(r,s)},set(t,e,n,r){n&&void 0!==n["#"]&&(n=n["#"]);const o=Reflect.get(t,e,r),s=Reflect.set(t,e,n);return o!==n&&i(),s},defineProperty(t,e,n){const r=Reflect.defineProperty(t,e,n);return i(),r},deleteProperty(t,e){const n=Reflect.deleteProperty(t,e);return i(),n},apply(t,o,i){if(!n){n=!0;const s=Reflect.apply(t,o,i);return r&&e(),n=r=!1,s}return Reflect.apply(t,o,i)}};return new Proxy(t,s)};function c(t){return null===t||"object"!=typeof t?t:(Object.keys(t).forEach((function(e){const n=t[e];null!==n&&"object"==typeof n&&c(n)})),Object.freeze(t))}const a=t=>c(function(t){if(null===t||"object"!=typeof t)return t;var e=t.constructor();for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=a(t[n]));return e}(t)),u=[];for(const t in document){const e=null===document[t]||n(document[t]);t.startsWith("on")&&e&&u.push(t.substring(2))}const d="dl--elist",f=t=>`dl--on-${t}`;function h(t){const e={};for(let n=0;n<t.childNodes.length;n++){const r=t.childNodes[n].id;r&&(e[r]=t.childNodes[n])}return e}function p(t,e){if("string"==typeof e){const n=e;(e=document.createElement(t.tagName)).innerHTML=n}const n={old:h(t),new:h(e)};let r;for(r=0;e.firstChild;r++){const o=e.removeChild(e.firstChild);if(r>=t.childNodes.length){t.appendChild(o);continue}let i=t.childNodes[r];const l=o.id;if(i.id||l){const e=l&&l in n.old?n.old[l]:o;e!==i&&(i=t.insertBefore(e,i))}if(i.nodeType!==o.nodeType||i.tagName!==o.tagName)t.replaceChild(o,i);else if([Node.TEXT_NODE,Node.COMMENT_NODE].indexOf(i.nodeType)>=0){if(i.textContent===o.textContent)continue;i.textContent=o.textContent}else if(i!==o){const t={base:s(i),new:s(o)};for(const e in t.base)e in t.new||i.removeAttribute(e);for(const e in t.new)e in t.base&&t.base[e]===t.new[e]||i.setAttribute(e,t.new[e]);p(i,o)}}for(;t.childNodes.length>r;)t.removeChild(t.lastChild);return!0}const b={$key:function(t,e,n){t.setAttribute("ref-key",e),$(t,n)},$class:function(t,e,n){const r=e.split(";").map((t=>t.split(":",2).map((t=>t.trim())))).map((t=>`\${${t[1]} ? '${t[0]}': ''}`)).join(" "),o=(t.getAttribute("class")||"")+` ${r}`;t.setAttribute("class",o),$(t,n)},$style:function(t,e,n){const r=t.getAttribute("style")||"",o=`\${function() { return this.__$styleMap(${e});}.call(this)}`;t.setAttribute("style",(r?r+"; ":"")+o),$(t,n)},$for:function(t,e,n){const r=/(.*)\s+(in)\s+(.*)$/.exec(e);if(4===r.length){const e=r[1].replace("(","").replace(")",""),o=r[3];w(t,`\${${o}.map(function(${e}) { return \``,"`}.bind(this)).join('')}"),$(t,n)}},$if:function(t,e,n){$(t,n),v(t,`\${${e} ? `);const r=t.nextElementSibling;r&&y(r,"else")?(w(t,"`","`"),$(r,"else"),w(r,":`","`}")):w(t,"`","`:``}")},$text:function(t,e,n){t.textContent=e,$(t,n)}},m=t=>`:${t}`,y=(t,e)=>t.hasAttribute(m(e)),g=(t,e)=>t.getAttribute(m(e)),$=(t,e)=>t.removeAttribute(m(e)),A=(t,e)=>t.querySelectorAll(`[\\${m(e)}]`),v=(t,e)=>t.insertAdjacentText("beforebegin",e),w=(t,e,n)=>{v(t,e),((t,e)=>{t.insertAdjacentText("afterend",e)})(t,n)};const x=["data","el","shadowDOM","template","created","updated","removed","$store","prop","tagName"],M=t=>Object.keys(t).filter((t=>!x.includes(t))).filter((t=>!t.startsWith("$"))).filter((e=>r(t,e))).reduce(((e,n)=>({...e,[n]:t[n]})),{}),N=t=>Object.keys(t).filter((e=>!r(t,e))).reduce(((e,n)=>({...e,[n]:t[n]})),{}),j=t=>Object.keys(t).filter((e=>r(t,e))).map((e=>{return n=e,r=t[e],t=>t[n]=r({...t});var n,r})),E=t=>Object.keys(t).filter((t=>t.startsWith("$"))).filter((t=>!x.includes(t))).reduce(((e,n)=>({...e,[n]:t[n]})),{}),O=t=>e=>(e.$store=t.getState(),t.subscribe((n=>e.$store={...t.getState()}))),T=(t,e,n)=>{Object.keys(e).filter((t=>!t.startsWith("_"))).map((r=>t[r]=e[r].bind(n)))},k=t=>{const{head:e,body:n}=o(t);!function(t,e={}){const n={...e,...b};for(const e in n){const r=e.replace("$","");for(const o of A(t,r))if(y(o,r)){const t=g(o,r);n[e](o,t,r)}}}(n),function(t){for(const e of t.querySelectorAll("[\\@call], [\\@bind]")){let t=e.getAttribute("@call");e.removeAttribute("@call"),e.hasAttribute("@bind")&&(e.setAttribute("dl--bind",e.getAttribute("@bind")),e.removeAttribute("@bind"),t="__$bindInput");let n=["click"];e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?n=["input","paste"]:e instanceof HTMLSelectElement?n=["change"]:e instanceof HTMLFormElement?n=["submit"]:e instanceof HTMLAnchorElement&&e.setAttribute("href","javascript:void(0);");let r=(e.getAttribute(d)||"").split(",").filter((t=>t));r=r.concat(n),e.setAttribute(d,r.join(","));for(const r of n)e.setAttribute(f(r),t)}for(const e of u)for(const n of t.querySelectorAll(`[\\@${e}]`)){const t=(n.getAttribute(d)||"").split(",").filter((t=>t));t.push(e),n.setAttribute(d,t.join(",")),n.setAttribute(f(e),n.getAttribute(`@${e}`)),n.removeAttribute(`@${e}`),n instanceof HTMLAnchorElement&&n.setAttribute("href","javascript:void(0);")}}(n);let r=(t=>t.replace(/\$?\{([^\;\{]+)\}/g,((t,e)=>`\${typeof ${e} != 'undefined' ? ${e} : ''}`)))((s=n.innerHTML,i.reduce(((t,e)=>t.replace(new RegExp(e[0],"g"),e[1])),s)));var s;e.querySelectorAll('style, link[rel="stylesheet"]').forEach((t=>{r+=t.outerHTML}));const l=(c=r,t=>new Function(`return \`${c}\``).call(t));var c;return{html:r,render:(t,e)=>{const{head:n,body:r}=o(l(e));return r.append(...n.querySelectorAll("style, link")),!t.isEqualNode(r)&&p(t,r)}}};function C(n){const r=n.target,o=r.getAttribute("ld--bind");if("checkbox"===r.type){const n=e(this.data,o)||[];t(this.data,o,r.checked?n.concat(r.value):n.filter((t=>t!=r.value)))}else r.options&&r.multiple?t(this.data,o,[].reduce.call(r,((t,e)=>e.selected?t.concat(e.value):t),[])):t(this.data,o,r.value)}const _={__$styleMap:t=>Object.keys(t).map((e=>{return`${n=e,n.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}: ${t[e]};`;var n})).join(" ")};function S(t={}){return function(t){let n=null;const r=O(t.$store),o=k(t.template),i=M(t),c=N(t.data),u=j(t.data),h=E(t),p=t=>u.forEach((e=>e(t)));return window.customElements.define(t.tagName.toLowerCase(),class extends HTMLElement{constructor(){super(),this.style.visibility=this.style.visibility?this.style.visibility:"hidden",this.$root=t.shadowDOM?this.attachShadow({mode:"open"}):this,n=this}render(e=!1){p(this._state),o.render(this.$root,{...this._state,..._})&&!e&&t.updated.call(this.context),"hidden"===this.style.visibility&&this.style.removeProperty("visibility")}connectedCallback(){if(!this.isConnected)return;this._state={...this._state,...c,prop:s(this,!0),...i};const n=l(this._state,this.render.bind(this));this.disconnectStore=r(n),this.$root.innerHTML=o.html,this.context={...i,...h,data:n,el:this.$root,prop:this._state.prop,$store:t.$store},function(t,n){function r(t){Array.from(t.querySelectorAll(`[${d}]`)).map((t=>{(t.getAttribute(d)||"").split(",").filter((t=>t)).map((e=>{t[`on${e}`]=r=>{r.preventDefault();const o=t.getAttribute(f(e));n[o].call(n,r)}}))}))}Array.from(t.querySelectorAll("[dl--bind]")).map((t=>{const r=e(n.data,t.getAttribute("dl--bind"));try{"INPUT"===t.tagName&&["radio","checkbox"].includes(t.type)?r.includes(t.value)&&(t.checked=!0):t.value=r}catch(t){}}));const o=new MutationObserver((t=>{[...t].filter((t=>t.addedNodes.length>0)).map((t=>t.target)).map((t=>r(t)))}));o.observe(t,{attributes:!0,childList:!0,subtree:!0}),r(t)}(this.$root,{...this.context,__$bindInput:C}),T(this,i,this.context),T(this._state,i,this.context),this.render(!0),t.created.call(this.context)}disconnectedCallback(){t.removed.call(this.context),this.disconnectStore()}get data(){return a(this._state)}}),n}({shadowDOM:!0,tagName:null,data:{},template:null,$store:{getState:()=>{},subscribe:()=>()=>{}},created(){},updated(){},removed(){},...t})}async function L(t){return await fetch(t).then((t=>{if(t.status>=400)throw new Error(`${t.url} (${t.status})`);return t})).then((t=>(t.headers.get("content-type")||"").includes("json")?t.json():t.text()))}function H(t,e={},n=""){const r=document.createElement(t);r.innerHTML=n;for(const[t,n]of Object.entries(e))r.setAttribute(t,n);return r}var P=(t,e={})=>(Array.isArray(t)||(t=[t]),t.map(((t,n)=>{try{return function(t){const e={el:null,template:null,tagName:null,shadowDOM:!0,debug:!1,...t},n=!e.tagName;if(e.tagName=e.tagName||`dlite-${Math.random().toString(36).substring(2,9).toLowerCase()}`,e.el){if("string"==typeof e.el){const t=document.querySelector(e.el);if(!t)throw new Error(`'${e.el}' could not be found.`);e.el=t}if(e.template||(e.template=e.el.innerHTML),e.el.innerHTML="",n){const t=H(e.tagName,s(e.el));for(const[n,r]of Object.entries(s(e.el)))t.setAttribute(n,r);e.el.parentNode.replaceChild(t,e.el)}}else if(!e.el&&n)throw new Error("Missing either 'el' or 'tagName' setting.");if(!e.template)throw new Error("Missing 'template' setting.");return S(e)}({...e,...t})}catch(r){if(!e.debug&&!t.debug)throw r;{const t=H("div",{style:"background-color: red; color: white; padding: 10px;"},`\n<h1>#${n+1}</h1>\n${r}\n<details>\n  <summary>Stacktrace</summary>\n  ${r.stack.replaceAll("\n","<br>")}\n</details>`);document.body.prepend(t),console.error(r)}}})));export{P as default,L as fetcher};
