reactivity.global.js 55 KB

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