@m3ui-vue/m3ui-vue 0.9.1 → 0.9.2

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 (86) hide show
  1. package/README.md +41 -0
  2. package/dist/API.md +199 -54
  3. package/dist/{MTextField-pJU1vFaR.js → MTextField-Ck0oWDMk.js} +8 -2
  4. package/dist/MTextField-Ck0oWDMk.js.map +1 -0
  5. package/dist/api.json +1 -1
  6. package/dist/code-editor.js +1 -1
  7. package/dist/components/MBox.vue.d.ts +3 -3
  8. package/dist/components/MColorPicker.vue.d.ts +13 -1
  9. package/dist/components/MColorPickerModal.vue.d.ts +14 -2
  10. package/dist/components/MDragHandle.vue.d.ts +12 -0
  11. package/dist/components/MEmojiSelector.vue.d.ts +1 -1
  12. package/dist/components/MFab.vue.d.ts +1 -1
  13. package/dist/components/MFabMenu.vue.d.ts +1 -1
  14. package/dist/components/MListItem.vue.d.ts +5 -5
  15. package/dist/components/MOverlay.vue.d.ts +1 -1
  16. package/dist/components/MScrollField.vue.d.ts +40 -0
  17. package/dist/components/MScrollable.vue.d.ts +9 -0
  18. package/dist/components/MSplitter.vue.d.ts +2 -2
  19. package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
  20. package/dist/components/MTransition.vue.d.ts +34 -0
  21. package/dist/components/MWindow.vue.d.ts +1 -1
  22. package/dist/components/_MColorPanel.vue.d.ts +18 -0
  23. package/dist/composables/_colorUtils.d.ts +34 -0
  24. package/dist/composables/_themeColor.d.ts +1 -0
  25. package/dist/composables/_useSpring.d.ts +15 -0
  26. package/dist/composables/dynamicColor.d.ts +18 -0
  27. package/dist/composables/useColorPalette.d.ts +27 -0
  28. package/dist/composables/useLocale.d.ts +10 -0
  29. package/dist/index.d.ts +9 -1
  30. package/dist/locales/index.js +70 -0
  31. package/dist/locales/index.js.map +1 -1
  32. package/dist/m3ui-vue.css +1 -1
  33. package/dist/m3ui.js +4808 -3622
  34. package/dist/m3ui.js.map +1 -1
  35. package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
  36. package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
  37. package/dist/plugin.d.ts +18 -0
  38. package/dist/rich-text-editor.js +2 -2
  39. package/dist/styles/palettes.css +546 -0
  40. package/dist/styles/theme.css +77 -0
  41. package/dist/styles.css +1 -1
  42. package/dist/{useLocale-Drihe5G2.js → useLocale-CFW8cIzL.js} +11 -1
  43. package/dist/useLocale-CFW8cIzL.js.map +1 -0
  44. package/package.json +2 -1
  45. package/src/__tests__/MButtonGroup.test.ts +51 -0
  46. package/src/__tests__/MColorPicker.test.ts +141 -0
  47. package/src/__tests__/MDragHandle.test.ts +57 -0
  48. package/src/__tests__/MListItemShape.test.ts +76 -0
  49. package/src/__tests__/MScrollField.test.ts +41 -0
  50. package/src/__tests__/MScrollable.test.ts +42 -0
  51. package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
  52. package/src/__tests__/MTransition.test.ts +27 -0
  53. package/src/__tests__/dynamicColor.test.ts +191 -0
  54. package/src/components/MBox.vue +4 -2
  55. package/src/components/MButtonGroup.vue +116 -35
  56. package/src/components/MColorPicker.vue +114 -210
  57. package/src/components/MColorPickerModal.vue +50 -251
  58. package/src/components/MDragHandle.vue +54 -0
  59. package/src/components/MList.vue +33 -3
  60. package/src/components/MListItem.vue +75 -5
  61. package/src/components/MScrollField.vue +302 -0
  62. package/src/components/MScrollable.vue +160 -5
  63. package/src/components/MSplitter.vue +33 -10
  64. package/src/components/MSwipeToDismiss.vue +247 -0
  65. package/src/components/MTransition.vue +149 -0
  66. package/src/components/_MColorPanel.vue +478 -0
  67. package/src/composables/_colorUtils.ts +107 -0
  68. package/src/composables/_themeColor.ts +33 -0
  69. package/src/composables/_useSpring.ts +89 -0
  70. package/src/composables/dynamicColor.ts +85 -0
  71. package/src/composables/useColorPalette.ts +171 -25
  72. package/src/composables/useFieldBg.ts +6 -0
  73. package/src/composables/useLocale.ts +22 -0
  74. package/src/index.ts +9 -1
  75. package/src/locales/de.ts +10 -0
  76. package/src/locales/es.ts +10 -0
  77. package/src/locales/fr.ts +10 -0
  78. package/src/locales/ja.ts +10 -0
  79. package/src/locales/ko.ts +10 -0
  80. package/src/locales/pt.ts +10 -0
  81. package/src/locales/zh.ts +10 -0
  82. package/src/plugin.ts +28 -7
  83. package/src/styles/palettes.css +546 -0
  84. package/src/styles/theme.css +77 -0
  85. package/dist/MTextField-pJU1vFaR.js.map +0 -1
  86. package/dist/useLocale-Drihe5G2.js.map +0 -1
