@reliability-design/web 1.1.1 → 1.2.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 (64) hide show
  1. package/dist/components/rel-accordion/rel-accordion.ts +17 -32
  2. package/dist/components/rel-alert/rel-alert.ts +34 -34
  3. package/dist/components/rel-avatar/rel-avatar.ts +5 -3
  4. package/dist/components/rel-badge/rel-badge.ts +2 -1
  5. package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +6 -6
  6. package/dist/components/rel-button/rel-button.ts +67 -21
  7. package/dist/components/rel-calendar/rel-calendar.ts +15 -8
  8. package/dist/components/rel-card/rel-card.ts +9 -17
  9. package/dist/components/rel-cardmedia/rel-cardmedia.ts +20 -23
  10. package/dist/components/rel-carousel/rel-carousel.ts +596 -468
  11. package/dist/components/rel-checkbox/rel-checkbox.ts +68 -16
  12. package/dist/components/rel-chip/rel-chip.ts +291 -244
  13. package/dist/components/rel-container/rel-container.ts +2 -2
  14. package/dist/components/rel-date-picker/rel-date-picker.ts +23 -19
  15. package/dist/components/rel-divider/rel-divider.ts +3 -3
  16. package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -2
  17. package/dist/components/rel-drawer/rel-drawer.ts +41 -88
  18. package/dist/components/rel-kbd/rel-kbd.ts +94 -118
  19. package/dist/components/rel-layout/rel-layout.ts +49 -58
  20. package/dist/components/rel-menu/rel-menu.ts +359 -359
  21. package/dist/components/rel-menubar/rel-menubar-menu.css +3 -0
  22. package/dist/components/rel-menubar/rel-menubar-menu.ts +2 -1
  23. package/dist/components/rel-menubar/rel-menubar.ts +602 -605
  24. package/dist/components/rel-otp/rel-otp.ts +22 -25
  25. package/dist/components/rel-pagination/rel-pagination.ts +101 -57
  26. package/dist/components/rel-popover/rel-popover-content.ts +6 -5
  27. package/dist/components/rel-popover/rel-popover.ts +26 -7
  28. package/dist/components/rel-progress/rel-progress.ts +10 -9
  29. package/dist/components/rel-radio/rel-radio.ts +228 -172
  30. package/dist/components/rel-range-picker/rel-range-picker.css +349 -0
  31. package/dist/components/rel-range-picker/rel-range-picker.ts +1079 -0
  32. package/dist/components/rel-resizable/rel-resizable-handle.ts +8 -7
  33. package/dist/components/rel-segmented-button/rel-segmented-button.ts +41 -20
  34. package/dist/components/rel-select/rel-select.ts +103 -32
  35. package/dist/components/rel-sheet/rel-sheet.ts +362 -684
  36. package/dist/components/rel-slider/rel-slider.ts +49 -27
  37. package/dist/components/rel-snackbar/rel-snackbar.ts +28 -28
  38. package/dist/components/rel-stepper/rel-stepper.ts +11 -10
  39. package/dist/components/rel-switch/rel-switch.ts +7 -6
  40. package/dist/components/rel-tab/rel-tab.ts +15 -29
  41. package/dist/components/rel-textfield/rel-textfield.ts +144 -35
  42. package/dist/components/rel-toast/rel-toast.ts +25 -12
  43. package/dist/components/rel-tooltip/rel-tooltip.ts +123 -123
  44. package/dist/components/rel-topbar/rel-topbar-actions.ts +1 -0
  45. package/dist/components/rel-topbar/rel-topbar-brand.ts +1 -0
  46. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +32 -2
  47. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +1 -1
  48. package/dist/components/rel-topbar/rel-topbar-item.ts +15 -10
  49. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +1 -0
  50. package/dist/components/rel-topbar/rel-topbar-profile.ts +30 -56
  51. package/dist/components/rel-topbar/rel-topbar-utilities.ts +1 -0
  52. package/dist/components/rel-topbar/rel-topbar.ts +137 -28
  53. package/dist/index.d.mts +153 -178
  54. package/dist/index.d.ts +153 -178
  55. package/dist/index.js +4711 -3875
  56. package/dist/index.js.map +1 -1
  57. package/dist/index.mjs +4047 -3202
  58. package/dist/index.mjs.map +1 -1
  59. package/dist/rel-menubar-menu-BEEQDAXW.css +3 -0
  60. package/dist/styles/vars-v2.css +525 -0
  61. package/dist/styles/vars.css +346 -346
  62. package/dist/{vars-TBB4BMSD.css → vars-I2PC74XD.css} +346 -346
  63. package/dist/vars-v2-VMGWTFJZ.css +525 -0
  64. package/package.json +2 -1
