UNPKG

vitepress-openapi

Version:

Generate VitePress API Documentation from OpenAPI Specification.

44 lines (35 loc) 830 B
import type { ClassValue } from 'clsx' import { clsx } from 'clsx' import { twMerge } from 'tailwind-merge' export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } export function isLocalStorageAvailable(): boolean { return typeof localStorage !== 'undefined' && typeof localStorage.getItem === 'function' } const RE_HASH_BRACES = /([{}])/g export function scrollToHash({ hash, }: { hash: string offset?: number container?: HTMLElement }) { if (typeof window === 'undefined') { return } const element = document.querySelector( hash // escape { and } characters .replace(RE_HASH_BRACES, '\\$1'), ) if (!element) { return } element.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest', }) window.location.hash = hash }