@m3ui-vue/m3ui-vue 1.1.3 → 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 (78) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +70 -8
  3. package/dist/{MMenuItem-BckcR0nW.js → MMenuItem-BfjqwcYP.js} +84 -63
  4. package/dist/MMenuItem-BfjqwcYP.js.map +1 -0
  5. package/dist/MSlider-JflHJ70q.js +1525 -0
  6. package/dist/MSlider-JflHJ70q.js.map +1 -0
  7. package/dist/{MTextField-FCPOTB0o.js → MTextField-NaIB6RbM.js} +5 -4
  8. package/dist/MTextField-NaIB6RbM.js.map +1 -0
  9. package/dist/api.json +1 -1
  10. package/dist/code-editor.js +1 -1
  11. package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
  12. package/dist/components/MButton.vue.d.ts +2 -0
  13. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  14. package/dist/components/MDialog.vue.d.ts +8 -5
  15. package/dist/components/MFlex.vue.d.ts +1 -1
  16. package/dist/components/MIconButton.vue.d.ts +2 -0
  17. package/dist/components/MListItem.vue.d.ts +5 -5
  18. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  19. package/dist/components/MSplitter.vue.d.ts +1 -1
  20. package/dist/components/MStack.vue.d.ts +1 -1
  21. package/dist/components/MToolbar.vue.d.ts +32 -5
  22. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  23. package/dist/composables/_containerTransform.d.ts +48 -0
  24. package/dist/composables/useContainerTransform.d.ts +30 -0
  25. package/dist/composables/useLocale.d.ts +3 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/locales/index.js +14 -0
  28. package/dist/locales/index.js.map +1 -1
  29. package/dist/m3ui-vue.css +1 -1
  30. package/dist/m3ui.js +4217 -3713
  31. package/dist/m3ui.js.map +1 -1
  32. package/dist/map.js +38 -38
  33. package/dist/rich-text-editor.js +10 -10
  34. package/dist/styles.css +1 -1
  35. package/dist/{useLocale-SfQHnJfp.js → useLocale-CXibICQA.js} +3 -1
  36. package/dist/useLocale-CXibICQA.js.map +1 -0
  37. package/package.json +2 -1
  38. package/src/__tests__/MAnimatedNumber.test.ts +24 -2
  39. package/src/__tests__/MContainerTransform.test.ts +279 -0
  40. package/src/__tests__/MDialog.test.ts +27 -0
  41. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  42. package/src/__tests__/MListItemShape.test.ts +9 -6
  43. package/src/__tests__/MListKeyboard.test.ts +90 -0
  44. package/src/__tests__/MMapTools.test.ts +2 -1
  45. package/src/__tests__/MNavigationRail.test.ts +33 -0
  46. package/src/__tests__/MSlider.test.ts +161 -0
  47. package/src/__tests__/MToolbar.test.ts +157 -0
  48. package/src/__tests__/attrsFallthrough.test.ts +6 -0
  49. package/src/__tests__/hydration.test.ts +25 -0
  50. package/src/components/MAnimatedNumber.vue +32 -6
  51. package/src/components/MButton.vue +4 -2
  52. package/src/components/MContainerTransform.vue +321 -0
  53. package/src/components/MDialog.vue +31 -6
  54. package/src/components/MFab.vue +10 -5
  55. package/src/components/MIconButton.vue +3 -1
  56. package/src/components/MList.vue +26 -2
  57. package/src/components/MListItem.vue +138 -84
  58. package/src/components/MNavigationRail.vue +40 -10
  59. package/src/components/MSlider.vue +161 -42
  60. package/src/components/MToolbar.vue +256 -15
  61. package/src/components/_MToolbarFab.vue +14 -0
  62. package/src/composables/_containerTransform.ts +179 -0
  63. package/src/composables/_useEscapeStack.ts +2 -0
  64. package/src/composables/useContainerTransform.ts +59 -0
  65. package/src/composables/useLocale.ts +5 -0
  66. package/src/index.ts +3 -0
  67. package/src/locales/de.ts +2 -0
  68. package/src/locales/es.ts +2 -0
  69. package/src/locales/fr.ts +2 -0
  70. package/src/locales/ja.ts +2 -0
  71. package/src/locales/ko.ts +2 -0
  72. package/src/locales/pt.ts +2 -0
  73. package/src/locales/zh.ts +2 -0
  74. package/dist/MMenuItem-BckcR0nW.js.map +0 -1
  75. package/dist/MSlider-LyH_gy8D.js +0 -1411
  76. package/dist/MSlider-LyH_gy8D.js.map +0 -1
  77. package/dist/MTextField-FCPOTB0o.js.map +0 -1
  78. package/dist/useLocale-SfQHnJfp.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ import { describe, it, expect, afterEach, beforeAll, afterAll } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MSlider from '../components/MSlider.vue'
