@tahoangphuc111/liquid-glass 0.2.1 → 0.3.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/README.md +150 -54
- package/dist/chunk-2D22LMVV.cjs +7810 -0
- package/dist/chunk-2D22LMVV.cjs.map +1 -0
- package/dist/chunk-EOYQFWEA.js +360 -0
- package/dist/chunk-EOYQFWEA.js.map +1 -0
- package/dist/chunk-Y5GIJQVW.js +7764 -0
- package/dist/chunk-Y5GIJQVW.js.map +1 -0
- package/dist/chunk-YEATG3CF.cjs +366 -0
- package/dist/chunk-YEATG3CF.cjs.map +1 -0
- package/dist/index.cjs +356 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -7
- package/dist/index.d.ts +70 -7
- package/dist/index.js +298 -112
- package/dist/index.js.map +1 -1
- package/dist/next/index.cjs +248 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +26 -0
- package/dist/next/index.d.ts +26 -0
- package/dist/next/index.js +226 -0
- package/dist/next/index.js.map +1 -0
- package/dist/react/index.cjs +119 -206
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +32 -3
- package/dist/react/index.d.ts +32 -3
- package/dist/react/index.js +102 -205
- package/dist/react/index.js.map +1 -1
- package/dist/styles.css +233 -50
- package/dist/{types-BYB6mjtX.d.cts → types-KM3HML4O.d.cts} +19 -1
- package/dist/{types-BYB6mjtX.d.ts → types-KM3HML4O.d.ts} +19 -1
- package/dist/vue/index.cjs +323 -8
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +314 -2
- package/dist/vue/index.d.ts +314 -2
- package/dist/vue/index.js +316 -3
- package/dist/vue/index.js.map +1 -1
- package/package.json +10 -1
- package/dist/chunk-6SFCPAUI.js +0 -3922
- package/dist/chunk-6SFCPAUI.js.map +0 -1
- package/dist/chunk-CSMPIDZE.cjs +0 -3964
- package/dist/chunk-CSMPIDZE.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# liquid-glass
|
|
2
2
|
|
|
3
|
-
Optical refraction and glass displacement for Vanilla JS, React, and Vue 3.
|
|
3
|
+
Optical refraction and glass displacement for Vanilla JS, React, Next.js, and Vue 3.
|
|
4
4
|
|
|
5
5
|
Uses WebAssembly (WASM SIMD) displacement maps on Chromium desktop, and falls back to WebGL scene capture or CSS backdrop filters on mobile and Safari.
|
|
6
6
|
|
|
@@ -23,88 +23,179 @@ import "@tahoangphuc111/liquid-glass/styles.css";
|
|
|
23
23
|
### Vanilla JavaScript
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
import { createLiquidGlass } from "@tahoangphuc111/liquid-glass";
|
|
26
|
+
import { createLiquidGlass, glassEffect } from "@tahoangphuc111/liquid-glass";
|
|
27
27
|
|
|
28
28
|
const element = document.querySelector<HTMLElement>(".glass-card")!;
|
|
29
29
|
|
|
30
30
|
const glass = createLiquidGlass(element, {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
surface: "convex_squircle",
|
|
32
|
+
thickness: 48,
|
|
33
|
+
bezel: 14,
|
|
34
|
+
ior: 2.15,
|
|
35
|
+
blur: 2,
|
|
36
|
+
interactive: true,
|
|
37
|
+
draggable: "elastic",
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
// Quick helper on elements, selectors, range sliders, or switch bars
|
|
41
|
+
glassEffect(".glass-button", { pill: true, draggable: true });
|
|
42
|
+
|
|
39
43
|
// Update options at runtime
|
|
40
|
-
glass.update({ thickness:
|
|
44
|
+
glass.update({ thickness: 56 });
|
|
41
45
|
|
|
42
46
|
// Clean up when removing the element
|
|
43
47
|
glass.destroy();
|
|
44
48
|
```
|
|
45
49
|
|
|
50
|
+
#### Bottom Navigation Switch (`createGlassSwitch`)
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { createGlassSwitch } from "@tahoangphuc111/liquid-glass";
|
|
54
|
+
|
|
55
|
+
const nav = document.querySelector<HTMLElement>("#bottom-nav")!;
|
|
56
|
+
|
|
57
|
+
const navSwitch = createGlassSwitch(nav, {
|
|
58
|
+
defaultValue: "home",
|
|
59
|
+
onChange(value, index) {
|
|
60
|
+
console.log("Selected tab:", value, index);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Or activate directly via glassEffect on .lg-switch / [role="tablist"]
|
|
65
|
+
nav.glassEffect({ defaultValue: "home" });
|
|
66
|
+
```
|
|
67
|
+
|
|
46
68
|
### React
|
|
47
69
|
|
|
48
|
-
Wrap components with `<LiquidGlass>` or use
|
|
70
|
+
Wrap components with `<LiquidGlass>` or use `<LiquidGlassSwitch>`, `useLiquidGlass`, and `useGlassSwitch`:
|
|
49
71
|
|
|
50
72
|
```tsx
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
import { useState } from "react";
|
|
74
|
+
import { LiquidGlass, LiquidGlassSwitch } from "@tahoangphuc111/liquid-glass/react";
|
|
75
|
+
|
|
76
|
+
export function AppShell() {
|
|
77
|
+
const [tab, setTab] = useState("home");
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<>
|
|
81
|
+
<LiquidGlass
|
|
82
|
+
surface="convex_squircle"
|
|
83
|
+
interactive
|
|
84
|
+
draggable="elastic"
|
|
85
|
+
className="p-6 rounded-2xl"
|
|
86
|
+
>
|
|
87
|
+
<h2>Refracted Card</h2>
|
|
88
|
+
<p>Content rendered inside liquid glass container.</p>
|
|
89
|
+
</LiquidGlass>
|
|
90
|
+
|
|
91
|
+
<LiquidGlassSwitch
|
|
92
|
+
value={tab}
|
|
93
|
+
onChange={(nextTab) => setTab(nextTab)}
|
|
94
|
+
items={[
|
|
95
|
+
{ value: "home", label: "Home" },
|
|
96
|
+
{ value: "search", label: "Search" },
|
|
97
|
+
{ value: "library", label: "Library" },
|
|
98
|
+
]}
|
|
99
|
+
/>
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
67
102
|
}
|
|
68
103
|
```
|
|
69
104
|
|
|
70
|
-
Or using the
|
|
105
|
+
Or using the hooks directly (`useLiquidGlass` / `useGlassSwitch`):
|
|
71
106
|
|
|
72
107
|
```tsx
|
|
73
108
|
import { useRef } from "react";
|
|
74
109
|
import { useLiquidGlass } from "@tahoangphuc111/liquid-glass/react";
|
|
75
110
|
|
|
76
111
|
export function CustomCard() {
|
|
77
|
-
|
|
112
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
113
|
+
|
|
114
|
+
useLiquidGlass(ref, {
|
|
115
|
+
surface: "convex_circle",
|
|
116
|
+
pill: true,
|
|
117
|
+
interactive: true,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return <div ref={ref} className="p-4">Pill button</div>;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Next.js (App Router & Pages Router)
|
|
125
|
+
|
|
126
|
+
Import from `@tahoangphuc111/liquid-glass/next` (pre-marked with `"use client";` for Next.js App Router) and import base styles in `app/layout.tsx`:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import "@tahoangphuc111/liquid-glass/styles.css";
|
|
130
|
+
```
|
|
78
131
|
|
|
79
|
-
|
|
80
|
-
surface: "convex_circle",
|
|
81
|
-
pill: true,
|
|
82
|
-
interactive: true
|
|
83
|
-
});
|
|
132
|
+
Inside a Client Component (with `next/link` and `usePathname()`):
|
|
84
133
|
|
|
85
|
-
|
|
134
|
+
```tsx
|
|
135
|
+
"use client";
|
|
136
|
+
|
|
137
|
+
import Link from "next/link";
|
|
138
|
+
import { usePathname, useRouter } from "next/navigation";
|
|
139
|
+
import {
|
|
140
|
+
LiquidGlassProvider,
|
|
141
|
+
LiquidGlassSwitch,
|
|
142
|
+
} from "@tahoangphuc111/liquid-glass/next";
|
|
143
|
+
|
|
144
|
+
export function BottomNavShell({ children }: { children: React.ReactNode }) {
|
|
145
|
+
const pathname = usePathname();
|
|
146
|
+
const router = useRouter();
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<LiquidGlassProvider>
|
|
150
|
+
{children}
|
|
151
|
+
<LiquidGlassSwitch
|
|
152
|
+
pathname={pathname}
|
|
153
|
+
linkComponent={Link}
|
|
154
|
+
onChange={(_, __, itemElement) => {
|
|
155
|
+
const href = itemElement.getAttribute("href");
|
|
156
|
+
if (href) router.push(href);
|
|
157
|
+
}}
|
|
158
|
+
items={[
|
|
159
|
+
{ value: "home", href: "/", label: "Home", exact: true },
|
|
160
|
+
{ value: "search", href: "/search", label: "Search" },
|
|
161
|
+
{ value: "library", href: "/library", label: "Library" },
|
|
162
|
+
]}
|
|
163
|
+
/>
|
|
164
|
+
</LiquidGlassProvider>
|
|
165
|
+
);
|
|
86
166
|
}
|
|
87
167
|
```
|
|
88
168
|
|
|
89
169
|
### Vue 3
|
|
90
170
|
|
|
91
|
-
Register as a global plugin or import
|
|
171
|
+
Register as a global plugin (`LiquidGlass`, `LiquidGlassSwitch`, `LiquidGlassProvider`) or import directly:
|
|
92
172
|
|
|
93
173
|
```vue
|
|
94
174
|
<script setup lang="ts">
|
|
95
|
-
import {
|
|
175
|
+
import { ref } from "vue";
|
|
176
|
+
import { LiquidGlass, LiquidGlassSwitch } from "@tahoangphuc111/liquid-glass/vue";
|
|
177
|
+
|
|
178
|
+
const activeTab = ref("home");
|
|
96
179
|
</script>
|
|
97
180
|
|
|
98
181
|
<template>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
182
|
+
<LiquidGlass
|
|
183
|
+
surface="convex_squircle"
|
|
184
|
+
:interactive="true"
|
|
185
|
+
draggable="elastic"
|
|
186
|
+
class="glass-panel"
|
|
187
|
+
>
|
|
188
|
+
<span>Vue Liquid Glass Panel</span>
|
|
189
|
+
</LiquidGlass>
|
|
190
|
+
|
|
191
|
+
<LiquidGlassSwitch
|
|
192
|
+
v-model="activeTab"
|
|
193
|
+
:items="[
|
|
194
|
+
{ value: 'home', label: 'Home' },
|
|
195
|
+
{ value: 'search', label: 'Search' },
|
|
196
|
+
{ value: 'library', label: 'Library' },
|
|
197
|
+
]"
|
|
198
|
+
/>
|
|
108
199
|
</template>
|
|
109
200
|
```
|
|
110
201
|
|
|
@@ -118,13 +209,13 @@ import { useLiquidGlass } from "@tahoangphuc111/liquid-glass/vue";
|
|
|
118
209
|
const panelRef = ref<HTMLElement | null>(null);
|
|
119
210
|
|
|
120
211
|
useLiquidGlass(panelRef, {
|
|
121
|
-
|
|
122
|
-
|
|
212
|
+
surface: "convex_squircle",
|
|
213
|
+
thickness: 35,
|
|
123
214
|
});
|
|
124
215
|
</script>
|
|
125
216
|
|
|
126
217
|
<template>
|
|
127
|
-
|
|
218
|
+
<div ref="panelRef" class="glass-box">Content</div>
|
|
128
219
|
</template>
|
|
129
220
|
```
|
|
130
221
|
|
|
@@ -140,16 +231,21 @@ useLiquidGlass(panelRef, {
|
|
|
140
231
|
| :--- | :--- | :--- | :--- |
|
|
141
232
|
| `surface` | `"convex_squircle" \| "convex_circle" \| "linear" \| "lip"` | `"convex_squircle"` | Geometric refraction profile. |
|
|
142
233
|
| `engine` | `"auto" \| "wasm-svg" \| "webgl" \| "css"` | `"auto"` | Execution engine. `auto` picks the best supported engine. |
|
|
143
|
-
| `thickness` | `number` | `
|
|
144
|
-
| `bezel` | `number` | `
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
234
|
+
| `thickness` | `number` | `48` | Virtual lens thickness in pixels. |
|
|
235
|
+
| `bezel` | `number` | `14` | Width of the refraction boundary edge in pixels. |
|
|
236
|
+
| `scaleRatio` | `number` | `2.35` | Refraction displacement scale factor. |
|
|
237
|
+
| `ior` | `number` | `2.15` | Index of refraction. 1.0 is air, 1.33 is water, 1.5+ is glass. |
|
|
238
|
+
| `blur` | `number` | `2` | Gaussian blur radius applied behind the displacement filter. |
|
|
239
|
+
| `radius` | `number` | `18` | Corner radius override in pixels. Defaults to element border radius. |
|
|
148
240
|
| `pill` | `boolean` | `false` | Locks corners to full pill or circular shape. |
|
|
149
241
|
| `hollow` | `boolean` | `false` | Keeps inner area flat and limits refraction only to bezel edges. |
|
|
150
242
|
| `interactive` | `boolean` | `false` | Enables spring physics on cursor hover and click. |
|
|
243
|
+
| `draggable` | `boolean \| "elastic"` | `false` | Enables micro-drag or droplet elastic drag motion on interactive elements. |
|
|
244
|
+
| `coalesce` | `boolean` | `true` | Enables nearby liquid glass coalescence in WebGL mode. |
|
|
245
|
+
| `chromaticAberration` | `boolean \| number` | `false` | Enables RGB dispersion on WebGL and WASM SVG displacement engines. |
|
|
246
|
+
| `highlight` | `number` | `0.44` | Specular rim highlight intensity. |
|
|
151
247
|
| `tintColor` | `string` | `undefined` | Overlay tint color in hex or rgb format. |
|
|
152
|
-
| `tintOpacity` | `number` | `0` | Opacity of the tint layer (0 to 1). |
|
|
248
|
+
| `tintOpacity` | `number` | `0.12` (WebGL) | Opacity of the tint layer (0 to 1). |
|
|
153
249
|
| `sceneElement` | `HTMLElement` | `null` | Target DOM element to sample for WebGL refraction mode. |
|
|
154
250
|
| `onEngineChange` | `(engine: GlassEngine) => void` | `undefined` | Callback fired when engine resolves or falls back. |
|
|
155
251
|
|