@oxy.so/bloom 23.8.0 → 23.8.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.
Files changed (117) hide show
  1. package/android/src/main/java/so/oxy/bloom/AvatarLoops.kt +293 -0
  2. package/android/src/main/java/so/oxy/bloom/AvatarSurface.kt +351 -0
  3. package/android/src/main/java/so/oxy/bloom/BloomPackage.kt +1 -1
  4. package/docs/agent-avatar.mdx +77 -1
  5. package/docs/no-nativewind.mdx +3 -1
  6. package/docs/task-catalog.json +1 -1
  7. package/docs/task-catalog.mdx +1 -1
  8. package/docs/theme.mdx +21 -0
  9. package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js +267 -111
  10. package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js.map +1 -1
  11. package/lib/commonjs/agent-avatar/VectorNativeSurface.js +75 -0
  12. package/lib/commonjs/agent-avatar/VectorNativeSurface.js.map +1 -0
  13. package/lib/commonjs/agent-avatar/vector-loop.js +161 -0
  14. package/lib/commonjs/agent-avatar/vector-loop.js.map +1 -0
  15. package/lib/commonjs/agent-avatar/vector-visibility.js +4 -1
  16. package/lib/commonjs/agent-avatar/vector-visibility.js.map +1 -1
  17. package/lib/commonjs/blur/BlurIsland.js +112 -118
  18. package/lib/commonjs/blur/BlurIsland.js.map +1 -1
  19. package/lib/commonjs/button/Button.js +12 -22
  20. package/lib/commonjs/button/Button.js.map +1 -1
  21. package/lib/commonjs/button/GroupBase.js +35 -50
  22. package/lib/commonjs/button/GroupBase.js.map +1 -1
  23. package/lib/commonjs/floating/lens/lens-frame.js +286 -0
  24. package/lib/commonjs/floating/lens/lens-frame.js.map +1 -0
  25. package/lib/commonjs/floating/lens/lens-material.js +1 -1
  26. package/lib/commonjs/page-header/PageHeader.js +24 -15
  27. package/lib/commonjs/page-header/PageHeader.js.map +1 -1
  28. package/lib/commonjs/panel-routing/expo-router/StackScene.js +1 -0
  29. package/lib/commonjs/panel-routing/expo-router/StackScene.js.map +1 -1
  30. package/lib/commonjs/surface/Surface.js +64 -193
  31. package/lib/commonjs/surface/Surface.js.map +1 -1
  32. package/lib/commonjs/tab-bar/TabBarBase.js +18 -15
  33. package/lib/commonjs/tab-bar/TabBarBase.js.map +1 -1
  34. package/lib/module/agent-avatar/VectorCharacterAvatar.js +268 -112
  35. package/lib/module/agent-avatar/VectorCharacterAvatar.js.map +1 -1
  36. package/lib/module/agent-avatar/VectorNativeSurface.js +66 -0
  37. package/lib/module/agent-avatar/VectorNativeSurface.js.map +1 -0
  38. package/lib/module/agent-avatar/vector-loop.js +150 -0
  39. package/lib/module/agent-avatar/vector-loop.js.map +1 -0
  40. package/lib/module/agent-avatar/vector-visibility.js +3 -1
  41. package/lib/module/agent-avatar/vector-visibility.js.map +1 -1
  42. package/lib/module/blur/BlurIsland.js +112 -116
  43. package/lib/module/blur/BlurIsland.js.map +1 -1
  44. package/lib/module/button/Button.js +13 -23
  45. package/lib/module/button/Button.js.map +1 -1
  46. package/lib/module/button/GroupBase.js +37 -52
  47. package/lib/module/button/GroupBase.js.map +1 -1
  48. package/lib/module/floating/lens/lens-frame.js +282 -0
  49. package/lib/module/floating/lens/lens-frame.js.map +1 -0
  50. package/lib/module/floating/lens/lens-material.js +1 -1
  51. package/lib/module/page-header/PageHeader.js +24 -15
  52. package/lib/module/page-header/PageHeader.js.map +1 -1
  53. package/lib/module/panel-routing/expo-router/StackScene.js +1 -0
  54. package/lib/module/panel-routing/expo-router/StackScene.js.map +1 -1
  55. package/lib/module/surface/Surface.js +65 -194
  56. package/lib/module/surface/Surface.js.map +1 -1
  57. package/lib/module/tab-bar/TabBarBase.js +18 -15
  58. package/lib/module/tab-bar/TabBarBase.js.map +1 -1
  59. package/lib/typescript/commonjs/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
  60. package/lib/typescript/commonjs/agent-avatar/VectorNativeSurface.d.ts +75 -0
  61. package/lib/typescript/commonjs/agent-avatar/VectorNativeSurface.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/agent-avatar/vector-loop.d.ts +93 -0
  63. package/lib/typescript/commonjs/agent-avatar/vector-loop.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/agent-avatar/vector-visibility.d.ts +2 -0
  65. package/lib/typescript/commonjs/agent-avatar/vector-visibility.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/blur/BlurIsland.d.ts +1 -1
  67. package/lib/typescript/commonjs/blur/BlurIsland.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/button/Button.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/button/GroupBase.d.ts.map +1 -1
  70. package/lib/typescript/commonjs/floating/lens/lens-frame.d.ts +52 -0
  71. package/lib/typescript/commonjs/floating/lens/lens-frame.d.ts.map +1 -0
  72. package/lib/typescript/commonjs/floating/lens/lens-material.d.ts +1 -1
  73. package/lib/typescript/commonjs/page-header/PageHeader.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/panel-routing/expo-router/StackScene.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/surface/Surface.d.ts.map +1 -1
  76. package/lib/typescript/commonjs/tab-bar/TabBarBase.d.ts.map +1 -1
  77. package/lib/typescript/module/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
  78. package/lib/typescript/module/agent-avatar/VectorNativeSurface.d.ts +75 -0
  79. package/lib/typescript/module/agent-avatar/VectorNativeSurface.d.ts.map +1 -0
  80. package/lib/typescript/module/agent-avatar/vector-loop.d.ts +93 -0
  81. package/lib/typescript/module/agent-avatar/vector-loop.d.ts.map +1 -0
  82. package/lib/typescript/module/agent-avatar/vector-visibility.d.ts +2 -0
  83. package/lib/typescript/module/agent-avatar/vector-visibility.d.ts.map +1 -1
  84. package/lib/typescript/module/blur/BlurIsland.d.ts +1 -1
  85. package/lib/typescript/module/blur/BlurIsland.d.ts.map +1 -1
  86. package/lib/typescript/module/button/Button.d.ts.map +1 -1
  87. package/lib/typescript/module/button/GroupBase.d.ts.map +1 -1
  88. package/lib/typescript/module/floating/lens/lens-frame.d.ts +52 -0
  89. package/lib/typescript/module/floating/lens/lens-frame.d.ts.map +1 -0
  90. package/lib/typescript/module/floating/lens/lens-material.d.ts +1 -1
  91. package/lib/typescript/module/page-header/PageHeader.d.ts.map +1 -1
  92. package/lib/typescript/module/panel-routing/expo-router/StackScene.d.ts.map +1 -1
  93. package/lib/typescript/module/surface/Surface.d.ts.map +1 -1
  94. package/lib/typescript/module/tab-bar/TabBarBase.d.ts.map +1 -1
  95. package/package.json +1 -1
  96. package/src/agent-avatar/VectorCharacterAvatar.tsx +327 -120
  97. package/src/agent-avatar/VectorNativeSurface.tsx +117 -0
  98. package/src/agent-avatar/vector-loop.ts +213 -0
  99. package/src/agent-avatar/vector-visibility.ts +3 -1
  100. package/src/blur/BlurIsland.tsx +16 -14
  101. package/src/button/Button.tsx +19 -36
  102. package/src/button/GroupBase.tsx +42 -56
  103. package/src/floating/lens/lens-frame.tsx +195 -0
  104. package/src/floating/lens/lens-material.ts +1 -1
  105. package/src/page-header/PageHeader.tsx +26 -13
  106. package/src/panel-routing/expo-router/StackScene.tsx +9 -0
  107. package/src/surface/Surface.tsx +13 -28
  108. package/src/tab-bar/TabBarBase.tsx +13 -8
  109. package/lib/commonjs/floating/lens/lens-button-host.js +0 -218
  110. package/lib/commonjs/floating/lens/lens-button-host.js.map +0 -1
  111. package/lib/module/floating/lens/lens-button-host.js +0 -214
  112. package/lib/module/floating/lens/lens-button-host.js.map +0 -1
  113. package/lib/typescript/commonjs/floating/lens/lens-button-host.d.ts +0 -34
  114. package/lib/typescript/commonjs/floating/lens/lens-button-host.d.ts.map +0 -1
  115. package/lib/typescript/module/floating/lens/lens-button-host.d.ts +0 -34
  116. package/lib/typescript/module/floating/lens/lens-button-host.d.ts.map +0 -1
  117. package/src/floating/lens/lens-button-host.tsx +0 -148
