cea40137005ca23670388e1320918f8bf921e338455b0710c49a255d602bd4e70618e6a56f0ddc358a16a9d4be274aadb0773dd3eb4a998ed74e22b0ebcc65 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016
  1. /**
  2. * @vue/reactivity v3.5.21
  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.value) {
  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. return targetIsArray && isIntegerKey(key) ? res : res.value;
  1027. }
  1028. if (isObject(res)) {
  1029. return isReadonly2 ? readonly(res) : reactive(res);
  1030. }
  1031. return res;
  1032. }
  1033. }
  1034. class MutableReactiveHandler extends BaseReactiveHandler {
  1035. constructor(isShallow2 = false) {
  1036. super(false, isShallow2);
  1037. }
  1038. set(target, key, value, receiver) {
  1039. let oldValue = target[key];
  1040. if (!this._isShallow) {
  1041. const isOldValueReadonly = isReadonly(oldValue);
  1042. if (!isShallow(value) && !isReadonly(value)) {
  1043. oldValue = toRaw(oldValue);
  1044. value = toRaw(value);
  1045. }
  1046. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  1047. if (isOldValueReadonly) {
  1048. {
  1049. warn(
  1050. `Set operation on key "${String(key)}" failed: target is readonly.`,
  1051. target[key]
  1052. );
  1053. }
  1054. return true;
  1055. } else {
  1056. oldValue.value = value;
  1057. return true;
  1058. }
  1059. }
  1060. }
  1061. const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
  1062. const result = Reflect.set(
  1063. target,
  1064. key,
  1065. value,
  1066. isRef(target) ? target : receiver
  1067. );
  1068. if (target === toRaw(receiver)) {
  1069. if (!hadKey) {
  1070. trigger(target, "add", key, value);
  1071. } else if (hasChanged(value, oldValue)) {
  1072. trigger(target, "set", key, value, oldValue);
  1073. }
  1074. }
  1075. return result;
  1076. }
  1077. deleteProperty(target, key) {
  1078. const hadKey = hasOwn(target, key);
  1079. const oldValue = target[key];
  1080. const result = Reflect.deleteProperty(target, key);
  1081. if (result && hadKey) {
  1082. trigger(target, "delete", key, void 0, oldValue);
  1083. }
  1084. return result;
  1085. }
  1086. has(target, key) {
  1087. const result = Reflect.has(target, key);
  1088. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  1089. track(target, "has", key);
  1090. }
  1091. return result;
  1092. }
  1093. ownKeys(target) {
  1094. track(
  1095. target,
  1096. "iterate",
  1097. isArray(target) ? "length" : ITERATE_KEY
  1098. );
  1099. return Reflect.ownKeys(target);
  1100. }
  1101. }
  1102. class ReadonlyReactiveHandler extends BaseReactiveHandler {
  1103. constructor(isShallow2 = false) {
  1104. super(true, isShallow2);
  1105. }
  1106. set(target, key) {
  1107. {
  1108. warn(
  1109. `Set operation on key "${String(key)}" failed: target is readonly.`,
  1110. target
  1111. );
  1112. }
  1113. return true;
  1114. }
  1115. deleteProperty(target, key) {
  1116. {
  1117. warn(
  1118. `Delete operation on key "${String(key)}" failed: target is readonly.`,
  1119. target
  1120. );
  1121. }
  1122. return true;
  1123. }
  1124. }
  1125. const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
  1126. const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
  1127. const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
  1128. const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
  1129. const toShallow = (value) => value;
  1130. const getProto = (v) => Reflect.getPrototypeOf(v);
  1131. function createIterableMethod(method, isReadonly2, isShallow2) {
  1132. return function(...args) {
  1133. const target = this["__v_raw"];
  1134. const rawTarget = toRaw(target);
  1135. const targetIsMap = isMap(rawTarget);
  1136. const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
  1137. const isKeyOnly = method === "keys" && targetIsMap;
  1138. const innerIterator = target[method](...args);
  1139. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  1140. !isReadonly2 && track(
  1141. rawTarget,
  1142. "iterate",
  1143. isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
  1144. );
  1145. return {
  1146. // iterator protocol
  1147. next() {
  1148. const { value, done } = innerIterator.next();
  1149. return done ? { value, done } : {
  1150. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1151. done
  1152. };
  1153. },
  1154. // iterable protocol
  1155. [Symbol.iterator]() {
  1156. return this;
  1157. }
  1158. };
  1159. };
  1160. }
  1161. function createReadonlyMethod(type) {
  1162. return function(...args) {
  1163. {
  1164. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1165. warn(
  1166. `${capitalize(type)} operation ${key}failed: target is readonly.`,
  1167. toRaw(this)
  1168. );
  1169. }
  1170. return type === "delete" ? false : type === "clear" ? void 0 : this;
  1171. };
  1172. }
  1173. function createInstrumentations(readonly, shallow) {
  1174. const instrumentations = {
  1175. get(key) {
  1176. const target = this["__v_raw"];
  1177. const rawTarget = toRaw(target);
  1178. const rawKey = toRaw(key);
  1179. if (!readonly) {
  1180. if (hasChanged(key, rawKey)) {
  1181. track(rawTarget, "get", key);
  1182. }
  1183. track(rawTarget, "get", rawKey);
  1184. }
  1185. const { has } = getProto(rawTarget);
  1186. const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
  1187. if (has.call(rawTarget, key)) {
  1188. return wrap(target.get(key));
  1189. } else if (has.call(rawTarget, rawKey)) {
  1190. return wrap(target.get(rawKey));
  1191. } else if (target !== rawTarget) {
  1192. target.get(key);
  1193. }
  1194. },
  1195. get size() {
  1196. const target = this["__v_raw"];
  1197. !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
  1198. return target.size;
  1199. },
  1200. has(key) {
  1201. const target = this["__v_raw"];
  1202. const rawTarget = toRaw(target);
  1203. const rawKey = toRaw(key);
  1204. if (!readonly) {
  1205. if (hasChanged(key, rawKey)) {
  1206. track(rawTarget, "has", key);
  1207. }
  1208. track(rawTarget, "has", rawKey);
  1209. }
  1210. return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
  1211. },
  1212. forEach(callback, thisArg) {
  1213. const observed = this;
  1214. const target = observed["__v_raw"];
  1215. const rawTarget = toRaw(target);
  1216. const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
  1217. !readonly && track(rawTarget, "iterate", ITERATE_KEY);
  1218. return target.forEach((value, key) => {
  1219. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1220. });
  1221. }
  1222. };
  1223. extend(
  1224. instrumentations,
  1225. readonly ? {
  1226. add: createReadonlyMethod("add"),
  1227. set: createReadonlyMethod("set"),
  1228. delete: createReadonlyMethod("delete"),
  1229. clear: createReadonlyMethod("clear")
  1230. } : {
  1231. add(value) {
  1232. if (!shallow && !isShallow(value) && !isReadonly(value)) {
  1233. value = toRaw(value);
  1234. }
  1235. const target = toRaw(this);
  1236. const proto = getProto(target);
  1237. const hadKey = proto.has.call(target, value);
  1238. if (!hadKey) {
  1239. target.add(value);
  1240. trigger(target, "add", value, value);
  1241. }
  1242. return this;
  1243. },
  1244. set(key, value) {
  1245. if (!shallow && !isShallow(value) && !isReadonly(value)) {
  1246. value = toRaw(value);
  1247. }
  1248. const target = toRaw(this);
  1249. const { has, get } = getProto(target);
  1250. let hadKey = has.call(target, key);
  1251. if (!hadKey) {
  1252. key = toRaw(key);
  1253. hadKey = has.call(target, key);
  1254. } else {
  1255. checkIdentityKeys(target, has, key);
  1256. }
  1257. const oldValue = get.call(target, key);
  1258. target.set(key, value);
  1259. if (!hadKey) {
  1260. trigger(target, "add", key, value);
  1261. } else if (hasChanged(value, oldValue)) {
  1262. trigger(target, "set", key, value, oldValue);
  1263. }
  1264. return this;
  1265. },
  1266. delete(key) {
  1267. const target = toRaw(this);
  1268. const { has, get } = getProto(target);
  1269. let hadKey = has.call(target, key);
  1270. if (!hadKey) {
  1271. key = toRaw(key);
  1272. hadKey = has.call(target, key);
  1273. } else {
  1274. checkIdentityKeys(target, has, key);
  1275. }
  1276. const oldValue = get ? get.call(target, key) : void 0;
  1277. const result = target.delete(key);
  1278. if (hadKey) {
  1279. trigger(target, "delete", key, void 0, oldValue);
  1280. }
  1281. return result;
  1282. },
  1283. clear() {
  1284. const target = toRaw(this);
  1285. const hadItems = target.size !== 0;
  1286. const oldTarget = isMap(target) ? new Map(target) : new Set(target) ;
  1287. const result = target.clear();
  1288. if (hadItems) {
  1289. trigger(
  1290. target,
  1291. "clear",
  1292. void 0,
  1293. void 0,
  1294. oldTarget
  1295. );
  1296. }
  1297. return result;
  1298. }
  1299. }
  1300. );
  1301. const iteratorMethods = [
  1302. "keys",
  1303. "values",
  1304. "entries",
  1305. Symbol.iterator
  1306. ];
  1307. iteratorMethods.forEach((method) => {
  1308. instrumentations[method] = createIterableMethod(method, readonly, shallow);
  1309. });
  1310. return instrumentations;
  1311. }
  1312. function createInstrumentationGetter(isReadonly2, shallow) {
  1313. const instrumentations = createInstrumentations(isReadonly2, shallow);
  1314. return (target, key, receiver) => {
  1315. if (key === "__v_isReactive") {
  1316. return !isReadonly2;
  1317. } else if (key === "__v_isReadonly") {
  1318. return isReadonly2;
  1319. } else if (key === "__v_raw") {
  1320. return target;
  1321. }
  1322. return Reflect.get(
  1323. hasOwn(instrumentations, key) && key in target ? instrumentations : target,
  1324. key,
  1325. receiver
  1326. );
  1327. };
  1328. }
  1329. const mutableCollectionHandlers = {
  1330. get: /* @__PURE__ */ createInstrumentationGetter(false, false)
  1331. };
  1332. const shallowCollectionHandlers = {
  1333. get: /* @__PURE__ */ createInstrumentationGetter(false, true)
  1334. };
  1335. const readonlyCollectionHandlers = {
  1336. get: /* @__PURE__ */ createInstrumentationGetter(true, false)
  1337. };
  1338. const shallowReadonlyCollectionHandlers = {
  1339. get: /* @__PURE__ */ createInstrumentationGetter(true, true)
  1340. };
  1341. function checkIdentityKeys(target, has, key) {
  1342. const rawKey = toRaw(key);
  1343. if (rawKey !== key && has.call(target, rawKey)) {
  1344. const type = toRawType(target);
  1345. warn(
  1346. `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.`
  1347. );
  1348. }
  1349. }
  1350. const reactiveMap = /* @__PURE__ */ new WeakMap();
  1351. const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
  1352. const readonlyMap = /* @__PURE__ */ new WeakMap();
  1353. const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
  1354. function targetTypeMap(rawType) {
  1355. switch (rawType) {
  1356. case "Object":
  1357. case "Array":
  1358. return 1 /* COMMON */;
  1359. case "Map":
  1360. case "Set":
  1361. case "WeakMap":
  1362. case "WeakSet":
  1363. return 2 /* COLLECTION */;
  1364. default:
  1365. return 0 /* INVALID */;
  1366. }
  1367. }
  1368. function getTargetType(value) {
  1369. return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(toRawType(value));
  1370. }
  1371. function reactive(target) {
  1372. if (isReadonly(target)) {
  1373. return target;
  1374. }
  1375. return createReactiveObject(
  1376. target,
  1377. false,
  1378. mutableHandlers,
  1379. mutableCollectionHandlers,
  1380. reactiveMap
  1381. );
  1382. }
  1383. function shallowReactive(target) {
  1384. return createReactiveObject(
  1385. target,
  1386. false,
  1387. shallowReactiveHandlers,
  1388. shallowCollectionHandlers,
  1389. shallowReactiveMap
  1390. );
  1391. }
  1392. function readonly(target) {
  1393. return createReactiveObject(
  1394. target,
  1395. true,
  1396. readonlyHandlers,
  1397. readonlyCollectionHandlers,
  1398. readonlyMap
  1399. );
  1400. }
  1401. function shallowReadonly(target) {
  1402. return createReactiveObject(
  1403. target,
  1404. true,
  1405. shallowReadonlyHandlers,
  1406. shallowReadonlyCollectionHandlers,
  1407. shallowReadonlyMap
  1408. );
  1409. }
  1410. function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
  1411. if (!isObject(target)) {
  1412. {
  1413. warn(
  1414. `value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(
  1415. target
  1416. )}`
  1417. );
  1418. }
  1419. return target;
  1420. }
  1421. if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
  1422. return target;
  1423. }
  1424. const targetType = getTargetType(target);
  1425. if (targetType === 0 /* INVALID */) {
  1426. return target;
  1427. }
  1428. const existingProxy = proxyMap.get(target);
  1429. if (existingProxy) {
  1430. return existingProxy;
  1431. }
  1432. const proxy = new Proxy(
  1433. target,
  1434. targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
  1435. );
  1436. proxyMap.set(target, proxy);
  1437. return proxy;
  1438. }
  1439. function isReactive(value) {
  1440. if (isReadonly(value)) {
  1441. return isReactive(value["__v_raw"]);
  1442. }
  1443. return !!(value && value["__v_isReactive"]);
  1444. }
  1445. function isReadonly(value) {
  1446. return !!(value && value["__v_isReadonly"]);
  1447. }
  1448. function isShallow(value) {
  1449. return !!(value && value["__v_isShallow"]);
  1450. }
  1451. function isProxy(value) {
  1452. return value ? !!value["__v_raw"] : false;
  1453. }
  1454. function toRaw(observed) {
  1455. const raw = observed && observed["__v_raw"];
  1456. return raw ? toRaw(raw) : observed;
  1457. }
  1458. function markRaw(value) {
  1459. if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
  1460. def(value, "__v_skip", true);
  1461. }
  1462. return value;
  1463. }
  1464. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1465. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1466. function isRef(r) {
  1467. return r ? r["__v_isRef"] === true : false;
  1468. }
  1469. function ref(value) {
  1470. return createRef(value, false);
  1471. }
  1472. function shallowRef(value) {
  1473. return createRef(value, true);
  1474. }
  1475. function createRef(rawValue, shallow) {
  1476. if (isRef(rawValue)) {
  1477. return rawValue;
  1478. }
  1479. return new RefImpl(rawValue, shallow);
  1480. }
  1481. class RefImpl {
  1482. constructor(value, isShallow2) {
  1483. this.dep = new Dep();
  1484. this["__v_isRef"] = true;
  1485. this["__v_isShallow"] = false;
  1486. this._rawValue = isShallow2 ? value : toRaw(value);
  1487. this._value = isShallow2 ? value : toReactive(value);
  1488. this["__v_isShallow"] = isShallow2;
  1489. }
  1490. get value() {
  1491. {
  1492. this.dep.track({
  1493. target: this,
  1494. type: "get",
  1495. key: "value"
  1496. });
  1497. }
  1498. return this._value;
  1499. }
  1500. set value(newValue) {
  1501. const oldValue = this._rawValue;
  1502. const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
  1503. newValue = useDirectValue ? newValue : toRaw(newValue);
  1504. if (hasChanged(newValue, oldValue)) {
  1505. this._rawValue = newValue;
  1506. this._value = useDirectValue ? newValue : toReactive(newValue);
  1507. {
  1508. this.dep.trigger({
  1509. target: this,
  1510. type: "set",
  1511. key: "value",
  1512. newValue,
  1513. oldValue
  1514. });
  1515. }
  1516. }
  1517. }
  1518. }
  1519. function triggerRef(ref2) {
  1520. if (ref2.dep) {
  1521. {
  1522. ref2.dep.trigger({
  1523. target: ref2,
  1524. type: "set",
  1525. key: "value",
  1526. newValue: ref2._value
  1527. });
  1528. }
  1529. }
  1530. }
  1531. function unref(ref2) {
  1532. return isRef(ref2) ? ref2.value : ref2;
  1533. }
  1534. function toValue(source) {
  1535. return isFunction(source) ? source() : unref(source);
  1536. }
  1537. const shallowUnwrapHandlers = {
  1538. get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
  1539. set: (target, key, value, receiver) => {
  1540. const oldValue = target[key];
  1541. if (isRef(oldValue) && !isRef(value)) {
  1542. oldValue.value = value;
  1543. return true;
  1544. } else {
  1545. return Reflect.set(target, key, value, receiver);
  1546. }
  1547. }
  1548. };
  1549. function proxyRefs(objectWithRefs) {
  1550. return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1551. }
  1552. class CustomRefImpl {
  1553. constructor(factory) {
  1554. this["__v_isRef"] = true;
  1555. this._value = void 0;
  1556. const dep = this.dep = new Dep();
  1557. const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
  1558. this._get = get;
  1559. this._set = set;
  1560. }
  1561. get value() {
  1562. return this._value = this._get();
  1563. }
  1564. set value(newVal) {
  1565. this._set(newVal);
  1566. }
  1567. }
  1568. function customRef(factory) {
  1569. return new CustomRefImpl(factory);
  1570. }
  1571. function toRefs(object) {
  1572. if (!isProxy(object)) {
  1573. warn(`toRefs() expects a reactive object but received a plain one.`);
  1574. }
  1575. const ret = isArray(object) ? new Array(object.length) : {};
  1576. for (const key in object) {
  1577. ret[key] = propertyToRef(object, key);
  1578. }
  1579. return ret;
  1580. }
  1581. class ObjectRefImpl {
  1582. constructor(_object, _key, _defaultValue) {
  1583. this._object = _object;
  1584. this._key = _key;
  1585. this._defaultValue = _defaultValue;
  1586. this["__v_isRef"] = true;
  1587. this._value = void 0;
  1588. }
  1589. get value() {
  1590. const val = this._object[this._key];
  1591. return this._value = val === void 0 ? this._defaultValue : val;
  1592. }
  1593. set value(newVal) {
  1594. this._object[this._key] = newVal;
  1595. }
  1596. get dep() {
  1597. return getDepFromReactive(toRaw(this._object), this._key);
  1598. }
  1599. }
  1600. class GetterRefImpl {
  1601. constructor(_getter) {
  1602. this._getter = _getter;
  1603. this["__v_isRef"] = true;
  1604. this["__v_isReadonly"] = true;
  1605. this._value = void 0;
  1606. }
  1607. get value() {
  1608. return this._value = this._getter();
  1609. }
  1610. }
  1611. function toRef(source, key, defaultValue) {
  1612. if (isRef(source)) {
  1613. return source;
  1614. } else if (isFunction(source)) {
  1615. return new GetterRefImpl(source);
  1616. } else if (isObject(source) && arguments.length > 1) {
  1617. return propertyToRef(source, key, defaultValue);
  1618. } else {
  1619. return ref(source);
  1620. }
  1621. }
  1622. function propertyToRef(source, key, defaultValue) {
  1623. const val = source[key];
  1624. return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
  1625. }
  1626. class ComputedRefImpl {
  1627. constructor(fn, setter, isSSR) {
  1628. this.fn = fn;
  1629. this.setter = setter;
  1630. /**
  1631. * @internal
  1632. */
  1633. this._value = void 0;
  1634. /**
  1635. * @internal
  1636. */
  1637. this.dep = new Dep(this);
  1638. /**
  1639. * @internal
  1640. */
  1641. this.__v_isRef = true;
  1642. // TODO isolatedDeclarations "__v_isReadonly"
  1643. // A computed is also a subscriber that tracks other deps
  1644. /**
  1645. * @internal
  1646. */
  1647. this.deps = void 0;
  1648. /**
  1649. * @internal
  1650. */
  1651. this.depsTail = void 0;
  1652. /**
  1653. * @internal
  1654. */
  1655. this.flags = 16;
  1656. /**
  1657. * @internal
  1658. */
  1659. this.globalVersion = globalVersion - 1;
  1660. /**
  1661. * @internal
  1662. */
  1663. this.next = void 0;
  1664. // for backwards compat
  1665. this.effect = this;
  1666. this["__v_isReadonly"] = !setter;
  1667. this.isSSR = isSSR;
  1668. }
  1669. /**
  1670. * @internal
  1671. */
  1672. notify() {
  1673. this.flags |= 16;
  1674. if (!(this.flags & 8) && // avoid infinite self recursion
  1675. activeSub !== this) {
  1676. batch(this, true);
  1677. return true;
  1678. }
  1679. }
  1680. get value() {
  1681. const link = this.dep.track({
  1682. target: this,
  1683. type: "get",
  1684. key: "value"
  1685. }) ;
  1686. refreshComputed(this);
  1687. if (link) {
  1688. link.version = this.dep.version;
  1689. }
  1690. return this._value;
  1691. }
  1692. set value(newValue) {
  1693. if (this.setter) {
  1694. this.setter(newValue);
  1695. } else {
  1696. warn("Write operation failed: computed value is readonly");
  1697. }
  1698. }
  1699. }
  1700. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1701. let getter;
  1702. let setter;
  1703. if (isFunction(getterOrOptions)) {
  1704. getter = getterOrOptions;
  1705. } else {
  1706. getter = getterOrOptions.get;
  1707. setter = getterOrOptions.set;
  1708. }
  1709. const cRef = new ComputedRefImpl(getter, setter, isSSR);
  1710. if (debugOptions && !isSSR) {
  1711. cRef.onTrack = debugOptions.onTrack;
  1712. cRef.onTrigger = debugOptions.onTrigger;
  1713. }
  1714. return cRef;
  1715. }
  1716. const TrackOpTypes = {
  1717. "GET": "get",
  1718. "HAS": "has",
  1719. "ITERATE": "iterate"
  1720. };
  1721. const TriggerOpTypes = {
  1722. "SET": "set",
  1723. "ADD": "add",
  1724. "DELETE": "delete",
  1725. "CLEAR": "clear"
  1726. };
  1727. const ReactiveFlags = {
  1728. "SKIP": "__v_skip",
  1729. "IS_REACTIVE": "__v_isReactive",
  1730. "IS_READONLY": "__v_isReadonly",
  1731. "IS_SHALLOW": "__v_isShallow",
  1732. "RAW": "__v_raw",
  1733. "IS_REF": "__v_isRef"
  1734. };
  1735. const WatchErrorCodes = {
  1736. "WATCH_GETTER": 2,
  1737. "2": "WATCH_GETTER",
  1738. "WATCH_CALLBACK": 3,
  1739. "3": "WATCH_CALLBACK",
  1740. "WATCH_CLEANUP": 4,
  1741. "4": "WATCH_CLEANUP"
  1742. };
  1743. const INITIAL_WATCHER_VALUE = {};
  1744. const cleanupMap = /* @__PURE__ */ new WeakMap();
  1745. let activeWatcher = void 0;
  1746. function getCurrentWatcher() {
  1747. return activeWatcher;
  1748. }
  1749. function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
  1750. if (owner) {
  1751. let cleanups = cleanupMap.get(owner);
  1752. if (!cleanups) cleanupMap.set(owner, cleanups = []);
  1753. cleanups.push(cleanupFn);
  1754. } else if (!failSilently) {
  1755. warn(
  1756. `onWatcherCleanup() was called when there was no active watcher to associate with.`
  1757. );
  1758. }
  1759. }
  1760. function watch(source, cb, options = EMPTY_OBJ) {
  1761. const { immediate, deep, once, scheduler, augmentJob, call } = options;
  1762. const warnInvalidSource = (s) => {
  1763. (options.onWarn || warn)(
  1764. `Invalid watch source: `,
  1765. s,
  1766. `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
  1767. );
  1768. };
  1769. const reactiveGetter = (source2) => {
  1770. if (deep) return source2;
  1771. if (isShallow(source2) || deep === false || deep === 0)
  1772. return traverse(source2, 1);
  1773. return traverse(source2);
  1774. };
  1775. let effect;
  1776. let getter;
  1777. let cleanup;
  1778. let boundCleanup;
  1779. let forceTrigger = false;
  1780. let isMultiSource = false;
  1781. if (isRef(source)) {
  1782. getter = () => source.value;
  1783. forceTrigger = isShallow(source);
  1784. } else if (isReactive(source)) {
  1785. getter = () => reactiveGetter(source);
  1786. forceTrigger = true;
  1787. } else if (isArray(source)) {
  1788. isMultiSource = true;
  1789. forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
  1790. getter = () => source.map((s) => {
  1791. if (isRef(s)) {
  1792. return s.value;
  1793. } else if (isReactive(s)) {
  1794. return reactiveGetter(s);
  1795. } else if (isFunction(s)) {
  1796. return call ? call(s, 2) : s();
  1797. } else {
  1798. warnInvalidSource(s);
  1799. }
  1800. });
  1801. } else if (isFunction(source)) {
  1802. if (cb) {
  1803. getter = call ? () => call(source, 2) : source;
  1804. } else {
  1805. getter = () => {
  1806. if (cleanup) {
  1807. pauseTracking();
  1808. try {
  1809. cleanup();
  1810. } finally {
  1811. resetTracking();
  1812. }
  1813. }
  1814. const currentEffect = activeWatcher;
  1815. activeWatcher = effect;
  1816. try {
  1817. return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
  1818. } finally {
  1819. activeWatcher = currentEffect;
  1820. }
  1821. };
  1822. }
  1823. } else {
  1824. getter = NOOP;
  1825. warnInvalidSource(source);
  1826. }
  1827. if (cb && deep) {
  1828. const baseGetter = getter;
  1829. const depth = deep === true ? Infinity : deep;
  1830. getter = () => traverse(baseGetter(), depth);
  1831. }
  1832. const scope = getCurrentScope();
  1833. const watchHandle = () => {
  1834. effect.stop();
  1835. if (scope && scope.active) {
  1836. remove(scope.effects, effect);
  1837. }
  1838. };
  1839. if (once && cb) {
  1840. const _cb = cb;
  1841. cb = (...args) => {
  1842. _cb(...args);
  1843. watchHandle();
  1844. };
  1845. }
  1846. let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
  1847. const job = (immediateFirstRun) => {
  1848. if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
  1849. return;
  1850. }
  1851. if (cb) {
  1852. const newValue = effect.run();
  1853. if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
  1854. if (cleanup) {
  1855. cleanup();
  1856. }
  1857. const currentWatcher = activeWatcher;
  1858. activeWatcher = effect;
  1859. try {
  1860. const args = [
  1861. newValue,
  1862. // pass undefined as the old value when it's changed for the first time
  1863. oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
  1864. boundCleanup
  1865. ];
  1866. oldValue = newValue;
  1867. call ? call(cb, 3, args) : (
  1868. // @ts-expect-error
  1869. cb(...args)
  1870. );
  1871. } finally {
  1872. activeWatcher = currentWatcher;
  1873. }
  1874. }
  1875. } else {
  1876. effect.run();
  1877. }
  1878. };
  1879. if (augmentJob) {
  1880. augmentJob(job);
  1881. }
  1882. effect = new ReactiveEffect(getter);
  1883. effect.scheduler = scheduler ? () => scheduler(job, false) : job;
  1884. boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
  1885. cleanup = effect.onStop = () => {
  1886. const cleanups = cleanupMap.get(effect);
  1887. if (cleanups) {
  1888. if (call) {
  1889. call(cleanups, 4);
  1890. } else {
  1891. for (const cleanup2 of cleanups) cleanup2();
  1892. }
  1893. cleanupMap.delete(effect);
  1894. }
  1895. };
  1896. {
  1897. effect.onTrack = options.onTrack;
  1898. effect.onTrigger = options.onTrigger;
  1899. }
  1900. if (cb) {
  1901. if (immediate) {
  1902. job(true);
  1903. } else {
  1904. oldValue = effect.run();
  1905. }
  1906. } else if (scheduler) {
  1907. scheduler(job.bind(null, true), true);
  1908. } else {
  1909. effect.run();
  1910. }
  1911. watchHandle.pause = effect.pause.bind(effect);
  1912. watchHandle.resume = effect.resume.bind(effect);
  1913. watchHandle.stop = watchHandle;
  1914. return watchHandle;
  1915. }
  1916. function traverse(value, depth = Infinity, seen) {
  1917. if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
  1918. return value;
  1919. }
  1920. seen = seen || /* @__PURE__ */ new Map();
  1921. if ((seen.get(value) || 0) >= depth) {
  1922. return value;
  1923. }
  1924. seen.set(value, depth);
  1925. depth--;
  1926. if (isRef(value)) {
  1927. traverse(value.value, depth, seen);
  1928. } else if (isArray(value)) {
  1929. for (let i = 0; i < value.length; i++) {
  1930. traverse(value[i], depth, seen);
  1931. }
  1932. } else if (isSet(value) || isMap(value)) {
  1933. value.forEach((v) => {
  1934. traverse(v, depth, seen);
  1935. });
  1936. } else if (isPlainObject(value)) {
  1937. for (const key in value) {
  1938. traverse(value[key], depth, seen);
  1939. }
  1940. for (const key of Object.getOwnPropertySymbols(value)) {
  1941. if (Object.prototype.propertyIsEnumerable.call(value, key)) {
  1942. traverse(value[key], depth, seen);
  1943. }
  1944. }
  1945. }
  1946. return value;
  1947. }
  1948. exports.ARRAY_ITERATE_KEY = ARRAY_ITERATE_KEY;
  1949. exports.EffectFlags = EffectFlags;
  1950. exports.EffectScope = EffectScope;
  1951. exports.ITERATE_KEY = ITERATE_KEY;
  1952. exports.MAP_KEY_ITERATE_KEY = MAP_KEY_ITERATE_KEY;
  1953. exports.ReactiveEffect = ReactiveEffect;
  1954. exports.ReactiveFlags = ReactiveFlags;
  1955. exports.TrackOpTypes = TrackOpTypes;
  1956. exports.TriggerOpTypes = TriggerOpTypes;
  1957. exports.WatchErrorCodes = WatchErrorCodes;
  1958. exports.computed = computed;
  1959. exports.customRef = customRef;
  1960. exports.effect = effect;
  1961. exports.effectScope = effectScope;
  1962. exports.enableTracking = enableTracking;
  1963. exports.getCurrentScope = getCurrentScope;
  1964. exports.getCurrentWatcher = getCurrentWatcher;
  1965. exports.isProxy = isProxy;
  1966. exports.isReactive = isReactive;
  1967. exports.isReadonly = isReadonly;
  1968. exports.isRef = isRef;
  1969. exports.isShallow = isShallow;
  1970. exports.markRaw = markRaw;
  1971. exports.onEffectCleanup = onEffectCleanup;
  1972. exports.onScopeDispose = onScopeDispose;
  1973. exports.onWatcherCleanup = onWatcherCleanup;
  1974. exports.pauseTracking = pauseTracking;
  1975. exports.proxyRefs = proxyRefs;
  1976. exports.reactive = reactive;
  1977. exports.reactiveReadArray = reactiveReadArray;
  1978. exports.readonly = readonly;
  1979. exports.ref = ref;
  1980. exports.resetTracking = resetTracking;
  1981. exports.shallowReactive = shallowReactive;
  1982. exports.shallowReadArray = shallowReadArray;
  1983. exports.shallowReadonly = shallowReadonly;
  1984. exports.shallowRef = shallowRef;
  1985. exports.stop = stop;
  1986. exports.toRaw = toRaw;
  1987. exports.toReactive = toReactive;
  1988. exports.toReadonly = toReadonly;
  1989. exports.toRef = toRef;
  1990. exports.toRefs = toRefs;
  1991. exports.toValue = toValue;
  1992. exports.track = track;
  1993. exports.traverse = traverse;
  1994. exports.trigger = trigger;
  1995. exports.triggerRef = triggerRef;
  1996. exports.unref = unref;
  1997. exports.watch = watch;
  1998. return exports;
  1999. })({});