@redvars/peacock 4.2.1 → 4.3.1

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 (254) hide show
  1. package/dist/{BaseField-D8ByB0l3.js → BaseField-CHBcjVc2.js} +3 -3
  2. package/dist/{BaseField-D8ByB0l3.js.map → BaseField-CHBcjVc2.js.map} +1 -1
  3. package/dist/{BaseInput-xCHvT4AN.js → BaseInput-DZp2O8Gh.js} +2 -2
  4. package/dist/{BaseInput-xCHvT4AN.js.map → BaseInput-DZp2O8Gh.js.map} +1 -1
  5. package/dist/ai-badge.js +2 -2
  6. package/dist/ai-summary.js +2 -2
  7. package/dist/alert.js +2 -2
  8. package/dist/anchor-nav.js +2 -2
  9. package/dist/app-shell.js +2 -2
  10. package/dist/assistant-panel.js +2 -2
  11. package/dist/assistant-step.js +2 -2
  12. package/dist/assistant-steps.js +2 -2
  13. package/dist/avatar-group.js +2 -2
  14. package/dist/banner.js +2 -2
  15. package/dist/{base-progress-DxNgAQtw.js → base-progress-CKQ32Ruw.js} +2 -2
  16. package/dist/{base-progress-DxNgAQtw.js.map → base-progress-CKQ32Ruw.js.map} +1 -1
  17. package/dist/bottom-sheet.js +2 -2
  18. package/dist/breadcrumb.js +2 -2
  19. package/dist/calendar.js +2 -2
  20. package/dist/{canvas-base-DHKf2CmA.js → canvas-base-BoKef3yr.js} +2 -2
  21. package/dist/{canvas-base-DHKf2CmA.js.map → canvas-base-BoKef3yr.js.map} +1 -1
  22. package/dist/carousel.js +644 -0
  23. package/dist/carousel.js.map +1 -0
  24. package/dist/{cartesian-chart-G6VX1aKk.js → cartesian-chart-DqZxnoG1.js} +2 -2
  25. package/dist/{cartesian-chart-G6VX1aKk.js.map → cartesian-chart-DqZxnoG1.js.map} +1 -1
  26. package/dist/{cb-group-base-BBDUgxne.js → cb-group-base-DHwx72Gt.js} +3 -1
  27. package/dist/{cb-group-base-BBDUgxne.js.map → cb-group-base-DHwx72Gt.js.map} +1 -1
  28. package/dist/{cb-group-base-CZLzCnXK.js → cb-group-base-DXnAJxEK.js} +3 -3
  29. package/dist/{cb-group-base-CZLzCnXK.js.map → cb-group-base-DXnAJxEK.js.map} +1 -1
  30. package/dist/cb-group.js +7 -4
  31. package/dist/cb-group.js.map +1 -1
  32. package/dist/cb-rule.js +3 -3
  33. package/dist/chart-area.js +4 -4
  34. package/dist/chart-bar.js +4 -4
  35. package/dist/{chart-base-DREru2P0.js → chart-base-ByCJM_9C.js} +2 -2
  36. package/dist/{chart-base-DREru2P0.js.map → chart-base-ByCJM_9C.js.map} +1 -1
  37. package/dist/chart-doughnut.js +3 -3
  38. package/dist/chart-line.js +4 -4
  39. package/dist/chart-pie.js +3 -3
  40. package/dist/chat-event.js +2 -2
  41. package/dist/chat-message.js +2 -2
  42. package/dist/chat-thread.js +2 -2
  43. package/dist/checkbox-group.js +3 -3
  44. package/dist/checkbox.js +3 -3
  45. package/dist/chip-set.js +2 -2
  46. package/dist/chip.js +2 -2
  47. package/dist/circular-progress.js +3 -3
  48. package/dist/citation.js +2 -2
  49. package/dist/code-editor.js +3 -3
  50. package/dist/code-highlighter.js +2 -2
  51. package/dist/color-field.js +4 -4
  52. package/dist/color-picker.js +2 -2
  53. package/dist/command-palette.js +2 -2
  54. package/dist/comment-composer.js +4 -4
  55. package/dist/condition-builder.js +4 -4
  56. package/dist/confirm-dialog.js +2 -2
  57. package/dist/copy-button.js +2 -2
  58. package/dist/currency-field.js +4 -4
  59. package/dist/custom-elements-jsdocs.json +902 -74
  60. package/dist/custom-elements.json +3301 -446
  61. package/dist/date-field.js +5 -5
  62. package/dist/date-picker.js +2 -2
  63. package/dist/date-range-field.js +5 -5
  64. package/dist/datetime-field.js +5 -5
  65. package/dist/dependency-map.js +3 -3
  66. package/dist/description-item.js +2 -2
  67. package/dist/description-list.js +2 -2
  68. package/dist/{diagram-CHF70xTL.js → diagram-Cnrj-4y3.js} +2 -2
  69. package/dist/{diagram-CHF70xTL.js.map → diagram-Cnrj-4y3.js.map} +1 -1
  70. package/dist/diagram-controls.js +2 -2
  71. package/dist/diagram-minimap.js +2 -2
  72. package/dist/diagram.js +4 -4
  73. package/dist/diff-viewer.js +2 -2
  74. package/dist/discussion-activity.js +2 -2
  75. package/dist/discussion-comment.js +2 -2
  76. package/dist/discussion.js +4 -4
  77. package/dist/{document-editor-Cb9fCxvA.js → document-editor-C8ThjDQ7.js} +2 -2
  78. package/dist/{document-editor-Cb9fCxvA.js.map → document-editor-C8ThjDQ7.js.map} +1 -1
  79. package/dist/document-editor.js +3 -3
  80. package/dist/draft-card.js +2 -2
  81. package/dist/erd.js +3 -3
  82. package/dist/file-upload.js +3 -3
  83. package/dist/filter-bar.js +2 -2
  84. package/dist/flow.js +4 -4
  85. package/dist/form.js +2 -2
  86. package/dist/{generative-view-C4fJ2zI7.js → generative-view-CQ8-g1wY.js} +2 -2
  87. package/dist/{generative-view-C4fJ2zI7.js.map → generative-view-CQ8-g1wY.js.map} +1 -1
  88. package/dist/generative-view.js +3 -3
  89. package/dist/highlight-Be0wu7kh.js +252 -0
  90. package/dist/highlight-Be0wu7kh.js.map +1 -0
  91. package/dist/highlight.js +6 -0
  92. package/dist/highlight.js.map +1 -0
  93. package/dist/html-editor.js +4 -4
  94. package/dist/{i18n-controller-CH4e9sju.js → i18n-controller-DLJcJ5gO.js} +2 -2
  95. package/dist/{i18n-controller-CH4e9sju.js.map → i18n-controller-DLJcJ5gO.js.map} +1 -1
  96. package/dist/image.js +2 -2
  97. package/dist/index.js +27 -17
  98. package/dist/index.js.map +1 -1
  99. package/dist/inline-edit.js +2 -2
  100. package/dist/input.js +3 -3
  101. package/dist/json-viewer.js +2 -2
  102. package/dist/kanban.js +2 -2
  103. package/dist/kbd.js +2 -2
  104. package/dist/linear-progress.js +3 -3
  105. package/dist/listbox.js +2 -2
  106. package/dist/loader-full.js +19 -9
  107. package/dist/loader-full.js.map +1 -1
  108. package/dist/loader.js +46 -9
  109. package/dist/loader.js.map +1 -1
  110. package/dist/markdown-editor.js +4 -4
  111. package/dist/mention-input.js +4 -4
  112. package/dist/modal.js +2 -2
  113. package/dist/navigation-bar.js +2 -2
  114. package/dist/navigation-drawer.js +2 -2
  115. package/dist/navigation-rail.js +2 -2
  116. package/dist/notification-center.js +2 -2
  117. package/dist/number-field.js +4 -4
  118. package/dist/page-header.js +2 -2
  119. package/dist/pagination.js +2 -2
  120. package/dist/password-field.js +4 -4
  121. package/dist/password-rules.js +2 -2
  122. package/dist/phone-field.js +4 -4
  123. package/dist/{picker-field-loXW-xrW.js → picker-field-B5xOFc3-.js} +3 -3
  124. package/dist/{picker-field-loXW-xrW.js.map → picker-field-B5xOFc3-.js.map} +1 -1
  125. package/dist/pin-input.js +4 -4
  126. package/dist/presence-indicator.js +2 -2
  127. package/dist/prompt-input.js +4 -4
  128. package/dist/radio.js +3 -3
  129. package/dist/rating.js +3 -3
  130. package/dist/redvars-loader.js +2 -2
  131. package/dist/relative-time.js +2 -2
  132. package/dist/resizable-panels.js +2 -2
  133. package/dist/{rich-text-input-B5j0eqCJ.js → rich-text-input-C4B9D6oD.js} +3 -3
  134. package/dist/{rich-text-input-B5j0eqCJ.js.map → rich-text-input-C4B9D6oD.js.map} +1 -1
  135. package/dist/{schema-BJzlGRP1.js → schema-CPhNrjrx.js} +2 -2
  136. package/dist/{schema-BJzlGRP1.js.map → schema-CPhNrjrx.js.map} +1 -1
  137. package/dist/search.js +3 -3
  138. package/dist/select.js +4 -4
  139. package/dist/side-sheet.js +2 -2
  140. package/dist/signature-pad.js +3 -3
  141. package/dist/site-footer-group.js +142 -0
  142. package/dist/site-footer-group.js.map +1 -0
  143. package/dist/site-footer.js +338 -0
  144. package/dist/site-footer.js.map +1 -0
  145. package/dist/site-header.js +774 -0
  146. package/dist/site-header.js.map +1 -0
  147. package/dist/site-nav-group.js +123 -0
  148. package/dist/site-nav-group.js.map +1 -0
  149. package/dist/site-nav-link.js +321 -0
  150. package/dist/site-nav-link.js.map +1 -0
  151. package/dist/site-nav-menu.js +506 -0
  152. package/dist/site-nav-menu.js.map +1 -0
  153. package/dist/site-nav-shared-BDR2HG8e.js +23 -0
  154. package/dist/site-nav-shared-BDR2HG8e.js.map +1 -0
  155. package/dist/slider.js +3 -3
  156. package/dist/snackbar.js +2 -2
  157. package/dist/sparkline.js +2 -2
  158. package/dist/split-button.js +2 -2
  159. package/dist/src/__internal/i18n/strings.d.ts +24 -0
  160. package/dist/src/carousel/carousel.d.ts +135 -0
  161. package/dist/src/carousel/index.d.ts +1 -0
  162. package/dist/src/highlight/highlight.d.ts +56 -0
  163. package/dist/src/highlight/index.d.ts +2 -0
  164. package/dist/src/highlight/matches.d.ts +9 -0
  165. package/dist/src/index.d.ts +9 -0
  166. package/dist/src/site-footer/index.d.ts +2 -0
  167. package/dist/src/site-footer/site-footer-group.d.ts +34 -0
  168. package/dist/src/site-footer/site-footer.d.ts +74 -0
  169. package/dist/src/site-header/index.d.ts +4 -0
  170. package/dist/src/site-header/site-header.d.ts +170 -0
  171. package/dist/src/site-header/site-nav-group.d.ts +32 -0
  172. package/dist/src/site-header/site-nav-link.d.ts +65 -0
  173. package/dist/src/site-header/site-nav-menu.d.ts +104 -0
  174. package/dist/src/site-header/site-nav-shared.d.ts +13 -0
  175. package/dist/src/table/table.d.ts +5 -0
  176. package/dist/src/video/index.d.ts +2 -0
  177. package/dist/src/video/video-source.d.ts +12 -0
  178. package/dist/src/video/video.d.ts +80 -0
  179. package/dist/stat.js +2 -2
  180. package/dist/status-indicator.js +2 -2
  181. package/dist/step.js +2 -2
  182. package/dist/stepper.js +2 -2
  183. package/dist/{strings-o6v6Hrmn.js → strings-MXyrGrNs.js} +28 -1
  184. package/dist/strings-MXyrGrNs.js.map +1 -0
  185. package/dist/svg.js +2 -2
  186. package/dist/switch.js +3 -3
  187. package/dist/table.js +53 -10
  188. package/dist/table.js.map +1 -1
  189. package/dist/test/carousel.test.d.ts +1 -0
  190. package/dist/test/highlight.test.d.ts +1 -0
  191. package/dist/test/site-footer.test.d.ts +1 -0
  192. package/dist/test/site-header.test.d.ts +1 -0
  193. package/dist/test/video.test.d.ts +1 -0
  194. package/dist/textarea.js +4 -4
  195. package/dist/time-field.js +5 -5
  196. package/dist/time-picker.js +2 -2
  197. package/dist/timeline-item.js +2 -2
  198. package/dist/timeline.js +2 -2
  199. package/dist/{toggle-base-BSzBnLZN.js → toggle-base-I1wE_fVe.js} +2 -2
  200. package/dist/{toggle-base-BSzBnLZN.js.map → toggle-base-I1wE_fVe.js.map} +1 -1
  201. package/dist/tour.js +2 -2
  202. package/dist/transfer-list.js +3 -3
  203. package/dist/tree-chart.js +3 -3
  204. package/dist/tree-item.js +2 -2
  205. package/dist/tree.js +2 -2
  206. package/dist/tsconfig.tsbuildinfo +1 -1
  207. package/dist/typing-indicator.js +2 -2
  208. package/dist/url-field.js +4 -4
  209. package/dist/user-menu.js +2 -2
  210. package/dist/video-IwNmHyft.js +509 -0
  211. package/dist/video-IwNmHyft.js.map +1 -0
  212. package/dist/video.js +12 -0
  213. package/dist/video.js.map +1 -0
  214. package/dist/virtual-list.js +2 -2
  215. package/dist/workflow-timeline.js +2 -2
  216. package/dist/workflow.js +3 -3
  217. package/dist/workspace-switcher.js +2 -2
  218. package/package.json +1 -1
  219. package/readme.md +5 -0
  220. package/src/__internal/i18n/strings.ts +31 -0
  221. package/src/carousel/carousel.scss +124 -0
  222. package/src/carousel/carousel.ts +547 -0
  223. package/src/carousel/index.ts +1 -0
  224. package/src/condition-builder/cb-group-base.scss +5 -1
  225. package/src/condition-builder/cb-group-base.ts +1 -1
  226. package/src/condition-builder/cb-group.scss +4 -0
  227. package/src/highlight/highlight.scss +25 -0
  228. package/src/highlight/highlight.ts +123 -0
  229. package/src/highlight/index.ts +2 -0
  230. package/src/highlight/matches.ts +94 -0
  231. package/src/index.ts +18 -0
  232. package/src/loader.ts +36 -0
  233. package/src/site-footer/index.ts +2 -0
  234. package/src/site-footer/site-footer-group.scss +53 -0
  235. package/src/site-footer/site-footer-group.ts +52 -0
  236. package/src/site-footer/site-footer.scss +171 -0
  237. package/src/site-footer/site-footer.ts +151 -0
  238. package/src/site-header/index.ts +8 -0
  239. package/src/site-header/site-header.scss +238 -0
  240. package/src/site-header/site-header.ts +565 -0
  241. package/src/site-header/site-nav-group.scss +29 -0
  242. package/src/site-header/site-nav-group.ts +57 -0
  243. package/src/site-header/site-nav-link.scss +154 -0
  244. package/src/site-header/site-nav-link.ts +140 -0
  245. package/src/site-header/site-nav-menu.scss +182 -0
  246. package/src/site-header/site-nav-menu.ts +336 -0
  247. package/src/site-header/site-nav-shared.ts +27 -0
  248. package/src/table/table.scss +52 -2
  249. package/src/table/table.ts +20 -6
  250. package/src/video/index.ts +2 -0
  251. package/src/video/video-source.ts +80 -0
  252. package/src/video/video.scss +183 -0
  253. package/src/video/video.ts +246 -0
  254. package/dist/strings-o6v6Hrmn.js.map +0 -1
