reactivity.cjs.prod.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. /**
  2. * @vue/reactivity v3.5.4
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. var shared = require('@vue/shared');
  9. let activeEffectScope;
  10. class EffectScope {
  11. constructor(detached = false) {
  12. this.detached = detached;
  13. /**
  14. * @internal
  15. */
  16. this._active = true;
  17. /**
  18. * @internal
  19. */
  20. this.effects = [];
  21. /**
  22. * @internal
  23. */
  24. this.cleanups = [];
  25. this._isPaused = false;
  26. this.parent = activeEffectScope;
  27. if (!detached && activeEffectScope) {
  28. this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
  29. this
  30. ) - 1;
  31. }
  32. }
  33. get active() {
  34. return this._active;
  35. }
  36. pause() {
  37. if (this._active) {
  38. this._isPaused = true;
  39. let i, l;
  40. if (this.scopes) {
  41. for (i = 0, l = this.scopes.length; i < l; i++) {
  42. this.scopes[i].pause();
  43. }
  44. }
  45. for (i = 0, l = this.effects.length; i < l; i++) {
  46. this.effects[i].pause();
  47. }
  48. }
  49. }
  50. /**
  51. * Resumes the effect scope, including all child scopes and effects.
  52. */
  53. resume() {
  54. if (this._active) {
  55. if (this._isPaused) {
  56. this._isPaused = false;
  57. let i, l;
  58. if (this.scopes) {
  59. for (i = 0, l = this.scopes.length; i < l; i++) {
  60. this.scopes[i].resume();
  61. }
  62. }
  63. for (i = 0, l = this.effects.length; i < l; i++) {
  64. this.effects[i].resume();
  65. }
  66. }
  67. }
  68. }
  69. run(fn) {
  70. if (this._active) {
  71. const currentEffectScope = activeEffectScope;
  72. try {
  73. activeEffectScope = this;
  74. return fn();
  75. } finally {
  76. activeEffectScope = currentEffectScope;
  77. }
  78. }
  79. }
  80. /**
  81. * This should only be called on non-detached scopes
  82. * @internal
  83. */
  84. on() {
  85. activeEffectScope = this;
  86. }
  87. /**
  88. * This should only be called on non-detached scopes
  89. * @internal
  90. */
  91. off() {
  92. activeEffectScope = this.parent;
  93. }
  94. stop(fromParent) {
  95. if (this._active) {
  96. let i, l;
  97. for (i = 0, l = this.effects.length; i < l; i++) {
  98. this.effects[i].stop();
  99. }
  100. for (i = 0, l = this.cleanups.length; i < l; i++) {
  101. this.cleanups[i]();
  102. }
  103. if (this.scopes) {
  104. for (i = 0, l = this.scopes.length; i < l; i++) {
  105. this.scopes[i].stop(true);
  106. }
  107. }
  108. if (!this.detached && this.parent && !fromParent) {
  109. const last = this.parent.scopes.pop();
  110. if (last && last !== this) {
  111. this.parent.scopes[this.index] = last;
  112. last.index = this.index;
  113. }
  114. }
  115. this.parent = void 0;
  116. this._active = false;
  117. }
  118. }
  119. }
  120. function effectScope(detached) {
  121. return new EffectScope(detached);
  122. }
  123. function getCurrentScope() {
  124. return activeEffectScope;
  125. }
  126. function onScopeDispose(fn, failSilently = false) {
  127. if (activeEffectScope) {
  128. activeEffectScope.cleanups.push(fn);
  129. }
  130. }
  131. let activeSub;
  132. const EffectFlags = {
  133. "ACTIVE": 1,
  134. "1": "ACTIVE",
  135. "RUNNING": 2,
  136. "2": "RUNNING",
  137. "TRACKING": 4,
  138. "4": "TRACKING",
  139. "NOTIFIED": 8,
  140. "8": "NOTIFIED",
  141. "DIRTY": 16,
  142. "16": "DIRTY",
  143. "ALLOW_RECURSE": 32,
  144. "32": "ALLOW_RECURSE",
  145. "PAUSED": 64,
  146. "64": "PAUSED"
  147. };
  148. const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
  149. class ReactiveEffect {
  150. constructor(fn) {
  151. this.fn = fn;
  152. /**
  153. * @internal
  154. */
  155. this.deps = void 0;
  156. /**
  157. * @internal
  158. */
  159. this.depsTail = void 0;
  160. /**
  161. * @internal
  162. */
  163. this.flags = 1 | 4;
  164. /**
  165. * @internal
  166. */
  167. this.nextEffect = void 0;
  168. /**
  169. * @internal
  170. */
  171. this.cleanup = void 0;
  172. this.scheduler = void 0;
  173. if (activeEffectScope && activeEffectScope.active) {
  174. activeEffectScope.effects.push(this);
  175. }
  176. }
  177. pause() {
  178. this.flags |= 64;
  179. }
  180. resume() {
  181. if (this.flags & 64) {
  182. this.flags &= ~64;
  183. if (pausedQueueEffects.has(this)) {
  184. pausedQueueEffects.delete(this);
  185. this.trigger();
  186. }
  187. }
  188. }
  189. /**
  190. * @internal
  191. */
  192. notify() {
  193. if (this.flags & 2 && !(this.flags & 32)) {
  194. return;
  195. }
  196. if (!(this.flags & 8)) {
  197. this.flags |= 8;
  198. this.nextEffect = batchedEffect;
  199. batchedEffect = this;
  200. }
  201. }
  202. run() {
  203. if (!(this.flags & 1)) {
  204. return this.fn();
  205. }
  206. this.flags |= 2;
  207. cleanupEffect(this);
  208. prepareDeps(this);
  209. const prevEffect = activeSub;
  210. const prevShouldTrack = shouldTrack;
  211. activeSub = this;
  212. shouldTrack = true;
  213. try {
  214. return this.fn();
  215. } finally {
  216. cleanupDeps(this);
  217. activeSub = prevEffect;
  218. shouldTrack = prevShouldTrack;
  219. this.flags &= ~2;
  220. }
  221. }
  222. stop() {
  223. if (this.flags & 1) {
  224. for (let link = this.deps; link; link = link.nextDep) {
  225. removeSub(link);
  226. }
  227. this.deps = this.depsTail = void 0;
  228. cleanupEffect(this);
  229. this.onStop && this.onStop();
  230. this.flags &= ~1;
  231. }
  232. }
  233. trigger() {
  234. if (this.flags & 64) {
  235. pausedQueueEffects.add(this);
  236. } else if (this.scheduler) {
  237. this.scheduler();
  238. } else {
  239. this.runIfDirty();
  240. }
  241. }
  242. /**
  243. * @internal
  244. */
  245. runIfDirty() {
  246. if (isDirty(this)) {
  247. this.run();
  248. }
  249. }
  250. get dirty() {
  251. return isDirty(this);
  252. }
  253. }
  254. let batchDepth = 0;
  255. let batchedEffect;
  256. function startBatch() {
  257. batchDepth++;
  258. }
  259. function endBatch() {
  260. if (--batchDepth > 0) {
  261. return;
  262. }
  263. let error;
  264. while (batchedEffect) {
  265. let e = batchedEffect;
  266. batchedEffect = void 0;
  267. while (e) {
  268. const next = e.nextEffect;
  269. e.nextEffect = void 0;
  270. e.flags &= ~8;
  271. if (e.flags & 1) {
  272. try {
  273. e.trigger();
  274. } catch (err) {
  275. if (!error) error = err;
  276. }
  277. }
  278. e = next;
  279. }
  280. }
  281. if (error) throw error;
  282. }
  283. function prepareDeps(sub) {
  284. for (let link = sub.deps; link; link = link.nextDep) {
  285. link.version = -1;
  286. link.prevActiveLink = link.dep.activeLink;
  287. link.dep.activeLink = link;
  288. }
  289. }
  290. function cleanupDeps(sub) {
  291. let head;
  292. let tail = sub.depsTail;
  293. for (let link = tail; link; link = link.prevDep) {
  294. if (link.version === -1) {
  295. if (link === tail) tail = link.prevDep;
  296. removeSub(link);
  297. removeDep(link);
  298. } else {
  299. head = link;
  300. }
  301. link.dep.activeLink = link.prevActiveLink;
  302. link.prevActiveLink = void 0;
  303. }
  304. sub.deps = head;
  305. sub.depsTail = tail;
  306. }
  307. function isDirty(sub) {
  308. for (let link = sub.deps; link; link = link.nextDep) {
  309. if (link.dep.version !== link.version || link.dep.computed && refreshComputed(link.dep.computed) || link.dep.version !== link.version) {
  310. return true;
  311. }
  312. }
  313. if (sub._dirty) {
  314. return true;
  315. }
  316. return false;
  317. }
  318. function refreshComputed(computed) {
  319. if (computed.flags & 4 && !(computed.flags & 16)) {
  320. return;
  321. }
  322. computed.flags &= ~16;
  323. if (computed.globalVersion === globalVersion) {
  324. return;
  325. }
  326. computed.globalVersion = globalVersion;
  327. const dep = computed.dep;
  328. computed.flags |= 2;
  329. if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
  330. computed.flags &= ~2;
  331. return;
  332. }
  333. const prevSub = activeSub;
  334. const prevShouldTrack = shouldTrack;
  335. activeSub = computed;
  336. shouldTrack = true;
  337. try {
  338. prepareDeps(computed);
  339. const value = computed.fn(computed._value);
  340. if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
  341. computed._value = value;
  342. dep.version++;
  343. }
  344. } catch (err) {
  345. dep.version++;
  346. throw err;
  347. } finally {
  348. activeSub = prevSub;
  349. shouldTrack = prevShouldTrack;
  350. cleanupDeps(computed);
  351. computed.flags &= ~2;
  352. }
  353. }
  354. function removeSub(link) {
  355. const { dep, prevSub, nextSub } = link;
  356. if (prevSub) {
  357. prevSub.nextSub = nextSub;
  358. link.prevSub = void 0;
  359. }
  360. if (nextSub) {
  361. nextSub.prevSub = prevSub;
  362. link.nextSub = void 0;
  363. }
  364. if (dep.subs === link) {
  365. dep.subs = prevSub;
  366. }
  367. if (!dep.subs && dep.computed) {
  368. dep.computed.flags &= ~4;
  369. for (let l = dep.computed.deps; l; l = l.nextDep) {
  370. removeSub(l);
  371. }
  372. }
  373. }
  374. function removeDep(link) {
  375. const { prevDep, nextDep } = link;
  376. if (prevDep) {
  377. prevDep.nextDep = nextDep;
  378. link.prevDep = void 0;
  379. }
  380. if (nextDep) {
  381. nextDep.prevDep = prevDep;
  382. link.nextDep = void 0;
  383. }
  384. }
  385. function effect(fn, options) {
  386. if (fn.effect instanceof ReactiveEffect) {
  387. fn = fn.effect.fn;
  388. }
  389. const e = new ReactiveEffect(fn);
  390. if (options) {
  391. shared.extend(e, options);
  392. }
  393. try {
  394. e.run();
  395. } catch (err) {
  396. e.stop();
  397. throw err;
  398. }
  399. const runner = e.run.bind(e);
  400. runner.effect = e;
  401. return runner;
  402. }
  403. function stop(runner) {
  404. runner.effect.stop();
  405. }
  406. let shouldTrack = true;
  407. const trackStack = [];
  408. function pauseTracking() {
  409. trackStack.push(shouldTrack);
  410. shouldTrack = false;
  411. }
  412. function enableTracking() {
  413. trackStack.push(shouldTrack);
  414. shouldTrack = true;
  415. }
  416. function resetTracking() {
  417. const last = trackStack.pop();
  418. shouldTrack = last === void 0 ? true : last;
  419. }
  420. function onEffectCleanup(fn, failSilently = false) {
  421. if (activeSub instanceof ReactiveEffect) {
  422. activeSub.cleanup = fn;
  423. }
  424. }
  425. function cleanupEffect(e) {
  426. const { cleanup } = e;
  427. e.cleanup = void 0;
  428. if (cleanup) {
  429. const prevSub = activeSub;
  430. activeSub = void 0;
  431. try {
  432. cleanup();
  433. } finally {
  434. activeSub = prevSub;
  435. }
  436. }
  437. }
  438. let globalVersion = 0;
  439. class Dep {
  440. constructor(computed) {
  441. this.computed = computed;
  442. this.version = 0;
  443. /**
  444. * Link between this dep and the current active effect
  445. */
  446. this.activeLink = void 0;
  447. /**
  448. * Doubly linked list representing the subscribing effects (tail)
  449. */
  450. this.subs = void 0;
  451. }
  452. track(debugInfo) {
  453. if (!activeSub || !shouldTrack || activeSub === this.computed) {
  454. return;
  455. }
  456. let link = this.activeLink;
  457. if (link === void 0 || link.sub !== activeSub) {
  458. link = this.activeLink = {
  459. dep: this,
  460. sub: activeSub,
  461. version: this.version,
  462. nextDep: void 0,
  463. prevDep: void 0,
  464. nextSub: void 0,
  465. prevSub: void 0,
  466. prevActiveLink: void 0
  467. };
  468. if (!activeSub.deps) {
  469. activeSub.deps = activeSub.depsTail = link;
  470. } else {
  471. link.prevDep = activeSub.depsTail;
  472. activeSub.depsTail.nextDep = link;
  473. activeSub.depsTail = link;
  474. }
  475. if (activeSub.flags & 4) {
  476. addSub(link);
  477. }
  478. } else if (link.version === -1) {
  479. link.version = this.version;
  480. if (link.nextDep) {
  481. const next = link.nextDep;
  482. next.prevDep = link.prevDep;
  483. if (link.prevDep) {
  484. link.prevDep.nextDep = next;
  485. }
  486. link.prevDep = activeSub.depsTail;
  487. link.nextDep = void 0;
  488. activeSub.depsTail.nextDep = link;
  489. activeSub.depsTail = link;
  490. if (activeSub.deps === link) {
  491. activeSub.deps = next;
  492. }
  493. }
  494. }
  495. return link;
  496. }
  497. trigger(debugInfo) {
  498. this.version++;
  499. globalVersion++;
  500. this.notify(debugInfo);
  501. }
  502. notify(debugInfo) {
  503. startBatch();
  504. try {
  505. if (false) ;
  506. for (let link = this.subs; link; link = link.prevSub) {
  507. link.sub.notify();
  508. }
  509. } finally {
  510. endBatch();
  511. }
  512. }
  513. }
  514. function addSub(link) {
  515. const computed = link.dep.computed;
  516. if (computed && !link.dep.subs) {
  517. computed.flags |= 4 | 16;
  518. for (let l = computed.deps; l; l = l.nextDep) {
  519. addSub(l);
  520. }
  521. }
  522. const currentTail = link.dep.subs;
  523. if (currentTail !== link) {
  524. link.prevSub = currentTail;
  525. if (currentTail) currentTail.nextSub = link;
  526. }
  527. link.dep.subs = link;
  528. }
  529. const targetMap = /* @__PURE__ */ new WeakMap();
  530. const ITERATE_KEY = Symbol(
  531. ""
  532. );
  533. const MAP_KEY_ITERATE_KEY = Symbol(
  534. ""
  535. );
  536. const ARRAY_ITERATE_KEY = Symbol(
  537. ""
  538. );
  539. function track(target, type, key) {
  540. if (shouldTrack && activeSub) {
  541. let depsMap = targetMap.get(target);
  542. if (!depsMap) {
  543. targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
  544. }
  545. let dep = depsMap.get(key);
  546. if (!dep) {
  547. depsMap.set(key, dep = new Dep());
  548. }
  549. {
  550. dep.track();
  551. }
  552. }
  553. }
  554. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  555. const depsMap = targetMap.get(target);
  556. if (!depsMap) {
  557. globalVersion++;
  558. return;
  559. }
  560. const run = (dep) => {
  561. if (dep) {
  562. {
  563. dep.trigger();
  564. }
  565. }
  566. };
  567. startBatch();
  568. if (type === "clear") {
  569. depsMap.forEach(run);
  570. } else {
  571. const targetIsArray = shared.isArray(target);
  572. const isArrayIndex = targetIsArray && shared.isIntegerKey(key);
  573. if (targetIsArray && key === "length") {
  574. const newLength = Number(newValue);
  575. depsMap.forEach((dep, key2) => {
  576. if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !shared.isSymbol(key2) && key2 >= newLength) {
  577. run(dep);
  578. }
  579. });
  580. } else {
  581. if (key !== void 0) {
  582. run(depsMap.get(key));
  583. }
  584. if (isArrayIndex) {
  585. run(depsMap.get(ARRAY_ITERATE_KEY));
  586. }
  587. switch (type) {
  588. case "add":
  589. if (!targetIsArray) {
  590. run(depsMap.get(ITERATE_KEY));
  591. if (shared.isMap(target)) {
  592. run(depsMap.get(MAP_KEY_ITERATE_KEY));
  593. }
  594. } else if (isArrayIndex) {
  595. run(depsMap.get("length"));
  596. }
  597. break;
  598. case "delete":
  599. if (!targetIsArray) {
  600. run(depsMap.get(ITERATE_KEY));
  601. if (shared.isMap(target)) {
  602. run(depsMap.get(MAP_KEY_ITERATE_KEY));
  603. }
  604. }
  605. break;
  606. case "set":
  607. if (shared.isMap(target)) {
  608. run(depsMap.get(ITERATE_KEY));
  609. }
  610. break;
  611. }
  612. }
  613. }
  614. endBatch();
  615. }
  616. function getDepFromReactive(object, key) {
  617. var _a;
  618. return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
  619. }
  620. function reactiveReadArray(array) {
  621. const raw = toRaw(array);
  622. if (raw === array) return raw;
  623. track(raw, "iterate", ARRAY_ITERATE_KEY);
  624. return isShallow(array) ? raw : raw.map(toReactive);
  625. }
  626. function shallowReadArray(arr) {
  627. track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
  628. return arr;
  629. }
  630. const arrayInstrumentations = {
  631. __proto__: null,
  632. [Symbol.iterator]() {
  633. return iterator(this, Symbol.iterator, toReactive);
  634. },
  635. concat(...args) {
  636. return reactiveReadArray(this).concat(
  637. ...args.map((x) => shared.isArray(x) ? reactiveReadArray(x) : x)
  638. );
  639. },
  640. entries() {
  641. return iterator(this, "entries", (value) => {
  642. value[1] = toReactive(value[1]);
  643. return value;
  644. });
  645. },
  646. every(fn, thisArg) {
  647. return apply(this, "every", fn, thisArg, void 0, arguments);
  648. },
  649. filter(fn, thisArg) {
  650. return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
  651. },
  652. find(fn, thisArg) {
  653. return apply(this, "find", fn, thisArg, toReactive, arguments);
  654. },
  655. findIndex(fn, thisArg) {
  656. return apply(this, "findIndex", fn, thisArg, void 0, arguments);
  657. },
  658. findLast(fn, thisArg) {
  659. return apply(this, "findLast", fn, thisArg, toReactive, arguments);
  660. },
  661. findLastIndex(fn, thisArg) {
  662. return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
  663. },
  664. // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
  665. forEach(fn, thisArg) {
  666. return apply(this, "forEach", fn, thisArg, void 0, arguments);
  667. },
  668. includes(...args) {
  669. return searchProxy(this, "includes", args);
  670. },
  671. indexOf(...args) {
  672. return searchProxy(this, "indexOf", args);
  673. },
  674. join(separator) {
  675. return reactiveReadArray(this).join(separator);
  676. },
  677. // keys() iterator only reads `length`, no optimisation required
  678. lastIndexOf(...args) {
  679. return searchProxy(this, "lastIndexOf", args);
  680. },
  681. map(fn, thisArg) {
  682. return apply(this, "map", fn, thisArg, void 0, arguments);
  683. },
  684. pop() {
  685. return noTracking(this, "pop");
  686. },
  687. push(...args) {
  688. return noTracking(this, "push", args);
  689. },
  690. reduce(fn, ...args) {
  691. return reduce(this, "reduce", fn, args);
  692. },
  693. reduceRight(fn, ...args) {
  694. return reduce(this, "reduceRight", fn, args);
  695. },
  696. shift() {
  697. return noTracking(this, "shift");
  698. },
  699. // slice could use ARRAY_ITERATE but also seems to beg for range tracking
  700. some(fn, thisArg) {
  701. return apply(this, "some", fn, thisArg, void 0, arguments);
  702. },
  703. splice(...args) {
  704. return noTracking(this, "splice", args);
  705. },
  706. toReversed() {
  707. return reactiveReadArray(this).toReversed();
  708. },
  709. toSorted(comparer) {
  710. return reactiveReadArray(this).toSorted(comparer);
  711. },
  712. toSpliced(...args) {
  713. return reactiveReadArray(this).toSpliced(...args);
  714. },
  715. unshift(...args) {
  716. return noTracking(this, "unshift", args);
  717. },
  718. values() {
  719. return iterator(this, "values", toReactive);
  720. }
  721. };
  722. function iterator(self, method, wrapValue) {
  723. const arr = shallowReadArray(self);
  724. const iter = arr[method]();
  725. if (arr !== self && !isShallow(self)) {
  726. iter._next = iter.next;
  727. iter.next = () => {
  728. const result = iter._next();
  729. if (result.value) {
  730. result.value = wrapValue(result.value);
  731. }
  732. return result;
  733. };
  734. }
  735. return iter;
  736. }
  737. const arrayProto = Array.prototype;
  738. function apply(self, method, fn, thisArg, wrappedRetFn, args) {
  739. const arr = shallowReadArray(self);
  740. const needsWrap = arr !== self && !isShallow(self);
  741. const methodFn = arr[method];
  742. if (methodFn !== arrayProto[method]) {
  743. const result2 = methodFn.apply(self, args);
  744. return needsWrap ? toReactive(result2) : result2;
  745. }
  746. let wrappedFn = fn;
  747. if (arr !== self) {
  748. if (needsWrap) {
  749. wrappedFn = function(item, index) {
  750. return fn.call(this, toReactive(item), index, self);
  751. };
  752. } else if (fn.length > 2) {
  753. wrappedFn = function(item, index) {
  754. return fn.call(this, item, index, self);
  755. };
  756. }
  757. }
  758. const result = methodFn.call(arr, wrappedFn, thisArg);
  759. return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
  760. }
  761. function reduce(self, method, fn, args) {
  762. const arr = shallowReadArray(self);
  763. let wrappedFn = fn;
  764. if (arr !== self) {
  765. if (!isShallow(self)) {
  766. wrappedFn = function(acc, item, index) {
  767. return fn.call(this, acc, toReactive(item), index, self);
  768. };
  769. } else if (fn.length > 3) {
  770. wrappedFn = function(acc, item, index) {
  771. return fn.call(this, acc, item, index, self);
  772. };
  773. }
  774. }
  775. return arr[method](wrappedFn, ...args);
  776. }
  777. function searchProxy(self, method, args) {
  778. const arr = toRaw(self);
  779. track(arr, "iterate", ARRAY_ITERATE_KEY);
  780. const res = arr[method](...args);
  781. if ((res === -1 || res === false) && isProxy(args[0])) {
  782. args[0] = toRaw(args[0]);
  783. return arr[method](...args);
  784. }
  785. return res;
  786. }
  787. function noTracking(self, method, args = []) {
  788. pauseTracking();
  789. startBatch();
  790. const res = toRaw(self)[method].apply(self, args);
  791. endBatch();
  792. resetTracking();
  793. return res;
  794. }
  795. const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,__isVue`);
  796. const builtInSymbols = new Set(
  797. /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
  798. );
  799. function hasOwnProperty(key) {
  800. if (!shared.isSymbol(key)) key = String(key);
  801. const obj = toRaw(this);
  802. track(obj, "has", key);
  803. return obj.hasOwnProperty(key);
  804. }
  805. class BaseReactiveHandler {
  806. constructor(_isReadonly = false, _isShallow = false) {
  807. this._isReadonly = _isReadonly;
  808. this._isShallow = _isShallow;
  809. }
  810. get(target, key, receiver) {
  811. const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
  812. if (key === "__v_isReactive") {
  813. return !isReadonly2;
  814. } else if (key === "__v_isReadonly") {
  815. return isReadonly2;
  816. } else if (key === "__v_isShallow") {
  817. return isShallow2;
  818. } else if (key === "__v_raw") {
  819. if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
  820. // this means the receiver is a user proxy of the reactive proxy
  821. Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
  822. return target;
  823. }
  824. return;
  825. }
  826. const targetIsArray = shared.isArray(target);
  827. if (!isReadonly2) {
  828. let fn;
  829. if (targetIsArray && (fn = arrayInstrumentations[key])) {
  830. return fn;
  831. }
  832. if (key === "hasOwnProperty") {
  833. return hasOwnProperty;
  834. }
  835. }
  836. const res = Reflect.get(
  837. target,
  838. key,
  839. // if this is a proxy wrapping a ref, return methods using the raw ref
  840. // as receiver so that we don't have to call `toRaw` on the ref in all
  841. // its class methods
  842. isRef(target) ? target : receiver
  843. );
  844. if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  845. return res;
  846. }
  847. if (!isReadonly2) {
  848. track(target, "get", key);
  849. }
  850. if (isShallow2) {
  851. return res;
  852. }
  853. if (isRef(res)) {
  854. return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
  855. }
  856. if (shared.isObject(res)) {
  857. return isReadonly2 ? readonly(res) : reactive(res);
  858. }
  859. return res;
  860. }
  861. }
  862. class MutableReactiveHandler extends BaseReactiveHandler {
  863. constructor(isShallow2 = false) {
  864. super(false, isShallow2);
  865. }
  866. set(target, key, value, receiver) {
  867. let oldValue = target[key];
  868. if (!this._isShallow) {
  869. const isOldValueReadonly = isReadonly(oldValue);
  870. if (!isShallow(value) && !isReadonly(value)) {
  871. oldValue = toRaw(oldValue);
  872. value = toRaw(value);
  873. }
  874. if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
  875. if (isOldValueReadonly) {
  876. return false;
  877. } else {
  878. oldValue.value = value;
  879. return true;
  880. }
  881. }
  882. }
  883. const hadKey = shared.isArray(target) && shared.isIntegerKey(key) ? Number(key) < target.length : shared.hasOwn(target, key);
  884. const result = Reflect.set(
  885. target,
  886. key,
  887. value,
  888. isRef(target) ? target : receiver
  889. );
  890. if (target === toRaw(receiver)) {
  891. if (!hadKey) {
  892. trigger(target, "add", key, value);
  893. } else if (shared.hasChanged(value, oldValue)) {
  894. trigger(target, "set", key, value);
  895. }
  896. }
  897. return result;
  898. }
  899. deleteProperty(target, key) {
  900. const hadKey = shared.hasOwn(target, key);
  901. target[key];
  902. const result = Reflect.deleteProperty(target, key);
  903. if (result && hadKey) {
  904. trigger(target, "delete", key, void 0);
  905. }
  906. return result;
  907. }
  908. has(target, key) {
  909. const result = Reflect.has(target, key);
  910. if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
  911. track(target, "has", key);
  912. }
  913. return result;
  914. }
  915. ownKeys(target) {
  916. track(
  917. target,
  918. "iterate",
  919. shared.isArray(target) ? "length" : ITERATE_KEY
  920. );
  921. return Reflect.ownKeys(target);
  922. }
  923. }
  924. class ReadonlyReactiveHandler extends BaseReactiveHandler {
  925. constructor(isShallow2 = false) {
  926. super(true, isShallow2);
  927. }
  928. set(target, key) {
  929. return true;
  930. }
  931. deleteProperty(target, key) {
  932. return true;
  933. }
  934. }
  935. const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
  936. const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
  937. const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
  938. const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
  939. const toShallow = (value) => value;
  940. const getProto = (v) => Reflect.getPrototypeOf(v);
  941. function get(target, key, isReadonly2 = false, isShallow2 = false) {
  942. target = target["__v_raw"];
  943. const rawTarget = toRaw(target);
  944. const rawKey = toRaw(key);
  945. if (!isReadonly2) {
  946. if (shared.hasChanged(key, rawKey)) {
  947. track(rawTarget, "get", key);
  948. }
  949. track(rawTarget, "get", rawKey);
  950. }
  951. const { has: has2 } = getProto(rawTarget);
  952. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  953. if (has2.call(rawTarget, key)) {
  954. return wrap(target.get(key));
  955. } else if (has2.call(rawTarget, rawKey)) {
  956. return wrap(target.get(rawKey));
  957. } else if (target !== rawTarget) {
  958. target.get(key);
  959. }
  960. }
  961. function has(key, isReadonly2 = false) {
  962. const target = this["__v_raw"];
  963. const rawTarget = toRaw(target);
  964. const rawKey = toRaw(key);
  965. if (!isReadonly2) {
  966. if (shared.hasChanged(key, rawKey)) {
  967. track(rawTarget, "has", key);
  968. }
  969. track(rawTarget, "has", rawKey);
  970. }
  971. return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
  972. }
  973. function size(target, isReadonly2 = false) {
  974. target = target["__v_raw"];
  975. !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
  976. return Reflect.get(target, "size", target);
  977. }
  978. function add(value, _isShallow = false) {
  979. if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
  980. value = toRaw(value);
  981. }
  982. const target = toRaw(this);
  983. const proto = getProto(target);
  984. const hadKey = proto.has.call(target, value);
  985. if (!hadKey) {
  986. target.add(value);
  987. trigger(target, "add", value, value);
  988. }
  989. return this;
  990. }
  991. function set(key, value, _isShallow = false) {
  992. if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
  993. value = toRaw(value);
  994. }
  995. const target = toRaw(this);
  996. const { has: has2, get: get2 } = getProto(target);
  997. let hadKey = has2.call(target, key);
  998. if (!hadKey) {
  999. key = toRaw(key);
  1000. hadKey = has2.call(target, key);
  1001. }
  1002. const oldValue = get2.call(target, key);
  1003. target.set(key, value);
  1004. if (!hadKey) {
  1005. trigger(target, "add", key, value);
  1006. } else if (shared.hasChanged(value, oldValue)) {
  1007. trigger(target, "set", key, value);
  1008. }
  1009. return this;
  1010. }
  1011. function deleteEntry(key) {
  1012. const target = toRaw(this);
  1013. const { has: has2, get: get2 } = getProto(target);
  1014. let hadKey = has2.call(target, key);
  1015. if (!hadKey) {
  1016. key = toRaw(key);
  1017. hadKey = has2.call(target, key);
  1018. }
  1019. get2 ? get2.call(target, key) : void 0;
  1020. const result = target.delete(key);
  1021. if (hadKey) {
  1022. trigger(target, "delete", key, void 0);
  1023. }
  1024. return result;
  1025. }
  1026. function clear() {
  1027. const target = toRaw(this);
  1028. const hadItems = target.size !== 0;
  1029. const result = target.clear();
  1030. if (hadItems) {
  1031. trigger(target, "clear", void 0, void 0);
  1032. }
  1033. return result;
  1034. }
  1035. function createForEach(isReadonly2, isShallow2) {
  1036. return function forEach(callback, thisArg) {
  1037. const observed = this;
  1038. const target = observed["__v_raw"];
  1039. const rawTarget = toRaw(target);
  1040. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  1041. !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
  1042. return target.forEach((value, key) => {
  1043. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1044. });
  1045. };
  1046. }
  1047. function createIterableMethod(method, isReadonly2, isShallow2) {
  1048. return function(...args) {
  1049. const target = this["__v_raw"];
  1050. const rawTarget = toRaw(target);
  1051. const targetIsMap = shared.isMap(rawTarget);
  1052. const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
  1053. const isKeyOnly = method === "keys" && targetIsMap;
  1054. const innerIterator = target[method](...args);
  1055. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  1056. !isReadonly2 && track(
  1057. rawTarget,
  1058. "iterate",
  1059. isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
  1060. );
  1061. return {
  1062. // iterator protocol
  1063. next() {
  1064. const { value, done } = innerIterator.next();
  1065. return done ? { value, done } : {
  1066. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1067. done
  1068. };
  1069. },
  1070. // iterable protocol
  1071. [Symbol.iterator]() {
  1072. return this;
  1073. }
  1074. };
  1075. };
  1076. }
  1077. function createReadonlyMethod(type) {
  1078. return function(...args) {
  1079. return type === "delete" ? false : type === "clear" ? void 0 : this;
  1080. };
  1081. }
  1082. function createInstrumentations() {
  1083. const mutableInstrumentations2 = {
  1084. get(key) {
  1085. return get(this, key);
  1086. },
  1087. get size() {
  1088. return size(this);
  1089. },
  1090. has,
  1091. add,
  1092. set,
  1093. delete: deleteEntry,
  1094. clear,
  1095. forEach: createForEach(false, false)
  1096. };
  1097. const shallowInstrumentations2 = {
  1098. get(key) {
  1099. return get(this, key, false, true);
  1100. },
  1101. get size() {
  1102. return size(this);
  1103. },
  1104. has,
  1105. add(value) {
  1106. return add.call(this, value, true);
  1107. },
  1108. set(key, value) {
  1109. return set.call(this, key, value, true);
  1110. },
  1111. delete: deleteEntry,
  1112. clear,
  1113. forEach: createForEach(false, true)
  1114. };
  1115. const readonlyInstrumentations2 = {
  1116. get(key) {
  1117. return get(this, key, true);
  1118. },
  1119. get size() {
  1120. return size(this, true);
  1121. },
  1122. has(key) {
  1123. return has.call(this, key, true);
  1124. },
  1125. add: createReadonlyMethod("add"),
  1126. set: createReadonlyMethod("set"),
  1127. delete: createReadonlyMethod("delete"),
  1128. clear: createReadonlyMethod("clear"),
  1129. forEach: createForEach(true, false)
  1130. };
  1131. const shallowReadonlyInstrumentations2 = {
  1132. get(key) {
  1133. return get(this, key, true, true);
  1134. },
  1135. get size() {
  1136. return size(this, true);
  1137. },
  1138. has(key) {
  1139. return has.call(this, key, true);
  1140. },
  1141. add: createReadonlyMethod("add"),
  1142. set: createReadonlyMethod("set"),
  1143. delete: createReadonlyMethod("delete"),
  1144. clear: createReadonlyMethod("clear"),
  1145. forEach: createForEach(true, true)
  1146. };
  1147. const iteratorMethods = [
  1148. "keys",
  1149. "values",
  1150. "entries",
  1151. Symbol.iterator
  1152. ];
  1153. iteratorMethods.forEach((method) => {
  1154. mutableInstrumentations2[method] = createIterableMethod(method, false, false);
  1155. readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
  1156. shallowInstrumentations2[method] = createIterableMethod(method, false, true);
  1157. shallowReadonlyInstrumentations2[method] = createIterableMethod(
  1158. method,
  1159. true,
  1160. true
  1161. );
  1162. });
  1163. return [
  1164. mutableInstrumentations2,
  1165. readonlyInstrumentations2,
  1166. shallowInstrumentations2,
  1167. shallowReadonlyInstrumentations2
  1168. ];
  1169. }
  1170. const [
  1171. mutableInstrumentations,
  1172. readonlyInstrumentations,
  1173. shallowInstrumentations,
  1174. shallowReadonlyInstrumentations
  1175. ] = /* @__PURE__ */ createInstrumentations();
  1176. function createInstrumentationGetter(isReadonly2, shallow) {
  1177. const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
  1178. return (target, key, receiver) => {
  1179. if (key === "__v_isReactive") {
  1180. return !isReadonly2;
  1181. } else if (key === "__v_isReadonly") {
  1182. return isReadonly2;
  1183. } else if (key === "__v_raw") {
  1184. return target;
  1185. }
  1186. return Reflect.get(
  1187. shared.hasOwn(instrumentations, key) && key in target ? instrumentations : target,
  1188. key,
  1189. receiver
  1190. );
  1191. };
  1192. }
  1193. const mutableCollectionHandlers = {
  1194. get: /* @__PURE__ */ createInstrumentationGetter(false, false)
  1195. };
  1196. const shallowCollectionHandlers = {
  1197. get: /* @__PURE__ */ createInstrumentationGetter(false, true)
  1198. };
  1199. const readonlyCollectionHandlers = {
  1200. get: /* @__PURE__ */ createInstrumentationGetter(true, false)
  1201. };
  1202. const shallowReadonlyCollectionHandlers = {
  1203. get: /* @__PURE__ */ createInstrumentationGetter(true, true)
  1204. };
  1205. const reactiveMap = /* @__PURE__ */ new WeakMap();
  1206. const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
  1207. const readonlyMap = /* @__PURE__ */ new WeakMap();
  1208. const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
  1209. function targetTypeMap(rawType) {
  1210. switch (rawType) {
  1211. case "Object":
  1212. case "Array":
  1213. return 1 /* COMMON */;
  1214. case "Map":
  1215. case "Set":
  1216. case "WeakMap":
  1217. case "WeakSet":
  1218. return 2 /* COLLECTION */;
  1219. default:
  1220. return 0 /* INVALID */;
  1221. }
  1222. }
  1223. function getTargetType(value) {
  1224. return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(shared.toRawType(value));
  1225. }
  1226. function reactive(target) {
  1227. if (isReadonly(target)) {
  1228. return target;
  1229. }
  1230. return createReactiveObject(
  1231. target,
  1232. false,
  1233. mutableHandlers,
  1234. mutableCollectionHandlers,
  1235. reactiveMap
  1236. );
  1237. }
  1238. function shallowReactive(target) {
  1239. return createReactiveObject(
  1240. target,
  1241. false,
  1242. shallowReactiveHandlers,
  1243. shallowCollectionHandlers,
  1244. shallowReactiveMap
  1245. );
  1246. }
  1247. function readonly(target) {
  1248. return createReactiveObject(
  1249. target,
  1250. true,
  1251. readonlyHandlers,
  1252. readonlyCollectionHandlers,
  1253. readonlyMap
  1254. );
  1255. }
  1256. function shallowReadonly(target) {
  1257. return createReactiveObject(
  1258. target,
  1259. true,
  1260. shallowReadonlyHandlers,
  1261. shallowReadonlyCollectionHandlers,
  1262. shallowReadonlyMap
  1263. );
  1264. }
  1265. function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
  1266. if (!shared.isObject(target)) {
  1267. return target;
  1268. }
  1269. if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
  1270. return target;
  1271. }
  1272. const existingProxy = proxyMap.get(target);
  1273. if (existingProxy) {
  1274. return existingProxy;
  1275. }
  1276. const targetType = getTargetType(target);
  1277. if (targetType === 0 /* INVALID */) {
  1278. return target;
  1279. }
  1280. const proxy = new Proxy(
  1281. target,
  1282. targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
  1283. );
  1284. proxyMap.set(target, proxy);
  1285. return proxy;
  1286. }
  1287. function isReactive(value) {
  1288. if (isReadonly(value)) {
  1289. return isReactive(value["__v_raw"]);
  1290. }
  1291. return !!(value && value["__v_isReactive"]);
  1292. }
  1293. function isReadonly(value) {
  1294. return !!(value && value["__v_isReadonly"]);
  1295. }
  1296. function isShallow(value) {
  1297. return !!(value && value["__v_isShallow"]);
  1298. }
  1299. function isProxy(value) {
  1300. return value ? !!value["__v_raw"] : false;
  1301. }
  1302. function toRaw(observed) {
  1303. const raw = observed && observed["__v_raw"];
  1304. return raw ? toRaw(raw) : observed;
  1305. }
  1306. function markRaw(value) {
  1307. if (!shared.hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
  1308. shared.def(value, "__v_skip", true);
  1309. }
  1310. return value;
  1311. }
  1312. const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
  1313. const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
  1314. function isRef(r) {
  1315. return r ? r["__v_isRef"] === true : false;
  1316. }
  1317. function ref(value) {
  1318. return createRef(value, false);
  1319. }
  1320. function shallowRef(value) {
  1321. return createRef(value, true);
  1322. }
  1323. function createRef(rawValue, shallow) {
  1324. if (isRef(rawValue)) {
  1325. return rawValue;
  1326. }
  1327. return new RefImpl(rawValue, shallow);
  1328. }
  1329. class RefImpl {
  1330. constructor(value, isShallow2) {
  1331. this.dep = new Dep();
  1332. this["__v_isRef"] = true;
  1333. this["__v_isShallow"] = false;
  1334. this._rawValue = isShallow2 ? value : toRaw(value);
  1335. this._value = isShallow2 ? value : toReactive(value);
  1336. this["__v_isShallow"] = isShallow2;
  1337. }
  1338. get value() {
  1339. {
  1340. this.dep.track();
  1341. }
  1342. return this._value;
  1343. }
  1344. set value(newValue) {
  1345. const oldValue = this._rawValue;
  1346. const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
  1347. newValue = useDirectValue ? newValue : toRaw(newValue);
  1348. if (shared.hasChanged(newValue, oldValue)) {
  1349. this._rawValue = newValue;
  1350. this._value = useDirectValue ? newValue : toReactive(newValue);
  1351. {
  1352. this.dep.trigger();
  1353. }
  1354. }
  1355. }
  1356. }
  1357. function triggerRef(ref2) {
  1358. {
  1359. ref2.dep.trigger();
  1360. }
  1361. }
  1362. function unref(ref2) {
  1363. return isRef(ref2) ? ref2.value : ref2;
  1364. }
  1365. function toValue(source) {
  1366. return shared.isFunction(source) ? source() : unref(source);
  1367. }
  1368. const shallowUnwrapHandlers = {
  1369. get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
  1370. set: (target, key, value, receiver) => {
  1371. const oldValue = target[key];
  1372. if (isRef(oldValue) && !isRef(value)) {
  1373. oldValue.value = value;
  1374. return true;
  1375. } else {
  1376. return Reflect.set(target, key, value, receiver);
  1377. }
  1378. }
  1379. };
  1380. function proxyRefs(objectWithRefs) {
  1381. return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1382. }
  1383. class CustomRefImpl {
  1384. constructor(factory) {
  1385. this["__v_isRef"] = true;
  1386. this._value = void 0;
  1387. const dep = this.dep = new Dep();
  1388. const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
  1389. this._get = get;
  1390. this._set = set;
  1391. }
  1392. get value() {
  1393. return this._value = this._get();
  1394. }
  1395. set value(newVal) {
  1396. this._set(newVal);
  1397. }
  1398. }
  1399. function customRef(factory) {
  1400. return new CustomRefImpl(factory);
  1401. }
  1402. function toRefs(object) {
  1403. const ret = shared.isArray(object) ? new Array(object.length) : {};
  1404. for (const key in object) {
  1405. ret[key] = propertyToRef(object, key);
  1406. }
  1407. return ret;
  1408. }
  1409. class ObjectRefImpl {
  1410. constructor(_object, _key, _defaultValue) {
  1411. this._object = _object;
  1412. this._key = _key;
  1413. this._defaultValue = _defaultValue;
  1414. this["__v_isRef"] = true;
  1415. this._value = void 0;
  1416. }
  1417. get value() {
  1418. const val = this._object[this._key];
  1419. return this._value = val === void 0 ? this._defaultValue : val;
  1420. }
  1421. set value(newVal) {
  1422. this._object[this._key] = newVal;
  1423. }
  1424. get dep() {
  1425. return getDepFromReactive(toRaw(this._object), this._key);
  1426. }
  1427. }
  1428. class GetterRefImpl {
  1429. constructor(_getter) {
  1430. this._getter = _getter;
  1431. this["__v_isRef"] = true;
  1432. this["__v_isReadonly"] = true;
  1433. this._value = void 0;
  1434. }
  1435. get value() {
  1436. return this._value = this._getter();
  1437. }
  1438. }
  1439. function toRef(source, key, defaultValue) {
  1440. if (isRef(source)) {
  1441. return source;
  1442. } else if (shared.isFunction(source)) {
  1443. return new GetterRefImpl(source);
  1444. } else if (shared.isObject(source) && arguments.length > 1) {
  1445. return propertyToRef(source, key, defaultValue);
  1446. } else {
  1447. return ref(source);
  1448. }
  1449. }
  1450. function propertyToRef(source, key, defaultValue) {
  1451. const val = source[key];
  1452. return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
  1453. }
  1454. class ComputedRefImpl {
  1455. constructor(fn, setter, isSSR) {
  1456. this.fn = fn;
  1457. this.setter = setter;
  1458. /**
  1459. * @internal
  1460. */
  1461. this._value = void 0;
  1462. /**
  1463. * @internal
  1464. */
  1465. this.dep = new Dep(this);
  1466. /**
  1467. * @internal
  1468. */
  1469. this.__v_isRef = true;
  1470. // TODO isolatedDeclarations "__v_isReadonly"
  1471. // A computed is also a subscriber that tracks other deps
  1472. /**
  1473. * @internal
  1474. */
  1475. this.deps = void 0;
  1476. /**
  1477. * @internal
  1478. */
  1479. this.depsTail = void 0;
  1480. /**
  1481. * @internal
  1482. */
  1483. this.flags = 16;
  1484. /**
  1485. * @internal
  1486. */
  1487. this.globalVersion = globalVersion - 1;
  1488. // for backwards compat
  1489. this.effect = this;
  1490. this["__v_isReadonly"] = !setter;
  1491. this.isSSR = isSSR;
  1492. }
  1493. /**
  1494. * @internal
  1495. */
  1496. notify() {
  1497. this.flags |= 16;
  1498. if (activeSub !== this) {
  1499. this.dep.notify();
  1500. }
  1501. }
  1502. get value() {
  1503. const link = this.dep.track();
  1504. refreshComputed(this);
  1505. if (link) {
  1506. link.version = this.dep.version;
  1507. }
  1508. return this._value;
  1509. }
  1510. set value(newValue) {
  1511. if (this.setter) {
  1512. this.setter(newValue);
  1513. }
  1514. }
  1515. }
  1516. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1517. let getter;
  1518. let setter;
  1519. if (shared.isFunction(getterOrOptions)) {
  1520. getter = getterOrOptions;
  1521. } else {
  1522. getter = getterOrOptions.get;
  1523. setter = getterOrOptions.set;
  1524. }
  1525. const cRef = new ComputedRefImpl(getter, setter, isSSR);
  1526. return cRef;
  1527. }
  1528. const TrackOpTypes = {
  1529. "GET": "get",
  1530. "HAS": "has",
  1531. "ITERATE": "iterate"
  1532. };
  1533. const TriggerOpTypes = {
  1534. "SET": "set",
  1535. "ADD": "add",
  1536. "DELETE": "delete",
  1537. "CLEAR": "clear"
  1538. };
  1539. const ReactiveFlags = {
  1540. "SKIP": "__v_skip",
  1541. "IS_REACTIVE": "__v_isReactive",
  1542. "IS_READONLY": "__v_isReadonly",
  1543. "IS_SHALLOW": "__v_isShallow",
  1544. "RAW": "__v_raw",
  1545. "IS_REF": "__v_isRef"
  1546. };
  1547. const WatchErrorCodes = {
  1548. "WATCH_GETTER": 2,
  1549. "2": "WATCH_GETTER",
  1550. "WATCH_CALLBACK": 3,
  1551. "3": "WATCH_CALLBACK",
  1552. "WATCH_CLEANUP": 4,
  1553. "4": "WATCH_CLEANUP"
  1554. };
  1555. const INITIAL_WATCHER_VALUE = {};
  1556. const cleanupMap = /* @__PURE__ */ new WeakMap();
  1557. let activeWatcher = void 0;
  1558. function getCurrentWatcher() {
  1559. return activeWatcher;
  1560. }
  1561. function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
  1562. if (owner) {
  1563. let cleanups = cleanupMap.get(owner);
  1564. if (!cleanups) cleanupMap.set(owner, cleanups = []);
  1565. cleanups.push(cleanupFn);
  1566. }
  1567. }
  1568. function watch(source, cb, options = shared.EMPTY_OBJ) {
  1569. const { immediate, deep, once, scheduler, augmentJob, call } = options;
  1570. const reactiveGetter = (source2) => {
  1571. if (deep) return source2;
  1572. if (isShallow(source2) || deep === false || deep === 0)
  1573. return traverse(source2, 1);
  1574. return traverse(source2);
  1575. };
  1576. let effect;
  1577. let getter;
  1578. let cleanup;
  1579. let boundCleanup;
  1580. let forceTrigger = false;
  1581. let isMultiSource = false;
  1582. if (isRef(source)) {
  1583. getter = () => source.value;
  1584. forceTrigger = isShallow(source);
  1585. } else if (isReactive(source)) {
  1586. getter = () => reactiveGetter(source);
  1587. forceTrigger = true;
  1588. } else if (shared.isArray(source)) {
  1589. isMultiSource = true;
  1590. forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
  1591. getter = () => source.map((s) => {
  1592. if (isRef(s)) {
  1593. return s.value;
  1594. } else if (isReactive(s)) {
  1595. return reactiveGetter(s);
  1596. } else if (shared.isFunction(s)) {
  1597. return call ? call(s, 2) : s();
  1598. } else ;
  1599. });
  1600. } else if (shared.isFunction(source)) {
  1601. if (cb) {
  1602. getter = call ? () => call(source, 2) : source;
  1603. } else {
  1604. getter = () => {
  1605. if (cleanup) {
  1606. pauseTracking();
  1607. try {
  1608. cleanup();
  1609. } finally {
  1610. resetTracking();
  1611. }
  1612. }
  1613. const currentEffect = activeWatcher;
  1614. activeWatcher = effect;
  1615. try {
  1616. return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
  1617. } finally {
  1618. activeWatcher = currentEffect;
  1619. }
  1620. };
  1621. }
  1622. } else {
  1623. getter = shared.NOOP;
  1624. }
  1625. if (cb && deep) {
  1626. const baseGetter = getter;
  1627. const depth = deep === true ? Infinity : deep;
  1628. getter = () => traverse(baseGetter(), depth);
  1629. }
  1630. const scope = getCurrentScope();
  1631. const watchHandle = () => {
  1632. effect.stop();
  1633. if (scope) {
  1634. shared.remove(scope.effects, effect);
  1635. }
  1636. };
  1637. if (once) {
  1638. if (cb) {
  1639. const _cb = cb;
  1640. cb = (...args) => {
  1641. _cb(...args);
  1642. watchHandle();
  1643. };
  1644. } else {
  1645. const _getter = getter;
  1646. getter = () => {
  1647. _getter();
  1648. watchHandle();
  1649. };
  1650. }
  1651. }
  1652. let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
  1653. const job = (immediateFirstRun) => {
  1654. if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
  1655. return;
  1656. }
  1657. if (cb) {
  1658. const newValue = effect.run();
  1659. if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue))) {
  1660. if (cleanup) {
  1661. cleanup();
  1662. }
  1663. const currentWatcher = activeWatcher;
  1664. activeWatcher = effect;
  1665. try {
  1666. const args = [
  1667. newValue,
  1668. // pass undefined as the old value when it's changed for the first time
  1669. oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
  1670. boundCleanup
  1671. ];
  1672. call ? call(cb, 3, args) : (
  1673. // @ts-expect-error
  1674. cb(...args)
  1675. );
  1676. oldValue = newValue;
  1677. } finally {
  1678. activeWatcher = currentWatcher;
  1679. }
  1680. }
  1681. } else {
  1682. effect.run();
  1683. }
  1684. };
  1685. if (augmentJob) {
  1686. augmentJob(job);
  1687. }
  1688. effect = new ReactiveEffect(getter);
  1689. effect.scheduler = scheduler ? () => scheduler(job, false) : job;
  1690. boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
  1691. cleanup = effect.onStop = () => {
  1692. const cleanups = cleanupMap.get(effect);
  1693. if (cleanups) {
  1694. if (call) {
  1695. call(cleanups, 4);
  1696. } else {
  1697. for (const cleanup2 of cleanups) cleanup2();
  1698. }
  1699. cleanupMap.delete(effect);
  1700. }
  1701. };
  1702. if (cb) {
  1703. if (immediate) {
  1704. job(true);
  1705. } else {
  1706. oldValue = effect.run();
  1707. }
  1708. } else if (scheduler) {
  1709. scheduler(job.bind(null, true), true);
  1710. } else {
  1711. effect.run();
  1712. }
  1713. watchHandle.pause = effect.pause.bind(effect);
  1714. watchHandle.resume = effect.resume.bind(effect);
  1715. watchHandle.stop = watchHandle;
  1716. return watchHandle;
  1717. }
  1718. function traverse(value, depth = Infinity, seen) {
  1719. if (depth <= 0 || !shared.isObject(value) || value["__v_skip"]) {
  1720. return value;
  1721. }
  1722. seen = seen || /* @__PURE__ */ new Set();
  1723. if (seen.has(value)) {
  1724. return value;
  1725. }
  1726. seen.add(value);
  1727. depth--;
  1728. if (isRef(value)) {
  1729. traverse(value.value, depth, seen);
  1730. } else if (shared.isArray(value)) {
  1731. for (let i = 0; i < value.length; i++) {
  1732. traverse(value[i], depth, seen);
  1733. }
  1734. } else if (shared.isSet(value) || shared.isMap(value)) {
  1735. value.forEach((v) => {
  1736. traverse(v, depth, seen);
  1737. });
  1738. } else if (shared.isPlainObject(value)) {
  1739. for (const key in value) {
  1740. traverse(value[key], depth, seen);
  1741. }
  1742. for (const key of Object.getOwnPropertySymbols(value)) {
  1743. if (Object.prototype.propertyIsEnumerable.call(value, key)) {
  1744. traverse(value[key], depth, seen);
  1745. }
  1746. }
  1747. }
  1748. return value;
  1749. }
  1750. exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
  1751. exports.EffectFlags = EffectFlags;
  1752. exports.EffectScope = EffectScope;
  1753. exports.ITERATE_KEY = ITERATE_KEY;
  1754. exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
  1755. exports.ReactiveEffect = ReactiveEffect;
  1756. exports.ReactiveFlags = ReactiveFlags;
  1757. exports.TrackOpTypes = TrackOpTypes;
  1758. exports.TriggerOpTypes = TriggerOpTypes;
  1759. exports.WatchErrorCodes = WatchErrorCodes;
  1760. exports.computed = computed;
  1761. exports.customRef = customRef;
  1762. exports.effect = effect;
  1763. exports.effectScope = effectScope;
  1764. exports.enableTracking = enableTracking;
  1765. exports.getCurrentScope = getCurrentScope;
  1766. exports.getCurrentWatcher = getCurrentWatcher;
  1767. exports.isProxy = isProxy;
  1768. exports.isReactive = isReactive;
  1769. exports.isReadonly = isReadonly;
  1770. exports.isRef = isRef;
  1771. exports.isShallow = isShallow;
  1772. exports.markRaw = markRaw;
  1773. exports.onEffectCleanup = onEffectCleanup;
  1774. exports.onScopeDispose = onScopeDispose;
  1775. exports.onWatcherCleanup = onWatcherCleanup;
  1776. exports.pauseTracking = pauseTracking;
  1777. exports.proxyRefs = proxyRefs;
  1778. exports.reactive = reactive;
  1779. exports.reactiveReadArray = reactiveReadArray;
  1780. exports.readonly = readonly;
  1781. exports.ref = ref;
  1782. exports.resetTracking = resetTracking;
  1783. exports.shallowReactive = shallowReactive;
  1784. exports.shallowReadArray = shallowReadArray;
  1785. exports.shallowReadonly = shallowReadonly;
  1786. exports.shallowRef = shallowRef;
  1787. exports.stop = stop;
  1788. exports.toRaw = toRaw;
  1789. exports.toReactive = toReactive;
  1790. exports.toReadonly = toReadonly;
  1791. exports.toRef = toRef;
  1792. exports.toRefs = toRefs;
  1793. exports.toValue = toValue;
  1794. exports.track = track;
  1795. exports.traverse = traverse;
  1796. exports.trigger = trigger;
  1797. exports.triggerRef = triggerRef;
  1798. exports.unref = unref;
  1799. exports.watch = watch;