5
+
6
+ let wrapper: VueWrapper | undefined
7
+ afterEach(() => {
8
+ wrapper?.unmount()
9
+ wrapper = undefined
10
+ })
11
+
12
+ // happy-dom has no layout: the slider's track is 880px long (the docs' Volume slider in the bug report)
13
+ const offsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth')!
14
+ beforeAll(() => {
15
+ Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
16
+ configurable: true,
17
+ get(this: HTMLElement) { return this.classList.contains('touch-none') ? 880 : 0 },
18
+ })
19
+ })
20
+ afterAll(() => Object.defineProperty(HTMLElement.prototype, 'offsetWidth', offsetWidth))
21
+
22
+ // The track's pieces (inactive/active) and its end dots, in template order
23
+ const track = (w: VueWrapper) => w.find('.touch-none')
24
+ const bar = (w: VueWrapper) => track(w).element.firstElementChild as HTMLElement
25
+ const pieces = (w: VueWrapper) => [...bar(w).children].filter((c) => !c.classList.contains('rounded-full')) as HTMLElement[]
26
+ const endDot = (w: VueWrapper) => [...bar(w).children].filter((c) => c.classList.contains('rounded-full')).at(-1) as HTMLElement
27
+ const startDot = (w: VueWrapper) => [...bar(w).children].filter((c) => c.classList.contains('rounded-full'))[0] as HTMLElement
28
+
29
+ describe('MSlider', () => {
30
+ it('shows the end dot while there is room for it in the inactive piece', async () => {
31
+ wrapper = mount(MSlider, { props: { modelValue: 90 } })
32
+ await nextTick()
33
+ expect(endDot(wrapper).style.opacity).toBe('1')
34
+ expect(pieces(wrapper)[1]!.style.width).not.toBe('0px')
35
+ })
36
+
37
+ it('hides the end dot once it no longer fits in the inactive piece, instead of leaving it in the thumb gap', async () => {
38
+ // 98 of 880px: an 11.6px piece, shorter than the dot's 12px inset + its radius
39
+ wrapper = mount(MSlider, { props: { modelValue: 98 } })
40
+ await nextTick()
41
+ expect(endDot(wrapper).style.opacity).toBe('0')
42
+ // The piece itself is still longer than its corner, so it stays (Compose draws it too)
43
+ expect(pieces(wrapper)[1]!.style.width).not.toBe('0px')
44
+ })
45
+
46
+ it('drops the inactive piece once it is shorter than its corner, like Compose', async () => {
47
+ // 99: a 3.2px piece
48
+ wrapper = mount(MSlider, { props: { modelValue: 99 } })
49
+ await nextTick()
50
+ expect(pieces(wrapper)[1]!.style.width).toBe('0px')
51
+ expect(endDot(wrapper).style.opacity).toBe('0')
52
+ })
53
+
54
+ it('applies the same to both ends of a range slider', async () => {
55
+ wrapper = mount(MSlider, { props: { variant: 'range', modelValue: [1, 99] } })
56
+ await nextTick()
57
+ const [before, , after] = pieces(wrapper)
58
+ expect(before!.style.width).toBe('0px')
59
+ expect(after!.style.width).toBe('0px')
60
+ expect(startDot(wrapper).style.opacity).toBe('0')
61
+ expect(endDot(wrapper).style.opacity).toBe('0')
62
+ })
63
+
64
+ it('keeps both dots of a range slider away from the ends', async () => {
65
+ wrapper = mount(MSlider, { props: { variant: 'range', modelValue: [20, 80] } })
66
+ await nextTick()
67
+ expect(startDot(wrapper).style.opacity).toBe('1')
68
+ expect(endDot(wrapper).style.opacity).toBe('1')
69
+ })
70
+
71
+ describe('range', () => {
72
+ // The track is 100px long from 0 for the pointer
73
+ const press = async (w: VueWrapper, at: number, moves: number[] = []) => {
74
+ const el = track(w).element as HTMLElement
75
+ el.getBoundingClientRect = () => ({ left: 0, top: 0, width: 100, height: 46, right: 100, bottom: 46, x: 0, y: 0, toJSON() {} })
76
+ el.dispatchEvent(new PointerEvent('pointerdown', { clientX: at, bubbles: true }))
77
+ await nextTick()
78
+ for (const x of moves) {
79
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: x }))
80
+ await nextTick()
81
+ }
82
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: moves.at(-1) ?? at }))
83
+ }
84
+ // A v-model the component updates, as a parent would
85
+ const mountRange = (value: [number, number]) => {
86
+ const w = mount(MSlider, {
87
+ props: { variant: 'range', modelValue: value, 'onUpdate:modelValue': (v: unknown) => w.setProps({ modelValue: v as [number, number] }) },
88
+ attachTo: document.body,
89
+ })
90
+ return w
91
+ }
92
+ const last = (w: VueWrapper) => (w.emitted('update:modelValue') as unknown[][]).at(-1)![0]
93
+
94
+ it('moves the end thumb for a press past two overlapping thumbs, keeping the pair ordered', async () => {
95
+ wrapper = mountRange([50, 50])
96
+ await press(wrapper, 70)
97
+ expect(last(wrapper)).toEqual([50, 70])
98
+ await press(wrapper, 30)
99
+ expect(last(wrapper)).toEqual([30, 70])
100
+ })
101
+
102
+ it('picks the thumb by the drag direction on two overlapping thumbs', async () => {
103
+ wrapper = mountRange([50, 50])
104
+ await press(wrapper, 50, [40, 30])
105
+ expect(last(wrapper)).toEqual([30, 50])
106
+ await wrapper.setProps({ modelValue: [50, 50] })
107
+ await press(wrapper, 50, [60, 75])
108
+ expect(last(wrapper)).toEqual([50, 75])
109
+ })
110
+
111
+ it('never lets a dragged thumb pass the other one', async () => {
112
+ wrapper = mountRange([20, 60])
113
+ await press(wrapper, 22, [40, 90])
114
+ expect(last(wrapper)).toEqual([60, 60])
115
+ await wrapper.setProps({ modelValue: [20, 60] })
116
+ await press(wrapper, 58, [10])
117
+ expect(last(wrapper)).toEqual([20, 20])
118
+ })
119
+
120
+ it('makes each thumb a slider of its own, moved by its keys within the other', async () => {
121
+ wrapper = mountRange([20, 60])
122
+ const thumbs = wrapper.findAll('[role=slider]')
123
+ expect(thumbs).toHaveLength(2)
124
+ expect(thumbs.map((t) => t.attributes('aria-label'))).toEqual(['Range start', 'Range end'])
125
+ expect(thumbs[0]!.attributes('aria-valuemax')).toBe('60')
126
+ expect(thumbs[1]!.attributes('aria-valuemin')).toBe('20')
127
+ await thumbs[1]!.trigger('keydown', { key: 'ArrowRight' })
128
+ expect(last(wrapper)).toEqual([20, 61])
129
+ await thumbs[1]!.trigger('keydown', { key: 'Home' })
130
+ expect(last(wrapper)).toEqual([20, 20])
131
+ await thumbs[0]!.trigger('keydown', { key: 'ArrowRight' })
132
+ expect(last(wrapper)).toEqual([20, 20])
133
+ await thumbs[0]!.trigger('keydown', { key: 'Home' })
134
+ expect(last(wrapper)).toEqual([0, 20])
135
+ expect(wrapper.find('[role=group]').exists()).toBe(true)
136
+ })
137
+
138
+ it('rings a thumb focused from the keyboard, not one a press focuses', async () => {
139
+ wrapper = mountRange([20, 60])
140
+ await press(wrapper, 70)
141
+ await nextTick()
142
+ const thumbs = wrapper.findAll('[role=slider]')
143
+ expect(document.activeElement).toBe(thumbs[1]!.element)
144
+ expect(thumbs[1]!.classes()).not.toContain('ring-2')
145
+ // The keys after a press bring the ring back, as browsers do
146
+ await thumbs[1]!.trigger('keydown', { key: 'ArrowLeft' })
147
+ expect(thumbs[1]!.classes()).toContain('ring-2')
148
+ // Tabbing to the other thumb
149
+ ;(thumbs[0]!.element as HTMLElement).focus()
150
+ await nextTick()
151
+ expect(thumbs[0]!.classes()).toContain('ring-2')
152
+ expect(thumbs[1]!.classes()).not.toContain('ring-2')
153
+ })
154
+
155
+ it('rings a thumb in the slider\'s own color', () => {
156
+ wrapper = mount(MSlider, { props: { variant: 'range', modelValue: [20, 60], color: 'tertiary' } })
157
+ const ring = (wrapper.find('[role=slider]').element as HTMLElement).style.getPropertyValue('--tw-ring-color')
158
+ expect(ring).toBe('var(--color-tertiary)')
159
+ })
160
+ })
161
+ })
@@ -0,0 +1,157 @@
1
+ import { describe, it, expect, afterEach, vi } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { h, nextTick } from 'vue'
4
+ import MToolbar from '../components/MToolbar.vue'
5
+ import MFab from '../components/MFab.vue'
6
+
7
+ let wrapper: VueWrapper | undefined
8
+ afterEach(() => {
9
+ wrapper?.unmount()
10
+ wrapper = undefined
11
+ vi.restoreAllMocks()
12
+ })
13
+
14
+ // happy-dom has no layout: give the unclipped content natural widths
15
+ function sizes(w: VueWrapper, widths: Record<string, number>) {
16
+ for (const [selector, width] of Object.entries(widths)) {
17
+ const el = w.find(selector).element
18
+ Object.defineProperty(el, 'offsetWidth', { configurable: true, get: () => width })
19
+ }
20
+ }
21
+ const reduceMotion = () =>
22
+ vi.spyOn(window, 'matchMedia').mockImplementation((q: string) => ({ matches: q.includes('reduce'), media: q, addEventListener() {}, removeEventListener() {} }) as unknown as MediaQueryList)
23
+ const button = (text: string) => () => h('button', text)
24
+
25
+ describe('MToolbar', () => {
26
+ it('collapses a floating toolbar without a FAB to its center, closing #leading and #trailing', async () => {
27
+ reduceMotion()
28
+ wrapper = mount(MToolbar, {
29
+ props: { variant: 'floating' },
30
+ slots: { leading: button('back'), default: button('add'), trailing: button('more') },
31
+ })
32
+ const [lead, , trail] = wrapper.findAll('.overflow-hidden, .gap-1.flex-row:not(.shrink-0)').map((x) => x.element as HTMLElement)
33
+ expect(wrapper.text()).toBe('backaddmore')
34
+ expect(lead!.style.width).toBe('')
35
+ await wrapper.setProps({ expanded: false })
36
+ expect(lead!.style.width).toBe('0px')
37
+ expect(trail!.style.width).toBe('0px')
38
+ expect(lead!.hasAttribute('inert')).toBe(true)
39
+ expect(trail!.hasAttribute('inert')).toBe(true)
40
+ // The center stays reachable
41
+ expect(wrapper.findAll('button').filter((b) => !b.element.closest('[inert]')).map((b) => b.text())).toEqual(['add'])
42
+ await wrapper.setProps({ expanded: true })
43
+ expect(lead!.style.width).toBe('')
44
+ expect(lead!.hasAttribute('inert')).toBe(false)
45
+ })
46
+
47
+ it('collapses into its FAB, keeping its footprint, while the FAB grows from 56 to 80px', async () => {
48
+ reduceMotion()
49
+ wrapper = mount(MToolbar, {
50
+ props: { variant: 'floating', fabPosition: 'end' },
51
+ slots: { default: button('add'), fab: () => h(MFab, { icon: 'edit', label: 'Edit' }) },
52
+ })
53
+ sizes(wrapper, { '.w-max': 200 })
54
+ const fabBox = wrapper.find('.absolute').element as HTMLElement
55
+ const body = wrapper.find('.rounded-full.overflow-hidden').element as HTMLElement
56
+ const region = body.parentElement!
57
+ expect(fabBox.style.width).toBe('56px')
58
+ await wrapper.setProps({ expanded: false })
59
+ expect(body.style.width).toBe('0px')
60
+ expect(region.style.width).toBe('200px')
61
+ expect(fabBox.style.width).toBe('80px')
62
+ expect(fabBox.style.height).toBe('80px')
63
+ expect(body.hasAttribute('inert')).toBe(true)
64
+ // The toolbar sizes the FAB, square even with a label (which names it), in the standard toolbar FAB's color
65
+ const fab = wrapper.findComponent(MFab).find('button')
66
+ expect(fab.classes()).toContain('w-full')
67
+ expect(fab.attributes('aria-label')).toBe('Edit')
68
+ expect(fab.text()).toBe('edit')
69
+ expect(fab.classes()).toContain('bg-primary-container')
70
+ await wrapper.setProps({ expanded: true })
71
+ expect(body.style.width).toBe('')
72
+ expect(region.style.width).toBe('')
73
+ expect(fabBox.style.width).toBe('56px')
74
+ })
75
+
76
+ it('gives the FAB of a colored toolbar the vibrant FAB color', () => {
77
+ wrapper = mount(MToolbar, {
78
+ props: { variant: 'floating', fabPosition: 'end', color: 'primary' },
79
+ slots: { default: button('add'), fab: () => h(MFab, { icon: 'edit', label: 'Edit' }) },
80
+ })
81
+ expect(wrapper.findComponent(MFab).find('button').classes()).toContain('bg-tertiary-container')
82
+ })
83
+
84
+ it('springs closed and settles', async () => {
85
+ wrapper = mount(MToolbar, {
86
+ props: { variant: 'floating' },
87
+ slots: { leading: button('back'), default: button('add') },
88
+ })
89
+ sizes(wrapper, { '.pe-1': 96 })
90
+ const lead = wrapper.find('.overflow-hidden').element as HTMLElement
91
+ await wrapper.setProps({ expanded: false })
92
+ await new Promise((r) => setTimeout(r, 120))
93
+ const mid = parseFloat(lead.style.width)
94
+ expect(mid).toBeGreaterThan(-1)
95
+ expect(mid).toBeLessThan(96)
96
+ await new Promise((r) => setTimeout(r, 900))
97
+ expect(lead.style.width).toBe('0px')
98
+ })
99
+
100
+ it('starts collapsed when rendered with expanded false', () => {
101
+ wrapper = mount(MToolbar, {
102
+ props: { variant: 'floating', expanded: false },
103
+ slots: { leading: button('back'), default: button('add') },
104
+ })
105
+ expect((wrapper.find('.overflow-hidden').element as HTMLElement).style.width).toBe('0px')
106
+ })
107
+
108
+ it('collapses on scroll down and expands on scroll up, 40px each way, when asked', async () => {
109
+ reduceMotion()
110
+ const list = document.createElement('div')
111
+ document.body.appendChild(list)
112
+ wrapper = mount(MToolbar, {
113
+ props: { variant: 'floating', collapseOnScroll: list, 'onUpdate:expanded': (v: boolean) => wrapper!.setProps({ expanded: v }) },
114
+ slots: { leading: button('back'), default: button('add') },
115
+ })
116
+ const scrollTo = async (top: number) => {
117
+ list.scrollTop = top
118
+ list.dispatchEvent(new Event('scroll'))
119
+ await nextTick()
120
+ }
121
+ await scrollTo(30)
122
+ expect(wrapper.props('expanded')).toBe(true)
123
+ await scrollTo(50)
124
+ expect(wrapper.props('expanded')).toBe(false)
125
+ // Back up less than 40px: stays collapsed
126
+ await scrollTo(20)
127
+ expect(wrapper.props('expanded')).toBe(false)
128
+ await scrollTo(5)
129
+ expect(wrapper.props('expanded')).toBe(true)
130
+ expect(wrapper.emitted('update:expanded')).toEqual([[false], [true]])
131
+ list.remove()
132
+ })
133
+
134
+ it('does not collapse on scroll unless asked', async () => {
135
+ wrapper = mount(MToolbar, { props: { variant: 'floating' }, slots: { leading: button('back'), default: button('add') } })
136
+ Object.defineProperty(window, 'scrollY', { configurable: true, value: 300 })
137
+ window.dispatchEvent(new Event('scroll'))
138
+ await nextTick()
139
+ expect(wrapper.emitted('update:expanded')).toBeUndefined()
140
+ })
141
+
142
+ it('never collapses a docked toolbar', async () => {
143
+ reduceMotion()
144
+ wrapper = mount(MToolbar, {
145
+ props: { variant: 'docked', expanded: false },
146
+ slots: { leading: button('back'), default: button('add'), trailing: button('more') },
147
+ })
148
+ const lead = wrapper.find('.overflow-hidden').element as HTMLElement
149
+ expect(lead.style.width).toBe('')
150
+ expect(lead.hasAttribute('inert')).toBe(false)
151
+ })
152
+
153
+ it('renders the items directly in the body without #leading or #trailing, as before', () => {
154
+ wrapper = mount(MToolbar, { slots: { default: () => [h('button', 'a'), h('button', 'b')] } })
155
+ expect(wrapper.find('.h-16').element.children).toHaveLength(2)
156
+ })
157
+ })
@@ -15,6 +15,8 @@ import MSkeleton from '../components/MSkeleton.vue'
15
15
  import MStepper from '../components/MStepper.vue'
