preact-reconciler
Version:
Custom renderers for Preact in <1KB.
2 lines (1 loc) • 1.85 kB
JavaScript
"use strict";const U=require("preact"),S=0,w=4;class I extends HTMLElement{setAttribute(n,t){var o,i,l,f,C;this[n]=t;const e=this.a,u=e==null?void 0:e.f;if(u){const m=e.e,r=(o=this.c)!=null?o:this.c=m.c,d=m.d,s=e.props;if(s[n]=t,e.b){e.sibling=(l=(i=this.nextSibling)==null?void 0:i.a)!=null?l:null,e.flags=(f=this.nextSibling)!=null&&f.nextSibling?w:S;const c=e.g;c[n]=t;const p=e.b;if(r.prepareUpdate){const a=r.prepareUpdate(p,u,c,s,d,null);a&&r.commitUpdate(p,a,u,c,s,e)}else(C=r.commitUpdate)==null||C.call(r,p,u,c,s,e)}else{this.ownerSVGElement=null,delete s.a,e.g={...s};const c=e.b=r.createInstance(u,s,d,null,e);let p=e.ref;Object.defineProperty(e,"ref",{get(){return p},set(a){p=x=>{var _;const v=x!=null,g=v?r.getPublicInstance(c):null;a&&"current"in a?a.current=g:v?e.refCleanup=a==null?void 0:a(g):(_=e.refCleanup)==null||_.call(e)}}}),e.ref=p,r.finalizeInitialChildren(c,u,s,d,null)&&r.commitMount(c,u,s,e)}}}appendChild(n){const t=n;return this.a?this.c.appendChild(this.a.b,t.a.b):this.c.appendChildToContainer(this.d,t.a.b),super.appendChild(n)}insertBefore(n,t){if(t===null)return this.appendChild(n);const o=n,i=t;return this.a?this.c.insertBefore(this.a.b,o.a.b,i.a.b):this.c.insertInContainerBefore(this.d,o.a.b,i.a.b),super.insertBefore(n,t)}removeChild(n){const t=n;return this.a?this.c.removeChild(this.a.b,t.a.b):this.c.removeChildFromContainer(this.d,t.a.b),super.removeChild(n)}}const P=U.options;let h;const E=b=>{if(!h){customElements.define(h="preact-reconciler",I);const n=P.__b;P.__b=t=>{var o;const i=t;if(typeof i.type=="string"&&!i.e){let l=i.__;for(;l!=null&&l.__;)l=l.__;i.e=l==null?void 0:l.__c.__P,(o=i.e)!=null&&o.c&&(i.f=i.type,i.type=h,i.props.a=i)}n==null||n(t)}}return{createContainer(n){const t=new I;return t.d=n,t.c=b,t},updateContainer:U.render,createPortal(){},injectIntoDevTools(){}}};module.exports=E;