glass-core
pane/glass-coreFreeUtility
pane publishes no description for this item.
Install it
npx shadcn@latest add https://pane.theui.company/r/glass-core.jsonSource
1"use client";23import * as React from "react";4import { GLASS_DISPLACEMENT } from "./config";5import { buildDisplacementMap, resolveBand } from "./displacement";6import type { GlassVariant } from "./types";78interface GlassFilterProps {9 id: string;10 variant: GlassVariant;11 width: number;12 height: number;13 radius: number;14}1516/**17 * Renders the hidden SVG that holds the actual refraction filter. Referenced18 * from CSS as `backdrop-filter: blur(...) url(#id)`. Chromium applies the19 * full displacement + chromatic-aberration chain; browsers that don't20 * support an SVG filter reference inside backdrop-filter simply ignore it21 * and fall back to the blur/saturate/specular layers, which is why this22 * only ever adds a bonus layer, never load-bearing.23 */24export function GlassFilter({25 id,26 variant,27 width,28 height,29 radius,30}: GlassFilterProps) {31 const cfg = GLASS_DISPLACEMENT[variant];3233 /**34 * How much of the configured bevel this element can carry. Small controls get35 * a narrower band (see `resolveBand`) and the deflection has to come down36 * with it: bending the backdrop further than the band is wide drags samples37 * from past the far side of the rim.38 */39 const scale = resolveBand(width, height, cfg.edge) / cfg.edge;40 const strength = cfg.strength * scale;4142 /** px of slack around the element: enough for the blurred map to settle and43 * for the rim to sample backdrop from just outside the border box */44 const margin = Math.ceil(strength + cfg.blur * 3);4546 const mapUri = React.useMemo(() => {47 if (width <= 0 || height <= 0) return null;48 return buildDisplacementMap({49 width,50 height,51 radius,52 edge: cfg.edge,53 margin,54 });55 }, [width, height, radius, cfg.edge, margin]);5657 if (!mapUri) return null;5859 /* the map's full deflection is 127/255 off centre, i.e. half a unit, so a60 `scale` of 2n buys n px of pull at the rim — config states the px. */61 const base = strength * 2;62 const aberration = cfg.chromaticAberration * scale * 2;6364 return (65 <svg66 aria-hidden="true"67 focusable="false"68 className="absolute h-0 w-0 overflow-hidden"69 >70 <defs>71 {/* everything sized in px against the element's own box: with72 percentage regions the map's placement is left to the filter73 region and the backdrop ends up offset from the surface it74 belongs to */}75 <filter76 id={id}77 filterUnits="userSpaceOnUse"78// … truncated
What it pulls in
npm packages
