open-bot-avatar 0.1.1 → 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.
- package/README.md +3 -2
- package/dist/dom/clock.d.ts +5 -3
- package/dist/dom/clock.d.ts.map +1 -1
- package/dist/dom/clock.js +24 -6
- package/dist/dom/clock.js.map +1 -1
- package/dist/dom/mount.d.ts +8 -2
- package/dist/dom/mount.d.ts.map +1 -1
- package/dist/dom/mount.js +82 -14
- package/dist/dom/mount.js.map +1 -1
- package/dist/dom/paint.d.ts +49 -0
- package/dist/dom/paint.d.ts.map +1 -0
- package/dist/dom/paint.js +183 -0
- package/dist/dom/paint.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/render.d.ts +34 -6
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +86 -13
- package/dist/render.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.js +2 -2
- package/dist/validate.js.map +1 -1
- package/package.json +1 -1
- package/src/dom/clock.ts +22 -7
- package/src/dom/mount.ts +90 -16
- package/src/dom/paint.ts +215 -0
- package/src/index.ts +1 -1
- package/src/render.ts +108 -16
- package/src/types.ts +4 -1
- package/src/validate.ts +2 -2
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ avatar.destroy();
|
|
|
34
34
|
| Option | Behavior |
|
|
35
35
|
| --- | --- |
|
|
36
36
|
| `definition` | Required avatar definition. Validate imported data first. |
|
|
37
|
-
| `color`, `eyeColor` | Body and eye colors as `#rgb` or `#rrggbb`. Defaults: `#ff6a1a`, `#151515`. |
|
|
37
|
+
| `color`, `eyeColor` | Body and eye colors as `#rgb` or `#rrggbb`, or any CSS color such as `var(--brand)`. Defaults: `#ff6a1a`, `#151515`. |
|
|
38
38
|
| `mood` | `"idle"` (default), `"thinking"` or `"happy"`. Changes ease from the current pose. |
|
|
39
39
|
| `followPointer` | Follow the mouse, pen or finger on the page. Default: `false`. |
|
|
40
40
|
| `lookAt` | Fixed `{ x, y }` direction, each from -1 to 1 (x right, y down). Overrides the pointer; `null` clears it. |
|
|
@@ -43,6 +43,7 @@ avatar.destroy();
|
|
|
43
43
|
| `depth` | Volume amount from 0 to 14. Default: 6; 0 is flat. |
|
|
44
44
|
| `reducedMotion` | `true`, `false` or `"system"` (default), which follows `prefers-reduced-motion`. |
|
|
45
45
|
| `still` | Render a static SVG without animation. Default: `false`. |
|
|
46
|
+
| `renderer` | `"canvas"` (default) paints each frame to one canvas. `"scene"` mounts a CSS 3D scene with one compositor layer per visible cross-section: more CPU, but less video memory for one avatar several hundred pixels wide. Without canvas support, live avatars use the scene. |
|
|
46
47
|
| `label` | Accessible name. Defaults to the definition's name; `""` marks it decorative. |
|
|
47
48
|
|
|
48
49
|
## React
|
|
@@ -119,7 +120,7 @@ See the [documentation](https://dominikscholz.github.io/open-bot-avatar/#/docs)
|
|
|
119
120
|
## Other exports
|
|
120
121
|
|
|
121
122
|
- `examples` and `getExample(id)` provide built-in definitions.
|
|
122
|
-
- `renderAvatarScene` and `sceneFrame` provide CSS 3D scene markup and per-frame transforms
|
|
123
|
+
- `renderAvatarScene` and `sceneFrame` provide CSS 3D scene markup and per-frame transforms, at one compositor layer per visible slice; `mountAvatar` uses them with `renderer: "scene"`.
|
|
123
124
|
- `computePose`, `createAnimator` and `pointerGaze` support custom animation hosts.
|
|
124
125
|
|
|
125
126
|
## License
|
package/dist/dom/clock.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Subscribers measure first and draw second, so layout reads never interleave
|
|
5
5
|
* with DOM writes. The loop sleeps once no subscriber needs frames (every
|
|
6
6
|
* avatar is still, or under reduced motion with its easing settled).
|
|
7
|
+
* Subscribers that ask to wait are skipped until their time comes.
|
|
7
8
|
*/
|
|
8
9
|
export interface Pointer {
|
|
9
10
|
x: number;
|
|
@@ -13,10 +14,11 @@ export interface FrameSubscriber {
|
|
|
13
14
|
measure?: () => void;
|
|
14
15
|
/**
|
|
15
16
|
* `time` is the animation clock in seconds, `pointer` the last pointer
|
|
16
|
-
* position in viewport pixels (null when there is none). Return true
|
|
17
|
-
* the
|
|
17
|
+
* position in viewport pixels (null when there is none). Return true for
|
|
18
|
+
* the next frame, a number of seconds to skip (neither measured nor drawn
|
|
19
|
+
* until then), or false once no more frames are needed.
|
|
18
20
|
*/
|
|
19
|
-
draw: (time: number, pointer: Pointer | null) => boolean;
|
|
21
|
+
draw: (time: number, pointer: Pointer | null) => boolean | number;
|
|
20
22
|
}
|
|
21
23
|
export declare function subscribeFrames(subscriber: FrameSubscriber): () => void;
|
|
22
24
|
/** Set the pointer every following avatar looks toward (viewport pixels), or null when there is none. */
|
package/dist/dom/clock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/dom/clock.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/dom/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;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;;;;;OAKG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,OAAO,GAAG,MAAM,CAAC;CACnE;AAiCD,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"}
|
package/dist/dom/clock.js
CHANGED
|
@@ -4,19 +4,36 @@
|
|
|
4
4
|
* Subscribers measure first and draw second, so layout reads never interleave
|
|
5
5
|
* with DOM writes. The loop sleeps once no subscriber needs frames (every
|
|
6
6
|
* avatar is still, or under reduced motion with its easing settled).
|
|
7
|
+
* Subscribers that ask to wait are skipped until their time comes.
|
|
7
8
|
*/
|
|
8
9
|
const subscribers = new Set();
|
|
9
10
|
let frame = 0;
|
|
11
|
+
/** Animation time before which a subscriber that asked to wait is skipped (neither measured nor drawn). */
|
|
12
|
+
const due = new WeakMap();
|
|
10
13
|
let pointer = null;
|
|
11
14
|
const startedAt = typeof performance !== 'undefined' ? performance.now() : 0;
|
|
12
15
|
function tick(now) {
|
|
13
16
|
frame = 0;
|
|
14
17
|
const time = (now - startedAt) / 1000;
|
|
15
|
-
for (const s of subscribers)
|
|
16
|
-
s.measure?.();
|
|
17
18
|
let busy = false;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const ready = [];
|
|
20
|
+
for (const s of subscribers) {
|
|
21
|
+
const at = due.get(s);
|
|
22
|
+
if (at !== undefined && at > time)
|
|
23
|
+
busy = true;
|
|
24
|
+
else
|
|
25
|
+
ready.push(s);
|
|
26
|
+
}
|
|
27
|
+
for (const s of ready)
|
|
28
|
+
s.measure?.();
|
|
29
|
+
for (const s of ready) {
|
|
30
|
+
const next = s.draw(time, pointer);
|
|
31
|
+
if (typeof next === 'number')
|
|
32
|
+
due.set(s, time + next);
|
|
33
|
+
else
|
|
34
|
+
due.delete(s);
|
|
35
|
+
busy = next !== false || busy;
|
|
36
|
+
}
|
|
20
37
|
if (busy)
|
|
21
38
|
wake();
|
|
22
39
|
}
|
|
@@ -29,8 +46,9 @@ export function subscribeFrames(subscriber) {
|
|
|
29
46
|
wake();
|
|
30
47
|
return () => {
|
|
31
48
|
subscribers.delete(subscriber);
|
|
32
|
-
if (subscribers.size === 0
|
|
33
|
-
|
|
49
|
+
if (subscribers.size === 0) {
|
|
50
|
+
if (frame)
|
|
51
|
+
cancelAnimationFrame(frame);
|
|
34
52
|
frame = 0;
|
|
35
53
|
}
|
|
36
54
|
};
|
package/dist/dom/clock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/dom/clock.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/dom/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkBH,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;AAC/C,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,2GAA2G;AAC3G,MAAM,GAAG,GAAG,IAAI,OAAO,EAA2B,CAAC;AACnD,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,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5B,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,GAAG,IAAI;YAAE,IAAI,GAAG,IAAI,CAAC;;YAC1C,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnC,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;;YACjD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,GAAG,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC;IAChC,CAAC;IACD,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,EAAE,CAAC;YAC3B,IAAI,KAAK;gBAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC;YACvC,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"}
|
package/dist/dom/mount.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AvatarDefinition, AvatarMotion } from '../types.ts';
|
|
2
2
|
export interface AvatarOptions {
|
|
3
3
|
definition: AvatarDefinition;
|
|
4
|
-
/** Body color
|
|
4
|
+
/** Body color: #rgb or #rrggbb, or any CSS color (e.g. var(--brand)). */
|
|
5
5
|
color?: string;
|
|
6
|
-
/** Eye color
|
|
6
|
+
/** Eye color: #rgb or #rrggbb, or any CSS color. Defaults to a near-black ink. */
|
|
7
7
|
eyeColor?: string;
|
|
8
8
|
/** Volume amount 0..14 (6 = natural depth, 0 = flat). */
|
|
9
9
|
depth?: number;
|
|
@@ -26,6 +26,12 @@ export interface AvatarOptions {
|
|
|
26
26
|
reducedMotion?: boolean | 'system';
|
|
27
27
|
/** Render one static SVG and never animate (thumbnails, lists). */
|
|
28
28
|
still?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* How a live avatar draws. 'canvas' (default) paints each frame to one canvas: one compositor layer
|
|
31
|
+
* per avatar. 'scene' is a CSS 3D scene with a compositor layer per visible slice: more CPU and
|
|
32
|
+
* layers, but less video memory for a single avatar several hundred pixels wide.
|
|
33
|
+
*/
|
|
34
|
+
renderer?: 'canvas' | 'scene';
|
|
29
35
|
/** Accessible name; defaults to the definition's name. "" marks the avatar decorative. */
|
|
30
36
|
label?: string;
|
|
31
37
|
}
|
package/dist/dom/mount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/dom/mount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/dom/mount.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAMjF,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qFAAqF;IACrF,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACzC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qFAAqF;IACrF,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,iFAAiF;IACjF,aAAa,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACnC,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC9B,0FAA0F;IAC1F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAC9C,OAAO,IAAI,IAAI,CAAC;CACjB;AAuFD,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,GAAG,aAAa,CA4KpF"}
|
package/dist/dom/mount.js
CHANGED
|
@@ -5,27 +5,32 @@
|
|
|
5
5
|
* avatar.update({ mood: 'happy' });
|
|
6
6
|
* avatar.destroy();
|
|
7
7
|
*
|
|
8
|
-
* Live avatars
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Live avatars paint each frame to one canvas (see paint.ts): one compositor
|
|
9
|
+
* layer and a small bitmap per avatar. `renderer: 'scene'` mounts a CSS 3D scene
|
|
10
|
+
* instead, where every cross-section is its own small SVG and each frame only
|
|
11
|
+
* writes a few CSS transforms; it costs a compositor layer per visible slice,
|
|
12
|
+
* and is also the fallback where canvas is unavailable. `still` avatars are a
|
|
13
|
+
* single static SVG and never animate. Every avatar on the page shares one
|
|
14
|
+
* animation loop.
|
|
13
15
|
*/
|
|
14
16
|
import { createAnimator } from '../animator.js';
|
|
15
17
|
import { pointerGaze } from '../follow.js';
|
|
16
|
-
import { DEFAULT_COLOR, DEFAULT_EYE_COLOR, renderAvatarScene, renderAvatarSvg, sceneFrame } from '../render.js';
|
|
18
|
+
import { DEFAULT_COLOR, DEFAULT_EYE_COLOR, liveFrame, renderAvatarScene, renderAvatarSvg, sceneFrame } from '../render.js';
|
|
17
19
|
import { requestFrame, subscribeFrames } from './clock.js';
|
|
20
|
+
import { canvasSupported, mountCanvas, paintCanvas } from './paint.js';
|
|
18
21
|
import { trackPointer } from './pointer.js';
|
|
19
22
|
import { prefersReducedMotion } from './reduced.js';
|
|
20
23
|
function mountScene(el, definition, depth) {
|
|
21
24
|
el.innerHTML = renderAvatarScene(definition, { depth });
|
|
22
25
|
const q = (s) => el.querySelector(s);
|
|
26
|
+
const stacks = { z: q('[data-stack="z"]'), x: q('[data-stack="x"]') };
|
|
23
27
|
return {
|
|
24
28
|
key: q('[data-avatar-scene]').dataset.avatarScene ?? '',
|
|
25
29
|
geometry: geometryKey(definition),
|
|
26
30
|
motion: q('[data-motion]'),
|
|
27
31
|
view: q('[data-view]'),
|
|
28
|
-
stacks
|
|
32
|
+
stacks,
|
|
33
|
+
slices: { z: [...stacks.z.children], x: [...stacks.x.children] },
|
|
29
34
|
eyes: [0, 1].map((i) => {
|
|
30
35
|
const root = q(`[data-eye="${i}"]`);
|
|
31
36
|
return { root, pill: root.querySelector('i'), arc: root.querySelector('svg') };
|
|
@@ -43,8 +48,11 @@ function put(m, key, el, prop, value) {
|
|
|
43
48
|
function apply(m, frame) {
|
|
44
49
|
put(m, 'motion', m.motion, 'transform', frame.motion);
|
|
45
50
|
put(m, 'view', m.view, 'transform', frame.view);
|
|
46
|
-
|
|
47
|
-
put(m, '
|
|
51
|
+
// display:none, not visibility: hidden slices would still each hold a 3D layer.
|
|
52
|
+
put(m, 'z', m.stacks.z, 'display', frame.stack === 'z' ? 'block' : 'none');
|
|
53
|
+
put(m, 'x', m.stacks.x, 'display', frame.stack === 'x' ? 'block' : 'none');
|
|
54
|
+
const slices = m.slices[frame.stack];
|
|
55
|
+
frame.slices.forEach((shown, i) => slices[i] && put(m, `${frame.stack}${i}`, slices[i], 'display', shown ? 'block' : 'none'));
|
|
48
56
|
frame.eyes.forEach((eye, i) => {
|
|
49
57
|
const e = m.eyes[i];
|
|
50
58
|
put(m, `e${i}`, e.root, 'transform', eye.transform);
|
|
@@ -54,6 +62,8 @@ function apply(m, frame) {
|
|
|
54
62
|
put(m, `a${i}`, e.arc, 'display', eye.happy ? 'block' : 'none');
|
|
55
63
|
});
|
|
56
64
|
}
|
|
65
|
+
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
66
|
+
const isHex = (c) => c === undefined || HEX.test(c);
|
|
57
67
|
const keys = new WeakMap();
|
|
58
68
|
/** Everything in a definition the static scene markup depends on. */
|
|
59
69
|
function geometryKey(definition) {
|
|
@@ -70,15 +80,47 @@ function eyesOrigin(definition) {
|
|
|
70
80
|
const at = (v) => (typeof v === 'number' && Number.isFinite(v) ? Math.min(1, Math.max(0, v / 100)) : 0.5);
|
|
71
81
|
return { x: at(x), y: at(y) };
|
|
72
82
|
}
|
|
83
|
+
/** Avatars smaller than this (CSS px) redraw at SMALL_FPS: the difference doesn't show, and pages often hold many. */
|
|
84
|
+
const SMALL_SIZE = 128;
|
|
85
|
+
const SMALL_FPS = 30;
|
|
86
|
+
/** How far outside the viewport (CSS px) avatars keep animating, so they are already moving as they scroll in. */
|
|
87
|
+
const VIEW_MARGIN = 100;
|
|
88
|
+
/** Slack so a 60 Hz display reliably draws every other frame rather than drifting between 1 and 3. */
|
|
89
|
+
const FRAME_SLACK = 0.004;
|
|
73
90
|
export function mountAvatar(host, initial) {
|
|
74
91
|
let opts = { ...initial };
|
|
75
92
|
const animator = createAnimator();
|
|
76
93
|
let rect = null;
|
|
77
94
|
let scene = null;
|
|
95
|
+
let surface = null;
|
|
78
96
|
let lastStill = '';
|
|
79
97
|
let failed = false;
|
|
80
98
|
let dirty = true;
|
|
81
99
|
let releasePointer = null;
|
|
100
|
+
let size = host.clientWidth;
|
|
101
|
+
const resize = typeof ResizeObserver === 'undefined'
|
|
102
|
+
? null
|
|
103
|
+
: new ResizeObserver(([entry]) => {
|
|
104
|
+
const next = entry.contentRect.width;
|
|
105
|
+
if (next === size)
|
|
106
|
+
return;
|
|
107
|
+
size = next;
|
|
108
|
+
requestFrame();
|
|
109
|
+
});
|
|
110
|
+
resize?.observe(host);
|
|
111
|
+
/** Whether the host is in or near the viewport. Offscreen, a live avatar only redraws after a change. */
|
|
112
|
+
let visible = true;
|
|
113
|
+
const intersect = typeof IntersectionObserver === 'undefined'
|
|
114
|
+
? null
|
|
115
|
+
: new IntersectionObserver((entries) => {
|
|
116
|
+
const next = entries[entries.length - 1].isIntersecting;
|
|
117
|
+
if (next === visible)
|
|
118
|
+
return;
|
|
119
|
+
visible = next;
|
|
120
|
+
if (visible)
|
|
121
|
+
requestFrame();
|
|
122
|
+
}, { rootMargin: `${VIEW_MARGIN}px` });
|
|
123
|
+
intersect?.observe(host);
|
|
82
124
|
if (getComputedStyle(host).position === 'static')
|
|
83
125
|
host.style.position = 'relative';
|
|
84
126
|
const syncHost = () => {
|
|
@@ -106,6 +148,7 @@ export function mountAvatar(host, initial) {
|
|
|
106
148
|
const clear = () => {
|
|
107
149
|
host.textContent = '';
|
|
108
150
|
scene = null;
|
|
151
|
+
surface = null;
|
|
109
152
|
lastStill = '';
|
|
110
153
|
};
|
|
111
154
|
const draw = (time, pointer) => {
|
|
@@ -114,7 +157,7 @@ export function mountAvatar(host, initial) {
|
|
|
114
157
|
const now = performance.now();
|
|
115
158
|
try {
|
|
116
159
|
if (p.still) {
|
|
117
|
-
if (scene)
|
|
160
|
+
if (scene || surface)
|
|
118
161
|
clear();
|
|
119
162
|
const svg = renderAvatarSvg(p.definition, {
|
|
120
163
|
color: p.color,
|
|
@@ -145,11 +188,30 @@ export function mountAvatar(host, initial) {
|
|
|
145
188
|
depth: p.depth,
|
|
146
189
|
motion: p.mood ?? 'idle',
|
|
147
190
|
motionBlend: step.motionBlend,
|
|
191
|
+
size: size || undefined,
|
|
148
192
|
time,
|
|
149
193
|
gaze: step.gaze,
|
|
150
194
|
view: p.view,
|
|
151
195
|
reducedMotion,
|
|
152
196
|
};
|
|
197
|
+
if (p.renderer !== 'scene' && canvasSupported()) {
|
|
198
|
+
if (scene)
|
|
199
|
+
clear();
|
|
200
|
+
const flat = liveFrame(p.definition, { ...options, color: p.color, eyeColor: p.eyeColor });
|
|
201
|
+
const key = `${geometryKey(p.definition)}|${p.depth}`;
|
|
202
|
+
if (!surface || surface.key !== key || !host.contains(surface.canvas))
|
|
203
|
+
surface = mountCanvas(host, key, p.definition, p.depth);
|
|
204
|
+
// Any CSS color works, as in the scene: one that is not hex is read back every frame from the
|
|
205
|
+
// host's computed `color` and --avatar-ink (which syncHost sets), so themes apply live.
|
|
206
|
+
const css = isHex(p.color) && isHex(p.eyeColor) ? null : getComputedStyle(host);
|
|
207
|
+
const fill = css && !isHex(p.color) ? css.color || flat.color : flat.color;
|
|
208
|
+
const ink = css && !isHex(p.eyeColor) ? css.getPropertyValue('--avatar-ink').trim() || flat.ink : flat.ink;
|
|
209
|
+
paintCanvas(surface, flat, size, fill, ink);
|
|
210
|
+
failed = false;
|
|
211
|
+
return !reducedMotion || step.moving;
|
|
212
|
+
}
|
|
213
|
+
if (surface)
|
|
214
|
+
clear();
|
|
153
215
|
const frame = sceneFrame(p.definition, options);
|
|
154
216
|
if (!scene || scene.key !== frame.scene || scene.geometry !== geometryKey(p.definition) || !host.contains(scene.view)) {
|
|
155
217
|
scene = mountScene(host, p.definition, p.depth);
|
|
@@ -170,14 +232,18 @@ export function mountAvatar(host, initial) {
|
|
|
170
232
|
syncHost();
|
|
171
233
|
const unsubscribe = subscribeFrames({
|
|
172
234
|
measure: () => {
|
|
173
|
-
rect = opts.followPointer && !opts.still && !opts.holdGaze && !opts.lookAt ? host.getBoundingClientRect() : null;
|
|
235
|
+
rect = visible && opts.followPointer && !opts.still && !opts.holdGaze && !opts.lookAt ? host.getBoundingClientRect() : null;
|
|
174
236
|
},
|
|
175
237
|
draw: (time, pointer) => {
|
|
176
|
-
// Stills only redraw after a change; live avatars
|
|
177
|
-
|
|
238
|
+
// Stills, and live avatars out of view, only redraw after a change; live avatars in view every
|
|
239
|
+
// frame they ask for. A change still draws offscreen, so the content is current when printed.
|
|
240
|
+
if ((opts.still || !visible) && !dirty)
|
|
178
241
|
return false;
|
|
179
242
|
dirty = false;
|
|
180
|
-
|
|
243
|
+
const more = draw(time, pointer);
|
|
244
|
+
if (!visible)
|
|
245
|
+
return false;
|
|
246
|
+
return more && size > 0 && size < SMALL_SIZE ? 1 / SMALL_FPS - FRAME_SLACK : more;
|
|
181
247
|
},
|
|
182
248
|
});
|
|
183
249
|
return {
|
|
@@ -189,6 +255,8 @@ export function mountAvatar(host, initial) {
|
|
|
189
255
|
},
|
|
190
256
|
destroy() {
|
|
191
257
|
unsubscribe();
|
|
258
|
+
resize?.disconnect();
|
|
259
|
+
intersect?.disconnect();
|
|
192
260
|
releasePointer?.();
|
|
193
261
|
releasePointer = null;
|
|
194
262
|
clear();
|
package/dist/dom/mount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../../src/dom/mount.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAEjI,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,c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AU,EAAE,CAAC;YACxB,cAAc,EAAE,EAAE,CAAC;YACnB,cAAc,GAAG,IAAI,CAAC;YACtB,KAAK,EAAE,CAAC;QACV,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AvatarFrame, Matrix } from '../render.ts';
|
|
2
|
+
import type { AvatarDefinition } from '../types.ts';
|
|
3
|
+
/** A square in viewBox units. */
|
|
4
|
+
export interface Square {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
size: number;
|
|
8
|
+
}
|
|
9
|
+
/** An axis-aligned box in viewBox units; empty when x0 > x1. */
|
|
10
|
+
export interface Bounds {
|
|
11
|
+
x0: number;
|
|
12
|
+
y0: number;
|
|
13
|
+
x1: number;
|
|
14
|
+
y1: number;
|
|
15
|
+
}
|
|
16
|
+
/** Slack around a frame's bounds when the bitmap is laid out, viewBox units: idle motion and gaze stay inside it. */
|
|
17
|
+
export declare const FIT_SLACK = 8;
|
|
18
|
+
/** Margin a frame keeps from the bitmap's edge for antialiasing, viewBox units. */
|
|
19
|
+
export declare const FIT_PAD = 1;
|
|
20
|
+
/**
|
|
21
|
+
* The square to lay the bitmap out over: `prev` while it still holds `b`, else `prev` grown to
|
|
22
|
+
* hold `b` with slack. Never larger than `cap` unless `b` itself leaves `cap`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function fitSquare(prev: Square | null, b: Bounds, cap: Square): Square;
|
|
25
|
+
/** Whether this environment can paint avatars: a 2D canvas and Path2D (jsdom has neither). */
|
|
26
|
+
export declare function canvasSupported(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Each shape's matrix with the frame's root motion applied, and the bounds of everything the frame
|
|
29
|
+
* paints, in viewBox units. Pure.
|
|
30
|
+
*/
|
|
31
|
+
export declare function framePlacement(frame: AvatarFrame): {
|
|
32
|
+
matrices: Matrix[];
|
|
33
|
+
bounds: Bounds;
|
|
34
|
+
};
|
|
35
|
+
/** A mounted canvas and the square and size its bitmap was last laid out at. */
|
|
36
|
+
export interface CanvasSurface {
|
|
37
|
+
key: string;
|
|
38
|
+
canvas: HTMLCanvasElement;
|
|
39
|
+
ctx: CanvasRenderingContext2D | null;
|
|
40
|
+
cap: Square;
|
|
41
|
+
fit: Square | null;
|
|
42
|
+
layout: string;
|
|
43
|
+
left: number;
|
|
44
|
+
top: number;
|
|
45
|
+
}
|
|
46
|
+
export declare function mountCanvas(el: HTMLElement, key: string, definition: AvatarDefinition, depth: number | undefined): CanvasSurface;
|
|
47
|
+
/** Paint one frame `size` CSS pixels wide. `fill` and `ink` override the frame's colors with any canvas color. */
|
|
48
|
+
export declare function paintCanvas(surface: CanvasSurface, frame: AvatarFrame, size: number, fill?: string, ink?: string): void;
|
|
49
|
+
//# sourceMappingURL=paint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paint.d.ts","sourceRoot":"","sources":["../../src/dom/paint.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,iCAAiC;AACjC,MAAM,WAAW,MAAM;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gEAAgE;AAChE,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,qHAAqH;AACrH,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,mFAAmF;AACnF,eAAO,MAAM,OAAO,IAAI,CAAC;AAEzB;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAsB7E;AAWD,8FAA8F;AAC9F,wBAAgB,eAAe,IAAI,OAAO,CAMzC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAwBzF;AAgCD,gFAAgF;AAChF,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAWhI;AAED,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,SAAc,EAAE,GAAG,SAAY,QA4CxH"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canvas renderer, the default for live avatars: paints flat avatar frames
|
|
3
|
+
* to one canvas, so an avatar costs one compositor layer and one small bitmap
|
|
4
|
+
* however many slices it shows. Equal geometry shares its parsed paths.
|
|
5
|
+
*
|
|
6
|
+
* The bitmap covers what the frames actually paint, plus slack, and only grows
|
|
7
|
+
* while the avatar's size and the pixel ratio stay the same. A GPU canvas that
|
|
8
|
+
* animates antialiased paths holds several times its bitmap in video memory,
|
|
9
|
+
* so covering every possible view up front (avatarExtent, kept as the upper
|
|
10
|
+
* bound) would cost about three times as much.
|
|
11
|
+
*
|
|
12
|
+
* The canvas sits in a wrapper at the host's content box, as the scene does,
|
|
13
|
+
* overhangs it by the avatar's reach and ignores the pointer.
|
|
14
|
+
*/
|
|
15
|
+
import { avatarExtent } from '../render.js';
|
|
16
|
+
/** Slack around a frame's bounds when the bitmap is laid out, viewBox units: idle motion and gaze stay inside it. */
|
|
17
|
+
export const FIT_SLACK = 8;
|
|
18
|
+
/** Margin a frame keeps from the bitmap's edge for antialiasing, viewBox units. */
|
|
19
|
+
export const FIT_PAD = 1;
|
|
20
|
+
/**
|
|
21
|
+
* The square to lay the bitmap out over: `prev` while it still holds `b`, else `prev` grown to
|
|
22
|
+
* hold `b` with slack. Never larger than `cap` unless `b` itself leaves `cap`.
|
|
23
|
+
*/
|
|
24
|
+
export function fitSquare(prev, b, cap) {
|
|
25
|
+
if (!(b.x0 <= b.x1 && b.y0 <= b.y1))
|
|
26
|
+
return prev ?? cap;
|
|
27
|
+
if (prev &&
|
|
28
|
+
b.x0 - FIT_PAD >= prev.x &&
|
|
29
|
+
b.y0 - FIT_PAD >= prev.y &&
|
|
30
|
+
b.x1 + FIT_PAD <= prev.x + prev.size &&
|
|
31
|
+
b.y1 + FIT_PAD <= prev.y + prev.size) {
|
|
32
|
+
return prev;
|
|
33
|
+
}
|
|
34
|
+
let x0 = b.x0 - FIT_SLACK, y0 = b.y0 - FIT_SLACK, x1 = b.x1 + FIT_SLACK, y1 = b.y1 + FIT_SLACK;
|
|
35
|
+
if (prev) {
|
|
36
|
+
x0 = Math.min(x0, prev.x);
|
|
37
|
+
y0 = Math.min(y0, prev.y);
|
|
38
|
+
x1 = Math.max(x1, prev.x + prev.size);
|
|
39
|
+
y1 = Math.max(y1, prev.y + prev.size);
|
|
40
|
+
}
|
|
41
|
+
const size = Math.max(x1 - x0, y1 - y0);
|
|
42
|
+
const inCap = b.x0 >= cap.x && b.y0 >= cap.y && b.x1 <= cap.x + cap.size && b.y1 <= cap.y + cap.size;
|
|
43
|
+
if (size >= cap.size && inCap)
|
|
44
|
+
return cap;
|
|
45
|
+
return { x: (x0 + x1 - size) / 2, y: (y0 + y1 - size) / 2, size };
|
|
46
|
+
}
|
|
47
|
+
const MAX_SECTIONS = 4096;
|
|
48
|
+
const sections = new Map();
|
|
49
|
+
let supported;
|
|
50
|
+
/** Whether this environment can paint avatars: a 2D canvas and Path2D (jsdom has neither). */
|
|
51
|
+
export function canvasSupported() {
|
|
52
|
+
if (supported === undefined) {
|
|
53
|
+
// Path2D first: asking jsdom for a context logs a "not implemented" error.
|
|
54
|
+
supported = typeof Path2D !== 'undefined' && typeof document !== 'undefined' && !!document.createElement('canvas').getContext('2d');
|
|
55
|
+
}
|
|
56
|
+
return supported;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Each shape's matrix with the frame's root motion applied, and the bounds of everything the frame
|
|
60
|
+
* paints, in viewBox units. Pure.
|
|
61
|
+
*/
|
|
62
|
+
export function framePlacement(frame) {
|
|
63
|
+
const boxes = new Map(frame.paths.map((p) => [p.id, p.box]));
|
|
64
|
+
const [ra, rb, rc, rd, re, rf] = frame.root;
|
|
65
|
+
const bounds = { x0: Infinity, y0: Infinity, x1: -Infinity, y1: -Infinity };
|
|
66
|
+
const add = (m, x, y) => {
|
|
67
|
+
const X = m[0] * x + m[2] * y + m[4], Y = m[1] * x + m[3] * y + m[5];
|
|
68
|
+
if (X < bounds.x0)
|
|
69
|
+
bounds.x0 = X;
|
|
70
|
+
if (X > bounds.x1)
|
|
71
|
+
bounds.x1 = X;
|
|
72
|
+
if (Y < bounds.y0)
|
|
73
|
+
bounds.y0 = Y;
|
|
74
|
+
if (Y > bounds.y1)
|
|
75
|
+
bounds.y1 = Y;
|
|
76
|
+
};
|
|
77
|
+
const matrices = frame.shapes.map((shape) => {
|
|
78
|
+
const [a, b, c, d, e, f] = shape.matrix;
|
|
79
|
+
const m = [ra * a + rc * b, rb * a + rd * b, ra * c + rc * d, rb * c + rd * d, ra * e + rc * f + re, rb * e + rd * f + rf];
|
|
80
|
+
const box = shape.kind === 'slice' ? boxes.get(shape.path) : eyeBox(shape.mark);
|
|
81
|
+
if (box) {
|
|
82
|
+
add(m, box.x, box.y);
|
|
83
|
+
add(m, box.x + box.w, box.y);
|
|
84
|
+
add(m, box.x, box.y + box.h);
|
|
85
|
+
add(m, box.x + box.w, box.y + box.h);
|
|
86
|
+
}
|
|
87
|
+
return m;
|
|
88
|
+
});
|
|
89
|
+
return { matrices, bounds };
|
|
90
|
+
}
|
|
91
|
+
function eyeBox(mark) {
|
|
92
|
+
if (mark.shape === 'pill')
|
|
93
|
+
return { x: mark.x, y: mark.y, w: mark.width, h: mark.height };
|
|
94
|
+
// A quadratic arc lies within its points' hull; the stroke reaches half its width past it.
|
|
95
|
+
const n = (mark.d.match(/-?\d+(?:\.\d+)?/g) ?? []).map(Number);
|
|
96
|
+
const xs = n.filter((_, i) => i % 2 === 0), ys = n.filter((_, i) => i % 2 === 1);
|
|
97
|
+
const x = Math.min(...xs) - mark.strokeWidth, y = Math.min(...ys) - mark.strokeWidth;
|
|
98
|
+
return { x, y, w: Math.max(...xs) + mark.strokeWidth - x, h: Math.max(...ys) + mark.strokeWidth - y };
|
|
99
|
+
}
|
|
100
|
+
function eye(ctx, mark) {
|
|
101
|
+
if (mark.shape === 'arc') {
|
|
102
|
+
ctx.lineWidth = mark.strokeWidth;
|
|
103
|
+
ctx.stroke(new Path2D(mark.d));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const { x, y, width: w, height: h, radius: r } = mark;
|
|
107
|
+
ctx.beginPath();
|
|
108
|
+
if (typeof ctx.roundRect === 'function')
|
|
109
|
+
ctx.roundRect(x, y, w, h, r);
|
|
110
|
+
else {
|
|
111
|
+
// Safari before 16 and Firefox before 112.
|
|
112
|
+
ctx.moveTo(x + r, y);
|
|
113
|
+
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
114
|
+
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
115
|
+
ctx.arcTo(x, y + h, x, y, r);
|
|
116
|
+
ctx.arcTo(x, y, x + w, y, r);
|
|
117
|
+
ctx.closePath();
|
|
118
|
+
}
|
|
119
|
+
ctx.fill();
|
|
120
|
+
}
|
|
121
|
+
export function mountCanvas(el, key, definition, depth) {
|
|
122
|
+
const cap = avatarExtent(definition, depth);
|
|
123
|
+
const wrap = document.createElement('div');
|
|
124
|
+
// In flow at the content box, like the scene's root, so the host's padding and border place it.
|
|
125
|
+
wrap.style.cssText = 'position:relative;width:100%;height:100%;pointer-events:none';
|
|
126
|
+
const canvas = document.createElement('canvas');
|
|
127
|
+
canvas.setAttribute('aria-hidden', 'true');
|
|
128
|
+
canvas.style.cssText = 'position:absolute';
|
|
129
|
+
wrap.append(canvas);
|
|
130
|
+
el.replaceChildren(wrap);
|
|
131
|
+
return { key, canvas, ctx: canvas.getContext('2d'), cap, fit: null, layout: '', left: 0, top: 0 };
|
|
132
|
+
}
|
|
133
|
+
/** Paint one frame `size` CSS pixels wide. `fill` and `ink` override the frame's colors with any canvas color. */
|
|
134
|
+
export function paintCanvas(surface, frame, size, fill = frame.color, ink = frame.ink) {
|
|
135
|
+
const { canvas, ctx } = surface;
|
|
136
|
+
if (!ctx || size <= 0)
|
|
137
|
+
return;
|
|
138
|
+
const dpr = window.devicePixelRatio || 1;
|
|
139
|
+
const scale = (size / 100) * dpr;
|
|
140
|
+
const layout = `${size}|${dpr}`;
|
|
141
|
+
if (sections.size > MAX_SECTIONS)
|
|
142
|
+
sections.clear();
|
|
143
|
+
for (const { id, d, evenOdd } of frame.paths) {
|
|
144
|
+
if (!sections.has(id))
|
|
145
|
+
sections.set(id, { path: new Path2D(d), rule: evenOdd ? 'evenodd' : 'nonzero' });
|
|
146
|
+
}
|
|
147
|
+
const { matrices, bounds } = framePlacement(frame);
|
|
148
|
+
const fit = fitSquare(surface.layout === layout ? surface.fit : null, bounds, surface.cap);
|
|
149
|
+
if (surface.layout === layout && fit === surface.fit) {
|
|
150
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
151
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// Whole device pixels, so the bitmap is never resampled. Setting the width also clears it.
|
|
155
|
+
surface.layout = layout;
|
|
156
|
+
surface.fit = fit;
|
|
157
|
+
surface.left = Math.floor(fit.x * scale);
|
|
158
|
+
surface.top = Math.floor(fit.y * scale);
|
|
159
|
+
const bitmap = Math.ceil(fit.size * scale) + 1;
|
|
160
|
+
canvas.width = canvas.height = bitmap;
|
|
161
|
+
canvas.style.left = `${surface.left / dpr}px`;
|
|
162
|
+
canvas.style.top = `${surface.top / dpr}px`;
|
|
163
|
+
canvas.style.width = canvas.style.height = `${bitmap / dpr}px`;
|
|
164
|
+
}
|
|
165
|
+
ctx.lineCap = 'round';
|
|
166
|
+
ctx.strokeStyle = ink;
|
|
167
|
+
ctx.fillStyle = fill;
|
|
168
|
+
// Shapes run in the thousands per second across a page: one setTransform each beats save/restore.
|
|
169
|
+
for (let i = 0; i < frame.shapes.length; i++) {
|
|
170
|
+
const shape = frame.shapes[i], m = matrices[i];
|
|
171
|
+
ctx.setTransform(scale * m[0], scale * m[1], scale * m[2], scale * m[3], scale * m[4] - surface.left, scale * m[5] - surface.top);
|
|
172
|
+
if (shape.kind === 'slice') {
|
|
173
|
+
const section = sections.get(shape.path);
|
|
174
|
+
ctx.fill(section.path, section.rule);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
ctx.fillStyle = ink;
|
|
178
|
+
eye(ctx, shape.mark);
|
|
179
|
+
ctx.fillStyle = fill;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=paint.js.map
|