-
-
Notifications
You must be signed in to change notification settings - Fork 966
/
riot.min.js
1 lines (1 loc) · 15.1 KB
/
riot.min.js
1
var t,e;t=this,e=function(t){"use strict";const e=0,n=1,r=2,s=3,o=4,i={EACH:0,IF:1,SIMPLE:2,TAG:3,SLOT:4};function u(t,e){return typeof t===e}function a(t){const e=t.ownerSVGElement;return!!e||null===e}function c(t){return"template"===t.tagName.toLowerCase()}function l(t){return u(t,"function")}function h(t){return!m(t)&&t.constructor===Object}function m(t){return null==t}const d=new Map,p=Symbol(),f=new Set,b="is",g="mount",y="update",v="unmount",N="shouldUpdate",O="onBeforeMount",E="onMounted",T="onBeforeUpdate",x="onUpdated",M="onBeforeUnmount",A="onUnmounted",S="props",j="state",w="slots",C="root",D=Symbol(),I=Symbol(),P=Symbol(),_=Symbol(),L=Symbol();function k(t){return t.replace(/-(\w)/g,((t,e)=>e.toUpperCase()))}function B(t){return Array.from(t.attributes).reduce(((t,e)=>(t[k(e.name)]=e.value,t)),{})}function U(t){for(;t.firstChild;)t.removeChild(t.firstChild)}const Y=t=>t.remove(),K=(t,e)=>e&&e.parentNode&&e.parentNode.insertBefore(t,e),R=0,$=1,z=2,G=3,H={ATTRIBUTE:0,EVENT:1,TEXT:2,VALUE:3};function F(){return this}function V(t){return l(t)?t.prototype&&t.prototype.constructor?new t:t():t}function q(t){const e=new Map,n=n=>(e.has(n)||e.set(n,t.call(this,n)))&&e.get(n);return n.cache=e,n}function W(t){return t.reduce(((t,e)=>{const{value:n,type:r}=e;switch(!0){case!e.name&&0===r:return{...t,...n};case 3===r:t.value=e.value;break;default:t[k(e.name)]=e.value}return t}),{})}function X(t,e,n,r={}){return Object.defineProperty(t,e,{value:n,enumerable:!1,writable:!1,configurable:!0,...r}),t}function Z(t,e,n){return Object.entries(e).forEach((([e,r])=>{X(t,e,r,n)})),t}function J(t,e){return Object.entries(e).forEach((([e,n])=>{t[e]||(t[e]=n)})),t}const Q={[g](t){this.el=t},[y]:F,[v](t,e,n=!1){n?Y(this.el):n||U(this.el)},clone(){return{...this}},createDOM:F},tt=Symbol(),et=Symbol(),nt=Symbol(),rt={nodes:[],mount(t,e){return this.update(t,e)},update(t,e){const{placeholder:n,nodes:r,childrenMap:s}=this,o=t===nt?null:this.evaluate(t),i=o?Array.from(o):[],{newChildrenMap:u,batches:a,futureNodes:c}=function(t,e,n,r){const{condition:s,template:o,childrenMap:i,itemName:u,getKey:a,indexName:c,root:l,isTemplateTag:h}=r,m=new Map,d=[],p=[];return t.forEach(((t,r)=>{const f=function(t,{itemName:e,indexName:n,index:r,item:s}){return X(t,e,s),n&&X(t,n,r),t}(Object.create(e),{itemName:u,indexName:c,index:r,item:t}),b=a?a(f):r,g=i.get(b),y=[];if(function(t,e){return!!t&&!t(e)}(s,f))return;const v=!g,N=g?g.template:o.clone(),O=N.el||l.cloneNode(),E=h&&v?function(t){const e=t.dom.cloneNode(!0),{head:n,tail:r}=function(){const t=document.createTextNode(""),e=document.createTextNode("");return t[tt]=!0,e[et]=!0,{head:t,tail:e}}();return{avoidDOMInjection:!0,fragment:e,head:n,tail:r,children:[n,...Array.from(e.childNodes),r]}}(N):N.meta;v?d.push((()=>N.mount(O,f,n,E))):d.push((()=>N.update(f,n))),h?y.push(...E.children):y.push(O),i.delete(b),p.push(...y),m.set(b,{nodes:y,template:N,context:f,index:r})})),{newChildrenMap:m,batches:d,futureNodes:p}}(i,t,e,this);return((t,e,n,r)=>{const s=e.length;let o=t.length,i=s,u=0,a=0,c=null;for(;u<o||a<i;)if(o===u){const t=i<s?a?n(e[a-1],-0).nextSibling:n(e[i-a],0):r;for(;a<i;)K(n(e[a++],1),t)}else if(i===a)for(;u<o;)c&&c.has(t[u])||Y(n(t[u],-1)),u++;else if(t[u]===e[a])u++,a++;else if(t[o-1]===e[i-1])o--,i--;else if(t[u]===e[i-1]&&e[a]===t[o-1]){const r=n(t[--o],-1).nextSibling;K(n(e[a++],1),n(t[u++],-1).nextSibling),K(n(e[--i],1),r),t[o]=e[i]}else{if(!c){c=new Map;let t=a;for(;t<i;)c.set(e[t],t++)}if(c.has(t[u])){const r=c.get(t[u]);if(a<r&&r<i){let s=u,m=1;for(;++s<o&&s<i&&c.get(t[s])===r+m;)m++;if(m>r-a){const s=n(t[u],0);for(;a<r;)K(n(e[a++],1),s)}else l=n(e[a++],1),(h=n(t[u++],-1))&&h.parentNode&&h.parentNode.replaceChild(l,h)}else u++}else Y(n(t[u++],-1))}var l,h})(r,c,function(t,e){return(n,r)=>{if(r<0){const n=t[t.length-1];if(n){const{template:r,nodes:s,context:o}=n;s.pop(),s.length||(t.pop(),r.unmount(o,e,null))}}return n}}(Array.from(s.values()),e),n),a.forEach((t=>t())),this.childrenMap=u,this.nodes=c,this},unmount(t,e){return this.update(nt,e),this}},st={mount(t,e){return this.update(t,e)},update(t,e){const n=!!this.evaluate(t),r=!this.value&&n,s=this.value&&!n,o=()=>{const n=this.node.cloneNode();K(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,t,e)};switch(!0){case r:o();break;case s:this.unmount(t);break;default:n&&this.template.update(t,e)}return this.value=n,this},unmount(t,e){return this.template.unmount(t,e,!0),this}},ot="undefined"==typeof Element?{}:Element.prototype,it=q((t=>ot.hasOwnProperty(t))),ut=/^on/,at={handleEvent(t){this[t.type](t)}},ct=new WeakMap;function lt(t){return m(t)?"":t}const ht=(t,e)=>t.childNodes[e],mt={[R]:function t(e,{name:n,isBoolean:r},s,o){return n?"ref"===n?(e&&e.removeAttribute(e,n),void s(e)):(!it(n)&&(function(t){return u(t,"boolean")}(s)||h(s)||l(s))&&(e[n]=s),void(function(t,e){return e?!t&&0!==t:null==t}(s,r)?e.removeAttribute(n):function(t){return["string","number","boolean"].includes(typeof t)}(s)&&e.setAttribute(n,function(t,e,n){return!0===e&&n?t:e}(n,s,r)))):(o&&function(t,e,n){const r=e?Object.keys(e):[];Object.keys(n).filter((t=>!r.includes(t))).forEach((e=>t.removeAttribute(e)))}(e,s,o),void(s&&function(e,n){Object.keys(n).forEach((r=>t(e,{name:r},n[r])))}(e,s)))},[$]:function(t,{name:e},n){const r=e.replace(ut,""),s=ct.get(t)||(t=>{const e=Object.create(at);return ct.set(t,e),e})(t),[o,i]=(t=>Array.isArray(t)?t:[t,!1])(n),u=s[r],a=o&&!u;u&&!o&&t.removeEventListener(r,s),a&&t.addEventListener(r,s,i),s[r]=o},[z]:function(t,e,n){t.data=lt(n)},[G]:function(t,e,n){t.value=lt(n)}},dt={mount(t){return this.value=this.evaluate(t),pt(this,this.value),this},update(t){const e=this.evaluate(t);return this.value!==e&&(pt(this,e),this.value=e),this},unmount(){return 1===this.type&&pt(this,null),"ref"===this.name&&mt[0](null,this,this.value),this}};function pt(t,e){return mt[t.type](t.node,t,e,t.value)}function ft(t,e){return{...dt,...e,node:2===e.type?ht(t,e.childNodeIndex):t}}const bt=(t,e)=>t[P]||e,gt={attributes:[],getTemplateScope(t,e){return function(t,e,n){if(!t||!t.length)return n;const r=t.map((t=>({...t,value:t.evaluate(e)})));return Object.assign(Object.create(n||null),W(r))}(this.attributes,t,e)},mount(t,e){const n=!!t.slots&&t.slots.find((({id:t})=>t===this.name)),{parentNode:r}=this.node,s=n?bt(t,e):t;return this.templateData=n,this.template=n&&Mt(n.html,n.bindings).createDOM(r)||this.template?.clone(),this.template&&(U(this.node),this.template.mount(this.node,this.getTemplateScope(t,s),s),this.template.children=Array.from(this.node.childNodes)),yt(this.node),Y(this.node),this},update(t,e){if(this.template){const n=this.templateData?bt(t,e):t;this.template.update(this.getTemplateScope(t,n),n)}return this},unmount(t,e,n){return this.template&&this.template.unmount(this.getTemplateScope(t,e),null,n),this}};function yt(t){const e=t&&t.firstChild;e&&(K(e,t),yt(t))}function vt(t){return t.reduce(((t,{bindings:e})=>t.concat(e)),[])}const Nt={mount(t){return this.update(t)},update(t,e){const n=this.evaluate(t);return n&&n===this.name?this.tag.update(t):(this.unmount(t,e,!0),this.name=n,this.tag=function(t,e=[],n=[]){return t?t({slots:e,attributes:n}):Mt(function(t){return t.reduce(((t,e)=>t+e.html),"")}(e),[...vt(e),{expressions:n.map((t=>({type:0,...t})))}])}(this.getComponent(n),this.slots,this.attributes),this.tag.mount(this.node,t)),this},unmount(t,e,n){return this.tag&&this.tag.unmount(n),this}},Ot={[n]:function(t,{evaluate:e,template:n}){const r=document.createTextNode("");return K(r,t),Y(t),{...st,node:t,evaluate:e,placeholder:r,template:n.createDOM(t)}},[r]:function(t,{expressions:e}){return n=e.map((e=>ft(t,e))),["mount","update","unmount"].reduce(((t,e)=>({...t,[e]:t=>n.map((n=>n[e](t)))&&void 0})),{});var n},[e]:function(t,{evaluate:e,condition:n,itemName:r,indexName:s,getKey:o,template:i}){const u=document.createTextNode(""),a=t.cloneNode();return K(u,t),Y(t),{...rt,childrenMap:new Map,node:t,root:a,condition:n,evaluate:e,isTemplateTag:c(a),template:i.createDOM(t),getKey:o,indexName:s,itemName:r,placeholder:u}},[s]:function(t,{evaluate:e,getComponent:n,slots:r,attributes:s}){return{...Nt,node:t,evaluate:e,slots:r,attributes:s,getComponent:n}},[o]:function(t,{name:e,attributes:n,template:r}){return{...gt,attributes:n,template:r,node:t,name:e}}};function Et(t,e){return t.map((t=>2===t.type?{...t,childNodeIndex:t.childNodeIndex+e}:t))}function Tt(t,e,n){const{selector:r,type:s,redundantAttribute:o,expressions:i}=e,u=r?t.querySelector(r):t;o&&u.removeAttribute(o);const a=i||[];return(Ot[s]||Ot[2])(u,{...e,expressions:n&&!r?Et(a,n):a})}const xt={createDOM(t){return this.dom=this.dom||function(t,e){return e&&("string"==typeof e?function(t,e){return a(t)?function(t,e){return e.ownerDocument.importNode((new window.DOMParser).parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${t}</svg>`,"application/xml").documentElement,!0)}(e,t):function(t,e){const n=c(e)?e:document.createElement("template");return n.innerHTML=t,n.content}(e,t)}(t,e):e)}(t,this.html)||document.createDocumentFragment(),this},mount(t,e,n,r={}){this.el&&this.unmount(e);const{fragment:s,children:o,avoidDOMInjection:i}=r,{parentNode:u}=o?o[0]:t,l=c(t),h=l?function(t,e,n){const r=Array.from(t.childNodes);return Math.max(r.indexOf(e),r.indexOf(n.head)+1,0)}(u,t,r):null;this.createDOM(t);const m=s||this.dom.cloneNode(!0);return this.el=l?u:t,this.children=l?o||Array.from(m.childNodes):null,!i&&m&&function(t,e){switch(!0){case a(t):!function(t,e){for(;t.firstChild;)e.appendChild(t.firstChild)}(e,t);break;case c(t):t.parentNode.replaceChild(e,t);break;default:t.appendChild(e)}}(t,m),this.bindings=this.bindingsData.map((t=>Tt(this.el,t,h))),this.bindings.forEach((t=>t.mount(e,n))),this.meta=r,this},update(t,e){return this.bindings.forEach((n=>n.update(t,e))),this},unmount(t,e,n=!1){const r=this.el;if(!r)return this;switch(this.bindings.forEach((r=>r.unmount(t,e,n))),!0){case r[D]||null===n:break;case Array.isArray(this.children):!function(t){for(let e=0;e<t.length;e++)Y(t[e])}(this.children);break;case!n:U(r);break;case!!n:Y(r)}return this.el=null,this},clone(){return{...this,meta:{},el:null}}};function Mt(t,e=[]){return{...xt,html:t,bindingsData:e}}const At=Object.freeze({[g]:F,[y]:F,[v]:F}),St=(t,e)=>t[p]=e;function jt(t){return[g,y,v].reduce(((e,n)=>(e[n]=t(n),e)),{})}function wt(t){return Array.isArray(t)?t:/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(t))&&"number"==typeof t.length?Array.from(t):[t]}function Ct(t,e){return wt("string"==typeof t?(e||document).querySelectorAll(t):t)}const Dt=Object.freeze({$(t){return Ct(t,this.root)[0]},$$(t){return Ct(t,this.root)}}),It=Object.freeze({[N]:F,[O]:F,[E]:F,[T]:F,[x]:F,[M]:F,[A]:F}),Pt=t=>1===t.length?t[0]:t;function _t(t,e,n){const r="object"==typeof e?e:{[e]:n},s=Object.keys(r);return wt(t).forEach((t=>{s.forEach((e=>t.setAttribute(e,r[e])))})),t}const Lt=new Map;var kt;const Bt={CSS_BY_NAME:Lt,add(t,e){return Lt.has(t)||(Lt.set(t,e),this.inject()),this},inject(){return(kt||(_t(kt=Ct("style[riot]")[0]||document.createElement("style"),"type","text/css"),kt.parentNode||document.head.appendChild(kt),kt)).innerHTML=[...Lt.values()].join("\n"),this},remove(t){return Lt.has(t)&&(Lt.delete(t),this.inject()),this}};function Ut(t,...e){return(...n)=>(n=[...e,...n]).length<t.length?Ut(t,...n):t(...n)}function Yt(t){return function(t,e){const n="string"==typeof e?[e]:e;return Pt(wt(t).map((t=>Pt(n.map((e=>t.getAttribute(e)))))))}(t,b)||t.tagName.toLowerCase()}function Kt(t,e){return{...t,...V(e)}}function Rt(t,e={}){return{...B(t),...V(e)}}const $t=q((t=>{const e=t?.bindingsData?.[0];return e?.selector?[]:e?.expressions?.reduce(((t,{name:e,type:n})=>n===H.ATTRIBUTE?t.concat([e]):t),[])??[]}));function zt(t,{slots:e,attributes:n,props:r}){return s=function(t){return[...f].reduce(((t,e)=>e(t)||t),t)}(Z(h(t)?Object.create(t):t,{mount(s,o={},i){return X(s,D,!1),this[P]=i,this[_]=function(t,e=[]){const n=e.map((e=>ft(t,e))),r={};return Object.assign(r,{expressions:n,...jt((t=>e=>(n.forEach((n=>n[t](e))),r)))})}(s,n).mount(i),X(this,S,Object.freeze({...Rt(s,r),...W(this[_].expressions)})),this[j]=Kt(this[j],o),this[L]=this.template.createDOM(s).clone(),St(s,this),t.name&&function(t,e){Yt(t)!==e&&_t(t,b,e)}(s,t.name),X(this,C,s),X(this,w,e),this[O](this[S],this[j]),this[L].mount(s,this,i),this[E](this[S],this[j]),this},update(t={},e){e&&(this[P]=e,this[_].update(e));const n=$t(this[L]),r=B({attributes:Array.from(this[C].attributes).filter((({name:t})=>!n.includes(t)))}),{[b]:s,...o}={...r,...W(this[_].expressions)};var i,u;if(!1!==this[N](o,this[S]))return X(this,S,Object.freeze({...e?(i=this[S],u=n,h(i)?Object.fromEntries(u.map((t=>[t,i[t]]))):i):this[S],...o})),this[j]=Kt(this[j],t),this[T](this[S],this[j]),this[I]||(this[I]=!0,this[L].update(this,this[P])),this[x](this[S],this[j]),this[I]=!1,this},unmount(t){return this[M](this[S],this[j]),this[_].unmount(),this[L].unmount(this,this[P],null===t?null:!t),this[A](this[S],this[j]),this}})),Object.keys(t).filter((e=>l(t[e]))).forEach((t=>{s[t]=s[t].bind(s)})),s;var s}function Gt({css:t,template:e,componentAPI:n,name:r}){return t&&r&&Bt.add(r,t),Ut(zt)(Z(J(n,{...It,[S]:{},[j]:{}}),{[w]:null,[C]:null,...Dt,name:r,css:t,template:e}))}const Ht=q(Ft);function Ft(t){const{css:e,template:n,exports:r,name:s}=t,o=n?function(t,e,n){return t(Mt,H,i,n)}(n,0,(t=>{const e=function(t={}){return Object.entries(V(t)).reduce(((t,[e,n])=>{var r;return t[(r=e,r.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=Ft(n),t}),{})}(t.exports?t.exports.components:{});return n=>n===t.name?Ht(t):e[n]||d.get(n)})(t)):Q;return({slots:t,attributes:i,props:u})=>{if(r&&r[D])return function(t,{slots:e,attributes:n,props:r,css:s,template:o}){const i=J(t({slots:e,attributes:n,props:r}),At);return jt((t=>(...e)=>{if(t===g){const[t]=e;X(t,D,!0),St(t,i)}return i[t](...e),i}))}(r,{slots:t,attributes:i,props:u,css:e,template:n});const a=V(r)||{},c=Gt({css:e,template:o,componentAPI:a,name:s})({slots:t,attributes:i,props:u});return{mount:(t,e,n)=>c.mount(t,n,e),update:(t,e)=>c.update(e,t),unmount:t=>c.unmount(t)}}}const Vt={cssManager:Bt,DOMBindings:{template:Mt,createBinding:Tt,createExpression:ft,bindingTypes:i,expressionTypes:H},globals:{PROPS_KEY:S,STATE_KEY:j,IS_COMPONENT_UPDATING:I,ATTRIBUTES_KEY_SYMBOL:_,COMPONENTS_IMPLEMENTATION_MAP:d,PLUGINS_SET:f,DOM_COMPONENT_INSTANCE_PROPERTY:p,PARENT_KEY_SYMBOL:P}};t.__=Vt,t.component=function(t){return(e,n,{slots:r,attributes:s,parentScope:o}={})=>function(...t){return t.reduce(((t,e)=>(...n)=>t(e(...n))))}((t=>t.mount(e,o)),(t=>t({props:n,slots:r,attributes:s})),Ft)(t)},t.install=function(t){return l(t),f.has(t),f.add(t),f},t.mount=function(t,e,n){return Ct(t).map((t=>function(t,e,n){const r=n||Yt(t);return d.has(r),d.get(r)({props:e,slots:void 0}).mount(t)}(t,e,n)))},t.pure=function(t){return l(t),t[D]=!0,t},t.register=function(t,{css:e,template:n,exports:r}){return d.has(t),d.set(t,Ft({name:t,css:e,template:n,exports:r})),d},t.uninstall=function(t){return f.has(t),f.delete(t),f},t.unmount=function(t,e){return Ct(t).map((t=>(t[p]&&t[p].unmount(e),t)))},t.unregister=function(t){return d.has(t),d.delete(t),Bt.remove(t),d},t.version="v9.4.3",t.withTypes=t=>t},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).riot={});