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
package/dist/rig.d.ts ADDED
@@ -0,0 +1,119 @@
1
+ export type Point = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ /** Role of the appendage: the middle one (C), the left one (L) and the right one (R). */
6
+ export type Role = "C" | "L" | "R";
7
+ /** A leaf or a flame tongue: a piece attached to the body that rotates and bends. */
8
+ export type Appendage = {
9
+ role: Role;
10
+ path: string;
11
+ pivot: Point;
12
+ tip: Point;
13
+ };
14
+ export type EyeStyle = "classic" | "pumpy" | "big";
15
+ export declare const EYE_STYLES: EyeStyle[];
16
+ /**
17
+ * Resting shape of the eye: a `w × h` pill (fully rounded corners), tilted
18
+ * `tilt` degrees (the same direction on both eyes, like italics) and shifted
19
+ * `dx`/`dy` from the base point. `dx` is mirrored: positive brings the eyes closer.
20
+ */
21
+ export type EyeShape = {
22
+ w: number;
23
+ h: number;
24
+ tilt: number;
25
+ dx: number;
26
+ dy: number;
27
+ };
28
+ export type Rig = {
29
+ id: string;
30
+ body: string;
31
+ appendages: Appendage[];
32
+ eyes: {
33
+ left: Point;
34
+ right: Point;
35
+ };
36
+ eyeStyles: Record<EyeStyle, EyeShape>;
37
+ ground: Point;
38
+ center: Point;
39
+ shadow: {
40
+ x: number;
41
+ y: number;
42
+ rx: number;
43
+ ry: number;
44
+ };
45
+ accessory: Point;
46
+ /**
47
+ * Center of the transformations: the body becomes a circle of radius
48
+ * `ROUND_RADIUS` around it (resting on the ground) and objects are born there.
49
+ */
50
+ anchor: Point;
51
+ /** Distance from the ground to the base of the appendages (for the tip physics). */
52
+ baseHeight: number;
53
+ /** Idle sway of the appendages: multiplies amplitude and frequency. */
54
+ idleAppendage: {
55
+ amp: number;
56
+ freq: number;
57
+ };
58
+ /** 0 = firm body; 1 = the body flickers like fire. */
59
+ flicker: number;
60
+ /** Optional light core (the 1000-day flame). */
61
+ core?: string;
62
+ };
63
+ export declare const VIEWBOX: {
64
+ readonly x: 190;
65
+ readonly y: 60;
66
+ readonly w: 880;
67
+ readonly h: 990;
68
+ };
69
+ export declare const VIEWBOX_ATTR: string;
70
+ export declare const ASPECT: number;
71
+ /** Happy arc-shaped eye (^), for an eye of width 80 centered at (0,0). */
72
+ export declare const HAPPY_EYE_PATH = "M-50,26 C-36,-38 36,-38 50,26 C34,4 -34,4 -50,26 Z";
73
+ /** Sparks of a hit: 8 directions, alternating distance and color. */
74
+ export declare const SPARKS: {
75
+ dx: number;
76
+ dy: number;
77
+ alt: boolean;
78
+ }[];
79
+ export declare const SPARK_PATH = "M0,-20 L7,-7 L20,0 L7,7 L0,20 L-7,7 L-20,0 L-7,-7Z";
80
+ /** Radius of the circle the body turns into (ground at y = 960, anchor at 660). */
81
+ export declare const ROUND_RADIUS = 300;
82
+ /** Radius of the bubble the body shrinks into and objects are born from. */
83
+ export declare const DOT_R = 36;
84
+ /** Scale of the round body when its radius is exactly the bubble's. */
85
+ export declare const DOT_SCALE: number;
86
+ /** Loading ring: outer radius and hole (46 px stroke). */
87
+ export declare const RING: {
88
+ readonly R: 133;
89
+ readonly hole: 87;
90
+ };
91
+ /**
92
+ * Check mark, relative to the anchor. The stroke is as wide as the bubble, so
93
+ * the start of the round-capped check is the bubble itself.
94
+ */
95
+ export declare const CHECK: {
96
+ readonly start: {
97
+ readonly x: -130;
98
+ readonly y: -10;
99
+ };
100
+ readonly path: "M-130,-10 L-45,75 L135,-105";
101
+ readonly length: number;
102
+ readonly width: number;
103
+ };
104
+ /**
105
+ * `</>`: each stroke is born at one of the three dots (the vertex of the <,
106
+ * the middle of the slash, the vertex of the >). Width 50 = the dots' diameter
107
+ * at that moment.
108
+ */
109
+ export declare const CODE: {
110
+ readonly dist: 170;
111
+ readonly radius: 25;
112
+ readonly strokes: readonly ["M-170,0 L-95,-75", "M-170,0 L-95,75", "M0,0 L38,-105", "M0,0 L-38,105", "M170,0 L95,-75", "M170,0 L95,75"];
113
+ readonly lengths: readonly [106.1, 106.1, 111.7, 111.7, 106.1, 106.1];
114
+ };
115
+ /** Energy orbit: full radius and radius of each dot. */
116
+ export declare const ORBIT: {
117
+ readonly R: 300;
118
+ readonly radii: readonly [26, 18, 26, 18, 26, 18, 26, 18];
119
+ };
package/dist/rig.js ADDED
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Rigs: the geometry of each character, separate from the motion engine. All
3
+ * characters share one coordinate system (ground at y = 960, center at
4
+ * x ≈ 627) and one viewBox, so reactions, accessories and objects work for
5
+ * every one of them.
6
+ */
7
+ export const EYE_STYLES = ["classic", "pumpy", "big"];
8
+ export const VIEWBOX = { x: 190, y: 60, w: 880, h: 990 };
9
+ export const VIEWBOX_ATTR = `${VIEWBOX.x} ${VIEWBOX.y} ${VIEWBOX.w} ${VIEWBOX.h}`;
10
+ export const ASPECT = VIEWBOX.h / VIEWBOX.w;
11
+ /** Happy arc-shaped eye (^), for an eye of width 80 centered at (0,0). */
12
+ export const HAPPY_EYE_PATH = "M-50,26 C-36,-38 36,-38 50,26 C34,4 -34,4 -50,26 Z";
13
+ /* ---------- effects ---------- */
14
+ /** Sparks of a hit: 8 directions, alternating distance and color. */
15
+ export const SPARKS = Array.from({ length: 8 }, (_, i) => {
16
+ const a = (i * Math.PI) / 4 + Math.PI / 8;
17
+ const r = i % 2 ? 300 : 370;
18
+ return { dx: Math.round(Math.cos(a) * r), dy: Math.round(Math.sin(a) * r), alt: i % 2 === 1 };
19
+ });
20
+ export const SPARK_PATH = "M0,-20 L7,-7 L20,0 L7,7 L0,20 L-7,7 L-20,0 L-7,-7Z";
21
+ /* ---------- transformations ---------- */
22
+ /** Radius of the circle the body turns into (ground at y = 960, anchor at 660). */
23
+ export const ROUND_RADIUS = 300;
24
+ /** Radius of the bubble the body shrinks into and objects are born from. */
25
+ export const DOT_R = 36;
26
+ /** Scale of the round body when its radius is exactly the bubble's. */
27
+ export const DOT_SCALE = DOT_R / ROUND_RADIUS;
28
+ /** Loading ring: outer radius and hole (46 px stroke). */
29
+ export const RING = { R: 133, hole: 87 };
30
+ /**
31
+ * Check mark, relative to the anchor. The stroke is as wide as the bubble, so
32
+ * the start of the round-capped check is the bubble itself.
33
+ */
34
+ export const CHECK = {
35
+ start: { x: -130, y: -10 },
36
+ path: "M-130,-10 L-45,75 L135,-105",
37
+ length: Math.hypot(85, 85) + Math.hypot(180, 180),
38
+ width: DOT_R * 2,
39
+ };
40
+ /**
41
+ * `</>`: each stroke is born at one of the three dots (the vertex of the <,
42
+ * the middle of the slash, the vertex of the >). Width 50 = the dots' diameter
43
+ * at that moment.
44
+ */
45
+ export const CODE = {
46
+ dist: 170,
47
+ radius: 25,
48
+ strokes: [
49
+ "M-170,0 L-95,-75",
50
+ "M-170,0 L-95,75",
51
+ "M0,0 L38,-105",
52
+ "M0,0 L-38,105",
53
+ "M170,0 L95,-75",
54
+ "M170,0 L95,75",
55
+ ],
56
+ lengths: [106.1, 106.1, 111.7, 111.7, 106.1, 106.1],
57
+ };
58
+ /** Energy orbit: full radius and radius of each dot. */
59
+ export const ORBIT = { R: 300, radii: [26, 18, 26, 18, 26, 18, 26, 18] };
@@ -1,4 +1,4 @@
1
- import { clamp, smooth } from "./spring.js";
1
+ import { clamp, smooth } from "./motion.js";
2
2
  /**
3
3
  * Computes one frame of the "character that travels between landing-page
4
4
  * slots on scroll" pattern. Caller supplies the slots (e.g. from
@@ -0,0 +1,10 @@
1
+ type Subscriber = (now: number) => void;
2
+ /** Last pointer position in the window and when it last moved. */
3
+ export declare const pointer: {
4
+ x: number;
5
+ y: number;
6
+ last: number;
7
+ inside: boolean;
8
+ };
9
+ export declare function subscribe(f: Subscriber): () => void;
10
+ export {};
package/dist/ticker.js ADDED
@@ -0,0 +1,42 @@
1
+ /*
2
+ * A single requestAnimationFrame for every character on the page, and a single
3
+ * pointer listener. Whoever subscribes receives the frame time; when nobody is
4
+ * left, the loop stops. With the tab hidden, the browser already pauses rAF.
5
+ */
6
+ const subscribers = new Set();
7
+ let frame = 0;
8
+ /** Last pointer position in the window and when it last moved. */
9
+ export const pointer = { x: 0, y: 0, last: -Infinity, inside: true };
10
+ function run(now) {
11
+ for (const f of subscribers)
12
+ f(now);
13
+ frame = subscribers.size ? requestAnimationFrame(run) : 0;
14
+ }
15
+ function onMove(e) {
16
+ pointer.x = e.clientX;
17
+ pointer.y = e.clientY;
18
+ pointer.last = performance.now();
19
+ pointer.inside = true;
20
+ }
21
+ function onLeave(e) {
22
+ if (!e.relatedTarget)
23
+ pointer.inside = false;
24
+ }
25
+ export function subscribe(f) {
26
+ if (subscribers.size === 0) {
27
+ window.addEventListener("pointermove", onMove, { passive: true });
28
+ document.documentElement.addEventListener("pointerleave", onLeave);
29
+ }
30
+ subscribers.add(f);
31
+ if (!frame)
32
+ frame = requestAnimationFrame(run);
33
+ return () => {
34
+ subscribers.delete(f);
35
+ if (subscribers.size === 0) {
36
+ window.removeEventListener("pointermove", onMove);
37
+ document.documentElement.removeEventListener("pointerleave", onLeave);
38
+ cancelAnimationFrame(frame);
39
+ frame = 0;
40
+ }
41
+ };
42
+ }
@@ -0,0 +1,21 @@
1
+ import type { PartialDelta } from './delta.js';
2
+ export declare const TRANSFORMATIONS: {
3
+ morphLoading: {
4
+ duration: number;
5
+ sample: (t: number) => PartialDelta;
6
+ };
7
+ morphCheck: {
8
+ duration: number;
9
+ sample: (t: number) => PartialDelta;
10
+ };
11
+ morphCode: {
12
+ duration: number;
13
+ sample: (t: number) => PartialDelta;
14
+ };
15
+ energy: {
16
+ duration: number;
17
+ sample: (t: number) => PartialDelta;
18
+ };
19
+ };
20
+ /** Reactions that cannot be interrupted: in the middle of them the body does not even exist. */
21
+ export declare const EXCLUSIVE: ReadonlySet<string>;
@@ -0,0 +1,306 @@
1
+ import { track } from './motion.js';
2
+ import { CHECK, CODE, DOT_R, DOT_SCALE, RING } from './rig.js';
3
+ /*
4
+ * Seamless transformations, in Pumpy's style. Three phases:
5
+ *
6
+ * 1. Entry: anticipates (squashes and stretches), the silhouette becomes a
7
+ * perfect circle around the anchor, the parts retract inwards, the eyes
8
+ * close and vanish, and the circle shrinks to the exact radius of the
9
+ * bubble (`DOT_R`).
10
+ * 2. Object: at the swap frame, the body vanishes and the bubble appears at the
11
+ * same center, with the same radius and the same colour, so nothing changes
12
+ * on screen. From there the bubble becomes dots, disc, ring, check or </>
13
+ * purely through continuous geometry: the dots are born under it, the ring
14
+ * is a disc that opens a hole, the check and the </> are strokes with the
15
+ * width of the bubble that grow out of it.
16
+ * 3. Exit: the same path in reverse. The object goes back to being the bubble,
17
+ * swaps for the circle and the circle grows, overshoots and goes back to
18
+ * being a strawberry.
19
+ *
20
+ * Everything in seconds in here; the brain receives progress from 0 to 1.
21
+ */
22
+ function fromCues(cues) {
23
+ const fns = Object.entries(cues).map(([k, c]) => [k, track(c)]);
24
+ return (s) => {
25
+ const d = {};
26
+ for (const [k, f] of fns)
27
+ d[k] = f(s);
28
+ return d;
29
+ };
30
+ }
31
+ /** Scale (delta) of the round body at the size of the bubble. */
32
+ const DOT_DELTA = DOT_SCALE - 1;
33
+ const ENTRY = 0.66;
34
+ const entry = fromCues({
35
+ bodySx: [
36
+ [0, 0],
37
+ [0.1, 0.1],
38
+ [0.22, -0.04],
39
+ [0.34, 0],
40
+ ],
41
+ bodySy: [
42
+ [0, 0],
43
+ [0.1, -0.1],
44
+ [0.22, 0.06],
45
+ [0.34, 0],
46
+ ],
47
+ round: [
48
+ [0.06, 0],
49
+ [0.4, 1],
50
+ ],
51
+ retract: [
52
+ [0.04, 0, 'easeIn'],
53
+ [0.3, 1],
54
+ ],
55
+ eyeSy: [
56
+ [0.08, 0],
57
+ [0.2, -0.9],
58
+ ],
59
+ eyesVanish: [
60
+ [0.18, 0],
61
+ [0.34, 1],
62
+ ],
63
+ scale: [
64
+ [0, 0],
65
+ [0.1, -0.04],
66
+ [0.36, -0.08],
67
+ [ENTRY, DOT_DELTA],
68
+ ],
69
+ });
70
+ const EXIT = 0.95;
71
+ function leave(options) {
72
+ const extra = options.hop ?? 0.1;
73
+ const f = fromCues({
74
+ // Grows from rest (the bubble was still at the swap frame).
75
+ scale: [
76
+ [0, DOT_DELTA],
77
+ [0.34, extra],
78
+ [0.48, -0.04],
79
+ [0.6, 0.01],
80
+ [0.7, 0],
81
+ ],
82
+ round: [
83
+ [0.16, 1],
84
+ [0.5, 0],
85
+ ],
86
+ retract: [
87
+ [0.26, 1, 'easeOut'],
88
+ [0.46, -0.18],
89
+ [0.62, 0.05],
90
+ [0.72, 0],
91
+ ],
92
+ eyesVanish: [
93
+ [0.16, 1],
94
+ [0.32, 0],
95
+ ],
96
+ eyeSy: [
97
+ [0.26, -0.9],
98
+ [0.42, 0.1],
99
+ [0.5, 0],
100
+ ],
101
+ bodySx: [
102
+ [0.3, 0],
103
+ [0.4, 0.06],
104
+ [0.52, -0.03],
105
+ [0.64, 0.01],
106
+ [0.7, 0],
107
+ ],
108
+ bodySy: [
109
+ [0.3, 0],
110
+ [0.4, -0.06],
111
+ [0.52, 0.03],
112
+ [0.64, -0.01],
113
+ [0.7, 0],
114
+ ],
115
+ happy: options.happy
116
+ ? [
117
+ [0.3, 0],
118
+ [0.4, 1],
119
+ [0.8, 1],
120
+ [0.95, 0],
121
+ ]
122
+ : [[0, 0]],
123
+ sparks: options.sparks
124
+ ? [
125
+ [0.05, 0, 'linear'],
126
+ [0.75, 1],
127
+ [0.7501, 0],
128
+ ]
129
+ : [[0, 0]],
130
+ });
131
+ return f;
132
+ }
133
+ /** Bubble pulse right after the swap: adds life without moving the center. */
134
+ const BUBBLE_PULSE = [
135
+ [0, DOT_R],
136
+ [0.08, DOT_R + 6],
137
+ [0.2, DOT_R],
138
+ ];
139
+ /**
140
+ * Builds a transformation: entry, `middle` seconds of object and exit. The object
141
+ * returns only its own fields; the rest (hidden body, bubble at the right radius)
142
+ * comes from here, and the bubble radius must return to `DOT_R` at the end of the middle.
143
+ */
144
+ function makeTransformation(middle, obj, options = {}) {
145
+ const exitSampler = leave(options);
146
+ const duration = ENTRY + middle + EXIT;
147
+ const morph = track([
148
+ [0, 0],
149
+ [0.1, 1],
150
+ [duration - 0.25, 1],
151
+ [duration, 0],
152
+ ]);
153
+ const hold = track([
154
+ [0, 0],
155
+ [0.08, 1],
156
+ [duration - 0.35, 1],
157
+ [duration, 0],
158
+ ]);
159
+ // Before returning, the bubble "inhales" (shrinks a little and returns to the exact radius, still).
160
+ const inhale = track([
161
+ [middle - 0.3, DOT_R],
162
+ [middle - 0.15, DOT_R - 6],
163
+ [middle - 0.02, DOT_R],
164
+ ]);
165
+ const sample = (t) => {
166
+ const s = t * duration;
167
+ let d;
168
+ if (s < ENTRY)
169
+ d = entry(s);
170
+ else if (s < ENTRY + middle) {
171
+ const objT = s - ENTRY;
172
+ d = {
173
+ scale: DOT_DELTA,
174
+ round: 1,
175
+ retract: 1,
176
+ eyeSy: -0.9,
177
+ eyesVanish: 1,
178
+ swap: 1,
179
+ bubbleR: DOT_R,
180
+ ...obj(objT),
181
+ };
182
+ if (objT > middle - 0.3)
183
+ d.bubbleR = inhale(objT);
184
+ }
185
+ else
186
+ d = exitSampler(s - ENTRY - middle);
187
+ return { ...d, morph: morph(s), holdGaze: hold(s) };
188
+ };
189
+ return { duration, sample };
190
+ }
191
+ /* ---------- becomes loading: dots → disc → spinning ring → disc → bubble ---------- */
192
+ const loading = fromCues({
193
+ bubbleR: [
194
+ ...BUBBLE_PULSE,
195
+ [1.15, DOT_R, 'easeOut'],
196
+ [1.45, RING.R],
197
+ [2.75, RING.R],
198
+ [3.05, DOT_R],
199
+ ],
200
+ dotsDist: [
201
+ [0.15, 0, 'easeOut'],
202
+ [0.45, 90],
203
+ [0.9, 90],
204
+ [1.15, 0],
205
+ ],
206
+ dotsBounce: [
207
+ [0.2, 0],
208
+ [0.45, 1],
209
+ [0.85, 1],
210
+ [1.05, 0],
211
+ ],
212
+ bubbleHole: [
213
+ [1.45, 0],
214
+ [1.7, RING.hole],
215
+ [2.45, RING.hole],
216
+ [2.7, 0],
217
+ ],
218
+ bubbleArc: [
219
+ [1.7, 0],
220
+ [1.95, 0.72],
221
+ [2.2, 0.72],
222
+ [2.42, 0],
223
+ ],
224
+ });
225
+ function loadingSpin(s) {
226
+ // Starts spinning when it becomes a disc (invisible until the ring opens) and accelerates.
227
+ const x = Math.max(0, s - 1.45);
228
+ return x < 0.4 ? 450 * x * x : 72 + 360 * (x - 0.4);
229
+ }
230
+ /* ---------- becomes check: the bubble walks to the start of the check and draws it ---------- */
231
+ const check = fromCues({
232
+ bubbleR: BUBBLE_PULSE,
233
+ bubbleX: [
234
+ [0.15, 0, 'easeOut'],
235
+ [0.42, CHECK.start.x],
236
+ [1.75, CHECK.start.x],
237
+ [2.0, 0],
238
+ ],
239
+ bubbleY: [
240
+ [0.15, 0, 'easeOut'],
241
+ [0.42, CHECK.start.y],
242
+ [1.75, CHECK.start.y],
243
+ [2.0, 0],
244
+ ],
245
+ checkDraw: [
246
+ [0.42, 0, 'easeOut'],
247
+ [0.8, 1],
248
+ [1.45, 1, 'easeIn'],
249
+ [1.75, 0],
250
+ ],
251
+ objScale: [
252
+ [0.8, 0],
253
+ [0.9, 0.1],
254
+ [1.04, -0.03],
255
+ [1.14, 0],
256
+ ],
257
+ });
258
+ /* ---------- becomes </>: three dots and a stroke leaving each one ---------- */
259
+ const code = fromCues({
260
+ bubbleR: [
261
+ ...BUBBLE_PULSE,
262
+ [0.3, DOT_R],
263
+ [0.55, CODE.radius],
264
+ [1.75, CODE.radius],
265
+ [2.0, DOT_R],
266
+ ],
267
+ dotsDist: [
268
+ [0.25, 0, 'easeOut'],
269
+ [0.55, CODE.dist],
270
+ [1.7, CODE.dist, 'easeIn'],
271
+ [1.95, 0],
272
+ ],
273
+ codeDraw: [
274
+ [0.55, 0, 'easeOut'],
275
+ [0.9, 1],
276
+ [1.35, 1, 'easeIn'],
277
+ [1.65, 0],
278
+ ],
279
+ objScale: [
280
+ [0.9, 0],
281
+ [1.0, 0.08],
282
+ [1.12, -0.02],
283
+ [1.22, 0],
284
+ ],
285
+ });
286
+ /* ---------- energy: eight dots come out from under the bubble and orbit ---------- */
287
+ const energy = fromCues({
288
+ bubbleR: [...BUBBLE_PULSE, [0.3, DOT_R], [0.55, 28], [1.55, 28], [1.8, 48], [1.95, DOT_R]],
289
+ orbitOpen: [
290
+ [0.25, 0, 'easeOut'],
291
+ [0.65, 1],
292
+ [1.3, 1, 'easeIn'],
293
+ [1.65, 0],
294
+ ],
295
+ });
296
+ export const TRANSFORMATIONS = {
297
+ morphLoading: makeTransformation(3.4, (s) => ({ ...loading(s), objRotate: loadingSpin(s) })),
298
+ morphCheck: makeTransformation(2.35, check, { happy: true }),
299
+ morphCode: makeTransformation(2.35, code),
300
+ energy: makeTransformation(2.3, (s) => ({ ...energy(s), objRotate: 260 * s + 160 * s * s }), {
301
+ hop: 0.2,
302
+ sparks: true,
303
+ }),
304
+ };
305
+ /** Reactions that cannot be interrupted: in the middle of them the body does not even exist. */
306
+ export const EXCLUSIVE = new Set(Object.keys(TRANSFORMATIONS));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "procedural-bot-animations",
3
- "version": "0.1.0",
4
- "description": "Procedural motion and a state machine for Open Bot Avatar: idle wander, breathing, spring bounce, velocity lean, and typed bot states.",
3
+ "version": "0.2.0",
4
+ "description": "A procedural animation engine for 2D SVG mascots: lively eyes (saccades, pursuit, blinks, eyelids), blended moods, reactions and activities, sprung and bending parts. Characters and animations are plain JSON. Includes a state machine and a scroll traveler.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -22,6 +22,7 @@
22
22
  "typecheck": "tsc --noEmit",
