@wrrdev/fenix-ui 1.1.13 → 1.1.15
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 +6 -5
- package/dist/components/autocomplete/autocomplete.d.ts +11 -5
- package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
- package/dist/components/autocomplete/autocomplete.js +18 -2
- package/dist/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/components/button/button.d.ts +15 -0
- package/dist/components/button/button.d.ts.map +1 -1
- package/dist/components/button/button.js +20 -1
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/checkbox/checkbox.d.ts +20 -4
- package/dist/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/checkbox.js +39 -2
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/datepicker/datepicker.d.ts +16 -2
- package/dist/components/datepicker/datepicker.d.ts.map +1 -1
- package/dist/components/datepicker/datepicker.js +46 -2
- package/dist/components/datepicker/datepicker.js.map +1 -1
- package/dist/components/editor/commands.d.ts +27 -0
- package/dist/components/editor/commands.d.ts.map +1 -0
- package/dist/components/editor/commands.js +235 -0
- package/dist/components/editor/commands.js.map +1 -0
- package/dist/components/editor/editor.d.ts +83 -0
- package/dist/components/editor/editor.d.ts.map +1 -0
- package/dist/components/editor/editor.js +1951 -0
- package/dist/components/editor/editor.js.map +1 -0
- package/dist/components/editor/index.d.ts +12 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +7 -0
- package/dist/components/editor/index.js.map +1 -0
- package/dist/components/editor/normalize-html.d.ts +33 -0
- package/dist/components/editor/normalize-html.d.ts.map +1 -0
- package/dist/components/editor/normalize-html.js +316 -0
- package/dist/components/editor/normalize-html.js.map +1 -0
- package/dist/components/editor/sanitize-html.d.ts +37 -0
- package/dist/components/editor/sanitize-html.d.ts.map +1 -0
- package/dist/components/editor/sanitize-html.js +247 -0
- package/dist/components/editor/sanitize-html.js.map +1 -0
- package/dist/components/editor/schema.d.ts +36 -0
- package/dist/components/editor/schema.d.ts.map +1 -0
- package/dist/components/editor/schema.js +232 -0
- package/dist/components/editor/schema.js.map +1 -0
- package/dist/components/editor/selection.d.ts +22 -0
- package/dist/components/editor/selection.d.ts.map +1 -0
- package/dist/components/editor/selection.js +97 -0
- package/dist/components/editor/selection.js.map +1 -0
- package/dist/components/editor/styles.d.ts +10 -0
- package/dist/components/editor/styles.d.ts.map +1 -0
- package/dist/components/editor/styles.js +446 -0
- package/dist/components/editor/styles.js.map +1 -0
- package/dist/components/editor/table-utils.d.ts +33 -0
- package/dist/components/editor/table-utils.d.ts.map +1 -0
- package/dist/components/editor/table-utils.js +150 -0
- package/dist/components/editor/table-utils.js.map +1 -0
- package/dist/components/fileupload/fileupload.d.ts +10 -2
- package/dist/components/fileupload/fileupload.d.ts.map +1 -1
- package/dist/components/fileupload/fileupload.js +17 -2
- package/dist/components/fileupload/fileupload.js.map +1 -1
- package/dist/components/floatlabel/floatlabel.d.ts +9 -3
- package/dist/components/floatlabel/floatlabel.d.ts.map +1 -1
- package/dist/components/floatlabel/floatlabel.js +22 -7
- package/dist/components/floatlabel/floatlabel.js.map +1 -1
- package/dist/components/input/input.d.ts +18 -7
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/input/input.js +33 -3
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/knob/knob.d.ts +7 -3
- package/dist/components/knob/knob.d.ts.map +1 -1
- package/dist/components/knob/knob.js +4 -2
- package/dist/components/knob/knob.js.map +1 -1
- package/dist/components/multiselect/multiselect.d.ts +13 -3
- package/dist/components/multiselect/multiselect.d.ts.map +1 -1
- package/dist/components/multiselect/multiselect.js +27 -2
- package/dist/components/multiselect/multiselect.js.map +1 -1
- package/dist/components/radio/radio.d.ts +27 -4
- package/dist/components/radio/radio.d.ts.map +1 -1
- package/dist/components/radio/radio.js +67 -8
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/rating/rating.d.ts +8 -4
- package/dist/components/rating/rating.d.ts.map +1 -1
- package/dist/components/rating/rating.js +5 -2
- package/dist/components/rating/rating.js.map +1 -1
- package/dist/components/select/select.d.ts +9 -3
- package/dist/components/select/select.d.ts.map +1 -1
- package/dist/components/select/select.js +11 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/slider/slider.d.ts +12 -6
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/slider/slider.js +10 -2
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/switch/switch.d.ts +20 -4
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/switch/switch.js +40 -2
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/textarea/textarea.d.ts +12 -5
- package/dist/components/textarea/textarea.d.ts.map +1 -1
- package/dist/components/textarea/textarea.js +12 -2
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/toast/toast.d.ts +27 -15
- package/dist/components/toast/toast.d.ts.map +1 -1
- package/dist/components/toast/toast.js +205 -32
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toggle-button-group/toggle-button-group.d.ts +13 -5
- package/dist/components/toggle-button-group/toggle-button-group.d.ts.map +1 -1
- package/dist/components/toggle-button-group/toggle-button-group.js +19 -2
- package/dist/components/toggle-button-group/toggle-button-group.js.map +1 -1
- package/dist/core/base.d.ts +7 -0
- package/dist/core/base.d.ts.map +1 -1
- package/dist/core/base.js +4 -1
- package/dist/core/base.js.map +1 -1
- package/dist/core/form-element.d.ts +81 -0
- package/dist/core/form-element.d.ts.map +1 -0
- package/dist/core/form-element.js +129 -0
- package/dist/core/form-element.js.map +1 -0
- package/dist/core/jsx.d.ts +25 -1
- package/dist/core/jsx.d.ts.map +1 -1
- package/dist/core/jsx.js.map +1 -1
- package/dist/core/presets.d.ts +8 -3
- package/dist/core/presets.d.ts.map +1 -1
- package/dist/core/presets.js +6 -17
- package/dist/core/presets.js.map +1 -1
- package/dist/core/types.d.ts +4 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/vue.d.ts +3 -1
- package/dist/core/vue.d.ts.map +1 -1
- package/dist/core/vue.js.map +1 -1
- package/dist/docs/app.d.ts.map +1 -1
- package/dist/docs/componentes/autocomplete.doc.d.ts.map +1 -1
- package/dist/docs/componentes/checkbox.doc.d.ts.map +1 -1
- package/dist/docs/componentes/datepicker.doc.d.ts.map +1 -1
- package/dist/docs/componentes/editor.doc.d.ts +6 -0
- package/dist/docs/componentes/editor.doc.d.ts.map +1 -0
- package/dist/docs/componentes/fileupload.doc.d.ts.map +1 -1
- package/dist/docs/componentes/index.d.ts.map +1 -1
- package/dist/docs/componentes/input.doc.d.ts.map +1 -1
- package/dist/docs/componentes/knob.doc.d.ts.map +1 -1
- package/dist/docs/componentes/multiselect.doc.d.ts.map +1 -1
- package/dist/docs/componentes/rating.doc.d.ts.map +1 -1
- package/dist/docs/componentes/select.doc.d.ts.map +1 -1
- package/dist/docs/componentes/slider.doc.d.ts.map +1 -1
- package/dist/docs/componentes/switch.doc.d.ts.map +1 -1
- package/dist/docs/componentes/textarea.doc.d.ts.map +1 -1
- package/dist/docs/componentes/toast.doc.d.ts.map +1 -1
- package/dist/docs/componentes/toggle-button-group.doc.d.ts.map +1 -1
- package/dist/docs/frameworks.d.ts +75 -0
- package/dist/docs/frameworks.d.ts.map +1 -0
- package/dist/docs/ui/code.d.ts +4 -0
- package/dist/docs/ui/code.d.ts.map +1 -1
- package/dist/fenix-ui.umd.min.js +786 -254
- package/dist/fenix-ui2.esm.js.map +1 -1
- package/dist/fenix-ui4.esm.js +4396 -172
- package/dist/fenix-ui4.esm.js.map +1 -1
- package/dist/fenix-ui5.esm.js +1 -0
- package/dist/fenix-ui5.esm.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/auto-import.d.ts.map +1 -1
- package/dist/plugins/auto-import.js +1 -0
- package/dist/plugins/auto-import.js.map +1 -1
- package/package.json +5 -1
|
@@ -4,7 +4,7 @@ var __typeError = (msg) => {
|
|
|
4
4
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
5
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
6
6
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
7
|
-
var _FxToast_instances, syncProgress_fn, render_fn;
|
|
7
|
+
var _FxToast_instances, wirePause_fn, startTimer_fn, pauseTimer_fn, resumeTimer_fn, syncProgress_fn, render_fn, syncMore_fn;
|
|
8
8
|
import { __fenixPreload } from "../../_virtual/preload-helper.js";
|
|
9
9
|
const REMOVED_EVENT = "fx-toast:removed";
|
|
10
10
|
const KIND_COLOR = {
|
|
@@ -19,6 +19,7 @@ const KIND_ICON = {
|
|
|
19
19
|
warning: "!",
|
|
20
20
|
info: "i"
|
|
21
21
|
};
|
|
22
|
+
const COPY_SVG = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="12" height="12" rx="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>';
|
|
22
23
|
const CARD_CSS = `
|
|
23
24
|
:host { display: contents; pointer-events: auto; }
|
|
24
25
|
/* Modo explícito: sobrepõe os tokens herdados do tema global SOMENTE neste card. */
|
|
@@ -52,36 +53,69 @@ const CARD_CSS = `
|
|
|
52
53
|
user-select: none;
|
|
53
54
|
}
|
|
54
55
|
.card {
|
|
55
|
-
display: flex; align-items:
|
|
56
|
+
display: flex; align-items: center; gap: 10px;
|
|
56
57
|
min-width: 260px; max-width: 360px;
|
|
58
|
+
/* Altura mínima idêntica à de um toast COM título: sem título o card não
|
|
59
|
+
fica "achatado" e o conjunto mantém o mesmo ritmo visual. */
|
|
60
|
+
min-height: 56px;
|
|
57
61
|
background: var(--fx-surface-background, #fff);
|
|
58
62
|
color: var(--fx-text-default, #1e293b);
|
|
59
63
|
border: 1px solid var(--fx-border-default, #e2e8f0);
|
|
60
64
|
border-left: 4px solid var(--kind);
|
|
61
65
|
border-radius: var(--fx-radius-md, 8px);
|
|
62
66
|
box-shadow: var(--fx-shadow-lg, 0 10px 30px rgba(0,0,0,.14));
|
|
63
|
-
padding: var(--fx-space-
|
|
67
|
+
padding: var(--fx-space-xs, 8px) var(--fx-space-md, 12px);
|
|
64
68
|
font-family: inherit;
|
|
65
69
|
animation: fx-toast-in .25s ease;
|
|
66
70
|
}
|
|
67
71
|
@keyframes fx-toast-in { from { opacity: 0; transform: translateY(-6px); } }
|
|
68
72
|
.card.leaving { opacity: 0; transition: opacity .2s ease; }
|
|
73
|
+
.card.no-title { min-height: 48px; }
|
|
69
74
|
.icon {
|
|
70
75
|
width: 22px; height: 22px; border-radius: 50%;
|
|
71
76
|
background: var(--kind);
|
|
72
77
|
color: #fff;
|
|
73
78
|
display: flex; align-items: center; justify-content: center;
|
|
74
79
|
font-size: 12px; font-weight: 700;
|
|
75
|
-
flex: none;
|
|
80
|
+
flex: none; align-self: center;
|
|
76
81
|
user-select: none;
|
|
77
82
|
}
|
|
78
|
-
.body { flex: 1; min-width: 0; }
|
|
83
|
+
.body { flex: 1; min-width: 0; align-self: center; }
|
|
79
84
|
.title { font-weight: 600; font-size: 14px; }
|
|
80
|
-
.msg {
|
|
81
|
-
|
|
85
|
+
.msg {
|
|
86
|
+
font-size: calc(var(--fx-font-size, 14px) - 2px);
|
|
87
|
+
color: var(--fx-text-muted, #64748b);
|
|
88
|
+
margin-top: 2px;
|
|
89
|
+
word-break: break-word; white-space: pre-line;
|
|
90
|
+
/* Mensagens longas mantêm o card no tamanho padrão e terminam em "…";
|
|
91
|
+
"Ver mais" expande o toast (sem perder o restante do texto). */
|
|
92
|
+
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
|
|
93
|
+
line-clamp: 2; overflow: hidden;
|
|
94
|
+
}
|
|
95
|
+
.card.expanded .msg {
|
|
96
|
+
display: block; overflow: visible;
|
|
97
|
+
-webkit-line-clamp: unset; line-clamp: unset;
|
|
98
|
+
}
|
|
99
|
+
.more {
|
|
100
|
+
all: unset; cursor: pointer; display: inline-block;
|
|
101
|
+
margin-top: 4px; padding: 2px 0;
|
|
102
|
+
font-size: 11px; font-weight: 600; color: var(--kind);
|
|
103
|
+
}
|
|
104
|
+
.more[hidden] { display: none; }
|
|
105
|
+
.more:hover { text-decoration: underline; }
|
|
106
|
+
.actions {
|
|
107
|
+
display: flex; align-items: center; gap: 2px;
|
|
108
|
+
flex: none; align-self: flex-start;
|
|
109
|
+
}
|
|
110
|
+
.copy, .close {
|
|
82
111
|
all: unset; cursor: pointer; flex: none; line-height: 1;
|
|
83
112
|
color: var(--fx-text-muted, #64748b); font-size: 15px; padding: 2px 4px; border-radius: 4px;
|
|
84
113
|
}
|
|
114
|
+
.copy[hidden] { display: none; }
|
|
115
|
+
.copy { font-size: 14px; display: inline-flex; align-items: center; }
|
|
116
|
+
.copy svg { display: block; }
|
|
117
|
+
.copy.done { color: var(--fx-color-success, #10b981); }
|
|
118
|
+
.copy:hover { color: var(--fx-color-primary, #6366f1); background: var(--fx-surface-surface-hover, rgba(0,0,0,.05)); }
|
|
85
119
|
.close:hover { color: var(--fx-color-danger, #f43f5e); background: var(--fx-surface-surface-hover, rgba(0,0,0,.05)); }
|
|
86
120
|
|
|
87
121
|
/* --- Barra de contagem regressiva (atributo progress) ---
|
|
@@ -110,9 +144,12 @@ const CARD_CSS = `
|
|
|
110
144
|
will-change: transform;
|
|
111
145
|
}
|
|
112
146
|
.progress.run { animation: fx-toast-drain var(--toast-duration, 4000ms) linear forwards; }
|
|
113
|
-
/*
|
|
147
|
+
/* Passar o mouse (ou focar) no toast pausa a contagem: a barra e o timer
|
|
148
|
+
congelam juntos até o cursor sair — tempo de ler a mensagem inteira.
|
|
149
|
+
progress="hover" é mantido por compatibilidade e se comporta como
|
|
150
|
+
"always" (o hover já pausa a contagem). */
|
|
114
151
|
.card:hover .progress.run,
|
|
115
|
-
.card:focus-within .progress.run { animation-play-state:
|
|
152
|
+
.card:focus-within .progress.run { animation-play-state: paused; }
|
|
116
153
|
@keyframes fx-toast-drain {
|
|
117
154
|
from { transform: scaleX(1); }
|
|
118
155
|
to { transform: scaleX(0); }
|
|
@@ -131,27 +168,42 @@ class FxToast extends HTMLElement {
|
|
|
131
168
|
super();
|
|
132
169
|
__privateAdd(this, _FxToast_instances);
|
|
133
170
|
this.timer = null;
|
|
171
|
+
this.remaining = 0;
|
|
172
|
+
this.startedAt = 0;
|
|
173
|
+
this.hovering = false;
|
|
174
|
+
this.disposed = false;
|
|
175
|
+
this.counting = false;
|
|
176
|
+
this.wired = false;
|
|
134
177
|
this.attachShadow({ mode: "open" });
|
|
135
178
|
}
|
|
136
179
|
static get observedAttributes() {
|
|
137
|
-
return [
|
|
180
|
+
return [
|
|
181
|
+
"kind",
|
|
182
|
+
"title",
|
|
183
|
+
"message",
|
|
184
|
+
"duration",
|
|
185
|
+
"icon",
|
|
186
|
+
"mode",
|
|
187
|
+
"progress",
|
|
188
|
+
"progress-origin"
|
|
189
|
+
];
|
|
138
190
|
}
|
|
139
191
|
/**
|
|
140
192
|
* Exibe a barra de contagem regressiva na base do card.
|
|
141
193
|
*
|
|
142
|
-
* A barra esvazia
|
|
143
|
-
*
|
|
144
|
-
* omitida — não há tempo restante a representar.
|
|
194
|
+
* A barra esvazia durante exatamente `duration` e usa a cor do `kind`.
|
|
195
|
+
* Com `duration="0"` (toast fixo) a barra é omitida — não há tempo restante.
|
|
145
196
|
*
|
|
146
197
|
* - `'always'` (ou atributo vazio): barra sempre correndo.
|
|
147
|
-
* - `'hover'`: a barra só corre enquanto o cursor estiver sobre o toast;
|
|
148
|
-
* ao sair, a animação pausa, então dá tempo de ler a mensagem.
|
|
149
198
|
* - `'paused'`: barra visível, porém parada.
|
|
199
|
+
* - `'hover'`: **compatibilidade** — equivale a `'always'`. O hover agora
|
|
200
|
+
* pausa a contagem (timer + barra) em qualquer modo, então a barra "só
|
|
201
|
+
* correr sob o cursor" deixou de fazer sentido.
|
|
150
202
|
*/
|
|
151
203
|
get progress() {
|
|
152
204
|
if (!this.hasAttribute("progress")) return void 0;
|
|
153
205
|
const v = this.getAttribute("progress");
|
|
154
|
-
return v === "
|
|
206
|
+
return v === "paused" ? "paused" : "always";
|
|
155
207
|
}
|
|
156
208
|
set progress(value) {
|
|
157
209
|
if (value) this.setAttribute("progress", value);
|
|
@@ -191,11 +243,13 @@ class FxToast extends HTMLElement {
|
|
|
191
243
|
}
|
|
192
244
|
connectedCallback() {
|
|
193
245
|
if (!this.shadowRoot.firstChild) __privateMethod(this, _FxToast_instances, render_fn).call(this);
|
|
246
|
+
this.disposed = false;
|
|
247
|
+
__privateMethod(this, _FxToast_instances, wirePause_fn).call(this);
|
|
194
248
|
const safe = this.safeDuration;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
249
|
+
this.counting = safe > 0;
|
|
250
|
+
if (safe > 0 && !this.timer) __privateMethod(this, _FxToast_instances, startTimer_fn).call(this, safe);
|
|
198
251
|
__privateMethod(this, _FxToast_instances, syncProgress_fn).call(this);
|
|
252
|
+
__privateMethod(this, _FxToast_instances, syncMore_fn).call(this);
|
|
199
253
|
}
|
|
200
254
|
/**
|
|
201
255
|
* Limpa recursos ao sair do DOM e avisa a API imperativa (`FenixToast`).
|
|
@@ -206,11 +260,24 @@ class FxToast extends HTMLElement {
|
|
|
206
260
|
* sem limite em uso prolongado.
|
|
207
261
|
*/
|
|
208
262
|
disconnectedCallback() {
|
|
263
|
+
this.disposed = true;
|
|
209
264
|
if (this.timer) clearTimeout(this.timer);
|
|
210
265
|
this.timer = null;
|
|
211
|
-
this.dispatchEvent(
|
|
266
|
+
this.dispatchEvent(
|
|
267
|
+
new CustomEvent(REMOVED_EVENT, { bubbles: false, composed: false })
|
|
268
|
+
);
|
|
212
269
|
}
|
|
213
270
|
attributeChangedCallback(name) {
|
|
271
|
+
if (name === "duration") {
|
|
272
|
+
if (this.timer) {
|
|
273
|
+
clearTimeout(this.timer);
|
|
274
|
+
this.timer = null;
|
|
275
|
+
}
|
|
276
|
+
const safe = this.safeDuration;
|
|
277
|
+
this.counting = safe > 0;
|
|
278
|
+
if (safe > 0 && this.isConnected && !this.disposed)
|
|
279
|
+
__privateMethod(this, _FxToast_instances, startTimer_fn).call(this, safe);
|
|
280
|
+
}
|
|
214
281
|
if (name === "duration" || name === "progress" || name === "progress-origin" || name === "kind") {
|
|
215
282
|
__privateMethod(this, _FxToast_instances, syncProgress_fn).call(this);
|
|
216
283
|
}
|
|
@@ -228,6 +295,52 @@ class FxToast extends HTMLElement {
|
|
|
228
295
|
}
|
|
229
296
|
}
|
|
230
297
|
_FxToast_instances = new WeakSet();
|
|
298
|
+
/**
|
|
299
|
+
* Pausa a contagem enquanto o cursor (ou o foco) estiver no toast e retoma
|
|
300
|
+
* de onde parou ao sair — assim uma mensagem longa pode ser lida inteira.
|
|
301
|
+
* A barra de progresso pausa junto (regra CSS de :hover/:focus-within).
|
|
302
|
+
*/
|
|
303
|
+
wirePause_fn = function() {
|
|
304
|
+
if (this.wired) return;
|
|
305
|
+
this.wired = true;
|
|
306
|
+
this.addEventListener("mouseenter", () => {
|
|
307
|
+
this.hovering = true;
|
|
308
|
+
__privateMethod(this, _FxToast_instances, pauseTimer_fn).call(this);
|
|
309
|
+
});
|
|
310
|
+
this.addEventListener("mouseleave", () => {
|
|
311
|
+
this.hovering = false;
|
|
312
|
+
__privateMethod(this, _FxToast_instances, resumeTimer_fn).call(this);
|
|
313
|
+
});
|
|
314
|
+
this.addEventListener("focusin", () => __privateMethod(this, _FxToast_instances, pauseTimer_fn).call(this));
|
|
315
|
+
this.addEventListener("focusout", () => {
|
|
316
|
+
if (!this.hovering) __privateMethod(this, _FxToast_instances, resumeTimer_fn).call(this);
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
startTimer_fn = function(ms) {
|
|
320
|
+
this.remaining = ms;
|
|
321
|
+
this.startedAt = Date.now();
|
|
322
|
+
this.timer = setTimeout(() => {
|
|
323
|
+
this.timer = null;
|
|
324
|
+
this.dismiss();
|
|
325
|
+
}, ms);
|
|
326
|
+
};
|
|
327
|
+
pauseTimer_fn = function() {
|
|
328
|
+
if (!this.timer) return;
|
|
329
|
+
clearTimeout(this.timer);
|
|
330
|
+
this.timer = null;
|
|
331
|
+
this.remaining = Math.max(
|
|
332
|
+
0,
|
|
333
|
+
this.remaining - (Date.now() - this.startedAt)
|
|
334
|
+
);
|
|
335
|
+
};
|
|
336
|
+
resumeTimer_fn = function() {
|
|
337
|
+
if (!this.counting || this.timer || this.disposed) return;
|
|
338
|
+
if (this.remaining <= 0) {
|
|
339
|
+
this.dismiss();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
__privateMethod(this, _FxToast_instances, startTimer_fn).call(this, this.remaining);
|
|
343
|
+
};
|
|
231
344
|
/**
|
|
232
345
|
* Aplica (ou remove) a barra de contagem regressiva.
|
|
233
346
|
*
|
|
@@ -248,15 +361,23 @@ syncProgress_fn = function() {
|
|
|
248
361
|
return;
|
|
249
362
|
}
|
|
250
363
|
if (!bar) {
|
|
251
|
-
this.shadowRoot.querySelector(".card").insertAdjacentHTML(
|
|
364
|
+
this.shadowRoot.querySelector(".card").insertAdjacentHTML(
|
|
365
|
+
"beforeend",
|
|
366
|
+
'<span class="progress" part="progress" aria-hidden="true"></span>'
|
|
367
|
+
);
|
|
252
368
|
}
|
|
253
369
|
const el = this.shadowRoot.querySelector(".progress");
|
|
254
370
|
el.style.setProperty("--toast-duration", `${dur}ms`);
|
|
255
|
-
el.style.setProperty(
|
|
371
|
+
el.style.setProperty(
|
|
372
|
+
"--toast-progress-origin",
|
|
373
|
+
`${this.progressOrigin} center`
|
|
374
|
+
);
|
|
256
375
|
el.classList.remove("run");
|
|
257
376
|
if (mode !== "paused") el.classList.add("run");
|
|
258
377
|
card.classList.add("entering");
|
|
259
|
-
requestAnimationFrame(
|
|
378
|
+
requestAnimationFrame(
|
|
379
|
+
() => requestAnimationFrame(() => card.classList.remove("entering"))
|
|
380
|
+
);
|
|
260
381
|
};
|
|
261
382
|
render_fn = function() {
|
|
262
383
|
const kind = this.getAttribute("kind") || "info";
|
|
@@ -269,22 +390,70 @@ render_fn = function() {
|
|
|
269
390
|
const iconContent = isFxIcon ? iconName : KIND_ICON[kind] ?? KIND_ICON.info;
|
|
270
391
|
this.shadowRoot.innerHTML = `
|
|
271
392
|
<style>${CARD_CSS}</style>
|
|
272
|
-
<div class="card" style="--kind:${color}" role="status" part="card">
|
|
393
|
+
<div class="card${title ? "" : " no-title"}" style="--kind:${color}" role="status" part="card">
|
|
273
394
|
<span class="icon${isFxIcon ? " fx-icon" : ""}">${iconContent}</span>
|
|
274
395
|
<div class="body">
|
|
275
|
-
${title ? '<div class="title"></div>' : ""}
|
|
276
|
-
${msg ? '<div class="msg"></div>' : ""}
|
|
396
|
+
${title ? '<div class="title" part="title"></div>' : ""}
|
|
397
|
+
${msg ? '<div class="msg" part="message"></div>' : ""}
|
|
398
|
+
${msg ? '<button class="more" part="more" hidden>Ver mais</button>' : ""}
|
|
399
|
+
</div>
|
|
400
|
+
<div class="actions">
|
|
401
|
+
${msg ? `<button class="copy" part="copy" hidden aria-label="Copiar mensagem" title="Copiar mensagem">${COPY_SVG}</button>` : ""}
|
|
402
|
+
<button class="close" aria-label="Fechar" title="Fechar">✕</button>
|
|
277
403
|
</div>
|
|
278
|
-
<button class="close" aria-label="Fechar">✕</button>
|
|
279
404
|
</div>`;
|
|
280
405
|
const t = this.shadowRoot.querySelector(".title");
|
|
281
406
|
const m = this.shadowRoot.querySelector(".msg");
|
|
282
407
|
if (t) t.textContent = title;
|
|
283
|
-
if (m)
|
|
284
|
-
|
|
408
|
+
if (m) {
|
|
409
|
+
m.textContent = msg;
|
|
410
|
+
m.title = msg;
|
|
411
|
+
}
|
|
412
|
+
const card = this.shadowRoot.querySelector(".card");
|
|
413
|
+
const more = this.shadowRoot.querySelector(".more");
|
|
414
|
+
const copy = this.shadowRoot.querySelector(".copy");
|
|
415
|
+
more?.addEventListener("click", () => {
|
|
416
|
+
const expanded = card.classList.toggle("expanded");
|
|
417
|
+
more.textContent = expanded ? "Ver menos" : "Ver mais";
|
|
418
|
+
if (copy) copy.hidden = !expanded;
|
|
419
|
+
if (expanded) __privateMethod(this, _FxToast_instances, pauseTimer_fn).call(this);
|
|
420
|
+
});
|
|
421
|
+
copy?.addEventListener("click", (e) => {
|
|
422
|
+
const btn = e.currentTarget;
|
|
423
|
+
const text = [title, msg].filter(Boolean).join("\n");
|
|
424
|
+
navigator.clipboard?.writeText(text).catch(() => {
|
|
425
|
+
});
|
|
426
|
+
btn.classList.add("done");
|
|
427
|
+
btn.title = "Copiado!";
|
|
428
|
+
setTimeout(() => {
|
|
429
|
+
btn.classList.remove("done");
|
|
430
|
+
btn.title = "Copiar mensagem";
|
|
431
|
+
}, 1200);
|
|
432
|
+
});
|
|
433
|
+
this.shadowRoot.querySelector(".close").addEventListener(
|
|
434
|
+
"click",
|
|
435
|
+
() => this.dismiss()
|
|
436
|
+
);
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* Mostra "Ver mais" somente quando a mensagem passou de 2 linhas.
|
|
440
|
+
* Sem layout (jsdom) scrollHeight/clientHeight são 0 → fica oculto.
|
|
441
|
+
*/
|
|
442
|
+
syncMore_fn = function() {
|
|
443
|
+
const card = this.shadowRoot?.querySelector(".card");
|
|
444
|
+
const more = this.shadowRoot?.querySelector(".more");
|
|
445
|
+
const msg = this.shadowRoot?.querySelector(".msg");
|
|
446
|
+
if (!card || !more || !msg) return;
|
|
447
|
+
if (card.classList.contains("expanded")) {
|
|
448
|
+
more.hidden = false;
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
more.hidden = !(msg.scrollHeight - msg.clientHeight > 1);
|
|
285
452
|
};
|
|
286
453
|
function regionFor(position) {
|
|
287
|
-
let region = document.querySelector(
|
|
454
|
+
let region = document.querySelector(
|
|
455
|
+
`[data-fx-toast-region="${position}"]`
|
|
456
|
+
);
|
|
288
457
|
if (!region) {
|
|
289
458
|
region = document.createElement("div");
|
|
290
459
|
region.setAttribute("data-fx-toast-region", position);
|
|
@@ -319,7 +488,10 @@ class ToastApi {
|
|
|
319
488
|
push(kind, title, messageOrOpts, opts) {
|
|
320
489
|
const id = ++this.seq;
|
|
321
490
|
const message = typeof messageOrOpts === "string" ? messageOrOpts : messageOrOpts?.message;
|
|
322
|
-
const o = {
|
|
491
|
+
const o = {
|
|
492
|
+
...typeof messageOrOpts === "object" && messageOrOpts ? messageOrOpts : void 0,
|
|
493
|
+
...opts
|
|
494
|
+
};
|
|
323
495
|
const el = document.createElement("fx-toast");
|
|
324
496
|
el.setAttribute("kind", kind);
|
|
325
497
|
el.setAttribute("title", title);
|
|
@@ -344,7 +516,8 @@ class ToastApi {
|
|
|
344
516
|
const FenixToast = new ToastApi();
|
|
345
517
|
globalThis.FenixToast = FenixToast;
|
|
346
518
|
function defineFxToast() {
|
|
347
|
-
if (!customElements.get("fx-toast"))
|
|
519
|
+
if (!customElements.get("fx-toast"))
|
|
520
|
+
customElements.define("fx-toast", FxToast);
|
|
348
521
|
}
|
|
349
522
|
export {
|
|
350
523
|
FenixToast,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;AAsBA,MAAM,gBAAgB;AAEtB,MAAM,aAAwC;AAAA,EAC5C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACX;AAGA,MAAM,YAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AACR;AAEA,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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B,WAAkD,aAAa;AAEzD,SAAS,gBAAgB;AAC9B,MAAI,CAAC,eAAe,IAAI,UAAU,EAAG,gBAAe,OAAO,YAAY,OAAO;AAChF","names":[],"ignoreList":[],"sources":["../../../src/components/toast/toast.ts"],"sourcesContent":["/**\n * <fx-toast> — notificações imperativas com posição e duração configuráveis.\n *\n * Atributos: kind (success|error|info|warning), title, message,\n * position (top-left|top-center|top-right|bottom-left|bottom-center|bottom-right),\n * duration (ms; 0 = fixo até fechar), mode ('light'|'dark' — força o esquema de\n * cores do card independentemente do tema global), progress (booleano ou\n * 'always'|'hover'|'paused' — barra de contagem regressiva na cor do kind),\n * progress-origin (left|right — lado pelo qual a barra esvazia; padrão left).\n */\nconst POSITIONS = [\n 'top-left', 'top-center', 'top-right',\n 'bottom-left', 'bottom-center', 'bottom-right',\n] as const;\nexport type ToastPosition = (typeof POSITIONS)[number];\ntype ToastKind = 'success' | 'error' | 'info' | 'warning';\n\n/**\n * Evento interno disparado quando o <fx-toast> sai do DOM.\n * A API `FenixToast` o escuta para remover a entrada do mapa interno —\n * é o que impede o acúmulo de toasts já dispensados.\n */\nconst REMOVED_EVENT = 'fx-toast:removed';\n\nconst KIND_COLOR: Record<ToastKind, string> = {\n success: 'var(--fx-color-success, #10b981)',\n error: 'var(--fx-color-danger, #f43f5e)',\n info: 'var(--fx-color-info, #0ea5e9)',\n warning: 'var(--fx-color-warning, #f59e0b)',\n};\n\n/** Ícone exibido no lugar da bolinha, conforme a variante. */\nconst KIND_ICON: Record<ToastKind, string> = {\n success: '✓',\n error: '✕',\n warning: '!',\n info: 'i',\n};\n\nconst CARD_CSS = `\n:host { display: contents; pointer-events: auto; }\n/* Modo explícito: sobrepõe os tokens herdados do tema global SOMENTE neste card. */\n:host([mode='dark']) {\n --fx-surface-background: #1e293b;\n --fx-text-default: #f1f5f9;\n --fx-text-muted: #94a3b8;\n --fx-border-default: #334155;\n --fx-shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);\n --fx-surface-surface-hover: rgba(255, 255, 255, .08);\n}\n:host([mode='light']) {\n --fx-surface-background: #ffffff;\n --fx-text-default: #1e293b;\n --fx-text-muted: #64748b;\n --fx-border-default: #e2e8f0;\n --fx-shadow-lg: 0 10px 30px rgba(0, 0, 0, .14);\n --fx-surface-surface-hover: rgba(0, 0, 0, .05);\n}\n.fx-icon {\n font-family: var(--fx-icon-font, 'Fenix Icons');\n font-weight: normal;\n font-style: normal;\n line-height: 1;\n letter-spacing: normal;\n display: inline-block;\n white-space: nowrap;\n direction: ltr;\n font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;\n -webkit-font-smoothing: antialiased;\n user-select: none;\n}\n.card {\n display: flex; align-items: flex-start; gap: 10px;\n min-width: 260px; max-width: 360px;\n background: var(--fx-surface-background, #fff);\n color: var(--fx-text-default, #1e293b);\n border: 1px solid var(--fx-border-default, #e2e8f0);\n border-left: 4px solid var(--kind);\n border-radius: var(--fx-radius-md, 8px);\n box-shadow: var(--fx-shadow-lg, 0 10px 30px rgba(0,0,0,.14));\n padding: var(--fx-space-sm, 8px) var(--fx-space-md, 12px);\n font-family: inherit;\n animation: fx-toast-in .25s ease;\n}\n@keyframes fx-toast-in { from { opacity: 0; transform: translateY(-6px); } }\n.card.leaving { opacity: 0; transition: opacity .2s ease; }\n.icon {\n width: 22px; height: 22px; border-radius: 50%;\n background: var(--kind);\n color: #fff;\n display: flex; align-items: center; justify-content: center;\n font-size: 12px; font-weight: 700;\n flex: none; margin-top: 2px;\n user-select: none;\n}\n.body { flex: 1; min-width: 0; }\n.title { font-weight: 600; font-size: 14px; }\n.msg { font-size: calc(var(--fx-font-size, 14px) - 2px); color: var(--fx-text-muted, #64748b); margin-top: 2px; word-break: break-word; white-space: pre-line; }\n.close {\n all: unset; cursor: pointer; flex: none; line-height: 1;\n color: var(--fx-text-muted, #64748b); font-size: 15px; padding: 2px 4px; border-radius: 4px;\n}\n.close:hover { color: var(--fx-color-danger, #f43f5e); background: var(--fx-surface-surface-hover, rgba(0,0,0,.05)); }\n\n/* --- Barra de contagem regressiva (atributo progress) ---\n Fica na base do card e esvazia durante a duração, na cor do kind (--kind) —\n ou seja, acompanha success/error/warning/info sem configuração extra.\n\n O lado é configurável pelo atributo progress-origin (padrão: left):\n left → a barra drena da direita para a esquerda (ancorada à esquerda)\n right → a barra drena da esquerda para a direita (ancorada à direita)\n A origem entra como custom property, então os keyframes são compartilhados.\n\n Usa escalaX em vez de width: a animação escreve só na compositor, sem\n reflow por frame. */\n.card { position: relative; overflow: hidden; }\n.progress {\n position: absolute;\n left: 0;\n bottom: 0;\n width: 100%;\n height: 3px;\n background: var(--kind);\n transform-origin: var(--toast-progress-origin, left center);\n transform: scaleX(1);\n border-radius: 0 0 var(--fx-radius-md, 8px) var(--fx-radius-md, 8px);\n pointer-events: none;\n will-change: transform;\n}\n.progress.run { animation: fx-toast-drain var(--toast-duration, 4000ms) linear forwards; }\n/* No modo hover a animação fica parada até o cursor/foco entrar no card. */\n.card:hover .progress.run,\n.card:focus-within .progress.run { animation-play-state: running; }\n@keyframes fx-toast-drain {\n from { transform: scaleX(1); }\n to { transform: scaleX(0); }\n}\n/* A barra só começa a correr no 2º frame: no 1º ela já apareceria zerada\n (o elemento acabou de ser inserido e a animação aplica o estado final). */\n.card.entering .progress { animation: none; }\n/* Ao dispensar, congela a barra: ela some junto com o card em .2s. */\n.card.leaving .progress { animation-play-state: paused; }\n@media (prefers-reduced-motion: reduce) {\n .progress.run { animation-duration: 0.01ms; }\n}\n`;\n\nexport class FxToast extends HTMLElement {\n static get observedAttributes() {\n return ['kind', 'title', 'message', 'duration', 'icon', 'mode', 'progress', 'progress-origin'];\n }\n\n /**\n * Exibe a barra de contagem regressiva na base do card.\n *\n * A barra esvazia da esquerda para a direita durante exatamente `duration`\n * e usa a cor do `kind`. Com `duration=\"0\"` (toast fixo) a barra é\n * omitida — não há tempo restante a representar.\n *\n * - `'always'` (ou atributo vazio): barra sempre correndo.\n * - `'hover'`: a barra só corre enquanto o cursor estiver sobre o toast;\n * ao sair, a animação pausa, então dá tempo de ler a mensagem.\n * - `'paused'`: barra visível, porém parada.\n */\n get progress(): 'always' | 'hover' | 'paused' | undefined {\n if (!this.hasAttribute('progress')) return undefined;\n const v = this.getAttribute('progress');\n return v === 'hover' || v === 'paused' ? v : 'always';\n }\n set progress(value: 'always' | 'hover' | 'paused' | undefined) {\n if (value) this.setAttribute('progress', value);\n else this.removeAttribute('progress');\n }\n\n /**\n * Lado a partir do qual a barra esvazia.\n *\n * - `'left'` (padrão): a barra fica ancorada à esquerda e drena da direita\n * para a esquerda.\n * - `'right'`: a barra fica ancorada à direita e drena da esquerda para a\n * direita (espelhado).\n *\n * Só tem efeito junto com `progress`; qualquer valor fora da lista cai em\n * `'left'`.\n */\n get progressOrigin(): 'left' | 'right' {\n return this.getAttribute('progress-origin') === 'right' ? 'right' : 'left';\n }\n set progressOrigin(value: 'left' | 'right') {\n this.setAttribute('progress-origin', value);\n }\n\n /** Duração efetiva em ms (0 = fixo). Mesma regra usada no timer. */\n private get safeDuration(): number {\n const dur = Number(this.getAttribute('duration') ?? '4000');\n if (dur === 0) return 0;\n return Math.max(Number.isNaN(dur) ? 4000 : dur, 1000);\n }\n\n /** Esquema de cores forçado do card: 'light' | 'dark' | undefined (segue o tema). */\n get mode(): 'light' | 'dark' | undefined {\n const m = this.getAttribute('mode');\n return m === 'light' || m === 'dark' ? m : undefined;\n }\n set mode(value: 'light' | 'dark' | undefined) {\n if (value) this.setAttribute('mode', value);\n else this.removeAttribute('mode');\n }\n\n private timer: ReturnType<typeof setTimeout> | null = null;\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n }\n\n connectedCallback() {\n if (!this.shadowRoot!.firstChild) this.#render();\n // Durações mínimas: valores muito baixos (ex.: digitação parcial no\n // playground) são elevados para 1s; 0 permanece fixo até fechar.\n const safe = this.safeDuration;\n if (safe > 0 && !this.timer) {\n this.timer = setTimeout(() => this.dismiss(), safe);\n }\n this.#syncProgress();\n }\n\n /**\n * Limpa recursos ao sair do DOM e avisa a API imperativa (`FenixToast`).\n *\n * O aviso é essencial: `dismiss()` (timer ou botão de fechar) tira o\n * elemento do DOM mas, sem isto, `ToastApi.map` continuaria segurando uma\n * referência forte para cada toast já dispensado — crescimento de memória\n * sem limite em uso prolongado.\n */\n disconnectedCallback() {\n if (this.timer) clearTimeout(this.timer);\n this.timer = null;\n this.dispatchEvent(new CustomEvent(REMOVED_EVENT, { bubbles: false, composed: false }));\n }\n\n attributeChangedCallback(name: string) {\n // A duração é lida em dois lugares (timer + barra): se mudar com o toast\n // na tela, ambos precisam se realinhar.\n if (name === 'duration' || name === 'progress' || name === 'progress-origin' || name === 'kind') {\n this.#syncProgress();\n }\n }\n\n /**\n * Aplica (ou remove) a barra de contagem regressiva.\n *\n * A barra só existe com `progress` e `duration > 0`. O tempo da animação\n * vem de `--toast-duration`, sempre igual ao do `setTimeout` que fecha o\n * toast — assim a barra e o desaparecimento nunca desalinham.\n */\n #syncProgress(): void {\n const card = this.shadowRoot?.querySelector<HTMLElement>('.card');\n if (!card) return;\n const bar = this.shadowRoot!.querySelector<HTMLElement>('.progress');\n const mode = this.progress;\n const dur = this.safeDuration;\n const shouldShow = !!mode && dur > 0;\n\n if (!shouldShow) {\n bar?.remove();\n card.classList.remove('entering');\n return;\n }\n if (!bar) {\n this.shadowRoot!.querySelector('.card')!.insertAdjacentHTML('beforeend', '<span class=\"progress\" part=\"progress\" aria-hidden=\"true\"></span>');\n }\n const el = this.shadowRoot!.querySelector<HTMLElement>('.progress')!;\n el.style.setProperty('--toast-duration', `${dur}ms`);\n // `left` (padrão) => origem à esquerda; `right` espelha a drenagem.\n el.style.setProperty('--toast-progress-origin', `${this.progressOrigin} center`);\n el.classList.remove('run');\n // `paused` mantém a barra cheia e imóvel; `always` e `hover` deixam a\n // animação correr (no `hover`, o CSS só a dispara sob :hover do host).\n if (mode !== 'paused') el.classList.add('run');\n // 1 frame sem animação para o browser registrar o estado inicial cheio\n // antes de a barra começar a esvaziar.\n card.classList.add('entering');\n requestAnimationFrame(() => requestAnimationFrame(() => card.classList.remove('entering')));\n }\n\n dismiss() {\n if (this.timer) clearTimeout(this.timer);\n this.timer = null;\n const card = this.shadowRoot!.querySelector('.card');\n if (card) {\n card.classList.add('leaving');\n setTimeout(() => this.remove(), 200);\n } else {\n this.remove();\n }\n }\n\n #render() {\n const kind = (this.getAttribute('kind') || 'info') as ToastKind;\n const title = this.getAttribute('title') ?? '';\n const msg = this.getAttribute('message') ?? '';\n const color = KIND_COLOR[kind] ?? KIND_COLOR.info;\n const iconName = this.getAttribute('icon');\n const isFxIcon = !!iconName && /^[a-z][a-z0-9_]*$/.test(iconName);\n if (isFxIcon) void import('../../icons');\n const iconContent = isFxIcon ? iconName : KIND_ICON[kind] ?? KIND_ICON.info;\n this.shadowRoot!.innerHTML = `\n <style>${CARD_CSS}</style>\n <div class=\"card\" style=\"--kind:${color}\" role=\"status\" part=\"card\">\n <span class=\"icon${isFxIcon ? ' fx-icon' : ''}\">${iconContent}</span>\n <div class=\"body\">\n ${title ? '<div class=\"title\"></div>' : ''}\n ${msg ? '<div class=\"msg\"></div>' : ''}\n </div>\n <button class=\"close\" aria-label=\"Fechar\">✕</button>\n </div>`;\n const t = this.shadowRoot!.querySelector<HTMLElement>('.title');\n const m = this.shadowRoot!.querySelector<HTMLElement>('.msg');\n if (t) t.textContent = title;\n if (m) m.textContent = msg;\n this.shadowRoot!.querySelector('.close')!.addEventListener('click', () => this.dismiss());\n }\n}\n\n/* ---------- Regiões por posição na tela ---------- */\nfunction regionFor(position: ToastPosition): HTMLElement {\n let region = document.querySelector<HTMLElement>(`[data-fx-toast-region=\"${position}\"]`);\n if (!region) {\n region = document.createElement('div');\n region.setAttribute('data-fx-toast-region', position);\n const [vertical, horizontal] = position.split('-') as [string, string];\n const style = region.style as CSSStyleDeclaration & Record<string, string>;\n style.position = 'fixed';\n style[vertical] = '16px';\n if (horizontal === 'center') {\n style.left = '50%';\n style.transform = 'translateX(-50%)';\n } else {\n style[horizontal] = '16px';\n }\n style.display = 'flex';\n style.flexDirection = 'column';\n style.gap = '8px';\n style.zIndex = '1100';\n style.pointerEvents = 'none';\n // Os cards reabilitam pointer-events via `:host { pointer-events: auto }` (herança),\n // sem necessidade de MutationObserver.\n document.body.appendChild(region);\n }\n return region;\n}\n\nexport interface ToastOptions {\n /** Texto secundário (também aceito como 2º argumento dos métodos). */\n message?: string;\n position?: ToastPosition;\n /** Tempo em ms até sumir. 0 = fixo até fechar. Padrão: 4000 */\n duration?: number;\n /**\n * Barra de contagem regressiva na base do card, na cor do `kind`.\n * `'always'` (padrão) corre sempre; `'hover'` só enquanto o cursor estiver\n * sobre o toast; `'paused'` exibe a barra cheia, porém imóvel.\n * Sem efeito com `duration: 0` (não há tempo restante a representar).\n */\n progress?: 'always' | 'hover' | 'paused';\n /**\n * Lado a partir do qual a barra esvazia. `'left'` (padrão) deixa a barra\n * ancorada à esquerda; `'right'` a ancora à direita (espelhado).\n * Só tem efeito junto com `progress`.\n */\n progressOrigin?: 'left' | 'right';\n /** Força o esquema de cores do card, independentemente do tema global. */\n mode?: 'light' | 'dark';\n}\n\nclass ToastApi {\n private seq = 0;\n private map = new Map<number, FxToast>();\n\n push(kind: ToastKind, title: string, messageOrOpts?: string | ToastOptions, opts?: ToastOptions): number {\n const id = ++this.seq;\n // Assinaturas suportadas:\n // push(kind, title, options)\n // push(kind, title, message, options) <- usada pela doc e mais intuitiva\n const message = typeof messageOrOpts === 'string' ? messageOrOpts : messageOrOpts?.message;\n const o: ToastOptions = { ...(typeof messageOrOpts === 'object' && messageOrOpts ? messageOrOpts : undefined), ...opts };\n const el = document.createElement('fx-toast') as FxToast;\n el.setAttribute('kind', kind);\n el.setAttribute('title', title);\n if (message) el.setAttribute('message', message);\n el.setAttribute('position', o.position ?? 'top-right');\n el.setAttribute('duration', String(o.duration ?? 4000));\n if (o.mode) el.setAttribute('mode', o.mode);\n if (o.progress) el.setAttribute('progress', o.progress);\n if (o.progressOrigin) el.setAttribute('progress-origin', o.progressOrigin);\n regionFor(o.position ?? 'top-right').appendChild(el);\n // O toast avisa quando sai do DOM (timer esgotado, botão de fechar ou\n // remoção externa). Sem este sync o mapa retém cada toast da sessão.\n el.addEventListener(REMOVED_EVENT, () => {\n if (this.map.get(id) === el) this.map.delete(id);\n });\n this.map.set(id, el);\n return id;\n }\n\n close(id: number) {\n this.map.get(id)?.dismiss();\n this.map.delete(id);\n }\n\n success = (t: string, m?: string, o?: ToastOptions) => this.push('success', t, m, o);\n error = (t: string, m?: string, o?: ToastOptions) => this.push('error', t, m, o);\n info = (t: string, m?: string, o?: ToastOptions) => this.push('info', t, m, o);\n warning = (t: string, m?: string, o?: ToastOptions) => this.push('warning', t, m, o);\n}\n\nexport const FenixToast = new ToastApi();\n// Exposto globalmente para uso em HTML puro (onclick=\"FenixToast.success(...)\")\n(globalThis as unknown as Record<string, unknown>).FenixToast = FenixToast;\n\nexport function defineFxToast() {\n if (!customElements.get('fx-toast')) customElements.define('fx-toast', FxToast);\n}\n\n"],"file":"components/toast/toast.js"}
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;AA0BA,MAAM,gBAAgB;AAEtB,MAAM,aAAwC;AAAA,EAC5C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACX;AAGA,MAAM,YAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AACR;AAGA,MAAM,WACJ;AAEF,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AAI,IAAI,EAAE,GAAG;AAClB,SAAK,IAAI,OAAO,EAAE;AAAA,EACpB;AAUF;AAEO,MAAM,aAAa,IAAI;AAE7B,WAAkD,aAAa;AAEzD,SAAS,gBAAgB;AAC9B,MAAI,CAAC,eAAe,IAAI,UAAU;AAChC,mBAAe,OAAO,YAAY,OAAO;AAC7C","names":[],"ignoreList":[],"sources":["../../../src/components/toast/toast.ts"],"sourcesContent":["/**\n * <fx-toast> — notificações imperativas com posição e duração configuráveis.\n *\n * Atributos: kind (success|error|info|warning), title, message,\n * position (top-left|top-center|top-right|bottom-left|bottom-center|bottom-right),\n * duration (ms; 0 = fixo até fechar), mode ('light'|'dark' — força o esquema de\n * cores do card independentemente do tema global), progress (booleano ou\n * 'always'|'hover'|'paused' — barra de contagem regressiva na cor do kind),\n * progress-origin (left|right — lado pelo qual a barra esvazia; padrão left).\n */\nconst POSITIONS = [\n \"top-left\",\n \"top-center\",\n \"top-right\",\n \"bottom-left\",\n \"bottom-center\",\n \"bottom-right\",\n] as const;\nexport type ToastPosition = (typeof POSITIONS)[number];\ntype ToastKind = \"success\" | \"error\" | \"info\" | \"warning\";\n\n/**\n * Evento interno disparado quando o <fx-toast> sai do DOM.\n * A API `FenixToast` o escuta para remover a entrada do mapa interno —\n * é o que impede o acúmulo de toasts já dispensados.\n */\nconst REMOVED_EVENT = \"fx-toast:removed\";\n\nconst KIND_COLOR: Record<ToastKind, string> = {\n success: \"var(--fx-color-success, #10b981)\",\n error: \"var(--fx-color-danger, #f43f5e)\",\n info: \"var(--fx-color-info, #0ea5e9)\",\n warning: \"var(--fx-color-warning, #f59e0b)\",\n};\n\n/** Ícone exibido no lugar da bolinha, conforme a variante. */\nconst KIND_ICON: Record<ToastKind, string> = {\n success: \"✓\",\n error: \"✕\",\n warning: \"!\",\n info: \"i\",\n};\n\n/** Ícone de copiar (SVG inline: não depende da fonte de ícones). */\nconst COPY_SVG =\n '<svg viewBox=\"0 0 24 24\" width=\"14\" height=\"14\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><rect x=\"9\" y=\"9\" width=\"12\" height=\"12\" rx=\"2\"></rect><path d=\"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1\"></path></svg>';\n\nconst CARD_CSS = `\n:host { display: contents; pointer-events: auto; }\n/* Modo explícito: sobrepõe os tokens herdados do tema global SOMENTE neste card. */\n:host([mode='dark']) {\n --fx-surface-background: #1e293b;\n --fx-text-default: #f1f5f9;\n --fx-text-muted: #94a3b8;\n --fx-border-default: #334155;\n --fx-shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);\n --fx-surface-surface-hover: rgba(255, 255, 255, .08);\n}\n:host([mode='light']) {\n --fx-surface-background: #ffffff;\n --fx-text-default: #1e293b;\n --fx-text-muted: #64748b;\n --fx-border-default: #e2e8f0;\n --fx-shadow-lg: 0 10px 30px rgba(0, 0, 0, .14);\n --fx-surface-surface-hover: rgba(0, 0, 0, .05);\n}\n.fx-icon {\n font-family: var(--fx-icon-font, 'Fenix Icons');\n font-weight: normal;\n font-style: normal;\n line-height: 1;\n letter-spacing: normal;\n display: inline-block;\n white-space: nowrap;\n direction: ltr;\n font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;\n -webkit-font-smoothing: antialiased;\n user-select: none;\n}\n.card {\n display: flex; align-items: center; gap: 10px;\n min-width: 260px; max-width: 360px;\n /* Altura mínima idêntica à de um toast COM título: sem título o card não\n fica \"achatado\" e o conjunto mantém o mesmo ritmo visual. */\n min-height: 56px;\n background: var(--fx-surface-background, #fff);\n color: var(--fx-text-default, #1e293b);\n border: 1px solid var(--fx-border-default, #e2e8f0);\n border-left: 4px solid var(--kind);\n border-radius: var(--fx-radius-md, 8px);\n box-shadow: var(--fx-shadow-lg, 0 10px 30px rgba(0,0,0,.14));\n padding: var(--fx-space-xs, 8px) var(--fx-space-md, 12px);\n font-family: inherit;\n animation: fx-toast-in .25s ease;\n}\n@keyframes fx-toast-in { from { opacity: 0; transform: translateY(-6px); } }\n.card.leaving { opacity: 0; transition: opacity .2s ease; }\n.card.no-title { min-height: 48px; }\n.icon {\n width: 22px; height: 22px; border-radius: 50%;\n background: var(--kind);\n color: #fff;\n display: flex; align-items: center; justify-content: center;\n font-size: 12px; font-weight: 700;\n flex: none; align-self: center;\n user-select: none;\n}\n.body { flex: 1; min-width: 0; align-self: center; }\n.title { font-weight: 600; font-size: 14px; }\n.msg {\n font-size: calc(var(--fx-font-size, 14px) - 2px);\n color: var(--fx-text-muted, #64748b);\n margin-top: 2px;\n word-break: break-word; white-space: pre-line;\n /* Mensagens longas mantêm o card no tamanho padrão e terminam em \"…\";\n \"Ver mais\" expande o toast (sem perder o restante do texto). */\n display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;\n line-clamp: 2; overflow: hidden;\n}\n.card.expanded .msg {\n display: block; overflow: visible;\n -webkit-line-clamp: unset; line-clamp: unset;\n}\n.more {\n all: unset; cursor: pointer; display: inline-block;\n margin-top: 4px; padding: 2px 0;\n font-size: 11px; font-weight: 600; color: var(--kind);\n}\n.more[hidden] { display: none; }\n.more:hover { text-decoration: underline; }\n.actions {\n display: flex; align-items: center; gap: 2px;\n flex: none; align-self: flex-start;\n}\n.copy, .close {\n all: unset; cursor: pointer; flex: none; line-height: 1;\n color: var(--fx-text-muted, #64748b); font-size: 15px; padding: 2px 4px; border-radius: 4px;\n}\n.copy[hidden] { display: none; }\n.copy { font-size: 14px; display: inline-flex; align-items: center; }\n.copy svg { display: block; }\n.copy.done { color: var(--fx-color-success, #10b981); }\n.copy:hover { color: var(--fx-color-primary, #6366f1); background: var(--fx-surface-surface-hover, rgba(0,0,0,.05)); }\n.close:hover { color: var(--fx-color-danger, #f43f5e); background: var(--fx-surface-surface-hover, rgba(0,0,0,.05)); }\n\n/* --- Barra de contagem regressiva (atributo progress) ---\n Fica na base do card e esvazia durante a duração, na cor do kind (--kind) —\n ou seja, acompanha success/error/warning/info sem configuração extra.\n\n O lado é configurável pelo atributo progress-origin (padrão: left):\n left → a barra drena da direita para a esquerda (ancorada à esquerda)\n right → a barra drena da esquerda para a direita (ancorada à direita)\n A origem entra como custom property, então os keyframes são compartilhados.\n\n Usa escalaX em vez de width: a animação escreve só na compositor, sem\n reflow por frame. */\n.card { position: relative; overflow: hidden; }\n.progress {\n position: absolute;\n left: 0;\n bottom: 0;\n width: 100%;\n height: 3px;\n background: var(--kind);\n transform-origin: var(--toast-progress-origin, left center);\n transform: scaleX(1);\n border-radius: 0 0 var(--fx-radius-md, 8px) var(--fx-radius-md, 8px);\n pointer-events: none;\n will-change: transform;\n}\n.progress.run { animation: fx-toast-drain var(--toast-duration, 4000ms) linear forwards; }\n/* Passar o mouse (ou focar) no toast pausa a contagem: a barra e o timer\n congelam juntos até o cursor sair — tempo de ler a mensagem inteira.\n progress=\"hover\" é mantido por compatibilidade e se comporta como\n \"always\" (o hover já pausa a contagem). */\n.card:hover .progress.run,\n.card:focus-within .progress.run { animation-play-state: paused; }\n@keyframes fx-toast-drain {\n from { transform: scaleX(1); }\n to { transform: scaleX(0); }\n}\n/* A barra só começa a correr no 2º frame: no 1º ela já apareceria zerada\n (o elemento acabou de ser inserido e a animação aplica o estado final). */\n.card.entering .progress { animation: none; }\n/* Ao dispensar, congela a barra: ela some junto com o card em .2s. */\n.card.leaving .progress { animation-play-state: paused; }\n@media (prefers-reduced-motion: reduce) {\n .progress.run { animation-duration: 0.01ms; }\n}\n`;\n\nexport class FxToast extends HTMLElement {\n static get observedAttributes() {\n return [\n \"kind\",\n \"title\",\n \"message\",\n \"duration\",\n \"icon\",\n \"mode\",\n \"progress\",\n \"progress-origin\",\n ];\n }\n\n /**\n * Exibe a barra de contagem regressiva na base do card.\n *\n * A barra esvazia durante exatamente `duration` e usa a cor do `kind`.\n * Com `duration=\"0\"` (toast fixo) a barra é omitida — não há tempo restante.\n *\n * - `'always'` (ou atributo vazio): barra sempre correndo.\n * - `'paused'`: barra visível, porém parada.\n * - `'hover'`: **compatibilidade** — equivale a `'always'`. O hover agora\n * pausa a contagem (timer + barra) em qualquer modo, então a barra \"só\n * correr sob o cursor\" deixou de fazer sentido.\n */\n get progress(): \"always\" | \"hover\" | \"paused\" | undefined {\n if (!this.hasAttribute(\"progress\")) return undefined;\n const v = this.getAttribute(\"progress\");\n return v === \"paused\" ? \"paused\" : \"always\";\n }\n set progress(value: \"always\" | \"hover\" | \"paused\" | undefined) {\n if (value) this.setAttribute(\"progress\", value);\n else this.removeAttribute(\"progress\");\n }\n\n /**\n * Lado a partir do qual a barra esvazia.\n *\n * - `'left'` (padrão): a barra fica ancorada à esquerda e drena da direita\n * para a esquerda.\n * - `'right'`: a barra fica ancorada à direita e drena da esquerda para a\n * direita (espelhado).\n *\n * Só tem efeito junto com `progress`; qualquer valor fora da lista cai em\n * `'left'`.\n */\n get progressOrigin(): \"left\" | \"right\" {\n return this.getAttribute(\"progress-origin\") === \"right\" ? \"right\" : \"left\";\n }\n set progressOrigin(value: \"left\" | \"right\") {\n this.setAttribute(\"progress-origin\", value);\n }\n\n /** Duração efetiva em ms (0 = fixo). Mesma regra usada no timer. */\n private get safeDuration(): number {\n const dur = Number(this.getAttribute(\"duration\") ?? \"4000\");\n if (dur === 0) return 0;\n return Math.max(Number.isNaN(dur) ? 4000 : dur, 1000);\n }\n\n /** Esquema de cores forçado do card: 'light' | 'dark' | undefined (segue o tema). */\n get mode(): \"light\" | \"dark\" | undefined {\n const m = this.getAttribute(\"mode\");\n return m === \"light\" || m === \"dark\" ? m : undefined;\n }\n set mode(value: \"light\" | \"dark\" | undefined) {\n if (value) this.setAttribute(\"mode\", value);\n else this.removeAttribute(\"mode\");\n }\n\n private timer: ReturnType<typeof setTimeout> | null = null;\n /** Tempo restante (ms) quando a contagem está pausada no hover/foco. */\n private remaining = 0;\n /** Instante em que o timer atual começou (para descontar o tempo decorrido). */\n private startedAt = 0;\n /** Cursor sobre o toast: não retoma a contagem no focusout. */\n private hovering = false;\n /** Já saiu do DOM — impede retomar a contagem. */\n private disposed = false;\n /** Existe contagem regressiva (duration > 0) — toasts fixos nunca retomam. */\n private counting = false;\n /** Listeners de pausa/retomada registrados uma única vez. */\n private wired = false;\n\n constructor() {\n super();\n this.attachShadow({ mode: \"open\" });\n }\n\n connectedCallback() {\n if (!this.shadowRoot!.firstChild) this.#render();\n this.disposed = false;\n this.#wirePause();\n // Durações mínimas: valores muito baixos (ex.: digitação parcial no\n // playground) são elevados para 1s; 0 permanece fixo até fechar.\n const safe = this.safeDuration;\n this.counting = safe > 0;\n if (safe > 0 && !this.timer) this.#startTimer(safe);\n this.#syncProgress();\n // jsdom não calcula layout: o \"Ver mais\" fica oculto (scrollHeight 0).\n this.#syncMore();\n }\n\n /**\n * Pausa a contagem enquanto o cursor (ou o foco) estiver no toast e retoma\n * de onde parou ao sair — assim uma mensagem longa pode ser lida inteira.\n * A barra de progresso pausa junto (regra CSS de :hover/:focus-within).\n */\n #wirePause(): void {\n if (this.wired) return;\n this.wired = true;\n this.addEventListener(\"mouseenter\", () => {\n this.hovering = true;\n this.#pauseTimer();\n });\n this.addEventListener(\"mouseleave\", () => {\n this.hovering = false;\n this.#resumeTimer();\n });\n // Teclado (botões copiar/fechar/ver mais) também mantém o toast na tela.\n this.addEventListener(\"focusin\", () => this.#pauseTimer());\n this.addEventListener(\"focusout\", () => {\n if (!this.hovering) this.#resumeTimer();\n });\n }\n\n #startTimer(ms: number): void {\n this.remaining = ms;\n this.startedAt = Date.now();\n this.timer = setTimeout(() => {\n this.timer = null;\n this.dismiss();\n }, ms);\n }\n\n #pauseTimer(): void {\n if (!this.timer) return;\n clearTimeout(this.timer);\n this.timer = null;\n this.remaining = Math.max(\n 0,\n this.remaining - (Date.now() - this.startedAt),\n );\n }\n\n #resumeTimer(): void {\n if (!this.counting || this.timer || this.disposed) return;\n if (this.remaining <= 0) {\n this.dismiss();\n return;\n }\n this.#startTimer(this.remaining);\n }\n\n /**\n * Limpa recursos ao sair do DOM e avisa a API imperativa (`FenixToast`).\n *\n * O aviso é essencial: `dismiss()` (timer ou botão de fechar) tira o\n * elemento do DOM mas, sem isto, `ToastApi.map` continuaria segurando uma\n * referência forte para cada toast já dispensado — crescimento de memória\n * sem limite em uso prolongado.\n */\n disconnectedCallback() {\n this.disposed = true;\n if (this.timer) clearTimeout(this.timer);\n this.timer = null;\n this.dispatchEvent(\n new CustomEvent(REMOVED_EVENT, { bubbles: false, composed: false }),\n );\n }\n\n attributeChangedCallback(name: string) {\n // A duração é lida em dois lugares (timer + barra): se mudar com o toast\n // na tela, ambos precisam se realinhar.\n if (name === \"duration\") {\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n const safe = this.safeDuration;\n this.counting = safe > 0;\n if (safe > 0 && this.isConnected && !this.disposed)\n this.#startTimer(safe);\n }\n if (\n name === \"duration\" ||\n name === \"progress\" ||\n name === \"progress-origin\" ||\n name === \"kind\"\n ) {\n this.#syncProgress();\n }\n }\n\n /**\n * Aplica (ou remove) a barra de contagem regressiva.\n *\n * A barra só existe com `progress` e `duration > 0`. O tempo da animação\n * vem de `--toast-duration`, sempre igual ao do `setTimeout` que fecha o\n * toast — assim a barra e o desaparecimento nunca desalinham.\n */\n #syncProgress(): void {\n const card = this.shadowRoot?.querySelector<HTMLElement>(\".card\");\n if (!card) return;\n const bar = this.shadowRoot!.querySelector<HTMLElement>(\".progress\");\n const mode = this.progress;\n const dur = this.safeDuration;\n const shouldShow = !!mode && dur > 0;\n\n if (!shouldShow) {\n bar?.remove();\n card.classList.remove(\"entering\");\n return;\n }\n if (!bar) {\n this.shadowRoot!.querySelector(\".card\")!.insertAdjacentHTML(\n \"beforeend\",\n '<span class=\"progress\" part=\"progress\" aria-hidden=\"true\"></span>',\n );\n }\n const el = this.shadowRoot!.querySelector<HTMLElement>(\".progress\")!;\n el.style.setProperty(\"--toast-duration\", `${dur}ms`);\n // `left` (padrão) => origem à esquerda; `right` espelha a drenagem.\n el.style.setProperty(\n \"--toast-progress-origin\",\n `${this.progressOrigin} center`,\n );\n el.classList.remove(\"run\");\n // `paused` mantém a barra cheia e imóvel; os demais modos animam\n // (o hover pausa a animação junto com o timer, via CSS).\n if (mode !== \"paused\") el.classList.add(\"run\");\n // 1 frame sem animação para o browser registrar o estado inicial cheio\n // antes de a barra começar a esvaziar.\n card.classList.add(\"entering\");\n requestAnimationFrame(() =>\n requestAnimationFrame(() => card.classList.remove(\"entering\")),\n );\n }\n\n dismiss() {\n if (this.timer) clearTimeout(this.timer);\n this.timer = null;\n const card = this.shadowRoot!.querySelector(\".card\");\n if (card) {\n card.classList.add(\"leaving\");\n setTimeout(() => this.remove(), 200);\n } else {\n this.remove();\n }\n }\n\n #render() {\n const kind = (this.getAttribute(\"kind\") || \"info\") as ToastKind;\n const title = this.getAttribute(\"title\") ?? \"\";\n const msg = this.getAttribute(\"message\") ?? \"\";\n const color = KIND_COLOR[kind] ?? KIND_COLOR.info;\n const iconName = this.getAttribute(\"icon\");\n const isFxIcon = !!iconName && /^[a-z][a-z0-9_]*$/.test(iconName);\n if (isFxIcon) void import(\"../../icons\");\n const iconContent = isFxIcon\n ? iconName\n : (KIND_ICON[kind] ?? KIND_ICON.info);\n this.shadowRoot!.innerHTML = `\n <style>${CARD_CSS}</style>\n <div class=\"card${title ? \"\" : \" no-title\"}\" style=\"--kind:${color}\" role=\"status\" part=\"card\">\n <span class=\"icon${isFxIcon ? \" fx-icon\" : \"\"}\">${iconContent}</span>\n <div class=\"body\">\n ${title ? '<div class=\"title\" part=\"title\"></div>' : \"\"}\n ${msg ? '<div class=\"msg\" part=\"message\"></div>' : \"\"}\n ${msg ? '<button class=\"more\" part=\"more\" hidden>Ver mais</button>' : \"\"}\n </div>\n <div class=\"actions\">\n ${msg ? `<button class=\"copy\" part=\"copy\" hidden aria-label=\"Copiar mensagem\" title=\"Copiar mensagem\">${COPY_SVG}</button>` : \"\"}\n <button class=\"close\" aria-label=\"Fechar\" title=\"Fechar\">✕</button>\n </div>\n </div>`;\n const t = this.shadowRoot!.querySelector<HTMLElement>(\".title\");\n const m = this.shadowRoot!.querySelector<HTMLElement>(\".msg\");\n if (t) t.textContent = title;\n if (m) {\n m.textContent = msg;\n // Dica nativa com o texto completo: passar o mouse na mensagem mostra\n // tudo, mesmo quando o card está truncado em 2 linhas.\n m.title = msg;\n }\n const card = this.shadowRoot!.querySelector<HTMLElement>(\".card\")!;\n const more = this.shadowRoot!.querySelector<HTMLButtonElement>(\".more\");\n const copy = this.shadowRoot!.querySelector<HTMLButtonElement>(\".copy\");\n more?.addEventListener(\"click\", () => {\n const expanded = card.classList.toggle(\"expanded\");\n more.textContent = expanded ? \"Ver menos\" : \"Ver mais\";\n // O botão de copiar só aparece com o texto aberto (não polui o card no\n // tamanho padrão). Enquanto o texto está expandido o toast não fecha.\n if (copy) copy.hidden = !expanded;\n if (expanded) this.#pauseTimer();\n });\n copy?.addEventListener(\"click\", (e) => {\n const btn = e.currentTarget as HTMLButtonElement;\n const text = [title, msg].filter(Boolean).join(\"\\n\");\n navigator.clipboard?.writeText(text).catch(() => {\n /* clipboard indisponível */\n });\n // Feedback: check verde + dica \"Copiado!\" por 1,2s.\n btn.classList.add(\"done\");\n btn.title = \"Copiado!\";\n setTimeout(() => {\n btn.classList.remove(\"done\");\n btn.title = \"Copiar mensagem\";\n }, 1200);\n });\n this.shadowRoot!.querySelector(\".close\")!.addEventListener(\"click\", () =>\n this.dismiss(),\n );\n }\n\n /**\n * Mostra \"Ver mais\" somente quando a mensagem passou de 2 linhas.\n * Sem layout (jsdom) scrollHeight/clientHeight são 0 → fica oculto.\n */\n #syncMore(): void {\n const card = this.shadowRoot?.querySelector<HTMLElement>(\".card\");\n const more = this.shadowRoot?.querySelector<HTMLButtonElement>(\".more\");\n const msg = this.shadowRoot?.querySelector<HTMLElement>(\".msg\");\n if (!card || !more || !msg) return;\n if (card.classList.contains(\"expanded\")) {\n more.hidden = false;\n return;\n }\n more.hidden = !(msg.scrollHeight - msg.clientHeight > 1);\n }\n}\n\n/* ---------- Regiões por posição na tela ---------- */\nfunction regionFor(position: ToastPosition): HTMLElement {\n let region = document.querySelector<HTMLElement>(\n `[data-fx-toast-region=\"${position}\"]`,\n );\n if (!region) {\n region = document.createElement(\"div\");\n region.setAttribute(\"data-fx-toast-region\", position);\n const [vertical, horizontal] = position.split(\"-\") as [string, string];\n const style = region.style as CSSStyleDeclaration & Record<string, string>;\n style.position = \"fixed\";\n style[vertical] = \"16px\";\n if (horizontal === \"center\") {\n style.left = \"50%\";\n style.transform = \"translateX(-50%)\";\n } else {\n style[horizontal] = \"16px\";\n }\n style.display = \"flex\";\n style.flexDirection = \"column\";\n style.gap = \"8px\";\n style.zIndex = \"1100\";\n style.pointerEvents = \"none\";\n // Os cards reabilitam pointer-events via `:host { pointer-events: auto }` (herança),\n // sem necessidade de MutationObserver.\n document.body.appendChild(region);\n }\n return region;\n}\n\nexport interface ToastOptions {\n /** Texto secundário (também aceito como 2º argumento dos métodos). */\n message?: string;\n position?: ToastPosition;\n /** Tempo em ms até sumir. 0 = fixo até fechar. Padrão: 4000 */\n duration?: number;\n /**\n * Barra de contagem regressiva na base do card, na cor do `kind`.\n * `'always'` (padrão) corre sempre; `'hover'` só enquanto o cursor estiver\n * sobre o toast; `'paused'` exibe a barra cheia, porém imóvel.\n * Sem efeito com `duration: 0` (não há tempo restante a representar).\n */\n progress?: \"always\" | \"hover\" | \"paused\";\n /**\n * Lado a partir do qual a barra esvazia. `'left'` (padrão) deixa a barra\n * ancorada à esquerda; `'right'` a ancora à direita (espelhado).\n * Só tem efeito junto com `progress`.\n */\n progressOrigin?: \"left\" | \"right\";\n /** Força o esquema de cores do card, independentemente do tema global. */\n mode?: \"light\" | \"dark\";\n}\n\nclass ToastApi {\n private seq = 0;\n private map = new Map<number, FxToast>();\n\n push(\n kind: ToastKind,\n title: string,\n messageOrOpts?: string | ToastOptions,\n opts?: ToastOptions,\n ): number {\n const id = ++this.seq;\n // Assinaturas suportadas:\n // push(kind, title, options)\n // push(kind, title, message, options) <- usada pela doc e mais intuitiva\n const message =\n typeof messageOrOpts === \"string\"\n ? messageOrOpts\n : messageOrOpts?.message;\n const o: ToastOptions = {\n ...(typeof messageOrOpts === \"object\" && messageOrOpts\n ? messageOrOpts\n : undefined),\n ...opts,\n };\n const el = document.createElement(\"fx-toast\") as FxToast;\n el.setAttribute(\"kind\", kind);\n el.setAttribute(\"title\", title);\n if (message) el.setAttribute(\"message\", message);\n el.setAttribute(\"position\", o.position ?? \"top-right\");\n el.setAttribute(\"duration\", String(o.duration ?? 4000));\n if (o.mode) el.setAttribute(\"mode\", o.mode);\n if (o.progress) el.setAttribute(\"progress\", o.progress);\n if (o.progressOrigin) el.setAttribute(\"progress-origin\", o.progressOrigin);\n regionFor(o.position ?? \"top-right\").appendChild(el);\n // O toast avisa quando sai do DOM (timer esgotado, botão de fechar ou\n // remoção externa). Sem este sync o mapa retém cada toast da sessão.\n el.addEventListener(REMOVED_EVENT, () => {\n if (this.map.get(id) === el) this.map.delete(id);\n });\n this.map.set(id, el);\n return id;\n }\n\n close(id: number) {\n this.map.get(id)?.dismiss();\n this.map.delete(id);\n }\n\n success = (t: string, m?: string, o?: ToastOptions) =>\n this.push(\"success\", t, m, o);\n error = (t: string, m?: string, o?: ToastOptions) =>\n this.push(\"error\", t, m, o);\n info = (t: string, m?: string, o?: ToastOptions) =>\n this.push(\"info\", t, m, o);\n warning = (t: string, m?: string, o?: ToastOptions) =>\n this.push(\"warning\", t, m, o);\n}\n\nexport const FenixToast = new ToastApi();\n// Exposto globalmente para uso em HTML puro (onclick=\"FenixToast.success(...)\")\n(globalThis as unknown as Record<string, unknown>).FenixToast = FenixToast;\n\nexport function defineFxToast() {\n if (!customElements.get(\"fx-toast\"))\n customElements.define(\"fx-toast\", FxToast);\n}\n"],"file":"components/toast/toast.js"}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FxFormElement } from '../../core/form-element';
|
|
2
2
|
/**
|
|
3
3
|
* <fx-toggle-button-group> — Grupo de botones de selección múltiple o única.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Form-Associated Custom Element: dentro de un <form> entra en el FormData
|
|
6
|
+
* con UNA entrada por valor seleccionado (via atributo `name`).
|
|
7
|
+
*
|
|
8
|
+
* Atributos: multiple (permite varios seleccionados), value (lista), name,
|
|
9
|
+
* size. Slots `option`: cada botón con [slot="option" value="..."].
|
|
10
|
+
* Eventos (composed): `change` (detail: { value: string[] }) e `valuesChange`
|
|
11
|
+
* (detail: { values: string[] }, two-way binding do Angular [(value)]).
|
|
8
12
|
*/
|
|
9
|
-
export declare class FxToggleButtonGroup extends
|
|
13
|
+
export declare class FxToggleButtonGroup extends FxFormElement {
|
|
10
14
|
static styles: string;
|
|
11
15
|
static get observedAttributes(): string[];
|
|
12
16
|
get value(): string[];
|
|
13
17
|
set value(v: string[]);
|
|
14
18
|
get multiple(): boolean;
|
|
19
|
+
/** No FormData do form: uma entrada `name` por valor selecionado. */
|
|
20
|
+
protected getFormValue(): string | FormData | null;
|
|
15
21
|
get options(): HTMLElement[];
|
|
16
22
|
protected render(): void;
|
|
23
|
+
/** form.reset(): restaura a seleção inicial e re-renderiza os botões. */
|
|
24
|
+
formResetCallback(): void;
|
|
17
25
|
private _bindOptions;
|
|
18
26
|
private _toggle;
|
|
19
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-button-group.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-button-group/toggle-button-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"toggle-button-group.d.ts","sourceRoot":"","sources":["../../../src/components/toggle-button-group/toggle-button-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAKxD;;;;;;;;;;GAUG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IACpD,OAAgB,MAAM,SA6BpB;IAEF,WAAoB,kBAAkB,IAAI,MAAM,EAAE,CAEjD;IAED,IAAI,KAAK,IAAI,MAAM,EAAE,CAGpB;IACD,IAAI,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAIpB;IAED,IAAI,QAAQ,IAAI,OAAO,CAAqC;IAE5D,qEAAqE;cAClD,YAAY,IAAI,MAAM,GAAG,QAAQ,GAAG,IAAI;IAQ3D,IAAI,OAAO,IAAI,WAAW,EAAE,CAE3B;cAEkB,MAAM,IAAI,IAAI;IAwBjC,yEAAyE;IAChE,iBAAiB,IAAI,IAAI;IAMlC,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,OAAO;CAqBhB;AAED,wBAAgB,yBAAyB,IAAI,OAAO,mBAAmB,CAEtE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FxFormElement } from "../../core/form-element.js";
|
|
2
2
|
import { css } from "../../core/css.js";
|
|
3
3
|
import { defineElement } from "../../core/define.js";
|
|
4
4
|
import { esc } from "../../core/sanitize.js";
|
|
5
|
-
const _FxToggleButtonGroup = class _FxToggleButtonGroup extends
|
|
5
|
+
const _FxToggleButtonGroup = class _FxToggleButtonGroup extends FxFormElement {
|
|
6
6
|
static get observedAttributes() {
|
|
7
7
|
return ["multiple", "size"];
|
|
8
8
|
}
|
|
@@ -12,10 +12,19 @@ const _FxToggleButtonGroup = class _FxToggleButtonGroup extends FxElement {
|
|
|
12
12
|
}
|
|
13
13
|
set value(v) {
|
|
14
14
|
this.setAttribute("value", v.join(","));
|
|
15
|
+
this.updateFormValue();
|
|
15
16
|
}
|
|
16
17
|
get multiple() {
|
|
17
18
|
return this.hasAttr("multiple");
|
|
18
19
|
}
|
|
20
|
+
/** No FormData do form: uma entrada `name` por valor selecionado. */
|
|
21
|
+
getFormValue() {
|
|
22
|
+
const values = this.value;
|
|
23
|
+
if (!this.name || values.length === 0) return null;
|
|
24
|
+
const fd = new FormData();
|
|
25
|
+
values.forEach((v) => fd.append(this.name, v));
|
|
26
|
+
return fd;
|
|
27
|
+
}
|
|
19
28
|
get options() {
|
|
20
29
|
return Array.from(this.children).filter((el) => el.matches('[slot="option"]')).map((el) => el);
|
|
21
30
|
}
|
|
@@ -33,6 +42,13 @@ const _FxToggleButtonGroup = class _FxToggleButtonGroup extends FxElement {
|
|
|
33
42
|
</div>
|
|
34
43
|
`);
|
|
35
44
|
this._bindOptions();
|
|
45
|
+
this.updateFormValue();
|
|
46
|
+
}
|
|
47
|
+
/** form.reset(): restaura a seleção inicial e re-renderiza os botões. */
|
|
48
|
+
formResetCallback() {
|
|
49
|
+
this.setAttribute("value", this._initialValue);
|
|
50
|
+
this.render();
|
|
51
|
+
this.updateFormValue();
|
|
36
52
|
}
|
|
37
53
|
_bindOptions() {
|
|
38
54
|
Array.from(this.root.querySelectorAll(".option") || []).forEach((opt) => {
|
|
@@ -62,6 +78,7 @@ const _FxToggleButtonGroup = class _FxToggleButtonGroup extends FxElement {
|
|
|
62
78
|
o.setAttribute("aria-pressed", String(on));
|
|
63
79
|
});
|
|
64
80
|
this.dispatchEvent(new CustomEvent("change", { bubbles: true, composed: true, detail: { value: current } }));
|
|
81
|
+
this.dispatchEvent(new CustomEvent("valuesChange", { bubbles: true, composed: true, detail: { values: [...current] } }));
|
|
65
82
|
}
|
|
66
83
|
};
|
|
67
84
|
_FxToggleButtonGroup.styles = css`
|