@m3ui-vue/m3ui-vue 0.6.0 → 0.6.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 +13 -1
- package/dist/MIcon-CaEooCmZ.js.map +1 -1
- package/dist/{MMenuItem-DbbrJhFE.js → MMenuItem-C7jKU-Qh.js} +13 -13
- package/dist/{MMenuItem-DbbrJhFE.js.map → MMenuItem-C7jKU-Qh.js.map} +1 -1
- package/dist/barcode.js.map +1 -1
- package/dist/chart.js +1 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/code-editor.js.map +1 -1
- package/dist/{common-VrOaLkjh.js → common-0dgrgaPL.js} +287 -213
- package/dist/common-0dgrgaPL.js.map +1 -0
- package/dist/components/MBar.vue.d.ts +58 -0
- package/dist/components/MLightbox.vue.d.ts +53 -0
- package/dist/components/MPageProgress.vue.d.ts +15 -0
- package/dist/components/MSlider.vue.d.ts +6 -0
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/composables/useColorPalette.d.ts +9 -0
- package/dist/composables/usePageProgress.d.ts +19 -0
- package/dist/{dist-Dsrzt6J5.js → dist-CrjSW5DN.js} +248 -241
- package/dist/{dist-Dsrzt6J5.js.map → dist-CrjSW5DN.js.map} +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3117 -2593
- package/dist/m3ui.js.map +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/plugin.d.ts +9 -0
- package/dist/qrcode.js.map +1 -1
- package/dist/rich-text-editor.js +1 -1
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/terminal.js.map +1 -1
- package/package.json +26 -26
- package/src/__tests__/MLightbox.test.ts +195 -0
- package/src/__tests__/plugin.test.ts +20 -1
- package/src/__tests__/useColorPalette.test.ts +22 -0
- package/src/__tests__/usePageProgress.test.ts +52 -0
- package/src/components/MBar.vue +158 -0
- package/src/components/MLightbox.vue +405 -0
- package/src/components/MPageProgress.vue +62 -0
- package/src/components/MSlider.vue +174 -52
- package/src/composables/useColorPalette.ts +29 -2
- package/src/composables/usePageProgress.ts +49 -0
- package/src/index.ts +5 -0
- package/src/plugin.ts +16 -4
- package/dist/common-VrOaLkjh.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m3ui-vue/m3ui-vue",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Material 3 component library for Vue 3 + Tailwind CSS v4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -176,48 +176,48 @@
|
|
|
176
176
|
}
|
|
177
177
|
},
|
|
178
178
|
"devDependencies": {
|
|
179
|
-
"@codemirror/commands": "^6.
|
|
179
|
+
"@codemirror/commands": "^6.11.0",
|
|
180
180
|
"@codemirror/lang-css": "^6.3.1",
|
|
181
|
-
"@codemirror/lang-html": "^6.4.
|
|
181
|
+
"@codemirror/lang-html": "^6.4.12",
|
|
182
182
|
"@codemirror/lang-javascript": "^6.2.5",
|
|
183
183
|
"@codemirror/lang-json": "^6.0.2",
|
|
184
184
|
"@codemirror/lang-python": "^6.2.1",
|
|
185
185
|
"@codemirror/lang-vue": "^0.1.3",
|
|
186
|
-
"@codemirror/language": "^6.12.
|
|
187
|
-
"@codemirror/state": "^6.
|
|
186
|
+
"@codemirror/language": "^6.12.4",
|
|
187
|
+
"@codemirror/state": "^6.7.4",
|
|
188
188
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
189
|
-
"@codemirror/view": "^6.43.
|
|
189
|
+
"@codemirror/view": "^6.43.11",
|
|
190
190
|
"@lezer/highlight": "^1.2.3",
|
|
191
|
-
"@tiptap/extension-color": "^3.
|
|
192
|
-
"@tiptap/extension-highlight": "^3.
|
|
193
|
-
"@tiptap/extension-image": "^3.
|
|
194
|
-
"@tiptap/extension-link": "^3.
|
|
195
|
-
"@tiptap/extension-placeholder": "^3.
|
|
196
|
-
"@tiptap/extension-text-align": "^3.
|
|
197
|
-
"@tiptap/extension-text-style": "^3.
|
|
198
|
-
"@tiptap/extension-underline": "^3.
|
|
199
|
-
"@tiptap/starter-kit": "^3.
|
|
200
|
-
"@tiptap/vue-3": "^3.
|
|
191
|
+
"@tiptap/extension-color": "^3.31.3",
|
|
192
|
+
"@tiptap/extension-highlight": "^3.31.3",
|
|
193
|
+
"@tiptap/extension-image": "^3.31.3",
|
|
194
|
+
"@tiptap/extension-link": "^3.31.3",
|
|
195
|
+
"@tiptap/extension-placeholder": "^3.31.3",
|
|
196
|
+
"@tiptap/extension-text-align": "^3.31.3",
|
|
197
|
+
"@tiptap/extension-text-style": "^3.31.3",
|
|
198
|
+
"@tiptap/extension-underline": "^3.31.3",
|
|
199
|
+
"@tiptap/starter-kit": "^3.31.3",
|
|
200
|
+
"@tiptap/vue-3": "^3.31.3",
|
|
201
201
|
"@types/jsbarcode": "^3.11.4",
|
|
202
|
-
"@types/markdown-it": "^14.
|
|
203
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
204
|
-
"@vue/test-utils": "^2.
|
|
202
|
+
"@types/markdown-it": "^14.2.0",
|
|
203
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
204
|
+
"@vue/test-utils": "^2.5.0",
|
|
205
205
|
"@vue/tsconfig": "^0.9.1",
|
|
206
|
-
"@webgpu/types": "^0.1.
|
|
206
|
+
"@webgpu/types": "^0.1.72",
|
|
207
207
|
"@xterm/addon-fit": "^0.11.0",
|
|
208
208
|
"@xterm/xterm": "^6.0.0",
|
|
209
209
|
"chart.js": "^4.5.1",
|
|
210
210
|
"codemirror": "^6.0.2",
|
|
211
|
-
"happy-dom": "^20.
|
|
212
|
-
"highlight.js": "^11.
|
|
211
|
+
"happy-dom": "^20.14.5",
|
|
212
|
+
"highlight.js": "^11.12.0",
|
|
213
213
|
"jsbarcode": "^3.12.3",
|
|
214
|
-
"markdown-it": "^
|
|
214
|
+
"markdown-it": "^15.0.2",
|
|
215
215
|
"qrcode-generator": "^2.0.4",
|
|
216
216
|
"typescript": "~6.0.3",
|
|
217
|
-
"vite": "^8.0
|
|
218
|
-
"vitest": "^
|
|
217
|
+
"vite": "^8.3.0",
|
|
218
|
+
"vitest": "^5.0.0",
|
|
219
219
|
"vue": "^3.5.42",
|
|
220
|
-
"vue-chartjs": "^5.3.
|
|
220
|
+
"vue-chartjs": "^5.3.4",
|
|
221
221
|
"vue-tsc": "^3.3.11"
|
|
222
222
|
},
|
|
223
223
|
"publishConfig": {
|
|
@@ -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
|
+
})
|
|
@@ -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
|
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
2
|
+
import { usePageProgress } from '../composables/usePageProgress'
|
|
3
|
+
|
|
4
|
+
describe('usePageProgress', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
const { done } = usePageProgress()
|
|
7
|
+
done()
|
|
8
|
+
vi.useRealTimers()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('start() activates the bar with an initial value', () => {
|
|
12
|
+
const { progress, isActive, start } = usePageProgress()
|
|
13
|
+
start()
|
|
14
|
+
expect(isActive.value).toBe(true)
|
|
15
|
+
expect(progress.value).toBeGreaterThan(0)
|
|
16
|
+
expect(progress.value).toBeLessThan(100)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('start() trickles progress toward 90% over time without reaching it', () => {
|
|
20
|
+
vi.useFakeTimers()
|
|
21
|
+
const { progress, start } = usePageProgress()
|
|
22
|
+
start()
|
|
23
|
+
vi.advanceTimersByTime(2000)
|
|
24
|
+
expect(progress.value).toBeGreaterThan(50)
|
|
25
|
+
expect(progress.value).toBeLessThan(90)
|
|
26
|
+
vi.useRealTimers()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('set() jumps straight to the given percentage, clamped to [0, 100]', () => {
|
|
30
|
+
const { progress, isActive, set } = usePageProgress()
|
|
31
|
+
set(150)
|
|
32
|
+
expect(progress.value).toBe(100)
|
|
33
|
+
expect(isActive.value).toBe(true)
|
|
34
|
+
|
|
35
|
+
set(-10)
|
|
36
|
+
expect(progress.value).toBe(0)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('done() completes the bar then fades it out and resets', () => {
|
|
40
|
+
vi.useFakeTimers()
|
|
41
|
+
const { progress, isActive, start, done } = usePageProgress()
|
|
42
|
+
start()
|
|
43
|
+
done()
|
|
44
|
+
expect(progress.value).toBe(100)
|
|
45
|
+
expect(isActive.value).toBe(true)
|
|
46
|
+
|
|
47
|
+
vi.advanceTimersByTime(200)
|
|
48
|
+
expect(isActive.value).toBe(false)
|
|
49
|
+
expect(progress.value).toBe(0)
|
|
50
|
+
vi.useRealTimers()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import MIcon from './MIcon.vue'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
title?: string
|
|
8
|
+
/** Material Symbol name, or an image src (URL, data URI, or a path with a file extension) — detected automatically. */
|
|
9
|
+
icon?: string
|
|
10
|
+
titleAlign?: 'start' | 'center'
|
|
11
|
+
/** Show the minimize/maximize/close buttons as a group. Defaults to `true`, except on `platform="macos"` where the OS draws native traffic lights instead. */
|
|
12
|
+
controls?: boolean
|
|
13
|
+
/** Individually hide one control while keeping the others — e.g. a fixed-size window with no maximize button. */
|
|
14
|
+
minimizable?: boolean
|
|
15
|
+
maximizable?: boolean
|
|
16
|
+
closable?: boolean
|
|
17
|
+
/** Reflects the real window state — the bar has no way to know it itself, the host app must read it from its Electron main process and pass it down. */
|
|
18
|
+
maximized?: boolean
|
|
19
|
+
platform?: 'windows' | 'macos'
|
|
20
|
+
/** Bar height in px. */
|
|
21
|
+
height?: number
|
|
22
|
+
/** Double-clicking empty drag space toggles maximize, matching native title bar behavior. */
|
|
23
|
+
doubleClickMaximize?: boolean
|
|
24
|
+
}>(),
|
|
25
|
+
{
|
|
26
|
+
titleAlign: 'start',
|
|
27
|
+
// Explicit `undefined` defaults, not omitted — an omitted optional boolean
|
|
28
|
+
// prop gets auto-cast to `false` by Vue (not left `undefined`), which would
|
|
29
|
+
// permanently break the `props.x ?? smartDefault` fallbacks below.
|
|
30
|
+
controls: undefined,
|
|
31
|
+
minimizable: undefined,
|
|
32
|
+
maximizable: undefined,
|
|
33
|
+
closable: undefined,
|
|
34
|
+
maximized: false,
|
|
35
|
+
platform: 'windows',
|
|
36
|
+
height: 36,
|
|
37
|
+
doubleClickMaximize: true,
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const emit = defineEmits<{ minimize: []; maximize: []; close: [] }>()
|
|
42
|
+
|
|
43
|
+
// A plain Material Symbol name never has a scheme/path/extension, so this is
|
|
44
|
+
// enough to tell an image src apart from an icon name without needing a
|
|
45
|
+
// separate prop.
|
|
46
|
+
const iconIsImage = computed(() => {
|
|
47
|
+
if (!props.icon) return false
|
|
48
|
+
return /^(data:|https?:\/\/|\.{0,2}\/)/.test(props.icon) || /\.(png|jpe?g|svg|gif|webp|ico|avif)$/i.test(props.icon)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const showControls = computed(() => props.controls ?? props.platform !== 'macos')
|
|
52
|
+
const showMinimize = computed(() => showControls.value && (props.minimizable ?? true))
|
|
53
|
+
const showMaximize = computed(() => showControls.value && (props.maximizable ?? true))
|
|
54
|
+
const showClose = computed(() => showControls.value && (props.closable ?? true))
|
|
55
|
+
const hasAnyControl = computed(() => showMinimize.value || showMaximize.value || showClose.value)
|
|
56
|
+
|
|
57
|
+
function onDblclick() {
|
|
58
|
+
if (props.doubleClickMaximize) emit('maximize')
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<div
|
|
64
|
+
class="relative flex w-full shrink-0 select-none items-center bg-surface-container text-on-surface"
|
|
65
|
+
style="-webkit-app-region: drag"
|
|
66
|
+
:style="{ height: `${height}px` }"
|
|
67
|
+
@dblclick="onDblclick"
|
|
68
|
+
>
|
|
69
|
+
<!-- Reserves space for native macOS traffic lights, drawn by the OS outside the web content -->
|
|
70
|
+
<div v-if="platform === 'macos'" class="h-full shrink-0" style="width: 78px" />
|
|
71
|
+
|
|
72
|
+
<div
|
|
73
|
+
v-if="icon || $slots.icon"
|
|
74
|
+
class="flex h-full shrink-0 items-center pl-3"
|
|
75
|
+
style="-webkit-app-region: no-drag"
|
|
76
|
+
>
|
|
77
|
+
<slot name="icon">
|
|
78
|
+
<img v-if="iconIsImage" :src="icon" alt="" class="h-4 w-4 object-contain" />
|
|
79
|
+
<MIcon v-else :name="icon!" :size="16" />
|
|
80
|
+
</slot>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<!-- Start-aligned title sits inline; centered title floats over the whole bar so it's
|
|
84
|
+
centered regardless of how wide the icon/controls on either side are. -->
|
|
85
|
+
<div
|
|
86
|
+
v-if="titleAlign === 'start'"
|
|
87
|
+
class="flex h-full flex-1 items-center truncate px-2 text-label-medium text-on-surface-variant"
|
|
88
|
+
>
|
|
89
|
+
<slot name="title">{{ title }}</slot>
|
|
90
|
+
</div>
|
|
91
|
+
<div v-else class="h-full flex-1" />
|
|
92
|
+
<div
|
|
93
|
+
v-if="titleAlign === 'center'"
|
|
94
|
+
class="pointer-events-none absolute inset-x-0 flex h-full items-center justify-center truncate px-20 text-label-medium text-on-surface-variant"
|
|
95
|
+
>
|
|
96
|
+
<slot name="title">{{ title }}</slot>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<div v-if="$slots.default" class="flex h-full items-center" style="-webkit-app-region: no-drag">
|
|
100
|
+
<slot />
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div v-if="$slots.trailing" class="flex h-full shrink-0 items-center" style="-webkit-app-region: no-drag">
|
|
104
|
+
<slot name="trailing" />
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<div v-if="hasAnyControl" class="flex h-full shrink-0" style="-webkit-app-region: no-drag">
|
|
108
|
+
<button
|
|
109
|
+
v-if="showMinimize"
|
|
110
|
+
type="button"
|
|
111
|
+
class="m3-bar-btn"
|
|
112
|
+
aria-label="Minimize"
|
|
113
|
+
@click="emit('minimize')"
|
|
114
|
+
>
|
|
115
|
+
<MIcon name="horizontal_rule" :size="16" />
|
|
116
|
+
</button>
|
|
117
|
+
<button
|
|
118
|
+
v-if="showMaximize"
|
|
119
|
+
type="button"
|
|
120
|
+
class="m3-bar-btn"
|
|
121
|
+
:aria-label="maximized ? 'Restore' : 'Maximize'"
|
|
122
|
+
@click="emit('maximize')"
|
|
123
|
+
>
|
|
124
|
+
<MIcon :name="maximized ? 'filter_none' : 'crop_square'" :size="14" />
|
|
125
|
+
</button>
|
|
126
|
+
<button
|
|
127
|
+
v-if="showClose"
|
|
128
|
+
type="button"
|
|
129
|
+
class="m3-bar-btn m3-bar-btn-close"
|
|
130
|
+
aria-label="Close"
|
|
131
|
+
@click="emit('close')"
|
|
132
|
+
>
|
|
133
|
+
<MIcon name="close" :size="16" />
|
|
134
|
+
</button>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
</template>
|
|
138
|
+
|
|
139
|
+
<style>
|
|
140
|
+
.m3-bar-btn {
|
|
141
|
+
display: inline-flex;
|
|
142
|
+
height: 100%;
|
|
143
|
+
width: 46px;
|
|
144
|
+
align-items: center;
|
|
145
|
+
justify-content: center;
|
|
146
|
+
color: var(--color-on-surface-variant);
|
|
147
|
+
transition: background-color 100ms ease, color 100ms ease;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
.m3-bar-btn:hover {
|
|
151
|
+
background-color: var(--color-surface-container-highest);
|
|
152
|
+
color: var(--color-on-surface);
|
|
153
|
+
}
|
|
154
|
+
.m3-bar-btn-close:hover {
|
|
155
|
+
background-color: var(--color-error);
|
|
156
|
+
color: var(--color-on-error);
|
|
157
|
+
}
|
|
158
|
+
</style>
|