@m3ui-vue/m3ui-vue 0.9.3 → 1.0.1

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 (97) hide show
  1. package/README.md +24 -29
  2. package/dist/API.md +179 -19
  3. package/dist/{MTextField-DKtgPymd.js → MTextField-BPbFeI9M.js} +305 -177
  4. package/dist/MTextField-BPbFeI9M.js.map +1 -0
  5. package/dist/api.json +1 -1
  6. package/dist/code-editor.js +1 -1
  7. package/dist/components/MAppBarWithSearch.vue.d.ts +70 -0
  8. package/dist/components/MBottomAppBar.vue.d.ts +37 -0
  9. package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
  10. package/dist/components/MChatBubble.vue.d.ts +1 -1
  11. package/dist/components/MChip.vue.d.ts +19 -2
  12. package/dist/components/MContainer.vue.d.ts +1 -1
  13. package/dist/components/MDataTable.vue.d.ts +1 -1
  14. package/dist/components/MDialog.vue.d.ts +1 -1
  15. package/dist/components/MFab.vue.d.ts +13 -4
  16. package/dist/components/MListItem.vue.d.ts +2 -2
  17. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  18. package/dist/components/MNavigationDrawer.vue.d.ts +9 -6
  19. package/dist/components/MNavigationRail.vue.d.ts +6 -0
  20. package/dist/components/MSearchBar.vue.d.ts +5 -3
  21. package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
  22. package/dist/components/MTable.vue.d.ts +1 -1
  23. package/dist/components/MTopAppBar.vue.d.ts +33 -2
  24. package/dist/components/MTransition.vue.d.ts +0 -9
  25. package/dist/composables/_searchAppBar.d.ts +6 -0
  26. package/dist/composables/_springAnimation.d.ts +17 -0
  27. package/dist/composables/_themeTransition.d.ts +2 -0
  28. package/dist/composables/_useSpring.d.ts +3 -5
  29. package/dist/composables/motion.d.ts +101 -0
  30. package/dist/composables/useColorPalette.d.ts +10 -0
  31. package/dist/composables/useLocale.d.ts +3 -0
  32. package/dist/index.d.ts +8 -1
  33. package/dist/locales/index.js +21 -0
  34. package/dist/locales/index.js.map +1 -1
  35. package/dist/m3ui-vue.css +1 -1
  36. package/dist/m3ui.js +7345 -6317
  37. package/dist/m3ui.js.map +1 -1
  38. package/dist/plugin.d.ts +7 -0
  39. package/dist/rich-text-editor.js +2 -2
  40. package/dist/styles/palettes-contrast.css +7764 -0
  41. package/dist/styles/theme.css +46 -2
  42. package/dist/styles.css +1 -1
  43. package/dist/{useLocale-Cn9MVIdw.js → useLocale-CuvWRZ1h.js} +4 -1
  44. package/dist/useLocale-CuvWRZ1h.js.map +1 -0
  45. package/package.json +3 -1
  46. package/src/__tests__/MAppBarWithSearch.test.ts +108 -0
  47. package/src/__tests__/MBottomAppBar.test.ts +71 -0
  48. package/src/__tests__/MBottomSheetScaffold.test.ts +122 -0
  49. package/src/__tests__/MChip.test.ts +63 -0
  50. package/src/__tests__/MFab.test.ts +36 -0
  51. package/src/__tests__/MNavigationDrawer.test.ts +185 -0
  52. package/src/__tests__/MNavigationRail.test.ts +93 -0
  53. package/src/__tests__/MPullToRefresh.test.ts +18 -1
  54. package/src/__tests__/MTopAppBar.test.ts +99 -0
  55. package/src/__tests__/MTransition.test.ts +12 -0
  56. package/src/__tests__/contrast.test.ts +64 -0
  57. package/src/__tests__/dynamicColor.test.ts +17 -0
  58. package/src/__tests__/motion.test.ts +37 -0
  59. package/src/__tests__/sheets.test.ts +19 -15
  60. package/src/__tests__/themeTransition.test.ts +119 -0
  61. package/src/components/MAppBarWithSearch.vue +236 -0
  62. package/src/components/MBottomAppBar.vue +181 -0
  63. package/src/components/MBottomSheetScaffold.vue +317 -0
  64. package/src/components/MBreadcrumbs.vue +1 -1
  65. package/src/components/MChip.vue +137 -5
  66. package/src/components/MContextMenu.vue +34 -33
  67. package/src/components/MFab.vue +73 -12
  68. package/src/components/MMenu.vue +34 -33
  69. package/src/components/MNavigationDrawer.vue +298 -38
  70. package/src/components/MNavigationRail.vue +189 -8
  71. package/src/components/MPullToRefresh.vue +18 -0
  72. package/src/components/MSearchBar.vue +29 -12
  73. package/src/components/MTopAppBar.vue +252 -28
  74. package/src/components/MTransition.vue +36 -41
  75. package/src/composables/_searchAppBar.ts +9 -0
  76. package/src/composables/_springAnimation.ts +74 -0
  77. package/src/composables/_themeColor.ts +11 -4
  78. package/src/composables/_themeTransition.ts +71 -0
  79. package/src/composables/_useSheetMotion.ts +101 -88
  80. package/src/composables/_useSpring.ts +11 -21
  81. package/src/composables/motion.ts +73 -0
  82. package/src/composables/useColorPalette.ts +103 -20
  83. package/src/composables/useLocale.ts +6 -0
  84. package/src/composables/useTheme.ts +4 -12
  85. package/src/index.ts +8 -1
  86. package/src/locales/de.ts +3 -0
  87. package/src/locales/es.ts +3 -0
  88. package/src/locales/fr.ts +3 -0
  89. package/src/locales/ja.ts +3 -0
  90. package/src/locales/ko.ts +3 -0
  91. package/src/locales/pt.ts +3 -0
  92. package/src/locales/zh.ts +3 -0
  93. package/src/plugin.ts +9 -1
  94. package/src/styles/palettes-contrast.css +7764 -0
  95. package/src/styles/theme.css +46 -2
  96. package/dist/MTextField-DKtgPymd.js.map +0 -1
  97. package/dist/useLocale-Cn9MVIdw.js.map +0 -1
