reactivity.esm-browser.js 53 KB

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