glacia-native 0.5.0 → 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.
Files changed (100) hide show
  1. package/LICENSE +29 -4
  2. package/README.md +27 -0
  3. package/lib/module/Bars.js +103 -9
  4. package/lib/module/Button.js +11 -8
  5. package/lib/module/Card.js +2 -2
  6. package/lib/module/Dialog.js +16 -17
  7. package/lib/module/Display.js +86 -8
  8. package/lib/module/Feedback.js +244 -21
  9. package/lib/module/Form.js +29 -33
  10. package/lib/module/Forms2.js +257 -13
  11. package/lib/module/Glass.js +2 -2
  12. package/lib/module/Input.js +12 -10
  13. package/lib/module/Message.js +84 -0
  14. package/lib/module/Overlays.js +195 -17
  15. package/lib/module/Pickers.js +16 -16
  16. package/lib/module/SegmentedControl.js +24 -11
  17. package/lib/module/Slider.js +24 -10
  18. package/lib/module/Switch.js +25 -10
  19. package/lib/module/TabBar.js +23 -13
  20. package/lib/module/Table.js +4 -3
  21. package/lib/module/Tabs.js +3 -2
  22. package/lib/module/ai.js +26 -18
  23. package/lib/module/charts/BarChart.js +11 -3
  24. package/lib/module/index.js +23 -2
  25. package/lib/module/internal/GlassContainer.js +54 -0
  26. package/lib/module/internal/GlassView.js +10 -2
  27. package/lib/module/internal/a11y.js +94 -0
  28. package/lib/module/internal/blur.js +78 -0
  29. package/lib/module/internal/fallback.js +120 -19
  30. package/lib/module/internal/glass-routing.js +7 -0
  31. package/lib/module/internal/glow.js +36 -0
  32. package/lib/module/internal/haptics.js +54 -0
  33. package/lib/module/internal/lens.js +70 -0
  34. package/lib/module/internal/material.js +64 -0
  35. package/lib/module/internal/motion.js +10 -1
  36. package/lib/module/internal/primitives.js +70 -4
  37. package/lib/module/internal/rim.js +35 -0
  38. package/lib/module/internal/tokens.js +80 -2
  39. package/lib/typescript/Bars.d.ts +67 -0
  40. package/lib/typescript/Display.d.ts +59 -0
  41. package/lib/typescript/Feedback.d.ts +58 -0
  42. package/lib/typescript/Forms2.d.ts +81 -0
  43. package/lib/typescript/Message.d.ts +67 -0
  44. package/lib/typescript/Overlays.d.ts +41 -0
  45. package/lib/typescript/SegmentedControl.d.ts +2 -0
  46. package/lib/typescript/Slider.d.ts +2 -0
  47. package/lib/typescript/Switch.d.ts +2 -0
  48. package/lib/typescript/TabBar.d.ts +2 -0
  49. package/lib/typescript/index.d.ts +9 -6
  50. package/lib/typescript/internal/GlassContainer.d.ts +37 -0
  51. package/lib/typescript/internal/GlassView.d.ts +21 -0
  52. package/lib/typescript/internal/a11y.d.ts +19 -0
  53. package/lib/typescript/internal/blur.d.ts +24 -0
  54. package/lib/typescript/internal/fallback.d.ts +32 -2
  55. package/lib/typescript/internal/glass-routing.d.ts +10 -0
  56. package/lib/typescript/internal/glow.d.ts +11 -0
  57. package/lib/typescript/internal/haptics.d.ts +7 -0
  58. package/lib/typescript/internal/lens.d.ts +47 -0
  59. package/lib/typescript/internal/material.d.ts +27 -0
  60. package/lib/typescript/internal/motion.d.ts +4 -0
  61. package/lib/typescript/internal/primitives.d.ts +23 -0
  62. package/lib/typescript/internal/rim.d.ts +16 -0
  63. package/lib/typescript/internal/tokens.d.ts +89 -0
  64. package/package.json +12 -3
  65. package/src/Bars.tsx +239 -2
  66. package/src/Button.tsx +16 -9
  67. package/src/Card.tsx +2 -2
  68. package/src/Dialog.tsx +37 -26
  69. package/src/Display.tsx +237 -6
  70. package/src/Feedback.tsx +448 -35
  71. package/src/Form.tsx +60 -40
  72. package/src/Forms2.tsx +455 -8
  73. package/src/Glass.tsx +4 -0
  74. package/src/Input.tsx +15 -11
  75. package/src/Message.tsx +218 -0
  76. package/src/Overlays.tsx +269 -39
  77. package/src/Pickers.tsx +11 -6
  78. package/src/SegmentedControl.tsx +39 -9
  79. package/src/Slider.tsx +26 -10
  80. package/src/Switch.tsx +29 -10
  81. package/src/TabBar.tsx +39 -12
  82. package/src/Table.tsx +4 -3
  83. package/src/Tabs.tsx +5 -0
  84. package/src/ai.tsx +37 -23
  85. package/src/charts/BarChart.tsx +41 -3
  86. package/src/index.ts +43 -1
  87. package/src/internal/GlassContainer.tsx +82 -0
  88. package/src/internal/GlassView.tsx +25 -0
  89. package/src/internal/a11y.ts +105 -0
  90. package/src/internal/blur.ts +90 -0
  91. package/src/internal/fallback.tsx +170 -15
  92. package/src/internal/glass-routing.ts +17 -0
  93. package/src/internal/glow.tsx +62 -0
  94. package/src/internal/haptics.ts +59 -0
  95. package/src/internal/lens.tsx +105 -0
  96. package/src/internal/material.ts +92 -0
  97. package/src/internal/motion.ts +10 -1
  98. package/src/internal/primitives.ts +83 -4
  99. package/src/internal/rim.tsx +79 -0
  100. package/src/internal/tokens.ts +82 -1
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // Backdrop blur for the fallback material.
3
+ //
4
+ // React Native has no backdrop blur of its own. The fallback's biggest missing
5
+ // layer is exactly that: without it a surface is a translucent rectangle, not
6
+ // glass. Two community backends provide a real native blur view, and the
7
+ // package accepts either:
8
+ //
9
+ // - `expo-blur` (Expo apps; also works on web through backdrop-filter)
10
+ // - `@react-native-community/blur` (bare React Native)
11
+ //
12
+ // They are optional peer dependencies, resolved at runtime like every other
13
+ // native module in this package: a project that installs neither still gets a
14
+ // working (unblurred) fallback instead of a crash, and the jsdom test run never
15
+ // touches a native module.
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.resolveBlurView = resolveBlurView;
18
+ exports.resetBlurResolver = resetBlurResolver;
19
+ exports.blurProps = blurProps;
20
+ let resolved;
21
+ /**
22
+ * The installed blur backend, or null when neither is available.
23
+ *
24
+ * Memoised: the answer is a property of the installed modules, not of the
25
+ * render, so resolving once keeps every surface on the same backend.
26
+ */
27
+ function resolveBlurView() {
28
+ if (resolved !== undefined)
29
+ return resolved;
30
+ try {
31
+ const expo = require("expo-blur");
32
+ if (expo?.BlurView) {
33
+ resolved = { kind: "expo", View: expo.BlurView };
34
+ return resolved;
35
+ }
36
+ }
37
+ catch {
38
+ // Not installed: try the bare-React-Native backend below.
39
+ }
40
+ try {
41
+ const community = require("@react-native-community/blur");
42
+ if (community?.BlurView) {
43
+ resolved = { kind: "community", View: community.BlurView };
44
+ return resolved;
45
+ }
46
+ }
47
+ catch {
48
+ // Neither backend is installed; the fallback renders tint, rim and shadow.
49
+ }
50
+ resolved = null;
51
+ return resolved;
52
+ }
53
+ /** Clears the memoised backend. Only tests call this. */
54
+ function resetBlurResolver() {
55
+ resolved = undefined;
56
+ }
57
+ /**
58
+ * The props one backend needs to blur a surface.
59
+ *
60
+ * The two libraries name the same idea differently — expo-blur takes a 0–100
61
+ * intensity and a tint, community-blur a 0–100 amount and a blur type — so the
62
+ * mapping lives here rather than in the fallback's render. Android needs an
63
+ * explicit method on expo-blur; Dimezis is its own real-time backdrop blur.
64
+ */
65
+ function blurProps(kind, intensity, isDark) {
66
+ if (kind === "expo") {
67
+ return {
68
+ intensity,
69
+ tint: isDark ? "dark" : "light",
70
+ experimentalBlurMethod: "dimezisBlurView",
71
+ };
72
+ }
73
+ return {
74
+ // Community blur amounts are coarser; the tint carries most of the read.
75
+ blurAmount: Math.max(1, Math.round(intensity / 1.6)),
76
+ blurType: isDark ? "dark" : "light",
77
+ };
78
+ }
@@ -5,30 +5,131 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const tokens_1 = require("./tokens");
7
7
  const primitives_1 = require("./primitives");
