devnonla-ui 0.16.0 → 0.16.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 +125 -21
- package/src/avatar/avatar.css +3 -58
- package/src/styles.css +16 -16
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { createContext, type ReactNode, useContext, useId } from "react";
|
|
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` turns to a random direction. Defaults to `still`. */
|
|
5
5
|
export type AgentAvatarMotion = "still" | "idle";
|
|
6
6
|
|
|
7
|
-
/** Fixed facing. The
|
|
7
|
+
/** Fixed facing. The shape stays centered and the eyes move that way. */
|
|
8
8
|
export type AgentAvatarLook = "forward" | "left" | "right" | "up" | "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";
|
|
12
12
|
|
|
13
13
|
export const AGENT_AVATAR_PARTS = {
|
|
14
|
-
shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield"],
|
|
14
|
+
shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield", "nonla"],
|
|
15
15
|
color: ["#6E56F0", "#1C1C1C", "#F0B429", "#3DCFC0", "#F47820", "#3B82F6", "#F2549B", "#A56B3C"],
|
|
16
16
|
} as const;
|
|
17
17
|
|
|
@@ -82,19 +82,64 @@ function eyeFill(color: string, eyeColor?: AgentAvatarEyeColor) {
|
|
|
82
82
|
return eyeInk(color);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
function randomLook(current: AgentAvatarLook) {
|
|
86
|
+
const pool = LOOKS.filter((item) => item !== current);
|
|
87
|
+
return pool[Math.floor(Math.random() * pool.length)];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Idle holds one facing, then picks a different one. */
|
|
91
|
+
function useIdleLook(active: boolean, home: AgentAvatarLook, delay: number) {
|
|
92
|
+
const [glance, setGlance] = useState(home);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!active) return;
|
|
96
|
+
const media = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
97
|
+
if (media.matches) {
|
|
98
|
+
setGlance(home);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let timer = 0;
|
|
103
|
+
const arm = (wait: number) => {
|
|
104
|
+
timer = window.setTimeout(() => {
|
|
105
|
+
setGlance((current) => randomLook(current));
|
|
106
|
+
arm(1100 + Math.random() * 1700);
|
|
107
|
+
}, wait);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
setGlance(home);
|
|
111
|
+
arm(700 + delay * 1000 + Math.random() * 900);
|
|
112
|
+
|
|
113
|
+
const onChange = () => {
|
|
114
|
+
if (!media.matches) return;
|
|
115
|
+
window.clearTimeout(timer);
|
|
116
|
+
setGlance(home);
|
|
117
|
+
};
|
|
118
|
+
media.addEventListener("change", onChange);
|
|
119
|
+
return () => {
|
|
120
|
+
window.clearTimeout(timer);
|
|
121
|
+
media.removeEventListener("change", onChange);
|
|
122
|
+
};
|
|
123
|
+
}, [active, home, delay]);
|
|
124
|
+
|
|
125
|
+
return active ? glance : home;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Eye travel in viewBox units. The shape stays on the center of the box. */
|
|
129
|
+
const LOOK: Record<AgentAvatarLook, [number, number]> = {
|
|
130
|
+
forward: [0, 0],
|
|
131
|
+
left: [-6.4, 0],
|
|
132
|
+
right: [6.4, 0],
|
|
133
|
+
up: [0, -4.4],
|
|
134
|
+
down: [0, 4.4],
|
|
135
|
+
"up-left": [-4.5, -3.1],
|
|
136
|
+
"up-right": [4.5, -3.1],
|
|
137
|
+
"down-left": [-4.5, 3.1],
|
|
138
|
+
"down-right": [4.5, 3.1],
|
|
96
139
|
};
|
|
97
140
|
|
|
141
|
+
const LOOKS = Object.keys(LOOK) as AgentAvatarLook[];
|
|
142
|
+
|
|
98
143
|
function mixHex(color: string, toward: "#fff" | "#000", amount: number) {
|
|
99
144
|
const hex = color.replace("#", "");
|
|
100
145
|
const channel = (start: number) => Number.parseInt(hex.slice(start, start + 2), 16);
|
|
@@ -109,6 +154,67 @@ const PaintContext = createContext("#111");
|
|
|
109
154
|
const ShadowContext = createContext<string | undefined>(undefined);
|
|
110
155
|
const InkContext = createContext(EYE);
|
|
111
156
|
|
|
157
|
+
/** Logo mark, fitted to the avatar box. The mark stays centered. Eyes and the smile travel. */
|
|
158
|
+
const NONLA_HAT =
|
|
159
|
+
"M32.05 11.6C31.32 11.6 26.28 15.07 17.23 22.05C12.68 25.52 8.71 28.77 6.19 31.06C5.2 31.92 4.21 32.86 3.49 33.77C2.95 34.49 2.36 35.16 2.09 35.57C1.91 36.15 1.95 36.83 2 37.37A30 4.86 0 0 1 62 37.37C62.05 36.83 62.09 36.15 61.91 35.57C61.64 35.16 61.05 34.49 60.51 33.77C59.79 32.86 58.8 31.92 57.81 31.06C55.29 28.77 51.32 25.52 46.77 22.05C37.72 15.07 32.68 11.6 32.05 11.6Z";
|
|
160
|
+
|
|
161
|
+
function nonlaTones(color: string) {
|
|
162
|
+
return {
|
|
163
|
+
brim: mixHex(color, "#000", 0.3),
|
|
164
|
+
face: mixHex(color, "#fff", 0.25),
|
|
165
|
+
hat: color,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function NonlaHat({ tone }: { tone: ReturnType<typeof nonlaTones> }) {
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<path fill={tone.hat} d={NONLA_HAT} />
|
|
173
|
+
<path fill="none" stroke={tone.hat} strokeWidth="0.4" d="M2.5 37.37A29.5 4.86 0 0 1 61.5 37.37" />
|
|
174
|
+
<path fill="none" stroke={tone.brim} strokeWidth="1" d="M2.5 37.37A29.5 4.77 0 0 1 61.5 37.37" />
|
|
175
|
+
<g fill="none" stroke={tone.brim} strokeWidth="0.5" strokeLinecap="round" opacity="0.55">
|
|
176
|
+
<path d="M31.23 12.86C25.6 20.25 17.95 27.5 10.15 33.9" />
|
|
177
|
+
<path d="M31.59 12.86C28.98 19.4 26.46 25.52 23.94 31.38" />
|
|
178
|
+
<path d="M32.5 12.86C35.11 19.4 37.63 25.52 40.15 31.38" />
|
|
179
|
+
<path d="M32.86 12.86C38.49 20.25 46.14 27.5 53.94 33.9" />
|
|
180
|
+
</g>
|
|
181
|
+
</>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function NonlaMark({ color }: { color: string }) {
|
|
186
|
+
const tone = nonlaTones(color);
|
|
187
|
+
const ink = useContext(InkContext);
|
|
188
|
+
const shadow = useContext(ShadowContext);
|
|
189
|
+
const catchlight = ink === EYE_ON_DARK ? EYE : "#fff";
|
|
190
|
+
const clip = `nonla-face-${useId().replace(/:/g, "")}`;
|
|
191
|
+
return (
|
|
192
|
+
<>
|
|
193
|
+
<g filter={shadow}>
|
|
194
|
+
<ellipse cx="32" cy="37.37" rx="30" ry="8.56" fill={tone.brim} />
|
|
195
|
+
<circle cx="32.05" cy="35.66" r="16.74" fill={tone.face} />
|
|
196
|
+
<NonlaHat tone={tone} />
|
|
197
|
+
</g>
|
|
198
|
+
<clipPath id={clip}>
|
|
199
|
+
<circle cx="32.05" cy="35.66" r="16.74" />
|
|
200
|
+
</clipPath>
|
|
201
|
+
<g clipPath={`url(#${clip})`}>
|
|
202
|
+
<g className="nonla-avatar-gaze">
|
|
203
|
+
<g className="nonla-avatar-eyes">
|
|
204
|
+
<ellipse cx="24.82" cy="40.3" rx="2" ry="3.06" fill={ink} />
|
|
205
|
+
<ellipse cx="38.96" cy="40.3" rx="2" ry="3.06" fill={ink} />
|
|
206
|
+
<ellipse cx="25.29" cy="39.08" rx="0.59" ry="0.86" fill={catchlight} />
|
|
207
|
+
<ellipse cx="39.43" cy="39.08" rx="0.59" ry="0.86" fill={catchlight} />
|
|
208
|
+
</g>
|
|
209
|
+
<path fill="none" stroke={EYE} strokeWidth="1.08" strokeLinecap="round" d="M28.8 44.67C30.47 46.65 33.53 46.65 35.15 44.67" />
|
|
210
|
+
</g>
|
|
211
|
+
</g>
|
|
212
|
+
{/* Covers eyes that travel up into the cone. The smile stays below this edge. */}
|
|
213
|
+
<NonlaHat tone={tone} />
|
|
214
|
+
</>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
112
218
|
function Eyes({ cx, cy, w = 5.2, h = 12 }: { cx: number; cy: number; w?: number; h?: number }) {
|
|
113
219
|
const gap = w * 1.5;
|
|
114
220
|
const top = cy - h / 2;
|
|
@@ -162,6 +268,7 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
|
|
|
162
268
|
<Eyes cx={32} cy={34} />,
|
|
163
269
|
-6,
|
|
164
270
|
),
|
|
271
|
+
nonla: <NonlaMark color={color} />,
|
|
165
272
|
};
|
|
166
273
|
return <InkContext.Provider value={eyeFill(color, eyeColor)}>{body[shape]}</InkContext.Provider>;
|
|
167
274
|
}
|
|
@@ -169,9 +276,8 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
|
|
|
169
276
|
export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
|
|
170
277
|
const resolved = resolveConfig(config);
|
|
171
278
|
const delay = stagger(`${resolved.shape}${resolved.color}`);
|
|
172
|
-
const
|
|
173
|
-
const [
|
|
174
|
-
const [ex, ey] = facing.eyes;
|
|
279
|
+
const shown = useIdleLook(motion === "idle", look, delay);
|
|
280
|
+
const [ex, ey] = LOOK[shown];
|
|
175
281
|
const uid = useId().replace(/:/g, "");
|
|
176
282
|
const light = `nonla-av-${uid}`;
|
|
177
283
|
const shadow = `nonla-av-s-${uid}`;
|
|
@@ -181,14 +287,12 @@ export function AgentAvatar({ config, size = 64, motion = "still", look = "forwa
|
|
|
181
287
|
role="img"
|
|
182
288
|
aria-label={label}
|
|
183
289
|
data-motion={motion}
|
|
184
|
-
data-look={
|
|
290
|
+
data-look={shown}
|
|
185
291
|
className={cn("nonla-avatar", className)}
|
|
186
292
|
style={{
|
|
187
293
|
width: size,
|
|
188
294
|
height: size,
|
|
189
295
|
["--nonla-avatar-delay" as string]: `${delay}s`,
|
|
190
|
-
["--nonla-avatar-hx" as string]: `${(hx / 64) * 100}%`,
|
|
191
|
-
["--nonla-avatar-hy" as string]: `${(hy / 64) * 100}%`,
|
|
192
296
|
["--nonla-avatar-ex" as string]: `${(ex / 64) * 100}%`,
|
|
193
297
|
["--nonla-avatar-ey" as string]: `${(ey / 64) * 100}%`,
|
|
194
298
|
}}
|
package/src/avatar/avatar.css
CHANGED
|
@@ -1,51 +1,3 @@
|
|
|
1
|
-
@keyframes nonla-avatar-wander {
|
|
2
|
-
0%,
|
|
3
|
-
14%,
|
|
4
|
-
100% {
|
|
5
|
-
transform: translate(var(--nonla-avatar-hx, 0), var(--nonla-avatar-hy, 0));
|
|
6
|
-
}
|
|
7
|
-
22%,
|
|
8
|
-
34% {
|
|
9
|
-
transform: translate(-5%, 1%);
|
|
10
|
-
}
|
|
11
|
-
42%,
|
|
12
|
-
54% {
|
|
13
|
-
transform: translate(0, -4%);
|
|
14
|
-
}
|
|
15
|
-
62%,
|
|
16
|
-
74% {
|
|
17
|
-
transform: translate(5%, 1%);
|
|
18
|
-
}
|
|
19
|
-
82%,
|
|
20
|
-
94% {
|
|
21
|
-
transform: translate(0, 4.4%);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@keyframes nonla-avatar-glance {
|
|
26
|
-
0%,
|
|
27
|
-
14%,
|
|
28
|
-
100% {
|
|
29
|
-
transform: translate(var(--nonla-avatar-ex, 0), var(--nonla-avatar-ey, 0));
|
|
30
|
-
}
|
|
31
|
-
22%,
|
|
32
|
-
34% {
|
|
33
|
-
transform: translate(-10%, 0.6%);
|
|
34
|
-
}
|
|
35
|
-
42%,
|
|
36
|
-
54% {
|
|
37
|
-
transform: translate(0, -6.9%);
|
|
38
|
-
}
|
|
39
|
-
62%,
|
|
40
|
-
74% {
|
|
41
|
-
transform: translate(10%, 0.6%);
|
|
42
|
-
}
|
|
43
|
-
82%,
|
|
44
|
-
94% {
|
|
45
|
-
transform: translate(0, 7.2%);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
1
|
@keyframes nonla-avatar-blink {
|
|
50
2
|
0%,
|
|
51
3
|
46%,
|
|
@@ -58,7 +10,7 @@
|
|
|
58
10
|
}
|
|
59
11
|
}
|
|
60
12
|
|
|
61
|
-
/*
|
|
13
|
+
/* The shape stays put. Only the eyes travel. */
|
|
62
14
|
.nonla-avatar {
|
|
63
15
|
display: inline-flex;
|
|
64
16
|
flex-shrink: 0;
|
|
@@ -70,7 +22,6 @@
|
|
|
70
22
|
display: block;
|
|
71
23
|
width: 100%;
|
|
72
24
|
height: 100%;
|
|
73
|
-
transform: translate(var(--nonla-avatar-hx, 0), var(--nonla-avatar-hy, 0));
|
|
74
25
|
}
|
|
75
26
|
|
|
76
27
|
.nonla-avatar-gaze {
|
|
@@ -83,14 +34,8 @@
|
|
|
83
34
|
transform-origin: center;
|
|
84
35
|
}
|
|
85
36
|
|
|
86
|
-
.nonla-avatar[data-motion="idle"] .nonla-avatar-bob {
|
|
87
|
-
animation: nonla-avatar-wander 8.4s ease-in-out infinite;
|
|
88
|
-
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
37
|
.nonla-avatar[data-motion="idle"] .nonla-avatar-gaze {
|
|
92
|
-
|
|
93
|
-
animation-delay: var(--nonla-avatar-delay, 0s);
|
|
38
|
+
transition: transform 0.55s ease-in-out;
|
|
94
39
|
}
|
|
95
40
|
|
|
96
41
|
.nonla-avatar[data-motion="idle"] .nonla-avatar-eyes {
|
|
@@ -99,9 +44,9 @@
|
|
|
99
44
|
}
|
|
100
45
|
|
|
101
46
|
@media (prefers-reduced-motion: reduce) {
|
|
102
|
-
.nonla-avatar[data-motion] .nonla-avatar-bob,
|
|
103
47
|
.nonla-avatar[data-motion] .nonla-avatar-gaze,
|
|
104
48
|
.nonla-avatar[data-motion] .nonla-avatar-eyes {
|
|
105
49
|
animation: none;
|
|
50
|
+
transition: none;
|
|
106
51
|
}
|
|
107
52
|
}
|
package/src/styles.css
CHANGED
|
@@ -18,25 +18,25 @@
|
|
|
18
18
|
color-scheme: dark;
|
|
19
19
|
|
|
20
20
|
/* ── Config. Set these. `.light` repeats the same keys. ────────────── */
|
|
21
|
-
/*
|
|
22
|
-
--nonla-bg: #
|
|
23
|
-
--nonla-text-main: #
|
|
24
|
-
--nonla-text-secondary:
|
|
25
|
-
--nonla-text-tertiary:
|
|
26
|
-
--nonla-text-quaternary:
|
|
21
|
+
/* Claude dark (claude.com). Warm gray, hue ~60. Page 950, sidebar 900, cards 850, bar 800. */
|
|
22
|
+
--nonla-bg: #141413;
|
|
23
|
+
--nonla-text-main: #faf9f5;
|
|
24
|
+
--nonla-text-secondary: #b0aea5;
|
|
25
|
+
--nonla-text-tertiary: #87867f;
|
|
26
|
+
--nonla-text-quaternary: #73726c;
|
|
27
27
|
--nonla-text-on-solid: #ffffff;
|
|
28
28
|
--nonla-brand: #f18d00;
|
|
29
|
-
--nonla-danger: #
|
|
30
|
-
--nonla-success: #
|
|
29
|
+
--nonla-danger: #bf4d43;
|
|
30
|
+
--nonla-success: #629987; /* mineral */
|
|
31
31
|
--nonla-warn: #f1b467;
|
|
32
|
-
--nonla-link: #
|
|
33
|
-
|
|
34
|
-
--nonla-sidebar: #
|
|
35
|
-
--nonla-surface: #
|
|
36
|
-
--nonla-bar: #
|
|
37
|
-
--nonla-border:
|
|
38
|
-
--nonla-border-secondary:
|
|
39
|
-
--nonla-input:
|
|
32
|
+
--nonla-link: #6a9bcc; /* sky */
|
|
33
|
+
|
|
34
|
+
--nonla-sidebar: #1a1918;
|
|
35
|
+
--nonla-surface: #1f1e1d;
|
|
36
|
+
--nonla-bar: #262624;
|
|
37
|
+
--nonla-border: #2c2b29;
|
|
38
|
+
--nonla-border-secondary: #242322;
|
|
39
|
+
--nonla-input: rgb(250 249 245 / 14%);
|
|
40
40
|
|
|
41
41
|
--nonla-font: ui-sans-serif, -apple-system, system-ui, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
|
|
42
42
|
/* Default body size. Tailwind `text-base` follows this. Leading is 1.6. */
|