12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892 |
- /**
- * @vue/reactivity v3.5.12
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
- * @license MIT
- **/
- import { hasChanged, extend, isArray, isIntegerKey, isSymbol, isMap, hasOwn, isObject, makeMap, toRawType, capitalize, def, isFunction, EMPTY_OBJ, isSet, isPlainObject, NOOP, remove } from '@vue/shared';
- function warn(msg, ...args) {
- console.warn(`[Vue warn] ${msg}`, ...args);
- }
- let activeEffectScope;
- class EffectScope {
- constructor(detached = false) {
- this.detached = detached;
- /**
- * @internal
- */
- this._active = true;
- /**
- * @internal
- */
- this.effects = [];
- /**
- * @internal
- */
- this.cleanups = [];
- this._isPaused = false;
- this.parent = activeEffectScope;
- if (!detached && activeEffectScope) {
- this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
- this
- ) - 1;
- }
- }
- get active() {
- return this._active;
- }
- pause() {
- if (this._active) {
- this._isPaused = true;
- let i, l;
- if (this.scopes) {
- for (i = 0, l = this.scopes.length; i < l; i++) {
- this.scopes[i].pause();
- }
- }
- for (i = 0, l = this.effects.length; i < l; i++) {
- this.effects[i].pause();
- }
- }
- }
- /**
- * Resumes the effect scope, including all child scopes and effects.
- */
- resume() {
- if (this._active) {
- if (this._isPaused) {
- this._isPaused = false;
- let i, l;
- if (this.scopes) {
- for (i = 0, l = this.scopes.length; i < l; i++) {
- this.scopes[i].resume();
- }
- }
- for (i = 0, l = this.effects.length; i < l; i++) {
- this.effects[i].resume();
- }
- }
- }
- }
- run(fn) {
- if (this._active) {
- const currentEffectScope = activeEffectScope;
- try {
- activeEffectScope = this;
- return fn();
- } finally {
- activeEffectScope = currentEffectScope;
- }
- } else if (!!(process.env.NODE_ENV !== "production")) {
- 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;
- }
- }
- this.parent = void 0;
- this._active = false;
- }
- }
- }
- function effectScope(detached) {
- return new EffectScope(detached);
- }
- function getCurrentScope() {
- return activeEffectScope;
- }
- function onScopeDispose(fn, failSilently = false) {
- if (activeEffectScope) {
- activeEffectScope.cleanups.push(fn);
- } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
- warn(
- `onScopeDispose() is called when there is no active effect scope to be associated with.`
- );
- }
- }
- let activeSub;
- const EffectFlags = {
- "ACTIVE": 1,
- "1": "ACTIVE",
- "RUNNING": 2,
- "2": "RUNNING",
- "TRACKING": 4,
- "4": "TRACKING",
- "NOTIFIED": 8,
- "8": "NOTIFIED",
- "DIRTY": 16,
- "16": "DIRTY",
- "ALLOW_RECURSE": 32,
- "32": "ALLOW_RECURSE",
- "PAUSED": 64,
- "64": "PAUSED"
- };
- const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
- class ReactiveEffect {
- constructor(fn) {
- this.fn = fn;
- /**
- * @internal
- */
- this.deps = void 0;
- /**
- * @internal
- */
- this.depsTail = void 0;
- /**
- * @internal
- */
- this.flags = 1 | 4;
- /**
- * @internal
- */
- this.next = void 0;
- /**
- * @internal
- */
- this.cleanup = void 0;
- this.scheduler = void 0;
- if (activeEffectScope && activeEffectScope.active) {
- activeEffectScope.effects.push(this);
- }
- }
- pause() {
- this.flags |= 64;
- }
- resume() {
- if (this.flags & 64) {
- this.flags &= ~64;
- if (pausedQueueEffects.has(this)) {
- pausedQueueEffects.delete(this);
- this.trigger();
- }
- }
- }
- /**
- * @internal
- */
- notify() {
- if (this.flags & 2 && !(this.flags & 32)) {
- return;
- }
- if (!(this.flags & 8)) {
- batch(this);
- }
- }
- run() {
- if (!(this.flags & 1)) {
- return this.fn();
- }
- this.flags |= 2;
- cleanupEffect(this);
- prepareDeps(this);
- const prevEffect = activeSub;
- const prevShouldTrack = shouldTrack;
- activeSub = this;
- shouldTrack = true;
- try {
- return this.fn();
- } finally {
- if (!!(process.env.NODE_ENV !== "production") && activeSub !== this) {
- warn(
- "Active effect was not restored correctly - this is likely a Vue internal bug."
- );
- }
- cleanupDeps(this);
- activeSub = prevEffect;
- shouldTrack = prevShouldTrack;
- this.flags &= ~2;
- }
- }
- stop() {
- if (this.flags & 1) {
- for (let link = this.deps; link; link = link.nextDep) {
- removeSub(link);
- }
- this.deps = this.depsTail = void 0;
- cleanupEffect(this);
- this.onStop && this.onStop();
- this.flags &= ~1;
- }
- }
- trigger() {
- if (this.flags & 64) {
- pausedQueueEffects.add(this);
- } else if (this.scheduler) {
- this.scheduler();
- } else {
- this.runIfDirty();
- }
- }
- /**
- * @internal
- */
- runIfDirty() {
- if (isDirty(this)) {
- this.run();
- }
- }
- get dirty() {
- return isDirty(this);
- }
- }
- let batchDepth = 0;
- let batchedSub;
- let batchedComputed;
- function batch(sub, isComputed = false) {
- sub.flags |= 8;
- if (isComputed) {
- sub.next = batchedComputed;
- batchedComputed = sub;
- return;
- }
- sub.next = batchedSub;
- batchedSub = sub;
- }
- function startBatch() {
- batchDepth++;
- }
- function endBatch() {
- if (--batchDepth > 0) {
- return;
- }
- if (batchedComputed) {
- let e = batchedComputed;
- batchedComputed = void 0;
- while (e) {
- const next = e.next;
- e.next = void 0;
- e.flags &= ~8;
- e = next;
- }
- }
- let error;
- while (batchedSub) {
- let e = batchedSub;
- batchedSub = void 0;
- while (e) {
- const next = e.next;
- e.next = void 0;
- e.flags &= ~8;
- if (e.flags & 1) {
- try {
- ;
- e.trigger();
- } catch (err) {
- if (!error) error = err;
- }
- }
- e = next;
- }
- }
- if (error) throw error;
- }
- function prepareDeps(sub) {
- for (let link = sub.deps; link; link = link.nextDep) {
- link.version = -1;
- link.prevActiveLink = link.dep.activeLink;
- link.dep.activeLink = link;
- }
- }
- function cleanupDeps(sub) {
- let head;
- let tail = sub.depsTail;
- let link = tail;
- while (link) {
- const prev = link.prevDep;
- if (link.version === -1) {
- if (link === tail) tail = prev;
- removeSub(link);
- removeDep(link);
- } else {
- head = link;
- }
- link.dep.activeLink = link.prevActiveLink;
- link.prevActiveLink = void 0;
- link = prev;
- }
- sub.deps = head;
- sub.depsTail = tail;
- }
- function isDirty(sub) {
- for (let link = sub.deps; link; link = link.nextDep) {
- if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
- return true;
- }
- }
- if (sub._dirty) {
- return true;
- }
- return false;
- }
- function refreshComputed(computed) {
- if (computed.flags & 4 && !(computed.flags & 16)) {
- return;
- }
- computed.flags &= ~16;
- if (computed.globalVersion === globalVersion) {
- return;
- }
- computed.globalVersion = globalVersion;
- const dep = computed.dep;
- computed.flags |= 2;
- if (dep.version > 0 && !computed.isSSR && computed.deps && !isDirty(computed)) {
- computed.flags &= ~2;
- return;
- }
- const prevSub = activeSub;
- const prevShouldTrack = shouldTrack;
- activeSub = computed;
- shouldTrack = true;
- try {
- prepareDeps(computed);
- const value = computed.fn(computed._value);
- if (dep.version === 0 || hasChanged(value, computed._value)) {
- computed._value = value;
- dep.version++;
- }
- } catch (err) {
- dep.version++;
- throw err;
- } finally {
- activeSub = prevSub;
- shouldTrack = prevShouldTrack;
- cleanupDeps(computed);
- computed.flags &= ~2;
- }
- }
- function removeSub(link, soft = false) {
- const { dep, prevSub, nextSub } = link;
- if (prevSub) {
- prevSub.nextSub = nextSub;
- link.prevSub = void 0;
- }
- if (nextSub) {
- nextSub.prevSub = prevSub;
- link.nextSub = void 0;
- }
- if (!!(process.env.NODE_ENV !== "production") && dep.subsHead === link) {
- dep.subsHead = nextSub;
- }
- if (dep.subs === link) {
- dep.subs = prevSub;
- if (!prevSub && dep.computed) {
- dep.computed.flags &= ~4;
- for (let l = dep.computed.deps; l; l = l.nextDep) {
- removeSub(l, true);
- }
- }
- }
- if (!soft && !--dep.sc && dep.map) {
- dep.map.delete(dep.key);
- }
- }
- function removeDep(link) {
- const { prevDep, nextDep } = link;
- if (prevDep) {
- prevDep.nextDep = nextDep;
- link.prevDep = void 0;
- }
- if (nextDep) {
- nextDep.prevDep = prevDep;
- link.nextDep = void 0;
- }
- }
- function effect(fn, options) {
- if (fn.effect instanceof ReactiveEffect) {
- fn = fn.effect.fn;
- }
- const e = new ReactiveEffect(fn);
- if (options) {
- extend(e, options);
- }
- try {
- e.run();
- } catch (err) {
- e.stop();
- throw err;
- }
- const runner = e.run.bind(e);
- runner.effect = e;
- return runner;
- }
- function stop(runner) {
- runner.effect.stop();
- }
- let shouldTrack = true;
- const trackStack = [];
- function pauseTracking() {
- trackStack.push(shouldTrack);
- shouldTrack = false;
- }
- function enableTracking() {
- trackStack.push(shouldTrack);
- shouldTrack = true;
- }
- function resetTracking() {
- const last = trackStack.pop();
- shouldTrack = last === void 0 ? true : last;
- }
- function onEffectCleanup(fn, failSilently = false) {
- if (activeSub instanceof ReactiveEffect) {
- activeSub.cleanup = fn;
- } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
- warn(
- `onEffectCleanup() was called when there was no active effect to associate with.`
- );
- }
- }
- function cleanupEffect(e) {
- const { cleanup } = e;
- e.cleanup = void 0;
- if (cleanup) {
- const prevSub = activeSub;
- activeSub = void 0;
- try {
- cleanup();
- } finally {
- activeSub = prevSub;
- }
- }
- }
- let globalVersion = 0;
- class Link {
- constructor(sub, dep) {
- this.sub = sub;
- this.dep = dep;
- this.version = dep.version;
- this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
- }
- }
- class Dep {
- constructor(computed) {
- this.computed = computed;
- this.version = 0;
- /**
- * Link between this dep and the current active effect
- */
- this.activeLink = void 0;
- /**
- * Doubly linked list representing the subscribing effects (tail)
- */
- this.subs = void 0;
- /**
- * For object property deps cleanup
- */
- this.map = void 0;
- this.key = void 0;
- /**
- * Subscriber counter
- */
- this.sc = 0;
- if (!!(process.env.NODE_ENV !== "production")) {
- this.subsHead = void 0;
- }
- }
- track(debugInfo) {
- if (!activeSub || !shouldTrack || activeSub === this.computed) {
- return;
- }
- let link = this.activeLink;
- if (link === void 0 || link.sub !== activeSub) {
- link = this.activeLink = new Link(activeSub, this);
- if (!activeSub.deps) {
- activeSub.deps = activeSub.depsTail = link;
- } else {
- link.prevDep = activeSub.depsTail;
- activeSub.depsTail.nextDep = link;
- activeSub.depsTail = link;
- }
- addSub(link);
- } else if (link.version === -1) {
- link.version = this.version;
- if (link.nextDep) {
- const next = link.nextDep;
- next.prevDep = link.prevDep;
- if (link.prevDep) {
- link.prevDep.nextDep = next;
- }
- link.prevDep = activeSub.depsTail;
- link.nextDep = void 0;
- activeSub.depsTail.nextDep = link;
- activeSub.depsTail = link;
- if (activeSub.deps === link) {
- activeSub.deps = next;
- }
- }
- }
- if (!!(process.env.NODE_ENV !== "production") && activeSub.onTrack) {
- activeSub.onTrack(
- extend(
- {
- effect: activeSub
- },
- debugInfo
- )
- );
- }
- return link;
- }
- trigger(debugInfo) {
- this.version++;
- globalVersion++;
- this.notify(debugInfo);
- }
- notify(debugInfo) {
- startBatch();
- try {
- if (!!(process.env.NODE_ENV !== "production")) {
- for (let head = this.subsHead; head; head = head.nextSub) {
- if (head.sub.onTrigger && !(head.sub.flags & 8)) {
- head.sub.onTrigger(
- extend(
- {
- effect: head.sub
- },
- debugInfo
- )
- );
- }
- }
- }
- for (let link = this.subs; link; link = link.prevSub) {
- if (link.sub.notify()) {
- ;
- link.sub.dep.notify();
- }
- }
- } finally {
- endBatch();
- }
- }
- }
- function addSub(link) {
- link.dep.sc++;
- if (link.sub.flags & 4) {
- const computed = link.dep.computed;
- if (computed && !link.dep.subs) {
- computed.flags |= 4 | 16;
- for (let l = computed.deps; l; l = l.nextDep) {
- addSub(l);
- }
- }
- const currentTail = link.dep.subs;
- if (currentTail !== link) {
- link.prevSub = currentTail;
- if (currentTail) currentTail.nextSub = link;
- }
- if (!!(process.env.NODE_ENV !== "production") && link.dep.subsHead === void 0) {
- link.dep.subsHead = link;
- }
- link.dep.subs = link;
- }
- }
- const targetMap = /* @__PURE__ */ new WeakMap();
- const ITERATE_KEY = Symbol(
- !!(process.env.NODE_ENV !== "production") ? "Object iterate" : ""
- );
- const MAP_KEY_ITERATE_KEY = Symbol(
- !!(process.env.NODE_ENV !== "production") ? "Map keys iterate" : ""
- );
- const ARRAY_ITERATE_KEY = Symbol(
- !!(process.env.NODE_ENV !== "production") ? "Array iterate" : ""
- );
- function track(target, type, key) {
- if (shouldTrack && activeSub) {
- let depsMap = targetMap.get(target);
- if (!depsMap) {
- targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
- }
- let dep = depsMap.get(key);
- if (!dep) {
- depsMap.set(key, dep = new Dep());
- dep.map = depsMap;
- dep.key = key;
- }
- if (!!(process.env.NODE_ENV !== "production")) {
- dep.track({
- target,
- type,
- key
- });
- } else {
- dep.track();
- }
- }
- }
- function trigger(target, type, key, newValue, oldValue, oldTarget) {
- const depsMap = targetMap.get(target);
- if (!depsMap) {
- globalVersion++;
- return;
- }
- const run = (dep) => {
- if (dep) {
- if (!!(process.env.NODE_ENV !== "production")) {
- dep.trigger({
- target,
- type,
- key,
- newValue,
- oldValue,
- oldTarget
- });
- } else {
- dep.trigger();
- }
- }
- };
- startBatch();
- if (type === "clear") {
- depsMap.forEach(run);
- } else {
- const targetIsArray = isArray(target);
- const isArrayIndex = targetIsArray && isIntegerKey(key);
- if (targetIsArray && key === "length") {
- const newLength = Number(newValue);
- depsMap.forEach((dep, key2) => {
- if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
- run(dep);
- }
- });
- } else {
- if (key !== void 0 || depsMap.has(void 0)) {
- run(depsMap.get(key));
- }
- if (isArrayIndex) {
- run(depsMap.get(ARRAY_ITERATE_KEY));
- }
- switch (type) {
- case "add":
- if (!targetIsArray) {
- run(depsMap.get(ITERATE_KEY));
- if (isMap(target)) {
- run(depsMap.get(MAP_KEY_ITERATE_KEY));
- }
- } else if (isArrayIndex) {
- run(depsMap.get("length"));
- }
- break;
- case "delete":
- if (!targetIsArray) {
- run(depsMap.get(ITERATE_KEY));
- if (isMap(target)) {
- run(depsMap.get(MAP_KEY_ITERATE_KEY));
- }
- }
- break;
- case "set":
- if (isMap(target)) {
- run(depsMap.get(ITERATE_KEY));
- }
- break;
- }
- }
- }
- endBatch();
- }
- function getDepFromReactive(object, key) {
- const depMap = targetMap.get(object);
- return depMap && depMap.get(key);
- }
- function reactiveReadArray(array) {
- const raw = toRaw(array);
- if (raw === array) return raw;
- track(raw, "iterate", ARRAY_ITERATE_KEY);
- return isShallow(array) ? raw : raw.map(toReactive);
- }
- function shallowReadArray(arr) {
- track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
- return arr;
- }
- const arrayInstrumentations = {
- __proto__: null,
- [Symbol.iterator]() {
- return iterator(this, Symbol.iterator, toReactive);
- },
- concat(...args) {
- return reactiveReadArray(this).concat(
- ...args.map((x) => isArray(x) ? reactiveReadArray(x) : x)
- );
- },
- entries() {
- return iterator(this, "entries", (value) => {
- value[1] = toReactive(value[1]);
- return value;
- });
- },
- every(fn, thisArg) {
- return apply(this, "every", fn, thisArg, void 0, arguments);
- },
- filter(fn, thisArg) {
- return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
- },
- find(fn, thisArg) {
- return apply(this, "find", fn, thisArg, toReactive, arguments);
- },
- findIndex(fn, thisArg) {
- return apply(this, "findIndex", fn, thisArg, void 0, arguments);
- },
- findLast(fn, thisArg) {
- return apply(this, "findLast", fn, thisArg, toReactive, arguments);
- },
- findLastIndex(fn, thisArg) {
- return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
- },
- // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
- forEach(fn, thisArg) {
- return apply(this, "forEach", fn, thisArg, void 0, arguments);
- },
- includes(...args) {
- return searchProxy(this, "includes", args);
- },
- indexOf(...args) {
- return searchProxy(this, "indexOf", args);
- },
- join(separator) {
- return reactiveReadArray(this).join(separator);
- },
- // keys() iterator only reads `length`, no optimisation required
- lastIndexOf(...args) {
- return searchProxy(this, "lastIndexOf", args);
- },
- map(fn, thisArg) {
- return apply(this, "map", fn, thisArg, void 0, arguments);
- },
- pop() {
- return noTracking(this, "pop");
- },
- push(...args) {
- return noTracking(this, "push", args);
- },
- reduce(fn, ...args) {
- return reduce(this, "reduce", fn, args);
- },
- reduceRight(fn, ...args) {
- return reduce(this, "reduceRight", fn, args);
- },
- shift() {
- return noTracking(this, "shift");
- },
- // slice could use ARRAY_ITERATE but also seems to beg for range tracking
- some(fn, thisArg) {
- return apply(this, "some", fn, thisArg, void 0, arguments);
- },
- splice(...args) {
- return noTracking(this, "splice", args);
- },
- toReversed() {
- return reactiveReadArray(this).toReversed();
- },
- toSorted(comparer) {
- return reactiveReadArray(this).toSorted(comparer);
- },
- toSpliced(...args) {
- return reactiveReadArray(this).toSpliced(...args);
- },
- unshift(...args) {
- return noTracking(this, "unshift", args);
- },
- values() {
- return iterator(this, "values", toReactive);
- }
- };
- function iterator(self, method, wrapValue) {
- const arr = shallowReadArray(self);
- const iter = arr[method]();
- if (arr !== self && !isShallow(self)) {
- iter._next = iter.next;
- iter.next = () => {
- const result = iter._next();
- if (result.value) {
- result.value = wrapValue(result.value);
- }
- return result;
- };
- }
- return iter;
- }
- const arrayProto = Array.prototype;
- function apply(self, method, fn, thisArg, wrappedRetFn, args) {
- const arr = shallowReadArray(self);
- const needsWrap = arr !== self && !isShallow(self);
- const methodFn = arr[method];
- if (methodFn !== arrayProto[method]) {
- const result2 = methodFn.apply(self, args);
- return needsWrap ? toReactive(result2) : result2;
- }
- let wrappedFn = fn;
- if (arr !== self) {
- if (needsWrap) {
- wrappedFn = function(item, index) {
- return fn.call(this, toReactive(item), index, self);
- };
- } else if (fn.length > 2) {
- wrappedFn = function(item, index) {
- return fn.call(this, item, index, self);
- };
- }
- }
- const result = methodFn.call(arr, wrappedFn, thisArg);
- return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
- }
- function reduce(self, method, fn, args) {
- const arr = shallowReadArray(self);
- let wrappedFn = fn;
- if (arr !== self) {
- if (!isShallow(self)) {
- wrappedFn = function(acc, item, index) {
- return fn.call(this, acc, toReactive(item), index, self);
- };
- } else if (fn.length > 3) {
- wrappedFn = function(acc, item, index) {
- return fn.call(this, acc, item, index, self);
- };
- }
- }
- return arr[method](wrappedFn, ...args);
- }
- function searchProxy(self, method, args) {
- const arr = toRaw(self);
- track(arr, "iterate", ARRAY_ITERATE_KEY);
- const res = arr[method](...args);
- if ((res === -1 || res === false) && isProxy(args[0])) {
- args[0] = toRaw(args[0]);
- return arr[method](...args);
- }
- return res;
- }
- function noTracking(self, method, args = []) {
- pauseTracking();
- startBatch();
- const res = toRaw(self)[method].apply(self, args);
- endBatch();
- resetTracking();
- return res;
- }
- const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
- const builtInSymbols = new Set(
- /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
- );
- function hasOwnProperty(key) {
- if (!isSymbol(key)) key = String(key);
- const obj = toRaw(this);
- track(obj, "has", key);
- return obj.hasOwnProperty(key);
- }
- class BaseReactiveHandler {
- constructor(_isReadonly = false, _isShallow = false) {
- this._isReadonly = _isReadonly;
- this._isShallow = _isShallow;
- }
- get(target, key, receiver) {
- const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
- if (key === "__v_isReactive") {
- return !isReadonly2;
- } else if (key === "__v_isReadonly") {
- return isReadonly2;
- } else if (key === "__v_isShallow") {
- return isShallow2;
- } else if (key === "__v_raw") {
- if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
- // this means the receiver is a user proxy of the reactive proxy
- Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
- return target;
- }
- return;
- }
- const targetIsArray = isArray(target);
- if (!isReadonly2) {
- let fn;
- if (targetIsArray && (fn = arrayInstrumentations[key])) {
- return fn;
- }
- if (key === "hasOwnProperty") {
- return hasOwnProperty;
- }
- }
- const res = Reflect.get(
- target,
- key,
- // if this is a proxy wrapping a ref, return methods using the raw ref
- // as receiver so that we don't have to call `toRaw` on the ref in all
- // its class methods
- isRef(target) ? target : receiver
- );
- if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
- return res;
- }
- if (!isReadonly2) {
- track(target, "get", key);
- }
- if (isShallow2) {
- return res;
- }
- if (isRef(res)) {
- return targetIsArray && isIntegerKey(key) ? res : res.value;
- }
- if (isObject(res)) {
- return isReadonly2 ? readonly(res) : reactive(res);
- }
- return res;
- }
- }
- class MutableReactiveHandler extends BaseReactiveHandler {
- constructor(isShallow2 = false) {
- super(false, isShallow2);
- }
- set(target, key, value, receiver) {
- let oldValue = target[key];
- if (!this._isShallow) {
- const isOldValueReadonly = isReadonly(oldValue);
- if (!isShallow(value) && !isReadonly(value)) {
- oldValue = toRaw(oldValue);
- value = toRaw(value);
- }
- if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
- if (isOldValueReadonly) {
- return false;
- } else {
- oldValue.value = value;
- return true;
- }
- }
- }
- const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
- const result = Reflect.set(
- target,
- key,
- value,
- isRef(target) ? target : receiver
- );
- if (target === toRaw(receiver)) {
- if (!hadKey) {
- trigger(target, "add", key, value);
- } else if (hasChanged(value, oldValue)) {
- trigger(target, "set", key, value, oldValue);
- }
- }
- return result;
- }
- 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;
- }
- has(target, key) {
- const result = Reflect.has(target, key);
- if (!isSymbol(key) || !builtInSymbols.has(key)) {
- track(target, "has", key);
- }
- return result;
- }
- ownKeys(target) {
- track(
- target,
- "iterate",
- isArray(target) ? "length" : ITERATE_KEY
- );
- return Reflect.ownKeys(target);
- }
- }
- class ReadonlyReactiveHandler extends BaseReactiveHandler {
- constructor(isShallow2 = false) {
- super(true, isShallow2);
- }
- set(target, key) {
- if (!!(process.env.NODE_ENV !== "production")) {
- warn(
- `Set operation on key "${String(key)}" failed: target is readonly.`,
- target
- );
- }
- return true;
- }
- deleteProperty(target, key) {
- if (!!(process.env.NODE_ENV !== "production")) {
- warn(
- `Delete operation on key "${String(key)}" failed: target is readonly.`,
- target
- );
- }
- return true;
- }
- }
- const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
- const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
- const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
- const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
- const toShallow = (value) => value;
- const getProto = (v) => Reflect.getPrototypeOf(v);
- function createIterableMethod(method, isReadonly2, isShallow2) {
- 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 = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
- !isReadonly2 && 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
- };
- },
- // iterable protocol
- [Symbol.iterator]() {
- return this;
- }
- };
- };
- }
- function createReadonlyMethod(type) {
- return function(...args) {
- if (!!(process.env.NODE_ENV !== "production")) {
- const key = args[0] ? `on key "${args[0]}" ` : ``;
- warn(
- `${capitalize(type)} operation ${key}failed: target is readonly.`,
- toRaw(this)
- );
- }
- return type === "delete" ? false : type === "clear" ? void 0 : this;
- };
- }
- function createInstrumentations(readonly, shallow) {
- const instrumentations = {
- get(key) {
- const target = this["__v_raw"];
- const rawTarget = toRaw(target);
- const rawKey = toRaw(key);
- if (!readonly) {
- if (hasChanged(key, rawKey)) {
- track(rawTarget, "get", key);
- }
- track(rawTarget, "get", rawKey);
- }
- const { has } = getProto(rawTarget);
- const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
- if (has.call(rawTarget, key)) {
- return wrap(target.get(key));
- } else if (has.call(rawTarget, rawKey)) {
- return wrap(target.get(rawKey));
- } else if (target !== rawTarget) {
- target.get(key);
- }
- },
- get size() {
- const target = this["__v_raw"];
- !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
- return Reflect.get(target, "size", target);
- },
- has(key) {
- const target = this["__v_raw"];
- const rawTarget = toRaw(target);
- const rawKey = toRaw(key);
- if (!readonly) {
- if (hasChanged(key, rawKey)) {
- track(rawTarget, "has", key);
- }
- track(rawTarget, "has", rawKey);
- }
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
- },
- forEach(callback, thisArg) {
- const observed = this;
- const target = observed["__v_raw"];
- const rawTarget = toRaw(target);
- const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
- !readonly && track(rawTarget, "iterate", ITERATE_KEY);
- return target.forEach((value, key) => {
- return callback.call(thisArg, wrap(value), wrap(key), observed);
- });
- }
- };
- extend(
- instrumentations,
- readonly ? {
- add: createReadonlyMethod("add"),
- set: createReadonlyMethod("set"),
- delete: createReadonlyMethod("delete"),
- clear: createReadonlyMethod("clear")
- } : {
- add(value) {
- if (!shallow && !isShallow(value) && !isReadonly(value)) {
- 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;
- },
- set(key, value) {
- if (!shallow && !isShallow(value) && !isReadonly(value)) {
- value = toRaw(value);
- }
- const target = toRaw(this);
- const { has, get } = getProto(target);
- let hadKey = has.call(target, key);
- if (!hadKey) {
- key = toRaw(key);
- hadKey = has.call(target, key);
- } else if (!!(process.env.NODE_ENV !== "production")) {
- checkIdentityKeys(target, has, key);
- }
- const oldValue = get.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;
- },
- delete(key) {
- const target = toRaw(this);
- const { has, get } = getProto(target);
- let hadKey = has.call(target, key);
- if (!hadKey) {
- key = toRaw(key);
- hadKey = has.call(target, key);
- } else if (!!(process.env.NODE_ENV !== "production")) {
- checkIdentityKeys(target, has, key);
- }
- const oldValue = get ? get.call(target, key) : void 0;
- const result = target.delete(key);
- if (hadKey) {
- trigger(target, "delete", key, void 0, oldValue);
- }
- return result;
- },
- clear() {
- const target = toRaw(this);
- const hadItems = target.size !== 0;
- const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0;
- const result = target.clear();
- if (hadItems) {
- trigger(
- target,
- "clear",
- void 0,
- void 0,
- oldTarget
- );
- }
- return result;
- }
- }
- );
- const iteratorMethods = [
- "keys",
- "values",
- "entries",
- Symbol.iterator
- ];
- iteratorMethods.forEach((method) => {
- instrumentations[method] = createIterableMethod(method, readonly, shallow);
- });
- return instrumentations;
- }
- function createInstrumentationGetter(isReadonly2, shallow) {
- const instrumentations = createInstrumentations(isReadonly2, shallow);
- return (target, key, receiver) => {
- if (key === "__v_isReactive") {
- return !isReadonly2;
- } else if (key === "__v_isReadonly") {
- return isReadonly2;
- } else if (key === "__v_raw") {
- return target;
- }
- return Reflect.get(
- hasOwn(instrumentations, key) && key in target ? instrumentations : target,
- key,
- receiver
- );
- };
- }
- const mutableCollectionHandlers = {
- get: /* @__PURE__ */ createInstrumentationGetter(false, false)
- };
- const shallowCollectionHandlers = {
- get: /* @__PURE__ */ createInstrumentationGetter(false, true)
- };
- const readonlyCollectionHandlers = {
- get: /* @__PURE__ */ createInstrumentationGetter(true, false)
- };
- const shallowReadonlyCollectionHandlers = {
- get: /* @__PURE__ */ createInstrumentationGetter(true, true)
- };
- function checkIdentityKeys(target, has, key) {
- const rawKey = toRaw(key);
- if (rawKey !== key && has.call(target, rawKey)) {
- const type = toRawType(target);
- 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.`
- );
- }
- }
- const reactiveMap = /* @__PURE__ */ new WeakMap();
- const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
- const readonlyMap = /* @__PURE__ */ new WeakMap();
- const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
- function targetTypeMap(rawType) {
- switch (rawType) {
- case "Object":
- case "Array":
- return 1 /* COMMON */;
- case "Map":
- case "Set":
- case "WeakMap":
- case "WeakSet":
- return 2 /* COLLECTION */;
- default:
- return 0 /* INVALID */;
- }
- }
- function getTargetType(value) {
- return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(toRawType(value));
- }
- function reactive(target) {
- if (isReadonly(target)) {
- return target;
- }
- return createReactiveObject(
- target,
- false,
- mutableHandlers,
- mutableCollectionHandlers,
- reactiveMap
- );
- }
- function shallowReactive(target) {
- return createReactiveObject(
- target,
- false,
- shallowReactiveHandlers,
- shallowCollectionHandlers,
- shallowReactiveMap
- );
- }
- function readonly(target) {
- return createReactiveObject(
- target,
- true,
- readonlyHandlers,
- readonlyCollectionHandlers,
- readonlyMap
- );
- }
- function shallowReadonly(target) {
- return createReactiveObject(
- target,
- true,
- shallowReadonlyHandlers,
- shallowReadonlyCollectionHandlers,
- shallowReadonlyMap
- );
- }
- function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
- if (!isObject(target)) {
- if (!!(process.env.NODE_ENV !== "production")) {
- warn(
- `value cannot be made ${isReadonly2 ? "readonly" : "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;
- }
- function isReactive(value) {
- if (isReadonly(value)) {
- return isReactive(value["__v_raw"]);
- }
- return !!(value && value["__v_isReactive"]);
- }
- function isReadonly(value) {
- return !!(value && value["__v_isReadonly"]);
- }
- function isShallow(value) {
- return !!(value && value["__v_isShallow"]);
- }
- function isProxy(value) {
- return value ? !!value["__v_raw"] : false;
- }
- function toRaw(observed) {
- const raw = observed && observed["__v_raw"];
- return raw ? toRaw(raw) : observed;
- }
- function markRaw(value) {
- if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
- def(value, "__v_skip", true);
- }
- return value;
- }
- const toReactive = (value) => isObject(value) ? reactive(value) : value;
- const toReadonly = (value) => isObject(value) ? readonly(value) : value;
- function isRef(r) {
- return r ? r["__v_isRef"] === true : false;
- }
- function ref(value) {
- return createRef(value, false);
- }
- function shallowRef(value) {
- return createRef(value, true);
- }
- function createRef(rawValue, shallow) {
- if (isRef(rawValue)) {
- return rawValue;
- }
- return new RefImpl(rawValue, shallow);
- }
- class RefImpl {
- constructor(value, isShallow2) {
- this.dep = new Dep();
- this["__v_isRef"] = true;
- this["__v_isShallow"] = false;
- this._rawValue = isShallow2 ? value : toRaw(value);
- this._value = isShallow2 ? value : toReactive(value);
- this["__v_isShallow"] = isShallow2;
- }
- get value() {
- if (!!(process.env.NODE_ENV !== "production")) {
- this.dep.track({
- target: this,
- type: "get",
- key: "value"
- });
- } else {
- this.dep.track();
- }
- return this._value;
- }
- set value(newValue) {
- const oldValue = this._rawValue;
- const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
- newValue = useDirectValue ? newValue : toRaw(newValue);
- if (hasChanged(newValue, oldValue)) {
- this._rawValue = newValue;
- this._value = useDirectValue ? newValue : toReactive(newValue);
- if (!!(process.env.NODE_ENV !== "production")) {
- this.dep.trigger({
- target: this,
- type: "set",
- key: "value",
- newValue,
- oldValue
- });
- } else {
- this.dep.trigger();
- }
- }
- }
- }
- function triggerRef(ref2) {
- if (ref2.dep) {
- if (!!(process.env.NODE_ENV !== "production")) {
- ref2.dep.trigger({
- target: ref2,
- type: "set",
- key: "value",
- newValue: ref2._value
- });
- } else {
- ref2.dep.trigger();
- }
- }
- }
- function unref(ref2) {
- return isRef(ref2) ? ref2.value : ref2;
- }
- function toValue(source) {
- return isFunction(source) ? source() : unref(source);
- }
- const shallowUnwrapHandlers = {
- get: (target, key, receiver) => key === "__v_raw" ? target : 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);
- }
- }
- };
- function proxyRefs(objectWithRefs) {
- return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
- }
- class CustomRefImpl {
- constructor(factory) {
- this["__v_isRef"] = true;
- this._value = void 0;
- const dep = this.dep = new Dep();
- const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
- this._get = get;
- this._set = set;
- }
- get value() {
- return this._value = this._get();
- }
- set value(newVal) {
- this._set(newVal);
- }
- }
- function customRef(factory) {
- return new CustomRefImpl(factory);
- }
- function toRefs(object) {
- if (!!(process.env.NODE_ENV !== "production") && !isProxy(object)) {
- 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;
- }
- class ObjectRefImpl {
- constructor(_object, _key, _defaultValue) {
- this._object = _object;
- this._key = _key;
- this._defaultValue = _defaultValue;
- this["__v_isRef"] = true;
- this._value = void 0;
- }
- get value() {
- const val = this._object[this._key];
- return this._value = 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;
- this._value = void 0;
- }
- get value() {
- return this._value = 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);
- }
- class ComputedRefImpl {
- constructor(fn, setter, isSSR) {
- this.fn = fn;
- this.setter = setter;
- /**
- * @internal
- */
- this._value = void 0;
- /**
- * @internal
- */
- this.dep = new Dep(this);
- /**
- * @internal
- */
- this.__v_isRef = true;
- // TODO isolatedDeclarations "__v_isReadonly"
- // A computed is also a subscriber that tracks other deps
- /**
- * @internal
- */
- this.deps = void 0;
- /**
- * @internal
- */
- this.depsTail = void 0;
- /**
- * @internal
- */
- this.flags = 16;
- /**
- * @internal
- */
- this.globalVersion = globalVersion - 1;
- /**
- * @internal
- */
- this.next = void 0;
- // for backwards compat
- this.effect = this;
- this["__v_isReadonly"] = !setter;
- this.isSSR = isSSR;
- }
- /**
- * @internal
- */
- notify() {
- this.flags |= 16;
- if (!(this.flags & 8) && // avoid infinite self recursion
- activeSub !== this) {
- batch(this, true);
- return true;
- } else if (!!(process.env.NODE_ENV !== "production")) ;
- }
- get value() {
- const link = !!(process.env.NODE_ENV !== "production") ? this.dep.track({
- target: this,
- type: "get",
- key: "value"
- }) : this.dep.track();
- refreshComputed(this);
- if (link) {
- link.version = this.dep.version;
- }
- return this._value;
- }
- set value(newValue) {
- if (this.setter) {
- this.setter(newValue);
- } else if (!!(process.env.NODE_ENV !== "production")) {
- warn("Write operation failed: computed value is readonly");
- }
- }
- }
- function computed(getterOrOptions, debugOptions, isSSR = false) {
- let getter;
- let setter;
- if (isFunction(getterOrOptions)) {
- getter = getterOrOptions;
- } else {
- getter = getterOrOptions.get;
- setter = getterOrOptions.set;
- }
- const cRef = new ComputedRefImpl(getter, setter, isSSR);
- if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
- cRef.onTrack = debugOptions.onTrack;
- cRef.onTrigger = debugOptions.onTrigger;
- }
- return cRef;
- }
- const TrackOpTypes = {
- "GET": "get",
- "HAS": "has",
- "ITERATE": "iterate"
- };
- const TriggerOpTypes = {
- "SET": "set",
- "ADD": "add",
- "DELETE": "delete",
- "CLEAR": "clear"
- };
- const ReactiveFlags = {
- "SKIP": "__v_skip",
- "IS_REACTIVE": "__v_isReactive",
- "IS_READONLY": "__v_isReadonly",
- "IS_SHALLOW": "__v_isShallow",
- "RAW": "__v_raw",
- "IS_REF": "__v_isRef"
- };
- const WatchErrorCodes = {
- "WATCH_GETTER": 2,
- "2": "WATCH_GETTER",
- "WATCH_CALLBACK": 3,
- "3": "WATCH_CALLBACK",
- "WATCH_CLEANUP": 4,
- "4": "WATCH_CLEANUP"
- };
- const INITIAL_WATCHER_VALUE = {};
- const cleanupMap = /* @__PURE__ */ new WeakMap();
- let activeWatcher = void 0;
- function getCurrentWatcher() {
- return activeWatcher;
- }
- function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
- if (owner) {
- let cleanups = cleanupMap.get(owner);
- if (!cleanups) cleanupMap.set(owner, cleanups = []);
- cleanups.push(cleanupFn);
- } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
- warn(
- `onWatcherCleanup() was called when there was no active watcher to associate with.`
- );
- }
- }
- function watch(source, cb, options = EMPTY_OBJ) {
- const { immediate, deep, once, scheduler, augmentJob, call } = options;
- const warnInvalidSource = (s) => {
- (options.onWarn || warn)(
- `Invalid watch source: `,
- s,
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
- );
- };
- const reactiveGetter = (source2) => {
- if (deep) return source2;
- if (isShallow(source2) || deep === false || deep === 0)
- return traverse(source2, 1);
- return traverse(source2);
- };
- let effect;
- let getter;
- let cleanup;
- let boundCleanup;
- let forceTrigger = false;
- let isMultiSource = false;
- if (isRef(source)) {
- getter = () => source.value;
- forceTrigger = isShallow(source);
- } else if (isReactive(source)) {
- getter = () => reactiveGetter(source);
- forceTrigger = true;
- } else if (isArray(source)) {
- isMultiSource = true;
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
- getter = () => source.map((s) => {
- if (isRef(s)) {
- return s.value;
- } else if (isReactive(s)) {
- return reactiveGetter(s);
- } else if (isFunction(s)) {
- return call ? call(s, 2) : s();
- } else {
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s);
- }
- });
- } else if (isFunction(source)) {
- if (cb) {
- getter = call ? () => call(source, 2) : source;
- } else {
- getter = () => {
- if (cleanup) {
- pauseTracking();
- try {
- cleanup();
- } finally {
- resetTracking();
- }
- }
- const currentEffect = activeWatcher;
- activeWatcher = effect;
- try {
- return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
- } finally {
- activeWatcher = currentEffect;
- }
- };
- }
- } else {
- getter = NOOP;
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source);
- }
- if (cb && deep) {
- const baseGetter = getter;
- const depth = deep === true ? Infinity : deep;
- getter = () => traverse(baseGetter(), depth);
- }
- const scope = getCurrentScope();
- const watchHandle = () => {
- effect.stop();
- if (scope) {
- remove(scope.effects, effect);
- }
- };
- if (once && cb) {
- const _cb = cb;
- cb = (...args) => {
- _cb(...args);
- watchHandle();
- };
- }
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
- const job = (immediateFirstRun) => {
- if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
- return;
- }
- if (cb) {
- const newValue = effect.run();
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
- if (cleanup) {
- cleanup();
- }
- const currentWatcher = activeWatcher;
- activeWatcher = effect;
- try {
- const args = [
- newValue,
- // pass undefined as the old value when it's changed for the first time
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
- boundCleanup
- ];
- call ? call(cb, 3, args) : (
- // @ts-expect-error
- cb(...args)
- );
- oldValue = newValue;
- } finally {
- activeWatcher = currentWatcher;
- }
- }
- } else {
- effect.run();
- }
- };
- if (augmentJob) {
- augmentJob(job);
- }
- effect = new ReactiveEffect(getter);
- effect.scheduler = scheduler ? () => scheduler(job, false) : job;
- boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
- cleanup = effect.onStop = () => {
- const cleanups = cleanupMap.get(effect);
- if (cleanups) {
- if (call) {
- call(cleanups, 4);
- } else {
- for (const cleanup2 of cleanups) cleanup2();
- }
- cleanupMap.delete(effect);
- }
- };
- if (!!(process.env.NODE_ENV !== "production")) {
- effect.onTrack = options.onTrack;
- effect.onTrigger = options.onTrigger;
- }
- if (cb) {
- if (immediate) {
- job(true);
- } else {
- oldValue = effect.run();
- }
- } else if (scheduler) {
- scheduler(job.bind(null, true), true);
- } else {
- effect.run();
- }
- watchHandle.pause = effect.pause.bind(effect);
- watchHandle.resume = effect.resume.bind(effect);
- watchHandle.stop = watchHandle;
- return watchHandle;
- }
- function traverse(value, depth = Infinity, seen) {
- if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
- return value;
- }
- seen = seen || /* @__PURE__ */ new Set();
- if (seen.has(value)) {
- return value;
- }
- seen.add(value);
- depth--;
- if (isRef(value)) {
- traverse(value.value, depth, seen);
- } else if (isArray(value)) {
- for (let i = 0; i < value.length; i++) {
- traverse(value[i], depth, seen);
- }
- } else if (isSet(value) || isMap(value)) {
- value.forEach((v) => {
- traverse(v, depth, seen);
- });
- } else if (isPlainObject(value)) {
- for (const key in value) {
- traverse(value[key], depth, seen);
- }
- for (const key of Object.getOwnPropertySymbols(value)) {
- if (Object.prototype.propertyIsEnumerable.call(value, key)) {
- traverse(value[key], depth, seen);
- }
- }
- }
- return value;
- }
- export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, WatchErrorCodes, computed, customRef, effect, effectScope, enableTracking, getCurrentScope, getCurrentWatcher, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onEffectCleanup, onScopeDispose, onWatcherCleanup, pauseTracking, proxyRefs, reactive, reactiveReadArray, readonly, ref, resetTracking, shallowReactive, shallowReadArray, shallowReadonly, shallowRef, stop, toRaw, toReactive, toReadonly, toRef, toRefs, toValue, track, traverse, trigger, triggerRef, unref, watch };
|