devnonla-ui 0.18.0 → 0.18.1
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/package.json +1 -1
- package/src/avatar/AgentAvatar.tsx +16 -4
- package/src/avatar/AgentBody.tsx +458 -0
- package/src/avatar/avatar.css +552 -4
- package/src/chat/message-ui/ChatWelcome.tsx +1 -1
- package/src/index.ts +2 -0
- package/src/markdown-editor/MermaidBlock.tsx +12 -0
- package/src/styles.css +1 -1
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createContext, type ReactNode, useContext, useEffect, useId, useState } from "react";
|
|
2
2
|
import { cn } from "../lib/cn";
|
|
3
3
|
|
|
4
|
-
/** `still` holds the pose. `idle`
|
|
4
|
+
/** `still` holds the pose. `idle` bobs the body, blinks, and glances. Defaults to `still`. */
|
|
5
5
|
export type AgentAvatarMotion = "still" | "idle";
|
|
6
6
|
|
|
7
|
-
/** Fixed facing. The shape stays centered and the eyes move that way. */
|
|
8
|
-
export type AgentAvatarLook = "forward" | "left" | "right" | "
|
|
7
|
+
/** Fixed facing. The shape stays centered and the eyes move that way. No straight-up glance. */
|
|
8
|
+
export type AgentAvatarLook = "forward" | "left" | "right" | "down" | "up-left" | "up-right" | "down-left" | "down-right";
|
|
9
9
|
|
|
10
10
|
/** Pupil color. Omitted picks black, or white when the face is dark. */
|
|
11
11
|
export type AgentAvatarEyeColor = "black" | "white";
|
|
@@ -130,7 +130,6 @@ const LOOK: Record<AgentAvatarLook, [number, number]> = {
|
|
|
130
130
|
forward: [0, 0],
|
|
131
131
|
left: [-6.4, 0],
|
|
132
132
|
right: [6.4, 0],
|
|
133
|
-
up: [0, -4.4],
|
|
134
133
|
down: [0, 4.4],
|
|
135
134
|
"up-left": [-4.5, -3.1],
|
|
136
135
|
"up-right": [4.5, -3.1],
|
|
@@ -273,6 +272,19 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
|
|
|
273
272
|
return <InkContext.Provider value={eyeFill(color, eyeColor)}>{body[shape]}</InkContext.Provider>;
|
|
274
273
|
}
|
|
275
274
|
|
|
275
|
+
export {
|
|
276
|
+
eyeFill,
|
|
277
|
+
InkContext,
|
|
278
|
+
LOOK,
|
|
279
|
+
mixHex,
|
|
280
|
+
PaintContext,
|
|
281
|
+
resolveConfig as resolveAvatarConfig,
|
|
282
|
+
ShadowContext,
|
|
283
|
+
Shape as AvatarShape,
|
|
284
|
+
stagger as avatarStagger,
|
|
285
|
+
useIdleLook,
|
|
286
|
+
};
|
|
287
|
+
|
|
276
288
|
export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
|
|
277
289
|
const resolved = resolveConfig(config);
|
|
278
290
|
const delay = stagger(`${resolved.shape}${resolved.color}`);
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { useEffect, useId, useState } from "react";
|
|
2
|
+
import { cn } from "../lib/cn";
|
|
3
|
+
import {
|
|
4
|
+
AGENT_AVATAR_PARTS,
|
|
5
|
+
type AgentAvatarConfig,
|
|
6
|
+
type AgentAvatarEyeColor,
|
|
7
|
+
type AgentAvatarLook,
|
|
8
|
+
AvatarShape,
|
|
9
|
+
avatarStagger,
|
|
10
|
+
LOOK,
|
|
11
|
+
mixHex,
|
|
12
|
+
PaintContext,
|
|
13
|
+
ShadowContext,
|
|
14
|
+
useIdleLook,
|
|
15
|
+
} from "./AgentAvatar";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `still` holds the pose. `idle` blinks and glances. `walk` steps the legs and swings the arms in the `look` direction.
|
|
19
|
+
* `run` is the same gait, faster, with a bigger swing and deeper knee and elbow bend.
|
|
20
|
+
* `talk` nods a little and gestures; pass `say` for a speech bubble above the head.
|
|
21
|
+
*/
|
|
22
|
+
export type AgentBodyMotion = "still" | "idle" | "walk" | "run" | "talk";
|
|
23
|
+
|
|
24
|
+
/** Pause after a page finishes before the next one. */
|
|
25
|
+
const PAGE_HOLD_MS = 1100;
|
|
26
|
+
|
|
27
|
+
/** Split on sentence ends / newlines, keeping the punctuation on the chunk. */
|
|
28
|
+
function splitSentences(text: string): string[] {
|
|
29
|
+
const parts = text.match(/[^.!?…\n]+(?:[.!?…]+|\n+)?/g);
|
|
30
|
+
if (!parts) return text.trim() ? [text.trim()] : [];
|
|
31
|
+
return parts.map((part) => part.replace(/\s+/g, " ").trim()).filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Break a long run into word pages that fit `maxChars`. Oversized words are hard-sliced. */
|
|
35
|
+
function chunkWords(text: string, maxChars: number): string[] {
|
|
36
|
+
const words = text.split(" ").filter(Boolean);
|
|
37
|
+
const pages: string[] = [];
|
|
38
|
+
let buf = "";
|
|
39
|
+
|
|
40
|
+
const push = () => {
|
|
41
|
+
if (buf) pages.push(buf);
|
|
42
|
+
buf = "";
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
for (const word of words) {
|
|
46
|
+
if (word.length > maxChars) {
|
|
47
|
+
push();
|
|
48
|
+
for (let i = 0; i < word.length; i += maxChars) {
|
|
49
|
+
pages.push(word.slice(i, i + maxChars));
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!buf) {
|
|
54
|
+
buf = word;
|
|
55
|
+
} else if (buf.length + 1 + word.length <= maxChars) {
|
|
56
|
+
buf = `${buf} ${word}`;
|
|
57
|
+
} else {
|
|
58
|
+
push();
|
|
59
|
+
buf = word;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
push();
|
|
63
|
+
return pages;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Paginate like an RPG dialogue box: prefer whole sentences, then pack short ones
|
|
68
|
+
* together, and word-wrap anything longer than `maxChars`.
|
|
69
|
+
*/
|
|
70
|
+
function paginateSay(text: string, maxChars: number): string[] {
|
|
71
|
+
const pages: string[] = [];
|
|
72
|
+
let buf = "";
|
|
73
|
+
|
|
74
|
+
const flush = () => {
|
|
75
|
+
if (buf) pages.push(buf);
|
|
76
|
+
buf = "";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
for (const sentence of splitSentences(text)) {
|
|
80
|
+
if (sentence.length > maxChars) {
|
|
81
|
+
flush();
|
|
82
|
+
pages.push(...chunkWords(sentence, maxChars));
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!buf) {
|
|
86
|
+
buf = sentence;
|
|
87
|
+
} else if (buf.length + 1 + sentence.length <= maxChars) {
|
|
88
|
+
buf = `${buf} ${sentence}`;
|
|
89
|
+
} else {
|
|
90
|
+
flush();
|
|
91
|
+
buf = sentence;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
flush();
|
|
95
|
+
return pages.length ? pages : [text];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Types the current page, then advances. Long `say` is cut into short pages first.
|
|
100
|
+
* Returns a blinking "more" cue while waiting on a non-final page.
|
|
101
|
+
*/
|
|
102
|
+
function useDialogue(text: string | undefined, maxChars: number, msPerChar = 32) {
|
|
103
|
+
const pages = text ? paginateSay(text, maxChars) : [];
|
|
104
|
+
const [page, setPage] = useState(0);
|
|
105
|
+
const [shown, setShown] = useState("");
|
|
106
|
+
const [typing, setTyping] = useState(false);
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
setPage(0);
|
|
110
|
+
}, [text, maxChars]);
|
|
111
|
+
|
|
112
|
+
const current = pages[page];
|
|
113
|
+
const hasMore = page < pages.length - 1;
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (!current) {
|
|
117
|
+
setShown("");
|
|
118
|
+
setTyping(false);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const media = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
123
|
+
let interval = 0;
|
|
124
|
+
let hold = 0;
|
|
125
|
+
|
|
126
|
+
const advanceLater = () => {
|
|
127
|
+
if (!hasMore) return;
|
|
128
|
+
hold = window.setTimeout(() => setPage((p) => p + 1), PAGE_HOLD_MS);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (media.matches) {
|
|
132
|
+
setShown(current);
|
|
133
|
+
setTyping(false);
|
|
134
|
+
advanceLater();
|
|
135
|
+
return () => window.clearTimeout(hold);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setShown("");
|
|
139
|
+
setTyping(true);
|
|
140
|
+
let i = 0;
|
|
141
|
+
interval = window.setInterval(() => {
|
|
142
|
+
i += 1;
|
|
143
|
+
setShown(current.slice(0, i));
|
|
144
|
+
if (i >= current.length) {
|
|
145
|
+
window.clearInterval(interval);
|
|
146
|
+
setTyping(false);
|
|
147
|
+
advanceLater();
|
|
148
|
+
}
|
|
149
|
+
}, msPerChar);
|
|
150
|
+
|
|
151
|
+
return () => {
|
|
152
|
+
window.clearInterval(interval);
|
|
153
|
+
window.clearTimeout(hold);
|
|
154
|
+
};
|
|
155
|
+
}, [current, hasMore, msPerChar]);
|
|
156
|
+
|
|
157
|
+
return { shown, typing, hasMore: hasMore && !typing };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Same 13 head shapes and palette as `AgentAvatar`. */
|
|
161
|
+
export const AGENT_BODY_PARTS = AGENT_AVATAR_PARTS;
|
|
162
|
+
|
|
163
|
+
type BodyShape = (typeof AGENT_BODY_PARTS.shape)[number] | "round";
|
|
164
|
+
|
|
165
|
+
export type AgentBodyConfig = {
|
|
166
|
+
shape: BodyShape;
|
|
167
|
+
color: string;
|
|
168
|
+
eyeColor?: AgentAvatarEyeColor;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/** Facing / walking direction. `up` is away from the viewer (seen from behind). */
|
|
172
|
+
export type AgentBodyLook = AgentAvatarLook | "up";
|
|
173
|
+
|
|
174
|
+
export type AgentBodyProps = {
|
|
175
|
+
/** Head shape and character color. Omitted parts use `nonla` and `#F47820`. */
|
|
176
|
+
config?: Partial<AgentBodyConfig>;
|
|
177
|
+
/** Width in px. Height follows the standing viewBox. Defaults to 80. */
|
|
178
|
+
size?: number;
|
|
179
|
+
motion?: AgentBodyMotion;
|
|
180
|
+
/** Facing / walking direction. Defaults to `forward`. */
|
|
181
|
+
look?: AgentBodyLook;
|
|
182
|
+
/**
|
|
183
|
+
* Spoken line. Shows an RPG speech bubble that types out above the head.
|
|
184
|
+
* Long text is split into short pages (by sentence, then by length) and advanced automatically.
|
|
185
|
+
*/
|
|
186
|
+
say?: string;
|
|
187
|
+
className?: string;
|
|
188
|
+
/** Accessible name. Defaults to "Agent". */
|
|
189
|
+
label?: string;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const DEFAULT_BODY_CONFIG: AgentAvatarConfig = {
|
|
193
|
+
shape: "nonla",
|
|
194
|
+
color: "#F47820",
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
function resolveBodyConfig(config?: Partial<AgentBodyConfig>): AgentAvatarConfig {
|
|
198
|
+
const rawShape = config?.shape ?? DEFAULT_BODY_CONFIG.shape;
|
|
199
|
+
const shape = rawShape === "round" ? "circle" : rawShape;
|
|
200
|
+
return {
|
|
201
|
+
shape,
|
|
202
|
+
color: config?.color ?? DEFAULT_BODY_CONFIG.color,
|
|
203
|
+
eyeColor: config?.eyeColor,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const VIEW_W = 80;
|
|
208
|
+
const VIEW_H = 108;
|
|
209
|
+
const ASPECT = VIEW_H / VIEW_W;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Cylinder torso: straight sides, same width top to bottom, softly rounded ends.
|
|
213
|
+
* Spans x=28.5..51.5, y=46..76. The shoulders (y=53) and hips (y=72) sit inside it.
|
|
214
|
+
* Sized a bit fuller than the head so the standing figure does not read as bobbleheaded.
|
|
215
|
+
*/
|
|
216
|
+
const TORSO = { x: 28.5, y: 46, width: 23, height: 30, rx: 7.5 } as const;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Short neck between the head and the torso. Narrow and mostly tucked under the chin
|
|
220
|
+
* so it does not read as a column sitting behind the head.
|
|
221
|
+
*/
|
|
222
|
+
const NECK = { x: 36.5, y: 39.5, width: 7, height: 10, rx: 2.2 } as const;
|
|
223
|
+
|
|
224
|
+
/** Shoulder joints at rest (far arm x=25.5, near arm x=54.5) and the torso center. */
|
|
225
|
+
const ARM_FAR_X = 25.5;
|
|
226
|
+
const ARM_NEAR_X = 54.5;
|
|
227
|
+
const ARM_CENTER = 40;
|
|
228
|
+
/**
|
|
229
|
+
* Side walk turns the torso a little toward the viewer: the near shoulder slips back and the far
|
|
230
|
+
* shoulder forward by this much, so the shoulders are close but not stacked.
|
|
231
|
+
*/
|
|
232
|
+
const ARM_TURN = 2.5;
|
|
233
|
+
/** Hip joints at rest (far leg x=35, near leg x=45). In a side walk they turn like the shoulders. */
|
|
234
|
+
const LEG_FAR_X = 35;
|
|
235
|
+
const LEG_NEAR_X = 45;
|
|
236
|
+
const LEG_TURN = ARM_TURN;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Where each head ends, in the 64-unit head box, measured near the neck column
|
|
240
|
+
* and after the shape's own vertical shift. Heads differ a lot (a pill ends at 46, a gem at 56),
|
|
241
|
+
* so each one is nudged vertically until its underside lands on the same line above the neck.
|
|
242
|
+
*/
|
|
243
|
+
const HEAD_BOTTOM: Record<AgentAvatarConfig["shape"], number> = {
|
|
244
|
+
circle: 53.5,
|
|
245
|
+
square: 55,
|
|
246
|
+
triangle: 56,
|
|
247
|
+
diamond: 51.7,
|
|
248
|
+
hex: 54,
|
|
249
|
+
gem: 56,
|
|
250
|
+
pill: 46,
|
|
251
|
+
arch: 48.3,
|
|
252
|
+
cloud: 48,
|
|
253
|
+
blob: 49.7,
|
|
254
|
+
drop: 54.4,
|
|
255
|
+
shield: 51.4,
|
|
256
|
+
/** Face circle bottom (~52.4); a lower value left the chin hanging over the neck. */
|
|
257
|
+
nonla: 52.6,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** Where the head underside should land (y in the body viewBox). Extra overlap hides the neck top. */
|
|
261
|
+
const HEAD_JOIN_Y = NECK.y + 4.5;
|
|
262
|
+
/** Head box is 64×64; keep it under ~0.7 so the torso reads larger than the face. */
|
|
263
|
+
const HEAD_SCALE = 0.68;
|
|
264
|
+
const HEAD_X = Number(((VIEW_W - 64 * HEAD_SCALE) / 2).toFixed(2));
|
|
265
|
+
|
|
266
|
+
function walkAxis(look: AgentBodyLook): "left" | "right" | "up" | "down" {
|
|
267
|
+
if (look === "left" || look === "up-left" || look === "down-left") return "left";
|
|
268
|
+
if (look === "right" || look === "up-right" || look === "down-right") return "right";
|
|
269
|
+
if (look === "up") return "up";
|
|
270
|
+
return "down";
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Full standing character: `AgentAvatar` head on a neck and rounded torso, with two arms and two legs.
|
|
275
|
+
* Each limb is drawn straight and rotates around a joint that sits inside the torso,
|
|
276
|
+
* so nothing detaches when it walks.
|
|
277
|
+
*/
|
|
278
|
+
export function AgentBody({
|
|
279
|
+
config,
|
|
280
|
+
size = 80,
|
|
281
|
+
motion = "still",
|
|
282
|
+
look = "forward",
|
|
283
|
+
say,
|
|
284
|
+
className,
|
|
285
|
+
label = "Agent",
|
|
286
|
+
}: AgentBodyProps) {
|
|
287
|
+
const resolved = resolveBodyConfig(config);
|
|
288
|
+
const delay = avatarStagger(`${resolved.shape}${resolved.color}`);
|
|
289
|
+
/** `look="up"` is the view from behind: no eyes, so there is nothing to glance with. */
|
|
290
|
+
const fromBehind = look === "up";
|
|
291
|
+
/** Walking down is walking at the viewer: the face looks straight ahead, not down. */
|
|
292
|
+
const home: AgentAvatarLook = look === "down" || look === "up" ? "forward" : look;
|
|
293
|
+
const shown = useIdleLook(motion === "idle" && !fromBehind, home, delay);
|
|
294
|
+
const [ex, ey] = LOOK[shown];
|
|
295
|
+
const dir = walkAxis(shown);
|
|
296
|
+
const headDrop = Number((HEAD_JOIN_Y - HEAD_BOTTOM[resolved.shape] * HEAD_SCALE).toFixed(2));
|
|
297
|
+
/** `run` reuses the walk cycle: same `data-motion="walk"` rules, with the gait sizes raised through `data-gait`. */
|
|
298
|
+
const walking = motion === "walk" || motion === "run";
|
|
299
|
+
const sideWalk = walking && (dir === "left" || dir === "right");
|
|
300
|
+
const turn = dir === "right" ? 1 : -1;
|
|
301
|
+
const farArmX = ARM_CENTER + turn * ARM_TURN - ARM_FAR_X;
|
|
302
|
+
const nearArmX = ARM_CENTER - turn * ARM_TURN - ARM_NEAR_X;
|
|
303
|
+
const farLegX = ARM_CENTER + turn * LEG_TURN - LEG_FAR_X;
|
|
304
|
+
const nearLegX = ARM_CENTER - turn * LEG_TURN - LEG_NEAR_X;
|
|
305
|
+
const line = say?.trim() || undefined;
|
|
306
|
+
const bubbleMax = Math.round(Math.min(200, Math.max(112, size * 2.35)));
|
|
307
|
+
/** ~2–3 mono lines in the bubble. Scales a little with character size. */
|
|
308
|
+
const pageChars = Math.round(Math.min(52, Math.max(36, size * 0.48)));
|
|
309
|
+
const { shown: typed, typing, hasMore } = useDialogue(line, pageChars);
|
|
310
|
+
const uid = useId().replace(/:/g, "");
|
|
311
|
+
const headLight = `nonla-bh-${uid}`;
|
|
312
|
+
const torsoLight = `nonla-bt-${uid}`;
|
|
313
|
+
const neckLight = `nonla-bn-${uid}`;
|
|
314
|
+
const shadow = `nonla-bs-${uid}`;
|
|
315
|
+
|
|
316
|
+
/** Limbs stay a step lighter than the torso so the body mass reads clearly. */
|
|
317
|
+
const nearStroke = mixHex(resolved.color, "#fff", 0.14);
|
|
318
|
+
const farStroke = mixHex(resolved.color, "#fff", 0.02);
|
|
319
|
+
const strokeProps = {
|
|
320
|
+
fill: "none" as const,
|
|
321
|
+
strokeWidth: 5.2,
|
|
322
|
+
strokeLinecap: "round" as const,
|
|
323
|
+
strokeLinejoin: "round" as const,
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
return (
|
|
327
|
+
<span
|
|
328
|
+
role="img"
|
|
329
|
+
aria-label={line ? `${label}. ${line}` : label}
|
|
330
|
+
data-motion={motion === "run" ? "walk" : motion}
|
|
331
|
+
data-gait={motion === "run" ? "run" : undefined}
|
|
332
|
+
data-look={shown}
|
|
333
|
+
data-dir={dir}
|
|
334
|
+
data-back={fromBehind ? "" : undefined}
|
|
335
|
+
data-say={line ? "" : undefined}
|
|
336
|
+
className={cn("nonla-body", className)}
|
|
337
|
+
style={{
|
|
338
|
+
width: size,
|
|
339
|
+
height: size * ASPECT,
|
|
340
|
+
["--nonla-avatar-delay" as string]: `${delay}s`,
|
|
341
|
+
["--nonla-avatar-ex" as string]: `${(ex / 64) * 100}%`,
|
|
342
|
+
["--nonla-avatar-ey" as string]: `${(ey / 64) * 100}%`,
|
|
343
|
+
["--nonla-body-bubble-size" as string]: `${Math.max(11, Math.round(size * 0.145))}px`,
|
|
344
|
+
["--nonla-body-bubble-max" as string]: `${bubbleMax}px`,
|
|
345
|
+
}}
|
|
346
|
+
>
|
|
347
|
+
{line ? (
|
|
348
|
+
<span
|
|
349
|
+
className="nonla-body-bubble"
|
|
350
|
+
data-typing={typing ? "" : undefined}
|
|
351
|
+
data-more={hasMore ? "" : undefined}
|
|
352
|
+
aria-hidden
|
|
353
|
+
>
|
|
354
|
+
<span className="nonla-body-bubble-text">
|
|
355
|
+
{typed}
|
|
356
|
+
{typing ? <span className="nonla-body-bubble-caret" /> : null}
|
|
357
|
+
</span>
|
|
358
|
+
{hasMore ? <span className="nonla-body-bubble-more" /> : null}
|
|
359
|
+
</span>
|
|
360
|
+
) : null}
|
|
361
|
+
<svg viewBox={`0 0 ${VIEW_W} ${VIEW_H}`} width="100%" height="100%" aria-hidden>
|
|
362
|
+
<defs>
|
|
363
|
+
<linearGradient id={headLight} gradientUnits="userSpaceOnUse" x1="32" y1="4" x2="32" y2="60">
|
|
364
|
+
<stop offset="0" stopColor={mixHex(resolved.color, "#fff", 0.16)} />
|
|
365
|
+
<stop offset="1" stopColor={resolved.color} />
|
|
366
|
+
</linearGradient>
|
|
367
|
+
{/* Torso a step darker than head/limbs so the body mass separates from the sticks. */}
|
|
368
|
+
<linearGradient id={torsoLight} gradientUnits="userSpaceOnUse" x1={TORSO.x} y1="0" x2={TORSO.x + TORSO.width} y2="0">
|
|
369
|
+
<stop offset="0" stopColor={mixHex(resolved.color, "#000", 0.1)} />
|
|
370
|
+
<stop offset="0.32" stopColor={mixHex(resolved.color, "#000", 0.04)} />
|
|
371
|
+
<stop offset="0.75" stopColor={mixHex(resolved.color, "#000", 0.14)} />
|
|
372
|
+
<stop offset="1" stopColor={mixHex(resolved.color, "#000", 0.22)} />
|
|
373
|
+
</linearGradient>
|
|
374
|
+
{/* Neck sits between head and torso — closer to the brighter limb tone. */}
|
|
375
|
+
<linearGradient id={neckLight} gradientUnits="userSpaceOnUse" x1={NECK.x} y1="0" x2={NECK.x + NECK.width} y2="0">
|
|
376
|
+
<stop offset="0" stopColor={mixHex(resolved.color, "#fff", 0.08)} />
|
|
377
|
+
<stop offset="0.5" stopColor={mixHex(resolved.color, "#fff", 0.04)} />
|
|
378
|
+
<stop offset="1" stopColor={mixHex(resolved.color, "#000", 0.06)} />
|
|
379
|
+
</linearGradient>
|
|
380
|
+
<filter id={shadow} x="-20%" y="-20%" width="140%" height="150%">
|
|
381
|
+
<feDropShadow dx="0" dy="0.9" stdDeviation="0.6" floodColor="#000" floodOpacity="0.18" />
|
|
382
|
+
</filter>
|
|
383
|
+
</defs>
|
|
384
|
+
|
|
385
|
+
<g filter={`url(#${shadow})`}>
|
|
386
|
+
{/*
|
|
387
|
+
Limbs are drawn straight down from their joints. The rest splay and the walk cycle are
|
|
388
|
+
CSS rotations around that joint. Legs and arms start inside the torso, which is painted
|
|
389
|
+
over the joints, so the joint is always covered.
|
|
390
|
+
Hip y=72 -> knee y=85 -> foot y=98. Shoulder y=53 -> elbow y=61.5 -> hand y=70.
|
|
391
|
+
*/}
|
|
392
|
+
|
|
393
|
+
{/* Legs first: the torso covers the hips */}
|
|
394
|
+
{/* In a side walk the hips sit at the torso center, turned a hair like the shoulders. */}
|
|
395
|
+
<g transform={sideWalk ? `translate(${farLegX} 0)` : undefined}>
|
|
396
|
+
<g className="nonla-stick-leg nonla-stick-leg-b" stroke={farStroke} {...strokeProps}>
|
|
397
|
+
{/* One stick at rest; walk swaps to thigh + shin so the knee can fold. */}
|
|
398
|
+
<line className="nonla-stick-leg-bone" x1="35" y1="72" x2="35" y2="98" />
|
|
399
|
+
<line className="nonla-stick-thigh" x1="35" y1="72" x2="35" y2="85" />
|
|
400
|
+
<g className="nonla-stick-shin">
|
|
401
|
+
<line x1="35" y1="85" x2="35" y2="98" />
|
|
402
|
+
</g>
|
|
403
|
+
</g>
|
|
404
|
+
</g>
|
|
405
|
+
<g transform={sideWalk ? `translate(${nearLegX} 0)` : undefined}>
|
|
406
|
+
<g className="nonla-stick-leg nonla-stick-leg-f" stroke={nearStroke} {...strokeProps}>
|
|
407
|
+
<line className="nonla-stick-leg-bone" x1="45" y1="72" x2="45" y2="98" />
|
|
408
|
+
<line className="nonla-stick-thigh" x1="45" y1="72" x2="45" y2="85" />
|
|
409
|
+
<g className="nonla-stick-shin">
|
|
410
|
+
<line x1="45" y1="85" x2="45" y2="98" />
|
|
411
|
+
</g>
|
|
412
|
+
</g>
|
|
413
|
+
</g>
|
|
414
|
+
|
|
415
|
+
{/*
|
|
416
|
+
Left arm sits behind the torso edge. In a side walk (left or right) both shoulders move
|
|
417
|
+
to the middle of the torso, a hair apart as if the torso is turned a little toward the
|
|
418
|
+
viewer. The far arm stays behind the torso and the near arm in front.
|
|
419
|
+
*/}
|
|
420
|
+
<g transform={sideWalk ? `translate(${farArmX} 0)` : undefined}>
|
|
421
|
+
<g className="nonla-stick-arm nonla-stick-arm-b" stroke={farStroke} {...strokeProps}>
|
|
422
|
+
<line x1="25.5" y1="53" x2="25.5" y2="61.5" />
|
|
423
|
+
<g className="nonla-stick-forearm">
|
|
424
|
+
<line x1="25.5" y1="61.5" x2="25.5" y2="70" />
|
|
425
|
+
</g>
|
|
426
|
+
</g>
|
|
427
|
+
</g>
|
|
428
|
+
|
|
429
|
+
{/* Neck, then the cylinder torso over its lower end */}
|
|
430
|
+
<rect className="nonla-body-neck" {...NECK} fill={`url(#${neckLight})`} />
|
|
431
|
+
<rect className="nonla-body-torso" {...TORSO} fill={`url(#${torsoLight})`} />
|
|
432
|
+
|
|
433
|
+
{/* Right arm hangs in front of the torso edge */}
|
|
434
|
+
<g transform={sideWalk ? `translate(${nearArmX} 0)` : undefined}>
|
|
435
|
+
<g className="nonla-stick-arm nonla-stick-arm-f" stroke={nearStroke} {...strokeProps}>
|
|
436
|
+
<line x1="54.5" y1="53" x2="54.5" y2="61.5" />
|
|
437
|
+
<g className="nonla-stick-forearm">
|
|
438
|
+
<line x1="54.5" y1="61.5" x2="54.5" y2="70" />
|
|
439
|
+
</g>
|
|
440
|
+
</g>
|
|
441
|
+
</g>
|
|
442
|
+
|
|
443
|
+
{/* AgentAvatar head on top */}
|
|
444
|
+
<g className="nonla-body-head">
|
|
445
|
+
<g transform={`translate(${HEAD_X} ${headDrop}) scale(${HEAD_SCALE})`}>
|
|
446
|
+
<PaintContext.Provider value={`url(#${headLight})`}>
|
|
447
|
+
{/* No shadow of its own: the group already has one, and a second one under the head dirties the neck. */}
|
|
448
|
+
<ShadowContext.Provider value={undefined}>
|
|
449
|
+
<AvatarShape {...resolved} />
|
|
450
|
+
</ShadowContext.Provider>
|
|
451
|
+
</PaintContext.Provider>
|
|
452
|
+
</g>
|
|
453
|
+
</g>
|
|
454
|
+
</g>
|
|
455
|
+
</svg>
|
|
456
|
+
</span>
|
|
457
|
+
);
|
|
458
|
+
}
|
package/src/avatar/avatar.css
CHANGED
|
@@ -10,7 +10,21 @@
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
/*
|
|
13
|
+
/* Soft idle bob: rise + stretch, settle + squash. Claude-style weight. */
|
|
14
|
+
@keyframes nonla-avatar-bob {
|
|
15
|
+
0%,
|
|
16
|
+
100% {
|
|
17
|
+
transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
|
|
18
|
+
}
|
|
19
|
+
45% {
|
|
20
|
+
transform: translate3d(0, -6%, 0) scale3d(0.97, 1.045, 1);
|
|
21
|
+
}
|
|
22
|
+
70% {
|
|
23
|
+
transform: translate3d(0, 1.5%, 0) scale3d(1.025, 0.97, 1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* The body bobs as one piece. Only the eyes travel for look. */
|
|
14
28
|
.nonla-avatar {
|
|
15
29
|
display: inline-flex;
|
|
16
30
|
flex-shrink: 0;
|
|
@@ -22,6 +36,8 @@
|
|
|
22
36
|
display: block;
|
|
23
37
|
width: 100%;
|
|
24
38
|
height: 100%;
|
|
39
|
+
transform-origin: 50% 85%;
|
|
40
|
+
will-change: transform;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
43
|
.nonla-avatar-gaze {
|
|
@@ -34,19 +50,551 @@
|
|
|
34
50
|
transform-origin: center;
|
|
35
51
|
}
|
|
36
52
|
|
|
37
|
-
.nonla-avatar[data-motion="idle"] .nonla-avatar-
|
|
38
|
-
|
|
53
|
+
.nonla-avatar[data-motion="idle"] .nonla-avatar-bob {
|
|
54
|
+
animation: nonla-avatar-bob 2.2s ease-in-out infinite;
|
|
55
|
+
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.nonla-avatar[data-motion="idle"] .nonla-avatar-gaze,
|
|
59
|
+
.nonla-body[data-motion] .nonla-avatar-gaze {
|
|
60
|
+
transition: transform 0.35s ease-out;
|
|
39
61
|
}
|
|
40
62
|
|
|
41
|
-
.nonla-avatar[data-motion="idle"] .nonla-avatar-eyes
|
|
63
|
+
.nonla-avatar[data-motion="idle"] .nonla-avatar-eyes,
|
|
64
|
+
.nonla-body[data-motion="idle"] .nonla-avatar-eyes,
|
|
65
|
+
.nonla-body[data-motion="walk"] .nonla-avatar-eyes {
|
|
42
66
|
animation: nonla-avatar-blink 6.4s ease-in-out infinite;
|
|
43
67
|
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
44
68
|
}
|
|
45
69
|
|
|
70
|
+
/* Seen from behind (look="up"): the eyes and mouth are on the far side of the head. */
|
|
71
|
+
.nonla-body[data-back] .nonla-avatar-gaze {
|
|
72
|
+
display: none;
|
|
73
|
+
}
|
|
74
|
+
|
|
46
75
|
@media (prefers-reduced-motion: reduce) {
|
|
76
|
+
.nonla-avatar[data-motion] .nonla-avatar-bob,
|
|
47
77
|
.nonla-avatar[data-motion] .nonla-avatar-gaze,
|
|
48
78
|
.nonla-avatar[data-motion] .nonla-avatar-eyes {
|
|
49
79
|
animation: none;
|
|
50
80
|
transition: none;
|
|
51
81
|
}
|
|
52
82
|
}
|
|
83
|
+
|
|
84
|
+
/* —— AgentBody: stick figure. Every limb is straight in the SVG and rotates around its joint. —— */
|
|
85
|
+
|
|
86
|
+
.nonla-body {
|
|
87
|
+
position: relative;
|
|
88
|
+
display: inline-flex;
|
|
89
|
+
flex-shrink: 0;
|
|
90
|
+
line-height: 0;
|
|
91
|
+
vertical-align: middle;
|
|
92
|
+
overflow: visible;
|
|
93
|
+
|
|
94
|
+
/* One full stride (left step + right step). Docs demo moves ~84px/s at 80px wide to match. */
|
|
95
|
+
--nonla-step: 0.5s;
|
|
96
|
+
/* Gait size. 1 is a walk. `run` raises them: bigger swing, deeper knee and elbow bend, shorter stride time. */
|
|
97
|
+
--nonla-a: 1;
|
|
98
|
+
--nonla-knee: 1;
|
|
99
|
+
--nonla-elbow: 1;
|
|
100
|
+
--nonla-fold: 1;
|
|
101
|
+
/* Front / back walk: how far a leg lengthens (toward the viewer) or shortens (away) on screen. */
|
|
102
|
+
--nonla-reach: 0.35;
|
|
103
|
+
|
|
104
|
+
/* +1 walks right, -1 walks left. Angles below are written as "forward" and flipped by this. */
|
|
105
|
+
--nonla-d: 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* RPG speech bubble: thick ink outline, cream fill, pointed tail, types out `say`. */
|
|
109
|
+
.nonla-body-bubble {
|
|
110
|
+
position: absolute;
|
|
111
|
+
left: 50%;
|
|
112
|
+
bottom: calc(100% - 2%);
|
|
113
|
+
z-index: 1;
|
|
114
|
+
box-sizing: border-box;
|
|
115
|
+
width: max-content;
|
|
116
|
+
max-width: var(--nonla-body-bubble-max, 160px);
|
|
117
|
+
min-width: 2.75em;
|
|
118
|
+
padding: 0.42em 0.62em 0.48em;
|
|
119
|
+
border: 2.5px solid #1c1c1c;
|
|
120
|
+
border-radius: 0.95em;
|
|
121
|
+
background: #fffef6;
|
|
122
|
+
color: #1c1c1c;
|
|
123
|
+
font-family: var(--nonla-mono-font, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace);
|
|
124
|
+
font-size: var(--nonla-body-bubble-size, 11px);
|
|
125
|
+
font-weight: 400;
|
|
126
|
+
line-height: 1.3;
|
|
127
|
+
letter-spacing: 0.01em;
|
|
128
|
+
text-align: left;
|
|
129
|
+
white-space: normal;
|
|
130
|
+
overflow-wrap: anywhere;
|
|
131
|
+
word-break: break-word;
|
|
132
|
+
hyphens: auto;
|
|
133
|
+
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.18);
|
|
134
|
+
transform: translateX(-50%);
|
|
135
|
+
transform-origin: 50% 100%;
|
|
136
|
+
pointer-events: none;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Outer (ink) triangle, then the cream fill on top — classic game balloon tail. */
|
|
140
|
+
.nonla-body-bubble::before,
|
|
141
|
+
.nonla-body-bubble::after {
|
|
142
|
+
content: "";
|
|
143
|
+
position: absolute;
|
|
144
|
+
left: 50%;
|
|
145
|
+
top: 100%;
|
|
146
|
+
width: 0;
|
|
147
|
+
height: 0;
|
|
148
|
+
border-style: solid;
|
|
149
|
+
border-left-color: transparent;
|
|
150
|
+
border-right-color: transparent;
|
|
151
|
+
border-bottom: 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.nonla-body-bubble::before {
|
|
155
|
+
margin-left: -7px;
|
|
156
|
+
border-width: 9px 7px 0;
|
|
157
|
+
border-top-color: #1c1c1c;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.nonla-body-bubble::after {
|
|
161
|
+
margin-left: -5px;
|
|
162
|
+
margin-top: -0.5px;
|
|
163
|
+
border-width: 6.5px 5px 0;
|
|
164
|
+
border-top-color: #fffef6;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.nonla-body-bubble-text {
|
|
168
|
+
display: block;
|
|
169
|
+
position: relative;
|
|
170
|
+
z-index: 1;
|
|
171
|
+
min-height: 1.3em;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.nonla-body-bubble-caret {
|
|
175
|
+
display: inline-block;
|
|
176
|
+
width: 0.08em;
|
|
177
|
+
height: 0.95em;
|
|
178
|
+
margin-left: 0.08em;
|
|
179
|
+
vertical-align: -0.12em;
|
|
180
|
+
background: #1c1c1c;
|
|
181
|
+
animation: nonla-body-bubble-caret 0.55s steps(1, end) infinite;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Classic RPG "more text" cue while waiting on the next page. */
|
|
185
|
+
.nonla-body-bubble-more {
|
|
186
|
+
display: block;
|
|
187
|
+
width: 0;
|
|
188
|
+
height: 0;
|
|
189
|
+
margin: 0.15em auto 0;
|
|
190
|
+
border-style: solid;
|
|
191
|
+
border-width: 0.42em 0.34em 0;
|
|
192
|
+
border-color: #1c1c1c transparent transparent;
|
|
193
|
+
animation: nonla-body-bubble-caret 0.7s steps(1, end) infinite;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.nonla-body[data-say] .nonla-body-bubble {
|
|
197
|
+
animation: nonla-body-bubble-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1) both;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@keyframes nonla-body-bubble-in {
|
|
201
|
+
from {
|
|
202
|
+
opacity: 0;
|
|
203
|
+
transform: translateX(-50%) translateY(6px) scale(0.86);
|
|
204
|
+
}
|
|
205
|
+
to {
|
|
206
|
+
opacity: 1;
|
|
207
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@keyframes nonla-body-bubble-caret {
|
|
212
|
+
0%,
|
|
213
|
+
49% {
|
|
214
|
+
opacity: 1;
|
|
215
|
+
}
|
|
216
|
+
50%,
|
|
217
|
+
100% {
|
|
218
|
+
opacity: 0;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.nonla-body[data-dir="left"] {
|
|
223
|
+
--nonla-d: -1;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.nonla-body[data-gait="run"] {
|
|
227
|
+
--nonla-step: 0.38s;
|
|
228
|
+
--nonla-a: 1.45;
|
|
229
|
+
--nonla-knee: 1.7;
|
|
230
|
+
--nonla-elbow: 2.3;
|
|
231
|
+
--nonla-fold: 1.2;
|
|
232
|
+
--nonla-reach: 0.45;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.nonla-body svg {
|
|
236
|
+
display: block;
|
|
237
|
+
overflow: visible;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* Joint pivots in viewBox units (80x108). Each limb sets its own x; hip y=72, knee y=85,
|
|
242
|
+
* shoulder y=53, elbow y=61.5. Children inherit x, so a shin pivots under its own thigh.
|
|
243
|
+
*/
|
|
244
|
+
.nonla-stick-leg {
|
|
245
|
+
transform-box: view-box;
|
|
246
|
+
transform-origin: var(--nonla-x) 72px;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.nonla-stick-shin {
|
|
250
|
+
transform-box: view-box;
|
|
251
|
+
transform-origin: var(--nonla-x) 85px;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.nonla-stick-arm {
|
|
255
|
+
transform-box: view-box;
|
|
256
|
+
transform-origin: var(--nonla-x) 53px;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.nonla-stick-forearm {
|
|
260
|
+
transform-box: view-box;
|
|
261
|
+
transform-origin: var(--nonla-x) 61.5px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Rest pose: a small natural splay, outward on each side. Left limbs lean left, right limbs lean right. */
|
|
265
|
+
.nonla-stick-leg-b {
|
|
266
|
+
--nonla-x: 35px;
|
|
267
|
+
--nonla-rest: 2deg;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.nonla-stick-leg-f {
|
|
271
|
+
--nonla-x: 45px;
|
|
272
|
+
--nonla-rest: -2deg;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/*
|
|
276
|
+
* Rest (still / idle / talk): one continuous stick — no knee joint, so the leg does not look bent.
|
|
277
|
+
* Walk: hide the full bone and show thigh + shin so the knee can fold.
|
|
278
|
+
*/
|
|
279
|
+
.nonla-stick-thigh,
|
|
280
|
+
.nonla-stick-shin {
|
|
281
|
+
opacity: 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.nonla-body[data-motion="walk"] .nonla-stick-leg-bone {
|
|
285
|
+
opacity: 0;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.nonla-body[data-motion="walk"] .nonla-stick-thigh,
|
|
289
|
+
.nonla-body[data-motion="walk"] .nonla-stick-shin {
|
|
290
|
+
opacity: 1;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.nonla-stick-arm-b {
|
|
294
|
+
--nonla-x: 25.5px;
|
|
295
|
+
--nonla-rest: 2deg;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.nonla-stick-arm-f {
|
|
299
|
+
--nonla-x: 54.5px;
|
|
300
|
+
--nonla-rest: -2deg;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.nonla-stick-leg,
|
|
304
|
+
.nonla-stick-arm {
|
|
305
|
+
transform: rotate(var(--nonla-rest, 0deg));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/* Talk: soft bob + a small near-arm gesture. After base limb selectors (specificity order). */
|
|
309
|
+
@keyframes nonla-body-talk-bob {
|
|
310
|
+
0%,
|
|
311
|
+
100% {
|
|
312
|
+
transform: translate3d(0, 0, 0);
|
|
313
|
+
}
|
|
314
|
+
40% {
|
|
315
|
+
transform: translate3d(0, -1.6%, 0);
|
|
316
|
+
}
|
|
317
|
+
70% {
|
|
318
|
+
transform: translate3d(0, 0.4%, 0);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
@keyframes nonla-body-talk-arm {
|
|
323
|
+
0%,
|
|
324
|
+
100% {
|
|
325
|
+
transform: rotate(calc(var(--nonla-rest, 0deg) - 18deg));
|
|
326
|
+
}
|
|
327
|
+
45% {
|
|
328
|
+
transform: rotate(calc(var(--nonla-rest, 0deg) - 32deg));
|
|
329
|
+
}
|
|
330
|
+
70% {
|
|
331
|
+
transform: rotate(calc(var(--nonla-rest, 0deg) - 14deg));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
@keyframes nonla-body-talk-forearm {
|
|
336
|
+
0%,
|
|
337
|
+
100% {
|
|
338
|
+
transform: rotate(-28deg);
|
|
339
|
+
}
|
|
340
|
+
45% {
|
|
341
|
+
transform: rotate(-42deg);
|
|
342
|
+
}
|
|
343
|
+
70% {
|
|
344
|
+
transform: rotate(-22deg);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.nonla-body[data-motion="talk"] svg {
|
|
349
|
+
animation: nonla-body-talk-bob 1.6s ease-in-out infinite;
|
|
350
|
+
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.nonla-body[data-motion="talk"] .nonla-stick-arm-f {
|
|
354
|
+
animation: nonla-body-talk-arm 1.6s ease-in-out infinite;
|
|
355
|
+
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.nonla-body[data-motion="talk"] .nonla-stick-arm-f .nonla-stick-forearm {
|
|
359
|
+
animation: nonla-body-talk-forearm 1.6s ease-in-out infinite;
|
|
360
|
+
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.nonla-body[data-motion="talk"] .nonla-avatar-eyes {
|
|
364
|
+
animation: nonla-avatar-blink 6.4s ease-in-out infinite;
|
|
365
|
+
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/*
|
|
369
|
+
* Side walk (left / right). Negative angle = limb reaches forward when walking right;
|
|
370
|
+
* --nonla-d flips it for walking left.
|
|
371
|
+
*
|
|
372
|
+
* Leg, one stride:
|
|
373
|
+
* 0% heel strike: leg forward, almost straight
|
|
374
|
+
* 0-50% stance: foot stays planted, so the thigh sweeps back at a steady rate (linear)
|
|
375
|
+
* 50% toe off: leg behind the hip
|
|
376
|
+
* 50-100% swing: thigh comes forward and the knee folds to clear the ground
|
|
377
|
+
*/
|
|
378
|
+
@keyframes nonla-stick-thigh {
|
|
379
|
+
0% {
|
|
380
|
+
transform: rotate(calc(var(--nonla-d) * -28deg * var(--nonla-a)));
|
|
381
|
+
animation-timing-function: linear;
|
|
382
|
+
}
|
|
383
|
+
50% {
|
|
384
|
+
transform: rotate(calc(var(--nonla-d) * 24deg * var(--nonla-a)));
|
|
385
|
+
animation-timing-function: ease-in-out;
|
|
386
|
+
}
|
|
387
|
+
100% {
|
|
388
|
+
transform: rotate(calc(var(--nonla-d) * -28deg * var(--nonla-a)));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/* The shin folds backward (opposite to forward) and straightens before the next heel strike. */
|
|
393
|
+
@keyframes nonla-stick-knee {
|
|
394
|
+
0% {
|
|
395
|
+
transform: rotate(calc(var(--nonla-d) * 3deg * var(--nonla-knee)));
|
|
396
|
+
}
|
|
397
|
+
14% {
|
|
398
|
+
transform: rotate(calc(var(--nonla-d) * 12deg * var(--nonla-knee)));
|
|
399
|
+
}
|
|
400
|
+
50% {
|
|
401
|
+
transform: rotate(calc(var(--nonla-d) * 14deg * var(--nonla-knee)));
|
|
402
|
+
}
|
|
403
|
+
72% {
|
|
404
|
+
transform: rotate(calc(var(--nonla-d) * 50deg * var(--nonla-knee)));
|
|
405
|
+
}
|
|
406
|
+
90% {
|
|
407
|
+
transform: rotate(calc(var(--nonla-d) * 16deg * var(--nonla-knee)));
|
|
408
|
+
}
|
|
409
|
+
100% {
|
|
410
|
+
transform: rotate(calc(var(--nonla-d) * 3deg * var(--nonla-knee)));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/* Arms swing opposite to the leg on the same side, with a looser elbow. */
|
|
415
|
+
@keyframes nonla-stick-arm-swing {
|
|
416
|
+
0% {
|
|
417
|
+
transform: rotate(calc(var(--nonla-d) * -22deg * var(--nonla-a)));
|
|
418
|
+
}
|
|
419
|
+
50% {
|
|
420
|
+
transform: rotate(calc(var(--nonla-d) * 16deg * var(--nonla-a)));
|
|
421
|
+
}
|
|
422
|
+
100% {
|
|
423
|
+
transform: rotate(calc(var(--nonla-d) * -22deg * var(--nonla-a)));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
@keyframes nonla-stick-elbow {
|
|
428
|
+
0% {
|
|
429
|
+
transform: rotate(calc(var(--nonla-d) * -26deg * var(--nonla-elbow)));
|
|
430
|
+
}
|
|
431
|
+
50% {
|
|
432
|
+
transform: rotate(calc(var(--nonla-d) * -6deg * var(--nonla-elbow)));
|
|
433
|
+
}
|
|
434
|
+
100% {
|
|
435
|
+
transform: rotate(calc(var(--nonla-d) * -26deg * var(--nonla-elbow)));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
.nonla-body[data-motion="walk"][data-dir="left"] .nonla-stick-leg,
|
|
440
|
+
.nonla-body[data-motion="walk"][data-dir="right"] .nonla-stick-leg {
|
|
441
|
+
animation: nonla-stick-thigh var(--nonla-step) linear infinite;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.nonla-body[data-motion="walk"][data-dir="left"] .nonla-stick-shin,
|
|
445
|
+
.nonla-body[data-motion="walk"][data-dir="right"] .nonla-stick-shin {
|
|
446
|
+
animation: nonla-stick-knee var(--nonla-step) linear infinite;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
.nonla-body[data-motion="walk"][data-dir="left"] .nonla-stick-arm,
|
|
450
|
+
.nonla-body[data-motion="walk"][data-dir="right"] .nonla-stick-arm {
|
|
451
|
+
animation: nonla-stick-arm-swing var(--nonla-step) ease-in-out infinite;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.nonla-body[data-motion="walk"][data-dir="left"] .nonla-stick-forearm,
|
|
455
|
+
.nonla-body[data-motion="walk"][data-dir="right"] .nonla-stick-forearm {
|
|
456
|
+
animation: nonla-stick-elbow var(--nonla-step) ease-in-out infinite;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/*
|
|
460
|
+
* Walking toward or away from the viewer. The legs stay under the hip, and depth shows as
|
|
461
|
+
* foreshortening: a leg reaching toward the viewer is longer on screen, one reaching away is shorter.
|
|
462
|
+
* Timing is the side walk's (planted 0-50%, swing 50-100% with the knee folding at 72%), and the
|
|
463
|
+
* planted foot must stand still on the floor. The body moves on screen while it is planted, so the
|
|
464
|
+
* foot slides the other way along the leg: toward the viewer the body goes down, the foot goes up
|
|
465
|
+
* (long to short), and away from the viewer the foot goes down (short to long). It moves linearly,
|
|
466
|
+
* by 0.7 of the leg when walking (about 18 units, --nonla-reach 0.35 each way). That is the floor
|
|
467
|
+
* distance one half-stride covers on screen, so the docs demo walks vertically at SPEED_Y = 70px/s,
|
|
468
|
+
* close to the 84px/s sideways. A foot closer to the viewer sits lower, which is also what depth
|
|
469
|
+
* looks like, so the legs may reach a little past the usual foot line.
|
|
470
|
+
*/
|
|
471
|
+
@keyframes nonla-stick-step-down {
|
|
472
|
+
0% {
|
|
473
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 + var(--nonla-reach)));
|
|
474
|
+
animation-timing-function: linear;
|
|
475
|
+
}
|
|
476
|
+
50% {
|
|
477
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 - var(--nonla-reach)));
|
|
478
|
+
animation-timing-function: ease-out;
|
|
479
|
+
}
|
|
480
|
+
72% {
|
|
481
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 - 0.5 * var(--nonla-fold)));
|
|
482
|
+
animation-timing-function: ease-in;
|
|
483
|
+
}
|
|
484
|
+
100% {
|
|
485
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 + var(--nonla-reach)));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
@keyframes nonla-stick-step-up {
|
|
490
|
+
0% {
|
|
491
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 - var(--nonla-reach)));
|
|
492
|
+
animation-timing-function: linear;
|
|
493
|
+
}
|
|
494
|
+
50% {
|
|
495
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 + var(--nonla-reach)));
|
|
496
|
+
animation-timing-function: ease-out;
|
|
497
|
+
}
|
|
498
|
+
72% {
|
|
499
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 - 0.5 * var(--nonla-fold)));
|
|
500
|
+
animation-timing-function: ease-in;
|
|
501
|
+
}
|
|
502
|
+
100% {
|
|
503
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 - var(--nonla-reach)));
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/*
|
|
508
|
+
* Arms keep the side-walk rhythm (same period, same ease-in-out, same phase) turned to face the
|
|
509
|
+
* viewer. The swing now goes toward and away from the screen, so an angle becomes a length:
|
|
510
|
+
* 0% arm reaches forward (side walk: -22deg) and the elbow bends most (-26deg), so both
|
|
511
|
+
* segments are foreshortened, the forearm more because its angle adds up (48deg)
|
|
512
|
+
* 50% arm swings back (+16deg) and the elbow nearly straightens (-6deg): almost full length
|
|
513
|
+
* The lengths are cos(angle), a little exaggerated so the perspective reads at 80px.
|
|
514
|
+
*/
|
|
515
|
+
@keyframes nonla-stick-arm-depth {
|
|
516
|
+
0%,
|
|
517
|
+
100% {
|
|
518
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(calc(1 - 0.12 * var(--nonla-a)));
|
|
519
|
+
}
|
|
520
|
+
50% {
|
|
521
|
+
transform: rotate(var(--nonla-rest, 0deg)) scaleY(1);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
@keyframes nonla-stick-forearm-depth {
|
|
526
|
+
0%,
|
|
527
|
+
100% {
|
|
528
|
+
transform: scaleY(calc(1 - 0.28 * var(--nonla-fold)));
|
|
529
|
+
}
|
|
530
|
+
50% {
|
|
531
|
+
transform: scaleY(1);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
.nonla-body[data-motion="walk"][data-dir="down"] .nonla-stick-leg {
|
|
536
|
+
animation: nonla-stick-step-down var(--nonla-step) linear infinite;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
.nonla-body[data-motion="walk"][data-dir="up"] .nonla-stick-leg {
|
|
540
|
+
animation: nonla-stick-step-up var(--nonla-step) linear infinite;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/* Seen from the front or back the legs stay parallel: no outward splay while walking. */
|
|
544
|
+
.nonla-body[data-motion="walk"][data-dir="up"] .nonla-stick-leg-b,
|
|
545
|
+
.nonla-body[data-motion="walk"][data-dir="up"] .nonla-stick-leg-f,
|
|
546
|
+
.nonla-body[data-motion="walk"][data-dir="down"] .nonla-stick-leg-b,
|
|
547
|
+
.nonla-body[data-motion="walk"][data-dir="down"] .nonla-stick-leg-f {
|
|
548
|
+
--nonla-rest: 0deg;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
.nonla-body[data-motion="walk"][data-dir="up"] .nonla-stick-arm,
|
|
552
|
+
.nonla-body[data-motion="walk"][data-dir="down"] .nonla-stick-arm {
|
|
553
|
+
animation: nonla-stick-arm-depth var(--nonla-step) ease-in-out infinite;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/* The forearm shortens as the elbow bends toward the viewer. The shin stays straight. */
|
|
557
|
+
.nonla-body[data-motion="walk"][data-dir="up"] .nonla-stick-shin,
|
|
558
|
+
.nonla-body[data-motion="walk"][data-dir="down"] .nonla-stick-shin {
|
|
559
|
+
animation: none;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
.nonla-body[data-motion="walk"][data-dir="up"] .nonla-stick-forearm,
|
|
563
|
+
.nonla-body[data-motion="walk"][data-dir="down"] .nonla-stick-forearm {
|
|
564
|
+
animation: nonla-stick-forearm-depth var(--nonla-step) ease-in-out infinite;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/*
|
|
568
|
+
* Far leg and near leg are half a stride apart. A negative delay starts an animation midway,
|
|
569
|
+
* so both legs share one keyframe set and stay in step. An arm moves with the leg on the other side.
|
|
570
|
+
* Keep this after every `animation` shorthand above: the shorthand resets the delay.
|
|
571
|
+
*/
|
|
572
|
+
.nonla-body[data-motion="walk"][data-dir] .nonla-stick-leg-b,
|
|
573
|
+
.nonla-body[data-motion="walk"][data-dir] .nonla-stick-leg-b .nonla-stick-shin,
|
|
574
|
+
.nonla-body[data-motion="walk"][data-dir] .nonla-stick-arm-f,
|
|
575
|
+
.nonla-body[data-motion="walk"][data-dir] .nonla-stick-arm-f .nonla-stick-forearm {
|
|
576
|
+
animation-delay: calc(var(--nonla-step) * -0.5);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
@media (prefers-reduced-motion: reduce) {
|
|
580
|
+
.nonla-body[data-motion][data-dir] .nonla-stick-leg,
|
|
581
|
+
.nonla-body[data-motion][data-dir] .nonla-stick-shin,
|
|
582
|
+
.nonla-body[data-motion][data-dir] .nonla-stick-arm,
|
|
583
|
+
.nonla-body[data-motion][data-dir] .nonla-stick-forearm,
|
|
584
|
+
.nonla-body[data-motion="talk"] svg,
|
|
585
|
+
.nonla-body[data-motion="talk"] .nonla-stick-arm-f,
|
|
586
|
+
.nonla-body[data-motion="talk"] .nonla-stick-arm-f .nonla-stick-forearm,
|
|
587
|
+
.nonla-body[data-motion] .nonla-avatar-gaze,
|
|
588
|
+
.nonla-body[data-motion] .nonla-avatar-eyes,
|
|
589
|
+
.nonla-body[data-say] .nonla-body-bubble,
|
|
590
|
+
.nonla-body-bubble-caret,
|
|
591
|
+
.nonla-body-bubble-more {
|
|
592
|
+
animation: none;
|
|
593
|
+
transition: none;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
.nonla-body-bubble-caret,
|
|
597
|
+
.nonla-body-bubble-more {
|
|
598
|
+
opacity: 1;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
@@ -17,7 +17,7 @@ export type ChatWelcomeProps = {
|
|
|
17
17
|
const DEFAULT_STARTERS = ["What can you help me with?", "Brainstorm a few ideas with me", "Walk me through how you work"] as const;
|
|
18
18
|
|
|
19
19
|
function DefaultAvatar({ name }: { name: string }) {
|
|
20
|
-
return <AgentAvatar size={72} label={name} />;
|
|
20
|
+
return <AgentAvatar size={72} motion="idle" label={name} />;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function ChatWelcome({ name, description, avatar, starters = [...DEFAULT_STARTERS], onStarter, disabled, className }: ChatWelcomeProps) {
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,8 @@ export type { AlertProps, AlertType } from "./alert/Alert";
|
|
|
17
17
|
export { Alert } from "./alert/Alert";
|
|
18
18
|
export type { AgentAvatarConfig, AgentAvatarEyeColor, AgentAvatarLook, AgentAvatarMotion, AgentAvatarProps } from "./avatar/AgentAvatar";
|
|
19
19
|
export { AGENT_AVATAR_PARTS, AgentAvatar } from "./avatar/AgentAvatar";
|
|
20
|
+
export type { AgentBodyConfig, AgentBodyLook, AgentBodyMotion, AgentBodyProps } from "./avatar/AgentBody";
|
|
21
|
+
export { AGENT_BODY_PARTS, AgentBody } from "./avatar/AgentBody";
|
|
20
22
|
export type { BlobShapeAppearance, BlobShapeProps, BlobShapeVariant } from "./blob-shape/BlobShape";
|
|
21
23
|
export { BlobShape } from "./blob-shape/BlobShape";
|
|
22
24
|
export type { CalendarProps } from "./calendar/Calendar";
|
|
@@ -12,6 +12,15 @@ function useMermaidTheme(): "default" | "dark" {
|
|
|
12
12
|
return mode === "light" ? "default" : "dark";
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/** Same stack as `--nonla-font` on `.nonla-ui` (Inter Variable). Mermaid bakes this into the SVG. */
|
|
16
|
+
function mermaidFontFamily(): string {
|
|
17
|
+
const fallback = '"Inter Variable", ui-sans-serif, system-ui, sans-serif';
|
|
18
|
+
if (typeof document === "undefined") return fallback;
|
|
19
|
+
const host = document.querySelector(".nonla-ui");
|
|
20
|
+
const value = host ? getComputedStyle(host).getPropertyValue("--nonla-font").trim() : "";
|
|
21
|
+
return value || fallback;
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
/** Mermaid keeps one global theme. Render one diagram at a time so a cancelled pass cannot overwrite it. */
|
|
16
25
|
let mermaidQueue: Promise<unknown> = Promise.resolve();
|
|
17
26
|
|
|
@@ -51,9 +60,12 @@ export function MermaidBlock({ children, className }: MermaidBlockProps) {
|
|
|
51
60
|
|
|
52
61
|
await enqueueMermaid(async () => {
|
|
53
62
|
if (cancelled) return;
|
|
63
|
+
const fontFamily = mermaidFontFamily();
|
|
54
64
|
mermaid.initialize({
|
|
55
65
|
startOnLoad: false,
|
|
56
66
|
theme,
|
|
67
|
+
fontFamily,
|
|
68
|
+
themeVariables: { fontFamily },
|
|
57
69
|
});
|
|
58
70
|
|
|
59
71
|
const raw = children.trim();
|
package/src/styles.css
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
/* `text-sm`. Composer, tool lines, and errors use this. User bubbles use `text-base`. */
|
|
52
52
|
--nonla-sm-text-size: 14px;
|
|
53
53
|
/* Code. One pixel under the body, so mono does not look larger than the text around it. */
|
|
54
|
-
--nonla-mono-text-size: calc(var(--nonla-base-text-size)
|
|
54
|
+
--nonla-mono-text-size: calc(var(--nonla-base-text-size));
|
|
55
55
|
--nonla-radius: 8px;
|
|
56
56
|
--nonla-height: 32px;
|
|
57
57
|
--nonla-height-sm: 24px;
|