@kodax-ai/botui 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ KodaX-AI BotUI License (KAI-BUL) 1.0
2
+
3
+ Copyright (c) 2026 Wei Zhang (张伟), also known as icetomoyo
4
+ <icetomoyo@gmail.com> <icetomoyo@163.com>
5
+
6
+ All rights reserved except as expressly granted in this License.
7
+
8
+ This License is derived from the KodaX-AI Fair Core License (KAI-FCL) 1.0 and
9
+ adapted for BotUI. It is a source-available license. It is not an open-source
10
+ license.
11
+
12
+ This License applies to every version of BotUI, including copies published
13
+ before this LICENSE file was added. Those earlier copies were published
14
+ without any license and granted no rights of use.
15
+
16
+ 1. Definitions
17
+
18
+ "Software" means BotUI, including its source code, documentation, examples,
19
+ packages, and the avatar designs, shapes, expressions, and motion it contains,
20
+ as distributed by KodaX-AI under this License.
21
+
22
+ "Output" means any image, SVG markup, animation, or other rendering produced by
23
+ the Software or copied from it.
24
+
25
+ "KodaX-AI" means Wei Zhang (张伟), who publishes under the names icetomoyo and
26
+ KodaX-AI, as the copyright owner and licensor of the Software, together with
27
+ that person's successors and assigns and any legal entity to which the rights
28
+ in the Software are transferred.
29
+
30
+ "You" means the individual or legal entity exercising permissions under this
31
+ License.
32
+
33
+ "Community Use" means use by an individual for personal learning, individual
34
+ non-commercial work, classroom instruction, non-production research, or
35
+ developing and testing changes for contribution to public open-source
36
+ projects.
37
+
38
+ "Commercial or Organizational Use" means any use by or for a company, school,
39
+ lab, institution, government agency, or other organization, including use that
40
+ is purely internal, and any use in or for a product, service, or activity that
41
+ is sold, monetized, or carried out for business purposes. Use by an individual
42
+ on behalf of, at the direction of, or for the benefit of an employer, client,
43
+ or other organization, and use in work done for payment, is Commercial or
44
+ Organizational Use. Any use that is not Community Use is Commercial or
45
+ Organizational Use.
46
+
47
+ "Attribution Notice" means the following text, or a translation of it that
48
+ keeps the names unchanged:
49
+
50
+ Bot avatars by BotUI. Copyright (c) icetomoyo / KodaX-AI.
51
+ https://github.com/icetomoyo/BotUI
52
+
53
+ "Watermark" means the visible "KodaX-AI" mark and the embedded copyright
54
+ metadata that the unmodified Software adds to its Output, at the sizes,
55
+ positions, and legibility at which the unmodified Software renders them with
56
+ its default settings.
57
+
58
+ "Customer Agreement" means a written agreement with KodaX-AI that grants
59
+ rights beyond this License.
60
+
61
+ 2. Conditions That Apply to Every Use
62
+
63
+ Every permission in this License is conditional on all of the following:
64
+
65
+ (a) You keep this LICENSE file, the NOTICE file, and all copyright, license,
66
+ and attribution notices in every copy of the Software or substantial
67
+ portion of it, including the copyright metadata embedded in Output.
68
+
69
+ (b) Every product, service, website, or document in which You use the Software
70
+ or its Output displays the Attribution Notice where a user can reasonably
71
+ find it, such as an "About" page, a credits or license list, or the
72
+ documentation.
73
+
74
+ (c) You do not present the Software, its Output, or the avatar designs as Your
75
+ own original work, and You do not imply endorsement by KodaX-AI.
76
+
77
+ 3. Community Grant
78
+
79
+ Subject to Section 2, KodaX-AI grants You a limited, non-exclusive,
80
+ non-transferable, no-charge license to download, run, inspect, modify, and
81
+ copy the Software, and to use its Output, solely for Community Use. For
82
+ Community Use You may turn the visible "KodaX-AI" mark off using the option the
83
+ Software provides.
84
+
85
+ 4. Commercial and Organizational Grant
86
+
87
+ Subject to Section 2, KodaX-AI grants You a limited, non-exclusive,
88
+ non-transferable, no-charge license to download, run, inspect, modify, and
89
+ copy the Software, to include it in Your own products and services, and to use
90
+ its Output, for Commercial or Organizational Use, on the further condition
91
+ that the Watermark is kept:
92
+
93
+ (a) the Watermark stays enabled wherever the Software or its Output is used;
94
+
95
+ (b) You do not remove, disable, hide, cover, crop out, shrink, recolor to
96
+ reduce legibility, or otherwise defeat the Watermark, whether by option,
97
+ by modifying the Software, by styling, by post-processing Output, or by
98
+ any other means; and
99
+
100
+ (c) modified versions of the Software render the Watermark at least as
101
+ visibly as the unmodified Software does.
102
+
103
+ Commercial or Organizational Use without the Watermark requires a Customer
104
+ Agreement.
105
+
106
+ 5. Distribution
107
+
108
+ You may deliver the Software to end users as part of Your own product or
109
+ service where that is necessary for the product or service to work, for
110
+ example as scripts loaded by a web page.
111
+
112
+ You may publish or share copies of the Software, modified or not, only under
113
+ this License, with Section 2(a) satisfied, with the Watermark function intact
114
+ and enabled by default, and with a clear statement of any changes You made.
115
+
116
+ 6. Restrictions
117
+
118
+ Except as expressly allowed by this License or a Customer Agreement, You must
119
+ not:
120
+
121
+ - use the Software or its Output for Commercial or Organizational Use without
122
+ the Watermark;
123
+ - sell, rent, lease, or sublicense the Software, or offer it as a standalone
124
+ avatar library, asset pack, or avatar generation service;
125
+ - remove or alter copyright, license, attribution, trademark, or third-party
126
+ notices;
127
+ - use the Software or its Output to train, fine-tune, or evaluate a model, or
128
+ to build a dataset, for the purpose of generating similar avatars;
129
+ - use KodaX-AI names, logos, product names, or trademarks except as required by
130
+ this License or to describe the origin of the Software accurately;
131
+ - violate applicable law or use the Software to infringe third-party rights.
132
+
133
+ 7. Contributions
134
+
135
+ You may submit changes, patches, issues, and documentation improvements to
136
+ KodaX-AI. Unless a separate written contribution agreement says otherwise, You
137
+ grant KodaX-AI a perpetual, worldwide, irrevocable, royalty-free license to
138
+ use, reproduce, modify, distribute, sublicense, and otherwise exploit
139
+ contributions You submit for inclusion in the Software, and You represent that
140
+ You have the right to grant that license.
141
+
142
+ 8. Separate Agreements
143
+
144
+ If You have a Customer Agreement with KodaX-AI, that Customer Agreement
145
+ controls for the uses it covers. This License controls only where the Customer
146
+ Agreement does not grant additional rights or impose different obligations.
147
+
148
+ 9. Ownership
149
+
150
+ KodaX-AI and its licensors retain all right, title, and interest in and to the
151
+ Software, including the avatar designs. No rights are granted except those
152
+ expressly stated in this License or a Customer Agreement.
153
+
154
+ 10. Termination
155
+
156
+ Your rights under this License terminate automatically if You violate this
157
+ License and do not cure the violation within 30 days after receiving notice
158
+ from KodaX-AI. Rights terminate immediately for intentional removal or defeat
159
+ of the Watermark in Commercial or Organizational Use, or for removal of
160
+ copyright or attribution notices. After termination, You must stop using and
161
+ distributing the Software and its Output, and You must delete copies not
162
+ otherwise authorized by a Customer Agreement.
163
+
164
+ 11. Disclaimer of Warranty
165
+
166
+ THE SOFTWARE IS PROVIDED "AS IS" AND "AS AVAILABLE", WITHOUT WARRANTIES OR
167
+ CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF
168
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT,
169
+ SECURITY, ACCURACY, OR AVAILABILITY.
170
+
171
+ 12. Limitation of Liability
172
+
173
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, KODAX-AI AND ITS CONTRIBUTORS WILL NOT
174
+ BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR
175
+ PUNITIVE DAMAGES, OR FOR LOST PROFITS, LOST REVENUE, LOST DATA, BUSINESS
176
+ INTERRUPTION, GOODWILL LOSS, OR PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
177
+ ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS LICENSE, EVEN IF ADVISED OF
178
+ THE POSSIBILITY OF SUCH DAMAGES.
179
+
180
+ 13. License Versions
181
+
182
+ KodaX-AI may publish revised versions of this License. Each copy of the
183
+ Software is governed by the version of this License that KodaX-AI distributed
184
+ with that copy.
185
+
186
+ 14. General
187
+
188
+ No rights are granted by implication, estoppel, or otherwise. This License
189
+ grants no patent or trademark rights except as needed to exercise the
190
+ permissions expressly stated in it. If any provision of this License is held
191
+ unenforceable, that provision is enforced to the maximum extent permitted and
192
+ the remaining provisions stay in effect. A failure or delay by KodaX-AI in
193
+ enforcing any provision is not a waiver of it. You may not assign or transfer
194
+ this License without KodaX-AI's prior written consent.
195
+
196
+ 15. Contact
197
+
198
+ For use without the Watermark, other commercial terms, or questions about this
199
+ License, contact:
200
+
201
+ Wei Zhang (张伟), also known as icetomoyo
202
+ <icetomoyo@gmail.com> <icetomoyo@163.com>
package/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ BotUI
2
+ Copyright 2026 Wei Zhang (张伟), also known as icetomoyo
3
+ <icetomoyo@gmail.com> <icetomoyo@163.com> / KodaX-AI
4
+
5
+ This product includes software developed by Wei Zhang (icetomoyo) / KodaX-AI.
6
+ Licensed under the KodaX-AI BotUI License 1.0. See the LICENSE file.
7
+ https://github.com/icetomoyo/BotUI
package/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # BotUI
2
+
3
+ 收录各种类型 Bot 形象的专门项目。RSIBot 采用其中一套主题。
4
+
5
+ 目前做好的是推荐系列“立体家族”(带眼睛的立体):36 个立体、16 种颜色、3 种眼型、55 个状态、17 个动作、21 种眼神,零依赖。其余方向还是草图,对比板在 `avatar-lab/directions.html`。
6
+
7
+ ![立体家族的 36 个立体](docs/solids.svg)
8
+
9
+ 同一个 Bot 在不同状态下的样子(每格换了一个立体和颜色):
10
+
11
+ ![状态示例](docs/states.svg)
12
+
13
+ 以上是引擎自己导出的静止帧(`docs/make.html` 生成);动起来的样子见下面的“本地查看”。
14
+
15
+ ## 使用
16
+
17
+ ```bash
18
+ npm install @kodax-ai/botui
19
+ ```
20
+
21
+ ```js
22
+ import {createAvatar} from '@kodax-ai/botui';
23
+
24
+ const bot = createAvatar({identity: 'research-bot', size: 36});
25
+ sidebar.append(bot.el);
26
+ bot.setState('thinking');
27
+ ```
28
+
29
+ 或者不写 JS、不用构建,直接从 CDN 引用:
30
+
31
+ ```html
32
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
33
+ <bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
34
+ ```
35
+
36
+ 只用一个主题时可以直接引用 `@kodax-ai/botui/themes/solids`。也可以不经 npm,按版本标签引用本仓库:`npm install github:icetomoyo/BotUI#v0.1.1`。完整的选项和方法见 [themes/solids/README.md](themes/solids/README.md)。
37
+
38
+ ## 许可
39
+
40
+ 源码公开,但不是开源软件。本项目采用 [KodaX-AI BotUI License 1.0](LICENSE),版权归张伟(Wei Zhang,icetomoyo)/ KodaX-AI 所有。要点(以 LICENSE 原文为准):
41
+
42
+ - **任何使用**都必须保留 `LICENSE`、`NOTICE` 和代码、SVG 里的版权信息,并在产品的“关于”、文档或致谢处写明:`Bot avatars by BotUI © icetomoyo / KodaX-AI`。
43
+ - **个人、学习、非商业使用**:免费,可以用 `watermark: false` 关掉水印。
44
+ - **商业或组织内使用**(公司、学校、机构内部使用也算):免费,但必须保持水印开启、清晰可见、不被遮挡或改动。形象在 48 px 及以上时右下角显示 `KodaX-AI`。
45
+ - **商用去水印**:需要与 KodaX-AI 另签书面授权。联系方式见 LICENSE。
46
+
47
+ ## 结构
48
+
49
+ 一个核心加每主题一个渲染器,零依赖的原生 ES 模块,不需要构建。
50
+
51
+ | 路径 | 内容 |
52
+ |---|---|
53
+ | `core/` | 各主题共用:帧循环、身份哈希、指针、状态词表(`states.js`)、主题注册(`registry.js`) |
54
+ | `themes/solids/` | 推荐系列“立体家族”:带眼睛的立体。用法见 [themes/solids/README.md](themes/solids/README.md) |
55
+ | `index.js` | 总入口:`createAvatar({theme, ...})` |
56
+ | `element.js` | 自定义元素 `<bot-avatar>` |
57
+ | `index.d.ts` | 类型声明 |
58
+ | `tests/check.html` | 自检页:把所有立体、状态、动作、眼神、颜色和选项跑一遍 |
59
+ | `avatar-lab/` | 早期草图存档,其余主题还在这里 |
60
+
61
+ ## 本地查看
62
+
63
+ ES 模块不能从 `file://` 加载。双击根目录的 `serve.cmd` 会起本地服务并打开试玩页 `themes/solids/playground.html`。同目录的 `sheet.html`(全家福)和 `filmstrip.html`(连续帧)用来核对造型和动作。
64
+
65
+ 自检:服务起来后打开 `http://127.0.0.1:8765/tests/check.html`,页面显示 `PASS` 或失败清单。
66
+
67
+ ## 发布到 npm(维护者)
68
+
69
+ 包名 `@kodax-ai/botui`,发布方式照搬 KodaX:仓库里的 `package.json` 始终是 `private: true`,直接 `npm publish` 会被拒绝。只有 `scripts/release.mjs` 会在打包那一刻把它改成 false,打完包立即还原。
70
+
71
+ 在仓库根目录运行 `npm run release`(与 `node scripts/release.mjs` 完全等同,后面的版本词和 `--dry-run`、`--otp=...` 等参数两种写法都一样)。
72
+
73
+ 最简单的用法:自己把 `package.json` 的 `version` 改好并提交,然后不带参数运行 `npm run release`。dist-tag 按版本号自动决定,和 KodaX 一样:
74
+
75
+ | package.json version | dist-tag |
76
+ |---|---|
77
+ | `0.2.0-alpha.3` | `alpha` |
78
+ | `0.2.0-beta.9` | `beta` |
79
+ | `0.2.0-rc.4` | `rc` |
80
+ | `0.2.0` | `latest` |
81
+
82
+ 也可以让脚本帮你改版本号,按 alpha → beta → rc → 正式版走:
83
+
84
+ ```bash
85
+ npm run release alpha minor # 0.1.0 -> 0.2.0-alpha.0(从正式版开新一轮;minor 可换成 patch / major,省略时是 patch)
86
+ npm run release alpha # 0.2.0-alpha.0 -> 0.2.0-alpha.1
87
+ npm run release beta # 0.2.0-alpha.1 -> 0.2.0-beta.0
88
+ npm run release rc # 0.2.0-beta.N -> 0.2.0-rc.0
89
+ npm run release final # 0.2.0-rc.N -> 0.2.0
90
+ npm run release patch # 0.2.0 -> 0.2.1(不走预发布的小修)
91
+ ```
92
+
93
+ 每一行都会:跑检查 → 打包审计 → 提交 `Release v<版本>` 并打标签 → 发布 → 推送。任何一行后面加 `--dry-run` 就是演练,不提交、不打标签,也不真发布。alpha / beta / rc 分别发到 npm 的 `alpha` / `beta` / `rc` 标签,只有正式版发到 `latest`,所以 `npm install @kodax-ai/botui` 永远拿到正式版,想试 beta 的人用 `npm install @kodax-ai/botui@beta`。新版本必须比当前版本高,写反了会直接报错。
94
+
95
+ 也支持 `minor`、`major`、`prerelease` 和直接写版本号(如 `npm run release 0.3.0-beta.0`)。
96
+
97
+ 不带参数时,HEAD 还没打标签的话脚本会自动打上 `v<版本>`。参数写错(比如 `--dryrun`)时,用 `node` 运行会直接报错;用 `npm run` 运行时 npm 会把它吞掉,脚本就当成真发布。和 KodaX 一样,真发布不会再问确认,没把握时先加 `--dry-run` 演练。
98
+
99
+ `release.mjs` 依次做这些事,任何一步失败都会停下:
100
+
101
+ 1. 检查 `package.json`:包名、`files` 白名单、`exports`、LICENSE,以及目标版本在 npm 上还不存在。
102
+ 2. 检查 git:已跟踪的文件没有未提交的改动(与包无关的未跟踪文件不影响);目标版本的标签状态正确。演练和 `--pack-only` 只给警告。
103
+ 3. 用无头 Chrome 跑 `tests/check.html`,必须显示 `PASS`(单独跑:`npm run check`)。
104
+ 4. 按目标版本打包到 `.release/`,然后审计:必需文件都在;测试、草图、截图之类的开发文件没有混进去;进包的每个文件都已提交且未修改;每个相对 import 都能在包里找到;最后把包按使用方的方式装进临时目录,在 Node 里按包名 import 一遍。
105
+ 5. 改版本号、提交 `Release v<版本>`、打标签。前面所有可能失败的步骤都已经跑完,所以审计失败不会留下半截的版本提交。
106
+ 6. `npm publish` 到 `registry.npmjs.org`,不受本机 `.npmrc` 镜像设置影响。dist-tag 按上面的表自动决定,预发布版本不会覆盖 `latest`。
107
+ 7. `git push origin <分支> v<版本>`。
108
+
109
+ 其他参数:`--otp=123456`(npm 两步验证)、`--no-push`(不推送)、`--tag=next`(指定 dist-tag)、`--skip-check`(跳过 Chrome 自检)。
110
+
111
+ 如果发布这一步失败了(常见原因是 OTP 过期),版本提交和标签已经留在本地,修好之后不带版本参数再跑一次就行:`npm run release --otp=123456`。
112
+
113
+ `npm run release --pack-only` 只打包不发布,生成的 tgz 可以在别的项目里 `npm install <路径>` 试用。
package/core/core.js ADDED
@@ -0,0 +1,58 @@
1
+ // What every theme shares: small maths, the identity hash, one pointer
2
+ // listener, one animation frame loop and the reduced-motion preference.
3
+ //
4
+ // A theme's avatar joins the loop with `join(avatar)`. The loop expects:
5
+ // el the host element
6
+ // visible false while scrolled out of view (the loop maintains it)
7
+ // static true to show only the resting pose
8
+ // playing false to pause
9
+ // maxFrameRate frames per second, at most
10
+ // step(dt) advance by dt seconds and redraw
11
+ // settle() draw the resting pose of the current state; sets `settled`
12
+
13
+ export const TAU = Math.PI * 2;
14
+ export const ease = (cur, target, dt, k) => cur + (target - cur) * (1 - Math.exp(-dt * k));
15
+ export const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
16
+ export const smooth = u => u * u * (3 - 2 * u);
17
+ export const bump = u => Math.sin(Math.PI * clamp(u, 0, 1));
18
+
19
+ export function hash(text) { let h = 2166136261; for (const ch of String(text)) h = Math.imul(h ^ ch.codePointAt(0), 16777619); return h >>> 0; }
20
+ export function random(seed) { let s = seed >>> 0; return () => { s = (s + 0x6D2B79F5) >>> 0; let x = Math.imul(s ^ (s >>> 15), 1 | s); x = (x + Math.imul(x ^ (x >>> 7), 61 | x)) ^ x; return ((x ^ (x >>> 14)) >>> 0) / 4294967296; }; }
21
+
22
+ /** Last pointer position in client space; `at` is when it last moved. */
23
+ export const pointer = {x: 0, y: 0, at: -1e9};
24
+ /** A client-space point every avatar should look at, or null. */
25
+ export const world = {attention: null};
26
+ export function setAttention(point) { world.attention = point; }
27
+
28
+ const browser = typeof window !== 'undefined';
29
+ if (browser) window.addEventListener('pointermove', e => { pointer.x = e.clientX; pointer.y = e.clientY; pointer.at = performance.now(); }, {passive: true});
30
+ const reduced = browser && window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : null;
31
+
32
+ const darkQuery = browser && window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
33
+ /** True when the system asks for a dark colour scheme. */
34
+ export const prefersDark = () => !!darkQuery?.matches;
35
+
36
+ const live = new Set();
37
+ let raf = 0, last = 0, observer = null;
38
+ function frame(now) {
39
+ const dt = Math.min(0.1, (now - last) / 1000), calm = reduced?.matches; last = now;
40
+ for (const a of live) {
41
+ if (!a.visible || !a.el.isConnected) continue;
42
+ if (a.static || calm) { if (!a.settled) a.settle(); continue; }
43
+ if (!a.playing) continue;
44
+ a.owed = (a.owed || 0) + dt;
45
+ if (a.owed + 0.002 >= 1 / a.maxFrameRate) { a.step(Math.min(0.1, a.owed)); a.owed = 0; }
46
+ }
47
+ raf = live.size ? requestAnimationFrame(frame) : 0;
48
+ }
49
+ export function join(avatar) {
50
+ live.add(avatar);
51
+ if (typeof IntersectionObserver !== 'undefined') {
52
+ observer = observer || new IntersectionObserver(entries => { for (const entry of entries) if (entry.target.botAvatar) entry.target.botAvatar.visible = entry.isIntersecting; }, {rootMargin: '80px'});
53
+ observer.observe(avatar.el);
54
+ }
55
+ if (!raf && browser) { last = performance.now(); raf = requestAnimationFrame(frame); }
56
+ }
57
+ export function leave(avatar) { live.delete(avatar); observer?.unobserve(avatar.el); }
58
+ export const joined = avatar => live.has(avatar);
@@ -0,0 +1,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
+ const themes = new Map();
8
+
9
+ export function registerTheme(theme) { themes.set(theme.name, theme); return theme; }
10
+ export const getTheme = name => themes.get(name) || null;
11
+ export const themeNames = () => [...themes.keys()];
12
+
13
+ /** Create an avatar. `theme` picks the theme by name; without it the first registered theme is used. */
14
+ export function createAvatar({theme, ...options} = {}) {
15
+ const chosen = themes.get(theme) || themes.values().next().value;
16
+ if (!chosen) throw new Error('BotUI: no theme is registered');
17
+ return chosen.create(options);
18
+ }
package/core/states.js ADDED
@@ -0,0 +1,36 @@
1
+ // The state vocabulary shared by every theme. A theme decides how each state
2
+ // looks; the names and their meaning are fixed here so a product can switch
3
+ // themes without changing its own code.
4
+
5
+ export const STATE_GROUPS = {life: '工作流程', mood: '情绪反应', signal: '信号', product: '产品场景', brand: '展示'};
6
+
7
+ export const STATES = {
8
+ idle: {zh: '空闲', group: 'life'}, listening: {zh: '倾听', group: 'life'}, thinking: {zh: '思考', group: 'life'},
9
+ streaming: {zh: '输出', group: 'life'}, searching: {zh: '搜索', group: 'life'}, reading: {zh: '阅读', group: 'life'},
10
+ working: {zh: '干活', group: 'life'}, coding: {zh: '写代码', group: 'life'}, running: {zh: '运行', group: 'life'},
11
+ computing: {zh: '计算', group: 'life'}, controlling: {zh: '操控', group: 'life'}, asking: {zh: '等你', group: 'life'},
12
+ blocked: {zh: '阻塞', group: 'life'}, finished: {zh: '完成', group: 'life'}, error: {zh: '出错', group: 'life'},
13
+ sleeping: {zh: '睡着', group: 'life'}, waking: {zh: '醒来', group: 'life'},
14
+
15
+ happy: {zh: '开心', group: 'mood'}, excited: {zh: '兴奋', group: 'mood'}, laughing: {zh: '大笑', group: 'mood'},
16
+ proud: {zh: '得意', group: 'mood'}, curious: {zh: '好奇', group: 'mood'}, playful: {zh: '调皮', group: 'mood'},
17
+ shy: {zh: '害羞', group: 'mood'}, surprised: {zh: '惊讶', group: 'mood'}, suspicious: {zh: '怀疑', group: 'mood'},
18
+ angry: {zh: '生气', group: 'mood'}, confused: {zh: '困惑', group: 'mood'}, sad: {zh: '难过', group: 'mood'},
19
+ drowsy: {zh: '犯困', group: 'mood'}, bored: {zh: '无聊', group: 'mood'}, scared: {zh: '害怕', group: 'mood'},
20
+ celebrating: {zh: '庆祝', group: 'mood'}, approving: {zh: '赞同', group: 'mood'}, loving: {zh: '喜欢', group: 'mood'},
21
+
22
+ orbit: {zh: '环绕', group: 'signal'}, radar: {zh: '雷达', group: 'signal'}, progress: {zh: '进度', group: 'signal'},
23
+ loading: {zh: '加载', group: 'signal'}, spawning: {zh: '生成', group: 'signal'}, dictating: {zh: '听写', group: 'signal'},
24
+ sending: {zh: '发送', group: 'signal'}, receiving: {zh: '接收', group: 'signal'}, uploading: {zh: '上传', group: 'signal'},
25
+ writing: {zh: '书写', group: 'signal'}, alerting: {zh: '警报', group: 'signal'}, bouncing: {zh: '弹跳', group: 'signal'},
26
+ 'powering-down': {zh: '关机', group: 'signal'},
27
+
28
+ humming: {zh: '哼歌', group: 'product'}, notifying: {zh: '有通知', group: 'product'}, dragging: {zh: '被拎起', group: 'product'},
29
+ greeting: {zh: '打招呼', group: 'product'},
30
+
31
+ logo: {zh: '标志', group: 'brand'}, showcase: {zh: '表演', group: 'brand'}, turntable: {zh: '转台', group: 'brand'},
32
+ };
33
+
34
+ /** Other names products use for the same states. */
35
+ export const ALIASES = {waiting: 'asking', failed: 'error', celebrate: 'celebrating', pending: 'thinking', done: 'finished', love: 'loving'};
36
+ export const resolveState = name => (STATES[name] ? name : ALIASES[name] || null);
package/element.js ADDED
@@ -0,0 +1,39 @@
1
+ // <bot-avatar>: the same avatars as a custom element, for pages without a build step.
2
+ //
3
+ // <script type="module" src="https://cdn.jsdelivr.net/npm/@kodax-ai/botui@0.1/element.js"></script>
4
+ // <bot-avatar identity="research-bot" size="36" state="thinking"></bot-avatar>
5
+ //
6
+ // Attributes mirror the options of createAvatar. Boolean ones are on when
7
+ // present: static, emphasized, paused, inert (no interaction), untracked (do
8
+ // not follow the pointer), no-watermark (see LICENSE for when that is allowed).
9
+ // The avatar itself is at `element.avatar`.
10
+
11
+ import {createAvatar} from './index.js';
12
+
13
+ const TEXT = {identity: 'identity', shape: 'shape', color: 'color', eyes: 'eyes', 'eye-color': 'eyeColor', state: 'state', scheme: 'scheme', signals: 'signals', label: 'label'};
14
+ const NUMBER = {size: 'size', hue: 'hue', progress: 'progress', 'max-frame-rate': 'maxFrameRate'};
15
+ const REBUILD = ['theme', 'inert'];
16
+
17
+ export class BotAvatarElement extends HTMLElement {
18
+ static observedAttributes = [...Object.keys(TEXT), ...Object.keys(NUMBER), ...REBUILD, 'static', 'emphasized', 'paused', 'untracked', 'no-watermark'];
19
+
20
+ options() {
21
+ const options = {static: this.hasAttribute('static'), emphasized: this.hasAttribute('emphasized'), playing: !this.hasAttribute('paused'), track: !this.hasAttribute('untracked'), watermark: !this.hasAttribute('no-watermark')};
22
+ for (const name in TEXT) if (this.hasAttribute(name)) options[TEXT[name]] = this.getAttribute(name);
23
+ for (const name in NUMBER) if (this.hasAttribute(name) && !Number.isNaN(Number(this.getAttribute(name)))) options[NUMBER[name]] = Number(this.getAttribute(name));
24
+ return options;
25
+ }
26
+ build() {
27
+ this.avatar?.dispose();
28
+ this.avatar = createAvatar({...this.options(), theme: this.getAttribute('theme') || undefined, interactive: !this.hasAttribute('inert')});
29
+ this.append(this.avatar.el);
30
+ }
31
+ connectedCallback() { if (this.avatar) this.avatar.resume(); else this.build(); }
32
+ disconnectedCallback() { this.avatar?.suspend(); }
33
+ attributeChangedCallback(name, before, after) {
34
+ if (!this.avatar || before === after) return;
35
+ if (REBUILD.includes(name)) this.build(); else this.avatar.update(this.options());
36
+ }
37
+ }
38
+
39
+ if (typeof customElements !== 'undefined' && !customElements.get('bot-avatar')) customElements.define('bot-avatar', BotAvatarElement);
package/index.d.ts ADDED
@@ -0,0 +1,122 @@
1
+ // Types for '@kodax-ai/botui' and '@kodax-ai/botui/themes/solids'.
2
+
3
+ export type StateGroup = 'life' | 'mood' | 'signal' | 'product' | 'brand';
4
+ export type StateName =
5
+ | 'idle' | 'listening' | 'thinking' | 'streaming' | 'searching' | 'reading' | 'working' | 'coding' | 'running'
6
+ | 'computing' | 'controlling' | 'asking' | 'blocked' | 'finished' | 'error' | 'sleeping' | 'waking'
7
+ | 'happy' | 'excited' | 'laughing' | 'proud' | 'curious' | 'playful' | 'shy' | 'surprised' | 'suspicious' | 'angry'
8
+ | 'confused' | 'sad' | 'drowsy' | 'bored' | 'scared' | 'celebrating' | 'approving' | 'loving'
9
+ | 'orbit' | 'radar' | 'progress' | 'loading' | 'spawning' | 'dictating' | 'sending' | 'receiving' | 'uploading'
10
+ | 'writing' | 'alerting' | 'bouncing' | 'powering-down'
11
+ | 'humming' | 'notifying' | 'dragging' | 'greeting'
12
+ | 'logo' | 'showcase' | 'turntable';
13
+ /** Other names accepted for a state. */
14
+ export type StateAlias = 'waiting' | 'failed' | 'celebrate' | 'pending' | 'done' | 'love';
15
+ export type GestureName =
16
+ | 'nod' | 'shake' | 'tilt' | 'glance' | 'wink' | 'wave' | 'bow' | 'spin' | 'flip' | 'roll' | 'jump' | 'bounce'
17
+ | 'wobble' | 'shiver' | 'startle' | 'stretch' | 'dance';
18
+ export type ExpressionName =
19
+ | 'neutral' | 'wide' | 'happy' | 'closed' | 'sleep' | 'squint' | 'sad' | 'focus' | 'angry' | 'calm' | 'sleepy' | 'shy'
20
+ | 'inspecting' | 'confused' | 'wink' | 'skeptic' | 'cross' | 'surprised' | 'dizzy' | 'love' | 'sparkle';
21
+ export type ColorName =
22
+ | 'red' | 'orange' | 'amber' | 'lime' | 'green' | 'teal' | 'cyan' | 'sky' | 'blue' | 'violet' | 'magenta' | 'pink'
23
+ | 'brown' | 'gray' | 'black' | 'white';
24
+ export type EyeStyle = 'bar' | 'dot' | 'tall';
25
+
26
+ export interface IdentityPool { shapes?: string[]; colors?: ColorName[]; eyes?: EyeStyle[]; }
27
+
28
+ export interface AvatarOptions {
29
+ /** Theme name. Only used by createAvatar from '@kodax-ai/botui'. */
30
+ theme?: string;
31
+ /** Bot ID. Picks shape, colour and eyes unless they are given. */
32
+ identity?: string;
33
+ /** Limits what an identity can be born as. */
34
+ pool?: IdentityPool;
35
+ /** Width and height in CSS pixels. Default 36. */
36
+ size?: number;
37
+ shape?: string;
38
+ color?: ColorName;
39
+ /** An OKLCH hue, 0..360, instead of a named colour. */
40
+ hue?: number;
41
+ eyes?: EyeStyle;
42
+ eyeColor?: string;
43
+ state?: StateName | StateAlias;
44
+ /** 0..1, shown by the `progress` state. */
45
+ progress?: number | null;
46
+ /** The background it sits on. Default 'light'; 'auto' follows the system. */
47
+ scheme?: 'light' | 'dark' | 'auto';
48
+ /** How signal states show. Default 'around'. */
49
+ signals?: 'around' | 'morph';
50
+ emphasized?: boolean;
51
+ /** Show the KodaX-AI mark (from 48 px up). Default true. Turning it off is allowed only for Community Use or under a Customer Agreement; see LICENSE. */
52
+ watermark?: boolean;
53
+ interactive?: boolean;
54
+ track?: boolean;
55
+ static?: boolean;
56
+ playing?: boolean;
57
+ maxFrameRate?: number;
58
+ /** False: nothing moves until you call step(). */
59
+ autoplay?: boolean;
60
+ /** Accessible name. Without it the avatar is hidden from assistive technology. */
61
+ label?: string;
62
+ }
63
+
64
+ export interface Avatar {
65
+ /** The host element. Append it to the page. Fires a bubbling `bot-poke` event when clicked. */
66
+ readonly el: HTMLSpanElement;
67
+ readonly state: StateName;
68
+ readonly shape: string;
69
+ readonly color: ColorName | null;
70
+ readonly eyes: EyeStyle;
71
+ update(options: Omit<AvatarOptions, 'theme' | 'interactive' | 'autoplay'>): this;
72
+ setState(name: StateName | StateAlias): this;
73
+ play(name: GestureName): this;
74
+ express(name: ExpressionName | null, ms?: number): this;
75
+ setExpression(name: ExpressionName | null, options?: {duration?: number}): this;
76
+ poke(action?: 'spin' | GestureName, options?: {turns?: number}): this;
77
+ /** Watch a client-space point; null hands control back to the pointer. */
78
+ lookAt(x: number | null, y?: number): this;
79
+ gaze(point: {x: number; y: number} | null): this;
80
+ /** Hold a direction, each axis -1..1; null releases it. */
81
+ look(direction: {x?: number; y?: number} | null): this;
82
+ blink(): this;
83
+ nudge(): this;
84
+ step(dt: number): this;
85
+ restart(): this;
86
+ /** Leave the frame loop, e.g. while detached from the page. */
87
+ suspend(): this;
88
+ resume(): this;
89
+ /** The current frame as standalone SVG markup. */
90
+ toSVG(): string;
91
+ dispose(): void;
92
+ }
93
+
94
+ export interface Theme {
95
+ name: string;
96
+ zh: string;
97
+ create(options?: AvatarOptions): Avatar;
98
+ catalog(): {shapes: {name: string; zh: string; group: string}[]; colors: string[]; eyes: string[]; states: string[]; gestures: string[]; expressions: string[]};
99
+ }
100
+
101
+ export function createAvatar(options?: AvatarOptions): Avatar;
102
+ export function registerTheme(theme: Theme): Theme;
103
+ export function getTheme(name: string): Theme | null;
104
+ export function themeNames(): string[];
105
+ /** Make every avatar look at a client-space point, or pass null to stop. */
106
+ export function setAttention(point: {x: number; y: number} | null): void;
107
+ export function resolveState(name: string): StateName | null;
108
+ export const STATES: Record<StateName, {zh: string; group: StateGroup}>;
109
+ export const STATE_GROUPS: Record<StateGroup, string>;
110
+ export const ALIASES: Record<StateAlias, StateName>;
111
+
112
+ // Also exported by '@kodax-ai/botui/themes/solids'.
113
+ export const theme: Theme;
114
+ export const SHAPES: {name: string; zh: string; group: 'poly' | 'lathe' | 'badge'}[];
115
+ export const GROUPS: Record<'poly' | 'lathe' | 'badge', string>;
116
+ export const COLORS: Record<ColorName, {hue: number; chroma?: number; base?: number; span?: number; eye?: string; dark?: object}>;
117
+ export const BIRTH_COLORS: ColorName[];
118
+ export const HUES: number[];
119
+ export const EYE_STYLES: Record<EyeStyle, {h: number; w: number; gap: number}>;
120
+ export const EXPRESSIONS: Record<ExpressionName, Function>;
121
+ export const GESTURES: Record<GestureName, {zh: string; dur: number}>;
122
+ export function identityFrom(identity: string, pool?: IdentityPool): {shape: string; color: ColorName; eyes: EyeStyle};
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ // BotUI: animated Bot avatars. One core, one renderer per theme.
2
+ //
3
+ // import {createAvatar} from '@kodax-ai/botui';
4
+ // const bot = createAvatar({identity: 'research-bot', size: 36});
5
+ // sidebar.append(bot.el);
6
+ // bot.setState('thinking');
7
+ //
8
+ // To ship a single theme, import it directly: '@kodax-ai/botui/themes/solids'.
9
+
10
+ import {registerTheme} from './core/registry.js';
11
+ import {theme as solids} from './themes/solids/index.js';
12
+
13
+ registerTheme(solids);
14
+
15
+ export {createAvatar, registerTheme, getTheme, themeNames} from './core/registry.js';
16
+ export {STATES, STATE_GROUPS, ALIASES, resolveState} from './core/states.js';
17
+ export {setAttention} from './core/core.js';