@oxy.so/bloom 21.2.0 → 21.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,7 +100,7 @@ None.
100
100
  | `activity-heatmap` | `@oxy.so/bloom/activity-heatmap` + barrel | universal | `activity-heatmap.mdx` | yes | 3 | | | | |
101
101
  | `address` | `@oxy.so/bloom/address` + barrel | universal | `address.mdx` | yes | 4 | n/a¹ | reads | | |
102
102
  | `admonition` | `@oxy.so/bloom/admonition` + barrel | universal | `admonition.mdx` | yes | 6 | | reads | | |
103
- | `agent-avatar` | `@oxy.so/bloom/agent-avatar` + barrel | universal | `agent-avatar.mdx` | yes | 49 | | | | |
103
+ | `agent-avatar` | `@oxy.so/bloom/agent-avatar` + barrel | universal | `agent-avatar.mdx` | yes | 50 | | | | |
104
104
  | `agent-chat` | `@oxy.so/bloom/agent-chat` + barrel | web fork | `agent-chat.mdx` | yes | 3 | n/a¹ | | | reads |
105
105
  | `agent-creator` | `@oxy.so/bloom/agent-creator` + barrel | web fork | `agent-creator.mdx` | yes | 18 | reads | | | |
106
106
  | `agent-limits-card` | `@oxy.so/bloom/agent-limits-card` + barrel | universal | `agent-limits-card.mdx` | yes | 2 | | | | delegated |
@@ -325,7 +325,7 @@ None.
325
325
  | `tenancy` | `@oxy.so/bloom/tenancy` + barrel | universal | `tenancy.mdx` | yes | 5 | | reads | | |
326
326
  | `text-field` | `@oxy.so/bloom/text-field` + barrel | universal | `text-field.mdx` | yes | 27 | reads | reads | | |
327
327
  | `textarea` | `@oxy.so/bloom/textarea` + barrel | universal | `textarea.mdx` | yes | 6 | reads | reads | | n/a¹ |
328
- | `theme` | `@oxy.so/bloom/theme` + barrel | web fork | `theme.mdx` | yes | 695 | | | n/a¹ | reads |
328
+ | `theme` | `@oxy.so/bloom/theme` + barrel | web fork | `theme.mdx` | yes | 696 | | | n/a¹ | reads |
329
329
  | `theme-toggle` | `@oxy.so/bloom/theme-toggle` + barrel | universal | `theme-toggle.mdx` | yes | 2 | n/a¹ | | | |
330
330
  | `toast` | `@oxy.so/bloom/toast` + barrel | universal | `toast.mdx` | yes | 21 | | | | |
331
331
  | `tooltip` | `@oxy.so/bloom/tooltip` + barrel | web fork | `tooltip.mdx` | yes | 8 | | reads | | |
@@ -568,3 +568,14 @@ The SVG cutover does not convert those historical checks into native-device vali
568
568
  `useAvatarRendererCapabilities({ enabled })` remains exported: shared live scheduling is
569
569
  available on every SVG platform when enabled, without an adapter or manifest request.
570
570
  Installing the former native companion no longer selects another rendering backend.
