@tooark/web-components 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -324,7 +324,8 @@ const PERSON_SVG = `
324
324
  * carregar, as iniciais de `name` (primeira letra, ou primeira mais última
325
325
  * quando há sobrenome); sem nome e sem imagem, um glifo de pessoa decorativo
326
326
  * (`aria-hidden`, a menos que o host tenha aria-label próprio). `color` troca
327
- * o tint primary por uma cor própria (texto na cor, fundo suave).
327
+ * o tint primary por uma cor própria (texto na cor, fundo suave) e
328
+ * `variant="solid"` preenche o fundo com a cor e escreve as iniciais em branco.
328
329
  */
329
330
  class ArkAvatar extends HTMLElementBase {
330
331
  constructor() {
@@ -339,7 +340,7 @@ class ArkAvatar extends HTMLElementBase {
339
340
  this.ownLabel = null;
340
341
  }
341
342
  static get observedAttributes() {
342
- return ["name", "src", "size", "shape", "color", "aria-label", "theme", "class", "testid"];
343
+ return ["name", "src", "size", "shape", "color", "variant", "aria-label", "theme", "class", "testid"];
343
344
  }
344
345
  connectedCallback() {
345
346
  upgradeProperties(this);
@@ -380,6 +381,9 @@ class ArkAvatar extends HTMLElementBase {
380
381
  getShape() {
381
382
  return (this.getAttribute("shape") || "").toLowerCase() === "square" ? "square" : "circle";
382
383
  }
384
+ getVariant() {
385
+ return (this.getAttribute("variant") || "").toLowerCase() === "solid" ? "solid" : "soft";
386
+ }
383
387
  render() {
384
388
  const initials = document.createElement("span");
385
389
  initials.setAttribute("aria-hidden", "true");
@@ -418,7 +422,7 @@ class ArkAvatar extends HTMLElementBase {
418
422
  this.imageEl.hidden = failed;
419
423
  this.imageEl.className = failed ? "" : "ark:h-full ark:w-full ark:object-cover";
420
424
  }
421
- // Cor própria: texto na cor e fundo suave por color-mix, como o badge.
425
+ // Cor própria, como o badge: suave é texto na cor e fundo por color-mix; sólido é fundo na cor e texto branco.
422
426
  applyCustomColor() {
423
427
  const color = this.getAttribute("color")?.trim();
424
428
  if (!color) {
@@ -426,8 +430,9 @@ class ArkAvatar extends HTMLElementBase {
426
430
  this.style.removeProperty("--ark-avatar-fg");
427
431
  return;
428
432
  }
429
- this.style.setProperty("--ark-avatar-bg", `color-mix(in oklab, ${color} 18%, transparent)`);
430
- this.style.setProperty("--ark-avatar-fg", color);
433
+ const solid = this.getVariant() === "solid";
434
+ this.style.setProperty("--ark-avatar-bg", solid ? color : `color-mix(in oklab, ${color} 18%, transparent)`);
435
+ this.style.setProperty("--ark-avatar-fg", solid ? "#fff" : color);
431
436
  }
432
437
  applyOwnClasses(next) {
433
438
  this.syncingClass = true;
@@ -469,7 +474,9 @@ class ArkAvatar extends HTMLElementBase {
469
474
  ].join(" ");
470
475
  const colors = this.getAttribute("color")?.trim()
471
476
  ? "ark:bg-(--ark-avatar-bg) ark:text-(--ark-avatar-fg)"
472
- : "ark:bg-primary-soft ark:text-primary-soft-fg";
477
+ : this.getVariant() === "solid"
478
+ ? "ark:bg-primary ark:text-primary-fg"
479
+ : "ark:bg-primary-soft ark:text-primary-soft-fg";
473
480
  this.applyOwnClasses([
474
481
  "ark:inline-flex ark:shrink-0 ark:items-center ark:justify-center ark:overflow-hidden ark:align-middle ark:font-semibold ark:uppercase ark:leading-none ark:select-none",
475
482
  sizing.box,
@@ -2536,8 +2543,10 @@ let nextId$1 = 0;
2536
2543
  * formulário; os dois são controles nativos, então <fieldset disabled> os
2537
2544
  * desabilita sem JS. `label` vira um <label for> próprio; sem ele o host
2538
2545
  * precisa de aria-label, ou de filhos (texto livre, links), que dão nome à
2539
- * caixa por aria-labelledby e a alternam ao clique. Os nós próprios ficam no
2540
- * início do host, marcados data-ark-chrome, antes dos filhos do usuário.
2546
+ * caixa por aria-labelledby e a alternam ao clique. `helper` acrescenta uma
2547
+ * dica abaixo do rótulo, que descreve a caixa por aria-describedby. Os nós
2548
+ * próprios ficam no início do host, marcados data-ark-chrome, antes dos filhos
2549
+ * do usuário.
2541
2550
  */
2542
2551
  class ArkCheckbox extends HTMLElementBase {
2543
2552
  static get observedAttributes() {
@@ -2548,6 +2557,7 @@ class ArkCheckbox extends HTMLElementBase {
2548
2557
  "name",
2549
2558
  "value",
2550
2559
  "label",
2560
+ "helper",
2551
2561
  "aria-label",
2552
2562
  "size",
2553
2563
  "intent",
@@ -2563,6 +2573,7 @@ class ArkCheckbox extends HTMLElementBase {
2563
2573
  this.boxEl = null;
2564
2574
  this.iconEl = null;
2565
2575
  this.labelEl = null;
2576
+ this.helperEl = null;
2566
2577
  this.inputEl = null;
2567
2578
  this.observer = null;
2568
2579
  /** Glifo em exibição; a troca depois do primeiro render entra com scale-in. */
@@ -2717,11 +2728,11 @@ class ArkCheckbox extends HTMLElementBase {
2717
2728
  getSizing() {
2718
2729
  const size = (this.getAttribute("size") || "md").toLowerCase();
2719
2730
  const sizes = {
2720
- xs: { box: "ark:h-3.5 ark:w-3.5 ark:p-px", label: "ark:text-xs" },
2721
- sm: { box: "ark:h-4 ark:w-4 ark:p-px", label: "ark:text-sm" },
2722
- md: { box: "ark:h-5 ark:w-5 ark:p-0.5", label: "ark:text-sm" },
2723
- lg: { box: "ark:h-6 ark:w-6 ark:p-0.5", label: "ark:text-base" },
2724
- xl: { box: "ark:h-7 ark:w-7 ark:p-1", label: "ark:text-lg" }
2731
+ xs: { box: "ark:h-3.5 ark:w-3.5 ark:p-px", label: "ark:text-xs", helper: "ark:text-2xs" },
2732
+ sm: { box: "ark:h-4 ark:w-4 ark:p-px", label: "ark:text-sm", helper: "ark:text-xs" },
2733
+ md: { box: "ark:h-5 ark:w-5 ark:p-0.5", label: "ark:text-sm", helper: "ark:text-xs" },
2734
+ lg: { box: "ark:h-6 ark:w-6 ark:p-0.5", label: "ark:text-base", helper: "ark:text-sm" },
2735
+ xl: { box: "ark:h-7 ark:w-7 ark:p-1", label: "ark:text-lg", helper: "ark:text-base" }
2725
2736
  };
2726
2737
  return sizes[size] ?? sizes.md;
2727
2738
  }
@@ -2743,7 +2754,8 @@ class ArkCheckbox extends HTMLElementBase {
2743
2754
  input.tabIndex = -1;
2744
2755
  input.setAttribute("aria-hidden", "true");
2745
2756
  input.setAttribute("data-ark-chrome", "input");
2746
- // No início do host: a caixa antes do rótulo na ordem de leitura; o input oculto não conta.
2757
+ // No início do host: a caixa antes do rótulo na ordem de leitura; o input oculto não conta. A caixa vem antes
2758
+ // do input porque um <label> do app em volta do host rotula o primeiro controle rotulável dentro dele.
2747
2759
  this.prepend(box, input);
2748
2760
  this.boxEl = box;
2749
2761
  this.iconEl = icon;
@@ -2765,7 +2777,32 @@ class ArkCheckbox extends HTMLElementBase {
2765
2777
  }
2766
2778
  this.labelEl.htmlFor = this.boxEl?.id ?? "";
2767
2779
  this.labelEl.textContent = text;
2768
- this.labelEl.className = ["ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
2780
+ this.labelEl.className = ["ark:col-start-2 ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
2781
+ }
2782
+ // Dica própria: um <span> depois do rótulo, só enquanto `helper` existir, que descreve a caixa por aria-describedby.
2783
+ // Com ela o host vira grid (updateAppearance): a caixa na primeira coluna, rótulo e dica empilhados na segunda.
2784
+ syncHelper(sizing) {
2785
+ if (!this.boxEl)
2786
+ return;
2787
+ const text = this.getAttribute("helper");
2788
+ if (!text) {
2789
+ this.helperEl?.remove();
2790
+ this.helperEl = null;
2791
+ this.boxEl.removeAttribute("aria-describedby");
2792
+ return;
2793
+ }
2794
+ if (!this.helperEl) {
2795
+ const helper = document.createElement("span");
2796
+ helper.setAttribute("data-ark-chrome", "helper");
2797
+ helper.id = `${this.boxEl.id}-helper`;
2798
+ (this.labelEl ?? this.inputEl)?.after(helper);
2799
+ this.helperEl = helper;
2800
+ }
2801
+ if (this.helperEl.textContent !== text)
2802
+ this.helperEl.textContent = text;
2803
+ // order: 1 põe a dica depois do rótulo livre do usuário, que vem depois dos nós próprios.
2804
+ this.helperEl.className = ["ark:col-start-2 ark:order-1 ark:text-fg-muted", sizing.helper].join(" ");
2805
+ this.boxEl.setAttribute("aria-describedby", this.helperEl.id);
2769
2806
  }
2770
2807
  // Nome acessível da caixa: o <label for> próprio; senão aria-label; senão os filhos do usuário, via
2771
2808
  // aria-labelledby no host (que ganha um id quando falta).
@@ -2793,6 +2830,16 @@ class ArkCheckbox extends HTMLElementBase {
2793
2830
  this.boxEl.removeAttribute("aria-label");
2794
2831
  this.boxEl.removeAttribute("aria-labelledby");
2795
2832
  }
2833
+ // Nomeada pelo host, a dica entraria no nome: sai da árvore e segue como descrição (aria-describedby alcança
2834
+ // nós ocultos).
2835
+ if (this.helperEl) {
2836
+ if (this.boxEl.getAttribute("aria-labelledby") === this.id) {
2837
+ this.helperEl.setAttribute("aria-hidden", "true");
2838
+ }
2839
+ else {
2840
+ this.helperEl.removeAttribute("aria-hidden");
2841
+ }
2842
+ }
2796
2843
  }
2797
2844
  syncIcon(kind) {
2798
2845
  if (!this.iconEl || kind === this.iconKind)
@@ -2828,11 +2875,20 @@ class ArkCheckbox extends HTMLElementBase {
2828
2875
  const checked = this.checked;
2829
2876
  const indeterminate = this.indeterminate;
2830
2877
  const disabled = this.disabled;
2878
+ // Com `helper` o host é grid: caixa na primeira coluna, rótulo e dica empilhados na segunda.
2879
+ const layout = this.hasAttribute("helper")
2880
+ ? "ark:inline-grid ark:grid-cols-[auto_minmax(0,1fr)] ark:gap-x-2 ark:gap-y-0.5"
2881
+ : "ark:inline-flex ark:gap-2";
2831
2882
  // O host dimeriza tudo (caixa e rótulo) quando qualquer controle interno está desabilitado, inclusive
2832
2883
  // por <fieldset disabled>.
2833
- this.applyOwnClasses("ark:inline-flex ark:cursor-pointer ark:items-center ark:gap-2 ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50".split(" "));
2884
+ this.applyOwnClasses([
2885
+ layout,
2886
+ "ark:cursor-pointer ark:items-center ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50"
2887
+ ]
2888
+ .join(" ")
2889
+ .split(" "));
2834
2890
  this.boxEl.className = [
2835
- "ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-sm ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
2891
+ "ark:col-start-1 ark:row-start-1 ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-sm ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
2836
2892
  palette.ring,
2837
2893
  sizing.box,
2838
2894
  checked || indeterminate
@@ -2843,6 +2899,7 @@ class ArkCheckbox extends HTMLElementBase {
2843
2899
  this.boxEl.disabled = disabled;
2844
2900
  this.syncIcon(indeterminate ? "mixed" : checked ? "check" : "none");
2845
2901
  this.syncLabel(sizing);
2902
+ this.syncHelper(sizing);
2846
2903
  this.syncName();
2847
2904
  this.inputEl.checked = checked;
2848
2905
  this.inputEl.indeterminate = indeterminate;
@@ -2853,6 +2910,8 @@ class ArkCheckbox extends HTMLElementBase {
2853
2910
  applyTestHooks(this, "checkbox", this.inputEl, "input");
2854
2911
  if (this.labelEl)
2855
2912
  applyTestHooks(this, "checkbox", this.labelEl, "label");
2913
+ if (this.helperEl)
2914
+ applyTestHooks(this, "checkbox", this.helperEl, "helper");
2856
2915
  }
2857
2916
  }
2858
2917
  ArkCheckbox.tagName = "ark-checkbox";
@@ -3445,7 +3504,9 @@ function normalize(text) {
3445
3504
  * e um listbox oculto que é dono das opções visíveis por `aria-owns`. Itens
3446
3505
  * e cabeçalhos se ordenam por `order` no CSS, então nada é inserido entre os
3447
3506
  * filhos. Com `filter` o texto filtra localmente pelo `label` dos itens; em
3448
- * qualquer caso `ark-query` sai com debounce para busca assíncrona. O foco
3507
+ * qualquer caso `ark-query` sai com debounce para busca assíncrona. Sem opções
3508
+ * visíveis a mensagem é `noResults`; `hint` a troca enquanto o campo está
3509
+ * vazio e `busy` (busca em andamento) a troca por `searching`. O foco
3449
3510
  * fica sempre no campo; setas movem a opção ativa (`aria-activedescendant`),
3450
3511
  * Enter seleciona, Esc fecha; `hotkey` abre de qualquer lugar da página. A
3451
3512
  * página para de rolar enquanto aberta, salvo com `no-scroll-lock`.
@@ -3459,6 +3520,8 @@ class ArkCommandPalette extends HTMLElementBase {
3459
3520
  "filter",
3460
3521
  "query-delay",
3461
3522
  "label",
3523
+ "hint",
3524
+ "busy",
3462
3525
  "theme",
3463
3526
  "lang",
3464
3527
  "locale-json",
@@ -3660,6 +3723,13 @@ class ArkCommandPalette extends HTMLElementBase {
3660
3723
  set noScrollLock(value) {
3661
3724
  this.toggleAttribute("no-scroll-lock", core.coerceBooleanAttr(value));
3662
3725
  }
3726
+ /** Busca assíncrona em andamento (atributo `busy`): o listbox fica `aria-busy` e, sem opções, aparece `searching`. */
3727
+ get busy() {
3728
+ return this.hasAttribute("busy");
3729
+ }
3730
+ set busy(value) {
3731
+ this.toggleAttribute("busy", core.coerceBooleanAttr(value));
3732
+ }
3663
3733
  /** Texto atual do campo de busca. */
3664
3734
  get query() {
3665
3735
  return this.inputEl?.value ?? "";
@@ -3743,15 +3813,31 @@ class ArkCommandPalette extends HTMLElementBase {
3743
3813
  applyTestHooks(this, "command-palette", header, "group");
3744
3814
  });
3745
3815
  this.listEl.setAttribute("aria-owns", visible.map((item) => item.id).join(" "));
3746
- this.emptyEl.hidden = visible.length > 0;
3747
- const noResults = this.getLocale().noResults;
3748
- if (this.emptyEl.textContent !== noResults)
3749
- this.emptyEl.textContent = noResults;
3816
+ this.syncEmpty(visible.length);
3750
3817
  const enabled = visible.filter((item) => !item.disabled);
3751
3818
  if (!enabled.some((item) => item.id === this.activeId))
3752
3819
  this.activeId = enabled[0]?.id ?? null;
3753
3820
  this.applyActive(items);
3754
3821
  }
3822
+ // Mensagem sem opções visíveis: `searching` com `busy`, o `hint` do app com o campo vazio, senão `noResults`.
3823
+ syncEmpty(visible) {
3824
+ if (!this.listEl || !this.emptyEl)
3825
+ return;
3826
+ const locale = this.getLocale();
3827
+ const busy = this.busy;
3828
+ const hint = this.getAttribute("hint");
3829
+ const text = busy ? locale.searching : hint && this.query.trim() === "" ? hint : locale.noResults;
3830
+ this.emptyEl.hidden = visible > 0;
3831
+ // Só escreve o que mudou: o observer (subtree) veria a troca do nó de texto e sincronizaria em laço.
3832
+ if (this.emptyEl.textContent !== text)
3833
+ this.emptyEl.textContent = text;
3834
+ if (busy) {
3835
+ this.listEl.setAttribute("aria-busy", "true");
3836
+ }
3837
+ else {
3838
+ this.listEl.removeAttribute("aria-busy");
3839
+ }
3840
+ }
3755
3841
  applyActive(items) {
3756
3842
  for (const item of items) {
3757
3843
  const active = item.id === this.activeId;
@@ -3912,8 +3998,7 @@ class ArkCommandPalette extends HTMLElementBase {
3912
3998
  this.inputEl.removeAttribute(attr);
3913
3999
  }
3914
4000
  }
3915
- if (this.emptyEl.textContent !== locale.noResults)
3916
- this.emptyEl.textContent = locale.noResults;
4001
+ this.syncEmpty(this.visibleItems().length);
3917
4002
  applyTestHooks(this, "command-palette", this);
3918
4003
  applyTestHooks(this, "command-palette", this.inputEl, "input");
3919
4004
  applyTestHooks(this, "command-palette", this.listEl, "list");
@@ -5147,11 +5232,12 @@ function cssLength$1(value) {
5147
5232
  * página e só anima (o console inferior, um painel lateral fixo). Os filhos
5148
5233
  * do usuário são o corpo e ficam onde estão; um filho `slot="footer"` vai ao
5149
5234
  * fim por CSS. O cabeçalho (título `h2` de `label` e botão de fechar) é o
5150
- * primeiro filho, marcado `data-ark-chrome`. `side` escolhe a borda, a
5151
- * direção do slide (com o easing `sheet`) e a borda desenhada; `size` é um
5152
- * preset ou um comprimento CSS no eixo da gaveta. `open` é a fonte da
5153
- * verdade, como no ark-dialog, e em overlay a página para de rolar enquanto
5154
- * aberta, salvo com `no-scroll-lock`.
5235
+ * primeiro filho, marcado `data-ark-chrome`; um container `slot="actions"`
5236
+ * entra na linha dele por CSS, entre o título e o fechar. `side` escolhe a
5237
+ * borda, a direção do slide (com o easing `sheet`) e a borda desenhada;
5238
+ * `size` é um preset ou um comprimento CSS no eixo da gaveta. `open` é a fonte
5239
+ * da verdade, como no ark-dialog, e em overlay a página para de rolar
5240
+ * enquanto aberta, salvo com `no-scroll-lock`.
5155
5241
  */
5156
5242
  class ArkDrawer extends HTMLElementBase {
5157
5243
  static get observedAttributes() {
@@ -5176,6 +5262,10 @@ class ArkDrawer extends HTMLElementBase {
5176
5262
  this.titleEl = null;
5177
5263
  this.closeEl = null;
5178
5264
  this.observer = null;
5265
+ /** Mede o filho `slot="actions"`: a largura dele é o espaço que o título deixa livre na linha do cabeçalho. */
5266
+ this.actionsObserver = null;
5267
+ /** O filho `slot="actions"` que o actionsObserver mede. */
5268
+ this.observedActions = null;
5179
5269
  this.ownClasses = [];
5180
5270
  this.syncingClass = false;
5181
5271
  this.state = "closed";
@@ -5200,7 +5290,8 @@ class ArkDrawer extends HTMLElementBase {
5200
5290
  connectedCallback() {
5201
5291
  upgradeProperties(this);
5202
5292
  if (!this.observer) {
5203
- this.observer = new MutationObserver(() => this.syncFooter());
5293
+ // Rodapé e ações que chegam depois (frameworks) ganham o hook; as ações também mudam o cabeçalho.
5294
+ this.observer = new MutationObserver(() => this.updateAppearance());
5204
5295
  this.observer.observe(this, { childList: true });
5205
5296
  }
5206
5297
  this.updateAppearance();
@@ -5213,6 +5304,9 @@ class ArkDrawer extends HTMLElementBase {
5213
5304
  disconnectedCallback() {
5214
5305
  this.observer?.disconnect();
5215
5306
  this.observer = null;
5307
+ this.actionsObserver?.disconnect();
5308
+ this.actionsObserver = null;
5309
+ this.observedActions = null;
5216
5310
  this.releaseTrap?.();
5217
5311
  this.releaseTrap = null;
5218
5312
  core.unlockScroll(this);
@@ -5424,8 +5518,8 @@ class ArkDrawer extends HTMLElementBase {
5424
5518
  .split(/\s+/)
5425
5519
  .filter(Boolean);
5426
5520
  }
5427
- syncHeader(label, showClose) {
5428
- if (!label && !showClose) {
5521
+ syncHeader(label, showClose, withActions) {
5522
+ if (!label && !showClose && !withActions) {
5429
5523
  this.headerEl?.remove();
5430
5524
  this.headerEl = null;
5431
5525
  this.titleEl = null;
@@ -5438,8 +5532,14 @@ class ArkDrawer extends HTMLElementBase {
5438
5532
  this.prepend(header);
5439
5533
  this.headerEl = header;
5440
5534
  }
5441
- this.headerEl.className =
5442
- "ark:sticky ark:top-0 ark:z-10 ark:-mx-6 ark:flex ark:items-start ark:gap-4 ark:bg-surface ark:px-6 ark:pt-6 ark:pb-4";
5535
+ // As ações vêm antes do cabeçalho (order) e ocupam 3rem até o fim da linha do título: ele sobe por cima desse
5536
+ // espaço e guarda ao menos a altura dessa linha.
5537
+ this.headerEl.className = [
5538
+ "ark:sticky ark:top-0 ark:z-10 ark:-mx-6 ark:flex ark:items-start ark:gap-4 ark:bg-surface ark:px-6 ark:pt-6 ark:pb-4",
5539
+ withActions ? "ark:-mt-12 ark:min-h-16" : ""
5540
+ ]
5541
+ .join(" ")
5542
+ .trim();
5443
5543
  if (label) {
5444
5544
  if (!this.titleEl) {
5445
5545
  const title = document.createElement("h2");
@@ -5448,7 +5548,13 @@ class ArkDrawer extends HTMLElementBase {
5448
5548
  this.titleEl = title;
5449
5549
  }
5450
5550
  this.titleEl.textContent = label;
5451
- this.titleEl.className = "ark:min-w-0 ark:flex-1 ark:text-base ark:leading-6 ark:font-semibold ark:text-fg";
5551
+ // Com ações, o título deixa livre a largura medida delas mais o espaço entre as duas.
5552
+ this.titleEl.className = [
5553
+ "ark:min-w-0 ark:flex-1 ark:text-base ark:leading-6 ark:font-semibold ark:text-fg",
5554
+ withActions ? "ark:me-[calc(var(--ark-drawer-actions-width,0px)+1rem)]" : ""
5555
+ ]
5556
+ .join(" ")
5557
+ .trim();
5452
5558
  }
5453
5559
  else {
5454
5560
  this.titleEl?.remove();
@@ -5479,6 +5585,28 @@ class ArkDrawer extends HTMLElementBase {
5479
5585
  if (footer)
5480
5586
  applyTestHooks(this, "drawer", footer, "footer");
5481
5587
  }
5588
+ // Passa a medir o filho `slot="actions"` atual (ou nenhum). Sem ResizeObserver (SSR, jsdom) o título não reserva
5589
+ // a largura delas, só o espaço entre os dois.
5590
+ syncActions(actions) {
5591
+ if (actions)
5592
+ applyTestHooks(this, "drawer", actions, "actions");
5593
+ if (actions === this.observedActions)
5594
+ return;
5595
+ this.actionsObserver?.disconnect();
5596
+ this.observedActions = actions;
5597
+ if (!actions) {
5598
+ this.style.removeProperty("--ark-drawer-actions-width");
5599
+ return;
5600
+ }
5601
+ if (typeof ResizeObserver === "undefined")
5602
+ return;
5603
+ if (!this.actionsObserver) {
5604
+ this.actionsObserver = new ResizeObserver(() => {
5605
+ this.style.setProperty("--ark-drawer-actions-width", `${this.observedActions?.offsetWidth ?? 0}px`);
5606
+ });
5607
+ }
5608
+ this.actionsObserver.observe(actions);
5609
+ }
5482
5610
  applyOwnClasses(next) {
5483
5611
  this.syncingClass = true;
5484
5612
  for (const cls of this.ownClasses) {
@@ -5515,7 +5643,9 @@ class ArkDrawer extends HTMLElementBase {
5515
5643
  this.setAttribute("tabindex", "-1");
5516
5644
  this.setAttribute("data-ark-side", this.side);
5517
5645
  this.setAttribute("data-ark-mode", this.mode);
5518
- this.syncHeader(label, !this.hasAttribute("no-close-button"));
5646
+ const actions = this.querySelector(':scope > [slot="actions"]');
5647
+ this.syncHeader(label, !this.hasAttribute("no-close-button"), actions !== null);
5648
+ this.syncActions(actions);
5519
5649
  // Nome acessível: o título; sem ele um aria-label do usuário fica.
5520
5650
  if (label && this.titleEl) {
5521
5651
  this.setAttribute("aria-labelledby", this.titleId);
@@ -5664,7 +5794,10 @@ const UPLOAD_SVG = `
5664
5794
  * seletor nativo e soltar arquivos na zona alimenta o mesmo input. Toda