@@ -0,0 +1,547 @@
1
+ import { html, LitElement, nothing, type PropertyValues } from 'lit';
2
+ import { property, query, state } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { styleMap } from 'lit/directives/style-map.js';
5
+ import IndividualComponent from '@/IndividualComponent.js';
6
+ import { I18nController } from '@/__internal/i18n/i18n-controller.js';
7
+ import { isRtl } from '@/__internal/i18n/locale.js';
8
+ import styles from './carousel.scss';
9
+
10
+ /** Detail of the `change` event. */
11
+ export interface CarouselChangeDetail {
12
+ /** The first slide in view, from 0. */
13
+ index: number;
14
+ }
15
+
16
+ /** A slide is never drawn narrower than this, so `per-view` drops on narrow screens. */
17
+ const MIN_SLIDE_WIDTH = 240;
18
+
19
+ /** With more pages than this, a "3 of 9" counter replaces the picker buttons. */
20
+ const MAX_PICKERS = 7;
21
+
22
+ /** How long the track must be still before a scroll counts as settled, in milliseconds. */
23
+ const SETTLE_DELAY = 100;
24
+
25
+ /** Marks a slide name the carousel wrote, so it can rewrite it and leave the app's own alone. */
26
+ const OWN_LABEL = 'data-carousel-label';
27
+
28
+ /**
29
+ * @label Carousel
30
+ * @tag wc-carousel
31
+ * @rawTag carousel
32
+ *
33
+ * @summary A row of slides shown one or a few at a time, with previous and next buttons and pickers.
34
+ * @overview
35
+ * <p>Carousel shows its children as slides, <code>per-view</code> at a time, for screenshots on a
36
+ * product page or a row of testimonials. The slides scroll with snap points, so touch swipe,
37
+ * trackpads and the scroll wheel work as they do anywhere else, and previous, next and picker
38
+ * buttons sit under them. With more than seven pages a "3 of 9" counter replaces the pickers.</p>
39
+ * <p>Each slide is never narrower than 15rem, so a carousel of three drops to two and then one as its
40
+ * container narrows. Slides out of view are <code>inert</code>, so Tab never reaches a link the
41
+ * person cannot see.</p>
42
+ * <p>Slides do not move on their own unless you set <code>autoplay</code>, and then a button to stop
43
+ * them comes first in the controls. Rotation pauses while the pointer rests on the carousel or focus
44
+ * is inside it, stops for good when the person uses any control, and does not start at all when the
45
+ * person asks for reduced motion.</p>
46
+ *
47
+ * @slot - The slides: any elements, one per slide. Give a slide an `aria-label` to name it; otherwise it is named "2 of 5".
48
+ *
49
+ * @csspart base - The carousel region.
50
+ * @csspart track - The scrolling row of slides.
51
+ * @csspart controls - The row of buttons under the slides.
52
+ *
53
+ * @cssprop --carousel-gap - Space between slides. Defaults to `--spacing-200`.
54
+ *
55
+ * @fires {CustomEvent<CarouselChangeDetail>} change - Dispatched when the slides in view change because the person used a control or scrolled, or autoplay moved on.
56
+ *
57
+ * @example
58
+ * ```html
59
+ * <wc-carousel label="Testimonials" per-view="3">
60
+ * <blockquote>We moved our incident process off spreadsheets in a week.</blockquote>
61
+ * <blockquote>Our customer portal runs on the same rules as the agents' workspace.</blockquote>
62
+ * <blockquote>Self-hosting took one command and a coffee.</blockquote>
63
+ * </wc-carousel>
64
+ * ```
65
+ * @example
66
+ * ```html
67
+ * <wc-carousel label="Product screenshots" autoplay loop>
68
+ * <img src="/img/workspace.webp" alt="The ITSM workspace" />
69
+ * <img src="/img/portal.webp" alt="The customer portal" />
70
+ * </wc-carousel>
71
+ * ```
72
+ * @tags media layout
73
+ */
74
+ @IndividualComponent
75
+ export class Carousel extends LitElement {
76
+ // ── Static ───────────────────────────────────────────────────────────────
77
+
78
+ static styles = [styles];
79
+
80
+ // ── Properties ───────────────────────────────────────────────────────────
81
+
82
+ /** What the slides are, such as "Testimonials": the name of the carousel region. */
83
+ @property({ reflect: true })
84
+ label = '';
85
+
86
+ /** How many slides show at once. Fewer show when the carousel is too narrow for them. */
87
+ @property({ type: Number, attribute: 'per-view', reflect: true })
88
+ perView = 1;
89
+
90
+ /** The first slide in view, from 0. */
91
+ @property({ type: Number, reflect: true })
92
+ index = 0;
93
+
94
+ /** Whether previous and next wrap around from the last page to the first and back. */
95
+ @property({ type: Boolean, reflect: true })
96
+ loop = false;
97
+
98
+ /** Whether the slides move on by themselves. A stop button comes first in the controls. */
99
+ @property({ type: Boolean, reflect: true })
100
+ autoplay = false;
101
+
102
+ /** How long each page shows while `autoplay` runs, in milliseconds. */
103
+ @property({ type: Number })
104
+ interval = 5000;
105
+
106
+ // ── State ────────────────────────────────────────────────────────────────
107
+
108
+ @state() private slideCount = 0;
109
+
110
+ /** How many slides fit: `per-view`, or fewer when the carousel is narrow. */
111
+ @state() private visible = 1;
112
+
113
+ /** Whether autoplay rotates the slides: off once the person stops it or uses a control. */
114
+ @state() private rotating = false;
115
+
116
+ /** Whether the pointer or focus is inside, which pauses rotation. */
117
+ @state() private held = false;
118
+
119
+ // ── Queries ──────────────────────────────────────────────────────────────
120
+
121
+ @query('.track') private readonly track?: HTMLElement;
122
+
123
+ // ── Private fields ───────────────────────────────────────────────────────
124
+
125
+ private readonly i18n = new I18nController(this);
126
+
127
+ private slides: HTMLElement[] = [];
128
+
129
+ /** Whether the person started rotation with the button, so hover and focus no longer pause it. */
130
+ private startedByPerson = false;
131
+
132
+ /** Whether the person stopped rotation or used a control, so autoplay never starts again. */
133
+ private stoppedByPerson = false;
134
+
135
+ /** Whether the next `index` update came from scrolling, so it needs no scroll of its own. */
136
+ private indexFromScroll = false;
137
+
138
+ /** Whether the next scroll to `index` is animated. */
139
+ private smoothScroll = false;
140
+
141
+ private timer?: ReturnType<typeof setInterval>;
142
+
143
+ private settleTimer?: ReturnType<typeof setTimeout>;
144
+
145
+ private readonly resizeObserver = new ResizeObserver(() =>
146
+ this.syncVisible(),
147
+ );
148
+
149
+ private readonly reducedMotion = window.matchMedia(
150
+ '(prefers-reduced-motion: reduce)',
151
+ );
152
+
153
+ // ── Lifecycle ────────────────────────────────────────────────────────────
154
+
155
+ override connectedCallback() {
156
+ super.connectedCallback();
157
+ this.addEventListener('pointerenter', this.handlePointerEnter);
158
+ this.addEventListener('pointerleave', this.handlePointerLeave);
159
+ this.addEventListener('focusin', this.handleFocusIn);
160
+ this.addEventListener('focusout', this.handleFocusOut);
161
+ }
162
+
163
+ override disconnectedCallback() {
164
+ this.removeEventListener('pointerenter', this.handlePointerEnter);
165
+ this.removeEventListener('pointerleave', this.handlePointerLeave);
166
+ this.removeEventListener('focusin', this.handleFocusIn);
167
+ this.removeEventListener('focusout', this.handleFocusOut);
168
+ this.resizeObserver.disconnect();
169
+ this.stopTimer();
170
+ clearTimeout(this.settleTimer);
171
+ super.disconnectedCallback();
172
+ }
173
+
174
+ protected override willUpdate(changed: PropertyValues<this>) {
175
+ super.willUpdate(changed);
176
+ if (changed.has('autoplay')) {
177
+ this.rotating =
178
+ this.autoplay && !this.stoppedByPerson && !this.reducedMotion.matches;
179
+ }
180
+ const clamped = this.clamp(this.index);
181
+ if (clamped !== this.index) this.index = clamped;
182
+ }
183
+
184
+ protected override firstUpdated() {
185
+ if (this.track) this.resizeObserver.observe(this.track);
186
+ }
187
+
188
+ // Untyped, because it reads private state.
189
+ protected override updated(changed: PropertyValues) {
190
+ super.updated(changed);
191
+ if (
192
+ changed.has('index') ||
193
+ changed.has('visible') ||
194
+ changed.has('slideCount')
195
+ ) {
196
+ this.syncSlides();
197
+ }
198
+ if (changed.has('index') && !this.indexFromScroll) {
199
+ this.scrollToIndex(this.smoothScroll);
200
+ }
201
+ this.indexFromScroll = false;
202
+ this.smoothScroll = false;
203
+ this.syncTimer();
204
+ }
205
+
206
+ // ── Public methods ───────────────────────────────────────────────────────
207
+
208
+ /** Shows the page after the current one, or the first after the last when `loop` is set. */
209
+ next() {
210
+ this.goToPage(this.page + 1, this.loop);
211
+ }
212
+
213
+ /** Shows the page before the current one, or the last before the first when `loop` is set. */
214
+ previous() {
215
+ this.goToPage(this.page - 1, this.loop);
216
+ }
217
+
218
+ /** Scrolls the slide at `index`, from 0, into the first place in view. */
219
+ goTo(index: number) {
220
+ this.moveTo(index);
221
+ }
222
+
223
+ // ── Private methods ──────────────────────────────────────────────────────
224
+
225
+ /** The first slide index that still fills the view. */
226
+ private get maxStart() {
227
+ return Math.max(0, this.slideCount - this.visible);
228
+ }
229
+
230
+ private get pageCount() {
231
+ return Math.max(1, Math.ceil(this.slideCount / this.visible));
232
+ }
233
+
234
+ /** The page in view: the last one once the view reaches the end. */
235
+ private get page() {
236
+ if (this.index >= this.maxStart) return this.pageCount - 1;
237
+ return Math.floor(this.index / this.visible);
238
+ }
239
+
240
+ private pageStart(page: number) {
241
+ return Math.min(page * this.visible, this.maxStart);
242
+ }
243
+
244
+ private clamp(index: number) {
245
+ return Math.min(Math.max(0, Math.round(index) || 0), this.maxStart);
246
+ }
247
+
248
+ private goToPage(page: number, wrap: boolean) {
249
+ const last = this.pageCount - 1;
250
+ let target = page;
251
+ if (target > last) target = wrap ? 0 : last;
252
+ if (target < 0) target = wrap ? last : 0;
253
+ this.moveTo(this.pageStart(target));
254
+ }
255
+
256
+ private moveTo(index: number) {
257
+ const target = this.clamp(index);
258
+ if (target === this.index) return;
259
+ this.smoothScroll = true;
260
+ this.index = target;
261
+ this.dispatchChange();
262
+ }
263
+
264
+ private dispatchChange() {
265
+ this.dispatchEvent(
266
+ new CustomEvent<CarouselChangeDetail>('change', {
267
+ detail: { index: this.index },
268
+ }),
269
+ );
270
+ }
271
+
272
+ private syncVisible() {
273
+ const { track } = this;
274
+ if (!track) return;
275
+ const gap = parseFloat(getComputedStyle(track).columnGap) || 0;
276
+ const fit = Math.floor((track.clientWidth + gap) / (MIN_SLIDE_WIDTH + gap));
277
+ const visible = Math.max(1, Math.min(Math.floor(this.perView) || 1, fit));
278
+ if (visible !== this.visible) this.visible = visible;
279
+ }
280
+
281
+ /** Names each slide and makes the ones out of view inert. */
282
+ private syncSlides() {
283
+ const total = String(this.slides.length);
284
+ const label = this.i18n.t('carouselSlideLabel');
285
+ this.slides.forEach((slide, i) => {
286
+ slide.setAttribute('role', 'group');
287
+ slide.setAttribute(
288
+ 'aria-roledescription',
289
+ this.i18n.t('carouselSlideRole'),
290
+ );
291
+ const named =
292
+ slide.hasAttribute('aria-labelledby') ||
293
+ (slide.hasAttribute('aria-label') && !slide.hasAttribute(OWN_LABEL));
294
+ if (!named) {
295
+ slide.setAttribute('aria-label', label(String(i + 1), total));
296
+ slide.setAttribute(OWN_LABEL, '');
297
+ }
298
+ const inView = i >= this.index && i < this.index + this.visible;
299
+ slide.toggleAttribute('inert', !inView);
300
+ });
301
+ }
302
+
303
+ private scrollToIndex(smooth: boolean) {
304
+ const { track } = this;
305
+ const slide = this.slides[this.index];
306
+ if (!track || !slide) return;
307
+ const trackBox = track.getBoundingClientRect();
308
+ const slideBox = slide.getBoundingClientRect();
309
+ const delta = isRtl(this)
310
+ ? slideBox.right - trackBox.right
311
+ : slideBox.left - trackBox.left;
312
+ if (Math.abs(delta) < 1) return;
313
+ track.scrollBy({
314
+ left: delta,
315
+ behavior: smooth && !this.reducedMotion.matches ? 'smooth' : 'instant',
316
+ });
317
+ }
318
+
319
+ /** The slide nearest the start edge of the track. */
320
+ private nearestIndex() {
321
+ const { track } = this;
322
+ if (!track || !this.slides.length) return 0;
323
+ const trackBox = track.getBoundingClientRect();
324
+ const rtl = isRtl(this);
325
+ let nearest = 0;
326
+ let best = Infinity;
327
+ this.slides.forEach((slide, i) => {
328
+ const box = slide.getBoundingClientRect();
329
+ const distance = Math.abs(
330
+ rtl ? box.right - trackBox.right : box.left - trackBox.left,
331
+ );
332
+ if (distance < best) {
333
+ best = distance;
334
+ nearest = i;
335
+ }
336
+ });
337
+ return nearest;
338
+ }
339
+
340
+ private get shouldRotate() {
341
+ return (
342
+ this.rotating &&
343
+ this.pageCount > 1 &&
344
+ (this.startedByPerson || !this.held)
345
+ );
346
+ }
347
+
348
+ private syncTimer() {
349
+ if (this.shouldRotate && this.isConnected) {
350
+ if (this.timer === undefined) {
351
+ this.timer = setInterval(
352
+ () => this.advance(),
353
+ Math.max(1000, this.interval),
354
+ );
355
+ }
356
+ } else {
357
+ this.stopTimer();
358
+ }
359
+ }
360
+
361
+ private stopTimer() {
362
+ clearInterval(this.timer);
363
+ this.timer = undefined;
364
+ }
365
+
366
+ private advance() {
367
+ this.goToPage(this.page + 1, true);
368
+ }
369
+
370
+ /** The person took over: autoplay stops and does not start again. */
371
+ private stopRotation() {
372
+ this.rotating = false;
373
+ this.stoppedByPerson = true;
374
+ this.startedByPerson = false;
375
+ }
376
+
377
+ // ── Event handlers ───────────────────────────────────────────────────────
378
+
379
+ private readonly handleSlotChange = (event: Event) => {
380
+ const slot = event.target as HTMLSlotElement;
381
+ const slides = slot
382
+ .assignedElements()
383
+ .filter((el): el is HTMLElement => el instanceof HTMLElement);
384
+ this.slides
385
+ .filter(slide => !slides.includes(slide))
386
+ .forEach(slide => slide.removeAttribute('inert'));
387
+ this.slides = slides;
388
+ this.slideCount = slides.length;
389
+ this.syncSlides();
390
+ };
391
+
392
+ private readonly handleScroll = () => {
393
+ clearTimeout(this.settleTimer);
394
+ this.settleTimer = setTimeout(() => {
395
+ const index = this.clamp(this.nearestIndex());
396
+ if (index === this.index) return;
397
+ this.indexFromScroll = true;
398
+ this.index = index;
399
+ this.dispatchChange();
400
+ }, SETTLE_DELAY);
401
+ };
402
+
403
+ // The ends' buttons are soft-disabled, which keeps them focusable but sends no click.
404
+ private readonly handlePrevious = () => {
405
+ this.stopRotation();
406
+ this.previous();
407
+ };
408
+
409
+ private readonly handleNext = () => {
410
+ this.stopRotation();
411
+ this.next();
412
+ };
413
+
414
+ private handlePicker(page: number) {
415
+ this.stopRotation();
416
+ this.goToPage(page, false);
417
+ }
418
+
419
+ private readonly handleRotation = () => {
420
+ if (this.rotating) {
421
+ this.stopRotation();
422
+ } else {
423
+ this.rotating = true;
424
+ this.stoppedByPerson = false;
425
+ this.startedByPerson = true;
426
+ }
427
+ };
428
+
429
+ private readonly handlePointerEnter = (event: PointerEvent) => {
430
+ if (event.pointerType === 'mouse') this.held = true;
431
+ };
432
+
433
+ private readonly handlePointerLeave = () => {
434
+ if (!this.matches(':focus-within')) this.held = false;
435
+ };
436
+
437
+ private readonly handleFocusIn = () => {
438
+ this.held = true;
439
+ };
440
+
441
+ private readonly handleFocusOut = (event: FocusEvent) => {
442
+ const next = event.relatedTarget as Node | null;
443
+ if (!next || !this.contains(next)) {
444
+ if (!this.matches(':hover')) this.held = false;
445
+ }
446
+ };
447
+
448
+ // ── Render helpers ───────────────────────────────────────────────────────
449
+
450
+ private renderPickers() {
451
+ const pages = this.pageCount;
452
+ const { page } = this;
453
+ if (pages > MAX_PICKERS) {
454
+ return html`<span class="counter"
455
+ >${this.i18n.t('carouselCounter')(
456
+ String(page + 1),
457
+ String(pages),
458
+ )}</span
459
+ >`;
460
+ }
461
+ const picker = this.i18n.t('carouselPicker');
462
+ const total = String(this.slideCount);
463
+ return html`<div
464
+ class="pickers"
465
+ role="group"
466
+ aria-label=${this.i18n.t('chooseSlide')}
467
+ >
468
+ ${Array.from({ length: pages }, (_, p) => {
469
+ const first = this.pageStart(p);
470
+ const last = Math.min(first + this.visible, this.slideCount);
471
+ const current = p === page;
472
+ return html`<button
473
+ class=${classMap({ picker: true, current })}
474
+ type="button"
475
+ aria-label=${picker(String(first + 1), String(last), total)}
476
+ aria-current=${current ? 'true' : nothing}
477
+ @click=${() => this.handlePicker(p)}
478
+ ></button>`;
479
+ })}
480
+ </div>`;
481
+ }
482
+
483
+ private renderControls() {
484
+ if (this.pageCount < 2) return nothing;
485
+ const atStart = !this.loop && this.page === 0;
486
+ const atEnd = !this.loop && this.page === this.pageCount - 1;
487
+ return html`<div class="controls" part="controls">
488
+ ${this.autoplay
489
+ ? html`<wc-icon-button
490
+ class="rotation"
491
+ variant="text"
492
+ shape="round"
493
+ aria-label=${this.rotating
494
+ ? this.i18n.t('stopSlideRotation')
495
+ : this.i18n.t('startSlideRotation')}
496
+ @click=${this.handleRotation}
497
+ >
498
+ <wc-icon name=${this.rotating ? 'pause' : 'play_arrow'}></wc-icon>
499
+ </wc-icon-button>`
500
+ : nothing}
501
+ <wc-icon-button
502
+ class="previous"
503
+ variant="tonal"
504
+ shape="round"
505
+ aria-label=${this.i18n.t('previousSlide')}
506
+ ?soft-disabled=${atStart}
507
+ @click=${this.handlePrevious}
508
+ >
509
+ <wc-icon class="chevron" name="chevron_left"></wc-icon>
510
+ </wc-icon-button>
511
+ ${this.renderPickers()}
512
+ <wc-icon-button
513
+ class="next"
514
+ variant="tonal"
515
+ shape="round"
516
+ aria-label=${this.i18n.t('nextSlide')}
517
+ ?soft-disabled=${atEnd}
518
+ @click=${this.handleNext}
519
+ >
520
+ <wc-icon class="chevron" name="chevron_right"></wc-icon>
521
+ </wc-icon-button>
522
+ </div>`;
523
+ }
524
+
525
+ // ── Render ───────────────────────────────────────────────────────────────
526
+
527
+ render() {
528
+ return html`<div
529
+ class="carousel"
530
+ part="base"
531
+ role="region"
532
+ aria-roledescription=${this.i18n.t('carouselRole')}
533
+ aria-label=${this.label || nothing}
534
+ >
535
+ <div
536
+ class="track"
537
+ part="track"
538
+ aria-live=${this.shouldRotate ? 'off' : 'polite'}
539
+ style=${styleMap({ '--_per-view': String(this.visible) })}
540
+ @scroll=${this.handleScroll}
541
+ >
542
+ <slot @slotchange=${this.handleSlotChange}></slot>
543
+ </div>
544
+ ${this.renderControls()}
545
+ </div>`;
546
+ }
547
+ }
@@ -0,0 +1 @@
1
+ export { Carousel, type CarouselChangeDetail } from './carousel.js';
@@ -16,7 +16,11 @@
16
16
 
