UNPKG

@jiess/core

Version:

基于javascript的配置式渲染库,同时支持vue2,vue3和react

1 lines 2.11 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JiessEnv=t():e.JiessEnv=t()}(globalThis,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>s}),function(e={},t="toString"){if("function"==typeof e[t]){if("string"==typeof t){const n=new RegExp(t,"g");return(e[t]+"").replace(n,"")}e[t]}}(),new WeakMap;const n=(...e)=>{};var r;((((()=>{let e})(),()=>{let e=0;return function(t,n=100){let r=(new Date).getTime();r-e>n&&t(),e=r}})(),()=>{let e=!0;return function(t,n=100){e&&(e=!1,setTimeout((()=>{e=!0,t()}),n))}})(),()=>{let e=0;return function(t,n=100){let r=(new Date).getTime();r-e>n&&(e=r,t())}})(),function(e){e.React="react",e.Vue2="vue2",e.Vue3="vue3"}(r||(r={}));const o="react";class s{jiess;env=o;constructor(e,t){this.jiess=e,this.initRender(),this.env=e.$env=o,e.JiessComponent=e=>{const{is:n,setup:r,children:o,...s}=e,c={is:n,setup:r,jiessEnv:this};return this.createElement(t(c).start(s,o))}}initRender(){const{$render:e}=this.jiess;"function"==typeof e&&(this.jiess.createElement=(...t)=>{try{return e.call(this,...t)}catch(e){console.error("Error in custom createElement:",e)}})}createElement(e,t={},n){const{useRef:r,createElement:o}=this.jiess,{ref:s,...c}=t;return"function"==typeof s&&(c.ref=r(null),s(c.ref)),o(e,c,n)}createVNode({key:e},t){const{NativeComponent:n}=t(this);return this.createElement(n,{key:e})}component(e,t){let r=n;const{useRef:o,useEffect:s,useReducer:c}=this.jiess;return i=>{let u=!0,f=!0;const a=o(!1),[l,p]=c((e=>a.current=!e)),d=o({forceUpdate:p});return e.frame=d.current,e.frameProps=i,(e=>{const t=o(!0);t.current&&(t.current=!1,e())})((()=>{r=t(),r("beforeMount")})),(e.ctx.useCustomHook||n)(i),e.frame&&(e.frame.props=i),s((()=>(u=!1,r("mounted"),()=>{f=!1,r("beforeUnmount")})),[]),s((()=>(u&&r("updated"),()=>f&&r("beforeUpdate")))),e.ctx._buildVNodeTree()}}}return t.default})()));