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