@chamn/engine 0.0.39 → 0.0.40

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
@@ -137,7 +137,7 @@ function $$_run_$$() {
137
137
  return $$_f_$$.apply($$_f_$$, $$$__args__$$$);
138
138
  }
139
139
  return $$_run_$$();
140
- `,new Function(o)(...r,t,n)}catch(a){console.log(o),console.warn(a)}},Zg=(e,t)=>{const n={};return t.forEach((r,o)=>{n[r]=e[o]}),n},ev=(e=[])=>{const t={};return e.forEach(({property:n,value:r})=>{let o=n.replace("-webkit","Webkit");o=o.replace("-ms","ms"),o=o.replace("-moz","Moz"),o=o.replace("-o","O");let a=o.split("-");a.length>=2&&(a=a.map((i,s)=>s!==0?Kj(i):i)),t[a.join("")]=r}),t},cx=(e,t)=>{const n={};return e.forEach(r=>{if(r.globalName){const o=t[r.globalName];o&&(n[r.globalName]=o,o.__esModule&&(n[r.globalName]=o.default))}}),n},ux=(e,t=1)=>{let n=0,r=e,o={},a={};for(;n<t;)Object.keys(r).forEach(i=>{o={...o,...r[i]}}),a=o,r=o,o={},n+=1;return a},bD=(e,t)=>{const n=[];return t.forEach(r=>{const o=r.exec(e);o!=null&&o.length&&n.push(o[1])}),n},yD=(e,t)=>{const n={};return t.forEach(r=>{e[r.name]&&(n[r.name]=e[r.name])}),n},xD=(e,t)=>yD(e,t),kc=e=>{var t;return((t=e.value.css)==null?void 0:t.class)||`c_${e.id}`},wD=(e,t)=>{const n=e.split(".");let r,o=t;return n.forEach(a=>{r=o==null?void 0:o[a],o=r}),r||(()=>`Component [${e}] not found`)},ds="DYNAMIC",SD=["$$context","$$nodeModel"],tv=e=>{let t;const n=new Set,r=(i,s)=>{const l=typeof i=="function"?i(t):i;if(!Object.is(l,t)){const c=t;t=s??typeof l!="object"?l:Object.assign({},t,l),n.forEach(u=>u(t,c))}},o=()=>t,a={setState:r,getState:o,subscribe:i=>(n.add(i),()=>n.delete(i)),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."),n.clear()}};return t=e(r,o,a),a},CD=e=>e?tv(e):tv;class _D{constructor(){fe(this,"storeMap",new Map)}addStore(t,n){const r=CD(n);return this.storeMap.set(t,r),r.name=t,r}setStore(t,n){this.storeMap.set(t,n)}removeStore(t){this.storeMap.delete(t)}getStore(t){return this.storeMap.get(t)}getState(t){var n;return(n=this.storeMap.get(t))==null?void 0:n.getState()}getStateObj(t){return{state:this.getState(t),updateState:n=>{this.setState(t,n)}}}setState(t,n){var r;return(r=this.storeMap.get(t))==null?void 0:r.setState(n)}connect(t,n){const r=this.storeMap.get(t);return r?r.subscribe(n):(console.warn("store not exits"),()=>{})}getStateSnapshot(){const t={};return this.storeMap.forEach((n,r)=>{t[r]=this.getStateObj(r)}),t}destroy(){this.storeMap=new Map}}class OD{constructor(){fe(this,"varSpace",new Map)}get(t){return this.varSpace.get(t)}add(t,n){this.varSpace.set(t,n)}remove(t){this.varSpace.delete(t)}destroy(){this.varSpace.clear()}getStateSnapshot(){const t={};return this.varSpace.forEach((n,r)=>{t[r]=n}),t}}class ED{constructor(){fe(this,"renderMode","normal"),fe(this,"components",{}),fe(this,"storeManager",new _D),fe(this,"variableManager",new OD),fe(this,"runtimeComponentCache",new Map),fe(this,"onGetRef"),fe(this,"onGetComponent"),fe(this,"onComponentMount"),fe(this,"onComponentDestroy"),fe(this,"processNodeConfigHook")}getComponent(t){var n;const r=t.value.componentName;let o=wD(r,this.components);return gD(o)||(o=vD(o),this.components[r]=o),this.onGetComponent&&(o=(n=this.onGetComponent)==null?void 0:n.call(this,o,t)),o}getContext(t={},n){let r=t;return n&&(r={...t},r.__proto__=n||null),r}pageRender(t,{components:n,onGetRef:r,$$context:o={},onGetComponent:a,onComponentMount:i,onComponentDestroy:s,renderMode:l,processNodeConfigHook:c}){this.renderMode=l,this.components=n,this.onGetRef=r,this.onGetComponent=a,this.onComponentMount=i,this.onComponentDestroy=s,this.processNodeConfigHook=c;const u=t.value.componentsTree,f=this.getComponent(u),d=this.convertModelToComponent(f,t.value.componentsTree),h={},v=u.props;return Object.keys(v).forEach(g=>{h[g]=v[g].value}),h.$$context=o,this.render(d,h)}transformProps(t={},{$$context:n}){const r=t,o=i=>{if(Array.isArray(i))return i.map(s=>o(s));if(Rc(i))return o(i.value);if(D6(i)){const s=i.value,l=s.value;if(!l)return console.warn("slot value is null, this maybe cause some error, pls check it",t),()=>{};const c=u=>{const f=`${u.id}-${ds}`;if(this.runtimeComponentCache.get(u.id))return{key:f,component:this.runtimeComponentCache.get(u.id)};const d=this.getComponent(u),h=this.convertModelToComponent(d,u),v=s.params||[];return{component:(...g)=>{const m=Zg(g,v),y=this.getContext({params:m},n);return this.render(h,{$$context:y,key:f})},key:f}};if(Array.isArray(l)){const u=l==null?void 0:l.map(f=>c(f));return(...f)=>u.map(d=>{if(pD(d.component)){const h=d.component;return b.createElement(h,{$$context:n,key:d.key})}else{const h=d.component;return h==null?void 0:h(...f)}})}else return c(l).component}else{if(Mr(i))return po(i.value,n||{});if(A6(i))return mD(i.value,n,this.storeManager);if(ea(i)){let s=i;Rc(i)&&(s=i.value);const l=s,c={};return Object.keys(s).forEach(u=>{c[u]=o(l[u])}),c}else return i}},a={};return Object.keys(r).forEach(i=>{const s=r[i];a[i]=o(s)}),a}collectSpecialProps(t={},n){const r=[],o=(a,i)=>{let s=i;Rc(i)&&(s=i.value),n(s)?r.push({keyPath:a,val:s}):Zo(s)?s.forEach((l,c)=>{o([...a,String(c)],l)}):ea(s)&&Object.keys(s).forEach(l=>{o([...a,l],s[l])})};return o(["$root"],t),r}convertModelToComponent(t,n){const r=this;class o extends b.Component{constructor(i){super(i),fe(this,"_CONDITION",!0),fe(this,"_DESIGN_BOX",!1),fe(this,"_NODE_MODEL",n),fe(this,"_NODE_ID",n.id),fe(this,"UNIQUE_ID",`${n.id}_${Vn()}`),fe(this,"targetComponentRef"),fe(this,"listenerHandle",[]),fe(this,"storeState"),fe(this,"storeListenDisposeList",[]),fe(this,"domHeader"),fe(this,"mediaStyleDomMap",{}),fe(this,"variableSpace"),fe(this,"nodeName"),fe(this,"updateState",u=>{this.storeState.setState(u),this.forceUpdate()}),fe(this,"getStyleDomById",u=>{const f=this.mediaStyleDomMap;let d=f[u];return d||(d=document.createElement("style"),f[u]=d),d.id=u,d}),fe(this,"addMediaCSS",()=>{var u;let f=this.domHeader;if(f||(f=(u=document.getElementsByTagName("head"))==null?void 0:u[0],this.domHeader=f),!this.domHeader)return;const d=this._NODE_MODEL.value.css;d&&d.value.forEach(h=>{var v;const g=`${this.UNIQUE_ID}_${h.state}`;let m=kc(this._NODE_MODEL);if(h.state!=="normal"&&(m=`${m}:${h.state}`),h.text){const y=this.getStyleDomById(g);y.innerText=`.${m} { ${h.text} }`,f==null||f.appendChild(y)}(v=h.media)!=null&&v.length&&h.media.forEach(y=>{const w=`${g}_${y.type}_${y.value}`,_=this.getStyleDomById(w);_.media=`screen and (${y.type}:${y.value}px)`,_.innerHTML=`.${m} { ${y.text} }`,f==null||f.appendChild(_)})})}),fe(this,"removeMediaCSS",()=>{const u=this.mediaStyleDomMap;Object.keys(u).forEach(f=>{var d;(d=this.domHeader)==null||d.removeChild(u[f])}),this.mediaStyleDomMap={}}),fe(this,"rebuildNode",()=>{this.storeListenDisposeList.forEach(u=>u()),this.removeMediaCSS(),this.connectStore(),this.addMediaCSS(),this.forceUpdate()}),this.targetComponentRef=b.createRef(),this.state=n.value.state||{};const s=n.value.nodeName||n.id;this.nodeName=s;const l=r.storeManager.getStore(s);l?(this.storeState=l,l.setState({...n.value.state||{}})):this.storeState=r.storeManager.addStore(s,()=>({...n.value.state||{}})),this.storeState.subscribe(u=>{this.setState({...u})}),this.connectStore();const c=r.variableManager.get(s);c?this.variableSpace=c:(this.variableSpace={staticVar:{},methods:{}},r.variableManager.add(s,this.variableSpace))}connectStore(){const i=r.collectSpecialProps(n.props,f=>!!Mr(f)),s=r.collectSpecialProps({css:n.value.css,class:n.value.classNames},f=>!!Mr(f));let l=[];[...i,...s].map(f=>{const d=f.val,h=[/\$\$context.stateManager\.(.+?)\./gim,/\$\$context.stateManager\["(.+?)"\]/gim,/\$\$context.stateManager\['(.+?)'\]/gim,/getStateObj\('(.+?)'\)/gim,/getStateObj\("(.+?)"\)/gim,/getStateById\('(.+?)'\)/gim,/getStateById\("(.+?)"\)/gim],v=bD(d.value,h);l=[...l,...v]}).filter(Boolean);const c=Array.from(new Set(l)),u=[];c.length&&c.forEach(f=>{r.storeManager.getStore(f)||(r.storeManager.addStore(f,()=>({})),console.warn(r.storeManager,f,"not exits"));const d=r.storeManager.connect(f,()=>{this.forceUpdate()});u.push(d)}),this.storeListenDisposeList=u}componentDidMount(){var i;this.addMediaCSS(),r.onGetRef&&r.onGetRef(this.targetComponentRef,n,this),(i=r.onComponentMount)==null||i.call(r,this,n);const s=()=>{r.storeManager.setStore(n.value.nodeName||n.id,this.storeState),this.storeState.setState({...this.state,...n.value.state||{}}),this.rebuildNode()};n.onChange(s)}componentWillUnmount(){var i;this.storeListenDisposeList.forEach(s=>s()),this.removeMediaCSS(),(i=r.onComponentDestroy)==null||i.call(r,this,n)}render(){var i;const{$$context:s,...l}=this.props,c=n.value.nodeName||n.id,u={key:n.id,...n.props,...l},f={state:this.state||{},staticVar:this.variableSpace.staticVar,updateState:this.updateState,storeManager:r.storeManager,getState:()=>r.storeManager.getStateObj(c),getStateObj:()=>r.storeManager.getStateObj(c),getStateObjById:P=>r.storeManager.getStateObj(P),stateManager:r.storeManager.getStateSnapshot(),getMethods:()=>r.variableManager.get(c).methods,getMethodsById:P=>r.variableManager.get(P).methods,getStaticVar:()=>r.variableManager.get(c).staticVar,getStaticVarById:P=>r.variableManager.get(P).staticVar};n.value.componentName===da.ROOT_CONTAINER&&(f.globalState=this.state,f.updateGlobalState=this.updateState);const d=r.getContext(f,s),h=r.transformProps({methods:n.value.methods},{$$context:d}).methods.reduce((P,k)=>(P[k.name]=k.define,P),{});d.methods=h,this.variableSpace.methods=Object.assign(this.variableSpace.methods,h);const v=n.value.loop;let g=[];if(v&&v.open){this.targetComponentRef.current=[];let P=v.data||[];if(Mr(v.data)){const k=v.data;P=po(k.value,d||{})}return g=P.map((...k)=>{var D;const B=k[1],F=[v.forName||"item",v.forIndex||"index"],W=Zg(k,F);let L="loopData";v.name&&(L=`${L}${v.name}`);const G=r.getContext({[L]:W},d),Y=r.transformProps(u,{$$context:G}),pe=((D=n.value.classNames)==null?void 0:D.map(j=>{var V;const ee=j.name;return Mr(j.status)&&po(String(((V=j.status)==null?void 0:V.value)||""),G)?ee:""}))||[];let I=`${Y.className??""} ${pe.join(" ")}`.trim();n.value.css&&(I=`${kc(n)} ${I}`.trim()),Y.className=I;const $=r.transformProps({style:n.value.style},{$$context:G});n.value.style&&(Y.style=ev($.style||[]));const{children:R}=Y;let N=[];if(R!==void 0)delete Y.children,N=Array.isArray(R)?R:[R];else{const j=[];n.value.children.forEach((V,ee)=>{const J=r.buildComponent(V,{$$context:G,idx:ee});j.push(J)}),N=j}if(Y.key=`${Y.key}-${B}`,Mr(v.key)){const j=v.key,V=po(j.value,G||{});Y.key+=`-${V}`}return Y.ref=j=>{this.targetComponentRef.current=this.targetComponentRef.current||[],this.targetComponentRef.current[B]=j},r.render(t,Y,...N)}),g}const m=r.transformProps(u,{$$context:d}),{children:y}=m;let w=[];if(y!==void 0)delete m.children,w=Array.isArray(y)?y:[y];else{const P=[];n.value.children.forEach((k,D)=>{const B=r.buildComponent(k,{$$context:d,idx:D});P.push(B)}),w=P}m.ref=this.targetComponentRef;const _=((i=n.value.classNames)==null?void 0:i.map(P=>{var k;const D=P.name;return Mr(P.status)&&po(((k=P.status)==null?void 0:k.value)||"",d)?D:""}))||[];let S=`${m.className??""} ${_.join(" ")}`.trim();n.value.css&&(S=`${kc(n)} ${S}`.trim()),m.className=S;const x=r.transformProps({style:n.value.style},{$$context:d});n.value.style&&(m.style=ev(x.style||[]));let C=n.value.condition??!0;typeof C!="boolean"&&(C=po(C.value,d||{}));let O={condition:C,props:m};r.processNodeConfigHook&&(O=r.processNodeConfigHook(O,n));const T=r.render(t,O.props,...w);return this._CONDITION=O.condition,O.condition?T:p("div",{style:{display:"none"},children:T})}}return fe(o,"__CP_TYPE__",ds),o.displayName=`${n.value.componentName}Dynamic`,o}buildComponent(t,{$$context:n={}}){const r=this.runtimeComponentCache;return typeof t=="string"?this.render(t):j6(t)?(({currentNode:o})=>{const a=o.value.id;let i=null;if(r.get(a)){const c=r.get(a);i=c==null?void 0:c.component}else{const c=this.getComponent(o);i=this.convertModelToComponent(c,o),!r.get(a)&&this.renderMode!=="design"&&r.set(a,{component:i})}const s=`${a}-${ds}`,l={$$context:n,$$nodeModel:t,key:s};return this.render(i,l)})({currentNode:t}):void 0}render(t,n={},...r){return typeof t=="string"||typeof t=="number"?String(t):(SD.forEach(o=>{o in n&&t.__CP_TYPE__!==ds&&delete n[o]}),b.createElement(t,n,...r))}clear(){this.runtimeComponentCache.clear(),this.storeManager.destroy()}}bP(new ED);const RD=["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"];var $D=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function TD(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var fx={exports:{}},Hl={};/**
140
+ `,new Function(o)(...r,t,n)}catch(a){console.log(o),console.warn(a)}},Zg=(e,t)=>{const n={};return t.forEach((r,o)=>{n[r]=e[o]}),n},ev=(e=[])=>{const t={};return e.forEach(({property:n,value:r})=>{let o=n.replace("-webkit","Webkit");o=o.replace("-ms","ms"),o=o.replace("-moz","Moz"),o=o.replace("-o","O");let a=o.split("-");a.length>=2&&(a=a.map((i,s)=>s!==0?Kj(i):i)),t[a.join("")]=r}),t},cx=(e,t)=>{const n={};return e.forEach(r=>{if(r.globalName){const o=t[r.globalName];o&&(n[r.globalName]=o,o.__esModule&&o.default&&(n[r.globalName]=o.default))}}),n},ux=(e,t=1)=>{let n=0,r=e,o={},a={};for(;n<t;)Object.keys(r).forEach(i=>{o={...o,...r[i]}}),a=o,r=o,o={},n+=1;return a},bD=(e,t)=>{const n=[];return t.forEach(r=>{const o=r.exec(e);o!=null&&o.length&&n.push(o[1])}),n},yD=(e,t)=>{const n={};return t.forEach(r=>{e[r.name]&&(n[r.name]=e[r.name])}),n},xD=(e,t)=>yD(e,t),kc=e=>{var t;return((t=e.value.css)==null?void 0:t.class)||`c_${e.id}`},wD=(e,t)=>{const n=e.split(".");let r,o=t;return n.forEach(a=>{r=o==null?void 0:o[a],o=r}),r||(()=>`Component [${e}] not found`)},ds="DYNAMIC",SD=["$$context","$$nodeModel"],tv=e=>{let t;const n=new Set,r=(i,s)=>{const l=typeof i=="function"?i(t):i;if(!Object.is(l,t)){const c=t;t=s??typeof l!="object"?l:Object.assign({},t,l),n.forEach(u=>u(t,c))}},o=()=>t,a={setState:r,getState:o,subscribe:i=>(n.add(i),()=>n.delete(i)),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."),n.clear()}};return t=e(r,o,a),a},CD=e=>e?tv(e):tv;class _D{constructor(){fe(this,"storeMap",new Map)}addStore(t,n){const r=CD(n);return this.storeMap.set(t,r),r.name=t,r}setStore(t,n){this.storeMap.set(t,n)}removeStore(t){this.storeMap.delete(t)}getStore(t){return this.storeMap.get(t)}getState(t){var n;return(n=this.storeMap.get(t))==null?void 0:n.getState()}getStateObj(t){return{state:this.getState(t),updateState:n=>{this.setState(t,n)}}}setState(t,n){var r;return(r=this.storeMap.get(t))==null?void 0:r.setState(n)}connect(t,n){const r=this.storeMap.get(t);return r?r.subscribe(n):(console.warn("store not exits"),()=>{})}getStateSnapshot(){const t={};return this.storeMap.forEach((n,r)=>{t[r]=this.getStateObj(r)}),t}destroy(){this.storeMap=new Map}}class OD{constructor(){fe(this,"varSpace",new Map)}get(t){return this.varSpace.get(t)}add(t,n){this.varSpace.set(t,n)}remove(t){this.varSpace.delete(t)}destroy(){this.varSpace.clear()}getStateSnapshot(){const t={};return this.varSpace.forEach((n,r)=>{t[r]=n}),t}}class ED{constructor(){fe(this,"renderMode","normal"),fe(this,"components",{}),fe(this,"storeManager",new _D),fe(this,"variableManager",new OD),fe(this,"runtimeComponentCache",new Map),fe(this,"onGetRef"),fe(this,"onGetComponent"),fe(this,"onComponentMount"),fe(this,"onComponentDestroy"),fe(this,"processNodeConfigHook")}getComponent(t){var n;const r=t.value.componentName;let o=wD(r,this.components);return gD(o)||(o=vD(o),this.components[r]=o),this.onGetComponent&&(o=(n=this.onGetComponent)==null?void 0:n.call(this,o,t)),o}getContext(t={},n){let r=t;return n&&(r={...t},r.__proto__=n||null),r}pageRender(t,{components:n,onGetRef:r,$$context:o={},onGetComponent:a,onComponentMount:i,onComponentDestroy:s,renderMode:l,processNodeConfigHook:c}){this.renderMode=l,this.components=n,this.onGetRef=r,this.onGetComponent=a,this.onComponentMount=i,this.onComponentDestroy=s,this.processNodeConfigHook=c;const u=t.value.componentsTree,f=this.getComponent(u),d=this.convertModelToComponent(f,t.value.componentsTree),h={},v=u.props;return Object.keys(v).forEach(g=>{h[g]=v[g].value}),h.$$context=o,this.render(d,h)}transformProps(t={},{$$context:n}){const r=t,o=i=>{if(Array.isArray(i))return i.map(s=>o(s));if(Rc(i))return o(i.value);if(D6(i)){const s=i.value,l=s.value;if(!l)return console.warn("slot value is null, this maybe cause some error, pls check it",t),()=>{};const c=u=>{const f=`${u.id}-${ds}`;if(this.runtimeComponentCache.get(u.id))return{key:f,component:this.runtimeComponentCache.get(u.id)};const d=this.getComponent(u),h=this.convertModelToComponent(d,u),v=s.params||[];return{component:(...g)=>{const m=Zg(g,v),y=this.getContext({params:m},n);return this.render(h,{$$context:y,key:f})},key:f}};if(Array.isArray(l)){const u=l==null?void 0:l.map(f=>c(f));return(...f)=>u.map(d=>{if(pD(d.component)){const h=d.component;return b.createElement(h,{$$context:n,key:d.key})}else{const h=d.component;return h==null?void 0:h(...f)}})}else return c(l).component}else{if(Mr(i))return po(i.value,n||{});if(A6(i))return mD(i.value,n,this.storeManager);if(ea(i)){let s=i;Rc(i)&&(s=i.value);const l=s,c={};return Object.keys(s).forEach(u=>{c[u]=o(l[u])}),c}else return i}},a={};return Object.keys(r).forEach(i=>{const s=r[i];a[i]=o(s)}),a}collectSpecialProps(t={},n){const r=[],o=(a,i)=>{let s=i;Rc(i)&&(s=i.value),n(s)?r.push({keyPath:a,val:s}):Zo(s)?s.forEach((l,c)=>{o([...a,String(c)],l)}):ea(s)&&Object.keys(s).forEach(l=>{o([...a,l],s[l])})};return o(["$root"],t),r}convertModelToComponent(t,n){const r=this;class o extends b.Component{constructor(i){super(i),fe(this,"_CONDITION",!0),fe(this,"_DESIGN_BOX",!1),fe(this,"_NODE_MODEL",n),fe(this,"_NODE_ID",n.id),fe(this,"UNIQUE_ID",`${n.id}_${Vn()}`),fe(this,"targetComponentRef"),fe(this,"listenerHandle",[]),fe(this,"storeState"),fe(this,"storeListenDisposeList",[]),fe(this,"domHeader"),fe(this,"mediaStyleDomMap",{}),fe(this,"variableSpace"),fe(this,"nodeName"),fe(this,"updateState",u=>{this.storeState.setState(u),this.forceUpdate()}),fe(this,"getStyleDomById",u=>{const f=this.mediaStyleDomMap;let d=f[u];return d||(d=document.createElement("style"),f[u]=d),d.id=u,d}),fe(this,"addMediaCSS",()=>{var u;let f=this.domHeader;if(f||(f=(u=document.getElementsByTagName("head"))==null?void 0:u[0],this.domHeader=f),!this.domHeader)return;const d=this._NODE_MODEL.value.css;d&&d.value.forEach(h=>{var v;const g=`${this.UNIQUE_ID}_${h.state}`;let m=kc(this._NODE_MODEL);if(h.state!=="normal"&&(m=`${m}:${h.state}`),h.text){const y=this.getStyleDomById(g);y.innerText=`.${m} { ${h.text} }`,f==null||f.appendChild(y)}(v=h.media)!=null&&v.length&&h.media.forEach(y=>{const w=`${g}_${y.type}_${y.value}`,_=this.getStyleDomById(w);_.media=`screen and (${y.type}:${y.value}px)`,_.innerHTML=`.${m} { ${y.text} }`,f==null||f.appendChild(_)})})}),fe(this,"removeMediaCSS",()=>{const u=this.mediaStyleDomMap;Object.keys(u).forEach(f=>{var d;(d=this.domHeader)==null||d.removeChild(u[f])}),this.mediaStyleDomMap={}}),fe(this,"rebuildNode",()=>{this.storeListenDisposeList.forEach(u=>u()),this.removeMediaCSS(),this.connectStore(),this.addMediaCSS(),this.forceUpdate()}),this.targetComponentRef=b.createRef(),this.state=n.value.state||{};const s=n.value.nodeName||n.id;this.nodeName=s;const l=r.storeManager.getStore(s);l?(this.storeState=l,l.setState({...n.value.state||{}})):this.storeState=r.storeManager.addStore(s,()=>({...n.value.state||{}})),this.storeState.subscribe(u=>{this.setState({...u})}),this.connectStore();const c=r.variableManager.get(s);c?this.variableSpace=c:(this.variableSpace={staticVar:{},methods:{}},r.variableManager.add(s,this.variableSpace))}connectStore(){const i=r.collectSpecialProps(n.props,f=>!!Mr(f)),s=r.collectSpecialProps({css:n.value.css,class:n.value.classNames},f=>!!Mr(f));let l=[];[...i,...s].map(f=>{const d=f.val,h=[/\$\$context.stateManager\.(.+?)\./gim,/\$\$context.stateManager\["(.+?)"\]/gim,/\$\$context.stateManager\['(.+?)'\]/gim,/getStateObj\('(.+?)'\)/gim,/getStateObj\("(.+?)"\)/gim,/getStateById\('(.+?)'\)/gim,/getStateById\("(.+?)"\)/gim],v=bD(d.value,h);l=[...l,...v]}).filter(Boolean);const c=Array.from(new Set(l)),u=[];c.length&&c.forEach(f=>{r.storeManager.getStore(f)||(r.storeManager.addStore(f,()=>({})),console.warn(r.storeManager,f,"not exits"));const d=r.storeManager.connect(f,()=>{this.forceUpdate()});u.push(d)}),this.storeListenDisposeList=u}componentDidMount(){var i;this.addMediaCSS(),r.onGetRef&&r.onGetRef(this.targetComponentRef,n,this),(i=r.onComponentMount)==null||i.call(r,this,n);const s=()=>{r.storeManager.setStore(n.value.nodeName||n.id,this.storeState),this.storeState.setState({...this.state,...n.value.state||{}}),this.rebuildNode()};n.onChange(s)}componentWillUnmount(){var i;this.storeListenDisposeList.forEach(s=>s()),this.removeMediaCSS(),(i=r.onComponentDestroy)==null||i.call(r,this,n)}render(){var i;const{$$context:s,...l}=this.props,c=n.value.nodeName||n.id,u={key:n.id,...n.props,...l},f={state:this.state||{},staticVar:this.variableSpace.staticVar,updateState:this.updateState,storeManager:r.storeManager,getState:()=>r.storeManager.getStateObj(c),getStateObj:()=>r.storeManager.getStateObj(c),getStateObjById:P=>r.storeManager.getStateObj(P),stateManager:r.storeManager.getStateSnapshot(),getMethods:()=>r.variableManager.get(c).methods,getMethodsById:P=>r.variableManager.get(P).methods,getStaticVar:()=>r.variableManager.get(c).staticVar,getStaticVarById:P=>r.variableManager.get(P).staticVar};n.value.componentName===da.ROOT_CONTAINER&&(f.globalState=this.state,f.updateGlobalState=this.updateState);const d=r.getContext(f,s),h=r.transformProps({methods:n.value.methods},{$$context:d}).methods.reduce((P,k)=>(P[k.name]=k.define,P),{});d.methods=h,this.variableSpace.methods=Object.assign(this.variableSpace.methods,h);const v=n.value.loop;let g=[];if(v&&v.open){this.targetComponentRef.current=[];let P=v.data||[];if(Mr(v.data)){const k=v.data;P=po(k.value,d||{})}return g=P.map((...k)=>{var D;const B=k[1],F=[v.forName||"item",v.forIndex||"index"],W=Zg(k,F);let L="loopData";v.name&&(L=`${L}${v.name}`);const G=r.getContext({[L]:W},d),Y=r.transformProps(u,{$$context:G}),pe=((D=n.value.classNames)==null?void 0:D.map(j=>{var V;const ee=j.name;return Mr(j.status)&&po(String(((V=j.status)==null?void 0:V.value)||""),G)?ee:""}))||[];let I=`${Y.className??""} ${pe.join(" ")}`.trim();n.value.css&&(I=`${kc(n)} ${I}`.trim()),Y.className=I;const $=r.transformProps({style:n.value.style},{$$context:G});n.value.style&&(Y.style=ev($.style||[]));const{children:R}=Y;let N=[];if(R!==void 0)delete Y.children,N=Array.isArray(R)?R:[R];else{const j=[];n.value.children.forEach((V,ee)=>{const J=r.buildComponent(V,{$$context:G,idx:ee});j.push(J)}),N=j}if(Y.key=`${Y.key}-${B}`,Mr(v.key)){const j=v.key,V=po(j.value,G||{});Y.key+=`-${V}`}return Y.ref=j=>{this.targetComponentRef.current=this.targetComponentRef.current||[],this.targetComponentRef.current[B]=j},r.render(t,Y,...N)}),g}const m=r.transformProps(u,{$$context:d}),{children:y}=m;let w=[];if(y!==void 0)delete m.children,w=Array.isArray(y)?y:[y];else{const P=[];n.value.children.forEach((k,D)=>{const B=r.buildComponent(k,{$$context:d,idx:D});P.push(B)}),w=P}m.ref=this.targetComponentRef;const _=((i=n.value.classNames)==null?void 0:i.map(P=>{var k;const D=P.name;return Mr(P.status)&&po(((k=P.status)==null?void 0:k.value)||"",d)?D:""}))||[];let S=`${m.className??""} ${_.join(" ")}`.trim();n.value.css&&(S=`${kc(n)} ${S}`.trim()),m.className=S;const x=r.transformProps({style:n.value.style},{$$context:d});n.value.style&&(m.style=ev(x.style||[]));let C=n.value.condition??!0;typeof C!="boolean"&&(C=po(C.value,d||{}));let O={condition:C,props:m};r.processNodeConfigHook&&(O=r.processNodeConfigHook(O,n));const T=r.render(t,O.props,...w);return this._CONDITION=O.condition,O.condition?T:p("div",{style:{display:"none"},children:T})}}return fe(o,"__CP_TYPE__",ds),o.displayName=`${n.value.componentName}Dynamic`,o}buildComponent(t,{$$context:n={}}){const r=this.runtimeComponentCache;return typeof t=="string"?this.render(t):j6(t)?(({currentNode:o})=>{const a=o.value.id;let i=null;if(r.get(a)){const c=r.get(a);i=c==null?void 0:c.component}else{const c=this.getComponent(o);i=this.convertModelToComponent(c,o),!r.get(a)&&this.renderMode!=="design"&&r.set(a,{component:i})}const s=`${a}-${ds}`,l={$$context:n,$$nodeModel:t,key:s};return this.render(i,l)})({currentNode:t}):void 0}render(t,n={},...r){return typeof t=="string"||typeof t=="number"?String(t):(SD.forEach(o=>{o in n&&t.__CP_TYPE__!==ds&&delete n[o]}),b.createElement(t,n,...r))}clear(){this.runtimeComponentCache.clear(),this.storeManager.destroy()}}bP(new ED);const RD=["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"];var $D=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function TD(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var fx={exports:{}},Hl={};/**
141
141
  * @license React
142
142
  * react-jsx-runtime.production.min.js
143
143
  *
@@ -325,5 +325,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
325
325
  ctx.font = "48px serif";
326
326
  ctx.fillText("Hello Canvas", 10, 50);
327
327
  }
328
- `}}}}]},{title:"HTML 标签",componentName:"CNativeTag",props:[{name:"htmlTag",title:"标签名",valueType:"string",setters:[{componentName:"SelectSetter",props:{options:De.HTMl_TAGS.map(e=>({name:e,value:e}))}}]},rr],isContainer:!0,groupName:"原子组件",snippets:[{title:"HTML",snapshotText:"HTML",category:"基础组件",schema:{props:{htmlTag:"div"}}}]}],oie=[...rie,...nie];class S2 extends b.Component{constructor(n){super(n);H(this,"currentSelectNode");H(this,"pluginManager");H(this,"workbenchRef",b.createRef());H(this,"pageSchema");H(this,"pageModel");H(this,"material");H(this,"emitter");H(this,"assetsPackageListManager");H(this,"updatePage",n=>{this.pageModel.updatePage(n)});H(this,"updateMaterials",async(n,r,o)=>{const a=await this.pluginManager.get("Designer"),i=a==null?void 0:a.export;this.pluginManager.assetsPackageListManager.setList(r),this.pageModel.assetPackagesList=this.pluginManager.assetsPackageListManager.getList();const s=i==null?void 0:i.getDesignerWindow();if(!s){console.warn("subWin not exits");return}await new tI(r,s).load();const c=cx(r,s);let u=ux(c);o!=null&&o.formatComponents&&(u=o.formatComponents(u)),i==null||i.updateRenderComponents(u),this.pageModel.materialsModel.addMaterials(n),this.emitter.emit("updateMaterials")});H(this,"refresh",async()=>{this.pageModel.reloadPage(this.pageModel.export("design"))});H(this,"getWorkbench",()=>this.workbenchRef.current);this.pageSchema=n.schema,this.material=n.material,this.currentSelectNode=null,window.__CHAMELEON_ENG__=this,this.assetsPackageListManager=new hP(n.assetPackagesList||[]);try{this.pageModel=new De.CPage(this.pageSchema,{materials:this.material||[],assetPackagesList:n.assetPackagesList||[]})}catch(r){console.error(r),this.pageModel=new De.CPage(De.EmptyPage)}this.emitter=qs()}updateCurrentSelectNode(n){this.currentSelectNode=n,this.emitter.emit("onSelectNodeChange",{node:n})}async componentDidMount(){var a,i,s,l,c,u;window.__C_ENGINE__=this;const n=this.props.plugins,r=new nL({engine:this,getWorkbench:()=>this.workbenchRef.current,emitter:this.emitter,pageModel:this.pageModel,i18n:Ox,assetsPackageListManager:this.assetsPackageListManager});this.pluginManager=r,r.customPlugin("Designer",f=>(f.ctx.config.beforeInitRender=vx,f.ctx.config.customRender=mx(this.props.components||{}),f.ctx.config.components=this.props.components,f)),(i=(a=this.props).beforePluginRun)==null||i.call(a,{pluginManager:this.pluginManager});const o=n.map(f=>this.pluginManager.add(f));(l=(s=this.props).onMount)==null||l.call(s,{pluginManager:this.pluginManager,engine:this}),await Promise.all(o),this.pageModel.emitter.on("onReloadPage",()=>{var d;if(!this.currentSelectNode)return;const f=this.pageModel.getNode((d=this.currentSelectNode)==null?void 0:d.id);f&&this.updateCurrentSelectNode(f)}),(u=(c=this.props).onReady)==null||u.call(c,{pluginManager:this.pluginManager,engine:this})}getActiveNode(){var r;if(!((r=this.currentSelectNode)!=null&&r.id))return null;const n=this.pageModel.getNode(this.currentSelectNode.id)??null;return this.currentSelectNode=n,n}render(){return p("div",{className:Ge([iI.engineContainer,this.props.className]),style:this.props.style,children:p(oI,{ref:this.workbenchRef,emitter:this.emitter})})}}H(S2,"version","0.0.39");exports.Engine=S2;exports.InnerComponentMeta=oie;exports.LOGGER=dn;exports.beforeInitRender=vx;exports.formatCSSTextProperty=pd;exports.formatCssToNodeVal=Gy;exports.formatNodeValToEditor=Ky;exports.formatStyleProperty=Bu;exports.getColorFromStr=Fu;exports.getDefaultRender=mx;exports.parseBoxShadowString=Ls;exports.plugins=tie;exports.registerCustomSetter=nB;exports.styleArr2Obj=Vy;exports.styleList2Text=Wy;exports.styleObjToArr=Uy;exports.waitReactUpdate=Bn;Object.keys(br).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>br[e]})});
328
+ `}}}}]},{title:"HTML 标签",componentName:"CNativeTag",props:[{name:"htmlTag",title:"标签名",valueType:"string",setters:[{componentName:"SelectSetter",props:{options:De.HTMl_TAGS.map(e=>({name:e,value:e}))}}]},rr],isContainer:!0,groupName:"原子组件",snippets:[{title:"HTML",snapshotText:"HTML",category:"基础组件",schema:{props:{htmlTag:"div"}}}]}],oie=[...rie,...nie];class S2 extends b.Component{constructor(n){super(n);H(this,"currentSelectNode");H(this,"pluginManager");H(this,"workbenchRef",b.createRef());H(this,"pageSchema");H(this,"pageModel");H(this,"material");H(this,"emitter");H(this,"assetsPackageListManager");H(this,"updatePage",n=>{this.pageModel.updatePage(n)});H(this,"updateMaterials",async(n,r,o)=>{const a=await this.pluginManager.get("Designer"),i=a==null?void 0:a.export;this.pluginManager.assetsPackageListManager.setList(r),this.pageModel.assetPackagesList=this.pluginManager.assetsPackageListManager.getList();const s=i==null?void 0:i.getDesignerWindow();if(!s){console.warn("subWin not exits");return}await new tI(r,s).load();const c=cx(r,s);let u=ux(c);o!=null&&o.formatComponents&&(u=o.formatComponents(u)),i==null||i.updateRenderComponents(u),this.pageModel.materialsModel.addMaterials(n),this.emitter.emit("updateMaterials")});H(this,"refresh",async()=>{this.pageModel.reloadPage(this.pageModel.export("design"))});H(this,"getWorkbench",()=>this.workbenchRef.current);this.pageSchema=n.schema,this.material=n.material,this.currentSelectNode=null,window.__CHAMELEON_ENG__=this,this.assetsPackageListManager=new hP(n.assetPackagesList||[]);try{this.pageModel=new De.CPage(this.pageSchema,{materials:this.material||[],assetPackagesList:n.assetPackagesList||[]})}catch(r){console.error(r),this.pageModel=new De.CPage(De.EmptyPage)}this.emitter=qs()}updateCurrentSelectNode(n){this.currentSelectNode=n,this.emitter.emit("onSelectNodeChange",{node:n})}async componentDidMount(){var a,i,s,l,c,u;window.__C_ENGINE__=this;const n=this.props.plugins,r=new nL({engine:this,getWorkbench:()=>this.workbenchRef.current,emitter:this.emitter,pageModel:this.pageModel,i18n:Ox,assetsPackageListManager:this.assetsPackageListManager});this.pluginManager=r,r.customPlugin("Designer",f=>(f.ctx.config.beforeInitRender=vx,f.ctx.config.customRender=mx(this.props.components||{}),f.ctx.config.components=this.props.components,f)),(i=(a=this.props).beforePluginRun)==null||i.call(a,{pluginManager:this.pluginManager});const o=n.map(f=>this.pluginManager.add(f));(l=(s=this.props).onMount)==null||l.call(s,{pluginManager:this.pluginManager,engine:this}),await Promise.all(o),this.pageModel.emitter.on("onReloadPage",()=>{var d;if(!this.currentSelectNode)return;const f=this.pageModel.getNode((d=this.currentSelectNode)==null?void 0:d.id);f&&this.updateCurrentSelectNode(f)}),(u=(c=this.props).onReady)==null||u.call(c,{pluginManager:this.pluginManager,engine:this})}getActiveNode(){var r;if(!((r=this.currentSelectNode)!=null&&r.id))return null;const n=this.pageModel.getNode(this.currentSelectNode.id)??null;return this.currentSelectNode=n,n}render(){return p("div",{className:Ge([iI.engineContainer,this.props.className]),style:this.props.style,children:p(oI,{ref:this.workbenchRef,emitter:this.emitter})})}}H(S2,"version","0.0.40");exports.Engine=S2;exports.InnerComponentMeta=oie;exports.LOGGER=dn;exports.beforeInitRender=vx;exports.formatCSSTextProperty=pd;exports.formatCssToNodeVal=Gy;exports.formatNodeValToEditor=Ky;exports.formatStyleProperty=Bu;exports.getColorFromStr=Fu;exports.getDefaultRender=mx;exports.parseBoxShadowString=Ls;exports.plugins=tie;exports.registerCustomSetter=nB;exports.styleArr2Obj=Vy;exports.styleList2Text=Wy;exports.styleObjToArr=Uy;exports.waitReactUpdate=Bn;Object.keys(br).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>br[e]})});
329
329
  //# sourceMappingURL=index.js.map