procedural-bot-animations 0.1.0 → 0.2.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.
Files changed (59) hide show
  1. package/README.md +167 -47
  2. package/dist/animation.d.ts +90 -0
  3. package/dist/animation.js +396 -0
  4. package/dist/brain.d.ts +194 -35
  5. package/dist/brain.js +578 -54
  6. package/dist/character.d.ts +123 -0
  7. package/dist/character.js +916 -0
  8. package/dist/characters/berry.d.ts +2 -0
  9. package/dist/characters/berry.js +38 -0
  10. package/dist/characters/flame.d.ts +2 -0
  11. package/dist/characters/flame.js +46 -0
  12. package/dist/delta.d.ts +16 -0
  13. package/dist/delta.js +146 -0
  14. package/dist/examples.d.ts +4 -0
  15. package/dist/examples.js +208 -0
  16. package/dist/focus.d.ts +46 -0
  17. package/dist/focus.js +284 -0
  18. package/dist/gaze.d.ts +41 -53
  19. package/dist/gaze.js +125 -82
  20. package/dist/index.d.ts +18 -11
  21. package/dist/index.js +18 -11
  22. package/dist/interactions.d.ts +30 -0
  23. package/dist/interactions.js +100 -0
  24. package/dist/library.d.ts +18 -0
  25. package/dist/library.js +14 -0
  26. package/dist/moods.d.ts +78 -46
  27. package/dist/moods.js +48 -73
  28. package/dist/motion.d.ts +93 -0
  29. package/dist/motion.js +167 -0
  30. package/dist/mount.d.ts +90 -0
  31. package/dist/mount.js +707 -0
  32. package/dist/parts.d.ts +36 -0
  33. package/dist/parts.js +131 -0
  34. package/dist/reactions.d.ts +184 -44
  35. package/dist/reactions.js +1851 -116
  36. package/dist/rig.d.ts +119 -0
  37. package/dist/rig.js +59 -0
  38. package/dist/scroll-traveler.js +1 -1
  39. package/dist/ticker.d.ts +10 -0
  40. package/dist/ticker.js +42 -0
  41. package/dist/transformations.d.ts +21 -0
  42. package/dist/transformations.js +306 -0
  43. package/package.json +7 -11
  44. package/dist/bind.d.ts +0 -27
  45. package/dist/bind.js +0 -42
  46. package/dist/blink.d.ts +0 -25
  47. package/dist/blink.js +0 -48
  48. package/dist/fake3d.d.ts +0 -20
  49. package/dist/fake3d.js +0 -24
  50. package/dist/noise.d.ts +0 -16
  51. package/dist/noise.js +0 -17
  52. package/dist/render.d.ts +0 -29
  53. package/dist/render.js +0 -97
  54. package/dist/rng.d.ts +0 -10
  55. package/dist/rng.js +0 -18
  56. package/dist/spring.d.ts +0 -21
  57. package/dist/spring.js +0 -33
  58. package/dist/types.d.ts +0 -63
  59. package/dist/types.js +0 -46
