@m3ui-vue/m3ui-vue 0.5.10 → 0.6.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 (87) hide show
  1. package/README.md +36 -2
  2. package/dist/{MMenuItem-DyY4zhRA.js → MMenuItem-DbbrJhFE.js} +2 -2
  3. package/dist/{MMenuItem-DyY4zhRA.js.map → MMenuItem-DbbrJhFE.js.map} +1 -1
  4. package/dist/barcode.d.ts +1 -0
  5. package/dist/barcode.js +51 -0
  6. package/dist/barcode.js.map +1 -0
  7. package/dist/code-editor.js +1 -1
  8. package/dist/components/MAutocomplete.vue.d.ts +1 -1
  9. package/dist/components/MBarcode.vue.d.ts +35 -0
  10. package/dist/components/MButton.vue.d.ts +1 -1
  11. package/dist/components/MButtonGroup.vue.d.ts +1 -1
  12. package/dist/components/MChatBubble.vue.d.ts +1 -1
  13. package/dist/components/MCircleProgressBar.vue.d.ts +1 -1
  14. package/dist/components/MCopyButton.vue.d.ts +31 -0
  15. package/dist/components/MExportButton.vue.d.ts +43 -0
  16. package/dist/components/MFab.vue.d.ts +1 -1
  17. package/dist/components/MKbd.vue.d.ts +12 -0
  18. package/dist/components/MLightbox.vue.d.ts +53 -0
  19. package/dist/components/MMultiAutocomplete.vue.d.ts +1 -1
  20. package/dist/components/MMultiSelect.vue.d.ts +1 -1
  21. package/dist/components/MPasswordMeter.vue.d.ts +17 -0
  22. package/dist/components/MPinInput.vue.d.ts +35 -0
  23. package/dist/components/MQRCode.vue.d.ts +35 -0
  24. package/dist/components/MRating.vue.d.ts +1 -1
  25. package/dist/components/MRelativeTime.vue.d.ts +8 -0
  26. package/dist/components/MSelect.vue.d.ts +1 -1
  27. package/dist/components/MShader.vue.d.ts +2 -2
  28. package/dist/components/MSignaturePad.vue.d.ts +37 -0
  29. package/dist/components/MSlider.vue.d.ts +1 -1
  30. package/dist/components/MSplitButton.vue.d.ts +1 -1
  31. package/dist/components/MSubtitle.vue.d.ts +1 -1
  32. package/dist/components/MTerminal.vue.d.ts +2 -2
  33. package/dist/components/MTitle.vue.d.ts +1 -1
  34. package/dist/components/MWindow.vue.d.ts +1 -1
  35. package/dist/composables/useColorPalette.d.ts +9 -0
  36. package/dist/composables/useLocale.d.ts +2 -0
  37. package/dist/index.d.ts +9 -0
  38. package/dist/locales/index.js +7 -0
  39. package/dist/locales/index.js.map +1 -1
  40. package/dist/m3ui-vue.css +1 -1
  41. package/dist/m3ui.js +1737 -1021
  42. package/dist/m3ui.js.map +1 -1
  43. package/dist/plugin.d.ts +9 -0
  44. package/dist/qrcode.d.ts +1 -0
  45. package/dist/qrcode.js +117 -0
  46. package/dist/qrcode.js.map +1 -0
  47. package/dist/rich-text-editor.js +2 -2
  48. package/dist/styles.css +1 -1
  49. package/dist/{useLocale-QCIVDYWx.js → useLocale-BKsIWNix.js} +2 -1
  50. package/dist/useLocale-BKsIWNix.js.map +1 -0
  51. package/package.json +21 -1
  52. package/src/__tests__/MBarcode.test.ts +40 -0
  53. package/src/__tests__/MCopyButton.test.ts +49 -0
  54. package/src/__tests__/MExportButton.test.ts +64 -0
  55. package/src/__tests__/MKbd.test.ts +33 -0
  56. package/src/__tests__/MLightbox.test.ts +195 -0
  57. package/src/__tests__/MPasswordMeter.test.ts +43 -0
  58. package/src/__tests__/MPinInput.test.ts +138 -0
  59. package/src/__tests__/MQRCode.test.ts +58 -0
  60. package/src/__tests__/MRelativeTime.test.ts +43 -0
  61. package/src/__tests__/MSignaturePad.test.ts +62 -0
  62. package/src/__tests__/plugin.test.ts +20 -1
  63. package/src/__tests__/useColorPalette.test.ts +22 -0
  64. package/src/barcode.ts +1 -0
  65. package/src/components/MBarcode.vue +61 -0
  66. package/src/components/MCopyButton.vue +62 -0
  67. package/src/components/MExportButton.vue +73 -0
  68. package/src/components/MKbd.vue +36 -0
  69. package/src/components/MLightbox.vue +405 -0
  70. package/src/components/MPasswordMeter.vue +56 -0
  71. package/src/components/MPinInput.vue +202 -0
  72. package/src/components/MQRCode.vue +131 -0
  73. package/src/components/MRelativeTime.vue +68 -0
  74. package/src/components/MSignaturePad.vue +138 -0
  75. package/src/composables/useColorPalette.ts +29 -2
  76. package/src/composables/useLocale.ts +5 -0
  77. package/src/index.ts +9 -0
  78. package/src/locales/de.ts +2 -0
  79. package/src/locales/es.ts +2 -0
  80. package/src/locales/fr.ts +2 -0
  81. package/src/locales/ja.ts +2 -0
  82. package/src/locales/ko.ts +2 -0
  83. package/src/locales/pt.ts +2 -0
  84. package/src/locales/zh.ts +2 -0
  85. package/src/plugin.ts +16 -4
  86. package/src/qrcode.ts +1 -0
  87. package/dist/useLocale-QCIVDYWx.js.map +0 -1
