reactivity.global.js 55 KB

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