reactivity.global.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113
  1. /**
  2. * @vue/reactivity v3.5.41
  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. return isShallow(array) ? raw : raw.map(toReactive);
  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. exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
  2046. exports.EffectFlags = EffectFlags;
  2047. exports.EffectScope = EffectScope;
  2048. exports.ITERATE_KEY = ITERATE_KEY;
  2049. exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
  2050. exports.ReactiveEffect = ReactiveEffect;
  2051. exports.ReactiveFlags = ReactiveFlags;
  2052. exports.TrackOpTypes = TrackOpTypes;
  2053. exports.TriggerOpTypes = TriggerOpTypes;
  2054. exports.WatchErrorCodes = WatchErrorCodes;
  2055. exports.computed = computed;
  2056. exports.customRef = customRef;
  2057. exports.effect = effect;
  2058. exports.effectScope = effectScope;
  2059. exports.enableTracking = enableTracking;
  2060. exports.getCurrentScope = getCurrentScope;
  2061. exports.getCurrentWatcher = getCurrentWatcher;
  2062. exports.isProxy = isProxy;
  2063. exports.isReactive = isReactive;
  2064. exports.isReadonly = isReadonly;
  2065. exports.isRef = isRef;
  2066. exports.isShallow = isShallow;
  2067. exports.markRaw = markRaw;
  2068. exports.onEffectCleanup = onEffectCleanup;
  2069. exports.onScopeDispose = onScopeDispose;
  2070. exports.onWatcherCleanup = onWatcherCleanup;
  2071. exports.pauseTracking = pauseTracking;
  2072. exports.proxyRefs = proxyRefs;
  2073. exports.reactive = reactive;
  2074. exports.reactiveReadArray = reactiveReadArray;
  2075. exports.readonly = readonly;
  2076. exports.ref = ref;
  2077. exports.resetTracking = resetTracking;
  2078. exports.shallowReactive = shallowReactive;
  2079. exports.shallowReadArray = shallowReadArray;
  2080. exports.shallowReadonly = shallowReadonly;
  2081. exports.shallowRef = shallowRef;
  2082. exports.stop = stop;
  2083. exports.toRaw = toRaw;
  2084. exports.toReactive = toReactive;
  2085. exports.toReadonly = toReadonly;
  2086. exports.toRef = toRef;
  2087. exports.toRefs = toRefs;
  2088. exports.toValue = toValue;
  2089. exports.track = track;
  2090. exports.traverse = traverse;
  2091. exports.trigger = trigger;
  2092. exports.triggerRef = triggerRef;
  2093. exports.unref = unref;
  2094. exports.watch = watch;
  2095. return exports;
  2096. })({});