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.prod.js 32KB

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