@m3ui-vue/m3ui-vue 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/API.md +199 -54
- package/dist/{MTextField-pJU1vFaR.js → MTextField-Ck0oWDMk.js} +8 -2
- package/dist/MTextField-Ck0oWDMk.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBox.vue.d.ts +3 -3
- package/dist/components/MColorPicker.vue.d.ts +13 -1
- package/dist/components/MColorPickerModal.vue.d.ts +14 -2
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +1 -1
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MOverlay.vue.d.ts +1 -1
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +9 -0
- package/dist/components/MSplitter.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +15 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +10 -0
- package/dist/index.d.ts +9 -1
- package/dist/locales/index.js +70 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4808 -3622
- package/dist/m3ui.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +77 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-Drihe5G2.js → useLocale-CFW8cIzL.js} +11 -1
- package/dist/useLocale-CFW8cIzL.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MScrollField.test.ts +41 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/components/MBox.vue +4 -2
- package/src/components/MButtonGroup.vue +116 -35
- package/src/components/MColorPicker.vue +114 -210
- package/src/components/MColorPickerModal.vue +50 -251
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MList.vue +33 -3
- package/src/components/MListItem.vue +75 -5
- package/src/components/MScrollField.vue +302 -0
- package/src/components/MScrollable.vue +160 -5
- package/src/components/MSplitter.vue +33 -10
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MTransition.vue +149 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +89 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +22 -0
- package/src/index.ts +9 -1
- package/src/locales/de.ts +10 -0
- package/src/locales/es.ts +10 -0
- package/src/locales/fr.ts +10 -0
- package/src/locales/ja.ts +10 -0
- package/src/locales/ko.ts +10 -0
- package/src/locales/pt.ts +10 -0
- package/src/locales/zh.ts +10 -0
- package/src/plugin.ts +28 -7
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +77 -0
- package/dist/MTextField-pJU1vFaR.js.map +0 -1
- package/dist/useLocale-Drihe5G2.js.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MList from '../components/MList.vue'
|
|
5
|
+
import MListItem from '../components/MListItem.vue'
|
|
6
|
+
import MListSubheader from '../components/MListSubheader.vue'
|
|
7
|
+
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
wrapper?.unmount()
|
|
11
|
+
wrapper = undefined
|
|
12
|
+
document.body.innerHTML = ''
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Springs run on rAF; give them time to settle
|
|
16
|
+
const settle = () => new Promise((r) => setTimeout(r, 600))
|
|
17
|
+
const radius = (el: Element) => (el as HTMLElement).style.borderRadius
|
|
18
|
+
|
|
19
|
+
describe('MListItem shape morph', () => {
|
|
20
|
+
it('rests at 4px and grows on hover and press when clickable', async () => {
|
|
21
|
+
wrapper = mount(MListItem, { props: { title: 'A', clickable: true }, attachTo: document.body })
|
|
22
|
+
const row = wrapper.element
|
|
23
|
+
await settle()
|
|
24
|
+
expect(radius(row)).toBe('4px')
|
|
25
|
+
row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
26
|
+
await settle()
|
|
27
|
+
expect(radius(row)).toBe('8px')
|
|
28
|
+
row.dispatchEvent(new PointerEvent('pointerdown', { button: 0, pointerType: 'mouse' }))
|
|
29
|
+
await settle()
|
|
30
|
+
expect(radius(row)).toBe('16px')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('ignores hover when not interactive, but morphs when selected', async () => {
|
|
34
|
+
wrapper = mount(MListItem, { props: { title: 'A' }, attachTo: document.body })
|
|
35
|
+
wrapper.element.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
36
|
+
await settle()
|
|
37
|
+
expect(radius(wrapper.element)).toBe('4px')
|
|
38
|
+
await wrapper.setProps({ active: true })
|
|
39
|
+
await settle()
|
|
40
|
+
expect(radius(wrapper.element)).toBe('16px')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('rounds the outer corners of each segmented run', async () => {
|
|
44
|
+
wrapper = mount(MList, {
|
|
45
|
+
props: { segmented: true },
|
|
46
|
+
slots: {
|
|
47
|
+
default: () => [
|
|
48
|
+
h(MListItem, { title: 'A' }),
|
|
49
|
+
h(MListItem, { title: 'B' }),
|
|
50
|
+
h(MListItem, { title: 'C' }),
|
|
51
|
+
h(MListSubheader, { title: 'More' }),
|
|
52
|
+
h(MListItem, { title: 'D' }),
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
attachTo: document.body,
|
|
56
|
+
})
|
|
57
|
+
await settle()
|
|
58
|
+
const rows = wrapper.findAll('[role="listitem"]').map((w) => w.element)
|
|
59
|
+
expect(rows.map(radius)).toEqual([
|
|
60
|
+
'16px 16px 4px 4px',
|
|
61
|
+
'4px',
|
|
62
|
+
'4px 4px 16px 16px',
|
|
63
|
+
'16px',
|
|
64
|
+
])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('keeps the pill in nav lists', async () => {
|
|
68
|
+
wrapper = mount(MList, {
|
|
69
|
+
props: { nav: true },
|
|
70
|
+
slots: { default: () => h(MListItem, { title: 'A', clickable: true }) },
|
|
71
|
+
attachTo: document.body,
|
|
72
|
+
})
|
|
73
|
+
await settle()
|
|
74
|
+
expect(radius(wrapper.find('[role="listitem"]').element)).toBe('')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MScrollField from '../components/MScrollField.vue'
|
|
4
|
+
|
|
5
|
+
let wrapper: VueWrapper | undefined
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
wrapper?.unmount()
|
|
8
|
+
wrapper = undefined
|
|
9
|
+
document.body.innerHTML = ''
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
13
|
+
|
|
14
|
+
describe('MScrollField', () => {
|
|
15
|
+
it('formats with two digits and moves with the arrow keys, wrapping around', async () => {
|
|
16
|
+
wrapper = mount(MScrollField, {
|
|
17
|
+
props: { modelValue: 0, count: 60, label: 'Minute', 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
18
|
+
attachTo: document.body,
|
|
19
|
+
})
|
|
20
|
+
const field = wrapper.find('[role="slider"]')
|
|
21
|
+
expect(field.attributes('aria-valuetext')).toBe('00')
|
|
22
|
+
await field.trigger('keydown', { key: 'ArrowUp' })
|
|
23
|
+
await wait()
|
|
24
|
+
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([59])
|
|
25
|
+
expect(field.attributes('aria-valuetext')).toBe('59')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('follows an outside change the short way around', async () => {
|
|
29
|
+
wrapper = mount(MScrollField, { props: { modelValue: 58, count: 60 }, attachTo: document.body })
|
|
30
|
+
await wrapper.setProps({ modelValue: 1 })
|
|
31
|
+
await wait()
|
|
32
|
+
// 58 → 59 → 0 → 1, never back through 57…2
|
|
33
|
+
const seen = wrapper.emitted<[number]>('update:modelValue')!.map((e) => e[0])
|
|
34
|
+
expect(seen).toEqual([59, 0, 1])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('uses a custom format', () => {
|
|
38
|
+
wrapper = mount(MScrollField, { props: { modelValue: 1, count: 2, format: (i: number) => ['L', 'oz'][i]! } })
|
|
39
|
+
expect(wrapper.find('[role="slider"]').attributes('aria-valuetext')).toBe('oz')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MScrollable from '../components/MScrollable.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
describe('MScrollable indicator', () => {
|
|
15
|
+
it('hides the native scrollbar and sizes the thumb to the visible fraction', async () => {
|
|
16
|
+
wrapper = mount(MScrollable, {
|
|
17
|
+
props: { scrollbar: 'indicator', scrollbarFade: false },
|
|
18
|
+
slots: { default: () => h('div', 'Long content') },
|
|
19
|
+
attachTo: document.body,
|
|
20
|
+
})
|
|
21
|
+
const el = wrapper.element as HTMLElement
|
|
22
|
+
expect(el.className).toContain('m3-scrollable-hidden')
|
|
23
|
+
Object.defineProperty(el, 'clientHeight', { value: 200, configurable: true })
|
|
24
|
+
Object.defineProperty(el, 'scrollHeight', { value: 800, configurable: true })
|
|
25
|
+
el.scrollTop = 300
|
|
26
|
+
el.dispatchEvent(new Event('scroll'))
|
|
27
|
+
const thumb = wrapper.find('.m3-scrollable-thumb-v').element as HTMLElement
|
|
28
|
+
// Track 196px (2px inset at each end), thumb 196 × 200/800 = 49px, offset 2 + 300/600 × (196 − 49)
|
|
29
|
+
expect(thumb.style.height).toBe('49px')
|
|
30
|
+
expect(thumb.style.transform).toBe('translate(0px, 375.5px)')
|
|
31
|
+
expect(thumb.style.opacity).toBe('1')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('draws nothing when the content fits', async () => {
|
|
35
|
+
wrapper = mount(MScrollable, { props: { scrollbar: 'indicator' }, slots: { default: () => h('div', 'Short') } })
|
|
36
|
+
const el = wrapper.element as HTMLElement
|
|
37
|
+
Object.defineProperty(el, 'clientHeight', { value: 200, configurable: true })
|
|
38
|
+
Object.defineProperty(el, 'scrollHeight', { value: 200, configurable: true })
|
|
39
|
+
el.dispatchEvent(new Event('scroll'))
|
|
40
|
+
expect((wrapper.find('.m3-scrollable-thumb-v').element as HTMLElement).style.display).toBe('none')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MSwipeToDismiss from '../components/MSwipeToDismiss.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
14
|
+
|
|
15
|
+
describe('MSwipeToDismiss', () => {
|
|
16
|
+
function setup(props: Record<string, unknown> = {}) {
|
|
17
|
+
wrapper = mount(MSwipeToDismiss, {
|
|
18
|
+
props,
|
|
19
|
+
slots: { default: () => h('div', 'Row'), background: ({ target }: { target: string }) => h('span', { class: 'bg' }, target) },
|
|
20
|
+
attachTo: document.body,
|
|
21
|
+
})
|
|
22
|
+
Object.defineProperty(wrapper.element, 'offsetWidth', { value: 300, configurable: true })
|
|
23
|
+
return wrapper
|
|
24
|
+
}
|
|
25
|
+
function drag(el: Element, dx: number, durationMs: number) {
|
|
26
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, pointerId: 1, bubbles: true }))
|
|
27
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + dx / 2, clientY: 10, pointerId: 1, timeStamp: 0 } as PointerEventInit))
|
|
28
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
29
|
+
return new Promise<void>((r) => setTimeout(() => {
|
|
30
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
31
|
+
r()
|
|
32
|
+
}, durationMs))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Slowly (under the 125px/s fling velocity) and still moving when released, so the 56px threshold decides
|
|
36
|
+
async function slowDrag(el: Element, dx: number) {
|
|
37
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, pointerId: 1, bubbles: true }))
|
|
38
|
+
const steps = 10
|
|
39
|
+
for (let i = 1; i <= steps; i++) {
|
|
40
|
+
await wait(60)
|
|
41
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + (dx * i) / steps, clientY: 10, pointerId: 1 }))
|
|
42
|
+
}
|
|
43
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it('dismisses past the 56px threshold', async () => {
|
|
47
|
+
const w = setup()
|
|
48
|
+
await slowDrag(w.element, -80)
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(w.find('.bg').text()).toBe('end-to-start')
|
|
51
|
+
await wait(400)
|
|
52
|
+
expect(w.emitted('dismiss')?.[0]).toEqual(['end-to-start'])
|
|
53
|
+
expect(w.emitted('update:modelValue')?.[0]).toEqual(['end-to-start'])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('springs back from a short swipe', async () => {
|
|
57
|
+
const w = setup()
|
|
58
|
+
await slowDrag(w.element, 30)
|
|
59
|
+
await wait(400)
|
|
60
|
+
expect(w.emitted('dismiss')).toBeUndefined()
|
|
61
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('a quick flick dismisses even a short swipe', async () => {
|
|
65
|
+
const w = setup()
|
|
66
|
+
await drag(w.element, 30, 10)
|
|
67
|
+
await wait(400)
|
|
68
|
+
expect(w.emitted('dismiss')?.[0]).toEqual(['start-to-end'])
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('only swipes in the allowed directions', async () => {
|
|
72
|
+
const w = setup({ endToStart: false })
|
|
73
|
+
await drag(w.element, -120, 300)
|
|
74
|
+
await wait(400)
|
|
75
|
+
expect(w.emitted('dismiss')).toBeUndefined()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('slides back when v-model is reset from inside @dismiss', async () => {
|
|
79
|
+
const state = ref<'settled' | 'start-to-end' | 'end-to-start'>('settled')
|
|
80
|
+
wrapper = mount(defineComponent({
|
|
81
|
+
setup: () => () => h(MSwipeToDismiss, {
|
|
82
|
+
modelValue: state.value,
|
|
83
|
+
'onUpdate:modelValue': (v: typeof state.value) => { state.value = v },
|
|
84
|
+
onDismiss: () => { state.value = 'settled' },
|
|
85
|
+
}, () => h('div', 'Row')),
|
|
86
|
+
}), { attachTo: document.body })
|
|
87
|
+
const root = wrapper.find('.touch-pan-y').element
|
|
88
|
+
Object.defineProperty(root, 'offsetWidth', { value: 300, configurable: true })
|
|
89
|
+
await drag(root, 30, 10)
|
|
90
|
+
await wait(800)
|
|
91
|
+
expect(state.value).toBe('settled')
|
|
92
|
+
expect((root.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('animates back when v-model is reset', async () => {
|
|
96
|
+
const w = setup()
|
|
97
|
+
await w.setProps({ modelValue: 'start-to-end' })
|
|
98
|
+
await wait(400)
|
|
99
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('translateX(300px)')
|
|
100
|
+
await w.setProps({ modelValue: 'settled' })
|
|
101
|
+
await wait(400)
|
|
102
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MTransition from '../components/MTransition.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
14
|
+
|
|
15
|
+
describe('MTransition', () => {
|
|
16
|
+
it('overlaps both views while animating, then removes the old one', async () => {
|
|
17
|
+
const page = ref('a')
|
|
18
|
+
wrapper = mount(defineComponent({
|
|
19
|
+
setup: () => () => h(MTransition, { type: 'fade-through' }, () => h('div', { key: page.value, class: 'page' }, page.value)),
|
|
20
|
+
}), { attachTo: document.body, global: { stubs: { transition: false } } })
|
|
21
|
+
page.value = 'b'
|
|
22
|
+
await nextTick()
|
|
23
|
+
expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['a', 'b'])
|
|
24
|
+
await wait(800)
|
|
25
|
+
expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['b'])
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { createApp, defineComponent, h, nextTick } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import { generateScheme, schemeRoles, schemeToCss } from '../composables/dynamicColor'
|
|
5
|
+
|
|
6
|
+
describe('generateScheme', () => {
|
|
7
|
+
it('builds every role for light and dark, with the official tonal spot values', async () => {
|
|
8
|
+
const scheme = await generateScheme('#6750A4')
|
|
9
|
+
expect(Object.keys(scheme.light)).toEqual([...schemeRoles])
|
|
10
|
+
expect(Object.keys(scheme.dark)).toEqual([...schemeRoles])
|
|
11
|
+
// SchemeTonalSpot of the M3 baseline seed (material-color-utilities)
|
|
12
|
+
expect(scheme.light.primary).toBe('#65558f')
|
|
13
|
+
expect(scheme.light['primary-container']).toBe('#e9ddff')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('keeps fixed roles the same in light and dark', async () => {
|
|
17
|
+
const { light, dark } = await generateScheme('#0b57d0')
|
|
18
|
+
for (const role of schemeRoles.filter((r) => r.includes('fixed'))) expect(dark[role]).toBe(light[role])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('honors variant and contrast', async () => {
|
|
22
|
+
const base = await generateScheme('#0b57d0')
|
|
23
|
+
const mono = await generateScheme('#0b57d0', { variant: 'monochrome' })
|
|
24
|
+
const high = await generateScheme('#0b57d0', { contrast: 1 })
|
|
25
|
+
expect(mono.light.primary).not.toBe(base.light.primary)
|
|
26
|
+
expect(high.light['on-surface-variant']).not.toBe(base.light['on-surface-variant'])
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('writes CSS blocks like palettes.css', async () => {
|
|
30
|
+
const css = schemeToCss({ light: { primary: '#111111' }, dark: { primary: '#eeeeee' } }, 'brand')
|
|
31
|
+
expect(css).toContain("[data-palette='brand'] {\n --color-primary: #111111;\n}")
|
|
32
|
+
expect(css).toContain("[data-palette='brand'].dark {\n color-scheme: dark;\n --color-primary: #eeeeee;\n}")
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// useColorPalette keeps module-level state: load a fresh copy of it (and the plugin) per test
|
|
37
|
+
async function fresh() {
|
|
38
|
+
vi.resetModules()
|
|
39
|
+
const palette = await import('../composables/useColorPalette')
|
|
40
|
+
const plugin = await import('../plugin')
|
|
41
|
+
return { ...palette, ...plugin }
|
|
42
|
+
}
|
|
43
|
+
function setup(useColorPalette: () => ReturnType<typeof import('../composables/useColorPalette')['useColorPalette']>) {
|
|
44
|
+
let result!: ReturnType<typeof useColorPalette>
|
|
45
|
+
mount(defineComponent({ setup() { result = useColorPalette(); return () => h('div') } }))
|
|
46
|
+
return result
|
|
47
|
+
}
|
|
48
|
+
const generatedCss = () => document.getElementById('m3-dynamic-palette')?.textContent ?? ''
|
|
49
|
+
const settle = () => new Promise((r) => setTimeout(r, 50))
|
|
50
|
+
|
|
51
|
+
describe('seed palettes', () => {
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
localStorage.clear()
|
|
54
|
+
document.documentElement.removeAttribute('data-palette')
|
|
55
|
+
document.head.innerHTML = ''
|
|
56
|
+
})
|
|
57
|
+
afterEach(() => vi.resetModules())
|
|
58
|
+
|
|
59
|
+
it('setSeed generates the scheme, switches to it and remembers it', async () => {
|
|
60
|
+
const { useColorPalette } = await fresh()
|
|
61
|
+
const p = setup(useColorPalette)
|
|
62
|
+
await p.setSeed('#0b57d0', { variant: 'vibrant' })
|
|
63
|
+
await nextTick()
|
|
64
|
+
expect(p.palette.value).toBe('seed')
|
|
65
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('seed')
|
|
66
|
+
expect(generatedCss()).toContain("[data-palette='seed']")
|
|
67
|
+
expect(p.seed.value).toEqual({ seed: '#0b57d0', variant: 'vibrant' })
|
|
68
|
+
expect(JSON.parse(localStorage.getItem('m3-seed')!)).toEqual({ seed: '#0b57d0', variant: 'vibrant' })
|
|
69
|
+
expect(JSON.parse(localStorage.getItem('m3-palette-css')!).id).toBe('seed')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('the last choice wins: a palette after a seed, and the seed is kept', async () => {
|
|
73
|
+
const { useColorPalette } = await fresh()
|
|
74
|
+
const p = setup(useColorPalette)
|
|
75
|
+
await p.setSeed('#0b57d0')
|
|
76
|
+
p.set('teal')
|
|
77
|
+
await nextTick()
|
|
78
|
+
expect(p.palette.value).toBe('teal')
|
|
79
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('teal')
|
|
80
|
+
expect(p.seed.value?.seed).toBe('#0b57d0')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('restores a generated palette on reload before the generator loads', async () => {
|
|
84
|
+
localStorage.setItem('m3-palette', 'seed')
|
|
85
|
+
localStorage.setItem('m3-palette-css', JSON.stringify({ id: 'seed', css: "[data-palette='seed'] { --color-primary: #123456; }" }))
|
|
86
|
+
await fresh()
|
|
87
|
+
expect(generatedCss()).toContain('#123456')
|
|
88
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('seed')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('generates a custom palette from its seed when it has no CSS of its own', async () => {
|
|
92
|
+
const { useColorPalette, createM3UI } = await fresh()
|
|
93
|
+
createApp({}).use(createM3UI({ customPalettes: [{ id: 'brand', label: 'Brand', seed: '#0b6e4f' }] }))
|
|
94
|
+
const p = setup(useColorPalette)
|
|
95
|
+
p.set('brand')
|
|
96
|
+
await settle()
|
|
97
|
+
expect(generatedCss()).toContain("[data-palette='brand']")
|
|
98
|
+
expect(p.palette.value).toBe('brand')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('keeps a custom palette\'s own CSS instead of generating it', async () => {
|
|
102
|
+
const style = document.createElement('style')
|
|
103
|
+
style.textContent = "[data-palette='brand'] { --color-primary: #ff0000; }"
|
|
104
|
+
document.head.appendChild(style)
|
|
105
|
+
const { useColorPalette, createM3UI } = await fresh()
|
|
106
|
+
createApp({}).use(createM3UI({ customPalettes: [{ id: 'brand', label: 'Brand', seed: '#0b6e4f' }] }))
|
|
107
|
+
const p = setup(useColorPalette)
|
|
108
|
+
p.set('brand')
|
|
109
|
+
await settle()
|
|
110
|
+
expect(generatedCss()).toBe('')
|
|
111
|
+
expect(p.palette.value).toBe('brand')
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('createM3UI seed', () => {
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
localStorage.clear()
|
|
118
|
+
document.documentElement.removeAttribute('data-palette')
|
|
119
|
+
document.head.innerHTML = ''
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('uses the seed on the first visit', async () => {
|
|
123
|
+
const { createM3UI } = await fresh()
|
|
124
|
+
createApp({}).use(createM3UI({ seed: '#0b57d0' }))
|
|
125
|
+
await settle()
|
|
126
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('seed')
|
|
127
|
+
expect(localStorage.getItem('m3-palette')).toBe('seed')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('prefers palette over seed', async () => {
|
|
131
|
+
const { createM3UI } = await fresh()
|
|
132
|
+
createApp({}).use(createM3UI({ palette: 'teal', seed: '#0b57d0' }))
|
|
133
|
+
await settle()
|
|
134
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('teal')
|
|
135
|
+
expect(generatedCss()).toBe('')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('leaves a stored choice alone', async () => {
|
|
139
|
+
localStorage.setItem('m3-palette', 'iron')
|
|
140
|
+
const { createM3UI } = await fresh()
|
|
141
|
+
createApp({}).use(createM3UI({ seed: '#0b57d0' }))
|
|
142
|
+
await settle()
|
|
143
|
+
expect(localStorage.getItem('m3-palette')).toBe('iron')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('a first-visit palette survives the first useColorPalette() call', async () => {
|
|
147
|
+
const { createM3UI, useColorPalette } = await fresh()
|
|
148
|
+
createApp({}).use(createM3UI({ palette: 'teal' }))
|
|
149
|
+
const p = setup(useColorPalette)
|
|
150
|
+
await nextTick()
|
|
151
|
+
expect(p.palette.value).toBe('teal')
|
|
152
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('teal')
|
|
153
|
+
expect(localStorage.getItem('m3-palette')).toBe('teal')
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
describe('createM3UI themeColor', () => {
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
localStorage.clear()
|
|
160
|
+
document.head.innerHTML = ''
|
|
161
|
+
document.documentElement.className = ''
|
|
162
|
+
document.documentElement.style.setProperty('--color-surface', '#fef7ff')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('creates the meta and follows the palette', async () => {
|
|
166
|
+
const { createM3UI } = await fresh()
|
|
167
|
+
createApp({}).use(createM3UI({ themeColor: 'surface' }))
|
|
168
|
+
const meta = () => document.querySelector<HTMLMetaElement>('meta[name="theme-color"]')!
|
|
169
|
+
expect(meta().content).toBe('#fef7ff')
|
|
170
|
+
// Dark mode (or a palette switch) changes the variable and touches <html>
|
|
171
|
+
document.documentElement.style.setProperty('--color-surface', '#141218')
|
|
172
|
+
document.documentElement.classList.add('dark')
|
|
173
|
+
await settle()
|
|
174
|
+
expect(meta().content).toBe('#141218')
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('takes over an existing light/dark pair', async () => {
|
|
178
|
+
document.head.innerHTML = '<meta name="theme-color" media="(prefers-color-scheme: light)" content="#ffffff"><meta name="theme-color" media="(prefers-color-scheme: dark)" content="#000000">'
|
|
179
|
+
const { createM3UI } = await fresh()
|
|
180
|
+
createApp({}).use(createM3UI({ themeColor: 'surface' }))
|
|
181
|
+
const all = Array.from(document.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]'))
|
|
182
|
+
expect(all.map((m) => [m.content, m.hasAttribute('media')])).toEqual([['#fef7ff', false], ['#fef7ff', false]])
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('leaves the meta alone by default', async () => {
|
|
186
|
+
document.head.innerHTML = '<meta name="theme-color" content="#6750a4">'
|
|
187
|
+
const { createM3UI } = await fresh()
|
|
188
|
+
createApp({}).use(createM3UI({}))
|
|
189
|
+
expect(document.querySelector<HTMLMetaElement>('meta[name="theme-color"]')!.content).toBe('#6750a4')
|
|
190
|
+
})
|
|
191
|
+
})
|
package/src/components/MBox.vue
CHANGED
|
@@ -15,8 +15,8 @@ const props = withDefaults(
|
|
|
15
15
|
padding?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
16
16
|
/** Border radius */
|
|
17
17
|
rounded?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full'
|
|
18
|
-
/** Shadow elevation level */
|
|
19
|
-
elevation?: 0 | 1 | 2 | 3
|
|
18
|
+
/** Shadow elevation level (M3 levels 0–5) */
|
|
19
|
+
elevation?: 0 | 1 | 2 | 3 | 4 | 5
|
|
20
20
|
/** Show border */
|
|
21
21
|
border?: boolean
|
|
22
22
|
/** HTML tag to render */
|
|
@@ -60,6 +60,8 @@ const elevationClasses: Record<number, string> = {
|
|
|
60
60
|
1: 'shadow-elevation-1',
|
|
61
61
|
2: 'shadow-elevation-2',
|
|
62
62
|
3: 'shadow-elevation-3',
|
|
63
|
+
4: 'shadow-elevation-4',
|
|
64
|
+
5: 'shadow-elevation-5',
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
const classes = computed(() => [
|