@cngx/common 0.1.0-rc.4 → 0.1.0-rc.6

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, DestroyRef, ChangeDetectionStrategy, Component, effect, untracked, InjectionToken, Injector, ViewContainerRef, LOCALE_ID, ViewEncapsulation, ElementRef, isDevMode, isSignal, runInInjectionContext } from '@angular/core';
2
+ import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, DestroyRef, ChangeDetectionStrategy, Component, effect, untracked, InjectionToken, Injector, Injectable, makeEnvironmentProviders, ViewContainerRef, LOCALE_ID, ViewEncapsulation, ElementRef, isDevMode, isSignal, runInInjectionContext } from '@angular/core';
3
3
  import { NgTemplateOutlet, DOCUMENT } from '@angular/common';
4
4
  import { CngxChip } from '@cngx/common/display';
5
5
  import { CngxMultiChipGroup, CngxChipInGroup, CngxSearch } from '@cngx/common/interactive';
@@ -8,7 +8,8 @@ import { Router, ActivatedRoute } from '@angular/router';
8
8
  import { DataSource } from '@angular/cdk/collections';
9
9
  import { arrayEqual } from '@cngx/utils';
10
10
  import { buildAsyncStateView, nextUid, createTransitionTracker } from '@cngx/core/utils';
11
- import { isObservable, firstValueFrom, defer, tap, filter, map } from 'rxjs';
11
+ import { isObservable, firstValueFrom, defer, tap, filter, map, finalize } from 'rxjs';
12
+ import { HttpContextToken, HttpContext, HttpEventType, provideHttpClient, withInterceptors } from '@angular/common/http';
12
13
 
