@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.
Files changed (53) hide show
  1. package/README.md +140 -113
  2. package/core/identity.js +46 -0
  3. package/{themes/solids → core}/motion.js +114 -114
  4. package/core/registry.js +26 -18
  5. package/docs/usage.md +202 -0
  6. package/element.js +5 -0
  7. package/index.d.ts +2 -0
  8. package/index.js +11 -5
  9. package/package.json +38 -2
  10. package/themes/caret/README.md +43 -0
  11. package/themes/caret/avatar.js +10 -0
  12. package/themes/caret/engine.js +143 -0
  13. package/themes/caret/index.d.ts +24 -0
  14. package/themes/caret/index.js +35 -0
  15. package/themes/critter/README.md +43 -0
  16. package/themes/critter/avatar.js +12 -0
  17. package/themes/critter/engine.js +113 -0
  18. package/themes/critter/index.d.ts +28 -0
  19. package/themes/critter/index.js +35 -0
  20. package/themes/doodle/README.md +43 -0
  21. package/themes/doodle/avatar.js +10 -0
  22. package/themes/doodle/engine.js +149 -0
  23. package/themes/doodle/index.d.ts +24 -0
  24. package/themes/doodle/index.js +36 -0
  25. package/themes/dots/README.md +42 -0
  26. package/themes/dots/avatar.js +15 -0
  27. package/themes/dots/engine.js +179 -0
  28. package/themes/dots/index.d.ts +24 -0
  29. package/themes/dots/index.js +35 -0
  30. package/themes/kaomoji/README.md +42 -0
  31. package/themes/kaomoji/avatar.js +10 -0
  32. package/themes/kaomoji/engine.js +110 -0
  33. package/themes/kaomoji/index.d.ts +24 -0
  34. package/themes/kaomoji/index.js +35 -0
  35. package/themes/liquid/README.md +47 -0
  36. package/themes/liquid/avatar.js +10 -0
  37. package/themes/liquid/engine.js +161 -0
  38. package/themes/liquid/index.d.ts +24 -0
  39. package/themes/liquid/index.js +35 -0
  40. package/themes/matrix/README.md +48 -0
  41. package/themes/matrix/avatar.js +227 -0
  42. package/themes/matrix/engine.js +479 -0
  43. package/themes/matrix/index.d.ts +47 -0
  44. package/themes/matrix/index.js +34 -0
  45. package/themes/orb/README.md +44 -0
  46. package/themes/orb/avatar.js +10 -0
  47. package/themes/orb/engine.js +130 -0
  48. package/themes/orb/index.d.ts +24 -0
  49. package/themes/orb/index.js +36 -0
  50. package/themes/solids/README.md +2 -2
  51. package/themes/solids/avatar.js +561 -579
  52. package/themes/solids/face.js +52 -56
  53. package/themes/solids/index.js +34 -28
