Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reactivity.cjs.js 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. /**
  2. * @vue/reactivity v3.4.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. function warn(msg, ...args) {
  10. console.warn(`[Vue warn] ${msg}`, ...args);
  11. }
  12. let activeEffectScope;
  13. class EffectScope {
  14. constructor(detached = false) {
  15. this.detached = detached;
  16. /**
  17. * @internal
  18. */
  19. this._active = true;
  20. /**
  21. * @internal
  22. */
  23. this.effects = [];
  24. /**
  25. * @internal
  26. */
  27. this.cleanups = [];
  28. this.parent = activeEffectScope;
  29. if (!detached && activeEffectScope) {
  30. this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
  31. this
  32. ) - 1;
  33. }
  34. }
  35. get active() {
  36. return this._active;
  37. }
  38. run(fn) {
  39. if (this._active) {
  40. const currentEffectScope = activeEffectScope;
  41. try {
  42. activeEffectScope = this;
  43. return fn();
  44. } finally {
  45. activeEffectScope = currentEffectScope;
  46. }
  47. } else {
  48. warn(`cannot run an inactive effect scope.`);
  49. }
  50. }
  51. /**
  52. * This should only be called on non-detached scopes
  53. * @internal
  54. */
  55. on() {
  56. activeEffectScope = this;
  57. }
  58. /**
  59. * This should only be called on non-detached scopes
  60. * @internal
  61. */
  62. off() {
  63. activeEffectScope = this.parent;
  64. }
  65. stop(fromParent) {
  66. if (this._active) {
  67. let i, l;
  68. for (i = 0, l = this.effects.length; i < l; i++) {
  69. this.effects[i].stop();
  70. }
  71. for (i = 0, l = this.cleanups.length; i < l; i++) {
  72. this.cleanups[i]();
  73. }
  74. if (this.scopes) {
  75. for (i = 0, l = this.scopes.length; i < l; i++) {
  76. this.scopes[i].stop(true);
  77. }
  78. }
  79. if (!this.detached && this.parent && !fromParent) {
  80. const last = this.parent.scopes.pop();
  81. if (last && last !== this) {
  82. this.parent.scopes[this.index] = last;
  83. last.index = this.index;
  84. }
  85. }
  86. this.parent = void 0;
  87. this._active = false;
  88. }
  89. }
  90. }
  91. function effectScope(detached) {
  92. return new EffectScope(detached);
  93. }
  94. function recordEffectScope(effect, scope = activeEffectScope) {
  95. if (scope && scope.active) {
  96. scope.effects.push(effect);
  97. }
  98. }
  99. function getCurrentScope() {
  100. return activeEffectScope;
  101. }
  102. function onScopeDispose(fn) {
  103. if (activeEffectScope) {
  104. activeEffectScope.cleanups.push(fn);
  105. } else {
  106. warn(
  107. `onScopeDispose() is called when there is no active effect scope to be associated with.`
  108. );
  109. }
  110. }
  111. let activeEffect;
  112. class ReactiveEffect {
  113. constructor(fn, trigger, scheduler, scope) {
  114. this.fn = fn;
  115. this.trigger = trigger;
  116. this.scheduler = scheduler;
  117. this.active = true;
  118. this.deps = [];
  119. /**
  120. * @internal
  121. */
  122. this._dirtyLevel = 4;
  123. /**
  124. * @internal
  125. */
  126. this._trackId = 0;
  127. /**
  128. * @internal
  129. */
  130. this._runnings = 0;
  131. /**
  132. * @internal
  133. */
  134. this._shouldSchedule = false;
  135. /**
  136. * @internal
  137. */
  138. this._depsLength = 0;
  139. recordEffectScope(this, scope);
  140. }
  141. get dirty() {
  142. if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
  143. this._dirtyLevel = 1;
  144. pauseTracking();
  145. for (let i = 0; i < this._depsLength; i++) {
  146. const dep = this.deps[i];
  147. if (dep.computed) {
  148. triggerComputed(dep.computed);
  149. if (this._dirtyLevel >= 4) {
  150. break;
  151. }
  152. }
  153. }
  154. if (this._dirtyLevel === 1) {
  155. this._dirtyLevel = 0;
  156. }
  157. resetTracking();
  158. }
  159. return this._dirtyLevel >= 4;
  160. }
  161. set dirty(v) {
  162. this._dirtyLevel = v ? 4 : 0;
  163. }
  164. run() {
  165. this._dirtyLevel = 0;
  166. if (!this.active) {
  167. return this.fn();
  168. }
  169. let lastShouldTrack = shouldTrack;
  170. let lastEffect = activeEffect;
  171. try {
  172. shouldTrack = true;
  173. activeEffect = this;
  174. this._runnings++;
  175. preCleanupEffect(this);
  176. return this.fn();
  177. } finally {
  178. postCleanupEffect(this);
  179. this._runnings--;
  180. activeEffect = lastEffect;
  181. shouldTrack = lastShouldTrack;
  182. }
  183. }
  184. stop() {
  185. if (this.active) {
  186. preCleanupEffect(this);
  187. postCleanupEffect(this);
  188. this.onStop && this.onStop();
  189. this.active = false;
  190. }
  191. }
  192. }
  193. function triggerComputed(computed) {
  194. return computed.value;
  195. }
  196. function preCleanupEffect(effect2) {
  197. effect2._trackId++;
  198. effect2._depsLength = 0;
  199. }
  200. function postCleanupEffect(effect2) {
  201. if (effect2.deps.length > effect2._depsLength) {
  202. for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
  203. cleanupDepEffect(effect2.deps[i], effect2);
  204. }
  205. effect2.deps.length = effect2._depsLength;
  206. }
  207. }
  208. function cleanupDepEffect(dep, effect2) {
  209. const trackId = dep.get(effect2);
  210. if (trackId !== void 0 && effect2._trackId !== trackId) {
  211. dep.delete(effect2);
  212. if (dep.size === 0) {
  213. dep.cleanup();
  214. }
  215. }
  216. }
  217. function effect(fn, options) {
  218. if (fn.effect instanceof ReactiveEffect) {
  219. fn = fn.effect.fn;
  220. }
  221. const _effect = new ReactiveEffect(fn, shared.NOOP, () => {
  222. if (_effect.dirty) {
  223. _effect.run();
  224. }
  225. });
  226. if (options) {
  227. shared.extend(_effect, options);
  228. if (options.scope) recordEffectScope(_effect, options.scope);
  229. }
  230. if (!options || !options.lazy) {
  231. _effect.run();
  232. }
  233. const runner = _effect.run.bind(_effect);
  234. runner.effect = _effect;
  235. return runner;
  236. }
  237. function stop(runner) {
  238. runner.effect.stop();
  239. }
  240. let shouldTrack = true;
  241. let pauseScheduleStack = 0;
  242. const trackStack = [];
  243. function pauseTracking() {
  244. trackStack.push(shouldTrack);
  245. shouldTrack = false;
  246. }
  247. function enableTracking() {
  248. trackStack.push(shouldTrack);
  249. shouldTrack = true;
  250. }
  251. function resetTracking() {
  252. const last = trackStack.pop();
  253. shouldTrack = last === void 0 ? true : last;
  254. }
  255. function pauseScheduling() {
  256. pauseScheduleStack++;
  257. }
  258. function resetScheduling() {
  259. pauseScheduleStack--;
  260. while (!pauseScheduleStack && queueEffectSchedulers.length) {
  261. queueEffectSchedulers.shift()();
  262. }
  263. }
  264. function trackEffect(effect2, dep, debuggerEventExtraInfo) {
  265. var _a;
  266. if (dep.get(effect2) !== effect2._trackId) {
  267. dep.set(effect2, effect2._trackId);
  268. const oldDep = effect2.deps[effect2._depsLength];
  269. if (oldDep !== dep) {
  270. if (oldDep) {
  271. cleanupDepEffect(oldDep, effect2);
  272. }
  273. effect2.deps[effect2._depsLength++] = dep;
  274. } else {
  275. effect2._depsLength++;
  276. }
  277. {
  278. (_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, shared.extend({ effect: effect2 }, debuggerEventExtraInfo));
  279. }
  280. }
  281. }
  282. const queueEffectSchedulers = [];
  283. function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
  284. var _a;
  285. pauseScheduling();
  286. for (const effect2 of dep.keys()) {
  287. let tracking;
  288. if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
  289. effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
  290. effect2._dirtyLevel = dirtyLevel;
  291. }
  292. if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
  293. {
  294. (_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, shared.extend({ effect: effect2 }, debuggerEventExtraInfo));
  295. }
  296. effect2.trigger();
  297. if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
  298. effect2._shouldSchedule = false;
  299. if (effect2.scheduler) {
  300. queueEffectSchedulers.push(effect2.scheduler);
  301. }
  302. }
  303. }
  304. }
  305. resetScheduling();
  306. }
  307. const createDep = (cleanup, computed) => {
  308. const dep = /* @__PURE__ */ new Map();
  309. dep.cleanup = cleanup;
  310. dep.computed = computed;
  311. return dep;
  312. };
  313. const targetMap = /* @__PURE__ */ new WeakMap();
  314. const ITERATE_KEY = Symbol("iterate" );
  315. const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
  316. function track(target, type, key) {
  317. if (shouldTrack && activeEffect) {
  318. let depsMap = targetMap.get(target);
  319. if (!depsMap) {
  320. targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
  321. }
  322. let dep = depsMap.get(key);
  323. if (!dep) {
  324. depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
  325. }
  326. trackEffect(
  327. activeEffect,
  328. dep,
  329. {
  330. target,
  331. type,
  332. key
  333. }
  334. );
  335. }
  336. }
  337. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  338. const depsMap = targetMap.get(target);
  339. if (!depsMap) {
  340. return;
  341. }
  342. let deps = [];
  343. if (type === "clear") {
  344. deps = [...depsMap.values()];
  345. } else if (key === "length" && shared.isArray(target)) {
  346. const newLength = Number(newValue);
  347. depsMap.forEach((dep, key2) => {
  348. if (key2 === "length" || !shared.isSymbol(key2) && key2 >= newLength) {
  349. deps.push(dep);
  350. }
  351. });
  352. } else {
  353. if (key !== void 0) {
  354. deps.push(depsMap.get(key));
  355. }
  356. switch (type) {
  357. case "add":
  358. if (!shared.isArray(target)) {
  359. deps.push(depsMap.get(ITERATE_KEY));
  360. if (shared.isMap(target)) {
  361. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  362. }
  363. } else if (shared.isIntegerKey(key)) {
  364. deps.push(depsMap.get("length"));
  365. }
  366. break;
  367. case "delete":
  368. if (!shared.isArray(target)) {
  369. deps.push(depsMap.get(ITERATE_KEY));
  370. if (shared.isMap(target)) {
  371. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  372. }
  373. }
  374. break;
  375. case "set":
  376. if (shared.isMap(target)) {
  377. deps.push(depsMap.get(ITERATE_KEY));
  378. }
  379. break;
  380. }
  381. }
  382. pauseScheduling();
  383. for (const dep of deps) {
  384. if (dep) {
  385. triggerEffects(
  386. dep,
  387. 4,
  388. {
  389. target,
  390. type,
  391. key,
  392. newValue,
  393. oldValue,
  394. oldTarget
  395. }
  396. );
  397. }
  398. }
  399. resetScheduling();
  400. }
  401. function getDepFromReactive(object, key) {
  402. const depsMap = targetMap.get(object);
  403. return depsMap && depsMap.get(key);
  404. }
  405. const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,__isVue`);
  406. const builtInSymbols = new Set(
  407. /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
  408. );
  409. const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
  410. function createArrayInstrumentations() {
  411. const instrumentations = {};
  412. ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
  413. instrumentations[key] = function(...args) {
  414. const arr = toRaw(this);
  415. for (let i = 0, l = this.length; i < l; i++) {
  416. track(arr, "get", i + "");
  417. }
  418. const res = arr[key](...args);
  419. if (res === -1 || res === false) {
  420. return arr[key](...args.map(toRaw));
  421. } else {
  422. return res;
  423. }
  424. };
  425. });
  426. ["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
  427. instrumentations[key] = function(...args) {
  428. pauseTracking();
  429. pauseScheduling();
  430. const res = toRaw(this)[key].apply(this, args);
  431. resetScheduling();
  432. resetTracking();
  433. return res;
  434. };
  435. });
  436. return instrumentations;
  437. }
  438. function hasOwnProperty(key) {
  439. if (!shared.isSymbol(key)) key = String(key);
  440. const obj = toRaw(this);
  441. track(obj, "has", key);
  442. return obj.hasOwnProperty(key);
  443. }
  444. class BaseReactiveHandler {
  445. constructor(_isReadonly = false, _isShallow = false) {
  446. this._isReadonly = _isReadonly;
  447. this._isShallow = _isShallow;
  448. }
  449. get(target, key, receiver) {
  450. const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
  451. if (key === "__v_isReactive") {
  452. return !isReadonly2;
  453. } else if (key === "__v_isReadonly") {
  454. return isReadonly2;
  455. } else if (key === "__v_isShallow") {
  456. return isShallow2;
  457. } else if (key === "__v_raw") {
  458. if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
  459. // this means the receiver is a user proxy of the reactive proxy
  460. Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
  461. return target;
  462. }
  463. return;
  464. }
  465. const targetIsArray = shared.isArray(target);
  466. if (!isReadonly2) {
  467. if (targetIsArray && shared.hasOwn(arrayInstrumentations, key)) {
  468. return Reflect.get(arrayInstrumentations, key, receiver);
  469. }
  470. if (key === "hasOwnProperty") {
  471. return hasOwnProperty;
  472. }
  473. }
  474. const res = Reflect.get(target, key, receiver);
  475. if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  476. return res;
  477. }
  478. if (!isReadonly2) {
  479. track(target, "get", key);
  480. }
  481. if (isShallow2) {
  482. return res;
  483. }
  484. if (isRef(res)) {
  485. return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
  486. }
  487. if (shared.isObject(res)) {
  488. return isReadonly2 ? readonly(res) : reactive(res);
  489. }
  490. return res;
  491. }
  492. }
  493. class MutableReactiveHandler extends BaseReactiveHandler {
  494. constructor(isShallow2 = false) {
  495. super(false, isShallow2);
  496. }
  497. set(target, key, value, receiver) {
  498. let oldValue = target[key];
  499. if (!this._isShallow) {
  500. const isOldValueReadonly = isReadonly(oldValue);
  501. if (!isShallow(value) && !isReadonly(value)) {
  502. oldValue = toRaw(oldValue);
  503. value = toRaw(value);
  504. }
  505. if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
  506. if (isOldValueReadonly) {
  507. return false;
  508. } else {
  509. oldValue.value = value;
  510. return true;
  511. }
  512. }
  513. }
  514. const hadKey = shared.isArray(target) && shared.isIntegerKey(key) ? Number(key) < target.length : shared.hasOwn(target, key);
  515. const result = Reflect.set(target, key, value, receiver);
  516. if (target === toRaw(receiver)) {
  517. if (!hadKey) {
  518. trigger(target, "add", key, value);
  519. } else if (shared.hasChanged(value, oldValue)) {
  520. trigger(target, "set", key, value, oldValue);
  521. }
  522. }
  523. return result;
  524. }
  525. deleteProperty(target, key) {
  526. const hadKey = shared.hasOwn(target, key);
  527. const oldValue = target[key];
  528. const result = Reflect.deleteProperty(target, key);
  529. if (result && hadKey) {
  530. trigger(target, "delete", key, void 0, oldValue);
  531. }
  532. return result;
  533. }
  534. has(target, key) {
  535. const result = Reflect.has(target, key);
  536. if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
  537. track(target, "has", key);
  538. }
  539. return result;
  540. }
  541. ownKeys(target) {
  542. track(
  543. target,
  544. "iterate",
  545. shared.isArray(target) ? "length" : ITERATE_KEY
  546. );
  547. return Reflect.ownKeys(target);
  548. }
  549. }
  550. class ReadonlyReactiveHandler extends BaseReactiveHandler {
  551. constructor(isShallow2 = false) {
  552. super(true, isShallow2);
  553. }
  554. set(target, key) {
  555. {
  556. warn(
  557. `Set operation on key "${String(key)}" failed: target is readonly.`,
  558. target
  559. );
  560. }
  561. return true;
  562. }
  563. deleteProperty(target, key) {
  564. {
  565. warn(
  566. `Delete operation on key "${String(key)}" failed: target is readonly.`,
  567. target
  568. );
  569. }
  570. return true;
  571. }
  572. }
  573. const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
  574. const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
  575. const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
  576. true
  577. );
  578. const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
  579. const toShallow = (value) => value;
  580. const getProto = (v) => Reflect.getPrototypeOf(v);
  581. function get(target, key, isReadonly2 = false, isShallow2 = false) {
  582. target = target["__v_raw"];
  583. const rawTarget = toRaw(target);
  584. const rawKey = toRaw(key);
  585. if (!isReadonly2) {
  586. if (shared.hasChanged(key, rawKey)) {
  587. track(rawTarget, "get", key);
  588. }
  589. track(rawTarget, "get", rawKey);
  590. }
  591. const { has: has2 } = getProto(rawTarget);
  592. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  593. if (has2.call(rawTarget, key)) {
  594. return wrap(target.get(key));
  595. } else if (has2.call(rawTarget, rawKey)) {
  596. return wrap(target.get(rawKey));
  597. } else if (target !== rawTarget) {
  598. target.get(key);
  599. }
  600. }
  601. function has(key, isReadonly2 = false) {
  602. const target = this["__v_raw"];
  603. const rawTarget = toRaw(target);
  604. const rawKey = toRaw(key);
  605. if (!isReadonly2) {
  606. if (shared.hasChanged(key, rawKey)) {
  607. track(rawTarget, "has", key);
  608. }
  609. track(rawTarget, "has", rawKey);
  610. }
  611. return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
  612. }
  613. function size(target, isReadonly2 = false) {
  614. target = target["__v_raw"];
  615. !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
  616. return Reflect.get(target, "size", target);
  617. }
  618. function add(value, _isShallow = false) {
  619. if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
  620. value = toRaw(value);
  621. }
  622. const target = toRaw(this);
  623. const proto = getProto(target);
  624. const hadKey = proto.has.call(target, value);
  625. if (!hadKey) {
  626. target.add(value);
  627. trigger(target, "add", value, value);
  628. }
  629. return this;
  630. }
  631. function set(key, value, _isShallow = false) {
  632. if (!_isShallow && !isShallow(value) && !isReadonly(value)) {
  633. value = toRaw(value);
  634. }
  635. const target = toRaw(this);
  636. const { has: has2, get: get2 } = getProto(target);
  637. let hadKey = has2.call(target, key);
  638. if (!hadKey) {
  639. key = toRaw(key);
  640. hadKey = has2.call(target, key);
  641. } else {
  642. checkIdentityKeys(target, has2, key);
  643. }
  644. const oldValue = get2.call(target, key);
  645. target.set(key, value);
  646. if (!hadKey) {
  647. trigger(target, "add", key, value);
  648. } else if (shared.hasChanged(value, oldValue)) {
  649. trigger(target, "set", key, value, oldValue);
  650. }
  651. return this;
  652. }
  653. function deleteEntry(key) {
  654. const target = toRaw(this);
  655. const { has: has2, get: get2 } = getProto(target);
  656. let hadKey = has2.call(target, key);
  657. if (!hadKey) {
  658. key = toRaw(key);
  659. hadKey = has2.call(target, key);
  660. } else {
  661. checkIdentityKeys(target, has2, key);
  662. }
  663. const oldValue = get2 ? get2.call(target, key) : void 0;
  664. const result = target.delete(key);
  665. if (hadKey) {
  666. trigger(target, "delete", key, void 0, oldValue);
  667. }
  668. return result;
  669. }
  670. function clear() {
  671. const target = toRaw(this);
  672. const hadItems = target.size !== 0;
  673. const oldTarget = shared.isMap(target) ? new Map(target) : new Set(target) ;
  674. const result = target.clear();
  675. if (hadItems) {
  676. trigger(target, "clear", void 0, void 0, oldTarget);
  677. }
  678. return result;
  679. }
  680. function createForEach(isReadonly2, isShallow2) {
  681. return function forEach(callback, thisArg) {
  682. const observed = this;
  683. const target = observed["__v_raw"];
  684. const rawTarget = toRaw(target);
  685. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  686. !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
  687. return target.forEach((value, key) => {
  688. return callback.call(thisArg, wrap(value), wrap(key), observed);
  689. });
  690. };
  691. }
  692. function createIterableMethod(method, isReadonly2, isShallow2) {
  693. return function(...args) {
  694. const target = this["__v_raw"];
  695. const rawTarget = toRaw(target);
  696. const targetIsMap = shared.isMap(rawTarget);
  697. const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
  698. const isKeyOnly = method === "keys" && targetIsMap;
  699. const innerIterator = target[method](...args);
  700. const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
  701. !isReadonly2 && track(
  702. rawTarget,
  703. "iterate",
  704. isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
  705. );
  706. return {
  707. // iterator protocol
  708. next() {
  709. const { value, done } = innerIterator.next();
  710. return done ? { value, done } : {
  711. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  712. done
  713. };
  714. },
  715. // iterable protocol
  716. [Symbol.iterator]() {
  717. return this;
  718. }
  719. };
  720. };
  721. }
  722. function createReadonlyMethod(type) {
  723. return function(...args) {
  724. {
  725. const key = args[0] ? `on key "${args[0]}" ` : ``;
  726. warn(
  727. `${shared.capitalize(type)} operation ${key}failed: target is readonly.`,
  728. toRaw(this)
  729. );
  730. }
  731. return type === "delete" ? false : type === "clear" ? void 0 : this;
  732. };
  733. }
  734. function createInstrumentations() {
  735. const mutableInstrumentations2 = {
  736. get(key) {
  737. return get(this, key);
  738. },
  739. get size() {
  740. return size(this);
  741. },
  742. has,
  743. add,
  744. set,
  745. delete: deleteEntry,
  746. clear,
  747. forEach: createForEach(false, false)
  748. };
  749. const shallowInstrumentations2 = {
  750. get(key) {
  751. return get(this, key, false, true);
  752. },
  753. get size() {
  754. return size(this);
  755. },
  756. has,
  757. add(value) {
  758. return add.call(this, value, true);
  759. },
  760. set(key, value) {
  761. return set.call(this, key, value, true);
  762. },
  763. delete: deleteEntry,
  764. clear,
  765. forEach: createForEach(false, true)
  766. };
  767. const readonlyInstrumentations2 = {
  768. get(key) {
  769. return get(this, key, true);
  770. },
  771. get size() {
  772. return size(this, true);
  773. },
  774. has(key) {
  775. return has.call(this, key, true);
  776. },
  777. add: createReadonlyMethod("add"),
  778. set: createReadonlyMethod("set"),
  779. delete: createReadonlyMethod("delete"),
  780. clear: createReadonlyMethod("clear"),
  781. forEach: createForEach(true, false)
  782. };
  783. const shallowReadonlyInstrumentations2 = {
  784. get(key) {
  785. return get(this, key, true, true);
  786. },
  787. get size() {
  788. return size(this, true);
  789. },
  790. has(key) {
  791. return has.call(this, key, true);
  792. },
  793. add: createReadonlyMethod("add"),
  794. set: createReadonlyMethod("set"),
  795. delete: createReadonlyMethod("delete"),
  796. clear: createReadonlyMethod("clear"),
  797. forEach: createForEach(true, true)
  798. };
  799. const iteratorMethods = [
  800. "keys",
  801. "values",
  802. "entries",
  803. Symbol.iterator
  804. ];
  805. iteratorMethods.forEach((method) => {
  806. mutableInstrumentations2[method] = createIterableMethod(method, false, false);
  807. readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
  808. shallowInstrumentations2[method] = createIterableMethod(method, false, true);
  809. shallowReadonlyInstrumentations2[method] = createIterableMethod(
  810. method,
  811. true,
  812. true
  813. );
  814. });
  815. return [
  816. mutableInstrumentations2,
  817. readonlyInstrumentations2,
  818. shallowInstrumentations2,
  819. shallowReadonlyInstrumentations2
  820. ];
  821. }
  822. const [
  823. mutableInstrumentations,
  824. readonlyInstrumentations,
  825. shallowInstrumentations,
  826. shallowReadonlyInstrumentations
  827. ] = /* @__PURE__ */ createInstrumentations();
  828. function createInstrumentationGetter(isReadonly2, shallow) {
  829. const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
  830. return (target, key, receiver) => {
  831. if (key === "__v_isReactive") {
  832. return !isReadonly2;
  833. } else if (key === "__v_isReadonly") {
  834. return isReadonly2;
  835. } else if (key === "__v_raw") {
  836. return target;
  837. }
  838. return Reflect.get(
  839. shared.hasOwn(instrumentations, key) && key in target ? instrumentations : target,
  840. key,
  841. receiver
  842. );
  843. };
  844. }
  845. const mutableCollectionHandlers = {
  846. get: /* @__PURE__ */ createInstrumentationGetter(false, false)
  847. };
  848. const shallowCollectionHandlers = {
  849. get: /* @__PURE__ */ createInstrumentationGetter(false, true)
  850. };
  851. const readonlyCollectionHandlers = {
  852. get: /* @__PURE__ */ createInstrumentationGetter(true, false)
  853. };
  854. const shallowReadonlyCollectionHandlers = {
  855. get: /* @__PURE__ */ createInstrumentationGetter(true, true)
  856. };
  857. function checkIdentityKeys(target, has2, key) {
  858. const rawKey = toRaw(key);
  859. if (rawKey !== key && has2.call(target, rawKey)) {
  860. const type = shared.toRawType(target);
  861. warn(
  862. `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.`
  863. );
  864. }
  865. }
  866. const reactiveMap = /* @__PURE__ */ new WeakMap();
  867. const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
  868. const readonlyMap = /* @__PURE__ */ new WeakMap();
  869. const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
  870. function targetTypeMap(rawType) {
  871. switch (rawType) {
  872. case "Object":
  873. case "Array":
  874. return 1 /* COMMON */;
  875. case "Map":
  876. case "Set":
  877. case "WeakMap":
  878. case "WeakSet":
  879. return 2 /* COLLECTION */;
  880. default:
  881. return 0 /* INVALID */;
  882. }
  883. }
  884. function getTargetType(value) {
  885. return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(shared.toRawType(value));
  886. }
  887. function reactive(target) {
  888. if (isReadonly(target)) {
  889. return target;
  890. }
  891. return createReactiveObject(
  892. target,
  893. false,
  894. mutableHandlers,
  895. mutableCollectionHandlers,
  896. reactiveMap
  897. );
  898. }
  899. function shallowReactive(target) {
  900. return createReactiveObject(
  901. target,
  902. false,
  903. shallowReactiveHandlers,
  904. shallowCollectionHandlers,
  905. shallowReactiveMap
  906. );
  907. }
  908. function readonly(target) {
  909. return createReactiveObject(
  910. target,
  911. true,
  912. readonlyHandlers,
  913. readonlyCollectionHandlers,
  914. readonlyMap
  915. );
  916. }
  917. function shallowReadonly(target) {
  918. return createReactiveObject(
  919. target,
  920. true,
  921. shallowReadonlyHandlers,
  922. shallowReadonlyCollectionHandlers,
  923. shallowReadonlyMap
  924. );
  925. }
  926. function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
  927. if (!shared.isObject(target)) {
  928. {
  929. warn(
  930. `value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(
  931. target
  932. )}`
  933. );
  934. }
  935. return target;
  936. }
  937. if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
  938. return target;
  939. }
  940. const existingProxy = proxyMap.get(target);
  941. if (existingProxy) {
  942. return existingProxy;
  943. }
  944. const targetType = getTargetType(target);
  945. if (targetType === 0 /* INVALID */) {
  946. return target;
  947. }
  948. const proxy = new Proxy(
  949. target,
  950. targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
  951. );
  952. proxyMap.set(target, proxy);
  953. return proxy;
  954. }
  955. function isReactive(value) {
  956. if (isReadonly(value)) {
  957. return isReactive(value["__v_raw"]);
  958. }
  959. return !!(value && value["__v_isReactive"]);
  960. }
  961. function isReadonly(value) {
  962. return !!(value && value["__v_isReadonly"]);
  963. }
  964. function isShallow(value) {
  965. return !!(value && value["__v_isShallow"]);
  966. }
  967. function isProxy(value) {
  968. return value ? !!value["__v_raw"] : false;
  969. }
  970. function toRaw(observed) {
  971. const raw = observed && observed["__v_raw"];
  972. return raw ? toRaw(raw) : observed;
  973. }
  974. function markRaw(value) {
  975. if (Object.isExtensible(value)) {
  976. shared.def(value, "__v_skip", true);
  977. }
  978. return value;
  979. }
  980. const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
  981. const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
  982. const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
  983. class ComputedRefImpl {
  984. constructor(getter, _setter, isReadonly, isSSR) {
  985. this.getter = getter;
  986. this._setter = _setter;
  987. this.dep = void 0;
  988. this.__v_isRef = true;
  989. this["__v_isReadonly"] = false;
  990. this.effect = new ReactiveEffect(
  991. () => getter(this._value),
  992. () => triggerRefValue(
  993. this,
  994. this.effect._dirtyLevel === 2 ? 2 : 3
  995. )
  996. );
  997. this.effect.computed = this;
  998. this.effect.active = this._cacheable = !isSSR;
  999. this["__v_isReadonly"] = isReadonly;
  1000. }
  1001. get value() {
  1002. const self = toRaw(this);
  1003. if ((!self._cacheable || self.effect.dirty) && shared.hasChanged(self._value, self._value = self.effect.run())) {
  1004. triggerRefValue(self, 4);
  1005. }
  1006. trackRefValue(self);
  1007. if (self.effect._dirtyLevel >= 2) {
  1008. if (this._warnRecursive) {
  1009. warn(COMPUTED_SIDE_EFFECT_WARN, `
  1010. getter: `, this.getter);
  1011. }
  1012. triggerRefValue(self, 2);
  1013. }
  1014. return self._value;
  1015. }
  1016. set value(newValue) {
  1017. this._setter(newValue);
  1018. }
  1019. // #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
  1020. get _dirty() {
  1021. return this.effect.dirty;
  1022. }
  1023. set _dirty(v) {
  1024. this.effect.dirty = v;
  1025. }
  1026. // #endregion
  1027. }
  1028. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1029. let getter;
  1030. let setter;
  1031. const onlyGetter = shared.isFunction(getterOrOptions);
  1032. if (onlyGetter) {
  1033. getter = getterOrOptions;
  1034. setter = () => {
  1035. warn("Write operation failed: computed value is readonly");
  1036. } ;
  1037. } else {
  1038. getter = getterOrOptions.get;
  1039. setter = getterOrOptions.set;
  1040. }
  1041. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1042. if (debugOptions && !isSSR) {
  1043. cRef.effect.onTrack = debugOptions.onTrack;
  1044. cRef.effect.onTrigger = debugOptions.onTrigger;
  1045. }
  1046. return cRef;
  1047. }
  1048. function trackRefValue(ref2) {
  1049. var _a;
  1050. if (shouldTrack && activeEffect) {
  1051. ref2 = toRaw(ref2);
  1052. trackEffect(
  1053. activeEffect,
  1054. (_a = ref2.dep) != null ? _a : ref2.dep = createDep(
  1055. () => ref2.dep = void 0,
  1056. ref2 instanceof ComputedRefImpl ? ref2 : void 0
  1057. ),
  1058. {
  1059. target: ref2,
  1060. type: "get",
  1061. key: "value"
  1062. }
  1063. );
  1064. }
  1065. }
  1066. function triggerRefValue(ref2, dirtyLevel = 4, newVal, oldVal) {
  1067. ref2 = toRaw(ref2);
  1068. const dep = ref2.dep;
  1069. if (dep) {
  1070. triggerEffects(
  1071. dep,
  1072. dirtyLevel,
  1073. {
  1074. target: ref2,
  1075. type: "set",
  1076. key: "value",
  1077. newValue: newVal,
  1078. oldValue: oldVal
  1079. }
  1080. );
  1081. }
  1082. }
  1083. function isRef(r) {
  1084. return !!(r && r.__v_isRef === true);
  1085. }
  1086. function ref(value) {
  1087. return createRef(value, false);
  1088. }
  1089. function shallowRef(value) {
  1090. return createRef(value, true);
  1091. }
  1092. function createRef(rawValue, shallow) {
  1093. if (isRef(rawValue)) {
  1094. return rawValue;
  1095. }
  1096. return new RefImpl(rawValue, shallow);
  1097. }
  1098. class RefImpl {
  1099. constructor(value, __v_isShallow) {
  1100. this.__v_isShallow = __v_isShallow;
  1101. this.dep = void 0;
  1102. this.__v_isRef = true;
  1103. this._rawValue = __v_isShallow ? value : toRaw(value);
  1104. this._value = __v_isShallow ? value : toReactive(value);
  1105. }
  1106. get value() {
  1107. trackRefValue(this);
  1108. return this._value;
  1109. }
  1110. set value(newVal) {
  1111. const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
  1112. newVal = useDirectValue ? newVal : toRaw(newVal);
  1113. if (shared.hasChanged(newVal, this._rawValue)) {
  1114. const oldVal = this._rawValue;
  1115. this._rawValue = newVal;
  1116. this._value = useDirectValue ? newVal : toReactive(newVal);
  1117. triggerRefValue(this, 4, newVal, oldVal);
  1118. }
  1119. }
  1120. }
  1121. function triggerRef(ref2) {
  1122. triggerRefValue(ref2, 4, ref2.value );
  1123. }
  1124. function unref(ref2) {
  1125. return isRef(ref2) ? ref2.value : ref2;
  1126. }
  1127. function toValue(source) {
  1128. return shared.isFunction(source) ? source() : unref(source);
  1129. }
  1130. const shallowUnwrapHandlers = {
  1131. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1132. set: (target, key, value, receiver) => {
  1133. const oldValue = target[key];
  1134. if (isRef(oldValue) && !isRef(value)) {
  1135. oldValue.value = value;
  1136. return true;
  1137. } else {
  1138. return Reflect.set(target, key, value, receiver);
  1139. }
  1140. }
  1141. };
  1142. function proxyRefs(objectWithRefs) {
  1143. return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1144. }
  1145. class CustomRefImpl {
  1146. constructor(factory) {
  1147. this.dep = void 0;
  1148. this.__v_isRef = true;
  1149. const { get, set } = factory(
  1150. () => trackRefValue(this),
  1151. () => triggerRefValue(this)
  1152. );
  1153. this._get = get;
  1154. this._set = set;
  1155. }
  1156. get value() {
  1157. return this._get();
  1158. }
  1159. set value(newVal) {
  1160. this._set(newVal);
  1161. }
  1162. }
  1163. function customRef(factory) {
  1164. return new CustomRefImpl(factory);
  1165. }
  1166. function toRefs(object) {
  1167. if (!isProxy(object)) {
  1168. warn(`toRefs() expects a reactive object but received a plain one.`);
  1169. }
  1170. const ret = shared.isArray(object) ? new Array(object.length) : {};
  1171. for (const key in object) {
  1172. ret[key] = propertyToRef(object, key);
  1173. }
  1174. return ret;
  1175. }
  1176. class ObjectRefImpl {
  1177. constructor(_object, _key, _defaultValue) {
  1178. this._object = _object;
  1179. this._key = _key;
  1180. this._defaultValue = _defaultValue;
  1181. this.__v_isRef = true;
  1182. }
  1183. get value() {
  1184. const val = this._object[this._key];
  1185. return val === void 0 ? this._defaultValue : val;
  1186. }
  1187. set value(newVal) {
  1188. this._object[this._key] = newVal;
  1189. }
  1190. get dep() {
  1191. return getDepFromReactive(toRaw(this._object), this._key);
  1192. }
  1193. }
  1194. class GetterRefImpl {
  1195. constructor(_getter) {
  1196. this._getter = _getter;
  1197. this.__v_isRef = true;
  1198. this.__v_isReadonly = true;
  1199. }
  1200. get value() {
  1201. return this._getter();
  1202. }
  1203. }
  1204. function toRef(source, key, defaultValue) {
  1205. if (isRef(source)) {
  1206. return source;
  1207. } else if (shared.isFunction(source)) {
  1208. return new GetterRefImpl(source);
  1209. } else if (shared.isObject(source) && arguments.length > 1) {
  1210. return propertyToRef(source, key, defaultValue);
  1211. } else {
  1212. return ref(source);
  1213. }
  1214. }
  1215. function propertyToRef(source, key, defaultValue) {
  1216. const val = source[key];
  1217. return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
  1218. }
  1219. const deferredComputed = computed;
  1220. const TrackOpTypes = {
  1221. "GET": "get",
  1222. "HAS": "has",
  1223. "ITERATE": "iterate"
  1224. };
  1225. const TriggerOpTypes = {
  1226. "SET": "set",
  1227. "ADD": "add",
  1228. "DELETE": "delete",
  1229. "CLEAR": "clear"
  1230. };
  1231. const ReactiveFlags = {
  1232. "SKIP": "__v_skip",
  1233. "IS_REACTIVE": "__v_isReactive",
  1234. "IS_READONLY": "__v_isReadonly",
  1235. "IS_SHALLOW": "__v_isShallow",
  1236. "RAW": "__v_raw"
  1237. };
  1238. exports.EffectScope = EffectScope;
  1239. exports.ITERATE_KEY = ITERATE_KEY;
  1240. exports.ReactiveEffect = ReactiveEffect;
  1241. exports.ReactiveFlags = ReactiveFlags;
  1242. exports.TrackOpTypes = TrackOpTypes;
  1243. exports.TriggerOpTypes = TriggerOpTypes;
  1244. exports.computed = computed;
  1245. exports.customRef = customRef;
  1246. exports.deferredComputed = deferredComputed;
  1247. exports.effect = effect;
  1248. exports.effectScope = effectScope;
  1249. exports.enableTracking = enableTracking;
  1250. exports.getCurrentScope = getCurrentScope;
  1251. exports.isProxy = isProxy;
  1252. exports.isReactive = isReactive;
  1253. exports.isReadonly = isReadonly;
  1254. exports.isRef = isRef;
  1255. exports.isShallow = isShallow;
  1256. exports.markRaw = markRaw;
  1257. exports.onScopeDispose = onScopeDispose;
  1258. exports.pauseScheduling = pauseScheduling;
  1259. exports.pauseTracking = pauseTracking;
  1260. exports.proxyRefs = proxyRefs;
  1261. exports.reactive = reactive;
  1262. exports.readonly = readonly;
  1263. exports.ref = ref;
  1264. exports.resetScheduling = resetScheduling;
  1265. exports.resetTracking = resetTracking;
  1266. exports.shallowReactive = shallowReactive;
  1267. exports.shallowReadonly = shallowReadonly;
  1268. exports.shallowRef = shallowRef;
  1269. exports.stop = stop;
  1270. exports.toRaw = toRaw;
  1271. exports.toRef = toRef;
  1272. exports.toRefs = toRefs;
  1273. exports.toValue = toValue;
  1274. exports.track = track;
  1275. exports.trigger = trigger;
  1276. exports.triggerRef = triggerRef;
  1277. exports.unref = unref;