13
14
  /**
14
15
  * Atom directive that tracks sort state (active field + direction).
@@ -1528,6 +1529,141 @@ function createAsyncState() {
1528
1529
  };
1529
1530
  }
1530
1531
 
1532
+ /** @internal Length-then-key-set equality for the operations Map signal. */
1533
+ function mapKeySetEqual(a, b) {
1534
+ if (a === b) {
1535
+ return true;
1536
+ }
1537
+ if (a.size !== b.size) {
1538
+ return false;
1539
+ }
1540
+ for (const key of a.keys()) {
1541
+ if (!b.has(key)) {
1542
+ return false;
1543
+ }
1544
+ }
1545
+ return true;
1546
+ }
1547
+ /** @internal Element-wise equality on (id, label, status) for the view array. */
1548
+ function operationsEqual(a, b) {
1549
+ if (a === b) {
1550
+ return true;
1551
+ }
1552
+ if (a.length !== b.length) {
1553
+ return false;
1554
+ }
1555
+ for (let i = 0; i < a.length; i++) {
1556
+ const x = a[i];
1557
+ const y = b[i];
1558
+ if (x.id !== y.id || x.label !== y.label || x.status !== y.status) {
1559
+ return false;
1560
+ }
1561
+ }
1562
+ return true;
1563
+ }
1564
+ /**
1565
+ * Opt-in aggregation registry for in-flight async operations.
1566
+ *
1567
+ * A single derived source for "is anything loading?" across a whole app: the
1568
+ * shell binds one `isAnythingLoading()` instead of N hand-maintained flags.
1569
+ * Producers register their `CngxAsyncState` (via `injectAsyncState({ register:
1570
+ * true })`, the HTTP interceptor, or directly) and unregister on teardown.
1571
+ *
1572
+ * Not `providedIn: 'root'` - consumers opt in with {@link provideAsyncRegistry}.
1573
+ * When the registry is absent, producers skip registration entirely.
1574
+ *
1575
+ * **Keyed by a per-operation uid, not the human label.** Async operations are
1576
+ * transient and collide on label; uid identity keeps N concurrent same-label
1577
+ * (or unlabeled) operations independent, so one `unregister` evicts exactly
1578
+ * its own entry. This is the one deliberate divergence from `CngxErrorRegistry`
1579
+ * (which keys by a stable scope name).
1580
+ *
1581
+ * Both views are `computed()` only - no `effect`, no service calls. Inner
1582
+ * status reactivity flows through each entry's `CngxAsyncState` signals; the
1583
+ * Map signal's `mapKeySetEqual` short-circuits register/unregister churn
1584
+ * without hiding status changes.
1585
+ *
1586
+ * @category common/data/async-registry
1587
+ */
1588
+ class CngxAsyncRegistry {
1589
+ entriesState = signal(new Map(), { ...(ngDevMode ? { debugName: "entriesState" } : /* istanbul ignore next */ {}), equal: mapKeySetEqual });
1590
+ /**
1591
+ * `true` when at least one registered operation reports `isLoading()`
1592
+ * (`loading`, `pending`, or `refreshing`).
1593
+ */
1594
+ isAnythingLoading = computed(() => {
1595
+ for (const entry of this.entriesState().values()) {
1596
+ if (entry.state.isLoading()) {
1597
+ return true;
1598
+ }
1599
+ }
1600
+ return false;
1601
+ }, ...(ngDevMode ? [{ debugName: "isAnythingLoading" }] : /* istanbul ignore next */ []));
1602
+ /** Every registered operation with its current status, in registration order. */
1603
+ activeOperations = computed(() => Array.from(this.entriesState(), ([id, entry]) => ({
1604
+ id,
1605
+ label: entry.label,
1606
+ status: entry.state.status(),
1607
+ })), { ...(ngDevMode ? { debugName: "activeOperations" } : /* istanbul ignore next */ {}), equal: operationsEqual });
1608
+ /**
1609
+ * Registers an async state under a fresh per-operation uid and returns it.
1610
+ * The optional `label` is display metadata only - never the map key, so
1611
+ * concurrent same-label (or unlabeled) operations stay independent.
1612
+ */
1613
+ register(state, label) {
1614
+ const id = nextUid('cngx-async-op');
1615
+ const next = new Map(this.entriesState());
1616
+ next.set(id, { label, state });
1617
+ this.entriesState.set(next);
1618
+ return id;
1619
+ }
1620
+ /** Removes the operation with the given uid. No-op if absent. */
1621
+ unregister(id) {
1622
+ const current = this.entriesState();
1623
+ if (!current.has(id)) {
1624
+ return;
1625
+ }
1626
+ const next = new Map(current);
1627
+ next.delete(id);
1628
+ this.entriesState.set(next);
1629
+ }
1630
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1631
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncRegistry });
1632
+ }
1633
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncRegistry, decorators: [{
1634
+ type: Injectable
1635
+ }] });
1636
+
1637
+ /**
1638
+ * Provides {@link CngxAsyncRegistry} in the host environment.
1639
+ *
1640
+ * Opt-in - not `providedIn: 'root'`. Add it to `bootstrapApplication`
1641
+ * providers to enable app-wide async observability; producers that opt in
1642
+ * (`injectAsyncState({ register: true })`, `provideAsyncHttpObservability()`)
1643
+ * then surface in `isAnythingLoading()` / `activeOperations()`.
1644
+ *
1645
+ * ```ts
1646
+ * bootstrapApplication(AppComponent, {
1647
+ * providers: [provideAsyncRegistry()],
1648
+ * });
1649
+ * ```
1650
+ *
1651
+ * @category common/data/async-registry
1652
+ */
1653
+ function provideAsyncRegistry() {
1654
+ return makeEnvironmentProviders([CngxAsyncRegistry]);
1655
+ }
1656
+ /**
1657
+ * Returns the ambient {@link CngxAsyncRegistry}, or `null` when the consumer
1658
+ * did not opt in via {@link provideAsyncRegistry}. Must run in an injection
1659
+ * context.
1660
+ *
1661
+ * @category common/data/async-registry
1662
+ */
1663
+ function injectAsyncRegistry() {
1664
+ return inject(CngxAsyncRegistry, { optional: true });
1665
+ }
1666
+
1531
1667
  /**
1532
1668
  * Create a reactive async state that auto-loads when signal dependencies change.
1533
1669
  *
@@ -1566,6 +1702,16 @@ function injectAsyncState(fn, options) {
1566
1702
  debounceTimer = undefined;
1567
1703
  }
1568
1704
  });
1705
+ // Opt-in observability: register with the ambient CngxAsyncRegistry (if any)
1706
+ // under a fresh per-operation uid, and unregister on destroy. No-op when the
1707
+ // caller did not opt in, or when no registry is provided.
1708
+ if (options?.register) {
1709
+ const registry = injectAsyncRegistry();
1710
+ if (registry) {
1711
+ const operationId = registry.register(state, options.label);
1712
+ destroyRef.onDestroy(() => registry.unregister(operationId));
1713
+ }
1714
+ }
1569
1715
  function executeQuery(computation) {
1570
1716
  cancelInFlight();
1571
1717
  // first load -> loading, subsequent -> refreshing
@@ -1999,6 +2145,119 @@ function tapHttpAsyncState(state, options) {
1999
2145
  });
2000
2146
  }
2001
2147
 
2148
+ /**
2149
+ * Per-request label surfaced in `CngxAsyncRegistry.activeOperations` when the
2150
+ * request is tracked by `cngxAsyncInterceptor`. Display only, never a key.
2151
+ *
2152
+ * @category common/data/async-registry
2153
+ */
2154
+ const CNGX_ASYNC_LABEL = new HttpContextToken(() => undefined);
2155
+ /**
2156
+ * Per-request opt-out. When `true`, `cngxAsyncInterceptor` passes the request
2157
+ * through without registering it - keeps polling / telemetry pings out of the
2158
+ * aggregate without a global allow-list.
2159
+ *
2160
+ * @category common/data/async-registry
2161
+ */
2162
+ const CNGX_ASYNC_SKIP = new HttpContextToken(() => false);
2163
+ /**
2164
+ * Returns an `HttpContext` that labels the request for async observability.
2165
+ * Pass an existing context to chain with other tokens.
2166
+ *
2167
+ * ```typescript
2168
+ * this.http.get('/api/users', { context: withAsyncLabel('users') });
2169
+ * ```
2170
+ *
2171
+ * @category common/data/async-registry
2172
+ */
2173
+ function withAsyncLabel(label, context = new HttpContext()) {
2174
+ return context.set(CNGX_ASYNC_LABEL, label);
2175
+ }
2176
+ /**
2177
+ * Returns an `HttpContext` that opts the request out of async observability.
2178
+ * Pass an existing context to chain with other tokens.
2179
+ *
2180
+ * ```typescript
2181
+ * this.http.get('/api/ping', { context: withAsyncSkip() });
2182
+ * ```
2183
+ *
2184
+ * @category common/data/async-registry
2185
+ */
2186
+ function withAsyncSkip(context = new HttpContext()) {
2187
+ return context.set(CNGX_ASYNC_SKIP, true);
2188
+ }
2189
+
2190
+ /**
2191
+ * Functional HTTP interceptor that surfaces every in-flight `HttpRequest` in
2192
+ * the ambient {@link CngxAsyncRegistry}, so `isAnythingLoading()` aggregates
2193
+ * raw HTTP traffic alongside explicit component states.
2194
+ *
2195
+ * Fully opt-in and self-contained:
2196
+ * - Resolves `inject(CngxAsyncRegistry, { optional: true })` and passes the
2197
+ * request straight through when no registry is provided - zero behaviour
2198
+ * change for consumers who do not opt in.
2199
+ * - Passes through without registering when `CNGX_ASYNC_SKIP` is set.
2200
+ * - Otherwise registers a fresh `createManualState` (set `loading`) under a
2201
+ * per-request uid, maps the final response / error onto it, and
2202
+ * `unregister`s in a `finalize` that fires on success **and** error (and on
2203
+ * unsubscribe), so a request can never pin the global loading state.
2204
+ *
2205
+ * Per-request uid identity (from `CngxAsyncRegistry`) means concurrent requests
2206
+ * sharing a label never evict one another - completing one leaves the other
2207
+ * tracked. The interceptor does not swallow errors: `setError` records the
2208
+ * failure, then the error propagates to the caller unchanged.
2209
+ *
2210
+ * @category common/data/async-registry
2211
+ */
2212
+ const cngxAsyncInterceptor = (req, next) => {
2213
+ const registry = inject(CngxAsyncRegistry, { optional: true });
2214
+ if (!registry || req.context.get(CNGX_ASYNC_SKIP)) {
2215
+ return next(req);
2216
+ }
2217
+ const state = createManualState();
2218
+ state.set('loading');
2219
+ const operationId = registry.register(state, req.context.get(CNGX_ASYNC_LABEL));
2220
+ return next(req).pipe(tap({
2221
+ next: (event) => {
2222
+ if (event.type === HttpEventType.Response) {
2223
+ state.setSuccess(event.body);
2224
+ }
2225
+ },
2226
+ error: (err) => state.setError(err),
2227
+ }), finalize(() => registry.unregister(operationId)));
2228
+ };
2229
+ /**
2230
+ * Sets up `HttpClient` with {@link cngxAsyncInterceptor} so every request
2231
+ * surfaces in {@link CngxAsyncRegistry}. Opt-in - add it to
2232
+ * `bootstrapApplication` providers alongside `provideAsyncRegistry()`.
2233
+ *
2234
+ * ```ts
2235
+ * bootstrapApplication(AppComponent, {
2236
+ * providers: [
2237
+ * provideAsyncRegistry(),
2238
+ * provideAsyncHttpObservability(),
2239
+ * ],
2240
+ * });
2241
+ * ```
2242
+ *
2243
+ * **Use this only when cngx owns the `HttpClient` setup.** It calls
2244
+ * `provideHttpClient(withInterceptors([cngxAsyncInterceptor]))` internally, so
2245
+ * an app that already calls `provideHttpClient` (especially with `withFetch()`
2246
+ * or other features) would get a second, feature-less `HttpClient`
2247
+ * configuration - last-provider-wins on `HttpBackend` can silently revert
2248
+ * `withFetch()` to the XHR backend. In that case do not call this; add the
2249
+ * exported {@link cngxAsyncInterceptor} to your own `withInterceptors` instead:
2250
+ *
2251
+ * ```ts
2252
+ * provideHttpClient(withFetch(), withInterceptors([authInterceptor, cngxAsyncInterceptor]))
2253
+ * ```
2254
+ *
2255
+ * @category common/data/async-registry
2256
+ */
2257
+ function provideAsyncHttpObservability() {
2258
+ return makeEnvironmentProviders([provideHttpClient(withInterceptors([cngxAsyncInterceptor]))]);
2259
+ }
2260
+
2002
2261
  /**
2003
2262
  * Structural directive for async state-driven content rendering.
2004
2263
  *
@@ -2716,7 +2975,7 @@ class CngxStatus {
2716
2975
  @if (label()) {
2717
2976
  <span class="cngx-status__label">{{ label() }}</span>
2718
2977
  }
2719
- `, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 1rem;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
2978
+ `, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 16px;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
2720
2979
  }
2721
2980
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, decorators: [{
2722
2981
  type: Component,
@@ -2733,7 +2992,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2733
2992
  @if (label()) {
2734
2993
  <span class="cngx-status__label">{{ label() }}</span>
2735
2994
  }
2736
- `, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 1rem;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"] }]
2995
+ `, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 16px;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"] }]
2737
2996
  }], ctorParameters: () => [], propDecorators: { tone: [{ type: i0.Input, args: [{ isSignal: true, alias: "tone", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], live: [{ type: i0.Input, args: [{ isSignal: true, alias: "live", required: false }] }] } });
2738
2997
 
2739
2998
  /**
@@ -2945,7 +3204,23 @@ function createScrollObserver(elementRef, destroyRef) {
2945
3204
  // when the element wasn't found on the first attempt (routed components,
2946
3205
  // content projection, lazy rendering).
2947
3206
  const retryTick = signal(0, ...(ngDevMode ? [{ debugName: "retryTick" }] : /* istanbul ignore next */ []));
