@m3ui-vue/m3ui-vue 1.0.2 → 1.1.0

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 (157) hide show
  1. package/dist/API.md +666 -12
  2. package/dist/MMenuItem-BOkcVtEe.js +809 -0
  3. package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
  4. package/dist/MSlider-BXsBv0ox.js +1402 -0
  5. package/dist/MSlider-BXsBv0ox.js.map +1 -0
  6. package/dist/MTextField-rML9jnXs.js +671 -0
  7. package/dist/MTextField-rML9jnXs.js.map +1 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +1 -1
  10. package/dist/components/MBottomSheet.vue.d.ts +20 -1
  11. package/dist/components/MDialog.vue.d.ts +17 -8
  12. package/dist/components/MDragDropList.vue.d.ts +1 -1
  13. package/dist/components/MIconButton.vue.d.ts +1 -1
  14. package/dist/components/MMap.vue.d.ts +74 -0
  15. package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
  16. package/dist/components/MMapControl.vue.d.ts +40 -0
  17. package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
  18. package/dist/components/MMapFilter.vue.d.ts +19 -0
  19. package/dist/components/MMapGeoJson.vue.d.ts +34 -0
  20. package/dist/components/MMapHover.vue.d.ts +17 -0
  21. package/dist/components/MMapIdentify.vue.d.ts +37 -0
  22. package/dist/components/MMapLayers.vue.d.ts +31 -0
  23. package/dist/components/MMapMarker.vue.d.ts +45 -0
  24. package/dist/components/MMapMeasure.vue.d.ts +43 -0
  25. package/dist/components/MMapPopup.vue.d.ts +45 -0
  26. package/dist/components/MMapSearch.vue.d.ts +28 -0
  27. package/dist/components/MMenuItem.vue.d.ts +2 -2
  28. package/dist/components/MSeekBar.vue.d.ts +122 -0
  29. package/dist/components/MSplitButton.vue.d.ts +2 -2
  30. package/dist/components/_MMapAttribution.vue.d.ts +7 -0
  31. package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
  32. package/dist/composables/_mapGeometry.d.ts +13 -0
  33. package/dist/composables/_mapPin.d.ts +5 -0
  34. package/dist/composables/_popupPosition.d.ts +12 -0
  35. package/dist/composables/_ssrState.d.ts +30 -0
  36. package/dist/composables/_storageKeys.d.ts +3 -0
  37. package/dist/composables/_useCalendarMonth.d.ts +24 -0
  38. package/dist/composables/_useEscapeStack.d.ts +3 -0
  39. package/dist/composables/_useScrollLock.d.ts +8 -0
  40. package/dist/composables/_useSheetMotion.d.ts +16 -1
  41. package/dist/composables/_useThemeTokens.d.ts +7 -0
  42. package/dist/composables/mapAdapters.d.ts +111 -0
  43. package/dist/composables/mapSearch.d.ts +31 -0
  44. package/dist/composables/themeInitScript.d.ts +4 -3
  45. package/dist/composables/useColorPalette.d.ts +173 -7
  46. package/dist/composables/useLocale.d.ts +38 -0
  47. package/dist/composables/useMap.d.ts +47 -0
  48. package/dist/composables/useMapFilter.d.ts +10 -0
  49. package/dist/composables/useMapLayers.d.ts +30 -0
  50. package/dist/composables/useTheme.d.ts +2 -1
  51. package/dist/index.d.ts +4 -1
  52. package/dist/locales/index.js +273 -7
  53. package/dist/locales/index.js.map +1 -1
  54. package/dist/m3ui-vue.css +1 -1
  55. package/dist/m3ui.js +7913 -8625
  56. package/dist/m3ui.js.map +1 -1
  57. package/dist/map.d.ts +24 -0
  58. package/dist/map.js +2067 -0
  59. package/dist/map.js.map +1 -0
  60. package/dist/plugin.d.ts +18 -2
  61. package/dist/rich-text-editor.js +26 -25
  62. package/dist/rich-text-editor.js.map +1 -1
  63. package/dist/styles.css +1 -1
  64. package/dist/{useLocale-CuvWRZ1h.js → useLocale-CqQrhWFl.js} +40 -2
  65. package/dist/useLocale-CqQrhWFl.js.map +1 -0
  66. package/package.json +11 -2
  67. package/src/__tests__/MDialog.test.ts +30 -0
  68. package/src/__tests__/MFab.test.ts +52 -6
  69. package/src/__tests__/MMap.test.ts +422 -0
  70. package/src/__tests__/MMapLayers.test.ts +257 -0
  71. package/src/__tests__/MMapTools.test.ts +233 -0
  72. package/src/__tests__/MSeekBar.test.ts +170 -0
  73. package/src/__tests__/MTooltip.test.ts +110 -0
  74. package/src/__tests__/_fakeMaplibre.ts +161 -0
  75. package/src/__tests__/calendarMonth.test.ts +59 -0
  76. package/src/__tests__/hydration.test.ts +33 -0
  77. package/src/__tests__/pickerModals.test.ts +128 -0
  78. package/src/__tests__/popupPosition.test.ts +224 -0
  79. package/src/__tests__/scrollLock.test.ts +110 -0
  80. package/src/__tests__/sheets.test.ts +158 -0
  81. package/src/__tests__/ssr.test.ts +63 -1
  82. package/src/__tests__/ssrState.test.ts +155 -0
  83. package/src/__tests__/themeInitScript.test.ts +18 -0
  84. package/src/components/MAutocomplete.vue +2 -4
  85. package/src/components/MBottomSheet.vue +211 -13
  86. package/src/components/MCommandPalette.vue +4 -6
  87. package/src/components/MContextMenu.vue +19 -5
  88. package/src/components/MDatePicker.vue +29 -70
  89. package/src/components/MDatePickerModal.vue +116 -172
  90. package/src/components/MDateRangePicker.vue +29 -51
  91. package/src/components/MDateRangePickerModal.vue +84 -162
  92. package/src/components/MDialog.vue +87 -63
  93. package/src/components/MFab.vue +29 -7
  94. package/src/components/MIconButton.vue +1 -1
  95. package/src/components/MLightbox.vue +12 -5
  96. package/src/components/MMap.vue +568 -0
  97. package/src/components/MMapBaseLayers.vue +67 -0
  98. package/src/components/MMapControl.vue +175 -0
  99. package/src/components/MMapFeatureInfo.vue +41 -0
  100. package/src/components/MMapFilter.vue +80 -0
  101. package/src/components/MMapGeoJson.vue +136 -0
  102. package/src/components/MMapHover.vue +131 -0
  103. package/src/components/MMapIdentify.vue +104 -0
  104. package/src/components/MMapLayers.vue +111 -0
  105. package/src/components/MMapMarker.vue +109 -0
  106. package/src/components/MMapMeasure.vue +452 -0
  107. package/src/components/MMapPopup.vue +103 -0
  108. package/src/components/MMapSearch.vue +162 -0
  109. package/src/components/MMenu.vue +31 -12
  110. package/src/components/MMenuItem.vue +21 -4
  111. package/src/components/MMultiAutocomplete.vue +2 -4
  112. package/src/components/MMultiSelect.vue +2 -4
  113. package/src/components/MNavigationDrawer.vue +2 -8
  114. package/src/components/MNavigationRail.vue +2 -3
  115. package/src/components/MSearchBar.vue +2 -5
  116. package/src/components/MSeekBar.vue +593 -0
  117. package/src/components/MSelect.vue +2 -8
  118. package/src/components/MSplitButton.vue +23 -7
  119. package/src/components/MSpotlightSearch.vue +4 -6
  120. package/src/components/MTimePicker.vue +23 -6
  121. package/src/components/MTimePickerModal.vue +213 -226
  122. package/src/components/MTooltip.vue +99 -3
  123. package/src/components/_MMapAttribution.vue +81 -0
  124. package/src/components/_MMapLayerItem.vue +77 -0
  125. package/src/composables/_mapGeometry.ts +75 -0
  126. package/src/composables/_mapPin.ts +25 -0
  127. package/src/composables/_popupPosition.ts +39 -0
  128. package/src/composables/_ssrState.ts +80 -0
  129. package/src/composables/_storageKeys.ts +6 -0
  130. package/src/composables/_useCalendarMonth.ts +74 -0
  131. package/src/composables/_useEscapeStack.ts +33 -0
  132. package/src/composables/_useScrollLock.ts +41 -0
  133. package/src/composables/_useSheetMotion.ts +82 -20
  134. package/src/composables/_useThemeTokens.ts +42 -0
  135. package/src/composables/mapAdapters.ts +208 -0
  136. package/src/composables/mapSearch.ts +56 -0
  137. package/src/composables/themeInitScript.ts +6 -4
  138. package/src/composables/useColorPalette.ts +23 -9
  139. package/src/composables/useLocale.ts +78 -0
  140. package/src/composables/useMap.ts +98 -0
  141. package/src/composables/useMapFilter.ts +45 -0
  142. package/src/composables/useMapLayers.ts +124 -0
  143. package/src/composables/useTheme.ts +8 -3
  144. package/src/composables/useWindowSizeClass.ts +14 -5
  145. package/src/index.ts +4 -1
  146. package/src/locales/de.ts +39 -1
  147. package/src/locales/es.ts +39 -1
  148. package/src/locales/fr.ts +39 -1
  149. package/src/locales/ja.ts +39 -1
  150. package/src/locales/ko.ts +39 -1
  151. package/src/locales/pt.ts +39 -1
  152. package/src/locales/zh.ts +39 -1
  153. package/src/map.ts +32 -0
  154. package/src/plugin.ts +54 -3
  155. package/dist/MTextField-BPbFeI9M.js +0 -1368
  156. package/dist/MTextField-BPbFeI9M.js.map +0 -1
  157. package/dist/useLocale-CuvWRZ1h.js.map +0 -1
