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

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/README.md CHANGED
@@ -120,6 +120,127 @@ 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. Labels that do not fit are cut with an ellipsis, the full
149
+ text stays in the accessible name. Component tokens: `--ck-segmented-bg`, `--ck-segmented-border-color`,
150
+ `--ck-segmented-fg`, `--ck-segmented-indicator-bg`, `--ck-segmented-indicator-fg`,
151
+ `--ck-segmented-radius` and `--ck-segmented-padding`.
152
+
153
+ Global element styles: a global `:focus-visible { outline: … }` beats the layered control and draws a
154
+ second ring on the segment itself. Keep it off the segments (`:focus-visible:not(.ck-segment)`) or put
155
+ resets in a layer declared before ckui: `@layer reset, ckui;`.
156
+
157
+ ## Toast
158
+
159
+ ```ts
160
+ import { CkToast } from '@ckui/core/toast';
161
+
162
+ const toast = inject(CkToast);
163
+ const ref = toast.show({
164
+ tone: 'success',
165
+ title: 'Saved',
166
+ message: 'Your changes are stored.',
167
+ action: { label: 'Undo', run: () => restore() },
168
+ });
169
+ const reason = await ref.dismissed; // 'timeout' | 'user' | 'action' | 'replaced' | 'programmatic'
170
+ ```
171
+
172
+ `CkToast.show()` returns a `CkToastRef` (`dismiss()`, `update(partial)`, `dismissed`); `dismissAll()` closes
173
+ everything. Options: `message` (plain text), `title`, `tone` (`neutral`, `success`, `warning`, `danger`),
174
+ `action` (`{ label, run }`), `duration` (milliseconds) and `id`. A toast closes after 5 seconds, except one with
175
+ an `action` or the tone `danger`, which stays until dismissed unless you give a `duration`. The timer pauses
176
+ while the pointer is over the toast, while focus is inside it and while the page is hidden. Showing a toast with
177
+ the `id` of an open one replaces it in place and restarts the timer; the earlier ref reports `replaced`.
178
+
179
+ Every toast has a dismiss button and can be swiped away sideways. Each one is announced to screen readers
180
+ (`danger` assertively, the others politely, as title and message); changed text is announced again, nothing is
181
+ announced on the server. The toasts live in one `section` that is a direct child of `body`, exempt from `inert`
182
+ and painted above dialogs, so they stay clickable while a dialog is open.
183
+
184
+ `provideCkToast({ position, align, max, size })` is optional: `position` is `bottom` (default) or `top`, `align`
185
+ is `center` on a narrow screen and `end` otherwise unless you set it, `max` (default 3) is how many show at once
186
+ (the rest queue), and `size` is the size of the action and dismiss buttons (default from `provideCkui`; `xl` is
187
+ 60px). The newest toast is always nearest the screen edge; safe-area insets are respected, and a narrow screen
188
+ gets the full width minus a `1rem` gutter. A toast that holds focus when it closes hands focus to the next toast,
189
+ else back to where it came from. Component tokens: `--ck-toast-bg` and `--ck-toast-fg` (neutral, success and
190
+ warning), `--ck-toast-danger-bg` and `--ck-toast-danger-fg`, `--ck-toast-radius`, `--ck-toast-max-width` and
191
+ `--ck-toast-shadow`.
192
+
193
+ Global element styles: a global `button:focus-visible { outline: … }` beats the layered toast buttons. Put
194
+ resets in a layer declared before ckui: `@layer reset, ckui;`.
195
+
196
+ ## Dialog
197
+
198
+ ```ts
199
+ import { CK_DIALOG_DATA, CK_DIALOG_IMPORTS, CkDialog, CkDialogRef } from '@ckui/core/dialog';
200
+
201
+ @Component({
202
+ imports: [CK_DIALOG_IMPORTS],
203
+ template: `
204
+ <h2 ckDialogTitle>Delete this workout?</h2>
205
+ <p ckDialogDescription>This cannot be undone.</p>
206
+ <ck-dialog-actions>
207
+ <button ckDialogInitialFocus ckDialogClose="keep">Keep it</button>
208
+ <button ckDialogClose="delete">Delete</button>
209
+ </ck-dialog-actions>
210
+ `,
211
+ })
212
+ class ConfirmDelete {}
213
+
214
+ const ref = inject(CkDialog).open<ConfirmDelete, void, 'keep' | 'delete'>(ConfirmDelete, {
215
+ role: 'alertdialog',
216
+ });
217
+ const answer = await ref.closed; // undefined when dismissed
218
+ ```
219
+
220
+ `CkDialog.open(componentOrTemplate, config)` returns a `CkDialogRef` (`close(result?)`, `closed`); `closeAll()`
221
+ closes everything. The content injects `CK_DIALOG_DATA` and `CkDialogRef`. Config: `data`, `role` (`dialog` or
222
+ `alertdialog`), `width` (`sm`, `md`, `lg`: 24, 32 or 48rem), `dismissible` (Escape, backdrop and swipe; default
223
+ `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
224
+ the dialog has left the screen, with the first result passed to `close()`; Escape, the backdrop, a swipe and
225
+ destroying the app resolve it with `undefined`.
226
+
227
+ The same dialog can be declared in a template: `<ck-dialog [(open)]="open" (closed)="onClosed($event)">` with one
228
+ `<ng-template>` inside, which is rendered only while the dialog is open. Building blocks: `ckDialogTitle` (names the
229
+ dialog), `ckDialogDescription`, `ck-dialog-body` (the only part that scrolls), `ck-dialog-actions`,
230
+ `ckDialogClose="result"` and `ckDialogInitialFocus`. Initial focus goes to the marked element, else the first
231
+ tabbable one of the content (never the close button), else the panel. Focus is trapped, the page behind is inert and
232
+ focus returns to the opener on close.
233
+
234
+ On a narrow screen with a coarse pointer (`mode: 'auto'`) the dialog is a bottom sheet as tall as its content, with a
235
+ swipe handle, stacked full-width actions and the safe-area inset; `fullHeight` makes it as tall as the screen allows.
236
+ Component tokens: `--ck-dialog-bg`, `--ck-dialog-radius`, `--ck-dialog-padding`, `--ck-dialog-max-width` and
237
+ `--ck-dialog-shadow`.
238
+
239
+ Global element styles: a global `h2`, `p` or `button:focus-visible` rule beats the layered dialog styles; scope it
240
+ with `:not(.ck-dialog__title)`, `:not(.ck-dialog__description)` and `:not(.ck-button)`, or put resets in a layer
241
+ declared before ckui: `@layer reset, ckui;`. A component opened through `CkDialog` must keep its host element a
242
+ flex column (the default styles do this); a global `display` on it stops the body from scrolling.
243
+
123
244
  ## Status
124
245
 
125
246
  Pre-release. Version 0.1 is in progress and the API is not stable yet.
@@ -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,KAA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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, 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 === null) {\n this.renderer.removeAttribute(this.element, name);\n } else {\n this.renderer.setAttribute(this.element, name, previous);\n }\n }\n }\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,EAAA,WAAA,kBAAA,CAAA,+BAAA,CAAA,CAAA;CAGgB,6BAAa,IAAI,IAAG;CAC7B;CAER,cAAA;EACE,MAAM,aAAa,OAAO,UAAU;EAGpC,IAAI,KAAK,kBAAkB,CAAC,KAAK,QAAQ,aAAa,MAAM,GAC1D,KAAK,SAAS,aAAa,KAAK,SAAS,QAAQ,QAAQ;EAI3D,MAAM,cAAc,UAAsB;GACxC,IAAI,KAAK,QAAO,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