@redvars/peacock 4.2.1 → 4.3.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 (244) 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-CZLzCnXK.js → cb-group-base-Bf7iOIGS.js} +2 -2
  27. package/dist/{cb-group-base-CZLzCnXK.js.map → cb-group-base-Bf7iOIGS.js.map} +1 -1
  28. package/dist/cb-group.js +3 -3
  29. package/dist/cb-rule.js +3 -3
  30. package/dist/chart-area.js +4 -4
  31. package/dist/chart-bar.js +4 -4
  32. package/dist/{chart-base-DREru2P0.js → chart-base-ByCJM_9C.js} +2 -2
  33. package/dist/{chart-base-DREru2P0.js.map → chart-base-ByCJM_9C.js.map} +1 -1
  34. package/dist/chart-doughnut.js +3 -3
  35. package/dist/chart-line.js +4 -4
  36. package/dist/chart-pie.js +3 -3
  37. package/dist/chat-event.js +2 -2
  38. package/dist/chat-message.js +2 -2
  39. package/dist/chat-thread.js +2 -2
  40. package/dist/checkbox-group.js +3 -3
  41. package/dist/checkbox.js +3 -3
  42. package/dist/chip-set.js +2 -2
  43. package/dist/chip.js +2 -2
  44. package/dist/circular-progress.js +3 -3
  45. package/dist/citation.js +2 -2
  46. package/dist/code-editor.js +3 -3
  47. package/dist/code-highlighter.js +2 -2
  48. package/dist/color-field.js +4 -4
  49. package/dist/color-picker.js +2 -2
  50. package/dist/command-palette.js +2 -2
  51. package/dist/comment-composer.js +4 -4
  52. package/dist/condition-builder.js +3 -3
  53. package/dist/confirm-dialog.js +2 -2
  54. package/dist/copy-button.js +2 -2
  55. package/dist/currency-field.js +4 -4
  56. package/dist/custom-elements-jsdocs.json +902 -74
  57. package/dist/custom-elements.json +2842 -1
  58. package/dist/date-field.js +5 -5
  59. package/dist/date-picker.js +2 -2
  60. package/dist/date-range-field.js +5 -5
  61. package/dist/datetime-field.js +5 -5
  62. package/dist/dependency-map.js +3 -3
  63. package/dist/description-item.js +2 -2
  64. package/dist/description-list.js +2 -2
  65. package/dist/{diagram-CHF70xTL.js → diagram-Cnrj-4y3.js} +2 -2
  66. package/dist/{diagram-CHF70xTL.js.map → diagram-Cnrj-4y3.js.map} +1 -1
  67. package/dist/diagram-controls.js +2 -2
  68. package/dist/diagram-minimap.js +2 -2
  69. package/dist/diagram.js +4 -4
  70. package/dist/diff-viewer.js +2 -2
  71. package/dist/discussion-activity.js +2 -2
  72. package/dist/discussion-comment.js +2 -2
  73. package/dist/discussion.js +4 -4
  74. package/dist/{document-editor-Cb9fCxvA.js → document-editor-C8ThjDQ7.js} +2 -2
  75. package/dist/{document-editor-Cb9fCxvA.js.map → document-editor-C8ThjDQ7.js.map} +1 -1
  76. package/dist/document-editor.js +3 -3
  77. package/dist/draft-card.js +2 -2
  78. package/dist/erd.js +3 -3
  79. package/dist/file-upload.js +3 -3
  80. package/dist/filter-bar.js +2 -2
  81. package/dist/flow.js +4 -4
  82. package/dist/form.js +2 -2
  83. package/dist/{generative-view-C4fJ2zI7.js → generative-view-CQ8-g1wY.js} +2 -2
  84. package/dist/{generative-view-C4fJ2zI7.js.map → generative-view-CQ8-g1wY.js.map} +1 -1
  85. package/dist/generative-view.js +3 -3
  86. package/dist/highlight-Be0wu7kh.js +252 -0
  87. package/dist/highlight-Be0wu7kh.js.map +1 -0
  88. package/dist/highlight.js +6 -0
  89. package/dist/highlight.js.map +1 -0
  90. package/dist/html-editor.js +4 -4
  91. package/dist/{i18n-controller-CH4e9sju.js → i18n-controller-DLJcJ5gO.js} +2 -2
  92. package/dist/{i18n-controller-CH4e9sju.js.map → i18n-controller-DLJcJ5gO.js.map} +1 -1
  93. package/dist/image.js +2 -2
  94. package/dist/index.js +26 -16
  95. package/dist/index.js.map +1 -1
  96. package/dist/inline-edit.js +2 -2
  97. package/dist/input.js +3 -3
  98. package/dist/json-viewer.js +2 -2
  99. package/dist/kanban.js +2 -2
  100. package/dist/kbd.js +2 -2
  101. package/dist/linear-progress.js +3 -3
  102. package/dist/listbox.js +2 -2
  103. package/dist/loader-full.js +19 -9
  104. package/dist/loader-full.js.map +1 -1
  105. package/dist/loader.js +46 -9
  106. package/dist/loader.js.map +1 -1
  107. package/dist/markdown-editor.js +4 -4
  108. package/dist/mention-input.js +4 -4
  109. package/dist/modal.js +2 -2
  110. package/dist/navigation-bar.js +2 -2
  111. package/dist/navigation-drawer.js +2 -2
  112. package/dist/navigation-rail.js +2 -2
  113. package/dist/notification-center.js +2 -2
  114. package/dist/number-field.js +4 -4
  115. package/dist/page-header.js +2 -2
  116. package/dist/pagination.js +2 -2
  117. package/dist/password-field.js +4 -4
  118. package/dist/password-rules.js +2 -2
  119. package/dist/phone-field.js +4 -4
  120. package/dist/{picker-field-loXW-xrW.js → picker-field-B5xOFc3-.js} +3 -3
  121. package/dist/{picker-field-loXW-xrW.js.map → picker-field-B5xOFc3-.js.map} +1 -1
  122. package/dist/pin-input.js +4 -4
  123. package/dist/presence-indicator.js +2 -2
  124. package/dist/prompt-input.js +4 -4
  125. package/dist/radio.js +3 -3
  126. package/dist/rating.js +3 -3
  127. package/dist/redvars-loader.js +2 -2
  128. package/dist/relative-time.js +2 -2
  129. package/dist/resizable-panels.js +2 -2
  130. package/dist/{rich-text-input-B5j0eqCJ.js → rich-text-input-C4B9D6oD.js} +3 -3
  131. package/dist/{rich-text-input-B5j0eqCJ.js.map → rich-text-input-C4B9D6oD.js.map} +1 -1
  132. package/dist/{schema-BJzlGRP1.js → schema-CPhNrjrx.js} +2 -2
  133. package/dist/{schema-BJzlGRP1.js.map → schema-CPhNrjrx.js.map} +1 -1
  134. package/dist/search.js +3 -3
  135. package/dist/select.js +4 -4
  136. package/dist/side-sheet.js +2 -2
  137. package/dist/signature-pad.js +3 -3
  138. package/dist/site-footer-group.js +142 -0
  139. package/dist/site-footer-group.js.map +1 -0
  140. package/dist/site-footer.js +338 -0
  141. package/dist/site-footer.js.map +1 -0
  142. package/dist/site-header.js +774 -0
  143. package/dist/site-header.js.map +1 -0
  144. package/dist/site-nav-group.js +123 -0
  145. package/dist/site-nav-group.js.map +1 -0
  146. package/dist/site-nav-link.js +321 -0
  147. package/dist/site-nav-link.js.map +1 -0
  148. package/dist/site-nav-menu.js +506 -0
  149. package/dist/site-nav-menu.js.map +1 -0
  150. package/dist/site-nav-shared-BDR2HG8e.js +23 -0
  151. package/dist/site-nav-shared-BDR2HG8e.js.map +1 -0
  152. package/dist/slider.js +3 -3
  153. package/dist/snackbar.js +2 -2
  154. package/dist/sparkline.js +2 -2
  155. package/dist/split-button.js +2 -2
  156. package/dist/src/__internal/i18n/strings.d.ts +24 -0
  157. package/dist/src/carousel/carousel.d.ts +135 -0
  158. package/dist/src/carousel/index.d.ts +1 -0
  159. package/dist/src/highlight/highlight.d.ts +56 -0
  160. package/dist/src/highlight/index.d.ts +2 -0
  161. package/dist/src/highlight/matches.d.ts +9 -0
  162. package/dist/src/index.d.ts +9 -0
  163. package/dist/src/site-footer/index.d.ts +2 -0
  164. package/dist/src/site-footer/site-footer-group.d.ts +34 -0
  165. package/dist/src/site-footer/site-footer.d.ts +74 -0
  166. package/dist/src/site-header/index.d.ts +4 -0
  167. package/dist/src/site-header/site-header.d.ts +170 -0
  168. package/dist/src/site-header/site-nav-group.d.ts +32 -0
  169. package/dist/src/site-header/site-nav-link.d.ts +65 -0
  170. package/dist/src/site-header/site-nav-menu.d.ts +104 -0
  171. package/dist/src/site-header/site-nav-shared.d.ts +13 -0
  172. package/dist/src/video/index.d.ts +2 -0
  173. package/dist/src/video/video-source.d.ts +12 -0
  174. package/dist/src/video/video.d.ts +80 -0
  175. package/dist/stat.js +2 -2
  176. package/dist/status-indicator.js +2 -2
  177. package/dist/step.js +2 -2
  178. package/dist/stepper.js +2 -2
  179. package/dist/{strings-o6v6Hrmn.js → strings-MXyrGrNs.js} +28 -1
  180. package/dist/strings-MXyrGrNs.js.map +1 -0
  181. package/dist/svg.js +2 -2
  182. package/dist/switch.js +3 -3
  183. package/dist/table.js +2 -2
  184. package/dist/test/carousel.test.d.ts +1 -0
  185. package/dist/test/highlight.test.d.ts +1 -0
  186. package/dist/test/site-footer.test.d.ts +1 -0
  187. package/dist/test/site-header.test.d.ts +1 -0
  188. package/dist/test/video.test.d.ts +1 -0
  189. package/dist/textarea.js +4 -4
  190. package/dist/time-field.js +5 -5
  191. package/dist/time-picker.js +2 -2
  192. package/dist/timeline-item.js +2 -2
  193. package/dist/timeline.js +2 -2
  194. package/dist/{toggle-base-BSzBnLZN.js → toggle-base-I1wE_fVe.js} +2 -2
  195. package/dist/{toggle-base-BSzBnLZN.js.map → toggle-base-I1wE_fVe.js.map} +1 -1
  196. package/dist/tour.js +2 -2
  197. package/dist/transfer-list.js +3 -3
  198. package/dist/tree-chart.js +3 -3
  199. package/dist/tree-item.js +2 -2
  200. package/dist/tree.js +2 -2
  201. package/dist/tsconfig.tsbuildinfo +1 -1
  202. package/dist/typing-indicator.js +2 -2
  203. package/dist/url-field.js +4 -4
  204. package/dist/user-menu.js +2 -2
  205. package/dist/video-IwNmHyft.js +509 -0
  206. package/dist/video-IwNmHyft.js.map +1 -0
  207. package/dist/video.js +12 -0
  208. package/dist/video.js.map +1 -0
  209. package/dist/virtual-list.js +2 -2
  210. package/dist/workflow-timeline.js +2 -2
  211. package/dist/workflow.js +3 -3
  212. package/dist/workspace-switcher.js +2 -2
  213. package/package.json +1 -1
  214. package/readme.md +5 -0
  215. package/src/__internal/i18n/strings.ts +31 -0
  216. package/src/carousel/carousel.scss +124 -0
  217. package/src/carousel/carousel.ts +547 -0
  218. package/src/carousel/index.ts +1 -0
  219. package/src/highlight/highlight.scss +25 -0
  220. package/src/highlight/highlight.ts +123 -0
  221. package/src/highlight/index.ts +2 -0
  222. package/src/highlight/matches.ts +94 -0
  223. package/src/index.ts +18 -0
  224. package/src/loader.ts +36 -0
  225. package/src/site-footer/index.ts +2 -0
  226. package/src/site-footer/site-footer-group.scss +53 -0
  227. package/src/site-footer/site-footer-group.ts +52 -0
  228. package/src/site-footer/site-footer.scss +171 -0
  229. package/src/site-footer/site-footer.ts +151 -0
  230. package/src/site-header/index.ts +8 -0
  231. package/src/site-header/site-header.scss +238 -0
  232. package/src/site-header/site-header.ts +565 -0
  233. package/src/site-header/site-nav-group.scss +29 -0
  234. package/src/site-header/site-nav-group.ts +57 -0
  235. package/src/site-header/site-nav-link.scss +154 -0
  236. package/src/site-header/site-nav-link.ts +140 -0
  237. package/src/site-header/site-nav-menu.scss +182 -0
  238. package/src/site-header/site-nav-menu.ts +336 -0
  239. package/src/site-header/site-nav-shared.ts +27 -0
  240. package/src/video/index.ts +2 -0
  241. package/src/video/video-source.ts +80 -0
  242. package/src/video/video.scss +183 -0
  243. package/src/video/video.ts +246 -0
  244. 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';