@@ -0,0 +1,593 @@
1
+ <script lang="ts">
2
+ export interface SeekBarChapter {
3
+ /** Where the chapter starts, in seconds */
4
+ start: number
5
+ /** Shown in the preview while the pointer is over it */
6
+ title?: string
7
+ }
8
+ </script>
9
+
10
+ <script setup lang="ts">
11
+ /**
12
+ * A media seek bar (not an M3 spec component; Media3's ProgressSlider is a plain M3 Slider, which this follows in
13
+ * its default look): the playback position on a track with the buffered part, optional chapters, elapsed and
14
+ * total (or remaining) time, and a preview of the time under the pointer. Dragging scrubs locally and seeks once
15
+ * on release (or live, with `live`); a tap or click seeks to that point. While `playing`, it advances on its own
16
+ * between `modelValue` updates, so a 4Hz `timeupdate` still moves it smoothly.
17
+ *
18
+ * @slot preview Replaces the bubble shown above the pointer while hovering or dragging (a frame preview, say).
19
+ * Props: `{ time, formatted, chapter }`
20
+ * @event update:modelValue Emitted on a seek (and continuously while dragging with `live`) — powers v-model
21
+ * @event seek Emitted once per seek with its time: on release of a drag, a tap or click, or a key press
22
+ * @event scrub-start Emitted when a drag starts, with its time
23
+ * @event scrub Emitted while dragging, with the time under the pointer
24
+ * @event update:remaining Emitted when the end label is clicked to switch between total and remaining time
25
+ */
26
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
27
+ import { useLocale } from '../composables/useLocale'
28
+
29
+ const props = withDefaults(defineProps<{
30
+ /** Playback position in seconds (v-model) */
31
+ modelValue: number
32
+ /** Media length in seconds; 0, NaN or Infinity (not loaded yet, a live stream) disables seeking */
33
+ duration: number
34
+ /** How much is loaded: up to a time, or time ranges (`[[start, end], …]`, like a media element's `buffered`) */
35
+ buffered?: number | [number, number][]
36
+ /** Chapter starts, drawn as gaps in the track; their titles show in the preview */
37
+ chapters?: SeekBarChapter[]
38
+ /** The media is playing: the bar moves on its own between updates, and the wavy line waves */
39
+ playing?: boolean
40
+ /** Playback speed, for that motion between updates */
41
+ playbackRate?: number
42
+ /** Updates the v-model continuously while dragging (the media follows the thumb), not only on release */
43
+ live?: boolean
44
+ /** `slider`: the M3 slider (bar thumb with a gap around it). `line`: a plain line with a round thumb. `wavy`: the played part waves while playing */
45
+ variant?: 'slider' | 'line' | 'wavy'
46
+ /** Track thickness: `md` (16px, the smallest M3 slider), `sm` (8px) or `xs` (4px, over a video) */
47
+ size?: 'xs' | 'sm' | 'md'
48
+ /** Where the elapsed and total time go */
49
+ time?: 'below' | 'sides' | 'none'
50
+ /** The end label shows the remaining time (`-1:23`) instead of the total; clicking it switches (v-model:remaining) */
51
+ remaining?: boolean
52
+ /** Formats a time in seconds. Default `m:ss`, or `h:mm:ss` for media an hour or longer */
53
+ format?: (seconds: number) => string
54
+ /** Seconds the arrow keys move; Page Up/Down move 10% */
55
+ keyStep?: number
56
+ /** Shows the time (and chapter) above the pointer while hovering or dragging */
57
+ preview?: boolean
58
+ /** Played part and thumb: an M3 role (`primary`, `secondary`, `tertiary`, `error`) or any CSS color */
59
+ color?: string
60
+ /** Unplayed track: an M3 role or any CSS color. Default secondary-container */
61
+ trackColor?: string
62
+ /** The time labels' color, as a CSS color (white over a video, say). Default on-surface-variant */
63
+ timeColor?: string
64
+ /** Disables seeking */
65
+ disabled?: boolean
66
+ /** Accessible name. Default the locale's `seekBar` */
67
+ label?: string
68
+ }>(), {
69
+ playing: false,
70
+ playbackRate: 1,
71
+ live: false,
72
+ variant: 'slider',
73
+ size: 'md',
74
+ time: 'below',
75
+ remaining: false,
76
+ keyStep: 5,
77
+ preview: true,
78
+ color: 'primary',
79
+ disabled: false,
80
+ })
81
+
82
+ const emit = defineEmits<{
83
+ 'update:modelValue': [number]
84
+ seek: [number]
85
+ 'scrub-start': [number]
86
+ scrub: [number]
87
+ 'update:remaining': [boolean]
88
+ }>()
89
+
90
+ const locale = useLocale()
91
+
92
+ // track: thickness; thumbH: the bar thumb's height (md = MSlider xs, SliderTokens.HandleHeight); dot: the line
93
+ // variant's round thumb under the pointer, dotIdle at rest (the thinner the line, the more it grows, as a
94
+ // video player's does); gap: around the bar thumb; hit: the pointer target's height; wave/amp/length: the wavy line
95
+ const SIZES = {
96
+ xs: { track: 4, thumbH: 16, dot: 21, dotIdle: 10, gap: 4, hit: 32, wave: 4, amp: 2.5, length: 18 },
97
+ sm: { track: 8, thumbH: 28, dot: 20, dotIdle: 14, gap: 5, hit: 40, wave: 6, amp: 3, length: 22 },
98
+ md: { track: 16, thumbH: 44, dot: 28, dotIdle: 21, gap: 6, hit: 46, wave: 8, amp: 4, length: 26 },
99
+ }
100
+ const s = computed(() => SIZES[props.size] ?? SIZES.md)
101
+
102
+ const dur = computed(() => (Number.isFinite(props.duration) && props.duration > 0 ? props.duration : 0))
103
+ const inactive = computed(() => props.disabled || !dur.value)
104
+
105
+ // ── Colors (as in MSlider: a role name or any CSS color; disabled per SliderTokens) ─────────────────────
106
+ const ROLES: Record<string, string> = {
107
+ primary: 'var(--color-primary)',
108
+ secondary: 'var(--color-secondary)',
109
+ tertiary: 'var(--color-tertiary)',
110
+ error: 'var(--color-error)',
111
+ 'secondary-container': 'var(--color-secondary-container)',
112
+ }
113
+ const colors = computed(() => {
114
+ if (props.disabled) {
115
+ return {
116
+ active: 'color-mix(in srgb, var(--color-on-surface) 38%, transparent)',
117
+ inactive: 'color-mix(in srgb, var(--color-on-surface) 12%, transparent)',
118
+ buffered: 'color-mix(in srgb, var(--color-on-surface) 20%, transparent)',
119
+ }
120
+ }
121
+ const active = ROLES[props.color] ?? props.color
122
+ const inactive = props.trackColor ? ROLES[props.trackColor] ?? props.trackColor : 'var(--color-secondary-container)'
123
+ return { active, inactive, buffered: `color-mix(in srgb, ${active} 35%, ${inactive})` }
124
+ })
125
+
126
+ // ── Time ────────────────────────────────────────────────────────────────────────────────────────────────
127
+ const pad = (n: number) => String(n).padStart(2, '0')
128
+ function fmt(t: number) {
129
+ if (props.format) return props.format(t)
130
+ const sec = Math.max(0, Math.floor(t))
131
+ const h = Math.floor(sec / 3600)
132
+ const m = Math.floor((sec % 3600) / 60)
133
+ return (dur.value >= 3600 ? `${h}:${pad(m)}` : String(h * 60 + m)) + ':' + pad(sec % 60)
134
+ }
135
+
136
+ // The shown position: the drag's while scrubbing, else `pos`, which follows modelValue and, while playing,
137
+ // advances on its own (only written when it moves half a pixel or crosses a second, so it re-renders rarely)
138
+ const scrubTime = ref<number | null>(null)
139
+ const pos = ref(props.modelValue)
140
+ const current = computed(() => Math.min(dur.value || Infinity, Math.max(0, scrubTime.value ?? pos.value)))
141
+
142
+ const showRemaining = ref(props.remaining)
143
+ watch(() => props.remaining, (v) => { showRemaining.value = v })
144
+ function toggleRemaining() {
145
+ showRemaining.value = !showRemaining.value
146
+ emit('update:remaining', showRemaining.value)
147
+ }
148
+ const timeStyle = computed(() => (props.timeColor ? { color: props.timeColor } : undefined))
149
+ const startText = computed(() => fmt(current.value))
150
+ const endText = computed(() => {
151
+ if (!dur.value) return '--:--'
152
+ return showRemaining.value ? `-${fmt(dur.value - current.value)}` : fmt(dur.value)
153
+ })
154
+ const valueText = computed(() =>
155
+ locale.seekBarValue.replace('{position}', fmt(current.value)).replace('{duration}', dur.value ? fmt(dur.value) : '--:--'),
156
+ )
157
+
158
+ const chapterAt = (t: number) => {
159
+ let found: SeekBarChapter | null = null
160
+ for (const c of props.chapters ?? []) if (c.start <= t && (!found || c.start >= found.start)) found = c
161
+ return found
162
+ }
163
+
164
+ // ── Geometry (px, from the measured track width) ────────────────────────────────────────────────────────
165
+ const trackEl = ref<HTMLElement>()
166
+ const width = ref(0)
167
+ const toPx = (t: number) => (dur.value ? (width.value * Math.min(1, Math.max(0, t / dur.value))) : 0)
168
+
169
+ // The bar thumb keeps clear of the track's ends, as MSlider's thumbInset; the round one may overhang them
170
+ const thumbX = computed(() => {
171
+ const x = toPx(current.value)
172
+ if (props.variant === 'line') return x
173
+ const inset = Math.max(2, s.value.track * 0.3)
174
+ return Math.min(width.value - inset, Math.max(inset, x))
175
+ })
176
+
177
+ const bufferedRanges = computed<[number, number][]>(() => {
178
+ const b = props.buffered
179
+ if (b === undefined) return []
180
+ return typeof b === 'number' ? [[0, b]] : b
181
+ })
182
+
183
+ interface Piece { a: number; b: number; rl: number; rr: number; fills: { left: number; width: number; color: string }[] }
184
+
185
+ // The track is drawn as pieces between cuts: chapter boundaries, the gap around the bar thumb and, for the wavy
186
+ // line, everything before the thumb (drawn by the SVG). Outer ends get a full radius, cut ends a small one, as
187
+ // the M3 slider's segments.
188
+ const pieces = computed<Piece[]>(() => {
189
+ const W = width.value
190
+ if (!W) return []
191
+ const { gap } = s.value
192
+ const track = trackH.value
193
+ const x = thumbX.value
194
+ const chapterGap = props.size === 'md' ? 4 : 2
195
+ const cuts: [number, number][] = []
196
+ for (const c of props.chapters ?? []) {
197
+ if (c.start <= 0 || c.start >= dur.value) continue
198
+ const cx = toPx(c.start)
199
+ cuts.push([cx - chapterGap / 2, cx + chapterGap / 2])
200
+ }
201
+ if (props.variant === 'slider') cuts.push([x - gap, x + gap])
202
+ if (props.variant === 'wavy') cuts.push([-Infinity, x + gap])
203
+ cuts.sort((p, q) => p[0] - q[0])
204
+ const spans: [number, number][] = []
205
+ let at = 0
206
+ for (const [c0, c1] of cuts) {
207
+ if (c0 > at) spans.push([at, Math.min(c0, W)])
208
+ at = Math.max(at, c1)
209
+ }
210
+ if (at < W) spans.push([at, W])
211
+
212
+ const full = track / 2
213
+ const small = Math.min(full, Math.max(1, track / 8))
214
+ const playedTo = props.variant === 'line' ? toPx(current.value) : x
215
+ return spans.filter(([a, b]) => b - a >= 0.5).map(([a, b]) => {
216
+ const fills: Piece['fills'] = []
217
+ for (const [t0, t1] of bufferedRanges.value) {
218
+ const l = Math.max(a, toPx(t0))
219
+ const r = Math.min(b, toPx(t1))
220
+ if (r > l) fills.push({ left: l - a, width: r - l, color: colors.value.buffered })
221
+ }
222
+ if (playedTo > a) fills.push({ left: 0, width: Math.min(b, playedTo) - a, color: colors.value.active })
223
+ return { a, b, rl: a <= 0.01 ? full : small, rr: b >= W - 0.01 ? full : small, fills }
224
+ })
225
+ })
226
+
227
+ // M3's stop indicator at the far end of a (md) slider track, while the thumb hasn't reached it
228
+ const stopDot = computed(() => props.variant === 'slider' && props.size === 'md' && thumbX.value < width.value - 12 - s.value.gap)
229
+
230
+ // ── Thumb ───────────────────────────────────────────────────────────────────────────────────────────────
231
+ const pressed = ref(false)
232
+ const focused = ref(false)
233
+ const hovered = ref(false)
234
+
235
+ // The line thickens under the pointer, as a video player's does; the wavy line's unplayed part is as thick as the
236
+ // wave's stroke (WavyProgressIndicatorDefaults: the same stroke for indicator and track)
237
+ const trackH = computed(() => {
238
+ if (props.variant === 'wavy') return s.value.wave
239
+ const t = s.value.track
240
+ return props.variant === 'line' && !inactive.value && (hovered.value || pressed.value) ? t + Math.max(2, t / 4) : t
241
+ })
242
+ const thumbStyle = computed(() => {
243
+ const base = { left: `${thumbX.value}px`, backgroundColor: colors.value.active }
244
+ if (props.variant === 'line') {
245
+ const { dot: d, dotIdle } = s.value
246
+ const scale = pressed.value || hovered.value || focused.value ? 1 : dotIdle / d
247
+ return { ...base, width: `${d}px`, height: `${d}px`, borderRadius: '50%', transform: `translate(-50%, -50%) scale(${scale})` }
248
+ }
249
+ // Pinches to half its width while pressed or focused, as MSlider (SliderTokens.PressedHandleWidth)
250
+ const narrow = pressed.value || focused.value ? 0.5 : 1
251
+ return { ...base, width: '4px', height: `${s.value.thumbH}px`, borderRadius: '2px', transform: `translate(-50%, -50%) scaleX(${narrow})` }
252
+ })
253
+
254
+ // ── Preview bubble ──────────────────────────────────────────────────────────────────────────────────────
255
+ const hoverTime = ref<number | null>(null)
256
+ const previewTime = computed(() => (props.preview && !inactive.value ? scrubTime.value ?? hoverTime.value : null))
257
+ const previewChapter = computed(() => (previewTime.value === null ? null : chapterAt(previewTime.value)))
258
+ const bubbleEl = ref<HTMLElement>()
259
+ const bubbleW = ref(0)
260
+ let bubbleObserver: ResizeObserver | null = null
261
+ watch(bubbleEl, (el) => {
262
+ bubbleObserver?.disconnect()
263
+ if (!el || typeof ResizeObserver === 'undefined') return
264
+ bubbleW.value = el.offsetWidth
265
+ bubbleObserver = new ResizeObserver(() => { bubbleW.value = el.offsetWidth })
266
+ bubbleObserver.observe(el)
267
+ })
268
+ // Centered over the time, but kept within the track
269
+ const previewX = computed(() => {
270
+ const x = previewTime.value === null ? 0 : toPx(previewTime.value)
271
+ const half = bubbleW.value / 2
272
+ return half * 2 >= width.value ? width.value / 2 : Math.min(width.value - half, Math.max(half, x))
273
+ })
274
+
275
+ // ── Pointer: mouse/pen scrub from the press; a touch waits to see a horizontal move (touch-action pan-y leaves a
276
+ // vertical one to the page), and a touch that doesn't move is a tap that seeks there ────────────────────────
277
+ let press: { id: number; x: number; y: number; touch: boolean; started: boolean } | null = null
278
+
279
+ function timeAt(clientX: number) {
280
+ const el = trackEl.value
281
+ if (!el || !dur.value) return 0
282
+ const r = el.getBoundingClientRect()
283
+ return (Math.min(1, Math.max(0, (clientX - r.left) / (r.width || 1)))) * dur.value
284
+ }
285
+
286
+ function scrubTo(t: number) {
287
+ scrubTime.value = t
288
+ emit('scrub', t)
289
+ if (props.live) emit('update:modelValue', t)
290
+ }
291
+
292
+ function begin(e: PointerEvent) {
293
+ if (!press) return
294
+ press.started = true
295
+ pressed.value = true
296
+ const t = timeAt(e.clientX)
297
+ emit('scrub-start', t)
298
+ scrubTo(t)
299
+ }
300
+
301
+ function commit(t: number) {
302
+ emit('update:modelValue', t)
303
+ emit('seek', t)
304
+ // Show it at once; a later modelValue resyncs
305
+ pos.value = t
306
+ base = t
307
+ baseAt = now()
308
+ }
309
+
310
+ function onPointerDown(e: PointerEvent) {
311
+ if (inactive.value || e.button !== 0) return
312
+ press = { id: e.pointerId, x: e.clientX, y: e.clientY, touch: e.pointerType === 'touch', started: false }
313
+ window.addEventListener('pointermove', onPointerMove)
314
+ window.addEventListener('pointerup', onPointerUp)
315
+ window.addEventListener('pointercancel', onPointerCancel)
316
+ if (!press.touch) {
317
+ e.preventDefault()
318
+ trackEl.value?.focus({ preventScroll: true })
319
+ begin(e)
320
+ }
321
+ }
322
+
323
+ function onPointerMove(e: PointerEvent) {
324
+ if (!press || e.pointerId !== press.id) return
325
+ if (!press.started) {
326
+ const dx = Math.abs(e.clientX - press.x)
327
+ const dy = Math.abs(e.clientY - press.y)
328
+ if (dy > 8 && dy > dx) return end()
329
+ if (dx < 4) return
330
+ begin(e)
331
+ }
332
+ scrubTo(timeAt(e.clientX))
333
+ }
334
+
335
+ function onPointerUp(e: PointerEvent) {
336
+ if (!press || e.pointerId !== press.id) return
337
+ const t = press.started ? scrubTime.value ?? timeAt(e.clientX) : timeAt(e.clientX)
338
+ end()
339
+ commit(t)
340
+ }
341
+
342
+ // The browser took the touch (a scroll): a drag in progress still lands where it was
343
+ function onPointerCancel(e: PointerEvent) {
344
+ if (!press || e.pointerId !== press.id) return
345
+ const t = press.started ? scrubTime.value : null
346
+ end()
347
+ if (t !== null) commit(t)
348
+ }
349
+
350
+ function end() {
351
+ press = null
352
+ pressed.value = false
353
+ scrubTime.value = null
354
+ window.removeEventListener('pointermove', onPointerMove)
355
+ window.removeEventListener('pointerup', onPointerUp)
356
+ window.removeEventListener('pointercancel', onPointerCancel)
357
+ }
358
+
359
+ function onHover(e: PointerEvent) {
360
+ if (e.pointerType === 'touch') return
361
+ hovered.value = true
362
+ hoverTime.value = timeAt(e.clientX)
363
+ }
364
+ function onLeave() {
365
+ hovered.value = false
366
+ hoverTime.value = null
367
+ }
368
+
369
+ function onKeyDown(e: KeyboardEvent) {
370
+ if (inactive.value) return
371
+ const d = dur.value
372
+ const steps: Record<string, number> = {
373
+ ArrowRight: props.keyStep, ArrowUp: props.keyStep, ArrowLeft: -props.keyStep, ArrowDown: -props.keyStep,
374
+ PageUp: d / 10, PageDown: -d / 10,
375
+ }
376
+ let t: number | null = null
377
+ if (e.key in steps) t = current.value + steps[e.key]!
378
+ else if (e.key === 'Home') t = 0
379
+ else if (e.key === 'End') t = d
380
+ if (t === null) return
381
+ e.preventDefault()
382
+ commit(Math.min(d, Math.max(0, t)))
383
+ }
384
+
385
+ // ── Motion between updates, and the wave (a rAF loop, only while either needs frames) ───────────────────
386
+ const now = () => (typeof performance !== 'undefined' ? performance.now() : 0)
387
+ let base = props.modelValue
388
+ let baseAt = now()
389
+ let raf = 0
390
+ let last = 0
391
+ let amp = 0
392
+ let phase = 0
393
+ const wavePathEl = ref<SVGPathElement>()
394
+ const svgH = computed(() => s.value.wave + 2 * s.value.amp + 2)
395
+ const reducedMotion = typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
396
+
397
+ const ampTarget = () => (props.variant === 'wavy' && props.playing && scrubTime.value === null ? s.value.amp : 0)
398
+ amp = ampTarget()
399
+
400
+ function advancing() {
401
+ return props.playing && scrubTime.value === null && !!dur.value
402
+ }
403
+
404
+ function syncPos(t: number) {
405
+ const W = width.value
406
+ const d = dur.value
407
+ if (Math.floor(t) !== Math.floor(pos.value) || (d && (Math.abs(t - pos.value) * W) / d >= 0.5)) pos.value = t
408
+ }
409
+
410
+ function drawWave() {
411
+ const path = wavePathEl.value
412
+ if (!path) return
413
+ const { wave, length, gap } = s.value
414
+ const half = wave / 2
415
+ const end = thumbX.value - gap - half
416
+ if (end <= half) return path.setAttribute('d', '')
417
+ const mid = svgH.value / 2
418
+ const k = (2 * Math.PI) / length
419
+ let d = ''
420
+ for (let x = half; ; x += 2) {
421
+ const px = Math.min(x, end)
422
+ d += `${d ? 'L' : 'M'}${px.toFixed(1)},${(mid + amp * Math.sin(k * px + phase)).toFixed(2)}`
423
+ if (px >= end) break
424
+ }
425
+ path.setAttribute('d', d)
426
+ }
427
+
428
+ function frame(t: number) {
429
+ const dt = last ? Math.min(0.1, (t - last) / 1000) : 0
430
+ last = t
431
+ if (advancing()) syncPos(Math.min(dur.value, base + ((t - baseAt) / 1000) * props.playbackRate))
432
+ if (props.variant === 'wavy') {
433
+ amp += (ampTarget() - amp) * (1 - Math.exp(-dt / 0.12))
434
+ if (Math.abs(ampTarget() - amp) < 0.01) amp = ampTarget()
435
+ // The wave travels with the playback, one length every 1.25s
436
+ if (props.playing && !reducedMotion) phase -= (dt * 2 * Math.PI) / 1.25
437
+ drawWave()
438
+ }
439
+ if (advancing() || (props.variant === 'wavy' && (amp !== ampTarget() || (props.playing && !reducedMotion)))) {
440
+ raf = requestAnimationFrame(frame)
441
+ } else {
442
+ raf = 0
443
+ last = 0
444
+ }
445
+ }
446
+
447
+ function kick() {
448
+ if (raf || typeof requestAnimationFrame === 'undefined') return
449
+ raf = requestAnimationFrame(frame)
450
+ }
451
+
452
+ watch(() => props.modelValue, (v) => {
453
+ base = v
454
+ baseAt = now()
455
+ pos.value = v
456
+ kick()
457
+ })
458
+ watch(() => props.playing, () => {
459
+ base = pos.value
460
+ baseAt = now()
461
+ kick()
462
+ })
463
+ watch(scrubTime, (v) => {
464
+ if (v === null) {
465
+ base = pos.value
466
+ baseAt = now()
467
+ }
468
+ kick()
469
+ })
470
+ // Paused, the (flat) wave still follows the thumb
471
+ watch([thumbX, () => props.variant, () => props.size], () => {
472
+ if (props.variant === 'wavy') drawWave()
473
+ }, { flush: 'post' })
474
+
475
+ let resizeObserver: ResizeObserver | null = null
476
+ onMounted(() => {
477
+ const el = trackEl.value!
478
+ width.value = el.clientWidth
479
+ if (typeof ResizeObserver !== 'undefined') {
480
+ resizeObserver = new ResizeObserver(() => { width.value = el.clientWidth })
481
+ resizeObserver.observe(el)
482
+ }
483
+ drawWave()
484
+ kick()
485
+ })
486
+ onBeforeUnmount(() => {
487
+ cancelAnimationFrame(raf)
488
+ resizeObserver?.disconnect()
489
+ bubbleObserver?.disconnect()
490
+ end()
491
+ })
492
+ </script>
493
+
494
+ <template>
495
+ <div class="flex min-w-0 select-none" :class="time === 'sides' ? 'items-center gap-3' : 'flex-col'">
496
+ <span v-if="time === 'sides'" class="min-w-[4ch] shrink-0 text-right text-label-medium tabular-nums" :class="!timeColor && 'text-on-surface-variant'" :style="timeStyle">{{ startText }}</span>
497
+
498
+ <div
499
+ ref="trackEl"
500
+ role="slider"
501
+ :tabindex="inactive ? -1 : 0"
502
+ :aria-label="label ?? locale.seekBar"
503
+ aria-valuemin="0"
504
+ :aria-valuemax="Math.round(dur)"
505
+ :aria-valuenow="Math.round(current)"
506
+ :aria-valuetext="valueText"
507
+ :aria-disabled="inactive || undefined"
508
+ class="group relative min-w-0 shrink-0 touch-pan-y outline-none"
509
+ :class="[inactive ? 'cursor-default' : 'cursor-pointer', time === 'sides' && 'flex-1']"
510
+ :style="{ height: `${s.hit}px` }"
511
+ @pointerdown="onPointerDown"
512
+ @pointermove="onHover"
513
+ @pointerleave="onLeave"
514
+ @keydown="onKeyDown"
515
+ @focus="focused = true"
516
+ @blur="focused = false"
517
+ >
518
+ <!-- A grace zone past the hit area (mostly above, where the preview opens), so the pointer doesn't have to
519
+ land exactly on a thin line: its events reach the track like the track's own -->
520
+ <div v-if="!inactive" class="absolute inset-x-0 -top-3 -bottom-1" />
521
+ <div
522
+ v-for="(p, i) in pieces"
523
+ :key="i"
524
+ class="absolute top-1/2 -translate-y-1/2 overflow-hidden transition-[height] duration-100"
525
+ :style="{
526
+ left: `${p.a}px`, width: `${p.b - p.a}px`, height: `${trackH}px`,
527
+ borderRadius: `${p.rl}px ${p.rr}px ${p.rr}px ${p.rl}px`, backgroundColor: colors.inactive,
528
+ }"
529
+ >
530
+ <div
531
+ v-for="(f, j) in p.fills"
532
+ :key="j"
533
+ class="absolute inset-y-0"
534
+ :style="{ left: `${f.left}px`, width: `${f.width}px`, backgroundColor: f.color }"
535
+ />
536
+ </div>
537
+
538
+ <svg
539
+ v-if="variant === 'wavy'"
540
+ class="pointer-events-none absolute top-1/2 left-0 -translate-y-1/2 overflow-visible"
541
+ :width="width"
542
+ :height="svgH"
543
+ aria-hidden="true"
544
+ >
545
+ <path ref="wavePathEl" fill="none" :stroke="colors.active" :stroke-width="s.wave" stroke-linecap="round" />
546
+ </svg>
547
+
548
+ <div
549
+ v-if="stopDot"
550
+ class="pointer-events-none absolute top-1/2 right-3 size-1 -translate-y-1/2 rounded-full"
551
+ :style="{ backgroundColor: colors.active }"
552
+ />
553
+
554
+ <div
555
+ class="pointer-events-none absolute top-1/2 transition-transform duration-75 group-focus-visible:ring-2 group-focus-visible:ring-primary group-focus-visible:ring-offset-2 group-focus-visible:ring-offset-surface"
556
+ :style="thumbStyle"
557
+ />
558
+
559
+ <div
560
+ v-if="previewTime !== null"
561
+ ref="bubbleEl"
562
+ class="pointer-events-none absolute bottom-full z-10 mb-1 -translate-x-1/2"
563
+ :style="{ left: `${previewX}px` }"
564
+ >
565
+ <slot name="preview" :time="previewTime" :formatted="fmt(previewTime)" :chapter="previewChapter">
566
+ <div class="flex h-7 max-w-60 items-center gap-1 rounded-full bg-inverse-surface px-2.5 text-label-medium whitespace-nowrap text-inverse-on-surface tabular-nums">
567
+ <span v-if="previewChapter?.title" class="truncate">{{ previewChapter.title }} ·</span>
568
+ <span>{{ fmt(previewTime) }}</span>
569
+ </div>
570
+ </slot>
571
+ </div>
572
+ </div>
573
+
574
+ <div v-if="time === 'below'" class="flex items-center justify-between text-label-medium tabular-nums" :class="!timeColor && 'text-on-surface-variant'" :style="timeStyle">
575
+ <span>{{ startText }}</span>
576
+ <button
577
+ type="button"
578
+ class="cursor-pointer rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-secondary"
579
+ :aria-label="showRemaining ? locale.seekBarShowDuration : locale.seekBarShowRemaining"
580
+ @click="toggleRemaining"
581
+ >{{ endText }}</button>
582
+ </div>
583
+ <button
584
+ v-else-if="time === 'sides'"
585
+ type="button"
586
+ class="min-w-[4ch] shrink-0 cursor-pointer rounded-sm text-left text-label-medium tabular-nums outline-none focus-visible:ring-2 focus-visible:ring-secondary"
587
+ :class="!timeColor && 'text-on-surface-variant'"
588
+ :style="timeStyle"
589
+ :aria-label="showRemaining ? locale.seekBarShowDuration : locale.seekBarShowRemaining"
590
+ @click="toggleRemaining"
591
+ >{{ endText }}</button>
592
+ </div>
593
+ </template>
@@ -9,6 +9,7 @@ import MIcon from './MIcon.vue'
9
9
  import MIconButton from './MIconButton.vue'
