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