16
16
  import MTabs from '../components/MTabs.vue'
17
17
  import MTransferList from '../components/MTransferList.vue'
18
+ import MContainerTransform from '../components/MContainerTransform.vue'
19
+ import MDialog from '../components/MDialog.vue'
18
20
 
19
21
  // These components render more than one root node (an element plus a Teleport, a v-if/v-show
20
22
  // pair, a comment before the root...), which makes Vue drop a consumer's class/attrs silently.
@@ -41,6 +43,10 @@ const cases: [name: string, component: Component, props: Record<string, unknown>
41
43
  ['MTabs', MTabs, { modelValue: 'a', tabs: [{ value: 'a', label: 'A' }] }, 'DIV'],
42
44
  ['MTabs (secondary)', MTabs, { modelValue: 'a', tabs: [{ value: 'a', label: 'A' }], variant: 'secondary' }, 'DIV'],
43
45
  ['MTransferList', MTransferList, { modelValue: [], items: [] }, 'DIV'],
46
+ ['MContainerTransform (the expanded view)', MContainerTransform, { open: true }, 'DIV'],
47
+ // A Teleport root: the attrs go on the dialog's surface
48
+ ['MDialog', MDialog, { modelValue: true, title: 'T' }, 'DIV'],
49
+ ['MDialog (fullscreen)', MDialog, { modelValue: true, title: 'T', fullscreen: true }, 'DIV'],
44
50
  ]
