@tooark/web-components 1.7.0 → 1.8.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
@@ -149,7 +149,8 @@ const CLOSE_SVG$3 = `
149
149
  * normalmente. `slot="icon"` fica à esquerda e `slot="action"` à direita,
150
150
  * posicionados por components.css sem sair do lugar (o ícone e o botão de
151
151
  * dispensar por posição absoluta na área reservada pelo padding; a ação por
152
- * float, então o texto contorna). `heading` cria um título próprio no início
152
+ * float, então o texto contorna; a que não fica na primeira linha desce sem
153
+ * cobrir a de cima). `heading` cria um título próprio no início
153
154
  * do host; `dismissible` põe o botão de dispensar no fim (chrome). `variant`
154
155
  * box (caixa arredondada) ou banner (largura toda, só borda inferior). `live`
155
156
  * define a live region: polite (role="status") ou assertive (role="alert"),
@@ -165,6 +166,9 @@ class ArkAlert extends HTMLElementBase {
165
166
  this.headingEl = null;
166
167
  this.dismissEl = null;
167
168
  this.observer = null;
169
+ /** Só existe com um `slot="action"`: a largura do host decide se a ação fica na primeira linha. */
170
+ this.actionObserver = null;
171
+ this.actionFrame = 0;
168
172
  this.dismissing = false;
169
173
  }
170
174
  static get observedAttributes() {
@@ -196,6 +200,7 @@ class ArkAlert extends HTMLElementBase {
196
200
  unfollowArkLocale(this);
197
201
  this.observer?.disconnect();
198
202
  this.observer = null;
203
+ this.unwatchAction();
199
204
  }
200
205
  attributeChangedCallback(name, _oldValue, newValue) {
201
206
  if (name === "class") {
@@ -321,8 +326,57 @@ class ArkAlert extends HTMLElementBase {
321
326
  if (icon)
322
327
  applyTestHooks(this, "alert", icon, "icon");
323
328
  const action = this.querySelector(':scope > [slot="action"]');
324
- if (action)
329
+ if (action) {
325
330
  applyTestHooks(this, "alert", action, "action");
331
+ this.watchAction();
332
+ }
333
+ else {
334
+ this.unwatchAction();
335
+ }
336
+ }
337
+ // --- Linha da ação ---
338
+ // A ação flutua na primeira linha, deslocada para cima para centrar um botão mais alto que a linha. Quando ela
339
+ // vem depois de um parágrafo ou de um texto que quebrou, ou não cabe ao lado dele, o float desce, e o mesmo
340
+ // deslocamento a fazia cobrir a linha de cima: o host mede onde ela ficou e components.css zera a margem
341
+ // (data-ark-action-below).
342
+ watchAction() {
343
+ if (!this.actionObserver && typeof ResizeObserver !== "undefined") {
344
+ // A reação espera o próximo frame: trocar a margem dentro do callback muda a altura do host, e o Chromium
345
+ // acusaria um laço de ResizeObserver.
346
+ this.actionObserver = new ResizeObserver(() => this.scheduleActionLine());
347
+ this.actionObserver.observe(this);
348
+ }
349
+ this.scheduleActionLine();
350
+ }
351
+ unwatchAction() {
352
+ this.actionObserver?.disconnect();
353
+ this.actionObserver = null;
354
+ cancelAnimationFrame(this.actionFrame);
355
+ this.actionFrame = 0;
356
+ this.removeAttribute("data-ark-action-below");
357
+ }
358
+ scheduleActionLine() {
359
+ if (this.actionFrame)
360
+ return;
361
+ this.actionFrame = requestAnimationFrame(() => {
362
+ this.actionFrame = 0;
363
+ this.syncActionLine();
364
+ });
365
+ }
366
+ syncActionLine() {
367
+ const action = this.querySelector(':scope > [slot="action"]');
368
+ if (!action || !this.isConnected || this.hidden)
369
+ return;
370
+ // Topo da ação sem a margem (que muda com o próprio estado), contra o início da primeira linha da mensagem:
371
+ // o fim do título próprio quando ele existe, senão o início da área de conteúdo do host.
372
+ const style = getComputedStyle(this);
373
+ const top = action.getBoundingClientRect().top - (Number.parseFloat(getComputedStyle(action).marginTop) || 0);
374
+ const firstLine = this.headingEl
375
+ ? this.headingEl.getBoundingClientRect().bottom
376
+ : this.getBoundingClientRect().top +
377
+ (Number.parseFloat(style.borderTopWidth) || 0) +
378
+ (Number.parseFloat(style.paddingTop) || 0);
379
+ this.toggleAttribute("data-ark-action-below", top - firstLine > 2);
326
380
  }
327
381
  applyOwnClasses(next) {
328
382
  this.syncingClass = true;
@@ -1007,6 +1061,14 @@ class ArkButton extends HTMLElementBase {
1007
1061
  get form() {
1008
1062
  return this.internals?.form ?? this.closest("form");
1009
1063
  }
1064
+ /**
1065
+ * Atribuir um id grava o atributo `form`, que associa o botão a um formulário de fora dele, como no
1066
+ * `<button form>` nativo; `null` ou `undefined` o removem. O React 19 atribui a prop como propriedade, e sem setter
1067
+ * a atribuição lançava.
1068
+ */
1069
+ set form(value) {
1070
+ reflectAttr(this, "form", value);
1071
+ }
1010
1072
  // O navegador só reconhece como botão padrão do formulário um botão de submit nativo; um elemento form-associated
1011
1073
  // nunca entra na submissão implícita, e um formulário com dois campos (login) não enviava no Enter. Fase de bolha:
1012
1074
  // o Enter que um componente ou o app já cancelou fica com eles.
@@ -1083,13 +1145,13 @@ class ArkButton extends HTMLElementBase {
1083
1145
  const variant = (this.getAttribute("variant") || "primary").toLowerCase();
1084
1146
  const attrIntent = this.getAttribute("intent");
1085
1147
  // Normaliza o intent antes de resolver a variante e o intent.
1086
- if (variant === "outline" || variant === "ghost" || variant === "solid") {
1148
+ if (variant === "outline" || variant === "ghost" || variant === "soft" || variant === "solid") {
1087
1149
  return {
1088
1150
  styleVariant: variant,
1089
1151
  intent: this.normalizeIntent(attrIntent)
1090
1152
  };
1091
1153
  }
1092
- // Se a variante não é "outline", "ghost" ou "solid", verifica se é uma variante de estilo baseada no intent.
1154
+ // Se a variante não é "outline", "ghost", "soft" ou "solid", verifica se é uma variante de estilo baseada no intent.
1093
1155
  if (variant === "primary" ||
1094
1156
  variant === "secondary" ||
1095
1157
  variant === "success" ||
@@ -1120,44 +1182,51 @@ class ArkButton extends HTMLElementBase {
1120
1182
  focusRing: "ark:ring-primary-ring",
1121
1183
  solid: "ark:bg-primary ark:text-primary-fg ark:border-transparent ark:hover:bg-primary-hover",
1122
1184
  outline: "ark:bg-transparent ark:text-primary-soft-fg ark:border-primary-border ark:hover:bg-primary-soft",
1123
- ghost: "ark:bg-transparent ark:text-primary-soft-fg ark:border-transparent ark:hover:bg-primary-soft"
1185
+ ghost: "ark:bg-transparent ark:text-primary-soft-fg ark:border-transparent ark:hover:bg-primary-soft",
1186
+ soft: "ark:bg-primary-soft ark:text-primary-soft-fg ark:border-transparent ark:hover:border-primary-border"
1124
1187
  },
1125
1188
  secondary: {
1126
1189
  focusRing: "ark:ring-secondary-ring",
1127
1190
  // "Solid" secundário é a superfície com borda (botão neutro de apoio).
1128
1191
  solid: "ark:bg-surface ark:text-fg ark:border-border-strong ark:hover:bg-surface-muted",
1129
1192
  outline: "ark:bg-transparent ark:text-secondary-soft-fg ark:border-secondary-border ark:hover:bg-secondary-soft",
1130
- ghost: "ark:bg-transparent ark:text-secondary-soft-fg ark:border-transparent ark:hover:bg-secondary-soft"
1193
+ ghost: "ark:bg-transparent ark:text-secondary-soft-fg ark:border-transparent ark:hover:bg-secondary-soft",
1194
+ soft: "ark:bg-secondary-soft ark:text-secondary-soft-fg ark:border-transparent ark:hover:border-secondary-border"
1131
1195
  },
1132
1196
  success: {
1133
1197
  focusRing: "ark:ring-success-ring",
1134
1198
  solid: "ark:bg-success ark:text-success-fg ark:border-transparent ark:hover:bg-success-hover",
1135
1199
  outline: "ark:bg-transparent ark:text-success-soft-fg ark:border-success-border ark:hover:bg-success-soft",
1136
- ghost: "ark:bg-transparent ark:text-success-soft-fg ark:border-transparent ark:hover:bg-success-soft"
1200
+ ghost: "ark:bg-transparent ark:text-success-soft-fg ark:border-transparent ark:hover:bg-success-soft",
1201
+ soft: "ark:bg-success-soft ark:text-success-soft-fg ark:border-transparent ark:hover:border-success-border"
1137
1202
  },
1138
1203
  warning: {
1139
1204
  focusRing: "ark:ring-warning-ring",
1140
1205
  solid: "ark:bg-warning ark:text-warning-fg ark:border-transparent ark:hover:bg-warning-hover",
1141
1206
  outline: "ark:bg-transparent ark:text-warning-soft-fg ark:border-warning-border ark:hover:bg-warning-soft",
1142
- ghost: "ark:bg-transparent ark:text-warning-soft-fg ark:border-transparent ark:hover:bg-warning-soft"
1207
+ ghost: "ark:bg-transparent ark:text-warning-soft-fg ark:border-transparent ark:hover:bg-warning-soft",
1208
+ soft: "ark:bg-warning-soft ark:text-warning-soft-fg ark:border-transparent ark:hover:border-warning-border"
1143
1209
  },
1144
1210
  danger: {
1145
1211
  focusRing: "ark:ring-danger-ring",
1146
1212
  solid: "ark:bg-danger ark:text-danger-fg ark:border-transparent ark:hover:bg-danger-hover",
1147
1213
  outline: "ark:bg-transparent ark:text-danger-soft-fg ark:border-danger-border ark:hover:bg-danger-soft",
1148
- ghost: "ark:bg-transparent ark:text-danger-soft-fg ark:border-transparent ark:hover:bg-danger-soft"
1214
+ ghost: "ark:bg-transparent ark:text-danger-soft-fg ark:border-transparent ark:hover:bg-danger-soft",
1215
+ soft: "ark:bg-danger-soft ark:text-danger-soft-fg ark:border-transparent ark:hover:border-danger-border"
1149
1216
  },
1150
1217
  info: {
1151
1218
  focusRing: "ark:ring-info-ring",
1152
1219
  solid: "ark:bg-info ark:text-info-fg ark:border-transparent ark:hover:bg-info-hover",
1153
1220
  outline: "ark:bg-transparent ark:text-info-soft-fg ark:border-info-border ark:hover:bg-info-soft",
1154
- ghost: "ark:bg-transparent ark:text-info-soft-fg ark:border-transparent ark:hover:bg-info-soft"
1221
+ ghost: "ark:bg-transparent ark:text-info-soft-fg ark:border-transparent ark:hover:bg-info-soft",
1222
+ soft: "ark:bg-info-soft ark:text-info-soft-fg ark:border-transparent ark:hover:border-info-border"
1155
1223
  },
1156
1224
  neutral: {
1157
1225
  focusRing: "ark:ring-neutral-ring",
1158
1226
  solid: "ark:bg-neutral ark:text-neutral-fg ark:border-transparent ark:hover:bg-neutral-hover",
1159
1227
  outline: "ark:bg-transparent ark:text-neutral-soft-fg ark:border-neutral-border ark:hover:bg-neutral-soft",
1160
- ghost: "ark:bg-transparent ark:text-neutral-soft-fg ark:border-transparent ark:hover:bg-neutral-soft"
1228
+ ghost: "ark:bg-transparent ark:text-neutral-soft-fg ark:border-transparent ark:hover:bg-neutral-soft",
1229
+ soft: "ark:bg-neutral-soft ark:text-neutral-soft-fg ark:border-transparent ark:hover:border-neutral-border"
1161
1230
  }
1162
1231
  };
1163
1232
  return palettes[intent];
@@ -1182,7 +1251,8 @@ class ArkButton extends HTMLElementBase {
1182
1251
  const variantClasses = {
1183
1252
  solid: palette.solid,
1184
1253
  outline: palette.outline,
1185
- ghost: palette.ghost
1254
+ ghost: palette.ghost,
1255
+ soft: palette.soft
1186
1256
  };
1187
1257
  // A altura vem do token --ark-size-* (min-height); o padding vertical fica
1188
1258
  // abaixo dele para o token governar e controles do mesmo size alinharem.
@@ -2766,9 +2836,12 @@ class ArkCheckbox extends HTMLElementBase {
2766
2836
  if (!this.boxEl)
2767
2837
  return;
2768
2838
  const target = event.target;
2769
- if (!target || target === this.boxEl || this.boxEl.contains(target))
2839
+ if (!target)
2770
2840
  return;
2771
- if (this.labelEl && (target === this.labelEl || this.labelEl.contains(target)))
2841
+ // Pelo caminho do evento, e não por contains(): o clique no glifo já alternou a caixa pelo botão, e o redesenho
2842
+ // tirou do DOM o svg clicado, que então não está mais dentro dela (a caixa alternava duas vezes).
2843
+ const path = event.composedPath();
2844
+ if (path.includes(this.boxEl) || (this.labelEl !== null && path.includes(this.labelEl)))
2772
2845
  return;
2773
2846
  if (target.closest("a, button, input, select, textarea, label, [contenteditable]") !== null)
2774
2847
  return;
@@ -6989,25 +7062,28 @@ class ArkDialog extends HTMLElementBase {
6989
7062
  this.warnWithoutName();
6990
7063
  // showPopover() antes do foco: os focáveis só têm caixas com o painel visível.
6991
7064
  void core.openPopover(this, "scale", { lockScroll: !this.noScrollLock });
6992
- this.releaseTrap?.();
6993
- this.releaseTrap = core.trapFocus(this, {
6994
- initial: this.initialFocus(),
6995
- onOutsidePointer: () => {
6996
- if (!this.persistent)
6997
- this.close("backdrop");
6998
- }
6999
- });
7000
- const emit = () => {
7001
- if (this.state === "open")
7002
- this.dispatchEvent(new CustomEvent("ark-open", { bubbles: true, composed: true }));
7065
+ const settle = () => {
7066
+ if (this.state !== "open")
7067
+ return;
7068
+ this.releaseTrap?.();
7069
+ this.releaseTrap = core.trapFocus(this, {
7070
+ initial: this.initialFocus(),
7071
+ onOutsidePointer: () => {
7072
+ if (!this.persistent)
7073
+ this.close("backdrop");
7074
+ }
7075
+ });
7076
+ this.dispatchEvent(new CustomEvent("ark-open", { bubbles: true, composed: true }));
7003
7077
  };
7004
- // Aberto já ao conectar (open no HTML, hidratação de SSR, framework que grava a prop antes de inserir): o evento
7005
- // sai num microtask, para chegar a quem se inscreve no mesmo ciclo em que o nó entrou (os wrappers React e
7006
- // Angular ligam os listeners dos overlays durante a montagem) em vez de disparar antes de alguém escutar.
7078
+ // Aberto já ao conectar (open no HTML, hidratação de SSR, framework que grava a prop antes de inserir): o trap e
7079
+ // o evento esperam um microtask. O foco inicial só é escolhido depois de os filhos conectarem (um ark-input do
7080
+ // corpo ainda não montou o <input>, e o foco caía no botão de fechar), e o ark-open chega a quem se inscreve no
7081
+ // mesmo ciclo em que o nó entrou (os wrappers React e Angular ligam os listeners dos overlays durante a
7082
+ // montagem) em vez de disparar antes de alguém escutar.
7007
7083
  if (this.openingOnConnect)
7008
- queueMicrotask(emit);
7084
+ queueMicrotask(settle);
7009
7085
  else
7010
- emit();
7086
+ settle();
7011
7087
  }
7012
7088
  closeNow(reason) {
7013
7089
  if (this.state !== "open")
@@ -7396,17 +7472,10 @@ class ArkDrawer extends HTMLElementBase {
7396
7472
  this.setAttribute("data-ark-state", "open");
7397
7473
  this.updateAppearance();
7398
7474
  this.warnWithoutName();
7399
- if (this.mode === "overlay") {
7475
+ const overlay = this.mode === "overlay";
7476
+ if (overlay) {
7400
7477
  // Percorre a própria largura/altura: entra de fora da viewport. Overlay é modal: a página para de rolar.
7401
7478
  void core.openPopover(this, this.preset(), { distance: "100%", easing: "sheet", lockScroll: !this.noScrollLock });
7402
- this.releaseTrap?.();
7403
- this.releaseTrap = core.trapFocus(this, {
7404
- initial: this.initialFocus(),
7405
- onOutsidePointer: () => {
7406
- if (!this.persistent)
7407
- this.close("backdrop");
7408
- }
7409
- });
7410
7479
  }
7411
7480
  else {
7412
7481
  // No fluxo o espaço já existe: um deslocamento curto (token) basta; a saída anterior fica preenchida.
@@ -7414,17 +7483,30 @@ class ArkDrawer extends HTMLElementBase {
7414
7483
  animation.cancel();
7415
7484
  void core.arkEnter(this, this.preset(), { easing: "sheet" });
7416
7485
  }
7417
- const emit = () => {
7418
- if (this.state === "open")
7419
- this.dispatchEvent(new CustomEvent("ark-open", { bubbles: true, composed: true }));
7486
+ const settle = () => {
7487
+ if (this.state !== "open")
7488
+ return;
7489
+ if (overlay) {
7490
+ this.releaseTrap?.();
7491
+ this.releaseTrap = core.trapFocus(this, {
7492
+ initial: this.initialFocus(),
7493
+ onOutsidePointer: () => {
7494
+ if (!this.persistent)
7495
+ this.close("backdrop");
7496
+ }
7497
+ });
7498
+ }
7499
+ this.dispatchEvent(new CustomEvent("ark-open", { bubbles: true, composed: true }));
7420
7500
  };
7421
- // Aberto já ao conectar (open no HTML, hidratação de SSR, framework que grava a prop antes de inserir): o evento
7422
- // sai num microtask, para chegar a quem se inscreve no mesmo ciclo em que o nó entrou (os wrappers React e
7423
- // Angular ligam os listeners dos overlays durante a montagem) em vez de disparar antes de alguém escutar.
7501
+ // Aberto já ao conectar (open no HTML, hidratação de SSR, framework que grava a prop antes de inserir): o trap e
7502
+ // o evento esperam um microtask. O foco inicial só é escolhido depois de os filhos conectarem (um ark-input do
7503
+ // corpo ainda não montou o <input>, e o foco caía no botão de fechar), e o ark-open chega a quem se inscreve no
7504
+ // mesmo ciclo em que o nó entrou (os wrappers React e Angular ligam os listeners dos overlays durante a
7505
+ // montagem) em vez de disparar antes de alguém escutar.
7424
7506
  if (this.openingOnConnect)
7425
- queueMicrotask(emit);
7507
+ queueMicrotask(settle);
7426
7508
  else
7427
- emit();
7509
+ settle();
7428
7510
  }
7429
7511
  closeNow(reason) {
7430
7512
  if (this.state !== "open")
@@ -8374,6 +8456,7 @@ const PASS_THROUGH_ATTRS$1 = [
8374
8456
  "max",
8375
8457
  "step",
8376
8458
  "spellcheck",
8459
+ "list",
8377
8460
  "aria-label"
8378
8461
  ];
8379
8462
  /** Ícones do botão de revelar senha (chrome próprio do componente). */
@@ -10082,7 +10165,9 @@ class ArkMenu extends HTMLElementBase {
10082
10165
  this.setAttribute("tabindex", "-1");
10083
10166
  // Redefine o que o UA dá a [popover] (inset, margin, border, padding, overflow, color, background); left/top
10084
10167
  // vêm inline do posicionamento e o display, com as transições, do components.css.
10085
- this.applyOwnClasses("ark:fixed ark:inset-auto ark:m-0 ark:min-w-40 ark:max-w-xs ark:max-h-[calc(100vh-1rem)] ark:overflow-y-auto ark:overscroll-contain ark:rounded-lg ark:border ark:border-border ark:bg-surface ark:p-1 ark:text-fg ark:shadow-lg ark:outline-none".split(" "));
10168
+ // text-start: o Chromium trata o atributo `align` de qualquer elemento HTML como dica de apresentação
10169
+ // (text-align), e align="end" alinhava à direita o rótulo dos grupos e o conteúdo livre do menu.
10170
+ this.applyOwnClasses("ark:fixed ark:inset-auto ark:m-0 ark:min-w-40 ark:max-w-xs ark:max-h-[calc(100vh-1rem)] ark:overflow-y-auto ark:overscroll-contain ark:rounded-lg ark:border ark:border-border ark:bg-surface ark:p-1 ark:text-start ark:text-fg ark:shadow-lg ark:outline-none".split(" "));
10086
10171
  applyTestHooks(this, "menu", this);
10087
10172
  }
10088
10173
  }
@@ -11935,9 +12020,11 @@ class ArkRadio extends HTMLElementBase {
11935
12020
  if (!this.boxEl)
11936
12021
  return;
11937
12022
  const target = event.target;
11938
- if (!target || target === this.boxEl || this.boxEl.contains(target))
12023
+ if (!target)
11939
12024
  return;
11940
- if (this.labelEl && (target === this.labelEl || this.labelEl.contains(target)))
12025
+ // Pelo caminho do evento, como no ark-checkbox: um nó clicado que o redesenho tira do DOM continua nele.
12026
+ const path = event.composedPath();
12027
+ if (path.includes(this.boxEl) || (this.labelEl !== null && path.includes(this.labelEl)))
11941
12028
  return;
11942
12029
  if (target.closest("a, button, input, select, textarea, label, [contenteditable]") !== null)
11943
12030
  return;
@@ -14476,7 +14563,8 @@ class ArkSwitch extends HTMLElementBase {
14476
14563
  if (!this.trackEl)
14477
14564
  return;
14478
14565
  const target = event.target;
14479
- if (!target || target === this.trackEl || this.trackEl.contains(target))
14566
+ // Pelo caminho do evento, como no ark-checkbox: um nó clicado que o redesenho tira do DOM continua nele.
14567
+ if (!target || event.composedPath().includes(this.trackEl))
14480
14568
  return;
14481
14569
  if (target.closest("a, button, input, select, textarea, label, [contenteditable]") !== null)
14482
14570
  return;
@@ -15417,8 +15505,9 @@ let arkTextareaIdCounter = 0;
15417
15505
  * Área de texto padronizada: a mesma grid label / campo / mensagem do
15418
15506
  * ark-input (ver components.css) e os mesmos atributos de label, helper e
15419
15507
  * erro. `rows` dá a altura inicial, `autosize` cresce com o conteúdo
15420
- * (`field-sizing: content` nativo, com fallback por JS), `monospace` e
15421
- * `resize` atendem edição de código e de dados.
15508
+ * (`field-sizing: content` nativo, com fallback por JS) a partir de uma
15509
+ * linha, ou das linhas de um `rows` explícito, `monospace` e `resize`
15510
+ * atendem edição de código e de dados.
15422
15511
  */
15423
15512
  class ArkTextarea extends HTMLElementBase {
15424
15513
  constructor() {
@@ -15532,7 +15621,8 @@ class ArkTextarea extends HTMLElementBase {
15532
15621
  this.textareaEl.required = this.hasAttribute("required");
15533
15622
  this.textareaEl.readOnly = this.hasAttribute("readonly");
15534
15623
  const rows = Number.parseInt(this.getAttribute("rows") || "", 10);
15535
- this.textareaEl.rows = Number.isFinite(rows) && rows > 0 ? rows : 3;
15624
+ const hasRows = Number.isFinite(rows) && rows > 0;
15625
+ this.textareaEl.rows = hasRows ? rows : 3;
15536
15626
  for (const name of PASS_THROUGH_ATTRS) {
15537
15627
  const value = this.getAttribute(name);
15538
15628
  if (value === null) {
@@ -15545,15 +15635,51 @@ class ArkTextarea extends HTMLElementBase {
15545
15635
  this.autosizeByJs = autosize && !this.supportsFieldSizing();
15546
15636
  if (!this.autosizeByJs)
15547
15637
  this.textareaEl.style.removeProperty("height");
15548
- // Fonte e padding por size; a altura mínima segue o token para uma linha alinhar com o ark-input.
15638
+ // Fonte e padding por size; a altura mínima segue o token para uma linha alinhar com o ark-input. `padY` repete
15639
+ // o ark:py-* da mesma linha, em passos da escala de espaçamento, para a altura mínima do autosize com `rows`.
15549
15640
  const sizes = {
15550
- xs: { field: "ark:min-h-(--ark-size-xs) ark:px-2 ark:py-0.5 ark:text-xs", label: "ark:text-2xs" },
15551
- sm: { field: "ark:min-h-(--ark-size-sm) ark:px-2.5 ark:py-1 ark:text-xs", label: "ark:text-2xs" },
15552
- md: { field: "ark:min-h-(--ark-size-md) ark:px-3 ark:py-1.5 ark:text-sm", label: "ark:text-xs" },
15553
- lg: { field: "ark:min-h-(--ark-size-lg) ark:px-4 ark:py-2 ark:text-base", label: "ark:text-sm" },
15554
- xl: { field: "ark:min-h-(--ark-size-xl) ark:px-5 ark:py-2.5 ark:text-lg", label: "ark:text-base" }
15641
+ xs: {
15642
+ field: "ark:min-h-(--ark-size-xs) ark:px-2 ark:py-0.5 ark:text-xs",
15643
+ label: "ark:text-2xs",
15644
+ token: "--ark-size-xs",
15645
+ padY: 0.5
15646
+ },
15647
+ sm: {
15648
+ field: "ark:min-h-(--ark-size-sm) ark:px-2.5 ark:py-1 ark:text-xs",
15649
+ label: "ark:text-2xs",
15650
+ token: "--ark-size-sm",
15651
+ padY: 1
15652
+ },
15653
+ md: {
15654
+ field: "ark:min-h-(--ark-size-md) ark:px-3 ark:py-1.5 ark:text-sm",
15655
+ label: "ark:text-xs",
15656
+ token: "--ark-size-md",
15657
+ padY: 1.5
15658
+ },
15659
+ lg: {
15660
+ field: "ark:min-h-(--ark-size-lg) ark:px-4 ark:py-2 ark:text-base",
15661
+ label: "ark:text-sm",
15662
+ token: "--ark-size-lg",
15663
+ padY: 2
15664
+ },
15665
+ xl: {
15666
+ field: "ark:min-h-(--ark-size-xl) ark:px-5 ark:py-2.5 ark:text-lg",
15667
+ label: "ark:text-base",
15668
+ token: "--ark-size-xl",
15669
+ padY: 2.5
15670
+ }
15555
15671
  };
15556
15672
  const size = sizes[(this.getAttribute("size") || "md").toLowerCase()] ?? sizes.md;
15673
+ // Com autosize a caixa mede o conteúdo e o `rows` do <textarea> deixa de contar (field-sizing: content o ignora):
15674
+ // um `rows` explícito vira a altura mínima, em linhas mais o padding e a borda da caixa, sem ficar abaixo do
15675
+ // token. Sem o atributo o autosize segue começando em uma linha, como sempre foi. Inline porque a utility
15676
+ // ark:min-h-* da caixa venceria uma regra de components.css.
15677
+ if (autosize && hasRows) {
15678
+ this.textareaEl.style.minHeight = `max(var(${size.token}), calc(${rows}lh + var(--ark-spacing, 0.25rem) * ${size.padY * 2} + 2px))`;
15679
+ }
15680
+ else {
15681
+ this.textareaEl.style.removeProperty("min-height");
15682
+ }
15557
15683
  const roundedMap = {
15558
15684
  none: "ark:rounded-none",
15559
15685
  xs: "ark:rounded-xs",
@@ -16910,11 +17036,24 @@ const OWN_CONTROLS = "a[href], button, input, select, textarea, [contenteditable
16910
17036
  * nível e posição explícitos). A árvore calcula a estrutura, coordena foco (um
16911
17037
  * tab stop só), teclado do padrão WAI-ARIA, seleção e caixas, e publica os
16912
17038
  * eventos consolidados: `ark-toggle`, `ark-selection-change` e `ark-activate`.
16913
- * Simples por padrão: sem `selection` só navega, expande e ativa.
17039
+ * Simples por padrão: sem `selection` só navega, expande e ativa, e sem
17040
+ * `icons` o único ícone de um nó é o `slot="icon"` que o app puser.
16914
17041
  */
16915
17042
  class ArkTree extends HTMLElementBase {
16916
17043
  static get observedAttributes() {
16917
- return ["selection", "checkboxes", "propagate", "value", "label", "size", "theme", "class", "testid"];
17044
+ return [
17045
+ "selection",
17046
+ "checkboxes",
17047
+ "propagate",
17048
+ "value",
17049
+ "label",
17050
+ "icons",
17051
+ "icon-color",
17052
+ "size",
17053
+ "theme",
17054
+ "class",
17055
+ "testid"
17056
+ ];
16918
17057
  }
16919
17058
  constructor() {
16920
17059
  super();
@@ -16929,6 +17068,8 @@ class ArkTree extends HTMLElementBase {
16929
17068
  this.known = new WeakSet();
16930
17069
  this.typeahead = "";
16931
17070
  this.typeaheadTimer = null;
17071
+ /** Cor que o `icon-color` gravou em `--ark-tree-icon-color` no host ("" quando não gravou nada). */
17072
+ this.iconColorSet = "";
16932
17073
  this.handleFocusIn = (event) => {
16933
17074
  const target = event.target;
16934
17075
  const item = target?.closest("ark-tree-item");
@@ -17094,6 +17235,27 @@ class ArkTree extends HTMLElementBase {
17094
17235
  set propagate(value) {
17095
17236
  this.toggleAttribute("propagate", core.coerceBooleanAttr(value));
17096
17237
  }
17238
+ /**
17239
+ * Ícones dos nós: sem o atributo cada nó mostra só o `slot="icon"` que o app puser; `files` desenha o ícone próprio
17240
+ * de pasta (ramos) ou de arquivo (folhas) nos nós sem `slot="icon"`; `none` esconde todos, os do app inclusive.
17241
+ */
17242
+ get icons() {
17243
+ const value = (this.getAttribute("icons") || "").toLowerCase();
17244
+ return value === "files" || value === "none" ? value : "";
17245
+ }
17246
+ set icons(value) {
17247
+ reflectAttr(this, "icons", value || null);
17248
+ }
17249
+ /**
17250
+ * Cor dos ícones: um intent (o token da marca), `current` (a cor do texto da árvore) ou uma cor CSS. Vale para os
17251
+ * ícones próprios e, só com o atributo, também para o `slot="icon"` do app. Padrão: o token `fg-muted`.
17252
+ */
17253
+ get iconColor() {
17254
+ return this.getAttribute("icon-color") || "";
17255
+ }
17256
+ set iconColor(value) {
17257
+ reflectAttr(this, "icon-color", value || null);
17258
+ }
17097
17259
  /**
17098
17260
  * Valores selecionados (ou marcados, com `checkboxes`): um valor em `single`, lista JSON em `multiple`. O
17099
17261
  * componente o reescreve a cada mudança; atribuir seleciona os itens desses valores.
@@ -17158,6 +17320,8 @@ class ArkTree extends HTMLElementBase {
17158
17320
  const items = this.items;
17159
17321
  const checkMode = this.checkMode();
17160
17322
  const selectMode = this.selection !== "none" && !checkMode;
17323
+ const icons = this.icons || null;
17324
+ const iconColor = this.iconColorSet ? "" : null;
17161
17325
  let inherited = false;
17162
17326
  for (const item of items) {
17163
17327
  const parent = item.parentItem;
@@ -17179,6 +17343,8 @@ class ArkTree extends HTMLElementBase {
17179
17343
  setAttr$1(item, name, this.getAttribute(name));
17180
17344
  setAttr$1(item, "data-ark-select", selectMode ? "" : null);
17181
17345
  setAttr$1(item, "data-ark-checkboxes", checkMode ? "" : null);
17346
+ setAttr$1(item, "data-ark-icons", icons);
17347
+ setAttr$1(item, "data-ark-icon-color", iconColor);
17182
17348
  // Um filho que chega depois sob um pai todo marcado (a carga de um `lazy`) chega marcado, com `propagate`.
17183
17349
  if (!this.known.has(item)) {
17184
17350
  this.known.add(item);
@@ -17380,8 +17546,35 @@ class ArkTree extends HTMLElementBase {
17380
17546
  this.ownClasses = next;
17381
17547
  this.syncingClass = false;
17382
17548
  }
17549
+ // `icon-color` vira o valor de --ark-tree-icon-color no host: intent aponta para o token, `current` para a cor do
17550
+ // texto, e o resto só entra se for uma cor CSS. Sem o atributo o host fica sem a propriedade (a do app, se houver,
17551
+ // continua valendo), e só a que o componente gravou é removida.
17552
+ syncIconColor() {
17553
+ const raw = this.iconColor.trim();
17554
+ const lower = raw.toLowerCase();
17555
+ let color = "";
17556
+ if (lower === "current") {
17557
+ color = "currentColor";
17558
+ }
17559
+ else if (raw && normalizeIntent(lower, "primary") === lower) {
17560
+ color = `var(--ark-color-${lower})`;
17561
+ }
17562
+ else if (raw && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("color", raw)) {
17563
+ color = raw;
17564
+ }
17565
+ if (color === this.iconColorSet)
17566
+ return;
17567
+ if (color) {
17568
+ this.style.setProperty("--ark-tree-icon-color", color);
17569
+ }
17570
+ else {
17571
+ this.style.removeProperty("--ark-tree-icon-color");
17572
+ }
17573
+ this.iconColorSet = color;
17574
+ }
17383
17575
  updateAppearance() {
17384
17576
  this.setAttribute("role", "tree");
17577
+ this.syncIconColor();
17385
17578
  setAttr$1(this, "aria-multiselectable", this.selection === "multiple" ? "true" : null);
17386
17579
  const label = this.getAttribute("label");
17387
17580
  if (label && !this.hasAttribute("aria-labelledby"))
@@ -17422,6 +17615,15 @@ const CHECK_SVG = `<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" st
17422
17615
  const DASH_SVG = `<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" aria-hidden="true" class="ark:h-full ark:w-full"><path d="M5 10h10"></path></svg>`;
