@m3ui-vue/m3ui-vue 1.0.2 → 1.0.3

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 (106) hide show
  1. package/dist/API.md +599 -9
  2. package/dist/MMenuItem-DFyXflk9.js +707 -0
  3. package/dist/MMenuItem-DFyXflk9.js.map +1 -0
  4. package/dist/MSlider-CdNIH7jc.js +1376 -0
  5. package/dist/MSlider-CdNIH7jc.js.map +1 -0
  6. package/dist/MTextField-B4X92vH_.js +671 -0
  7. package/dist/MTextField-B4X92vH_.js.map +1 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +1 -1
  10. package/dist/components/MIconButton.vue.d.ts +1 -1
  11. package/dist/components/MMap.vue.d.ts +74 -0
  12. package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
  13. package/dist/components/MMapControl.vue.d.ts +23 -0
  14. package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
  15. package/dist/components/MMapFilter.vue.d.ts +19 -0
  16. package/dist/components/MMapGeoJson.vue.d.ts +34 -0
  17. package/dist/components/MMapHover.vue.d.ts +17 -0
  18. package/dist/components/MMapIdentify.vue.d.ts +37 -0
  19. package/dist/components/MMapLayers.vue.d.ts +31 -0
  20. package/dist/components/MMapMarker.vue.d.ts +42 -0
  21. package/dist/components/MMapMeasure.vue.d.ts +43 -0
  22. package/dist/components/MMapPopup.vue.d.ts +43 -0
  23. package/dist/components/MMapSearch.vue.d.ts +28 -0
  24. package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
  25. package/dist/composables/_mapGeometry.d.ts +13 -0
  26. package/dist/composables/_ssrState.d.ts +30 -0
  27. package/dist/composables/_storageKeys.d.ts +3 -0
  28. package/dist/composables/_useThemeTokens.d.ts +7 -0
  29. package/dist/composables/mapAdapters.d.ts +111 -0
  30. package/dist/composables/mapSearch.d.ts +31 -0
  31. package/dist/composables/themeInitScript.d.ts +4 -3
  32. package/dist/composables/useColorPalette.d.ts +173 -7
  33. package/dist/composables/useLocale.d.ts +30 -0
  34. package/dist/composables/useMap.d.ts +47 -0
  35. package/dist/composables/useMapFilter.d.ts +10 -0
  36. package/dist/composables/useMapLayers.d.ts +30 -0
  37. package/dist/composables/useTheme.d.ts +2 -1
  38. package/dist/index.d.ts +2 -1
  39. package/dist/locales/index.js +217 -7
  40. package/dist/locales/index.js.map +1 -1
  41. package/dist/m3ui-vue.css +1 -1
  42. package/dist/m3ui.js +6709 -7976
  43. package/dist/m3ui.js.map +1 -1
  44. package/dist/map.d.ts +24 -0
  45. package/dist/map.js +1931 -0
  46. package/dist/map.js.map +1 -0
  47. package/dist/plugin.d.ts +18 -2
  48. package/dist/rich-text-editor.js +27 -26
  49. package/dist/rich-text-editor.js.map +1 -1
  50. package/dist/styles.css +1 -1
  51. package/dist/{useLocale-CuvWRZ1h.js → useLocale-b5-hzsL3.js} +32 -2
  52. package/dist/useLocale-b5-hzsL3.js.map +1 -0
  53. package/package.json +11 -2
  54. package/src/__tests__/MFab.test.ts +52 -6
  55. package/src/__tests__/MMap.test.ts +292 -0
  56. package/src/__tests__/MMapLayers.test.ts +257 -0
  57. package/src/__tests__/MMapTools.test.ts +233 -0
  58. package/src/__tests__/_fakeMaplibre.ts +158 -0
  59. package/src/__tests__/hydration.test.ts +33 -0
  60. package/src/__tests__/ssr.test.ts +63 -1
  61. package/src/__tests__/ssrState.test.ts +155 -0
  62. package/src/__tests__/themeInitScript.test.ts +18 -0
  63. package/src/components/MFab.vue +29 -7
  64. package/src/components/MIconButton.vue +1 -1
  65. package/src/components/MLightbox.vue +6 -2
  66. package/src/components/MMap.vue +522 -0
  67. package/src/components/MMapBaseLayers.vue +67 -0
  68. package/src/components/MMapControl.vue +61 -0
  69. package/src/components/MMapFeatureInfo.vue +41 -0
  70. package/src/components/MMapFilter.vue +80 -0
  71. package/src/components/MMapGeoJson.vue +136 -0
  72. package/src/components/MMapHover.vue +131 -0
  73. package/src/components/MMapIdentify.vue +103 -0
  74. package/src/components/MMapLayers.vue +111 -0
  75. package/src/components/MMapMarker.vue +102 -0
  76. package/src/components/MMapMeasure.vue +452 -0
  77. package/src/components/MMapPopup.vue +99 -0
  78. package/src/components/MMapSearch.vue +162 -0
  79. package/src/components/_MMapLayerItem.vue +77 -0
  80. package/src/composables/_mapGeometry.ts +75 -0
  81. package/src/composables/_ssrState.ts +80 -0
  82. package/src/composables/_storageKeys.ts +6 -0
  83. package/src/composables/_useThemeTokens.ts +42 -0
  84. package/src/composables/mapAdapters.ts +208 -0
  85. package/src/composables/mapSearch.ts +56 -0
  86. package/src/composables/themeInitScript.ts +6 -4
  87. package/src/composables/useColorPalette.ts +23 -9
  88. package/src/composables/useLocale.ts +62 -0
  89. package/src/composables/useMap.ts +98 -0
  90. package/src/composables/useMapFilter.ts +45 -0
  91. package/src/composables/useMapLayers.ts +124 -0
  92. package/src/composables/useTheme.ts +8 -3
  93. package/src/composables/useWindowSizeClass.ts +14 -5
  94. package/src/index.ts +2 -1
  95. package/src/locales/de.ts +31 -1
  96. package/src/locales/es.ts +31 -1
  97. package/src/locales/fr.ts +31 -1
  98. package/src/locales/ja.ts +31 -1
  99. package/src/locales/ko.ts +31 -1
  100. package/src/locales/pt.ts +31 -1
  101. package/src/locales/zh.ts +31 -1
  102. package/src/map.ts +32 -0
  103. package/src/plugin.ts +54 -3
  104. package/dist/MTextField-BPbFeI9M.js +0 -1368
  105. package/dist/MTextField-BPbFeI9M.js.map +0 -1
  106. package/dist/useLocale-CuvWRZ1h.js.map +0 -1
