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/blink.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { type Rng } from "./rng.js";
2
- export interface BlinkOptions {
3
- /** Min/max seconds between blinks. Default [1.8, 6]. */
4
- intervalSeconds?: [number, number];
5
- /** Blink duration in seconds. Default 0.15. */
6
- durationSeconds?: number;
7
- /** Chance a blink is a double-blink. Default 0.2. */
8
- doubleChance?: number;
9
- rng?: Rng;
10
- }
11
- /**
12
- * Schedules blinks and reports how shut the eyes should be (0 open, 1 shut)
13
- * at the current time. Since this engine renders its own eyes instead of
14
- * going through Open Bot Avatar's runtime (which blinks on its own),
15
- * driving the blink is this package's job now.
16
- */
17
- export declare class BlinkScheduler {
18
- private nextAt;
19
- private closedUntil;
20
- private pendingSecondBlink;
21
- private readonly opts;
22
- constructor(opts?: BlinkOptions);
23
- /** Call every frame with the running clock `t` (seconds). Returns shut-ness, 0 (open) to 1 (shut). */
24
- update(t: number): number;
25
- }
package/dist/blink.js DELETED
@@ -1,48 +0,0 @@
1
- import { chance, mulberry32, randRange } from "./rng.js";
2
- /**
3
- * Schedules blinks and reports how shut the eyes should be (0 open, 1 shut)
4
- * at the current time. Since this engine renders its own eyes instead of
5
- * going through Open Bot Avatar's runtime (which blinks on its own),
6
- * driving the blink is this package's job now.
7
- */
8
- export class BlinkScheduler {
9
- nextAt;
10
- closedUntil = -1;
11
- pendingSecondBlink = false;
12
- opts;
13
- constructor(opts = {}) {
14
- this.opts = {
15
- intervalSeconds: opts.intervalSeconds ?? [1.8, 6],
16
- durationSeconds: opts.durationSeconds ?? 0.15,
17
- doubleChance: opts.doubleChance ?? 0.2,
18
- rng: opts.rng ?? mulberry32(),
19
- };
20
- this.nextAt = randRange(this.opts.rng, ...this.opts.intervalSeconds);
21
- }
22
- /** Call every frame with the running clock `t` (seconds). Returns shut-ness, 0 (open) to 1 (shut). */
23
- update(t) {
24
- const { intervalSeconds, durationSeconds, doubleChance, rng } = this.opts;
25
- if (this.closedUntil < 0 && t >= this.nextAt) {
26
- this.closedUntil = t + durationSeconds;
27
- }
28
- if (this.closedUntil >= 0 && t >= this.closedUntil) {
29
- this.closedUntil = -1;
30
- if (this.pendingSecondBlink) {
31
- this.pendingSecondBlink = false;
32
- this.nextAt = t + durationSeconds * 1.6;
33
- }
34
- else if (chance(rng, doubleChance)) {
35
- this.pendingSecondBlink = true;
36
- this.nextAt = t + durationSeconds * 1.6;
37
- }
38
- else {
39
- this.nextAt = t + randRange(rng, ...intervalSeconds);
40
- }
41
- }
42
- if (this.closedUntil < 0)
43
- return 0;
44
- const remaining = this.closedUntil - t;
45
- const half = durationSeconds / 2;
46
- return remaining > half ? 1 - (remaining - half) / half : remaining / half;
47
- }
48
- }
package/dist/fake3d.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { PoseDelta } from "./types.js";
2
- export interface FakeTurnOptions {
3
- /** Max eye slide, in viewBox units, at `turn = ±1`. Default 6. */
4
- maxSlide?: number;
5
- /** How much the far eye shrinks in width at `turn = ±1`, 0..1. Default 0.4. */
6
- farShrink?: number;
7
- /** How much the near eye grows in width at `turn = ±1`, 0..1. Default 0.12. */
8
- nearGrow?: number;
9
- /** Body lean, degrees at `turn = ±1`. Default 2. */
10
- bodyLeanDeg?: number;
11
- }
12
- /**
13
- * The Pumpy/Open-Bot-Avatar-style "fake 3D turn": on a flat silhouette with
14
- * no real depth, sliding both eyes toward the turn direction and shrinking
15
- * the eye on the far side (while the near one grows slightly) reads as the
16
- * head rotating, the same illusion Open Bot Avatar gets from projecting
17
- * stacked cross-sections — reproduced here directly on the eyes since this
18
- * engine draws its own flat silhouette instead of that projection.
19
- */
20
- export declare function fakeTurn(turn: number, options?: FakeTurnOptions): PoseDelta;
package/dist/fake3d.js DELETED
@@ -1,24 +0,0 @@
1
- import { clamp } from "./spring.js";
2
- /**
3
- * The Pumpy/Open-Bot-Avatar-style "fake 3D turn": on a flat silhouette with
4
- * no real depth, sliding both eyes toward the turn direction and shrinking
5
- * the eye on the far side (while the near one grows slightly) reads as the
6
- * head rotating, the same illusion Open Bot Avatar gets from projecting
7
- * stacked cross-sections — reproduced here directly on the eyes since this
8
- * engine draws its own flat silhouette instead of that projection.
9
- */
10
- export function fakeTurn(turn, options = {}) {
11
- const { maxSlide = 6, farShrink = 0.4, nearGrow = 0.12, bodyLeanDeg = 2 } = options;
12
- const t = clamp(turn, -1, 1);
13
- const slide = t * maxSlide;
14
- // t > 0: turning toward the right eye (near side), away from the left eye (far side).
15
- const leftScaleX = 1 - Math.max(0, t) * farShrink - Math.max(0, -t) * 0; // left shrinks when turning right
16
- const rightScaleX = 1 - Math.max(0, -t) * farShrink; // right shrinks when turning left
17
- const leftGrow = 1 + Math.max(0, -t) * nearGrow; // left grows when turning left (left becomes near)
18
- const rightGrow = 1 + Math.max(0, t) * nearGrow; // right grows when turning right
19
- return {
20
- leftEye: { offsetX: slide, scaleX: leftScaleX * leftGrow },
21
- rightEye: { offsetX: slide, scaleX: rightScaleX * rightGrow },
22
- body: { rotate: t * bodyLeanDeg },
23
- };
24
- }
package/dist/noise.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * Sum of a few incommensurate sine waves so the output never visibly
3
- * repeats over a normal viewing session, unlike a single `sin(t)`. Give
4
- * each character instance on a page a different `seed` so they drift apart
5
- * instead of moving in lockstep.
6
- */
7
- export declare function neverRepeating(t: number, seed?: number): number;
8
- export interface BreathingOptions {
9
- /** Cycles per second. Default 0.26 (~1.65 rad/s, calibrated by ear). */
10
- frequency?: number;
11
- /** How much of `amplitude` a full breath moves, 0..1. Default 1. */
12
- depthAmount?: number;
13
- seed?: number;
14
- }
15
- /** A squash & stretch breathing multiplier, 1 at rest, oscillating by up to ±2% * `depthAmount`. Multiply directly onto `body.scaleY`/`scaleX`. */
16
- export declare function breathing(t: number, opts?: BreathingOptions): number;
package/dist/noise.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Sum of a few incommensurate sine waves so the output never visibly
3
- * repeats over a normal viewing session, unlike a single `sin(t)`. Give
4
- * each character instance on a page a different `seed` so they drift apart
5
- * instead of moving in lockstep.
6
- */
7
- export function neverRepeating(t, seed = 0) {
8
- const a = Math.sin(t * 0.9 + seed * 1.7);
9
- const b = Math.sin(t * 1.53 + seed * 0.4) * 0.6;
10
- const c = Math.sin(t * 2.31 + seed * 2.9) * 0.35;
11
- return (a + b + c) / 1.95;
12
- }
13
- /** A squash & stretch breathing multiplier, 1 at rest, oscillating by up to ±2% * `depthAmount`. Multiply directly onto `body.scaleY`/`scaleX`. */
14
- export function breathing(t, opts = {}) {
15
- const { frequency = 0.26, depthAmount = 1, seed = 0 } = opts;
16
- return 1 + Math.sin(t * frequency * Math.PI * 2 + seed) * 0.02 * depthAmount;
17
- }
package/dist/render.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import type { AvatarDefinitionLike, Pose } from "./types.js";
2
- export interface RenderOptions {
3
- color?: string;
4
- eyeColor?: string;
5
- /** Pixel size of the (square) mounted SVG. Default: fills the host via 100%/100%. */
6
- size?: number;
7
- }
8
- export interface Bounds {
9
- x: number;
10
- y: number;
11
- width: number;
12
- height: number;
13
- }
14
- export interface MountedRig {
15
- svg: SVGSVGElement;
16
- /** The body silhouette's bounding box in viewBox units, read once after mount via `getBBox`. */
17
- bounds: Bounds;
18
- applyPose(pose: Pose): void;
19
- destroy(): void;
20
- }
21
- /**
22
- * Renders an Open-Bot-Avatar-shaped definition as our own SVG — one filled
23
- * body path plus two independently posable eye groups — instead of going
24
- * through `open-bot-avatar`'s own renderer/runtime. This is what lets the
25
- * procedural engine (moods, reactions, gaze) deform the eyes and body pose
26
- * every frame; Open Bot Avatar's JSON format is reused here only as the
27
- * *shape* input.
28
- */
29
- export declare function mountRig(host: HTMLElement, definition: AvatarDefinitionLike, options?: RenderOptions): MountedRig;
package/dist/render.js DELETED
@@ -1,97 +0,0 @@
1
- const SVG_NS = "http://www.w3.org/2000/svg";
2
- function createEyeGroup(eyeColor) {
3
- const group = document.createElementNS(SVG_NS, "g");
4
- // Neutral pill eye: ~4 wide, 11 tall at scale 1 (per the Open Bot Avatar
5
- // contract's sizing) — a true stadium (flat sides, fully round caps, rx =
6
- // half the width), not an ellipse, matching the "pill" eyes both Open Bot
7
- // Avatar and DevBerry's own Berry use.
8
- const pill = document.createElementNS(SVG_NS, "rect");
9
- pill.setAttribute("x", "-2");
10
- pill.setAttribute("y", "-5.5");
11
- pill.setAttribute("width", "4");
12
- pill.setAttribute("height", "11");
13
- pill.setAttribute("rx", "2");
14
- pill.setAttribute("fill", eyeColor);
15
- // Happy arc: a simple upward stroke, same footprint as the pill.
16
- const arc = document.createElementNS(SVG_NS, "path");
17
- arc.setAttribute("d", "M -2.4 1.5 Q 0 -4.5 2.4 1.5");
18
- arc.setAttribute("fill", "none");
19
- arc.setAttribute("stroke", eyeColor);
20
- arc.setAttribute("stroke-width", "2");
21
- arc.setAttribute("stroke-linecap", "round");
22
- arc.setAttribute("opacity", "0");
23
- group.append(pill, arc);
24
- return { group, pill, arc };
25
- }
26
- function applyEyeTransform(group, baseX, baseY, pose) {
27
- const openness = 1 - pose.shut;
28
- const sx = pose.scaleX;
29
- const sy = pose.scaleY * Math.max(openness, 0.04);
30
- group.setAttribute("transform", `translate(${baseX + pose.offsetX} ${baseY + pose.offsetY}) rotate(${pose.rotate}) scale(${sx} ${sy})`);
31
- }
32
- /**
33
- * Renders an Open-Bot-Avatar-shaped definition as our own SVG — one filled
34
- * body path plus two independently posable eye groups — instead of going
35
- * through `open-bot-avatar`'s own renderer/runtime. This is what lets the
36
- * procedural engine (moods, reactions, gaze) deform the eyes and body pose
37
- * every frame; Open Bot Avatar's JSON format is reused here only as the
38
- * *shape* input.
39
- */
40
- export function mountRig(host, definition, options = {}) {
41
- const { color = "#ff6a1a", eyeColor = "#151515" } = options;
42
- const svg = document.createElementNS(SVG_NS, "svg");
43
- svg.setAttribute("viewBox", "0 0 100 100");
44
- svg.setAttribute("width", "100%");
45
- svg.setAttribute("height", "100%");
46
- if (options.size) {
47
- svg.setAttribute("width", String(options.size));
48
- svg.setAttribute("height", String(options.size));
49
- }
50
- const bodyGroup = document.createElementNS(SVG_NS, "g");
51
- const bodyPath = document.createElementNS(SVG_NS, "path");
52
- bodyPath.setAttribute("d", definition.body.path);
53
- bodyPath.setAttribute("fill", color);
54
- bodyGroup.appendChild(bodyPath);
55
- const { eyes } = definition;
56
- const halfSpacing = eyes.spacing / 2;
57
- const leftBaseX = eyes.x - halfSpacing;
58
- const rightBaseX = eyes.x + halfSpacing;
59
- const baseY = eyes.y;
60
- const left = createEyeGroup(eyeColor);
61
- const right = createEyeGroup(eyeColor);
62
- left.group.setAttribute("transform", `translate(${leftBaseX} ${baseY}) scale(${eyes.scale})`);
63
- right.group.setAttribute("transform", `translate(${rightBaseX} ${baseY}) scale(${eyes.scale})`);
64
- svg.append(bodyGroup, left.group, right.group);
65
- host.appendChild(svg);
66
- // getBBox needs the element attached to a rendered document; in a headless
67
- // DOM (SSR, some test environments) this can throw — fall back to the
68
- // viewBox itself rather than crash the mount.
69
- let bounds;
70
- try {
71
- const box = bodyPath.getBBox();
72
- bounds = { x: box.x, y: box.y, width: box.width, height: box.height };
73
- }
74
- catch {
75
- bounds = { x: 0, y: 0, width: 100, height: 100 };
76
- }
77
- function applyPose(pose) {
78
- const { body } = pose;
79
- const pivotX = bounds.x + bounds.width / 2;
80
- const pivotY = bounds.y + bounds.height; // ground pivot: bottom of the silhouette
81
- bodyGroup.setAttribute("transform", `translate(${body.x} ${body.y}) translate(${pivotX} ${pivotY}) rotate(${body.rotate}) scale(${body.scaleX} ${body.scaleY}) translate(${-pivotX} ${-pivotY})`);
82
- applyEyeTransform(left.group, leftBaseX, baseY, pose.leftEye);
83
- applyEyeTransform(right.group, rightBaseX, baseY, pose.rightEye);
84
- left.pill.setAttribute("opacity", String(1 - pose.leftEye.arcAmount));
85
- left.arc.setAttribute("opacity", String(pose.leftEye.arcAmount));
86
- right.pill.setAttribute("opacity", String(1 - pose.rightEye.arcAmount));
87
- right.arc.setAttribute("opacity", String(pose.rightEye.arcAmount));
88
- }
89
- return {
90
- svg,
91
- bounds,
92
- applyPose,
93
- destroy() {
94
- host.removeChild(svg);
95
- },
96
- };
97
- }
package/dist/rng.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Seedable PRNG (mulberry32). Deterministic by design: pass a fixed seed in
3
- * tests or demos that need to reproduce a run; omit it for real randomness.
4
- */
5
- export type Rng = () => number;
6
- export declare function mulberry32(seed?: number): Rng;
7
- /** Random float in [min, max). */
8
- export declare function randRange(rng: Rng, min: number, max: number): number;
9
- /** True with probability `p` (0..1). */
10
- export declare function chance(rng: Rng, p: number): boolean;
package/dist/rng.js DELETED
@@ -1,18 +0,0 @@
1
- export function mulberry32(seed = Date.now() >>> 0) {
2
- let a = seed >>> 0;
3
- return function rng() {
4
- a |= 0;
5
- a = (a + 0x6d2b79f5) | 0;
6
- let t = Math.imul(a ^ (a >>> 15), 1 | a);
7
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
8
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
9
- };
10
- }
11
- /** Random float in [min, max). */
12
- export function randRange(rng, min, max) {
13
- return min + rng() * (max - min);
14
- }
15
- /** True with probability `p` (0..1). */
16
- export function chance(rng, p) {
17
- return rng() < p;
18
- }
package/dist/spring.d.ts DELETED
@@ -1,21 +0,0 @@
1
- /** Clamp `v` to the [a, b] range. */
2
- export declare function clamp(v: number, a: number, b: number): number;
3
- export declare function lerp(a: number, b: number, t: number): number;
4
- /** Smoothstep of `x` between `a` and `b`. */
5
- export declare function smooth(a: number, b: number, x: number): number;
6
- /**
7
- * Exponential damping toward `target` with no overshoot.
8
- * Frame-rate independent: `rate` is in 1/seconds, `dt` in seconds.
9
- */
10
- export declare function damp(current: number, target: number, rate: number, dt: number): number;
11
- export interface SpringState {
12
- value: number;
13
- velocity: number;
14
- }
15
- /**
16
- * Damped spring (critically-damped when `damping = 2 * sqrt(stiffness)`,
17
- * overshoots when lower). Mutates and returns `state`.
18
- */
19
- export declare function spring(state: SpringState, target: number, stiffness: number, damping: number, dt: number): SpringState;
20
- /** Caps a frame delta so a tab coming back from sleep doesn't blow up springs. */
21
- export declare function safeDt(rawDtMs: number, maxMs?: number): number;
package/dist/spring.js DELETED
@@ -1,33 +0,0 @@
1
- /** Clamp `v` to the [a, b] range. */
2
- export function clamp(v, a, b) {
3
- return v < a ? a : v > b ? b : v;
4
- }
5
- export function lerp(a, b, t) {
6
- return a + (b - a) * t;
7
- }
8
- /** Smoothstep of `x` between `a` and `b`. */
9
- export function smooth(a, b, x) {
10
- const t = clamp((x - a) / (b - a), 0, 1);
11
- return t * t * (3 - 2 * t);
12
- }
13
- /**
14
- * Exponential damping toward `target` with no overshoot.
15
- * Frame-rate independent: `rate` is in 1/seconds, `dt` in seconds.
16
- */
17
- export function damp(current, target, rate, dt) {
18
- return lerp(current, target, 1 - Math.exp(-rate * dt));
19
- }
20
- /**
21
- * Damped spring (critically-damped when `damping = 2 * sqrt(stiffness)`,
22
- * overshoots when lower). Mutates and returns `state`.
23
- */
24
- export function spring(state, target, stiffness, damping, dt) {
25
- const force = stiffness * (target - state.value) - damping * state.velocity;
26
- state.velocity += force * dt;
27
- state.value += state.velocity * dt;
28
- return state;
29
- }
30
- /** Caps a frame delta so a tab coming back from sleep doesn't blow up springs. */
31
- export function safeDt(rawDtMs, maxMs = 50) {
32
- return clamp(rawDtMs, 0, maxMs) / 1000;
33
- }
package/dist/types.d.ts DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * The slice of an Open Bot Avatar definition this engine needs: one
3
- * silhouette path plus eye placement, in a 0 0 100 100 viewBox (see
4
- * https://github.com/DominikScholz/open-bot-avatar/blob/main/docs/avatar-contract.md).
5
- * Written as a local, duck-typed interface — not imported from
6
- * `open-bot-avatar` — so this package has zero required runtime dependency
7
- * on it. Open Bot Avatar (its editor and `generate-avatar` skill) is used
8
- * only to *model* the shape; this engine renders and animates it itself.
9
- */
10
- export interface AvatarDefinitionLike {
11
- body: {
12
- path: string;
13
- };
14
- eyes: {
15
- x: number;
16
- y: number;
17
- spacing: number;
18
- scale: number;
19
- };
20
- }
21
- export interface EyePose {
22
- /** Slide, in viewBox units, on top of the base eye position. */
23
- offsetX: number;
24
- offsetY: number;
25
- /** Multiplies the neutral eye size. 1 = neutral. */
26
- scaleX: number;
27
- scaleY: number;
28
- /** Degrees. */
29
- rotate: number;
30
- /** 0 = fully open, 1 = fully shut (blink/squint-to-closed). */
31
- shut: number;
32
- /** 0..1 crossfade from the neutral pill shape to a happy upward arc. */
33
- arcAmount: number;
34
- }
35
- export interface BodyPose {
36
- /** Viewbox-unit translation, applied before any host-level transform. */
37
- x: number;
38
- y: number;
39
- rotate: number;
40
- scaleX: number;
41
- scaleY: number;
42
- }
43
- export interface Pose {
44
- body: BodyPose;
45
- leftEye: EyePose;
46
- rightEye: EyePose;
47
- }
48
- export declare function neutralEyePose(): EyePose;
49
- export declare function neutralBodyPose(): BodyPose;
50
- export declare function neutralPose(): Pose;
51
- /** Adds `delta` onto `base` in place, used to layer moods/reactions additively. Multiplicative fields (scale) multiply instead of add. */
52
- export declare function addEyePose(base: EyePose, delta: Partial<EyePose>): EyePose;
53
- export declare function addBodyPose(base: BodyPose, delta: Partial<BodyPose>): BodyPose;
54
- export declare function addPose(base: Pose, delta: PoseDelta): Pose;
55
- export interface PoseDelta {
56
- body?: Partial<BodyPose>;
57
- leftEye?: Partial<EyePose>;
58
- rightEye?: Partial<EyePose>;
59
- /** Same delta applied to both eyes; merged before the per-eye fields above. */
60
- eyes?: Partial<EyePose>;
61
- }
62
- /** Resolves a `PoseDelta`'s `eyes` convenience field into both `leftEye`/`rightEye`. */
63
- export declare function resolveDelta(delta: PoseDelta): Required<Pick<PoseDelta, "body" | "leftEye" | "rightEye">>;
package/dist/types.js DELETED
@@ -1,46 +0,0 @@
1
- export function neutralEyePose() {
2
- return { offsetX: 0, offsetY: 0, scaleX: 1, scaleY: 1, rotate: 0, shut: 0, arcAmount: 0 };
3
- }
4
- export function neutralBodyPose() {
5
- return { x: 0, y: 0, rotate: 0, scaleX: 1, scaleY: 1 };
6
- }
7
- export function neutralPose() {
8
- return { body: neutralBodyPose(), leftEye: neutralEyePose(), rightEye: neutralEyePose() };
9
- }
10
- /** Adds `delta` onto `base` in place, used to layer moods/reactions additively. Multiplicative fields (scale) multiply instead of add. */
11
- export function addEyePose(base, delta) {
12
- return {
13
- offsetX: base.offsetX + (delta.offsetX ?? 0),
14
- offsetY: base.offsetY + (delta.offsetY ?? 0),
15
- scaleX: base.scaleX * (delta.scaleX ?? 1),
16
- scaleY: base.scaleY * (delta.scaleY ?? 1),
17
- rotate: base.rotate + (delta.rotate ?? 0),
18
- shut: Math.max(base.shut, delta.shut ?? 0),
19
- arcAmount: Math.max(base.arcAmount, delta.arcAmount ?? 0),
20
- };
21
- }
22
- export function addBodyPose(base, delta) {
23
- return {
24
- x: base.x + (delta.x ?? 0),
25
- y: base.y + (delta.y ?? 0),
26
- rotate: base.rotate + (delta.rotate ?? 0),
27
- scaleX: base.scaleX * (delta.scaleX ?? 1),
28
- scaleY: base.scaleY * (delta.scaleY ?? 1),
29
- };
30
- }
31
- export function addPose(base, delta) {
32
- return {
33
- body: addBodyPose(base.body, delta.body ?? {}),
34
- leftEye: addEyePose(base.leftEye, delta.leftEye ?? {}),
35
- rightEye: addEyePose(base.rightEye, delta.rightEye ?? {}),
36
- };
37
- }
38
- /** Resolves a `PoseDelta`'s `eyes` convenience field into both `leftEye`/`rightEye`. */
39
- export function resolveDelta(delta) {
40
- const eyes = delta.eyes ?? {};
41
- return {
42
- body: delta.body ?? {},
43
- leftEye: { ...eyes, ...(delta.leftEye ?? {}) },
44
- rightEye: { ...eyes, ...(delta.rightEye ?? {}) },
45
- };
46
- }