@@ -1,56 +1,52 @@
1
- // The face is two eyes, drawn as strokes on the surface of the solid.
2
- //
3
- // An expression is a function (side, style) -> {lines, w, fill, shut}. `side`
4
- // is -1 for the left eye and 1 for the right. `lines` are polylines in eye
5
- // units, centred on the eye, y down. `w` is the stroke width. `fill` closes and
6
- // fills the shape. `shut` marks an expression that is already a closed eye, so
7
- // blinking leaves it alone.
8
-
9
- const TAU = Math.PI * 2;
10
-
11
- /** The neutral eye a Bot is born with. `gap` is half the distance between eyes. */
12
- export const EYE_STYLES = {
13
- bar: {h: 0.2, w: 0.3, gap: 0.4},
14
- dot: {h: 0.03, w: 0.42, gap: 0.42},
15
- tall: {h: 0.27, w: 0.2, gap: 0.34},
16
- };
17
-
18
- const loop = (n, fn) => Array.from({length: n + 1}, (_, i) => fn(i / n * TAU));
19
- const mirror = (side, pts) => pts.map(([x, y]) => [-side * x, y]);
20
- const LID = [[-0.15, 0.06], [0.15, 0.06]];
21
- const bar = (st, tall = 1, wide = 1) => ({lines: [[[0, -st.h * tall], [0, st.h * tall]]], w: st.w * wide});
22
-
23
- export const EXPRESSIONS = {
24
- neutral: (side, st) => bar(st),
25
- wide: (side, st) => bar(st, st.h < 0.1 ? 1 : 1.35, 1.12),
26
- happy: () => ({lines: [[[-0.17, 0.1], [0, -0.12], [0.17, 0.1]]], w: 0.2}),
27
- closed: () => ({lines: [LID], w: 0.2, shut: true}),
28
- sleep: () => ({lines: [[[-0.16, 0], [-0.06, 0.09], [0.06, 0.09], [0.16, 0]]], w: 0.17, shut: true}),
29
- squint: side => ({lines: [mirror(side, [[-0.13, -0.14], [0.1, 0], [-0.13, 0.14]])], w: 0.18}),
30
- sad: side => ({lines: [mirror(side, [[-0.1, 0.16], [0.08, -0.14]])], w: 0.26}),
31
- focus: side => ({lines: [mirror(side, [[-0.11, -0.13], [0.09, 0.13]])], w: 0.28}),
32
- angry: side => ({lines: [mirror(side, [[-0.14, -0.17], [0.11, -0.02]]), [[0, 0.05], [0, 0.19]]], w: 0.19}),
33
- calm: () => ({lines: [[[-0.15, -0.02], [-0.07, 0.07], [0.07, 0.07], [0.15, -0.02]]], w: 0.18}),
34
- sleepy: (side, st) => ({lines: [[[-0.15, -0.04], [0.15, -0.04]], [[0, 0.03], [0, 0.1 + st.h * 0.6]]], w: 0.16}),
35
- shy: (side, st) => bar(st, st.h < 0.1 ? 1 : 0.55, 0.9),
36
- inspecting: (side, st) => (side < 0 ? bar(st, 1.45, 1.15) : {lines: [[[-0.13, 0.03], [0.13, 0.03]]], w: 0.2}),
37
- confused: (side, st) => (side < 0 ? bar(st, 1.2) : {lines: [loop(12, a => [0.09 * Math.cos(a), 0.09 * Math.sin(a)])], w: 0.11}),
38
- wink: (side, st) => (side > 0 ? EXPRESSIONS.happy() : bar(st)),
39
- skeptic: (side, st) => (side > 0 ? {lines: [[[-0.14, -0.02], [0.14, -0.08]]], w: 0.2} : bar(st)),
40
- cross: () => ({lines: [[[-0.13, -0.13], [0.13, 0.13]], [[0.13, -0.13], [-0.13, 0.13]]], w: 0.15}),
41
- surprised: () => ({lines: [loop(14, a => [0.15 * Math.cos(a), 0.17 * Math.sin(a)])], w: 0.12}),
42
- dizzy: side => ({lines: [Array.from({length: 19}, (_, i) => { const a = i * 0.62 * side, r = 0.012 * i; return [r * Math.cos(a), r * Math.sin(a)]; })], w: 0.09}),
43
- love: () => ({lines: [loop(18, a => [0.014 * 16 * Math.sin(a) ** 3, -0.014 * (13 * Math.cos(a) - 5 * Math.cos(2 * a) - 2 * Math.cos(3 * a) - Math.cos(4 * a)) - 0.02])], w: 0.06, fill: true}),
44
- sparkle: () => ({lines: [loop(8, a => { const r = Math.round(a / TAU * 8) % 2 ? 0.07 : 0.26; return [r * Math.sin(a), -r * Math.cos(a)]; })], w: 0.05, fill: true}),
45
- };
46
-
47
- /**
48
- * Points of one eye for an expression, with `open` (0..1) applied. Below a
49
- * quarter open, any expression collapses to a closed lid.
50
- */
51
- export function eyeShape(name, side, style, open) {
52
- const shape = (EXPRESSIONS[name] || EXPRESSIONS.neutral)(side, style);
53
- if (shape.shut) return shape;
54
- if (open < 0.25) return {lines: [LID], w: 0.2};
55
- return {...shape, lines: shape.lines.map(line => line.map(([x, y]) => [x, y * Math.min(open, 1.4)]))};
56
- }
1
+ // The face is two eyes, drawn as strokes on the surface of the solid.
2
+ //
3
+ // An expression is a function (side, style) -> {lines, w, fill, shut}. `side`
4
+ // is -1 for the left eye and 1 for the right. `lines` are polylines in eye
5
+ // units, centred on the eye, y down. `w` is the stroke width. `fill` closes and
6
+ // fills the shape. `shut` marks an expression that is already a closed eye, so
7
+ // blinking leaves it alone.
8
+
9
+ const TAU = Math.PI * 2;
10
+
11
+ // The neutral eye a Bot is born with lives in core/identity.js, shared by every theme.
12
+ export {EYE_STYLES} from '../../core/identity.js';
13
+
14
+ const loop = (n, fn) => Array.from({length: n + 1}, (_, i) => fn(i / n * TAU));
15
+ const mirror = (side, pts) => pts.map(([x, y]) => [-side * x, y]);
16
+ const LID = [[-0.15, 0.06], [0.15, 0.06]];
17
+ const bar = (st, tall = 1, wide = 1) => ({lines: [[[0, -st.h * tall], [0, st.h * tall]]], w: st.w * wide});
18
+
19
+ export const EXPRESSIONS = {
20
+ neutral: (side, st) => bar(st),
21
+ wide: (side, st) => bar(st, st.h < 0.1 ? 1 : 1.35, 1.12),
22
+ happy: () => ({lines: [[[-0.17, 0.1], [0, -0.12], [0.17, 0.1]]], w: 0.2}),
23
+ closed: () => ({lines: [LID], w: 0.2, shut: true}),
24
+ sleep: () => ({lines: [[[-0.16, 0], [-0.06, 0.09], [0.06, 0.09], [0.16, 0]]], w: 0.17, shut: true}),
25
+ squint: side => ({lines: [mirror(side, [[-0.13, -0.14], [0.1, 0], [-0.13, 0.14]])], w: 0.18}),
26
+ sad: side => ({lines: [mirror(side, [[-0.1, 0.16], [0.08, -0.14]])], w: 0.26}),
27
+ focus: side => ({lines: [mirror(side, [[-0.11, -0.13], [0.09, 0.13]])], w: 0.28}),
28
+ angry: side => ({lines: [mirror(side, [[-0.14, -0.17], [0.11, -0.02]]), [[0, 0.05], [0, 0.19]]], w: 0.19}),
29
+ calm: () => ({lines: [[[-0.15, -0.02], [-0.07, 0.07], [0.07, 0.07], [0.15, -0.02]]], w: 0.18}),
30
+ sleepy: (side, st) => ({lines: [[[-0.15, -0.04], [0.15, -0.04]], [[0, 0.03], [0, 0.1 + st.h * 0.6]]], w: 0.16}),
31
+ shy: (side, st) => bar(st, st.h < 0.1 ? 1 : 0.55, 0.9),
32
+ inspecting: (side, st) => (side < 0 ? bar(st, 1.45, 1.15) : {lines: [[[-0.13, 0.03], [0.13, 0.03]]], w: 0.2}),
33
+ confused: (side, st) => (side < 0 ? bar(st, 1.2) : {lines: [loop(12, a => [0.09 * Math.cos(a), 0.09 * Math.sin(a)])], w: 0.11}),
34
+ wink: (side, st) => (side > 0 ? EXPRESSIONS.happy() : bar(st)),
35
+ skeptic: (side, st) => (side > 0 ? {lines: [[[-0.14, -0.02], [0.14, -0.08]]], w: 0.2} : bar(st)),
36
+ cross: () => ({lines: [[[-0.13, -0.13], [0.13, 0.13]], [[0.13, -0.13], [-0.13, 0.13]]], w: 0.15}),
37
+ surprised: () => ({lines: [loop(14, a => [0.15 * Math.cos(a), 0.17 * Math.sin(a)])], w: 0.12}),
38
+ dizzy: side => ({lines: [Array.from({length: 19}, (_, i) => { const a = i * 0.62 * side, r = 0.012 * i; return [r * Math.cos(a), r * Math.sin(a)]; })], w: 0.09}),
39
+ love: () => ({lines: [loop(18, a => [0.014 * 16 * Math.sin(a) ** 3, -0.014 * (13 * Math.cos(a) - 5 * Math.cos(2 * a) - 2 * Math.cos(3 * a) - Math.cos(4 * a)) - 0.02])], w: 0.06, fill: true}),
40
+ sparkle: () => ({lines: [loop(8, a => { const r = Math.round(a / TAU * 8) % 2 ? 0.07 : 0.26; return [r * Math.sin(a), -r * Math.cos(a)]; })], w: 0.05, fill: true}),
41
+ };
42
+
43
+ /**
44
+ * Points of one eye for an expression, with `open` (0..1) applied. Below a
45
+ * quarter open, any expression collapses to a closed lid.
46
+ */
47
+ export function eyeShape(name, side, style, open) {
48
+ const shape = (EXPRESSIONS[name] || EXPRESSIONS.neutral)(side, style);
49
+ if (shape.shut) return shape;
50
+ if (open < 0.25) return {lines: [LID], w: 0.2};
51
+ return {...shape, lines: shape.lines.map(line => line.map(([x, y]) => [x, y * Math.min(open, 1.4)]))};
52
+ }
@@ -1,28 +1,34 @@
1
- // BotUI solids theme: shaded 3D solids with eyes.
2
- //
3
- // import {createAvatar} from './themes/solids/index.js';
4
- // const bot = createAvatar({identity: 'research-bot', size: 36});
5
- // sidebar.append(bot.el);
6
- // bot.setState('thinking');
7
-
8
- import {SolidAvatar, COLORS} from './avatar.js';
9
- import {STATES} from '../../core/states.js';
10
- import {GESTURES} from './motion.js';
11
- import {SHAPES} from './geometry.js';
12
- import {EYE_STYLES, EXPRESSIONS} from './face.js';
13
-
14
- export {SolidAvatar, COLORS, BIRTH_COLORS, HUES, identityFrom} from './avatar.js';
15
- export {STATES, STATE_GROUPS, ALIASES, resolveState} from '../../core/states.js';
16
- export {setAttention} from '../../core/core.js';
17
- export {GESTURES} from './motion.js';
18
- export {SHAPES, GROUPS} from './geometry.js';
19
- export {EYE_STYLES, EXPRESSIONS} from './face.js';
20
-
21
- /** Create an avatar. See SolidAvatar for the options. Append `.el` to the page. */
22
- export function createAvatar(options) { return new SolidAvatar(options); }
23
-
24
- /** This theme, in the form core/registry.js expects. */
25
- export const theme = {
26
- name: 'solids', zh: '立体家族', create: createAvatar,
27
- catalog: () => ({shapes: SHAPES, colors: Object.keys(COLORS), eyes: Object.keys(EYE_STYLES), states: Object.keys(STATES), gestures: Object.keys(GESTURES), expressions: Object.keys(EXPRESSIONS)}),
28
- };
1
+ // BotUI solids theme: shaded 3D solids with eyes.
2
+ //
3
+ // import {createAvatar} from './themes/solids/index.js';
4
+ // const bot = createAvatar({identity: 'research-bot', size: 36});
5
+ // sidebar.append(bot.el);
6
+ // bot.setState('thinking');
7
+
8
+ import {SolidAvatar} 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 {SHAPES} from './geometry.js';
14
+ import {EXPRESSIONS} from './face.js';
15
+
16
+ export {SolidAvatar, identityFrom} from './avatar.js';
17
+ export {COLORS, BIRTH_COLORS, HUES} 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} from './geometry.js';
22
+ export {EYE_STYLES} from '../../core/identity.js';
23
+ export {EXPRESSIONS} from './face.js';
24
+
25
+ /** Create an avatar. See SolidAvatar for the options. Append `.el` to the page. */
26
+ export function createAvatar(options) { return new SolidAvatar(options); }
27
+
28
+ /** This theme, in the form core/registry.js expects. */
29
+ export const theme = {
30
+ name: 'solids', zh: '立体家族', create: createAvatar,
31
+ catalog: () => ({shapes: SHAPES, colors: Object.keys(COLORS), eyes: Object.keys(EYE_STYLES), states: Object.keys(STATES), gestures: Object.keys(GESTURES), expressions: Object.keys(EXPRESSIONS)}),
32
+ };
33
+ // Importing a theme makes it available to createAvatar({theme}) from the package entry.
34
+ registerTheme(theme);