ProjetRIOT/riot.min.js

1 line
15 KiB
JavaScript
Raw Normal View History

2023-03-26 17:40:15 +02:00
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 s(t){return"template"===t.tagName.toLowerCase()}function o(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="mount",d="update",p="unmount",m="props",f="slots",b="root",g=Symbol(),v=Symbol(),y=Symbol(),O=Symbol(),j=Symbol();function N(t){return t.replace(/-(\w)/g,((t,e)=>e.toUpperCase()))}function x(t){for(;t.firstChild;)t.removeChild(t.firstChild)}const M=t=>t.remove(),E=(t,e)=>e&&e.parentNode&&e.parentNode.insertBefore(t,e),A={ATTRIBUTE:0,EVENT:1,TEXT:2,VALUE:3};function T(){return this}function w(t){return o(t)?t.prototype&&t.prototype.constructor?new t:t():t}function S(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 C(t){return t.reduce(((t,e)=>{const{value:n,type:r}=e;switch(!0){case!e.name&&0===r:return Object.assign({},t,n);case 3===r:t.value=e.value;break;default:t[N(e.name)]=e.value}return t}),{})}function D(t,e,n,r){return void 0===r&&(r={}),Object.defineProperty(t,e,Object.assign({value:n,enumerable:!1,writable:!1,configurable:!0},r)),t}function k(t,e,n){return Object.entries(e).forEach((e=>{let[r,s]=e;D(t,r,s,n)})),t}function L(t,e){return Object.entries(e).forEach((e=>{let[n,r]=e;t[n]||(t[n]=r)})),t}const U=Object.freeze({[h]:T,[d]:T,[p]:T}),B=Object.assign({},U,{clone:T,createDOM:T}),I=Symbol(),P=Symbol(),_=Symbol(),$={nodes:[],mount(t,e){return this.update(t,e)},update(t,e){const{placeholder:n,nodes:r,childrenMap:s}=this,o=t===_?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,d=new Map,p=[],m=[];return t.forEach(((t,r)=>{const f=function(t,e){let{itemName:n,indexName:r,index:s,item:o}=e;return D(t,n,o),r&&D(t,r,s),t}(Object.create(e),{itemName:u,indexName:c,index:r,item:t}),b=a?a(f):r,g=i.get(b),v=[];if(function(t,e){return!!t&&!t(e)}(s,f))return;const y=!g,O=g?g.template:o.clone(),j=O.el||l.cloneNode(),N=h&&y?function(t){const e=t.dom.cloneNode(!0),{head:n,tail:r}=function(){const t=document.createTextNode(""),e=document.createTextNode("");return t[I]=!0,e[P]=!0,{head:t,tail:e}}();return{avoidDOMInjection:!0,fragment:e,head:n,tail:r,children:[n,...Array.from(e.childNodes),r]}}(O):O.meta;y?p.push((()=>O.mount(j,f,n,N))):p.push((()=>O.update(f,n))),h?v.push(...N.children):v.push(j),i.delete(b),m.push(...v),d.set(b,{nodes:v,template:O,context:f,index:r})})),{newChildrenMap:d,batches:p,futureNodes:m}}(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;)E(n(e[a++],1),t)}else if(i===a)for(;u<o;)c&&c.has(t[u])||M(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;E(n(e[a++],1),n(t[u++],-1).nextSibling),E(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,d=1;for(;++s<o&&s<i&&c.get(t[s])===r+d;)d++;if(d>r-a){const s=n(t[u],0);for(;a<r;)E(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 M(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(_,e),this}},z={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();E(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,t,e)};switch(!0){case r:o();break;case s:this.u