17423
17616
  /** Spinner de `loading` (o mesmo giro contínuo do botão). */
17424
17617
  const SPINNER_SVG = `<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class="ark:h-full ark:w-full ark-animate-spin"><circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25"></circle><path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round"></path></svg>`;
17618
+ /**
17619
+ * Ícones próprios de pasta e arquivo (`icons="files"` na árvore ou `icon` no item): contorno na grade de 16, o lado do
17620
+ * ícone no tamanho padrão, com a cor de `--ark-tree-icon-color` e o corpo da pasta num preenchimento leve.
17621
+ */
17622
+ const ICON_SVGS = {
17623
+ folder: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="ark:h-full ark:w-full"><path d="M1.75 4.25a1.5 1.5 0 0 1 1.5-1.5h2.8a1 1 0 0 1 .76.35L7.9 4.4h4.85a1.5 1.5 0 0 1 1.5 1.5v5.85a1.5 1.5 0 0 1-1.5 1.5h-9.5a1.5 1.5 0 0 1-1.5-1.5z" fill="currentColor" fill-opacity="0.14"></path></svg>`,
17624
+ "folder-open": `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="ark:h-full ark:w-full"><path d="M1.75 11.5V4.25a1.5 1.5 0 0 1 1.5-1.5h2.8a1 1 0 0 1 .76.35L7.9 4.4h3.85a1.5 1.5 0 0 1 1.5 1.5v.85"></path><path d="M4.02 6.75h9.9a.9.9 0 0 1 .86 1.16l-1.3 4.27a1.5 1.5 0 0 1-1.43 1.07H2.9a1.15 1.15 0 0 1-1.1-1.49l1.26-4.3a1 1 0 0 1 .96-.71z" fill="currentColor" fill-opacity="0.14"></path></svg>`,
17625
+ file: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="ark:h-full ark:w-full"><path d="M4.25 1.75h4.4a1 1 0 0 1 .7.3l2.6 2.6a1 1 0 0 1 .3.7v7.4a1.5 1.5 0 0 1-1.5 1.5h-6.5a1.5 1.5 0 0 1-1.5-1.5v-9.5a1.5 1.5 0 0 1 1.5-1.5z"></path><path d="M8.75 2v2.25a1 1 0 0 0 1 1H12"></path></svg>`
17626
+ };
17425
17627
  let itemSeq = 0;
