62c21ee98457a5cb385ced76c2c8eb2b87e360d7b9cea6aacf2065c6f6f7e9482b7fbf58c98cedb2f17858f757ea425eb1df2b80c7b43ebb9375871380810f 50 KB

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