@ikeofficial/liquid-glass-js 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +138 -2
- package/build/angular/index.d.ts +8 -0
- package/build/angular/index.js +1 -0
- package/build/core/liquid-glass.css +1 -0
- package/build/core/liquid-glass.d.ts +45 -0
- package/build/core/liquid-glass.js +1 -0
- package/build/core/optics.js +1 -0
- package/build/core/options.js +1 -0
- package/build/core/renderers/sampled.js +1 -0
- package/build/core/renderers/svg.js +1 -0
- package/build/core/renderers/webgl.js +28 -0
- package/build/react/index.d.ts +4 -0
- package/build/react/index.js +1 -0
- package/build/vue/index.d.ts +3 -0
- package/build/vue/index.js +1 -0
- package/package.json +80 -4
- package/skills/liquid-glass-js/SKILL.md +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mattia Bigi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Liquid Glass JS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A dependency-free glass material for ordinary HTML elements. It can bend the element’s own text, CSS and images, sample an image, canvas or video behind it, or refract the live page backdrop. Angular, React and Vue bind the same JavaScript core to their lifecycle.
|
|
4
|
+
|
|
5
|
+
## Playground
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
mise trust
|
|
9
|
+
mise install
|
|
10
|
+
mise run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Open [the local playground](http://127.0.0.1:4173/demo/). Drag the lens or focus it and use the arrow keys. Compare the photo, grid and typography scenes and change the optical settings. Select Button, Switch, Slider, Segmented, or Media in the native-controls showcase to try the control and copy Tailwind HTML, JavaScript, Angular, Vue, or React source. The usage panel includes examples for all four entry points.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @ikeofficial/liquid-glass-js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The package includes minified ESM and CSS, TypeScript declarations, and an [agent skill](skills/liquid-glass-js/SKILL.md). Frameworks are optional peers of their respective adapters. Installing the core alone adds zero dependencies. The playground and build tools use separate development dependencies.
|
|
22
|
+
|
|
23
|
+
## Publishing
|
|
24
|
+
|
|
25
|
+
The **Publish to npm** GitHub Actions workflow publishes `@ikeofficial/liquid-glass-js` to npmjs.com. Add an npm granular access token with permission to publish this package and bypass 2FA as the `NPM_TOKEN` repository secret under GitHub Settings → Secrets and variables → Actions. Do not commit the token. npm plans to remove direct publishing with granular tokens in January 2027; migrate to [trusted publishing](https://docs.npmjs.com/trusted-publishers/) before then.
|
|
26
|
+
|
|
27
|
+
Update the version in `package.json`, then run **Publish to npm** from the Actions tab. Each published npm version must be new. To build a local archive, run `mise run install` and `mise run pack`.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
[MIT](LICENSE)
|
|
32
|
+
|
|
33
|
+
## Plain JavaScript
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { liquidGlass } from "@ikeofficial/liquid-glass-js";
|
|
37
|
+
import "@ikeofficial/liquid-glass-js/style.css";
|
|
38
|
+
|
|
39
|
+
const item = document.querySelector("#item");
|
|
40
|
+
const glass = liquidGlass(item, { mode: "content", radius: 30, refraction: 18 });
|
|
41
|
+
|
|
42
|
+
glass.update({ chroma: 0.2 });
|
|
43
|
+
glass.destroy();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The call returns a controller. Reapplying to the same element updates the existing controller. `update(options)` merges options. Use `update(options, { replace: true })` to reset omitted options. Call `destroy()` when the element unmounts. Read `glass.renderer` for the active renderer or listen on the host for `liquidglass:rendererchange`.
|
|
47
|
+
|
|
48
|
+
For plain HTML, copy the `src/` folder from the repository and serve it over HTTP. Load `liquid-glass.css` with a stylesheet link and import `liquidGlass` from the folder’s `liquid-glass.js` in a module script.
|
|
49
|
+
|
|
50
|
+
## Angular
|
|
51
|
+
|
|
52
|
+
Add `LiquidGlassDirective` to a standalone component’s imports and load the shared stylesheet globally, for example via your Angular workspace’s styles list. Angular 20 or later within the package’s peer range.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Component } from "@angular/core";
|
|
56
|
+
import { LiquidGlassDirective } from "@ikeofficial/liquid-glass-js/angular";
|
|
57
|
+
|
|
58
|
+
@Component({
|
|
59
|
+
imports: [LiquidGlassDirective],
|
|
60
|
+
template: '<button [liquidGlass]="{ mode: \'content\', radius: 22 }">Continue</button>',
|
|
61
|
+
})
|
|
62
|
+
export class Action {}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
A bare `liquidGlass` attribute uses the defaults.
|
|
66
|
+
|
|
67
|
+
## React
|
|
68
|
+
|
|
69
|
+
```jsx
|
|
70
|
+
import { useLiquidGlass } from "@ikeofficial/liquid-glass-js/react";
|
|
71
|
+
import "@ikeofficial/liquid-glass-js/style.css";
|
|
72
|
+
|
|
73
|
+
export function Action() {
|
|
74
|
+
const ref = useLiquidGlass({ mode: "content", radius: 22 });
|
|
75
|
+
return <button ref={ref}>Continue</button>;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The hook returns a callback ref for a DOM element. In TypeScript, you can narrow it with `useLiquidGlass<HTMLButtonElement>()`.
|
|
80
|
+
|
|
81
|
+
## Vue
|
|
82
|
+
|
|
83
|
+
```vue
|
|
84
|
+
<script setup>
|
|
85
|
+
import { vLiquidGlass } from "@ikeofficial/liquid-glass-js/vue";
|
|
86
|
+
import "@ikeofficial/liquid-glass-js/style.css";
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<button v-liquid-glass="{ mode: 'content', radius: 22 }">Continue</button>
|
|
91
|
+
</template>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The directive can also be registered globally with `app.directive("liquid-glass", vLiquidGlass)`.
|
|
95
|
+
|
|
96
|
+
## Rendering modes
|
|
97
|
+
|
|
98
|
+
| Options | What bends | Browser behavior |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `{ mode: "content" }` | The host’s rendered pixels, including its CSS background and descendants | SVG element filter in Chromium, Firefox and WebKit |
|
|
101
|
+
| Default, or `{ mode: "auto" }` | Live page pixels when supported, otherwise the supplied backdrop | SVG refraction in Chromium, sampled media when supplied, then CSS frost |
|
|
102
|
+
| `{ mode: "backdrop" }` | Arbitrary page pixels behind the host | SVG refraction in Chromium. CSS frost in other engines. A supplied backdrop retains its sample-first behavior. |
|
|
103
|
+
| `{ mode: "sampled", backdrop: media }` | A supplied `<img>`, `<canvas>`, or `<video>` behind the host | Shared WebGL renderer where available, with Canvas 2D fallback |
|
|
104
|
+
| `{ mode: "frost" }` | No displacement | CSS tint, blur and highlights where supported |
|
|
105
|
+
|
|
106
|
+
Use an ordinary HTML host with available `::before` and `::after` pseudo-elements. For content mode, put the artwork inside the host or use a CSS background. The filter refracts pixels only inside the lens silhouette. Use a decorative presentation layer for labels that must stay sharp, and keep the filtered host compact on mobile. The playground clips the aligned scene copy at the parent after refraction, so the glass outline stays stable as the optical settings change.
|
|
107
|
+
|
|
108
|
+
A sampled media element must sit visually behind the lens in the same document, axis-aligned, without padding or borders. Images and videos support `object-fit: fill` or centered `cover` or `contain`. Use a same-origin or CORS-enabled source. The library resamples on resize, scroll, and media load. Video uses `requestVideoFrameCallback()` when available. Call `glass.refresh()` after moving the lens programmatically or redrawing a canvas.
|
|
109
|
+
|
|
110
|
+
Automatic mode requires an explicit `backdrop` element for the sampled fallback. Use `mode: "sampled"` when the video or image should drive refraction on every browser. For the native-control snippets, load Tailwind CSS v4 and the shared glass stylesheet. The Media example also needs a same-origin video and poster, or a video served with CORS enabled and loaded with `crossorigin="anonymous"`.
|
|
111
|
+
|
|
112
|
+
The SVG modes use an internally generated PNG data URL. Where CSP disallows `data:` images, use a sampled backdrop or frost. Reduced motion disables pointer tracking. Reduced transparency and forced colors use a solid treatment. A CSS-only treatment is also available by applying the `liquid-glass` class with the shared stylesheet.
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
| Option | Default | Effect |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| `mode` | `"auto"` | Auto, content, backdrop, sampled, or frost |
|
|
119
|
+
| `backdrop` | `null` | Optional image, canvas or video source for auto, backdrop, and sampled modes |
|
|
120
|
+
| `radius` | 24 | Corner radius in CSS pixels. Set size with your CSS |
|
|
121
|
+
| `refraction` | 18 | Requested edge displacement in CSS pixels, bounded by the lens size. Zero disables distortion |
|
|
122
|
+
| `bevel` | 24 | Width of the refracted edge in CSS pixels |
|
|
123
|
+
| `curvature` | 2 | Shape of the optical bevel, 0.25–8 |
|
|
124
|
+
| `chroma` | 0 | Color-channel spread, 0–1 |
|
|
125
|
+
| `blur` | 2 | Frost in CSS pixels |
|
|
126
|
+
| `saturation` | 1.35 | Color saturation multiplier |
|
|
127
|
+
| `tint` | 0.14 | Tint opacity, 0–1. Set `--liquid-glass-tint-rgb` as an RGB triplet |
|
|
128
|
+
| `glow` | 0.23 | Interior highlight opacity, 0–1 |
|
|
129
|
+
| `edgeHighlight` | 0.85 | Rim light intensity, 0–1 |
|
|
130
|
+
| `lightAngle` | 145 | Rim gradient angle in degrees |
|
|
131
|
+
| `interactive` | `true` | Pointer-tracking highlight |
|
|
132
|
+
|
|
133
|
+
## Agent skill
|
|
134
|
+
|
|
135
|
+
Copy [`skills/liquid-glass-js`](skills/liquid-glass-js) into your project’s `.agents/skills/` directory. Invoke `$liquid-glass-js` and provide a checkout or tarball path.
|
|
136
|
+
|
|
137
|
+
## References
|
|
138
|
+
|
|
139
|
+
The content-rendering approach draws on [Aave’s Building Glass for the Web](https://aave.com/design/building-glass-for-the-web) and the browser measurements reported by [gentpan/liquidglass](https://github.com/gentpan/liquidglass). The playground uses original generated photography.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type LiquidGlassOptions } from "@ikeofficial/liquid-glass-js";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export declare class LiquidGlassDirective {
|
|
4
|
+
readonly liquidGlass: import("@angular/core").InputSignal<"" | LiquidGlassOptions | null>;
|
|
5
|
+
constructor();
|
|
6
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LiquidGlassDirective, never>;
|
|
7
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<LiquidGlassDirective, "[liquidGlass]", never, { "liquidGlass": { "alias": "liquidGlass"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{afterRenderEffect as o,DestroyRef as n,Directive as u,ElementRef as c,inject as r,input as d,NgZone as p}from"@angular/core";import{liquidGlass as m}from"@ikeofficial/liquid-glass-js";import*as e from"@angular/core";class s{liquidGlass=d("",...ngDevMode?[{debugName:"liquidGlass"}]:[]);constructor(){const{nativeElement:a}=r(c),l=r(p);let t;o({write:()=>{const i=this.liquidGlass()||{};l.runOutsideAngular(()=>{t?t.update(i,{replace:!0}):t=m(a,i)})}}),r(n).onDestroy(()=>t?.destroy())}static \u0275fac=e.\u0275\u0275ngDeclareFactory({minVersion:"12.0.0",version:"20.3.35",ngImport:e,type:s,deps:[],target:e.\u0275\u0275FactoryTarget.Directive});static \u0275dir=e.\u0275\u0275ngDeclareDirective({minVersion:"17.1.0",version:"20.3.35",type:s,isStandalone:!0,selector:"[liquidGlass]",inputs:{liquidGlass:{classPropertyName:"liquidGlass",publicName:"liquidGlass",isSignal:!0,isRequired:!1,transformFunction:null}},ngImport:e})}e.\u0275\u0275ngDeclareClassMetadata({minVersion:"12.0.0",version:"20.3.35",ngImport:e,type:s,decorators:[{type:u,args:[{selector:"[liquidGlass]",standalone:!0}]}],ctorParameters:()=>[],propDecorators:{liquidGlass:[{type:e.Input,args:[{isSignal:!0,alias:"liquidGlass",required:!1}]}]}});export{s as LiquidGlassDirective};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:where(.liquid-glass){--liquid-glass-lens: ;--liquid-glass-content-filter: none;--liquid-glass-overlay-filter: var(--liquid-glass-lens) blur(var(--liquid-glass-blur, 2px)) saturate(var(--liquid-glass-saturation, 1.35));--liquid-glass-light-x: 25%;--liquid-glass-light-y: 0%;position:relative;z-index:0;border-radius:var(--liquid-glass-radius, 24px);filter:var(--liquid-glass-content-filter)}:where(.liquid-glass):before,:where(.liquid-glass):after{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none}:where(.liquid-glass):before{z-index:-1;background:radial-gradient(ellipse at var(--liquid-glass-light-x) var(--liquid-glass-light-y),rgb(255 255 255 / var(--liquid-glass-glow, .23)),transparent 72%),rgb(var(--liquid-glass-tint-rgb, 255 255 255) / var(--liquid-glass-tint, .14));-webkit-backdrop-filter:var(--liquid-glass-overlay-filter);backdrop-filter:var(--liquid-glass-overlay-filter)}:where(.liquid-glass):after{padding:1px;opacity:calc(var(--liquid-glass-edge, .85) * var(--liquid-glass-css-rim, 1));background:radial-gradient(ellipse at var(--liquid-glass-light-x) var(--liquid-glass-light-y),rgb(255 255 255 / .95),transparent 64%),linear-gradient(var(--liquid-glass-angle, 145deg),rgb(255 255 255 / .55),rgb(255 255 255 / .11) 50%,rgb(255 255 255 / .42));mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);mask-composite:exclude}:where(.liquid-glass:active):before{box-shadow:inset 0 0 18px #ffffff2b}:where(.liquid-glass>.liquid-glass-backdrop){position:absolute;inset:0;width:100%;height:100%;z-index:-2;border-radius:inherit;pointer-events:none}@media(prefers-reduced-transparency:reduce),(forced-colors:active){:where(.liquid-glass){filter:none}:where(.liquid-glass):before{background:var(--liquid-glass-solid, Canvas);-webkit-backdrop-filter:none;backdrop-filter:none}:where(.liquid-glass):after{background:currentColor}:where(.liquid-glass>.liquid-glass-backdrop){visibility:hidden}}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type LiquidGlassMode = "auto" | "content" | "backdrop" | "sampled" | "frost";
|
|
2
|
+
export type LiquidGlassRenderer = "content" | "backdrop" | "sampled" | "frost";
|
|
3
|
+
|
|
4
|
+
export interface LiquidGlassOptions {
|
|
5
|
+
/** Auto (default) prefers live backdrop refraction, then a supplied backdrop, then frost. */
|
|
6
|
+
mode?: LiquidGlassMode;
|
|
7
|
+
/** Optional image, canvas, or video displayed behind a lens in auto, sampled, or backdrop mode. */
|
|
8
|
+
backdrop?: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | null;
|
|
9
|
+
/** Uniform corner radius in CSS pixels. Defaults to 24. */
|
|
10
|
+
radius?: number;
|
|
11
|
+
/** Blur in CSS pixels. Defaults to 2. */
|
|
12
|
+
blur?: number;
|
|
13
|
+
/** Maximum edge displacement in CSS pixels. Defaults to 18. */
|
|
14
|
+
refraction?: number;
|
|
15
|
+
/** Width of the refractive edge in CSS pixels. Defaults to 24. */
|
|
16
|
+
bevel?: number;
|
|
17
|
+
/** Falloff exponent from 0.25 to 8. Defaults to 2. */
|
|
18
|
+
curvature?: number;
|
|
19
|
+
/** Chromatic spread from 0 to 1. Defaults to 0. */
|
|
20
|
+
chroma?: number;
|
|
21
|
+
/** Saturation multiplier. Defaults to 1.35. */
|
|
22
|
+
saturation?: number;
|
|
23
|
+
/** Tint opacity from 0 to 1. Defaults to 0.14. */
|
|
24
|
+
tint?: number;
|
|
25
|
+
/** Interior highlight opacity from 0 to 1. Defaults to 0.23. */
|
|
26
|
+
glow?: number;
|
|
27
|
+
/** Rim highlight intensity from 0 to 1. Defaults to 0.85. */
|
|
28
|
+
edgeHighlight?: number;
|
|
29
|
+
/** Rim gradient angle in degrees. Defaults to 145. */
|
|
30
|
+
lightAngle?: number;
|
|
31
|
+
/** Enable pointer-tracking highlights. Defaults to true. */
|
|
32
|
+
interactive?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LiquidGlassController {
|
|
36
|
+
/** The active renderer after the last scheduled paint. */
|
|
37
|
+
readonly renderer: LiquidGlassRenderer;
|
|
38
|
+
/** Merge changes, or reset omitted options to their defaults with replace. */
|
|
39
|
+
update(options: LiquidGlassOptions, behavior?: { replace?: boolean }): void;
|
|
40
|
+
/** Resample an explicit backdrop after changing position or drawing new canvas content. */
|
|
41
|
+
refresh(): void;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function liquidGlass(element: HTMLElement, options?: LiquidGlassOptions): LiquidGlassController;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lensGeometry as te}from"./optics.js";import{resolveOptions as K}from"./options.js";import{makeBackdropLens as ne}from"./renderers/sampled.js";import{browserEngine as re,makeSvgLens as ie}from"./renderers/svg.js";const H=new WeakMap,R="liquid-glass";function le(t,z={}){const O=t?.ownerDocument,n=O?.defaultView;if(!n||!(t instanceof n.HTMLElement))throw new TypeError("liquidGlass requires an HTML element");const C=H.get(t);if(C)return C.update(z),C;let r=K(n,z);const T=re(n),Q=T==="blink"&&n.CSS?.supports("backdrop-filter",'url("#glass")'),S=n.matchMedia("(prefers-reduced-motion: reduce)"),w=n.matchMedia("(prefers-reduced-transparency: reduce), (forced-colors: active)"),V=new Map,U=t.classList.contains(R),q=new n.ResizeObserver(a);let M,P,l,x,c,A,v=null,p=null,g,m="frost",h=!1;function s(e,i){const o="--liquid-glass-"+e;t.style.getPropertyValue(o)!==String(i)&&(V.has(o)||V.set(o,[t.style.getPropertyValue(o),t.style.getPropertyPriority(o)]),t.style.setProperty(o,i))}function a(){!h&&v===null&&(v=n.requestAnimationFrame(Z))}function f(e,i=""){s("overlay-filter",e==="content"?"none":""),s("css-rim",e==="content"||e==="sampled"?0:""),s("content-filter",e==="content"?i:""),s("lens",e==="backdrop"?i:""),m!==e&&(m=e,n.queueMicrotask(()=>{!h&&m===e&&t.dispatchEvent(new n.CustomEvent("liquidglass:rendererchange",{detail:{renderer:e}}))}))}function y(){M?.dispose(),M=void 0,P=void 0}function Z(){v=null;const{mode:e,refraction:i,radius:o,bevel:d,curvature:u,lightAngle:$}=r,E=e==="content",j=Q&&(e==="auto"||e==="backdrop"),D=j&&e==="auto",b=E?t.offsetWidth:t.clientWidth,k=E?t.offsetHeight:t.clientHeight;if(w.matches||e==="frost"||!i||!t.isConnected||!b||!k){f("frost"),y(),l?.canvas.remove();return}const X=E?Math.min(n.devicePixelRatio||1,2):1,Y=[b,k,Math.min(o,b/2,k/2),d,u,$,X].join("/");Y!==x?.key&&(x={...te(b,k,r,X),width:b,height:k,key:Y});function I(){return c?(l??=ne(O),l.canvas.parentNode||t.prepend(l.canvas),l.render(c,x,r)?(f("sampled"),!0):(l.canvas.remove(),!1)):(l?.canvas.remove(),!1)}if(!D&&I()){y();return}if(!E&&!j){f("frost"),y();return}const F=E?"content":"backdrop";P!==F&&(y(),M=ie(t,T,F),P=F,l?.canvas.remove(),f("frost"));const ee=r;M.render(x,r,J=>{r===ee&&(J?(l?.canvas.remove(),f(F,J)):(!D||!I())&&f("frost"))})}function L(){g=void 0,s("light-x",""),s("light-y","")}function B(e){!r.interactive||S.matches||e.pointerType==="touch"||(g={x:e.clientX,y:e.clientY},p===null&&(p=n.requestAnimationFrame(()=>{if(p=null,!g)return;const{width:i,height:o,left:d,top:u}=t.getBoundingClientRect();!i||!o||(s("light-x",(g.x-d)/i*100+"%"),s("light-y",(g.y-u)/o*100+"%"))})))}function G(e){c!==e&&(c&&(q.unobserve(c),c.removeEventListener("load",a),A?.(),A=void 0),c=e,c?(q.observe(c),c.addEventListener("load",a),c.localName==="video"&&(A=_(c)),n.addEventListener("scroll",a,!0),n.addEventListener("resize",a)):(n.removeEventListener("scroll",a,!0),n.removeEventListener("resize",a)))}function _(e){const i=["loadeddata","seeked","resize"];for(const u of i)e.addEventListener(u,a);function o(){w.matches||a(),d=e.requestVideoFrameCallback(o)}let d=e.requestVideoFrameCallback?.(o);return()=>{d!==void 0&&e.cancelVideoFrameCallback(d);for(const u of i)e.removeEventListener(u,a)}}function W(){t.classList.add(R),s("radius",r.radius+"px"),s("blur",r.blur+"px"),s("saturation",r.saturation),s("tint",r.tint),s("glow",r.glow),s("edge",r.edgeHighlight),s("angle",r.lightAngle+"deg"),r.interactive||L(),G(r.refraction&&["auto","backdrop","sampled"].includes(r.mode)?r.backdrop:null),a()}const N={get renderer(){return m},update(e,{replace:i=!1}={}){h||(r=K(n,e,i?void 0:r),W())},refresh:a,destroy(){if(!h){h=!0,v!==null&&n.cancelAnimationFrame(v),p!==null&&n.cancelAnimationFrame(p),y(),l?.canvas.remove(),G(null),q.disconnect(),t.removeEventListener("pointermove",B),t.removeEventListener("pointerleave",L),S.removeEventListener("change",L),w.removeEventListener("change",a);for(const[e,[i,o]]of V)t.style.setProperty(e,i,o);U||t.classList.remove(R),H.delete(t),m="frost"}}};return H.set(t,N),t.addEventListener("pointermove",B,{passive:!0}),t.addEventListener("pointerleave",L),S.addEventListener("change",L),w.addEventListener("change",a),q.observe(t),W(),N}export{le as liquidGlass};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const nt=192,ot=1.5,h=new Map;function tt(t){if(h.has(t))return h.get(t);const n=new Float32Array(193),a=1.3+t*.55,l=Math.tan(Math.acos(1/1.5));n[0]=1;for(let r=1;r<192;r++){const c=1-r/192,I=c**(a-1)*(1-c**a)**(1/a-1),M=Math.atan(I),o=Math.tan(M-Math.asin(Math.sin(M)/1.5));n[r]=.72*o/l+.28*c*c*(3-2*c)}return h.size===32&&h.delete(h.keys().next().value),h.set(t,n),n}function st(t,n,{radius:a,bevel:l,curvature:r,lightAngle:c=145},I=1){const M=Math.min(I,512/Math.max(t,n)),o=Math.max(1,Math.round(t*M)),i=Math.max(1,Math.round(n*M)),N=new Uint8Array(o*i),P=new Uint8Array(o*i),H=new Float32Array(o*i*2),U=t/2,k=n/2,W=Math.min(a,U,k),J=Math.min(l,U,k),v=t/o,z=n/i,G=Math.max(v,z),X=tt(r),j=c*Math.PI/180,K=-Math.sin(j),L=Math.cos(j),O=Math.ceil(o/2),Q=Math.ceil(i/2);for(let s=0;s<Q;s++){const x=W-(s+.5)*z,f=i-s-1;for(let e=0;e<O;e++){let w=function(_,$,C,D){const A=_*o+$;N[A]=R,F&&(H[2*A]=C*F,H[2*A+1]=D*F);const E=-C*K-D*L;P[A]=Z*(.19+.81*Math.max(E,-E*.64))};const d=W-(e+.5)*v,g=Math.max(0,d),u=Math.max(0,x),m=g&&u?Math.hypot(g,u):g+u,Y=W-m-Math.min(Math.max(d,x),0);if(Y<=-G/2)continue;const R=Math.min(1,.5+Y/G)*255,p=o-e-1,S=p===e?0:m?g/m:+(d>x),b=f===s?0:m?u/m:+(x>d),q=Math.max(0,Y),B=Math.min(192,q*192/J),y=Math.floor(B),F=X[y]+(X[Math.min(192,y+1)]-X[y])*(B-y),T=Math.max(0,1-q/2.1),V=Math.max(0,1-q/10),Z=255*(.78*T**2+.22*V**2);w(s,e,S,b),p!==e&&w(s,p,-S,b),f!==s&&w(f,e,S,-b),f!==s&&p!==e&&w(f,p,-S,-b)}}return{columns:o,rows:i,offsets:H,coverage:N,highlights:P}}function et(t,n,a,l){return Math.min(t,Math.min(a,l)*.48/(1+n))}export{st as lensGeometry,et as lensStrength};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=Object.freeze({mode:"auto",backdrop:null,radius:24,blur:2,refraction:18,bevel:24,curvature:2,chroma:0,saturation:1.35,tint:.14,glow:.23,edgeHighlight:.85,lightAngle:145,interactive:!0}),u={radius:[0,1/0],blur:[0,1/0],refraction:[0,1/0],bevel:[.5,1/0],curvature:[.25,8],chroma:[0,1],saturation:[0,1/0],tint:[0,1],glow:[0,1],edgeHighlight:[0,1],lightAngle:[-1/0,1/0]};function f(o,i,c=a){const e={...c};for(const t of Object.keys(a))i[t]!==void 0&&(e[t]=i[t]);for(const[t,[s,l]]of Object.entries(u)){const r=e[t];if(!Number.isFinite(r)||r<s||r>l)throw new RangeError("Invalid liquidGlass option: "+t)}if(!["auto","content","backdrop","sampled","frost"].includes(e.mode))throw new TypeError('mode must be "auto", "content", "backdrop", "sampled", or "frost"');if(typeof e.interactive!="boolean")throw new TypeError("interactive must be a boolean");const n=e.backdrop;if(n!==null&&(!(n instanceof o.HTMLImageElement||n instanceof o.HTMLCanvasElement||n instanceof o.HTMLVideoElement)||n.ownerDocument!==o.document))throw new TypeError("backdrop must be an image, canvas, or video from the same document, or null");return e}export{f as resolveOptions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lensStrength as L}from"../optics.js";import{drawWebGl as V}from"./webgl.js";function z(s){const i=s.createElement("canvas");i.className="liquid-glass-backdrop",i.setAttribute("aria-hidden","true");const m=i.getContext("2d"),r=s.createElement("canvas"),a=r.getContext("2d");let p;function v(t,o,w){const{columns:e,rows:h,offsets:u,coverage:N,highlights:R}=o,{refraction:q,chroma:B,edgeHighlight:A}=w;if(!m||!a||!t.isConnected)return!1;const n=t.getBoundingClientRect(),l=i.getBoundingClientRect();if(!l.width||!l.height||!n.width||!n.height||n.right<=l.left||n.left>=l.right||n.bottom<=l.top||n.top>=l.bottom||t.localName==="img"&&(!t.complete||!t.naturalWidth)||t.localName==="canvas"&&(!t.width||!t.height)||t.localName==="video"&&(t.readyState<2||!t.videoWidth))return!1;(!p||i.width!==e||i.height!==h)&&(i.width=r.width=e,i.height=r.height=h,p=m.createImageData(e,h));const x=e/l.width,b=h/l.height,I=L(q,B,o.width,o.height),F=I*e/o.width,G=I*h/o.height;let k=n.left,D=n.top,M=n.width,C=n.height;if(t.localName!=="canvas"){const d=t.naturalWidth??t.videoWidth,f=t.naturalHeight??t.videoHeight,g=s.defaultView.getComputedStyle(t).objectFit;if(g==="cover"||g==="contain"){const W=(g==="cover"?Math.max:Math.min)(M/d,C/f),H=W*d,c=W*f;k+=(M-H)/2,D+=(C-c)/2,M=H,C=c}else if(g!=="fill")return!1}if(a.clearRect(0,0,e,h),a.save(),a.beginPath(),a.rect((n.left-l.left)*x,(n.top-l.top)*b,n.width*x,n.height*b),a.clip(),a.drawImage(t,(k-l.left)*x,(D-l.top)*b,M*x,C*b),a.restore(),V(s,r,o,I,w,m))return!0;let E;try{E=a.getImageData(0,0,e,h).data}catch(d){if(d.name!=="SecurityError")throw d;return r.width=e,!1}for(let d=0,f=0;d<h;d++)for(let g=0;g<e;g++,f++){const P=u[f*2]*F,W=u[f*2+1]*G,H=R[f]*A/255;for(let c=0;c<4;c++){const j=c===0?1-B:c===2?1+B:1,S=X(E,e,h,g+P*j,d+W*j,c);p.data[f*4+c]=c===3?S*N[f]/255:S+(255-S)*H}}return m.putImageData(p,0,0),!0}return{canvas:i,render:v}}function X(s,i,m,r,a,p){r=Math.max(0,Math.min(i-1,r)),a=Math.max(0,Math.min(m-1,a));const v=Math.floor(r),t=Math.floor(a),o=r-v,w=a-t,e=(t*i+v)*4+p,h=o?4:0,u=w?i*4:0,N=s[e]*(1-o)+s[e+h]*o,R=s[e+u]*(1-o)+s[e+u+h]*o;return N*(1-w)+R*w}export{z as makeBackdropLens};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lensStrength as X}from"../optics.js";const Y="http://www.w3.org/2000/svg",K=new WeakMap,S={x:0,y:0,width:1,height:1};let W=0;function $(n){const{userAgentData:r,userAgent:t}=n.navigator;return r?.brands.some(({brand:s})=>s==="Chromium")||/\b(?:Chrome|Chromium)\//.test(t)?"blink":/Firefox\//.test(t)?"gecko":/AppleWebKit\//.test(t)?"webkit":"unknown"}function C(n,r){for(const[t,s]of Object.entries(r)){const e=String(s);n.getAttribute(t)!==e&&n.setAttribute(t,e)}return n}function I(n,r,t){return C(n.createElementNS(Y,r),t)}function z(n,r,t,s){if(!s)return{unit:1,xScale:1,yScale:1};if(n==="webkit"){const e=Math.min(r,t);return{unit:e,xScale:e/r,yScale:e/t}}return{unit:n==="gecko"?Math.hypot(r,t)/Math.SQRT2:r,xScale:1,yScale:1}}function J(n,r,t,s){K.has(n)||K.set(n,{entries:new Map,canvas:n.createElement("canvas")});const{entries:e,canvas:i}=K.get(n),c=[r,t,s.key].join("/");let a=e.get(c);if(a)return e.delete(c),e.set(c,a),a;const{columns:g,rows:h,offsets:p,coverage:l,highlights:b,width:f,height:o}=s,{xScale:d,yScale:y}=z(r,f,o,t);i.width=g,i.height=h;const v=i.getContext("2d");if(a={url:null,ready:Promise.resolve(null)},v){const R=v.createImageData(g,h),x=R.data;for(let m=0;m<l.length;m++){const u=4*m;x[u]=127.5+127.5*p[2*m]*d,x[u+1]=127.5+127.5*p[2*m+1]*y,x[u+2]=b[m],x[u+3]=t?l[m]:255}v.putImageData(R,0,0);const M=i.toDataURL(),O=new n.defaultView.Image;O.src=M,a.ready=O.decode().then(()=>(a.url=M,M),()=>null)}return e.size>=32&&e.delete(e.keys().next().value),e.set(c,a),a}function Z(n,r,t){const s=I(n,"filter",{...S,id:"liquid-glass-"+ ++W,primitiveUnits:r?"objectBoundingBox":"userSpaceOnUse","color-interpolation-filters":"sRGB"});function e(f,o){const d=I(n,f,o);return s.append(d),d}r&&e("feFlood",{...S,"flood-color":"rgb(128,128,0)",result:"neutral"});const i=e("feImage",{...S,preserveAspectRatio:"none",result:r?"shape":"offsets"});r&&e("feComposite",{...S,in:"shape",in2:"neutral",operator:"over",result:"offsets"});const c=t.blur?"frosted":"SourceGraphic",a=t.blur?e("feGaussianBlur",{in:"SourceGraphic",result:c}):null;function g(f){return e("feDisplacementMap",{in:c,in2:"offsets",xChannelSelector:"R",yChannelSelector:"G",result:f})}const h=[];if(t.chroma){const f=["red","green","blue"];for(const[o,d]of f.entries()){h.push(g(d));const y=Array(20).fill(0);y[o*6]=1,y[19]=1,e("feColorMatrix",{in:d,values:y.join(" "),result:d+"Only"})}e("feBlend",{in:"redOnly",in2:"greenOnly",mode:"screen",result:"redGreen"}),e("feBlend",{in:"redGreen",in2:"blueOnly",mode:"screen",result:"rgb"}),e("feComposite",{in:"rgb",in2:"green",operator:"in",result:"warped"})}else h.push(g("warped"));let p="warped";const l=t.saturation?e("feColorMatrix",{in:p,type:"saturate",result:"saturated"}):null;l&&(p="saturated");const b=t.rim?e("feColorMatrix",{...S,in:"offsets",result:"rim"}):null;return b&&(e("feComposite",{...S,in:"rim",in2:p,operator:"atop",result:"lit"}),p="lit"),r&&(e("feComposite",{...S,in:p,in2:"shape",operator:"in",result:"interior"}),e("feComposite",{in:"SourceGraphic",in2:"shape",operator:"out",result:"exterior"}),e("feComposite",{in:"interior",in2:"exterior",operator:"arithmetic",k2:1,k3:1})),{graph:s,map:i,displacements:h,blur:a,saturation:l,rim:b}}function ee(n,r,t){const s=n.ownerDocument,e=s.defaultView,i=t==="content",c=I(s,"svg",{width:0,height:0,"aria-hidden":"true"});c.style.cssText="position:absolute;overflow:hidden;pointer-events:none";const a=n.getRootNode();(a===s?s.body:a).append(c);const g=I(s,"defs",{});c.append(g);let h,p=0,l,b=!1,f,o,d,y,v,R=!1;function x(u=!1){u&&(o.graph.id="liquid-glass-"+ ++W),f.apply('url("#'+o.graph.id+'")')}function M(){if(!l)return;const{geometry:u,options:q}=f,{width:w,height:k,key:B}=u,{refraction:D,chroma:T,blur:j,saturation:U,edgeHighlight:E}=q,L=[l,B,D,T,i?j:0,i?U:1,i?E:0];if(y?.every((G,A)=>G===L[A])){x();return}y=L;const F={chroma:!!T,blur:i&&!!j,saturation:i&&U!==1,rim:i&&!!E},N=Object.values(F).join("/");d!==N&&(d=N,o=Z(s,i,F),g.replaceChildren(o.graph));const{unit:H}=z(r,w,k,i),P=2*X(D,T,w,k)/H;if(i){const G=18/w,A=18/k;C(o.graph,{x:-G,y:-A,width:1+2*G,height:1+2*A})}const Q=o.map.getAttribute("href")!==l;C(o.map,{href:l,width:i?1:w,height:i?1:k});for(const[G,A]of o.displacements.entries())C(A,{scale:P*(F.chroma?1+(G-1)*T:1)});o.blur&&C(o.blur,{stdDeviation:j/w+" "+j/k}),o.saturation&&C(o.saturation,{values:U}),o.rim&&C(o.rim,{values:"0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 "+E+" 0 0"});const V=i&&r==="webkit";x(V),V&&Q&&(e.clearTimeout(v),v=e.setTimeout(()=>x(!0),94))}function O(u,q,w){if(f={geometry:u,options:q,apply:w},h!==u.key){h=u.key,b=!1;const k=++p,B=J(s,r,i,u);B.url?l=B.url:B.ready.then(D=>{R||k!==p||(D?(l=D,M()):l||(b=!0,f.apply("")))})}b?w(""):M()}function m(){R=!0,e.clearTimeout(v),c.remove()}return{render:O,dispose:m}}export{$ as browserEngine,ee as makeSvgLens};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const u=new WeakMap,D=`
|
|
2
|
+
attribute vec2 position;
|
|
3
|
+
varying vec2 uv;
|
|
4
|
+
void main() {
|
|
5
|
+
gl_Position = vec4(position, 0.0, 1.0);
|
|
6
|
+
uv = vec2(position.x + 1.0, 1.0 - position.y) * 0.5;
|
|
7
|
+
}
|
|
8
|
+
`,b=`
|
|
9
|
+
precision mediump float;
|
|
10
|
+
varying vec2 uv;
|
|
11
|
+
uniform sampler2D plate;
|
|
12
|
+
uniform sampler2D lens;
|
|
13
|
+
uniform vec2 strength;
|
|
14
|
+
uniform float chroma;
|
|
15
|
+
uniform float rim;
|
|
16
|
+
|
|
17
|
+
void main() {
|
|
18
|
+
vec4 map = texture2D(lens, uv);
|
|
19
|
+
vec2 offset = (map.rg * 255.0 - 128.0) / 127.0 * strength;
|
|
20
|
+
vec4 color = texture2D(plate, uv + offset);
|
|
21
|
+
if (chroma > 0.0) {
|
|
22
|
+
color.r = texture2D(plate, uv + offset * (1.0 - chroma)).r;
|
|
23
|
+
color.b = texture2D(plate, uv + offset * (1.0 + chroma)).b;
|
|
24
|
+
}
|
|
25
|
+
color.rgb = mix(color.rgb, vec3(1.0), map.b * rim);
|
|
26
|
+
gl_FragColor = vec4(color.rgb, color.a * map.a);
|
|
27
|
+
}
|
|
28
|
+
`;function v(e){const t=e.createProgram();for(const[a,n]of[[e.VERTEX_SHADER,D],[e.FRAGMENT_SHADER,b]]){const s=e.createShader(a);e.shaderSource(s,n),e.compileShader(s),e.attachShader(t,s),e.deleteShader(s)}if(e.linkProgram(t),!e.getProgramParameter(t,e.LINK_STATUS))return e.deleteProgram(t),null;e.useProgram(t);const r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),e.STATIC_DRAW);const o=e.getAttribLocation(t,"position");e.enableVertexAttribArray(o),e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0);for(const[a,n]of["plate","lens"].entries())e.activeTexture(e.TEXTURE0+a),e.bindTexture(e.TEXTURE_2D,e.createTexture()),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(e.getUniformLocation(t,n),a);return e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),{strength:e.getUniformLocation(t,"strength"),chroma:e.getUniformLocation(t,"chroma"),rim:e.getUniformLocation(t,"rim")}}function L(e){const t=e.createElement("canvas"),r=t.getContext("webgl",{antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!1});if(!r)return null;let o=v(r),a;return t.addEventListener("webglcontextlost",n=>{n.preventDefault(),o=null}),t.addEventListener("webglcontextrestored",()=>{o=v(r),a=void 0}),function(s,m,T,{chroma:A,edgeHighlight:d},R){if(!o||r.isContextLost())return!1;const{width:_,height:x,columns:f,rows:E,offsets:h,coverage:p,highlights:U}=m;(t.width!==f||t.height!==E)&&(t.width=f,t.height=E),r.viewport(0,0,f,E),r.activeTexture(r.TEXTURE0);try{r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,s)}catch(c){if(c.name!=="SecurityError")throw c;return!1}if(a!==m){const c=new Uint8ClampedArray(f*E*4);for(let i=0;i<p.length;i++)c[4*i]=128+127*h[2*i],c[4*i+1]=128+127*h[2*i+1],c[4*i+2]=U[i],c[4*i+3]=p[i];r.activeTexture(r.TEXTURE1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,f,E,0,r.RGBA,r.UNSIGNED_BYTE,c),a=m}return r.uniform2f(o.strength,T/_,T/x),r.uniform1f(o.chroma,A),r.uniform1f(o.rim,d),r.drawArrays(r.TRIANGLES,0,3),R.clearRect(0,0,f,E),R.drawImage(t,0,0),!0}}function P(e,t,r,o,a,n){return u.has(e)||u.set(e,L(e)),u.get(e)?.(t,r,o,a,n)??!1}export{P as drawWebGl};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type RefCallback } from "react";
|
|
2
|
+
import { type LiquidGlassOptions } from "@ikeofficial/liquid-glass-js";
|
|
3
|
+
/** Attach the material to an ordinary DOM element using a callback ref. */
|
|
4
|
+
export declare function useLiquidGlass<T extends HTMLElement = HTMLElement>(options?: LiquidGlassOptions): RefCallback<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{useEffect as n,useRef as s,useState as c}from"react";import{liquidGlass as o}from"@ikeofficial/liquid-glass-js";function a(r){const[e,l]=c(null),t=s(null);return n(()=>{if(!e)return;const u=o(e);return t.current=u,()=>{u.destroy(),t.current=null}},[e]),n(()=>{t.current?.update(r??{},{replace:!0})},[e,r]),l}export{a as useLiquidGlass};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{liquidGlass as r}from"@ikeofficial/liquid-glass-js";const t=new WeakMap,d={mounted(e,{value:o}){t.set(e,r(e,o))},updated(e,{value:o}){t.get(e)?.update(o??{},{replace:!0})},beforeUnmount(e){t.get(e)?.destroy(),t.delete(e)}};export{d as vLiquidGlass};
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikeofficial/liquid-glass-js",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Refractive, interactive glass surfaces for the web",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./build/core/liquid-glass.d.ts",
|
|
9
|
+
"default": "./build/core/liquid-glass.js"
|
|
10
|
+
},
|
|
11
|
+
"./style.css": "./build/core/liquid-glass.css",
|
|
12
|
+
"./angular": {
|
|
13
|
+
"types": "./build/angular/index.d.ts",
|
|
14
|
+
"default": "./build/angular/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"types": "./build/react/index.d.ts",
|
|
18
|
+
"default": "./build/react/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./vue": {
|
|
21
|
+
"types": "./build/vue/index.d.ts",
|
|
22
|
+
"default": "./build/vue/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "./build/core/liquid-glass.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"skills/liquid-glass-js",
|
|
28
|
+
"build"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": [
|
|
31
|
+
"**/*.css"
|
|
32
|
+
],
|
|
33
|
+
"keywords": [
|
|
34
|
+
"liquid-glass",
|
|
35
|
+
"backdrop-filter",
|
|
36
|
+
"refraction",
|
|
37
|
+
"vanilla-js"
|
|
38
|
+
],
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@angular/core": ">=20 <23",
|
|
41
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
42
|
+
"vue": "^3.3.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@angular/core": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"react": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"vue": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@angular/compiler": "20.3.35",
|
|
57
|
+
"@angular/compiler-cli": "20.3.35",
|
|
58
|
+
"@angular/core": "20.3.35",
|
|
59
|
+
"@angular/platform-browser": "20.3.35",
|
|
60
|
+
"@types/react": "19.3.0",
|
|
61
|
+
"esbuild": "^0.28.2",
|
|
62
|
+
"jsdom": "29.1.1",
|
|
63
|
+
"react": "19.3.1",
|
|
64
|
+
"react-dom": "19.3.1",
|
|
65
|
+
"rxjs": "7.8.2",
|
|
66
|
+
"tailwindcss": "4.3.3",
|
|
67
|
+
"typescript": "5.9.3",
|
|
68
|
+
"vue": "3.5.45"
|
|
69
|
+
},
|
|
70
|
+
"repository": {
|
|
71
|
+
"type": "git",
|
|
72
|
+
"url": "https://github.com/bigimattia/liquidglass-js.git"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"registry": "https://registry.npmjs.org",
|
|
76
|
+
"access": "public"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"prepack": "mise run build"
|
|
80
|
+
},
|
|
81
|
+
"license": "MIT"
|
|
82
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: liquid-glass-js
|
|
3
|
+
description: Install and integrate the Liquid Glass JS library with plain JavaScript, Angular, React, or Vue. Use when a user requests this library or wants to tune its element, image, or live-page refraction.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
- Install the supplied `ikeofficial-liquid-glass-js-*.tgz` using the target project’s package manager. From a library checkout, run `mise run install` and `mise run pack` to build the archive in `dist/`. If neither source nor archive is available, ask for its location.
|
|
9
|
+
- Always load `@ikeofficial/liquid-glass-js/style.css`. In Angular, add it to the app’s global styles. For plain HTML without a bundler, copy the library’s `src/` folder to public assets, link `liquid-glass.css`, and import the ES module `liquid-glass.js`.
|
|
10
|
+
|
|
11
|
+
## Attach to an existing element
|
|
12
|
+
|
|
13
|
+
- JavaScript uses `const glass = liquidGlass(element, options)` from `@ikeofficial/liquid-glass-js`. Call `glass.update(changes)` when tuning and `glass.destroy()` when unmounting.
|
|
14
|
+
- Angular imports the standalone `LiquidGlassDirective` from `@ikeofficial/liquid-glass-js/angular` and uses `[liquidGlass]="options"`.
|
|
15
|
+
- React imports `useLiquidGlass` from `@ikeofficial/liquid-glass-js/react` and passes its return value to the element’s `ref`.
|
|
16
|
+
- Vue imports `vLiquidGlass` from `@ikeofficial/liquid-glass-js/vue` and uses `v-liquid-glass="options"` on the element.
|
|
17
|
+
|
|
18
|
+
Use an ordinary HTML host with geometry supplied by the app’s CSS and available `::before` and `::after` pseudo-elements. The adapters clean themselves up and treat a new options object as the complete configuration.
|
|
19
|
+
|
|
20
|
+
## Choose the surface to refract
|
|
21
|
+
|
|
22
|
+
- `{ mode: "content" }` bends the host’s own rendered pixels across browsers. Put the artwork inside the element or paint it via its CSS background. Use a decorative layer when text must stay optically sharp.
|
|
23
|
+
- `{ mode: "sampled", backdrop: media }` samples a same-origin or CORS-enabled image, canvas, or video behind the lens. Use an axis-aligned, borderless source and `object-fit: fill` or centered `cover` or `contain`. Call `glass.refresh()` after changing position or redrawing a canvas.
|
|
24
|
+
- Automatic mode (the default) refracts live page pixels in Chromium and falls back to the supplied backdrop or CSS frost. Use `{ mode: "backdrop" }` without a source to select live page refraction explicitly. `{ mode: "frost" }` uses CSS directly. Use sampled or frost mode if CSP prevents the generated SVG-map image.
|
|
25
|
+
- Use the target project’s own markup and geometry. Check focus, contrast, and the effect over detailed artwork. Run `mise run dev` in the library checkout for the playground and framework examples.
|