@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.
Files changed (53) hide show
  1. package/README.md +32 -6
  2. package/core/identity.js +46 -0
  3. package/{themes/solids → core}/motion.js +114 -114
  4. package/core/registry.js +26 -18
  5. package/docs/usage.md +202 -0
  6. package/element.js +5 -0
  7. package/index.d.ts +2 -0
  8. package/index.js +11 -9
  9. package/package.json +33 -2
  10. package/themes/caret/README.md +43 -0
  11. package/themes/caret/avatar.js +10 -0
  12. package/themes/caret/engine.js +143 -0
  13. package/themes/caret/index.d.ts +24 -0
  14. package/themes/caret/index.js +35 -0
  15. package/themes/critter/README.md +43 -0
  16. package/themes/critter/avatar.js +12 -0
  17. package/themes/critter/engine.js +113 -0
  18. package/themes/critter/index.d.ts +28 -0
  19. package/themes/critter/index.js +35 -0
  20. package/themes/doodle/README.md +43 -0
  21. package/themes/doodle/avatar.js +10 -0
  22. package/themes/doodle/engine.js +149 -0
  23. package/themes/doodle/index.d.ts +24 -0
  24. package/themes/doodle/index.js +36 -0
  25. package/themes/dots/README.md +42 -0
  26. package/themes/dots/avatar.js +15 -0
  27. package/themes/dots/engine.js +179 -0
  28. package/themes/dots/index.d.ts +24 -0
  29. package/themes/dots/index.js +35 -0
  30. package/themes/kaomoji/README.md +42 -0
  31. package/themes/kaomoji/avatar.js +10 -0
  32. package/themes/kaomoji/engine.js +110 -0
  33. package/themes/kaomoji/index.d.ts +24 -0
  34. package/themes/kaomoji/index.js +35 -0
  35. package/themes/liquid/README.md +47 -0
  36. package/themes/liquid/avatar.js +10 -0
  37. package/themes/liquid/engine.js +161 -0
  38. package/themes/liquid/index.d.ts +24 -0
  39. package/themes/liquid/index.js +35 -0
  40. package/themes/matrix/README.md +4 -2
  41. package/themes/matrix/avatar.js +24 -19
  42. package/themes/matrix/engine.js +61 -25
  43. package/themes/matrix/index.d.ts +2 -1
  44. package/themes/matrix/index.js +9 -15
  45. package/themes/orb/README.md +44 -0
  46. package/themes/orb/avatar.js +10 -0
  47. package/themes/orb/engine.js +130 -0
  48. package/themes/orb/index.d.ts +24 -0
  49. package/themes/orb/index.js +36 -0
  50. package/themes/solids/README.md +1 -1
  51. package/themes/solids/avatar.js +6 -24
  52. package/themes/solids/face.js +52 -56
  53. package/themes/solids/index.js +34 -28