8
+ const a11y_1 = require("./a11y");
9
+ const blur_1 = require("./blur");
10
+ const glow_1 = require("./glow");
11
+ const material_1 = require("./material");
12
+ const rim_1 = require("./rim");
13
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 };
14
+ /** Layout and paint properties that belong to the surface itself. */
15
+ const HOISTED = new Set([
16
+ "backgroundColor",
17
+ "shadowColor",
18
+ "shadowOpacity",
19
+ "shadowRadius",
20
+ "shadowOffset",
21
+ "elevation",
22
+ ]);
23
+ /** Merges a style prop into one object; a function style is not resolvable here. */
24
+ function flattenStyle(style) {
25
+ if (!style)
26
+ return {};
27
+ if (Array.isArray(style)) {
28
+ return style.reduce((acc, entry) => ({ ...acc, ...flattenStyle(entry) }), {});
29
+ }
30
+ if (typeof style === "function")
31
+ return {};
32
+ return style;
33
+ }
8
34
  /**
9
35
  * Glacia's own glass surface for every platform where Apple's material is not
10
36
  * available: Android, iOS before 26, and Expo Go.
11
37
  *
12
- * It renders the resolver's real React Native `View` with the same shape and
13
- * layout as the native glass, so switching branches never shifts the layout.
38
+ * The material is the web one, rebuilt in layers, because a single flat View
39
+ * could never read as glass:
40
+ *
41
+ * 1. backdrop blur (`expo-blur` / `@react-native-community/blur` when either
42
+ * is installed — a real `UIVisualEffectView` on iOS 17),
43
+ * 2. the tint token on top of the blurred backdrop,
44
+ * 3. a painted rim light, brightest on the top edge, so corners read as curved,
45
+ * 4. a soft highlight just inside the top edge,
46
+ * 5. the 0.5px edge line, and
47
+ * 6. a drop shadow on the surface itself (outside the clipped layer).
48
+ *
49
+ * All of that lives in an absolutely-positioned, clipped layer behind the
50
+ * children. The caller's style stays on the outer View, so heights, padding and
51
+ * flex behaviour are byte-identical to the old flat implementation and
52
+ * switching branches never shifts the layout.
53
+ *
54
+ * Reduce Transparency still replaces the whole thing with a solid colour: the
55
+ * preference exists precisely to remove see-through surfaces.
14
56
  */
