@ckui/core 0.1.0-next.0 → 0.1.0-next.2

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.
Files changed (36) hide show
  1. package/README.md +239 -0
  2. package/fesm2022/ckui-core-badge.mjs +169 -0
  3. package/fesm2022/ckui-core-badge.mjs.map +1 -0
  4. package/fesm2022/ckui-core-button.mjs +5 -13
  5. package/fesm2022/ckui-core-button.mjs.map +1 -1
  6. package/fesm2022/ckui-core-dialog.mjs +908 -0
  7. package/fesm2022/ckui-core-dialog.mjs.map +1 -0
  8. package/fesm2022/ckui-core-field.mjs +6 -10
  9. package/fesm2022/ckui-core-field.mjs.map +1 -1
  10. package/fesm2022/ckui-core-internal-overlay.mjs +468 -0
  11. package/fesm2022/ckui-core-internal-overlay.mjs.map +1 -0
  12. package/fesm2022/ckui-core-internal.mjs +271 -8
  13. package/fesm2022/ckui-core-internal.mjs.map +1 -1
  14. package/fesm2022/ckui-core-progress.mjs +165 -0
  15. package/fesm2022/ckui-core-progress.mjs.map +1 -0
  16. package/fesm2022/ckui-core-segmented.mjs +528 -0
  17. package/fesm2022/ckui-core-segmented.mjs.map +1 -0
  18. package/fesm2022/ckui-core-stepper.mjs +842 -0
  19. package/fesm2022/ckui-core-stepper.mjs.map +1 -0
  20. package/fesm2022/ckui-core-toast.mjs +883 -0
  21. package/fesm2022/ckui-core-toast.mjs.map +1 -0
  22. package/fesm2022/ckui-core.mjs +5 -1
  23. package/fesm2022/ckui-core.mjs.map +1 -1
  24. package/package.json +29 -1
  25. package/styles/tokens.css +3 -0
  26. package/types/ckui-core-badge.d.ts +44 -0
  27. package/types/ckui-core-button.d.ts +0 -1
  28. package/types/ckui-core-dialog.d.ts +219 -0
  29. package/types/ckui-core-field.d.ts +0 -1
  30. package/types/ckui-core-internal-overlay.d.ts +76 -0
  31. package/types/ckui-core-internal.d.ts +115 -8
  32. package/types/ckui-core-progress.d.ts +43 -0
  33. package/types/ckui-core-segmented.d.ts +124 -0
  34. package/types/ckui-core-stepper.d.ts +186 -0
  35. package/types/ckui-core-toast.d.ts +97 -0
  36. package/types/ckui-core.d.ts +4 -0
package/README.md CHANGED
@@ -120,6 +120,245 @@ the rule off for templates that use `ck-field`.
120
120
  Global element styles: your own unlayered rules such as `input { font: … }` beat the layered field,
121
121
  by design. Put resets in a layer declared before ckui: `@layer reset, ckui;`.
122
122
 