@@ -0,0 +1,63 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MChip from '../components/MChip.vue'
5
+
6
+ const chip = (props: Record<string, unknown>, slots: Record<string, string> = {}) =>
7
+ mount(MChip, { props, slots: { default: 'Label', ...slots } })
8
+
9
+ describe('MChip', () => {
10
+ it('keeps the generic tone chip without a type', () => {
11
+ const w = chip({ tone: 'primary' })
12
+ expect(w.element.tagName).toBe('SPAN')
13
+ expect(w.classes()).toContain('bg-primary-container')
14
+ expect(w.find('button').exists()).toBe(false)
15
+ })
16
+
17
+ it('labels the generic remove button from the locale', () => {
18
+ expect(chip({ removable: true }).find('button').attributes('aria-label')).toBe('Remove')
19
+ })
20
+
21
+ it('draws an outlined assist chip with a primary icon and 8px corners', () => {
22
+ const w = chip({ type: 'assist', icon: 'event' })
23
+ expect(w.classes()).toEqual(expect.arrayContaining(['border', 'border-outline-variant', 'text-on-surface', 'rounded-sm']))
24
+ expect(w.find('.material-symbols-outlined').classes()).toContain('text-primary')
25
+ expect(w.find('button').classes()).toContain('pl-2')
26
+ })
27
+
28
+ it('draws an elevated suggestion chip without an outline', () => {
29
+ const w = chip({ type: 'suggestion', elevated: true })
30
+ expect(w.classes()).toEqual(expect.arrayContaining(['bg-surface-container-low', 'shadow-elevation-1', 'text-on-surface-variant']))
31
+ expect(w.classes()).not.toContain('border')
32
+ expect(w.find('button').classes()).toEqual(expect.arrayContaining(['pl-4', 'pr-4']))
33
+ })
34
+
35
+ it('toggles a filter chip with v-model:selected, filling it and morphing to a pill', async () => {
36
+ const w = chip({ type: 'filter', selected: false })
37
+ await w.find('button').trigger('click')
38
+ expect(w.emitted('update:selected')).toEqual([[true]])
39
+ expect(w.emitted('click')).toHaveLength(1)
40
+ await w.setProps({ selected: true })
41
+ expect(w.classes()).toContain('bg-secondary-container')
42
+ expect(w.find('button').attributes('aria-pressed')).toBe('true')
43
+ expect(w.find('[aria-hidden="true"]').text()).toBe('check')
44
+ })
45
+
46
+ it('makes an input chip with an avatar and a separate remove button', async () => {
47
+ const w = chip({ type: 'input', removable: true }, { avatar: '<img alt="" src="a.png">' })
48
+ const buttons = w.findAll('button')
49
+ expect(buttons).toHaveLength(2)
50
+ expect(buttons[0]!.find('img').exists()).toBe(true)
51
+ expect(buttons[0]!.classes()).toEqual(expect.arrayContaining(['pl-1', 'pr-2']))
52
+ await buttons[1]!.trigger('click')
53
+ expect(w.emitted('remove')).toHaveLength(1)
54
+ expect(w.emitted('click')).toBeUndefined()
55
+ })
56
+
57
+ it('disables a typed chip', async () => {
58
+ const w = chip({ type: 'filter', disabled: true })
59
+ expect(w.find('button').attributes('disabled')).toBeDefined()
60
+ expect(w.classes()).toContain('text-on-surface/38')
61
+ await nextTick()
62
+ })
63
+ })
@@ -0,0 +1,36 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MFab from '../components/MFab.vue'
5
+
6
+ const fab = (props: Record<string, unknown>) => mount(MFab, { props: { icon: 'edit', ...props } })
7
+
8
+ describe('MFab', () => {
9
+ it('keeps the baseline extended FAB for the regular size', () => {
10
+ const b = fab({ label: 'Compose' }).find('button')
11
+ expect(b.classes()).toEqual(expect.arrayContaining(['h-14', 'min-w-20', 'pl-4', 'pr-5']))
12
+ expect(b.find('span.whitespace-nowrap').classes()).toContain('text-label-large')
13
+ })
14
+
15
+ it.each([
16
+ ['small', 'h-14', 'text-title-medium', '8px'],
17
+ ['medium', 'h-20', 'text-title-large', '12px'],
18
+ ['large', 'h-24', 'text-headline-small', '16px'],
19
+ ])('sizes the %s extended FAB from ExtendedFab tokens', (size, height, text, gap) => {
20
+ const b = fab({ label: 'Compose', size }).find('button')
21
+ expect(b.classes()).toContain(height)
22
+ const label = b.find('span.whitespace-nowrap')
23
+ expect(label.classes()).toContain(text)
24
+ expect((label.element as HTMLElement).style.paddingLeft).toBe(gap)
25
+ })
26
+
27
+ it('collapses to the icon with expanded false, keeping the label as its accessible name', async () => {
28
+ const w = fab({ label: 'Compose', expanded: false })
29
+ await nextTick()
30
+ const b = w.find('button')
31
+ expect(b.attributes('aria-label')).toBe('Compose')
32
+ const label = b.find('span.whitespace-nowrap').element as HTMLElement
33
+ expect(label.style.display).toBe('none')
34
+ expect((b.element as HTMLElement).style.width).toBe('56px')
35
+ })
36
+ })
@@ -0,0 +1,185 @@
1
+ import { describe, it, expect, afterEach, vi } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import MNavigationDrawer from '../components/MNavigationDrawer.vue'
4
+
5
+ const sections = [{ items: [{ value: 'inbox', label: 'Inbox', icon: 'inbox' }, { value: 'sent', label: 'Sent', icon: 'send' }] }]
6
+
7
+ let wrapper: VueWrapper | undefined
8
+ afterEach(() => {
9
+ wrapper?.unmount()
10
+ wrapper = undefined
11
+ document.body.innerHTML = ''
12
+ })
13
+
14
+ function open(props: Record<string, unknown> = {}) {
15
+ wrapper = mount(MNavigationDrawer, {
16
+ props: { modelValue: true, sections, ...props },
17
+ attachTo: document.body,
18
+ global: { stubs: { transition: false } },
19
+ })
20
+ const panel = document.body.querySelector<HTMLElement>('.nd-panel')!
21
+ // The open is a Web Animation, and happy-dom's timeline doesn't advance on its own
22
+ panel.getAnimations().forEach((a) => a.finish())
23
+ // happy-dom has no layout
24
+ Object.defineProperty(panel, 'offsetWidth', { value: 300 })
25
+ Object.defineProperty(panel, 'offsetHeight', { value: 300 })
26
+ return panel
27
+ }
28
+
29
+ // Moves 25px per step toward `to`, `msPerStep` apart (the events' timeStamp is what the fling velocity is measured
30
+ // from), along x, or along y with `vertical`, starting on `target` (the panel by default)
31
+ function swipe(panel: HTMLElement, from: number, to: number, msPerStep = 100, vertical = false, target: HTMLElement = panel) {
32
+ let t = 1000
33
+ const send = (type: string, p: number) => {
34
+ const e = new PointerEvent(type, { pointerId: 1, button: 0, bubbles: true, clientX: vertical ? 150 : p, clientY: vertical ? p : 300 })
35
+ Object.defineProperty(e, 'timeStamp', { value: t })
36
+ ;(type === 'pointerdown' ? target : panel).dispatchEvent(e)
37
+ }
38
+ const dir = Math.sign(to - from)
39
+ send('pointerdown', from)
40
+ for (let x = from; dir * (to - x) >= 0; x += dir * 25) {
41
+ t += msPerStep
42
+ send('pointermove', x)
43
+ }
44
+ send('pointerup', to)
45
+ }
46
+
47
+ describe('MNavigationDrawer swipe to close', () => {
48
+ it('opens as a Web Animation (compositor-run), with the open state inline underneath', () => {
49
+ wrapper = mount(MNavigationDrawer, {
50
+ props: { modelValue: true, sections },
51
+ attachTo: document.body,
52
+ global: { stubs: { transition: false } },
53
+ })
54
+ const panel = document.body.querySelector<HTMLElement>('.nd-panel')!
55
+ expect(panel.getAnimations()).toHaveLength(1)
56
+ expect(panel.style.transform).toBe('translateX(0%)')
57
+ expect(document.body.querySelector<HTMLElement>('.nd-scrim')!.getAnimations()).toHaveLength(1)
58
+ })
59
+
60
+ it('closes when slowly swiped past half its width, and springs back from a short swipe', () => {
61
+ const panel = open()
62
+ swipe(panel, 250, 175, 400)
63
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
64
+ swipe(panel, 250, 50, 400)
65
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
66
+ })
67
+
68
+ it('closes on a quick flick even when it moved less than half', () => {
69
+ const panel = open()
70
+ swipe(panel, 250, 175, 16)
71
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
72
+ })
73
+
74
+ it('swipes toward its own side when it opens from the right', () => {
75
+ const panel = open({ side: 'right' })
76
+ swipe(panel, 100, 25, 16)
77
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
78
+ swipe(panel, 100, 300, 400)
79
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
80
+ })
81
+
82
+ it('ignores a vertical drag (the items scroll)', () => {
83
+ const panel = open()
84
+ const opts = { pointerId: 1, button: 0, bubbles: true, clientX: 250 }
85
+ panel.dispatchEvent(new PointerEvent('pointerdown', { ...opts, clientY: 300 }))
86
+ panel.dispatchEvent(new PointerEvent('pointermove', { ...opts, clientX: 240, clientY: 200 }))
87
+ panel.dispatchEvent(new PointerEvent('pointermove', { ...opts, clientX: 40, clientY: 200 }))
88
+ panel.dispatchEvent(new PointerEvent('pointerup', { ...opts, clientX: 40, clientY: 200 }))
89
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
90
+ })
91
+
92
+ it('does not swipe with swipeEnabled false', () => {
93
+ swipe(open({ swipeEnabled: false }), 250, 0, 16)
94
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
95
+ })
96
+
97
+ it('closes a bottom drawer swiped down and a top drawer swiped up', () => {
98
+ let panel = open({ side: 'bottom' })
99
+ swipe(panel, 100, 175, 400, true)
100
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
101
+ swipe(panel, 100, 300, 400, true)
102
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
103
+ wrapper!.unmount()
104
+ panel = open({ side: 'top' })
105
+ swipe(panel, 250, 175, 16, true)
106
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
107
+ })
108
+
109
+ it('lets a vertical drawer\'s list scroll first: the drawer follows only once the list is at its edge', () => {
110
+ const panel = open({ side: 'bottom' })
111
+ const list = panel.querySelector<HTMLElement>('[data-nd-list]')!
112
+ Object.defineProperty(list, 'scrollHeight', { value: 600 })
113
+ Object.defineProperty(list, 'clientHeight', { value: 200 })
114
+ list.scrollTop = 50
115
+ swipe(panel, 100, 300, 16, true, list)
116
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
117
+ // Swiping up never moves it: there's nothing further to open
118
+ list.scrollTop = 0
119
+ swipe(panel, 300, 100, 16, true, list)
120
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
121
+ swipe(panel, 100, 300, 16, true, list)
122
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
123
+ })
124
+
125
+ it('claims a top/bottom touch swipe on its first move, so the browser never starts its own pan', () => {
126
+ const panel = open({ side: 'bottom' })
127
+ const list = panel.querySelector<HTMLElement>('[data-nd-list]')!
128
+ let ts = 1000
129
+ const touch = (type: string, y: number) => {
130
+ const t = { identifier: 1, clientX: 150, clientY: y, target: list }
131
+ const ev = new Event(type, { bubbles: true, cancelable: true }) as Event & Record<string, unknown>
132
+ Object.assign(ev, { touches: type === 'touchend' ? [] : [t], changedTouches: [t] })
133
+ Object.defineProperty(ev, 'timeStamp', { value: (ts += 400) })
134
+ list.dispatchEvent(ev)
135
+ return ev
136
+ }
137
+ touch('touchstart', 100)
138
+ expect(touch('touchmove', 103).defaultPrevented).toBe(true)
139
+ touch('touchmove', 300)
140
+ touch('touchend', 300)
141
+ expect(wrapper!.emitted('update:modelValue')).toEqual([[false]])
142
+ })
143
+
144
+ it('leaves a top/bottom touch swipe toward the open side to the list', () => {
145
+ const panel = open({ side: 'bottom' })
146
+ const list = panel.querySelector<HTMLElement>('[data-nd-list]')!
147
+ const touch = (type: string, y: number) => {
148
+ const t = { identifier: 1, clientX: 150, clientY: y, target: list }
149
+ const ev = new Event(type, { bubbles: true, cancelable: true }) as Event & Record<string, unknown>
150
+ Object.assign(ev, { touches: type === 'touchend' ? [] : [t], changedTouches: [t] })
151
+ list.dispatchEvent(ev)
152
+ return ev
153
+ }
154
+ touch('touchstart', 300)
155
+ expect(touch('touchmove', 297).defaultPrevented).toBe(false)
156
+ expect(touch('touchmove', 100).defaultPrevented).toBe(false)
157
+ touch('touchend', 100)
158
+ expect(wrapper!.emitted('update:modelValue')).toBeUndefined()
159
+ })
160
+
161
+ it('keeps a top/bottom swipe out of the list\'s touch-action while the list is at that edge', async () => {
162
+ vi.stubGlobal('CSS', { supports: (p: string, v: string) => p === 'touch-action' && v === 'pan-down' })
163
+ const nextFrame = () => new Promise((r) => requestAnimationFrame(r))
164
+ let panel = open({ side: 'bottom' })
165
+ let list = panel.querySelector<HTMLElement>('[data-nd-list]')!
166
+ Object.defineProperty(list, 'scrollHeight', { value: 600 })
167
+ Object.defineProperty(list, 'clientHeight', { value: 200 })
168
+ await nextFrame()
169
+ // At the top only the finger moving up scrolls natively; down is the drawer's
170
+ expect(list.style.touchAction).toBe('pan-down')
171
+ expect(panel.classList.contains('touch-none')).toBe(true)
172
+ list.scrollTop = 50
173
+ list.dispatchEvent(new Event('scroll'))
174
+ expect(list.style.touchAction).toBe('pan-y')
175
+ wrapper!.unmount()
176
+
177
+ panel = open({ side: 'top' })
178
+ list = panel.querySelector<HTMLElement>('[data-nd-list]')!
179
+ Object.defineProperty(list, 'scrollHeight', { value: 200 })
180
+ Object.defineProperty(list, 'clientHeight', { value: 200 })
181
+ await nextFrame()
182
+ expect(list.style.touchAction).toBe('pan-up')
183
+ vi.unstubAllGlobals()
184
+ })
185
+ })
@@ -0,0 +1,93 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import MNavigationRail from '../components/MNavigationRail.vue'
4
+
5
+ const items = [
6
+ { value: 'inbox', label: 'Inbox', icon: 'inbox' },
7
+ { value: 'sent', label: 'Sent', icon: 'send' },
8
+ ]
9
+
10
+ let wrapper: VueWrapper | undefined
11
+ afterEach(() => {
12
+ wrapper?.unmount()
13
+ wrapper = undefined
14
+ document.body.innerHTML = ''
15
+ })
16
+
17
+ function open(props: Record<string, unknown> = {}) {
18
+ wrapper = mount(MNavigationRail, {
19
+ props: { modelValue: 'inbox', items, modal: true, hideOnCollapse: true, expanded: true, ...props },
20
+ attachTo: document.body,
21
+ global: { stubs: { transition: false } },
22
+ })
23
+ const panel = document.body.querySelector<HTMLElement>('.wnr-panel')!
24
+ // The slide-in is a Web Animation, and happy-dom's timeline doesn't advance on its own
25
+ panel?.getAnimations().forEach((a) => a.finish())
26
+ return panel
27
+ }
28
+
29
+ // Moves 25px per step, `msPerStep` apart (the events' timeStamp is what the fling velocity is measured from)
30
+ function swipe(panel: HTMLElement, from: number, to: number, msPerStep = 100) {
31
+ let t = 1000
32
+ const send = (type: string, x: number) => {
33
+ const e = new PointerEvent(type, { pointerId: 1, button: 0, bubbles: true, clientY: 300, clientX: x })
34
+ Object.defineProperty(e, 'timeStamp', { value: t })
35
+ panel.dispatchEvent(e)
36
+ }
37
+ send('pointerdown', from)
38
+ for (let x = from; x >= to; x -= 25) {
39
+ t += msPerStep
40
+ send('pointermove', x)
41
+ }
42
+ send('pointerup', to)
43
+ }
44
+
45
+ describe('MNavigationRail', () => {
46
+ it('shows no collapsed rail with hideOnCollapse, only the modal panel', () => {
47
+ const panel = open()
48
+ expect(panel).not.toBeNull()
49
+ expect(wrapper!.find('nav').exists()).toBe(false)
50
+ })
51
+
52
+ it('slides the hideOnCollapse panel in as a Web Animation, the open state inline underneath', async () => {
53
+ wrapper = mount(MNavigationRail, {
54
+ props: { modelValue: 'inbox', items, modal: true, hideOnCollapse: true, expanded: false },
55
+ attachTo: document.body,
56
+ global: { stubs: { transition: false } },
57
+ })
58
+ await wrapper.setProps({ expanded: true })
59
+ const panel = document.body.querySelector<HTMLElement>('.wnr-panel')!
60
+ const [slide] = panel.getAnimations()
61
+ expect((slide!.effect as KeyframeEffect).getKeyframes()[0]!.transform).toBe('translateX(-100%)')
62
+ expect(panel.style.transform).toBe('translateX(0%)')
63
+ })
64
+
65
+ it('keeps the collapsed rail on screen in the default modal', () => {
66
+ open({ hideOnCollapse: false })
67
+ expect(wrapper!.find('nav').exists()).toBe(true)
68
+ })
69
+
70
+ it('closes when slowly swiped past half its width, and springs back from a short swipe', () => {
71
+ const panel = open()
72
+ swipe(panel, 200, 150, 400)
73
+ expect(wrapper!.emitted('update:expanded')).toBeUndefined()
74
+ swipe(panel, 200, 50, 400)
75
+ expect(wrapper!.emitted('update:expanded')).toEqual([[false]])
76
+ })
77
+
78
+ it('closes on a quick flick even when it moved less than half', () => {
79
+ const panel = open()
80
+ swipe(panel, 200, 150, 16)
81
+ expect(wrapper!.emitted('update:expanded')).toEqual([[false]])
82
+ })
83
+
84
+ it('ignores a vertical drag (the items scroll)', () => {
85
+ const panel = open()
86
+ const opts = { pointerId: 1, button: 0, bubbles: true, clientX: 200 }
87
+ panel.dispatchEvent(new PointerEvent('pointerdown', { ...opts, clientY: 300 }))
88
+ panel.dispatchEvent(new PointerEvent('pointermove', { ...opts, clientX: 190, clientY: 200 }))
89
+ panel.dispatchEvent(new PointerEvent('pointermove', { ...opts, clientX: 40, clientY: 200 }))
90
+ panel.dispatchEvent(new PointerEvent('pointerup', { ...opts, clientX: 40, clientY: 200 }))
91
+ expect(wrapper!.emitted('update:expanded')).toBeUndefined()
92
+ })
93
+ })
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from 'vitest'
1
+ import { describe, it, expect, vi } from 'vitest'
2
2
  import { mount } from '@vue/test-utils'