@@ -1,468 +1,596 @@
1
- import { LitElement, html, css, nothing } from "lit";
2
- import { customElement, property, state, query } from "lit/decorators.js";
3
-
4
- @customElement("rel-carousel")
5
- export class RelCarousel extends LitElement {
6
- @property({ type: Number, reflect: true }) value = 0;
7
- @property({ type: Boolean }) loop = false;
8
- @property({ type: Boolean }) autoplay = false;
9
- @property({ type: Number }) interval = 5000;
10
- @property({ type: Boolean, attribute: "pause-on-hover" }) pauseOnHover = true;
11
- @property({ type: Boolean, attribute: "show-buttons" }) showButtons = true;
12
- @property({ type: Boolean, attribute: "show-dots" }) showDots = true;
13
- @property({ type: String }) orientation: "horizontal" | "vertical" = "horizontal";
14
- @property({ type: String }) label: string = "Carousel";
15
- @property({ type: Number }) gap?: number;
16
- @property({ type: Boolean, reflect: true }) disabled = false;
17
-
18
- @state() private slideCount = 0;
19
- @state() private isDragging = false;
20
- @state() private dragStartX = 0;
21
- @state() private currentTranslate = 0;
22
- @state() private prevTranslate = 0;
23
-
24
- @query(".viewport") private viewport?: HTMLElement;
25
- @query(".track") private track?: HTMLElement;
26
- @query("slot") private slotElement?: HTMLSlotElement;
27
-
28
- private autoplayTimer?: number;
29
- private animationId?: number;
30
- private prefersReducedMotion = false;
31
-
32
- static styles = css`
33
- :host {
34
- display: block;
35
- font-family: var(--rel-fontFamilies-primary);
36
- position: relative;
37
- user-select: none;
38
- }
39
-
40
- :host([disabled]) {
41
- opacity: 0.6;
42
- pointer-events: none;
43
- }
44
-
45
- .viewport {
46
- overflow: hidden;
47
- position: relative;
48
- width: 100%;
49
- }
50
-
51
- .track {
52
- display: flex;
53
- transition: transform 0.3s ease-out;
54
- will-change: transform;
55
- }
56
-
57
- .track.dragging {
58
- transition: none;
59
- }
60
-
61
- .track.no-transition {
62
- transition: none;
63
- }
64
-
65
- ::slotted(*) {
66
- flex: 0 0 100%;
67
- min-width: 0;
68
- }
69
-
70
- /* Navigation buttons */
71
- .nav-button {
72
- position: absolute;
73
- top: 50%;
74
- transform: translateY(-50%);
75
- z-index: 10;
76
- width: var(--rel-carousel-nav-size, 40px);
77
- height: var(--rel-carousel-nav-size, 40px);
78
- border-radius: 50%;
79
- border: 1px solid var(--rel-color-border-default);
80
- background: var(--rel-color-bg-primary);
81
- color: var(--rel-colors-gray-primary);
82
- cursor: pointer;
83
- display: flex;
84
- align-items: center;
85
- justify-content: center;
86
- transition: all 0.15s ease;
87
- box-shadow: var(--rel-shadows-shadow-100);
88
- }
89
-
90
- .nav-button:hover:not(:disabled) {
91
- background: var(--rel-surface-secondary);
92
- }
93
-
94
- .nav-button:focus-visible {
95
- outline: 2px solid var(--rel-colors-blue-primary);
96
- outline-offset: 2px;
97
- }
98
-
99
- .nav-button:disabled {
100
- opacity: 0.4;
101
- cursor: not-allowed;
102
- }
103
-
104
- .nav-button.prev {
105
- left: 12px;
106
- }
107
-
108
- .nav-button.next {
109
- right: 12px;
110
- }
111
-
112
- .nav-button svg {
113
- width: 20px;
114
- height: 20px;
115
- }
116
-
117
- /* Dots indicator */
118
- .dots {
119
- display: flex;
120
- justify-content: center;
121
- gap: var(--rel-spacing-space-xs);
122
- margin-top: var(--rel-spacing-space-md);
123
- }
124
-
125
- .dot {
126
- width: var(--rel-carousel-dot-size, 8px);
127
- height: var(--rel-carousel-dot-size, 8px);
128
- border-radius: 50%;
129
- border: none;
130
- background: var(--rel-colors-gray-border);
131
- cursor: pointer;
132
- padding: 0;
133
- transition: all 0.15s ease;
134
- }
135
-
136
- .dot:hover {
137
- background: var(--rel-colors-gray-divider);
138
- }
139
-
140
- .dot.active {
141
- background: var(--rel-color-brand);
142
- width: var(--rel-carousel-dot-size-active, 24px);
143
- border-radius: 4px;
144
- }
145
-
146
- .dot:focus-visible {
147
- outline: 2px solid var(--rel-colors-blue-primary);
148
- outline-offset: 2px;
149
- }
150
-
151
- /* Reduced motion support */
152
- @media (prefers-reduced-motion: reduce) {
153
- .track {
154
- transition: none;
155
- }
156
- }
157
- `;
158
-
159
- connectedCallback() {
160
- super.connectedCallback();
161
- this.prefersReducedMotion = window.matchMedia(
162
- "(prefers-reduced-motion: reduce)"
163
- ).matches;
164
-
165
- if (this.autoplay) {
166
- this.startAutoplay();
167
- }
168
- }
169
-
170
- disconnectedCallback() {
171
- super.disconnectedCallback();
172
- this.stopAutoplay();
173
- if (this.animationId) {
174
- cancelAnimationFrame(this.animationId);
175
- }
176
- }
177
-
178
- private handleSlotChange() {
179
- const slot = this.slotElement;
180
- if (!slot) return;
181
-
182
- const elements = slot.assignedElements();
183
- this.slideCount = elements.length;
184
-
185
- // Ensure value is within bounds
186
- if (this.value >= this.slideCount) {
187
- this.value = this.slideCount - 1;
188
- }
189
- if (this.value < 0) {
190
- this.value = 0;
191
- }
192
-
193
- this.updateTransform();
194
- }
195
-
196
- private updateTransform() {
197
- if (!this.track || !this.viewport) return;
198
-
199
- const slideWidth = this.viewport.offsetWidth;
200
- const gapValue = this.gap ?? 0;
201
- const translate = -(this.value * (slideWidth + gapValue));
202
-
203
- this.currentTranslate = translate;
204
- this.prevTranslate = translate;
205
- this.track.style.transform = `translateX(${translate}px)`;
206
-
207
- if (this.gap) {
208
- this.track.style.gap = `${this.gap}px`;
209
- } else {
210
- this.track.style.gap = "";
211
- }
212
- }
213
-
214
- private goToPrevious() {
215
- if (this.disabled) return;
216
-
217
- if (this.value > 0) {
218
- this.value--;
219
- } else if (this.loop) {
220
- this.value = this.slideCount - 1;
221
- }
222
-
223
- this.updateTransform();
224
- this.emitChange();
225
- }
226
-
227
- private goToNext() {
228
- if (this.disabled) return;
229
-
230
- if (this.value < this.slideCount - 1) {
231
- this.value++;
232
- } else if (this.loop) {
233
- this.value = 0;
234
- }
235
-
236
- this.updateTransform();
237
- this.emitChange();
238
- }
239
-
240
- private goToSlide(index: number) {
241
- if (this.disabled || index < 0 || index >= this.slideCount) return;
242
-
243
- this.value = index;
244
- this.updateTransform();
245
- this.emitChange();
246
- }
247
-
248
- private emitChange() {
249
- this.dispatchEvent(
250
- new CustomEvent("rel-change", {
251
- detail: { value: this.value },
252
- bubbles: true,
253
- composed: true,
254
- })
255
- );
256
- }
257
-
258
- private startAutoplay() {
259
- if (!this.autoplay || this.disabled) return;
260
-
261
- this.stopAutoplay();
262
- this.autoplayTimer = window.setInterval(() => {
263
- this.goToNext();
264
- }, this.interval);
265
- }
266
-
267
- private stopAutoplay() {
268
- if (this.autoplayTimer) {
269
- clearInterval(this.autoplayTimer);
270
- this.autoplayTimer = undefined;
271
- }
272
- }
273
-
274
- private handlePointerDown(e: PointerEvent) {
275
- if (this.disabled || !this.track) return;
276
-
277
- this.isDragging = true;
278
- this.dragStartX = e.clientX;
279
- this.prevTranslate = this.currentTranslate;
280
-
281
- this.track.classList.add("dragging");
282
-
283
- if (this.autoplay && this.pauseOnHover) {
284
- this.stopAutoplay();
285
- }
286
-
287
- e.preventDefault();
288
- }
289
-
290
- private handlePointerMove(e: PointerEvent) {
291
- if (!this.isDragging || !this.track) return;
292
-
293
- const currentX = e.clientX;
294
- const deltaX = currentX - this.dragStartX;
295
- this.currentTranslate = this.prevTranslate + deltaX;
296
-
297
- if (!this.prefersReducedMotion && this.animationId) {
298
- cancelAnimationFrame(this.animationId);
299
- }
300
-
301
- this.animationId = requestAnimationFrame(() => {
302
- if (this.track) {
303
- this.track.style.transform = `translateX(${this.currentTranslate}px)`;
304
- }
305
- });
306
- }
307
-
308
- private handlePointerUp(e: PointerEvent) {
309
- if (!this.isDragging || !this.track || !this.viewport) return;
310
-
311
- this.isDragging = false;
312
- this.track.classList.remove("dragging");
313
-
314
- const deltaX = e.clientX - this.dragStartX;
315
- const slideWidth = this.viewport.offsetWidth;
316
- const threshold = slideWidth * 0.2; // 20% threshold
317
-
318
- if (Math.abs(deltaX) > threshold) {
319
- if (deltaX > 0 && (this.value > 0 || this.loop)) {
320
- this.goToPrevious();
321
- } else if (deltaX < 0 && (this.value < this.slideCount - 1 || this.loop)) {
322
- this.goToNext();
323
- } else {
324
- this.updateTransform();
325
- }
326
- } else {
327
- this.updateTransform();
328
- }
329
-
330
- if (this.autoplay) {
331
- this.startAutoplay();
332
- }
333
- }
334
-
335
- private handleKeyDown(e: KeyboardEvent) {
336
- if (this.disabled) return;
337
-
338
- switch (e.key) {
339
- case "ArrowLeft":
340
- e.preventDefault();
341
- this.goToPrevious();
342
- break;
343
- case "ArrowRight":
344
- e.preventDefault();
345
- this.goToNext();
346
- break;
347
- case "Home":
348
- e.preventDefault();
349
- this.goToSlide(0);
350
- break;
351
- case "End":
352
- e.preventDefault();
353
- this.goToSlide(this.slideCount - 1);
354
- break;
355
- }
356
- }
357
-
358
- private handleMouseEnter() {
359
- if (this.autoplay && this.pauseOnHover) {
360
- this.stopAutoplay();
361
- }
362
- }
363
-
364
- private handleMouseLeave() {
365
- if (this.autoplay && this.pauseOnHover) {
366
- this.startAutoplay();
367
- }
368
- }
369
-
370
- updated(changedProperties: Map<string, any>) {
371
- if (changedProperties.has("autoplay") || changedProperties.has("interval")) {
372
- if (this.autoplay) {
373
- this.startAutoplay();
374
- } else {
375
- this.stopAutoplay();
376
- }
377
- }
378
-
379
- if (changedProperties.has("value")) {
380
- this.updateTransform();
381
- }
382
- }
383
-
384
- render() {
385
- const canGoPrev = this.loop || this.value > 0;
386
- const canGoNext = this.loop || this.value < this.slideCount - 1;
387
-
388
- return html`
389
- <div
390
- class="viewport"
391
- part="viewport"
392
- role="region"
393
- aria-roledescription="carousel"
394
- aria-label=${this.label}
395
- @keydown=${this.handleKeyDown}
396
- @mouseenter=${this.handleMouseEnter}
397
- @mouseleave=${this.handleMouseLeave}
398
- tabindex="0"
399
- >
400
- <div
401
- class="track"
402
- part="track"
403
- @pointerdown=${this.handlePointerDown}
404
- @pointermove=${this.handlePointerMove}
405
- @pointerup=${this.handlePointerUp}
406
- @pointercancel=${this.handlePointerUp}
407
- >
408
- <slot @slotchange=${this.handleSlotChange}></slot>
409
- </div>
410
-
411
- ${this.showButtons
412
- ? html`
413
- <button
414
- class="nav-button prev"
415
- part="prev-button"
416
- aria-label="Previous slide"
417
- ?disabled=${!canGoPrev || this.disabled}
418
- @click=${this.goToPrevious}
419
- >
420
- <svg viewBox="0 0 16 16" fill="none">
421
- <path
422
- d="M10 12L6 8L10 4"
423
- stroke="currentColor"
424
- stroke-width="2"
425
- stroke-linecap="round"
426
- stroke-linejoin="round"
427
- />
428
- </svg>
429
- </button>
430
-
431
- <button
432
- class="nav-button next"
433
- part="next-button"
434
- aria-label="Next slide"
435
- ?disabled=${!canGoNext || this.disabled}
436
- @click=${this.goToNext}
437
- >
438
- <svg viewBox="0 0 16 16" fill="none">
439
- <path
440
- d="M6 4L10 8L6 12"
441
- stroke="currentColor"
442
- stroke-width="2"
443
- stroke-linecap="round"
444
- stroke-linejoin="round"
445
- />
446
- </svg>
447
- </button>
448
- `
449
- : nothing}
450
- </div>
451
-
452
- ${this.showDots && this.slideCount > 1
453
- ? html`
454
- <div class="dots" part="dots">
455
- ${Array.from({ length: this.slideCount }, (_, i) => html`
456
- <button
457
- class="dot ${i === this.value ? "active" : ""}"
458
- part="dot"
459
- aria-label="Go to slide ${i + 1}"
460
- @click=${() => this.goToSlide(i)}
461
- ></button>
462
- `)}
463
- </div>
464
- `
465
- : nothing}
466
- `;
467
- }
468
- }
1
+ import { LitElement, html, css, nothing } from "lit";
2
+ import { customElement, property, state, query } from "lit/decorators.js";
3
+ import "../../styles/vars-v2.css";
4
+
5
+ @customElement("rel-carousel")
6
+ export class RelCarousel extends LitElement {
7
+ @property({ type: Number, reflect: true }) value = 0;
8
+ @property({ type: Boolean }) loop = false;
9
+ @property({ type: Boolean }) autoplay = false;
10
+ @property({ type: Number }) interval = 5000;
11
+ @property({ type: Boolean, attribute: "pause-on-hover" }) pauseOnHover = true;
12
+ @property({ type: Boolean, attribute: "show-buttons" }) showButtons = false;
13
+ @property({ type: Boolean, attribute: "show-dots" }) showDots = false;
14
+ @property({ type: String }) orientation: "horizontal" | "vertical" = "horizontal";
15
+ @property({ type: String }) label: string = "Carousel";
16
+ @property({ type: Number }) gap?: number;
17
+ @property({ type: Boolean, reflect: true }) disabled = false;
18
+
19
+ @state() private slideCount = 0;
20
+ @state() private isDragging = false;
21
+ @state() private dragStartX = 0;
22
+ @state() private currentTranslate = 0;
23
+ @state() private prevTranslate = 0;
24
+
25
+ @query(".viewport") private viewport?: HTMLElement;
26
+ @query(".track") private track?: HTMLElement;
27
+ @query("slot") private slotElement?: HTMLSlotElement;
28
+
29
+ private autoplayTimer?: number;
30
+ private animationId?: number;
31
+ private prefersReducedMotion = false;
32
+ // Number of clone slides prepended before the real slides
33
+ private clonesBefore = 0;
34
+ private _silentJumping = false;
35
+ private _ro?: ResizeObserver;
36
+
37
+ static styles = css`
38
+ :host {
39
+ display: block;
40
+ font-family: var(--rel-fontFamilies-primary);
41
+ position: relative;
42
+ user-select: none;
43
+ }
44
+
45
+ :host([disabled]) {
46
+ opacity: 0.6;
47
+ pointer-events: none;
48
+ cursor: not-allowed;
49
+ }
50
+
51
+ .viewport {
52
+ overflow: hidden;
53
+ position: relative;
54
+ width: 100%;
55
+ display: block;
56
+ }
57
+
58
+ .track {
59
+ display: flex;
60
+ width: 100%;
61
+ transition: transform 0.3s ease-out;
62
+ will-change: transform;
63
+ }
64
+
65
+ .track.dragging {
66
+ transition: none;
67
+ }
68
+
69
+ .track.no-transition {
70
+ transition: none;
71
+ }
72
+
73
+ ::slotted(*) {
74
+ flex-shrink: 0 !important;
75
+ width: var(--rel-carousel-slide-width, 100%) !important;
76
+ min-width: 0 !important;
77
+ box-sizing: border-box !important;
78
+ }
79
+
80
+ /* Clone slides injected for seamless loop */
81
+ .carousel-clone {
82
+ flex: 0 0 100%;
83
+ min-width: 0;
84
+ box-sizing: border-box;
85
+ display: flex;
86
+ align-items: center;
87
+ justify-content: center;
88
+ background: var(--rel-color-bg-tertiary, #f0f0f0);
89
+ }
90
+
91
+ /* Navigation buttons */
92
+ .nav-button {
93
+ position: absolute;
94
+ top: 50%;
95
+ transform: translateY(-50%);
96
+ z-index: 10;
97
+ width: var(--rel-carousel-nav-size, 40px);
98
+ height: var(--rel-carousel-nav-size, 40px);
99
+ border-radius: 50%;
100
+ border: 1px solid var(--rel-color-border-default);
101
+ background: var(--rel-color-bg-primary);
102
+ color: var(--rel-color-text-primary);
103
+ cursor: pointer;
104
+ display: flex;
105
+ align-items: center;
106
+ justify-content: center;
107
+ transition: all 0.15s ease;
108
+ box-shadow: var(--rel-shadows-shadow-100);
109
+ }
110
+
111
+ .nav-button:hover:not(:disabled) {
112
+ background: var(--rel-color-bg-secondary);
113
+ }
114
+
115
+ .nav-button:focus-visible {
116
+ outline: 2px solid var(--rel-color-border-focus);
117
+ outline-offset: 2px;
118
+ }
119
+
120
+ .nav-button:disabled {
121
+ opacity: 0.4;
122
+ cursor: not-allowed;
123
+ }
124
+
125
+ .nav-button.prev {
126
+ left: 12px;
127
+ }
128
+
129
+ .nav-button.next {
130
+ right: 12px;
131
+ }
132
+
133
+ .nav-button svg {
134
+ width: 20px;
135
+ height: 20px;
136
+ }
137
+
138
+ /* Dots indicator */
139
+ .dots {
140
+ display: flex;
141
+ justify-content: center;
142
+ gap: var(--rel-spacing-space-xs);
143
+ margin-top: var(--rel-spacing-space-md);
144
+ }
145
+
146
+ .dot {
147
+ width: var(--rel-carousel-dot-size, 8px);
148
+ height: var(--rel-carousel-dot-size, 8px);
149
+ border-radius: 50%;
150
+ border: none;
151
+ background: var(--rel-color-border-default);
152
+ cursor: pointer;
153
+ padding: 0;
154
+ transition: all 0.15s ease;
155
+ }
156
+
157
+ .dot:hover {
158
+ background: var(--rel-color-border-divider);
159
+ }
160
+
161
+ .dot.active {
162
+ background: var(--rel-color-brand);
163
+ width: var(--rel-carousel-dot-size-active, 24px);
164
+ border-radius: 4px;
165
+ }
166
+
167
+ .dot:focus-visible {
168
+ outline: 2px solid var(--rel-color-border-focus);
169
+ outline-offset: 2px;
170
+ }
171
+
172
+ /* Reduced motion support */
173
+ @media (prefers-reduced-motion: reduce) {
174
+ .track {
175
+ transition: none;
176
+ }
177
+ }
178
+
179
+ :host-context([data-theme="dark"]) .nav-button,
180
+ :host-context(.dark) .nav-button {
181
+ background: var(--rel-color-bg-secondary);
182
+ border-color: var(--rel-color-border-default);
183
+ color: var(--rel-color-text-primary);
184
+ }
185
+
186
+ :host-context([data-theme="dark"]) .nav-button:hover,
187
+ :host-context(.dark) .nav-button:hover {
188
+ background: var(--rel-color-bg-tertiary);
189
+ }
190
+ `;
191
+
192
+ connectedCallback() {
193
+ super.connectedCallback();
194
+ this.prefersReducedMotion = window.matchMedia(
195
+ "(prefers-reduced-motion: reduce)"
196
+ ).matches;
197
+
198
+ if (this.autoplay) {
199
+ this.startAutoplay();
200
+ }
201
+ }
202
+
203
+ firstUpdated() {
204
+ const ro = new ResizeObserver(() => {
205
+ const w = this.viewport?.offsetWidth ?? 0;
206
+ if (w === 0) return;
207
+ this.style.setProperty('--rel-carousel-slide-width', `${w}px`);
208
+ this.renderRoot.querySelectorAll('.carousel-clone').forEach(el => {
209
+ (el as HTMLElement).style.width = `${w}px`;
210
+ });
211
+ this.updateTransform();
212
+ });
213
+ if (this.viewport) ro.observe(this.viewport);
214
+ this._ro = ro;
215
+
216
+ requestAnimationFrame(() => {
217
+ const w = this.viewport?.offsetWidth ?? 0;
218
+ if (w > 0) {
219
+ this.style.setProperty('--rel-carousel-slide-width', `${w}px`);
220
+ this.updateTransform();
221
+ }
222
+ });
223
+ }
224
+
225
+ disconnectedCallback() {
226
+ super.disconnectedCallback();
227
+ this._ro?.disconnect();
228
+ this.stopAutoplay();
229
+ if (this.animationId) {
230
+ cancelAnimationFrame(this.animationId);
231
+ }
232
+ }
233
+
234
+ private handleSlotChange() {
235
+ const slot = this.slotElement;
236
+ const track = this.track;
237
+ if (!slot || !track) return;
238
+
239
+ const elements = slot.assignedElements();
240
+ this.slideCount = elements.length;
241
+
242
+ // Clamp value to valid real-slide range
243
+ if (this.value >= this.slideCount) this.value = Math.max(0, this.slideCount - 1);
244
+ if (this.value < 0) this.value = 0;
245
+
246
+ // Remove any existing shadow-DOM clones
247
+ track.querySelectorAll(".carousel-clone").forEach((el) => el.remove());
248
+
249
+ const useClones = (this.loop || this.autoplay) && this.slideCount > 1;
250
+
251
+ if (useClones) {
252
+ this.clonesBefore = 1;
253
+
254
+ // Clone last slide → prepend before <slot>
255
+ const lastEl = elements[this.slideCount - 1] as HTMLElement;
256
+ const lastClone = lastEl.cloneNode(true) as HTMLElement;
257
+ lastClone.classList.add("carousel-clone");
258
+ lastClone.setAttribute("aria-hidden", "true");
259
+ lastClone.style.width = `${this.viewport?.offsetWidth ?? 0}px`;
260
+ lastClone.style.boxSizing = 'border-box';
261
+ track.insertBefore(lastClone, slot);
262
+
263
+ // Clone first slide → append after <slot>
264
+ const firstEl = elements[0] as HTMLElement;
265
+ const firstClone = firstEl.cloneNode(true) as HTMLElement;
266
+ firstClone.classList.add("carousel-clone");
267
+ firstClone.setAttribute("aria-hidden", "true");
268
+ firstClone.style.width = `${this.viewport?.offsetWidth ?? 0}px`;
269
+ firstClone.style.boxSizing = 'border-box';
270
+ track.appendChild(firstClone);
271
+ } else {
272
+ this.clonesBefore = 0;
273
+ }
274
+
275
+ requestAnimationFrame(() => this.updateTransform());
276
+
277
+ // If loop/autoplay clones were inserted but viewport has no width yet,
278
+ // retry once after paint when dimensions are available
279
+ if (useClones && this.unit() === 0) {
280
+ requestAnimationFrame(() => {
281
+ requestAnimationFrame(() => {
282
+ this.handleSlotChange();
283
+ });
284
+ });
285
+ }
286
+ }
287
+
288
+ private unit(): number {
289
+ const slideWidth = this.viewport?.offsetWidth ?? 0;
290
+ const gapValue = this.gap && this.gap > 0 ? this.gap : 0;
291
+ return slideWidth + gapValue;
292
+ }
293
+
294
+ private updateTransform() {
295
+ if (!this.track || !this.viewport) return;
296
+
297
+ const u = this.unit();
298
+ const translate = -((this.value + this.clonesBefore) * u);
299
+
300
+ this.currentTranslate = translate;
301
+ this.prevTranslate = translate;
302
+ this.track.style.transform = `translateX(${translate}px)`;
303
+ this.track.style.gap = this.gap && this.gap > 0 ? `${this.gap}px` : "";
304
+ }
305
+
306
+ private goToPrevious() {
307
+ if (this.disabled) return;
308
+
309
+ if (this.value > 0) {
310
+ this.value--;
311
+ this.updateTransform();
312
+ this.emitChange();
313
+ } else if (this.clonesBefore > 0) {
314
+ // Animate to the lastClone (position 0 in the track)
315
+ const translate = 0;
316
+ this.currentTranslate = translate;
317
+ this.prevTranslate = translate;
318
+ this.track!.style.transform = `translateX(${translate}px)`;
319
+ this.track!.addEventListener(
320
+ "transitionend",
321
+ () => this.silentJump(this.slideCount - 1),
322
+ { once: true }
323
+ );
324
+ }
325
+ }
326
+
327
+ private goToNext() {
328
+ if (this.disabled) return;
329
+
330
+ if (this.value < this.slideCount - 1) {
331
+ this.value++;
332
+ this.updateTransform();
333
+ this.emitChange();
334
+ } else if (this.clonesBefore > 0) {
335
+ // Animate to the firstClone (one position past the last real slide)
336
+ const cloneFirstPos = this.slideCount + this.clonesBefore;
337
+ const translate = -(cloneFirstPos * this.unit());
338
+ this.currentTranslate = translate;
339
+ this.prevTranslate = translate;
340
+ this.track!.style.transform = `translateX(${translate}px)`;
341
+ this.track!.addEventListener(
342
+ "transitionend",
343
+ () => this.silentJump(0),
344
+ { once: true }
345
+ );
346
+ }
347
+ }
348
+
349
+ // Silently reposition to newValue with no visible transition, then re-enable animation.
350
+ private silentJump(newValue: number) {
351
+ if (!this.track) return;
352
+ this.track.classList.add("no-transition");
353
+ this._silentJumping = true;
354
+ this.value = newValue;
355
+ this.updateTransform();
356
+ this._silentJumping = false;
357
+ requestAnimationFrame(() => {
358
+ requestAnimationFrame(() => {
359
+ this.track!.classList.remove("no-transition");
360
+ });
361
+ });
362
+ this.emitChange();
363
+ }
364
+
365
+ private goToSlide(index: number) {
366
+ if (this.disabled || index < 0 || index >= this.slideCount) return;
367
+
368
+ this.value = index;
369
+ this.updateTransform();
370
+ this.emitChange();
371
+ }
372
+
373
+ private emitChange() {
374
+ this.dispatchEvent(
375
+ new CustomEvent("rel-change", {
376
+ detail: { value: this.value },
377
+ bubbles: true,
378
+ composed: true,
379
+ })
380
+ );
381
+ }
382
+
383
+ private startAutoplay() {
384
+ if (!this.autoplay || this.disabled) return;
385
+
386
+ this.stopAutoplay();
387
+ this.autoplayTimer = window.setInterval(() => {
388
+ this.goToNext();
389
+ }, this.interval);
390
+ }
391
+
392
+ private stopAutoplay() {
393
+ if (this.autoplayTimer) {
394
+ clearInterval(this.autoplayTimer);
395
+ this.autoplayTimer = undefined;
396
+ }
397
+ }
398
+
399
+ private handlePointerDown(e: PointerEvent) {
400
+ if (this.disabled || !this.track) return;
401
+
402
+ this.isDragging = true;
403
+ this.dragStartX = e.clientX;
404
+ this.prevTranslate = this.currentTranslate;
405
+
406
+ this.track.classList.add("dragging");
407
+
408
+ if (this.autoplay && this.pauseOnHover) {
409
+ this.stopAutoplay();
410
+ }
411
+
412
+ e.preventDefault();
413
+ }
414
+
415
+ private handlePointerMove(e: PointerEvent) {
416
+ if (!this.isDragging || !this.track) return;
417
+
418
+ const currentX = e.clientX;
419
+ const deltaX = currentX - this.dragStartX;
420
+ this.currentTranslate = this.prevTranslate + deltaX;
421
+
422
+ if (!this.prefersReducedMotion && this.animationId) {
423
+ cancelAnimationFrame(this.animationId);
424
+ }
425
+
426
+ this.animationId = requestAnimationFrame(() => {
427
+ if (this.track) {
428
+ this.track.style.transform = `translateX(${this.currentTranslate}px)`;
429
+ }
430
+ });
431
+ }
432
+
433
+ private handlePointerUp(e: PointerEvent) {
434
+ if (!this.isDragging || !this.track || !this.viewport) return;
435
+
436
+ this.isDragging = false;
437
+ this.track.classList.remove("dragging");
438
+
439
+ const deltaX = e.clientX - this.dragStartX;
440
+ const slideWidth = this.viewport.offsetWidth;
441
+ const threshold = slideWidth * 0.2; // 20% threshold
442
+
443
+ if (Math.abs(deltaX) > threshold) {
444
+ if (deltaX > 0 && (this.value > 0 || this.clonesBefore > 0)) {
445
+ this.goToPrevious();
446
+ } else if (deltaX < 0 && (this.value < this.slideCount - 1 || this.clonesBefore > 0)) {
447
+ this.goToNext();
448
+ } else {
449
+ this.updateTransform();
450
+ }
451
+ } else {
452
+ this.updateTransform();
453
+ }
454
+
455
+ if (this.autoplay) {
456
+ this.startAutoplay();
457
+ }
458
+ }
459
+
460
+ private handleKeyDown(e: KeyboardEvent) {
461
+ if (this.disabled) return;
462
+
463
+ switch (e.key) {
464
+ case "ArrowLeft":
465
+ e.preventDefault();
466
+ this.goToPrevious();
467
+ break;
468
+ case "ArrowRight":
469
+ e.preventDefault();
470
+ this.goToNext();
471
+ break;
472
+ case "Home":
473
+ e.preventDefault();
474
+ this.goToSlide(0);
475
+ break;
476
+ case "End":
477
+ e.preventDefault();
478
+ this.goToSlide(this.slideCount - 1);
479
+ break;
480
+ }
481
+ }
482
+
483
+ private handleMouseEnter() {
484
+ if (this.autoplay && this.pauseOnHover) {
485
+ this.stopAutoplay();
486
+ }
487
+ }
488
+
489
+ private handleMouseLeave() {
490
+ if (this.autoplay && this.pauseOnHover) {
491
+ this.startAutoplay();
492
+ }
493
+ }
494
+
495
+ updated(changedProperties: Map<string, any>) {
496
+ if (changedProperties.has("autoplay") || changedProperties.has("interval")) {
497
+ if (this.autoplay) {
498
+ this.startAutoplay();
499
+ } else {
500
+ this.stopAutoplay();
501
+ }
502
+ }
503
+
504
+ // Only call updateTransform via Lit lifecycle for in-range values;
505
+ // out-of-range transitions (clone positions) are managed directly.
506
+ // Skip when _silentJumping — silentJump() calls updateTransform() itself.
507
+ if (changedProperties.has("value") && !this._silentJumping && this.value >= 0 && this.value < this.slideCount) {
508
+ this.updateTransform();
509
+ }
510
+ }
511
+
512
+ render() {
513
+ const canGoPrev = this.clonesBefore > 0 || this.value > 0;
514
+ const canGoNext = this.clonesBefore > 0 || this.value < this.slideCount - 1;
515
+
516
+ return html`
517
+ <div
518
+ class="viewport"
519
+ part="viewport"
520
+ role="region"
521
+ aria-roledescription="carousel"
522
+ aria-label=${this.label}
523
+ @keydown=${this.handleKeyDown}
524
+ @mouseenter=${this.handleMouseEnter}
525
+ @mouseleave=${this.handleMouseLeave}
526
+ tabindex="0"
527
+ >
528
+ <div
529
+ class="track"
530
+ part="track"
531
+ @pointerdown=${this.handlePointerDown}
532
+ @pointermove=${this.handlePointerMove}
533
+ @pointerup=${this.handlePointerUp}
534
+ @pointercancel=${this.handlePointerUp}
535
+ >
536
+ <slot @slotchange=${this.handleSlotChange}></slot>
537
+ </div>
538
+
539
+ ${this.showButtons
540
+ ? html`
541
+ <button
542
+ class="nav-button prev"
543
+ part="prev-button"
544
+ aria-label="Previous slide"
545
+ ?disabled=${!canGoPrev || this.disabled}
546
+ @click=${this.goToPrevious}
547
+ >
548
+ <svg viewBox="0 0 16 16" fill="none">
549
+ <path
550
+ d="M10 12L6 8L10 4"
551
+ stroke="currentColor"
552
+ stroke-width="2"
553
+ stroke-linecap="round"
554
+ stroke-linejoin="round"
555
+ />
556
+ </svg>
557
+ </button>
558
+
559
+ <button
560
+ class="nav-button next"
561
+ part="next-button"
562
+ aria-label="Next slide"
563
+ ?disabled=${!canGoNext || this.disabled}
564
+ @click=${this.goToNext}
565
+ >
566
+ <svg viewBox="0 0 16 16" fill="none">
567
+ <path
568
+ d="M6 4L10 8L6 12"
569
+ stroke="currentColor"
570
+ stroke-width="2"
571
+ stroke-linecap="round"
572
+ stroke-linejoin="round"
573
+ />
574
+ </svg>
575
+ </button>
576
+ `
577
+ : nothing}
578
+ </div>
579
+
580
+ ${this.showDots && this.slideCount > 1
581
+ ? html`
582
+ <div class="dots" part="dots">
583
+ ${Array.from({ length: this.slideCount }, (_, i) => html`
584
+ <button
585
+ class="dot ${i === this.value ? "active" : ""}"
586
+ part="dot"
587
+ aria-label="Go to slide ${i + 1}"
588
+ @click=${() => this.goToSlide(i)}
589
+ ></button>
590
+ `)}
591
+ </div>
592
+ `
593
+ : nothing}
594
+ `;
595
+ }
596
+ }