-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
1 lines (1 loc) · 3.87 KB
/
index.js
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).reactem={})}(this,(function(t){"use strict";let e=60103,r=60107,n=60109;if("function"==typeof Symbol&&Symbol.for){const t=Symbol.for;e=t("react.element"),r=t("react.fragment"),n=t("react.provider")}class i{constructor(t,r,s){this.$type=e,this.name=t,this.attrs=r,this.children=s.reverse()}}function o(t,e,...r){return new i(t,e,r)}class h extends i{constructor(t){super("",null,t),this.$type=r}}function a({children:t}){return new h(t)}class l{constructor(t){this._context=[t],this.Provider=({value:t,children:e})=>new c(this,{value:t},e)}PushProvider(t){this._context.push(t)}PopProvider(){this._context.pop()}currentValue(){return this._context[this._context.length-1]}}class c extends i{constructor(t,e,r){super("",e,r),this.$type=n,this._ctx=t}}function f(t){return t.currentValue()}function u(t){return new l(t)}var d=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"];let m=t=>String(t).replace(/[&<>"']/g,(t=>`&${p[t]};`)),p={"&":"amp","<":"lt",">":"gt",'"':"quot","'":"apos"},y="dangerouslySetInnerHTML",g={className:"class",htmlFor:"for"};class v{constructor(t){this.stack=[],this.html="",this.root=t}push(t){if(t.$type===n)t._ctx.PushProvider(t.attrs.value);else if(t.$type===r);else if(t.name)if(-1===d.indexOf(t.name)){if(this.html+="<"+t.name,t.attrs)for(let e in t.attrs)!1!==t.attrs[e]&&null!=t.attrs[e]&&e!==y&&(this.html+=` ${g[e]?g[e]:m(e)}="${m(t.attrs[e])}"`);if(this.html+=">",t.attrs&&t.attrs[y])return this.html+=t.attrs[y].__html,void(this.html+=`</${t.name}>`)}else{if(this.html+="<"+t.name,t.attrs)for(let e in t.attrs)!1!==t.attrs[e]&&null!=t.attrs[e]&&e!==y&&(s+=` ${g[e]?g[e]:m(e)}="${m(t.attrs[e])}"`);this.html+="/>"}this.stack.push(t)}pop(){let t=this.stack.pop();t.$type===n?t._ctx.PopProvider():t.$type===r||t.name&&-1===d.indexOf(t.name)&&(this.html+=`</${t.name}>`)}render(){for(;this.root.name instanceof Function;)this.root=this.root.name({...this.root.attrs,children:this.root.children.slice().reverse()});for(this.root instanceof Array&&(this.root=new h(this.root)),this.root instanceof i?this.push(this.root):this.html+=m(this.root);this.stack.length>0;){let t=this.stack[this.stack.length-1];if(t.children&&0!=t.children.length){let e=t.children.pop();if(e instanceof i)if(e.name instanceof Function){let r=e.name({...e.attrs,children:e.children.slice().reverse()});t.children.push(r)}else this.push(e);else if(e instanceof Array)for(let r of e.slice().reverse())t.children.push(r);else this.html+=m(e)}else this.pop()}return this.html}async renderAsync(){for(this.root instanceof Promise&&(this.root=await this.root);this.root.name instanceof Function;)this.root=await this.root.name({...this.root.attrs,children:this.root.children.slice().reverse()});for(this.root instanceof Array&&(this.root=new h(this.root)),this.root instanceof i?this.push(this.root):this.html+=m(this.root);this.stack.length>0;){let t=this.stack[this.stack.length-1];if(t.children&&0!=t.children.length){let e=t.children.pop();if(e instanceof i)if(e.name instanceof Function){let r=await e.name({...e.attrs,children:e.children.slice().reverse()});t.children.push(r)}else this.push(e);else if(e instanceof Array)for(let r of e.slice().reverse())t.children.push(r);else this.html+=m(e)}else this.pop()}return this.html}destroy(){}}async function x(t){const e=new v(t);try{return await e.renderAsync()}finally{e.destroy()}}function $(t){const e=new v(t);try{return e.render(1/0)}finally{e.destroy()}}var w={h:o,useContext:f,createContext:u,createElement:o,renderToString:$,renderToStringAsync:x,Fragment:a};t.Fragment=a,t.createContext=u,t.createElement=o,t.default=w,t.h=o,t.renderToString=$,t.renderToStringAsync=x,t.useContext=f,Object.defineProperty(t,"__esModule",{value:!0})}));