3
3
  import MPullToRefresh from '../components/MPullToRefresh.vue'
4
4
 
@@ -103,4 +103,21 @@ describe('MPullToRefresh (mouse)', () => {
103
103
  expect(wrapper.emitted('refresh')).toHaveLength(1)
104
104
  wrapper.unmount()
105
105
  })
106
+
107
+ it('lets the browser pan only upward while a pull can start, both ways once scrolled or refreshing', async () => {
108
+ vi.stubGlobal('CSS', { supports: (p: string, v: string) => p === 'touch-action' && v === 'pan-down' })
109
+ const { wrapper, scrollEl } = mountPtr()
110
+ const el = scrollEl as HTMLElement
111
+ expect(el.style.touchAction).toBe('pan-down')
112
+ el.scrollTop = 120
113
+ el.dispatchEvent(new Event('scroll'))
114
+ expect(el.style.touchAction).toBe('pan-y')
115
+ el.scrollTop = 0
116
+ el.dispatchEvent(new Event('scroll'))
117
+ expect(el.style.touchAction).toBe('pan-down')
118
+ await wrapper.setProps({ refreshing: true })
119
+ expect(el.style.touchAction).toBe('pan-y')
120
+ wrapper.unmount()
121
+ vi.unstubAllGlobals()
122
+ })
106
123
  })