@@ -0,0 +1,2 @@
1
+ import type { Rig } from "../rig.js";
2
+ export declare const RIG_BERRY: Rig;
@@ -0,0 +1,38 @@
1
+ export const RIG_BERRY = {
2
+ id: "berry",
3
+ body: "M463,408 C380,434 320,502 320,596 C320,722 440,862 540,926 C580,951 606,960 628,960 C652,960 678,951 718,926 C818,862 934,722 934,596 C934,502 876,434 792,408 C760,398 700,392 628,392 C560,392 500,398 463,408 Z",
4
+ appendages: [
5
+ {
6
+ role: "C",
7
+ path: "M563,342 C563,292 594,252 627,252 C660,252 692,292 692,342 L692,430 L563,430 Z",
8
+ pivot: { x: 627, y: 425 },
9
+ tip: { x: 627, y: 252 },
10
+ },
11
+ {
12
+ role: "L",
13
+ path: "M463,408 C437,386 421,360 425,342 C429,320 470,309 512,316 C536,321 553,331 565,342 L565,430 L480,430 Z",
14
+ pivot: { x: 565, y: 425 },
15
+ tip: { x: 425, y: 342 },
16
+ },
17
+ {
18
+ role: "R",
19
+ path: "M792,408 C818,386 834,360 830,342 C826,320 785,309 743,316 C719,321 702,331 690,342 L690,430 L775,430 Z",
20
+ pivot: { x: 690, y: 425 },
21
+ tip: { x: 830, y: 342 },
22
+ },
23
+ ],
24
+ eyes: { left: { x: 513, y: 600 }, right: { x: 691, y: 600 } },
25
+ eyeStyles: {
26
+ classic: { w: 80, h: 160, tilt: 0, dx: 0, dy: 0 },
27
+ pumpy: { w: 82, h: 124, tilt: 0, dx: 6, dy: 14 },
28
+ big: { w: 100, h: 176, tilt: 14, dx: 4, dy: 26 },
29
+ },
30
+ ground: { x: 627, y: 960 },
31
+ center: { x: 628, y: 660 },
32
+ shadow: { x: 628, y: 990, rx: 250, ry: 22 },
33
+ accessory: { x: 880, y: 300 },
34
+ anchor: { x: 627, y: 660 },
35
+ baseHeight: 535,
36
+ idleAppendage: { amp: 1, freq: 1 },
37
+ flicker: 0,
38
+ };
@@ -0,0 +1,2 @@
1
+ import type { Rig } from "../rig.js";
2
+ export declare const RIG_FLAME: Rig;
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Flame: the outline generated with the open-bot-avatar skill (100×100 box,
3
+ * scaled 9.5× to our system), cut into pieces to gain physics: a round body,
4
+ * the main tongue (C), the left shoulder tongue (L) and, only on the 1-day
5
+ * ember, a third one on the right (R). The tongue bases go inside the body, so
6
+ * bending the tip never opens a gap.
7
+ */
8
+ export const RIG_FLAME = {
9
+ id: "flame",
10
+ body: "M627,960 C456,960 323,846 323,694 C323,608 352,561 399,528 C466,485 560,490 646,490 C741,490 817,490 874,528 C922,570 950,628 950,694 C950,846 817,960 627,960 Z",
11
+ appendages: [
12
+ {
13
+ role: "C",
14
+ path: "M489,570 C489,456 542,352 622,257 C636,240 657,242 667,261 C703,333 755,376 817,433 C874,485 912,542 922,599 L741,675 L532,675 Z",
15
+ pivot: { x: 694, y: 580 },
16
+ tip: { x: 644, y: 248 },
17
+ },
18
+ {
19
+ role: "L",
20
+ path: "M352,599 C352,552 380,509 408,480 C423,461 442,466 446,490 C454,523 470,552 499,575 L494,656 L370,656 Z",
21
+ pivot: { x: 428, y: 580 },
22
+ tip: { x: 430, y: 469 },
23
+ },
24
+ {
25
+ role: "R",
26
+ path: "M826,570 C846,523 874,490 898,466 C912,452 926,461 926,480 C926,514 936,552 945,599 L912,666 L836,656 Z",
27
+ pivot: { x: 893, y: 590 },
28
+ tip: { x: 917, y: 461 },
29
+ },
30
+ ],
31
+ eyes: { left: { x: 560, y: 722 }, right: { x: 712, y: 722 } },
32
+ eyeStyles: {
33
+ classic: { w: 80, h: 140, tilt: 0, dx: 0, dy: 0 },
34
+ pumpy: { w: 86, h: 112, tilt: 0, dx: 2, dy: 8 },
35
+ big: { w: 100, h: 156, tilt: 14, dx: -4, dy: 6 },
36
+ },
37
+ ground: { x: 627, y: 960 },
38
+ center: { x: 636, y: 694 },
39
+ shadow: { x: 627, y: 985, rx: 280, ry: 22 },
40
+ accessory: { x: 800, y: 330 },
41
+ anchor: { x: 627, y: 660 },
42
+ baseHeight: 380,
43
+ idleAppendage: { amp: 2.4, freq: 2.6 },
44
+ flicker: 1,
45
+ core: "M627,922 C532,922 466,860 466,780 C466,704 508,656 551,613 C560,656 584,680 613,689 C608,618 641,552 689,499 C732,570 788,637 788,760 C788,856 722,922 627,922 Z",
46
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What moods, activities and reactions add on top of the base layer. Everything
3
+ * is an offset from neutral: 0 in every field is the character at rest.
4
+ *
5
+ * Units: positions in drawing px (viewBox), angles in degrees, scales as an
6
+ * increment over 1 (`eyeSy: -0.5` leaves the eye at half its height).
7
+ */
8
+ export declare const FIELDS: readonly ["rootY", "opacity", "bodyRotate", "centerRotate", "bodySx", "bodySy", "scale", "partC", "partL", "partR", "eyeX", "eyeY", "eyeSx", "eyeSy", "lidTop", "lidBottom", "lidAngle", "closeLeft", "closeRight", "turn", "happy", "happyLeft", "happyRight", "shadow", "holdGaze", "partAmp", "lamp", "exclaim", "question", "ellipsis", "zzz", "rays", "sparks", "gray", "core", "embers", "smoke", "morph", "round", "retract", "eyesVanish", "swap", "bubbleR", "bubbleHole", "bubbleArc", "bubbleX", "bubbleY", "dotsDist", "dotsBounce", "checkDraw", "codeDraw", "orbitOpen", "objScale", "objRotate"];
9
+ export type DeltaField = (typeof FIELDS)[number];
10
+ export type Delta = Record<DeltaField, number>;
11
+ export type PartialDelta = Partial<Delta>;
12
+ export declare const zeroDelta: () => Delta;
13
+ /** `acc += d * weight`, field by field. Mutates `acc` in place. */
14
+ export declare function addDelta(acc: Delta, d: PartialDelta, weight?: number): Delta;
15
+ /** Fields that are movement through space. With reduced motion, they are left out. */
16
+ export declare const MOTION_FIELDS: readonly DeltaField[];
package/dist/delta.js ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * What moods, activities and reactions add on top of the base layer. Everything
3
+ * is an offset from neutral: 0 in every field is the character at rest.
4
+ *
5
+ * Units: positions in drawing px (viewBox), angles in degrees, scales as an
6
+ * increment over 1 (`eyeSy: -0.5` leaves the eye at half its height).
7
+ */
8
+ export const FIELDS = [
9
+ /** Raises (negative) or lowers the whole character; the shadow stays on the ground. */
10
+ "rootY",
11
+ /** Added to the opacity (−1 disappears). */
12
+ "opacity",
13
+ /** Rotation around the ground (leaning). */
14
+ "bodyRotate",
15
+ /** Rotation around the body center (somersault). */
16
+ "centerRotate",
17
+ "bodySx",
18
+ "bodySy",
19
+ /** Uniform scale of the character, from the ground (−1 vanishes, to become an object). */
20
+ "scale",
21
+ "partC",
22
+ /** Left appendage: positive raises it. */
23
+ "partL",
24
+ /** Right appendage: negative raises it (mirrored). */
25
+ "partR",
26
+ "eyeX",
27
+ "eyeY",
28
+ "eyeSx",
29
+ "eyeSy",
30
+ /** Top eyelid (0 open, 1 closes the eye from the top down). */
31
+ "lidTop",
32
+ /** Bottom eyelid (0 open, 1 closes from the bottom up): a smiling look. */
33
+ "lidBottom",
34
+ /** Eyelid tilt: positive slopes down toward the inside (angry, suspicious), negative toward the outside (worried). */
35
+ "lidAngle",
36
+ /** Closes just one eye (a wink). 0 to 1. */
37
+ "closeLeft",
38
+ "closeRight",
39
+ /** Fake 3D turn: −1 to 1 turns the face; up to ±1.6 is a profile. */
40
+ "turn",
41
+ /** Arc-shaped eyes (^): both of them, or just one. */
42
+ "happy",
43
+ "happyLeft",
44
+ "happyRight",
45
+ "shadow",
46
+ /** How much the reaction takes over the gaze (0 follows the target, 1 only the reaction rules). */
47
+ "holdGaze",
48
+ /** Multiplies the amplitude of the appendage sway (−1 freezes it). */
49
+ "partAmp",
50
+ /* accessories (0 hidden, 1 visible) */
51
+ "lamp",
52
+ "exclaim",
53
+ "question",
54
+ "ellipsis",
55
+ "zzz",
56
+ "rays",
57
+ /** Progress of the sparks (0 to 1); 0 when there are none. */
58
+ "sparks",
59
+ /* flame only */
60
+ /** Loses its color: 0 normal, 1 gray (put out, at risk). */
61
+ "gray",
62
+ /** Lit yellow core (0 to 1), on top of the fixed one of the 1000-day streak. */
63
+ "core",
64
+ /** Embers rising from the tongues (intensity, 0 to 1). */
65
+ "embers",
66
+ /** Smoke coming off the tip (intensity, 0 to 1). */
67
+ "smoke",
68
+ /*
69
+ * Seamless transformation (Pumpy's grammar). The body becomes a perfect
70
+ * circle around the anchor, shrinks to the size of the bubble and, on that
71
+ * frame, swaps with it: same color, same center, same radius. The bubble
72
+ * turns into dots, a ring, a check or </> through continuous geometry, and
73
+ * the way back is the same in reverse.
74
+ */
75
+ /** 0 to 1: scaling becomes relative to the anchor and the idle goes quiet. */
76
+ "morph",
77
+ /** 0 to 1: the silhouette becomes a circle. */
78
+ "round",
79
+ /** 0 to 1: appendages retract into the body (negative: they pop out bigger). */
80
+ "retract",
81
+ /** 0 to 1: the eyes shrink until they vanish. */
82
+ "eyesVanish",
83
+ /** ≥ 0.5: shows the object in place of the body. */
84
+ "swap",
85
+ /** Outer radius of the bubble (px). With hole 0, it is a disc. */
86
+ "bubbleR",
87
+ /** Radius of the hole: with a hole, the bubble becomes a ring. */
88
+ "bubbleHole",
89
+ /** Fraction of the ring that is missing (0 = whole ring). */
90
+ "bubbleArc",
91
+ "bubbleX",
92
+ "bubbleY",
93
+ /** Distance from the side dots to the bubble (px); they are born underneath it. */
94
+ "dotsDist",
95
+ /** How much the dots bounce (0 to 1). */
96
+ "dotsBounce",
97
+ /** How much of the check has been drawn, from the bubble. */
98
+ "checkDraw",
99
+ /** How much of the </> has been drawn, from the three dots. */
100
+ "codeDraw",
101
+ /** 0 to 1: the orbit dots come out from under the bubble up to the full radius. */
102
+ "orbitOpen",
103
+ /** Added to the object's scale (pulse). */
104
+ "objScale",
105
+ /** Rotation of the object, in degrees. */
106
+ "objRotate",
107
+ ];
108
+ export const zeroDelta = () => Object.fromEntries(FIELDS.map((c) => [c, 0]));
109
+ /** `acc += d * weight`, field by field. Mutates `acc` in place. */
110
+ export function addDelta(acc, d, weight = 1) {
111
+ for (const k in d) {
112
+ const key = k;
113
+ acc[key] += (d[key] ?? 0) * weight;
114
+ }
115
+ return acc;
116
+ }
117
+ /** Fields that are movement through space. With reduced motion, they are left out. */
118
+ export const MOTION_FIELDS = [
119
+ "rootY",
120
+ "bodyRotate",
121
+ "centerRotate",
122
+ "bodySx",
123
+ "bodySy",
124
+ "scale",
125
+ "turn",
126
+ "sparks",
127
+ "embers",
128
+ "smoke",
129
+ "morph",
130
+ "round",
131
+ "retract",
132
+ "eyesVanish",
133
+ "swap",
134
+ "bubbleR",
135
+ "bubbleHole",
136
+ "bubbleArc",
137
+ "bubbleX",
138
+ "bubbleY",
139
+ "dotsDist",
140
+ "dotsBounce",
141
+ "checkDraw",
142
+ "codeDraw",
143
+ "orbitOpen",
144
+ "objScale",
145
+ "objRotate",
146
+ ];
@@ -0,0 +1,4 @@
1
+ import type { AnimationDefinition } from "./animation.js";
2
+ import type { CharacterDefinition } from "./character.js";
3
+ export declare const EXAMPLE_CHARACTERS: CharacterDefinition[];
4
+ export declare const EXAMPLE_ANIMATIONS: AnimationDefinition[];
@@ -0,0 +1,208 @@
1
+ /*
2
+ * Original example characters and animations, written as plain data in the
3
+ * two JSON formats (see docs/character-format.md and docs/animation-format.md).
4
+ * Every entry validates with zero warnings.
5
+ */
6
+ export const EXAMPLE_CHARACTERS = [
7
+ {
8
+ // A soft rounded blob, wider than tall. No parts.
9
+ version: 1,
10
+ id: "blob",
11
+ name: "Blob",
12
+ body: {
13
+ path: "M50 24 C70 24 86 38 86 58 C86 78 74 90 50 90 C26 90 14 78 14 58 C14 38 30 24 50 24 Z",
14
+ },
15
+ eyes: { x: 50, y: 54, spacing: 21, scale: 1.55 },
16
+ rig: { color: "#ff8fb1" },
17
+ },
18
+ {
19
+ // A dome with three scallops along the bottom. No parts.
20
+ version: 1,
21
+ id: "ghost",
22
+ name: "Ghost",
23
+ body: {
24
+ path: "M20 50 C20 28 33 14 50 14 C67 14 80 28 80 50 L80 82 C80 90 60 90 60 82 C60 90 40 90 40 82 C40 90 20 90 20 82 L20 50 Z",
25
+ },
26
+ eyes: { x: 50, y: 43, spacing: 18, scale: 1.7 },
27
+ rig: { color: "#8b7fe8" },
28
+ },
29
+ {
30
+ // A round body with three leaves on top. Each leaf base sits inside the body, so bending never opens a gap.
31
+ version: 1,
32
+ id: "sprout",
33
+ name: "Sprout",
34
+ body: {
35
+ path: "M50 36 C70 36 82 50 82 65 C82 80 70 90 50 90 C30 90 18 80 18 65 C18 50 30 36 50 36 Z",
36
+ },
37
+ eyes: { x: 50, y: 64, spacing: 19, scale: 1.3 },
38
+ rig: {
39
+ parts: [
40
+ {
41
+ role: "C",
42
+ path: "M44 46 C42 32 46 18 50 10 C54 18 58 32 56 46 Z",
43
+ pivot: [50, 43],
44
+ tip: [50, 10],
45
+ },
46
+ {
47
+ role: "L",
48
+ path: "M34 46 C32 36 26 28 18 24 C26 20 36 22 42 30 C45 34 46 40 46 46 Z",
49
+ pivot: [40, 44],
50
+ tip: [18, 24],
51
+ },
52
+ {
53
+ role: "R",
54
+ path: "M66 46 C68 36 74 28 82 24 C74 20 64 22 58 30 C55 34 54 40 54 46 Z",
55
+ pivot: [60, 44],
56
+ tip: [82, 24],
57
+ },
58
+ ],
59
+ color: "#4fae6a",
60
+ },
61
+ },
62
+ {
63
+ // A rounded square with two antennas (L and R).
64
+ version: 1,
65
+ id: "robot",
66
+ name: "Robot",
67
+ body: {
68
+ path: "M30 30 L70 30 C75.5 30 80 34.5 80 40 L80 80 C80 85.5 75.5 90 70 90 L30 90 C24.5 90 20 85.5 20 80 L20 40 C20 34.5 24.5 30 30 30 Z",
69
+ },
70
+ eyes: { x: 50, y: 59, spacing: 18, scale: 1.45 },
71
+ rig: {
72
+ parts: [
73
+ {
74
+ role: "L",
75
+ path: "M29 38 C27 31 24.5 24 22.8 17.5 C19 16 18.5 7.5 24 7.5 C29.5 7.5 29.5 16 26.2 17.5 C28 24 31 31 33 38 Z",
76
+ pivot: [31, 36],
77
+ tip: [24, 8],
78
+ },
79
+ {
80
+ role: "R",
81
+ path: "M71 38 C73 31 75.5 24 77.2 17.5 C81 16 81.5 7.5 76 7.5 C70.5 7.5 70.5 16 73.8 17.5 C72 24 69 31 67 38 Z",
82
+ pivot: [69, 36],
83
+ tip: [76, 8],
84
+ },
85
+ ],
86
+ idle: { amp: 0.6, freq: 1.4 },
87
+ color: "#6c8cff",
88
+ },
89
+ },
90
+ ];
91
+ export const EXAMPLE_ANIMATIONS = [
92
+ {
93
+ // Yes: anticipation up, then two dips that get smaller. Volume is kept (bodySx = -bodySy).
94
+ version: 1,
95
+ kind: "reaction",
96
+ id: "nod",
97
+ name: "Nod",
98
+ duration: 0.9,
99
+ tracks: {
100
+ bodySy: [[0, 0], [0.12, 0.04], [0.3, -0.12], [0.48, 0.02], [0.66, -0.09], [0.84, 0.01], [1, 0]],
101
+ bodySx: [[0, 0], [0.12, -0.04], [0.3, 0.12], [0.48, -0.02], [0.66, 0.09], [0.84, -0.01], [1, 0]],
102
+ eyeY: [[0, 0], [0.12, -3], [0.3, 10], [0.48, -2], [0.66, 8], [0.84, 0], [1, 0]],
103
+ partC: [[0, 0], [0.12, -6], [0.3, 14], [0.48, -5], [0.66, 9], [0.84, -2], [1, 0]],
104
+ partL: [[0, 0], [0.3, -8], [0.48, 3], [0.66, -5], [1, 0]],
105
+ partR: [[0, 0], [0.3, 8], [0.48, -3], [0.66, 5], [1, 0]],
106
+ lidBottom: [[0, 0], [0.25, 0.2], [0.8, 0.2], [1, 0]],
107
+ holdGaze: [[0, 0], [0.06, 1], [0.5, 1], [0.68, 0], [1, 0]],
108
+ },
109
+ },
110
+ {
111
+ // No: the face turns side to side with shrinking swings and a slight frown.
112
+ version: 1,
113
+ kind: "reaction",
114
+ id: "shake",
115
+ name: "Shake",
116
+ duration: 1,
117
+ tracks: {
118
+ turn: [[0, 0], [0.12, 0.35], [0.3, -0.45], [0.48, 0.4], [0.66, -0.3], [0.82, 0.12], [1, 0]],
119
+ eyeX: [[0, 0], [0.12, 8], [0.3, -12], [0.48, 11], [0.66, -8], [0.82, 3], [1, 0]],
120
+ bodyRotate: [[0, 0], [0.12, 2], [0.3, -3], [0.48, 3], [0.66, -2], [0.82, 1], [1, 0]],
121
+ lidTop: [[0, 0], [0.2, 0.15], [0.8, 0.15], [1, 0]],
122
+ lidAngle: [[0, 0], [0.2, 10], [0.8, 10], [1, 0]],
123
+ partL: [[0, 0], [0.3, -8], [0.5, 6], [0.7, -5], [1, 0]],
124
+ partR: [[0, 0], [0.3, 8], [0.5, -6], [0.7, 5], [1, 0]],
125
+ holdGaze: [[0, 0], [0.06, 1], [0.5, 1], [0.68, 0], [1, 0]],
126
+ },
127
+ },
128
+ {
129
+ // Squat (anticipation), a tall stretch with the parts spreading, then a settle with overshoot.
130
+ version: 1,
131
+ kind: "reaction",
132
+ id: "stretch",
133
+ name: "Stretch",
134
+ duration: 1.5,
135
+ tracks: {
136
+ bodySy: [[0, 0], [0.18, -0.14], [0.42, 0.22], [0.58, 0.2], [0.72, -0.05], [0.86, 0.02], [1, 0]],
137
+ bodySx: [[0, 0], [0.18, 0.14], [0.42, -0.22], [0.58, -0.2], [0.72, 0.05], [0.86, -0.02], [1, 0]],
138
+ rootY: [[0, 0], [0.18, 0], [0.42, -18], [0.58, -14], [0.72, 0], [1, 0]],
139
+ partL: [[0, 0], [0.18, -12], [0.42, 30], [0.58, 26], [0.72, -8], [0.86, 3], [1, 0]],
140
+ partR: [[0, 0], [0.18, 12], [0.42, -30], [0.58, -26], [0.72, 8], [0.86, -3], [1, 0]],
141
+ partC: [[0, 0], [0.18, -8], [0.42, 12], [0.58, 10], [0.72, -6], [0.86, 2], [1, 0]],
142
+ lidTop: [[0, 0], [0.18, 0.3], [0.42, 0], [1, 0]],
143
+ lidBottom: [[0, 0], [0.42, 0.3], [0.62, 0.3], [0.86, 0], [1, 0]],
144
+ eyeY: [[0, 0], [0.42, -8], [0.62, -8], [0.86, 0], [1, 0]],
145
+ shadow: [[0, 0], [0.42, -0.15], [0.58, -0.12], [0.72, 0], [1, 0]],
146
+ holdGaze: [[0, 0], [0.08, 1], [0.55, 1], [0.7, 0], [1, 0]],
147
+ },
148
+ },
149
+ {
150
+ // A suspicious glance to the side: turn, squint, a small lean, then back.
151
+ version: 1,
152
+ kind: "reaction",
153
+ id: "sideEye",
154
+ name: "Side eye",
155
+ duration: 1.6,
156
+ tracks: {
157
+ turn: [[0, 0], [0.2, -0.5], [0.7, -0.5], [0.92, 0], [1, 0]],
158
+ eyeX: [[0, 0], [0.2, -26], [0.7, -26], [0.92, 0], [1, 0]],
159
+ lidTop: [[0, 0], [0.2, 0.4], [0.7, 0.4], [0.92, 0], [1, 0]],
160
+ lidBottom: [[0, 0], [0.2, 0.12], [0.7, 0.12], [0.92, 0], [1, 0]],
161
+ lidAngle: [[0, 0], [0.2, 16], [0.7, 16], [0.92, 0], [1, 0]],
162
+ bodyRotate: [[0, 0], [0.2, -3], [0.7, -3], [0.92, 0], [1, 0]],
163
+ bodySy: [[0, 0], [0.1, 0.02], [0.22, -0.03], [0.7, -0.03], [0.92, 0], [1, 0]],
164
+ bodySx: [[0, 0], [0.1, -0.02], [0.22, 0.03], [0.7, 0.03], [0.92, 0], [1, 0]],
165
+ partL: [[0, 0], [0.2, -10], [0.7, -10], [0.92, 0], [1, 0]],
166
+ partR: [[0, 0], [0.2, 10], [0.7, 10], [0.92, 0], [1, 0]],
167
+ holdGaze: [[0, 0], [0.08, 1], [0.6, 1], [0.75, 0], [1, 0]],
168
+ },
169
+ },
170
+ {
171
+ // A loop: swaying side to side while bobbing twice, with a contented smile.
172
+ version: 1,
173
+ kind: "activity",
174
+ id: "humming",
175
+ name: "Humming",
176
+ period: 3.2,
177
+ tracks: {
178
+ bodyRotate: [[0, 0], [0.25, 3], [0.5, 0], [0.75, -3], [1, 0]],
179
+ bodySy: [[0, -0.015], [0.25, 0.02], [0.5, -0.015], [0.75, 0.02], [1, -0.015]],
180
+ bodySx: [[0, 0.015], [0.25, -0.02], [0.5, 0.015], [0.75, -0.02], [1, 0.015]],
181
+ partL: [[0, 0], [0.25, 8], [0.5, 0], [0.75, -4], [1, 0]],
182
+ partR: [[0, 0], [0.25, -4], [0.5, 0], [0.75, 8], [1, 0]],
183
+ partC: [[0, 0], [0.25, 6], [0.5, 0], [0.75, -6], [1, 0]],
184
+ eyeY: [[0, 0], [0.25, -3], [0.5, 0], [0.75, -3], [1, 0]],
185
+ lidBottom: [[0, 0.25], [1, 0.25]],
186
+ },
187
+ },
188
+ {
189
+ // A mood: heavy-lidded, looking up and away, parts relaxed.
190
+ version: 1,
191
+ kind: "mood",
192
+ id: "dreamy",
193
+ name: "Dreamy",
194
+ pose: {
195
+ lidTop: 0.3,
196
+ lidBottom: 0.1,
197
+ lidAngle: -8,
198
+ eyeY: -10,
199
+ turn: 0.2,
200
+ bodyRotate: -3,
201
+ partL: 8,
202
+ partR: -8,
203
+ partC: 5,
204
+ partAmp: -0.4,
205
+ rootY: -4,
206
+ },
207
+ },
208
+ ];
@@ -0,0 +1,46 @@
1
+ import type { Rng } from "./motion.js";
2
+ export declare const ANCHOR_ATTRIBUTE = "data-bot-focus";
3
+ type Point = {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ type Kind = "focus" | "key" | "click" | "scroll" | "anchor";
8
+ export type GazeMode = "free" | "focus";
9
+ export type Reason = Kind | "cursor" | "screen" | "text" | "element" | "wander";
10
+ export type Decision = {
11
+ /** Window px, `'screen'` (look at whoever is in front) or `null` (the brain wanders). */
12
+ point: Point | "screen" | null;
13
+ /** Attention impulse of this frame. */
14
+ interest: number;
15
+ /** Seconds to glide to the target; 0 = saccade. */
16
+ glide: number;
17
+ /** In focus (something held the gaze) or wandering. */
18
+ mode: GazeMode;
19
+ reason: Reason | null;
20
+ };
21
+ /** Starts observing the page; returns the function that stops it. */
22
+ export declare function observePage(): () => void;
23
+ /** Free/focus gaze state of one character. */
24
+ export type FocusState = {
25
+ point: Point | "screen" | null;
26
+ /** Followed element (the position is read every frame: it may move). */
27
+ el: Element | null;
28
+ until: number;
29
+ seen: number;
30
+ nextCursor: number;
31
+ glide: number;
32
+ mode: GazeMode;
33
+ reason: Reason | null;
34
+ anchorIndex: number;
35
+ };
36
+ export declare const newFocusState: () => FocusState;
37
+ /**
38
+ * Where to look right now, in the requested mode. Call every frame.
39
+ */
40
+ export declare function decideGaze(f: FocusState, now: number, rng: Rng, myRect: DOMRect, cursor: {
41
+ x: number;
42
+ y: number;
43
+ last: number;
44
+ inside: boolean;
45
+ }, mode: GazeMode): Decision;
46
+ export {};