@kodax-ai/botui 0.1.2 → 0.1.3
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/README.md +32 -6
- package/core/identity.js +46 -0
- package/{themes/solids → core}/motion.js +114 -114
- package/core/registry.js +26 -18
- package/docs/usage.md +202 -0
- package/element.js +5 -0
- package/index.d.ts +2 -0
- package/index.js +11 -9
- package/package.json +33 -2
- package/themes/caret/README.md +43 -0
- package/themes/caret/avatar.js +10 -0
- package/themes/caret/engine.js +143 -0
- package/themes/caret/index.d.ts +24 -0
- package/themes/caret/index.js +35 -0
- package/themes/critter/README.md +43 -0
- package/themes/critter/avatar.js +12 -0
- package/themes/critter/engine.js +113 -0
- package/themes/critter/index.d.ts +28 -0
- package/themes/critter/index.js +35 -0
- package/themes/doodle/README.md +43 -0
- package/themes/doodle/avatar.js +10 -0
- package/themes/doodle/engine.js +149 -0
- package/themes/doodle/index.d.ts +24 -0
- package/themes/doodle/index.js +36 -0
- package/themes/dots/README.md +42 -0
- package/themes/dots/avatar.js +15 -0
- package/themes/dots/engine.js +179 -0
- package/themes/dots/index.d.ts +24 -0
- package/themes/dots/index.js +35 -0
- package/themes/kaomoji/README.md +42 -0
- package/themes/kaomoji/avatar.js +10 -0
- package/themes/kaomoji/engine.js +110 -0
- package/themes/kaomoji/index.d.ts +24 -0
- package/themes/kaomoji/index.js +35 -0
- package/themes/liquid/README.md +47 -0
- package/themes/liquid/avatar.js +10 -0
- package/themes/liquid/engine.js +161 -0
- package/themes/liquid/index.d.ts +24 -0
- package/themes/liquid/index.js +35 -0
- package/themes/matrix/README.md +4 -2
- package/themes/matrix/avatar.js +24 -19
- package/themes/matrix/engine.js +61 -25
- package/themes/matrix/index.d.ts +2 -1
- package/themes/matrix/index.js +9 -15
- package/themes/orb/README.md +44 -0
- package/themes/orb/avatar.js +10 -0
- package/themes/orb/engine.js +130 -0
- package/themes/orb/index.d.ts +24 -0
- package/themes/orb/index.js +36 -0
- package/themes/solids/README.md +1 -1
- package/themes/solids/avatar.js +6 -24
- package/themes/solids/face.js +52 -56
- package/themes/solids/index.js +34 -28
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
收录各种类型 Bot 形象的专门项目。RSIBot 采用其中一套主题。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
共 9 个主题,零依赖。推荐系列是“立体家族”(带眼睛的立体):36 个立体、16 种颜色、3 种眼型、55 个状态、17 个动作、21 种眼神。另外 8 个主题共用点阵主题的引擎(见下面的“主题”),颜色、眼型、状态、动作、眼神与立体家族一致,同一个 Bot ID 在每个主题里是同一种颜色和眼型。早期草图的对比板在 `avatar-lab/directions.html`。
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
@@ -33,7 +33,30 @@ bot.setState('thinking');
|
|
|
33
33
|
<bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
总入口只带默认主题立体家族,其他主题按需引入,不用的不会进你的包:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
40
|
+
import '@kodax-ai/botui/themes/kaomoji'; // 引入即注册
|
|
41
|
+
|
|
42
|
+
const bot = createAvatar({theme: 'kaomoji', identity: 'research-bot'});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
只用一个主题时也可以直接 `import {createAvatar} from '@kodax-ai/botui/themes/<主题名>'`。CDN 用法同理:先加载 `themes/<主题名>/index.js`,再写 `<bot-avatar theme="<主题名>">`。也可以不经 npm,按版本标签引用本仓库:`npm install github:icetomoyo/BotUI#v0.1.3`。接入说明(选主题、React / Vue / 纯 HTML、状态映射、包体积、水印)见 [docs/usage.md](docs/usage.md),它也随 npm 包发布。完整的选项和方法见 [themes/solids/README.md](themes/solids/README.md)。
|
|
46
|
+
|
|
47
|
+
## 主题
|
|
48
|
+
|
|
49
|
+
| 主题 | `theme` | 样子 | 说明 |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| 立体家族 | `solids` | 带眼睛的立体(默认) | [themes/solids](themes/solids/README.md) |
|
|
52
|
+
| 点阵 | `matrix` | 彩色方块上的 5×5 点阵屏 | [themes/matrix](themes/matrix/README.md) |
|
|
53
|
+
| 活点 | `dots` | 五颗带弹簧的点,拉长、分裂、合并成表情 | [themes/dots](themes/dots/README.md) |
|
|
54
|
+
| 字符脸 | `kaomoji` | 打出来的字符脸 `o_o` `^_^` | [themes/kaomoji](themes/kaomoji/README.md) |
|
|
55
|
+
| 光标 | `caret` | 一个文本光标,弯成各种字形 | [themes/caret](themes/caret/README.md) |
|
|
56
|
+
| 光晕 | `orb` | 流动的柔光,加立体家族的眼睛 | [themes/orb](themes/orb/README.md) |
|
|
57
|
+
| 液面 | `liquid` | 玻璃杯里的液体,液面就是脸 | [themes/liquid](themes/liquid/README.md) |
|
|
58
|
+
| 像素生物 | `critter` | 像素画小生物,猫耳 / 熊耳 / 兔耳 / 天线 | [themes/critter](themes/critter/README.md) |
|
|
59
|
+
| 手绘 | `doodle` | 抖动的墨线手绘,带嘴 | [themes/doodle](themes/doodle/README.md) |
|
|
37
60
|
|
|
38
61
|
## 许可
|
|
39
62
|
|
|
@@ -50,18 +73,21 @@ bot.setState('thinking');
|
|
|
50
73
|
|
|
51
74
|
| 路径 | 内容 |
|
|
52
75
|
|---|---|
|
|
53
|
-
| `core/` | 各主题共用:帧循环、身份哈希、指针、状态词表(`states.js`)、主题注册(`registry.js`) |
|
|
76
|
+
| `core/` | 各主题共用:帧循环、身份哈希、指针、状态词表(`states.js`)、主题注册(`registry.js`)、姿态和动作(`motion.js`)、颜色眼型水印(`identity.js`) |
|
|
54
77
|
| `themes/solids/` | 推荐系列“立体家族”:带眼睛的立体。用法见 [themes/solids/README.md](themes/solids/README.md) |
|
|
55
78
|
| `themes/matrix/` | 点阵:彩色方块上的 5×5 点阵屏,颜色和眼型与立体家族一致。用法见 [themes/matrix/README.md](themes/matrix/README.md) |
|
|
56
|
-
| `
|
|
79
|
+
| `themes/dots/` | 活点:同一块方块上五颗带弹簧的点,拉长、分裂、合并成每种表情。用法见 [themes/dots/README.md](themes/dots/README.md) |
|
|
80
|
+
| `themes/kaomoji/` … `themes/doodle/` | 字符脸、光标、光晕、液面、像素生物、手绘,都建在点阵上,各自目录有 README |
|
|
81
|
+
| `index.js` | 总入口:`createAvatar({theme, ...})`,只带立体家族,其他主题引入后自动注册 |
|
|
57
82
|
| `element.js` | 自定义元素 `<bot-avatar>` |
|
|
58
83
|
| `index.d.ts` | 类型声明 |
|
|
59
84
|
| `tests/check.html` | 自检页:把每个主题的所有外形、状态、动作、眼神、颜色和选项跑一遍 |
|
|
60
|
-
| `
|
|
85
|
+
| `docs/usage.md` | 给使用方的接入说明(随 npm 包发布) |
|
|
86
|
+
| `avatar-lab/` | 早期草图存档 |
|
|
61
87
|
|
|
62
88
|
## 本地查看
|
|
63
89
|
|
|
64
|
-
ES 模块不能从 `file://` 加载。双击根目录的 `serve.cmd` 会起本地服务并打开试玩页 `themes/solids/playground.html
|
|
90
|
+
ES 模块不能从 `file://` 加载。双击根目录的 `serve.cmd` 会起本地服务并打开试玩页 `themes/solids/playground.html`(其他主题在各自目录下,如 `themes/matrix/playground.html`)。立体家族目录里的 `sheet.html`(全家福)和 `filmstrip.html`(连续帧)用来核对造型和动作。
|
|
65
91
|
|
|
66
92
|
自检:服务起来后打开 `http://127.0.0.1:8765/tests/check.html`,页面显示 `PASS` 或失败清单。
|
|
67
93
|
|
package/core/identity.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// What a Bot looks like in every theme: its colour, its eye style and the
|
|
2
|
+
// attribution it carries. A theme adds its own shapes on top, so the same Bot ID
|
|
3
|
+
// keeps its colour and eyes whichever theme draws it.
|
|
4
|
+
|
|
5
|
+
import {hash} from './core.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Body colours. `chroma`, `base` and `span` default to a saturated mid tone; `eye`
|
|
9
|
+
* overrides the eye colour; `dark` holds what changes on a dark background
|
|
10
|
+
* (without it the colour is simply a little lighter there).
|
|
11
|
+
*/
|
|
12
|
+
export const COLORS = {
|
|
13
|
+
red: {hue: 25}, orange: {hue: 55}, amber: {hue: 85}, lime: {hue: 120}, green: {hue: 150}, teal: {hue: 175},
|
|
14
|
+
cyan: {hue: 200}, sky: {hue: 235}, blue: {hue: 265}, violet: {hue: 290}, magenta: {hue: 330}, pink: {hue: 0, chroma: 0.13, base: 0.68},
|
|
15
|
+
brown: {hue: 60, chroma: 0.06, base: 0.5, dark: {base: 0.58}}, gray: {hue: 260, chroma: 0.012, base: 0.58, dark: {base: 0.67}},
|
|
16
|
+
black: {hue: 260, chroma: 0.012, base: 0.3, span: 0.15, dark: {base: 0.45, span: 0.17, chroma: 0.02}},
|
|
17
|
+
white: {hue: 260, chroma: 0.006, base: 0.83, span: 0.13, eye: 'oklch(0.3 0.03 260)', dark: {}},
|
|
18
|
+
};
|
|
19
|
+
/** The colours a Bot ID can be born with: the twelve saturated ones. */
|
|
20
|
+
export const BIRTH_COLORS = Object.keys(COLORS).slice(0, 12);
|
|
21
|
+
export const HUES = BIRTH_COLORS.map(name => COLORS[name].hue);
|
|
22
|
+
|
|
23
|
+
/** The eye style a Bot is born with, as the solids draw it. `gap` is half the distance between eyes. */
|
|
24
|
+
export const EYE_STYLES = {
|
|
25
|
+
bar: {h: 0.2, w: 0.3, gap: 0.4},
|
|
26
|
+
dot: {h: 0.03, w: 0.42, gap: 0.42},
|
|
27
|
+
tall: {h: 0.27, w: 0.2, gap: 0.34},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Names from `given` that pass `test`, or all of `all` when none do. */
|
|
31
|
+
export const pick = (given, test, all) => { const kept = (given || []).filter(test); return kept.length ? kept : all; };
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The colour and eye style a Bot ID maps to, the same in every theme. `pool` can
|
|
35
|
+
* limit the choice: {colors, eyes}, each a list of names.
|
|
36
|
+
*/
|
|
37
|
+
export function bornLook(identity, pool) {
|
|
38
|
+
const h = hash(identity), colors = pick(pool?.colors, name => COLORS[name], BIRTH_COLORS), eyes = pick(pool?.eyes, name => EYE_STYLES[name], Object.keys(EYE_STYLES));
|
|
39
|
+
return {color: colors[(h >>> 8) % colors.length], eyes: eyes[(h >>> 16) % eyes.length]};
|
|
40
|
+
}
|
|
41
|
+
/** A theme's shape for a Bot ID, from `shapes` (names), honouring pool.shapes. */
|
|
42
|
+
export const shapeFor = (identity, shapes, pool) => { const list = pick(pool?.shapes, name => shapes.includes(name), shapes); return list[hash(identity + '/shape') % list.length]; };
|
|
43
|
+
|
|
44
|
+
// Attribution carried by every avatar: invisibly in the SVG, and as a visible mark from WATERMARK_FROM pixels up.
|
|
45
|
+
export const WATERMARK = 'KodaX-AI', WATERMARK_FROM = 48;
|
|
46
|
+
export const CREDIT = 'BotUI. Copyright (c) 2026 Wei Zhang (icetomoyo) / KodaX-AI. KodaX-AI BotUI License 1.0. https://github.com/icetomoyo/BotUI';
|
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
// How
|
|
2
|
-
//
|
|
3
|
-
// A pose is `(avatar, t, look) => targets`, returning only what differs from
|
|
4
|
-
// REST. `look` is where the avatar's attention is, each axis about -1..1.
|
|
5
|
-
// Targets: yaw, pitch, roll (radians); sy (vertical stretch); lift (down is
|
|
6
|
-
// positive); scale; gx, gy (eyes sliding on the face); expr; sat; blush;
|
|
7
|
-
// rate and stiff (how fast it gets there); orbit (speed of circling dots);
|
|
8
|
-
// mark (a glyph beside the head); ring ('progress' or 'spin'); bars (sound
|
|
9
|
-
// bars); still (no blinking).
|
|
10
|
-
|
|
11
|
-
import {TAU, smooth, bump} from '
|
|
12
|
-
|
|
13
|
-
// The resting turn and tilt every pose is built on. A page may change it to try other angles.
|
|
14
|
-
export const BASE = {yaw: 0.3, pitch: -0.26};
|
|
15
|
-
export const REST = {get yaw() { return BASE.yaw; }, get pitch() { return BASE.pitch; }, roll: 0, sy: 1, lift: 0, scale: 1, gx: 0, gy: 0, expr: 'neutral', sat: 1, blush: 0, rate: 9, stiff: 260, orbit: 0, mark: null, ring: null, bars: false, still: false};
|
|
16
|
-
|
|
17
|
-
const sin = Math.sin;
|
|
18
|
-
const beat = (t, f) => Math.abs(sin(t * f));
|
|
19
|
-
const talk = t => Math.abs(sin(t * 4.2) * Math.cos(t * 1.7));
|
|
20
|
-
const float = t => 2 * sin(t * 1.7);
|
|
21
|
-
// Positive yaw turns the face to the viewer's left and negative pitch tilts it up, so a look to the right or down subtracts yaw and adds pitch.
|
|
22
|
-
// The rest pose already tilts up, so looking up gets less travel than looking down.
|
|
23
|
-
const facing = (l, yaw = BASE.yaw, pitch = BASE.pitch) => ({yaw: yaw - l.x * 0.9, pitch: pitch + l.y * (l.y < 0 ? 0.4 : 0.6), gx: l.x * 0.16, gy: l.y * 0.16});
|
|
24
|
-
const SHOW = ['nod', 'spin', 'wink', 'jump', 'wobble', 'tilt', 'flip', 'dance', 'glance', 'stretch'];
|
|
25
|
-
const PLAY = ['wink', 'wobble', 'spin', 'dance'];
|
|
26
|
-
|
|
27
|
-
export const POSES = {
|
|
28
|
-
// ---- the working day ----
|
|
29
|
-
idle: {pose: (a, t, l) => ({...facing(l), lift: float(t)})},
|
|
30
|
-
listening: {enter: a => a.hop(60), pose: (a, t, l) => ({...facing(l, 0, -0.4), scale: 1.06, roll: 0.07 * sin(t * 0.9), lift: 1.5 * sin(t * 2.4), expr: 'wide'})},
|
|
31
|
-
thinking: {pose: (a, t) => ({yaw: 0.75 * sin(t * 1.15), pitch: 0.2 + 0.08 * sin(t * 2.3), roll: 0.1 * sin(t * 0.8), gx: 0.16 * sin(t * 1.15), gy: -0.2, lift: float(t), rate: 6, orbit: 1})},
|
|
32
|
-
streaming: {pose: (a, t) => ({yaw: 0.25 + 0.3 * sin(t * 1.3), sy: 0.8 + 0.42 * talk(t), lift: float(t), rate: 20, stiff: 700, mark: 'dots'})},
|
|
33
|
-
searching: {pose: (a, t) => { if (a.every(1.1)) a.pulse(); return {yaw: 0.9 * sin(t * 1.6), pitch: -0.2 + 0.12 * sin(t * 0.9), gx: 0.14 * sin(t * 1.6), gy: 0.05 * sin(t * 2.7), lift: float(t), expr: 'inspecting', mark: 'search', rate: 7}; }},
|
|
34
|
-
reading: {pose: (a, t) => { const u = (t * 0.9) % 1, line = Math.floor(t * 0.9) % 3; return {yaw: 0.5 * (u - 0.5), pitch: -0.44 + 0.06 * line, gx: 0.2 * (u - 0.5), gy: 0.1 + 0.04 * line, lift: float(t) * 0.5, rate: 10}; }},
|
|
35
|
-
working: {pose: (a, t) => ({yaw: BASE.yaw + 0.14 * sin(t * 2.2), pitch: -0.5, roll: 0.07 * sin(t * 7), lift: -2.5 * beat(t, 7), gx: 0.14 * sin(t * 3.1), gy: 0.12, expr: 'focus'})},
|
|
36
|
-
coding: {pose: (a, t) => ({yaw: BASE.yaw + 0.1 * sin(t * 1.9), pitch: -0.45, lift: -1.8 * beat(t, 9), sy: 1 - 0.04 * beat(t, 9), gx: 0.1 * sin(t * 2.3), gy: 0.12, expr: 'focus', mark: 'code'})},
|
|
37
|
-
running: {pose: (a, t) => { if (a.every(0.26)) a.emit('dust'); return {yaw: 0.55, pitch: -0.2, roll: 0.14 + 0.05 * sin(t * 14), lift: -7 * beat(t, 7), sy: 1 + 0.08 * sin(t * 14), gx: 0.12, expr: 'focus', rate: 12}; }},
|
|
38
|
-
computing: {pose: (a, t) => ({yaw: BASE.yaw + 0.25 * sin(t * 2), pitch: -0.05, roll: 0.05 * sin(t * 3.3), gy: -0.16, gx: 0.1 * sin(t * 4), lift: float(t), expr: 'focus', orbit: 2.3})},
|
|
39
|
-
controlling: {pose: (a, t) => { if (a.every(0.77)) a.nudge(); const k = Math.floor(t * 1.3), x = sin(k * 12.9898) * 0.9, y = sin(k * 78.233) * 0.6; return {yaw: BASE.yaw + x * 0.7, pitch: -0.26 - y * 0.4, gx: x * 0.15, gy: y * 0.12, lift: float(t), expr: 'focus', mark: 'cursor', rate: 14}; }},
|
|
40
|
-
asking: {enter: a => a.play('tilt'), pose: (a, t, l) => { if (a.every(3.2)) a.hop(70); return {...facing(l, 0.1, -0.3), roll: 0.2 * Math.sign(sin(t * 1.1)), lift: float(t), expr: 'wide', mark: 'ask'}; }},
|
|
41
|
-
blocked: {pose: () => ({yaw: 0.3, pitch: -0.22, sy: 0.55, lift: 12, expr: 'closed', sat: 0.25, rate: 5, stiff: 120})},
|
|
42
|
-
finished: {enter: a => { a.play('spin'); a.hop(150); a.burst('spark', 8); }, pose: (a, t) => ({yaw: 0.3, pitch: -0.3, lift: float(t), expr: 'happy'})},
|
|
43
|
-
error: {enter: a => { a.play('shake'); a.express('cross', 1300); }, pose: () => ({yaw: 0.15, pitch: -0.2, roll: 0.12, sy: 0.9, lift: 5, gy: 0.1, expr: 'sad', sat: 0.6})},
|
|
44
|
-
sleeping: {pose: (a, t) => { if (a.every(1.3)) a.emit('z'); return {yaw: 0.35, pitch: -0.42, roll: 0.14, sy: 0.88 + 0.05 * sin(t * 1.2), lift: 8, expr: 'sleep', sat: 0.85, rate: 3, stiff: 60}; }},
|
|
45
|
-
waking: {enter: a => { a.express('sleepy', 1100); a.play('stretch'); }, pose: (a, t, l) => ({...facing(l), lift: float(t), expr: 'wide'})},
|
|
46
|
-
|
|
47
|
-
// ---- moods ----
|
|
48
|
-
happy: {pose: (a, t, l) => ({...facing(l), lift: -3 * beat(t, 3.2), roll: 0.08 * sin(t * 3.2), expr: 'happy', blush: 0.5})},
|
|
49
|
-
excited: {enter: a => a.hop(120), pose: (a, t, l) => { if (a.every(1.6)) a.burst('spark', 4); return {...facing(l, 0.2, -0.32), lift: -7 * beat(t, 6), sy: 1 + 0.07 * sin(t * 12), scale: 1.06, expr: 'sparkle', blush: 0.4}; }},
|
|
50
|
-
laughing: {pose: (a, t) => ({yaw: BASE.yaw, pitch: -0.5, lift: -2.5 * beat(t, 11), sy: 1 + 0.07 * sin(t * 22), roll: 0.06 * sin(t * 5), expr: 'happy', blush: 0.6, stiff: 700, rate: 14})},
|
|
51
|
-
proud: {pose: (a, t) => { if (a.every(2.2)) a.burst('spark', 3); return {yaw: 0.35, pitch: -0.55, sy: 1.07, scale: 1.06, lift: float(t) * 0.5, expr: 'calm', blush: 0.3}; }},
|
|
52
|
-
curious: {pose: (a, t, l) => ({...facing(l, 0.1, -0.3), roll: 0.22 * Math.sign(sin(t * 0.8)), scale: 1.07, lift: float(t), expr: 'inspecting'})},
|
|
53
|
-
playful: {pose: (a, t, l) => { if (a.every(2.4)) a.play(PLAY[a.beat++ % PLAY.length]); return {...facing(l), roll: 0.16 * sin(t * 2.6), lift: -4 * beat(t, 2.6), expr: 'happy'}; }},
|
|
54
|
-
shy: {pose: (a, t) => ({yaw: 0.75, pitch: 0.05, roll: -0.08, scale: 0.94, gx: 0.12, gy: 0.14, lift: 3 + float(t) * 0.4, expr: 'shy', blush: 1, rate: 5})},
|
|
55
|
-
surprised: {enter: a => a.play('startle'), pose: (a, t, l) => ({...facing(l, 0.2, -0.4), scale: 1.08, sy: 1.06, lift: -2, expr: 'surprised'})},
|
|
56
|
-
suspicious: {pose: (a, t) => ({yaw: 0.6, pitch: -0.2, roll: -0.1, gx: -0.16, gy: 0.02 * sin(t), lift: float(t) * 0.5, expr: 'skeptic', rate: 4})},
|
|
57
|
-
angry: {pose: (a, t, l) => { if (a.every(1.5)) a.squash(2); return {...facing(l, 0.15, -0.2), roll: 0.035 * sin(t * 38), sy: 0.94, scale: 1.04, lift: 2, expr: 'angry', mark: 'anger', rate: 12}; }},
|
|
58
|
-
confused: {pose: (a, t) => ({yaw: 0.5 * sin(t * 0.9), pitch: -0.2, roll: 0.2 * sin(t * 0.9 + 1), gx: 0.1 * sin(t * 1.8), lift: float(t), expr: 'confused', mark: 'ask'})},
|
|
59
|
-
sad: {pose: a => { if (a.every(2.4)) a.emit('tear'); return {yaw: 0.15, pitch: 0.12, sy: 0.92, lift: 6, gy: 0.14, roll: -0.06, expr: 'sad', sat: 0.7, rate: 4, stiff: 120}; }},
|
|
60
|
-
drowsy: {pose: (a, t) => { const u = (t * 0.35) % 1, nod = u < 0.8 ? smooth(u / 0.8) : 1 - smooth((u - 0.8) / 0.2); return {yaw: 0.25, pitch: -0.3 + 0.5 * nod, roll: 0.12 * nod, lift: 3 + 4 * nod, expr: 'sleepy', sat: 0.9, rate: 8}; }},
|
|
61
|
-
bored: {pose: (a, t) => { if (a.every(4)) a.squash(1.5); return {yaw: 0.5, pitch: -0.15, roll: 0.2, sy: 0.94 + 0.03 * sin(t * 0.8), lift: 5, gx: 0.15 * sin(t * 0.4), gy: -0.1, expr: 'sleepy', rate: 3, stiff: 80}; }},
|
|
62
|
-
scared: {pose: (a, t) => ({yaw: -0.3, pitch: -0.38, roll: 0.03 * sin(t * 45), sy: 0.9, scale: 0.92, lift: 3, gx: 0.1 * sin(t * 7), gy: -0.05, expr: 'surprised', sat: 0.8, mark: 'sweat', rate: 14})},
|
|
63
|
-
celebrating: {enter: a => { a.play('jump'); a.burst('confetti', 14); }, pose: (a, t) => { if (a.every(1.15)) { a.play(a.beat++ % 2 ? 'jump' : 'spin'); a.burst('confetti', 10); } return {yaw: 0.25, pitch: -0.3, lift: float(t), expr: 'sparkle'}; }},
|
|
64
|
-
approving: {enter: a => a.play('nod'), pose: (a, t, l) => { if (a.every(1.7)) a.play('nod'); return {...facing(l), lift: float(t), expr: 'happy', mark: 'check'}; }},
|
|
65
|
-
loving: {pose: (a, t, l) => { if (a.every(0.9)) a.emit('heart'); return {...facing(l, 0.15, -0.3), roll: 0.1 * sin(t * 2), lift: -2 * beat(t, 2), scale: 1.04, expr: 'love', blush: 0.8}; }},
|
|
66
|
-
|
|
67
|
-
// ---- signals: what is going on, shown with something around the body ----
|
|
68
|
-
orbit: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 1.3), gx: 0.14 * Math.cos(t * 2.6), gy: 0.08 * sin(t * 2.6), lift: float(t), orbit: 1.6})},
|
|
69
|
-
radar: {pose: (a, t) => { if (a.every(0.9)) a.pulse(); return {yaw: 1.0 * sin(t * 1.1), pitch: -0.3, lift: float(t), expr: 'wide', rate: 8}; }},
|
|
70
|
-
progress: {pose: (a, t, l) => ({...facing(l, 0.2, -0.3), lift: float(t) * 0.5, expr: 'focus', ring: 'progress'})},
|
|
71
|
-
loading: {pose: (a, t) => ({yaw: BASE.yaw + 0.15 * sin(t * 2), lift: float(t), gy: -0.08, ring: 'spin'})},
|
|
72
|
-
spawning: {enter: a => { a.p.scale = 0.15; a.vel.scale = 0; for (let i = 0; i < 8; i++) a.emit('in'); }, pose: (a, t) => { if (a.every(0.2) && a.since < 2.4) a.emit('in'); return {scale: Math.min(1, 0.3 + a.since * 0.32), yaw: BASE.yaw + Math.max(0, 2.4 - a.since) * 1.2, lift: float(t), expr: a.since < 1.6 ? 'closed' : 'wide', rate: 12}; }},
|
|
73
|
-
dictating: {pose: (a, t) => ({yaw: BASE.yaw + 0.2 * sin(t * 1.1), sy: 0.92 + 0.2 * talk(t), lift: float(t), expr: 'calm', bars: true, rate: 20, stiff: 700})},
|
|
74
|
-
sending: {pose: (a, t) => { if (a.every(0.2)) a.emit('out'); return {yaw: 0.45, pitch: -0.45, lift: float(t) - 2, gx: 0.1, gy: -0.15, expr: 'focus'}; }},
|
|
75
|
-
receiving: {pose: (a, t) => { if (a.every(0.13)) a.emit('in'); return {yaw: BASE.yaw + 0.1 * sin(t * 2), pitch: -0.35, scale: 1 + 0.03 * sin(t * 9), lift: float(t), expr: 'wide'}; }},
|
|
76
|
-
uploading: {pose: (a, t) => { if (a.every(0.28)) a.emit('up'); return {yaw: BASE.yaw, pitch: -0.5, gy: -0.18, sy: 1.05, lift: -2 + float(t), mark: 'up'}; }},
|
|
77
|
-
writing: {pose: (a, t) => { const u = (t * 0.7) % 1; return {yaw: -0.15 + 0.4 * u, pitch: -0.5, gx: 0.18 * (u - 0.5), gy: 0.15, lift: -1.2 * beat(t, 8), expr: 'focus', mark: 'pen'}; }},
|
|
78
|
-
alerting: {enter: a => a.play('startle'), pose: (a, t, l) => { if (a.every(1.3)) a.play('startle'); return {...facing(l, 0.2, -0.3), scale: 1.05, lift: float(t), expr: 'wide', mark: 'bang'}; }},
|
|
79
|
-
bouncing: {enter: a => a.play('jump'), pose: (a, t, l) => { if (a.every(0.85)) a.play('jump'); return {...facing(l), expr: 'happy'}; }},
|
|
80
|
-
'powering-down': {pose: () => ({yaw: 0.3, pitch: 0.1, sy: 0.7, scale: 0.82, lift: 14, expr: 'closed', sat: 0.12, rate: 2, stiff: 40, still: true})},
|
|
81
|
-
|
|
82
|
-
// ---- product moments ----
|
|
83
|
-
humming: {pose: (a, t) => { if (a.every(0.6)) a.emit('note'); return {yaw: BASE.yaw + 0.25 * sin(t * 1.5), roll: 0.14 * sin(t * 3), lift: -2 * beat(t, 3), expr: 'calm', blush: 0.3}; }},
|
|
84
|
-
notifying: {enter: a => a.hop(110), pose: (a, t, l) => { if (a.every(2)) a.hop(110); return {...facing(l), scale: 1.03, lift: float(t), expr: 'wide', mark: 'badge'}; }},
|
|
85
|
-
dragging: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 2.3), pitch: -0.1, roll: 0.25 * sin(t * 3.1), sy: 1.16, lift: -8, expr: 'surprised', stiff: 120})},
|
|
86
|
-
greeting: {enter: a => { a.hop(120); a.play('wave'); }, pose: (a, t, l) => { if (a.every(2.6)) a.play('wave'); return {...facing(l, 0.1, -0.3), lift: float(t), scale: 1.04, expr: 'happy'}; }},
|
|
87
|
-
|
|
88
|
-
// ---- showing it off ----
|
|
89
|
-
logo: {pose: () => ({yaw: 0.5, pitch: -0.32, rate: 6, still: true})},
|
|
90
|
-
showcase: {pose: (a, t, l) => { if (a.every(1.8)) a.play(SHOW[a.beat++ % SHOW.length]); return {...facing(l), lift: float(t)}; }},
|
|
91
|
-
turntable: {pose: (a, t) => ({yaw: t * 1.3, pitch: -0.3, rate: 30})},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// `move(u, g)` adds this gesture's offsets at progress u (0..1) to g.
|
|
95
|
-
export const GESTURES = {
|
|
96
|
-
nod: {zh: '点头', dur: 0.7, move: (u, g) => { g.pitch -= 0.38 * sin(u * TAU * 2) * (1 - u); }},
|
|
97
|
-
shake: {zh: '摇头', dur: 0.75, move: (u, g) => { g.yaw += 0.55 * sin(u * TAU * 2.5) * (1 - u); }},
|
|
98
|
-
tilt: {zh: '歪头', dur: 1.3, move: (u, g) => { g.roll += 0.32 * smooth(Math.min(1, u * 4)) * smooth(Math.min(1, (1 - u) * 4)); }},
|
|
99
|
-
glance: {zh: '张望', dur: 1.6, move: (u, g) => { g.yaw += 0.8 * sin(u * TAU) * Math.sqrt(bump(u)); g.gx += 0.12 * sin(u * TAU); }},
|
|
100
|
-
wink: {zh: '眨眼', dur: 0.6, expr: 'wink', move: (u, g) => { g.roll += 0.12 * bump(u); }},
|
|
101
|
-
wave: {zh: '招手', dur: 1.1, expr: 'happy', move: (u, g) => { g.roll += 0.3 * sin(u * TAU * 3) * Math.sqrt(bump(u)); g.lift -= 4 * bump(u); }},
|
|
102
|
-
bow: {zh: '鞠躬', dur: 1.2, expr: 'closed', move: (u, g) => { g.pitch += 0.75 * bump(u) ** 2; g.sy -= 0.08 * bump(u); }},
|
|
103
|
-
spin: {zh: '转圈', dur: 0.75, move: (u, g) => { g.yaw += TAU * smooth(u); g.sy += 0.1 * bump(u); }},
|
|
104
|
-
flip: {zh: '空翻', dur: 0.85, expr: 'happy', move: (u, g) => { g.pitch -= TAU * smooth(u); g.lift -= 13 * bump(u); }, end: a => a.squash(3)},
|
|
105
|
-
roll: {zh: '侧翻', dur: 0.9, expr: 'happy', move: (u, g) => { g.roll += TAU * smooth(u); g.lift -= 9 * bump(u); }, end: a => a.squash(2)},
|
|
106
|
-
jump: {zh: '跳', dur: 0.8, expr: 'happy', move: (u, g) => { if (u < 0.22) { g.sy -= 0.28 * bump(u / 0.22); return; } const v = (u - 0.22) / 0.78; g.lift -= 72 * v * (1 - v); g.sy += 0.14 * bump(v * 2); }, end: a => a.squash(4)},
|
|
107
|
-
bounce: {zh: '弹一下', dur: 0.5, start: a => { a.hop(170); a.squash(3); }, move: () => {}},
|
|
108
|
-
wobble: {zh: '果冻', dur: 0.9, start: a => a.squash(5), move: (u, g) => { g.roll += 0.16 * sin(u * TAU * 3) * (1 - u); }},
|
|
109
|
-
shiver: {zh: '发抖', dur: 0.9, expr: 'squint', move: (u, g) => { g.roll += 0.05 * sin(u * 60) * bump(u); g.sy -= 0.06 * bump(u); }},
|
|
110
|
-
startle: {zh: '一惊', dur: 0.5, expr: 'surprised', move: (u, g) => { g.lift -= 9 * (1 - u) ** 2; g.scale += 0.14 * (1 - u); }},
|
|
111
|
-
stretch: {zh: '伸懒腰', dur: 1.2, expr: 'closed', move: (u, g) => { g.sy += 0.36 * bump(u) ** 2 - 0.12 * bump(Math.min(1, u * 5)); g.pitch += 0.25 * bump(u); g.roll += 0.08 * sin(u * TAU); }},
|
|
112
|
-
dance: {zh: '跳舞', dur: 2.4, expr: 'happy', move: (u, g) => { const e = Math.sqrt(bump(u)); g.roll += 0.22 * sin(u * TAU * 4) * e; g.lift -= 6 * Math.abs(sin(u * TAU * 4)) * e; g.yaw += 0.5 * sin(u * TAU * 2) * e; }},
|
|
113
|
-
};
|
|
114
|
-
export const FIDGETS = ['tilt', 'glance', 'wink', 'stretch', 'nod'];
|
|
1
|
+
// How every theme acts out each state, and the one-shot gestures. Drawn first for the solids.
|
|
2
|
+
//
|
|
3
|
+
// A pose is `(avatar, t, look) => targets`, returning only what differs from
|
|
4
|
+
// REST. `look` is where the avatar's attention is, each axis about -1..1.
|
|
5
|
+
// Targets: yaw, pitch, roll (radians); sy (vertical stretch); lift (down is
|
|
6
|
+
// positive); scale; gx, gy (eyes sliding on the face); expr; sat; blush;
|
|
7
|
+
// rate and stiff (how fast it gets there); orbit (speed of circling dots);
|
|
8
|
+
// mark (a glyph beside the head); ring ('progress' or 'spin'); bars (sound
|
|
9
|
+
// bars); still (no blinking).
|
|
10
|
+
|
|
11
|
+
import {TAU, smooth, bump} from './core.js';
|
|
12
|
+
|
|
13
|
+
// The resting turn and tilt every pose is built on. A page may change it to try other angles.
|
|
14
|
+
export const BASE = {yaw: 0.3, pitch: -0.26};
|
|
15
|
+
export const REST = {get yaw() { return BASE.yaw; }, get pitch() { return BASE.pitch; }, roll: 0, sy: 1, lift: 0, scale: 1, gx: 0, gy: 0, expr: 'neutral', sat: 1, blush: 0, rate: 9, stiff: 260, orbit: 0, mark: null, ring: null, bars: false, still: false};
|
|
16
|
+
|
|
17
|
+
const sin = Math.sin;
|
|
18
|
+
const beat = (t, f) => Math.abs(sin(t * f));
|
|
19
|
+
const talk = t => Math.abs(sin(t * 4.2) * Math.cos(t * 1.7));
|
|
20
|
+
const float = t => 2 * sin(t * 1.7);
|
|
21
|
+
// Positive yaw turns the face to the viewer's left and negative pitch tilts it up, so a look to the right or down subtracts yaw and adds pitch.
|
|
22
|
+
// The rest pose already tilts up, so looking up gets less travel than looking down.
|
|
23
|
+
const facing = (l, yaw = BASE.yaw, pitch = BASE.pitch) => ({yaw: yaw - l.x * 0.9, pitch: pitch + l.y * (l.y < 0 ? 0.4 : 0.6), gx: l.x * 0.16, gy: l.y * 0.16});
|
|
24
|
+
const SHOW = ['nod', 'spin', 'wink', 'jump', 'wobble', 'tilt', 'flip', 'dance', 'glance', 'stretch'];
|
|
25
|
+
const PLAY = ['wink', 'wobble', 'spin', 'dance'];
|
|
26
|
+
|
|
27
|
+
export const POSES = {
|
|
28
|
+
// ---- the working day ----
|
|
29
|
+
idle: {pose: (a, t, l) => ({...facing(l), lift: float(t)})},
|
|
30
|
+
listening: {enter: a => a.hop(60), pose: (a, t, l) => ({...facing(l, 0, -0.4), scale: 1.06, roll: 0.07 * sin(t * 0.9), lift: 1.5 * sin(t * 2.4), expr: 'wide'})},
|
|
31
|
+
thinking: {pose: (a, t) => ({yaw: 0.75 * sin(t * 1.15), pitch: 0.2 + 0.08 * sin(t * 2.3), roll: 0.1 * sin(t * 0.8), gx: 0.16 * sin(t * 1.15), gy: -0.2, lift: float(t), rate: 6, orbit: 1})},
|
|
32
|
+
streaming: {pose: (a, t) => ({yaw: 0.25 + 0.3 * sin(t * 1.3), sy: 0.8 + 0.42 * talk(t), lift: float(t), rate: 20, stiff: 700, mark: 'dots'})},
|
|
33
|
+
searching: {pose: (a, t) => { if (a.every(1.1)) a.pulse(); return {yaw: 0.9 * sin(t * 1.6), pitch: -0.2 + 0.12 * sin(t * 0.9), gx: 0.14 * sin(t * 1.6), gy: 0.05 * sin(t * 2.7), lift: float(t), expr: 'inspecting', mark: 'search', rate: 7}; }},
|
|
34
|
+
reading: {pose: (a, t) => { const u = (t * 0.9) % 1, line = Math.floor(t * 0.9) % 3; return {yaw: 0.5 * (u - 0.5), pitch: -0.44 + 0.06 * line, gx: 0.2 * (u - 0.5), gy: 0.1 + 0.04 * line, lift: float(t) * 0.5, rate: 10}; }},
|
|
35
|
+
working: {pose: (a, t) => ({yaw: BASE.yaw + 0.14 * sin(t * 2.2), pitch: -0.5, roll: 0.07 * sin(t * 7), lift: -2.5 * beat(t, 7), gx: 0.14 * sin(t * 3.1), gy: 0.12, expr: 'focus'})},
|
|
36
|
+
coding: {pose: (a, t) => ({yaw: BASE.yaw + 0.1 * sin(t * 1.9), pitch: -0.45, lift: -1.8 * beat(t, 9), sy: 1 - 0.04 * beat(t, 9), gx: 0.1 * sin(t * 2.3), gy: 0.12, expr: 'focus', mark: 'code'})},
|
|
37
|
+
running: {pose: (a, t) => { if (a.every(0.26)) a.emit('dust'); return {yaw: 0.55, pitch: -0.2, roll: 0.14 + 0.05 * sin(t * 14), lift: -7 * beat(t, 7), sy: 1 + 0.08 * sin(t * 14), gx: 0.12, expr: 'focus', rate: 12}; }},
|
|
38
|
+
computing: {pose: (a, t) => ({yaw: BASE.yaw + 0.25 * sin(t * 2), pitch: -0.05, roll: 0.05 * sin(t * 3.3), gy: -0.16, gx: 0.1 * sin(t * 4), lift: float(t), expr: 'focus', orbit: 2.3})},
|
|
39
|
+
controlling: {pose: (a, t) => { if (a.every(0.77)) a.nudge(); const k = Math.floor(t * 1.3), x = sin(k * 12.9898) * 0.9, y = sin(k * 78.233) * 0.6; return {yaw: BASE.yaw + x * 0.7, pitch: -0.26 - y * 0.4, gx: x * 0.15, gy: y * 0.12, lift: float(t), expr: 'focus', mark: 'cursor', rate: 14}; }},
|
|
40
|
+
asking: {enter: a => a.play('tilt'), pose: (a, t, l) => { if (a.every(3.2)) a.hop(70); return {...facing(l, 0.1, -0.3), roll: 0.2 * Math.sign(sin(t * 1.1)), lift: float(t), expr: 'wide', mark: 'ask'}; }},
|
|
41
|
+
blocked: {pose: () => ({yaw: 0.3, pitch: -0.22, sy: 0.55, lift: 12, expr: 'closed', sat: 0.25, rate: 5, stiff: 120})},
|
|
42
|
+
finished: {enter: a => { a.play('spin'); a.hop(150); a.burst('spark', 8); }, pose: (a, t) => ({yaw: 0.3, pitch: -0.3, lift: float(t), expr: 'happy'})},
|
|
43
|
+
error: {enter: a => { a.play('shake'); a.express('cross', 1300); }, pose: () => ({yaw: 0.15, pitch: -0.2, roll: 0.12, sy: 0.9, lift: 5, gy: 0.1, expr: 'sad', sat: 0.6})},
|
|
44
|
+
sleeping: {pose: (a, t) => { if (a.every(1.3)) a.emit('z'); return {yaw: 0.35, pitch: -0.42, roll: 0.14, sy: 0.88 + 0.05 * sin(t * 1.2), lift: 8, expr: 'sleep', sat: 0.85, rate: 3, stiff: 60}; }},
|
|
45
|
+
waking: {enter: a => { a.express('sleepy', 1100); a.play('stretch'); }, pose: (a, t, l) => ({...facing(l), lift: float(t), expr: 'wide'})},
|
|
46
|
+
|
|
47
|
+
// ---- moods ----
|
|
48
|
+
happy: {pose: (a, t, l) => ({...facing(l), lift: -3 * beat(t, 3.2), roll: 0.08 * sin(t * 3.2), expr: 'happy', blush: 0.5})},
|
|
49
|
+
excited: {enter: a => a.hop(120), pose: (a, t, l) => { if (a.every(1.6)) a.burst('spark', 4); return {...facing(l, 0.2, -0.32), lift: -7 * beat(t, 6), sy: 1 + 0.07 * sin(t * 12), scale: 1.06, expr: 'sparkle', blush: 0.4}; }},
|
|
50
|
+
laughing: {pose: (a, t) => ({yaw: BASE.yaw, pitch: -0.5, lift: -2.5 * beat(t, 11), sy: 1 + 0.07 * sin(t * 22), roll: 0.06 * sin(t * 5), expr: 'happy', blush: 0.6, stiff: 700, rate: 14})},
|
|
51
|
+
proud: {pose: (a, t) => { if (a.every(2.2)) a.burst('spark', 3); return {yaw: 0.35, pitch: -0.55, sy: 1.07, scale: 1.06, lift: float(t) * 0.5, expr: 'calm', blush: 0.3}; }},
|
|
52
|
+
curious: {pose: (a, t, l) => ({...facing(l, 0.1, -0.3), roll: 0.22 * Math.sign(sin(t * 0.8)), scale: 1.07, lift: float(t), expr: 'inspecting'})},
|
|
53
|
+
playful: {pose: (a, t, l) => { if (a.every(2.4)) a.play(PLAY[a.beat++ % PLAY.length]); return {...facing(l), roll: 0.16 * sin(t * 2.6), lift: -4 * beat(t, 2.6), expr: 'happy'}; }},
|
|
54
|
+
shy: {pose: (a, t) => ({yaw: 0.75, pitch: 0.05, roll: -0.08, scale: 0.94, gx: 0.12, gy: 0.14, lift: 3 + float(t) * 0.4, expr: 'shy', blush: 1, rate: 5})},
|
|
55
|
+
surprised: {enter: a => a.play('startle'), pose: (a, t, l) => ({...facing(l, 0.2, -0.4), scale: 1.08, sy: 1.06, lift: -2, expr: 'surprised'})},
|
|
56
|
+
suspicious: {pose: (a, t) => ({yaw: 0.6, pitch: -0.2, roll: -0.1, gx: -0.16, gy: 0.02 * sin(t), lift: float(t) * 0.5, expr: 'skeptic', rate: 4})},
|
|
57
|
+
angry: {pose: (a, t, l) => { if (a.every(1.5)) a.squash(2); return {...facing(l, 0.15, -0.2), roll: 0.035 * sin(t * 38), sy: 0.94, scale: 1.04, lift: 2, expr: 'angry', mark: 'anger', rate: 12}; }},
|
|
58
|
+
confused: {pose: (a, t) => ({yaw: 0.5 * sin(t * 0.9), pitch: -0.2, roll: 0.2 * sin(t * 0.9 + 1), gx: 0.1 * sin(t * 1.8), lift: float(t), expr: 'confused', mark: 'ask'})},
|
|
59
|
+
sad: {pose: a => { if (a.every(2.4)) a.emit('tear'); return {yaw: 0.15, pitch: 0.12, sy: 0.92, lift: 6, gy: 0.14, roll: -0.06, expr: 'sad', sat: 0.7, rate: 4, stiff: 120}; }},
|
|
60
|
+
drowsy: {pose: (a, t) => { const u = (t * 0.35) % 1, nod = u < 0.8 ? smooth(u / 0.8) : 1 - smooth((u - 0.8) / 0.2); return {yaw: 0.25, pitch: -0.3 + 0.5 * nod, roll: 0.12 * nod, lift: 3 + 4 * nod, expr: 'sleepy', sat: 0.9, rate: 8}; }},
|
|
61
|
+
bored: {pose: (a, t) => { if (a.every(4)) a.squash(1.5); return {yaw: 0.5, pitch: -0.15, roll: 0.2, sy: 0.94 + 0.03 * sin(t * 0.8), lift: 5, gx: 0.15 * sin(t * 0.4), gy: -0.1, expr: 'sleepy', rate: 3, stiff: 80}; }},
|
|
62
|
+
scared: {pose: (a, t) => ({yaw: -0.3, pitch: -0.38, roll: 0.03 * sin(t * 45), sy: 0.9, scale: 0.92, lift: 3, gx: 0.1 * sin(t * 7), gy: -0.05, expr: 'surprised', sat: 0.8, mark: 'sweat', rate: 14})},
|
|
63
|
+
celebrating: {enter: a => { a.play('jump'); a.burst('confetti', 14); }, pose: (a, t) => { if (a.every(1.15)) { a.play(a.beat++ % 2 ? 'jump' : 'spin'); a.burst('confetti', 10); } return {yaw: 0.25, pitch: -0.3, lift: float(t), expr: 'sparkle'}; }},
|
|
64
|
+
approving: {enter: a => a.play('nod'), pose: (a, t, l) => { if (a.every(1.7)) a.play('nod'); return {...facing(l), lift: float(t), expr: 'happy', mark: 'check'}; }},
|
|
65
|
+
loving: {pose: (a, t, l) => { if (a.every(0.9)) a.emit('heart'); return {...facing(l, 0.15, -0.3), roll: 0.1 * sin(t * 2), lift: -2 * beat(t, 2), scale: 1.04, expr: 'love', blush: 0.8}; }},
|
|
66
|
+
|
|
67
|
+
// ---- signals: what is going on, shown with something around the body ----
|
|
68
|
+
orbit: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 1.3), gx: 0.14 * Math.cos(t * 2.6), gy: 0.08 * sin(t * 2.6), lift: float(t), orbit: 1.6})},
|
|
69
|
+
radar: {pose: (a, t) => { if (a.every(0.9)) a.pulse(); return {yaw: 1.0 * sin(t * 1.1), pitch: -0.3, lift: float(t), expr: 'wide', rate: 8}; }},
|
|
70
|
+
progress: {pose: (a, t, l) => ({...facing(l, 0.2, -0.3), lift: float(t) * 0.5, expr: 'focus', ring: 'progress'})},
|
|
71
|
+
loading: {pose: (a, t) => ({yaw: BASE.yaw + 0.15 * sin(t * 2), lift: float(t), gy: -0.08, ring: 'spin'})},
|
|
72
|
+
spawning: {enter: a => { a.p.scale = 0.15; a.vel.scale = 0; for (let i = 0; i < 8; i++) a.emit('in'); }, pose: (a, t) => { if (a.every(0.2) && a.since < 2.4) a.emit('in'); return {scale: Math.min(1, 0.3 + a.since * 0.32), yaw: BASE.yaw + Math.max(0, 2.4 - a.since) * 1.2, lift: float(t), expr: a.since < 1.6 ? 'closed' : 'wide', rate: 12}; }},
|
|
73
|
+
dictating: {pose: (a, t) => ({yaw: BASE.yaw + 0.2 * sin(t * 1.1), sy: 0.92 + 0.2 * talk(t), lift: float(t), expr: 'calm', bars: true, rate: 20, stiff: 700})},
|
|
74
|
+
sending: {pose: (a, t) => { if (a.every(0.2)) a.emit('out'); return {yaw: 0.45, pitch: -0.45, lift: float(t) - 2, gx: 0.1, gy: -0.15, expr: 'focus'}; }},
|
|
75
|
+
receiving: {pose: (a, t) => { if (a.every(0.13)) a.emit('in'); return {yaw: BASE.yaw + 0.1 * sin(t * 2), pitch: -0.35, scale: 1 + 0.03 * sin(t * 9), lift: float(t), expr: 'wide'}; }},
|
|
76
|
+
uploading: {pose: (a, t) => { if (a.every(0.28)) a.emit('up'); return {yaw: BASE.yaw, pitch: -0.5, gy: -0.18, sy: 1.05, lift: -2 + float(t), mark: 'up'}; }},
|
|
77
|
+
writing: {pose: (a, t) => { const u = (t * 0.7) % 1; return {yaw: -0.15 + 0.4 * u, pitch: -0.5, gx: 0.18 * (u - 0.5), gy: 0.15, lift: -1.2 * beat(t, 8), expr: 'focus', mark: 'pen'}; }},
|
|
78
|
+
alerting: {enter: a => a.play('startle'), pose: (a, t, l) => { if (a.every(1.3)) a.play('startle'); return {...facing(l, 0.2, -0.3), scale: 1.05, lift: float(t), expr: 'wide', mark: 'bang'}; }},
|
|
79
|
+
bouncing: {enter: a => a.play('jump'), pose: (a, t, l) => { if (a.every(0.85)) a.play('jump'); return {...facing(l), expr: 'happy'}; }},
|
|
80
|
+
'powering-down': {pose: () => ({yaw: 0.3, pitch: 0.1, sy: 0.7, scale: 0.82, lift: 14, expr: 'closed', sat: 0.12, rate: 2, stiff: 40, still: true})},
|
|
81
|
+
|
|
82
|
+
// ---- product moments ----
|
|
83
|
+
humming: {pose: (a, t) => { if (a.every(0.6)) a.emit('note'); return {yaw: BASE.yaw + 0.25 * sin(t * 1.5), roll: 0.14 * sin(t * 3), lift: -2 * beat(t, 3), expr: 'calm', blush: 0.3}; }},
|
|
84
|
+
notifying: {enter: a => a.hop(110), pose: (a, t, l) => { if (a.every(2)) a.hop(110); return {...facing(l), scale: 1.03, lift: float(t), expr: 'wide', mark: 'badge'}; }},
|
|
85
|
+
dragging: {pose: (a, t) => ({yaw: BASE.yaw + 0.3 * sin(t * 2.3), pitch: -0.1, roll: 0.25 * sin(t * 3.1), sy: 1.16, lift: -8, expr: 'surprised', stiff: 120})},
|
|
86
|
+
greeting: {enter: a => { a.hop(120); a.play('wave'); }, pose: (a, t, l) => { if (a.every(2.6)) a.play('wave'); return {...facing(l, 0.1, -0.3), lift: float(t), scale: 1.04, expr: 'happy'}; }},
|
|
87
|
+
|
|
88
|
+
// ---- showing it off ----
|
|
89
|
+
logo: {pose: () => ({yaw: 0.5, pitch: -0.32, rate: 6, still: true})},
|
|
90
|
+
showcase: {pose: (a, t, l) => { if (a.every(1.8)) a.play(SHOW[a.beat++ % SHOW.length]); return {...facing(l), lift: float(t)}; }},
|
|
91
|
+
turntable: {pose: (a, t) => ({yaw: t * 1.3, pitch: -0.3, rate: 30})},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// `move(u, g)` adds this gesture's offsets at progress u (0..1) to g.
|
|
95
|
+
export const GESTURES = {
|
|
96
|
+
nod: {zh: '点头', dur: 0.7, move: (u, g) => { g.pitch -= 0.38 * sin(u * TAU * 2) * (1 - u); }},
|
|
97
|
+
shake: {zh: '摇头', dur: 0.75, move: (u, g) => { g.yaw += 0.55 * sin(u * TAU * 2.5) * (1 - u); }},
|
|
98
|
+
tilt: {zh: '歪头', dur: 1.3, move: (u, g) => { g.roll += 0.32 * smooth(Math.min(1, u * 4)) * smooth(Math.min(1, (1 - u) * 4)); }},
|
|
99
|
+
glance: {zh: '张望', dur: 1.6, move: (u, g) => { g.yaw += 0.8 * sin(u * TAU) * Math.sqrt(bump(u)); g.gx += 0.12 * sin(u * TAU); }},
|
|
100
|
+
wink: {zh: '眨眼', dur: 0.6, expr: 'wink', move: (u, g) => { g.roll += 0.12 * bump(u); }},
|
|
101
|
+
wave: {zh: '招手', dur: 1.1, expr: 'happy', move: (u, g) => { g.roll += 0.3 * sin(u * TAU * 3) * Math.sqrt(bump(u)); g.lift -= 4 * bump(u); }},
|
|
102
|
+
bow: {zh: '鞠躬', dur: 1.2, expr: 'closed', move: (u, g) => { g.pitch += 0.75 * bump(u) ** 2; g.sy -= 0.08 * bump(u); }},
|
|
103
|
+
spin: {zh: '转圈', dur: 0.75, move: (u, g) => { g.yaw += TAU * smooth(u); g.sy += 0.1 * bump(u); }},
|
|
104
|
+
flip: {zh: '空翻', dur: 0.85, expr: 'happy', move: (u, g) => { g.pitch -= TAU * smooth(u); g.lift -= 13 * bump(u); }, end: a => a.squash(3)},
|
|
105
|
+
roll: {zh: '侧翻', dur: 0.9, expr: 'happy', move: (u, g) => { g.roll += TAU * smooth(u); g.lift -= 9 * bump(u); }, end: a => a.squash(2)},
|
|
106
|
+
jump: {zh: '跳', dur: 0.8, expr: 'happy', move: (u, g) => { if (u < 0.22) { g.sy -= 0.28 * bump(u / 0.22); return; } const v = (u - 0.22) / 0.78; g.lift -= 72 * v * (1 - v); g.sy += 0.14 * bump(v * 2); }, end: a => a.squash(4)},
|
|
107
|
+
bounce: {zh: '弹一下', dur: 0.5, start: a => { a.hop(170); a.squash(3); }, move: () => {}},
|
|
108
|
+
wobble: {zh: '果冻', dur: 0.9, start: a => a.squash(5), move: (u, g) => { g.roll += 0.16 * sin(u * TAU * 3) * (1 - u); }},
|
|
109
|
+
shiver: {zh: '发抖', dur: 0.9, expr: 'squint', move: (u, g) => { g.roll += 0.05 * sin(u * 60) * bump(u); g.sy -= 0.06 * bump(u); }},
|
|
110
|
+
startle: {zh: '一惊', dur: 0.5, expr: 'surprised', move: (u, g) => { g.lift -= 9 * (1 - u) ** 2; g.scale += 0.14 * (1 - u); }},
|
|
111
|
+
stretch: {zh: '伸懒腰', dur: 1.2, expr: 'closed', move: (u, g) => { g.sy += 0.36 * bump(u) ** 2 - 0.12 * bump(Math.min(1, u * 5)); g.pitch += 0.25 * bump(u); g.roll += 0.08 * sin(u * TAU); }},
|
|
112
|
+
dance: {zh: '跳舞', dur: 2.4, expr: 'happy', move: (u, g) => { const e = Math.sqrt(bump(u)); g.roll += 0.22 * sin(u * TAU * 4) * e; g.lift -= 6 * Math.abs(sin(u * TAU * 4)) * e; g.yaw += 0.5 * sin(u * TAU * 2) * e; }},
|
|
113
|
+
};
|
|
114
|
+
export const FIDGETS = ['tilt', 'glance', 'wink', 'stretch', 'nod'];
|
package/core/registry.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
// Themes register here so a product can pick one by name.
|
|
2
|
-
//
|
|
3
|
-
// A theme is {name, zh, create(options), catalog()}. `create` returns an avatar
|
|
4
|
-
// with at least: el, update, setState, play, poke, express, look, gaze, blink,
|
|
5
|
-
// step, restart, suspend, resume, toSVG, dispose.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
// Themes register here so a product can pick one by name.
|
|
2
|
+
//
|
|
3
|
+
// A theme is {name, zh, create(options), catalog()}. `create` returns an avatar
|
|
4
|
+
// with at least: el, update, setState, play, poke, express, look, gaze, blink,
|
|
5
|
+
// step, restart, suspend, resume, toSVG, dispose.
|
|
6
|
+
//
|
|
7
|
+
// Each theme registers itself when its module is imported, so a page only loads
|
|
8
|
+
// the themes it imports. The package entry imports the solids and makes them the
|
|
9
|
+
// default; without a default, the first registered theme is used.
|
|
10
|
+
|
|
11
|
+
const themes = new Map();
|
|
12
|
+
let fallback = null;
|
|
13
|
+
|
|
14
|
+
export function registerTheme(theme) { themes.set(theme.name, theme); return theme; }
|
|
15
|
+
/** Make a registered theme the one used when createAvatar is given no `theme`. */
|
|
16
|
+
export function setDefaultTheme(name) { if (themes.has(name)) fallback = name; return fallback; }
|
|
17
|
+
export const getTheme = name => themes.get(name) || null;
|
|
18
|
+
export const themeNames = () => [...themes.keys()];
|
|
19
|
+
|
|
20
|
+
/** Create an avatar. `theme` picks the theme by name; without it the default theme is used. */
|
|
21
|
+
export function createAvatar({theme, ...options} = {}) {
|
|
22
|
+
if (theme && !themes.has(theme) && typeof console !== 'undefined') console.warn(`BotUI: theme "${theme}" is not loaded; import '@kodax-ai/botui/themes/${theme}' first. Using the default.`);
|
|
23
|
+
const chosen = themes.get(theme) || themes.get(fallback) || themes.values().next().value;
|
|
24
|
+
if (!chosen) throw new Error('BotUI: no theme is registered');
|
|
25
|
+
return chosen.create(options);
|
|
26
|
+
}
|
package/docs/usage.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# BotUI 接入说明
|
|
2
|
+
|
|
3
|
+
给在自己的产品里使用 `@kodax-ai/botui` 的项目看。这份文件随 npm 包发布,在 `node_modules/@kodax-ai/botui/docs/usage.md`。每个主题的完整选项和细节见各自目录的 README(同样在包里:`themes/<主题名>/README.md`)。
|
|
4
|
+
|
|
5
|
+
BotUI 源码公开,但不是开源软件,使用前请先看最后一节“许可和水印”。
|
|
6
|
+
|
|
7
|
+
## 1. 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @kodax-ai/botui
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
零依赖,原生 ES 模块,不需要构建步骤;任何支持 ES 模块的打包工具(Vite、webpack、Rollup、esbuild)都能直接用。TypeScript 类型随包提供。
|
|
14
|
+
|
|
15
|
+
不用 npm 时可以从 CDN 引用,见第 5 节。
|
|
16
|
+
|
|
17
|
+
## 2. 最小例子
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
21
|
+
|
|
22
|
+
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
23
|
+
document.querySelector('#sidebar').append(bot.el);
|
|
24
|
+
|
|
25
|
+
bot.setState('thinking'); // 开始干活
|
|
26
|
+
bot.setState('finished'); // 干完了
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `identity` 是 Bot 的 ID。外形、颜色、眼型都由它稳定决定:同一个 ID 在任何页面、任何时候都是同一个样子,不同的 Bot 自然区分开。不想让它自动决定时,用 `shape`、`color`、`eyes` 指定。
|
|
30
|
+
- `bot.el` 是一个元素,放进页面就开始动;所有头像共用一个帧循环,页面里放几十个也没问题。
|
|
31
|
+
- 不再需要时调用 `bot.dispose()`。
|
|
32
|
+
|
|
33
|
+
## 3. 选主题
|
|
34
|
+
|
|
35
|
+
一共 9 个主题,选项、方法、状态、动作、眼神都一样,换主题不用改其他代码。
|
|
36
|
+
|
|
37
|
+
| 主题 | `theme` | 样子 |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| 立体家族 | `solids` | 带眼睛的立体(默认,36 种外形) |
|
|
40
|
+
| 点阵 | `matrix` | 彩色方块上的 5×5 点阵屏 |
|
|
41
|
+
| 活点 | `dots` | 五颗带弹簧的点,拉长、分裂、合并成表情 |
|
|
42
|
+
| 字符脸 | `kaomoji` | 打出来的字符脸 `o_o` `^_^` |
|
|
43
|
+
| 光标 | `caret` | 一个文本光标,弯成各种字形 |
|
|
44
|
+
| 光晕 | `orb` | 流动的柔光,加立体家族的眼睛 |
|
|
45
|
+
| 液面 | `liquid` | 玻璃杯里的液体,液面就是脸 |
|
|
46
|
+
| 像素生物 | `critter` | 像素画小生物,猫耳 / 熊耳 / 兔耳 / 天线 |
|
|
47
|
+
| 手绘 | `doodle` | 抖动的墨线手绘,带嘴 |
|
|
48
|
+
|
|
49
|
+
颜色和眼型在所有主题里由同一套算法决定,所以同一个 Bot 换主题后还是同一种颜色、同一种眼睛。
|
|
50
|
+
|
|
51
|
+
**只用一个主题**:直接从主题入口引入,最省体积。
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import {createAvatar} from '@kodax-ai/botui/themes/kaomoji';
|
|
55
|
+
const bot = createAvatar({identity: 'research-bot'});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**一个产品里用几个主题,或让用户切换**:总入口只带默认的立体家族,其他主题引入一次即注册,之后用 `theme` 选择。
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
62
|
+
import '@kodax-ai/botui/themes/kaomoji';
|
|
63
|
+
import '@kodax-ai/botui/themes/critter';
|
|
64
|
+
|
|
65
|
+
createAvatar({theme: 'kaomoji', identity: 'a'});
|
|
66
|
+
createAvatar({theme: 'critter', identity: 'b'});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`theme` 写了一个没引入的主题时,会在控制台警告并退回默认主题,不会报错。想改默认主题:`setDefaultTheme('kaomoji')`(该主题必须已引入)。`themeNames()` 列出已注册的主题。
|
|
70
|
+
|
|
71
|
+
## 4. 在框架里用
|
|
72
|
+
|
|
73
|
+
头像是普通的 DOM 元素,框架只需要在挂载时放进去、卸载时 `dispose()`。
|
|
74
|
+
|
|
75
|
+
### React
|
|
76
|
+
|
|
77
|
+
```jsx
|
|
78
|
+
import {useEffect, useRef} from 'react';
|
|
79
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
80
|
+
|
|
81
|
+
export function BotAvatar({identity, state = 'idle', size = 36}) {
|
|
82
|
+
const host = useRef(null), bot = useRef(null);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
bot.current = createAvatar({identity, size, state});
|
|
85
|
+
host.current.append(bot.current.el);
|
|
86
|
+
return () => bot.current.dispose();
|
|
87
|
+
}, [identity, size]);
|
|
88
|
+
useEffect(() => { bot.current?.setState(state); }, [state]);
|
|
89
|
+
return <span ref={host} style={{display: 'inline-block', width: size, height: size}} />;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Vue 3
|
|
94
|
+
|
|
95
|
+
```vue
|
|
96
|
+
<script setup>
|
|
97
|
+
import {onMounted, onBeforeUnmount, ref, watch} from 'vue';
|
|
98
|
+
import {createAvatar} from '@kodax-ai/botui';
|
|
99
|
+
|
|
100
|
+
const props = defineProps({identity: String, state: {type: String, default: 'idle'}, size: {type: Number, default: 36}});
|
|
101
|
+
const host = ref(null);
|
|
102
|
+
let bot;
|
|
103
|
+
onMounted(() => { bot = createAvatar({identity: props.identity, size: props.size, state: props.state}); host.value.append(bot.el); });
|
|
104
|
+
onBeforeUnmount(() => bot?.dispose());
|
|
105
|
+
watch(() => props.state, state => bot?.setState(state));
|
|
106
|
+
watch(() => [props.identity, props.size], ([identity, size]) => bot?.update({identity, size}));
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<template><span ref="host" :style="{display: 'inline-block', width: size + 'px', height: size + 'px'}" /></template>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 自定义元素(任何框架或纯 HTML)
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import '@kodax-ai/botui/element.js';
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
<bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
属性和选项一一对应(`eye-color`、`max-frame-rate` 这类用短横线写法)。布尔属性存在即打开:`static`、`emphasized`、`paused`、`inert`(不响应交互)、`untracked`(不跟随指针)。改属性立即生效,头像对象在 `element.avatar` 上。
|
|
123
|
+
|
|
124
|
+
服务端渲染:模块可以在 Node 里导入(导入时不碰 DOM),但 `createAvatar` 需要浏览器 DOM,请只在客户端创建(React 的 `useEffect`、Vue 的 `onMounted` 里已经是这样)。
|
|
125
|
+
|
|
126
|
+
## 5. 不用构建:CDN
|
|
127
|
+
|
|
128
|
+
```html
|
|
129
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
|
|
130
|
+
<bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
用默认以外的主题时,**先**加载主题脚本,再加载 `element.js`:
|
|
134
|
+
|
|
135
|
+
```html
|
|
136
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/themes/kaomoji/index.js"></script>
|
|
137
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
|
|
138
|
+
<bot-avatar theme="kaomoji" identity="research-bot"></bot-avatar>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 6. 把产品状态映射到头像
|
|
142
|
+
|
|
143
|
+
最常用的是 `setState`。状态是持续的,直到换下一个。55 个状态分五组,完整列表在 `STATES`(每项带中文名 `zh` 和分组 `group`):
|
|
144
|
+
|
|
145
|
+
| 组 | 例子 | 什么时候用 |
|
|
146
|
+
|---|---|---|
|
|
147
|
+
| 工作流程 | `idle` `listening` `thinking` `streaming` `searching` `reading` `working` `coding` `running` `computing` `controlling` `asking` `blocked` `finished` `error` `sleeping` `waking` | 对应 Agent 的运行阶段 |
|
|
148
|
+
| 情绪反应 | `happy` `excited` `proud` `curious` `confused` `sad` `scared` `celebrating` `approving` `loving` 等 18 个 | 对用户操作的反应 |
|
|
149
|
+
| 信号 | `progress` `loading` `spawning` `dictating` `sending` `receiving` `uploading` `writing` `alerting` `powering-down` 等 13 个 | 表示一个具体的过程 |
|
|
150
|
+
| 产品场景 | `humming` `notifying` `dragging` `greeting` | 后台待命、有新消息、被拖动、欢迎 |
|
|
151
|
+
| 展示 | `logo` `showcase` `turntable` | 官网、关于页 |
|
|
152
|
+
|
|
153
|
+
一个聊天 / Agent 产品的典型映射:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
const MAP = {
|
|
157
|
+
queued: 'thinking', planning: 'thinking', toolCall: 'working', browsing: 'searching',
|
|
158
|
+
editingCode: 'coding', answering: 'streaming', needsInput: 'asking', waitingApproval: 'asking',
|
|
159
|
+
rateLimited: 'blocked', done: 'finished', failed: 'error', idleLong: 'sleeping',
|
|
160
|
+
};
|
|
161
|
+
bot.setState(MAP[event.type] ?? 'idle');
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
另外接受几个常见别名:`waiting` → `asking`、`pending` → `thinking`、`done` → `finished`、`failed` → `error`、`celebrate` → `celebrating`、`love` → `loving`。不认识的名字会被忽略,不会报错。
|
|
165
|
+
|
|
166
|
+
其他常用方法(`STATES`、`ALIASES`、`setAttention` 从总入口导入;`GESTURES`、`EXPRESSIONS`、`COLORS` 这些表从主题入口导入,如 `@kodax-ai/botui/themes/solids`):
|
|
167
|
+
|
|
168
|
+
| 方法 | 作用 |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `bot.update({progress: 0.4})` 配合 `setState('progress')` | 显示具体进度(0–1);不给进度时循环播放 |
|
|
171
|
+
| `bot.play('nod')` | 一次性动作(点头、摇头、挥手、跳等 17 个,见 `GESTURES`),叠加在当前状态上 |
|
|
172
|
+
| `bot.express('happy', 1500)` | 临时换一个眼神(21 个,见 `EXPRESSIONS`),毫秒后恢复 |
|
|
173
|
+
| `bot.nudge()` | 轻轻点一下头,适合用户每次按键时调用 |
|
|
174
|
+
| `bot.lookAt(x, y)` / `bot.look({x, y})` | 看向页面上的一点 / 一个方向;传 `null` 交还给指针 |
|
|
175
|
+
| `setAttention({x, y})` | 让页面上所有头像一起看向一点(比如输入框) |
|
|
176
|
+
| `bot.update({...})` | 改任意选项:`size`、`color`、`state`、`emphasized`、`identity`…… |
|
|
177
|
+
| `bot.toSVG()` | 当前帧导出成独立 SVG 字符串,用于 favicon、通知图标、导出 |
|
|
178
|
+
|
|
179
|
+
常用选项:`size`(像素)、`scheme: 'light' | 'dark' | 'auto'`(所在背景,`auto` 跟随系统)、`emphasized`(标记当前正在说话的 Bot)、`label`(无障碍名称,不给时头像是装饰性的)、`static`(只显示静止姿态;系统开启“减少动态效果”时自动如此)、`interactive`、`track`。
|
|
180
|
+
|
|
181
|
+
## 7. 包体积
|
|
182
|
+
|
|
183
|
+
总入口只带默认主题,其他主题按需引入,没引入的主题不会进你的包。下面是各入口实际加载的全部源码(未压缩 / gzip,2026-11-28 的版本):
|
|
184
|
+
|
|
185
|
+
| 引入 | 未压缩 | gzip |
|
|
186
|
+
|---|---|---|
|
|
187
|
+
| `@kodax-ai/botui`(总入口,含立体家族) | 85 kB | 28 kB |
|
|
188
|
+
| `@kodax-ai/botui/themes/matrix` | 69 kB | 23 kB |
|
|
189
|
+
| 其他任一单独主题(dots、kaomoji、caret、orb、liquid、critter、doodle) | 76–83 kB | 25–27 kB |
|
|
190
|
+
| 总入口 + 任一其他主题 | 约 137–145 kB | 约 44–47 kB |
|
|
191
|
+
| 全部 9 个主题 + `element.js` | 211 kB | 63 kB |
|
|
192
|
+
|
|
193
|
+
主题之间共享 `core/` 和点阵引擎,所以多引入一个主题只增加它自己的那一小部分。源码没有压缩,经过打包工具的压缩后还会更小。npm 包本身约 90 kB(解压后约 295 kB),包含全部主题。
|
|
194
|
+
|
|
195
|
+
## 8. 许可和水印
|
|
196
|
+
|
|
197
|
+
BotUI 采用 [KodaX-AI BotUI License 1.0](../LICENSE),源码公开但不是开源软件。要点如下,以 LICENSE 原文为准:
|
|
198
|
+
|
|
199
|
+
- 任何使用都要保留 `LICENSE`、`NOTICE` 和代码、SVG 里的版权信息,并在产品的“关于”、文档或致谢处写明:`Bot avatars by BotUI © icetomoyo / KodaX-AI`。
|
|
200
|
+
- 个人、学习、非商业使用:免费,可以用 `watermark: false`(或属性 `no-watermark`)关掉水印。
|
|
201
|
+
- 商业或组织内使用(公司、学校、机构内部使用也算):免费,但必须保持水印开启、清晰可见、不被遮挡或改动。头像在 48 px 及以上时右下角显示 `KodaX-AI`,更小时不显示,但导出的 SVG 里始终带版权信息。
|
|
202
|
+
- 商用去水印需要与 KodaX-AI 另签书面授权,联系方式见 LICENSE。
|