@@ -0,0 +1,99 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MTopAppBar from '../components/MTopAppBar.vue'
5
+
6
+ let wrapper: VueWrapper | undefined
7
+ afterEach(() => {
8
+ wrapper?.unmount()
9
+ wrapper = undefined
10
+ document.body.innerHTML = ''
11
+ })
12
+
13
+ function bar(props: Record<string, unknown>) {
14
+ wrapper = mount(MTopAppBar, { props: { title: 'Inbox', ...props }, attachTo: document.body })
15
+ const bottomRow = () => wrapper!.find('.items-end').element as HTMLElement
16
+ return { bar: wrapper.find('header').element as HTMLElement, bottomRow }
17
+ }
18
+
19
+ function scroller() {
20
+ const el = document.createElement('div')
21
+ document.body.appendChild(el)
22
+ return {
23
+ el,
24
+ to(y: number) {
25
+ el.scrollTop = y
26
+ el.dispatchEvent(new Event('scroll'))
27
+ },
28
+ }
29
+ }
30
+
31
+ describe('MTopAppBar', () => {
32
+ it.each([
33
+ [{ variant: 'medium' }, '48px'],
34
+ [{ variant: 'large' }, '88px'],
35
+ [{ variant: 'medium', flexible: true }, '48px'],
36
+ [{ variant: 'medium', flexible: true, subtitle: 'Work' }, '72px'],
37
+ [{ variant: 'large', flexible: true }, '56px'],
38
+ [{ variant: 'large', flexible: true, subtitle: 'Work' }, '88px'],
39
+ ])('sizes the title row of %o from the app bar tokens', (props, height) => {
40
+ expect(bar(props).bottomRow().style.height).toBe(height)
41
+ })
42
+
43
+ it('uses the flexible title and subtitle styles', () => {
44
+ bar({ variant: 'large', flexible: true, subtitle: 'Work' })
45
+ expect(wrapper!.find('h1').classes()).toContain('text-display-small')
46
+ expect(wrapper!.find('.items-end p').classes()).toContain('text-title-medium')
47
+ })
48
+
49
+ it('shows a subtitle under a small title', () => {
50
+ bar({ subtitle: '3 unread' })
51
+ expect(wrapper!.find('p').text()).toBe('3 unread')
52
+ expect(wrapper!.find('p').classes()).toContain('text-label-medium')
53
+ })
54
+
55
+ it('collapses a medium bar with the content and swaps the titles (exit-until-collapsed)', async () => {
56
+ const s = scroller()
57
+ const { bar: el, bottomRow } = bar({ variant: 'medium', scrollBehavior: 'exit-until-collapsed', scrollTarget: s.el })
58
+ expect(wrapper!.find('header').classes()).toContain('sticky')
59
+ s.to(30)
60
+ expect(el.style.height).toBe('82px')
61
+ // The bottom margin keeps the expanded 112px in the layout
62
+ expect(el.style.marginBottom).toBe('30px')
63
+ expect(bottomRow().style.height).toBe('18px')
64
+ s.to(200)
65
+ expect(el.style.height).toBe('64px')
66
+ const [small, big] = wrapper!.findAll('.min-w-0').map((w) => w.element as HTMLElement)
67
+ expect(small!.style.opacity).toBe('1')
68
+ expect(big!.style.opacity).toBe('0')
69
+ // Only back at the top does it expand again
70
+ s.to(10)
71
+ expect(el.style.height).toBe('102px')
72
+ })
73
+
74
+ it('hides a small bar while scrolling down and brings it back scrolling up (enter-always)', () => {
75
+ const s = scroller()
76
+ const { bar: el } = bar({ scrollBehavior: 'enter-always', scrollTarget: s.el })
77
+ s.to(40)
78
+ expect(el.style.height).toBe('24px')
79
+ s.to(300)
80
+ expect(el.style.height).toBe('0px')
81
+ s.to(280)
82
+ expect(el.style.height).toBe('20px')
83
+ })
84
+
85
+ it('keeps the navigation button a grandchild of the header (consumers select header > div > button)', () => {
86
+ bar({ navigationIcon: 'menu' })
87
+ expect(wrapper!.find('header > div > button').exists()).toBe(true)
88
+ })
89
+
90
+ it('takes the scrolled color when content moves under a pinned bar', async () => {
91
+ const s = scroller()
92
+ const { bar: el } = bar({ scrollBehavior: 'pinned', scrollTarget: s.el })
93
+ expect(el.classList).toContain('bg-surface')
94
+ s.to(5)
95
+ await nextTick()
96
+ expect(el.classList).toContain('bg-surface-container')
97
+ expect(el.style.height).toBe('')
98
+ })
99
+ })
@@ -24,4 +24,16 @@ describe('MTransition', () => {
24
24
  await wait(800)
25
25
  expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['b'])
26
26
  })
