reactivity.cjs.prod.js 49 KB

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