@glass-sdk/liquid-glass 0.0.0-stage → 0.0.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 +21 -0
- package/README.md +596 -2
- package/dist/concentric-COCiG9DQ.js +179 -0
- package/dist/core.js +9 -0
- package/dist/dom-CKc8vDTR.js +2532 -0
- package/dist/dom.js +2 -0
- package/dist/gpu-Co5Y89mh.js +244 -0
- package/dist/gpu.js +2 -0
- package/dist/index.js +933 -0
- package/dist/map-encoder.worker-DO1drw0Y.js +16 -0
- package/dist/materials-DVPgteZ9.js +234 -0
- package/dist/styles.css +341 -0
- package/dist/styles.d.css.ts +2 -0
- package/dist/types/core/concentric.d.ts +32 -0
- package/dist/types/core/index.d.ts +10 -0
- package/dist/types/core/materials.d.ts +43 -0
- package/dist/types/core/morph-path.d.ts +110 -0
- package/dist/types/core/optics.d.ts +2 -0
- package/dist/types/core/progressive.d.ts +17 -0
- package/dist/types/core/shape.d.ts +16 -0
- package/dist/types/core/spring.d.ts +60 -0
- package/dist/types/core/union.d.ts +20 -0
- package/dist/types/dom/control-motion.d.ts +13 -0
- package/dist/types/dom/filter-bounds.d.ts +30 -0
- package/dist/types/dom/filter-patch.d.ts +9 -0
- package/dist/types/dom/fixed-shape.d.ts +3 -0
- package/dist/types/dom/foreground.d.ts +20 -0
- package/dist/types/dom/index.d.ts +61 -0
- package/dist/types/dom/interaction.d.ts +16 -0
- package/dist/types/dom/map-encoder.d.ts +5 -0
- package/dist/types/dom/map-encoder.worker.d.ts +1 -0
- package/dist/types/dom/map-encoding.d.ts +5 -0
- package/dist/types/dom/map-image.d.ts +14 -0
- package/dist/types/dom/map-store.d.ts +22 -0
- package/dist/types/dom/maps.d.ts +31 -0
- package/dist/types/dom/morph.d.ts +70 -0
- package/dist/types/dom/png.d.ts +7 -0
- package/dist/types/dom/progressive-maps.d.ts +6 -0
- package/dist/types/dom/progressive.d.ts +14 -0
- package/dist/types/dom/selection.d.ts +5 -0
- package/dist/types/dom/shape-layout.d.ts +29 -0
- package/dist/types/dom/ticker.d.ts +36 -0
- package/dist/types/dom/warm.d.ts +14 -0
- package/dist/types/gpu/index.d.ts +48 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/react/control-thumb.d.ts +11 -0
- package/dist/types/react/index.d.ts +155 -0
- package/dist/types/react/merged-ref.d.ts +3 -0
- package/dist/types/react/shape.d.ts +23 -0
- package/dist/types/react/value-control-motion.d.ts +9 -0
- package/dist/types/react/value-controls.d.ts +20 -0
- package/package.json +80 -4
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ShapePoint } from "./concentric.js";
|
|
2
|
+
import type { GlassRadius } from "./shape.js";
|
|
3
|
+
/** A box in any shared coordinate space. */
|
|
4
|
+
export interface Box {
|
|
5
|
+
left: number;
|
|
6
|
+
top: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
/** A rounded box: the outline of glass in motion. */
|
|
11
|
+
export interface MorphShape extends Box {
|
|
12
|
+
radius: number;
|
|
13
|
+
}
|
|
14
|
+
/** A shape whose maps can be prepared: dimensions, corners, and an optional
|
|
15
|
+
* traced outline in the shape's own box. */
|
|
16
|
+
export interface MorphGeometry {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
radius: GlassRadius;
|
|
20
|
+
outline?: ShapePoint[];
|
|
21
|
+
/** Map density. Resting shapes match their surface exactly; shapes passed
|
|
22
|
+
* through in motion use one pixel per CSS pixel. */
|
|
23
|
+
dpr?: number;
|
|
24
|
+
/** A resting shape, whose maps are worth keeping across loads. */
|
|
25
|
+
resting?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const mix: (a: number, b: number, t: number) => number;
|
|
28
|
+
export declare function smoothstep(edge0: number, edge1: number, x: number): number;
|
|
29
|
+
/** Pixel radius of a declared glass shape at a given size. */
|
|
30
|
+
export declare function radiusPixels(radius: GlassRadius | string | null | undefined, width: number, height: number): number;
|
|
31
|
+
/** How far apart two shapes are: relative size, then corners. */
|
|
32
|
+
export declare function shapeDistance(a: {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
radius: GlassRadius;
|
|
36
|
+
}, b: {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
radius: GlassRadius;
|
|
40
|
+
}): number;
|
|
41
|
+
/** Gap between two boxes, or zero when they overlap. */
|
|
42
|
+
export declare const boxGap: (a: Box, b: Box) => number;
|
|
43
|
+
/** Where glass grows from and where it grows to. */
|
|
44
|
+
export interface MorphEndpoints {
|
|
45
|
+
from: Box;
|
|
46
|
+
fromRadius: GlassRadius;
|
|
47
|
+
to: Box;
|
|
48
|
+
toRadius: GlassRadius;
|
|
49
|
+
/** The axis the surface opens along leads the growth; the other follows.
|
|
50
|
+
* Undefined: both axes move together, as for a layout change. */
|
|
51
|
+
along?: "x" | "y";
|
|
52
|
+
}
|
|
53
|
+
/** The axis along which `to` lies beyond `from`: the direction a popup opens. */
|
|
54
|
+
export declare function openingAxis(from: Box, to: Box): "x" | "y";
|
|
55
|
+
/** The outline at progress `p` along the path: it leaves its source with
|
|
56
|
+
* fully rounded, drop-like corners, stretches along the opening axis before
|
|
57
|
+
* it widens, and only takes its final corners once it has nearly arrived. */
|
|
58
|
+
export declare function morphShape(e: MorphEndpoints, p: number): MorphShape;
|
|
59
|
+
/** Visibility of a popup's content: it appears once the glass has room. */
|
|
60
|
+
export declare const contentReveal: (p: number) => number;
|
|
61
|
+
/** How far the source's own content has withdrawn into the glass that left it. */
|
|
62
|
+
export declare const sourceConceal: (p: number) => number;
|
|
63
|
+
/** How far apart a drop and its glass can be and still flow together; the
|
|
64
|
+
* neck thins as the drop reaches its place, so it pinches off and rests as
|
|
65
|
+
* its own shape even right beside its source. */
|
|
66
|
+
export declare const neckWidth: (p: number, neck: number) => number;
|
|
67
|
+
/** One prepared shape on the path. */
|
|
68
|
+
export interface MorphStop {
|
|
69
|
+
p: number;
|
|
70
|
+
shape: MorphGeometry;
|
|
71
|
+
/** Drawn in this box rather than stretched to the live outline: a traced
|
|
72
|
+
* union, or the glass a drop is still inside. */
|
|
73
|
+
box?: Box;
|
|
74
|
+
/** Draws the source glass as part of itself. */
|
|
75
|
+
absorbs: boolean;
|
|
76
|
+
}
|
|
77
|
+
export interface MorphPlanOptions {
|
|
78
|
+
/** Shapes prepared between the endpoints. */
|
|
79
|
+
stops?: number;
|
|
80
|
+
/** Union samples while a drop is joined to its glass. */
|
|
81
|
+
unions?: number;
|
|
82
|
+
/** Neck reach in pixels. */
|
|
83
|
+
neck?: number;
|
|
84
|
+
/** Map density of the shapes in motion. */
|
|
85
|
+
dpr?: number;
|
|
86
|
+
/** Map density of the resting endpoints. */
|
|
87
|
+
restDpr?: number;
|
|
88
|
+
}
|
|
89
|
+
/** The glass a drop detaches from. `width` and `height` are its layout size
|
|
90
|
+
* and `radius` its declared corners, so its stop matches its own resting map. */
|
|
91
|
+
export interface MorphGlass extends Box {
|
|
92
|
+
radius: GlassRadius;
|
|
93
|
+
layoutWidth: number;
|
|
94
|
+
layoutHeight: number;
|
|
95
|
+
}
|
|
96
|
+
/** Plan the shapes an animation passes through, so their maps can be
|
|
97
|
+
* prepared together before it starts. Stops are spaced evenly by how much
|
|
98
|
+
* the shape changes between them; the endpoints are exact. A drop leaving
|
|
99
|
+
* glass adds the traced unions of the two while they are joined, beginning
|
|
100
|
+
* with the glass's own shape while the drop is still inside it. */
|
|
101
|
+
export declare function planMorph(e: MorphEndpoints, glass: MorphGlass | undefined, options?: MorphPlanOptions): MorphStop[];
|
|
102
|
+
/** What to draw at progress `p`: the two stops around it and their blend,
|
|
103
|
+
* plus how much of the source glass the frame draws in its place. */
|
|
104
|
+
export interface MorphDraw {
|
|
105
|
+
a: MorphStop;
|
|
106
|
+
b?: MorphStop;
|
|
107
|
+
mix: number;
|
|
108
|
+
absorb: number;
|
|
109
|
+
}
|
|
110
|
+
export declare function morphDraw(stops: readonly MorphStop[], p: number): MorphDraw | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type GlassBlurEdge = "top" | "bottom" | "inline-start" | "inline-end";
|
|
2
|
+
export type PhysicalEdge = "top" | "bottom" | "left" | "right";
|
|
3
|
+
export interface ProgressiveBlurOptions {
|
|
4
|
+
/** Edge where blur is strongest. Default: bottom. */
|
|
5
|
+
edge?: GlassBlurEdge;
|
|
6
|
+
/** Depth in CSS pixels. Default: 80. Clamped to half the viewport for scroll edges. */
|
|
7
|
+
size?: number;
|
|
8
|
+
/** Maximum Gaussian standard deviation in CSS pixels. Default: 20. */
|
|
9
|
+
blur?: number;
|
|
10
|
+
/** Maximum optical travel in CSS pixels. Default: 0. */
|
|
11
|
+
refraction?: number;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function validateProgressive(options: ProgressiveBlurOptions): void;
|
|
15
|
+
export declare function physicalEdge(edge: GlassBlurEdge, rtl: boolean): PhysicalEdge;
|
|
16
|
+
/** Clamp Safari rubber-banding; RTL scrollLeft is negative in modern engines. */
|
|
17
|
+
export declare function scrollEdgeStrength(edge: PhysicalEdge, left: number, top: number, maxX: number, maxY: number, rtl: boolean, size: number): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SmoothCornerOptions } from "@lisse/core";
|
|
2
|
+
/** A fixed continuous corner, a continuous capsule, or a circular cap. */
|
|
3
|
+
export type GlassRadius = number | "capsule" | "circle";
|
|
4
|
+
export declare function cornerOptions(radius: GlassRadius): SmoothCornerOptions;
|
|
5
|
+
export declare function shapePath(width: number, height: number, radius: GlassRadius): string;
|
|
6
|
+
export declare function shapeClip(width: number, height: number, radius: GlassRadius): string;
|
|
7
|
+
type Point = [number, number];
|
|
8
|
+
/** Tessellate Lisse's SVG path for the WGSL distance field. This is the same
|
|
9
|
+
* outline used by the DOM, not a second corner formula. Uniform shapes are
|
|
10
|
+
* symmetric, so the GPU only needs the top-right quadrant. */
|
|
11
|
+
export declare function shapePolygon(width: number, height: number, radius: GlassRadius): Point[];
|
|
12
|
+
export declare function shapeSegments(width: number, height: number, radius: GlassRadius): {
|
|
13
|
+
segments: number[][];
|
|
14
|
+
count: number;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** A spring described the way SwiftUI describes one: perceptual duration in
|
|
2
|
+
* seconds and bounce from 0 (critically damped) to just under 1. */
|
|
3
|
+
export interface SpringOptions {
|
|
4
|
+
duration: number;
|
|
5
|
+
bounce: number;
|
|
6
|
+
}
|
|
7
|
+
/** Named springs shared by every glass interaction, so motion reads as one material. */
|
|
8
|
+
export declare const springs: {
|
|
9
|
+
/** The material catching a finger or pointer. */
|
|
10
|
+
readonly press: {
|
|
11
|
+
readonly duration: 0.24;
|
|
12
|
+
readonly bounce: 0.2;
|
|
13
|
+
};
|
|
14
|
+
/** Letting go: gel-like overshoot back to rest. */
|
|
15
|
+
readonly release: {
|
|
16
|
+
readonly duration: 0.5;
|
|
17
|
+
readonly bounce: 0.42;
|
|
18
|
+
};
|
|
19
|
+
/** Light settling into and out of the material. */
|
|
20
|
+
readonly glow: {
|
|
21
|
+
readonly duration: 0.42;
|
|
22
|
+
readonly bounce: 0;
|
|
23
|
+
};
|
|
24
|
+
/** Glass growing out of, or back into, another shape. */
|
|
25
|
+
readonly morph: {
|
|
26
|
+
readonly duration: 0.42;
|
|
27
|
+
readonly bounce: 0.18;
|
|
28
|
+
};
|
|
29
|
+
/** A surface flowing to a new layout. */
|
|
30
|
+
readonly layout: {
|
|
31
|
+
readonly duration: 0.4;
|
|
32
|
+
readonly bounce: 0.16;
|
|
33
|
+
};
|
|
34
|
+
/** A selection lens following a drag. */
|
|
35
|
+
readonly track: {
|
|
36
|
+
readonly duration: 0.18;
|
|
37
|
+
readonly bounce: 0;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/** One damped harmonic oscillator. Retargeting keeps the current velocity, so
|
|
41
|
+
* every animation built on it can be interrupted and reversed mid-flight. */
|
|
42
|
+
export declare class Spring {
|
|
43
|
+
value: number;
|
|
44
|
+
velocity: number;
|
|
45
|
+
target: number;
|
|
46
|
+
private stiffness;
|
|
47
|
+
private damping;
|
|
48
|
+
constructor(value: number, options: SpringOptions);
|
|
49
|
+
configure({ duration, bounce }: SpringOptions): this;
|
|
50
|
+
/** Move to `value` immediately and stop. */
|
|
51
|
+
jump(value: number): this;
|
|
52
|
+
get settled(): boolean;
|
|
53
|
+
/** Advance by `dt` seconds with the closed-form solution; large frames stay stable. */
|
|
54
|
+
step(dt: number): this;
|
|
55
|
+
}
|
|
56
|
+
/** Seconds until a spring released from `from` toward `to` with `velocity`
|
|
57
|
+
* comes to rest, or stays within `precision` (a fraction of the travel). */
|
|
58
|
+
export declare function settleTime(options: SpringOptions, from: number, to: number, velocity?: number, precision?: number): number;
|
|
59
|
+
/** iOS-style rubber band: follows a short drag, then resists without a hard stop. */
|
|
60
|
+
export declare function rubberBand(offset: number, limit: number, coefficient?: number): number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ShapePoint } from "./concentric.js";
|
|
2
|
+
/** An axis-aligned rounded rectangle in any shared coordinate space. */
|
|
3
|
+
export interface RoundRect {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
radius: number;
|
|
9
|
+
}
|
|
10
|
+
/** Signed distance to a rounded rectangle: negative inside. */
|
|
11
|
+
export declare function roundRectDistance(px: number, py: number, r: RoundRect): number;
|
|
12
|
+
/** Polynomial smooth minimum: shapes closer than `k` flow into each other. */
|
|
13
|
+
export declare function smoothMin(a: number, b: number, k: number): number;
|
|
14
|
+
/** Twice the signed area; positive for the clockwise-on-screen winding the
|
|
15
|
+
* renderer expects (top edge left to right, with y pointing down). */
|
|
16
|
+
export declare function windingArea(points: readonly ShapePoint[]): number;
|
|
17
|
+
/** Outlines of the smooth union of rounded rectangles, traced with marching
|
|
18
|
+
* squares at `step` pixels. Returns one loop per connected body, wound the way
|
|
19
|
+
* the renderer expects and simplified to at most `limit` edges each. */
|
|
20
|
+
export declare function smoothUnion(shapes: readonly RoundRect[], k: number, step?: number, limit?: number): ShapePoint[][];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GlassMotion } from "./interaction.js";
|
|
2
|
+
/** Motion options for native-style value controls. */
|
|
3
|
+
export interface ControlMotionOptions {
|
|
4
|
+
/** Override the scene's motion level. */
|
|
5
|
+
motion?: GlassMotion;
|
|
6
|
+
/** Lift the thumb into glass under a press. Default: true. */
|
|
7
|
+
interactive?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Advance visible thumbs before the scene samples their optical geometry.
|
|
10
|
+
* Returns whether any thumb in the scene is still moving. */
|
|
11
|
+
export declare function updateControlMotion(root: HTMLElement, now: number): boolean;
|
|
12
|
+
/** Controls have their own measured geometry; generic button press scaling must not compound it. */
|
|
13
|
+
export declare function attachNativeControlMotion(element: HTMLElement, motion: GlassMotion, interactive: boolean): () => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Bounds of the source and every optical surface, including transformed controls. */
|
|
2
|
+
export interface FilterBounds {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function filterBounds(width: number, height: number, surfaces: readonly FilterBounds[], padding: number): FilterBounds;
|
|
9
|
+
export interface EdgeSides {
|
|
10
|
+
left: boolean;
|
|
11
|
+
top: boolean;
|
|
12
|
+
right: boolean;
|
|
13
|
+
bottom: boolean;
|
|
14
|
+
/** Corners some region reaches past on both of its sides, indexed [x][y] as 0 or 2. */
|
|
15
|
+
corners: Set<string>;
|
|
16
|
+
}
|
|
17
|
+
/** Which content edges, and which corners, a sampled region crosses. */
|
|
18
|
+
export declare function crossedSides(width: number, height: number, regions: readonly FilterBounds[]): EdgeSides;
|
|
19
|
+
/** Edge tiles that extend the live source past its sides by repeating its
|
|
20
|
+
* edge pixels, like a clamp-to-edge sampler. Only the sides and corners some
|
|
21
|
+
* surface samples past are produced; a scene whose glass stays inside its
|
|
22
|
+
* content needs none. Each tile is a named result a surface merges into its
|
|
23
|
+
* own cropped backdrop, so no full-size extended copy of the source is ever
|
|
24
|
+
* built or re-evaluated. */
|
|
25
|
+
export declare function edgeTiles(width: number, height: number, bounds: FilterBounds, prefix: string, sides: EdgeSides): {
|
|
26
|
+
markup: string;
|
|
27
|
+
names: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
/** The tile keys a region needs: its crossed sides, and the corners of two crossed sides. */
|
|
30
|
+
export declare function tilesFor(width: number, height: number, r: FilterBounds): string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Keep SVG filters as retained elements. Each frame's markup is parsed into
|
|
2
|
+
* an inert template and compared with the live filters: matching filters only
|
|
3
|
+
* have changed attributes written, so image primitives keep their loaded
|
|
4
|
+
* images and filter references stay valid. Rebuilding filter markup instead
|
|
5
|
+
* makes every image reload asynchronously, which shows as the material
|
|
6
|
+
* blinking for a frame whenever a surface animates. Image primitives name
|
|
7
|
+
* their map with a short `data-map` token, resolved to its URL only when the
|
|
8
|
+
* map changes. */
|
|
9
|
+
export declare function patchFilters(defs: Element, markup: readonly string[], resolve: (token: string) => string | undefined): (id: string) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MaterialOptions } from "../core/materials.js";
|
|
2
|
+
import type { MaterialMaps } from "./maps.js";
|
|
3
|
+
export interface ForegroundLens {
|
|
4
|
+
element: HTMLElement;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
w: number;
|
|
8
|
+
h: number;
|
|
9
|
+
opacity: number;
|
|
10
|
+
options: MaterialOptions;
|
|
11
|
+
maps?: MaterialMaps;
|
|
12
|
+
}
|
|
13
|
+
/** Compare sibling stacking branches before falling back to document order. */
|
|
14
|
+
export declare function comparePaintOrder(a: HTMLElement, b: HTMLElement): number;
|
|
15
|
+
export declare function overlaps(a: Pick<ForegroundLens, "x" | "y" | "w" | "h">, b: Pick<ForegroundLens, "x" | "y" | "w" | "h">): boolean;
|
|
16
|
+
/** Filter live foreground DOM through higher lenses, without repainting their rims.
|
|
17
|
+
* Transparent input must stay transparent: unlike the backdrop pass, no edge
|
|
18
|
+
* extension or opaque material fill belongs in this foreground contribution.
|
|
19
|
+
*/
|
|
20
|
+
export declare function foregroundFilter(id: string, target: ForegroundLens, overlays: readonly ForegroundLens[]): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { GlassMotion, SurfaceAnimator } from "./interaction.js";
|
|
2
|
+
import type { GlassMorph } from "./morph.js";
|
|
3
|
+
export { attachInteraction, resolveMotion } from "./interaction.js";
|
|
4
|
+
export type { GlassMotion, SurfaceAnimator } from "./interaction.js";
|
|
5
|
+
export { attachGeometryMotion, radiusPixels } from "./morph.js";
|
|
6
|
+
export { attachSelectionLens } from "./selection.js";
|
|
7
|
+
export type { GeometryAnimator, GeometryMotionOptions, GlassMorph, LensFrame, LensPlacement, LensWaypoint } from "./morph.js";
|
|
8
|
+
import type { ScrollEdgesOptions } from "./progressive.js";
|
|
9
|
+
import type { ProgressiveBlurOptions } from "../core/progressive.js";
|
|
10
|
+
export type { ScrollEdgesOptions, GlassScrollTarget } from "./progressive.js";
|
|
11
|
+
import type { MaterialOptions } from "../core/materials.js";
|
|
12
|
+
export { getMaterialMaps, clearMaterialMapCache } from "./maps.js";
|
|
13
|
+
export type { MaterialMaps } from "./maps.js";
|
|
14
|
+
export interface GlassDiagnostic {
|
|
15
|
+
surfaces: number;
|
|
16
|
+
maps: number;
|
|
17
|
+
mapTime: number;
|
|
18
|
+
error?: Error;
|
|
19
|
+
}
|
|
20
|
+
export interface GlassSceneOptions {
|
|
21
|
+
onDiagnostic?: (diagnostic: GlassDiagnostic) => void;
|
|
22
|
+
maxSurfaces?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Material plus the motion a registered surface takes part in. */
|
|
25
|
+
export interface SurfaceOptions extends MaterialOptions {
|
|
26
|
+
/** React to touch and pointer input: grow, stretch toward a drag, settle with
|
|
27
|
+
* overshoot, and light up beneath the pointer. */
|
|
28
|
+
interactive?: boolean;
|
|
29
|
+
/** Grow out of this element when registered, and back into it when Base UI
|
|
30
|
+
* marks the popup with `data-ending-style`. */
|
|
31
|
+
morphFrom?: () => Element | null | undefined;
|
|
32
|
+
/** `become`: the source's glass is this surface, and withdraws its own
|
|
33
|
+
* content while the surface is present. `detach`: this surface leaves the
|
|
34
|
+
* source's glass as a drop, joined by a liquid neck until they part.
|
|
35
|
+
* Default: a glass source is become; a source inside glass, such as a
|
|
36
|
+
* toolbar button, is detached from. */
|
|
37
|
+
morph?: GlassMorph;
|
|
38
|
+
/** Spring the glass outline when the surface's layout box changes. */
|
|
39
|
+
fluid?: boolean;
|
|
40
|
+
/** Motion level for this surface. System reduced motion always applies. */
|
|
41
|
+
motion?: GlassMotion;
|
|
42
|
+
/** Neck reach of a detaching drop in pixels; `0` grows a plain shape. */
|
|
43
|
+
neck?: number;
|
|
44
|
+
/** Grow out of `morphFrom` when registered. `false` only runs the exit. */
|
|
45
|
+
morphEnter?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface GlassSceneController {
|
|
48
|
+
setContent(element: HTMLElement | null): void;
|
|
49
|
+
addSurface(element: HTMLElement, options?: SurfaceOptions): () => void;
|
|
50
|
+
/** Live DOM above the backdrop that must pass through overlapping glass. */
|
|
51
|
+
addForeground(element: HTMLElement): () => void;
|
|
52
|
+
/** Step an animation each frame before the scene samples glass geometry. */
|
|
53
|
+
addAnimator(animator: SurfaceAnimator): () => void;
|
|
54
|
+
addProgressiveBlur(element: HTMLElement, options?: ProgressiveBlurOptions): () => void;
|
|
55
|
+
addScrollEdges(options: ScrollEdgesOptions): () => void;
|
|
56
|
+
dispose(): void;
|
|
57
|
+
}
|
|
58
|
+
/** Refract one explicit live DOM layer. Foreground controls stay semantic HTML. */
|
|
59
|
+
export declare function createGlassScene(root: HTMLElement, config?: GlassSceneOptions): GlassSceneController;
|
|
60
|
+
export { registerShapeContainer, observeConcentricShape, observeCornerPlacement } from "./shape-layout.js";
|
|
61
|
+
export type { ConcentricOptions, CornerOptions, GlassCornerPosition } from "./shape-layout.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** `full` follows the system: reduced motion always removes elasticity. */
|
|
2
|
+
export type GlassMotion = "full" | "reduced" | "none";
|
|
3
|
+
export declare function resolveMotion(motion: GlassMotion | undefined): GlassMotion;
|
|
4
|
+
export interface SurfaceAnimator {
|
|
5
|
+
/** Advance to `now` before the scene samples geometry. Returns true while
|
|
6
|
+
* the animation is in motion and needs the next frame. While the scene is
|
|
7
|
+
* `quiet`, an animator leaves the page as it is: nothing moves, so the GPU
|
|
8
|
+
* is free for the maps another surface is waiting on. */
|
|
9
|
+
frame(now: number, quiet?: boolean): boolean | void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
}
|
|
12
|
+
/** Elastic, illuminated response to touch and pointer input: the surface grows
|
|
13
|
+
* under a press, stretches toward a drag with constant volume, and settles with
|
|
14
|
+
* gel-like overshoot on release. Writes only `translate`, `scale` and custom
|
|
15
|
+
* properties, so consumer `transform` styles continue to compose. */
|
|
16
|
+
export declare function attachInteraction(element: HTMLElement, motion: () => GlassMotion): SurfaceAnimator;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Encode map planes (and capsule slices) to `data:` URLs on a worker, so the
|
|
2
|
+
* main thread never compresses images. Without workers (including under a
|
|
3
|
+
* restrictive CSP) the identical encoder runs locally. The pixels are copied
|
|
4
|
+
* for the worker, so they remain available for that fallback. */
|
|
5
|
+
export declare function encodeMaterialPixels(pixels: Uint8Array, width: number, height: number, cap?: number): Promise<string[][]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Encode GPU readback pixels, never DOM content. The atlas holds four planes
|
|
2
|
+
* stacked vertically. Each plane yields its full image followed, for capsule
|
|
3
|
+
* maps, by its left, middle, and right slices. Everything runs on the CPU of
|
|
4
|
+
* whichever thread calls it. */
|
|
5
|
+
export declare function encodeMapPixels(pixels: Uint8Array, width: number, height: number, cap?: number): Promise<string[][]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MapGeometry } from "../gpu/index.js";
|
|
2
|
+
import type { MaterialMaps } from "./maps.js";
|
|
3
|
+
export type MapPlane = "displacement" | "mask" | "highlight" | "outline";
|
|
4
|
+
/** Beyond two heights, Lisse capsule ends are independent of its width.
|
|
5
|
+
* Bake one longer capsule and reuse its ends instead of readback per frame. */
|
|
6
|
+
export declare function capsuleMapGeometry(g: MapGeometry): MapGeometry | undefined;
|
|
7
|
+
export declare function mapToken(url: string): string;
|
|
8
|
+
export declare function mapUrl(token: string): string | undefined;
|
|
9
|
+
/** Forget a released map image. */
|
|
10
|
+
export declare function releaseMapToken(url: string): void;
|
|
11
|
+
/** Place GPU pixels in SVG filter coordinates. A pressed or stretched
|
|
12
|
+
* capsule keeps round ends: caps scale with its height and only the straight
|
|
13
|
+
* middle stretches. No DOM rasterization. */
|
|
14
|
+
export declare function mapImage(maps: MaterialMaps, plane: MapPlane, result: string, x: number, y: number, width: number, height: number, unitX?: number, unitY?: number): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Material maps persisted across page loads. A reload then draws its glass
|
|
2
|
+
* from the store in the first frames, before the GPU device has even been
|
|
3
|
+
* requested. Entries are keyed by geometry and the renderer version, so a
|
|
4
|
+
* shader or encoder change never shows stale maps. Lookups and writes are
|
|
5
|
+
* batched per task into one transaction each. */
|
|
6
|
+
export interface StoredMaps {
|
|
7
|
+
planes: string[][];
|
|
8
|
+
duration: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function preloadStoredMaps(prefix: string): Promise<void>;
|
|
11
|
+
/** Maps stored for `key`, or undefined when absent or storage is unavailable. */
|
|
12
|
+
export declare function loadStoredMaps(key: string): Promise<StoredMaps | undefined>;
|
|
13
|
+
/** Keys present in the preloaded store, for decoding ahead of first use. */
|
|
14
|
+
export declare function preloadedKeys(): string[];
|
|
15
|
+
/** Maps available without waiting: the first-paint set, then the preloaded store. */
|
|
16
|
+
export declare function peekStoredMaps(key: string): StoredMaps | undefined;
|
|
17
|
+
/** Remember that `key` was needed early in this session, so the next load
|
|
18
|
+
* finds it synchronously. Writes happen once things have settled. */
|
|
19
|
+
export declare function claimFirstPaint(key: string, maps: StoredMaps): void;
|
|
20
|
+
/** Persist freshly encoded maps. Writes are deferred so they never share a
|
|
21
|
+
* frame with the animation that produced them. */
|
|
22
|
+
export declare function saveStoredMaps(key: string, maps: StoredMaps): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MapGeometry } from "../gpu/index.js";
|
|
2
|
+
import type { MapPlane } from "./map-image.js";
|
|
3
|
+
export interface MaterialMaps {
|
|
4
|
+
displacement: string;
|
|
5
|
+
mask: string;
|
|
6
|
+
highlight: string;
|
|
7
|
+
outline: string;
|
|
8
|
+
duration: number;
|
|
9
|
+
/** Capsule maps reused at any width: CSS cap width, plane height, and slices. */
|
|
10
|
+
capsule?: {
|
|
11
|
+
cap: number;
|
|
12
|
+
height: number;
|
|
13
|
+
planes: Record<MapPlane, [string, string, string]>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function getMaterialMaps(g: MapGeometry): Promise<MaterialMaps>;
|
|
17
|
+
/** Internal surface path; public map requests still return the exact geometry.
|
|
18
|
+
* Shapes an animation merely passes through are not worth keeping across
|
|
19
|
+
* loads: with `persist` false they are rendered at once and never wait on the
|
|
20
|
+
* store, whose startup read can take longer than the animation. */
|
|
21
|
+
export declare function getSurfaceMaterialMaps(g: MapGeometry, persist?: boolean): Promise<MaterialMaps>;
|
|
22
|
+
/** Maps for a surface available without waiting a task: already shown, or
|
|
23
|
+
* stored from an earlier load. Stored maps are handed out before their images
|
|
24
|
+
* are decoded; a filter image resolves a `data:` URL in the frame it is
|
|
25
|
+
* referenced, and decoding continues in the background for later swaps. */
|
|
26
|
+
export declare function peekSurfaceMaterialMaps(g: MapGeometry): MaterialMaps | undefined;
|
|
27
|
+
export declare function peekMaterialMaps(g: MapGeometry): MaterialMaps | undefined;
|
|
28
|
+
export declare function decode(url: string): Promise<void>;
|
|
29
|
+
/** Record that maps were drawn, so eviction never releases images on screen. */
|
|
30
|
+
export declare function touchMaps(maps: MaterialMaps): void;
|
|
31
|
+
export declare function clearMaterialMapCache(): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { GlassRadius } from "../core/shape.js";
|
|
2
|
+
import type { Box, MorphGeometry } from "../core/morph-path.js";
|
|
3
|
+
import type { GlassMotion, SurfaceAnimator } from "./interaction.js";
|
|
4
|
+
export { radiusPixels } from "../core/morph-path.js";
|
|
5
|
+
/** A shape an animation passes through, for its maps to be prepared ahead. */
|
|
6
|
+
export type LensWaypoint = MorphGeometry;
|
|
7
|
+
/** A prepared shape drawn in a box: stretched to the live outline, or fixed
|
|
8
|
+
* where a traced union or an absorbed glass lies. */
|
|
9
|
+
export interface LensPlacement extends Box {
|
|
10
|
+
shape: LensWaypoint;
|
|
11
|
+
}
|
|
12
|
+
/** One frame of an animated outline. */
|
|
13
|
+
export interface LensFrame extends Box {
|
|
14
|
+
/** Pixels, or a capsule whose ends stay exact at every width. */
|
|
15
|
+
radius: number | "capsule";
|
|
16
|
+
/** The material to draw: the two prepared shapes around this frame,
|
|
17
|
+
* blended by `mix`. Absent while nothing should be drawn yet. */
|
|
18
|
+
draw?: {
|
|
19
|
+
a: LensPlacement;
|
|
20
|
+
b?: LensPlacement;
|
|
21
|
+
mix: number;
|
|
22
|
+
};
|
|
23
|
+
/** Glass this frame draws in its place, and how much of it. */
|
|
24
|
+
absorbs?: {
|
|
25
|
+
element: Element;
|
|
26
|
+
weight: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface GeometryAnimator extends SurfaceAnimator {
|
|
30
|
+
/** The animated outline, or undefined when the surface rests at its layout box. */
|
|
31
|
+
geometry(): LensFrame | undefined;
|
|
32
|
+
/** Shapes along the current animation's path. A new array starts a new path. */
|
|
33
|
+
waypoints(): readonly LensWaypoint[];
|
|
34
|
+
/** Material opacity while materializing or leaving a non-glass source. */
|
|
35
|
+
opacity(): number;
|
|
36
|
+
/** Waiting for the maps of its path before moving. */
|
|
37
|
+
pending(): boolean;
|
|
38
|
+
}
|
|
39
|
+
/** How a surface relates to the glass it grows out of. */
|
|
40
|
+
export type GlassMorph = "become" | "detach";
|
|
41
|
+
export interface GeometryMotionOptions {
|
|
42
|
+
/** Grow out of this element on entry and shrink back into it on exit. */
|
|
43
|
+
from?: () => Element | null | undefined;
|
|
44
|
+
/** `become`: the source's glass is this surface, and withdraws its own
|
|
45
|
+
* content while the surface is present. `detach`: this surface leaves the
|
|
46
|
+
* source's glass as a drop, joined by a liquid neck until they part.
|
|
47
|
+
* Default: a glass source is become; a source inside glass is detached from. */
|
|
48
|
+
morph?: GlassMorph;
|
|
49
|
+
/** Spring between layout boxes when the surface moves or resizes within its parent. */
|
|
50
|
+
layout?: boolean;
|
|
51
|
+
radius: GlassRadius;
|
|
52
|
+
motion: () => GlassMotion;
|
|
53
|
+
/** Whether a shape's maps are ready to draw. An entrance waits briefly for its path. */
|
|
54
|
+
prepared?: (shape: LensWaypoint) => boolean;
|
|
55
|
+
/** How far a detaching drop stays joined to its glass by a liquid neck, in
|
|
56
|
+
* pixels. `0` lets it grow as a plain shape, with no union to trace. */
|
|
57
|
+
neck?: number;
|
|
58
|
+
/** Grow out of the source when attached. `false` only runs the exit back
|
|
59
|
+
* into it, for an element that was already in place. Default: true. */
|
|
60
|
+
enter?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Animate a surface's optical outline independently of its layout box.
|
|
63
|
+
* Entry grows the glass out of a source shape along a planned path; Base UI
|
|
64
|
+
* `data-ending-style` runs the same path back before the popup unmounts, so
|
|
65
|
+
* an exit needs no new maps. Each frame names the two prepared shapes around
|
|
66
|
+
* it, which the scene blends, so the material never jumps between maps.
|
|
67
|
+
* Layout changes spring along a path from the previous outline. Content is
|
|
68
|
+
* clipped by the outline, so the glass opens to reveal it rather than
|
|
69
|
+
* scaling it. */
|
|
70
|
+
export declare function attachGeometryMotion(element: HTMLElement, options: GeometryMotionOptions): GeometryAnimator;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Encode tightly packed RGBA pixels, `stride` bytes per row, as a PNG. The
|
|
2
|
+
* "Sub" filter turns the maps' smooth gradients into runs zlib packs well. */
|
|
3
|
+
export declare function encodePng(width: number, height: number, rgba: Uint8Array, stride?: number): Promise<Uint8Array>;
|
|
4
|
+
export declare function base64(bytes: Uint8Array): string;
|
|
5
|
+
/** A `data:` URL: Chromium resolves it synchronously for `feImage`, where a
|
|
6
|
+
* `blob:` URL would leave the material blank for a frame. */
|
|
7
|
+
export declare function pngDataUrl(width: number, height: number, rgba: Uint8Array, stride?: number): Promise<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GlassBlurEdge, ProgressiveBlurOptions } from "../core/progressive.js";
|
|
2
|
+
export type GlassScrollTarget = HTMLElement | (() => HTMLElement | null);
|
|
3
|
+
export interface ScrollEdgesOptions extends Omit<ProgressiveBlurOptions, "edge"> {
|
|
4
|
+
/** Scrollport to blur. Only this element is filtered; siblings stay sharp. */
|
|
5
|
+
target: GlassScrollTarget;
|
|
6
|
+
edges?: readonly GlassBlurEdge[];
|
|
7
|
+
}
|
|
8
|
+
export declare function createProgressiveLayer(root: HTMLElement, onError: (error: Error) => void, viewportMode?: boolean): {
|
|
9
|
+
add(element: HTMLElement, options?: ProgressiveBlurOptions): () => void;
|
|
10
|
+
addScroll(options: ScrollEdgesOptions): () => void;
|
|
11
|
+
count(): number;
|
|
12
|
+
update(content: HTMLElement | null): string;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GlassMotion, SurfaceAnimator } from "./interaction.js";
|
|
2
|
+
/** A selection lens for a tab list: it springs between tabs, follows a drag
|
|
3
|
+
* across the list with velocity stretch, and selects the tab beneath it on release. Selection itself stays with the tabs: the lens
|
|
4
|
+
* only clicks the tab it lands on, so keyboard and state handling are unchanged. */
|
|
5
|
+
export declare function attachSelectionLens(indicator: HTMLElement, motion: () => GlassMotion): SurfaceAnimator;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ShapePoint } from "../core/concentric.js";
|
|
2
|
+
import type { GlassRadius } from "../core/shape.js";
|
|
3
|
+
/** Wake the shared loop, for callers that learn of a container change first. */
|
|
4
|
+
export declare function wakeShapeLayout(element?: Element): void;
|
|
5
|
+
export declare function shapeContainerAttributes(radius: GlassRadius): {
|
|
6
|
+
"data-lg-container": string;
|
|
7
|
+
"data-lg-container-radius": string;
|
|
8
|
+
};
|
|
9
|
+
/** Declare geometry for DOM consumers without clipping or changing layout. */
|
|
10
|
+
export declare function registerShapeContainer(element: HTMLElement, radius: GlassRadius): () => void;
|
|
11
|
+
export declare function setResolvedShape(element: HTMLElement, points?: ShapePoint[]): void;
|
|
12
|
+
export interface ConcentricOptions {
|
|
13
|
+
/** Gap from the container outline. Defaults to the smallest measured edge inset. */
|
|
14
|
+
inset?: number;
|
|
15
|
+
/** Radius for portions of the child away from the container boundary. */
|
|
16
|
+
radius?: GlassRadius;
|
|
17
|
+
/** Keep a centered text/icon band inside the inherited curve. */
|
|
18
|
+
contentPadding?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function observeConcentricShape(element: HTMLElement, options?: ConcentricOptions, container?: () => HTMLElement | null): () => void;
|
|
21
|
+
export type GlassCornerPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
22
|
+
export interface CornerOptions {
|
|
23
|
+
corner?: GlassCornerPosition;
|
|
24
|
+
gap?: number;
|
|
25
|
+
radius?: GlassRadius;
|
|
26
|
+
}
|
|
27
|
+
export declare function observeCornerPlacement(element: HTMLElement, options?: CornerOptions, container?: () => HTMLElement | null): () => void;
|
|
28
|
+
/** Resolve a glass surface contour once per geometry change, including nested containers. */
|
|
29
|
+
export declare function createConcentricResolver(element: HTMLElement, inset: number | undefined, radius: GlassRadius): () => ShapePoint[] | undefined;
|