-
-
Notifications
You must be signed in to change notification settings - Fork 970
/
Copy pathriot.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 p=new Map,d=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 R=t=>t.remove(),Y=(t,e)=>e&&e.parentNode&&e.parentNode.insertBefore(t,e),K=0,$=1,z=2,F=3,G=4,H={ATTRIBUTE:0,EVENT:$,TEXT:2,VALUE:3,REF:G};function V(){return this}function q(t){return l(t)?t.prototype&&t.prototype.constructor?new t:t():t}function W(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 X(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 Z(t,e,n,r={}){return Object.defineProperty(t,e,{value:n,enumerable:!1,writable:!1,configurable:!0,...r}),t}function J(t,e,n){return Object.entries(e).forEach((([e,r])=>{Z(t,e,r,n)})),t}function Q(t,e){return Object.entries(e).forEach((([e,n])=>{t[e]||(t[e]=n)})),t}const tt={[g](t){this.el=t},[y]:V,[v](t,e,n=!1){n?R(this.el):n||U(this.el)},clone(){return{...this}},createDOM:V},et=Symbol(),nt=Symbol(),rt=Symbol(),st={nodes:[],mount(t,e){return this.update(t,e)},update(t,e){const{placeholder:n,nodes:r,childrenMap:s}=this,o=t===rt?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,p=[],d=[];return t.forEach(((t,r)=>{const f=function(t,{itemName:e,indexName:n,index:r,item:s}){return Z(t,e,s),n&&Z(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[et]=!0,e[nt]=!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?p.push((()=>N.mount(O,f,n,E))):p.push((()=>N.update(f,n))),h?y.push(...E.children):y.push(O),i.delete(b),d.push(...y),m.set(b,{nodes:y,template:N,context:f,index:r})})),{newChildrenMap:m,batches:p,futureNodes:d}}(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;)Y(n(e[a++],1),t)}else if(i===a)for(;u<o;)c&&c.has(t[u])||R(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;Y(n(e[a++],1),n(t[u++],-1).nextSibling),Y(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;)Y(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 R(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(rt,e),this}},ot={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();Y(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}},it="undefined"==typeof Element?{}:Element.prototype,ut=W((t=>it.hasOwnProperty(t))),at=/^on/,ct={handleEvent(t){this[t.type](t)}},lt=new WeakMap;function ht(t){return m(t)?"":t}const mt=(t,e)=>t.childNodes[e],pt={[K]:function t({node:e,name:n,isBoolean:r,value:s},o){if(!n)return s&&function(t,e,n){const r=e?Object.keys(e):[];Object.keys(n).filter((t=>!r.includes(t))).forEach((e=>t.removeAttribute(e)))}(e,o,s),void(o&&function(e,n){Object.keys(n).forEach((r=>t({node:e,name:r},n[r])))}(e,o));!ut(n)&&(function(t){return u(t,"boolean")}(o)||h(o)||l(o))&&(e[n]=o),function(t,e){return e?!t&&0!==t:null==t}(o,r)?e.removeAttribute(n):function(t){return["string","number","boolean"].includes(typeof t)}(o)&&e.setAttribute(n,function(t,e,n){return!0===e&&n?t:e}(n,o,r))},[$]:function({node:t,name:e},n){const r=e.replace(at,""),s=lt.get(t)||(t=>{const e=Object.create(ct);return lt.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({node:t},e){t.data=ht(e)},[F]:function({node:t},e){t.value=ht(e)},[G]:function({node:t,value:e},n){n?n(t):e(null)}},dt={mount(t){return this.value=this.evaluate(t),pt[this.type](this,this.value),this},update(t){const e=this.evaluate(t);return this.value!==e&&(pt[this.type](this,e),this.value=e),this},unmount(){return[$,G].includes(this.type)&&pt[this.type](this,null),this}};function ft(t,e){return{...dt,...e,node:2===e.type?mt(t,e.childNodeIndex):t}}const bt=(t,e)=>e?.find((e=>e.id===t)),gt=(t,e)=>t[P]||e,yt={attributes:[],getTemplateScope(t,e){return((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),X(r))})(this.attributes,t,e)},mount(t,e){const n=!!t.slots&&bt(this.name,t.slots),{parentNode:r}=this.node,s=n?gt(t,e):t;return this.templateData=n?.html?n:bt(this.name,s.slots),this.template=this.templateData&&At(this.templateData.html,this.templateData.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)),vt(this.node),R(this.node),this},update(t,e){if(this.template){const n=this.templateData?gt(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 vt(t){const e=t&&t.firstChild;e&&(Y(e,t),vt(t))}function Nt(t){return t.reduce(((t,{bindings:e})=>t.concat(e)),[])}const Ot={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}):At(function(t){return t.reduce(((t,e)=>t+e.html),"")}(e),[...Nt(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}},Et={[n]:function(t,{evaluate:e,template:n}){const r=document.createTextNode("");return Y(r,t),R(t),{...ot,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 Y(u,t),R(t),{...st,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{...Ot,node:t,evaluate:e,slots:r,attributes:s,getComponent:n}},[o]:function(t,{name:e,attributes:n,template:r}){return{...yt,attributes:n,template:r,node:t,name:e}}};function Tt(t,e){return t.map((t=>2===t.type?{...t,childNodeIndex:t.childNodeIndex+e}:t))}function xt(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(Et[s]||Et[2])(u,{...e,expressions:n&&!r?Tt(a,n):a})}const Mt={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=>xt(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++)R(t[e])}(this.children);break;case!n:U(r);break;case!!n:R(r)}return this.el=null,this},clone(){return{...this,meta:{},el:null}}};function At(t,e=[]){return{...Mt,html:t,bindingsData:e}}const St=Object.freeze({[g]:V,[y]:V,[v]:V}),jt=(t,e)=>t[d]=e;function wt(t){return[g,y,v].reduce(((e,n)=>(e[n]=t(n),e)),{})}function Ct(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 Dt(t,e){return Ct("string"==typeof t?(e||document).querySelectorAll(t):t)}const It=Object.freeze({$(t){return Dt(t,this.root)[0]},$$(t){return Dt(t,this.root)}}),Pt=Object.freeze({[N]:V,[O]:V,[E]:V,[T]:V,[x]:V,[M]:V,[A]:V}),_t=t=>1===t.length?t[0]:t;function Lt(t,e,n){const r="object"==typeof e?e:{[e]:n},s=Object.keys(r);return Ct(t).forEach((t=>{s.forEach((e=>t.setAttribute(e,r[e])))})),t}const kt=new Map;var Bt;const Ut={CSS_BY_NAME:kt,add(t,e){return kt.has(t)||(kt.set(t,e),this.inject()),this},inject(){return(Bt||(Lt(Bt=Dt("style[riot]")[0]||document.createElement("style"),"type","text/css"),Bt.parentNode||document.head.appendChild(Bt),Bt)).innerHTML=[...kt.values()].join("\n"),this},remove(t){return kt.has(t)&&(kt.delete(t),this.inject()),this}};function Rt(t,...e){return(...n)=>(n=[...e,...n]).length<t.length?Rt(t,...n):t(...n)}function Yt(t){return function(t,e){const n="string"==typeof e?[e]:e;return _t(Ct(t).map((t=>_t(n.map((e=>t.getAttribute(e)))))))}(t,b)||t.tagName.toLowerCase()}function Kt(t,e){return{...t,...q(e)}}function $t(t,e={}){return{...B(t),...q(e)}}const zt=W((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 Ft(t,{slots:e,attributes:n,props:r}){return s=function(t){return[...f].reduce(((t,e)=>e(t)||t),t)}(J(h(t)?Object.create(t):t,{mount(s,o={},i){return Z(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,...wt((t=>e=>(n.forEach((n=>n[t](e))),r)))})}(s,n).mount(i),Z(this,S,Object.freeze({...$t(s,r),...X(this[_].expressions)})),this[j]=Kt(this[j],o),this[L]=this.template.createDOM(s).clone(),jt(s,this),t.name&&function(t,e){Yt(t)!==e&&Lt(t,b,e)}(s,t.name),Z(this,C,s),Z(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=zt(this[L]),r=B({attributes:Array.from(this[C].attributes).filter((({name:t})=>!n.includes(t)))}),{[b]:s,...o}={...r,...X(this[_].expressions)};var i,u;if(!1!==this[N](o,this[S]))return Z(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&&Ut.add(r,t),Rt(Ft)(J(Q(n,{...Pt,[S]:{},[j]:{}}),{[w]:null,[C]:null,...It,name:r,css:t,template:e}))}const Ht=W(Vt);function Vt(t){const{css:e,template:n,exports:r,name:s}=t,o=n?function(t,e,n){return t(At,H,i,n)}(n,0,(t=>{const e=function(t={}){return Object.entries(q(t)).reduce(((t,[e,n])=>{var r;return t[(r=e,r.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=Vt(n),t}),{})}(t.exports?t.exports.components:{});return n=>n===t.name?Ht(t):e[n]||p.get(n)})(t)):tt;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=Q(t({slots:e,attributes:n,props:r}),St);return wt((t=>(...e)=>{if(t===g){const[t]=e;Z(t,D,!0),jt(t,i)}return i[t](...e),i}))}(r,{slots:t,attributes:i,props:u,css:e,template:n});const a=q(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 qt={cssManager:Ut,DOMBindings:{template:At,createBinding:xt,createExpression:ft,bindingTypes:i,expressionTypes:H},globals:{PROPS_KEY:S,STATE_KEY:j,IS_COMPONENT_UPDATING:I,ATTRIBUTES_KEY_SYMBOL:_,COMPONENTS_IMPLEMENTATION_MAP:p,PLUGINS_SET:f,DOM_COMPONENT_INSTANCE_PROPERTY:d,PARENT_KEY_SYMBOL:P}};t.__=qt,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})),Vt)(t)},t.install=function(t){return l(t),f.has(t),f.add(t),f},t.mount=function(t,e,n){return Dt(t).map((t=>function(t,e,n){const r=n||Yt(t);return p.has(r),p.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 p.has(t),p.set(t,Vt({name:t,css:e,template:n,exports:r})),p},t.uninstall=function(t){return f.has(t),f.delete(t),f},t.unmount=function(t,e){return Dt(t).map((t=>(t[d]&&t[d].unmount(e),t)))},t.unregister=function(t){return p.has(t),p.delete(t),Ut.remove(t),p},t.version="v9.4.7",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={});