reactivity.global.js 59 KB

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