@selectwin/kit 0.1.253 → 0.1.254
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/README.md +83 -69
- package/dist/SelectAttachMenu.d.ts +29 -0
- package/dist/SelectAttachMenu.js +167 -0
- package/dist/SelectAudioRecorder.d.ts +27 -0
- package/dist/SelectAudioRecorder.js +287 -0
- package/dist/SelectChatSendButton.d.ts +14 -0
- package/dist/SelectChatSendButton.js +25 -0
- package/dist/SelectConversation.d.ts +33 -2
- package/dist/SelectConversation.js +127 -83
- package/dist/SelectConversationQuote.d.ts +20 -0
- package/dist/SelectConversationQuote.js +87 -0
- package/dist/SelectConversationReactions.d.ts +31 -0
- package/dist/SelectConversationReactions.js +101 -0
- package/dist/SelectEmojiPicker.d.ts +12 -0
- package/dist/SelectEmojiPicker.js +178 -0
- package/dist/SelectIconTile.d.ts +2 -1
- package/dist/SelectLightbox.d.ts +32 -0
- package/dist/SelectLightbox.js +172 -0
- package/dist/SelectLocale.d.ts +68 -0
- package/dist/SelectLocale.js +140 -0
- package/dist/SelectMail.d.ts +3 -2
- package/dist/SelectMail.js +224 -244
- package/dist/SelectMessageCards.d.ts +150 -0
- package/dist/SelectMessageCards.js +429 -0
- package/dist/SelectMessageTicks.d.ts +7 -0
- package/dist/SelectMessageTicks.js +31 -0
- package/dist/SelectVoiceNote.d.ts +27 -0
- package/dist/SelectVoiceNote.js +245 -0
- package/dist/emojiData.d.ts +33 -0
- package/dist/emojiData.js +103 -0
- package/dist/icons.d.ts +22 -0
- package/dist/icons.js +89 -10
- package/dist/index.d.ts +23 -1
- package/dist/index.js +236 -224
- package/dist/internal/fileKind.d.ts +12 -0
- package/dist/internal/fileKind.js +44 -0
- package/dist/style.css +1 -1
- package/package.json +67 -67
package/README.md
CHANGED
|
@@ -1,69 +1,83 @@
|
|
|
1
|
-
# @selectwin/kit
|
|
2
|
-
|
|
3
|
-
Design system da Selectwin — primitivos React, charts SVG (sem dependência de biblioteca de
|
|
4
|
-
gráficos) e tokens CSS, theme-aware (light/dark).
|
|
5
|
-
|
|
6
|
-
Uso interno da Selectwin. Publicado no npm para facilitar a distribuição entre os apps da casa;
|
|
7
|
-
não há suporte, documentação pública nem garantia de estabilidade de API para terceiros.
|
|
8
|
-
|
|
9
|
-
## Uso
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i @selectwin/kit
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
```tsx
|
|
16
|
-
import '@selectwin/kit/styles.css'; // tokens + estilos (uma vez, no root)
|
|
17
|
-
import { SelectButton, SelectSection } from '@selectwin/kit';
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Idioma (0.1.187): os textos próprios do kit ("Página anterior", "Mais filtros", "Fechar"…) e os números que ele
|
|
21
|
-
formata saem em português. Para inglês, envolva o app no `SelectLocaleProvider`:
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
24
|
-
import { SelectLocaleProvider } from '@selectwin/kit';
|
|
25
|
-
|
|
26
|
-
<SelectLocaleProvider locale="en">{app}</SelectLocaleProvider>; // 'pt-BR' | 'en'
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
A prop de texto do componente (`confirmLabel`, `noun`…) sempre ganha do dicionário.
|
|
30
|
-
|
|
31
|
-
Tom corporativo (0.1.188; arredondado suave no botão desde a 0.1.192, em tudo desde a 0.1.193 e bem suave desde a
|
|
32
|
-
0.1.195): campo e botão com 1rem (`--select-radius`, `--select-radius-button`), card 1.5rem, caixa de dentro e menu
|
|
33
|
-
1rem, item de menu 0.75rem (`--select-radius-sm`); pílula só em selo. Rótulos de KPI
|
|
34
|
-
e cabeçalho de tabela em caixa-alta espaçada. Nos gráficos, cor é situação: verde `--select-chart-paid` = pago, dourado
|
|
35
|
-
`--select-chart-pending` (+ `-edge`) = pendente, `--select-chart-compare` = o período anterior, e os cinzas
|
|
36
|
-
`--select-chart-ramp-1..4` para categoria. O app que quer o visual antigo sobrescreve esses tokens.
|
|
37
|
-
|
|
38
|
-
O card mostra o dado; a explicação vai no tooltip (0.1.196). O "i" `help` está no `SelectSection`, no
|
|
39
|
-
`SelectDataTable`, no `SelectChartCard`, no `SelectKpiCard`, no `SelectListCard`, em cada número do `SelectMiniStats` e
|
|
40
|
-
em cada balde do `SelectBalanceCard`. Na `SelectShareBar`, cada faixa tem o seu tooltip, e a nota da parte vai em
|
|
41
|
-
`tip`; o que o clique faz vai em `selectHint`/`clearHint`, no lugar da linha `hint`.
|
|
42
|
-
|
|
43
|
-
O tutorial flutuante (0.1.232): o `SelectTutorial` é um cartão no canto de baixo à esquerda (o direito é do
|
|
44
|
-
`SelectAssistant`) que abre um vídeo curto, sempre no tema OPOSTO ao do painel, para se destacar — os tokens
|
|
45
|
-
`--select-tutorial-*`, invertidos no bloco do escuro. O vídeo expande para o centro da tela sem recomeçar, e o selo
|
|
46
|
-
"Visto" acende sozinho quando ele termina (`watched` manda, quando vem). Abrir, fechar de vez (`onDismiss`) e guardar o
|
|
47
|
-
que foi visto são de quem usa.
|
|
48
|
-
|
|
49
|
-
A dock da moldura (0.1.233): o `SelectAppDock`, com o `SelectAppDockItem` e o `SelectAppDockSeparator`, é a barra de baixo
|
|
50
|
-
do painel, a `AppDock` que o dashboard-web desenhou. O padrão é a aba que sobe da borda de baixo do painel;
|
|
51
|
-
`variant="floating"` a solta da borda, e `draggable` deixa o usuário levá-la para onde quiser dentro do palco (o ancestral
|
|
52
|
-
posicionado). Ela gruda no centro e nas bordas, a alça anda pelo teclado (as setas, e Home volta) e dois cliques a
|
|
53
|
-
devolvem ao centro de baixo. No celular, ela fica parada embaixo. A posição vem em frações do palco (`null` é a casa), e
|
|
54
|
-
guardar é de quem usa (`position` + `onPositionChange`). Cada item é o alvo inteiro, ícone e nome (`labels` mostra o nome
|
|
55
|
-
embaixo). O item aceso usa `--select-appdock-active` e `--select-appdock-active-ink`, que o app troca pela cor dele.
|
|
56
|
-
|
|
57
|
-
Peer deps: **react**, **react-dom** (obrigatórios); **gsap** (opcional — só componentes animados),
|
|
58
|
-
**react-router-dom** (opcional). Tematização = sobrescrever os tokens CSS `--select-*` / `--sw-*`.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`
|
|
1
|
+
# @selectwin/kit
|
|
2
|
+
|
|
3
|
+
Design system da Selectwin — primitivos React, charts SVG (sem dependência de biblioteca de
|
|
4
|
+
gráficos) e tokens CSS, theme-aware (light/dark).
|
|
5
|
+
|
|
6
|
+
Uso interno da Selectwin. Publicado no npm para facilitar a distribuição entre os apps da casa;
|
|
7
|
+
não há suporte, documentação pública nem garantia de estabilidade de API para terceiros.
|
|
8
|
+
|
|
9
|
+
## Uso
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @selectwin/kit
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import '@selectwin/kit/styles.css'; // tokens + estilos (uma vez, no root)
|
|
17
|
+
import { SelectButton, SelectSection } from '@selectwin/kit';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Idioma (0.1.187): os textos próprios do kit ("Página anterior", "Mais filtros", "Fechar"…) e os números que ele
|
|
21
|
+
formata saem em português. Para inglês, envolva o app no `SelectLocaleProvider`:
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { SelectLocaleProvider } from '@selectwin/kit';
|
|
25
|
+
|
|
26
|
+
<SelectLocaleProvider locale="en">{app}</SelectLocaleProvider>; // 'pt-BR' | 'en'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
A prop de texto do componente (`confirmLabel`, `noun`…) sempre ganha do dicionário.
|
|
30
|
+
|
|
31
|
+
Tom corporativo (0.1.188; arredondado suave no botão desde a 0.1.192, em tudo desde a 0.1.193 e bem suave desde a
|
|
32
|
+
0.1.195): campo e botão com 1rem (`--select-radius`, `--select-radius-button`), card 1.5rem, caixa de dentro e menu
|
|
33
|
+
1rem, item de menu 0.75rem (`--select-radius-sm`); pílula só em selo. Rótulos de KPI
|
|
34
|
+
e cabeçalho de tabela em caixa-alta espaçada. Nos gráficos, cor é situação: verde `--select-chart-paid` = pago, dourado
|
|
35
|
+
`--select-chart-pending` (+ `-edge`) = pendente, `--select-chart-compare` = o período anterior, e os cinzas
|
|
36
|
+
`--select-chart-ramp-1..4` para categoria. O app que quer o visual antigo sobrescreve esses tokens.
|
|
37
|
+
|
|
38
|
+
O card mostra o dado; a explicação vai no tooltip (0.1.196). O "i" `help` está no `SelectSection`, no
|
|
39
|
+
`SelectDataTable`, no `SelectChartCard`, no `SelectKpiCard`, no `SelectListCard`, em cada número do `SelectMiniStats` e
|
|
40
|
+
em cada balde do `SelectBalanceCard`. Na `SelectShareBar`, cada faixa tem o seu tooltip, e a nota da parte vai em
|
|
41
|
+
`tip`; o que o clique faz vai em `selectHint`/`clearHint`, no lugar da linha `hint`.
|
|
42
|
+
|
|
43
|
+
O tutorial flutuante (0.1.232): o `SelectTutorial` é um cartão no canto de baixo à esquerda (o direito é do
|
|
44
|
+
`SelectAssistant`) que abre um vídeo curto, sempre no tema OPOSTO ao do painel, para se destacar — os tokens
|
|
45
|
+
`--select-tutorial-*`, invertidos no bloco do escuro. O vídeo expande para o centro da tela sem recomeçar, e o selo
|
|
46
|
+
"Visto" acende sozinho quando ele termina (`watched` manda, quando vem). Abrir, fechar de vez (`onDismiss`) e guardar o
|
|
47
|
+
que foi visto são de quem usa.
|
|
48
|
+
|
|
49
|
+
A dock da moldura (0.1.233): o `SelectAppDock`, com o `SelectAppDockItem` e o `SelectAppDockSeparator`, é a barra de baixo
|
|
50
|
+
do painel, a `AppDock` que o dashboard-web desenhou. O padrão é a aba que sobe da borda de baixo do painel;
|
|
51
|
+
`variant="floating"` a solta da borda, e `draggable` deixa o usuário levá-la para onde quiser dentro do palco (o ancestral
|
|
52
|
+
posicionado). Ela gruda no centro e nas bordas, a alça anda pelo teclado (as setas, e Home volta) e dois cliques a
|
|
53
|
+
devolvem ao centro de baixo. No celular, ela fica parada embaixo. A posição vem em frações do palco (`null` é a casa), e
|
|
54
|
+
guardar é de quem usa (`position` + `onPositionChange`). Cada item é o alvo inteiro, ícone e nome (`labels` mostra o nome
|
|
55
|
+
embaixo). O item aceso usa `--select-appdock-active` e `--select-appdock-active-ink`, que o app troca pela cor dele.
|
|
56
|
+
|
|
57
|
+
Peer deps: **react**, **react-dom** (obrigatórios); **gsap** (opcional — só componentes animados),
|
|
58
|
+
**react-router-dom** (opcional). Tematização = sobrescrever os tokens CSS `--select-*` / `--sw-*`.
|
|
59
|
+
|
|
60
|
+
As peças do chat (0.1.254, o inbox do WhatsApp da SWMX): o `SelectConversationBubble` ganha a citação (`quote`, o
|
|
61
|
+
`SelectConversationQuote`, que também é a faixa "Respondendo a…" do compositor), a hora e o estado DENTRO do balão
|
|
62
|
+
(`stamp`, com o `SelectMessageTicks`: relógio, ✓, ✓✓, ✓✓ na cor da marca, alerta), as reações presas na borda (`reactions`,
|
|
63
|
+
o `SelectConversationReactions`), a barra de ações (`actions`), o tom do que não saiu (`tone`) e a borda fina dos cartões
|
|
64
|
+
(`flush`); e o `SelectUnreadDivider` ("2 mensagens novas"). Em volta: o `SelectReactionPicker` (as 6 rápidas e o "+"), o
|
|
65
|
+
`SelectEmojiPicker` (a lista curada do kit, sem biblioteca, com a busca em português e em inglês), o `SelectVoiceNote` (a
|
|
66
|
+
onda, a posição pelo teclado, 1× · 1,5× · 2×), o `SelectAudioRecorder` (o `MediaRecorder`, ogg/opus quando o navegador
|
|
67
|
+
grava; o `onSend` entrega o arquivo e o tipo), o `SelectChatSendButton` (enviar ou gravar), os cartões
|
|
68
|
+
(`SelectLocationCard`, `SelectContactCard`, `SelectTemplateMessage` com as variáveis em destaque, `SelectInteractiveMessage`
|
|
69
|
+
com os botões, a lista e o link, `SelectDocumentCard`, `SelectMediaAlbum`), o `SelectLightbox` e o `SelectAttachMenu`
|
|
70
|
+
(popover no computador, folha de baixo no celular). O balão de quem envia sai do acento do app — na SWMX, o petróleo claro,
|
|
71
|
+
não o verde do WhatsApp; os tons do chat se trocam pelos `--select-chat-*` (a lista está no `select.css`, no bloco da
|
|
72
|
+
0.1.254).
|
|
73
|
+
|
|
74
|
+
O vazio das listas tem módulo próprio (0.1.234): o `SelectTableEmpty` só depende do React, e a `SelectCardGrid` não
|
|
75
|
+
leva mais a tabela nem o GSAP. O teste `SelectTableEmpty.test.ts` trava esse grafo de imports.
|
|
76
|
+
|
|
77
|
+
## Build
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm run build # → dist/index.js (o barril) + um módulo ESM por componente + dist/style.css + os .d.ts
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`npm publish` roda `prepublishOnly` (= build) e publica só `dist/` (sem sourcemaps).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SelectIconTileTone } from './SelectIconTile';
|
|
3
|
+
import { SelectPlacement } from './SelectPopover';
|
|
4
|
+
export interface SelectAttachOption {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
/** A dica sob o nome (só no popover): "PDF, planilha, até 100 MB". */
|
|
8
|
+
hint?: string;
|
|
9
|
+
icon: ReactNode;
|
|
10
|
+
/** A cor do quadradinho (o `SelectIconTile`): `critical` o documento, `accent` a foto, `violet` o áudio… */
|
|
11
|
+
tone?: SelectIconTileTone;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface SelectAttachMenuProps {
|
|
15
|
+
open: boolean;
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
/** O botão que abre (o clipe). Ele alterna o `open`. */
|
|
18
|
+
activator: ReactNode;
|
|
19
|
+
options: SelectAttachOption[];
|
|
20
|
+
onPick: (id: string) => void;
|
|
21
|
+
/** O título da folha do celular (padrão: "Anexar"). */
|
|
22
|
+
title?: string;
|
|
23
|
+
/** A nota miúda no pé da folha. */
|
|
24
|
+
note?: ReactNode;
|
|
25
|
+
variant?: 'auto' | 'popover' | 'sheet';
|
|
26
|
+
/** De onde o popover abre (padrão: para cima, alinhado ao começo do clipe). */
|
|
27
|
+
placement?: SelectPlacement;
|
|
28
|
+
}
|
|
29
|
+
export declare function SelectAttachMenu({ open, onClose, activator, options, onPick, title, note, variant, placement }: SelectAttachMenuProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
import { useSelectMessages as e } from "./SelectLocale.js";
|
|
3
|
+
import { useMatchMedia as t } from "./internal/useMatchMedia.js";
|
|
4
|
+
import { useFocusTrap as n } from "./internal/useFocusTrap.js";
|
|
5
|
+
import { LayerProvider as r, isTopLayer as i, openLayer as a, useParentLayer as o } from "./internal/layers.js";
|
|
6
|
+
import { detectSelectTheme as s } from "./detectSelectTheme.js";
|
|
7
|
+
import { SelectPopover as c } from "./SelectPopover.js";
|
|
8
|
+
import { SelectIconTile as l } from "./SelectIconTile.js";
|
|
9
|
+
import { useEffect as u, useRef as d, useState as f } from "react";
|
|
10
|
+
import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
11
|
+
import { createPortal as g } from "react-dom";
|
|
12
|
+
//#region src/SelectAttachMenu.tsx
|
|
13
|
+
var _ = "(max-width: 47.9375em)";
|
|
14
|
+
function v(e) {
|
|
15
|
+
return (t) => {
|
|
16
|
+
var n;
|
|
17
|
+
let r = Array.from(t.currentTarget.querySelectorAll("[data-attach-option]:not(:disabled)")), i = r.indexOf(document.activeElement);
|
|
18
|
+
if (i < 0) return;
|
|
19
|
+
let a = t.key === "ArrowRight" ? i + 1 : t.key === "ArrowLeft" ? i - 1 : t.key === "ArrowDown" ? i + e : t.key === "ArrowUp" ? i - e : t.key === "Home" ? 0 : t.key === "End" ? r.length - 1 : null;
|
|
20
|
+
a != null && (t.preventDefault(), (n = r[Math.max(0, Math.min(r.length - 1, a))]) == null || n.focus());
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function y({ options: e, onPick: t, columns: n, size: r }) {
|
|
24
|
+
let i = v(n), a = d(null);
|
|
25
|
+
return u(() => {
|
|
26
|
+
var e;
|
|
27
|
+
(e = a.current) == null || (e = e.querySelector("[data-attach-option]:not(:disabled)")) == null || e.focus({ preventScroll: !0 });
|
|
28
|
+
}, []), /* @__PURE__ */ m("div", {
|
|
29
|
+
ref: a,
|
|
30
|
+
className: `select-attach__grid select-attach__grid--${r}`,
|
|
31
|
+
onKeyDown: i,
|
|
32
|
+
children: e.map((e) => /* @__PURE__ */ h("button", {
|
|
33
|
+
type: "button",
|
|
34
|
+
role: "menuitem",
|
|
35
|
+
className: "select-attach__option",
|
|
36
|
+
"data-attach-option": !0,
|
|
37
|
+
disabled: e.disabled,
|
|
38
|
+
onClick: () => t(e.id),
|
|
39
|
+
children: [/* @__PURE__ */ m(l, {
|
|
40
|
+
icon: e.icon,
|
|
41
|
+
tone: e.tone ?? "neutral",
|
|
42
|
+
size: r === "lg" ? "lg" : "md",
|
|
43
|
+
className: "select-attach__tile"
|
|
44
|
+
}), /* @__PURE__ */ h("span", {
|
|
45
|
+
className: "select-attach__text",
|
|
46
|
+
children: [/* @__PURE__ */ m("span", {
|
|
47
|
+
className: "select-attach__label",
|
|
48
|
+
children: e.label
|
|
49
|
+
}), e.hint && r === "md" ? /* @__PURE__ */ m("span", {
|
|
50
|
+
className: "select-attach__hint",
|
|
51
|
+
children: e.hint
|
|
52
|
+
}) : null]
|
|
53
|
+
})]
|
|
54
|
+
}, e.id))
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function b({ open: n, onClose: r, activator: i, options: a, onPick: o, title: s, note: l, variant: u = "auto", placement: d = "top-start" }) {
|
|
58
|
+
let f = e().chat, p = t(u === "auto" ? _ : void 0), g = u === "sheet" || u === "auto" && p, v = (e) => {
|
|
59
|
+
o(e), r();
|
|
60
|
+
};
|
|
61
|
+
return g ? /* @__PURE__ */ m(x, {
|
|
62
|
+
open: n,
|
|
63
|
+
onClose: r,
|
|
64
|
+
activator: i,
|
|
65
|
+
title: s ?? f.attach,
|
|
66
|
+
note: l,
|
|
67
|
+
children: /* @__PURE__ */ m(y, {
|
|
68
|
+
options: a,
|
|
69
|
+
onPick: v,
|
|
70
|
+
columns: 3,
|
|
71
|
+
size: "lg"
|
|
72
|
+
})
|
|
73
|
+
}) : /* @__PURE__ */ m(c, {
|
|
74
|
+
active: n,
|
|
75
|
+
onClose: r,
|
|
76
|
+
activator: i,
|
|
77
|
+
placement: d,
|
|
78
|
+
role: "menu",
|
|
79
|
+
children: /* @__PURE__ */ h("div", {
|
|
80
|
+
className: "select-attach",
|
|
81
|
+
role: "group",
|
|
82
|
+
"aria-label": s ?? f.attach,
|
|
83
|
+
children: [/* @__PURE__ */ m(y, {
|
|
84
|
+
options: a,
|
|
85
|
+
onPick: v,
|
|
86
|
+
columns: 2,
|
|
87
|
+
size: "md"
|
|
88
|
+
}), l ? /* @__PURE__ */ m("div", {
|
|
89
|
+
className: "select-attach__note",
|
|
90
|
+
children: l
|
|
91
|
+
}) : null]
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function x({ open: t, onClose: c, activator: l, title: _, note: v, children: y }) {
|
|
96
|
+
let b = e().chat, x = d(null), S = d(null), [C] = f(() => ({})), w = o(), [T, E] = f("light"), D = d(c);
|
|
97
|
+
return D.current = c, u(() => {
|
|
98
|
+
if (!t) return;
|
|
99
|
+
E(s(x.current));
|
|
100
|
+
let e = document.activeElement instanceof HTMLElement && document.activeElement !== document.body ? document.activeElement : null, n = a(C, w), r = (e) => {
|
|
101
|
+
e.key === "Escape" && !e.defaultPrevented && i(C) && D.current();
|
|
102
|
+
};
|
|
103
|
+
document.addEventListener("keydown", r);
|
|
104
|
+
let o = document.body.style.overflow;
|
|
105
|
+
return document.body.style.overflow = "hidden", () => {
|
|
106
|
+
n(), document.removeEventListener("keydown", r), document.body.style.overflow = o, e != null && e.isConnected && e.focus({ preventScroll: !0 });
|
|
107
|
+
};
|
|
108
|
+
}, [
|
|
109
|
+
t,
|
|
110
|
+
C,
|
|
111
|
+
w
|
|
112
|
+
]), n(t, S, { initialFocus: !1 }), /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m("span", {
|
|
113
|
+
className: "select-pop__trigger",
|
|
114
|
+
ref: x,
|
|
115
|
+
children: l
|
|
116
|
+
}), t && typeof document < "u" ? g(/* @__PURE__ */ h("div", {
|
|
117
|
+
className: "select select-attachsheet",
|
|
118
|
+
"data-theme": T,
|
|
119
|
+
children: [/* @__PURE__ */ m("div", {
|
|
120
|
+
className: "select-attachsheet__scrim",
|
|
121
|
+
onClick: c,
|
|
122
|
+
"aria-hidden": "true"
|
|
123
|
+
}), /* @__PURE__ */ m("div", {
|
|
124
|
+
ref: S,
|
|
125
|
+
className: "select-attachsheet__panel",
|
|
126
|
+
role: "dialog",
|
|
127
|
+
"aria-modal": "true",
|
|
128
|
+
"aria-label": _,
|
|
129
|
+
tabIndex: -1,
|
|
130
|
+
children: /* @__PURE__ */ h(r, {
|
|
131
|
+
value: C,
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ m("span", {
|
|
134
|
+
className: "select-attachsheet__handle",
|
|
135
|
+
"aria-hidden": "true"
|
|
136
|
+
}),
|
|
137
|
+
/* @__PURE__ */ h("div", {
|
|
138
|
+
className: "select-attachsheet__head",
|
|
139
|
+
children: [/* @__PURE__ */ m("span", {
|
|
140
|
+
className: "select-attachsheet__title",
|
|
141
|
+
children: _
|
|
142
|
+
}), /* @__PURE__ */ m("button", {
|
|
143
|
+
type: "button",
|
|
144
|
+
className: "select-attachsheet__close",
|
|
145
|
+
onClick: c,
|
|
146
|
+
children: b.close
|
|
147
|
+
})]
|
|
148
|
+
}),
|
|
149
|
+
/* @__PURE__ */ m("div", {
|
|
150
|
+
className: "select-attach",
|
|
151
|
+
role: "menu",
|
|
152
|
+
"aria-label": _,
|
|
153
|
+
children: y
|
|
154
|
+
}),
|
|
155
|
+
v ? /* @__PURE__ */ m("div", {
|
|
156
|
+
className: "select-attachsheet__note",
|
|
157
|
+
children: v
|
|
158
|
+
}) : null
|
|
159
|
+
]
|
|
160
|
+
})
|
|
161
|
+
})]
|
|
162
|
+
}), document.body) : null] });
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { b as SelectAttachMenu };
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=SelectAttachMenu.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface SelectAudioRecording {
|
|
2
|
+
blob: Blob;
|
|
3
|
+
/** O tipo que o navegador gravou ("audio/ogg;codecs=opus", "audio/webm;codecs=opus"…). */
|
|
4
|
+
mimeType: string;
|
|
5
|
+
/** Em segundos. */
|
|
6
|
+
duration: number;
|
|
7
|
+
/** A onda: 64 alturas de 0 a 1. */
|
|
8
|
+
peaks: number[];
|
|
9
|
+
}
|
|
10
|
+
export interface SelectAudioRecorderProps {
|
|
11
|
+
onSend: (audio: SelectAudioRecording) => void;
|
|
12
|
+
/** O ✕ e a lixeira: a gravação vai fora e o microfone é solto. */
|
|
13
|
+
onDiscard: () => void;
|
|
14
|
+
/** Começa a gravar ao aparecer (padrão: sim). */
|
|
15
|
+
autoStart?: boolean;
|
|
16
|
+
/** O teto em segundos: ao chegar, pausa (padrão: 900, 15 min). */
|
|
17
|
+
maxDuration?: number;
|
|
18
|
+
/** Os formatos, na ordem de preferência. */
|
|
19
|
+
mimeTypes?: readonly string[];
|
|
20
|
+
/** Quantas barras ao vivo (padrão: 48). */
|
|
21
|
+
bars?: number;
|
|
22
|
+
}
|
|
23
|
+
export type SelectAudioRecorderStatus = 'idle' | 'requesting' | 'recording' | 'paused' | 'sending' | 'denied' | 'nomic' | 'unsupported' | 'failed';
|
|
24
|
+
export declare const SELECT_AUDIO_MIME_TYPES: readonly string[];
|
|
25
|
+
/** O navegador grava áudio? (o `MediaRecorder` e o pedido do microfone) */
|
|
26
|
+
export declare function canRecordAudio(): boolean;
|
|
27
|
+
export declare function SelectAudioRecorder({ onSend, onDiscard, autoStart, maxDuration, mimeTypes, bars, }: SelectAudioRecorderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
import { SelectButton as e } from "./SelectButton.js";
|
|
3
|
+
import { CloseIcon as t, MicrophoneIcon as n, TrashIcon as r, WarningIcon as i } from "./icons.js";
|
|
4
|
+
import { useSelectMessages as a } from "./SelectLocale.js";
|
|
5
|
+
import { formatVoiceTime as o } from "./SelectVoiceNote.js";
|
|
6
|
+
import { SelectChatSendButton as s } from "./SelectChatSendButton.js";
|
|
7
|
+
import { useCallback as c, useEffect as ee, useRef as l, useState as u } from "react";
|
|
8
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
9
|
+
//#region src/SelectAudioRecorder.tsx
|
|
10
|
+
var p = [
|
|
11
|
+
"audio/ogg;codecs=opus",
|
|
12
|
+
"audio/webm;codecs=opus",
|
|
13
|
+
"audio/mp4",
|
|
14
|
+
"audio/webm"
|
|
15
|
+
], m = 100, h = 64;
|
|
16
|
+
function g() {
|
|
17
|
+
var e;
|
|
18
|
+
return typeof window < "u" && window.MediaRecorder !== void 0 && !!((e = navigator.mediaDevices) != null && e.getUserMedia);
|
|
19
|
+
}
|
|
20
|
+
function _(e) {
|
|
21
|
+
let t = typeof window < "u" ? window.MediaRecorder : void 0;
|
|
22
|
+
if (t && typeof t.isTypeSupported == "function") return e.find((e) => {
|
|
23
|
+
try {
|
|
24
|
+
return t.isTypeSupported(e);
|
|
25
|
+
} catch {
|
|
26
|
+
return !1;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function v(e, t) {
|
|
31
|
+
if (!e.length) return [];
|
|
32
|
+
let n = [];
|
|
33
|
+
for (let r = 0; r < t; r++) {
|
|
34
|
+
let i = Math.floor(r * e.length / t), a = Math.max(i + 1, Math.floor((r + 1) * e.length / t)), o = 0;
|
|
35
|
+
for (let t = i; t < a && t < e.length; t++) o = Math.max(o, e[t] ?? 0);
|
|
36
|
+
n.push(Math.round(o * 100) / 100);
|
|
37
|
+
}
|
|
38
|
+
return n;
|
|
39
|
+
}
|
|
40
|
+
function y({ onSend: y, onDiscard: b, autoStart: x = !0, maxDuration: S = 900, mimeTypes: C = p, bars: w = 48 }) {
|
|
41
|
+
let T = a().chat, E = Math.max(8, Math.floor(w)), [D, O] = u("idle"), [k, A] = u(0), [j, M] = u(() => Array.from({ length: E }, () => 0)), N = l(null), P = l(null), F = l([]), I = l(null), L = l(null), R = l(void 0), z = l(0), B = l(0), V = l([]), H = l(!0), U = l(0), W = l(D);
|
|
42
|
+
W.current = D;
|
|
43
|
+
let G = l({
|
|
44
|
+
onSend: y,
|
|
45
|
+
onDiscard: b,
|
|
46
|
+
maxDuration: S
|
|
47
|
+
});
|
|
48
|
+
G.current = {
|
|
49
|
+
onSend: y,
|
|
50
|
+
onDiscard: b,
|
|
51
|
+
maxDuration: S
|
|
52
|
+
};
|
|
53
|
+
let K = () => typeof performance < "u" ? performance.now() : Date.now(), q = c(() => {
|
|
54
|
+
var e;
|
|
55
|
+
U.current += 1, clearInterval(R.current), R.current = void 0;
|
|
56
|
+
let t = P.current;
|
|
57
|
+
if (P.current = null, t && (t.ondataavailable = null, t.onerror = null, t.state !== "inactive")) try {
|
|
58
|
+
t.stop();
|
|
59
|
+
} catch {}
|
|
60
|
+
(e = N.current) == null || e.getTracks().forEach((e) => e.stop()), N.current = null, L.current = null;
|
|
61
|
+
let n = I.current;
|
|
62
|
+
I.current = null, n && n.state !== "closed" && n.close().catch(() => void 0);
|
|
63
|
+
}, []), J = () => {
|
|
64
|
+
let e = L.current;
|
|
65
|
+
if (!e) return .08 + Math.random() * .1;
|
|
66
|
+
let t = new Uint8Array(e.fftSize);
|
|
67
|
+
e.getByteTimeDomainData(t);
|
|
68
|
+
let n = 0;
|
|
69
|
+
for (let e = 0; e < t.length; e++) {
|
|
70
|
+
let r = ((t[e] ?? 128) - 128) / 128;
|
|
71
|
+
n += r * r;
|
|
72
|
+
}
|
|
73
|
+
return Math.min(1, Math.sqrt(n / t.length) * 3.2);
|
|
74
|
+
}, Y = c(() => {
|
|
75
|
+
let e = P.current;
|
|
76
|
+
if (e && W.current === "recording") {
|
|
77
|
+
try {
|
|
78
|
+
e.pause();
|
|
79
|
+
} catch {}
|
|
80
|
+
B.current += K() - z.current, A(B.current), O("paused");
|
|
81
|
+
}
|
|
82
|
+
}, []), X = c(() => {
|
|
83
|
+
clearInterval(R.current), R.current = setInterval(() => {
|
|
84
|
+
if (W.current !== "recording") return;
|
|
85
|
+
let e = B.current + (K() - z.current);
|
|
86
|
+
A(e);
|
|
87
|
+
let t = J();
|
|
88
|
+
V.current.push(t), M((e) => [...e.slice(1), t]), e >= G.current.maxDuration * 1e3 && Y();
|
|
89
|
+
}, m);
|
|
90
|
+
}, [Y]), Z = c(async () => {
|
|
91
|
+
if (!g()) {
|
|
92
|
+
O("unsupported");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
q(), F.current = [], V.current = [], B.current = 0, A(0), M(Array.from({ length: E }, () => 0)), O("requesting");
|
|
96
|
+
let e = U.current, t;
|
|
97
|
+
try {
|
|
98
|
+
t = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
99
|
+
} catch (t) {
|
|
100
|
+
if (!H.current || e !== U.current) return;
|
|
101
|
+
let n = t == null ? void 0 : t.name;
|
|
102
|
+
O(n === "NotAllowedError" || n === "SecurityError" ? "denied" : n === "NotFoundError" || n === "OverconstrainedError" ? "nomic" : "failed");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!H.current || e !== U.current) {
|
|
106
|
+
t.getTracks().forEach((e) => e.stop());
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
N.current = t;
|
|
110
|
+
let n;
|
|
111
|
+
try {
|
|
112
|
+
let e = _(C);
|
|
113
|
+
n = e ? new MediaRecorder(t, { mimeType: e }) : new MediaRecorder(t);
|
|
114
|
+
} catch {
|
|
115
|
+
q(), O("failed");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
n.ondataavailable = (e) => {
|
|
119
|
+
e.data && e.data.size > 0 && F.current.push(e.data);
|
|
120
|
+
}, n.onerror = () => {
|
|
121
|
+
q(), H.current && O("failed");
|
|
122
|
+
}, P.current = n;
|
|
123
|
+
try {
|
|
124
|
+
let e = window.AudioContext ?? window.webkitAudioContext;
|
|
125
|
+
if (e) {
|
|
126
|
+
let n = new e(), r = n.createAnalyser();
|
|
127
|
+
r.fftSize = 512, n.createMediaStreamSource(t).connect(r), I.current = n, L.current = r;
|
|
128
|
+
}
|
|
129
|
+
} catch {}
|
|
130
|
+
n.start(250), z.current = K(), O("recording"), X();
|
|
131
|
+
}, [
|
|
132
|
+
q,
|
|
133
|
+
E,
|
|
134
|
+
C,
|
|
135
|
+
X
|
|
136
|
+
]), te = () => {
|
|
137
|
+
let e = P.current;
|
|
138
|
+
if (e && D === "paused") {
|
|
139
|
+
try {
|
|
140
|
+
e.resume();
|
|
141
|
+
} catch {}
|
|
142
|
+
z.current = K(), O("recording");
|
|
143
|
+
}
|
|
144
|
+
}, ne = async () => {
|
|
145
|
+
var e;
|
|
146
|
+
let t = P.current;
|
|
147
|
+
if (!t || D !== "recording" && D !== "paused") return;
|
|
148
|
+
let n = D === "recording" ? B.current + (K() - z.current) : B.current;
|
|
149
|
+
O("sending"), clearInterval(R.current), await new Promise((e) => {
|
|
150
|
+
if (t.state === "inactive") {
|
|
151
|
+
e();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
t.addEventListener("stop", () => e(), { once: !0 });
|
|
155
|
+
try {
|
|
156
|
+
t.stop();
|
|
157
|
+
} catch {
|
|
158
|
+
e();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
let r = t.mimeType || ((e = F.current[0]) == null ? void 0 : e.type) || "audio/webm", i = new Blob(F.current, { type: r }), a = v(V.current, h);
|
|
162
|
+
q(), H.current && G.current.onSend({
|
|
163
|
+
blob: i,
|
|
164
|
+
mimeType: r,
|
|
165
|
+
duration: Math.round(n / 100) / 10,
|
|
166
|
+
peaks: a
|
|
167
|
+
});
|
|
168
|
+
}, Q = () => {
|
|
169
|
+
q(), G.current.onDiscard();
|
|
170
|
+
};
|
|
171
|
+
if (ee(() => (H.current = !0, x && Z(), () => {
|
|
172
|
+
H.current = !1, q();
|
|
173
|
+
}), []), D === "denied" || D === "nomic" || D === "unsupported" || D === "failed") {
|
|
174
|
+
let n = D === "denied" ? T.recDenied : D === "nomic" ? T.recNoMic : D === "unsupported" ? T.recUnsupported : T.recFailed;
|
|
175
|
+
return /* @__PURE__ */ f("div", {
|
|
176
|
+
className: "select-recorder select-recorder--blocked",
|
|
177
|
+
role: "group",
|
|
178
|
+
"aria-label": T.recorder,
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ d("span", {
|
|
181
|
+
className: "select-recorder__icon",
|
|
182
|
+
"aria-hidden": "true",
|
|
183
|
+
children: /* @__PURE__ */ d(i, {})
|
|
184
|
+
}),
|
|
185
|
+
/* @__PURE__ */ d("span", {
|
|
186
|
+
className: "select-recorder__message",
|
|
187
|
+
role: "alert",
|
|
188
|
+
children: n
|
|
189
|
+
}),
|
|
190
|
+
D === "unsupported" ? null : /* @__PURE__ */ d(e, {
|
|
191
|
+
variant: "secondary",
|
|
192
|
+
size: "sm",
|
|
193
|
+
inline: !0,
|
|
194
|
+
onClick: () => void Z(),
|
|
195
|
+
children: T.retry
|
|
196
|
+
}),
|
|
197
|
+
/* @__PURE__ */ d("button", {
|
|
198
|
+
type: "button",
|
|
199
|
+
className: "select-recorder__btn",
|
|
200
|
+
onClick: Q,
|
|
201
|
+
"aria-label": T.close,
|
|
202
|
+
title: T.close,
|
|
203
|
+
children: /* @__PURE__ */ d(t, {})
|
|
204
|
+
})
|
|
205
|
+
]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
let $ = D === "recording" || D === "paused", re = D === "recording" ? T.recording : D === "paused" ? T.recPaused : D === "requesting" ? T.recRequesting : "";
|
|
209
|
+
return /* @__PURE__ */ f("div", {
|
|
210
|
+
className: `select-recorder select-recorder--${D}`,
|
|
211
|
+
role: "group",
|
|
212
|
+
"aria-label": T.recorder,
|
|
213
|
+
children: [
|
|
214
|
+
/* @__PURE__ */ d("button", {
|
|
215
|
+
type: "button",
|
|
216
|
+
className: "select-recorder__btn select-recorder__discard",
|
|
217
|
+
onClick: Q,
|
|
218
|
+
"aria-label": T.recDiscard,
|
|
219
|
+
title: T.recDiscard,
|
|
220
|
+
children: /* @__PURE__ */ d(r, {})
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ d("span", {
|
|
223
|
+
className: "select-recorder__dot",
|
|
224
|
+
"aria-hidden": "true"
|
|
225
|
+
}),
|
|
226
|
+
D === "requesting" ? /* @__PURE__ */ d("span", {
|
|
227
|
+
className: "select-recorder__wait",
|
|
228
|
+
children: T.recRequesting
|
|
229
|
+
}) : /* @__PURE__ */ d("span", {
|
|
230
|
+
className: "select-recorder__time",
|
|
231
|
+
role: "timer",
|
|
232
|
+
"aria-label": o(k / 1e3),
|
|
233
|
+
children: o(k / 1e3)
|
|
234
|
+
}),
|
|
235
|
+
/* @__PURE__ */ d("span", {
|
|
236
|
+
className: "select-recorder__bars",
|
|
237
|
+
"aria-hidden": "true",
|
|
238
|
+
children: j.map((e, t) => /* @__PURE__ */ d("span", {
|
|
239
|
+
className: "select-recorder__bar",
|
|
240
|
+
style: { height: `${Math.round(Math.max(.1, e) * 100)}%` }
|
|
241
|
+
}, t))
|
|
242
|
+
}),
|
|
243
|
+
/* @__PURE__ */ d("span", {
|
|
244
|
+
className: "select-visually-hidden",
|
|
245
|
+
"aria-live": "polite",
|
|
246
|
+
children: re
|
|
247
|
+
}),
|
|
248
|
+
/* @__PURE__ */ d("button", {
|
|
249
|
+
type: "button",
|
|
250
|
+
className: "select-recorder__btn select-recorder__pause",
|
|
251
|
+
onClick: D === "idle" ? () => void Z() : D === "paused" ? te : Y,
|
|
252
|
+
disabled: !$ && D !== "idle",
|
|
253
|
+
"aria-label": D === "idle" ? T.record : D === "paused" ? T.recResume : T.recPause,
|
|
254
|
+
title: D === "idle" ? T.record : D === "paused" ? T.recResume : T.recPause,
|
|
255
|
+
children: D === "paused" || D === "idle" ? /* @__PURE__ */ d(n, {}) : /* @__PURE__ */ f("svg", {
|
|
256
|
+
viewBox: "0 0 24 24",
|
|
257
|
+
fill: "currentColor",
|
|
258
|
+
"aria-hidden": "true",
|
|
259
|
+
children: [/* @__PURE__ */ d("rect", {
|
|
260
|
+
x: "6.5",
|
|
261
|
+
y: "5",
|
|
262
|
+
width: "4",
|
|
263
|
+
height: "14",
|
|
264
|
+
rx: "1.2"
|
|
265
|
+
}), /* @__PURE__ */ d("rect", {
|
|
266
|
+
x: "13.5",
|
|
267
|
+
y: "5",
|
|
268
|
+
width: "4",
|
|
269
|
+
height: "14",
|
|
270
|
+
rx: "1.2"
|
|
271
|
+
})]
|
|
272
|
+
})
|
|
273
|
+
}),
|
|
274
|
+
/* @__PURE__ */ d(s, {
|
|
275
|
+
mode: "send",
|
|
276
|
+
label: T.recSend,
|
|
277
|
+
onClick: () => void ne(),
|
|
278
|
+
disabled: !$,
|
|
279
|
+
busy: D === "sending"
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
export { p as SELECT_AUDIO_MIME_TYPES, y as SelectAudioRecorder, g as canRecordAudio };
|
|
286
|
+
|
|
287
|
+
//# sourceMappingURL=SelectAudioRecorder.js.map
|