23
23
  "test": "vitest run",
24
24
  "test:watch": "vitest",
25
+ "site": "npm run build && rm -rf site/dist site/docs && cp -r dist site/dist && mkdir -p site/docs && cp docs/character-format.md docs/animation-format.md site/docs/",
25
26
  "check": "npm run typecheck && npm run test && npm run build"
26
27
  },
27
28
  "keywords": [
@@ -30,7 +31,10 @@
30
31
  "mascot",
31
32
  "procedural-animation",
32
33
  "state-machine",
33
- "open-bot-avatar"
34
+ "open-bot-avatar",
35
+ "svg",
36
+ "character-animation",
37
+ "eyes"
34
38
  ],
35
39
  "license": "MIT",
36
40
  "author": "Jp-mainieri",
@@ -39,14 +43,6 @@
39
43
  "url": "https://github.com/Jp-mainieri/procedural-bot-animations.git"
40
44
  },
41
45
  "homepage": "https://github.com/Jp-mainieri/procedural-bot-animations",
42
- "peerDependencies": {
43
- "open-bot-avatar": ">=0.1.0"
44
- },
45
- "peerDependenciesMeta": {
46
- "open-bot-avatar": {
47
- "optional": true
48
- }
49
- },
50
46
  "devDependencies": {
51
47
  "typescript": "^5.9.3",
52
48
  "vitest": "^3.2.4"
package/dist/bind.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { Brain, type BrainOptions } from "./brain.js";
2
- import type { GazeTarget } from "./gaze.js";
3
- import type { AvatarDefinitionLike } from "./types.js";
4
- import { type MountedRig, type RenderOptions } from "./render.js";
5
- export interface BoundBot {
6
- readonly brain: Brain;
7
- readonly rig: MountedRig;
8
- /** Advance one frame. `nowMs` should be monotonically increasing, e.g. from `requestAnimationFrame`. */
9
- tick(nowMs: number): void;
10
- /** Runs `tick` on `requestAnimationFrame` until `stop()`. */
11
- start(): void;
12
- stop(): void;
13
- destroy(): void;
14
- }
15
- export interface BindOptions extends RenderOptions {
16
- host: HTMLElement;
17
- definition: AvatarDefinitionLike;
18
- brain?: BrainOptions;
19
- /** Returns the live gaze target (e.g. pointer position relative to the host, -1..1) or `null` for autonomous wandering. */
20
- getGazeTarget?: () => GazeTarget | null;
21
- }
22
- /**
23
- * Mounts a definition with `mountRig` and wires a `Brain` to it: every
24
- * frame it reads the gaze target, advances mood/gaze/blink/reactions, and
25
- * applies the resulting pose to the rendered SVG.
26
- */
27
- export declare function bindBrain(options: BindOptions): BoundBot;
package/dist/bind.js DELETED
@@ -1,42 +0,0 @@
1
- import { Brain } from "./brain.js";
2
- import { safeDt } from "./spring.js";
3
- import { mountRig } from "./render.js";
4
- /**
5
- * Mounts a definition with `mountRig` and wires a `Brain` to it: every
6
- * frame it reads the gaze target, advances mood/gaze/blink/reactions, and
7
- * applies the resulting pose to the rendered SVG.
8
- */
9
- export function bindBrain(options) {
10
- const rig = mountRig(options.host, options.definition, options);
11
- const brain = new Brain(options.brain);
12
- let lastMs = null;
13
- let rafId = null;
14
- function tick(nowMs) {
15
- const dt = safeDt(lastMs === null ? 16 : nowMs - lastMs);
16
- lastMs = nowMs;
17
- const target = options.getGazeTarget?.() ?? null;
18
- rig.applyPose(brain.update(dt, target));
19
- }
20
- return {
21
- brain,
22
- rig,
23
- tick,
24
- start() {
25
- const loop = (nowMs) => {
26
- tick(nowMs);
27
- rafId = requestAnimationFrame(loop);
28
- };
29
- rafId = requestAnimationFrame(loop);
30
- },
31
- stop() {
32
- if (rafId !== null)
33
- cancelAnimationFrame(rafId);
34
- rafId = null;
35
- lastMs = null;
36
- },
37
- destroy() {
38
- this.stop();
39
- rig.destroy();
40
- },
41
- };
42
- }