reactivity.global.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. /**
  2. * @vue/reactivity v3.5.22
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. var VueReactivity = (function (exports) {
  7. 'use strict';
  8. // @__NO_SIDE_EFFECTS__
  9. function makeMap(str) {
  10. const map = /* @__PURE__ */ Object.create(null);
  11. for (const key of str.split(",")) map[key] = 1;
  12. return (val) => val in map;
  13. }
  14. const EMPTY_OBJ = Object.freeze({}) ;
  15. const NOOP = () => {
  16. };
  17. const extend = Object.assign;
  18. const remove = (arr, el) => {
  19. const i = arr.indexOf(el);
  20. if (i > -1) {
  21. arr.splice(i, 1);
  22. }
  23. };
  24. const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  25. const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
  26. const isArray = Array.isArray;
  27. const isMap = (val) => toTypeString(val) === "[object Map]";
  28. const isSet = (val) => toTypeString(val) === "[object Set]";
  29. const isFunction = (val) => typeof val === "function";
  30. const isString = (val) => typeof val === "string";
  31. const isSymbol = (val) => typeof val === "symbol";
  32. const isObject = (val) => val !== null && typeof val === "object";
  33. const objectToString = Object.prototype.toString;
  34. const toTypeString = (value) => objectToString.call(value);
  35. const toRawType = (value) => {
  36. return toTypeString(value).slice(8, -1);
  37. };
  38. const isPlainObject = (val) => toTypeString(val) === "[object Object]";
  39. const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
  40. const cacheStringFunction = (fn) => {
  41. const cache = /* @__PURE__ */ Object.create(null);
  42. return ((str) => {
  43. const hit = cache[str];
  44. return hit || (cache[str] = fn(str));
  45. });
  46. };
  47. const capitalize = cacheStringFunction((str) => {
  48. return str.charAt(0).toUpperCase() + str.slice(1);
  49. });
  50. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  51. const def = (obj, key, value, writable = false) => {
  52. Object.defineProperty(obj, key, {
  53. configurable: true,
  54. enumerable: false,
  55. writable,
  56. value
  57. });
  58. };
  59. function warn(msg, ...args) {
  60. console.warn(`[Vue warn] ${msg}`, ...args);
  61. }
  62. let activeEffectScope;
  63. class EffectScope {
  64. constructor(detached = false) {
  65. this.detached = detached;
  66. /**
  67. * @internal
  68. */
  69. this._active = true;
  70. /**
  71. * @internal track `on` calls, allow `on` call multiple times
  72. */
  73. this._on = 0;
  74. /**
  75. * @internal
  76. */
  77. this.effects = [];
  78. /**
  79. * @internal
  80. */
  81. this.cleanups = [];
  82. this._isPaused = false;
  83. this.parent = activeEffectScope;
  84. if (!detached && activeEffectScope) {
  85. this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
  86. this
  87. ) - 1;
  88. }
  89. }
  90. get active() {
  91. return this._active;
  92. }
  93. pause() {
  94. if (this._active) {
  95. this._isPaused = true;
  96. let i, l;
  97. if (this.scopes) {
  98. for (i = 0, l = this.scopes.length; i < l; i++) {
  99. this.scopes[i].pause();
  100. }
  101. }
  102. for (i = 0, l = this.effects.length; i < l; i++) {
  103. this.effects[i].pause();
  104. }
  105. }
  106. }
  107. /**
  108. * Resumes the effect scope, including all child scopes and effects.
  109. */
  110. resume() {
  111. if (this._active) {
  112. if (this._isPaused) {
  113. this._isPaused = false;
  114. let i, l;
  115. if (this.scopes) {
  116. for (i = 0, l = this.scopes.length; i < l; i++) {
  117. this.scopes[i].resume();
  118. }
  119. }
  120. for (i = 0, l = this.effects.length; i < l; i++) {
  121. this.effects[i].resume();
  122. }
  123. }
  124. }
  125. }
  126. run(fn) {
  127. if (this._active) {
  128. const currentEffectScope = activeEffectScope;
  129. try {
  130. activeEffectScope = this;
  131. return fn();
  132. } finally {
  133. activeEffectScope = currentEffectScope;
  134. }
  135. } else {
  136. warn(`cannot run an inactive effect scope.`);
  137. }
  138. }
  139. /**
  140. * This should only be called on non-detached scopes
  141. * @internal
  142. */
  143. on() {
  144. if (++this._on === 1) {
  145. this.prevScope = activeEffectScope;
  146. activeEffectScope = this;
  147. }
  148. }
  149. /**
  150. * This should only be called on non-detached scopes
  151. * @internal
  152. */
  153. off() {
  154. if (this._on > 0 && --this._on === 0) {
  155. activeEffectScope = this.prevScope;
  156. this.prevScope = void 0;
  157. }
  158. }
  159. stop(fromParent) {
  160. if (this._active) {
  161. this._active = false;
  162. let i, l;
  163. for (i = 0, l = this.effects.length; i < l; i++) {
  164. this.effects[i].stop();
  165. }
  166. this.effects.length = 0;
  167. for (i = 0, l = this.cleanups.length; i < l; i++) {
  168. this.cleanups[i]();
  169. }
  170. this.cleanups.length = 0;
  171. if (this.scopes) {
  172. for (i = 0, l = this.scopes.length; i < l; i++) {
  173. this.scopes[i].stop(true);
  174. }
  175. this.scopes.length = 0;
  176. }
  177. if (!this.detached && this.parent && !fromParent) {
  178. const last = this.parent.scopes.pop();
  179. if (last && last !== this) {
  180. this.parent.scopes[this.index] = last;
  181. last.index = this.index;
  182. }
  183. }
  184. this.parent = void 0;
  185. }
  186. }
  187. }
  188. function effectScope(detached) {
  189. return new EffectScope(detached);
  190. }
  191. function getCurrentScope() {
  192. return activeEffectScope;
  193. }
  194. function onScopeDispose(fn, failSilently = false) {
  195. if (activeEffectScope) {
  196. activeEffectScope.cleanups.push(fn);
  197. } else if (!failSilently) {
  198. warn(
  199. `onScopeDispose() is called when there is no active effect scope to be associated with.`
  200. );
  201. }
  202. }
  203. let activeSub;
  204. const EffectFlags = {
  205. "ACTIVE": 1,
  206. "1": "ACTIVE",
  207. "RUNNING": 2,
  208. "2": "RUNNING",
  209. "TRACKING": 4,
  210. "4": "TRACKING",
  211. "NOTIFIED": 8,
  212. "8": "NOTIFIED",
  213. "DIRTY": 16,
  214. "16": "DIRTY",
  215. "ALLOW_RECURSE": 32,
  216. "32": "ALLOW_RECURSE",
  217. "PAUSED": 64,
  218. "64": "PAUSED",
  219. "EVALUATED": 128,
  220. "128": "EVALUATED"
  221. };
  222. const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
  223. class ReactiveEffect {
  224. constructor(fn) {
  225. this.fn = fn;
  226. /**
  227. * @internal
  228. */
  229. this.deps = void 0;
  230. /**
  231. * @internal
  232. */
  233. this.depsTail = void 0;
  234. /**
  235. * @internal
  236. */
  237. this.flags = 1 | 4;
  238. /**
  239. * @internal
  240. */
  241. this.next = void 0;
  242. /**
  243. * @internal
  244. */
  245. this.cleanup = void 0;
  246. this.scheduler = void 0;
  247. if (activeEffectScope && activeEffectScope.active) {
  248. activeEffectScope.effects.push(this);
  249. }
  250. }
  251. pause() {
  252. this.flags |= 64;
  253. }
  254. resume() {
  255. if (this.flags & 64) {
  256. this.flags &= -65;
  257. if (pausedQueueEffects.has(this)) {
  258. pausedQueueEffects.delete(this);
  259. this.trigger();
  260. }
  261. }
  262. }
  263. /**
  264. * @internal
  265. */
  266. notify() {
  267. if (this.flags & 2 && !(this.flags & 32)) {
  268. return;
  269. }
  270. if (!(this.flags & 8)) {
  271. batch(this);
  272. }
  273. }
  274. run() {
  275. if (!(this.flags & 1)) {
  276. return this.fn();
  277. }
  278. this.flags |= 2;
  279. cleanupEffect(this);
  280. prepareDeps(this);
  281. const prevEffect = activeSub;
  282. const prevShouldTrack = shouldTrack;
  283. activeSub = this;
  284. shouldTrack = true;
  285. try {
  286. return this.fn();
  287. } finally {
  288. if (activeSub !== this) {
  289. warn(
  290. "Active effect was not restored correctly - this is likely a Vue internal bug."
  291. );
  292. }
  293. cleanupDeps(this);
  294. activeSub = prevEffect;
  295. shouldTrack = prevShouldTrack;
  296. this.flags &= -3;
  297. }
  298. }
  299. stop() {
  300. if (this.flags & 1) {
  301. for (let link = this.deps; link; link = link.nextDep) {
  302. removeSub(link);
  303. }
  304. this.deps = this.depsTail = void 0;
  305. cleanupEffect(this);
  306. this.onStop && this.onStop();
  307. this.flags &= -2;
  308. }
  309. }
  310. trigger() {
  311. if (this.flags & 64) {
  312. pausedQueueEffects.add(this);
  313. } else if (this.scheduler) {
  314. this.scheduler();
  315. } else {
  316. this.runIfDirty();
  317. }
  318. }
  319. /**
  320. * @internal
  321. */
  322. runIfDirty() {
  323. if (isDirty(this)) {
  324. this.run();
  325. }
  326. }
  327. get dirty() {
  328. return isDirty(this);
  329. }
  330. }
  331. let batchDepth = 0;
  332. let batchedSub;
  333. let batchedComputed;
  334. function batch(sub, isComputed = false) {
  335. sub.flags |= 8;
  336. if (isComputed) {
  337. sub.next = batchedComputed;
  338. batchedComputed = sub;
  339. return;
  340. }
  341. sub.next = batchedSub;
  342. batchedSub = sub;
  343. }
  344. function startBatch() {
  345. batchDepth++;
  346. }
  347. function endBatch() {
  348. if (--batchDepth > 0) {
  349. return;
  350. }
  351. if (batchedComputed) {
  352. let e = batchedComputed;
  353. batchedComputed = void 0;
  354. while (e) {
  355. const next = e.next;
  356. e.next = void 0;
  357. e.flags &= -9;
  358. e = next;
  359. }
  360. }
  361. let error;
  362. while (batchedSub) {
  363. let e = batchedSub;
  364. batchedSub = void 0;
  365. while (e) {
  366. const next = e.next;
  367. e.next = void 0;
  368. e.flags &= -9;
  369. if (e.flags & 1) {
  370. try {
  371. ;
  372. e.trigger();
  373. } catch (err) {
  374. if (!error) error = err;
  375. }
  376. }
  377. e = next;
  378. }
  379. }
  380. if (error) throw error;
  381. }
  382. function prepareDeps(sub) {
  383. for (let link = sub.deps; link; link = link.nextDep) {
  384. link.version = -1;
  385. link.prevActiveLink = link.dep.activeLink;
  386. link.dep.activeLink = link;
  387. }
  388. }
  389. function cleanupDeps(sub) {
  390. let head;
  391. let tail = sub.depsTail;
  392. let link = tail;
  393. while (link) {
  394. const prev = link.prevDep;
  395. if (link.version === -1) {
  396. if (link === tail) tail = prev;
  397. removeSub(link);
  398. removeDep(link);
  399. } else {
  400. head = link;
  401. }
  402. link.dep.activeLink = link.prevActiveLink;
  403. link.prevActiveLink = void 0;
  404. link = prev;
  405. }
  406. sub.deps = head;
  407. sub.depsTail = tail;
  408. }
  409. function isDirty(sub) {
  410. for (let link = sub.deps; link; link = link.nextDep) {
  411. if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
  412. return true;
  413. }
  414. }
  415. if (sub._dirty) {
  416. return true;
  417. }
  418. return false;
  419. }
  420. function refreshComputed(computed) {
  421. if (computed.flags & 4 && !(computed.flags & 16)) {
  422. return;
  423. }
  424. computed.flags &= -17;
  425. if (computed.globalVersion === globalVersion) {
  426. return;
  427. }
  428. computed.globalVersion = globalVersion;
  429. if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
  430. return;
  431. }
  432. computed.flags |= 2;
  433. const dep = computed.dep;
  434. const prevSub = activeSub;
  435. const prevShouldTrack = shouldTrack;
  436. activeSub = computed;
  437. shouldTrack = true;
  438. try {
  439. prepareDeps(computed);
  440. const value = computed.fn(computed._value);
  441. if (dep.version === 0 || hasChanged(value, computed._value)) {
  442. computed.flags |= 128;
  443. computed._value = value;
  444. dep.version++;
  445. }
  446. } catch (err) {
  447. dep.version++;
  448. throw err;
  449. } finally {
  450. activeSub = prevSub;
  451. shouldTrack = prevShouldTrack;
  452. cleanupDeps(computed);
  453. computed.flags &= -3;
  454. }
  455. }
  456. function removeSub(link, soft = false) {
  457. const { dep, prevSub, nextSub } = link;
  458. if (prevSub) {
  459. prevSub.nextSub = nextSub;
  460. link.prevSub = void 0;
  461. }
  462. if (nextSub) {
  463. nextSub.prevSub = prevSub;
  464. link.nextSub = void 0;
  465. }
  466. if (dep.subsHead === link) {
  467. dep.subsHead = nextSub;
  468. }
  469. if (dep.subs === link) {
  470. dep.subs = prevSub;
  471. if (!prevSub && dep.computed) {
  472. dep.computed.flags &= -5;
  473. for (let l = dep.computed.deps; l; l = l.nextDep) {
  474. removeSub(l, true);
  475. }
  476. }
  477. }
  478. if (!soft && !--dep.sc && dep.map) {
  479. dep.map.delete(dep.key);
  480. }
  481. }
  482. function removeDep(link) {
  483. const { prevDep, nextDep } = link;
  484. if (prevDep) {
  485. prevDep.nextDep = nextDep;
  486. link.prevDep = void 0;
  487. }
  488. if (nextDep) {
  489. nextDep.prevDep = prevDep;
  490. link.nextDep = void 0;
  491. }
  492. }
  493. function effect(fn, options) {
  494. if (fn.effect instanceof ReactiveEffect) {
  495. fn = fn.effect.fn;
  496. }
  497. const e = new ReactiveEffect(fn);
  498. if (options) {
  499. extend(e, options);
  500. }
  501. try {
  502. e.run();
  503. } catch (err) {
  504. e.stop();
  505. throw err;
  506. }
  507. const runner = e.run.bind(e);
  508. runner.effect = e;
  509. return runner;
  510. }
  511. function stop(runner) {
  512. runner.effect.stop();
  513. }
  514. let shouldTrack = true;
  515. const trackStack = [];
  516. function pauseTracking() {
  517. trackStack.push(shouldTrack);
  518. shouldTrack = false;
  519. }
  520. function enableTracking() {
  521. trackStack.push(shouldTrack);
  522. shouldTrack = true;
  523. }
  524. function resetTracking() {
  525. const last = trackStack.pop();
  526. shouldTrack = last === void 0 ? true : last;
  527. }
  528. function onEffectCleanup(fn, failSilently = false) {
  529. if (activeSub instanceof ReactiveEffect) {
  530. activeSub.cleanup = fn;
  531. } else if (!failSilently) {
  532. warn(
  533. `onEffectCleanup() was called when there was no active effect to associate with.`
  534. );
  535. }
  536. }
  537. function cleanupEffect(e) {
  538. const { cleanup } = e;
  539. e.cleanup = void 0;
  540. if (cleanup) {
  541. const prevSub = activeSub;
  542. activeSub = void 0;
  543. try {
  544. cleanup();
  545. } finally {
  546. activeSub = prevSub;
  547. }
  548. }
  549. }
  550. let globalVersion = 0;
  551. class Link {
  552. constructor(sub, dep) {
  553. this.sub = sub;
  554. this.dep = dep;
  555. this.version = dep.version;
  556. this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
  557. }
  558. }
  559. class Dep {
  560. // TODO isolatedDeclarations "__v_skip"
  561. constructor(computed) {
  562. this.computed = computed;
  563. this.version = 0;
  564. /**
  565. * Link between this dep and the current active effect
  566. */
  567. this.activeLink = void 0;
  568. /**
  569. * Doubly linked list representing the subscribing effects (tail)
  570. */
  571. this.subs = void 0;
  572. /**
  573. * For object property deps cleanup
  574. */
  575. this.map = void 0;
  576. this.key = void 0;
  577. /**
  578. * Subscriber counter
  579. */
  580. this.sc = 0;
  581. /**
  582. * @internal
  583. */
  584. this.__v_skip = true;
  585. {
  586. this.subsHead = void 0;
  587. }
  588. }
  589. track(debugInfo) {
  590. if (!activeSub || !shouldTrack || activeSub === this.computed) {
  591. return;
  592. }
  593. let link = this.activeLink;
  594. if (link === void 0 || link.sub !== activeSub) {
  595. link = this.activeLink = new Link(activeSub, this);
  596. if (!activeSub.deps) {
  597. activeSub.deps = activeSub.depsTail = link;
  598. } else {
  599. link.prevDep = activeSub.depsTail;
  600. activeSub.depsTail.nextDep = link;
  601. activeSub.depsTail = link;
  602. }
  603. addSub(link);
  604. } else if (link.version === -1) {
  605. link.version = this.version;
  606. if (link.nextDep) {
  607. const next = link.nextDep;
  608. next.prevDep = link.prevDep;
  609. if (link.prevDep) {
  610. link.prevDep.nextDep = next;
  611. }
  612. link.prevDep = activeSub.depsTail;
  613. link.nextDep = void 0;
  614. activeSub.depsTail.nextDep = link;
  615. activeSub.depsTail = link;
  616. if (activeSub.deps === link) {
  617. activeSub.deps = next;
  618. }
  619. }
  620. }
  621. if (activeSub.onTrack) {
  622. activeSub.onTrack(
  623. extend(
  624. {
  625. effect: activeSub
  626. },
  627. debugInfo
  628. )
  629. );
  630. }
  631. return link;
  632. }
  633. trigger(debugInfo) {
  634. this.version++;
  635. globalVersion++;
  636. this.notify(debugInfo);
  637. }
  638. notify(debugInfo) {
  639. startBatch();
  640. try {
  641. if (true) {
  642. for (let head = this.subsHead; head; head = head.nextSub) {
  643. if (head.sub.onTrigger && !(head.sub.flags & 8)) {
  644. head.sub.onTrigger(
  645. extend(
  646. {
  647. effect: head.sub
  648. },
  649. debugInfo
  650. )
  651. );
  652. }
  653. }
  654. }
  655. for (let link = this.subs; link; link = link.prevSub) {
  656. if (link.sub.notify()) {
  657. ;
  658. link.sub.dep.notify();
  659. }
  660. }
  661. } finally {
  662. endBatch();
  663. }
  664. }
  665. }
  666. function addSub(link) {
  667. link.dep.sc++;
  668. if (link.sub.flags & 4) {
  669. const computed = link.dep.computed;
  670. if (computed && !link.dep.subs) {
  671. computed.flags |= 4 | 16;
  672. for (let l = computed.deps; l; l = l.nextDep) {
  673. addSub(l);
  674. }
  675. }
  676. const currentTail = link.dep.subs;
  677. if (currentTail !== link) {
  678. link.prevSub = currentTail;
  679. if (currentTail) currentTail.nextSub = link;
  680. }
  681. if (link.dep.subsHead === void 0) {
  682. link.dep.subsHead = link;
  683. }
  684. link.dep.subs = link;
  685. }
  686. }
  687. const targetMap = /* @__PURE__ */ new WeakMap();
  688. const ITERATE_KEY = Symbol(
  689. "Object iterate"
  690. );
  691. const MAP_KEY_ITERATE_KEY = Symbol(
  692. "Map keys iterate"
  693. );
  694. const ARRAY_ITERATE_KEY = Symbol(
  695. "Array iterate"
  696. );
  697. function track(target, type, key) {
  698. if (shouldTrack && activeSub) {
  699. let depsMap = targetMap.get(target);
  700. if (!depsMap) {
  701. targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
  702. }
  703. let dep = depsMap.get(key);
  704. if (!dep) {
  705. depsMap.set(key, dep = new Dep());
  706. dep.map = depsMap;
  707. dep.key = key;
  708. }
  709. {
  710. dep.track({
  711. target,
  712. type,
  713. key
  714. });
  715. }
  716. }
  717. }
  718. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  719. const depsMap = targetMap.get(target);
  720. if (!depsMap) {
  721. globalVersion++;
  722. return;
  723. }
  724. const run = (dep) => {
  725. if (dep) {
  726. {
  727. dep.trigger({
  728. target,
  729. type,
  730. key,
  731. newValue,
  732. oldValue,
  733. oldTarget
  734. });
  735. }
  736. }
  737. };
  738. startBatch();
  739. if (type === "clear") {
  740. depsMap.forEach(run);
  741. } else {
  742. const targetIsArray = isArray(target);
  743. const isArrayIndex = targetIsArray && isIntegerKey(key);
  744. if (targetIsArray && key === "length") {
  745. const newLength = Number(newValue);
  746. depsMap.forEach((dep, key2) => {
  747. if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
  748. run(dep);
  749. }
  750. });
  751. } else {
  752. if (key !== void 0 || depsMap.has(void 0)) {
  753. run(depsMap.get(key));
  754. }
  755. if (isArrayIndex) {
  756. run(depsMap.get(ARRAY_ITERATE_KEY));
  757. }
  758. switch (type) {
  759. case "add":
  760. if (!targetIsArray) {
  761. run(depsMap.get(ITERATE_KEY));
  762. if (isMap(target)) {
  763. run(depsMap.get(MAP_KEY_ITERATE_KEY));
  764. }
  765. } else if (isArrayIndex) {
  766. run(depsMap.get("length"));
  767. }
  768. break;
  769. case "delete":
  770. if (!targetIsArray) {
  771. run(depsMap.get(ITERATE_KEY));
  772. if (isMap(target)) {
  773. run(depsMap.get(MAP_KEY_ITERATE_KEY));
  774. }
  775. }
  776. break;
  777. case "set":
  778. if (isMap(target)) {
  779. run(depsMap.get(ITERATE_KEY));
  780. }
  781. break;
  782. }
  783. }
  784. }
  785. endBatch();
  786. }
  787. function getDepFromReactive(object, key) {
  788. const depMap = targetMap.get(object);
  789. return depMap && depMap.get(key);
  790. }
  791. function reactiveReadArray(array) {
  792. const raw = toRaw(array);
  793. if (raw === array) return raw;
  794. track(raw, "iterate", ARRAY_ITERATE_KEY);
  795. return isShallow(array) ? raw : raw.map(toReactive);
  796. }
  797. function shallowReadArray(arr) {
  798. track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
  799. return arr;
  800. }
  801. const arrayInstrumentations = {
  802. __proto__: null,
  803. [Symbol.iterator]() {
  804. return iterator(this, Symbol.iterator, toReactive);
  805. },
  806. concat(...args) {
  807. return reactiveReadArray(this).concat(
  808. ...args.map((x) => isArray(x) ? reactiveReadArray(x) : x)
  809. );
  810. },
  811. entries() {
  812. return iterator(this, "entries", (value) => {
  813. value[1] = toReactive(value[1]);
  814. return value;
  815. });
  816. },
  817. every(fn, thisArg) {
  818. return apply(this, "every", fn, thisArg, void 0, arguments);
  819. },
  820. filter(fn, thisArg) {
  821. return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
  822. },
  823. find(fn, thisArg) {
  824. return apply(this, "find", fn, thisArg, toReactive, arguments);
  825. },
  826. findIndex(fn, thisArg) {
  827. return apply(this, "findIndex", fn, thisArg, void 0, arguments);
  828. },
  829. findLast(fn, thisArg) {
  830. return apply(this, "findLast", fn, thisArg, toReactive, arguments);
  831. },
  832. findLastIndex(fn, thisArg) {
  833. return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
  834. },
  835. // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
  836. forEach(fn, thisArg) {
  837. return apply(this, "forEach", fn, thisArg, void 0, arguments);
  838. },
  839. includes(...args) {
  840. return searchProxy(this, "includes", args);
  841. },
  842. indexOf(...args) {
  843. return searchProxy(this, "indexOf", args);
  844. },
  845. join(separator) {
  846. return reactiveReadArray(this).join(separator);
  847. },
  848. // keys() iterator only reads `length`, no optimization required
  849. lastIndexOf(...args) {
  850. return searchProxy(this, "lastIndexOf", args);
  851. },
  852. map(fn, thisArg) {
  853. return apply(this, "map", fn, thisArg, void 0, arguments);
  854. },
  855. pop() {
  856. return noTracking(this, "pop");
  857. },
  858. push(...args) {
  859. return noTracking(this, "push", args);
  860. },
  861. reduce(fn, ...args) {
  862. return reduce(this, "reduce", fn, args);
  863. },
  864. reduceRight(fn, ...args) {
  865. return reduce(this, "reduceRight", fn, args);
  866. },
  867. shift() {
  868. return noTracking(this, "shift");
  869. },
  870. // slice could use ARRAY_ITERATE but also seems to beg for range tracking
  871. some(fn, thisArg) {
  872. return apply(this, "some", fn, thisArg, void 0, arguments);
  873. },
  874. splice(...args) {
  875. return noTracking(this, "splice", args);
  876. },
  877. toReversed() {
  878. return reactiveReadArray(this).toReversed();
  879. },
  880. toSorted(comparer) {
  881. return reactiveReadArray(this).toSorted(comparer);
  882. },
  883. toSpliced(...args) {
  884. return reactiveReadArray(this).toSpliced(...args);
  885. },
  886. unshift(...args) {
  887. return noTracking(this, "unshift", args);
  888. },
  889. values() {
  890. return iterator(this, "values", toReactive);
  891. }
  892. };
  893. function iterator(self, method, wrapValue) {
  894. const arr = shallowReadArray(self);
  895. const iter = arr[method]();
  896. if (arr !== self && !isShallow(self)) {
  897. iter._next = iter.next;
  898. iter.next = () => {
  899. const result = iter._next();
  900. if (!result.done) {
  901. result.value = wrapValue(result.value);
  902. }
  903. return result;
  904. };
  905. }
  906. return iter;
  907. }
  908. const arrayProto = Array.prototype;
  909. function apply(self, method, fn, thisArg, wrappedRetFn, args) {
  910. const arr = shallowReadArray(self);
  911. const needsWrap = arr !== self && !isShallow(self);
  912. const methodFn = arr[method];
  913. if (methodFn !== arrayProto[method]) {
  914. const result2 = methodFn.apply(self, args);
  915. return needsWrap ? toReactive(result2) : result2;
  916. }
  917. let wrappedFn = fn;
  918. if (arr !== self) {
  919. if (needsWrap) {
  920. wrappedFn = function(item, index) {
  921. return fn.call(this, toReactive(item), index, self);
  922. };
  923. } else if (fn.length > 2) {
  924. wrappedFn = function(item, index) {
  925. return fn.call(this, item, index, self);
  926. };
  927. }
  928. }
  929. const result = methodFn.call(arr, wrappedFn, thisArg);
  930. return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
  931. }
  932. function reduce(self, method, fn, args) {
  933. const arr = shallowReadArray(self);
  934. let wrappedFn = fn;
  935. if (arr !== self) {
  936. if (!isShallow(self)) {
  937. wrappedFn = function(acc, item, index) {
  938. return fn.call(this, acc, toReactive(item), index, self);
  939. };
  940. } else if (fn.length > 3) {
  941. wrappedFn = function(acc, item, index) {
  942. return fn.call(this, acc, item, index, self);
  943. };
  944. }
  945. }
  946. return arr[method](wrappedFn, ...args);
  947. }
  948. function searchProxy(self, method, args) {
  949. const arr = toRaw(self);
  950. track(arr, "iterate", ARRAY_ITERATE_KEY);
  951. const res = arr[method](...args);
  952. if ((res === -1 || res === false) && isProxy(args[0])) {
  953. args[0] = toRaw(args[0]);
  954. return arr[method](...args);
  955. }
  956. return res;
  957. }
  958. function noTracking(self, method, args = []) {
  959. pauseTracking();
  960. startBatch();
  961. const res = toRaw(self)[method].apply(self, args);
  962. endBatch();
  963. resetTracking();
  964. return res;
  965. }
  966. const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
  967. const builtInSymbols = new Set(
  968. /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
  969. );
  970. function hasOwnProperty(key) {
  971. if (!isSymbol(key)) key = String(key);
  972. const obj = toRaw(this);
  973. track(obj, "has", key);
  974. return obj.hasOwnProperty(key);
  975. }
  976. class BaseReactiveHandler {
  977. constructor(_isReadonly = false, _isShallow = false) {
  978. this._isReadonly = _isReadonly;
  979. this._isShallow = _isShallow;
  980. }
  981. get(target, key, receiver) {
  982. if (key === "__v_skip") return target["__v_skip"];
  983. const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
  984. if (key === "__v_isReactive") {
  985. return !isReadonly2;
  986. } else if (key === "__v_isReadonly") {
  987. return isReadonly2;
  988. } else if (key === "__v_isShallow") {
  989. return isShallow2;
  990. } else if (key === "__v_raw") {
  991. if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
  992. // this means the receiver is a user proxy of the reactive proxy
  993. Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
  994. return target;
  995. }
  996. return;
  997. }
  998. const targetIsArray = isArray(target);
  999. if (!isReadonly2) {
  1000. let fn;
  1001. if (targetIsArray && (fn = arrayInstrumentations[key])) {
  1002. return fn;
  1003. }
  1004. if (key === "hasOwnProperty") {
  1005. return hasOwnProperty;
  1006. }
  1007. }
  1008. const res = Reflect.get(
  1009. target,
  1010. key,
  1011. // if this is a proxy wrapping a ref, return methods using the raw ref
  1012. // as receiver so that we don't have to call `toRaw` on the ref in all
  1013. // its class methods
  1014. isRef(target) ? target : receiver
  1015. );
  1016. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  1017. return res;
  1018. }
  1019. if (!isReadonly2) {
  1020. track(target, "get", key);
  1021. }
  1022. if (isShallow2) {
  1023. return res;
  1024. }
  1025. if (isRef(res)) {
  1026. const value = targetIsArray && isIntegerKey(key) ? res : res.value;
  1027. return isReadonly2 && isObject(value) ? readonly(value) : 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 target.size;
  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 Map();
  1922. if ((seen.get(value) || 0) >= depth) {
  1923. return value;
  1924. }
  1925. seen.set(value, depth);
  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. })({});