571
+
572
+ ## On a server: `@oxy.so/bloom/agent-avatar/svg`
573
+
574
+ Code that cannot render React (an API making a bot's profile photo, an image card) draws a
575
+ character with `@oxy.so/bloom/agent-avatar/svg`: `renderAgentAvatarSvg(character, options)` answers
576
+ the same still frame `VectorStaticPortrait` draws, as an SVG string, and `renderAgentAvatarPicture
577
+ (character, color)` a profile picture (painted in the account colour, centred with room for a
578
+ circular crop, on a much lighter tint of that colour that always keeps the character visible).
579
+ Rasterize it with whatever the server has. The entry imports no React or React Native; it draws from
580
+ the full catalog unless `catalog` is passed.
581
+
@@ -8,7 +8,7 @@ order: 4
8
8
 
9
9
  # Public React part census
10
10
 
11
- The TypeScript checker resolves **1485 React part-contract identities** through **935 native** and **935 web** package entrypoints. Aliases/namespaces and wildcard subpaths are retained below; platform implementations with the same normalized source path and symbol share one contract identity, even when their implementations differ. A family count or a hook import cannot establish part adoption.
11
+ The TypeScript checker resolves **1485 React part-contract identities** through **936 native** and **936 web** package entrypoints. Aliases/namespaces and wildcard subpaths are retained below; platform implementations with the same normalized source path and symbol share one contract identity, even when their implementations differ. A family count or a hook import cannot establish part adoption.
12
12
 
13
13
  The generator follows exported value symbols, star exports, namespace exports, default exports, callable static members, object-valued parts, memo/forwardRef/factory and class signatures. Cycles terminate by symbol and type; real aliases share identity while inline members retain their lexical owner. External part declarations retain their package provenance and do not establish a Bloom-owned implementation. React-callable exports with component names (including default/underscore names), exotic markers or element-return signatures are component candidates; lower-case aliases retain their resolved identity; ambiguous any/unknown values fail the unresolved-symbol gate. Type-only exports and lower-case scalar-return hooks/utilities are not components. Size vocabularies come from resolved prop types, including aliases, unions and subsets—not spelling patterns.
14
14
 
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "package": {
4
4
  "name": "@oxy.so/bloom",
5
- "version": "21.2.0",
5
+ "version": "21.3.0",
6
6
  "peers": {
7
7
  "@lottiefiles/dotlottie-react": ">=0.13.0",
8
8
  "@react-native-community/netinfo": ">=11.1.0",
@@ -8,7 +8,7 @@ order: 1
8
8
 
9
9
  # Choose an API by task
10
10
 
11
- This guide belongs to **@oxy.so/bloom 21.2.0**. Read it from the installed package alongside [the structured index](./task-catalog.json). A source build version is not a registry-publication receipt. Use the containing package’s manifest for exact peer ranges.
11
+ This guide belongs to **@oxy.so/bloom 21.3.0**. Read it from the installed package alongside [the structured index](./task-catalog.json). A source build version is not a registry-publication receipt. Use the containing package’s manifest for exact peer ranges.
12
12
 
13
13
  Start under the application’s BloomProvider and follow [getting started](./getting-started.mdx) for CSS, fonts and platform setup. These examples accept domain content/actions and require a bounded host. They do not add a provider per route. For document scrolling, follow [the host contract](./compose-layouts.mdx); Expo’s bounded reset must not silently prevent document overflow.
14
14
 
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.avatarPictureBackground = avatarPictureBackground;
7
+ exports.renderAgentAvatarPicture = renderAgentAvatarPicture;
8
+ exports.renderAgentAvatarSvg = renderAgentAvatarSvg;
9
+ exports.vectorFrameToSvg = vectorFrameToSvg;
10
+ var _colorUtils = require("../theme/color-engine/color-utils.js");
11
+ var _contrast = require("../theme/color-engine/contrast.js");
12
+ var _hct = require("../theme/color-engine/hct.js");
13
+ var _tonalPalette = require("../theme/color-engine/tonal-palette.js");
14
+ var _character = require("./character.js");
15
+ var _vectorAssets = require("./vector-assets.js");
16
+ var _vectorPortrait = require("./vector-portrait.js");
17
+ var _vectorViewbox = require("./vector-viewbox.js");
18
+ /**
19
+ * A character as an SVG document, with no React and no native module: for a server that needs a
20
+ * picture of an avatar (a bot's profile photo, an image card). It is the frame
21
+ * `VectorStaticPortrait` draws (`loadVectorPortrait`), through the same crop (`avatarViewBox`), so
22
+ * a server's picture and an app's portrait are one drawing.
23
+ *
24
+ * Draws from Bloom's full catalog unless a `catalog` is passed: a server has no bundle to keep
25
+ * small. Apps keep drawing with `AgentAvatar`; this entry is for code that cannot render React.
26
+ */
27
+
28
+ const ESCAPES = {
29
+ '&': '&',
30
+ '<': '&lt;',
31
+ '>': '&gt;',
32
+ '"': '&quot;',
33
+ "'": '&apos;'
34
+ };
35
+ const attr = value => String(value).replace(/[&<>"']/g, c => ESCAPES[c] ?? c);
36
+
37
+ /** A vector frame as SVG markup, drawn as `VectorStaticPortrait` draws it. */
38
+ function vectorFrameToSvg(frame, options = {}) {
39
+ const size = options.size ?? 512;
40
+ const [cx = 0, cy = 0, cw = 320, ch = 320] = (0, _vectorViewbox.avatarViewBox)(frame.viewBox).split(/\s+/).map(Number);
41
+ const margin = Math.max(0, options.margin ?? 0);
42
+ const box = [cx - cw * margin, cy - ch * margin, cw * (1 + 2 * margin), ch * (1 + 2 * margin)].map(n => Math.round(n * 100) / 100);
43
+ const viewBox = box.join(' ');
44
+ const clips = frame.paths.flatMap(path => path.clip === undefined ? [] : [`<clipPath id="c-${attr(path.id)}" clipPathUnits="userSpaceOnUse"><path d="${attr(path.clip)}"/></clipPath>`]).join('');
45
+ const background = options.background ? `<rect x="${box[0]}" y="${box[1]}" width="${box[2]}" height="${box[3]}" fill="${attr(options.background)}"/>` : '';
46
+ const paths = frame.paths.map(path => {
47
+ const parts = [`d="${attr(path.d)}"`, `fill="${attr(path.fill)}"`, `opacity="${attr(path.opacity)}"`, `fill-opacity="${attr(path.fillOpacity)}"`, 'fill-rule="nonzero"'];
48
+ if (path.stroke) {
49
+ parts.push(`stroke="${attr(path.stroke)}"`, `stroke-width="${attr(path.strokeWidth ?? 1.5)}"`);
50
+ }
51
+ if (path.clip !== undefined) parts.push(`clip-path="url(#c-${attr(path.id)})"`);
52
+ return `<path ${parts.join(' ')}/>`;
53
+ }).join('');
54
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="${attr(viewBox)}">` + `${clips ? `<defs>${clips}</defs>` : ''}${background}${paths}</svg>`;
55
+ }
56
+
57
+ /** The character, at rest, as an SVG document. */
58
+ async function renderAgentAvatarSvg(character, options = {}) {
59
+ const frame = await (0, _vectorPortrait.loadVectorPortrait)(character, options.catalog ?? _vectorAssets.vectorAssetLoader);
60
+ return vectorFrameToSvg(frame, options);
61
+ }
62
+
63
+ /** The contrast the picture's background keeps with the character's body, at least. */
64
+ const PICTURE_CONTRAST = 2.4;
65
+ /** How light the background is when the body allows it: a much lighter tint of its own colour. */
66
+ const PICTURE_LIGHT_TONE = 95;
67
+ /** The tint keeps the body's hue, softened so it reads as a background and not a second colour. */
68
+ const PICTURE_MAX_CHROMA = 20;
69
+
70
+ /**
71
+ * The background a character's picture stands on: its body colour's own hue, in a much lighter
72
+ * tint (tone 95 of a softened tonal palette, as Bloom's themes derive their surfaces). A body too
73
+ * light for that to show it (a pale yellow, a white) gets the darkest tint that keeps the same
74
+ * contrast instead, so the character is always visible against it.
75
+ */
76
+ function avatarPictureBackground(bodyHex) {
77
+ const body = _hct.Hct.fromInt((0, _colorUtils.argbFromHex)(bodyHex));
78
+ const palette = _tonalPalette.TonalPalette.fromHueAndChroma(body.hue, Math.min(body.chroma, PICTURE_MAX_CHROMA));
79
+ if ((0, _contrast.ratioOfTones)(body.tone, PICTURE_LIGHT_TONE) >= PICTURE_CONTRAST) {
80
+ return (0, _colorUtils.hexFromArgb)(palette.tone(PICTURE_LIGHT_TONE));
81
+ }
82
+ const dark = (0, _contrast.darker)(body.tone, PICTURE_CONTRAST);
83
+ return (0, _colorUtils.hexFromArgb)(palette.tone(dark < 0 ? 0 : dark));
84
+ }
85
+
86
+ /** Room around a picture's character, so a circular crop (a profile photo) never cuts it. */
87
+ const PICTURE_MARGIN = 0.12;
88
+
89
+ /**
90
+ * A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
91
+ * a hex; the character's own paint when it is not one), centred with room for a circular crop, on
92
+ * a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
93
+ * character leaves an app as an image.
94
+ */
95
+ async function renderAgentAvatarPicture(character, color, options = {}) {
96
+ const painted = (0, _character.avatarCharacterInColor)(character, color);
97
+ const background = avatarPictureBackground((0, _character.avatarBodyHex)((0, _character.resolveAvatarCharacter)(painted)));
98
+ return renderAgentAvatarSvg(painted, {
99
+ ...options,
100
+ background,
101
+ margin: PICTURE_MARGIN
102
+ });
103
+ }
104
+ //# sourceMappingURL=portrait-svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_colorUtils","require","_contrast","_hct","_tonalPalette","_character","_vectorAssets","_vectorPortrait","_vectorViewbox","ESCAPES","attr","value","String","replace","c","vectorFrameToSvg","frame","options","size","cx","cy","cw","ch","avatarViewBox","viewBox","split","map","Number","margin","Math","max","box","n","round","join","clips","paths","flatMap","path","clip","undefined","id","background","parts","d","fill","opacity","fillOpacity","stroke","push","strokeWidth","renderAgentAvatarSvg","character","loadVectorPortrait","catalog","vectorAssetLoader","PICTURE_CONTRAST","PICTURE_LIGHT_TONE","PICTURE_MAX_CHROMA","avatarPictureBackground","bodyHex","body","Hct","fromInt","argbFromHex","palette","TonalPalette","fromHueAndChroma","hue","min","chroma","ratioOfTones","tone","hexFromArgb","dark","darker","PICTURE_MARGIN","renderAgentAvatarPicture","color","painted","avatarCharacterInColor","avatarBodyHex","resolveAvatarCharacter"],"sourceRoot":"../../../src","sources":["agent-avatar/portrait-svg.ts"],"mappings":";;;;;;;;;AASA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,a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CAACf,kBAAkB,CAAC,CAAC;EACtD;EACA,MAAMiB,IAAI,GAAG,IAAAC,gBAAM,EAACd,IAAI,CAACW,IAAI,EAAEhB,gBAAgB,CAAC;EAChD,OAAO,IAAAiB,uBAAW,EAACR,OAAO,CAACO,IAAI,CAACE,IAAI,GAAG,CAAC,GAAG,CAAC,GAAGA,IAAI,CAAC,CAAC;AACvD;;AAEA;AACA,MAAME,cAAc,GAAG,IAAI;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,wBAAwBA,CAC5CzB,SAA0B,EAC1B0B,KAAgC,EAChC7D,OAAwD,GAAG,CAAC,CAAC,EAC5C;EACjB,MAAM8D,OAAO,GAAG,IAAAC,iCAAsB,EAAC5B,SAAS,EAAE0B,KAAK,CAAC;EACxD,MAAMpC,UAAU,GAAGiB,uBAAuB,CAAC,IAAAsB,wBAAa,EAAC,IAAAC,iCAAsB,EAACH,OAAO,CAAC,CAAC,CAAC;EAC1F,OAAO5B,oBAAoB,CAAC4B,OAAO,EAAE;IAAE,GAAG9D,OAAO;IAAEyB,UAAU;IAAEd,MAAM,EAAEgD;EAAe,CAAC,CAAC;AAC1F","ignoreList":[]}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "avatarCharacterInColor", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _character.avatarCharacterInColor;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "avatarPictureBackground", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _portraitSvg.avatarPictureBackground;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "parseAvatarCharacter", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _character.parseAvatarCharacter;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "renderAgentAvatarPicture", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _portraitSvg.renderAgentAvatarPicture;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "renderAgentAvatarSvg", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _portraitSvg.renderAgentAvatarSvg;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "vectorFrameToSvg", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _portraitSvg.vectorFrameToSvg;
40
+ }
41
+ });
42
+ var _portraitSvg = require("../portrait-svg.js");
43
+ var _character = require("../character.js");
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_portraitSvg","require","_character"],"sourceRoot":"../../../../src","sources":["agent-avatar/svg/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAAC,UAAA,GAAAD,OAAA","ignoreList":[]}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * A character as an SVG document, with no React and no native module: for a server that needs a
5
+ * picture of an avatar (a bot's profile photo, an image card). It is the frame
6
+ * `VectorStaticPortrait` draws (`loadVectorPortrait`), through the same crop (`avatarViewBox`), so
7
+ * a server's picture and an app's portrait are one drawing.
8
+ *
9
+ * Draws from Bloom's full catalog unless a `catalog` is passed: a server has no bundle to keep
10
+ * small. Apps keep drawing with `AgentAvatar`; this entry is for code that cannot render React.
11
+ */
12
+ import { argbFromHex, hexFromArgb } from "../theme/color-engine/color-utils.js";
13
+ import { darker, ratioOfTones } from "../theme/color-engine/contrast.js";
14
+ import { Hct } from "../theme/color-engine/hct.js";
15
+ import { TonalPalette } from "../theme/color-engine/tonal-palette.js";
16
+ import { avatarBodyHex, avatarCharacterInColor, resolveAvatarCharacter } from "./character.js";
17
+ import { vectorAssetLoader } from "./vector-assets.js";
18
+ import { loadVectorPortrait } from "./vector-portrait.js";
19
+ import { avatarViewBox } from "./vector-viewbox.js";
20
+ const ESCAPES = {
21
+ '&': '&amp;',
22
+ '<': '&lt;',
23
+ '>': '&gt;',
24
+ '"': '&quot;',
25
+ "'": '&apos;'
26
+ };
27
+ const attr = value => String(value).replace(/[&<>"']/g, c => ESCAPES[c] ?? c);
28
+
29
+ /** A vector frame as SVG markup, drawn as `VectorStaticPortrait` draws it. */
30
+ export function vectorFrameToSvg(frame, options = {}) {
31
+ const size = options.size ?? 512;
32
+ const [cx = 0, cy = 0, cw = 320, ch = 320] = avatarViewBox(frame.viewBox).split(/\s+/).map(Number);
33
+ const margin = Math.max(0, options.margin ?? 0);
34
+ const box = [cx - cw * margin, cy - ch * margin, cw * (1 + 2 * margin), ch * (1 + 2 * margin)].map(n => Math.round(n * 100) / 100);
35
+ const viewBox = box.join(' ');
36
+ const clips = frame.paths.flatMap(path => path.clip === undefined ? [] : [`<clipPath id="c-${attr(path.id)}" clipPathUnits="userSpaceOnUse"><path d="${attr(path.clip)}"/></clipPath>`]).join('');
37
+ const background = options.background ? `<rect x="${box[0]}" y="${box[1]}" width="${box[2]}" height="${box[3]}" fill="${attr(options.background)}"/>` : '';
38
+ const paths = frame.paths.map(path => {
39
+ const parts = [`d="${attr(path.d)}"`, `fill="${attr(path.fill)}"`, `opacity="${attr(path.opacity)}"`, `fill-opacity="${attr(path.fillOpacity)}"`, 'fill-rule="nonzero"'];
40
+ if (path.stroke) {
41
+ parts.push(`stroke="${attr(path.stroke)}"`, `stroke-width="${attr(path.strokeWidth ?? 1.5)}"`);
42
+ }
43
+ if (path.clip !== undefined) parts.push(`clip-path="url(#c-${attr(path.id)})"`);
44
+ return `<path ${parts.join(' ')}/>`;
45
+ }).join('');
46
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="${attr(viewBox)}">` + `${clips ? `<defs>${clips}</defs>` : ''}${background}${paths}</svg>`;
47
+ }
48
+
49
+ /** The character, at rest, as an SVG document. */
50
+ export async function renderAgentAvatarSvg(character, options = {}) {
51
+ const frame = await loadVectorPortrait(character, options.catalog ?? vectorAssetLoader);
52
+ return vectorFrameToSvg(frame, options);
53
+ }
54
+
55
+ /** The contrast the picture's background keeps with the character's body, at least. */
56
+ const PICTURE_CONTRAST = 2.4;
57
+ /** How light the background is when the body allows it: a much lighter tint of its own colour. */
58
+ const PICTURE_LIGHT_TONE = 95;
59
+ /** The tint keeps the body's hue, softened so it reads as a background and not a second colour. */
60
+ const PICTURE_MAX_CHROMA = 20;
61
+
62
+ /**
63
+ * The background a character's picture stands on: its body colour's own hue, in a much lighter
64
+ * tint (tone 95 of a softened tonal palette, as Bloom's themes derive their surfaces). A body too
65
+ * light for that to show it (a pale yellow, a white) gets the darkest tint that keeps the same
66
+ * contrast instead, so the character is always visible against it.
67
+ */
68
+ export function avatarPictureBackground(bodyHex) {
69
+ const body = Hct.fromInt(argbFromHex(bodyHex));
70
+ const palette = TonalPalette.fromHueAndChroma(body.hue, Math.min(body.chroma, PICTURE_MAX_CHROMA));
71
+ if (ratioOfTones(body.tone, PICTURE_LIGHT_TONE) >= PICTURE_CONTRAST) {
72
+ return hexFromArgb(palette.tone(PICTURE_LIGHT_TONE));
73
+ }
74
+ const dark = darker(body.tone, PICTURE_CONTRAST);
75
+ return hexFromArgb(palette.tone(dark < 0 ? 0 : dark));
76
+ }
77
+
78
+ /** Room around a picture's character, so a circular crop (a profile photo) never cuts it. */
79
+ const PICTURE_MARGIN = 0.12;
80
+
81
+ /**
82
+ * A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
83
+ * a hex; the character's own paint when it is not one), centred with room for a circular crop, on
84
+ * a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
85
+ * character leaves an app as an image.
86
+ */
87
+ export async function renderAgentAvatarPicture(character, color, options = {}) {
88
+ const painted = avatarCharacterInColor(character, color);
89
+ const background = avatarPictureBackground(avatarBodyHex(resolveAvatarCharacter(painted)));
90
+ return renderAgentAvatarSvg(painted, {
91
+ ...options,
92
+ background,
93
+ margin: PICTURE_MARGIN
94
+ });
95
+ }
96
+ //# sourceMappingURL=portrait-svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["argbFromHex","hexFromArgb","darker","ratioOfTones","Hct","TonalPalette","avatarBodyHex","avatarCharacterInColor","resolveAvatarCharacter","vectorAssetLoader","loadVectorPortrait","avatarViewBox","ESCAPES","attr","value","String","replace","c","vectorFrameToSvg","frame","options","size","cx","cy","cw","ch","viewBox","split","map","Number","margin","Math","max","box","n","round","join","clips","paths","flatMap","path","clip","undefined","id","background","parts","d","fill","opacity","fillOpacity","stroke","push","strokeWidth","renderAgentAvatarSvg","character","catalog","PICTURE_CONTRAST","PICTURE_LIGHT_TONE","PICTURE_MAX_CHROMA","avatarPictureBackground","bodyHex","body","fromInt","palette","fromHueAndChroma","hue","min","chroma","tone","dark","PICTURE_MARGIN","renderAgentAvatarPicture","color","painted"],"sourceRoot":"../../../src","sources":["agent-avatar/portrait-svg.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,sCAAmC;AAC5E,SAASC,MAAM,EAAEC,YAAY,QAAQ,mCAAgC;AACrE,SAASC,GAAG,QAAQ,8BAA2B;AAC/C,SAASC,YAAY,QAAQ,wCAAqC;AAClE,SACEC,aAAa,EACbC,sBAAsB,EACtBC,sBAAsB,QAEjB,gBAAa;AACpB,SAASC,iBAAiB,QAAQ,oBAAiB;AACnD,SAASC,kBAAkB,QAAQ,sBAAmB;AAEtD,SAASC,aAAa,QAAQ,qBAAkB;AAgBhD,MAAMC,OAA+B,GAAG;EACtC,GAAG,EAAE,OAAO;EACZ,GAAG,EAAE,MAAM;EACX,GAAG,EAAE,MAAM;EACX,GAAG,EAAE,QAAQ;EACb,GAAG,EAAE;AACP,CAAC;AACD,MAAMC,IAAI,GAAIC,KAAsB,IAAKC,MAAM,CAACD,KAAK,CAAC,CAACE,OAAO,CAAC,UAAU,EAAGC,CAAC,IAAKL,OAAO,CAACK,CAAC,CAAC,IAAIA,CAAC,CAAC;;AAElG;AACA,OAAO,SAASC,gBAAgBA,CAACC,KAA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AO,CAAC,CAAC,CAAC;EAC1F,OAAOpB,oBAAoB,CAACoB,OAAO,EAAE;IAAE,GAAGrD,OAAO;IAAEwB,UAAU;IAAEd,MAAM,EAAEwC;EAAe,CAAC,CAAC;AAC1F","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * A character as an SVG document, with no React and no native module, for a server
5
+ * (`./portrait-svg`). Apps keep drawing with `AgentAvatar`; this entry is for code that cannot
6
+ * render React. See docs/agent-avatar.mdx.
7
+ */
8
+ export { avatarPictureBackground, renderAgentAvatarPicture, renderAgentAvatarSvg, vectorFrameToSvg } from "../portrait-svg.js";
9
+ export { avatarCharacterInColor, parseAvatarCharacter } from "../character.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["avatarPictureBackground","renderAgentAvatarPicture","renderAgentAvatarSvg","vectorFrameToSvg","avatarCharacterInColor","parseAvatarCharacter"],"sourceRoot":"../../../../src","sources":["agent-avatar/svg/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA,SACEA,uBAAuB,EACvBC,wBAAwB,EACxBC,oBAAoB,EACpBC,gBAAgB,QACX,oBAAiB;AAExB,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,iBAAc","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ import { type AvatarCharacter } from './character';
2
+ import type { VectorAssetLoader, VectorFrame } from './vector-types';
3
+ export interface AgentAvatarSvgOptions {
4
+ /** The square's side, in pixels. Default 512. */
5
+ size?: number;
6
+ /** A colour behind the character (any CSS colour); transparent when absent. */
7
+ background?: string;
8
+ /**
9
+ * Room around the character, as a fraction of the avatar crop on each side. Default 0: the crop
10
+ * an app draws. A picture something crops into a circle wants some (`renderAgentAvatarPicture`).
11
+ */
12
+ margin?: number;
13
+ /** The vector assets to draw from; Bloom's full catalog when absent. */
14
+ catalog?: VectorAssetLoader;
15
+ }
16
+ /** A vector frame as SVG markup, drawn as `VectorStaticPortrait` draws it. */
17
+ export declare function vectorFrameToSvg(frame: VectorFrame, options?: AgentAvatarSvgOptions): string;
18
+ /** The character, at rest, as an SVG document. */
19
+ export declare function renderAgentAvatarSvg(character: AvatarCharacter, options?: AgentAvatarSvgOptions): Promise<string>;
20
+ /**
21
+ * The background a character's picture stands on: its body colour's own hue, in a much lighter
22
+ * tint (tone 95 of a softened tonal palette, as Bloom's themes derive their surfaces). A body too
23
+ * light for that to show it (a pale yellow, a white) gets the darkest tint that keeps the same
24
+ * contrast instead, so the character is always visible against it.
25
+ */
26
+ export declare function avatarPictureBackground(bodyHex: string): string;
27
+ /**
28
+ * A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
29
+ * a hex; the character's own paint when it is not one), centred with room for a circular crop, on
30
+ * a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
31
+ * character leaves an app as an image.
32
+ */
33
+ export declare function renderAgentAvatarPicture(character: AvatarCharacter, color: string | null | undefined, options?: Pick<AgentAvatarSvgOptions, 'size' | 'catalog'>): Promise<string>;
34
+ //# sourceMappingURL=portrait-svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portrait-svg.d.ts","sourceRoot":"","sources":["../../../../src/agent-avatar/portrait-svg.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGrE,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAWD,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAgDhG;AAED,kDAAkD;AAClD,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,eAAe,EAC1B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,MAAM,CAAC,CAGjB;AASD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAW/D;AAKD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,eAAe,EAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,GAAE,IAAI,CAAC,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAM,GAC5D,OAAO,CAAC,MAAM,CAAC,CAIjB"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A character as an SVG document, with no React and no native module, for a server
3
+ * (`./portrait-svg`). Apps keep drawing with `AgentAvatar`; this entry is for code that cannot
4
+ * render React. See docs/agent-avatar.mdx.
5
+ */
6
+ export { avatarPictureBackground, renderAgentAvatarPicture, renderAgentAvatarSvg, vectorFrameToSvg, } from '../portrait-svg';
7
+ export type { AgentAvatarSvgOptions } from '../portrait-svg';
8
+ export { avatarCharacterInColor, parseAvatarCharacter } from '../character';
9
+ export type { AvatarCharacter } from '../character';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agent-avatar/svg/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { type AvatarCharacter } from './character.js';
2
+ import type { VectorAssetLoader, VectorFrame } from './vector-types.js';
3
+ export interface AgentAvatarSvgOptions {
4
+ /** The square's side, in pixels. Default 512. */
5
+ size?: number;
6
+ /** A colour behind the character (any CSS colour); transparent when absent. */
7
+ background?: string;
8
+ /**
9
+ * Room around the character, as a fraction of the avatar crop on each side. Default 0: the crop
10
+ * an app draws. A picture something crops into a circle wants some (`renderAgentAvatarPicture`).
11
+ */
12
+ margin?: number;
13
+ /** The vector assets to draw from; Bloom's full catalog when absent. */
14
+ catalog?: VectorAssetLoader;
15
+ }
16
+ /** A vector frame as SVG markup, drawn as `VectorStaticPortrait` draws it. */
17
+ export declare function vectorFrameToSvg(frame: VectorFrame, options?: AgentAvatarSvgOptions): string;
18
+ /** The character, at rest, as an SVG document. */
19
+ export declare function renderAgentAvatarSvg(character: AvatarCharacter, options?: AgentAvatarSvgOptions): Promise<string>;
20
+ /**
21
+ * The background a character's picture stands on: its body colour's own hue, in a much lighter
22
+ * tint (tone 95 of a softened tonal palette, as Bloom's themes derive their surfaces). A body too
23
+ * light for that to show it (a pale yellow, a white) gets the darkest tint that keeps the same
24
+ * contrast instead, so the character is always visible against it.
25
+ */
26
+ export declare function avatarPictureBackground(bodyHex: string): string;
27
+ /**
28
+ * A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
29
+ * a hex; the character's own paint when it is not one), centred with room for a circular crop, on
30
+ * a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
31
+ * character leaves an app as an image.
32
+ */
33
+ export declare function renderAgentAvatarPicture(character: AvatarCharacter, color: string | null | undefined, options?: Pick<AgentAvatarSvgOptions, 'size' | 'catalog'>): Promise<string>;
34
+ //# sourceMappingURL=portrait-svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portrait-svg.d.ts","sourceRoot":"","sources":["../../../../src/agent-avatar/portrait-svg.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,gBAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAgB,CAAC;AAGrE,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAWD,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAgDhG;AAED,kDAAkD;AAClD,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,eAAe,EAC1B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,MAAM,CAAC,CAGjB;AASD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAW/D;AAKD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,eAAe,EAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,GAAE,IAAI,CAAC,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAM,GAC5D,OAAO,CAAC,MAAM,CAAC,CAIjB"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A character as an SVG document, with no React and no native module, for a server
3
+ * (`./portrait-svg`). Apps keep drawing with `AgentAvatar`; this entry is for code that cannot
4
+ * render React. See docs/agent-avatar.mdx.
5
+ */
6
+ export { avatarPictureBackground, renderAgentAvatarPicture, renderAgentAvatarSvg, vectorFrameToSvg, } from '../portrait-svg.js';
7
+ export type { AgentAvatarSvgOptions } from '../portrait-svg.js';
8
+ export { avatarCharacterInColor, parseAvatarCharacter } from '../character.js';
9
+ export type { AvatarCharacter } from '../character.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agent-avatar/svg/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,oBAAiB,CAAC;AACzB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAiB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iBAAc,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/bloom",
3
- "version": "21.2.0",
3
+ "version": "21.3.0",
4
4
  "packageManager": "bun@1.4.3",
5
5
  "description": "Bloom UI — Oxy ecosystem component library for React Native + Expo + Web",
6
6
  "main": "lib/commonjs/index.js",
@@ -667,6 +667,20 @@
667
667
  "default": "./lib/commonjs/agent-avatar/catalog/*.js"
668
668
  }
669
669
  },
670
+ "./agent-avatar/svg": {
671
+ "react-native": {
672
+ "types": "./lib/typescript/module/agent-avatar/svg/index.d.ts",
673
+ "default": "./src/agent-avatar/svg/index.ts"
674
+ },
675
+ "import": {
676
+ "types": "./lib/typescript/module/agent-avatar/svg/index.d.ts",
677
+ "default": "./lib/module/agent-avatar/svg/index.js"
678
+ },
679
+ "require": {
680
+ "types": "./lib/typescript/commonjs/agent-avatar/svg/index.d.ts",
681
+ "default": "./lib/commonjs/agent-avatar/svg/index.js"
682
+ }
683
+ },
670
684
  "./avatar-flight": {
671
685
  "react-native": {
672
686
  "types": "./lib/typescript/module/avatar-flight/index.d.ts",
@@ -4836,6 +4850,9 @@
4836
4850
  "agent-avatar/catalog/*": [
4837
4851
  "./lib/typescript/module/agent-avatar/catalog/*.d.ts"
4838
4852
  ],
4853
+ "agent-avatar/svg": [
4854
+ "./lib/typescript/module/agent-avatar/svg/index.d.ts"
4855
+ ],
4839
4856
  "avatar-flight": [
4840
4857
  "./lib/typescript/module/avatar-flight/index.d.ts"
4841
4858
  ],
@@ -0,0 +1,151 @@
1
+ /**
2
+ * A character as an SVG document, with no React and no native module: for a server that needs a
3
+ * picture of an avatar (a bot's profile photo, an image card). It is the frame
4
+ * `VectorStaticPortrait` draws (`loadVectorPortrait`), through the same crop (`avatarViewBox`), so
5
+ * a server's picture and an app's portrait are one drawing.
6
+ *
7
+ * Draws from Bloom's full catalog unless a `catalog` is passed: a server has no bundle to keep
8
+ * small. Apps keep drawing with `AgentAvatar`; this entry is for code that cannot render React.
9
+ */
10
+ import { argbFromHex, hexFromArgb } from '../theme/color-engine/color-utils';
11
+ import { darker, ratioOfTones } from '../theme/color-engine/contrast';
12
+ import { Hct } from '../theme/color-engine/hct';
13
+ import { TonalPalette } from '../theme/color-engine/tonal-palette';
14
+ import {
15
+ avatarBodyHex,
16
+ avatarCharacterInColor,
17
+ resolveAvatarCharacter,
18
+ type AvatarCharacter,
19
+ } from './character';
20
+ import { vectorAssetLoader } from './vector-assets';
21
+ import { loadVectorPortrait } from './vector-portrait';
22
+ import type { VectorAssetLoader, VectorFrame } from './vector-types';
23
+ import { avatarViewBox } from './vector-viewbox';
24
+
25
+ export interface AgentAvatarSvgOptions {
26
+ /** The square's side, in pixels. Default 512. */
27
+ size?: number;
28
+ /** A colour behind the character (any CSS colour); transparent when absent. */
29
+ background?: string;
30
+ /**
31
+ * Room around the character, as a fraction of the avatar crop on each side. Default 0: the crop
32
+ * an app draws. A picture something crops into a circle wants some (`renderAgentAvatarPicture`).
33
+ */
34
+ margin?: number;
35
+ /** The vector assets to draw from; Bloom's full catalog when absent. */
36
+ catalog?: VectorAssetLoader;
37
+ }
38
+
39
+ const ESCAPES: Record<string, string> = {
40
+ '&': '&amp;',
41
+ '<': '&lt;',
42
+ '>': '&gt;',
43
+ '"': '&quot;',
44
+ "'": '&apos;',
45
+ };
46
+ const attr = (value: string | number) => String(value).replace(/[&<>"']/g, (c) => ESCAPES[c] ?? c);
47
+
48
+ /** A vector frame as SVG markup, drawn as `VectorStaticPortrait` draws it. */
49
+ export function vectorFrameToSvg(frame: VectorFrame, options: AgentAvatarSvgOptions = {}): string {
50
+ const size = options.size ?? 512;
51
+ const [cx = 0, cy = 0, cw = 320, ch = 320] = avatarViewBox(frame.viewBox)
52
+ .split(/\s+/)
53
+ .map(Number);
54
+ const margin = Math.max(0, options.margin ?? 0);
55
+ const box = [
56
+ cx - cw * margin,
57
+ cy - ch * margin,
58
+ cw * (1 + 2 * margin),
59
+ ch * (1 + 2 * margin),
60
+ ].map((n) => Math.round(n * 100) / 100);
61
+ const viewBox = box.join(' ');
62
+ const clips = frame.paths
63
+ .flatMap((path) =>
64
+ path.clip === undefined
65
+ ? []
66
+ : [
67
+ `<clipPath id="c-${attr(path.id)}" clipPathUnits="userSpaceOnUse"><path d="${attr(path.clip)}"/></clipPath>`,
68
+ ],
69
+ )
70
+ .join('');
71
+ const background = options.background
72
+ ? `<rect x="${box[0]}" y="${box[1]}" width="${box[2]}" height="${box[3]}" fill="${attr(options.background)}"/>`
73
+ : '';
74
+ const paths = frame.paths
75
+ .map((path) => {
76
+ const parts = [
77
+ `d="${attr(path.d)}"`,
78
+ `fill="${attr(path.fill)}"`,
79
+ `opacity="${attr(path.opacity)}"`,
80
+ `fill-opacity="${attr(path.fillOpacity)}"`,
81
+ 'fill-rule="nonzero"',
82
+ ];
83
+ if (path.stroke) {
84
+ parts.push(
85
+ `stroke="${attr(path.stroke)}"`,
86
+ `stroke-width="${attr(path.strokeWidth ?? 1.5)}"`,
87
+ );
88
+ }
89
+ if (path.clip !== undefined) parts.push(`clip-path="url(#c-${attr(path.id)})"`);
90
+ return `<path ${parts.join(' ')}/>`;
91
+ })
92
+ .join('');
93
+ return (
94
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="${attr(viewBox)}">` +
95
+ `${clips ? `<defs>${clips}</defs>` : ''}${background}${paths}</svg>`
96
+ );
97
+ }
98
+
99
+ /** The character, at rest, as an SVG document. */
100
+ export async function renderAgentAvatarSvg(
101
+ character: AvatarCharacter,
102
+ options: AgentAvatarSvgOptions = {},
103
+ ): Promise<string> {
104
+ const frame = await loadVectorPortrait(character, options.catalog ?? vectorAssetLoader);
105
+ return vectorFrameToSvg(frame, options);
106
+ }
107
+
108
+ /** The contrast the picture's background keeps with the character's body, at least. */
109
+ const PICTURE_CONTRAST = 2.4;
110
+ /** How light the background is when the body allows it: a much lighter tint of its own colour. */
111
+ const PICTURE_LIGHT_TONE = 95;
112
+ /** The tint keeps the body's hue, softened so it reads as a background and not a second colour. */
113
+ const PICTURE_MAX_CHROMA = 20;
114
+
115
+ /**
116
+ * The background a character's picture stands on: its body colour's own hue, in a much lighter
117
+ * tint (tone 95 of a softened tonal palette, as Bloom's themes derive their surfaces). A body too
118
+ * light for that to show it (a pale yellow, a white) gets the darkest tint that keeps the same
119
+ * contrast instead, so the character is always visible against it.
120
+ */
121
+ export function avatarPictureBackground(bodyHex: string): string {
122
+ const body = Hct.fromInt(argbFromHex(bodyHex));
123
+ const palette = TonalPalette.fromHueAndChroma(
124
+ body.hue,
125
+ Math.min(body.chroma, PICTURE_MAX_CHROMA),
126
+ );
127
+ if (ratioOfTones(body.tone, PICTURE_LIGHT_TONE) >= PICTURE_CONTRAST) {
128
+ return hexFromArgb(palette.tone(PICTURE_LIGHT_TONE));
129
+ }
130
+ const dark = darker(body.tone, PICTURE_CONTRAST);
131
+ return hexFromArgb(palette.tone(dark < 0 ? 0 : dark));
132
+ }
133
+
134
+ /** Room around a picture's character, so a circular crop (a profile photo) never cuts it. */
135
+ const PICTURE_MARGIN = 0.12;
136
+
137
+ /**
138
+ * A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
139
+ * a hex; the character's own paint when it is not one), centred with room for a circular crop, on
140
+ * a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
141
+ * character leaves an app as an image.
142
+ */
143
+ export async function renderAgentAvatarPicture(
144
+ character: AvatarCharacter,
145
+ color: string | null | undefined,
146
+ options: Pick<AgentAvatarSvgOptions, 'size' | 'catalog'> = {},
147
+ ): Promise<string> {
148
+ const painted = avatarCharacterInColor(character, color);
149
+ const background = avatarPictureBackground(avatarBodyHex(resolveAvatarCharacter(painted)));
150
+ return renderAgentAvatarSvg(painted, { ...options, background, margin: PICTURE_MARGIN });
151
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A character as an SVG document, with no React and no native module, for a server
3
+ * (`./portrait-svg`). Apps keep drawing with `AgentAvatar`; this entry is for code that cannot
4
+ * render React. See docs/agent-avatar.mdx.
5
+ */
6
+ export {
7
+ avatarPictureBackground,
8
+ renderAgentAvatarPicture,
9
+ renderAgentAvatarSvg,
10
+ vectorFrameToSvg,
11
+ } from '../portrait-svg';
12
+ export type { AgentAvatarSvgOptions } from '../portrait-svg';
13
+ export { avatarCharacterInColor, parseAvatarCharacter } from '../character';
14
+ export type { AvatarCharacter } from '../character';