10
10
  import { useFieldBg } from '../composables/useFieldBg'
11
11
  import { useLocale } from '../composables/useLocale'
12
+ import { useScrollLock } from '../composables/_useScrollLock'
12
13
 
13
14
  export interface SelectOption {
14
15
  label: string
@@ -147,13 +148,7 @@ function onKeydown(e: KeyboardEvent) {
147
148
  }
148
149
  }
149
150
 
150
- watch(modalOpen, (v) => {
151
- if (v) {
152
- document.body.style.overflow = 'hidden'
153
- } else {
154
- document.body.style.overflow = ''
155
- }
156
- })
151
+ useScrollLock(modalOpen)
157
152
 
158
153
  function closeModal() { modalOpen.value = false }
159
154
 
@@ -164,7 +159,6 @@ onMounted(() => {
164
159
  onUnmounted(() => {
165
160
  document.removeEventListener('mousedown', onOutsideClick)
166
161
  window.removeEventListener('scroll', onScroll, true)
167
- document.body.style.overflow = ''
168
162
  })
169
163
 
170
164
  const triggerClasses = computed(() => {
@@ -9,6 +9,7 @@
9
9
  import { computed, onMounted, onUnmounted, ref } from 'vue'
10
10
  import MIcon from './MIcon.vue'
11
11
  import { vRipple } from '../directives/vRipple'
12
+ import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
12
13
 
13
14
  export interface SplitButtonItem {
14
15
  label: string
@@ -114,23 +115,36 @@ const buttonStateClasses = computed(() => {
114
115
  ]
115
116
  })
116
117
 
118
+ // At least as wide as the button, at the window's left edge until placeMenu() can measure it (once it's in the
119
+ // DOM, before it paints) and keep it on screen (see _popupPosition.ts): under the button, aligned with its start
120
+ // edge, else its end edge or the window edge; above it when it doesn't fit below
121
+ let anchorRect: DOMRect | null = null
117
122
  function computeMenuPos() {
118
123
  if (!containerEl.value) return
119
124
  const rect = containerEl.value.getBoundingClientRect()
120
- const menuH = (props.items?.length ?? 0) * 44 + 16
121
- const spaceBelow = window.innerHeight - rect.bottom - 8
122
- const above = spaceBelow < menuH && rect.top > menuH
125
+ anchorRect = rect
123
126
  menuStyle.value = {
124
127
  position: 'fixed',
125
128
  zIndex: '500',
126
- left: `${rect.left}px`,
129
+ left: '0px',
130
+ top: `${rect.bottom + 4}px`,
127
131
  minWidth: `${rect.width}px`,
128
- ...(above
129
- ? { bottom: `${window.innerHeight - rect.top + 4}px` }
130
- : { top: `${rect.bottom + 4}px` }),
132
+ maxWidth: `${window.innerWidth - 2 * POPUP_MARGIN}px`,
131
133
  }
132
134
  }
133
135
 
136
+ function placeMenu(el: Element) {
137
+ if (!anchorRect) return
138
+ const menu = el as HTMLElement
139
+ const w = menu.offsetWidth
140
+ const h = menu.offsetHeight
141
+ const left = dropdownX(anchorRect, w, window.innerWidth, 'start')
142
+ const top = fitPopup([anchorRect.bottom + 4, anchorRect.top - 4 - h], h, window.innerHeight)
143
+ menuStyle.value = { ...menuStyle.value, left: `${left}px`, top: `${top}px` }
144
+ menu.style.left = `${left}px`
145
+ menu.style.top = `${top}px`
146
+ }
147
+
134
148
  function toggleMenu() {
135
149
  if (props.disabled) return
136
150
  if (!open.value) computeMenuPos()
@@ -217,6 +231,7 @@ onUnmounted(() => {
217
231
  enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
218
232
  leave-active-class="transition-[opacity,transform] duration-100"
219
233
  leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
234
+ @enter="placeMenu"
220
235
  >
221
236
  <div
222
237
  v-if="open && items?.length"
@@ -245,6 +260,7 @@ onUnmounted(() => {
245
260
  enter-from-class="opacity-0 -translate-y-1 scale-[0.98]"
246
261
  leave-active-class="transition-[opacity,transform] duration-100"
247
262
  leave-to-class="opacity-0 -translate-y-1 scale-[0.98]"
263
+ @enter="placeMenu"
248
264
  >
249
265
  <div
250
266
  v-if="open && !items?.length && $slots.menu"