45
51
 
46
52
  describe('consumer attrs reach multi-root components', () => {
@@ -117,3 +117,28 @@ describe('hydrating server-rendered adaptive layouts', () => {
117
117
  expect(first).toBe(1024)
118
118
  })
119
119
  })
120
+
121
+ describe('hydrating MContainerTransform', () => {
122
+ it('renders the element on the server and the expanded view only in the browser, open from the start', async () => {
123
+ vi.resetModules()
124
+ const MContainerTransform = (await import('../components/MContainerTransform.vue')).default
125
+ const slots = { default: () => h('button', { class: 'card' }, 'Card'), expanded: () => h('p', 'Detail') }
126
+ const render = () => h(MContainerTransform, { open: true }, slots)
127
+ const ctx: { teleports?: Record<string, string> } = {}
128
+ const html = await renderToString(createSSRApp({ render }), ctx)
129
+ expect(html).toContain('Card')
130
+ expect(html + JSON.stringify(ctx.teleports)).not.toContain('Detail')
131
+
132
+ // As Nuxt does: the page, then what was teleported to <body> at its end
133
+ const container = document.createElement('div')
134
+ container.innerHTML = html
135
+ document.body.appendChild(container)
136
+ document.body.insertAdjacentHTML('beforeend', ctx.teleports?.body ?? '')
137
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
138
+ createSSRApp({ render }).mount(container)
139
+ await nextTick()
140
+ await nextTick()
141
+ expect(warn.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('Hydration'))).toEqual([])
142
+ expect(document.body.querySelector('[role=dialog]')?.textContent).toBe('Detail')
143
+ })
144
+ })
@@ -22,7 +22,9 @@ const props = withDefaults(
22
22
  /**
23
23
  * Intl options for the type: `{ style: 'currency', currency: 'EUR' }`, `{ style: 'percent' }`,
24
24
  * `{ style: 'unit', unit: 'kilometer-per-hour' }`, `{ notation: 'compact' }` for numbers; `{ timeStyle: 'medium' }`
25
- * (the default), `{ hour: '2-digit', minute: '2-digit' }`, `{ dateStyle: 'short' }` for times. Unused for durations
25
+ * (the default), `{ hour: '2-digit', minute: '2-digit' }`, `{ dateStyle: 'short' }` for times. Unused for durations.
26
+ * Dollar-sign currencies show their country (`AR$`, `MX$`, `US$`) in any language; set `currencyDisplay` for
27
+ * Intl's own output (`'symbol'` gives the local peso as a plain `$`)
26
28
  */
27
29
  format?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions
28
30
  /** BCP-47 language for the format (`es-AR` for Argentine pesos and separators); defaults to the app's locale */
@@ -64,7 +66,18 @@ const parts = computed<Part[]>(() => {
64
66
  const options = (props.format as Intl.DateTimeFormatOptions | undefined) ?? { timeStyle: 'medium' }
65
67
  return new Intl.DateTimeFormat(lang.value, options).formatToParts(numeric.value)
66
68
  }
67
- return new Intl.NumberFormat(lang.value, props.format as Intl.NumberFormatOptions | undefined).formatToParts(numeric.value)
69
+ const format = props.format as Intl.NumberFormatOptions | undefined
70
+ const out = new Intl.NumberFormat(lang.value, format).formatToParts(numeric.value)
71
+ if (format?.style !== 'currency' || format.currencyDisplay || !format.currency) return out
72
+ // Intl writes a plain "$" (the local peso, US dollars in the US) or a code (MXN in Argentina) for many currencies:
73
+ // give the dollar-sign ones their country instead (AR$, MX$, US$), with the language's spacing for a symbol.
74
+ // Symbols that already say which currency they are (US$, MX$, €, R$, ¥) stay as Intl writes them.
75
+ const code = format.currency.toUpperCase()
76
+ const symbol = out.find((p) => p.type === 'currency')?.value
77
+ if (symbol !== '$' && symbol !== code) return out
78
+ const narrow = new Intl.NumberFormat(lang.value, { ...format, currencyDisplay: 'narrowSymbol' }).formatToParts(numeric.value)
79
+ for (const p of narrow) if (p.type === 'currency' && p.value === '$') p.value = code === 'TWD' ? 'NT$' : `${code.slice(0, 2)}$`
80
+ return narrow
68
81
  })