27
+
28
+ it('slides the entering view in from 20% of its width as a Web Animation', async () => {
29
+ const page = ref('a')
30
+ wrapper = mount(defineComponent({
31
+ setup: () => () => h(MTransition, null, () => h('div', { key: page.value, class: 'page' }, page.value)),
32
+ }), { attachTo: document.body, global: { stubs: { transition: false } } })
33
+ page.value = 'b'
34
+ await nextTick()
35
+ const entering = wrapper.findAll('.page')[1]!.element as HTMLElement
36
+ const slide = entering.getAnimations().find((a) => 'transform' in (a.effect as KeyframeEffect).getKeyframes()[0]!)
37
+ expect((slide!.effect as KeyframeEffect).getKeyframes()[0]!.transform).toBe('translateX(20%)')
38
+ })
27
39
  })
@@ -0,0 +1,64 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick } from 'vue'
4
+ import { readFileSync } from 'node:fs'
5
+ import { resolve } from 'node:path'
6
+ import { useColorPalette, palettes } from '../composables/useColorPalette'
7
+
8
+ function withSetup() {
9
+ let result!: ReturnType<typeof useColorPalette>
10
+ mount(defineComponent({
11
+ setup() {
12
+ result = useColorPalette()
13
+ return () => h('div')
14
+ },
15
+ }))
16
+ return result
17
+ }
18
+
19
+ describe('contrast levels', () => {
20
+ afterEach(async () => {
21
+ withSetup().setContrast('standard')
22
+ await nextTick()
23
+ })
24
+
25
+ it('sets data-contrast on <html> and remembers the level', async () => {
26
+ const { setContrast, contrast, activeContrast } = withSetup()
27
+ setContrast('high')
28
+ await nextTick()
29
+ expect(contrast.value).toBe('high')
30
+ expect(activeContrast.value).toBe('high')
31
+ expect(document.documentElement.getAttribute('data-contrast')).toBe('high')
32
+ expect(localStorage.getItem('m3-contrast')).toBe('high')
33
+ setContrast('standard')
34
+ await nextTick()
35
+ expect(document.documentElement.hasAttribute('data-contrast')).toBe(false)
36
+ })
37
+
38
+ it('resolves system to the OS preference (standard without prefers-contrast: more)', async () => {
39
+ const { setContrast, activeContrast } = withSetup()
40
+ setContrast('system')
41
+ await nextTick()
42
+ expect(activeContrast.value).toBe('standard')
43
+ })
44
+ })
45
+
46
+ describe('palettes-contrast.css', () => {
47
+ const css = readFileSync(resolve(__dirname, '../styles/palettes-contrast.css'), 'utf8')
48
+
49
+ it('has medium and high, light and dark, for every built-in palette', () => {
50
+ for (const { id } of palettes) {
51
+ const base = id === 'purple' ? 'html:not([data-palette])' : `[data-palette='${id}']`
52
+ for (const level of ['medium', 'high']) {
53
+ expect(css).toContain(`${base}[data-contrast='${level}']:not(.dark) {`)
54
+ expect(css).toContain(`${base}[data-contrast='${level}'].dark {`)
55
+ }
56
+ }
57
+ })
58
+
59
+ it('raises contrast: high-contrast on-surface is black in light and white in dark', () => {
60
+ const block = (selector: string) => css.slice(css.indexOf(`${selector} {`)).split('}')[0]!
61
+ expect(block("[data-palette='teal'][data-contrast='high']:not(.dark)")).toContain('--color-on-surface: #000000;')
62
+ expect(block("[data-palette='teal'][data-contrast='high'].dark")).toContain('--color-on-surface: #FFFFFF;')
63
+ })
64
+ })
@@ -162,6 +162,23 @@ describe('createM3UI themeColor', () => {
162
162
  document.documentElement.style.setProperty('--color-surface', '#fef7ff')
163
163
  })
