@dazecoop/liquid-glass 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +256 -2
- package/lib/index.cjs +1172 -0
- package/lib/index.d.cts +156 -0
- package/lib/index.d.ts +156 -0
- package/lib/index.js +1172 -0
- package/lib/liquid-glass.css +390 -0
- package/lib/liquid-glass.global.js +12 -0
- package/lib/react.cjs +238 -0
- package/lib/react.d.cts +91 -0
- package/lib/react.d.ts +91 -0
- package/lib/react.js +238 -0
- package/package.json +81 -4
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/** Parameters that shape and light the glass. All are optional when passed to set(). */
|
|
2
|
+
export interface GlassParams {
|
|
3
|
+
/** Lens width in CSS pixels (anchored glass takes its anchor's). Default 280 */
|
|
4
|
+
width?: number;
|
|
5
|
+
/** Lens height in CSS pixels (anchored glass takes its anchor's). Default 180 */
|
|
6
|
+
height?: number;
|
|
7
|
+
/** Corner radius in CSS pixels (anchored glass takes its anchor's). Default 64 */
|
|
8
|
+
radius?: number;
|
|
9
|
+
/** How far the curved rim reaches in, in CSS pixels. Half the smaller side or more is a full dome. Default 35 */
|
|
10
|
+
bevel?: number;
|
|
11
|
+
/** How far the rim bends the content, in CSS pixels. Default 40 */
|
|
12
|
+
refraction?: number;
|
|
13
|
+
/** Blur radius in CSS pixels. Default 2 */
|
|
14
|
+
frost?: number;
|
|
15
|
+
/** Chromatic dispersion at the rim, 0 to 1. Default 0.4 */
|
|
16
|
+
chroma?: number;
|
|
17
|
+
/** Magnification across the whole lens. Default 1.08 */
|
|
18
|
+
zoom?: number;
|
|
19
|
+
/** Strength of the specular highlight, 0 to 1. Default 0.35 */
|
|
20
|
+
specular?: number;
|
|
21
|
+
/** Strength of the edge glow where the glass turns away, 0 to 1. Default 0.3 */
|
|
22
|
+
fresnel?: number;
|
|
23
|
+
/** Brightness of what's seen through the glass, -0.5 to 0.5. Default 0 */
|
|
24
|
+
brightness?: number;
|
|
25
|
+
/** Saturation of what's seen through the glass, -1 (grey) to 1. Default 0 */
|
|
26
|
+
saturation?: number;
|
|
27
|
+
/** A CSS colour laid over the glass, for legibility. Default "" */
|
|
28
|
+
tint?: string;
|
|
29
|
+
/** Strength of the rim lighting and edge hairline, 0 to 1. Default 1 */
|
|
30
|
+
rim?: number;
|
|
31
|
+
/** Milky body inside the rim, 0 to 1. Default 1 */
|
|
32
|
+
body?: number;
|
|
33
|
+
/** UIKit's rim profile: the bend decays by e every this many px inward. 0 is a circular bevel. Default 0 */
|
|
34
|
+
falloff?: number;
|
|
35
|
+
/** Angle of the light, in degrees */
|
|
36
|
+
lightAngle?: number;
|
|
37
|
+
/** Squash and stretch as the lens moves: 0 off, 1 full. Default 1 */
|
|
38
|
+
stretch?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface GlassOptions extends GlassParams {
|
|
42
|
+
/** An element to fill as its background, instead of a lens that follows moveTo() */
|
|
43
|
+
anchor?: HTMLElement | null;
|
|
44
|
+
/** An element for the lens to live in, clipped to it and scrolling with it */
|
|
45
|
+
container?: HTMLElement | null;
|
|
46
|
+
/** Anchored glass brightens on hover and flattens on press */
|
|
47
|
+
button?: boolean;
|
|
48
|
+
/** Re-copy a large source at most every this many ms. Default 0 */
|
|
49
|
+
throttle?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type PresetName = "clear" | "frosted" | "dark" | "prism" | "dome";
|
|
53
|
+
|
|
54
|
+
export class LiquidGlass {
|
|
55
|
+
/** Starting looks, each a set of parameters: glass.set(LiquidGlass.presets.frosted) */
|
|
56
|
+
static presets: Record<PresetName, GlassParams>;
|
|
57
|
+
/** Creates glass that refracts `source`, a live element */
|
|
58
|
+
constructor(source: HTMLElement, options?: GlassOptions);
|
|
59
|
+
/** The glass's own element */
|
|
60
|
+
readonly el: HTMLDivElement;
|
|
61
|
+
readonly params: Required<Omit<GlassParams, "body" | "falloff" | "lightAngle" | "stretch">> & GlassParams;
|
|
62
|
+
readonly visible: boolean;
|
|
63
|
+
readonly destroyed: boolean;
|
|
64
|
+
/** Updates any of the parameters */
|
|
65
|
+
set(params: GlassParams): void;
|
|
66
|
+
/** Moves the lens to a point in viewport (client) coordinates, showing it */
|
|
67
|
+
moveTo(x: number, y: number): void;
|
|
68
|
+
/** Grows the lens slightly while true */
|
|
69
|
+
press(down: boolean): void;
|
|
70
|
+
/** Fades the lens in or out. With pop it bursts like a bubble on the way out and swells back in */
|
|
71
|
+
show(visible: boolean, options?: { pop?: boolean }): void;
|
|
72
|
+
/** Removes the glass and everything it added, and stops it listening. Safe to call twice */
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface Looks {
|
|
77
|
+
switch: { light: GlassParams; dark: GlassParams };
|
|
78
|
+
tabs: { light: GlassParams; dark: GlassParams };
|
|
79
|
+
button: { light: GlassParams; dark: GlassParams };
|
|
80
|
+
}
|
|
81
|
+
/** The components' glass, light and dark, tuned against iOS 26 */
|
|
82
|
+
export const LOOKS: Looks;
|
|
83
|
+
|
|
84
|
+
export interface GlassSwitchOptions {
|
|
85
|
+
/** How much bigger than the thumb the lens grows. Default 1.55 */
|
|
86
|
+
grow?: number;
|
|
87
|
+
/** How much more it swells while pressed. Default 1.08 */
|
|
88
|
+
press?: number;
|
|
89
|
+
/** How far the lens leans towards a hovering pointer, in px. Default 4 */
|
|
90
|
+
lean?: number;
|
|
91
|
+
/** The glass. Default LOOKS.switch for the nearest [data-theme] */
|
|
92
|
+
look?: GlassParams;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A switch, or a segmented switch with a label each side. Fires a bubbling "change"
|
|
97
|
+
* CustomEvent with detail.value (0 or 1).
|
|
98
|
+
*/
|
|
99
|
+
export class GlassSwitch {
|
|
100
|
+
constructor(root: HTMLElement, options?: GlassSwitchOptions);
|
|
101
|
+
readonly root: HTMLElement;
|
|
102
|
+
readonly lens: LiquidGlass;
|
|
103
|
+
/** 0 or 1 */
|
|
104
|
+
readonly value: number;
|
|
105
|
+
select(index: number): void;
|
|
106
|
+
destroy(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface GlassTabBarOptions {
|
|
110
|
+
/** How much bigger than a tab the lens grows. Default 1.3 */
|
|
111
|
+
grow?: number;
|
|
112
|
+
/** How much more it swells while pressed. Default 1.1 */
|
|
113
|
+
press?: number;
|
|
114
|
+
/** The glass. Default LOOKS.tabs for the nearest [data-theme] */
|
|
115
|
+
look?: GlassParams;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A floating tab bar. Fires a bubbling "change" CustomEvent with detail.tab (the element). */
|
|
119
|
+
export class GlassTabBar {
|
|
120
|
+
constructor(root: HTMLElement, options?: GlassTabBarOptions);
|
|
121
|
+
readonly root: HTMLElement;
|
|
122
|
+
readonly lens: LiquidGlass;
|
|
123
|
+
readonly tabs: HTMLElement[];
|
|
124
|
+
readonly current: HTMLElement | null;
|
|
125
|
+
choose(tab: HTMLElement): void;
|
|
126
|
+
destroy(): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface GlassButtonOptions {
|
|
130
|
+
/** Where the lens lives. Default the button's parent */
|
|
131
|
+
container?: HTMLElement;
|
|
132
|
+
/** What it refracts. Default the container's [data-glass-source] child */
|
|
133
|
+
source?: HTMLElement;
|
|
134
|
+
/** Growth when hovered. Default 1.1 */
|
|
135
|
+
grow?: number;
|
|
136
|
+
/** More growth when pressed. Default 1.08 */
|
|
137
|
+
press?: number;
|
|
138
|
+
/** How opaque the tint gets, 0 to 1. Default 0.95 */
|
|
139
|
+
lit?: number;
|
|
140
|
+
/** How long it stays lit after release, in ms. Default 120 */
|
|
141
|
+
hang?: number;
|
|
142
|
+
/** The glass. Default LOOKS.button for the nearest [data-theme] */
|
|
143
|
+
look?: GlassParams;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class GlassButton {
|
|
147
|
+
constructor(button: HTMLElement, options?: GlassButtonOptions);
|
|
148
|
+
readonly btn: HTMLElement;
|
|
149
|
+
readonly lens: LiquidGlass;
|
|
150
|
+
destroy(): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type GlassComponent = GlassSwitch | GlassTabBar | GlassButton;
|
|
154
|
+
|
|
155
|
+
/** Builds every [data-glass-switch], [data-glass-tabs] and [data-glass-button] under root */
|
|
156
|
+
export function initComponents(root?: ParentNode): GlassComponent[];
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/** Parameters that shape and light the glass. All are optional when passed to set(). */
|
|
2
|
+
export interface GlassParams {
|
|
3
|
+
/** Lens width in CSS pixels (anchored glass takes its anchor's). Default 280 */
|
|
4
|
+
width?: number;
|
|
5
|
+
/** Lens height in CSS pixels (anchored glass takes its anchor's). Default 180 */
|
|
6
|
+
height?: number;
|
|
7
|
+
/** Corner radius in CSS pixels (anchored glass takes its anchor's). Default 64 */
|
|
8
|
+
radius?: number;
|
|
9
|
+
/** How far the curved rim reaches in, in CSS pixels. Half the smaller side or more is a full dome. Default 35 */
|
|
10
|
+
bevel?: number;
|
|
11
|
+
/** How far the rim bends the content, in CSS pixels. Default 40 */
|
|
12
|
+
refraction?: number;
|
|
13
|
+
/** Blur radius in CSS pixels. Default 2 */
|
|
14
|
+
frost?: number;
|
|
15
|
+
/** Chromatic dispersion at the rim, 0 to 1. Default 0.4 */
|
|
16
|
+
chroma?: number;
|
|
17
|
+
/** Magnification across the whole lens. Default 1.08 */
|
|
18
|
+
zoom?: number;
|
|
19
|
+
/** Strength of the specular highlight, 0 to 1. Default 0.35 */
|
|
20
|
+
specular?: number;
|
|
21
|
+
/** Strength of the edge glow where the glass turns away, 0 to 1. Default 0.3 */
|
|
22
|
+
fresnel?: number;
|
|
23
|
+
/** Brightness of what's seen through the glass, -0.5 to 0.5. Default 0 */
|
|
24
|
+
brightness?: number;
|
|
25
|
+
/** Saturation of what's seen through the glass, -1 (grey) to 1. Default 0 */
|
|
26
|
+
saturation?: number;
|
|
27
|
+
/** A CSS colour laid over the glass, for legibility. Default "" */
|
|
28
|
+
tint?: string;
|
|
29
|
+
/** Strength of the rim lighting and edge hairline, 0 to 1. Default 1 */
|
|
30
|
+
rim?: number;
|
|
31
|
+
/** Milky body inside the rim, 0 to 1. Default 1 */
|
|
32
|
+
body?: number;
|
|
33
|
+
/** UIKit's rim profile: the bend decays by e every this many px inward. 0 is a circular bevel. Default 0 */
|
|
34
|
+
falloff?: number;
|
|
35
|
+
/** Angle of the light, in degrees */
|
|
36
|
+
lightAngle?: number;
|
|
37
|
+
/** Squash and stretch as the lens moves: 0 off, 1 full. Default 1 */
|
|
38
|
+
stretch?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface GlassOptions extends GlassParams {
|
|
42
|
+
/** An element to fill as its background, instead of a lens that follows moveTo() */
|
|
43
|
+
anchor?: HTMLElement | null;
|
|
44
|
+
/** An element for the lens to live in, clipped to it and scrolling with it */
|
|
45
|
+
container?: HTMLElement | null;
|
|
46
|
+
/** Anchored glass brightens on hover and flattens on press */
|
|
47
|
+
button?: boolean;
|
|
48
|
+
/** Re-copy a large source at most every this many ms. Default 0 */
|
|
49
|
+
throttle?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type PresetName = "clear" | "frosted" | "dark" | "prism" | "dome";
|
|
53
|
+
|
|
54
|
+
export class LiquidGlass {
|
|
55
|
+
/** Starting looks, each a set of parameters: glass.set(LiquidGlass.presets.frosted) */
|
|
56
|
+
static presets: Record<PresetName, GlassParams>;
|
|
57
|
+
/** Creates glass that refracts `source`, a live element */
|
|
58
|
+
constructor(source: HTMLElement, options?: GlassOptions);
|
|
59
|
+
/** The glass's own element */
|
|
60
|
+
readonly el: HTMLDivElement;
|
|
61
|
+
readonly params: Required<Omit<GlassParams, "body" | "falloff" | "lightAngle" | "stretch">> & GlassParams;
|
|
62
|
+
readonly visible: boolean;
|
|
63
|
+
readonly destroyed: boolean;
|
|
64
|
+
/** Updates any of the parameters */
|
|
65
|
+
set(params: GlassParams): void;
|
|
66
|
+
/** Moves the lens to a point in viewport (client) coordinates, showing it */
|
|
67
|
+
moveTo(x: number, y: number): void;
|
|
68
|
+
/** Grows the lens slightly while true */
|
|
69
|
+
press(down: boolean): void;
|
|
70
|
+
/** Fades the lens in or out. With pop it bursts like a bubble on the way out and swells back in */
|
|
71
|
+
show(visible: boolean, options?: { pop?: boolean }): void;
|
|
72
|
+
/** Removes the glass and everything it added, and stops it listening. Safe to call twice */
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface Looks {
|
|
77
|
+
switch: { light: GlassParams; dark: GlassParams };
|
|
78
|
+
tabs: { light: GlassParams; dark: GlassParams };
|
|
79
|
+
button: { light: GlassParams; dark: GlassParams };
|
|
80
|
+
}
|
|
81
|
+
/** The components' glass, light and dark, tuned against iOS 26 */
|
|
82
|
+
export const LOOKS: Looks;
|
|
83
|
+
|
|
84
|
+
export interface GlassSwitchOptions {
|
|
85
|
+
/** How much bigger than the thumb the lens grows. Default 1.55 */
|
|
86
|
+
grow?: number;
|
|
87
|
+
/** How much more it swells while pressed. Default 1.08 */
|
|
88
|
+
press?: number;
|
|
89
|
+
/** How far the lens leans towards a hovering pointer, in px. Default 4 */
|
|
90
|
+
lean?: number;
|
|
91
|
+
/** The glass. Default LOOKS.switch for the nearest [data-theme] */
|
|
92
|
+
look?: GlassParams;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A switch, or a segmented switch with a label each side. Fires a bubbling "change"
|
|
97
|
+
* CustomEvent with detail.value (0 or 1).
|
|
98
|
+
*/
|
|
99
|
+
export class GlassSwitch {
|
|
100
|
+
constructor(root: HTMLElement, options?: GlassSwitchOptions);
|
|
101
|
+
readonly root: HTMLElement;
|
|
102
|
+
readonly lens: LiquidGlass;
|
|
103
|
+
/** 0 or 1 */
|
|
104
|
+
readonly value: number;
|
|
105
|
+
select(index: number): void;
|
|
106
|
+
destroy(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface GlassTabBarOptions {
|
|
110
|
+
/** How much bigger than a tab the lens grows. Default 1.3 */
|
|
111
|
+
grow?: number;
|
|
112
|
+
/** How much more it swells while pressed. Default 1.1 */
|
|
113
|
+
press?: number;
|
|
114
|
+
/** The glass. Default LOOKS.tabs for the nearest [data-theme] */
|
|
115
|
+
look?: GlassParams;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A floating tab bar. Fires a bubbling "change" CustomEvent with detail.tab (the element). */
|
|
119
|
+
export class GlassTabBar {
|
|
120
|
+
constructor(root: HTMLElement, options?: GlassTabBarOptions);
|
|
121
|
+
readonly root: HTMLElement;
|
|
122
|
+
readonly lens: LiquidGlass;
|
|
123
|
+
readonly tabs: HTMLElement[];
|
|
124
|
+
readonly current: HTMLElement | null;
|
|
125
|
+
choose(tab: HTMLElement): void;
|
|
126
|
+
destroy(): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface GlassButtonOptions {
|
|
130
|
+
/** Where the lens lives. Default the button's parent */
|
|
131
|
+
container?: HTMLElement;
|
|
132
|
+
/** What it refracts. Default the container's [data-glass-source] child */
|
|
133
|
+
source?: HTMLElement;
|
|
134
|
+
/** Growth when hovered. Default 1.1 */
|
|
135
|
+
grow?: number;
|
|
136
|
+
/** More growth when pressed. Default 1.08 */
|
|
137
|
+
press?: number;
|
|
138
|
+
/** How opaque the tint gets, 0 to 1. Default 0.95 */
|
|
139
|
+
lit?: number;
|
|
140
|
+
/** How long it stays lit after release, in ms. Default 120 */
|
|
141
|
+
hang?: number;
|
|
142
|
+
/** The glass. Default LOOKS.button for the nearest [data-theme] */
|
|
143
|
+
look?: GlassParams;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class GlassButton {
|
|
147
|
+
constructor(button: HTMLElement, options?: GlassButtonOptions);
|
|
148
|
+
readonly btn: HTMLElement;
|
|
149
|
+
readonly lens: LiquidGlass;
|
|
150
|
+
destroy(): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type GlassComponent = GlassSwitch | GlassTabBar | GlassButton;
|
|
154
|
+
|
|
155
|
+
/** Builds every [data-glass-switch], [data-glass-tabs] and [data-glass-button] under root */
|
|
156
|
+
export function initComponents(root?: ParentNode): GlassComponent[];
|