-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.js
1 lines (1 loc) · 6.45 KB
/
index.min.js
1
var G=(r,t,f)=>{t=t||(n=>n),f=f||document;let c=n=>n&&typeof n=="object"&&!(n instanceof Array),b=(n,e)=>c(n)&&c(e)?{...n,...e}:e,m=(n,e)=>typeof n=="string"&&typeof e=="string"?n+e:e,o=n=>{if(n.nodeType!=1)return()=>[t(n.textContent)];let e=n.tagName.toLowerCase(),y=Array.from(n.attributes).map(({nodeName:h,nodeValue:u})=>({key:h,value:n.getAttribute(h)})),C=Array.from((e=="template"?n.content:n).childNodes).map(h=>o(h));return(h,u,l,a)=>y.reduce((O,j)=>O.reduce((i,E)=>{let{scope:g,attributes:A}=E;var{key:s,value:p}=j;return(s.substr(0,1)==":"||s.substr(s.length-1)==":")&&(s=s.substr(0,1)==":"?s.substr(1):s.substr(0,s.length-1),p==""?p=g:g&&typeof g=="object"&&g[p]!=null?p=g[p]:p=null),s=="each"?p instanceof Array&&p.forEach(v=>{i.push({attributes:{...A},scope:b(g,v)})}):s=="with"?p!=null&&i.push({...E,scope:b(g,p)}):s=="if"||s=="not"?(s=="if"&&p||s=="not"&&!p)&&i.push(E):s=="show"||s=="hide"?((s=="hide"&&p||s=="show"&&!p)&&(A.style="display: none;"+(typeof A.style=="string"?A.style:"")),i.push({...E,attributes:A})):s=="case"?u!=null&&u==p&&i.push(E):s=="switch"?i.push({...E,word:p}):s=="bind"?(p&&typeof p=="object"&&Object.keys(p).forEach(v=>{A[v]=m(A[v],p[v])}),i.push({...E,attributes:A})):(A[s]=m(A[s],p),i.push({...E,attributes:A})),i},[]),[{scope:e=="slot"?a:h,attributes:{}}]).reduce((O,{scope:j,attributes:i,word:E})=>{let g=(e=="slot"?l:C).reduce((p,v)=>(v(j,E,l||C,a).forEach(L=>{p.push(L)}),p),[]).filter(p=>p),A=e.indexOf("-")>=0?f.getElementById(e):null;if(i.text!=null&&A==null){for(;g.length;)g.pop();g.push(t(i.text)),i={...i},delete i.text}var s=null;return e=="template"||e=="slot"?s=g:A!=null?s=o(A)(i,null,C,j):s=[r(e,i,g)],s.forEach(p=>{O.push(p)}),O},[])};return(n,e)=>{if(e){let y=n.tagName.toLowerCase(),C=Array.from(n.attributes).reduce((u,{attrName:l,attrValue:a})=>({...u,[l]:a}),{}),h=o(e);return u=>r(y,C,h(u))}else{let y=o(n);return C=>y(C)[0]}}};var F=1,_=3,W={},J=[],X="http://www.w3.org/2000/svg",z=function(r){this.events[r.type](r)},x=r=>r==null?r:r.key,Y=(r,t,f,c,b)=>{t==="key"||(t[0]==="o"&&t[1]==="n"?((r.events||(r.events={}))[t=t.slice(2)]=c)?f||r.addEventListener(t,z):r.removeEventListener(t,z):!b&&t!=="list"&&t!=="form"&&t in r?r[t]=c??"":c==null||c===!1?r.removeAttribute(t):r.setAttribute(t,c))},U=(r,t)=>{var f=r.props,c=r.type===_?document.createTextNode(r.tag):(t=t||r.tag==="svg")?document.createElementNS(X,r.tag,{is:f.is}):document.createElement(r.tag,{is:f.is});for(var b in f)Y(c,b,null,f[b],t);for(var m=0;m<r.children.length;m++)c.appendChild(U(r.children[m]=B(r.children[m]),t));return r.node=c},R=(r,t,f,c,b)=>{if(f!==c)if(f!=null&&f.type===_&&c.type===_)f.tag!==c.tag&&(t.nodeValue=c.tag);else if(f==null||f.tag!==c.tag)t=r.insertBefore(U(c=B(c),b),t),f!=null&&r.removeChild(f.node);else{var m,o,n,e,y=f.props,C=c.props,h=f.children,u=c.children,l=0,a=0,O=h.length-1,j=u.length-1;b=b||c.tag==="svg";for(var i in{...y,...C})(i==="value"||i==="selected"||i==="checked"?t[i]:y[i])!==C[i]&&Y(t,i,y[i],C[i],b);for(;a<=j&&l<=O&&!((n=x(h[l]))==null||n!==x(u[a]));)R(t,h[l].node,h[l++],u[a]=B(u[a++]),b);for(;a<=j&&l<=O&&!((n=x(h[O]))==null||n!==x(u[j]));)R(t,h[O].node,h[O--],u[j]=B(u[j--]),b);if(l>O)for(;a<=j;)t.insertBefore(U(u[a]=B(u[a++]),b),(o=h[l])&&o.node);else if(a>j)for(;l<=O;)t.removeChild(h[l++].node);else{for(var E={},g={},i=l;i<=O;i++)(n=h[i].key)!=null&&(E[n]=h[i]);for(;a<=j;){if(n=x(o=h[l]),e=x(u[a]=B(u[a])),g[n]||e!=null&&e===x(h[l+1])){n==null&&t.removeChild(o.node),l++;continue}e==null||f.type===F?(n==null&&(R(t,o&&o.node,o,u[a],b),a++),l++):(n===e?(R(t,o.node,o,u[a],b),g[e]=!0,l++):(m=E[e])!=null?(R(t,t.insertBefore(m.node,o&&o.node),m,u[a],b),g[e]=!0):R(t,o&&o.node,null,u[a],b),a++)}for(;l<=O;)x(o=h[l++])==null&&t.removeChild(o.node);for(var i in E)g[i]==null&&t.removeChild(E[i].node)}}return c.node=t},B=r=>r!==!0&&r!==!1&&r?r:q(""),Z=r=>r.nodeType===_?q(r.nodeValue,r):M(r.nodeName.toLowerCase(),W,J.map.call(r.childNodes,Z),F,r),M=(r,t,f,c,b)=>({tag:r,props:t,key:t.key,children:f,type:c,node:b}),q=(r,t)=>M(r,W,J,_,t),$=(r,t,f=J)=>M(r,t,Array.isArray(f)?f:[f]),D=(r,t)=>((r=R(r.parentNode,r,r.vdom||Z(r),t)).vdom=t,r);var Q=({root:r,template:t,format:f,...c})=>{var b,m=!1;f=typeof f=="function"?f:e=>e,c.init=typeof c.init=="function"?c.init:e=>e,c.done=typeof c.done=="function"?c.done:()=>null;let o=(e,y)=>{if(e=="init"&&!m||e!="init"&&m&&typeof c[e]=="function"){m=!0;let C=e=="init"?c.init(y,o):e=="done"?c.done(b,o):c[e](b,y,o);b=C===void 0?b:C,e=="done"?m=!1:D(r,n(f(b)))}},n=G((e,y,C)=>(Object.keys(y||{}).forEach(h=>{h.substr(0,7)=="data-on"&&(h=h.substr(5));let u=y[h]||y["data-"+h];h.substr(0,2)=="on"&&(y[h]=typeof c[u]=="function"?l=>{o(u,l)}:window[u]||(()=>{}))}),$(e,y,C)),q)(r,t);return o},N=r=>({...r,Query:r.query.split("&").map(t=>t.split("=")).map(t=>({key:decodeURIComponent(t.shift()),value:decodeURIComponent(t.join("="))})).filter(({key:t})=>t!="").reduce((t,{key:f,value:c})=>(f.substr(f.length-2)=="[]"?(f=f.substr(0,f.length-2),t[f]instanceof Array||(t[f]=[]),t[f].push(c)):t[f]=c,t),{})}),w=({root:r,components:t,routes:f,middleware:c,...b})=>{r=r||document.body.querySelector("main")||document.body,f=f instanceof Array?f:[],c=[N].concat(c).filter(u=>typeof u=="function"),t=t&&typeof t=="object"?t:{};let m=document.createElement("template");f.length&&(Array.from(r.children).forEach(u=>{m.content.appendChild(u.cloneNode(!0))}),t.home={template:m});let o=Object.keys(t),n={},e={config:Object.keys(b).reduce((u,l)=>(o.indexOf(l)<0&&(u[l]=b[l]),u),{}),root:r,refresh:()=>h()},y=o.reduce((u,l)=>{let a=t[l];a.root==null&&(a.root=r),a.root==r&&f.length&&a.template==null&&(a.template=m);let O=Q(a);return u.push(O),a.root!=r||!f.length?O("init",{api:b[l],...e}):n[l]=O,u},[]);var C=n.home;let h=()=>{let u=window.location.hash,l=u.split("?"),a=l.shift(),O=l.join("?"),j=a.split("/").map(decodeURIComponent),i=f.reduce((E,{route:g,...A})=>{if(g==null){if(!E.weight)return{...A,...E,weight:1}}else{let p=g.split("/");if(p.length==j.length){var s=2;let v=j.reduce((L,P,I)=>(L&&(p[I].substr(0,1)==":"?L[p[I].substr(1)]=P:p[I]!==P?L=null:s++),L),{});if(v&&s>E.weight)return{...A,route:g,Params:v,weight:s}}}return E},{route:null,Params:{},weight:0});if(i){C("done"),C=n[i.component]||n.home;let E=s=>JSON.parse(JSON.stringify(s)),g={url:u,path:a,query:O,route:i.route,Params:i.Params||{}},A={...c.reduce((s,p)=>p(s),E(g)),...g};y.forEach(s=>s("hashchange",E(A))),C("init",{...A,api:b[i.component],...e})}};return f.length&&(window.addEventListener("hashchange",h),h()),()=>{f.length&&window.removeEventListener("hashchange",h),y.forEach(u=>u("done"))}};export{w as default};