164
164
 
165
+ // Reproduces the old observer's miss only when run alone (-t): the seed tests above leave theme-transitioning
166
+ // timers that touch <html> later and update the meta anyway
167
+ it('follows a generated palette rewritten in place (same seed id, new contrast)', async () => {
168
+ const { createM3UI } = await fresh()
169
+ createApp({}).use(createM3UI({ themeColor: 'surface' }))
170
+ const meta = () => document.querySelector<HTMLMetaElement>('meta[name="theme-color"]')!
171
+ const style = document.createElement('style')
172
+ style.id = 'm3-dynamic-palette'
173
+ document.head.appendChild(style)
174
+ await settle()
175
+ // Only the <style>'s text changes; <html>'s attributes stay the same
176
+ document.documentElement.style.setProperty('--color-surface', '#faf8ff')
177
+ style.textContent = '[data-palette="seed"] { --color-surface: #faf8ff }'
178
+ await settle()
179
+ expect(meta().content).toBe('#faf8ff')
180
+ })
181
+
165
182
  it('creates the meta and follows the palette', async () => {
166
183
  const { createM3UI } = await fresh()
167
184
  createApp({}).use(createM3UI({ themeColor: 'surface' }))
@@ -0,0 +1,37 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { readFileSync } from 'node:fs'
3
+ import { resolve } from 'node:path'
4
+ import { cubicBezier, motionDurations, motionEasings, motionSprings } from '../composables/motion'
5
+ import { DEFAULT_SPATIAL, FAST_SPATIAL, fastOutSlowIn } from '../composables/_useSpring'
6
+
7
+ describe('motion tokens', () => {
8
+ it('evaluates cubic-bezier easings', () => {
9
+ const linear = cubicBezier(...motionEasings.linear)
10
+ expect(linear(0.3)).toBeCloseTo(0.3, 5)
11
+ const emphasized = cubicBezier(...motionEasings.emphasized)
12
+ expect(emphasized(0)).toBe(0)
13
+ expect(emphasized(1)).toBe(1)
14
+ // Front-loaded: well past halfway by the middle of the duration
15
+ expect(emphasized(0.5)).toBeGreaterThan(0.85)
16
+ expect(fastOutSlowIn(0.5)).toBeCloseTo(cubicBezier(0.4, 0, 0.2, 1)(0.5), 10)
17
+ })
18
+
19
+ it('keeps the internal spring shorthands on the Standard scheme', () => {
20
+ expect(FAST_SPATIAL).toEqual(motionSprings.standard.fastSpatial)
21
+ expect(DEFAULT_SPATIAL).toEqual({ dampingRatio: 0.9, stiffness: 700 })
22
+ expect(motionSprings.expressive.fastSpatial).toEqual({ dampingRatio: 0.6, stiffness: 800 })
23
+ })
24
+
25
+ it('matches the CSS variables in theme.css', () => {
26
+ const css = readFileSync(resolve(__dirname, '../styles/theme.css'), 'utf8')
27
+ for (const [name, ms] of Object.entries(motionDurations)) {
28
+ const cssName = name.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/(\d)$/, '-$1')
29
+ expect(css).toContain(`--duration-${cssName}: ${ms}ms;`)
30
+ }
31
+ for (const [name, [x1, y1, x2, y2]] of Object.entries(motionEasings)) {
32
+ if (name === 'linear') continue
33
+ const cssName = name.replace(/([A-Z])/g, '-$1').toLowerCase()
34
+ expect(css).toContain(`--ease-${cssName}: cubic-bezier(${x1}, ${y1}, ${x2}, ${y2});`)
35
+ }
36
+ })
37
+ })