15
- exports.FallbackGlassView = (0, react_1.forwardRef)(function FallbackGlassView({ effect = "regular", tintColor, testID, style, children, isDark = false, ...props }, ref) {
57
+ exports.FallbackGlassView = (0, react_1.forwardRef)(function FallbackGlassView({ effect = "regular", surface = "panel", tintColor, pressed, testID, style, children, isDark = false, reducedTransparency, ...props }, ref) {
16
58
  const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
17
59
  const { View } = (0, primitives_1.primitives)();
18
- const bg = effect === "none"
19
- ? "transparent"
20
- : effect === "clear"
21
- ? isDark
22
- ? "rgba(28, 28, 30, 0.35)"
23
- : "rgba(255, 255, 255, 0.35)"
24
- : tintColor || themeColors.glass;
25
- const containerStyle = {
26
- backgroundColor: bg,
27
- borderColor: themeColors.edge,
28
- borderWidth: 0.5,
29
- borderRadius: tokens_1.radii.md,
30
- overflow: "hidden",
31
- ...style,
32
- };
33
- return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: containerStyle, ...props, children: children }));
60
+ // Reduce Transparency means the translucent material is replaced by a solid
61
+ // colour — the point of the preference is to remove see-through surfaces.
62
+ const systemReduced = (0, a11y_1.useReducedTransparency)();
63
+ const solid = reducedTransparency ?? systemReduced;
64
+ const flat = flattenStyle(style);
65
+ const radius = typeof flat.borderRadius === "number" ? flat.borderRadius : tokens_1.radii.md;
66
+ const explicitBackground = typeof flat.backgroundColor === "string" ? flat.backgroundColor : undefined;
67
+ // `effect="none"` is a deliberate "no surface here" (a ghost button); it
68
+ // paints nothing at all, exactly as before.
69
+ const bare = effect === "none";
70
+ const layered = !solid && !bare;
71
+ const profile = (0, material_1.materialFor)(surface, bare ? "regular" : effect, isDark);
72
+ const blur = layered ? (0, blur_1.resolveBlurView)() : null;
73
+ const surfaceStyle = { ...flat };
74
+ for (const key of HOISTED)
75
+ delete surfaceStyle[key];
76
+ // The edge is the web's 0.5px inset line. A component that draws only one
77
+ // edge (AppBar's scroll edge) keeps its own widths; a component that asked
78
+ // for a 1px box border is brought back to the hairline.
79
+ const perEdge = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"].some((key) => typeof flat[key] === "number");
80
+ if (typeof flat.borderWidth === "number") {
81
+ surfaceStyle.borderWidth = Math.min(flat.borderWidth, 0.5);
82
+ }
83
+ else if (!perEdge) {
84
+ surfaceStyle.borderWidth = 0.5;
85
+ }
86
+ surfaceStyle.borderColor = flat.borderColor ?? themeColors.edge;
87
+ surfaceStyle.borderRadius = radius;
88
+ if (solid) {
89
+ // The solid path is the old single flat view: opaque, no layers, and the
90
+ // caller's own background (a filled button) still wins over the token.
91
+ surfaceStyle.backgroundColor =
92
+ flat.backgroundColor ??
93
+ (effect === "clear" && tintColor ? tintColor : themeColors.glassSolid);
94
+ surfaceStyle.overflow = "hidden";
95
+ }
96
+ else if (bare) {
97
+ surfaceStyle.backgroundColor = flat.backgroundColor ?? "transparent";
98
+ surfaceStyle.overflow = "hidden";
99
+ }
100
+ else {
101
+ // Layered material. An opaque background is a filled control, not glass:
102
+ // it still gets a rim so it does not read as a sticker, but no blur tint.
103
+ const opaque = Boolean(explicitBackground);
104
+ const tint = opaque
105
+ ? explicitBackground
106
+ : effect === "clear"
107
+ ? isDark
108
+ ? "rgba(28, 28, 30, 0.35)"
109
+ : "rgba(255, 255, 255, 0.35)"
110
+ : tintColor || themeColors.glass;
111
+ const rim = opaque ? profile.rim * 0.5 : profile.rim;
112
+ const highlight = opaque ? profile.highlight * 0.5 : profile.highlight;
113
+ const blurrable = Boolean(blur) && !opaque;
114
+ const shadowOpacity = typeof flat.shadowOpacity === "number" ? flat.shadowOpacity : profile.shadowOpacity;
115
+ const shadowRadius = typeof flat.shadowRadius === "number" ? flat.shadowRadius : profile.shadowRadius;
116
+ const shadowHeight = typeof flat.shadowOffset?.height === "number"
117
+ ? flat.shadowOffset.height
118
+ : profile.shadowOffsetY;
119
+ // The hint family (badges, tooltips) sits flush with the page on the web.
120
+ const lifts = !(0, material_1.isFlatProfile)(surface) && shadowOpacity > 0;
121
+ return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: [
122
+ surfaceStyle,
123
+ lifts
124
+ ? {
125
+ shadowColor: tokens_1.material.shadowColor,
126
+ shadowOpacity,
127
+ shadowRadius,
128
+ shadowOffset: { width: 0, height: shadowHeight },
129
+ elevation: typeof flat.elevation === "number" ? flat.elevation : profile.elevation,
130
+ }
131
+ : null,
132
+ ], ...props, children: [(0, jsx_runtime_1.jsxs)(View, { testID: testID ? `${testID}-material` : undefined, style: [fill, { borderRadius: radius, overflow: "hidden" }], pointerEvents: "none", children: [blurrable && blur ? ((0, jsx_runtime_1.jsx)(blur.View, { ...(0, blur_1.blurProps)(blur.kind, profile.blur, isDark), style: [fill, { borderRadius: radius }] })) : null, (0, jsx_runtime_1.jsx)(View, { testID: testID ? `${testID}-tint` : undefined, style: [fill, { backgroundColor: tint }] }), (0, jsx_runtime_1.jsx)(rim_1.GlassRim, { radius: radius, rim: rim, highlight: highlight }), pressed !== undefined ? (0, jsx_runtime_1.jsx)(glow_1.SurfaceGlow, { active: pressed }) : null] }), children] }));
133
+ }
134
+ return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: surfaceStyle, ...props, children: children }));
34
135
  });
