@m3ui-vue/m3ui-vue 1.1.2 → 1.1.3

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 (88) hide show
  1. package/dist/API.md +135 -5
  2. package/dist/{MIcon-DLOkQduI.js → MIcon-Bxh9j135.js} +15 -8
  3. package/dist/MIcon-Bxh9j135.js.map +1 -0
  4. package/dist/{MMenuItem-DVxKEv1W.js → MMenuItem-BckcR0nW.js} +4 -4
  5. package/dist/{MMenuItem-DVxKEv1W.js.map → MMenuItem-BckcR0nW.js.map} +1 -1
  6. package/dist/{MSlider-BXsBv0ox.js → MSlider-LyH_gy8D.js} +56 -47
  7. package/dist/MSlider-LyH_gy8D.js.map +1 -0
  8. package/dist/{MTextField-rML9jnXs.js → MTextField-FCPOTB0o.js} +65 -64
  9. package/dist/{MTextField-rML9jnXs.js.map → MTextField-FCPOTB0o.js.map} +1 -1
  10. package/dist/api.json +1 -1
  11. package/dist/code-editor.js +2 -2
  12. package/dist/components/MAnimatedNumber.vue.d.ts +27 -0
  13. package/dist/components/MIcon.vue.d.ts +2 -0
  14. package/dist/components/MListGroup.vue.d.ts +23 -0
  15. package/dist/components/MScheduler.vue.d.ts +2 -2
  16. package/dist/components/MScheme.vue.d.ts +60 -0
  17. package/dist/components/MSparkline.vue.d.ts +41 -0
  18. package/dist/components/MWindow.vue.d.ts +2 -2
  19. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  20. package/dist/composables/_useSegmentRuns.d.ts +8 -0
  21. package/dist/composables/dynamicColor.d.ts +11 -0
  22. package/dist/composables/useColorPalette.d.ts +3 -1
  23. package/dist/composables/useConfetti.d.ts +32 -0
  24. package/dist/composables/useLocale.d.ts +6 -0
  25. package/dist/index.d.ts +7 -1
  26. package/dist/locales/index.js +21 -0
  27. package/dist/locales/index.js.map +1 -1
  28. package/dist/m3ui-vue.css +1 -1
  29. package/dist/m3ui.js +16187 -15377
  30. package/dist/m3ui.js.map +1 -1
  31. package/dist/map.js +45 -45
  32. package/dist/{material-color-utilities-Cktu8DBU.js → material-color-utilities-C_iikgRm.js} +928 -603
  33. package/dist/material-color-utilities-C_iikgRm.js.map +1 -0
  34. package/dist/rich-text-editor.js +4 -4
  35. package/dist/styles.css +1 -1
  36. package/dist/terminal.js +1 -1
  37. package/dist/{useLocale-CqQrhWFl.js → useLocale-SfQHnJfp.js} +4 -1
  38. package/dist/useLocale-SfQHnJfp.js.map +1 -0
  39. package/package.json +1 -1
  40. package/src/__tests__/MAnimatedNumber.test.ts +106 -0
  41. package/src/__tests__/MIcon.test.ts +19 -0
  42. package/src/__tests__/MListItemShape.test.ts +34 -0
  43. package/src/__tests__/MScheme.test.ts +107 -0
  44. package/src/__tests__/MSparkline.test.ts +96 -0
  45. package/src/__tests__/iconButtonNames.test.ts +124 -0
  46. package/src/__tests__/ssr.test.ts +1 -0
  47. package/src/__tests__/useConfetti.test.ts +81 -0
  48. package/src/components/MAnimatedNumber.vue +301 -0
  49. package/src/components/MAutocomplete.vue +34 -4
  50. package/src/components/MBottomSheet.vue +1 -0
  51. package/src/components/MDataTable.vue +1 -1
  52. package/src/components/MIcon.vue +11 -4
  53. package/src/components/MList.vue +8 -30
  54. package/src/components/MListGroup.vue +66 -0
  55. package/src/components/MMaskField.vue +3 -0
  56. package/src/components/MMultiAutocomplete.vue +5 -1
  57. package/src/components/MMultiSelect.vue +19 -9
  58. package/src/components/MScheme.vue +162 -0
  59. package/src/components/MSearchBar.vue +2 -0
  60. package/src/components/MSelect.vue +44 -10
  61. package/src/components/MSideSheet.vue +3 -0
  62. package/src/components/MSimpleCarousel.vue +6 -0
  63. package/src/components/MSparkline.vue +250 -0
  64. package/src/components/MSplitButton.vue +3 -0
  65. package/src/components/MSpotlightSearch.vue +1 -0
  66. package/src/components/MTable.vue +1 -0
  67. package/src/components/MTagInput.vue +4 -0
  68. package/src/components/MTextField.vue +3 -0
  69. package/src/components/MTour.vue +1 -0
  70. package/src/components/MTreeTable.vue +1 -0
  71. package/src/components/_MTreeNode.vue +3 -0
  72. package/src/composables/_useSegmentRuns.ts +39 -0
  73. package/src/composables/dynamicColor.ts +66 -0
  74. package/src/composables/useColorPalette.ts +2 -2
  75. package/src/composables/useConfetti.ts +204 -0
  76. package/src/composables/useLocale.ts +9 -0
  77. package/src/index.ts +7 -1
  78. package/src/locales/de.ts +3 -0
  79. package/src/locales/es.ts +3 -0
  80. package/src/locales/fr.ts +3 -0
  81. package/src/locales/ja.ts +3 -0
  82. package/src/locales/ko.ts +3 -0
  83. package/src/locales/pt.ts +3 -0
  84. package/src/locales/zh.ts +3 -0
  85. package/dist/MIcon-DLOkQduI.js.map +0 -1
  86. package/dist/MSlider-BXsBv0ox.js.map +0 -1
  87. package/dist/material-color-utilities-Cktu8DBU.js.map +0 -1
  88. package/dist/useLocale-CqQrhWFl.js.map +0 -1
