@vowt-tech/ui 0.178.0 → 0.179.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/guia/LEIA-PRIMEIRO.md +1 -1
- package/guia/VERSAO +1 -1
- package/guia/componentes.md +2 -2
- package/package.json +1 -1
- package/src/components/ai-orb.tsx +195 -3
- package/src/styles/theme.css +47 -0
package/guia/LEIA-PRIMEIRO.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Design system VOWT, guia para este app
|
|
2
2
|
|
|
3
|
-
> Pasta gerada pelo pacote @vowt-tech/ui 0.
|
|
3
|
+
> Pasta gerada pelo pacote @vowt-tech/ui 0.179.0. Não edite: ela é refeita a cada atualização
|
|
4
4
|
> do pacote pelo comando `vowt-ux-ui-design sync`. Regra própria deste app fica fora daqui.
|
|
5
5
|
|
|
6
6
|
Este app usa o design system da VOWT. Do pacote @vowt-tech/ui, o app importa os fundamentos,
|
package/guia/VERSAO
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.179.0
|
package/guia/componentes.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Componentes
|
|
2
2
|
|
|
3
|
-
> Gerado do pacote @vowt-tech/ui 0.
|
|
3
|
+
> Gerado do pacote @vowt-tech/ui 0.179.0. Cada linha traz o nome da peça, o import do pacote e
|
|
4
4
|
> a página com o exemplo.
|
|
5
5
|
|
|
6
6
|
Antes de montar uma tela, procure aqui. Cada peça é importada do pacote, como
|
|
@@ -10,7 +10,7 @@ app não copia nem altera a peça: o pedido de mudança vai ao repositório vowt
|
|
|
10
10
|
## Componentes
|
|
11
11
|
|
|
12
12
|
- `accordion`: `import { Accordion, AccordionItem, AccordionTrigger, AccordionPanel } from '@vowt-tech/ui/accordion'`. Página: https://developers.vowt.com.br/accordion
|
|
13
|
-
- `ai-orb`: `import { AiOrb } from '@vowt-tech/ui/ai-orb'`. Página: https://developers.vowt.com.br/ai-orb
|
|
13
|
+
- `ai-orb`: `import { AiOrb, VoiceOrb } from '@vowt-tech/ui/ai-orb'`. Página: https://developers.vowt.com.br/ai-orb
|
|
14
14
|
- `alert-dialog`: `import { ConfirmDialog, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger } from '@vowt-tech/ui/alert-dialog'`. Página: https://developers.vowt.com.br/alert-dialog
|
|
15
15
|
- `alert`: `import { Alert, AlertTitle, AlertDescription, AlertAction } from '@vowt-tech/ui/alert'`. Página: https://developers.vowt.com.br/alert
|
|
16
16
|
- `area-chart`: `import { AreaChart } from '@vowt-tech/ui/area-chart'`. Página: https://developers.vowt.com.br/area-chart
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { MicIcon, MicOffIcon, PauseIcon, PlayIcon, PowerIcon } from 'lucide-react';
|
|
2
5
|
import { cn } from '../lib/utils';
|
|
6
|
+
import { Button } from './button';
|
|
3
7
|
|
|
4
8
|
// Orb da IA, D-769: a bola animada nas cores da IA, azul, violeta e rosa, que mostra a IA pronta
|
|
5
9
|
// para conversar, como no vazio do Assistente de IA e na saudação do Início. Só desenho: sem som,
|
|
6
10
|
// sem microfone e sem clique. Sempre animado; para quem reduz o movimento no sistema, fica parado.
|
|
7
11
|
// O desenho vive na classe `ai-orb` do tema; aqui só entram as medidas que dependem do tamanho.
|
|
8
|
-
//
|
|
12
|
+
// D-866: com `state` e `level`, o mesmo desenho reage a uma conversa por voz; o Voice orb, logo
|
|
13
|
+
// abaixo, junta o orb, a legenda e os controles.
|
|
9
14
|
|
|
10
15
|
/** Medidas do desenho a partir do tamanho: abaixo de 50px, desfoque e pontos menores. */
|
|
11
16
|
function orbVars(size: number) {
|
|
@@ -29,10 +34,15 @@ function orbVars(size: number) {
|
|
|
29
34
|
};
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
export type VoiceOrbState =
|
|
38
|
+
'connecting' | 'listening' | 'thinking' | 'speaking' | 'paused' | 'error';
|
|
39
|
+
|
|
32
40
|
function AiOrb({
|
|
33
41
|
size = 48,
|
|
34
42
|
duration = 20,
|
|
35
43
|
label,
|
|
44
|
+
state,
|
|
45
|
+
level,
|
|
36
46
|
className,
|
|
37
47
|
}: {
|
|
38
48
|
/** Tamanho em px. 48 no vazio da janela, 64 na tela cheia, 80 na saudação do Início. */
|
|
@@ -41,13 +51,19 @@ function AiOrb({
|
|
|
41
51
|
duration?: number;
|
|
42
52
|
/** Nome para leitor de tela, como "VOWT AI Agent". Sem ele, o orb é só enfeite e fica escondido. */
|
|
43
53
|
label?: string;
|
|
54
|
+
/** Estado de uma conversa por voz, D-866: cada um com o seu visual. Sem ele, o orb de sempre. */
|
|
55
|
+
state?: VoiceOrbState;
|
|
56
|
+
/** Nível do som, de 0 a 1, vindo do app. O orb cresce um pouco com a voz. */
|
|
57
|
+
level?: number;
|
|
44
58
|
className?: string;
|
|
45
59
|
}) {
|
|
46
60
|
const { tiny, style } = orbVars(size);
|
|
61
|
+
const clamped = level === undefined ? 0 : Math.min(1, Math.max(0, level));
|
|
47
62
|
return (
|
|
48
63
|
<span
|
|
49
64
|
data-slot="ai-orb"
|
|
50
65
|
data-size={tiny ? 'tiny' : undefined}
|
|
66
|
+
data-state={state}
|
|
51
67
|
role={label ? 'img' : undefined}
|
|
52
68
|
aria-label={label}
|
|
53
69
|
aria-hidden={label ? undefined : true}
|
|
@@ -58,10 +74,186 @@ function AiOrb({
|
|
|
58
74
|
width: size,
|
|
59
75
|
height: size,
|
|
60
76
|
'--ai-orb-duration': `${duration}s`,
|
|
77
|
+
'--ai-orb-level': clamped,
|
|
61
78
|
} as React.CSSProperties
|
|
62
79
|
}
|
|
63
80
|
/>
|
|
64
81
|
);
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
|
|
84
|
+
const STATE_LABELS: Record<VoiceOrbState, string> = {
|
|
85
|
+
connecting: 'Conectando',
|
|
86
|
+
listening: 'Ouvindo',
|
|
87
|
+
thinking: 'Pensando',
|
|
88
|
+
speaking: 'Falando',
|
|
89
|
+
paused: 'Pausado',
|
|
90
|
+
error: 'Erro na conversa',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const VOICE_LABELS = {
|
|
94
|
+
...STATE_LABELS,
|
|
95
|
+
mute: 'Desligar o microfone',
|
|
96
|
+
unmute: 'Ligar o microfone',
|
|
97
|
+
pause: 'Pausar a conversa',
|
|
98
|
+
resume: 'Retomar a conversa',
|
|
99
|
+
end: 'Encerrar a conversa',
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type VoiceOrbLabels = Partial<typeof VOICE_LABELS>;
|
|
103
|
+
|
|
104
|
+
const ORB_SIZE = { sm: 64, default: 96, lg: 128 } as const;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A legenda é anunciada ao leitor de tela só quando para de mudar, e só o trecho novo: com o texto
|
|
108
|
+
* chegando aos poucos, ele não repete a frase inteira a cada palavra.
|
|
109
|
+
*/
|
|
110
|
+
function useCaptionAnnouncement(caption: string | undefined) {
|
|
111
|
+
const [announced, setAnnounced] = React.useState('');
|
|
112
|
+
const last = React.useRef('');
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
const text = caption?.trim() ?? '';
|
|
115
|
+
if (!text) {
|
|
116
|
+
last.current = '';
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
const delta = text.startsWith(last.current) ? text.slice(last.current.length).trim() : text;
|
|
121
|
+
last.current = text;
|
|
122
|
+
if (delta) setAnnounced(delta);
|
|
123
|
+
}, 800);
|
|
124
|
+
return () => clearTimeout(timer);
|
|
125
|
+
}, [caption]);
|
|
126
|
+
return announced;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Voice orb, D-866: a conversa por voz com a IA. O pacote não acessa microfone, áudio nem rede: o
|
|
130
|
+
// app passa o estado, o nível do som e a legenda, e recebe os eventos dos controles. O estado tem
|
|
131
|
+
// nome para o leitor de tela; a legenda ao vivo é anunciada sem repetir o que já foi lido. Para
|
|
132
|
+
// quem reduz o movimento, o orb não cresce nem gira: só troca de visual a cada estado.
|
|
133
|
+
function VoiceOrb({
|
|
134
|
+
state,
|
|
135
|
+
level,
|
|
136
|
+
caption,
|
|
137
|
+
muted = false,
|
|
138
|
+
onMutedChange,
|
|
139
|
+
onPausedChange,
|
|
140
|
+
onEnd,
|
|
141
|
+
label = 'VOWT AI Agent',
|
|
142
|
+
size = 'default',
|
|
143
|
+
labels: customLabels,
|
|
144
|
+
className,
|
|
145
|
+
}: {
|
|
146
|
+
state: VoiceOrbState;
|
|
147
|
+
/** Nível do som de quem fala, de 0 a 1, vindo do app. */
|
|
148
|
+
level?: number;
|
|
149
|
+
/** A legenda ao vivo, como o que a IA está dizendo. */
|
|
150
|
+
caption?: string;
|
|
151
|
+
/** Microfone desligado. */
|
|
152
|
+
muted?: boolean;
|
|
153
|
+
/** Com ele, aparece o botão do microfone. */
|
|
154
|
+
onMutedChange?: (muted: boolean) => void;
|
|
155
|
+
/** Com ele, aparece o botão de pausar e retomar. O app troca o estado para paused e de volta. */
|
|
156
|
+
onPausedChange?: (paused: boolean) => void;
|
|
157
|
+
/** Com ele, aparece o botão de encerrar. */
|
|
158
|
+
onEnd?: () => void;
|
|
159
|
+
/** Nome da IA para o leitor de tela. */
|
|
160
|
+
label?: string;
|
|
161
|
+
size?: 'sm' | 'default' | 'lg';
|
|
162
|
+
/** Textos dos estados e dos botões, para outro idioma. */
|
|
163
|
+
labels?: VoiceOrbLabels;
|
|
164
|
+
className?: string;
|
|
165
|
+
}) {
|
|
166
|
+
const labels = { ...VOICE_LABELS, ...customLabels };
|
|
167
|
+
const paused = state === 'paused';
|
|
168
|
+
const stateLabel = labels[state];
|
|
169
|
+
const announced = useCaptionAnnouncement(caption);
|
|
170
|
+
const buttonSize = size === 'sm' ? 'icon-sm' : size === 'lg' ? 'icon-lg' : 'icon';
|
|
171
|
+
const hasControls = onMutedChange || onPausedChange || onEnd;
|
|
172
|
+
return (
|
|
173
|
+
<div
|
|
174
|
+
data-slot="voice-orb"
|
|
175
|
+
data-state={state}
|
|
176
|
+
className={cn('flex flex-col items-center gap-4 text-center', className)}
|
|
177
|
+
>
|
|
178
|
+
{/* Espaço para o orb crescer com a voz sem empurrar o resto. */}
|
|
179
|
+
<div className="grid place-items-center p-3">
|
|
180
|
+
<AiOrb
|
|
181
|
+
size={ORB_SIZE[size]}
|
|
182
|
+
state={state}
|
|
183
|
+
level={level}
|
|
184
|
+
label={`${label}: ${stateLabel}`}
|
|
185
|
+
/>
|
|
186
|
+
</div>
|
|
187
|
+
<p
|
|
188
|
+
data-slot="voice-orb-state"
|
|
189
|
+
className={cn(
|
|
190
|
+
size === 'lg' ? 'text-body-14-medium' : 'text-body-13-medium',
|
|
191
|
+
state === 'error' ? 'text-text-error' : 'text-muted-foreground',
|
|
192
|
+
)}
|
|
193
|
+
>
|
|
194
|
+
{/* O nome do estado é anunciado quando muda. */}
|
|
195
|
+
<span role="status">{stateLabel}</span>
|
|
196
|
+
</p>
|
|
197
|
+
{caption && (
|
|
198
|
+
<p
|
|
199
|
+
data-slot="voice-orb-caption"
|
|
200
|
+
aria-hidden
|
|
201
|
+
className={cn(
|
|
202
|
+
'max-w-prose text-balance',
|
|
203
|
+
size === 'sm'
|
|
204
|
+
? 'text-body-13'
|
|
205
|
+
: size === 'lg'
|
|
206
|
+
? 'text-heading-18-regular'
|
|
207
|
+
: 'text-body-14',
|
|
208
|
+
)}
|
|
209
|
+
>
|
|
210
|
+
{caption}
|
|
211
|
+
</p>
|
|
212
|
+
)}
|
|
213
|
+
<span className="sr-only" aria-live="polite">
|
|
214
|
+
{announced}
|
|
215
|
+
</span>
|
|
216
|
+
{hasControls && (
|
|
217
|
+
<div data-slot="voice-orb-controls" className="flex items-center gap-2">
|
|
218
|
+
{onMutedChange && (
|
|
219
|
+
<Button
|
|
220
|
+
variant={muted ? 'secondary' : 'outline'}
|
|
221
|
+
size={buttonSize}
|
|
222
|
+
shape="pill"
|
|
223
|
+
aria-pressed={muted}
|
|
224
|
+
aria-label={muted ? labels.unmute : labels.mute}
|
|
225
|
+
onClick={() => onMutedChange(!muted)}
|
|
226
|
+
>
|
|
227
|
+
{muted ? <MicOffIcon /> : <MicIcon />}
|
|
228
|
+
</Button>
|
|
229
|
+
)}
|
|
230
|
+
{onPausedChange && (
|
|
231
|
+
<Button
|
|
232
|
+
variant="outline"
|
|
233
|
+
size={buttonSize}
|
|
234
|
+
shape="pill"
|
|
235
|
+
aria-label={paused ? labels.resume : labels.pause}
|
|
236
|
+
disabled={state === 'connecting' || state === 'error'}
|
|
237
|
+
onClick={() => onPausedChange(!paused)}
|
|
238
|
+
>
|
|
239
|
+
{paused ? <PlayIcon /> : <PauseIcon />}
|
|
240
|
+
</Button>
|
|
241
|
+
)}
|
|
242
|
+
{onEnd && (
|
|
243
|
+
<Button
|
|
244
|
+
variant="destructive"
|
|
245
|
+
size={buttonSize}
|
|
246
|
+
shape="pill"
|
|
247
|
+
aria-label={labels.end}
|
|
248
|
+
onClick={onEnd}
|
|
249
|
+
>
|
|
250
|
+
<PowerIcon />
|
|
251
|
+
</Button>
|
|
252
|
+
)}
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export { AiOrb, VoiceOrb };
|
package/src/styles/theme.css
CHANGED
|
@@ -1624,10 +1624,57 @@
|
|
|
1624
1624
|
&[data-size='tiny']::after {
|
|
1625
1625
|
mask-image: none;
|
|
1626
1626
|
}
|
|
1627
|
+
/* Conversa por voz, D-866: o orb cresce até 15% com o nível do som que o app passa, e cada
|
|
1628
|
+
estado tem o seu visual. Conectando pulsa devagar e meio apagado; pensando gira mais rápido;
|
|
1629
|
+
pausado e erro param e perdem a cor, e o erro ganha o contorno vermelho. */
|
|
1630
|
+
&[data-state] {
|
|
1631
|
+
transform: scale(calc(1 + var(--ai-orb-level, 0) * 0.15));
|
|
1632
|
+
transition:
|
|
1633
|
+
transform var(--duration-fast) ease-out,
|
|
1634
|
+
filter var(--duration-medium) ease-out,
|
|
1635
|
+
opacity var(--duration-medium) ease-out;
|
|
1636
|
+
}
|
|
1637
|
+
&[data-state='connecting'] {
|
|
1638
|
+
animation: ai-orb-pulse 1.6s ease-in-out infinite;
|
|
1639
|
+
}
|
|
1640
|
+
&[data-state='thinking']::before {
|
|
1641
|
+
animation-duration: calc(var(--ai-orb-duration, 20s) / 5);
|
|
1642
|
+
}
|
|
1643
|
+
&[data-state='paused'],
|
|
1644
|
+
&[data-state='error'] {
|
|
1645
|
+
filter: grayscale(1);
|
|
1646
|
+
opacity: 0.6;
|
|
1647
|
+
&::before {
|
|
1648
|
+
animation-play-state: paused;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
&[data-state='error'] {
|
|
1652
|
+
outline: 2px solid var(--destructive);
|
|
1653
|
+
outline-offset: 3px;
|
|
1654
|
+
}
|
|
1627
1655
|
@media (prefers-reduced-motion: reduce) {
|
|
1628
1656
|
&::before {
|
|
1629
1657
|
animation: none;
|
|
1630
1658
|
}
|
|
1659
|
+
&[data-state] {
|
|
1660
|
+
transform: none;
|
|
1661
|
+
transition: none;
|
|
1662
|
+
animation: none;
|
|
1663
|
+
}
|
|
1664
|
+
/* Sem o pulso, conectando fica parado e meio apagado, para não parecer pronto. */
|
|
1665
|
+
&[data-state='connecting'] {
|
|
1666
|
+
opacity: 0.6;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
@keyframes ai-orb-pulse {
|
|
1672
|
+
0%,
|
|
1673
|
+
100% {
|
|
1674
|
+
opacity: 0.5;
|
|
1675
|
+
}
|
|
1676
|
+
50% {
|
|
1677
|
+
opacity: 0.85;
|
|
1631
1678
|
}
|
|
1632
1679
|
}
|
|
1633
1680
|
|