import { Qn as toRef, xt as inject } from "./vue.runtime.esm-bundler-BvoXUmaf.js"; import { $ as PREFERS_REDUCED_MOTION, J as refElement, V as mergeDeep, g as clamp, it as consoleWarn } from "./defineComponent-DB6xIcDy.js"; import { r as easingPatterns } from "./easing-DfcvkbkS.js"; import { i as useRtl } from "./locale-DDGMqzqb.js"; //#region node_modules/vuetify/lib/composables/goto.js var GoToSymbol = Symbol.for("vuetify:goto"); function genDefaults() { return { container: void 0, duration: 300, layout: false, offset: 0, easing: "easeInOutCubic", patterns: easingPatterns }; } function getContainer(el) { return getTarget(el) ?? (document.scrollingElement || document.body); } function getTarget(el) { return typeof el === "string" ? document.querySelector(el) : refElement(el); } function getOffset(target, horizontal, rtl) { if (typeof target === "number") return horizontal && rtl ? -target : target; let el = getTarget(target); let totalOffset = 0; while (el) { totalOffset += horizontal ? el.offsetLeft : el.offsetTop; el = el.offsetParent; } return totalOffset; } function createGoTo(options, locale) { return { rtl: locale.isRtl, options: mergeDeep(genDefaults(), options) }; } async function scrollTo(_target, _options, horizontal, goTo) { const property = horizontal ? "scrollLeft" : "scrollTop"; const options = mergeDeep(goTo?.options ?? genDefaults(), _options); const rtl = goTo?.rtl.value; const target = (typeof _target === "number" ? _target : getTarget(_target)) ?? 0; const container = options.container === "parent" && target instanceof HTMLElement ? target.parentElement : getContainer(options.container); const ease = PREFERS_REDUCED_MOTION() ? options.patterns.instant : typeof options.easing === "function" ? options.easing : options.patterns[options.easing]; if (!ease) throw new TypeError(`Easing function "${options.easing}" not found.`); let targetLocation; if (typeof target === "number") targetLocation = getOffset(target, horizontal, rtl); else { targetLocation = getOffset(target, horizontal, rtl) - getOffset(container, horizontal, rtl); if (options.layout) { const layoutOffset = window.getComputedStyle(target).getPropertyValue("--v-layout-top"); if (layoutOffset) targetLocation -= parseInt(layoutOffset, 10); } } targetLocation += options.offset; targetLocation = clampTarget(container, targetLocation, !!rtl, !!horizontal); const startLocation = container[property] ?? 0; if (targetLocation === startLocation) return Promise.resolve(targetLocation); const startTime = performance.now(); return new Promise((resolve) => requestAnimationFrame(function step(currentTime) { const progress = (currentTime - startTime) / options.duration; const location = Math.floor(startLocation + (targetLocation - startLocation) * ease(clamp(progress, 0, 1))); container[property] = location; if (progress >= 1 && Math.abs(location - container[property]) < 10) return resolve(targetLocation); else if (progress > 2) { consoleWarn("Scroll target is not reachable"); return resolve(container[property]); } requestAnimationFrame(step); })); } function useGoTo(_options = {}) { const goToInstance = inject(GoToSymbol); const { isRtl } = useRtl(); if (!goToInstance) throw new Error("[Vuetify] Could not find injected goto instance"); const goTo = { ...goToInstance, rtl: toRef(() => goToInstance.rtl.value || isRtl.value) }; async function go(target, options) { return scrollTo(target, mergeDeep(_options, options), false, goTo); } go.horizontal = async (target, options) => { return scrollTo(target, mergeDeep(_options, options), true, goTo); }; return go; } /** * Clamp target value to achieve a smooth scroll animation * when the value goes outside the scroll container size */ function clampTarget(container, value, rtl, horizontal) { const { scrollWidth, scrollHeight } = container; const [containerWidth, containerHeight] = container === document.scrollingElement ? [window.innerWidth, window.innerHeight] : [container.offsetWidth, container.offsetHeight]; let min; let max; if (horizontal) if (rtl) { min = -(scrollWidth - containerWidth); max = 0; } else { min = 0; max = scrollWidth - containerWidth; } else { min = 0; max = scrollHeight + -containerHeight; } return clamp(value, min, max); } //#endregion export { createGoTo as n, useGoTo as r, GoToSymbol as t }; //# sourceMappingURL=goto-Bn-PzNUr.js.map