@@ -70,8 +70,17 @@ const emit = defineEmits<{ 'update:modelValue': [unknown] }>()
70
70
 
71
71
  const locale = useLocale()
72
72
  const id = useId()
73
+ // ARIA combobox + listbox: the trigger names itself by the label and points at the open list and its selected option
74
+ const labelId = `${id}-label`
75
+ const listId = `${id}-list`
76
+ const optionId = (i: number) => `${id}-opt-${i}`
77
+ const selectedIndex = computed(() => props.options.findIndex((o) => eq(o.value, props.modelValue)))
73
78
  const open = ref(false)
74
79
  const modalOpen = ref(false)
80
+ // Focused (from the keyboard too) looks like open: M3's focused field, 2dp primary indicator and primary label,
81
+ // instead of the browser's own outline
82
+ const focused = ref(false)
83
+ const highlighted = computed(() => open.value || modalOpen.value || focused.value)
75
84
  const fieldEl = ref<HTMLElement | null>(null)
76
85
  const { resolvedFieldBg } = useFieldBg(fieldEl, () => props.fieldBg)
77
86
  const dropdownEl = ref<HTMLElement | null>(null)
@@ -164,7 +173,7 @@ onUnmounted(() => {
164
173
  const triggerClasses = computed(() => {
165
174
  const pl = props.leadingIcon ? 'pl-12' : 'pl-4'
166
175
  const base = [
167
- 'flex w-full items-center pr-10 text-body-large transition-[border-color,border-width] duration-150',
176
+ 'flex w-full items-center pr-10 text-body-large outline-none transition-[border-color,border-width] duration-150',
168
177
  props.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
169
178
  pl,
170
179
  ]
@@ -172,7 +181,7 @@ const triggerClasses = computed(() => {
172
181
  if (props.variant === 'outlined') {
173
182
  const border = props.disabled
174
183
  ? 'border-on-surface/12'
175
- : open.value
184
+ : highlighted.value
176
185
  ? (props.error ? 'border-2 border-error' : 'border-2 border-primary')
177
186
  : (props.error ? 'border-error' : 'border-outline hover:border-on-surface')
178
187
  return [...base, 'h-14 rounded-xs border bg-transparent', border].join(' ')
@@ -180,7 +189,7 @@ const triggerClasses = computed(() => {
180
189
 
181
190
  const border = props.disabled
182
191
  ? 'border-on-surface/38'
183
- : open.value
192
+ : highlighted.value
184
193
  ? (props.error ? 'border-b-2 border-error' : 'border-b-2 border-primary')
185
194
  : (props.error ? 'border-error' : 'border-on-surface-variant hover:border-on-surface')
186
195
  const bg = props.disabled
@@ -189,7 +198,7 @@ const triggerClasses = computed(() => {
189
198
  return [...base, 'h-14 rounded-t-xs border-b pt-6 pb-2', bg, border].join(' ')
190
199
  })
191
200
 
192
- const isFloated = computed(() => hasValue.value || open.value)
201
+ const isFloated = computed(() => hasValue.value || highlighted.value)
193
202
 
194
203
  const labelClasses = computed(() => {
195
204
  const left = props.leadingIcon
@@ -210,7 +219,7 @@ const labelClasses = computed(() => {
210
219
  isFloated.value ? floated : unFloated,
211
220
  props.disabled
212
221
  ? 'text-on-surface/38'
213
- : open.value
222
+ : highlighted.value
214
223
  ? (props.error ? 'text-error' : 'text-primary')
215
224
  : (props.error ? 'text-error' : 'text-on-surface-variant'),
216
225
  ].join(' ')
@@ -242,22 +251,31 @@ const labelClasses = computed(() => {
242
251
  :id="id"
243
252
  :tabindex="disabled ? -1 : 0"
244
253
  role="combobox"
245
- :aria-expanded="open"
254
+ aria-haspopup="listbox"
255
+ :aria-expanded="open || modalOpen"
256
+ :aria-controls="open || modalOpen ? listId : undefined"
257
+ :aria-activedescendant="(open || modalOpen) && selectedIndex >= 0 ? optionId(selectedIndex) : undefined"
258
+ :aria-labelledby="label ? labelId : undefined"
259
+ :aria-required="required || undefined"
260
+ :aria-invalid="error || undefined"
246
261
  :aria-disabled="disabled"
247
262
  :class="[triggerClasses, disabled ? 'pointer-events-none' : '']"
248
263
  @click="toggle"
249
264
  @keydown="onKeydown"
265
+ @focus="focused = true"
266
+ @blur="focused = false"
250
267
  >
251
268
  <span v-if="hasValue" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ selectedLabel }}</span>
252
269
  </div>
253
270
 
254
271
  <!-- Floating label -->
255
- <label :for="id" :class="labelClasses">
272
+ <label :id="labelId" :for="id" :class="labelClasses">
256
273
  {{ label }}<span v-if="required" class="text-error">&nbsp;*</span>
257
274
  </label>
258
275
 
259
276
  <!-- Clear button -->
260
277
  <button
278
+ :aria-label="locale.clear"
261
279
  v-if="clearable && hasValue && !disabled"
262
280
  type="button"
263
281
  class="absolute right-9 top-1/2 -translate-y-1/2 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
@@ -296,13 +314,20 @@ const labelClasses = computed(() => {
296
314
  >
297
315
  <div
298
316
  v-if="open && mode === 'docked'"
317
+ :id="listId"
299
318
  ref="dropdownEl"
319
+ role="listbox"
320
+ :aria-labelledby="label ? labelId : undefined"
300
321
  class="fixed z-500 max-h-60 overflow-auto rounded-xs bg-surface-container py-1 shadow-elevation-2"
301
322
  :style="dropPos"
302
323
  >
303
324
  <div
304
325
  v-for="(opt, i) in options"
326
+ :id="optionId(i)"
305
327
  :key="i"
328
+ role="option"
329
+ :aria-selected="eq(opt.value, modelValue)"
330
+ :aria-disabled="opt.disabled || undefined"
306
331
  class="flex cursor-pointer items-center gap-3 px-4 py-3 text-body-large"
307
332
  :class="[
308
333
  opt.disabled
@@ -337,20 +362,29 @@ const labelClasses = computed(() => {
337
362
  class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
338
363
  @click.self="closeModal"
339
364
  >
340
- <div class="select-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3">
365
+ <div
366
+ class="select-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3"
367
+ role="dialog"
368
+ aria-modal="true"
369
+ :aria-labelledby="`${id}-dialog-title`"
370
+ >
341
371
  <!-- Header -->
342
372
  <div class="flex items-center justify-between px-6 pt-6 pb-4">
343
- <h2 class="text-headline-small text-on-surface">{{ label || placeholder }}</h2>
373
+ <h2 :id="`${id}-dialog-title`" class="text-headline-small text-on-surface">{{ label || placeholder }}</h2>
344
374
  <MIconButton icon="close" :label="locale.close" @click="closeModal" />
345
375
  </div>
346
376
 
347
377
  <div class="h-px bg-outline-variant" />
348
378
 
349
379
  <!-- Options list -->
350
- <div class="flex-1 overflow-y-auto py-2">
380
+ <div :id="listId" role="listbox" :aria-labelledby="`${id}-dialog-title`" class="flex-1 overflow-y-auto py-2">
351
381
  <div
352
382
  v-for="(opt, i) in options"
383
+ :id="optionId(i)"
353
384
  :key="i"
385
+ role="option"
386
+ :aria-selected="eq(opt.value, modelValue)"
387
+ :aria-disabled="opt.disabled || undefined"
354
388
  class="flex cursor-pointer items-center gap-4 px-6 py-3.5 text-body-large transition-colors"
355
389
  :class="[
356
390
  opt.disabled
@@ -11,7 +11,9 @@
11
11
  */
12
12
  import MIcon from './MIcon.vue'
13
13
  import { useSheetMotion } from '../composables/_useSheetMotion'
14
+ import { useLocale } from '../composables/useLocale'
14
15
 
16
+ const locale = useLocale()
15
17
  withDefaults(defineProps<{
16
18
  /** Open/closed state (v-model) */
17
19
  modelValue: boolean
@@ -56,6 +58,7 @@ const motion = useSheetMotion('x', close)
56
58
  <h2 class="text-title-large text-on-surface">{{ title }}</h2>
57
59
  </slot>
58
60
  <button
61
+ :aria-label="locale.close"
59
62
  type="button"
60
63
  class="flex h-9 w-9 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8"
61
64
  @click="close"
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue'
11
11
  import MIcon from './MIcon.vue'
12
+ import { useLocale } from '../composables/useLocale'
12
13
 
13
14
  export interface SimpleCarouselItem {
14
15
  src: string
@@ -18,6 +19,7 @@ export interface SimpleCarouselItem {
18
19
  ratio?: number
19
20
  }
20
21
 
22
+ const locale = useLocale()
21
23
  const props = withDefaults(
22
24
  defineProps<{
23
25
  /** Slides to render — required */
@@ -293,6 +295,7 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
293
295
 
294
296
  <template v-if="showArrows && items.length > 1">
295
297
  <button
298
+ :aria-label="locale.previous"
296
299
  type="button"
297
300
  class="absolute left-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-surface/80 text-on-surface shadow-elevation-1 opacity-0 backdrop-blur-sm transition-all duration-200 hover:bg-surface hover:shadow-elevation-2 group-hover:opacity-100"
298
301
  @click="prev"
@@ -300,6 +303,7 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
300
303
  <MIcon name="chevron_left" :size="24" />
301
304
  </button>
302
305
  <button
306
+ :aria-label="locale.next"
303
307
  type="button"
304
308
  class="absolute right-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-surface/80 text-on-surface shadow-elevation-1 opacity-0 backdrop-blur-sm transition-all duration-200 hover:bg-surface hover:shadow-elevation-2 group-hover:opacity-100"
305
309
  @click="next"
@@ -318,6 +322,8 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
318
322
  v-for="p in totalPages"
319
323
  :key="p"
320
324
  type="button"
325
+ :aria-label="locale.carouselItem.replace('{index}', String(p)).replace('{count}', String(totalPages))"
326
+ :aria-current="(p - 1) === activePage || undefined"
321
327
  class="h-2 cursor-pointer rounded-full transition-all duration-300"
322
328
  :class="(p - 1) === activePage ? 'w-5 bg-on-surface' : 'w-2 bg-on-surface/30 hover:bg-on-surface/50'"
323
329
  @click="isPageBased ? scrollToPage(p - 1) : scrollToItem(p - 1)"
@@ -0,0 +1,250 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A small trend chart, drawn as SVG with no chart library: a line, an area or bars, for next to a number (a stat
4
+ * card, a table cell, a list item). It fills its box (size it with classes; 96×28px by default), drawn at its real
5
+ * size so dots and bars don't stretch. When the data changes the shape springs to the new values. Screen readers
6
+ * get a summary (first, last, low, high) instead of the drawing. Not an M3 spec component.
7
+ *
8
+ * @event hover With `interactive`: the index of the point under the pointer, or null when it leaves
9
+ */
10
+ import { computed, onMounted, onUnmounted, ref, useId, watch } from 'vue'
11
+ import { useLocale } from '../composables/useLocale'
12
+ import { useSpring, DEFAULT_SPATIAL } from '../composables/_useSpring'
13
+
14
+ const props = withDefaults(
15
+ defineProps<{
16
+ /** The values, oldest first */
17
+ data: number[]
18
+ /** Line, line with a soft fill under it, or bars */
19
+ type?: 'line' | 'area' | 'bar'
20
+ /** An M3 color role (`primary`, `tertiary`, `error`...) or any CSS color */
21
+ color?: string
22
+ /** Smooth curve through the points (monotone: it never overshoots them) instead of straight segments */
23
+ smooth?: boolean
24
+ /** A dot on the last point (line and area) */
25
+ showLast?: boolean
26
+ /** Line width in px */
27
+ strokeWidth?: number
28
+ /** Fix the bottom of the scale (otherwise the lowest value, or 0 for bars) */
29
+ min?: number
30
+ /** Fix the top of the scale (otherwise the highest value) */
31
+ max?: number
32
+ /** A dashed reference line at this value (a target, yesterday's close) */
33
+ baseline?: number
34
+ /** Follow the pointer with a dot and emit `hover` with the index under it */
35
+ interactive?: boolean
36
+ /** Accessible name; defaults to a summary of the data in the app's language */
37
+ label?: string
38
+ /** Spring to new data; false (or reduced motion) jumps */
39
+ animate?: boolean
40
+ }>(),
41
+ { type: 'line', color: 'primary', smooth: true, showLast: true, strokeWidth: 2, interactive: false, animate: true },
42
+ )
43
+
44
+ const emit = defineEmits<{ hover: [index: number | null] }>()
45
+
46
+ const ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'success', 'on-surface', 'on-surface-variant', 'outline', 'inverse-primary'])
47
+ const stroke = computed(() => (ROLES.has(props.color) ? `var(--color-${props.color})` : props.color))
48
+
49
+ // Drawn at the box's real size (measured), so circles and bar corners stay round
50
+ const root = ref<HTMLElement>()
51
+ const width = ref(96)
52
+ const height = ref(28)
53
+ let observer: ResizeObserver | undefined
54
+ onMounted(() => {
55
+ if (!root.value) return
56
+ const measure = () => {
57
+ width.value = Math.max(1, root.value!.clientWidth)
58
+ height.value = Math.max(1, root.value!.clientHeight)
59
+ }
60
+ measure()
61
+ observer = new ResizeObserver(measure)
62
+ observer.observe(root.value)
63
+ })
64
+ onUnmounted(() => observer?.disconnect())
65
+
66
+ const domain = computed(() => {
67
+ const values = props.baseline === undefined ? props.data : [...props.data, props.baseline]
68
+ let lo = props.min ?? (props.type === 'bar' ? Math.min(0, ...values) : Math.min(...values))
69
+ let hi = props.max ?? Math.max(...values)
70
+ if (!props.data.length) return { lo: 0, hi: 1 }
71
+ if (hi === lo) {
72
+ hi += 1
73
+ lo -= props.type === 'bar' ? 0 : 1
74
+ }
75
+ return { lo, hi }
76
+ })
77
+ // Values as 0..1 of the scale; these are what spring when the data changes
78
+ const targets = computed(() => props.data.map((v) => (v - domain.value.lo) / (domain.value.hi - domain.value.lo)))
79
+ const shown = ref<number[]>([...targets.value])
80
+ const reduceMotion = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches
81
+ // In thousandths: useSpring settles within 0.05 of the target, which on a 0..1 scale would cut the last 5% short
82
+ const { snap } = useSpring(() => targets.value.map((v) => v * 1000), (v) => (shown.value = v.map((n) => n / 1000)), DEFAULT_SPATIAL)
83
+ watch(targets, () => {
84
+ if (!props.animate || reduceMotion()) snap()
85
+ })
86
+
87
+ const pad = computed(() => (props.type === 'bar' ? 0 : Math.max(props.strokeWidth, props.showLast || props.interactive ? props.strokeWidth * 2 + 1 : 0)))
88
+ const x = (i: number, n = shown.value.length) =>
89
+ props.type === 'bar' ? ((i + 0.5) / n) * width.value : n < 2 ? width.value / 2 : pad.value + (i / (n - 1)) * (width.value - pad.value * 2)
90
+ const y = (t: number) => pad.value + (1 - t) * (height.value - pad.value * 2)
91
+ const points = computed(() => shown.value.map((t, i) => [x(i), y(t)] as const))
92
+
93
+ // Monotone cubic (Fritsch–Carlson): a smooth curve that never bulges past its points
94
+ function curve(pts: readonly (readonly [number, number])[]) {
95
+ if (pts.length < 2) return pts.length ? `M${pts[0]![0]},${pts[0]![1]}` : ''
96
+ if (!props.smooth) return pts.map(([px, py], i) => `${i ? 'L' : 'M'}${px.toFixed(2)},${py.toFixed(2)}`).join('')
97
+ const n = pts.length
98
+ const dx = [], dy = [], m = [], tan: number[] = []
99
+ for (let i = 0; i < n - 1; i++) {
100
+ dx.push(pts[i + 1]![0] - pts[i]![0])
101
+ dy.push(pts[i + 1]![1] - pts[i]![1])
102
+ m.push(dy[i]! / dx[i]!)
103
+ }
104
+ tan.push(m[0]!)
105
+ for (let i = 1; i < n - 1; i++) tan.push(m[i - 1]! * m[i]! <= 0 ? 0 : (m[i - 1]! + m[i]!) / 2)
106
+ tan.push(m[n - 2]!)
107
+ for (let i = 0; i < n - 1; i++) {
108
+ if (m[i] === 0) {
109
+ tan[i] = 0
110
+ tan[i + 1] = 0
111
+ continue
112
+ }
113
+ const a = tan[i]! / m[i]!
114
+ const b = tan[i + 1]! / m[i]!
115
+ const h = a * a + b * b
116
+ if (h > 9) {
117
+ const k = 3 / Math.sqrt(h)
118
+ tan[i] = k * a * m[i]!
119
+ tan[i + 1] = k * b * m[i]!
120
+ }
121
+ }
122
+ let d = `M${pts[0]![0].toFixed(2)},${pts[0]![1].toFixed(2)}`
123
+ for (let i = 0; i < n - 1; i++) {
124
+ const [x0, y0] = pts[i]!
125
+ const [x1, y1] = pts[i + 1]!
126
+ const c = dx[i]! / 3
127
+ d += `C${(x0 + c).toFixed(2)},${(y0 + tan[i]! * c).toFixed(2)} ${(x1 - c).toFixed(2)},${(y1 - tan[i + 1]! * c).toFixed(2)} ${x1.toFixed(2)},${y1.toFixed(2)}`
128
+ }
129
+ return d
130
+ }
131
+
132
+ const linePath = computed(() => curve(points.value))
133
+ const areaPath = computed(() => {
134
+ const pts = points.value
135
+ if (pts.length < 2) return ''
136
+ const bottom = height.value
137
+ return `${linePath.value}L${pts[pts.length - 1]![0].toFixed(2)},${bottom}L${pts[0]![0].toFixed(2)},${bottom}Z`
138
+ })
139
+ const bars = computed(() => {
140
+ const n = shown.value.length
141
+ const slot = width.value / Math.max(1, n)
142
+ const w = Math.max(1, slot * 0.68)
143
+ const zero = y(Math.max(0, Math.min(1, -domain.value.lo / (domain.value.hi - domain.value.lo))))
144
+ return shown.value.map((t, i) => {
145
+ const top = y(t)
146
+ return { x: i * slot + (slot - w) / 2, y: Math.min(top, zero), w, h: Math.max(1, Math.abs(zero - top)) }
147
+ })
148
+ })
149
+ const baselineY = computed(() =>
150
+ props.baseline === undefined ? undefined : y((props.baseline - domain.value.lo) / (domain.value.hi - domain.value.lo)),
151
+ )
152
+
153
+ // Hover
154
+ const hoverIndex = ref<number | null>(null)
155
+ function onMove(e: PointerEvent) {
156
+ if (!props.interactive || !root.value || !props.data.length) return
157
+ const r = root.value.getBoundingClientRect()
158
+ const px = e.clientX - r.left
159
+ let best = 0
160
+ for (let i = 1; i < props.data.length; i++) if (Math.abs(x(i, props.data.length) - px) < Math.abs(x(best, props.data.length) - px)) best = i
161
+ if (best !== hoverIndex.value) {
162
+ hoverIndex.value = best
163
+ emit('hover', best)
164
+ }
165
+ }
166
+ function onLeave() {
167
+ if (hoverIndex.value === null) return
168
+ hoverIndex.value = null
169
+ emit('hover', null)
170
+ }
171
+ const dotIndex = computed(() => hoverIndex.value ?? (props.showLast && props.type !== 'bar' ? shown.value.length - 1 : null))
172
+
173
+ const t = useLocale()
174
+ const summary = computed(() => {
175
+ if (props.label) return props.label
176
+ if (!props.data.length) return ''
177
+ const fmt = new Intl.NumberFormat(t.lang, { maximumFractionDigits: 2 })
178
+ return t.sparklineSummary
179
+ .replace('{first}', fmt.format(props.data[0]!))
180
+ .replace('{last}', fmt.format(props.data[props.data.length - 1]!))
181
+ .replace('{min}', fmt.format(Math.min(...props.data)))
182
+ .replace('{max}', fmt.format(Math.max(...props.data)))
183
+ })
184
+ const gradientId = `m3-spark-${useId()}`
185
+ </script>
186
+
187
+ <template>
188
+ <span ref="root" class="m3-sparkline" role="img" :aria-label="summary" @pointermove="onMove" @pointerleave="onLeave">
189
+ <svg :viewBox="`0 0 ${width} ${height}`" :width="width" :height="height" aria-hidden="true">
190
+ <defs v-if="type === 'area'">
191
+ <linearGradient :id="gradientId" x1="0" y1="0" x2="0" y2="1">
192
+ <stop offset="0" :stop-color="stroke" stop-opacity="0.32" />
193
+ <stop offset="1" :stop-color="stroke" stop-opacity="0" />
194
+ </linearGradient>
195
+ </defs>
196
+ <line
197
+ v-if="baselineY !== undefined"
198
+ x1="0"
199
+ :x2="width"
200
+ :y1="baselineY"
201
+ :y2="baselineY"
202
+ stroke="var(--color-outline)"
203
+ stroke-width="1"
204
+ stroke-dasharray="3 3"
205
+ />
206
+ <template v-if="type === 'bar'">
207
+ <rect
208
+ v-for="(b, i) in bars"
209
+ :key="i"
210
+ :x="b.x"
211
+ :y="b.y"
212
+ :width="b.w"
213
+ :height="b.h"
214
+ :rx="Math.min(b.w / 2, 2)"
215
+ :fill="stroke"
216
+ :opacity="hoverIndex === null || hoverIndex === i ? 1 : 0.45"
217
+ />
218
+ </template>
219
+ <template v-else>
220
+ <path v-if="type === 'area'" :d="areaPath" :fill="`url(#${gradientId})`" />
221
+ <path :d="linePath" fill="none" :stroke="stroke" :stroke-width="strokeWidth" stroke-linecap="round" stroke-linejoin="round" />
222
+ <circle
223
+ v-if="dotIndex !== null && points[dotIndex]"
224
+ :cx="points[dotIndex]![0]"
225
+ :cy="points[dotIndex]![1]"
226
+ :r="strokeWidth + 1"
227
+ :fill="stroke"
228
+ stroke="var(--color-surface)"
229
+ :stroke-width="Math.max(1, strokeWidth / 2)"
230
+ />
231
+ </template>
232
+ </svg>
233
+ </span>
234
+ </template>
235
+
236
+ <style>
237
+ /* Defaults in the base layer so a size class on the component wins (see MShape). */
238
+ @layer base {
239
+ .m3-sparkline {
240
+ display: inline-block;
241
+ width: 6rem;
242
+ height: 1.75rem;
243
+ vertical-align: middle;
244
+ }
245
+ }
246
+ .m3-sparkline > svg {
247
+ display: block;
248
+ overflow: visible;
249
+ }
250
+ </style>
@@ -10,6 +10,7 @@ import { computed, onMounted, onUnmounted, ref } from 'vue'
10
10
  import MIcon from './MIcon.vue'
11
11
  import { vRipple } from '../directives/vRipple'
12
12
  import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
13
+ import { useLocale } from '../composables/useLocale'
13
14
 
14
15
  export interface SplitButtonItem {
15
16
  label: string
@@ -18,6 +19,7 @@ export interface SplitButtonItem {
18
19
  onClick?: () => void
19
20
  }
20
21
 
22
+ const locale = useLocale()
21
23
  defineOptions({ inheritAttrs: false })
22
24
 
23
25
  const props = withDefaults(defineProps<{
@@ -203,6 +205,7 @@ onUnmounted(() => {
203
205
 
204
206
  <!-- Toggle -->
205
207
  <button
208
+ :aria-label="locale.menu" aria-haspopup="menu" :aria-expanded="open"
206
209
  type="button"
207
210
  class="toggle-btn relative flex cursor-pointer items-center justify-center overflow-hidden"
208
211
  :class="[
@@ -189,6 +189,7 @@ onBeforeUnmount(() => {
189
189
  />
190
190
  <MSpinner v-if="loading" :size="20" class="shrink-0 text-primary" />
191
191
  <button
192
+ :aria-label="locale.clearSearch"
192
193
  v-else-if="hasQuery"
193
194
  type="button"
194
195
  class="flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant hover:bg-on-surface/8"
@@ -272,6 +272,7 @@ const hasActions = computed(() => !!slots['row-actions'])
272
272
  class="w-full bg-transparent text-body-medium text-on-surface outline-none placeholder:text-on-surface-variant"
273
273
  />
274
274
  <button
275
+ type="button" :aria-label="locale.clearSearch"
275
276
  v-if="search"
276
277
  class="text-on-surface-variant transition-colors hover:text-on-surface"
277
278
  @click="search = ''"
@@ -9,7 +9,9 @@ import { computed, ref, useId } from 'vue'
9
9
  import MIcon from './MIcon.vue'
10
10
  import { useFieldBg } from '../composables/useFieldBg'
11
11
  import { useDebounce } from '../composables/useDebounce'
12
+ import { useLocale } from '../composables/useLocale'
12
13
 
14
+ const locale = useLocale()
13
15
  const props = withDefaults(
14
16
  defineProps<{
15
17
  /** Array of tags (v-model) */
@@ -225,6 +227,7 @@ const labelClasses = computed(() => {
225
227
  >
226
228
  {{ tag }}
227
229
  <button
230
+ :aria-label="`${locale.remove} ${tag}`"
228
231
  v-if="!disabled"
229
232
  type="button"
230
233
  class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
@@ -261,6 +264,7 @@ const labelClasses = computed(() => {
261
264
  </label>
262
265
 
263
266
  <button
267
+ :aria-label="locale.clear"
264
268
  v-if="clearable && hasValue && !disabled"
265
269
  type="button"
266
270
  class="absolute right-2 top-4 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
@@ -11,7 +11,9 @@ import { computed, ref, useId, useSlots } from "vue";
11
11
  import MIcon from "./MIcon.vue";
12
12
  import { useFieldBg } from "../composables/useFieldBg";
13
13
  import { useDebounce } from "../composables/useDebounce";
14
+ import { useLocale } from '../composables/useLocale'
14
15
 
16
+ const locale = useLocale()
15
17
  const props = withDefaults(
16
18
  defineProps<{
17
19
  /** Bound value (v-model) */
@@ -214,6 +216,7 @@ function onInput(event: Event) {
214
216
  <slot name="trailing" />
215
217
  </div>
216
218
  <button
219
+ :aria-label="locale.clear"
217
220
  v-else-if="showClear"
218
221
  type="button"
219
222
  class="absolute right-3 top-1/2 -translate-y-1/2 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
@@ -225,6 +225,7 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
225
225
  {{ currentStep + 1 }} / {{ steps.length }}
226
226
  </span>
227
227
  <button
228
+ :aria-label="locale.close"
228
229
  type="button"
229
230
  class="flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8"
230
231
  @click="close"
@@ -145,6 +145,7 @@ function alignClass(a?: string) { return a === 'center' ? 'text-center' : a ===
145
145
  <!-- First column gets indent + expand icon -->
146
146
  <div v-if="ci === 0" class="flex items-center gap-1" :style="{ paddingLeft: `${item.depth * indent}px` }">
147
147
  <button
148
+ :aria-label="isExpanded(item.row) ? locale.collapse : locale.expand" :aria-expanded="isExpanded(item.row)"
148
149
  v-if="item.hasChildren"
149
150
  type="button"
150
151
  class="flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-transform duration-200 hover:bg-on-surface/8"
@@ -4,7 +4,9 @@ import MTreeNode from './_MTreeNode.vue'
4
4
  import MCheckbox from './MCheckbox.vue'
5
5
  import MIcon from './MIcon.vue'
6
6
  import type { TreeContext, TreeNode } from './MTree.vue'
7
+ import { useLocale } from '../composables/useLocale'
7
8
 
9
+ const locale = useLocale()
8
10
  const props = defineProps<{ node: TreeNode; depth: number }>()
9
11
 
10
12
  const tree = inject<TreeContext>('m-tree')!
@@ -93,6 +95,7 @@ function onAfterLeave(el: Element) {
93
95
  <div class="flex w-6 shrink-0 items-center justify-center">
94
96
  <!-- Chevron for branch nodes -->
95
97
  <button
98
+ :aria-label="isExpanded ? locale.collapse : locale.expand"
96
99
  v-if="hasChildren"
97
100
  type="button"
98
101
  class="flex h-5 w-5 items-center justify-center rounded text-on-surface-variant transition-transform duration-200"
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Internal (not exported from index.ts): where each item of a segmented list sits in its run, for
3
+ * SegmentedListItem's segmentedShapes(index, count). A run is consecutive `role="listitem"` children of `el`;
4
+ * anything else (a subheader, an MListGroup) ends it. Used by MList and by MListGroup for its own items.
5
+ */
6
+ import { onMounted, onUnmounted, shallowRef, type Ref } from 'vue'
7
+
8
+ export type SegmentPosition = 'single' | 'first' | 'middle' | 'last'
9
+
10
+ export function useSegmentRuns(el: Ref<HTMLElement | undefined>) {
11
+ const positions = shallowRef(new Map<Element, SegmentPosition>())
12
+
13
+ function measure() {
14
+ const map = new Map<Element, SegmentPosition>()
15
+ let run: Element[] = []
16
+ const flush = () => {
17
+ run.forEach((item, i) => map.set(item, run.length === 1 ? 'single' : i === 0 ? 'first' : i === run.length - 1 ? 'last' : 'middle'))
18
+ run = []
19
+ }
20
+ for (const child of el.value?.children ?? []) {
21
+ if (child.getAttribute('role') === 'listitem') run.push(child)
22
+ else flush()
23
+ }
24
+ flush()
25
+ positions.value = map
26
+ }
27
+
28
+ let observer: MutationObserver | undefined
29
+ onMounted(() => {
30
+ measure()
31
+ if (el.value) {
32
+ observer = new MutationObserver(measure)
33
+ observer.observe(el.value, { childList: true })
34
+ }
35
+ })
36
+ onUnmounted(() => observer?.disconnect())
37
+
38
+ return (item: Element | null | undefined) => (item ? positions.value.get(item) : undefined)
39
+ }