@m3ui-vue/m3ui-vue 1.1.2 → 1.1.4

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 (128) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +202 -10
  3. package/dist/{MIcon-DLOkQduI.js → MIcon-Bxh9j135.js} +15 -8
  4. package/dist/MIcon-Bxh9j135.js.map +1 -0
  5. package/dist/{MMenuItem-DVxKEv1W.js → MMenuItem-BfjqwcYP.js} +85 -64
  6. package/dist/MMenuItem-BfjqwcYP.js.map +1 -0
  7. package/dist/MSlider-JflHJ70q.js +1525 -0
  8. package/dist/MSlider-JflHJ70q.js.map +1 -0
  9. package/dist/{MTextField-rML9jnXs.js → MTextField-NaIB6RbM.js} +68 -66
  10. package/dist/MTextField-NaIB6RbM.js.map +1 -0
  11. package/dist/api.json +1 -1
  12. package/dist/code-editor.js +2 -2
  13. package/dist/components/MAnimatedNumber.vue.d.ts +29 -0
  14. package/dist/components/MButton.vue.d.ts +2 -0
  15. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  16. package/dist/components/MDialog.vue.d.ts +8 -5
  17. package/dist/components/MFlex.vue.d.ts +1 -1
  18. package/dist/components/MIcon.vue.d.ts +2 -0
  19. package/dist/components/MIconButton.vue.d.ts +2 -0
  20. package/dist/components/MListGroup.vue.d.ts +23 -0
  21. package/dist/components/MListItem.vue.d.ts +5 -5
  22. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  23. package/dist/components/MScheduler.vue.d.ts +2 -2
  24. package/dist/components/MScheme.vue.d.ts +60 -0
  25. package/dist/components/MSparkline.vue.d.ts +41 -0
  26. package/dist/components/MSplitter.vue.d.ts +1 -1
  27. package/dist/components/MStack.vue.d.ts +1 -1
  28. package/dist/components/MToolbar.vue.d.ts +32 -5
  29. package/dist/components/MWindow.vue.d.ts +2 -2
  30. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  31. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  32. package/dist/composables/_containerTransform.d.ts +48 -0
  33. package/dist/composables/_useSegmentRuns.d.ts +8 -0
  34. package/dist/composables/dynamicColor.d.ts +11 -0
  35. package/dist/composables/useColorPalette.d.ts +3 -1
  36. package/dist/composables/useConfetti.d.ts +32 -0
  37. package/dist/composables/useContainerTransform.d.ts +30 -0
  38. package/dist/composables/useLocale.d.ts +9 -0
  39. package/dist/index.d.ts +10 -1
  40. package/dist/locales/index.js +35 -0
  41. package/dist/locales/index.js.map +1 -1
  42. package/dist/m3ui-vue.css +1 -1
  43. package/dist/m3ui.js +16844 -15530
  44. package/dist/m3ui.js.map +1 -1
  45. package/dist/map.js +55 -55
  46. package/dist/{material-color-utilities-Cktu8DBU.js → material-color-utilities-C_iikgRm.js} +928 -603
  47. package/dist/material-color-utilities-C_iikgRm.js.map +1 -0
  48. package/dist/rich-text-editor.js +11 -11
  49. package/dist/styles.css +1 -1
  50. package/dist/terminal.js +1 -1
  51. package/dist/{useLocale-CqQrhWFl.js → useLocale-CXibICQA.js} +6 -1
  52. package/dist/useLocale-CXibICQA.js.map +1 -0
  53. package/package.json +2 -1
  54. package/src/__tests__/MAnimatedNumber.test.ts +128 -0
  55. package/src/__tests__/MContainerTransform.test.ts +279 -0
  56. package/src/__tests__/MDialog.test.ts +27 -0
  57. package/src/__tests__/MIcon.test.ts +19 -0
  58. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  59. package/src/__tests__/MListItemShape.test.ts +42 -5
  60. package/src/__tests__/MListKeyboard.test.ts +90 -0
  61. package/src/__tests__/MMapTools.test.ts +2 -1
  62. package/src/__tests__/MNavigationRail.test.ts +33 -0
  63. package/src/__tests__/MScheme.test.ts +107 -0
  64. package/src/__tests__/MSlider.test.ts +161 -0
  65. package/src/__tests__/MSparkline.test.ts +96 -0
  66. package/src/__tests__/MToolbar.test.ts +157 -0
  67. package/src/__tests__/attrsFallthrough.test.ts +6 -0
  68. package/src/__tests__/hydration.test.ts +25 -0
  69. package/src/__tests__/iconButtonNames.test.ts +124 -0
  70. package/src/__tests__/ssr.test.ts +1 -0
  71. package/src/__tests__/useConfetti.test.ts +81 -0
  72. package/src/components/MAnimatedNumber.vue +327 -0
  73. package/src/components/MAutocomplete.vue +34 -4
  74. package/src/components/MBottomSheet.vue +1 -0
  75. package/src/components/MButton.vue +4 -2
  76. package/src/components/MContainerTransform.vue +321 -0
  77. package/src/components/MDataTable.vue +1 -1
  78. package/src/components/MDialog.vue +31 -6
  79. package/src/components/MFab.vue +10 -5
  80. package/src/components/MIcon.vue +11 -4
  81. package/src/components/MIconButton.vue +3 -1
  82. package/src/components/MList.vue +33 -31
  83. package/src/components/MListGroup.vue +66 -0
  84. package/src/components/MListItem.vue +138 -84
  85. package/src/components/MMaskField.vue +3 -0
  86. package/src/components/MMultiAutocomplete.vue +5 -1
  87. package/src/components/MMultiSelect.vue +19 -9
  88. package/src/components/MNavigationRail.vue +40 -10
  89. package/src/components/MScheme.vue +162 -0
  90. package/src/components/MSearchBar.vue +2 -0
  91. package/src/components/MSelect.vue +44 -10
  92. package/src/components/MSideSheet.vue +3 -0
  93. package/src/components/MSimpleCarousel.vue +6 -0
  94. package/src/components/MSlider.vue +161 -42
  95. package/src/components/MSparkline.vue +250 -0
  96. package/src/components/MSplitButton.vue +3 -0
  97. package/src/components/MSpotlightSearch.vue +1 -0
  98. package/src/components/MTable.vue +1 -0
  99. package/src/components/MTagInput.vue +4 -0
  100. package/src/components/MTextField.vue +3 -0
  101. package/src/components/MToolbar.vue +256 -15
  102. package/src/components/MTour.vue +1 -0
  103. package/src/components/MTreeTable.vue +1 -0
  104. package/src/components/_MToolbarFab.vue +14 -0
  105. package/src/components/_MTreeNode.vue +3 -0
  106. package/src/composables/_containerTransform.ts +179 -0
  107. package/src/composables/_useEscapeStack.ts +2 -0
  108. package/src/composables/_useSegmentRuns.ts +39 -0
  109. package/src/composables/dynamicColor.ts +66 -0
  110. package/src/composables/useColorPalette.ts +2 -2
  111. package/src/composables/useConfetti.ts +204 -0
  112. package/src/composables/useContainerTransform.ts +59 -0
  113. package/src/composables/useLocale.ts +14 -0
  114. package/src/index.ts +10 -1
  115. package/src/locales/de.ts +5 -0
  116. package/src/locales/es.ts +5 -0
  117. package/src/locales/fr.ts +5 -0
  118. package/src/locales/ja.ts +5 -0
  119. package/src/locales/ko.ts +5 -0
  120. package/src/locales/pt.ts +5 -0
  121. package/src/locales/zh.ts +5 -0
  122. package/dist/MIcon-DLOkQduI.js.map +0 -1
  123. package/dist/MMenuItem-DVxKEv1W.js.map +0 -1
  124. package/dist/MSlider-BXsBv0ox.js +0 -1402
  125. package/dist/MSlider-BXsBv0ox.js.map +0 -1
  126. package/dist/MTextField-rML9jnXs.js.map +0 -1
  127. package/dist/material-color-utilities-Cktu8DBU.js.map +0 -1
  128. package/dist/useLocale-CqQrhWFl.js.map +0 -1