@@ -1,289 +1,88 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
- * A modal, centered color picker with saturation/brightness area, hue slider, hex input, and preset swatches —
4
- * the sibling of MColorPicker, a fully separate component rather than a shared internal. Only emits on confirm.
3
+ * A color picker in a dialog: saturation/brightness area, hue (and optional opacity) slider, eyedropper,
4
+ * HEX/RGB/HSL fields, recent colors and preset swatches. Built on MDialog; the color is only applied on confirm,
5
+ * and the preview shows it next to the original.
5
6
  *
6
7
  * @event update:modelValue Emitted when a color is confirmed — powers v-model. Only fires on confirm, not while
7
8
  * dragging
8
9
  * @event update:show Emitted when the dialog opens or closes — powers v-model:show
9
10
  */
10
- import { computed, ref, watch } from 'vue'
11
+ import { ref, watch } from 'vue'
11
12
  import MButton from './MButton.vue'
12
- import MIcon from './MIcon.vue'
13
+ import MDialog from './MDialog.vue'
14
+ import MColorPanel from './_MColorPanel.vue'
13
15
  import { useLocale } from '../composables/useLocale'
16
+ import { defaultColorPresets, normalizeHex, pushRecentColor } from '../composables/_colorUtils'
14
17
 
15
18
  const props = withDefaults(defineProps<{
16
- /** Selected color in hex format (v-model) */
19
+ /** Selected color in hex format (v-model). `#rrggbb`, or `#rrggbbaa` when `alpha` is on and the color isn't opaque. */
17
20
  modelValue: string
18
21
  /** Controls dialog visibility (v-model:show) */
19
22
  show?: boolean
20
23
  /** Preset color swatches shown in the dialog */
21
24
  presets?: string[]
22
- /** Dialog title */
25
+ /** Dialog title; defaults to the locale's `selectColor` */
23
26
  title?: string
27
+ /** Adds an opacity slider and an alpha channel to the value */
28
+ alpha?: boolean
29
+ /** Remember confirmed colors and show them above the presets (stored in localStorage, shared by every picker). */
30
+ recent?: boolean
31
+ /** How many recent colors to keep. */
32
+ recentLimit?: number
33
+ /** Show a button to pick a color from the screen, where the browser supports it (Chrome, Edge). */
34
+ eyedropper?: boolean
24
35
  }>(), {
25
36
  show: false,
26
- presets: () => [
27
- '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',
28
- '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39',
29
- '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#607d8b',
30
- ],
37
+ presets: () => defaultColorPresets,
38
+ alpha: false,
39
+ recent: true,
40
+ recentLimit: 7,
41
+ eyedropper: true,
31
42
  })
