@glass-sdk/liquid-glass 0.0.2 → 0.0.3-beta.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/CHANGELOG.md +124 -0
- package/README.md +66 -149
- package/dist/core/concentric.js +20 -3
- package/dist/core/corner-options.js +12 -0
- package/dist/core/corner-path.js +118 -0
- package/dist/core/materials.js +264 -32
- package/dist/core/optics.js +1 -2
- package/dist/core/progressive.js +1 -2
- package/dist/core/shape.js +18 -28
- package/dist/core/spring.js +5 -10
- package/dist/core.js +5 -6
- package/dist/dom/backdrop-glass.js +46 -0
- package/dist/dom/compose-layers.js +42 -31
- package/dist/dom/composited.js +136 -0
- package/dist/dom/control-motion.js +58 -47
- package/dist/dom/engine.js +1 -2
- package/dist/dom/escaped-layers.js +179 -0
- package/dist/dom/filter-bounds.js +42 -13
- package/dist/dom/filter-budget.js +1 -2
- package/dist/dom/filter-chain.js +40 -0
- package/dist/dom/filter-groups.js +33 -14
- package/dist/dom/filter-paint-root.js +8 -6
- package/dist/dom/filter-patch.js +94 -55
- package/dist/dom/filter-reach.js +32 -19
- package/dist/dom/filter-stages.js +1 -2
- package/dist/dom/fixed-shape.js +23 -16
- package/dist/dom/foreground.js +16 -17
- package/dist/dom/interaction.js +65 -92
- package/dist/dom/layout-rect.js +42 -0
- package/dist/dom/layout-size.js +28 -0
- package/dist/dom/lens-layers.js +250 -136
- package/dist/dom/map-encoder.js +16 -13
- package/dist/dom/map-encoder.worker.js +2 -3
- package/dist/dom/map-encoding.js +49 -12
- package/dist/dom/map-image.js +29 -7
- package/dist/dom/map-store.js +1 -2
- package/dist/dom/maps.js +133 -83
- package/dist/dom/material-graph.js +108 -29
- package/dist/dom/media-mirror.js +244 -0
- package/dist/dom/page-zoom.js +19 -18
- package/dist/dom/png.js +1 -2
- package/dist/dom/progressive.js +152 -147
- package/dist/dom/renderer.js +1 -2
- package/dist/dom/sampling-bounds.js +1 -2
- package/dist/dom/selection.js +133 -79
- package/dist/dom/shape-attributes.js +9 -0
- package/dist/dom/shape-effects.js +14 -0
- package/dist/dom/shape-geometry.js +3 -0
- package/dist/dom/shape-layout.js +115 -116
- package/dist/dom/shared-backdrop.js +33 -25
- package/dist/dom/specular.js +116 -0
- package/dist/dom/ticker.js +28 -19
- package/dist/dom/tint-color.js +24 -0
- package/dist/dom/warm.js +63 -59
- package/dist/dom.js +591 -505
- package/dist/gpu/geometry.js +2 -3
- package/dist/gpu/maps.js +1109 -7
- package/dist/gpu/planes.js +2 -3
- package/dist/gpu.js +66 -64
- package/dist/index.js +12 -10
- package/dist/react/button.js +12 -11
- package/dist/react/color-picker.js +199 -0
- package/dist/react/control-thumb.js +4 -5
- package/dist/react/menu.js +82 -111
- package/dist/react/merged-ref.js +1 -2
- package/dist/react/progressive.js +1 -2
- package/dist/react/scene.js +71 -55
- package/dist/react/shape.js +67 -47
- package/dist/react/slider.js +81 -0
- package/dist/react/surface.js +90 -56
- package/dist/react/switch.js +101 -0
- package/dist/react/tabs.js +85 -63
- package/dist/react/toolbar.js +38 -123
- package/dist/react/value-control-motion.js +1 -2
- package/dist/styles.css +517 -111
- package/dist/types/core/concentric.d.ts +8 -0
- package/dist/types/core/corner-options.d.ts +4 -0
- package/dist/types/core/corner-path.d.ts +8 -0
- package/dist/types/core/index.d.ts +3 -5
- package/dist/types/core/materials.d.ts +100 -28
- package/dist/types/core/shape.d.ts +4 -6
- package/dist/types/core/spring.d.ts +8 -12
- package/dist/types/dom/backdrop-glass.d.ts +38 -0
- package/dist/types/dom/compose-layers.d.ts +4 -0
- package/dist/types/dom/composited.d.ts +61 -0
- package/dist/types/dom/escaped-layers.d.ts +32 -0
- package/dist/types/dom/filter-bounds.d.ts +4 -0
- package/dist/types/dom/filter-chain.d.ts +6 -0
- package/dist/types/dom/filter-groups.d.ts +1 -1
- package/dist/types/dom/filter-paint-root.d.ts +3 -0
- package/dist/types/dom/filter-patch.d.ts +5 -0
- package/dist/types/dom/filter-reach.d.ts +9 -9
- package/dist/types/dom/foreground.d.ts +2 -1
- package/dist/types/dom/index.d.ts +8 -19
- package/dist/types/dom/interaction.d.ts +8 -8
- package/dist/types/dom/layout-rect.d.ts +17 -0
- package/dist/types/dom/layout-size.d.ts +11 -0
- package/dist/types/dom/lens-layers.d.ts +18 -10
- package/dist/types/dom/map-encoder.d.ts +5 -2
- package/dist/types/dom/map-encoding.d.ts +12 -3
- package/dist/types/dom/map-image.d.ts +7 -1
- package/dist/types/dom/maps.d.ts +25 -7
- package/dist/types/dom/material-graph.d.ts +73 -10
- package/dist/types/dom/media-mirror.d.ts +49 -0
- package/dist/types/dom/progressive.d.ts +2 -5
- package/dist/types/dom/sampling-bounds.d.ts +1 -3
- package/dist/types/dom/selection.d.ts +29 -4
- package/dist/types/dom/shape-attributes.d.ts +6 -0
- package/dist/types/dom/shape-effects.d.ts +10 -0
- package/dist/types/dom/shape-geometry.d.ts +6 -0
- package/dist/types/dom/shape-layout.d.ts +2 -4
- package/dist/types/dom/shared-backdrop.d.ts +7 -3
- package/dist/types/dom/specular.d.ts +50 -0
- package/dist/types/dom/ticker.d.ts +4 -1
- package/dist/types/dom/tint-color.d.ts +11 -0
- package/dist/types/dom/warm.d.ts +8 -2
- package/dist/types/gpu/geometry.d.ts +2 -0
- package/dist/types/gpu/planes.d.ts +3 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/react/button.d.ts +1 -1
- package/dist/types/react/color-picker.d.ts +26 -0
- package/dist/types/react/index.d.ts +14 -10
- package/dist/types/react/menu.d.ts +4 -5
- package/dist/types/react/progressive.d.ts +1 -1
- package/dist/types/react/scene.d.ts +4 -2
- package/dist/types/react/shape.d.ts +11 -1
- package/dist/types/react/slider.d.ts +14 -0
- package/dist/types/react/surface.d.ts +11 -22
- package/dist/types/react/switch.d.ts +9 -0
- package/dist/types/react/tabs.d.ts +3 -3
- package/dist/types/react/toolbar.d.ts +1 -1
- package/package.json +46 -40
- package/dist/core/morph-path.js +0 -206
- package/dist/core/union.js +0 -117
- package/dist/dom/compound-field.js +0 -23
- package/dist/dom/exit-handoff.js +0 -14
- package/dist/dom/map-blend.js +0 -8
- package/dist/dom/morph.js +0 -296
- package/dist/react/value-controls.js +0 -176
- package/dist/types/core/morph-path.d.ts +0 -110
- package/dist/types/core/union.d.ts +0 -20
- package/dist/types/dom/compound-field.d.ts +0 -35
- package/dist/types/dom/exit-handoff.d.ts +0 -7
- package/dist/types/dom/map-blend.d.ts +0 -22
- package/dist/types/dom/morph.d.ts +0 -78
- package/dist/types/react/value-controls.d.ts +0 -20
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.3: Glass measured on macOS 27, and much faster in Chromium
|
|
4
|
+
|
|
5
|
+
_2026-11-22_
|
|
6
|
+
|
|
7
|
+
### New
|
|
8
|
+
|
|
9
|
+
- `GlassColorPicker`: a hue and saturation wheel whose dot grows into a Lens bubble while you drag.
|
|
10
|
+
- `GlassRow`: a row that follows the curve of the glass panel it sits in, as menu items do.
|
|
11
|
+
- `GlassPopupSurface`: glass for dialogs and popovers that stays hidden until its glass is drawn.
|
|
12
|
+
- `specular`: two rim highlights that turn toward the pointer, and with the device's tilt on Android.
|
|
13
|
+
- `frost` (0 to 1) moves Regular and Clear glass from see-through to frosted.
|
|
14
|
+
- `floating` gives menus, popovers and dialogs the deeper shadow macOS casts for them.
|
|
15
|
+
- `--lg-backdrop` gives glass a body over transparent content. Set it to the color behind the scene.
|
|
16
|
+
- `--lg-accent` colors a slider's fill and a switch's track from CSS.
|
|
17
|
+
- `tint` takes any CSS color, including a theme variable such as `var(--accent)`.
|
|
18
|
+
- `GlassSwitch` and `GlassSlider` accept `disabled`, and a switch follows its own `width` and `height`.
|
|
19
|
+
|
|
20
|
+
### Improved
|
|
21
|
+
|
|
22
|
+
- Materials follow macOS 27's glass, measured on `NSGlassEffectView` in both appearances. Glass changes with its size: small controls stay nearly clear, and panels gather frost and shadow.
|
|
23
|
+
- The rim is lit and outlined as on macOS.
|
|
24
|
+
- Each surface draws its own glass as a backdrop filter in Chromium and Electron, so a change redraws only the glass over it. Hovering an open menu runs about five times as fast.
|
|
25
|
+
- The glass engine loads after the page: importing a surface costs 4 KB gzipped instead of 45 KB.
|
|
26
|
+
- Tabs move as macOS 27's do: the selection rests on a glass plate, a press lifts a magnifying lens, and dragging keeps it exactly under the pointer.
|
|
27
|
+
- A pressed lens is sharp, with a crisp outline and soft color fringes all round its rim.
|
|
28
|
+
- Pressed switch and slider thumbs lift into a lens at macOS's sizes and timing.
|
|
29
|
+
- Interactive glass grows 2.5px under a press and settles back in about 200ms.
|
|
30
|
+
- Menus open at once and open submenus as soon as the pointer reaches them.
|
|
31
|
+
- In Safari, a scene with a lot of glass on screen draws a simpler filter instead of shifting or losing its glass, and Regular glass casts its shadow as a box shadow, so it costs little more than Clear.
|
|
32
|
+
- In Firefox, glass over other glass shows the labels and icons on it, so a tab bar's lens magnifies the tabs it passes.
|
|
33
|
+
- A scene given more surfaces than `maxSurfaces` reports it through `onDiagnostic` instead of throwing.
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- In Safari, `GlassContent layout="scroll"` no longer draws blank while the page is zoomed.
|
|
38
|
+
|
|
39
|
+
### Breaking changes
|
|
40
|
+
|
|
41
|
+
- `material` defaults to `"regular"`. The new `"lens"` material is the old unfrosted look.
|
|
42
|
+
- Morphing is removed: `morphFrom`, `morph`, `neck`, `morphEnter` and `fluid` are gone from `GlassSurface` and `GlassMenuContent`, and `GlassMorph` is no longer exported.
|
|
43
|
+
- `GlassTabsIndicator` is the resting plate (Regular by default), and `GlassTabsList` defaults to `interactive={false}`.
|
|
44
|
+
- `/core` no longer exports `materials`, `smoothUnion`, `smoothMin`, `roundRectDistance`, `RoundRect` or `springs.morph`. Use `glassRecipe(options)` for a material's values.
|
|
45
|
+
- `/dom` no longer exports `attachGeometryMotion`, `radiusPixels`, `GeometryAnimator`, `GeometryMotionOptions`, `LensFrame`, `LensPlacement` or `LensWaypoint`. `MaterialMaps.overlay` is replaced by `rim` and `light`, and `attachSelectionLens` takes its lens through the returned `setLens`.
|
|
46
|
+
- `.lg-switch-thumb` styling and `--lg-switch-travel` are no longer needed; size the switch itself.
|
|
47
|
+
- Surfaces get an inline `border-radius` in every browser instead of a `clip-path`, so content inside glass is clipped to rounded corners rather than continuous ones.
|
|
48
|
+
|
|
49
|
+
## 0.0.2: Faster glass in every engine, and a smaller download
|
|
50
|
+
|
|
51
|
+
_2026-10-10_
|
|
52
|
+
|
|
53
|
+
### New
|
|
54
|
+
|
|
55
|
+
- `GlassContent layout="scroll"` makes the content layer the scroll viewport. It keeps glass and blur still while Safari scrolls. Pass its ref to `GlassScrollEdges`:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
const viewport = useRef<HTMLDivElement>(null);
|
|
59
|
+
|
|
60
|
+
<GlassScene style={{ height: 320, overflow: "hidden" }}>
|
|
61
|
+
<GlassContent
|
|
62
|
+
layout="scroll"
|
|
63
|
+
ref={viewport}
|
|
64
|
+
tabIndex={0}
|
|
65
|
+
role="region"
|
|
66
|
+
aria-label="Reading list"
|
|
67
|
+
style={{ scrollPaddingBlock: 80 }}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</GlassContent>
|
|
71
|
+
<GlassScrollEdges target={viewport} size={80} blur={20} />
|
|
72
|
+
</GlassScene>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Before, you wrapped `GlassContent layout="flow"` in your own scrolling `div`. That still works.
|
|
76
|
+
|
|
77
|
+
### Improved
|
|
78
|
+
|
|
79
|
+
- An app that imports one component downloads about a third as much up front. The package ships one module per component, so bundlers drop the components and Base UI parts you don't import, and the GPU renderer loads on demand the first time glass needs it. Importing `GlassSurface` or `GlassButton` costs 46 to 47 KB gzipped, down from 139 KB.
|
|
80
|
+
- Firefox draws each surface's glass from a live copy of the content in its own layer, so unchanged glass isn't drawn again. Scrolling, menus, and switches use about a seventh of the CPU they did.
|
|
81
|
+
- `GlassProgressiveBlur` and `GlassScrollEdges` no longer need images or WebGPU, and now render in Firefox and Safari as well as Chrome.
|
|
82
|
+
- In Safari, a menu opens or closes with one redraw, where every frame of the animation used to take about 200 ms. Pressed glass keeps its outline instead of stretching, dragging glass runs at 60 fps, and glass follows page zoom and pinch.
|
|
83
|
+
- In Chrome, a surface that moves as a whole gets its own layer while it moves, so dragging glass costs about 40% less GPU time.
|
|
84
|
+
- `GlassContent` keeps your props, ref, and children on its own element inside stable wrappers. Target its class rather than relying on it being a direct child of the scene.
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
|
|
88
|
+
- In Safari, displacement now covers every sampled pixel, and filters survive partial repaints.
|
|
89
|
+
|
|
90
|
+
## 0.0.1: Initial public release
|
|
91
|
+
|
|
92
|
+
_2026-10-08_
|
|
93
|
+
|
|
94
|
+
The first public release of `@glass-sdk/liquid-glass`: glass surfaces and controls for React, the web, and Electron. Clear and Regular materials refract live content in light and dark appearances.
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
npm install @glass-sdk/liquid-glass@~0.0.1
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { GlassScene, GlassContent, GlassSurface, GlassButton } from "@glass-sdk/liquid-glass";
|
|
102
|
+
import "@glass-sdk/liquid-glass/styles.css";
|
|
103
|
+
|
|
104
|
+
<GlassScene material="regular" appearance="light" style={{ height: 320 }}>
|
|
105
|
+
<GlassContent>
|
|
106
|
+
<img src="/landscape.jpg" alt="Mountain lake" />
|
|
107
|
+
</GlassContent>
|
|
108
|
+
<GlassSurface radius={28} style={{ position: "absolute", left: 24, top: 100, padding: 20 }}>
|
|
109
|
+
<GlassButton onClick={save}>Save</GlassButton>
|
|
110
|
+
</GlassSurface>
|
|
111
|
+
</GlassScene>;
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### New
|
|
115
|
+
|
|
116
|
+
- `GlassScene` and `GlassContent` set up a scene and its live background. Text, SVG, and images in the content layer stay live.
|
|
117
|
+
- `GlassSurface` and `GlassButton`, with `material`, `appearance`, `radius`, `refraction`, `tint`, `interactive`, `fluid`, `morphFrom`, `morph`, and `motion` props. Set defaults on the scene and override them per surface.
|
|
118
|
+
- Controls built on Base UI: `GlassToolbar` and its buttons, links, groups, and spacers; `GlassTabs` and composable tab parts; `GlassMenu` with submenus, groups, checkbox and radio items; `GlassSlider` and `GlassSwitch`.
|
|
119
|
+
- `GlassProgressiveBlur` softens content at an edge, and `GlassScrollEdges` blurs the edges of a scrolling viewport.
|
|
120
|
+
- `GlassShape`, `GlassShapeContainer`, and `GlassCorner` for continuous corners and concentric, container-relative geometry. `GlassForeground` and `useGlassForeground` let higher glass refract ordinary DOM.
|
|
121
|
+
- `@glass-sdk/liquid-glass/dom` drives scenes without React through `createGlassScene()`. `/core` and `/gpu` expose the geometry, material, and map-rendering APIs.
|
|
122
|
+
- Reduced-motion preferences always apply, and reduced transparency and forced colors turn the blur effects off.
|
|
123
|
+
|
|
124
|
+
Rendering needs React 19 or later for the components, HTTPS or localhost, and a WebGPU adapter. Safari has known rendering issues in this release.
|
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Liquid Glass
|
|
2
2
|
|
|
3
|
-
Glass surfaces and controls for React, the web, and Electron. Clear and
|
|
3
|
+
Glass surfaces and controls for React, the web, and Electron, modeled on macOS 27. Regular, Clear and Lens materials refract live content in light and dark appearances.
|
|
4
4
|
|
|
5
5
|
[Examples and component reference](https://liquid-glass.glassapp.dev/#examples) · [GitHub](https://github.com/Glass-HQ/liquid-glass)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install @glass-sdk/liquid-glass
|
|
10
|
+
npm install @glass-sdk/liquid-glass @base-ui/react
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
@@ -18,76 +18,70 @@ import "@glass-sdk/liquid-glass/styles.css";
|
|
|
18
18
|
|
|
19
19
|
export function Example() {
|
|
20
20
|
return (
|
|
21
|
-
<GlassScene
|
|
21
|
+
<GlassScene appearance="light" style={{ height: 320 }}>
|
|
22
22
|
<GlassContent>
|
|
23
|
-
<img
|
|
24
|
-
|
|
23
|
+
<img
|
|
24
|
+
src="/landscape.jpg"
|
|
25
|
+
alt="Mountain lake"
|
|
26
|
+
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
27
|
+
/>
|
|
25
28
|
</GlassContent>
|
|
26
|
-
<GlassSurface radius={28}
|
|
27
|
-
|
|
28
|
-
<GlassButton onClick={() => console.log("Saved")}>Save</GlassButton>
|
|
29
|
+
<GlassSurface radius={28} style={{ position: "absolute", left: 24, top: 100, padding: 20 }}>
|
|
30
|
+
<GlassButton onClick={save}>Save</GlassButton>
|
|
29
31
|
</GlassSurface>
|
|
30
32
|
</GlassScene>
|
|
31
33
|
);
|
|
32
34
|
}
|
|
33
35
|
```
|
|
34
36
|
|
|
35
|
-
Import the stylesheet once
|
|
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.
|
|
37
|
+
Import the stylesheet once; it needs no Tailwind or CSS reset. Put glass inside a `GlassScene` with one `GlassContent` layer for what the glass refracts. Text, SVG and images in that layer stay live. In Next.js, use a client component.
|
|
38
38
|
|
|
39
39
|
## Components
|
|
40
40
|
|
|
41
|
-
| Component
|
|
42
|
-
|
|
|
43
|
-
| `GlassScene`, `GlassContent`
|
|
44
|
-
| `GlassSurface`, `GlassButton`
|
|
45
|
-
| `GlassToolbar`, `GlassToolbarButton`, `GlassToolbarLink`, `GlassToolbarGroup`, `GlassToolbarSpacer`
|
|
46
|
-
| `GlassTabs` |
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `GlassForeground`, `useGlassForeground`
|
|
52
|
-
| `
|
|
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
|
|
41
|
+
| Component | Purpose |
|
|
42
|
+
| -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
|
|
43
|
+
| `GlassScene`, `GlassContent` | A scene and the live content its glass refracts. |
|
|
44
|
+
| `GlassSurface`, `GlassPopupSurface`, `GlassButton` | Glass, glass for dialogs and popovers, and a button. |
|
|
45
|
+
| `GlassToolbar`, `GlassToolbarButton`, `GlassToolbarLink`, `GlassToolbarGroup`, `GlassToolbarSpacer` | A keyboard-navigable toolbar. |
|
|
46
|
+
| `GlassTabs`, or `GlassTabsRoot`, `GlassTabsList`, `GlassTabsTrigger`, `GlassTabsIndicator`, `GlassTabsContent` | A tab bar, or composable tabs and panels. |
|
|
47
|
+
| `GlassMenu`, `GlassMenuTrigger`, `GlassMenuContent`, `GlassMenuItem`, `GlassMenuSubmenu…` | Menus and submenus. |
|
|
48
|
+
| `GlassSlider`, `GlassSwitch`, `GlassColorPicker` | A slider, a switch and a color wheel. |
|
|
49
|
+
| `GlassRow` | A row that follows the corners of its glass panel. |
|
|
50
|
+
| `GlassShape`, `GlassShapeContainer`, `GlassCorner` | Continuous corners and concentric shapes. |
|
|
51
|
+
| `GlassForeground`, `useGlassForeground` | DOM above the content that higher glass also refracts. |
|
|
52
|
+
| `GlassProgressiveBlur`, `GlassScrollEdges` | Blur that fades in at an edge, and at a scroller's edges. |
|
|
58
53
|
|
|
59
|
-
|
|
54
|
+
Controls are built on [Base UI](https://base-ui.com/react/overview/quick-start), so its props, refs, accessible names and callbacks work as usual. Use `render` to put glass on your own component; it must forward props and ref to its element.
|
|
60
55
|
|
|
61
|
-
|
|
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. |
|
|
56
|
+
## Options
|
|
73
57
|
|
|
74
|
-
|
|
58
|
+
Set these on `GlassScene` to apply to everything in it, or on any surface or control.
|
|
75
59
|
|
|
76
|
-
|
|
60
|
+
| Prop | Default | Usage |
|
|
61
|
+
| ------------- | ---------- | -------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `material` | `regular` | `regular` frosts, `clear` stays sharp, `lens` magnifies with color fringes. |
|
|
63
|
+
| `appearance` | `light` | `light` or `dark`. |
|
|
64
|
+
| `radius` | By control | Corner radius in pixels, `"capsule"` or `"circle"`. |
|
|
65
|
+
| `refraction` | By size | How far the rim bends what is behind it, in pixels. |
|
|
66
|
+
| `tint` | None | Any CSS color, including a theme variable such as `var(--accent)`. |
|
|
67
|
+
| `frost` | `0` | From 0 (see-through) to 1 (frosted). Lens ignores it. |
|
|
68
|
+
| `interactive` | By control | Grow slightly and light up under a press. On for buttons, toolbars and switches. |
|
|
69
|
+
| `floating` | `false` | A deeper shadow, for glass above the window. Menus, popovers and `GlassPopupSurface` set it. |
|
|
70
|
+
| `specular` | `false` | Rim highlights that turn toward the pointer. |
|
|
71
|
+
| `motion` | `full` | `full`, `reduced` or `none`. The system's reduced-motion setting always applies. |
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
Like macOS's, glass changes with its size: controls up to 64px stay nearly clear, and from there to 160px glass gathers the frost and shadow of a panel.
|
|
79
74
|
|
|
80
|
-
|
|
75
|
+
CSS custom properties:
|
|
81
76
|
|
|
82
|
-
|
|
77
|
+
- `--lg-backdrop`: the color behind the scene. Glass over transparent content looks as it would over that color instead of showing only its rim.
|
|
78
|
+
- `--lg-accent`: a slider's fill and a switch's on track, when no `tint` is set.
|
|
79
|
+
- `--lg-foreground`: text and icon color on glass.
|
|
80
|
+
- `--lg-tab-selection`: the fill of the tab bar's resting selection.
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
<GlassSurface material="clear" render={<Button onClick={save} />}>
|
|
86
|
-
Save
|
|
87
|
-
</GlassSurface>
|
|
88
|
-
```
|
|
82
|
+
Styles use low-specificity `:where()` selectors, so `className`, inline styles and utility classes override them. Change corners with `radius` rather than CSS, so the glass and its content agree.
|
|
89
83
|
|
|
90
|
-
|
|
84
|
+
## Examples
|
|
91
85
|
|
|
92
86
|
```tsx
|
|
93
87
|
<GlassMenu>
|
|
@@ -102,98 +96,29 @@ Menus stay inside their scene. Content accepts `side`, `align`, `sideOffset`, `a
|
|
|
102
96
|
</GlassMenuSubmenu>
|
|
103
97
|
</GlassMenuContent>
|
|
104
98
|
</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
99
|
|
|
113
|
-
|
|
114
|
-
<GlassTabs aria-label="Navigation" defaultValue="home"
|
|
100
|
+
<GlassTabs aria-label="View" defaultValue="home"
|
|
115
101
|
items={[{ value: "home", label: "Home" }, { value: "library", label: "Library" }]} />
|
|
116
102
|
|
|
117
|
-
<GlassSlider aria-label="Volume" defaultValue={50}
|
|
118
|
-
|
|
119
|
-
<
|
|
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>
|
|
103
|
+
<GlassSlider aria-label="Volume" defaultValue={50} />
|
|
104
|
+
<GlassSwitch aria-label="Wi-Fi" style={{ width: 44, height: 20 }} />
|
|
105
|
+
<GlassColorPicker value={color} onValueChange={setColor} />
|
|
135
106
|
```
|
|
136
107
|
|
|
137
|
-
|
|
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:
|
|
108
|
+
Menus also have groups, separators, checkbox and radio items. A switch sizes its thumb from its own `width` and `height`. For a scrolling list with blurred edges, make the content the scroller and pass its ref:
|
|
158
109
|
|
|
159
110
|
```tsx
|
|
160
111
|
const viewport = useRef<HTMLDivElement>(null);
|
|
161
112
|
|
|
162
|
-
<GlassScene style={{ height: 320
|
|
163
|
-
<GlassContent layout="scroll" ref={viewport}
|
|
164
|
-
aria-label="Reading list" style={{ scrollPaddingBlock: 80 }}>
|
|
113
|
+
<GlassScene style={{ height: 320 }}>
|
|
114
|
+
<GlassContent layout="scroll" ref={viewport}>
|
|
165
115
|
{children}
|
|
166
116
|
</GlassContent>
|
|
167
117
|
<GlassScrollEdges target={viewport} size={80} blur={20} />
|
|
168
|
-
</GlassScene
|
|
118
|
+
</GlassScene>;
|
|
169
119
|
```
|
|
170
120
|
|
|
171
|
-
|
|
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.
|
|
121
|
+
The [examples site](https://liquid-glass.glassapp.dev/#examples) shows every component with its code and full props.
|
|
197
122
|
|
|
198
123
|
## Without React
|
|
199
124
|
|
|
@@ -204,7 +129,7 @@ import "@glass-sdk/liquid-glass/styles.css";
|
|
|
204
129
|
const scene = createGlassScene(document.querySelector<HTMLElement>(".lg-scene")!);
|
|
205
130
|
scene.setContent(document.querySelector<HTMLElement>(".lg-content")!);
|
|
206
131
|
const remove = scene.addSurface(document.querySelector<HTMLElement>(".lg-surface")!, {
|
|
207
|
-
|
|
132
|
+
radius: 28,
|
|
208
133
|
});
|
|
209
134
|
|
|
210
135
|
// On teardown:
|
|
@@ -212,25 +137,17 @@ remove();
|
|
|
212
137
|
scene.dispose();
|
|
213
138
|
```
|
|
214
139
|
|
|
215
|
-
|
|
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.
|
|
140
|
+
`/core`, `/gpu` and `/dom` expose the geometry, materials, map rendering and scene controller for custom integrations.
|
|
229
141
|
|
|
230
|
-
##
|
|
142
|
+
## Requirements
|
|
231
143
|
|
|
232
|
-
|
|
144
|
+
- React 19 or later and `@base-ui/react` for the components.
|
|
145
|
+
- HTTPS or localhost and a WebGPU adapter. Blur needs no WebGPU.
|
|
146
|
+
- Chromium and Electron are fastest. Firefox and Safari are supported. Safari can be slow with large scenes, so keep scenes close to the content they refract.
|
|
147
|
+
- Glass refracts its scene's content layer, not the rest of the page. Rotated or transformed ancestors aren't supported.
|
|
148
|
+
- A scene holds 16 surfaces by default and up to 64 (`maxSurfaces`). `onDiagnostic` reports errors and timing.
|
|
149
|
+
- NodeNext TypeScript projects need `skipLibCheck: true` for vgpu's declarations.
|
|
233
150
|
|
|
234
|
-
##
|
|
151
|
+
## License
|
|
235
152
|
|
|
236
|
-
|
|
153
|
+
[MIT](LICENSE).
|
package/dist/core/concentric.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shapePolygon as e } from "./shape.js";
|
|
2
|
-
|
|
2
|
+
// src/core/concentric.ts
|
|
3
3
|
function t(t, r) {
|
|
4
4
|
if (!Number.isFinite(r) || r < 0) throw RangeError("Shape inset must be finite and nonnegative.");
|
|
5
5
|
if (t.outline && !t.outline.length) return [];
|
|
@@ -82,5 +82,22 @@ function c(e) {
|
|
|
82
82
|
count: n
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
function l(e, t, n) {
|
|
86
|
+
if (t <= 0 && n <= 0) return e;
|
|
87
|
+
let r = e.width + t, i = e.height + n;
|
|
88
|
+
if (e.outline) return {
|
|
89
|
+
...e,
|
|
90
|
+
width: r,
|
|
91
|
+
height: i,
|
|
92
|
+
outline: e.outline.map(([r, i]) => [r > e.width / 2 ? r + t : r, i > e.height / 2 ? i + n : i])
|
|
93
|
+
};
|
|
94
|
+
if (e.radius === "circle") return e;
|
|
95
|
+
let a = e.radius === "capsule" ? Math.min(e.width, e.height) / 2 : e.radius;
|
|
96
|
+
return {
|
|
97
|
+
...e,
|
|
98
|
+
width: r,
|
|
99
|
+
height: i,
|
|
100
|
+
radius: a
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export { r as concentricOutline, s as contentInsets, o as cornerPlacement, t as insetShape, c as outlineSegments, i as polygonClip, l as scrolledShape };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/core/corner-options.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
if (typeof e != "number" && e !== "capsule" && e !== "circle") throw RangeError("Unknown glass radius.");
|
|
4
|
+
if (typeof e == "number" && (!Number.isFinite(e) || e < 0)) throw RangeError("Corner radius must be finite and nonnegative.");
|
|
5
|
+
return {
|
|
6
|
+
radius: typeof e == "number" ? e : 2 ** 53 - 1,
|
|
7
|
+
smoothing: .8125,
|
|
8
|
+
preserveSmoothing: !0,
|
|
9
|
+
curve: e === "circle" ? "arc" : "squircle"
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export { e as cornerOptions };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/core/corner-path.ts
|
|
2
|
+
var e = (e) => e.toFixed(4), t = (e) => e * Math.PI / 180;
|
|
3
|
+
function n(e, n, r, i) {
|
|
4
|
+
if (e <= 0) return {
|
|
5
|
+
a: 0,
|
|
6
|
+
b: 0,
|
|
7
|
+
c: 0,
|
|
8
|
+
d: 0,
|
|
9
|
+
p: 0,
|
|
10
|
+
arc: 0
|
|
11
|
+
};
|
|
12
|
+
let a = (1 + n) * e;
|
|
13
|
+
r || (n = Math.min(n, i / e - 1), a = Math.min(a, i));
|
|
14
|
+
let o = 90 * (1 - n), s = Math.sin(t(o / 2)) * e * Math.sqrt(2), c = e * Math.tan(t((90 - o) / 4)), l = 45 * n, u = c * Math.cos(t(l)), d = u * Math.tan(t(l)), f = (a - s - u - d) / 3, p = 2 * f;
|
|
15
|
+
if (r && a > i) {
|
|
16
|
+
let e = i - d - s - u;
|
|
17
|
+
f = Math.min(f, e - e / 6), p = e - f, a = Math.min(a, i);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
a: p,
|
|
21
|
+
b: f,
|
|
22
|
+
c: u,
|
|
23
|
+
d,
|
|
24
|
+
p: a,
|
|
25
|
+
arc: s
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function r(t, r, i, a) {
|
|
29
|
+
let { a: o, b: s, c, d: l, p: u, arc: d } = n(t, r, i, a), [f, p, m, h, g, _] = [
|
|
30
|
+
o,
|
|
31
|
+
o + s,
|
|
32
|
+
o + s + c,
|
|
33
|
+
c,
|
|
34
|
+
s + c,
|
|
35
|
+
l
|
|
36
|
+
].map((t) => [e(t), e(-t)]), v = e(t), y = e(d), b = "-" + y;
|
|
37
|
+
return {
|
|
38
|
+
p: u,
|
|
39
|
+
segments: {
|
|
40
|
+
TR: `c ${f[0]} 0 ${p[0]} 0 ${m[0]} ${_[0]} a ${v} ${v} 0 0 1 ${y} ${y} c ${_[0]} ${h[0]} ${_[0]} ${g[0]} ${_[0]} ${m[0]}`,
|
|
41
|
+
BR: `c 0 ${f[0]} 0 ${p[0]} ${_[1]} ${m[0]} a ${v} ${v} 0 0 1 ${b} ${y} c ${h[1]} ${_[0]} ${g[1]} ${_[0]} ${m[1]} ${_[0]}`,
|
|
42
|
+
BL: `c ${f[1]} 0 ${p[1]} 0 ${m[1]} ${_[1]} a ${v} ${v} 0 0 1 ${b} ${b} c ${_[1]} ${h[1]} ${_[1]} ${g[1]} ${_[1]} ${m[1]}`,
|
|
43
|
+
TL: `c 0 ${f[1]} 0 ${p[1]} ${_[0]} ${m[1]} a ${v} ${v} 0 0 1 ${y} ${b} c ${h[0]} ${_[1]} ${g[0]} ${_[1]} ${m[0]} ${_[1]}`
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function i(t, n) {
|
|
48
|
+
let r = Math.min(t, n), i = e(r), a = e(-r);
|
|
49
|
+
return {
|
|
50
|
+
p: r,
|
|
51
|
+
segments: {
|
|
52
|
+
TR: `a ${i} ${i} 0 0 1 ${i} ${i}`,
|
|
53
|
+
BR: `a ${i} ${i} 0 0 1 ${a} ${i}`,
|
|
54
|
+
BL: `a ${i} ${i} 0 0 1 ${a} ${a}`,
|
|
55
|
+
TL: `a ${i} ${i} 0 0 1 ${i} ${a}`
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function a(t, r, i, a) {
|
|
60
|
+
let { a: o, b: s, c, d: l, p: u } = n(t, Math.min(r, a / t - 1), i, a), d = o + s + c, [f, p, m, h, g, _, v, y] = [
|
|
61
|
+
o,
|
|
62
|
+
o + s,
|
|
63
|
+
d,
|
|
64
|
+
c,
|
|
65
|
+
s + c,
|
|
66
|
+
l,
|
|
67
|
+
u - d,
|
|
68
|
+
t - l
|
|
69
|
+
].map((t) => [e(t), e(-t)]);
|
|
70
|
+
return {
|
|
71
|
+
p: u,
|
|
72
|
+
r: e(t),
|
|
73
|
+
A: f,
|
|
74
|
+
AB: p,
|
|
75
|
+
E: m,
|
|
76
|
+
C: h,
|
|
77
|
+
BC: g,
|
|
78
|
+
D: _,
|
|
79
|
+
AX: v,
|
|
80
|
+
AY: y
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function o(r, i, a, o, s) {
|
|
84
|
+
let c = (e) => {
|
|
85
|
+
let r = Math.max(0, Math.min(e / a - 1, o)), { a: i, b: c, p: l } = n(a, r, s, e), u = t(45 * r);
|
|
86
|
+
return {
|
|
87
|
+
a: i,
|
|
88
|
+
b: c,
|
|
89
|
+
p: l,
|
|
90
|
+
sin: Math.sin(u),
|
|
91
|
+
cos: Math.cos(u)
|
|
92
|
+
};
|
|
93
|
+
}, l = c(r / 2), u = c(i / 2), d = (t) => e(Object.is(t, -0) ? 0 : t), f = (e, t, n, r, i, o) => {
|
|
94
|
+
let s = r === 0 ? l : u, c = o === 0 ? l : u, f = e + (n + i) * a, p = t + (r + o) * a, m = f - i * a * s.cos - n * a * s.sin, h = p - o * a * s.cos - r * a * s.sin, g = f - n * a * c.cos - i * a * c.sin, _ = p - r * a * c.cos - o * a * c.sin, v = e + n * s.p, y = t + r * s.p, b = Math.hypot(g - m, _ - h) > 1e-6, x = b ? g : m, S = b ? _ : h, C = e + i * c.p, w = t + o * c.p, T = `L ${d(v)} ${d(y)} `;
|
|
95
|
+
return T += `c ${d(-n * s.a)} ${d(-r * s.a)} ${d(-n * (s.a + s.b))} ${d(-r * (s.a + s.b))} ${d(m - v)} ${d(h - y)} `, b && (T += `a ${d(a)} ${d(a)} 0 0 1 ${d(g - m)} ${d(_ - h)} `), T + `c ${d(C - i * (c.a + c.b) - x)} ${d(w - o * (c.a + c.b) - S)} ${d(C - i * c.a - x)} ${d(w - o * c.a - S)} ${d(C - x)} ${d(w - S)}`;
|
|
96
|
+
};
|
|
97
|
+
return `M ${d(l.p)} 0 ${f(r, 0, -1, 0, 0, 1)} ${f(r, i, 0, -1, -1, 0)} ${f(0, i, 1, 0, 0, -1)} ${f(0, 0, 0, 1, 1, 0)} Z`;
|
|
98
|
+
}
|
|
99
|
+
function s(t, n, { radius: s, smoothing: c, preserveSmoothing: l, curve: u }) {
|
|
100
|
+
if (t <= 0 || n <= 0) return "M 0 0 H 0 V 0 H 0 Z";
|
|
101
|
+
if (s <= 0) return `M 0 0 H ${t} V ${n} H 0 Z`;
|
|
102
|
+
let d = Math.min(t, n) / 2, f = Math.min(s, d);
|
|
103
|
+
if (u === "squircle") {
|
|
104
|
+
if (d > f + 1e-9 && d < (1 + c) * f - 1e-9) return o(t, n, f, c, l);
|
|
105
|
+
if (Math.abs(f - d) < 1e-9) {
|
|
106
|
+
let r = a(d, c, l, Math.max(t, n) / 2);
|
|
107
|
+
if (t >= n) {
|
|
108
|
+
let i = `c ${r.A[0]} 0 ${r.AB[0]} 0 ${r.E[0]} ${r.D[0]} a ${r.r} ${r.r} 0 0 1 ${r.AX[0]} ${r.AY[0]} a ${r.r} ${r.r} 0 0 1 ${r.AX[1]} ${r.AY[0]} c ${r.C[1]} ${r.D[0]} ${r.BC[1]} ${r.D[0]} ${r.E[1]} ${r.D[0]}`, a = `c ${r.A[1]} 0 ${r.AB[1]} 0 ${r.E[1]} ${r.D[1]} a ${r.r} ${r.r} 0 0 1 ${r.AX[1]} ${r.AY[1]} a ${r.r} ${r.r} 0 0 1 ${r.AX[0]} ${r.AY[1]} c ${r.C[0]} ${r.D[1]} ${r.BC[0]} ${r.D[1]} ${r.E[0]} ${r.D[1]}`;
|
|
109
|
+
return `M ${e(r.p)} 0 L ${e(t - r.p)} 0 ${i} L ${e(r.p)} ${e(n)} ${a} Z`;
|
|
110
|
+
}
|
|
111
|
+
let i = `c 0 ${r.A[1]} 0 ${r.AB[1]} ${r.D[0]} ${r.E[1]} a ${r.r} ${r.r} 0 0 1 ${r.AY[0]} ${r.AX[1]} a ${r.r} ${r.r} 0 0 1 ${r.AY[0]} ${r.AX[0]} c ${r.D[0]} ${r.C[0]} ${r.D[0]} ${r.BC[0]} ${r.D[0]} ${r.E[0]}`, o = `c 0 ${r.A[0]} 0 ${r.AB[0]} ${r.D[1]} ${r.E[0]} a ${r.r} ${r.r} 0 0 1 ${r.AY[1]} ${r.AX[0]} a ${r.r} ${r.r} 0 0 1 ${r.AY[1]} ${r.AX[1]} c ${r.D[1]} ${r.C[1]} ${r.D[1]} ${r.BC[1]} ${r.D[1]} ${r.E[1]}`;
|
|
112
|
+
return `M 0 ${e(r.p)} ${i} L ${e(t)} ${e(n - r.p)} ${o} L 0 ${e(r.p)} Z`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let { p, segments: m } = u === "squircle" ? r(f, c, l, d) : i(f, d), h = (e) => m[e] ? " " + m[e] : "";
|
|
116
|
+
return `M ${e(p)} 0 L ${e(t - p)} 0${h("TR")} L ${e(t)} ${e(p)} L ${e(t)} ${e(n - p)}${h("BR")} L ${e(t - p)} ${e(n)} L ${e(p)} ${e(n)}${h("BL")} L 0 ${e(n - p)} L 0 ${e(p)}${h("TL")} Z`;
|
|
117
|
+
}
|
|
118
|
+
export { s as cornerPath };
|