@tahoangphuc111/liquid-glass 0.2.1 → 0.3.0

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.
Files changed (41) hide show
  1. package/README.md +150 -54
  2. package/dist/chunk-FB6QOH33.js +7532 -0
  3. package/dist/chunk-FB6QOH33.js.map +1 -0
  4. package/dist/chunk-KKMJIY4M.cjs +360 -0
  5. package/dist/chunk-KKMJIY4M.cjs.map +1 -0
  6. package/dist/chunk-RMWCG5MB.js +354 -0
  7. package/dist/chunk-RMWCG5MB.js.map +1 -0
  8. package/dist/chunk-ZECDS4SL.cjs +7578 -0
  9. package/dist/chunk-ZECDS4SL.cjs.map +1 -0
  10. package/dist/index.cjs +281 -146
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +68 -7
  13. package/dist/index.d.ts +68 -7
  14. package/dist/index.js +223 -100
  15. package/dist/index.js.map +1 -1
  16. package/dist/next/index.cjs +206 -0
  17. package/dist/next/index.cjs.map +1 -0
  18. package/dist/next/index.d.cts +26 -0
  19. package/dist/next/index.d.ts +26 -0
  20. package/dist/next/index.js +184 -0
  21. package/dist/next/index.js.map +1 -0
  22. package/dist/react/index.cjs +115 -206
  23. package/dist/react/index.cjs.map +1 -1
  24. package/dist/react/index.d.cts +32 -3
  25. package/dist/react/index.d.ts +32 -3
  26. package/dist/react/index.js +98 -205
  27. package/dist/react/index.js.map +1 -1
  28. package/dist/styles.css +233 -50
  29. package/dist/{types-BYB6mjtX.d.cts → types-BqXPylfU.d.cts} +18 -1
  30. package/dist/{types-BYB6mjtX.d.ts → types-BqXPylfU.d.ts} +18 -1
  31. package/dist/vue/index.cjs +312 -7
  32. package/dist/vue/index.cjs.map +1 -1
  33. package/dist/vue/index.d.cts +314 -2
  34. package/dist/vue/index.d.ts +314 -2
  35. package/dist/vue/index.js +305 -2
  36. package/dist/vue/index.js.map +1 -1
  37. package/package.json +10 -1
  38. package/dist/chunk-6SFCPAUI.js +0 -3922
  39. package/dist/chunk-6SFCPAUI.js.map +0 -1
  40. package/dist/chunk-CSMPIDZE.cjs +0 -3964
  41. 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
- surface: "convex_squircle",
32
- thickness: 40,
33
- bezel: 24,
34
- ior: 1.45,
35
- blur: 2,
36
- interactive: true
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: 50 });
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 the `useLiquidGlass` hook:
70
+ Wrap components with `<LiquidGlass>` or use `<LiquidGlassSwitch>`, `useLiquidGlass`, and `useGlassSwitch`:
49
71
 
50
72
  ```tsx
51
- import { LiquidGlass } from "@tahoangphuc111/liquid-glass/react";
52
-
53
- export function GlassCard() {
54
- return (
55
- <LiquidGlass
56
- surface="convex_squircle"
57
- thickness={40}
58
- bezel={24}
59
- ior={1.45}
60
- interactive
61
- className="p-6 rounded-2xl"
62
- >
63
- <h2>Refracted Card</h2>
64
- <p>Content rendered inside liquid glass container.</p>
65
- </LiquidGlass>
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 hook directly:
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
- const ref = useRef<HTMLDivElement>(null);
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
- useLiquidGlass(ref, {
80
- surface: "convex_circle",
81
- pill: true,
82
- interactive: true
83
- });
132
+ Inside a Client Component (with `next/link` and `usePathname()`):
84
133
 
85
- return <div ref={ref} className="p-4">Pill button</div>;
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 components directly:
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 { LiquidGlass } from "@tahoangphuc111/liquid-glass/vue";
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
- <LiquidGlass
100
- surface="convex_squircle"
101
- :thickness="40"
102
- :bezel="24"
103
- :interactive="true"
104
- class="glass-panel"
105
- >
106
- <span>Vue Liquid Glass Panel</span>
107
- </LiquidGlass>
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
- surface: "convex_squircle",
122
- thickness: 35
212
+ surface: "convex_squircle",
213
+ thickness: 35,
123
214
  });
124
215
  </script>
125
216
 
126
217
  <template>
127
- <div ref="panelRef" class="glass-box">Content</div>
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` | `40` | Virtual lens thickness in pixels. |
144
- | `bezel` | `number` | `24` | Width of the refraction boundary edge in pixels. |
145
- | `ior` | `number` | `1.45` | Index of refraction. 1.0 is air, 1.33 is water, 1.5 is glass. |
146
- | `blur` | `number` | `0` | Gaussian blur radius applied behind the displacement filter. |
147
- | `radius` | `number` | `24` | Corner radius override in pixels. Defaults to element border radius. |
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