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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013
  1. import { computed, customRef, effectScope, getCurrentInstance, getCurrentScope, hasInjectionContext, inject, isReactive, isRef, nextTick, onBeforeMount, onBeforeUnmount, onMounted, onScopeDispose, onUnmounted, provide, reactive, readonly, ref, shallowReadonly, shallowRef, toRef as toRef$1, toRefs as toRefs$1, toValue, unref, watch, watchEffect } from "vue";
  2. //#region computedEager/index.ts
  3. /**
  4. *
  5. * @deprecated This function will be removed in future version.
  6. *
  7. * Note: If you are using Vue 3.4+, you can straight use computed instead.
  8. * Because in Vue 3.4+, if computed new value does not change,
  9. * computed, effect, watch, watchEffect, render dependencies will not be triggered.
  10. * refer: https://github.com/vuejs/core/pull/5912
  11. *
  12. * @param fn effect function
  13. * @param options WatchOptionsBase
  14. * @returns readonly shallowRef
  15. */
  16. function computedEager(fn, options) {
  17. var _options$flush;
  18. const result = shallowRef();
  19. watchEffect(() => {
  20. result.value = fn();
  21. }, {
  22. ...options,
  23. flush: (_options$flush = options === null || options === void 0 ? void 0 : options.flush) !== null && _options$flush !== void 0 ? _options$flush : "sync"
  24. });
  25. return readonly(result);
  26. }
  27. /** @deprecated use `computedEager` instead */
  28. const eagerComputed = computedEager;
  29. //#endregion
  30. //#region computedWithControl/index.ts
  31. /**
  32. * Explicitly define the deps of computed.
  33. *
  34. * @param source
  35. * @param fn
  36. */
  37. function computedWithControl(source, fn, options = {}) {
  38. let v = void 0;
  39. let track;
  40. let trigger;
  41. let dirty = true;
  42. const update = () => {
  43. dirty = true;
  44. trigger();
  45. };
  46. watch(source, update, {
  47. flush: "sync",
  48. ...options
  49. });
  50. const get = typeof fn === "function" ? fn : fn.get;
  51. const set = typeof fn === "function" ? void 0 : fn.set;
  52. const result = customRef((_track, _trigger) => {
  53. track = _track;
  54. trigger = _trigger;
  55. return {
  56. get() {
  57. if (dirty) {
  58. v = get(v);
  59. dirty = false;
  60. }
  61. track();
  62. return v;
  63. },
  64. set(v) {
  65. set === null || set === void 0 || set(v);
  66. }
  67. };
  68. });
  69. result.trigger = update;
  70. return result;
  71. }
  72. /** @deprecated use `computedWithControl` instead */
  73. const controlledComputed = computedWithControl;
  74. //#endregion
  75. //#region createDisposableDirective/index.ts
  76. /**
  77. * Utility for authoring disposable directives. Reactive effects created within `mounted` directive hook will be tracked and automatically disposed when directive is unmounted.
  78. *
  79. * @see https://vueuse.org/createDisposableDirective
  80. *
  81. * @__NO_SIDE_EFFECTS__
  82. */
  83. function createDisposableDirective(origin = {}) {
  84. function isFunc(fn) {
  85. return typeof fn === "function";
  86. }
  87. const normalisedOrigin = isFunc(origin) ? {
  88. mounted: origin,
  89. updated: origin
  90. } : origin;
  91. const { mounted, unmounted } = normalisedOrigin;
  92. if (!isFunc(mounted)) return origin;
  93. const scopeWeakMap = /* @__PURE__ */ new WeakMap();
  94. return {
  95. ...normalisedOrigin,
  96. mounted(el, binding, vNode, prevNode) {
  97. var _scopeWeakMap$get;
  98. const scope = (_scopeWeakMap$get = scopeWeakMap.get(el)) !== null && _scopeWeakMap$get !== void 0 ? _scopeWeakMap$get : effectScope();
  99. scopeWeakMap.set(el, scope);
  100. scope.run(() => {
  101. mounted === null || mounted === void 0 || mounted(el, binding, vNode, prevNode);
  102. });
  103. },
  104. unmounted(el, binding, vNode, prevNode) {
  105. var _scopeWeakMap$get2;
  106. (_scopeWeakMap$get2 = scopeWeakMap.get(el)) === null || _scopeWeakMap$get2 === void 0 || _scopeWeakMap$get2.stop();
  107. scopeWeakMap.delete(el);
  108. if (isFunc(unmounted)) unmounted(el, binding, vNode, prevNode);
  109. }
  110. };
  111. }
  112. //#endregion
  113. //#region tryOnScopeDispose/index.ts
  114. /**
  115. * Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing
  116. *
  117. * @param fn
  118. */
  119. function tryOnScopeDispose(fn, failSilently) {
  120. if (getCurrentScope()) {
  121. onScopeDispose(fn, failSilently);
  122. return true;
  123. }
  124. return false;
  125. }
  126. //#endregion
  127. //#region createEventHook/index.ts
  128. /**
  129. * Utility for creating event hooks
  130. *
  131. * @see https://vueuse.org/createEventHook
  132. *
  133. * @__NO_SIDE_EFFECTS__
  134. */
  135. function createEventHook() {
  136. const fns = /* @__PURE__ */ new Set();
  137. const off = (fn) => {
  138. fns.delete(fn);
  139. };
  140. const clear = () => {
  141. fns.clear();
  142. };
  143. const on = (fn) => {
  144. fns.add(fn);
  145. const offFn = () => off(fn);
  146. tryOnScopeDispose(offFn);
  147. return { off: offFn };
  148. };
  149. const trigger = (...args) => {
  150. return Promise.all(Array.from(fns).map((fn) => fn(...args)));
  151. };
  152. return {
  153. on,
  154. off,
  155. trigger,
  156. clear
  157. };
  158. }
  159. //#endregion
  160. //#region createGlobalState/index.ts
  161. /**
  162. * Keep states in the global scope to be reusable across Vue instances.
  163. *
  164. * @see https://vueuse.org/createGlobalState
  165. * @param stateFactory A factory function to create the state
  166. *
  167. * @__NO_SIDE_EFFECTS__
  168. */
  169. function createGlobalState(stateFactory) {
  170. let initialized = false;
  171. let state;
  172. const scope = effectScope(true);
  173. return ((...args) => {
  174. if (!initialized) {
  175. state = scope.run(() => stateFactory(...args));
  176. initialized = true;
  177. }
  178. return state;
  179. });
  180. }
  181. //#endregion
  182. //#region provideLocal/map.ts
  183. const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
  184. //#endregion
  185. //#region injectLocal/index.ts
  186. /**
  187. * On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
  188. *
  189. * @example
  190. * ```ts
  191. * injectLocal('MyInjectionKey', 1)
  192. * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
  193. * ```
  194. *
  195. * @__NO_SIDE_EFFECTS__
  196. */
  197. const injectLocal = (...args) => {
  198. var _getCurrentInstance;
  199. const key = args[0];
  200. const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
  201. const owner = instance !== null && instance !== void 0 ? instance : getCurrentScope();
  202. if (owner == null && !hasInjectionContext()) throw new Error("injectLocal must be called in setup");
  203. if (owner && localProvidedStateMap.has(owner) && key in localProvidedStateMap.get(owner)) return localProvidedStateMap.get(owner)[key];
  204. return inject(...args);
  205. };
  206. //#endregion
  207. //#region provideLocal/index.ts
  208. /**
  209. * On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component.
  210. *
  211. * @example
  212. * ```ts
  213. * provideLocal('MyInjectionKey', 1)
  214. * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
  215. * ```
  216. */
  217. function provideLocal(key, value) {
  218. var _getCurrentInstance;
  219. const instance = (_getCurrentInstance = getCurrentInstance()) === null || _getCurrentInstance === void 0 ? void 0 : _getCurrentInstance.proxy;
  220. const owner = instance !== null && instance !== void 0 ? instance : getCurrentScope();
  221. if (owner == null) throw new Error("provideLocal must be called in setup");
  222. if (!localProvidedStateMap.has(owner)) localProvidedStateMap.set(owner, Object.create(null));
  223. const localProvidedState = localProvidedStateMap.get(owner);
  224. localProvidedState[key] = value;
  225. return provide(key, value);
  226. }
  227. //#endregion
  228. //#region createInjectionState/index.ts
  229. function createInjectionState(composable, options) {
  230. const key = (options === null || options === void 0 ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
  231. const defaultValue = options === null || options === void 0 ? void 0 : options.defaultValue;
  232. const useProvidingState = (...args) => {
  233. const state = composable(...args);
  234. provideLocal(key, state);
  235. return state;
  236. };
  237. const useInjectedState = () => injectLocal(key, defaultValue);
  238. return [useProvidingState, useInjectedState];
  239. }
  240. //#endregion
  241. //#region createRef/index.ts
  242. /**
  243. * Returns a `deepRef` or `shallowRef` depending on the `deep` param.
  244. *
  245. * @example createRef(1) // ShallowRef<number>
  246. * @example createRef(1, false) // ShallowRef<number>
  247. * @example createRef(1, true) // Ref<number>
  248. * @example createRef("string") // ShallowRef<string>
  249. * @example createRef<"A"|"B">("A", true) // Ref<"A"|"B">
  250. *
  251. * @param value
  252. * @param deep
  253. * @returns the `deepRef` or `shallowRef`
  254. *
  255. * @__NO_SIDE_EFFECTS__
  256. */
  257. function createRef(value, deep) {
  258. if (deep === true) return ref(value);
  259. else return shallowRef(value);
  260. }
  261. //#endregion
  262. //#region utils/is.ts
  263. const isClient = typeof window !== "undefined" && typeof document !== "undefined";
  264. const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
  265. const isDef = (val) => typeof val !== "undefined";
  266. const notNullish = (val) => val != null;
  267. const assert = (condition, ...infos) => {
  268. if (!condition) console.warn(...infos);
  269. };
  270. const toString = Object.prototype.toString;
  271. const isObject = (val) => toString.call(val) === "[object Object]";
  272. const now = () => Date.now();
  273. const timestamp = () => +Date.now();
  274. const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
  275. const noop = () => {};
  276. const rand = (min, max) => {
  277. min = Math.ceil(min);
  278. max = Math.floor(max);
  279. return Math.floor(Math.random() * (max - min + 1)) + min;
  280. };
  281. const hasOwn = (val, key) => Object.hasOwn(val, key);
  282. const isIOS = /* @__PURE__ */ getIsIOS();
  283. function getIsIOS() {
  284. var _window, _window2, _window3;
  285. return isClient && !!((_window = window) === null || _window === void 0 || (_window = _window.navigator) === null || _window === void 0 ? void 0 : _window.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.navigator) === null || _window2 === void 0 ? void 0 : _window2.maxTouchPoints) > 2 && /iPad|Macintosh/.test((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.navigator.userAgent));
  286. }
  287. //#endregion
  288. //#region toRef/index.ts
  289. function toRef(...args) {
  290. if (args.length !== 1) return toRef$1(...args);
  291. const r = args[0];
  292. return typeof r === "function" ? readonly(customRef(() => ({
  293. get: r,
  294. set: noop
  295. }))) : ref(r);
  296. }
  297. //#endregion
  298. //#region utils/filters.ts
  299. /**
  300. * @internal
  301. */
  302. function createFilterWrapper(filter, fn) {
  303. function wrapper(...args) {
  304. return new Promise((resolve, reject) => {
  305. Promise.resolve(filter(() => fn.apply(this, args), {
  306. fn,
  307. thisArg: this,
  308. args
  309. })).then(resolve).catch(reject);
  310. });
  311. }
  312. return wrapper;
  313. }
  314. const bypassFilter = (invoke) => {
  315. return invoke();
  316. };
  317. /**
  318. * Create an EventFilter that debounce the events
  319. */
  320. function debounceFilter(ms, options = {}) {
  321. let timer;
  322. let maxTimer;
  323. let lastRejector = noop;
  324. const _clearTimeout = (timer) => {
  325. clearTimeout(timer);
  326. lastRejector();
  327. lastRejector = noop;
  328. };
  329. let lastInvoker;
  330. const filter = (invoke) => {
  331. const duration = toValue(ms);
  332. const maxDuration = toValue(options.maxWait);
  333. if (timer) _clearTimeout(timer);
  334. if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
  335. if (maxTimer) {
  336. _clearTimeout(maxTimer);
  337. maxTimer = void 0;
  338. }
  339. return Promise.resolve(invoke());
  340. }
  341. return new Promise((resolve, reject) => {
  342. lastRejector = options.rejectOnCancel ? reject : resolve;
  343. lastInvoker = invoke;
  344. if (maxDuration && !maxTimer) maxTimer = setTimeout(() => {
  345. if (timer) _clearTimeout(timer);
  346. maxTimer = void 0;
  347. resolve(lastInvoker());
  348. }, maxDuration);
  349. timer = setTimeout(() => {
  350. if (maxTimer) _clearTimeout(maxTimer);
  351. maxTimer = void 0;
  352. resolve(invoke());
  353. }, duration);
  354. });
  355. };
  356. return filter;
  357. }
  358. function throttleFilter(...args) {
  359. let lastExec = 0;
  360. let timer;
  361. let isLeading = true;
  362. let lastRejector = noop;
  363. let lastValue;
  364. let ms;
  365. let trailing;
  366. let leading;
  367. let rejectOnCancel;
  368. if (!isRef(args[0]) && typeof args[0] === "object") ({delay: ms, trailing = true, leading = true, rejectOnCancel = false} = args[0]);
  369. else [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
  370. const clear = () => {
  371. if (timer) {
  372. clearTimeout(timer);
  373. timer = void 0;
  374. lastRejector();
  375. lastRejector = noop;
  376. }
  377. };
  378. const filter = (_invoke) => {
  379. const duration = toValue(ms);
  380. const elapsed = Date.now() - lastExec;
  381. const invoke = () => {
  382. return lastValue = _invoke();
  383. };
  384. clear();
  385. if (duration <= 0) {
  386. lastExec = Date.now();
  387. return invoke();
  388. }
  389. if (elapsed > duration) {
  390. lastExec = Date.now();
  391. if (leading || !isLeading) invoke();
  392. } else if (trailing) lastValue = new Promise((resolve, reject) => {
  393. lastRejector = rejectOnCancel ? reject : resolve;
  394. timer = setTimeout(() => {
  395. lastExec = Date.now();
  396. isLeading = true;
  397. resolve(invoke());
  398. clear();
  399. }, Math.max(0, duration - elapsed));
  400. });
  401. if (!leading && !timer) timer = setTimeout(() => isLeading = true, duration);
  402. isLeading = false;
  403. return lastValue;
  404. };
  405. return filter;
  406. }
  407. /**
  408. * EventFilter that gives extra controls to pause and resume the filter
  409. *
  410. * @param extendFilter Extra filter to apply when the PausableFilter is active, default to none
  411. * @param options Options to configure the filter
  412. */
  413. function pausableFilter(extendFilter = bypassFilter, options = {}) {
  414. const { initialState = "active" } = options;
  415. const isActive = toRef(initialState === "active");
  416. function pause() {
  417. isActive.value = false;
  418. }
  419. function resume() {
  420. isActive.value = true;
  421. }
  422. const eventFilter = (...args) => {
  423. if (isActive.value) extendFilter(...args);
  424. };
  425. return {
  426. isActive: shallowReadonly(isActive),
  427. pause,
  428. resume,
  429. eventFilter
  430. };
  431. }
  432. //#endregion
  433. //#region utils/general.ts
  434. function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
  435. return new Promise((resolve, reject) => {
  436. if (throwOnTimeout) setTimeout(reject, ms, reason);
  437. else setTimeout(resolve, ms);
  438. });
  439. }
  440. function identity(arg) {
  441. return arg;
  442. }
  443. /**
  444. * Create singleton promise function
  445. *
  446. * @example
  447. * ```
  448. * const promise = createSingletonPromise(async () => { ... })
  449. *
  450. * await promise()
  451. * await promise() // all of them will be bind to a single promise instance
  452. * await promise() // and be resolved together
  453. * ```
  454. */
  455. function createSingletonPromise(fn) {
  456. let _promise;
  457. function wrapper() {
  458. if (!_promise) _promise = fn();
  459. return _promise;
  460. }
  461. wrapper.reset = async () => {
  462. const _prev = _promise;
  463. _promise = void 0;
  464. if (_prev) await _prev;
  465. };
  466. return wrapper;
  467. }
  468. function invoke(fn) {
  469. return fn();
  470. }
  471. function containsProp(obj, ...props) {
  472. return props.some((k) => k in obj);
  473. }
  474. function increaseWithUnit(target, delta) {
  475. var _target$match;
  476. if (typeof target === "number") return target + delta;
  477. const value = ((_target$match = target.match(/^-?\d+\.?\d*/)) === null || _target$match === void 0 ? void 0 : _target$match[0]) || "";
  478. const unit = target.slice(value.length);
  479. const result = Number.parseFloat(value) + delta;
  480. if (Number.isNaN(result)) return target;
  481. return result + unit;
  482. }
  483. /**
  484. * Get a px value for SSR use, do not rely on this method outside of SSR as REM unit is assumed at 16px, which might not be the case on the client
  485. */
  486. function pxValue(px) {
  487. return px.endsWith("rem") ? Number.parseFloat(px) * 16 : Number.parseFloat(px);
  488. }
  489. /**
  490. * Create a new subset object by giving keys
  491. */
  492. function objectPick(obj, keys, omitUndefined = false) {
  493. return keys.reduce((n, k) => {
  494. if (k in obj) {
  495. if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
  496. }
  497. return n;
  498. }, {});
  499. }
  500. /**
  501. * Create a new subset object by omit giving keys
  502. */
  503. function objectOmit(obj, keys, omitUndefined = false) {
  504. return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
  505. return (!omitUndefined || value !== void 0) && !keys.includes(key);
  506. }));
  507. }
  508. function objectEntries(obj) {
  509. return Object.entries(obj);
  510. }
  511. function toArray(value) {
  512. return Array.isArray(value) ? value : [value];
  513. }
  514. //#endregion
  515. //#region utils/port.ts
  516. function cacheStringFunction(fn) {
  517. const cache = Object.create(null);
  518. return ((str) => {
  519. return cache[str] || (cache[str] = fn(str));
  520. });
  521. }
  522. const hyphenateRE = /\B([A-Z])/g;
  523. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
  524. const camelizeRE = /-(\w)/g;
  525. const camelize = cacheStringFunction((str) => {
  526. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  527. });
  528. //#endregion
  529. //#region utils/vue.ts
  530. function getLifeCycleTarget(target) {
  531. return target || getCurrentInstance();
  532. }
  533. //#endregion
  534. //#region createSharedComposable/index.ts
  535. /**
  536. * Make a composable function usable with multiple Vue instances.
  537. *
  538. * @see https://vueuse.org/createSharedComposable
  539. *
  540. * @__NO_SIDE_EFFECTS__
  541. */
  542. function createSharedComposable(composable) {
  543. if (!isClient) return composable;
  544. let subscribers = 0;
  545. let state;
  546. let scope;
  547. const dispose = () => {
  548. subscribers -= 1;
  549. if (scope && subscribers <= 0) {
  550. scope.stop();
  551. state = void 0;
  552. scope = void 0;
  553. }
  554. };
  555. return ((...args) => {
  556. subscribers += 1;
  557. if (!scope) {
  558. scope = effectScope(true);
  559. state = scope.run(() => composable(...args));
  560. }
  561. tryOnScopeDispose(dispose);
  562. return state;
  563. });
  564. }
  565. //#endregion
  566. //#region extendRef/index.ts
  567. function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
  568. for (const [key, value] of Object.entries(extend)) {
  569. if (key === "value") continue;
  570. if (isRef(value) && unwrap) Object.defineProperty(ref, key, {
  571. get() {
  572. return value.value;
  573. },
  574. set(v) {
  575. value.value = v;
  576. },
  577. enumerable
  578. });
  579. else Object.defineProperty(ref, key, {
  580. value,
  581. enumerable
  582. });
  583. }
  584. return ref;
  585. }
  586. //#endregion
  587. //#region get/index.ts
  588. function get(obj, key) {
  589. if (key == null) return unref(obj);
  590. return unref(obj)[key];
  591. }
  592. //#endregion
  593. //#region isDefined/index.ts
  594. function isDefined(v) {
  595. return unref(v) != null;
  596. }
  597. //#endregion
  598. //#region makeDestructurable/index.ts
  599. /* @__NO_SIDE_EFFECTS__ */
  600. function makeDestructurable(obj, arr) {
  601. if (typeof Symbol !== "undefined") {
  602. const clone = { ...obj };
  603. Object.defineProperty(clone, Symbol.iterator, {
  604. enumerable: false,
  605. value() {
  606. let index = 0;
  607. return { next: () => ({
  608. value: arr[index++],
  609. done: index > arr.length
  610. }) };
  611. }
  612. });
  613. return clone;
  614. } else return Object.assign([...arr], obj);
  615. }
  616. //#endregion
  617. //#region reactify/index.ts
  618. /**
  619. * Converts plain function into a reactive function.
  620. * The converted function accepts refs as it's arguments
  621. * and returns a ComputedRef, with proper typing.
  622. *
  623. * @param fn - Source function
  624. * @param options - Options
  625. *
  626. * @__NO_SIDE_EFFECTS__
  627. */
  628. function reactify(fn, options) {
  629. const unrefFn = (options === null || options === void 0 ? void 0 : options.computedGetter) === false ? unref : toValue;
  630. return function(...args) {
  631. return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
  632. };
  633. }
  634. /** @deprecated use `reactify` instead */
  635. const createReactiveFn = reactify;
  636. //#endregion
  637. //#region reactifyObject/index.ts
  638. /**
  639. * Apply `reactify` to an object
  640. *
  641. * @__NO_SIDE_EFFECTS__
  642. */
  643. function reactifyObject(obj, optionsOrKeys = {}) {
  644. let keys = [];
  645. let options;
  646. if (Array.isArray(optionsOrKeys)) keys = optionsOrKeys;
  647. else {
  648. options = optionsOrKeys;
  649. const { includeOwnProperties = true } = optionsOrKeys;
  650. keys.push(...Object.keys(obj));
  651. if (includeOwnProperties) keys.push(...Object.getOwnPropertyNames(obj));
  652. }
  653. return Object.fromEntries(keys.map((key) => {
  654. const value = obj[key];
  655. return [key, typeof value === "function" ? reactify(value.bind(obj), options) : value];
  656. }));
  657. }
  658. //#endregion
  659. //#region toReactive/index.ts
  660. /**
  661. * Converts ref to reactive.
  662. *
  663. * @see https://vueuse.org/toReactive
  664. * @param objectRef A ref of object
  665. */
  666. function toReactive(objectRef) {
  667. if (!isRef(objectRef)) return reactive(objectRef);
  668. return reactive(new Proxy({}, {
  669. get(_, p, receiver) {
  670. return unref(Reflect.get(objectRef.value, p, receiver));
  671. },
  672. set(_, p, value) {
  673. if (isRef(objectRef.value[p]) && !isRef(value)) objectRef.value[p].value = value;
  674. else objectRef.value[p] = value;
  675. return true;
  676. },
  677. deleteProperty(_, p) {
  678. return Reflect.deleteProperty(objectRef.value, p);
  679. },
  680. has(_, p) {
  681. return Reflect.has(objectRef.value, p);
  682. },
  683. ownKeys() {
  684. return Object.keys(objectRef.value);
  685. },
  686. getOwnPropertyDescriptor() {
  687. return {
  688. enumerable: true,
  689. configurable: true
  690. };
  691. }
  692. }));
  693. }
  694. //#endregion
  695. //#region reactiveComputed/index.ts
  696. /**
  697. * Computed reactive object.
  698. */
  699. function reactiveComputed(fn) {
  700. return toReactive(computed(fn));
  701. }
  702. //#endregion
  703. //#region reactiveOmit/index.ts
  704. /**
  705. * Reactively omit fields from a reactive object
  706. *
  707. * @see https://vueuse.org/reactiveOmit
  708. */
  709. function reactiveOmit(obj, ...keys) {
  710. const flatKeys = keys.flat();
  711. const predicate = flatKeys[0];
  712. return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
  713. }
  714. //#endregion
  715. //#region reactivePick/index.ts
  716. /**
  717. * Reactively pick fields from a reactive object
  718. *
  719. * @see https://vueuse.org/reactivePick
  720. */
  721. function reactivePick(obj, ...keys) {
  722. const flatKeys = keys.flat();
  723. const predicate = flatKeys[0];
  724. return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
  725. }
  726. //#endregion
  727. //#region refAutoReset/index.ts
  728. /**
  729. * Create a ref which will be reset to the default value after some time.
  730. *
  731. * @see https://vueuse.org/refAutoReset
  732. * @param defaultValue The value which will be set.
  733. * @param afterMs A zero-or-greater delay in milliseconds.
  734. */
  735. function refAutoReset(defaultValue, afterMs = 1e4) {
  736. return customRef((track, trigger) => {
  737. let value = toValue(defaultValue);
  738. let timer;
  739. const resetAfter = () => setTimeout(() => {
  740. value = toValue(defaultValue);
  741. trigger();
  742. }, toValue(afterMs));
  743. tryOnScopeDispose(() => {
  744. clearTimeout(timer);
  745. });
  746. return {
  747. get() {
  748. track();
  749. return value;
  750. },
  751. set(newValue) {
  752. value = newValue;
  753. trigger();
  754. clearTimeout(timer);
  755. timer = resetAfter();
  756. }
  757. };
  758. });
  759. }
  760. /** @deprecated use `refAutoReset` instead */
  761. const autoResetRef = refAutoReset;
  762. //#endregion
  763. //#region useDebounceFn/index.ts
  764. /**
  765. * Debounce execution of a function.
  766. *
  767. * @see https://vueuse.org/useDebounceFn
  768. * @param fn A function to be executed after delay milliseconds debounced.
  769. * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
  770. * @param options Options
  771. *
  772. * @return A new, debounce, function.
  773. *
  774. * @__NO_SIDE_EFFECTS__
  775. */
  776. function useDebounceFn(fn, ms = 200, options = {}) {
  777. return createFilterWrapper(debounceFilter(ms, options), fn);
  778. }
  779. //#endregion
  780. //#region refDebounced/index.ts
  781. /**
  782. * Debounce updates of a ref.
  783. *
  784. * @return A new debounced ref.
  785. */
  786. function refDebounced(value, ms = 200, options = {}) {
  787. const debounced = ref(toValue(value));
  788. const updater = useDebounceFn(() => {
  789. debounced.value = value.value;
  790. }, ms, options);
  791. watch(value, () => updater());
  792. return shallowReadonly(debounced);
  793. }
  794. /** @deprecated use `refDebounced` instead */
  795. const debouncedRef = refDebounced;
  796. /** @deprecated use `refDebounced` instead */
  797. const useDebounce = refDebounced;
  798. //#endregion
  799. //#region refDefault/index.ts
  800. /**
  801. * Apply default value to a ref.
  802. *
  803. * @__NO_SIDE_EFFECTS__
  804. */
  805. function refDefault(source, defaultValue) {
  806. return computed({
  807. get() {
  808. var _source$value;
  809. return (_source$value = source.value) !== null && _source$value !== void 0 ? _source$value : defaultValue;
  810. },
  811. set(value) {
  812. source.value = value;
  813. }
  814. });
  815. }
  816. //#endregion
  817. //#region refManualReset/index.ts
  818. /**
  819. * Create a ref with manual reset functionality.
  820. *
  821. * @see https://vueuse.org/refManualReset
  822. * @param defaultValue The value which will be set.
  823. */
  824. function refManualReset(defaultValue) {
  825. let value = toValue(defaultValue);
  826. let trigger;
  827. const reset = () => {
  828. value = toValue(defaultValue);
  829. trigger();
  830. };
  831. const refValue = customRef((track, _trigger) => {
  832. trigger = _trigger;
  833. return {
  834. get() {
  835. track();
  836. return value;
  837. },
  838. set(newValue) {
  839. value = newValue;
  840. trigger();
  841. }
  842. };
  843. });
  844. refValue.reset = reset;
  845. return refValue;
  846. }
  847. //#endregion
  848. //#region useThrottleFn/index.ts
  849. /**
  850. * Throttle execution of a function. Especially useful for rate limiting
  851. * execution of handlers on events like resize and scroll.
  852. *
  853. * @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
  854. * to `callback` when the throttled-function is executed.
  855. * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
  856. * (default value: 200)
  857. *
  858. * @param [trailing] if true, call fn again after the time is up (default value: false)
  859. *
  860. * @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)
  861. *
  862. * @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)
  863. *
  864. * @return A new, throttled, function.
  865. *
  866. * @__NO_SIDE_EFFECTS__
  867. */
  868. function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
  869. return createFilterWrapper(throttleFilter(ms, trailing, leading, rejectOnCancel), fn);
  870. }
  871. //#endregion
  872. //#region refThrottled/index.ts
  873. /**
  874. * Throttle execution of a function. Especially useful for rate limiting
  875. * execution of handlers on events like resize and scroll.
  876. *
  877. * @param value Ref value to be watched with throttle effect
  878. * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
  879. * @param trailing if true, update the value again after the delay time is up
  880. * @param leading if true, update the value on the leading edge of the ms timeout
  881. */
  882. function refThrottled(value, delay = 200, trailing = true, leading = true) {
  883. if (delay <= 0) return value;
  884. const throttled = ref(toValue(value));
  885. const updater = useThrottleFn(() => {
  886. throttled.value = value.value;
  887. }, delay, trailing, leading);
  888. watch(value, () => updater());
  889. return throttled;
  890. }
  891. /** @deprecated use `refThrottled` instead */
  892. const throttledRef = refThrottled;
  893. /** @deprecated use `refThrottled` instead */
  894. const useThrottle = refThrottled;
  895. //#endregion
  896. //#region refWithControl/index.ts
  897. /**
  898. * Fine-grained controls over ref and its reactivity.
  899. *
  900. * @__NO_SIDE_EFFECTS__
  901. */
  902. function refWithControl(initial, options = {}) {
  903. let source = initial;
  904. let track;
  905. let trigger;
  906. const ref = customRef((_track, _trigger) => {
  907. track = _track;
  908. trigger = _trigger;
  909. return {
  910. get() {
  911. return get();
  912. },
  913. set(v) {
  914. set(v);
  915. }
  916. };
  917. });
  918. function get(tracking = true) {
  919. if (tracking) track();
  920. return source;
  921. }
  922. function set(value, triggering = true) {
  923. var _options$onBeforeChan, _options$onChanged;
  924. if (value === source) return;
  925. const old = source;
  926. if (((_options$onBeforeChan = options.onBeforeChange) === null || _options$onBeforeChan === void 0 ? void 0 : _options$onBeforeChan.call(options, value, old)) === false) return;
  927. source = value;
  928. (_options$onChanged = options.onChanged) === null || _options$onChanged === void 0 || _options$onChanged.call(options, value, old);
  929. if (triggering) trigger();
  930. }
  931. /**
  932. * Get the value without tracked in the reactivity system
  933. */
  934. const untrackedGet = () => get(false);
  935. /**
  936. * Set the value without triggering the reactivity system
  937. */
  938. const silentSet = (v) => set(v, false);
  939. /**
  940. * Get the value without tracked in the reactivity system.
  941. *
  942. * Alias for `untrackedGet()`
  943. */
  944. const peek = () => get(false);
  945. /**
  946. * Set the value without triggering the reactivity system
  947. *
  948. * Alias for `silentSet(v)`
  949. */
  950. const lay = (v) => set(v, false);
  951. return extendRef(ref, {
  952. get,
  953. set,
  954. untrackedGet,
  955. silentSet,
  956. peek,
  957. lay
  958. }, { enumerable: true });
  959. }
  960. /** @deprecated use `refWithControl` instead */
  961. const controlledRef = refWithControl;
  962. //#endregion
  963. //#region set/index.ts
  964. /**
  965. * Shorthand for `ref.value = x`
  966. */
  967. function set(...args) {
  968. if (args.length === 2) {
  969. const [ref, value] = args;
  970. ref.value = value;
  971. }
  972. if (args.length === 3) {
  973. const [target, key, value] = args;
  974. target[key] = value;
  975. }
  976. }
  977. //#endregion
  978. //#region watchWithFilter/index.ts
  979. function watchWithFilter(source, cb, options = {}) {
  980. const { eventFilter = bypassFilter, ...watchOptions } = options;
  981. return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
  982. }
  983. //#endregion
  984. //#region watchPausable/index.ts
  985. /** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */
  986. function watchPausable(source, cb, options = {}) {
  987. const { eventFilter: filter, initialState = "active", ...watchOptions } = options;
  988. const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
  989. return {
  990. stop: watchWithFilter(source, cb, {
  991. ...watchOptions,
  992. eventFilter
  993. }),
  994. pause,
  995. resume,
  996. isActive
  997. };
  998. }
  999. /** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */
  1000. const pausableWatch = watchPausable;
  1001. //#endregion
  1002. //#region syncRef/index.ts
  1003. /**
  1004. * Two-way refs synchronization.
  1005. * From the set theory perspective to restrict the option's type
  1006. * Check in the following order:
  1007. * 1. L = R
  1008. * 2. L ∩ R ≠ ∅
  1009. * 3. L ⊆ R
  1010. * 4. L ∩ R = ∅
  1011. */
  1012. function syncRef(left, right, ...[options]) {
  1013. const { flush = "sync", deep = false, immediate = true, direction = "both", transform = {} } = options || {};
  1014. const watchers = [];
  1015. const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
  1016. const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
  1017. if (direction === "both" || direction === "ltr") watchers.push(watchPausable(left, (newValue) => {
  1018. watchers.forEach((w) => w.pause());
  1019. right.value = transformLTR(newValue);
  1020. watchers.forEach((w) => w.resume());
  1021. }, {
  1022. flush,
  1023. deep,
  1024. immediate
  1025. }));
  1026. if (direction === "both" || direction === "rtl") watchers.push(watchPausable(right, (newValue) => {
  1027. watchers.forEach((w) => w.pause());
  1028. left.value = transformRTL(newValue);
  1029. watchers.forEach((w) => w.resume());
  1030. }, {
  1031. flush,
  1032. deep,
  1033. immediate
  1034. }));
  1035. const stop = () => {
  1036. watchers.forEach((w) => w.stop());
  1037. };
  1038. return stop;
  1039. }
  1040. //#endregion
  1041. //#region syncRefs/index.ts
  1042. /**
  1043. * Keep target ref(s) in sync with the source ref
  1044. *
  1045. * @param source source ref
  1046. * @param targets
  1047. */
  1048. function syncRefs(source, targets, options = {}) {
  1049. const { flush = "sync", deep = false, immediate = true } = options;
  1050. const targetsArray = toArray(targets);
  1051. return watch(source, (newValue) => targetsArray.forEach((target) => target.value = newValue), {
  1052. flush,
  1053. deep,
  1054. immediate
  1055. });
  1056. }
  1057. //#endregion
  1058. //#region toRefs/index.ts
  1059. /**
  1060. * Extended `toRefs` that also accepts refs of an object.
  1061. *
  1062. * @see https://vueuse.org/toRefs
  1063. * @param objectRef A ref or normal object or array.
  1064. * @param options Options
  1065. */
  1066. function toRefs(objectRef, options = {}) {
  1067. if (!isRef(objectRef)) return toRefs$1(objectRef);
  1068. const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
  1069. for (const key in objectRef.value) result[key] = customRef(() => ({
  1070. get() {
  1071. return objectRef.value[key];
  1072. },
  1073. set(v) {
  1074. var _toValue;
  1075. if ((_toValue = toValue(options.replaceRef)) !== null && _toValue !== void 0 ? _toValue : true) if (Array.isArray(objectRef.value)) {
  1076. const copy = [...objectRef.value];
  1077. copy[key] = v;
  1078. objectRef.value = copy;
  1079. } else {
  1080. const newObject = {
  1081. ...objectRef.value,
  1082. [key]: v
  1083. };
  1084. Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
  1085. objectRef.value = newObject;
  1086. }
  1087. else objectRef.value[key] = v;
  1088. }
  1089. }));
  1090. return result;
  1091. }
  1092. //#endregion
  1093. //#region tryOnBeforeMount/index.ts
  1094. /**
  1095. * Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function
  1096. *
  1097. * @param fn
  1098. * @param sync if set to false, it will run in the nextTick() of Vue
  1099. * @param target
  1100. */
  1101. function tryOnBeforeMount(fn, sync = true, target) {
  1102. if (getLifeCycleTarget(target)) onBeforeMount(fn, target);
  1103. else if (sync) fn();
  1104. else nextTick(fn);
  1105. }
  1106. //#endregion
  1107. //#region tryOnBeforeUnmount/index.ts
  1108. /**
  1109. * Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
  1110. *
  1111. * @param fn
  1112. * @param target
  1113. */
  1114. function tryOnBeforeUnmount(fn, target) {
  1115. if (getLifeCycleTarget(target)) onBeforeUnmount(fn, target);
  1116. }
  1117. //#endregion
  1118. //#region tryOnMounted/index.ts
  1119. /**
  1120. * Call onMounted() if it's inside a component lifecycle, if not, just call the function
  1121. *
  1122. * @param fn
  1123. * @param sync if set to false, it will run in the nextTick() of Vue
  1124. * @param target
  1125. */
  1126. function tryOnMounted(fn, sync = true, target) {
  1127. if (getLifeCycleTarget(target)) onMounted(fn, target);
  1128. else if (sync) fn();
  1129. else nextTick(fn);
  1130. }
  1131. //#endregion
  1132. //#region tryOnUnmounted/index.ts
  1133. /**
  1134. * Call onUnmounted() if it's inside a component lifecycle, if not, do nothing
  1135. *
  1136. * @param fn
  1137. * @param target
  1138. */
  1139. function tryOnUnmounted(fn, target) {
  1140. if (getLifeCycleTarget(target)) onUnmounted(fn, target);
  1141. }
  1142. //#endregion
  1143. //#region until/index.ts
  1144. function createUntil(r, isNot = false) {
  1145. function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
  1146. let stop = null;
  1147. const promises = [new Promise((resolve) => {
  1148. stop = watch(r, (v) => {
  1149. if (condition(v) !== isNot) {
  1150. if (stop) stop();
  1151. else nextTick(() => stop === null || stop === void 0 ? void 0 : stop());
  1152. resolve(v);
  1153. }
  1154. }, {
  1155. flush,
  1156. deep,
  1157. immediate: true
  1158. });
  1159. })];
  1160. if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop === null || stop === void 0 ? void 0 : stop()));
  1161. return Promise.race(promises);
  1162. }
  1163. function toBe(value, options) {
  1164. if (!isRef(value)) return toMatch((v) => v === value, options);
  1165. const { flush = "sync", deep = false, timeout, throwOnTimeout } = options !== null && options !== void 0 ? options : {};
  1166. let stop = null;
  1167. const promises = [new Promise((resolve) => {
  1168. stop = watch([r, value], ([v1, v2]) => {
  1169. if (isNot !== (v1 === v2)) {
  1170. if (stop) stop();
  1171. else nextTick(() => stop === null || stop === void 0 ? void 0 : stop());
  1172. resolve(v1);
  1173. }
  1174. }, {
  1175. flush,
  1176. deep,
  1177. immediate: true
  1178. });
  1179. })];
  1180. if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
  1181. stop === null || stop === void 0 || stop();
  1182. return toValue(r);
  1183. }));
  1184. return Promise.race(promises);
  1185. }
  1186. function toBeTruthy(options) {
  1187. return toMatch((v) => Boolean(v), options);
  1188. }
  1189. function toBeNull(options) {
  1190. return toBe(null, options);
  1191. }
  1192. function toBeUndefined(options) {
  1193. return toBe(void 0, options);
  1194. }
  1195. function toBeNaN(options) {
  1196. return toMatch(Number.isNaN, options);
  1197. }
  1198. function toContains(value, options) {
  1199. return toMatch((v) => {
  1200. const array = Array.from(v);
  1201. return array.includes(value) || array.includes(toValue(value));
  1202. }, options);
  1203. }
  1204. function changed(options) {
  1205. return changedTimes(1, options);
  1206. }
  1207. function changedTimes(n = 1, options) {
  1208. let count = -1;
  1209. return toMatch(() => {
  1210. count += 1;
  1211. return count >= n;
  1212. }, options);
  1213. }
  1214. if (Array.isArray(toValue(r))) return {
  1215. toMatch,
  1216. toContains,
  1217. changed,
  1218. changedTimes,
  1219. get not() {
  1220. return createUntil(r, !isNot);
  1221. }
  1222. };
  1223. else return {
  1224. toMatch,
  1225. toBe,
  1226. toBeTruthy,
  1227. toBeNull,
  1228. toBeNaN,
  1229. toBeUndefined,
  1230. changed,
  1231. changedTimes,
  1232. get not() {
  1233. return createUntil(r, !isNot);
  1234. }
  1235. };
  1236. }
  1237. function until(r) {
  1238. return createUntil(r);
  1239. }
  1240. //#endregion
  1241. //#region useArrayDifference/index.ts
  1242. function defaultComparator(value, othVal) {
  1243. return value === othVal;
  1244. }
  1245. /**
  1246. * Reactive get array difference of two array
  1247. * @see https://vueuse.org/useArrayDifference
  1248. * @returns - the difference of two array
  1249. * @param args
  1250. *
  1251. * @__NO_SIDE_EFFECTS__
  1252. */
  1253. function useArrayDifference(...args) {
  1254. var _args$, _args$2;
  1255. const list = args[0];
  1256. const values = args[1];
  1257. let compareFn = (_args$ = args[2]) !== null && _args$ !== void 0 ? _args$ : defaultComparator;
  1258. const { symmetric = false } = (_args$2 = args[3]) !== null && _args$2 !== void 0 ? _args$2 : {};
  1259. if (typeof compareFn === "string") {
  1260. const key = compareFn;
  1261. compareFn = (value, othVal) => value[key] === othVal[key];
  1262. }
  1263. const diff1 = computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
  1264. if (symmetric) {
  1265. const diff2 = computed(() => toValue(values).filter((x) => toValue(list).findIndex((y) => compareFn(x, y)) === -1));
  1266. return computed(() => symmetric ? [...toValue(diff1), ...toValue(diff2)] : toValue(diff1));
  1267. } else return diff1;
  1268. }
  1269. //#endregion
  1270. //#region useArrayEvery/index.ts
  1271. /**
  1272. * Reactive `Array.every`
  1273. *
  1274. * @see https://vueuse.org/useArrayEvery
  1275. * @param list - the array was called upon.
  1276. * @param fn - a function to test each element.
  1277. *
  1278. * @returns **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**.
  1279. *
  1280. * @__NO_SIDE_EFFECTS__
  1281. */
  1282. function useArrayEvery(list, fn) {
  1283. return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
  1284. }
  1285. //#endregion
  1286. //#region useArrayFilter/index.ts
  1287. /**
  1288. * Reactive `Array.filter`
  1289. *
  1290. * @see https://vueuse.org/useArrayFilter
  1291. * @param list - the array was called upon.
  1292. * @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
  1293. *
  1294. * @returns a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned.
  1295. *
  1296. * @__NO_SIDE_EFFECTS__
  1297. */
  1298. function useArrayFilter(list, fn) {
  1299. return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
  1300. }
  1301. //#endregion
  1302. //#region useArrayFind/index.ts
  1303. /**
  1304. * Reactive `Array.find`
  1305. *
  1306. * @see https://vueuse.org/useArrayFind
  1307. * @param list - the array was called upon.
  1308. * @param fn - a function to test each element.
  1309. *
  1310. * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
  1311. *
  1312. * @__NO_SIDE_EFFECTS__
  1313. */
  1314. function useArrayFind(list, fn) {
  1315. return computed(() => toValue(toValue(list).find((element, index, array) => fn(toValue(element), index, array))));
  1316. }
  1317. //#endregion
  1318. //#region useArrayFindIndex/index.ts
  1319. /**
  1320. * Reactive `Array.findIndex`
  1321. *
  1322. * @see https://vueuse.org/useArrayFindIndex
  1323. * @param list - the array was called upon.
  1324. * @param fn - a function to test each element.
  1325. *
  1326. * @returns the index of the first element in the array that passes the test. Otherwise, "-1".
  1327. *
  1328. * @__NO_SIDE_EFFECTS__
  1329. */
  1330. function useArrayFindIndex(list, fn) {
  1331. return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
  1332. }
  1333. //#endregion
  1334. //#region useArrayFindLast/index.ts
  1335. function findLast(arr, cb) {
  1336. let index = arr.length;
  1337. while (index-- > 0) if (cb(arr[index], index, arr)) return arr[index];
  1338. }
  1339. /**
  1340. * Reactive `Array.findLast`
  1341. *
  1342. * @see https://vueuse.org/useArrayFindLast
  1343. * @param list - the array was called upon.
  1344. * @param fn - a function to test each element.
  1345. *
  1346. * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
  1347. *
  1348. * @__NO_SIDE_EFFECTS__
  1349. */
  1350. function useArrayFindLast(list, fn) {
  1351. return computed(() => toValue(!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))));
  1352. }
  1353. //#endregion
  1354. //#region useArrayIncludes/index.ts
  1355. function isArrayIncludesOptions(obj) {
  1356. return isObject(obj) && containsProp(obj, "formIndex", "comparator");
  1357. }
  1358. /**
  1359. * Reactive `Array.includes`
  1360. *
  1361. * @see https://vueuse.org/useArrayIncludes
  1362. *
  1363. * @returns true if the `value` is found in the array. Otherwise, false.
  1364. *
  1365. * @__NO_SIDE_EFFECTS__
  1366. */
  1367. function useArrayIncludes(...args) {
  1368. var _comparator;
  1369. const list = args[0];
  1370. const value = args[1];
  1371. let comparator = args[2];
  1372. let formIndex = 0;
  1373. if (isArrayIncludesOptions(comparator)) {
  1374. var _comparator$fromIndex;
  1375. formIndex = (_comparator$fromIndex = comparator.fromIndex) !== null && _comparator$fromIndex !== void 0 ? _comparator$fromIndex : 0;
  1376. comparator = comparator.comparator;
  1377. }
  1378. if (typeof comparator === "string") {
  1379. const key = comparator;
  1380. comparator = (element, value) => element[key] === toValue(value);
  1381. }
  1382. comparator = (_comparator = comparator) !== null && _comparator !== void 0 ? _comparator : ((element, value) => element === toValue(value));
  1383. return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(toValue(element), toValue(value), index, toValue(array))));
  1384. }
  1385. //#endregion
  1386. //#region useArrayJoin/index.ts
  1387. /**
  1388. * Reactive `Array.join`
  1389. *
  1390. * @see https://vueuse.org/useArrayJoin
  1391. * @param list - the array was called upon.
  1392. * @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (",").
  1393. *
  1394. * @returns a string with all array elements joined. If arr.length is 0, the empty string is returned.
  1395. *
  1396. * @__NO_SIDE_EFFECTS__
  1397. */
  1398. function useArrayJoin(list, separator) {
  1399. return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
  1400. }
  1401. //#endregion
  1402. //#region useArrayMap/index.ts
  1403. /**
  1404. * Reactive `Array.map`
  1405. *
  1406. * @see https://vueuse.org/useArrayMap
  1407. * @param list - the array was called upon.
  1408. * @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
  1409. *
  1410. * @returns a new array with each element being the result of the callback function.
  1411. *
  1412. * @__NO_SIDE_EFFECTS__
  1413. */
  1414. function useArrayMap(list, fn) {
  1415. return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
  1416. }
  1417. //#endregion
  1418. //#region useArrayReduce/index.ts
  1419. /**
  1420. * Reactive `Array.reduce`
  1421. *
  1422. * @see https://vueuse.org/useArrayReduce
  1423. * @param list - the array was called upon.
  1424. * @param reducer - a "reducer" function.
  1425. * @param args
  1426. *
  1427. * @returns the value that results from running the "reducer" callback function to completion over the entire array.
  1428. *
  1429. * @__NO_SIDE_EFFECTS__
  1430. */
  1431. function useArrayReduce(list, reducer, ...args) {
  1432. const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
  1433. return computed(() => {
  1434. const resolved = toValue(list);
  1435. return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
  1436. });
  1437. }
  1438. //#endregion
  1439. //#region useArraySome/index.ts
  1440. /**
  1441. * Reactive `Array.some`
  1442. *
  1443. * @see https://vueuse.org/useArraySome
  1444. * @param list - the array was called upon.
  1445. * @param fn - a function to test each element.
  1446. *
  1447. * @returns **true** if the `fn` function returns a **truthy** value for any element from the array. Otherwise, **false**.
  1448. *
  1449. * @__NO_SIDE_EFFECTS__
  1450. */
  1451. function useArraySome(list, fn) {
  1452. return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
  1453. }
  1454. //#endregion
  1455. //#region useArrayUnique/index.ts
  1456. function uniq(array) {
  1457. return Array.from(new Set(array));
  1458. }
  1459. function uniqueElementsBy(array, fn) {
  1460. return array.reduce((acc, v) => {
  1461. if (!acc.some((x) => fn(v, x, array))) acc.push(v);
  1462. return acc;
  1463. }, []);
  1464. }
  1465. /**
  1466. * reactive unique array
  1467. * @see https://vueuse.org/useArrayUnique
  1468. * @param list - the array was called upon.
  1469. * @param compareFn
  1470. * @returns A computed ref that returns a unique array of items.
  1471. *
  1472. * @__NO_SIDE_EFFECTS__
  1473. */
  1474. function useArrayUnique(list, compareFn) {
  1475. return computed(() => {
  1476. const resolvedList = toValue(list).map((element) => toValue(element));
  1477. return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
  1478. });
  1479. }
  1480. //#endregion
  1481. //#region useCounter/index.ts
  1482. /**
  1483. * Basic counter with utility functions.
  1484. *
  1485. * @see https://vueuse.org/useCounter
  1486. * @param [initialValue]
  1487. * @param options
  1488. */
  1489. function useCounter(initialValue = 0, options = {}) {
  1490. let _initialValue = unref(initialValue);
  1491. const count = shallowRef(initialValue);
  1492. const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } = options;
  1493. const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
  1494. const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
  1495. const get = () => count.value;
  1496. const set = (val) => count.value = Math.max(min, Math.min(max, val));
  1497. const reset = (val = _initialValue) => {
  1498. _initialValue = val;
  1499. return set(val);
  1500. };
  1501. return {
  1502. count: shallowReadonly(count),
  1503. inc,
  1504. dec,
  1505. get,
  1506. set,
  1507. reset
  1508. };
  1509. }
  1510. //#endregion
  1511. //#region useDateFormat/index.ts
  1512. const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
  1513. 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}|z{1,4}|SSS/g;
  1514. function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
  1515. let m = hours < 12 ? "AM" : "PM";
  1516. if (hasPeriod) m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
  1517. return isLowercase ? m.toLowerCase() : m;
  1518. }
  1519. function formatOrdinal(num) {
  1520. const suffixes = [
  1521. "th",
  1522. "st",
  1523. "nd",
  1524. "rd"
  1525. ];
  1526. const v = num % 100;
  1527. return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
  1528. }
  1529. function formatDate(date, formatStr, options = {}) {
  1530. var _options$customMeridi;
  1531. const years = date.getFullYear();
  1532. const month = date.getMonth();
  1533. const days = date.getDate();
  1534. const hours = date.getHours();
  1535. const minutes = date.getMinutes();
  1536. const seconds = date.getSeconds();
  1537. const milliseconds = date.getMilliseconds();
  1538. const day = date.getDay();
  1539. const meridiem = (_options$customMeridi = options.customMeridiem) !== null && _options$customMeridi !== void 0 ? _options$customMeridi : defaultMeridiem;
  1540. const stripTimeZone = (dateString) => {
  1541. var _dateString$split$;
  1542. return (_dateString$split$ = dateString.split(" ")[1]) !== null && _dateString$split$ !== void 0 ? _dateString$split$ : "";
  1543. };
  1544. const matches = {
  1545. Yo: () => formatOrdinal(years),
  1546. YY: () => String(years).slice(-2),
  1547. YYYY: () => years,
  1548. M: () => month + 1,
  1549. Mo: () => formatOrdinal(month + 1),
  1550. MM: () => `${month + 1}`.padStart(2, "0"),
  1551. MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
  1552. MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
  1553. D: () => String(days),
  1554. Do: () => formatOrdinal(days),
  1555. DD: () => `${days}`.padStart(2, "0"),
  1556. H: () => String(hours),
  1557. Ho: () => formatOrdinal(hours),
  1558. HH: () => `${hours}`.padStart(2, "0"),
  1559. h: () => `${hours % 12 || 12}`.padStart(1, "0"),
  1560. ho: () => formatOrdinal(hours % 12 || 12),
  1561. hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
  1562. m: () => String(minutes),
  1563. mo: () => formatOrdinal(minutes),
  1564. mm: () => `${minutes}`.padStart(2, "0"),
  1565. s: () => String(seconds),
  1566. so: () => formatOrdinal(seconds),
  1567. ss: () => `${seconds}`.padStart(2, "0"),
  1568. SSS: () => `${milliseconds}`.padStart(3, "0"),
  1569. d: () => day,
  1570. dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
  1571. ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
  1572. dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
  1573. A: () => meridiem(hours, minutes),
  1574. AA: () => meridiem(hours, minutes, false, true),
  1575. a: () => meridiem(hours, minutes, true),
  1576. aa: () => meridiem(hours, minutes, true, true),
  1577. z: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
  1578. zz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
  1579. zzz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
  1580. zzzz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "longOffset" }))
  1581. };
  1582. return formatStr.replace(REGEX_FORMAT, (match, $1) => {
  1583. var _ref, _matches$match;
  1584. return (_ref = $1 !== null && $1 !== void 0 ? $1 : (_matches$match = matches[match]) === null || _matches$match === void 0 ? void 0 : _matches$match.call(matches)) !== null && _ref !== void 0 ? _ref : match;
  1585. });
  1586. }
  1587. function normalizeDate(date) {
  1588. if (date === null) return /* @__PURE__ */ new Date(NaN);
  1589. if (date === void 0) return /* @__PURE__ */ new Date();
  1590. if (date instanceof Date) return new Date(date);
  1591. if (typeof date === "string" && !/Z$/i.test(date)) {
  1592. const d = date.match(REGEX_PARSE);
  1593. if (d) {
  1594. const m = d[2] - 1 || 0;
  1595. const ms = (d[7] || "0").substring(0, 3);
  1596. return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
  1597. }
  1598. }
  1599. return new Date(date);
  1600. }
  1601. /**
  1602. * Get the formatted date according to the string of tokens passed in.
  1603. *
  1604. * @see https://vueuse.org/useDateFormat
  1605. * @param date - The date to format, can either be a `Date` object, a timestamp, or a string
  1606. * @param formatStr - The combination of tokens to format the date
  1607. * @param options - UseDateFormatOptions
  1608. *
  1609. * @__NO_SIDE_EFFECTS__
  1610. */
  1611. function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
  1612. return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
  1613. }
  1614. //#endregion
  1615. //#region useIntervalFn/index.ts
  1616. /**
  1617. * Wrapper for `setInterval` with controls
  1618. *
  1619. * @see https://vueuse.org/useIntervalFn
  1620. * @param cb
  1621. * @param interval
  1622. * @param options
  1623. */
  1624. function useIntervalFn(cb, interval = 1e3, options = {}) {
  1625. const { immediate = true, immediateCallback = false } = options;
  1626. let timer = null;
  1627. const isActive = shallowRef(false);
  1628. function clean() {
  1629. if (timer) {
  1630. clearInterval(timer);
  1631. timer = null;
  1632. }
  1633. }
  1634. function pause() {
  1635. isActive.value = false;
  1636. clean();
  1637. }
  1638. function resume() {
  1639. const intervalValue = toValue(interval);
  1640. if (intervalValue <= 0) return;
  1641. isActive.value = true;
  1642. if (immediateCallback) cb();
  1643. clean();
  1644. if (isActive.value) timer = setInterval(cb, intervalValue);
  1645. }
  1646. if (immediate && isClient) resume();
  1647. if (isRef(interval) || typeof interval === "function") tryOnScopeDispose(watch(interval, () => {
  1648. if (isActive.value && isClient) resume();
  1649. }));
  1650. tryOnScopeDispose(pause);
  1651. return {
  1652. isActive: shallowReadonly(isActive),
  1653. pause,
  1654. resume
  1655. };
  1656. }
  1657. //#endregion
  1658. //#region useInterval/index.ts
  1659. function useInterval(interval = 1e3, options = {}) {
  1660. const { controls: exposeControls = false, immediate = true, callback } = options;
  1661. const counter = shallowRef(0);
  1662. const update = () => counter.value += 1;
  1663. const reset = () => {
  1664. counter.value = 0;
  1665. };
  1666. const controls = useIntervalFn(callback ? () => {
  1667. update();
  1668. callback(counter.value);
  1669. } : update, interval, { immediate });
  1670. if (exposeControls) return {
  1671. counter: shallowReadonly(counter),
  1672. reset,
  1673. ...controls
  1674. };
  1675. else return shallowReadonly(counter);
  1676. }
  1677. //#endregion
  1678. //#region useLastChanged/index.ts
  1679. function useLastChanged(source, options = {}) {
  1680. var _options$initialValue;
  1681. const ms = shallowRef((_options$initialValue = options.initialValue) !== null && _options$initialValue !== void 0 ? _options$initialValue : null);
  1682. watch(source, () => ms.value = timestamp(), options);
  1683. return shallowReadonly(ms);
  1684. }
  1685. //#endregion
  1686. //#region useTimeoutFn/index.ts
  1687. /**
  1688. * Wrapper for `setTimeout` with controls.
  1689. *
  1690. * @param cb
  1691. * @param interval
  1692. * @param options
  1693. */
  1694. function useTimeoutFn(cb, interval, options = {}) {
  1695. const { immediate = true, immediateCallback = false } = options;
  1696. const isPending = shallowRef(false);
  1697. let timer;
  1698. function clear() {
  1699. if (timer) {
  1700. clearTimeout(timer);
  1701. timer = void 0;
  1702. }
  1703. }
  1704. function stop() {
  1705. isPending.value = false;
  1706. clear();
  1707. }
  1708. function start(...args) {
  1709. if (immediateCallback) cb();
  1710. clear();
  1711. isPending.value = true;
  1712. timer = setTimeout(() => {
  1713. isPending.value = false;
  1714. timer = void 0;
  1715. cb(...args);
  1716. }, toValue(interval));
  1717. }
  1718. if (immediate) {
  1719. isPending.value = true;
  1720. if (isClient) start();
  1721. }
  1722. tryOnScopeDispose(stop);
  1723. return {
  1724. isPending: shallowReadonly(isPending),
  1725. start,
  1726. stop
  1727. };
  1728. }
  1729. //#endregion
  1730. //#region useTimeout/index.ts
  1731. function useTimeout(interval = 1e3, options = {}) {
  1732. const { controls: exposeControls = false, callback } = options;
  1733. const controls = useTimeoutFn(callback !== null && callback !== void 0 ? callback : noop, interval, options);
  1734. const ready = computed(() => !controls.isPending.value);
  1735. if (exposeControls) return {
  1736. ready,
  1737. ...controls
  1738. };
  1739. else return ready;
  1740. }
  1741. //#endregion
  1742. //#region useToNumber/index.ts
  1743. /**
  1744. * Reactively convert a string ref to number.
  1745. *
  1746. * @__NO_SIDE_EFFECTS__
  1747. */
  1748. function useToNumber(value, options = {}) {
  1749. const { method = "parseFloat", radix, nanToZero } = options;
  1750. return computed(() => {
  1751. let resolved = toValue(value);
  1752. if (typeof method === "function") resolved = method(resolved);
  1753. else if (typeof resolved === "string") resolved = Number[method](resolved, radix);
  1754. if (nanToZero && Number.isNaN(resolved)) resolved = 0;
  1755. return resolved;
  1756. });
  1757. }
  1758. //#endregion
  1759. //#region useToString/index.ts
  1760. /**
  1761. * Reactively convert a ref to string.
  1762. *
  1763. * @see https://vueuse.org/useToString
  1764. *
  1765. * @__NO_SIDE_EFFECTS__
  1766. */
  1767. function useToString(value) {
  1768. return computed(() => `${toValue(value)}`);
  1769. }
  1770. //#endregion
  1771. //#region useToggle/index.ts
  1772. /**
  1773. * A boolean ref with a toggler
  1774. *
  1775. * @see https://vueuse.org/useToggle
  1776. * @param [initialValue]
  1777. * @param options
  1778. *
  1779. * @__NO_SIDE_EFFECTS__
  1780. */
  1781. function useToggle(initialValue = false, options = {}) {
  1782. const { truthyValue = true, falsyValue = false } = options;
  1783. const valueIsRef = isRef(initialValue);
  1784. const _value = shallowRef(initialValue);
  1785. function toggle(value) {
  1786. if (arguments.length) {
  1787. _value.value = value;
  1788. return _value.value;
  1789. } else {
  1790. const truthy = toValue(truthyValue);
  1791. _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
  1792. return _value.value;
  1793. }
  1794. }
  1795. if (valueIsRef) return toggle;
  1796. else return [_value, toggle];
  1797. }
  1798. //#endregion
  1799. //#region watchArray/index.ts
  1800. /**
  1801. * Watch for an array with additions and removals.
  1802. *
  1803. * @see https://vueuse.org/watchArray
  1804. */
  1805. function watchArray(source, cb, options) {
  1806. let oldList = (options === null || options === void 0 ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : toValue(source)];
  1807. return watch(source, (newList, _, onCleanup) => {
  1808. const oldListRemains = Array.from({ length: oldList.length });
  1809. const added = [];
  1810. for (const obj of newList) {
  1811. let found = false;
  1812. for (let i = 0; i < oldList.length; i++) if (!oldListRemains[i] && obj === oldList[i]) {
  1813. oldListRemains[i] = true;
  1814. found = true;
  1815. break;
  1816. }
  1817. if (!found) added.push(obj);
  1818. }
  1819. const removed = oldList.filter((_, i) => !oldListRemains[i]);
  1820. cb(newList, oldList, added, removed, onCleanup);
  1821. oldList = [...newList];
  1822. }, options);
  1823. }
  1824. //#endregion
  1825. //#region watchAtMost/index.ts
  1826. function watchAtMost(source, cb, options) {
  1827. const { count, ...watchOptions } = options;
  1828. const current = shallowRef(0);
  1829. const { stop, resume, pause } = watchWithFilter(source, (...args) => {
  1830. current.value += 1;
  1831. if (current.value >= toValue(count)) nextTick(() => stop());
  1832. cb(...args);
  1833. }, watchOptions);
  1834. return {
  1835. count: current,
  1836. stop,
  1837. resume,
  1838. pause
  1839. };
  1840. }
  1841. //#endregion
  1842. //#region watchDebounced/index.ts
  1843. function watchDebounced(source, cb, options = {}) {
  1844. const { debounce = 0, maxWait = void 0, ...watchOptions } = options;
  1845. return watchWithFilter(source, cb, {
  1846. ...watchOptions,
  1847. eventFilter: debounceFilter(debounce, { maxWait })
  1848. });
  1849. }
  1850. /** @deprecated use `watchDebounced` instead */
  1851. const debouncedWatch = watchDebounced;
  1852. //#endregion
  1853. //#region watchDeep/index.ts
  1854. /**
  1855. * Shorthand for watching value with {deep: true}
  1856. *
  1857. * @see https://vueuse.org/watchDeep
  1858. */
  1859. function watchDeep(source, cb, options) {
  1860. return watch(source, cb, {
  1861. ...options,
  1862. deep: true
  1863. });
  1864. }
  1865. //#endregion
  1866. //#region watchIgnorable/index.ts
  1867. function watchIgnorable(source, cb, options = {}) {
  1868. const { eventFilter = bypassFilter, ...watchOptions } = options;
  1869. const filteredCb = createFilterWrapper(eventFilter, cb);
  1870. let ignoreUpdates;
  1871. let ignorePrevAsyncUpdates;
  1872. let stop;
  1873. if (watchOptions.flush === "sync") {
  1874. let ignore = false;
  1875. ignorePrevAsyncUpdates = () => {};
  1876. ignoreUpdates = (updater) => {
  1877. ignore = true;
  1878. updater();
  1879. ignore = false;
  1880. };
  1881. stop = watch(source, (...args) => {
  1882. if (!ignore) filteredCb(...args);
  1883. }, watchOptions);
  1884. } else {
  1885. const disposables = [];
  1886. let ignoreCounter = 0;
  1887. let syncCounter = 0;
  1888. ignorePrevAsyncUpdates = () => {
  1889. ignoreCounter = syncCounter;
  1890. };
  1891. disposables.push(watch(source, () => {
  1892. syncCounter++;
  1893. }, {
  1894. ...watchOptions,
  1895. flush: "sync"
  1896. }));
  1897. ignoreUpdates = (updater) => {
  1898. const syncCounterPrev = syncCounter;
  1899. updater();
  1900. ignoreCounter += syncCounter - syncCounterPrev;
  1901. };
  1902. disposables.push(watch(source, (...args) => {
  1903. const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter;
  1904. ignoreCounter = 0;
  1905. syncCounter = 0;
  1906. if (ignore) return;
  1907. filteredCb(...args);
  1908. }, watchOptions));
  1909. stop = () => {
  1910. disposables.forEach((fn) => fn());
  1911. };
  1912. }
  1913. return {
  1914. stop,
  1915. ignoreUpdates,
  1916. ignorePrevAsyncUpdates
  1917. };
  1918. }
  1919. /** @deprecated use `watchIgnorable` instead */
  1920. const ignorableWatch = watchIgnorable;
  1921. //#endregion
  1922. //#region watchImmediate/index.ts
  1923. /**
  1924. * Shorthand for watching value with {immediate: true}
  1925. *
  1926. * @see https://vueuse.org/watchImmediate
  1927. */
  1928. function watchImmediate(source, cb, options) {
  1929. return watch(source, cb, {
  1930. ...options,
  1931. immediate: true
  1932. });
  1933. }
  1934. //#endregion
  1935. //#region watchOnce/index.ts
  1936. /**
  1937. * Shorthand for watching value with { once: true }
  1938. *
  1939. * @see https://vueuse.org/watchOnce
  1940. */
  1941. function watchOnce(source, cb, options) {
  1942. return watch(source, cb, {
  1943. ...options,
  1944. once: true
  1945. });
  1946. }
  1947. //#endregion
  1948. //#region watchThrottled/index.ts
  1949. function watchThrottled(source, cb, options = {}) {
  1950. const { throttle = 0, trailing = true, leading = true, ...watchOptions } = options;
  1951. return watchWithFilter(source, cb, {
  1952. ...watchOptions,
  1953. eventFilter: throttleFilter(throttle, trailing, leading)
  1954. });
  1955. }
  1956. /** @deprecated use `watchThrottled` instead */
  1957. const throttledWatch = watchThrottled;
  1958. //#endregion
  1959. //#region watchTriggerable/index.ts
  1960. function watchTriggerable(source, cb, options = {}) {
  1961. let cleanupFn;
  1962. function onEffect() {
  1963. if (!cleanupFn) return;
  1964. const fn = cleanupFn;
  1965. cleanupFn = void 0;
  1966. fn();
  1967. }
  1968. /** Register the function `cleanupFn` */
  1969. function onCleanup(callback) {
  1970. cleanupFn = callback;
  1971. }
  1972. const _cb = (value, oldValue) => {
  1973. onEffect();
  1974. return cb(value, oldValue, onCleanup);
  1975. };
  1976. const res = watchIgnorable(source, _cb, options);
  1977. const { ignoreUpdates } = res;
  1978. const trigger = () => {
  1979. let res;
  1980. ignoreUpdates(() => {
  1981. res = _cb(getWatchSources(source), getOldValue(source));
  1982. });
  1983. return res;
  1984. };
  1985. return {
  1986. ...res,
  1987. trigger
  1988. };
  1989. }
  1990. function getWatchSources(sources) {
  1991. if (isReactive(sources)) return sources;
  1992. if (Array.isArray(sources)) return sources.map((item) => toValue(item));
  1993. return toValue(sources);
  1994. }
  1995. function getOldValue(source) {
  1996. return Array.isArray(source) ? source.map(() => void 0) : void 0;
  1997. }
  1998. //#endregion
  1999. //#region whenever/index.ts
  2000. function whenever(source, cb, options) {
  2001. const stop = watch(source, (v, ov, onInvalidate) => {
  2002. if (v) {
  2003. if (options === null || options === void 0 ? void 0 : options.once) nextTick(() => stop());
  2004. cb(v, ov, onInvalidate);
  2005. }
  2006. }, {
  2007. ...options,
  2008. once: false
  2009. });
  2010. return stop;
  2011. }
  2012. //#endregion
  2013. export { assert, autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, controlledComputed, controlledRef, createDisposableDirective, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, createReactiveFn, createRef, createSharedComposable, createSingletonPromise, debounceFilter, debouncedRef, debouncedWatch, eagerComputed, extendRef, formatDate, get, getLifeCycleTarget, hasOwn, hyphenate, identity, ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, isWorker, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, pausableWatch, promiseTimeout, provideLocal, pxValue, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refManualReset, refThrottled, refWithControl, set, syncRef, syncRefs, throttleFilter, throttledRef, throttledWatch, timestamp, toArray, toReactive, toRef, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };