reactivity.cjs.prod.js 49 KB

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