123
+ ## Segmented control
124
+
125
+ ```ts
126
+ import { CK_SEGMENTED_IMPORTS } from '@ckui/core/segmented';
127
+ ```
128
+
129
+ ```html
130
+ <ck-segmented aria-label="Calendar view" [(value)]="view">
131
+ <ck-segment value="day">Day</ck-segment>
132
+ <ck-segment value="week">Week</ck-segment>
133
+ <ck-segment value="month">Month</ck-segment>
134
+ </ck-segmented>
135
+ ```
136
+
137
+ `ck-segmented` is one radio group of mutually exclusive options (`CkSegmented`, `CkSegment`). It is a
138
+ single tab stop; the arrow keys move and select (Left and Right swap in right-to-left text), `Home` and
139
+ `End` go to the first and last enabled segment, `Space` selects. It works with Reactive Forms,
140
+ `ngModel` and Signal Forms (`[formField]`) and with `[(value)]` on its own. Inputs of `ck-segmented`:
141
+ `value` (`T | null`; `null` selects nothing and hides the indicator), `size` (default from `provideCkui`),
142
+ `disabled` and `fullWidth`. Inputs of `ck-segment`: `value` (required) and `disabled`. A segment holds
143
+ text, a direct `svg` child (an icon, shown before the text), or both; font-icon elements land in the label. The group needs an `aria-label` or
144
+ `aria-labelledby`, and an icon-only segment needs an `aria-label` (development builds warn about both).
145
+
146
+ The group is as tall as the control height of its size and every segment is that tall to hit (44px for
147
+ `sm` and `md` under a coarse pointer, 60px at `xl`). The selected segment is marked by a raised indicator
148
+ with its own 3:1 border, not by colour alone, and it slides to a new selection over
149
+ `--ck-duration-normal` (not under reduced motion, and not when it first appears). A segment is as wide
150
+ as an equal share of the group or its label (with icon and padding), whichever is larger, so a long
151
+ label never cuts a short neighbour's share: its column grows and the others shrink. Only when the
152
+ labels at their natural width cannot fit together does the group switch to equal columns and cut the
153
+ labels with an ellipsis (the full text stays in the accessible name); it never overflows its
154
+ container, and goes back to content widths as soon as there is room, also when only a label, the size or a loading font changes. Component tokens:
155
+ `--ck-segmented-bg`, `--ck-segmented-border-color`, `--ck-segmented-fg`,
156
+ `--ck-segmented-indicator-bg`, `--ck-segmented-indicator-fg`, `--ck-segmented-radius`,
157
+ `--ck-segmented-padding` (the gap around the indicator) and `--ck-segmented-padding-inline`
158
+ (horizontal padding of a segment, for a tighter control; the size's control padding by default).
159
+
160
+ Global element styles: a global `:focus-visible { outline: … }` beats the layered control and draws a
161
+ second ring on the segment itself. Keep it off the segments (`:focus-visible:not(.ck-segment)`) or put
162
+ resets in a layer declared before ckui: `@layer reset, ckui;`.
163
+
164
+ ## Badge
165
+
166
+ ```ts
167
+ import { CK_BADGE_IMPORTS } from '@ckui/core/badge';
168
+ ```
169
+
170
+ ```html
171
+ <ck-badge tone="success" dot>Connected</ck-badge>
172
+ <ck-badge tone="danger">
173
+ <svg
174
+ ckBadgeIcon
175
+ viewBox="0 0 16 16"
176
+ fill="none"
177
+ stroke="currentColor"
178
+ stroke-width="2"
179
+ stroke-linecap="round"
180
+ stroke-linejoin="round"
181
+ >
182
+ <path d="M8 3v6M8 12.5v.5" />
183
+ </svg>
184
+ Upload failed
185
+ </ck-badge>
186
+ ```
187
+
188
+ `ck-badge` is a small, non-interactive status pill (`CkBadge`, `CkBadgeIcon`). Inputs: `tone` (`neutral`
189
+ default, `success`, `warning`, `danger`), `dot` (a leading dot in the text colour) and `size` (`md`, a 1.5rem
190
+ pill, default; `sm`, 1.25rem, for dense lists). `ckBadgeIcon` on a projected `svg` makes it the leading icon,
191
+ drawn one em wide and hidden from assistive technology. The badge never wraps: text that does not fit its
192
+ container is cut with an ellipsis.
193
+
194
+ A badge has no role and is not a live region. The text has to state the status, since a dot, an icon or a
195
+ colour alone says nothing to a screen reader, and development builds warn about a badge without text. When a
196
+ change must be heard, announce it yourself, for instance in a `role="status"` element or a toast. Component
197
+ tokens: `--ck-badge-bg`, `--ck-badge-fg`, `--ck-badge-dot` (the dot's own colour, default the text colour; a coloured dot is decoration, so the text must still state the status) and `--ck-badge-radius` (they apply to every tone; scope them by `.ck-badge--<tone>` to restyle one tone).
198
+
199
+ Global element styles: a global rule such as `span { overflow: visible }` (no truncation) or
200
+ `svg { inline-size: 100% }` (a huge icon) beats the layered badge. Scope it away from the badge or put
201
+ resets in a layer declared before ckui: `@layer reset, ckui;`.
202
+
203
+ ## Progress
204
+
205
+ ```ts
206
+ import { CkProgress } from '@ckui/core/progress';
207
+ ```
208
+
209
+ ```html
210
+ <ck-progress aria-label="Upload" [value]="percent()" />
211
+ <ck-progress
212
+ aria-label="Workout"
213
+ [value]="step()"
214
+ [max]="7"
215
+ [valueText]="'Step ' + step() + ' of 7'"
216
+ />
217
+ <ck-progress aria-label="Connecting" [value]="null" />
218
+ ```
219
+
220
+ `ck-progress` is a horizontal progress bar (`CkProgress`, `role="progressbar"`). Inputs: `value` (a number
221
+ from 0 to `max`; below 0 counts as 0 and above `max` as `max`; `null`, `undefined`, `NaN` or any non-number
222
+ shows the indeterminate bar without `aria-valuenow`), `max` (default 100; anything that is not a finite number
223
+ above 0 counts as 100) and `valueText` (`aria-valuetext`, e.g. "Step 2 of 7"). The bar needs an `aria-label`
224
+ or `aria-labelledby` (development builds warn without one) and is not a live region: announce milestones
225
+ yourself.
226
+
227
+ The fill grows with a transform from the start edge (mirrored in right-to-left text) over
228
+ `--ck-duration-normal`, and not at all under `prefers-reduced-motion`, where the indeterminate bar is a still,
229
+ half-width fill. In forced colors the track gets an outline and the fill is `Highlight`. Component tokens:
230
+ `--ck-progress-track`, `--ck-progress-fill`, `--ck-progress-thickness` and `--ck-progress-radius`; keep the
231
+ fill at 3:1 against the track.
232
+
233
+ ## Stepper
234
+
235
+ ```ts
236
+ import { CkStepper } from '@ckui/core/stepper';
237
+ ```
238
+
239
+ ```html
240
+ <ck-stepper aria-label="FTP" unit="W" [min]="50" [max]="600" [step]="5" [(value)]="ftp" />
241
+ <ck-stepper
242
+ aria-label="FTP"
243
+ decrementLabel="FTP minus 5"
244
+ incrementLabel="FTP plus 5"
245
+ [formControl]="ftp"
246
+ />
247
+ ```
248
+
249
+ `ck-stepper` is a number field with a minus and a plus button (`CkStepper`, a form control for Reactive Forms,
250
+ `ngModel` and Signal Forms). The value is a `number` or `null`. Inputs: `min`, `max`, `step` (default 1, counted
251
+ from `min`; it also sets the fraction digits), `largeStep` (Page Up/Down, default 10 steps), `unit` (text after the
252
+ value, read as part of the value text: "250 W"), `size`, `readonly`, `disabled`, `decrementLabel` and
253
+ `incrementLabel` (per-instance names for the buttons; the defaults come from the labels token).
254
+
255
+ The value is a real text input with `role="spinbutton"` and the only tab stop; the buttons are outside the tab
256
+ order. Name it with `aria-label` or `aria-labelledby` on `ck-stepper` (they are inputs and move onto the input
257
+ element, like `aria-describedby` for a hint or an error; bind them as `[aria-label]`) or wrap it in a `<label>`;
258
+ development builds warn without a name. The input uses `inputmode="decimal"`, and `text` when `min` is below 0. Arrow
259
+ Up/Down step, Page Up/Down move by `largeStep`, Home/End jump to `min`/`max` when set. Typed text is read on Enter or
260
+ blur: it is parsed with the locale (`LOCALE_ID`; both `.` and `,` count as a decimal mark), clamped, snapped to the
261
+ step, and text that is no number goes back to the last value. An empty field is `null`; from `null` the first arrow
262
+ or button press starts at `min`, else at 0. A held button repeats after 400 ms, every 80 ms, and by five steps after
263
+ two seconds; it stops on release, on leaving the button and at a limit. A `min` above `max` pins the value to `min`,
264
+ and a `step` that is 0, negative or not a number counts as 1; development builds warn about both. `(valueChange)`
265
+ fires once per user change and never for a programmatic write.
266
+
267
+ The buttons are squares of the control height (44px or more on a coarse pointer, 60px at `xl`). Component tokens:
268
+ `--ck-stepper-bg`, `--ck-stepper-border-color`, `--ck-stepper-radius` and `--ck-stepper-value-width` (default: as
269
+ wide as the formatted `min` and `max`).
270
+
271
+ Global element styles: an unlayered `button { border: … }` or `input { … }` beats the layered parts, and a global
272
+ `:focus-visible { outline: … }` draws a second ring on the input. Keep them off the stepper
273
+ (`button:not(.ck-stepper__button)`) or put resets in a layer declared before ckui: `@layer reset, ckui;`.
274
+
275
+ ## Toast
276
+
277
+ ```ts
278
+ import { CkToast } from '@ckui/core/toast';
279
+
280
+ const toast = inject(CkToast);
281
+ const ref = toast.show({
282
+ tone: 'success',
283
+ title: 'Saved',
284
+ message: 'Your changes are stored.',
285
+ action: { label: 'Undo', run: () => restore() },
286
+ });
287
+ const reason = await ref.dismissed; // 'timeout' | 'user' | 'action' | 'replaced' | 'programmatic'
288
+ ```
289
+
290
+ `CkToast.show()` returns a `CkToastRef` (`dismiss()`, `update(partial)`, `dismissed`); `dismissAll()` closes
291
+ everything. Options: `message` (plain text), `title`, `tone` (`neutral`, `success`, `warning`, `danger`),
292
+ `action` (`{ label, run }`), `duration` (milliseconds) and `id`. A toast closes after 5 seconds, except one with
293
+ an `action` or the tone `danger`, which stays until dismissed unless you give a `duration`. The timer pauses
294
+ while the pointer is over the toast, while focus is inside it and while the page is hidden. Showing a toast with
295
+ the `id` of an open one replaces it in place and restarts the timer; the earlier ref reports `replaced`.
296
+
297
+ Every toast has a dismiss button and can be swiped away sideways. Each one is announced to screen readers
298
+ (`danger` assertively, the others politely, as title and message); changed text is announced again, nothing is
299
+ announced on the server. The toasts live in one `section` that is a direct child of `body`, exempt from `inert`
300
+ and painted above dialogs, so they stay clickable while a dialog is open.
301
+
302
+ `provideCkToast({ position, align, max, size })` is optional: `position` is `bottom` (default) or `top`, `align`
303
+ is `center` on a narrow screen and `end` otherwise unless you set it, `max` (default 3) is how many show at once
304
+ (the rest queue), and `size` is the size of the action and dismiss buttons (default from `provideCkui`; `xl` is
305
+ 60px). The newest toast is always nearest the screen edge; safe-area insets are respected, and a narrow screen
306
+ gets the full width minus a `1rem` gutter. A toast that holds focus when it closes hands focus to the next toast,
307
+ else back to where it came from. Component tokens: `--ck-toast-bg` and `--ck-toast-fg` (neutral, success and
308
+ warning), `--ck-toast-danger-bg` and `--ck-toast-danger-fg`, `--ck-toast-radius`, `--ck-toast-max-width` and
309
+ `--ck-toast-shadow`.
310
+
311
+ Global element styles: a global `button:focus-visible { outline: … }` beats the layered toast buttons. Put
312
+ resets in a layer declared before ckui: `@layer reset, ckui;`.
313
+
314
+ ## Dialog
315
+
316
+ ```ts
317
+ import { CK_DIALOG_DATA, CK_DIALOG_IMPORTS, CkDialog, CkDialogRef } from '@ckui/core/dialog';
318
+
319
+ @Component({
320
+ imports: [CK_DIALOG_IMPORTS],
321
+ template: `
322
+ <h2 ckDialogTitle>Delete this workout?</h2>
323
+ <p ckDialogDescription>This cannot be undone.</p>
324
+ <ck-dialog-actions>
325
+ <button ckDialogInitialFocus ckDialogClose="keep">Keep it</button>
326
+ <button ckDialogClose="delete">Delete</button>
327
+ </ck-dialog-actions>
328
+ `,
329
+ })
330
+ class ConfirmDelete {}
331
+
332
+ const ref = inject(CkDialog).open<ConfirmDelete, void, 'keep' | 'delete'>(ConfirmDelete, {
333
+ role: 'alertdialog',
334
+ });
335
+ const answer = await ref.closed; // undefined when dismissed
336
+ ```
337
+
338
+ `CkDialog.open(componentOrTemplate, config)` returns a `CkDialogRef` (`close(result?)`, `closed`); `closeAll()`
339
+ closes everything. The content injects `CK_DIALOG_DATA` and `CkDialogRef`. Config: `data`, `role` (`dialog` or
340
+ `alertdialog`), `width` (`sm`, `md`, `lg`: 24, 32 or 48rem), `dismissible` (Escape, backdrop and swipe; default
341
+ `true`), `closeButton`, `mode` (`auto`, `modal`, `sheet`), `fullHeight`, `injector` and `ariaLabel`. A component dialog sees the providers of the app root; pass `injector: inject(Injector)` from the opener for route-level or component-level ones (`CK_DIALOG_DATA` and `CkDialogRef` are provided on top). `closed` resolves after
342
+ the dialog has left the screen, with the first result passed to `close()`; Escape, the backdrop, a swipe and
343
+ destroying the app resolve it with `undefined`.
344
+
345
+ The same dialog can be declared in a template: `<ck-dialog [(open)]="open" (closed)="onClosed($event)">` with one
346
+ `<ng-template>` inside, which is rendered only while the dialog is open. Building blocks: `ckDialogTitle` (names the
347
+ dialog), `ckDialogDescription`, `ck-dialog-body` (the only part that scrolls), `ck-dialog-actions`,
348
+ `ckDialogClose="result"` and `ckDialogInitialFocus`. Initial focus goes to the marked element, else the first
349
+ tabbable one of the content (never the close button), else the panel. Focus is trapped, the page behind is inert and
350
+ focus returns to the opener on close.
351
+
352
+ On a narrow screen with a coarse pointer (`mode: 'auto'`) the dialog is a bottom sheet as tall as its content, with a
353
+ swipe handle, stacked full-width actions and the safe-area inset; `fullHeight` makes it as tall as the screen allows.
354
+ Component tokens: `--ck-dialog-bg`, `--ck-dialog-radius`, `--ck-dialog-padding`, `--ck-dialog-max-width` and
355
+ `--ck-dialog-shadow`.
356
+
357
+ Global element styles: a global `h2`, `p` or `button:focus-visible` rule beats the layered dialog styles; scope it
358
+ with `:not(.ck-dialog__title)`, `:not(.ck-dialog__description)` and `:not(.ck-button)`, or put resets in a layer
359
+ declared before ckui: `@layer reset, ckui;`. A component opened through `CkDialog` must keep its host element a
360
+ flex column (the default styles do this); a global `display` on it stops the body from scrolling.
361
+
123
362
  ## Status
124
363
 
125
364
  Pre-release. Version 0.1 is in progress and the API is not stable yet.
@@ -0,0 +1,169 @@
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, PLATFORM_ID, ViewEncapsulation, afterNextRender, booleanAttribute, computed, inject, input } from "@angular/core";
3
+ import { isPlatformBrowser } from "@angular/common";
4
+ const TONES = [
5
+ "neutral",
6
+ "success",
7
+ "warning",
8
+ "danger"
9
+ ];
10
+ const SIZES = ["sm", "md"];
11
+ var CkBadgeIcon = class CkBadgeIcon {
12
+ static ɵfac = i0.ɵɵngDeclareFactory({
13
+ minVersion: "12.0.0",
14
+ version: "22.2.4",
15
+ ngImport: i0,
16
+ type: CkBadgeIcon,
17
+ deps: [],
18
+ target: i0.ɵɵFactoryTarget.Directive
19
+ });
20
+ static ɵdir = i0.ɵɵngDeclareDirective({
21
+ minVersion: "14.0.0",
22
+ version: "22.2.4",
23
+ type: CkBadgeIcon,
24
+ isStandalone: true,
25
+ selector: "[ckBadgeIcon]",
26
+ host: {
27
+ attributes: { "aria-hidden": "true" },
28
+ classAttribute: "ck-badge__icon"
29
+ },
30
+ ngImport: i0
31
+ });
32
+ };
33
+ i0.ɵɵngDeclareClassMetadata({
34
+ minVersion: "12.0.0",
35
+ version: "22.2.4",
36
+ ngImport: i0,
37
+ type: CkBadgeIcon,
38
+ decorators: [{
39
+ type: Directive,
40
+ args: [{
41
+ selector: "[ckBadgeIcon]",
42
+ host: {
43
+ class: "ck-badge__icon",
44
+ "aria-hidden": "true"
45
+ }
46
+ }]
47
+ }]
48
+ });
49
+ var CkBadge = class CkBadge {
50
+ tone = input("neutral", ...ngDevMode ? [{ debugName: "tone" }] : /* istanbul ignore next */ []);
51
+ dot = input(false, {
52
+ ...ngDevMode ? { debugName: "dot" } : /* istanbul ignore next */ {},
53
+ transform: booleanAttribute
54
+ });
55
+ size = input("md", ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
56
+ element = inject(ElementRef).nativeElement;
57
+ modifierClasses = computed(() => {
58
+ return `ck-badge ck-badge--${TONES.includes(this.tone()) ? this.tone() : "neutral"} ck-badge--${SIZES.includes(this.size()) ? this.size() : "md"}`;
59
+ }, ...ngDevMode ? [{ debugName: "modifierClasses" }] : /* istanbul ignore next */ []);
60
+ constructor() {
61
+ if (typeof ngDevMode !== "undefined" && ngDevMode && isPlatformBrowser(inject(PLATFORM_ID))) {
62
+ let destroyed = false;
63
+ inject(DestroyRef).onDestroy(() => destroyed = true);
64
+ afterNextRender(() => {
65
+ const text = this.element.querySelector(".ck-badge__text");
66
+ if (!destroyed && (text?.textContent ?? "").trim() === "") console.warn("[ckui] ck-badge has no text. The text must state the status; a dot or an icon alone is colour alone.", this.element);
67
+ });
68
+ }
69
+ }
70
+ static ɵfac = i0.ɵɵngDeclareFactory({
71
+ minVersion: "12.0.0",
72
+ version: "22.2.4",
73
+ ngImport: i0,
74
+ type: CkBadge,
75
+ deps: [],
76
+ target: i0.ɵɵFactoryTarget.Component
77
+ });
78
+ static ɵcmp = i0.ɵɵngDeclareComponent({
79
+ minVersion: "17.0.0",
80
+ version: "22.2.4",
81
+ type: CkBadge,
82
+ isStandalone: true,
83
+ selector: "ck-badge",
84
+ inputs: {
85
+ tone: {
86
+ classPropertyName: "tone",
87
+ publicName: "tone",
88
+ isSignal: true,
89
+ isRequired: false,
90
+ transformFunction: null
91
+ },
92
+ dot: {
93
+ classPropertyName: "dot",
94
+ publicName: "dot",
95
+ isSignal: true,
96
+ isRequired: false,
97
+ transformFunction: null
98
+ },
99
+ size: {
100
+ classPropertyName: "size",
101
+ publicName: "size",
102
+ isSignal: true,
103
+ isRequired: false,
104
+ transformFunction: null
105
+ }
106
+ },
107
+ host: { properties: { "class": "modifierClasses()" } },
108
+ ngImport: i0,
109
+ template: `@if (dot()) {
110
+ <span class="ck-badge__dot" aria-hidden="true"></span>
111
+ }
112
+ <ng-content select="[ckBadgeIcon]" /><span class="ck-badge__text"><ng-content /></span>`,
113
+ isInline: true,
114
+ styles: ["@layer ckui{.ck-badge{--_ck-badge-bg: var(--ck-color-control);--_ck-badge-fg: var(--ck-color-fg);--_ck-badge-height: 1.5rem;--_ck-badge-font-size: var(--ck-font-size-sm);--_ck-badge-padding-inline: var(--ck-space-2);--_ck-badge-gap: calc(var(--ck-space-1) * 1.5);display:inline-flex;align-items:center;gap:var(--_ck-badge-gap);box-sizing:border-box;min-inline-size:0;max-inline-size:100%;block-size:var(--_ck-badge-height);padding-inline:var(--_ck-badge-padding-inline);border-radius:var(--ck-badge-radius, var(--ck-radius-full));background:var(--ck-badge-bg, var(--_ck-badge-bg));color:var(--ck-badge-fg, var(--_ck-badge-fg));color-scheme:var(--ck-color-scheme);font-family:inherit;font-size:var(--_ck-badge-font-size);font-weight:var(--ck-font-weight-semibold);font-variant-numeric:var(--ck-font-variant-numeric);line-height:var(--ck-line-height-tight);white-space:nowrap;vertical-align:middle}.ck-badge--sm{--_ck-badge-height: 1.25rem;--_ck-badge-font-size: var(--ck-font-size-xs);--_ck-badge-padding-inline: calc(var(--ck-space-1) * 1.5);--_ck-badge-gap: var(--ck-space-1)}.ck-badge--success{--_ck-badge-fg: var(--ck-color-success-fg)}.ck-badge--warning{--_ck-badge-fg: var(--ck-color-warning-fg)}.ck-badge--danger{--_ck-badge-bg: var(--ck-color-danger);--_ck-badge-fg: var(--ck-color-on-danger)}.ck-badge__text{display:block;min-inline-size:0;overflow:hidden;text-overflow:ellipsis}.ck-badge__dot{flex:none;inline-size:.5em;block-size:.5em;border-radius:var(--ck-radius-full);background:var(--ck-badge-dot, currentColor)}.ck-badge__icon{flex:none;inline-size:1em;block-size:1em}@media(forced-colors:active){.ck-badge{border:1px solid CanvasText}.ck-badge__dot{forced-color-adjust:none;background:CanvasText}}}\n"],
115
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
116
+ encapsulation: i0.ViewEncapsulation.None
117
+ });
118
+ };
119
+ i0.ɵɵngDeclareClassMetadata({
120
+ minVersion: "12.0.0",
121
+ version: "22.2.4",
122
+ ngImport: i0,
123
+ type: CkBadge,
124
+ decorators: [{
125
+ type: Component,
126
+ args: [{
127
+ selector: "ck-badge",
128
+ changeDetection: ChangeDetectionStrategy.OnPush,
129
+ encapsulation: ViewEncapsulation.None,
130
+ host: { "[class]": "modifierClasses()" },
131
+ template: `@if (dot()) {
132
+ <span class="ck-badge__dot" aria-hidden="true"></span>
133
+ }
134
+ <ng-content select="[ckBadgeIcon]" /><span class="ck-badge__text"><ng-content /></span>`,
135
+ styles: ["@layer ckui{.ck-badge{--_ck-badge-bg: var(--ck-color-control);--_ck-badge-fg: var(--ck-color-fg);--_ck-badge-height: 1.5rem;--_ck-badge-font-size: var(--ck-font-size-sm);--_ck-badge-padding-inline: var(--ck-space-2);--_ck-badge-gap: calc(var(--ck-space-1) * 1.5);display:inline-flex;align-items:center;gap:var(--_ck-badge-gap);box-sizing:border-box;min-inline-size:0;max-inline-size:100%;block-size:var(--_ck-badge-height);padding-inline:var(--_ck-badge-padding-inline);border-radius:var(--ck-badge-radius, var(--ck-radius-full));background:var(--ck-badge-bg, var(--_ck-badge-bg));color:var(--ck-badge-fg, var(--_ck-badge-fg));color-scheme:var(--ck-color-scheme);font-family:inherit;font-size:var(--_ck-badge-font-size);font-weight:var(--ck-font-weight-semibold);font-variant-numeric:var(--ck-font-variant-numeric);line-height:var(--ck-line-height-tight);white-space:nowrap;vertical-align:middle}.ck-badge--sm{--_ck-badge-height: 1.25rem;--_ck-badge-font-size: var(--ck-font-size-xs);--_ck-badge-padding-inline: calc(var(--ck-space-1) * 1.5);--_ck-badge-gap: var(--ck-space-1)}.ck-badge--success{--_ck-badge-fg: var(--ck-color-success-fg)}.ck-badge--warning{--_ck-badge-fg: var(--ck-color-warning-fg)}.ck-badge--danger{--_ck-badge-bg: var(--ck-color-danger);--_ck-badge-fg: var(--ck-color-on-danger)}.ck-badge__text{display:block;min-inline-size:0;overflow:hidden;text-overflow:ellipsis}.ck-badge__dot{flex:none;inline-size:.5em;block-size:.5em;border-radius:var(--ck-radius-full);background:var(--ck-badge-dot, currentColor)}.ck-badge__icon{flex:none;inline-size:1em;block-size:1em}@media(forced-colors:active){.ck-badge{border:1px solid CanvasText}.ck-badge__dot{forced-color-adjust:none;background:CanvasText}}}\n"]
136
+ }]
137
+ }],
138
+ ctorParameters: () => [],
139
+ propDecorators: {
140
+ tone: [{
141
+ type: i0.Input,
142
+ args: [{
143
+ isSignal: true,
144
+ alias: "tone",
145
+ required: false
146
+ }]
147
+ }],
148
+ dot: [{
149
+ type: i0.Input,
150
+ args: [{
151
+ isSignal: true,
152
+ alias: "dot",
153
+ required: false
154
+ }]
155
+ }],
156
+ size: [{
157
+ type: i0.Input,
158
+ args: [{
159
+ isSignal: true,
160
+ alias: "size",
161
+ required: false
162
+ }]
163
+ }]
164
+ }
165
+ });
166
+ const CK_BADGE_IMPORTS = [CkBadge, CkBadgeIcon];
167
+ export { CK_BADGE_IMPORTS, CkBadge, CkBadgeIcon };
168
+
169
+ //# sourceMappingURL=ckui-core-badge.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ckui-core-badge.mjs","names":[],"sources":["../../../../projects/core/badge/badge.ts","../../../../projects/core/badge/index.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n Directive,\n ElementRef,\n PLATFORM_ID,\n ViewEncapsulation,\n afterNextRender,\n booleanAttribute,\n computed,\n inject,\n input,\n} from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\n\ndeclare const ngDevMode: unknown;\n\nexport type CkBadgeTone = 'neutral' | 'success' | 'warning' | 'danger';\nexport type CkBadgeSize = 'sm' | 'md';\n\nconst TONES: readonly CkBadgeTone[] = ['neutral', 'success', 'warning', 'danger'];\nconst SIZES: readonly CkBadgeSize[] = ['sm', 'md'];\n\n/** Marks a projected element (usually an `svg`) as the badge's leading icon. It is decorative. */\n@Directive({\n selector: '[ckBadgeIcon]',\n host: { class: 'ck-badge__icon', 'aria-hidden': 'true' },\n})\nexport class CkBadgeIcon {}\n\n/**\n * A small, non-interactive status label: a pill with text, an optional leading dot or icon. It is\n * not a live region and has no role; the text must say what the status is, colour never does.\n */\n@Component({\n selector: 'ck-badge',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n '[class]': 'modifierClasses()',\n },\n template: `@if (dot()) {\n <span class=\"ck-badge__dot\" aria-hidden=\"true\"></span>\n }\n <ng-content select=\"[ckBadgeIcon]\" /><span class=\"ck-badge__text\"><ng-content /></span>`,\n styleUrl: './badge.css',\n})\nexport class CkBadge {\n /** Colours of the badge. An unknown value falls back to `neutral`. */\n readonly tone = input<CkBadgeTone>('neutral');\n /** Adds a leading dot in the text colour. */\n readonly dot = input(false, { transform: booleanAttribute });\n /** `md` is a 1.5rem pill, `sm` a smaller one for dense lists. An unknown value falls back to `md`. */\n readonly size = input<CkBadgeSize>('md');\n\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n\n protected readonly modifierClasses = computed(() => {\n const tone = TONES.includes(this.tone()) ? this.tone() : 'neutral';\n const size = SIZES.includes(this.size()) ? this.size() : 'md';\n return `ck-badge ck-badge--${tone} ck-badge--${size}`;\n });\n\n constructor() {\n if (typeof ngDevMode !== 'undefined' && ngDevMode && isPlatformBrowser(inject(PLATFORM_ID))) {\n let destroyed = false;\n inject(DestroyRef).onDestroy(() => (destroyed = true));\n afterNextRender(() => {\n const text = this.element.querySelector('.ck-badge__text');\n if (!destroyed && (text?.textContent ?? '').trim() === '') {\n console.warn(\n '[ckui] ck-badge has no text. The text must state the status; a dot or an icon alone is colour alone.',\n this.element,\n );\n }\n });\n }\n }\n}\n","import { CkBadge, CkBadgeIcon } from './badge';\n\nexport type { CkBadgeSize, CkBadgeTone } from './badge';\nexport { CkBadge, CkBadgeIcon } from './badge';\n\n/** Everything a template needs for a badge: `imports: [CK_BADGE_IMPORTS]`. */\nexport const CK_BADGE_IMPORTS = [CkBadge, CkBadgeIcon] as const;\n"],"mappings":";;;AAqBA,MAAM,QAAgC;CAAC;CAAW;CAAW;CAAW;AAAQ;AAChF,MAAM,QAAgC,CAAC,MAAM,IAAI;AAOjD,IAAa,cAAb,MAAa,YAAW;CAAX,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAW,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAX,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAW,cAAA;EAAA,UAAA;EAAA,MAAA;GAAA,YAAA,EAAA,eAAA,OAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;CAAA,CAAA;;AAAX,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAW,YAAA,CAAA;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AA;EAAA,QAAA;GAAA,MAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,KAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,MAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA,EAAA,YAAA,EAAA,SAAA,oBAAA,EAAA;EAAA,UAAA;EAAA,UANR;;;;EAGgF,UAAA;EAAA,QAAA,CAAA,srDAAA;EAAA,iBAAA,GAAA,wBAAA;EAAA,eAAA,GAAA,kBAAA;CAAA,CAAA;;AAG/E,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAO,YAAA,CAAA;EAbnB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAU,iBACH,wBAAwB;GAAM,eAChC,kBAAkB;GAAI,MAC/B,EACJ,WAAW,oBACZ;GAAA,UACS;;;;GAGgF,QAAA,CAAA,srDAAA;EAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvC5F,MAAa,mBAAmB,CAAC,SAAS,WAAW"}
@@ -2,7 +2,7 @@ import { isPlatformBrowser } from "@angular/common";
2
2
  import * as i0 from "@angular/core";
3
3
  import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, PLATFORM_ID, Renderer2, ViewEncapsulation, afterNextRender, booleanAttribute, computed, effect, inject, input, untracked } from "@angular/core";
4
4
  import { CK_CONFIG, CK_LABELS } from "@ckui/core";
5
- import { CkAnnouncer } from "@ckui/core/internal";
5
+ import { CkAnnouncer, hasAccessibleName } from "@ckui/core/internal";
6
6
  var CkButton = class CkButton {
7
7
  variant = input("secondary", ...ngDevMode ? [{ debugName: "variant" }] : /* istanbul ignore next */ []);
8
8
  size = input(void 0, ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
@@ -62,7 +62,10 @@ var CkButton = class CkButton {
62
62
  let destroyed = false;
63
63
  destroyRef.onDestroy(() => destroyed = true);
64
64
  afterNextRender(() => {
65
- if (!destroyed && this.iconOnly() && !this.hasAccessibleName()) console.warn("[ckui] ckButton with iconOnly has no accessible name. Add an aria-label, aria-labelledby or title.", this.element);
65
+ if (!destroyed && this.iconOnly() && !hasAccessibleName(this.element, {
66
+ title: true,
67
+ text: true
68
+ })) console.warn("[ckui] ckButton with iconOnly has no accessible name. Add an aria-label, aria-labelledby or title.", this.element);
66
69
  });
67
70
  }
68
71
  }
@@ -77,12 +80,6 @@ var CkButton = class CkButton {
77
80
  else this.renderer.setAttribute(this.element, name, previous);
78
81
  }
79
82
  }
80
- hasAccessibleName() {
81
- const element = this.element;
82
- const attribute = (name) => (element.getAttribute(name) ?? "").trim() !== "";
83
- if (attribute("aria-label") || attribute("title") || visibleText(element) !== "") return true;
84
- return (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).some((id) => id !== "" && (element.ownerDocument.getElementById(id)?.textContent ?? "").trim() !== "");
85
- }
86
83
  static ɵfac = i0.ɵɵngDeclareFactory({
87
84
  minVersion: "12.0.0",
88
85
  version: "22.2.4",
@@ -223,11 +220,6 @@ i0.ɵɵngDeclareClassMetadata({
223
220
  }]
224
221
  }
225
222
  });
