@reliability-design/web 1.4.5 → 1.4.7

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 (142) hide show
  1. package/CHANGELOG.md +211 -49
  2. package/dist/components/rel-accordion/README.md +132 -132
  3. package/dist/components/rel-alert/README.md +145 -141
  4. package/dist/components/rel-autocomplete/README.md +156 -61
  5. package/dist/components/rel-avatar/README.md +116 -130
  6. package/dist/components/rel-badge/README.md +98 -93
  7. package/dist/components/rel-breadcrumb/README.md +96 -102
  8. package/dist/components/rel-button/README.md +160 -130
  9. package/dist/components/rel-calendar/README.md +109 -109
  10. package/dist/components/rel-card/README.md +75 -94
  11. package/dist/components/rel-cardmedia/README.md +100 -127
  12. package/dist/components/rel-carousel/README.md +184 -166
  13. package/dist/components/rel-checkbox/README.md +93 -75
  14. package/dist/components/rel-chip/README.md +132 -121
  15. package/dist/components/rel-container/README.md +107 -99
  16. package/dist/components/rel-date-picker/README.md +200 -289
  17. package/dist/components/rel-divider/README.md +78 -100
  18. package/dist/components/rel-drawer/README.md +187 -200
  19. package/dist/components/rel-kbd/README.md +141 -151
  20. package/dist/components/rel-menu/README.md +178 -151
  21. package/dist/components/rel-menubar/README.md +218 -329
  22. package/dist/components/rel-otp/README.md +170 -440
  23. package/dist/components/rel-pagination/README.md +100 -424
  24. package/dist/components/rel-popover/README.md +203 -568
  25. package/dist/components/rel-progress/README.md +88 -110
  26. package/dist/components/rel-radio/README.md +131 -135
  27. package/dist/components/rel-range-picker/README.md +162 -0
  28. package/dist/components/rel-resizable/README.md +199 -140
  29. package/dist/components/rel-segmented-button/README.md +155 -141
  30. package/dist/components/rel-select/README.md +154 -93
  31. package/dist/components/rel-sheet/README.md +168 -224
  32. package/dist/components/rel-skeleton/README.md +103 -0
  33. package/dist/components/rel-slider/README.md +130 -135
  34. package/dist/components/rel-snackbar/README.md +162 -134
  35. package/dist/components/rel-stepper/README.md +158 -160
  36. package/dist/components/rel-switch/README.md +108 -102
  37. package/dist/components/rel-tab/README.md +171 -163
  38. package/dist/components/rel-textfield/README.md +159 -69
  39. package/dist/components/rel-time-picker/README.md +122 -157
  40. package/dist/components/rel-toast/README.md +157 -148
  41. package/dist/components/rel-tooltip/README.md +108 -103
  42. package/dist/components/rel-upload/README.md +220 -0
  43. package/dist/index.d.mts +1387 -350
  44. package/dist/index.d.ts +1387 -350
  45. package/dist/index.js +5863 -3600
  46. package/dist/index.js.map +1 -1
  47. package/dist/index.mjs +5864 -3592
  48. package/dist/index.mjs.map +1 -1
  49. package/dist/styles/vars.css +877 -866
  50. package/dist/{vars-XNMTSRVN.css → vars-JHTUGNRG.css} +877 -866
  51. package/package.json +4 -3
  52. package/dist/components/rel-accordion/rel-accordion.ts +0 -336
  53. package/dist/components/rel-alert/rel-alert.ts +0 -305
  54. package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -689
  55. package/dist/components/rel-avatar/rel-avatar.ts +0 -142
  56. package/dist/components/rel-badge/rel-badge.ts +0 -170
  57. package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
  58. package/dist/components/rel-button/rel-button.ts +0 -560
  59. package/dist/components/rel-calendar/index.ts +0 -1
  60. package/dist/components/rel-calendar/rel-calendar.ts +0 -519
  61. package/dist/components/rel-card/rel-card.ts +0 -88
  62. package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
  63. package/dist/components/rel-carousel/index.ts +0 -1
  64. package/dist/components/rel-carousel/rel-carousel.ts +0 -700
  65. package/dist/components/rel-chart/README.md +0 -286
  66. package/dist/components/rel-chart/index.ts +0 -1
  67. package/dist/components/rel-chart/rel-chart.ts +0 -754
  68. package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
  69. package/dist/components/rel-chip/rel-chip.ts +0 -472
  70. package/dist/components/rel-container/rel-container.ts +0 -95
  71. package/dist/components/rel-date-picker/date-format.test.ts +0 -43
  72. package/dist/components/rel-date-picker/date-format.ts +0 -47
  73. package/dist/components/rel-date-picker/index.ts +0 -1
  74. package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1237
  75. package/dist/components/rel-divider/rel-divider.ts +0 -54
  76. package/dist/components/rel-drawer/index.ts +0 -1
  77. package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
  78. package/dist/components/rel-drawer/rel-drawer.ts +0 -604
  79. package/dist/components/rel-kbd/rel-kbd.ts +0 -188
  80. package/dist/components/rel-layout/rel-layout.ts +0 -49
  81. package/dist/components/rel-menu/rel-menu.ts +0 -535
  82. package/dist/components/rel-menubar/index.ts +0 -2
  83. package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
  84. package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
  85. package/dist/components/rel-menubar/rel-menubar.ts +0 -777
  86. package/dist/components/rel-nav-menu/README.md +0 -289
  87. package/dist/components/rel-nav-menu/index.ts +0 -3
  88. package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
  89. package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
  90. package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
  91. package/dist/components/rel-navbar/README.md +0 -126
  92. package/dist/components/rel-navbar/rel-navbar.ts +0 -105
  93. package/dist/components/rel-otp/index.ts +0 -1
  94. package/dist/components/rel-otp/rel-otp.ts +0 -517
  95. package/dist/components/rel-pagination/index.ts +0 -1
  96. package/dist/components/rel-pagination/rel-pagination.ts +0 -509
  97. package/dist/components/rel-popover/index.ts +0 -2
  98. package/dist/components/rel-popover/rel-popover-content.ts +0 -81
  99. package/dist/components/rel-popover/rel-popover.ts +0 -444
  100. package/dist/components/rel-progress/rel-progress.ts +0 -225
  101. package/dist/components/rel-radio/rel-radio.ts +0 -305
  102. package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1331
  103. package/dist/components/rel-resizable/index.ts +0 -3
  104. package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
  105. package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
  106. package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
  107. package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -213
  108. package/dist/components/rel-select/rel-select.ts +0 -1385
  109. package/dist/components/rel-sheet/rel-sheet.ts +0 -465
  110. package/dist/components/rel-sidebar/README.md +0 -209
  111. package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1185
  112. package/dist/components/rel-skeleton/rel-skeleton.ts +0 -134
  113. package/dist/components/rel-slider/rel-slider.ts +0 -670
  114. package/dist/components/rel-snackbar/rel-snackbar.ts +0 -325
  115. package/dist/components/rel-stepper/rel-stepper.ts +0 -565
  116. package/dist/components/rel-switch/rel-switch.ts +0 -197
  117. package/dist/components/rel-tab/rel-tab.ts +0 -264
  118. package/dist/components/rel-table/README.md +0 -178
  119. package/dist/components/rel-table/rel-table-body.ts +0 -22
  120. package/dist/components/rel-table/rel-table-caption.ts +0 -30
  121. package/dist/components/rel-table/rel-table-cell.ts +0 -43
  122. package/dist/components/rel-table/rel-table-footer.ts +0 -24
  123. package/dist/components/rel-table/rel-table-head.ts +0 -47
  124. package/dist/components/rel-table/rel-table-header.ts +0 -22
  125. package/dist/components/rel-table/rel-table-row.ts +0 -37
  126. package/dist/components/rel-table/rel-table.ts +0 -62
  127. package/dist/components/rel-textfield/rel-textfield.ts +0 -866
  128. package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1126
  129. package/dist/components/rel-toast/rel-toast.ts +0 -204
  130. package/dist/components/rel-tooltip/rel-tooltip.ts +0 -190
  131. package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
  132. package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
  133. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
  134. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
  135. package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
  136. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
  137. package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
  138. package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
  139. package/dist/components/rel-topbar/rel-topbar.ts +0 -446
  140. package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
  141. package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
  142. package/dist/components/rel-upload/rel-upload.ts +0 -943
