forty-cdk 0.44.0 → 0.45.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/accordion/README.md +16 -3
- package/combobox/README.md +15 -4
- package/disclosure/README.md +15 -3
- package/fesm2022/forty-cdk-accordion.mjs +64 -17
- package/fesm2022/forty-cdk-accordion.mjs.map +1 -1
- package/fesm2022/forty-cdk-avatar.mjs +6 -7
- package/fesm2022/forty-cdk-avatar.mjs.map +1 -1
- package/fesm2022/forty-cdk-combobox.mjs +8 -9
- package/fesm2022/forty-cdk-combobox.mjs.map +1 -1
- package/fesm2022/forty-cdk-core-anchored.mjs +9 -7
- package/fesm2022/forty-cdk-core-anchored.mjs.map +1 -1
- package/fesm2022/forty-cdk-core.mjs +72 -15
- package/fesm2022/forty-cdk-core.mjs.map +1 -1
- package/fesm2022/forty-cdk-defaults.mjs.map +1 -1
- package/fesm2022/forty-cdk-disclosure.mjs +69 -15
- package/fesm2022/forty-cdk-disclosure.mjs.map +1 -1
- package/fesm2022/forty-cdk-select.mjs +6 -7
- package/fesm2022/forty-cdk-select.mjs.map +1 -1
- package/fesm2022/forty-cdk-table.mjs +45 -1
- package/fesm2022/forty-cdk-table.mjs.map +1 -1
- package/package.json +1 -1
- package/radio-group/README.md +2 -2
- package/table/README.md +2 -0
- package/toggle/README.md +2 -2
- package/types/forty-cdk-accordion.d.ts +27 -4
- package/types/forty-cdk-combobox.d.ts +6 -6
- package/types/forty-cdk-core-anchored.d.ts +21 -4
- package/types/forty-cdk-core.d.ts +22 -26
- package/types/forty-cdk-defaults.d.ts +4 -3
- package/types/forty-cdk-disclosure.d.ts +37 -4
package/accordion/README.md
CHANGED
|
@@ -149,6 +149,10 @@ A disabled item cannot be toggled and is skipped by the arrow keys, while stayin
|
|
|
149
149
|
|
|
150
150
|
### `ForAccordionContent`
|
|
151
151
|
|
|
152
|
+
| Property | Type | Description |
|
|
153
|
+
| ------------------ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
154
|
+
| `hiddenUntilFound` | `input<boolean>` | Hides a closed, mounted panel with `hidden="until-found"` in place of `aria-hidden` + `inert`. A find-in-page match or a fragment link inside it expands the item, as a trigger click would. Closing is instant.<br>**Default:** `false` |
|
|
155
|
+
|
|
152
156
|
| Data attribute | Values |
|
|
153
157
|
| ------------------ | -------------------------- |
|
|
154
158
|
| `data-state` | `open` \| `closed` |
|
|
@@ -157,6 +161,14 @@ A disabled item cannot be toggled and is skipped by the arrow keys, while stayin
|
|
|
157
161
|
|
|
158
162
|
`data-disabled` on the item, trigger and content reflects the item's own `[disabled]` or the root's, whichever is set.
|
|
159
163
|
|
|
164
|
+
#### Searchable closed panels with `hiddenUntilFound`
|
|
165
|
+
|
|
166
|
+
Set `hiddenUntilFound` on a panel you leave mounted, and the browser hides the closed panel with `hidden="until-found"`: no consumer CSS is needed to hide it, and find-in-page can still reach its text. A match, or a fragment link to an id inside it, expands the item, collapsing the open one in single mode, exactly as a trigger click would, and the trigger reports `aria-expanded="true"`. A disabled item, or a disabled accordion, stays collapsed and the panel stays hidden.
|
|
167
|
+
|
|
168
|
+
- **No exit animation.** The panel is hidden the moment it closes, so pair the opt-in with an open transition only, if any.
|
|
169
|
+
- **Padding and border stay visible.** `until-found` hides the panel's content with `content-visibility: hidden`, not `display: none`, so the host's own box still renders. Put padding and borders on an inner element.
|
|
170
|
+
- **Browser support.** `hidden="until-found"` is Baseline since December 2025. An older engine treats the value as plain `hidden`, so the panel stays hidden but find-in-page cannot open it.
|
|
171
|
+
|
|
160
172
|
## Keyboard
|
|
161
173
|
|
|
162
174
|
| Key | Action |
|
|
@@ -172,9 +184,10 @@ A disabled item cannot be toggled and is skipped by the arrow keys, while stayin
|
|
|
172
184
|
- **Heading wrapper is your job.** The library does not render a heading around the trigger, so wrap it in the heading level (`<h2>`–`<h6>`) appropriate to your document outline. Without it, screen-reader landmark navigation is broken.
|
|
173
185
|
- **Use a real `<button type="button">` for the trigger.** Native Enter / Space activation and focus come for free; the directive does not synthesize them.
|
|
174
186
|
- **`role="region"`** is added to every panel automatically. APG recommends suppressing it on accordions with 6+ panels to avoid landmark proliferation; there is currently no opt-out.
|
|
175
|
-
- **Closed panels leave the accessibility tree.** While closed, `ForAccordionContent` sets `aria-hidden="true"` and `inert` on the panel, removing it from both the accessibility tree and the focus order. The directive does **not** apply `[hidden]`, so pick how to hide it visually:
|
|
176
|
-
- **Mount / unmount with `@if (item.expanded())`**: the panel is absent from the DOM while closed; the cleanest path for `animate.enter` / `animate.leave`. The trigger
|
|
177
|
-
- **Leave it mounted**: preserve internal state or run CSS-only transitions off `data-state`. Add `display: none` (or your own collapse animation) keyed on `[data-state="closed"]` to also hide it visually.
|
|
187
|
+
- **Closed panels leave the accessibility tree.** While closed, `ForAccordionContent` sets `aria-hidden="true"` and `inert` on the panel, removing it from both the accessibility tree and the focus order. The directive does **not** apply `[hidden]` unless you opt in with `hiddenUntilFound`, so pick how to hide it visually:
|
|
188
|
+
- **Mount / unmount with `@if (item.expanded())`**: the panel is absent from the DOM while closed; the cleanest path for `animate.enter` / `animate.leave`. The trigger drops `aria-controls` while the panel is unmounted, because a reference to an id that is not in the DOM is worse than none.
|
|
189
|
+
- **Leave it mounted**: preserve internal state or run CSS-only transitions off `data-state`. Add `display: none` (or your own collapse animation) keyed on `[data-state="closed"]` to also hide it visually. The trigger keeps `aria-controls` on the closed panel, since it is still in the DOM.
|
|
190
|
+
- **Leave it mounted with `hiddenUntilFound`**: the browser hides the closed panel, removes it from the accessibility tree and the focus order, and lets find-in-page open it. The directive drops `aria-hidden` and `inert` there, since an inert panel is out of reach of find-in-page. See [Searchable closed panels](#searchable-closed-panels-with-hiddenuntilfound).
|
|
178
191
|
- **`aria-disabled`** is applied to the open trigger only when single mode is active and `collapsible=false`, indicating the user cannot collapse it from this trigger.
|
|
179
192
|
- **A truly disabled item (`[disabled]` on `[forAccordionItem]`) uses the native `disabled` attribute on the trigger, by design.** The trigger is a real single-purpose `<button>`, not a roving-tabindex collection item (each trigger stays independently in the Tab order; arrow-key navigation is the APG-optional enhancement on top). The disabled trigger leaves the Tab order and the arrow-key navigation (which already skips it), but stays in the accessibility tree so screen readers announce it as unavailable in browse mode. The [APG Accordion pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/) does not require disabled headers to remain focusable.
|
|
180
193
|
|
package/combobox/README.md
CHANGED
|
@@ -250,7 +250,7 @@ Focus stays on the `<input>` the whole time the listbox is open, so options neve
|
|
|
250
250
|
| `sideOffset` | `4` | Main-axis gap (px) for comboboxes that don't set `sideOffset` themselves. |
|
|
251
251
|
| `collisionPadding` | `8` | Collision-middleware padding (px) for comboboxes that don't set it themselves. |
|
|
252
252
|
| `openHighlight` | `'first'` | Where the editable anatomy's highlight lands on open (`'first'` or `'selected'`), for comboboxes that don't set `openHighlight` themselves. See [Open / close behavior](#open--close-behavior). |
|
|
253
|
-
| `restoreQueryOnClose` | `false` | Whether
|
|
253
|
+
| `restoreQueryOnClose` | `false` | Whether an editable combobox rewrites `query` when the listbox closes without a pick (the selected label in single mode, `''` in multi mode), for comboboxes that don't set it themselves. |
|
|
254
254
|
| `loop` | `true` | Whether arrow navigation wraps past the first / last enabled option, for comboboxes that don't set `loop` themselves. |
|
|
255
255
|
| `toggleAriaLabel` | `'Show options'` | Accessible name of a `[forComboboxToggle]` that sets no `[ariaLabel]`. |
|
|
256
256
|
| `chipsAriaLabel` | `'Selected items'` | Accessible name of a multi-mode `[forComboboxChips]` group that sets no `[ariaLabel]`. |
|
|
@@ -490,7 +490,7 @@ They diverge while the user types and resync on activation:
|
|
|
490
490
|
- **Multi mode** → option's value is toggled in/out of `value`. If `commitOnSelect` is on (default), `query` is **cleared** so the user can search the next item. Listbox stays open.
|
|
491
491
|
- Clear button → both reset.
|
|
492
492
|
- `clearOnQueryChange` (off by default, **single mode only**): flip on to drop `value` automatically whenever the query is edited (useful when the user editing means "I'm picking a new one").
|
|
493
|
-
- `restoreQueryOnClose` (off by default
|
|
493
|
+
- `restoreQueryOnClose` (off by default): flip on to rewrite the input when the listbox closes without a pick, putting the selected label back in single mode and clearing the typed filter in multi mode. See [`restoreQueryOnClose`](#restorequeryonclose).
|
|
494
494
|
|
|
495
495
|
### `commitOnSelect`: single vs multi
|
|
496
496
|
|
|
@@ -529,7 +529,18 @@ Single, restoreQueryOnClose=true
|
|
|
529
529
|
user presses Escape → query="Banana" value=["banana"] ← label restored, listbox closes
|
|
530
530
|
```
|
|
531
531
|
|
|
532
|
-
The label is the one `selected()` resolves: the option's own label once it has rendered, `[itemToStringLabel]` before that (a value bound before the listbox ever opened).
|
|
532
|
+
The label is the one `selected()` resolves: the option's own label once it has rendered, `[itemToStringLabel]` before that (a value bound before the listbox ever opened).
|
|
533
|
+
|
|
534
|
+
In multi mode the input is the search field for the next chip rather than a display of the value, so there is no label to restore: the same closes clear the typed filter instead, and an option press keeps the listbox open as before.
|
|
535
|
+
|
|
536
|
+
```text
|
|
537
|
+
Multi, restoreQueryOnClose=true
|
|
538
|
+
user activates "Banana" → query="" value=["banana"] ← listbox stays open
|
|
539
|
+
user types "ap" → query="ap" value=["banana"]
|
|
540
|
+
user presses Escape → query="" value=["banana"] ← filter cleared, listbox closes
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
The picker anatomy ignores the input, since it already clears its in-panel filter on every close. Enable it for the whole scope with `provideForComboboxDefaults({ restoreQueryOnClose: true })`.
|
|
533
544
|
|
|
534
545
|
## Multi mode
|
|
535
546
|
|
|
@@ -598,7 +609,7 @@ When the input is empty (no query) and the user presses Backspace, focus jumps t
|
|
|
598
609
|
| Commit label / clear query on select | `true` | `[commitOnSelect]="false"` |
|
|
599
610
|
| Clear value on query edit (single only) | `false` | `[clearOnQueryChange]="true"` |
|
|
600
611
|
| Highlight the selection on open | `first` | `openHighlight="selected"` |
|
|
601
|
-
| Restore label on close
|
|
612
|
+
| Restore label / clear query on close | `false` | `[restoreQueryOnClose]="true"` |
|
|
602
613
|
|
|
603
614
|
`openHighlight` decides where the editable anatomy's highlight lands when the listbox opens from focus, click, ArrowDown / ArrowUp or `openOverlay()` without an argument. With `'selected'`, a single-select combobox showing "Spain" reopens on "Spain" rather than on the first option; with nothing selected, ArrowDown still lands on the first option and ArrowUp on the last. Opening from a typed query always highlights the first match, because the list is a filter result there, and the picker anatomy always opens on the selection. With [virtualization](#virtualization) the selection is not honoured: an open that would land on it highlights the first rendered enabled option instead. Both inputs take their default from the scope: `provideForComboboxDefaults({ openHighlight: 'selected', restoreQueryOnClose: true })`.
|
|
604
615
|
|
package/disclosure/README.md
CHANGED
|
@@ -90,24 +90,36 @@ One class and one directive, two states. `disabled` drops the trigger from the t
|
|
|
90
90
|
|
|
91
91
|
Reflects on its host: `id`, `aria-expanded`, `aria-controls`, `disabled`, `data-state`. Toggles the state on click. The disabled reflection and the click guard follow the effective state, which is the trigger's own `disabled` OR the root's. That reflection is the native `disabled` attribute plus `data-disabled`, with no `aria-disabled`: one channel only.
|
|
92
92
|
|
|
93
|
-
`aria-controls`
|
|
93
|
+
`aria-controls` references the content whenever it is mounted, open or closed. Under `@if (open())` the closed content is not in the DOM, so the trigger drops `aria-controls` until it mounts: a reference to a missing id is worse than none.
|
|
94
94
|
|
|
95
95
|
Use a native `<button type="button">` so Enter / Space activation come for free. Other elements lose keyboard accessibility, and that is on you.
|
|
96
96
|
|
|
97
97
|
### `ForDisclosureContent`
|
|
98
98
|
|
|
99
|
+
| Property | Type | Description |
|
|
100
|
+
| ------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| `hiddenUntilFound` | `input<boolean>` | Hides a closed, mounted panel with `hidden="until-found"` in place of `aria-hidden` + `inert`. A find-in-page match or a fragment link inside it opens the disclosure, as a trigger click would. Closing is instant.<br>**Default:** `false` |
|
|
102
|
+
|
|
99
103
|
| Data attribute | Values |
|
|
100
104
|
| --------------- | ------------------ |
|
|
101
105
|
| `data-state` | `open` \| `closed` |
|
|
102
106
|
| `data-disabled` | present \| absent |
|
|
103
107
|
|
|
104
|
-
Reflects on its host: `id`, `data-state`, `data-disabled`, `aria-hidden` (when closed), `inert` (when closed).
|
|
108
|
+
Reflects on its host: `id`, `data-state`, `data-disabled`, `aria-hidden` (when closed), `inert` (when closed), or `hidden="until-found"` in place of the last two when `hiddenUntilFound` is set.
|
|
105
109
|
|
|
106
110
|
The directive does **not** apply `[hidden]` or otherwise control DOM presence. Two patterns work:
|
|
107
111
|
|
|
108
112
|
- **Mount/unmount with `@if (open())`**: the panel is absent from the DOM while closed; idiomatic for `animate.enter` / `animate.leave`.
|
|
109
113
|
- **Leave it mounted**: preserve scroll/input state or run CSS-only transitions off `data-state`. While closed, the directive sets `aria-hidden="true"` and `inert` on the host so the panel is removed from the accessibility tree and focus order. Add `display: none` (or your own collapse animation) keyed on `[data-state="closed"]` to also hide it visually.
|
|
110
114
|
|
|
115
|
+
#### Searchable closed panels with `hiddenUntilFound`
|
|
116
|
+
|
|
117
|
+
Set `hiddenUntilFound` on a panel you leave mounted, and the browser hides the closed panel with `hidden="until-found"`: no consumer CSS is needed to hide it, and find-in-page can still reach its text. A match, or a fragment link to an id inside it, opens the disclosure exactly as a trigger click would, and the trigger reports `aria-expanded="true"`. A disabled disclosure stays closed and the panel stays hidden.
|
|
118
|
+
|
|
119
|
+
- **No exit animation.** The panel is hidden the moment it closes, so pair the opt-in with an open transition only, if any.
|
|
120
|
+
- **Padding and border stay visible.** `until-found` hides the panel's content with `content-visibility: hidden`, not `display: none`, so the host's own box still renders. Put padding and borders on an inner element.
|
|
121
|
+
- **Browser support.** `hidden="until-found"` is Baseline since December 2025. An older engine treats the value as plain `hidden`, so the panel stays hidden but find-in-page cannot open it.
|
|
122
|
+
|
|
111
123
|
If the panel is a semantic region, add `role="region"` and `aria-labelledby="..."` pointing to the trigger.
|
|
112
124
|
|
|
113
125
|
## Accessibility
|
|
@@ -115,7 +127,7 @@ If the panel is a semantic region, add `role="region"` and `aria-labelledby="...
|
|
|
115
127
|
Implements the [WAI-ARIA Disclosure pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/).
|
|
116
128
|
|
|
117
129
|
- The library does not auto-add `role="button"` or keyboard handlers when the trigger is not a `<button>`. Always use a real button.
|
|
118
|
-
- The directive does not apply the native `hidden` attribute to the content
|
|
130
|
+
- The directive does not apply the native `hidden` attribute to the content unless you opt in with `hiddenUntilFound`. Either wrap it with `@if (open())` so it unmounts when closed, or leave it mounted and rely on the `aria-hidden="true"` + `inert` reflection that keeps the closed panel out of the accessibility tree and focus order. Visual hiding (and enter/leave transitions) are still on you. Drive them off `[data-state]`.
|
|
119
131
|
- Disabled state sets the native `disabled` attribute on the trigger (effective on `<button>` elements). Click is also ignored at the directive level as a defensive measure. The trigger can be disabled from the root (`[forDisclosure] [disabled]`) or per trigger (`[forDisclosureTrigger] [disabled]`); either source disables it.
|
|
120
132
|
|
|
121
133
|
## Styling
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { Directive, ElementRef, InjectionToken, booleanAttribute, computed, inject, input, model, signal } from "@angular/core";
|
|
3
|
-
import { Collection, IdGenerator, adoptHostId, assertRootContext, hostButtonType, hostLabelledBy, injectReflectedDirection, injectTextDirection, moveIndex, orphanContextError, reflectDisabled, registerHandle, resolveListNavigation } from "forty-cdk/core";
|
|
3
|
+
import { Collection, HIDDEN_UNTIL_FOUND, IdGenerator, adoptHostId, assertRootContext, hostButtonType, hostLabelledBy, injectReflectedDirection, injectTextDirection, keepHiddenUntilFound, moveIndex, orphanContextError, reflectDisabled, registerHandle, resolveListNavigation } from "forty-cdk/core";
|
|
4
4
|
const FOR_ACCORDION_CONTEXT = new InjectionToken("FOR_ACCORDION_CONTEXT");
|
|
5
5
|
const FOR_ACCORDION_ITEM_CONTEXT = new InjectionToken("FOR_ACCORDION_ITEM_CONTEXT");
|
|
6
6
|
function injectAccordionContext(piece) {
|
|
@@ -32,6 +32,7 @@ function injectAccordionItemContext(piece) {
|
|
|
32
32
|
}
|
|
33
33
|
var ForAccordion = class ForAccordion {
|
|
34
34
|
#triggers = new Collection();
|
|
35
|
+
#contents = signal([], ...ngDevMode ? [{ debugName: "#contents" }] : /* istanbul ignore next */ []);
|
|
35
36
|
multiple = input(false, {
|
|
36
37
|
...ngDevMode ? { debugName: "multiple" } : /* istanbul ignore next */ {},
|
|
37
38
|
transform: booleanAttribute
|
|
@@ -89,6 +90,18 @@ var ForAccordion = class ForAccordion {
|
|
|
89
90
|
unregisterTrigger(handle) {
|
|
90
91
|
this.#triggers.unregister(handle);
|
|
91
92
|
}
|
|
93
|
+
registerContent(item) {
|
|
94
|
+
this.#contents.update((contents) => [...contents, item]);
|
|
95
|
+
}
|
|
96
|
+
unregisterContent(item) {
|
|
97
|
+
this.#contents.update((contents) => {
|
|
98
|
+
const index = contents.lastIndexOf(item);
|
|
99
|
+
return index < 0 ? contents : [...contents.slice(0, index), ...contents.slice(index + 1)];
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
hasContent(item) {
|
|
103
|
+
return this.#contents().includes(item);
|
|
104
|
+
}
|
|
92
105
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
93
106
|
minVersion: "12.0.0",
|
|
94
107
|
version: "22.2.4",
|
|
@@ -409,7 +422,7 @@ var ForAccordionTrigger = class ForAccordionTrigger {
|
|
|
409
422
|
"attr.type": "buttonType()",
|
|
410
423
|
"id": "item.triggerId()",
|
|
411
424
|
"attr.aria-expanded": "item.expanded() ? \"true\" : \"false\"",
|
|
412
|
-
"attr.aria-controls": "item.expanded() ? item.contentId() : null",
|
|
425
|
+
"attr.aria-controls": "item.expanded() || parent.hasContent(item) ? item.contentId() : null",
|
|
413
426
|
"attr.aria-disabled": "ariaDisabled() ? \"true\" : null",
|
|
414
427
|
"attr.data-state": "item.expanded() ? \"open\" : \"closed\"",
|
|
415
428
|
"attr.data-disabled": "item.disabled() ? \"\" : null",
|
|
@@ -434,7 +447,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
434
447
|
"[attr.type]": "buttonType()",
|
|
435
448
|
"[id]": "item.triggerId()",
|
|
436
449
|
"[attr.aria-expanded]": "item.expanded() ? \"true\" : \"false\"",
|
|
437
|
-
"[attr.aria-controls]": "item.expanded() ? item.contentId() : null",
|
|
450
|
+
"[attr.aria-controls]": "item.expanded() || parent.hasContent(item) ? item.contentId() : null",
|
|
438
451
|
"[attr.aria-disabled]": "ariaDisabled() ? \"true\" : null",
|
|
439
452
|
"[attr.data-state]": "item.expanded() ? \"open\" : \"closed\"",
|
|
440
453
|
"[attr.data-disabled]": "item.disabled() ? \"\" : null",
|
|
@@ -449,9 +462,22 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
449
462
|
var ForAccordionContent = class ForAccordionContent {
|
|
450
463
|
parent = injectAccordionContext("ForAccordionContent");
|
|
451
464
|
item = injectAccordionItemContext("ForAccordionContent");
|
|
465
|
+
#host = inject(ElementRef).nativeElement;
|
|
466
|
+
hiddenUntilFound = input(false, {
|
|
467
|
+
...ngDevMode ? { debugName: "hiddenUntilFound" } : /* istanbul ignore next */ {},
|
|
468
|
+
transform: booleanAttribute
|
|
469
|
+
});
|
|
470
|
+
hiddenValue = HIDDEN_UNTIL_FOUND;
|
|
471
|
+
untilFound = computed(() => this.hiddenUntilFound() && !this.item.expanded(), ...ngDevMode ? [{ debugName: "untilFound" }] : /* istanbul ignore next */ []);
|
|
452
472
|
labelledBy = hostLabelledBy(() => this.item.triggerId());
|
|
453
473
|
constructor() {
|
|
454
|
-
this.item.adoptContentId(
|
|
474
|
+
this.item.adoptContentId(this.#host);
|
|
475
|
+
registerHandle(this.item, (item) => this.parent.registerContent(item), (item) => this.parent.unregisterContent(item));
|
|
476
|
+
}
|
|
477
|
+
onBeforeMatch() {
|
|
478
|
+
if (!this.untilFound()) return;
|
|
479
|
+
this.item.toggle();
|
|
480
|
+
if (this.untilFound()) keepHiddenUntilFound(this.#host, () => this.untilFound());
|
|
455
481
|
}
|
|
456
482
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
457
483
|
minVersion: "12.0.0",
|
|
@@ -462,20 +488,31 @@ var ForAccordionContent = class ForAccordionContent {
|
|
|
462
488
|
target: i0.ɵɵFactoryTarget.Directive
|
|
463
489
|
});
|
|
464
490
|
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
465
|
-
minVersion: "
|
|
491
|
+
minVersion: "17.1.0",
|
|
466
492
|
version: "22.2.4",
|
|
467
493
|
type: ForAccordionContent,
|
|
468
494
|
isStandalone: true,
|
|
469
495
|
selector: "[forAccordionContent]",
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
"attr.data-disabled": "item.disabled() ? \"\" : null",
|
|
477
|
-
"attr.data-orientation": "parent.orientation()"
|
|
496
|
+
inputs: { hiddenUntilFound: {
|
|
497
|
+
classPropertyName: "hiddenUntilFound",
|
|
498
|
+
publicName: "hiddenUntilFound",
|
|
499
|
+
isSignal: true,
|
|
500
|
+
isRequired: false,
|
|
501
|
+
transformFunction: null
|
|
478
502
|
} },
|
|
503
|
+
host: {
|
|
504
|
+
listeners: { "beforematch": "onBeforeMatch()" },
|
|
505
|
+
properties: {
|
|
506
|
+
"id": "item.contentId()",
|
|
507
|
+
"attr.role": "\"region\"",
|
|
508
|
+
"attr.hidden": "untilFound() ? hiddenValue : null",
|
|
509
|
+
"attr.aria-hidden": "item.expanded() || hiddenUntilFound() ? null : \"true\"",
|
|
510
|
+
"attr.inert": "item.expanded() || hiddenUntilFound() ? null : \"\"",
|
|
511
|
+
"attr.data-state": "item.expanded() ? \"open\" : \"closed\"",
|
|
512
|
+
"attr.data-disabled": "item.disabled() ? \"\" : null",
|
|
513
|
+
"attr.data-orientation": "parent.orientation()"
|
|
514
|
+
}
|
|
515
|
+
},
|
|
479
516
|
exportAs: ["forAccordionContent"],
|
|
480
517
|
ngImport: i0
|
|
481
518
|
});
|
|
@@ -493,15 +530,25 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
493
530
|
host: {
|
|
494
531
|
"[id]": "item.contentId()",
|
|
495
532
|
"[attr.role]": "\"region\"",
|
|
496
|
-
"[attr.
|
|
497
|
-
"[attr.
|
|
533
|
+
"[attr.hidden]": "untilFound() ? hiddenValue : null",
|
|
534
|
+
"[attr.aria-hidden]": "item.expanded() || hiddenUntilFound() ? null : \"true\"",
|
|
535
|
+
"[attr.inert]": "item.expanded() || hiddenUntilFound() ? null : \"\"",
|
|
498
536
|
"[attr.data-state]": "item.expanded() ? \"open\" : \"closed\"",
|
|
499
537
|
"[attr.data-disabled]": "item.disabled() ? \"\" : null",
|
|
500
|
-
"[attr.data-orientation]": "parent.orientation()"
|
|
538
|
+
"[attr.data-orientation]": "parent.orientation()",
|
|
539
|
+
"(beforematch)": "onBeforeMatch()"
|
|
501
540
|
}
|
|
502
541
|
}]
|
|
503
542
|
}],
|
|
504
|
-
ctorParameters: () => []
|
|
543
|
+
ctorParameters: () => [],
|
|
544
|
+
propDecorators: { hiddenUntilFound: [{
|
|
545
|
+
type: i0.Input,
|
|
546
|
+
args: [{
|
|
547
|
+
isSignal: true,
|
|
548
|
+
alias: "hiddenUntilFound",
|
|
549
|
+
required: false
|
|
550
|
+
}]
|
|
551
|
+
}] }
|
|
505
552
|
});
|
|
506
553
|
export { FOR_ACCORDION_CONTEXT, FOR_ACCORDION_ITEM_CONTEXT, ForAccordion, ForAccordionContent, ForAccordionItem, ForAccordionTrigger };
|
|
507
554
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forty-cdk-accordion.mjs","names":[],"sources":["../../../projects/forty-cdk/accordion/src/accordion-context.ts","../../../projects/forty-cdk/accordion/src/accordion.ts","../../../projects/forty-cdk/accordion/src/accordion-item.ts","../../../projects/forty-cdk/accordion/src/accordion-trigger.ts","../../../projects/forty-cdk/accordion/src/accordion-content.ts"],"sourcesContent":["import { inject, InjectionToken, type Signal } from '@angular/core';\n\nimport {\n assertRootContext,\n type ListNavigationAction,\n orphanContextError,\n type WritingDirection,\n} from 'forty-cdk/core';\n\n/**\n * Registry entry for one `ForAccordionTrigger`. Triggers register their host\n * element so the root can drive keyboard navigation over its own triggers\n * without an unscoped DOM query that would leak into nested accordions.\n *\n * Part of the registration protocol, so it is never exported from\n * `public-api.ts` — see {@link AccordionContext}.\n */\nexport interface ForAccordionTriggerHandle {\n readonly host: HTMLElement;\n readonly disabled: Signal<boolean>;\n}\n\n/**\n * Coordination contract owned by the `ForAccordion` root.\n * Items derive their state from this context; triggers route clicks and\n * keyboard navigation through it.\n */\nexport interface ForAccordionContext {\n readonly multiple: Signal<boolean>;\n readonly collapsible: Signal<boolean>;\n /** Whether the whole accordion is disabled; each item ORs this into its own disabled state. */\n readonly disabled: Signal<boolean>;\n readonly orientation: Signal<'horizontal' | 'vertical'>;\n readonly dir: Signal<WritingDirection>;\n isExpanded(itemValue: string): boolean;\n toggle(itemValue: string): void;\n /** Whether the given item is allowed to collapse right now. */\n canCollapse(itemValue: string): boolean;\n /**\n * Focus a sibling trigger relative to the one currently focused. Disabled\n * triggers are skipped. `currentTrigger` is the element from which the\n * keyboard event originated. Navigation stays within this accordion's own\n * registered triggers, so a nested accordion does not cross-contaminate.\n */\n focusByOffset(currentTrigger: HTMLElement, action: ListNavigationAction): void;\n}\n\n/**\n * Per-item state contract. Provided by `ForAccordionItem`, consumed by\n * its `ForAccordionTrigger` and `ForAccordionContent`.\n */\nexport interface ForAccordionItemContext {\n readonly expanded: Signal<boolean>;\n readonly disabled: Signal<boolean>;\n readonly value: Signal<string>;\n readonly triggerId: Signal<string>;\n readonly contentId: Signal<string>;\n /** Adopts a consumer-set static `id` on the trigger host into `triggerId`. */\n adoptTriggerId(el: HTMLElement): void;\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void;\n toggle(): void;\n}\n\n/**\n * DI token for the accordion's coordination surface, provided by `[forAccordion]`.\n *\n * Publicly typed as the read surface {@link ForAccordionContext}, which is the whole of\n * what the token promises a consumer. The pieces read the same token at an internal type\n * that adds the trigger-registration protocol, so a wrapper re-providing it must alias it\n * to the root: `{ provide: FOR_ACCORDION_CONTEXT, useExisting: MyAccordion }`, where\n * `MyAccordion` extends `ForAccordion`. A value that merely satisfies the declared type\n * resolves too, and is rejected in dev mode by the first piece to reach the protocol.\n */\nexport const FOR_ACCORDION_CONTEXT = new InjectionToken<ForAccordionContext>(\n 'FOR_ACCORDION_CONTEXT',\n);\n\nexport const FOR_ACCORDION_ITEM_CONTEXT = new InjectionToken<ForAccordionItemContext>(\n 'FOR_ACCORDION_ITEM_CONTEXT',\n);\n\n/**\n * The accordion's internal coordination surface: everything\n * {@link ForAccordionContext} publishes plus the trigger-registration protocol\n * the root drives keyboard navigation from.\n *\n * Never exported from `public-api.ts`. It is the type the pieces read\n * {@link FOR_ACCORDION_CONTEXT} at, so a consumer who injects that token gets\n * the read surface while the pieces get the wiring protocol. `ForAccordion`\n * declares the protocol members TS-`private`, which keeps them out of the\n * emitted `.d.ts` while `useExisting` still satisfies this contract at runtime.\n */\nexport interface AccordionContext extends ForAccordionContext {\n registerTrigger(handle: ForAccordionTriggerHandle): void;\n unregisterTrigger(handle: ForAccordionTriggerHandle): void;\n}\n\nexport function injectAccordionContext(piece: string): AccordionContext {\n const ctx = inject(FOR_ACCORDION_CONTEXT, { optional: true }) as AccordionContext | null;\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-ACCORDION-001',\n piece,\n root: '[forAccordion]',\n token: 'FOR_ACCORDION_CONTEXT',\n });\n }\n assertRootContext({\n entryPoint: 'accordion',\n token: 'FOR_ACCORDION_CONTEXT',\n root: '[forAccordion]',\n piece,\n probe: () => ctx.registerTrigger,\n });\n return ctx;\n}\n\nexport function injectAccordionItemContext(piece: string): ForAccordionItemContext {\n const ctx = inject(FOR_ACCORDION_ITEM_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-ACCORDION-002',\n piece,\n root: '[forAccordionItem]',\n token: 'FOR_ACCORDION_ITEM_CONTEXT',\n });\n }\n return ctx;\n}\n","import { booleanAttribute, Directive, input, model } from '@angular/core';\n\nimport {\n Collection,\n type ListNavigationAction,\n moveIndex,\n type WritingDirection,\n injectReflectedDirection,\n injectTextDirection,\n} from 'forty-cdk/core';\nimport {\n FOR_ACCORDION_CONTEXT,\n type ForAccordionContext,\n type ForAccordionTriggerHandle,\n} from './accordion-context';\n\n/**\n * Root of the Accordion primitive. Holds the open value(s) and orchestrates\n * single/multiple expansion, collapse rules, and keyboard navigation between\n * triggers.\n *\n * Implements the [WAI-ARIA Accordion pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/).\n *\n * State is modeled as `value: readonly string[]` regardless of mode:\n * - In single mode (`multiple=false`, default), the array has 0 or 1 element.\n * - In multiple mode, any number of items can be open.\n *\n * @example\n * ```html\n * <div forAccordion [(value)]=\"open\" collapsible>\n * <div forAccordionItem value=\"a\">\n * <h3><button type=\"button\" forAccordionTrigger>A</button></h3>\n * <section forAccordionContent>...</section>\n * </div>\n * <div forAccordionItem value=\"b\">...</div>\n * </div>\n * ```\n */\n@Directive({\n selector: '[forAccordion]',\n exportAs: 'forAccordion',\n host: {\n '[attr.data-orientation]': 'orientation()',\n '[attr.data-disabled]': 'disabled() ? \"\" : null',\n '[attr.dir]': 'reflectedDir()',\n },\n providers: [{ provide: FOR_ACCORDION_CONTEXT, useExisting: ForAccordion }],\n})\nexport class ForAccordion implements ForAccordionContext {\n readonly #triggers = new Collection<ForAccordionTriggerHandle>();\n\n /** When true, multiple items can be expanded simultaneously. */\n readonly multiple = input(false, { transform: booleanAttribute });\n\n /**\n * When true, the whole accordion is disabled: every item's trigger reflects\n * the native `disabled` attribute (dropped from the Tab order and skipped by\n * arrow-key navigation) and cannot toggle. Composes with a per-item\n * `[disabled]` — an item is effectively disabled when either is set. Mirrors\n * the root `disabled` on `ForTabs` / `ForStepper` / `ForDisclosure`.\n */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n /**\n * Single mode only: when true, the open item can be collapsed by clicking\n * its trigger. When false, exactly one item stays open at all times once\n * any has been opened.\n */\n readonly collapsible = input(false, { transform: booleanAttribute });\n\n /**\n * Layout direction of the trigger list. `'vertical'` (default) maps\n * ArrowUp/Down to prev/next; `'horizontal'` maps ArrowLeft/Right (with RTL\n * swap when `dir='rtl'`).\n */\n readonly orientation = input<'horizontal' | 'vertical'>('vertical');\n\n /**\n * Writing direction. Only relevant when `orientation='horizontal'`. When unset (default `null`),\n * the inherited ambient direction is resolved from the nearest ancestor carrying a `dir`\n * attribute (or `<html dir>`), defaulting to `'ltr'`. An explicit `[dir]` always wins. The\n * resolved value is reflected to the host `dir` attribute when a direction is set or declared,\n * and drives arrow-key semantics.\n */\n readonly _dirInput = input<WritingDirection | null>(null, { alias: 'dir' });\n readonly dir = injectTextDirection(this._dirInput);\n private readonly reflectedDir = injectReflectedDirection(this._dirInput);\n\n /**\n * When true (default), arrow navigation between triggers wraps at the ends —\n * moving past the last trigger focuses the first and vice versa. Set `false`\n * to stop at the boundaries. Mirrors the `loop` input on `ForTabs` and\n * `ForListbox`.\n */\n readonly loop = input(true, { transform: booleanAttribute });\n\n /**\n * Two-way bindable. List of currently expanded item values. In single\n * mode the array has 0 or 1 element. The `model()` change emitter\n * (`(valueChange)`) fires only on internal toggles, never on consumer\n * writes via `[(value)]` — observe transitions without binding back.\n */\n readonly value = model<readonly string[]>([]);\n\n isExpanded(itemValue: string): boolean {\n return this.value().includes(itemValue);\n }\n\n toggle(itemValue: string): void {\n const current = this.value();\n const isOpen = current.includes(itemValue);\n\n if (isOpen) {\n if (!this.canCollapse(itemValue)) {\n return;\n }\n this.value.set(current.filter((v) => v !== itemValue));\n return;\n }\n\n if (this.multiple()) {\n this.value.set([...current, itemValue]);\n } else {\n this.value.set([itemValue]);\n }\n }\n\n canCollapse(_itemValue: string): boolean {\n return this.multiple() || this.collapsible();\n }\n\n focusByOffset(currentTrigger: HTMLElement, action: ListNavigationAction): void {\n const triggers = this.#triggers.items();\n if (triggers.length === 0) {\n return;\n }\n const currentIndex = triggers.findIndex((t) => t.host === currentTrigger);\n if (currentIndex === -1 && action !== 'first' && action !== 'last') {\n return;\n }\n const next = moveIndex(currentIndex < 0 ? 0 : currentIndex, triggers.length, action, {\n loop: this.loop(),\n isDisabled: (i) => triggers[i]?.disabled() ?? false,\n });\n if (next !== null) {\n triggers[next]?.host.focus();\n }\n }\n\n private registerTrigger(handle: ForAccordionTriggerHandle): void {\n this.#triggers.register(handle);\n }\n\n private unregisterTrigger(handle: ForAccordionTriggerHandle): void {\n this.#triggers.unregister(handle);\n }\n}\n","import { booleanAttribute, computed, Directive, inject, input, signal } from '@angular/core';\n\nimport { adoptHostId, IdGenerator } from 'forty-cdk/core';\nimport {\n FOR_ACCORDION_ITEM_CONTEXT,\n type ForAccordionItemContext,\n injectAccordionContext,\n} from './accordion-context';\n\n/**\n * One section of a `ForAccordion`. Owns the unique `value` identifying this\n * item to the root and exposes the per-item context that the trigger and\n * content read.\n */\n@Directive({\n selector: '[forAccordionItem]',\n exportAs: 'forAccordionItem',\n host: {\n '[attr.data-state]': 'expanded() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'disabled() ? \"\" : null',\n '[attr.data-orientation]': 'parent.orientation()',\n },\n providers: [{ provide: FOR_ACCORDION_ITEM_CONTEXT, useExisting: ForAccordionItem }],\n})\nexport class ForAccordionItem implements ForAccordionItemContext {\n private readonly parent = injectAccordionContext('ForAccordionItem');\n readonly #idGen = inject(IdGenerator);\n\n /** Unique identifier of this item within the accordion. Required. */\n readonly value = input.required<string>();\n\n /**\n * When true, this item's trigger ignores clicks and reflects the native\n * `disabled` attribute (not `aria-disabled`): dropped from the Tab order and\n * skipped by arrow-key navigation, but kept in the accessibility tree so\n * screen readers still announce it. See `ForAccordionTrigger` for the rationale. Bind via\n * `[disabled]`; read the composed {@link disabled} for state.\n */\n readonly disabledInput = input(false, { transform: booleanAttribute, alias: 'disabled' });\n\n /**\n * Effective disabled: this item's own `[disabled]` OR'd with the root\n * `[forAccordion]`'s `disabled`. Everything that gates on the item's disabled\n * state — native attribute reflection, trigger click, arrow-navigation skip,\n * `data-disabled` — reads this, so disabling the whole accordion disables\n * every item.\n */\n readonly disabled = computed(() => this.disabledInput() || this.parent.disabled());\n\n readonly #triggerId = signal(this.#idGen.next('for-accordion-trigger'));\n readonly #contentId = signal(this.#idGen.next('for-accordion-content'));\n\n readonly triggerId = this.#triggerId.asReadonly();\n readonly contentId = this.#contentId.asReadonly();\n\n readonly expanded = computed(() => this.parent.isExpanded(this.value()));\n\n /**\n * Adopts a consumer-set static `id` on the `[forAccordionTrigger]` host into\n * `triggerId` (preserving anchors / external `aria-labelledby` references /\n * label `for`) instead of letting the `[id]` host binding clobber it.\n */\n adoptTriggerId(el: HTMLElement): void {\n adoptHostId(el, this.#triggerId);\n }\n\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void {\n adoptHostId(el, this.#contentId);\n }\n\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n this.parent.toggle(this.value());\n }\n}\n","import { computed, Directive, ElementRef, inject } from '@angular/core';\n\nimport {\n hostButtonType,\n registerHandle,\n reflectDisabled,\n resolveListNavigation,\n} from 'forty-cdk/core';\nimport { injectAccordionContext, injectAccordionItemContext } from './accordion-context';\n\n/**\n * Header button for a `ForAccordionItem`. Apply on a `<button>` wrapped in a\n * heading element (`<h2>`–`<h6>`) so APG landmark navigation works. The\n * directive host-binds `type=\"button\"` so a trigger inside a `<form>` never\n * submits it on toggle.\n *\n * Handles ARIA wiring, click-to-toggle, and the recommended keyboard\n * navigation (ArrowDown / ArrowUp / Home / End).\n *\n * `aria-controls` is emitted only while the item is expanded — mirroring the\n * overlay triggers' open-only gating — so the reference never dangles at an\n * unmounted panel under the recommended `@if (item.expanded())` mount pattern.\n */\n@Directive({\n selector: '[forAccordionTrigger]',\n exportAs: 'forAccordionTrigger',\n host: {\n '[attr.type]': 'buttonType()',\n '[id]': 'item.triggerId()',\n '[attr.aria-expanded]': 'item.expanded() ? \"true\" : \"false\"',\n '[attr.aria-controls]': 'item.expanded() ? item.contentId() : null',\n '[attr.aria-disabled]': 'ariaDisabled() ? \"true\" : null',\n '[attr.data-state]': 'item.expanded() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'item.disabled() ? \"\" : null',\n '[attr.data-orientation]': 'parent.orientation()',\n '(click)': 'item.toggle()',\n '(keydown)': 'onKeyDown($event)',\n },\n})\nexport class ForAccordionTrigger {\n private readonly buttonType = hostButtonType();\n\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly parent = injectAccordionContext('ForAccordionTrigger');\n private readonly item = injectAccordionItemContext('ForAccordionTrigger');\n\n /**\n * APG: aria-disabled is true only when the panel is open AND the accordion\n * disallows collapse. A real `disabled` item is reflected via the native\n * `disabled` attribute instead — the sanctioned exception to that rule:\n * the trigger is a real single-purpose `<button>`, not a roving collection\n * item (every trigger stays independently in the Tab order; the arrow-key\n * navigation is an APG-optional enhancement layered on top, not a\n * roving-tabindex collection), so native `disabled` is correct here. The\n * button stays in the accessibility tree — screen readers still announce it\n * as unavailable in browse mode — while being dropped from the Tab order and\n * the arrow-key navigation (which `focusByOffset` already skips), keeping\n * disabled triggers uniformly unreachable. The APG Accordion pattern does not\n * require disabled headers to remain focusable.\n */\n private readonly ariaDisabled = computed(() => {\n if (this.item.disabled()) {\n return false;\n }\n return this.item.expanded() && !this.parent.canCollapse(this.item.value());\n });\n\n constructor() {\n this.item.adoptTriggerId(this.#host.nativeElement);\n const handle = {\n host: this.#host.nativeElement,\n disabled: this.item.disabled,\n };\n registerHandle(\n handle,\n (h) => this.parent.registerTrigger(h),\n (h) => this.parent.unregisterTrigger(h),\n );\n reflectDisabled(this.item.disabled);\n }\n\n private onKeyDown(event: KeyboardEvent): void {\n const action = resolveListNavigation(event, {\n orientation: this.parent.orientation(),\n dir: this.parent.dir(),\n });\n if (!action) {\n return;\n }\n event.preventDefault();\n this.parent.focusByOffset(this.#host.nativeElement, action);\n }\n}\n","import { Directive, ElementRef, inject } from '@angular/core';\n\nimport { hostLabelledBy } from 'forty-cdk/core';\nimport { injectAccordionContext, injectAccordionItemContext } from './accordion-context';\n\n/**\n * Panel revealed by a `ForAccordionTrigger`. The directive does not manage\n * DOM presence — wrap with `@if (item.expanded())` so panels mount and\n * unmount with the expanded state and `animate.enter` / `animate.leave`\n * work natively. If the consumer prefers to keep the panel mounted (for\n * CSS-only transitions or to preserve internal state), the directive\n * reflects `aria-hidden=\"true\"` and `inert` while closed so the panel is\n * removed from the accessibility tree and focus order automatically.\n *\n * APG note: `role=\"region\"` adds the panel to the landmark navigation tree.\n * If the accordion has 6+ simultaneously expandable panels, consider not\n * using region — the directive will gain an opt-out input when this comes up\n * in real usage.\n */\n@Directive({\n selector: '[forAccordionContent]',\n exportAs: 'forAccordionContent',\n host: {\n '[id]': 'item.contentId()',\n '[attr.role]': '\"region\"',\n '[attr.aria-hidden]': 'item.expanded() ? null : \"true\"',\n '[attr.inert]': 'item.expanded() ? null : \"\"',\n '[attr.data-state]': 'item.expanded() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'item.disabled() ? \"\" : null',\n '[attr.data-orientation]': 'parent.orientation()',\n },\n})\nexport class ForAccordionContent {\n private readonly parent = injectAccordionContext('ForAccordionContent');\n private readonly item = injectAccordionItemContext('ForAccordionContent');\n\n private readonly labelledBy = hostLabelledBy(() => this.item.triggerId());\n\n constructor() {\n this.item.adoptContentId(inject<ElementRef<HTMLElement>>(ElementRef).nativeElement);\n }\n}\n"],"mappings":";;;AA0EA,MAAa,wBAAwB,IAAI,eACvC,uBAAuB;AAGzB,MAAa,6BAA6B,IAAI,eAC5C,4BAA4B;AAmB9B,SAAgB,uBAAuB,OAAa;CAClD,MAAM,MAAM,OAAO,uBAAuB,EAAE,UAAU,KAAI,CAAE;CAC5D,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN;E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A,YAAA;EAAA,SAAA;EAAA,MAAA;EAAmB,cAAA;EAAA,UAAA;EAAA,MAAA,EAAA,YAAA;GAAA,MAAA;GAAA,aAAA;GAAA,oBAAA;GAAA,cAAA;GAAA,mBAAA;GAAA,sBAAA;GAAA,yBAAA;EAAA,EAAA;EAAA,UAAA,CAAA,qBAAA;EAAA,UAAA;CAAA,CAAA;;AAAnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAmB,YAAA,CAAA;EAb/B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM;IACJ,QAAQ;IACR,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,qBAAqB;IACrB,wBAAwB;IACxB,2BAA2B;GAC5B;EACF,CAAA"}
|
|
1
|
+
{"version":3,"file":"forty-cdk-accordion.mjs","names":[],"sources":["../../../projects/forty-cdk/accordion/src/accordion-context.ts","../../../projects/forty-cdk/accordion/src/accordion.ts","../../../projects/forty-cdk/accordion/src/accordion-item.ts","../../../projects/forty-cdk/accordion/src/accordion-trigger.ts","../../../projects/forty-cdk/accordion/src/accordion-content.ts"],"sourcesContent":["import { inject, InjectionToken, type Signal } from '@angular/core';\n\nimport {\n assertRootContext,\n type ListNavigationAction,\n orphanContextError,\n type WritingDirection,\n} from 'forty-cdk/core';\n\n/**\n * Registry entry for one `ForAccordionTrigger`. Triggers register their host\n * element so the root can drive keyboard navigation over its own triggers\n * without an unscoped DOM query that would leak into nested accordions.\n *\n * Part of the registration protocol, so it is never exported from\n * `public-api.ts` — see {@link AccordionContext}.\n */\nexport interface ForAccordionTriggerHandle {\n readonly host: HTMLElement;\n readonly disabled: Signal<boolean>;\n}\n\n/**\n * Coordination contract owned by the `ForAccordion` root.\n * Items derive their state from this context; triggers route clicks and\n * keyboard navigation through it.\n */\nexport interface ForAccordionContext {\n readonly multiple: Signal<boolean>;\n readonly collapsible: Signal<boolean>;\n /** Whether the whole accordion is disabled; each item ORs this into its own disabled state. */\n readonly disabled: Signal<boolean>;\n readonly orientation: Signal<'horizontal' | 'vertical'>;\n readonly dir: Signal<WritingDirection>;\n isExpanded(itemValue: string): boolean;\n toggle(itemValue: string): void;\n /** Whether the given item is allowed to collapse right now. */\n canCollapse(itemValue: string): boolean;\n /**\n * Focus a sibling trigger relative to the one currently focused. Disabled\n * triggers are skipped. `currentTrigger` is the element from which the\n * keyboard event originated. Navigation stays within this accordion's own\n * registered triggers, so a nested accordion does not cross-contaminate.\n */\n focusByOffset(currentTrigger: HTMLElement, action: ListNavigationAction): void;\n}\n\n/**\n * Per-item state contract. Provided by `ForAccordionItem`, consumed by\n * its `ForAccordionTrigger` and `ForAccordionContent`.\n */\nexport interface ForAccordionItemContext {\n readonly expanded: Signal<boolean>;\n readonly disabled: Signal<boolean>;\n readonly value: Signal<string>;\n readonly triggerId: Signal<string>;\n readonly contentId: Signal<string>;\n /** Adopts a consumer-set static `id` on the trigger host into `triggerId`. */\n adoptTriggerId(el: HTMLElement): void;\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void;\n toggle(): void;\n}\n\n/**\n * DI token for the accordion's coordination surface, provided by `[forAccordion]`.\n *\n * Publicly typed as the read surface {@link ForAccordionContext}, which is the whole of\n * what the token promises a consumer. The pieces read the same token at an internal type\n * that adds the trigger-registration protocol, so a wrapper re-providing it must alias it\n * to the root: `{ provide: FOR_ACCORDION_CONTEXT, useExisting: MyAccordion }`, where\n * `MyAccordion` extends `ForAccordion`. A value that merely satisfies the declared type\n * resolves too, and is rejected in dev mode by the first piece to reach the protocol.\n */\nexport const FOR_ACCORDION_CONTEXT = new InjectionToken<ForAccordionContext>(\n 'FOR_ACCORDION_CONTEXT',\n);\n\nexport const FOR_ACCORDION_ITEM_CONTEXT = new InjectionToken<ForAccordionItemContext>(\n 'FOR_ACCORDION_ITEM_CONTEXT',\n);\n\n/**\n * The accordion's internal coordination surface: everything\n * {@link ForAccordionContext} publishes plus the trigger-registration protocol\n * the root drives keyboard navigation from.\n *\n * Never exported from `public-api.ts`. It is the type the pieces read\n * {@link FOR_ACCORDION_CONTEXT} at, so a consumer who injects that token gets\n * the read surface while the pieces get the wiring protocol. `ForAccordion`\n * declares the protocol members TS-`private`, which keeps them out of the\n * emitted `.d.ts` while `useExisting` still satisfies this contract at runtime.\n */\nexport interface AccordionContext extends ForAccordionContext {\n registerTrigger(handle: ForAccordionTriggerHandle): void;\n unregisterTrigger(handle: ForAccordionTriggerHandle): void;\n registerContent(item: ForAccordionItemContext): void;\n unregisterContent(item: ForAccordionItemContext): void;\n /** Whether a `[forAccordionContent]` is mounted for the item, so its trigger can reference it. */\n hasContent(item: ForAccordionItemContext): boolean;\n}\n\nexport function injectAccordionContext(piece: string): AccordionContext {\n const ctx = inject(FOR_ACCORDION_CONTEXT, { optional: true }) as AccordionContext | null;\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-ACCORDION-001',\n piece,\n root: '[forAccordion]',\n token: 'FOR_ACCORDION_CONTEXT',\n });\n }\n assertRootContext({\n entryPoint: 'accordion',\n token: 'FOR_ACCORDION_CONTEXT',\n root: '[forAccordion]',\n piece,\n probe: () => ctx.registerTrigger,\n });\n return ctx;\n}\n\nexport function injectAccordionItemContext(piece: string): ForAccordionItemContext {\n const ctx = inject(FOR_ACCORDION_ITEM_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-ACCORDION-002',\n piece,\n root: '[forAccordionItem]',\n token: 'FOR_ACCORDION_ITEM_CONTEXT',\n });\n }\n return ctx;\n}\n","import { booleanAttribute, Directive, input, model, signal } from '@angular/core';\n\nimport {\n Collection,\n type ListNavigationAction,\n moveIndex,\n type WritingDirection,\n injectReflectedDirection,\n injectTextDirection,\n} from 'forty-cdk/core';\nimport {\n FOR_ACCORDION_CONTEXT,\n type ForAccordionContext,\n type ForAccordionItemContext,\n type ForAccordionTriggerHandle,\n} from './accordion-context';\n\n/**\n * Root of the Accordion primitive. Holds the open value(s) and orchestrates\n * single/multiple expansion, collapse rules, and keyboard navigation between\n * triggers.\n *\n * Implements the [WAI-ARIA Accordion pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/).\n *\n * State is modeled as `value: readonly string[]` regardless of mode:\n * - In single mode (`multiple=false`, default), the array has 0 or 1 element.\n * - In multiple mode, any number of items can be open.\n *\n * @example\n * ```html\n * <div forAccordion [(value)]=\"open\" collapsible>\n * <div forAccordionItem value=\"a\">\n * <h3><button type=\"button\" forAccordionTrigger>A</button></h3>\n * <section forAccordionContent>...</section>\n * </div>\n * <div forAccordionItem value=\"b\">...</div>\n * </div>\n * ```\n */\n@Directive({\n selector: '[forAccordion]',\n exportAs: 'forAccordion',\n host: {\n '[attr.data-orientation]': 'orientation()',\n '[attr.data-disabled]': 'disabled() ? \"\" : null',\n '[attr.dir]': 'reflectedDir()',\n },\n providers: [{ provide: FOR_ACCORDION_CONTEXT, useExisting: ForAccordion }],\n})\nexport class ForAccordion implements ForAccordionContext {\n readonly #triggers = new Collection<ForAccordionTriggerHandle>();\n readonly #contents = signal<readonly ForAccordionItemContext[]>([]);\n\n /** When true, multiple items can be expanded simultaneously. */\n readonly multiple = input(false, { transform: booleanAttribute });\n\n /**\n * When true, the whole accordion is disabled: every item's trigger reflects\n * the native `disabled` attribute (dropped from the Tab order and skipped by\n * arrow-key navigation) and cannot toggle. Composes with a per-item\n * `[disabled]` — an item is effectively disabled when either is set. Mirrors\n * the root `disabled` on `ForTabs` / `ForStepper` / `ForDisclosure`.\n */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n /**\n * Single mode only: when true, the open item can be collapsed by clicking\n * its trigger. When false, exactly one item stays open at all times once\n * any has been opened.\n */\n readonly collapsible = input(false, { transform: booleanAttribute });\n\n /**\n * Layout direction of the trigger list. `'vertical'` (default) maps\n * ArrowUp/Down to prev/next; `'horizontal'` maps ArrowLeft/Right (with RTL\n * swap when `dir='rtl'`).\n */\n readonly orientation = input<'horizontal' | 'vertical'>('vertical');\n\n /**\n * Writing direction. Only relevant when `orientation='horizontal'`. When unset (default `null`),\n * the inherited ambient direction is resolved from the nearest ancestor carrying a `dir`\n * attribute (or `<html dir>`), defaulting to `'ltr'`. An explicit `[dir]` always wins. The\n * resolved value is reflected to the host `dir` attribute when a direction is set or declared,\n * and drives arrow-key semantics.\n */\n readonly _dirInput = input<WritingDirection | null>(null, { alias: 'dir' });\n readonly dir = injectTextDirection(this._dirInput);\n private readonly reflectedDir = injectReflectedDirection(this._dirInput);\n\n /**\n * When true (default), arrow navigation between triggers wraps at the ends —\n * moving past the last trigger focuses the first and vice versa. Set `false`\n * to stop at the boundaries. Mirrors the `loop` input on `ForTabs` and\n * `ForListbox`.\n */\n readonly loop = input(true, { transform: booleanAttribute });\n\n /**\n * Two-way bindable. List of currently expanded item values. In single\n * mode the array has 0 or 1 element. The `model()` change emitter\n * (`(valueChange)`) fires only on internal toggles, never on consumer\n * writes via `[(value)]` — observe transitions without binding back.\n */\n readonly value = model<readonly string[]>([]);\n\n isExpanded(itemValue: string): boolean {\n return this.value().includes(itemValue);\n }\n\n toggle(itemValue: string): void {\n const current = this.value();\n const isOpen = current.includes(itemValue);\n\n if (isOpen) {\n if (!this.canCollapse(itemValue)) {\n return;\n }\n this.value.set(current.filter((v) => v !== itemValue));\n return;\n }\n\n if (this.multiple()) {\n this.value.set([...current, itemValue]);\n } else {\n this.value.set([itemValue]);\n }\n }\n\n canCollapse(_itemValue: string): boolean {\n return this.multiple() || this.collapsible();\n }\n\n focusByOffset(currentTrigger: HTMLElement, action: ListNavigationAction): void {\n const triggers = this.#triggers.items();\n if (triggers.length === 0) {\n return;\n }\n const currentIndex = triggers.findIndex((t) => t.host === currentTrigger);\n if (currentIndex === -1 && action !== 'first' && action !== 'last') {\n return;\n }\n const next = moveIndex(currentIndex < 0 ? 0 : currentIndex, triggers.length, action, {\n loop: this.loop(),\n isDisabled: (i) => triggers[i]?.disabled() ?? false,\n });\n if (next !== null) {\n triggers[next]?.host.focus();\n }\n }\n\n private registerTrigger(handle: ForAccordionTriggerHandle): void {\n this.#triggers.register(handle);\n }\n\n private unregisterTrigger(handle: ForAccordionTriggerHandle): void {\n this.#triggers.unregister(handle);\n }\n\n private registerContent(item: ForAccordionItemContext): void {\n this.#contents.update((contents) => [...contents, item]);\n }\n\n private unregisterContent(item: ForAccordionItemContext): void {\n this.#contents.update((contents) => {\n const index = contents.lastIndexOf(item);\n return index < 0 ? contents : [...contents.slice(0, index), ...contents.slice(index + 1)];\n });\n }\n\n private hasContent(item: ForAccordionItemContext): boolean {\n return this.#contents().includes(item);\n }\n}\n","import { booleanAttribute, computed, Directive, inject, input, signal } from '@angular/core';\n\nimport { adoptHostId, IdGenerator } from 'forty-cdk/core';\nimport {\n FOR_ACCORDION_ITEM_CONTEXT,\n type ForAccordionItemContext,\n injectAccordionContext,\n} from './accordion-context';\n\n/**\n * One section of a `ForAccordion`. Owns the unique `value` identifying this\n * item to the root and exposes the per-item context that the trigger and\n * content read.\n */\n@Directive({\n selector: '[forAccordionItem]',\n exportAs: 'forAccordionItem',\n host: {\n '[attr.data-state]': 'expanded() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'disabled() ? \"\" : null',\n '[attr.data-orientation]': 'parent.orientation()',\n },\n providers: [{ provide: FOR_ACCORDION_ITEM_CONTEXT, useExisting: ForAccordionItem }],\n})\nexport class ForAccordionItem implements ForAccordionItemContext {\n private readonly parent = injectAccordionContext('ForAccordionItem');\n readonly #idGen = inject(IdGenerator);\n\n /** Unique identifier of this item within the accordion. Required. */\n readonly value = input.required<string>();\n\n /**\n * When true, this item's trigger ignores clicks and reflects the native\n * `disabled` attribute (not `aria-disabled`): dropped from the Tab order and\n * skipped by arrow-key navigation, but kept in the accessibility tree so\n * screen readers still announce it. See `ForAccordionTrigger` for the rationale. Bind via\n * `[disabled]`; read the composed {@link disabled} for state.\n */\n readonly disabledInput = input(false, { transform: booleanAttribute, alias: 'disabled' });\n\n /**\n * Effective disabled: this item's own `[disabled]` OR'd with the root\n * `[forAccordion]`'s `disabled`. Everything that gates on the item's disabled\n * state — native attribute reflection, trigger click, arrow-navigation skip,\n * `data-disabled` — reads this, so disabling the whole accordion disables\n * every item.\n */\n readonly disabled = computed(() => this.disabledInput() || this.parent.disabled());\n\n readonly #triggerId = signal(this.#idGen.next('for-accordion-trigger'));\n readonly #contentId = signal(this.#idGen.next('for-accordion-content'));\n\n readonly triggerId = this.#triggerId.asReadonly();\n readonly contentId = this.#contentId.asReadonly();\n\n readonly expanded = computed(() => this.parent.isExpanded(this.value()));\n\n /**\n * Adopts a consumer-set static `id` on the `[forAccordionTrigger]` host into\n * `triggerId` (preserving anchors / external `aria-labelledby` references /\n * label `for`) instead of letting the `[id]` host binding clobber it.\n */\n adoptTriggerId(el: HTMLElement): void {\n adoptHostId(el, this.#triggerId);\n }\n\n /** Adopts a consumer-set static `id` on the content host into `contentId`. */\n adoptContentId(el: HTMLElement): void {\n adoptHostId(el, this.#contentId);\n }\n\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n this.parent.toggle(this.value());\n }\n}\n","import { computed, Directive, ElementRef, inject } from '@angular/core';\n\nimport {\n hostButtonType,\n registerHandle,\n reflectDisabled,\n resolveListNavigation,\n} from 'forty-cdk/core';\nimport { injectAccordionContext, injectAccordionItemContext } from './accordion-context';\n\n/**\n * Header button for a `ForAccordionItem`. Apply on a `<button>` wrapped in a\n * heading element (`<h2>`–`<h6>`) so APG landmark navigation works. The\n * directive host-binds `type=\"button\"` so a trigger inside a `<form>` never\n * submits it on toggle.\n *\n * Handles ARIA wiring, click-to-toggle, and the recommended keyboard\n * navigation (ArrowDown / ArrowUp / Home / End).\n *\n * `aria-controls` references the item's content while the item is expanded,\n * and while it is collapsed with the content kept mounted. A panel unmounted\n * by `@if (item.expanded())` is not referenced while collapsed.\n */\n@Directive({\n selector: '[forAccordionTrigger]',\n exportAs: 'forAccordionTrigger',\n host: {\n '[attr.type]': 'buttonType()',\n '[id]': 'item.triggerId()',\n '[attr.aria-expanded]': 'item.expanded() ? \"true\" : \"false\"',\n '[attr.aria-controls]': 'item.expanded() || parent.hasContent(item) ? item.contentId() : null',\n '[attr.aria-disabled]': 'ariaDisabled() ? \"true\" : null',\n '[attr.data-state]': 'item.expanded() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'item.disabled() ? \"\" : null',\n '[attr.data-orientation]': 'parent.orientation()',\n '(click)': 'item.toggle()',\n '(keydown)': 'onKeyDown($event)',\n },\n})\nexport class ForAccordionTrigger {\n private readonly buttonType = hostButtonType();\n\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly parent = injectAccordionContext('ForAccordionTrigger');\n private readonly item = injectAccordionItemContext('ForAccordionTrigger');\n\n /**\n * APG: aria-disabled is true only when the panel is open AND the accordion\n * disallows collapse. A real `disabled` item is reflected via the native\n * `disabled` attribute instead — the sanctioned exception to that rule:\n * the trigger is a real single-purpose `<button>`, not a roving collection\n * item (every trigger stays independently in the Tab order; the arrow-key\n * navigation is an APG-optional enhancement layered on top, not a\n * roving-tabindex collection), so native `disabled` is correct here. The\n * button stays in the accessibility tree — screen readers still announce it\n * as unavailable in browse mode — while being dropped from the Tab order and\n * the arrow-key navigation (which `focusByOffset` already skips), keeping\n * disabled triggers uniformly unreachable. The APG Accordion pattern does not\n * require disabled headers to remain focusable.\n */\n private readonly ariaDisabled = computed(() => {\n if (this.item.disabled()) {\n return false;\n }\n return this.item.expanded() && !this.parent.canCollapse(this.item.value());\n });\n\n constructor() {\n this.item.adoptTriggerId(this.#host.nativeElement);\n const handle = {\n host: this.#host.nativeElement,\n disabled: this.item.disabled,\n };\n registerHandle(\n handle,\n (h) => this.parent.registerTrigger(h),\n (h) => this.parent.unregisterTrigger(h),\n );\n reflectDisabled(this.item.disabled);\n }\n\n private onKeyDown(event: KeyboardEvent): void {\n const action = resolveListNavigation(event, {\n orientation: this.parent.orientation(),\n dir: this.parent.dir(),\n });\n if (!action) {\n return;\n }\n event.preventDefault();\n this.parent.focusByOffset(this.#host.nativeElement, action);\n }\n}\n","import { booleanAttribute, computed, Directive, ElementRef, inject, input } from '@angular/core';\n\nimport {\n HIDDEN_UNTIL_FOUND,\n hostLabelledBy,\n keepHiddenUntilFound,\n registerHandle,\n} from 'forty-cdk/core';\nimport { injectAccordionContext, injectAccordionItemContext } from './accordion-context';\n\n/**\n * Panel revealed by a `ForAccordionTrigger`. The directive does not manage\n * DOM presence — wrap with `@if (item.expanded())` so panels mount and\n * unmount with the expanded state and `animate.enter` / `animate.leave`\n * work natively. If the consumer prefers to keep the panel mounted (for\n * CSS-only transitions or to preserve internal state), the directive\n * reflects `aria-hidden=\"true\"` and `inert` while closed so the panel is\n * removed from the accessibility tree and focus order automatically.\n *\n * Set `hiddenUntilFound` on a mounted panel to hide it with\n * `hidden=\"until-found\"` instead, so find-in-page can reach its text and open it.\n *\n * APG note: `role=\"region\"` adds the panel to the landmark navigation tree.\n * If the accordion has 6+ simultaneously expandable panels, consider not\n * using region — the directive will gain an opt-out input when this comes up\n * in real usage.\n */\n@Directive({\n selector: '[forAccordionContent]',\n exportAs: 'forAccordionContent',\n host: {\n '[id]': 'item.contentId()',\n '[attr.role]': '\"region\"',\n '[attr.hidden]': 'untilFound() ? hiddenValue : null',\n '[attr.aria-hidden]': 'item.expanded() || hiddenUntilFound() ? null : \"true\"',\n '[attr.inert]': 'item.expanded() || hiddenUntilFound() ? null : \"\"',\n '[attr.data-state]': 'item.expanded() ? \"open\" : \"closed\"',\n '[attr.data-disabled]': 'item.disabled() ? \"\" : null',\n '[attr.data-orientation]': 'parent.orientation()',\n '(beforematch)': 'onBeforeMatch()',\n },\n})\nexport class ForAccordionContent {\n private readonly parent = injectAccordionContext('ForAccordionContent');\n private readonly item = injectAccordionItemContext('ForAccordionContent');\n readonly #host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n\n /**\n * When set, a collapsed panel is hidden with `hidden=\"until-found\"` in place of\n * `aria-hidden` + `inert`, and a find-in-page match or fragment navigation inside it\n * expands the item as a trigger click would. A disabled item stays collapsed. Closing\n * is instant, so the opt-in rules out an exit animation.\n */\n readonly hiddenUntilFound = input(false, { transform: booleanAttribute });\n\n private readonly hiddenValue = HIDDEN_UNTIL_FOUND;\n\n private readonly untilFound = computed(() => this.hiddenUntilFound() && !this.item.expanded());\n\n private readonly labelledBy = hostLabelledBy(() => this.item.triggerId());\n\n constructor() {\n this.item.adoptContentId(this.#host);\n registerHandle(\n this.item,\n (item) => this.parent.registerContent(item),\n (item) => this.parent.unregisterContent(item),\n );\n }\n\n private onBeforeMatch(): void {\n if (!this.untilFound()) {\n return;\n }\n this.item.toggle();\n if (this.untilFound()) {\n keepHiddenUntilFound(this.#host, () => this.untilFound());\n }\n }\n}\n"],"mappings":";;;AA0EA,MAAa,wBAAwB,IAAI,eACvC,uBAAuB;AAGzB,MAAa,6BAA6B,IAAI,eAC5C,4BAA4B;AAuB9B,SAAgB,uBAAuB,OAAa;CAClD,MAAM,MAAM,OAAO,uBAAuB,EAAE,UAAU,KAAI,CAAE;CAC5D,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN;EACA,MAAM;EACN,OAAO;CACR,CAAA;CAEH,kBAAkB;EAChB,YAAY;EACZ,OAAO;EACP,MAAM;EACN;EACA,aAAa,IAAI;CAClB,CAAA;CACD,OAAO;AACT;AAEA,SAAgB,2BAA2B,OAAa;CACtD,MAAM,MAAM,OAAO,4BAA4B,EAAE,UAAU,KAAI,CAAE;CACjE,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN;EACA,MAAM;EACN,OAAO;CACR,CAAA;CAEH,OAAO;AACT;ACpFA,IAAa,eAAb,MAAa,aAAY;CACd,YAAY,IAAI,WAAU;CAC1B,YAAY,OAA2C,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAG1D,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,W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from "forty-cdk/core";
|
|
5
5
|
import { FOR_AVATAR_DEFAULTS, FOR_AVATAR_DEFAULTS as FOR_AVATAR_DEFAULTS$1, provideForAvatarDefaults } from "forty-cdk/defaults";
|
|
6
6
|
const FOR_AVATAR_CONTEXT = new InjectionToken("FOR_AVATAR_CONTEXT");
|
|
7
|
-
const ROOT_ASSERTION = {
|
|
8
|
-
entryPoint: "avatar",
|
|
9
|
-
token: "FOR_AVATAR_CONTEXT",
|
|
10
|
-
root: "[forAvatar]"
|
|
11
|
-
};
|
|
12
7
|
function injectAvatarContext(piece) {
|
|
13
8
|
const ctx = inject(FOR_AVATAR_CONTEXT, { optional: true });
|
|
14
9
|
if (!ctx) throw orphanContextError({
|
|
@@ -19,7 +14,9 @@ function injectAvatarContext(piece) {
|
|
|
19
14
|
});
|
|
20
15
|
const widened = ctx;
|
|
21
16
|
assertRootContext({
|
|
22
|
-
|
|
17
|
+
entryPoint: "avatar",
|
|
18
|
+
token: "FOR_AVATAR_CONTEXT",
|
|
19
|
+
root: "[forAvatar]",
|
|
23
20
|
piece,
|
|
24
21
|
probe: () => widened.reportStatus
|
|
25
22
|
});
|
|
@@ -35,7 +32,9 @@ function injectAvatarImageContext() {
|
|
|
35
32
|
});
|
|
36
33
|
const widened = ctx;
|
|
37
34
|
assertRootContext({
|
|
38
|
-
|
|
35
|
+
entryPoint: "avatar",
|
|
36
|
+
token: "FOR_AVATAR_CONTEXT",
|
|
37
|
+
root: "[forAvatar]",
|
|
39
38
|
piece: "ForAvatarImage",
|
|
40
39
|
probe: () => widened.reportStatus
|
|
41
40
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forty-cdk-avatar.mjs","names":["FOR_AVATAR_DEFAULTS"],"sources":["../../../projects/forty-cdk/avatar/src/avatar-context.ts","../../../projects/forty-cdk/avatar/src/avatar.ts","../../../projects/forty-cdk/avatar/src/avatar-image.ts","../../../projects/forty-cdk/avatar/src/avatar-fallback.ts"],"sourcesContent":["import { inject, InjectionToken, type Signal } from '@angular/core';\n\nimport { assertRootContext, orphanContextError } from 'forty-cdk/core';\n\n/**\n * Lifecycle stages of the avatar's image:\n * - `idle`: no `src` set yet.\n * - `loading`: `src` set, waiting for the network.\n * - `loaded`: image rendered successfully.\n * - `error`: image failed to load.\n */\nexport type ForAvatarStatus = 'idle' | 'loading' | 'loaded' | 'error';\n\n/** Read surface `[forAvatar]` publishes through {@link FOR_AVATAR_CONTEXT}. */\nexport interface ForAvatarContext {\n /** Current status of the avatar's image. */\n readonly status: Signal<ForAvatarStatus>;\n /**\n * `true` when the consumer should render the fallback. Drives `@if` in\n * the consumer's template. Honors `fallbackDelayMs` for `idle` / `loading`\n * states; `error` flips it to `true` immediately.\n */\n readonly shouldShowFallback: Signal<boolean>;\n}\n\n/**\n * The avatar's piece-coordination surface: the one call `[forAvatarImage]`\n * makes so the root can transition its state machine.\n *\n * **Not** part of {@link ForAvatarContext} and never exported from\n * `public-api.ts` — a consumer drives the status by binding `[src]`, never by\n * reporting a transition into the root.\n */\nexport interface AvatarPieceContext {\n /** Reported by `[forAvatarImage]` so the root can transition its state machine. */\n reportStatus(status: ForAvatarStatus): void;\n}\n\n/**\n * The avatar's internal coordination surface: everything\n * {@link ForAvatarContext} publishes plus the {@link AvatarPieceContext} call.\n *\n * Never exported from `public-api.ts`. It is the type the pieces read\n * {@link FOR_AVATAR_CONTEXT} at, so a consumer who injects that token gets the\n * read surface while `[forAvatarImage]` gets the transition channel. `ForAvatar`\n * declares `reportStatus` TS-`private`, which keeps it out of the emitted\n * `.d.ts` while `useExisting` still satisfies this contract at runtime.\n */\nexport interface AvatarContext extends ForAvatarContext, AvatarPieceContext {}\n\n/**\n * DI token for the avatar's coordination surface, provided by `[forAvatar]`.\n *\n * Publicly typed as the read surface {@link ForAvatarContext}, which is the whole of\n * what the token promises a consumer. `[forAvatarImage]` reads the same token at an\n * internal type that adds the status-report channel, so a wrapper re-providing it must\n * alias it to the root: `{ provide: FOR_AVATAR_CONTEXT, useExisting: MyAvatar }`, where\n * `MyAvatar` extends `ForAvatar`. A value that merely satisfies the declared type\n * resolves too, and is rejected in dev mode by the first piece to reach the channel.\n */\nexport const FOR_AVATAR_CONTEXT = new InjectionToken<ForAvatarContext>('FOR_AVATAR_CONTEXT');\n\n/**\n * The constant half of both resolvers' {@link assertRootContext} calls, so the\n * fallback and the image state the same requirement.\n */\nconst ROOT_ASSERTION = {\n entryPoint: 'avatar',\n token: 'FOR_AVATAR_CONTEXT',\n root: '[forAvatar]',\n};\n\n/**\n * Injects the nearest {@link ForAvatarContext}, throwing a descriptive error\n * when used outside a `[forAvatar]` element.\n *\n * @param piece Name of the calling directive, used in the error message.\n */\nexport function injectAvatarContext(piece: string): AvatarContext {\n const ctx = inject(FOR_AVATAR_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-AVATAR-001',\n piece,\n root: '[forAvatar]',\n token: 'FOR_AVATAR_CONTEXT',\n });\n }\n const widened = ctx as AvatarContext;\n assertRootContext({\n ...ROOT_ASSERTION,\n piece,\n probe: () => widened.reportStatus,\n });\n return widened;\n}\n\n/**\n * `[forAvatarImage]`'s own resolver. It reports a distinct failure from the rest\n * of the anatomy — the image is the piece that drives the state machine, so an\n * orphaned one silently never transitions — and therefore carries its own code\n * rather than routing through {@link injectAvatarContext}.\n */\nexport function injectAvatarImageContext(): AvatarContext {\n const ctx = inject(FOR_AVATAR_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-AVATAR-002',\n piece: 'ForAvatarImage',\n root: '[forAvatar]',\n token: 'FOR_AVATAR_CONTEXT',\n });\n }\n const widened = ctx as AvatarContext;\n assertRootContext({\n ...ROOT_ASSERTION,\n piece: 'ForAvatarImage',\n probe: () => widened.reportStatus,\n });\n return widened;\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n computed,\n DestroyRef,\n Directive,\n effect,\n inject,\n input,\n linkedSignal,\n numberAttribute,\n PLATFORM_ID,\n signal,\n} from '@angular/core';\n\nimport { FOR_AVATAR_CONTEXT, type ForAvatarContext, type ForAvatarStatus } from './avatar-context';\nimport { FOR_AVATAR_DEFAULTS } from 'forty-cdk/defaults';\n\n/**\n * Headless avatar root. Tracks the load lifecycle of an inner\n * `[forAvatarImage]` and exposes `status` + `shouldShowFallback` so the\n * consumer can swap the image for fallback content (initials, generic icon)\n * via `@if`.\n *\n * No ARIA role is imposed — avatars are typically presentational. If the\n * surrounding component conveys identity (a person's name in the header,\n * a chat bubble), the consumer should provide an `aria-label` on the\n * relevant ancestor or pair the avatar with visible text.\n *\n * @example\n * ```html\n * <span forAvatar #a=\"forAvatar\" fallbackDelayMs=\"500\">\n * <img forAvatarImage [src]=\"user.avatarUrl\" [alt]=\"user.name\" />\n * @if (a.shouldShowFallback()) {\n * <span forAvatarFallback>{{ user.initials }}</span>\n * }\n * </span>\n * ```\n */\n@Directive({\n selector: '[forAvatar]',\n exportAs: 'forAvatar',\n host: {\n '[attr.data-status]': 'status()',\n },\n providers: [{ provide: FOR_AVATAR_CONTEXT, useExisting: ForAvatar }],\n})\nexport class ForAvatar implements ForAvatarContext {\n readonly #defaults = inject(FOR_AVATAR_DEFAULTS);\n\n /**\n * Milliseconds to defer the fallback for fast loads, avoiding a brief\n * \"initials → image\" flicker. Set to `0` (default) to show immediately\n * during `idle` / `loading`, or to e.g. `500` to skip rendering during\n * quick cached loads. `error` always shows the fallback immediately.\n * The default is read from `provideForAvatarDefaults` for the\n * surrounding scope.\n */\n readonly fallbackDelayMs = input(this.#defaults.fallbackDelayMs, {\n transform: (value: unknown) => {\n const parsed = numberAttribute(value);\n return Number.isFinite(parsed) ? parsed : this.#defaults.fallbackDelayMs;\n },\n });\n\n readonly #status = signal<ForAvatarStatus>('idle');\n readonly status = this.#status.asReadonly();\n\n // Whether the deferred-fallback timer has fired for the current status/delay.\n // `linkedSignal` resets it to `false` whenever the source changes (the\n // canonical replacement for resetting state inside an effect); the timer\n // callback in the constructor flips it to `true`.\n readonly #timerElapsed = linkedSignal<{ status: ForAvatarStatus; delay: number }, boolean>({\n source: () => ({ status: this.#status(), delay: this.fallbackDelayMs() }),\n computation: () => false,\n });\n #timer: ReturnType<typeof setTimeout> | null = null;\n readonly #isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n readonly shouldShowFallback = computed(() => {\n const status = this.#status();\n if (status === 'loaded') return false;\n if (status === 'error') return true;\n // idle | loading: an immediate (delay <= 0) gate shows the fallback right\n // away; a deferred gate waits for the timer armed in the effect below.\n if (this.fallbackDelayMs() <= 0) return true;\n return this.#timerElapsed();\n });\n\n private reportStatus(status: ForAvatarStatus): void {\n this.#status.set(status);\n }\n\n constructor() {\n // Imperative timer integration: the effect's only job is to (re)arm a\n // setTimeout for the deferred-fallback case (idle | loading with a positive\n // delay). The synchronous branches (loaded / error / delay <= 0) are pure\n // derivations and live in `shouldShowFallback`. The signal write happens\n // inside the timer callback, which runs outside the effect's reactive\n // scope, so this does NOT create a self-cycle in the reactive graph.\n effect(() => {\n const status = this.#status();\n const delay = this.fallbackDelayMs();\n this.#cancelTimer();\n if (this.#isBrowser && (status === 'idle' || status === 'loading') && delay > 0) {\n this.#timer = setTimeout(() => {\n this.#timer = null;\n this.#timerElapsed.set(true);\n }, delay);\n }\n });\n\n inject(DestroyRef).onDestroy(() => this.#cancelTimer());\n }\n\n #cancelTimer(): void {\n if (this.#timer !== null) {\n clearTimeout(this.#timer);\n this.#timer = null;\n }\n }\n}\n","import { afterNextRender, DestroyRef, Directive, ElementRef, inject, output } from '@angular/core';\n\nimport { type ForAvatarStatus, injectAvatarImageContext } from './avatar-context';\n\n/**\n * Wraps an `<img>` and reports its load lifecycle to the surrounding\n * `[forAvatar]`. The native `src` / `alt` bindings are owned by the\n * consumer — this directive only observes.\n *\n * Reflects `data-status` on the image element so the consumer can hide it\n * via CSS while loading or after an error (e.g. `img[data-status=\"error\"]\n * { display: none }`).\n */\n@Directive({\n selector: 'img[forAvatarImage]',\n exportAs: 'forAvatarImage',\n host: {\n '[attr.data-status]': 'status()',\n '(load)': 'onLoad()',\n '(error)': 'onError()',\n },\n})\nexport class ForAvatarImage {\n readonly #host = inject<ElementRef<HTMLImageElement>>(ElementRef).nativeElement;\n readonly #parent = injectAvatarImageContext();\n\n /**\n * Emits whenever the image lifecycle transitions to a new state. Useful\n * if the consumer wants to log analytics, swap to a different src on\n * error, etc.\n */\n readonly loadStatusChange = output<ForAvatarStatus>();\n\n constructor() {\n const parent = this.#parent;\n const host = this.#host;\n\n let destroyed = false;\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(() => (destroyed = true));\n\n afterNextRender(() => {\n this.#syncFromAttr();\n if (destroyed || typeof MutationObserver === 'undefined') return;\n const observer = new MutationObserver(() => {\n this.#syncFromAttr();\n });\n observer.observe(host, { attributes: true, attributeFilter: ['src'] });\n destroyRef.onDestroy(() => observer.disconnect());\n });\n\n // Re-emit upstream whenever the parent's status changes due to our writes.\n // De-dupe on the (request, status) pair rather than status alone: a new\n // `src` opens a fresh request token, so an identical status (e.g. a second\n // image that also `loaded`) still re-reports for the new request, while a\n // repeated status within the same request is suppressed.\n let last: ForAvatarStatus | null = null;\n let lastReportedToken = -1;\n const emit = (status: ForAvatarStatus): void => {\n if (destroyed) return;\n if (last === status && lastReportedToken === this.#requestToken) return;\n last = status;\n lastReportedToken = this.#requestToken;\n parent.reportStatus(status);\n this.loadStatusChange.emit(status);\n };\n this.#emit = emit;\n }\n\n private status(): ForAvatarStatus {\n return this.#parent.status();\n }\n\n private onLoad(): void {\n // Ignore a `load` that fires for a request the host has already moved past\n // (the native event can arrive after `src` was reassigned).\n if (!this.#isCurrentRequest()) return;\n if (!this.#host.complete) return;\n this.#emit('loaded');\n }\n\n private onError(): void {\n if (!this.#isCurrentRequest()) return;\n if (!this.#host.complete) return;\n this.#emit('error');\n }\n\n /**\n * Cheap string-identity fast-path: true when the `src` the host currently\n * carries is the one the latest `#syncFromAttr` observed, so a native\n * load/error event has not drifted away from the in-flight request. This\n * proves src-attribute stability only; request *completeness* (a late event\n * from a superseded resource that happens to share the current src) is\n * verified separately in onLoad/onError via `this.#host.complete`.\n */\n #isCurrentRequest(): boolean {\n return this.#host.getAttribute('src') === this.#requestSrc;\n }\n\n #syncFromAttr(): void {\n const src = this.#host.getAttribute('src');\n this.#requestToken++;\n this.#requestSrc = src;\n if (!src) {\n this.#emit('idle');\n return;\n }\n if (this.#host.complete) {\n // Cached image: load/error events may not fire — derive from naturalWidth.\n if (this.#host.naturalWidth > 0) {\n this.#emit('loaded');\n return;\n }\n // A complete image with zero intrinsic width is ambiguous: it may be a\n // broken image OR a valid SVG with no intrinsic dimensions. Don't\n // pessimistically flag `error` and hide a valid image — verify with\n // `decode()`, which resolves for a decodable (even zero-size) image and\n // rejects for a broken one. Stay `loading` until it settles.\n this.#emit('loading');\n this.#verifyCachedZeroSize(src);\n return;\n }\n this.#emit('loading');\n }\n\n #verifyCachedZeroSize(src: string): void {\n const decode = this.#host.decode?.bind(this.#host);\n if (!decode) {\n // No `decode()` (older engines / jsdom): keep the legacy heuristic.\n this.#emit('error');\n return;\n }\n decode().then(\n () => {\n if (this.#host.getAttribute('src') === src) {\n this.#emit('loaded');\n }\n },\n () => {\n if (this.#host.getAttribute('src') === src) {\n this.#emit('error');\n }\n },\n );\n }\n\n // Initialized in constructor.\n #emit!: (status: ForAvatarStatus) => void;\n\n /** Monotonic id bumped on every `src` change so stale events are ignored. */\n #requestToken = 0;\n /** The `src` the latest `#syncFromAttr` observed, used to match native events. */\n #requestSrc: string | null = null;\n}\n","import { Directive } from '@angular/core';\n\nimport { injectAvatarContext } from './avatar-context';\n\n/**\n * Marker for the avatar's fallback content (initials, generic icon, …).\n * Reflects `data-status` from the parent `[forAvatar]` so the consumer can\n * style for the `error` state separately from `idle` / `loading` if needed.\n *\n * The decision of *whether* to render the fallback lives on the root —\n * drive `@if` with `forAvatar.shouldShowFallback()`.\n */\n@Directive({\n selector: '[forAvatarFallback]',\n exportAs: 'forAvatarFallback',\n host: {\n '[attr.data-status]': 'parent.status()',\n },\n})\nexport class ForAvatarFallback {\n private readonly parent = injectAvatarContext('ForAvatarFallback');\n}\n"],"mappings":";;;;;AA4DA,MAAa,qBAAqB,IAAI,eAAiC,oBAAoB;AAM3F,MAAM,iBAAiB;CACrB,YAAY;CACZ,OAAO;CACP,MAAM;AACP;AAQD,SAAgB,oBAAoB,OAAa;CAC/C,MAAM,MAAM,OAAO,oBAAoB,EAAE,UAAU,KAAI,CAAE;CACzD,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN;EACA,MAAM;EACN,OAAO;CACR,CAAA;CAEH,MAAM,UAAU;CAChB,kBAAkB;EAChB,GAAG;EACH;EACA,aAAa,QAAQ;CACtB,CAAA;CACD,OAAO;AACT;AAQA,SAAgB,2BAAwB;CACtC,MAAM,MAAM,OAAO,oBAAoB,EAAE,UAAU,KAAI,CAAE;CACzD,IAAI,CAAC,KACH,MAAM,mBAAmB;EACvB,MAAM;EACN,OAAO;EACP,MAAM;EACN,OAAO;CACR,CAAA;CAEH,MAAM,UAAU;CAChB,kBAAkB;EAChB,GAAG;EACH,OAAO;EACP,aAAa,QAAQ;CACtB,CAAA;CACD,OAAO;AACT;AC1EA,IAAa,YAAb,MAAa,UAAS;CACX,YAAY,OAAOA,qBAAmB;CAUtC,kBAAkB,MAAM,KAAK,UAAU,iBAAe;EAAA,GAAA,YAAA,EAAA,WAAA,kBAAA,+BAAA,CAAA;EAC7D,YAAY,UAAkB;GAC5B,MAAM,SAAS,gBAAgB,KAAK;GACpC,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,KAAK,UAAU;EAC3D;CAAC,CAAA;CAGM,UAAU,OAAwB,QAAO,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CACzC,SAAS,KAAK,QAAQ,WAAU;CAMhC,gBAAgB,aAAY;EAAA,GAAA,YAAA,EAAA,WAAA,gBAAA,+BAAA,CAAA;EACnC,eAAe;GAAE,QAA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AA;IAAA,QAAA;IAAA,SAAA;GAAA;GAAA,YAAA,EAAA,oBAAA,WAAA;EAAA;EAAA,UAAA,CAAA,gBAAA;EAAA,UAAA;CAAA,CAAA;;AAAd,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAc,YAAA,CAAA;EAT1B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM;IACJ,sBAAsB;IACtB,UAAU;IACV,WAAW;GACZ;EACF,CAAA;;;;;;;;ACFD,IAAa,oBAAb,MAAa,kBAAiB;CACX,SAAS,oBAAoB,mBAAmB;CADtD,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAiB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAjB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAiB,cAAA;EAAA,UAAA;EAAA,MAAA,EAAA,YAAA,EAAA,oBAAA,kBAAA,EAAA;EAAA,UAAA,CAAA,mBAAA;EAAA,UAAA;CAAA,CAAA;;AAAjB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAiB,YAAA,CAAA;EAP7B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM,EACJ,sBAAsB,kBACvB;EACF,CAAA"}
|
|
1
|
+
{"version":3,"file":"forty-cdk-avatar.mjs","names":["FOR_AVATAR_DEFAULTS"],"sources":["../../../projects/forty-cdk/avatar/src/avatar-context.ts","../../../projects/forty-cdk/avatar/src/avatar.ts","../../../projects/forty-cdk/avatar/src/avatar-image.ts","../../../projects/forty-cdk/avatar/src/avatar-fallback.ts"],"sourcesContent":["import { inject, InjectionToken, type Signal } from '@angular/core';\n\nimport { assertRootContext, orphanContextError } from 'forty-cdk/core';\n\n/**\n * Lifecycle stages of the avatar's image:\n * - `idle`: no `src` set yet.\n * - `loading`: `src` set, waiting for the network.\n * - `loaded`: image rendered successfully.\n * - `error`: image failed to load.\n */\nexport type ForAvatarStatus = 'idle' | 'loading' | 'loaded' | 'error';\n\n/** Read surface `[forAvatar]` publishes through {@link FOR_AVATAR_CONTEXT}. */\nexport interface ForAvatarContext {\n /** Current status of the avatar's image. */\n readonly status: Signal<ForAvatarStatus>;\n /**\n * `true` when the consumer should render the fallback. Drives `@if` in\n * the consumer's template. Honors `fallbackDelayMs` for `idle` / `loading`\n * states; `error` flips it to `true` immediately.\n */\n readonly shouldShowFallback: Signal<boolean>;\n}\n\n/**\n * The avatar's piece-coordination surface: the one call `[forAvatarImage]`\n * makes so the root can transition its state machine.\n *\n * **Not** part of {@link ForAvatarContext} and never exported from\n * `public-api.ts` — a consumer drives the status by binding `[src]`, never by\n * reporting a transition into the root.\n */\nexport interface AvatarPieceContext {\n /** Reported by `[forAvatarImage]` so the root can transition its state machine. */\n reportStatus(status: ForAvatarStatus): void;\n}\n\n/**\n * The avatar's internal coordination surface: everything\n * {@link ForAvatarContext} publishes plus the {@link AvatarPieceContext} call.\n *\n * Never exported from `public-api.ts`. It is the type the pieces read\n * {@link FOR_AVATAR_CONTEXT} at, so a consumer who injects that token gets the\n * read surface while `[forAvatarImage]` gets the transition channel. `ForAvatar`\n * declares `reportStatus` TS-`private`, which keeps it out of the emitted\n * `.d.ts` while `useExisting` still satisfies this contract at runtime.\n */\nexport interface AvatarContext extends ForAvatarContext, AvatarPieceContext {}\n\n/**\n * DI token for the avatar's coordination surface, provided by `[forAvatar]`.\n *\n * Publicly typed as the read surface {@link ForAvatarContext}, which is the whole of\n * what the token promises a consumer. `[forAvatarImage]` reads the same token at an\n * internal type that adds the status-report channel, so a wrapper re-providing it must\n * alias it to the root: `{ provide: FOR_AVATAR_CONTEXT, useExisting: MyAvatar }`, where\n * `MyAvatar` extends `ForAvatar`. A value that merely satisfies the declared type\n * resolves too, and is rejected in dev mode by the first piece to reach the channel.\n */\nexport const FOR_AVATAR_CONTEXT = new InjectionToken<ForAvatarContext>('FOR_AVATAR_CONTEXT');\n\n/**\n * Injects the nearest {@link ForAvatarContext}, throwing a descriptive error\n * when used outside a `[forAvatar]` element.\n *\n * @param piece Name of the calling directive, used in the error message.\n */\nexport function injectAvatarContext(piece: string): AvatarContext {\n const ctx = inject(FOR_AVATAR_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-AVATAR-001',\n piece,\n root: '[forAvatar]',\n token: 'FOR_AVATAR_CONTEXT',\n });\n }\n const widened = ctx as AvatarContext;\n assertRootContext({\n entryPoint: 'avatar',\n token: 'FOR_AVATAR_CONTEXT',\n root: '[forAvatar]',\n piece,\n probe: () => widened.reportStatus,\n });\n return widened;\n}\n\n/**\n * `[forAvatarImage]`'s own resolver. It reports a distinct failure from the rest\n * of the anatomy — the image is the piece that drives the state machine, so an\n * orphaned one silently never transitions — and therefore carries its own code\n * rather than routing through {@link injectAvatarContext}.\n */\nexport function injectAvatarImageContext(): AvatarContext {\n const ctx = inject(FOR_AVATAR_CONTEXT, { optional: true });\n if (!ctx) {\n throw orphanContextError({\n code: 'FORCDK-AVATAR-002',\n piece: 'ForAvatarImage',\n root: '[forAvatar]',\n token: 'FOR_AVATAR_CONTEXT',\n });\n }\n const widened = ctx as AvatarContext;\n assertRootContext({\n entryPoint: 'avatar',\n token: 'FOR_AVATAR_CONTEXT',\n root: '[forAvatar]',\n piece: 'ForAvatarImage',\n probe: () => widened.reportStatus,\n });\n return widened;\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n computed,\n DestroyRef,\n Directive,\n effect,\n inject,\n input,\n linkedSignal,\n numberAttribute,\n PLATFORM_ID,\n signal,\n} from '@angular/core';\n\nimport { FOR_AVATAR_CONTEXT, type ForAvatarContext, type ForAvatarStatus } from './avatar-context';\nimport { FOR_AVATAR_DEFAULTS } from 'forty-cdk/defaults';\n\n/**\n * Headless avatar root. Tracks the load lifecycle of an inner\n * `[forAvatarImage]` and exposes `status` + `shouldShowFallback` so the\n * consumer can swap the image for fallback content (initials, generic icon)\n * via `@if`.\n *\n * No ARIA role is imposed — avatars are typically presentational. If the\n * surrounding component conveys identity (a person's name in the header,\n * a chat bubble), the consumer should provide an `aria-label` on the\n * relevant ancestor or pair the avatar with visible text.\n *\n * @example\n * ```html\n * <span forAvatar #a=\"forAvatar\" fallbackDelayMs=\"500\">\n * <img forAvatarImage [src]=\"user.avatarUrl\" [alt]=\"user.name\" />\n * @if (a.shouldShowFallback()) {\n * <span forAvatarFallback>{{ user.initials }}</span>\n * }\n * </span>\n * ```\n */\n@Directive({\n selector: '[forAvatar]',\n exportAs: 'forAvatar',\n host: {\n '[attr.data-status]': 'status()',\n },\n providers: [{ provide: FOR_AVATAR_CONTEXT, useExisting: ForAvatar }],\n})\nexport class ForAvatar implements ForAvatarContext {\n readonly #defaults = inject(FOR_AVATAR_DEFAULTS);\n\n /**\n * Milliseconds to defer the fallback for fast loads, avoiding a brief\n * \"initials → image\" flicker. Set to `0` (default) to show immediately\n * during `idle` / `loading`, or to e.g. `500` to skip rendering during\n * quick cached loads. `error` always shows the fallback immediately.\n * The default is read from `provideForAvatarDefaults` for the\n * surrounding scope.\n */\n readonly fallbackDelayMs = input(this.#defaults.fallbackDelayMs, {\n transform: (value: unknown) => {\n const parsed = numberAttribute(value);\n return Number.isFinite(parsed) ? parsed : this.#defaults.fallbackDelayMs;\n },\n });\n\n readonly #status = signal<ForAvatarStatus>('idle');\n readonly status = this.#status.asReadonly();\n\n // Whether the deferred-fallback timer has fired for the current status/delay.\n // `linkedSignal` resets it to `false` whenever the source changes (the\n // canonical replacement for resetting state inside an effect); the timer\n // callback in the constructor flips it to `true`.\n readonly #timerElapsed = linkedSignal<{ status: ForAvatarStatus; delay: number }, boolean>({\n source: () => ({ status: this.#status(), delay: this.fallbackDelayMs() }),\n computation: () => false,\n });\n #timer: ReturnType<typeof setTimeout> | null = null;\n readonly #isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n readonly shouldShowFallback = computed(() => {\n const status = this.#status();\n if (status === 'loaded') return false;\n if (status === 'error') return true;\n // idle | loading: an immediate (delay <= 0) gate shows the fallback right\n // away; a deferred gate waits for the timer armed in the effect below.\n if (this.fallbackDelayMs() <= 0) return true;\n return this.#timerElapsed();\n });\n\n private reportStatus(status: ForAvatarStatus): void {\n this.#status.set(status);\n }\n\n constructor() {\n // Imperative timer integration: the effect's only job is to (re)arm a\n // setTimeout for the deferred-fallback case (idle | loading with a positive\n // delay). The synchronous branches (loaded / error / delay <= 0) are pure\n // derivations and live in `shouldShowFallback`. The signal write happens\n // inside the timer callback, which runs outside the effect's reactive\n // scope, so this does NOT create a self-cycle in the reactive graph.\n effect(() => {\n const status = this.#status();\n const delay = this.fallbackDelayMs();\n this.#cancelTimer();\n if (this.#isBrowser && (status === 'idle' || status === 'loading') && delay > 0) {\n this.#timer = setTimeout(() => {\n this.#timer = null;\n this.#timerElapsed.set(true);\n }, delay);\n }\n });\n\n inject(DestroyRef).onDestroy(() => this.#cancelTimer());\n }\n\n #cancelTimer(): void {\n if (this.#timer !== null) {\n clearTimeout(this.#timer);\n this.#timer = null;\n }\n }\n}\n","import { afterNextRender, DestroyRef, Directive, ElementRef, inject, output } from '@angular/core';\n\nimport { type ForAvatarStatus, injectAvatarImageContext } from './avatar-context';\n\n/**\n * Wraps an `<img>` and reports its load lifecycle to the surrounding\n * `[forAvatar]`. The native `src` / `alt` bindings are owned by the\n * consumer — this directive only observes.\n *\n * Reflects `data-status` on the image element so the consumer can hide it\n * via CSS while loading or after an error (e.g. `img[data-status=\"error\"]\n * { display: none }`).\n */\n@Directive({\n selector: 'img[forAvatarImage]',\n exportAs: 'forAvatarImage',\n host: {\n '[attr.data-status]': 'status()',\n '(load)': 'onLoad()',\n '(error)': 'onError()',\n },\n})\nexport class ForAvatarImage {\n readonly #host = inject<ElementRef<HTMLImageElement>>(ElementRef).nativeElement;\n readonly #parent = injectAvatarImageContext();\n\n /**\n * Emits whenever the image lifecycle transitions to a new state. Useful\n * if the consumer wants to log analytics, swap to a different src on\n * error, etc.\n */\n readonly loadStatusChange = output<ForAvatarStatus>();\n\n constructor() {\n const parent = this.#parent;\n const host = this.#host;\n\n let destroyed = false;\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(() => (destroyed = true));\n\n afterNextRender(() => {\n this.#syncFromAttr();\n if (destroyed || typeof MutationObserver === 'undefined') return;\n const observer = new MutationObserver(() => {\n this.#syncFromAttr();\n });\n observer.observe(host, { attributes: true, attributeFilter: ['src'] });\n destroyRef.onDestroy(() => observer.disconnect());\n });\n\n // Re-emit upstream whenever the parent's status changes due to our writes.\n // De-dupe on the (request, status) pair rather than status alone: a new\n // `src` opens a fresh request token, so an identical status (e.g. a second\n // image that also `loaded`) still re-reports for the new request, while a\n // repeated status within the same request is suppressed.\n let last: ForAvatarStatus | null = null;\n let lastReportedToken = -1;\n const emit = (status: ForAvatarStatus): void => {\n if (destroyed) return;\n if (last === status && lastReportedToken === this.#requestToken) return;\n last = status;\n lastReportedToken = this.#requestToken;\n parent.reportStatus(status);\n this.loadStatusChange.emit(status);\n };\n this.#emit = emit;\n }\n\n private status(): ForAvatarStatus {\n return this.#parent.status();\n }\n\n private onLoad(): void {\n // Ignore a `load` that fires for a request the host has already moved past\n // (the native event can arrive after `src` was reassigned).\n if (!this.#isCurrentRequest()) return;\n if (!this.#host.complete) return;\n this.#emit('loaded');\n }\n\n private onError(): void {\n if (!this.#isCurrentRequest()) return;\n if (!this.#host.complete) return;\n this.#emit('error');\n }\n\n /**\n * Cheap string-identity fast-path: true when the `src` the host currently\n * carries is the one the latest `#syncFromAttr` observed, so a native\n * load/error event has not drifted away from the in-flight request. This\n * proves src-attribute stability only; request *completeness* (a late event\n * from a superseded resource that happens to share the current src) is\n * verified separately in onLoad/onError via `this.#host.complete`.\n */\n #isCurrentRequest(): boolean {\n return this.#host.getAttribute('src') === this.#requestSrc;\n }\n\n #syncFromAttr(): void {\n const src = this.#host.getAttribute('src');\n this.#requestToken++;\n this.#requestSrc = src;\n if (!src) {\n this.#emit('idle');\n return;\n }\n if (this.#host.complete) {\n // Cached image: load/error events may not fire — derive from naturalWidth.\n if (this.#host.naturalWidth > 0) {\n this.#emit('loaded');\n return;\n }\n // A complete image with zero intrinsic width is ambiguous: it may be a\n // broken image OR a valid SVG with no intrinsic dimensions. Don't\n // pessimistically flag `error` and hide a valid image — verify with\n // `decode()`, which resolves for a decodable (even zero-size) image and\n // rejects for a broken one. Stay `loading` until it settles.\n this.#emit('loading');\n this.#verifyCachedZeroSize(src);\n return;\n }\n this.#emit('loading');\n }\n\n #verifyCachedZeroSize(src: string): void {\n const decode = this.#host.decode?.bind(this.#host);\n if (!decode) {\n // No `decode()` (older engines / jsdom): keep the legacy heuristic.\n this.#emit('error');\n return;\n }\n decode().then(\n () => {\n if (this.#host.getAttribute('src') === src) {\n this.#emit('loaded');\n }\n },\n () => {\n if (this.#host.getAttribute('src') === src) {\n this.#emit('error');\n }\n },\n );\n }\n\n // Initialized in constructor.\n #emit!: (status: ForAvatarStatus) => void;\n\n /** Monotonic id bumped on every `src` change so stale events are ignored. */\n #requestToken = 0;\n /** The `src` the latest `#syncFromAttr` observed, used to match native events. */\n #requestSrc: string | null = null;\n}\n","import { Directive } from '@angular/core';\n\nimport { injectAvatarContext } from './avatar-context';\n\n/**\n * Marker for the avatar's fallback content (initials, generic icon, …).\n * Reflects `data-status` from the parent `[forAvatar]` so the consumer can\n * style for the `error` state separately from `idle` / `loading` if needed.\n *\n * The decision of *whether* to render the fallback lives on the root —\n * drive `@if` with `forAvatar.shouldShowFallback()`.\n */\n@Directive({\n selector: '[forAvatarFallback]',\n exportAs: 'forAvatarFallback',\n host: {\n '[attr.data-status]': 'parent.status()',\n },\n})\nexport class ForAvatarFallback {\n private readonly parent = injectAvatarContext('ForAvatarFallback');\n}\n"],"mappings":";;;;;AA4DA,MAAa,qBAAqB,IAAI,eAAiC,oBAAoB;AAQ3F,SAAgB,o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