reactivity.cjs.prod.js 48 KB

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