Skip to content

About

WebGL2 liquid glass for Vue and Nuxt.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Liquid Glass: real shader-refracted glass for Vue 3 and Nuxt

npm version npm downloads bundle size CI status GitHub stars license

Liquid glass for Vue 3 and Nuxt, rendered with WebGL2 shaders. It does real refraction, lens distortion, chromatic aberration, frost and edge lighting in Chrome, Edge, Firefox and Safari.

Documentation

  • Real shader. A signed distance field masks each lens, which has a quarter-circle bevel. It does not use an SVG displacement filter, so Safari and Firefox render the same effect as Chrome.
  • Zero cost at idle. Frames render on demand and the page shares one WebGL context. An idle page makes no requestAnimationFrame or GL calls.
  • Accessible by default. It respects prefers-reduced-motion, prefers-reduced-transparency, prefers-contrast, forced-colors and Save-Data.
  • SSR-first. The server renders a CSS backdrop-filter fallback and the client adds the WebGL canvas after mount. Hydration has no warnings and needs no <ClientOnly>.
  • Small. The main entry is under 12 KiB min+gzip. snapDOM, the optional DOM-capture library, loads only when a snapshot backdrop needs it.

Install

pnpm add @mahbodhastam/liquid-glass
# optional, for glass over arbitrary HTML:
pnpm add @zumer/snapdom

It requires Vue 3.4 or newer. For Nuxt, it requires Nuxt 3.13 or newer, including Nuxt 4.

Quick start

Vue

// main.ts
import { createLiquidGlass } from '@mahbodhastam/liquid-glass'

app.use(createLiquidGlass())
<script setup lang="ts">
import { ref } from 'vue'

const hero = ref<HTMLImageElement | null>(null)
</script>

<template>
  <section class="relative">
    <img ref="hero" src="/hero.jpg" alt="" class="absolute inset-0 size-full object-cover">
    <LiquidGlass :source="hero" class="rounded-3xl p-6" :blur="12" :refraction="0.4">
      <h2>Content stays real DOM</h2>
    </LiquidGlass>
  </section>
</template>

Nuxt

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@mahbodhastam/liquid-glass/nuxt'],
})

Components and composables are auto-imported.

Learn more

The official docs cover backdrops, props, composables, accessibility, performance, quality tiers and browser support. Benchmark numbers and methods are in docs/perf.md.

Development

pnpm install
pnpm build          # tsdown builds dist: index, core, snapdom, nuxt
pnpm dev            # Vite playground (build first; it imports dist)
pnpm dev:nuxt       # Nuxt SSR fixture
pnpm test           # unit (Vitest + happy-dom)
pnpm test:e2e       # real WebGL: Chromium, Firefox, WebKit, Nuxt SSR
pnpm size           # 12 KiB min+gzip budget
pnpm bench          # presentation benchmark

License

MIT

About

WebGL2 liquid glass for Vue and Nuxt.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages