@cngx/common 0.0.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/a11y/README.md +77 -0
  4. package/card/README.md +79 -0
  5. package/chart/README.md +31 -0
  6. package/data/README.md +883 -0
  7. package/dialog/README.md +84 -0
  8. package/display/README.md +30 -0
  9. package/fesm2022/cngx-common-a11y.mjs +1260 -0
  10. package/fesm2022/cngx-common-a11y.mjs.map +1 -0
  11. package/fesm2022/cngx-common-card.mjs +765 -0
  12. package/fesm2022/cngx-common-card.mjs.map +1 -0
  13. package/fesm2022/cngx-common-chart.mjs +2943 -0
  14. package/fesm2022/cngx-common-chart.mjs.map +1 -0
  15. package/fesm2022/cngx-common-data.mjs +2886 -0
  16. package/fesm2022/cngx-common-data.mjs.map +1 -0
  17. package/fesm2022/cngx-common-dialog.mjs +1366 -0
  18. package/fesm2022/cngx-common-dialog.mjs.map +1 -0
  19. package/fesm2022/cngx-common-display.mjs +1603 -0
  20. package/fesm2022/cngx-common-display.mjs.map +1 -0
  21. package/fesm2022/cngx-common-interactive.mjs +8185 -0
  22. package/fesm2022/cngx-common-interactive.mjs.map +1 -0
  23. package/fesm2022/cngx-common-layout.mjs +1335 -0
  24. package/fesm2022/cngx-common-layout.mjs.map +1 -0
  25. package/fesm2022/cngx-common-popover.mjs +1200 -0
  26. package/fesm2022/cngx-common-popover.mjs.map +1 -0
  27. package/fesm2022/cngx-common-stepper.mjs +1350 -0
  28. package/fesm2022/cngx-common-stepper.mjs.map +1 -0
  29. package/fesm2022/cngx-common-tabs.mjs +1551 -0
  30. package/fesm2022/cngx-common-tabs.mjs.map +1 -0
  31. package/fesm2022/cngx-common.mjs +34 -0
  32. package/fesm2022/cngx-common.mjs.map +1 -0
  33. package/interactive/README.md +211 -0
  34. package/layout/README.md +117 -0
  35. package/package.json +100 -0
  36. package/popover/README.md +218 -0
  37. package/stepper/README.md +102 -0
  38. package/tabs/README.md +32 -0
  39. package/types/cngx-common-a11y.d.ts +616 -0
  40. package/types/cngx-common-card.d.ts +413 -0
  41. package/types/cngx-common-chart.d.ts +1081 -0
  42. package/types/cngx-common-data.d.ts +1460 -0
  43. package/types/cngx-common-dialog.d.ts +772 -0
  44. package/types/cngx-common-display.d.ts +1136 -0
  45. package/types/cngx-common-interactive.d.ts +5013 -0
  46. package/types/cngx-common-layout.d.ts +737 -0
  47. package/types/cngx-common-popover.d.ts +520 -0
  48. package/types/cngx-common-stepper.d.ts +982 -0
  49. package/types/cngx-common-tabs.d.ts +1237 -0
  50. package/types/cngx-common.d.ts +13 -0
@@ -0,0 +1,1551 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, model, input, inject, signal, computed, Directive, TemplateRef, contentChild, DestroyRef, afterNextRender, untracked, effect, makeEnvironmentProviders, isDevMode, linkedSignal, runInInjectionContext } from '@angular/core';
3
+ import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
4
+ import { createTransitionTracker, CNGX_STATEFUL, nextUid } from '@cngx/core/utils';
5
+ import { isObservable } from 'rxjs';
6
+ import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
+ import { Router, NavigationEnd } from '@angular/router';
8
+ import { filter } from 'rxjs/operators';
9
+
10
+ /**
11
+ * Wraps a {@link CngxCommitController} with the action-shape adapter
12
+ * that collapses `Observable<boolean>` / `Promise<boolean>` /
13
+ * `boolean` returns into a single `accept: boolean` outcome.
14
+ */
15
+ function createTabsCommitHandler(opts) {
16
+ const { controller } = opts;
17
+ return {
18
+ isCommitting: controller.isCommitting,
19
+ beginTransition(fromIndex, toIndex, action, onResolve) {
20
+ controller.begin((handlers) => runTabsAction(action, fromIndex, toIndex, handlers), toIndex, fromIndex, {
21
+ onSuccess: () => onResolve(true),
22
+ onError: () => onResolve(false),
23
+ });
24
+ },
25
+ cancel() {
26
+ controller.cancel();
27
+ },
28
+ };
29
+ }
30
+ function runTabsAction(action, fromIndex, toIndex, handlers) {
31
+ let cancelled = false;
32
+ let unsubscribe = null;
33
+ const safeSuccess = (accept) => {
34
+ if (cancelled) {
35
+ return;
36
+ }
37
+ if (accept) {
38
+ handlers.onSuccess(toIndex);
39
+ }
40
+ else {
41
+ handlers.onError(new Error('Tab transition refused by commitAction'));
42
+ }
43
+ };
44
+ const safeError = (err) => {
45
+ if (cancelled) {
46
+ return;
47
+ }
48
+ handlers.onError(err);
49
+ };
50
+ let result;
51
+ try {
52
+ result = action(fromIndex, toIndex);
53
+ }
54
+ catch (err) {
55
+ safeError(err);
56
+ return {
57
+ cancel: () => {
58
+ cancelled = true;
59
+ },
60
+ };
61
+ }
62
+ if (isObservable(result)) {
63
+ // Synchronous Observables (`of(true)`) emit inside `.subscribe` before
64
+ // the assignment binds — close over a pre-declared `let` to avoid TDZ.
65
+ let sub = null;
66
+ sub = result.subscribe({
67
+ next: (accept) => {
68
+ safeSuccess(accept);
69
+ sub?.unsubscribe();
70
+ },
71
+ error: (err) => safeError(err),
72
+ });
73
+ unsubscribe = () => sub?.unsubscribe();
74
+ }
75
+ else if (result != null &&
76
+ typeof result.then === 'function') {
77
+ result.then(safeSuccess, safeError);
78
+ }
79
+ else {
80
+ safeSuccess(result);
81
+ }
82
+ return {
83
+ cancel: () => {
84
+ cancelled = true;
85
+ unsubscribe?.();
86
+ },
87
+ };
88
+ }
89
+ /**
90
+ * DI token for the commit-handler factory. Defaults to
91
+ * {@link createTabsCommitHandler}. Sibling to
92
+ * `CNGX_ARRAY_COMMIT_HANDLER_FACTORY` (select) and
93
+ * `CNGX_STEPPER_COMMIT_HANDLER_FACTORY`.
94
+ */
95
+ const CNGX_TABS_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxTabsCommitHandlerFactory', {
96
+ providedIn: 'root',
97
+ factory: () => createTabsCommitHandler,
98
+ });
99
+
100
+ /**
101
+ * DI token for the tab presenter's contract. Presenter provides via
102
+ * `useExisting`; `CngxTab` injects to register; the organism injects
103
+ * to forward keyboard nav from `CngxRovingTabindex`.
104
+ */
105
+ const CNGX_TAB_GROUP_HOST = new InjectionToken('CngxTabGroupHost');
106
+
107
+ /**
108
+ * Tab-group presenter — brain of every cngx tab flow. Owns the
109
+ * active-index model, the tab registry, orientation, loop policy,
110
+ * and the commit-controller lifecycle. Provides
111
+ * {@link CNGX_TAB_GROUP_HOST} for atoms and {@link CNGX_STATEFUL}
112
+ * so `<cngx-toast-on />` / `<cngx-banner-on />` compose without
113
+ * `[state]` wiring.
114
+ *
115
+ * **Layer:** `@cngx/common/tabs` (Level 2). Directive-only —
116
+ * organisms compose via `hostDirectives`, consumers attach
117
+ * `[cngxTabGroup]` directly.
118
+ */
119
+ class CngxTabGroupPresenter {
120
+ activeIndex = model(0, ...(ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []));
121
+ orientation = input('horizontal', ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
122
+ loop = input(true, ...(ngDevMode ? [{ debugName: "loop" }] : /* istanbul ignore next */ []));
123
+ /**
124
+ * Async-commit action gating the transition. When non-null,
125
+ * `select(...)` routes through {@link CngxTabsCommitHandler}; the
126
+ * action's resolution decides whether the change lands. Supersede
127
+ * semantics come from the commit-controller — a rapid second
128
+ * `select(...)` cancels the in-flight runner.
129
+ */
130
+ commitAction = input(null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
131
+ /**
132
+ * Default `'optimistic'` — tab change is navigation, not a save,
133
+ * so eager visual feedback matches the user's mental model.
134
+ * Switch to `'pessimistic'` when the new tab must wait for the
135
+ * action to confirm.
136
+ */
137
+ commitMode = input('optimistic', ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
138
+ genericFactory = inject(CNGX_COMMIT_CONTROLLER_FACTORY);
139
+ commitController = this.genericFactory();
140
+ commitHandler = inject(CNGX_TABS_COMMIT_HANDLER_FACTORY)({ controller: this.commitController });
141
+ /** Producer surface for the `CNGX_STATEFUL` bridge contract. */
142
+ state = this.commitController.state;
143
+ commitState = this.commitController.state;
144
+ /**
145
+ * Index the user is currently trying to commit to. Tracked
146
+ * separately from `state.data()` (which only updates on success)
147
+ * to drive per-tab `aria-busy`.
148
+ */
149
+ intendedIndex = this.commitController.intendedValue;
150
+ /**
151
+ * Current/previous pair for `commitState.status()`. Skin
152
+ * sub-components feed `<span cngxLiveRegion>` from this tracker
153
+ * for declarative SR announcements. Shared across consumers so
154
+ * the tracker's `linkedSignal` is allocated once per presenter.
155
+ */
156
+ commitTransition = createTransitionTracker(() => this.commitController.state.status());
157
+ // Persistence-of-error surface — see `CngxTabGroupHost.lastFailedIndex`
158
+ // and `originIndexDuringCommit` for the contract.
159
+ lastFailedIndexState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastFailedIndexState" }] : /* istanbul ignore next */ []));
160
+ originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
161
+ /** {@inheritDoc CngxTabGroupHost.lastFailedIndex} */
162
+ lastFailedIndex = this.lastFailedIndexState.asReadonly();
163
+ /** {@inheritDoc CngxTabGroupHost.originIndexDuringCommit} */
164
+ originIndexDuringCommit = this.originIndexDuringCommitState.asReadonly();
165
+ tabsState = signal([], { ...(ngDevMode ? { debugName: "tabsState" } : /* istanbul ignore next */ {}), equal: tabsEqual });
166
+ tabs = this.tabsState.asReadonly();
167
+ clampedIndex = computed(() => {
168
+ const count = this.tabs().length;
169
+ if (count === 0) {
170
+ return 0;
171
+ }
172
+ return Math.max(0, Math.min(this.activeIndex(), count - 1));
173
+ }, ...(ngDevMode ? [{ debugName: "clampedIndex" }] : /* istanbul ignore next */ []));
174
+ activeId = computed(() => this.tabs()[this.clampedIndex()]?.id ?? null, { ...(ngDevMode ? { debugName: "activeId" } : /* istanbul ignore next */ {}), equal: Object.is });
175
+ register(handle) {
176
+ const current = this.tabsState();
177
+ const idx = current.findIndex((h) => h.id === handle.id);
178
+ if (idx >= 0) {
179
+ const next = current.slice();
180
+ next[idx] = handle;
181
+ this.tabsState.set(next);
182
+ return;
183
+ }
184
+ this.tabsState.set([...current, handle]);
185
+ }
186
+ unregister(id) {
187
+ const current = this.tabsState();
188
+ const next = current.filter((h) => h.id !== id);
189
+ if (next.length !== current.length) {
190
+ this.tabsState.set(next);
191
+ }
192
+ }
193
+ /** {@inheritDoc CngxTabGroupHost.clearLastFailed} */
194
+ clearLastFailed() {
195
+ this.lastFailedIndexState.set(undefined);
196
+ }
197
+ select(index) {
198
+ const tabs = this.tabs();
199
+ if (tabs.length === 0) {
200
+ return;
201
+ }
202
+ const target = Math.max(0, Math.min(index, tabs.length - 1));
203
+ if (tabs[target].disabled()) {
204
+ return;
205
+ }
206
+ const previous = this.activeIndex();
207
+ if (target === previous) {
208
+ return;
209
+ }
210
+ const action = this.commitAction();
211
+ if (!action) {
212
+ // No-action fast path — `originIndexDuringCommit` stays
213
+ // untouched, so a stale origin can never leak into the
214
+ // live-region announcement.
215
+ this.activeIndex.set(target);
216
+ if (this.lastFailedIndexState() === target) {
217
+ this.lastFailedIndexState.set(undefined);
218
+ }
219
+ return;
220
+ }
221
+ // Open the commit window — origin is captured ONLY here so a
222
+ // stale value never lingers into a non-commit navigation.
223
+ this.originIndexDuringCommitState.set(previous);
224
+ const mode = this.commitMode();
225
+ if (mode === 'optimistic') {
226
+ this.activeIndex.set(target);
227
+ }
228
+ this.commitHandler.beginTransition(previous, target, action, (accept) => {
229
+ if (accept) {
230
+ // Window closes on success — origin label no longer needed;
231
+ // clear the rejection flag if the user re-picked the failed
232
+ // target successfully.
233
+ this.originIndexDuringCommitState.set(undefined);
234
+ if (this.lastFailedIndexState() === target) {
235
+ this.lastFailedIndexState.set(undefined);
236
+ }
237
+ if (mode === 'pessimistic') {
238
+ this.activeIndex.set(target);
239
+ }
240
+ }
241
+ else {
242
+ // Reject — flag the refused target; RETAIN the origin so
243
+ // the organism's `liveAnnouncement` computed can resolve
244
+ // the origin label for the rich rollback phrase. Optimistic
245
+ // rolls back; pessimistic never moved.
246
+ this.lastFailedIndexState.set(target);
247
+ if (mode === 'optimistic') {
248
+ this.activeIndex.set(previous);
249
+ }
250
+ }
251
+ });
252
+ }
253
+ selectNext() {
254
+ const tabs = this.tabs();
255
+ if (tabs.length === 0) {
256
+ return;
257
+ }
258
+ let next = this.activeIndex() + 1;
259
+ while (next < tabs.length && tabs[next].disabled()) {
260
+ next++;
261
+ }
262
+ if (next < tabs.length) {
263
+ this.select(next);
264
+ return;
265
+ }
266
+ if (this.loop()) {
267
+ let i = 0;
268
+ while (i < tabs.length && tabs[i].disabled()) {
269
+ i++;
270
+ }
271
+ if (i < tabs.length && i !== this.activeIndex()) {
272
+ this.select(i);
273
+ }
274
+ }
275
+ }
276
+ selectPrevious() {
277
+ const tabs = this.tabs();
278
+ if (tabs.length === 0) {
279
+ return;
280
+ }
281
+ let prev = this.activeIndex() - 1;
282
+ while (prev >= 0 && tabs[prev].disabled()) {
283
+ prev--;
284
+ }
285
+ if (prev >= 0) {
286
+ this.select(prev);
287
+ return;
288
+ }
289
+ if (this.loop()) {
290
+ let i = tabs.length - 1;
291
+ while (i >= 0 && tabs[i].disabled()) {
292
+ i--;
293
+ }
294
+ if (i >= 0 && i !== this.activeIndex()) {
295
+ this.select(i);
296
+ }
297
+ }
298
+ }
299
+ selectById(id) {
300
+ const tabs = this.tabs();
301
+ const idx = tabs.findIndex((h) => h.id === id);
302
+ if (idx >= 0) {
303
+ this.select(idx);
304
+ }
305
+ }
306
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, deps: [], target: i0.ɵɵFactoryTarget.Directive });
307
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabGroupPresenter, isStandalone: true, selector: "[cngxTabGroup]", inputs: { activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, commitAction: { classPropertyName: "commitAction", publicName: "commitAction", isSignal: true, isRequired: false, transformFunction: null }, commitMode: { classPropertyName: "commitMode", publicName: "commitMode", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activeIndex: "activeIndexChange" }, providers: [
308
+ { provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
309
+ { provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
310
+ ], exportAs: ["cngxTabGroup"], ngImport: i0 });
311
+ }
312
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, decorators: [{
313
+ type: Directive,
314
+ args: [{
315
+ selector: '[cngxTabGroup]',
316
+ exportAs: 'cngxTabGroup',
317
+ standalone: true,
318
+ providers: [
319
+ { provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
320
+ { provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
321
+ ],
322
+ }]
323
+ }], propDecorators: { activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], commitAction: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitAction", required: false }] }], commitMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitMode", required: false }] }] } });
324
+ /**
325
+ * Structural equality for the tab registry. Compares length and
326
+ * per-entry `id`, `disabled()`, and `label()`.
327
+ *
328
+ * `errorAggregator` is left out on purpose. The handle is a stable
329
+ * per-tab reference injected once, so comparing it would push the
330
+ * memoisation burden onto consumers and break the structural-equal
331
+ * contract.
332
+ *
333
+ * Reading `disabled()` and `label()` here doesn't subscribe — the
334
+ * comparator runs synchronously inside `signal.set()`, outside any
335
+ * tracking context.
336
+ *
337
+ * @internal
338
+ */
339
+ function tabsEqual(a, b) {
340
+ if (a === b) {
341
+ return true;
342
+ }
343
+ if (a.length !== b.length) {
344
+ return false;
345
+ }
346
+ for (let i = 0; i < a.length; i++) {
347
+ if (a[i].id !== b[i].id ||
348
+ a[i].disabled() !== b[i].disabled() ||
349
+ a[i].label() !== b[i].label()) {
350
+ return false;
351
+ }
352
+ }
353
+ return true;
354
+ }
355
+
356
+ /**
357
+ * DI token the organism provides via `useExisting`. The overflow
358
+ * molecule and consumer-authored skin sub-components inject this
359
+ * instead of the concrete component class.
360
+ */
361
+ const CNGX_TAB_PANEL_HOST = new InjectionToken('CngxTabPanelHost');
362
+
363
+ /**
364
+ * Structural slot directive marking the per-tab panel-body template.
365
+ * Discovered by `<cngx-tab-group>` via `contentChild` on each
366
+ * `CngxTab` and projected into the matching `role="tabpanel"`.
367
+ *
368
+ * ```html
369
+ * <div cngxTab id="settings">
370
+ * <ng-template cngxTabLabel>Settings</ng-template>
371
+ * <ng-template cngxTabContent>
372
+ * <p>Settings panel body…</p>
373
+ * </ng-template>
374
+ * </div>
375
+ * ```
376
+ */
377
+ class CngxTabContent {
378
+ templateRef = inject((TemplateRef));
379
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
380
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabContent, isStandalone: true, selector: "ng-template[cngxTabContent]", exportAs: ["cngxTabContent"], ngImport: i0 });
381
+ }
382
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, decorators: [{
383
+ type: Directive,
384
+ args: [{
385
+ selector: 'ng-template[cngxTabContent]',
386
+ exportAs: 'cngxTabContent',
387
+ standalone: true,
388
+ }]
389
+ }] });
390
+
391
+ /**
392
+ * Structural slot directive marking the per-tab label template.
393
+ * Discovered by `<cngx-tab-group>` via `contentChild` on each
394
+ * `CngxTab` and projected into the tab strip.
395
+ *
396
+ * ```html
397
+ * <div cngxTab id="settings">
398
+ * <ng-template cngxTabLabel>Settings</ng-template>
399
+ * <ng-template cngxTabContent>...</ng-template>
400
+ * </div>
401
+ * ```
402
+ */
403
+ class CngxTabLabel {
404
+ templateRef = inject((TemplateRef));
405
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
406
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabLabel, isStandalone: true, selector: "ng-template[cngxTabLabel]", exportAs: ["cngxTabLabel"], ngImport: i0 });
407
+ }
408
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, decorators: [{
409
+ type: Directive,
410
+ args: [{
411
+ selector: 'ng-template[cngxTabLabel]',
412
+ exportAs: 'cngxTabLabel',
413
+ standalone: true,
414
+ }]
415
+ }] });
416
+
417
+ /**
418
+ * Single-tab atom. Registers with the enclosing presenter via
419
+ * {@link CNGX_TAB_GROUP_HOST} on construction; deregisters via
420
+ * {@link DestroyRef} on teardown. The presenter holds the atom's
421
+ * input signals by reference, so input changes propagate without
422
+ * re-registration. `labelTemplate` / `contentTemplate` are projected
423
+ * by the organism — the atom carries no rendering logic.
424
+ */
425
+ class CngxTab {
426
+ id = input(nextUid('cngx-tab-'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
427
+ disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
428
+ label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
429
+ errorAggregator = input(undefined, ...(ngDevMode ? [{ debugName: "errorAggregator" }] : /* istanbul ignore next */ []));
430
+ labelTemplate = contentChild(CngxTabLabel, ...(ngDevMode ? [{ debugName: "labelTemplate" }] : /* istanbul ignore next */ []));
431
+ contentTemplate = contentChild(CngxTabContent, ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
432
+ host = inject(CNGX_TAB_GROUP_HOST, { optional: true });
433
+ /** `true` when the presenter's `activeId` equals this tab's id. */
434
+ selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
435
+ constructor() {
436
+ if (!this.host) {
437
+ throw new Error('CngxTab: no enclosing CngxTabGroupPresenter found. Wrap the tab inside an element carrying [cngxTabGroup] (or place it inside <cngx-tab-group>).');
438
+ }
439
+ const tabId = this.id();
440
+ this.host.register({
441
+ id: tabId,
442
+ label: this.label,
443
+ disabled: this.disabled,
444
+ errorAggregator: this.errorAggregator,
445
+ });
446
+ const host = this.host;
447
+ inject(DestroyRef).onDestroy(() => host.unregister(tabId));
448
+ }
449
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, deps: [], target: i0.ɵɵFactoryTarget.Directive });
450
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxTab, isStandalone: true, selector: "[cngxTab]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, errorAggregator: { classPropertyName: "errorAggregator", publicName: "errorAggregator", isSignal: true, isRequired: false, transformFunction: null } }, queries: [{ propertyName: "labelTemplate", first: true, predicate: CngxTabLabel, descendants: true, isSignal: true }, { propertyName: "contentTemplate", first: true, predicate: CngxTabContent, descendants: true, isSignal: true }], exportAs: ["cngxTab"], ngImport: i0 });
451
+ }
452
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, decorators: [{
453
+ type: Directive,
454
+ args: [{
455
+ selector: '[cngxTab]',
456
+ exportAs: 'cngxTab',
457
+ standalone: true,
458
+ }]
459
+ }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], errorAggregator: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorAggregator", required: false }] }], labelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabLabel), { isSignal: true }] }], contentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabContent), { isSignal: true }] }] } });
460
+
461
+ /**
462
+ * URL deep-linking for tab groups. Bidirectional sync between
463
+ * `activeId` and a URL fragment or query-param. Opt-in via
464
+ * `[cngxTabsFragmentSync]` on the presenter element.
465
+ *
466
+ * - `mode = 'fragment'` (default) → `#tab=settings`
467
+ * - `mode = 'queryParam'` with `paramName = 'tab'` → `?tab=settings`
468
+ *
469
+ * `Router` is optional — without it the directive logs a dev warning
470
+ * via `afterNextRender` and becomes a no-op. Every `router.navigate`
471
+ * and `host.selectById` inside the effects sits in `untracked()`.
472
+ */
473
+ class CngxTabsFragmentSync {
474
+ mode = input('fragment', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
475
+ paramName = input('tab', ...(ngDevMode ? [{ debugName: "paramName" }] : /* istanbul ignore next */ []));
476
+ host = inject(CNGX_TAB_GROUP_HOST, { host: true });
477
+ router = inject(Router, { optional: true });
478
+ constructor() {
479
+ if (!this.router) {
480
+ afterNextRender(() => {
481
+ console.warn('CngxTabsFragmentSync: no Router available — directive is a no-op. ' +
482
+ 'Provide @angular/router via provideRouter(...) to enable deep-linking.');
483
+ });
484
+ return;
485
+ }
486
+ const router = this.router;
487
+ const destroyRef = inject(DestroyRef);
488
+ afterNextRender(() => {
489
+ const initial = this.readUrlValue(router);
490
+ if (initial) {
491
+ untracked(() => this.host.selectById(initial));
492
+ }
493
+ });
494
+ effect(() => {
495
+ const id = this.host.activeId();
496
+ if (!id) {
497
+ return;
498
+ }
499
+ untracked(() => {
500
+ const navigation = this.mode() === 'fragment'
501
+ ? router.navigate([], {
502
+ fragment: `${this.paramName()}=${id}`,
503
+ queryParamsHandling: 'merge',
504
+ replaceUrl: true,
505
+ })
506
+ : router.navigate([], {
507
+ queryParams: { [this.paramName()]: id },
508
+ queryParamsHandling: 'merge',
509
+ replaceUrl: true,
510
+ });
511
+ // Router rejection (e.g. cancelled navigation) has no recovery path.
512
+ navigation.catch?.(() => undefined);
513
+ });
514
+ });
515
+ const navEnd = toSignal(router.events.pipe(filter((e) => e instanceof NavigationEnd), takeUntilDestroyed(destroyRef)), { initialValue: null });
516
+ effect(() => {
517
+ const e = navEnd();
518
+ if (!e) {
519
+ return;
520
+ }
521
+ untracked(() => {
522
+ const next = this.readUrlValue(router);
523
+ if (next && next !== this.host.activeId()) {
524
+ this.host.selectById(next);
525
+ }
526
+ });
527
+ });
528
+ }
529
+ readUrlValue(router) {
530
+ if (this.mode() === 'fragment') {
531
+ const fragment = router.routerState.snapshot.root.fragment ?? '';
532
+ return this.parseFragment(fragment);
533
+ }
534
+ return (router.routerState.snapshot.root.queryParamMap.get(this.paramName()) ??
535
+ null);
536
+ }
537
+ parseFragment(fragment) {
538
+ const param = this.paramName();
539
+ const segments = fragment.split('&');
540
+ for (const seg of segments) {
541
+ const [key, val] = seg.split('=');
542
+ if (key === param && val) {
543
+ return val;
544
+ }
545
+ }
546
+ return null;
547
+ }
548
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsFragmentSync, deps: [], target: i0.ɵɵFactoryTarget.Directive });
549
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabsFragmentSync, isStandalone: true, selector: "[cngxTabsFragmentSync]", inputs: { mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, paramName: { classPropertyName: "paramName", publicName: "paramName", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxTabsFragmentSync"], ngImport: i0 });
550
+ }
551
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsFragmentSync, decorators: [{
552
+ type: Directive,
553
+ args: [{
554
+ selector: '[cngxTabsFragmentSync]',
555
+ exportAs: 'cngxTabsFragmentSync',
556
+ standalone: true,
557
+ }]
558
+ }], ctorParameters: () => [], propDecorators: { mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], paramName: [{ type: i0.Input, args: [{ isSignal: true, alias: "paramName", required: false }] }] } });
559
+
560
+ const TABS_CONFIG_DEFAULTS = {
561
+ defaultOrientation: 'horizontal',
562
+ defaultLoop: true,
563
+ defaultCommitMode: 'optimistic',
564
+ routerSyncMode: 'fragment',
565
+ routerSyncParam: 'tab',
566
+ ariaLabels: {
567
+ tabsRegion: 'Tabs',
568
+ },
569
+ fallbackLabels: {
570
+ // W3C ARIA tablist convention — kept distinct from
571
+ // `i18n.tabsLabel` so AT doesn't read the same string twice
572
+ // back-to-back across `aria-roledescription` and `aria-label`.
573
+ tabRoleDescription: 'tab list',
574
+ tabPanelRoleDescription: 'tab panel',
575
+ },
576
+ overflowStabilizeMs: 100,
577
+ overflowMaxDeferMs: 250,
578
+ templates: {},
579
+ };
580
+ /**
581
+ * DI token for the resolved tabs config. `providedIn: 'root'` with
582
+ * the library defaults; override via {@link provideTabsConfig}
583
+ * (root) or {@link provideTabsConfigAt} (component scope).
584
+ */
585
+ const CNGX_TABS_CONFIG = new InjectionToken('CngxTabsConfig', { providedIn: 'root', factory: () => TABS_CONFIG_DEFAULTS });
586
+ /**
587
+ * Internal helper that brands a config-mutator function with the
588
+ * `_target` discriminator. Every `with*` config feature returns one
589
+ * of these.
590
+ *
591
+ * @internal
592
+ */
593
+ function defineTabsConfigFeature(fn) {
594
+ return Object.assign(fn, { _target: 'config' });
595
+ }
596
+ /**
597
+ * Override the default orientation. Per-instance `[orientation]`
598
+ * still wins; this changes the cascade default only.
599
+ */
600
+ function withTabsDefaultOrientation(orientation) {
601
+ return defineTabsConfigFeature((cfg) => ({
602
+ ...cfg,
603
+ defaultOrientation: orientation,
604
+ }));
605
+ }
606
+ /**
607
+ * @deprecated Use {@link withTabsDefaultOrientation}. The unprefixed name
608
+ * collides with the stepper family's identical symbol when both libs
609
+ * are auto-imported. The alias stays for one minor release before
610
+ * removal.
611
+ */
612
+ const withDefaultOrientation = withTabsDefaultOrientation;
613
+ /**
614
+ * Override whether roving-tabindex navigation loops from last back to
615
+ * first (and vice versa). Per-instance `[loop]` Input still wins.
616
+ */
617
+ function withTabsRovingLoop(loop) {
618
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, defaultLoop: loop }));
619
+ }
620
+ /**
621
+ * Override the default commit mode for async tab transitions.
622
+ * `'optimistic'` activates the tab on action dispatch and rolls back
623
+ * on error; `'pessimistic'` waits for success. Per-instance
624
+ * `[commitMode]` Input still wins.
625
+ */
626
+ function withTabsCommitMode(mode) {
627
+ return defineTabsConfigFeature((cfg) => ({
628
+ ...cfg,
629
+ defaultCommitMode: mode,
630
+ }));
631
+ }
632
+ /**
633
+ * Configure router synchronisation for the active tab. `mode` chooses
634
+ * the URL surface (URL fragment or query parameter); `param` names
635
+ * the key (default `'tab'`).
636
+ */
637
+ function withTabsRouterSync(mode, param = 'tab') {
638
+ return defineTabsConfigFeature((cfg) => ({
639
+ ...cfg,
640
+ routerSyncMode: mode,
641
+ routerSyncParam: param,
642
+ }));
643
+ }
644
+ /**
645
+ * Merge ARIA labels into the cascade. Keys not provided keep their
646
+ * library defaults; per-instance overrides on the tab group still win.
647
+ */
648
+ function withTabsAriaLabels(labels) {
649
+ return defineTabsConfigFeature((cfg) => ({
650
+ ...cfg,
651
+ ariaLabels: { ...cfg.ariaLabels, ...labels },
652
+ }));
653
+ }
654
+ /**
655
+ * Merge text fallback labels (overflow trigger, busy / rejection text)
656
+ * into the cascade. Used when a slot directive is not present.
657
+ */
658
+ function withTabsFallbackLabels(labels) {
659
+ return defineTabsConfigFeature((cfg) => ({
660
+ ...cfg,
661
+ fallbackLabels: { ...cfg.fallbackLabels, ...labels },
662
+ }));
663
+ }
664
+ /**
665
+ * Override the IO-debounce window (ms). See
666
+ * {@link CngxTabsConfig.overflowStabilizeMs}.
667
+ */
668
+ function withTabOverflowStabilizeMs(ms) {
669
+ return defineTabsConfigFeature((cfg) => ({
670
+ ...cfg,
671
+ overflowStabilizeMs: ms,
672
+ }));
673
+ }
674
+ /**
675
+ * Override the worst-case staleness ceiling on the visibility-map
676
+ * commit. See {@link CngxTabsConfig.overflowMaxDeferMs}.
677
+ */
678
+ function withTabOverflowMaxDeferMs(ms) {
679
+ return defineTabsConfigFeature((cfg) => ({
680
+ ...cfg,
681
+ overflowMaxDeferMs: ms,
682
+ }));
683
+ }
684
+ /**
685
+ * App-wide override for the More-button label. Middle tier;
686
+ * per-instance `*cngxTabOverflowTrigger` still wins.
687
+ *
688
+ * ```ts
689
+ * @ViewChild('moreTrigger', { static: true, read: TemplateRef })
690
+ * moreTrigger!: TemplateRef<CngxTabOverflowTriggerContext>;
691
+ *
692
+ * providers: [provideTabsConfig(withTabOverflowTriggerTemplate(this.moreTrigger))]
693
+ * ```
694
+ */
695
+ function withTabOverflowTriggerTemplate(template) {
696
+ return defineTabsConfigFeature((cfg) => ({
697
+ ...cfg,
698
+ templates: { ...cfg.templates, overflowTrigger: template },
699
+ }));
700
+ }
701
+ /**
702
+ * App-wide override for each row inside the overflow popover.
703
+ * Middle tier; per-instance `*cngxTabOverflowItem` still wins.
704
+ */
705
+ function withTabOverflowItemTemplate(template) {
706
+ return defineTabsConfigFeature((cfg) => ({
707
+ ...cfg,
708
+ templates: { ...cfg.templates, overflowItem: template },
709
+ }));
710
+ }
711
+ /**
712
+ * App-wide override for the error-badge decoration. Middle tier;
713
+ * per-instance `*cngxTabErrorBadge` still wins. Sibling of the
714
+ * stepper family's `withStepBadgeTemplate`.
715
+ */
716
+ function withTabErrorBadgeTemplate(template) {
717
+ return defineTabsConfigFeature((cfg) => ({
718
+ ...cfg,
719
+ templates: { ...cfg.templates, errorBadge: template },
720
+ }));
721
+ }
722
+ /**
723
+ * App-wide override for the rejection-icon decoration. Middle
724
+ * tier; per-instance `*cngxTabRejectionIcon` still wins. Sibling
725
+ * of {@link withStepRejectionTemplate}.
726
+ */
727
+ function withTabRejectionIconTemplate(template) {
728
+ return defineTabsConfigFeature((cfg) => ({
729
+ ...cfg,
730
+ templates: { ...cfg.templates, rejectionIcon: template },
731
+ }));
732
+ }
733
+ /**
734
+ * App-wide override for the commit-pending busy-spinner overlay.
735
+ * Middle tier; per-instance `*cngxTabBusySpinner` still wins.
736
+ * Sibling of {@link withStepBusySpinnerTemplate}.
737
+ */
738
+ function withTabBusySpinnerTemplate(template) {
739
+ return defineTabsConfigFeature((cfg) => ({
740
+ ...cfg,
741
+ templates: { ...cfg.templates, busySpinner: template },
742
+ }));
743
+ }
744
+ function resolveFeatures(features) {
745
+ return features.reduce((cfg, feat) => feat(cfg), TABS_CONFIG_DEFAULTS);
746
+ }
747
+ /**
748
+ * Root-level provider. Apply once in `bootstrapApplication` /
749
+ * `appConfig.providers`. Returns {@link EnvironmentProviders} per
750
+ * the canonical cngx config-cascade signature.
751
+ */
752
+ function provideTabsConfig(...features) {
753
+ return makeEnvironmentProviders([
754
+ { provide: CNGX_TABS_CONFIG, useValue: resolveFeatures(features) },
755
+ ]);
756
+ }
757
+ /**
758
+ * Component-scoped override. Returns `Provider[]` (not
759
+ * {@link EnvironmentProviders}) because `viewProviders` rejects
760
+ * opaque environment providers. Resolution priority: per-instance
761
+ * Input > viewProviders (`At`) > root > default.
762
+ *
763
+ * ```ts
764
+ * @Component({
765
+ * viewProviders: [...provideTabsConfigAt(withTabsDefaultOrientation('vertical'))],
766
+ * })
767
+ * ```
768
+ */
769
+ function provideTabsConfigAt(...features) {
770
+ return [{ provide: CNGX_TABS_CONFIG, useValue: resolveFeatures(features) }];
771
+ }
772
+ /**
773
+ * Inject the resolved tabs config in an injection context.
774
+ */
775
+ function injectTabsConfig() {
776
+ return inject(CNGX_TABS_CONFIG);
777
+ }
778
+
779
+ const TABS_I18N_DEFAULTS = {
780
+ tabsLabel: 'Tabs',
781
+ selectedTab: (label, position, count) => `Tab ${position} of ${count}: ${label}`,
782
+ tabHasErrors: (count) => `${count} error${count === 1 ? '' : 's'}`,
783
+ moreTabsLabel: (count) => `${count} more`,
784
+ previousTab: 'Previous tab',
785
+ nextTab: 'Next tab',
786
+ commitFailedRetry: 'Tab change refused — retry?',
787
+ commitInFlight: 'Switching tab…',
788
+ commitRolledBackTo: (originLabel) => `Could not save changes — reverted to "${originLabel}".`,
789
+ };
790
+ /**
791
+ * DI token for the tabs i18n bundle. `providedIn: 'root'` with
792
+ * English defaults.
793
+ */
794
+ const CNGX_TABS_I18N = new InjectionToken('CngxTabsI18n', { providedIn: 'root', factory: () => TABS_I18N_DEFAULTS });
795
+ /**
796
+ * Brands an i18n-mutator with the `_target` discriminator.
797
+ *
798
+ * @internal
799
+ */
800
+ function defineTabsI18nFeature(fn) {
801
+ return Object.assign(fn, { _target: 'i18n' });
802
+ }
803
+ /**
804
+ * Override i18n labels via a partial bundle — unset keys keep the
805
+ * English default. Same shape as `withTabsAriaLabels` /
806
+ * `withTabsFallbackLabels` so `provideCngxTabs` composes both
807
+ * surfaces uniformly.
808
+ */
809
+ function withTabsI18nLabels(overrides) {
810
+ return defineTabsI18nFeature((bundle) => ({ ...bundle, ...overrides }));
811
+ }
812
+ function resolveI18nFeatures(features) {
813
+ return features.reduce((bundle, feat) => feat(bundle), TABS_I18N_DEFAULTS);
814
+ }
815
+ /**
816
+ * Provider for the tabs i18n bundle. Compose `withTabsI18nLabels(...)`
817
+ * (and future i18n `with*` features); unset keys fall back to the
818
+ * English default.
819
+ *
820
+ * ```ts
821
+ * bootstrapApplication(AppComponent, {
822
+ * providers: [
823
+ * provideTabsI18n(
824
+ * withTabsI18nLabels({ tabsLabel: 'Reiter', previousTab: 'Vorheriger' }),
825
+ * ),
826
+ * ],
827
+ * });
828
+ * ```
829
+ */
830
+ function provideTabsI18n(...features) {
831
+ return {
832
+ provide: CNGX_TABS_I18N,
833
+ useValue: resolveI18nFeatures(features),
834
+ };
835
+ }
836
+ /**
837
+ * Inject the resolved tabs i18n bundle.
838
+ */
839
+ function injectTabsI18n() {
840
+ return inject(CNGX_TABS_I18N);
841
+ }
842
+
843
+ function partitionFeatures(features) {
844
+ const config = [];
845
+ const i18n = [];
846
+ for (const feat of features) {
847
+ if (feat._target === 'i18n') {
848
+ i18n.push(feat);
849
+ continue;
850
+ }
851
+ if (feat._target === 'config') {
852
+ config.push(feat);
853
+ continue;
854
+ }
855
+ // Unbranded feature — runtime escape from the `_target` type.
856
+ // Drop with dev-warn so an i18n-shaped override never lands
857
+ // silently in `CNGX_TABS_CONFIG`.
858
+ if (isDevMode()) {
859
+ console.warn('[provideCngxTabs] Dropped feature without a `_target` ' +
860
+ 'discriminator. Brand config-side mutators with ' +
861
+ '`defineTabsConfigFeature(...)` (or use a `with*` helper) ' +
862
+ 'and i18n-side mutators with `withTabsI18nLabels(...)`.');
863
+ }
864
+ }
865
+ return { config, i18n };
866
+ }
867
+ /**
868
+ * Unified aggregator for tabs configuration. Routes features by
869
+ * `_target` to {@link provideTabsConfig} and {@link provideTabsI18n}.
870
+ * Sibling to `provideCngxMenu` and `provideCngxSelect`; apply once in
871
+ * the app providers array. Returns {@link EnvironmentProviders}; for
872
+ * `viewProviders` use {@link provideCngxTabsAt} — opaque
873
+ * `EnvironmentProviders` cannot live there.
874
+ *
875
+ * ```ts
876
+ * bootstrapApplication(AppComponent, {
877
+ * providers: [
878
+ * provideCngxTabs(
879
+ * withTabsDefaultOrientation('vertical'),
880
+ * withTabsAriaLabels({ tabsRegion: 'Bereiche' }),
881
+ * withTabsI18nLabels({ tabsLabel: 'Bereiche', moreTabsLabel: (n) => `${n} mehr` }),
882
+ * withTabOverflowStabilizeMs(150),
883
+ * ),
884
+ * ],
885
+ * });
886
+ * ```
887
+ */
888
+ function provideCngxTabs(...features) {
889
+ const { config, i18n } = partitionFeatures(features);
890
+ return makeEnvironmentProviders([
891
+ provideTabsConfig(...config),
892
+ ...(i18n.length > 0 ? [provideTabsI18n(...i18n)] : []),
893
+ ]);
894
+ }
895
+ /**
896
+ * Component-scoped twin of {@link provideCngxTabs}. Returns
897
+ * `Provider[]` for `viewProviders`/`providers`; same dispatch
898
+ * semantics, different scope.
899
+ *
900
+ * ```ts
901
+ * @Component({
902
+ * viewProviders: [
903
+ * ...provideCngxTabsAt(
904
+ * withTabsDefaultOrientation('vertical'),
905
+ * withTabsI18nLabels({ tabsLabel: 'Bereiche' }),
906
+ * ),
907
+ * ],
908
+ * })
909
+ * ```
910
+ */
911
+ function provideCngxTabsAt(...features) {
912
+ const { config, i18n } = partitionFeatures(features);
913
+ return [
914
+ ...provideTabsConfigAt(...config),
915
+ ...(i18n.length > 0 ? [provideTabsI18n(...i18n)] : []),
916
+ ];
917
+ }
918
+
919
+ /**
920
+ * Default adapter for the cngx-native `<cngx-tab-group>` strip:
921
+ * walks `host.closest('.cngx-tabs__strip-wrapper')` for the IO root,
922
+ * then `[id="${handle.id}-header"]` for each button.
923
+ */
924
+ function createCngxTabOverflowDefaultDomAdapter() {
925
+ return {
926
+ resolveStripRoot(_panelHost, host) {
927
+ const wrapper = host.closest('.cngx-tabs__strip-wrapper');
928
+ return wrapper?.querySelector('.cngx-tabs__strip') ?? null;
929
+ },
930
+ resolveTabButton(handle, root, _idx) {
931
+ return root.querySelector(`[id="${handle.id}-header"]`);
932
+ },
933
+ };
934
+ }
935
+ /**
936
+ * DI token for the overflow molecule's DOM-resolution strategy.
937
+ * Override at directive `providers` or component `viewProviders` to
938
+ * swap in a Material, custom-skin, or test-double adapter without
939
+ * forking the molecule. Defaults to
940
+ * {@link createCngxTabOverflowDefaultDomAdapter}.
941
+ */
942
+ const CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY = new InjectionToken('CngxTabOverflowDomAdapterFactory', {
943
+ providedIn: 'root',
944
+ factory: () => createCngxTabOverflowDefaultDomAdapter,
945
+ });
946
+
947
+ /**
948
+ * Bounded retry loop for DOM-anchoring patterns — shared
949
+ * attempt-counter + give-up + cancellation contract. Used by
950
+ * `<cngx-tab-overflow>`'s rAF strip-attach loop and `[cngxMatTabs]`'s
951
+ * `afterNextRender` header-anchor loop. Consumer-supplied scheduler
952
+ * lets different timing primitives flow through one counter.
953
+ *
954
+ * ```ts
955
+ * const retry = createDomAnchorRetry({
956
+ * attempt: () => {
957
+ * const root = host.closest('.strip-wrapper');
958
+ * if (!root) return null;
959
+ * observer.observe(root);
960
+ * return true;
961
+ * },
962
+ * maxAttempts: 60,
963
+ * schedule: (cb) => {
964
+ * const h = requestAnimationFrame(cb);
965
+ * return () => cancelAnimationFrame(h);
966
+ * },
967
+ * onGiveUp: () => console.warn('strip wrapper not found'),
968
+ * });
969
+ * afterNextRender(() => retry.start());
970
+ * destroyRef.onDestroy(() => retry.cancel());
971
+ * ```
972
+ */
973
+ function createDomAnchorRetry(options) {
974
+ let attempts = 0;
975
+ let cancelLast = null;
976
+ let stopped = false;
977
+ const tick = () => {
978
+ if (stopped) {
979
+ cancelLast = null;
980
+ return;
981
+ }
982
+ cancelLast = null;
983
+ let result;
984
+ try {
985
+ result = options.attempt();
986
+ }
987
+ catch {
988
+ // Swallow + terminal stop — covers the test-runner teardown
989
+ // race where a global (e.g. IntersectionObserver) is reset
990
+ // between schedule and fire, before consumer DestroyRef can
991
+ // call cancel(). Production callback bugs still surface via
992
+ // their own console.error before they throw here.
993
+ stopped = true;
994
+ return;
995
+ }
996
+ if (result === true) {
997
+ stopped = true;
998
+ return;
999
+ }
1000
+ attempts++;
1001
+ if (attempts >= options.maxAttempts) {
1002
+ stopped = true;
1003
+ options.onGiveUp?.();
1004
+ return;
1005
+ }
1006
+ cancelLast = options.schedule(tick);
1007
+ };
1008
+ return {
1009
+ start: () => {
1010
+ stopped = false;
1011
+ attempts = 0;
1012
+ tick();
1013
+ },
1014
+ cancel: () => {
1015
+ stopped = true;
1016
+ cancelLast?.();
1017
+ cancelLast = null;
1018
+ },
1019
+ };
1020
+ }
1021
+ /**
1022
+ * DI token for the DOM-anchor retry policy. Default
1023
+ * {@link createDomAnchorRetry}. Two real consumers today —
1024
+ * `<cngx-tab-overflow>`'s rAF strip-attach loop and
1025
+ * `[cngxMatTabs]`'s `afterNextRender` header-anchor loop. Override
1026
+ * via `providers` / `viewProviders` for retry-with-backoff,
1027
+ * telemetry on give-up, etc. Symmetric to
1028
+ * `CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY`,
1029
+ * `CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY`, and
1030
+ * `CNGX_TABS_COMMIT_HANDLER_FACTORY`.
1031
+ */
1032
+ const CNGX_DOM_ANCHOR_RETRY_FACTORY = new InjectionToken('CngxDomAnchorRetryFactory', {
1033
+ providedIn: 'root',
1034
+ factory: () => createDomAnchorRetry,
1035
+ });
1036
+
1037
+ /**
1038
+ * Structural slot for the More-button label. 3-stage cascade:
1039
+ * per-instance directive >
1040
+ * `CNGX_TABS_CONFIG.templates.overflowTrigger` >
1041
+ * `i18n.moreTabsLabel(count)`.
1042
+ *
1043
+ * ```html
1044
+ * <cngx-tab-overflow>
1045
+ * <ng-template cngxTabOverflowTrigger let-count>
1046
+ * <my-icon name="dots" /> +{{ count }}
1047
+ * </ng-template>
1048
+ * </cngx-tab-overflow>
1049
+ * ```
1050
+ */
1051
+ class CngxTabOverflowTrigger {
1052
+ templateRef = inject(TemplateRef);
1053
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabOverflowTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1054
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabOverflowTrigger, isStandalone: true, selector: "ng-template[cngxTabOverflowTrigger]", exportAs: ["cngxTabOverflowTrigger"], ngImport: i0 });
1055
+ }
1056
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabOverflowTrigger, decorators: [{
1057
+ type: Directive,
1058
+ args: [{
1059
+ selector: 'ng-template[cngxTabOverflowTrigger]',
1060
+ exportAs: 'cngxTabOverflowTrigger',
1061
+ standalone: true,
1062
+ }]
1063
+ }] });
1064
+
1065
+ /**
1066
+ * Structural slot for the per-row body inside the More popover.
1067
+ * 3-stage cascade: per-instance directive >
1068
+ * `CNGX_TABS_CONFIG.templates.overflowItem` > built-in label text.
1069
+ *
1070
+ * ```html
1071
+ * <cngx-tab-overflow>
1072
+ * <ng-template cngxTabOverflowItem let-tab let-disabled="disabled">
1073
+ * <my-icon [name]="tab.id" />
1074
+ * <span class="row-label" [class.is-muted]="disabled">
1075
+ * {{ tab.label() }}
1076
+ * </span>
1077
+ * </ng-template>
1078
+ * </cngx-tab-overflow>
1079
+ * ```
1080
+ */
1081
+ class CngxTabOverflowItem {
1082
+ templateRef = inject(TemplateRef);
1083
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabOverflowItem, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1084
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabOverflowItem, isStandalone: true, selector: "ng-template[cngxTabOverflowItem]", exportAs: ["cngxTabOverflowItem"], ngImport: i0 });
1085
+ }
1086
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabOverflowItem, decorators: [{
1087
+ type: Directive,
1088
+ args: [{
1089
+ selector: 'ng-template[cngxTabOverflowItem]',
1090
+ exportAs: 'cngxTabOverflowItem',
1091
+ standalone: true,
1092
+ }]
1093
+ }] });
1094
+
1095
+ /**
1096
+ * Structural slot for the error-badge template. 3-stage cascade:
1097
+ * per-instance directive >
1098
+ * `CNGX_TABS_CONFIG.templates.errorBadge` >
1099
+ * `CNGX_TABS_GLYPHS.errorBadge`.
1100
+ *
1101
+ * ```html
1102
+ * <cngx-tab-group>
1103
+ * <ng-template cngxTabErrorBadge let-tab="tab">
1104
+ * <span class="my-badge-pill">
1105
+ * {{ tab.errorAggregator()?.count() }}
1106
+ * </span>
1107
+ * </ng-template>
1108
+ * </cngx-tab-group>
1109
+ * ```
1110
+ */
1111
+ class CngxTabErrorBadge {
1112
+ templateRef = inject(TemplateRef);
1113
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabErrorBadge, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1114
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabErrorBadge, isStandalone: true, selector: "ng-template[cngxTabErrorBadge]", exportAs: ["cngxTabErrorBadge"], ngImport: i0 });
1115
+ }
1116
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabErrorBadge, decorators: [{
1117
+ type: Directive,
1118
+ args: [{
1119
+ selector: 'ng-template[cngxTabErrorBadge]',
1120
+ exportAs: 'cngxTabErrorBadge',
1121
+ standalone: true,
1122
+ }]
1123
+ }] });
1124
+
1125
+ /**
1126
+ * Structural slot for the rejection-decoration template. 3-stage
1127
+ * cascade: per-instance directive >
1128
+ * `CNGX_TABS_CONFIG.templates.rejectionIcon` >
1129
+ * `CNGX_TABS_GLYPHS.rejectionIcon`.
1130
+ *
1131
+ * ```html
1132
+ * <cngx-tab-group>
1133
+ * <ng-template
1134
+ * cngxTabRejectionIcon
1135
+ * let-failedIndex="failedIndex"
1136
+ * let-originLabel="originLabel"
1137
+ * >
1138
+ * <my-icon name="rollback" />
1139
+ * @if (originLabel) {
1140
+ * <span class="cngx-sr-only">Rolled back to {{ originLabel }}</span>
1141
+ * }
1142
+ * </ng-template>
1143
+ * </cngx-tab-group>
1144
+ * ```
1145
+ */
1146
+ class CngxTabRejectionIcon {
1147
+ templateRef = inject(TemplateRef);
1148
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabRejectionIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1149
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabRejectionIcon, isStandalone: true, selector: "ng-template[cngxTabRejectionIcon]", exportAs: ["cngxTabRejectionIcon"], ngImport: i0 });
1150
+ }
1151
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabRejectionIcon, decorators: [{
1152
+ type: Directive,
1153
+ args: [{
1154
+ selector: 'ng-template[cngxTabRejectionIcon]',
1155
+ exportAs: 'cngxTabRejectionIcon',
1156
+ standalone: true,
1157
+ }]
1158
+ }] });
1159
+
1160
+ /**
1161
+ * Structural slot for the busy-spinner template. 3-stage cascade:
1162
+ * per-instance directive >
1163
+ * `CNGX_TABS_CONFIG.templates.busySpinner` > built-in pulse span.
1164
+ *
1165
+ * ```html
1166
+ * <cngx-tab-group>
1167
+ * <ng-template cngxTabBusySpinner>
1168
+ * <my-spinner size="sm" />
1169
+ * </ng-template>
1170
+ * </cngx-tab-group>
1171
+ * ```
1172
+ */
1173
+ class CngxTabBusySpinner {
1174
+ templateRef = inject(TemplateRef);
1175
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabBusySpinner, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1176
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabBusySpinner, isStandalone: true, selector: "ng-template[cngxTabBusySpinner]", exportAs: ["cngxTabBusySpinner"], ngImport: i0 });
1177
+ }
1178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabBusySpinner, decorators: [{
1179
+ type: Directive,
1180
+ args: [{
1181
+ selector: 'ng-template[cngxTabBusySpinner]',
1182
+ exportAs: 'cngxTabBusySpinner',
1183
+ standalone: true,
1184
+ }]
1185
+ }] });
1186
+
1187
+ /**
1188
+ * Wires the 3-stage template cascade for the three `<cngx-tab-group>`
1189
+ * skin slots:
1190
+ * per-instance directive >
1191
+ * `CNGX_TABS_CONFIG.templates.<key>` >
1192
+ * `null` (built-in default).
1193
+ *
1194
+ * Pure — no DI, no side effects. Safe in field-init. Sibling to
1195
+ * `createStepperTemplateBindings` and `createTabOverflowTemplateBindings`.
1196
+ *
1197
+ * Single-consumer today: `[cngxMatTabs]` does not consume this —
1198
+ * Material owns the rendered tab-button chrome via its own MDC
1199
+ * template, leaving no DOM seam. See `tabs-accepted-debt §9`.
1200
+ */
1201
+ function createTabGroupTemplateBindings(opts) {
1202
+ return {
1203
+ errorBadge: computed(() => opts.errorBadgeSlot()?.templateRef ??
1204
+ opts.config.templates?.errorBadge ??
1205
+ null),
1206
+ rejectionIcon: computed(() => opts.rejectionIconSlot()?.templateRef ??
1207
+ opts.config.templates?.rejectionIcon ??
1208
+ null),
1209
+ busySpinner: computed(() => opts.busySpinnerSlot()?.templateRef ??
1210
+ opts.config.templates?.busySpinner ??
1211
+ null),
1212
+ };
1213
+ }
1214
+
1215
+ // Single-consumer factory — staged under family-uniformity
1216
+ // (tabs-accepted-debt §9, alongside `createTabGroupTemplateBindings`
1217
+ // and `CngxMatTabAggregatorContent`). Re-Eval: second consumer OR
1218
+ // sibling debt closure.
1219
+ /**
1220
+ * Pure factory bundling the `<cngx-tab-group>` AT-announcement +
1221
+ * descriptor surfaces. Owns one internal `linkedSignal`
1222
+ * (prior-active-index, drives the success-arm direction prefix) —
1223
+ * lazy by `linkedSignal` semantics, so the organism reads
1224
+ * `liveAnnouncement` once at construction to seed it.
1225
+ */
1226
+ function createTabGroupAnnouncements(options) {
1227
+ const { presenter, i18n, config, ariaLabel, ariaLabelledBy } = options;
1228
+ const tabsRoleDescription = computed(() => config.fallbackLabels?.tabRoleDescription ?? 'tab list', ...(ngDevMode ? [{ debugName: "tabsRoleDescription" }] : /* istanbul ignore next */ []));
1229
+ const tabPanelRoleDescription = computed(() => config.fallbackLabels?.tabPanelRoleDescription ?? 'tab panel', ...(ngDevMode ? [{ debugName: "tabPanelRoleDescription" }] : /* istanbul ignore next */ []));
1230
+ const resolvedAriaLabel = computed(() => {
1231
+ if (ariaLabelledBy()) {
1232
+ return null;
1233
+ }
1234
+ return ariaLabel() ?? config.ariaLabels?.tabsRegion ?? i18n.tabsLabel;
1235
+ }, ...(ngDevMode ? [{ debugName: "resolvedAriaLabel" }] : /* istanbul ignore next */ []));
1236
+ // `prev?.source` gives the source value before the most recent
1237
+ // change — prior activeIndex without an `effect`-driven slot
1238
+ // (Pillar 1). Coalesce to current on first emission.
1239
+ const priorActiveIndex = linkedSignal({ ...(ngDevMode ? { debugName: "priorActiveIndex" } : /* istanbul ignore next */ {}), source: () => presenter.activeIndex(),
1240
+ computation: (curr, prev) => prev?.source ?? curr,
1241
+ equal: Object.is });
1242
+ const liveAnnouncement = computed(() => {
1243
+ const current = presenter.commitTransition.current();
1244
+ if (current === 'pending') {
1245
+ return i18n.commitInFlight;
1246
+ }
1247
+ if (current === 'error') {
1248
+ // No `previous === 'pending'` guard — sync rejections collapse
1249
+ // pending → error in one flush, so the tracker captures
1250
+ // `previous = 'idle'` and an unguarded read keeps the
1251
+ // announcement reachable for `commitAction = () => false`.
1252
+ const failedIdx = presenter.lastFailedIndex();
1253
+ const originIdx = presenter.originIndexDuringCommit();
1254
+ if (failedIdx !== undefined && originIdx !== undefined) {
1255
+ const originLabel = presenter.tabs()[originIdx]?.label();
1256
+ if (originLabel) {
1257
+ return i18n.commitRolledBackTo(originLabel);
1258
+ }
1259
+ }
1260
+ return i18n.commitFailedRetry;
1261
+ }
1262
+ if (current === 'success') {
1263
+ const tabs = presenter.tabs();
1264
+ const idx = presenter.activeIndex();
1265
+ const tab = tabs[idx];
1266
+ if (!tab) {
1267
+ return '';
1268
+ }
1269
+ const label = tab.label() ?? '';
1270
+ const positionPhrase = i18n.selectedTab(label, idx + 1, tabs.length);
1271
+ const prevIdx = priorActiveIndex();
1272
+ if (idx > prevIdx) {
1273
+ return `${i18n.nextTab}: ${positionPhrase}`;
1274
+ }
1275
+ if (idx < prevIdx) {
1276
+ return `${i18n.previousTab}: ${positionPhrase}`;
1277
+ }
1278
+ return positionPhrase;
1279
+ }
1280
+ return '';
1281
+ }, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
1282
+ function statusPhrase(tab) {
1283
+ const aggregator = tab.errorAggregator();
1284
+ if (!aggregator?.shouldShow()) {
1285
+ return '';
1286
+ }
1287
+ const announcement = aggregator.announcement();
1288
+ if (announcement) {
1289
+ return announcement;
1290
+ }
1291
+ return i18n.tabHasErrors(aggregator.errorCount());
1292
+ }
1293
+ function tabAriaLabel(tab, position) {
1294
+ const tabs = presenter.tabs();
1295
+ return i18n.selectedTab(tab.label() ?? '', position, tabs.length);
1296
+ }
1297
+ // Eager seed — `linkedSignal` is lazy and the success arm doesn't
1298
+ // touch the tracker at construction (commitTransition is `idle`),
1299
+ // so without this read `prev?.source` is undefined on the first
1300
+ // nav and the direction prefix is silently lost.
1301
+ priorActiveIndex();
1302
+ return {
1303
+ tabsRoleDescription,
1304
+ tabPanelRoleDescription,
1305
+ resolvedAriaLabel,
1306
+ liveAnnouncement,
1307
+ statusPhrase,
1308
+ tabAriaLabel,
1309
+ };
1310
+ }
1311
+
1312
+ /**
1313
+ * Default glyph fallbacks for `<cngx-tab-group>` skin slots. Read by
1314
+ * the organism when neither a per-instance slot directive nor
1315
+ * `CNGX_TABS_CONFIG.templates.<key>` is bound. Sibling to
1316
+ * `CNGX_SELECT_GLYPHS` and `CNGX_STEPPER_GLYPHS`. Exported because
1317
+ * Sheriff forbids deep-relative imports across library boundaries;
1318
+ * `@internal` enforces consumer intent. Consumers customise via slot
1319
+ * directives or `withTab*Template` config features.
1320
+ *
1321
+ * @internal
1322
+ */
1323
+ const CNGX_TABS_GLYPHS = {
1324
+ /** Default visual for `*cngxTabErrorBadge` when no override is bound. */
1325
+ errorBadge: '!',
1326
+ /** Default visual for `*cngxTabRejectionIcon` when no override is bound. */
1327
+ rejectionIcon: '!',
1328
+ };
1329
+
1330
+ /**
1331
+ * DOM `id` for a hidden-tab option row in the overflow listbox.
1332
+ * Stable across CD passes so `aria-activedescendant` resolves to
1333
+ * the same `<li>`. `-overflow-option` suffix avoids collision with
1334
+ * the strip-button (`-header`) and per-tab descriptor (`-desc`).
1335
+ */
1336
+ function tabOverflowOptionId(tab) {
1337
+ return `${tab.id}-overflow-option`;
1338
+ }
1339
+ /**
1340
+ * Structural equal — same `count` + same `hiddenTabs` reference.
1341
+ * The upstream `hiddenTabs` signal already uses `tabIdListEqual`,
1342
+ * so this guard stops `ngTemplateOutlet` rebinding on shape-stable
1343
+ * IO emissions.
1344
+ */
1345
+ function triggerContextEqual(a, b) {
1346
+ return a.count === b.count && a.hiddenTabs === b.hiddenTabs;
1347
+ }
1348
+ /**
1349
+ * Structural equal — same length + per-index `id` and `disabled`.
1350
+ * Without this, every IO emission yields fresh
1351
+ * `ActiveDescendantItem[]` references and AD's `resolvedItems`
1352
+ * cascade fires for an unchanged visible-tab set.
1353
+ */
1354
+ function adItemsEqual(a, b) {
1355
+ if (a === b) {
1356
+ return true;
1357
+ }
1358
+ if (a.length !== b.length) {
1359
+ return false;
1360
+ }
1361
+ for (let i = 0; i < a.length; i++) {
1362
+ if (a[i].id !== b[i].id || a[i].disabled !== b[i].disabled) {
1363
+ return false;
1364
+ }
1365
+ }
1366
+ return true;
1367
+ }
1368
+ /**
1369
+ * Wires the 3-stage template cascade for the overflow molecule's
1370
+ * two visible regions: per-instance directive >
1371
+ * `CNGX_TABS_CONFIG.templates.overflow*` > built-in markup
1372
+ * (template-outlet returns `null`).
1373
+ *
1374
+ * Pure — no DI, no side effects, no destroy hooks. Safe to call
1375
+ * from a component's field-init block. Mirrors the select-family
1376
+ * `createTemplateRegistry` pattern.
1377
+ */
1378
+ function createTabOverflowTemplateBindings(opts) {
1379
+ const triggerTemplate = computed(() => opts.triggerSlot()?.templateRef ??
1380
+ opts.config.templates?.overflowTrigger ??
1381
+ null, ...(ngDevMode ? [{ debugName: "triggerTemplate" }] : /* istanbul ignore next */ []));
1382
+ const itemTemplate = computed(() => opts.itemSlot()?.templateRef ??
1383
+ opts.config.templates?.overflowItem ??
1384
+ null, ...(ngDevMode ? [{ debugName: "itemTemplate" }] : /* istanbul ignore next */ []));
1385
+ const triggerContext = computed(() => {
1386
+ const count = opts.hiddenCount();
1387
+ const hiddenTabs = opts.hiddenTabs();
1388
+ return { $implicit: count, count, hiddenTabs };
1389
+ }, { ...(ngDevMode ? { debugName: "triggerContext" } : /* istanbul ignore next */ {}), equal: triggerContextEqual });
1390
+ const itemContextCache = new WeakMap();
1391
+ const buildItemContext = (tab, index) => {
1392
+ const disabled = tab.disabled();
1393
+ const cached = itemContextCache.get(tab);
1394
+ if (cached?.disabled === disabled && cached?.index === index) {
1395
+ return cached.context;
1396
+ }
1397
+ const context = {
1398
+ $implicit: tab,
1399
+ tab,
1400
+ pick: () => opts.pickTab(tab),
1401
+ disabled,
1402
+ index,
1403
+ };
1404
+ itemContextCache.set(tab, { context, disabled, index });
1405
+ return context;
1406
+ };
1407
+ const adItems = computed(() => opts.hiddenTabs().map((tab) => ({
1408
+ id: tabOverflowOptionId(tab),
1409
+ value: tab,
1410
+ label: tab.label() ?? tab.id,
1411
+ disabled: tab.disabled(),
1412
+ })), { ...(ngDevMode ? { debugName: "adItems" } : /* istanbul ignore next */ {}), equal: adItemsEqual });
1413
+ return {
1414
+ triggerTemplate,
1415
+ itemTemplate,
1416
+ triggerContext,
1417
+ buildItemContext,
1418
+ adItems,
1419
+ };
1420
+ }
1421
+ /**
1422
+ * Resets the AD highlight on popover close. Keyboard-open paths
1423
+ * (ArrowDown / End / typeahead on the closed trigger) set
1424
+ * `activeIndex` via AD's own keydown listener before opening —
1425
+ * unaffected. Mouse-open leaves `activeIndex === -1` so the popover
1426
+ * renders unhighlighted. Without this reset, the next open would
1427
+ * inherit a stale index from the prior keyboard session.
1428
+ *
1429
+ * Must run in injection context.
1430
+ */
1431
+ function createOverflowPopoverHighlightSync(popover, ad) {
1432
+ effect(() => {
1433
+ const visible = popover().isVisible();
1434
+ untracked(() => {
1435
+ if (!visible) {
1436
+ ad().resetHighlight();
1437
+ }
1438
+ });
1439
+ });
1440
+ }
1441
+ /**
1442
+ * DI token for the overflow popover highlight-sync policy.
1443
+ * Default {@link createOverflowPopoverHighlightSync}. Override via
1444
+ * `providers` / `viewProviders` for last-index preservation,
1445
+ * telemetry on close, custom highlight rules. Symmetric to
1446
+ * `CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY` and
1447
+ * `CNGX_TABS_COMMIT_HANDLER_FACTORY`.
1448
+ */
1449
+ const CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY = new InjectionToken('CngxOverflowPopoverHighlightSyncFactory', {
1450
+ providedIn: 'root',
1451
+ factory: () => createOverflowPopoverHighlightSync,
1452
+ });
1453
+
1454
+ const DEFAULT_SCROLL_OPTIONS = {
1455
+ behavior: 'smooth',
1456
+ block: 'nearest',
1457
+ inline: 'center',
1458
+ };
1459
+ /**
1460
+ * Scroll-into-view effect for any strip-based organism (tabs,
1461
+ * stepper headers, future scrolling lists). Tracks `activeId` and
1462
+ * scrolls the matching `[id="<itemId>-header"]` into view.
1463
+ *
1464
+ * The DOM call sits in `untracked()` (only `activeId` is tracked).
1465
+ * `scrollIntoView` is missing in jsdom — guarded with optional chain.
1466
+ */
1467
+ function createOrganismScrollSync(opts) {
1468
+ const { activeId, hostElement, scrollOptions, injector } = opts;
1469
+ const resolvedOptions = scrollOptions ?? DEFAULT_SCROLL_OPTIONS;
1470
+ runInInjectionContext(injector, () => {
1471
+ effect(() => {
1472
+ const id = activeId();
1473
+ if (!id) {
1474
+ return;
1475
+ }
1476
+ untracked(() => {
1477
+ const button = hostElement.querySelector(`[id="${id}-header"]`);
1478
+ button?.scrollIntoView?.(resolvedOptions);
1479
+ });
1480
+ });
1481
+ });
1482
+ }
1483
+ /**
1484
+ * DI token for the active-item scroll-into-view policy. Defaults to
1485
+ * {@link createOrganismScrollSync}. Override for instant scroll,
1486
+ * custom selector, telemetry, or `prefers-reduced-motion` opt-out.
1487
+ * Sibling to `CNGX_DOM_ANCHOR_RETRY_FACTORY` and
1488
+ * `CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY`.
1489
+ */
1490
+ const CNGX_ORGANISM_SCROLL_SYNC_FACTORY = new InjectionToken('CngxOrganismScrollSyncFactory', {
1491
+ providedIn: 'root',
1492
+ factory: () => createOrganismScrollSync,
1493
+ });
1494
+
1495
+ /**
1496
+ * Structural equal for `Map<string, T>` (size + same value reference
1497
+ * per key, via `Object.is`).
1498
+ *
1499
+ * @internal
1500
+ */
1501
+ function directiveMapEqual(a, b) {
1502
+ if (a === b) {
1503
+ return true;
1504
+ }
1505
+ if (a.size !== b.size) {
1506
+ return false;
1507
+ }
1508
+ for (const [id, dir] of a) {
1509
+ if (b.get(id) !== dir) {
1510
+ return false;
1511
+ }
1512
+ }
1513
+ return true;
1514
+ }
1515
+ /**
1516
+ * Build a `Signal<Map<string, T>>` from a `Signal<readonly T[]>` of
1517
+ * directives keyed by `id()`. Structural equal prevents cascade when
1518
+ * `contentChildren` re-emits an unchanged child set. Shared by
1519
+ * `<cngx-tab-group>`, `<cngx-stepper>`, and `<cngx-mat-stepper>`.
1520
+ */
1521
+ function createDirectiveByIdMap(opts) {
1522
+ return computed(() => {
1523
+ const map = new Map();
1524
+ for (const dir of opts.source()) {
1525
+ map.set(dir.id(), dir);
1526
+ }
1527
+ return map;
1528
+ }, { equal: directiveMapEqual });
1529
+ }
1530
+ /**
1531
+ * DI token for the per-id directive-resolution policy. Defaults to
1532
+ * {@link createDirectiveByIdMap}. Override for WeakMap resolution,
1533
+ * telemetry, or custom equality. Sibling to
1534
+ * `CNGX_DOM_ANCHOR_RETRY_FACTORY` and
1535
+ * `CNGX_ORGANISM_SCROLL_SYNC_FACTORY`.
1536
+ */
1537
+ const CNGX_DIRECTIVE_BY_ID_MAP_FACTORY = new InjectionToken('CngxDirectiveByIdMapFactory', {
1538
+ providedIn: 'root',
1539
+ factory: () => createDirectiveByIdMap,
1540
+ });
1541
+
1542
+ /**
1543
+ * @module @cngx/common/tabs
1544
+ */
1545
+
1546
+ /**
1547
+ * Generated bundle index. Do not edit.
1548
+ */
1549
+
1550
+ export { CNGX_DIRECTIVE_BY_ID_MAP_FACTORY, CNGX_DOM_ANCHOR_RETRY_FACTORY, CNGX_ORGANISM_SCROLL_SYNC_FACTORY, CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY, CNGX_TABS_COMMIT_HANDLER_FACTORY, CNGX_TABS_CONFIG, CNGX_TABS_GLYPHS, CNGX_TABS_I18N, CNGX_TAB_GROUP_HOST, CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY, CNGX_TAB_PANEL_HOST, CngxTab, CngxTabBusySpinner, CngxTabContent, CngxTabErrorBadge, CngxTabGroupPresenter, CngxTabLabel, CngxTabOverflowItem, CngxTabOverflowTrigger, CngxTabRejectionIcon, CngxTabsFragmentSync, createCngxTabOverflowDefaultDomAdapter, createDirectiveByIdMap, createDomAnchorRetry, createOrganismScrollSync, createOverflowPopoverHighlightSync, createTabGroupAnnouncements, createTabGroupTemplateBindings, createTabOverflowTemplateBindings, createTabsCommitHandler, injectTabsConfig, injectTabsI18n, provideCngxTabs, provideCngxTabsAt, provideTabsConfig, provideTabsConfigAt, provideTabsI18n, tabOverflowOptionId, withDefaultOrientation, withTabBusySpinnerTemplate, withTabErrorBadgeTemplate, withTabOverflowItemTemplate, withTabOverflowMaxDeferMs, withTabOverflowStabilizeMs, withTabOverflowTriggerTemplate, withTabRejectionIconTemplate, withTabsAriaLabels, withTabsCommitMode, withTabsDefaultOrientation, withTabsFallbackLabels, withTabsI18nLabels, withTabsRouterSync, withTabsRovingLoop };
1551
+ //# sourceMappingURL=cngx-common-tabs.mjs.map