@@ -0,0 +1,117 @@
1
+ import * as ReactNative from 'react-native';
2
+ import {
3
+ Platform,
4
+ processColor,
5
+ UIManager,
6
+ type HostComponent,
7
+ type NativeSyntheticEvent,
8
+ type ViewProps,
9
+ } from 'react-native';
10
+ import type { VectorLoopTracks } from './vector-loop';
11
+
12
+ /** One frame as the native surface draws it: colours as native colour numbers, the viewBox as four numbers. */
13
+ export type NativeVectorFrame = {
14
+ /** Changes with every frame JS draws, so a frame equal to an older one still replaces the loop's. */
15
+ revision: number;
16
+ viewBox: number[];
17
+ /** The whole drawing's opacity (the entrance), as one layer. */
18
+ opacity: number;
19
+ paths: {
20
+ d: string;
21
+ clip?: string;
22
+ fill: number;
23
+ opacity: number;
24
+ fillOpacity: number;
25
+ stroke?: number;
26
+ strokeWidth?: number;
27
+ }[];
28
+ };
29
+ /** A complete rest loop (`VectorLoopTracks`) in the same native form. */
30
+ export type NativeVectorLoop = {
31
+ duration: number;
32
+ length: number;
33
+ viewBox: number[];
34
+ paths: {
35
+ fill: number;
36
+ fillOpacity: number;
37
+ stroke?: number;
38
+ strokeWidth?: number;
39
+ d: string[];
40
+ opacity: number[];
41
+ clip?: string[];
42
+ }[];
43
+ };
44
+ /** Plays the loop: at `epoch` (a `performance.now()` reading) the loop is `time` seconds in. */
45
+ export type NativeVectorClock = { epoch: number; time: number };
46
+
47
+ export type NativeVectorSurfaceProps = ViewProps & {
48
+ frame?: NativeVectorFrame;
49
+ /** The rest loop this surface is about: it answers `onLoop` with whether it has it. */
50
+ loopKey?: string;
51
+ /** The loop `loopKey` names, handed over once when the surface does not have it. */
52
+ loopTracks?: NativeVectorLoop;
53
+ /** Set while the surface plays the loop by itself; the JS thread draws nothing meanwhile. */
54
+ loopClock?: NativeVectorClock;
55
+ /** A non-zero id asks for a PNG of what is on screen, answered by `onCapture`. */
56
+ capture?: number;
57
+ onLoop?: (event: NativeSyntheticEvent<{ key: string; ready: boolean }>) => void;
58
+ onCapture?: (event: NativeSyntheticEvent<{ id: number; data: string | null }>) => void;
59
+ };
60
+
61
+ const NAME = 'BloomAvatarSurfaceV1';
62
+
63
+ /**
64
+ * The native avatar surface (`android/.../AvatarSurface.kt`), when the app's binary has it. It
65
+ * draws a frame with its paths parsed once, and plays a rest loop on its own frame clock, kept
66
+ * across starts: no shadow-tree commits, no bitmaps and no layout events per frame. A JS-only
67
+ * update keeps the SVG drawing until the binary is rebuilt; the web always draws SVG.
68
+ */
69
+ function resolveSurface(): HostComponent<NativeVectorSurfaceProps> | null {
70
+ if (Platform.OS === 'web') return null;
71
+ try {
72
+ if (!UIManager?.getViewManagerConfig?.(NAME)) return null;
73
+ // Through the namespace: react-native-web has no `requireNativeComponent` export.
74
+ return ReactNative.requireNativeComponent<NativeVectorSurfaceProps>(NAME);
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+ export const VectorNativeSurface = resolveSurface();
80
+
81
+ const color = (value: string): number => {
82
+ const processed = processColor(value);
83
+ return typeof processed === 'number' ? processed : 0xff000000;
84
+ };
85
+ /** A viewBox string as four numbers. */
86
+ export const viewBoxNumbers = (viewBox: string): number[] =>
87
+ viewBox
88
+ .trim()
89
+ .split(/[\s,]+/)
90
+ .map(Number);
91
+
92
+ /** The native form of one drawn path's paint. */
93
+ export function nativePaint(path: { fill: string; stroke?: string; strokeWidth?: number }): {
94
+ fill: number;
95
+ stroke?: number;
96
+ strokeWidth?: number;
97
+ } {
98
+ return path.stroke === undefined
99
+ ? { fill: color(path.fill) }
100
+ : { fill: color(path.fill), stroke: color(path.stroke), strokeWidth: path.strokeWidth ?? 1.5 };
101
+ }
102
+
103
+ /** A complete loop in the surface's form. */
104
+ export function nativeVectorLoop(tracks: VectorLoopTracks, viewBox: string): NativeVectorLoop {
105
+ return {
106
+ duration: tracks.duration,
107
+ length: tracks.length,
108
+ viewBox: viewBoxNumbers(viewBox),
109
+ paths: tracks.paths.map((track) => ({
110
+ ...nativePaint(track),
111
+ fillOpacity: track.fillOpacity,
112
+ d: track.d,
113
+ opacity: track.opacity,
114
+ ...(track.clip ? { clip: track.clip } : {}),
115
+ })),
116
+ };
117
+ }
@@ -0,0 +1,213 @@
1
+ import { VECTOR_UNCLIPPED } from './vector-visibility';
2
+ import type { VectorFrame } from './vector-types';
3
+
4
+ /**
5
+ * A character at rest repeats itself. With no gesture, pointer, mood or transition, and no
6
+ * reference face (whose procedural gaze never repeats), the frame it draws depends on one number:
7
+ * where it is in its idle clip. So the frames of that clip are computed once, the first time
8
+ * round, and replayed after that: its loop.
9
+ *
10
+ * The loop's frames sit on a fixed grid, `VECTOR_LOOP_FPS` a second, the rate frames are painted
11
+ * at, and an avatar at rest draws the grid frame its clock is in. Every avatar with the same
12
+ * geometry and paint shares one loop, keyed by `vectorFrameRecipeKey`.
13
+ */
14
+ export const VECTOR_LOOP_FPS = 30;
15
+ /** The loops kept, in path characters (about bytes): Alia's is 2 M, the largest character 10 M. */
16
+ export const VECTOR_LOOP_CACHE_CHARACTERS = 24_000_000;
17
+
18
+ export type VectorLoop<Frame extends { drawing: VectorFrame }> = {
19
+ /** Seconds the loop takes: its idle clip's duration. */
20
+ duration: number;
21
+ /** One slot per grid frame, filled the first time that frame is drawn. */
22
+ frames: (Frame | undefined)[];
23
+ /** How many slots are filled. */
24
+ drawn: number;
25
+ /** Path characters held, for the cache budget. */
26
+ characters: number;
27
+ /** Its tracks, built once every frame is drawn (`vectorLoopTracks`); `null` if it has none. */
28
+ tracks?: VectorLoopTracks | null;
29
+ /** What it is made from, as a name that is the same on every start (`vectorLoopKey`). */
30
+ key?: string;
31
+ };
32
+
33
+ /**
34
+ * A complete loop as one track per drawn path, for a player that draws it frame by frame without
35
+ * recomputing anything: what stays the same on every frame (the paint) and what changes (outline,
36
+ * clip and opacity, one entry per frame). A path that is clipped on some frames and not on others
37
+ * gets `VECTOR_UNCLIPPED` on the frames it has none, which hides nothing.
38
+ */
39
+ export type VectorLoopTracks = {
40
+ /** Seconds the loop takes. */
41
+ duration: number;
42
+ /** Grid frames in it: the length of every per-frame list. */
43
+ length: number;
44
+ viewBox: string;
45
+ paths: {
46
+ id: string;
47
+ fill: string;
48
+ fillOpacity: number;
49
+ stroke?: string;
50
+ strokeWidth?: number;
51
+ d: string[];
52
+ opacity: number[];
53
+ clip?: string[];
54
+ }[];
55
+ };
56
+
57
+ const loops = new Map<string, VectorLoop<{ drawing: VectorFrame }>>();
58
+ let held = 0;
59
+
60
+ /** The loop of the avatar whose frame recipe is `key`, with an idle clip of `duration` seconds. */
61
+ export function vectorLoop<Frame extends { drawing: VectorFrame }>(
62
+ key: string,
63
+ duration: number,
64
+ ): VectorLoop<Frame> {
65
+ const known = loops.get(key);
66
+ if (known) {
67
+ loops.delete(key);
68
+ loops.set(key, known);
69
+ return known as VectorLoop<Frame>;
70
+ }
71
+ const length = Math.max(1, Math.round(duration * VECTOR_LOOP_FPS));
72
+ const loop: VectorLoop<Frame> = {
73
+ duration,
74
+ frames: Array.from({ length }, () => undefined),
75
+ drawn: 0,
76
+ characters: 0,
77
+ };
78
+ loops.set(key, loop);
79
+ return loop;
80
+ }
81
+
82
+ /**
83
+ * A name for a loop's content that is the same on every start of the app, for a store that keeps
84
+ * loops across starts (the native avatar surface). It is a hash of what the loop is drawn from: the
85
+ * character (`recipe`), its idle clip's tracks, and its first frame as drawn, which carries the
86
+ * geometry, the paint and what the renderer makes of them. Remembered on the loop.
87
+ */
88
+ export function vectorLoopKey(
89
+ loop: VectorLoop<{ drawing: VectorFrame }>,
90
+ recipe: string,
91
+ clip: unknown,
92
+ first: () => VectorFrame,
93
+ ): string {
94
+ loop.key ??= hashText(
95
+ JSON.stringify([LOOP_KEY_FORMAT, recipe, loop.duration, loop.frames.length, clip, first()]),
96
+ );
97
+ return loop.key;
98
+ }
99
+ const LOOP_KEY_FORMAT = 1;
100
+ /** 64 bits of two multiply-xor lanes over the text's UTF-16 units, as 16 hex digits. */
101
+ function hashText(text: string): string {
102
+ let a = 0xdeadbeef,
103
+ b = 0x41c6ce57;
104
+ for (let i = 0; i < text.length; i++) {
105
+ const unit = text.charCodeAt(i);
106
+ a = Math.imul(a ^ unit, 2654435761);
107
+ b = Math.imul(b ^ unit, 1597334677);
108
+ }
109
+ a = Math.imul(a ^ (a >>> 16), 2246822507) ^ Math.imul(b ^ (b >>> 13), 3266489909);
110
+ b = Math.imul(b ^ (b >>> 16), 2246822507) ^ Math.imul(a ^ (a >>> 13), 3266489909);
111
+ return (b >>> 0).toString(16).padStart(8, '0') + (a >>> 0).toString(16).padStart(8, '0');
112
+ }
113
+
114
+ /**
115
+ * Lets go of a loop's frames once something else plays it (the native surface): the JS thread
116
+ * draws none of them again, and if it ever must, it draws them again.
117
+ */
118
+ export function releaseVectorLoop(loop: VectorLoop<{ drawing: VectorFrame }>) {
119
+ held -= loop.characters;
120
+ loop.frames.fill(undefined);
121
+ loop.drawn = 0;
122
+ loop.characters = 0;
123
+ loop.tracks = undefined;
124
+ }
125
+
126
+ /** The grid frame a clock of `time` seconds is in. */
127
+ export function vectorLoopIndex(loop: VectorLoop<{ drawing: VectorFrame }>, time: number): number {
128
+ const length = loop.frames.length;
129
+ const elapsed = loop.duration > 0 ? ((time % loop.duration) + loop.duration) % loop.duration : 0;
130
+ return Math.min(length - 1, Math.floor((elapsed / loop.duration) * length)) || 0;
131
+ }
132
+
133
+ /** The clip time grid frame `index` is drawn at. */
134
+ export function vectorLoopTime(loop: VectorLoop<{ drawing: VectorFrame }>, index: number): number {
135
+ return (index * loop.duration) / loop.frames.length;
136
+ }
137
+
138
+ /** Grid frame `index`: drawn by `draw` the first time it is asked for, remembered after that. */
139
+ export function vectorLoopFrame<Frame extends { drawing: VectorFrame }>(
140
+ loop: VectorLoop<Frame>,
141
+ index: number,
142
+ draw: () => Frame,
143
+ ): Frame {
144
+ const known = loop.frames[index];
145
+ if (known) return known;
146
+ const frame = draw();
147
+ loop.frames[index] = frame;
148
+ loop.drawn++;
149
+ const characters = frame.drawing.paths.reduce(
150
+ (sum, path) => sum + path.d.length + (path.clip?.length ?? 0),
151
+ 0,
152
+ );
153
+ loop.characters += characters;
154
+ held += characters;
155
+ // The least recently used loops go first; one in use is rebuilt by the avatar that needs it.
156
+ for (const [key, old] of loops) {
157
+ if (held <= VECTOR_LOOP_CACHE_CHARACTERS || old === loop) break;
158
+ loops.delete(key);
159
+ held -= old.characters;
160
+ }
161
+ return frame;
162
+ }
163
+
164
+ /**
165
+ * The tracks of a complete loop, or `null` while frames are missing or when its frames do not
166
+ * draw the same paths with the same paint (then it is replayed frame by frame instead).
167
+ */
168
+ export function vectorLoopTracks(
169
+ loop: VectorLoop<{ drawing: VectorFrame }>,
170
+ ): VectorLoopTracks | null {
171
+ if (loop.tracks !== undefined) return loop.tracks;
172
+ if (loop.drawn < loop.frames.length) return null;
173
+ const drawings = loop.frames.map((frame) => frame!.drawing);
174
+ const first = drawings[0]!;
175
+ const same = drawings.every(
176
+ (drawing) =>
177
+ drawing.viewBox === first.viewBox &&
178
+ drawing.paths.length === first.paths.length &&
179
+ drawing.paths.every((path, i) => {
180
+ const model = first.paths[i]!;
181
+ return (
182
+ path.id === model.id &&
183
+ path.fill === model.fill &&
184
+ path.fillOpacity === model.fillOpacity &&
185
+ path.stroke === model.stroke &&
186
+ path.strokeWidth === model.strokeWidth
187
+ );
188
+ }),
189
+ );
190
+ loop.tracks = same
191
+ ? {
192
+ duration: loop.duration,
193
+ length: loop.frames.length,
194
+ viewBox: first.viewBox,
195
+ paths: first.paths.map((path, i) => {
196
+ const clipped = drawings.some((drawing) => drawing.paths[i]!.clip !== undefined);
197
+ return {
198
+ id: path.id,
199
+ fill: path.fill,
200
+ fillOpacity: path.fillOpacity,
201
+ stroke: path.stroke,
202
+ strokeWidth: path.strokeWidth,
203
+ d: drawings.map((drawing) => drawing.paths[i]!.d),
204
+ opacity: drawings.map((drawing) => drawing.paths[i]!.opacity),
205
+ clip: clipped
206
+ ? drawings.map((drawing) => drawing.paths[i]!.clip ?? VECTOR_UNCLIPPED)
207
+ : undefined,
208
+ };
209
+ }),
210
+ }
211
+ : null;
212
+ return loop.tracks;
213
+ }
@@ -9,6 +9,8 @@ export type OcclusionPart = {
9
9
  opaque?: boolean;
10
10
  group?: string;
11
11
  };
12
+ /** A clip that hides nothing: the frame and a margin round it. Every mask starts from it. */
13
+ export const VECTOR_UNCLIPPED = 'M-2 -2H322V322H-2Z';
12
14
  const SIZE = 322,
13
15
  STEP = 1,
14
16
  ORIGIN = -1,
@@ -190,7 +192,7 @@ function contours(field: Float32Array, bounds: [number, number, number, number])
190
192
  next.set(ia, ib);
191
193
  }
192
194
  }
