reactivity.cjs.prod.js 49 KB

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