@oxy.so/bloom 21.2.0 → 21.3.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.
- package/docs/adoption-matrix.mdx +2 -2
- package/docs/agent-avatar.mdx +11 -0
- package/docs/public-parts.mdx +1 -1
- package/docs/task-catalog.json +1 -1
- package/docs/task-catalog.mdx +1 -1
- package/lib/commonjs/agent-avatar/portrait-svg.js +110 -0
- package/lib/commonjs/agent-avatar/portrait-svg.js.map +1 -0
- package/lib/commonjs/agent-avatar/svg/index.js +44 -0
- package/lib/commonjs/agent-avatar/svg/index.js.map +1 -0
- package/lib/module/agent-avatar/portrait-svg.js +102 -0
- package/lib/module/agent-avatar/portrait-svg.js.map +1 -0
- package/lib/module/agent-avatar/svg/index.js +10 -0
- package/lib/module/agent-avatar/svg/index.js.map +1 -0
- package/lib/typescript/commonjs/agent-avatar/portrait-svg.d.ts +35 -0
- package/lib/typescript/commonjs/agent-avatar/portrait-svg.d.ts.map +1 -0
- package/lib/typescript/commonjs/agent-avatar/svg/index.d.ts +10 -0
- package/lib/typescript/commonjs/agent-avatar/svg/index.d.ts.map +1 -0
- package/lib/typescript/module/agent-avatar/portrait-svg.d.ts +35 -0
- package/lib/typescript/module/agent-avatar/portrait-svg.d.ts.map +1 -0
- package/lib/typescript/module/agent-avatar/svg/index.d.ts +10 -0
- package/lib/typescript/module/agent-avatar/svg/index.d.ts.map +1 -0
- package/package.json +18 -1
- package/src/agent-avatar/portrait-svg.ts +157 -0
- package/src/agent-avatar/svg/index.ts +14 -0
package/docs/adoption-matrix.mdx
CHANGED
|
@@ -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 |
|
|
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 |
|
|
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 | | |
|
package/docs/agent-avatar.mdx
CHANGED
|
@@ -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, much lighter tint of that colour; only a body nearly as light gets a darker tint, so the character is always 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
|
+
|
package/docs/public-parts.mdx
CHANGED
|
@@ -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 **
|
|
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
|
|
package/docs/task-catalog.json
CHANGED
package/docs/task-catalog.mdx
CHANGED
|
@@ -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.
|
|
11
|
+
This guide belongs to **@oxy.so/bloom 21.3.1**. 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,110 @@
|
|
|
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
|
+
'<': '<',
|
|
31
|
+
'>': '>',
|
|
32
|
+
'"': '"',
|
|
33
|
+
"'": '''
|
|
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
|
+
/** How light the background is: a much, much lighter tint of the body's own colour. */
|
|
64
|
+
const PICTURE_LIGHT_TONE = 97;
|
|
65
|
+
/**
|
|
66
|
+
* The least contrast with the body at which that light tint still shows the character (a lime or
|
|
67
|
+
* a pure green on its own pale tint reads clearly; a pale yellow or a white would vanish).
|
|
68
|
+
*/
|
|
69
|
+
const PICTURE_MIN_CONTRAST = 1.25;
|
|
70
|
+
/** The contrast a body too light for the tint gets instead, from a darker tint of its hue. */
|
|
71
|
+
const PICTURE_FALLBACK_CONTRAST = 1.6;
|
|
72
|
+
/** The tint keeps the body's hue, softened so it reads as a background and not a second colour. */
|
|
73
|
+
const PICTURE_MAX_CHROMA = 20;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The background a character's picture stands on: its body colour's own hue in a much, much
|
|
77
|
+
* lighter tint (tone 97 of a softened tonal palette, as Bloom's themes derive their surfaces),
|
|
78
|
+
* for every colour that still shows against it, light ones included. Only a body nearly as light
|
|
79
|
+
* as that (a pale yellow, a white) gets a darker tint of its hue instead, so the character is
|
|
80
|
+
* never the same as what it stands on.
|
|
81
|
+
*/
|
|
82
|
+
function avatarPictureBackground(bodyHex) {
|
|
83
|
+
const body = _hct.Hct.fromInt((0, _colorUtils.argbFromHex)(bodyHex));
|
|
84
|
+
const palette = _tonalPalette.TonalPalette.fromHueAndChroma(body.hue, Math.min(body.chroma, PICTURE_MAX_CHROMA));
|
|
85
|
+
if ((0, _contrast.ratioOfTones)(body.tone, PICTURE_LIGHT_TONE) >= PICTURE_MIN_CONTRAST) {
|
|
86
|
+
return (0, _colorUtils.hexFromArgb)(palette.tone(PICTURE_LIGHT_TONE));
|
|
87
|
+
}
|
|
88
|
+
const dark = (0, _contrast.darker)(body.tone, PICTURE_FALLBACK_CONTRAST);
|
|
89
|
+
return (0, _colorUtils.hexFromArgb)(palette.tone(dark < 0 ? 0 : dark));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Room around a picture's character, so a circular crop (a profile photo) never cuts it. */
|
|
93
|
+
const PICTURE_MARGIN = 0.12;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
|
|
97
|
+
* a hex; the character's own paint when it is not one), centred with room for a circular crop, on
|
|
98
|
+
* a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
|
|
99
|
+
* character leaves an app as an image.
|
|
100
|
+
*/
|
|
101
|
+
async function renderAgentAvatarPicture(character, color, options = {}) {
|
|
102
|
+
const painted = (0, _character.avatarCharacterInColor)(character, color);
|
|
103
|
+
const background = avatarPictureBackground((0, _character.avatarBodyHex)((0, _character.resolveAvatarCharacter)(painted)));
|
|
104
|
+
return renderAgentAvatarSvg(painted, {
|
|
105
|
+
...options,
|
|
106
|
+
background,
|
|
107
|
+
margin: PICTURE_MARGIN
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
//# 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_LIGHT_TONE","PICTURE_MIN_CONTRAST","PICTURE_FALLBACK_CONTRAST","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,aAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAMA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AAEA,IAAAO,cAAA,GAAAP,OAAA;AAtBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA8BA,MAAMQ,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;AACO,SAASC,gBAAgBA,CAACC,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K,CAAC;EACxD,MAAMrC,UAAU,GAAGkB,uBAAuB,CAAC,IAAAsB,wBAAa,EAAC,IAAAC,iCAAsB,EAACH,OAAO,CAAC,CAAC,CAAC;EAC1F,OAAO7B,oBAAoB,CAAC6B,OAAO,EAAE;IAAE,GAAG/D,OAAO;IAAEyB,UAAU;IAAEd,MAAM,EAAEiD;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,102 @@
|
|
|
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
|
+
'&': '&',
|
|
22
|
+
'<': '<',
|
|
23
|
+
'>': '>',
|
|
24
|
+
'"': '"',
|
|
25
|
+
"'": '''
|
|
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
|
+
/** How light the background is: a much, much lighter tint of the body's own colour. */
|
|
56
|
+
const PICTURE_LIGHT_TONE = 97;
|
|
57
|
+
/**
|
|
58
|
+
* The least contrast with the body at which that light tint still shows the character (a lime or
|
|
59
|
+
* a pure green on its own pale tint reads clearly; a pale yellow or a white would vanish).
|
|
60
|
+
*/
|
|
61
|
+
const PICTURE_MIN_CONTRAST = 1.25;
|
|
62
|
+
/** The contrast a body too light for the tint gets instead, from a darker tint of its hue. */
|
|
63
|
+
const PICTURE_FALLBACK_CONTRAST = 1.6;
|
|
64
|
+
/** The tint keeps the body's hue, softened so it reads as a background and not a second colour. */
|
|
65
|
+
const PICTURE_MAX_CHROMA = 20;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The background a character's picture stands on: its body colour's own hue in a much, much
|
|
69
|
+
* lighter tint (tone 97 of a softened tonal palette, as Bloom's themes derive their surfaces),
|
|
70
|
+
* for every colour that still shows against it, light ones included. Only a body nearly as light
|
|
71
|
+
* as that (a pale yellow, a white) gets a darker tint of its hue instead, so the character is
|
|
72
|
+
* never the same as what it stands on.
|
|
73
|
+
*/
|
|
74
|
+
export function avatarPictureBackground(bodyHex) {
|
|
75
|
+
const body = Hct.fromInt(argbFromHex(bodyHex));
|
|
76
|
+
const palette = TonalPalette.fromHueAndChroma(body.hue, Math.min(body.chroma, PICTURE_MAX_CHROMA));
|
|
77
|
+
if (ratioOfTones(body.tone, PICTURE_LIGHT_TONE) >= PICTURE_MIN_CONTRAST) {
|
|
78
|
+
return hexFromArgb(palette.tone(PICTURE_LIGHT_TONE));
|
|
79
|
+
}
|
|
80
|
+
const dark = darker(body.tone, PICTURE_FALLBACK_CONTRAST);
|
|
81
|
+
return hexFromArgb(palette.tone(dark < 0 ? 0 : dark));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Room around a picture's character, so a circular crop (a profile photo) never cuts it. */
|
|
85
|
+
const PICTURE_MARGIN = 0.12;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
|
|
89
|
+
* a hex; the character's own paint when it is not one), centred with room for a circular crop, on
|
|
90
|
+
* a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
|
|
91
|
+
* character leaves an app as an image.
|
|
92
|
+
*/
|
|
93
|
+
export async function renderAgentAvatarPicture(character, color, options = {}) {
|
|
94
|
+
const painted = avatarCharacterInColor(character, color);
|
|
95
|
+
const background = avatarPictureBackground(avatarBodyHex(resolveAvatarCharacter(painted)));
|
|
96
|
+
return renderAgentAvatarSvg(painted, {
|
|
97
|
+
...options,
|
|
98
|
+
background,
|
|
99
|
+
margin: PICTURE_MARGIN
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//# 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_LIGHT_TONE","PICTURE_MIN_CONTRAST","PICTURE_FALLBACK_CONTRAST","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,KAAkB,EAAEC,OAA8B,GAAG,CAAC,CAAC,EAAU;EAChG,MAAMC,IAAI,GAAGD,OAAO,CAACC,IAAI,IAAI,GAAG;EAChC,MAAM,CAACC,EAAE,GAAG,CAAC,EAAEC,EAAE,GAAG,CAAC,EAAEC,EAAE,GAAG,GAAG,EAAEC,EAAE,GAAG,GAAG,CAAC,GAAGd,aAAa,CAACQ,KAAK,CAACO,OAAO,CAAC,CACtEC,KAAK,CAAC,KAAK,CAAC,CACZC,GAAG,CAACC,MAAM,CAAC;EACd,MAAMC,MAAM,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEZ,OAAO,CAACU,MAAM,IAA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O,CAAC/D,WAAW,CAAC6D,OAAO,CAAC,CAAC;EAC9C,MAAMG,OAAO,GAAG3D,YAAY,CAAC4D,gBAAgB,CAC3CH,IAAI,CAACI,GAAG,EACRnC,IAAI,CAACoC,GAAG,CAACL,IAAI,CAACM,MAAM,EAAET,kBAAkB,CAC1C,CAAC;EACD,IAAIxD,YAAY,CAAC2D,IAAI,CAACO,IAAI,EAAEb,kBAAkB,CAAC,IAAIC,oBAAoB,EAAE;IACvE,OAAOxD,WAAW,CAAC+D,OAAO,CAACK,IAAI,CAACb,kBAAkB,CAAC,CAAC;EACtD;EACA,MAAMc,IAAI,GAAGpE,MAAM,CAAC4D,IAAI,CAACO,IAAI,EAAEX,yBAAyB,CAAC;EACzD,OAAOzD,WAAW,CAAC+D,OAAO,CAACK,IAAI,CAACC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAGA,IAAI,CAAC,CAAC;AACvD;;AAEA;AACA,MAAMC,cAAc,GAAG,IAAI;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,wBAAwBA,CAC5ClB,SAA0B,EAC1BmB,KAAgC,EAChCrD,OAAwD,GAAG,CAAC,CAAC,EAC5C;EACjB,MAAMsD,OAAO,GAAGnE,sBAAsB,CAAC+C,SAAS,EAAEmB,KAAK,CAAC;EACxD,MAAM7B,UAAU,GAAGgB,uBAAuB,CAACtD,aAAa,CAACE,sBAAsB,CAACkE,OAAO,CAAC,CAAC,CAAC;EAC1F,OAAOrB,oBAAoB,CAACqB,OAAO,EAAE;IAAE,GAAGtD,OAAO;IAAEwB,UAAU;IAAEd,MAAM,EAAEyC;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,35 @@
|
|
|
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, much
|
|
22
|
+
* lighter tint (tone 97 of a softened tonal palette, as Bloom's themes derive their surfaces),
|
|
23
|
+
* for every colour that still shows against it, light ones included. Only a body nearly as light
|
|
24
|
+
* as that (a pale yellow, a white) gets a darker tint of its hue instead, so the character is
|
|
25
|
+
* never the same as what it stands on.
|
|
26
|
+
*/
|
|
27
|
+
export declare function avatarPictureBackground(bodyHex: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
|
|
30
|
+
* a hex; the character's own paint when it is not one), centred with room for a circular crop, on
|
|
31
|
+
* a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
|
|
32
|
+
* character leaves an app as an image.
|
|
33
|
+
*/
|
|
34
|
+
export declare function renderAgentAvatarPicture(character: AvatarCharacter, color: string | null | undefined, options?: Pick<AgentAvatarSvgOptions, 'size' | 'catalog'>): Promise<string>;
|
|
35
|
+
//# 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;AAcD;;;;;;GAMG;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,35 @@
|
|
|
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, much
|
|
22
|
+
* lighter tint (tone 97 of a softened tonal palette, as Bloom's themes derive their surfaces),
|
|
23
|
+
* for every colour that still shows against it, light ones included. Only a body nearly as light
|
|
24
|
+
* as that (a pale yellow, a white) gets a darker tint of its hue instead, so the character is
|
|
25
|
+
* never the same as what it stands on.
|
|
26
|
+
*/
|
|
27
|
+
export declare function avatarPictureBackground(bodyHex: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
|
|
30
|
+
* a hex; the character's own paint when it is not one), centred with room for a circular crop, on
|
|
31
|
+
* a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
|
|
32
|
+
* character leaves an app as an image.
|
|
33
|
+
*/
|
|
34
|
+
export declare function renderAgentAvatarPicture(character: AvatarCharacter, color: string | null | undefined, options?: Pick<AgentAvatarSvgOptions, 'size' | 'catalog'>): Promise<string>;
|
|
35
|
+
//# 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;AAcD;;;;;;GAMG;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.
|
|
3
|
+
"version": "21.3.1",
|
|
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,157 @@
|
|
|
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
|
+
'&': '&',
|
|
41
|
+
'<': '<',
|
|
42
|
+
'>': '>',
|
|
43
|
+
'"': '"',
|
|
44
|
+
"'": ''',
|
|
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
|
+
/** How light the background is: a much, much lighter tint of the body's own colour. */
|
|
109
|
+
const PICTURE_LIGHT_TONE = 97;
|
|
110
|
+
/**
|
|
111
|
+
* The least contrast with the body at which that light tint still shows the character (a lime or
|
|
112
|
+
* a pure green on its own pale tint reads clearly; a pale yellow or a white would vanish).
|
|
113
|
+
*/
|
|
114
|
+
const PICTURE_MIN_CONTRAST = 1.25;
|
|
115
|
+
/** The contrast a body too light for the tint gets instead, from a darker tint of its hue. */
|
|
116
|
+
const PICTURE_FALLBACK_CONTRAST = 1.6;
|
|
117
|
+
/** The tint keeps the body's hue, softened so it reads as a background and not a second colour. */
|
|
118
|
+
const PICTURE_MAX_CHROMA = 20;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The background a character's picture stands on: its body colour's own hue in a much, much
|
|
122
|
+
* lighter tint (tone 97 of a softened tonal palette, as Bloom's themes derive their surfaces),
|
|
123
|
+
* for every colour that still shows against it, light ones included. Only a body nearly as light
|
|
124
|
+
* as that (a pale yellow, a white) gets a darker tint of its hue instead, so the character is
|
|
125
|
+
* never the same as what it stands on.
|
|
126
|
+
*/
|
|
127
|
+
export function avatarPictureBackground(bodyHex: string): string {
|
|
128
|
+
const body = Hct.fromInt(argbFromHex(bodyHex));
|
|
129
|
+
const palette = TonalPalette.fromHueAndChroma(
|
|
130
|
+
body.hue,
|
|
131
|
+
Math.min(body.chroma, PICTURE_MAX_CHROMA),
|
|
132
|
+
);
|
|
133
|
+
if (ratioOfTones(body.tone, PICTURE_LIGHT_TONE) >= PICTURE_MIN_CONTRAST) {
|
|
134
|
+
return hexFromArgb(palette.tone(PICTURE_LIGHT_TONE));
|
|
135
|
+
}
|
|
136
|
+
const dark = darker(body.tone, PICTURE_FALLBACK_CONTRAST);
|
|
137
|
+
return hexFromArgb(palette.tone(dark < 0 ? 0 : dark));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Room around a picture's character, so a circular crop (a profile photo) never cuts it. */
|
|
141
|
+
const PICTURE_MARGIN = 0.12;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A gemie's or a person's profile picture: the character painted in `color` (a Bloom preset key or
|
|
145
|
+
* a hex; the character's own paint when it is not one), centred with room for a circular crop, on
|
|
146
|
+
* a much lighter tint of that colour (`avatarPictureBackground`). One drawing for every place a
|
|
147
|
+
* character leaves an app as an image.
|
|
148
|
+
*/
|
|
149
|
+
export async function renderAgentAvatarPicture(
|
|
150
|
+
character: AvatarCharacter,
|
|
151
|
+
color: string | null | undefined,
|
|
152
|
+
options: Pick<AgentAvatarSvgOptions, 'size' | 'catalog'> = {},
|
|
153
|
+
): Promise<string> {
|
|
154
|
+
const painted = avatarCharacterInColor(character, color);
|
|
155
|
+
const background = avatarPictureBackground(avatarBodyHex(resolveAvatarCharacter(painted)));
|
|
156
|
+
return renderAgentAvatarSvg(painted, { ...options, background, margin: PICTURE_MARGIN });
|
|
157
|
+
}
|
|
@@ -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';
|