From: Eduardo San Martin Morote Date: Fri, 24 Apr 2020 14:49:49 +0000 (+0200) Subject: chore: remove unused file X-Git-Tag: v4.0.0-alpha.8~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d775fff8890f99d6741f7276dbfc21c268b55bf;p=thirdparty%2Fvuejs%2Frouter.git chore: remove unused file --- diff --git a/src/utils/scroll.ts b/src/utils/scroll.ts deleted file mode 100644 index 950c1410..00000000 --- a/src/utils/scroll.ts +++ /dev/null @@ -1,89 +0,0 @@ -// import { RouteLocationNormalized } from '../types' - -import { isBrowser } from './env' - -export type ScrollToPosition = { - x: number - y: number -} - -export interface ScrollToElement { - selector: string - offset?: ScrollToPosition -} - -export type ScrollPosition = ScrollToPosition | ScrollToElement - -export function computeScrollPosition(el?: Element): ScrollToPosition { - return el - ? { - x: el.scrollLeft, - y: el.scrollTop, - } - : { - x: window.pageXOffset, - y: window.pageYOffset, - } -} - -function getElementPosition( - el: Element, - offset: ScrollToPosition -): ScrollToPosition { - const docEl = document.documentElement - const docRect = docEl.getBoundingClientRect() - const elRect = el.getBoundingClientRect() - return { - x: elRect.left - docRect.left - offset.x, - y: elRect.top - docRect.top - offset.y, - } -} - -const hashStartsWithNumberRE = /^#\d/ - -export function scrollToPosition(position: ScrollPosition): void { - let normalizedPosition: ScrollToPosition | null = null - - if ('selector' in position) { - // getElementById would still fail if the selector contains a more complicated query like #main[data-attr] - // but at the same time, it doesn't make much sense to select an element with an id and an extra selector - const el = hashStartsWithNumberRE.test(position.selector) - ? document.getElementById(position.selector.slice(1)) - : document.querySelector(position.selector) - - if (el) { - const offset: ScrollToPosition = position.offset || { x: 0, y: 0 } - normalizedPosition = getElementPosition(el, offset) - } - // TODO: else dev warning? - } else { - normalizedPosition = { - x: position.x, - y: position.y, - } - } - - if (isBrowser && normalizedPosition) { - window.scrollTo(normalizedPosition.x, normalizedPosition.y) - } -} - -/** - * TODO: refactor the scroll behavior so it can be tree shaken - */ - -export const scrollPositions = new Map() - -export function getScrollKey(path: string, distance: number): string { - const position: number = - isBrowser && history.state ? history.state.position - distance : -1 - return position + path -} - -export function saveScrollOnLeave(key: string) { - scrollPositions.set(key, isBrowser ? computeScrollPosition() : { x: 0, y: 0 }) -} - -export function getSavedScroll(key: string) { - return scrollPositions.get(key) -}