@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,220 @@
|
|
|
1
|
+
import { createCanvas } from "./canvas.js";
|
|
2
|
+
import { getRuntime } from "./runtime.js";
|
|
3
|
+
function solveField(maskAt, R) {
|
|
4
|
+
let u = null;
|
|
5
|
+
let pN = 0;
|
|
6
|
+
const levels = [
|
|
7
|
+
32,
|
|
8
|
+
80,
|
|
9
|
+
64,
|
|
10
|
+
80,
|
|
11
|
+
128,
|
|
12
|
+
120
|
|
13
|
+
];
|
|
14
|
+
for(let lv = 0; lv < levels.length; lv += 2){
|
|
15
|
+
const N = levels[lv];
|
|
16
|
+
const it = levels[lv + 1];
|
|
17
|
+
const a = maskAt(N);
|
|
18
|
+
const m = new Uint8Array(N * N);
|
|
19
|
+
for(let i = 0; i < N * N; i++)m[i] = a[i] > 127 ? 1 : 0;
|
|
20
|
+
const h = R / N;
|
|
21
|
+
const c = 4 * h * h;
|
|
22
|
+
const nu = new Float32Array(N * N);
|
|
23
|
+
if (u) {
|
|
24
|
+
const prev = u;
|
|
25
|
+
for(let y = 0; y < N; y++)for(let x = 0; x < N; x++){
|
|
26
|
+
const i = y * N + x;
|
|
27
|
+
nu[i] = m[i] ? prev[(y >> 1) * pN + (x >> 1)] : 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for(let k = 0; k < it; k++)for(let y = 1; y < N - 1; y++)for(let x = 1; x < N - 1; x++){
|
|
31
|
+
const i = y * N + x;
|
|
32
|
+
if (!m[i]) continue;
|
|
33
|
+
const v = (nu[i - 1] + nu[i + 1] + nu[i - N] + nu[i + N] + c) * 0.25;
|
|
34
|
+
nu[i] = nu[i] + 1.85 * (v - nu[i]);
|
|
35
|
+
}
|
|
36
|
+
u = nu;
|
|
37
|
+
pN = N;
|
|
38
|
+
}
|
|
39
|
+
return u;
|
|
40
|
+
}
|
|
41
|
+
function shade(u, alpha, hex, P, mat, y0, R) {
|
|
42
|
+
const G = 128;
|
|
43
|
+
const clamp = (v, a, b)=>Math.max(a, Math.min(b, v));
|
|
44
|
+
const s2l = (c)=>{
|
|
45
|
+
const v = c / 255;
|
|
46
|
+
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
47
|
+
};
|
|
48
|
+
const l2s = (x)=>{
|
|
49
|
+
const v = clamp(x, 0, 1);
|
|
50
|
+
return 255 * (v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055);
|
|
51
|
+
};
|
|
52
|
+
const n = parseInt(hex.slice(1), 16);
|
|
53
|
+
const alb = [
|
|
54
|
+
s2l(n >> 16 & 255),
|
|
55
|
+
s2l(n >> 8 & 255),
|
|
56
|
+
s2l(255 & n)
|
|
57
|
+
];
|
|
58
|
+
const o = new Uint8ClampedArray(P * P * 4);
|
|
59
|
+
const puff = 'vinyl' === mat ? 0.75 : 0.6;
|
|
60
|
+
const ln = Math.hypot(-0.45, -0.72, 0.55);
|
|
61
|
+
const L0 = -0.45 / ln;
|
|
62
|
+
const L1 = -0.72 / ln;
|
|
63
|
+
const L2 = 0.55 / ln;
|
|
64
|
+
const hn = Math.hypot(L0, L1, L2 + 1);
|
|
65
|
+
const H0 = L0 / hn;
|
|
66
|
+
const H1 = L1 / hn;
|
|
67
|
+
const H2 = (L2 + 1) / hn;
|
|
68
|
+
const U = (ux, uy)=>{
|
|
69
|
+
const gx = clamp(ux, 0, G - 1.001);
|
|
70
|
+
const gy = clamp(uy, 0, G - 1.001);
|
|
71
|
+
const x = 0 | gx;
|
|
72
|
+
const y = 0 | gy;
|
|
73
|
+
const fx = gx - x;
|
|
74
|
+
const fy = gy - y;
|
|
75
|
+
const i = y * G + x;
|
|
76
|
+
return (u[i] * (1 - fx) + u[i + 1] * fx) * (1 - fy) + (u[i + G] * (1 - fx) + u[i + G + 1] * fx) * fy;
|
|
77
|
+
};
|
|
78
|
+
let seed = 7;
|
|
79
|
+
const rnd = ()=>{
|
|
80
|
+
seed = 16807 * seed % 2147483647;
|
|
81
|
+
return seed / 2147483647;
|
|
82
|
+
};
|
|
83
|
+
const h = R / G;
|
|
84
|
+
for(let py = 0; py < P; py++)for(let px = 0; px < P; px++){
|
|
85
|
+
const j = (py * P + px) * 4;
|
|
86
|
+
const al = alpha[py * P + px];
|
|
87
|
+
if (!al) continue;
|
|
88
|
+
const gx = (px + 0.5) / P * G - 0.5;
|
|
89
|
+
const gy = (py + 0.5) / P * G - 0.5;
|
|
90
|
+
const su = Math.max(Math.sqrt(Math.max(U(gx, gy), 0)), 1.2);
|
|
91
|
+
const dux = (U(gx + 1, gy) - U(gx - 1, gy)) / (2 * h);
|
|
92
|
+
const duy = (U(gx, gy + 1) - U(gx, gy - 1)) / (2 * h);
|
|
93
|
+
let nx = -puff * dux / (2 * su);
|
|
94
|
+
let ny = -puff * duy / (2 * su);
|
|
95
|
+
let nz = 1;
|
|
96
|
+
const nl = Math.hypot(nx, ny, nz);
|
|
97
|
+
nx /= nl;
|
|
98
|
+
ny /= nl;
|
|
99
|
+
nz /= nl;
|
|
100
|
+
const ndl = nx * L0 + ny * L1 + nz * L2;
|
|
101
|
+
const wrap = Math.max(0, (ndl + 0.45) / 1.45);
|
|
102
|
+
const sky = 0.5 - 0.5 * ny;
|
|
103
|
+
const bounce = 0.18 * Math.max(0, ny);
|
|
104
|
+
const yU = y0 + (py + 0.5) / P * R;
|
|
105
|
+
const ao = 1 - 0.32 * clamp((yU - 84) / 24, 0, 1) * Math.max(0, 0.3 + ny);
|
|
106
|
+
const k = (0.3 * (0.6 + 0.4 * sky) + 0.78 * wrap) * ao;
|
|
107
|
+
const fres = (1 - nz) ** 2.2;
|
|
108
|
+
let add = 0;
|
|
109
|
+
if ('vinyl' === mat) {
|
|
110
|
+
const ndh = Math.max(0, nx * H0 + ny * H1 + nz * H2);
|
|
111
|
+
add = ndh ** 24 * 0.28 + ndh ** 180 * 0.6 + 0.06 * fres;
|
|
112
|
+
} else add = 0.16 * fres;
|
|
113
|
+
const grain = 'vinyl' === mat ? (rnd() - 0.5) * 0.015 : (rnd() - 0.5) * 0.07;
|
|
114
|
+
for(let ch = 0; ch < 3; ch++){
|
|
115
|
+
const a = alb[ch];
|
|
116
|
+
const b = bounce * (0 === ch ? 1 : 1 === ch ? 0.85 : 0.6) * a;
|
|
117
|
+
o[j + ch] = l2s(a * k * (1 + grain) + b + add);
|
|
118
|
+
}
|
|
119
|
+
o[j + 3] = al;
|
|
120
|
+
}
|
|
121
|
+
return o;
|
|
122
|
+
}
|
|
123
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
124
|
+
function region(d) {
|
|
125
|
+
const C = getRuntime().caches;
|
|
126
|
+
const cached = C.reg.get(d);
|
|
127
|
+
if (cached) return cached;
|
|
128
|
+
let measurePath = C.measure;
|
|
129
|
+
if (!measurePath?.isConnected) {
|
|
130
|
+
const svg = document.createElementNS(SVG_NS, 'svg');
|
|
131
|
+
svg.setAttribute('width', '0');
|
|
132
|
+
svg.setAttribute('height', '0');
|
|
133
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
134
|
+
svg.style.position = 'absolute';
|
|
135
|
+
measurePath = document.createElementNS(SVG_NS, 'path');
|
|
136
|
+
C.measure = measurePath;
|
|
137
|
+
svg.appendChild(measurePath);
|
|
138
|
+
document.body.appendChild(svg);
|
|
139
|
+
}
|
|
140
|
+
measurePath.setAttribute('d', d);
|
|
141
|
+
const b = measurePath.getBBox();
|
|
142
|
+
const pad = 2;
|
|
143
|
+
const R = Math.ceil(Math.max(b.width, b.height) + 2 * pad);
|
|
144
|
+
const r = [
|
|
145
|
+
Math.floor(b.x + b.width / 2 - R / 2),
|
|
146
|
+
Math.floor(b.y + b.height / 2 - R / 2),
|
|
147
|
+
R
|
|
148
|
+
];
|
|
149
|
+
C.reg.set(d, r);
|
|
150
|
+
return r;
|
|
151
|
+
}
|
|
152
|
+
function rmaskAlpha(d, x0, y0, R, N) {
|
|
153
|
+
const { ctx } = createCanvas(N);
|
|
154
|
+
ctx.scale(N / R, N / R);
|
|
155
|
+
ctx.translate(-x0, -y0);
|
|
156
|
+
ctx.fill(new Path2D(d));
|
|
157
|
+
const rgba = ctx.getImageData(0, 0, N, N).data;
|
|
158
|
+
const a = new Uint8ClampedArray(N * N);
|
|
159
|
+
for(let i = 0; i < N * N; i++)a[i] = rgba[4 * i + 3];
|
|
160
|
+
return a;
|
|
161
|
+
}
|
|
162
|
+
const caches = ()=>getRuntime().caches;
|
|
163
|
+
const retain = (key)=>{
|
|
164
|
+
const R = caches().retain;
|
|
165
|
+
R.set(key, (R.get(key) ?? 0) + 1);
|
|
166
|
+
};
|
|
167
|
+
const release = (key)=>{
|
|
168
|
+
const R = caches().retain;
|
|
169
|
+
const n = (R.get(key) ?? 0) - 1;
|
|
170
|
+
if (n > 0) R.set(key, n);
|
|
171
|
+
else R.delete(key);
|
|
172
|
+
};
|
|
173
|
+
const isRetained = (key)=>caches().retain.has(key);
|
|
174
|
+
const retainedCount = ()=>caches().retain.size;
|
|
175
|
+
const LOOK_VERSION = 'v14.1';
|
|
176
|
+
const bakeKey = (d, col, P, mat)=>`${LOOK_VERSION}|${d}|${col}|${P}|${mat}`;
|
|
177
|
+
function solveCached(d, x0, y0, R) {
|
|
178
|
+
const { hc } = caches();
|
|
179
|
+
let u = hc.get(d);
|
|
180
|
+
if (!u) {
|
|
181
|
+
u = solveField((N)=>rmaskAlpha(d, x0, y0, R, N), R);
|
|
182
|
+
hc.set(d, u);
|
|
183
|
+
}
|
|
184
|
+
return u;
|
|
185
|
+
}
|
|
186
|
+
async function encode(rgba, P) {
|
|
187
|
+
const { ctx, toBlob } = createCanvas(P);
|
|
188
|
+
ctx.putImageData(new ImageData(rgba, P, P), 0, 0);
|
|
189
|
+
return toBlob();
|
|
190
|
+
}
|
|
191
|
+
const bakeOnMain = async ({ d, col, P, mat, region: [x0, y0, R] })=>encode(shade(solveCached(d, x0, y0, R), rmaskAlpha(d, x0, y0, R, P), col, P, mat, y0, R), P);
|
|
192
|
+
function bake(d, col, P, mat, run = bakeOnMain) {
|
|
193
|
+
const key = bakeKey(d, col, P, mat);
|
|
194
|
+
const { bc: BC, inflight: INFLIGHT } = caches();
|
|
195
|
+
const hit = BC.get(key);
|
|
196
|
+
if (hit) return Promise.resolve(hit);
|
|
197
|
+
const pending = INFLIGHT.get(key);
|
|
198
|
+
if (pending) return pending;
|
|
199
|
+
const reg = region(d);
|
|
200
|
+
const p = run({
|
|
201
|
+
d,
|
|
202
|
+
col,
|
|
203
|
+
P,
|
|
204
|
+
mat,
|
|
205
|
+
region: reg
|
|
206
|
+
}).then((blob)=>{
|
|
207
|
+
const res = {
|
|
208
|
+
key,
|
|
209
|
+
url: URL.createObjectURL(blob),
|
|
210
|
+
x0: reg[0],
|
|
211
|
+
y0: reg[1],
|
|
212
|
+
R: reg[2]
|
|
213
|
+
};
|
|
214
|
+
BC.set(key, res);
|
|
215
|
+
return res;
|
|
216
|
+
}).finally(()=>INFLIGHT.delete(key));
|
|
217
|
+
INFLIGHT.set(key, p);
|
|
218
|
+
return p;
|
|
219
|
+
}
|
|
220
|
+
export { LOOK_VERSION, bake, bakeKey, bakeOnMain, isRetained, region, release, retain, retainedCount, rmaskAlpha, shade, solveCached, solveField };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Canvas2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
2
|
+
/** A square 2D canvas: OffscreenCanvas where it exists (workers), else a DOM canvas. */
|
|
3
|
+
export declare function createCanvas(n: number): {
|
|
4
|
+
ctx: Canvas2D;
|
|
5
|
+
toBlob: () => Promise<Blob>;
|
|
6
|
+
};
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function createCanvas(n) {
|
|
2
|
+
if ("u" > typeof OffscreenCanvas) {
|
|
3
|
+
const cv = new OffscreenCanvas(n, n);
|
|
4
|
+
const ctx = cv.getContext('2d');
|
|
5
|
+
if (!ctx) throw new Error('2D canvas unavailable');
|
|
6
|
+
return {
|
|
7
|
+
ctx,
|
|
8
|
+
toBlob: ()=>cv.convertToBlob({
|
|
9
|
+
type: 'image/png'
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const cv = document.createElement('canvas');
|
|
14
|
+
cv.width = cv.height = n;
|
|
15
|
+
const ctx = cv.getContext('2d');
|
|
16
|
+
if (!ctx) throw new Error('2D canvas unavailable');
|
|
17
|
+
return {
|
|
18
|
+
ctx,
|
|
19
|
+
toBlob: ()=>new Promise((ok, fail)=>cv.toBlob((b)=>b ? ok(b) : fail(new Error('toBlob failed')), 'image/png'))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { createCanvas };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type StateId } from './eyes.js';
|
|
2
|
+
import type { Look } from './glyph.js';
|
|
3
|
+
import type { SvgNode } from './svg.js';
|
|
4
|
+
export interface CharLayer {
|
|
5
|
+
d: string;
|
|
6
|
+
col: string;
|
|
7
|
+
mat: 'felt' | 'vinyl';
|
|
8
|
+
/** a layer of the grey ghost veil (baked only for Not set up, Inviting and the coverage crown) */
|
|
9
|
+
veil: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface CharTree {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
/** the page's `.ch` classes: st-<state>, ghosting (the veil shows), veiled (colour layers hidden) */
|
|
15
|
+
state: StateId;
|
|
16
|
+
ghosting: boolean;
|
|
17
|
+
veiled: boolean;
|
|
18
|
+
children: SvgNode[];
|
|
19
|
+
layers: CharLayer[];
|
|
20
|
+
}
|
|
21
|
+
export interface CharOptions {
|
|
22
|
+
size: number;
|
|
23
|
+
state: StateId;
|
|
24
|
+
shadow: boolean;
|
|
25
|
+
/** Partial coverage: the crown */
|
|
26
|
+
cover: boolean;
|
|
27
|
+
/** id prefix, unique per instance */
|
|
28
|
+
ids: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function charTree(c: Look, o: CharOptions): CharTree;
|
|
31
|
+
/** The page's bake size for a layer: ⌈region R × size / 136 × min(2, DPR)⌉ (makeChar, o.res = 1). */
|
|
32
|
+
export declare const bakeSize: (R: number, size: number, dpr: number) => number;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { hexOf, mix } from "./color.js";
|
|
2
|
+
import { HARD, TONE } from "./data.gen.js";
|
|
3
|
+
import { eyeTargets, eyesPath } from "./eyes.js";
|
|
4
|
+
import { geom, shapeOf } from "./geom.js";
|
|
5
|
+
import { r2 } from "./paths.js";
|
|
6
|
+
import { propOf } from "./propOf.js";
|
|
7
|
+
const el = (tag, attrs, children)=>({
|
|
8
|
+
tag,
|
|
9
|
+
attrs,
|
|
10
|
+
...children ? {
|
|
11
|
+
children
|
|
12
|
+
} : {}
|
|
13
|
+
});
|
|
14
|
+
function parseFragment(s) {
|
|
15
|
+
const out = [];
|
|
16
|
+
const stack = [
|
|
17
|
+
out
|
|
18
|
+
];
|
|
19
|
+
for (const m of s.matchAll(/<(\/?)(\w+)([^>]*?)(\/?)>/g)){
|
|
20
|
+
const [, close, tag, rest, self] = m;
|
|
21
|
+
if (close) {
|
|
22
|
+
stack.pop();
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const attrs = {};
|
|
26
|
+
for (const a of rest.matchAll(/([\w:-]+)="([^"]*)"/g))attrs[a[1]] = a[2];
|
|
27
|
+
const node = {
|
|
28
|
+
tag,
|
|
29
|
+
attrs
|
|
30
|
+
};
|
|
31
|
+
stack[stack.length - 1].push(node);
|
|
32
|
+
if (!self) {
|
|
33
|
+
node.children = [];
|
|
34
|
+
stack.push(node.children);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function charTree(c, o) {
|
|
40
|
+
const S = shapeOf(c.shape);
|
|
41
|
+
const G = geom(S);
|
|
42
|
+
const col = hexOf(c.color);
|
|
43
|
+
const { size, ids: id } = o;
|
|
44
|
+
const st = o.state;
|
|
45
|
+
const [vx, vy, vw, vh] = S.v;
|
|
46
|
+
const vr = 0.46 * vh;
|
|
47
|
+
const ecol = 'coral' === c.color ? '#FF7A5E' : mix(col, '#ffffff', 0.62);
|
|
48
|
+
const dk = mix(col, '#0d0b0c', 0.34);
|
|
49
|
+
const lt = mix(col, '#ffffff', 0.4);
|
|
50
|
+
const layers = [];
|
|
51
|
+
const LY = (d, color, mat, lgFill, cls = '', veil = false)=>{
|
|
52
|
+
const i = layers.length;
|
|
53
|
+
layers.push({
|
|
54
|
+
d,
|
|
55
|
+
col: color,
|
|
56
|
+
mat: mat ?? 'felt',
|
|
57
|
+
veil
|
|
58
|
+
});
|
|
59
|
+
return el('g', {
|
|
60
|
+
class: `ly ${cls}`,
|
|
61
|
+
'data-j': i
|
|
62
|
+
}, [
|
|
63
|
+
el('path', {
|
|
64
|
+
class: 'lg',
|
|
65
|
+
d,
|
|
66
|
+
fill: lgFill || color
|
|
67
|
+
}),
|
|
68
|
+
el('image', {
|
|
69
|
+
class: 'li',
|
|
70
|
+
preserveAspectRatio: 'none'
|
|
71
|
+
})
|
|
72
|
+
]);
|
|
73
|
+
};
|
|
74
|
+
const partCol = (p)=>TONE[p.tone] ?? p.tone;
|
|
75
|
+
const parts = S.parts || [];
|
|
76
|
+
const back = parts.filter((p)=>'b' === p.z).map((p)=>LY(p.d, partCol(p), HARD.has(p.tone) ? 'vinyl' : null));
|
|
77
|
+
const front = parts.filter((p)=>'b' !== p.z).map((p)=>LY(p.d, partCol(p), HARD.has(p.tone) ? 'vinyl' : null));
|
|
78
|
+
const body = LY(S.d, col, null, `url(#${id}g)`, 'bodyly');
|
|
79
|
+
const P = c.prop && 'none' !== c.prop ? propOf(c.prop, S, col) : null;
|
|
80
|
+
const pv = P ? P.layers.map((l)=>LY(l.d, l.col, l.mat)) : [];
|
|
81
|
+
const pdeco = P ? P.deco.filter((x)=>!x.clip).flatMap((x)=>parseFragment(x.s)) : [];
|
|
82
|
+
const pdecoClip = P ? P.deco.filter((x)=>x.clip).flatMap((x)=>parseFragment(x.s)) : [];
|
|
83
|
+
const veil = el('g', {
|
|
84
|
+
class: 'veil',
|
|
85
|
+
'clip-path': `url(#${id}v)`
|
|
86
|
+
}, [
|
|
87
|
+
...parts.filter((p)=>'b' === p.z),
|
|
88
|
+
{
|
|
89
|
+
d: S.d
|
|
90
|
+
},
|
|
91
|
+
...parts.filter((p)=>'b' !== p.z)
|
|
92
|
+
].map((p)=>LY(p.d, '#C2C7CF', 'felt', '#C2C7CF', 'vy', true)));
|
|
93
|
+
const t = eyeTargets(c.eyes, 'power' === st ? 'box' : st);
|
|
94
|
+
const box = 'box' === st;
|
|
95
|
+
const ghostT = box || 'invite' === st ? 0 : 1;
|
|
96
|
+
const figOp = box ? 0.5 : 1;
|
|
97
|
+
const propScale = box || 'invite' === st ? 0 : 1;
|
|
98
|
+
const work = 'working' === st ? 1 : 0;
|
|
99
|
+
const ty = box ? -8 : 0;
|
|
100
|
+
const shadowK = box ? 0.35 : 1;
|
|
101
|
+
const d0 = eyesPath(S, t, 1, 0, t.gy);
|
|
102
|
+
const bo = r2(Math.max(0, Math.min(1.2, t.bright)));
|
|
103
|
+
const cover = o.cover && 'off' !== st;
|
|
104
|
+
let veilH;
|
|
105
|
+
if (cover) {
|
|
106
|
+
const covT = G.top[1];
|
|
107
|
+
const covY = Math.min(covT + 0.3 * (108 - covT), vy - 4);
|
|
108
|
+
veilH = r2(Math.max(covY, covT + 0.2 * (covY - covT)) + 30);
|
|
109
|
+
} else veilH = r2(140 * (1 - ghostT));
|
|
110
|
+
const shadow = [];
|
|
111
|
+
if (o.shadow) {
|
|
112
|
+
const [fl, fr] = G.foot;
|
|
113
|
+
const hw = Math.max(12, (fr - fl) / 2);
|
|
114
|
+
const cx = r2((fl + fr) / 2);
|
|
115
|
+
const hgt = Math.max(0, Math.min(1, -ty / 12));
|
|
116
|
+
const kA = (1 - 0.2 * hgt) * shadowK;
|
|
117
|
+
const kC = (1 - 0.45 * hgt) * shadowK;
|
|
118
|
+
shadow.push(el('g', {
|
|
119
|
+
class: 'shd'
|
|
120
|
+
}, [
|
|
121
|
+
el('ellipse', {
|
|
122
|
+
class: 'sha',
|
|
123
|
+
cx,
|
|
124
|
+
cy: 108.5,
|
|
125
|
+
rx: r2(1.3 * hw),
|
|
126
|
+
ry: 8,
|
|
127
|
+
fill: `url(#${id}s)`,
|
|
128
|
+
opacity: r2(0.16 * (1 - 0.4 * hgt) * shadowK),
|
|
129
|
+
transform: `translate(${cx} 108) scale(${r2(kA)} ${r2(kA)}) translate(${-cx} -108)`
|
|
130
|
+
}),
|
|
131
|
+
el('ellipse', {
|
|
132
|
+
class: 'shc',
|
|
133
|
+
cx,
|
|
134
|
+
cy: 108,
|
|
135
|
+
rx: r2(0.95 * hw),
|
|
136
|
+
ry: 3.6,
|
|
137
|
+
fill: `url(#${id}s)`,
|
|
138
|
+
opacity: r2(0.36 * (1 - 0.8 * hgt) * shadowK),
|
|
139
|
+
transform: `translate(${cx} 108) scale(${r2(kC)} 1) translate(${-cx} -108)`
|
|
140
|
+
})
|
|
141
|
+
]));
|
|
142
|
+
}
|
|
143
|
+
const lipY = vy + vh + 0.9;
|
|
144
|
+
const pa = P?.anim ? {
|
|
145
|
+
class: 'pa',
|
|
146
|
+
'data-a': P.anim.type,
|
|
147
|
+
'data-px': P.anim.px,
|
|
148
|
+
'data-py': P.anim.py
|
|
149
|
+
} : {};
|
|
150
|
+
for (const n of pdeco)if ('beam' === n.attrs.class) n.attrs.opacity = r2(0.55 * work);
|
|
151
|
+
const clipGroup = el('g', {
|
|
152
|
+
'clip-path': `url(#${id}k)`
|
|
153
|
+
}, pdecoClip);
|
|
154
|
+
const figChildren = [
|
|
155
|
+
el('g', {
|
|
156
|
+
class: 'back'
|
|
157
|
+
}, back),
|
|
158
|
+
body,
|
|
159
|
+
el('g', {
|
|
160
|
+
class: 'front'
|
|
161
|
+
}, front),
|
|
162
|
+
...o.cover ? [
|
|
163
|
+
veil,
|
|
164
|
+
clipGroup
|
|
165
|
+
] : [
|
|
166
|
+
clipGroup,
|
|
167
|
+
veil
|
|
168
|
+
],
|
|
169
|
+
el('g', {
|
|
170
|
+
class: 'visor'
|
|
171
|
+
}, [
|
|
172
|
+
el('rect', {
|
|
173
|
+
x: vx,
|
|
174
|
+
y: vy,
|
|
175
|
+
width: vw,
|
|
176
|
+
height: vh,
|
|
177
|
+
rx: vr,
|
|
178
|
+
fill: `url(#${id}vg)`,
|
|
179
|
+
stroke: dk,
|
|
180
|
+
'stroke-width': 1.4
|
|
181
|
+
}),
|
|
182
|
+
el('rect', {
|
|
183
|
+
x: vx,
|
|
184
|
+
y: vy + 1.4,
|
|
185
|
+
width: vw,
|
|
186
|
+
height: vh,
|
|
187
|
+
rx: vr,
|
|
188
|
+
fill: 'none',
|
|
189
|
+
stroke: '#04060B',
|
|
190
|
+
'stroke-opacity': '.55',
|
|
191
|
+
'stroke-width': 3,
|
|
192
|
+
'clip-path': `url(#${id}c)`
|
|
193
|
+
}),
|
|
194
|
+
el('path', {
|
|
195
|
+
d: `M${r2(vx + 0.7 * vr)} ${r2(lipY)}Q${vx + vw / 2} ${r2(lipY + 1.8)} ${r2(vx + vw - 0.7 * vr)} ${r2(lipY)}`,
|
|
196
|
+
fill: 'none',
|
|
197
|
+
stroke: mix(col, '#ffffff', 0.6),
|
|
198
|
+
'stroke-opacity': '.5',
|
|
199
|
+
'stroke-width': 1.2,
|
|
200
|
+
'stroke-linecap': 'round'
|
|
201
|
+
}),
|
|
202
|
+
el('ellipse', {
|
|
203
|
+
class: 'vglow',
|
|
204
|
+
cx: vx + vw / 2,
|
|
205
|
+
cy: vy + vh / 2,
|
|
206
|
+
rx: 0.42 * vw,
|
|
207
|
+
ry: 0.5 * vh,
|
|
208
|
+
fill: `url(#${id}eg)`,
|
|
209
|
+
opacity: r2(0.8 * bo)
|
|
210
|
+
}),
|
|
211
|
+
el('path', {
|
|
212
|
+
d: `M${r2(vx + 0.42 * vh)} ${r2(vy + 4.2)}Q${r2(vx + 0.3 * vw)} ${r2(vy + 2.7)} ${r2(vx + 0.46 * vw)} ${r2(vy + 3.6)}`,
|
|
213
|
+
fill: 'none',
|
|
214
|
+
stroke: '#fff',
|
|
215
|
+
'stroke-opacity': '.2',
|
|
216
|
+
'stroke-width': 2.2,
|
|
217
|
+
'stroke-linecap': 'round'
|
|
218
|
+
})
|
|
219
|
+
]),
|
|
220
|
+
el('g', {
|
|
221
|
+
class: 'eyes',
|
|
222
|
+
opacity: bo
|
|
223
|
+
}, [
|
|
224
|
+
el('path', {
|
|
225
|
+
class: 'eg',
|
|
226
|
+
d: d0,
|
|
227
|
+
fill: ecol,
|
|
228
|
+
stroke: ecol,
|
|
229
|
+
'stroke-width': 2.6,
|
|
230
|
+
'stroke-linejoin': 'round',
|
|
231
|
+
opacity: '.2'
|
|
232
|
+
}),
|
|
233
|
+
el('path', {
|
|
234
|
+
class: 'ef',
|
|
235
|
+
d: d0,
|
|
236
|
+
fill: ecol,
|
|
237
|
+
stroke: ecol,
|
|
238
|
+
'stroke-width': r2(0.25 * vh * 0.17),
|
|
239
|
+
'stroke-linejoin': 'round'
|
|
240
|
+
})
|
|
241
|
+
]),
|
|
242
|
+
el('g', {
|
|
243
|
+
class: 'props',
|
|
244
|
+
opacity: propScale
|
|
245
|
+
}, P ? [
|
|
246
|
+
el('g', pa, [
|
|
247
|
+
el('g', {
|
|
248
|
+
class: 'pv'
|
|
249
|
+
}, pv),
|
|
250
|
+
...pdeco
|
|
251
|
+
])
|
|
252
|
+
] : [])
|
|
253
|
+
];
|
|
254
|
+
const defs = el('defs', {}, [
|
|
255
|
+
el('radialGradient', {
|
|
256
|
+
id: `${id}g`,
|
|
257
|
+
cx: '.36',
|
|
258
|
+
cy: '.26',
|
|
259
|
+
r: '.9'
|
|
260
|
+
}, [
|
|
261
|
+
el('stop', {
|
|
262
|
+
offset: '0',
|
|
263
|
+
'stop-color': lt
|
|
264
|
+
}),
|
|
265
|
+
el('stop', {
|
|
266
|
+
offset: '.55',
|
|
267
|
+
'stop-color': col
|
|
268
|
+
}),
|
|
269
|
+
el('stop', {
|
|
270
|
+
offset: '1',
|
|
271
|
+
'stop-color': dk
|
|
272
|
+
})
|
|
273
|
+
]),
|
|
274
|
+
el('clipPath', {
|
|
275
|
+
id: `${id}k`
|
|
276
|
+
}, [
|
|
277
|
+
el('path', {
|
|
278
|
+
d: S.d
|
|
279
|
+
})
|
|
280
|
+
]),
|
|
281
|
+
el('clipPath', {
|
|
282
|
+
id: `${id}c`
|
|
283
|
+
}, [
|
|
284
|
+
el('rect', {
|
|
285
|
+
x: vx,
|
|
286
|
+
y: vy,
|
|
287
|
+
width: vw,
|
|
288
|
+
height: vh,
|
|
289
|
+
rx: vr
|
|
290
|
+
})
|
|
291
|
+
]),
|
|
292
|
+
el('linearGradient', {
|
|
293
|
+
id: `${id}vg`,
|
|
294
|
+
x1: '0',
|
|
295
|
+
y1: '0',
|
|
296
|
+
x2: '0',
|
|
297
|
+
y2: '1'
|
|
298
|
+
}, [
|
|
299
|
+
el('stop', {
|
|
300
|
+
offset: '0',
|
|
301
|
+
'stop-color': '#3A4258'
|
|
302
|
+
}),
|
|
303
|
+
el('stop', {
|
|
304
|
+
offset: '.5',
|
|
305
|
+
'stop-color': '#1B2030'
|
|
306
|
+
}),
|
|
307
|
+
el('stop', {
|
|
308
|
+
offset: '1',
|
|
309
|
+
'stop-color': '#11141E'
|
|
310
|
+
})
|
|
311
|
+
]),
|
|
312
|
+
el('radialGradient', {
|
|
313
|
+
id: `${id}eg`
|
|
314
|
+
}, [
|
|
315
|
+
el('stop', {
|
|
316
|
+
offset: '0',
|
|
317
|
+
'stop-color': ecol,
|
|
318
|
+
'stop-opacity': '.55'
|
|
319
|
+
}),
|
|
320
|
+
el('stop', {
|
|
321
|
+
offset: '1',
|
|
322
|
+
'stop-color': ecol,
|
|
323
|
+
'stop-opacity': '0'
|
|
324
|
+
})
|
|
325
|
+
]),
|
|
326
|
+
el('radialGradient', {
|
|
327
|
+
id: `${id}s`
|
|
328
|
+
}, [
|
|
329
|
+
el('stop', {
|
|
330
|
+
offset: '0',
|
|
331
|
+
'stop-color': '#2A2838'
|
|
332
|
+
}),
|
|
333
|
+
el('stop', {
|
|
334
|
+
offset: '.55',
|
|
335
|
+
'stop-color': '#2A2838',
|
|
336
|
+
'stop-opacity': '.45'
|
|
337
|
+
}),
|
|
338
|
+
el('stop', {
|
|
339
|
+
offset: '1',
|
|
340
|
+
'stop-color': '#2A2838',
|
|
341
|
+
'stop-opacity': '0'
|
|
342
|
+
})
|
|
343
|
+
]),
|
|
344
|
+
el('clipPath', {
|
|
345
|
+
id: `${id}v`
|
|
346
|
+
}, [
|
|
347
|
+
el('rect', {
|
|
348
|
+
class: 'veilr',
|
|
349
|
+
x: -20,
|
|
350
|
+
y: -30,
|
|
351
|
+
width: 160,
|
|
352
|
+
height: Math.max(0, veilH)
|
|
353
|
+
})
|
|
354
|
+
])
|
|
355
|
+
]);
|
|
356
|
+
return {
|
|
357
|
+
width: size,
|
|
358
|
+
height: Math.round(128 * size / 136),
|
|
359
|
+
state: st,
|
|
360
|
+
ghosting: box || 'invite' === st || o.cover && 'off' !== st,
|
|
361
|
+
veiled: box || 'invite' === st,
|
|
362
|
+
children: [
|
|
363
|
+
defs,
|
|
364
|
+
...shadow,
|
|
365
|
+
el('g', {
|
|
366
|
+
class: 'fig',
|
|
367
|
+
transform: `translate(60 ${r2(108 + ty)}) rotate(0) scale(1 1) translate(-60 -108)`,
|
|
368
|
+
opacity: r2(figOp)
|
|
369
|
+
}, figChildren)
|
|
370
|
+
],
|
|
371
|
+
layers
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const bakeSize = (R, size, dpr)=>Math.ceil(size / 136 * R * Math.min(2, dpr || 1));
|
|
375
|
+
export { bakeSize, charTree };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function hexRgb(h: string): [number, number, number];
|
|
2
|
+
export declare const luma: (h: string) => number;
|
|
3
|
+
/** Linear in sRGB, rounded per channel, as on the page. */
|
|
4
|
+
export declare function mix(a: string, b: string, t: number): string;
|
|
5
|
+
/** Unknown ids fall back to the second palette entry (cobalt), as on the page. */
|
|
6
|
+
export declare const hexOf: (id: string) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { COLORS } from "./data.gen.js";
|
|
2
|
+
function hexRgb(h) {
|
|
3
|
+
const n = parseInt(h.slice(1), 16);
|
|
4
|
+
return [
|
|
5
|
+
n >> 16 & 255,
|
|
6
|
+
n >> 8 & 255,
|
|
7
|
+
255 & n
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
const luma = (h)=>{
|
|
11
|
+
const [r, g, b] = hexRgb(h);
|
|
12
|
+
return 0.299 * r + 0.587 * g + 0.114 * b;
|
|
13
|
+
};
|
|
14
|
+
function mix(a, b, t) {
|
|
15
|
+
const x = hexRgb(a);
|
|
16
|
+
const y = hexRgb(b);
|
|
17
|
+
return `#${x.map((v, i)=>Math.round(v + (y[i] - v) * t).toString(16).padStart(2, '0')).join('')}`;
|
|
18
|
+
}
|
|
19
|
+
const hexOf = (id)=>(COLORS.find((c)=>c.id === id) || COLORS["1"]).hex;
|
|
20
|
+
export { hexOf, hexRgb, luma, mix };
|