Constants
Global constants for browser feature detection and environment checks. All constants are exported from #v0/constants.
Import
import {
IN_BROWSER,
SUPPORTS_TOUCH,
SUPPORTS_MATCH_MEDIA,
SUPPORTS_OBSERVER,
SUPPORTS_INTERSECTION_OBSERVER,
SUPPORTS_MUTATION_OBSERVER,
version,
__LOGGER_ENABLED__
} from '#v0/constants'
Environment Detection
IN_BROWSER
SSR-safe check for browser environment.
const IN_BROWSER: boolean
true if running in a browser environment, false during SSR
Implementation
export const IN_BROWSER = typeof window !== 'undefined'
Usage
import { IN_BROWSER } from '#v0/constants'
if (IN_BROWSER) {
// Safe to access window, document, localStorage, etc.
window.addEventListener('resize', handleResize)
}
// Conditionally import browser-only code
const storage = IN_BROWSER
? window.localStorage
: new Map() // SSR fallback
<script setup lang="ts">
import { IN_BROWSER } from '#v0/constants'
import { onMounted } from 'vue'
if (IN_BROWSER) {
// Run immediately in browser
console.log('Browser detected')
} else {
// Use onMounted for SSR-safe initialization
onMounted(() => {
console.log('Client hydrated')
})
}
</script>
Feature Detection
SUPPORTS_TOUCH
Detects touch device support.
const SUPPORTS_TOUCH: boolean
true if the device supports touch events
Implementation
export const SUPPORTS_TOUCH = IN_BROWSER && (
'ontouchstart' in window || window.navigator.maxTouchPoints > 0
)
Usage
import { SUPPORTS_TOUCH } from '#v0/constants'
if (SUPPORTS_TOUCH) {
element.addEventListener('touchstart', handleTouch)
} else {
element.addEventListener('mousedown', handleMouse)
}
// Adjust UI for touch devices
const buttonSize = SUPPORTS_TOUCH ? 'large' : 'medium'
Detects matchMedia API availability.
const SUPPORTS_MATCH_MEDIA: boolean
true if window.matchMedia is available
Implementation
export const SUPPORTS_MATCH_MEDIA = IN_BROWSER &&
'matchMedia' in window &&
typeof window.matchMedia === 'function'
Usage
import { SUPPORTS_MATCH_MEDIA } from '#v0/constants'
if (SUPPORTS_MATCH_MEDIA) {
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
mediaQuery.addEventListener('change', handleThemeChange)
}
// Safe media query helper
function useMediaQuery(query: string) {
if (!SUPPORTS_MATCH_MEDIA) return false
return window.matchMedia(query).matches
}
const isDark = useMediaQuery('(prefers-color-scheme: dark)')
SUPPORTS_OBSERVER
Detects ResizeObserver API availability.
const SUPPORTS_OBSERVER: boolean
true if ResizeObserver is available
Implementation
export const SUPPORTS_OBSERVER = IN_BROWSER && 'ResizeObserver' in window
Usage
import { SUPPORTS_OBSERVER } from '#v0/constants'
if (SUPPORTS_OBSERVER) {
const observer = new ResizeObserver(entries => {
for (const entry of entries) {
console.log('Element resized:', entry.contentRect)
}
})
observer.observe(element)
} else {
// Fallback: use window resize listener
window.addEventListener('resize', handleResize)
}
SUPPORTS_INTERSECTION_OBSERVER
Detects IntersectionObserver API availability.
const SUPPORTS_INTERSECTION_OBSERVER: boolean
true if IntersectionObserver is available
Implementation
export const SUPPORTS_INTERSECTION_OBSERVER = IN_BROWSER &&
'IntersectionObserver' in window
Usage
import { SUPPORTS_INTERSECTION_OBSERVER } from '#v0/constants'
if (SUPPORTS_INTERSECTION_OBSERVER) {
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
console.log('Element is visible')
}
})
})
observer.observe(element)
} else {
// Fallback: assume always visible or use scroll listener
console.log('IntersectionObserver not supported')
}
// Lazy loading images
if (SUPPORTS_INTERSECTION_OBSERVER) {
const lazyImages = document.querySelectorAll('img[data-src]')
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target as HTMLImageElement
img.src = img.dataset.src!
imageObserver.unobserve(img)
}
})
})
lazyImages.forEach(img => imageObserver.observe(img))
}
SUPPORTS_MUTATION_OBSERVER
Detects MutationObserver API availability.
const SUPPORTS_MUTATION_OBSERVER: boolean
true if MutationObserver is available
Implementation
export const SUPPORTS_MUTATION_OBSERVER = IN_BROWSER &&
'MutationObserver' in window
Usage
import { SUPPORTS_MUTATION_OBSERVER } from '#v0/constants'
if (SUPPORTS_MUTATION_OBSERVER) {
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
console.log('DOM changed:', mutation.type)
})
})
observer.observe(element, {
attributes: true,
childList: true,
subtree: true
})
} else {
// Fallback: manual tracking or polling
console.log('MutationObserver not supported')
}
Version
version
The current version of @vuetify/v0.
Semantic version string (e.g., '0.1.0')
Implementation
export const version = typeof __VERSION__ === 'undefined' ? '0.0.0' : __VERSION__
Usage
import { version } from '#v0/constants'
console.log(`Running @vuetify/v0 ${version}`)
// Feature detection based on version
const [major, minor, patch] = version.split('.').map(Number)
if (major >= 1) {
// Use new API
}
Development
LOGGER_ENABLED
Indicates whether logging is enabled.
const __LOGGER_ENABLED__: boolean
true if logging is enabled (development mode or explicitly enabled)
This is a build-time constant. It’s automatically set based on the environment and should not be manually modified.
Implementation
export const __LOGGER_ENABLED__ = (
typeof __DEV__ !== 'undefined' && __DEV__
) || (
typeof __VITE_LOGGER_ENABLED__ !== 'undefined' &&
__VITE_LOGGER_ENABLED__ === 'true'
)
Usage
import { __LOGGER_ENABLED__ } from '#v0/constants'
if (__LOGGER_ENABLED__) {
console.log('[v0] Debug information')
}
// Tree-shaking: dead code elimination in production
if (__LOGGER_ENABLED__) {
// This entire block will be removed in production builds
console.group('[v0] Performance Metrics')
console.log('Render time:', performance.now())
console.groupEnd()
}
HTML Elements
Set of HTML elements that are self-closing (void elements).
const SELF_CLOSING_TAGS: Set<SelfClosingElement>
These elements cannot have children and don’t need closing tags:
area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr
Usage
import { SELF_CLOSING_TAGS } from '#v0/constants'
if (SELF_CLOSING_TAGS.has(tagName)) {
// Don't try to append children
}
COMMON_ELEMENTS
Common HTML element types for polymorphic components.
const COMMON_ELEMENTS: Record<string, string>
Categories
- Layout:
DIV, SPAN, SECTION, ARTICLE, ASIDE, HEADER, FOOTER, MAIN, NAV
- Text:
P, H1, H2, H3, H4, H5, H6
- Interactive:
BUTTON, A, INPUT, TEXTAREA, SELECT, LABEL
- Lists:
UL, OL, LI, DL, DT, DD
- Media:
IMG, VIDEO, AUDIO, CANVAS, SVG
- Table:
TABLE, THEAD, TBODY, TFOOT, TR, TH, TD
- Form:
FORM, FIELDSET, LEGEND
Usage
import { COMMON_ELEMENTS } from '#v0/constants'
const element = COMMON_ELEMENTS.BUTTON // 'button'
const container = COMMON_ELEMENTS.DIV // 'div'
isSelfClosingTag
Checks if an element is self-closing.
function isSelfClosingTag(tag: keyof HTMLElementTagNameMap): boolean
tag
keyof HTMLElementTagNameMap
required
The HTML tag name to check
true if the tag is self-closing
Usage
import { isSelfClosingTag } from '#v0/constants'
isSelfClosingTag('img') // true
isSelfClosingTag('div') // false
isSelfClosingTag('input') // true