reactivity.cjs.prod.js 49 KB

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