@liqeliquid/liqe-liquid 0.0.0-stage → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 youssefahmed2017
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,388 @@
1
- # Temporary Holding Version
1
+ # Liqe-Liquid
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
+ An open-source liquid glass material and control set for the web. It bends light at its edges, keeps text readable on its own, and moves like the real thing: every number is measured from macOS 27, frame by frame, then improved where the web can do better. Status: **v0.7 preview**.
4
+
5
+ [Docs and live demos](https://youssefahmed2017.github.io/Liqe-Liquid/) · [Lab](https://youssefahmed2017.github.io/Liqe-Liquid/lab.html) · [npm](https://www.npmjs.com/package/@liqeliquid/liqe-liquid) · MIT
6
+
7
+ > Liqe-Liquid is inspired by physical optics and modern translucent interface design. It is not affiliated with, endorsed by, or sponsored by Apple Inc. All third-party trademarks belong to their respective owners.
8
+
9
+ Liqe-Liquid is an original material. It's written from scratch from public optics (refraction, specular reflection, surface tension) and from measurements of how system glass looks and moves. It does not use Apple's code, assets, names, icons, fonts, wallpapers or component layouts.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm i @liqeliquid/liqe-liquid
15
+ ```
16
+
17
+ ```js
18
+ import Liqe from '@liqeliquid/liqe-liquid'; // also sets window.Liqe
19
+ import '@liqeliquid/liqe-liquid/liqe.css'; // with a bundler that handles CSS; or link the file
20
+ Liqe.autoMount();
21
+ ```
22
+
23
+ Or from the jsDelivr CDN, no build step:
24
+
25
+ ```html
26
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@liqeliquid/liqe-liquid@0.7/source/liqe.css">
27
+ <script src="https://cdn.jsdelivr.net/npm/@liqeliquid/liqe-liquid@0.7/dist/liqe.js"></script>
28
+ ```
29
+
30
+ It needs a browser (it reads `window` and `document` when loaded), so in server-rendered apps import it on the client only.
31
+
32
+ ### Try it in one file
33
+
34
+ Save this as `test.html` and open it in Chrome. Glass needs something behind it to bend, so give the page a colourful background:
35
+
36
+ ```html
37
+ <!doctype html>
38
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@liqeliquid/liqe-liquid@0.7/source/liqe.css">
39
+ <script src="https://cdn.jsdelivr.net/npm/@liqeliquid/liqe-liquid@0.7/dist/liqe.js"></script>
40
+ <style>nav a { color: inherit; text-decoration: none; font: 600 15px system-ui, sans-serif; }</style>
41
+ <!-- data-liqe-lum: the page's average brightness (0 to 1), so Guard can pick the ink; it can't read a gradient -->
42
+ <body data-liqe-lum="0.25" style="margin:0;min-height:100vh;background:linear-gradient(120deg,#ff8a3d,#2447bd)">
43
+ <nav class="liqe" data-meniscus="native" data-ink="auto" style="margin:40px;padding:12px 24px;border-radius:99px;display:inline-flex;gap:20px">
44
+ <a href="#">Home</a> <a href="#">Docs</a>
45
+ </nav>
46
+ <script>Liqe.mount(document.querySelector('nav'), { sample: 'dom' });</script>
47
+ </body>
48
+ ```
49
+
50
+ Liqe is a browser library, not a command-line tool: install it into your project (`npm i`), not globally, and open it in a page rather than running it with Node.
51
+
52
+ ![A Liqe-Liquid button on the design site poster. The rim bends the type behind the label.](docs/images/liqe-button.png)
53
+
54
+ ## What we learned from studying translucent materials
55
+
56
+ Apple's 2025 "Liquid Glass" made a clear case for a material that **bends light at its edges** instead of only blurring it, that picks up **specular highlights** as things move, and that **adapts its tint** to what's behind it. It also showed the main weakness of this style: when the material is transparent enough to look magical, text on it can lose contrast. Users and developers have reported readability problems, and the main fix offered is a system accessibility setting (Reduce Transparency) that users have to find and switch on themselves.
57
+
58
+ Liqe-Liquid keeps the good idea (light bending at the edge) and treats the weakness as a design bug the material has to solve on its own:
59
+
60
+ | Problem seen in glass UIs | Liqe-Liquid answer |
61
+ |---|---|
62
+ | Text contrast depends on whatever is behind the glass | **Guard** measures the backdrop and tints until text passes 4.5:1 against the *worst* patch, not the average |
63
+ | Readability relies on users finding an accessibility setting | Guard is on by default; reduced transparency and calm motion are respected automatically |
64
+ | Distortion everywhere is tiring | **Meniscus**: refraction lives only in a thin edge band. The centre, where text sits, is never distorted |
65
+ | Glass stacked on glass gets muddy | One glass layer only. Glass on glass is not allowed |
66
+ | Heavy effects cost battery | **Budget**: at most 4 refracting surfaces at once; the rest fall back to blur |
67
+ | Static glass feels like a sticker | **Viscosity**: the surface stretches with drag velocity and settles on a spring |
68
+
69
+ ## The five parts
70
+
71
+ - **Meniscus**: an edge band (default 14 px) where the backdrop is pulled inward along the surface normal, like light bending through a curved rim. Profiles: `off`, `soft`, `deep`.
72
+ - **Rim light**: a thin edge highlight from a fixed key light at the upper left. (v0.3.1 removed the pointer-following hotspot and rim: it read as a gimmick, and native glass doesn't do it.)
73
+ - **Guard**: a tint layer whose opacity is computed per frame from sampled backdrop luminance, so the text colour meets the contrast target over the worst sample. Levels: `auto`, `clear`, `tint`, `frost`, `solid`.
74
+ - **Viscosity**: drag and press deform the surface (squash and stretch along the velocity direction), then a spring settles it.
75
+ - **Droplet**: a liqe control can expand into a panel from its own bounds and collapse back into it.
76
+
77
+ ![The design site's grid scene. Grid lines bend as they pass through the button.](docs/images/liqe-refraction.png)
78
+
79
+ ## Rules
80
+
81
+ 1. Glass belongs to the **chrome layer**: toolbars, tab bars, floating controls, sheets. Never to content such as articles, lists or cards.
82
+ 2. Text on glass passes **4.5:1** (body) or **3:1** (large text and icons) against the worst backdrop patch beneath it.
83
+ 3. **One layer.** No glass on glass.
84
+ 4. Refraction stays in the **meniscus band**; the centre stays optically flat.
85
+ 5. `prefers-reduced-transparency` (or `data-transparency="reduced"`) makes every surface `solid`. Calm mode (`Liqe.setCalm(true)`, e.g. from `prefers-reduced-motion`) turns off refraction movement and viscosity.
86
+ 6. At most **4** refracting surfaces on screen. Extra surfaces fall back to blur and tint.
87
+
88
+ ## Browser support
89
+
90
+ | Feature | Chromium (Chrome, Edge, Arc, Opera) | Safari | Firefox |
91
+ |---|---|---|---|
92
+ | Meniscus refraction (`backdrop-filter: url(#svg)`) | Yes | Falls back to blur | Falls back to blur |
93
+ | Blur, tint, Guard, rim light, Viscosity, Droplet | Yes | Yes | Yes |
94
+
95
+ Verified on 2026-12-02 in WebKit 605.1.15 (Safari's engine, macOS 27.2) by loading the lab off-screen: refraction correctly switches off, the blur-and-saturate fallback applies, Guard measured the label at 4.91:1, a mouse press lit the button and released cleanly, `Liqe.show()`/`hide()` are present, there's no horizontal overflow and no script errors. Firefox wasn't available to test.
96
+
97
+ Refraction uses an SVG `feDisplacementMap` generated at runtime for each surface's exact size and corner radius. That technique only works as a backdrop filter in Chromium today, so other engines get the same material without the edge bending. Edge refraction can also only bend content inside the element's own box.
98
+
99
+ ## Usage
100
+
101
+ ```html
102
+ <nav class="liqe" data-guard="auto" data-meniscus="native" data-ink="auto">
103
+ …
104
+ </nav>
105
+
106
+ <script>
107
+ Liqe.autoMount(); // mounts every .liqe on the page
108
+ // optional: let Guard read the backdrop when you control it (canvas, image, video)
109
+ Liqe.mount(document.querySelector('nav'), { sample: rect => myLuminanceSamples(rect) });
110
+ Liqe.controls(); // switches, sliders, checkboxes, radios, glass buttons
111
+ </script>
112
+ ```
113
+
114
+ Light and dark follow the page: the system setting, or `<html data-theme="light|dark">`.
115
+
116
+ ### Attributes
117
+
118
+ | Attribute | Values | Effect |
119
+ |---|---|---|
120
+ | `data-guard` | `auto` (default), `clear`, `tint`, `frost`, `solid` | Tint level. `auto` solves for the contrast target |
121
+ | `data-meniscus` | `soft` (default), `deep`, `liquid`, `panel`, `native`, `native-clear`, `thick`, `off` | Edge refraction profile. The band is capped at 60% of the half-height so the centre stays flat |
122
+ | `data-viscous` | present | Press dip and spring release |
123
+ | `data-drag` | `free`, `snap-y` | Draggable with stretch and wobble. `snap-y` docks top or bottom |
124
+ | `data-dock-gap` | px | Distance from the bottom edge when docked, e.g. to sit above a tab bar |
125
+
126
+ The base `.liqe` rule uses `:where()` (zero specificity), so your own classes always win for layout.
127
+
128
+ ### Developing
129
+
130
+ Edit `source/js/` (ES modules; `main.js` is the entry and public API) and `source/liqe.css`, then `npm run build` and `npm test`. `dist/` is generated. The lab (`lab.html`) and the docs (`index.html`) load the build directly.
131
+
132
+ Without a `sample` function, `auto` uses a conservative fixed tint (equivalent to `frost`), because a web page can't read the pixels behind an arbitrary element.
133
+
134
+ ## v0.2: perfecting one button
135
+
136
+ The current milestone is a single glass button that bends light, responds naturally, stays readable and degrades gracefully. Every later component builds on it.
137
+
138
+ ### Optics model
139
+
140
+ The rim is a convex squircle of height `thickness` over a band `bezel` px wide. For each pixel, a vertical view ray meets the tilted rim at angle θ₁, refracts by Snell's law (n₁ sin θ₁ = n₂ sin θ₂, air n₁ = 1, glass n₂ = `ior`), and shifts sideways by `thickness · tan(θ₁ − θ₂)` before reaching the backdrop. That shift, along the inward normal of a rounded-rectangle distance field, is the displacement map. The centre is flat, so it doesn't bend at all.
141
+
142
+ - **Dispersion**: the red, green and blue channels are displaced by `1 − d`, `1` and `1 + d` times the shift, then recombined. Red bends least, as in real glass.
143
+ - **Specular rim**: a second map, computed from the same normals, lights the rim facing an upper-left key light. It's stronger toward grazing angles (Fresnel-like), with a faint internal reflection on the far side.
144
+
145
+ ### Material properties (CSS custom properties, inherited)
146
+
147
+ | Property | Default (soft) | Meaning |
148
+ |---|---|---|
149
+ | `--liqe-thickness` | 18 | Rim height in px |
150
+ | `--liqe-ior` | 1.5 | Refractive index (1 = no bending) |
151
+ | `--liqe-bezel` | 16 | Rim width in px (capped at 60% of the half-height) |
152
+ | `--liqe-frost` | 3 | Blur before refraction, px |
153
+ | `--liqe-dispersion` | 0.04 | Colour split, 0–0.3 |
154
+ | `--liqe-specular` | 0.55 | Rim light strength, 0–1 |
155
+ | `--liqe-radius` | 22px | Corner radius |
156
+
157
+ ### The button
158
+
159
+ ```html
160
+ <button class="liqe liqe-button" data-guard="auto" data-press="squish" data-ripple data-magnetic>
161
+ Get started
162
+ </button>
163
+ ```
164
+
165
+ - **Crisp press (mouse and keyboard)**: the surface brightens instantly and keeps its exact size; release is instant too. This matches a measurement of a native macOS glass button (see below).
166
+ - **Squish press (touch and pen)**: flattens 6% and widens 3% (volume preserved). On release the spring overshoots, so it swells slightly before settling. A quick tap gets a push, so even a 10 ms tap visibly dips.
167
+ - **Ripple** (touch and pen): a ring of light spreads from the touch point.
168
+ - **Magnetic hover**: leans up to 4 px toward a mouse pointer. No lighting changes on hover.
169
+ - **Keyboard**: Space and Enter press and release exactly like touch. `:focus-visible` shows a 3 px ring offset 4 px.
170
+ - **Disabled**: no press, no ripple, faded.
171
+ - **Guard** keeps the label at 4.5:1 or better against the worst patch behind it.
172
+ - **Calm mode** removes the squish, swell, ripple and magnetism. **Reduced transparency** makes it solid.
173
+
174
+ ### Measured: a native macOS glass button
175
+
176
+ On 2026-12-02 we built a tiny test app on macOS 27.2 showing one system glass button (SwiftUI `.buttonStyle(.glass)`, extra-large) over a striped backdrop. The app pressed the button with posted mouse events (a 400 ms press, a 30 ms tap, an 800 ms press), and we recorded the screen at 60 fps and measured the button in every frame. This was black-box observation only; no system code or assets were used.
177
+
178
+ | | Result |
179
+ |---|---|
180
+ | Size during press | Unchanged: 206 × 72 px in every frame, no scale or squish |
181
+ | Press response | Mean brightness over the button rose from 90.6 to 107.9 (≈ +19%) within one frame |
182
+ | Release | Back to 90.6 within one frame; no spring, no overshoot |
183
+ | 30 ms tap | Lit for exactly two frames |
184
+
185
+ Not covered: hover, touch (iOS), drag, and the glass appearing or disappearing. Touch behaviour is the next thing to measure, in the iOS Simulator.
186
+
187
+ ### Tests
188
+
189
+ `npm test` runs 10 unit tests on the pure maths: zero bending in the flat centre, bending growing toward the rim, no bending at index 1, monotonic response to thickness and index, bounded edge values, outward normals, Guard choosing a passing tint, Guard tinting more over busier backdrops, and the quick-tap press curve.
190
+
191
+ What the tests don't cover yet: visual regression and real-browser interaction. The in-app test browser throttles animation frames, so motion was checked by maths, not by frame capture.
192
+
193
+ ### Reviewed and not adopted (yet)
194
+
195
+ - **Noise-based "lensing"** (`feTurbulence` into `feDisplacementMap`): that's a wobble effect, not refraction. Liqe uses geometry-driven maps.
196
+ - **Gooey metaball merging** (`feGaussianBlur` + alpha `feColorMatrix`): works on solid shapes but can't merge two backdrop-filtered glass surfaces. Real merging ("Fusion") needs one surface whose shape and displacement map come from a smooth union of two distance fields. That's the next milestone after the button.
197
+ - **Gyroscope-driven light**: device motion is blocked in many embedded contexts. The pointer drives the light for now.
198
+ - **TypeScript monorepo, WebGL/WebGPU renderers, 41 components**: sensible later. Not before the button is perfect.
199
+
200
+ ## v0.3: real glass in a real app
201
+
202
+ Built while making **Liqe FM** (`liqe-app/index.html`), a radio web app whose chrome is all Liqe glass.
203
+
204
+ ![Liqe FM. The toolbar, play control, mini player, and station dock are glass over art the page generates.](docs/images/liqe-fm.png)
205
+
206
+ - **Adaptive ink** (`data-ink="auto"`): glass stays clear and changes its *text* instead of going opaque. Guard tries light ink on a dark wash and dark ink on a light wash, keeps whichever needs less tint, and only switches when the difference is clear (no flicker). The first ink applies instantly; later changes glide over 0.35 s.
207
+ - **DOM sampler** (`Liqe.mount(el, { sample: 'dom' })`): Guard probes a 6×3 grid under the surface with `elementsFromPoint`, skipping glass. It reads `data-liqe-lum` (average) or `data-liqe-lum-grid` (an N×N patch map, so Guard sees the exact patch under each probe), or falls back to the first solid background colour.
208
+ - **Fast attack, slow release**: tint arrives within a frame or two when text is at risk, and relaxes gently afterwards. Guard runs every 50 ms.
209
+ - **`liquid` preset**, tuned to a screen recording of native macOS system glass (Spotlight, menus): heavy frost that keeps colour rich, strong rim lensing, a bright rim light, and a slightly denser wash toward the top.
210
+ - **Snappy show/hide**, from the same recording: Spotlight appears at about 106% and settles to 100% in about 0.1 s, fading in within about 50 ms, and leaves in about 0.13 s.
211
+ - **Budget counts only on-screen glass**, re-checked on scroll, so an off-screen button frees its refraction slot.
212
+
213
+ ## v0.4: matched against native Liquid Glass
214
+
215
+ Compared frame by frame with a screen recording of macOS 27.2, especially Apple's own Liquid Glass preview in System Settings (Clear setting), and checked side by side in `liqe-app/compare-vs-native.png` using `liqe-app/compare.html`.
216
+
217
+ ![The lens compare page as it renders now: glass capsules over a drawn sky, trees, and diagonal bands. The bands bend through the search capsule.](docs/images/liqe-lens.png)
218
+
219
+ - **Full-height lens** (`shape: 1`, `reach: 1`): native capsules bend straight lines into S-curves across their whole height, with only the centre line unshifted. The old squircle rim (bending hugging the edge, flat centre) is still available as `shape: 0`.
220
+ - **Depth scales with size** (`depth`): lens thickness is now a fraction of the curve's width. A fixed px thickness made larger controls look almost flat (about 2 px of shift on a 104 px capsule, against roughly a quarter of the height natively).
221
+ - **Two materials, as the OS uses them**: `liquid` (clear) for controls over content, with light frost (1.6), slight desaturation (1.15) and the full lens; `panel` for sheets, menus and sidebars, with heavy frost and a rim lens.
222
+ - **Neutral grey veil** instead of a white milky layer: native glass slightly darkens and desaturates the backdrop, so a capsule over a white cloud stays visible.
223
+ - **Fixed lighting only**: no pointer-following hotspot or rim (removed in v0.3.1).
224
+ - **Bug fix**: the CSS fallback variable `--liqe-sat` was being read as a material override, forcing saturation to 1.7 on every material. It's now `--liqe-fallback-sat`.
225
+ - **Budget** default raised to 6 on-screen refracting surfaces; small capsules are cheap, and big panels are what the budget protects.
226
+
227
+ **Deliberate difference from native**: native toolbars often put white icons on a light grey veil over bright photos (we measured about 2:1). Liqe keeps Guard: over bright content it switches to dark ink, so labels stay at 4.5:1.
228
+
229
+ ## v0.6: native materials, measured pixel by pixel
230
+
231
+ `data-meniscus="native"` (regular) and `"native-clear"` reproduce Apple's own glass (macOS 27.2). They aren't hand-tuned; they're measured.
232
+
233
+ ### How it was measured
234
+ 1. A tiny native app draws real system glass (`.glassEffect(.regular | .clear)`) in 10 shapes (capsules 36–100 pt, circles, a 260×140 rounded rect) at known positions over a swappable backdrop, and its window is captured at 1600×840 (2×).
235
+ 2. **Warp:** greyscale *position-coded* backdrops (coarse ramps plus two-phase 400 px triangle waves, each captured twice with a half-level dither) reveal, for every pixel under the glass, which backdrop pixel it sampled. Neutral greys survive colour management; outside the glass the decode is exact to 0.14 px.
236
+ 3. **Tone:** 17 flat greys (0–255) plus a checker and an unseen validation pattern.
237
+ 4. **Fitting:** the full pipeline (blur → warp → tone → rim) is simulated in NumPy and fitted to Apple's pixels, then confirmed by rendering Liqe in headless Chrome at the same 2× size and diffing pixel by pixel.
238
+
239
+ ### What Apple's glass actually does (on a flat or mid-grey backdrop)
240
+ - **Warp** depends only on the distance to the edge (radially symmetric), concentrated in a band of about 7–9 CSS px on small glass and 12–16 px on medium and large glass. It's stored as lookup tables per size, interpolated between sizes.
241
+ - **Blur:** Gaussian in sRGB, σ ≈ 5.8 px (small) → 6.5 px (100 pt) → 8 px (large rect); clear glass ≈ 13 px.
242
+ - **Regular glass has no flat veil; it has an adaptive tone curve.** Content darker than its surroundings passes almost unchanged; brighter content compresses (slope about 0.3). The whole curve slides with the local average brightness: `out = C(in − μ) − C(0) + U(μ)`, with μ a 20 px blur of the backdrop. In the SVG filter this is a `0.5·in + 0.5·(1−μ)` composite (keeps alpha at 1), two `feComponentTransfer` tables and an arithmetic composite.
243
+ - **Clear glass is linear:** `out ≈ 24 + 0.719·in` (a grey-85 veil at 28%).
244
+ - **Rim:** one device pixel just *outside* the edge, multiplicatively darker, depending on which way the edge faces. Regular: about 28% at top and bottom rising to about 42% at the sides; clear: about 0% at top and bottom, about 55% at the sides. Liqe draws it from the distance field at device resolution.
245
+ - **No drop shadow, top sheen or fixed light rim** on a flat backdrop.
246
+ - **Light appearance** (follows the page: `<html data-theme>` or the system setting). Measured with `measure/glassprobe.swift`, which rebuilds the app above; its dark captures reproduce the dark tables exactly. Regular glass turns into a milky veil that's the same at every size, `out ≈ 102 + 0.525·in`, keeping about 1.07× the colour. It's adaptive like dark glass but mirrored: brighter detail passes and darker detail compresses. That curve is the dark one mirrored, checked against the slopes of sharp in-window glass (0.58 / 0.20), not fitted. Clear glass becomes `71 + 0.678·in` (a grey-220 veil at 32%). The rim is the same dark line outside the edge at about 0.75× the strength. Guard judges contrast through the glass, so light glass lifting black to 102 counts. Control Center (`thick`) doesn't change with the appearance: measured with the Mac set to Light (21 flat and colour backdrops, real Control Center), it's `32 + 0.604·in` with white labels, the same as dark, so `thick` stays as it is. The knob lens isn't measured in light yet. Side by side: `measure/frames/light-glass-vs-macos.png`.
247
+ - **Vibrancy** (label levels on glass): measured with `glassprobe.swift` (`GP_CONTENT=1 GP_SWATCH=glyph`). Fixed colours are drawn unchanged on macOS glass; only the system's label styles are vibrant, and icons and text behave alike. Primary labels are solid ink. Secondary, tertiary and quaternary labels are the glass shifted toward the ink: +76 / +51 / +38 levels under white ink, −102 / −77 / −64 under black ink. Liqe gives `.liqe-secondary`, `.liqe-tertiary` and `.liqe-quaternary` those colours, one per surface from Guard's samples, then raises secondary to 4.5:1 and the other two to 3:1 (for icons, large text and placeholders). macOS's own secondary label is about 2:1, so Guard's floor sets the colour in practice; tertiary and quaternary usually meet at the same 3:1 grey. Not modelled: the per-pixel shift (Chrome can't blend children with a backdrop filter, and has no `plus-darker`) and the vibrant system colours (blue, red, ...). Glass also doesn't bend what sits on it, icons included: checked against a bare copy, they match within 4 grey levels.
248
+
249
+ ### Accuracy (RMS difference from Apple's capture, grey levels out of 255)
250
+ | Backdrop | Start of this round | Now |
251
+ |---|---|---|
252
+ | Checker (used for fitting) | 5.96 | 2.84 |
253
+ | Unseen validation pattern | 5.98 | 2.68 |
254
+
255
+ Clear glass is within about 0.5–1 level in its band and core (the capture's own noise is ±1). Regular glass's core is 0.6–3.5 and its band 1.3–3.8. The remaining error is mostly the outermost 1–2 device pixels at the boundary.
256
+
257
+ ## v0.7: colour, adaptive tone and liquid morphing
258
+
259
+ ### Colour
260
+ Apple's glass keeps colour: measured chroma retention is about 1.08× on small regular glass, about 1.0× on large regular glass and about 0.95× on clear glass. Liqe now tone-maps **brightness only** (the adaptive curve runs on luminance) and adds the original chroma back at the measured ratio. Clear glass gets a 1.32× saturation boost so colour survives its veil. Result: retention of 1.00–1.08× against Apple's 0.86–1.13× (Apple is slightly hue-dependent, keeping red and blue more than yellow).
261
+
262
+ ### Adaptive tone (validated on an unseen pattern)
263
+ Regular glass's curve slides with the local average brightness μ (a 20 px blur of the backdrop): `out = C(Y − μ) − C(0) + U(μ)`. On a validation backdrop the model was never fitted to, the error dropped from 5.98 to 2.70 grey levels.
264
+
265
+ ### Fusion: liquid morphing (`Liqe.group`)
266
+ Measured from native glass shapes in one container moving together and apart:
267
+ - Shapes **bulge toward each other** before touching; a **neck forms and grows** as they settle (20 → 66 px over about 0.2 s for 72 pt circles).
268
+ - On separating, the **neck stretches and then snaps** (it survives until the gap reaches about 44 device px).
269
+ - Modelled as a smooth union of rounded rectangles, `k = 0.77 × spacing`, doubled while separating. The warp, mask and rim all come from the union's distance field. Normals use the *un-normalised* gradient, so the warp fades smoothly on symmetry ridges instead of leaving a seam.
270
+ - Liqe's settled neck measures 72 px against Apple's 70.
271
+
272
+ ```js
273
+ const g = Liqe.group(el, { spacing: 16, blobs: [{ x: 2, y: 2, w: 196, h: 60 }, { x: 138, y: 2, w: 60, h: 60 }] });
274
+ g.animateTo([{ x: 2, y: 2, w: 122, h: 60 }, { x: 138, y: 2, w: 60, h: 60 }]); // splits into two
275
+ ```
276
+
277
+ ### Not reproduced, because I couldn't measure it
278
+ - Interactive glass press (`.interactive()`) and hover: macOS ignored synthetic mouse input, so no change was recorded. These are unknown, not confirmed absent.
279
+ - Clear glass at very large sizes, colour hue dependence, and behaviour over video or moving content.
280
+
281
+ ## Legal guardrails (not legal advice)
282
+
283
+ - A visual effect such as blur or refraction isn't owned by anyone, but names, logos, icons, specific product layouts and trade dress can be. So:
284
+ - Never call this "Liquid Glass" or describe it as Apple's material.
285
+ - Never ship Apple icons (SF Symbols), fonts (SF Pro), wallpapers, screenshots or copies of Apple app layouts.
286
+ - Write all code from scratch; don't port code from Apple frameworks or copy third-party demos without checking their license.
287
+ - Before a commercial launch, run a trademark search on "Liqe-Liquid", and have a lawyer review it.
288
+
289
+ ## Control Center glass (`data-meniscus="thick"`), measured
290
+
291
+ Measured on macOS 27.2 by showing phase-shifted sine patterns, greys, colours, a checkerboard and stripes full screen behind the real Control Center and decoding every pixel (4-step phase shift, hierarchical unwrap). All numbers are in device pixels on a 2x display unless noted.
292
+
293
+ - **Tile geometry**: exact whole CSS pixels: 140×64, 64×64, 140×140, 292×64. A one-pixel dark line sits just *outside* the left and right edges.
294
+ - **Outline**: Apple-style continuous corners. The straight edge starts to curve 1.52866 r from the corner and comes in through three cubic Béziers, with no jump in curvature. r is the CSS radius (32 for toggles and the 140×140 tile, 24 for sliders). Round 64×64 buttons stay true circles, because neither side can hold that run. Liqe clips the glass to this outline inside the filter, under the slightly larger circular `border-radius`.
295
+ - **Warp**: a fixed absolute bezel, identical on all ten tiles to within about 1 px. The inward shift is 133 px at the edge, then 110 px at depth 1.5, 75 at 4.5, 47 at 8.5, 28.5 at 12.5, 7 at 20.5, and 0 by 28 (14 CSS px). The warp's own distance field is the circular one.
296
+ - **Blur**: Gaussian σ 3 CSS px, applied before the warp. Two-Gaussian mixes scored worse.
297
+ - **Tone**: luminance becomes 32/255 + 0.61·Y; colour around it is multiplied by 1.08.
298
+ - **Rim light**: out = in·(1 + L) + 0.85·L, where L depends on depth and edge direction. On edges facing up or down, L is 0.38 at the outer pixel, 0.21 at the next and 0.07 at the third, fading out by about 16 px. On edges facing sideways, L is 0.
299
+ - **Side hairline**: the backdrop outside the edge is multiplied by 1 − 0.6·|nx|⁵.
300
+
301
+ Scored against the real captures, with the tiles' own icons and labels masked out (RMS, 0–255):
302
+
303
+ | Backdrop | Warp band | Interior |
304
+ |---|---|---|
305
+ | greys | 0.6 | 0.6 |
306
+ | red | 0.8 | 0.4 |
307
+ | blue | 0.9 | 0.6 |
308
+ | stripes | 1.6 | 1.4 |
309
+ | checker | 5.8 | 4.6 |
310
+
311
+ Rim pixels (0–3 px): 12–13 on greys, down from 23 before the corner and geometry fixes.
312
+
313
+ ### Appear / dismiss (`Liqe.show()` / `Liqe.hide()` on `thick` glass), measured
314
+
315
+ Recorded at 60 fps on macOS 27.2: phase-shifted sine gratings (periods 512 and 96 px) behind the real Control Center, 3 runs for each direction, aligned on the first frame that changes. Tooling is in `measure/` (`rec_cc.py`, `warp_anim.py`).
316
+
317
+ - **No scale and no slide.** The panel stays where it is.
318
+ - **The lens grows instead of fading.** The warp keeps its shape and scales in strength and width together: `D(d,t) = λ(t)·D(d/λ(t))`, fit error ≤ 0.6 px.
319
+ - Open λ per frame: 0, 0, .045, .18, .33, .48, .605, .72, .775, .835, .88, .915, .94, .955, .97, .98, .985, .99, .995 → 1 (about 350 ms).
320
+ - Close λ: 1, .975, .865, .725, .58, .45, .34, .25, .185, .135, .095, .07, .05, .04, 0 (about 233 ms, ×0.74 per frame).
321
+ - **Glass and content opacity α.**
322
+ - Open: α is λ one frame later.
323
+ - Close: 1, .974, .879, .703, .491, .374, .276, .182, .135, .089, .065, .045, .03, .02, 0.
324
+ - The rim light follows α².
325
+ - **Blur.**
326
+ - Open: full strength from the first frame.
327
+ - Close: gone on the first frame, so the leaving glass is sharp.
328
+
329
+ Implementation: `pose(s, λ, α, closing)` swaps a displacement map per λ (quantised to 1/40 and cached, about 7 ms to build), mixes the glass over the backdrop in the filter, and sets `--liqe-appear` for the tint, veil, rim and children. `measure/anim_pose.html?lam=&a=&c=` renders any single pose.
330
+
331
+ ## Controls (`Liqe.controls(root)`), measured from native macOS 27 controls
332
+
333
+ ![The control set on the design site, light appearance: switches, sliders, tick marks, vertical sliders, checkbox, radio, segmented control, push buttons, and a progress bar.](docs/images/liqe-controls.png)
334
+
335
+ Markup is plain HTML inputs, so keyboard and screen readers work as usual:
336
+
337
+ ```html
338
+ <input type="checkbox" class="liqe-switch"> <!-- add liqe-switch--small for the small size -->
339
+ <input type="range" class="liqe-slider" min="0" max="100" value="40">
340
+ <input type="range" class="liqe-slider" orient="vertical" min="0" max="100" value="50"> <!-- or writing-mode: vertical-lr; direction: rtl -->
341
+ <input type="range" class="liqe-slider" list="ticks" min="0" max="100" value="60"> <!-- tick dots at each <datalist id="ticks"> value -->
342
+ <button class="liqe-glass-btn liqe-glass-btn--capsule">Capsule</button> <!-- glass push button; drop --capsule for radius 5 -->
343
+ <button class="liqe-glass-btn liqe-glass-btn--prominent">Prominent</button>
344
+ <label><input type="checkbox" class="liqe-check"> Snap to grid</label>
345
+ <label><input type="radio" name="r" class="liqe-radio"> Fit</label>
346
+ <div class="liqe-segmented" role="radiogroup"><label><input type="radio" name="s"><span>Day</span></label>…</div>
347
+ <button class="liqe-push">Cancel</button> <button class="liqe-push liqe-push--default">Save</button>
348
+ <progress class="liqe-progress" max="100" value="45"></progress>
349
+ ```
350
+
351
+ How it was measured: `measure/ctlprobe.swift` is a native window holding NSSwitch, NSSlider, checkbox, radio, segmented, push and progress controls. It presses its own controls with posted events, never the real cursor, and records itself losslessly at 60 fps through ScreenCaptureKit. Grating backdrops behind the window gave the lens field.
352
+
353
+ - **Rest state** (dark appearance, sRGB), RMS against the real 2× capture:
354
+
355
+ | Control | RMS | Size and colour |
356
+ |---|---|---|
357
+ | Switch | 4.7–5.5 | track 54×24, knob 32×20, travel 18; on `#137cff`; track white at 9.8% |
358
+ | Slider | 4.4 | track 6 px, knob 20×16 |
359
+ | Checkbox (off / on) | 0.9 / 9.5 | 16 px, radius 5 |
360
+ | Radio | 0.5–7.7 | 16 px |
361
+ | Segmented | 12.7 | 24 px high, radius 6, `#2f2f2f`, selected `#117dff` |
362
+ | Push button | 8.7 | 24 px high, radius 6 |
363
+ | Progress bar | 3.9 | 8 px capsule |
364
+
365
+ - **Only the switch and slider knobs are glass.** Pressed, the white face fades while the knob grows into a lens.
366
+ - Switch lens: 52×33 (×1.63), over about 200 ms.
367
+ - Slider lens: 26×21.5 (×1.3), over about 120 ms.
368
+ - Vertical slider: the horizontal one turned 90°, filling from the bottom (knob 16×20, lens 21.5×26). The vertical NSSlider was recorded beside the horizontal one with the same posted presses: knob size, lens size, and press and release timing matched frame for frame. Its lens lighting does not turn: the milky gradient and rim light stay on the up- and down-facing edges. Drag-follow and squash reuse the horizontal fits. Scored on both axes with the same tracker, they agree: slow drags give rms 4.9–5.9 device px vertical against 4.9 horizontal, and quick drags give 14.6–15.9 against 15.6. Quick drags misfit equally on both axes, which is a limit of the follow model. These runs were recorded with ffmpeg through `measure/rec_slider.py`, because ctlprobe's own ScreenCaptureKit recorder reached only about 30 fps in Low Power Mode. Frames: `measure/frames/slider-vertical-frames.png`.
369
+ - Slider fill: it ends at the lens centre and trails with it, except at the ends. When the value reaches max, the blue fills to the track end in that frame, even while the lens is still on its way. At min it empties completely. The white knob hides this at rest, so it only shows through the pressed glass. Measured from a 60 fps recording of the vertical NSSlider.
370
+ - Tick marks: one 2 px round dot per `<datalist>` value, at the knob centre's stops, 7 px from the track's centre line (below it, or right of it when vertical). White 25% in dark, black 26% in light. Measured from stills of NSSlider with `numberOfTickMarks = 11`, horizontal and vertical (`measure/frames/slider-ticks.png`).
371
+ - Glass push buttons (`.liqe-glass-btn`, `--capsule`, `--prominent`): NSButton bezelStyle `.glass` in ctlprobe. Look from 2x stills (Display P3 converted to sRGB) and a 60 fps hand-driven screen recording, dark and light: 24 px high, a regular 13 px label with 12 px either side, a flat veil over a 1 px blur, a bright lip on the top and bottom edges, a dark hairline outside the sides and slightly darker mid-height. Hover and press change brightness under the label: hover ×1.33 grey / ×1.18 blue in dark, ×0.956 / ×0.90 in light; press adds ×1.10 plus a gaussian light around the pointer that follows it while held, and grows the button 3 × 1 px. On release the light fades with a ~130 ms time constant. Not modelled: edge refraction and Guard, so labels only meet 4.5:1 on flat page colours. The Prominent blue measured from macOS (white on about #0080ff) reaches about 3.9:1. Recorded with `measure/rec_button.py` and ctlprobe's Light / Dark button; side by side: `measure/frames/glass-buttons-vs-macos.png`.
372
+ - Checkbox, radio and segmented stay flat, as on the Mac. They only tint while pressed.
373
+ - **The knob lens (`data-meniscus="knob"`) pulls the backdrop outward** and shows a shrunken view, about 0.75 at the centre line.
374
+ - Outward pull: 0 on the ring, peaking at 9 device px at 7 px depth, then easing linearly to 0 at the centre.
375
+ - No blur and no tint.
376
+ - The ring is 2 device px of black at 50%, darker on the sides.
377
+ - Inside it, a white line at 21% fades to nothing over about 6 px, on edges facing up or down only.
378
+ - The slider's lens is milky, with white at 15% → 7.5%, and nearly flat.
379
+ - The element reaches 6 px past the lens (`--liqe-inset`), so the outward pull has backdrop to sample. `clip-path` trims it back.
380
+ - **Timing**, per 60 fps frame from the mouse event:
381
+ - Switch press: white face 1 → 0 by 211 ms; lens growth starts at about 95 ms and ends at 194 ms.
382
+ - Switch release: lens shrinks over 65–190 ms; white returns over 65–275 ms.
383
+ - Slide: spring with ω 11.5 and ζ 0.69, about 4% overshoot.
384
+ - A quick click only dips the white to about 0.8 and never grows the lens.
385
+
386
+ ## License
387
+
388
+ MIT © 2026 youssefahmed2017. See [LICENSE](LICENSE).