@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,1335 @@
1
+ import * as i0 from '@angular/core';
2
+ import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed, DestroyRef, model, contentChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
4
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
+ import { fromEvent } from 'rxjs';
6
+ import * as i1 from '@cngx/common/a11y';
7
+ import { CngxFocusTrap } from '@cngx/common/a11y';
8
+
9
+ /**
10
+ * Manages backdrop overlay behavior: visibility, click-to-close, and
11
+ * `inert` toggling on sibling elements.
12
+ *
13
+ * When visible, all sibling elements of the host receive the `inert`
14
+ * attribute, preventing focus and interaction behind the backdrop.
15
+ * This is critical for a11y in modal/drawer overlays.
16
+ *
17
+ * The directive is purely behavioral -- the consumer provides all
18
+ * visual styling (background color, opacity, transitions) via CSS
19
+ * custom properties and the `.cngx-backdrop--visible` class.
20
+ *
21
+ * ### Drawer backdrop
22
+ * ```html
23
+ * <div cngxDrawer #drawer="cngxDrawer">
24
+ * <div [cngxBackdrop]="drawer.opened()" (backdropClick)="drawer.close()"
25
+ * class="my-backdrop"></div>
26
+ * <nav [cngxDrawerPanel]="drawer">…</nav>
27
+ * <main [cngxDrawerContent]="drawer">…</main>
28
+ * </div>
29
+ * ```
30
+ *
31
+ * ### CSS (consumer responsibility)
32
+ * ```css
33
+ * .my-backdrop {
34
+ * position: fixed;
35
+ * inset: 0;
36
+ * background: var(--cngx-backdrop-color, rgba(0, 0, 0, 0.5));
37
+ * opacity: 0;
38
+ * pointer-events: none;
39
+ * transition: opacity 0.25s ease;
40
+ * }
41
+ * .my-backdrop.cngx-backdrop--visible {
42
+ * opacity: 1;
43
+ * pointer-events: auto;
44
+ * }
45
+ * ```
46
+ */
47
+ class CngxBackdrop {
48
+ /** Whether the backdrop is visible and siblings are inert. */
49
+ visible = input(false, { ...(ngDevMode ? { debugName: "visible" } : /* istanbul ignore next */ {}), alias: 'cngxBackdrop' });
50
+ /** Whether clicking the backdrop emits `backdropClick`. */
51
+ closeOnClick = input(true, ...(ngDevMode ? [{ debugName: "closeOnClick" }] : /* istanbul ignore next */ []));
52
+ /** Emitted when the backdrop is clicked (and `closeOnClick` is true). */
53
+ backdropClick = output();
54
+ el = inject((ElementRef));
55
+ siblings = signal([], ...(ngDevMode ? [{ debugName: "siblings" }] : /* istanbul ignore next */ []));
56
+ constructor() {
57
+ afterNextRender(() => {
58
+ const el = this.el.nativeElement;
59
+ const parent = el.parentElement;
60
+ this.siblings.set(parent
61
+ ? Array.from(parent.children).filter((child) => child !== el && child instanceof HTMLElement)
62
+ : []);
63
+ });
64
+ effect(() => {
65
+ const visible = this.visible();
66
+ this.siblings().forEach((el) => visible ? el.setAttribute('inert', '') : el.removeAttribute('inert'));
67
+ });
68
+ }
69
+ /** @internal */
70
+ handleHostClick() {
71
+ if (this.visible() && this.closeOnClick()) {
72
+ this.backdropClick.emit();
73
+ }
74
+ }
75
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, deps: [], target: i0.ɵɵFactoryTarget.Directive });
76
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBackdrop, isStandalone: true, selector: "[cngxBackdrop]", inputs: { visible: { classPropertyName: "visible", publicName: "cngxBackdrop", isSignal: true, isRequired: false, transformFunction: null }, closeOnClick: { classPropertyName: "closeOnClick", publicName: "closeOnClick", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { backdropClick: "backdropClick" }, host: { listeners: { "click": "handleHostClick()" }, properties: { "class.cngx-backdrop--visible": "visible()", "attr.aria-hidden": "!visible()" } }, exportAs: ["cngxBackdrop"], ngImport: i0 });
77
+ }
78
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, decorators: [{
79
+ type: Directive,
80
+ args: [{
81
+ selector: '[cngxBackdrop]',
82
+ exportAs: 'cngxBackdrop',
83
+ standalone: true,
84
+ host: {
85
+ '[class.cngx-backdrop--visible]': 'visible()',
86
+ '[attr.aria-hidden]': '!visible()',
87
+ '(click)': 'handleHostClick()',
88
+ },
89
+ }]
90
+ }], ctorParameters: () => [], propDecorators: { visible: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxBackdrop", required: false }] }], closeOnClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClick", required: false }] }], backdropClick: [{ type: i0.Output, args: ["backdropClick"] }] } });
91
+
92
+ /**
93
+ * State owner for a drawer / sidebar system.
94
+ *
95
+ * Holds the open/close state and handles the Escape key. Supports both
96
+ * **controlled** (`[cngxDrawerOpened]="signal()"`) and **uncontrolled**
97
+ * (internal state via `open()` / `close()` / `toggle()`) modes.
98
+ *
99
+ * Child directives (`CngxDrawerPanel`, `CngxDrawerContent`) receive a
100
+ * reference to this directive via an explicit input — no ancestor injection.
101
+ *
102
+ * ### Uncontrolled
103
+ * ```html
104
+ * <div cngxDrawer #drawer="cngxDrawer">
105
+ * <button (click)="drawer.toggle()">Menu</button>
106
+ * <nav [cngxDrawerPanel]="drawer" position="left">…</nav>
107
+ * <main [cngxDrawerContent]="drawer">…</main>
108
+ * </div>
109
+ * ```
110
+ *
111
+ * ### Controlled
112
+ * ```html
113
+ * <div cngxDrawer [cngxDrawerOpened]="sidebarOpen()"
114
+ * (openedChange)="sidebarOpen.set($event)">
115
+ * …
116
+ * </div>
117
+ * ```
118
+ */
119
+ class CngxDrawer {
120
+ /** @internal Host element ref — used by `CngxDrawerPanel` for click-outside containment. */
121
+ elementRef = inject((ElementRef));
122
+ /** Controlled opened state. When bound, takes precedence over internal state. */
123
+ openedInput = input(undefined, { ...(ngDevMode ? { debugName: "openedInput" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerOpened' });
124
+ openedState = signal(false, ...(ngDevMode ? [{ debugName: "openedState" }] : /* istanbul ignore next */ []));
125
+ /** Resolved opened state — controlled input wins over internal state. */
126
+ opened = computed(() => this.openedInput() ?? this.openedState(), ...(ngDevMode ? [{ debugName: "opened" }] : /* istanbul ignore next */ []));
127
+ /** Emitted when the opened state changes. Wire to a signal for two-way binding. */
128
+ openedChange = output();
129
+ /** Emitted when the drawer closes. Convenience shorthand for close-only listeners. */
130
+ closed = output();
131
+ /** Opens the drawer. */
132
+ open() {
133
+ this.openedState.set(true);
134
+ this.openedChange.emit(true);
135
+ }
136
+ /** Closes the drawer. */
137
+ close() {
138
+ if (!this.opened()) {
139
+ return;
140
+ }
141
+ this.openedState.set(false);
142
+ this.openedChange.emit(false);
143
+ this.closed.emit();
144
+ }
145
+ /** Toggles the drawer between open and closed. */
146
+ toggle() {
147
+ if (this.opened()) {
148
+ this.close();
149
+ }
150
+ else {
151
+ this.open();
152
+ }
153
+ }
154
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawer, deps: [], target: i0.ɵɵFactoryTarget.Directive });
155
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawer, isStandalone: true, selector: "[cngxDrawer]", inputs: { openedInput: { classPropertyName: "openedInput", publicName: "cngxDrawerOpened", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { openedChange: "openedChange", closed: "closed" }, host: { listeners: { "keydown.escape": "close()" }, properties: { "class.cngx-drawer--opened": "opened()" } }, exportAs: ["cngxDrawer"], ngImport: i0 });
156
+ }
157
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawer, decorators: [{
158
+ type: Directive,
159
+ args: [{
160
+ selector: '[cngxDrawer]',
161
+ exportAs: 'cngxDrawer',
162
+ standalone: true,
163
+ host: {
164
+ '[class.cngx-drawer--opened]': 'opened()',
165
+ '(keydown.escape)': 'close()',
166
+ },
167
+ }]
168
+ }], propDecorators: { openedInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerOpened", required: false }] }], openedChange: [{ type: i0.Output, args: ["openedChange"] }], closed: [{ type: i0.Output, args: ["closed"] }] } });
169
+
170
+ /**
171
+ * The sliding panel of a drawer. Reads its open state from an explicit
172
+ * `[cngxDrawerPanel]` reference — no ancestor injection.
173
+ *
174
+ * Composes `CngxFocusTrap` as a `hostDirective` — the consumer controls
175
+ * the `[enabled]` and `[autoFocus]` inputs from the template.
176
+ *
177
+ * Optionally closes the drawer when the user clicks outside the panel
178
+ * (`closeOnClickOutside`, default `true`).
179
+ *
180
+ * ```html
181
+ * <nav [cngxDrawerPanel]="drawer" position="left" mode="over"
182
+ * [enabled]="drawer.opened()" [autoFocus]="true">
183
+ * <a href="/home">Home</a>
184
+ * </nav>
185
+ * ```
186
+ */
187
+ class CngxDrawerPanel {
188
+ /** Reference to the parent `CngxDrawer` state owner. */
189
+ drawerRef = input.required({ ...(ngDevMode ? { debugName: "drawerRef" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerPanel' });
190
+ /** Direction the panel slides from. */
191
+ position = input('left', ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
192
+ /**
193
+ * How the panel interacts with the content area:
194
+ * - `'over'` (default) — overlays content (absolute positioned)
195
+ * - `'push'` — pushes content aside (content gets margin)
196
+ * - `'side'` — always visible, no toggle behavior
197
+ */
198
+ mode = input('over', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
199
+ /** Whether clicking outside the panel closes the drawer. */
200
+ closeOnClickOutside = input(true, ...(ngDevMode ? [{ debugName: "closeOnClickOutside" }] : /* istanbul ignore next */ []));
201
+ /** Whether the drawer is currently open (derived from the drawer ref). In `side` mode, always `true`. */
202
+ isOpen = computed(() => this.mode() === 'side' || this.drawerRef().opened(), ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
203
+ constructor() {
204
+ const doc = inject(DOCUMENT);
205
+ // Hit-test against the container, not the panel — toggle buttons and backdrops
206
+ // sit inside the container and must not count as outside clicks.
207
+ fromEvent(doc, 'click')
208
+ .pipe(takeUntilDestroyed())
209
+ .subscribe((e) => {
210
+ if (this.mode() !== 'side' &&
211
+ this.isOpen() &&
212
+ this.closeOnClickOutside() &&
213
+ !this.drawerRef().elementRef.nativeElement.contains(e.target)) {
214
+ this.drawerRef().close();
215
+ }
216
+ });
217
+ }
218
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
219
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerPanel", isSignal: true, isRequired: true, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, closeOnClickOutside: { classPropertyName: "closeOnClickOutside", publicName: "closeOnClickOutside", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "complementary" }, properties: { "class.cngx-drawer-panel": "true", "class.cngx-drawer-panel--open": "isOpen()", "class.cngx-drawer-panel--left": "position() === 'left'", "class.cngx-drawer-panel--right": "position() === 'right'", "class.cngx-drawer-panel--top": "position() === 'top'", "class.cngx-drawer-panel--bottom": "position() === 'bottom'", "class.cngx-drawer-panel--over": "mode() === 'over'", "class.cngx-drawer-panel--push": "mode() === 'push'", "class.cngx-drawer-panel--side": "mode() === 'side'", "attr.aria-hidden": "mode() === 'side' ? null : !isOpen()" } }, exportAs: ["cngxDrawerPanel"], hostDirectives: [{ directive: i1.CngxFocusTrap, inputs: ["enabled", "enabled", "autoFocus", "autoFocus"] }], ngImport: i0 });
220
+ }
221
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, decorators: [{
222
+ type: Directive,
223
+ args: [{
224
+ selector: '[cngxDrawerPanel]',
225
+ exportAs: 'cngxDrawerPanel',
226
+ standalone: true,
227
+ hostDirectives: [{ directive: CngxFocusTrap, inputs: ['enabled', 'autoFocus'] }],
228
+ host: {
229
+ '[class.cngx-drawer-panel]': 'true',
230
+ '[class.cngx-drawer-panel--open]': 'isOpen()',
231
+ '[class.cngx-drawer-panel--left]': "position() === 'left'",
232
+ '[class.cngx-drawer-panel--right]': "position() === 'right'",
233
+ '[class.cngx-drawer-panel--top]': "position() === 'top'",
234
+ '[class.cngx-drawer-panel--bottom]': "position() === 'bottom'",
235
+ '[class.cngx-drawer-panel--over]': "mode() === 'over'",
236
+ '[class.cngx-drawer-panel--push]': "mode() === 'push'",
237
+ '[class.cngx-drawer-panel--side]': "mode() === 'side'",
238
+ '[attr.aria-hidden]': "mode() === 'side' ? null : !isOpen()",
239
+ role: 'complementary',
240
+ },
241
+ }]
242
+ }], ctorParameters: () => [], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerPanel", required: true }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], closeOnClickOutside: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClickOutside", required: false }] }] } });
243
+
244
+ /**
245
+ * Marks the main content area adjacent to a drawer panel.
246
+ *
247
+ * Adds a CSS class when the drawer is open so the consumer can offset
248
+ * the content via CSS transitions or transforms.
249
+ *
250
+ * ```html
251
+ * <main [cngxDrawerContent]="drawer">
252
+ * Page content
253
+ * </main>
254
+ * ```
255
+ */
256
+ class CngxDrawerContent {
257
+ /** Reference to the parent `CngxDrawer` state owner. */
258
+ drawerRef = input.required({ ...(ngDevMode ? { debugName: "drawerRef" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerContent' });
259
+ /** Whether the drawer is currently open (derived from the drawer ref). */
260
+ isOpen = computed(() => this.drawerRef().opened(), ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
261
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
262
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerContent, isStandalone: true, selector: "[cngxDrawerContent]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerContent", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class.cngx-drawer-content": "true", "class.cngx-drawer-content--shifted": "isOpen()" } }, exportAs: ["cngxDrawerContent"], ngImport: i0 });
263
+ }
264
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerContent, decorators: [{
265
+ type: Directive,
266
+ args: [{
267
+ selector: '[cngxDrawerContent]',
268
+ exportAs: 'cngxDrawerContent',
269
+ standalone: true,
270
+ host: {
271
+ '[class.cngx-drawer-content]': 'true',
272
+ '[class.cngx-drawer-content--shifted]': 'isOpen()',
273
+ },
274
+ }]
275
+ }], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerContent", required: true }] }] } });
276
+
277
+ /**
278
+ * Observes whether the host element is visible in the viewport or a scroll container.
279
+ *
280
+ * Wraps the browser's `IntersectionObserver` API and exposes its state as
281
+ * Angular signals. The observer is automatically recreated when `root`,
282
+ * `rootMargin`, or `threshold` inputs change, and disconnected on destroy.
283
+ *
284
+ * Use cases: lazy loading images, infinite scroll sentinels, scroll-triggered
285
+ * animations, "back to top" buttons, analytics viewport tracking.
286
+ *
287
+ * ### Lazy load sentinel
288
+ * ```html
289
+ * <div cngxIntersectionObserver #io="cngxIntersectionObserver"
290
+ * (entered)="loadNextPage()">
291
+ * @if (io.isIntersecting()) { Loading... }
292
+ * </div>
293
+ * ```
294
+ *
295
+ * ### Scroll-triggered animation
296
+ * ```html
297
+ * <section cngxIntersectionObserver #io="cngxIntersectionObserver"
298
+ * [threshold]="0.5"
299
+ * [class.visible]="io.isIntersecting()">
300
+ * Content fades in at 50% visibility
301
+ * </section>
302
+ * ```
303
+ *
304
+ * ### Custom scroll container
305
+ * ```html
306
+ * <div cngxIntersectionObserver [root]="'.scroll-container'" [rootMargin]="'100px'">
307
+ * Observed within a scrollable parent
308
+ * </div>
309
+ * ```
310
+ */
311
+ class CngxIntersectionObserver {
312
+ /** CSS selector for the scroll container root. `null` (default) uses the viewport. */
313
+ root = input(null, ...(ngDevMode ? [{ debugName: "root" }] : /* istanbul ignore next */ []));
314
+ /** Margin around the root, using CSS margin syntax (e.g. `'100px 0px'`). */
315
+ rootMargin = input('0px', ...(ngDevMode ? [{ debugName: "rootMargin" }] : /* istanbul ignore next */ []));
316
+ /** Visibility ratio(s) at which the callback fires. `0` = any pixel visible, `1` = fully visible. */
317
+ threshold = input(0, ...(ngDevMode ? [{ debugName: "threshold" }] : /* istanbul ignore next */ []));
318
+ entryState = signal(null, ...(ngDevMode ? [{ debugName: "entryState" }] : /* istanbul ignore next */ []));
319
+ /** `true` when any part of the element is visible within the root. */
320
+ isIntersecting = computed(() => this.entryState()?.isIntersecting ?? false, ...(ngDevMode ? [{ debugName: "isIntersecting" }] : /* istanbul ignore next */ []));
321
+ /** The fraction of the element currently visible (0–1). */
322
+ intersectionRatio = computed(() => this.entryState()?.intersectionRatio ?? 0, ...(ngDevMode ? [{ debugName: "intersectionRatio" }] : /* istanbul ignore next */ []));
323
+ /** Emitted on every intersection change with the raw `IntersectionObserverEntry`. */
324
+ intersectionChange = output();
325
+ /** Emitted once when the element enters the observed area. */
326
+ entered = output();
327
+ /** Emitted once when the element leaves the observed area. */
328
+ left = output();
329
+ el = inject((ElementRef));
330
+ doc = inject(DOCUMENT);
331
+ constructor() {
332
+ const win = this.doc.defaultView;
333
+ if (!win) {
334
+ return;
335
+ }
336
+ effect((onCleanup) => {
337
+ const root = this.root();
338
+ const rootMargin = this.rootMargin();
339
+ const threshold = this.threshold();
340
+ const resolvedRoot = root ? this.doc.querySelector(root) : null;
341
+ const observer = new IntersectionObserver((entries) => {
342
+ const entry = entries[0];
343
+ const wasIntersecting = this.entryState()?.isIntersecting ?? false;
344
+ this.entryState.set(entry);
345
+ this.intersectionChange.emit(entry);
346
+ if (entry.isIntersecting && !wasIntersecting) {
347
+ this.entered.emit();
348
+ }
349
+ if (!entry.isIntersecting && wasIntersecting) {
350
+ this.left.emit();
351
+ }
352
+ }, { root: resolvedRoot, rootMargin, threshold });
353
+ observer.observe(this.el.nativeElement);
354
+ onCleanup(() => observer.disconnect());
355
+ });
356
+ }
357
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxIntersectionObserver, deps: [], target: i0.ɵɵFactoryTarget.Directive });
358
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxIntersectionObserver, isStandalone: true, selector: "[cngxIntersectionObserver]", inputs: { root: { classPropertyName: "root", publicName: "root", isSignal: true, isRequired: false, transformFunction: null }, rootMargin: { classPropertyName: "rootMargin", publicName: "rootMargin", isSignal: true, isRequired: false, transformFunction: null }, threshold: { classPropertyName: "threshold", publicName: "threshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { intersectionChange: "intersectionChange", entered: "entered", left: "left" }, exportAs: ["cngxIntersectionObserver"], ngImport: i0 });
359
+ }
360
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxIntersectionObserver, decorators: [{
361
+ type: Directive,
362
+ args: [{
363
+ selector: '[cngxIntersectionObserver]',
364
+ exportAs: 'cngxIntersectionObserver',
365
+ standalone: true,
366
+ }]
367
+ }], ctorParameters: () => [], propDecorators: { root: [{ type: i0.Input, args: [{ isSignal: true, alias: "root", required: false }] }], rootMargin: [{ type: i0.Input, args: [{ isSignal: true, alias: "rootMargin", required: false }] }], threshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "threshold", required: false }] }], intersectionChange: [{ type: i0.Output, args: ["intersectionChange"] }], entered: [{ type: i0.Output, args: ["entered"] }], left: [{ type: i0.Output, args: ["left"] }] } });
368
+
369
+ /**
370
+ * Reactive media query directive that exposes a `matches` signal.
371
+ *
372
+ * Wraps `window.matchMedia()` with automatic cleanup. Usable for
373
+ * responsive layouts, drawer mode switching, conditional rendering,
374
+ * or any behavior that depends on viewport/preference queries.
375
+ *
376
+ * ### Responsive drawer mode
377
+ * ```html
378
+ * <div cngxMediaQuery="(min-width: 1024px)" #mq="cngxMediaQuery">
379
+ * <nav [cngxDrawerPanel]="drawer"
380
+ * [mode]="mq.matches() ? 'side' : 'over'">
381
+ * …
382
+ * </nav>
383
+ * </div>
384
+ * ```
385
+ *
386
+ * ### Conditional content
387
+ * ```html
388
+ * <div cngxMediaQuery="(prefers-color-scheme: dark)" #dark="cngxMediaQuery">
389
+ * @if (dark.matches()) { <span>Dark mode active</span> }
390
+ * </div>
391
+ * ```
392
+ */
393
+ class CngxMediaQuery {
394
+ /** The CSS media query string to evaluate. */
395
+ query = input.required({ ...(ngDevMode ? { debugName: "query" } : /* istanbul ignore next */ {}), alias: 'cngxMediaQuery' });
396
+ matchesState = signal(false, ...(ngDevMode ? [{ debugName: "matchesState" }] : /* istanbul ignore next */ []));
397
+ win = inject(DOCUMENT).defaultView;
398
+ /** Whether the media query currently matches. */
399
+ matches = this.matchesState.asReadonly();
400
+ constructor() {
401
+ effect((onCleanup) => {
402
+ const win = this.win;
403
+ if (!win) {
404
+ this.matchesState.set(false);
405
+ return;
406
+ }
407
+ const mql = win.matchMedia(this.query());
408
+ this.matchesState.set(mql.matches);
409
+ const handler = (e) => this.matchesState.set(e.matches);
410
+ mql.addEventListener('change', handler);
411
+ onCleanup(() => mql.removeEventListener('change', handler));
412
+ });
413
+ }
414
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMediaQuery, deps: [], target: i0.ɵɵFactoryTarget.Directive });
415
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxMediaQuery, isStandalone: true, selector: "[cngxMediaQuery]", inputs: { query: { classPropertyName: "query", publicName: "cngxMediaQuery", isSignal: true, isRequired: true, transformFunction: null } }, exportAs: ["cngxMediaQuery"], ngImport: i0 });
416
+ }
417
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMediaQuery, decorators: [{
418
+ type: Directive,
419
+ args: [{
420
+ selector: '[cngxMediaQuery]',
421
+ exportAs: 'cngxMediaQuery',
422
+ standalone: true,
423
+ }]
424
+ }], ctorParameters: () => [], propDecorators: { query: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxMediaQuery", required: true }] }] } });
425
+
426
+ /**
427
+ * Observes size changes of the host element via the `ResizeObserver` API.
428
+ *
429
+ * Exposes `width()`, `height()`, `contentRect()`, and `isReady()` as Angular
430
+ * signals that update on every resize. The observer is automatically
431
+ * disconnected on destroy and recreated when the `box` input changes.
432
+ *
433
+ * Use cases: responsive component logic in TypeScript (not just CSS),
434
+ * container queries without CSS support, dynamic canvas/chart sizing,
435
+ * resize-aware layouts.
436
+ *
437
+ * ### Display current size
438
+ * ```html
439
+ * <div cngxResizeObserver #ro="cngxResizeObserver" style="resize: horizontal; overflow: auto;">
440
+ * {{ ro.width() | number:'1.0-0' }} × {{ ro.height() | number:'1.0-0' }} px
441
+ * </div>
442
+ * ```
443
+ *
444
+ * ### Responsive logic in TypeScript
445
+ * ```typescript
446
+ * readonly ro = viewChild(CngxResizeObserver);
447
+ * readonly columns = computed(() => (this.ro()?.width() ?? 0) > 600 ? 3 : 1);
448
+ * ```
449
+ */
450
+ class CngxResizeObserver {
451
+ /** Which box model to observe. `'content-box'` (default), `'border-box'`, or `'device-pixel-content-box'`. */
452
+ box = input('content-box', ...(ngDevMode ? [{ debugName: "box" }] : /* istanbul ignore next */ []));
453
+ entryState = signal(null, ...(ngDevMode ? [{ debugName: "entryState" }] : /* istanbul ignore next */ []));
454
+ /** The full `DOMRectReadOnly` of the content box. `null` before first observation. */
455
+ contentRect = computed(() => this.entryState()?.contentRect ?? null, ...(ngDevMode ? [{ debugName: "contentRect" }] : /* istanbul ignore next */ []));
456
+ /** Current width in pixels. `0` before first observation. */
457
+ width = computed(() => this.entryState()?.contentRect.width ?? 0, ...(ngDevMode ? [{ debugName: "width" }] : /* istanbul ignore next */ []));
458
+ /** Current height in pixels. `0` before first observation. */
459
+ height = computed(() => this.entryState()?.contentRect.height ?? 0, ...(ngDevMode ? [{ debugName: "height" }] : /* istanbul ignore next */ []));
460
+ /** `true` after the first resize observation has been received. */
461
+ isReady = computed(() => this.entryState() !== null, ...(ngDevMode ? [{ debugName: "isReady" }] : /* istanbul ignore next */ []));
462
+ /** Emitted on every resize with the raw `ResizeObserverEntry`. */
463
+ resize = output();
464
+ el = inject((ElementRef));
465
+ constructor() {
466
+ const win = inject(DOCUMENT).defaultView;
467
+ if (!win) {
468
+ return;
469
+ }
470
+ const observer = new win.ResizeObserver((entries) => {
471
+ this.entryState.set(entries[0]);
472
+ this.resize.emit(entries[0]);
473
+ });
474
+ effect(() => {
475
+ observer.disconnect();
476
+ observer.observe(this.el.nativeElement, { box: this.box() });
477
+ });
478
+ inject(DestroyRef).onDestroy(() => observer.disconnect());
479
+ }
480
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizeObserver, deps: [], target: i0.ɵɵFactoryTarget.Directive });
481
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxResizeObserver, isStandalone: true, selector: "[cngxResizeObserver]", inputs: { box: { classPropertyName: "box", publicName: "box", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { resize: "resize" }, exportAs: ["cngxResizeObserver"], ngImport: i0 });
482
+ }
483
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizeObserver, decorators: [{
484
+ type: Directive,
485
+ args: [{
486
+ selector: '[cngxResizeObserver]',
487
+ exportAs: 'cngxResizeObserver',
488
+ standalone: true,
489
+ }]
490
+ }], ctorParameters: () => [], propDecorators: { box: [{ type: i0.Input, args: [{ isSignal: true, alias: "box", required: false }] }], resize: [{ type: i0.Output, args: ["resize"] }] } });
491
+
492
+ /** Shared ref-count for scroll lock instances on the same document. */
493
+ const lockCounts = new WeakMap();
494
+ function acquireScrollLock(html) {
495
+ const count = lockCounts.get(html) ?? 0;
496
+ if (count === 0) {
497
+ html.dataset['cngxPrevOverflow'] = html.style.overflow;
498
+ html.dataset['cngxPrevScrollbarGutter'] = html.style.scrollbarGutter;
499
+ html.style.overflow = 'hidden';
500
+ html.style.scrollbarGutter = 'stable';
501
+ }
502
+ lockCounts.set(html, count + 1);
503
+ }
504
+ function releaseScrollLock(html) {
505
+ const count = lockCounts.get(html) ?? 0;
506
+ if (count <= 1) {
507
+ html.style.overflow = html.dataset['cngxPrevOverflow'] ?? '';
508
+ html.style.scrollbarGutter = html.dataset['cngxPrevScrollbarGutter'] ?? '';
509
+ delete html.dataset['cngxPrevOverflow'];
510
+ delete html.dataset['cngxPrevScrollbarGutter'];
511
+ lockCounts.set(html, 0);
512
+ }
513
+ else {
514
+ lockCounts.set(html, count - 1);
515
+ }
516
+ }
517
+ /**
518
+ * Prevents scrolling on the document body when enabled.
519
+ *
520
+ * Sets `overflow: hidden` and `scrollbar-gutter: stable` on `<html>` to
521
+ * prevent layout shift when the scrollbar disappears. Restores original
522
+ * values when all lock instances are released.
523
+ *
524
+ * Multiple instances are ref-counted — the original styles are only
525
+ * restored when the last lock is released.
526
+ *
527
+ * ### With a drawer
528
+ * ```html
529
+ * <div cngxDrawer #drawer="cngxDrawer" [cngxScrollLock]="drawer.opened()">
530
+ * …
531
+ * </div>
532
+ * ```
533
+ *
534
+ * ### With a modal
535
+ * ```html
536
+ * <div [cngxScrollLock]="isModalOpen()">…</div>
537
+ * ```
538
+ */
539
+ class CngxScrollLock {
540
+ /** Whether scroll lock is active. */
541
+ enabled = input(false, { ...(ngDevMode ? { debugName: "enabled" } : /* istanbul ignore next */ {}), alias: 'cngxScrollLock' });
542
+ constructor() {
543
+ const html = inject(DOCUMENT).documentElement;
544
+ let locked = false;
545
+ effect(() => {
546
+ if (this.enabled() && !locked) {
547
+ acquireScrollLock(html);
548
+ locked = true;
549
+ }
550
+ else if (!this.enabled() && locked) {
551
+ releaseScrollLock(html);
552
+ locked = false;
553
+ }
554
+ });
555
+ inject(DestroyRef).onDestroy(() => {
556
+ if (locked) {
557
+ releaseScrollLock(html);
558
+ }
559
+ });
560
+ }
561
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, deps: [], target: i0.ɵɵFactoryTarget.Directive });
562
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxScrollLock, isStandalone: true, selector: "[cngxScrollLock]", inputs: { enabled: { classPropertyName: "enabled", publicName: "cngxScrollLock", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxScrollLock"], ngImport: i0 });
563
+ }
564
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, decorators: [{
565
+ type: Directive,
566
+ args: [{
567
+ selector: '[cngxScrollLock]',
568
+ exportAs: 'cngxScrollLock',
569
+ standalone: true,
570
+ }]
571
+ }], ctorParameters: () => [], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLock", required: false }] }] } });
572
+
573
+ /**
574
+ * Headless skeleton loading placeholder.
575
+ *
576
+ * Toggles between loading and content states via CSS classes and ARIA attributes.
577
+ * No template -- the consumer renders the skeleton UI.
578
+ *
579
+ * Exposes an `indices()` signal for `@for` rendering of repeated skeleton elements.
580
+ * Respects `prefers-reduced-motion` (disables shimmer animation class).
581
+ *
582
+ * ### Basic loading placeholder
583
+ * ```html
584
+ * <div [cngxSkeleton]="isLoading()" #sk="cngxSkeleton">
585
+ * @if (sk.loading()) {
586
+ * @for (i of sk.indices(); track i) {
587
+ * <div class="skeleton-line" aria-hidden="true"></div>
588
+ * }
589
+ * } @else {
590
+ * <p>{{ content() }}</p>
591
+ * }
592
+ * </div>
593
+ * ```
594
+ *
595
+ * ### Card list with repeat count
596
+ * ```html
597
+ * <div [cngxSkeleton]="loading()" [count]="3" #sk="cngxSkeleton">
598
+ * @if (sk.loading()) {
599
+ * @for (i of sk.indices(); track i) {
600
+ * <div class="skeleton-card" aria-hidden="true">
601
+ * <div class="skeleton-avatar"></div>
602
+ * <div class="skeleton-line"></div>
603
+ * </div>
604
+ * }
605
+ * } @else {
606
+ * @for (card of cards(); track card.id) {
607
+ * <app-card [data]="card" />
608
+ * }
609
+ * }
610
+ * </div>
611
+ * ```
612
+ */
613
+ class CngxSkeleton {
614
+ /** Controls the loading state. */
615
+ skeleton = input(false, { ...(ngDevMode ? { debugName: "skeleton" } : /* istanbul ignore next */ {}), alias: 'cngxSkeleton' });
616
+ /** Enables the `.cngx-skeleton--shimmer` class (respects `prefers-reduced-motion`). */
617
+ shimmer = input(true, ...(ngDevMode ? [{ debugName: "shimmer" }] : /* istanbul ignore next */ []));
618
+ /** Repeat count — exposed via the `indices()` signal for `@for` rendering. */
619
+ count = input(1, ...(ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []));
620
+ prefersReducedMotion;
621
+ constructor() {
622
+ const win = inject(DOCUMENT).defaultView;
623
+ const pref = signal(false, ...(ngDevMode ? [{ debugName: "pref" }] : /* istanbul ignore next */ []));
624
+ if (win?.matchMedia) {
625
+ const mq = win.matchMedia('(prefers-reduced-motion: reduce)');
626
+ pref.set(mq.matches);
627
+ const listener = (e) => pref.set(e.matches);
628
+ mq.addEventListener('change', listener);
629
+ inject(DestroyRef).onDestroy(() => mq.removeEventListener('change', listener));
630
+ }
631
+ this.prefersReducedMotion = pref.asReadonly();
632
+ }
633
+ /** Whether the skeleton is in loading state. Mirrors the `cngxSkeleton` input. */
634
+ loading = computed(() => this.skeleton(), ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
635
+ /** Array of indices for `@for` rendering of repeated skeleton elements. */
636
+ indices = computed(() => Array.from({ length: this.count() }, (_, i) => i), ...(ngDevMode ? [{ debugName: "indices" }] : /* istanbul ignore next */ []));
637
+ /** @internal — shimmer class condition. */
638
+ showShimmer = computed(() => this.loading() && this.shimmer() && !this.prefersReducedMotion(), ...(ngDevMode ? [{ debugName: "showShimmer" }] : /* istanbul ignore next */ []));
639
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSkeleton, deps: [], target: i0.ɵɵFactoryTarget.Directive });
640
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSkeleton, isStandalone: true, selector: "[cngxSkeleton]", inputs: { skeleton: { classPropertyName: "skeleton", publicName: "cngxSkeleton", isSignal: true, isRequired: false, transformFunction: null }, shimmer: { classPropertyName: "shimmer", publicName: "shimmer", isSignal: true, isRequired: false, transformFunction: null }, count: { classPropertyName: "count", publicName: "count", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-skeleton--loading": "loading()", "class.cngx-skeleton--shimmer": "showShimmer()", "attr.aria-busy": "loading() || null" }, classAttribute: "cngx-skeleton" }, exportAs: ["cngxSkeleton"], ngImport: i0 });
641
+ }
642
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSkeleton, decorators: [{
643
+ type: Directive,
644
+ args: [{
645
+ selector: '[cngxSkeleton]',
646
+ standalone: true,
647
+ exportAs: 'cngxSkeleton',
648
+ host: {
649
+ class: 'cngx-skeleton',
650
+ '[class.cngx-skeleton--loading]': 'loading()',
651
+ '[class.cngx-skeleton--shimmer]': 'showShimmer()',
652
+ '[attr.aria-busy]': 'loading() || null',
653
+ },
654
+ }]
655
+ }], ctorParameters: () => [], propDecorators: { skeleton: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSkeleton", required: false }] }], shimmer: [{ type: i0.Input, args: [{ isSignal: true, alias: "shimmer", required: false }] }], count: [{ type: i0.Input, args: [{ isSignal: true, alias: "count", required: false }] }] } });
656
+
657
+ /**
658
+ * Infinite scroll trigger using `IntersectionObserver`.
659
+ *
660
+ * Place on a sentinel element at the bottom of a list. Fires `loadMore`
661
+ * when the sentinel enters the viewport. Includes a debounce guard and
662
+ * a `loading` input to prevent re-triggers during fetch.
663
+ *
664
+ * The observer is automatically recreated when `root`, `rootMargin`, or
665
+ * `threshold` inputs change, and disconnected on destroy or when `enabled`
666
+ * is set to `false`.
667
+ *
668
+ * ### Basic infinite list
669
+ * ```html
670
+ * <div class="item-list">
671
+ * @for (item of items(); track item.id) {
672
+ * <app-item [data]="item" />
673
+ * }
674
+ * <div cngxInfiniteScroll [loading]="isFetching()" (loadMore)="fetchNext()">
675
+ * @if (scroll.isLoading()) { <mat-spinner diameter="24" /> }
676
+ * </div>
677
+ * </div>
678
+ * ```
679
+ *
680
+ * ### Disable when all loaded
681
+ * ```html
682
+ * <div cngxInfiniteScroll
683
+ * [enabled]="hasNextPage()"
684
+ * [loading]="isFetching()"
685
+ * (loadMore)="fetchNext()">
686
+ * @if (!hasNextPage()) { <p>All items loaded</p> }
687
+ * </div>
688
+ * ```
689
+ *
690
+ * ### Custom scroll container with pre-fetch margin
691
+ * ```html
692
+ * <div cngxInfiniteScroll
693
+ * [root]="'.scroll-container'"
694
+ * [rootMargin]="'0px 0px 400px 0px'"
695
+ * [loading]="loading()"
696
+ * (loadMore)="loadMore()">
697
+ * </div>
698
+ * ```
699
+ */
700
+ class CngxInfiniteScroll {
701
+ /** IntersectionObserver threshold (0–1). */
702
+ threshold = input(0, ...(ngDevMode ? [{ debugName: "threshold" }] : /* istanbul ignore next */ []));
703
+ /** Pre-fetch margin. `'0px 0px 200px 0px'` triggers 200px before the sentinel is visible. */
704
+ rootMargin = input('0px 0px 200px 0px', ...(ngDevMode ? [{ debugName: "rootMargin" }] : /* istanbul ignore next */ []));
705
+ /** CSS selector for a custom scroll container root. `null` uses the viewport. */
706
+ root = input(null, ...(ngDevMode ? [{ debugName: "root" }] : /* istanbul ignore next */ []));
707
+ /** When `false`, the observer disconnects entirely. Use to stop loading when all items are fetched. */
708
+ enabled = input(true, ...(ngDevMode ? [{ debugName: "enabled" }] : /* istanbul ignore next */ []));
709
+ /** Set to `true` while fetching. Prevents re-trigger until the fetch completes. */
710
+ loading = input(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
711
+ /** Minimum ms between consecutive `loadMore` emissions. */
712
+ debounceMs = input(200, ...(ngDevMode ? [{ debugName: "debounceMs" }] : /* istanbul ignore next */ []));
713
+ /** Emitted when the sentinel is visible, not loading, and debounce has elapsed. */
714
+ loadMore = output();
715
+ /** Readonly mirror of the `loading` input. */
716
+ isLoading = computed(() => this.loading(), ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
717
+ el = inject((ElementRef));
718
+ doc = inject(DOCUMENT);
719
+ lastEmitTime = 0;
720
+ constructor() {
721
+ const win = this.doc.defaultView;
722
+ if (!win) {
723
+ return;
724
+ }
725
+ effect((onCleanup) => {
726
+ const enabled = this.enabled();
727
+ const root = this.root();
728
+ const rootMargin = this.rootMargin();
729
+ const threshold = this.threshold();
730
+ const debounceMs = this.debounceMs();
731
+ if (!enabled) {
732
+ return;
733
+ }
734
+ const isLoading = () => this.loading();
735
+ const resolvedRoot = root ? this.doc.querySelector(root) : null;
736
+ const observer = new IntersectionObserver((entries) => {
737
+ const entry = entries[0];
738
+ if (!entry.isIntersecting) {
739
+ return;
740
+ }
741
+ if (isLoading()) {
742
+ return;
743
+ }
744
+ const now = Date.now();
745
+ if (now - this.lastEmitTime < debounceMs) {
746
+ return;
747
+ }
748
+ this.lastEmitTime = now;
749
+ this.loadMore.emit();
750
+ }, { root: resolvedRoot, rootMargin, threshold });
751
+ observer.observe(this.el.nativeElement);
752
+ onCleanup(() => observer.disconnect());
753
+ });
754
+ }
755
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxInfiniteScroll, deps: [], target: i0.ɵɵFactoryTarget.Directive });
756
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxInfiniteScroll, isStandalone: true, selector: "[cngxInfiniteScroll]", inputs: { threshold: { classPropertyName: "threshold", publicName: "threshold", isSignal: true, isRequired: false, transformFunction: null }, rootMargin: { classPropertyName: "rootMargin", publicName: "rootMargin", isSignal: true, isRequired: false, transformFunction: null }, root: { classPropertyName: "root", publicName: "root", isSignal: true, isRequired: false, transformFunction: null }, enabled: { classPropertyName: "enabled", publicName: "enabled", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, debounceMs: { classPropertyName: "debounceMs", publicName: "debounceMs", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { loadMore: "loadMore" }, host: { properties: { "class.cngx-infinite-scroll--loading": "isLoading()", "attr.aria-busy": "isLoading() || null" }, classAttribute: "cngx-infinite-scroll" }, exportAs: ["cngxInfiniteScroll"], ngImport: i0 });
757
+ }
758
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxInfiniteScroll, decorators: [{
759
+ type: Directive,
760
+ args: [{
761
+ selector: '[cngxInfiniteScroll]',
762
+ standalone: true,
763
+ exportAs: 'cngxInfiniteScroll',
764
+ host: {
765
+ class: 'cngx-infinite-scroll',
766
+ '[class.cngx-infinite-scroll--loading]': 'isLoading()',
767
+ '[attr.aria-busy]': 'isLoading() || null',
768
+ },
769
+ }]
770
+ }], ctorParameters: () => [], propDecorators: { threshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "threshold", required: false }] }], rootMargin: [{ type: i0.Input, args: [{ isSignal: true, alias: "rootMargin", required: false }] }], root: [{ type: i0.Input, args: [{ isSignal: true, alias: "root", required: false }] }], enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "enabled", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], debounceMs: [{ type: i0.Input, args: [{ isSignal: true, alias: "debounceMs", required: false }] }], loadMore: [{ type: i0.Output, args: ["loadMore"] }] } });
771
+
772
+ /**
773
+ * Communicates when a sticky-positioned element becomes stuck.
774
+ *
775
+ * Applies `position: sticky; top: 0` on the host automatically.
776
+ * The directive adds a sentinel element before the host and uses
777
+ * `IntersectionObserver` to detect when the sentinel scrolls out,
778
+ * meaning the header is now stuck. Toggles a CSS class for shadow,
779
+ * elevation, or background changes.
780
+ *
781
+ * ### Sticky header with shadow
782
+ * ```html
783
+ * <header cngxStickyHeader #sh="cngxStickyHeader"
784
+ * style="position: sticky; top: 0;">
785
+ * Page header
786
+ * </header>
787
+ * ```
788
+ *
789
+ * ```css
790
+ * .cngx-sticky--active { box-shadow: 0 2px 4px rgba(0,0,0,.1); }
791
+ * ```
792
+ */
793
+ class CngxStickyHeader {
794
+ /** Intersection threshold — `0` triggers as soon as the sentinel leaves. */
795
+ threshold = input(0, ...(ngDevMode ? [{ debugName: "threshold" }] : /* istanbul ignore next */ []));
796
+ /** Emitted when the sticky state changes. */
797
+ stickyChange = output();
798
+ isStickyState = signal(false, ...(ngDevMode ? [{ debugName: "isStickyState" }] : /* istanbul ignore next */ []));
799
+ /** Whether the header is currently in its stuck position. */
800
+ isSticky = this.isStickyState.asReadonly();
801
+ el = inject((ElementRef));
802
+ doc = inject(DOCUMENT);
803
+ constructor() {
804
+ const destroyRef = inject(DestroyRef);
805
+ // IntersectionObserver sentinel pattern — host is stuck once the 1px sentinel leaves the viewport.
806
+ afterNextRender(() => {
807
+ const host = this.el.nativeElement;
808
+ const sentinel = this.doc.createElement('div');
809
+ sentinel.style.height = '1px';
810
+ sentinel.style.width = '1px';
811
+ sentinel.style.marginBottom = '-1px';
812
+ sentinel.style.visibility = 'hidden';
813
+ sentinel.style.pointerEvents = 'none';
814
+ sentinel.setAttribute('aria-hidden', 'true');
815
+ host.parentElement?.insertBefore(sentinel, host);
816
+ const observer = new IntersectionObserver((entries) => {
817
+ const isSticky = !entries[0].isIntersecting;
818
+ if (isSticky !== this.isStickyState()) {
819
+ this.isStickyState.set(isSticky);
820
+ this.stickyChange.emit(isSticky);
821
+ }
822
+ }, { threshold: this.threshold() });
823
+ observer.observe(sentinel);
824
+ destroyRef.onDestroy(() => {
825
+ observer.disconnect();
826
+ sentinel.remove();
827
+ });
828
+ });
829
+ }
830
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStickyHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
831
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStickyHeader, isStandalone: true, selector: "[cngxStickyHeader]", inputs: { threshold: { classPropertyName: "threshold", publicName: "threshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { stickyChange: "stickyChange" }, host: { properties: { "class.cngx-sticky--active": "isSticky()" }, styleAttribute: "position: sticky; top: 0; z-index: var(--cngx-sticky-z-index, 1)" }, exportAs: ["cngxStickyHeader"], ngImport: i0 });
832
+ }
833
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStickyHeader, decorators: [{
834
+ type: Directive,
835
+ args: [{
836
+ selector: '[cngxStickyHeader]',
837
+ exportAs: 'cngxStickyHeader',
838
+ standalone: true,
839
+ host: {
840
+ style: 'position: sticky; top: 0; z-index: var(--cngx-sticky-z-index, 1)',
841
+ '[class.cngx-sticky--active]': 'isSticky()',
842
+ },
843
+ }]
844
+ }], ctorParameters: () => [], propDecorators: { threshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "threshold", required: false }] }], stickyChange: [{ type: i0.Output, args: ["stickyChange"] }] } });
845
+
846
+ /**
847
+ * Tracks which section is currently most visible in the viewport.
848
+ *
849
+ * Observes a list of elements by their IDs using `IntersectionObserver`
850
+ * and reports the one with the highest intersection ratio as the active section.
851
+ * Ideal for scroll-based navigation highlighting and reading progress.
852
+ *
853
+ * ### Navigation highlighting
854
+ * ```html
855
+ * <nav [cngxScrollSpy]="['intro', 'features', 'pricing']"
856
+ * #spy="cngxScrollSpy">
857
+ * <a [class.active]="spy.activeId() === 'intro'" href="#intro">Intro</a>
858
+ * <a [class.active]="spy.activeId() === 'features'" href="#features">Features</a>
859
+ * <a [class.active]="spy.activeId() === 'pricing'" href="#pricing">Pricing</a>
860
+ * </nav>
861
+ *
862
+ * <section id="intro">…</section>
863
+ * <section id="features">…</section>
864
+ * <section id="pricing">…</section>
865
+ * ```
866
+ */
867
+ class CngxScrollSpy {
868
+ /** IDs of the sections to observe. */
869
+ sections = input.required({ ...(ngDevMode ? { debugName: "sections" } : /* istanbul ignore next */ {}), alias: 'cngxScrollSpy' });
870
+ /** Minimum visibility ratio to consider a section as a candidate. */
871
+ threshold = input(0.3, ...(ngDevMode ? [{ debugName: "threshold" }] : /* istanbul ignore next */ []));
872
+ /** CSS selector for the scroll container root. `null` uses the viewport. */
873
+ root = input(null, ...(ngDevMode ? [{ debugName: "root" }] : /* istanbul ignore next */ []));
874
+ /** Root margin for the observer. */
875
+ rootMargin = input('0px', ...(ngDevMode ? [{ debugName: "rootMargin" }] : /* istanbul ignore next */ []));
876
+ /** Emitted when the active section changes. */
877
+ activeIdChange = output();
878
+ activeIdState = signal(null, ...(ngDevMode ? [{ debugName: "activeIdState" }] : /* istanbul ignore next */ []));
879
+ /** ID of the section with the highest intersection ratio. */
880
+ activeId = this.activeIdState.asReadonly();
881
+ doc = inject(DOCUMENT);
882
+ /** Last observed intersection ratio keyed by section ID. */
883
+ ratios = new Map();
884
+ initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
885
+ activeCleanup;
886
+ constructor() {
887
+ afterNextRender(() => {
888
+ this.initialized.set(true);
889
+ });
890
+ // Recreate the observer whenever inputs change (deferred until DOM is ready).
891
+ effect((onCleanup) => {
892
+ this.sections();
893
+ this.threshold();
894
+ this.root();
895
+ this.rootMargin();
896
+ if (!this.initialized()) {
897
+ return;
898
+ }
899
+ this.activeCleanup?.();
900
+ this.activeCleanup = this.setupObserver();
901
+ onCleanup(() => {
902
+ this.activeCleanup?.();
903
+ this.activeCleanup = undefined;
904
+ });
905
+ });
906
+ }
907
+ /** Builds an `IntersectionObserver` for the current section IDs. Returns a disconnect callback. */
908
+ setupObserver() {
909
+ const ids = this.sections();
910
+ const thresholdValue = this.threshold();
911
+ const rootSelector = this.root();
912
+ const rootMarginValue = this.rootMargin();
913
+ this.ratios.clear();
914
+ const elements = ids
915
+ .map((id) => this.doc.getElementById(id))
916
+ .filter((el) => el !== null);
917
+ if (elements.length === 0) {
918
+ return;
919
+ }
920
+ const resolvedRoot = rootSelector ? this.doc.querySelector(rootSelector) : null;
921
+ const observer = new IntersectionObserver((entries) => {
922
+ entries.forEach((entry) => this.ratios.set(entry.target.id, entry.intersectionRatio));
923
+ const best = Array.from(this.ratios).reduce((acc, [id, ratio]) => ratio >= thresholdValue && ratio > acc.ratio ? { id, ratio } : acc, { id: null, ratio: 0 });
924
+ if (best.id !== this.activeIdState()) {
925
+ this.activeIdState.set(best.id);
926
+ this.activeIdChange.emit(best.id);
927
+ }
928
+ }, {
929
+ root: resolvedRoot,
930
+ rootMargin: rootMarginValue,
931
+ threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1],
932
+ });
933
+ elements.forEach((el) => observer.observe(el));
934
+ return () => observer.disconnect();
935
+ }
936
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollSpy, deps: [], target: i0.ɵɵFactoryTarget.Directive });
937
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxScrollSpy, isStandalone: true, selector: "[cngxScrollSpy]", inputs: { sections: { classPropertyName: "sections", publicName: "cngxScrollSpy", isSignal: true, isRequired: true, transformFunction: null }, threshold: { classPropertyName: "threshold", publicName: "threshold", isSignal: true, isRequired: false, transformFunction: null }, root: { classPropertyName: "root", publicName: "root", isSignal: true, isRequired: false, transformFunction: null }, rootMargin: { classPropertyName: "rootMargin", publicName: "rootMargin", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activeIdChange: "activeIdChange" }, exportAs: ["cngxScrollSpy"], ngImport: i0 });
938
+ }
939
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollSpy, decorators: [{
940
+ type: Directive,
941
+ args: [{
942
+ selector: '[cngxScrollSpy]',
943
+ exportAs: 'cngxScrollSpy',
944
+ standalone: true,
945
+ }]
946
+ }], ctorParameters: () => [], propDecorators: { sections: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollSpy", required: true }] }], threshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "threshold", required: false }] }], root: [{ type: i0.Input, args: [{ isSignal: true, alias: "root", required: false }] }], rootMargin: [{ type: i0.Input, args: [{ isSignal: true, alias: "rootMargin", required: false }] }], activeIdChange: [{ type: i0.Output, args: ["activeIdChange"] }] } });
947
+
948
+ /**
949
+ * Manages text truncation with expand/collapse state detection.
950
+ *
951
+ * Applies `-webkit-line-clamp` when collapsed and detects whether the text
952
+ * is actually clamped (content overflows). Exposes `isClamped` so the consumer
953
+ * can conditionally show a "Show more" toggle only when needed.
954
+ *
955
+ * The `expanded` state supports two-way binding (controlled + uncontrolled).
956
+ *
957
+ * ### Basic truncation with toggle
958
+ * ```html
959
+ * <p [cngxTruncate]="3" [(expanded)]="expanded" #trunc="cngxTruncate">
960
+ * Long text content that may or may not overflow…
961
+ * </p>
962
+ * @if (trunc.isClamped() || trunc.expanded()) {
963
+ * <button (click)="expanded.set(!expanded())"
964
+ * [attr.aria-expanded]="expanded()">
965
+ * {{ expanded() ? 'Show less' : 'Show more' }}
966
+ * </button>
967
+ * }
968
+ * ```
969
+ */
970
+ class CngxTruncate {
971
+ /** Maximum number of visible lines when collapsed. */
972
+ lines = input(3, { ...(ngDevMode ? { debugName: "lines" } : /* istanbul ignore next */ {}), alias: 'cngxTruncate' });
973
+ /** Whether the text is expanded (full content visible). Supports two-way binding. */
974
+ expanded = model(false, ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
975
+ isClampedState = signal(false, ...(ngDevMode ? [{ debugName: "isClampedState" }] : /* istanbul ignore next */ []));
976
+ /** Whether the text content actually exceeds the line limit and is being clamped. */
977
+ isClamped = this.isClampedState.asReadonly();
978
+ el = inject((ElementRef));
979
+ observer = null;
980
+ rafHandle = null;
981
+ // null strips the host binding — preferred over an empty string for -webkit-line-clamp.
982
+ /** @internal */
983
+ clampValue = () => (this.expanded() ? null : String(this.lines()));
984
+ /** @internal */
985
+ displayValue = () => (this.expanded() ? null : '-webkit-box');
986
+ /** @internal */
987
+ orientValue = () => (this.expanded() ? null : 'vertical');
988
+ /** @internal */
989
+ overflowValue = () => (this.expanded() ? null : 'hidden');
990
+ constructor() {
991
+ const destroyRef = inject(DestroyRef);
992
+ afterNextRender(() => {
993
+ this.checkClamped();
994
+ this.observer = new ResizeObserver(() => this.checkClamped());
995
+ this.observer.observe(this.el.nativeElement);
996
+ });
997
+ // Re-check after expanded/lines change; RAF ensures styles are applied first.
998
+ effect(() => {
999
+ this.expanded(); // track
1000
+ this.lines(); // track
1001
+ this.cancelRaf();
1002
+ this.rafHandle = requestAnimationFrame(() => this.checkClamped());
1003
+ });
1004
+ destroyRef.onDestroy(() => {
1005
+ this.observer?.disconnect();
1006
+ this.cancelRaf();
1007
+ });
1008
+ }
1009
+ cancelRaf() {
1010
+ if (this.rafHandle !== null) {
1011
+ cancelAnimationFrame(this.rafHandle);
1012
+ this.rafHandle = null;
1013
+ }
1014
+ }
1015
+ /**
1016
+ * Compares `scrollHeight` vs `clientHeight` to detect overflow.
1017
+ * Only meaningful when collapsed — when expanded, the last known
1018
+ * clamped state is preserved (can't measure hypothetical clamp height
1019
+ * while showing full content).
1020
+ */
1021
+ checkClamped() {
1022
+ const el = this.el.nativeElement;
1023
+ if (this.expanded()) {
1024
+ return;
1025
+ }
1026
+ this.isClampedState.set(el.scrollHeight > el.clientHeight);
1027
+ }
1028
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTruncate, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1029
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTruncate, isStandalone: true, selector: "[cngxTruncate]", inputs: { lines: { classPropertyName: "lines", publicName: "cngxTruncate", isSignal: true, isRequired: false, transformFunction: null }, expanded: { classPropertyName: "expanded", publicName: "expanded", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { expanded: "expandedChange" }, host: { properties: { "style.-webkit-line-clamp": "clampValue()", "style.display": "displayValue()", "style.-webkit-box-orient": "orientValue()", "style.overflow": "overflowValue()" } }, exportAs: ["cngxTruncate"], ngImport: i0 });
1030
+ }
1031
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTruncate, decorators: [{
1032
+ type: Directive,
1033
+ args: [{
1034
+ selector: '[cngxTruncate]',
1035
+ exportAs: 'cngxTruncate',
1036
+ standalone: true,
1037
+ host: {
1038
+ '[style.-webkit-line-clamp]': 'clampValue()',
1039
+ '[style.display]': 'displayValue()',
1040
+ '[style.-webkit-box-orient]': 'orientValue()',
1041
+ '[style.overflow]': 'overflowValue()',
1042
+ },
1043
+ }]
1044
+ }], ctorParameters: () => [], propDecorators: { lines: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxTruncate", required: false }] }], expanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "expanded", required: false }] }, { type: i0.Output, args: ["expandedChange"] }] } });
1045
+
1046
+ /**
1047
+ * Search-text highlighting via `<mark>` elements.
1048
+ *
1049
+ * Walks `TEXT_NODE` children of the host element, splits at match boundaries,
1050
+ * and wraps matched portions in `<mark>` elements. No `innerHTML` — safe by
1051
+ * construction. The `<mark>` element has correct native SR semantics (announced
1052
+ * as "highlighted" in most screen readers).
1053
+ *
1054
+ * Original DOM structure is restored when the term changes or the directive is destroyed.
1055
+ *
1056
+ * ### Search result highlighting
1057
+ * ```html
1058
+ * <p [cngxHighlight]="searchTerm()">
1059
+ * Angular Signals represent a fundamental shift in reactivity.
1060
+ * </p>
1061
+ * ```
1062
+ *
1063
+ * ### Case-sensitive matching
1064
+ * ```html
1065
+ * <p [cngxHighlight]="term()" [highlightCaseSensitive]="true">
1066
+ * CamelCase matters here.
1067
+ * </p>
1068
+ * ```
1069
+ */
1070
+ class CngxHighlight {
1071
+ /** The search term to highlight. Empty string clears all highlights. */
1072
+ term = input('', { ...(ngDevMode ? { debugName: "term" } : /* istanbul ignore next */ {}), alias: 'cngxHighlight' });
1073
+ /** Whether matching is case-sensitive. */
1074
+ caseSensitive = input(false, { ...(ngDevMode ? { debugName: "caseSensitive" } : /* istanbul ignore next */ {}), alias: 'highlightCaseSensitive' });
1075
+ matchCountState = signal(0, ...(ngDevMode ? [{ debugName: "matchCountState" }] : /* istanbul ignore next */ []));
1076
+ /** Number of matches found in the current highlight pass. */
1077
+ matchCount = this.matchCountState.asReadonly();
1078
+ el = inject((ElementRef));
1079
+ doc = inject(DOCUMENT);
1080
+ /** Snapshot of original child nodes — restored before each re-highlight. */
1081
+ originalNodes = null;
1082
+ initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
1083
+ constructor() {
1084
+ inject(DestroyRef).onDestroy(() => this.restore());
1085
+ afterNextRender(() => {
1086
+ this.initialized.set(true);
1087
+ });
1088
+ // matchCountState is written via untracked path — re-entering the effect would loop.
1089
+ effect(() => {
1090
+ const term = this.term();
1091
+ const caseSensitive = this.caseSensitive();
1092
+ if (this.initialized()) {
1093
+ this.applyHighlight(term, caseSensitive);
1094
+ }
1095
+ });
1096
+ }
1097
+ /**
1098
+ * Performs the highlight pass: restores original DOM, then wraps matches
1099
+ * in `<mark>` elements. Updates `matchCountState` with the result count.
1100
+ */
1101
+ applyHighlight(term, caseSensitive) {
1102
+ const host = this.el.nativeElement;
1103
+ if (this.originalNodes === null) {
1104
+ this.originalNodes = Array.from(host.childNodes).map((n) => n.cloneNode(true));
1105
+ }
1106
+ else {
1107
+ this.restoreNodes(host);
1108
+ }
1109
+ if (!term) {
1110
+ this.matchCountState.set(0);
1111
+ return;
1112
+ }
1113
+ let count = 0;
1114
+ const walker = this.doc.createTreeWalker(host, NodeFilter.SHOW_TEXT);
1115
+ const textNodes = [];
1116
+ // Collect nodes before modifying the DOM during the walk.
1117
+ let node;
1118
+ while ((node = walker.nextNode())) {
1119
+ textNodes.push(node);
1120
+ }
1121
+ for (const textNode of textNodes) {
1122
+ const text = textNode.textContent ?? '';
1123
+ const flags = caseSensitive ? 'g' : 'gi';
1124
+ const regex = new RegExp(this.escapeRegex(term), flags);
1125
+ const matches = [...text.matchAll(regex)];
1126
+ if (matches.length === 0) {
1127
+ continue;
1128
+ }
1129
+ count += matches.length;
1130
+ const fragment = this.doc.createDocumentFragment();
1131
+ let lastIndex = 0;
1132
+ for (const match of matches) {
1133
+ const matchStart = match.index;
1134
+ const matchEnd = matchStart + match[0].length;
1135
+ if (matchStart > lastIndex) {
1136
+ fragment.appendChild(this.doc.createTextNode(text.slice(lastIndex, matchStart)));
1137
+ }
1138
+ const mark = this.doc.createElement('mark');
1139
+ mark.textContent = text.slice(matchStart, matchEnd);
1140
+ fragment.appendChild(mark);
1141
+ lastIndex = matchEnd;
1142
+ }
1143
+ if (lastIndex < text.length) {
1144
+ fragment.appendChild(this.doc.createTextNode(text.slice(lastIndex)));
1145
+ }
1146
+ textNode.parentNode.replaceChild(fragment, textNode);
1147
+ }
1148
+ this.matchCountState.set(count);
1149
+ }
1150
+ /** Restores the original DOM structure. */
1151
+ restore() {
1152
+ if (this.originalNodes !== null) {
1153
+ this.restoreNodes(this.el.nativeElement);
1154
+ }
1155
+ }
1156
+ restoreNodes(host) {
1157
+ if (!this.originalNodes) {
1158
+ return;
1159
+ }
1160
+ while (host.firstChild) {
1161
+ host.removeChild(host.firstChild);
1162
+ }
1163
+ for (const node of this.originalNodes) {
1164
+ host.appendChild(node.cloneNode(true));
1165
+ }
1166
+ }
1167
+ /** Escapes special regex characters in the search term. */
1168
+ escapeRegex(str) {
1169
+ return str.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
1170
+ }
1171
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxHighlight, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1172
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxHighlight, isStandalone: true, selector: "[cngxHighlight]", inputs: { term: { classPropertyName: "term", publicName: "cngxHighlight", isSignal: true, isRequired: false, transformFunction: null }, caseSensitive: { classPropertyName: "caseSensitive", publicName: "highlightCaseSensitive", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxHighlight"], ngImport: i0 });
1173
+ }
1174
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxHighlight, decorators: [{
1175
+ type: Directive,
1176
+ args: [{
1177
+ selector: '[cngxHighlight]',
1178
+ exportAs: 'cngxHighlight',
1179
+ standalone: true,
1180
+ }]
1181
+ }], ctorParameters: () => [], propDecorators: { term: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxHighlight", required: false }] }], caseSensitive: [{ type: i0.Input, args: [{ isSignal: true, alias: "highlightCaseSensitive", required: false }] }] } });
1182
+
1183
+ /**
1184
+ * Marks a custom toggle template inside `cngx-expandable-text`.
1185
+ *
1186
+ * ```html
1187
+ * <cngx-expandable-text [lines]="3">
1188
+ * Long text…
1189
+ * <ng-template cngxExpandableToggle let-expanded let-toggle="toggle">
1190
+ * <button (click)="toggle()" class="icon-btn">
1191
+ * <mat-icon>{{ expanded ? 'expand_less' : 'expand_more' }}</mat-icon>
1192
+ * </button>
1193
+ * </ng-template>
1194
+ * </cngx-expandable-text>
1195
+ * ```
1196
+ */
1197
+ class CngxExpandableToggle {
1198
+ templateRef;
1199
+ constructor(templateRef) {
1200
+ this.templateRef = templateRef;
1201
+ }
1202
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableToggle, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
1203
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxExpandableToggle, isStandalone: true, selector: "ng-template[cngxExpandableToggle]", ngImport: i0 });
1204
+ }
1205
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableToggle, decorators: [{
1206
+ type: Directive,
1207
+ args: [{
1208
+ selector: 'ng-template[cngxExpandableToggle]',
1209
+ standalone: true,
1210
+ }]
1211
+ }], ctorParameters: () => [{ type: i0.TemplateRef }] });
1212
+ /**
1213
+ * Molecule wrapping `CngxTruncate` with a built-in expand/collapse toggle.
1214
+ *
1215
+ * Projects content into a truncated container and conditionally renders
1216
+ * a "Show more" / "Show less" button when the content is actually clamped.
1217
+ * Handles `aria-expanded` automatically.
1218
+ *
1219
+ * Supports custom toggle templates via `ng-template[cngxExpandableToggle]` —
1220
+ * use for icon buttons or any custom UI instead of plain text labels.
1221
+ *
1222
+ * ### Basic usage
1223
+ * ```html
1224
+ * <cngx-expandable-text [lines]="3">
1225
+ * Long text that may or may not overflow the container…
1226
+ * </cngx-expandable-text>
1227
+ * ```
1228
+ *
1229
+ * ### Custom labels
1230
+ * ```html
1231
+ * <cngx-expandable-text [lines]="2" moreLabel="Mehr" lessLabel="Weniger">
1232
+ * Langer Text…
1233
+ * </cngx-expandable-text>
1234
+ * ```
1235
+ *
1236
+ * ### Custom toggle template
1237
+ * ```html
1238
+ * <cngx-expandable-text [lines]="3">
1239
+ * Long text…
1240
+ * <ng-template cngxExpandableToggle let-expanded let-toggle="toggle">
1241
+ * <button (click)="toggle()">{{ expanded ? 'Collapse' : 'Expand' }}</button>
1242
+ * </ng-template>
1243
+ * </cngx-expandable-text>
1244
+ * ```
1245
+ */
1246
+ class CngxExpandableText {
1247
+ /** Maximum visible lines when collapsed. */
1248
+ lines = input(3, ...(ngDevMode ? [{ debugName: "lines" }] : /* istanbul ignore next */ []));
1249
+ /** Whether the text is expanded. Supports two-way `[(expanded)]` binding. */
1250
+ expanded = model(false, ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
1251
+ /** Label for the "show more" button. */
1252
+ moreLabel = input('Show more', ...(ngDevMode ? [{ debugName: "moreLabel" }] : /* istanbul ignore next */ []));
1253
+ /** Label for the "show less" button. */
1254
+ lessLabel = input('Show less', ...(ngDevMode ? [{ debugName: "lessLabel" }] : /* istanbul ignore next */ []));
1255
+ /** Optional custom toggle template projected by the consumer. */
1256
+ customToggle = contentChild(CngxExpandableToggle, ...(ngDevMode ? [{ debugName: "customToggle" }] : /* istanbul ignore next */ []));
1257
+ /** Template context for the custom toggle. */
1258
+ toggleContext() {
1259
+ return {
1260
+ $implicit: this.expanded(),
1261
+ expanded: this.expanded(),
1262
+ toggle: () => this.expanded.set(!this.expanded()),
1263
+ };
1264
+ }
1265
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableText, deps: [], target: i0.ɵɵFactoryTarget.Component });
1266
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxExpandableText, isStandalone: true, selector: "cngx-expandable-text", inputs: { lines: { classPropertyName: "lines", publicName: "lines", isSignal: true, isRequired: false, transformFunction: null }, expanded: { classPropertyName: "expanded", publicName: "expanded", isSignal: true, isRequired: false, transformFunction: null }, moreLabel: { classPropertyName: "moreLabel", publicName: "moreLabel", isSignal: true, isRequired: false, transformFunction: null }, lessLabel: { classPropertyName: "lessLabel", publicName: "lessLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { expanded: "expandedChange" }, host: { styleAttribute: "display:block" }, queries: [{ propertyName: "customToggle", first: true, predicate: CngxExpandableToggle, descendants: true, isSignal: true }], exportAs: ["cngxExpandableText"], ngImport: i0, template: `
1267
+ <div [cngxTruncate]="lines()" [(expanded)]="expanded" #trunc="cngxTruncate">
1268
+ <ng-content />
1269
+ </div>
1270
+ @if (trunc.isClamped() || expanded()) {
1271
+ @if (customToggle(); as tpl) {
1272
+ <ng-container
1273
+ [ngTemplateOutlet]="tpl.templateRef"
1274
+ [ngTemplateOutletContext]="toggleContext()"
1275
+ />
1276
+ } @else {
1277
+ <button
1278
+ type="button"
1279
+ class="cngx-expandable-text__toggle"
1280
+ [attr.aria-expanded]="expanded()"
1281
+ (click)="expanded.set(!expanded())"
1282
+ >
1283
+ {{ expanded() ? lessLabel() : moreLabel() }}
1284
+ </button>
1285
+ }
1286
+ }
1287
+ `, isInline: true, dependencies: [{ kind: "directive", type: CngxTruncate, selector: "[cngxTruncate]", inputs: ["cngxTruncate", "expanded"], outputs: ["expandedChange"], exportAs: ["cngxTruncate"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1288
+ }
1289
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableText, decorators: [{
1290
+ type: Component,
1291
+ args: [{
1292
+ selector: 'cngx-expandable-text',
1293
+ exportAs: 'cngxExpandableText',
1294
+ standalone: true,
1295
+ imports: [CngxTruncate, NgTemplateOutlet],
1296
+ changeDetection: ChangeDetectionStrategy.OnPush,
1297
+ encapsulation: ViewEncapsulation.None,
1298
+ host: {
1299
+ style: 'display:block',
1300
+ },
1301
+ template: `
1302
+ <div [cngxTruncate]="lines()" [(expanded)]="expanded" #trunc="cngxTruncate">
1303
+ <ng-content />
1304
+ </div>
1305
+ @if (trunc.isClamped() || expanded()) {
1306
+ @if (customToggle(); as tpl) {
1307
+ <ng-container
1308
+ [ngTemplateOutlet]="tpl.templateRef"
1309
+ [ngTemplateOutletContext]="toggleContext()"
1310
+ />
1311
+ } @else {
1312
+ <button
1313
+ type="button"
1314
+ class="cngx-expandable-text__toggle"
1315
+ [attr.aria-expanded]="expanded()"
1316
+ (click)="expanded.set(!expanded())"
1317
+ >
1318
+ {{ expanded() ? lessLabel() : moreLabel() }}
1319
+ </button>
1320
+ }
1321
+ }
1322
+ `,
1323
+ }]
1324
+ }], propDecorators: { lines: [{ type: i0.Input, args: [{ isSignal: true, alias: "lines", required: false }] }], expanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "expanded", required: false }] }, { type: i0.Output, args: ["expandedChange"] }], moreLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "moreLabel", required: false }] }], lessLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "lessLabel", required: false }] }], customToggle: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxExpandableToggle), { isSignal: true }] }] } });
1325
+
1326
+ /**
1327
+ * @module @cngx/common/layout
1328
+ */
1329
+
1330
+ /**
1331
+ * Generated bundle index. Do not edit.
1332
+ */
1333
+
1334
+ export { CngxBackdrop, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxResizeObserver, CngxScrollLock, CngxScrollSpy, CngxSkeleton, CngxStickyHeader, CngxTruncate };
1335
+ //# sourceMappingURL=cngx-common-layout.mjs.map