@@ -6,8 +6,9 @@
6
6
  * @event update:modelValue Emitted while dragging and on key presses, with the new value (a `[low, high]` pair
7
7
  * for the range variant).
8
8
  */
9
- import { computed, onBeforeUnmount, ref } from 'vue'
9
+ import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
10
10
  import MIcon from './MIcon.vue'
11
+ import { useLocale } from '../composables/useLocale'
11
12
 
12
13
  const props = withDefaults(
13
14
  defineProps<{
@@ -63,9 +64,30 @@ const props = withDefaults(
63
64
 
64
65
  const emit = defineEmits<{ 'update:modelValue': [number | [number, number]] }>()
65
66
 
67
+ const t = useLocale()
66
68
  const trackEl = ref<HTMLElement>()
69
+ const thumbEls = ref<HTMLElement[]>([])
70
+ // Range: 0 = the start (low) thumb, 1 = the end (high) one
67
71
  const dragging = ref<false | 'single' | 0 | 1>(false)
68
72
  const focused = ref(false)
73
+ const focusedThumb = ref<0 | 1 | null>(null)
74
+ // Range: a press focuses the thumb it moves (so the arrows move that one next), from script, which browsers take as
75
+ // :focus-visible. The ring is ours instead: only for focus from the keyboard, or once the keys are used after a press
76
+ const keyboardThumb = ref<0 | 1 | null>(null)
77
+ let focusingFromPointer = false
78
+ function focusThumb(idx: 0 | 1) {
79
+ focusingFromPointer = true
80
+ thumbEls.value[idx]?.focus({ preventScroll: true })
81
+ focusingFromPointer = false
82
+ }
83
+ function onThumbFocus(idx: 0 | 1) {
84
+ focusedThumb.value = idx
85
+ keyboardThumb.value = focusingFromPointer ? null : idx
86
+ }
87
+ function onThumbBlur() {
88
+ focusedThumb.value = null
89
+ keyboardThumb.value = null
90
+ }
69
91
  const isVertical = computed(() => props.orientation === 'vertical')
70
92
  const isRange = computed(() => props.variant === 'range')
71
93
  const isCentered = computed(() => props.variant === 'centered')
@@ -92,16 +114,56 @@ const centerPct = computed(() => toPct(0))
92
114
  // Standard never gets a start indicator at all (matches the official M3
93
115
  // slider: only the far/unreached end is ever marked).
94
116
  const startDotHidden = computed(() => {
117
+ if (startLen.value < s.value.dotInset + s.value.dot / 2) return true
95
118
  if (props.variant === 'centered') return Math.min(pctLo.value, centerPct.value) <= 0
96
119
  if (props.variant === 'range') return pctLo.value <= 0
97
120
  return true
98
121
  })
99
122
  const endDotHidden = computed(() => {
123
+ if (endLen.value < s.value.dotInset + s.value.dot / 2) return true
100
124
  if (props.variant === 'centered') return Math.max(pctLo.value, centerPct.value) >= 100
101
125
  if (props.variant === 'range') return pctHi.value >= 100
102
126
  return pctLo.value >= 100
103
127
  })
104
128
 
129
+ // Near the ends, the inactive piece between a thumb and the track's end gets shorter than its own corner: like
130
+ // Compose's Slider (drawTrack only draws an inactive piece longer than its corner radius, with its stop indicator),
131
+ // it goes, and the dot goes as soon as it no longer fits inside it (it was left floating in the thumb's gap).
132
+ // Needs the track's length in px, measured; before that (server render) both behave as before.
133
+ const trackLen = ref(0)
134
+ let resizeObserver: ResizeObserver | undefined
135
+ const measureTrack = () => {
136
+ const el = trackEl.value
137
+ if (el) trackLen.value = isVertical.value ? el.offsetHeight : el.offsetWidth
138
+ }
139
+ onMounted(() => {
140
+ measureTrack()
141
+ if (typeof ResizeObserver === 'undefined' || !trackEl.value) return
142
+ resizeObserver = new ResizeObserver(measureTrack)
143
+ resizeObserver.observe(trackEl.value)
144
+ })
145
+ onBeforeUnmount(() => resizeObserver?.disconnect())
146
+ /** A thumb's clamped position (clampedPos) in px from the start */
147
+ const posPx = (pct: number) => {
148
+ const inset = s.value.thumbInset
149
+ return Math.min(Math.max((pct / 100) * trackLen.value, inset), trackLen.value - inset)
150
+ }
151
+ // Length of the inactive piece at each end that a thumb bounds (Infinity where no thumb does, or before measuring)
152
+ const startLen = computed(() => {
153
+ if (!trackLen.value) return Infinity
154
+ if (props.variant === 'range') return posPx(pctLo.value) - gap.value
155
+ if (props.variant === 'centered' && pctLo.value <= centerPct.value) return posPx(pctLo.value) - gap.value
156
+ return Infinity
157
+ })
158
+ const endLen = computed(() => {
159
+ if (!trackLen.value) return Infinity
160
+ if (props.variant === 'range') return trackLen.value - posPx(pctHi.value) - gap.value
161
+ if (props.variant === 'centered' && pctLo.value < centerPct.value) return Infinity
162
+ return trackLen.value - posPx(pctLo.value) - gap.value
163
+ })
164
+ const startPieceHidden = computed(() => startLen.value <= fullR.value)
165
+ const endPieceHidden = computed(() => endLen.value <= fullR.value)
166
+
105
167
  const sizeMap = {
106
168
  // thumbH 44 matches SliderTokens.HandleHeight exactly — hitArea bumped from
107
169
  // 38 to 46 to keep containing it (was sized for the old 32px handle).
@@ -177,19 +239,33 @@ function valueFromEvent(e: PointerEvent) {
177
239
  return clamp(props.min + ratioFromEvent(e) * (props.max - props.min))
178
240
  }
179
241
 
242
+ // Range: like Compose's RangeSlider, a thumb never passes the other (start ∈ [min, end], end ∈ [start, max]), so
243
+ // the emitted pair is always [low, high]. A press takes the thumb on its side; on two overlapping thumbs, the
244
+ // first move's direction picks one (Compose's fix for taps and drags when thumbs overlap).
245
+ let overlapPress = false
246
+ function rangeValue(idx: 0 | 1, v: number): [number, number] {
247
+ const { lo, hi } = val.value
248
+ return idx === 0 ? [Math.min(v, hi), hi] : [lo, Math.max(v, lo)]
249
+ }
250
+
180
251
  function onPointerDown(e: PointerEvent) {
181
252
  if (props.disabled) return
182
253
  e.preventDefault()
183
254
  const v = valueFromEvent(e)
184
255
  if (isRange.value) {
185
- const cur = props.modelValue as [number, number]
186
- const dist0 = Math.abs(v - cur[0])
187
- const dist1 = Math.abs(v - cur[1])
188
- const idx: 0 | 1 = dist0 <= dist1 ? 0 : 1
256
+ const { lo, hi } = val.value
257
+ overlapPress = false
258
+ let idx: 0 | 1
259
+ if (v <= lo && v < hi) idx = 0
260
+ else if (v >= hi && v > lo) idx = 1
261
+ else if (lo === hi) {
262
+ // Right on two overlapping thumbs: wait for the drag's direction
263
+ idx = 0
264
+ overlapPress = true
265
+ } else idx = Math.abs(v - lo) <= Math.abs(v - hi) ? 0 : 1
189
266
  dragging.value = idx
190
- const next: [number, number] = [cur[0], cur[1]]
191
- next[idx] = v
192
- emit('update:modelValue', next)
267
+ focusThumb(idx)
268
+ if (!overlapPress) emit('update:modelValue', rangeValue(idx, v))
193
269
  } else {
194
270
  dragging.value = 'single'
195
271
  emit('update:modelValue', v)
@@ -203,10 +279,13 @@ function onPointerMove(e: PointerEvent) {
203
279
  if (dragging.value === false) return
204
280
  const v = valueFromEvent(e)
205
281
  if (isRange.value) {
206
- const cur = props.modelValue as [number, number]
207
- const next: [number, number] = [cur[0], cur[1]]
208
- next[dragging.value as 0 | 1] = v
209
- emit('update:modelValue', next)
282
+ if (overlapPress) {
283
+ if (v === val.value.lo) return
284
+ overlapPress = false
285
+ dragging.value = v > val.value.lo ? 1 : 0
286
+ focusThumb(dragging.value)
287
+ }
288
+ emit('update:modelValue', rangeValue(dragging.value as 0 | 1, v))
210
289
  } else {
211
290
  emit('update:modelValue', v)
212
291
  }
@@ -214,26 +293,39 @@ function onPointerMove(e: PointerEvent) {
214
293
 
215
294
  function onPointerUp() {
216
295
  dragging.value = false
296
+ overlapPress = false
217
297
  window.removeEventListener('pointermove', onPointerMove)
218
298
  window.removeEventListener('pointerup', onPointerUp)
219
299
  window.removeEventListener('pointercancel', onPointerUp)
220
300
  }
221
301
 
302
+ const KEY_DELTA: Record<string, number> = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1 }
303
+
222
304
  function onKeyDown(e: KeyboardEvent) {
223
305
  if (props.disabled) return
224
- const d: Record<string, number> = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1 }
225
- const delta = d[e.key]
306
+ const delta = KEY_DELTA[e.key]
226
307
  if (delta !== undefined) {
227
308
  e.preventDefault()
228
- if (isRange.value) {
229
- const cur = props.modelValue as [number, number]
230
- emit('update:modelValue', [clamp(cur[0] + delta * props.step), cur[1]])
231
- } else {
232
- emit('update:modelValue', clamp((props.modelValue as number) + delta * props.step))
233
- }
309
+ emit('update:modelValue', clamp((props.modelValue as number) + delta * props.step))
234
310
  }
235
- if (e.key === 'Home') { e.preventDefault(); emit('update:modelValue', isRange.value ? [props.min, (props.modelValue as [number, number])[1]] : props.min) }
236
- if (e.key === 'End') { e.preventDefault(); emit('update:modelValue', isRange.value ? [(props.modelValue as [number, number])[0], props.max] : props.max) }
311
+ if (e.key === 'Home') { e.preventDefault(); emit('update:modelValue', props.min) }
312
+ if (e.key === 'End') { e.preventDefault(); emit('update:modelValue', props.max) }
313
+ }
314
+
315
+ // Range: each thumb is a slider of its own, moved by its keys within the other thumb
316
+ function onThumbKeyDown(idx: 0 | 1, e: KeyboardEvent) {
317
+ if (props.disabled) return
318
+ const { lo, hi } = val.value
319
+ const cur = idx === 0 ? lo : hi
320
+ const delta = KEY_DELTA[e.key]
321
+ let next: number | undefined
322
+ if (delta !== undefined) next = clamp(cur + delta * props.step)
323
+ else if (e.key === 'Home') next = idx === 0 ? props.min : lo
324
+ else if (e.key === 'End') next = idx === 0 ? hi : props.max
325
+ if (next === undefined) return
326
+ e.preventDefault()
327
+ keyboardThumb.value = idx
328
+ emit('update:modelValue', rangeValue(idx, next))
237
329
  }
238
330
 
239
331
  onBeforeUnmount(() => {
@@ -266,6 +358,7 @@ function fillActiveSize(pct: number) {
266
358
  return `calc(${clampedPos(pct)} - ${gap.value}px)`
267
359
  }
268
360
  function fillInactiveSize(pct: number) {
361
+ if (endPieceHidden.value) return '0px'
269
362
  return `calc(100% - ${clampedPos(pct)} - ${gap.value}px)`
270
363
  }
271
364
 
@@ -276,6 +369,7 @@ function fillInactiveSize(pct: number) {
276
369
 
277
370
  // Range: both pctLo and pctHi are thumbs.
278
371
  function rangeInactiveBeforeSize() {
372
+ if (startPieceHidden.value) return '0px'
279
373
  return `calc(${clampedPos(pctLo.value)} - ${gap.value}px)`
280
374
  }
281
375
  function rangeActiveStart() {
@@ -285,6 +379,7 @@ function rangeActiveSize() {
285
379
  return `calc(${clampedPos(pctHi.value)} - ${clampedPos(pctLo.value)} - ${gap.value * 2}px)`
286
380
  }
287
381
  function rangeInactiveAfterSize() {
382
+ if (endPieceHidden.value) return '0px'
288
383
  return `calc(100% - ${clampedPos(pctHi.value)} - ${gap.value}px)`
289
384
  }
290
385
 
@@ -300,11 +395,13 @@ function centeredActiveSize() {
300
395
  : `calc(${centerPct.value}% - ${clampedPos(pctLo.value)} - ${gap.value}px)`
301
396
  }
302
397
  function centeredFarInactiveSize() {
398
+ if (endPieceHidden.value) return '0px'
303
399
  return pctLo.value >= centerPct.value
304
400
  ? `calc(100% - ${clampedPos(pctLo.value)} - ${gap.value}px)`
305
401
  : `calc(100% - ${centerPct.value}% - ${gap.value}px)`
306
402
  }
307
403
  function centeredNearInactiveSize() {
404
+ if (startPieceHidden.value) return '0px'
308
405
  return pctLo.value <= centerPct.value
309
406
  ? `calc(${clampedPos(pctLo.value)} - ${gap.value}px)`
310
407
  : `calc(${centerPct.value}% - ${gap.value}px)`
@@ -350,7 +447,7 @@ function clampedPos(pct: number) {
350
447
  return `clamp(${inset}px, ${pct}%, calc(100% - ${inset}px))`
351
448
  }
352
449
 
353
- function thumbPos(pct: number) {
450
+ function thumbPos(pct: number, idx: 0 | 1 = 0) {
354
451
  const tw = isVertical.value ? s.value.thumbH : s.value.thumbW
355
452
  const th = isVertical.value ? s.value.thumbW : s.value.thumbH
356
453
  const br = Math.min(tw, th) / 2
@@ -361,6 +458,8 @@ function thumbPos(pct: number) {
361
458
  height: `${th}px`,
362
459
  borderRadius: `${br}px`,
363
460
  backgroundColor: thumbCt.value.active,
461
+ // The keyboard focus ring takes the thumb's color (color, thumbColor), not a fixed primary
462
+ '--tw-ring-color': thumbCt.value.active,
364
463
  zIndex: '2',
365
464
  transition: nd.value ? 'left 75ms ease, bottom 75ms ease, transform 80ms ease' : 'transform 80ms ease',
366
465
  }
@@ -369,8 +468,8 @@ function thumbPos(pct: number) {
369
468
  // ratio matches SliderTokens.PressedHandleWidth/FocusHandleWidth = 2dp,
370
469
  // i.e. half of the base 4dp width — applies on keyboard focus too, not
371
470
  // just an active pointer drag (Compose's isFocused covers both).
372
- const isNarrowed = isDragging || focused.value
373
- const grow = isDragging ? 1.08 : 1
471
+ const isNarrowed = isRange.value ? dragging.value === idx || focusedThumb.value === idx : isDragging || focused.value
472
+ const grow = (isRange.value ? dragging.value === idx : isDragging) ? 1.08 : 1
374
473
  const narrow = isNarrowed ? 0.5 : 1
375
474
  if (isVertical.value) {
376
475
  base.left = '50%'
@@ -392,6 +491,7 @@ function thumbIconPos(pct: number) {
392
491
  const base: Record<string, string> = {
393
492
  position: 'absolute',
394
493
  color: thumbCt.value.active,
494
+ '--tw-ring-color': thumbCt.value.active,
395
495
  zIndex: '2',
396
496
  transition: nd.value ? 'left 75ms ease, bottom 75ms ease, transform 80ms ease' : 'transform 80ms ease',
397
497
  }
@@ -423,13 +523,13 @@ const displayValue = computed(() => {
423
523
 
424
524
  const tooltipValue = computed(() => {
425
525
  if (isRange.value && typeof dragging.value === 'number')
426
- return (props.modelValue as [number, number])[dragging.value]
526
+ return dragging.value === 0 ? val.value.lo : val.value.hi
427
527
  return props.modelValue
428
528
  })
429
529
 
430
530
  const tooltipPct = computed(() => {
431
531
  if (isRange.value && typeof dragging.value === 'number')
432
- return toPct((props.modelValue as [number, number])[dragging.value])
532
+ return dragging.value === 0 ? pctLo.value : pctHi.value
433
533
  return pctLo.value
434
534
  })
435
535
  </script>
@@ -445,13 +545,14 @@ const tooltipPct = computed(() => {
445
545
  <!-- Track area -->
446
546
  <div
447
547
  ref="trackEl"
448
- role="slider"
449
- tabindex="0"
548
+ :role="isRange ? 'group' : 'slider'"
549
+ :tabindex="isRange ? undefined : 0"
550
+ :aria-label="isRange ? label : undefined"
450
551
  :aria-valuenow="isRange ? undefined : (modelValue as number)"
451
- :aria-valuemin="min"
452
- :aria-valuemax="max"
552
+ :aria-valuemin="isRange ? undefined : min"
553
+ :aria-valuemax="isRange ? undefined : max"
453
554
  :aria-disabled="disabled || undefined"
454
- :aria-orientation="orientation"
555
+ :aria-orientation="isRange ? undefined : orientation"
455
556
  class="group relative touch-none cursor-pointer outline-none"
456
557
  :class="disabled && 'cursor-not-allowed'"
457
558
  :style="isVertical
@@ -459,8 +560,8 @@ const tooltipPct = computed(() => {
459
560
  : { height: `${s.hitArea}px`, width: '100%' }
460
561
  "
461
562
  @pointerdown="onPointerDown"
462
- @keydown="onKeyDown"
463
- @focus="focused = true"
563
+ @keydown="!isRange && onKeyDown($event)"
564
+ @focus="focused = !isRange"
464
565
  @blur="focused = false"
465
566
  >
466
567
  <!-- Track container -->
@@ -606,16 +707,34 @@ const tooltipPct = computed(() => {
606
707
  </template>
607
708
  </div>
608
709
 
609
- <!-- Thumb(s) — only the pctLo thumb takes keyboard input (arrow keys only
610
- move index 0 in range mode, see onKeyDown), so it's the only one that
611
- gets the focus-visible ring. -->
612
- <template v-if="thumbIcon">
613
- <MIcon :name="thumbIcon" :size="s.thumbIconSize" class="pointer-events-none rounded-full group-focus-visible:ring-2 group-focus-visible:ring-primary group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface" :style="thumbIconPos(pctLo)" />
614
- <MIcon v-if="isRange" :name="thumbIcon" :size="s.thumbIconSize" class="pointer-events-none" :style="thumbIconPos(pctHi)" />
710
+ <!-- Thumb(s). Standard/centered: the track is the slider and its focus rings the thumb. Range: each thumb
711
+ is a slider of its own (Compose's two semantics nodes), focusable, with its own keys and ring. -->
712
+ <template v-if="!isRange">
713
+ <MIcon v-if="thumbIcon" :name="thumbIcon" :size="s.thumbIconSize" class="pointer-events-none rounded-full group-focus-visible:ring-2 group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface" :style="thumbIconPos(pctLo)" />
714
+ <div v-else class="pointer-events-none group-focus-visible:ring-2 group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface" :style="thumbPos(pctLo)" />
615
715
  </template>
616
716
  <template v-else>
617
- <div class="pointer-events-none group-focus-visible:ring-2 group-focus-visible:ring-primary group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface" :style="thumbPos(pctLo)" />
618
- <div v-if="isRange" class="pointer-events-none" :style="thumbPos(pctHi)" />
717
+ <div
718
+ v-for="idx in ([0, 1] as const)"
719
+ :key="idx"
720
+ :ref="(el) => { if (el) thumbEls[idx] = el as HTMLElement }"
721
+ role="slider"
722
+ :tabindex="disabled ? -1 : 0"
723
+ :aria-label="idx === 0 ? t.sliderRangeStart : t.sliderRangeEnd"
724
+ :aria-valuenow="idx === 0 ? val.lo : val.hi"
725
+ :aria-valuemin="idx === 0 ? min : val.lo"
726
+ :aria-valuemax="idx === 0 ? val.hi : max"
727
+ :aria-disabled="disabled || undefined"
728
+ :aria-orientation="orientation"
729
+ class="pointer-events-none flex items-center justify-center rounded-full outline-none"
730
+ :class="keyboardThumb === idx && 'ring-2 ring-offset-2 ring-offset-surface'"
731
+ :style="thumbIcon ? thumbIconPos(idx === 0 ? pctLo : pctHi) : thumbPos(idx === 0 ? pctLo : pctHi, idx)"
732
+ @keydown="onThumbKeyDown(idx, $event)"
733
+ @focus="onThumbFocus(idx)"
734
+ @blur="onThumbBlur"
735
+ >
736
+ <MIcon v-if="thumbIcon" :name="thumbIcon" :size="s.thumbIconSize" />
737
+ </div>
619
738
  </template>
620
739
 
621
740
  <!-- Tooltip -->
@@ -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 = ''"