48759e2e28ed09134b55ea033985b1cdd4629959b06879b071c0733a395a9a56593c2082810b3db5eb63873c55585f63a72320a010794478d00f2ae4b1f910 51 KB

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