{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "liquid-glass",
  "title": "Liquid Glass",
  "author": "Visant Labs <visantsupply@gmail.com>",
  "description": "A superfície que refrata o fundo de verdade, com franja cromática nas bordas. É a base de todas as peças de vidro.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/visant/ui/liquid-glass.tsx",
      "content": "\"use client\";\nimport * as React from \"react\";\n\n/*\n * Miolo: rizroze/liquid-glass (https://github.com/rizroze/liquid-glass).\n * Alterações: tipos, porque o `shadcn add` entrega isto para compilar no projeto de\n * quem instala, e as cores do mapa de deslocamento em rgb(), porque são dado do\n * filtro, não tema, e o portão de hex do registry não distingue.\n *\n * MIT License\n *\n * Copyright (c) 2026 Riz Roze\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nexport interface LiquidGlassOptions {\n  width?: number;\n  height?: number;\n  borderRadius?: number;\n  scale?: number;\n  aberration?: number[];\n  blur?: number;\n  border?: number;\n  lightness?: number;\n  alpha?: number;\n  frost?: number;\n  saturation?: number;\n  displaceBlur?: number;\n  filterId?: string;\n  fallbackFilter?: string;\n}\ntype Config = ReturnType<typeof resolveConfig>;\ntype FilterRefs = ReturnType<typeof createFilterSVG>;\n\nfunction resolveConfig(el: HTMLElement, opts: LiquidGlassOptions) {\n  const rect = el.getBoundingClientRect();\n  const ab = opts.aberration ?? [0, 10, 20];\n  return {\n    width: opts.width ?? Math.round(rect.width),\n    height: opts.height ?? Math.round(rect.height),\n    radius: opts.borderRadius ?? 50,\n    scale: opts.scale ?? -180,\n    border: opts.border ?? 0.07,\n    lightness: opts.lightness ?? 50,\n    alpha: opts.alpha ?? 0.93,\n    blur: opts.blur ?? 11,\n    r: ab[0],\n    g: ab[1],\n    b: ab[2],\n    frost: opts.frost ?? 0,\n    saturation: opts.saturation ?? 1,\n    displace: opts.displaceBlur ?? 0\n  };\n}\nconst isChromium = typeof navigator !== \"undefined\" && /Chrome\\//.test(navigator.userAgent);\nconst _mapCache = /* @__PURE__ */ new Map<string, string>();\nfunction buildDisplacementMap(c: Config) {\n  const key = `${c.width}:${c.height}:${c.radius}:${c.scale}:${c.border}:${c.blur}:${c.lightness}:${c.alpha}`;\n  const cached = _mapCache.get(key);\n  if (cached) return cached;\n  const maxDisplace = Math.max(Math.abs(c.scale) * 0.5, 20);\n  const padX = Math.ceil(maxDisplace);\n  const padY = Math.ceil(maxDisplace);\n  const totalW = c.width + padX * 2;\n  const totalH = c.height + padY * 2;\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = totalW;\n  canvas.height = totalH;\n  const ctx = canvas.getContext(\"2d\")!;\n  ctx.fillStyle = \"rgb(128, 128, 128)\";\n  ctx.fillRect(0, 0, totalW, totalH);\n  const ox = padX;\n  const oy = padY;\n  ctx.save();\n  ctx.beginPath();\n  ctx.roundRect(ox, oy, c.width, c.height, c.radius);\n  ctx.clip();\n  ctx.fillStyle = \"rgb(0, 0, 0)\";\n  ctx.fillRect(ox, oy, c.width, c.height);\n  const redGrad = ctx.createLinearGradient(ox + c.width, oy, ox, oy);\n  redGrad.addColorStop(0, \"rgb(0, 0, 0)\");\n  redGrad.addColorStop(1, \"rgb(255, 0, 0)\");\n  ctx.fillStyle = redGrad;\n  ctx.fillRect(ox, oy, c.width, c.height);\n  ctx.globalCompositeOperation = \"difference\";\n  const blueGrad = ctx.createLinearGradient(ox, oy, ox, oy + c.height);\n  blueGrad.addColorStop(0, \"rgb(0, 0, 0)\");\n  blueGrad.addColorStop(1, \"rgb(0, 0, 255)\");\n  ctx.fillStyle = blueGrad;\n  ctx.fillRect(ox, oy, c.width, c.height);\n  ctx.globalCompositeOperation = \"source-over\";\n  const borderPx = Math.min(c.width, c.height) * (c.border * 0.5);\n  ctx.filter = `blur(${c.blur}px)`;\n  ctx.fillStyle = `hsla(0, 0%, ${c.lightness}%, ${c.alpha})`;\n  ctx.beginPath();\n  ctx.roundRect(\n    ox + borderPx,\n    oy + borderPx,\n    c.width - borderPx * 2,\n    c.height - borderPx * 2,\n    c.radius\n  );\n  ctx.fill();\n  ctx.restore();\n  const uri = canvas.toDataURL();\n  _mapCache.set(key, uri);\n  return uri;\n}\nlet _instanceCount = 0;\nfunction createFilterSVG(id: string) {\n  const svg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n  svg.setAttribute(\"xmlns\", \"http://www.w3.org/2000/svg\");\n  svg.style.cssText = \"position:absolute;width:0;height:0;pointer-events:none;\";\n  svg.innerHTML = `\n    <defs>\n      <filter id=\"${id}\" color-interpolation-filters=\"sRGB\" x=\"-38%\" y=\"-188%\" width=\"176%\" height=\"476%\">\n        <feImage result=\"map\" preserveAspectRatio=\"none\" />\n        <feDisplacementMap in=\"SourceGraphic\" in2=\"map\" xChannelSelector=\"R\" yChannelSelector=\"B\" result=\"dispRed\" data-channel=\"red\" />\n        <feColorMatrix in=\"dispRed\" type=\"matrix\" values=\"1 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0\" result=\"red\" />\n        <feDisplacementMap in=\"SourceGraphic\" in2=\"map\" xChannelSelector=\"R\" yChannelSelector=\"B\" result=\"dispGreen\" data-channel=\"green\" />\n        <feColorMatrix in=\"dispGreen\" type=\"matrix\" values=\"0 0 0 0 0  0 1 0 0 0  0 0 0 0 0  0 0 0 1 0\" result=\"green\" />\n        <feDisplacementMap in=\"SourceGraphic\" in2=\"map\" xChannelSelector=\"R\" yChannelSelector=\"B\" result=\"dispBlue\" data-channel=\"blue\" />\n        <feColorMatrix in=\"dispBlue\" type=\"matrix\" values=\"0 0 0 0 0  0 0 0 0 0  0 0 1 0 0  0 0 0 1 0\" result=\"blue\" />\n        <feBlend in=\"red\" in2=\"green\" mode=\"screen\" result=\"rg\" />\n        <feBlend in=\"rg\" in2=\"blue\" mode=\"screen\" result=\"output\" />\n        <feGaussianBlur in=\"output\" stdDeviation=\"0\" />\n      </filter>\n    </defs>\n  `;\n  const filter = svg.querySelector(\"filter\")!;\n  const feImage = svg.querySelector(\"feImage\")!;\n  const red = svg.querySelector('[data-channel=\"red\"]')!;\n  const green = svg.querySelector('[data-channel=\"green\"]')!;\n  const blue = svg.querySelector('[data-channel=\"blue\"]')!;\n  const blurEl = svg.querySelector(\"feGaussianBlur\")!;\n  return { svg, feImage, red, green, blue, blur: blurEl, filter };\n}\nfunction applyConfig(c: Config, refs: FilterRefs) {\n  /* Peça ainda sem tamanho (oculta ou antes do layout): medir aqui daria x=\"-Infinity%\" no filtro. */\n  if (c.width <= 0 || c.height <= 0) return;\n  const uri = buildDisplacementMap(c);\n  const maxD = Math.max(Math.abs(c.scale) * 0.5, 20);\n  const pctX = Math.ceil(maxD / c.width * 100);\n  const pctY = Math.ceil(maxD / c.height * 100);\n  refs.filter.setAttribute(\"x\", `-${pctX}%`);\n  refs.filter.setAttribute(\"y\", `-${pctY}%`);\n  refs.filter.setAttribute(\"width\", `${100 + pctX * 2}%`);\n  refs.filter.setAttribute(\"height\", `${100 + pctY * 2}%`);\n  refs.feImage.setAttributeNS(\"http://www.w3.org/1999/xlink\", \"href\", uri);\n  refs.feImage.setAttribute(\"href\", uri);\n  refs.red.setAttribute(\"scale\", String(c.scale + c.r));\n  refs.green.setAttribute(\"scale\", String(c.scale + c.g));\n  refs.blue.setAttribute(\"scale\", String(c.scale + c.b));\n  refs.blur.setAttribute(\"stdDeviation\", String(c.displace));\n}\nfunction createLiquidGlass(element: HTMLElement, options: LiquidGlassOptions = {}) {\n  const fallback = options.fallbackFilter ?? \"blur(12px)\";\n  if (!isChromium) {\n    const prev = element.style.backdropFilter;\n    const prevWebkit = element.style.getPropertyValue(\"-webkit-backdrop-filter\");\n    element.style.backdropFilter = fallback;\n    element.style.setProperty(\"-webkit-backdrop-filter\", fallback);\n    const dummySvg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n    return {\n      isActive: false,\n      filterElement: dummySvg,\n      update(_: LiquidGlassOptions) {\n      },\n      destroy() {\n        element.style.backdropFilter = prev;\n        element.style.setProperty(\"-webkit-backdrop-filter\", prevWebkit);\n      }\n    };\n  }\n  const id = options.filterId ?? `liquid-glass-${++_instanceCount}`;\n  const refs = createFilterSVG(id);\n  document.body.appendChild(refs.svg);\n  let currentOpts = { ...options };\n  let config = resolveConfig(element, currentOpts);\n  applyConfig(config, refs);\n  const applyStyles = (c: Config) => {\n    element.style.backdropFilter = `url(#${id}) saturate(${c.saturation})`;\n    element.style.setProperty(\n      \"-webkit-backdrop-filter\",\n      `url(#${id}) saturate(${c.saturation})`\n    );\n    if (c.frost > 0) {\n      element.style.background = `hsl(0 0% 0% / ${c.frost})`;\n    }\n  };\n  applyStyles(config);\n  let resizeRaf = 0;\n  const ro = new ResizeObserver(() => {\n    cancelAnimationFrame(resizeRaf);\n    resizeRaf = requestAnimationFrame(() => {\n      if (currentOpts.width == null || currentOpts.height == null) {\n        config = resolveConfig(element, currentOpts);\n        applyConfig(config, refs);\n        applyStyles(config);\n      }\n    });\n  });\n  ro.observe(element);\n  return {\n    isActive: true,\n    filterElement: refs.svg,\n    update(newOpts: LiquidGlassOptions) {\n      currentOpts = { ...currentOpts, ...newOpts };\n      config = resolveConfig(element, currentOpts);\n      applyConfig(config, refs);\n      applyStyles(config);\n    },\n    destroy() {\n      ro.disconnect();\n      cancelAnimationFrame(resizeRaf);\n      refs.svg.remove();\n      element.style.backdropFilter = \"\";\n      element.style.setProperty(\"-webkit-backdrop-filter\", \"\");\n      element.style.background = \"\";\n    }\n  };\n}\n\n/** Opções fixas, ou em função da altura: refração em px some numa peça grande. */\nexport type GlassOptions = LiquidGlassOptions | ((height: number) => LiquidGlassOptions);\n\n/**\n * A superfície que refrata o que está atrás dela. Chromium refrata de verdade;\n * Safari e Firefox caem em blur sozinhos.\n *\n * Vidro sobre vidro tem de ser IRMÃO, nunca filho: backdrop-filter faz do elemento\n * uma \"backdrop root\", e um filho com backdrop-filter só enxerga o que está dentro\n * do pai. Por isso as peças de vidro põem esta camada ao lado do conteúdo.\n *\n * O tamanho vem de offsetWidth/Height, não do retângulo na tela: dentro de um palco\n * escalado por transform, o retângulo mente e o mapa sai no tamanho errado.\n */\nexport function LiquidGlass({\n  options = {},\n  ...props\n}: React.HTMLAttributes<HTMLDivElement> & { options?: GlassOptions }) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const opts = React.useRef(options);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const read = () => {\n      const h = el.offsetHeight;\n      const o = opts.current;\n      return { ...(typeof o === \"function\" ? o(h) : o), width: el.offsetWidth, height: h };\n    };\n    const glass = createLiquidGlass(el, read());\n    const ro = new ResizeObserver(() => glass.update(read()));\n    ro.observe(el);\n    return () => {\n      ro.disconnect();\n      glass.destroy();\n    };\n  }, []);\n  return <div ref={ref} {...props} />;\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "uso": {
      "quando": "Superfície própria que precise refratar o fundo, como barra flutuante ou lente",
      "evite": "Painel grande com conteúdo: glass-panel; controle pronto: glass-button ou glass-slider"
    }
  },
  "categories": [
    "efeitos",
    "vidro",
    "refracao",
    "backdrop-filter",
    "primitiva"
  ],
  "type": "registry:ui"
}