@dolfinhos/avatar 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/chunk-PPIZV2B3.js +145 -0
- package/dist/chunk-PPIZV2B3.js.map +1 -0
- package/dist/index.cjs +175 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +136 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +21 -0
- package/dist/react.d.ts +21 -0
- package/dist/react.js +18 -0
- package/dist/react.js.map +1 -0
- package/package.json +76 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dolfinsis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dolfinhos/avatar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
O rosto dos operadores do Dolfinhos em SVG: uma forma arredondada em contorno grosso, com dois olhos ovais e sem boca. Toda expressão vem dos olhos. No alto à direita o contorno se abre e ali fica o sinal, um ponto que pulsa quando o operador está trabalhando ou esperando aprovação.
|
|
4
|
+
|
|
5
|
+
- **Formas:** `square`, `tab`, `circle`, `capsule`, `egg`, `pebble`, `hexagon`, `drop`.
|
|
6
|
+
- **Cores:** as 16 de `AVATAR_COLORS`. Todas têm contraste de pelo menos 3:1 em fundo branco, inclusive no ponto mais claro do degradê.
|
|
7
|
+
- **Expressões:**
|
|
8
|
+
- `idle`: pisca de vez em quando;
|
|
9
|
+
- `thinking`;
|
|
10
|
+
- `speaking`;
|
|
11
|
+
- `working`: usando uma ferramenta (o sinal pulsa);
|
|
12
|
+
- `waiting`: esperando aprovação (o sinal pulsa);
|
|
13
|
+
- `happy`;
|
|
14
|
+
- `error`;
|
|
15
|
+
- `sleeping`: operador pausado.
|
|
16
|
+
|
|
17
|
+
Uma cor por rosto, com degradê suave. Em fundo escuro, passe `background: 'dark'` e a cor clareia. Até 24 px entra um corte pequeno: contorno fechado, sem sinal. As animações param com `prefers-reduced-motion`.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { OperatorHead } from '@dolfinhos/avatar/react';
|
|
21
|
+
import { expressionFor } from '@dolfinhos/avatar';
|
|
22
|
+
|
|
23
|
+
<OperatorHead avatar={operador.avatar} title={operador.name} expression={expressionFor(ultimoEvento?.type)} size={40} />
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Fora do React, `headSvg(avatar, { expression, size, title, animated, background })` devolve o SVG como texto (para `innerHTML`, e-mail ou favicon). A cor inválida vira o azul padrão e o título é escapado, então dá para usar dados vindos do banco.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var HEAD_SHAPES = ["square", "tab", "circle", "capsule", "egg", "pebble", "hexagon", "drop"];
|
|
3
|
+
var EXPRESSIONS = ["idle", "thinking", "speaking", "working", "waiting", "happy", "error", "sleeping"];
|
|
4
|
+
var AVATAR_COLORS = [
|
|
5
|
+
"#2563eb",
|
|
6
|
+
"#0284c7",
|
|
7
|
+
"#0f766e",
|
|
8
|
+
"#15803d",
|
|
9
|
+
"#4d7c0f",
|
|
10
|
+
"#a16207",
|
|
11
|
+
"#c2410c",
|
|
12
|
+
"#dc2626",
|
|
13
|
+
"#e11d48",
|
|
14
|
+
"#be123c",
|
|
15
|
+
"#db2777",
|
|
16
|
+
"#c026d3",
|
|
17
|
+
"#9333ea",
|
|
18
|
+
"#7c3aed",
|
|
19
|
+
"#4f46e5",
|
|
20
|
+
"#475569"
|
|
21
|
+
];
|
|
22
|
+
var COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
23
|
+
var FALLBACK_COLOR = "#2563eb";
|
|
24
|
+
var SMALL_SIZE = 24;
|
|
25
|
+
var STROKE = 30;
|
|
26
|
+
var GAP = 82;
|
|
27
|
+
var rr = (x, y, w, h, [a, b, c, d]) => `M${x + a} ${y}H${x + w - b}A${b} ${b} 0 0 1 ${x + w} ${y + b}V${y + h - c}A${c} ${c} 0 0 1 ${x + w - c} ${y + h}H${x + d}A${d} ${d} 0 0 1 ${x} ${y + h - d}V${y + a}A${a} ${a} 0 0 1 ${x + a} ${y}Z`;
|
|
28
|
+
var SHAPES = {
|
|
29
|
+
square: { d: rr(36, 44, 184, 176, [56, 56, 56, 56]), length: 623.9, offset: 153.3, signal: [200.9, 57.9], eyes: [128, 128] },
|
|
30
|
+
tab: { d: rr(26, 56, 204, 152, [84, 52, 36, 84]), length: 634.2, offset: 139.3, signal: [206.6, 64.6], eyes: [132, 128] },
|
|
31
|
+
circle: { d: "M128 34A98 98 0 1 1 128 230A98 98 0 1 1 128 34Z", length: 616, offset: 114.9, signal: [195.1, 60.5], eyes: [128, 128] },
|
|
32
|
+
capsule: { d: rr(20, 70, 216, 128, [64, 64, 64, 64]), length: 578.2, offset: 162.4, signal: [203.9, 78.5], eyes: [128, 132] },
|
|
33
|
+
egg: { d: rr(50, 30, 156, 200, [78, 78, 66, 66]), length: 588.5, offset: 111.6, signal: [189.4, 59.8], eyes: [128, 126] },
|
|
34
|
+
pebble: {
|
|
35
|
+
d: "M131 40C188 40 222 80 218 138C214 192 178 220 124 218C70 216 36 186 38 130C40 76 76 40 131 40Z",
|
|
36
|
+
length: 573.6,
|
|
37
|
+
offset: 109.8,
|
|
38
|
+
signal: [193.8, 63.5],
|
|
39
|
+
eyes: [128, 126]
|
|
40
|
+
},
|
|
41
|
+
hexagon: {
|
|
42
|
+
d: "M43.1 157.9Q28 132 43.1 106.1L62.9 71.9Q78 46 108 46L148 46Q178 46 193.1 71.9L212.9 106.1Q228 132 212.9 157.9L193.1 192.1Q178 218 148 218L108 218Q78 218 62.9 192.1Z",
|
|
43
|
+
length: 566.2,
|
|
44
|
+
offset: 273.2,
|
|
45
|
+
signal: [186.5, 62.6],
|
|
46
|
+
eyes: [128, 132]
|
|
47
|
+
},
|
|
48
|
+
drop: {
|
|
49
|
+
d: "M106.2 72.2Q128 34 149.8 72.2L210.2 177.8Q232 216 188 216L68 216Q24 216 45.8 177.8Z",
|
|
50
|
+
length: 545.4,
|
|
51
|
+
offset: 101,
|
|
52
|
+
signal: [149.6, 71.8],
|
|
53
|
+
eyes: [128, 162]
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var EYE = { rx: 16, ry: 22, gap: 32 };
|
|
57
|
+
var STYLE = `<style>
|
|
58
|
+
.dlf-eye{transform-box:fill-box;transform-origin:center}
|
|
59
|
+
.dlf-idle .dlf-eye{animation:dlf-blink 5s infinite}
|
|
60
|
+
.dlf-speaking .dlf-eye{animation:dlf-talk .32s ease-in-out infinite alternate}
|
|
61
|
+
.dlf-thinking .dlf-eyes{animation:dlf-float 2.4s ease-in-out infinite alternate}
|
|
62
|
+
.dlf-working .dlf-eyes{animation:dlf-scan 1.6s ease-in-out infinite alternate}
|
|
63
|
+
.dlf-waiting .dlf-eyes{animation:dlf-look 2.8s ease-in-out infinite}
|
|
64
|
+
.dlf-working .dlf-signal,.dlf-waiting .dlf-signal{animation:dlf-pulse 1.2s ease-in-out infinite alternate}
|
|
65
|
+
@keyframes dlf-blink{0%,92%,100%{transform:scaleY(1)}95%{transform:scaleY(.1)}}
|
|
66
|
+
@keyframes dlf-talk{to{transform:scaleY(.75)}}
|
|
67
|
+
@keyframes dlf-float{to{transform:translateY(-5px)}}
|
|
68
|
+
@keyframes dlf-scan{from{transform:translateX(-7px)}to{transform:translateX(7px)}}
|
|
69
|
+
@keyframes dlf-look{0%,100%{transform:none}30%{transform:translateX(-10px)}70%{transform:translateX(10px)}}
|
|
70
|
+
@keyframes dlf-pulse{to{opacity:.3}}
|
|
71
|
+
@media (prefers-reduced-motion:reduce){.dlf-eye,.dlf-eyes,.dlf-signal{animation:none!important}}
|
|
72
|
+
</style>`;
|
|
73
|
+
var mix = (hex, to, k) => "#" + [1, 3, 5].map((i) => Math.round(parseInt(hex.slice(i, i + 2), 16) * (1 - k) + to * k).toString(16).padStart(2, "0")).join("");
|
|
74
|
+
function headColor(spec) {
|
|
75
|
+
return COLOR.test(spec.color) ? spec.color.toLowerCase() : FALLBACK_COLOR;
|
|
76
|
+
}
|
|
77
|
+
function eyes(expression, ink, [cx, cy]) {
|
|
78
|
+
const line = (d) => `<path d="${d}" fill="none" stroke="${ink}" stroke-width="12" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
79
|
+
const one = (x) => {
|
|
80
|
+
switch (expression) {
|
|
81
|
+
case "happy":
|
|
82
|
+
return line(`M${x - 15} ${cy + 7}Q${x} ${cy - 15} ${x + 15} ${cy + 7}`);
|
|
83
|
+
case "error":
|
|
84
|
+
return line(`M${x - 11} ${cy - 11}L${x + 11} ${cy + 11}M${x + 11} ${cy - 11}L${x - 11} ${cy + 11}`);
|
|
85
|
+
case "sleeping":
|
|
86
|
+
return line(`M${x - 15} ${cy + 3}Q${x} ${cy + 13} ${x + 15} ${cy + 3}`);
|
|
87
|
+
case "thinking":
|
|
88
|
+
return `<ellipse class="dlf-eye" cx="${x + 7}" cy="${cy - 9}" rx="${EYE.rx * 0.85}" ry="${EYE.ry * 0.85}" fill="${ink}"/>`;
|
|
89
|
+
case "working":
|
|
90
|
+
return `<ellipse class="dlf-eye" cx="${x}" cy="${cy + 5}" rx="${EYE.rx + 2}" ry="${EYE.ry / 2}" fill="${ink}"/>`;
|
|
91
|
+
default:
|
|
92
|
+
return `<ellipse class="dlf-eye" cx="${x}" cy="${cy}" rx="${EYE.rx}" ry="${EYE.ry}" fill="${ink}"/>`;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return `<g class="dlf-eyes">${one(cx - EYE.gap)}${one(cx + EYE.gap)}</g>`;
|
|
96
|
+
}
|
|
97
|
+
var escapeXml = (text) => text.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
98
|
+
function headSvg(spec, options = {}) {
|
|
99
|
+
const expression = options.expression ?? "idle";
|
|
100
|
+
const animated = options.animated !== false;
|
|
101
|
+
const size = options.size ?? 64;
|
|
102
|
+
const base = headColor(spec);
|
|
103
|
+
const color = options.background === "dark" ? mix(base, 255, 0.35) : base;
|
|
104
|
+
const shape = SHAPES[spec.shape] ?? SHAPES.square;
|
|
105
|
+
const small = size <= SMALL_SIZE;
|
|
106
|
+
const id = `dlf-g${color.slice(1)}`;
|
|
107
|
+
const ink = `url(#${id})`;
|
|
108
|
+
const gradient = `<defs><linearGradient id="${id}" gradientUnits="userSpaceOnUse" x1="24" y1="24" x2="232" y2="232"><stop offset="0" stop-color="${mix(color, 255, 0.16)}"/><stop offset="1" stop-color="${mix(color, 0, 0.06)}"/></linearGradient></defs>`;
|
|
109
|
+
const gap = small ? "" : ` stroke-dasharray="${(shape.length - GAP).toFixed(1)} ${GAP}" stroke-dashoffset="${-shape.offset}"`;
|
|
110
|
+
const outline = `<path d="${shape.d}" fill="none" stroke="${ink}" stroke-width="${STROKE}" stroke-linecap="round" stroke-linejoin="round"${gap}/>`;
|
|
111
|
+
const signal = small ? "" : `<circle class="dlf-signal" cx="${shape.signal[0]}" cy="${shape.signal[1]}" r="15" fill="${ink}"/>`;
|
|
112
|
+
const a11y = options.title ? `role="img" aria-label="${escapeXml(options.title)}"` : 'aria-hidden="true"';
|
|
113
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="${size}" height="${size}" ${a11y} class="dlf-head${animated ? ` dlf-${expression}` : ""}">` + (animated ? STYLE : "") + (options.title ? `<title>${escapeXml(options.title)}</title>` : "") + gradient + outline + signal + eyes(expression, ink, shape.eyes) + "</svg>";
|
|
114
|
+
}
|
|
115
|
+
function expressionFor(eventType, status) {
|
|
116
|
+
switch (eventType) {
|
|
117
|
+
case "run.started":
|
|
118
|
+
return "thinking";
|
|
119
|
+
case "text.delta":
|
|
120
|
+
return "speaking";
|
|
121
|
+
case "tool.calling":
|
|
122
|
+
return "working";
|
|
123
|
+
case "tool.approval_required":
|
|
124
|
+
return "waiting";
|
|
125
|
+
case "tool.result":
|
|
126
|
+
return status === "error" ? "error" : "thinking";
|
|
127
|
+
case "run.completed":
|
|
128
|
+
return status === "awaiting_approval" ? "waiting" : "happy";
|
|
129
|
+
case "run.error":
|
|
130
|
+
return "error";
|
|
131
|
+
default:
|
|
132
|
+
return "idle";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
HEAD_SHAPES,
|
|
138
|
+
EXPRESSIONS,
|
|
139
|
+
AVATAR_COLORS,
|
|
140
|
+
SMALL_SIZE,
|
|
141
|
+
headColor,
|
|
142
|
+
headSvg,
|
|
143
|
+
expressionFor
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=chunk-PPIZV2B3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Rostos dos operadores: uma forma arredondada em contorno grosso, com dois\n * olhos ovais e uma abertura no alto à direita onde fica o sinal (o ponto que\n * pulsa quando o operador trabalha ou espera aprovação). Uma cor só, com\n * degradê suave, numa tela 256.\n *\n * Mesmo formato do `AvatarSpec` do `@dolfinhos/core`, sem depender dele: o\n * frontend instala só este pacote.\n */\n\nexport type HeadShape = 'square' | 'tab' | 'circle' | 'capsule' | 'egg' | 'pebble' | 'hexagon' | 'drop';\n\nexport interface AvatarSpec {\n shape: HeadShape;\n /** Cor do rosto, `#rrggbb`. Use uma de `AVATAR_COLORS` (contrastam com fundo branco). */\n color: string;\n}\n\n/**\n * - `idle`: parado, pisca de vez em quando\n * - `thinking`: olhos para cima, de lado\n * - `speaking`: olhos pulsam enquanto o texto chega\n * - `working`: olhos estreitos, varrendo (usando uma ferramenta); o sinal pulsa\n * - `waiting`: olha de um lado para o outro (esperando aprovação); o sinal pulsa\n * - `happy`: olhos em arco (terminou)\n * - `error`: olhos em ×\n * - `sleeping`: olhos fechados (operador pausado)\n */\nexport type Expression = 'idle' | 'thinking' | 'speaking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';\n\nexport const HEAD_SHAPES: readonly HeadShape[] = ['square', 'tab', 'circle', 'capsule', 'egg', 'pebble', 'hexagon', 'drop'];\nexport const EXPRESSIONS: readonly Expression[] = ['idle', 'thinking', 'speaking', 'working', 'waiting', 'happy', 'error', 'sleeping'];\n/** Cores da família: todas com contraste de pelo menos 3:1 em fundo branco, inclusive no ponto mais claro do degradê. */\nexport const AVATAR_COLORS: readonly string[] = [\n '#2563eb', '#0284c7', '#0f766e', '#15803d', '#4d7c0f', '#a16207', '#c2410c', '#dc2626',\n '#e11d48', '#be123c', '#db2777', '#c026d3', '#9333ea', '#7c3aed', '#4f46e5', '#475569',\n];\n\nconst COLOR = /^#[0-9a-fA-F]{6}$/;\nconst FALLBACK_COLOR = '#2563eb';\n\n/** Até este tamanho (px) vale o corte pequeno: contorno fechado, sem sinal (detalhes que viram ruído). */\nexport const SMALL_SIZE = 24;\n\nconst STROKE = 30;\n/** Comprimento da abertura no contorno (já contando as pontas redondas da linha). */\nconst GAP = 82;\n\nconst rr = (x: number, y: number, w: number, h: number, [a, b, c, d]: [number, number, number, number]) =>\n `M${x + a} ${y}H${x + w - b}A${b} ${b} 0 0 1 ${x + w} ${y + b}V${y + h - c}A${c} ${c} 0 0 1 ${x + w - c} ${y + h}H${x + d}A${d} ${d} 0 0 1 ${x} ${y + h - d}V${y + a}A${a} ${a} 0 0 1 ${x + a} ${y}Z`;\n\n/**\n * Cada forma: contorno, comprimento dele, onde começa a abertura (deslocamento\n * do traço), onde fica o sinal e o centro dos olhos (um pouco acima do centro:\n * o centro óptico). Comprimentos medidos no navegador (`getTotalLength`).\n */\nconst SHAPES: Record<HeadShape, { d: string; length: number; offset: number; signal: [number, number]; eyes: [number, number] }> = {\n square: { d: rr(36, 44, 184, 176, [56, 56, 56, 56]), length: 623.9, offset: 153.3, signal: [200.9, 57.9], eyes: [128, 128] },\n tab: { d: rr(26, 56, 204, 152, [84, 52, 36, 84]), length: 634.2, offset: 139.3, signal: [206.6, 64.6], eyes: [132, 128] },\n circle: { d: 'M128 34A98 98 0 1 1 128 230A98 98 0 1 1 128 34Z', length: 616, offset: 114.9, signal: [195.1, 60.5], eyes: [128, 128] },\n capsule: { d: rr(20, 70, 216, 128, [64, 64, 64, 64]), length: 578.2, offset: 162.4, signal: [203.9, 78.5], eyes: [128, 132] },\n egg: { d: rr(50, 30, 156, 200, [78, 78, 66, 66]), length: 588.5, offset: 111.6, signal: [189.4, 59.8], eyes: [128, 126] },\n pebble: {\n d: 'M131 40C188 40 222 80 218 138C214 192 178 220 124 218C70 216 36 186 38 130C40 76 76 40 131 40Z',\n length: 573.6,\n offset: 109.8,\n signal: [193.8, 63.5],\n eyes: [128, 126],\n },\n hexagon: {\n d: 'M43.1 157.9Q28 132 43.1 106.1L62.9 71.9Q78 46 108 46L148 46Q178 46 193.1 71.9L212.9 106.1Q228 132 212.9 157.9L193.1 192.1Q178 218 148 218L108 218Q78 218 62.9 192.1Z',\n length: 566.2,\n offset: 273.2,\n signal: [186.5, 62.6],\n eyes: [128, 132],\n },\n drop: {\n d: 'M106.2 72.2Q128 34 149.8 72.2L210.2 177.8Q232 216 188 216L68 216Q24 216 45.8 177.8Z',\n length: 545.4,\n offset: 101,\n signal: [149.6, 71.8],\n eyes: [128, 162],\n },\n};\n\nconst EYE = { rx: 16, ry: 22, gap: 32 };\n\n/** Animação de cada expressão; todas param com `prefers-reduced-motion`. */\nconst STYLE = `<style>\n.dlf-eye{transform-box:fill-box;transform-origin:center}\n.dlf-idle .dlf-eye{animation:dlf-blink 5s infinite}\n.dlf-speaking .dlf-eye{animation:dlf-talk .32s ease-in-out infinite alternate}\n.dlf-thinking .dlf-eyes{animation:dlf-float 2.4s ease-in-out infinite alternate}\n.dlf-working .dlf-eyes{animation:dlf-scan 1.6s ease-in-out infinite alternate}\n.dlf-waiting .dlf-eyes{animation:dlf-look 2.8s ease-in-out infinite}\n.dlf-working .dlf-signal,.dlf-waiting .dlf-signal{animation:dlf-pulse 1.2s ease-in-out infinite alternate}\n@keyframes dlf-blink{0%,92%,100%{transform:scaleY(1)}95%{transform:scaleY(.1)}}\n@keyframes dlf-talk{to{transform:scaleY(.75)}}\n@keyframes dlf-float{to{transform:translateY(-5px)}}\n@keyframes dlf-scan{from{transform:translateX(-7px)}to{transform:translateX(7px)}}\n@keyframes dlf-look{0%,100%{transform:none}30%{transform:translateX(-10px)}70%{transform:translateX(10px)}}\n@keyframes dlf-pulse{to{opacity:.3}}\n@media (prefers-reduced-motion:reduce){.dlf-eye,.dlf-eyes,.dlf-signal{animation:none!important}}\n</style>`;\n\nconst mix = (hex: string, to: number, k: number) =>\n '#' + [1, 3, 5].map((i) => Math.round(parseInt(hex.slice(i, i + 2), 16) * (1 - k) + to * k).toString(16).padStart(2, '0')).join('');\n\n/** Cor válida do rosto (cor inválida vira o azul padrão: o valor vem do banco). */\nexport function headColor(spec: Pick<AvatarSpec, 'color'>) {\n return COLOR.test(spec.color) ? spec.color.toLowerCase() : FALLBACK_COLOR;\n}\n\nfunction eyes(expression: Expression, ink: string, [cx, cy]: [number, number]) {\n const line = (d: string) => `<path d=\"${d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"12\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n const one = (x: number) => {\n switch (expression) {\n case 'happy':\n return line(`M${x - 15} ${cy + 7}Q${x} ${cy - 15} ${x + 15} ${cy + 7}`);\n case 'error':\n return line(`M${x - 11} ${cy - 11}L${x + 11} ${cy + 11}M${x + 11} ${cy - 11}L${x - 11} ${cy + 11}`);\n case 'sleeping':\n return line(`M${x - 15} ${cy + 3}Q${x} ${cy + 13} ${x + 15} ${cy + 3}`);\n case 'thinking':\n return `<ellipse class=\"dlf-eye\" cx=\"${x + 7}\" cy=\"${cy - 9}\" rx=\"${EYE.rx * 0.85}\" ry=\"${EYE.ry * 0.85}\" fill=\"${ink}\"/>`;\n case 'working':\n return `<ellipse class=\"dlf-eye\" cx=\"${x}\" cy=\"${cy + 5}\" rx=\"${EYE.rx + 2}\" ry=\"${EYE.ry / 2}\" fill=\"${ink}\"/>`;\n default:\n return `<ellipse class=\"dlf-eye\" cx=\"${x}\" cy=\"${cy}\" rx=\"${EYE.rx}\" ry=\"${EYE.ry}\" fill=\"${ink}\"/>`;\n }\n };\n return `<g class=\"dlf-eyes\">${one(cx - EYE.gap)}${one(cx + EYE.gap)}</g>`;\n}\n\nconst escapeXml = (text: string) => text.replace(/[<>&\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n\nexport interface HeadSvgOptions {\n expression?: Expression;\n /** Largura e altura em px. Padrão: 64. */\n size?: number;\n /** Texto para leitores de tela (o nome do operador). Sem ele, o SVG fica decorativo. */\n title?: string;\n /** Inclui as animações. Padrão: sim. */\n animated?: boolean;\n /** Fundo onde o rosto aparece. Em `dark` a cor clareia para continuar visível. Padrão: `light`. */\n background?: 'light' | 'dark';\n}\n\n/** O rosto como texto SVG (para `innerHTML`, e-mail, favicon ou servidor). */\nexport function headSvg(spec: AvatarSpec, options: HeadSvgOptions = {}): string {\n const expression = options.expression ?? 'idle';\n // Sem a classe da expressão, o CSS de outro rosto animado na página não pega este.\n const animated = options.animated !== false;\n const size = options.size ?? 64;\n const base = headColor(spec);\n const color = options.background === 'dark' ? mix(base, 255, 0.35) : base;\n const shape = SHAPES[spec.shape] ?? SHAPES.square;\n const small = size <= SMALL_SIZE;\n\n // O id depende só da cor: rostos iguais na página compartilham o mesmo degradê, sem conflito.\n const id = `dlf-g${color.slice(1)}`;\n const ink = `url(#${id})`;\n const gradient = `<defs><linearGradient id=\"${id}\" gradientUnits=\"userSpaceOnUse\" x1=\"24\" y1=\"24\" x2=\"232\" y2=\"232\"><stop offset=\"0\" stop-color=\"${mix(color, 255, 0.16)}\"/><stop offset=\"1\" stop-color=\"${mix(color, 0, 0.06)}\"/></linearGradient></defs>`;\n const gap = small ? '' : ` stroke-dasharray=\"${(shape.length - GAP).toFixed(1)} ${GAP}\" stroke-dashoffset=\"${-shape.offset}\"`;\n const outline = `<path d=\"${shape.d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"${STROKE}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"${gap}/>`;\n const signal = small ? '' : `<circle class=\"dlf-signal\" cx=\"${shape.signal[0]}\" cy=\"${shape.signal[1]}\" r=\"15\" fill=\"${ink}\"/>`;\n\n const a11y = options.title ? `role=\"img\" aria-label=\"${escapeXml(options.title)}\"` : 'aria-hidden=\"true\"';\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" width=\"${size}\" height=\"${size}\" ${a11y} class=\"dlf-head${animated ? ` dlf-${expression}` : ''}\">` +\n (animated ? STYLE : '') +\n (options.title ? `<title>${escapeXml(options.title)}</title>` : '') +\n gradient +\n outline +\n signal +\n eyes(expression, ink, shape.eyes) +\n '</svg>'\n );\n}\n\n/** Expressão a partir dos eventos SSE do painel (`type` de cada `DolfinhosEvent`). */\nexport function expressionFor(eventType: string | undefined, status?: string): Expression {\n switch (eventType) {\n case 'run.started':\n return 'thinking';\n case 'text.delta':\n return 'speaking';\n case 'tool.calling':\n return 'working';\n case 'tool.approval_required':\n return 'waiting';\n case 'tool.result':\n return status === 'error' ? 'error' : 'thinking';\n case 'run.completed':\n return status === 'awaiting_approval' ? 'waiting' : 'happy';\n case 'run.error':\n return 'error';\n default:\n return 'idle';\n }\n}\n"],"mappings":";AA8BO,IAAM,cAAoC,CAAC,UAAU,OAAO,UAAU,WAAW,OAAO,UAAU,WAAW,MAAM;AACnH,IAAM,cAAqC,CAAC,QAAQ,YAAY,YAAY,WAAW,WAAW,SAAS,SAAS,UAAU;AAE9H,IAAM,gBAAmC;AAAA,EAC9C;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAC7E;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAAA,EAAW;AAC/E;AAEA,IAAM,QAAQ;AACd,IAAM,iBAAiB;AAGhB,IAAM,aAAa;AAE1B,IAAM,SAAS;AAEf,IAAM,MAAM;AAEZ,IAAM,KAAK,CAAC,GAAW,GAAW,GAAW,GAAW,CAAC,GAAG,GAAG,GAAG,CAAC,MACjE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAA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ACtB,QAAM,WAAW,6BAA6B,EAAE,mGAAmG,IAAI,OAAO,KAAK,IAAI,CAAC,mCAAmC,IAAI,OAAO,GAAG,IAAI,CAAC;AAC9N,QAAM,MAAM,QAAQ,KAAK,uBAAuB,MAAM,SAAS,KAAK,QAAQ,CAAC,CAAC,IAAI,GAAG,wBAAwB,CAAC,MAAM,MAAM;AAC1H,QAAM,UAAU,YAAY,MAAM,CAAC,yBAAyB,GAAG,mBAAmB,MAAM,mDAAmD,GAAG;AAC9I,QAAM,SAAS,QAAQ,KAAK,kCAAkC,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,OAAO,CAAC,CAAC,kBAAkB,GAAG;AAE1H,QAAM,OAAO,QAAQ,QAAQ,0BAA0B,UAAU,QAAQ,KAAK,CAAC,MAAM;AACrF,SACE,wEAAwE,IAAI,aAAa,IAAI,KAAK,IAAI,mBAAmB,WAAW,QAAQ,UAAU,KAAK,EAAE,QAC5J,WAAW,QAAQ,OACnB,QAAQ,QAAQ,UAAU,UAAU,QAAQ,KAAK,CAAC,aAAa,MAChE,WACA,UACA,SACA,KAAK,YAAY,KAAK,MAAM,IAAI,IAChC;AAEJ;AAGO,SAAS,cAAc,WAA+B,QAA6B;AACxF,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,WAAW,UAAU,UAAU;AAAA,IACxC,KAAK;AACH,aAAO,WAAW,sBAAsB,YAAY;AAAA,IACtD,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AVATAR_COLORS: () => AVATAR_COLORS,
|
|
24
|
+
EXPRESSIONS: () => EXPRESSIONS,
|
|
25
|
+
HEAD_SHAPES: () => HEAD_SHAPES,
|
|
26
|
+
SMALL_SIZE: () => SMALL_SIZE,
|
|
27
|
+
expressionFor: () => expressionFor,
|
|
28
|
+
headColor: () => headColor,
|
|
29
|
+
headSvg: () => headSvg
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var HEAD_SHAPES = ["square", "tab", "circle", "capsule", "egg", "pebble", "hexagon", "drop"];
|
|
33
|
+
var EXPRESSIONS = ["idle", "thinking", "speaking", "working", "waiting", "happy", "error", "sleeping"];
|
|
34
|
+
var AVATAR_COLORS = [
|
|
35
|
+
"#2563eb",
|
|
36
|
+
"#0284c7",
|
|
37
|
+
"#0f766e",
|
|
38
|
+
"#15803d",
|
|
39
|
+
"#4d7c0f",
|
|
40
|
+
"#a16207",
|
|
41
|
+
"#c2410c",
|
|
42
|
+
"#dc2626",
|
|
43
|
+
"#e11d48",
|
|
44
|
+
"#be123c",
|
|
45
|
+
"#db2777",
|
|
46
|
+
"#c026d3",
|
|
47
|
+
"#9333ea",
|
|
48
|
+
"#7c3aed",
|
|
49
|
+
"#4f46e5",
|
|
50
|
+
"#475569"
|
|
51
|
+
];
|
|
52
|
+
var COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
53
|
+
var FALLBACK_COLOR = "#2563eb";
|
|
54
|
+
var SMALL_SIZE = 24;
|
|
55
|
+
var STROKE = 30;
|
|
56
|
+
var GAP = 82;
|
|
57
|
+
var rr = (x, y, w, h, [a, b, c, d]) => `M${x + a} ${y}H${x + w - b}A${b} ${b} 0 0 1 ${x + w} ${y + b}V${y + h - c}A${c} ${c} 0 0 1 ${x + w - c} ${y + h}H${x + d}A${d} ${d} 0 0 1 ${x} ${y + h - d}V${y + a}A${a} ${a} 0 0 1 ${x + a} ${y}Z`;
|
|
58
|
+
var SHAPES = {
|
|
59
|
+
square: { d: rr(36, 44, 184, 176, [56, 56, 56, 56]), length: 623.9, offset: 153.3, signal: [200.9, 57.9], eyes: [128, 128] },
|
|
60
|
+
tab: { d: rr(26, 56, 204, 152, [84, 52, 36, 84]), length: 634.2, offset: 139.3, signal: [206.6, 64.6], eyes: [132, 128] },
|
|
61
|
+
circle: { d: "M128 34A98 98 0 1 1 128 230A98 98 0 1 1 128 34Z", length: 616, offset: 114.9, signal: [195.1, 60.5], eyes: [128, 128] },
|
|
62
|
+
capsule: { d: rr(20, 70, 216, 128, [64, 64, 64, 64]), length: 578.2, offset: 162.4, signal: [203.9, 78.5], eyes: [128, 132] },
|
|
63
|
+
egg: { d: rr(50, 30, 156, 200, [78, 78, 66, 66]), length: 588.5, offset: 111.6, signal: [189.4, 59.8], eyes: [128, 126] },
|
|
64
|
+
pebble: {
|
|
65
|
+
d: "M131 40C188 40 222 80 218 138C214 192 178 220 124 218C70 216 36 186 38 130C40 76 76 40 131 40Z",
|
|
66
|
+
length: 573.6,
|
|
67
|
+
offset: 109.8,
|
|
68
|
+
signal: [193.8, 63.5],
|
|
69
|
+
eyes: [128, 126]
|
|
70
|
+
},
|
|
71
|
+
hexagon: {
|
|
72
|
+
d: "M43.1 157.9Q28 132 43.1 106.1L62.9 71.9Q78 46 108 46L148 46Q178 46 193.1 71.9L212.9 106.1Q228 132 212.9 157.9L193.1 192.1Q178 218 148 218L108 218Q78 218 62.9 192.1Z",
|
|
73
|
+
length: 566.2,
|
|
74
|
+
offset: 273.2,
|
|
75
|
+
signal: [186.5, 62.6],
|
|
76
|
+
eyes: [128, 132]
|
|
77
|
+
},
|
|
78
|
+
drop: {
|
|
79
|
+
d: "M106.2 72.2Q128 34 149.8 72.2L210.2 177.8Q232 216 188 216L68 216Q24 216 45.8 177.8Z",
|
|
80
|
+
length: 545.4,
|
|
81
|
+
offset: 101,
|
|
82
|
+
signal: [149.6, 71.8],
|
|
83
|
+
eyes: [128, 162]
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var EYE = { rx: 16, ry: 22, gap: 32 };
|
|
87
|
+
var STYLE = `<style>
|
|
88
|
+
.dlf-eye{transform-box:fill-box;transform-origin:center}
|
|
89
|
+
.dlf-idle .dlf-eye{animation:dlf-blink 5s infinite}
|
|
90
|
+
.dlf-speaking .dlf-eye{animation:dlf-talk .32s ease-in-out infinite alternate}
|
|
91
|
+
.dlf-thinking .dlf-eyes{animation:dlf-float 2.4s ease-in-out infinite alternate}
|
|
92
|
+
.dlf-working .dlf-eyes{animation:dlf-scan 1.6s ease-in-out infinite alternate}
|
|
93
|
+
.dlf-waiting .dlf-eyes{animation:dlf-look 2.8s ease-in-out infinite}
|
|
94
|
+
.dlf-working .dlf-signal,.dlf-waiting .dlf-signal{animation:dlf-pulse 1.2s ease-in-out infinite alternate}
|
|
95
|
+
@keyframes dlf-blink{0%,92%,100%{transform:scaleY(1)}95%{transform:scaleY(.1)}}
|
|
96
|
+
@keyframes dlf-talk{to{transform:scaleY(.75)}}
|
|
97
|
+
@keyframes dlf-float{to{transform:translateY(-5px)}}
|
|
98
|
+
@keyframes dlf-scan{from{transform:translateX(-7px)}to{transform:translateX(7px)}}
|
|
99
|
+
@keyframes dlf-look{0%,100%{transform:none}30%{transform:translateX(-10px)}70%{transform:translateX(10px)}}
|
|
100
|
+
@keyframes dlf-pulse{to{opacity:.3}}
|
|
101
|
+
@media (prefers-reduced-motion:reduce){.dlf-eye,.dlf-eyes,.dlf-signal{animation:none!important}}
|
|
102
|
+
</style>`;
|
|
103
|
+
var mix = (hex, to, k) => "#" + [1, 3, 5].map((i) => Math.round(parseInt(hex.slice(i, i + 2), 16) * (1 - k) + to * k).toString(16).padStart(2, "0")).join("");
|
|
104
|
+
function headColor(spec) {
|
|
105
|
+
return COLOR.test(spec.color) ? spec.color.toLowerCase() : FALLBACK_COLOR;
|
|
106
|
+
}
|
|
107
|
+
function eyes(expression, ink, [cx, cy]) {
|
|
108
|
+
const line = (d) => `<path d="${d}" fill="none" stroke="${ink}" stroke-width="12" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
109
|
+
const one = (x) => {
|
|
110
|
+
switch (expression) {
|
|
111
|
+
case "happy":
|
|
112
|
+
return line(`M${x - 15} ${cy + 7}Q${x} ${cy - 15} ${x + 15} ${cy + 7}`);
|
|
113
|
+
case "error":
|
|
114
|
+
return line(`M${x - 11} ${cy - 11}L${x + 11} ${cy + 11}M${x + 11} ${cy - 11}L${x - 11} ${cy + 11}`);
|
|
115
|
+
case "sleeping":
|
|
116
|
+
return line(`M${x - 15} ${cy + 3}Q${x} ${cy + 13} ${x + 15} ${cy + 3}`);
|
|
117
|
+
case "thinking":
|
|
118
|
+
return `<ellipse class="dlf-eye" cx="${x + 7}" cy="${cy - 9}" rx="${EYE.rx * 0.85}" ry="${EYE.ry * 0.85}" fill="${ink}"/>`;
|
|
119
|
+
case "working":
|
|
120
|
+
return `<ellipse class="dlf-eye" cx="${x}" cy="${cy + 5}" rx="${EYE.rx + 2}" ry="${EYE.ry / 2}" fill="${ink}"/>`;
|
|
121
|
+
default:
|
|
122
|
+
return `<ellipse class="dlf-eye" cx="${x}" cy="${cy}" rx="${EYE.rx}" ry="${EYE.ry}" fill="${ink}"/>`;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return `<g class="dlf-eyes">${one(cx - EYE.gap)}${one(cx + EYE.gap)}</g>`;
|
|
126
|
+
}
|
|
127
|
+
var escapeXml = (text) => text.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
128
|
+
function headSvg(spec, options = {}) {
|
|
129
|
+
const expression = options.expression ?? "idle";
|
|
130
|
+
const animated = options.animated !== false;
|
|
131
|
+
const size = options.size ?? 64;
|
|
132
|
+
const base = headColor(spec);
|
|
133
|
+
const color = options.background === "dark" ? mix(base, 255, 0.35) : base;
|
|
134
|
+
const shape = SHAPES[spec.shape] ?? SHAPES.square;
|
|
135
|
+
const small = size <= SMALL_SIZE;
|
|
136
|
+
const id = `dlf-g${color.slice(1)}`;
|
|
137
|
+
const ink = `url(#${id})`;
|
|
138
|
+
const gradient = `<defs><linearGradient id="${id}" gradientUnits="userSpaceOnUse" x1="24" y1="24" x2="232" y2="232"><stop offset="0" stop-color="${mix(color, 255, 0.16)}"/><stop offset="1" stop-color="${mix(color, 0, 0.06)}"/></linearGradient></defs>`;
|
|
139
|
+
const gap = small ? "" : ` stroke-dasharray="${(shape.length - GAP).toFixed(1)} ${GAP}" stroke-dashoffset="${-shape.offset}"`;
|
|
140
|
+
const outline = `<path d="${shape.d}" fill="none" stroke="${ink}" stroke-width="${STROKE}" stroke-linecap="round" stroke-linejoin="round"${gap}/>`;
|
|
141
|
+
const signal = small ? "" : `<circle class="dlf-signal" cx="${shape.signal[0]}" cy="${shape.signal[1]}" r="15" fill="${ink}"/>`;
|
|
142
|
+
const a11y = options.title ? `role="img" aria-label="${escapeXml(options.title)}"` : 'aria-hidden="true"';
|
|
143
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="${size}" height="${size}" ${a11y} class="dlf-head${animated ? ` dlf-${expression}` : ""}">` + (animated ? STYLE : "") + (options.title ? `<title>${escapeXml(options.title)}</title>` : "") + gradient + outline + signal + eyes(expression, ink, shape.eyes) + "</svg>";
|
|
144
|
+
}
|
|
145
|
+
function expressionFor(eventType, status) {
|
|
146
|
+
switch (eventType) {
|
|
147
|
+
case "run.started":
|
|
148
|
+
return "thinking";
|
|
149
|
+
case "text.delta":
|
|
150
|
+
return "speaking";
|
|
151
|
+
case "tool.calling":
|
|
152
|
+
return "working";
|
|
153
|
+
case "tool.approval_required":
|
|
154
|
+
return "waiting";
|
|
155
|
+
case "tool.result":
|
|
156
|
+
return status === "error" ? "error" : "thinking";
|
|
157
|
+
case "run.completed":
|
|
158
|
+
return status === "awaiting_approval" ? "waiting" : "happy";
|
|
159
|
+
case "run.error":
|
|
160
|
+
return "error";
|
|
161
|
+
default:
|
|
162
|
+
return "idle";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
AVATAR_COLORS,
|
|
168
|
+
EXPRESSIONS,
|
|
169
|
+
HEAD_SHAPES,
|
|
170
|
+
SMALL_SIZE,
|
|
171
|
+
expressionFor,
|
|
172
|
+
headColor,
|
|
173
|
+
headSvg
|
|
174
|
+
});
|
|
175
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Rostos dos operadores: uma forma arredondada em contorno grosso, com dois\n * olhos ovais e uma abertura no alto à direita onde fica o sinal (o ponto que\n * pulsa quando o operador trabalha ou espera aprovação). Uma cor só, com\n * degradê suave, numa tela 256.\n *\n * Mesmo formato do `AvatarSpec` do `@dolfinhos/core`, sem depender dele: o\n * frontend instala só este pacote.\n */\n\nexport type HeadShape = 'square' | 'tab' | 'circle' | 'capsule' | 'egg' | 'pebble' | 'hexagon' | 'drop';\n\nexport interface AvatarSpec {\n shape: HeadShape;\n /** Cor do rosto, `#rrggbb`. Use uma de `AVATAR_COLORS` (contrastam com fundo branco). */\n color: string;\n}\n\n/**\n * - `idle`: parado, pisca de vez em quando\n * - `thinking`: olhos para cima, de lado\n * - `speaking`: olhos pulsam enquanto o texto chega\n * - `working`: olhos estreitos, varrendo (usando uma ferramenta); o sinal pulsa\n * - `waiting`: olha de um lado para o outro (esperando aprovação); o sinal pulsa\n * - `happy`: olhos em arco (terminou)\n * - `error`: olhos em ×\n * - `sleeping`: olhos fechados (operador pausado)\n */\nexport type Expression = 'idle' | 'thinking' | 'speaking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';\n\nexport const HEAD_SHAPES: readonly HeadShape[] = ['square', 'tab', 'circle', 'capsule', 'egg', 'pebble', 'hexagon', 'drop'];\nexport const EXPRESSIONS: readonly Expression[] = ['idle', 'thinking', 'speaking', 'working', 'waiting', 'happy', 'error', 'sleeping'];\n/** Cores da família: todas com contraste de pelo menos 3:1 em fundo branco, inclusive no ponto mais claro do degradê. */\nexport const AVATAR_COLORS: readonly string[] = [\n '#2563eb', '#0284c7', '#0f766e', '#15803d', '#4d7c0f', '#a16207', '#c2410c', '#dc2626',\n '#e11d48', '#be123c', '#db2777', '#c026d3', '#9333ea', '#7c3aed', '#4f46e5', '#475569',\n];\n\nconst COLOR = /^#[0-9a-fA-F]{6}$/;\nconst FALLBACK_COLOR = '#2563eb';\n\n/** Até este tamanho (px) vale o corte pequeno: contorno fechado, sem sinal (detalhes que viram ruído). */\nexport const SMALL_SIZE = 24;\n\nconst STROKE = 30;\n/** Comprimento da abertura no contorno (já contando as pontas redondas da linha). */\nconst GAP = 82;\n\nconst rr = (x: number, y: number, w: number, h: number, [a, b, c, d]: [number, number, number, number]) =>\n `M${x + a} ${y}H${x + w - b}A${b} ${b} 0 0 1 ${x + w} ${y + b}V${y + h - c}A${c} ${c} 0 0 1 ${x + w - c} ${y + h}H${x + d}A${d} ${d} 0 0 1 ${x} ${y + h - d}V${y + a}A${a} ${a} 0 0 1 ${x + a} ${y}Z`;\n\n/**\n * Cada forma: contorno, comprimento dele, onde começa a abertura (deslocamento\n * do traço), onde fica o sinal e o centro dos olhos (um pouco acima do centro:\n * o centro óptico). Comprimentos medidos no navegador (`getTotalLength`).\n */\nconst SHAPES: Record<HeadShape, { d: string; length: number; offset: number; signal: [number, number]; eyes: [number, number] }> = {\n square: { d: rr(36, 44, 184, 176, [56, 56, 56, 56]), length: 623.9, offset: 153.3, signal: [200.9, 57.9], eyes: [128, 128] },\n tab: { d: rr(26, 56, 204, 152, [84, 52, 36, 84]), length: 634.2, offset: 139.3, signal: [206.6, 64.6], eyes: [132, 128] },\n circle: { d: 'M128 34A98 98 0 1 1 128 230A98 98 0 1 1 128 34Z', length: 616, offset: 114.9, signal: [195.1, 60.5], eyes: [128, 128] },\n capsule: { d: rr(20, 70, 216, 128, [64, 64, 64, 64]), length: 578.2, offset: 162.4, signal: [203.9, 78.5], eyes: [128, 132] },\n egg: { d: rr(50, 30, 156, 200, [78, 78, 66, 66]), length: 588.5, offset: 111.6, signal: [189.4, 59.8], eyes: [128, 126] },\n pebble: {\n d: 'M131 40C188 40 222 80 218 138C214 192 178 220 124 218C70 216 36 186 38 130C40 76 76 40 131 40Z',\n length: 573.6,\n offset: 109.8,\n signal: [193.8, 63.5],\n eyes: [128, 126],\n },\n hexagon: {\n d: 'M43.1 157.9Q28 132 43.1 106.1L62.9 71.9Q78 46 108 46L148 46Q178 46 193.1 71.9L212.9 106.1Q228 132 212.9 157.9L193.1 192.1Q178 218 148 218L108 218Q78 218 62.9 192.1Z',\n length: 566.2,\n offset: 273.2,\n signal: [186.5, 62.6],\n eyes: [128, 132],\n },\n drop: {\n d: 'M106.2 72.2Q128 34 149.8 72.2L210.2 177.8Q232 216 188 216L68 216Q24 216 45.8 177.8Z',\n length: 545.4,\n offset: 101,\n signal: [149.6, 71.8],\n eyes: [128, 162],\n },\n};\n\nconst EYE = { rx: 16, ry: 22, gap: 32 };\n\n/** Animação de cada expressão; todas param com `prefers-reduced-motion`. */\nconst STYLE = `<style>\n.dlf-eye{transform-box:fill-box;transform-origin:center}\n.dlf-idle .dlf-eye{animation:dlf-blink 5s infinite}\n.dlf-speaking .dlf-eye{animation:dlf-talk .32s ease-in-out infinite alternate}\n.dlf-thinking .dlf-eyes{animation:dlf-float 2.4s ease-in-out infinite alternate}\n.dlf-working .dlf-eyes{animation:dlf-scan 1.6s ease-in-out infinite alternate}\n.dlf-waiting .dlf-eyes{animation:dlf-look 2.8s ease-in-out infinite}\n.dlf-working .dlf-signal,.dlf-waiting .dlf-signal{animation:dlf-pulse 1.2s ease-in-out infinite alternate}\n@keyframes dlf-blink{0%,92%,100%{transform:scaleY(1)}95%{transform:scaleY(.1)}}\n@keyframes dlf-talk{to{transform:scaleY(.75)}}\n@keyframes dlf-float{to{transform:translateY(-5px)}}\n@keyframes dlf-scan{from{transform:translateX(-7px)}to{transform:translateX(7px)}}\n@keyframes dlf-look{0%,100%{transform:none}30%{transform:translateX(-10px)}70%{transform:translateX(10px)}}\n@keyframes dlf-pulse{to{opacity:.3}}\n@media (prefers-reduced-motion:reduce){.dlf-eye,.dlf-eyes,.dlf-signal{animation:none!important}}\n</style>`;\n\nconst mix = (hex: string, to: number, k: number) =>\n '#' + [1, 3, 5].map((i) => Math.round(parseInt(hex.slice(i, i + 2), 16) * (1 - k) + to * k).toString(16).padStart(2, '0')).join('');\n\n/** Cor válida do rosto (cor inválida vira o azul padrão: o valor vem do banco). */\nexport function headColor(spec: Pick<AvatarSpec, 'color'>) {\n return COLOR.test(spec.color) ? spec.color.toLowerCase() : FALLBACK_COLOR;\n}\n\nfunction eyes(expression: Expression, ink: string, [cx, cy]: [number, number]) {\n const line = (d: string) => `<path d=\"${d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"12\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n const one = (x: number) => {\n switch (expression) {\n case 'happy':\n return line(`M${x - 15} ${cy + 7}Q${x} ${cy - 15} ${x + 15} ${cy + 7}`);\n case 'error':\n return line(`M${x - 11} ${cy - 11}L${x + 11} ${cy + 11}M${x + 11} ${cy - 11}L${x - 11} ${cy + 11}`);\n case 'sleeping':\n return line(`M${x - 15} ${cy + 3}Q${x} ${cy + 13} ${x + 15} ${cy + 3}`);\n case 'thinking':\n return `<ellipse class=\"dlf-eye\" cx=\"${x + 7}\" cy=\"${cy - 9}\" rx=\"${EYE.rx * 0.85}\" ry=\"${EYE.ry * 0.85}\" fill=\"${ink}\"/>`;\n case 'working':\n return `<ellipse class=\"dlf-eye\" cx=\"${x}\" cy=\"${cy + 5}\" rx=\"${EYE.rx + 2}\" ry=\"${EYE.ry / 2}\" fill=\"${ink}\"/>`;\n default:\n return `<ellipse class=\"dlf-eye\" cx=\"${x}\" cy=\"${cy}\" rx=\"${EYE.rx}\" ry=\"${EYE.ry}\" fill=\"${ink}\"/>`;\n }\n };\n return `<g class=\"dlf-eyes\">${one(cx - EYE.gap)}${one(cx + EYE.gap)}</g>`;\n}\n\nconst escapeXml = (text: string) => text.replace(/[<>&\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n\nexport interface HeadSvgOptions {\n expression?: Expression;\n /** Largura e altura em px. Padrão: 64. */\n size?: number;\n /** Texto para leitores de tela (o nome do operador). Sem ele, o SVG fica decorativo. */\n title?: string;\n /** Inclui as animações. Padrão: sim. */\n animated?: boolean;\n /** Fundo onde o rosto aparece. Em `dark` a cor clareia para continuar visível. Padrão: `light`. */\n background?: 'light' | 'dark';\n}\n\n/** O rosto como texto SVG (para `innerHTML`, e-mail, favicon ou servidor). */\nexport function headSvg(spec: AvatarSpec, options: HeadSvgOptions = {}): string {\n const expression = options.expression ?? 'idle';\n // Sem a classe da expressão, o CSS de outro rosto animado na página não pega este.\n const animated = options.animated !== false;\n const size = options.size ?? 64;\n const base = headColor(spec);\n const color = options.background === 'dark' ? mix(base, 255, 0.35) : base;\n const shape = SHAPES[spec.shape] ?? SHAPES.square;\n const small = size <= SMALL_SIZE;\n\n // O id depende só da cor: rostos iguais na página compartilham o mesmo degradê, sem conflito.\n const id = `dlf-g${color.slice(1)}`;\n const ink = `url(#${id})`;\n const gradient = `<defs><linearGradient id=\"${id}\" gradientUnits=\"userSpaceOnUse\" x1=\"24\" y1=\"24\" x2=\"232\" y2=\"232\"><stop offset=\"0\" stop-color=\"${mix(color, 255, 0.16)}\"/><stop offset=\"1\" stop-color=\"${mix(color, 0, 0.06)}\"/></linearGradient></defs>`;\n const gap = small ? '' : ` stroke-dasharray=\"${(shape.length - GAP).toFixed(1)} ${GAP}\" stroke-dashoffset=\"${-shape.offset}\"`;\n const outline = `<path d=\"${shape.d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"${STROKE}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"${gap}/>`;\n const signal = small ? '' : `<circle class=\"dlf-signal\" cx=\"${shape.signal[0]}\" cy=\"${shape.signal[1]}\" r=\"15\" fill=\"${ink}\"/>`;\n\n const a11y = options.title ? `role=\"img\" aria-label=\"${escapeXml(options.title)}\"` : 'aria-hidden=\"true\"';\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" width=\"${size}\" height=\"${size}\" ${a11y} class=\"dlf-head${animated ? ` dlf-${expression}` : ''}\">` +\n (animated ? STYLE : '') +\n (options.title ? `<title>${escapeXml(options.title)}</title>` : '') +\n gradient +\n outline +\n signal +\n eyes(expression, ink, shape.eyes) +\n '</svg>'\n );\n}\n\n/** Expressão a partir dos eventos SSE do painel (`type` de cada `DolfinhosEvent`). */\nexport function expressionFor(eventType: string | undefined, status?: string): Expression {\n switch (eventType) {\n case 'run.started':\n return 'thinking';\n case 'text.delta':\n return 'speaking';\n case 'tool.calling':\n return 'working';\n case 'tool.approval_required':\n return 'waiting';\n case 'tool.result':\n return status === 'error' ? 'error' : 'thinking';\n case 'run.completed':\n return status === 'awaiting_approval' ? 'waiting' : 'happy';\n case 'run.error':\n return 'error';\n default:\n return 'idle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AAkB,GAAG;AAE1H,QAAM,OAAO,QAAQ,QAAQ,0BAA0B,UAAU,QAAQ,KAAK,CAAC,MAAM;AACrF,SACE,wEAAwE,IAAI,aAAa,IAAI,KAAK,IAAI,mBAAmB,WAAW,QAAQ,UAAU,KAAK,EAAE,QAC5J,WAAW,QAAQ,OACnB,QAAQ,QAAQ,UAAU,UAAU,QAAQ,KAAK,CAAC,aAAa,MAChE,WACA,UACA,SACA,KAAK,YAAY,KAAK,MAAM,IAAI,IAChC;AAEJ;AAGO,SAAS,cAAc,WAA+B,QAA6B;AACxF,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,WAAW,UAAU,UAAU;AAAA,IACxC,KAAK;AACH,aAAO,WAAW,sBAAsB,YAAY;AAAA,IACtD,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rostos dos operadores: uma forma arredondada em contorno grosso, com dois
|
|
3
|
+
* olhos ovais e uma abertura no alto à direita onde fica o sinal (o ponto que
|
|
4
|
+
* pulsa quando o operador trabalha ou espera aprovação). Uma cor só, com
|
|
5
|
+
* degradê suave, numa tela 256.
|
|
6
|
+
*
|
|
7
|
+
* Mesmo formato do `AvatarSpec` do `@dolfinhos/core`, sem depender dele: o
|
|
8
|
+
* frontend instala só este pacote.
|
|
9
|
+
*/
|
|
10
|
+
type HeadShape = 'square' | 'tab' | 'circle' | 'capsule' | 'egg' | 'pebble' | 'hexagon' | 'drop';
|
|
11
|
+
interface AvatarSpec {
|
|
12
|
+
shape: HeadShape;
|
|
13
|
+
/** Cor do rosto, `#rrggbb`. Use uma de `AVATAR_COLORS` (contrastam com fundo branco). */
|
|
14
|
+
color: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* - `idle`: parado, pisca de vez em quando
|
|
18
|
+
* - `thinking`: olhos para cima, de lado
|
|
19
|
+
* - `speaking`: olhos pulsam enquanto o texto chega
|
|
20
|
+
* - `working`: olhos estreitos, varrendo (usando uma ferramenta); o sinal pulsa
|
|
21
|
+
* - `waiting`: olha de um lado para o outro (esperando aprovação); o sinal pulsa
|
|
22
|
+
* - `happy`: olhos em arco (terminou)
|
|
23
|
+
* - `error`: olhos em ×
|
|
24
|
+
* - `sleeping`: olhos fechados (operador pausado)
|
|
25
|
+
*/
|
|
26
|
+
type Expression = 'idle' | 'thinking' | 'speaking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';
|
|
27
|
+
declare const HEAD_SHAPES: readonly HeadShape[];
|
|
28
|
+
declare const EXPRESSIONS: readonly Expression[];
|
|
29
|
+
/** Cores da família: todas com contraste de pelo menos 3:1 em fundo branco, inclusive no ponto mais claro do degradê. */
|
|
30
|
+
declare const AVATAR_COLORS: readonly string[];
|
|
31
|
+
/** Até este tamanho (px) vale o corte pequeno: contorno fechado, sem sinal (detalhes que viram ruído). */
|
|
32
|
+
declare const SMALL_SIZE = 24;
|
|
33
|
+
/** Cor válida do rosto (cor inválida vira o azul padrão: o valor vem do banco). */
|
|
34
|
+
declare function headColor(spec: Pick<AvatarSpec, 'color'>): string;
|
|
35
|
+
interface HeadSvgOptions {
|
|
36
|
+
expression?: Expression;
|
|
37
|
+
/** Largura e altura em px. Padrão: 64. */
|
|
38
|
+
size?: number;
|
|
39
|
+
/** Texto para leitores de tela (o nome do operador). Sem ele, o SVG fica decorativo. */
|
|
40
|
+
title?: string;
|
|
41
|
+
/** Inclui as animações. Padrão: sim. */
|
|
42
|
+
animated?: boolean;
|
|
43
|
+
/** Fundo onde o rosto aparece. Em `dark` a cor clareia para continuar visível. Padrão: `light`. */
|
|
44
|
+
background?: 'light' | 'dark';
|
|
45
|
+
}
|
|
46
|
+
/** O rosto como texto SVG (para `innerHTML`, e-mail, favicon ou servidor). */
|
|
47
|
+
declare function headSvg(spec: AvatarSpec, options?: HeadSvgOptions): string;
|
|
48
|
+
/** Expressão a partir dos eventos SSE do painel (`type` de cada `DolfinhosEvent`). */
|
|
49
|
+
declare function expressionFor(eventType: string | undefined, status?: string): Expression;
|
|
50
|
+
|
|
51
|
+
export { AVATAR_COLORS, EXPRESSIONS, HEAD_SHAPES, SMALL_SIZE, expressionFor, headColor, headSvg };
|
|
52
|
+
export type { AvatarSpec, Expression, HeadShape, HeadSvgOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rostos dos operadores: uma forma arredondada em contorno grosso, com dois
|
|
3
|
+
* olhos ovais e uma abertura no alto à direita onde fica o sinal (o ponto que
|
|
4
|
+
* pulsa quando o operador trabalha ou espera aprovação). Uma cor só, com
|
|
5
|
+
* degradê suave, numa tela 256.
|
|
6
|
+
*
|
|
7
|
+
* Mesmo formato do `AvatarSpec` do `@dolfinhos/core`, sem depender dele: o
|
|
8
|
+
* frontend instala só este pacote.
|
|
9
|
+
*/
|
|
10
|
+
type HeadShape = 'square' | 'tab' | 'circle' | 'capsule' | 'egg' | 'pebble' | 'hexagon' | 'drop';
|
|
11
|
+
interface AvatarSpec {
|
|
12
|
+
shape: HeadShape;
|
|
13
|
+
/** Cor do rosto, `#rrggbb`. Use uma de `AVATAR_COLORS` (contrastam com fundo branco). */
|
|
14
|
+
color: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* - `idle`: parado, pisca de vez em quando
|
|
18
|
+
* - `thinking`: olhos para cima, de lado
|
|
19
|
+
* - `speaking`: olhos pulsam enquanto o texto chega
|
|
20
|
+
* - `working`: olhos estreitos, varrendo (usando uma ferramenta); o sinal pulsa
|
|
21
|
+
* - `waiting`: olha de um lado para o outro (esperando aprovação); o sinal pulsa
|
|
22
|
+
* - `happy`: olhos em arco (terminou)
|
|
23
|
+
* - `error`: olhos em ×
|
|
24
|
+
* - `sleeping`: olhos fechados (operador pausado)
|
|
25
|
+
*/
|
|
26
|
+
type Expression = 'idle' | 'thinking' | 'speaking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';
|
|
27
|
+
declare const HEAD_SHAPES: readonly HeadShape[];
|
|
28
|
+
declare const EXPRESSIONS: readonly Expression[];
|
|
29
|
+
/** Cores da família: todas com contraste de pelo menos 3:1 em fundo branco, inclusive no ponto mais claro do degradê. */
|
|
30
|
+
declare const AVATAR_COLORS: readonly string[];
|
|
31
|
+
/** Até este tamanho (px) vale o corte pequeno: contorno fechado, sem sinal (detalhes que viram ruído). */
|
|
32
|
+
declare const SMALL_SIZE = 24;
|
|
33
|
+
/** Cor válida do rosto (cor inválida vira o azul padrão: o valor vem do banco). */
|
|
34
|
+
declare function headColor(spec: Pick<AvatarSpec, 'color'>): string;
|
|
35
|
+
interface HeadSvgOptions {
|
|
36
|
+
expression?: Expression;
|
|
37
|
+
/** Largura e altura em px. Padrão: 64. */
|
|
38
|
+
size?: number;
|
|
39
|
+
/** Texto para leitores de tela (o nome do operador). Sem ele, o SVG fica decorativo. */
|
|
40
|
+
title?: string;
|
|
41
|
+
/** Inclui as animações. Padrão: sim. */
|
|
42
|
+
animated?: boolean;
|
|
43
|
+
/** Fundo onde o rosto aparece. Em `dark` a cor clareia para continuar visível. Padrão: `light`. */
|
|
44
|
+
background?: 'light' | 'dark';
|
|
45
|
+
}
|
|
46
|
+
/** O rosto como texto SVG (para `innerHTML`, e-mail, favicon ou servidor). */
|
|
47
|
+
declare function headSvg(spec: AvatarSpec, options?: HeadSvgOptions): string;
|
|
48
|
+
/** Expressão a partir dos eventos SSE do painel (`type` de cada `DolfinhosEvent`). */
|
|
49
|
+
declare function expressionFor(eventType: string | undefined, status?: string): Expression;
|
|
50
|
+
|
|
51
|
+
export { AVATAR_COLORS, EXPRESSIONS, HEAD_SHAPES, SMALL_SIZE, expressionFor, headColor, headSvg };
|
|
52
|
+
export type { AvatarSpec, Expression, HeadShape, HeadSvgOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AVATAR_COLORS,
|
|
3
|
+
EXPRESSIONS,
|
|
4
|
+
HEAD_SHAPES,
|
|
5
|
+
SMALL_SIZE,
|
|
6
|
+
expressionFor,
|
|
7
|
+
headColor,
|
|
8
|
+
headSvg
|
|
9
|
+
} from "./chunk-PPIZV2B3.js";
|
|
10
|
+
export {
|
|
11
|
+
AVATAR_COLORS,
|
|
12
|
+
EXPRESSIONS,
|
|
13
|
+
HEAD_SHAPES,
|
|
14
|
+
SMALL_SIZE,
|
|
15
|
+
expressionFor,
|
|
16
|
+
headColor,
|
|
17
|
+
headSvg
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react.tsx
|
|
21
|
+
var react_exports = {};
|
|
22
|
+
__export(react_exports, {
|
|
23
|
+
OperatorHead: () => OperatorHead
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(react_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
30
|
+
var FALLBACK_COLOR = "#2563eb";
|
|
31
|
+
var SMALL_SIZE = 24;
|
|
32
|
+
var STROKE = 30;
|
|
33
|
+
var GAP = 82;
|
|
34
|
+
var rr = (x, y, w, h, [a, b, c, d]) => `M${x + a} ${y}H${x + w - b}A${b} ${b} 0 0 1 ${x + w} ${y + b}V${y + h - c}A${c} ${c} 0 0 1 ${x + w - c} ${y + h}H${x + d}A${d} ${d} 0 0 1 ${x} ${y + h - d}V${y + a}A${a} ${a} 0 0 1 ${x + a} ${y}Z`;
|
|
35
|
+
var SHAPES = {
|
|
36
|
+
square: { d: rr(36, 44, 184, 176, [56, 56, 56, 56]), length: 623.9, offset: 153.3, signal: [200.9, 57.9], eyes: [128, 128] },
|
|
37
|
+
tab: { d: rr(26, 56, 204, 152, [84, 52, 36, 84]), length: 634.2, offset: 139.3, signal: [206.6, 64.6], eyes: [132, 128] },
|
|
38
|
+
circle: { d: "M128 34A98 98 0 1 1 128 230A98 98 0 1 1 128 34Z", length: 616, offset: 114.9, signal: [195.1, 60.5], eyes: [128, 128] },
|
|
39
|
+
capsule: { d: rr(20, 70, 216, 128, [64, 64, 64, 64]), length: 578.2, offset: 162.4, signal: [203.9, 78.5], eyes: [128, 132] },
|
|
40
|
+
egg: { d: rr(50, 30, 156, 200, [78, 78, 66, 66]), length: 588.5, offset: 111.6, signal: [189.4, 59.8], eyes: [128, 126] },
|
|
41
|
+
pebble: {
|
|
42
|
+
d: "M131 40C188 40 222 80 218 138C214 192 178 220 124 218C70 216 36 186 38 130C40 76 76 40 131 40Z",
|
|
43
|
+
length: 573.6,
|
|
44
|
+
offset: 109.8,
|
|
45
|
+
signal: [193.8, 63.5],
|
|
46
|
+
eyes: [128, 126]
|
|
47
|
+
},
|
|
48
|
+
hexagon: {
|
|
49
|
+
d: "M43.1 157.9Q28 132 43.1 106.1L62.9 71.9Q78 46 108 46L148 46Q178 46 193.1 71.9L212.9 106.1Q228 132 212.9 157.9L193.1 192.1Q178 218 148 218L108 218Q78 218 62.9 192.1Z",
|
|
50
|
+
length: 566.2,
|
|
51
|
+
offset: 273.2,
|
|
52
|
+
signal: [186.5, 62.6],
|
|
53
|
+
eyes: [128, 132]
|
|
54
|
+
},
|
|
55
|
+
drop: {
|
|
56
|
+
d: "M106.2 72.2Q128 34 149.8 72.2L210.2 177.8Q232 216 188 216L68 216Q24 216 45.8 177.8Z",
|
|
57
|
+
length: 545.4,
|
|
58
|
+
offset: 101,
|
|
59
|
+
signal: [149.6, 71.8],
|
|
60
|
+
eyes: [128, 162]
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var EYE = { rx: 16, ry: 22, gap: 32 };
|
|
64
|
+
var STYLE = `<style>
|
|
65
|
+
.dlf-eye{transform-box:fill-box;transform-origin:center}
|
|
66
|
+
.dlf-idle .dlf-eye{animation:dlf-blink 5s infinite}
|
|
67
|
+
.dlf-speaking .dlf-eye{animation:dlf-talk .32s ease-in-out infinite alternate}
|
|
68
|
+
.dlf-thinking .dlf-eyes{animation:dlf-float 2.4s ease-in-out infinite alternate}
|
|
69
|
+
.dlf-working .dlf-eyes{animation:dlf-scan 1.6s ease-in-out infinite alternate}
|
|
70
|
+
.dlf-waiting .dlf-eyes{animation:dlf-look 2.8s ease-in-out infinite}
|
|
71
|
+
.dlf-working .dlf-signal,.dlf-waiting .dlf-signal{animation:dlf-pulse 1.2s ease-in-out infinite alternate}
|
|
72
|
+
@keyframes dlf-blink{0%,92%,100%{transform:scaleY(1)}95%{transform:scaleY(.1)}}
|
|
73
|
+
@keyframes dlf-talk{to{transform:scaleY(.75)}}
|
|
74
|
+
@keyframes dlf-float{to{transform:translateY(-5px)}}
|
|
75
|
+
@keyframes dlf-scan{from{transform:translateX(-7px)}to{transform:translateX(7px)}}
|
|
76
|
+
@keyframes dlf-look{0%,100%{transform:none}30%{transform:translateX(-10px)}70%{transform:translateX(10px)}}
|
|
77
|
+
@keyframes dlf-pulse{to{opacity:.3}}
|
|
78
|
+
@media (prefers-reduced-motion:reduce){.dlf-eye,.dlf-eyes,.dlf-signal{animation:none!important}}
|
|
79
|
+
</style>`;
|
|
80
|
+
var mix = (hex, to, k) => "#" + [1, 3, 5].map((i) => Math.round(parseInt(hex.slice(i, i + 2), 16) * (1 - k) + to * k).toString(16).padStart(2, "0")).join("");
|
|
81
|
+
function headColor(spec) {
|
|
82
|
+
return COLOR.test(spec.color) ? spec.color.toLowerCase() : FALLBACK_COLOR;
|
|
83
|
+
}
|
|
84
|
+
function eyes(expression, ink, [cx, cy]) {
|
|
85
|
+
const line = (d) => `<path d="${d}" fill="none" stroke="${ink}" stroke-width="12" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
86
|
+
const one = (x) => {
|
|
87
|
+
switch (expression) {
|
|
88
|
+
case "happy":
|
|
89
|
+
return line(`M${x - 15} ${cy + 7}Q${x} ${cy - 15} ${x + 15} ${cy + 7}`);
|
|
90
|
+
case "error":
|
|
91
|
+
return line(`M${x - 11} ${cy - 11}L${x + 11} ${cy + 11}M${x + 11} ${cy - 11}L${x - 11} ${cy + 11}`);
|
|
92
|
+
case "sleeping":
|
|
93
|
+
return line(`M${x - 15} ${cy + 3}Q${x} ${cy + 13} ${x + 15} ${cy + 3}`);
|
|
94
|
+
case "thinking":
|
|
95
|
+
return `<ellipse class="dlf-eye" cx="${x + 7}" cy="${cy - 9}" rx="${EYE.rx * 0.85}" ry="${EYE.ry * 0.85}" fill="${ink}"/>`;
|
|
96
|
+
case "working":
|
|
97
|
+
return `<ellipse class="dlf-eye" cx="${x}" cy="${cy + 5}" rx="${EYE.rx + 2}" ry="${EYE.ry / 2}" fill="${ink}"/>`;
|
|
98
|
+
default:
|
|
99
|
+
return `<ellipse class="dlf-eye" cx="${x}" cy="${cy}" rx="${EYE.rx}" ry="${EYE.ry}" fill="${ink}"/>`;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return `<g class="dlf-eyes">${one(cx - EYE.gap)}${one(cx + EYE.gap)}</g>`;
|
|
103
|
+
}
|
|
104
|
+
var escapeXml = (text) => text.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
105
|
+
function headSvg(spec, options = {}) {
|
|
106
|
+
const expression = options.expression ?? "idle";
|
|
107
|
+
const animated = options.animated !== false;
|
|
108
|
+
const size = options.size ?? 64;
|
|
109
|
+
const base = headColor(spec);
|
|
110
|
+
const color = options.background === "dark" ? mix(base, 255, 0.35) : base;
|
|
111
|
+
const shape = SHAPES[spec.shape] ?? SHAPES.square;
|
|
112
|
+
const small = size <= SMALL_SIZE;
|
|
113
|
+
const id = `dlf-g${color.slice(1)}`;
|
|
114
|
+
const ink = `url(#${id})`;
|
|
115
|
+
const gradient = `<defs><linearGradient id="${id}" gradientUnits="userSpaceOnUse" x1="24" y1="24" x2="232" y2="232"><stop offset="0" stop-color="${mix(color, 255, 0.16)}"/><stop offset="1" stop-color="${mix(color, 0, 0.06)}"/></linearGradient></defs>`;
|
|
116
|
+
const gap = small ? "" : ` stroke-dasharray="${(shape.length - GAP).toFixed(1)} ${GAP}" stroke-dashoffset="${-shape.offset}"`;
|
|
117
|
+
const outline = `<path d="${shape.d}" fill="none" stroke="${ink}" stroke-width="${STROKE}" stroke-linecap="round" stroke-linejoin="round"${gap}/>`;
|
|
118
|
+
const signal = small ? "" : `<circle class="dlf-signal" cx="${shape.signal[0]}" cy="${shape.signal[1]}" r="15" fill="${ink}"/>`;
|
|
119
|
+
const a11y = options.title ? `role="img" aria-label="${escapeXml(options.title)}"` : 'aria-hidden="true"';
|
|
120
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="${size}" height="${size}" ${a11y} class="dlf-head${animated ? ` dlf-${expression}` : ""}">` + (animated ? STYLE : "") + (options.title ? `<title>${escapeXml(options.title)}</title>` : "") + gradient + outline + signal + eyes(expression, ink, shape.eyes) + "</svg>";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/react.tsx
|
|
124
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
125
|
+
function OperatorHead({ avatar, expression = "idle", size = 40, title, className, animated = true, background = "light" }) {
|
|
126
|
+
const html = (0, import_react.useMemo)(
|
|
127
|
+
() => headSvg(avatar, { expression, size, animated, background, ...title ? { title } : {} }),
|
|
128
|
+
[avatar.shape, avatar.color, expression, size, title, animated, background]
|
|
129
|
+
);
|
|
130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className, style: { display: "inline-flex", width: size, height: size }, dangerouslySetInnerHTML: { __html: html } });
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
OperatorHead
|
|
135
|
+
});
|
|
136
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx","../src/index.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { headSvg, type AvatarSpec, type Expression } from './index.js';\n\nexport interface OperatorHeadProps {\n avatar: AvatarSpec;\n expression?: Expression;\n /** Px. Padrão: 40. */\n size?: number;\n /** Nome do operador, para leitores de tela. Sem ele, o rosto é decorativo. */\n title?: string;\n className?: string;\n /** Padrão: sim. Desligue em miniaturas paradas (listas de escolha). */\n animated?: boolean;\n /** Fundo onde o rosto aparece; em `dark` a cor clareia. Padrão: `light`. */\n background?: 'light' | 'dark';\n}\n\n/** Rosto do operador. O SVG é gerado aqui a partir de dados validados (cor e formas de listas fixas). */\nexport function OperatorHead({ avatar, expression = 'idle', size = 40, title, className, animated = true, background = 'light' }: OperatorHeadProps) {\n const html = useMemo(\n () => headSvg(avatar, { expression, size, animated, background, ...(title ? { title } : {}) }),\n [avatar.shape, avatar.color, expression, size, title, animated, background],\n );\n return <span className={className} style={{ display: 'inline-flex', width: size, height: size }} dangerouslySetInnerHTML={{ __html: html }} />;\n}\n\nexport type { AvatarSpec, Expression } from './index.js';\n","/**\n * Rostos dos operadores: uma forma arredondada em contorno grosso, com dois\n * olhos ovais e uma abertura no alto à direita onde fica o sinal (o ponto que\n * pulsa quando o operador trabalha ou espera aprovação). Uma cor só, com\n * degradê suave, numa tela 256.\n *\n * Mesmo formato do `AvatarSpec` do `@dolfinhos/core`, sem depender dele: o\n * frontend instala só este pacote.\n */\n\nexport type HeadShape = 'square' | 'tab' | 'circle' | 'capsule' | 'egg' | 'pebble' | 'hexagon' | 'drop';\n\nexport interface AvatarSpec {\n shape: HeadShape;\n /** Cor do rosto, `#rrggbb`. Use uma de `AVATAR_COLORS` (contrastam com fundo branco). */\n color: string;\n}\n\n/**\n * - `idle`: parado, pisca de vez em quando\n * - `thinking`: olhos para cima, de lado\n * - `speaking`: olhos pulsam enquanto o texto chega\n * - `working`: olhos estreitos, varrendo (usando uma ferramenta); o sinal pulsa\n * - `waiting`: olha de um lado para o outro (esperando aprovação); o sinal pulsa\n * - `happy`: olhos em arco (terminou)\n * - `error`: olhos em ×\n * - `sleeping`: olhos fechados (operador pausado)\n */\nexport type Expression = 'idle' | 'thinking' | 'speaking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';\n\nexport const HEAD_SHAPES: readonly HeadShape[] = ['square', 'tab', 'circle', 'capsule', 'egg', 'pebble', 'hexagon', 'drop'];\nexport const EXPRESSIONS: readonly Expression[] = ['idle', 'thinking', 'speaking', 'working', 'waiting', 'happy', 'error', 'sleeping'];\n/** Cores da família: todas com contraste de pelo menos 3:1 em fundo branco, inclusive no ponto mais claro do degradê. */\nexport const AVATAR_COLORS: readonly string[] = [\n '#2563eb', '#0284c7', '#0f766e', '#15803d', '#4d7c0f', '#a16207', '#c2410c', '#dc2626',\n '#e11d48', '#be123c', '#db2777', '#c026d3', '#9333ea', '#7c3aed', '#4f46e5', '#475569',\n];\n\nconst COLOR = /^#[0-9a-fA-F]{6}$/;\nconst FALLBACK_COLOR = '#2563eb';\n\n/** Até este tamanho (px) vale o corte pequeno: contorno fechado, sem sinal (detalhes que viram ruído). */\nexport const SMALL_SIZE = 24;\n\nconst STROKE = 30;\n/** Comprimento da abertura no contorno (já contando as pontas redondas da linha). */\nconst GAP = 82;\n\nconst rr = (x: number, y: number, w: number, h: number, [a, b, c, d]: [number, number, number, number]) =>\n `M${x + a} ${y}H${x + w - b}A${b} ${b} 0 0 1 ${x + w} ${y + b}V${y + h - c}A${c} ${c} 0 0 1 ${x + w - c} ${y + h}H${x + d}A${d} ${d} 0 0 1 ${x} ${y + h - d}V${y + a}A${a} ${a} 0 0 1 ${x + a} ${y}Z`;\n\n/**\n * Cada forma: contorno, comprimento dele, onde começa a abertura (deslocamento\n * do traço), onde fica o sinal e o centro dos olhos (um pouco acima do centro:\n * o centro óptico). Comprimentos medidos no navegador (`getTotalLength`).\n */\nconst SHAPES: Record<HeadShape, { d: string; length: number; offset: number; signal: [number, number]; eyes: [number, number] }> = {\n square: { d: rr(36, 44, 184, 176, [56, 56, 56, 56]), length: 623.9, offset: 153.3, signal: [200.9, 57.9], eyes: [128, 128] },\n tab: { d: rr(26, 56, 204, 152, [84, 52, 36, 84]), length: 634.2, offset: 139.3, signal: [206.6, 64.6], eyes: [132, 128] },\n circle: { d: 'M128 34A98 98 0 1 1 128 230A98 98 0 1 1 128 34Z', length: 616, offset: 114.9, signal: [195.1, 60.5], eyes: [128, 128] },\n capsule: { d: rr(20, 70, 216, 128, [64, 64, 64, 64]), length: 578.2, offset: 162.4, signal: [203.9, 78.5], eyes: [128, 132] },\n egg: { d: rr(50, 30, 156, 200, [78, 78, 66, 66]), length: 588.5, offset: 111.6, signal: [189.4, 59.8], eyes: [128, 126] },\n pebble: {\n d: 'M131 40C188 40 222 80 218 138C214 192 178 220 124 218C70 216 36 186 38 130C40 76 76 40 131 40Z',\n length: 573.6,\n offset: 109.8,\n signal: [193.8, 63.5],\n eyes: [128, 126],\n },\n hexagon: {\n d: 'M43.1 157.9Q28 132 43.1 106.1L62.9 71.9Q78 46 108 46L148 46Q178 46 193.1 71.9L212.9 106.1Q228 132 212.9 157.9L193.1 192.1Q178 218 148 218L108 218Q78 218 62.9 192.1Z',\n length: 566.2,\n offset: 273.2,\n signal: [186.5, 62.6],\n eyes: [128, 132],\n },\n drop: {\n d: 'M106.2 72.2Q128 34 149.8 72.2L210.2 177.8Q232 216 188 216L68 216Q24 216 45.8 177.8Z',\n length: 545.4,\n offset: 101,\n signal: [149.6, 71.8],\n eyes: [128, 162],\n },\n};\n\nconst EYE = { rx: 16, ry: 22, gap: 32 };\n\n/** Animação de cada expressão; todas param com `prefers-reduced-motion`. */\nconst STYLE = `<style>\n.dlf-eye{transform-box:fill-box;transform-origin:center}\n.dlf-idle .dlf-eye{animation:dlf-blink 5s infinite}\n.dlf-speaking .dlf-eye{animation:dlf-talk .32s ease-in-out infinite alternate}\n.dlf-thinking .dlf-eyes{animation:dlf-float 2.4s ease-in-out infinite alternate}\n.dlf-working .dlf-eyes{animation:dlf-scan 1.6s ease-in-out infinite alternate}\n.dlf-waiting .dlf-eyes{animation:dlf-look 2.8s ease-in-out infinite}\n.dlf-working .dlf-signal,.dlf-waiting .dlf-signal{animation:dlf-pulse 1.2s ease-in-out infinite alternate}\n@keyframes dlf-blink{0%,92%,100%{transform:scaleY(1)}95%{transform:scaleY(.1)}}\n@keyframes dlf-talk{to{transform:scaleY(.75)}}\n@keyframes dlf-float{to{transform:translateY(-5px)}}\n@keyframes dlf-scan{from{transform:translateX(-7px)}to{transform:translateX(7px)}}\n@keyframes dlf-look{0%,100%{transform:none}30%{transform:translateX(-10px)}70%{transform:translateX(10px)}}\n@keyframes dlf-pulse{to{opacity:.3}}\n@media (prefers-reduced-motion:reduce){.dlf-eye,.dlf-eyes,.dlf-signal{animation:none!important}}\n</style>`;\n\nconst mix = (hex: string, to: number, k: number) =>\n '#' + [1, 3, 5].map((i) => Math.round(parseInt(hex.slice(i, i + 2), 16) * (1 - k) + to * k).toString(16).padStart(2, '0')).join('');\n\n/** Cor válida do rosto (cor inválida vira o azul padrão: o valor vem do banco). */\nexport function headColor(spec: Pick<AvatarSpec, 'color'>) {\n return COLOR.test(spec.color) ? spec.color.toLowerCase() : FALLBACK_COLOR;\n}\n\nfunction eyes(expression: Expression, ink: string, [cx, cy]: [number, number]) {\n const line = (d: string) => `<path d=\"${d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"12\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n const one = (x: number) => {\n switch (expression) {\n case 'happy':\n return line(`M${x - 15} ${cy + 7}Q${x} ${cy - 15} ${x + 15} ${cy + 7}`);\n case 'error':\n return line(`M${x - 11} ${cy - 11}L${x + 11} ${cy + 11}M${x + 11} ${cy - 11}L${x - 11} ${cy + 11}`);\n case 'sleeping':\n return line(`M${x - 15} ${cy + 3}Q${x} ${cy + 13} ${x + 15} ${cy + 3}`);\n case 'thinking':\n return `<ellipse class=\"dlf-eye\" cx=\"${x + 7}\" cy=\"${cy - 9}\" rx=\"${EYE.rx * 0.85}\" ry=\"${EYE.ry * 0.85}\" fill=\"${ink}\"/>`;\n case 'working':\n return `<ellipse class=\"dlf-eye\" cx=\"${x}\" cy=\"${cy + 5}\" rx=\"${EYE.rx + 2}\" ry=\"${EYE.ry / 2}\" fill=\"${ink}\"/>`;\n default:\n return `<ellipse class=\"dlf-eye\" cx=\"${x}\" cy=\"${cy}\" rx=\"${EYE.rx}\" ry=\"${EYE.ry}\" fill=\"${ink}\"/>`;\n }\n };\n return `<g class=\"dlf-eyes\">${one(cx - EYE.gap)}${one(cx + EYE.gap)}</g>`;\n}\n\nconst escapeXml = (text: string) => text.replace(/[<>&\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n\nexport interface HeadSvgOptions {\n expression?: Expression;\n /** Largura e altura em px. Padrão: 64. */\n size?: number;\n /** Texto para leitores de tela (o nome do operador). Sem ele, o SVG fica decorativo. */\n title?: string;\n /** Inclui as animações. Padrão: sim. */\n animated?: boolean;\n /** Fundo onde o rosto aparece. Em `dark` a cor clareia para continuar visível. Padrão: `light`. */\n background?: 'light' | 'dark';\n}\n\n/** O rosto como texto SVG (para `innerHTML`, e-mail, favicon ou servidor). */\nexport function headSvg(spec: AvatarSpec, options: HeadSvgOptions = {}): string {\n const expression = options.expression ?? 'idle';\n // Sem a classe da expressão, o CSS de outro rosto animado na página não pega este.\n const animated = options.animated !== false;\n const size = options.size ?? 64;\n const base = headColor(spec);\n const color = options.background === 'dark' ? mix(base, 255, 0.35) : base;\n const shape = SHAPES[spec.shape] ?? SHAPES.square;\n const small = size <= SMALL_SIZE;\n\n // O id depende só da cor: rostos iguais na página compartilham o mesmo degradê, sem conflito.\n const id = `dlf-g${color.slice(1)}`;\n const ink = `url(#${id})`;\n const gradient = `<defs><linearGradient id=\"${id}\" gradientUnits=\"userSpaceOnUse\" x1=\"24\" y1=\"24\" x2=\"232\" y2=\"232\"><stop offset=\"0\" stop-color=\"${mix(color, 255, 0.16)}\"/><stop offset=\"1\" stop-color=\"${mix(color, 0, 0.06)}\"/></linearGradient></defs>`;\n const gap = small ? '' : ` stroke-dasharray=\"${(shape.length - GAP).toFixed(1)} ${GAP}\" stroke-dashoffset=\"${-shape.offset}\"`;\n const outline = `<path d=\"${shape.d}\" fill=\"none\" stroke=\"${ink}\" stroke-width=\"${STROKE}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"${gap}/>`;\n const signal = small ? '' : `<circle class=\"dlf-signal\" cx=\"${shape.signal[0]}\" cy=\"${shape.signal[1]}\" r=\"15\" fill=\"${ink}\"/>`;\n\n const a11y = options.title ? `role=\"img\" aria-label=\"${escapeXml(options.title)}\"` : 'aria-hidden=\"true\"';\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" width=\"${size}\" height=\"${size}\" ${a11y} class=\"dlf-head${animated ? ` dlf-${expression}` : ''}\">` +\n (animated ? STYLE : '') +\n (options.title ? `<title>${escapeXml(options.title)}</title>` : '') +\n gradient +\n outline +\n signal +\n eyes(expression, ink, shape.eyes) +\n '</svg>'\n );\n}\n\n/** Expressão a partir dos eventos SSE do painel (`type` de cada `DolfinhosEvent`). */\nexport function expressionFor(eventType: string | undefined, status?: string): Expression {\n switch (eventType) {\n case 'run.started':\n return 'thinking';\n case 'text.delta':\n return 'speaking';\n case 'tool.calling':\n return 'working';\n case 'tool.approval_required':\n return 'waiting';\n case 'tool.result':\n return status === 'error' ? 'error' : 'thinking';\n case 'run.completed':\n return status === 'awaiting_approval' ? 'waiting' : 'happy';\n case 'run.error':\n return 'error';\n default:\n return 'idle';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;;;ACsCxB,IAAM,QAAQ;AACd,IAAM,iBAAiB;AAGhB,IAAM,aAAa;AAE1B,IAAM,SAAS;AAEf,IAAM,MAAM;AAEZ,IAAM,KAAK,CAAC,GAAW,GAAW,GAAW,GAAW,CAAC,GAAG,GAAG,GAAG,CAAC,MACjE,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC;AAOpM,IAAM,SAA6H;AAAA,EACjI,QAAQ,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1H,QAAM,UAAU,YAAY,MAAM,CAAC,yBAAyB,GAAG,mBAAmB,MAAM,mDAAmD,GAAG;AAC9I,QAAM,SAAS,QAAQ,KAAK,kCAAkC,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,OAAO,CAAC,CAAC,kBAAkB,GAAG;AAE1H,QAAM,OAAO,QAAQ,QAAQ,0BAA0B,UAAU,QAAQ,KAAK,CAAC,MAAM;AACrF,SACE,wEAAwE,IAAI,aAAa,IAAI,KAAK,IAAI,mBAAmB,WAAW,QAAQ,UAAU,KAAK,EAAE,QAC5J,WAAW,QAAQ,OACnB,QAAQ,QAAQ,UAAU,UAAU,QAAQ,KAAK,CAAC,aAAa,MAChE,WACA,UACA,SACA,KAAK,YAAY,KAAK,MAAM,IAAI,IAChC;AAEJ;;;AD3JS;AALF,SAAS,aAAa,EAAE,QAAQ,aAAa,QAAQ,OAAO,IAAI,OAAO,WAAW,WAAW,MAAM,aAAa,QAAQ,GAAsB;AACnJ,QAAM,WAAO;AAAA,IACX,MAAM,QAAQ,QAAQ,EAAE,YAAY,MAAM,UAAU,YAAY,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAG,CAAC;AAAA,IAC7F,CAAC,OAAO,OAAO,OAAO,OAAO,YAAY,MAAM,OAAO,UAAU,UAAU;AAAA,EAC5E;AACA,SAAO,4CAAC,UAAK,WAAsB,OAAO,EAAE,SAAS,eAAe,OAAO,MAAM,QAAQ,KAAK,GAAG,yBAAyB,EAAE,QAAQ,KAAK,GAAG;AAC9I;","names":[]}
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { AvatarSpec, Expression } from './index.cjs';
|
|
3
|
+
|
|
4
|
+
interface OperatorHeadProps {
|
|
5
|
+
avatar: AvatarSpec;
|
|
6
|
+
expression?: Expression;
|
|
7
|
+
/** Px. Padrão: 40. */
|
|
8
|
+
size?: number;
|
|
9
|
+
/** Nome do operador, para leitores de tela. Sem ele, o rosto é decorativo. */
|
|
10
|
+
title?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Padrão: sim. Desligue em miniaturas paradas (listas de escolha). */
|
|
13
|
+
animated?: boolean;
|
|
14
|
+
/** Fundo onde o rosto aparece; em `dark` a cor clareia. Padrão: `light`. */
|
|
15
|
+
background?: 'light' | 'dark';
|
|
16
|
+
}
|
|
17
|
+
/** Rosto do operador. O SVG é gerado aqui a partir de dados validados (cor e formas de listas fixas). */
|
|
18
|
+
declare function OperatorHead({ avatar, expression, size, title, className, animated, background }: OperatorHeadProps): react.JSX.Element;
|
|
19
|
+
|
|
20
|
+
export { AvatarSpec, Expression, OperatorHead };
|
|
21
|
+
export type { OperatorHeadProps };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { AvatarSpec, Expression } from './index.js';
|
|
3
|
+
|
|
4
|
+
interface OperatorHeadProps {
|
|
5
|
+
avatar: AvatarSpec;
|
|
6
|
+
expression?: Expression;
|
|
7
|
+
/** Px. Padrão: 40. */
|
|
8
|
+
size?: number;
|
|
9
|
+
/** Nome do operador, para leitores de tela. Sem ele, o rosto é decorativo. */
|
|
10
|
+
title?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Padrão: sim. Desligue em miniaturas paradas (listas de escolha). */
|
|
13
|
+
animated?: boolean;
|
|
14
|
+
/** Fundo onde o rosto aparece; em `dark` a cor clareia. Padrão: `light`. */
|
|
15
|
+
background?: 'light' | 'dark';
|
|
16
|
+
}
|
|
17
|
+
/** Rosto do operador. O SVG é gerado aqui a partir de dados validados (cor e formas de listas fixas). */
|
|
18
|
+
declare function OperatorHead({ avatar, expression, size, title, className, animated, background }: OperatorHeadProps): react.JSX.Element;
|
|
19
|
+
|
|
20
|
+
export { AvatarSpec, Expression, OperatorHead };
|
|
21
|
+
export type { OperatorHeadProps };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
headSvg
|
|
3
|
+
} from "./chunk-PPIZV2B3.js";
|
|
4
|
+
|
|
5
|
+
// src/react.tsx
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function OperatorHead({ avatar, expression = "idle", size = 40, title, className, animated = true, background = "light" }) {
|
|
9
|
+
const html = useMemo(
|
|
10
|
+
() => headSvg(avatar, { expression, size, animated, background, ...title ? { title } : {} }),
|
|
11
|
+
[avatar.shape, avatar.color, expression, size, title, animated, background]
|
|
12
|
+
);
|
|
13
|
+
return /* @__PURE__ */ jsx("span", { className, style: { display: "inline-flex", width: size, height: size }, dangerouslySetInnerHTML: { __html: html } });
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
OperatorHead
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { headSvg, type AvatarSpec, type Expression } from './index.js';\n\nexport interface OperatorHeadProps {\n avatar: AvatarSpec;\n expression?: Expression;\n /** Px. Padrão: 40. */\n size?: number;\n /** Nome do operador, para leitores de tela. Sem ele, o rosto é decorativo. */\n title?: string;\n className?: string;\n /** Padrão: sim. Desligue em miniaturas paradas (listas de escolha). */\n animated?: boolean;\n /** Fundo onde o rosto aparece; em `dark` a cor clareia. Padrão: `light`. */\n background?: 'light' | 'dark';\n}\n\n/** Rosto do operador. O SVG é gerado aqui a partir de dados validados (cor e formas de listas fixas). */\nexport function OperatorHead({ avatar, expression = 'idle', size = 40, title, className, animated = true, background = 'light' }: OperatorHeadProps) {\n const html = useMemo(\n () => headSvg(avatar, { expression, size, animated, background, ...(title ? { title } : {}) }),\n [avatar.shape, avatar.color, expression, size, title, animated, background],\n );\n return <span className={className} style={{ display: 'inline-flex', width: size, height: size }} dangerouslySetInnerHTML={{ __html: html }} />;\n}\n\nexport type { AvatarSpec, Expression } from './index.js';\n"],"mappings":";;;;;AAAA,SAAS,eAAe;AAuBf;AALF,SAAS,aAAa,EAAE,QAAQ,aAAa,QAAQ,OAAO,IAAI,OAAO,WAAW,WAAW,MAAM,aAAa,QAAQ,GAAsB;AACnJ,QAAM,OAAO;AAAA,IACX,MAAM,QAAQ,QAAQ,EAAE,YAAY,MAAM,UAAU,YAAY,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAG,CAAC;AAAA,IAC7F,CAAC,OAAO,OAAO,OAAO,OAAO,YAAY,MAAM,OAAO,UAAU,UAAU;AAAA,EAC5E;AACA,SAAO,oBAAC,UAAK,WAAsB,OAAO,EAAE,SAAS,eAAe,OAAO,MAAM,QAAQ,KAAK,GAAG,yBAAyB,EAAE,QAAQ,KAAK,GAAG;AAC9I;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolfinhos/avatar",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Rostos dos operadores do Dolfinhos em SVG: formas arredondadas em contorno, só com olhos, com expressões.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"dolfinhos",
|
|
8
|
+
"avatar",
|
|
9
|
+
"svg",
|
|
10
|
+
"robot",
|
|
11
|
+
"agents"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/dolfinsis/dolfinhos-toolkit.git",
|
|
16
|
+
"directory": "packages/avatar"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/dolfinsis/dolfinhos-toolkit/tree/main/packages/avatar#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/dolfinsis/dolfinhos-toolkit/issues"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./react": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/react.d.ts",
|
|
41
|
+
"default": "./dist/react.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/react.d.cts",
|
|
45
|
+
"default": "./dist/react.cjs"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": ">=18"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"react": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@testing-library/react": "^16.3.3",
|
|
62
|
+
"@types/react": "^19.3.3",
|
|
63
|
+
"jsdom": "^31.0.1",
|
|
64
|
+
"react": "^19.3.1",
|
|
65
|
+
"react-dom": "^19.3.1"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=20"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsup",
|
|
75
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
76
|
+
"test": "vitest run",
|
|
77
|
+
"clean": "rm -rf dist .turbo"
|
|
78
|
+
}
|
|
6
79
|
}
|