@chamn/render 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17,5 +17,5 @@
17
17
  return f.apply(f, args)
18
18
  }
19
19
  return runTimeFunc();
20
- `;new Function(a)(...o,e,r)}catch(a){console.warn(a)}},tr=(t,e)=>{const r={};return e.forEach((n,o)=>{r[n]=t[o]}),r},er=t=>{const e={};return Object.keys(t).forEach(r=>{let n=r.replace("-webkit","Webkit");n=n.replace("-ms","ms"),n=n.replace("-moz","Moz"),n=n.replace("-o","O");let o=n.split("-");o.length>=2&&(o=o.map((a,i)=>i!==0?qh(a):a)),e[o.join("")]=t[r]}),e},rr=t=>{let e="";return Object.keys(t).forEach(r=>{e+=`${r}:${t[r]};`}),e},mv=(t,e)=>{const r={};return t.forEach(n=>{if(n.globalName){const o=e[n.globalName];o&&(r[n.globalName]=o)}}),r},yv=(t,e=1)=>{let r=0,n=t,o={},a={};for(;r<e;)Object.keys(n).forEach(i=>{o={...o,...n[i]}}),a=o,n=o,o={},r+=1;return a},ta=(t,e)=>{const r=[];return e.forEach(n=>{const a=n.exec(t);a!=null&&a.length&&r.push(a[1])}),r},ea=(t,e)=>{const r={};return e.forEach(n=>{t[n.name]&&(r[n.name]=t[n.name])}),r},bv=(t,e)=>ea(t,e),_v=(t,e)=>ea(t,e),ue="DYNAMIC",Sv=["$$context","$$nodeModel"],Pn=t=>{let e;const r=new Set,n=(c,u)=>{const l=typeof c=="function"?c(e):c;if(!Object.is(l,e)){const p=e;e=u??typeof l!="object"?l:Object.assign({},e,l),r.forEach(f=>f(e,p))}},o=()=>e,s={setState:n,getState:o,subscribe:c=>(r.add(c),()=>r.delete(c)),destroy:()=>{({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),r.clear()}};return e=t(n,o,s),s},jv=t=>t?Pn(t):Pn;class Ov{constructor(){m(this,"storeMap",new Map)}addStore(e,r){const n=jv(r);return this.storeMap.set(e,n),n.name=e,n}setStore(e,r){this.storeMap.set(e,r)}removeStore(e){this.storeMap.delete(e)}getStore(e){return this.storeMap.get(e)}getState(e){var r;return(r=this.storeMap.get(e))==null?void 0:r.getState()}getStateObj(e){return{state:this.getState(e),updateState:r=>{this.setState(e,r)}}}setState(e,r){var n;return(n=this.storeMap.get(e))==null?void 0:n.setState(r)}connect(e,r){const n=this.storeMap.get(e);return n?n.subscribe(r):(console.warn("store not exits"),()=>{})}getStateSnapshot(){const e={};return this.storeMap.forEach((r,n)=>{e[n]=this.getStateObj(n)}),e}destroy(){this.storeMap=new Map}}class wv{constructor(){m(this,"varSpace",new Map)}get(e){return this.varSpace.get(e)}add(e,r){this.varSpace.set(e,r)}remove(e){this.varSpace.delete(e)}destroy(){this.varSpace.clear()}getStateSnapshot(){const e={};return this.varSpace.forEach((r,n)=>{e[n]=r}),e}}class ra{constructor(){m(this,"renderMode","normal");m(this,"components",{});m(this,"storeManager",new Ov);m(this,"variableManager",new wv);m(this,"runtimeComponentCache",new Map);m(this,"onGetRef");m(this,"onGetComponent");m(this,"onComponentMount");m(this,"onComponentDestroy");m(this,"processNodeConfigHook")}getComponent(e){var o;const r=e.value.componentName;let n=this.components[r]||(()=>`Component [${r}] not found`);return Ko(n)||(n=Xo(n),this.components[r]=n),this.onGetComponent&&(n=(o=this.onGetComponent)==null?void 0:o.call(this,n,e)),n}getContext(e={},r){let n=e;return r&&(n={...e},n.__proto__=r||null),n}pageRender(e,{components:r,onGetRef:n,$$context:o={},onGetComponent:a,onComponentMount:i,onComponentDestroy:s,renderMode:c,processNodeConfigHook:u}){this.renderMode=c,this.components=r,this.onGetRef=n,this.onGetComponent=a,this.onComponentMount=i,this.onComponentDestroy=s,this.processNodeConfigHook=u;const l=e.value.componentsTree,p=this.getComponent(l),f=this.convertModelToComponent(p,e.value.componentsTree),d={},g=l.props;return Object.keys(g).forEach(y=>{d[y]=g[y].value}),d.$$context=o,this.render(f,d)}transformProps(e={},{$$context:r}){const n=e,o=i=>{if(Array.isArray(i))return i.map(s=>o(s));if(Pe(i))return o(i.value);if(Lf(i)){const s=i.value,c=s.value;if(!c)return console.warn("slot value is null, this maybe cause some error, pls check it",e),()=>{};const u=l=>{const p=`${l.id}-${ue}`;if(this.runtimeComponentCache.get(l.id))return{key:p,component:this.runtimeComponentCache.get(l.id)};const f=this.getComponent(l),d=this.convertModelToComponent(f,l),g=s.params||[];return{component:(...j)=>{const O=tr(j,g),x=this.getContext({params:O},r);return this.render(d,{$$context:x,key:p})},key:p}};if(Array.isArray(c)){const l=c==null?void 0:c.map(p=>u(p));return(...p)=>l.map(f=>Yo(f.component)?S.createElement(f.component,{$$context:r,key:f.key}):f.component(...p))}else return u(c).component}else{if(ct(i))return lt(i.value,r||{});if(Df(i))return Zo(i.value,r,this.storeManager);if(Nt(i)){let s=i;Pe(i)&&(s=i.value);const c=s,u={};return Object.keys(s).forEach(l=>{u[l]=o(c[l])}),u}else return i}},a={};return Object.keys(n).forEach(i=>{const s=n[i];a[i]=o(s)}),a}collectSpecialProps(e={},r){const n=[],o=(a,i)=>{let s=i;Pe(i)&&(s=i.value),r(s)?n.push({keyPath:a,val:s}):Et(s)?s.forEach((c,u)=>{o([...a,String(u)],c)}):Nt(s)&&Object.keys(s).forEach(c=>{o([...a,c],s[c])})};return o(["$root"],e),n}convertModelToComponent(e,r){const n=this;class o extends S.Component{constructor(s){super(s);m(this,"_CONDITION",!0);m(this,"_DESIGN_BOX",!1);m(this,"_NODE_MODEL",r);m(this,"_NODE_ID",r.id);m(this,"UNIQUE_ID",`${r.id}_${Z()}`);m(this,"targetComponentRef");m(this,"listenerHandle",[]);m(this,"storeState");m(this,"storeListenDisposeList",[]);m(this,"domHeader");m(this,"mediaStyleDomMap",{});m(this,"variableSpace");m(this,"nodeName");m(this,"updateState",s=>{this.storeState.setState(s),this.forceUpdate()});m(this,"getStyleDomById",s=>{const c=this.mediaStyleDomMap;let u=c[s];return u||(u=document.createElement("style"),c[s]=u),u.id=s,u});m(this,"addMediaCSS",()=>{var u;let s=this.domHeader;if(s||(s=(u=document.getElementsByTagName("head"))==null?void 0:u[0],this.domHeader=s),!this.domHeader)return;const c=this._NODE_MODEL.value.css;c&&c.value.forEach(l=>{var d;const p=`${this.UNIQUE_ID}_${l.state}`;let f=`.${c.class}`;if(l.state!=="normal"&&(f=`${f}:${l.state}`),Object.keys(l.style).length!==0){const g=this.getStyleDomById(p);g.innerText=`${f} { ${rr(l.style)} }`,s==null||s.appendChild(g)}(d=l.media)!=null&&d.length&&l.media.forEach(g=>{const y=`${p}_${g.type}_${g.value}`,b=this.getStyleDomById(y);b.media=`screen and (${g.type}:${g.value}px)`,b.innerHTML=`${f} { ${rr(g.style)} }`,s==null||s.appendChild(b)})})});m(this,"removeMediaCSS",()=>{const s=this.mediaStyleDomMap;Object.keys(s).forEach(c=>{var u;(u=this.domHeader)==null||u.removeChild(s[c])}),this.mediaStyleDomMap={}});m(this,"rebuildNode",()=>{this.storeListenDisposeList.forEach(s=>s()),this.removeMediaCSS(),this.connectStore(),this.addMediaCSS(),this.forceUpdate()});this.targetComponentRef=S.createRef(),this.state=r.value.state||{};const c=r.value.nodeName||r.id;this.nodeName=c;const u=n.storeManager.getStore(c);u?(this.storeState=u,u.setState({...r.value.state||{}})):this.storeState=n.storeManager.addStore(c,()=>({...r.value.state||{}})),this.storeState.subscribe(p=>{this.setState({...p})}),this.connectStore();const l=n.variableManager.get(c);l?this.variableSpace=l:(this.variableSpace={staticVar:{},methods:{}},n.variableManager.add(c,this.variableSpace))}connectStore(){const s=n.collectSpecialProps(r.props,f=>!!ct(f)),c=n.collectSpecialProps({css:r.value.css,class:r.value.classNames},f=>!!ct(f));let u=[];[...s,...c].map(f=>{const d=f.val,g=[/\$\$context.stateManager\.(.+?)\./gim,/\$\$context.stateManager\["(.+?)"\]/gim,/\$\$context.stateManager\['(.+?)'\]/gim,/getStateObj\('(.+?)'\)/gim,/getStateObj\("(.+?)"\)/gim,/getStateById\('(.+?)'\)/gim,/getStateById\("(.+?)"\)/gim],y=ta(d.value,g);u=[...u,...y]}).filter(Boolean);const l=Array.from(new Set(u)),p=[];l.length&&l.forEach(f=>{n.storeManager.getStore(f)||(n.storeManager.addStore(f,()=>({})),console.warn(n.storeManager,f,"not exits"));const g=n.storeManager.connect(f,()=>{this.forceUpdate()});p.push(g)}),this.storeListenDisposeList=p}componentDidMount(){var c;this.addMediaCSS(),n.onGetRef&&n.onGetRef(this.targetComponentRef,r,this),(c=n.onComponentMount)==null||c.call(n,this,r);const s=()=>{n.storeManager.setStore(r.value.nodeName||r.id,this.storeState),this.storeState.setState({...this.state,...r.value.state||{}}),this.rebuildNode()};r.onChange(s)}componentWillUnmount(){var s;this.storeListenDisposeList.forEach(c=>c()),this.removeMediaCSS(),(s=n.onComponentDestroy)==null||s.call(n,this,r)}render(){var oe;const{$$context:s,...c}=this.props,u=r.value.nodeName||r.id,l={key:r.id,...r.props,...c},p={state:this.state||{},staticVar:this.variableSpace.staticVar,updateState:this.updateState,storeManager:n.storeManager,getState:()=>n.storeManager.getStateObj(u),getStateObj:()=>n.storeManager.getStateObj(u),getStateObjById:R=>n.storeManager.getStateObj(R),stateManager:n.storeManager.getStateSnapshot(),getMethods:()=>n.variableManager.get(u).methods,getMethodsById:R=>n.variableManager.get(R).methods,getStaticVar:()=>n.variableManager.get(u).staticVar,getStaticVarById:R=>n.variableManager.get(R).staticVar};r.value.componentName===xt.ROOT_CONTAINER&&(p.globalState=this.state,p.updateGlobalState=this.updateState);const f=n.getContext(p,s),y=n.transformProps({methods:r.value.methods},{$$context:f}).methods.reduce((R,Q)=>(R[Q.name]=Q.define,R),{});f.methods=y,this.variableSpace.methods=Object.assign(this.variableSpace.methods,y);const b=r.value.loop;let j=[];if(b&&b.open){this.targetComponentRef.current=[];let R=b.data||[];if(ct(b.data)){const Q=b.data;R=lt(Q.value,f||{})}return j=R.map((...Q)=>{var Ir;const Ft=Q[1],bt=[b.forName||"item",b.forIndex||"index"],Ce=tr(Q,bt);let Ee="loopData";b.name&&(Ee=`${Ee}${b.name}`);const Bt=n.getContext({[Ee]:Ce},f),q=n.transformProps(l,{$$context:Bt}),ua=((Ir=r.value.classNames)==null?void 0:Ir.map(G=>{var ie;const se=G.name;return(ct(G.status)?lt(String(((ie=G.status)==null?void 0:ie.value)||""),Bt):!1)?se:""}))||[];let Ne=`${q.className??""} ${ua.join(" ")}`.trim();r.value.css&&(Ne=`${r.value.css.class} ${Ne}`.trim()),q.className=Ne;const la=n.transformProps(r.value.style,{$$context:Bt});r.value.style&&(q.style=er(la||{}));const{children:ae}=q;let $e=[];if(ae!==void 0)delete q.children,$e=Array.isArray(ae)?ae:[ae];else{const G=[];r.value.children.forEach((Lr,ie)=>{const fa=n.buildComponent(Lr,{$$context:Bt,idx:ie});G.push(fa)}),$e=G}if(q.key=`${q.key}-${Ft}`,ct(b.key)){const G=b.key,se=lt(G.value,Bt||{});q.key+=`-${se}`}return q.ref=G=>{this.targetComponentRef.current=this.targetComponentRef.current||[],this.targetComponentRef.current[Ft]=G},n.render(e,q,...$e)}),j}const O=n.transformProps(l,{$$context:f}),{children:x}=O;let M=[];if(x!==void 0)delete O.children,M=Array.isArray(x)?x:[x];else{const R=[];r.value.children.forEach((Ft,bt)=>{const Ce=n.buildComponent(Ft,{$$context:f,idx:bt});R.push(Ce)}),M=R}O.ref=this.targetComponentRef;const I=((oe=r.value.classNames)==null?void 0:oe.map(R=>{var bt;const Q=R.name;return(ct(R.status)?lt(((bt=R.status)==null?void 0:bt.value)||"",f):!1)?Q:""}))||[];let k=`${O.className??""} ${I.join(" ")}`.trim();r.value.css&&(k=`${r.value.css.class} ${k}`.trim()),O.className=k;const Lt=n.transformProps(r.value.style,{$$context:f});r.value.style&&(O.style=er(Lt||{}));let C=r.value.condition??!0;typeof C!="boolean"&&(C=lt(C.value,f||{}));let ot={condition:C,props:O};n.processNodeConfigHook&&(ot=n.processNodeConfigHook(ot,r));const it=n.render(e,ot.props,...M);return this._CONDITION=ot.condition,ot.condition?it:S.createElement("div",{style:{display:"none"}},it)}}return m(o,"__CP_TYPE__",ue),o.displayName=`${r.value.componentName}Dynamic`,o}buildComponent(e,{$$context:r={}}){const n=this.runtimeComponentCache;return typeof e=="string"?this.render(e):If(e)?(({currentNode:a})=>{const i=a.value.id;let s=null;if(n.get(i))s=n.get(i);else{const l=this.getComponent(a);s=this.convertModelToComponent(l,a)}!n.get(i)&&this.renderMode!=="design"&&n.set(i,s);const c=`${i}-${ue}`,u={$$context:r,$$nodeModel:e,key:c};return this.render(s,u)})({currentNode:e}):void 0}render(e,r={},...n){return typeof e=="string"||typeof e=="number"?String(e):(Sv.forEach(a=>{a in r&&e.__CP_TYPE__!==ue&&delete r[a]}),S.createElement(e,r,...n))}clear(){this.runtimeComponentCache.clear(),this.storeManager.destroy()}}const Cv=Dn(new ra),Ev=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","content","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","element","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","image","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","math","menu","menuitem","meta","meter","multicol","nav","nextid","nobr","noembed","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","plaintext","pre","progress","q","rb","rbc","rp","rt","rtc","ruby","s","samp","script","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],nt=t=>{const e={};return t.forEach(r=>{e[r.key]=r.value}),e},Nv=[...Ev,...Sf],$v=Nv.reduce((t,e)=>(t[e]=({children:r,$$attributes:n=[],...o})=>{let a=r;return Array.isArray(r)||(a=[r]),S.createElement(e,{...o,...nt(n)},...a)},t),{}),Tv=({children:t,width:e,height:r,$$attributes:n=[],...o})=>{let a=t;Array.isArray(t)||(a=[t]),a=a.filter(u=>u!==void 0);const{style:i={},...s}=nt(n),c={height:r,width:e,...i,...o.style||{}};return S.createElement("div",{...o,...s,style:c},...a)},Mv=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("canvas",{...r,...nt(e)},...n)},Av=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("img",{...r,...nt(e)},...n)},xv=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("video",{...r,...nt(e)},...n)},Pv=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("audio",{...r,...nt(e)},...n)},Rv=({$$attributes:t=[],content:e,...r})=>S.createElement("span",{...r,...nt(t)},e),Dv=({children:t,$$attributes:e=[],afterMount:r,beforeDestroy:n,...o})=>{let a=t;return Array.isArray(t)||(a=[t]),S.useEffect(()=>(r==null||r(o),()=>{n==null||n(o)}),[]),S.createElement("div",{...o,...nt(e)},...a)},Iv=({children:t,$$attributes:e=[],htmlTag:r="div",...n})=>{let o=t;Array.isArray(t)||(o=[t]);const{style:a={},...i}=nt(e),s={...a,...n.style||{}};return S.createElement(r,{...n,...i,style:s},...o)},Lv={RootContainer:({children:t})=>t,...$v,CContainer:Dv,CVideo:xv,CAudio:Pv,CBlock:Tv,CImage:Av,CText:Rv,CCanvas:Mv,CNativeTag:Iv};class Fv{constructor(){m(this,"refMap",new Map)}get(e){return this.refMap.get(e)}add(e,r){this.refMap.set(e,r)}remove(e){this.refMap.delete(e)}destroy(){this.refMap.clear()}}class na extends S.Component{constructor(r){super(r);m(this,"refManager");m(this,"dynamicComponentInstanceMap",new Map);m(this,"onGetRef",(r,n,o)=>{var a,i;(i=(a=this.props).onGetRef)==null||i.call(a,r,n,o),this.dynamicComponentInstanceMap.set(n.id,o),this.refManager.add(n.value.refId||n.id,r)});m(this,"rerender",r=>{if(this.props.adapter.clear(),(r==null?void 0:r.nodeType)==="PAGE"&&r)this.setState({pageModel:r});else if(Nt(r)&&Oo(r)){const n=r;this.setState({pageModel:new de(n,{materials:this.state.pageModel.materialsModel.rawValue})})}});this.state={pageModel:r.pageModel||new de(r.page)},this.refManager=new Fv}getPageModel(){return this.state.pageModel}componentDidMount(){const{render:r}=this.props;r&&(r.ref.current=this)}componentWillUnmount(){this.refManager.destroy()}render(){const{props:r}=this,{adapter:n,onGetComponent:o,onComponentDestroy:a,onComponentMount:i}=r,{pageModel:s}=this.state;if(!s)return console.warn("pageModel is null"),null;const c={...Lv,...r.components},u=this.props.$$context??{};return u.refs=this.refManager,n.pageRender(s,{libs:{},components:c,onGetRef:this.onGetRef,onGetComponent:o,onComponentMount:i,onComponentDestroy:a,$$context:u,renderMode:r.renderMode,processNodeConfigHook:r.processNodeConfigHook})}}const Bv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)}}};class Uv extends S.Component{constructor(r){super(r);m(this,"onDoubleClick",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:""}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var o,a;(a=(o=this.props).onError)==null||a.call(o,n)}render(){if(this.state.hasError){const{onDoubleClick:r}=this,n=this.props.node.value;console.error(this.props.node,this.props.children);const o=S.createElement("div",{style:{backgroundColor:"rgb(255 206 215 / 13%)",padding:"5px",color:"#ff0000b0",textAlign:"center",fontSize:"12px"}},"Render error, node id: ",n.id,", node name:",n.title," component name:",n.title||n.componentName,S.createElement("p",null,"msg: ",String(this.state.error)),S.createElement("button",{onDoubleClick:r,style:{border:"1px solid rgba(100,100,100,0.1)",backgroundColor:"#fff",padding:"5px 10px",borderRadius:"2px",color:"gray",cursor:"pointer",marginTop:"5px"}},"double click to refresh"),S.createElement("div",{style:{display:"none"}}));return S.createElement(this.props.targetComponent,{onlyRenderChild:!0},o)}return this.props.children}}class oa{constructor(){m(this,"instanceMap",new Map)}get(e){return this.instanceMap.get(e)}add(e,r){const n=this.instanceMap.get(e);n?n.push(r):this.instanceMap.set(e,[r])}remove(e,r){const n=this.instanceMap.get(e);if(r!==void 0&&Array.isArray(n)){const o=n.filter(a=>a!==r);this.instanceMap.set(e,o)}else this.instanceMap.delete(e)}destroy(){this.instanceMap.clear()}}const aa=t=>{const{node:e}=t,r=S.useMemo(()=>{const s=e.isContainer();return Nt(s)?s:{placeholder:"Drag the component to place it",width:"100%",height:"100%",style:{}}},[t.node]),{placeholder:n,height:o,width:a,style:i}=r;return S.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(200,200,200,0.1)",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"2px",fontSize:"14px",color:"gray",cursor:"default",minWidth:"300px",minHeight:"50px",width:a,height:o,...i}},n)};class kv extends S.Component{constructor(r){super(r);m(this,"instanceManager",new oa);m(this,"renderRef");m(this,"dropPlaceholder",aa);m(this,"onGetComponent",(r,n)=>{const o=this;class a extends S.Component{constructor(){super(...arguments);m(this,"_DESIGN_BOX",!0);m(this,"_NODE_MODEL",n);m(this,"_NODE_ID",n.id);m(this,"_UNIQUE_ID",`${n.id}_${Z()}`);m(this,"_STATUS")}componentDidMount(){o.instanceManager.add(n.id,this)}componentWillUnmount(){this._STATUS="DESTROY",o.instanceManager.remove(n.id,this)}render(){const{children:c=[],onlyRenderChild:u,...l}=this.props;let p=c;return Et(c)||(p=[c]),!!!p.filter(Boolean).length&&(n.isContainer()||n.value.componentName===xt.ROOT_CONTAINER)&&p.push(S.createElement(o.dropPlaceholder,{node:n})),u?p:S.createElement(r,l,...p)}}return S.forwardRef(function(s,c){return S.createElement(Uv,{node:n,targetComponent:a},S.createElement(a,{ref:c,...s}))})});this.renderRef=S.createRef(),r.dropPlaceholder&&(this.dropPlaceholder=r.dropPlaceholder)}componentDidMount(){var r,n;(n=(r=this.props).onMount)==null||n.call(r,this)}getPageModel(){var r;return(r=this.renderRef.current)==null?void 0:r.state.pageModel}rerender(r){var n;return(n=this.renderRef.current)==null?void 0:n.rerender(r)}getInstancesById(r,n){let o=[...this.instanceManager.get(r)||[]];return n!==void 0&&(o=o.filter(a=>n===(a==null?void 0:a._UNIQUE_ID))),o}getInstanceByDom(r){const n=sa(r);if(!n)return null;const o=ia(n);return(o==null?void 0:o.stateNode)||null}getDomsById(r,n){const o=this.getInstancesById(r),a=[];return o==null||o.forEach(i=>{if((i==null?void 0:i._STATUS)==="DESTROY")return;const s=ga.findDOMNode(i);if(s&&!(s instanceof Text))if(n){const c=Array.from(s.querySelectorAll(n));a.push(...c)}else a.push(s)}),a}getDomRectById(r,n){return this.getDomsById(r,n).map(i=>i==null?void 0:i.getBoundingClientRect()).filter(Boolean)}render(){const{props:r,onGetComponent:n}=this,{render:o,...a}=r;return o&&(o.ref.current=this),S.createElement(na,{onGetComponent:n,...a,processNodeConfigHook:(i,s)=>{var g,y;if(s.nodeType!=="NODE")return i;const{props:c,condition:u}=i;let l={...c};const p=((g=s.value.configure)==null?void 0:g.devState)||{},f=(y=s.material)==null?void 0:y.value.fixedProps;if(f!==void 0){if(Nt(f))l={...l,...f};else if(typeof f=="function"){const b=f(l);l={...l,...b}}}let d=u;return p.condition===!1&&(d=p.condition),{props:vv(l,p.props||{}),condition:d}},ref:this.renderRef})}}const sa=t=>{if(!t)return null;const e=Object.keys(t).find(r=>r.startsWith("__reactInternalInstance$")||r.startsWith("__reactFiber$"))||"";return e?t[e]:sa(t.parentElement)},ia=t=>{var e;return t?(e=t==null?void 0:t.stateNode)!=null&&e._DESIGN_BOX?t:ia(t.return):null},Vv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)},getInstancesById(e,r){var n;return((n=t.current)==null?void 0:n.getInstancesById(e,r))||[]},getInstanceByDom(e){var r;return((r=t.current)==null?void 0:r.getInstanceByDom(e))||null},getDomsById(e,r){var n;return((n=t.current)==null?void 0:n.getDomsById(e,r))||[]},getDomRectById(e,r){var n;return((n=t.current)==null?void 0:n.getDomRectById(e,r))||[]}}};var zv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Gv(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ca={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(zv,function(){var r=function(){},n={},o={},a={};function i(f,d){f=f.push?f:[f];var g=[],y=f.length,b=y,j,O,x,M;for(j=function(I,k){k.length&&g.push(I),b--,b||d(g)};y--;){if(O=f[y],x=o[O],x){j(O,x);continue}M=a[O]=a[O]||[],M.push(j)}}function s(f,d){if(f){var g=a[f];if(o[f]=d,!!g)for(;g.length;)g[0](f,d),g.splice(0,1)}}function c(f,d){f.call&&(f={success:f}),d.length?(f.error||r)(d):(f.success||r)(f)}function u(f,d,g,y){var b=document,j=g.async,O=(g.numRetries||0)+1,x=g.before||r,M=f.replace(/[\?|#].*$/,""),I=f.replace(/^(css|img|module|nomodule)!/,""),k,Lt,C;if(y=y||0,/(^css!|\.css$)/.test(M))C=b.createElement("link"),C.rel="stylesheet",C.href=I,k="hideFocus"in C,k&&C.relList&&(k=0,C.rel="preload",C.as="style");else if(/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(M))C=b.createElement("img"),C.src=I;else if(C=b.createElement("script"),C.src=I,C.async=j===void 0?!0:j,Lt="noModule"in C,/^module!/.test(M)){if(!Lt)return d(f,"l");C.type="module"}else if(/^nomodule!/.test(M)&&Lt)return d(f,"l");C.onload=C.onerror=C.onbeforeload=function(ot){var it=ot.type[0];if(k)try{C.sheet.cssText.length||(it="e")}catch(oe){oe.code!=18&&(it="e")}if(it=="e"){if(y+=1,y<O)return u(f,d,g,y)}else if(C.rel=="preload"&&C.as=="style")return C.rel="stylesheet";d(f,it,ot.defaultPrevented)},x(f,C)!==!1&&b.head.appendChild(C)}function l(f,d,g){f=f.push?f:[f];var y=f.length,b=y,j=[],O,x;for(O=function(M,I,k){if(I=="e"&&j.push(M),I=="b")if(k)j.push(M);else return;y--,y||d(j)},x=0;x<b;x++)u(f[x],O,g)}function p(f,d,g){var y,b;if(d&&d.trim&&(y=d),b=(y?g:d)||{},y){if(y in n)throw"LoadJS";n[y]=!0}function j(O,x){l(f,function(M){c(b,M),O&&c({success:O,error:x},M),s(y,M)},b)}if(b.returnPromise)return new Promise(j);j()}return p.ready=function(d,g){return i(d,function(y){c(g,y)}),p},p.done=function(d){s(d,[])},p.reset=function(){n={},o={},a={}},p.isDefined=function(d){return d in n},p})})(ca);var Hv=ca.exports;const Rn=Gv(Hv);class Jv{constructor(e,r){m(this,"assets");m(this,"loadStatus");m(this,"win",window);m(this,"_onSuccessList",[]);m(this,"_onErrorList",[]);this.assets=e,this.loadStatus="INIT",r!=null&&r.window&&(this.win=r.window)}load(){const e=this.assets||[],r=[];for(let n=0;n<e.length;n++){const o=e[n];o.id||(o.id=Z()),r.push(o.id);const a=o.resources.map(i=>i.src);Rn(a,o.id,{async:!1,before:(i,s)=>(this.win.document.body.appendChild(s),!1)})}if(e.length===0){this._onSuccessList.forEach(n=>n());return}return new Promise((n,o)=>{Rn.ready(r,{success:()=>{this._onSuccessList.forEach(a=>a()),n("")},error:a=>{this._onErrorList.forEach(i=>i(a)),o(a)}})})}onSuccess(e){return this._onSuccessList.push(e),this}onError(e){return this._onErrorList.push(e),this}}exports.AssetLoader=Jv;exports.ComponentInstanceManager=oa;exports.DefaultDropPlaceholder=aa;exports.DefineReactAdapter=ra;exports.DesignRender=kv;exports.ReactAdapter=Cv;exports.Render=na;exports.canAcceptsRef=Ko;exports.collectVariable=mv;exports.compWrapper=Xo;exports.convertCodeStringToFunction=Zo;exports.flatObject=yv;exports.formatSourceStylePropertyName=er;exports.getAdapter=Dn;exports.getCSSTextValue=rr;exports.getComponentsLibs=bv;exports.getMatchVal=ta;exports.getObjFromArrayMap=tr;exports.getThirdLibs=_v;exports.isClass=gv;exports.runExpression=lt;exports.shouldConstruct=Yo;exports.useDesignRender=Vv;exports.useRender=Bv;
20
+ `;new Function(a)(...o,e,r)}catch(a){console.warn(a)}},tr=(t,e)=>{const r={};return e.forEach((n,o)=>{r[n]=t[o]}),r},er=t=>{const e={};return Object.keys(t).forEach(r=>{let n=r.replace("-webkit","Webkit");n=n.replace("-ms","ms"),n=n.replace("-moz","Moz"),n=n.replace("-o","O");let o=n.split("-");o.length>=2&&(o=o.map((a,i)=>i!==0?qh(a):a)),e[o.join("")]=t[r]}),e},rr=t=>{let e="";return Object.keys(t).forEach(r=>{e+=`${r}:${t[r]};`}),e},mv=(t,e)=>{const r={};return t.forEach(n=>{if(n.globalName){const o=e[n.globalName];o&&(r[n.globalName]=o)}}),r},yv=(t,e=1)=>{let r=0,n=t,o={},a={};for(;r<e;)Object.keys(n).forEach(i=>{o={...o,...n[i]}}),a=o,n=o,o={},r+=1;return a},ta=(t,e)=>{const r=[];return e.forEach(n=>{const a=n.exec(t);a!=null&&a.length&&r.push(a[1])}),r},ea=(t,e)=>{const r={};return e.forEach(n=>{t[n.name]&&(r[n.name]=t[n.name])}),r},bv=(t,e)=>ea(t,e),_v=(t,e)=>ea(t,e),ue="DYNAMIC",Sv=["$$context","$$nodeModel"],Pn=t=>{let e;const r=new Set,n=(c,u)=>{const l=typeof c=="function"?c(e):c;if(!Object.is(l,e)){const p=e;e=u??typeof l!="object"?l:Object.assign({},e,l),r.forEach(f=>f(e,p))}},o=()=>e,s={setState:n,getState:o,subscribe:c=>(r.add(c),()=>r.delete(c)),destroy:()=>{({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),r.clear()}};return e=t(n,o,s),s},jv=t=>t?Pn(t):Pn;class Ov{constructor(){m(this,"storeMap",new Map)}addStore(e,r){const n=jv(r);return this.storeMap.set(e,n),n.name=e,n}setStore(e,r){this.storeMap.set(e,r)}removeStore(e){this.storeMap.delete(e)}getStore(e){return this.storeMap.get(e)}getState(e){var r;return(r=this.storeMap.get(e))==null?void 0:r.getState()}getStateObj(e){return{state:this.getState(e),updateState:r=>{this.setState(e,r)}}}setState(e,r){var n;return(n=this.storeMap.get(e))==null?void 0:n.setState(r)}connect(e,r){const n=this.storeMap.get(e);return n?n.subscribe(r):(console.warn("store not exits"),()=>{})}getStateSnapshot(){const e={};return this.storeMap.forEach((r,n)=>{e[n]=this.getStateObj(n)}),e}destroy(){this.storeMap=new Map}}class wv{constructor(){m(this,"varSpace",new Map)}get(e){return this.varSpace.get(e)}add(e,r){this.varSpace.set(e,r)}remove(e){this.varSpace.delete(e)}destroy(){this.varSpace.clear()}getStateSnapshot(){const e={};return this.varSpace.forEach((r,n)=>{e[n]=r}),e}}class ra{constructor(){m(this,"renderMode","normal");m(this,"components",{});m(this,"storeManager",new Ov);m(this,"variableManager",new wv);m(this,"runtimeComponentCache",new Map);m(this,"onGetRef");m(this,"onGetComponent");m(this,"onComponentMount");m(this,"onComponentDestroy");m(this,"processNodeConfigHook")}getComponent(e){var o;const r=e.value.componentName;let n=this.components[r]||(()=>`Component [${r}] not found`);return Ko(n)||(n=Xo(n),this.components[r]=n),this.onGetComponent&&(n=(o=this.onGetComponent)==null?void 0:o.call(this,n,e)),n}getContext(e={},r){let n=e;return r&&(n={...e},n.__proto__=r||null),n}pageRender(e,{components:r,onGetRef:n,$$context:o={},onGetComponent:a,onComponentMount:i,onComponentDestroy:s,renderMode:c,processNodeConfigHook:u}){this.renderMode=c,this.components=r,this.onGetRef=n,this.onGetComponent=a,this.onComponentMount=i,this.onComponentDestroy=s,this.processNodeConfigHook=u;const l=e.value.componentsTree,p=this.getComponent(l),f=this.convertModelToComponent(p,e.value.componentsTree),d={},g=l.props;return Object.keys(g).forEach(y=>{d[y]=g[y].value}),d.$$context=o,this.render(f,d)}transformProps(e={},{$$context:r}){const n=e,o=i=>{if(Array.isArray(i))return i.map(s=>o(s));if(Pe(i))return o(i.value);if(Lf(i)){const s=i.value,c=s.value;if(!c)return console.warn("slot value is null, this maybe cause some error, pls check it",e),()=>{};const u=l=>{const p=`${l.id}-${ue}`;if(this.runtimeComponentCache.get(l.id))return{key:p,component:this.runtimeComponentCache.get(l.id)};const f=this.getComponent(l),d=this.convertModelToComponent(f,l),g=s.params||[];return{component:(...j)=>{const O=tr(j,g),x=this.getContext({params:O},r);return this.render(d,{$$context:x,key:p})},key:p}};if(Array.isArray(c)){const l=c==null?void 0:c.map(p=>u(p));return(...p)=>l.map(f=>Yo(f.component)?S.createElement(f.component,{$$context:r,key:f.key}):f.component(...p))}else return u(c).component}else{if(ct(i))return lt(i.value,r||{});if(Df(i))return Zo(i.value,r,this.storeManager);if(Nt(i)){let s=i;Pe(i)&&(s=i.value);const c=s,u={};return Object.keys(s).forEach(l=>{u[l]=o(c[l])}),u}else return i}},a={};return Object.keys(n).forEach(i=>{const s=n[i];a[i]=o(s)}),a}collectSpecialProps(e={},r){const n=[],o=(a,i)=>{let s=i;Pe(i)&&(s=i.value),r(s)?n.push({keyPath:a,val:s}):Et(s)?s.forEach((c,u)=>{o([...a,String(u)],c)}):Nt(s)&&Object.keys(s).forEach(c=>{o([...a,c],s[c])})};return o(["$root"],e),n}convertModelToComponent(e,r){const n=this;class o extends S.Component{constructor(s){super(s);m(this,"_CONDITION",!0);m(this,"_DESIGN_BOX",!1);m(this,"_NODE_MODEL",r);m(this,"_NODE_ID",r.id);m(this,"UNIQUE_ID",`${r.id}_${Z()}`);m(this,"targetComponentRef");m(this,"listenerHandle",[]);m(this,"storeState");m(this,"storeListenDisposeList",[]);m(this,"domHeader");m(this,"mediaStyleDomMap",{});m(this,"variableSpace");m(this,"nodeName");m(this,"updateState",s=>{this.storeState.setState(s),this.forceUpdate()});m(this,"getStyleDomById",s=>{const c=this.mediaStyleDomMap;let u=c[s];return u||(u=document.createElement("style"),c[s]=u),u.id=s,u});m(this,"addMediaCSS",()=>{var u;let s=this.domHeader;if(s||(s=(u=document.getElementsByTagName("head"))==null?void 0:u[0],this.domHeader=s),!this.domHeader)return;const c=this._NODE_MODEL.value.css;c&&c.value.forEach(l=>{var d;const p=`${this.UNIQUE_ID}_${l.state}`;let f=`.${c.class}`;if(l.state!=="normal"&&(f=`${f}:${l.state}`),Object.keys(l.style).length!==0){const g=this.getStyleDomById(p);g.innerText=`${f} { ${rr(l.style)} }`,s==null||s.appendChild(g)}(d=l.media)!=null&&d.length&&l.media.forEach(g=>{const y=`${p}_${g.type}_${g.value}`,b=this.getStyleDomById(y);b.media=`screen and (${g.type}:${g.value}px)`,b.innerHTML=`${f} { ${rr(g.style)} }`,s==null||s.appendChild(b)})})});m(this,"removeMediaCSS",()=>{const s=this.mediaStyleDomMap;Object.keys(s).forEach(c=>{var u;(u=this.domHeader)==null||u.removeChild(s[c])}),this.mediaStyleDomMap={}});m(this,"rebuildNode",()=>{this.storeListenDisposeList.forEach(s=>s()),this.removeMediaCSS(),this.connectStore(),this.addMediaCSS(),this.forceUpdate()});this.targetComponentRef=S.createRef(),this.state=r.value.state||{};const c=r.value.nodeName||r.id;this.nodeName=c;const u=n.storeManager.getStore(c);u?(this.storeState=u,u.setState({...r.value.state||{}})):this.storeState=n.storeManager.addStore(c,()=>({...r.value.state||{}})),this.storeState.subscribe(p=>{this.setState({...p})}),this.connectStore();const l=n.variableManager.get(c);l?this.variableSpace=l:(this.variableSpace={staticVar:{},methods:{}},n.variableManager.add(c,this.variableSpace))}connectStore(){const s=n.collectSpecialProps(r.props,f=>!!ct(f)),c=n.collectSpecialProps({css:r.value.css,class:r.value.classNames},f=>!!ct(f));let u=[];[...s,...c].map(f=>{const d=f.val,g=[/\$\$context.stateManager\.(.+?)\./gim,/\$\$context.stateManager\["(.+?)"\]/gim,/\$\$context.stateManager\['(.+?)'\]/gim,/getStateObj\('(.+?)'\)/gim,/getStateObj\("(.+?)"\)/gim,/getStateById\('(.+?)'\)/gim,/getStateById\("(.+?)"\)/gim],y=ta(d.value,g);u=[...u,...y]}).filter(Boolean);const l=Array.from(new Set(u)),p=[];l.length&&l.forEach(f=>{n.storeManager.getStore(f)||(n.storeManager.addStore(f,()=>({})),console.warn(n.storeManager,f,"not exits"));const g=n.storeManager.connect(f,()=>{this.forceUpdate()});p.push(g)}),this.storeListenDisposeList=p}componentDidMount(){var c;this.addMediaCSS(),n.onGetRef&&n.onGetRef(this.targetComponentRef,r,this),(c=n.onComponentMount)==null||c.call(n,this,r);const s=()=>{n.storeManager.setStore(r.value.nodeName||r.id,this.storeState),this.storeState.setState({...this.state,...r.value.state||{}}),this.rebuildNode()};r.onChange(s)}componentWillUnmount(){var s;this.storeListenDisposeList.forEach(c=>c()),this.removeMediaCSS(),(s=n.onComponentDestroy)==null||s.call(n,this,r)}render(){var oe;const{$$context:s,...c}=this.props,u=r.value.nodeName||r.id,l={key:r.id,...r.props,...c},p={state:this.state||{},staticVar:this.variableSpace.staticVar,updateState:this.updateState,storeManager:n.storeManager,getState:()=>n.storeManager.getStateObj(u),getStateObj:()=>n.storeManager.getStateObj(u),getStateObjById:R=>n.storeManager.getStateObj(R),stateManager:n.storeManager.getStateSnapshot(),getMethods:()=>n.variableManager.get(u).methods,getMethodsById:R=>n.variableManager.get(R).methods,getStaticVar:()=>n.variableManager.get(u).staticVar,getStaticVarById:R=>n.variableManager.get(R).staticVar};r.value.componentName===xt.ROOT_CONTAINER&&(p.globalState=this.state,p.updateGlobalState=this.updateState);const f=n.getContext(p,s),y=n.transformProps({methods:r.value.methods},{$$context:f}).methods.reduce((R,Q)=>(R[Q.name]=Q.define,R),{});f.methods=y,this.variableSpace.methods=Object.assign(this.variableSpace.methods,y);const b=r.value.loop;let j=[];if(b&&b.open){this.targetComponentRef.current=[];let R=b.data||[];if(ct(b.data)){const Q=b.data;R=lt(Q.value,f||{})}return j=R.map((...Q)=>{var Ir;const Ft=Q[1],bt=[b.forName||"item",b.forIndex||"index"],Ce=tr(Q,bt);let Ee="loopData";b.name&&(Ee=`${Ee}${b.name}`);const Bt=n.getContext({[Ee]:Ce},f),q=n.transformProps(l,{$$context:Bt}),ua=((Ir=r.value.classNames)==null?void 0:Ir.map(G=>{var ie;const se=G.name;return(ct(G.status)?lt(String(((ie=G.status)==null?void 0:ie.value)||""),Bt):!1)?se:""}))||[];let Ne=`${q.className??""} ${ua.join(" ")}`.trim();r.value.css&&(Ne=`${r.value.css.class} ${Ne}`.trim()),q.className=Ne;const la=n.transformProps(r.value.style,{$$context:Bt});r.value.style&&(q.style=er(la||{}));const{children:ae}=q;let $e=[];if(ae!==void 0)delete q.children,$e=Array.isArray(ae)?ae:[ae];else{const G=[];r.value.children.forEach((Lr,ie)=>{const fa=n.buildComponent(Lr,{$$context:Bt,idx:ie});G.push(fa)}),$e=G}if(q.key=`${q.key}-${Ft}`,ct(b.key)){const G=b.key,se=lt(G.value,Bt||{});q.key+=`-${se}`}return q.ref=G=>{this.targetComponentRef.current=this.targetComponentRef.current||[],this.targetComponentRef.current[Ft]=G},n.render(e,q,...$e)}),j}const O=n.transformProps(l,{$$context:f}),{children:x}=O;let M=[];if(x!==void 0)delete O.children,M=Array.isArray(x)?x:[x];else{const R=[];r.value.children.forEach((Ft,bt)=>{const Ce=n.buildComponent(Ft,{$$context:f,idx:bt});R.push(Ce)}),M=R}O.ref=this.targetComponentRef;const I=((oe=r.value.classNames)==null?void 0:oe.map(R=>{var bt;const Q=R.name;return(ct(R.status)?lt(((bt=R.status)==null?void 0:bt.value)||"",f):!1)?Q:""}))||[];let k=`${O.className??""} ${I.join(" ")}`.trim();r.value.css&&(k=`${r.value.css.class} ${k}`.trim()),O.className=k;const Lt=n.transformProps(r.value.style,{$$context:f});r.value.style&&(O.style=er(Lt||{}));let C=r.value.condition??!0;typeof C!="boolean"&&(C=lt(C.value,f||{}));let ot={condition:C,props:O};n.processNodeConfigHook&&(ot=n.processNodeConfigHook(ot,r));const it=n.render(e,ot.props,...M);return this._CONDITION=ot.condition,ot.condition?it:S.createElement("div",{style:{display:"none"}},it)}}return m(o,"__CP_TYPE__",ue),o.displayName=`${r.value.componentName}Dynamic`,o}buildComponent(e,{$$context:r={}}){const n=this.runtimeComponentCache;return typeof e=="string"?this.render(e):If(e)?(({currentNode:a})=>{const i=a.value.id;let s=null;if(n.get(i))s=n.get(i);else{const l=this.getComponent(a);s=this.convertModelToComponent(l,a)}!n.get(i)&&this.renderMode!=="design"&&n.set(i,s);const c=`${i}-${ue}`,u={$$context:r,$$nodeModel:e,key:c};return this.render(s,u)})({currentNode:e}):void 0}render(e,r={},...n){return typeof e=="string"||typeof e=="number"?String(e):(Sv.forEach(a=>{a in r&&e.__CP_TYPE__!==ue&&delete r[a]}),S.createElement(e,r,...n))}clear(){this.runtimeComponentCache.clear(),this.storeManager.destroy()}}const Cv=Dn(new ra),Ev=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","content","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","element","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","image","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","math","menu","menuitem","meta","meter","multicol","nav","nextid","nobr","noembed","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","plaintext","pre","progress","q","rb","rbc","rp","rt","rtc","ruby","s","samp","script","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],nt=t=>{const e={};return t.forEach(r=>{e[r.key]=r.value}),e},Nv=[...Ev,...Sf],$v=Nv.reduce((t,e)=>(t[e]=({children:r,$$attributes:n=[],...o})=>{let a=r;return Array.isArray(r)||(a=[r]),S.createElement(e,{...o,...nt(n)},...a)},t),{}),Tv=({children:t,width:e,height:r,$$attributes:n=[],...o})=>{let a=t;Array.isArray(t)||(a=[t]),a=a.filter(u=>u!==void 0);const{style:i={},...s}=nt(n),c={height:r,width:e,...i,...o.style||{}};return S.createElement("div",{...o,...s,style:c},...a)},Mv=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("canvas",{...r,...nt(e)},...n)},Av=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("img",{...r,...nt(e)},...n)},xv=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("video",{...r,...nt(e)},...n)},Pv=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("audio",{...r,...nt(e)},...n)},Rv=({$$attributes:t=[],content:e,...r})=>S.createElement("span",{...r,...nt(t)},e),Dv=({children:t,$$attributes:e=[],afterMount:r,beforeDestroy:n,...o})=>{let a=t;return Array.isArray(t)||(a=[t]),S.useEffect(()=>(r==null||r(o),()=>{n==null||n(o)}),[]),S.createElement("div",{...o,...nt(e)},...a)},Iv=({children:t,$$attributes:e=[],htmlTag:r="div",...n})=>{let o=t;Array.isArray(t)||(o=[t]);const{style:a={},...i}=nt(e),s={...a,...n.style||{}};return S.createElement(r,{...n,...i,style:s},...o)},Lv={RootContainer:({children:t})=>t,...$v,CContainer:Dv,CVideo:xv,CAudio:Pv,CBlock:Tv,CImage:Av,CText:Rv,CCanvas:Mv,CNativeTag:Iv};class Fv{constructor(){m(this,"refMap",new Map)}get(e){return this.refMap.get(e)}add(e,r){this.refMap.set(e,r)}remove(e){this.refMap.delete(e)}destroy(){this.refMap.clear()}}class na extends S.Component{constructor(r){super(r);m(this,"refManager");m(this,"dynamicComponentInstanceMap",new Map);m(this,"onGetRef",(r,n,o)=>{var a,i;(i=(a=this.props).onGetRef)==null||i.call(a,r,n,o),this.dynamicComponentInstanceMap.set(n.id,o),this.refManager.add(n.value.refId||n.id,r)});m(this,"rerender",r=>{if(this.props.adapter.clear(),(r==null?void 0:r.nodeType)==="PAGE"&&r)this.setState({pageModel:r});else if(Nt(r)&&Oo(r)){const n=r;this.setState({pageModel:new de(n,{materials:this.state.pageModel.materialsModel.rawValue})})}});this.state={pageModel:r.pageModel||new de(r.page)},this.refManager=new Fv}getPageModel(){return this.state.pageModel}componentDidMount(){const{render:r}=this.props;r&&(r.ref.current=this)}componentWillUnmount(){this.refManager.destroy()}render(){const{props:r}=this,{adapter:n,onGetComponent:o,onComponentDestroy:a,onComponentMount:i}=r,{pageModel:s}=this.state;if(!s)return console.warn("pageModel is null"),null;const c={...Lv,...r.components},u=this.props.$$context??{};return u.refs=this.refManager,n.pageRender(s,{libs:{},components:c,onGetRef:this.onGetRef,onGetComponent:o,onComponentMount:i,onComponentDestroy:a,$$context:u,renderMode:r.renderMode,processNodeConfigHook:r.processNodeConfigHook})}}const Bv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)}}};class Uv extends S.Component{constructor(r){super(r);m(this,"onDoubleClick",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:""}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var o,a;(a=(o=this.props).onError)==null||a.call(o,n)}render(){if(this.state.hasError){const{onDoubleClick:r}=this,n=this.props.node.value;console.error(this.props.node,this.props.children);const o=S.createElement("div",{style:{backgroundColor:"rgb(255 206 215 / 13%)",padding:"5px",color:"#ff0000b0",textAlign:"center",fontSize:"12px"}},"Render error, node id: ",n.id,", node name:",n.title," component name:",n.title||n.componentName,S.createElement("p",null,"msg: ",String(this.state.error)),S.createElement("button",{onDoubleClick:r,style:{border:"1px solid rgba(100,100,100,0.1)",backgroundColor:"#fff",padding:"5px 10px",borderRadius:"2px",color:"gray",cursor:"pointer",marginTop:"5px"}},"double click to refresh"),S.createElement("div",{style:{display:"none"}}));return S.createElement(this.props.targetComponent,{onlyRenderChild:!0},o)}return this.props.children}}class oa{constructor(){m(this,"instanceMap",new Map)}get(e){return this.instanceMap.get(e)}add(e,r){const n=this.instanceMap.get(e);n?n.push(r):this.instanceMap.set(e,[r])}remove(e,r){const n=this.instanceMap.get(e);if(r!==void 0&&Array.isArray(n)){const o=n.filter(a=>a!==r);this.instanceMap.set(e,o)}else this.instanceMap.delete(e)}destroy(){this.instanceMap.clear()}}const aa=t=>{const{node:e}=t,r=S.useMemo(()=>{const s=e.isContainer();return Nt(s)?s:{placeholder:"Drag the component to place it",width:"100%",height:"100%",style:{}}},[t.node]),{placeholder:n,height:o,width:a,style:i}=r;return S.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(200,200,200,0.1)",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"2px",fontSize:"14px",color:"gray",cursor:"default",minWidth:"300px",minHeight:"50px",width:a,height:o,...i}},n)};class kv extends S.Component{constructor(r){super(r);m(this,"instanceManager",new oa);m(this,"renderRef");m(this,"dropPlaceholder",aa);m(this,"onGetComponent",(r,n)=>{const o=this;class a extends S.Component{constructor(){super(...arguments);m(this,"_DESIGN_BOX",!0);m(this,"_NODE_MODEL",n);m(this,"_NODE_ID",n.id);m(this,"_UNIQUE_ID",`${n.id}_${Z()}`);m(this,"_STATUS")}componentDidMount(){o.instanceManager.add(n.id,this)}componentWillUnmount(){this._STATUS="DESTROY",o.instanceManager.remove(n.id,this)}render(){const{children:c=[],onlyRenderChild:u,...l}=this.props;let p=c;return Et(c)||(p=[c]),!!!p.filter(Boolean).length&&(n.isContainer()||n.value.componentName===xt.ROOT_CONTAINER)&&p.push(S.createElement(o.dropPlaceholder,{node:n})),u?p:S.createElement(r,l,...p)}}return S.forwardRef(function(s,c){return S.createElement(Uv,{node:n,targetComponent:a},S.createElement(a,{ref:c,...s}))})});this.renderRef=S.createRef(),r.dropPlaceholder&&(this.dropPlaceholder=r.dropPlaceholder)}componentDidMount(){var r,n;(n=(r=this.props).onMount)==null||n.call(r,this)}getPageModel(){var r;return(r=this.renderRef.current)==null?void 0:r.state.pageModel}rerender(r){var n;return(n=this.renderRef.current)==null?void 0:n.rerender(r)}getInstancesById(r,n){let o=[...this.instanceManager.get(r)||[]];return n!==void 0&&(o=o.filter(a=>n===(a==null?void 0:a._UNIQUE_ID))),o}getInstanceByDom(r){const n=sa(r);if(!n)return null;const o=ia(n);return(o==null?void 0:o.stateNode)||null}getDomsById(r,n){const o=this.getInstancesById(r),a=[];return o==null||o.forEach(i=>{var c;if((i==null?void 0:i._STATUS)==="DESTROY")return;const s=ga.findDOMNode(i);if(s&&!(s instanceof Text))if(n){const u=Array.from(((c=s.querySelectorAll)==null?void 0:c.call(s,n))||[]);a.push(...u)}else a.push(s)}),a}getDomRectById(r,n){return this.getDomsById(r,n).map(i=>i==null?void 0:i.getBoundingClientRect()).filter(Boolean)}render(){const{props:r,onGetComponent:n}=this,{render:o,...a}=r;return o&&(o.ref.current=this),S.createElement(na,{onGetComponent:n,...a,processNodeConfigHook:(i,s)=>{var g,y;if(s.nodeType!=="NODE")return i;const{props:c,condition:u}=i;let l={...c};const p=((g=s.value.configure)==null?void 0:g.devState)||{},f=(y=s.material)==null?void 0:y.value.fixedProps;if(f!==void 0){if(Nt(f))l={...l,...f};else if(typeof f=="function"){const b=f(l);l={...l,...b}}}let d=u;return p.condition===!1&&(d=p.condition),{props:vv(l,p.props||{}),condition:d}},ref:this.renderRef})}}const sa=t=>{if(!t)return null;const e=Object.keys(t).find(r=>r.startsWith("__reactInternalInstance$")||r.startsWith("__reactFiber$"))||"";return e?t[e]:sa(t.parentElement)},ia=t=>{var e;return t?(e=t==null?void 0:t.stateNode)!=null&&e._DESIGN_BOX?t:ia(t.return):null},Vv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)},getInstancesById(e,r){var n;return((n=t.current)==null?void 0:n.getInstancesById(e,r))||[]},getInstanceByDom(e){var r;return((r=t.current)==null?void 0:r.getInstanceByDom(e))||null},getDomsById(e,r){var n;return((n=t.current)==null?void 0:n.getDomsById(e,r))||[]},getDomRectById(e,r){var n;return((n=t.current)==null?void 0:n.getDomRectById(e,r))||[]}}};var zv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Gv(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ca={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(zv,function(){var r=function(){},n={},o={},a={};function i(f,d){f=f.push?f:[f];var g=[],y=f.length,b=y,j,O,x,M;for(j=function(I,k){k.length&&g.push(I),b--,b||d(g)};y--;){if(O=f[y],x=o[O],x){j(O,x);continue}M=a[O]=a[O]||[],M.push(j)}}function s(f,d){if(f){var g=a[f];if(o[f]=d,!!g)for(;g.length;)g[0](f,d),g.splice(0,1)}}function c(f,d){f.call&&(f={success:f}),d.length?(f.error||r)(d):(f.success||r)(f)}function u(f,d,g,y){var b=document,j=g.async,O=(g.numRetries||0)+1,x=g.before||r,M=f.replace(/[\?|#].*$/,""),I=f.replace(/^(css|img|module|nomodule)!/,""),k,Lt,C;if(y=y||0,/(^css!|\.css$)/.test(M))C=b.createElement("link"),C.rel="stylesheet",C.href=I,k="hideFocus"in C,k&&C.relList&&(k=0,C.rel="preload",C.as="style");else if(/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(M))C=b.createElement("img"),C.src=I;else if(C=b.createElement("script"),C.src=I,C.async=j===void 0?!0:j,Lt="noModule"in C,/^module!/.test(M)){if(!Lt)return d(f,"l");C.type="module"}else if(/^nomodule!/.test(M)&&Lt)return d(f,"l");C.onload=C.onerror=C.onbeforeload=function(ot){var it=ot.type[0];if(k)try{C.sheet.cssText.length||(it="e")}catch(oe){oe.code!=18&&(it="e")}if(it=="e"){if(y+=1,y<O)return u(f,d,g,y)}else if(C.rel=="preload"&&C.as=="style")return C.rel="stylesheet";d(f,it,ot.defaultPrevented)},x(f,C)!==!1&&b.head.appendChild(C)}function l(f,d,g){f=f.push?f:[f];var y=f.length,b=y,j=[],O,x;for(O=function(M,I,k){if(I=="e"&&j.push(M),I=="b")if(k)j.push(M);else return;y--,y||d(j)},x=0;x<b;x++)u(f[x],O,g)}function p(f,d,g){var y,b;if(d&&d.trim&&(y=d),b=(y?g:d)||{},y){if(y in n)throw"LoadJS";n[y]=!0}function j(O,x){l(f,function(M){c(b,M),O&&c({success:O,error:x},M),s(y,M)},b)}if(b.returnPromise)return new Promise(j);j()}return p.ready=function(d,g){return i(d,function(y){c(g,y)}),p},p.done=function(d){s(d,[])},p.reset=function(){n={},o={},a={}},p.isDefined=function(d){return d in n},p})})(ca);var Hv=ca.exports;const Rn=Gv(Hv);class Jv{constructor(e,r){m(this,"assets");m(this,"loadStatus");m(this,"win",window);m(this,"_onSuccessList",[]);m(this,"_onErrorList",[]);this.assets=e,this.loadStatus="INIT",r!=null&&r.window&&(this.win=r.window)}load(){const e=this.assets||[],r=[];for(let n=0;n<e.length;n++){const o=e[n];o.id||(o.id=Z()),r.push(o.id);const a=o.resources.map(i=>i.src);Rn(a,o.id,{async:!1,before:(i,s)=>(this.win.document.body.appendChild(s),!1)})}if(e.length===0){this._onSuccessList.forEach(n=>n());return}return new Promise((n,o)=>{Rn.ready(r,{success:()=>{this._onSuccessList.forEach(a=>a()),n("")},error:a=>{this._onErrorList.forEach(i=>i(a)),o(a)}})})}onSuccess(e){return this._onSuccessList.push(e),this}onError(e){return this._onErrorList.push(e),this}}exports.AssetLoader=Jv;exports.ComponentInstanceManager=oa;exports.DefaultDropPlaceholder=aa;exports.DefineReactAdapter=ra;exports.DesignRender=kv;exports.ReactAdapter=Cv;exports.Render=na;exports.canAcceptsRef=Ko;exports.collectVariable=mv;exports.compWrapper=Xo;exports.convertCodeStringToFunction=Zo;exports.flatObject=yv;exports.formatSourceStylePropertyName=er;exports.getAdapter=Dn;exports.getCSSTextValue=rr;exports.getComponentsLibs=bv;exports.getMatchVal=ta;exports.getObjFromArrayMap=tr;exports.getThirdLibs=_v;exports.isClass=gv;exports.runExpression=lt;exports.shouldConstruct=Yo;exports.useDesignRender=Vv;exports.useRender=Bv;
21
21
  //# sourceMappingURL=index.js.map