ui-optago 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui-optago.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* ============================================================================
2
- UI ÓPTAGO — Design System v1.0.4 (JavaScript)
2
+ UI ÓPTAGO: Design System v1.1.0 (JavaScript)
3
3
  Sem dependências de build. Carregue no <head> SEM defer para evitar
4
4
  flash de tema errado (FOUC):
5
5
 
@@ -42,11 +42,11 @@
42
42
 
43
43
  // Fonte única da versão exibida no badge do header e no rodapé
44
44
  // (elementos com o atributo data-op-version). Atualize só aqui.
45
- var VERSION = '1.0.4';
45
+ var VERSION = '1.1.0';
46
46
  OptagoUI.version = VERSION;
47
47
 
48
48
  /* --------------------------------------------------------------------------
49
- 1. TEMA — aplicado imediatamente (antes do primeiro paint)
49
+ 1. TEMA: aplicado imediatamente (antes do primeiro paint)
50
50
  -------------------------------------------------------------------------- */
51
51
  var THEME_KEY = 'op-theme';
52
52
 
@@ -138,7 +138,7 @@
138
138
  };
139
139
 
140
140
  /* --------------------------------------------------------------------------
141
- 4. TOASTS — OptagoUI.toast('Mensagem', 'success'|'error'|'warning'|'info')
141
+ 4. TOASTS: OptagoUI.toast('Mensagem', 'success'|'error'|'warning'|'info')
142
142
  -------------------------------------------------------------------------- */
143
143
  var TOAST_ICONS = {
144
144
  success: 'ph-check-circle',
@@ -166,11 +166,17 @@
166
166
  toast.innerHTML =
167
167
  '<div class="op-toast-icon"><i class="ph ' + (TOAST_ICONS[type] || TOAST_ICONS.info) + '"></i></div>' +
168
168
  '<span></span>' +
169
- '<button class="op-toast-close" aria-label="Fechar"><i class="ph ph-x"></i></button>';
169
+ '<button class="op-toast-close" aria-label="Fechar"><i class="ph ph-x"></i></button>' +
170
+ '<div class="op-toast-progress"><div class="op-toast-progress-bar"></div></div>';
170
171
  toast.querySelector('span').textContent = message;
171
172
  container.appendChild(toast);
172
173
 
174
+ var bar = toast.querySelector('.op-toast-progress-bar');
173
175
  var removed = false;
176
+ var timer = null;
177
+ var remaining = duration;
178
+ var startedAt = 0;
179
+
174
180
  var dismiss = function () {
175
181
  if (removed) return;
176
182
  removed = true;
@@ -178,13 +184,43 @@
178
184
  setTimeout(function () { toast.remove(); }, 320);
179
185
  };
180
186
 
187
+ // Anima a barra de largura atual até 0 ao longo de `ms`; usar
188
+ // transition (não @keyframes) permite congelar no valor exato em pause().
189
+ var run = function (ms) {
190
+ startedAt = Date.now();
191
+ timer = setTimeout(dismiss, ms);
192
+ requestAnimationFrame(function () {
193
+ bar.style.transitionDuration = ms + 'ms';
194
+ bar.style.width = '0%';
195
+ });
196
+ };
197
+
198
+ var pause = function () {
199
+ if (removed || !timer) return;
200
+ clearTimeout(timer);
201
+ timer = null;
202
+ remaining -= Date.now() - startedAt;
203
+ // Congela a barra no ponto exato em px (transition-duration 0 = sem salto).
204
+ bar.style.width = getComputedStyle(bar).width;
205
+ bar.style.transitionDuration = '0ms';
206
+ };
207
+
208
+ var resume = function () {
209
+ if (removed || timer || remaining <= 0) return;
210
+ run(remaining);
211
+ };
212
+
213
+ toast.addEventListener('mouseenter', pause);
214
+ toast.addEventListener('mouseleave', resume);
215
+ toast.addEventListener('focusin', pause);
216
+ toast.addEventListener('focusout', resume);
181
217
  toast.querySelector('.op-toast-close').addEventListener('click', dismiss);
182
218
 
183
219
  requestAnimationFrame(function () {
184
220
  requestAnimationFrame(function () { toast.classList.add('is-visible'); });
185
221
  });
186
222
 
187
- setTimeout(dismiss, duration);
223
+ run(duration);
188
224
 
189
225
  return toast;
190
226
  };
@@ -209,7 +245,7 @@
209
245
  };
210
246
 
211
247
  /* --------------------------------------------------------------------------
212
- 5b. TABULATOR — tabela avançada com tema Óptago
248
+ 5b. TABULATOR: tabela avançada com tema Óptago
213
249
  Uso: OptagoUI.tabulator('#minhaTabela', { data: [...], columns: [...] })
214
250
  Carrega a biblioteca (CDN) sob demanda; o CSS base do Tabulator é
215
251
  inserido ANTES do ui-optago.css para que o tema personalizado
@@ -257,7 +293,7 @@
257
293
  };
258
294
 
259
295
  /* --------------------------------------------------------------------------
260
- 5c. TELA DE CARREGAMENTO — overlay em tela cheia
296
+ 5c. TELA DE CARREGAMENTO: overlay em tela cheia
261
297
  Uso: OptagoUI.showLoading('Salvando...') ... OptagoUI.hideLoading()
262
298
  ou data-op-loading-form no <form> para acionar sozinho no submit.
263
299
  -------------------------------------------------------------------------- */
@@ -304,7 +340,7 @@
304
340
  });
305
341
 
306
342
  /* --------------------------------------------------------------------------
307
- 6. HELPERS DO SHOWCASE — copiar HTML / ver código
343
+ 6. HELPERS DO SHOWCASE: copiar HTML / ver código
308
344
  -------------------------------------------------------------------------- */
309
345
  function dedentHTML(el) {
310
346
  var html = el.innerHTML.replace(/^\n+|\s+$/g, '');
@@ -499,7 +535,7 @@
499
535
  });
500
536
 
501
537
  // Toasts vindos do servidor (flash messages), sem precisar de <script>
502
- // inline — importante para funcionar com Content-Security-Policy estrito.
538
+ // inline: importante para funcionar com Content-Security-Policy estrito.
503
539
  // Uso: <div hidden data-op-toast='[{"type":"success","message":"Oi!"}]'></div>
504
540
  document.querySelectorAll('[data-op-toast]').forEach(function (el) {
505
541
  try {