index.iife.js 66 KB

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