17426
17628
  /**
17427
17629
  * Nó de um ark-tree. A linha própria é o `role="treeitem"` (foco, teclado e
@@ -17431,8 +17633,10 @@ let itemSeq = 0;
17431
17633
  * tem a própria linha. O chevron, a caixa e o rótulo são chrome próprio; o
17432
17634
  * `slot="icon"` e o `slot="trailing"` do usuário entram na linha pela grid do
17433
17635
  * components.css (e ficam fora do treeitem, então um botão no trailing é um
17434
- * controle à parte). Seleção, foco, teclado e a estrutura são coordenados pelo
17435
- * ark-tree.
17636
+ * controle à parte). O ícone próprio de pasta ou arquivo só existe quando a
17637
+ * árvore pede (`icons="files"`) ou o item o nomeia (`icon`), e cede o lugar
17638
+ * ao `slot="icon"` do usuário. Seleção, foco, teclado e a estrutura são
17639
+ * coordenados pelo ark-tree.
17436
17640
  */
17437
17641
  class ArkTreeItem extends HTMLElementBase {
17438
17642
  constructor() {
@@ -17441,12 +17645,27 @@ class ArkTreeItem extends HTMLElementBase {
17441
17645
  this.toggleEl = null;
17442
17646
  this.checkEl = null;
17443
17647
  this.labelEl = null;
17648
+ /** Ícone próprio de pasta ou arquivo: criado só quando a árvore ou o item o pedem. */
17649
+ this.iconEl = null;
17444
17650
  /** Ícones em uso no chevron e na caixa: trocar o innerHTML sem mudança geraria mutações sem fim no observer da árvore. */
17445
17651
  this.toggleIcon = "";
17446
17652
  this.checkIcon = "";
17653
+ this.ownIcon = "";
17447
17654
  }
17448
17655
  static get observedAttributes() {
17449
- return ["value", "label", "expanded", "lazy", "loading", "selected", "checked", "disabled", "size", "testid"];
17656
+ return [
17657
+ "value",
17658
+ "label",
17659
+ "icon",
17660
+ "expanded",
17661
+ "lazy",
17662
+ "loading",
17663
+ "selected",
17664
+ "checked",
17665
+ "disabled",
17666
+ "size",
17667
+ "testid"
17668
+ ];
17450
17669
  }
17451
17670
  connectedCallback() {
17452
17671
  upgradeProperties(this);
@@ -17475,6 +17694,17 @@ class ArkTreeItem extends HTMLElementBase {
17475
17694
  set label(value) {
17476
17695
  reflectAttr(this, "label", value);
17477
17696
  }
17697
+ /**
17698
+ * Ícone próprio deste nó: folder, file ou none. Sem o atributo vale o da árvore (`icons="files"`: pasta nos ramos,
17699
+ * arquivo nas folhas). Um `slot="icon"` do usuário tem precedência sobre os dois.
17700
+ */
17701
+ get icon() {
17702
+ const value = (this.getAttribute("icon") || "").toLowerCase();
17703
+ return value === "folder" || value === "file" || value === "none" ? value : "";
17704
+ }
17705
+ set icon(value) {
17706
+ reflectAttr(this, "icon", value || null);
17707
+ }
17478
17708
  /** Aberto; refletido quando o usuário expande ou recolhe. */
17479
17709
  get expanded() {
17480
17710
  return this.hasAttribute("expanded");
@@ -17549,6 +17779,10 @@ class ArkTreeItem extends HTMLElementBase {
17549
17779
  get toggleElement() {
17550
17780
  return this.toggleEl;
17551
17781
  }
17782
+ /** O ícone próprio de pasta ou arquivo, ou `null` quando o nó não tem um. */
17783
+ get iconElement() {
17784
+ return this.iconEl;
17785
+ }
17552
17786
  /** A caixa própria, para a árvore distinguir o clique que só marca. */
17553
17787
  get checkElement() {
17554
17788
  return this.checkEl;
@@ -17580,7 +17814,59 @@ class ArkTreeItem extends HTMLElementBase {
17580
17814
  this.setAttribute("role", "none");
17581
17815
  this.updateAppearance();
17582
17816
  // Chrome no início, antes dos filhos do usuário: a grid do components.css posiciona cada parte.
17583
- this.prepend(row, toggle, check, label);
17817
+ if (this.iconEl) {
17818
+ this.prepend(row, toggle, check, this.iconEl, label);
17819
+ }
17820
+ else {
17821
+ this.prepend(row, toggle, check, label);
17822
+ }
17823
+ }
17824
+ // Qual ícone próprio desenhar ("" para nenhum). A árvore manda em `none` (esconde até o do usuário, pelo CSS); o
17825
+ // `slot="icon"` do usuário vence o próprio; o `icon` do item vence a escolha automática de `icons="files"`.
17826
+ resolveOwnIcon(branch) {
17827
+ // O modo chega propagado pela árvore; na primeira montagem, antes dela passar, vem do atributo da própria árvore.
17828
+ const mode = (this.getAttribute("data-ark-icons") ??
17829
+ this.closest("ark-tree")?.getAttribute("icons") ??
17830
+ "").toLowerCase();
17831
+ const own = this.icon;
17832
+ if (mode === "none" || own === "none" || (mode !== "files" && own === ""))
17833
+ return "";
17834
+ for (const child of Array.from(this.children)) {
17835
+ if (child.getAttribute("slot") === "icon")
17836
+ return "";
17837
+ }
17838
+ const kind = own || (branch ? "folder" : "file");
17839
+ return kind === "folder" && branch && this.expanded ? "folder-open" : kind;
17840
+ }
17841
+ // Cria, troca ou remove o ícone próprio, só quando muda: cada escrita aqui passa pelo observer da árvore.
17842
+ syncOwnIcon(branch) {
17843
+ const kind = this.resolveOwnIcon(branch);
17844
+ if (kind === "") {
17845
+ if (this.iconEl) {
17846
+ this.iconEl.remove();
17847
+ this.iconEl = null;
17848
+ this.ownIcon = "";
17849
+ }
17850
+ return;
17851
+ }
17852
+ if (!this.iconEl) {
17853
+ const icon = document.createElement("span");
17854
+ icon.setAttribute("data-ark-chrome", "icon");
17855
+ icon.setAttribute("aria-hidden", "true");
17856
+ icon.className = "ark:inline-flex ark:shrink-0 ark:items-center ark:justify-center";
17857
+ this.iconEl = icon;
17858
+ this.ownIcon = "";
17859
+ }
17860
+ if (this.ownIcon !== kind) {
17861
+ this.iconEl.innerHTML = ICON_SVGS[kind];
17862
+ this.iconEl.setAttribute("data-ark-icon", kind);
17863
+ this.ownIcon = kind;
17864
+ }
17865
+ // Na primeira montagem o chrome ainda está fora do DOM: o render() insere o ícone junto com o resto.
17866
+ if (this.labelEl?.parentNode === this && this.iconEl.parentNode !== this) {
17867
+ this.insertBefore(this.iconEl, this.labelEl);
17868
+ }
17869
+ applyTestHooks(this, "tree-item", this.iconEl, "icon");
17584
17870
  }
17585
17871
  sizeClasses() {
17586
17872
  const sizes = {
@@ -17626,6 +17912,7 @@ class ArkTreeItem extends HTMLElementBase {
17626
17912
  this.toggleEl.innerHTML = toggleIcon;
17627
17913
  this.toggleIcon = toggleIcon;
17628
17914
  }
17915
+ this.syncOwnIcon(branch);
17629
17916
  // A caixa só aparece com `checkboxes`; o estado vai em aria-checked na linha.
17630
17917
  this.checkEl.hidden = !checkable;
17631
17918
  const checked = this.checked;