@wallarm-org/design-system 4.6.2 → 4.7.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/dist/components/AgentAvatar/AgentAvatar.d.ts +45 -0
- package/dist/components/AgentAvatar/AgentAvatar.js +544 -0
- package/dist/components/AgentAvatar/AgentAvatarGroup.d.ts +12 -0
- package/dist/components/AgentAvatar/AgentAvatarGroup.js +25 -0
- package/dist/components/AgentAvatar/index.d.ts +4 -0
- package/dist/components/AgentAvatar/index.js +3 -0
- package/dist/components/AgentAvatar/useBakedLayers.d.ts +9 -0
- package/dist/components/AgentAvatar/useBakedLayers.js +75 -0
- package/dist/components/AgentAvatar/useCharacter.d.ts +39 -0
- package/dist/components/AgentAvatar/useCharacter.js +251 -0
- package/dist/components/AgentGlyph/AgentGlyph.d.ts +30 -0
- package/dist/components/AgentGlyph/AgentGlyph.js +192 -0
- package/dist/components/AgentGlyph/index.d.ts +4 -0
- package/dist/components/AgentGlyph/index.js +2 -0
- package/dist/components/AgentLookBuilder/index.d.ts +3 -0
- package/dist/components/AgentLookBuilder/index.js +2 -0
- package/dist/components/AgentLookBuilder/kit.d.ts +36 -0
- package/dist/components/AgentLookBuilder/kit.js +30 -0
- package/dist/components/Chat/ChatGreeting.d.ts +1 -1
- package/dist/components/Chat/ChatGreeting.js +95 -44
- package/dist/components/Chat/ChatHeaderTitle.d.ts +1 -1
- package/dist/components/Chat/ChatHeaderTitle.js +32 -29
- package/dist/components/WallySkeleton/WallySkeleton.js +92 -71
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/agent-characters/bake.d.ts +40 -0
- package/dist/lib/agent-characters/bake.js +220 -0
- package/dist/lib/agent-characters/canvas.d.ts +7 -0
- package/dist/lib/agent-characters/canvas.js +22 -0
- package/dist/lib/agent-characters/char.d.ts +32 -0
- package/dist/lib/agent-characters/char.js +375 -0
- package/dist/lib/agent-characters/color.d.ts +6 -0
- package/dist/lib/agent-characters/color.js +20 -0
- package/dist/lib/agent-characters/data.gen.d.ts +106 -0
- package/dist/lib/agent-characters/data.gen.js +3854 -0
- package/dist/lib/agent-characters/engine.d.ts +206 -0
- package/dist/lib/agent-characters/engine.js +1241 -0
- package/dist/lib/agent-characters/eyes.d.ts +18 -0
- package/dist/lib/agent-characters/eyes.js +132 -0
- package/dist/lib/agent-characters/geom.d.ts +23 -0
- package/dist/lib/agent-characters/geom.js +109 -0
- package/dist/lib/agent-characters/glyph.d.ts +21 -0
- package/dist/lib/agent-characters/glyph.js +126 -0
- package/dist/lib/agent-characters/look.d.ts +24 -0
- package/dist/lib/agent-characters/look.js +68 -0
- package/dist/lib/agent-characters/motion.d.ts +73 -0
- package/dist/lib/agent-characters/motion.js +1215 -0
- package/dist/lib/agent-characters/paths.d.ts +13 -0
- package/dist/lib/agent-characters/paths.js +118 -0
- package/dist/lib/agent-characters/places.d.ts +76 -0
- package/dist/lib/agent-characters/places.js +64 -0
- package/dist/lib/agent-characters/propOf.d.ts +7 -0
- package/dist/lib/agent-characters/propOf.js +20 -0
- package/dist/lib/agent-characters/props.d.ts +4 -0
- package/dist/lib/agent-characters/props.js +337 -0
- package/dist/lib/agent-characters/queue.d.ts +23 -0
- package/dist/lib/agent-characters/queue.js +73 -0
- package/dist/lib/agent-characters/runtime.d.ts +69 -0
- package/dist/lib/agent-characters/runtime.js +178 -0
- package/dist/lib/agent-characters/svg.d.ts +6 -0
- package/dist/lib/agent-characters/svg.js +6 -0
- package/dist/lib/agent-characters/worker.d.ts +6 -0
- package/dist/lib/agent-characters/worker.js +94 -0
- package/dist/metadata/components.json +689 -276
- package/dist/theme/components/agent-avatar.css +42 -0
- package/dist/theme/index.css +1 -0
- package/dist/utils/renderSvgNode.d.ts +4 -0
- package/dist/utils/renderSvgNode.js +12 -0
- package/package.json +2 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentShapeDef } from './data.gen.js';
|
|
2
|
+
export type StateId = 'idle' | 'hello' | 'working' | 'needs' | 'done' | 'failed' | 'off' | 'box' | 'power' | 'invite' | 'partly';
|
|
3
|
+
export interface EyePose {
|
|
4
|
+
w: number;
|
|
5
|
+
ht: number;
|
|
6
|
+
hb: number;
|
|
7
|
+
kt: number;
|
|
8
|
+
kb: number;
|
|
9
|
+
lid: number;
|
|
10
|
+
rot: number;
|
|
11
|
+
bright: number;
|
|
12
|
+
gy: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function eyeTargets(style: string, st: StateId): EyePose;
|
|
15
|
+
/** "Hello": the eyes pop open, wider and brighter, before the arcs. */
|
|
16
|
+
export declare const helloPop: (b: EyePose) => EyePose;
|
|
17
|
+
export declare function eyeD(cx: number, cyIn: number, w: number, ht: number, hb: number, kt: number, kb: number, lid: number, rot: number, open: number, s: number): string;
|
|
18
|
+
export declare function eyesPath(S: AgentShapeDef, e: EyePose, open: number, gx?: number, gy?: number): string;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { EYE_BASE } from "./data.gen.js";
|
|
2
|
+
import { r2 } from "./paths.js";
|
|
3
|
+
function eyeTargets(style, st) {
|
|
4
|
+
const b = {
|
|
5
|
+
...EYE_BASE[style] || EYE_BASE.oval,
|
|
6
|
+
rot: 0,
|
|
7
|
+
bright: 1,
|
|
8
|
+
gy: 0
|
|
9
|
+
};
|
|
10
|
+
switch(st){
|
|
11
|
+
case 'working':
|
|
12
|
+
return {
|
|
13
|
+
...b,
|
|
14
|
+
ht: 0.5 * b.ht,
|
|
15
|
+
hb: 0.5 * b.hb,
|
|
16
|
+
kt: 0.7,
|
|
17
|
+
kb: 0.7,
|
|
18
|
+
lid: Math.min(1, b.lid + 0.15)
|
|
19
|
+
};
|
|
20
|
+
case 'needs':
|
|
21
|
+
return {
|
|
22
|
+
...b,
|
|
23
|
+
w: 1.12 * b.w,
|
|
24
|
+
ht: 1.15 * b.ht,
|
|
25
|
+
hb: 1.15 * b.hb,
|
|
26
|
+
lid: Math.min(b.lid, 0.15)
|
|
27
|
+
};
|
|
28
|
+
case 'done':
|
|
29
|
+
case 'hello':
|
|
30
|
+
{
|
|
31
|
+
const ht = 0.95 * Math.max(b.ht, 1.1);
|
|
32
|
+
return {
|
|
33
|
+
...b,
|
|
34
|
+
w: 1.1 * b.w,
|
|
35
|
+
ht,
|
|
36
|
+
hb: -0.6 * ht,
|
|
37
|
+
kt: 0.6,
|
|
38
|
+
kb: 0.6,
|
|
39
|
+
lid: 0,
|
|
40
|
+
gy: -0.1
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
case 'failed':
|
|
44
|
+
return {
|
|
45
|
+
...b,
|
|
46
|
+
w: 1.05 * Math.max(b.w, 1),
|
|
47
|
+
ht: 0,
|
|
48
|
+
hb: 0,
|
|
49
|
+
lid: 0,
|
|
50
|
+
rot: 6,
|
|
51
|
+
bright: 0.7,
|
|
52
|
+
gy: 0.55
|
|
53
|
+
};
|
|
54
|
+
case 'off':
|
|
55
|
+
return {
|
|
56
|
+
...b,
|
|
57
|
+
w: 0.15 * b.w,
|
|
58
|
+
ht: 0.06,
|
|
59
|
+
hb: 0.06,
|
|
60
|
+
lid: 0,
|
|
61
|
+
bright: 0.12
|
|
62
|
+
};
|
|
63
|
+
case 'box':
|
|
64
|
+
case 'power':
|
|
65
|
+
return {
|
|
66
|
+
...b,
|
|
67
|
+
lid: 0.5,
|
|
68
|
+
ht: 1.15,
|
|
69
|
+
hb: 1.15,
|
|
70
|
+
kt: 0.55,
|
|
71
|
+
kb: 0.55,
|
|
72
|
+
bright: 0.35
|
|
73
|
+
};
|
|
74
|
+
case 'invite':
|
|
75
|
+
return {
|
|
76
|
+
...b,
|
|
77
|
+
lid: Math.min(b.lid, 0.3),
|
|
78
|
+
bright: 0.8
|
|
79
|
+
};
|
|
80
|
+
default:
|
|
81
|
+
return b;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const helloPop = (b)=>({
|
|
85
|
+
...b,
|
|
86
|
+
w: 1.16 * b.w,
|
|
87
|
+
ht: 1.28 * b.ht,
|
|
88
|
+
hb: 1.28 * b.hb,
|
|
89
|
+
kt: 0.55,
|
|
90
|
+
kb: 0.55,
|
|
91
|
+
lid: 0,
|
|
92
|
+
rot: 0,
|
|
93
|
+
bright: 1.15,
|
|
94
|
+
gy: -0.06
|
|
95
|
+
});
|
|
96
|
+
function eyeD(cx, cyIn, w, ht, hb, kt, kb, lid, rot, open, s) {
|
|
97
|
+
const h1 = ht * open * (1 - lid);
|
|
98
|
+
let h2 = hb * open;
|
|
99
|
+
const k1 = kt + (1 - kt) * 0.8 * lid;
|
|
100
|
+
const cy = cyIn + 0.25 * (1 - open) * ht;
|
|
101
|
+
if (h2 < -0.8 * h1) h2 = -0.8 * h1;
|
|
102
|
+
const W = Math.max(0.05, w - s / 2);
|
|
103
|
+
const T = Math.max(0, h1 - s / 2);
|
|
104
|
+
let B = h2 > 0 ? Math.max(0, h2 - s / 2) : h2 + s / 2;
|
|
105
|
+
if (B < -0.8 * T) B = -0.8 * T;
|
|
106
|
+
const a = rot * Math.PI / 180;
|
|
107
|
+
const c = Math.cos(a);
|
|
108
|
+
const sn = Math.sin(a);
|
|
109
|
+
const R = (x, y)=>`${r2(cx + (x - cx) * c - (y - cy) * sn)} ${r2(cy + (x - cx) * sn + (y - cy) * c)}`;
|
|
110
|
+
return `M${R(cx - W, cy)}C${R(cx - W, cy - k1 * T)} ${R(cx - k1 * W, cy - T)} ${R(cx, cy - T)}C${R(cx + k1 * W, cy - T)} ${R(cx + W, cy - k1 * T)} ${R(cx + W, cy)}C${R(cx + W, cy + kb * B)} ${R(cx + kb * W, cy + B)} ${R(cx, cy + B)}C${R(cx - kb * W, cy + B)} ${R(cx - W, cy + kb * B)} ${R(cx - W, cy)}Z`;
|
|
111
|
+
}
|
|
112
|
+
function eyesPath(S, e, open, gx = 0, gy = 0) {
|
|
113
|
+
const [vx, vy, vw, vh] = S.v;
|
|
114
|
+
const unit = 0.17 * vh;
|
|
115
|
+
const cy0 = vy + vh / 2;
|
|
116
|
+
let d = '';
|
|
117
|
+
for (const side of [
|
|
118
|
+
-1,
|
|
119
|
+
1
|
|
120
|
+
]){
|
|
121
|
+
const near = side * gx > 0 ? 1 + 0.08 * Math.abs(gx) : 1 - 0.06 * Math.abs(gx);
|
|
122
|
+
const wm = 1 - 0.1 * Math.abs(gx);
|
|
123
|
+
const cx = vx + vw * (0.5 + 0.2 * side) + 0.18 * gx * vw;
|
|
124
|
+
const cy = cy0 + 0.12 * gy * vh;
|
|
125
|
+
const w = e.w * unit * near * wm * (1 + 0.06 * (1 - open));
|
|
126
|
+
const s = 0.25 * e.w * unit;
|
|
127
|
+
const lid = Math.max(e.lid, 0.25 * Math.max(0, gy));
|
|
128
|
+
d += eyeD(cx, cy, w, e.ht * unit * near, e.hb * unit * near, e.kt, e.kb, lid, side * e.rot, open, s);
|
|
129
|
+
}
|
|
130
|
+
return d;
|
|
131
|
+
}
|
|
132
|
+
export { eyeD, eyeTargets, eyesPath, helloPop };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AgentShapeDef } from './data.gen.js';
|
|
2
|
+
export declare const SHAPE: Record<string, AgentShapeDef>;
|
|
3
|
+
export declare const shapeOf: (id: string) => AgentShapeDef;
|
|
4
|
+
/** Geometry analysis: top anchor, half-width per row (240 rows, y = i / 2), footprint at y 104. */
|
|
5
|
+
export interface Geom {
|
|
6
|
+
top: [number, number];
|
|
7
|
+
HW: Float32Array;
|
|
8
|
+
foot: [number, number];
|
|
9
|
+
}
|
|
10
|
+
export interface GeomView extends Geom {
|
|
11
|
+
hw: (y: number) => number;
|
|
12
|
+
}
|
|
13
|
+
/** Seeds the cache with known geometry (tests without a canvas, or precomputed data). */
|
|
14
|
+
export declare function primeGeom(id: string, g: Geom): void;
|
|
15
|
+
export declare function geom(S: AgentShapeDef): GeomView;
|
|
16
|
+
/** Optical centre: units below the viewBox centre (y 50); halfway between the body's box centre and its area centroid. */
|
|
17
|
+
export declare function optY(c: {
|
|
18
|
+
shape: string;
|
|
19
|
+
}): number;
|
|
20
|
+
/** The px to move the character up so its optical centre sits on the row's centre line. */
|
|
21
|
+
export declare const optPx: (c: {
|
|
22
|
+
shape: string;
|
|
23
|
+
}, size: number) => number;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createCanvas } from "./canvas.js";
|
|
2
|
+
import { GEOMS, SHAPES } from "./data.gen.js";
|
|
3
|
+
import { r2 } from "./paths.js";
|
|
4
|
+
const SHAPE = Object.fromEntries(SHAPES.map((s)=>[
|
|
5
|
+
s.id,
|
|
6
|
+
s
|
|
7
|
+
]));
|
|
8
|
+
const shapeOf = (id)=>SHAPE[id] || SHAPE.dome;
|
|
9
|
+
const GEOM = new Map();
|
|
10
|
+
const view = (g)=>({
|
|
11
|
+
...g,
|
|
12
|
+
hw: (y)=>{
|
|
13
|
+
const i = Math.round(2 * y);
|
|
14
|
+
return i >= 0 && i < 240 ? g.HW[i] : 0;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
function maskOf(d, N = 240, R = 120) {
|
|
18
|
+
const { ctx } = createCanvas(N);
|
|
19
|
+
ctx.scale(N / R, N / R);
|
|
20
|
+
ctx.fill(new Path2D(d));
|
|
21
|
+
return ctx.getImageData(0, 0, N, N).data;
|
|
22
|
+
}
|
|
23
|
+
function primeGeom(id, g) {
|
|
24
|
+
GEOM.set(id, view(g));
|
|
25
|
+
}
|
|
26
|
+
function geom(S) {
|
|
27
|
+
const cached = GEOM.get(S.id);
|
|
28
|
+
if (cached) return cached;
|
|
29
|
+
const known = GEOMS[S.id];
|
|
30
|
+
if (known && S.d === SHAPE[S.id]?.d) {
|
|
31
|
+
const g = view({
|
|
32
|
+
top: known.top,
|
|
33
|
+
HW: Float32Array.from(known.HW),
|
|
34
|
+
foot: known.foot
|
|
35
|
+
});
|
|
36
|
+
GEOM.set(S.id, g);
|
|
37
|
+
return g;
|
|
38
|
+
}
|
|
39
|
+
const N = 240;
|
|
40
|
+
const k = N / 120;
|
|
41
|
+
const body = maskOf(S.d);
|
|
42
|
+
const all = maskOf(S.d + (S.parts || []).map((p)=>p.d).join(''));
|
|
43
|
+
const at = (m, ux, uy)=>{
|
|
44
|
+
const x = Math.round(ux * k);
|
|
45
|
+
const y = Math.round(uy * k);
|
|
46
|
+
return x >= 0 && y >= 0 && x < N && y < N && m[(y * N + x) * 4 + 3] > 127;
|
|
47
|
+
};
|
|
48
|
+
let top = S.top;
|
|
49
|
+
if (!top) {
|
|
50
|
+
let ty = 120;
|
|
51
|
+
for(let y = 0; y < 120; y += 0.5)if (at(body, 60, y) || at(body, 58, y) || at(body, 62, y)) {
|
|
52
|
+
ty = y;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
top = [
|
|
56
|
+
60,
|
|
57
|
+
ty
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
const HW = new Float32Array(N);
|
|
61
|
+
for(let i = 0; i < N; i++){
|
|
62
|
+
const y = i / k;
|
|
63
|
+
let l = 0;
|
|
64
|
+
let r = 0;
|
|
65
|
+
while(l < 60 && at(body, top[0] - l - 0.5, y))l += 0.5;
|
|
66
|
+
while(r < 60 && at(body, top[0] + r + 0.5, y))r += 0.5;
|
|
67
|
+
HW[i] = Math.max(l, r);
|
|
68
|
+
}
|
|
69
|
+
let fl = 0;
|
|
70
|
+
let fr = 0;
|
|
71
|
+
for(let x = 0; x < 120; x += 0.5)if (at(all, x, 104)) {
|
|
72
|
+
fl = x;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
for(let x = 120; x > 0; x -= 0.5)if (at(all, x, 104)) {
|
|
76
|
+
fr = x;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
const g = view({
|
|
80
|
+
top,
|
|
81
|
+
HW,
|
|
82
|
+
foot: [
|
|
83
|
+
fl,
|
|
84
|
+
fr
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
GEOM.set(S.id, g);
|
|
88
|
+
return g;
|
|
89
|
+
}
|
|
90
|
+
const OPTY = new Map();
|
|
91
|
+
function optY(c) {
|
|
92
|
+
const S = shapeOf(c.shape);
|
|
93
|
+
const cached = OPTY.get(S.id);
|
|
94
|
+
if (void 0 !== cached) return cached;
|
|
95
|
+
const g = geom(S);
|
|
96
|
+
const top = g.top[1];
|
|
97
|
+
let sw = 0;
|
|
98
|
+
let sy = 0;
|
|
99
|
+
for(let y = top; y <= 108; y += 0.5){
|
|
100
|
+
const w = g.hw(y);
|
|
101
|
+
sw += w;
|
|
102
|
+
sy += w * y;
|
|
103
|
+
}
|
|
104
|
+
const v = ((top + 108) / 2 + (sw ? sy / sw : (top + 108) / 2)) / 2 - 50;
|
|
105
|
+
OPTY.set(S.id, v);
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
108
|
+
const optPx = (c, size)=>-r2(optY(c) * size / 136);
|
|
109
|
+
export { SHAPE, geom, optPx, optY, primeGeom, shapeOf };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type StateId } from './eyes.js';
|
|
2
|
+
import { type SvgNode } from './svg.js';
|
|
3
|
+
export interface Look {
|
|
4
|
+
shape: string;
|
|
5
|
+
color: string;
|
|
6
|
+
eyes: string;
|
|
7
|
+
prop: string;
|
|
8
|
+
}
|
|
9
|
+
export interface GlyphTree {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
/** the optical lift in px (optPx): negative moves the character up */
|
|
13
|
+
oy: number;
|
|
14
|
+
/** whole-SVG opacity (Not set up) */
|
|
15
|
+
opacity?: number;
|
|
16
|
+
children: SvgNode[];
|
|
17
|
+
}
|
|
18
|
+
/** The flat 16–32 px character as nodes. `clipId` names the Partial coverage crown's clip (unique per document). */
|
|
19
|
+
export declare function glyphTree(c: Look, size: number, state: StateId, clipId: string): GlyphTree;
|
|
20
|
+
/** The page's glyph() string, byte for byte (parity tests and the side-by-side harness). */
|
|
21
|
+
export declare function glyph(c: Look, size: number, state?: StateId): string;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { hexOf, luma, mix } from "./color.js";
|
|
2
|
+
import { GLYPH_PROPS, TONE } from "./data.gen.js";
|
|
3
|
+
import { eyeTargets, eyesPath } from "./eyes.js";
|
|
4
|
+
import { geom, optPx, shapeOf } from "./geom.js";
|
|
5
|
+
import { r2 } from "./paths.js";
|
|
6
|
+
import { propOf } from "./propOf.js";
|
|
7
|
+
import { toSvgString } from "./svg.js";
|
|
8
|
+
let GUID = 0;
|
|
9
|
+
function glyphTree(c, size, state, clipId) {
|
|
10
|
+
const S = shapeOf(c.shape);
|
|
11
|
+
const col = hexOf(c.color);
|
|
12
|
+
const [vx, vy, vw, vh] = S.v;
|
|
13
|
+
const vr = 0.46 * vh;
|
|
14
|
+
const ghost = 'box' === state;
|
|
15
|
+
const off = 'off' === state;
|
|
16
|
+
const inv = 'invite' === state;
|
|
17
|
+
const pt = 'partly' === state;
|
|
18
|
+
const st = pt ? 'idle' : state;
|
|
19
|
+
const fc = ghost || inv ? '#C9CED6' : off ? mix(col, '#B8BCC4', 0.6) : col;
|
|
20
|
+
const sw = r2(136 / size);
|
|
21
|
+
const pc = (p)=>ghost || inv ? '#C9CED6' : TONE[p.tone];
|
|
22
|
+
const parts = S.parts || [];
|
|
23
|
+
const L = (d, f)=>({
|
|
24
|
+
tag: 'path',
|
|
25
|
+
attrs: {
|
|
26
|
+
d,
|
|
27
|
+
fill: f,
|
|
28
|
+
stroke: mix(f, '#0d0b0c', 0.28),
|
|
29
|
+
'stroke-width': sw,
|
|
30
|
+
'stroke-linejoin': 'round'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const out = [
|
|
34
|
+
...parts.filter((p)=>'b' === p.z).map((p)=>L(p.d, pc(p))),
|
|
35
|
+
L(S.d, fc),
|
|
36
|
+
...parts.filter((p)=>'b' !== p.z).map((p)=>L(p.d, pc(p)))
|
|
37
|
+
];
|
|
38
|
+
if (pt) {
|
|
39
|
+
const ct = geom(S).top[1];
|
|
40
|
+
const cy = Math.min(ct + 0.3 * (108 - ct), vy - 4);
|
|
41
|
+
out.push({
|
|
42
|
+
tag: 'clipPath',
|
|
43
|
+
attrs: {
|
|
44
|
+
id: clipId
|
|
45
|
+
},
|
|
46
|
+
children: [
|
|
47
|
+
{
|
|
48
|
+
tag: 'rect',
|
|
49
|
+
attrs: {
|
|
50
|
+
x: -20,
|
|
51
|
+
y: -30,
|
|
52
|
+
width: 160,
|
|
53
|
+
height: r2(cy + 30)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}, {
|
|
58
|
+
tag: 'g',
|
|
59
|
+
attrs: {
|
|
60
|
+
'clip-path': `url(#${clipId})`
|
|
61
|
+
},
|
|
62
|
+
children: [
|
|
63
|
+
...parts.filter((p)=>'b' === p.z).map((p)=>L(p.d, '#C9CED6')),
|
|
64
|
+
L(S.d, '#C9CED6'),
|
|
65
|
+
...parts.filter((p)=>'b' !== p.z).map((p)=>L(p.d, '#C9CED6'))
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (!ghost) {
|
|
70
|
+
out.push({
|
|
71
|
+
tag: 'rect',
|
|
72
|
+
attrs: {
|
|
73
|
+
x: vx,
|
|
74
|
+
y: vy,
|
|
75
|
+
width: vw,
|
|
76
|
+
height: vh,
|
|
77
|
+
rx: vr,
|
|
78
|
+
fill: '#16181D'
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const t = eyeTargets(c.eyes, st);
|
|
82
|
+
const ec = 'coral' === c.color ? '#FF7A5E' : mix(col, '#ffffff', 0.62);
|
|
83
|
+
const lsw = 0.25 * vh * 0.17;
|
|
84
|
+
const ln = 'done' === st || 'hello' === st ? lsw : 'failed' === st ? Math.max(lsw, 122.4 / size) : 0;
|
|
85
|
+
out.push({
|
|
86
|
+
tag: 'path',
|
|
87
|
+
attrs: {
|
|
88
|
+
d: eyesPath(S, t, 1, 0, t.gy),
|
|
89
|
+
fill: ec,
|
|
90
|
+
...ln ? {
|
|
91
|
+
stroke: ec,
|
|
92
|
+
'stroke-width': r2(ln),
|
|
93
|
+
'stroke-linejoin': 'round'
|
|
94
|
+
} : {},
|
|
95
|
+
opacity: inv ? 0.6 : off ? 0.35 : 'failed' === st ? 0.75 : 1
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (!ghost && !inv && c.prop && GLYPH_PROPS.has(c.prop)) for (const l of propOf(c.prop, S, col)?.layers ?? [])out.push(luma(l.col) > 190 ? L(l.d, l.col) : {
|
|
100
|
+
tag: 'path',
|
|
101
|
+
attrs: {
|
|
102
|
+
d: l.d,
|
|
103
|
+
fill: l.col
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
width: size,
|
|
108
|
+
height: Math.round(128 * size / 136),
|
|
109
|
+
oy: optPx(c, size),
|
|
110
|
+
...ghost ? {
|
|
111
|
+
opacity: 0.55
|
|
112
|
+
} : {},
|
|
113
|
+
children: out
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function glyph(c, size, state = 'idle') {
|
|
117
|
+
const t = glyphTree(c, size, state, `gc${'partly' === state ? ++GUID : GUID}`);
|
|
118
|
+
return toSvgString('svg', {
|
|
119
|
+
viewBox: '-8 -14 136 128',
|
|
120
|
+
width: t.width,
|
|
121
|
+
height: t.height,
|
|
122
|
+
'aria-hidden': 'true',
|
|
123
|
+
style: `--oy:${t.oy}px;display:block;${t.opacity ? 'opacity:.55' : ''}`
|
|
124
|
+
}, t.children);
|
|
125
|
+
}
|
|
126
|
+
export { glyph, glyphTree };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type AgentLook, type AgentPropId } from './data.gen.js';
|
|
2
|
+
type Look = Omit<AgentLook, 'v'>;
|
|
3
|
+
export type LookIssueCode = 'coral-not-wally' | 'dots-look-alike' | 'reads-as-wally' | 'glyph-twin' | 'sky-teal-same-shape';
|
|
4
|
+
/** Every code is a warning: the builder warns and never blocks; Random and the default look skip them all (D19). */
|
|
5
|
+
export interface LookIssue {
|
|
6
|
+
code: LookIssueCode;
|
|
7
|
+
level: 'warning';
|
|
8
|
+
}
|
|
9
|
+
/** The page's PRNG (mulberry32, reference line 1296). */
|
|
10
|
+
export declare function rng(seed: number): () => number;
|
|
11
|
+
/** The page's seed hash (reference line 1734). It iterates code points but reads charCodeAt(0), so an astral
|
|
12
|
+
* character counts by its high surrogate only, exactly as on the page. */
|
|
13
|
+
export declare const hash32: (s: string) => number;
|
|
14
|
+
export declare function lookIssues(look: Look, { isWally, others }: {
|
|
15
|
+
isWally: boolean;
|
|
16
|
+
others: readonly Look[];
|
|
17
|
+
}): LookIssue[];
|
|
18
|
+
/**
|
|
19
|
+
* A first look for an agent without a preset, the same on every client for the same uid.
|
|
20
|
+
* `others`: the six presets until looks can be stored (B3), then the tenant's stored looks.
|
|
21
|
+
* `propPool`: no prop by default (P10), since a custom agent's job is not known.
|
|
22
|
+
*/
|
|
23
|
+
export declare function defaultLook(agentId: string, others?: readonly Look[], propPool?: readonly AgentPropId[]): AgentLook;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CAST, COLORS, EYE_STYLES, SHAPE_IDS } from "./data.gen.js";
|
|
2
|
+
function rng(seed) {
|
|
3
|
+
let a = seed >>> 0;
|
|
4
|
+
return ()=>{
|
|
5
|
+
a |= 0;
|
|
6
|
+
a = a + 0x6d2b79f5 | 0;
|
|
7
|
+
let t = Math.imul(a ^ a >>> 15, 1 | a);
|
|
8
|
+
t ^= t + Math.imul(t ^ t >>> 7, 61 | t);
|
|
9
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const hash32 = (s)=>[
|
|
13
|
+
...s
|
|
14
|
+
].reduce((a, ch)=>31 * a + ch.charCodeAt(0) | 0, 7);
|
|
15
|
+
const BLUE = new Set([
|
|
16
|
+
'cobalt',
|
|
17
|
+
'sky',
|
|
18
|
+
'powder',
|
|
19
|
+
'petrol'
|
|
20
|
+
]);
|
|
21
|
+
function lookIssues(look, { isWally, others }) {
|
|
22
|
+
const out = [];
|
|
23
|
+
if ('coral' === look.color && !isWally) out.push('coral-not-wally');
|
|
24
|
+
if ('cloud' === look.shape && BLUE.has(look.color) && 'beanie' === look.prop || 'butter' === look.color && ('glasses' === look.prop || 'monocle' === look.prop) || ('mint' === look.color || 'sage' === look.color) && ('pebble' === look.shape || 'capsule' === look.shape || 'egg' === look.shape)) out.push('dots-look-alike');
|
|
25
|
+
if (!isWally && 'dome' === look.shape && 'antennae' === look.prop) out.push('reads-as-wally');
|
|
26
|
+
for (const o of others){
|
|
27
|
+
if (o.shape === look.shape && o.color === look.color) out.push('glyph-twin');
|
|
28
|
+
if (o.shape === look.shape && ('sky' === o.color && 'cyan' === look.color || 'cyan' === o.color && 'sky' === look.color)) out.push('sky-teal-same-shape');
|
|
29
|
+
}
|
|
30
|
+
return out.map((code)=>({
|
|
31
|
+
code,
|
|
32
|
+
level: 'warning'
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
const PRESET_LOOKS = CAST.map(({ shape, color, eyes, prop })=>({
|
|
36
|
+
shape,
|
|
37
|
+
color,
|
|
38
|
+
eyes,
|
|
39
|
+
prop
|
|
40
|
+
}));
|
|
41
|
+
const DRAW_COLORS = COLORS.filter((c)=>!c.brand).map((c)=>c.id);
|
|
42
|
+
function defaultLook(agentId, others = PRESET_LOOKS, propPool = [
|
|
43
|
+
'none'
|
|
44
|
+
]) {
|
|
45
|
+
const r = rng(hash32(agentId));
|
|
46
|
+
const pick = (list)=>list[Math.floor(r() * list.length)];
|
|
47
|
+
const draw = ()=>({
|
|
48
|
+
v: 1,
|
|
49
|
+
shape: pick(SHAPE_IDS),
|
|
50
|
+
color: pick(DRAW_COLORS),
|
|
51
|
+
eyes: pick(EYE_STYLES),
|
|
52
|
+
prop: propPool.length ? pick(propPool) : 'none'
|
|
53
|
+
});
|
|
54
|
+
const first = draw();
|
|
55
|
+
if (0 === lookIssues(first, {
|
|
56
|
+
isWally: false,
|
|
57
|
+
others
|
|
58
|
+
}).length) return first;
|
|
59
|
+
for(let i = 1; i < 200; i++){
|
|
60
|
+
const look = draw();
|
|
61
|
+
if (0 === lookIssues(look, {
|
|
62
|
+
isWally: false,
|
|
63
|
+
others
|
|
64
|
+
}).length) return look;
|
|
65
|
+
}
|
|
66
|
+
return first;
|
|
67
|
+
}
|
|
68
|
+
export { defaultLook, hash32, lookIssues, rng };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type Ease = (t: number) => number;
|
|
2
|
+
/** additive clip channels: gaze, lid, openness, brightness, crown line, prop angle / turn / shift, beam */
|
|
3
|
+
export type Channels = Partial<Record<'gx' | 'gy' | 'lid' | 'op' | 'br' | 'cv' | 'pa' | 'pw' | 'pdx' | 'pb' | 'bm', number>>;
|
|
4
|
+
/** [t ms, ty, sy, rot, ease, channels] */
|
|
5
|
+
export type Key = readonly [number, number, number, number?, (Ease | null)?, Channels?];
|
|
6
|
+
export declare const lerp: (a: number, b: number, t: number) => number;
|
|
7
|
+
export declare const E_SETTLE: Ease;
|
|
8
|
+
export declare const E_GRAV: Ease;
|
|
9
|
+
export declare const E_RISE: Ease;
|
|
10
|
+
export declare const E_INOUT: Ease;
|
|
11
|
+
export declare const E_FILL: Ease;
|
|
12
|
+
export declare const E_OUT: Ease;
|
|
13
|
+
export declare const E_IN: Ease;
|
|
14
|
+
export declare const E_LIN: Ease;
|
|
15
|
+
export declare const logn: (r: () => number, med: number, s: number, lo: number, hi: number) => number;
|
|
16
|
+
export interface SpringP {
|
|
17
|
+
k: number;
|
|
18
|
+
c: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Spring {
|
|
21
|
+
x: number;
|
|
22
|
+
v: number;
|
|
23
|
+
t: number;
|
|
24
|
+
p: SpringP;
|
|
25
|
+
}
|
|
26
|
+
export declare const P_SHAPE: SpringP;
|
|
27
|
+
export declare const P_POP: SpringP;
|
|
28
|
+
export declare const P_DART: SpringP;
|
|
29
|
+
export declare const P_PURSUIT: SpringP;
|
|
30
|
+
export declare const P_BRIGHT: SpringP;
|
|
31
|
+
export declare const P_SQ: SpringP;
|
|
32
|
+
export declare const P_LAND: SpringP;
|
|
33
|
+
export declare const P_W: SpringP;
|
|
34
|
+
export declare const spring: (x: number, p: SpringP) => Spring;
|
|
35
|
+
/** semi-implicit Euler in sub-steps of at most 1/240 s */
|
|
36
|
+
export declare function stepS(s: Spring, dt: number): void;
|
|
37
|
+
export declare const NOX: Channels;
|
|
38
|
+
/** "Failed": a signal glitch, then a small "no-no"; every 2.5–4 s */
|
|
39
|
+
export declare const BEAT: Key[];
|
|
40
|
+
/** "Hello": a head tilt in place of a wave */
|
|
41
|
+
export declare const HELLO_TILT: Key[];
|
|
42
|
+
/** "Hello": the prop joins in from the top of the hop */
|
|
43
|
+
export declare const HELLO_PROP: Record<string, Key[]>;
|
|
44
|
+
/** idle "Plays with its prop"; props without a move never pick it */
|
|
45
|
+
export declare const FIDDLE: Record<string, Key[]>;
|
|
46
|
+
/** fiddles with 50–130 ms keys need the full frame rate */
|
|
47
|
+
export declare const FAST: Set<string>;
|
|
48
|
+
export interface Gaze {
|
|
49
|
+
gx: number;
|
|
50
|
+
gy: number;
|
|
51
|
+
}
|
|
52
|
+
/** the idle repertoire inside "On duty"; side s = ±1 */
|
|
53
|
+
export declare const ACTS: {
|
|
54
|
+
bored: () => Key[];
|
|
55
|
+
lean: (s: number) => Key[];
|
|
56
|
+
shuffle: (s: number) => Key[];
|
|
57
|
+
look: (g: Gaze, L: number) => Key[];
|
|
58
|
+
/** double take */
|
|
59
|
+
take: (g: Gaze, L: number) => Key[];
|
|
60
|
+
stretch: () => Key[];
|
|
61
|
+
/** "Partial coverage" instead of the stretch: the colour climbs 70% of the crown as it looks up, a content
|
|
62
|
+
* blink, then it sinks home slower than it rose */
|
|
63
|
+
reach: (L: number) => Key[];
|
|
64
|
+
};
|
|
65
|
+
export declare const ACT_W: Record<string, number>;
|
|
66
|
+
/** perks up, glances at Set up, looks back, a slow blink; feet on the floor; rest gaze straight ahead */
|
|
67
|
+
export declare const INVITE: (c: Gaze) => Key[];
|
|
68
|
+
/** the .props group transform from the prop channels */
|
|
69
|
+
export declare function propTr(X: Channels, F?: {
|
|
70
|
+
px: number;
|
|
71
|
+
py: number;
|
|
72
|
+
} | null): string;
|
|
73
|
+
export declare const blinkOpen: (u: number) => number;
|