reactivity.global.js 54 KB

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