193
- let d = 'M-2 -2H322V322H-2Z';
195
+ let d = VECTOR_UNCLIPPED;
194
196
  for (const start of [...next.keys()]) {
195
197
  if (!next.has(start)) continue;
196
198
  const loop: number[] = [];
@@ -1,7 +1,8 @@
1
1
  import { resolveSurfaceGeometry } from '../surface/resolve-surface-geometry';
2
2
  import { surfaceStyle } from '../shapes/surface-style';
3
3
  import { SURFACE_SHAPES } from '../design-tokens/shapes';
4
- import React, { memo } from 'react';
4
+ import type React from 'react';
5
+ import { memo } from 'react';
5
6
  import { StyleSheet, View } from 'react-native';
6
7
 
7
8
  import { useDirectionProps, useIsRtl } from '../hooks/use-is-rtl';
@@ -12,8 +13,7 @@ import { useSurfaceLayer } from '../surface/use-surface-layer';
12
13
  import { resolveSurfaceMaterial } from '../surface/resolve-surface-material';
13
14
  import { borderRadius } from '../styles/tokens';
14
15
  import { SurfacePaint } from '../surface/SurfacePaint';
15
- import { LensButtonHost, splitLensStyle } from '../floating/lens/lens-button-host';
16
- import { useLensAvailable } from '../floating/lens/lens-material';
16
+ import { useLensFrame, withLens } from '../floating/lens/lens-frame';
17
17
  import type { BlurIslandProps } from './types';
18
18
 
19
19
  /** Floating control container using the shared surface material.
@@ -30,7 +30,7 @@ const BlurIslandComponent: React.FC<BlurIslandProps> = ({
30
30
  style,
31
31
  testID,
32
32
  }) => {
33
- const lensAvailable = useLensAvailable();
33
+ const frame = useLensFrame(variant === 'lens', style);
34
34
  const directionProps = useDirectionProps();
35
35
  const direction = useIsRtl() ? 'rtl' : 'ltr';
36
36
  const layer = useSurfaceLayer();
@@ -40,20 +40,18 @@ const BlurIslandComponent: React.FC<BlurIslandProps> = ({
40
40
  parentFill: layer.parentFill,
41
41
  parentLevel: layer.parentLevel,
42
42
  });
43
- const { paintFill: fill, publishedFill: publishedFill } = material;
43
+ const { paintFill: fill, publishedFill } = material;
44
44
  const geometry = resolveSurfaceGeometry(radius, style, borderRadius.full, cornerCurve);
45
45
  const shape = geometry.shape;
46
46
 
47
- if (variant === 'lens' && lensAvailable) {
47
+ if (frame.lens) {
48
48
  // The island is the native lens: the engine draws the material, its shadow and its light, and the
49
49
  // controls inside draw their content. Placement stays on the host, the look on the inner view.
50
- const split = splitLensStyle(style);
50
+ // It floats over what moves behind (a map, a feed), so the window draws its lens.
51
51
  return (
52
52
  <BloomScope>
53
- <LensButtonHost
54
- radius={typeof geometry.radius === 'number' ? geometry.radius : undefined}
55
- style={split.host}
56
- >
53
+ {withLens(
54
+ frame,
57
55
  <View
58
56
  collapsable={false}
59
57
  {...directionProps}
@@ -63,14 +61,18 @@ const BlurIslandComponent: React.FC<BlurIslandProps> = ({
63
61
  style={[
64
62
  styles.island,
65
63
  { borderRadius: geometry.radius, overflow: 'hidden' },
66
- split.control,
64
+ frame.style,
67
65
  ]}
68
66
  >
69
67
  <SurfaceLevelProvider level={material.level} fill={publishedFill}>
70
68
  {children}
71
69
  </SurfaceLevelProvider>
72
- </View>
73
- </LensButtonHost>
70
+ </View>,
71
+ {
72
+ radius: typeof geometry.radius === 'number' ? geometry.radius : undefined,
73
+ floating: true,
74
+ },
75
+ )}
74
76
  </BloomScope>
75
77
  );
76
78
  }
@@ -2,15 +2,10 @@ import { GlyphAttention } from './GlyphAttention';
2
2
  import { resolveButtonOverrides } from './shared';
3
3
  import { Group } from './Group';
4
4
  import { useGroupedButton } from './use-grouped-button';
5
- import { LensButtonHost, splitLensStyle } from '../floating/lens/lens-button-host';
5
+ import { useLensFrame, withLens } from '../floating/lens/lens-frame';
6
6
  import { useLensOriginReporter } from '../floating/lens/use-lens-menu';
7
7
  import { compositeOnto } from '../surface/shared';
8
- import {
9
- useControlMaterial,
10
- useFloatingControl,
11
- useInFloatingRegion,
12
- useLensAvailable,
13
- } from '../floating/lens/lens-material';
8
+ import { useControlMaterial, useFloatingControl } from '../floating/lens/lens-material';
14
9
  import { useInLensBase } from '../floating/lens/native-lens';
15
10
  import { useSurfaceLayer } from '../surface/use-surface-layer';
16
11
  import React, {
@@ -20,7 +15,6 @@ import React, {
20
15
  useRef,
21
16
  useEffect,
22
17
  memo,
23
- type ComponentType,
24
18
  createContext,
25
19
  useContext,
26
20
  } from 'react';
@@ -479,7 +473,6 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
479
473
  const material = materialProp ?? regionMaterial;
480
474
  // A floating control (on the lens) is the floating size, whatever its caller says.
481
475
  const sizeProp = useFloatingControl(materialProp) ? FLOATING_CONTROL_SIZE : requestedSize;
482
- const inFloatingRegion = useInFloatingRegion();
483
476
  const { size, tone } = useBloomAppearance(
484
477
  { size: typeof sizeProp === 'number' ? undefined : sizeProp, tone: toneProp },
485
478
  { size: 'md', tone: 'accent' },
@@ -504,7 +497,6 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
504
497
  ? geometry.iconSize
505
498
  : ICON_BUTTON_ICON_SIZE[size]
506
499
  : geometry.iconSize;
507
- const lensAvailable = useLensAvailable();
508
500
  const inLensBase = useInLensBase();
509
501
  const palette = useMemo(
510
502
  () =>
@@ -547,14 +539,12 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
547
539
  // Where the device has the lens, every button with a material is drawn by it: one material for
548
540
  // every button. In a floating region (`material="lens"`) the window draws it over what moves
549
541
  // behind; anywhere else it is drawn in its place, against the surface it sits on, as a feed's ⋯.
550
- const lens =
551
- lensAvailable &&
552
- (material === 'lens' || (material === 'surface' && palette.rest.surface === true));
553
- // Outside a floating region (a header, a toolbar, a bar, a FAB) the control is in the page's
554
- // content: its lens is drawn in its place, so it scrolls and stacks with the page.
555
- const restBackdrop = lens && !inFloatingRegion ? layer.parentFill : undefined;
542
+ const frame = useLensFrame(
543
+ material === 'lens' || (material === 'surface' && palette.rest.surface === true),
544
+ style,
545
+ );
556
546
  // On the lens (its own or an enclosing base's) the engine draws the shadow and rim.
557
- const onLens = inLensBase || lens;
547
+ const onLens = inLensBase || frame.lens;
558
548
 
559
549
  // Pressed state drives the ACTIVE palette. Tracked through state rather than
560
550
  // Pressable's function-form `style`, which NativeWind's css-interop swallows
@@ -624,8 +614,9 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
624
614
  // of the button's own shape. The resting paint, composited onto the page, is what it looks like.
625
615
  const reportOrigin = useLensOriginReporter();
626
616
  const restFill = palette.rest.background;
627
- const styleRadius = StyleSheet.flatten(style)?.borderRadius;
628
- const originRadius = typeof styleRadius === 'number' ? styleRadius : BUTTON_RADIUS;
617
+ const flatStyle = StyleSheet.flatten(style);
618
+ const originRadius =
619
+ typeof flatStyle?.borderRadius === 'number' ? flatStyle.borderRadius : BUTTON_RADIUS;
629
620
  const pageColor = theme.colors.background;
630
621
  useEffect(() => {
631
622
  if (!reportOrigin) return;
@@ -770,7 +761,6 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
770
761
  ? () => (target === '_blank' ? openExternal(href) : openHref(href))
771
762
  : undefined));
772
763
 
773
- const split = lens ? splitLensStyle(style) : null;
774
764
  const pressable = (
775
765
  <ButtonPressable
776
766
  interactive={interactive}
@@ -787,7 +777,7 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
787
777
  ? {}
788
778
  : { tabIndex: tabIndex < 0 ? (-1 as const) : (0 as const) })}
789
779
  baseStyle={baseStyles}
790
- style={split ? split.control : style}
780
+ style={frame.style}
791
781
  onLongPress={isInteractionBlocked ? undefined : onLongPress}
792
782
  onPress={
793
783
  handlePress
@@ -850,12 +840,12 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
850
840
  {...(ariaHasPopup == null ? {} : { 'aria-haspopup': ariaHasPopup })}
851
841
  testID={testID}
852
842
  >
853
- {paint.surface && !lens ? (
843
+ {paint.surface && !frame.lens ? (
854
844
  <SurfacePaint
855
845
  fill={paint.background}
856
- radius={StyleSheet.flatten(style)?.borderRadius ?? BUTTON_RADIUS}
846
+ radius={flatStyle?.borderRadius ?? BUTTON_RADIUS}
857
847
  // A continuous corner (a squircle FAB) on the paint too.
858
- shape={StyleSheet.flatten(style)?.borderCurve === 'continuous' ? SMOOTH : undefined}
848
+ shape={flatStyle?.borderCurve === 'continuous' ? SMOOTH : undefined}
859
849
  />
860
850
  ) : null}
861
851
  <ButtonContent
@@ -881,18 +871,11 @@ const ButtonComponent = forwardRef<ComponentRef<typeof View>, ButtonProps>(
881
871
  {decoration}
882
872
  </ButtonPressable>
883
873
  );
884
- if (!split) return pressable;
885
- const flatRadius = StyleSheet.flatten(style)?.borderRadius;
886
- return (
887
- <LensButtonHost
888
- tint={appearance === 'solid' ? paint.background : undefined}
889
- radius={typeof flatRadius === 'number' ? flatRadius : BUTTON_RADIUS}
890
- restBackdrop={restBackdrop}
891
- style={split.host}
892
- >
893
- {pressable}
894
- </LensButtonHost>
895
- );
874
+ // The lens takes the paint's fill (a solid control's) and radius.
875
+ return withLens(frame, pressable, {
876
+ tint: appearance === 'solid' ? paint.background : undefined,
877
+ radius: originRadius,
878
+ });
896
879
  },
897
880
  );
898
881
 
@@ -16,7 +16,7 @@ import { BloomScope, useBloomAppearance } from '../appearance';
16
16
  import { useBloomControlDensity } from '../appearance/context';
17
17
 
18
18
  import { useThemeRecipe } from '../theme/use-theme-paint';
19
- import { hairlineOn, useSurfaceFill, useSurfaceFillRecipe } from '../styles/surface-levels';
19
+ import { hairlineOn, useSurfaceFillRecipe } from '../styles/surface-levels';
20
20
  import {
21
21
  BUTTON_RADIUS,
22
22
  BUTTON_SHADOW,
@@ -32,12 +32,8 @@ import type { WebCssStyle } from '../styles/web-view-style';
32
32
  import { moveSelection, SELECTION_FADE, SELECTION_SPRING } from '../motion/selection-motion';
33
33
  import { surfacePresenceStyle, useEnteredPresence } from '../surface/use-surface-presence';
34
34
  import { IS_WEB } from '../styles/platform';
35
- import { LensButtonHost, splitLensStyle } from '../floating/lens/lens-button-host';
36
- import {
37
- useFloatingControl,
38
- useInFloatingRegion,
39
- useLensAvailable,
40
- } from '../floating/lens/lens-material';
35
+ import { useLensFrame, withLens } from '../floating/lens/lens-frame';
36
+ import { useFloatingControl } from '../floating/lens/lens-material';
41
37
  import { useGroupSelection } from './use-group-selection';
42
38
  import type { SurfaceProps } from '../surface/types';
43
39
  import type { ButtonGroupProps } from './types';
@@ -179,58 +175,48 @@ export function createButtonGroup(Surface: ComponentType<SurfaceProps>) {
179
175
  {item}
180
176
  </Fragment>
181
177
  ));
182
- // The group's one material: its own Surface, or, with `material="lens"` on a device that has the
183
- // native lens, the lens itself behind the items. The items draw their content either way.
184
- // Where the device has the lens the group is drawn by it, as every button is: by the window in
185
- // a floating region, else in its place against the surface it sits on.
186
- const lens = useLensAvailable();
187
- const backing = useSurfaceFill();
188
- const restBackdrop = useInFloatingRegion() ? undefined : backing;
189
- const frame = (content: ReactNode) => {
190
- if (lens) {
191
- const split = splitLensStyle(style);
192
- return (
193
- <LensButtonHost
178
+ // The group's one material: the native lens behind the items where the device has it, as every
179
+ // button is (by the window in a floating region, else in its place against the surface it sits
180
+ // on), or its own Surface. The items draw their content either way.
181
+ const lensFrame = useLensFrame(true, style);
182
+ const frame = (content: ReactNode) =>
183
+ withLens(
184
+ lensFrame,
185
+ lensFrame.lens ? (
186
+ <View
187
+ role="group"
188
+ accessibilityLabel={accessibilityLabel}
189
+ // The group holds its items (GROUP_HOLDS_ITEMS).
190
+ collapsable={false}
191
+ testID={testID}
192
+ style={[{ borderRadius: BUTTON_RADIUS, overflow: 'hidden' }, lensFrame.style]}
193
+ >
194
+ {content}
195
+ </View>
196
+ ) : (
197
+ <Surface
194
198
  radius={BUTTON_RADIUS}
195
- restBackdrop={restBackdrop}
196
- style={{ alignSelf: 'flex-start', ...split.host }}
199
+ cornerCurve="round"
200
+ {...paintHook}
201
+ role="group"
202
+ accessibilityLabel={accessibilityLabel}
203
+ // The group holds its items (GROUP_HOLDS_ITEMS).
204
+ collapsable={false}
205
+ testID={testID}
206
+ style={[
207
+ {
208
+ alignSelf: 'flex-start',
209
+ boxShadow: recipe.paint.shadow,
210
+ },
211
+ paintStyle,
212
+ style,
213
+ ]}
197
214
  >
198
- <View
199
- role="group"
200
- accessibilityLabel={accessibilityLabel}
201
- // The group holds its items (GROUP_HOLDS_ITEMS).
202
- collapsable={false}
203
- testID={testID}
204
- style={[{ borderRadius: BUTTON_RADIUS, overflow: 'hidden' }, split.control]}
205
- >
206
- {content}
207
- </View>
208
- </LensButtonHost>
209
- );
210
- }
211
- return (
212
- <Surface
213
- radius={BUTTON_RADIUS}
214
- cornerCurve="round"
215
- {...paintHook}
216
- role="group"
217
- accessibilityLabel={accessibilityLabel}
218
- // The group holds its items (GROUP_HOLDS_ITEMS).
219
- collapsable={false}
220
- testID={testID}
221
- style={[
222
- {
223
- alignSelf: 'flex-start',
224
- boxShadow: recipe.paint.shadow,
225
- },
226
- paintStyle,
227
- style,
228
- ]}
229
- >
230
- {content}
231
- </Surface>
215
+ {content}
216
+ </Surface>
217
+ ),
218
+ { radius: BUTTON_RADIUS },
232
219
  );
233
- };
234
220
  if (separated)
235
221
  return (
236
222
  <ButtonGroupContext.Provider value={context}>