reactivity.global.js 55 KB

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