@@ -0,0 +1,43 @@
1
+ # 手绘 doodle
2
+
3
+ 用墨线手绘的 Bot:轮廓描两遍(一道实线,一道更淡、收笔时越过起点的线),颜色像马克笔一样涂得稍微出了线,右下角几笔排线做阴影。线条会“沸腾”:每秒重画八次,每次抖得不一样,就像手绘动画。眼睛和立体家族同形,每种眼神配一张嘴,害羞时脸上划几道红。
4
+
5
+ 来自 avatar-lab 的草图方向 O(手绘),2026-11-28 做成主题。
6
+
7
+ ## 用法
8
+
9
+ ```js
10
+ import {createAvatar} from '@kodax-ai/botui/themes/doodle'; // 或相对路径 ./themes/doodle/index.js
11
+
12
+ const bot = createAvatar({identity: 'research-bot', size: 36});
13
+ sidebar.append(bot.el);
14
+ bot.setState('thinking');
15
+ ```
16
+
17
+ 从总入口用:先 `import '@kodax-ai/botui/themes/doodle'`,再 `createAvatar({theme: 'doodle', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="doodle" identity="research-bot"></bot-avatar>`。
18
+
19
+ ## 与点阵的关系
20
+
21
+ 外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形、颜色和眼型。不同的是:
22
+
23
+ | 项 | 手绘 |
24
+ |---|---|
25
+ | 身体 | 三种外形都画成抖动的墨线,填色偏移出线 |
26
+ | 眼睛 | 用立体家族的 `eyeShape`:21 种眼神、三种眼型同形,线条一样会抖 |
27
+ | 嘴(`MOUTHS`) | 每种眼神一张:开心上弯、难过下弯、生气锯齿、惊讶一个圈、困一条平线……说话的状态(输出、听写、哼歌、大笑、打招呼)嘴一张一合 |
28
+ | 腮红 | 三道短斜线 |
29
+ | 信号状态 | 屏幕不放图案,靠眼神、嘴和右上角记号表达;进度状态外圈有一道铅笔画的弧 |
30
+ | 沸腾 | 抖动由帧号的哈希决定,每 1/8 秒换一次;静止帧(`static`)不抖 |
31
+
32
+ ## 纯模型
33
+
34
+ `createDoodle(options)` 与 `createMatrix` 用法相同。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
35
+
36
+ ## 文件
37
+
38
+ | 文件 | 内容 |
39
+ |---|---|
40
+ | `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
41
+ | `avatar.js` | `DoodleAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
42
+ | `engine.js` | 手绘:抖动的轮廓、排线、眼睛、嘴表 `MOUTHS`、进度弧 |
43
+ | `playground.html` | 试玩页(共用 `../solids/playground.js`) |
@@ -0,0 +1,10 @@
1
+ import {MatrixAvatar} from '../matrix/avatar.js';
2
+ import {createDoodle} from './engine.js';
3
+
4
+ export {identityFrom} from '../matrix/avatar.js';
5
+
6
+ /** The doodle avatar: the matrix avatar drawn by hand, in boiling ink lines. Options and methods as MatrixAvatar's. */
7
+ export class DoodleAvatar extends MatrixAvatar {
8
+ static className = 'botui-doodle';
9
+ createModel(options) { return createDoodle(options); }
10
+ }
@@ -0,0 +1,149 @@
1
+ // The doodle theme's model: the Bot drawn by hand, in ink, with marker colour.
2
+ //
3
+ // The outline is drawn twice in ink, and the colour is filled in a little off
4
+ // the lines, like a marker. The lines boil: every eighth of a second they are
5
+ // redrawn with a slightly different wobble, the way hand-drawn animation does.
6
+ // The eyes are the solids' eyes, every expression and eye style, drawn in the
7
+ // same wobbly ink, with a mouth for each expression and a scribble of blush.
8
+ //
9
+ // Everything else (outline shapes, motion, marks, particles, halo, handling) is
10
+ // the matrix model's. Pure, like it: no DOM, no clock, no Math.random; the
11
+ // wobble comes from a hash of the frame number.
12
+ // Sketched in avatar-lab as direction O (手绘), made a theme on 2026-11-28.
13
+
14
+ import {Matrix} from '../matrix/engine.js';
15
+ import {eyeShape} from '../solids/face.js';
16
+ import {EYE_STYLES} from '../../core/identity.js';
17
+ import {TAU, clamp} from '../../core/core.js';
18
+
19
+ const {sin, cos, abs, max, floor, pow} = Math;
20
+ const fixed = v => v.toFixed(2);
21
+ const E = 42, R = 36, BOIL = 8, RING = 44, BLUSH = 'oklch(0.68 0.17 15)', HEART = 'oklch(0.6 0.22 15)';
22
+ const noise = n => { const s = sin(n * 12.9898 + 78.233) * 43758.5453; return s - floor(s) - 0.5; };
23
+
24
+ /** The doodle's eyes are the solids': dot (圆点), bar (竖条), tall (长条). */
25
+ export const doodleEyes = Object.freeze(Object.keys(EYE_STYLES));
26
+
27
+ // The outlines as points, so they can wobble: the matrix theme's three shapes.
28
+ const ring = (n, at) => Array.from({length: n}, (_, i) => at(i / n * TAU));
29
+ const OUTLINES = {
30
+ circle: ring(30, a => [50 + R * cos(a), 50 + R * sin(a)]),
31
+ squircle: ring(36, a => { const p = 4.5, r = pow(pow(abs(cos(a)), p) + pow(abs(sin(a)), p), -1 / p) / pow(2, 0.5 - 1 / p) * (R + 2); return [50 + r * cos(a), 50 + r * sin(a)]; }),
32
+ hex: ring(36, a => { const k = floor((a + TAU / 12) / (TAU / 6)), mid = k * TAU / 6, r = (R + 3) * cos(TAU / 12) / cos(a - mid); return [50 + r * cos(a), 50 + r * sin(a)]; }),
33
+ };
34
+
35
+ // A smooth line through points (closed: loops back to the start).
36
+ function smooth(points, closed) {
37
+ const mid = (a, b) => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2], pt = p => fixed(p[0]) + ',' + fixed(p[1]);
38
+ if (!closed) {
39
+ if (points.length < 3) return points.map((p, i) => (i ? 'L' : 'M') + pt(p)).join('');
40
+ let d = 'M' + pt(points[0]);
41
+ for (let i = 1; i < points.length - 1; i++) d += 'Q' + pt(points[i]) + ' ' + pt(mid(points[i], points[i + 1]));
42
+ return d + 'L' + pt(points[points.length - 1]);
43
+ }
44
+ const n = points.length;
45
+ let d = 'M' + pt(mid(points[n - 1], points[0]));
46
+ for (let i = 0; i < n; i++) d += 'Q' + pt(points[i]) + ' ' + pt(mid(points[i], points[(i + 1) % n]));
47
+ return d + 'Z';
48
+ }
49
+ const wobble = (points, amount, seed) => points.map(([x, y], i) => [x + noise(seed + i * 1.7) * amount, y + noise(seed + i * 2.3 + 50) * amount]);
50
+
51
+ /** A mouth for each expression, as lines in the face's units (x right, y down), or null for none. */
52
+ const curve = (w, bend, y = 0.36) => [[-w, y - bend], [0, y + bend], [w, y - bend]];
53
+ const oval = (rx, ry, y = 0.38) => ring(10, a => [rx * cos(a), y + ry * sin(a)]).concat([[rx, y]]);
54
+ export const MOUTHS = {
55
+ neutral: () => [curve(0.08, 0.025)],
56
+ wide: () => [oval(0.05, 0.06)],
57
+ happy: () => [curve(0.15, 0.07)],
58
+ closed: () => [curve(0.07, 0)],
59
+ sleep: () => [oval(0.035, 0.04)],
60
+ squint: () => [curve(0.17, 0.09)],
61
+ sad: () => [curve(0.12, -0.05, 0.4)],
62
+ focus: () => [[[-0.06, 0.37], [0.06, 0.37]]],
63
+ angry: () => [[[-0.12, 0.4], [-0.06, 0.36], [0, 0.4], [0.06, 0.36], [0.12, 0.4]]],
64
+ calm: () => [curve(0.1, 0.04)],
65
+ sleepy: () => [[[-0.07, 0.38], [0.07, 0.37]]],
66
+ shy: () => [curve(0.05, 0.02)],
67
+ inspecting: () => [[[-0.02, 0.37], [0.1, 0.35]]],
68
+ confused: () => [[[-0.1, 0.4], [-0.03, 0.36], [0.03, 0.4], [0.1, 0.36]]],
69
+ wink: () => [[[-0.1, 0.36], [0.02, 0.41], [0.12, 0.33]]],
70
+ skeptic: () => [[[-0.1, 0.39], [0.1, 0.36]]],
71
+ cross: () => [[[-0.1, 0.38], [-0.04, 0.35], [0.02, 0.4], [0.1, 0.37]]],
72
+ surprised: () => [oval(0.06, 0.075)],
73
+ dizzy: () => [[[-0.12, 0.38], [-0.06, 0.34], [0, 0.39], [0.06, 0.34], [0.12, 0.38]]],
74
+ love: () => [curve(0.13, 0.06)],
75
+ sparkle: () => [curve(0.15, 0.08), [[-0.15, 0.29], [0.15, 0.29]]],
76
+ };
77
+ // States it talks in: the mouth opens and closes.
78
+ const TALK = {streaming: 9, dictating: 7, humming: 4, laughing: 11, greeting: 6};
79
+
80
+ class Doodle extends Matrix {
81
+ tileLayout(ink, node) {
82
+ return [
83
+ node('tile', 'path', {fill: ink.body, opacity: 0.92}),
84
+ ...[0, 1, 2].map(() => node('tile', 'path', {fill: 'none', stroke: ink.dark, 'stroke-linecap': 'round', 'stroke-width': 1.4, opacity: 0.45})),
85
+ node('tile', 'path', {fill: 'none', stroke: ink.dark, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'stroke-width': 2.8}),
86
+ node('tile', 'path', {fill: 'none', stroke: ink.dark, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'stroke-width': 1.3, opacity: 0.55}),
87
+ node('tile', 'path', {fill: 'none', 'stroke-linecap': 'round', 'stroke-width': 3}),
88
+ ];
89
+ }
90
+ /** The wobble seed for this frame: the lines are redrawn BOIL times a second. */
91
+ get seed() { return floor(this.t * BOIL) * 97; }
92
+ drawTile(nodes, n, {ink, dim}) {
93
+ const s = this.seed, base = OUTLINES[this.shape] || OUTLINES.circle;
94
+ // Marker colour a little off the lines; three hatch strokes of shade low on the right.
95
+ Object.assign(nodes[n++], {d: smooth(wobble(base.map(([x, y]) => [50 + (x - 50) * 0.95 + 2.2, 50 + (y - 50) * 0.95 + 1.6]), 2.2, s + 7), true), fill: ink.body});
96
+ for (let i = 0; i < 3; i++) {
97
+ const a = 0.35 + i * 0.22, r1 = R - 13, r2 = R - 4, j = noise(s + 300 + i) * 1.6;
98
+ Object.assign(nodes[n++], {d: `M${fixed(50 + r1 * cos(a) + j)},${fixed(50 + r1 * sin(a))}L${fixed(50 + r2 * cos(a - 0.28))},${fixed(50 + r2 * sin(a - 0.28) + j)}`, stroke: ink.dark, opacity: fixed(0.4 * dim)});
99
+ }
100
+ // The outline twice: a firm line, then a lighter one that overshoots where the pen started.
101
+ Object.assign(nodes[n++], {d: smooth(wobble(base, 1.6, s), true), stroke: ink.dark, opacity: fixed(0.5 + 0.5 * dim)});
102
+ const second = wobble(base, 2.6, s + 31), over = [...second, ...second.slice(0, 4)].map(([x, y]) => [50 + (x - 50) * 1.02, 50 + (y - 50) * 1.02]);
103
+ Object.assign(nodes[n++], {d: smooth(over, false), stroke: ink.dark, opacity: fixed(0.55 * dim)});
104
+ // The progress ring: a pencil arc around it.
105
+ const node = nodes[n++], u = this.state === 'progress' ? clamp(this.progress ?? (this.t * 0.22) % 1, 0, 1) : 0;
106
+ if (u <= 0.001) Object.assign(node, {d: '', opacity: 0});
107
+ else {
108
+ const steps = max(2, floor(u * 32)), pts = Array.from({length: steps + 1}, (_, i) => { const a = -TAU / 4 + u * TAU * i / steps; return [50 + RING * cos(a), 50 + RING * sin(a)]; });
109
+ Object.assign(node, {d: smooth(wobble(pts, 1.2, s + 77), false), stroke: ink.accent, opacity: 1});
110
+ }
111
+ return n;
112
+ }
113
+ faceLayout(ink, node) {
114
+ const line = {fill: 'none', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', stroke: ink.dark};
115
+ return [
116
+ ...[-1, 1].map(() => node('tile', 'path', {fill: 'none', stroke: BLUSH, 'stroke-linecap': 'round', 'stroke-width': 1.5, opacity: 0})),
117
+ ...[-1, 1].map(() => node('tile', 'path', line)),
118
+ node('tile', 'path', {...line, 'stroke-width': 2.4}),
119
+ ];
120
+ }
121
+ drawFace(nodes, n, {ink, dim, yaw, pitch, facing}) {
122
+ const p = this.p, s = this.seed, style = EYE_STYLES[this.eyes] || EYE_STYLES.tall, k = this.size < 40 ? 1.15 : 1, fade = 0.35 + 0.65 * dim;
123
+ const ox = clamp((-sin(yaw) * 1.5 + this.gx * 5) * 7, -9, 9), oy = clamp((pitch * 1.6 + this.gy * 5) * 5, -6, 6);
124
+ const draw = (lines, cx, cy, amount, seed) => lines.map((line, i) => smooth(wobble(line.map(([x, y]) => [cx + x * E * k, cy + y * E * k]), amount, seed + i * 13), false)).join('');
125
+ // Blush: three short slashes under each eye.
126
+ for (const side of [-1, 1]) {
127
+ const cx = 50 + side * 22 + ox, cy = 58 + oy, on = facing ? 0.9 * p.blush : 0;
128
+ const d = on > 0.02 ? [0, 1, 2].map(i => `M${fixed(cx - 4 + i * 3.4 + noise(s + side * 9 + i))},${fixed(cy + 2)}l2.4,-4`).join('') : '';
129
+ Object.assign(nodes[n++], {d, opacity: fixed(on)});
130
+ }
131
+ for (const side of [-1, 1]) {
132
+ const node = nodes[n++];
133
+ if (!facing) { Object.assign(node, {d: '', opacity: 0}); continue; }
134
+ const eye = eyeShape(this.shown, side, style, p.open), cx = 50 + side * style.gap * E * k + ox, cy = 45 + oy;
135
+ // A filled eye (love, sparkle) is coloured in.
136
+ const colour = this.shown === 'love' ? HEART : ink.dark;
137
+ Object.assign(node, {d: draw(eye.lines, cx, cy, 0.9, s + side * 40) + (eye.fill ? 'Z' : ''), 'stroke-width': fixed(max(2.2, eye.w * E * k * 0.75)), stroke: colour, fill: eye.fill ? colour : 'none', opacity: fixed(fade)});
138
+ }
139
+ // The mouth: the expression's, or opening and closing while it talks.
140
+ const talk = !this.forced && facing ? TALK[this.state] : 0, mouth = nodes[n++];
141
+ let lines = facing ? (MOUTHS[this.shown] || MOUTHS.neutral)() : [];
142
+ if (talk) { const open = abs(sin(this.t * talk)) * (0.6 + 0.4 * abs(sin(this.t * talk * 0.37))); lines = [oval(0.07, 0.01 + 0.07 * open)]; }
143
+ Object.assign(mouth, {d: lines.length ? draw(lines, 50 + ox, 50 + oy, 0.7, s + 200) : '', opacity: fixed(fade)});
144
+ return n;
145
+ }
146
+ }
147
+
148
+ /** A doodle model. Options as createMatrix's: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
149
+ export const createDoodle = options => new Doodle(options);
@@ -0,0 +1,24 @@
1
+ // Types for '@kodax-ai/botui/themes/doodle'.
2
+
3
+ import type {ColorName, EyeStyle, ExpressionName, IdentityPool, Theme} from '../../index.js';
4
+ import type {MatrixAvatar, MatrixOptions, MatrixShape, MatrixModel, MatrixTone} from '../matrix/index.js';
5
+
6
+ export type {Avatar, AvatarOptions, ColorName, EyeStyle, ExpressionName, GestureName, IdentityPool, StateName, StateAlias, StateGroup, Theme} from '../../index.js';
7
+ export type {MatrixOptions as DoodleOptions, MatrixShape as DoodleShape} from '../matrix/index.js';
8
+ export {setAttention, resolveState, STATES, STATE_GROUPS, ALIASES, COLORS, BIRTH_COLORS, HUES, EYE_STYLES, GESTURES} from '../../index.js';
9
+ export {SHAPES, GROUPS} from '../matrix/index.js';
10
+
11
+ export interface DoodleAvatar extends MatrixAvatar {}
12
+ export const DoodleAvatar: {new (options?: MatrixOptions): DoodleAvatar};
13
+
14
+ export const theme: Theme;
15
+ export function createAvatar(options?: MatrixOptions): DoodleAvatar;
16
+ export function identityFrom(identity: string, pool?: IdentityPool): {shape: MatrixShape; color: ColorName; eyes: EyeStyle};
17
+ export const EXPRESSIONS: Record<ExpressionName, Function>;
18
+
19
+ // The pure model: the matrix model with a hand-drawn body, eyes and mouth in boiling ink lines.
20
+ export function createDoodle(options: MatrixTone & {identity?: string; shape: MatrixShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
21
+ export const doodleShapes: readonly MatrixShape[];
22
+ export const doodleEyes: readonly EyeStyle[];
23
+ export const FACES: Record<ExpressionName, Function>;
24
+ export const MOUTHS: Record<ExpressionName, () => [number, number][][]>;
@@ -0,0 +1,36 @@
1
+ // BotUI doodle theme: the Bot drawn by hand, in ink and marker.
2
+ //
3
+ // import {createAvatar} from './themes/doodle/index.js';
4
+ // const bot = createAvatar({identity: 'research-bot', size: 36});
5
+ // sidebar.append(bot.el);
6
+ // bot.setState('thinking');
7
+
8
+ import {DoodleAvatar} from './avatar.js';
9
+ import {COLORS, EYE_STYLES} from '../../core/identity.js';
10
+ import {STATES} from '../../core/states.js';
11
+ import {registerTheme} from '../../core/registry.js';
12
+ import {GESTURES} from '../../core/motion.js';
13
+ import {EXPRESSIONS as FACES} from '../solids/face.js';
14
+ import {SHAPES} from '../matrix/engine.js';
15
+
16
+ export {DoodleAvatar, identityFrom} from './avatar.js';
17
+ export {COLORS, BIRTH_COLORS, HUES, EYE_STYLES} from '../../core/identity.js';
18
+ export {STATES, STATE_GROUPS, ALIASES, resolveState} from '../../core/states.js';
19
+ export {setAttention} from '../../core/core.js';
20
+ export {GESTURES} from '../../core/motion.js';
21
+ export {SHAPES, GROUPS, matrixShapes as doodleShapes} from '../matrix/engine.js';
22
+ export {createDoodle, doodleEyes, MOUTHS} from './engine.js';
23
+ export {EXPRESSIONS as FACES} from '../solids/face.js';
24
+ /** The expressions, by name: the solids' eyes, drawn by hand, with a mouth each (see FACES and MOUTHS). */
25
+ export const EXPRESSIONS = FACES;
26
+
27
+ /** Create an avatar. Options as MatrixAvatar's. Append `.el` to the page. */
28
+ export function createAvatar(options) { return new DoodleAvatar(options); }
29
+
30
+ /** This theme, in the form core/registry.js expects. */
31
+ export const theme = {
32
+ name: 'doodle', zh: '手绘', create: createAvatar,
33
+ catalog: () => ({shapes: SHAPES, colors: Object.keys(COLORS), eyes: Object.keys(EYE_STYLES), states: Object.keys(STATES), gestures: Object.keys(GESTURES), expressions: Object.keys(FACES)}),
34
+ };
35
+ // Importing a theme makes it available to createAvatar({theme}) from the package entry.
36
+ registerTheme(theme);
@@ -0,0 +1,42 @@
1
+ # 活点 dots
2
+
3
+ 五颗带弹簧的点,画在点阵主题的彩色方块上。每颗点是一个能移动、拉长、旋转的胶囊,被弹簧拉向目标位置,所以每次换表情都是一次物理运动:眼睛拉长成竖条,分裂成对勾,合并成一颗点。用不到的点缩进旁边一颗看得见的点里,之后再从里面分裂出来。
4
+
5
+ 来自 avatar-lab 的草图方向 H(活点),2026-11-28 做成主题。
6
+
7
+ ## 用法
8
+
9
+ ```js
10
+ import {createAvatar} from '@kodax-ai/botui/themes/dots'; // 或相对路径 ./themes/dots/index.js
11
+
12
+ const bot = createAvatar({identity: 'research-bot', size: 36});
13
+ sidebar.append(bot.el);
14
+ bot.setState('thinking');
15
+ ```
16
+
17
+ 从总入口用:先 `import '@kodax-ai/botui/themes/dots'`,再 `createAvatar({theme: 'dots', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="dots" identity="research-bot"></bot-avatar>`。
18
+
19
+ ## 与点阵的关系
20
+
21
+ 方块、外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形、颜色和眼型。不同的只有脸:
22
+
23
+ | 项 | 活点 |
24
+ |---|---|
25
+ | 眼型 | `dot` 圆点、`bar` 竖条、`tall` 长条,是一颗点的三种比例 |
26
+ | 眼神 | 21 种都有,由 1–2 颗点拼成:`happy` 是两笔 ^,`squint` 是 > <,`love` 是两颗红心,`sparkle` 是来回转的十字 |
27
+ | 换表情 | 立即开始变形,不像点阵那样藏在一次眨眼后面 |
28
+ | 信号状态 | 点拼成图案:思考三点弹跳、输出五根音柱、完成对勾、进度条、雷达、上下行箭头、书写、感叹号等 |
29
+ | 戳一下 | 除了点阵的反应,五颗点还会被弹散再弹回来 |
30
+
31
+ ## 纯模型
32
+
33
+ `createDots(options)` 与 `createMatrix` 用法相同,只是脸换成五颗点。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
34
+
35
+ ## 文件
36
+
37
+ | 文件 | 内容 |
38
+ |---|---|
39
+ | `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
40
+ | `avatar.js` | `DotsAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
41
+ | `engine.js` | 五颗点:眼神表 `FACES`、屏幕表 `SCREENS`、弹簧 |
42
+ | `playground.html` | 试玩页(共用 `../solids/playground.js`) |
@@ -0,0 +1,15 @@
1
+ // The live dots theme: five dots on springs, on the matrix theme's coloured tile.
2
+ //
3
+ // Everything but the face is the matrix theme's: options, methods, interaction,
4
+ // watermark, identity. A Bot has the same tile outline, colour and eye style here
5
+ // as in the matrix, and the same colour and eye style as in the solids.
6
+
7
+ import {MatrixAvatar} from '../matrix/avatar.js';
8
+ import {createDots} from './engine.js';
9
+
10
+ export {identityFrom} from '../matrix/avatar.js';
11
+
12
+ export class DotsAvatar extends MatrixAvatar {
13
+ static className = 'botui-dots';
14
+ createModel(options) { return createDots(options); }
15
+ }
@@ -0,0 +1,179 @@
1
+ // The live dots theme's model: five dots on springs, on the matrix theme's tile.
2
+ //
3
+ // The dots left the grid. Each one is a capsule that can move, stretch and turn,
4
+ // and each pulls toward a target on a bouncy spring, so every change of face is a
5
+ // physical move: eyes stretch into bars, split into a tick, merge into one dot.
6
+ // A dot that is not needed shrinks into a visible neighbour and splits out of it
7
+ // again later. Expressions change at once instead of behind a blink: the morph is
8
+ // the point.
9
+ //
10
+ // Everything else (tile, motion, marks, particles, halo, handling) is the matrix
11
+ // model's; this file only draws the face. Pure, like it: no DOM, no clock, no
12
+ // Math.random, so the same Bot and the same inputs always give the same frames.
13
+ // Sketched in avatar-lab as direction H (活点), made a theme on 2026-11-28.
14
+
15
+ import {Matrix} from '../matrix/engine.js';
16
+ import {TAU, ease, clamp} from '../../core/core.js';
17
+
18
+ const {sin, cos, abs, max, min, floor, ceil, round, PI} = Math;
19
+ const fixed = v => v.toFixed(2);
20
+
21
+ // Frame units, as the matrix: the tile is centred on 50,50 with a radius of about 38.
22
+ const BLOBS = 5, EX = 14, EY = 48, FEATURE = 1.55, SCREEN = 1.25, STIFF = 300, DAMP = 21;
23
+ const HEART = 'oklch(0.64 0.22 15)', BLUSH = 'oklch(0.74 0.17 15)';
24
+ /** Eye sizes for the solids' eye styles: dot (圆点), bar (竖条), tall (长条). */
25
+ const EYE = {dot: {w: 8, h: 8}, bar: {w: 7.5, h: 11.5}, tall: {w: 6.5, h: 15}};
26
+ export const dotsEyes = Object.freeze(Object.keys(EYE));
27
+ // A capsule: centre, length along its own x, thickness, turn in degrees, plus {o, fill}.
28
+ const B = (x, y, w, h, a = 0, extra) => ({x, y, w, h, a, o: 1, ...extra});
29
+
30
+ // ---- the face ----
31
+ /**
32
+ * The 21 expressions: (eye size, t, side) -> [main dot, second dot], drawn for the
33
+ * right eye around its centre; the left eye is the mirror image. Eyes use dots 0-3.
34
+ */
35
+ export const FACES = {
36
+ neutral: E => [B(0, 0, E.w, E.h)],
37
+ wide: E => [B(0, -0.5, E.w * 1.2, E.h * 1.3)],
38
+ happy: () => [B(-2.6, 0.6, 8, 3.6, -45), B(2.6, 0.6, 8, 3.6, 45)],
39
+ closed: () => [B(0, 1, 10, 3)],
40
+ sleep: () => [B(0, 3, 9, 2.6)],
41
+ squint: () => [B(0.5, -2, 8, 3.4, -30), B(0.5, 2, 8, 3.4, 30)],
42
+ sad: () => [B(0, 2, 9, 4.2, 22)],
43
+ focus: E => [B(0, 1, E.w * 1.15, max(3.5, E.h * 0.5))],
44
+ angry: E => [B(0, 1.5, E.w, E.h * 0.7), B(-0.5, -E.h / 2 - 3.5, 10, 3.2, -25)],
45
+ calm: () => [B(-2.6, 0, 7, 3.2, 28), B(2.6, 0, 7, 3.2, -28)],
46
+ sleepy: E => [B(0, 2, E.w * 1.1, max(3, E.h * 0.35))],
47
+ shy: E => [B(0, 2.5, E.w * 0.75, E.h * 0.6)],
48
+ inspecting: (E, t, side) => side < 0 ? [B(0, 1, E.w * 1.15, 3.6)] : [B(0, -0.5, E.w * 1.25, E.h * 1.3)],
49
+ confused: (E, t, side) => side < 0 ? [B(0, 0, E.w, E.h)] : [B(0, -1.5, E.w * 0.7, E.w * 0.7), B(0, -E.h / 2 - 4, 8, 3, -15)],
50
+ wink: (E, t, side) => side > 0 ? FACES.happy() : FACES.neutral(E),
51
+ skeptic: (E, t, side) => side > 0 ? [B(0, 1, E.w * 1.15, 3.4), B(0, -6.5, 9, 3, -12)] : FACES.neutral(E),
52
+ cross: () => [B(0, 0, 10, 3.4, 45), B(0, 0, 10, 3.4, -45)],
53
+ surprised: () => [B(0, -0.5, 10, 10)],
54
+ // Two dots chase each other round the eye, the other way round on the other side.
55
+ dizzy: (E, t, side) => { const a = t * 11 * side; return [B(3.2 * cos(a), 3.2 * sin(a), 4.6, 4.6), B(-3.2 * cos(a), -3.2 * sin(a), 3.4, 3.4)]; },
56
+ // A V with fat rounded tops reads as a heart; it beats.
57
+ love: (E, t) => { const k = 1 + 0.12 * abs(sin(t * 4)); return [B(-2.3 * k, 0, 9 * k, 5.8 * k, 45, {fill: HEART}), B(2.3 * k, 0, 9 * k, 5.8 * k, -45, {fill: HEART})]; },
58
+ // A plus that springs round into a cross and back: the turn is the twinkle.
59
+ sparkle: (E, t) => { const turn = floor(t * 3.5) % 2 ? 45 : 0; return [B(0, 0, 11, 3, turn), B(0, 0, 11, 3, turn + 90)]; },
60
+ };
61
+ /** Expressions that also open a mouth, with dot 4, from the face's centre. */
62
+ const MOUTHS = {surprised: B(0, 14, 5.5, 6.5)};
63
+
64
+ // ---- the screen ----
65
+ // What the dots show instead of a face: (t, progress, since) -> targets by dot index, or null for the face.
66
+ // Rows run 0, 2, 4, 3, 1 from left to right, so the eyes (0 and 1) end up at the ends.
67
+ const ROW = [0, 2, 4, 3, 1];
68
+ const row = fn => { const out = []; ROW.forEach((i, k) => { out[i] = fn(k); }); return out; };
69
+ const three = fn => { const out = []; [0, 4, 1].forEach((i, k) => { out[i] = fn(k); }); return out; };
70
+ const cycle = u => ({o: min(1, 0.3 + 4 * min(u, 1 - u))});
71
+ export const SCREENS = {
72
+ thinking: t => three(k => B(38 + k * 12, 52 - 8 * max(0, sin(t * 5.5 - k * 0.85)), 8, 8)),
73
+ streaming: t => row(k => B(33 + k * 8.5, 50, 5.6, 6 + 16 * abs(sin(t * 7 + k * 1.6) * cos(t * 2.2 + k)))),
74
+ // The eyes stretch into a tick.
75
+ finished: () => [B(42, 54, 11.5, 5.6, 45), B(54.5, 49.5, 24.5, 5.6, -45)],
76
+ orbit: t => { const a = t * 4; return [B(50 + 17 * cos(a), 50 + 17 * sin(a), 6.5, 6.5), B(50 - 17 * cos(a), 50 - 17 * sin(a), 6.5, 6.5), null, null, B(50, 50, 8, 8)]; },
77
+ radar: t => {
78
+ const a = (t * 2.4) % TAU, behind = ((a - 5.64) % TAU + TAU) % TAU;
79
+ return [B(50 + 9.5 * cos(a), 50 + 9.5 * sin(a), 19, 3.6, a * 180 / PI), B(62, 41, 5.5, 5.5, 0, {o: max(0.08, 1 - behind / 2.5)}), null, null, B(50, 50, 6, 6)];
80
+ },
81
+ progress: (t, progress) => { const w = 8 + 40 * clamp(progress ?? (t * 0.22) % 1, 0, 1); return [B(26 + w / 2, 50, w, 8), null, B(50, 50, 48, 8, 0, {o: 0.22})]; },
82
+ loading: t => three(k => { const s = 4 + 5 * max(0, sin(t * 6 - k * 0.9)); return B(38 + k * 12, 50, s, s); }),
83
+ // Born as one dot that splits into the face.
84
+ spawning: (t, progress, since) => { if (since >= 0.9) return null; const s = 4 + 8 * min(1, since * 2); return [B(50, 50, s, s)]; },
85
+ dictating: t => row(k => B(33 + k * 8.5, 50, 5.6, 5 + 18 * abs(sin(t * 6 + k * 1.3) * cos(t * 2.1 + k)))),
86
+ sending: t => { const u = (t * 1.4) % 1, x = 53 + 6 * u, y = 47 - 6 * u, f = cycle(u); return [B(x - 4, y, 10, 5, 0, f), B(x, y + 4, 10, 5, 90, f), null, null, B(x - 7, y + 7, 21, 5, -45, f)]; },
87
+ receiving: t => { const u = (t * 1.2) % 1, y = 54 + 8 * u, f = cycle(u); return [B(46.8, y - 3.2, 10, 5, 45, f), B(53.2, y - 3.2, 10, 5, -45, f), null, null, B(50, y - 10, 5, 20, 0, f)]; },
88
+ uploading: t => { const u = (t * 1.2) % 1, y = 46 - 8 * u, f = cycle(u); return [B(46.8, y + 3.2, 10, 5, -45, f), B(53.2, y + 3.2, 10, 5, 45, f), null, null, B(50, y + 10, 5, 20, 0, f)]; },
89
+ writing: t => { const w = 4 + 30 * ((t * 0.5) % 1); return [null, B(33 + w, 56, 3.4, 11, 0, {o: floor(t * 3) % 2 ? 1 : 0.35}), B(30 + w / 2, 56, w, 4.6), B(50, 43, 40, 4.6, 0, {o: 0.55})]; },
90
+ alerting: t => { const k = 1 + 0.15 * max(0, sin(t * 7)); return [B(50, 45, 7 * k, 19 * k), B(50, 63, 7 * k, 7 * k)]; },
91
+ bouncing: t => { const h = abs(sin(t * 4)), low = max(0, 1 - h * 4); return [null, null, B(50, 66, 26, 3.5, 0, {o: 0.5}), null, B(50, 59 - 20 * h, 9 + 3 * low, 9 - 3 * low)]; },
92
+ // The eyes slide together into a line, which shrinks to a dim dot.
93
+ 'powering-down': (t, progress, since) => since < 0.7 ? [B(50, 50, 36, 3)] : [B(50, 50, 5, 5, 0, {o: 0.45 + 0.25 * sin(t * 1.6)})],
94
+ };
95
+ // Where a dot that is not needed hides: in its eye, or in the other one.
96
+ const ANCHOR = [1, 0, 0, 1, 1];
97
+
98
+ class Dots extends Matrix {
99
+ constructor(options) {
100
+ super(options);
101
+ this.morphs = true;
102
+ }
103
+ faceLayout(ink, node) {
104
+ this.blobs = Array.from({length: BLOBS}, () => ({x: 50, y: 50, w: 0, h: 0, a: 0, o: 0, vx: 0, vy: 0, vw: 0, vh: 0, va: 0, fill: null}));
105
+ return [
106
+ ...[-1, 1].map(() => node('tile', 'ellipse', {rx: 4.6, ry: 2.6, fill: BLUSH, opacity: 0})),
107
+ ...Array.from({length: BLOBS}, () => node('tile', 'rect', {fill: ink.dark})),
108
+ ];
109
+ }
110
+ /** As the matrix's, and the dots scatter. */
111
+ poke(action, options) {
112
+ super.poke(action, options);
113
+ for (const b of this.blobs) { b.vx += (this.rng() - 0.5) * 360; b.vy += (this.rng() - 0.5) * 360; }
114
+ return this;
115
+ }
116
+ /** Where each dot is heading this frame. */
117
+ targets(yaw, pitch, facing) {
118
+ const p = this.p, T = new Array(BLOBS).fill(null);
119
+ let face = false, ox = 0, oy = 0;
120
+ if (facing) {
121
+ const screen = !this.forced && SCREENS[this.state]?.(this.t, this.progress, this.since);
122
+ // The screen tables are drawn small and scaled up about the centre.
123
+ if (screen) screen.forEach((q, i) => { if (q && i < BLOBS) T[i] = {...q, x: 50 + (q.x - 50) * SCREEN, y: 50 + (q.y - 50) * SCREEN, w: q.w * SCREEN, h: q.h * SCREEN}; });
124
+ else {
125
+ face = true;
126
+ // Positive yaw turns the face to the viewer's left, negative pitch tilts it up.
127
+ ox = clamp((-sin(yaw) * 1.5 + this.gx * 5) * 7, -8, 8); oy = clamp((pitch * 1.6 + this.gy * 5) * 6, -6, 6);
128
+ // The face tables are drawn small and scaled up, more so on small avatars; a blink squeezes the eyes about their centres.
129
+ const E = EYE[this.eyes] || EYE.bar, k = FEATURE * (this.size < 40 ? 1.1 : 1), shut = 0.12 + 0.88 * p.open;
130
+ const look = FACES[this.shown] || FACES.neutral;
131
+ for (const side of [-1, 1]) look(E, this.t, side).forEach((q, j) => {
132
+ if (!q || j > 1) return;
133
+ const flat = abs(q.a) < 10;
134
+ T[j * 2 + (side < 0 ? 0 : 1)] = {...q, x: 50 + side * (EX + q.x * k) + ox, y: EY + oy + q.y * k * shut, w: q.w * k, h: flat ? max(2.2, q.h * k * shut) : q.h * k, a: side > 0 ? q.a : -q.a};
135
+ });
136
+ const mouth = MOUTHS[this.shown];
137
+ if (mouth) T[4] = {...mouth, x: 50 + ox + mouth.x, y: 50 + oy + mouth.y * k, w: mouth.w * k, h: mouth.h * k};
138
+ }
139
+ }
140
+ const shown = T.slice();
141
+ T.forEach((target, i) => {
142
+ if (target) return;
143
+ const home = shown[ANCHOR[i]] || shown[0] || shown[1] || shown[4];
144
+ T[i] = home ? {x: home.x, y: home.y, w: 3, h: 3, a: home.a, o: 0} : {x: 50, y: 50, w: 3, h: 3, a: 0, o: 0};
145
+ });
146
+ return {T, face, ox, oy};
147
+ }
148
+ drawFace(nodes, n, {dt, ink, dim, yaw, pitch, facing}) {
149
+ const {T, face, ox, oy} = this.targets(yaw, pitch, facing);
150
+ const steps = dt === null ? 0 : max(1, ceil(dt / 0.0167 - 1e-6)), h = steps ? dt / steps : 0;
151
+ this.blobs.forEach((b, i) => {
152
+ const t = T[i];
153
+ // A capsule looks the same half a turn round, so it always takes the shorter way.
154
+ b.a -= 180 * round(b.a / 180);
155
+ let ta = t.a - b.a; ta = b.a + ta - 180 * round(ta / 180);
156
+ if (!steps) Object.assign(b, {x: t.x, y: t.y, w: t.w, h: t.h, a: ta, o: t.o, vx: 0, vy: 0, vw: 0, vh: 0, va: 0});
157
+ else for (let s = 0; s < steps; s++) {
158
+ b.vx += (-STIFF * (b.x - t.x) - DAMP * b.vx) * h; b.x += b.vx * h;
159
+ b.vy += (-STIFF * (b.y - t.y) - DAMP * b.vy) * h; b.y += b.vy * h;
160
+ b.vw += (-STIFF * (b.w - t.w) - DAMP * b.vw) * h; b.w += b.vw * h;
161
+ b.vh += (-STIFF * (b.h - t.h) - DAMP * b.vh) * h; b.h += b.vh * h;
162
+ b.va += (-STIFF * (b.a - ta) - DAMP * b.va) * h; b.a += b.va * h;
163
+ b.o = ease(b.o, t.o, h, 14);
164
+ }
165
+ b.fill = t.fill || null;
166
+ });
167
+ const fade = 0.35 + 0.65 * dim, blush = face ? 0.8 * this.p.blush : 0;
168
+ for (const side of [-1, 1]) Object.assign(nodes[n++], {cx: fixed(50 + side * 21 + ox), cy: fixed(60 + oy), opacity: fixed(blush)});
169
+ for (const b of this.blobs) {
170
+ const w = max(0.5, b.w), hh = max(0.5, b.h);
171
+ Object.assign(nodes[n++], {x: fixed(b.x - w / 2), y: fixed(b.y - hh / 2), width: fixed(w), height: fixed(hh), rx: fixed(min(w, hh) / 2),
172
+ transform: `rotate(${fixed(b.a)} ${fixed(b.x)} ${fixed(b.y)})`, opacity: fixed(clamp(b.o, 0, 1) * fade), fill: b.fill || ink.dark});
173
+ }
174
+ return n;
175
+ }
176
+ }
177
+
178
+ /** A live dots model. Options as createMatrix's: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
179
+ export const createDots = options => new Dots(options);
@@ -0,0 +1,24 @@
1
+ // Types for '@kodax-ai/botui/themes/dots'.
2
+
3
+ import type {ColorName, EyeStyle, ExpressionName, IdentityPool, Theme} from '../../index.js';
4
+ import type {MatrixAvatar, MatrixOptions, MatrixShape, MatrixModel, MatrixTone} from '../matrix/index.js';
5
+
6
+ export type {Avatar, AvatarOptions, ColorName, EyeStyle, ExpressionName, GestureName, IdentityPool, StateName, StateAlias, StateGroup, Theme} from '../../index.js';
7
+ export type {MatrixOptions as DotsOptions, MatrixShape as DotsShape} from '../matrix/index.js';
8
+ export {setAttention, resolveState, STATES, STATE_GROUPS, ALIASES, COLORS, BIRTH_COLORS, HUES, EYE_STYLES, GESTURES} from '../../index.js';
9
+ export {SHAPES, GROUPS} from '../matrix/index.js';
10
+
11
+ export interface DotsAvatar extends MatrixAvatar {}
12
+ export const DotsAvatar: {new (options?: MatrixOptions): DotsAvatar};
13
+
14
+ export const theme: Theme;
15
+ export function createAvatar(options?: MatrixOptions): DotsAvatar;
16
+ export function identityFrom(identity: string, pool?: IdentityPool): {shape: MatrixShape; color: ColorName; eyes: EyeStyle};
17
+ export const EXPRESSIONS: Record<ExpressionName, Function>;
18
+
19
+ // The pure model: the matrix model with a face of five spring dots.
20
+ export function createDots(options: MatrixTone & {identity?: string; shape: MatrixShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
21
+ export const dotsShapes: readonly MatrixShape[];
22
+ export const dotsEyes: readonly EyeStyle[];
23
+ export const FACES: Record<ExpressionName, Function>;
24
+ export const SCREENS: Record<string, Function>;
@@ -0,0 +1,35 @@
1
+ // BotUI live dots theme: five dots on springs that stretch, split and merge into each face.
2
+ //
3
+ // import {createAvatar} from './themes/dots/index.js';
4
+ // const bot = createAvatar({identity: 'research-bot', size: 36});
5
+ // sidebar.append(bot.el);
6
+ // bot.setState('thinking');
7
+
8
+ import {DotsAvatar} from './avatar.js';
9
+ import {COLORS, EYE_STYLES} from '../../core/identity.js';
10
+ import {STATES} from '../../core/states.js';
11
+ import {registerTheme} from '../../core/registry.js';
12
+ import {GESTURES} from '../../core/motion.js';
13
+ import {FACES} from './engine.js';
14
+ import {SHAPES} from '../matrix/engine.js';
15
+
16
+ export {DotsAvatar, identityFrom} from './avatar.js';
17
+ export {COLORS, BIRTH_COLORS, HUES, EYE_STYLES} from '../../core/identity.js';
18
+ export {STATES, STATE_GROUPS, ALIASES, resolveState} from '../../core/states.js';
19
+ export {setAttention} from '../../core/core.js';
20
+ export {GESTURES} from '../../core/motion.js';
21
+ export {SHAPES, GROUPS, matrixShapes as dotsShapes} from '../matrix/engine.js';
22
+ export {createDots, dotsEyes, FACES, SCREENS} from './engine.js';
23
+ /** The expressions, by name; here each one is a pose of the five dots (see FACES). */
24
+ export const EXPRESSIONS = FACES;
25
+
26
+ /** Create an avatar. Options as MatrixAvatar's. Append `.el` to the page. */
27
+ export function createAvatar(options) { return new DotsAvatar(options); }
28
+
29
+ /** This theme, in the form core/registry.js expects. */
30
+ export const theme = {
31
+ name: 'dots', zh: '活点', create: createAvatar,
32
+ catalog: () => ({shapes: SHAPES, colors: Object.keys(COLORS), eyes: Object.keys(EYE_STYLES), states: Object.keys(STATES), gestures: Object.keys(GESTURES), expressions: Object.keys(FACES)}),
33
+ };
34
+ // Importing a theme makes it available to createAvatar({theme}) from the package entry.
35
+ registerTheme(theme);
@@ -0,0 +1,42 @@
1
+ # 字符脸 kaomoji
2
+
3
+ 脸是打出来的几个字符,画在点阵主题的彩色方块上:`o_o`、`^_^`、`>_<`。聊天 Bot 的脸和它的回复是同一种媒介。换表情藏在一次眨眼后面:一行字合上,换字,再睁开。信号状态也是字符:滚动的省略号、百分比、往前推的箭头。
4
+
5
+ 来自 avatar-lab 的草图方向 K(字符脸),2026-11-28 做成主题。
6
+
7
+ ## 用法
8
+
9
+ ```js
10
+ import {createAvatar} from '@kodax-ai/botui/themes/kaomoji'; // 或相对路径 ./themes/kaomoji/index.js
11
+
12
+ const bot = createAvatar({identity: 'research-bot', size: 36});
13
+ sidebar.append(bot.el);
14
+ bot.setState('thinking');
15
+ ```
16
+
17
+ 从总入口用:先 `import '@kodax-ai/botui/themes/kaomoji'`,再 `createAvatar({theme: 'kaomoji', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="kaomoji" identity="research-bot"></bot-avatar>`。
18
+
19
+ ## 与点阵的关系
20
+
21
+ 方块、外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形、颜色和眼型。不同的只有脸:
22
+
23
+ | 项 | 字符脸 |
24
+ |---|---|
25
+ | 眼型 | `dot` 是 `•_•`,`bar` 是 `o_o`,`tall` 是 `0_0` |
26
+ | 眼神 | 21 种都有:`happy` `^_^`、`sad` `;_;`、`angry` `ÒдÓ`、`skeptic` `¬_¬`、`love` 红色 `♥_♥`、`dizzy` 在 `@_@` 和 `6_9` 之间跳 |
27
+ | 换表情 | 藏在一次眨眼后面,和点阵一样 |
28
+ | 信号状态 | 思考 `•••` 滚动、输出时嘴一张一合、进度 `60%`、加载 `·o·`、发送 `>>>`、接收 `<<<`、上传 `^^^` 上浮、书写 `abc_`、提醒 `(!)` |
29
+ | 字体 | 系统等宽字体(`ui-monospace`、Cascadia Mono、SF Mono、Menlo、Consolas),不加载网络字体;不同系统字形略有差别 |
30
+
31
+ ## 纯模型
32
+
33
+ `createKaomoji(options)` 与 `createMatrix` 用法相同,只是脸换成一个 `text` 节点(`text` 属性即文本内容)。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
34
+
35
+ ## 文件
36
+
37
+ | 文件 | 内容 |
38
+ |---|---|
39
+ | `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
40
+ | `avatar.js` | `KaomojiAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
41
+ | `engine.js` | 字符脸:眼神表 `FACES`、屏幕表 `SCREENS` |
42
+ | `playground.html` | 试玩页(共用 `../solids/playground.js`) |
@@ -0,0 +1,10 @@
1
+ import {MatrixAvatar} from '../matrix/avatar.js';
2
+ import {createKaomoji} from './engine.js';
3
+
4
+ export {identityFrom} from '../matrix/avatar.js';
5
+
6
+ /** The typed face avatar: the matrix avatar with a face of text. Options and methods as MatrixAvatar's. */
7
+ export class KaomojiAvatar extends MatrixAvatar {
8
+ static className = 'botui-kaomoji';
9
+ createModel(options) { return createKaomoji(options); }
10
+ }