@kodax-ai/botui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +113 -3
- package/core/core.js +58 -0
- package/core/registry.js +18 -0
- package/core/states.js +36 -0
- package/element.js +39 -0
- package/index.d.ts +122 -0
- package/index.js +17 -0
- package/package.json +66 -4
- package/themes/solids/README.md +101 -0
- package/themes/solids/avatar.js +579 -0
- package/themes/solids/face.js +56 -0
- package/themes/solids/geometry.js +206 -0
- package/themes/solids/index.js +28 -0
- package/themes/solids/motion.js +110 -0
- package/themes/solids/symbols.js +37 -0
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kodax-ai/botui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Animated Bot avatars for AI products. One core, one renderer per theme, no dependencies.",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"author": "icetomoyo",
|
|
8
|
+
"homepage": "https://github.com/icetomoyo/BotUI#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/icetomoyo/BotUI.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/icetomoyo/BotUI/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"avatar",
|
|
18
|
+
"bot",
|
|
19
|
+
"ai",
|
|
20
|
+
"agent",
|
|
21
|
+
"chatbot",
|
|
22
|
+
"svg",
|
|
23
|
+
"animation",
|
|
24
|
+
"web-component",
|
|
25
|
+
"kodax"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"check": "node scripts/check.mjs",
|
|
33
|
+
"pack:local": "node scripts/release.mjs --pack-only",
|
|
34
|
+
"release:dry": "node scripts/release.mjs --dry-run",
|
|
35
|
+
"release": "node scripts/release.mjs"
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"main": "./index.js",
|
|
39
|
+
"types": "./index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./index.d.ts",
|
|
43
|
+
"default": "./index.js"
|
|
44
|
+
},
|
|
45
|
+
"./element": "./element.js",
|
|
46
|
+
"./themes/solids": {
|
|
47
|
+
"types": "./index.d.ts",
|
|
48
|
+
"default": "./themes/solids/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./core": "./core/core.js",
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"sideEffects": [
|
|
54
|
+
"./index.js",
|
|
55
|
+
"./element.js"
|
|
56
|
+
],
|
|
57
|
+
"files": [
|
|
58
|
+
"index.js",
|
|
59
|
+
"index.d.ts",
|
|
60
|
+
"element.js",
|
|
61
|
+
"core",
|
|
62
|
+
"themes/*/*.js",
|
|
63
|
+
"!themes/*/playground.js",
|
|
64
|
+
"themes/*/README.md",
|
|
65
|
+
"LICENSE",
|
|
66
|
+
"NOTICE"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# 立体家族 solids
|
|
2
|
+
|
|
3
|
+
带眼睛的立体。BotUI 的推荐系列。一个 Bot 的形象 = 立体 × 颜色 × 眼型,由 Bot ID 稳定决定,也可以逐项指定。
|
|
4
|
+
|
|
5
|
+
零依赖、原生 ES 模块、不需要构建。每个形象是一个 `<span>` 里的一张 SVG。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/solids'; // 或相对路径 ./themes/solids/index.js
|
|
11
|
+
|
|
12
|
+
const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
13
|
+
sidebar.append(bot.el);
|
|
14
|
+
bot.setState('thinking');
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
不写 JS 也可以用自定义元素:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
|
|
21
|
+
<bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
元素的属性与下面的选项同名(驼峰改成短横线:`eye-color`、`max-frame-rate`)。布尔属性出现即为开:`static`、`emphasized`、`paused`、`inert`(不响应交互)、`untracked`(不跟随指针)、`no-watermark`(关掉水印,仅限许可证允许的情况)。形象对象在 `element.avatar`。
|
|
25
|
+
|
|
26
|
+
## 选项
|
|
27
|
+
|
|
28
|
+
| 选项 | 默认 | 说明 |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `identity` | `'bot'` | Bot ID。没指定的立体、颜色、眼型都由它决定,同一个 ID 永远是同一个样子 |
|
|
31
|
+
| `pool` | 全部 | 限定 ID 能分到的范围:`{shapes, colors, eyes}`,各为名字数组 |
|
|
32
|
+
| `size` | `36` | 宽高,CSS 像素。40 以下眼睛自动放大 |
|
|
33
|
+
| `shape` | 由 ID | `SHAPES` 里的名字,共 36 个 |
|
|
34
|
+
| `color` | 由 ID | `COLORS` 里的名字,共 16 个。后 4 个中性色(brown、gray、black、white)不会被 ID 自动分到 |
|
|
35
|
+
| `hue` | – | 不用命名颜色时,直接给 OKLCH 色相 0–360 |
|
|
36
|
+
| `eyes` | 由 ID | `bar` 竖条、`dot` 圆点、`tall` 长条 |
|
|
37
|
+
| `eyeColor` | 近白 | 任意 CSS 颜色 |
|
|
38
|
+
| `state` | `'idle'` | `STATES` 里的名字,共 55 个,见下 |
|
|
39
|
+
| `progress` | 循环 | 0–1,`progress` 状态显示的进度 |
|
|
40
|
+
| `scheme` | `'light'` | 所在背景:`light`、`dark`、`auto`(跟随系统) |
|
|
41
|
+
| `signals` | `'around'` | 信号类状态的画法:`around` 画在身体周围,`morph` 身体变成符号 |
|
|
42
|
+
| `emphasized` | `false` | 标记为当前 Bot:略放大,脚下有光环 |
|
|
43
|
+
| `interactive` | `true` | 悬停、按压、点击、拖拽旋转 |
|
|
44
|
+
| `track` | `true` | 头和眼睛跟随指针 |
|
|
45
|
+
| `static` | `false` | 只显示静止姿态。系统开了“减少动态效果”时总是如此 |
|
|
46
|
+
| `playing` | `true` | `false` 暂停 |
|
|
47
|
+
| `maxFrameRate` | `60` | 帧率上限 |
|
|
48
|
+
| `autoplay` | `true` | `false` 时不进帧循环,由你调用 `step(dt)` |
|
|
49
|
+
| `label` | – | 无障碍名称。不给则对读屏隐藏 |
|
|
50
|
+
| `watermark` | `true` | 右下角的 KodaX-AI 标记,48 px 及以上才画。商业或组织内使用必须保持开启,见根目录 [LICENSE](../../LICENSE) |
|
|
51
|
+
|
|
52
|
+
## 方法
|
|
53
|
+
|
|
54
|
+
| 方法 | 说明 |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `update(options)` | 改任意选项。换立体时会转身变过去 |
|
|
57
|
+
| `setState(name)` | 切换状态。接受别名:`waiting`、`failed`、`celebrate`、`pending`、`done`、`love` |
|
|
58
|
+
| `play(name)` | 播一次动作(`GESTURES`,17 个),叠加在状态上 |
|
|
59
|
+
| `express(name, ms)` / `setExpression(name, {duration})` | 临时换眼神(`EXPRESSIONS`,21 个) |
|
|
60
|
+
| `poke(action, {turns})` | `'spin'`、`'bounce'`、`'nod'` 或任意动作名;不给参数则随机反应 |
|
|
61
|
+
| `lookAt(x, y)` / `gaze(point)` | 盯住页面上一个点;传 `null` 交还给指针 |
|
|
62
|
+
| `look({x, y})` | 固定朝一个方向看,各轴 -1..1;传 `null` 取消 |
|
|
63
|
+
| `blink()`、`nudge()` | 眨眼;轻点一下头(适合每次按键) |
|
|
64
|
+
| `restart()` | 当前状态从头开始 |
|
|
65
|
+
| `suspend()` / `resume()` | 离开 / 回到帧循环(元素暂时不在页面上时用) |
|
|
66
|
+
| `step(dt)` | 手动推进 dt 秒并重画。同样的 ID 和同样的步进得到同样的画面 |
|
|
67
|
+
| `toSVG()` | 当前这一帧的独立 SVG 字符串 |
|
|
68
|
+
| `dispose()` | 移除并释放 |
|
|
69
|
+
|
|
70
|
+
`setAttention({x, y})` 让页面上所有形象一起看向一个点(比如输入框的光标),传 `null` 取消。
|
|
71
|
+
|
|
72
|
+
用户点击形象时,`el` 上会冒泡一个 `bot-poke` 事件,`detail.avatar` 是被点的形象。
|
|
73
|
+
|
|
74
|
+
## 状态
|
|
75
|
+
|
|
76
|
+
| 组 | 状态 |
|
|
77
|
+
|---|---|
|
|
78
|
+
| 工作流程 17 | idle listening thinking streaming searching reading working coding running computing controlling asking blocked finished error sleeping waking |
|
|
79
|
+
| 情绪反应 18 | happy excited laughing proud curious playful shy surprised suspicious angry confused sad drowsy bored scared celebrating approving loving |
|
|
80
|
+
| 信号 13 | orbit radar progress loading spawning dictating sending receiving uploading writing alerting bouncing powering-down |
|
|
81
|
+
| 产品场景 4 | humming notifying dragging greeting |
|
|
82
|
+
| 展示 3 | logo showcase turntable |
|
|
83
|
+
|
|
84
|
+
状态的名字和含义定义在 `core/states.js`,所有主题共用;换主题不需要改产品代码。
|
|
85
|
+
|
|
86
|
+
## 文件
|
|
87
|
+
|
|
88
|
+
| 文件 | 内容 |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `index.js` | 入口和导出 |
|
|
91
|
+
| `avatar.js` | `SolidAvatar`:选项、交互、物理、渲染 |
|
|
92
|
+
| `geometry.js` | 36 个立体的网格 |
|
|
93
|
+
| `face.js` | 眼型和眼神 |
|
|
94
|
+
| `motion.js` | 每个状态的姿态、动作、空闲小动作 |
|
|
95
|
+
| `symbols.js` | `signals: 'morph'` 时身体变成的符号 |
|
|
96
|
+
| `playground.html` | 试玩页 |
|
|
97
|
+
| `sheet.html`、`filmstrip.html` | 全家福和连续帧,核对造型和动作用 |
|
|
98
|
+
|
|
99
|
+
## 加一个立体
|
|
100
|
+
|
|
101
|
+
在 `geometry.js` 的 `DEFS` 里加一行:名字、中文名、分组(`poly` 多面体、`lathe` 旋转体、`badge` 厚片)和一个生成网格的函数。眼睛、状态、动作、交互都会自动适用。加完跑一遍 `tests/check.html`。
|