@delacour/react-native-ui 0.6.0-alpha.20261103104147 → 0.6.0-alpha.20261103135630
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/package.json +4 -4
- package/src/components/avatar/AGENTS.md +4 -3
- package/src/components/avatar/avatar-group.tsx +3 -3
- package/src/components/avatar/avatar.utils.test.ts +88 -4
- package/src/components/avatar/avatar.utils.ts +60 -13
- package/src/components/avatar/avatar.variants.test.ts +6 -0
- package/src/components/avatar/avatar.variants.ts +2 -1
- package/src/components/avatar/index.ts +3 -0
- package/src/components/signature/AGENTS.md +3 -2
- package/src/components/signature/signature.skia.ts +5 -2
- package/src/components/signature/signature.tsx +1 -1
- package/src/components/signature/signature.types.ts +2 -2
- package/src/components/sketch/AGENTS.md +2 -1
- package/src/components/sketch/sketch.skia.ts +2 -2
- package/src/components/sketch/sketch.types.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.20261103135630",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -181,10 +181,10 @@
|
|
|
181
181
|
"expo-blur": ">=15",
|
|
182
182
|
"@maplibre/maplibre-react-native": "^11.5.0",
|
|
183
183
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
184
|
-
"@delacour/react-native-bottom-sheet": "0.6.0-alpha.
|
|
185
|
-
"@delacour/react-native-charts": "0.6.0-alpha.
|
|
184
|
+
"@delacour/react-native-bottom-sheet": "0.6.0-alpha.20261103135630",
|
|
185
|
+
"@delacour/react-native-charts": "0.6.0-alpha.20261103135630",
|
|
186
186
|
"@legendapp/list": ">=3.3",
|
|
187
|
-
"react-native-skia": ">=3.
|
|
187
|
+
"react-native-skia": ">=3.9.0",
|
|
188
188
|
"expo-linear-gradient": ">=15",
|
|
189
189
|
"expo-router": ">=57",
|
|
190
190
|
"react": ">=19",
|
|
@@ -17,7 +17,7 @@ Compound root plus `Avatar.Badge` and `Avatar.Group`.
|
|
|
17
17
|
| `avatar.context.tsx` | `AvatarProvider`, `AvatarGroupProvider`, `useAvatar()`, `useAvatarContext()`, `useAvatarGroupContext()`, `useAvatarPart()` |
|
|
18
18
|
| `avatar.variants.ts` | Pure `tv()` slots, `AVATAR_SIZE_POINTS`, `resolveAvatarSize`, `resolveAvatarOverlap`, `resolveAvatarInteractive` |
|
|
19
19
|
| `avatar.variants.test.ts` | |
|
|
20
|
-
| `avatar.utils.ts` | Pure non-styling logic — initials, the image-retry key, group overflow maths, the spoken label |
|
|
20
|
+
| `avatar.utils.ts` | Pure non-styling logic — initials, the image-retry key, flattening a group's fragments, group overflow maths, the spoken label |
|
|
21
21
|
| `avatar.utils.test.ts` | |
|
|
22
22
|
|
|
23
23
|
## Design
|
|
@@ -28,8 +28,9 @@ Compound root plus `Avatar.Badge` and `Avatar.Group`.
|
|
|
28
28
|
showing rather than an empty circle — there is no loading state to manage
|
|
29
29
|
because there is nothing to swap.
|
|
30
30
|
- **A failure is remembered by key, not by object.** `resolveAvatarSourceKey`
|
|
31
|
-
turns the source into a string —
|
|
32
|
-
|
|
31
|
+
turns the source into a JSON string — every request field (URI, bundle,
|
|
32
|
+
method, sorted headers, body, cache mode), or the asset's module id — and
|
|
33
|
+
`onError` stores the key that failed. Keyed by object identity, an
|
|
33
34
|
inline `source={{ uri }}` is new every render and a dead URL would retry
|
|
34
35
|
forever; keyed by URI alone, a token refresh in the headers would never retry.
|
|
35
36
|
A consumer's `imageProps.onError` fires after the fallback has taken over.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ReactElement, type ReactNode, useMemo } from "react";
|
|
2
2
|
import { View, type ViewProps } from "react-native";
|
|
3
3
|
import { Pressable } from "../pressable";
|
|
4
4
|
import { Text } from "../text";
|
|
5
5
|
import { type AvatarGroupContextValue, AvatarGroupProvider } from "./avatar.context";
|
|
6
|
-
import { resolveAvatarGroup, resolveAvatarOverflowLabel } from "./avatar.utils";
|
|
6
|
+
import { flattenAvatarChildren, resolveAvatarGroup, resolveAvatarOverflowLabel } from "./avatar.utils";
|
|
7
7
|
import { type AvatarSize, avatarVariants, resolveAvatarOverlap } from "./avatar.variants";
|
|
8
8
|
|
|
9
9
|
export type AvatarGroupProps = ViewProps & {
|
|
@@ -113,7 +113,7 @@ export function AvatarGroup({
|
|
|
113
113
|
children,
|
|
114
114
|
...props
|
|
115
115
|
}: AvatarGroupProps): ReactElement {
|
|
116
|
-
const items =
|
|
116
|
+
const items = flattenAvatarChildren(children);
|
|
117
117
|
const { visible, overflow } = resolveAvatarGroup({ count: items.length, max, total });
|
|
118
118
|
const shift = resolveAvatarOverlap({ size: size ?? "md", overlap });
|
|
119
119
|
const count = visible + (overflow > 0 ? 1 : 0);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { createElement, Fragment } from "react";
|
|
2
3
|
import {
|
|
4
|
+
flattenAvatarChildren,
|
|
3
5
|
resolveAvatarAccessibilityLabel,
|
|
4
6
|
resolveAvatarGroup,
|
|
5
7
|
resolveAvatarInitials,
|
|
@@ -55,7 +57,36 @@ describe("resolveAvatarSourceKey", () => {
|
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
test("names a bundled asset by its module id", () => {
|
|
58
|
-
expect(resolveAvatarSourceKey(12)).toBe("asset
|
|
60
|
+
expect(resolveAvatarSourceKey(12)).toBe(JSON.stringify([["asset", 12]]));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("tells a bundled asset from a uri of the same text", () => {
|
|
64
|
+
expect(resolveAvatarSourceKey(3)).not.toBe(resolveAvatarSourceKey({ uri: "3" }));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("changes when the cache mode changes, so a cache miss can retry", () => {
|
|
68
|
+
expect(resolveAvatarSourceKey({ uri: "https://a.test/1.png", cache: "only-if-cached" })).not.toBe(
|
|
69
|
+
resolveAvatarSourceKey({ uri: "https://a.test/1.png", cache: "reload" })
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("changes when the method or body changes", () => {
|
|
74
|
+
const get = resolveAvatarSourceKey({ uri: "https://a.test/1.png" });
|
|
75
|
+
const post = resolveAvatarSourceKey({ uri: "https://a.test/1.png", method: "POST" });
|
|
76
|
+
const body = resolveAvatarSourceKey({ uri: "https://a.test/1.png", method: "POST", body: "id=1" });
|
|
77
|
+
expect(new Set([get, post, body]).size).toBe(3);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("does not let header values that look like separators collide", () => {
|
|
81
|
+
expect(resolveAvatarSourceKey({ uri: "https://a.test/1.png", headers: { "X-A": "1&X-B=2" } })).not.toBe(
|
|
82
|
+
resolveAvatarSourceKey({ uri: "https://a.test/1.png", headers: { "X-A": "1", "X-B": "2" } })
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("does not let a uri that looks like a separator collide across a list", () => {
|
|
87
|
+
expect(resolveAvatarSourceKey([{ uri: "https://a.test/1.png|uri:https://a.test/2.png" }])).not.toBe(
|
|
88
|
+
resolveAvatarSourceKey([{ uri: "https://a.test/1.png" }, { uri: "https://a.test/2.png" }])
|
|
89
|
+
);
|
|
59
90
|
});
|
|
60
91
|
|
|
61
92
|
test("changes when the uri changes", () => {
|
|
@@ -78,9 +109,9 @@ describe("resolveAvatarSourceKey", () => {
|
|
|
78
109
|
});
|
|
79
110
|
|
|
80
111
|
test("reads every entry of a multi-resolution list", () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
112
|
+
const both = resolveAvatarSourceKey([{ uri: "https://a.test/1x.png" }, { uri: "https://a.test/2x.png" }]);
|
|
113
|
+
expect(both).not.toBe(resolveAvatarSourceKey([{ uri: "https://a.test/1x.png" }]));
|
|
114
|
+
expect(both).not.toBe(resolveAvatarSourceKey([{ uri: "https://a.test/2x.png" }]));
|
|
84
115
|
expect(resolveAvatarSourceKey([])).toBeNull();
|
|
85
116
|
});
|
|
86
117
|
});
|
|
@@ -172,3 +203,56 @@ describe("resolveAvatarAccessibilityLabel", () => {
|
|
|
172
203
|
expect(resolveAvatarAccessibilityLabel({ accessibilityLabel: "You", name: "Aria Whitlock" })).toBe("You");
|
|
173
204
|
});
|
|
174
205
|
});
|
|
206
|
+
|
|
207
|
+
describe("flattenAvatarChildren", () => {
|
|
208
|
+
const face = (name: string, key?: string) => createElement("Face", { key, name });
|
|
209
|
+
const names = (children: Parameters<typeof flattenAvatarChildren>[0]) =>
|
|
210
|
+
flattenAvatarChildren(children).map((child) => (child.props as { name: string }).name);
|
|
211
|
+
|
|
212
|
+
test("keeps direct children in the order they were written", () => {
|
|
213
|
+
expect(names([face("Ana"), face("Ben")])).toEqual(["Ana", "Ben"]);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("counts each avatar inside a fragment as its own face", () => {
|
|
217
|
+
expect(names(createElement(Fragment, null, face("Ana"), face("Ben")))).toEqual(["Ana", "Ben"]);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("opens nested fragments and keeps the written order", () => {
|
|
221
|
+
const nested = [
|
|
222
|
+
face("Ana"),
|
|
223
|
+
createElement(Fragment, null, face("Ben"), createElement(Fragment, null, face("Cai"))),
|
|
224
|
+
];
|
|
225
|
+
expect(names(nested)).toEqual(["Ana", "Ben", "Cai"]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("drops text, null and booleans", () => {
|
|
229
|
+
expect(names([face("Ana"), "text", null, false, createElement(Fragment, null, true, face("Ben"))])).toEqual([
|
|
230
|
+
"Ana",
|
|
231
|
+
"Ben",
|
|
232
|
+
]);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("gives every face a unique key when two fragments reuse the same keys", () => {
|
|
236
|
+
const keys = flattenAvatarChildren([
|
|
237
|
+
createElement(Fragment, { key: "a" }, face("Ana", "x")),
|
|
238
|
+
createElement(Fragment, { key: "b" }, face("Ben", "x")),
|
|
239
|
+
]).map((child) => child.key);
|
|
240
|
+
expect(new Set(keys).size).toBe(2);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("does not let a fragment key and a face key run together into another pair", () => {
|
|
244
|
+
const keys = flattenAvatarChildren([
|
|
245
|
+
createElement(Fragment, { key: "a" }, face("Ana", "b.$c")),
|
|
246
|
+
createElement(Fragment, { key: "a.$b" }, face("Ben", "c")),
|
|
247
|
+
]).map((child) => child.key);
|
|
248
|
+
expect(new Set(keys).size).toBe(2);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("keeps keys unique through nested fragments", () => {
|
|
252
|
+
const keys = flattenAvatarChildren([
|
|
253
|
+
createElement(Fragment, { key: "a" }, createElement(Fragment, { key: "b" }, face("Ana", "c"))),
|
|
254
|
+
createElement(Fragment, { key: "a.$b" }, face("Ben", "c")),
|
|
255
|
+
]).map((child) => child.key);
|
|
256
|
+
expect(new Set(keys).size).toBe(2);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
@@ -7,8 +7,27 @@
|
|
|
7
7
|
* `ImageSourcePropType` for the same reason. See AGENTS.md.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { Children, cloneElement, Fragment, isValidElement, type ReactElement, type ReactNode } from "react";
|
|
11
|
+
|
|
12
|
+
/** The cache modes `Image` accepts for a URI request. */
|
|
13
|
+
export type AvatarSourceCache = "default" | "reload" | "force-cache" | "only-if-cached";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A URI request, as `Image` accepts it. Holds only the fields that change what
|
|
17
|
+
* is fetched. `width`, `height` and `scale` are left out: they pick an entry,
|
|
18
|
+
* they do not change the request.
|
|
19
|
+
*/
|
|
20
|
+
export type AvatarSourceRequest = {
|
|
21
|
+
uri?: string | null;
|
|
22
|
+
bundle?: string | null;
|
|
23
|
+
method?: string | null;
|
|
24
|
+
headers?: Readonly<Record<string, string>> | null;
|
|
25
|
+
body?: string | null;
|
|
26
|
+
cache?: AvatarSourceCache | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
10
29
|
/** One entry of an image source, as `Image` accepts it — a URI request or a bundled asset's module id. */
|
|
11
|
-
export type AvatarSourceEntry = number |
|
|
30
|
+
export type AvatarSourceEntry = number | AvatarSourceRequest;
|
|
12
31
|
|
|
13
32
|
/** Anything `Image`'s `source` accepts: one entry or a list of resolutions. */
|
|
14
33
|
export type AvatarSource = AvatarSourceEntry | readonly AvatarSourceEntry[];
|
|
@@ -38,15 +57,20 @@ export function resolveAvatarInitials(name: string | undefined): string {
|
|
|
38
57
|
return `${first}${last}`.toUpperCase();
|
|
39
58
|
}
|
|
40
59
|
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
/** One entry as a plain value, ready for `JSON.stringify`. Header pairs are sorted by name. */
|
|
61
|
+
function entryKey(entry: AvatarSourceEntry): unknown {
|
|
62
|
+
if (typeof entry === "number") return ["asset", entry];
|
|
43
63
|
if (!entry.uri) return null;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
|
|
64
|
+
const headers = Object.entries(entry.headers ?? {}).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
65
|
+
return [
|
|
66
|
+
"uri",
|
|
67
|
+
entry.uri,
|
|
68
|
+
entry.bundle ?? null,
|
|
69
|
+
entry.method ?? null,
|
|
70
|
+
headers,
|
|
71
|
+
entry.body ?? null,
|
|
72
|
+
entry.cache ?? null,
|
|
73
|
+
];
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
/**
|
|
@@ -55,16 +79,19 @@ function entryKey(entry: AvatarSourceEntry): string | null {
|
|
|
55
79
|
* The avatar remembers which source failed by this key rather than by object
|
|
56
80
|
* identity, because an inline `source={{ uri }}` is a new object every render —
|
|
57
81
|
* keyed by identity, a failed image would retry forever. Keyed by URI alone, a
|
|
58
|
-
* token refresh in the headers would never retry at all.
|
|
59
|
-
*
|
|
82
|
+
* token refresh in the headers would never retry at all. Every field that
|
|
83
|
+
* changes the request is part of the key, including `cache`, so a cache miss
|
|
84
|
+
* retries when the cache mode changes. The key is a JSON array, so no value can
|
|
85
|
+
* look like a separator, and header order is normalised so an equal request is
|
|
86
|
+
* an equal key.
|
|
60
87
|
*
|
|
61
88
|
* `null` means there is nothing to load.
|
|
62
89
|
*/
|
|
63
90
|
export function resolveAvatarSourceKey(source: AvatarSource | null | undefined): string | null {
|
|
64
91
|
if (source === null || source === undefined) return null;
|
|
65
92
|
const entries: readonly AvatarSourceEntry[] = Array.isArray(source) ? source : [source as AvatarSourceEntry];
|
|
66
|
-
const keys = entries.map(entryKey).filter((key)
|
|
67
|
-
return keys.length === 0 ? null :
|
|
93
|
+
const keys = entries.map(entryKey).filter((key) => key !== null);
|
|
94
|
+
return keys.length === 0 ? null : JSON.stringify(keys);
|
|
68
95
|
}
|
|
69
96
|
|
|
70
97
|
/**
|
|
@@ -103,6 +130,26 @@ export function resolveAvatarGroup({ count, max, total }: { count: number; max?:
|
|
|
103
130
|
return { visible, overflow: people - visible };
|
|
104
131
|
}
|
|
105
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The faces a group holds, with fragments opened up.
|
|
135
|
+
*
|
|
136
|
+
* `Children.toArray` treats a fragment as one child, so a fragment with two
|
|
137
|
+
* avatars would count as one face and skip `max`. This walks into each
|
|
138
|
+
* fragment, at any depth. A face from a fragment gets the key
|
|
139
|
+
* `JSON.stringify([fragmentKey, faceKey])`. A pair rather than a joined string,
|
|
140
|
+
* because `.$a` + `.$b.$c` and `.$a.$b` + `.$c` join to the same text.
|
|
141
|
+
*/
|
|
142
|
+
export function flattenAvatarChildren(children: ReactNode): ReactElement[] {
|
|
143
|
+
return Children.toArray(children).flatMap((child) => {
|
|
144
|
+
if (!isValidElement(child)) return [];
|
|
145
|
+
if (child.type !== Fragment) return [child];
|
|
146
|
+
const { children: inner } = child.props as { children?: ReactNode };
|
|
147
|
+
return flattenAvatarChildren(inner).map((nested) =>
|
|
148
|
+
cloneElement(nested, { key: JSON.stringify([child.key, nested.key]) })
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
106
153
|
/** The most the overflow tile draws before it reads `99+`. Three digits do not fit a small circle. */
|
|
107
154
|
export const AVATAR_OVERFLOW_DISPLAY_MAX = 99;
|
|
108
155
|
|
|
@@ -255,3 +255,9 @@ describe("resolveAvatarInteractive", () => {
|
|
|
255
255
|
expect(resolveAvatarInteractive({ onLongPress: () => {} })).toBe(true);
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
|
+
|
|
259
|
+
describe("avatarVariants image", () => {
|
|
260
|
+
test("sizes the image to the face, so a bundled asset is scaled rather than drawn at its own size", () => {
|
|
261
|
+
expect(avatarVariants().image().split(" ")).toEqual(expect.arrayContaining(["absolute", "inset-0", "size-full"]));
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -109,7 +109,8 @@ export const avatarVariants = tv({
|
|
|
109
109
|
slots: {
|
|
110
110
|
root: "relative",
|
|
111
111
|
face: "size-full items-center justify-center overflow-hidden rounded-full",
|
|
112
|
-
|
|
112
|
+
/** `size-full` too: a bundled asset brings its own width and height, which `inset-0` does not override. */
|
|
113
|
+
image: "absolute inset-0 size-full",
|
|
113
114
|
fallbackLabel: "text-center font-medium",
|
|
114
115
|
/** Edge length the fallback glyph inherits. */
|
|
115
116
|
icon: "",
|
|
@@ -10,7 +10,10 @@ export {
|
|
|
10
10
|
export {
|
|
11
11
|
AVATAR_OVERFLOW_DISPLAY_MAX,
|
|
12
12
|
type AvatarSource,
|
|
13
|
+
type AvatarSourceCache,
|
|
13
14
|
type AvatarSourceEntry,
|
|
15
|
+
type AvatarSourceRequest,
|
|
16
|
+
flattenAvatarChildren,
|
|
14
17
|
resolveAvatarAccessibilityLabel,
|
|
15
18
|
resolveAvatarGroup,
|
|
16
19
|
resolveAvatarInitials,
|
|
@@ -126,8 +126,9 @@ standalone SVG document, or as a PNG.
|
|
|
126
126
|
`resolveSignatureExport`, so the same options give the same box, the same
|
|
127
127
|
literal ink and the same background or none — a PNG is transparent unless
|
|
128
128
|
`background` is set. It renders the cached stroke paths off screen on a CPU
|
|
129
|
-
surface (`Skia.Surface.MakeRaster`) at `scale` pixels per point (default the screen's ratio) and
|
|
130
|
-
base64 with no `data:` prefix, as `Sketch.toPNG` does
|
|
129
|
+
surface (`Skia.Surface.MakeRaster`) at `scale` pixels per point (default the screen's ratio) and resolves to
|
|
130
|
+
base64 with no `data:` prefix, as `Sketch.toPNG` does — a promise, because
|
|
131
|
+
react-native-skia 3.9 made `encodeToBase64` asynchronous. Off screen rather than a
|
|
131
132
|
snapshot of the pad, so the guideline, the placeholder and the pad's fill never
|
|
132
133
|
reach the file. `""` before the pad is measured. The point's `t` is stored so
|
|
133
134
|
a speed-eased stroke width can follow without a format change.
|
|
@@ -69,10 +69,13 @@ function drawSignatureStrokes(canvas: SkCanvas, strokes: readonly SignatureStrok
|
|
|
69
69
|
* uses, so the PNG is the SVG rasterised: the same box, the same literal ink,
|
|
70
70
|
* the same background or none. Off screen rather than a snapshot of the pad, so
|
|
71
71
|
* the guideline, the placeholder and the pad's own fill never reach the file.
|
|
72
|
-
* The strokes are the cached paths the pad draws.
|
|
72
|
+
* The strokes are the cached paths the pad draws. Resolves to `""` when the frame
|
|
73
73
|
* has no pixels — an unmeasured pad.
|
|
74
74
|
*/
|
|
75
|
-
export function renderSignaturePng(
|
|
75
|
+
export async function renderSignaturePng(
|
|
76
|
+
value: SignatureValue,
|
|
77
|
+
options: SignaturePngOptions & { scale: number }
|
|
78
|
+
): Promise<string> {
|
|
76
79
|
const { background, box, strokeColor, strokeWidth } = resolveSignatureExport(value, options);
|
|
77
80
|
const size = signaturePngSize(box, options.scale);
|
|
78
81
|
if (size === null) return "";
|
|
@@ -369,7 +369,7 @@ function SignatureRoot({
|
|
|
369
369
|
*
|
|
370
370
|
* @example
|
|
371
371
|
* const svg = pad.current?.toSVG({ viewBox: "tight", background: "#ffffff" });
|
|
372
|
-
* const png = pad.current?.toPNG({ viewBox: "tight", background: "#ffffff" }); // base64
|
|
372
|
+
* const png = await pad.current?.toPNG({ viewBox: "tight", background: "#ffffff" }); // base64
|
|
373
373
|
*/
|
|
374
374
|
export const Signature = Object.assign(SignatureRoot, {
|
|
375
375
|
/** The drawing surface — the gesture, the ink, the guideline and the accessibility surface. */
|
|
@@ -67,11 +67,11 @@ export type SignatureHandle = {
|
|
|
67
67
|
/** The signature as a standalone SVG document. Valid, if blank, when empty. */
|
|
68
68
|
toSVG: (options?: SignatureExportOptions) => string;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Resolves to the signature as a base64-encoded PNG (no `data:` prefix), framed and
|
|
71
71
|
* coloured as `toSVG` with the same options would be, at `scale` pixels per
|
|
72
72
|
* point. Transparent unless `background` is set. `""` before the pad is measured.
|
|
73
73
|
*/
|
|
74
|
-
toPNG: (options?: SignaturePngOptions) => string
|
|
74
|
+
toPNG: (options?: SignaturePngOptions) => Promise<string>;
|
|
75
75
|
/** One smoothed SVG path `d` per stroke, in pad coordinates. */
|
|
76
76
|
toPaths: () => readonly string[];
|
|
77
77
|
};
|
|
@@ -140,7 +140,8 @@ DisplayNames: `DelacourUI.Sketch`, `.Sketch.Canvas`, `.Toolbar`, `.Tool`,
|
|
|
140
140
|
to the canvas times `scale` (default the screen's pixel ratio), by the same
|
|
141
141
|
`drawSketchItems` the picture records — not a snapshot of the visible canvas,
|
|
142
142
|
which would need the view mounted and would capture nothing of the background
|
|
143
|
-
option. It
|
|
143
|
+
option. It resolves to base64 without a `data:` prefix — asynchronous, because
|
|
144
|
+
react-native-skia 3.9 made `encodeToBase64` return a promise; `""`
|
|
144
145
|
before the canvas is measured. Saving or sharing it is the app's job.
|
|
145
146
|
|
|
146
147
|
## Layout
|
|
@@ -70,9 +70,9 @@ type SketchPngTarget = SketchArea & { background: string | null; scale: number }
|
|
|
70
70
|
*
|
|
71
71
|
* Off screen rather than a snapshot of the visible canvas, so the file holds the
|
|
72
72
|
* marks and the background only — never the image being annotated under them —
|
|
73
|
-
* matching `toSVG`.
|
|
73
|
+
* matching `toSVG`. Resolves to `""` before the canvas is measured.
|
|
74
74
|
*/
|
|
75
|
-
export function renderSketchPng(items: readonly SketchItem[], target: SketchPngTarget): string {
|
|
75
|
+
export async function renderSketchPng(items: readonly SketchItem[], target: SketchPngTarget): Promise<string> {
|
|
76
76
|
const pixelWidth = Math.round(target.width * target.scale);
|
|
77
77
|
const pixelHeight = Math.round(target.height * target.scale);
|
|
78
78
|
if (pixelWidth <= 0 || pixelHeight <= 0) return "";
|
|
@@ -26,11 +26,11 @@ export type SketchHandle = {
|
|
|
26
26
|
/** Self-contained SVG: the viewBox is the canvas, an optional background rect, masks inlined. */
|
|
27
27
|
toSVG: (options?: SketchExportOptions) => string;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Resolves to the drawing as a base64-encoded PNG (no `data:` prefix), the canvas's size
|
|
30
30
|
* times `scale`. Holds the marks and the background only — never what
|
|
31
31
|
* `Sketch.Canvas` children paint under them. `""` before the canvas is measured.
|
|
32
32
|
*/
|
|
33
|
-
toPNG: (options?: SketchPngOptions) => string
|
|
33
|
+
toPNG: (options?: SketchPngOptions) => Promise<string>;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|