@@ -24,9 +24,16 @@ exports.defaultRouter = defaultRouter;
24
24
  */
25
25
  function routerFor(module) {
26
26
  const view = module?.LiquidGlassView ?? null;
27
+ const container = module?.LiquidGlassContainerView ?? null;
27
28
  return {
29
+ // A module that reports support but lacks the container still renders real
30
+ // glass; the container is only needed by GlassContainer, which falls back
31
+ // when it is missing.
28
32
  supported: Boolean(module?.isLiquidGlassSupported) && Boolean(view),
29
33
  LiquidGlassView: view,
34
+ // The container merges only when the material itself is available; a
35
+ // container without the view would have nothing to merge.
36
+ LiquidGlassContainerView: container,
30
37
  };
31
38
  }
32
39
  /**
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SurfaceGlow = SurfaceGlow;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // The specular press highlight, painted as a radial glow.
6
+ //
7
+ // The web material fades a 240px radial white highlight in under the finger
8
+ // for 220ms whenever a glass control is held. That is what makes a press feel
9
+ // like touching a lens rather than a flat sticker. The fallback had only an
10
+ // opacity dip, so controls never looked held.
11
+ //
12
+ // The glow lives inside the clipped material layer, so it follows the same
13
+ // radius as the surface and can never spill outside it.
14
+ const react_1 = require("react");
15
+ const motion_1 = require("./motion");
16
+ const primitives_1 = require("./primitives");
17
+ const tokens_1 = require("./tokens");
18
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 };
19
+ /**
20
+ * A radial highlight that fades in while `active`.
21
+ *
22
+ * Motion uses the package's spring tokens and respects Reduce Motion: with the
23
+ * preference on, the glow appears at its end state rather than fading.
24
+ */
25
+ function SurfaceGlow({ active }) {
26
+ const { Svg, Defs, RadialGradient, Stop, Rect, Animated } = (0, primitives_1.primitives)();
27
+ const { value, animated } = (0, motion_1.useSpring)(active ? 1 : 0, "snappy");
28
+ const gradientId = `glow-${(0, react_1.useId)().replace(/[^a-zA-Z0-9_-]/g, "")}`;
29
+ const painting = ((0, jsx_runtime_1.jsxs)(Svg, { width: "100%", height: "100%", style: fill, pointerEvents: "none", children: [(0, jsx_runtime_1.jsx)(Defs, { children: (0, jsx_runtime_1.jsxs)(RadialGradient, { id: gradientId, cx: "50%", cy: "50%", r: "50%", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: tokens_1.material.glow }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: 0 })] }) }), (0, jsx_runtime_1.jsx)(Rect, { x: "0", y: "0", width: "100%", height: "100%", fill: `url(#${gradientId})` })] }));
30
+ // Off-device there is no Animated API; the settled state is what a preview
31
+ // should show, exactly as `useSpring` documents.
32
+ if (!animated) {
33
+ return ((0, jsx_runtime_1.jsx)(Animated.View, { style: [fill, { opacity: active ? 1 : 0 }], pointerEvents: "none", children: painting }));
34
+ }
35
+ return ((0, jsx_runtime_1.jsx)(Animated.View, { style: [fill, { opacity: value }], pointerEvents: "none", children: painting }));
36
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // Haptic feedback for controls.
3
+ //
4
+ // Native iOS controls tick as you move them — a switch toggling, a segment
5
+ // being chosen. Glacia's controls are drawn by the library, so they have to
6
+ // ask for that tick themselves.
7
+ //
8
+ // There is no single React Native API for it, and Glacia does not take a
9
+ // dependency for one. Instead this tries, in order, the APIs that ship with
10
+ // common Expo and React Native projects, and does nothing where none is
11
+ // present. A missing tick must never break a control, so every call is
12
+ // wrapped: these helpers cannot throw.
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.hapticSelection = hapticSelection;
15
+ const primitives_1 = require("./primitives");
16
+ function resolveTick() {
17
+ // Expo's haptics module, when the app has it installed.
18
+ try {
19
+ const expo = require("expo-haptics");
20
+ if (expo?.selectionAsync) {
21
+ return () => {
22
+ expo.selectionAsync().catch?.(() => { });
23
+ };
24
+ }
25
+ }
26
+ catch {
27
+ // Not an Expo project, or expo-haptics is not installed: try the next one.
28
+ }
29
+ // React Native's own Vibration API: a 10 ms buzz is the closest thing to a
30
+ // selection tick that ships with core. It is a coarser feel, but it is real
31
+ // feedback on a device that has no better module.
32
+ const { Vibration } = (0, primitives_1.primitives)();
33
+ if (Vibration?.vibrate) {
34
+ return () => {
35
+ Vibration.vibrate(10);
36
+ };
37
+ }
38
+ return null;
39
+ }
40
+ /**
41
+ * One selection tick, for a control whose value just changed by one step.
42
+ *
43
+ * Silent where no haptics API is available (the DOM preview, a test run, a
44
+ * device without a vibration motor). Never throws.
45
+ */
46
+ function hapticSelection() {
47
+ try {
48
+ const tick = resolveTick();
49
+ tick?.();
50
+ }
51
+ catch {
52
+ // Haptics are a nicety; a failure here must not surface to the user.
53
+ }
54
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lensFill = void 0;
4
+ exports.lensShadow = lensShadow;
5
+ exports.LensRim = LensRim;
6
+ exports.SelectedLens = SelectedLens;
7
+ exports.rowLensStyle = rowLensStyle;
8
+ const jsx_runtime_1 = require("react/jsx-runtime");
9
+ const tokens_1 = require("./tokens");
10
+ const primitives_1 = require("./primitives");
11
+ const rim_1 = require("./rim");
12
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 };
13
+ /**
14
+ * How far a lens sits above its row.
15
+ *
16
+ * Shallower than a panel's shadow: a lens is inside a surface that already
17
+ * floats, so it needs contact, not altitude.
18
+ */
19
+ function lensShadow(isDark) {
20
+ return {
21
+ shadowColor: tokens_1.material.shadowColor,
22
+ shadowOpacity: isDark ? 0 : 0.1,
23
+ shadowRadius: 8,
24
+ shadowOffset: { width: 0, height: 2 },
25
+ };
26
+ }
27
+ /**
28
+ * The rim of a lens, on its own.
29
+ *
30
+ * For indicators that are already animated views and cannot become a
31
+ * `SelectedLens`: they keep their own transform, and this paints the light on
32
+ * top of whatever tint they already have.
33
+ */
34
+ function LensRim({ radius, isDark }) {
35
+ const { View } = (0, primitives_1.primitives)();
36
+ const rim = (isDark ? tokens_1.material.rim.dark : tokens_1.material.rim.light) * 0.66;
37
+ return ((0, jsx_runtime_1.jsx)(View, { style: { ...fill, overflow: "hidden", borderRadius: radius }, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(rim_1.GlassRim, { radius: radius, rim: rim, highlight: tokens_1.material.highlight * 0.7 }) }));
38
+ }
39
+ /**
40
+ * A selected state, drawn as the web's lens.
41
+ *
42
+ * Rendered as an absolutely positioned overlay so it never changes the layout
43
+ * of the row it marks: parents keep their padding and press handling, and the
44
+ * content paints above it by sibling order.
45
+ */
46
+ function SelectedLens({ radius, isDark, style, children, testID }) {
47
+ const { View } = (0, primitives_1.primitives)();
48
+ const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
49
+ return ((0, jsx_runtime_1.jsxs)(View, { testID: testID, pointerEvents: "none", style: [
50
+ {
51
+ borderRadius: radius,
52
+ backgroundColor: theme.glassActive,
53
+ ...lensShadow(isDark),
54
+ },
55
+ style,
56
+ ], children: [(0, jsx_runtime_1.jsx)(LensRim, { radius: radius, isDark: isDark }), children] }));
57
+ }
58
+ /** The lens overlay for a row: inset from the panel's edges, full width inside. */
59
+ function rowLensStyle(radius, inset = 6) {
60
+ return {
61
+ position: "absolute",
62
+ top: 2,
63
+ bottom: 2,
64
+ left: inset,
65
+ right: inset,
66
+ borderRadius: radius,
67
+ };
68
+ }
69
+ /** A pill lens filling its own box, for indicators pinned to a control. */
70
+ exports.lensFill = { ...fill, borderRadius: tokens_1.radii.pill };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ // The fallback's material recipe — the web engine's surface profiles, in
3
+ // React Native terms.
4
+ //
5
+ // The web fits a different lens per component family (panel, control, field,
6
+ // overlay, hint, rail). The fallback had a single flat surface for all of
7
+ // them, which is why a dialog and a badge looked identical. This module turns
8
+ // each profile into the numbers the layered fallback needs: how strongly the
9
+ // backdrop is blurred, how bright the rim is, how much light sits inside the
10
+ // top edge, and whether the surface is lifted by a shadow.
11
+ //
12
+ // Nothing here renders. It is a table plus one resolver, so the fallback
13
+ // component stays a layout and the profiles stay reviewable against the web.
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.materialFor = materialFor;
16
+ exports.isFlatProfile = isFlatProfile;
17
+ const tokens_1 = require("./tokens");
18
+ /**
19
+ * The web profile values this mapping is derived from.
20
+ *
21
+ * Kept in the same order and with the same names as the engine's table so the
22
+ * two can be diffed by eye: bend drives the blur strength, depth the inner
23
+ * highlight, and dome the rim brightness (the dome is the part of the lens
24
+ * that catches the light).
25
+ */
26
+ const webProfiles = {
27
+ panel: { bend: 0.45, depth: 0.25, dome: 0.5 },
28
+ control: { bend: 0.55, depth: 0.3, dome: 0.6 },
29
+ field: { bend: 0.35, depth: 0.2, dome: 0.34 },
30
+ overlay: { bend: 0.5, depth: 0.34, dome: 0.66 },
31
+ hint: { bend: 0.28, depth: 0.22, dome: 0.3 },
32
+ rail: { bend: 0.4, depth: 0.22, dome: 0.4 },
33
+ };
34
+ /** The reference profile: the panel is the base lens the others scale from. */
35
+ const BASE_BLUR = 24;
36
+ const BASE_DOME = webProfiles.panel.dome;
37
+ const BASE_DEPTH = webProfiles.panel.depth;
38
+ /**
39
+ * The material for one surface.
40
+ *
41
+ * The `clear` effect is the same stack with a thinner lens — less blur and a
42
+ * fainter rim — which is what the web means by clear. Reduce Transparency is
43
+ * handled before this call: it replaces the whole stack with a solid colour.
44
+ */
45
+ function materialFor(profile = "panel", effect = "regular", isDark = false) {
46
+ const lens = webProfiles[profile];
47
+ const thin = effect === "clear" ? 0.55 : 1;
48
+ const rimBase = isDark ? tokens_1.material.rim.dark : tokens_1.material.rim.light;
49
+ return {
50
+ blur: Math.round(BASE_BLUR * (lens.bend / webProfiles.panel.bend) * thin),
51
+ rim: rimBase * (lens.dome / BASE_DOME) * thin,
52
+ highlight: tokens_1.material.highlight * (lens.depth / BASE_DEPTH) * thin,
53
+ // The web drops every surface by 1px; overlays carry their own, deeper
54
+ // shadow from the component's style, which the fallback prefers when set.
55
+ shadowOpacity: isDark ? 0 : tokens_1.material.shadowOpacity.light,
56
+ shadowRadius: 3,
57
+ shadowOffsetY: 1,
58
+ elevation: isDark ? 0 : 1,
59
+ };
60
+ }
61
+ /** Whether a surface is a shadowed one at all (the hint family sits flat). */
62
+ function isFlatProfile(profile) {
63
+ return profile === "hint";
64
+ }
@@ -7,10 +7,14 @@
7
7
  // does not pass `isDark`, so a theme-aware app needs no extra prop threading.