@@ -0,0 +1,195 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MLightbox from '../components/MLightbox.vue'
5
+
6
+ const items = [
7
+ { src: '/a.jpg', alt: 'A' },
8
+ { src: '/b.jpg', alt: 'B' },
9
+ { src: '/c.jpg', alt: 'C' },
10
+ ]
11
+
12
+ describe('MLightbox', () => {
13
+ beforeEach(() => {
14
+ document.body.innerHTML = ''
15
+ })
16
+
17
+ it('renders nothing when closed', () => {
18
+ mount(MLightbox, {
19
+ props: { modelValue: false, items },
20
+ attachTo: document.body,
21
+ })
22
+ expect(document.body.querySelector('.fixed')).toBeNull()
23
+ })
24
+
25
+ it('shows the image at the given index when open', () => {
26
+ mount(MLightbox, {
27
+ props: { modelValue: true, items, index: 1 },
28
+ attachTo: document.body,
29
+ })
30
+ const img = document.body.querySelector('img')
31
+ expect(img?.getAttribute('src')).toBe('/b.jpg')
32
+ })
33
+
34
+ it('next()/prev() navigate and emit update:index', async () => {
35
+ const wrapper = mount(MLightbox, {
36
+ props: { modelValue: true, items, index: 0 },
37
+ attachTo: document.body,
38
+ })
39
+ await (wrapper.vm as any).next()
40
+ await nextTick()
41
+ expect(wrapper.emitted('update:index')?.[0]).toEqual([1])
42
+ expect(document.body.querySelector('img')?.getAttribute('src')).toBe('/b.jpg')
43
+ })
44
+
45
+ it('loops from the last image back to the first by default', async () => {
46
+ const wrapper = mount(MLightbox, {
47
+ props: { modelValue: true, items, index: 2 },
48
+ attachTo: document.body,
49
+ })
50
+ await (wrapper.vm as any).next()
51
+ await nextTick()
52
+ expect(document.body.querySelector('img')?.getAttribute('src')).toBe('/a.jpg')
53
+ })
54
+
55
+ it('does not loop past the last image when loop is false', async () => {
56
+ const wrapper = mount(MLightbox, {
57
+ props: { modelValue: true, items, index: 2, loop: false },
58
+ attachTo: document.body,
59
+ })
60
+ await (wrapper.vm as any).next()
61
+ await nextTick()
62
+ expect(document.body.querySelector('img')?.getAttribute('src')).toBe('/c.jpg')
63
+ })
64
+
65
+ it('emits update:modelValue false when the close button is clicked', async () => {
66
+ const wrapper = mount(MLightbox, {
67
+ props: { modelValue: true, items },
68
+ attachTo: document.body,
69
+ })
70
+ const closeBtn = document.body.querySelector('button[aria-label="Close"]') as HTMLButtonElement
71
+ closeBtn.click()
72
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
73
+ })
74
+
75
+ it('hides prev/next arrows for a single image', () => {
76
+ mount(MLightbox, {
77
+ props: { modelValue: true, items: [items[0]] },
78
+ attachTo: document.body,
79
+ })
80
+ expect(document.body.querySelector('[aria-label="Previous"]')).toBeNull()
81
+ expect(document.body.querySelector('[aria-label="Next"]')).toBeNull()
82
+ })
83
+
84
+ it('auto-detects <img> elements in the default slot when no items are given', async () => {
85
+ const wrapper = mount(MLightbox, {
86
+ props: { modelValue: false },
87
+ slots: { default: '<img src="/x.jpg" alt="X" /><img src="/y.jpg" alt="Y" />' },
88
+ attachTo: document.body,
89
+ })
90
+ await nextTick()
91
+ const imgs = document.body.querySelectorAll('.contents img')
92
+ expect(imgs).toHaveLength(2)
93
+ ;(imgs[1] as HTMLImageElement).dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
94
+ await nextTick()
95
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([true])
96
+ expect(document.body.querySelectorAll('.fixed img')[0]?.getAttribute('src')).toContain('/y.jpg')
97
+ })
98
+
99
+ it('skips images marked data-lightbox="false"', async () => {
100
+ mount(MLightbox, {
101
+ props: { modelValue: false },
102
+ slots: { default: '<img src="/x.jpg" data-lightbox="false" /><img src="/y.jpg" />' },
103
+ attachTo: document.body,
104
+ })
105
+ await nextTick()
106
+ const wrapperVm = document.body.querySelector('.contents img[src="/x.jpg"]') as HTMLImageElement
107
+ expect(wrapperVm.onclick).toBeNull()
108
+ })
109
+
110
+ it('does not render thumbnails by default', () => {
111
+ mount(MLightbox, {
112
+ props: { modelValue: true, items },
113
+ attachTo: document.body,
114
+ })
115
+ expect(document.body.querySelectorAll('.ring-2')).toHaveLength(0)
116
+ })
117
+
118
+ it('renders a thumbnail per image when showThumbnails is set, and clicking one jumps to it', async () => {
119
+ const wrapper = mount(MLightbox, {
120
+ props: { modelValue: true, items, index: 0, showThumbnails: true },
121
+ attachTo: document.body,
122
+ })
123
+ const thumbs = document.body.querySelectorAll('.ring-2')
124
+ expect(thumbs).toHaveLength(3)
125
+ ;(thumbs[2] as HTMLButtonElement).click()
126
+ await nextTick()
127
+ expect(wrapper.emitted('update:index')?.[0]).toEqual([2])
128
+ })
129
+
130
+ it('rounds the image by default', () => {
131
+ mount(MLightbox, {
132
+ props: { modelValue: true, items },
133
+ attachTo: document.body,
134
+ })
135
+ expect(document.body.querySelector('img')?.className).toContain('rounded-2xl')
136
+ })
137
+
138
+ it('does not round the image when rounded is false', () => {
139
+ mount(MLightbox, {
140
+ props: { modelValue: true, items, rounded: false },
141
+ attachTo: document.body,
142
+ })
143
+ expect(document.body.querySelector('img')?.className).not.toContain('rounded-2xl')
144
+ })
145
+
146
+ it('dragging left past the threshold navigates to the next image', async () => {
147
+ const wrapper = mount(MLightbox, {
148
+ props: { modelValue: true, items, index: 0 },
149
+ attachTo: document.body,
150
+ })
151
+ const stage = document.body.querySelector('.touch-pan-y') as HTMLElement
152
+ stage.dispatchEvent(new PointerEvent('pointerdown', { clientX: 200, pointerId: 1, button: 0, bubbles: true }))
153
+ stage.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, pointerId: 1, bubbles: true }))
154
+ stage.dispatchEvent(new PointerEvent('pointerup', { clientX: 50, pointerId: 1, bubbles: true }))
155
+ await nextTick()
156
+ expect(wrapper.emitted('update:index')?.[0]).toEqual([1])
157
+ })
158
+
159
+ it('dragging right past the threshold navigates to the previous image', async () => {
160
+ const wrapper = mount(MLightbox, {
161
+ props: { modelValue: true, items, index: 1 },
162
+ attachTo: document.body,
163
+ })
164
+ const stage = document.body.querySelector('.touch-pan-y') as HTMLElement
165
+ stage.dispatchEvent(new PointerEvent('pointerdown', { clientX: 50, pointerId: 1, button: 0, bubbles: true }))
166
+ stage.dispatchEvent(new PointerEvent('pointermove', { clientX: 200, pointerId: 1, bubbles: true }))
167
+ stage.dispatchEvent(new PointerEvent('pointerup', { clientX: 200, pointerId: 1, bubbles: true }))
168
+ await nextTick()
169
+ expect(wrapper.emitted('update:index')?.[0]).toEqual([0])
170
+ })
171
+
172
+ it('ignores drag gestures when there is only one image', async () => {
173
+ const wrapper = mount(MLightbox, {
174
+ props: { modelValue: true, items: [items[0]] },
175
+ attachTo: document.body,
176
+ })
177
+ const stage = document.body.querySelector('.touch-pan-y') as HTMLElement
178
+ stage.dispatchEvent(new PointerEvent('pointerdown', { clientX: 200, pointerId: 1, button: 0, bubbles: true }))
179
+ stage.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, pointerId: 1, bubbles: true }))
180
+ stage.dispatchEvent(new PointerEvent('pointerup', { clientX: 50, pointerId: 1, bubbles: true }))
181
+ await nextTick()
182
+ expect(wrapper.emitted('update:index')).toBeUndefined()
183
+ })
184
+
185
+ it('exposes open()/close() for programmatic control', async () => {
186
+ const wrapper = mount(MLightbox, {
187
+ props: { items },
188
+ attachTo: document.body,
189
+ })
190
+ ;(wrapper.vm as any).open(2)
191
+ await nextTick()
192
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([true])
193
+ expect(document.body.querySelector('img')?.getAttribute('src')).toBe('/c.jpg')
194
+ })
195
+ })
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MPasswordMeter from '../components/MPasswordMeter.vue'
4
+
5
+ describe('MPasswordMeter', () => {
6
+ it('shows no label and no filled segments for an empty value', () => {
7
+ const wrapper = mount(MPasswordMeter, { props: { value: '' } })
8
+ expect(wrapper.find('p').exists()).toBe(false)
9
+ })
10
+
11
+ it('rates a short lowercase-only password as very weak', () => {
12
+ const wrapper = mount(MPasswordMeter, { props: { value: 'abc' } })
13
+ expect(wrapper.text()).toBe('Very weak')
14
+ })
15
+
16
+ it('rates a long, varied password as strong', () => {
17
+ const wrapper = mount(MPasswordMeter, { props: { value: 'Sup3r$ecureLongPass!' } })
18
+ expect(wrapper.text()).toBe('Strong')
19
+ })
20
+
21
+ it('emits score whenever the value changes', async () => {
22
+ const wrapper = mount(MPasswordMeter, { props: { value: '' } })
23
+ expect(wrapper.emitted('score')![0]).toEqual([-1])
24
+
25
+ await wrapper.setProps({ value: 'Sup3r$ecureLongPass!' })
26
+ expect(wrapper.emitted('score')!.at(-1)).toEqual([4])
27
+ })
28
+
29
+ it('supports custom labels', () => {
30
+ const wrapper = mount(MPasswordMeter, {
31
+ props: { value: 'abc', labels: ['Muy débil', 'Débil', 'Regular', 'Buena', 'Fuerte'] },
32
+ })
33
+ expect(wrapper.text()).toBe('Muy débil')
34
+ })
35
+
36
+ it('respects a custom minLength when scoring', () => {
37
+ const short = mount(MPasswordMeter, { props: { value: '1234', minLength: 4 } })
38
+ const shortScore = short.emitted('score')![0]![0]
39
+ const long = mount(MPasswordMeter, { props: { value: '123', minLength: 4 } })
40
+ const longScore = long.emitted('score')![0]![0]
41
+ expect(shortScore).toBeGreaterThan(longScore as number)
42
+ })
43
+ })
@@ -0,0 +1,138 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MPinInput from '../components/MPinInput.vue'
4
+
5
+ describe('MPinInput', () => {
6
+ it('renders `length` boxes', () => {
7
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4 } })
8
+ expect(wrapper.findAll('input')).toHaveLength(4)
9
+ })
10
+
11
+ it('defaults to 6 boxes', () => {
12
+ const wrapper = mount(MPinInput, { props: { modelValue: '' } })
13
+ expect(wrapper.findAll('input')).toHaveLength(6)
14
+ })
15
+
16
+ it('renders each digit in its own box', () => {
17
+ const wrapper = mount(MPinInput, { props: { modelValue: '12', length: 4 } })
18
+ const inputs = wrapper.findAll('input')
19
+ expect(inputs[0].element.value).toBe('1')
20
+ expect(inputs[1].element.value).toBe('2')
21
+ expect(inputs[2].element.value).toBe('')
22
+ })
23
+
24
+ it('emits update:modelValue and advances focus on digit entry', async () => {
25
+ const wrapper = mount(MPinInput, {
26
+ props: { modelValue: '', length: 4 },
27
+ attachTo: document.body,
28
+ })
29
+ const inputs = wrapper.findAll('input')
30
+ await inputs[0].setValue('5')
31
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['5'])
32
+ wrapper.unmount()
33
+ })
34
+
35
+ it('rejects non-numeric input by default', async () => {
36
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4 } })
37
+ const input = wrapper.findAll('input')[0]
38
+ await input.setValue('a')
39
+ expect(wrapper.emitted('update:modelValue')).toBeUndefined()
40
+ })
41
+
42
+ it('allows letters when type is alphanumeric', async () => {
43
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4, type: 'alphanumeric' } })
44
+ const input = wrapper.findAll('input')[0]
45
+ await input.setValue('a')
46
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['a'])
47
+ })
48
+
49
+ it('emits complete when all boxes are filled', async () => {
50
+ const wrapper = mount(MPinInput, { props: { modelValue: '123', length: 4 } })
51
+ const input = wrapper.findAll('input')[3]
52
+ await input.setValue('4')
53
+ expect(wrapper.emitted('complete')![0]).toEqual(['1234'])
54
+ })
55
+
56
+ it('moves focus back and clears the previous box on backspace from an empty box', async () => {
57
+ const wrapper = mount(MPinInput, {
58
+ props: { modelValue: '12', length: 4 },
59
+ attachTo: document.body,
60
+ })
61
+ const inputs = wrapper.findAll('input')
62
+ await inputs[2].trigger('keydown', { key: 'Backspace' })
63
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['1'])
64
+ wrapper.unmount()
65
+ })
66
+
67
+ it('distributes a pasted code across the remaining boxes', async () => {
68
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4 } })
69
+ const input = wrapper.findAll('input')[0]
70
+ await input.trigger('paste', {
71
+ clipboardData: { getData: () => '1234' },
72
+ })
73
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual(['1234'])
74
+ expect(wrapper.emitted('complete')![0]).toEqual(['1234'])
75
+ })
76
+
77
+ it("keeps a skipped box's position when it's filled in afterwards", async () => {
78
+ // Simulates clicking box 3 directly while boxes 1-2 are still empty,
79
+ // then coming back to fill the gap — the middle boxes must not shift.
80
+ const wrapper = mount(MPinInput, { props: { modelValue: '1', length: 4 } })
81
+
82
+ await wrapper.findAll('input')[3].setValue('4')
83
+ let value = wrapper.emitted('update:modelValue')!.at(-1)![0] as string
84
+ await wrapper.setProps({ modelValue: value })
85
+ let inputs = wrapper.findAll('input')
86
+ expect(inputs[0].element.value).toBe('1')
87
+ expect(inputs[1].element.value).toBe('')
88
+ expect(inputs[2].element.value).toBe('')
89
+ expect(inputs[3].element.value).toBe('4')
90
+
91
+ await inputs[2].setValue('3')
92
+ value = wrapper.emitted('update:modelValue')!.at(-1)![0] as string
93
+ await wrapper.setProps({ modelValue: value })
94
+ inputs = wrapper.findAll('input')
95
+ expect(inputs[2].element.value).toBe('3')
96
+ expect(inputs[3].element.value).toBe('4')
97
+
98
+ await inputs[1].setValue('2')
99
+ expect(wrapper.emitted('complete')!.at(-1)).toEqual(['1234'])
100
+ })
101
+
102
+ it('renders as masked input when masked is true', () => {
103
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4, masked: true } })
104
+ expect(wrapper.findAll('input')[0].attributes('type')).toBe('password')
105
+ })
106
+
107
+ it('derives length from groups and renders a separator at each boundary', () => {
108
+ const wrapper = mount(MPinInput, { props: { modelValue: '', groups: [2, 3, 2] } })
109
+ expect(wrapper.findAll('input')).toHaveLength(7)
110
+ const spans = wrapper.findAll('span')
111
+ expect(spans).toHaveLength(2)
112
+ expect(spans[0].text()).toBe('-')
113
+ expect(spans[1].text()).toBe('-')
114
+ })
115
+
116
+ it('uses a custom separator', () => {
117
+ const wrapper = mount(MPinInput, { props: { modelValue: '', groups: [2, 2], separator: '•' } })
118
+ expect(wrapper.find('span').text()).toBe('•')
119
+ })
120
+
121
+ it('treats grouped boxes as one continuous value for typing and complete', async () => {
122
+ const wrapper = mount(MPinInput, { props: { modelValue: '12', groups: [2, 2] } })
123
+ const inputs = wrapper.findAll('input')
124
+ expect(inputs).toHaveLength(4)
125
+ await inputs[2].setValue('3')
126
+ let value = wrapper.emitted('update:modelValue')!.at(-1)![0] as string
127
+ await wrapper.setProps({ modelValue: value })
128
+ await wrapper.findAll('input')[3].setValue('4')
129
+ expect(wrapper.emitted('complete')!.at(-1)).toEqual(['1234'])
130
+ })
131
+
132
+ it('disables all boxes when disabled', () => {
133
+ const wrapper = mount(MPinInput, { props: { modelValue: '', length: 4, disabled: true } })
134
+ for (const input of wrapper.findAll('input')) {
135
+ expect(input.attributes('disabled')).toBeDefined()
136
+ }
137
+ })
138
+ })
@@ -0,0 +1,58 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MQRCode from '../components/MQRCode.vue'
4
+
5
+ describe('MQRCode', () => {
6
+ it('renders an svg with the given size', () => {
7
+ const wrapper = mount(MQRCode, { props: { value: 'https://example.com', size: 150 } })
8
+ const svg = wrapper.find('svg')
9
+ expect(svg.exists()).toBe(true)
10
+ expect(svg.attributes('width')).toBe('150')
11
+ expect(svg.attributes('height')).toBe('150')
12
+ })
13
+
14
+ it('defaults the aria-label to the encoded value', () => {
15
+ const wrapper = mount(MQRCode, { props: { value: 'https://example.com' } })
16
+ expect(wrapper.find('svg').attributes('aria-label')).toBe('https://example.com')
17
+ })
18
+
19
+ it('uses a custom label when provided', () => {
20
+ const wrapper = mount(MQRCode, { props: { value: 'https://example.com', label: 'Table 5 menu' } })
21
+ expect(wrapper.find('svg').attributes('aria-label')).toBe('Table 5 menu')
22
+ })
23
+
24
+ it('defaults to plain square modules (rects, no arcs)', () => {
25
+ const wrapper = mount(MQRCode, { props: { value: 'hi', color: '#ff0000', background: '#eeeeee' } })
26
+ const rects = wrapper.findAll('rect')
27
+ expect(rects[0].attributes('fill')).toBe('#eeeeee')
28
+ const moduleRects = rects.slice(1)
29
+ expect(moduleRects.length).toBeGreaterThan(1)
30
+ expect(moduleRects.every((r) => r.attributes('fill') === '#ff0000')).toBe(true)
31
+ expect(wrapper.findAll('path')).toHaveLength(0)
32
+ })
33
+
34
+ it('rounds only the outer container when rounded is true', () => {
35
+ const rounded = mount(MQRCode, { props: { value: 'hi', rounded: true } })
36
+ const square = mount(MQRCode, { props: { value: 'hi', rounded: false } })
37
+ expect(Number(rounded.find('rect').attributes('rx'))).toBeGreaterThan(0)
38
+ expect(Number(square.find('rect').attributes('rx'))).toBe(0)
39
+ // modules are always plain rects with no rx, regardless of `rounded`
40
+ expect(rounded.findAll('rect').slice(1).every((r) => !r.attributes('rx'))).toBe(true)
41
+ })
42
+
43
+ it('renders dot-style modules as paths when moduleStyle is "dots"', () => {
44
+ const wrapper = mount(MQRCode, { props: { value: 'hi', moduleStyle: 'dots', color: '#ff0000' } })
45
+ const paths = wrapper.findAll('path')
46
+ expect(paths.length).toBeGreaterThan(1)
47
+ expect(paths.every((p) => p.attributes('fill') === '#ff0000')).toBe(true)
48
+ // isolated modules should have rounded/circular corners (arc commands)
49
+ expect(paths.some((p) => p.attributes('d')!.includes('A'))).toBe(true)
50
+ })
51
+
52
+ it('falls back to an error message when the data is too large to encode', () => {
53
+ const tooLong = 'x'.repeat(5000)
54
+ const wrapper = mount(MQRCode, { props: { value: tooLong } })
55
+ expect(wrapper.find('svg').exists()).toBe(false)
56
+ expect(wrapper.text().length).toBeGreaterThan(0)
57
+ })
58
+ })
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MRelativeTime from '../components/MRelativeTime.vue'
4
+
5
+ describe('MRelativeTime', () => {
6
+ it('renders a past time as "ago"', () => {
7
+ const fiveMinAgo = new Date(Date.now() - 5 * 60 * 1000)
8
+ const wrapper = mount(MRelativeTime, { props: { value: fiveMinAgo, locale: 'en' } })
9
+ expect(wrapper.text()).toContain('ago')
10
+ })
11
+
12
+ it('renders a future time as "in"', () => {
13
+ const inTwoHours = new Date(Date.now() + 2 * 60 * 60 * 1000)
14
+ const wrapper = mount(MRelativeTime, { props: { value: inTwoHours, locale: 'en' } })
15
+ expect(wrapper.text()).toContain('in')
16
+ })
17
+
18
+ it('renders "now" for the current instant', () => {
19
+ const wrapper = mount(MRelativeTime, { props: { value: new Date(), locale: 'en' } })
20
+ expect(wrapper.text().toLowerCase()).toContain('now')
21
+ })
22
+
23
+ it('sets datetime and title attributes', () => {
24
+ const date = new Date('2026-01-01T00:00:00.000Z')
25
+ const wrapper = mount(MRelativeTime, { props: { value: date, locale: 'en' } })
26
+ const time = wrapper.find('time')
27
+ expect(time.attributes('datetime')).toBe(date.toISOString())
28
+ expect(time.attributes('title')).toBeTruthy()
29
+ })
30
+
31
+ it('accepts a timestamp number and an ISO string', () => {
32
+ const wrapper1 = mount(MRelativeTime, { props: { value: Date.now(), locale: 'en' } })
33
+ const wrapper2 = mount(MRelativeTime, { props: { value: new Date().toISOString(), locale: 'en' } })
34
+ expect(wrapper1.find('time').exists()).toBe(true)
35
+ expect(wrapper2.find('time').exists()).toBe(true)
36
+ })
37
+
38
+ it('respects the locale prop', () => {
39
+ const fiveMinAgo = new Date(Date.now() - 5 * 60 * 1000)
40
+ const wrapper = mount(MRelativeTime, { props: { value: fiveMinAgo, locale: 'es' } })
41
+ expect(wrapper.text()).toMatch(/hace/i)
42
+ })
43
+ })
@@ -0,0 +1,62 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MSignaturePad from '../components/MSignaturePad.vue'
4
+
5
+ function draw(wrapper: ReturnType<typeof mount>) {
6
+ const canvas = wrapper.find('canvas')
7
+ return canvas
8
+ .trigger('pointerdown', { clientX: 10, clientY: 10, pointerId: 1 })
9
+ .then(() => canvas.trigger('pointermove', { clientX: 20, clientY: 20, pointerId: 1 }))
10
+ .then(() => canvas.trigger('pointerup', { pointerId: 1 }))
11
+ }
12
+
13
+ describe('MSignaturePad', () => {
14
+ it('starts empty', () => {
15
+ const wrapper = mount(MSignaturePad)
16
+ expect((wrapper.vm as any).isEmpty()).toBe(true)
17
+ })
18
+
19
+ it('is no longer empty after drawing a stroke', async () => {
20
+ const wrapper = mount(MSignaturePad)
21
+ await draw(wrapper)
22
+ expect((wrapper.vm as any).isEmpty()).toBe(false)
23
+ })
24
+
25
+ it('emits begin, end and change with a data URL', async () => {
26
+ const wrapper = mount(MSignaturePad)
27
+ await draw(wrapper)
28
+ expect(wrapper.emitted('begin')).toHaveLength(1)
29
+ expect(wrapper.emitted('end')).toHaveLength(1)
30
+ expect(wrapper.emitted('end')![0]![0]).toMatch(/^data:/)
31
+ expect(wrapper.emitted('change')).toHaveLength(1)
32
+ })
33
+
34
+ it('clear() empties the pad', async () => {
35
+ const wrapper = mount(MSignaturePad)
36
+ await draw(wrapper)
37
+ ;(wrapper.vm as any).clear()
38
+ expect((wrapper.vm as any).isEmpty()).toBe(true)
39
+ })
40
+
41
+ it('undo() removes only the last stroke', async () => {
42
+ const wrapper = mount(MSignaturePad)
43
+ await draw(wrapper)
44
+ await draw(wrapper)
45
+ ;(wrapper.vm as any).undo()
46
+ expect((wrapper.vm as any).isEmpty()).toBe(false)
47
+ ;(wrapper.vm as any).undo()
48
+ expect((wrapper.vm as any).isEmpty()).toBe(true)
49
+ })
50
+
51
+ it('does not draw when disabled', async () => {
52
+ const wrapper = mount(MSignaturePad, { props: { disabled: true } })
53
+ await draw(wrapper)
54
+ expect((wrapper.vm as any).isEmpty()).toBe(true)
55
+ expect(wrapper.emitted('begin')).toBeUndefined()
56
+ })
57
+
58
+ it('exposes toDataURL()', () => {
59
+ const wrapper = mount(MSignaturePad)
60
+ expect((wrapper.vm as any).toDataURL()).toMatch(/^data:/)
61
+ })
62
+ })
@@ -1,6 +1,7 @@
1
- import { describe, it, expect, beforeEach } from 'vitest'
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2
2
  import { createApp, defineComponent, h } from 'vue'