@@ -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
+ }
@@ -0,0 +1,123 @@
1
+ import { html, LitElement, type PropertyValues } from 'lit';
2
+ import { property, state } from 'lit/decorators.js';
3
+ import IndividualComponent from '@/IndividualComponent.js';
4
+ import { resolveLocale } from '@/__internal/i18n/locale.js';
5
+ import { findMatches, type HighlightRange, mergeRanges } from './matches.js';
6
+ import styles from './highlight.scss';
7
+
8
+ export type { HighlightRange } from './matches.js';
9
+
10
+ /**
11
+ * @label Highlight
12
+ * @tag wc-highlight
13
+ * @rawTag highlight
14
+ *
15
+ * @summary Marks the words of a search query in a piece of text.
16
+ * @overview
17
+ * <p>Highlight shows its text with each word of <code>query</code> marked, for search results in a
18
+ * knowledge base, a site search or a filtered list. Words match on their own, in any order,
19
+ * ignoring case and accents, so "resume" marks "Résumé".</p>
20
+ * <p>It reads its children as plain text and never parses HTML, so text from records or a search
21
+ * index is safe to put in it. When the server already knows where the matches are, set
22
+ * <code>ranges</code> instead of <code>query</code>.</p>
23
+ * <p>Marks use the tertiary container colour, so they differ from links and from the selection.</p>
24
+ *
25
+ * @slot - The text. Only its text content is used; markup in it is not rendered.
26
+ *
27
+ * @csspart mark - Each marked run of text, a `<mark>` element.
28
+ *
29
+ * @cssprop --highlight-background - Background of the marks. Defaults to `--color-tertiary-container`.
30
+ * @cssprop --highlight-color - Text colour of the marks. Defaults to `--color-on-tertiary-container`.
31
+ *
32
+ * @example
33
+ * ```html
34
+ * <wc-highlight query="reset password">
35
+ * If you forgot your password, choose Forgot password and reset it from the link we email you.
36
+ * </wc-highlight>
37
+ * ```
38
+ * @tags display search
39
+ */
40
+ @IndividualComponent
41
+ export class Highlight extends LitElement {
42
+ // ── Static ───────────────────────────────────────────────────────────────
43
+
44
+ static styles = [styles];
45
+
46
+ // ── Properties ───────────────────────────────────────────────────────────
47
+
48
+ /** The search query whose words are marked. */
49
+ @property({ reflect: true })
50
+ query = '';
51
+
52
+ /**
53
+ * Runs to mark, as `[start, end)` offsets in the element's `textContent`, for matches the server
54
+ * already found. When set, `query` is ignored.
55
+ */
56
+ @property({ attribute: false })
57
+ ranges?: HighlightRange[];
58
+
59
+ /** The language to fold case in. Defaults to the nearest `lang`, else the browser's. */
60
+ @property({ reflect: true })
61
+ locale?: string;
62
+
63
+ // ── State ────────────────────────────────────────────────────────────────
64
+
65
+ /** The element's text content. */
66
+ @state() private text = '';
67
+
68
+ // ── Private fields ───────────────────────────────────────────────────────
69
+
70
+ /** Watches the text, so the marks follow when it changes. */
71
+ private readonly textObserver = new MutationObserver(() => this.syncText());
72
+
73
+ // ── Lifecycle ────────────────────────────────────────────────────────────
74
+
75
+ override connectedCallback() {
76
+ super.connectedCallback();
77
+ this.syncText();
78
+ this.textObserver.observe(this, {
79
+ childList: true,
80
+ characterData: true,
81
+ subtree: true,
82
+ });
83
+ }
84
+
85
+ override disconnectedCallback() {
86
+ this.textObserver.disconnect();
87
+ super.disconnectedCallback();
88
+ }
89
+
90
+ protected override willUpdate(changed: PropertyValues<this>) {
91
+ super.willUpdate(changed);
92
+ this.syncText();
93
+ }
94
+
95
+ // ── Private methods ──────────────────────────────────────────────────────
96
+
97
+ /** The runs to mark, as `[start, end)` offsets in the text. */
98
+ private get marks(): HighlightRange[] {
99
+ if (this.ranges) return mergeRanges(this.ranges, this.text.length);
100
+ return findMatches(this.text, this.query, resolveLocale(this.locale, this));
101
+ }
102
+
103
+ private syncText() {
104
+ // Kept as is, so `ranges` offsets match the text; CSS collapses the whitespace when it renders.
105
+ const text = this.textContent ?? '';
106
+ if (text !== this.text) this.text = text;
107
+ }
108
+
109
+ // ── Render ───────────────────────────────────────────────────────────────
110
+
111
+ render() {
112
+ const { text } = this;
113
+ const pieces = [];
114
+ let at = 0;
115
+ for (const [start, end] of this.marks) {
116
+ if (start > at) pieces.push(text.slice(at, start));
117
+ pieces.push(html`<mark part="mark">${text.slice(start, end)}</mark>`);
118
+ at = end;
119
+ }
120
+ if (at < text.length) pieces.push(text.slice(at));
121
+ return html`${pieces}`;
122
+ }
123
+ }
@@ -0,0 +1,2 @@
1
+ export { Highlight, type HighlightRange } from './highlight.js';
2
+ export { findMatches } from './matches.js';