@@ -2,6 +2,9 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
2
2
  import { createSSRApp, h, nextTick, type Component } from 'vue'
3
3
  import { renderToString } from 'vue/server-renderer'
4
4
 
5
+ // Each test imports the whole library afresh: a cold import can take seconds when the suite runs in parallel
6
+ vi.setConfig({ testTimeout: 30_000 })
7
+
5
8
  /** A fresh copy of the library seeing a window of this width (the window size is read when its modules load). */
6
9
  async function load(width: number) {
7
10
  Object.defineProperty(window, 'innerWidth', { value: width, configurable: true })
@@ -71,6 +74,36 @@ describe('hydrating server-rendered adaptive layouts', () => {
71
74
  expect(container.textContent).toContain('content')
72
75
  })
73
76
 
77
+ it('with a viewport (from a cookie), renders the right layout from the server on, without a jump', async () => {
78
+ const props = { modelValue: 'a', items }
79
+ const slots = { default: () => 'content' }
80
+ const viewport = { width: 1200, height: 800 }
81
+ const server = await load(0)
82
+ // Under happy-dom there is a window, so the flag stands in for the server's (ssr.test.ts renders it without one)
83
+ const html = await renderToString(createSSRApp({ render: () => h(server.MNavigationSuite, props, slots) }).use(server.createM3UI({ initialState: { viewport }, isHydrating: () => true })))
84
+ expect(html).toMatch(/^<div class="[^"]*flex-row/)
85
+
86
+ const lib = await load(1200)
87
+ const container = document.createElement('div')
88
+ container.innerHTML = html
89
+ document.body.appendChild(container)
90
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
91
+ const layouts: string[] = []
92
+ const app = createSSRApp({
93
+ render: () => h(lib.MNavigationSuite, { ...props, onVnodeUpdated: () => layouts.push(container.firstElementChild!.className) }, slots),
94
+ })
95
+ app.use(lib.createM3UI({ initialState: { viewport }, isHydrating: () => true }))
96
+ // happy-dom has no layout: what the browser measures once mounted
97
+ vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(1200)
98
+ vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(800)
99
+ app.mount(container)
100
+ await nextTick()
101
+ expect(warn.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('Hydration'))).toEqual([])
102
+ // Never compact on the client either
103
+ expect(container.firstElementChild!.className).toContain('flex-row')
104
+ expect(layouts.filter((c) => c.includes('flex-col'))).toEqual([])
105
+ })
106
+
74
107
  it('without isHydrating, guesses from the window on the first render (client-only apps)', async () => {
75
108
  const { useWindowSizeClass } = await load(1024)
76
109
  let first = -1
@@ -73,6 +73,8 @@ describe('SSR', () => {
73
73
  ['terminal', 'MTerminal', {}],
74
74
  ['qrcode', 'MQRCode', { value: 'x' }],
75
75
  ['barcode', 'MBarcode', { value: '123456' }],
76
+ // The empty container: MapLibre only loads in the browser
77
+ ['map', 'MMap', { mapStyle: 'https://tiles.test/style.json' }],
76
78
  ] as const)('renders %s/%s', async (entry, name, componentProps) => {
77
79
  const mod = await import(`../${entry}.ts`)
78
80
  await expect(render(mod[name], componentProps)).resolves.toBeTypeOf('string')
@@ -95,7 +97,67 @@ describe('SSR', () => {
95
97
  expect(await render(lib.MPagination, { modelValue: 1, total: 50 }, { locale: lib.defaultLocale })).toBeTruthy()
96
98
  })
97
99
 
98
- it.each(['useTheme', 'useColorPalette', 'useDevice', 'useLocale', 'useWindowSizeClass', 'useToast', 'useNotification'] as const)(
100
+ describe('initialState', () => {
101
+ // What a component renders from the composables, server-side
102
+ async function state(options: object) {
103
+ const app = createSSRApp({
104
+ setup() {
105
+ const { theme } = lib.useTheme()
106
+ const { palette, contrast, activeContrast } = lib.useColorPalette()
107
+ return () => h('p', `${theme.value} ${palette.value} ${contrast.value} ${activeContrast.value}`)
108
+ },
109
+ })
110
+ app.use(lib.createM3UI(options))
111
+ return (await renderToString(app)).replace(/<\/?p>/g, '')
112
+ }
113
+
114
+ it('reports the user\'s choice on the server', async () => {
115
+ expect(await state({ initialState: { theme: 'dark', palette: 'blue', contrast: 'high' } })).toBe('dark blue high high')
116
+ })
117
+
118
+ it('falls back to the plugin\'s defaults, like a first visit', async () => {
119
+ expect(await state({ palette: 'red', contrast: 'medium', initialState: {} })).toBe('system red medium medium')
120
+ expect(await state({ seed: '#6750a4', initialState: {} })).toBe('system seed standard standard')
121
+ })
122
+
123
+ it('resolves system contrast to standard (the server can\'t know the OS preference)', async () => {
124
+ expect(await state({ initialState: { contrast: 'system' } })).toBe('system purple system standard')
125
+ })
126
+
127
+ it('lets persistPalette: false win over the stored choice', async () => {
128
+ expect(await state({ palette: 'red', contrast: 'high', persistPalette: false, initialState: { palette: 'blue', contrast: 'medium' } }))
129
+ .toBe('system red high high')
130
+ })
131
+
132
+ it('ignores invalid values (cookies are user input)', async () => {
133
+ expect(await state({ initialState: { theme: 'pink', contrast: 'max' } as object })).toBe('system purple standard standard')
134
+ })
135
+
136
+ it('renders the adaptive layouts for the given viewport', async () => {
137
+ const suite = (options: object) => render(lib.MNavigationSuite, { modelValue: 'a', items: [{ value: 'a', label: 'A', icon: 'home' }] }, options)
138
+ // A desktop window: a rail beside the content (a row); none known: compact, a bar under it (a column)
139
+ expect(await suite({ initialState: { viewport: { width: 1280, height: 800 } } })).toMatch(/^<div class="[^"]*flex-row/)
140
+ expect(await suite({ initialState: {} })).toMatch(/^<div class="[^"]*flex-col/)
141
+ expect(await suite({ initialState: { viewport: { width: -1, height: 800 } } })).toMatch(/^<div class="[^"]*flex-col/)
142
+ })
143
+
144
+ it('reports the viewport through useWindowSizeClass()', async () => {
145
+ const app = createSSRApp({
146
+ setup() {
147
+ const { widthClass, heightClass } = lib.useWindowSizeClass()
148
+ return () => h('p', `${widthClass.value} ${heightClass.value}`)
149
+ },
150
+ })
151
+ app.use(lib.createM3UI({ initialState: { viewport: { width: 1280, height: 800 } } }))
152
+ expect(await renderToString(app)).toBe('<p>large medium</p>')
153
+ })
154
+
155
+ it('without it, keeps reporting the module defaults', async () => {
156
+ expect(await state({ palette: 'red' })).toBe('system purple standard standard')
157
+ })
158
+ })
159
+
160
+ it.each(['useTheme','useColorPalette', 'useDevice', 'useLocale', 'useWindowSizeClass', 'useToast', 'useNotification'] as const)(
99
161
  '%s() works in setup', async (name) => {
100
162
  const app = createSSRApp({
101
163
  setup() {
@@ -0,0 +1,155 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { createSSRApp, h, nextTick } from 'vue'
3
+
4
+ // Each test imports the whole library afresh: a cold import can take seconds when the suite runs in parallel
5
+ vi.setConfig({ testTimeout: 30_000 })
6
+
7
+ // Fresh modules per test: the theme, palette and cookie switch live at module level
8
+ async function load() {
9
+ vi.resetModules()
10
+ return await import('../index')
11
+ }
12
+
13
+ function cookie(name: string) {
14
+ return document.cookie.split('; ').find((c) => c.startsWith(`${name}=`))?.slice(name.length + 1)
15
+ }
16
+
17
+ beforeEach(() => {
18
+ localStorage.clear()
19
+ for (const name of ['m3-theme', 'm3-palette', 'm3-contrast', 'm3-viewport']) document.cookie = `${name}=; Max-Age=0; Path=/`
20
+ })
21
+
22
+ afterEach(() => {
23
+ vi.restoreAllMocks()
24
+ document.body.innerHTML = ''
25
+ })
26
+
27
+ describe('initialState while hydrating', () => {
28
+ it('renders the server\'s values first (no mismatch), then the stored ones', async () => {
29
+ // The browser holds other values than the cookies the server read (a user from before the cookies)
30
+ localStorage.setItem('m3-theme', 'light')
31
+ localStorage.setItem('m3-palette', 'green')
32
+ const lib = await load()
33
+ const container = document.createElement('div')
34
+ // What the server rendered from the cookies (see ssr.test.ts)
35
+ container.innerHTML = '<p>dark blue</p>'
36
+ document.body.appendChild(container)
37
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
38
+
39
+ let hydrating = true
40
+ const app = createSSRApp({
41
+ setup() {
42
+ const { theme } = lib.useTheme()
43
+ const { palette } = lib.useColorPalette()
44
+ return () => h('p', `${theme.value} ${palette.value}`)
45
+ },
46
+ })
47
+ app.use(lib.createM3UI({ initialState: { theme: 'dark', palette: 'blue' }, isHydrating: () => hydrating }))
48
+ app.mount(container)
49
+ hydrating = false
50
+ await nextTick()
51
+
52
+ expect(warn.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('Hydration'))).toEqual([])
53
+ expect(container.textContent).toBe('light green')
54
+ })
55
+
56
+ it('stays writable during hydration', async () => {
57
+ const lib = await load()
58
+ let theme!: ReturnType<typeof lib.useTheme>['theme']
59
+ const app = createSSRApp({
60
+ setup() {
61
+ theme = lib.useTheme().theme
62
+ return () => h('p', theme.value)
63
+ },
64
+ })
65
+ const container = document.createElement('div')
66
+ container.innerHTML = '<p>dark</p>'
67
+ app.use(lib.createM3UI({ initialState: { theme: 'dark' }, isHydrating: () => true })).mount(container)
68
+ theme.value = 'light'
69
+ await nextTick()
70
+ expect(localStorage.getItem('m3-theme')).toBe('light')
71
+ })
72
+ })
73
+
74
+ describe('cookies', () => {
75
+ it('copies what is already stored when the plugin installs', async () => {
76
+ localStorage.setItem('m3-theme', 'dark')
77
+ localStorage.setItem('m3-palette', 'teal')
78
+ const lib = await load()
79
+ createSSRApp({ render: () => null }).use(lib.createM3UI({ cookies: true }))
80
+ expect(cookie('m3-theme')).toBe('dark')
81
+ expect(cookie('m3-palette')).toBe('teal')
82
+ })
83
+
84
+ it('writes the first-visit default palette', async () => {
85
+ const lib = await load()
86
+ createSSRApp({ render: () => null }).use(lib.createM3UI({ cookies: true, palette: 'red' }))
87
+ expect(cookie('m3-palette')).toBe('red')
88
+ })
89
+
90
+ it('follows changes to the theme, the palette and the contrast', async () => {
91
+ const lib = await load()
92
+ let api!: { theme: ReturnType<typeof lib.useTheme>, palette: ReturnType<typeof lib.useColorPalette> }
93
+ const app = createSSRApp({
94
+ setup() {
95
+ api = { theme: lib.useTheme(), palette: lib.useColorPalette() }
96
+ return () => null
97
+ },
98
+ })
99
+ app.use(lib.createM3UI({ cookies: true })).mount(document.createElement('div'))
100
+ api.theme.theme.value = 'dark'
101
+ api.palette.set('blue')
102
+ api.palette.setContrast('high')
103
+ await nextTick()
104
+ await vi.waitFor(() => expect(cookie('m3-palette')).toBe('blue'))
105
+ expect(cookie('m3-theme')).toBe('dark')
106
+ expect(cookie('m3-contrast')).toBe('high')
107
+ })
108
+
109
+ it('keeps the window size, following resizes', async () => {
110
+ vi.useFakeTimers()
111
+ try {
112
+ Object.defineProperty(window, 'innerWidth', { value: 1280, configurable: true })
113
+ Object.defineProperty(window, 'innerHeight', { value: 800, configurable: true })
114
+ const lib = await load()
115
+ createSSRApp({ render: () => null }).use(lib.createM3UI({ cookies: true }))
116
+ expect(cookie('m3-viewport')).toBe('1280x800')
117
+ Object.defineProperty(window, 'innerWidth', { value: 390, configurable: true })
118
+ window.dispatchEvent(new Event('resize'))
119
+ // Debounced: not on every resize event
120
+ expect(cookie('m3-viewport')).toBe('1280x800')
121
+ vi.advanceTimersByTime(300)
122
+ expect(cookie('m3-viewport')).toBe('390x800')
123
+ } finally {
124
+ vi.useRealTimers()
125
+ }
126
+ })
127
+
128
+ it('falls back to the cookies when storage has nothing (cleared storage, or set by a server), and keeps them', async () => {
129
+ document.cookie = 'm3-theme=dark; Path=/'
130
+ document.cookie = 'm3-palette=blue; Path=/'
131
+ const lib = await load()
132
+ let state = ''
133
+ createSSRApp({
134
+ setup() {
135
+ const { theme } = lib.useTheme()
136
+ const { palette } = lib.useColorPalette()
137
+ state = `${theme.value} ${palette.value}`
138
+ return () => null
139
+ },
140
+ }).use(lib.createM3UI({ cookies: true, palette: 'red' })).mount(document.createElement('div'))
141
+ expect(state).toBe('dark blue')
142
+ expect(cookie('m3-theme')).toBe('dark')
143
+ expect(cookie('m3-palette')).toBe('blue')
144
+ expect(document.documentElement.classList.contains('dark')).toBe(true)
145
+ })
146
+
147
+ it('writes none without the option', async () => {
148
+ localStorage.setItem('m3-theme', 'dark')
149
+ const lib = await load()
150
+ createSSRApp({ render: () => null }).use(lib.createM3UI({ palette: 'red' }))
151
+ expect(cookie('m3-theme')).toBeUndefined()
152
+ expect(cookie('m3-palette')).toBeUndefined()
153
+ expect(cookie('m3-viewport')).toBeUndefined()
154
+ })
155
+ })
@@ -92,6 +92,24 @@ describe('themeInitScript', () => {
92
92
  expect(html.getAttribute('data-contrast')).toBe('high')
93
93
  })
94
94
 
95
+ it('falls back to the cookies when storage has nothing', () => {
96
+ document.cookie = 'm3-theme=dark; Path=/'
97
+ document.cookie = 'm3-palette=blue; Path=/'
98
+ try {
99
+ matchMedia({})
100
+ run({ palette: 'red' })
101
+ expect(html.classList.contains('dark')).toBe(true)
102
+ expect(html.getAttribute('data-palette')).toBe('blue')
103
+ // Storage wins over a cookie
104
+ localStorage.setItem('m3-theme', 'light')
105
+ run()
106
+ expect(html.classList.contains('dark')).toBe(false)
107
+ } finally {
108
+ document.cookie = 'm3-theme=; Max-Age=0; Path=/'
109
+ document.cookie = 'm3-palette=; Max-Age=0; Path=/'
110
+ }
111
+ })
112
+
95
113
  it('survives blocked storage', () => {
96
114
  vi.stubGlobal('localStorage', { getItem: () => { throw new Error('blocked') } })
97
115
  expect(() => run({ palette: 'red' })).not.toThrow()
@@ -113,10 +113,11 @@ const colorMap: Record<string, string> = {
113
113
  // minimum width = height, MediumExtendedFabIconPadding/LargeExtendedFabIconPadding (12/16dp, the tokens'
114
114
  // IconLabelSpace is marked incorrect there).
115
115
  const EXTENDED = {
116
- regular: { px: 56, icon: 24, gap: 12, box: 'h-14 min-w-20 rounded-2xl pl-4 pr-5', text: 'text-label-large font-medium' },
117
- small: { px: 56, icon: 24, gap: 8, box: 'h-14 min-w-14 rounded-2xl px-4', text: 'text-title-medium font-medium' },
118
- medium: { px: 80, icon: 28, gap: 12, box: 'h-20 min-w-20 rounded-lg-increased px-[26px]', text: 'text-title-large' },
119
- large: { px: 96, icon: 32, gap: 16, box: 'h-24 min-w-24 rounded-xl px-7', text: 'text-headline-small' },
116
+ // lead: the box's start padding (its pl-/px- class)
117
+ regular: { px: 56, icon: 24, lead: 16, gap: 'pl-3', box: 'h-14 min-w-20 rounded-2xl pl-4 pr-5', text: 'text-label-large font-medium' },
118
+ small: { px: 56, icon: 24, lead: 16, gap: 'pl-2', box: 'h-14 min-w-14 rounded-2xl px-4', text: 'text-title-medium font-medium' },
119
+ medium: { px: 80, icon: 28, lead: 26, gap: 'pl-3', box: 'h-20 min-w-20 rounded-lg-increased px-[26px]', text: 'text-title-large' },
120
+ large: { px: 96, icon: 32, lead: 28, gap: 'pl-4', box: 'h-24 min-w-24 rounded-xl px-7', text: 'text-headline-small' },
120
121
  } as const
121
122
  const extended = computed(() => (props.label ? EXTENDED[props.size] : null))
122
123
 
@@ -152,7 +153,23 @@ const fabPx = computed(() => {
152
153
 
153
154
  // Collapsing an extended FAB: the width lerps from the square (the minimum width) to the full width on
154
155
  // FastSpatial, the label fades on FastEffects, and it leaves the layout once fully collapsed.
156
+ // Collapsed, the icon sits centered like a plain FAB's. Compose keeps the start padding instead, which only centers it
157
+ // where padding + icon + padding fills the square: the large size's 28 + 32 + 28 leaves it 4dp off center (a
158
+ // deliberate departure), so the start padding lerps to the centered one with the width.
159
+ const collapsedLead = (e: (typeof EXTENDED)[keyof typeof EXTENDED]) => (e.px - e.icon) / 2
155
160
  const fabButton = ref<HTMLElement | { $el: HTMLElement }>()
161
+ // An extended FAB that starts collapsed renders collapsed (server-side rendering: before the springs below run).
162
+ // Constant objects: Vue applies a binding again only when its value changes, so these never undo the springs'
163
+ // writes on a later render
164
+ const startCollapsed = !!extended.value && !props.expanded
165
+ const initialButtonStyle = startCollapsed
166
+ ? {
167
+ width: `${extended.value!.px}px`,
168
+ minWidth: '0',
169
+ ...(collapsedLead(extended.value!) !== extended.value!.lead && { paddingLeft: `${collapsedLead(extended.value!)}px` }),
170
+ }
171
+ : undefined
172
+ const initialLabelStyle = startCollapsed ? { display: 'none', opacity: '0' } : undefined
156
173
  const labelEl = ref<HTMLElement>()
157
174
  const buttonEl = () => (fabButton.value instanceof HTMLElement ? fabButton.value : fabButton.value?.$el)
158
175
 
@@ -164,11 +181,15 @@ useSpring(
164
181
  if (labelEl.value) labelEl.value.style.display = p <= 0 && !props.expanded ? 'none' : ''
165
182
  el.style.width = ''
166
183
  el.style.minWidth = ''
184
+ el.style.paddingLeft = ''
167
185
  if (p >= 1 && props.expanded) return
168
186
  const full = el.offsetWidth
169
- const min = extended.value.px
187
+ const { px: min, lead } = extended.value
188
+ const t = Math.min(1, Math.max(0, p))
170
189
  el.style.minWidth = '0'
171
190
  el.style.width = `${min + (full - min) * Math.max(0, p)}px`
191
+ const centered = collapsedLead(extended.value)
192
+ if (centered !== lead) el.style.paddingLeft = `${centered + (lead - centered) * t}px`
172
193
  },
173
194
  FAST_SPATIAL,
174
195
  )
@@ -348,6 +369,7 @@ onUnmounted(() => {
348
369
  :class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
349
370
  :disabled="disabled"
350
371
  :aria-label="label && !expanded ? label : undefined"
372
+ :style="initialButtonStyle"
351
373
  v-ripple="{ disabled, color: rippleColor }"
352
374
  @click="handleFabClick"
353
375
  >
@@ -362,8 +384,8 @@ onUnmounted(() => {
362
384
  v-if="extended"
363
385
  ref="labelEl"
364
386
  class="shrink-0 whitespace-nowrap"
365
- :class="extended.text"
366
- :style="{ paddingLeft: `${extended.gap}px` }"
387
+ :class="[extended.text, extended.gap]"
388
+ :style="initialLabelStyle"
367
389
  >{{ label }}</span>
368
390
  </component>
369
391
  </div>
@@ -14,7 +14,7 @@ const props = withDefaults(
14
14
  defineProps<{
15
15
  /** Material Symbol icon name */
16
16
  icon: string
17
- /** Accessible label (aria-label and title) */
17
+ /** Accessible label (its aria-label; no visible tooltip: wrap it in MTooltip for one) */
18
18
  label?: string
19
19
  /** Visual style */
20
20
  variant?: 'standard' | 'filled' | 'tonal' | 'outlined'
@@ -27,6 +27,7 @@
27
27
  * dampingRatio 0.9 / stiffness 700) stepped in one rAF loop that writes transforms directly.
28
28
  */
29
29
  import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
30
+ import { isHydrating } from '../composables/_hydration'
30
31
  import MIconButton from './MIconButton.vue'
31
32
  import MSpinner from './MSpinner.vue'
32
33
  import { useLocale } from '../composables/useLocale'
@@ -336,12 +337,15 @@ function hide() {
336
337
  animate()
337
338
  }
338
339
 
339
- // Not on the server (SSR): it renders closed there, and an open one opens on the client
340
+ // Not on the server (SSR): it renders closed there, and an open one opens on the client. Hydrating that HTML
341
+ // (createM3UI({ isHydrating })), the first render has to stay closed to match it: open once mounted instead
342
+ const hydrating = isHydrating()
340
343
  watch(() => props.modelValue, (v) => {
341
344
  if (typeof document === 'undefined') return
342
345
  if (v) !rendered.value && show()
343
346
  else rendered.value && hide()
344
- }, { immediate: true })
347
+ }, { immediate: !hydrating })
348
+ if (hydrating) onMounted(() => { if (props.modelValue && !rendered.value) show() })
345
349
  watch(() => props.index, (v) => {
346
350
  if (v === currentIndex.value || !galleryItems.value[v]) return
347
351
  // Closed, or still opening (a consumer usually sets the index and opens in the same tick): show