3
3
  import { createM3UI } from '../plugin'
4
+ import { useColorPalette } from '../composables/useColorPalette'
4
5
 
5
6
  describe('createM3UI', () => {
6
7
  beforeEach(() => {
@@ -8,6 +9,10 @@ describe('createM3UI', () => {
8
9
  localStorage.removeItem('m3-palette')
9
10
  })
10
11
 
12
+ afterEach(() => {
13
+ useColorPalette().setPersistPalette(true)
14
+ })
15
+
11
16
  it('installs without options', () => {
12
17
  const app = createApp(defineComponent({ render: () => h('div') }))
13
18
  expect(() => app.use(createM3UI())).not.toThrow()
@@ -33,4 +38,18 @@ describe('createM3UI', () => {
33
38
  expect(document.documentElement.getAttribute('data-palette')).toBe('teal')
34
39
  expect(localStorage.getItem('m3-palette')).toBe('teal')
35
40
  })
41
+
42
+ it('persistPalette: false forces the palette even over a stored value', () => {
43
+ localStorage.setItem('m3-palette', 'teal')
44
+ document.documentElement.setAttribute('data-palette', 'teal')
45
+ const app = createApp(defineComponent({ render: () => h('div') }))
46
+ app.use(createM3UI({ palette: 'iron', persistPalette: false }))
47
+ expect(document.documentElement.getAttribute('data-palette')).toBe('iron')
48
+ })
49
+
50
+ it('persistPalette: false does not write the forced palette to localStorage', () => {
51
+ const app = createApp(defineComponent({ render: () => h('div') }))
52
+ app.use(createM3UI({ palette: 'iron', persistPalette: false }))
53
+ expect(localStorage.getItem('m3-palette')).toBeNull()
54
+ })
36
55
  })
@@ -68,4 +68,26 @@ describe('useColorPalette', () => {
68
68
  await nextTick()
69
69
  expect(localStorage.getItem('m3-palette')).toBe('blue')
70
70
  })
71
+
72
+ it('setPersistPalette(false) stops set() from persisting, but still applies live', async () => {
73
+ const { set, setPersistPalette } = withSetup()
74
+ await nextTick()
75
+ setPersistPalette(false)
76
+ const before = localStorage.getItem('m3-palette')
77
+ set('crimson')
78
+ await nextTick()
79
+ expect(document.documentElement.getAttribute('data-palette')).toBe('crimson')
80
+ expect(localStorage.getItem('m3-palette')).toBe(before)
81
+ setPersistPalette(true)
82
+ })
83
+
84
+ it('setPersistPalette(true) resumes persisting immediately', async () => {
85
+ const { set, setPersistPalette } = withSetup()
86
+ setPersistPalette(false)
87
+ set('sand')
88
+ await nextTick()
89
+ setPersistPalette(true)
90
+ await nextTick()
91
+ expect(localStorage.getItem('m3-palette')).toBe('sand')
92
+ })
71
93
  })
package/src/barcode.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as MBarcode } from './components/MBarcode.vue'
@@ -0,0 +1,61 @@
1
+ <script setup lang="ts">
2
+ import { ref, watchEffect } from 'vue'
3
+ import JsBarcode from 'jsbarcode'
4
+
5
+ const props = withDefaults(
6
+ defineProps<{
7
+ value: string
8
+ /** Barcode symbology. Common values: 'CODE128', 'EAN13', 'EAN8', 'UPC', 'CODE39', 'ITF14', 'MSI', 'pharmacode', 'codabar'. */
9
+ format?: string
10
+ width?: number
11
+ height?: number
12
+ displayValue?: boolean
13
+ color?: string
14
+ background?: string
15
+ margin?: number
16
+ fontSize?: number
17
+ label?: string
18
+ }>(),
19
+ {
20
+ format: 'CODE128',
21
+ width: 2,
22
+ height: 80,
23
+ displayValue: true,
24
+ color: '#000000',
25
+ background: '#ffffff',
26
+ margin: 10,
27
+ fontSize: 20,
28
+ },
29
+ )
30
+
31
+ const svgEl = ref<SVGSVGElement | null>(null)
32
+ const error = ref<string | null>(null)
33
+
34
+ // flush: 'post' runs synchronously right after (re-)render, once the ref is
35
+ // attached — the default 'pre' flush defers the first run to a microtask
36
+ // after the ref is set, which is later than callers expect a mount to settle.
37
+ watchEffect(() => {
38
+ if (!svgEl.value) return
39
+ error.value = null
40
+ JsBarcode(svgEl.value, props.value, {
41
+ format: props.format,
42
+ width: props.width,
43
+ height: props.height,
44
+ displayValue: props.displayValue,
45
+ lineColor: props.color,
46
+ background: props.background,
47
+ margin: props.margin,
48
+ fontSize: props.fontSize,
49
+ valid: (ok) => {
50
+ if (!ok) error.value = `Invalid value "${props.value}" for format "${props.format}"`
51
+ },
52
+ })
53
+ }, { flush: 'post' })
54
+ </script>
55
+
56
+ <template>
57
+ <div v-if="error" class="flex items-center justify-center text-body-small text-error">
58
+ <slot name="error">{{ error }}</slot>
59
+ </div>
60
+ <svg v-show="!error" ref="svgEl" role="img" :aria-label="label ?? value"></svg>
61
+ </template>