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