32
43
 
33
- const locale = useLocale()
44
+ const t = useLocale()
34
45
  const emit = defineEmits<{
35
46
  'update:modelValue': [string]
36
47
  'update:show': [boolean]
37
48
  }>()
38
49
 
39
- const satBrightEl = ref<HTMLElement>()
40
- const draggingSB = ref(false)
41
- const hue = ref(0)
42
- const sat = ref(100)
43
- const bright = ref(100)
44
- const hexInput = ref('')
45
-
46
- function hexToHsv(hex: string) {
47
- let c = hex.replace('#', '')
48
- if (c.length === 3) c = c[0]! + c[0]! + c[1]! + c[1]! + c[2]! + c[2]!
49
- const r = parseInt(c.substring(0, 2), 16) / 255
50
- const g = parseInt(c.substring(2, 4), 16) / 255
51
- const b = parseInt(c.substring(4, 6), 16) / 255
52
- const max = Math.max(r, g, b), min = Math.min(r, g, b)
53
- const d = max - min
54
- let h = 0
55
- if (d !== 0) {
56
- if (max === r) h = ((g - b) / d + 6) % 6
57
- else if (max === g) h = (b - r) / d + 2
58
- else h = (r - g) / d + 4
59
- h *= 60
60
- }
61
- return { h, s: max === 0 ? 0 : (d / max) * 100, v: max * 100 }
62
- }
63
-
64
- function hsvToHex(h: number, s: number, v: number) {
65
- s /= 100; v /= 100
66
- const c = v * s
67
- const x = c * (1 - Math.abs((h / 60) % 2 - 1))
68
- const m = v - c
69
- let r = 0, g = 0, b = 0
70
- if (h < 60) { r = c; g = x }
71
- else if (h < 120) { r = x; g = c }
72
- else if (h < 180) { g = c; b = x }
73
- else if (h < 240) { g = x; b = c }
74
- else if (h < 300) { r = x; b = c }
75
- else { r = c; b = x }
76
- const toHex = (n: number) => Math.round((n + m) * 255).toString(16).padStart(2, '0')
77
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`
78
- }
79
-
80
- const currentHex = computed(() => hsvToHex(hue.value, sat.value, bright.value))
81
- const hueColor = computed(() => `hsl(${hue.value}, 100%, 50%)`)
50
+ // The color being picked; becomes the value only on confirm
51
+ const draft = ref(props.modelValue)
82
52
 
83
53
  watch(() => props.show, (open) => {
84
- if (open) {
85
- const hsv = hexToHsv(props.modelValue)
86
- hue.value = hsv.h
87
- sat.value = hsv.s
88
- bright.value = hsv.v
89
- hexInput.value = props.modelValue
90
- document.addEventListener('keydown', onKeydown)
91
- document.body.style.overflow = 'hidden'
92
- } else {
93
- document.removeEventListener('keydown', onKeydown)
94
- document.body.style.overflow = ''
95
- }
96
- })
97
-
98
- function syncHex() {
99
- hexInput.value = currentHex.value
100
- }
101
-
102
- // ── Saturation / Brightness ────────────────────────────────────────
103
- function onSBPointerDown(e: PointerEvent) {
104
- e.preventDefault()
105
- draggingSB.value = true
106
- updateSB(e)
107
- ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
108
- }
109
- function onSBPointerMove(e: PointerEvent) {
110
- if (!draggingSB.value) return
111
- updateSB(e)
112
- }
113
- function onSBPointerUp() {
114
- draggingSB.value = false
115
- syncHex()
116
- }
117
- function updateSB(e: PointerEvent) {
118
- if (!satBrightEl.value) return
119
- const rect = satBrightEl.value.getBoundingClientRect()
120
- sat.value = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100))
121
- bright.value = Math.max(0, Math.min(100, (1 - (e.clientY - rect.top) / rect.height) * 100))
122
- syncHex()
123
- }
124
-
125
- function onHueInput(e: Event) {
126
- hue.value = Number((e.target as HTMLInputElement).value)
127
- syncHex()
128
- }
129
-
130
- function selectPreset(color: string) {
131
- const hsv = hexToHsv(color)
132
- hue.value = hsv.h
133
- sat.value = hsv.s
134
- bright.value = hsv.v
135
- hexInput.value = color
136
- }
54
+ if (open) draft.value = props.modelValue
55
+ }, { immediate: true })
137
56
 
138
- function onHexFieldInput(e: Event) {
139
- const v = (e.target as HTMLInputElement).value
140
- hexInput.value = v
141
- if (/^#[0-9a-fA-F]{6}$/.test(v)) {
142
- const hsv = hexToHsv(v)
143
- hue.value = hsv.h
144
- sat.value = hsv.s
145
- bright.value = hsv.v
146
- }
147
- }
148
-
149
- // ── Actions ────────────────────────────────────────────────────────
150
57
  function cancel() { emit('update:show', false) }
151
58
 
152
59
  function confirm() {
153
- emit('update:modelValue', currentHex.value)
60
+ const picked = normalizeHex(draft.value) || draft.value
61
+ if (props.recent) pushRecentColor(picked, props.recentLimit)
62
+ emit('update:modelValue', picked)
154
63
  emit('update:show', false)
155
64
  }
156
-
157
- function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
158
65
  </script>
159
66
 
160
67
  <template>
161
- <Teleport to="body">
162
- <Transition name="m3-cp-modal">
163
- <div
164
- v-if="show"
165
- class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
166
- @click.self="cancel"
167
- >
168
- <div class="cp-box w-[328px] rounded-[28px] bg-surface-container-high px-6 pt-6 pb-4 shadow-elevation-3">
169
- <!-- Header -->
170
- <div class="mb-4 flex items-center gap-3">
171
- <span
172
- class="h-10 w-10 shrink-0 rounded-full border border-outline-variant"
173
- :style="{ backgroundColor: currentHex }"
174
- />
175
- <div>
176
- <p class="text-label-medium text-on-surface-variant">
177
- {{ title || 'Select color' }}
178
- </p>
179
- <p class="font-mono text-title-medium text-on-surface">{{ currentHex }}</p>
180
- </div>
181
- </div>
182
-
183
- <!-- Saturation / Brightness area -->
184
- <div
185
- ref="satBrightEl"
186
- class="relative mb-3 h-44 w-full cursor-crosshair overflow-hidden rounded-lg"
187
- :style="{ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, ${hueColor})`, touchAction: 'none' }"
188
- @pointerdown="onSBPointerDown"
189
- @pointermove="onSBPointerMove"
190
- @pointerup="onSBPointerUp"
191
- >
192
- <div
193
- class="pointer-events-none absolute h-5 w-5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-elevation-1"
194
- :style="{
195
- left: `${sat}%`,
196
- top: `${100 - bright}%`,
197
- backgroundColor: currentHex,
198
- }"
199
- />
200
- </div>
201
-
202
- <!-- Hue slider -->
203
- <div class="mb-3">
204
- <input
205
- type="range"
206
- min="0"
207
- max="360"
208
- :value="hue"
209
- class="hue-slider h-3 w-full cursor-pointer appearance-none rounded-full outline-none"
210
- @input="onHueInput"
211
- />
212
- </div>
213
-
214
- <!-- Hex input -->
215
- <div class="mb-3">
216
- <input
217
- type="text"
218
- :value="hexInput"
219
- maxlength="7"
220
- class="w-full rounded-xs border border-outline bg-transparent px-3 py-2 font-mono text-body-medium text-on-surface caret-primary outline-none transition-colors focus:border-primary"
221
- @input="onHexFieldInput"
222
- />
223
- </div>
224
-
225
- <!-- Presets -->
226
- <div class="mb-4 flex flex-wrap gap-1.5">
227
- <button
228
- v-for="color in presets"
229
- :key="color"
230
- type="button"
231
- class="flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border transition-transform duration-100 hover:scale-110"
232
- :class="color === currentHex ? 'border-on-surface' : 'border-transparent'"
233
- :style="{ backgroundColor: color }"
234
- @click="selectPreset(color)"
235
- >
236
- <MIcon v-if="color === currentHex" name="check" :size="14" class="text-white drop-shadow-[0_1px_1px_rgba(0,0,0,0.5)]" />
237
- </button>
238
- </div>
239
-
240
- <!-- Footer -->
241
- <div class="flex justify-end gap-2">
242
- <MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
243
- <MButton variant="text" @click="confirm">OK</MButton>
244
- </div>
245
- </div>
246
- </div>
247
- </Transition>
248
- </Teleport>
68
+ <MDialog
69
+ :model-value="show"
70
+ :title="title || t.selectColor"
71
+ max-width="328px"
72
+ :closable="false"
73
+ @update:model-value="!$event && cancel()"
74
+ >
75
+ <MColorPanel
76
+ v-model="draft"
77
+ :presets="presets"
78
+ :alpha="alpha"
79
+ :recent="recent"
80
+ :eyedropper="eyedropper"
81
+ :original="modelValue"
82
+ />
83
+ <template #actions>
84
+ <MButton variant="text" @click="cancel">{{ t.cancel }}</MButton>
85
+ <MButton variant="text" @click="confirm">{{ t.confirm }}</MButton>
86
+ </template>
87
+ </MDialog>
249
88
  </template>