69
82
  const text = computed(() => parts.value.map((p) => p.value).join(''))
70
83
 
@@ -117,7 +130,7 @@ const cells = computed<Cell[]>(() => {
117
130
  })
118
131
 
119
132
  // ── Rolling: one spring per digit column, stepped in a rAF loop and written to its strip's transform ─────────
120
- interface Column { pos: number; vel: number; target: number; base: number; el?: HTMLElement }
133
+ interface Column { pos: number; vel: number; target: number; base: number; el?: HTMLElement; rolling?: boolean }
121
134
  const columns = new Map<string, Column>()
122
135
  let mounted = false
123
136
  let raf = 0
@@ -129,8 +142,13 @@ const mod = (n: number, base: number) => ((n % base) + base) % base
129
142
  const write = (c: Column) => {
130
143
  if (!c.el) return
131
144
  c.el.style.transform = `translateY(${-mod(c.pos, c.base)}lh)`
132
- // Unmasked a little before landing, so the mask eases out with the last of the roll
133
- c.el.parentElement?.toggleAttribute('data-rolling', Math.abs(c.pos - c.target) > 0.15)
145
+ // Unmasked a little before landing, so the mask eases out with the last of the roll. Only touched when it changes:
146
+ // an attribute write every frame restyles the column every frame
147
+ const rolling = Math.abs(c.pos - c.target) > 0.15
148
+ if (rolling !== c.rolling) {
149
+ c.rolling = rolling
150
+ c.el.parentElement?.toggleAttribute('data-rolling', rolling)
151
+ }
134
152
  }
