@chamn/render 0.0.13 → 0.0.14

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.umd.js CHANGED
@@ -14,5 +14,5 @@
14
14
  var $$context = args.pop();
15
15
  $$context.stateManager = __$$storeManager__.getStateSnapshot();
16
16
  return f.apply(f, args)
17
- `;new Function(a)(...o,e,r)}catch(a){console.warn(a)}},Ar=(t,e)=>{const r={};return e.forEach((n,o)=>{r[n]=t[o]}),r},Mr=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,s)=>s!==0?Uh(a):a)),e[o.join("")]=t[r]}),e},Pr=t=>{let e="";return Object.keys(t).forEach(r=>{e+=`${r}:${t[r]};`}),e},cv=(t,e)=>{const r={};return t.forEach(n=>{if(n.globalName){const o=e[n.globalName];o&&(r[n.globalName]=o)}}),r},uv=(t,e=1)=>{let r=0,n=t,o={},a={};for(;r<e;)Object.keys(n).forEach(s=>{o={...o,...n[s]}}),a=o,n=o,o={},r+=1;return a},je="DYNAMIC",lv=["$$context","$$nodeModel"],Ko=t=>{let e;const r=new Set,n=(c,u)=>{const l=typeof c=="function"?c(e):c;if(!Object.is(l,e)){const d=e;e=u??typeof l!="object"?l:Object.assign({},e,l),r.forEach(f=>f(e,d))}},o=()=>e,i={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,i),i},fv=t=>t?Ko(t):Ko;var dv=t=>(({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&console.warn("[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'."),fv(t));class pv{constructor(){b(this,"storeMap",new Map)}addStore(e,r){const n=dv(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)}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]={state:r.getState(),updateState:o=>{r.setState(o)}}}),e}destroy(){this.storeMap.forEach(e=>{e.destroy()}),this.storeMap=new Map}}class hv{constructor(){b(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 Xo{constructor(){b(this,"renderMode","normal");b(this,"components",{});b(this,"storeManager",new pv);b(this,"variableManager",new hv);b(this,"runtimeComponentCache",new Map);b(this,"onGetRef");b(this,"onGetComponent");b(this,"onComponentMount");b(this,"onComponentDestroy");b(this,"processNodeConfigHook")}getComponent(e){var o;const r=e.value.componentName;let n=this.components[r]||(()=>`Component [${r}] not found`);return Qo(n)||(n=qo(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={variableSpace:{},...e},n.__proto__=r||null),n}pageRender(e,{components:r,onGetRef:n,$$context:o={},onGetComponent:a,onComponentMount:s,onComponentDestroy:i,renderMode:c,processNodeConfigHook:u}){this.renderMode=c,this.components=r,this.onGetRef=n,this.onGetComponent=a,this.onComponentMount=s,this.onComponentDestroy=i,this.processNodeConfigHook=u;const l=e.value.componentsTree,d=this.getComponent(l),f=this.convertModelToComponent(d,e.value.componentsTree),p={},m=l.props;return Object.keys(m).forEach(v=>{p[v]=m[v].value}),p.$$context=o,this.render(f,p)}transformProps(e={},{$$context:r}){const n=e,o=s=>{if(Array.isArray(s))return s.map(i=>o(i));if(vr(s))return o(s.value);if(Tf(s)){const i=s.value,c=i.value;if(!c)return console.warn("slot value is null, this maybe cause some error, pls check it",e),()=>{};const u=l=>{const d=`${l.id}-${je}`;if(this.runtimeComponentCache.get(l.id))return{key:d,component:this.runtimeComponentCache.get(l.id)};const f=this.getComponent(l),p=this.convertModelToComponent(f,l),m=i.params||[];return{component:(...O)=>{const E=Ar(O,m),D=this.getContext({params:E},r);return this.render(p,{$$context:D,key:d})},key:d}};if(Array.isArray(c)){const l=c==null?void 0:c.map(d=>u(d));return(...d)=>l.map(f=>Wo(f.component)?_.createElement(f.component,{$$context:r,key:f.key}):f.component(...d))}else return u(c).component}else{if(vt(s))return bt(s.value,r||{});if(Nf(s))return Yo(s.value,r,this.storeManager);if(Rt(s)){let i=s;vr(s)&&(i=s.value);const c=i,u={};return Object.keys(i).forEach(l=>{u[l]=o(c[l])}),u}else return s}},a={};return Object.keys(n).forEach(s=>{const i=n[s];a[s]=o(i)}),a}collectSpecialProps(e={},r){const n=[],o=(a,s)=>{let i=s;vr(s)&&(i=s.value),r(i)?n.push({keyPath:a,val:i}):xt(i)?i.forEach((c,u)=>{o([...a,String(u)],c)}):Rt(i)&&Object.keys(i).forEach(c=>{o([...a,c],i[c])})};return o(["$root"],e),n}convertModelToComponent(e,r){const n=this;class o extends _.Component{constructor(i){super(i);b(this,"_CONDITION",!0);b(this,"_DESIGN_BOX",!1);b(this,"_NODE_MODEL",r);b(this,"_NODE_ID",r.id);b(this,"UNIQUE_ID",`${r.id}_${K()}`);b(this,"targetComponentRef");b(this,"listenerHandle",[]);b(this,"storeState");b(this,"staticState",{});b(this,"storeListenDisposeLint",[]);b(this,"domHeader");b(this,"mediaStyleDomMap",{});b(this,"variableSpace");b(this,"nodeName");b(this,"updateState",i=>{this.storeState.setState(i),this.forceUpdate()});b(this,"getStyleDomById",i=>{const c=this.mediaStyleDomMap;let u=c[i];return u||(u=document.createElement("style"),u.type="text/css",c[i]=u),u.id=i,u});b(this,"addMediaCSS",()=>{var u;let i=this.domHeader;if(i||(i=(u=document.getElementsByTagName("head"))==null?void 0:u[0],this.domHeader=i),!this.domHeader)return;const c=this._NODE_MODEL.value.css;c&&c.value.forEach(l=>{var p;const d=`${this.UNIQUE_ID}_${l.state}`;let f=`.${c.class}`;if(l.state!=="normal"&&(f=`${f}:${l.state}`),Object.keys(l.style).length!==0){const m=this.getStyleDomById(d);m.innerText=`${f} { ${Pr(l.style)} }`,i==null||i.appendChild(m)}(p=l.media)!=null&&p.length&&l.media.forEach(m=>{const v=`${d}_${m.type}_${m.value}`,j=this.getStyleDomById(v);j.media=`screen and (${m.type}:${m.value}px)`,j.innerHTML=`${f} { ${Pr(m.style)} }`,i==null||i.appendChild(j)})})});b(this,"removeMediaCSS",()=>{const i=this.mediaStyleDomMap;Object.keys(i).forEach(c=>{var u;(u=this.domHeader)==null||u.removeChild(i[c])})});b(this,"rebuildNode",()=>{this.storeListenDisposeLint.forEach(i=>i()),this.removeMediaCSS(),this.connectStore(),this.addMediaCSS(),this.forceUpdate()});this.targetComponentRef=_.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(d=>{this.setState({...d})}),this.connectStore();const l=n.variableManager.get(c);l?this.variableSpace=l:(this.variableSpace={},n.variableManager.add(c,this.variableSpace))}connectStore(){const i=n.collectSpecialProps(r.props,f=>!!vt(f)),c=n.collectSpecialProps({css:r.value.css,class:r.value.classNames},f=>!!vt(f)),u=[...i,...c].map(f=>{const p=f.val,v=/\$\$context.stateManager\.(.+?)\./gim.exec(p.value);return v!=null&&v.length?v[1]:""}).filter(Boolean),l=Array.from(new Set(u)),d=[];l.length&&l.forEach(f=>{n.storeManager.getStore(f)||(n.storeManager.addStore(f,()=>({})),console.log(n.storeManager,f,"not exits"));const m=n.storeManager.connect(f,()=>{this.forceUpdate()});d.push(m)}),this.storeListenDisposeLint=d}componentDidMount(){var c;this.addMediaCSS(),n.onGetRef&&n.onGetRef(this.targetComponentRef,r,this),(c=n.onComponentMount)==null||c.call(n,this,r);const i=()=>{n.storeManager.setStore(r.value.nodeName||r.id,this.storeState),this.storeState.setState({...this.state,...r.value.state||{}}),this.rebuildNode()};r.onChange(i)}componentWillUnmount(){var i;this.storeListenDisposeLint.forEach(c=>c()),this.removeMediaCSS(),(i=n.onComponentDestroy)==null||i.call(n,this,r)}render(){var _t;const{$$context:i,...c}=this.props,u={key:r.id,...r.props,...c},l={state:this.state||{},variableSpace:this.variableSpace,updateState:this.updateState,staticState:this.staticState};r.value.componentName===Tt.ROOT_CONTAINER&&(l.globalState=this.state,l.updateGlobalState=this.updateState),l.stateManager=n.storeManager.getStateSnapshot(),l.variableSpace=n.variableManager.get(this.nodeName),l.variableManager=n.variableManager.getStateSnapshot();const d=n.getContext(l,i),m=n.transformProps({methods:r.value.methods},{$$context:d}).methods.reduce((L,Z)=>(L[Z.name]=Z.define,L),{});d.methods=m,d.variableSpace||(d.variableSpace={}),d.variableSpace.methods=m;const v=r.value.loop;let j=[];if(v&&v.open){this.targetComponentRef.current=[];let L=v.data||[];if(vt(v.data)){const Z=v.data;L=bt(Z.value,d||{})}return j=L.map((...Z)=>{var ia;const oe=Z[1],Ft=[v.forName||"item",v.forIndex||"index"],Dr=Ar(Z,Ft);let xr="loopData";v.name&&(xr=`${xr}${v.name}`);const ae=n.getContext({[xr]:Dr,staticState:this.staticState},d),tt=n.transformProps(u,{$$context:ae}),$v=((ia=r.value.classNames)==null?void 0:ia.map(W=>{var we;const Ce=W.name;return(vt(W.status)?bt(String(((we=W.status)==null?void 0:we.value)||""),ae):!1)?Ce:""}))||[];let Ir=`${tt.className??""} ${$v.join(" ")}`.trim();r.value.css&&(Ir=`${r.value.css.class} ${Ir}`.trim()),tt.className=Ir;const Tv=n.transformProps(r.value.style,{$$context:ae});r.value.style&&(tt.style=Mr(Tv||{}));const{children:Oe}=tt;let Rr=[];if(Oe!==void 0)delete tt.children,Rr=Array.isArray(Oe)?Oe:[Oe];else{const W=[];r.value.children.forEach((sa,we)=>{const Av=n.buildComponent(sa,{$$context:ae,idx:we});W.push(Av)}),Rr=W}if(tt.key=`${tt.key}-${oe}`,vt(v.key)){const W=v.key,Ce=bt(W.value,ae||{});tt.key+=`-${Ce}`}return tt.ref=W=>{this.targetComponentRef.current=this.targetComponentRef.current||[],this.targetComponentRef.current[oe]=W},n.render(e,tt,...Rr)}),j}const O=n.transformProps(u,{$$context:d}),{children:E}=O;let D=[];if(E!==void 0)delete O.children,D=Array.isArray(E)?E:[E];else{const L=[];r.value.children.forEach((oe,Ft)=>{const Dr=n.buildComponent(oe,{$$context:d,idx:Ft});L.push(Dr)}),D=L}O.ref=this.targetComponentRef;const x=((_t=r.value.classNames)==null?void 0:_t.map(L=>{var Ft;const Z=L.name;return(vt(L.status)?bt(((Ft=L.status)==null?void 0:Ft.value)||"",d):!1)?Z:""}))||[];let R=`${O.className??""} ${x.join(" ")}`.trim();r.value.css&&(R=`${r.value.css.class} ${R}`.trim()),O.className=R;const X=n.transformProps(r.value.style,{$$context:d});r.value.style&&(O.style=Mr(X||{}));let st=r.value.condition??!0;typeof st!="boolean"&&(st=bt(st.value,d||{}));let w={condition:st,props:O};n.processNodeConfigHook&&(w=n.processNodeConfigHook(w,r));const ne=n.render(e,w.props,...D);return this._CONDITION=w.condition,w.condition?ne:_.createElement("div",{style:{display:"none"}},ne)}}return b(o,"__CP_TYPE__",je),o.displayName=`${r.value.componentName}Dynamic`,o}buildComponent(e,{$$context:r={}}){const n=this.runtimeComponentCache;return typeof e=="string"?this.render(e):$f(e)?(({currentNode:a})=>{const s=a.value.id;let i=null;if(n.get(s))i=n.get(s);else{const l=this.getComponent(a);i=this.convertModelToComponent(l,a)}!n.get(s)&&this.renderMode!=="design"&&n.set(s,i);const c=`${s}-${je}`,u={$$context:r,$$nodeModel:e,key:c};return this.render(i,u)})({currentNode:e}):void 0}render(e,r={},...n){return typeof e=="string"||typeof e=="number"?String(e):(lv.forEach(a=>{a in r&&e.__CP_TYPE__!==je&&delete r[a]}),_.createElement(e,r,...n))}clear(){this.runtimeComponentCache.clear(),this.storeManager.destroy()}}const vv=Fr(new Xo),mv=["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","search","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"],ot=t=>{const e={};return t.forEach(r=>{e[r.key]=r.value}),e},gv=[...mv,...pf].reduce((t,e)=>(t[e]=({children:r,$$attributes:n=[],...o})=>{let a=r;return Array.isArray(r)||(a=[r]),_.createElement(e,{...o,...ot(n)},...a)},t),{}),yv={RootContainer:({children:t})=>t,...gv,CContainer:({children:t,$$attributes:e=[],afterMount:r,beforeDestroy:n,...o})=>{let a=t;return Array.isArray(t)||(a=[t]),_.useEffect(()=>(r==null||r(o),()=>{n==null||n(o)}),[]),_.createElement("div",{...o,...ot(e)},...a)},CVideo:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("video",{...r,...ot(e)},...n)},CAudio:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("audio",{...r,...ot(e)},...n)},CBlock:({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:s={},...i}=ot(n),c={height:r,width:e,...s,...o.style||{}};return _.createElement("div",{...o,...i,style:c},...a)},CImage:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("img",{...r,...ot(e)},...n)},CText:({$$attributes:t=[],content:e,...r})=>_.createElement("span",{...r,...ot(t)},e),CCanvas:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("canvas",{...r,...ot(e)},...n)},CNativeTag:({children:t,$$attributes:e=[],htmlTag:r="div",...n})=>{let o=t;Array.isArray(t)||(o=[t]);const{style:a={},...s}=ot(e),i={...a,...n.style||{}};return _.createElement(r,{...n,...s,style:i},...o)}};class bv{constructor(){b(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 Zo extends _.Component{constructor(r){super(r);b(this,"refManager");b(this,"dynamicComponentInstanceMap",new Map);b(this,"onGetRef",(r,n,o)=>{var a,s;(s=(a=this.props).onGetRef)==null||s.call(a,r,n,o),this.dynamicComponentInstanceMap.set(n.id,o),this.refManager.add(n.value.refId||n.id,r)});b(this,"rerender",r=>{if(this.props.adapter.clear(),(r==null?void 0:r.nodeType)==="PAGE"&&r)this.setState({pageModel:r});else if(Rt(r)&&oo(r)){const n=r;this.setState({pageModel:new ge(n,{materials:this.state.pageModel.materialsModel.rawValue})})}});this.state={pageModel:r.pageModel||new ge(r.page)},this.refManager=new bv}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:s}=r,{pageModel:i}=this.state;if(!i)return console.warn("pageModel is null"),null;const c={...yv,...r.components};return n.pageRender(i,{libs:{},components:c,onGetRef:this.onGetRef,onGetComponent:o,onComponentMount:s,onComponentDestroy:a,$$context:{refs:this.refManager},renderMode:r.renderMode,processNodeConfigHook:r.processNodeConfigHook})}}const _v=()=>{const t=_.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)}}};class Sv extends _.Component{constructor(r){super(r);b(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=_.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,_.createElement("p",null,"msg: ",String(this.state.error)),_.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"),_.createElement("div",{style:{display:"none"}}));return _.createElement(this.props.targetComponent,{onlyRenderChild:!0},o)}return this.props.children}}class ta{constructor(){b(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 ea=t=>{const{node:e}=t,r=_.useMemo(()=>{const i=e.isContainer();return Rt(i)?i:{placeholder:"Drag the component to place it",width:"100%",height:"100%",style:{}}},[t.node]),{placeholder:n,height:o,width:a,style:s}=r;return _.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,...s}},n)};class jv extends _.Component{constructor(r){super(r);b(this,"instanceManager",new ta);b(this,"renderRef");b(this,"dropPlaceholder",ea);b(this,"onGetComponent",(r,n)=>{const o=this;class a extends _.Component{constructor(){super(...arguments);b(this,"_DESIGN_BOX",!0);b(this,"_NODE_MODEL",n);b(this,"_NODE_ID",n.id);b(this,"_UNIQUE_ID",`${n.id}_${K()}`);b(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 d=c;return xt(c)||(d=[c]),!!!d.filter(Boolean).length&&(n.isContainer()||n.value.componentName===Tt.ROOT_CONTAINER)&&d.push(_.createElement(o.dropPlaceholder,{node:n})),u?d:_.createElement(r,l,...d)}}return _.forwardRef(function(i,c){return _.createElement(Sv,{node:n,targetComponent:a},_.createElement(a,{ref:c,...i}))})});this.renderRef=_.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=ra(r);if(!n)return null;const o=na(n);return(o==null?void 0:o.stateNode)||null}getDomsById(r,n){const o=this.getInstancesById(r),a=[];return o==null||o.forEach(s=>{if((s==null?void 0:s._STATUS)==="DESTROY")return;const i=ua.findDOMNode(s);if(i&&!(i instanceof Text))if(n){const c=Array.from(i.querySelectorAll(n));a.push(...c)}else a.push(i)}),a}getDomRectById(r,n){return this.getDomsById(r,n).map(s=>s==null?void 0:s.getBoundingClientRect()).filter(Boolean)}render(){const{props:r,onGetComponent:n}=this,{render:o,...a}=r;return o&&(o.ref.current=this),_.createElement(Zo,{onGetComponent:n,...a,processNodeConfigHook:(s,i)=>{var m,v;if(i.nodeType!=="NODE")return s;const{props:c,condition:u}=s;let l={...c};const d=((m=i.value.configure)==null?void 0:m.devState)||{},f=(v=i.material)==null?void 0:v.value.fixedProps;if(f!==void 0){if(Rt(f))l={...l,...f};else if(typeof f=="function"){const j=f(l);l={...l,...j}}}let p=u;return d.condition===!1&&(p=d.condition),{props:iv(l,d.props||{}),condition:p}},ref:this.renderRef})}}const ra=t=>{if(!t)return null;const e=Object.keys(t).find(r=>r.startsWith("__reactInternalInstance$")||r.startsWith("__reactFiber$"))||"";return e?t[e]:ra(t.parentElement)},na=t=>{var e;return t?(e=t==null?void 0:t.stateNode)!=null&&e._DESIGN_BOX?t:na(t.return):null},Ov=()=>{const t=_.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 Cv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wv(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var oa={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(Cv,function(){var r=function(){},n={},o={},a={};function s(f,p){f=f.push?f:[f];var m=[],v=f.length,j=v,O,E,D,x;for(O=function(R,X){X.length&&m.push(R),j--,j||p(m)};v--;){if(E=f[v],D=o[E],D){O(E,D);continue}x=a[E]=a[E]||[],x.push(O)}}function i(f,p){if(f){var m=a[f];if(o[f]=p,!!m)for(;m.length;)m[0](f,p),m.splice(0,1)}}function c(f,p){f.call&&(f={success:f}),p.length?(f.error||r)(p):(f.success||r)(f)}function u(f,p,m,v){var j=document,O=m.async,E=(m.numRetries||0)+1,D=m.before||r,x=f.replace(/[\?|#].*$/,""),R=f.replace(/^(css|img|module|nomodule)!/,""),X,st,w;if(v=v||0,/(^css!|\.css$)/.test(x))w=j.createElement("link"),w.rel="stylesheet",w.href=R,X="hideFocus"in w,X&&w.relList&&(X=0,w.rel="preload",w.as="style");else if(/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(x))w=j.createElement("img"),w.src=R;else if(w=j.createElement("script"),w.src=R,w.async=O===void 0?!0:O,st="noModule"in w,/^module!/.test(x)){if(!st)return p(f,"l");w.type="module"}else if(/^nomodule!/.test(x)&&st)return p(f,"l");w.onload=w.onerror=w.onbeforeload=function(ne){var _t=ne.type[0];if(X)try{w.sheet.cssText.length||(_t="e")}catch(L){L.code!=18&&(_t="e")}if(_t=="e"){if(v+=1,v<E)return u(f,p,m,v)}else if(w.rel=="preload"&&w.as=="style")return w.rel="stylesheet";p(f,_t,ne.defaultPrevented)},D(f,w)!==!1&&j.head.appendChild(w)}function l(f,p,m){f=f.push?f:[f];var v=f.length,j=v,O=[],E,D;for(E=function(x,R,X){if(R=="e"&&O.push(x),R=="b")if(X)O.push(x);else return;v--,v||p(O)},D=0;D<j;D++)u(f[D],E,m)}function d(f,p,m){var v,j;if(p&&p.trim&&(v=p),j=(v?m:p)||{},v){if(v in n)throw"LoadJS";n[v]=!0}function O(E,D){l(f,function(x){c(j,x),E&&c({success:E,error:D},x),i(v,x)},j)}if(j.returnPromise)return new Promise(O);O()}return d.ready=function(p,m){return s(p,function(v){c(m,v)}),d},d.done=function(p){i(p,[])},d.reset=function(){n={},o={},a={}},d.isDefined=function(p){return p in n},d})})(oa);var Ev=oa.exports;const aa=wv(Ev);class Nv{constructor(e,r){b(this,"assets");b(this,"loadStatus");b(this,"win",window);b(this,"_onSuccessList",[]);b(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=K()),r.push(o.id);const a=o.resources.map(s=>s.src);aa(a,o.id,{async:!1,before:(s,i)=>(this.win.document.body.appendChild(i),!1)})}if(e.length===0){this._onSuccessList.forEach(n=>n());return}return new Promise((n,o)=>{aa.ready(r,{success:()=>{this._onSuccessList.forEach(a=>a()),n("")},error:a=>{this._onErrorList.forEach(s=>s(a)),o(a)}})})}onSuccess(e){return this._onSuccessList.push(e),this}onError(e){return this._onErrorList.push(e),this}}y.AssetLoader=Nv,y.ComponentInstanceManager=ta,y.DefaultDropPlaceholder=ea,y.DefineReactAdapter=Xo,y.DesignRender=jv,y.ReactAdapter=vv,y.Render=Zo,y.canAcceptsRef=Qo,y.collectVariable=cv,y.compWrapper=qo,y.convertCodeStringToFunction=Yo,y.flatObject=uv,y.formatSourceStylePropertyName=Mr,y.getAdapter=Fr,y.getCSSTextValue=Pr,y.getObjFromArrayMap=Ar,y.isClass=sv,y.runExpression=bt,y.shouldConstruct=Wo,y.useDesignRender=Ov,y.useRender=_v,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
17
+ `;new Function(a)(...o,e,r)}catch(a){console.warn(a)}},Ar=(t,e)=>{const r={};return e.forEach((n,o)=>{r[n]=t[o]}),r},Mr=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,s)=>s!==0?Uh(a):a)),e[o.join("")]=t[r]}),e},Pr=t=>{let e="";return Object.keys(t).forEach(r=>{e+=`${r}:${t[r]};`}),e},cv=(t,e)=>{const r={};return t.forEach(n=>{if(n.globalName){const o=e[n.globalName];o&&(r[n.globalName]=o)}}),r},uv=(t,e=1)=>{let r=0,n=t,o={},a={};for(;r<e;)Object.keys(n).forEach(s=>{o={...o,...n[s]}}),a=o,n=o,o={},r+=1;return a},je="DYNAMIC",lv=["$$context","$$nodeModel"],Ko=t=>{let e;const r=new Set,n=(c,u)=>{const l=typeof c=="function"?c(e):c;if(!Object.is(l,e)){const d=e;e=u??typeof l!="object"?l:Object.assign({},e,l),r.forEach(f=>f(e,d))}},o=()=>e,i={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,i),i},fv=t=>t?Ko(t):Ko;var dv=t=>(({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1}&&"production")!=="production"&&console.warn("[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'."),fv(t));class pv{constructor(){b(this,"storeMap",new Map)}addStore(e,r){const n=dv(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)}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]={state:r.getState(),updateState:o=>{r.setState(o)}}}),e}destroy(){this.storeMap.forEach(e=>{e.destroy()}),this.storeMap=new Map}}class hv{constructor(){b(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 Xo{constructor(){b(this,"renderMode","normal");b(this,"components",{});b(this,"storeManager",new pv);b(this,"variableManager",new hv);b(this,"runtimeComponentCache",new Map);b(this,"onGetRef");b(this,"onGetComponent");b(this,"onComponentMount");b(this,"onComponentDestroy");b(this,"processNodeConfigHook")}getComponent(e){var o;const r=e.value.componentName;let n=this.components[r]||(()=>`Component [${r}] not found`);return Qo(n)||(n=qo(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={variableSpace:{},...e},n.__proto__=r||null),n}pageRender(e,{components:r,onGetRef:n,$$context:o={},onGetComponent:a,onComponentMount:s,onComponentDestroy:i,renderMode:c,processNodeConfigHook:u}){this.renderMode=c,this.components=r,this.onGetRef=n,this.onGetComponent=a,this.onComponentMount=s,this.onComponentDestroy=i,this.processNodeConfigHook=u;const l=e.value.componentsTree,d=this.getComponent(l),f=this.convertModelToComponent(d,e.value.componentsTree),p={},m=l.props;return Object.keys(m).forEach(v=>{p[v]=m[v].value}),p.$$context=o,this.render(f,p)}transformProps(e={},{$$context:r}){const n=e,o=s=>{if(Array.isArray(s))return s.map(i=>o(i));if(vr(s))return o(s.value);if(Tf(s)){const i=s.value,c=i.value;if(!c)return console.warn("slot value is null, this maybe cause some error, pls check it",e),()=>{};const u=l=>{const d=`${l.id}-${je}`;if(this.runtimeComponentCache.get(l.id))return{key:d,component:this.runtimeComponentCache.get(l.id)};const f=this.getComponent(l),p=this.convertModelToComponent(f,l),m=i.params||[];return{component:(...O)=>{const E=Ar(O,m),D=this.getContext({params:E},r);return this.render(p,{$$context:D,key:d})},key:d}};if(Array.isArray(c)){const l=c==null?void 0:c.map(d=>u(d));return(...d)=>l.map(f=>Wo(f.component)?_.createElement(f.component,{$$context:r,key:f.key}):f.component(...d))}else return u(c).component}else{if(vt(s))return bt(s.value,r||{});if(Nf(s))return Yo(s.value,r,this.storeManager);if(Rt(s)){let i=s;vr(s)&&(i=s.value);const c=i,u={};return Object.keys(i).forEach(l=>{u[l]=o(c[l])}),u}else return s}},a={};return Object.keys(n).forEach(s=>{const i=n[s];a[s]=o(i)}),a}collectSpecialProps(e={},r){const n=[],o=(a,s)=>{let i=s;vr(s)&&(i=s.value),r(i)?n.push({keyPath:a,val:i}):xt(i)?i.forEach((c,u)=>{o([...a,String(u)],c)}):Rt(i)&&Object.keys(i).forEach(c=>{o([...a,c],i[c])})};return o(["$root"],e),n}convertModelToComponent(e,r){const n=this;class o extends _.Component{constructor(i){super(i);b(this,"_CONDITION",!0);b(this,"_DESIGN_BOX",!1);b(this,"_NODE_MODEL",r);b(this,"_NODE_ID",r.id);b(this,"UNIQUE_ID",`${r.id}_${K()}`);b(this,"targetComponentRef");b(this,"listenerHandle",[]);b(this,"storeState");b(this,"staticState",{});b(this,"storeListenDisposeLint",[]);b(this,"domHeader");b(this,"mediaStyleDomMap",{});b(this,"variableSpace");b(this,"nodeName");b(this,"updateState",i=>{this.storeState.setState(i),this.forceUpdate()});b(this,"getStyleDomById",i=>{const c=this.mediaStyleDomMap;let u=c[i];return u||(u=document.createElement("style"),c[i]=u),u.id=i,u});b(this,"addMediaCSS",()=>{var u;let i=this.domHeader;if(i||(i=(u=document.getElementsByTagName("head"))==null?void 0:u[0],this.domHeader=i),!this.domHeader)return;const c=this._NODE_MODEL.value.css;c&&c.value.forEach(l=>{var p;const d=`${this.UNIQUE_ID}_${l.state}`;let f=`.${c.class}`;if(l.state!=="normal"&&(f=`${f}:${l.state}`),Object.keys(l.style).length!==0){const m=this.getStyleDomById(d);m.innerText=`${f} { ${Pr(l.style)} }`,i==null||i.appendChild(m)}(p=l.media)!=null&&p.length&&l.media.forEach(m=>{const v=`${d}_${m.type}_${m.value}`,j=this.getStyleDomById(v);j.media=`screen and (${m.type}:${m.value}px)`,j.innerHTML=`${f} { ${Pr(m.style)} }`,i==null||i.appendChild(j)})})});b(this,"removeMediaCSS",()=>{const i=this.mediaStyleDomMap;Object.keys(i).forEach(c=>{var u;(u=this.domHeader)==null||u.removeChild(i[c])}),this.mediaStyleDomMap={}});b(this,"rebuildNode",()=>{this.storeListenDisposeLint.forEach(i=>i()),this.removeMediaCSS(),this.connectStore(),this.addMediaCSS(),this.forceUpdate()});this.targetComponentRef=_.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(d=>{this.setState({...d})}),this.connectStore();const l=n.variableManager.get(c);l?this.variableSpace=l:(this.variableSpace={},n.variableManager.add(c,this.variableSpace))}connectStore(){const i=n.collectSpecialProps(r.props,f=>!!vt(f)),c=n.collectSpecialProps({css:r.value.css,class:r.value.classNames},f=>!!vt(f)),u=[...i,...c].map(f=>{const p=f.val,v=/\$\$context.stateManager\.(.+?)\./gim.exec(p.value);return v!=null&&v.length?v[1]:""}).filter(Boolean),l=Array.from(new Set(u)),d=[];l.length&&l.forEach(f=>{n.storeManager.getStore(f)||(n.storeManager.addStore(f,()=>({})),console.log(n.storeManager,f,"not exits"));const m=n.storeManager.connect(f,()=>{this.forceUpdate()});d.push(m)}),this.storeListenDisposeLint=d}componentDidMount(){var c;this.addMediaCSS(),n.onGetRef&&n.onGetRef(this.targetComponentRef,r,this),(c=n.onComponentMount)==null||c.call(n,this,r);const i=()=>{n.storeManager.setStore(r.value.nodeName||r.id,this.storeState),this.storeState.setState({...this.state,...r.value.state||{}}),this.rebuildNode()};r.onChange(i)}componentWillUnmount(){var i;this.storeListenDisposeLint.forEach(c=>c()),this.removeMediaCSS(),(i=n.onComponentDestroy)==null||i.call(n,this,r)}render(){var _t;const{$$context:i,...c}=this.props,u={key:r.id,...r.props,...c},l={state:this.state||{},variableSpace:this.variableSpace,updateState:this.updateState,staticState:this.staticState};r.value.componentName===Tt.ROOT_CONTAINER&&(l.globalState=this.state,l.updateGlobalState=this.updateState),l.stateManager=n.storeManager.getStateSnapshot(),l.variableSpace=n.variableManager.get(this.nodeName),l.variableManager=n.variableManager.getStateSnapshot();const d=n.getContext(l,i),m=n.transformProps({methods:r.value.methods},{$$context:d}).methods.reduce((L,Z)=>(L[Z.name]=Z.define,L),{});d.methods=m,d.variableSpace||(d.variableSpace={}),d.variableSpace.methods=m;const v=r.value.loop;let j=[];if(v&&v.open){this.targetComponentRef.current=[];let L=v.data||[];if(vt(v.data)){const Z=v.data;L=bt(Z.value,d||{})}return j=L.map((...Z)=>{var ia;const oe=Z[1],Ft=[v.forName||"item",v.forIndex||"index"],Dr=Ar(Z,Ft);let xr="loopData";v.name&&(xr=`${xr}${v.name}`);const ae=n.getContext({[xr]:Dr,staticState:this.staticState},d),tt=n.transformProps(u,{$$context:ae}),$v=((ia=r.value.classNames)==null?void 0:ia.map(W=>{var we;const Ce=W.name;return(vt(W.status)?bt(String(((we=W.status)==null?void 0:we.value)||""),ae):!1)?Ce:""}))||[];let Ir=`${tt.className??""} ${$v.join(" ")}`.trim();r.value.css&&(Ir=`${r.value.css.class} ${Ir}`.trim()),tt.className=Ir;const Tv=n.transformProps(r.value.style,{$$context:ae});r.value.style&&(tt.style=Mr(Tv||{}));const{children:Oe}=tt;let Rr=[];if(Oe!==void 0)delete tt.children,Rr=Array.isArray(Oe)?Oe:[Oe];else{const W=[];r.value.children.forEach((sa,we)=>{const Av=n.buildComponent(sa,{$$context:ae,idx:we});W.push(Av)}),Rr=W}if(tt.key=`${tt.key}-${oe}`,vt(v.key)){const W=v.key,Ce=bt(W.value,ae||{});tt.key+=`-${Ce}`}return tt.ref=W=>{this.targetComponentRef.current=this.targetComponentRef.current||[],this.targetComponentRef.current[oe]=W},n.render(e,tt,...Rr)}),j}const O=n.transformProps(u,{$$context:d}),{children:E}=O;let D=[];if(E!==void 0)delete O.children,D=Array.isArray(E)?E:[E];else{const L=[];r.value.children.forEach((oe,Ft)=>{const Dr=n.buildComponent(oe,{$$context:d,idx:Ft});L.push(Dr)}),D=L}O.ref=this.targetComponentRef;const x=((_t=r.value.classNames)==null?void 0:_t.map(L=>{var Ft;const Z=L.name;return(vt(L.status)?bt(((Ft=L.status)==null?void 0:Ft.value)||"",d):!1)?Z:""}))||[];let R=`${O.className??""} ${x.join(" ")}`.trim();r.value.css&&(R=`${r.value.css.class} ${R}`.trim()),O.className=R;const X=n.transformProps(r.value.style,{$$context:d});r.value.style&&(O.style=Mr(X||{}));let st=r.value.condition??!0;typeof st!="boolean"&&(st=bt(st.value,d||{}));let w={condition:st,props:O};n.processNodeConfigHook&&(w=n.processNodeConfigHook(w,r));const ne=n.render(e,w.props,...D);return this._CONDITION=w.condition,w.condition?ne:_.createElement("div",{style:{display:"none"}},ne)}}return b(o,"__CP_TYPE__",je),o.displayName=`${r.value.componentName}Dynamic`,o}buildComponent(e,{$$context:r={}}){const n=this.runtimeComponentCache;return typeof e=="string"?this.render(e):$f(e)?(({currentNode:a})=>{const s=a.value.id;let i=null;if(n.get(s))i=n.get(s);else{const l=this.getComponent(a);i=this.convertModelToComponent(l,a)}!n.get(s)&&this.renderMode!=="design"&&n.set(s,i);const c=`${s}-${je}`,u={$$context:r,$$nodeModel:e,key:c};return this.render(i,u)})({currentNode:e}):void 0}render(e,r={},...n){return typeof e=="string"||typeof e=="number"?String(e):(lv.forEach(a=>{a in r&&e.__CP_TYPE__!==je&&delete r[a]}),_.createElement(e,r,...n))}clear(){this.runtimeComponentCache.clear(),this.storeManager.destroy()}}const vv=Fr(new Xo),mv=["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","search","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"],ot=t=>{const e={};return t.forEach(r=>{e[r.key]=r.value}),e},gv=[...mv,...pf].reduce((t,e)=>(t[e]=({children:r,$$attributes:n=[],...o})=>{let a=r;return Array.isArray(r)||(a=[r]),_.createElement(e,{...o,...ot(n)},...a)},t),{}),yv={RootContainer:({children:t})=>t,...gv,CContainer:({children:t,$$attributes:e=[],afterMount:r,beforeDestroy:n,...o})=>{let a=t;return Array.isArray(t)||(a=[t]),_.useEffect(()=>(r==null||r(o),()=>{n==null||n(o)}),[]),_.createElement("div",{...o,...ot(e)},...a)},CVideo:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("video",{...r,...ot(e)},...n)},CAudio:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("audio",{...r,...ot(e)},...n)},CBlock:({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:s={},...i}=ot(n),c={height:r,width:e,...s,...o.style||{}};return _.createElement("div",{...o,...i,style:c},...a)},CImage:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("img",{...r,...ot(e)},...n)},CText:({$$attributes:t=[],content:e,...r})=>_.createElement("span",{...r,...ot(t)},e),CCanvas:({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),_.createElement("canvas",{...r,...ot(e)},...n)},CNativeTag:({children:t,$$attributes:e=[],htmlTag:r="div",...n})=>{let o=t;Array.isArray(t)||(o=[t]);const{style:a={},...s}=ot(e),i={...a,...n.style||{}};return _.createElement(r,{...n,...s,style:i},...o)}};class bv{constructor(){b(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 Zo extends _.Component{constructor(r){super(r);b(this,"refManager");b(this,"dynamicComponentInstanceMap",new Map);b(this,"onGetRef",(r,n,o)=>{var a,s;(s=(a=this.props).onGetRef)==null||s.call(a,r,n,o),this.dynamicComponentInstanceMap.set(n.id,o),this.refManager.add(n.value.refId||n.id,r)});b(this,"rerender",r=>{if(this.props.adapter.clear(),(r==null?void 0:r.nodeType)==="PAGE"&&r)this.setState({pageModel:r});else if(Rt(r)&&oo(r)){const n=r;this.setState({pageModel:new ge(n,{materials:this.state.pageModel.materialsModel.rawValue})})}});this.state={pageModel:r.pageModel||new ge(r.page)},this.refManager=new bv}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:s}=r,{pageModel:i}=this.state;if(!i)return console.warn("pageModel is null"),null;const c={...yv,...r.components};return n.pageRender(i,{libs:{},components:c,onGetRef:this.onGetRef,onGetComponent:o,onComponentMount:s,onComponentDestroy:a,$$context:{refs:this.refManager},renderMode:r.renderMode,processNodeConfigHook:r.processNodeConfigHook})}}const _v=()=>{const t=_.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)}}};class Sv extends _.Component{constructor(r){super(r);b(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=_.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,_.createElement("p",null,"msg: ",String(this.state.error)),_.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"),_.createElement("div",{style:{display:"none"}}));return _.createElement(this.props.targetComponent,{onlyRenderChild:!0},o)}return this.props.children}}class ta{constructor(){b(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 ea=t=>{const{node:e}=t,r=_.useMemo(()=>{const i=e.isContainer();return Rt(i)?i:{placeholder:"Drag the component to place it",width:"100%",height:"100%",style:{}}},[t.node]),{placeholder:n,height:o,width:a,style:s}=r;return _.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,...s}},n)};class jv extends _.Component{constructor(r){super(r);b(this,"instanceManager",new ta);b(this,"renderRef");b(this,"dropPlaceholder",ea);b(this,"onGetComponent",(r,n)=>{const o=this;class a extends _.Component{constructor(){super(...arguments);b(this,"_DESIGN_BOX",!0);b(this,"_NODE_MODEL",n);b(this,"_NODE_ID",n.id);b(this,"_UNIQUE_ID",`${n.id}_${K()}`);b(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 d=c;return xt(c)||(d=[c]),!!!d.filter(Boolean).length&&(n.isContainer()||n.value.componentName===Tt.ROOT_CONTAINER)&&d.push(_.createElement(o.dropPlaceholder,{node:n})),u?d:_.createElement(r,l,...d)}}return _.forwardRef(function(i,c){return _.createElement(Sv,{node:n,targetComponent:a},_.createElement(a,{ref:c,...i}))})});this.renderRef=_.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=ra(r);if(!n)return null;const o=na(n);return(o==null?void 0:o.stateNode)||null}getDomsById(r,n){const o=this.getInstancesById(r),a=[];return o==null||o.forEach(s=>{if((s==null?void 0:s._STATUS)==="DESTROY")return;const i=ua.findDOMNode(s);if(i&&!(i instanceof Text))if(n){const c=Array.from(i.querySelectorAll(n));a.push(...c)}else a.push(i)}),a}getDomRectById(r,n){return this.getDomsById(r,n).map(s=>s==null?void 0:s.getBoundingClientRect()).filter(Boolean)}render(){const{props:r,onGetComponent:n}=this,{render:o,...a}=r;return o&&(o.ref.current=this),_.createElement(Zo,{onGetComponent:n,...a,processNodeConfigHook:(s,i)=>{var m,v;if(i.nodeType!=="NODE")return s;const{props:c,condition:u}=s;let l={...c};const d=((m=i.value.configure)==null?void 0:m.devState)||{},f=(v=i.material)==null?void 0:v.value.fixedProps;if(f!==void 0){if(Rt(f))l={...l,...f};else if(typeof f=="function"){const j=f(l);l={...l,...j}}}let p=u;return d.condition===!1&&(p=d.condition),{props:iv(l,d.props||{}),condition:p}},ref:this.renderRef})}}const ra=t=>{if(!t)return null;const e=Object.keys(t).find(r=>r.startsWith("__reactInternalInstance$")||r.startsWith("__reactFiber$"))||"";return e?t[e]:ra(t.parentElement)},na=t=>{var e;return t?(e=t==null?void 0:t.stateNode)!=null&&e._DESIGN_BOX?t:na(t.return):null},Ov=()=>{const t=_.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 Cv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wv(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var oa={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(Cv,function(){var r=function(){},n={},o={},a={};function s(f,p){f=f.push?f:[f];var m=[],v=f.length,j=v,O,E,D,x;for(O=function(R,X){X.length&&m.push(R),j--,j||p(m)};v--;){if(E=f[v],D=o[E],D){O(E,D);continue}x=a[E]=a[E]||[],x.push(O)}}function i(f,p){if(f){var m=a[f];if(o[f]=p,!!m)for(;m.length;)m[0](f,p),m.splice(0,1)}}function c(f,p){f.call&&(f={success:f}),p.length?(f.error||r)(p):(f.success||r)(f)}function u(f,p,m,v){var j=document,O=m.async,E=(m.numRetries||0)+1,D=m.before||r,x=f.replace(/[\?|#].*$/,""),R=f.replace(/^(css|img|module|nomodule)!/,""),X,st,w;if(v=v||0,/(^css!|\.css$)/.test(x))w=j.createElement("link"),w.rel="stylesheet",w.href=R,X="hideFocus"in w,X&&w.relList&&(X=0,w.rel="preload",w.as="style");else if(/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(x))w=j.createElement("img"),w.src=R;else if(w=j.createElement("script"),w.src=R,w.async=O===void 0?!0:O,st="noModule"in w,/^module!/.test(x)){if(!st)return p(f,"l");w.type="module"}else if(/^nomodule!/.test(x)&&st)return p(f,"l");w.onload=w.onerror=w.onbeforeload=function(ne){var _t=ne.type[0];if(X)try{w.sheet.cssText.length||(_t="e")}catch(L){L.code!=18&&(_t="e")}if(_t=="e"){if(v+=1,v<E)return u(f,p,m,v)}else if(w.rel=="preload"&&w.as=="style")return w.rel="stylesheet";p(f,_t,ne.defaultPrevented)},D(f,w)!==!1&&j.head.appendChild(w)}function l(f,p,m){f=f.push?f:[f];var v=f.length,j=v,O=[],E,D;for(E=function(x,R,X){if(R=="e"&&O.push(x),R=="b")if(X)O.push(x);else return;v--,v||p(O)},D=0;D<j;D++)u(f[D],E,m)}function d(f,p,m){var v,j;if(p&&p.trim&&(v=p),j=(v?m:p)||{},v){if(v in n)throw"LoadJS";n[v]=!0}function O(E,D){l(f,function(x){c(j,x),E&&c({success:E,error:D},x),i(v,x)},j)}if(j.returnPromise)return new Promise(O);O()}return d.ready=function(p,m){return s(p,function(v){c(m,v)}),d},d.done=function(p){i(p,[])},d.reset=function(){n={},o={},a={}},d.isDefined=function(p){return p in n},d})})(oa);var Ev=oa.exports;const aa=wv(Ev);class Nv{constructor(e,r){b(this,"assets");b(this,"loadStatus");b(this,"win",window);b(this,"_onSuccessList",[]);b(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=K()),r.push(o.id);const a=o.resources.map(s=>s.src);aa(a,o.id,{async:!1,before:(s,i)=>(this.win.document.body.appendChild(i),!1)})}if(e.length===0){this._onSuccessList.forEach(n=>n());return}return new Promise((n,o)=>{aa.ready(r,{success:()=>{this._onSuccessList.forEach(a=>a()),n("")},error:a=>{this._onErrorList.forEach(s=>s(a)),o(a)}})})}onSuccess(e){return this._onSuccessList.push(e),this}onError(e){return this._onErrorList.push(e),this}}y.AssetLoader=Nv,y.ComponentInstanceManager=ta,y.DefaultDropPlaceholder=ea,y.DefineReactAdapter=Xo,y.DesignRender=jv,y.ReactAdapter=vv,y.Render=Zo,y.canAcceptsRef=Qo,y.collectVariable=cv,y.compWrapper=qo,y.convertCodeStringToFunction=Yo,y.flatObject=uv,y.formatSourceStylePropertyName=Mr,y.getAdapter=Fr,y.getCSSTextValue=Pr,y.getObjFromArrayMap=Ar,y.isClass=sv,y.runExpression=bt,y.shouldConstruct=Wo,y.useDesignRender=Ov,y.useRender=_v,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
18
18
  //# sourceMappingURL=index.umd.js.map