3207
+ // Late-mount watcher for the string-selector path. A viewport gated behind
3208
+ // async data (or a skeleton->content swap) can mount many renders after the
3209
+ // one-shot afterNextRender retry fires, so a single retry misses it. This
3210
+ // observer bumps retryTick the instant the selector matches, then
3211
+ // disconnects. Created only in the unresolved-string case; stays null on
3212
+ // every faster path.
3213
+ let mutationObserver = null;
3214
+ function disconnectMutationObserver() {
3215
+ mutationObserver?.disconnect();
3216
+ mutationObserver = null;
3217
+ }
2948
3218
  function attachListeners(el, onCleanup) {
3219
+ // A viewport resolved: the late-mount watcher has done its job. Disconnect
3220
+ // it on attach so it can never outlive a resolved element — the node is
3221
+ // already in the DOM, so the observer would otherwise never fire again and
3222
+ // leak until destroy.
3223
+ disconnectMutationObserver();
2949
3224
  elementState.set(el);
2950
3225
  scrollTopState.set(el.scrollTop);
2951
3226
  clientHeightState.set(el.clientHeight);
@@ -2992,11 +3267,38 @@ function createScrollObserver(elementRef, destroyRef) {
2992
3267
  // untracked: afterNextRender may run in the same microtask as the effect.
2993
3268
  // Reading elementState() without untracked could create an unintended dependency
2994
3269
  // in whatever reactive context is active.
2995
- if (untracked(() => elementState()) == null) {
2996
- retryTick.update((v) => v + 1);
3270
+ if (untracked(() => elementState()) != null) {
3271
+ return;
3272
+ }
3273
+ // Element missing after the first render. Bump once for the common
3274
+ // next-render mount (routed component, content projection, lazy rendering).
3275
+ retryTick.update((v) => v + 1);
3276
+ // A string selector can still be unresolved because its viewport mounts
3277
+ // arbitrarily late — an async-gated list, a skeleton->content swap. Watch
3278
+ // the document and attach the instant it appears. Non-string refs
3279
+ // (HTMLElement / ElementRef) are not document-queryable, so the watcher
3280
+ // cannot help them; they stay on the single-retry path. Guard MutationObserver
3281
+ // for SSR.
3282
+ if (typeof elementRef !== 'string' || typeof MutationObserver === 'undefined') {
3283
+ return;
3284
+ }
3285
+ if (isDevMode()) {
3286
+ console.warn(`recycler scrollElement '${elementRef}' not found on first render; ` +
3287
+ 'it will attach automatically once it mounts. If it never does, check the selector.');
2997
3288
  }
3289
+ mutationObserver = new MutationObserver(() => {
3290
+ if (resolveElement(elementRef, doc) == null) {
3291
+ return;
3292
+ }
3293
+ // Found it. Disconnect before the retry bump so the resolving effect run
3294
+ // never observes a live-but-spent watcher, then let the effect attach.
3295
+ disconnectMutationObserver();
3296
+ retryTick.update((v) => v + 1);
3297
+ });
3298
+ mutationObserver.observe(doc.documentElement, { childList: true, subtree: true });
2998
3299
  });
2999
3300
  destroyRef.onDestroy(() => {
3301
+ disconnectMutationObserver();
3000
3302
  elementState.set(null);
3001
3303
  });
3002
3304
  return {
@@ -4003,5 +4305,5 @@ function createMaterialBidirectionalSync(opts) {
4003
4305
  * Generated bundle index. Do not edit.
4004
4306
  */
4005
4307
 
4006
- export { CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CNGX_STAT, CngxAsync, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxStatus, CngxTrend, CngxVirtualItem, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, createSortHeaderState, fromHttpResource, fromResource, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState };
4308
+ export { CNGX_ASYNC_LABEL, CNGX_ASYNC_SKIP, CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CNGX_STAT, CngxAsync, CngxAsyncRegistry, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxStatus, CngxTrend, CngxVirtualItem, cngxAsyncInterceptor, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createManualState, createMaterialBidirectionalSync, createSortHeaderState, fromHttpResource, fromResource, injectAsyncRegistry, injectAsyncState, injectDataSource, injectRecycler, injectSmartDataSource, provideAsyncHttpObservability, provideAsyncRegistry, provideRecyclerI18n, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState, withAsyncLabel, withAsyncSkip };
4007
4309
  //# sourceMappingURL=cngx-common-data.mjs.map