open-bot-avatar 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/dist/animator.d.ts +32 -0
- package/dist/animator.d.ts.map +1 -0
- package/dist/animator.js +43 -0
- package/dist/animator.js.map +1 -0
- package/dist/color.d.ts +19 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +50 -0
- package/dist/color.js.map +1 -0
- package/dist/contour.d.ts +22 -0
- package/dist/contour.d.ts.map +1 -0
- package/dist/contour.js +133 -0
- package/dist/contour.js.map +1 -0
- package/dist/dom/clock.d.ts +26 -0
- package/dist/dom/clock.d.ts.map +1 -0
- package/dist/dom/clock.js +47 -0
- package/dist/dom/clock.js.map +1 -0
- package/dist/dom/index.d.ts +7 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +5 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/mount.d.ts +38 -0
- package/dist/dom/mount.d.ts.map +1 -0
- package/dist/dom/mount.js +198 -0
- package/dist/dom/mount.js.map +1 -0
- package/dist/dom/pointer.d.ts +3 -0
- package/dist/dom/pointer.d.ts.map +1 -0
- package/dist/dom/pointer.js +52 -0
- package/dist/dom/pointer.js.map +1 -0
- package/dist/dom/reduced.d.ts +2 -0
- package/dist/dom/reduced.d.ts.map +1 -0
- package/dist/dom/reduced.js +16 -0
- package/dist/dom/reduced.js.map +1 -0
- package/dist/examples.d.ts +13 -0
- package/dist/examples.d.ts.map +1 -0
- package/dist/examples.js +103 -0
- package/dist/examples.js.map +1 -0
- package/dist/follow.d.ts +60 -0
- package/dist/follow.d.ts.map +1 -0
- package/dist/follow.js +67 -0
- package/dist/follow.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/mood.d.ts +23 -0
- package/dist/mood.d.ts.map +1 -0
- package/dist/mood.js +26 -0
- package/dist/mood.js.map +1 -0
- package/dist/motion.d.ts +72 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +162 -0
- package/dist/motion.js.map +1 -0
- package/dist/path.d.ts +77 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +406 -0
- package/dist/path.js.map +1 -0
- package/dist/render.d.ts +115 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +324 -0
- package/dist/render.js.map +1 -0
- package/dist/seams.d.ts +16 -0
- package/dist/seams.d.ts.map +1 -0
- package/dist/seams.js +109 -0
- package/dist/seams.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +73 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +266 -0
- package/dist/validate.js.map +1 -0
- package/dist/volume.d.ts +113 -0
- package/dist/volume.d.ts.map +1 -0
- package/dist/volume.js +582 -0
- package/dist/volume.js.map +1 -0
- package/package.json +43 -3
- package/src/animator.ts +69 -0
- package/src/color.ts +57 -0
- package/src/contour.ts +126 -0
- package/src/dom/clock.ts +63 -0
- package/src/dom/index.ts +6 -0
- package/src/dom/mount.ts +245 -0
- package/src/dom/pointer.ts +51 -0
- package/src/dom/reduced.ts +18 -0
- package/src/examples.ts +112 -0
- package/src/follow.ts +81 -0
- package/src/index.ts +21 -0
- package/src/mood.ts +39 -0
- package/src/motion.ts +209 -0
- package/src/path.ts +319 -0
- package/src/render.ts +461 -0
- package/src/seams.ts +111 -0
- package/src/types.ts +74 -0
- package/src/validate.ts +282 -0
- package/src/volume.ts +640 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dominik Scholz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,127 @@
|
|
|
1
|
-
#
|
|
1
|
+
# open-bot-avatar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open Bot Avatar renders object avatars from an SVG silhouette and eye placement. The renderer adds volume, blinking, gaze and motion.
|
|
4
|
+
|
|
5
|
+
The `open-bot-avatar` package has no dependencies. Its main entry point works without a DOM; `open-bot-avatar/dom` adds browser mounting and pointer tracking.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add open-bot-avatar
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Mount an avatar
|
|
14
|
+
|
|
15
|
+
Create an empty element with an explicit size, such as a 96 × 96 pixel div with `id="bot"`. `mountAvatar` fills that element.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { getExample } from "open-bot-avatar";
|
|
19
|
+
import { mountAvatar } from "open-bot-avatar/dom";
|
|
20
|
+
|
|
21
|
+
const avatar = mountAvatar(document.querySelector("#bot")!, {
|
|
22
|
+
definition: getExample("mug")!,
|
|
23
|
+
color: "#ff6a1a",
|
|
24
|
+
followPointer: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
avatar.update({ mood: "happy" });
|
|
28
|
+
// When the avatar is no longer needed:
|
|
29
|
+
avatar.destroy();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`update` accepts any subset of the mount options. Omitted options keep their values. Call `destroy` when the avatar is no longer needed; it stops tracking and animation and removes the avatar's content.
|
|
33
|
+
|
|
34
|
+
| Option | Behavior |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `definition` | Required avatar definition. Validate imported data first. |
|
|
37
|
+
| `color`, `eyeColor` | Body and eye colors as `#rgb` or `#rrggbb`. Defaults: `#ff6a1a`, `#151515`. |
|
|
38
|
+
| `mood` | `"idle"` (default), `"thinking"` or `"happy"`. Changes ease from the current pose. |
|
|
39
|
+
| `followPointer` | Follow the mouse, pen or finger on the page. Default: `false`. |
|
|
40
|
+
| `lookAt` | Fixed `{ x, y }` direction, each from -1 to 1 (x right, y down). Overrides the pointer; `null` clears it. |
|
|
41
|
+
| `holdGaze` | Keep the current look direction. Default: `false`. |
|
|
42
|
+
| `view` | Extra `{ yaw, pitch }` rotation in radians, relative to the resting view. |
|
|
43
|
+
| `depth` | Volume amount from 0 to 14. Default: 6; 0 is flat. |
|
|
44
|
+
| `reducedMotion` | `true`, `false` or `"system"` (default), which follows `prefers-reduced-motion`. |
|
|
45
|
+
| `still` | Render a static SVG without animation. Default: `false`. |
|
|
46
|
+
| `label` | Accessible name. Defaults to the definition's name; `""` marks it decorative. |
|
|
47
|
+
|
|
48
|
+
## React
|
|
49
|
+
|
|
50
|
+
There is no separate React package. Copy this component to mount on setup, update after rendering, and destroy on cleanup. In other frameworks, use the equivalent lifecycle hooks.
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { useEffect, useRef } from "react";
|
|
54
|
+
import { mountAvatar, type AvatarOptions, type MountedAvatar } from "open-bot-avatar/dom";
|
|
55
|
+
|
|
56
|
+
export function BotAvatar({ size = 96, ...options }: AvatarOptions & { size?: number }) {
|
|
57
|
+
const host = useRef<HTMLDivElement>(null);
|
|
58
|
+
const avatar = useRef<MountedAvatar | null>(null);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
avatar.current = mountAvatar(host.current!, options);
|
|
61
|
+
return () => avatar.current?.destroy();
|
|
62
|
+
}, []);
|
|
63
|
+
useEffect(() => avatar.current?.update(options));
|
|
64
|
+
return <div ref={host} style={{ width: size, aspectRatio: "1" }} />;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Pass a validated definition as the definition prop.
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Static SVG and frames
|
|
71
|
+
|
|
72
|
+
`renderAvatarSvg` returns a standalone SVG string. `avatarFrame` returns paths, transforms and eye shapes in back-to-front drawing order for custom renderers. Neither needs a DOM.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { avatarFrame, renderAvatarSvg, validateAvatar } from "open-bot-avatar";
|
|
76
|
+
|
|
77
|
+
// text is a JSON string. JSON.parse throws if its syntax is invalid.
|
|
78
|
+
const result = validateAvatar(JSON.parse(text));
|
|
79
|
+
if (!result.ok) throw new Error(result.errors.join("\n"));
|
|
80
|
+
|
|
81
|
+
const options = { color: "#1fbf68", time: 1.2, motion: "happy" as const };
|
|
82
|
+
const svg = renderAvatarSvg(result.value, { ...options, size: 256 });
|
|
83
|
+
const frame = avatarFrame(result.value, options);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Both functions accept `RenderOptions`:
|
|
87
|
+
|
|
88
|
+
- `color`, `eyeColor`, `depth` and `view` work as in the mount API.
|
|
89
|
+
- `motion` selects the mood (default: `"idle"`); `time` sets the animation clock in seconds (default: 0).
|
|
90
|
+
- `gaze` sets a fixed direction: `{ x, y, weight? }`. Each axis ranges from -1 to 1; `weight` ranges from 0 to 1 and defaults to 1.
|
|
91
|
+
- `size` sets the SVG width and height in pixels. Omit it for a fluid SVG.
|
|
92
|
+
- `reducedMotion` is a boolean, defaulting to `false`. It freezes body motion and blinking; gaze still applies. It does not read system preferences.
|
|
93
|
+
- `motionBlend` lets a custom animation host blend from another mood: `{ from, t }`, with `t` from 0 to 1. `from` can be a mood or `{ motion, blend? }` for an interrupted transition.
|
|
94
|
+
|
|
95
|
+
## Definitions and validation
|
|
96
|
+
|
|
97
|
+
A definition contains one filled SVG path in a `0 0 100 100` viewBox and an eye pair. The path can have multiple closed subpaths; holes wind opposite to their outline. Color and animation are renderer options.
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"version": 1,
|
|
102
|
+
"id": "box",
|
|
103
|
+
"name": "Box",
|
|
104
|
+
"body": { "path": "M20 20 H80 V80 H20 Z" },
|
|
105
|
+
"eyes": { "x": 50, "y": 46, "spacing": 15, "scale": 1 }
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`x` and `y` locate the center of the eye pair. `spacing` is the center-to-center distance; `scale` adjusts eye size. Use a lowercase slug for `id` and a short display name for `name`. Unknown fields are rejected.
|
|
110
|
+
|
|
111
|
+
Parse JSON text first, then call `validateAvatar` before rendering imported definitions. It returns `{ ok: true, value }` with a normalized definition or `{ ok: false, errors }` with validation errors. Invalid JSON syntax throws in `JSON.parse`, before validation.
|
|
112
|
+
|
|
113
|
+
## Make an avatar
|
|
114
|
+
|
|
115
|
+
In the [editor](https://dominikscholz.github.io/open-bot-avatar/), describe an avatar in Generate. Copy the prompt into a chat model or open it in an agent app. The editor does not run a model. Paste the returned JSON into Import or drop a JSON file. Import validates it before adding it. If validation fails, use the repair prompt to request a correction.
|
|
116
|
+
|
|
117
|
+
See the [documentation](https://dominikscholz.github.io/open-bot-avatar/#/docs) and [definition contract](https://github.com/dominikscholz/open-bot-avatar/blob/main/docs/avatar-contract.md).
|
|
118
|
+
|
|
119
|
+
## Other exports
|
|
120
|
+
|
|
121
|
+
- `examples` and `getExample(id)` provide built-in definitions.
|
|
122
|
+
- `renderAvatarScene` and `sceneFrame` provide CSS 3D scene markup and per-frame transforms.
|
|
123
|
+
- `computePose`, `createAnimator` and `pointerGaze` support custom animation hosts.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AvatarMotion, AvatarMotionBlend } from './types.ts';
|
|
2
|
+
export interface AnimatorInput {
|
|
3
|
+
/** Wall clock, ms (e.g. performance.now()). Easing runs on it even when the animation clock stops. */
|
|
4
|
+
now: number;
|
|
5
|
+
motion: AvatarMotion;
|
|
6
|
+
/** Look target, -1..1 per axis (x right, y down), e.g. from pointerGaze; null eases back to rest. */
|
|
7
|
+
target: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
} | null;
|
|
11
|
+
/** Keep the current look as it is (e.g. while the user drags the view). */
|
|
12
|
+
hold?: boolean;
|
|
13
|
+
/** Snap instead of easing. */
|
|
14
|
+
reducedMotion: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface AnimatorStep {
|
|
17
|
+
gaze?: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
weight: number;
|
|
21
|
+
};
|
|
22
|
+
motionBlend?: AvatarMotionBlend;
|
|
23
|
+
/** True while the look or a mood change is still easing. */
|
|
24
|
+
moving: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface Animator {
|
|
27
|
+
step(input: AnimatorInput): AnimatorStep;
|
|
28
|
+
/** Back to rest with no mood history, e.g. when the avatar is remounted. */
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createAnimator(): Animator;
|
|
32
|
+
//# sourceMappingURL=animator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animator.d.ts","sourceRoot":"","sources":["../src/animator.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE,MAAM,WAAW,aAAa;IAC5B,sGAAsG;IACtG,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,YAAY,CAAC;IACrB,qGAAqG;IACrG,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACxC,2EAA2E;IAC3E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,8BAA8B;IAC9B,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,4DAA4D;IAC5D,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAAC;IACzC,4EAA4E;IAC5E,KAAK,IAAI,IAAI,CAAC;CACf;AAED,wBAAgB,cAAc,IAAI,QAAQ,CAgCzC"}
|
package/dist/animator.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-avatar state a live renderer keeps between frames, independent of
|
|
3
|
+
* any platform: the eased look toward a target (follow.ts) and the eased
|
|
4
|
+
* change between moods (mood.ts). Feed it once per frame; it returns the
|
|
5
|
+
* `gaze` and `motionBlend` render options for that frame and whether it is
|
|
6
|
+
* still easing.
|
|
7
|
+
*/
|
|
8
|
+
import { REST, followGaze, followStep } from './follow.js';
|
|
9
|
+
import { moodProgress, settleMood } from './mood.js';
|
|
10
|
+
export function createAnimator() {
|
|
11
|
+
let follow = REST;
|
|
12
|
+
let last = null;
|
|
13
|
+
// The mood on screen and when its change began.
|
|
14
|
+
let mood = null;
|
|
15
|
+
return {
|
|
16
|
+
step({ now, motion, target, hold = false, reducedMotion }) {
|
|
17
|
+
const dt = last === null ? 0 : (now - last) / 1000;
|
|
18
|
+
last = now;
|
|
19
|
+
let moving = false;
|
|
20
|
+
if (!hold)
|
|
21
|
+
({ state: follow, moving } = followStep(follow, target, dt, reducedMotion));
|
|
22
|
+
// A new mood eases in from the pose on screen (a change under way included); reduced motion switches at once.
|
|
23
|
+
if (mood && motion !== mood.motion) {
|
|
24
|
+
const shown = { motion: mood.motion, blend: mood.blend && { from: mood.blend.from, t: moodProgress(now - mood.since) } };
|
|
25
|
+
mood = { motion, blend: reducedMotion ? undefined : { from: settleMood(shown), t: 0 }, since: now };
|
|
26
|
+
}
|
|
27
|
+
mood ??= { motion, since: now };
|
|
28
|
+
const t = reducedMotion ? 1 : moodProgress(now - mood.since);
|
|
29
|
+
let motionBlend;
|
|
30
|
+
if (mood.blend && t < 1)
|
|
31
|
+
motionBlend = { from: mood.blend.from, t };
|
|
32
|
+
else
|
|
33
|
+
mood.blend = undefined;
|
|
34
|
+
return { gaze: followGaze(follow), motionBlend, moving: moving || motionBlend !== undefined };
|
|
35
|
+
},
|
|
36
|
+
reset() {
|
|
37
|
+
follow = REST;
|
|
38
|
+
last = null;
|
|
39
|
+
mood = null;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=animator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animator.js","sourceRoot":"","sources":["../src/animator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAkB,M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AAC;YAChC,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7D,IAAI,WAA0C,CAAC;YAC/C,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC;gBAAE,WAAW,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;;gBAC/D,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YAE5B,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAChG,CAAC;QACD,KAAK;YACH,MAAM,GAAG,IAAI,CAAC;YACd,IAAI,GAAG,IAAI,CAAC;YACZ,IAAI,GAAG,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Minimal hex color handling for the renderer. Only #rgb / #rrggbb are accepted. */
|
|
2
|
+
export type Rgb = [number, number, number];
|
|
3
|
+
export declare function parseHex(input: unknown): Rgb | null;
|
|
4
|
+
export declare function toHex([r, g, b]: Rgb): string;
|
|
5
|
+
export declare function mix(a: Rgb, b: Rgb, t: number): Rgb;
|
|
6
|
+
/**
|
|
7
|
+
* Darken while keeping the hue rich: blend toward a deeper, slightly
|
|
8
|
+
* saturated version of the color rather than toward gray-black.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shade(c: Rgb, t: number): Rgb;
|
|
11
|
+
export declare function tint(c: Rgb, t: number): Rgb;
|
|
12
|
+
/** WCAG relative luminance. */
|
|
13
|
+
export declare function luminance([r, g, b]: Rgb): number;
|
|
14
|
+
export declare function contrast(a: Rgb, b: Rgb): number;
|
|
15
|
+
export declare const DARK_INK: Rgb;
|
|
16
|
+
export declare const LIGHT_INK: Rgb;
|
|
17
|
+
/** Pick the eye ink with the best contrast against the body color. */
|
|
18
|
+
export declare function autoEyeColor(body: Rgb): Rgb;
|
|
19
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAAA,qFAAqF;AAErF,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE3C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,GAAG,IAAI,CAOnD;AAED,wBAAgB,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAG5C;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,CAElD;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,CAI5C;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,CAE3C;AAED,+BAA+B;AAC/B,wBAAgB,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAMhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,CAG/C;AAED,eAAO,MAAM,QAAQ,EAAE,GAAkB,CAAC;AAC1C,eAAO,MAAM,SAAS,EAAE,GAAqB,CAAC;AAE9C,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAE3C"}
|
package/dist/color.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Minimal hex color handling for the renderer. Only #rgb / #rrggbb are accepted. */
|
|
2
|
+
export function parseHex(input) {
|
|
3
|
+
if (typeof input !== 'string')
|
|
4
|
+
return null;
|
|
5
|
+
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(input.trim());
|
|
6
|
+
if (!m)
|
|
7
|
+
return null;
|
|
8
|
+
let h = m[1];
|
|
9
|
+
if (h.length === 3)
|
|
10
|
+
h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
|
11
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
12
|
+
}
|
|
13
|
+
export function toHex([r, g, b]) {
|
|
14
|
+
const c = (v) => Math.round(Math.min(255, Math.max(0, v))).toString(16).padStart(2, '0');
|
|
15
|
+
return `#${c(r)}${c(g)}${c(b)}`;
|
|
16
|
+
}
|
|
17
|
+
export function mix(a, b, t) {
|
|
18
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Darken while keeping the hue rich: blend toward a deeper, slightly
|
|
22
|
+
* saturated version of the color rather than toward gray-black.
|
|
23
|
+
*/
|
|
24
|
+
export function shade(c, t) {
|
|
25
|
+
const max = Math.max(...c);
|
|
26
|
+
const deep = [c[0] * 0.35 - (max - c[0]) * 0.1, c[1] * 0.35 - (max - c[1]) * 0.1, c[2] * 0.35 - (max - c[2]) * 0.1];
|
|
27
|
+
return mix(c, deep, t);
|
|
28
|
+
}
|
|
29
|
+
export function tint(c, t) {
|
|
30
|
+
return mix(c, [255, 255, 255], t);
|
|
31
|
+
}
|
|
32
|
+
/** WCAG relative luminance. */
|
|
33
|
+
export function luminance([r, g, b]) {
|
|
34
|
+
const ch = (v) => {
|
|
35
|
+
const s = v / 255;
|
|
36
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
37
|
+
};
|
|
38
|
+
return 0.2126 * ch(r) + 0.7152 * ch(g) + 0.0722 * ch(b);
|
|
39
|
+
}
|
|
40
|
+
export function contrast(a, b) {
|
|
41
|
+
const la = luminance(a), lb = luminance(b);
|
|
42
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
43
|
+
}
|
|
44
|
+
export const DARK_INK = [20, 22, 34];
|
|
45
|
+
export const LIGHT_INK = [250, 250, 255];
|
|
46
|
+
/** Pick the eye ink with the best contrast against the body color. */
|
|
47
|
+
export function autoEyeColor(body) {
|
|
48
|
+
return contrast(body, DARK_INK) >= contrast(body, LIGHT_INK) ? DARK_INK : LIGHT_INK;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAAA,qFAAqF;AAIrF,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,CAAC,GAAG,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACb,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,QAA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IAC3C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE9C,sEAAsE;AACtE,MAAM,UAAU,YAAY,CAAC,IAAS;IACpC,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iso-contours of a sampled scalar field (marching squares), assembled into
|
|
3
|
+
* closed loops and simplified. Used once per definition to turn a part's
|
|
4
|
+
* depth field into plain cross-section paths, so slices need no SVG masks.
|
|
5
|
+
*/
|
|
6
|
+
import type { Point } from './path.ts';
|
|
7
|
+
export interface Field {
|
|
8
|
+
/** Row-major samples, nx * ny. The outermost ring should be below every level. */
|
|
9
|
+
values: Float64Array;
|
|
10
|
+
nx: number;
|
|
11
|
+
ny: number;
|
|
12
|
+
x0: number;
|
|
13
|
+
y0: number;
|
|
14
|
+
step: number;
|
|
15
|
+
}
|
|
16
|
+
/** Closed loops where the field crosses `level` (inside = value ≥ level). */
|
|
17
|
+
export declare function contourLoops(field: Field, level: number): Point[][];
|
|
18
|
+
/** Ramer-Douglas-Peucker on a closed loop. */
|
|
19
|
+
export declare function simplifyLoop(loop: Point[], tolerance: number): Point[];
|
|
20
|
+
/** Compact closed path from loops (draw with fill-rule evenodd). */
|
|
21
|
+
export declare function loopsToPath(loops: Point[][]): string;
|
|
22
|
+
//# sourceMappingURL=contour.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contour.d.ts","sourceRoot":"","sources":["../src/contour.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,WAAW,KAAK;IACpB,kFAAkF;IAClF,MAAM,EAAE,YAAY,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE,CA+DnE;AASD,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,EAAE,CAsBtE;AAOD,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,CAIpD"}
|
package/dist/contour.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** Closed loops where the field crosses `level` (inside = value ≥ level). */
|
|
2
|
+
export function contourLoops(field, level) {
|
|
3
|
+
const { values, nx, ny, x0, y0, step } = field;
|
|
4
|
+
const at = (i, j) => values[j * nx + i] - level;
|
|
5
|
+
// Edge keys: horizontal edge (i,j)-(i+1,j) = 2*(j*nx+i), vertical (i,j)-(i,j+1) = 2*(j*nx+i)+1.
|
|
6
|
+
const points = new Map();
|
|
7
|
+
const links = new Map();
|
|
8
|
+
const point = (key) => {
|
|
9
|
+
if (points.has(key))
|
|
10
|
+
return;
|
|
11
|
+
const idx = key >> 1, i = idx % nx, j = (idx - i) / nx;
|
|
12
|
+
const a = at(i, j);
|
|
13
|
+
if (key & 1) {
|
|
14
|
+
const b = at(i, j + 1), t = a / (a - b);
|
|
15
|
+
points.set(key, [x0 + i * step, y0 + (j + t) * step]);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const b = at(i + 1, j), t = a / (a - b);
|
|
19
|
+
points.set(key, [x0 + (i + t) * step, y0 + j * step]);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const link = (p, q) => {
|
|
23
|
+
point(p);
|
|
24
|
+
point(q);
|
|
25
|
+
(links.get(p) ?? links.set(p, []).get(p)).push(q);
|
|
26
|
+
(links.get(q) ?? links.set(q, []).get(q)).push(p);
|
|
27
|
+
};
|
|
28
|
+
for (let j = 0; j < ny - 1; j++) {
|
|
29
|
+
for (let i = 0; i < nx - 1; i++) {
|
|
30
|
+
const tl = at(i, j) >= 0, tr = at(i + 1, j) >= 0, br = at(i + 1, j + 1) >= 0, bl = at(i, j + 1) >= 0;
|
|
31
|
+
const code = (tl ? 8 : 0) | (tr ? 4 : 0) | (br ? 2 : 0) | (bl ? 1 : 0);
|
|
32
|
+
if (code === 0 || code === 15)
|
|
33
|
+
continue;
|
|
34
|
+
const top = 2 * (j * nx + i), bottom = 2 * ((j + 1) * nx + i);
|
|
35
|
+
const left = 2 * (j * nx + i) + 1, right = 2 * (j * nx + i + 1) + 1;
|
|
36
|
+
if (code === 10 || code === 5) {
|
|
37
|
+
const center = (at(i, j) + at(i + 1, j) + at(i + 1, j + 1) + at(i, j + 1)) / 4 >= 0;
|
|
38
|
+
// Diagonal corners: the center decides whether they connect through the cell.
|
|
39
|
+
if ((code === 10) === center) {
|
|
40
|
+
link(top, right);
|
|
41
|
+
link(bottom, left);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
link(left, top);
|
|
45
|
+
link(right, bottom);
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const crossed = [];
|
|
50
|
+
if (tl !== tr)
|
|
51
|
+
crossed.push(top);
|
|
52
|
+
if (tr !== br)
|
|
53
|
+
crossed.push(right);
|
|
54
|
+
if (br !== bl)
|
|
55
|
+
crossed.push(bottom);
|
|
56
|
+
if (bl !== tl)
|
|
57
|
+
crossed.push(left);
|
|
58
|
+
link(crossed[0], crossed[1]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const loops = [];
|
|
62
|
+
const seen = new Set();
|
|
63
|
+
for (const start of links.keys()) {
|
|
64
|
+
if (seen.has(start))
|
|
65
|
+
continue;
|
|
66
|
+
const loop = [];
|
|
67
|
+
let prev = -1, cur = start;
|
|
68
|
+
while (!seen.has(cur)) {
|
|
69
|
+
seen.add(cur);
|
|
70
|
+
loop.push(points.get(cur));
|
|
71
|
+
const next = links.get(cur).find((n) => n !== prev && !seen.has(n));
|
|
72
|
+
if (next === undefined)
|
|
73
|
+
break;
|
|
74
|
+
prev = cur;
|
|
75
|
+
cur = next;
|
|
76
|
+
}
|
|
77
|
+
if (loop.length >= 3)
|
|
78
|
+
loops.push(loop);
|
|
79
|
+
}
|
|
80
|
+
return loops;
|
|
81
|
+
}
|
|
82
|
+
function perpendicular(p, a, b) {
|
|
83
|
+
const dx = b[0] - a[0], dy = b[1] - a[1];
|
|
84
|
+
const len = Math.hypot(dx, dy);
|
|
85
|
+
if (len === 0)
|
|
86
|
+
return Math.hypot(p[0] - a[0], p[1] - a[1]);
|
|
87
|
+
return Math.abs(dx * (a[1] - p[1]) - dy * (a[0] - p[0])) / len;
|
|
88
|
+
}
|
|
89
|
+
/** Ramer-Douglas-Peucker on a closed loop. */
|
|
90
|
+
export function simplifyLoop(loop, tolerance) {
|
|
91
|
+
if (loop.length <= 8)
|
|
92
|
+
return loop;
|
|
93
|
+
// Split at the point farthest from the first so the closed loop becomes two open chains.
|
|
94
|
+
let far = 0, best = -1;
|
|
95
|
+
for (let k = 1; k < loop.length; k++) {
|
|
96
|
+
const d = Math.hypot(loop[k][0] - loop[0][0], loop[k][1] - loop[0][1]);
|
|
97
|
+
if (d > best) {
|
|
98
|
+
best = d;
|
|
99
|
+
far = k;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const keep = new Uint8Array(loop.length);
|
|
103
|
+
keep[0] = keep[far] = 1;
|
|
104
|
+
const stack = [[0, far], [far, loop.length]];
|
|
105
|
+
while (stack.length) {
|
|
106
|
+
const [s, e] = stack.pop();
|
|
107
|
+
const end = loop[e % loop.length];
|
|
108
|
+
let idx = -1, max = tolerance;
|
|
109
|
+
for (let k = s + 1; k < e; k++) {
|
|
110
|
+
const d = perpendicular(loop[k], loop[s], end);
|
|
111
|
+
if (d > max) {
|
|
112
|
+
max = d;
|
|
113
|
+
idx = k;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (idx >= 0) {
|
|
117
|
+
keep[idx] = 1;
|
|
118
|
+
stack.push([s, idx], [idx, e]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return loop.filter((_, k) => keep[k]);
|
|
122
|
+
}
|
|
123
|
+
const n1 = (v) => {
|
|
124
|
+
const r = Math.round(v * 10) / 10;
|
|
125
|
+
return (Object.is(r, -0) ? 0 : r).toString();
|
|
126
|
+
};
|
|
127
|
+
/** Compact closed path from loops (draw with fill-rule evenodd). */
|
|
128
|
+
export function loopsToPath(loops) {
|
|
129
|
+
return loops
|
|
130
|
+
.map((loop) => `M${n1(loop[0][0])} ${n1(loop[0][1])}L${loop.slice(1).map((p) => `${n1(p[0])} ${n1(p[1])}`).join(' ')}Z`)
|
|
131
|
+
.join('');
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=contour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contour.js","sourceRoot":"","sources":["../src/contour.ts"],"names":[],"mappings":"AAiBA,6EAA6E;AAC7E,MAAM,UAAU,YAAY,CAAC,KAAY,EAAE,KAAa;IACtD,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,E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C,EAAE,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One shared animation loop for every live avatar on the page.
|
|
3
|
+
*
|
|
4
|
+
* Subscribers measure first and draw second, so layout reads never interleave
|
|
5
|
+
* with DOM writes. The loop sleeps once no subscriber needs frames (every
|
|
6
|
+
* avatar is still, or under reduced motion with its easing settled).
|
|
7
|
+
*/
|
|
8
|
+
export interface Pointer {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
export interface FrameSubscriber {
|
|
13
|
+
measure?: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* `time` is the animation clock in seconds, `pointer` the last pointer
|
|
16
|
+
* position in viewport pixels (null when there is none). Return true while
|
|
17
|
+
* the subscriber still needs frames.
|
|
18
|
+
*/
|
|
19
|
+
draw: (time: number, pointer: Pointer | null) => boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function subscribeFrames(subscriber: FrameSubscriber): () => void;
|
|
22
|
+
/** Set the pointer every following avatar looks toward (viewport pixels), or null when there is none. */
|
|
23
|
+
export declare function setPointer(next: Pointer | null): void;
|
|
24
|
+
/** Request a frame after a non-animated change (color, depth, definition). */
|
|
25
|
+
export declare function requestFrame(): void;
|
|
26
|
+
//# sourceMappingURL=clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/dom/clock.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,OAAO;IACtB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;;OAIG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,OAAO,CAAC;CAC1D;AAoBD,wBAAgB,eAAe,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,IAAI,CAUvE;AAED,yGAAyG;AACzG,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,QAG9C;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,SAE3B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One shared animation loop for every live avatar on the page.
|
|
3
|
+
*
|
|
4
|
+
* Subscribers measure first and draw second, so layout reads never interleave
|
|
5
|
+
* with DOM writes. The loop sleeps once no subscriber needs frames (every
|
|
6
|
+
* avatar is still, or under reduced motion with its easing settled).
|
|
7
|
+
*/
|
|
8
|
+
const subscribers = new Set();
|
|
9
|
+
let frame = 0;
|
|
10
|
+
let pointer = null;
|
|
11
|
+
const startedAt = typeof performance !== 'undefined' ? performance.now() : 0;
|
|
12
|
+
function tick(now) {
|
|
13
|
+
frame = 0;
|
|
14
|
+
const time = (now - startedAt) / 1000;
|
|
15
|
+
for (const s of subscribers)
|
|
16
|
+
s.measure?.();
|
|
17
|
+
let busy = false;
|
|
18
|
+
for (const s of subscribers)
|
|
19
|
+
busy = s.draw(time, pointer) || busy;
|
|
20
|
+
if (busy)
|
|
21
|
+
wake();
|
|
22
|
+
}
|
|
23
|
+
function wake() {
|
|
24
|
+
if (!frame && subscribers.size > 0 && typeof requestAnimationFrame !== 'undefined')
|
|
25
|
+
frame = requestAnimationFrame(tick);
|
|
26
|
+
}
|
|
27
|
+
export function subscribeFrames(subscriber) {
|
|
28
|
+
subscribers.add(subscriber);
|
|
29
|
+
wake();
|
|
30
|
+
return () => {
|
|
31
|
+
subscribers.delete(subscriber);
|
|
32
|
+
if (subscribers.size === 0 && frame) {
|
|
33
|
+
cancelAnimationFrame(frame);
|
|
34
|
+
frame = 0;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Set the pointer every following avatar looks toward (viewport pixels), or null when there is none. */
|
|
39
|
+
export function setPointer(next) {
|
|
40
|
+
pointer = next;
|
|
41
|
+
wake();
|
|
42
|
+
}
|
|
43
|
+
/** Request a frame after a non-animated change (color, depth, definition). */
|
|
44
|
+
export function requestFrame() {
|
|
45
|
+
wake();
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/dom/clock.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;AAC/C,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,IAAI,OAAO,GAAmB,IAAI,CAAC;AACnC,MAAM,SAAS,GAAG,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E,SAAS,IAAI,CAAC,GAAW;IACvB,KAAK,GAAG,CAAC,CAAC;IACV,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IACtC,KAAK,MAAM,CAAC,IAAI,WAAW;QAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;IAC3C,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,MAAM,CAAC,IAAI,WAAW;QAAE,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC;IAClE,IAAI,IAAI;QAAE,IAAI,EAAE,CAAC;AACnB,CAAC;AAED,SAAS,IAAI;IACX,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,IAAI,OAAO,qBAAqB,KAAK,WAAW;QAAE,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAC1H,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,UAA2B;IACzD,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5B,IAAI,EAAE,CAAC;IACP,OAAO,GAAG,EAAE;QACV,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/B,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;YACpC,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAC5B,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,UAAU,CAAC,IAAoB;IAC7C,OAAO,GAAG,IAAI,CAAC;IACf,IAAI,EAAE,CAAC;AACT,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,YAAY;IAC1B,IAAI,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { mountAvatar } from './mount.ts';
|
|
2
|
+
export type { AvatarOptions, MountedAvatar } from './mount.ts';
|
|
3
|
+
export { requestFrame, setPointer, subscribeFrames } from './clock.ts';
|
|
4
|
+
export type { FrameSubscriber, Pointer } from './clock.ts';
|
|
5
|
+
export { trackPointer } from './pointer.ts';
|
|
6
|
+
export { prefersReducedMotion } from './reduced.ts';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AvatarDefinition, AvatarMotion } from '../types.ts';
|
|
2
|
+
export interface AvatarOptions {
|
|
3
|
+
definition: AvatarDefinition;
|
|
4
|
+
/** Body color, #rgb or #rrggbb. */
|
|
5
|
+
color?: string;
|
|
6
|
+
/** Eye color, #rgb or #rrggbb. Defaults to a near-black ink. */
|
|
7
|
+
eyeColor?: string;
|
|
8
|
+
/** Volume amount 0..14 (6 = natural depth, 0 = flat). */
|
|
9
|
+
depth?: number;
|
|
10
|
+
mood?: AvatarMotion;
|
|
11
|
+
/** Eyes look and the body turns toward the mouse, pen or finger anywhere on the page. */
|
|
12
|
+
followPointer?: boolean;
|
|
13
|
+
/** Fixed look direction (-1..1 per axis, x right, y down). Wins over the pointer. */
|
|
14
|
+
lookAt?: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
} | null;
|
|
18
|
+
/** Keep the current look as it is (e.g. while the user drags the view). */
|
|
19
|
+
holdGaze?: boolean;
|
|
20
|
+
/** Extra view rotation in radians on top of the resting view (e.g. drag-to-turn). */
|
|
21
|
+
view?: {
|
|
22
|
+
yaw: number;
|
|
23
|
+
pitch: number;
|
|
24
|
+
};
|
|
25
|
+
/** true or false to force; 'system' (default) follows prefers-reduced-motion. */
|
|
26
|
+
reducedMotion?: boolean | 'system';
|
|
27
|
+
/** Render one static SVG and never animate (thumbnails, lists). */
|
|
28
|
+
still?: boolean;
|
|
29
|
+
/** Accessible name; defaults to the definition's name. "" marks the avatar decorative. */
|
|
30
|
+
label?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface MountedAvatar {
|
|
33
|
+
/** Change any options; only what changed is redrawn. */
|
|
34
|
+
update(options: Partial<AvatarOptions>): void;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare function mountAvatar(host: HTMLElement, initial: AvatarOptions): MountedAvatar;
|
|
38
|
+
//# sourceMappingURL=mount.d.ts.map
|