250
-
251
- <style scoped>
252
- .hue-slider {
253
- background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
254
- }
255
- .hue-slider::-webkit-slider-thumb {
256
- -webkit-appearance: none;
257
- width: 16px;
258
- height: 16px;
259
- border-radius: 50%;
260
- background: white;
261
- box-shadow: 0 1px 3px rgba(0,0,0,0.4);
262
- cursor: pointer;
263
- }
264
- .hue-slider::-moz-range-thumb {
265
- width: 16px;
266
- height: 16px;
267
- border-radius: 50%;
268
- background: white;
269
- box-shadow: 0 1px 3px rgba(0,0,0,0.4);
270
- border: none;
271
- cursor: pointer;
272
- }
273
- .m3-cp-modal-enter-active,
274
- .m3-cp-modal-leave-active {
275
- transition: opacity 0.15s ease;
276
- }
277
- .m3-cp-modal-enter-from,
278
- .m3-cp-modal-leave-to {
279
- opacity: 0;
280
- }
281
- .m3-cp-modal-enter-active .cp-box,
282
- .m3-cp-modal-leave-active .cp-box {
283
- transition: transform 0.15s ease;
284
- }
285
- .m3-cp-modal-enter-from .cp-box,
286
- .m3-cp-modal-leave-to .cp-box {
287
- transform: scale(0.95);
288
- }
289
- </style>
@@ -0,0 +1,54 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * M3's drag handle: the capsule users drag to resize or move something, e.g. the divider between two panes.
4
+ * Port of Compose's `VerticalDragHandle`; it only draws the handle and its pressed/dragged look, the dragging
5
+ * itself is up to the parent (MSplitter uses it).
6
+ */
7
+ import { computed, ref, watch } from 'vue'
8
+ import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
9
+
10
+ const props = withDefaults(defineProps<{
11
+ /** `vertical` is a tall capsule for horizontal drags (between side-by-side panes); `horizontal` is a wide one for vertical drags. */
12
+ orientation?: 'vertical' | 'horizontal'
13
+ /** Show the dragged look (the parent is dragging) */
14
+ dragging?: boolean
15
+ }>(), { orientation: 'vertical', dragging: false })
16
+
17
+ const pressed = ref(false)
18
+
19
+ // DragHandleTokens: 4×48dp CornerFull in Outline at rest; 12×52dp CornerMedium in OnSurface pressed or
20
+ // dragged (CornerMedium is 12dp, which on a 12dp-wide bar is still a pill). ContainerWidth (24dp) is the
21
+ // touch area. VerticalDragHandle switches sizes instantly; this springs between them (Standard FastSpatial,
22
+ // like the library's other shape changes) and fades the color, a deliberate departure.
23
+ const active = computed(() => props.dragging || pressed.value)
24
+ const barEl = ref<HTMLElement | null>(null)
25
+ const { snap } = useSpring(
26
+ () => (active.value ? [12, 52] : [4, 48]),
27
+ ([thick, long]) => {
28
+ if (!barEl.value) return
29
+ const vertical = props.orientation === 'vertical'
30
+ barEl.value.style.width = `${vertical ? thick : long}px`
31
+ barEl.value.style.height = `${vertical ? long : thick}px`
32
+ },
33
+ FAST_SPATIAL,
34
+ )
35
+ // Same sizes, other axis: redraw
36
+ watch(() => props.orientation, () => snap())
37
+ </script>
38
+
39
+ <template>
40
+ <span
41
+ class="inline-flex shrink-0 items-center justify-center"
42
+ :class="orientation === 'vertical' ? 'h-13 w-6' : 'h-6 w-13'"
43
+ @pointerdown="pressed = true"
44
+ @pointerup="pressed = false"
45
+ @pointerleave="pressed = false"
46
+ @pointercancel="pressed = false"
47
+ >
48
+ <span
49
+ ref="barEl"
50
+ class="block rounded-full transition-colors duration-150"
51
+ :class="active ? 'bg-on-surface' : 'bg-outline'"
52
+ />
53
+ </span>
54
+ </template>
@@ -7,7 +7,7 @@
7
7
  * @slot default MListItem / MListSubheader children
