+"use strict";var w=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var q=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},B=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of F(e))!V.call(t,o)&&o!==r&&w(t,o,{get:()=>e[o],enumerable:!(i=P(e,o))||i.enumerable});return t};var W=t=>B(w({},"__esModule",{value:!0}),t);var te={};q(te,{app:()=>M,component:()=>Z,computed:()=>G,hasWindow:()=>ee,mapper:()=>O,ref:()=>Q,render:()=>J,state:()=>z,store:()=>X,styler:()=>U,valueOf:()=>Y});module.exports=W(te);var N=()=>{let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e="",r=t.length;for(let i=0;i<10;i++)e+=t.charAt(Math.floor(Math.random()*r));return e},K=N(),v=t=>{K=t};var R=t=>t.map(e=>JSON.stringify(Object.hasOwn(e,"get")&&e.get())).join(""),I=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();var E=t=>{let e="",r=!1,i={},o=s=>{},f=()=>{let s=document.querySelector(`[data-nice-id="${e}"]`);!s||r||(r=!0,setTimeout(()=>{let n=o(e);n&&s.replaceWith(n.children[0]),r=!1},0))};return(s,n)=>(e=N(),v(e),i=s??{},o=t(i,n),{id:e,type:"component",properties:s,render:o,markDirty:f,key:n??e})};var M=(t,e)=>{let r=E(t)();if(e&&typeof window<"u"){let i=e?document.querySelector(e):void 0;if(!i)throw new Error(`Failed to attach - Element "${e}" not found in the DOM.`);r.markDirty=()=>{let o=r.render(N());if(o){for(;i.firstChild;)i.removeChild(i.firstChild);window?Array.from(o.hydrate().children).forEach(f=>{i.appendChild(f)}):i.innerHTML=o.html}},r.markDirty()}else return{html:r.render("nice-app-root").html,id:"nice-app-root",hydrate:i=>{let o=document.querySelector(`#${i}`);if(!o)throw new Error(`Failed to attach - Element "${e}" not found in the DOM.`);r.markDirty=()=>{let f=r.render(N());if(f){for(;o.firstChild;)o.removeChild(o.firstChild);window?Array.from(f.hydrate().children).forEach(m=>{o.appendChild(m)}):o.innerHTML=f.html}},r.markDirty()}}};var L=(t,...e)=>o=>{let f=`<!-- ${o} BEGIN -->`,m=`<!-- ${o} END -->`,s="",n={},a={};t.forEach((p,l)=>{let d=e[l];if(s+=p,d===void 0)return;let u=j(p),c=Math.random().toString(36).substring(7);if(typeof d!="object"){u&&!p.endsWith('"')?s+=`"${d}"`:s+=d;return}switch(d.type){case"component":s+=c,n[c]=d.render(d.id);break;case"state":s+=c,a[c]=d;break}}),Object.keys(n).forEach(p=>{s=s.replace(p,n[p].html.replace(/(<.+)( )/,`$1 data-reattach-child="${p}" `))}),Object.keys(a).forEach(p=>{let l=s.split(p)[0],d=j(l),u=a[p].get(),c=u,g=1;if(u)if(typeof u=="object"&&u.type==="component"){let T=u;c=T.render(T.id).html}else Array.isArray(u)&&(g=u.length,c=u.map(T=>{if(typeof T=="object"&&T.type==="component"){let b=T;return b.render(b.id).html}else return T}).join(""));let k=d?`"${c||""}" data-bind-${d}="${p}"`:`<!-- @ --><span data-reattach-state="${p}" data-reattach-extras="${!!c&&g}"></span>${c}<!-- # -->`;s=s.replace(p,k)});let y=()=>{let p=_(s);return p.children[0].setAttribute("data-nice-id",o),Object.keys(a).forEach(l=>{p.querySelectorAll(`[data-reattach-state="${l}"]`).forEach(d=>{let u=d.getAttribute("data-reattach-extras");if(u&&u!=="false")for(let g=0;g<parseInt(u);g++)d.nextSibling?.remove();let c=a[l].get();a[l].markers.push([d.previousSibling,d.nextSibling]),S(c,d.previousSibling,d.nextSibling)})}),Object.keys(n).forEach(l=>{p.querySelectorAll(`[data-reattach-child="${l}"]`).forEach(d=>{d.replaceWith(n[l].hydrate().children[0])})}),p.querySelectorAll("*").forEach(l=>{Array.from(l.attributes).forEach(d=>{let u=d.name.match(/data-bind-(.+)$/);if(u){let c=u[1].trim(),g=d.value,k=c.startsWith("on-"),T=c.startsWith("set-"),b=c==="ref",h=a[g];if(!h)return;h.attributes[c]||(h.attributes[c]=[]),k?(l.removeAttribute(c),l.addEventListener(c.slice(3),C=>h.set(C))):T?(l.removeAttribute(c),h.listen(C=>{l[c.slice(4)]=C}),l[c.slice(4)]=h.get()):b?(l.removeAttribute(c),h.set(l)):(h.attributes[c].push(l),l.setAttribute(c,h.get()??"")),l.removeAttribute(d.name)}})}),p};return{html:s.trim(),hydrate:y}},S=(t,e,r)=>{let i=[],o=e.nextSibling;for(;o!==r;)i.push(o),o=o?.nextSibling;if(t&&typeof t=="object"&&t.type==="component"){let f=t,m=f.render(f.id);i.forEach(s=>s.remove()),m&&Array.from(m.hydrate().children).reverse().forEach(s=>e.after(s))}else{let f=Array.isArray(t)?t:[t],m=f.map(n=>{if(typeof n=="object"&&n.type==="component"){let a=n;return a.key??a.id}else return}).filter(n=>n!==void 0),s=f.map(n=>{if(typeof n=="object"&&n.type==="component"){console.log("RendernChild",n,n.properties);let a=n,y=a.render(a.id).hydrate();return y.children[0]&&n.key&&y.children[0].setAttribute("data-nice-key",n.key),console.log(y.children[0]),y}else return n});m.length?(i.forEach(n=>{m.includes(n.getAttribute("data-nice-key"))||n.remove()}),s.reverse().forEach(n=>{if(n instanceof HTMLElement){let a=null;Array.from(n.children).reverse().forEach(y=>{e.parentElement?.querySelector(`[data-nice-key="${y.getAttribute("data-nice-key")}"]`)||(a??r).before(y),a=y})}else{let a=document.createTextNode(n);e.after(a)}})):(i.forEach(n=>n.remove()),s.reverse().forEach(n=>{if(n instanceof HTMLElement)Array.from(n.children).reverse().forEach(a=>e.after(a));else{let a=document.createTextNode(n);e.after(a)}}))}},_=t=>{let e=document.createElement("div");return e.innerHTML=t,e},j=t=>{let e=/.+ (.+)="?$/gm,r,i=[];for(;(r=e.exec(t))!==null;)r.index===e.lastIndex&&e.lastIndex++,r.forEach(o=>{i.push(o)});if(i.length===2)return i[1]};var x=t=>{let e=t,r=N(),i=[],o=[],f=[],m={};return{id:r,type:"state",get:()=>e,set:s=>{let n=e;typeof t=="function"?n=s(e):n=s,n!==e&&(e=n,i.forEach(a=>a(n)),Object.entries(m).forEach(([a,y])=>{y.forEach(p=>{p.setAttribute(a,n??"")})}),f.forEach(([a,y])=>{S(e,a,y)}))},listen:s=>i.push(s),textNodes:o,markers:f,attributes:m}},A=(t,e)=>{let r=x(void 0),i=void 0,o=(e??[]).map(m=>m&&typeof m=="object"&&Object.hasOwn(m,"listen")?m:!1).filter(Boolean),f=m=>{let s=!!m&&!e,n=t(m),a=R(o);n!==r.get()&&a!==i&&!s&&r.set(n)};return e?(o.forEach(m=>m.listen(f)),f()):r.listen(f),r},$=t=>A(t||(()=>{}));var D=t=>{let e=Object.entries(t).reduce((r,[i,o])=>(r[i]=x(o),r),{});return r=>e[r]};var O=(t,e)=>{let r=[];return typeof t=="number"?r=Array.from({length:t},(i,o)=>o+1):typeof t=="object"?r=Array.from(Object.entries(t)):Array.isArray(t)&&(r=t),r.map((i,o)=>e(i,o))},H=t=>typeof t=="object"&&Object.hasOwn(t,"get")?t.get():t,U=t=>Object.entries(t).reduce((e,[r,i])=>`${e}${I(r)}: ${i};`,"");var z=x,G=A,J=L,Z=E,Q=$,X=D,Y=H,ee=typeof window<"u";
0 commit comments