All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.module-min.mikado.js Maven / Gradle / Ivy

The newest version!
import{TemplateDOM,Template,MikadoOptions,MikadoCallbacks,NodeCache,ProxyCache}from"./type.js";import Observer from"./array.js";import{create_path,construct}from"./factory.js";import proxy_create from"./proxy.js";export const includes=Object.create(null);export default function Mikado(a,b={}){if(!(this instanceof Mikado))return new Mikado(a,b);if(!1,"string"==typeof a){const c=includes[a];if(c instanceof Mikado)return c;a=c[0],b||(b=c[1])}this.dom=[],this.length=0,this.root=b.root||b.mount||null,this.recycle=!!b.recycle,this.state=b.state||{},this.shadow=b.shadow||!!a.cmp,this.key=a.key||"",this.live={};const c=a.fn;a.fc||c&&(a.fc=c.slice()),this.apply=c&&c.pop(),this.tpl=a,this.name=a.name,this.inc=[];const d=this.recycle||!!this.key;this.pool=d&&b.pool?1:0,this.pool_shared=[],this.pool_keyed=new Map,this.cache=d&&(a.cache||!!b.cache),this.async=!!b.async,this.timer=0,this.on=b.on||null;{this.proxy=null,this.fullproxy=0;const a=b.observe;a&&new Observer(a).mount(this)}this.root?this.mount(this.root,b.hydrate):this.factory=null}export function register(a,b){let c,d;return"string"==typeof a?(c=d=a,a=includes[c],a instanceof Mikado||(a=a[0])):c=a.name,!1,includes[c]=[a,b],Mikado}export function unregister(a){!1,"object"==typeof a&&(a=a.name);const b=includes[a];return b&&(b instanceof Mikado&&b.destroy(),includes[a]=null),Mikado}Mikado.prototype.mount=function(a,b){if(!1,this.timer&&this.cancel(),this.shadow){const b=this.tpl.cmp;if(a=a.shadowRoot||a.attachShadow({mode:"open"}),b&&b.length){const c=a.lastElementChild;if(c)a=c;else{b.push({tag:"root"});for(let c,d=0;da?this.length+a:a,a=this.dom[d]):d=this.index(a)),a=a;let e,f;if(this.key){const c=b[this.key];if(!(e=this.live[c]))this.pool&&(e=this.pool_keyed.get(c))&&(this.pool_keyed.delete(c),this.checkout(a),this.dom[d]=e,a.replaceWith(e));else if(e!==a){const b=this.index(e),c=ba?this.length+a-1:a,a=this.dom[d]):d=this.index(a)),a=a,this.apply(b,c||this.state,d,a._mkp||create_path(a,this.factory._mkp,this.cache));const e=this.on&&this.on.update;return e&&e(a,this),this},Mikado.prototype.cancel=function(){return!1,cancelAnimationFrame(this.timer),this.timer=0,this},Mikado.prototype.create=function(a,b,c,d){const e=this.key,f=e&&a[e];let g,h,i,j;this.pool&&(e?(h=this.pool_keyed)&&(g=h.get(f))&&(!1,h.delete(f),j=1):(h=this.pool_shared)&&h.length&&(!1,g=h.pop())),g||(g=i=this.factory,!i&&(this.factory=g=i=construct(this,this.tpl.tpl,[],""),finishFactory(this)));let k;if(this.apply){const d=g._mkp||create_path(g,this.factory._mkp,!!i||this.cache);k=i&&this.cache&&Array(d.length),this.apply(a,b||this.state,c,d,!!i,k)}i&&(!1,g=i.cloneNode(!0),k&&!0!==k&&(g._mkc=k),g._mkr=1),e&&(!j&&(g._mkk=f),d&&(this.live[f]=g));const l=this.on&&this.on[i?"create":"recycle"];return l&&l(g,this),g},Mikado.prototype.add=function(a,b,c){let d;"number"==typeof b?(c=0>b?this.length+b:b,b=null,d=cc&&(c+=this.length),d=cg?h:g,j=0;for(d||(d=0);d=h;let n,o,p,q;if(this.proxy&&(l._mkx?q=this.fullproxy:c[d]=apply_proxy(this,e[d],l)),!m&&(n=e[d],o=l[f],p=n._mkk,p===o)){q||this.update(n,l,b,d);continue}if(m||!a[o]){m||!this.pool?(h++,i=h>g?h:g,this.add(l,b,d)):this.replace(n,l,b,d);continue}let r,s;for(let a=d+1;a=s+j){const c=e[r-1];this.root.insertBefore(c,n),q||this.update(c,l,b,d),r==s?(1h?h:a)-1),j--,d--,!1}k=1;break}}k||(this.remove(d),h--,i=h>g?h:g,d--)}return this};function splice(a,b,c,d){const e=d||a[b];if(d&&b++,bc;b--)a[b]=a[b-1];a[c]=e}Mikado.prototype.append=function(a,b,c){let d;"number"==typeof b?(c=0>b?this.length+b:b,b=null,d=1):"number"==typeof c&&(0>c&&(c+=this.length),d=1);const e=a.length;for(let f=0;fa&&(a=c+a):a=this.index(a)),!c||a>=c)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;let d;!a&&b>=c?(d=this.dom,b=d.length,this.root.textContent="",this.root._mkd=this.dom=[],c=0):(d=this.dom.splice(a,b),c-=b);const e=this.pool&&!this.key,f=this.key||this.pool,g=this.on&&this.on.remove;let h=this.key&&this.pool;h&&b>=h&&(this.pool_keyed=new Map,h=0);for(let h,i=0;ithis.pool&&(!1,this.pool_keyed.delete(this.pool_keyed.keys().next().value));else{const b=this.pool_shared.length;!1,this.pool_shared[b]=a}},Mikado.prototype.flush=function(){return!1,this.pool_shared=[],this.pool_keyed=new Map,this},Mikado.prototype.destroy=function(){for(let a,b=0;b




© 2015 - 2025 Weber Informatics LLC | Privacy Policy