135
153
 
136
154
  // The strip's starting transform, set once per column, so the server renders the right digits. Vue may write it
@@ -149,7 +167,11 @@ function initialStyle(cell: Cell) {
149
167
  }
150
168
  const setStrip = (key: string) => (el: unknown) => {
151
169
  const c = columns.get(key)
152
- if (c) c.el = (el as HTMLElement | null) ?? undefined
170
+ if (!c) return
171
+ const next = (el as HTMLElement | null) ?? undefined
172
+ // A new element doesn't carry the old one's data-rolling
173
+ if (next !== c.el) c.rolling = undefined
174
+ c.el = next
153
175
  }
154
176
  // Two runs of the column's digits, so a digit rolling past the last shows the first coming in below it seamlessly
155
177
  const strip = (base: number) => Array.from({ length: base * 2 }, (_, i) => i % base)
@@ -275,6 +297,10 @@ onUnmounted(() => cancelAnimationFrame(raf))
275
297
  mask-size: 100% 100%;
276
298
  transition-duration: 120ms;
277
299
  }
300
+ /* Its own layer while it rolls, so moving it doesn't repaint the column */
301
+ .m3-anum-digit[data-rolling] > .m3-anum-strip {
302
+ will-change: transform;
303
+ }
278
304
  .m3-anum-strip {
279
305
  display: flex;
280
306
  flex-direction: column;
@@ -30,6 +30,8 @@ const props = withDefaults(
30
30
  loading?: boolean
31
31
  /** Material Symbol icon name shown next to the label */
32
32
  icon?: string
33
+ /** Draw the icon filled (Material Symbols' FILL axis), e.g. a starred star or a play icon */
34
+ iconFilled?: boolean
33
35
  /** Which side of the label the icon renders on */
34
36
  // Which side of the label `icon` renders on. Real M3 buttons support both via
35
37
  // `ButtonDefaults.contentPaddingFor(hasStartIcon/hasEndIcon)` — padding ends up identical
@@ -182,12 +184,12 @@ const variantClasses = computed(() => {
182
184
  >
183
185
  <template v-if="iconPos === 'leading'">
184
186
  <MSpinner v-if="loading" :size="spinnerSize" />
185
- <MIcon v-else-if="icon" :name="icon" :size="iconSize" />
187
+ <MIcon v-else-if="icon" :name="icon" :size="iconSize" :filled="iconFilled" />
186
188
  </template>
187
189
  <slot />
188
190
  <template v-if="iconPos === 'trailing'">
189
191
  <MSpinner v-if="loading" :size="spinnerSize" />
190
- <MIcon v-else-if="icon" :name="icon" :size="iconSize" />
192
+ <MIcon v-else-if="icon" :name="icon" :size="iconSize" :filled="iconFilled" />
191
193
  </template>
192
194
  </component>
193
195
  </template>