@glass-sdk/liquid-glass 0.0.0-stage → 0.0.2

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 (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -2
  3. package/dist/core/concentric.js +86 -0
  4. package/dist/core/materials.js +41 -0
  5. package/dist/core/morph-path.js +206 -0
  6. package/dist/core/optics.js +7 -0
  7. package/dist/core/progressive.js +35 -0
  8. package/dist/core/shape.js +95 -0
  9. package/dist/core/spring.js +78 -0
  10. package/dist/core/union.js +117 -0
  11. package/dist/core.js +6 -0
  12. package/dist/dom/compose-layers.js +54 -0
  13. package/dist/dom/compound-field.js +23 -0
  14. package/dist/dom/control-motion.js +101 -0
  15. package/dist/dom/engine.js +7 -0
  16. package/dist/dom/exit-handoff.js +14 -0
  17. package/dist/dom/filter-bounds.js +87 -0
  18. package/dist/dom/filter-budget.js +45 -0
  19. package/dist/dom/filter-groups.js +38 -0
  20. package/dist/dom/filter-paint-root.js +41 -0
  21. package/dist/dom/filter-patch.js +129 -0
  22. package/dist/dom/filter-reach.js +36 -0
  23. package/dist/dom/filter-stages.js +7 -0
  24. package/dist/dom/fixed-shape.js +20 -0
  25. package/dist/dom/foreground.js +36 -0
  26. package/dist/dom/interaction.js +129 -0
  27. package/dist/dom/lens-layers.js +163 -0
  28. package/dist/dom/map-blend.js +8 -0
  29. package/dist/dom/map-encoder.js +47 -0
  30. package/dist/dom/map-encoder.worker.js +16 -0
  31. package/dist/dom/map-encoding.js +17 -0
  32. package/dist/dom/map-image.js +34 -0
  33. package/dist/dom/map-store.js +189 -0
  34. package/dist/dom/maps.js +131 -0
  35. package/dist/dom/material-graph.js +52 -0
  36. package/dist/dom/morph.js +296 -0
  37. package/dist/dom/page-zoom.js +46 -0
  38. package/dist/dom/png.js +105 -0
  39. package/dist/dom/progressive.js +299 -0
  40. package/dist/dom/renderer.js +6 -0
  41. package/dist/dom/sampling-bounds.js +22 -0
  42. package/dist/dom/selection.js +106 -0
  43. package/dist/dom/shape-layout.js +199 -0
  44. package/dist/dom/shared-backdrop.js +41 -0
  45. package/dist/dom/ticker.js +103 -0
  46. package/dist/dom/warm.js +108 -0
  47. package/dist/dom.js +694 -0
  48. package/dist/gpu/geometry.js +9 -0
  49. package/dist/gpu/maps.js +8 -0
  50. package/dist/gpu/planes.js +4 -0
  51. package/dist/gpu.js +213 -0
  52. package/dist/index.js +11 -0
  53. package/dist/react/button.js +23 -0
  54. package/dist/react/control-thumb.js +50 -0
  55. package/dist/react/menu.js +159 -0
  56. package/dist/react/merged-ref.js +18 -0
  57. package/dist/react/progressive.js +73 -0
  58. package/dist/react/scene.js +122 -0
  59. package/dist/react/shape.js +93 -0
  60. package/dist/react/surface.js +69 -0
  61. package/dist/react/tabs.js +94 -0
  62. package/dist/react/toolbar.js +145 -0
  63. package/dist/react/value-control-motion.js +9 -0
  64. package/dist/react/value-controls.js +176 -0
  65. package/dist/styles.css +360 -0
  66. package/dist/styles.d.css.ts +2 -0
  67. package/dist/types/core/concentric.d.ts +32 -0
  68. package/dist/types/core/index.d.ts +10 -0
  69. package/dist/types/core/materials.d.ts +43 -0
  70. package/dist/types/core/morph-path.d.ts +110 -0
  71. package/dist/types/core/optics.d.ts +1 -0
  72. package/dist/types/core/progressive.d.ts +17 -0
  73. package/dist/types/core/shape.d.ts +16 -0
  74. package/dist/types/core/spring.d.ts +60 -0
  75. package/dist/types/core/union.d.ts +20 -0
  76. package/dist/types/dom/compose-layers.d.ts +15 -0
  77. package/dist/types/dom/compound-field.d.ts +35 -0
  78. package/dist/types/dom/control-motion.d.ts +13 -0
  79. package/dist/types/dom/engine.d.ts +9 -0
  80. package/dist/types/dom/exit-handoff.d.ts +7 -0
  81. package/dist/types/dom/filter-bounds.d.ts +30 -0
  82. package/dist/types/dom/filter-budget.d.ts +20 -0
  83. package/dist/types/dom/filter-groups.d.ts +25 -0
  84. package/dist/types/dom/filter-paint-root.d.ts +9 -0
  85. package/dist/types/dom/filter-patch.d.ts +4 -0
  86. package/dist/types/dom/filter-reach.d.ts +23 -0
  87. package/dist/types/dom/filter-stages.d.ts +5 -0
  88. package/dist/types/dom/fixed-shape.d.ts +3 -0
  89. package/dist/types/dom/foreground.d.ts +20 -0
  90. package/dist/types/dom/index.d.ts +64 -0
  91. package/dist/types/dom/interaction.d.ts +16 -0
  92. package/dist/types/dom/lens-layers.d.ts +68 -0
  93. package/dist/types/dom/map-blend.d.ts +22 -0
  94. package/dist/types/dom/map-encoder.d.ts +5 -0
  95. package/dist/types/dom/map-encoder.worker.d.ts +1 -0
  96. package/dist/types/dom/map-encoding.d.ts +5 -0
  97. package/dist/types/dom/map-image.d.ts +17 -0
  98. package/dist/types/dom/map-store.d.ts +22 -0
  99. package/dist/types/dom/maps.d.ts +31 -0
  100. package/dist/types/dom/material-graph.d.ts +22 -0
  101. package/dist/types/dom/morph.d.ts +78 -0
  102. package/dist/types/dom/page-zoom.d.ts +18 -0
  103. package/dist/types/dom/png.d.ts +9 -0
  104. package/dist/types/dom/progressive.d.ts +42 -0
  105. package/dist/types/dom/renderer.d.ts +4 -0
  106. package/dist/types/dom/sampling-bounds.d.ts +10 -0
  107. package/dist/types/dom/selection.d.ts +5 -0
  108. package/dist/types/dom/shape-layout.d.ts +29 -0
  109. package/dist/types/dom/shared-backdrop.d.ts +19 -0
  110. package/dist/types/dom/ticker.d.ts +36 -0
  111. package/dist/types/dom/warm.d.ts +17 -0
  112. package/dist/types/gpu/geometry.d.ts +17 -0
  113. package/dist/types/gpu/index.d.ts +36 -0
  114. package/dist/types/gpu/planes.d.ts +2 -0
  115. package/dist/types/index.d.ts +4 -0
  116. package/dist/types/react/button.d.ts +11 -0
  117. package/dist/types/react/control-thumb.d.ts +11 -0
  118. package/dist/types/react/index.d.ts +20 -0
  119. package/dist/types/react/menu.d.ts +29 -0
  120. package/dist/types/react/merged-ref.d.ts +3 -0
  121. package/dist/types/react/progressive.d.ts +15 -0
  122. package/dist/types/react/scene.d.ts +35 -0
  123. package/dist/types/react/shape.d.ts +23 -0
  124. package/dist/types/react/surface.d.ts +35 -0
  125. package/dist/types/react/tabs.d.ts +29 -0
  126. package/dist/types/react/toolbar.d.ts +21 -0
  127. package/dist/types/react/value-control-motion.d.ts +9 -0
  128. package/dist/types/react/value-controls.d.ts +20 -0
  129. package/package.json +80 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Glass HQ
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,236 @@
1
- # Temporary Holding Version
1
+ # Liquid Glass
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Glass surfaces and controls for React, the web, and Electron. Clear and Regular materials support light and dark appearances and refract live content.
4
+
5
+ [Examples and component reference](https://liquid-glass.glassapp.dev/#examples) · [GitHub](https://github.com/Glass-HQ/liquid-glass)
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @glass-sdk/liquid-glass@~0.0.2
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```tsx
16
+ import { GlassScene, GlassContent, GlassSurface, GlassButton } from "@glass-sdk/liquid-glass";
17
+ import "@glass-sdk/liquid-glass/styles.css";
18
+
19
+ export function Example() {
20
+ return (
21
+ <GlassScene material="regular" appearance="light" style={{ height: 320 }}>
22
+ <GlassContent>
23
+ <img src="/landscape.jpg" alt="Mountain lake"
24
+ style={{ width: "100%", height: "100%", objectFit: "cover" }} />
25
+ </GlassContent>
26
+ <GlassSurface radius={28}
27
+ style={{ position: "absolute", left: 24, top: 100, padding: 20 }}>
28
+ <GlassButton onClick={() => console.log("Saved")}>Save</GlassButton>
29
+ </GlassSurface>
30
+ </GlassScene>
31
+ );
32
+ }
33
+ ```
34
+
35
+ Import the stylesheet once. It requires neither Tailwind nor a CSS reset. Put glass components inside `GlassScene`, with one `GlassContent` layer for the background. Text, SVG, and images in that layer stay live. In Next.js, use a client component.
36
+
37
+ `GlassContent` keeps your props, ref, and children on its source element inside stable transparent wrappers. Target its class rather than relying on it being a direct child of the scene. Put opacity and clipping intended for the finished composition on `GlassScene` or a shared ancestor; `GlassContent` styles describe the input behind the glass.
38
+
39
+ ## Components
40
+
41
+ | Component | Purpose |
42
+ | --- | --- |
43
+ | `GlassScene`, `GlassContent` | Scene and live background layer. |
44
+ | `GlassSurface`, `GlassButton` | Glass container and button. |
45
+ | `GlassToolbar`, `GlassToolbarButton`, `GlassToolbarLink`, `GlassToolbarGroup`, `GlassToolbarSpacer` | Keyboard-navigable toolbar. |
46
+ | `GlassTabs` | Tab bar with a moving selection indicator. |
47
+ | `GlassTabsRoot`, `GlassTabsList`, `GlassTabsTrigger`, `GlassTabsIndicator`, `GlassTabsContent` | Composable tabs and panels. |
48
+ | `GlassMenu`, `GlassMenuTrigger`, `GlassMenuContent`, `GlassMenuItem` | Menu with positioning and focus restoration. |
49
+ | `GlassMenuSubmenu`, `GlassMenuSubmenuTrigger`, `GlassMenuSubmenuContent` | Nested menus. |
50
+ | `GlassSlider`, `GlassSwitch` | Slider and switch. |
51
+ | `GlassForeground`, `useGlassForeground` | Foreground content that higher glass surfaces can refract. |
52
+ | `GlassShape`, `GlassShapeContainer`, `GlassCorner` | Continuous corners and container-relative geometry. |
53
+ | `GlassProgressiveBlur`, `GlassScrollEdges` | Progressive blur over background content and scroll edges. |
54
+
55
+ Buttons, toolbars, tabs, menus, sliders, and switches use Base UI behavior. Standard props, refs, accessible names, and state callbacks remain available. See the [component examples](https://liquid-glass.glassapp.dev/#examples) for usage and the [Base UI reference](https://base-ui.com/react/overview/quick-start) for inherited props.
56
+
57
+ ## Material and motion
58
+
59
+ Set defaults on `GlassScene`; individual surfaces can override them. Menu popups default to Regular.
60
+
61
+ | Prop | Default | Usage |
62
+ | --- | --- | --- |
63
+ | `material` | `"clear"` | `"clear"` or `"regular"`. |
64
+ | `appearance` | `"light"` | `"light"` or `"dark"`. |
65
+ | `radius` | Component-specific | Continuous corner radius in CSS pixels, `"capsule"`, or `"circle"`. Generic surfaces default to 8px. |
66
+ | `refraction` | `60` | Nonnegative displacement in CSS pixels. Nested surfaces limit their default to the parent inset. |
67
+ | `tint` | None | Six-digit hex color. Colors the glass without changing text or icons. |
68
+ | `interactive` | Component-specific | Press and drag feedback; on by default for buttons, toolbars, and tab bars. |
69
+ | `fluid` | `false` | Animate the outline when layout dimensions change. |
70
+ | `morphFrom` | None | Element ref or getter for a surface's opening and closing shape. |
71
+ | `morph` | By context | `"become"` replaces its source; `"detach"` separates from it. |
72
+ | `motion` | `"full"` | `"full"`, `"reduced"`, or `"none"`; inherited from the scene. |
73
+
74
+ Slider and switch pressed thumbs default to Clear, with refraction of 5px and 7.75px respectively. Their `tint` sets the track color.
75
+
76
+ System reduced-motion preferences always apply, including with `motion="full"`. Reduced motion removes stretching and travel; `"none"` removes transitions. Safari uses the same motion settings as other browsers.
77
+
78
+ Override styles with `className`, inline styles, or CSS utilities. The stylesheet uses low-specificity `:where()` selectors. Use `radius` to change corners so the material and content clip agree. Override `--lg-foreground` for text and icon colors.
79
+
80
+ ## Composing controls
81
+
82
+ The `render` prop merges props, handlers, styles, and refs with your component. Custom components must forward them to their DOM element. Use transparent backgrounds to keep the glass visible.
83
+
84
+ ```tsx
85
+ <GlassSurface material="clear" render={<Button onClick={save} />}>
86
+ Save
87
+ </GlassSurface>
88
+ ```
89
+
90
+ Menus stay inside their scene. Content accepts `side`, `align`, `sideOffset`, `alignOffset`, and `collisionAvoidance`; defaults are bottom/end with an 8px offset. Use `positionerProps` and `portalProps` for additional Base UI options.
91
+
92
+ ```tsx
93
+ <GlassMenu>
94
+ <GlassMenuTrigger render={<GlassButton />}>Options</GlassMenuTrigger>
95
+ <GlassMenuContent>
96
+ <GlassMenuItem onClick={save}>Save</GlassMenuItem>
97
+ <GlassMenuSubmenu>
98
+ <GlassMenuSubmenuTrigger>Share</GlassMenuSubmenuTrigger>
99
+ <GlassMenuSubmenuContent>
100
+ <GlassMenuItem onClick={copyLink}>Copy link</GlassMenuItem>
101
+ </GlassMenuSubmenuContent>
102
+ </GlassMenuSubmenu>
103
+ </GlassMenuContent>
104
+ </GlassMenu>
105
+ ```
106
+
107
+ `GlassMenuGroup`, `GlassMenuGroupLabel`, `GlassMenuSeparator`, `GlassMenuCheckboxItem`, `GlassMenuRadioGroup`, and `GlassMenuRadioItem` expose the corresponding Base UI parts.
108
+
109
+ In a toolbar, compose the trigger with `GlassToolbarButton render={<GlassMenuTrigger />}`. Use toolbar buttons and links for arrow-key navigation. `GlassToolbarSpacer` separates glass groups: `sizing="fixed"` gives an 8px gap; `"flexible"` fills available space. Give the toolbar a width or height for flexible spacing.
110
+
111
+ ## Tabs, sliders, and switches
112
+
113
+ ```tsx
114
+ <GlassTabs aria-label="Navigation" defaultValue="home"
115
+ items={[{ value: "home", label: "Home" }, { value: "library", label: "Library" }]} />
116
+
117
+ <GlassSlider aria-label="Volume" defaultValue={50}
118
+ onValueCommitted={(value) => console.log(value)} />
119
+ <GlassSlider ticks aria-label="Intensity" min={0} max={100} step={25} />
120
+ <label>Notifications <GlassSwitch name="notifications" defaultChecked /></label>
121
+ ```
122
+
123
+ Tabs select the first enabled item unless `defaultValue` is set. Use `value` and `onValueChange` for controlled selection. For panels or custom triggers, compose the tab parts:
124
+
125
+ ```tsx
126
+ <GlassTabsRoot defaultValue="preview">
127
+ <GlassTabsList aria-label="View">
128
+ <GlassTabsIndicator />
129
+ <GlassTabsTrigger value="preview">Preview</GlassTabsTrigger>
130
+ <GlassTabsTrigger value="usage">Usage</GlassTabsTrigger>
131
+ </GlassTabsList>
132
+ <GlassTabsContent value="preview">Your preview</GlassTabsContent>
133
+ <GlassTabsContent value="usage">Your usage code</GlassTabsContent>
134
+ </GlassTabsRoot>
135
+ ```
136
+
137
+ The list also works within an existing Base UI tabs root; do not nest another root. Keep interactive elements out of tab labels.
138
+
139
+ Sliders accept a numeric `value` or `defaultValue`, `min`, `max`, `step`, `onValueChange`, and `onValueCommitted`. Defaults are 0–100 with a 0.1 step. With `ticks`, the step must divide the range evenly, with at most 100 intervals. `thumbProps` exposes input refs and accessible value text.
140
+
141
+ Switches accept Base UI switch props, including `checked`, `defaultChecked`, `onCheckedChange`, `name`, and `inputRef`. Name inputs with a label or `aria-label`. Both controls support forms, RTL, `tint`, and reduced motion.
142
+
143
+ ## Progressive blur
144
+
145
+ `GlassProgressiveBlur` softens `GlassContent` at an edge. Put captions and controls outside that content layer to keep them sharp.
146
+
147
+ ```tsx
148
+ <GlassScene style={{ height: 320, overflow: "hidden" }}>
149
+ <GlassContent>
150
+ <img src="/landscape.jpg" alt="Mountain lake"
151
+ style={{ width: "100%", height: "100%", objectFit: "cover" }} />
152
+ </GlassContent>
153
+ <GlassProgressiveBlur edge="bottom" size={80} blur={20} />
154
+ </GlassScene>
155
+ ```
156
+
157
+ For scrolling content, use `GlassContent layout="scroll"` as the viewport and pass its ref to `GlassScrollEdges`. This keeps the glass and blur stationary during Safari scrolling. Give the scene a bounded height, and place floating controls beside the content:
158
+
159
+ ```tsx
160
+ const viewport = useRef<HTMLDivElement>(null);
161
+
162
+ <GlassScene style={{ height: 320, overflow: "hidden" }}>
163
+ <GlassContent layout="scroll" ref={viewport} tabIndex={0} role="region"
164
+ aria-label="Reading list" style={{ scrollPaddingBlock: 80 }}>
165
+ {children}
166
+ </GlassContent>
167
+ <GlassScrollEdges target={viewport} size={80} blur={20} />
168
+ </GlassScene>
169
+ ```
170
+
171
+ | Prop | Default | Usage |
172
+ | --- | --- | --- |
173
+ | `edge` | `"bottom"` | Primitive edge: `top`, `bottom`, `inline-start`, or `inline-end`. |
174
+ | `edges` | `["top", "bottom"]` | Scroll helper edges. Logical edges follow direction. |
175
+ | `target` | Required on scroll helper | Ref to the scrolling viewport. |
176
+ | `size` | `80` | Edge depth in pixels, 0–4096; scroll edges clamp to half the viewport. |
177
+ | `blur` | `20` | Gaussian standard deviation in pixels, 0–64. |
178
+ | `refraction` | `0` | Optical displacement in pixels, 0–32. |
179
+ | `disabled` | `false` | Remove the effect. |
180
+
181
+ The viewport needs an explicit height and scrolling overflow. Keep fixed headers and controls outside it, and use scroll padding so focused content can enter the clear area. Blur clears at reached edges and when there is no overflow. Reduced transparency and forced colors disable the effect. If map preparation fails, content remains readable and `onDiagnostic` reports the error.
182
+
183
+ ## Content shapes and foregrounds
184
+
185
+ `GlassShape` clips images and content to continuous corners without needing a scene:
186
+
187
+ ```tsx
188
+ <GlassShape radius={28} render={<img src="/cover.jpg" alt="Album cover" />} />
189
+ <GlassShape radius={40} style={{ padding: 4 }}>
190
+ <GlassShape concentric={{ inset: 4 }} radius={8}>Nested content</GlassShape>
191
+ </GlassShape>
192
+ ```
193
+
194
+ `concentric` follows the nearest declared container's outline. `GlassSurface` supports it too. Use `GlassShapeContainer` to declare geometry without clipping; `GlassCorner` positions a control near a curved corner. Both concentric shapes and corner controls accept `container={containerRef}` for siblings or portals. The container must be measurable; rotation is unsupported. Keep popups outside clipped content.
195
+
196
+ Use `GlassForeground` for ordinary DOM above the background that should refract beneath a higher glass surface. For an existing element ref, use `useGlassForeground()`. Keep overlapping content and menus in the same scene.
197
+
198
+ ## Without React
199
+
200
+ ```ts
201
+ import { createGlassScene } from "@glass-sdk/liquid-glass/dom";
202
+ import "@glass-sdk/liquid-glass/styles.css";
203
+
204
+ const scene = createGlassScene(document.querySelector<HTMLElement>(".lg-scene")!);
205
+ scene.setContent(document.querySelector<HTMLElement>(".lg-content")!);
206
+ const remove = scene.addSurface(document.querySelector<HTMLElement>(".lg-surface")!, {
207
+ material: "regular", radius: 28,
208
+ });
209
+
210
+ // On teardown:
211
+ remove();
212
+ scene.dispose();
213
+ ```
214
+
215
+ Use the positioned scene/content/surface structure from the React example. `scene.addForeground(element)` registers foreground content and returns a cleanup function. `scene.addAnimator(animator)` updates custom animation before scene measurements.
216
+
217
+ In Firefox, each surface draws its own glass: the scene adds an `aria-hidden` layer as the surface's last child, beneath its other children, which paints a live `-moz-element()` view of the content and refracts it. The content layer itself is not filtered there. Firefox otherwise repaints a filtered content layer in software on every frame anything on the page animates. If the content element has no `id`, the scene gives it one while it is attached. Surfaces should not rely on `:last-child` styling of their own children.
218
+
219
+ The `/core`, `/gpu`, and `/dom` exports provide geometry, materials, rendering, and controller APIs for custom integrations. Type declarations describe their options.
220
+
221
+ ## Requirements and limitations
222
+
223
+ - React 19+ for React components; HTTPS or localhost and an available WebGPU adapter to render glass material maps. Progressive blur needs no WebGPU.
224
+ - SVG filter performance varies between browser engines. Safari can spend substantially longer filtering large content layers than Chromium, even when material maps are cached. Keep scenes close to the content they need to refract, and test animated menus on the devices you support. Chromium, Firefox, Safari, and Electron are acceptance targets; they do not have identical performance.
225
+ - For consistent refraction in Safari, give `GlassContent` an opaque background. Transparent source pixels can leave the original content visible beneath its refracted image.
226
+ - Use bounded scenes with explicit content layers. Arbitrary page-backdrop sampling, native video composition, rotated/transformed ancestors, and native ports are outside the supported scope. Cross-origin image policies apply.
227
+ - `GlassScene.maxSurfaces` defaults to 16 and accepts at most 64. Use `onDiagnostic` for map readiness, construction timing, filter graph limits, and GPU errors.
228
+ - NodeNext TypeScript consumers currently need `skipLibCheck: true` for upstream vgpu declarations.
229
+
230
+ ## How it works
231
+
232
+ vgpu renders WGSL material maps; SVG filters apply them to live DOM content. Maps are cached and reused as surfaces move. Geometry changes prepare new maps. The library does not capture DOM screenshots.
233
+
234
+ ## Contributing and license
235
+
236
+ See [Contributing](https://github.com/Glass-HQ/liquid-glass/blob/main/CONTRIBUTING.md). Licensed under [MIT](LICENSE).
@@ -0,0 +1,86 @@
1
+ import { shapePolygon as e } from "./shape.js";
2
+ //#region src/core/concentric.ts
3
+ function t(t, r) {
4
+ if (!Number.isFinite(r) || r < 0) throw RangeError("Shape inset must be finite and nonnegative.");
5
+ if (t.outline && !t.outline.length) return [];
6
+ let i = t.outline ? [...t.outline, t.outline[0]] : e(t.width, t.height, t.radius), a = [
7
+ [0, 0],
8
+ [t.width, 0],
9
+ [t.width, t.height],
10
+ [0, t.height]
11
+ ];
12
+ for (let e = 1; e < i.length; e++) {
13
+ let t = i[e - 1], o = i[e], s = o[0] - t[0], c = o[1] - t[1], l = Math.hypot(s, c);
14
+ if (!(l < 2e-4) && (a = n(a, -c / l, s / l, (-c * t[0] + s * t[1]) / l + r), !a.length)) break;
15
+ }
16
+ return a;
17
+ }
18
+ function n(e, t, n, r) {
19
+ let i = [];
20
+ for (let a = 0; a < e.length; a++) {
21
+ let o = e[a], s = e[(a + 1) % e.length], c = o[0] * t + o[1] * n - r, l = s[0] * t + s[1] * n - r;
22
+ if (c >= -1e-7 && i.push(o), c < 0 != l < 0) {
23
+ let e = c / (c - l);
24
+ i.push([o[0] + (s[0] - o[0]) * e, o[1] + (s[1] - o[1]) * e]);
25
+ }
26
+ }
27
+ return i;
28
+ }
29
+ function r(t, r, i = 8) {
30
+ let a = e(r.width, r.height, i).map(([e, t]) => [e + r.x, t + r.y]);
31
+ for (let e = 0; e < t.length; e++) {
32
+ let r = t[e], i = t[(e + 1) % t.length], o = i[0] - r[0], s = i[1] - r[1], c = Math.hypot(o, s);
33
+ c < 1e-7 || (a = n(a, -s / c, o / c, (-s * r[0] + o * r[1]) / c));
34
+ }
35
+ return a.map(([e, t]) => [Math.round((e - r.x) * 1e4) / 1e4, Math.round((t - r.y) * 1e4) / 1e4]);
36
+ }
37
+ function i(e) {
38
+ return e.length ? `polygon(${e.map(([e, t]) => `${e.toFixed(3)}px ${t.toFixed(3)}px`).join(",")})` : "polygon(0px 0px,0px 0px,0px 0px)";
39
+ }
40
+ function a(e, t, n) {
41
+ return e.every((r, i) => {
42
+ let a = e[(i + 1) % e.length];
43
+ return (a[0] - r[0]) * (n - r[1]) - (a[1] - r[1]) * (t - r[0]) >= -.001;
44
+ });
45
+ }
46
+ function o(n, r, i, o, s = "circle") {
47
+ let c = t(n, o), l = e(r, i, s), u = (e) => c.length > 0 && l.every(([t, n]) => a(c, t + e, n + e)), d = Math.min((n.width - r) / 2, (n.height - i) / 2);
48
+ if (d < 0 || !u(d)) throw RangeError("The control does not fit inside its shape container.");
49
+ let f = 0, p = d;
50
+ for (let e = 0; e < 24; e++) {
51
+ let e = (f + p) / 2;
52
+ u(e) ? p = e : f = e;
53
+ }
54
+ return p;
55
+ }
56
+ function s(e, t, n, r) {
57
+ let i = [(n - Math.min(n, r)) / 2, (n + Math.min(n, r)) / 2], a = 0, o = t;
58
+ for (let t of i) {
59
+ let n = [];
60
+ for (let r = 0; r < e.length; r++) {
61
+ let i = e[r], a = e[(r + 1) % e.length];
62
+ Math.abs(i[1] - a[1]) < 1e-7 ? Math.abs(t - i[1]) < 1e-5 && n.push(i[0], a[0]) : t >= Math.min(i[1], a[1]) && t <= Math.max(i[1], a[1]) && n.push(i[0] + (a[0] - i[0]) * (t - i[1]) / (a[1] - i[1]));
63
+ }
64
+ n.length && (a = Math.max(a, Math.min(...n)), o = Math.min(o, Math.max(...n)));
65
+ }
66
+ return {
67
+ left: a,
68
+ right: t - o
69
+ };
70
+ }
71
+ function c(e) {
72
+ let t = [];
73
+ for (let n = 0; n < e.length; n++) {
74
+ let r = e[n], i = e[(n + 1) % e.length];
75
+ if (![...r, ...i].every(Number.isFinite)) throw RangeError("Outline coordinates must be finite.");
76
+ Math.hypot(i[0] - r[0], i[1] - r[1]) > 1e-5 && t.push([...r, ...i]);
77
+ }
78
+ let n = t.length;
79
+ if (n < 3 || n > 1024) throw RangeError("A glass outline needs between 3 and 1024 edges.");
80
+ return {
81
+ segments: t,
82
+ count: n
83
+ };
84
+ }
85
+ //#endregion
86
+ export { r as concentricOutline, s as contentInsets, o as cornerPlacement, t as insetShape, c as outlineSegments, i as polygonClip };
@@ -0,0 +1,41 @@
1
+ //#region src/core/materials.ts
2
+ var e = {
3
+ clear: {
4
+ blur: 0,
5
+ refraction: 60,
6
+ light: {
7
+ shadowLift: .18,
8
+ highlightRolloff: 0
9
+ },
10
+ dark: {
11
+ shadowLift: .15,
12
+ highlightRolloff: .2
13
+ }
14
+ },
15
+ regular: {
16
+ blur: 7.33,
17
+ refraction: 60,
18
+ light: {
19
+ fillSigma: 23,
20
+ fillOpacity: .34,
21
+ tone: [
22
+ .36,
23
+ .67,
24
+ -.1113,
25
+ 1.1031
26
+ ]
27
+ },
28
+ dark: {
29
+ fillSigma: 21.8,
30
+ fillOpacity: .65,
31
+ tone: [
32
+ .105,
33
+ .83,
34
+ -.2091,
35
+ 1.0648
36
+ ]
37
+ }
38
+ }
39
+ };
40
+ //#endregion
41
+ export { e as materials };
@@ -0,0 +1,206 @@
1
+ import { smoothUnion as e } from "./union.js";
2
+ //#region src/core/morph-path.ts
3
+ var t = (e, t, n) => e + (t - e) * n;
4
+ function n(e, t, n) {
5
+ let r = Math.min(1, Math.max(0, (n - e) / (t - e)));
6
+ return r * r * (3 - 2 * r);
7
+ }
8
+ function r(e, t, n) {
9
+ let r = Math.min(t, n) / 2;
10
+ if (e === "capsule" || e === "circle") return r;
11
+ let i = Number(e);
12
+ return Math.max(0, Math.min(Number.isFinite(i) ? i : 8, r));
13
+ }
14
+ function i(e, t) {
15
+ let n = r(e.radius, e.width, e.height), i = r(t.radius, t.width, t.height);
16
+ return Math.abs(Math.log(e.width / t.width)) + Math.abs(Math.log(e.height / t.height)) + Math.abs(n - i) / Math.max(4, Math.min(t.width, t.height) / 2);
17
+ }
18
+ var a = (e, t) => Math.hypot(Math.max(0, e.left - (t.left + t.width), t.left - (e.left + e.width)), Math.max(0, e.top - (t.top + t.height), t.top - (e.top + e.height))), o = (e, t, n = .5) => t.left >= e.left - n && t.top >= e.top - n && t.left + t.width <= e.left + e.width + n && t.top + t.height <= e.top + e.height + n;
19
+ function s(e, t) {
20
+ let n = t.top >= e.top + e.height - .5 || t.top + t.height <= e.top + .5;
21
+ return n === (t.left >= e.left + e.width - .5 || t.left + t.width <= e.left + .5) ? Math.abs(t.left + t.width / 2 - e.left - e.width / 2) / Math.max(1, t.width) > Math.abs(t.top + t.height / 2 - e.top - e.height / 2) / Math.max(1, t.height) ? "x" : "y" : n ? "y" : "x";
22
+ }
23
+ function c(e, t, n) {
24
+ if (!n || e >= 1) return e;
25
+ let r = Math.max(0, e);
26
+ return t ? 1 - (1 - r) ** 1.6 : r ** 1.4;
27
+ }
28
+ function l(e, i) {
29
+ let a = e.along !== void 0, o = c(i, e.along === "x", a), s = c(i, e.along === "y", a), l = Math.max(1, t(e.from.width, e.to.width, o)), u = Math.max(1, t(e.from.height, e.to.height, s)), d = t(e.from.left + e.from.width / 2, e.to.left + e.to.width / 2, o), f = t(e.from.top + e.from.height / 2, e.to.top + e.to.height / 2, s), p = Math.min(l, u) / 2, m = Math.min(1, Math.max(0, i)), h = r(e.fromRadius, e.from.width, e.from.height), g = t(h, r(e.toRadius, l, u), m), _ = Math.min(p, Math.max(g, .34 * Math.min(l, u))), v = .12 * (1 - h / Math.max(1, Math.min(e.from.width, e.from.height) / 2)), y = a ? (v > 0 ? n(0, v, m) : 1) * (1 - n(.35, .8, m)) : 0, b = Math.min(p, t(g, _, y));
30
+ return {
31
+ left: d - l / 2,
32
+ top: f - u / 2,
33
+ width: l,
34
+ height: u,
35
+ radius: b
36
+ };
37
+ }
38
+ var u = (e) => n(.4, .9, e), d = (e) => n(.02, .3, e), f = (e, t) => t * (1 - n(.3, .95, e)), p = (e, t) => Math.round(e / t) * t, m = /* @__PURE__ */ new Map();
39
+ function h(e, t, n = {}) {
40
+ if (!t) return g(e, t, n);
41
+ let r = (e) => ({
42
+ ...e,
43
+ left: Number((e.left - t.left).toFixed(8)),
44
+ top: Number((e.top - t.top).toFixed(8))
45
+ }), i = {
46
+ ...e,
47
+ from: r(e.from),
48
+ to: r(e.to)
49
+ }, a = {
50
+ ...t,
51
+ left: 0,
52
+ top: 0
53
+ }, o = JSON.stringify([
54
+ i,
55
+ a,
56
+ n
57
+ ]), s = m.get(o);
58
+ return s ? m.delete(o) : s = g(i, a, n), m.set(o, s), m.size > 16 && m.delete(m.keys().next().value), s.map((e) => ({
59
+ ...e,
60
+ shape: { ...e.shape },
61
+ ...e.box ? { box: {
62
+ ...e.box,
63
+ left: e.box.left + t.left,
64
+ top: e.box.top + t.top
65
+ } } : {}
66
+ }));
67
+ }
68
+ function g(n, s, c) {
69
+ let { stops: u = 14, unions: d = 16, neck: m = 18, dpr: h = 1, restDpr: g = h } = c, _ = Array.from({ length: 241 }, (e, t) => l(n, t / 240)), v = (e, t, n) => {
70
+ let r = n ? t.width : Math.max(1, Math.round(t.width)), i = n ? t.height : Math.max(1, Math.round(t.height)), a = p(Math.min(t.radius, r / 2, i / 2), .5);
71
+ return {
72
+ p: e,
73
+ shape: {
74
+ width: r,
75
+ height: i,
76
+ radius: a >= Math.min(r, i) / 2 - .25 ? "capsule" : a,
77
+ dpr: h
78
+ },
79
+ absorbs: !1
80
+ };
81
+ }, y = [], b = [0];
82
+ for (let e = 1; e <= 240; e++) b.push(b[e - 1] + i(_[e], _[e - 1]));
83
+ let x = b[240], S = 1;
84
+ for (let e = 1; e < 240 && x > 0; e++) b[e] >= x * S / (u - 1) && S < u - 1 && (y.push(v(e / 240, _[e], !1)), S++);
85
+ let C = {
86
+ p: 0,
87
+ shape: {
88
+ width: n.from.width,
89
+ height: n.from.height,
90
+ radius: n.fromRadius,
91
+ dpr: g,
92
+ resting: !0
93
+ },
94
+ absorbs: !1
95
+ }, w = {
96
+ p: 1,
97
+ shape: {
98
+ width: n.to.width,
99
+ height: n.to.height,
100
+ radius: n.toRadius,
101
+ dpr: g,
102
+ resting: !0
103
+ },
104
+ absorbs: !1
105
+ };
106
+ if (!s) return [
107
+ C,
108
+ ...y,
109
+ w
110
+ ];
111
+ let T = {
112
+ x: s.left,
113
+ y: s.top,
114
+ width: s.width,
115
+ height: s.height,
116
+ radius: r(s.radius, s.width, s.height)
117
+ }, E = (e) => {
118
+ let t = _[e], n = f(e / 240, m);
119
+ return !o(s, t) && n >= 1 && a(s, t) <= n;
120
+ }, D = -1, O = -1;
121
+ for (let e = 0; e <= 240; e++) {
122
+ if (!E(e)) {
123
+ if (D >= 0) break;
124
+ continue;
125
+ }
126
+ D < 0 && (D = e), O = e;
127
+ }
128
+ if (D < 0) return [
129
+ C,
130
+ ...y,
131
+ w
132
+ ];
133
+ let k = {
134
+ p: Math.max(0, D - 1) / 240,
135
+ shape: {
136
+ width: s.layoutWidth,
137
+ height: s.layoutHeight,
138
+ radius: s.radius,
139
+ dpr: g,
140
+ resting: !0
141
+ },
142
+ box: { ...s },
143
+ absorbs: !0
144
+ }, A = Math.max(2, Math.min(d, Math.ceil((O - D) / 240 / .025) + 1)), j = [];
145
+ for (let n = 0; n < A; n++) {
146
+ let r = Math.round(t(D, O, n / (A - 1))), i = _[r], a = r / 240, o = e([T, {
147
+ x: i.left,
148
+ y: i.top,
149
+ width: i.width,
150
+ height: i.height,
151
+ radius: i.radius
152
+ }], f(a, m), 1.5, 700);
153
+ if (o.length !== 1) continue;
154
+ let s = o[0], c = Math.floor(Math.min(...s.map(([e]) => e))), l = Math.floor(Math.min(...s.map(([, e]) => e))), u = Math.ceil(Math.max(...s.map(([e]) => e))), d = Math.ceil(Math.max(...s.map(([, e]) => e)));
155
+ j.push({
156
+ p: a,
157
+ shape: {
158
+ width: u - c,
159
+ height: d - l,
160
+ radius: 0,
161
+ outline: s.map(([e, t]) => [e - c, t - l]),
162
+ dpr: h
163
+ },
164
+ box: {
165
+ left: c,
166
+ top: l,
167
+ width: u - c,
168
+ height: d - l
169
+ },
170
+ absorbs: !0
171
+ });
172
+ }
173
+ if (!j.length) return [
174
+ C,
175
+ ...y,
176
+ w
177
+ ];
178
+ let M = v(Math.min(1, (O + 1) / 240), _[Math.min(240, O + 1)], !1), N = y.filter((e) => e.p > M.p);
179
+ return [
180
+ k,
181
+ ...j,
182
+ M,
183
+ ...N,
184
+ w
185
+ ];
186
+ }
187
+ function _(e, t) {
188
+ if (!e.length || t < e[0].p - 1e-9) return;
189
+ let n = 0;
190
+ for (; n + 1 < e.length && e[n + 1].p <= t;) n++;
191
+ let r = e[n], i = e[n + 1];
192
+ if (!i || i.p <= r.p) return {
193
+ a: r,
194
+ mix: 0,
195
+ absorb: +!!r.absorbs
196
+ };
197
+ let a = Math.min(1, Math.max(0, (t - r.p) / (i.p - r.p)));
198
+ return {
199
+ a: r,
200
+ b: i,
201
+ mix: a,
202
+ absorb: (r.absorbs ? 1 - a : 0) + (i.absorbs ? a : 0)
203
+ };
204
+ }
205
+ //#endregion
206
+ export { a as boxGap, u as contentReveal, t as mix, _ as morphDraw, l as morphShape, f as neckWidth, s as openingAxis, h as planMorph, r as radiusPixels, i as shapeDistance, n as smoothstep, d as sourceConceal };
@@ -0,0 +1,7 @@
1
+ //#region src/core/optics.ts
2
+ function e(e, t, n) {
3
+ let r = Math.max(0, Math.min(1, -e * n));
4
+ return t * (1 - Math.max(0, Math.min(1, Math.sqrt((2 - r) * r))));
5
+ }
6
+ //#endregion
7
+ export { e as edgeDisplacement };
@@ -0,0 +1,35 @@
1
+ //#region src/core/progressive.ts
2
+ function e(e) {
3
+ for (let [t, n, r] of [
4
+ [
5
+ "size",
6
+ e.size ?? 80,
7
+ 4096
8
+ ],
9
+ [
10
+ "blur",
11
+ e.blur ?? 20,
12
+ 64
13
+ ],
14
+ [
15
+ "refraction",
16
+ e.refraction ?? 0,
17
+ 32
18
+ ]
19
+ ]) if (!Number.isFinite(n) || n < 0 || n > r) throw RangeError(`${t} must be finite and between 0 and ${r}.`);
20
+ if (e.edge && ![
21
+ "top",
22
+ "bottom",
23
+ "inline-start",
24
+ "inline-end"
25
+ ].includes(e.edge)) throw RangeError("Unknown progressive blur edge.");
26
+ }
27
+ function t(e, t) {
28
+ return e === "inline-start" ? t ? "right" : "left" : e === "inline-end" ? t ? "left" : "right" : e;
29
+ }
30
+ function n(e, t, n, r, i, a, o) {
31
+ let s = Math.max(0, Math.min(r, a ? r + t : t)), c = Math.max(0, Math.min(i, n)), l = e === "top" ? c : e === "bottom" ? i - c : e === "left" ? s : r - s, u = Math.max(0, Math.min(1, l / Math.max(1, Math.min(o, 32))));
32
+ return u * u * (3 - 2 * u);
33
+ }
34
+ //#endregion
35
+ export { t as physicalEdge, n as scrollEdgeStrength, e as validateProgressive };