8
8
  // - `useSpring` animates a number towards its target with the package's spring
9
9
  // tokens through React Native's Animated API. No CSS, no timers of our own.
10
+ // - Motion respects the system's Reduce Motion preference: when it is on, the
11
+ // value settles at its target instead of animating. Doing it here means every
12
+ // animation built on `useSpring` complies without repeating the check.
10
13
  Object.defineProperty(exports, "__esModule", { value: true });
11
14
  exports.useIsDark = useIsDark;
12
15
  exports.useSpring = useSpring;
13
16
  const react_1 = require("react");
17
+ const a11y_1 = require("./a11y");
14
18
  const primitives_1 = require("./primitives");
15
19
  const tokens_1 = require("./tokens");
16
20
  /**
@@ -29,10 +33,15 @@ function useIsDark(isDark) {
29
33
  * on this platform. A caller that gets `animated === false` renders the target
30
34
  * directly, so the DOM preview and tests show the settled state rather than an
31
35
  * animation the environment cannot advance.
36
+ *
37
+ * Reduce Motion turns this into the same case: `animated` is false and the
38
+ * value is already at its target, so the component jumps to its end state
39
+ * rather than playing a transition the user asked not to see.
32
40
  */
33
41
  function useSpring(target, spring = "snappy") {
34
42
  const { Animated, isNative } = (0, primitives_1.primitives)();
35
- const animated = Boolean(isNative && Animated?.Value && Animated?.spring);
43
+ const reducedMotion = (0, a11y_1.useReducedMotion)();
44
+ const animated = Boolean(isNative && Animated?.Value && Animated?.spring) && !reducedMotion;
36
45
  // Off-device there is no Animated; a plain ref keeps the call sites identical.
37
46
  const value = (0, react_1.useRef)(null);
38
47
  if (value.current === null) {
@@ -181,15 +181,23 @@ function resolve() {
181
181
  };
182
182
  /** An image that reads its remote source in the DOM preview. */
183
183
  function imageFallback(props) {
184
- const { source, accessibilityLabel, style, onError } = props ?? {};
184
+ const { source, accessibilityLabel, accessibilityRole, style, onError, onLoad, testID, ...rest } = props ?? {};
185
185
  const { createElement } = require("react");
186
+ const source_ = typeof source === "number" ? undefined : source?.uri;
186
187
  return createElement("img", {
187
- src: source?.uri,
188
+ src: source_,
189
+ // `alt` covers the visible-description case; `aria-label` is what queries
190
+ // and screen readers in the preview read, so both are set.
188
191
  alt: accessibilityLabel ?? "",
192
+ "aria-label": accessibilityLabel,
193
+ "aria-role": accessibilityRole,
194
+ "data-testid": testID,
189
195
  style: toDomStyle(style),
190
- // A broken source must reach the component the same way it does on a
191
- // device, or a fallback (initials, placeholder) can never render.
196
+ // Load and error must reach the component the way they do on a device,
197
+ // or the placeholder and the fallback can never render in the preview.
192
198
  onError,
199
+ onLoad,
200
+ ...rest,
193
201
  });
194
202
  }
195
203
  const SvgComponent = svg?.default ?? fallback("svg");
@@ -205,6 +213,11 @@ function resolve() {
205
213
  Circle: svg?.Circle ?? fallback("circle"),
206
214
  Rect: svg?.Rect ?? fallback("rect"),
207
215
  Polygon: svg?.Polygon ?? fallback("polygon"),
216
+ Defs: svg?.Defs ?? fallback("defs"),
217
+ LinearGradient: svg?.LinearGradient ?? fallback("linearGradient"),
218
+ RadialGradient: svg?.RadialGradient ?? fallback("radialGradient"),
219
+ Stop: svg?.Stop ?? fallback("stop"),
220
+ ClipPath: svg?.ClipPath ?? fallback("clipPath"),
208
221
  // TextInput is not an SVG primitive, but resolving it here keeps every
209
222
  // component on one runtime-resolution path instead of two.
210
223
  TextInput: rn?.TextInput ?? fallback("input"),
@@ -222,6 +235,18 @@ function resolve() {
222
235
  isNative: Boolean(rn?.View),
223
236
  PanResponder: rn?.PanResponder ?? panResponderShim(),
224
237
  useColorScheme: rn?.useColorScheme ?? null,
238
+ // AccessibilityInfo and Vibration are only meaningful on a device; both
239
+ // are null off it, and their callers already treat absence as "off".
240
+ AccessibilityInfo: rn?.AccessibilityInfo ?? null,
241
+ Vibration: rn?.Vibration ?? null,
242
+ // Off-device there is no window; the DOM preview reports the viewport when
243
+ // it can and a conventional phone size otherwise. Snap points are
244
+ // fractions, so any consistent height yields the same proportions.
245
+ useWindowDimensions: rn?.useWindowDimensions ??
246
+ (() => {
247
+ const view = typeof globalThis !== "undefined" ? globalThis.window : undefined;
248
+ return { width: view?.innerWidth ?? 390, height: view?.innerHeight ?? 800 };
249
+ }),
225
250
  };
226
251
  }
227
252
  /**
@@ -373,6 +398,39 @@ const LENGTH_PROPS = new Set([
373
398
  "gap",
374
399
  ]);
375
400
  /** Converts an RN style object to DOM-compatible CSS. */
401
+ /**
402
+ * Rewrites React Native's `transform` array into a CSS transform string.
403
+ *
404
+ * The preview is a browser, and a browser does not understand
405
+ * `[{ translateX: 12 }, { scale: 2 }]`; React Native's Shape controls and
406
+ * glass offsets would silently not move. Translating the entries here keeps the
407
+ * preview faithful to what a device shows.
408
+ */
409
+ function transformToCss(entries) {
410
+ if (!Array.isArray(entries))
411
+ return typeof entries === "string" ? entries : undefined;
412
+ const parts = [];
413
+ for (const entry of entries) {
414
+ if (!entry || typeof entry !== "object")
415
+ continue;
416
+ for (const [key, raw] of Object.entries(entry)) {
417
+ const value = typeof raw?.__getValue === "function" ? raw.__getValue() : raw;
418
+ if (typeof value !== "number")
419
+ continue;
420
+ if (key === "translateX")
421
+ parts.push(`translateX(${value}px)`);
422
+ else if (key === "translateY")
423
+ parts.push(`translateY(${value}px)`);
424
+ else if (key === "scale")
425
+ parts.push(`scale(${value})`);
426
+ else if (key === "rotate")
427
+ parts.push(`rotate(${value}deg)`);
428
+ else if (key === "rotateZ")
429
+ parts.push(`rotateZ(${value}deg)`);
430
+ }
431
+ }
432
+ return parts.length > 0 ? parts.join(" ") : undefined;
433
+ }
376
434
  function toDomStyle(style) {
377
435
  if (!style)
378
436
  return style;
@@ -386,6 +444,14 @@ function toDomStyle(style) {
386
444
  continue;
387
445
  // Animated values resolve to plain numbers off-device.
388
446
  const resolved = typeof value?.interpolate === "function" ? value.__getValue?.() : value;
447
+ if (key === "transform") {
448
+ const css = transformToCss(resolved);
449
+ // Only set it when there is something to say; an empty transform would
450
+ // override an earlier entry in a style array.
451
+ if (css)
452
+ merged[key] = css;
453
+ continue;
454
+ }
389
455
  merged[key] =
390
456
  typeof resolved === "number" && LENGTH_PROPS.has(key) ? `${resolved}px` : resolved;
391
457
  }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlassRim = GlassRim;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // The painted rim: light caught on the curved edge of a glass surface.
6
+ //
7
+ // This is the layer that makes a rounded corner *read* as rounded. The web
8
+ // engine paints a rim gradient into every glass element (brightest along the
9
+ // top edge, fading down the sides, nearly gone at the bottom), plus a soft
10
+ // highlight just inside the top. The fallback only had a uniform 8% edge line,
11
+ // which is why the owner described the corners as "not fully curved".
12
+ //
13
+ // Drawn in SVG because that is what the package already uses for its charts
14
+ // and share the same resolver: no new native dependency, and it works
15
+ // identically on iOS and Android.
16
+ const react_1 = require("react");
17
+ const primitives_1 = require("./primitives");
18
+ const tokens_1 = require("./tokens");
19
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 };
20
+ /**
21
+ * The rim light and top highlight of one surface.
22
+ *
23
+ * Both are stacked stops of a vertical gradient in the same colour: the eye
24
+ * reads the brightest edge as a lit curve and the falloff as the curve turning
25
+ * away from the light.
26
+ */
27
+ function GlassRim({ radius, rim, highlight }) {
28
+ const { Svg, Defs, Rect, LinearGradient, Stop } = (0, primitives_1.primitives)();
29
+ const key = (0, react_1.useId)().replace(/[^a-zA-Z0-9_-]/g, "");
30
+ const rimId = `rim-${key}`;
31
+ const highlightId = `top-${key}`;
32
+ // SVG clamps rx/ry to half the side, so a pill radius simply becomes a pill.
33
+ const rx = Math.max(0, radius - 0.5);
34
+ return ((0, jsx_runtime_1.jsxs)(Svg, { width: "100%", height: "100%", style: fill, pointerEvents: "none", children: [(0, jsx_runtime_1.jsxs)(Defs, { children: [(0, jsx_runtime_1.jsxs)(LinearGradient, { id: rimId, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: rim }), (0, jsx_runtime_1.jsx)(Stop, { offset: "0.55", stopColor: tokens_1.material.rimColor, stopOpacity: rim * 0.35 }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: rim * 0.08 })] }), (0, jsx_runtime_1.jsxs)(LinearGradient, { id: highlightId, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: tokens_1.material.rimColor, stopOpacity: highlight }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: tokens_1.material.rimColor, stopOpacity: 0 })] })] }), (0, jsx_runtime_1.jsx)(Rect, { x: 0.5, y: 0.5, width: "99%", height: "99%", rx: rx, ry: rx, fill: "none", stroke: `url(#${rimId})`, strokeWidth: 1 }), (0, jsx_runtime_1.jsx)(Rect, { x: 1, y: 1, width: "98%", height: "40%", rx: Math.max(0, rx - 1), ry: Math.max(0, rx - 1), fill: `url(#${highlightId})` })] }));
35
+ }