glacia-native 0.5.1 → 0.5.2
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 +29 -4
- package/README.md +27 -0
- package/lib/module/Bars.js +10 -9
- package/lib/module/Button.js +11 -8
- package/lib/module/Card.js +2 -2
- package/lib/module/Dialog.js +16 -17
- package/lib/module/Display.js +8 -7
- package/lib/module/Feedback.js +24 -15
- package/lib/module/Form.js +29 -33
- package/lib/module/Forms2.js +38 -21
- package/lib/module/Glass.js +2 -2
- package/lib/module/Input.js +12 -10
- package/lib/module/Message.js +11 -15
- package/lib/module/Overlays.js +22 -6
- package/lib/module/Pickers.js +16 -16
- package/lib/module/SegmentedControl.js +19 -10
- package/lib/module/Slider.js +18 -9
- package/lib/module/Switch.js +21 -9
- package/lib/module/TabBar.js +18 -12
- package/lib/module/Table.js +4 -3
- package/lib/module/Tabs.js +3 -2
- package/lib/module/ai.js +18 -15
- package/lib/module/charts/BarChart.js +11 -3
- package/lib/module/internal/GlassView.js +2 -2
- package/lib/module/internal/blur.js +78 -0
- package/lib/module/internal/fallback.js +110 -20
- package/lib/module/internal/glow.js +36 -0
- package/lib/module/internal/lens.js +70 -0
- package/lib/module/internal/material.js +64 -0
- package/lib/module/internal/primitives.js +1 -0
- package/lib/module/internal/rim.js +35 -0
- package/lib/module/internal/tokens.js +34 -2
- package/lib/typescript/Message.d.ts +5 -9
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/internal/GlassView.d.ts +13 -0
- package/lib/typescript/internal/blur.d.ts +24 -0
- package/lib/typescript/internal/fallback.d.ts +27 -2
- package/lib/typescript/internal/glow.d.ts +11 -0
- package/lib/typescript/internal/lens.d.ts +47 -0
- package/lib/typescript/internal/material.d.ts +27 -0
- package/lib/typescript/internal/primitives.d.ts +2 -0
- package/lib/typescript/internal/rim.d.ts +16 -0
- package/lib/typescript/internal/tokens.d.ts +36 -0
- package/package.json +12 -3
- package/src/Bars.tsx +12 -2
- package/src/Button.tsx +16 -9
- package/src/Card.tsx +2 -2
- package/src/Dialog.tsx +37 -26
- package/src/Display.tsx +8 -5
- package/src/Feedback.tsx +36 -13
- package/src/Form.tsx +60 -40
- package/src/Forms2.tsx +65 -24
- package/src/Glass.tsx +4 -0
- package/src/Input.tsx +15 -11
- package/src/Message.tsx +15 -16
- package/src/Overlays.tsx +25 -6
- package/src/Pickers.tsx +11 -6
- package/src/SegmentedControl.tsx +33 -9
- package/src/Slider.tsx +19 -10
- package/src/Switch.tsx +24 -10
- package/src/TabBar.tsx +33 -12
- package/src/Table.tsx +4 -3
- package/src/Tabs.tsx +5 -0
- package/src/ai.tsx +28 -20
- package/src/charts/BarChart.tsx +41 -3
- package/src/index.ts +1 -0
- package/src/internal/GlassView.tsx +17 -0
- package/src/internal/blur.ts +90 -0
- package/src/internal/fallback.tsx +158 -20
- package/src/internal/glow.tsx +62 -0
- package/src/internal/lens.tsx +105 -0
- package/src/internal/material.ts +92 -0
- package/src/internal/primitives.ts +3 -0
- package/src/internal/rim.tsx +79 -0
- package/src/internal/tokens.ts +34 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// The fallback's material recipe — the web engine's surface profiles, in
|
|
2
|
+
// React Native terms.
|
|
3
|
+
//
|
|
4
|
+
// The web fits a different lens per component family (panel, control, field,
|
|
5
|
+
// overlay, hint, rail). The fallback had a single flat surface for all of
|
|
6
|
+
// them, which is why a dialog and a badge looked identical. This module turns
|
|
7
|
+
// each profile into the numbers the layered fallback needs: how strongly the
|
|
8
|
+
// backdrop is blurred, how bright the rim is, how much light sits inside the
|
|
9
|
+
// top edge, and whether the surface is lifted by a shadow.
|
|
10
|
+
//
|
|
11
|
+
// Nothing here renders. It is a table plus one resolver, so the fallback
|
|
12
|
+
// component stays a layout and the profiles stay reviewable against the web.
|
|
13
|
+
|
|
14
|
+
import { material } from "./tokens";
|
|
15
|
+
|
|
16
|
+
/** The six surfaces the web engine distinguishes. */
|
|
17
|
+
export type SurfaceProfile = "panel" | "control" | "field" | "overlay" | "hint" | "rail";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The web profile values this mapping is derived from.
|
|
21
|
+
*
|
|
22
|
+
* Kept in the same order and with the same names as the engine's table so the
|
|
23
|
+
* two can be diffed by eye: bend drives the blur strength, depth the inner
|
|
24
|
+
* highlight, and dome the rim brightness (the dome is the part of the lens
|
|
25
|
+
* that catches the light).
|
|
26
|
+
*/
|
|
27
|
+
const webProfiles: Record<
|
|
28
|
+
SurfaceProfile,
|
|
29
|
+
{ bend: number; depth: number; dome: number }
|
|
30
|
+
> = {
|
|
31
|
+
panel: { bend: 0.45, depth: 0.25, dome: 0.5 },
|
|
32
|
+
control: { bend: 0.55, depth: 0.3, dome: 0.6 },
|
|
33
|
+
field: { bend: 0.35, depth: 0.2, dome: 0.34 },
|
|
34
|
+
overlay: { bend: 0.5, depth: 0.34, dome: 0.66 },
|
|
35
|
+
hint: { bend: 0.28, depth: 0.22, dome: 0.3 },
|
|
36
|
+
rail: { bend: 0.4, depth: 0.22, dome: 0.4 },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** A resolved material for one surface, in the units React Native accepts. */
|
|
40
|
+
export interface ResolvedMaterial {
|
|
41
|
+
/** Backdrop blur intensity on expo-blur's 0–100 scale. */
|
|
42
|
+
blur: number;
|
|
43
|
+
/** Alpha of the rim's brightest (top) stop. */
|
|
44
|
+
rim: number;
|
|
45
|
+
/** Alpha of the highlight inside the top edge. */
|
|
46
|
+
highlight: number;
|
|
47
|
+
/** How far the surface is lifted, from the theme's shadow tokens. */
|
|
48
|
+
shadowOpacity: number;
|
|
49
|
+
shadowRadius: number;
|
|
50
|
+
shadowOffsetY: number;
|
|
51
|
+
/** Android's equivalent of the iOS shadow. */
|
|
52
|
+
elevation: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The reference profile: the panel is the base lens the others scale from. */
|
|
56
|
+
const BASE_BLUR = 24;
|
|
57
|
+
const BASE_DOME = webProfiles.panel.dome;
|
|
58
|
+
const BASE_DEPTH = webProfiles.panel.depth;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The material for one surface.
|
|
62
|
+
*
|
|
63
|
+
* The `clear` effect is the same stack with a thinner lens — less blur and a
|
|
64
|
+
* fainter rim — which is what the web means by clear. Reduce Transparency is
|
|
65
|
+
* handled before this call: it replaces the whole stack with a solid colour.
|
|
66
|
+
*/
|
|
67
|
+
export function materialFor(
|
|
68
|
+
profile: SurfaceProfile = "panel",
|
|
69
|
+
effect: "clear" | "regular" | "none" = "regular",
|
|
70
|
+
isDark = false,
|
|
71
|
+
): ResolvedMaterial {
|
|
72
|
+
const lens = webProfiles[profile];
|
|
73
|
+
const thin = effect === "clear" ? 0.55 : 1;
|
|
74
|
+
const rimBase = isDark ? material.rim.dark : material.rim.light;
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
blur: Math.round(BASE_BLUR * (lens.bend / webProfiles.panel.bend) * thin),
|
|
78
|
+
rim: rimBase * (lens.dome / BASE_DOME) * thin,
|
|
79
|
+
highlight: material.highlight * (lens.depth / BASE_DEPTH) * thin,
|
|
80
|
+
// The web drops every surface by 1px; overlays carry their own, deeper
|
|
81
|
+
// shadow from the component's style, which the fallback prefers when set.
|
|
82
|
+
shadowOpacity: isDark ? 0 : material.shadowOpacity.light,
|
|
83
|
+
shadowRadius: 3,
|
|
84
|
+
shadowOffsetY: 1,
|
|
85
|
+
elevation: isDark ? 0 : 1,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Whether a surface is a shadowed one at all (the hint family sits flat). */
|
|
90
|
+
export function isFlatProfile(profile: SurfaceProfile): boolean {
|
|
91
|
+
return profile === "hint";
|
|
92
|
+
}
|
|
@@ -31,6 +31,8 @@ export interface RNPrimitives {
|
|
|
31
31
|
/** Gradient and clipping nodes, for the colour picker's hue track. */
|
|
32
32
|
Defs: any;
|
|
33
33
|
LinearGradient: any;
|
|
34
|
+
/** The radial gradient the press glow is painted with. */
|
|
35
|
+
RadialGradient: any;
|
|
34
36
|
Stop: any;
|
|
35
37
|
ClipPath: any;
|
|
36
38
|
SvgText: any;
|
|
@@ -296,6 +298,7 @@ function resolve(): RNPrimitives {
|
|
|
296
298
|
Polygon: svg?.Polygon ?? fallback("polygon"),
|
|
297
299
|
Defs: svg?.Defs ?? fallback("defs"),
|
|
298
300
|
LinearGradient: svg?.LinearGradient ?? fallback("linearGradient"),
|
|
301
|
+
RadialGradient: svg?.RadialGradient ?? fallback("radialGradient"),
|
|
299
302
|
Stop: svg?.Stop ?? fallback("stop"),
|
|
300
303
|
ClipPath: svg?.ClipPath ?? fallback("clipPath"),
|
|
301
304
|
// TextInput is not an SVG primitive, but resolving it here keeps every
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The painted rim: light caught on the curved edge of a glass surface.
|
|
2
|
+
//
|
|
3
|
+
// This is the layer that makes a rounded corner *read* as rounded. The web
|
|
4
|
+
// engine paints a rim gradient into every glass element (brightest along the
|
|
5
|
+
// top edge, fading down the sides, nearly gone at the bottom), plus a soft
|
|
6
|
+
// highlight just inside the top. The fallback only had a uniform 8% edge line,
|
|
7
|
+
// which is why the owner described the corners as "not fully curved".
|
|
8
|
+
//
|
|
9
|
+
// Drawn in SVG because that is what the package already uses for its charts
|
|
10
|
+
// and share the same resolver: no new native dependency, and it works
|
|
11
|
+
// identically on iOS and Android.
|
|
12
|
+
|
|
13
|
+
import { useId } from "react";
|
|
14
|
+
|
|
15
|
+
import { primitives } from "./primitives";
|
|
16
|
+
import { material } from "./tokens";
|
|
17
|
+
|
|
18
|
+
const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } as const;
|
|
19
|
+
|
|
20
|
+
export interface GlassRimProps {
|
|
21
|
+
/** The surface's corner radius, so the rim follows the shape. */
|
|
22
|
+
radius: number;
|
|
23
|
+
/** Alpha of the brightest (top) part of the rim. */
|
|
24
|
+
rim: number;
|
|
25
|
+
/** Alpha of the highlight inside the top edge. */
|
|
26
|
+
highlight: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The rim light and top highlight of one surface.
|
|
31
|
+
*
|
|
32
|
+
* Both are stacked stops of a vertical gradient in the same colour: the eye
|
|
33
|
+
* reads the brightest edge as a lit curve and the falloff as the curve turning
|
|
34
|
+
* away from the light.
|
|
35
|
+
*/
|
|
36
|
+
export function GlassRim({ radius, rim, highlight }: GlassRimProps) {
|
|
37
|
+
const { Svg, Defs, Rect, LinearGradient, Stop } = primitives();
|
|
38
|
+
const key = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
39
|
+
const rimId = `rim-${key}`;
|
|
40
|
+
const highlightId = `top-${key}`;
|
|
41
|
+
// SVG clamps rx/ry to half the side, so a pill radius simply becomes a pill.
|
|
42
|
+
const rx = Math.max(0, radius - 0.5);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Svg width="100%" height="100%" style={fill} pointerEvents="none">
|
|
46
|
+
<Defs>
|
|
47
|
+
<LinearGradient id={rimId} x1="0" y1="0" x2="0" y2="1">
|
|
48
|
+
<Stop offset="0" stopColor={material.rimColor} stopOpacity={rim} />
|
|
49
|
+
<Stop offset="0.55" stopColor={material.rimColor} stopOpacity={rim * 0.35} />
|
|
50
|
+
<Stop offset="1" stopColor={material.rimColor} stopOpacity={rim * 0.08} />
|
|
51
|
+
</LinearGradient>
|
|
52
|
+
<LinearGradient id={highlightId} x1="0" y1="0" x2="0" y2="1">
|
|
53
|
+
<Stop offset="0" stopColor={material.rimColor} stopOpacity={highlight} />
|
|
54
|
+
<Stop offset="1" stopColor={material.rimColor} stopOpacity={0} />
|
|
55
|
+
</LinearGradient>
|
|
56
|
+
</Defs>
|
|
57
|
+
<Rect
|
|
58
|
+
x={0.5}
|
|
59
|
+
y={0.5}
|
|
60
|
+
width="99%"
|
|
61
|
+
height="99%"
|
|
62
|
+
rx={rx}
|
|
63
|
+
ry={rx}
|
|
64
|
+
fill="none"
|
|
65
|
+
stroke={`url(#${rimId})`}
|
|
66
|
+
strokeWidth={1}
|
|
67
|
+
/>
|
|
68
|
+
<Rect
|
|
69
|
+
x={1}
|
|
70
|
+
y={1}
|
|
71
|
+
width="98%"
|
|
72
|
+
height="40%"
|
|
73
|
+
rx={Math.max(0, rx - 1)}
|
|
74
|
+
ry={Math.max(0, rx - 1)}
|
|
75
|
+
fill={`url(#${highlightId})`}
|
|
76
|
+
/>
|
|
77
|
+
</Svg>
|
|
78
|
+
);
|
|
79
|
+
}
|
package/src/internal/tokens.ts
CHANGED
|
@@ -5,6 +5,7 @@ export const radii = {
|
|
|
5
5
|
md: tokenRadii.md.number,
|
|
6
6
|
lg: tokenRadii.lg.number,
|
|
7
7
|
xl: tokenRadii.xl.number,
|
|
8
|
+
stack: tokenRadii.stack.number,
|
|
8
9
|
pill: tokenRadii.pill.number,
|
|
9
10
|
};
|
|
10
11
|
|
|
@@ -71,8 +72,16 @@ export const colors = {
|
|
|
71
72
|
muted: "#3C3C4399",
|
|
72
73
|
glass: "rgba(255, 255, 255, 0.6)",
|
|
73
74
|
glassActive: "rgba(236, 236, 240, 0.85)",
|
|
75
|
+
/**
|
|
76
|
+
* The near-solid surface the web uses where legibility beats translucency:
|
|
77
|
+
* menus and toggle groups. A glass surface underneath text that must be
|
|
78
|
+
* read at a glance is the one place the web deliberately goes opaque-ish.
|
|
79
|
+
*/
|
|
80
|
+
surface: "rgba(255, 255, 255, 0.86)",
|
|
74
81
|
edge: "rgba(0, 0, 0, 0.08)",
|
|
75
|
-
separator:
|
|
82
|
+
// The agreed separator value: the web CSS one (0.15 / 0.16 dark), so the
|
|
83
|
+
// three files that carried three different light values now agree.
|
|
84
|
+
separator: "rgba(60, 60, 67, 0.15)",
|
|
76
85
|
fill: "#0088FF",
|
|
77
86
|
destructive: "#FF3B30",
|
|
78
87
|
on: "#34C759",
|
|
@@ -105,6 +114,7 @@ export const colors = {
|
|
|
105
114
|
muted: "#EBEBF599",
|
|
106
115
|
glass: "rgba(40, 40, 40, 0.62)",
|
|
107
116
|
glassActive: "rgba(70, 70, 70, 0.62)",
|
|
117
|
+
surface: "rgba(40, 40, 40, 0.86)",
|
|
108
118
|
edge: "rgba(255, 255, 255, 0.08)",
|
|
109
119
|
separator: "rgba(235, 235, 245, 0.16)",
|
|
110
120
|
fill: "#0091FF",
|
|
@@ -127,6 +137,29 @@ export const colors = {
|
|
|
127
137
|
/** Keeps the shared token file honest if a colour is added there first. */
|
|
128
138
|
export type ThemeColors = typeof colors.light;
|
|
129
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The values the fallback's material layers are built from.
|
|
142
|
+
*
|
|
143
|
+
* These are the web engine's numbers, not new inventions: the rim shine is the
|
|
144
|
+
* web's `--gl-rim` brightness (0.30 light / 0.13 dark), the top highlight and
|
|
145
|
+
* press glow are the web overlay alphas, and the drop shadow is the web's
|
|
146
|
+
* `0 1px 3px` black 0.06. They live here, next to the colours, so no component
|
|
147
|
+
* carries a material literal of its own.
|
|
148
|
+
*/
|
|
149
|
+
export const material = {
|
|
150
|
+
/** Maximum alpha of the painted rim light, per theme (web: shine). */
|
|
151
|
+
rim: { light: 0.3, dark: 0.13 },
|
|
152
|
+
/** Alpha of the soft highlight drawn inside the top edge. */
|
|
153
|
+
highlight: 0.1,
|
|
154
|
+
/** Alpha of the radial glow that fades in while a surface is held. */
|
|
155
|
+
glow: 0.035,
|
|
156
|
+
/** Shadow colour; the web drops surfaces by 1px with 6% black in light. */
|
|
157
|
+
shadowColor: "#000000",
|
|
158
|
+
shadowOpacity: { light: 0.06, dark: 0 },
|
|
159
|
+
/** The colour the rim light and the top highlight are painted in. */
|
|
160
|
+
rimColor: "#FFFFFF",
|
|
161
|
+
};
|
|
162
|
+
|
|
130
163
|
/** The semantic tone of a feedback component (Banner, Toast). */
|
|
131
164
|
export type Tone = "info" | "success" | "warning" | "error";
|
|
132
165
|
|