@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
@@ -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"
@@ -1,12 +1,20 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
3
  * A container for grouping icon buttons and actions — docked to an edge or floating as a rounded pill,
4
- * horizontal or vertical, with an optional paired FAB.
4
+ * horizontal or vertical, with an optional paired FAB. A floating toolbar collapses (`v-model:expanded`): with a
5
+ * FAB, into the FAB, which grows to 80px; without one, to its center (the default slot), closing `#leading` and
6
+ * `#trailing`. `collapseOnScroll` does it as the content scrolls.
5
7
  *
6
- * @slot fab A FAB rendered alongside the toolbar body, positioned by fabPosition
7
- * @slot default Toolbar items — typically MIconButton/MButton, separated with MDivider
8
+ * @slot fab A FAB rendered alongside the toolbar body, positioned by fabPosition. The toolbar sizes an MFab in it
9
+ * @slot default Toolbar items — typically MIconButton/MButton, separated with MDivider. With #leading or #trailing,
10
+ * the center, which stays when a floating toolbar without a FAB collapses
11
+ * @slot leading Items before the center, hidden when a floating toolbar without a FAB collapses
12
+ * @slot trailing Items after the center, hidden when a floating toolbar without a FAB collapses
13
+ * @event update:expanded The toolbar collapsed or expanded on scroll (`collapseOnScroll`)
8
14
  */
9
- import { computed } from 'vue'
15
+ import { computed, onMounted, onUnmounted, onUpdated, ref, useSlots, watch } from 'vue'
16
+ import { motionSprings } from '../composables/motion'
17
+ import MToolbarFab from './_MToolbarFab.vue'
10
18
 
