UNPKG

@jiess/core

Version:

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

1 lines 24.1 kB
(()=>{"use strict";var e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,s=new WeakMap){if(Object.is(e,t))return!0;const o=typeof e;if(o!==typeof t)return!1;if(!e||!t||"object"!==o)return!1;if(s.has(e)&&s.has(t))return s.get(e)===t&&s.get(t)===e;s.set(e,t),s.set(t,e);const i=Object.prototype.toString.call(e);if(i!==Object.prototype.toString.call(t))return!1;switch(i){case"[object Date]":return e.getTime()===t.getTime();case"[object Promise]":return!1;case"[object Function]":case"[object RegExp]":case"[object Symbol]":return String(e)===String(t);case"[object ArrayBuffer]":case"[object SharedArrayBuffer]":if(e.byteLength!==t.byteLength)return!1;const o=new Uint8Array(e),i=new Uint8Array(t);for(let t=0;t<e.byteLength;t++)if(o[t]!==i[t])return!1;return!0;case"[object BigInt]":return e===t;case"[object TypedArray]":return JSON.stringify(Array.from(e))===JSON.stringify(Array.from(t));case"[object Map]":if(e.size!==t.size)return!1;for(const[o,i]of e)if(!t.has(o)||!r(i,t.get(o),s))return!1;return!0;case"[object Set]":if(e.size!==t.size)return!1;const n=[...e],c=[...t];for(let e=0;e<n.length;e++){let t=!1;for(let o=0;o<c.length;o++)if(r(n[e],c[o],s)){t=!0;break}if(!t)return!1}return!0}if(Array.isArray(e)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!r(e[o],t[o],s))return!1;return!0}const n=Object.keys(e),c=Object.keys(t);if(n.length!==c.length)return!1;const a=new Set(c);for(let o of n)if(!a.has(o)||!r(e[o],t[o],s))return!1;return!0}e.r(t),e.d(t,{$clearReactiveCache:()=>Y,$clearRefCache:()=>Z,$computed:()=>H,$entry:()=>oe,$isReactive:()=>F,$isRef:()=>L,$reactive:()=>U,$ref:()=>G,$set:()=>q,$watch:()=>Q,$watchEffect:()=>X,clearStaticCache:()=>re,default:()=>ie,getCacheSize:()=>se,staticJsRenders:()=>ee});const s=(e,t,s=!0)=>{if(Object.is(e,t))return!0;const o=typeof e;if(o!==typeof t)return!1;if(!e||!t||"object"!==o)return!1;if(s)if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const s=e[r],o=t[r];if(!Object.is(s,o)){if(typeof s!=typeof o)return!1;if(!s||!o||"object"!=typeof s)return!1}}}else{if(Array.isArray(t))return!1;{const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;const o=new Set(s);for(const s of r){if(!o.has(s))return!1;const r=e[s],i=t[s];if(!Object.is(r,i)){if(typeof r!=typeof i)return!1;if(!r||!i||"object"!=typeof r)return!1}}}}let i=e,n=t;if(s){const r=(e,t)=>{if(!e||"object"!=typeof e)return e;if(t.has(e))return t.get(e);if(O(e))return e;const s=Array.isArray(e)?[]:{};t.set(e,s);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(Array.isArray(s)?s[Number(o)]=r(e[o],t):s[o]=r(e[o],t));return s},s=new WeakMap;i=r(e,s),n=r(t,s)}return r(i,n,new WeakMap)},o=(...e)=>{};function i(e,t,r=!0){if(Array.isArray(t))return t.some(t=>i(e,t));if("string"==typeof t){const e=t.toLowerCase();"exp"!==e&&"regex"!==e||(t="RegExp")}else if(r)throw new Error(`${t} Error:须提供字符串`);const s="string"==typeof t?t.charAt(0).toUpperCase()+t.slice(1):t,o=Object.prototype.toString.call(e)===`[object ${s}]`;if(!o&&"Object"===s&&null!==e&&"object"==typeof e){const t=Object.prototype.toString.call(e);return t.includes("ArrayBuffer")||t.includes("TypedArray")||t.startsWith("[object ")}return o}const n=i,c=(e,t,r=new WeakMap)=>{if(!e||"object"!=typeof e){if(t){const r=t(e,"filter");return void 0!==r?r:void 0}return e}if(r.has(e))return r.get(e);if(e instanceof Date){const t=new Date(e.getTime());return r.set(e,t),t}if(e instanceof RegExp){const t=new RegExp(e.source,e.flags);return r.set(e,t),t}if(O(e)){const r=t?.(e,"filter");return void 0!==r?r:e}let s;if(s=Array.isArray(e)?new Array(e.length):{},r.set(e,s),Array.isArray(e))for(let o=0;o<e.length;o++){const i=c(e[o],t,r);void 0!==i&&(s[o]=i)}else{for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const i=c(e[o],t,r);void 0!==i&&(s[o]=i)}Object.getOwnPropertySymbols(e).forEach(o=>{const i=c(e[o],t,r);void 0!==i&&(s[o]=i)})}if(t){const e=t(s,"clone");if(void 0!==e)return e}return s},a=(e,t)=>!((e,t)=>!(!t||""!==e)||[null,void 0,NaN].some(t=>Object.is(t,e)))(e,t);function f(){let e=null;return(t,...r)=>(e||(e=Promise.resolve().then(()=>(e=null,t.call(this,...r)))),e)}const h=(e,t=!1)=>{let r;return function(s,o=100){const i=()=>"function"==typeof e?e():"function"==typeof s?s():void 0;a(r,!0)?clearTimeout(r):t&&i(),r=setTimeout(i,o)}};function u(e,t){if(!e||!t)return;let r;if(r=Array.isArray(t)?t:t.replace(/\[(\d+)\]/g,".$1").split("."),r=r.filter(Boolean),0===r.length)return;let s=e;for(const e of r)try{const t=Number(e);s=!isNaN(t)&&Number.isInteger(t)&&Array.isArray(s)?s[t]:s[e]}catch(e){return}return s}(((h(),e=>{let t;return function(r,s=100){a(t,!0)&&clearTimeout(t),t=setTimeout(()=>"function"==typeof e?e():"function"==typeof r?r():void 0,s)}})(),e=>{let t=!0;return function(r,s=100){t&&(t=!1,setTimeout(()=>{t=!0,"function"==typeof e?e():"function"==typeof r&&r()},s))}})(),e=>{let t,r=0;return function(s,o=100){const i="function"==typeof e?e:s;let n=Date.now();n-r>=o?(r=n,"function"==typeof i&&i()):a(t,!0)||(t=setTimeout(()=>{r=Date.now(),t=void 0,"function"==typeof i&&i()},o))}})(),"undefined"==typeof window||"undefined"==typeof document||!window.document||window.document.createElement;const l="JIESS_CONSTRUCTOR",p="THIS_IS_JIESS",y="JIESS_INIT_VALUE",d="__JIESS_REF__",g="__JIESS_COMPUTED__",b="__JIESS_PARENT__",_=new Set(["is","component","$exclude"]),v=(e,t)=>Array.isArray(e)?[...e]:n(e,"object")?{...e}:t?void(()=>{throw new Error("shallowCopy Error:须提供对象或数组")})():e;function w(e){return!(!e||"object"!=typeof e||!e[p])}const m=e=>!!n(e,"object")&&!!e[d],M=(e,t)=>{throw new Error(`${e} Error:${t}`)};function S(e,t,r=o,s="数据类型"){return n(e,t)?r():M(s,`须提供 ${t} 类型`)}const x=(e,t,r=l)=>!!n(e,"object")&&Object.is(e[r],t),O=e=>null!==e&&"object"==typeof e&&(!!w(e)||(e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||(e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||(e instanceof Promise||(!!(Reflect.has(e,"__v_isReactive")||Reflect.has(e,"__v_isReadonly")||Reflect.has(e,"$")||Reflect.has(e,"_")||Reflect.has(e,"__")||Reflect.has(e,"is")||Reflect.has(e,"$slots")||Reflect.has(e,"$$typeof")||Reflect.has(e,"nodeType"))||(!!Object.keys(e).some(e=>e.startsWith("__v_")||e.startsWith("__react")||e.startsWith("El")||e.startsWith("a-")||e.startsWith("van-"))||"function"==typeof e.install)))))),j=({...e})=>{const{default:t,...r}=e;return Object.assign(r,t||{})};function A(e={},t="toString"){if("function"==typeof e[t]){if("string"==typeof t){const r=new RegExp(t,"g");return(e[t]+"").replace(r,"")}return e[t]+""}return""}const R=(()=>{const e=A();return(t,r)=>A(t,r)===e})(),k=(e,t,r={})=>(e.has(t)?r=e.get(t):e.set(t,r),r);class T{_disposed=!1;_resources=[];add(e){if(this._disposed)throw new Error("ResourceManager has been disposed");return this._resources.push(e),this}remove(e){if(this._disposed)return;const t=this._resources.indexOf(e);-1!==t&&this._resources.splice(t,1)}get disposed(){return this._disposed}dispose(){if(!this._disposed){this._disposed=!0;for(let e=this._resources.length-1;e>=0;e--)try{this._resources[e].dispose()}catch(e){}this._resources=[]}}get size(){return this._resources.length}}class C{static uid=1;constructor(e,t={}){this[l]=e,this.J_uid=C.uid++,"function"==typeof t&&(t=t(this)),Object.assign(this,t),this.bindCxt()}bindCxt(){for(const e of Reflect.ownKeys(this.__proto__))if("constructor"!==e&&"string"==typeof e){if(e.startsWith("_"))continue;const t=Object.getOwnPropertyDescriptor(this.__proto__,e);if(t&&t.get)continue;"function"==typeof this[e]&&(this[e]=this[e].bind(this)),this.freezeField(e)}}resetField(e,t){Object.prototype.hasOwnProperty.call(this,e)&&Object.defineProperty(this,e,{value:t})}freezeField(e){Object.prototype.hasOwnProperty.call(this,e)&&Object.defineProperty(this,e,{writable:!1,enumerable:!0,configurable:!0})}}class E extends C{watcher;fn;flush;effecting="start";value;computer=!1;debounce2;debounce1=h();dirty=!0;get isDirty(){return this.dirty}target;proxy;constructor(e,t,r="pre"){super("Composite"),this.watcher=e,this.fn=t,this.flush=r,this.debounce2=f.call(this)}initComputed(e,t){this.computer=!0,this.target=e,this.proxy=t}_initCounter=0;_initBaseTime=0;init(e,t,r,s){const o=Date.now();if(o-this._initBaseTime>1e3&&(this._initCounter=0,this._initBaseTime=o),!this.computer&&++this._initCounter>500)throw new Error(`[死循环检测] Composite.init 循环调用超过 500 次,key=${String(t)}`);return this.computer&&!this.dirty||(this.computer||("function"==typeof this.value&&this.value(),this.watcher.effecter.stop(this)),this.watcher.effecter.addCurrent(this),this.done(e,t,r,s),this.watcher.effecter.removeCurrent(),this.dirty=!1),this.value}done(e,t,r,s){return this.computer?"doned"===this.effecting?this.recomputeWithDependency(e,t,r,s):(this.effecting="start",this.value=this.fn(r,t,e,s),this.effecting="computed",this.computer&&(this.proxy.value=this.value),this.effecting="doned"):(this.effecting="start",this.value=this.fn(r,t,e,s),this.effecting="computed",this.effecting="doned"),this.value}recomputeWithDependency(e,t,r,s){this.effecting="start";try{this.value=this.fn(r,t,e,s),this.effecting="computed",this.computer&&(this.proxy.value=this.value)}finally{this.effecting="doned"}}check(e){this.computer?"start"===this.effecting?M("Computed","计算中禁止赋值"):"function"==typeof e&&e(e=>{this.target.value=e,this.watcher.effecter.trigger(this.target,"value",e,this.proxy)}):"function"==typeof e&&e()}trigger(e,t,r,s){this.dirty=!0,this.check((i=o)=>{"sync"===this.flush?i(this.init(e,t,r,s)):"pre"===this.flush?this.debounce2(()=>i(this.init())):this.debounce1(()=>i(this.init()),0)})}stop(){"function"==typeof this.value&&this.value(),this.watcher.effecter.stop(this)}}const P=new Set([Symbol.iterator,"constructor","__proto__","prototype",NaN,null,void 0,1/0]),W=new Set(["push","pop","shift","unshift","splice","sort","reverse"]);class $ extends C{watcher;current;execStack=[];mapStore;reverseMap;collectCache;constructor(e){super("Effecter"),this.watcher=e,this.mapStore=new WeakMap,this.reverseMap=new WeakMap,this.collectCache=new WeakMap}addCurrent(e){this.current&&this.execStack.push(this.current),this.current=e,this.collectCache.set(e,new WeakMap)}removeCurrent(){this.current&&this.collectCache.delete(this.current),this.current=this.execStack.pop()}shouldExclude(e,t){return(!Array.isArray(e)||"string"!=typeof t||!W.has(t))&&(P.has(t)||R(e,t))}getCacheKey(e,t){try{return`${e.constructor.name}-${JSON.stringify(t)}-${e[Symbol.toStringTag]||""}`}catch(r){return`${e.constructor.name}-${String(t)}-${e[Symbol.toStringTag]||""}`}}collect(e,t){if(!this.current||"start"!==this.current.effecting)return;if(this.shouldExclude(e,t))return;const r=this.current,s=t,o=this.collectCache.get(r);if(o){const r=o.get(e);if(r&&r.has(t))return}const i=k(this.mapStore,e);if(i[s]=i[s]||new Set,i[s].add(r),this.mapStore.set(e,i),o){const r=o.get(e)||new Set;r.add(t),o.set(e,r)}const n=this.reverseMap.get(r)||new Set;n.add({target:e,key:s}),this.reverseMap.set(r,n)}trigger(e,t,r,s){if(this.shouldExclude(e,t))return;this.current?.check();const o=k(this.mapStore,e),i=t;if(o.hasOwnProperty(i)){const n=new Set(o[i]),c=new Set;n.forEach(o=>{o===this.current||c.has(o)||(o.trigger(e,t,r,s),c.add(o))})}this.watcher.update(s,t,r)}stop(e){const t=this.reverseMap.get(e);t&&(t.forEach(({target:t,key:r})=>{const s=this.mapStore.get(t);s&&s[r]&&(s[r].delete(e),0===s[r].size&&delete s[r],0===Object.keys(s).length&&this.mapStore.delete(t))}),this.reverseMap.delete(e),this.collectCache.delete(e))}}const D=new Set(["push","pop","shift","unshift","splice","sort","reverse"]);class N extends C{watcher;_targetToProxy=new WeakMap;_childKeyMap=new WeakMap;constructor(e){super("Observer"),this.watcher=e}create(e,t,r=new WeakSet,s=!1){return O(e)&&"Target"!==e[l]?e:S(e,["array","object"],()=>{if(r.has(e))return this._targetToProxy.get(e)||e;r.add(e);const o=new Proxy(e,this.getProxyHandler(t));if(this._targetToProxy.set(e,o),!s)for(const t in e)if(!_.has(t)&&i(e[t],["array","object"])){const s=this.create(e[t],o,r,!1);this._childKeyMap.set(s,t),e[t]=s}return o},"创建响应式数据")}getProxyHandler(e){return{has:(e,t)=>(this.watcher.effecter.collect(e,t),t in e),get:(t,r,s)=>{if(r===p)return!0;if("__JIESS_TARGET__"===r)return t;if(r===b)return e;if(r===Symbol.toStringTag)return Array.isArray(t)?"Array":t instanceof Map?"Map":t instanceof Set?"Set":t instanceof Date?"Date":t instanceof RegExp?"RegExp":"Object";if(this.watcher.effecter.collect(t,r),x(t,!0,g)&&"value"===r)return t.getValue();if(t instanceof Map||t instanceof Set||t instanceof Date||t instanceof RegExp){const e=Reflect.get(t,r);return"function"==typeof e?e.bind(t):e}const o=Reflect.get(t,r,s);if(Array.isArray(t)&&"string"==typeof r&&D.has(r)){const e=this,o=Array.prototype[r];return function(...n){const c=t.length,a="sort"===r||"reverse"===r||"unshift"===r||"shift"===r,f=a?[...t]:null,h=o.apply(t,n);if("push"===r||"unshift"===r||"splice"===r){const o=[...n];"splice"===r&&o.splice(0,2),o.forEach((c,a)=>{if(i(c,["array","object"])&&!(c instanceof Map)&&!(c instanceof Set)&&!(c instanceof Date)&&!(c instanceof RegExp)){const i=new WeakSet,f=e.create(c,s,i,!1);let h=0;"push"===r?h=t.length-o.length+a:"unshift"===r?h=a:"splice"===r&&(h=n[0]+a),e._childKeyMap.set(f,h),t[h]=f}})}if("splice"===r)for(let r="number"==typeof n[0]?n[0]:0;r<t.length;r++){const s=t[r];s&&"object"==typeof s&&e._childKeyMap.has(s)&&e._childKeyMap.set(s,r)}else if("sort"===r||"reverse"===r||"shift"===r||"unshift"===r)for(let r=0;r<t.length;r++){const s=t[r];s&&"object"==typeof s&&e._childKeyMap.has(s)&&e._childKeyMap.set(s,r)}if(a&&f)for(let e=0;e<Math.max(c,t.length);e++)Object.is(f[e],t[e])||(s[e]=t[e]);else{let e=0,o=Math.max(c,t.length);"push"===r?(e=c,o=t.length):"pop"===r?(e=t.length,o=c):"splice"===r&&(e="number"==typeof n[0]?n[0]:0);for(let r=e;r<o;r++)s[r]=t[r]}return s.length=t.length,e.trigger(t,r,h,s),h}}return o},set:(t,r,s,o)=>{if(r===b)return e=s,!0;if(Object.is(t[r],s))return!0;const i=Reflect.set(t,r,s,o);return this.trigger(t,r,s,o),i},deleteProperty:(e,t)=>{if(t in e){const r=Reflect.deleteProperty(e,t),s=this._targetToProxy.get(e)||e;return this.trigger(e,t,void 0,s),r}return Reflect.deleteProperty(e,t)}}}trigger(e,t,r,s){const{effecter:o}=this.watcher;if(x(e,!0,g))e.setValue(r,t);else if(o.trigger(e,t,r,s),Array.isArray(e)&&"string"==typeof t&&D.has(t)&&o.trigger(e,"length",e.length,s),s&&s[b]){const e=s[b],t=this._childKeyMap.get(s);void 0!==t&&o.trigger(e,t,s,e)}}}const V=(e,t)=>void 0===e?t:e;class I extends C{proxy;field;config;value;result;oldValue;isDestory=!1;cbs;debounce1;other;_resourceManager;get disposed(){return this._resourceManager.disposed}constructor(e,t,r={}){super("Observe"),this.proxy=e,this.field=t,this.config=r,this._resourceManager=new T,this.cbs=new Set,this.debounce1=h(),this._resourceManager.add({disposed:!1,dispose:()=>{this.debounce1=null}});const{hasKey:s,defaultValue:o,observe:i,...n}=r;this.other=n,this.observe(i),this.value=v(s?e[t]:e);const c=this.value=V(this.value,o);this.getValue((e,t)=>{this.result=e,t&&this.dispatch(e,{value:c,...n})})}getValue(e){const{value:t,config:r,result:s}=this,{defaultValue:o,done:i}=r;"function"==typeof i?n(i,"AsyncFunction")?(i(t,this).then(t=>e(t,!0)).catch(e=>{console.error("Observe.getValue async done error:",e)}),e(V(s,o))):e(i(t,this)):e(t)}observe(e){return"function"==typeof e&&this.cbs.add(e),this}remove(e){return"function"==typeof e&&this.cbs.delete(e),this}destroy(){this.dispose()}dispose(){this._resourceManager.disposed||(this.isDestory=!0,this._resourceManager.dispose(),this.cbs.clear(),this.proxy=null,this.field=null,this.config=null,this.other=null)}resolve(e){if(this.isDestory||!this.config)return;const t=this.value,r={value:e,oldValue:t,...this.other};let{isSync:o,hasKey:i,sameState:n=!1,done:c}=this.config;if(i){try{n=s(t,e)}catch(e){console.error(e)}this.value=v(e),this.oldValue=t,n&&"function"!=typeof c||this.getValue(e=>this.dispatch(e,r))}else{const t=()=>{this.value=v(e),this.getValue(e=>this.dispatch(e,r))};o?t():this.debounce1(()=>t(),0)}}dispatch(e,t){t.oldResult=this.result,t.result=this.result=e,this.cbs.forEach(r=>{r(e,t.oldResult,t)})}}class K extends C{_setter;_composite;value;constructor(){super("Target"),this[p]=!0,this.value=y,this[g]=!0}initSetter(e){this._setter=e}initComposite(e){this._composite=e}getValue(){return(this.value===y||this._composite&&this._composite.isDirty)&&(this.value=this._composite?.init()),this.value}setValue(e,t){"value"!==t?M("Computed","仅允许对value赋值"):"function"==typeof this._setter?(this._setter(e),this.update()):"computed"===this._composite?.effecting||M("Computed","须提供setter")}update(){this._composite&&this._composite.trigger(this,"value",this.value,this)}}class J extends C{static _default;static getDefault(){return J._default&&!J._default.disposed||(J._default=new J),J._default}static _globalResourceManager;_proxyToObserve=new WeakMap;_proxyToObserveNo=new WeakMap;_pathCache=new WeakMap;_dependencyCache=new WeakMap;effecter;observer;_resourceManager;get disposed(){return this._resourceManager?.disposed??J._globalResourceManager?.disposed??!1}constructor(){super("Watcher"),this._resourceManager=new T,this.observer=new N(this),this.effecter=new $(this)}static getGlobalResourceManager(){return J._globalResourceManager||(J._globalResourceManager=new T),J._globalResourceManager}clearProxyResources(e){this.clearObservers(e),this._proxyToObserve.delete(e),this._proxyToObserveNo.delete(e)}dispose(){this._resourceManager?.disposed||(this._resourceManager?.dispose(),J._globalResourceManager&&!J._globalResourceManager.disposed&&(J._globalResourceManager.dispose(),J._globalResourceManager=void 0),this._proxyToObserve=new WeakMap,this._proxyToObserveNo=new WeakMap,this._pathCache=new WeakMap,this._dependencyCache=new WeakMap,J._default===this&&(J._default=void 0))}static disposeAll(){J.getGlobalResourceManager().dispose()}hasLoopReference(e,t=new WeakSet){if("object"!=typeof e||null===e)return!1;if(t.has(e))return!0;t.add(e);let r=0;const s=[{obj:e,keys:Object.keys(e),index:0}];for(;s.length>0&&r<1e3;){const e=s[s.length-1];if(!e)break;const{obj:o,keys:i,index:n}=e;if(n>=i.length){t.delete(o),s.pop(),r--;continue}const c=i[n];e&&(e.index=n+1);const a=o[c];if("object"==typeof a&&null!==a){if(t.has(a))return!0;t.add(a),s.push({obj:a,keys:Object.keys(a),index:0}),r++}}return s.forEach(e=>t.delete(e.obj)),!1}createProxy(e){let t=e;return this.hasLoopReference(e)&&(t=c(e)),this.observer?.create(t)}createShallowProxy(e){return this.observer?.create(e,void 0,new WeakSet,!0)}createComputed(e,t){const r=new K,s=this.createProxy(r);if(n(e,"object")){const{get:t,set:s}=e;"function"==typeof t&&(e=t),"function"==typeof s&&r.initSetter(s)}const o=new E(this,e,t);return r.initComposite(o),o.initComputed(r,s),s}watchEffect(e,t){const r=new E(this,e,t);return r.init(),()=>r.stop()}observe(e={$proxy:{}}){let{$proxy:t,field:r,warn:s=!0,...o}=e,i=t,c=r;if("string"==typeof r&&r.includes(".")){let e=this._pathCache.get(t);e||(e=new Map,this._pathCache.set(t,e));const s=r,o=e.get(s);if(o)i=o.target,c=o.field;else{const o=r.split("."),n=o.pop(),a=u(t,o);e.set(s,{target:a,field:n}),i=a,c=n}}const a=n(i,"object")&&(Reflect.has(i,g)||Reflect.has(i,d))?"value":c,f=o.hasKey=n(a,["number","string"]);if(w(i)){const e=new I(i,a,o);if(f){const t=k(this._proxyToObserve,i,{}),r=a;t[r]=t[r]||[],t[r].push(e),this._proxyToObserve.set(i,t)}else{const t=k(this._proxyToObserveNo,i,[]);this._proxyToObserveNo.set(i,t),t.push(e)}return e}if(s){if("function"==typeof s){const e=o.done,t=s(i,a);return e?e(t):t}console.warn("$proxy:需要定义为响应式对象")}return(e=>{const{$proxy:t,field:r,done:s}=e;return s?s(t):r?t[r]:t})(e)}bind(e,t,r,{cb:s}){if(!n(r,["number","string"])&&null!=r){const o=r,i=this.createProxy(o);return i[b]=e,"function"==typeof s?s(i):t&&(e[t]=i),i}e[t]=r}update(e,t,r){const s=this._proxyToObserve.get(e);if(s&&Object.keys(s).length>0){const o=s[t];if(o&&Array.isArray(o)&&o.length>0){const i=o.filter(e=>!e.isDestory);i.length>0&&(i.forEach(e=>e.resolve(r)),s[t]=i,0===i.length&&(delete s[t],0===Object.keys(s).length&&this._proxyToObserve.delete(e)))}}this.resolveParent(e)}clearObservers(e){if(this._proxyToObserve.has(e)){const t=this._proxyToObserve.get(e);if(t)for(const e in t){const r=t[e];Array.isArray(r)&&r.forEach(e=>e.destroy())}this._proxyToObserve.delete(e)}if(this._proxyToObserveNo.has(e)){const t=this._proxyToObserveNo.get(e);Array.isArray(t)&&t.forEach(e=>e.destroy()),this._proxyToObserveNo.delete(e)}}resolveParent(e){if(this._proxyToObserveNo.has(e)){const t=this._proxyToObserveNo.get(e);if(Array.isArray(t)){const r=t.filter(t=>!t.isDestory&&(t.resolve(e),!0));r.length!==t.length&&(0===r.length?this._proxyToObserveNo.delete(e):this._proxyToObserveNo.set(e,r))}}const t=e[b];t?.[p]&&this.resolveParent(t)}}const z={reactive:new WeakMap,shallowReactive:new WeakMap,refCache:new Map,refMap:new WeakMap,computedMap:new WeakMap},B=new WeakMap;function F(e){return w(e)}function L(e){return m(e)}function U(e,t={}){return S(e,["Object","Array"],()=>{let r;const{shallow:s=!1}=t;return s?z.shallowReactive.has(e)?r=z.shallowReactive.get(e):(r=J.getDefault().createShallowProxy(e),z.shallowReactive.set(e,r)):z.reactive.has(e)?r=z.reactive.get(e):(r=J.getDefault().createProxy(e),z.reactive.set(e,r)),r},"创建响应式对象:参数必须是对象或数组类型")}function G(e,t,r={}){const{shallow:s=!1}=r;if(t&&z.refCache.has(t))return z.refCache.get(t);if(n(e,["array","object"])){const t=e;if(z.refMap.has(t))return z.refMap.get(t)}const o={value:e,[d]:!0},i=s?J.getDefault().createShallowProxy(o):J.getDefault().createProxy(o);return t?z.refCache.set(t,i):n(e,["array","object"])&&z.refMap.set(e,i),i}function H(e,t){return S(e,["Object","Function"],()=>{let r=null;return z.computedMap.has(e)?r=z.computedMap.get(e):(r=J.getDefault().createComputed(e,t),z.computedMap.set(e,r)),r},"创建计算属性:参数必须是函数或包含 getter/setter 的对象")}function q(e,t,r,s={}){return J.getDefault().bind(e,t,r,s)}function Q(e,t,r){const s={};"number"==typeof t?isNaN(t)||(s.field=t):"function"==typeof t?(r=t,t=void 0):t&&("object"==typeof t?Object.assign(s,t):"string"==typeof t&&(s.field=t));let o=e;if("string"==typeof s.field){let t=s.field;if(t&&t.includes(".")){let r=B.get(e);r||(r=new Map,B.set(e,r));const i=t,n=r.get(i);if(n)o=n.target,t=n.field;else{const s=t.split("."),n=s.pop(),c=u(e,s);r.set(i,{target:c,field:n}),o=c,t=n}s.field=t}}const i=J.getDefault().observe({$proxy:o,...s});if(x(i,"Observe")){if(s.immediate){let e;e=!s.field||"string"!=typeof s.field&&"number"!=typeof s.field?o:o[s.field],r(e,void 0)}return i.observe((e,t)=>{r(e,t)}),()=>{i.destroy()}}return()=>{}}const X=(e,t)=>S(e,"function",()=>J.getDefault().watchEffect(e,t),"创建副作用观察器:参数必须是函数");function Y(e){if(z.reactive.has(e)&&z.reactive.delete(e),z.shallowReactive.has(e)&&z.shallowReactive.delete(e),z.refMap.has(e)){const t=z.refMap.get(e);if(t)for(const[e,r]of z.refCache.entries())r===t&&z.refCache.delete(e);z.refMap.delete(e)}}function Z(e){z.refCache.delete(e)}new Map,new Set(["@keyframes","@-webkit-keyframes","@-moz-keyframes","@-o-keyframes","@font-face","@import","@charset","@namespace","@layer","@media","@supports","@page","@counter-style","@font-feature-values","@property","@color-profile"]),new WeakMap;const ee=new Map,te=[];function re(){te.forEach(e=>{const t=ee.get(e);t&&"function"==typeof t.dispose?t.dispose():t&&"function"==typeof t.destroy&&t.destroy()}),ee.clear(),te.length=0}function se(){return ee.size}function oe(e,t,r){return new e(j(t),r).jiess}const ie=oe;module.exports=t})();