智慧水务管理系统 - 精河县供水工程综合管理平台

reactivity.cjs.prod.js 49KB

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