226
- function visibleText(node) {
227
- if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? "").trim();
228
- if (node instanceof Element && (node.getAttribute("aria-hidden") === "true" || node.hasAttribute("hidden"))) return "";
229
- return Array.from(node.childNodes, visibleText).join("");
230
- }
231
223
  export { CkButton };
232
224
 
233
225
  //# sourceMappingURL=ckui-core-button.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ckui-core-button.mjs","names":[],"sources":["../../../../projects/core/button/button.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n PLATFORM_ID,\n Renderer2,\n ViewEncapsulation,\n afterNextRender,\n booleanAttribute,\n computed,\n effect,\n inject,\n input,\n untracked,\n} from '@angular/core';\nimport { CK_CONFIG, CK_LABELS, CkSize } from '@ckui/core';\nimport { CkAnnouncer } from '@ckui/core/internal';\n\ndeclare const ngDevMode: unknown;\n\nexport type CkButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';\n\n/**\n * Styles a native `<button>` or `<a>` as a button. The element keeps every native attribute\n * (`type`, `form`, `aria-*`, `routerLink`); there is no `<ck-button>` element.\n */\n@Component({\n selector: 'button[ckButton], a[ckButton]',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'ck-button',\n '[class]': 'modifierClasses()',\n '[class.ck-button--icon-only]': 'iconOnly()',\n '[class.ck-button--loading]': 'loading()',\n '[class.ck-button--disabled]': 'disabled()',\n },\n template: `\n <span class=\"ck-button__content\"><ng-content /></span>\n <span class=\"ck-button__spinner\" aria-hidden=\"true\"></span>\n `,\n styleUrl: './button.css',\n})\nexport class CkButton {\n readonly variant = input<CkButtonVariant>('secondary');\n /** `undefined` uses the size from `provideCkui`. */\n readonly size = input<CkSize | undefined>(undefined);\n readonly iconOnly = input(false, { transform: booleanAttribute });\n readonly loading = input(false, { transform: booleanAttribute });\n readonly disabled = input(false, { transform: booleanAttribute });\n\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly renderer = inject(Renderer2);\n private readonly config = inject(CK_CONFIG);\n private readonly labels = inject(CK_LABELS);\n private readonly announcer = inject(CkAnnouncer);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly isNativeButton = this.element.tagName === 'BUTTON';\n\n protected readonly modifierClasses = computed(\n () => `ck-button--${this.variant()} ck-button--${this.size() ?? this.config.size}`,\n );\n\n /** The consumer's own value of every attribute this component currently overrides. */\n private readonly overridden = new Map<string, string | null>();\n private previousLoading: boolean | undefined;\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n\n // A later `[type]` binding or a static type wins; only a missing type gets the default.\n if (this.isNativeButton && !this.element.hasAttribute('type')) {\n this.renderer.setAttribute(this.element, 'type', 'button');\n }\n\n // Capture phase on the host runs before routerLink and consumer (click) listeners.\n const blockClick = (event: Event): void => {\n if (this.loading() || this.disabled()) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n for (const type of ['click', 'auxclick']) {\n this.element.addEventListener(type, blockClick, { capture: true });\n destroyRef.onDestroy(() =>\n this.element.removeEventListener(type, blockClick, { capture: true }),\n );\n }\n\n effect(() => {\n const disabled = this.disabled();\n const loading = this.loading();\n const blockedLink = !this.isNativeButton && disabled;\n this.override('disabled', this.isNativeButton && disabled ? '' : null);\n this.override('aria-disabled', loading || blockedLink ? 'true' : null);\n this.override('tabindex', blockedLink ? '-1' : null);\n });\n\n effect(() => {\n const loading = this.loading();\n const started = this.previousLoading === false && loading;\n this.previousLoading = loading;\n if (started && this.isBrowser) {\n const message = untracked(() => this.labels().loading);\n void this.announcer.announce(message);\n }\n });\n\n if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n let destroyed = false;\n destroyRef.onDestroy(() => (destroyed = true));\n afterNextRender(() => {\n if (!destroyed && this.iconOnly() && !this.hasAccessibleName()) {\n console.warn(\n '[ckui] ckButton with iconOnly has no accessible name. Add an aria-label, aria-labelledby or title.',\n this.element,\n );\n }\n });\n }\n }\n\n /** Sets the attribute, or gives the consumer's own value back when `value` is null. */\n private override(name: string, value: string | null): void {\n if (value !== null) {\n if (!this.overridden.has(name)) {\n this.overridden.set(name, this.element.getAttribute(name));\n }\n this.renderer.setAttribute(this.element, name, value);\n } else if (this.overridden.has(name)) {\n const previous = this.overridden.get(name) ?? null;\n this.overridden.delete(name);\n if (previous === null) {\n this.renderer.removeAttribute(this.element, name);\n } else {\n this.renderer.setAttribute(this.element, name, previous);\n }\n }\n }\n\n private hasAccessibleName(): boolean {\n const element = this.element;\n const attribute = (name: string): boolean => (element.getAttribute(name) ?? '').trim() !== '';\n if (attribute('aria-label') || attribute('title') || visibleText(element) !== '') {\n return true;\n }\n return (element.getAttribute('aria-labelledby') ?? '')\n .split(/\\s+/)\n .some(\n (id) =>\n id !== '' && (element.ownerDocument.getElementById(id)?.textContent ?? '').trim() !== '',\n );\n }\n}\n\n/** Text that is neither in an `aria-hidden` nor in a `hidden` subtree. */\nfunction visibleText(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent ?? '').trim();\n }\n if (\n node instanceof Element &&\n (node.getAttribute('aria-hidden') === 'true' || node.hasAttribute('hidden'))\n ) {\n return '';\n }\n return Array.from(node.childNodes, visibleText).join('');\n}\n"],"mappings":";;;;;AA6CA,IAAa,WAAb,MAAa,SAAQ;CACV,UAAU,MAAuB,aAAY,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CAE7C,OAAO,MAA0B,QAAU,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAC3C,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CACrD,UAAU,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,UAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CACpD,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAgB,CAAA;CAE7C,UAAU,OAAgC,UAAU,CAAC,CAAC;CACtD,WAAW,OAAO,SAAS;CAC3B,SAAS,OAAO,SAAS;CACzB,SAAS,OAAO,SAAS;CACzB,YAAY,OAAO,WAAW;CAC9B,YAAY,kBAAkB,OAAO,WAAW,CAAC;CACjD,iBAAiB,KAAK,QAAQ,YAAY;CAExC,kBAAkB,eAC7B,cAAc,KAAK,QAAO,EAAE,cAAe,KAAK,KAAI,KAAM,KAAK,OAAO,QAC7E,GAAA,YAAA,CAAA,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sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n PLATFORM_ID,\n Renderer2,\n ViewEncapsulation,\n afterNextRender,\n booleanAttribute,\n computed,\n effect,\n inject,\n input,\n untracked,\n} from '@angular/core';\nimport { CK_CONFIG, CK_LABELS, CkSize } from '@ckui/core';\nimport { CkAnnouncer, hasAccessibleName } from '@ckui/core/internal';\n\ndeclare const ngDevMode: unknown;\n\nexport type CkButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';\n\n/**\n * Styles a native `<button>` or `<a>` as a button. The element keeps every native attribute\n * (`type`, `form`, `aria-*`, `routerLink`); there is no `<ck-button>` element.\n */\n@Component({\n selector: 'button[ckButton], a[ckButton]',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'ck-button',\n '[class]': 'modifierClasses()',\n '[class.ck-button--icon-only]': 'iconOnly()',\n '[class.ck-button--loading]': 'loading()',\n '[class.ck-button--disabled]': 'disabled()',\n },\n template: `\n <span class=\"ck-button__content\"><ng-content /></span>\n <span class=\"ck-button__spinner\" aria-hidden=\"true\"></span>\n `,\n styleUrl: './button.css',\n})\nexport class CkButton {\n readonly variant = input<CkButtonVariant>('secondary');\n /** `undefined` uses the size from `provideCkui`. */\n readonly size = input<CkSize | undefined>(undefined);\n readonly iconOnly = input(false, { transform: booleanAttribute });\n readonly loading = input(false, { transform: booleanAttribute });\n readonly disabled = input(false, { transform: booleanAttribute });\n\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly renderer = inject(Renderer2);\n private readonly config = inject(CK_CONFIG);\n private readonly labels = inject(CK_LABELS);\n private readonly announcer = inject(CkAnnouncer);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly isNativeButton = this.element.tagName === 'BUTTON';\n\n protected readonly modifierClasses = computed(\n () => `ck-button--${this.variant()} ck-button--${this.size() ?? this.config.size}`,\n );\n\n /** The consumer's own value of every attribute this component currently overrides. */\n private readonly overridden = new Map<string, string | null>();\n private previousLoading: boolean | undefined;\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n\n // A later `[type]` binding or a static type wins; only a missing type gets the default.\n if (this.isNativeButton && !this.element.hasAttribute('type')) {\n this.renderer.setAttribute(this.element, 'type', 'button');\n }\n\n // Capture phase on the host runs before routerLink and consumer (click) listeners.\n const blockClick = (event: Event): void => {\n if (this.loading() || this.disabled()) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n for (const type of ['click', 'auxclick']) {\n this.element.addEventListener(type, blockClick, { capture: true });\n destroyRef.onDestroy(() =>\n this.element.removeEventListener(type, blockClick, { capture: true }),\n );\n }\n\n effect(() => {\n const disabled = this.disabled();\n const loading = this.loading();\n const blockedLink = !this.isNativeButton && disabled;\n this.override('disabled', this.isNativeButton && disabled ? '' : null);\n this.override('aria-disabled', loading || blockedLink ? 'true' : null);\n this.override('tabindex', blockedLink ? '-1' : null);\n });\n\n effect(() => {\n const loading = this.loading();\n const started = this.previousLoading === false && loading;\n this.previousLoading = loading;\n if (started && this.isBrowser) {\n const message = untracked(() => this.labels().loading);\n void this.announcer.announce(message);\n }\n });\n\n if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n let destroyed = false;\n destroyRef.onDestroy(() => (destroyed = true));\n afterNextRender(() => {\n if (\n !destroyed &&\n this.iconOnly() &&\n !hasAccessibleName(this.element, { title: true, text: true })\n ) {\n console.warn(\n '[ckui] ckButton with iconOnly has no accessible name. Add an aria-label, aria-labelledby or title.',\n this.element,\n );\n }\n });\n }\n }\n\n /** Sets the attribute, or gives the consumer's own value back when `value` is null. */\n private override(name: string, value: string | null): void {\n if (value !== null) {\n if (!this.overridden.has(name)) {\n this.overridden.set(name, this.element.getAttribute(name));\n }\n this.renderer.setAttribute(this.element, name, value);\n } else if (this.overridden.has(name)) {\n const previous = this.overridden.get(name) ?? null;\n this.overridden.delete(name);\n if (previous ===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