@@ -1,700 +0,0 @@
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 = false;
12
- @property({ type: Boolean, attribute: "show-dots" }) showDots = false;
13
-
14
- /**
15
- * Figma "Type" axis. When set it drives which controls render:
16
- * default = content only · only-indicators = dots · side-arrows = overlaid
17
- * arrows + dots · bottom-arrows = dots flanked by arrows below the slide.
18
- * When unset, the legacy show-buttons/show-dots booleans apply unchanged.
19
- */
20
- @property({ type: String, reflect: true })
21
- type?: "default" | "only-indicators" | "side-arrows" | "bottom-arrows";
22
-
23
- @property({ type: String, reflect: true }) orientation: "horizontal" | "vertical" = "horizontal";
24
- @property({ type: String }) label: string = "Carousel";
25
- @property({ type: Number }) gap?: number;
26
- @property({ type: Boolean, reflect: true }) disabled = false;
27
-
28
- @state() private slideCount = 0;
29
- @state() private isDragging = false;
30
- @state() private dragStartX = 0;
31
- @state() private currentTranslate = 0;
32
- @state() private prevTranslate = 0;
33
-
34
- @query(".viewport") private viewport?: HTMLElement;
35
- @query(".track") private track?: HTMLElement;
36
- @query("slot") private slotElement?: HTMLSlotElement;
37
-
38
- private autoplayTimer?: number;
39
- private animationId?: number;
40
- private prefersReducedMotion = false;
41
- // Number of clone slides prepended before the real slides
42
- private clonesBefore = 0;
43
- private _silentJumping = false;
44
- private _ro?: ResizeObserver;
45
-
46
- static styles = css`
47
- :host {
48
- color: var(--rel-text-default);
49
- display: block;
50
- font-family: var(--rel-fonts-font-family);
51
- position: relative;
52
- user-select: none;
53
- }
54
-
55
- :host([disabled]) {
56
- opacity: 0.6;
57
- pointer-events: none;
58
- cursor: not-allowed;
59
- }
60
-
61
- .viewport {
62
- overflow: hidden;
63
- position: relative;
64
- width: 100%;
65
- display: block;
66
- }
67
-
68
- .track {
69
- display: flex;
70
- width: 100%;
71
- transition: transform 0.3s ease-out;
72
- will-change: transform;
73
- }
74
-
75
- /* Vertical orientation: column track inside a fixed-height viewport */
76
- :host([orientation="vertical"]) .viewport {
77
- height: var(--rel-carousel-height, 320px);
78
- }
79
-
80
- :host([orientation="vertical"]) .track {
81
- flex-direction: column;
82
- height: 100%;
83
- }
84
-
85
- :host([orientation="vertical"]) ::slotted(*) {
86
- width: 100% !important;
87
- height: var(--rel-carousel-slide-height, 100%) !important;
88
- }
89
-
90
- .track.dragging {
91
- transition: none;
92
- }
93
-
94
- .track.no-transition {
95
- transition: none;
96
- }
97
-
98
- ::slotted(*) {
99
- flex-shrink: 0 !important;
100
- width: var(--rel-carousel-slide-width, 100%) !important;
101
- min-width: 0 !important;
102
- box-sizing: border-box !important;
103
- }
104
-
105
- /* Clone slides injected for seamless loop */
106
- .carousel-clone {
107
- flex: 0 0 100%;
108
- min-width: 0;
109
- box-sizing: border-box;
110
- display: flex;
111
- align-items: center;
112
- justify-content: center;
113
- background: var(--rel-bg-neutral-elevated-1);
114
- }
115
-
116
- /* Default typography for slotted slide captions (Figma roles) */
117
- ::slotted(h1), ::slotted(h2), ::slotted(h3), ::slotted(h4) {
118
- font-family: var(--rel-headings-sm-font-family);
119
- font-weight: var(--rel-headings-sm-font-weight);
120
- font-size: var(--rel-headings-xs-font-size);
121
- line-height: var(--rel-headings-xs-line-height);
122
- letter-spacing: var(--rel-headings-xs-letter-spacing);
123
- margin: 0 0 var(--rel-spacing-2xs) 0;
124
- }
125
-
126
- ::slotted(p) {
127
- font-family: var(--rel-body-sm-regular-font-family);
128
- font-weight: var(--rel-body-sm-regular-font-weight);
129
- font-size: var(--rel-body-sm-regular-font-size);
130
- line-height: var(--rel-body-sm-regular-line-height);
131
- letter-spacing: var(--rel-body-sm-regular-letter-spacing);
132
- color: var(--rel-text-body);
133
- margin: 0 0 var(--rel-spacing-lg) 0;
134
- }
135
-
136
-
137
- /* Navigation buttons */
138
- .nav-button {
139
- position: absolute;
140
- top: 50%;
141
- transform: translateY(-50%);
142
- z-index: 10;
143
- width: var(--rel-carousel-nav-size, 40px);
144
- height: var(--rel-carousel-nav-size, 40px);
145
- border-radius: 50%;
146
- border: 1px solid var(--rel-border-default);
147
- background: var(--rel-bg-neutral);
148
- color: var(--rel-action-neutral-label-icons-ghost);
149
- cursor: pointer;
150
- display: flex;
151
- align-items: center;
152
- justify-content: center;
153
- transition: all 0.15s ease;
154
- box-shadow: var(--rel-shadows-shadow-100);
155
- }
156
-
157
- .nav-button:hover:not(:disabled) {
158
- background: var(--rel-bg-surface-elevated);
159
- }
160
-
161
- .nav-button:focus-visible {
162
- outline: 2px solid var(--rel-border-focus);
163
- outline-offset: 2px;
164
- }
165
-
166
- .nav-button:disabled {
167
- opacity: 0.4;
168
- cursor: not-allowed;
169
- }
170
-
171
- .nav-button.prev {
172
- left: var(--rel-spacing-sm);
173
- }
174
-
175
- .nav-button.next {
176
- right: var(--rel-spacing-sm);
177
- }
178
-
179
- /* Bottom arrows (Figma Type=Bottom Arrows): inline with the dots row */
180
- .dots .nav-button {
181
- position: static;
182
- transform: none;
183
- width: 32px;
184
- height: 32px;
185
- box-shadow: none;
186
- }
187
-
188
- .nav-button svg {
189
- width: 20px;
190
- height: 20px;
191
- }
192
-
193
- /* Dots indicator */
194
- .dots {
195
- display: flex;
196
- align-items: center;
197
- justify-content: center;
198
- gap: var(--rel-spacing-xs);
199
- margin-top: var(--rel-spacing-md);
200
- }
201
-
202
- .dot {
203
- width: var(--rel-carousel-dot-size, 8px);
204
- height: var(--rel-carousel-dot-size, 8px);
205
- border-radius: 50%;
206
- border: none;
207
- background: var(--rel-bg-neutral-elevated-2);
208
- cursor: pointer;
209
- padding: 0;
210
- transition: all 0.15s ease;
211
- }
212
-
213
- .dot:hover {
214
- background: var(--rel-bg-neutral-elevated-2);
215
- }
216
-
217
- .dot.active {
218
- background: var(--rel-bg-surface-brand);
219
- width: var(--rel-carousel-dot-size-active, 24px);
220
- border-radius: var(--rel-border-radius-xs);
221
- }
222
-
223
- .dot:focus-visible {
224
- outline: 2px solid var(--rel-border-focus);
225
- outline-offset: 2px;
226
- }
227
-
228
- /* Reduced motion support */
229
- @media (prefers-reduced-motion: reduce) {
230
- .track {
231
- transition: none;
232
- }
233
- }
234
-
235
- :host-context([data-theme="dark"]) .nav-button,
236
- :host-context(.dark) .nav-button {
237
- background: var(--rel-bg-surface-elevated);
238
- border-color: var(--rel-border-default);
239
- color: var(--rel-text-default);
240
- }
241
-
242
- :host-context([data-theme="dark"]) .nav-button:hover,
243
- :host-context(.dark) .nav-button:hover {
244
- background: var(--rel-bg-neutral-elevated-1);
245
- }
246
- `;
247
-
248
- connectedCallback() {
249
- super.connectedCallback();
250
- this.prefersReducedMotion = window.matchMedia(
251
- "(prefers-reduced-motion: reduce)"
252
- ).matches;
253
-
254
- // WCAG 2.2.2: auto-advance must pause while keyboard focus is inside the
255
- // carousel, not just on mouse hover.
256
- this.addEventListener("focusin", this.handleFocusIn);
257
- this.addEventListener("focusout", this.handleFocusOut);
258
-
259
- if (this.autoplay) {
260
- this.startAutoplay();
261
- }
262
- }
263
-
264
- firstUpdated() {
265
- const ro = new ResizeObserver(() => {
266
- const w = this.viewport?.offsetWidth ?? 0;
267
- const h = this.viewport?.offsetHeight ?? 0;
268
- if (w === 0 && h === 0) return;
269
- this.style.setProperty('--rel-carousel-slide-width', `${w}px`);
270
- this.style.setProperty('--rel-carousel-slide-height', `${h}px`);
271
- this.renderRoot.querySelectorAll('.carousel-clone').forEach(el => {
272
- if (this.vertical) (el as HTMLElement).style.height = `${h}px`;
273
- else (el as HTMLElement).style.width = `${w}px`;
274
- });
275
- this.updateTransform();
276
- });
277
- if (this.viewport) ro.observe(this.viewport);
278
- this._ro = ro;
279
-
280
- requestAnimationFrame(() => {
281
- const w = this.viewport?.offsetWidth ?? 0;
282
- const h = this.viewport?.offsetHeight ?? 0;
283
- if (w > 0 || h > 0) {
284
- this.style.setProperty('--rel-carousel-slide-width', `${w}px`);
285
- this.style.setProperty('--rel-carousel-slide-height', `${h}px`);
286
- this.updateTransform();
287
- }
288
- });
289
- }
290
-
291
- disconnectedCallback() {
292
- super.disconnectedCallback();
293
- this.removeEventListener("focusin", this.handleFocusIn);
294
- this.removeEventListener("focusout", this.handleFocusOut);
295
- this._ro?.disconnect();
296
- this.stopAutoplay();
297
- if (this.animationId) {
298
- cancelAnimationFrame(this.animationId);
299
- }
300
- }
301
-
302
- private handleSlotChange() {
303
- const slot = this.slotElement;
304
- const track = this.track;
305
- if (!slot || !track) return;
306
-
307
- const elements = slot.assignedElements();
308
- this.slideCount = elements.length;
309
-
310
- // Clamp value to valid real-slide range
311
- if (this.value >= this.slideCount) this.value = Math.max(0, this.slideCount - 1);
312
- if (this.value < 0) this.value = 0;
313
-
314
- // Remove any existing shadow-DOM clones
315
- track.querySelectorAll(".carousel-clone").forEach((el) => el.remove());
316
-
317
- const useClones = (this.loop || this.autoplay) && this.slideCount > 1;
318
-
319
- if (useClones) {
320
- this.clonesBefore = 1;
321
-
322
- const sizeClone = (clone: HTMLElement) => {
323
- if (this.vertical) clone.style.height = `${this.viewport?.offsetHeight ?? 0}px`;
324
- else clone.style.width = `${this.viewport?.offsetWidth ?? 0}px`;
325
- clone.style.boxSizing = 'border-box';
326
- };
327
-
328
- // Clone last slide → prepend before <slot>
329
- const lastEl = elements[this.slideCount - 1] as HTMLElement;
330
- const lastClone = lastEl.cloneNode(true) as HTMLElement;
331
- lastClone.classList.add("carousel-clone");
332
- lastClone.setAttribute("aria-hidden", "true");
333
- sizeClone(lastClone);
334
- track.insertBefore(lastClone, slot);
335
-
336
- // Clone first slide → append after <slot>
337
- const firstEl = elements[0] as HTMLElement;
338
- const firstClone = firstEl.cloneNode(true) as HTMLElement;
339
- firstClone.classList.add("carousel-clone");
340
- firstClone.setAttribute("aria-hidden", "true");
341
- sizeClone(firstClone);
342
- track.appendChild(firstClone);
343
- } else {
344
- this.clonesBefore = 0;
345
- }
346
-
347
- requestAnimationFrame(() => this.updateTransform());
348
-
349
- // If loop/autoplay clones were inserted but viewport has no width yet,
350
- // retry once after paint when dimensions are available
351
- if (useClones && this.unit() === 0) {
352
- requestAnimationFrame(() => {
353
- requestAnimationFrame(() => {
354
- this.handleSlotChange();
355
- });
356
- });
357
- }
358
- }
359
-
360
- private get vertical(): boolean {
361
- return this.orientation === "vertical";
362
- }
363
-
364
- /** Translate along the orientation axis. */
365
- private axisTransform(px: number): string {
366
- return this.vertical ? `translateY(${px}px)` : `translateX(${px}px)`;
367
- }
368
-
369
- private unit(): number {
370
- const slideSize = (this.vertical ? this.viewport?.offsetHeight : this.viewport?.offsetWidth) ?? 0;
371
- const gapValue = this.gap && this.gap > 0 ? this.gap : 0;
372
- return slideSize + gapValue;
373
- }
374
-
375
- private updateTransform() {
376
- if (!this.track || !this.viewport) return;
377
-
378
- const u = this.unit();
379
- const translate = -((this.value + this.clonesBefore) * u);
380
-
381
- this.currentTranslate = translate;
382
- this.prevTranslate = translate;
383
- this.track.style.transform = this.axisTransform(translate);
384
- this.track.style.gap = this.gap && this.gap > 0 ? `${this.gap}px` : "";
385
- }
386
-
387
- private goToPrevious() {
388
- if (this.disabled) return;
389
-
390
- if (this.value > 0) {
391
- this.value--;
392
- this.updateTransform();
393
- this.emitChange();
394
- } else if (this.clonesBefore > 0) {
395
- // Animate to the lastClone (position 0 in the track)
396
- const translate = 0;
397
- this.currentTranslate = translate;
398
- this.prevTranslate = translate;
399
- this.track!.style.transform = this.axisTransform(translate);
400
- this.track!.addEventListener(
401
- "transitionend",
402
- () => this.silentJump(this.slideCount - 1),
403
- { once: true }
404
- );
405
- }
406
- }
407
-
408
- private goToNext() {
409
- if (this.disabled) return;
410
-
411
- if (this.value < this.slideCount - 1) {
412
- this.value++;
413
- this.updateTransform();
414
- this.emitChange();
415
- } else if (this.clonesBefore > 0) {
416
- // Animate to the firstClone (one position past the last real slide)
417
- const cloneFirstPos = this.slideCount + this.clonesBefore;
418
- const translate = -(cloneFirstPos * this.unit());
419
- this.currentTranslate = translate;
420
- this.prevTranslate = translate;
421
- this.track!.style.transform = this.axisTransform(translate);
422
- this.track!.addEventListener(
423
- "transitionend",
424
- () => this.silentJump(0),
425
- { once: true }
426
- );
427
- }
428
- }
429
-
430
- // Silently reposition to newValue with no visible transition, then re-enable animation.
431
- private silentJump(newValue: number) {
432
- if (!this.track) return;
433
- this.track.classList.add("no-transition");
434
- this._silentJumping = true;
435
- this.value = newValue;
436
- this.updateTransform();
437
- this._silentJumping = false;
438
- requestAnimationFrame(() => {
439
- requestAnimationFrame(() => {
440
- this.track!.classList.remove("no-transition");
441
- });
442
- });
443
- this.emitChange();
444
- }
445
-
446
- private goToSlide(index: number) {
447
- if (this.disabled || index < 0 || index >= this.slideCount) return;
448
-
449
- this.value = index;
450
- this.updateTransform();
451
- this.emitChange();
452
- }
453
-
454
- private emitChange() {
455
- this.dispatchEvent(
456
- new CustomEvent("rel-change", {
457
- detail: { value: this.value },
458
- bubbles: true,
459
- composed: true,
460
- })
461
- );
462
- }
463
-
464
- private startAutoplay() {
465
- if (!this.autoplay || this.disabled) return;
466
-
467
- this.stopAutoplay();
468
- this.autoplayTimer = window.setInterval(() => {
469
- this.goToNext();
470
- }, this.interval);
471
- }
472
-
473
- private stopAutoplay() {
474
- if (this.autoplayTimer) {
475
- clearInterval(this.autoplayTimer);
476
- this.autoplayTimer = undefined;
477
- }
478
- }
479
-
480
- private handlePointerDown(e: PointerEvent) {
481
- if (this.disabled || !this.track) return;
482
-
483
- this.isDragging = true;
484
- this.dragStartX = this.vertical ? e.clientY : e.clientX;
485
- this.prevTranslate = this.currentTranslate;
486
-
487
- this.track.classList.add("dragging");
488
-
489
- if (this.autoplay && this.pauseOnHover) {
490
- this.stopAutoplay();
491
- }
492
-
493
- e.preventDefault();
494
- }
495
-
496
- private handlePointerMove(e: PointerEvent) {
497
- if (!this.isDragging || !this.track) return;
498
-
499
- const current = this.vertical ? e.clientY : e.clientX;
500
- const delta = current - this.dragStartX;
501
- this.currentTranslate = this.prevTranslate + delta;
502
-
503
- if (!this.prefersReducedMotion && this.animationId) {
504
- cancelAnimationFrame(this.animationId);
505
- }
506
-
507
- this.animationId = requestAnimationFrame(() => {
508
- if (this.track) {
509
- this.track.style.transform = this.axisTransform(this.currentTranslate);
510
- }
511
- });
512
- }
513
-
514
- private handlePointerUp(e: PointerEvent) {
515
- if (!this.isDragging || !this.track || !this.viewport) return;
516
-
517
- this.isDragging = false;
518
- this.track.classList.remove("dragging");
519
-
520
- const delta = (this.vertical ? e.clientY : e.clientX) - this.dragStartX;
521
- const slideSize = this.vertical ? this.viewport.offsetHeight : this.viewport.offsetWidth;
522
- const threshold = slideSize * 0.2; // 20% threshold
523
-
524
- if (Math.abs(delta) > threshold) {
525
- if (delta > 0 && (this.value > 0 || this.clonesBefore > 0)) {
526
- this.goToPrevious();
527
- } else if (delta < 0 && (this.value < this.slideCount - 1 || this.clonesBefore > 0)) {
528
- this.goToNext();
529
- } else {
530
- this.updateTransform();
531
- }
532
- } else {
533
- this.updateTransform();
534
- }
535
-
536
- if (this.autoplay) {
537
- this.startAutoplay();
538
- }
539
- }
540
-
541
- private handleKeyDown(e: KeyboardEvent) {
542
- if (this.disabled) return;
543
-
544
- switch (e.key) {
545
- case "ArrowLeft":
546
- case "ArrowUp":
547
- e.preventDefault();
548
- this.goToPrevious();
549
- break;
550
- case "ArrowRight":
551
- case "ArrowDown":
552
- e.preventDefault();
553
- this.goToNext();
554
- break;
555
- case "Home":
556
- e.preventDefault();
557
- this.goToSlide(0);
558
- break;
559
- case "End":
560
- e.preventDefault();
561
- this.goToSlide(this.slideCount - 1);
562
- break;
563
- }
564
- }
565
-
566
- private handleFocusIn = () => {
567
- if (this.autoplay) this.stopAutoplay();
568
- };
569
-
570
- private handleFocusOut = (e: FocusEvent) => {
571
- if (!this.autoplay) return;
572
- const next = e.relatedTarget as Node | null;
573
- // Resume only once focus has fully left the carousel (light or shadow).
574
- if (next && (this.contains(next) || this.shadowRoot?.contains(next))) return;
575
- this.startAutoplay();
576
- };
577
-
578
- private handleMouseEnter() {
579
- if (this.autoplay && this.pauseOnHover) {
580
- this.stopAutoplay();
581
- }
582
- }
583
-
584
- private handleMouseLeave() {
585
- if (this.autoplay && this.pauseOnHover) {
586
- this.startAutoplay();
587
- }
588
- }
589
-
590
- updated(changedProperties: Map<string, any>) {
591
- if (changedProperties.has("autoplay") || changedProperties.has("interval")) {
592
- if (this.autoplay) {
593
- this.startAutoplay();
594
- } else {
595
- this.stopAutoplay();
596
- }
597
- }
598
-
599
- // Only call updateTransform via Lit lifecycle for in-range values;
600
- // out-of-range transitions (clone positions) are managed directly.
601
- // Skip when _silentJumping — silentJump() calls updateTransform() itself.
602
- if (changedProperties.has("value") && !this._silentJumping && this.value >= 0 && this.value < this.slideCount) {
603
- this.updateTransform();
604
- }
605
- }
606
-
607
- /** Where nav arrows render, honouring the Figma type when set. */
608
- private get buttonPlacement(): "side" | "bottom" | "none" {
609
- if (this.type === "side-arrows") return "side";
610
- if (this.type === "bottom-arrows") return "bottom";
611
- if (this.type === "only-indicators" || this.type === "default") return "none";
612
- return this.showButtons ? "side" : "none";
613
- }
614
-
615
- private get dotsVisible(): boolean {
616
- if (this.type === "default") return false;
617
- if (this.type) return true;
618
- return this.showDots;
619
- }
620
-
621
- private renderNavButton(direction: "prev" | "next", enabled: boolean) {
622
- const path = direction === "prev" ? "M10 12L6 8L10 4" : "M6 4L10 8L6 12";
623
- return html`
624
- <button
625
- class="nav-button ${direction}"
626
- part="${direction}-button"
627
- aria-label="${direction === "prev" ? "Previous" : "Next"} slide"
628
- ?disabled=${!enabled || this.disabled}
629
- @click=${direction === "prev" ? this.goToPrevious : this.goToNext}
630
- >
631
- <svg viewBox="0 0 16 16" fill="none">
632
- <path
633
- d="${path}"
634
- stroke="currentColor"
635
- stroke-width="2"
636
- stroke-linecap="round"
637
- stroke-linejoin="round"
638
- />
639
- </svg>
640
- </button>
641
- `;
642
- }
643
-
644
- render() {
645
- const canGoPrev = this.clonesBefore > 0 || this.value > 0;
646
- const canGoNext = this.clonesBefore > 0 || this.value < this.slideCount - 1;
647
-
648
- return html`
649
- <div
650
- class="viewport"
651
- part="viewport"
652
- role="region"
653
- aria-roledescription="carousel"
654
- aria-label=${this.label}
655
- @keydown=${this.handleKeyDown}
656
- @mouseenter=${this.handleMouseEnter}
657
- @mouseleave=${this.handleMouseLeave}
658
- tabindex="0"
659
- >
660
- <div
661
- class="track"
662
- part="track"
663
- @pointerdown=${this.handlePointerDown}
664
- @pointermove=${this.handlePointerMove}
665
- @pointerup=${this.handlePointerUp}
666
- @pointercancel=${this.handlePointerUp}
667
- >
668
- <slot @slotchange=${this.handleSlotChange}></slot>
669
- </div>
670
-
671
- ${this.buttonPlacement === "side"
672
- ? html`
673
- ${this.renderNavButton("prev", canGoPrev)}
674
- ${this.renderNavButton("next", canGoNext)}
675
- `
676
- : nothing}
677
- </div>
678
-
679
- ${(this.dotsVisible || this.buttonPlacement === "bottom") && this.slideCount > 1
680
- ? html`
681
- <div class="dots" part="dots">
682
- ${this.buttonPlacement === "bottom" ? this.renderNavButton("prev", canGoPrev) : nothing}
683
- ${this.dotsVisible
684
- ? Array.from({ length: this.slideCount }, (_, i) => html`
685
- <button
686
- class="dot ${i === this.value ? "active" : ""}"
687
- part="dot"
688
- aria-label="Go to slide ${i + 1}"
689
- aria-current="${i === this.value ? "true" : nothing}"
690
- @click=${() => this.goToSlide(i)}
691
- ></button>
692
- `)
693
- : nothing}
694
- ${this.buttonPlacement === "bottom" ? this.renderNavButton("next", canGoNext) : nothing}
695
- </div>
696
- `
697
- : nothing}
698
- `;
699
- }
700
- }