@glasshome/ui 1.24.0 → 1.25.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/SPEC.md +40 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/card-classes.d.ts +4 -4
- package/dist/lib/input-classes.d.ts +1 -0
- package/dist/lib/overlay-classes.d.ts +2 -2
- package/dist/lib/position-bar-classes.d.ts +1 -1
- package/dist/lib/thumb-classes.d.ts +0 -1
- package/dist/solid/index.js +339 -339
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/toggle-group.d.ts +1 -1
- package/dist/tokens/index.js +201 -101
- package/dist/tokens/material.d.ts +53 -8
- package/dist/{utils-rZf2Zpkw.js → utils-Sl2ceVna.js} +23 -23
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/lib/button-variants.ts +1 -1
- package/src/lib/card-classes.ts +2 -2
- package/src/lib/input-classes.ts +5 -0
- package/src/lib/overlay-classes.ts +1 -1
- package/src/lib/position-bar-classes.ts +1 -1
- package/src/lib/thumb-classes.ts +0 -7
- package/src/solid/checkbox.tsx +1 -1
- package/src/solid/slider.tsx +5 -3
- package/src/solid/sliding-indicator.tsx +2 -2
- package/src/solid/switch.tsx +5 -7
- package/src/solid/tabs.tsx +1 -1
- package/src/solid/toggle-group.tsx +3 -3
- package/src/solid/toggle.tsx +1 -1
- package/src/styles/globals.css +237 -21
- package/src/styles/theme.css +27 -14
- package/src/tokens/material.ts +215 -41
package/src/tokens/material.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { clamp } from "./theme-colors.js";
|
|
|
2
2
|
|
|
3
3
|
export const MATERIAL_VERSION = 1;
|
|
4
4
|
|
|
5
|
-
export type MaterialPresetId = "frosted" | "paper" | "neon" | "chalk";
|
|
5
|
+
export type MaterialPresetId = "frosted" | "frost" | "paper" | "neon" | "chalk";
|
|
6
6
|
|
|
7
7
|
/** Tier 2 of the glass formula: what every surface's knobs are multiplied by. The homeowner's dials. */
|
|
8
8
|
export interface MaterialDials {
|
|
@@ -10,18 +10,59 @@ export interface MaterialDials {
|
|
|
10
10
|
blur: number;
|
|
11
11
|
/** How much of the card colour a surface keeps, %; the rest is the wallpaper. */
|
|
12
12
|
clarity: number;
|
|
13
|
-
/**
|
|
13
|
+
/** Default for edge, sheen and shadow together; each can then move on its own. */
|
|
14
14
|
depth: number;
|
|
15
15
|
/** Scales the tone wash. */
|
|
16
16
|
tint: number;
|
|
17
|
-
/**
|
|
17
|
+
/** Bloom radius in the surface's own hue, px. */
|
|
18
18
|
glow: number;
|
|
19
19
|
/** 0..1; above 0 every surface is hand-inked: a drawn line over a hand-laid fill. */
|
|
20
20
|
ink: number;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
export
|
|
23
|
+
export type WashStyle = "flat" | "fade" | "two-tone";
|
|
24
|
+
export type RimPosition = "top" | "top-bottom" | "around";
|
|
25
|
+
export type GlowPosition = "outside" | "inside";
|
|
26
|
+
export type MaterialFace = "flat" | "raised";
|
|
27
|
+
|
|
28
|
+
/** The creator's terms. Every one has a default that renders today's glass. */
|
|
29
|
+
export interface MaterialTerms extends MaterialDials {
|
|
30
|
+
/** Backdrop saturation and brightness together; 1 is each surface's own. */
|
|
31
|
+
vibrancy: number;
|
|
32
|
+
/** The bright hairline and rim light. Defaults to depth. */
|
|
33
|
+
edge: number;
|
|
34
|
+
/** The white sweep. Defaults to depth. */
|
|
35
|
+
sheen: number;
|
|
36
|
+
/** The lift shadow. Defaults to depth. */
|
|
37
|
+
shadow: number;
|
|
38
|
+
/** Glass thickness: a soft inner shade with a light catch, 0..1. */
|
|
39
|
+
inset: number;
|
|
40
|
+
/** Where the light comes from, degrees, 0 is the top; turns sheen, rim and inset together. */
|
|
41
|
+
lightFrom: number;
|
|
42
|
+
rim: RimPosition;
|
|
43
|
+
/** Dark mode multiplies edge, sheen, inset and inner glow by this. */
|
|
44
|
+
darkScale: number;
|
|
45
|
+
glowAt: GlowPosition;
|
|
46
|
+
/** Light inside the card from the top, 0..1. */
|
|
47
|
+
innerGlow: number;
|
|
48
|
+
/** 0 is white light, 1 the surface's own hue. */
|
|
49
|
+
innerGlowHue: number;
|
|
50
|
+
/** Fine still frost over a card's fill, 0..1. */
|
|
51
|
+
grain: number;
|
|
52
|
+
washStyle: WashStyle;
|
|
53
|
+
/** Angle of the tone wash, degrees. */
|
|
54
|
+
washAngle: number;
|
|
55
|
+
face: MaterialFace;
|
|
56
|
+
/** Raised and pressed depth, for the surface face and the controls. */
|
|
57
|
+
relief: number;
|
|
58
|
+
/** "theme" is the theme's --primary; otherwise a colour. */
|
|
59
|
+
accent: string;
|
|
60
|
+
/** Accent wash on surfaces that pass no tone, 0..0.6. */
|
|
61
|
+
fill: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Terms a preset turns on; inert at zero, never a creator term. */
|
|
65
|
+
export interface MaterialPresetTerms {
|
|
25
66
|
/** Edge width, px. */
|
|
26
67
|
edgeWidth: number;
|
|
27
68
|
/** 0..1, how far the edge moves toward the material ink. */
|
|
@@ -32,36 +73,55 @@ export interface MaterialTerms {
|
|
|
32
73
|
inkLift: number;
|
|
33
74
|
}
|
|
34
75
|
|
|
35
|
-
export type MaterialSpec = MaterialDials & MaterialTerms
|
|
76
|
+
export type MaterialSpec = MaterialDials & MaterialPresetTerms & Partial<MaterialTerms>;
|
|
36
77
|
|
|
37
78
|
/** What was chosen, never what was computed. */
|
|
38
79
|
export interface Material {
|
|
39
80
|
v: typeof MATERIAL_VERSION;
|
|
40
81
|
preset: MaterialPresetId;
|
|
41
|
-
dials?: Partial<
|
|
82
|
+
dials?: Partial<MaterialTerms>;
|
|
42
83
|
}
|
|
43
84
|
|
|
44
85
|
export type BlurMode = "dynamic" | "performant" | "none";
|
|
45
86
|
|
|
46
|
-
const PLAIN:
|
|
87
|
+
const PLAIN: MaterialPresetTerms = { edgeWidth: 1, edgeInk: 0, edgeAccent: 0, inkLift: 0 };
|
|
47
88
|
|
|
48
89
|
export const MATERIAL_PRESETS: Record<MaterialPresetId, MaterialSpec> = {
|
|
49
|
-
/**
|
|
90
|
+
/** Glass: clear, blurred, lit rim. The id predates the name and stays for stored themes. */
|
|
50
91
|
frosted: { blur: 24, clarity: 60, depth: 1, tint: 1, glow: 0, ink: 0, ...PLAIN },
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
/**
|
|
92
|
+
/** Frosted: the same glass with a fine frost over each card. */
|
|
93
|
+
frost: { blur: 24, clarity: 60, depth: 1, tint: 1, glow: 0, ink: 0, ...PLAIN, grain: 0.4 },
|
|
94
|
+
/** Opaque matte stock, a faint inked cut edge, a short contact shadow; the Ink dial draws on it. */
|
|
95
|
+
paper: {
|
|
96
|
+
blur: 0,
|
|
97
|
+
clarity: 100,
|
|
98
|
+
depth: 0.5,
|
|
99
|
+
tint: 0.85,
|
|
100
|
+
glow: 0,
|
|
101
|
+
ink: 0,
|
|
102
|
+
...PLAIN,
|
|
103
|
+
edgeInk: 0.3,
|
|
104
|
+
sheen: 0,
|
|
105
|
+
edge: 0.2,
|
|
106
|
+
shadow: 0.7,
|
|
107
|
+
},
|
|
108
|
+
/** Smoky glass lit from inside in its own hue, a soft hue edge and a small bloom. */
|
|
54
109
|
neon: {
|
|
55
|
-
blur:
|
|
56
|
-
clarity:
|
|
110
|
+
blur: 9,
|
|
111
|
+
clarity: 57,
|
|
57
112
|
depth: 0.4,
|
|
58
|
-
tint: 0.
|
|
59
|
-
edgeWidth: 1
|
|
113
|
+
tint: 0.6,
|
|
114
|
+
edgeWidth: 1,
|
|
60
115
|
edgeInk: 0,
|
|
61
|
-
edgeAccent:
|
|
116
|
+
edgeAccent: 0.35,
|
|
62
117
|
inkLift: 0,
|
|
63
|
-
glow:
|
|
118
|
+
glow: 3,
|
|
64
119
|
ink: 0,
|
|
120
|
+
vibrancy: 1.3,
|
|
121
|
+
edge: 0.25,
|
|
122
|
+
sheen: 0.3,
|
|
123
|
+
shadow: 1,
|
|
124
|
+
innerGlow: 0.35,
|
|
65
125
|
},
|
|
66
126
|
/** Matte board, the Ink body drawn in the foreground colour. */
|
|
67
127
|
chalk: { blur: 0, clarity: 100, depth: 0.3, tint: 0.7, glow: 0, ink: 1, ...PLAIN, inkLift: 1 },
|
|
@@ -69,48 +129,162 @@ export const MATERIAL_PRESETS: Record<MaterialPresetId, MaterialSpec> = {
|
|
|
69
129
|
|
|
70
130
|
export const FROSTED: Material = { v: 1, preset: "frosted" };
|
|
71
131
|
|
|
72
|
-
|
|
132
|
+
type NumericTerm = {
|
|
133
|
+
[K in keyof MaterialTerms]: MaterialTerms[K] extends number ? K : never;
|
|
134
|
+
}[keyof MaterialTerms];
|
|
135
|
+
|
|
136
|
+
export const MATERIAL_RANGES: Record<NumericTerm, [number, number]> = {
|
|
73
137
|
blur: [0, 48],
|
|
74
138
|
clarity: [0, 100],
|
|
75
139
|
depth: [0, 2],
|
|
76
140
|
tint: [0, 2],
|
|
77
141
|
glow: [0, 40],
|
|
78
142
|
ink: [0, 1],
|
|
143
|
+
vibrancy: [0.5, 2],
|
|
144
|
+
edge: [0, 2],
|
|
145
|
+
sheen: [0, 2],
|
|
146
|
+
shadow: [0, 2],
|
|
147
|
+
inset: [0, 1],
|
|
148
|
+
lightFrom: [0, 360],
|
|
149
|
+
darkScale: [0, 1],
|
|
150
|
+
innerGlow: [0, 1],
|
|
151
|
+
innerGlowHue: [0, 1],
|
|
152
|
+
grain: [0, 1],
|
|
153
|
+
washAngle: [0, 360],
|
|
154
|
+
relief: [0, 2],
|
|
155
|
+
fill: [0, 0.6],
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type DepthLed = "edge" | "sheen" | "shadow";
|
|
159
|
+
|
|
160
|
+
const TERM_DEFAULTS: Omit<MaterialTerms, keyof MaterialDials | DepthLed> = {
|
|
161
|
+
vibrancy: 1,
|
|
162
|
+
inset: 0,
|
|
163
|
+
lightFrom: 315,
|
|
164
|
+
rim: "top",
|
|
165
|
+
darkScale: 1,
|
|
166
|
+
glowAt: "outside",
|
|
167
|
+
innerGlow: 0,
|
|
168
|
+
innerGlowHue: 1,
|
|
169
|
+
grain: 0,
|
|
170
|
+
washStyle: "fade",
|
|
171
|
+
washAngle: 135,
|
|
172
|
+
face: "flat",
|
|
173
|
+
relief: 1,
|
|
174
|
+
accent: "theme",
|
|
175
|
+
fill: 0,
|
|
79
176
|
};
|
|
80
177
|
|
|
81
178
|
/** Below this the text floor fails over a busy wallpaper with nothing blurred behind it. */
|
|
82
179
|
const NO_BLUR_CLARITY_FLOOR = 85;
|
|
83
180
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
181
|
+
const NUMERIC_TERMS = Object.keys(MATERIAL_RANGES) as NumericTerm[];
|
|
182
|
+
|
|
183
|
+
export function materialTerms(material: Material): MaterialTerms {
|
|
184
|
+
const {
|
|
185
|
+
edgeWidth: _w,
|
|
186
|
+
edgeInk: _i,
|
|
187
|
+
edgeAccent: _a,
|
|
188
|
+
inkLift: _l,
|
|
189
|
+
...preset
|
|
190
|
+
} = MATERIAL_PRESETS[material.preset];
|
|
191
|
+
const merged = { ...TERM_DEFAULTS, ...preset, ...material.dials };
|
|
192
|
+
const terms: MaterialTerms = {
|
|
193
|
+
...merged,
|
|
194
|
+
edge: merged.edge ?? merged.depth,
|
|
195
|
+
sheen: merged.sheen ?? merged.depth,
|
|
196
|
+
shadow: merged.shadow ?? merged.depth,
|
|
93
197
|
};
|
|
198
|
+
for (const key of NUMERIC_TERMS) terms[key] = clamp(terms[key], ...MATERIAL_RANGES[key]);
|
|
199
|
+
return terms;
|
|
94
200
|
}
|
|
95
201
|
|
|
202
|
+
export function materialDials(material: Material): MaterialDials {
|
|
203
|
+
const { blur, clarity, depth, tint, glow, ink } = materialTerms(material);
|
|
204
|
+
return { blur, clarity, depth, tint, glow, ink };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Today's offsets are drawn for light from 315deg; another angle rotates them. */
|
|
208
|
+
const LIGHT_HOME = 315;
|
|
209
|
+
|
|
210
|
+
const round = (n: number) => Math.round(n * 10000) / 10000;
|
|
211
|
+
|
|
212
|
+
const svgTile = (size: number, filter: string) =>
|
|
213
|
+
`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='${size}' height='${size}'><filter id='n' x='0' y='0' width='100%' height='100%'>${filter}</filter><rect width='${size}' height='${size}' filter='url(%23n)'/></svg>")`;
|
|
214
|
+
|
|
215
|
+
/* Frost: a fine even tooth in neutral grey, its strength baked into the alpha. */
|
|
216
|
+
const frostTile = (strength: number) =>
|
|
217
|
+
svgTile(
|
|
218
|
+
160,
|
|
219
|
+
`<feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='0' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.7 0 0 0 0 0.7 0 0 0 0 0.7 0 0 0 ${round(strength * 0.3)} 0'/>`,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const WASH_SPLIT: Record<WashStyle, number> = { flat: 1, fade: 3, "two-tone": 1 };
|
|
223
|
+
const RIM: Record<RimPosition, [bottom: number, around: number]> = {
|
|
224
|
+
top: [0, 0],
|
|
225
|
+
"top-bottom": [1, 0],
|
|
226
|
+
around: [0, 1],
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/** The --surface-control-* palette: calm on a flat face, neumorphic on a raised one. */
|
|
230
|
+
const CONTROLS: Record<MaterialFace, Record<`--material-control-${string}`, string>> = {
|
|
231
|
+
flat: {
|
|
232
|
+
"--material-control-track": "var(--input)",
|
|
233
|
+
"--material-control-fill": "var(--material-accent)",
|
|
234
|
+
"--material-control-knob": "oklch(1 0 0)",
|
|
235
|
+
},
|
|
236
|
+
raised: {
|
|
237
|
+
"--material-control-track": "var(--material-well)",
|
|
238
|
+
"--material-control-fill":
|
|
239
|
+
"linear-gradient(90deg, color-mix(in srgb, var(--material-accent), black 50%), var(--material-accent))",
|
|
240
|
+
"--material-control-knob": "var(--material-face)",
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
|
|
96
244
|
export function resolveMaterial(
|
|
97
245
|
material: Material,
|
|
98
246
|
blurMode: BlurMode,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const t =
|
|
102
|
-
const
|
|
103
|
-
const
|
|
247
|
+
mode: "light" | "dark" = "light",
|
|
248
|
+
): Record<`--${string}`, string> {
|
|
249
|
+
const t = materialTerms(material);
|
|
250
|
+
const p = MATERIAL_PRESETS[material.preset];
|
|
251
|
+
const blur = blurMode === "none" ? 0 : t.blur;
|
|
252
|
+
const clarity = blurMode === "none" ? Math.max(t.clarity, NO_BLUR_CLARITY_FLOOR) : t.clarity;
|
|
253
|
+
const dim = mode === "dark" ? t.darkScale : 1;
|
|
254
|
+
const turn = ((t.lightFrom - LIGHT_HOME) * Math.PI) / 180;
|
|
255
|
+
const [rimBottom, rimAround] = RIM[t.rim];
|
|
104
256
|
return {
|
|
105
257
|
"--material-blur": `${blur}px`,
|
|
106
258
|
"--material-clarity": `${clarity}%`,
|
|
107
|
-
"--material-depth": `${
|
|
108
|
-
"--material-tint": `${
|
|
109
|
-
"--material-edge-width": `${
|
|
110
|
-
"--material-edge-ink": `${
|
|
111
|
-
"--material-edge-accent": `${
|
|
112
|
-
"--material-glow": `${
|
|
113
|
-
"--material-ink-level": `${
|
|
114
|
-
"--material-ink-lift": `${
|
|
259
|
+
"--material-depth": `${t.depth}`,
|
|
260
|
+
"--material-tint": `${t.tint}`,
|
|
261
|
+
"--material-edge-width": `${p.edgeWidth}px`,
|
|
262
|
+
"--material-edge-ink": `${p.edgeInk}`,
|
|
263
|
+
"--material-edge-accent": `${p.edgeAccent}`,
|
|
264
|
+
"--material-glow": `${t.glow}px`,
|
|
265
|
+
"--material-ink-level": `${t.ink}`,
|
|
266
|
+
"--material-ink-lift": `${p.inkLift}`,
|
|
267
|
+
"--_material-vibrancy": `${t.vibrancy}`,
|
|
268
|
+
"--_material-edge": `${round(t.edge * dim)}`,
|
|
269
|
+
"--_material-sheen": `${round(t.sheen * dim)}`,
|
|
270
|
+
"--_material-shadow": `${t.shadow}`,
|
|
271
|
+
"--_material-inset": `${round(t.inset * dim)}`,
|
|
272
|
+
"--_material-light-cos": `${round(Math.cos(turn))}`,
|
|
273
|
+
"--_material-light-sin": `${round(Math.sin(turn))}`,
|
|
274
|
+
"--_material-rim-bottom": `${rimBottom}`,
|
|
275
|
+
"--_material-rim-around": `${rimAround}`,
|
|
276
|
+
"--_material-glow-out": t.glowAt === "outside" ? "1" : "0",
|
|
277
|
+
"--_material-glow-in": t.glowAt === "inside" ? "1" : "0",
|
|
278
|
+
"--_material-inner-glow": `${round(t.innerGlow * dim)}`,
|
|
279
|
+
"--_material-inner-glow-hue": `${t.innerGlowHue}`,
|
|
280
|
+
"--_material-grain": t.grain > 0 ? frostTile(t.grain) : "none",
|
|
281
|
+
"--_material-wash-split": `${WASH_SPLIT[t.washStyle]}`,
|
|
282
|
+
"--_material-wash-angle": `${t.washAngle}deg`,
|
|
283
|
+
"--_material-two-tone": t.washStyle === "two-tone" ? "1" : "0",
|
|
284
|
+
"--_material-face-raised": t.face === "raised" ? "1" : "0",
|
|
285
|
+
...CONTROLS[t.face],
|
|
286
|
+
"--_material-relief": `${t.relief}`,
|
|
287
|
+
"--material-accent": t.accent === "theme" ? "var(--primary)" : t.accent,
|
|
288
|
+
"--_material-fill": `${t.fill}`,
|
|
115
289
|
};
|
|
116
290
|
}
|