2023-07-24 11:13:08 +08:00
function makeMap ( str , expectsLowerCase ) {
2023-09-06 09:51:55 +08:00
const map = /* @__PURE__ */ Object . create ( null );
const list = str . split ( "," );
for ( let i = 0 ; i < list . length ; i ++ ) {
map [ list [ i ]] = true ;
}
return expectsLowerCase ? ( val ) => !! map [ val . toLowerCase ()] : ( val ) => !! map [ val ];
2023-07-24 11:13:08 +08:00
}
const extend = Object . assign ;
2023-09-06 09:51:55 +08:00
const hasOwnProperty$1 = Object . prototype . hasOwnProperty ;
const hasOwn = ( val , key ) => hasOwnProperty$1 . call ( val , key );
2023-07-24 11:13:08 +08:00
const isArray = Array . isArray ;
2023-09-06 09:51:55 +08:00
const isMap = ( val ) => toTypeString ( val ) === "[object Map]" ;
const isFunction = ( val ) => typeof val === "function" ;
const isString = ( val ) => typeof val === "string" ;
const isSymbol = ( val ) => typeof val === "symbol" ;
const isObject = ( val ) => val !== null && typeof val === "object" ;
2023-07-24 11:13:08 +08:00
const objectToString = Object . prototype . toString ;
const toTypeString = ( value ) => objectToString . call ( value );
const toRawType = ( value ) => {
2023-09-06 09:51:55 +08:00
return toTypeString ( value ). slice ( 8 , - 1 );
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
const isIntegerKey = ( key ) => isString ( key ) && key !== "NaN" && key [ 0 ] !== "-" && "" + parseInt ( key , 10 ) === key ;
2023-07-24 11:13:08 +08:00
const cacheStringFunction = ( fn ) => {
2023-09-06 09:51:55 +08:00
const cache = /* @__PURE__ */ Object . create ( null );
return ( str ) => {
const hit = cache [ str ];
return hit || ( cache [ str ] = fn ( str ));
};
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
const capitalize = cacheStringFunction (
( str ) => str . charAt ( 0 ). toUpperCase () + str . slice ( 1 )
);
2023-07-24 11:13:08 +08:00
const hasChanged = ( value , oldValue ) => ! Object . is ( value , oldValue );
const def = ( obj , key , value ) => {
2023-09-06 09:51:55 +08:00
Object . defineProperty ( obj , key , {
configurable : true ,
enumerable : false ,
value
});
2023-07-24 11:13:08 +08:00
};
function warn ( msg , ... args ) {
2023-09-06 09:51:55 +08:00
console . warn ( `[Vue warn] ${ msg } ` , ... args );
2023-07-24 11:13:08 +08:00
}
let activeEffectScope ;
class EffectScope {
2023-09-06 09:51:55 +08:00
constructor ( detached = false ) {
this . detached = detached ;
2023-07-24 11:13:08 +08:00
/**
* @internal
*/
2023-09-06 09:51:55 +08:00
this . _active = true ;
2023-07-24 11:13:08 +08:00
/**
* @internal
*/
2023-09-06 09:51:55 +08:00
this . effects = [];
/**
* @internal
*/
this . cleanups = [];
this . parent = activeEffectScope ;
if ( ! detached && activeEffectScope ) {
this . index = ( activeEffectScope . scopes || ( activeEffectScope . scopes = [])). push (
this
) - 1 ;
}
}
get active () {
return this . _active ;
}
run ( fn ) {
if ( this . _active ) {
const currentEffectScope = activeEffectScope ;
try {
activeEffectScope = this ;
return fn ();
} finally {
activeEffectScope = currentEffectScope ;
}
} else {
warn ( `cannot run an inactive effect scope.` );
}
}
/**
* This should only be called on non-detached scopes
* @internal
*/
on () {
activeEffectScope = this ;
}
/**
* This should only be called on non-detached scopes
* @internal
*/
off () {
activeEffectScope = this . parent ;
}
stop ( fromParent ) {
if ( this . _active ) {
let i , l ;
for ( i = 0 , l = this . effects . length ; i < l ; i ++ ) {
this . effects [ i ]. stop ();
}
for ( i = 0 , l = this . cleanups . length ; i < l ; i ++ ) {
this . cleanups [ i ]();
}
if ( this . scopes ) {
for ( i = 0 , l = this . scopes . length ; i < l ; i ++ ) {
this . scopes [ i ]. stop ( true );
}
}
if ( ! this . detached && this . parent && ! fromParent ) {
const last = this . parent . scopes . pop ();
if ( last && last !== this ) {
this . parent . scopes [ this . index ] = last ;
last . index = this . index ;
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
this . parent = void 0 ;
this . _active = false ;
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
2023-07-24 11:13:08 +08:00
}
function effectScope ( detached ) {
2023-09-06 09:51:55 +08:00
return new EffectScope ( detached );
2023-07-24 11:13:08 +08:00
}
function recordEffectScope ( effect , scope = activeEffectScope ) {
2023-09-06 09:51:55 +08:00
if ( scope && scope . active ) {
scope . effects . push ( effect );
}
2023-07-24 11:13:08 +08:00
}
function getCurrentScope () {
2023-09-06 09:51:55 +08:00
return activeEffectScope ;
2023-07-24 11:13:08 +08:00
}
function onScopeDispose ( fn ) {
2023-09-06 09:51:55 +08:00
if ( activeEffectScope ) {
activeEffectScope . cleanups . push ( fn );
} else {
warn (
`onScopeDispose() is called when there is no active effect scope to be associated with.`
);
}
2023-07-24 11:13:08 +08:00
}
const createDep = ( effects ) => {
2023-09-06 09:51:55 +08:00
const dep = new Set ( effects );
dep . w = 0 ;
dep . n = 0 ;
return dep ;
2023-07-24 11:13:08 +08:00
};
const wasTracked = ( dep ) => ( dep . w & trackOpBit ) > 0 ;
const newTracked = ( dep ) => ( dep . n & trackOpBit ) > 0 ;
const initDepMarkers = ({ deps }) => {
2023-09-06 09:51:55 +08:00
if ( deps . length ) {
for ( let i = 0 ; i < deps . length ; i ++ ) {
deps [ i ]. w |= trackOpBit ;
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
2023-07-24 11:13:08 +08:00
};
const finalizeDepMarkers = ( effect ) => {
2023-09-06 09:51:55 +08:00
const { deps } = effect ;
if ( deps . length ) {
let ptr = 0 ;
for ( let i = 0 ; i < deps . length ; i ++ ) {
const dep = deps [ i ];
if ( wasTracked ( dep ) && ! newTracked ( dep )) {
dep . delete ( effect );
} else {
deps [ ptr ++ ] = dep ;
}
dep . w &= ~ trackOpBit ;
dep . n &= ~ trackOpBit ;
}
deps . length = ptr ;
}
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
const targetMap = /* @__PURE__ */ new WeakMap ();
2023-07-24 11:13:08 +08:00
let effectTrackDepth = 0 ;
let trackOpBit = 1 ;
const maxMarkerBits = 30 ;
let activeEffect ;
2023-09-06 09:51:55 +08:00
const ITERATE_KEY = Symbol ( "iterate" );
const MAP_KEY_ITERATE_KEY = Symbol ( "Map key iterate" );
2023-07-24 11:13:08 +08:00
class ReactiveEffect {
2023-09-06 09:51:55 +08:00
constructor ( fn , scheduler = null , scope ) {
this . fn = fn ;
this . scheduler = scheduler ;
this . active = true ;
this . deps = [];
this . parent = void 0 ;
recordEffectScope ( this , scope );
}
run () {
if ( ! this . active ) {
return this . fn ();
}
let parent = activeEffect ;
let lastShouldTrack = shouldTrack ;
while ( parent ) {
if ( parent === this ) {
return ;
}
parent = parent . parent ;
}
try {
this . parent = activeEffect ;
activeEffect = this ;
shouldTrack = true ;
trackOpBit = 1 << ++ effectTrackDepth ;
if ( effectTrackDepth <= maxMarkerBits ) {
initDepMarkers ( this );
} else {
cleanupEffect ( this );
}
return this . fn ();
} finally {
if ( effectTrackDepth <= maxMarkerBits ) {
finalizeDepMarkers ( this );
}
trackOpBit = 1 << -- effectTrackDepth ;
activeEffect = this . parent ;
shouldTrack = lastShouldTrack ;
this . parent = void 0 ;
if ( this . deferStop ) {
this . stop ();
}
}
}
stop () {
if ( activeEffect === this ) {
this . deferStop = true ;
} else if ( this . active ) {
cleanupEffect ( this );
if ( this . onStop ) {
this . onStop ();
}
this . active = false ;
}
}
}
function cleanupEffect ( effect2 ) {
const { deps } = effect2 ;
if ( deps . length ) {
for ( let i = 0 ; i < deps . length ; i ++ ) {
deps [ i ]. delete ( effect2 );
}
deps . length = 0 ;
}
2023-07-24 11:13:08 +08:00
}
function effect ( fn , options ) {
2023-09-06 09:51:55 +08:00
if ( fn . effect ) {
fn = fn . effect . fn ;
}
const _effect = new ReactiveEffect ( fn );
if ( options ) {
extend ( _effect , options );
if ( options . scope )
recordEffectScope ( _effect , options . scope );
}
if ( ! options || ! options . lazy ) {
_effect . run ();
}
const runner = _effect . run . bind ( _effect );
runner . effect = _effect ;
return runner ;
2023-07-24 11:13:08 +08:00
}
function stop ( runner ) {
2023-09-06 09:51:55 +08:00
runner . effect . stop ();
2023-07-24 11:13:08 +08:00
}
let shouldTrack = true ;
const trackStack = [];
function pauseTracking () {
2023-09-06 09:51:55 +08:00
trackStack . push ( shouldTrack );
shouldTrack = false ;
2023-07-24 11:13:08 +08:00
}
function enableTracking () {
2023-09-06 09:51:55 +08:00
trackStack . push ( shouldTrack );
shouldTrack = true ;
2023-07-24 11:13:08 +08:00
}
function resetTracking () {
2023-09-06 09:51:55 +08:00
const last = trackStack . pop ();
shouldTrack = last === void 0 ? true : last ;
2023-07-24 11:13:08 +08:00
}
function track ( target , type , key ) {
2023-09-06 09:51:55 +08:00
if ( shouldTrack && activeEffect ) {
let depsMap = targetMap . get ( target );
if ( ! depsMap ) {
targetMap . set ( target , depsMap = /* @__PURE__ */ new Map ());
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
let dep = depsMap . get ( key );
if ( ! dep ) {
depsMap . set ( key , dep = createDep ());
}
const eventInfo = { effect : activeEffect , target , type , key } ;
trackEffects ( dep , eventInfo );
}
2023-07-24 11:13:08 +08:00
}
function trackEffects ( dep , debuggerEventExtraInfo ) {
2023-09-06 09:51:55 +08:00
let shouldTrack2 = false ;
if ( effectTrackDepth <= maxMarkerBits ) {
if ( ! newTracked ( dep )) {
dep . n |= trackOpBit ;
shouldTrack2 = ! wasTracked ( dep );
}
} else {
shouldTrack2 = ! dep . has ( activeEffect );
}
if ( shouldTrack2 ) {
dep . add ( activeEffect );
activeEffect . deps . push ( dep );
if ( activeEffect . onTrack ) {
activeEffect . onTrack (
extend (
{
effect : activeEffect
},
debuggerEventExtraInfo
)
);
}
}
2023-07-24 11:13:08 +08:00
}
function trigger ( target , type , key , newValue , oldValue , oldTarget ) {
2023-09-06 09:51:55 +08:00
const depsMap = targetMap . get ( target );
if ( ! depsMap ) {
return ;
}
let deps = [];
if ( type === "clear" ) {
deps = [... depsMap . values ()];
} else if ( key === "length" && isArray ( target )) {
const newLength = Number ( newValue );
depsMap . forEach (( dep , key2 ) => {
if ( key2 === "length" || key2 >= newLength ) {
deps . push ( dep );
}
});
} else {
if ( key !== void 0 ) {
deps . push ( depsMap . get ( key ));
}
switch ( type ) {
case "add" :
if ( ! isArray ( target )) {
deps . push ( depsMap . get ( ITERATE_KEY ));
if ( isMap ( target )) {
deps . push ( depsMap . get ( MAP_KEY_ITERATE_KEY ));
}
} else if ( isIntegerKey ( key )) {
deps . push ( depsMap . get ( "length" ));
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
break ;
case "delete" :
if ( ! isArray ( target )) {
deps . push ( depsMap . get ( ITERATE_KEY ));
if ( isMap ( target )) {
deps . push ( depsMap . get ( MAP_KEY_ITERATE_KEY ));
}
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
break ;
case "set" :
if ( isMap ( target )) {
deps . push ( depsMap . get ( ITERATE_KEY ));
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
break ;
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
const eventInfo = { target , type , key , newValue , oldValue , oldTarget } ;
if ( deps . length === 1 ) {
if ( deps [ 0 ]) {
{
triggerEffects ( deps [ 0 ], eventInfo );
}
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
} else {
const effects = [];
for ( const dep of deps ) {
if ( dep ) {
effects . push (... dep );
}
}
{
triggerEffects ( createDep ( effects ), eventInfo );
}
}
2023-07-24 11:13:08 +08:00
}
function triggerEffects ( dep , debuggerEventExtraInfo ) {
2023-09-06 09:51:55 +08:00
const effects = isArray ( dep ) ? dep : [... dep ];
for ( const effect2 of effects ) {
if ( effect2 . computed ) {
triggerEffect ( effect2 , debuggerEventExtraInfo );
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
for ( const effect2 of effects ) {
if ( ! effect2 . computed ) {
triggerEffect ( effect2 , debuggerEventExtraInfo );
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
function triggerEffect ( effect2 , debuggerEventExtraInfo ) {
if ( effect2 !== activeEffect || effect2 . allowRecurse ) {
if ( effect2 . onTrigger ) {
effect2 . onTrigger ( extend ({ effect : effect2 }, debuggerEventExtraInfo ));
}
if ( effect2 . scheduler ) {
effect2 . scheduler ();
} else {
effect2 . run ();
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
}
function getDepFromReactive ( object , key ) {
var _a ;
return ( _a = targetMap . get ( object )) == null ? void 0 : _a . get ( key );
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
const isNonTrackableKeys = /* @__PURE__ */ makeMap ( `__proto__,__v_isRef,__isVue` );
2023-07-24 11:13:08 +08:00
const builtInSymbols = new Set (
2023-09-06 09:51:55 +08:00
/* @__PURE__ */ Object . getOwnPropertyNames ( Symbol ). filter (( key ) => key !== "arguments" && key !== "caller" ). map (( key ) => Symbol [ key ]). filter ( isSymbol )
);
const get$1 = /* @__PURE__ */ createGetter ();
const shallowGet = /* @__PURE__ */ createGetter ( false , true );
const readonlyGet = /* @__PURE__ */ createGetter ( true );
const shallowReadonlyGet = /* @__PURE__ */ createGetter ( true , true );
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations ();
2023-07-24 11:13:08 +08:00
function createArrayInstrumentations () {
2023-09-06 09:51:55 +08:00
const instrumentations = {};
[ "includes" , "indexOf" , "lastIndexOf" ]. forEach (( key ) => {
instrumentations [ key ] = function (... args ) {
const arr = toRaw ( this );
for ( let i = 0 , l = this . length ; i < l ; i ++ ) {
track ( arr , "get" , i + "" );
}
const res = arr [ key ](... args );
if ( res === - 1 || res === false ) {
return arr [ key ](... args . map ( toRaw ));
} else {
2023-07-24 11:13:08 +08:00
return res ;
2023-09-06 09:51:55 +08:00
}
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
});
[ "push" , "pop" , "shift" , "unshift" , "splice" ]. forEach (( key ) => {
instrumentations [ key ] = function (... args ) {
pauseTracking ();
const res = toRaw ( this )[ key ]. apply ( this , args );
resetTracking ();
return res ;
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
});
return instrumentations ;
}
function hasOwnProperty ( key ) {
const obj = toRaw ( this );
track ( obj , "has" , key );
return obj . hasOwnProperty ( key );
}
function createGetter ( isReadonly2 = false , shallow = false ) {
return function get2 ( target , key , receiver ) {
if ( key === "__v_isReactive" ) {
return ! isReadonly2 ;
} else if ( key === "__v_isReadonly" ) {
return isReadonly2 ;
} else if ( key === "__v_isShallow" ) {
return shallow ;
} else if ( key === "__v_raw" && receiver === ( isReadonly2 ? shallow ? shallowReadonlyMap : readonlyMap : shallow ? shallowReactiveMap : reactiveMap ). get ( target )) {
return target ;
}
const targetIsArray = isArray ( target );
if ( ! isReadonly2 ) {
if ( targetIsArray && hasOwn ( arrayInstrumentations , key )) {
return Reflect . get ( arrayInstrumentations , key , receiver );
}
if ( key === "hasOwnProperty" ) {
return hasOwnProperty ;
}
}
const res = Reflect . get ( target , key , receiver );
if ( isSymbol ( key ) ? builtInSymbols . has ( key ) : isNonTrackableKeys ( key )) {
return res ;
}
if ( ! isReadonly2 ) {
track ( target , "get" , key );
}
if ( shallow ) {
return res ;
}
if ( isRef ( res )) {
return targetIsArray && isIntegerKey ( key ) ? res : res . value ;
}
if ( isObject ( res )) {
return isReadonly2 ? readonly ( res ) : reactive ( res );
}
return res ;
};
}
const set$1 = /* @__PURE__ */ createSetter ();
const shallowSet = /* @__PURE__ */ createSetter ( true );
function createSetter ( shallow = false ) {
return function set2 ( target , key , value , receiver ) {
let oldValue = target [ key ];
if ( isReadonly ( oldValue ) && isRef ( oldValue ) && ! isRef ( value )) {
return false ;
}
if ( ! shallow ) {
if ( ! isShallow ( value ) && ! isReadonly ( value )) {
oldValue = toRaw ( oldValue );
value = toRaw ( value );
}
if ( ! isArray ( target ) && isRef ( oldValue ) && ! isRef ( value )) {
oldValue . value = value ;
return true ;
}
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
const hadKey = isArray ( target ) && isIntegerKey ( key ) ? Number ( key ) < target . length : hasOwn ( target , key );
const result = Reflect . set ( target , key , value , receiver );
if ( target === toRaw ( receiver )) {
if ( ! hadKey ) {
trigger ( target , "add" , key , value );
} else if ( hasChanged ( value , oldValue )) {
trigger ( target , "set" , key , value , oldValue );
}
2023-07-24 11:13:08 +08:00
}
return result ;
2023-09-06 09:51:55 +08:00
};
}
function deleteProperty ( target , key ) {
const hadKey = hasOwn ( target , key );
const oldValue = target [ key ];
const result = Reflect . deleteProperty ( target , key );
if ( result && hadKey ) {
trigger ( target , "delete" , key , void 0 , oldValue );
}
return result ;
}
function has$1 ( target , key ) {
const result = Reflect . has ( target , key );
if ( ! isSymbol ( key ) || ! builtInSymbols . has ( key )) {
track ( target , "has" , key );
}
return result ;
2023-07-24 11:13:08 +08:00
}
function ownKeys ( target ) {
2023-09-06 09:51:55 +08:00
track ( target , "iterate" , isArray ( target ) ? "length" : ITERATE_KEY );
return Reflect . ownKeys ( target );
2023-07-24 11:13:08 +08:00
}
const mutableHandlers = {
2023-09-06 09:51:55 +08:00
get : get$1 ,
set : set$1 ,
deleteProperty ,
has : has$1 ,
ownKeys
2023-07-24 11:13:08 +08:00
};
const readonlyHandlers = {
2023-09-06 09:51:55 +08:00
get : readonlyGet ,
set ( target , key ) {
{
warn (
`Set operation on key " ${ String ( key ) } " failed: target is readonly.` ,
target
);
}
return true ;
},
deleteProperty ( target , key ) {
{
warn (
`Delete operation on key " ${ String ( key ) } " failed: target is readonly.` ,
target
);
}
return true ;
}
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
const shallowReactiveHandlers = /* @__PURE__ */ extend (
{},
mutableHandlers ,
{
2023-07-24 11:13:08 +08:00
get : shallowGet ,
set : shallowSet
2023-09-06 09:51:55 +08:00
}
);
const shallowReadonlyHandlers = /* @__PURE__ */ extend (
{},
readonlyHandlers ,
{
2023-07-24 11:13:08 +08:00
get : shallowReadonlyGet
2023-09-06 09:51:55 +08:00
}
);
2023-07-24 11:13:08 +08:00
const toShallow = ( value ) => value ;
const getProto = ( v ) => Reflect . getPrototypeOf ( v );
2023-09-06 09:51:55 +08:00
function get ( target , key , isReadonly = false , isShallow = false ) {
target = target [ "__v_raw" ];
const rawTarget = toRaw ( target );
const rawKey = toRaw ( key );
if ( ! isReadonly ) {
if ( key !== rawKey ) {
track ( rawTarget , "get" , key );
}
track ( rawTarget , "get" , rawKey );
}
const { has : has2 } = getProto ( rawTarget );
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive ;
if ( has2 . call ( rawTarget , key )) {
return wrap ( target . get ( key ));
} else if ( has2 . call ( rawTarget , rawKey )) {
return wrap ( target . get ( rawKey ));
} else if ( target !== rawTarget ) {
target . get ( key );
}
}
function has ( key , isReadonly = false ) {
const target = this [ "__v_raw" ];
const rawTarget = toRaw ( target );
const rawKey = toRaw ( key );
if ( ! isReadonly ) {
if ( key !== rawKey ) {
track ( rawTarget , "has" , key );
}
track ( rawTarget , "has" , rawKey );
}
return key === rawKey ? target . has ( key ) : target . has ( key ) || target . has ( rawKey );
2023-07-24 11:13:08 +08:00
}
function size ( target , isReadonly = false ) {
2023-09-06 09:51:55 +08:00
target = target [ "__v_raw" ];
! isReadonly && track ( toRaw ( target ), "iterate" , ITERATE_KEY );
return Reflect . get ( target , "size" , target );
2023-07-24 11:13:08 +08:00
}
function add ( value ) {
2023-09-06 09:51:55 +08:00
value = toRaw ( value );
const target = toRaw ( this );
const proto = getProto ( target );
const hadKey = proto . has . call ( target , value );
if ( ! hadKey ) {
target . add ( value );
trigger ( target , "add" , value , value );
}
return this ;
}
function set ( key , value ) {
value = toRaw ( value );
const target = toRaw ( this );
const { has : has2 , get : get2 } = getProto ( target );
let hadKey = has2 . call ( target , key );
if ( ! hadKey ) {
key = toRaw ( key );
hadKey = has2 . call ( target , key );
} else {
checkIdentityKeys ( target , has2 , key );
}
const oldValue = get2 . call ( target , key );
target . set ( key , value );
if ( ! hadKey ) {
trigger ( target , "add" , key , value );
} else if ( hasChanged ( value , oldValue )) {
trigger ( target , "set" , key , value , oldValue );
}
return this ;
2023-07-24 11:13:08 +08:00
}
function deleteEntry ( key ) {
2023-09-06 09:51:55 +08:00
const target = toRaw ( this );
const { has : has2 , get : get2 } = getProto ( target );
let hadKey = has2 . call ( target , key );
if ( ! hadKey ) {
key = toRaw ( key );
hadKey = has2 . call ( target , key );
} else {
checkIdentityKeys ( target , has2 , key );
}
const oldValue = get2 ? get2 . call ( target , key ) : void 0 ;
const result = target . delete ( key );
if ( hadKey ) {
trigger ( target , "delete" , key , void 0 , oldValue );
}
return result ;
2023-07-24 11:13:08 +08:00
}
function clear () {
2023-09-06 09:51:55 +08:00
const target = toRaw ( this );
const hadItems = target . size !== 0 ;
const oldTarget = isMap ( target ) ? new Map ( target ) : new Set ( target ) ;
const result = target . clear ();
if ( hadItems ) {
trigger ( target , "clear" , void 0 , void 0 , oldTarget );
}
return result ;
2023-07-24 11:13:08 +08:00
}
function createForEach ( isReadonly , isShallow ) {
2023-09-06 09:51:55 +08:00
return function forEach ( callback , thisArg ) {
const observed = this ;
const target = observed [ "__v_raw" ];
const rawTarget = toRaw ( target );
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive ;
! isReadonly && track ( rawTarget , "iterate" , ITERATE_KEY );
return target . forEach (( value , key ) => {
return callback . call ( thisArg , wrap ( value ), wrap ( key ), observed );
});
};
2023-07-24 11:13:08 +08:00
}
function createIterableMethod ( method , isReadonly , isShallow ) {
2023-09-06 09:51:55 +08:00
return function (... args ) {
const target = this [ "__v_raw" ];
const rawTarget = toRaw ( target );
const targetIsMap = isMap ( rawTarget );
const isPair = method === "entries" || method === Symbol . iterator && targetIsMap ;
const isKeyOnly = method === "keys" && targetIsMap ;
const innerIterator = target [ method ](... args );
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive ;
! isReadonly && track (
rawTarget ,
"iterate" ,
isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
);
return {
// iterator protocol
next () {
const { value , done } = innerIterator . next ();
return done ? { value , done } : {
value : isPair ? [ wrap ( value [ 0 ]), wrap ( value [ 1 ])] : wrap ( value ),
done
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
},
// iterable protocol
[ Symbol . iterator ]() {
return this ;
}
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
};
2023-07-24 11:13:08 +08:00
}
function createReadonlyMethod ( type ) {
2023-09-06 09:51:55 +08:00
return function (... args ) {
{
const key = args [ 0 ] ? `on key " ${ args [ 0 ] } " ` : `` ;
console . warn (
` ${ capitalize ( type ) } operation ${ key } failed: target is readonly.` ,
toRaw ( this )
);
}
return type === "delete" ? false : this ;
};
2023-07-24 11:13:08 +08:00
}
function createInstrumentations () {
2023-09-06 09:51:55 +08:00
const mutableInstrumentations2 = {
get ( key ) {
return get ( this , key );
},
get size () {
return size ( this );
},
has ,
add ,
set ,
delete : deleteEntry ,
clear ,
forEach : createForEach ( false , false )
};
const shallowInstrumentations2 = {
get ( key ) {
return get ( this , key , false , true );
},
get size () {
return size ( this );
},
has ,
add ,
set ,
delete : deleteEntry ,
clear ,
forEach : createForEach ( false , true )
};
const readonlyInstrumentations2 = {
get ( key ) {
return get ( this , key , true );
},
get size () {
return size ( this , true );
},
has ( key ) {
return has . call ( this , key , true );
},
add : createReadonlyMethod ( "add" ),
set : createReadonlyMethod ( "set" ),
delete : createReadonlyMethod ( "delete" ),
clear : createReadonlyMethod ( "clear" ),
forEach : createForEach ( true , false )
};
const shallowReadonlyInstrumentations2 = {
get ( key ) {
return get ( this , key , true , true );
},
get size () {
return size ( this , true );
},
has ( key ) {
return has . call ( this , key , true );
},
add : createReadonlyMethod ( "add" ),
set : createReadonlyMethod ( "set" ),
delete : createReadonlyMethod ( "delete" ),
clear : createReadonlyMethod ( "clear" ),
forEach : createForEach ( true , true )
};
const iteratorMethods = [ "keys" , "values" , "entries" , Symbol . iterator ];
iteratorMethods . forEach (( method ) => {
mutableInstrumentations2 [ method ] = createIterableMethod (
method ,
false ,
false
);
readonlyInstrumentations2 [ method ] = createIterableMethod (
method ,
true ,
false
);
shallowInstrumentations2 [ method ] = createIterableMethod (
method ,
false ,
true
);
shallowReadonlyInstrumentations2 [ method ] = createIterableMethod (
method ,
true ,
true
);
});
return [
mutableInstrumentations2 ,
readonlyInstrumentations2 ,
shallowInstrumentations2 ,
shallowReadonlyInstrumentations2
];
}
const [
mutableInstrumentations ,
readonlyInstrumentations ,
shallowInstrumentations ,
shallowReadonlyInstrumentations
] = /* @__PURE__ */ createInstrumentations ();
2023-07-24 11:13:08 +08:00
function createInstrumentationGetter ( isReadonly , shallow ) {
2023-09-06 09:51:55 +08:00
const instrumentations = shallow ? isReadonly ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations ;
return ( target , key , receiver ) => {
if ( key === "__v_isReactive" ) {
return ! isReadonly ;
} else if ( key === "__v_isReadonly" ) {
return isReadonly ;
} else if ( key === "__v_raw" ) {
return target ;
}
return Reflect . get (
hasOwn ( instrumentations , key ) && key in target ? instrumentations : target ,
key ,
receiver
);
};
2023-07-24 11:13:08 +08:00
}
const mutableCollectionHandlers = {
2023-09-06 09:51:55 +08:00
get : /* @__PURE__ */ createInstrumentationGetter ( false , false )
2023-07-24 11:13:08 +08:00
};
const shallowCollectionHandlers = {
2023-09-06 09:51:55 +08:00
get : /* @__PURE__ */ createInstrumentationGetter ( false , true )
2023-07-24 11:13:08 +08:00
};
const readonlyCollectionHandlers = {
2023-09-06 09:51:55 +08:00
get : /* @__PURE__ */ createInstrumentationGetter ( true , false )
2023-07-24 11:13:08 +08:00
};
const shallowReadonlyCollectionHandlers = {
2023-09-06 09:51:55 +08:00
get : /* @__PURE__ */ createInstrumentationGetter ( true , true )
2023-07-24 11:13:08 +08:00
};
2023-09-06 09:51:55 +08:00
function checkIdentityKeys ( target , has2 , key ) {
const rawKey = toRaw ( key );
if ( rawKey !== key && has2 . call ( target , rawKey )) {
const type = toRawType ( target );
console . warn (
`Reactive ${ type } contains both the raw and reactive versions of the same object ${ type === `Map` ? ` as keys` : `` } , which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
);
}
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
const reactiveMap = /* @__PURE__ */ new WeakMap ();
const shallowReactiveMap = /* @__PURE__ */ new WeakMap ();
const readonlyMap = /* @__PURE__ */ new WeakMap ();
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap ();
2023-07-24 11:13:08 +08:00
function targetTypeMap ( rawType ) {
2023-09-06 09:51:55 +08:00
switch ( rawType ) {
case "Object" :
case "Array" :
return 1 /* COMMON */ ;
case "Map" :
case "Set" :
case "WeakMap" :
case "WeakSet" :
return 2 /* COLLECTION */ ;
default :
return 0 /* INVALID */ ;
}
2023-07-24 11:13:08 +08:00
}
function getTargetType ( value ) {
2023-09-06 09:51:55 +08:00
return value [ "__v_skip" ] || ! Object . isExtensible ( value ) ? 0 /* INVALID */ : targetTypeMap ( toRawType ( value ));
2023-07-24 11:13:08 +08:00
}
function reactive ( target ) {
2023-09-06 09:51:55 +08:00
if ( isReadonly ( target )) {
return target ;
}
return createReactiveObject (
target ,
false ,
mutableHandlers ,
mutableCollectionHandlers ,
reactiveMap
);
2023-07-24 11:13:08 +08:00
}
function shallowReactive ( target ) {
2023-09-06 09:51:55 +08:00
return createReactiveObject (
target ,
false ,
shallowReactiveHandlers ,
shallowCollectionHandlers ,
shallowReactiveMap
);
2023-07-24 11:13:08 +08:00
}
function readonly ( target ) {
2023-09-06 09:51:55 +08:00
return createReactiveObject (
target ,
true ,
readonlyHandlers ,
readonlyCollectionHandlers ,
readonlyMap
);
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
function shallowReadonly ( target ) {
return createReactiveObject (
target ,
true ,
shallowReadonlyHandlers ,
shallowReadonlyCollectionHandlers ,
shallowReadonlyMap
);
}
function createReactiveObject ( target , isReadonly2 , baseHandlers , collectionHandlers , proxyMap ) {
if ( ! isObject ( target )) {
{
console . warn ( `value cannot be made reactive: ${ String ( target ) } ` );
}
return target ;
}
if ( target [ "__v_raw" ] && ! ( isReadonly2 && target [ "__v_isReactive" ])) {
return target ;
}
const existingProxy = proxyMap . get ( target );
if ( existingProxy ) {
return existingProxy ;
}
const targetType = getTargetType ( target );
if ( targetType === 0 /* INVALID */ ) {
return target ;
}
const proxy = new Proxy (
target ,
targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
);
proxyMap . set ( target , proxy );
return proxy ;
2023-07-24 11:13:08 +08:00
}
function isReactive ( value ) {
2023-09-06 09:51:55 +08:00
if ( isReadonly ( value )) {
return isReactive ( value [ "__v_raw" ]);
}
return !! ( value && value [ "__v_isReactive" ]);
2023-07-24 11:13:08 +08:00
}
function isReadonly ( value ) {
2023-09-06 09:51:55 +08:00
return !! ( value && value [ "__v_isReadonly" ]);
2023-07-24 11:13:08 +08:00
}
function isShallow ( value ) {
2023-09-06 09:51:55 +08:00
return !! ( value && value [ "__v_isShallow" ]);
2023-07-24 11:13:08 +08:00
}
function isProxy ( value ) {
2023-09-06 09:51:55 +08:00
return isReactive ( value ) || isReadonly ( value );
2023-07-24 11:13:08 +08:00
}
function toRaw ( observed ) {
2023-09-06 09:51:55 +08:00
const raw = observed && observed [ "__v_raw" ];
return raw ? toRaw ( raw ) : observed ;
2023-07-24 11:13:08 +08:00
}
function markRaw ( value ) {
2023-09-06 09:51:55 +08:00
def ( value , "__v_skip" , true );
return value ;
2023-07-24 11:13:08 +08:00
}
const toReactive = ( value ) => isObject ( value ) ? reactive ( value ) : value ;
const toReadonly = ( value ) => isObject ( value ) ? readonly ( value ) : value ;
2023-09-06 09:51:55 +08:00
function trackRefValue ( ref2 ) {
if ( shouldTrack && activeEffect ) {
ref2 = toRaw ( ref2 );
{
trackEffects ( ref2 . dep || ( ref2 . dep = createDep ()), {
target : ref2 ,
type : "get" ,
key : "value"
});
}
}
}
function triggerRefValue ( ref2 , newVal ) {
ref2 = toRaw ( ref2 );
const dep = ref2 . dep ;
if ( dep ) {
{
triggerEffects ( dep , {
target : ref2 ,
type : "set" ,
key : "value" ,
newValue : newVal
});
}
}
2023-07-24 11:13:08 +08:00
}
function isRef ( r ) {
2023-09-06 09:51:55 +08:00
return !! ( r && r . __v_isRef === true );
2023-07-24 11:13:08 +08:00
}
function ref ( value ) {
2023-09-06 09:51:55 +08:00
return createRef ( value , false );
2023-07-24 11:13:08 +08:00
}
function shallowRef ( value ) {
2023-09-06 09:51:55 +08:00
return createRef ( value , true );
2023-07-24 11:13:08 +08:00
}
function createRef ( rawValue , shallow ) {
2023-09-06 09:51:55 +08:00
if ( isRef ( rawValue )) {
return rawValue ;
}
return new RefImpl ( rawValue , shallow );
2023-07-24 11:13:08 +08:00
}
class RefImpl {
2023-09-06 09:51:55 +08:00
constructor ( value , __v_isShallow ) {
this . __v_isShallow = __v_isShallow ;
this . dep = void 0 ;
this . __v_isRef = true ;
this . _rawValue = __v_isShallow ? value : toRaw ( value );
this . _value = __v_isShallow ? value : toReactive ( value );
}
get value () {
trackRefValue ( this );
return this . _value ;
}
set value ( newVal ) {
const useDirectValue = this . __v_isShallow || isShallow ( newVal ) || isReadonly ( newVal );
newVal = useDirectValue ? newVal : toRaw ( newVal );
if ( hasChanged ( newVal , this . _rawValue )) {
this . _rawValue = newVal ;
this . _value = useDirectValue ? newVal : toReactive ( newVal );
triggerRefValue ( this , newVal );
}
}
}
function triggerRef ( ref2 ) {
triggerRefValue ( ref2 , ref2 . value );
}
function unref ( ref2 ) {
return isRef ( ref2 ) ? ref2 . value : ref2 ;
}
function toValue ( source ) {
return isFunction ( source ) ? source () : unref ( source );
2023-07-24 11:13:08 +08:00
}
const shallowUnwrapHandlers = {
2023-09-06 09:51:55 +08:00
get : ( target , key , receiver ) => unref ( Reflect . get ( target , key , receiver )),
set : ( target , key , value , receiver ) => {
const oldValue = target [ key ];
if ( isRef ( oldValue ) && ! isRef ( value )) {
oldValue . value = value ;
return true ;
} else {
return Reflect . set ( target , key , value , receiver );
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
}
2023-07-24 11:13:08 +08:00
};
function proxyRefs ( objectWithRefs ) {
2023-09-06 09:51:55 +08:00
return isReactive ( objectWithRefs ) ? objectWithRefs : new Proxy ( objectWithRefs , shallowUnwrapHandlers );
2023-07-24 11:13:08 +08:00
}
class CustomRefImpl {
2023-09-06 09:51:55 +08:00
constructor ( factory ) {
this . dep = void 0 ;
this . __v_isRef = true ;
const { get , set } = factory (
() => trackRefValue ( this ),
() => triggerRefValue ( this )
);
this . _get = get ;
this . _set = set ;
}
get value () {
return this . _get ();
}
set value ( newVal ) {
this . _set ( newVal );
}
2023-07-24 11:13:08 +08:00
}
function customRef ( factory ) {
2023-09-06 09:51:55 +08:00
return new CustomRefImpl ( factory );
2023-07-24 11:13:08 +08:00
}
function toRefs ( object ) {
2023-09-06 09:51:55 +08:00
if ( ! isProxy ( object )) {
console . warn ( `toRefs() expects a reactive object but received a plain one.` );
}
const ret = isArray ( object ) ? new Array ( object . length ) : {};
for ( const key in object ) {
ret [ key ] = propertyToRef ( object , key );
}
return ret ;
2023-07-24 11:13:08 +08:00
}
class ObjectRefImpl {
2023-09-06 09:51:55 +08:00
constructor ( _object , _key , _defaultValue ) {
this . _object = _object ;
this . _key = _key ;
this . _defaultValue = _defaultValue ;
this . __v_isRef = true ;
}
get value () {
const val = this . _object [ this . _key ];
return val === void 0 ? this . _defaultValue : val ;
}
set value ( newVal ) {
this . _object [ this . _key ] = newVal ;
}
get dep () {
return getDepFromReactive ( toRaw ( this . _object ), this . _key );
}
}
class GetterRefImpl {
constructor ( _getter ) {
this . _getter = _getter ;
this . __v_isRef = true ;
this . __v_isReadonly = true ;
}
get value () {
return this . _getter ();
}
}
function toRef ( source , key , defaultValue ) {
if ( isRef ( source )) {
return source ;
} else if ( isFunction ( source )) {
return new GetterRefImpl ( source );
} else if ( isObject ( source ) && arguments . length > 1 ) {
return propertyToRef ( source , key , defaultValue );
} else {
return ref ( source );
}
}
function propertyToRef ( source , key , defaultValue ) {
const val = source [ key ];
return isRef ( val ) ? val : new ObjectRefImpl (
source ,
key ,
defaultValue
);
2023-07-24 11:13:08 +08:00
}
class ComputedRefImpl {
2023-09-06 09:51:55 +08:00
constructor ( getter , _setter , isReadonly , isSSR ) {
this . _setter = _setter ;
this . dep = void 0 ;
this . __v_isRef = true ;
this [ "__v_isReadonly" ] = false ;
this . _dirty = true ;
this . effect = new ReactiveEffect ( getter , () => {
if ( ! this . _dirty ) {
2023-07-24 11:13:08 +08:00
this . _dirty = true ;
2023-09-06 09:51:55 +08:00
triggerRefValue ( this );
}
});
this . effect . computed = this ;
this . effect . active = this . _cacheable = ! isSSR ;
this [ "__v_isReadonly" ] = isReadonly ;
}
get value () {
const self = toRaw ( this );
trackRefValue ( self );
if ( self . _dirty || ! self . _cacheable ) {
self . _dirty = false ;
self . _value = self . effect . run ();
}
return self . _value ;
}
set value ( newValue ) {
this . _setter ( newValue );
}
2023-07-24 11:13:08 +08:00
}
function computed ( getterOrOptions , debugOptions , isSSR = false ) {
2023-09-06 09:51:55 +08:00
let getter ;
let setter ;
const onlyGetter = isFunction ( getterOrOptions );
if ( onlyGetter ) {
getter = getterOrOptions ;
setter = () => {
console . warn ( "Write operation failed: computed value is readonly" );
} ;
} else {
getter = getterOrOptions . get ;
setter = getterOrOptions . set ;
}
const cRef = new ComputedRefImpl ( getter , setter , onlyGetter || ! setter , isSSR );
if ( debugOptions && ! isSSR ) {
cRef . effect . onTrack = debugOptions . onTrack ;
cRef . effect . onTrigger = debugOptions . onTrigger ;
}
return cRef ;
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
const tick = /* @__PURE__ */ Promise . resolve ();
2023-07-24 11:13:08 +08:00
const queue = [];
let queued = false ;
const scheduler = ( fn ) => {
2023-09-06 09:51:55 +08:00
queue . push ( fn );
if ( ! queued ) {
queued = true ;
tick . then ( flush );
}
2023-07-24 11:13:08 +08:00
};
const flush = () => {
2023-09-06 09:51:55 +08:00
for ( let i = 0 ; i < queue . length ; i ++ ) {
queue [ i ]();
}
queue . length = 0 ;
queued = false ;
2023-07-24 11:13:08 +08:00
};
class DeferredComputedRefImpl {
2023-09-06 09:51:55 +08:00
constructor ( getter ) {
this . dep = void 0 ;
this . _dirty = true ;
this . __v_isRef = true ;
this [ "__v_isReadonly" ] = true ;
let compareTarget ;
let hasCompareTarget = false ;
let scheduled = false ;
this . effect = new ReactiveEffect ( getter , ( computedTrigger ) => {
if ( this . dep ) {
if ( computedTrigger ) {
compareTarget = this . _value ;
hasCompareTarget = true ;
} else if ( ! scheduled ) {
const valueToCompare = hasCompareTarget ? compareTarget : this . _value ;
scheduled = true ;
hasCompareTarget = false ;
scheduler (() => {
if ( this . effect . active && this . _get () !== valueToCompare ) {
triggerRefValue ( this );
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
scheduled = false ;
});
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
for ( const e of this . dep ) {
if ( e . computed instanceof DeferredComputedRefImpl ) {
e . scheduler (
true
/* computedTrigger */
);
}
}
}
this . _dirty = true ;
});
this . effect . computed = this ;
}
_get () {
if ( this . _dirty ) {
this . _dirty = false ;
return this . _value = this . effect . run ();
}
return this . _value ;
}
get value () {
trackRefValue ( this );
return toRaw ( this ). _get ();
}
2023-07-24 11:13:08 +08:00
}
function deferredComputed ( getter ) {
2023-09-06 09:51:55 +08:00
return new DeferredComputedRefImpl ( getter );
2023-07-24 11:13:08 +08:00
}
2023-09-06 09:51:55 +08:00
export { EffectScope , ITERATE_KEY , ReactiveEffect , computed , customRef , deferredComputed , effect , effectScope , enableTracking , getCurrentScope , isProxy , isReactive , isReadonly , isRef , isShallow , markRaw , onScopeDispose , pauseTracking , proxyRefs , reactive , readonly , ref , resetTracking , shallowReactive , shallowReadonly , shallowRef , stop , toRaw , toRef , toRefs , toValue , track , trigger , triggerRef , unref };