11
19
  const props = withDefaults(defineProps<{
12
20
  /** Docked (edge-attached, full width/height, bordered) or floating (rounded pill with shadow) */
@@ -19,14 +27,25 @@ const props = withDefaults(defineProps<{
19
27
  fabPosition?: 'start' | 'end' | 'none'
20
28
  /** Item alignment along the main axis */
21
29
  align?: 'start' | 'center' | 'end' | 'between'
30
+ /**
31
+ * Collapse a floating toolbar as the content scrolls down and expand it as it scrolls back up (40px each way):
32
+ * `true` follows the window, or pass the scrolling element (or a CSS selector for it). Off by default
33
+ */
34
+ collapseOnScroll?: boolean | string | HTMLElement | null
22
35
  }>(), {
23
36
  variant: 'docked',
24
37
  orientation: 'horizontal',
25
38
  color: 'surface',
26
39
  fabPosition: 'none',
27
40
  align: 'center',
41
+ collapseOnScroll: false,
28
42
  })
29
43
 
44
+ /** A floating toolbar's state: collapsed, it shows only the FAB, or only its center without one. Default `true` */
45
+ const expanded = defineModel<boolean>('expanded', { default: true })
46
+
47
+ const slots = useSlots()
48
+
30
49
  const colorClasses = computed(() => {
31
50
  const map: Record<string, string> = {
32
51
  surface: 'bg-surface-container text-on-surface',
@@ -48,6 +67,167 @@ const alignClass = computed(() => {
48
67
  })
49
68
 
50
69
  const isVertical = computed(() => props.orientation === 'vertical')
70
+ const floating = computed(() => props.variant === 'floating')
71
+ const hasFab = computed(() => !!slots.fab && props.fabPosition !== 'none')
72
+ // A floating toolbar with a FAB collapses into it; one without, to its center
73
+ const fabMode = computed(() => floating.value && hasFab.value)
74
+ const sections = computed(() => !!(slots.leading || slots.trailing))
75
+ const collapsible = computed(() => floating.value && (hasFab.value || sections.value))
76
+ // The standard floating toolbar's FAB is PrimaryContainer, the vibrant one's TertiaryContainer
77
+ const fabColor = computed(() => (props.color === 'surface' ? 'primary' : 'tertiary'))
78
+ // What a collapsed toolbar hides is out of reach for keyboard and assistive technology
79
+ const hidden = computed(() => collapsible.value && !expanded.value)
80
+
81
+ // ── Collapse: one spring (FloatingToolbarDefaults.animationSpec = Expressive FastSpatial) for the progress, in a
82
+ // rAF loop that writes sizes (layout, so not a Web Animation). Like Compose: with a FAB, the toolbar keeps its
83
+ // footprint and clips toward the FAB, which grows from 56 to 80dp; without, #leading/#trailing shrink toward the
84
+ // center. Settled expanded, every size is left to the layout (style cleared), so content changes reflow normally.
85
+ const FAB_MIN = 56
86
+ const FAB_MAX = 80
87
+ const region = ref<HTMLElement>()
88
+ const body = ref<HTMLElement>()
89
+ const inner = ref<HTMLElement>()
90
+ const fabBox = ref<HTMLElement>()
91
+ const leadClip = ref<HTMLElement>()
92
+ const leadInner = ref<HTMLElement>()
93
+ const trailClip = ref<HTMLElement>()
94
+ const trailInner = ref<HTMLElement>()
95
+
96
+ let progress = expanded.value ? 1 : 0
97
+ let velocity = 0
98
+ let raf = 0
99
+ let last = 0
100
+ let full = 0
101
+ let lead = 0
102
+ let trail = 0
103
+ const reduceMotion = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches
104
+ const size = () => (isVertical.value ? 'height' : 'width')
105
+ const measure = (el?: HTMLElement) => (el ? (isVertical.value ? el.offsetHeight : el.offsetWidth) : 0)
106
+
107
+ function write() {
108
+ const settled = !raf
109
+ const p = Math.max(0, progress)
110
+ const axis = size()
111
+ const open = settled && progress === 1
112
+ if (fabMode.value) {
113
+ if (region.value) region.value.style[axis] = open ? '' : `${full}px`
114
+ if (body.value) body.value.style[axis] = open ? '' : `${full * p}px`
115
+ const fab = Math.max(0, FAB_MIN + (FAB_MAX - FAB_MIN) * (1 - progress))
116
+ if (fabBox.value) {
117
+ fabBox.value.style.width = `${fab}px`
118
+ fabBox.value.style.height = `${fab}px`
119
+ }
120
+ } else if (floating.value) {
121
+ if (leadClip.value) leadClip.value.style[axis] = open ? '' : `${lead * p}px`
122
+ if (trailClip.value) trailClip.value.style[axis] = open ? '' : `${trail * p}px`
123
+ }
124
+ }
125
+
126
+ function frame(now: number) {
127
+ let dt = Math.min((now - last) / 1000, 1 / 30)
128
+ last = now
129
+ const { stiffness: k, dampingRatio } = motionSprings.expressive.fastSpatial
130
+ const c = 2 * dampingRatio * Math.sqrt(k)
131
+ const target = expanded.value ? 1 : 0
132
+ while (dt > 0) {
133
+ const h = Math.min(dt, 0.004)
134
+ dt -= h
135
+ velocity += (-k * (progress - target) - c * velocity) * h
136
+ progress += velocity * h
137
+ }
138
+ if (Math.abs(progress - target) < 0.001 && Math.abs(velocity) < 0.01) {
139
+ progress = target
140
+ velocity = 0
141
+ raf = 0
142
+ } else raf = requestAnimationFrame(frame)
143
+ write()
144
+ }
145
+
146
+ function animate() {
147
+ // Natural sizes, read while every size is still the layout's (expanded) or from the unclipped inner content
148
+ full = measure(inner.value)
149
+ lead = measure(leadInner.value)
150
+ trail = measure(trailInner.value)
151
+ if (!collapsible.value || reduceMotion()) {
152
+ cancelAnimationFrame(raf)
153
+ raf = 0
154
+ progress = expanded.value ? 1 : 0
155
+ velocity = 0
156
+ write()
157
+ return
158
+ }
159
+ if (!raf) {
160
+ last = performance.now()
161
+ raf = requestAnimationFrame(frame)
162
+ }
163
+ }
164
+
165
+ watch(expanded, animate)
166
+ onMounted(() => {
167
+ full = measure(inner.value)
168
+ lead = measure(leadInner.value)
169
+ trail = measure(trailInner.value)
170
+ write()
171
+ })
172
+ // A re-render (new items) may change the natural sizes: a collapsed toolbar keeps the new ones
173
+ onUpdated(() => {
174
+ if (raf || progress === 1) return
175
+ full = measure(inner.value)
176
+ lead = measure(leadInner.value)
177
+ trail = measure(trailInner.value)
178
+ write()
179
+ })
180
+
181
+ // ── collapseOnScroll: Compose's floatingToolbarVerticalNestedScroll. The content's offset (minus the scroll
182
+ // position) is compared with a threshold 40dp behind the last switch, so small back-and-forth scrolls don't flicker.
183
+ const SCROLL_THRESHOLD = 40
184
+ let scroller: HTMLElement | Window | null = null
185
+ let lastTop = 0
186
+ let threshold = 0
187
+ const scrollTop = () => (!scroller ? 0 : scroller === window ? window.scrollY : (scroller as HTMLElement).scrollTop)
188
+ const resetThreshold = () => (threshold = -lastTop + (expanded.value ? -SCROLL_THRESHOLD : SCROLL_THRESHOLD))
189
+
190
+ function onScroll() {
191
+ const top = scrollTop()
192
+ const delta = lastTop - top
193
+ lastTop = top
194
+ const offset = -top
195
+ if (delta < 0 && offset <= threshold) {
196
+ threshold = offset + SCROLL_THRESHOLD
197
+ expanded.value = false
198
+ } else if (delta > 0 && offset >= threshold) {
199
+ threshold = offset - SCROLL_THRESHOLD
200
+ expanded.value = true
201
+ }
202
+ }
203
+
204
+ function attachScroll() {
205
+ scroller?.removeEventListener('scroll', onScroll)
206
+ scroller = null
207
+ const target = props.collapseOnScroll
208
+ if (!target || typeof window === 'undefined') return
209
+ scroller = target === true ? window : typeof target === 'string' ? document.querySelector<HTMLElement>(target) : target
210
+ if (!scroller) return
211
+ scroller.addEventListener('scroll', onScroll, { passive: true })
212
+ lastTop = scrollTop()
213
+ resetThreshold()
214
+ }
215
+
216
+ onMounted(() => {
217
+ attachScroll()
218
+ watch(() => props.collapseOnScroll, attachScroll)
219
+ // Expanded or collapsed some other way (the FAB): scrolling switches it again from here
220
+ watch(expanded, resetThreshold)
221
+ })
222
+ onUnmounted(() => {
223
+ cancelAnimationFrame(raf)
224
+ scroller?.removeEventListener('scroll', onScroll)
225
+ })
226
+
227
+ // Starting sizes for the server render and the first paint, set once (the loop writes them from then on)
228
+ const startCollapsed = !expanded.value
229
+ const fabStart = { width: `${startCollapsed ? FAB_MAX : FAB_MIN}px`, height: `${startCollapsed ? FAB_MAX : FAB_MIN}px` }
230
+ const clipStart = startCollapsed ? { [props.orientation === 'vertical' ? 'height' : 'width']: '0px' } : {}
51
231
  </script>
52
232
 
53
233
  <template>
@@ -55,35 +235,96 @@ const isVertical = computed(() => props.orientation === 'vertical')
55
235
  class="flex items-center gap-2"
56
236
  :class="[
57
237
  isVertical ? 'flex-col' : 'flex-row',
58
- fabPosition === 'start' && !isVertical ? 'flex-row' : '',
59
- fabPosition === 'start' && isVertical ? 'flex-col' : '',
238
+ fabMode ? (isVertical ? 'min-w-20' : 'min-h-20') : '',
60
239
  ]"
61
240
  >
62
241
  <!-- FAB start -->
63
- <div v-if="$slots.fab && fabPosition === 'start'" class="shrink-0">
64
- <slot name="fab" />
242
+ <div v-if="hasFab && fabPosition === 'start'" class="relative size-14 shrink-0">
243
+ <div ref="fabBox" class="absolute" :class="isVertical ? 'top-0 left-1/2 -translate-x-1/2' : 'left-0 top-1/2 -translate-y-1/2'" :style="fabStart">
244
+ <MToolbarFab :color="fabColor"><slot name="fab" /></MToolbarFab>
245
+ </div>
246
+ </div>
247
+
248
+ <!-- Floating with a FAB: the pill clips toward the FAB inside a region that keeps the toolbar's footprint -->
249
+ <div
250
+ v-if="fabMode"
251
+ ref="region"
252
+ class="flex shrink-0"
253
+ :class="[isVertical ? 'flex-col' : 'flex-row', fabPosition === 'end' ? 'justify-end' : 'justify-start']"
254
+ >
255
+ <div
256
+ ref="body"
257
+ class="overflow-hidden rounded-full shadow-elevation-1"
258
+ :class="[isVertical ? 'w-16' : 'h-16', colorClasses]"
259
+ :style="clipStart"
260
+ :inert="hidden || undefined"
261
+ >
262
+ <div
263
+ ref="inner"
264
+ class="flex shrink-0 items-center gap-1"
265
+ :class="[isVertical ? 'h-max w-16 flex-col py-2' : 'h-16 w-max flex-row px-2', alignClass]"
266
+ >
267
+ <slot name="leading" />
268
+ <slot />
269
+ <slot name="trailing" />
270
+ </div>
271
+ </div>
65
272
  </div>
66
273
 
67
274
  <!-- Toolbar body -->
68
275
  <div
69
- class="flex items-center gap-1"
276
+ v-else
277
+ class="flex items-center"
70
278
  :class="[
279
+ sections ? '' : 'gap-1',
71
280
  isVertical ? 'flex-col w-16' : 'flex-row h-16',
72
- isVertical ? (variant === 'floating' ? 'py-2' : 'py-4') : (variant === 'floating' ? 'px-2' : 'px-4'),
281
+ isVertical ? (floating ? 'py-2' : 'py-4') : (floating ? 'px-2' : 'px-4'),
73
282
  alignClass,
74
283
  colorClasses,
75
- variant === 'floating' ? 'rounded-full' : '',
76
- variant === 'floating' && fabPosition !== 'none' ? 'shadow-elevation-1' : '',
284
+ floating ? 'rounded-full' : '',
285
+ floating && hasFab ? 'shadow-elevation-1' : '',
77
286
  variant === 'docked' ? 'w-full border-t border-outline-variant' : '',
78
287
  variant === 'docked' && isVertical ? 'h-full w-16 border-t-0 border-r border-outline-variant' : '',
79
288
  ]"
80
289
  >
81
- <slot />
290
+ <template v-if="sections">
291
+ <!-- Each side closes toward the center: its content is anchored to the center-facing edge -->
292
+ <div
293
+ v-if="$slots.leading"
294
+ ref="leadClip"
295
+ class="flex shrink-0 overflow-hidden"
296
+ :class="isVertical ? 'flex-col justify-end' : 'flex-row justify-end'"
297
+ :style="floating ? clipStart : undefined"
298
+ :inert="hidden || undefined"
299
+ >
300
+ <div ref="leadInner" class="flex shrink-0 items-center gap-1" :class="isVertical ? 'flex-col pb-1' : 'flex-row pe-1'">
301
+ <slot name="leading" />
302
+ </div>
303
+ </div>
304
+ <div class="flex items-center gap-1" :class="isVertical ? 'flex-col' : 'flex-row'">
305
+ <slot />
306
+ </div>
307
+ <div
308
+ v-if="$slots.trailing"
309
+ ref="trailClip"
310
+ class="flex shrink-0 overflow-hidden"
311
+ :class="isVertical ? 'flex-col justify-start' : 'flex-row justify-start'"
312
+ :style="floating ? clipStart : undefined"
313
+ :inert="hidden || undefined"
314
+ >
315
+ <div ref="trailInner" class="flex shrink-0 items-center gap-1" :class="isVertical ? 'flex-col pt-1' : 'flex-row ps-1'">
316
+ <slot name="trailing" />
317
+ </div>
318
+ </div>
319
+ </template>
320
+ <slot v-else />
82
321
  </div>
83
322
 
84
323
  <!-- FAB end -->
85
- <div v-if="$slots.fab && fabPosition === 'end'" class="shrink-0">
86
- <slot name="fab" />
324
+ <div v-if="hasFab && fabPosition === 'end'" class="relative size-14 shrink-0">
325
+ <div ref="fabBox" class="absolute" :class="isVertical ? 'bottom-0 left-1/2 -translate-x-1/2' : 'right-0 top-1/2 -translate-y-1/2'" :style="fabStart">
326
+ <MToolbarFab :color="fabColor"><slot name="fab" /></MToolbarFab>
327
+ </div>
87
328
  </div>
88
329
  </div>
89
330
  </template>
@@ -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"
@@ -0,0 +1,14 @@
1
+ <script setup lang="ts">
2
+ // The box MToolbar's #fab slot renders in: tells an MFab inside that the toolbar sizes it (it fills this box, which
3
+ // grows from 56 to 80px as the toolbar collapses) and which color to default to. A component of its own so only
4
+ // the slot's FAB sees it, not one inside the toolbar's items.
5
+ import { provide } from 'vue'
6
+
7
+ const props = defineProps<{ color: 'primary' | 'tertiary' }>()
8
+
9
+ provide('m-toolbar-fab', props)
10
+ </script>
11
+
12
+ <template>
13
+ <slot />
14
+ </template>
@@ -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,179 @@
1
+ /*
2
+ * Internal (not exported from index.ts): Material's container transform, the engine behind MContainerTransform.
3
+ *
4
+ * A port of Material Components for Android's MaterialContainerTransform (transition/MaterialContainerTransform.java,
5
+ * FitModeEvaluators, FadeModeEvaluators, MaskEvaluator, TransitionUtils), with its defaults: linear path between the
6
+ * two boxes' top-centers, FIT_MODE_AUTO, FADE_MODE_IN, the non-arc progress thresholds, a 32% black scrim, 500ms
7
+ * (motionDurationLong2) to open and 400ms (motionDurationMedium4) to close on the emphasized curve. Both views keep
8
+ * their own layout and are scaled uniformly to the container's current width (or height), so nothing stretches;
9
+ * a rounded clip, the union of both masked boxes, morphs between their shapes. Android draws snapshots on a canvas;
10
+ * here the source is a clone, the destination the real panel, and every frame is computed up front and played as
11
+ * Web Animations (see _springAnimation.ts) so the compositor runs the transforms and opacities.
12
+ */
13
+ import { SAMPLE_MS } from './_springAnimation'
14
+
15
+ export interface Box { left: number; top: number; width: number; height: number }
16
+
17
+ interface Thresholds { fade: [number, number]; scale: [number, number]; scaleMask: [number, number]; shapeMask: [number, number] }
18
+ const ENTER: Thresholds = { fade: [0, 0.25], scale: [0, 1], scaleMask: [0, 1], shapeMask: [0, 0.75] }
19
+ const RETURN: Thresholds = { fade: [0.6, 0.9], scale: [0, 1], scaleMask: [0, 0.9], shapeMask: [0.3, 0.9] }
20
+
21
+ export const OPEN_MS = 500
22
+ export const CLOSE_MS = 400
23
+ export const SCRIM_OPACITY = 0x52 / 255
24
+
25
+ // Android's emphasized interpolator (motionEasingEmphasizedInterpolator): the path
26
+ // M 0,0 C 0.05,0 0.133333,0.06 0.166666,0.4 C 0.208333,0.82 0.25,1 1,1, not a single cubic
27
+ function segment(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x: number) {
28
+ let lo = 0
29
+ let hi = 1
30
+ for (let i = 0; i < 30; i++) {
31
+ const u = (lo + hi) / 2
32
+ const bx = (1 - u) ** 3 * x0 + 3 * (1 - u) ** 2 * u * x1 + 3 * (1 - u) * u ** 2 * x2 + u ** 3 * x3
33
+ if (bx < x) lo = u
34
+ else hi = u
35
+ }
36
+ const u = (lo + hi) / 2
37
+ return (1 - u) ** 3 * y0 + 3 * (1 - u) ** 2 * u * y1 + 3 * (1 - u) * u ** 2 * y2 + u ** 3 * y3
38
+ }
39
+ export function emphasized(t: number) {
40
+ if (t <= 0) return 0
41
+ if (t >= 1) return 1
42
+ return t < 0.166666
43
+ ? segment(0, 0, 0.05, 0, 0.133333, 0.06, 0.166666, 0.4, t)
44
+ : segment(0.166666, 0.4, 0.208333, 0.82, 0.25, 1, 1, 1, t)
45
+ }
46
+
47
+ const lerp = (a: number, b: number, f: number) => a + f * (b - a)
48
+ // TransitionUtils.lerp with start/end fractions (clamped outside them, like Android unless overshoot is allowed)
49
+ function lerpRange(a: number, b: number, [from, to]: [number, number], f: number) {
50
+ if (f < from) return a
51
+ if (f > to) return b
52
+ return lerp(a, b, (f - from) / (to - from))
53
+ }
54
+
55
+ /** Where a view sits: translate from its own resting box, uniform scale from its top-left corner, opacity */
56
+ export interface ViewState { x: number; y: number; scale: number; opacity: number }
57
+ export interface Frame {
58
+ /** The container's clip, in the same coordinates as the boxes, and its corner radius */
59
+ clip: Box
60
+ radius: number
61
+ start: ViewState
62
+ end: ViewState
63
+ scrim: number
64
+ }
65
+
66
+ /**
67
+ * The transition's state at progress `p` (already eased), from the `start` box to the `end` one. `entering` is the
68
+ * direction (Android's TRANSITION_DIRECTION_AUTO: the bigger box is the detail), which picks the thresholds and the
69
+ * fade: entering, the end view fades in on top of the start one; returning, the start one fades out on top.
70
+ */
71
+ export function containerFrame(p: number, start: Box, end: Box, startRadius: number, endRadius: number, entering: boolean): Frame {
72
+ const th = entering ? ENTER : RETURN
73
+
74
+ // FitModeEvaluators: fit to the width unless the end box, scaled to the start's width, ends up shorter
75
+ const fitWidth = entering
76
+ ? (end.height * start.width) / end.width >= start.height
77
+ : (start.height * end.width) / start.width >= end.height
78
+ let startScale: number
79
+ let endScale: number
80
+ if (fitWidth) {
81
+ const width = lerpRange(start.width, end.width, th.scale, p)
82
+ startScale = width / start.width
83
+ endScale = width / end.width
84
+ } else {
85
+ const height = lerpRange(start.height, end.height, th.scale, p)
86
+ startScale = height / start.height
87
+ endScale = height / end.height
88
+ }
89
+ const sw = start.width * startScale
90
+ const sh = start.height * startScale
91
+ const ew = end.width * endScale
92
+ const eh = end.height * endScale
93
+
94
+ // The linear motion path between the top-centers
95
+ const mx = lerp(start.left + start.width / 2, end.left + end.width / 2, p)
96
+ const my = lerp(start.top, end.top, p)
97
+ const startBox = { left: mx - sw / 2, top: my, width: sw, height: sh }
98
+ const endBox = { left: mx - ew / 2, top: my, width: ew, height: eh }
99
+
100
+ // Mask the taller (or wider) of the two down toward the other over the scale-mask range
101
+ const startMasked = { ...startBox }
102
+ const endMasked = { ...endBox }
103
+ const maskProgress = lerpRange(0, 1, th.scaleMask, p)
104
+ if (fitWidth) {
105
+ const maskStart = sh > eh
106
+ const target = maskStart ? startMasked : endMasked
107
+ target.height -= Math.abs(eh - sh) * (maskStart ? maskProgress : 1 - maskProgress)
108
+ } else {
109
+ const maskStart = sw > ew
110
+ const target = maskStart ? startMasked : endMasked
111
+ const diff = Math.abs(ew - sw) * (maskStart ? maskProgress : 1 - maskProgress)
112
+ target.left += diff / 2
113
+ target.width -= diff
114
+ }
115
+ const left = Math.min(startMasked.left, endMasked.left)
116
+ const top = Math.min(startMasked.top, endMasked.top)
117
+ const right = Math.max(startMasked.left + startMasked.width, endMasked.left + endMasked.width)
118
+ const bottom = Math.max(startMasked.top + startMasked.height, endMasked.top + endMasked.height)
119
+
120
+ const fade = lerpRange(0, 1, th.fade, p)
121
+ return {
122
+ clip: { left, top, width: right - left, height: bottom - top },
123
+ radius: lerpRange(startRadius, endRadius, th.shapeMask, p),
124
+ start: { x: startBox.left - start.left, y: startBox.top - start.top, scale: startScale, opacity: entering ? 1 : 1 - fade },
125
+ end: { x: endBox.left - end.left, y: endBox.top - end.top, scale: endScale, opacity: entering ? fade : 1 },
126
+ scrim: (entering ? p : 1 - p) * SCRIM_OPACITY,
127
+ }
128
+ }
129
+
130
+ /** Every frame of a transition, one per 60Hz frame of `duration` ms, on the emphasized curve */
131
+ export function containerFrames(start: Box, end: Box, startRadius: number, endRadius: number, entering: boolean, duration: number): Frame[] {
132
+ const n = Math.max(1, Math.round(duration / SAMPLE_MS))
133
+ return Array.from({ length: n + 1 }, (_, i) => containerFrame(emphasized(i / n), start, end, startRadius, endRadius, entering))
134
+ }
135
+
136
+ const view = (s: ViewState): Keyframe => ({ transform: `translate(${s.x}px, ${s.y}px) scale(${s.scale})`, opacity: s.opacity })
137
+
138
+ /**
139
+ * Plays `frames` on the clip layer (positioned at the viewport's origin, `vw` × `vh`), the two views and the scrim.
140
+ * Returns the running animations (empty without the Web Animations API). `fill: 'forwards'` holds the last frame
141
+ * (a closing run, until the layer is removed).
142
+ */
143
+ export function playContainerFrames(
144
+ frames: Frame[],
145
+ els: { clip: HTMLElement; start?: HTMLElement | null; end: HTMLElement; scrim?: HTMLElement | null },
146
+ vw: number,
147
+ vh: number,
148
+ fill?: FillMode,
149
+ ): Animation[] {
150
+ if (typeof els.end.animate !== 'function') return []
151
+ const duration = (frames.length - 1) * SAMPLE_MS
152
+ const options: KeyframeAnimationOptions = { duration, easing: 'linear', fill }
153
+ const clip = (f: Frame) => {
154
+ const { left, top, width, height } = f.clip
155
+ return `inset(${top}px ${vw - left - width}px ${vh - top - height}px ${left}px round ${f.radius}px)`
156
+ }
157
+ const anims = [
158
+ els.clip.animate(frames.map((f) => ({ clipPath: clip(f) })), options),
159
+ els.end.animate(frames.map((f) => view(f.end)), options),
160
+ ]
161
+ if (els.start) anims.push(els.start.animate(frames.map((f) => view(f.start)), options))
162
+ if (els.scrim) anims.push(els.scrim.animate(frames.map((f) => ({ opacity: f.scrim })), options))
163
+ for (const a of anims) a.finished.catch(() => {})
164
+ return anims
165
+ }
166
+
167
+ /** A resting box in viewport coordinates */
168
+ export function boxOf(el: Element): Box {
169
+ const r = el.getBoundingClientRect()
170
+ return { left: r.left, top: r.top, width: r.width, height: r.height }
171
+ }
172
+
173
+ /** An element's top-left corner radius in px (a percentage resolves against its width) */
174
+ export function radiusOf(el: Element): number {
175
+ const value = getComputedStyle(el).borderTopLeftRadius || '0'
176
+ const n = parseFloat(value)
177
+ if (Number.isNaN(n)) return 0
178
+ return value.trim().endsWith('%') ? (n / 100) * (el as HTMLElement).offsetWidth : n
179
+ }
@@ -11,6 +11,8 @@ const stack: (() => void)[] = []
11
11
 
12
12
  function onKeydown(e: KeyboardEvent) {
13
13
  if (e.key !== 'Escape' || !stack.length) return
14
+ // Handled: the browser then doesn't also run a close watcher with it (MContainerTransform's, under a dialog)
15
+ e.preventDefault()
14
16
  stack[stack.length - 1]!()
15
17
  }
16
18
 
@@ -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
+ }