d71a8e072de325213d83144d4a72bf30f4dbf65edbf42d14f5e9aeef4af20a8e2c19fd8f32dd5fd2dcad3dccb083fc3954fa5cd89838da349764b96937ba60 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695
  1. 'use strict';
  2. var vueDemi = require('vue-demi');
  3. function computedEager(fn, options) {
  4. var _a;
  5. const result = vueDemi.shallowRef();
  6. vueDemi.watchEffect(() => {
  7. result.value = fn();
  8. }, {
  9. ...options,
  10. flush: (_a = options == null ? void 0 : options.flush) != null ? _a : "sync"
  11. });
  12. return vueDemi.readonly(result);
  13. }
  14. function computedWithControl(source, fn) {
  15. let v = void 0;
  16. let track;
  17. let trigger;
  18. const dirty = vueDemi.ref(true);
  19. const update = () => {
  20. dirty.value = true;
  21. trigger();
  22. };
  23. vueDemi.watch(source, update, { flush: "sync" });
  24. const get = typeof fn === "function" ? fn : fn.get;
  25. const set = typeof fn === "function" ? void 0 : fn.set;
  26. const result = vueDemi.customRef((_track, _trigger) => {
  27. track = _track;
  28. trigger = _trigger;
  29. return {
  30. get() {
  31. if (dirty.value) {
  32. v = get();
  33. dirty.value = false;
  34. }
  35. track();
  36. return v;
  37. },
  38. set(v2) {
  39. set == null ? void 0 : set(v2);
  40. }
  41. };
  42. });
  43. if (Object.isExtensible(result))
  44. result.trigger = update;
  45. return result;
  46. }
  47. function tryOnScopeDispose(fn) {
  48. if (vueDemi.getCurrentScope()) {
  49. vueDemi.onScopeDispose(fn);
  50. return true;
  51. }
  52. return false;
  53. }
  54. function createEventHook() {
  55. const fns = /* @__PURE__ */ new Set();
  56. const off = (fn) => {
  57. fns.delete(fn);
  58. };
  59. const on = (fn) => {
  60. fns.add(fn);
  61. const offFn = () => off(fn);
  62. tryOnScopeDispose(offFn);
  63. return {
  64. off: offFn
  65. };
  66. };
  67. const trigger = (...args) => {
  68. return Promise.all(Array.from(fns).map((fn) => fn(...args)));
  69. };
  70. return {
  71. on,
  72. off,
  73. trigger
  74. };
  75. }
  76. function createGlobalState(stateFactory) {
  77. let initialized = false;
  78. let state;
  79. const scope = vueDemi.effectScope(true);
  80. return (...args) => {
  81. if (!initialized) {
  82. state = scope.run(() => stateFactory(...args));
  83. initialized = true;
  84. }
  85. return state;
  86. };
  87. }
  88. const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
  89. const provideLocal = (key, value) => {
  90. var _a;
  91. const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
  92. if (instance == null)
  93. throw new Error("provideLocal must be called in setup");
  94. if (!localProvidedStateMap.has(instance))
  95. localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
  96. const localProvidedState = localProvidedStateMap.get(instance);
  97. localProvidedState[key] = value;
  98. vueDemi.provide(key, value);
  99. };
  100. const injectLocal = (...args) => {
  101. var _a;
  102. const key = args[0];
  103. const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
  104. if (instance == null)
  105. throw new Error("injectLocal must be called in setup");
  106. if (localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
  107. return localProvidedStateMap.get(instance)[key];
  108. return vueDemi.inject(...args);
  109. };
  110. function createInjectionState(composable, options) {
  111. const key = (options == null ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
  112. const defaultValue = options == null ? void 0 : options.defaultValue;
  113. const useProvidingState = (...args) => {
  114. const state = composable(...args);
  115. provideLocal(key, state);
  116. return state;
  117. };
  118. const useInjectedState = () => injectLocal(key, defaultValue);
  119. return [useProvidingState, useInjectedState];
  120. }
  121. function createSharedComposable(composable) {
  122. let subscribers = 0;
  123. let state;
  124. let scope;
  125. const dispose = () => {
  126. subscribers -= 1;
  127. if (scope && subscribers <= 0) {
  128. scope.stop();
  129. state = void 0;
  130. scope = void 0;
  131. }
  132. };
  133. return (...args) => {
  134. subscribers += 1;
  135. if (!state) {
  136. scope = vueDemi.effectScope(true);
  137. state = scope.run(() => composable(...args));
  138. }
  139. tryOnScopeDispose(dispose);
  140. return state;
  141. };
  142. }
  143. function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
  144. if (!vueDemi.isVue3 && !vueDemi.version.startsWith("2.7.")) {
  145. if (process.env.NODE_ENV !== "production")
  146. throw new Error("[VueUse] extendRef only works in Vue 2.7 or above.");
  147. return;
  148. }
  149. for (const [key, value] of Object.entries(extend)) {
  150. if (key === "value")
  151. continue;
  152. if (vueDemi.isRef(value) && unwrap) {
  153. Object.defineProperty(ref, key, {
  154. get() {
  155. return value.value;
  156. },
  157. set(v) {
  158. value.value = v;
  159. },
  160. enumerable
  161. });
  162. } else {
  163. Object.defineProperty(ref, key, { value, enumerable });
  164. }
  165. }
  166. return ref;
  167. }
  168. function get(obj, key) {
  169. if (key == null)
  170. return vueDemi.unref(obj);
  171. return vueDemi.unref(obj)[key];
  172. }
  173. function isDefined(v) {
  174. return vueDemi.unref(v) != null;
  175. }
  176. function makeDestructurable(obj, arr) {
  177. if (typeof Symbol !== "undefined") {
  178. const clone = { ...obj };
  179. Object.defineProperty(clone, Symbol.iterator, {
  180. enumerable: false,
  181. value() {
  182. let index = 0;
  183. return {
  184. next: () => ({
  185. value: arr[index++],
  186. done: index > arr.length
  187. })
  188. };
  189. }
  190. });
  191. return clone;
  192. } else {
  193. return Object.assign([...arr], obj);
  194. }
  195. }
  196. function toValue(r) {
  197. return typeof r === "function" ? r() : vueDemi.unref(r);
  198. }
  199. const resolveUnref = toValue;
  200. function reactify(fn, options) {
  201. const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vueDemi.unref : toValue;
  202. return function(...args) {
  203. return vueDemi.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
  204. };
  205. }
  206. function reactifyObject(obj, optionsOrKeys = {}) {
  207. let keys = [];
  208. let options;
  209. if (Array.isArray(optionsOrKeys)) {
  210. keys = optionsOrKeys;
  211. } else {
  212. options = optionsOrKeys;
  213. const { includeOwnProperties = true } = optionsOrKeys;
  214. keys.push(...Object.keys(obj));
  215. if (includeOwnProperties)
  216. keys.push(...Object.getOwnPropertyNames(obj));
  217. }
  218. return Object.fromEntries(
  219. keys.map((key) => {
  220. const value = obj[key];
  221. return [
  222. key,
  223. typeof value === "function" ? reactify(value.bind(obj), options) : value
  224. ];
  225. })
  226. );
  227. }
  228. function toReactive(objectRef) {
  229. if (!vueDemi.isRef(objectRef))
  230. return vueDemi.reactive(objectRef);
  231. const proxy = new Proxy({}, {
  232. get(_, p, receiver) {
  233. return vueDemi.unref(Reflect.get(objectRef.value, p, receiver));
  234. },
  235. set(_, p, value) {
  236. if (vueDemi.isRef(objectRef.value[p]) && !vueDemi.isRef(value))
  237. objectRef.value[p].value = value;
  238. else
  239. objectRef.value[p] = value;
  240. return true;
  241. },
  242. deleteProperty(_, p) {
  243. return Reflect.deleteProperty(objectRef.value, p);
  244. },
  245. has(_, p) {
  246. return Reflect.has(objectRef.value, p);
  247. },
  248. ownKeys() {
  249. return Object.keys(objectRef.value);
  250. },
  251. getOwnPropertyDescriptor() {
  252. return {
  253. enumerable: true,
  254. configurable: true
  255. };
  256. }
  257. });
  258. return vueDemi.reactive(proxy);
  259. }
  260. function reactiveComputed(fn) {
  261. return toReactive(vueDemi.computed(fn));
  262. }
  263. function reactiveOmit(obj, ...keys) {
  264. const flatKeys = keys.flat();
  265. const predicate = flatKeys[0];
  266. return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
  267. }
  268. const isClient = typeof window !== "undefined" && typeof document !== "undefined";
  269. const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
  270. const isDef = (val) => typeof val !== "undefined";
  271. const notNullish = (val) => val != null;
  272. const assert = (condition, ...infos) => {
  273. if (!condition)
  274. console.warn(...infos);
  275. };
  276. const toString = Object.prototype.toString;
  277. const isObject = (val) => toString.call(val) === "[object Object]";
  278. const now = () => Date.now();
  279. const timestamp = () => +Date.now();
  280. const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
  281. const noop = () => {
  282. };
  283. const rand = (min, max) => {
  284. min = Math.ceil(min);
  285. max = Math.floor(max);
  286. return Math.floor(Math.random() * (max - min + 1)) + min;
  287. };
  288. const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
  289. const isIOS = /* @__PURE__ */ getIsIOS();
  290. function getIsIOS() {
  291. var _a, _b;
  292. return isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? void 0 : window.navigator) == null ? void 0 : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? void 0 : window.navigator.userAgent));
  293. }
  294. function createFilterWrapper(filter, fn) {
  295. function wrapper(...args) {
  296. return new Promise((resolve, reject) => {
  297. Promise.resolve(filter(() => fn.apply(this, args), { fn, thisArg: this, args })).then(resolve).catch(reject);
  298. });
  299. }
  300. return wrapper;
  301. }
  302. const bypassFilter = (invoke) => {
  303. return invoke();
  304. };
  305. function debounceFilter(ms, options = {}) {
  306. let timer;
  307. let maxTimer;
  308. let lastRejector = noop;
  309. const _clearTimeout = (timer2) => {
  310. clearTimeout(timer2);
  311. lastRejector();
  312. lastRejector = noop;
  313. };
  314. const filter = (invoke) => {
  315. const duration = toValue(ms);
  316. const maxDuration = toValue(options.maxWait);
  317. if (timer)
  318. _clearTimeout(timer);
  319. if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
  320. if (maxTimer) {
  321. _clearTimeout(maxTimer);
  322. maxTimer = null;
  323. }
  324. return Promise.resolve(invoke());
  325. }
  326. return new Promise((resolve, reject) => {
  327. lastRejector = options.rejectOnCancel ? reject : resolve;
  328. if (maxDuration && !maxTimer) {
  329. maxTimer = setTimeout(() => {
  330. if (timer)
  331. _clearTimeout(timer);
  332. maxTimer = null;
  333. resolve(invoke());
  334. }, maxDuration);
  335. }
  336. timer = setTimeout(() => {
  337. if (maxTimer)
  338. _clearTimeout(maxTimer);
  339. maxTimer = null;
  340. resolve(invoke());
  341. }, duration);
  342. });
  343. };
  344. return filter;
  345. }
  346. function throttleFilter(...args) {
  347. let lastExec = 0;
  348. let timer;
  349. let isLeading = true;
  350. let lastRejector = noop;
  351. let lastValue;
  352. let ms;
  353. let trailing;
  354. let leading;
  355. let rejectOnCancel;
  356. if (!vueDemi.isRef(args[0]) && typeof args[0] === "object")
  357. ({ delay: ms, trailing = true, leading = true, rejectOnCancel = false } = args[0]);
  358. else
  359. [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
  360. const clear = () => {
  361. if (timer) {
  362. clearTimeout(timer);
  363. timer = void 0;
  364. lastRejector();
  365. lastRejector = noop;
  366. }
  367. };
  368. const filter = (_invoke) => {
  369. const duration = toValue(ms);
  370. const elapsed = Date.now() - lastExec;
  371. const invoke = () => {
  372. return lastValue = _invoke();
  373. };
  374. clear();
  375. if (duration <= 0) {
  376. lastExec = Date.now();
  377. return invoke();
  378. }
  379. if (elapsed > duration && (leading || !isLeading)) {
  380. lastExec = Date.now();
  381. invoke();
  382. } else if (trailing) {
  383. lastValue = new Promise((resolve, reject) => {
  384. lastRejector = rejectOnCancel ? reject : resolve;
  385. timer = setTimeout(() => {
  386. lastExec = Date.now();
  387. isLeading = true;
  388. resolve(invoke());
  389. clear();
  390. }, Math.max(0, duration - elapsed));
  391. });
  392. }
  393. if (!leading && !timer)
  394. timer = setTimeout(() => isLeading = true, duration);
  395. isLeading = false;
  396. return lastValue;
  397. };
  398. return filter;
  399. }
  400. function pausableFilter(extendFilter = bypassFilter) {
  401. const isActive = vueDemi.ref(true);
  402. function pause() {
  403. isActive.value = false;
  404. }
  405. function resume() {
  406. isActive.value = true;
  407. }
  408. const eventFilter = (...args) => {
  409. if (isActive.value)
  410. extendFilter(...args);
  411. };
  412. return { isActive: vueDemi.readonly(isActive), pause, resume, eventFilter };
  413. }
  414. const directiveHooks = {
  415. mounted: vueDemi.isVue3 ? "mounted" : "inserted",
  416. updated: vueDemi.isVue3 ? "updated" : "componentUpdated",
  417. unmounted: vueDemi.isVue3 ? "unmounted" : "unbind"
  418. };
  419. function cacheStringFunction(fn) {
  420. const cache = /* @__PURE__ */ Object.create(null);
  421. return (str) => {
  422. const hit = cache[str];
  423. return hit || (cache[str] = fn(str));
  424. };
  425. }
  426. const hyphenateRE = /\B([A-Z])/g;
  427. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
  428. const camelizeRE = /-(\w)/g;
  429. const camelize = cacheStringFunction((str) => {
  430. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  431. });
  432. function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
  433. return new Promise((resolve, reject) => {
  434. if (throwOnTimeout)
  435. setTimeout(() => reject(reason), ms);
  436. else
  437. setTimeout(resolve, ms);
  438. });
  439. }
  440. function identity(arg) {
  441. return arg;
  442. }
  443. function createSingletonPromise(fn) {
  444. let _promise;
  445. function wrapper() {
  446. if (!_promise)
  447. _promise = fn();
  448. return _promise;
  449. }
  450. wrapper.reset = async () => {
  451. const _prev = _promise;
  452. _promise = void 0;
  453. if (_prev)
  454. await _prev;
  455. };
  456. return wrapper;
  457. }
  458. function invoke(fn) {
  459. return fn();
  460. }
  461. function containsProp(obj, ...props) {
  462. return props.some((k) => k in obj);
  463. }
  464. function increaseWithUnit(target, delta) {
  465. var _a;
  466. if (typeof target === "number")
  467. return target + delta;
  468. const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? void 0 : _a[0]) || "";
  469. const unit = target.slice(value.length);
  470. const result = Number.parseFloat(value) + delta;
  471. if (Number.isNaN(result))
  472. return target;
  473. return result + unit;
  474. }
  475. function objectPick(obj, keys, omitUndefined = false) {
  476. return keys.reduce((n, k) => {
  477. if (k in obj) {
  478. if (!omitUndefined || obj[k] !== void 0)
  479. n[k] = obj[k];
  480. }
  481. return n;
  482. }, {});
  483. }
  484. function objectOmit(obj, keys, omitUndefined = false) {
  485. return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
  486. return (!omitUndefined || value !== void 0) && !keys.includes(key);
  487. }));
  488. }
  489. function objectEntries(obj) {
  490. return Object.entries(obj);
  491. }
  492. function getLifeCycleTarget(target) {
  493. return target || vueDemi.getCurrentInstance();
  494. }
  495. function toRef(...args) {
  496. if (args.length !== 1)
  497. return vueDemi.toRef(...args);
  498. const r = args[0];
  499. return typeof r === "function" ? vueDemi.readonly(vueDemi.customRef(() => ({ get: r, set: noop }))) : vueDemi.ref(r);
  500. }
  501. const resolveRef = toRef;
  502. function reactivePick(obj, ...keys) {
  503. const flatKeys = keys.flat();
  504. const predicate = flatKeys[0];
  505. return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
  506. }
  507. function refAutoReset(defaultValue, afterMs = 1e4) {
  508. return vueDemi.customRef((track, trigger) => {
  509. let value = toValue(defaultValue);
  510. let timer;
  511. const resetAfter = () => setTimeout(() => {
  512. value = toValue(defaultValue);
  513. trigger();
  514. }, toValue(afterMs));
  515. tryOnScopeDispose(() => {
  516. clearTimeout(timer);
  517. });
  518. return {
  519. get() {
  520. track();
  521. return value;
  522. },
  523. set(newValue) {
  524. value = newValue;
  525. trigger();
  526. clearTimeout(timer);
  527. timer = resetAfter();
  528. }
  529. };
  530. });
  531. }
  532. function useDebounceFn(fn, ms = 200, options = {}) {
  533. return createFilterWrapper(
  534. debounceFilter(ms, options),
  535. fn
  536. );
  537. }
  538. function refDebounced(value, ms = 200, options = {}) {
  539. const debounced = vueDemi.ref(value.value);
  540. const updater = useDebounceFn(() => {
  541. debounced.value = value.value;
  542. }, ms, options);
  543. vueDemi.watch(value, () => updater());
  544. return debounced;
  545. }
  546. function refDefault(source, defaultValue) {
  547. return vueDemi.computed({
  548. get() {
  549. var _a;
  550. return (_a = source.value) != null ? _a : defaultValue;
  551. },
  552. set(value) {
  553. source.value = value;
  554. }
  555. });
  556. }
  557. function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
  558. return createFilterWrapper(
  559. throttleFilter(ms, trailing, leading, rejectOnCancel),
  560. fn
  561. );
  562. }
  563. function refThrottled(value, delay = 200, trailing = true, leading = true) {
  564. if (delay <= 0)
  565. return value;
  566. const throttled = vueDemi.ref(value.value);
  567. const updater = useThrottleFn(() => {
  568. throttled.value = value.value;
  569. }, delay, trailing, leading);
  570. vueDemi.watch(value, () => updater());
  571. return throttled;
  572. }
  573. function refWithControl(initial, options = {}) {
  574. let source = initial;
  575. let track;
  576. let trigger;
  577. const ref = vueDemi.customRef((_track, _trigger) => {
  578. track = _track;
  579. trigger = _trigger;
  580. return {
  581. get() {
  582. return get();
  583. },
  584. set(v) {
  585. set(v);
  586. }
  587. };
  588. });
  589. function get(tracking = true) {
  590. if (tracking)
  591. track();
  592. return source;
  593. }
  594. function set(value, triggering = true) {
  595. var _a, _b;
  596. if (value === source)
  597. return;
  598. const old = source;
  599. if (((_a = options.onBeforeChange) == null ? void 0 : _a.call(options, value, old)) === false)
  600. return;
  601. source = value;
  602. (_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
  603. if (triggering)
  604. trigger();
  605. }
  606. const untrackedGet = () => get(false);
  607. const silentSet = (v) => set(v, false);
  608. const peek = () => get(false);
  609. const lay = (v) => set(v, false);
  610. return extendRef(
  611. ref,
  612. {
  613. get,
  614. set,
  615. untrackedGet,
  616. silentSet,
  617. peek,
  618. lay
  619. },
  620. { enumerable: true }
  621. );
  622. }
  623. const controlledRef = refWithControl;
  624. function set(...args) {
  625. if (args.length === 2) {
  626. const [ref, value] = args;
  627. ref.value = value;
  628. }
  629. if (args.length === 3) {
  630. if (vueDemi.isVue2) {
  631. vueDemi.set(...args);
  632. } else {
  633. const [target, key, value] = args;
  634. target[key] = value;
  635. }
  636. }
  637. }
  638. function watchWithFilter(source, cb, options = {}) {
  639. const {
  640. eventFilter = bypassFilter,
  641. ...watchOptions
  642. } = options;
  643. return vueDemi.watch(
  644. source,
  645. createFilterWrapper(
  646. eventFilter,
  647. cb
  648. ),
  649. watchOptions
  650. );
  651. }
  652. function watchPausable(source, cb, options = {}) {
  653. const {
  654. eventFilter: filter,
  655. ...watchOptions
  656. } = options;
  657. const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
  658. const stop = watchWithFilter(
  659. source,
  660. cb,
  661. {
  662. ...watchOptions,
  663. eventFilter
  664. }
  665. );
  666. return { stop, pause, resume, isActive };
  667. }
  668. function syncRef(left, right, ...[options]) {
  669. const {
  670. flush = "sync",
  671. deep = false,
  672. immediate = true,
  673. direction = "both",
  674. transform = {}
  675. } = options || {};
  676. const watchers = [];
  677. const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
  678. const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
  679. if (direction === "both" || direction === "ltr") {
  680. watchers.push(watchPausable(
  681. left,
  682. (newValue) => {
  683. watchers.forEach((w) => w.pause());
  684. right.value = transformLTR(newValue);
  685. watchers.forEach((w) => w.resume());
  686. },
  687. { flush, deep, immediate }
  688. ));
  689. }
  690. if (direction === "both" || direction === "rtl") {
  691. watchers.push(watchPausable(
  692. right,
  693. (newValue) => {
  694. watchers.forEach((w) => w.pause());
  695. left.value = transformRTL(newValue);
  696. watchers.forEach((w) => w.resume());
  697. },
  698. { flush, deep, immediate }
  699. ));
  700. }
  701. const stop = () => {
  702. watchers.forEach((w) => w.stop());
  703. };
  704. return stop;
  705. }
  706. function syncRefs(source, targets, options = {}) {
  707. const {
  708. flush = "sync",
  709. deep = false,
  710. immediate = true
  711. } = options;
  712. if (!Array.isArray(targets))
  713. targets = [targets];
  714. return vueDemi.watch(
  715. source,
  716. (newValue) => targets.forEach((target) => target.value = newValue),
  717. { flush, deep, immediate }
  718. );
  719. }
  720. function toRefs(objectRef, options = {}) {
  721. if (!vueDemi.isRef(objectRef))
  722. return vueDemi.toRefs(objectRef);
  723. const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
  724. for (const key in objectRef.value) {
  725. result[key] = vueDemi.customRef(() => ({
  726. get() {
  727. return objectRef.value[key];
  728. },
  729. set(v) {
  730. var _a;
  731. const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
  732. if (replaceRef) {
  733. if (Array.isArray(objectRef.value)) {
  734. const copy = [...objectRef.value];
  735. copy[key] = v;
  736. objectRef.value = copy;
  737. } else {
  738. const newObject = { ...objectRef.value, [key]: v };
  739. Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
  740. objectRef.value = newObject;
  741. }
  742. } else {
  743. objectRef.value[key] = v;
  744. }
  745. }
  746. }));
  747. }
  748. return result;
  749. }
  750. function tryOnBeforeMount(fn, sync = true, target) {
  751. const instance = getLifeCycleTarget(target);
  752. if (instance)
  753. vueDemi.onBeforeMount(fn, target);
  754. else if (sync)
  755. fn();
  756. else
  757. vueDemi.nextTick(fn);
  758. }
  759. function tryOnBeforeUnmount(fn, target) {
  760. const instance = getLifeCycleTarget(target);
  761. if (instance)
  762. vueDemi.onBeforeUnmount(fn, target);
  763. }
  764. function tryOnMounted(fn, sync = true, target) {
  765. const instance = getLifeCycleTarget();
  766. if (instance)
  767. vueDemi.onMounted(fn, target);
  768. else if (sync)
  769. fn();
  770. else
  771. vueDemi.nextTick(fn);
  772. }
  773. function tryOnUnmounted(fn, target) {
  774. const instance = getLifeCycleTarget(target);
  775. if (instance)
  776. vueDemi.onUnmounted(fn, target);
  777. }
  778. function createUntil(r, isNot = false) {
  779. function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
  780. let stop = null;
  781. const watcher = new Promise((resolve) => {
  782. stop = vueDemi.watch(
  783. r,
  784. (v) => {
  785. if (condition(v) !== isNot) {
  786. stop == null ? void 0 : stop();
  787. resolve(v);
  788. }
  789. },
  790. {
  791. flush,
  792. deep,
  793. immediate: true
  794. }
  795. );
  796. });
  797. const promises = [watcher];
  798. if (timeout != null) {
  799. promises.push(
  800. promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
  801. );
  802. }
  803. return Promise.race(promises);
  804. }
  805. function toBe(value, options) {
  806. if (!vueDemi.isRef(value))
  807. return toMatch((v) => v === value, options);
  808. const { flush = "sync", deep = false, timeout, throwOnTimeout } = options != null ? options : {};
  809. let stop = null;
  810. const watcher = new Promise((resolve) => {
  811. stop = vueDemi.watch(
  812. [r, value],
  813. ([v1, v2]) => {
  814. if (isNot !== (v1 === v2)) {
  815. stop == null ? void 0 : stop();
  816. resolve(v1);
  817. }
  818. },
  819. {
  820. flush,
  821. deep,
  822. immediate: true
  823. }
  824. );
  825. });
  826. const promises = [watcher];
  827. if (timeout != null) {
  828. promises.push(
  829. promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
  830. stop == null ? void 0 : stop();
  831. return toValue(r);
  832. })
  833. );
  834. }
  835. return Promise.race(promises);
  836. }
  837. function toBeTruthy(options) {
  838. return toMatch((v) => Boolean(v), options);
  839. }
  840. function toBeNull(options) {
  841. return toBe(null, options);
  842. }
  843. function toBeUndefined(options) {
  844. return toBe(void 0, options);
  845. }
  846. function toBeNaN(options) {
  847. return toMatch(Number.isNaN, options);
  848. }
  849. function toContains(value, options) {
  850. return toMatch((v) => {
  851. const array = Array.from(v);
  852. return array.includes(value) || array.includes(toValue(value));
  853. }, options);
  854. }
  855. function changed(options) {
  856. return changedTimes(1, options);
  857. }
  858. function changedTimes(n = 1, options) {
  859. let count = -1;
  860. return toMatch(() => {
  861. count += 1;
  862. return count >= n;
  863. }, options);
  864. }
  865. if (Array.isArray(toValue(r))) {
  866. const instance = {
  867. toMatch,
  868. toContains,
  869. changed,
  870. changedTimes,
  871. get not() {
  872. return createUntil(r, !isNot);
  873. }
  874. };
  875. return instance;
  876. } else {
  877. const instance = {
  878. toMatch,
  879. toBe,
  880. toBeTruthy,
  881. toBeNull,
  882. toBeNaN,
  883. toBeUndefined,
  884. changed,
  885. changedTimes,
  886. get not() {
  887. return createUntil(r, !isNot);
  888. }
  889. };
  890. return instance;
  891. }
  892. }
  893. function until(r) {
  894. return createUntil(r);
  895. }
  896. function defaultComparator(value, othVal) {
  897. return value === othVal;
  898. }
  899. function useArrayDifference(...args) {
  900. var _a;
  901. const list = args[0];
  902. const values = args[1];
  903. let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
  904. if (typeof compareFn === "string") {
  905. const key = compareFn;
  906. compareFn = (value, othVal) => value[key] === othVal[key];
  907. }
  908. return vueDemi.computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
  909. }
  910. function useArrayEvery(list, fn) {
  911. return vueDemi.computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
  912. }
  913. function useArrayFilter(list, fn) {
  914. return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
  915. }
  916. function useArrayFind(list, fn) {
  917. return vueDemi.computed(() => toValue(
  918. toValue(list).find((element, index, array) => fn(toValue(element), index, array))
  919. ));
  920. }
  921. function useArrayFindIndex(list, fn) {
  922. return vueDemi.computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
  923. }
  924. function findLast(arr, cb) {
  925. let index = arr.length;
  926. while (index-- > 0) {
  927. if (cb(arr[index], index, arr))
  928. return arr[index];
  929. }
  930. return void 0;
  931. }
  932. function useArrayFindLast(list, fn) {
  933. return vueDemi.computed(() => toValue(
  934. !Array.prototype.findLast ? findLast(toValue(list), (element, index, array) => fn(toValue(element), index, array)) : toValue(list).findLast((element, index, array) => fn(toValue(element), index, array))
  935. ));
  936. }
  937. function isArrayIncludesOptions(obj) {
  938. return isObject(obj) && containsProp(obj, "formIndex", "comparator");
  939. }
  940. function useArrayIncludes(...args) {
  941. var _a;
  942. const list = args[0];
  943. const value = args[1];
  944. let comparator = args[2];
  945. let formIndex = 0;
  946. if (isArrayIncludesOptions(comparator)) {
  947. formIndex = (_a = comparator.fromIndex) != null ? _a : 0;
  948. comparator = comparator.comparator;
  949. }
  950. if (typeof comparator === "string") {
  951. const key = comparator;
  952. comparator = (element, value2) => element[key] === toValue(value2);
  953. }
  954. comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
  955. return vueDemi.computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
  956. toValue(element),
  957. toValue(value),
  958. index,
  959. toValue(array)
  960. )));
  961. }
  962. function useArrayJoin(list, separator) {
  963. return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
  964. }
  965. function useArrayMap(list, fn) {
  966. return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).map(fn));
  967. }
  968. function useArrayReduce(list, reducer, ...args) {
  969. const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
  970. return vueDemi.computed(() => {
  971. const resolved = toValue(list);
  972. return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
  973. });
  974. }
  975. function useArraySome(list, fn) {
  976. return vueDemi.computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
  977. }
  978. function uniq(array) {
  979. return Array.from(new Set(array));
  980. }
  981. function uniqueElementsBy(array, fn) {
  982. return array.reduce((acc, v) => {
  983. if (!acc.some((x) => fn(v, x, array)))
  984. acc.push(v);
  985. return acc;
  986. }, []);
  987. }
  988. function useArrayUnique(list, compareFn) {
  989. return vueDemi.computed(() => {
  990. const resolvedList = toValue(list).map((element) => toValue(element));
  991. return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
  992. });
  993. }
  994. function useCounter(initialValue = 0, options = {}) {
  995. let _initialValue = vueDemi.unref(initialValue);
  996. const count = vueDemi.ref(initialValue);
  997. const {
  998. max = Number.POSITIVE_INFINITY,
  999. min = Number.NEGATIVE_INFINITY
  1000. } = options;
  1001. const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
  1002. const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
  1003. const get = () => count.value;
  1004. const set = (val) => count.value = Math.max(min, Math.min(max, val));
  1005. const reset = (val = _initialValue) => {
  1006. _initialValue = val;
  1007. return set(val);
  1008. };
  1009. return { count, inc, dec, get, set, reset };
  1010. }
  1011. const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
  1012. const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
  1013. function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
  1014. let m = hours < 12 ? "AM" : "PM";
  1015. if (hasPeriod)
  1016. m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
  1017. return isLowercase ? m.toLowerCase() : m;
  1018. }
  1019. function formatOrdinal(num) {
  1020. const suffixes = ["th", "st", "nd", "rd"];
  1021. const v = num % 100;
  1022. return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
  1023. }
  1024. function formatDate(date, formatStr, options = {}) {
  1025. var _a;
  1026. const years = date.getFullYear();
  1027. const month = date.getMonth();
  1028. const days = date.getDate();
  1029. const hours = date.getHours();
  1030. const minutes = date.getMinutes();
  1031. const seconds = date.getSeconds();
  1032. const milliseconds = date.getMilliseconds();
  1033. const day = date.getDay();
  1034. const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
  1035. const matches = {
  1036. Yo: () => formatOrdinal(years),
  1037. YY: () => String(years).slice(-2),
  1038. YYYY: () => years,
  1039. M: () => month + 1,
  1040. Mo: () => formatOrdinal(month + 1),
  1041. MM: () => `${month + 1}`.padStart(2, "0"),
  1042. MMM: () => date.toLocaleDateString(options.locales, { month: "short" }),
  1043. MMMM: () => date.toLocaleDateString(options.locales, { month: "long" }),
  1044. D: () => String(days),
  1045. Do: () => formatOrdinal(days),
  1046. DD: () => `${days}`.padStart(2, "0"),
  1047. H: () => String(hours),
  1048. Ho: () => formatOrdinal(hours),
  1049. HH: () => `${hours}`.padStart(2, "0"),
  1050. h: () => `${hours % 12 || 12}`.padStart(1, "0"),
  1051. ho: () => formatOrdinal(hours % 12 || 12),
  1052. hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
  1053. m: () => String(minutes),
  1054. mo: () => formatOrdinal(minutes),
  1055. mm: () => `${minutes}`.padStart(2, "0"),
  1056. s: () => String(seconds),
  1057. so: () => formatOrdinal(seconds),
  1058. ss: () => `${seconds}`.padStart(2, "0"),
  1059. SSS: () => `${milliseconds}`.padStart(3, "0"),
  1060. d: () => day,
  1061. dd: () => date.toLocaleDateString(options.locales, { weekday: "narrow" }),
  1062. ddd: () => date.toLocaleDateString(options.locales, { weekday: "short" }),
  1063. dddd: () => date.toLocaleDateString(options.locales, { weekday: "long" }),
  1064. A: () => meridiem(hours, minutes),
  1065. AA: () => meridiem(hours, minutes, false, true),
  1066. a: () => meridiem(hours, minutes, true),
  1067. aa: () => meridiem(hours, minutes, true, true)
  1068. };
  1069. return formatStr.replace(REGEX_FORMAT, (match, $1) => {
  1070. var _a2, _b;
  1071. return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? void 0 : _a2.call(matches)) != null ? _b : match;
  1072. });
  1073. }
  1074. function normalizeDate(date) {
  1075. if (date === null)
  1076. return new Date(Number.NaN);
  1077. if (date === void 0)
  1078. return /* @__PURE__ */ new Date();
  1079. if (date instanceof Date)
  1080. return new Date(date);
  1081. if (typeof date === "string" && !/Z$/i.test(date)) {
  1082. const d = date.match(REGEX_PARSE);
  1083. if (d) {
  1084. const m = d[2] - 1 || 0;
  1085. const ms = (d[7] || "0").substring(0, 3);
  1086. return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
  1087. }
  1088. }
  1089. return new Date(date);
  1090. }
  1091. function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
  1092. return vueDemi.computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
  1093. }
  1094. function useIntervalFn(cb, interval = 1e3, options = {}) {
  1095. const {
  1096. immediate = true,
  1097. immediateCallback = false
  1098. } = options;
  1099. let timer = null;
  1100. const isActive = vueDemi.ref(false);
  1101. function clean() {
  1102. if (timer) {
  1103. clearInterval(timer);
  1104. timer = null;
  1105. }
  1106. }
  1107. function pause() {
  1108. isActive.value = false;
  1109. clean();
  1110. }
  1111. function resume() {
  1112. const intervalValue = toValue(interval);
  1113. if (intervalValue <= 0)
  1114. return;
  1115. isActive.value = true;
  1116. if (immediateCallback)
  1117. cb();
  1118. clean();
  1119. timer = setInterval(cb, intervalValue);
  1120. }
  1121. if (immediate && isClient)
  1122. resume();
  1123. if (vueDemi.isRef(interval) || typeof interval === "function") {
  1124. const stopWatch = vueDemi.watch(interval, () => {
  1125. if (isActive.value && isClient)
  1126. resume();
  1127. });
  1128. tryOnScopeDispose(stopWatch);
  1129. }
  1130. tryOnScopeDispose(pause);
  1131. return {
  1132. isActive,
  1133. pause,
  1134. resume
  1135. };
  1136. }
  1137. function useInterval(interval = 1e3, options = {}) {
  1138. const {
  1139. controls: exposeControls = false,
  1140. immediate = true,
  1141. callback
  1142. } = options;
  1143. const counter = vueDemi.ref(0);
  1144. const update = () => counter.value += 1;
  1145. const reset = () => {
  1146. counter.value = 0;
  1147. };
  1148. const controls = useIntervalFn(
  1149. callback ? () => {
  1150. update();
  1151. callback(counter.value);
  1152. } : update,
  1153. interval,
  1154. { immediate }
  1155. );
  1156. if (exposeControls) {
  1157. return {
  1158. counter,
  1159. reset,
  1160. ...controls
  1161. };
  1162. } else {
  1163. return counter;
  1164. }
  1165. }
  1166. function useLastChanged(source, options = {}) {
  1167. var _a;
  1168. const ms = vueDemi.ref((_a = options.initialValue) != null ? _a : null);
  1169. vueDemi.watch(
  1170. source,
  1171. () => ms.value = timestamp(),
  1172. options
  1173. );
  1174. return ms;
  1175. }
  1176. function useTimeoutFn(cb, interval, options = {}) {
  1177. const {
  1178. immediate = true
  1179. } = options;
  1180. const isPending = vueDemi.ref(false);
  1181. let timer = null;
  1182. function clear() {
  1183. if (timer) {
  1184. clearTimeout(timer);
  1185. timer = null;
  1186. }
  1187. }
  1188. function stop() {
  1189. isPending.value = false;
  1190. clear();
  1191. }
  1192. function start(...args) {
  1193. clear();
  1194. isPending.value = true;
  1195. timer = setTimeout(() => {
  1196. isPending.value = false;
  1197. timer = null;
  1198. cb(...args);
  1199. }, toValue(interval));
  1200. }
  1201. if (immediate) {
  1202. isPending.value = true;
  1203. if (isClient)
  1204. start();
  1205. }
  1206. tryOnScopeDispose(stop);
  1207. return {
  1208. isPending: vueDemi.readonly(isPending),
  1209. start,
  1210. stop
  1211. };
  1212. }
  1213. function useTimeout(interval = 1e3, options = {}) {
  1214. const {
  1215. controls: exposeControls = false,
  1216. callback
  1217. } = options;
  1218. const controls = useTimeoutFn(
  1219. callback != null ? callback : noop,
  1220. interval,
  1221. options
  1222. );
  1223. const ready = vueDemi.computed(() => !controls.isPending.value);
  1224. if (exposeControls) {
  1225. return {
  1226. ready,
  1227. ...controls
  1228. };
  1229. } else {
  1230. return ready;
  1231. }
  1232. }
  1233. function useToNumber(value, options = {}) {
  1234. const {
  1235. method = "parseFloat",
  1236. radix,
  1237. nanToZero
  1238. } = options;
  1239. return vueDemi.computed(() => {
  1240. let resolved = toValue(value);
  1241. if (typeof resolved === "string")
  1242. resolved = Number[method](resolved, radix);
  1243. if (nanToZero && Number.isNaN(resolved))
  1244. resolved = 0;
  1245. return resolved;
  1246. });
  1247. }
  1248. function useToString(value) {
  1249. return vueDemi.computed(() => `${toValue(value)}`);
  1250. }
  1251. function useToggle(initialValue = false, options = {}) {
  1252. const {
  1253. truthyValue = true,
  1254. falsyValue = false
  1255. } = options;
  1256. const valueIsRef = vueDemi.isRef(initialValue);
  1257. const _value = vueDemi.ref(initialValue);
  1258. function toggle(value) {
  1259. if (arguments.length) {
  1260. _value.value = value;
  1261. return _value.value;
  1262. } else {
  1263. const truthy = toValue(truthyValue);
  1264. _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
  1265. return _value.value;
  1266. }
  1267. }
  1268. if (valueIsRef)
  1269. return toggle;
  1270. else
  1271. return [_value, toggle];
  1272. }
  1273. function watchArray(source, cb, options) {
  1274. let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
  1275. return vueDemi.watch(source, (newList, _, onCleanup) => {
  1276. const oldListRemains = Array.from({ length: oldList.length });
  1277. const added = [];
  1278. for (const obj of newList) {
  1279. let found = false;
  1280. for (let i = 0; i < oldList.length; i++) {
  1281. if (!oldListRemains[i] && obj === oldList[i]) {
  1282. oldListRemains[i] = true;
  1283. found = true;
  1284. break;
  1285. }
  1286. }
  1287. if (!found)
  1288. added.push(obj);
  1289. }
  1290. const removed = oldList.filter((_2, i) => !oldListRemains[i]);
  1291. cb(newList, oldList, added, removed, onCleanup);
  1292. oldList = [...newList];
  1293. }, options);
  1294. }
  1295. function watchAtMost(source, cb, options) {
  1296. const {
  1297. count,
  1298. ...watchOptions
  1299. } = options;
  1300. const current = vueDemi.ref(0);
  1301. const stop = watchWithFilter(
  1302. source,
  1303. (...args) => {
  1304. current.value += 1;
  1305. if (current.value >= toValue(count))
  1306. vueDemi.nextTick(() => stop());
  1307. cb(...args);
  1308. },
  1309. watchOptions
  1310. );
  1311. return { count: current, stop };
  1312. }
  1313. function watchDebounced(source, cb, options = {}) {
  1314. const {
  1315. debounce = 0,
  1316. maxWait = void 0,
  1317. ...watchOptions
  1318. } = options;
  1319. return watchWithFilter(
  1320. source,
  1321. cb,
  1322. {
  1323. ...watchOptions,
  1324. eventFilter: debounceFilter(debounce, { maxWait })
  1325. }
  1326. );
  1327. }
  1328. function watchDeep(source, cb, options) {
  1329. return vueDemi.watch(
  1330. source,
  1331. cb,
  1332. {
  1333. ...options,
  1334. deep: true
  1335. }
  1336. );
  1337. }
  1338. function watchIgnorable(source, cb, options = {}) {
  1339. const {
  1340. eventFilter = bypassFilter,
  1341. ...watchOptions
  1342. } = options;
  1343. const filteredCb = createFilterWrapper(
  1344. eventFilter,
  1345. cb
  1346. );
  1347. let ignoreUpdates;
  1348. let ignorePrevAsyncUpdates;
  1349. let stop;
  1350. if (watchOptions.flush === "sync") {
  1351. const ignore = vueDemi.ref(false);
  1352. ignorePrevAsyncUpdates = () => {
  1353. };
  1354. ignoreUpdates = (updater) => {
  1355. ignore.value = true;
  1356. updater();
  1357. ignore.value = false;
  1358. };
  1359. stop = vueDemi.watch(
  1360. source,
  1361. (...args) => {
  1362. if (!ignore.value)
  1363. filteredCb(...args);
  1364. },
  1365. watchOptions
  1366. );
  1367. } else {
  1368. const disposables = [];
  1369. const ignoreCounter = vueDemi.ref(0);
  1370. const syncCounter = vueDemi.ref(0);
  1371. ignorePrevAsyncUpdates = () => {
  1372. ignoreCounter.value = syncCounter.value;
  1373. };
  1374. disposables.push(
  1375. vueDemi.watch(
  1376. source,
  1377. () => {
  1378. syncCounter.value++;
  1379. },
  1380. { ...watchOptions, flush: "sync" }
  1381. )
  1382. );
  1383. ignoreUpdates = (updater) => {
  1384. const syncCounterPrev = syncCounter.value;
  1385. updater();
  1386. ignoreCounter.value += syncCounter.value - syncCounterPrev;
  1387. };
  1388. disposables.push(
  1389. vueDemi.watch(
  1390. source,
  1391. (...args) => {
  1392. const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
  1393. ignoreCounter.value = 0;
  1394. syncCounter.value = 0;
  1395. if (ignore)
  1396. return;
  1397. filteredCb(...args);
  1398. },
  1399. watchOptions
  1400. )
  1401. );
  1402. stop = () => {
  1403. disposables.forEach((fn) => fn());
  1404. };
  1405. }
  1406. return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
  1407. }
  1408. function watchImmediate(source, cb, options) {
  1409. return vueDemi.watch(
  1410. source,
  1411. cb,
  1412. {
  1413. ...options,
  1414. immediate: true
  1415. }
  1416. );
  1417. }
  1418. function watchOnce(source, cb, options) {
  1419. const stop = vueDemi.watch(source, (...args) => {
  1420. vueDemi.nextTick(() => stop());
  1421. return cb(...args);
  1422. }, options);
  1423. return stop;
  1424. }
  1425. function watchThrottled(source, cb, options = {}) {
  1426. const {
  1427. throttle = 0,
  1428. trailing = true,
  1429. leading = true,
  1430. ...watchOptions
  1431. } = options;
  1432. return watchWithFilter(
  1433. source,
  1434. cb,
  1435. {
  1436. ...watchOptions,
  1437. eventFilter: throttleFilter(throttle, trailing, leading)
  1438. }
  1439. );
  1440. }
  1441. function watchTriggerable(source, cb, options = {}) {
  1442. let cleanupFn;
  1443. function onEffect() {
  1444. if (!cleanupFn)
  1445. return;
  1446. const fn = cleanupFn;
  1447. cleanupFn = void 0;
  1448. fn();
  1449. }
  1450. function onCleanup(callback) {
  1451. cleanupFn = callback;
  1452. }
  1453. const _cb = (value, oldValue) => {
  1454. onEffect();
  1455. return cb(value, oldValue, onCleanup);
  1456. };
  1457. const res = watchIgnorable(source, _cb, options);
  1458. const { ignoreUpdates } = res;
  1459. const trigger = () => {
  1460. let res2;
  1461. ignoreUpdates(() => {
  1462. res2 = _cb(getWatchSources(source), getOldValue(source));
  1463. });
  1464. return res2;
  1465. };
  1466. return {
  1467. ...res,
  1468. trigger
  1469. };
  1470. }
  1471. function getWatchSources(sources) {
  1472. if (vueDemi.isReactive(sources))
  1473. return sources;
  1474. if (Array.isArray(sources))
  1475. return sources.map((item) => toValue(item));
  1476. return toValue(sources);
  1477. }
  1478. function getOldValue(source) {
  1479. return Array.isArray(source) ? source.map(() => void 0) : void 0;
  1480. }
  1481. function whenever(source, cb, options) {
  1482. const stop = vueDemi.watch(
  1483. source,
  1484. (v, ov, onInvalidate) => {
  1485. if (v) {
  1486. if (options == null ? void 0 : options.once)
  1487. vueDemi.nextTick(() => stop());
  1488. cb(v, ov, onInvalidate);
  1489. }
  1490. },
  1491. {
  1492. ...options,
  1493. once: false
  1494. }
  1495. );
  1496. return stop;
  1497. }
  1498. exports.assert = assert;
  1499. exports.autoResetRef = refAutoReset;
  1500. exports.bypassFilter = bypassFilter;
  1501. exports.camelize = camelize;
  1502. exports.clamp = clamp;
  1503. exports.computedEager = computedEager;
  1504. exports.computedWithControl = computedWithControl;
  1505. exports.containsProp = containsProp;
  1506. exports.controlledComputed = computedWithControl;
  1507. exports.controlledRef = controlledRef;
  1508. exports.createEventHook = createEventHook;
  1509. exports.createFilterWrapper = createFilterWrapper;
  1510. exports.createGlobalState = createGlobalState;
  1511. exports.createInjectionState = createInjectionState;
  1512. exports.createReactiveFn = reactify;
  1513. exports.createSharedComposable = createSharedComposable;
  1514. exports.createSingletonPromise = createSingletonPromise;
  1515. exports.debounceFilter = debounceFilter;
  1516. exports.debouncedRef = refDebounced;
  1517. exports.debouncedWatch = watchDebounced;
  1518. exports.directiveHooks = directiveHooks;
  1519. exports.eagerComputed = computedEager;
  1520. exports.extendRef = extendRef;
  1521. exports.formatDate = formatDate;
  1522. exports.get = get;
  1523. exports.getLifeCycleTarget = getLifeCycleTarget;
  1524. exports.hasOwn = hasOwn;
  1525. exports.hyphenate = hyphenate;
  1526. exports.identity = identity;
  1527. exports.ignorableWatch = watchIgnorable;
  1528. exports.increaseWithUnit = increaseWithUnit;
  1529. exports.injectLocal = injectLocal;
  1530. exports.invoke = invoke;
  1531. exports.isClient = isClient;
  1532. exports.isDef = isDef;
  1533. exports.isDefined = isDefined;
  1534. exports.isIOS = isIOS;
  1535. exports.isObject = isObject;
  1536. exports.isWorker = isWorker;
  1537. exports.makeDestructurable = makeDestructurable;
  1538. exports.noop = noop;
  1539. exports.normalizeDate = normalizeDate;
  1540. exports.notNullish = notNullish;
  1541. exports.now = now;
  1542. exports.objectEntries = objectEntries;
  1543. exports.objectOmit = objectOmit;
  1544. exports.objectPick = objectPick;
  1545. exports.pausableFilter = pausableFilter;
  1546. exports.pausableWatch = watchPausable;
  1547. exports.promiseTimeout = promiseTimeout;
  1548. exports.provideLocal = provideLocal;
  1549. exports.rand = rand;
  1550. exports.reactify = reactify;
  1551. exports.reactifyObject = reactifyObject;
  1552. exports.reactiveComputed = reactiveComputed;
  1553. exports.reactiveOmit = reactiveOmit;
  1554. exports.reactivePick = reactivePick;
  1555. exports.refAutoReset = refAutoReset;
  1556. exports.refDebounced = refDebounced;
  1557. exports.refDefault = refDefault;
  1558. exports.refThrottled = refThrottled;
  1559. exports.refWithControl = refWithControl;
  1560. exports.resolveRef = resolveRef;
  1561. exports.resolveUnref = resolveUnref;
  1562. exports.set = set;
  1563. exports.syncRef = syncRef;
  1564. exports.syncRefs = syncRefs;
  1565. exports.throttleFilter = throttleFilter;
  1566. exports.throttledRef = refThrottled;
  1567. exports.throttledWatch = watchThrottled;
  1568. exports.timestamp = timestamp;
  1569. exports.toReactive = toReactive;
  1570. exports.toRef = toRef;
  1571. exports.toRefs = toRefs;
  1572. exports.toValue = toValue;
  1573. exports.tryOnBeforeMount = tryOnBeforeMount;
  1574. exports.tryOnBeforeUnmount = tryOnBeforeUnmount;
  1575. exports.tryOnMounted = tryOnMounted;
  1576. exports.tryOnScopeDispose = tryOnScopeDispose;
  1577. exports.tryOnUnmounted = tryOnUnmounted;
  1578. exports.until = until;
  1579. exports.useArrayDifference = useArrayDifference;
  1580. exports.useArrayEvery = useArrayEvery;
  1581. exports.useArrayFilter = useArrayFilter;
  1582. exports.useArrayFind = useArrayFind;
  1583. exports.useArrayFindIndex = useArrayFindIndex;
  1584. exports.useArrayFindLast = useArrayFindLast;
  1585. exports.useArrayIncludes = useArrayIncludes;
  1586. exports.useArrayJoin = useArrayJoin;
  1587. exports.useArrayMap = useArrayMap;
  1588. exports.useArrayReduce = useArrayReduce;
  1589. exports.useArraySome = useArraySome;
  1590. exports.useArrayUnique = useArrayUnique;
  1591. exports.useCounter = useCounter;
  1592. exports.useDateFormat = useDateFormat;
  1593. exports.useDebounce = refDebounced;
  1594. exports.useDebounceFn = useDebounceFn;
  1595. exports.useInterval = useInterval;
  1596. exports.useIntervalFn = useIntervalFn;
  1597. exports.useLastChanged = useLastChanged;
  1598. exports.useThrottle = refThrottled;
  1599. exports.useThrottleFn = useThrottleFn;
  1600. exports.useTimeout = useTimeout;
  1601. exports.useTimeoutFn = useTimeoutFn;
  1602. exports.useToNumber = useToNumber;
  1603. exports.useToString = useToString;
  1604. exports.useToggle = useToggle;
  1605. exports.watchArray = watchArray;
  1606. exports.watchAtMost = watchAtMost;
  1607. exports.watchDebounced = watchDebounced;
  1608. exports.watchDeep = watchDeep;
  1609. exports.watchIgnorable = watchIgnorable;
  1610. exports.watchImmediate = watchImmediate;
  1611. exports.watchOnce = watchOnce;
  1612. exports.watchPausable = watchPausable;
  1613. exports.watchThrottled = watchThrottled;
  1614. exports.watchTriggerable = watchTriggerable;
  1615. exports.watchWithFilter = watchWithFilter;
  1616. exports.whenever = whenever;