5665
5795
  * mudança emite `change` com os arquivos e anuncia os nomes ao leitor de
5666
5796
  * tela. O rótulo aponta para o input (associação nativa) e nomeia o botão
5667
- * junto do próprio texto dele.
5797
+ * junto do próprio texto dele. Com `directory` o campo escolhe uma pasta: o
5798
+ * seletor abre em modo pasta, uma pasta solta é lida até o fim, a lista vira
5799
+ * um resumo e `change` leva também o caminho de cada arquivo. Sem ele, uma
5800
+ * pasta solta é recusada com aviso.
5668
5801
  */
5669
5802
  class ArkFileInput extends HTMLElementBase {
5670
5803
  constructor() {
@@ -5678,14 +5811,18 @@ class ArkFileInput extends HTMLElementBase {
5678
5811
  this.messageEl = null;
5679
5812
  /** Profundidade de dragenter/dragleave, porque eles disparam também nos filhos da zona. */
5680
5813
  this.dragDepth = 0;
5814
+ /** O último drop trouxe uma pasta que o campo não aceita: a lista mostra o aviso até a próxima seleção. */
5815
+ this.folderRejected = false;
5816
+ /** Caminho de cada arquivo vindo de um drop em modo pasta, na ordem de `files`; nulo quando veio do seletor. */
5817
+ this.droppedPaths = null;
5818
+ /** Conta as seleções: a leitura assíncrona de uma pasta solta só é publicada se nada veio depois dela. */
5819
+ this.selectionSeq = 0;
5681
5820
  // --- Interação ---
5682
5821
  // O change nativo do input oculto não sobe ao host: quem escuta no host recebe só o CustomEvent com detail.
5683
5822
  this.handleChange = (event) => {
5684
- event?.stopPropagation();
5685
- this.syncList();
5686
- const files = this.files;
5687
- core.announce(files.length ? files.map((file) => file.name).join(", ") : this.getLocale().noFile);
5688
- this.dispatchEvent(new CustomEvent("change", { detail: { files }, bubbles: true, composed: true }));
5823
+ event.stopPropagation();
5824
+ this.resetSelection();
5825
+ this.publish();
5689
5826
  };
5690
5827
  this.handleDragEnter = (event) => {
5691
5828
  if (this.isDisabled())
@@ -5708,28 +5845,46 @@ class ArkFileInput extends HTMLElementBase {
5708
5845
  if (this.dragDepth === 0)
5709
5846
  this.setDragover(false);
5710
5847
  };
5711
- // Soltar alimenta o mesmo input (FileList é atribuível): só o primeiro arquivo sem `multiple`.
5848
+ // Soltar alimenta o mesmo input (FileList é atribuível): só o primeiro arquivo sem `multiple`. Uma pasta não é um
5849
+ // arquivo (o navegador a entrega como um File vazio, que não dá para ler): sem `directory` fica de fora, com aviso
5850
+ // na lista e anúncio; com ele é lida até o fim.
5712
5851
  this.handleDrop = (event) => {
5713
5852
  if (this.isDisabled())
5714
5853
  return;
5715
5854
  event.preventDefault();
5716
5855
  this.dragDepth = 0;
5717
5856
  this.setDragover(false);
5718
- const dropped = event.dataTransfer?.files;
5719
- if (!dropped || dropped.length === 0 || !this.inputEl)
5857
+ if (!event.dataTransfer || !this.inputEl)
5858
+ return;
5859
+ const { files, folders } = ArkFileInput.readDrop(event.dataTransfer);
5860
+ if (files.length === 0 && folders.length === 0)
5861
+ return;
5862
+ if (this.directory) {
5863
+ void this.selectDropped(files, folders);
5864
+ return;
5865
+ }
5866
+ if (files.length === 0) {
5867
+ // Só pastas: a seleção fica como estava e não há `change`.
5868
+ this.folderRejected = true;
5869
+ this.syncList();
5870
+ core.announce(this.getLocale().foldersNotAccepted);
5720
5871
  return;
5872
+ }
5873
+ this.resetSelection();
5874
+ this.folderRejected = folders.length > 0;
5721
5875
  const transfer = new DataTransfer();
5722
- const count = this.multiple ? dropped.length : 1;
5876
+ const count = this.multiple ? files.length : 1;
5723
5877
  for (let index = 0; index < count; index += 1)
5724
- transfer.items.add(dropped[index]);
5878
+ transfer.items.add(files[index]);
5725
5879
  this.inputEl.files = transfer.files;
5726
- this.handleChange();
5880
+ this.publish();
5727
5881
  };
5728
5882
  }
5729
5883
  static get observedAttributes() {
5730
5884
  return [
5731
5885
  "accept",
5732
5886
  "multiple",
5887
+ "directory",
5733
5888
  "label",
5734
5889
  "helper",
5735
5890
  "error",
@@ -5765,6 +5920,21 @@ class ArkFileInput extends HTMLElementBase {
5765
5920
  get files() {
5766
5921
  return Array.from(this.inputEl?.files ?? []);
5767
5922
  }
5923
+ /**
5924
+ * Caminho de cada arquivo de `files`, na mesma ordem, a partir da pasta escolhida ou solta (`pasta/sub/a.txt`);
5925
+ * o nome do arquivo quando ele não veio de uma pasta.
5926
+ */
5927
+ get paths() {
5928
+ const dropped = this.droppedPaths;
5929
+ return this.files.map((file, index) => dropped?.[index] ?? (file.webkitRelativePath || file.name));
5930
+ }
5931
+ /** Escolhe uma pasta inteira: o seletor abre em modo pasta e a zona lê as pastas soltas. Padrão: desligado. */
5932
+ get directory() {
5933
+ return this.hasAttribute("directory");
5934
+ }
5935
+ set directory(value) {
5936
+ this.toggleAttribute("directory", core.coerceBooleanAttr(value));
5937
+ }
5768
5938
  get multiple() {
5769
5939
  return this.hasAttribute("multiple");
5770
5940
  }
@@ -5782,6 +5952,7 @@ class ArkFileInput extends HTMLElementBase {
5782
5952
  if (!this.inputEl)
5783
5953
  return;
5784
5954
  this.inputEl.value = "";
5955
+ this.resetSelection();
5785
5956
  this.syncList();
5786
5957
  }
5787
5958
  focus(options) {
@@ -5794,6 +5965,106 @@ class ArkFileInput extends HTMLElementBase {
5794
5965
  isDisabled() {
5795
5966
  return this.buttonEl ? this.buttonEl.matches(":disabled") : this.disabled;
5796
5967
  }
5968
+ // Uma seleção nova (seletor, drop ou clear) descarta o aviso, os caminhos do drop anterior e a leitura em curso.
5969
+ resetSelection() {
5970
+ this.folderRejected = false;
5971
+ this.droppedPaths = null;
5972
+ this.selectionSeq += 1;
5973
+ }
5974
+ // Lista, anúncio e `change` da seleção atual do input. Em modo pasta o anúncio é o resumo e `detail` leva os
5975
+ // caminhos; fora dele o detail é só `{ files }`, como sempre foi.
5976
+ publish() {
5977
+ this.syncList();
5978
+ const files = this.files;
5979
+ const locale = this.getLocale();
5980
+ if (this.directory) {
5981
+ const summary = this.summarize(locale);
5982
+ core.announce(files.length ? [summary.folder, summary.count].filter(Boolean).join(", ") : locale.noFolder);
5983
+ const detail = { files, paths: this.paths };
5984
+ this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
5985
+ return;
5986
+ }
5987
+ const selection = files.length ? files.map((file) => file.name).join(", ") : locale.noFile;
5988
+ core.announce(this.folderRejected ? `${selection}. ${locale.foldersNotAccepted}` : selection);
5989
+ this.dispatchEvent(new CustomEvent("change", { detail: { files }, bubbles: true, composed: true }));
5990
+ }
5991
+ // Resumo da seleção em modo pasta: o nome da pasta, quando todos os caminhos saem da mesma, a contagem e o tamanho.
5992
+ summarize(locale) {
5993
+ const files = this.files;
5994
+ const roots = new Set(this.paths.map((path) => (path.includes("/") ? path.slice(0, path.indexOf("/")) : "")));
5995
+ const [root = ""] = roots;
5996
+ return {
5997
+ folder: roots.size === 1 ? root : "",
5998
+ count: locale.fileCount.replace("{count}", String(files.length)),
5999
+ size: files.reduce((total, file) => total + file.size, 0)
6000
+ };
6001
+ }
6002
+ // Separa arquivos e pastas de um drop. A pasta só se distingue pela entrada (webkitGetAsEntry), que existe só
6003
+ // durante o evento; sem a API, ou num DataTransfer montado por código, tudo é arquivo.
6004
+ static readDrop(transfer) {
6005
+ const files = [];
6006
+ const folders = [];
6007
+ const items = Array.from(transfer.items ?? []);
6008
+ if (items.length === 0)
6009
+ return { files: Array.from(transfer.files ?? []), folders };
6010
+ for (const item of items) {
6011
+ if (item.kind !== "file")
6012
+ continue;
6013
+ const entry = typeof item.webkitGetAsEntry === "function" ? item.webkitGetAsEntry() : null;
6014
+ if (entry?.isDirectory) {
6015
+ folders.push(entry);
6016
+ continue;
6017
+ }
6018
+ const file = item.getAsFile();
6019
+ if (file)
6020
+ files.push(file);
6021
+ }
6022
+ return { files, folders };
6023
+ }
6024
+ // Lê uma pasta solta até o fim, descendo nas subpastas. readEntries devolve lotes (100 no Chromium), então é
6025
+ // chamado até vir vazio; uma entrada que falha ao ler fica de fora sem derrubar o resto.
6026
+ static async readFolder(folder, prefix, found) {
6027
+ const reader = folder.createReader();
6028
+ for (;;) {
6029
+ const batch = await new Promise((resolve) => {
6030
+ reader.readEntries(resolve, () => resolve([]));
6031
+ });
6032
+ if (batch.length === 0)
6033
+ return;
6034
+ for (const entry of batch) {
6035
+ const path = `${prefix}${entry.name}`;
6036
+ if (entry.isDirectory) {
6037
+ await ArkFileInput.readFolder(entry, `${path}/`, found);
6038
+ }
6039
+ else if (entry.isFile) {
6040
+ const file = await new Promise((resolve) => {
6041
+ entry.file(resolve, () => resolve(null));
6042
+ });
6043
+ if (file)
6044
+ found.push({ file, path });
6045
+ }
6046
+ }
6047
+ }
6048
+ }
6049
+ // Drop em modo pasta: as pastas são lidas até o fim e tudo vai para o input, cada arquivo de pasta com o caminho a
6050
+ // partir do nome dela (como o webkitRelativePath do seletor) e os arquivos soltos junto com o próprio nome.
6051
+ async selectDropped(files, folders) {
6052
+ this.resetSelection();
6053
+ const seq = this.selectionSeq;
6054
+ const found = files.map((file) => ({ file, path: file.name }));
6055
+ for (const folder of folders)
6056
+ await ArkFileInput.readFolder(folder, `${folder.name}/`, found);
6057
+ // Outra seleção chegou enquanto a pasta era lida: esta não vale mais.
6058
+ if (seq !== this.selectionSeq || !this.inputEl)
6059
+ return;
6060
+ found.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
6061
+ const transfer = new DataTransfer();
6062
+ for (const entry of found)
6063
+ transfer.items.add(entry.file);
6064
+ this.inputEl.files = transfer.files;
6065
+ this.droppedPaths = found.map((entry) => entry.path);
6066
+ this.publish();
6067
+ }
5797
6068
  setDragover(active) {
5798
6069
  if (this.hasAttribute("data-ark-dragover") === active)
5799
6070
  return;
@@ -5924,21 +6195,43 @@ class ArkFileInput extends HTMLElementBase {
5924
6195
  return `${(bytes / 1024).toFixed(1)} KB`;
5925
6196
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
5926
6197
  }
5927
- // Lista dos nomes (com o tamanho) ou a string noFile.
6198
+ // Lista dos nomes (com o tamanho) ou a string noFile; por último, o aviso da pasta recusada. Em modo pasta a
6199
+ // seleção pode ter centenas de arquivos, então a lista é uma linha só: a pasta, a contagem e o tamanho total.
5928
6200
  syncList() {
5929
6201
  if (!this.listEl)
5930
6202
  return;
5931
6203
  const files = this.files;
6204
+ const locale = this.getLocale();
6205
+ const directory = this.directory;
5932
6206
  const text = this.getSizing().text;
5933
6207
  this.listEl.textContent = "";
6208
+ // max-w-full: centrada na zona, a lista teria a largura do nome mais longo e o truncate dos itens nunca cortaria.
5934
6209
  this.listEl.className = [
5935
- "ark:m-0 ark:flex ark:list-none ark:flex-col ark:items-center ark:gap-0.5 ark:p-0",
6210
+ "ark:m-0 ark:flex ark:max-w-full ark:list-none ark:flex-col ark:items-center ark:gap-0.5 ark:p-0",
5936
6211
  text
5937
6212
  ].join(" ");
5938
6213
  if (files.length === 0) {
5939
6214
  const item = document.createElement("li");
5940
6215
  item.className = "ark:text-fg-muted";
5941
- item.textContent = this.getLocale().noFile;
6216
+ item.textContent = directory ? locale.noFolder : locale.noFile;
6217
+ this.listEl.appendChild(item);
6218
+ }
6219
+ else if (directory) {
6220
+ const summary = this.summarize(locale);
6221
+ const item = document.createElement("li");
6222
+ item.setAttribute("data-ark-chrome", "summary");
6223
+ item.className = "ark:inline-flex ark:max-w-full ark:items-baseline ark:gap-1.5 ark:text-fg";
6224
+ if (summary.folder) {
6225
+ const name = document.createElement("span");
6226
+ name.className = "ark:truncate";
6227
+ name.textContent = summary.folder;
6228
+ item.appendChild(name);
6229
+ }
6230
+ const total = document.createElement("span");
6231
+ total.className = summary.folder ? "ark:shrink-0 ark:text-xs ark:text-fg-muted" : "ark:shrink-0";
6232
+ total.textContent = `${summary.count} · ${ArkFileInput.formatSize(summary.size)}`;
6233
+ item.appendChild(total);
6234
+ applyTestHooks(this, "file-input", item, "summary");
5942
6235
  this.listEl.appendChild(item);
5943
6236
  return;
5944
6237
  }
@@ -5956,6 +6249,13 @@ class ArkFileInput extends HTMLElementBase {
5956
6249
  applyTestHooks(this, "file-input", item, "item");
5957
6250
  this.listEl.appendChild(item);
5958
6251
  }
6252
+ if (this.folderRejected) {
6253
+ const item = document.createElement("li");
6254
+ item.className = "ark:text-danger-soft-fg";
6255
+ item.textContent = locale.foldersNotAccepted;
6256
+ applyTestHooks(this, "file-input", item, "rejected");
6257
+ this.listEl.appendChild(item);
6258
+ }
5959
6259
  }
5960
6260
  updateAppearance() {
5961
6261
  if (!this.inputEl ||
@@ -5972,10 +6272,14 @@ class ArkFileInput extends HTMLElementBase {
5972
6272
  const palette = this.getPalette(intent);
5973
6273
  const sizing = this.getSizing();
5974
6274
  const disabled = this.disabled;
6275
+ const directory = this.directory;
5975
6276
  const error = this.hasAttribute("error") || this.hasAttribute("error-message");
5976
6277
  const dragover = this.hasAttribute("data-ark-dragover");
5977
6278
  this.inputEl.name = this.getAttribute("name") || "";
5978
- this.inputEl.multiple = this.multiple;
6279
+ // Com `directory` o seletor abre em modo pasta. Onde o navegador não tem esse modo (mobile mais antigo) o atributo
6280
+ // não faz nada e sobra o seletor de arquivos: `multiple` deixa escolher os arquivos da pasta de uma vez.
6281
+ this.inputEl.multiple = this.multiple || directory;
6282
+ this.inputEl.toggleAttribute("webkitdirectory", directory);
5979
6283
  this.inputEl.required = this.hasAttribute("required");
5980
6284
  this.inputEl.disabled = disabled;
5981
6285
  const accept = this.getAttribute("accept");
@@ -6015,13 +6319,14 @@ class ArkFileInput extends HTMLElementBase {
6015
6319
  palette.ring
6016
6320
  ].join(" ");
6017
6321
  this.buttonEl.disabled = disabled;
6018
- if (this.buttonEl.getAttribute("data-ark-label") !== locale.chooseFile) {
6322
+ const choose = directory ? locale.chooseFolder : locale.chooseFile;
6323
+ if (this.buttonEl.getAttribute("data-ark-label") !== choose) {
6019
6324
  this.buttonEl.innerHTML = `${UPLOAD_SVG}<span></span>`;
6020
- this.buttonEl.lastElementChild.textContent = locale.chooseFile;
6021
- this.buttonEl.setAttribute("data-ark-label", locale.chooseFile);
6325
+ this.buttonEl.lastElementChild.textContent = choose;
6326
+ this.buttonEl.setAttribute("data-ark-label", choose);
6022
6327
  }
6023
6328
  this.hintEl.className = ["ark:text-fg-muted", sizing.text].join(" ");
6024
- this.hintEl.textContent = locale.dropHint;
6329
+ this.hintEl.textContent = directory ? locale.dropFolderHint : locale.dropHint;
6025
6330
  this.syncList();
6026
6331
  // Label: associação nativa com o input; o botão é nomeado pelo rótulo mais o próprio texto.
6027
6332
  const labelText = this.getAttribute("label") || "";
@@ -8208,7 +8513,7 @@ let nextId = 0;
8208
8513
  * silêncio e `change` dispara só no que ganhou a marca; as setas movem o foco
8209
8514
  * e marcam, Espaço marca o focado, e um único deles fica na ordem de Tab (o
8210
8515
  * marcado, ou o primeiro habilitado). `label`, aria-label e filhos nomeiam a
8211
- * opção como no ark-checkbox.
8516
+ * opção e `helper` a descreve, como no ark-checkbox.
8212
8517
  */
8213
8518
  class ArkRadio extends HTMLElementBase {
8214
8519
  static get observedAttributes() {
@@ -8218,6 +8523,7 @@ class ArkRadio extends HTMLElementBase {
8218
8523
  "name",
8219
8524
  "value",
8220
8525
  "label",
8526
+ "helper",
8221
8527
  "aria-label",
8222
8528
  "size",
8223
8529
  "intent",
@@ -8233,6 +8539,7 @@ class ArkRadio extends HTMLElementBase {
8233
8539
  this.boxEl = null;
8234
8540
  this.dotEl = null;
8235
8541
  this.labelEl = null;
8542
+ this.helperEl = null;
8236
8543
  this.inputEl = null;
8237
8544
  this.observer = null;
8238
8545
  /** Raiz do grupo no último connect, para ressincronizar os que ficam quando este sai. */
@@ -8453,11 +8760,11 @@ class ArkRadio extends HTMLElementBase {
8453
8760
  getSizing() {
8454
8761
  const size = (this.getAttribute("size") || "md").toLowerCase();
8455
8762
  const sizes = {
8456
- xs: { box: "ark:h-3.5 ark:w-3.5", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-xs" },
8457
- sm: { box: "ark:h-4 ark:w-4", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-sm" },
8458
- md: { box: "ark:h-5 ark:w-5", dot: "ark:h-2 ark:w-2", label: "ark:text-sm" },
8459
- lg: { box: "ark:h-6 ark:w-6", dot: "ark:h-2.5 ark:w-2.5", label: "ark:text-base" },
8460
- xl: { box: "ark:h-7 ark:w-7", dot: "ark:h-3 ark:w-3", label: "ark:text-lg" }
8763
+ xs: { box: "ark:h-3.5 ark:w-3.5", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-xs", helper: "ark:text-2xs" },
8764
+ sm: { box: "ark:h-4 ark:w-4", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-sm", helper: "ark:text-xs" },
8765
+ md: { box: "ark:h-5 ark:w-5", dot: "ark:h-2 ark:w-2", label: "ark:text-sm", helper: "ark:text-xs" },
8766
+ lg: { box: "ark:h-6 ark:w-6", dot: "ark:h-2.5 ark:w-2.5", label: "ark:text-base", helper: "ark:text-sm" },
8767
+ xl: { box: "ark:h-7 ark:w-7", dot: "ark:h-3 ark:w-3", label: "ark:text-lg", helper: "ark:text-base" }
8461
8768
  };
8462
8769
  return sizes[size] ?? sizes.md;
8463
8770
  }
@@ -8479,6 +8786,7 @@ class ArkRadio extends HTMLElementBase {
8479
8786
  input.tabIndex = -1;
8480
8787
  input.setAttribute("aria-hidden", "true");
8481
8788
  input.setAttribute("data-ark-chrome", "input");
8789
+ // A opção vem antes do input: um <label> do app em volta do host rotula o primeiro controle rotulável.
8482
8790
  this.prepend(box, input);
8483
8791
  this.boxEl = box;
8484
8792
  this.dotEl = dot;
@@ -8499,7 +8807,32 @@ class ArkRadio extends HTMLElementBase {
8499
8807
  }
8500
8808
  this.labelEl.htmlFor = this.boxEl?.id ?? "";
8501
8809
  this.labelEl.textContent = text;
8502
- this.labelEl.className = ["ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
8810
+ this.labelEl.className = ["ark:col-start-2 ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
8811
+ }
8812
+ // Dica própria: um <span> depois do rótulo, só enquanto `helper` existir, que descreve a opção por aria-describedby.
8813
+ // Com ela o host vira grid (updateAppearance): a opção na primeira coluna, rótulo e dica empilhados na segunda.
8814
+ syncHelper(sizing) {
8815
+ if (!this.boxEl)
8816
+ return;
8817
+ const text = this.getAttribute("helper");
8818
+ if (!text) {
8819
+ this.helperEl?.remove();
8820
+ this.helperEl = null;
8821
+ this.boxEl.removeAttribute("aria-describedby");
8822
+ return;
8823
+ }
8824
+ if (!this.helperEl) {
8825
+ const helper = document.createElement("span");
8826
+ helper.setAttribute("data-ark-chrome", "helper");
8827
+ helper.id = `${this.boxEl.id}-helper`;
8828
+ (this.labelEl ?? this.inputEl)?.after(helper);
8829
+ this.helperEl = helper;
8830
+ }
8831
+ if (this.helperEl.textContent !== text)
8832
+ this.helperEl.textContent = text;
8833
+ // order: 1 põe a dica depois do rótulo livre do usuário, que vem depois dos nós próprios.
8834
+ this.helperEl.className = ["ark:col-start-2 ark:order-1 ark:text-fg-muted", sizing.helper].join(" ");
8835
+ this.boxEl.setAttribute("aria-describedby", this.helperEl.id);
8503
8836
  }
8504
8837
  syncName() {
8505
8838
  if (!this.boxEl)
@@ -8525,6 +8858,16 @@ class ArkRadio extends HTMLElementBase {
8525
8858
  this.boxEl.removeAttribute("aria-label");
8526
8859
  this.boxEl.removeAttribute("aria-labelledby");
8527
8860
  }
8861
+ // Nomeada pelo host, a dica entraria no nome: sai da árvore e segue como descrição (aria-describedby alcança
8862
+ // nós ocultos).
8863
+ if (this.helperEl) {
8864
+ if (this.boxEl.getAttribute("aria-labelledby") === this.id) {
8865
+ this.helperEl.setAttribute("aria-hidden", "true");
8866
+ }
8867
+ else {
8868
+ this.helperEl.removeAttribute("aria-hidden");
8869
+ }
8870
+ }
8528
8871
  }
8529
8872
  syncDot(checked, sizing) {
8530
8873
  if (!this.dotEl)
@@ -8560,9 +8903,18 @@ class ArkRadio extends HTMLElementBase {
8560
8903
  const sizing = this.getSizing();
8561
8904
  const checked = this.checked;
8562
8905
  const disabled = this.disabled;
8563
- this.applyOwnClasses("ark:inline-flex ark:cursor-pointer ark:items-center ark:gap-2 ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50".split(" "));
8906
+ // Com `helper` o host é grid: caixa na primeira coluna, rótulo e dica empilhados na segunda.
8907
+ const layout = this.hasAttribute("helper")
8908
+ ? "ark:inline-grid ark:grid-cols-[auto_minmax(0,1fr)] ark:gap-x-2 ark:gap-y-0.5"
8909
+ : "ark:inline-flex ark:gap-2";
8910
+ this.applyOwnClasses([
8911
+ layout,
8912
+ "ark:cursor-pointer ark:items-center ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50"
8913
+ ]
8914
+ .join(" ")
8915
+ .split(" "));
8564
8916
  this.boxEl.className = [
8565
- "ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-full ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
8917
+ "ark:col-start-1 ark:row-start-1 ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-full ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
8566
8918
  palette.ring,
8567
8919
  sizing.box,
8568
8920
  checked ? palette.on : "ark:border-border-strong ark:bg-surface ark:text-transparent ark:hover:bg-surface-muted"
@@ -8571,6 +8923,7 @@ class ArkRadio extends HTMLElementBase {
8571
8923
  this.boxEl.disabled = disabled;
8572
8924
  this.syncDot(checked, sizing);
8573
8925
  this.syncLabel(sizing);
8926
+ this.syncHelper(sizing);
8574
8927
  this.syncName();
8575
8928
  this.inputEl.checked = checked;
8576
8929
  this.inputEl.disabled = disabled;
@@ -8581,6 +8934,8 @@ class ArkRadio extends HTMLElementBase {
8581
8934
  applyTestHooks(this, "radio", this.inputEl, "input");
8582
8935
  if (this.labelEl)
8583
8936
  applyTestHooks(this, "radio", this.labelEl, "label");
8937
+ if (this.helperEl)
8938
+ applyTestHooks(this, "radio", this.helperEl, "helper");
8584
8939
  }
8585
8940
  }
8586
8941
  ArkRadio.tagName = "ark-radio";