| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816 |
- var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
- if (VueDemi.install) {
- return VueDemi
- }
- if (!Vue) {
- console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
- return VueDemi
- }
- // Vue 2.7
- if (Vue.version.slice(0, 4) === '2.7.') {
- for (var key in Vue) {
- VueDemi[key] = Vue[key]
- }
- VueDemi.isVue2 = true
- VueDemi.isVue3 = false
- VueDemi.install = function () {}
- VueDemi.Vue = Vue
- VueDemi.Vue2 = Vue
- VueDemi.version = Vue.version
- VueDemi.warn = Vue.util.warn
- VueDemi.hasInjectionContext = function() {
- return !!VueDemi.getCurrentInstance()
- }
- function createApp(rootComponent, rootProps) {
- var vm
- var provide = {}
- var app = {
- config: Vue.config,
- use: Vue.use.bind(Vue),
- mixin: Vue.mixin.bind(Vue),
- component: Vue.component.bind(Vue),
- provide: function (key, value) {
- provide[key] = value
- return this
- },
- directive: function (name, dir) {
- if (dir) {
- Vue.directive(name, dir)
- return app
- } else {
- return Vue.directive(name)
- }
- },
- mount: function (el, hydrating) {
- if (!vm) {
- vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
- vm.$mount(el, hydrating)
- return vm
- } else {
- return vm
- }
- },
- unmount: function () {
- if (vm) {
- vm.$destroy()
- vm = undefined
- }
- },
- }
- return app
- }
- VueDemi.createApp = createApp
- }
- // Vue 2.6.x
- else if (Vue.version.slice(0, 2) === '2.') {
- if (VueCompositionAPI) {
- for (var key in VueCompositionAPI) {
- VueDemi[key] = VueCompositionAPI[key]
- }
- VueDemi.isVue2 = true
- VueDemi.isVue3 = false
- VueDemi.install = function () {}
- VueDemi.Vue = Vue
- VueDemi.Vue2 = Vue
- VueDemi.version = Vue.version
- VueDemi.hasInjectionContext = function() {
- return !!VueDemi.getCurrentInstance()
- }
- } else {
- console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
- }
- }
- // Vue 3
- else if (Vue.version.slice(0, 2) === '3.') {
- for (var key in Vue) {
- VueDemi[key] = Vue[key]
- }
- VueDemi.isVue2 = false
- VueDemi.isVue3 = true
- VueDemi.install = function () {}
- VueDemi.Vue = Vue
- VueDemi.Vue2 = undefined
- VueDemi.version = Vue.version
- VueDemi.set = function (target, key, val) {
- if (Array.isArray(target)) {
- target.length = Math.max(target.length, key)
- target.splice(key, 1, val)
- return val
- }
- target[key] = val
- return val
- }
- VueDemi.del = function (target, key) {
- if (Array.isArray(target)) {
- target.splice(key, 1)
- return
- }
- delete target[key]
- }
- } else {
- console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
- }
- return VueDemi
- })(
- ((globalThis || self).VueDemi = (globalThis || self).VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
- (globalThis || self).Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
- (globalThis || self).VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
- );
- ;
- ;(function (exports, vueDemi) {
- 'use strict';
- function computedEager(fn, options) {
- var _a;
- const result = vueDemi.shallowRef();
- vueDemi.watchEffect(() => {
- result.value = fn();
- }, {
- ...options,
- flush: (_a = options == null ? void 0 : options.flush) != null ? _a : "sync"
- });
- return vueDemi.readonly(result);
- }
- function computedWithControl(source, fn) {
- let v = void 0;
- let track;
- let trigger;
- const dirty = vueDemi.ref(true);
- const update = () => {
- dirty.value = true;
- trigger();
- };
- vueDemi.watch(source, update, { flush: "sync" });
- const get = typeof fn === "function" ? fn : fn.get;
- const set = typeof fn === "function" ? void 0 : fn.set;
- const result = vueDemi.customRef((_track, _trigger) => {
- track = _track;
- trigger = _trigger;
- return {
- get() {
- if (dirty.value) {
- v = get();
- dirty.value = false;
- }
- track();
- return v;
- },
- set(v2) {
- set == null ? void 0 : set(v2);
- }
- };
- });
- if (Object.isExtensible(result))
- result.trigger = update;
- return result;
- }
- function tryOnScopeDispose(fn) {
- if (vueDemi.getCurrentScope()) {
- vueDemi.onScopeDispose(fn);
- return true;
- }
- return false;
- }
- function createEventHook() {
- const fns = /* @__PURE__ */ new Set();
- const off = (fn) => {
- fns.delete(fn);
- };
- const on = (fn) => {
- fns.add(fn);
- const offFn = () => off(fn);
- tryOnScopeDispose(offFn);
- return {
- off: offFn
- };
- };
- const trigger = (...args) => {
- return Promise.all(Array.from(fns).map((fn) => fn(...args)));
- };
- return {
- on,
- off,
- trigger
- };
- }
- function createGlobalState(stateFactory) {
- let initialized = false;
- let state;
- const scope = vueDemi.effectScope(true);
- return (...args) => {
- if (!initialized) {
- state = scope.run(() => stateFactory(...args));
- initialized = true;
- }
- return state;
- };
- }
- const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
- const provideLocal = (key, value) => {
- var _a;
- const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
- if (instance == null)
- throw new Error("provideLocal must be called in setup");
- if (!localProvidedStateMap.has(instance))
- localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
- const localProvidedState = localProvidedStateMap.get(instance);
- localProvidedState[key] = value;
- vueDemi.provide(key, value);
- };
- const injectLocal = (...args) => {
- var _a;
- const key = args[0];
- const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
- if (instance == null)
- throw new Error("injectLocal must be called in setup");
- if (localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
- return localProvidedStateMap.get(instance)[key];
- return vueDemi.inject(...args);
- };
- function createInjectionState(composable, options) {
- const key = (options == null ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
- const defaultValue = options == null ? void 0 : options.defaultValue;
- const useProvidingState = (...args) => {
- const state = composable(...args);
- provideLocal(key, state);
- return state;
- };
- const useInjectedState = () => injectLocal(key, defaultValue);
- return [useProvidingState, useInjectedState];
- }
- function createSharedComposable(composable) {
- let subscribers = 0;
- let state;
- let scope;
- const dispose = () => {
- subscribers -= 1;
- if (scope && subscribers <= 0) {
- scope.stop();
- state = void 0;
- scope = void 0;
- }
- };
- return (...args) => {
- subscribers += 1;
- if (!state) {
- scope = vueDemi.effectScope(true);
- state = scope.run(() => composable(...args));
- }
- tryOnScopeDispose(dispose);
- return state;
- };
- }
- function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
- if (!vueDemi.isVue3 && !vueDemi.version.startsWith("2.7.")) {
- if (process.env.NODE_ENV !== "production")
- throw new Error("[VueUse] extendRef only works in Vue 2.7 or above.");
- return;
- }
- for (const [key, value] of Object.entries(extend)) {
- if (key === "value")
- continue;
- if (vueDemi.isRef(value) && unwrap) {
- Object.defineProperty(ref, key, {
- get() {
- return value.value;
- },
- set(v) {
- value.value = v;
- },
- enumerable
- });
- } else {
- Object.defineProperty(ref, key, { value, enumerable });
- }
- }
- return ref;
- }
- function get(obj, key) {
- if (key == null)
- return vueDemi.unref(obj);
- return vueDemi.unref(obj)[key];
- }
- function isDefined(v) {
- return vueDemi.unref(v) != null;
- }
- function makeDestructurable(obj, arr) {
- if (typeof Symbol !== "undefined") {
- const clone = { ...obj };
- Object.defineProperty(clone, Symbol.iterator, {
- enumerable: false,
- value() {
- let index = 0;
- return {
- next: () => ({
- value: arr[index++],
- done: index > arr.length
- })
- };
- }
- });
- return clone;
- } else {
- return Object.assign([...arr], obj);
- }
- }
- function toValue(r) {
- return typeof r === "function" ? r() : vueDemi.unref(r);
- }
- const resolveUnref = toValue;
- function reactify(fn, options) {
- const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vueDemi.unref : toValue;
- return function(...args) {
- return vueDemi.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
- };
- }
- function reactifyObject(obj, optionsOrKeys = {}) {
- let keys = [];
- let options;
- if (Array.isArray(optionsOrKeys)) {
- keys = optionsOrKeys;
- } else {
- options = optionsOrKeys;
- const { includeOwnProperties = true } = optionsOrKeys;
- keys.push(...Object.keys(obj));
- if (includeOwnProperties)
- keys.push(...Object.getOwnPropertyNames(obj));
- }
- return Object.fromEntries(
- keys.map((key) => {
- const value = obj[key];
- return [
- key,
- typeof value === "function" ? reactify(value.bind(obj), options) : value
- ];
- })
- );
- }
- function toReactive(objectRef) {
- if (!vueDemi.isRef(objectRef))
- return vueDemi.reactive(objectRef);
- const proxy = new Proxy({}, {
- get(_, p, receiver) {
- return vueDemi.unref(Reflect.get(objectRef.value, p, receiver));
- },
- set(_, p, value) {
- if (vueDemi.isRef(objectRef.value[p]) && !vueDemi.isRef(value))
- objectRef.value[p].value = value;
- else
- objectRef.value[p] = value;
- return true;
- },
- deleteProperty(_, p) {
- return Reflect.deleteProperty(objectRef.value, p);
- },
- has(_, p) {
- return Reflect.has(objectRef.value, p);
- },
- ownKeys() {
- return Object.keys(objectRef.value);
- },
- getOwnPropertyDescriptor() {
- return {
- enumerable: true,
- configurable: true
- };
- }
- });
- return vueDemi.reactive(proxy);
- }
- function reactiveComputed(fn) {
- return toReactive(vueDemi.computed(fn));
- }
- function reactiveOmit(obj, ...keys) {
- const flatKeys = keys.flat();
- const predicate = flatKeys[0];
- 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]))));
- }
- const isClient = typeof window !== "undefined" && typeof document !== "undefined";
- const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
- const isDef = (val) => typeof val !== "undefined";
- const notNullish = (val) => val != null;
- const assert = (condition, ...infos) => {
- if (!condition)
- console.warn(...infos);
- };
- const toString = Object.prototype.toString;
- const isObject = (val) => toString.call(val) === "[object Object]";
- const now = () => Date.now();
- const timestamp = () => +Date.now();
- const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
- const noop = () => {
- };
- const rand = (min, max) => {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min + 1)) + min;
- };
- const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
- const isIOS = /* @__PURE__ */ getIsIOS();
- function getIsIOS() {
- var _a, _b;
- 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));
- }
- function createFilterWrapper(filter, fn) {
- function wrapper(...args) {
- return new Promise((resolve, reject) => {
- Promise.resolve(filter(() => fn.apply(this, args), { fn, thisArg: this, args })).then(resolve).catch(reject);
- });
- }
- return wrapper;
- }
- const bypassFilter = (invoke) => {
- return invoke();
- };
- function debounceFilter(ms, options = {}) {
- let timer;
- let maxTimer;
- let lastRejector = noop;
- const _clearTimeout = (timer2) => {
- clearTimeout(timer2);
- lastRejector();
- lastRejector = noop;
- };
- const filter = (invoke) => {
- const duration = toValue(ms);
- const maxDuration = toValue(options.maxWait);
- if (timer)
- _clearTimeout(timer);
- if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
- if (maxTimer) {
- _clearTimeout(maxTimer);
- maxTimer = null;
- }
- return Promise.resolve(invoke());
- }
- return new Promise((resolve, reject) => {
- lastRejector = options.rejectOnCancel ? reject : resolve;
- if (maxDuration && !maxTimer) {
- maxTimer = setTimeout(() => {
- if (timer)
- _clearTimeout(timer);
- maxTimer = null;
- resolve(invoke());
- }, maxDuration);
- }
- timer = setTimeout(() => {
- if (maxTimer)
- _clearTimeout(maxTimer);
- maxTimer = null;
- resolve(invoke());
- }, duration);
- });
- };
- return filter;
- }
- function throttleFilter(...args) {
- let lastExec = 0;
- let timer;
- let isLeading = true;
- let lastRejector = noop;
- let lastValue;
- let ms;
- let trailing;
- let leading;
- let rejectOnCancel;
- if (!vueDemi.isRef(args[0]) && typeof args[0] === "object")
- ({ delay: ms, trailing = true, leading = true, rejectOnCancel = false } = args[0]);
- else
- [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
- const clear = () => {
- if (timer) {
- clearTimeout(timer);
- timer = void 0;
- lastRejector();
- lastRejector = noop;
- }
- };
- const filter = (_invoke) => {
- const duration = toValue(ms);
- const elapsed = Date.now() - lastExec;
- const invoke = () => {
- return lastValue = _invoke();
- };
- clear();
- if (duration <= 0) {
- lastExec = Date.now();
- return invoke();
- }
- if (elapsed > duration && (leading || !isLeading)) {
- lastExec = Date.now();
- invoke();
- } else if (trailing) {
- lastValue = new Promise((resolve, reject) => {
- lastRejector = rejectOnCancel ? reject : resolve;
- timer = setTimeout(() => {
- lastExec = Date.now();
- isLeading = true;
- resolve(invoke());
- clear();
- }, Math.max(0, duration - elapsed));
- });
- }
- if (!leading && !timer)
- timer = setTimeout(() => isLeading = true, duration);
- isLeading = false;
- return lastValue;
- };
- return filter;
- }
- function pausableFilter(extendFilter = bypassFilter) {
- const isActive = vueDemi.ref(true);
- function pause() {
- isActive.value = false;
- }
- function resume() {
- isActive.value = true;
- }
- const eventFilter = (...args) => {
- if (isActive.value)
- extendFilter(...args);
- };
- return { isActive: vueDemi.readonly(isActive), pause, resume, eventFilter };
- }
- const directiveHooks = {
- mounted: vueDemi.isVue3 ? "mounted" : "inserted",
- updated: vueDemi.isVue3 ? "updated" : "componentUpdated",
- unmounted: vueDemi.isVue3 ? "unmounted" : "unbind"
- };
- function cacheStringFunction(fn) {
- const cache = /* @__PURE__ */ Object.create(null);
- return (str) => {
- const hit = cache[str];
- return hit || (cache[str] = fn(str));
- };
- }
- const hyphenateRE = /\B([A-Z])/g;
- const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
- const camelizeRE = /-(\w)/g;
- const camelize = cacheStringFunction((str) => {
- return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
- });
- function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
- return new Promise((resolve, reject) => {
- if (throwOnTimeout)
- setTimeout(() => reject(reason), ms);
- else
- setTimeout(resolve, ms);
- });
- }
- function identity(arg) {
- return arg;
- }
- function createSingletonPromise(fn) {
- let _promise;
- function wrapper() {
- if (!_promise)
- _promise = fn();
- return _promise;
- }
- wrapper.reset = async () => {
- const _prev = _promise;
- _promise = void 0;
- if (_prev)
- await _prev;
- };
- return wrapper;
- }
- function invoke(fn) {
- return fn();
- }
- function containsProp(obj, ...props) {
- return props.some((k) => k in obj);
- }
- function increaseWithUnit(target, delta) {
- var _a;
- if (typeof target === "number")
- return target + delta;
- const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? void 0 : _a[0]) || "";
- const unit = target.slice(value.length);
- const result = Number.parseFloat(value) + delta;
- if (Number.isNaN(result))
- return target;
- return result + unit;
- }
- function objectPick(obj, keys, omitUndefined = false) {
- return keys.reduce((n, k) => {
- if (k in obj) {
- if (!omitUndefined || obj[k] !== void 0)
- n[k] = obj[k];
- }
- return n;
- }, {});
- }
- function objectOmit(obj, keys, omitUndefined = false) {
- return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
- return (!omitUndefined || value !== void 0) && !keys.includes(key);
- }));
- }
- function objectEntries(obj) {
- return Object.entries(obj);
- }
- function getLifeCycleTarget(target) {
- return target || vueDemi.getCurrentInstance();
- }
- function toRef(...args) {
- if (args.length !== 1)
- return vueDemi.toRef(...args);
- const r = args[0];
- return typeof r === "function" ? vueDemi.readonly(vueDemi.customRef(() => ({ get: r, set: noop }))) : vueDemi.ref(r);
- }
- const resolveRef = toRef;
- function reactivePick(obj, ...keys) {
- const flatKeys = keys.flat();
- const predicate = flatKeys[0];
- 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)])));
- }
- function refAutoReset(defaultValue, afterMs = 1e4) {
- return vueDemi.customRef((track, trigger) => {
- let value = toValue(defaultValue);
- let timer;
- const resetAfter = () => setTimeout(() => {
- value = toValue(defaultValue);
- trigger();
- }, toValue(afterMs));
- tryOnScopeDispose(() => {
- clearTimeout(timer);
- });
- return {
- get() {
- track();
- return value;
- },
- set(newValue) {
- value = newValue;
- trigger();
- clearTimeout(timer);
- timer = resetAfter();
- }
- };
- });
- }
- function useDebounceFn(fn, ms = 200, options = {}) {
- return createFilterWrapper(
- debounceFilter(ms, options),
- fn
- );
- }
- function refDebounced(value, ms = 200, options = {}) {
- const debounced = vueDemi.ref(value.value);
- const updater = useDebounceFn(() => {
- debounced.value = value.value;
- }, ms, options);
- vueDemi.watch(value, () => updater());
- return debounced;
- }
- function refDefault(source, defaultValue) {
- return vueDemi.computed({
- get() {
- var _a;
- return (_a = source.value) != null ? _a : defaultValue;
- },
- set(value) {
- source.value = value;
- }
- });
- }
- function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
- return createFilterWrapper(
- throttleFilter(ms, trailing, leading, rejectOnCancel),
- fn
- );
- }
- function refThrottled(value, delay = 200, trailing = true, leading = true) {
- if (delay <= 0)
- return value;
- const throttled = vueDemi.ref(value.value);
- const updater = useThrottleFn(() => {
- throttled.value = value.value;
- }, delay, trailing, leading);
- vueDemi.watch(value, () => updater());
- return throttled;
- }
- function refWithControl(initial, options = {}) {
- let source = initial;
- let track;
- let trigger;
- const ref = vueDemi.customRef((_track, _trigger) => {
- track = _track;
- trigger = _trigger;
- return {
- get() {
- return get();
- },
- set(v) {
- set(v);
- }
- };
- });
- function get(tracking = true) {
- if (tracking)
- track();
- return source;
- }
- function set(value, triggering = true) {
- var _a, _b;
- if (value === source)
- return;
- const old = source;
- if (((_a = options.onBeforeChange) == null ? void 0 : _a.call(options, value, old)) === false)
- return;
- source = value;
- (_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
- if (triggering)
- trigger();
- }
- const untrackedGet = () => get(false);
- const silentSet = (v) => set(v, false);
- const peek = () => get(false);
- const lay = (v) => set(v, false);
- return extendRef(
- ref,
- {
- get,
- set,
- untrackedGet,
- silentSet,
- peek,
- lay
- },
- { enumerable: true }
- );
- }
- const controlledRef = refWithControl;
- function set(...args) {
- if (args.length === 2) {
- const [ref, value] = args;
- ref.value = value;
- }
- if (args.length === 3) {
- if (vueDemi.isVue2) {
- vueDemi.set(...args);
- } else {
- const [target, key, value] = args;
- target[key] = value;
- }
- }
- }
- function watchWithFilter(source, cb, options = {}) {
- const {
- eventFilter = bypassFilter,
- ...watchOptions
- } = options;
- return vueDemi.watch(
- source,
- createFilterWrapper(
- eventFilter,
- cb
- ),
- watchOptions
- );
- }
- function watchPausable(source, cb, options = {}) {
- const {
- eventFilter: filter,
- ...watchOptions
- } = options;
- const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
- const stop = watchWithFilter(
- source,
- cb,
- {
- ...watchOptions,
- eventFilter
- }
- );
- return { stop, pause, resume, isActive };
- }
- function syncRef(left, right, ...[options]) {
- const {
- flush = "sync",
- deep = false,
- immediate = true,
- direction = "both",
- transform = {}
- } = options || {};
- const watchers = [];
- const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
- const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
- if (direction === "both" || direction === "ltr") {
- watchers.push(watchPausable(
- left,
- (newValue) => {
- watchers.forEach((w) => w.pause());
- right.value = transformLTR(newValue);
- watchers.forEach((w) => w.resume());
- },
- { flush, deep, immediate }
- ));
- }
- if (direction === "both" || direction === "rtl") {
- watchers.push(watchPausable(
- right,
- (newValue) => {
- watchers.forEach((w) => w.pause());
- left.value = transformRTL(newValue);
- watchers.forEach((w) => w.resume());
- },
- { flush, deep, immediate }
- ));
- }
- const stop = () => {
- watchers.forEach((w) => w.stop());
- };
- return stop;
- }
- function syncRefs(source, targets, options = {}) {
- const {
- flush = "sync",
- deep = false,
- immediate = true
- } = options;
- if (!Array.isArray(targets))
- targets = [targets];
- return vueDemi.watch(
- source,
- (newValue) => targets.forEach((target) => target.value = newValue),
- { flush, deep, immediate }
- );
- }
- function toRefs(objectRef, options = {}) {
- if (!vueDemi.isRef(objectRef))
- return vueDemi.toRefs(objectRef);
- const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
- for (const key in objectRef.value) {
- result[key] = vueDemi.customRef(() => ({
- get() {
- return objectRef.value[key];
- },
- set(v) {
- var _a;
- const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
- if (replaceRef) {
- if (Array.isArray(objectRef.value)) {
- const copy = [...objectRef.value];
- copy[key] = v;
- objectRef.value = copy;
- } else {
- const newObject = { ...objectRef.value, [key]: v };
- Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
- objectRef.value = newObject;
- }
- } else {
- objectRef.value[key] = v;
- }
- }
- }));
- }
- return result;
- }
- function tryOnBeforeMount(fn, sync = true, target) {
- const instance = getLifeCycleTarget(target);
- if (instance)
- vueDemi.onBeforeMount(fn, target);
- else if (sync)
- fn();
- else
- vueDemi.nextTick(fn);
- }
- function tryOnBeforeUnmount(fn, target) {
- const instance = getLifeCycleTarget(target);
- if (instance)
- vueDemi.onBeforeUnmount(fn, target);
- }
- function tryOnMounted(fn, sync = true, target) {
- const instance = getLifeCycleTarget();
- if (instance)
- vueDemi.onMounted(fn, target);
- else if (sync)
- fn();
- else
- vueDemi.nextTick(fn);
- }
- function tryOnUnmounted(fn, target) {
- const instance = getLifeCycleTarget(target);
- if (instance)
- vueDemi.onUnmounted(fn, target);
- }
- function createUntil(r, isNot = false) {
- function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
- let stop = null;
- const watcher = new Promise((resolve) => {
- stop = vueDemi.watch(
- r,
- (v) => {
- if (condition(v) !== isNot) {
- stop == null ? void 0 : stop();
- resolve(v);
- }
- },
- {
- flush,
- deep,
- immediate: true
- }
- );
- });
- const promises = [watcher];
- if (timeout != null) {
- promises.push(
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
- );
- }
- return Promise.race(promises);
- }
- function toBe(value, options) {
- if (!vueDemi.isRef(value))
- return toMatch((v) => v === value, options);
- const { flush = "sync", deep = false, timeout, throwOnTimeout } = options != null ? options : {};
- let stop = null;
- const watcher = new Promise((resolve) => {
- stop = vueDemi.watch(
- [r, value],
- ([v1, v2]) => {
- if (isNot !== (v1 === v2)) {
- stop == null ? void 0 : stop();
- resolve(v1);
- }
- },
- {
- flush,
- deep,
- immediate: true
- }
- );
- });
- const promises = [watcher];
- if (timeout != null) {
- promises.push(
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
- stop == null ? void 0 : stop();
- return toValue(r);
- })
- );
- }
- return Promise.race(promises);
- }
- function toBeTruthy(options) {
- return toMatch((v) => Boolean(v), options);
- }
- function toBeNull(options) {
- return toBe(null, options);
- }
- function toBeUndefined(options) {
- return toBe(void 0, options);
- }
- function toBeNaN(options) {
- return toMatch(Number.isNaN, options);
- }
- function toContains(value, options) {
- return toMatch((v) => {
- const array = Array.from(v);
- return array.includes(value) || array.includes(toValue(value));
- }, options);
- }
- function changed(options) {
- return changedTimes(1, options);
- }
- function changedTimes(n = 1, options) {
- let count = -1;
- return toMatch(() => {
- count += 1;
- return count >= n;
- }, options);
- }
- if (Array.isArray(toValue(r))) {
- const instance = {
- toMatch,
- toContains,
- changed,
- changedTimes,
- get not() {
- return createUntil(r, !isNot);
- }
- };
- return instance;
- } else {
- const instance = {
- toMatch,
- toBe,
- toBeTruthy,
- toBeNull,
- toBeNaN,
- toBeUndefined,
- changed,
- changedTimes,
- get not() {
- return createUntil(r, !isNot);
- }
- };
- return instance;
- }
- }
- function until(r) {
- return createUntil(r);
- }
- function defaultComparator(value, othVal) {
- return value === othVal;
- }
- function useArrayDifference(...args) {
- var _a;
- const list = args[0];
- const values = args[1];
- let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
- if (typeof compareFn === "string") {
- const key = compareFn;
- compareFn = (value, othVal) => value[key] === othVal[key];
- }
- return vueDemi.computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
- }
- function useArrayEvery(list, fn) {
- return vueDemi.computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
- }
- function useArrayFilter(list, fn) {
- return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
- }
- function useArrayFind(list, fn) {
- return vueDemi.computed(() => toValue(
- toValue(list).find((element, index, array) => fn(toValue(element), index, array))
- ));
- }
- function useArrayFindIndex(list, fn) {
- return vueDemi.computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
- }
- function findLast(arr, cb) {
- let index = arr.length;
- while (index-- > 0) {
- if (cb(arr[index], index, arr))
- return arr[index];
- }
- return void 0;
- }
- function useArrayFindLast(list, fn) {
- return vueDemi.computed(() => toValue(
- !Array.prototype.findLast ? findLast(toValue(list), (element, index, array) => fn(toValue(element), index, array)) : toValue(list).findLast((element, index, array) => fn(toValue(element), index, array))
- ));
- }
- function isArrayIncludesOptions(obj) {
- return isObject(obj) && containsProp(obj, "formIndex", "comparator");
- }
- function useArrayIncludes(...args) {
- var _a;
- const list = args[0];
- const value = args[1];
- let comparator = args[2];
- let formIndex = 0;
- if (isArrayIncludesOptions(comparator)) {
- formIndex = (_a = comparator.fromIndex) != null ? _a : 0;
- comparator = comparator.comparator;
- }
- if (typeof comparator === "string") {
- const key = comparator;
- comparator = (element, value2) => element[key] === toValue(value2);
- }
- comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
- return vueDemi.computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
- toValue(element),
- toValue(value),
- index,
- toValue(array)
- )));
- }
- function useArrayJoin(list, separator) {
- return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
- }
- function useArrayMap(list, fn) {
- return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).map(fn));
- }
- function useArrayReduce(list, reducer, ...args) {
- const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
- return vueDemi.computed(() => {
- const resolved = toValue(list);
- return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
- });
- }
- function useArraySome(list, fn) {
- return vueDemi.computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
- }
- function uniq(array) {
- return Array.from(new Set(array));
- }
- function uniqueElementsBy(array, fn) {
- return array.reduce((acc, v) => {
- if (!acc.some((x) => fn(v, x, array)))
- acc.push(v);
- return acc;
- }, []);
- }
- function useArrayUnique(list, compareFn) {
- return vueDemi.computed(() => {
- const resolvedList = toValue(list).map((element) => toValue(element));
- return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
- });
- }
- function useCounter(initialValue = 0, options = {}) {
- let _initialValue = vueDemi.unref(initialValue);
- const count = vueDemi.ref(initialValue);
- const {
- max = Number.POSITIVE_INFINITY,
- min = Number.NEGATIVE_INFINITY
- } = options;
- const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
- const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
- const get = () => count.value;
- const set = (val) => count.value = Math.max(min, Math.min(max, val));
- const reset = (val = _initialValue) => {
- _initialValue = val;
- return set(val);
- };
- return { count, inc, dec, get, set, reset };
- }
- const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
- 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;
- function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
- let m = hours < 12 ? "AM" : "PM";
- if (hasPeriod)
- m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
- return isLowercase ? m.toLowerCase() : m;
- }
- function formatOrdinal(num) {
- const suffixes = ["th", "st", "nd", "rd"];
- const v = num % 100;
- return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
- }
- function formatDate(date, formatStr, options = {}) {
- var _a;
- const years = date.getFullYear();
- const month = date.getMonth();
- const days = date.getDate();
- const hours = date.getHours();
- const minutes = date.getMinutes();
- const seconds = date.getSeconds();
- const milliseconds = date.getMilliseconds();
- const day = date.getDay();
- const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
- const matches = {
- Yo: () => formatOrdinal(years),
- YY: () => String(years).slice(-2),
- YYYY: () => years,
- M: () => month + 1,
- Mo: () => formatOrdinal(month + 1),
- MM: () => `${month + 1}`.padStart(2, "0"),
- MMM: () => date.toLocaleDateString(options.locales, { month: "short" }),
- MMMM: () => date.toLocaleDateString(options.locales, { month: "long" }),
- D: () => String(days),
- Do: () => formatOrdinal(days),
- DD: () => `${days}`.padStart(2, "0"),
- H: () => String(hours),
- Ho: () => formatOrdinal(hours),
- HH: () => `${hours}`.padStart(2, "0"),
- h: () => `${hours % 12 || 12}`.padStart(1, "0"),
- ho: () => formatOrdinal(hours % 12 || 12),
- hh: () => `${hours % 12 || 12}`.padStart(2, "0"),
- m: () => String(minutes),
- mo: () => formatOrdinal(minutes),
- mm: () => `${minutes}`.padStart(2, "0"),
- s: () => String(seconds),
- so: () => formatOrdinal(seconds),
- ss: () => `${seconds}`.padStart(2, "0"),
- SSS: () => `${milliseconds}`.padStart(3, "0"),
- d: () => day,
- dd: () => date.toLocaleDateString(options.locales, { weekday: "narrow" }),
- ddd: () => date.toLocaleDateString(options.locales, { weekday: "short" }),
- dddd: () => date.toLocaleDateString(options.locales, { weekday: "long" }),
- A: () => meridiem(hours, minutes),
- AA: () => meridiem(hours, minutes, false, true),
- a: () => meridiem(hours, minutes, true),
- aa: () => meridiem(hours, minutes, true, true)
- };
- return formatStr.replace(REGEX_FORMAT, (match, $1) => {
- var _a2, _b;
- return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? void 0 : _a2.call(matches)) != null ? _b : match;
- });
- }
- function normalizeDate(date) {
- if (date === null)
- return new Date(Number.NaN);
- if (date === void 0)
- return /* @__PURE__ */ new Date();
- if (date instanceof Date)
- return new Date(date);
- if (typeof date === "string" && !/Z$/i.test(date)) {
- const d = date.match(REGEX_PARSE);
- if (d) {
- const m = d[2] - 1 || 0;
- const ms = (d[7] || "0").substring(0, 3);
- return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
- }
- }
- return new Date(date);
- }
- function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
- return vueDemi.computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
- }
- function useIntervalFn(cb, interval = 1e3, options = {}) {
- const {
- immediate = true,
- immediateCallback = false
- } = options;
- let timer = null;
- const isActive = vueDemi.ref(false);
- function clean() {
- if (timer) {
- clearInterval(timer);
- timer = null;
- }
- }
- function pause() {
- isActive.value = false;
- clean();
- }
- function resume() {
- const intervalValue = toValue(interval);
- if (intervalValue <= 0)
- return;
- isActive.value = true;
- if (immediateCallback)
- cb();
- clean();
- timer = setInterval(cb, intervalValue);
- }
- if (immediate && isClient)
- resume();
- if (vueDemi.isRef(interval) || typeof interval === "function") {
- const stopWatch = vueDemi.watch(interval, () => {
- if (isActive.value && isClient)
- resume();
- });
- tryOnScopeDispose(stopWatch);
- }
- tryOnScopeDispose(pause);
- return {
- isActive,
- pause,
- resume
- };
- }
- function useInterval(interval = 1e3, options = {}) {
- const {
- controls: exposeControls = false,
- immediate = true,
- callback
- } = options;
- const counter = vueDemi.ref(0);
- const update = () => counter.value += 1;
- const reset = () => {
- counter.value = 0;
- };
- const controls = useIntervalFn(
- callback ? () => {
- update();
- callback(counter.value);
- } : update,
- interval,
- { immediate }
- );
- if (exposeControls) {
- return {
- counter,
- reset,
- ...controls
- };
- } else {
- return counter;
- }
- }
- function useLastChanged(source, options = {}) {
- var _a;
- const ms = vueDemi.ref((_a = options.initialValue) != null ? _a : null);
- vueDemi.watch(
- source,
- () => ms.value = timestamp(),
- options
- );
- return ms;
- }
- function useTimeoutFn(cb, interval, options = {}) {
- const {
- immediate = true
- } = options;
- const isPending = vueDemi.ref(false);
- let timer = null;
- function clear() {
- if (timer) {
- clearTimeout(timer);
- timer = null;
- }
- }
- function stop() {
- isPending.value = false;
- clear();
- }
- function start(...args) {
- clear();
- isPending.value = true;
- timer = setTimeout(() => {
- isPending.value = false;
- timer = null;
- cb(...args);
- }, toValue(interval));
- }
- if (immediate) {
- isPending.value = true;
- if (isClient)
- start();
- }
- tryOnScopeDispose(stop);
- return {
- isPending: vueDemi.readonly(isPending),
- start,
- stop
- };
- }
- function useTimeout(interval = 1e3, options = {}) {
- const {
- controls: exposeControls = false,
- callback
- } = options;
- const controls = useTimeoutFn(
- callback != null ? callback : noop,
- interval,
- options
- );
- const ready = vueDemi.computed(() => !controls.isPending.value);
- if (exposeControls) {
- return {
- ready,
- ...controls
- };
- } else {
- return ready;
- }
- }
- function useToNumber(value, options = {}) {
- const {
- method = "parseFloat",
- radix,
- nanToZero
- } = options;
- return vueDemi.computed(() => {
- let resolved = toValue(value);
- if (typeof resolved === "string")
- resolved = Number[method](resolved, radix);
- if (nanToZero && Number.isNaN(resolved))
- resolved = 0;
- return resolved;
- });
- }
- function useToString(value) {
- return vueDemi.computed(() => `${toValue(value)}`);
- }
- function useToggle(initialValue = false, options = {}) {
- const {
- truthyValue = true,
- falsyValue = false
- } = options;
- const valueIsRef = vueDemi.isRef(initialValue);
- const _value = vueDemi.ref(initialValue);
- function toggle(value) {
- if (arguments.length) {
- _value.value = value;
- return _value.value;
- } else {
- const truthy = toValue(truthyValue);
- _value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
- return _value.value;
- }
- }
- if (valueIsRef)
- return toggle;
- else
- return [_value, toggle];
- }
- function watchArray(source, cb, options) {
- let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
- return vueDemi.watch(source, (newList, _, onCleanup) => {
- const oldListRemains = Array.from({ length: oldList.length });
- const added = [];
- for (const obj of newList) {
- let found = false;
- for (let i = 0; i < oldList.length; i++) {
- if (!oldListRemains[i] && obj === oldList[i]) {
- oldListRemains[i] = true;
- found = true;
- break;
- }
- }
- if (!found)
- added.push(obj);
- }
- const removed = oldList.filter((_2, i) => !oldListRemains[i]);
- cb(newList, oldList, added, removed, onCleanup);
- oldList = [...newList];
- }, options);
- }
- function watchAtMost(source, cb, options) {
- const {
- count,
- ...watchOptions
- } = options;
- const current = vueDemi.ref(0);
- const stop = watchWithFilter(
- source,
- (...args) => {
- current.value += 1;
- if (current.value >= toValue(count))
- vueDemi.nextTick(() => stop());
- cb(...args);
- },
- watchOptions
- );
- return { count: current, stop };
- }
- function watchDebounced(source, cb, options = {}) {
- const {
- debounce = 0,
- maxWait = void 0,
- ...watchOptions
- } = options;
- return watchWithFilter(
- source,
- cb,
- {
- ...watchOptions,
- eventFilter: debounceFilter(debounce, { maxWait })
- }
- );
- }
- function watchDeep(source, cb, options) {
- return vueDemi.watch(
- source,
- cb,
- {
- ...options,
- deep: true
- }
- );
- }
- function watchIgnorable(source, cb, options = {}) {
- const {
- eventFilter = bypassFilter,
- ...watchOptions
- } = options;
- const filteredCb = createFilterWrapper(
- eventFilter,
- cb
- );
- let ignoreUpdates;
- let ignorePrevAsyncUpdates;
- let stop;
- if (watchOptions.flush === "sync") {
- const ignore = vueDemi.ref(false);
- ignorePrevAsyncUpdates = () => {
- };
- ignoreUpdates = (updater) => {
- ignore.value = true;
- updater();
- ignore.value = false;
- };
- stop = vueDemi.watch(
- source,
- (...args) => {
- if (!ignore.value)
- filteredCb(...args);
- },
- watchOptions
- );
- } else {
- const disposables = [];
- const ignoreCounter = vueDemi.ref(0);
- const syncCounter = vueDemi.ref(0);
- ignorePrevAsyncUpdates = () => {
- ignoreCounter.value = syncCounter.value;
- };
- disposables.push(
- vueDemi.watch(
- source,
- () => {
- syncCounter.value++;
- },
- { ...watchOptions, flush: "sync" }
- )
- );
- ignoreUpdates = (updater) => {
- const syncCounterPrev = syncCounter.value;
- updater();
- ignoreCounter.value += syncCounter.value - syncCounterPrev;
- };
- disposables.push(
- vueDemi.watch(
- source,
- (...args) => {
- const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
- ignoreCounter.value = 0;
- syncCounter.value = 0;
- if (ignore)
- return;
- filteredCb(...args);
- },
- watchOptions
- )
- );
- stop = () => {
- disposables.forEach((fn) => fn());
- };
- }
- return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
- }
- function watchImmediate(source, cb, options) {
- return vueDemi.watch(
- source,
- cb,
- {
- ...options,
- immediate: true
- }
- );
- }
- function watchOnce(source, cb, options) {
- const stop = vueDemi.watch(source, (...args) => {
- vueDemi.nextTick(() => stop());
- return cb(...args);
- }, options);
- return stop;
- }
- function watchThrottled(source, cb, options = {}) {
- const {
- throttle = 0,
- trailing = true,
- leading = true,
- ...watchOptions
- } = options;
- return watchWithFilter(
- source,
- cb,
- {
- ...watchOptions,
- eventFilter: throttleFilter(throttle, trailing, leading)
- }
- );
- }
- function watchTriggerable(source, cb, options = {}) {
- let cleanupFn;
- function onEffect() {
- if (!cleanupFn)
- return;
- const fn = cleanupFn;
- cleanupFn = void 0;
- fn();
- }
- function onCleanup(callback) {
- cleanupFn = callback;
- }
- const _cb = (value, oldValue) => {
- onEffect();
- return cb(value, oldValue, onCleanup);
- };
- const res = watchIgnorable(source, _cb, options);
- const { ignoreUpdates } = res;
- const trigger = () => {
- let res2;
- ignoreUpdates(() => {
- res2 = _cb(getWatchSources(source), getOldValue(source));
- });
- return res2;
- };
- return {
- ...res,
- trigger
- };
- }
- function getWatchSources(sources) {
- if (vueDemi.isReactive(sources))
- return sources;
- if (Array.isArray(sources))
- return sources.map((item) => toValue(item));
- return toValue(sources);
- }
- function getOldValue(source) {
- return Array.isArray(source) ? source.map(() => void 0) : void 0;
- }
- function whenever(source, cb, options) {
- const stop = vueDemi.watch(
- source,
- (v, ov, onInvalidate) => {
- if (v) {
- if (options == null ? void 0 : options.once)
- vueDemi.nextTick(() => stop());
- cb(v, ov, onInvalidate);
- }
- },
- {
- ...options,
- once: false
- }
- );
- return stop;
- }
- exports.assert = assert;
- exports.autoResetRef = refAutoReset;
- exports.bypassFilter = bypassFilter;
- exports.camelize = camelize;
- exports.clamp = clamp;
- exports.computedEager = computedEager;
- exports.computedWithControl = computedWithControl;
- exports.containsProp = containsProp;
- exports.controlledComputed = computedWithControl;
- exports.controlledRef = controlledRef;
- exports.createEventHook = createEventHook;
- exports.createFilterWrapper = createFilterWrapper;
- exports.createGlobalState = createGlobalState;
- exports.createInjectionState = createInjectionState;
- exports.createReactiveFn = reactify;
- exports.createSharedComposable = createSharedComposable;
- exports.createSingletonPromise = createSingletonPromise;
- exports.debounceFilter = debounceFilter;
- exports.debouncedRef = refDebounced;
- exports.debouncedWatch = watchDebounced;
- exports.directiveHooks = directiveHooks;
- exports.eagerComputed = computedEager;
- exports.extendRef = extendRef;
- exports.formatDate = formatDate;
- exports.get = get;
- exports.getLifeCycleTarget = getLifeCycleTarget;
- exports.hasOwn = hasOwn;
- exports.hyphenate = hyphenate;
- exports.identity = identity;
- exports.ignorableWatch = watchIgnorable;
- exports.increaseWithUnit = increaseWithUnit;
- exports.injectLocal = injectLocal;
- exports.invoke = invoke;
- exports.isClient = isClient;
- exports.isDef = isDef;
- exports.isDefined = isDefined;
- exports.isIOS = isIOS;
- exports.isObject = isObject;
- exports.isWorker = isWorker;
- exports.makeDestructurable = makeDestructurable;
- exports.noop = noop;
- exports.normalizeDate = normalizeDate;
- exports.notNullish = notNullish;
- exports.now = now;
- exports.objectEntries = objectEntries;
- exports.objectOmit = objectOmit;
- exports.objectPick = objectPick;
- exports.pausableFilter = pausableFilter;
- exports.pausableWatch = watchPausable;
- exports.promiseTimeout = promiseTimeout;
- exports.provideLocal = provideLocal;
- exports.rand = rand;
- exports.reactify = reactify;
- exports.reactifyObject = reactifyObject;
- exports.reactiveComputed = reactiveComputed;
- exports.reactiveOmit = reactiveOmit;
- exports.reactivePick = reactivePick;
- exports.refAutoReset = refAutoReset;
- exports.refDebounced = refDebounced;
- exports.refDefault = refDefault;
- exports.refThrottled = refThrottled;
- exports.refWithControl = refWithControl;
- exports.resolveRef = resolveRef;
- exports.resolveUnref = resolveUnref;
- exports.set = set;
- exports.syncRef = syncRef;
- exports.syncRefs = syncRefs;
- exports.throttleFilter = throttleFilter;
- exports.throttledRef = refThrottled;
- exports.throttledWatch = watchThrottled;
- exports.timestamp = timestamp;
- exports.toReactive = toReactive;
- exports.toRef = toRef;
- exports.toRefs = toRefs;
- exports.toValue = toValue;
- exports.tryOnBeforeMount = tryOnBeforeMount;
- exports.tryOnBeforeUnmount = tryOnBeforeUnmount;
- exports.tryOnMounted = tryOnMounted;
- exports.tryOnScopeDispose = tryOnScopeDispose;
- exports.tryOnUnmounted = tryOnUnmounted;
- exports.until = until;
- exports.useArrayDifference = useArrayDifference;
- exports.useArrayEvery = useArrayEvery;
- exports.useArrayFilter = useArrayFilter;
- exports.useArrayFind = useArrayFind;
- exports.useArrayFindIndex = useArrayFindIndex;
- exports.useArrayFindLast = useArrayFindLast;
- exports.useArrayIncludes = useArrayIncludes;
- exports.useArrayJoin = useArrayJoin;
- exports.useArrayMap = useArrayMap;
- exports.useArrayReduce = useArrayReduce;
- exports.useArraySome = useArraySome;
- exports.useArrayUnique = useArrayUnique;
- exports.useCounter = useCounter;
- exports.useDateFormat = useDateFormat;
- exports.useDebounce = refDebounced;
- exports.useDebounceFn = useDebounceFn;
- exports.useInterval = useInterval;
- exports.useIntervalFn = useIntervalFn;
- exports.useLastChanged = useLastChanged;
- exports.useThrottle = refThrottled;
- exports.useThrottleFn = useThrottleFn;
- exports.useTimeout = useTimeout;
- exports.useTimeoutFn = useTimeoutFn;
- exports.useToNumber = useToNumber;
- exports.useToString = useToString;
- exports.useToggle = useToggle;
- exports.watchArray = watchArray;
- exports.watchAtMost = watchAtMost;
- exports.watchDebounced = watchDebounced;
- exports.watchDeep = watchDeep;
- exports.watchIgnorable = watchIgnorable;
- exports.watchImmediate = watchImmediate;
- exports.watchOnce = watchOnce;
- exports.watchPausable = watchPausable;
- exports.watchThrottled = watchThrottled;
- exports.watchTriggerable = watchTriggerable;
- exports.watchWithFilter = watchWithFilter;
- exports.whenever = whenever;
- })(this.VueUse = this.VueUse || {}, VueDemi);
|