17
17
  .body {
18
18
  position: relative;
19
- padding-inline-start: var(--_connector-width);
19
+
20
+ // The connector column shows only once there are two items to join.
21
+ &.connected {
22
+ padding-inline-start: var(--_connector-width);
23
+ }
20
24
  }
21
25
 
22
26
  .connector {
@@ -487,7 +487,7 @@ export class CbGroupBase extends LitElement {
487
487
  @dragleave=${this._onDragLeave}
488
488
  @drop=${this._onDrop}
489
489
  >
490
- <div class="body">
490
+ <div class=${classMap({ body: true, connected: this._itemCount > 1 })}>
491
491
  ${this._renderConnector()}
492
492
  <div class=${classMap({ items: true, empty: this._itemCount === 0 })}>
493
493
  <slot @slotchange=${this._onSlotChange}></slot>
@@ -17,5 +17,9 @@
17
17
  align-items: center;
18
18
  gap: var(--spacing-100);
19
19
  padding-top: var(--spacing-100);
20
+ }
21
+
22
+ // Lines up with the items while the connector column shows.
23
+ .body.connected + .footer {
20
24
  padding-inline-start: var(--_connector-width);
21
25
  }
@@ -0,0 +1,25 @@
1
+ @use '../../scss/mixin';
2
+
3
+ @include mixin.base-styles;
4
+
5
+ :host {
6
+ display: inline;
7
+ }
8
+
9
+ mark {
10
+ border-radius: var(--shape-corner-extra-small);
11
+ padding-inline: 0.0625rem;
12
+ background-color: var(
13
+ --highlight-background,
14
+ var(--color-tertiary-container)
15
+ );
16
+ color: var(--highlight-color, var(--color-on-tertiary-container));
17
+ box-decoration-break: clone;
18
+ }
19
+
20
+ @media (forced-colors: active) {
21
+ mark {
22
+ background-color: Mark;
23
+ color: MarkText;
24
+ }
25
+ }