UNPKG

bootstrap-vue-next

Version:

BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.

304 lines (303 loc) 8.03 kB
import { ref, isRef, watch, computed, getCurrentScope, onScopeDispose, unref, readonly, toRef as toRef$1, customRef, onMounted, nextTick, getCurrentInstance } from "vue"; function tryOnScopeDispose(fn) { if (getCurrentScope()) { onScopeDispose(fn); return true; } return false; } 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() : unref(r); } const isClient = typeof window !== "undefined" && typeof document !== "undefined"; typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope; const notNullish = (val) => val != null; const toString = Object.prototype.toString; const isObject = (val) => toString.call(val) === "[object Object]"; const timestamp = () => +Date.now(); const noop = () => { }; 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 pausableFilter(extendFilter = bypassFilter) { const isActive = ref(true); function pause() { isActive.value = false; } function resume() { isActive.value = true; } const eventFilter = (...args) => { if (isActive.value) extendFilter(...args); }; return { isActive: readonly(isActive), pause, resume, eventFilter }; } function cacheStringFunction(fn) { const cache = /* @__PURE__ */ Object.create(null); return (str) => { const hit = cache[str]; return hit || (cache[str] = fn(str)); }; } const camelizeRE = /-(\w)/g; const camelize = cacheStringFunction((str) => { return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : ""); }); 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 getLifeCycleTarget(target) { return getCurrentInstance(); } function toRef(...args) { if (args.length !== 1) return toRef$1(...args); const r = args[0]; return typeof r === "function" ? readonly(customRef(() => ({ get: r, set: noop }))) : ref(r); } function useDebounceFn(fn, ms = 200, options = {}) { return createFilterWrapper( debounceFilter(ms, options), fn ); } function watchWithFilter(source, cb, options = {}) { const { eventFilter = bypassFilter, ...watchOptions } = options; return 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 tryOnMounted(fn, sync = true, target) { const instance = getLifeCycleTarget(); if (instance) onMounted(fn, target); else if (sync) fn(); else nextTick(fn); } function useIntervalFn(cb, interval = 1e3, options = {}) { const { immediate = true, immediateCallback = false } = options; let timer = null; const isActive = 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 (isRef(interval) || typeof interval === "function") { const stopWatch = watch(interval, () => { if (isActive.value && isClient) resume(); }); tryOnScopeDispose(stopWatch); } tryOnScopeDispose(pause); return { isActive, pause, resume }; } function useToNumber(value, options = {}) { const { method = "parseFloat", radix, nanToZero } = options; return computed(() => { let resolved = toValue(value); if (typeof resolved === "string") resolved = Number[method](resolved, radix); if (nanToZero && Number.isNaN(resolved)) resolved = 0; return resolved; }); } export { tryOnScopeDispose as a, isIOS as b, isClient as c, notNullish as d, increaseWithUnit as e, toRef as f, tryOnMounted as g, timestamp as h, isObject as i, useIntervalFn as j, camelize as k, useDebounceFn as l, makeDestructurable as m, noop as n, syncRef as s, toValue as t, useToNumber as u, watchPausable as w }; //# sourceMappingURL=index-DlGgXMQF.mjs.map