@kodax-ai/botui 0.1.1 → 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 +140 -113
- 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 -5
- package/package.json +38 -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 +48 -0
- package/themes/matrix/avatar.js +227 -0
- package/themes/matrix/engine.js +479 -0
- package/themes/matrix/index.d.ts +47 -0
- package/themes/matrix/index.js +34 -0
- 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 +2 -2
- package/themes/solids/avatar.js +561 -579
- package/themes/solids/face.js +52 -56
- package/themes/solids/index.js +34 -28
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The typed face theme's model: a face made of text, on the matrix theme's tile.
|
|
2
|
+
//
|
|
3
|
+
// Every expression is three or four typed characters (o_o, ^_^, >_<), so a chat
|
|
4
|
+
// Bot's face is written in the same medium as its replies. A new face is typed
|
|
5
|
+
// behind a blink: the line folds shut, the text changes, it opens again. Signal
|
|
6
|
+
// states are text too: a rolling ellipsis, a percentage, arrows that advance.
|
|
7
|
+
//
|
|
8
|
+
// Everything else (tile, motion, marks, particles, halo, handling) is the matrix
|
|
9
|
+
// model's; this file only draws the face. Pure, like it: no DOM, no clock, no
|
|
10
|
+
// Math.random, so the same Bot and the same inputs always give the same frames.
|
|
11
|
+
// Sketched in avatar-lab as direction K (字符脸), made a theme on 2026-11-28.
|
|
12
|
+
|
|
13
|
+
import {Matrix} from '../matrix/engine.js';
|
|
14
|
+
import {clamp} from '../../core/core.js';
|
|
15
|
+
|
|
16
|
+
const {sin, abs, max, min, floor, round} = Math;
|
|
17
|
+
const fixed = v => v.toFixed(2);
|
|
18
|
+
const FONT = "ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace";
|
|
19
|
+
const HEART = 'oklch(0.6 0.22 15)', BLUSH = 'oklch(0.74 0.17 15)';
|
|
20
|
+
// Spaces would collapse; a no-break space holds its place.
|
|
21
|
+
const keep = text => text.replace(/ /g, ' ');
|
|
22
|
+
const frame = (t, rate, list) => list[floor(t * rate) % list.length];
|
|
23
|
+
|
|
24
|
+
/** The eye character for each of the solids' eye styles: dot (圆点), bar (竖条), tall (长条). */
|
|
25
|
+
const EYE = {dot: '•', bar: 'o', tall: '0'};
|
|
26
|
+
export const kaomojiEyes = Object.freeze(Object.keys(EYE));
|
|
27
|
+
|
|
28
|
+
/** The 21 expressions: (eye character, t) -> text, or {text, fill}. */
|
|
29
|
+
export const FACES = {
|
|
30
|
+
neutral: e => `${e}_${e}`,
|
|
31
|
+
wide: () => 'O_O',
|
|
32
|
+
happy: () => '^_^',
|
|
33
|
+
closed: () => '-_-',
|
|
34
|
+
sleep: () => 'u_u',
|
|
35
|
+
squint: () => '>_<',
|
|
36
|
+
sad: () => ';_;',
|
|
37
|
+
focus: () => 'ò_ó',
|
|
38
|
+
angry: () => 'ÒдÓ',
|
|
39
|
+
calm: () => '˘‿˘',
|
|
40
|
+
sleepy: () => '=_=',
|
|
41
|
+
shy: e => `${e}//${e}`,
|
|
42
|
+
inspecting: e => `${e}_O`,
|
|
43
|
+
confused: () => '?_?',
|
|
44
|
+
wink: () => '^_~',
|
|
45
|
+
skeptic: () => '¬_¬',
|
|
46
|
+
cross: () => 'x_x',
|
|
47
|
+
surprised: () => '°o°',
|
|
48
|
+
dizzy: (e, t) => frame(t, 5, ['@_@', '@_@', '6_9']),
|
|
49
|
+
love: () => ({text: '♥_♥', fill: HEART}),
|
|
50
|
+
sparkle: (e, t) => frame(t, 3.5, ['*_*', '+_+']),
|
|
51
|
+
};
|
|
52
|
+
// Expressions whose eyes are already shut, so a blink leaves them alone.
|
|
53
|
+
const SHUT = new Set(['closed', 'sleep', 'sleepy', 'happy', 'calm', 'cross']);
|
|
54
|
+
|
|
55
|
+
/** What the screen types instead of a face: (eye, t, progress, since) -> text or {text, y, scale, opacity}, or null for the face. */
|
|
56
|
+
export const SCREENS = {
|
|
57
|
+
thinking: (e, t) => frame(t, 4.5, ['• ', '•• ', '•••', ' ••', ' •']),
|
|
58
|
+
streaming: (e, t) => frame(t, 8, [`${e}_${e}`, `${e}o${e}`, `${e}O${e}`, `${e}o${e}`]),
|
|
59
|
+
finished: () => '^o^',
|
|
60
|
+
orbit: (e, t) => `(${frame(t, 8, ['|', '/', '-', '\\'])})`,
|
|
61
|
+
radar: (e, t) => frame(t, 3, [' • ', '(•)', '((•))']),
|
|
62
|
+
progress: (e, t, progress) => round(clamp(progress ?? (t * 0.22) % 1, 0, 1) * 100) + '%',
|
|
63
|
+
loading: (e, t) => frame(t, 5, ['o··', '·o·', '··o', '·o·']),
|
|
64
|
+
spawning: (e, t, progress, since) => since >= 1.2 ? null : ['_', `${e}_`, `${e}_${e}`][min(2, floor(since * 2.6))],
|
|
65
|
+
dictating: (e, t) => frame(t, 6, [`${e}-${e}`, `${e}~${e}`, `${e}=${e}`, `${e}~${e}`]),
|
|
66
|
+
sending: (e, t) => frame(t, 4, ['> ', '>> ', '>>>', ' >>', ' >']),
|
|
67
|
+
receiving: (e, t) => frame(t, 4, [' <', ' <<', '<<<', '<< ', '< ']),
|
|
68
|
+
uploading: (e, t) => { const u = (t * 1.5) % 1; return {text: '^^^', y: 4 - 9 * u, opacity: 1 - 0.7 * u}; },
|
|
69
|
+
writing: (e, t) => 'abc'.slice(0, min(3, floor((t * 3) % 5))) + (floor(t * 3.4) % 2 ? '_' : ' '),
|
|
70
|
+
alerting: (e, t) => ({text: '(!)', scale: 1 + 0.12 * max(0, sin(t * 7))}),
|
|
71
|
+
bouncing: (e, t) => ({text: e, y: 6 - 18 * abs(sin(t * 4))}),
|
|
72
|
+
'powering-down': (e, t, progress, since) => since < 0.5 ? '-_-' : since < 1 ? '._.' : {text: '.', opacity: 0.45 + 0.25 * sin(t * 1.6)},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
class Kaomoji extends Matrix {
|
|
76
|
+
faceLayout(ink, node) {
|
|
77
|
+
return [
|
|
78
|
+
...[-1, 1].map(() => node('tile', 'ellipse', {rx: 5.5, ry: 3, fill: BLUSH, opacity: 0})),
|
|
79
|
+
node('tile', 'text', {x: 0, y: 0, 'text-anchor': 'middle', 'dominant-baseline': 'central', 'font-family': FONT, 'font-weight': 700, fill: ink.dark, text: ''}),
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
/** What to type this frame: {text, fill, y, scale, opacity, face}. */
|
|
83
|
+
typing(facing) {
|
|
84
|
+
if (!facing) return {text: ''};
|
|
85
|
+
const e = EYE[this.eyes] || EYE.bar;
|
|
86
|
+
const screen = !this.forced && SCREENS[this.state]?.(e, this.t, this.progress, this.since);
|
|
87
|
+
if (screen) return typeof screen === 'string' ? {text: screen} : screen;
|
|
88
|
+
let name = this.shown;
|
|
89
|
+
// Halfway through a blink the eyes are shut.
|
|
90
|
+
if (this.p.open < 0.45 && !SHUT.has(name)) name = 'closed';
|
|
91
|
+
const look = (FACES[name] || FACES.neutral)(e, this.t);
|
|
92
|
+
return {face: true, ...(typeof look === 'string' ? {text: look} : look)};
|
|
93
|
+
}
|
|
94
|
+
drawFace(nodes, n, {ink, dim, yaw, pitch, facing}) {
|
|
95
|
+
const p = this.p, typed = this.typing(facing);
|
|
96
|
+
// The face follows the gaze across the screen; a blink folds the line flat and opens it again.
|
|
97
|
+
const ox = typed.face ? clamp((-sin(yaw) * 1.5 + this.gx * 5) * 7, -8, 8) : 0, oy = typed.face ? clamp((pitch * 1.6 + this.gy * 5) * 5, -5, 5) : 0;
|
|
98
|
+
const text = keep(typed.text || ''), length = [...text].length;
|
|
99
|
+
const size = min(33, 105 / max(3, length)) * (this.size < 40 ? 1.12 : 1) * (typed.scale || 1);
|
|
100
|
+
const fold = typed.face ? 0.3 + 0.7 * abs(p.open * 2 - 1) : 1;
|
|
101
|
+
const blush = typed.face ? 0.8 * p.blush : 0;
|
|
102
|
+
for (const side of [-1, 1]) Object.assign(nodes[n++], {cx: fixed(50 + side * 24 + ox), cy: fixed(62 + oy), opacity: fixed(blush)});
|
|
103
|
+
Object.assign(nodes[n++], {text, 'font-size': fixed(size), fill: typed.fill || ink.dark, opacity: fixed((typed.opacity ?? 1) * (0.35 + 0.65 * dim)),
|
|
104
|
+
transform: `translate(${fixed(50 + ox)} ${fixed(50 + oy + (typed.y || 0))}) scale(1 ${fixed(fold)})`});
|
|
105
|
+
return n;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A typed face model. Options as createMatrix's: identity, hue, chroma, light, dots, edge, shape, eyes, state, progress, size, emphasized. */
|
|
110
|
+
export const createKaomoji = options => new Kaomoji(options);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Types for '@kodax-ai/botui/themes/kaomoji'.
|
|
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 KaomojiOptions, MatrixShape as KaomojiShape} 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 KaomojiAvatar extends MatrixAvatar {}
|
|
12
|
+
export const KaomojiAvatar: {new (options?: MatrixOptions): KaomojiAvatar};
|
|
13
|
+
|
|
14
|
+
export const theme: Theme;
|
|
15
|
+
export function createAvatar(options?: MatrixOptions): KaomojiAvatar;
|
|
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 typed characters.
|
|
20
|
+
export function createKaomoji(options: MatrixTone & {identity?: string; shape: MatrixShape; eyes?: EyeStyle; state?: string; progress?: number | null; size?: number; emphasized?: boolean}): MatrixModel;
|
|
21
|
+
export const kaomojiShapes: readonly MatrixShape[];
|
|
22
|
+
export const kaomojiEyes: readonly EyeStyle[];
|
|
23
|
+
export const FACES: Record<ExpressionName, Function>;
|
|
24
|
+
export const SCREENS: Record<string, Function>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// BotUI typed face theme: a face made of text, on a coloured tile.
|
|
2
|
+
//
|
|
3
|
+
// import {createAvatar} from './themes/kaomoji/index.js';
|
|
4
|
+
// const bot = createAvatar({identity: 'research-bot', size: 36});
|
|
5
|
+
// sidebar.append(bot.el);
|
|
6
|
+
// bot.setState('thinking');
|
|
7
|
+
|
|
8
|
+
import {KaomojiAvatar} 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 {KaomojiAvatar, 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 kaomojiShapes} from '../matrix/engine.js';
|
|
22
|
+
export {createKaomoji, kaomojiEyes, FACES, SCREENS} from './engine.js';
|
|
23
|
+
/** The expressions, by name; here each one is a few typed characters (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 KaomojiAvatar(options); }
|
|
28
|
+
|
|
29
|
+
/** This theme, in the form core/registry.js expects. */
|
|
30
|
+
export const theme = {
|
|
31
|
+
name: 'kaomoji', 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,47 @@
|
|
|
1
|
+
# 液面 liquid
|
|
2
|
+
|
|
3
|
+
方块是一只玻璃杯,装着 Bot 颜色的液体。没有眼睛,液面就是脸:开心时两边沿杯壁往上翘,难过时往下垂,生气时沸腾,睡着时又平又低。杯子倾斜时液面保持水平,跳起或转圈时会晃。工作时冒泡,进度就是装了多满。
|
|
4
|
+
|
|
5
|
+
来自 avatar-lab 的草图方向 U(液面),2026-11-28 做成主题。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {createAvatar} from '@kodax-ai/botui/themes/liquid'; // 或相对路径 ./themes/liquid/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/liquid'`,再 `createAvatar({theme: 'liquid', ...})`。自定义元素:同样先加载主题脚本,再写 `<bot-avatar theme="liquid" identity="research-bot"></bot-avatar>`。
|
|
18
|
+
|
|
19
|
+
## 与点阵的关系
|
|
20
|
+
|
|
21
|
+
外形(圆角方、圆、六边形)、颜色、动作、记号、粒子、交互、水印都和 [点阵](../matrix/README.md) 一样,选项和方法也完全相同;同一个 Bot ID 在两个主题里是同一个外形和颜色。不同的是:
|
|
22
|
+
|
|
23
|
+
| 项 | 液面 |
|
|
24
|
+
|---|---|
|
|
25
|
+
| 方块 | 浅色玻璃,液体是 Bot 的颜色,后面一层更深的液面做出厚度 |
|
|
26
|
+
| 眼型 | 没有眼睛;三种眼型变成三种气泡:`dot` 少而大,`bar` 中等,`tall` 多而小 |
|
|
27
|
+
| 眼神(`FACES`) | 21 种都是液面的姿态:弯曲(`happy` 上翘、`sad` 下垂)、波纹高低和碎度、倾斜(`skeptic`、`inspecting`)、沸腾(`angry`)、颜色偏向(`angry` 偏红、`sad` 偏蓝、`shy` / `love` 偏粉) |
|
|
28
|
+
| 状态(`MOODS`) | 液位、气泡多少、波纹速度:工作时冒泡,难过和睡着时液位低,庆祝时满;进度 = 液位;生成时从空慢慢灌满,关机时慢慢流干;思考时气泡绕圈,发送 / 接收时气泡横向流动 |
|
|
29
|
+
| 眨眼 | 液面泛起一圈涟漪 |
|
|
30
|
+
| 背面 | 转到背面仍看得见液体(它是玻璃杯) |
|
|
31
|
+
|
|
32
|
+
小尺寸(24 px 以下)时液面的弯曲不容易看出来,主要靠颜色、液位和气泡区分。
|
|
33
|
+
|
|
34
|
+
裁剪需要 SVG id,每个实例用一个递增计数生成唯一 id。除此之外模型是纯的:不碰 DOM、不用时钟和 `Math.random`。
|
|
35
|
+
|
|
36
|
+
## 纯模型
|
|
37
|
+
|
|
38
|
+
`createLiquid(options)` 与 `createMatrix` 用法相同。节点里有 `defs`、`clipPath` 和一个裁剪用的 `g`,这些节点带 `parent` 指向它所嵌套的节点。
|
|
39
|
+
|
|
40
|
+
## 文件
|
|
41
|
+
|
|
42
|
+
| 文件 | 内容 |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `index.js` | 入口:`createAvatar`、`theme` 和各种表 |
|
|
45
|
+
| `avatar.js` | `LiquidAvatar`:继承点阵的 `MatrixAvatar`,只换模型 |
|
|
46
|
+
| `engine.js` | 液面:姿态表 `FACES`、状态表 `MOODS`、晃动、气泡 |
|
|
47
|
+
| `playground.html` | 试玩页(共用 `../solids/playground.js`) |
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {MatrixAvatar} from '../matrix/avatar.js';
|
|
2
|
+
import {createLiquid} from './engine.js';
|
|
3
|
+
|
|
4
|
+
export {identityFrom} from '../matrix/avatar.js';
|
|
5
|
+
|
|
6
|
+
/** The liquid avatar: the matrix avatar as a glass of the Bot's colour. Options and methods as MatrixAvatar's. */
|
|
7
|
+
export class LiquidAvatar extends MatrixAvatar {
|
|
8
|
+
static className = 'botui-liquid';
|
|
9
|
+
createModel(options) { return createLiquid(options); }
|
|
10
|
+
}
|