@molecule/app-carousel-angular 0.0.0-stage → 0.0.1-stage

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.
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Carousel component (React parity).
3
+ *
4
+ * @module
5
+ */
6
+ import { type AfterViewInit, type DoCheck, type OnDestroy } from '@angular/core';
7
+ import type { UIClassMap } from '@molecule/app-ui';
8
+ import * as i0 from "@angular/core";
9
+ /**
10
+ * Carousel component.
11
+ *
12
+ * Generic image / card carousel with arrows + dots + optional autoplay, fully
13
+ * controlled-optional. The host IS the root `<div>` (`div[mol-carousel]`),
14
+ * matching React's root exactly; the slides are the element's projected
15
+ * content, and each one is moved into its own `[data-mol-id="carousel-slide"]`
16
+ * wrapper — React's per-child wrapper — once the view exists. Same props (React
17
+ * names), same DOM, same `onChange(index)` calls as
18
+ * `@molecule/app-carousel-react`'s `Carousel`. Omit `index` for internal
19
+ * state; pass `index` + `onChange` to own it.
20
+ */
21
+ export declare class Carousel implements AfterViewInit, DoCheck, OnDestroy {
22
+ /** Controlled active index — caller owns state. */
23
+ index?: number;
24
+ /** Called when the active index changes. */
25
+ onChange?: (index: number) => void;
26
+ /** Show prev/next arrows (defaults to true at read time). */
27
+ showArrows?: boolean;
28
+ /** Show dot indicator strip (defaults to true at read time). */
29
+ showDots?: boolean;
30
+ /** Auto-advance interval in ms (set 0 to disable). */
31
+ autoplayMs?: number;
32
+ /** Pause autoplay on mouseover (defaults to true at read time). */
33
+ pauseOnHover?: boolean;
34
+ /** Loop back to start at end (defaults to true at read time). */
35
+ loop?: boolean;
36
+ /** Extra classes on the root element. */
37
+ className?: string;
38
+ /** The values the arrow Button receives as inputs. */
39
+ readonly arrowLeftStyle: Record<string, string>;
40
+ /** The values the arrow Button receives as inputs. */
41
+ readonly arrowRightStyle: Record<string, string>;
42
+ /** The dot button's inline style text. */
43
+ readonly dotStyle = "background: transparent; border: none; padding: 4px";
44
+ /** The flex track holding the slide wrappers. */
45
+ private track?;
46
+ /** The host element — React's root `<div>`. */
47
+ private readonly host;
48
+ /** i18n state; its `t` reads the provider on every call. */
49
+ private readonly i18n;
50
+ /** React's `useState(0)`: the uncontrolled active index. */
51
+ private readonly internal;
52
+ /** React's `useState(false)`: the pointer-over state autoplay pauses on. */
53
+ private readonly hovered;
54
+ /** How many slides the projected content holds — React's `children.length`. */
55
+ private readonly slideCount;
56
+ /** The slide wrappers, in render order. */
57
+ private readonly wrappers;
58
+ /** Where the host sat before a no-slides render detached it. */
59
+ private hostParent;
60
+ /** The autoplay interval, and the dependency key it was started for. */
61
+ private timer;
62
+ private timerKey;
63
+ /** The slide count whose publication is queued for after the current check. */
64
+ private pendingCount;
65
+ constructor();
66
+ /**
67
+ * Mirrors React's effect dependency list onto the autoplay interval: it
68
+ * restarts whenever the interval, the pause setting, the hover state, the
69
+ * slide count, the active index or the `setIdx` inputs change.
70
+ */
71
+ ngDoCheck(): void;
72
+ /** Clears the autoplay interval when the component is destroyed. */
73
+ ngOnDestroy(): void;
74
+ /**
75
+ * Keeps every slide wrapper's `aria-hidden` and width on the active index —
76
+ * React's per-child attributes, which the template cannot bind because the
77
+ * wrappers are React's, not the template's.
78
+ */
79
+ private syncWrappers;
80
+ /**
81
+ * Starts, restarts or clears the autoplay interval for the current inputs —
82
+ * React's autoplay effect, driven by {@link ngDoCheck} for plain inputs and by
83
+ * a signal effect for state.
84
+ */
85
+ private syncTimer;
86
+ /**
87
+ * The current class map.
88
+ * @returns The UIClassMap.
89
+ */
90
+ cm(): UIClassMap;
91
+ /**
92
+ * React's `const active = index ?? internal`.
93
+ * @returns The active slide index.
94
+ */
95
+ activeIndex(): number;
96
+ /**
97
+ * Computes the root class list (React's `cm.position('relative')` plus the
98
+ * extra `className`).
99
+ * @returns The class string.
100
+ */
101
+ classes(): string;
102
+ /**
103
+ * The arrows' extra class (React's `cm.position('absolute')`).
104
+ * @returns The class string.
105
+ */
106
+ absoluteClass(): string;
107
+ /**
108
+ * React's `showArrows = true` default, gated on more than one slide.
109
+ * @returns Whether the arrows render.
110
+ */
111
+ arrowsShown(): boolean;
112
+ /**
113
+ * React's `showDots = true` default, gated on more than one slide.
114
+ * @returns Whether the dot strip renders.
115
+ */
116
+ dotsShown(): boolean;
117
+ /**
118
+ * The translated previous-arrow label.
119
+ * @returns The accessible name.
120
+ */
121
+ previousLabel(): string;
122
+ /**
123
+ * The translated next-arrow label.
124
+ * @returns The accessible name.
125
+ */
126
+ nextLabel(): string;
127
+ /**
128
+ * The translated label of one dot.
129
+ * @param i - The dot's slide index.
130
+ * @returns The accessible name.
131
+ */
132
+ goToLabel(i: number): string;
133
+ /**
134
+ * The dot strip's class list (React's flex row + `cm.sp('py', 2)`).
135
+ * @returns The class string.
136
+ */
137
+ dotsClasses(): string;
138
+ /**
139
+ * One dot button's class list.
140
+ * @returns The class string.
141
+ */
142
+ dotClasses(): string;
143
+ /**
144
+ * The one dot glyph's inline style: React's 8px circle in the active or
145
+ * inactive theme token.
146
+ * @param i - The dot's slide index.
147
+ * @returns The declaration string.
148
+ */
149
+ dotFill(i: number): string;
150
+ /**
151
+ * The track's inline style — React's flex track, translated to the active
152
+ * slide.
153
+ * @returns The declaration string.
154
+ */
155
+ trackStyle(): string;
156
+ /**
157
+ * The dot indices, in order (React's `children.map((_, i) => …)`).
158
+ * @returns The indices `0 … slideCount - 1`.
159
+ */
160
+ dotIndexes(): number[];
161
+ /** Records the pointer entering the carousel. */
162
+ enter(): void;
163
+ /** Records the pointer leaving the carousel. */
164
+ leave(): void;
165
+ /** Moves one slide back. */
166
+ previous(): void;
167
+ /** Moves one slide forward. */
168
+ next(): void;
169
+ /**
170
+ * Jumps to one slide.
171
+ * @param i - The destination index.
172
+ */
173
+ goTo(i: number): void;
174
+ /**
175
+ * Moves to an index, clamping or wrapping exactly as React's `setIdx` does,
176
+ * then reports the clamped value through `onChange` (also when controlled).
177
+ * @param index - The requested index.
178
+ */
179
+ setIdx(index: number): void;
180
+ /**
181
+ * Wraps the projected slides once the view (and its track query) exists —
182
+ * the projected content is created with the view, and a zoneless app does not
183
+ * re-check a clean view.
184
+ */
185
+ ngAfterViewInit(): void;
186
+ /**
187
+ * Wraps every projected slide that is not wrapped yet, keeps the host element
188
+ * to React's rule (no element at all without slides) and publishes the count.
189
+ * Idempotent: the first check wraps, later checks only reconcile.
190
+ */
191
+ private wrapSlides;
192
+ /**
193
+ * Publishes the slide count after the current check when it changed: the
194
+ * projected content exists only after the view is created, and a write during
195
+ * this check would change a binding the check already read.
196
+ *
197
+ * @param total - The count read from the rendered wrappers.
198
+ */
199
+ private publishCount;
200
+ static ɵfac: i0.ɵɵFactoryDeclaration<Carousel, never>;
201
+ static ɵcmp: i0.ɵɵComponentDeclaration<Carousel, "div[mol-carousel]", never, { "index": { "alias": "index"; "required": false; }; "onChange": { "alias": "onChange"; "required": false; }; "showArrows": { "alias": "showArrows"; "required": false; }; "showDots": { "alias": "showDots"; "required": false; }; "autoplayMs": { "alias": "autoplayMs"; "required": false; }; "pauseOnHover": { "alias": "pauseOnHover"; "required": false; }; "loop": { "alias": "loop"; "required": false; }; "className": { "alias": "className"; "required": false; }; }, {}, never, ["*"], true, never>;
202
+ }
203
+ //# sourceMappingURL=carousel.component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carousel.component.d.ts","sourceRoot":"","sources":["../src/carousel.component.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,475 @@
1
+ /**
2
+ * Carousel component (React parity).
3
+ *
4
+ * @module
5
+ */
6
+ import { Component, effect, ElementRef, inject, signal, ViewChild, } from '@angular/core';
7
+ import { useTranslation } from '@molecule/app-angular';
8
+ import { getClassMap } from '@molecule/app-ui';
9
+ import { Button } from '@molecule/app-ui-angular';
10
+ import * as i0 from "@angular/core";
11
+ const _c0 = ["track"];
12
+ const _c1 = ["*"];
13
+ function Carousel_Conditional_4_Template(rf, ctx) { if (rf & 1) {
14
+ const _r1 = i0.ɵɵgetCurrentView();
15
+ i0.ɵɵelementStart(0, "button", 3);
16
+ i0.ɵɵlistener("click", function Carousel_Conditional_4_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.previous()); });
17
+ i0.ɵɵtext(1, "\u2039");
18
+ i0.ɵɵelementEnd();
19
+ i0.ɵɵelementStart(2, "button", 3);
20
+ i0.ɵɵlistener("click", function Carousel_Conditional_4_Template_button_click_2_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.next()); });
21
+ i0.ɵɵtext(3, "\u203A");
22
+ i0.ɵɵelementEnd();
23
+ } if (rf & 2) {
24
+ const ctx_r1 = i0.ɵɵnextContext();
25
+ i0.ɵɵstyleMap(ctx_r1.arrowLeftStyle);
26
+ i0.ɵɵproperty("variant", "ghost")("size", "sm")("className", ctx_r1.absoluteClass());
27
+ i0.ɵɵattribute("aria-label", ctx_r1.previousLabel());
28
+ i0.ɵɵadvance(2);
29
+ i0.ɵɵstyleMap(ctx_r1.arrowRightStyle);
30
+ i0.ɵɵproperty("variant", "ghost")("size", "sm")("className", ctx_r1.absoluteClass());
31
+ i0.ɵɵattribute("aria-label", ctx_r1.nextLabel());
32
+ } }
33
+ function Carousel_Conditional_5_For_2_Template(rf, ctx) { if (rf & 1) {
34
+ const _r3 = i0.ɵɵgetCurrentView();
35
+ i0.ɵɵelementStart(0, "button", 5);
36
+ i0.ɵɵlistener("click", function Carousel_Conditional_5_For_2_Template_button_click_0_listener() { const i_r4 = i0.ɵɵrestoreView(_r3).$implicit; const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.goTo(i_r4)); });
37
+ i0.ɵɵelement(1, "span", 6);
38
+ i0.ɵɵelementEnd();
39
+ } if (rf & 2) {
40
+ const i_r4 = ctx.$implicit;
41
+ const ctx_r1 = i0.ɵɵnextContext(2);
42
+ i0.ɵɵstyleMap(ctx_r1.dotStyle);
43
+ i0.ɵɵclassMap(ctx_r1.dotClasses());
44
+ i0.ɵɵattribute("data-active", i_r4 === ctx_r1.activeIndex() ? "true" : "false")("aria-label", ctx_r1.goToLabel(i_r4))("aria-current", i_r4 === ctx_r1.activeIndex() ? "true" : null);
45
+ i0.ɵɵadvance();
46
+ i0.ɵɵstyleMap(ctx_r1.dotFill(i_r4));
47
+ } }
48
+ function Carousel_Conditional_5_Template(rf, ctx) { if (rf & 1) {
49
+ i0.ɵɵelementStart(0, "div");
50
+ i0.ɵɵrepeaterCreate(1, Carousel_Conditional_5_For_2_Template, 2, 9, "button", 4, i0.ɵɵrepeaterTrackByIdentity);
51
+ i0.ɵɵelementEnd();
52
+ } if (rf & 2) {
53
+ const ctx_r1 = i0.ɵɵnextContext();
54
+ i0.ɵɵclassMap(ctx_r1.dotsClasses());
55
+ i0.ɵɵadvance();
56
+ i0.ɵɵrepeater(ctx_r1.dotIndexes());
57
+ } }
58
+ // Arrow offsets + vertical centering, exactly as React writes them: the
59
+ // ClassMap contract exposes no left/right/top or translate resolver (only
60
+ // `position` + `inset0`), so the edge offsets and the -50% Y translate that
61
+ // centers each arrow are inline — a sanctioned "ClassMap can't express it"
62
+ // case. Left arrow pins to the left edge, right arrow to the right edge; both
63
+ // sit at the vertical middle.
64
+ const ARROW_LEFT_STYLE = { left: '8px', top: '50%', transform: 'translateY(-50%)' };
65
+ const ARROW_RIGHT_STYLE = { right: '8px', top: '50%', transform: 'translateY(-50%)' };
66
+ // The dot button's hit target is a bare transparent square: the inline
67
+ // background/border/padding are native resets, not a competing design, and the
68
+ // 8px dot is drawn by the child span.
69
+ const DOT_STYLE = 'background: transparent; border: none; padding: 4px';
70
+ /**
71
+ * Reads the projected slide nodes out of the track: everything the component
72
+ * has not wrapped yet, in render order.
73
+ *
74
+ * @param track - The flex track element.
75
+ * @param wrappers - The slide wrappers already created, in render order.
76
+ * @returns The nodes still to wrap, in order.
77
+ */
78
+ const unwrapped = (track, wrappers) => Array.from(track.childNodes).filter((node) => !wrappers.includes(node) &&
79
+ // Angular anchors structural blocks with comment nodes; React renders
80
+ // none, and the conformance normalizer strips them.
81
+ node.nodeType !== Node.COMMENT_NODE &&
82
+ // The template's indentation can leave whitespace-only text nodes.
83
+ !(node.nodeType === Node.TEXT_NODE && (node.textContent ?? '').trim() === ''));
84
+ /**
85
+ * Carousel component.
86
+ *
87
+ * Generic image / card carousel with arrows + dots + optional autoplay, fully
88
+ * controlled-optional. The host IS the root `<div>` (`div[mol-carousel]`),
89
+ * matching React's root exactly; the slides are the element's projected
90
+ * content, and each one is moved into its own `[data-mol-id="carousel-slide"]`
91
+ * wrapper — React's per-child wrapper — once the view exists. Same props (React
92
+ * names), same DOM, same `onChange(index)` calls as
93
+ * `@molecule/app-carousel-react`'s `Carousel`. Omit `index` for internal
94
+ * state; pass `index` + `onChange` to own it.
95
+ */
96
+ export class Carousel {
97
+ /** Controlled active index — caller owns state. */
98
+ index;
99
+ /** Called when the active index changes. */
100
+ onChange;
101
+ /** Show prev/next arrows (defaults to true at read time). */
102
+ showArrows;
103
+ /** Show dot indicator strip (defaults to true at read time). */
104
+ showDots;
105
+ /** Auto-advance interval in ms (set 0 to disable). */
106
+ autoplayMs;
107
+ /** Pause autoplay on mouseover (defaults to true at read time). */
108
+ pauseOnHover;
109
+ /** Loop back to start at end (defaults to true at read time). */
110
+ loop;
111
+ /** Extra classes on the root element. */
112
+ className;
113
+ /** The values the arrow Button receives as inputs. */
114
+ arrowLeftStyle = ARROW_LEFT_STYLE;
115
+ /** The values the arrow Button receives as inputs. */
116
+ arrowRightStyle = ARROW_RIGHT_STYLE;
117
+ /** The dot button's inline style text. */
118
+ dotStyle = DOT_STYLE;
119
+ /** The flex track holding the slide wrappers. */
120
+ track;
121
+ /** The host element — React's root `<div>`. */
122
+ host = inject((ElementRef));
123
+ /** i18n state; its `t` reads the provider on every call. */
124
+ i18n = useTranslation();
125
+ /** React's `useState(0)`: the uncontrolled active index. */
126
+ internal = signal(0, /* @ts-ignore */
127
+ ...(ngDevMode ? [{ debugName: "internal" }] : /* istanbul ignore next */ []));
128
+ /** React's `useState(false)`: the pointer-over state autoplay pauses on. */
129
+ hovered = signal(false, /* @ts-ignore */
130
+ ...(ngDevMode ? [{ debugName: "hovered" }] : /* istanbul ignore next */ []));
131
+ /** How many slides the projected content holds — React's `children.length`. */
132
+ slideCount = signal(0, /* @ts-ignore */
133
+ ...(ngDevMode ? [{ debugName: "slideCount" }] : /* istanbul ignore next */ []));
134
+ /** The slide wrappers, in render order. */
135
+ wrappers = [];
136
+ /** Where the host sat before a no-slides render detached it. */
137
+ hostParent = null;
138
+ /** The autoplay interval, and the dependency key it was started for. */
139
+ timer = null;
140
+ timerKey = '';
141
+ /** The slide count whose publication is queued for after the current check. */
142
+ pendingCount = -1;
143
+ constructor() {
144
+ // Every wrapper's `aria-hidden` and width follow the active index, as
145
+ // React's render does — a signal effect, so a targeted (zoneless) update
146
+ // that re-evaluates the template bindings runs it too.
147
+ effect(() => {
148
+ this.syncWrappers();
149
+ });
150
+ // React's autoplay effect: an interval that advances by one and restarts on
151
+ // every change of the index, the interval, the hover state or the prop
152
+ // values `setIdx` closes over (React lists `setIdx` itself as a dependency).
153
+ // A prop is a plain input, so a change reaches `syncTimer` through the
154
+ // check that wrote it (see `ngDoCheck`); the signals this effect reads —
155
+ // the active index, the hover state and the slide count — re-run it here.
156
+ effect(() => {
157
+ this.activeIndex();
158
+ this.hovered();
159
+ this.slideCount();
160
+ this.syncTimer();
161
+ });
162
+ }
163
+ /**
164
+ * Mirrors React's effect dependency list onto the autoplay interval: it
165
+ * restarts whenever the interval, the pause setting, the hover state, the
166
+ * slide count, the active index or the `setIdx` inputs change.
167
+ */
168
+ ngDoCheck() {
169
+ this.wrapSlides();
170
+ this.syncWrappers();
171
+ this.syncTimer();
172
+ }
173
+ /** Clears the autoplay interval when the component is destroyed. */
174
+ ngOnDestroy() {
175
+ if (this.timer)
176
+ clearInterval(this.timer);
177
+ this.timer = null;
178
+ }
179
+ /**
180
+ * Keeps every slide wrapper's `aria-hidden` and width on the active index —
181
+ * React's per-child attributes, which the template cannot bind because the
182
+ * wrappers are React's, not the template's.
183
+ */
184
+ syncWrappers() {
185
+ const active = this.activeIndex();
186
+ const total = this.slideCount();
187
+ for (const [i, wrapper] of this.wrappers.entries()) {
188
+ wrapper.setAttribute('aria-hidden', i === active ? 'false' : 'true');
189
+ wrapper.style.width = total === 0 ? '0%' : `${100 / total}%`;
190
+ wrapper.style.flexShrink = '0';
191
+ }
192
+ }
193
+ /**
194
+ * Starts, restarts or clears the autoplay interval for the current inputs —
195
+ * React's autoplay effect, driven by {@link ngDoCheck} for plain inputs and by
196
+ * a signal effect for state.
197
+ */
198
+ syncTimer() {
199
+ const autoplayMs = this.autoplayMs ?? 0;
200
+ const pauseOnHover = this.pauseOnHover ?? true;
201
+ const total = this.slideCount();
202
+ const current = this.activeIndex();
203
+ const key = [
204
+ autoplayMs,
205
+ pauseOnHover,
206
+ this.hovered(),
207
+ total,
208
+ current,
209
+ this.index === undefined,
210
+ this.loop ?? true,
211
+ ].join('|');
212
+ if (key === this.timerKey)
213
+ return;
214
+ this.timerKey = key;
215
+ if (this.timer) {
216
+ clearInterval(this.timer);
217
+ this.timer = null;
218
+ }
219
+ if (!autoplayMs || total === 0 || (pauseOnHover && this.hovered()))
220
+ return;
221
+ this.timer = setInterval(() => this.setIdx(current + 1), autoplayMs);
222
+ }
223
+ /**
224
+ * The current class map.
225
+ * @returns The UIClassMap.
226
+ */
227
+ cm() {
228
+ return getClassMap();
229
+ }
230
+ /**
231
+ * React's `const active = index ?? internal`.
232
+ * @returns The active slide index.
233
+ */
234
+ activeIndex() {
235
+ return this.index ?? this.internal();
236
+ }
237
+ /**
238
+ * Computes the root class list (React's `cm.position('relative')` plus the
239
+ * extra `className`).
240
+ * @returns The class string.
241
+ */
242
+ classes() {
243
+ return this.cm().cn(this.cm().position('relative'), this.className);
244
+ }
245
+ /**
246
+ * The arrows' extra class (React's `cm.position('absolute')`).
247
+ * @returns The class string.
248
+ */
249
+ absoluteClass() {
250
+ return this.cm().position('absolute');
251
+ }
252
+ /**
253
+ * React's `showArrows = true` default, gated on more than one slide.
254
+ * @returns Whether the arrows render.
255
+ */
256
+ arrowsShown() {
257
+ return (this.showArrows ?? true) && this.slideCount() > 1;
258
+ }
259
+ /**
260
+ * React's `showDots = true` default, gated on more than one slide.
261
+ * @returns Whether the dot strip renders.
262
+ */
263
+ dotsShown() {
264
+ return (this.showDots ?? true) && this.slideCount() > 1;
265
+ }
266
+ /**
267
+ * The translated previous-arrow label.
268
+ * @returns The accessible name.
269
+ */
270
+ previousLabel() {
271
+ return this.i18n.t('carousel.previous', {}, { defaultValue: 'Previous' });
272
+ }
273
+ /**
274
+ * The translated next-arrow label.
275
+ * @returns The accessible name.
276
+ */
277
+ nextLabel() {
278
+ return this.i18n.t('carousel.next', {}, { defaultValue: 'Next' });
279
+ }
280
+ /**
281
+ * The translated label of one dot.
282
+ * @param i - The dot's slide index.
283
+ * @returns The accessible name.
284
+ */
285
+ goToLabel(i) {
286
+ return this.i18n.t('carousel.goToSlide', { index: i + 1 }, { defaultValue: 'Go to slide {{index}}' });
287
+ }
288
+ /**
289
+ * The dot strip's class list (React's flex row + `cm.sp('py', 2)`).
290
+ * @returns The class string.
291
+ */
292
+ dotsClasses() {
293
+ return this.cm().cn(this.cm().flex({ align: 'center', justify: 'center', gap: 'xs' }), this.cm().sp('py', 2));
294
+ }
295
+ /**
296
+ * One dot button's class list.
297
+ * @returns The class string.
298
+ */
299
+ dotClasses() {
300
+ return this.cm().cn(this.cm().cursorPointer, this.cm().touchTargetCompact, this.cm().flex({ align: 'center', justify: 'center' }));
301
+ }
302
+ /**
303
+ * The one dot glyph's inline style: React's 8px circle in the active or
304
+ * inactive theme token.
305
+ * @param i - The dot's slide index.
306
+ * @returns The declaration string.
307
+ */
308
+ dotFill(i) {
309
+ // Theme tokens: the inactive dot was `rgba(0,0,0,0.2)`, which is invisible
310
+ // on a dark surface.
311
+ const background = i === this.activeIndex()
312
+ ? 'var(--mol-color-primary, currentColor)'
313
+ : 'var(--mol-color-border, rgba(128,128,128,0.4))';
314
+ return `display: block; width: 8px; height: 8px; border-radius: 50%; background: ${background}`;
315
+ }
316
+ /**
317
+ * The track's inline style — React's flex track, translated to the active
318
+ * slide.
319
+ * @returns The declaration string.
320
+ */
321
+ trackStyle() {
322
+ const total = this.slideCount();
323
+ const shift = total === 0 ? 0 : (this.activeIndex() / total) * 100;
324
+ return `display: flex; width: ${total * 100}%; transform: translateX(-${shift}%); transition: transform 250ms ease`;
325
+ }
326
+ /**
327
+ * The dot indices, in order (React's `children.map((_, i) => …)`).
328
+ * @returns The indices `0 … slideCount - 1`.
329
+ */
330
+ dotIndexes() {
331
+ return Array.from({ length: this.slideCount() }, (_, i) => i);
332
+ }
333
+ /** Records the pointer entering the carousel. */
334
+ enter() {
335
+ this.hovered.set(true);
336
+ }
337
+ /** Records the pointer leaving the carousel. */
338
+ leave() {
339
+ this.hovered.set(false);
340
+ }
341
+ /** Moves one slide back. */
342
+ previous() {
343
+ this.setIdx(this.activeIndex() - 1);
344
+ }
345
+ /** Moves one slide forward. */
346
+ next() {
347
+ this.setIdx(this.activeIndex() + 1);
348
+ }
349
+ /**
350
+ * Jumps to one slide.
351
+ * @param i - The destination index.
352
+ */
353
+ goTo(i) {
354
+ this.setIdx(i);
355
+ }
356
+ /**
357
+ * Moves to an index, clamping or wrapping exactly as React's `setIdx` does,
358
+ * then reports the clamped value through `onChange` (also when controlled).
359
+ * @param index - The requested index.
360
+ */
361
+ setIdx(index) {
362
+ const total = this.slideCount();
363
+ const clamped = (this.loop ?? true) ? (index + total) % total : Math.max(0, Math.min(total - 1, index));
364
+ if (this.index === undefined)
365
+ this.internal.set(clamped);
366
+ this.onChange?.(clamped);
367
+ }
368
+ /**
369
+ * Wraps the projected slides once the view (and its track query) exists —
370
+ * the projected content is created with the view, and a zoneless app does not
371
+ * re-check a clean view.
372
+ */
373
+ ngAfterViewInit() {
374
+ this.wrapSlides();
375
+ }
376
+ /**
377
+ * Wraps every projected slide that is not wrapped yet, keeps the host element
378
+ * to React's rule (no element at all without slides) and publishes the count.
379
+ * Idempotent: the first check wraps, later checks only reconcile.
380
+ */
381
+ wrapSlides() {
382
+ const track = this.track?.nativeElement;
383
+ if (track) {
384
+ for (const node of unwrapped(track, this.wrappers)) {
385
+ const wrapper = document.createElement('div');
386
+ wrapper.setAttribute('data-mol-id', 'carousel-slide');
387
+ track.insertBefore(wrapper, node);
388
+ wrapper.appendChild(node);
389
+ this.wrappers.push(wrapper);
390
+ }
391
+ }
392
+ const host = this.host.nativeElement;
393
+ if (this.wrappers.length === 0) {
394
+ if (host.isConnected) {
395
+ this.hostParent = host.parentNode;
396
+ host.remove();
397
+ }
398
+ }
399
+ else if (!host.isConnected && this.hostParent) {
400
+ this.hostParent.appendChild(host);
401
+ }
402
+ this.publishCount(this.wrappers.length);
403
+ }
404
+ /**
405
+ * Publishes the slide count after the current check when it changed: the
406
+ * projected content exists only after the view is created, and a write during
407
+ * this check would change a binding the check already read.
408
+ *
409
+ * @param total - The count read from the rendered wrappers.
410
+ */
411
+ publishCount(total) {
412
+ if (total === this.slideCount() || total === this.pendingCount)
413
+ return;
414
+ this.pendingCount = total;
415
+ queueMicrotask(() => {
416
+ this.pendingCount = -1;
417
+ this.slideCount.set(total);
418
+ });
419
+ }
420
+ static ɵfac = function Carousel_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || Carousel)(); };
421
+ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: Carousel, selectors: [["div", "mol-carousel", ""]], viewQuery: function Carousel_Query(rf, ctx) { if (rf & 1) {
422
+ i0.ɵɵviewQuery(_c0, 5);
423
+ } if (rf & 2) {
424
+ let _t;
425
+ i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.track = _t.first);
426
+ } }, hostVars: 2, hostBindings: function Carousel_HostBindings(rf, ctx) { if (rf & 1) {
427
+ i0.ɵɵlistener("mouseenter", function Carousel_mouseenter_HostBindingHandler() { return ctx.enter(); })("mouseleave", function Carousel_mouseleave_HostBindingHandler() { return ctx.leave(); });
428
+ } if (rf & 2) {
429
+ i0.ɵɵclassMap(ctx.classes());
430
+ } }, inputs: { index: "index", onChange: "onChange", showArrows: "showArrows", showDots: "showDots", autoplayMs: "autoplayMs", pauseOnHover: "pauseOnHover", loop: "loop", className: "className" }, ngContentSelectors: _c1, decls: 6, vars: 4, consts: [["track", ""], [2, "overflow", "hidden"], [3, "class"], ["mol-button", "", 3, "click", "variant", "size", "className"], ["type", "button", "data-mol-id", "carousel-dot", 3, "class", "style"], ["type", "button", "data-mol-id", "carousel-dot", 3, "click"], ["aria-hidden", "true"]], template: function Carousel_Template(rf, ctx) { if (rf & 1) {
431
+ i0.ɵɵprojectionDef();
432
+ i0.ɵɵelementStart(0, "div", 1)(1, "div", null, 0);
433
+ i0.ɵɵprojection(3);
434
+ i0.ɵɵelementEnd()();
435
+ i0.ɵɵconditionalCreate(4, Carousel_Conditional_4_Template, 4, 12);
436
+ i0.ɵɵconditionalCreate(5, Carousel_Conditional_5_Template, 3, 2, "div", 2);
437
+ } if (rf & 2) {
438
+ i0.ɵɵadvance();
439
+ i0.ɵɵstyleMap(ctx.trackStyle());
440
+ i0.ɵɵadvance(3);
441
+ i0.ɵɵconditional(ctx.arrowsShown() ? 4 : -1);
442
+ i0.ɵɵadvance();
443
+ i0.ɵɵconditional(ctx.dotsShown() ? 5 : -1);
444
+ } }, dependencies: [Button], encapsulation: 2 });
445
+ }
446
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(Carousel, [{
447
+ type: Component,
448
+ args: [{
449
+ selector: 'div[mol-carousel]',
450
+ standalone: true,
451
+ imports: [Button],
452
+ inputs: [
453
+ 'index',
454
+ 'onChange',
455
+ 'showArrows',
456
+ 'showDots',
457
+ 'autoplayMs',
458
+ 'pauseOnHover',
459
+ 'loop',
460
+ 'className',
461
+ ],
462
+ host: {
463
+ '[class]': 'classes()',
464
+ '(mouseenter)': 'enter()',
465
+ '(mouseleave)': 'leave()',
466
+ },
467
+ // prettier-ignore
468
+ template: `<div style="overflow: hidden"><div #track [style]="trackStyle()"><ng-content></ng-content></div></div>@if (arrowsShown()) {<button mol-button [variant]="'ghost'" [size]="'sm'" (click)="previous()" [attr.aria-label]="previousLabel()" [className]="absoluteClass()" [style]="arrowLeftStyle">‹</button><button mol-button [variant]="'ghost'" [size]="'sm'" (click)="next()" [attr.aria-label]="nextLabel()" [className]="absoluteClass()" [style]="arrowRightStyle">›</button>}@if (dotsShown()) {<div [class]="dotsClasses()">@for (i of dotIndexes(); track i) {<button type="button" data-mol-id="carousel-dot" [attr.data-active]="i === activeIndex() ? 'true' : 'false'" [attr.aria-label]="goToLabel(i)" [attr.aria-current]="i === activeIndex() ? 'true' : null" (click)="goTo(i)" [class]="dotClasses()" [style]="dotStyle"><span aria-hidden="true" [style]="dotFill(i)"></span></button>}</div>}`,
469
+ }]
470
+ }], () => [], { track: [{
471
+ type: ViewChild,
472
+ args: ['track']
473
+ }] }); })();
474
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(Carousel, { className: "Carousel", filePath: "carousel.component.ts", lineNumber: 90 }); })();
475
+ //# sourceMappingURL=carousel.component.js.map