8
8
  * @event update:selected Fires when a selectable item is clicked (via v-model:selected)
9
9
  */
10
- import { computed, provide } from 'vue'
10
+ import { computed, onMounted, onUnmounted, provide, ref, shallowRef } from 'vue'
11
11
 
12
12
  const props = withDefaults(
13
13
  defineProps<{
@@ -33,7 +33,36 @@ const emit = defineEmits<{
33
33
  'update:selected': [value: string | number | null]
34
34
  }>()
35
35
 
36
+ // Segmented items need to know whether they open or close their run of items (SegmentedListItem's
37
+ // segmentedShapes(index, count)). A subheader or any other non-item child starts a new run.
38
+ const listEl = ref<HTMLElement>()
39
+ const positions = shallowRef(new Map<Element, 'single' | 'first' | 'middle' | 'last'>())
40
+ function measure() {
41
+ const map = new Map<Element, 'single' | 'first' | 'middle' | 'last'>()
42
+ let run: Element[] = []
43
+ const flush = () => {
44
+ run.forEach((el, i) => map.set(el, run.length === 1 ? 'single' : i === 0 ? 'first' : i === run.length - 1 ? 'last' : 'middle'))
45
+ run = []
46
+ }
47
+ for (const child of listEl.value?.children ?? []) {
48
+ if (child.getAttribute('role') === 'listitem') run.push(child)
49
+ else flush()
50
+ }
51
+ flush()
52
+ positions.value = map
53
+ }
54
+ let observer: MutationObserver | undefined
55
+ onMounted(() => {
56
+ measure()
57
+ if (listEl.value) {
58
+ observer = new MutationObserver(measure)
59
+ observer.observe(listEl.value, { childList: true })
60
+ }
61
+ })
62
+ onUnmounted(() => observer?.disconnect())
63
+
36
64
  provide('m-list', {
65
+ segmentPosition: (el: Element | null | undefined) => (el ? positions.value.get(el) : undefined),
37
66
  dense: computed(() => props.dense),
38
67
  nav: computed(() => props.nav),
39
68
  segmented: computed(() => props.segmented),
@@ -46,13 +75,14 @@ provide('m-list', {
46
75
 
47
76
  const classes = computed(() => [
48
77
  'flex flex-col',
49
- props.segmented ? 'gap-2 p-2' : 'py-2',
78
+ // ListTokens.SegmentedGap = 2dp
79
+ props.segmented ? 'gap-0.5 p-2' : 'py-2',
50
80
  props.nav && !props.segmented && 'gap-0.5 px-3',
51
81
  ])
52
82
  </script>
53
83
 
54
84
  <template>
55
- <ul role="list" :class="classes">
85
+ <ul ref="listEl" role="list" :class="classes">
56
86
  <slot />
57
87
  </ul>
58
88
  </template>
@@ -13,11 +13,13 @@
13
13
  * @event update:expanded Fires when an expandable item is toggled open/closed
14
14
  */
15
15
  import { computed, inject, ref, useAttrs, watch } from 'vue'
16
+ import type { ComponentPublicInstance } from 'vue'
16
17
  import type { ComputedRef } from 'vue'
17
18
  import MIcon from './MIcon.vue'
18
19
  import MAvatar from './MAvatar.vue'
19
20
  import MCheckbox from './MCheckbox.vue'
20
21
  import MSwitch from './MSwitch.vue'
22
+ import { useSpring } from '../composables/_useSpring'
21
23
 
22
24
  export type ListItemLeading = 'icon' | 'avatar' | 'checkbox' | 'radio' | 'image' | 'icon-container'
23
25
  export type ListItemTrailing = 'icon' | 'text' | 'switch' | 'checkbox'
@@ -87,6 +89,7 @@ watch(() => props.expanded, (v) => { if (v !== undefined) internalExpanded.value
87
89
  const isExpanded = computed(() => internalExpanded.value)
88
90
 
89
91
  const list = inject<{
92
+ segmentPosition: (el: Element | null | undefined) => 'single' | 'first' | 'middle' | 'last' | undefined
90
93
  dense: ComputedRef<boolean>
91
94
  nav: ComputedRef<boolean>
92
95
  segmented: ComputedRef<boolean>
@@ -157,9 +160,8 @@ const minHeightClass = computed(() => {
157
160
 
158
161
  const containerClasses = computed(() => [
159
162
  'mli-row relative flex w-full items-center gap-4 text-left',
160
- isSegmented.value
161
- ? 'rounded-xl bg-surface-container px-4'
162
- : isNav.value ? 'rounded-full px-4' : 'px-4',
163
+ // Corner radius: a pill in nav lists, otherwise sprung by expressiveRadii below
164
+ isSegmented.value ? 'bg-surface-container px-4' : isNav.value ? 'rounded-full px-4' : 'px-4',
163
165
  isDense.value
164
166
  ? 'py-1'
165
167
  : resolvedLines.value === 3 ? 'py-3' : 'py-2',
@@ -171,6 +173,57 @@ const containerClasses = computed(() => [
171
173
  props.disabled && 'opacity-[0.38] pointer-events-none',
172
174
  ])
173
175
 
176
+ // ── Expressive shape morph ──────────────────────────────────────────────────────────────────
177
+ // The current (non-deprecated) ListItem overloads morph the container's corners by interaction, with
178
+ // ListItemDefaults.shapes(): ListTokens.ItemContainerExpressiveShape CornerExtraSmall (4dp) at rest,
179
+ // ItemHovered… CornerMedium (8dp), ItemPressed/Focused/Selected… CornerLarge (16dp), priority
180
+ // pressed > selected > focused > hovered (shapeForInteraction). SegmentedListItem's segmentedShapes() swaps
181
+ // only the resting shape's outer corners for ListTokens.ContainerShape (CornerLarge) on the first and last
182
+ // item of a run; the interaction shapes stay the same. Animated with MotionSchemeKeyTokens.FastSpatial.
183
+ // Nav lists keep their pill (that's NavigationDrawerItem's shape, which doesn't morph).
184
+ const rootEl = ref<Element | ComponentPublicInstance | null>(null)
185
+ const shapeEl = ref<HTMLElement | null>(null)
186
+ const el = (r: Element | ComponentPublicInstance | null) => (r && '$el' in r ? (r.$el as Element) : r)
187
+ const hovered = ref(false)
188
+ const pressed = ref(false)
189
+ const focused = ref(false)
190
+
191
+ const REST = 4
192
+ const HOVERED = 8
193
+ const LARGE = 16
194
+
195
+ const segmentPosition = computed(() => (isSegmented.value ? list?.segmentPosition(el(rootEl.value)) : undefined))
196
+
197
+ const expressiveRadii = computed<number[]>(() => {
198
+ if (isNav.value) return []
199
+ const interactive = isClickable.value && !props.disabled
200
+ const r = interactive && pressed.value ? LARGE
201
+ : isActive.value ? LARGE
202
+ : interactive && focused.value ? LARGE
203
+ : interactive && hovered.value ? HOVERED
204
+ : null
205
+ if (r !== null) return [r, r, r, r]
206
+ const pos = segmentPosition.value
207
+ const top = pos === 'first' || pos === 'single' ? LARGE : REST
208
+ const bottom = pos === 'last' || pos === 'single' ? LARGE : REST
209
+ return [top, top, bottom, bottom]
210
+ })
211
+
212
+ const { snap } = useSpring(() => expressiveRadii.value, (v) => {
213
+ const target = shapeEl.value ?? (el(rootEl.value) as HTMLElement | null)
214
+ if (!target) return
215
+ target.style.borderRadius = v.length ? v.map((n) => `${n}px`).join(' ') : ''
216
+ })
217
+ // A change of place in the list (or of list style) isn't an interaction: jump there
218
+ watch([segmentPosition, isNav], () => snap())
219
+
220
+ function onPointerEnter(e: PointerEvent) { if (e.pointerType !== 'touch') hovered.value = true }
221
+ function onPointerLeave() { hovered.value = false; pressed.value = false }
222
+ function onPointerDown(e: PointerEvent) { if (e.button === 0) pressed.value = true }
223
+ function onPointerUp() { pressed.value = false }
224
+ function onFocus(e: FocusEvent) { focused.value = (e.currentTarget as Element).matches(':focus-visible') }
225
+ function onBlur() { focused.value = false }
226
+
174
227
  const tag = computed(() => {
175
228
  if (props.href) return 'a'
176
229
  if (props.to) return 'router-link'
@@ -209,8 +262,17 @@ function handleTrailingToggle() {
209
262
  </script>
210
263
 
211
264
  <template>
212
- <li v-if="expandable" role="listitem">
213
- <div :class="containerClasses" @click="handleClick">
265
+ <li v-if="expandable" ref="rootEl" role="listitem">
266
+ <div
267
+ ref="shapeEl"
268
+ :class="containerClasses"
269
+ @click="handleClick"
270
+ @pointerenter="onPointerEnter"
271
+ @pointerleave="onPointerLeave"
272
+ @pointerdown="onPointerDown"
273
+ @pointerup="onPointerUp"
274
+ @pointercancel="onPointerUp"
275
+ >
214
276
  <!-- Leading -->
215
277
  <slot name="leading">
216
278
  <MIcon v-if="resolvedLeading === 'icon'" :name="icon!" :size="24" class="shrink-0" :class="activeIconClass" />
@@ -252,9 +314,17 @@ function handleTrailingToggle() {
252
314
  v-else
253
315
  :is="tag"
254
316
  :class="containerClasses"
317
+ ref="rootEl"
255
318
  v-bind="linkProps"
256
319
  role="listitem"
257
320
  @click="handleClick"
321
+ @pointerenter="onPointerEnter"
322
+ @pointerleave="onPointerLeave"
323
+ @pointerdown="onPointerDown"
324
+ @pointerup="onPointerUp"
325
+ @pointercancel="onPointerUp"
326
+ @focus="onFocus"
327
+ @blur="onBlur"
258
328
  >
259
329
  <!-- Divider -->
260
330
  <div