@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/element.js
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
// present: static, emphasized, paused, inert (no interaction), untracked (do
|
|
8
8
|
// not follow the pointer), no-watermark (see LICENSE for when that is allowed).
|
|
9
9
|
// The avatar itself is at `element.avatar`.
|
|
10
|
+
//
|
|
11
|
+
// The `theme` attribute picks a loaded theme. This file loads only the default
|
|
12
|
+
// (the solids); load any other theme with its own script first:
|
|
13
|
+
// <script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/themes/dots/index.js"></script>
|
|
14
|
+
// <bot-avatar theme="dots" identity="research-bot"></bot-avatar>
|
|
10
15
|
|
|
11
16
|
import {createAvatar} from './index.js';
|
|
12
17
|
|
package/index.d.ts
CHANGED
|
@@ -100,6 +100,8 @@ export interface Theme {
|
|
|
100
100
|
|
|
101
101
|
export function createAvatar(options?: AvatarOptions): Avatar;
|
|
102
102
|
export function registerTheme(theme: Theme): Theme;
|
|
103
|
+
/** Make a registered theme the default for createAvatar without `theme`. Returns the default's name. */
|
|
104
|
+
export function setDefaultTheme(name: string): string | null;
|
|
103
105
|
export function getTheme(name: string): Theme | null;
|
|
104
106
|
export function themeNames(): string[];
|
|
105
107
|
/** Make every avatar look at a client-space point, or pass null to stop. */
|
package/index.js
CHANGED
|
@@ -5,17 +5,19 @@
|
|
|
5
5
|
// sidebar.append(bot.el);
|
|
6
6
|
// bot.setState('thinking');
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
8
|
+
// This entry brings only the default theme, the solids. Every other theme is
|
|
9
|
+
// loaded by importing it, which also registers it here by name:
|
|
10
|
+
//
|
|
11
|
+
// import '@kodax-ai/botui/themes/dots';
|
|
12
|
+
// createAvatar({theme: 'dots', identity: 'research-bot'});
|
|
13
|
+
//
|
|
14
|
+
// So a page only carries the themes it imports, however many there are.
|
|
10
15
|
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {theme as matrix} from './themes/matrix/index.js';
|
|
16
|
+
import {setDefaultTheme} from './core/registry.js';
|
|
17
|
+
import './themes/solids/index.js';
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
registerTheme(solids);
|
|
17
|
-
registerTheme(matrix);
|
|
19
|
+
setDefaultTheme('solids');
|
|
18
20
|
|
|
19
|
-
export {createAvatar, registerTheme, getTheme, themeNames} from './core/registry.js';
|
|
21
|
+
export {createAvatar, registerTheme, setDefaultTheme, getTheme, themeNames} from './core/registry.js';
|
|
20
22
|
export {STATES, STATE_GROUPS, ALIASES, resolveState} from './core/states.js';
|
|
21
23
|
export {setAttention} from './core/core.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kodax-ai/botui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Animated Bot avatars for AI products. One core, one renderer per theme, no dependencies.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -51,12 +51,42 @@
|
|
|
51
51
|
"types": "./themes/matrix/index.d.ts",
|
|
52
52
|
"default": "./themes/matrix/index.js"
|
|
53
53
|
},
|
|
54
|
+
"./themes/dots": {
|
|
55
|
+
"types": "./themes/dots/index.d.ts",
|
|
56
|
+
"default": "./themes/dots/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./themes/kaomoji": {
|
|
59
|
+
"types": "./themes/kaomoji/index.d.ts",
|
|
60
|
+
"default": "./themes/kaomoji/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./themes/caret": {
|
|
63
|
+
"types": "./themes/caret/index.d.ts",
|
|
64
|
+
"default": "./themes/caret/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./themes/orb": {
|
|
67
|
+
"types": "./themes/orb/index.d.ts",
|
|
68
|
+
"default": "./themes/orb/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./themes/liquid": {
|
|
71
|
+
"types": "./themes/liquid/index.d.ts",
|
|
72
|
+
"default": "./themes/liquid/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./themes/critter": {
|
|
75
|
+
"types": "./themes/critter/index.d.ts",
|
|
76
|
+
"default": "./themes/critter/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./themes/doodle": {
|
|
79
|
+
"types": "./themes/doodle/index.d.ts",
|
|
80
|
+
"default": "./themes/doodle/index.js"
|
|
81
|
+
},
|
|
54
82
|
"./core": "./core/core.js",
|
|
55
83
|
"./package.json": "./package.json"
|
|
56
84
|
},
|
|
57
85
|
"sideEffects": [
|
|
58
86
|
"./index.js",
|
|
59
|
-
"./element.js"
|
|
87
|
+
"./element.js",
|
|
88
|
+
"./core/core.js",
|
|
89
|
+
"./themes/*/index.js"
|
|
60
90
|
],
|
|
61
91
|
"files": [
|
|
62
92
|
"index.js",
|
|
@@ -67,6 +97,7 @@
|
|
|
67
97
|
"themes/*/*.d.ts",
|
|
68
98
|
"!themes/*/playground.js",
|
|
69
99
|
"themes/*/README.md",
|
|
100
|
+
"docs/usage.md",
|
|
70
101
|
"LICENSE",
|
|
71
102
|
"NOTICE"
|
|
72
103
|
]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 光标 caret
|
|
2
|
+
|
|
3
|
+
脸是一个文本光标,画在点阵主题的彩色方块上。空闲时像光标一样闪,一格一格跟着指针跳。每种表情都是同一笔弯成的字形(开心 `^`、闭眼 `_`、怀疑 `¬`、完成 ✓),弹簧带着它从一个字形弹到下一个。工作时像终端转圈,或者往右推、身后留下打好的字块。
|
|
4
|
+
|
|
5
|
+
来自 avatar-lab 的草图方向 T(光标),2026-11-28 做成主题。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/caret'; // 或相对路径 ./themes/caret/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/caret'`,再 `createAvatar({theme: 'caret', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="caret" identity="research-bot"></bot-avatar>`。
|
|
18
|
+
|
|
19
|
+
## 与点阵的关系
|
|
20
|
+
|
|
21
|
+
方块、外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形、颜色和眼型。不同的只有脸:
|
|
22
|
+
|
|
23
|
+
| 项 | 光标 |
|
|
24
|
+
|---|---|
|
|
25
|
+
| 眼型 | `dot` 块光标、`bar` 竖线光标、`tall` 细长竖线 |
|
|
26
|
+
| 眼神 | 21 种都是一笔四点的字形:`happy` ^、`squint` >、`sad` ⌒、`skeptic` ¬、`cross` ×、`love` 红色 ♥、`sparkle` 来回转的十字 |
|
|
27
|
+
| 换表情 | 立即开始,四个点各自被弹簧拉过去 |
|
|
28
|
+
| 空闲 | 中性表情时像真光标一样闪(静止帧不闪),视线一格一格地跳 |
|
|
29
|
+
| 信号状态 | 思考像终端转圈(每次转 1/8)、输出往右推并留下字块、进度是填满的字块、完成 ✓、雷达扫线、上下行箭头、书写、感叹号、关机时先一条横线再一个暗点 |
|
|
30
|
+
| 戳一下 | 除了点阵的反应,光标的四个点会被弹乱再弹回来 |
|
|
31
|
+
|
|
32
|
+
## 纯模型
|
|
33
|
+
|
|
34
|
+
`createCaret(options)` 与 `createMatrix` 用法相同,只是脸换成一条折线和几个字块。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
|
|
35
|
+
|
|
36
|
+
## 文件
|
|
37
|
+
|
|
38
|
+
| 文件 | 内容 |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
|
|
41
|
+
| `avatar.js` | `CaretAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
|
|
42
|
+
| `engine.js` | 光标:字形表 `FACES`、屏幕表 `SCREENS`、弹簧 |
|
|
43
|
+
| `playground.html` | 试玩页(共用 `../solids/playground.js`) |
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {MatrixAvatar} from '../matrix/avatar.js';
|
|
2
|
+
import {createCaret} from './engine.js';
|
|
3
|
+
|
|
4
|
+
export {identityFrom} from '../matrix/avatar.js';
|
|
5
|
+
|
|
6
|
+
/** The caret avatar: the matrix avatar with a text cursor for a face. Options and methods as MatrixAvatar's. */
|
|
7
|
+
export class CaretAvatar extends MatrixAvatar {
|
|
8
|
+
static className = 'botui-caret';
|
|
9
|
+
createModel(options) { return createCaret(options); }
|
|
10
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// The caret theme's model: the Bot is a text cursor, on the matrix theme's tile.
|
|
2
|
+
//
|
|
3
|
+
// One thick stroke with round ends. Idle, it blinks the way a cursor does and
|
|
4
|
+
// hops from column to column after the pointer. Every expression bends the same
|
|
5
|
+
// stroke into a glyph (^ for happy, _ when shut, ¬ for skeptic, a check when
|
|
6
|
+
// done), and it springs from one glyph to the next. Working, it spins like a
|
|
7
|
+
// terminal spinner and types: it pushes right and leaves blocks of text behind.
|
|
8
|
+
//
|
|
9
|
+
// Everything else (tile, motion, marks, particles, halo, handling) is the matrix
|
|
10
|
+
// model's; this file only draws the face. Pure, like it: no DOM, no clock, no
|
|
11
|
+
// Math.random, so the same Bot and the same inputs always give the same frames.
|
|
12
|
+
// Sketched in avatar-lab as direction T (光标), made a theme on 2026-11-28.
|
|
13
|
+
|
|
14
|
+
import {Matrix} from '../matrix/engine.js';
|
|
15
|
+
import {TAU, ease, clamp} from '../../core/core.js';
|
|
16
|
+
|
|
17
|
+
const {sin, cos, abs, max, min, floor, round, ceil} = Math;
|
|
18
|
+
const fixed = v => v.toFixed(2);
|
|
19
|
+
const STIFF = 420, DAMP = 26, KEYS = 4, COLUMN = 12;
|
|
20
|
+
const HEART = 'oklch(0.6 0.22 15)';
|
|
21
|
+
|
|
22
|
+
/** The cursor for each of the solids' eye styles: dot (圆点) a block, bar (竖条) a beam, tall (长条) a slim beam. */
|
|
23
|
+
const CURSOR = {dot: {w: 15, h: 13}, bar: {w: 8.5, h: 17}, tall: {w: 6, h: 20}};
|
|
24
|
+
export const caretEyes = Object.freeze(Object.keys(CURSOR));
|
|
25
|
+
|
|
26
|
+
// A glyph is four points the stroke runs through, a width, and `gap` to lift the pen between the 2nd and 3rd.
|
|
27
|
+
const G = (points, w, extra) => ({p: points, w, ...extra});
|
|
28
|
+
const line = (x1, y1, x2, y2, w, extra) => G([[x1, y1], [x1 + (x2 - x1) / 3, y1 + (y2 - y1) / 3], [x1 + (x2 - x1) * 2 / 3, y1 + (y2 - y1) * 2 / 3], [x2, y2]], w, extra);
|
|
29
|
+
const vee = (x1, y1, x2, y2, x3, y3, w, extra) => G([[x1, y1], [x2, y2], [x2, y2], [x3, y3]], w, extra);
|
|
30
|
+
const two = (a, b, w, extra) => G([...a, ...b], w, {gap: true, ...extra});
|
|
31
|
+
const spin = (a, r, w) => line(-r * cos(a), -r * sin(a), r * cos(a), r * sin(a), w);
|
|
32
|
+
|
|
33
|
+
/** The 21 expressions: (cursor size, t) -> glyph, around the centre of the screen. */
|
|
34
|
+
export const FACES = {
|
|
35
|
+
neutral: C => line(0, -C.h, 0, C.h, C.w),
|
|
36
|
+
wide: C => line(0, -C.h * 1.2, 0, C.h * 1.2, max(16, C.w * 1.8)),
|
|
37
|
+
happy: () => vee(-13, 6, 0, -7, 13, 6, 7),
|
|
38
|
+
closed: () => line(-12, 12, 12, 12, 7),
|
|
39
|
+
sleep: () => line(-10, 16, 10, 16, 6, {o: 0.6}),
|
|
40
|
+
squint: () => vee(-9, -11, 8, 0, -9, 11, 7),
|
|
41
|
+
sad: () => G([[-12, 9], [-6, 1], [6, 1], [12, 9]], 7),
|
|
42
|
+
focus: C => line(-4, -C.h, 4, C.h, C.w * 1.15),
|
|
43
|
+
angry: C => line(5, -C.h, -5, C.h, C.w * 1.3),
|
|
44
|
+
calm: () => G([[-12, -1], [-5, 6], [5, 6], [12, -1]], 7),
|
|
45
|
+
sleepy: C => line(0, 2, 0, 14, C.w),
|
|
46
|
+
shy: C => line(0, 7, 0, 14, C.w * 0.8),
|
|
47
|
+
inspecting: C => line(10, -C.h * 1.1, 10, C.h * 1.1, C.w),
|
|
48
|
+
confused: () => G([[-12, 2], [-4, -5], [4, 5], [12, -2]], 7),
|
|
49
|
+
wink: () => line(-9, 0, 9, 0, 7),
|
|
50
|
+
skeptic: () => G([[-12, -5], [6, -5], [12, -5], [12, 7]], 7),
|
|
51
|
+
cross: () => two([[-10, -10], [10, 10]], [[10, -10], [-10, 10]], 7),
|
|
52
|
+
surprised: () => line(0, 0, 0, 0, 24),
|
|
53
|
+
dizzy: (C, t) => spin(t * 9, 12, 7),
|
|
54
|
+
love: () => vee(-8, -5, 0, 5, 8, -5, 11, {fill: HEART}),
|
|
55
|
+
sparkle: (C, t) => { const a = floor(t * 3.5) % 2 ? TAU / 8 : 0; return two([[-12 * cos(a), -12 * sin(a)], [12 * cos(a), 12 * sin(a)]], [[12 * sin(a), -12 * cos(a)], [-12 * sin(a), 12 * cos(a)]], 6); },
|
|
56
|
+
};
|
|
57
|
+
// Glyphs already shut, so a blink leaves them alone.
|
|
58
|
+
const SHUT = new Set(['closed', 'sleep', 'wink', 'happy', 'calm', 'sad', 'skeptic', 'cross', 'confused', 'sparkle', 'love', 'squint', 'dizzy']);
|
|
59
|
+
|
|
60
|
+
// ---- the screen ----
|
|
61
|
+
// What the cursor does instead of a face: (C, t, progress, since) -> {glyph, keys}, or null for the face.
|
|
62
|
+
// `keys` are the blocks it has typed: [{x, w, o}], on a line below the middle.
|
|
63
|
+
const typed = (n, o = 0.5) => Array.from({length: KEYS}, (_, i) => ({x: -27 + i * 15, w: 11, o: i < n ? o : 0}));
|
|
64
|
+
const NONE = typed(0);
|
|
65
|
+
export const SCREENS = {
|
|
66
|
+
// A terminal spinner: the beam turns in eighths.
|
|
67
|
+
thinking: (C, t) => ({glyph: spin(TAU / 4 + floor(t * 7) * TAU / 8, 15, C.w), keys: NONE}),
|
|
68
|
+
// Pushes right, leaving typed blocks behind; then a new line.
|
|
69
|
+
streaming: (C, t) => { const step = floor(t * 6) % 6, n = min(KEYS, step); return {glyph: line(-27 + n * 15, -9, -27 + n * 15, 9, C.w * 0.85), keys: typed(n)}; },
|
|
70
|
+
finished: () => ({glyph: vee(-14, 1, -4, 11, 15, -10, 8), keys: NONE}),
|
|
71
|
+
orbit: (C, t) => ({glyph: spin(t * 6, 13, C.w), keys: NONE}),
|
|
72
|
+
radar: (C, t) => { const a = t * 2.6; return {glyph: line(0, 0, 17 * cos(a), 17 * sin(a), 6), keys: NONE}; },
|
|
73
|
+
progress: (C, t, progress) => { const n = round(clamp(progress ?? (t * 0.22) % 1, 0, 1) * KEYS); return {glyph: line(-27 + n * 15, -9, -27 + n * 15, 9, C.w * 0.85), keys: typed(KEYS, 0.18).map((k, i) => ({...k, o: i < n ? 1 : 0.18}))}; },
|
|
74
|
+
loading: (C, t) => ({glyph: line(0, -C.h, 0, C.h, C.w, {o: floor(t * 6) % 2 ? 1 : 0.15}), keys: NONE}),
|
|
75
|
+
spawning: (C, t, progress, since) => since >= 1 ? null : {glyph: line(0, -C.h * min(1, since * 1.5), 0, C.h * min(1, since * 1.5), C.w), keys: NONE},
|
|
76
|
+
dictating: (C, t) => { const h = 4 + 14 * abs(sin(t * 6) * cos(t * 2.1)); return {glyph: line(0, -h, 0, h, C.w), keys: NONE}; },
|
|
77
|
+
sending: (C, t) => { const u = (t * 1.6) % 1, x = -8 + 16 * u; return {glyph: vee(x - 6, -10, x + 5, 0, x - 6, 10, 7, {o: min(1, 4 * min(u, 1 - u) + 0.2)}), keys: NONE}; },
|
|
78
|
+
receiving: (C, t) => { const u = (t * 1.4) % 1, y = -8 + 16 * u; return {glyph: vee(-10, y - 6, 0, y + 5, 10, y - 6, 7, {o: min(1, 4 * min(u, 1 - u) + 0.2)}), keys: NONE}; },
|
|
79
|
+
uploading: (C, t) => { const u = (t * 1.4) % 1, y = 8 - 16 * u; return {glyph: vee(-10, y + 6, 0, y - 5, 10, y + 6, 7, {o: min(1, 4 * min(u, 1 - u) + 0.2)}), keys: NONE}; },
|
|
80
|
+
writing: (C, t) => { const n = floor(t * 2.5) % (KEYS + 2), k = min(KEYS, n); return {glyph: line(-27 + k * 15, -9, -27 + k * 15, 9, C.w * 0.85, {o: floor(t * 5) % 2 ? 1 : 0.4}), keys: typed(k, 0.8)}; },
|
|
81
|
+
alerting: (C, t) => { const k = 1 + 0.12 * max(0, sin(t * 7)); return {glyph: two([[0, -15 * k], [0, 3 * k]], [[0, 13 * k], [0, 13 * k]], 8 * k), keys: NONE}; },
|
|
82
|
+
bouncing: (C, t) => { const y = 12 - 26 * abs(sin(t * 4)); return {glyph: line(0, y - 4, 0, y + 4, 13), keys: NONE}; },
|
|
83
|
+
// A screen switching off: a line across, then a dim dot.
|
|
84
|
+
'powering-down': (C, t, progress, since) => ({glyph: since < 0.6 ? line(-18, 0, 18, 0, 4) : line(0, 0, 0, 0, 6, {o: 0.45 + 0.25 * sin(t * 1.6)}), keys: NONE}),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
class Caret extends Matrix {
|
|
88
|
+
faceLayout(ink, node) {
|
|
89
|
+
this.pen = {p: Array.from({length: 4}, () => [50, 50]), v: Array.from({length: 4}, () => [0, 0]), w: 8, vw: 0, o: 1};
|
|
90
|
+
this.keys = Array.from({length: KEYS}, () => ({x: 50, w: 0, o: 0}));
|
|
91
|
+
return [
|
|
92
|
+
...this.keys.map(() => node('tile', 'rect', {height: 7, rx: 3.5, fill: ink.dark, opacity: 0})),
|
|
93
|
+
node('tile', 'path', {fill: 'none', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', stroke: ink.dark}),
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
/** As the matrix's, and the cursor jolts. */
|
|
97
|
+
poke(action, options) {
|
|
98
|
+
super.poke(action, options);
|
|
99
|
+
for (const v of this.pen.v) { v[0] += (this.rng() - 0.5) * 300; v[1] += (this.rng() - 0.5) * 300; }
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
/** Where the stroke and the typed blocks are heading. */
|
|
103
|
+
goal(yaw, pitch, facing, still) {
|
|
104
|
+
const C = CURSOR[this.eyes] || CURSOR.bar, k = this.size < 40 ? 1.12 : 1;
|
|
105
|
+
if (!facing) return {glyph: line(0, 0, 0, 0, 0, {o: 0}), keys: NONE, ox: 0, oy: 0, k};
|
|
106
|
+
const screen = !this.forced && SCREENS[this.state]?.(C, this.t, this.progress, this.since);
|
|
107
|
+
if (screen) return {...screen, ox: 0, oy: 0, k};
|
|
108
|
+
// The cursor hops a column at a time after the gaze, and drifts a little up and down.
|
|
109
|
+
const ox = round(clamp(-sin(yaw) * 1.5 + this.gx * 5, -1, 1)) * COLUMN, oy = clamp((pitch * 1.6 + this.gy * 5) * 5, -5, 5);
|
|
110
|
+
let name = this.shown;
|
|
111
|
+
const glyph = (FACES[name] || FACES.neutral)(C, this.t);
|
|
112
|
+
// A blink squeezes the stroke flat. Idle and neutral it also blinks like a cursor, except in a still frame.
|
|
113
|
+
const shut = SHUT.has(name) ? 1 : 0.15 + 0.85 * this.p.open;
|
|
114
|
+
let o = glyph.o ?? 1;
|
|
115
|
+
if (name === 'neutral' && this.state === 'idle' && !this.hover && !still) o *= (this.t % 1.06) < 0.62 ? 1 : 0.14;
|
|
116
|
+
return {glyph: {...glyph, p: glyph.p.map(([x, y]) => [x, y * shut]), o}, keys: NONE, ox, oy, k};
|
|
117
|
+
}
|
|
118
|
+
drawFace(nodes, n, {dt, ink, dim, yaw, pitch, facing}) {
|
|
119
|
+
const {glyph, keys, ox, oy, k} = this.goal(yaw, pitch, facing, dt === null), pen = this.pen;
|
|
120
|
+
const steps = dt === null ? 0 : max(1, ceil(dt / 0.0167 - 1e-6)), h = steps ? dt / steps : 0;
|
|
121
|
+
const to = glyph.p.map(([x, y]) => [50 + ox + x * k, 50 + oy + y * k]);
|
|
122
|
+
if (!steps) { pen.p = to.map(q => [...q]); pen.v = to.map(() => [0, 0]); pen.w = glyph.w * k; pen.vw = 0; pen.o = glyph.o ?? 1; }
|
|
123
|
+
else for (let s = 0; s < steps; s++) {
|
|
124
|
+
pen.p.forEach((q, i) => { for (const a of [0, 1]) { pen.v[i][a] += (-STIFF * (q[a] - to[i][a]) - DAMP * pen.v[i][a]) * h; q[a] += pen.v[i][a] * h; } });
|
|
125
|
+
pen.vw += (-STIFF * (pen.w - glyph.w * k) - DAMP * pen.vw) * h; pen.w += pen.vw * h;
|
|
126
|
+
// A cursor's blink is a hard on and off, not a fade.
|
|
127
|
+
pen.o = ease(pen.o, glyph.o ?? 1, h, 40);
|
|
128
|
+
}
|
|
129
|
+
keys.forEach((key, i) => {
|
|
130
|
+
const mine = this.keys[i];
|
|
131
|
+
if (!steps) Object.assign(mine, {x: key.x, w: key.w, o: key.o});
|
|
132
|
+
else { mine.x = ease(mine.x, key.x, dt, 30); mine.w = ease(mine.w, key.w, dt, 30); mine.o = ease(mine.o, key.o, dt, 18); }
|
|
133
|
+
});
|
|
134
|
+
const fade = 0.35 + 0.65 * dim;
|
|
135
|
+
for (const key of this.keys) Object.assign(nodes[n++], {x: fixed(50 + (key.x - key.w / 2) * k), y: fixed(50 + 13 * k), width: fixed(max(0, key.w * k)), opacity: fixed(clamp(key.o, 0, 1) * fade)});
|
|
136
|
+
const [a, b, c, d] = pen.p.map(([x, y]) => fixed(x) + ',' + fixed(y));
|
|
137
|
+
Object.assign(nodes[n++], {d: glyph.gap ? `M${a}L${b}M${c}L${d}` : `M${a}L${b}L${c}L${d}`, 'stroke-width': fixed(max(0.5, pen.w)), stroke: glyph.fill || ink.dark, opacity: fixed(clamp(pen.o, 0, 1) * fade)});
|
|
138
|
+
return n;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A caret model. Options as createMatrix's: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
|
|
143
|
+
export const createCaret = options => new Caret(options);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Types for '@kodax-ai/botui/themes/caret'.
|
|
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 CaretOptions, MatrixShape as CaretShape} 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 CaretAvatar extends MatrixAvatar {}
|
|
12
|
+
export const CaretAvatar: {new (options?: MatrixOptions): CaretAvatar};
|
|
13
|
+
|
|
14
|
+
export const theme: Theme;
|
|
15
|
+
export function createAvatar(options?: MatrixOptions): CaretAvatar;
|
|
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 text cursor for a face.
|
|
20
|
+
export function createCaret(options: MatrixTone & {identity?: string; shape: MatrixShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
|
|
21
|
+
export const caretShapes: readonly MatrixShape[];
|
|
22
|
+
export const caretEyes: readonly EyeStyle[];
|
|
23
|
+
export const FACES: Record<ExpressionName, Function>;
|
|
24
|
+
export const SCREENS: Record<string, Function>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// BotUI caret theme: a text cursor for a face, on a coloured tile.
|
|
2
|
+
//
|
|
3
|
+
// import {createAvatar} from './themes/caret/index.js';
|
|
4
|
+
// const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
5
|
+
// sidebar.append(bot.el);
|
|
6
|
+
// bot.setState('thinking');
|
|
7
|
+
|
|
8
|
+
import {CaretAvatar} 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 {CaretAvatar, 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 caretShapes} from '../matrix/engine.js';
|
|
22
|
+
export {createCaret, caretEyes, FACES, SCREENS} from './engine.js';
|
|
23
|
+
/** The expressions, by name; here each one is a glyph the cursor bends into (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 CaretAvatar(options); }
|
|
28
|
+
|
|
29
|
+
/** This theme, in the form core/registry.js expects. */
|
|
30
|
+
export const theme = {
|
|
31
|
+
name: 'caret', 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,43 @@
|
|
|
1
|
+
# 像素生物 critter
|
|
2
|
+
|
|
3
|
+
一只像素画小生物:方块像素拼成的身体、两只脚,耳朵就是外形(猫耳、熊耳、兔耳、天线)。脸是点阵主题的 5×5 屏幕,每种眼神和信号都画成身体上的像素。工作时原地踏步,累了或卡住时坐下;猫会抖耳朵,兔子难过时耳朵耷拉,天线在思考时一闪一闪。
|
|
4
|
+
|
|
5
|
+
来自 avatar-lab 的草图方向 J(像素生物),2026-11-28 做成主题。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/critter'; // 或相对路径 ./themes/critter/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/critter'`,再 `createAvatar({theme: 'critter', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="critter" identity="research-bot"></bot-avatar>`。
|
|
18
|
+
|
|
19
|
+
## 与点阵的关系
|
|
20
|
+
|
|
21
|
+
颜色、眼型、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也相同;同一个 Bot ID 在两个主题里是同一种颜色和眼型。不同的是:
|
|
22
|
+
|
|
23
|
+
| 项 | 像素生物 |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `shape` | 耳朵:`cat` 猫耳、`bear` 熊耳、`bunny` 兔耳、`antenna` 天线。由 Bot ID 稳定决定,和点阵的外形是两套 |
|
|
26
|
+
| 脸 | 点阵的 `FACES` 和 `SCREENS` 原样使用,亮的点画成深色像素,不亮的不画 |
|
|
27
|
+
| 坐下 | 睡觉、阻塞、困、无聊、难过、出错、关机时脚收起、身体下沉 |
|
|
28
|
+
| 踏步 | 工作、编码、运行、控制、搜索、发送、接收、上传时两只脚轮流抬起 |
|
|
29
|
+
| 耳朵 | 猫隔几秒抖一下耳朵;兔子在难过、困、出错、害怕时耳朵耷拉;天线的灯在思考、计算、加载、聆听时闪 |
|
|
30
|
+
| 背面 | 转到背面只有身体,没有脸 |
|
|
31
|
+
|
|
32
|
+
## 纯模型
|
|
33
|
+
|
|
34
|
+
`createCritter(options)` 与 `createMatrix` 用法相同,`shape` 换成耳朵的名字。不碰 DOM、不用时钟和 `Math.random`,同样的输入永远得到同样的帧。
|
|
35
|
+
|
|
36
|
+
## 文件
|
|
37
|
+
|
|
38
|
+
| 文件 | 内容 |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
|
|
41
|
+
| `avatar.js` | `CritterAvatar`:继承点阵的 `MatrixAvatar`,换模型和外形表 |
|
|
42
|
+
| `engine.js` | 像素身体、耳朵表、坐下和踏步;脸用点阵的 `lit()` |
|
|
43
|
+
| `playground.html` | 试玩页(共用 `../solids/playground.js`) |
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {MatrixAvatar, identityFrom as tileIdentity} from '../matrix/avatar.js';
|
|
2
|
+
import {createCritter, critterShapes} from './engine.js';
|
|
3
|
+
|
|
4
|
+
/** The look a Bot ID maps to: one of the critters, and the same colour and eye style as in every theme. */
|
|
5
|
+
export const identityFrom = (identity, pool) => tileIdentity(identity, pool, critterShapes);
|
|
6
|
+
|
|
7
|
+
/** The pixel critter avatar: the matrix avatar with a pixel creature for a body. Options and methods as MatrixAvatar's; `shape` is one of critterShapes. */
|
|
8
|
+
export class CritterAvatar extends MatrixAvatar {
|
|
9
|
+
static className = 'botui-critter';
|
|
10
|
+
static shapes = critterShapes;
|
|
11
|
+
createModel(options) { return createCritter(options); }
|
|
12
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The pixel critter theme's model: a little pixel-art creature, with the matrix theme's face.
|
|
2
|
+
//
|
|
3
|
+
// The body is a block of square pixels with ears (cat, bear, bunny, or an
|
|
4
|
+
// antenna: that is the shape) and two feet. The face is the matrix theme's 5x5
|
|
5
|
+
// screen, every expression and every signal, drawn as pixels on the body. It
|
|
6
|
+
// walks in place while it works, sits down when it is tired or stuck, a cat
|
|
7
|
+
// twitches an ear, a bunny's ears flop when it is sad, an antenna blinks while
|
|
8
|
+
// it thinks.
|
|
9
|
+
//
|
|
10
|
+
// Everything else (motion, marks, particles, halo, handling) is the matrix
|
|
11
|
+
// model's. Pure, like it: no DOM, no clock, no Math.random.
|
|
12
|
+
// Sketched in avatar-lab as direction J (像素生物), made a theme on 2026-11-28.
|
|
13
|
+
|
|
14
|
+
import {Matrix} from '../matrix/engine.js';
|
|
15
|
+
import {ease} from '../../core/core.js';
|
|
16
|
+
|
|
17
|
+
const {max, floor} = Math;
|
|
18
|
+
const fixed = v => v.toFixed(2);
|
|
19
|
+
// A 9 x 11 grid: ears in rows 0-2, the body in rows 3-9, feet in row 10; the face's 5x5 sits at columns 2-6, rows 4-8.
|
|
20
|
+
const CELL = 7.6, COLS = 9, X0 = 50 - COLS / 2 * CELL, Y0 = 50 - 5.5 * CELL, FACE = [2, 4], SEAM = 0.35, BLUSH = 'oklch(0.74 0.17 15)';
|
|
21
|
+
|
|
22
|
+
const BODY = [];
|
|
23
|
+
for (let r = 3; r <= 9; r++) for (let c = 0; c < COLS; c++) if (!((r === 3 || r === 9) && (c === 0 || c === COLS - 1))) BODY.push([c, r]);
|
|
24
|
+
|
|
25
|
+
/** The ears: (t, mood) -> pixels [col, row]. */
|
|
26
|
+
const EARS = {
|
|
27
|
+
cat: (t, mood) => { const twitch = !mood.down && t % 4.3 < 0.18; return [[twitch ? 0 : 1, 1], [7, 1], [1, 2], [2, 2], [6, 2], [7, 2]]; },
|
|
28
|
+
bear: () => [[1, 1], [2, 1], [6, 1], [7, 1], [0, 2], [1, 2], [2, 2], [6, 2], [7, 2], [8, 2]],
|
|
29
|
+
bunny: (t, mood) => mood.down ? [[0, 2], [1, 2], [2, 2], [6, 2], [7, 2], [8, 2]] : [[2, 0], [6, 0], [2, 1], [6, 1], [2, 2], [6, 2]],
|
|
30
|
+
antenna: () => [[4, 1], [4, 2]],
|
|
31
|
+
};
|
|
32
|
+
export const critterShapes = Object.freeze(Object.keys(EARS));
|
|
33
|
+
/** The critters, in the same form as the solids' SHAPES. */
|
|
34
|
+
export const SHAPES = [
|
|
35
|
+
{name: 'cat', zh: '猫耳', group: 'critter'},
|
|
36
|
+
{name: 'bear', zh: '熊耳', group: 'critter'},
|
|
37
|
+
{name: 'bunny', zh: '兔耳', group: 'critter'},
|
|
38
|
+
{name: 'antenna', zh: '天线', group: 'critter'},
|
|
39
|
+
];
|
|
40
|
+
export const GROUPS = {critter: '像素生物'};
|
|
41
|
+
|
|
42
|
+
// States it sits down in (feet tucked, a row lower), and states it walks in place.
|
|
43
|
+
const SIT = new Set(['sleeping', 'blocked', 'drowsy', 'bored', 'powering-down', 'sad', 'error']);
|
|
44
|
+
const WALK = new Set(['working', 'running', 'coding', 'controlling', 'sending', 'receiving', 'uploading', 'searching']);
|
|
45
|
+
const DOWN = new Set(['sleeping', 'blocked', 'drowsy', 'sad', 'error', 'powering-down', 'scared']);
|
|
46
|
+
const THINK = new Set(['thinking', 'computing', 'loading', 'orbit', 'radar', 'listening']);
|
|
47
|
+
|
|
48
|
+
// Pixels as one path: each row's runs as rectangles, a little overlap so no seam shows between them.
|
|
49
|
+
function pixels(cells, dy, grow = 0) {
|
|
50
|
+
const rows = new Map();
|
|
51
|
+
for (const [c, r] of cells) { if (!rows.has(r)) rows.set(r, new Set()); rows.get(r).add(c); }
|
|
52
|
+
let d = '';
|
|
53
|
+
for (const [r, set] of rows) {
|
|
54
|
+
const cols = [...set].sort((a, b) => a - b);
|
|
55
|
+
for (let i = 0; i < cols.length;) {
|
|
56
|
+
let j = i; while (j + 1 < cols.length && cols[j + 1] === cols[j] + 1) j++;
|
|
57
|
+
const x = X0 + cols[i] * CELL - grow, y = Y0 + r * CELL + dy - grow, w = (cols[j] - cols[i] + 1) * CELL + 2 * grow, h = CELL + SEAM + 2 * grow;
|
|
58
|
+
d += `M${fixed(x)},${fixed(y)}h${fixed(w)}v${fixed(h)}h${fixed(-w)}Z`;
|
|
59
|
+
i = j + 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return d;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class Critter extends Matrix {
|
|
66
|
+
static shapes = critterShapes;
|
|
67
|
+
tileLayout(ink) {
|
|
68
|
+
this.sit = 0;
|
|
69
|
+
const node = (tag, attrs) => ({layer: 'tile', tag, attrs, parent: null});
|
|
70
|
+
return [node('path', {fill: ink.edge, display: 'none'}), node('path', {fill: ink.body}), node('rect', {width: CELL, height: CELL, fill: ink.bright, display: 'none'})];
|
|
71
|
+
}
|
|
72
|
+
/** Which mood the body is in: {down (ears flop), sit, walk, think}. */
|
|
73
|
+
mood() {
|
|
74
|
+
const state = this.forced ? 'idle' : this.state;
|
|
75
|
+
return {down: DOWN.has(state), sit: SIT.has(state), walk: WALK.has(state), think: THINK.has(state)};
|
|
76
|
+
}
|
|
77
|
+
drawTile(nodes, n, {dt, ink, dim}) {
|
|
78
|
+
const mood = this.mood();
|
|
79
|
+
this.sit = dt === null ? +mood.sit : ease(this.sit, +mood.sit, dt, 8);
|
|
80
|
+
const dy = this.sit * CELL * 0.8;
|
|
81
|
+
// Feet: two pixels each; walking lifts one and then the other; sitting tucks them under.
|
|
82
|
+
let feet = [[1, 10], [2, 10], [6, 10], [7, 10]];
|
|
83
|
+
if (this.sit > 0.5) feet = [];
|
|
84
|
+
else if (mood.walk) feet = floor(this.t * 6) % 2 ? [[1, 10], [2, 10], [6, 9.6], [7, 9.6]] : [[1, 9.6], [2, 9.6], [6, 10], [7, 10]];
|
|
85
|
+
const ears = EARS[this.shape](this.t, mood), body = [...BODY, ...ears, ...feet];
|
|
86
|
+
const [edge, fill, bulb] = [nodes[n++], nodes[n++], nodes[n++]];
|
|
87
|
+
if (ink.edge === 'none') edge.display = 'none';
|
|
88
|
+
else Object.assign(edge, {display: 'inline', d: pixels(body, dy, 0.9), fill: ink.edge});
|
|
89
|
+
Object.assign(fill, {d: pixels(body, dy), fill: ink.body});
|
|
90
|
+
// The antenna's bulb blinks while it thinks.
|
|
91
|
+
if (this.shape !== 'antenna') bulb.display = 'none';
|
|
92
|
+
else {
|
|
93
|
+
const on = mood.think ? floor(this.t * 3) % 2 : 1;
|
|
94
|
+
Object.assign(bulb, {display: 'inline', x: fixed(X0 + 4 * CELL), y: fixed(Y0 + dy), fill: on ? ink.bright : ink.accent, opacity: fixed(0.5 + 0.5 * dim)});
|
|
95
|
+
}
|
|
96
|
+
return n;
|
|
97
|
+
}
|
|
98
|
+
faceLayout(ink, node) {
|
|
99
|
+
return Array.from({length: 25}, () => node('tile', 'rect', {width: fixed(CELL + SEAM), height: fixed(CELL + SEAM), fill: ink.dark, opacity: 0}));
|
|
100
|
+
}
|
|
101
|
+
drawFace(nodes, n, {dt, dim, ink, yaw, pitch, facing}) {
|
|
102
|
+
const {on, blush} = this.lit(yaw, pitch, facing), dy = this.sit * CELL * 0.8;
|
|
103
|
+
for (let i = 0; i < 25; i++) {
|
|
104
|
+
this.level[i] = dt === null ? on[i] : ease(this.level[i], on[i], dt, 26);
|
|
105
|
+
const c = i % 5 + FACE[0], r = floor(i / 5) + FACE[1];
|
|
106
|
+
Object.assign(nodes[n++], {x: fixed(X0 + c * CELL), y: fixed(Y0 + r * CELL + dy), opacity: fixed(max(0, this.level[i]) * dim), fill: blush[i] ? BLUSH : ink.dark});
|
|
107
|
+
}
|
|
108
|
+
return n;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A critter model. Options as createMatrix's, with `shape` one of critterShapes: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
|
|
113
|
+
export const createCritter = options => new Critter(options);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Types for '@kodax-ai/botui/themes/critter'.
|
|
2
|
+
|
|
3
|
+
import type {AvatarOptions, ColorName, EyeStyle, ExpressionName, IdentityPool, Theme} from '../../index.js';
|
|
4
|
+
import type {MatrixAvatar, 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 {setAttention, resolveState, STATES, STATE_GROUPS, ALIASES, COLORS, BIRTH_COLORS, HUES, EYE_STYLES, GESTURES} from '../../index.js';
|
|
8
|
+
|
|
9
|
+
/** Which ears it has. */
|
|
10
|
+
export type CritterShape = 'cat' | 'bear' | 'bunny' | 'antenna';
|
|
11
|
+
/** `shape` is the critter's ears; `signals` and `eyeColor` are ignored, the face shows signals itself. */
|
|
12
|
+
export interface CritterOptions extends Omit<AvatarOptions, 'shape' | 'signals' | 'eyeColor'> { shape?: CritterShape; }
|
|
13
|
+
export interface CritterAvatar extends Omit<MatrixAvatar, 'shape'> { readonly shape: CritterShape; }
|
|
14
|
+
export const CritterAvatar: {new (options?: CritterOptions): CritterAvatar};
|
|
15
|
+
|
|
16
|
+
export const theme: Theme;
|
|
17
|
+
export function createAvatar(options?: CritterOptions): CritterAvatar;
|
|
18
|
+
export function identityFrom(identity: string, pool?: IdentityPool): {shape: CritterShape; color: ColorName; eyes: EyeStyle};
|
|
19
|
+
export const SHAPES: {name: CritterShape; zh: string; group: 'critter'}[];
|
|
20
|
+
export const GROUPS: Record<'critter', string>;
|
|
21
|
+
export const EXPRESSIONS: Record<ExpressionName, Function>;
|
|
22
|
+
|
|
23
|
+
// The pure model: the matrix model with a pixel body and the 5x5 face drawn as pixels.
|
|
24
|
+
export function createCritter(options: MatrixTone & {identity?: string; shape: CritterShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
|
|
25
|
+
export const critterShapes: readonly CritterShape[];
|
|
26
|
+
export const critterEyes: readonly EyeStyle[];
|
|
27
|
+
export const FACES: Record<ExpressionName, Function>;
|
|
28
|
+
export const SCREENS: Record<string, Function>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// BotUI pixel critter theme: a little pixel-art creature with the matrix face.
|
|
2
|
+
//
|
|
3
|
+
// import {createAvatar} from './themes/critter/index.js';
|
|
4
|
+
// const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
5
|
+
// sidebar.append(bot.el);
|
|
6
|
+
// bot.setState('thinking');
|
|
7
|
+
|
|
8
|
+
import {CritterAvatar} 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 '../matrix/engine.js';
|
|
14
|
+
import {SHAPES} from './engine.js';
|
|
15
|
+
|
|
16
|
+
export {CritterAvatar, 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, critterShapes, createCritter} from './engine.js';
|
|
22
|
+
export {FACES, SCREENS, matrixEyes as critterEyes} from '../matrix/engine.js';
|
|
23
|
+
/** The expressions, by name: the matrix theme's 5x5 faces, drawn as pixels (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 CritterAvatar(options); }
|
|
28
|
+
|
|
29
|
+
/** This theme, in the form core/registry.js expects. */
|
|
30
|
+
export const theme = {
|
|
31
|
+
name: 'critter', 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);
|