@m3ui-vue/m3ui-vue 0.8.8 → 0.9.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 (375) hide show
  1. package/README.md +25 -5
  2. package/dist/API.md +3661 -0
  3. package/dist/MIcon-CaEooCmZ.js.map +1 -1
  4. package/dist/{MMenuItem-5xojJYAL.js → MTextField-pJU1vFaR.js} +374 -364
  5. package/dist/MTextField-pJU1vFaR.js.map +1 -0
  6. package/dist/api.json +1 -0
  7. package/dist/barcode.js +9 -11
  8. package/dist/barcode.js.map +1 -1
  9. package/dist/chart.js.map +1 -1
  10. package/dist/code-editor.js +2 -2
  11. package/dist/code-editor.js.map +1 -1
  12. package/dist/components/MAbsolute.vue.d.ts +12 -0
  13. package/dist/components/MAlert.vue.d.ts +4 -0
  14. package/dist/components/MAppBar.vue.d.ts +12 -0
  15. package/dist/components/MAppLayout.vue.d.ts +2 -0
  16. package/dist/components/MAspectRatio.vue.d.ts +1 -0
  17. package/dist/components/MAutocomplete.vue.d.ts +18 -0
  18. package/dist/components/MAvatar.vue.d.ts +3 -0
  19. package/dist/components/MBadge.vue.d.ts +6 -0
  20. package/dist/components/MBar.vue.d.ts +5 -0
  21. package/dist/components/MBarcode.vue.d.ts +9 -0
  22. package/dist/components/MBottomSheet.vue.d.ts +3 -0
  23. package/dist/components/MBox.vue.d.ts +6 -0
  24. package/dist/components/MBreadcrumbs.vue.d.ts +2 -0
  25. package/dist/components/MButton.vue.d.ts +14 -4
  26. package/dist/components/MButtonGroup.vue.d.ts +7 -0
  27. package/dist/components/MCalendar.vue.d.ts +8 -0
  28. package/dist/components/MCard.vue.d.ts +17 -0
  29. package/dist/components/MCarousel.vue.d.ts +61 -36
  30. package/dist/components/MCenter.vue.d.ts +1 -0
  31. package/dist/components/MChart.vue.d.ts +7 -0
  32. package/dist/components/MChatBubble.vue.d.ts +10 -0
  33. package/dist/components/MCheckbox.vue.d.ts +5 -0
  34. package/dist/components/MChip.vue.d.ts +9 -0
  35. package/dist/components/MCircleProgressBar.vue.d.ts +7 -0
  36. package/dist/components/MCodeEditor.vue.d.ts +9 -0
  37. package/dist/components/MColorPicker.vue.d.ts +8 -0
  38. package/dist/components/MColorPickerModal.vue.d.ts +4 -0
  39. package/dist/components/MCommandPalette.vue.d.ts +8 -0
  40. package/dist/components/MConfirmDialog.vue.d.ts +7 -0
  41. package/dist/components/MContainer.vue.d.ts +4 -0
  42. package/dist/components/MContextMenu.vue.d.ts +3 -6
  43. package/dist/components/MCopyButton.vue.d.ts +10 -0
  44. package/dist/components/MDataTable.vue.d.ts +33 -12
  45. package/dist/components/MDatePicker.vue.d.ts +16 -0
  46. package/dist/components/MDatePickerModal.vue.d.ts +9 -0
  47. package/dist/components/MDateRangePicker.vue.d.ts +18 -0
  48. package/dist/components/MDateRangePickerModal.vue.d.ts +9 -0
  49. package/dist/components/MDialog.vue.d.ts +10 -6
  50. package/dist/components/MDivider.vue.d.ts +6 -0
  51. package/dist/components/MDragDropList.vue.d.ts +6 -0
  52. package/dist/components/MEmoji.vue.d.ts +6 -0
  53. package/dist/components/MEmojiButton.vue.d.ts +5 -0
  54. package/dist/components/MEmojiSelector.vue.d.ts +21 -5
  55. package/dist/components/MEmptyState.vue.d.ts +4 -0
  56. package/dist/components/MExpansionPanel.vue.d.ts +9 -0
  57. package/dist/components/MExportButton.vue.d.ts +8 -0
  58. package/dist/components/MFab.vue.d.ts +9 -0
  59. package/dist/components/MFabMenu.vue.d.ts +15 -1
  60. package/dist/components/MFileUpload.vue.d.ts +8 -0
  61. package/dist/components/MFixed.vue.d.ts +10 -0
  62. package/dist/components/MFlex.vue.d.ts +7 -1
  63. package/dist/components/MFooter.vue.d.ts +11 -0
  64. package/dist/components/MFullscreen.vue.d.ts +2 -0
  65. package/dist/components/MGrid.vue.d.ts +7 -0
  66. package/dist/components/MHotkeys.vue.d.ts +4 -0
  67. package/dist/components/MIcon.vue.d.ts +2 -0
  68. package/dist/components/MIconButton.vue.d.ts +10 -0
  69. package/dist/components/MInfiniteScroll.vue.d.ts +6 -0
  70. package/dist/components/MJsonEditor.vue.d.ts +8 -0
  71. package/dist/components/MJsonViewer.vue.d.ts +4 -0
  72. package/dist/components/MKanban.vue.d.ts +2 -0
  73. package/dist/components/MKbd.vue.d.ts +2 -0
  74. package/dist/components/MLightbox.vue.d.ts +19 -5
  75. package/dist/components/MList.vue.d.ts +7 -0
  76. package/dist/components/MListItem.vue.d.ts +24 -0
  77. package/dist/components/MListSubheader.vue.d.ts +6 -0
  78. package/dist/components/MLoadingIndicator.vue.d.ts +10 -0
  79. package/dist/components/MLoadingOverlay.vue.d.ts +5 -0
  80. package/dist/components/MMarkdown.vue.d.ts +3 -0
  81. package/dist/components/MMaskField.vue.d.ts +15 -0
  82. package/dist/components/MMasonry.vue.d.ts +5 -0
  83. package/dist/components/MMenu.vue.d.ts +3 -6
  84. package/dist/components/MMenuDivider.vue.d.ts +4 -0
  85. package/dist/components/MMenuItem.vue.d.ts +5 -0
  86. package/dist/components/MMultiAutocomplete.vue.d.ts +20 -0
  87. package/dist/components/MMultiSelect.vue.d.ts +21 -0
  88. package/dist/components/MNavigationBar.vue.d.ts +2 -0
  89. package/dist/components/MNavigationDrawer.vue.d.ts +11 -0
  90. package/dist/components/MNavigationRail.vue.d.ts +9 -6
  91. package/dist/components/MNavigationSuite.vue.d.ts +5 -3
  92. package/dist/components/MNumberField.vue.d.ts +17 -0
  93. package/dist/components/MOverlay.vue.d.ts +3 -0
  94. package/dist/components/MPageProgress.vue.d.ts +3 -0
  95. package/dist/components/MPagination.vue.d.ts +3 -0
  96. package/dist/components/MPasswordMeter.vue.d.ts +1 -0
  97. package/dist/components/MPinInput.vue.d.ts +11 -0
  98. package/dist/components/MProgressBar.vue.d.ts +6 -0
  99. package/dist/components/MPullToRefresh.vue.d.ts +8 -0
  100. package/dist/components/MQRCode.vue.d.ts +6 -0
  101. package/dist/components/MRadio.vue.d.ts +5 -0
  102. package/dist/components/MRadioGroup.vue.d.ts +6 -0
  103. package/dist/components/MRating.vue.d.ts +11 -0
  104. package/dist/components/MRelativeTime.vue.d.ts +1 -0
  105. package/dist/components/MResponsive.vue.d.ts +3 -0
  106. package/dist/components/MResult.vue.d.ts +6 -0
  107. package/dist/components/MRichTextEditor.vue.d.ts +8 -0
  108. package/dist/components/MScheduler.vue.d.ts +48 -1
  109. package/dist/components/MScrollable.vue.d.ts +3 -0
  110. package/dist/components/MSearchBar.vue.d.ts +6 -0
  111. package/dist/components/MSection.vue.d.ts +5 -0
  112. package/dist/components/MSegmentedButton.vue.d.ts +5 -0
  113. package/dist/components/MSelect.vue.d.ts +17 -0
  114. package/dist/components/MShader.vue.d.ts +1 -0
  115. package/dist/components/MShape.vue.d.ts +1 -1
  116. package/dist/components/MShortNavigationBar.vue.d.ts +8 -9
  117. package/dist/components/MSideSheet.vue.d.ts +3 -0
  118. package/dist/components/MSignaturePad.vue.d.ts +7 -0
  119. package/dist/components/MSimpleCarousel.vue.d.ts +12 -2
  120. package/dist/components/MSkeleton.vue.d.ts +8 -0
  121. package/dist/components/MSlider.vue.d.ts +15 -1
  122. package/dist/components/MSnackbar.vue.d.ts +1 -0
  123. package/dist/components/MSpinner.vue.d.ts +6 -0
  124. package/dist/components/MSplitButton.vue.d.ts +7 -0
  125. package/dist/components/MSplitter.vue.d.ts +4 -0
  126. package/dist/components/MSpotlightSearch.vue.d.ts +18 -0
  127. package/dist/components/MStack.vue.d.ts +8 -1
  128. package/dist/components/MStatCard.vue.d.ts +7 -0
  129. package/dist/components/MStepper.vue.d.ts +7 -0
  130. package/dist/components/MSticky.vue.d.ts +2 -0
  131. package/dist/components/MSubtitle.vue.d.ts +4 -0
  132. package/dist/components/MSwitch.vue.d.ts +5 -6
  133. package/dist/components/MTable.vue.d.ts +17 -4
  134. package/dist/components/MTabs.vue.d.ts +6 -0
  135. package/dist/components/MTagInput.vue.d.ts +17 -0
  136. package/dist/components/MTerminal.vue.d.ts +4 -0
  137. package/dist/components/MText.vue.d.ts +10 -0
  138. package/dist/components/MTextField.vue.d.ts +18 -0
  139. package/dist/components/MTimePicker.vue.d.ts +10 -0
  140. package/dist/components/MTimePickerModal.vue.d.ts +5 -0
  141. package/dist/components/MTimeline.vue.d.ts +3 -0
  142. package/dist/components/MTitle.vue.d.ts +4 -0
  143. package/dist/components/MToggleButton.vue.d.ts +4 -0
  144. package/dist/components/MToolbar.vue.d.ts +6 -1
  145. package/dist/components/MTooltip.vue.d.ts +7 -0
  146. package/dist/components/MTopAppBar.vue.d.ts +8 -0
  147. package/dist/components/MTour.vue.d.ts +5 -0
  148. package/dist/components/MTransferList.vue.d.ts +11 -0
  149. package/dist/components/MTree.vue.d.ts +11 -0
  150. package/dist/components/MTreeTable.vue.d.ts +7 -0
  151. package/dist/components/MVirtualTable.vue.d.ts +6 -0
  152. package/dist/components/MWindow.vue.d.ts +33 -1
  153. package/dist/composables/_carouselStrategy.d.ts +101 -0
  154. package/dist/composables/useLocale.d.ts +21 -0
  155. package/dist/data/emoji-names/emoji-names-de.d.ts +2 -0
  156. package/dist/data/emoji-names/emoji-names-en.d.ts +2 -0
  157. package/dist/data/emoji-names/emoji-names-es.d.ts +2 -0
  158. package/dist/data/emoji-names/emoji-names-fr.d.ts +2 -0
  159. package/dist/data/emoji-names/emoji-names-ja.d.ts +2 -0
  160. package/dist/data/emoji-names/emoji-names-ko.d.ts +2 -0
  161. package/dist/data/emoji-names/emoji-names-pt.d.ts +2 -0
  162. package/dist/data/emoji-names/emoji-names-zh.d.ts +2 -0
  163. package/dist/data/emojis.d.ts +7 -1
  164. package/dist/emoji-names-de-BphO5XpV.js +1877 -0
  165. package/dist/emoji-names-de-BphO5XpV.js.map +1 -0
  166. package/dist/emoji-names-en-9ZvMRvzi.js +1877 -0
  167. package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -0
  168. package/dist/emoji-names-es-DvfWU3Pj.js +1877 -0
  169. package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -0
  170. package/dist/emoji-names-fr-B-jhUlsP.js +1877 -0
  171. package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -0
  172. package/dist/emoji-names-ja-l8cMFJo1.js +1877 -0
  173. package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -0
  174. package/dist/emoji-names-ko-YP-o9G0c.js +1877 -0
  175. package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -0
  176. package/dist/emoji-names-pt-DGj_Js4M.js +1877 -0
  177. package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -0
  178. package/dist/emoji-names-zh-Dzecwtw_.js +1877 -0
  179. package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -0
  180. package/dist/index.d.ts +2 -2
  181. package/dist/locales/index.js +140 -7
  182. package/dist/locales/index.js.map +1 -1
  183. package/dist/m3ui-vue.css +1 -1
  184. package/dist/m3ui.js +6642 -5160
  185. package/dist/m3ui.js.map +1 -1
  186. package/dist/markdown.js +1 -1
  187. package/dist/markdown.js.map +1 -1
  188. package/dist/plugin.d.ts +6 -0
  189. package/dist/qrcode.js.map +1 -1
  190. package/dist/rich-text-editor.js +10 -10
  191. package/dist/rich-text-editor.js.map +1 -1
  192. package/dist/styles.css +1 -1
  193. package/dist/terminal.js +34 -27
  194. package/dist/terminal.js.map +1 -1
  195. package/dist/{useLocale-D3ZWZ8jY.js → useLocale-Drihe5G2.js} +33 -11
  196. package/dist/useLocale-Drihe5G2.js.map +1 -0
  197. package/package.json +4 -2
  198. package/src/__tests__/MCarousel.test.ts +183 -21
  199. package/src/__tests__/MDialog.test.ts +18 -0
  200. package/src/__tests__/MEmojiSelector.test.ts +138 -0
  201. package/src/__tests__/MHotkeys.test.ts +57 -0
  202. package/src/__tests__/MLightbox.test.ts +313 -5
  203. package/src/__tests__/MScheduler.test.ts +122 -0
  204. package/src/__tests__/MTerminal.test.ts +63 -0
  205. package/src/__tests__/attrsFallthrough.test.ts +65 -0
  206. package/src/__tests__/hostLocale.test.ts +57 -0
  207. package/src/__tests__/plugin.test.ts +28 -1
  208. package/src/components/MAbsolute.vue +18 -0
  209. package/src/components/MAlert.vue +12 -0
  210. package/src/components/MAppBar.vue +12 -0
  211. package/src/components/MAppLayout.vue +11 -0
  212. package/src/components/MAspectRatio.vue +6 -0
  213. package/src/components/MAutocomplete.vue +24 -0
  214. package/src/components/MAvatar.vue +12 -1
  215. package/src/components/MBadge.vue +11 -0
  216. package/src/components/MBar.vue +19 -0
  217. package/src/components/MBarcode.vue +18 -2
  218. package/src/components/MBottomSheet.vue +13 -1
  219. package/src/components/MBox.vue +12 -0
  220. package/src/components/MBreadcrumbs.vue +7 -0
  221. package/src/components/MButton.vue +22 -4
  222. package/src/components/MButtonGroup.vue +13 -0
  223. package/src/components/MCalendar.vue +14 -0
  224. package/src/components/MCard.vue +26 -0
  225. package/src/components/MCarousel.vue +542 -200
  226. package/src/components/MCenter.vue +6 -0
  227. package/src/components/MChart.vue +12 -0
  228. package/src/components/MChatBubble.vue +17 -0
  229. package/src/components/MCheckbox.vue +11 -0
  230. package/src/components/MChip.vue +17 -0
  231. package/src/components/MCircleProgressBar.vue +13 -0
  232. package/src/components/MCodeEditor.vue +18 -2
  233. package/src/components/MColorPicker.vue +13 -0
  234. package/src/components/MColorPickerModal.vue +12 -0
  235. package/src/components/MCommandPalette.vue +17 -1
  236. package/src/components/MConfirmDialog.vue +15 -0
  237. package/src/components/MContainer.vue +9 -0
  238. package/src/components/MContextMenu.vue +20 -7
  239. package/src/components/MCopyButton.vue +16 -0
  240. package/src/components/MDataTable.vue +58 -12
  241. package/src/components/MDatePicker.vue +21 -0
  242. package/src/components/MDatePickerModal.vue +17 -1
  243. package/src/components/MDateRangePicker.vue +23 -0
  244. package/src/components/MDateRangePickerModal.vue +17 -1
  245. package/src/components/MDialog.vue +43 -10
  246. package/src/components/MDivider.vue +6 -0
  247. package/src/components/MDragDropList.vue +18 -0
  248. package/src/components/MEmoji.vue +6 -0
  249. package/src/components/MEmojiButton.vue +11 -0
  250. package/src/components/MEmojiSelector.vue +486 -78
  251. package/src/components/MEmptyState.vue +9 -0
  252. package/src/components/MExpansionPanel.vue +17 -0
  253. package/src/components/MExportButton.vue +15 -0
  254. package/src/components/MFab.vue +20 -1
  255. package/src/components/MFabMenu.vue +20 -0
  256. package/src/components/MFileUpload.vue +19 -0
  257. package/src/components/MFixed.vue +16 -0
  258. package/src/components/MFlex.vue +11 -0
  259. package/src/components/MFooter.vue +11 -0
  260. package/src/components/MFullscreen.vue +8 -0
  261. package/src/components/MGrid.vue +12 -0
  262. package/src/components/MHotkeys.vue +20 -13
  263. package/src/components/MIcon.vue +10 -1
  264. package/src/components/MIconButton.vue +13 -0
  265. package/src/components/MInfiniteScroll.vue +16 -0
  266. package/src/components/MJsonEditor.vue +13 -0
  267. package/src/components/MJsonViewer.vue +7 -0
  268. package/src/components/MKanban.vue +18 -0
  269. package/src/components/MKbd.vue +6 -0
  270. package/src/components/MLightbox.vue +766 -268
  271. package/src/components/MList.vue +15 -0
  272. package/src/components/MListDetail.vue +11 -0
  273. package/src/components/MListItem.vue +37 -0
  274. package/src/components/MListSubheader.vue +6 -0
  275. package/src/components/MLoadingIndicator.vue +15 -0
  276. package/src/components/MLoadingOverlay.vue +18 -1
  277. package/src/components/MMarkdown.vue +7 -0
  278. package/src/components/MMaskField.vue +21 -0
  279. package/src/components/MMasonry.vue +11 -0
  280. package/src/components/MMenu.vue +19 -7
  281. package/src/components/MMenuDivider.vue +4 -0
  282. package/src/components/MMenuItem.vue +16 -0
  283. package/src/components/MMultiAutocomplete.vue +26 -0
  284. package/src/components/MMultiSelect.vue +27 -0
  285. package/src/components/MNavigationBar.vue +7 -0
  286. package/src/components/MNavigationDrawer.vue +30 -1
  287. package/src/components/MNavigationRail.vue +27 -6
  288. package/src/components/MNavigationSuite.vue +20 -3
  289. package/src/components/MNotificationHost.vue +3 -0
  290. package/src/components/MNumberField.vue +24 -0
  291. package/src/components/MOverlay.vue +11 -0
  292. package/src/components/MPageProgress.vue +7 -0
  293. package/src/components/MPagination.vue +15 -1
  294. package/src/components/MPasswordMeter.vue +7 -0
  295. package/src/components/MPinInput.vue +19 -0
  296. package/src/components/MProgressBar.vue +9 -0
  297. package/src/components/MPullToRefresh.vue +17 -0
  298. package/src/components/MQRCode.vue +12 -0
  299. package/src/components/MRadio.vue +11 -0
  300. package/src/components/MRadioGroup.vue +11 -0
  301. package/src/components/MRating.vue +19 -0
  302. package/src/components/MRelative.vue +8 -0
  303. package/src/components/MRelativeTime.vue +6 -0
  304. package/src/components/MResponsive.vue +9 -0
  305. package/src/components/MResult.vue +14 -0
  306. package/src/components/MRichTextEditor.vue +14 -0
  307. package/src/components/MScheduler.vue +303 -115
  308. package/src/components/MScrollable.vue +8 -0
  309. package/src/components/MSearchBar.vue +17 -0
  310. package/src/components/MSection.vue +13 -0
  311. package/src/components/MSegmentedButton.vue +10 -0
  312. package/src/components/MSelect.vue +22 -0
  313. package/src/components/MShader.vue +13 -0
  314. package/src/components/MShape.vue +6 -0
  315. package/src/components/MShortNavigationBar.vue +23 -9
  316. package/src/components/MSideSheet.vue +14 -1
  317. package/src/components/MSignaturePad.vue +15 -0
  318. package/src/components/MSimpleCarousel.vue +18 -0
  319. package/src/components/MSkeleton.vue +8 -0
  320. package/src/components/MSlider.vue +21 -0
  321. package/src/components/MSnackbar.vue +5 -0
  322. package/src/components/MSpacer.vue +6 -0
  323. package/src/components/MSpinner.vue +10 -0
  324. package/src/components/MSplitButton.vue +17 -1
  325. package/src/components/MSplitter.vue +10 -0
  326. package/src/components/MSpotlightSearch.vue +28 -1
  327. package/src/components/MStack.vue +12 -0
  328. package/src/components/MStatCard.vue +13 -0
  329. package/src/components/MStepper.vue +12 -0
  330. package/src/components/MSticky.vue +7 -0
  331. package/src/components/MSubtitle.vue +9 -0
  332. package/src/components/MSupportingPane.vue +10 -0
  333. package/src/components/MSwitch.vue +14 -6
  334. package/src/components/MTable.vue +33 -4
  335. package/src/components/MTabs.vue +12 -0
  336. package/src/components/MTagInput.vue +23 -0
  337. package/src/components/MTerminal.vue +33 -10
  338. package/src/components/MText.vue +15 -0
  339. package/src/components/MTextField.vue +26 -0
  340. package/src/components/MTimePicker.vue +15 -0
  341. package/src/components/MTimePickerModal.vue +13 -1
  342. package/src/components/MTimeline.vue +7 -0
  343. package/src/components/MTitle.vue +9 -0
  344. package/src/components/MToggleButton.vue +12 -0
  345. package/src/components/MToolbar.vue +12 -0
  346. package/src/components/MTooltip.vue +18 -0
  347. package/src/components/MTopAppBar.vue +18 -0
  348. package/src/components/MTour.vue +15 -2
  349. package/src/components/MTransferList.vue +24 -0
  350. package/src/components/MTree.vue +11 -0
  351. package/src/components/MTreeTable.vue +15 -0
  352. package/src/components/MVirtualTable.vue +12 -0
  353. package/src/components/MWindow.vue +34 -0
  354. package/src/composables/_carouselStrategy.ts +712 -0
  355. package/src/composables/useLocale.ts +54 -3
  356. package/src/data/emoji-names/emoji-names-de.ts +1875 -0
  357. package/src/data/emoji-names/emoji-names-en.ts +1875 -0
  358. package/src/data/emoji-names/emoji-names-es.ts +1875 -0
  359. package/src/data/emoji-names/emoji-names-fr.ts +1875 -0
  360. package/src/data/emoji-names/emoji-names-ja.ts +1875 -0
  361. package/src/data/emoji-names/emoji-names-ko.ts +1875 -0
  362. package/src/data/emoji-names/emoji-names-pt.ts +1875 -0
  363. package/src/data/emoji-names/emoji-names-zh.ts +1875 -0
  364. package/src/data/emojis.ts +29 -198
  365. package/src/index.ts +2 -2
  366. package/src/locales/de.ts +19 -0
  367. package/src/locales/es.ts +19 -0
  368. package/src/locales/fr.ts +19 -0
  369. package/src/locales/ja.ts +19 -0
  370. package/src/locales/ko.ts +19 -0
  371. package/src/locales/pt.ts +19 -0
  372. package/src/locales/zh.ts +19 -0
  373. package/src/plugin.ts +14 -2
  374. package/dist/MMenuItem-5xojJYAL.js.map +0 -1
  375. package/dist/useLocale-D3ZWZ8jY.js.map +0 -1
@@ -1,6 +1,34 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed, watch, onMounted, onBeforeUnmount } from 'vue'
3
- import MIcon from './MIcon.vue'
2
+ /**
3
+ * A full-screen image viewer in the style of Google Photos. Images grow out of the picture you tapped and
4
+ * shrink back into it, you swipe between them with the next one already in view, zoom with a double tap or a
5
+ * pinch, and drag one down to close. Tapping the image hides the bars. Wrap your content and it finds the `<img>`
6
+ * elements by itself, or pass items.
7
+ *
8
+ * @slot default Content to scan for `<img>` elements when items is not given
9
+ * @slot actions Extra buttons in the top bar, for the image being shown (download, share, info…)
10
+ * @event update:modelValue Fires when the lightbox opens or closes
11
+ * @event update:index Fires whenever the current index changes (next/prev/goTo/auto-detected image click)
12
+ * @event change Fires alongside update:index with the new index
13
+ */
14
+ /*
15
+ * Full-screen image viewer. M3 has no lightbox component; the reference is Google Photos' viewer:
16
+ * a black stage, a top bar (close, position, actions) and a bottom area (caption, thumbnails) that
17
+ * a tap hides and shows, and gestures for everything.
18
+ *
19
+ * - Swipe between images on a track where the neighbors are already there (prev / current / next
20
+ * are rendered), velocity-aware; arrows and keys too.
21
+ * - Zoom: double tap / double click at a point, pinch, wheel; drag to pan while zoomed.
22
+ * - Drag the image down (or up) to dismiss, the backdrop fading as it goes.
23
+ * - Opens from and closes back into the image it came from when there is one (auto-scanned
24
+ * images, or `open(index, el)`); otherwise it scales and fades.
25
+ *
26
+ * Motion follows the library's convention: plain JS springs (Standard DefaultSpatial,
27
+ * dampingRatio 0.9 / stiffness 700) stepped in one rAF loop that writes transforms directly.
28
+ */
29
+ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
30
+ import MIconButton from './MIconButton.vue'
31
+ import MSpinner from './MSpinner.vue'
4
32
  import { useLocale } from '../composables/useLocale'
5
33
 
6
34
  export interface LightboxItem {
@@ -9,25 +37,28 @@ export interface LightboxItem {
9
37
  caption?: string
10
38
  }
11
39
 
12
- interface OriginRect {
13
- x: number
14
- y: number
15
- width: number
16
- height: number
17
- }
40
+ defineOptions({ inheritAttrs: false })
18
41
 
19
42
  const props = withDefaults(
20
43
  defineProps<{
44
+ /** v-model — open/closed state */
21
45
  modelValue?: boolean
22
46
  /** Explicit gallery. Omit it to auto-detect `<img>` elements rendered in the default slot instead. */
23
47
  items?: LightboxItem[]
48
+ /** v-model:index — current image index */
24
49
  index?: number
50
+ /** Wrap around when navigating past the first/last image */
25
51
  loop?: boolean
52
+ /** Overrides the close button aria-label (defaults to the active locale) */
26
53
  closeLabel?: string
27
54
  /** Show a row of clickable thumbnails at the bottom for jumping directly to an image. */
28
55
  showThumbnails?: boolean
29
- /** Round the corners of the main opened image (the thumbnail strip keeps its own fixed rounding). */
56
+ /** Round the corners of the opened image. */
30
57
  rounded?: boolean
58
+ /** Allow zooming (double tap / double click, pinch, wheel, + and - keys). */
59
+ zoom?: boolean
60
+ /** Largest zoom factor. */
61
+ maxZoom?: number
31
62
  }>(),
32
63
  {
33
64
  modelValue: false,
@@ -35,6 +66,8 @@ const props = withDefaults(
35
66
  loop: true,
36
67
  showThumbnails: false,
37
68
  rounded: true,
69
+ zoom: true,
70
+ maxZoom: 4,
38
71
  },
39
72
  )
40
73
 
@@ -44,217 +77,670 @@ const emit = defineEmits<{
44
77
  change: [index: number]
45
78
  }>()
46
79
 
80
+ defineSlots<{
81
+ default?: () => unknown
82
+ /** Extra buttons in the top bar (download, share, info…). */
83
+ actions?: (scope: { item: LightboxItem; index: number }) => unknown
84
+ }>()
85
+
47
86
  const locale = useLocale()
48
87
 
49
88
  const containerEl = ref<HTMLElement>()
50
- const stageImageEl = ref<HTMLElement>()
89
+ const rootEl = ref<HTMLElement>()
90
+ const stageEl = ref<HTMLElement>()
91
+ const thumbsEl = ref<HTMLElement>()
51
92
  const scannedItems = ref<LightboxItem[]>([])
52
- const isOpen = ref(props.modelValue)
93
+ const scannedEls: HTMLElement[] = []
94
+ /** Elements the viewer can open from / close into, by item index. */
95
+ const origins = new Map<number, HTMLElement>()
96
+
97
+ const rendered = ref(false)
53
98
  const currentIndex = ref(props.index)
54
- const direction = ref(1)
55
- // Set on open() when we have a clicked thumbnail to expand from (Discord-style); cleared once
56
- // the opening transition has played so later next()/prev() use the plain slide instead.
57
- const isFirstShow = ref(true)
58
- let originRect: OriginRect | null = null
99
+ const chrome = ref(true)
100
+ const zoomed = ref(false)
101
+ const loaded = ref(new Set<string>())
102
+ /** Width / height of each image, measured once it loads. */
103
+ const ratios = ref(new Map<string, number>())
104
+ /** The area an image can fill: the stage minus the slide's padding (p-4, sm:p-12). */
105
+ const box = ref({ w: 0, h: 0 })
59
106
 
60
107
  const galleryItems = computed(() => props.items ?? scannedItems.value)
108
+ const count = computed(() => galleryItems.value.length)
61
109
  const current = computed(() => galleryItems.value[currentIndex.value])
62
- const hasMultiple = computed(() => galleryItems.value.length > 1)
110
+ const hasMultiple = computed(() => count.value > 1)
63
111
 
64
- watch(() => props.modelValue, (v) => { isOpen.value = v })
65
- watch(() => props.index, (v) => { currentIndex.value = v })
112
+ function neighbor(i: number, delta: number) {
113
+ const n = i + delta
114
+ if (n >= 0 && n < count.value) return n
115
+ if (!props.loop || count.value < 2) return null
116
+ return (n + count.value) % count.value
117
+ }
118
+ const prevIndex = computed(() => neighbor(currentIndex.value, -1))
119
+ const nextIndex = computed(() => neighbor(currentIndex.value, 1))
120
+ // Current first in the DOM, then its neighbors (preloaded, ready for a swipe).
121
+ const slides = computed(() =>
122
+ [
123
+ { offset: 0, index: currentIndex.value },
124
+ { offset: 1, index: nextIndex.value },
125
+ { offset: -1, index: prevIndex.value },
126
+ ].filter((s): s is { offset: number; index: number } => s.index !== null && !!galleryItems.value[s.index]),
127
+ )
66
128
 
67
- function setIndex(i: number) {
68
- currentIndex.value = i
69
- emit('update:index', i)
70
- emit('change', i)
129
+ const positionLabel = computed(() =>
130
+ locale.carouselItem.replace('{index}', String(currentIndex.value + 1)).replace('{count}', String(count.value)),
131
+ )
132
+
133
+ // ── Springs ───────────────────────────────────────────────────────────────────────────────────
134
+
135
+ interface Spring { pos: number; vel: number; target: number; k: number; z: number }
136
+ const spring = (pos: number, k = 700, z = 0.9): Spring => ({ pos, vel: 0, target: pos, k, z })
137
+
138
+ const trackX = spring(0)
139
+ const dismissY = spring(0)
140
+ const scale = spring(1)
141
+ const panX = spring(0)
142
+ const panY = spring(0)
143
+ const intro = spring(0)
144
+ const backdrop = spring(0, 300, 1)
145
+ const springs = [trackX, dismissY, scale, panX, panY, intro, backdrop]
146
+
147
+ const GAP = 16
148
+ let stageW = 0
149
+ let stageH = 0
150
+ let raf = 0
151
+ let lastFrame = 0
152
+ let onSettled: (() => void) | null = null
153
+ /** The origin as a transform of the open image: offset, scale, and the crop that gives it the origin's shape. */
154
+ interface Origin { dx: number; dy: number; s: number; insetX: number; insetY: number; radius: number }
155
+ let introFrom: Origin | null = null
156
+ const reducedMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
157
+
158
+ function setNow(s: Spring, v: number) {
159
+ s.pos = v
160
+ s.target = v
161
+ s.vel = 0
162
+ }
163
+
164
+ function animate() {
165
+ if (reducedMotion()) springs.forEach((s) => setNow(s, s.target))
166
+ if (!raf) {
167
+ lastFrame = performance.now()
168
+ raf = requestAnimationFrame(step)
169
+ }
170
+ write()
171
+ }
172
+
173
+ function step(now: number) {
174
+ raf = 0
175
+ const dt = Math.min((now - lastFrame) / 1000, 1 / 30)
176
+ lastFrame = now
177
+ let moving = false
178
+ for (const s of springs) {
179
+ for (let left = dt; left > 0; left -= 0.004) {
180
+ const h = Math.min(0.004, left)
181
+ s.vel += (-s.k * (s.pos - s.target) - 2 * s.z * Math.sqrt(s.k) * s.vel) * h
182
+ s.pos += s.vel * h
183
+ }
184
+ const eps = s === scale || s === intro || s === backdrop ? 0.001 : 0.5
185
+ if (Math.abs(s.pos - s.target) < eps && Math.abs(s.vel) < eps * 10) setNow(s, s.target)
186
+ else moving = true
187
+ }
188
+ write()
189
+ if (moving || dragging()) raf = requestAnimationFrame(step)
190
+ else if (onSettled) {
191
+ const cb = onSettled
192
+ onSettled = null
193
+ cb()
194
+ }
195
+ }
196
+
197
+ /** Writes every animated value to the DOM (never through reactive bindings). */
198
+ function write() {
199
+ const root = rootEl.value
200
+ if (!root) return
201
+ const fade = 1 - Math.min(Math.abs(dismissY.pos) / (stageH * 0.5 || 300), 1) * 0.85
202
+ const back = root.querySelector<HTMLElement>('[data-lb-backdrop]')
203
+ if (back) back.style.opacity = String(Math.max(0, Math.min(1, backdrop.pos * fade)))
204
+ root.querySelectorAll<HTMLElement>('[data-lb-slide]').forEach((el) => {
205
+ const k = Number(el.dataset.offset)
206
+ el.style.transform = `translate3d(${k * (stageW + GAP) + trackX.pos}px, 0, 0)`
207
+ })
208
+ // Neighbors show their image plainly: clear what was written while one of them was current.
209
+ root.querySelectorAll<HTMLElement>('[data-lb-slide]:not([data-offset="0"]) [data-lb-zoom]').forEach((el) => {
210
+ el.style.transform = ''
211
+ el.style.opacity = ''
212
+ el.style.clipPath = ''
213
+ })
214
+ const zoomEl = root.querySelector<HTMLElement>('[data-lb-slide][data-offset="0"] [data-lb-zoom]')
215
+ if (zoomEl) {
216
+ const shrink = 1 - Math.min(Math.abs(dismissY.pos) / (stageH || 600), 1) * 0.3
217
+ let tx = panX.pos
218
+ let ty = panY.pos + dismissY.pos
219
+ let s = scale.pos * shrink
220
+ let opacity = 1
221
+ let clip = ''
222
+ const p = intro.pos
223
+ if (p < 1) {
224
+ if (introFrom) {
225
+ // Container transform: start as the origin (its position, size, crop and corners) and
226
+ // open up into the whole image.
227
+ tx = introFrom.dx + (tx - introFrom.dx) * p
228
+ ty = introFrom.dy + (ty - introFrom.dy) * p
229
+ s = introFrom.s + (s - introFrom.s) * p
230
+ const q = Math.max(0, 1 - p)
231
+ const radius = introFrom.radius + ((props.rounded ? 16 : 0) - introFrom.radius) * p
232
+ clip = `inset(${introFrom.insetY * q}px ${introFrom.insetX * q}px round ${Math.max(0, radius)}px)`
233
+ } else {
234
+ s *= 0.92 + 0.08 * p
235
+ opacity = Math.max(0, Math.min(1, p))
236
+ }
237
+ }
238
+ zoomEl.style.transform = `translate3d(${tx}px, ${ty}px, 0) scale(${s})`
239
+ zoomEl.style.opacity = String(opacity)
240
+ zoomEl.style.clipPath = clip
241
+ }
242
+ }
243
+
244
+ // ── Opening and closing ───────────────────────────────────────────────────────────────────────
245
+
246
+ let restoreFocus: HTMLElement | null = null
247
+
248
+ function measure() {
249
+ stageW = stageEl.value?.clientWidth ?? 0
250
+ stageH = stageEl.value?.clientHeight ?? 0
251
+ const pad = window.innerWidth >= 640 ? 48 : 16
252
+ const w = Math.max(0, stageW - pad * 2)
253
+ const h = Math.max(0, stageH - pad * 2)
254
+ if (w !== box.value.w || h !== box.value.h) box.value = { w, h }
255
+ }
256
+
257
+ function currentImg() {
258
+ return rootEl.value?.querySelector<HTMLImageElement>('[data-lb-slide][data-offset="0"] img') ?? null
259
+ }
260
+
261
+ /**
262
+ * The origin element as a transform of the open image. The origin usually crops the picture
263
+ * (object-cover thumbnails), so the image is scaled to cover it and clipped to its shape.
264
+ */
265
+ function originTransform(): Origin | null {
266
+ const el = origins.get(currentIndex.value)
267
+ const img = currentImg()
268
+ const stage = stageEl.value
269
+ if (!el || !el.isConnected || !img || !stage || !img.offsetWidth) return null
270
+ const o = el.getBoundingClientRect()
271
+ if (!o.width || !o.height) return null
272
+ const st = stage.getBoundingClientRect()
273
+ const iw = img.offsetWidth
274
+ const ih = img.offsetHeight
275
+ const s = Math.max(0.05, Math.max(o.width / iw, o.height / ih))
276
+ return {
277
+ dx: o.left + o.width / 2 - (st.left + st.width / 2),
278
+ dy: o.top + o.height / 2 - (st.top + st.height / 2),
279
+ s,
280
+ // Insets and radius are in the image's own (unscaled) pixels: the clip is scaled with it.
281
+ insetX: Math.max(0, (iw - o.width / s) / 2),
282
+ insetY: Math.max(0, (ih - o.height / s) / 2),
283
+ radius: (Number.parseFloat(getComputedStyle(el).borderTopLeftRadius) || 0) / s,
284
+ }
285
+ }
286
+
287
+ async function show() {
288
+ restoreFocus = document.activeElement as HTMLElement | null
289
+ rendered.value = true
290
+ chrome.value = true
291
+ resetZoom(true)
292
+ setNow(trackX, 0)
293
+ setNow(dismissY, 0)
294
+ setNow(intro, 0)
295
+ setNow(backdrop, 0)
296
+ backdrop.k = 300
297
+ document.addEventListener('keydown', onKeydown)
298
+ document.body.style.overflow = 'hidden'
299
+ await nextTick()
300
+ measure()
301
+ backdrop.target = 1
302
+ animate()
303
+ rootEl.value?.querySelector<HTMLElement>('[data-lb-close]')?.focus()
304
+ // Grow out of the origin once the image has a size to grow into (or after a short wait).
305
+ const img = currentImg()
306
+ if (img && !img.complete) {
307
+ await Promise.race([new Promise((r) => img.addEventListener('load', r, { once: true })), new Promise((r) => setTimeout(r, 300))])
308
+ }
309
+ if (!rendered.value) return
310
+ introFrom = originTransform()
311
+ intro.target = 1
312
+ animate()
71
313
  }
72
314
 
315
+ function hide() {
316
+ document.removeEventListener('keydown', onKeydown)
317
+ // The bars and the backdrop go with the image, not after it.
318
+ chrome.value = false
319
+ backdrop.k = 700
320
+ introFrom = originTransform()
321
+ resetZoom()
322
+ intro.target = 0
323
+ backdrop.target = 0
324
+ if (introFrom) dismissY.target = 0
325
+ else if (dismissY.pos !== 0) {
326
+ // Dismissed by a drag with nowhere to return to: carry on in that direction.
327
+ intro.target = 1
328
+ dismissY.target = Math.sign(dismissY.pos) * (stageH || 800)
329
+ }
330
+ onSettled = () => {
331
+ rendered.value = false
332
+ document.body.style.overflow = ''
333
+ restoreFocus?.focus?.()
334
+ restoreFocus = null
335
+ }
336
+ animate()
337
+ }
338
+
339
+ watch(() => props.modelValue, (v) => (v ? !rendered.value && show() : rendered.value && hide()), { immediate: true })
340
+ watch(() => props.index, (v) => {
341
+ if (v === currentIndex.value || !galleryItems.value[v]) return
342
+ // Closed, or still opening (a consumer usually sets the index and opens in the same tick): show
343
+ // that image directly. Only an index change while it's open slides.
344
+ if (!rendered.value || intro.pos < 0.999 || intro.target < 1) {
345
+ resetZoom(true)
346
+ setNow(trackX, 0)
347
+ currentIndex.value = v
348
+ } else {
349
+ go(v)
350
+ }
351
+ })
352
+
73
353
  function open(i = 0, sourceEl?: HTMLElement) {
74
- originRect = sourceEl ? sourceEl.getBoundingClientRect() : null
75
- isFirstShow.value = true
354
+ if (sourceEl) origins.set(i, sourceEl)
76
355
  setIndex(i)
77
- isOpen.value = true
78
356
  emit('update:modelValue', true)
357
+ if (!rendered.value) show()
79
358
  }
80
359
 
81
360
  function close() {
82
- isOpen.value = false
83
361
  emit('update:modelValue', false)
362
+ if (rendered.value) hide()
363
+ }
364
+
365
+ // ── Navigation ────────────────────────────────────────────────────────────────────────────────
366
+
367
+ function setIndex(i: number) {
368
+ if (i === currentIndex.value) return
369
+ currentIndex.value = i
370
+ emit('update:index', i)
371
+ emit('change', i)
372
+ }
373
+
374
+ /**
375
+ * Moves to `i`. The index changes right away; the track starts where the new image already was
376
+ * (or one slot away, for a jump) and springs to center.
377
+ */
378
+ function go(i: number, direction?: number) {
379
+ if (i === currentIndex.value || !galleryItems.value[i]) return
380
+ const dir = direction ?? (i > currentIndex.value ? 1 : -1)
381
+ resetZoom(true)
382
+ setNow(dismissY, 0)
383
+ setIndex(i)
384
+ trackX.pos += dir * (stageW + GAP)
385
+ trackX.target = 0
386
+ animate()
84
387
  }
85
388
 
86
389
  function next() {
87
- const len = galleryItems.value.length
88
- if (!len) return
89
- isFirstShow.value = false
90
- direction.value = 1
91
- if (currentIndex.value < len - 1) setIndex(currentIndex.value + 1)
92
- else if (props.loop) setIndex(0)
390
+ if (nextIndex.value !== null) go(nextIndex.value, 1)
93
391
  }
94
392
 
95
393
  function prev() {
96
- const len = galleryItems.value.length
97
- if (!len) return
98
- isFirstShow.value = false
99
- direction.value = -1
100
- if (currentIndex.value > 0) setIndex(currentIndex.value - 1)
101
- else if (props.loop) setIndex(len - 1)
394
+ if (prevIndex.value !== null) go(prevIndex.value, -1)
102
395
  }
103
396
 
104
- function goTo(i: number) {
105
- if (i === currentIndex.value) return
106
- isFirstShow.value = false
107
- direction.value = i > currentIndex.value ? 1 : -1
108
- setIndex(i)
397
+ watch(currentIndex, async () => {
398
+ await nextTick()
399
+ write()
400
+ // Scroll only the strip: scrollIntoView() would also scroll the viewer's own (overflow-hidden)
401
+ // container and leave the whole thing shifted sideways.
402
+ const strip = thumbsEl.value
403
+ const thumb = strip?.querySelector<HTMLElement>('[data-lb-thumb][aria-current="true"]')
404
+ if (strip && thumb) strip.scrollTo({ left: thumb.offsetLeft - (strip.clientWidth - thumb.offsetWidth) / 2, behavior: 'smooth' })
405
+ })
406
+
407
+ // ── Zoom ──────────────────────────────────────────────────────────────────────────────────────
408
+
409
+ function panBounds(s: number) {
410
+ const img = currentImg()
411
+ const w = img?.offsetWidth ?? 0
412
+ const h = img?.offsetHeight ?? 0
413
+ return { x: Math.max(0, (w * s - stageW) / 2), y: Math.max(0, (h * s - stageH) / 2) }
109
414
  }
110
415
 
111
- function onKeydown(e: KeyboardEvent) {
112
- if (e.key === 'Escape') close()
113
- else if (e.key === 'ArrowRight') next()
114
- else if (e.key === 'ArrowLeft') prev()
416
+ function clampPanTargets() {
417
+ const b = panBounds(scale.target)
418
+ panX.target = Math.max(-b.x, Math.min(b.x, panX.target))
419
+ panY.target = Math.max(-b.y, Math.min(b.y, panY.target))
115
420
  }
116
421
 
117
- watch(isOpen, (open) => {
118
- if (open) {
119
- document.addEventListener('keydown', onKeydown)
120
- document.body.style.overflow = 'hidden'
422
+ function resetZoom(now = false) {
423
+ for (const [s, v] of [[scale, 1], [panX, 0], [panY, 0]] as const) {
424
+ if (now) setNow(s, v)
425
+ else s.target = v
426
+ }
427
+ zoomed.value = false
428
+ }
429
+
430
+ /** Zooms to `factor` keeping the point (x, y), relative to the stage center, under the pointer. */
431
+ function zoomTo(factor: number, x: number, y: number, now = false) {
432
+ const s = Math.max(1, Math.min(props.maxZoom, factor))
433
+ const ratio = s / scale.target
434
+ const tx = x - (x - panX.target) * ratio
435
+ const ty = y - (y - panY.target) * ratio
436
+ scale.target = s
437
+ panX.target = tx
438
+ panY.target = ty
439
+ clampPanTargets()
440
+ if (now) [scale, panX, panY].forEach((sp) => setNow(sp, sp.target))
441
+ zoomed.value = s > 1.01
442
+ animate()
443
+ }
444
+
445
+ function stagePoint(clientX: number, clientY: number) {
446
+ const r = stageEl.value!.getBoundingClientRect()
447
+ return { x: clientX - (r.left + r.width / 2), y: clientY - (r.top + r.height / 2) }
448
+ }
449
+
450
+ function toggleZoomAt(clientX: number, clientY: number) {
451
+ if (!props.zoom) return
452
+ if (zoomed.value) {
453
+ resetZoom()
454
+ animate()
121
455
  } else {
122
- document.removeEventListener('keydown', onKeydown)
123
- document.body.style.overflow = ''
456
+ const p = stagePoint(clientX, clientY)
457
+ zoomTo(Math.min(2.5, props.maxZoom), p.x, p.y)
124
458
  }
125
- })
459
+ }
126
460
 
127
- // ── Image transition: Discord-style expand from the clicked thumbnail on open, then a
128
- // slide between images on next()/prev()/goTo(). Driven entirely from JS (css: false) since
129
- // the "expand" transform depends on the clicked element's on-screen position/size, which
130
- // plain CSS classes can't know about.
131
- function transitionEndPromise(el: HTMLElement) {
132
- return new Promise<void>((resolve) => {
133
- const handler = (ev: TransitionEvent) => {
134
- if (ev.target !== el) return
135
- el.removeEventListener('transitionend', handler)
136
- resolve()
137
- }
138
- el.addEventListener('transitionend', handler)
139
- })
461
+ function onWheel(e: WheelEvent) {
462
+ if (!props.zoom || !rendered.value) return
463
+ e.preventDefault()
464
+ const p = stagePoint(e.clientX, e.clientY)
465
+ // Trackpad pinches arrive as ctrl+wheel with small deltas.
466
+ const factor = Math.exp(-e.deltaY * (e.ctrlKey ? 0.01 : 0.002))
467
+ zoomTo(scale.target * factor, p.x, p.y, true)
468
+ }
469
+
470
+ // ── Gestures ──────────────────────────────────────────────────────────────────────────────────
471
+
472
+ type Mode = 'pending' | 'swipe' | 'dismiss' | 'pan' | 'pinch' | 'ignore'
473
+ const pointers = new Map<number, { x: number; y: number }>()
474
+ let mode: Mode | null = null
475
+ let start = { x: 0, y: 0, t: 0, trackX: 0, dismissY: 0, panX: 0, panY: 0 }
476
+ let pinch = { dist: 0, scale: 1, mid: { x: 0, y: 0 }, panX: 0, panY: 0 }
477
+ let samples: { t: number; x: number; y: number }[] = []
478
+ let lastTap = { t: -Infinity, x: 0, y: 0 }
479
+ let tapTimer: ReturnType<typeof setTimeout> | null = null
480
+ const dragging = () => mode !== null && mode !== 'pending'
481
+
482
+ function onPointerDown(e: PointerEvent) {
483
+ if (e.button !== 0 || (e.target as Element).closest('button, a, input')) return
484
+ measure()
485
+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY })
486
+ try { stageEl.value?.setPointerCapture(e.pointerId) } catch { /* not capturable */ }
487
+ if (pointers.size === 2 && props.zoom) {
488
+ startPinch()
489
+ return
490
+ }
491
+ if (pointers.size > 1) return
492
+ springs.forEach((s) => (s.target = s.pos))
493
+ start = { x: e.clientX, y: e.clientY, t: performance.now(), trackX: trackX.pos, dismissY: dismissY.pos, panX: panX.pos, panY: panY.pos }
494
+ samples = [{ t: start.t, x: e.clientX, y: e.clientY }]
495
+ mode = 'pending'
496
+ }
497
+
498
+ function onPointerMove(e: PointerEvent) {
499
+ if (!pointers.has(e.pointerId)) return
500
+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY })
501
+ if (mode === 'pinch' && pointers.size >= 2) {
502
+ const [a, b] = [...pointers.values()] as [{ x: number; y: number }, { x: number; y: number }]
503
+ const s = Math.max(0.8, Math.min(props.maxZoom * 1.2, pinch.scale * (Math.hypot(a.x - b.x, a.y - b.y) / pinch.dist)))
504
+ const mid = stagePoint((a.x + b.x) / 2, (a.y + b.y) / 2)
505
+ lastMid = mid
506
+ const ratio = s / pinch.scale
507
+ setNow(scale, s)
508
+ setNow(panX, mid.x - (pinch.mid.x - pinch.panX) * ratio)
509
+ setNow(panY, mid.y - (pinch.mid.y - pinch.panY) * ratio)
510
+ zoomed.value = s > 1.01
511
+ write()
512
+ return
513
+ }
514
+ const dx = e.clientX - start.x
515
+ const dy = e.clientY - start.y
516
+ const now = performance.now()
517
+ samples.push({ t: now, x: e.clientX, y: e.clientY })
518
+ while (samples.length > 2 && now - samples[0]!.t > 100) samples.shift()
519
+ if (mode === 'pending') {
520
+ const slop = e.pointerType === 'touch' ? 8 : 4
521
+ if (Math.hypot(dx, dy) < slop) return
522
+ if (zoomed.value) mode = 'pan'
523
+ else if (Math.abs(dx) > Math.abs(dy)) mode = hasMultiple.value ? 'swipe' : 'dismiss'
524
+ else mode = 'dismiss'
525
+ chromeBeforeDrag = chrome.value
526
+ if (mode === 'dismiss') chrome.value = false
527
+ }
528
+ if (mode === 'swipe') {
529
+ // Resist past the ends of a non-looping gallery.
530
+ let x = start.trackX + dx
531
+ if ((x > 0 && prevIndex.value === null) || (x < 0 && nextIndex.value === null)) x = start.trackX + dx * 0.3
532
+ setNow(trackX, x)
533
+ } else if (mode === 'dismiss') {
534
+ setNow(dismissY, start.dismissY + dy)
535
+ } else if (mode === 'pan') {
536
+ setNow(panX, start.panX + dx)
537
+ setNow(panY, start.panY + dy)
538
+ }
539
+ write()
540
+ }
541
+
542
+ let chromeBeforeDrag = true
543
+ let lastMid = { x: 0, y: 0 }
544
+
545
+ function startPinch() {
546
+ if (tapTimer) clearTimeout(tapTimer)
547
+ tapTimer = null
548
+ // Fingers rarely land together: the first one may already have started a swipe or a
549
+ // dismiss drag. Undo it, or its offset would stay applied on top of the zoom.
550
+ if (mode === 'swipe' || mode === 'dismiss') {
551
+ trackX.target = 0
552
+ dismissY.target = 0
553
+ chrome.value = chromeBeforeDrag
554
+ }
555
+ const [a, b] = [...pointers.values()] as [{ x: number; y: number }, { x: number; y: number }]
556
+ const mid = stagePoint((a.x + b.x) / 2, (a.y + b.y) / 2)
557
+ pinch = { dist: Math.hypot(a.x - b.x, a.y - b.y) || 1, scale: scale.pos, mid, panX: panX.pos, panY: panY.pos }
558
+ lastMid = mid
559
+ setNow(scale, scale.pos)
560
+ setNow(panX, panX.pos)
561
+ setNow(panY, panY.pos)
562
+ mode = 'pinch'
563
+ animate()
564
+ }
565
+
566
+ /** After a pinch: back to 1 if it went below, into range around the fingers if it went past max. */
567
+ function settleZoom() {
568
+ if (scale.pos < 1) resetZoom()
569
+ else zoomTo(scale.pos, lastMid.x, lastMid.y)
570
+ animate()
571
+ }
572
+
573
+ function velocity() {
574
+ const a = samples[0]
575
+ const b = samples[samples.length - 1]
576
+ if (!a || !b || b.t - a.t < 1) return { x: 0, y: 0 }
577
+ return { x: ((b.x - a.x) / (b.t - a.t)) * 1000, y: ((b.y - a.y) / (b.t - a.t)) * 1000 }
140
578
  }
141
579
 
142
- function onImageBeforeEnter(el: Element) {
143
- const target = el as HTMLElement
144
- if (isFirstShow.value) {
145
- if (originRect) {
146
- // Translate by the two boxes' centers (target fills the stage and centers the image via
147
- // flex, so its center already coincides with the image's), but scale by the ratio against
148
- // the actual rendered <img> size, not the full-stage wrapper's size.
149
- const containerRect = target.getBoundingClientRect()
150
- const imgRect = target.querySelector('img')?.getBoundingClientRect() ?? containerRect
151
- const dx = originRect.x + originRect.width / 2 - (containerRect.left + containerRect.width / 2)
152
- const dy = originRect.y + originRect.height / 2 - (containerRect.top + containerRect.height / 2)
153
- const area = Math.max(imgRect.width * imgRect.height, 1)
154
- const scale = Math.min(1, Math.max(0.05, Math.sqrt((originRect.width * originRect.height) / area)))
155
- target.style.transform = `translate(${dx}px, ${dy}px) scale(${scale})`
580
+ function onPointerUp(e: PointerEvent) {
581
+ if (!pointers.has(e.pointerId)) return
582
+ pointers.delete(e.pointerId)
583
+ if (mode === 'pinch') {
584
+ if (pointers.size > 1) return
585
+ settleZoom()
586
+ const rest = [...pointers.values()][0]
587
+ if (!rest) {
588
+ mode = null
589
+ return
590
+ }
591
+ // One finger left: it keeps moving a zoomed image, and does nothing otherwise.
592
+ const t = performance.now()
593
+ start = { x: rest.x, y: rest.y, t, trackX: trackX.pos, dismissY: dismissY.pos, panX: panX.pos, panY: panY.pos }
594
+ samples = [{ t, x: rest.x, y: rest.y }]
595
+ mode = scale.target > 1.01 ? 'pan' : 'ignore'
596
+ return
597
+ }
598
+ if (mode === 'ignore') {
599
+ if (pointers.size === 0) mode = null
600
+ return
601
+ }
602
+ const m = mode
603
+ mode = null
604
+ const v = velocity()
605
+ if (m === 'pending' && e.type === 'pointerup') return onTap(e)
606
+ if (m === 'swipe') {
607
+ const threshold = Math.min(120, (stageW || 480) * 0.25)
608
+ const dx = trackX.pos
609
+ if ((dx <= -threshold || v.x < -500) && nextIndex.value !== null) {
610
+ trackX.vel = v.x
611
+ next()
612
+ } else if ((dx >= threshold || v.x > 500) && prevIndex.value !== null) {
613
+ trackX.vel = v.x
614
+ prev()
156
615
  } else {
157
- target.style.transform = 'scale(0.92)'
616
+ trackX.target = 0
617
+ trackX.vel = v.x
618
+ animate()
158
619
  }
159
- } else {
160
- target.style.transform = `translateX(${direction.value >= 0 ? 100 : -100}%)`
620
+ } else if (m === 'dismiss') {
621
+ if (Math.abs(dismissY.pos) > 120 || Math.abs(v.y) > 800) {
622
+ dismissY.vel = v.y
623
+ close()
624
+ } else {
625
+ chrome.value = chromeBeforeDrag
626
+ dismissY.target = 0
627
+ dismissY.vel = v.y
628
+ animate()
629
+ }
630
+ } else if (m === 'pan') {
631
+ panX.vel = v.x
632
+ panY.vel = v.y
633
+ panX.target = panX.pos + v.x * 0.2
634
+ panY.target = panY.pos + v.y * 0.2
635
+ clampPanTargets()
636
+ animate()
161
637
  }
162
- target.style.opacity = '0'
163
638
  }
164
639
 
165
- async function onImageEnter(el: Element, done: () => void) {
166
- const target = el as HTMLElement
167
- void target.offsetWidth // force reflow so the "from" styles above are committed first
168
- if (isFirstShow.value) {
169
- // Let the scrim fade in on its own first, Discord-style, before the image starts growing.
170
- await new Promise((resolve) => setTimeout(resolve, 120))
640
+ /** A tap toggles the bars (or closes, outside the image); two taps zoom. */
641
+ function onTap(e: PointerEvent) {
642
+ const now = performance.now()
643
+ const double = now - lastTap.t < 300 && Math.hypot(e.clientX - lastTap.x, e.clientY - lastTap.y) < 30
644
+ lastTap = { t: double ? -Infinity : now, x: e.clientX, y: e.clientY }
645
+ if (tapTimer) clearTimeout(tapTimer)
646
+ tapTimer = null
647
+ if (double) {
648
+ toggleZoomAt(e.clientX, e.clientY)
649
+ return
171
650
  }
172
- target.style.transition = 'transform 0.32s cubic-bezier(0.2, 0, 0, 1), opacity 0.28s ease'
173
- target.style.transform = ''
174
- target.style.opacity = ''
175
- await transitionEndPromise(target)
176
- target.style.transition = ''
177
- isFirstShow.value = false
178
- done()
179
- }
180
-
181
- async function onImageLeave(el: Element, done: () => void) {
182
- const target = el as HTMLElement
183
- target.style.transition = 'transform 0.32s cubic-bezier(0.2, 0, 0, 1), opacity 0.28s ease'
184
- target.style.transform = `translateX(${direction.value >= 0 ? -100 : 100}%)`
185
- target.style.opacity = '0'
186
- await transitionEndPromise(target)
187
- done()
188
- }
189
-
190
- // ── Swipe/drag to navigate: follows the pointer 1:1 while held, then either commits to
191
- // next()/prev() (which take over via the enter/leave hooks above, continuing smoothly from
192
- // wherever the drag left off) or springs back to center if released short of the threshold.
193
- let dragPointerId: number | null = null
194
- let dragStartX = 0
195
- let dragOffsetPx = 0
196
- let dragStageWidth = 0
197
- let isDragging = false
198
-
199
- function onStagePointerDown(e: PointerEvent) {
200
- if (!hasMultiple.value || e.button !== 0) return
201
- const stage = e.currentTarget as HTMLElement
202
- dragStageWidth = stage.clientWidth
203
- dragStartX = e.clientX
204
- dragOffsetPx = 0
205
- dragPointerId = e.pointerId
206
- isDragging = true
207
- stage.setPointerCapture(e.pointerId)
208
- if (stageImageEl.value) stageImageEl.value.style.transition = 'none'
209
- }
210
-
211
- function onStagePointerMove(e: PointerEvent) {
212
- if (!isDragging || e.pointerId !== dragPointerId) return
213
- dragOffsetPx = e.clientX - dragStartX
214
- if (stageImageEl.value) stageImageEl.value.style.transform = `translateX(${dragOffsetPx}px)`
215
- }
216
-
217
- function endDrag(e: PointerEvent) {
218
- if (!isDragging || e.pointerId !== dragPointerId) return
219
- isDragging = false
220
- const stage = e.currentTarget as HTMLElement
221
- if (stage.hasPointerCapture(e.pointerId)) stage.releasePointerCapture(e.pointerId)
222
-
223
- const threshold = Math.min(120, dragStageWidth * 0.25)
224
- const offset = dragOffsetPx
225
- dragOffsetPx = 0
226
-
227
- if (offset <= -threshold) next()
228
- else if (offset >= threshold) prev()
229
- else if (stageImageEl.value) {
230
- const el = stageImageEl.value
231
- el.style.transition = 'transform 0.25s cubic-bezier(0.2, 0, 0, 1)'
232
- el.style.transform = ''
233
- const cleanup = (ev: TransitionEvent) => {
234
- if (ev.target !== el) return
235
- el.style.transition = ''
236
- el.removeEventListener('transitionend', cleanup)
237
- }
238
- el.addEventListener('transitionend', cleanup)
651
+ // By position, not e.target: the stage captures the pointer, so pointerup targets the stage.
652
+ const r = currentImg()?.getBoundingClientRect()
653
+ const onImage = zoomed.value || (!!r && e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom)
654
+ tapTimer = setTimeout(() => {
655
+ tapTimer = null
656
+ if (onImage) chrome.value = !chrome.value
657
+ else close()
658
+ }, props.zoom ? 260 : 0)
659
+ }
660
+
661
+ // ── Keyboard and focus ────────────────────────────────────────────────────────────────────────
662
+
663
+ function onKeydown(e: KeyboardEvent) {
664
+ if (e.key === 'Escape') close()
665
+ else if (e.key === 'ArrowRight') next()
666
+ else if (e.key === 'ArrowLeft') prev()
667
+ else if (props.zoom && (e.key === '+' || e.key === '=')) zoomTo(scale.target * 1.5, 0, 0)
668
+ else if (props.zoom && e.key === '-') zoomTo(scale.target / 1.5, 0, 0)
669
+ else if (props.zoom && e.key === '0') { resetZoom(); animate() }
670
+ else if (e.key === 'Tab') trapFocus(e)
671
+ else return
672
+ if (e.key !== 'Tab') e.preventDefault()
673
+ }
674
+
675
+ function trapFocus(e: KeyboardEvent) {
676
+ const els = Array.from(rootEl.value?.querySelectorAll<HTMLElement>('button, a[href], input, [tabindex]:not([tabindex="-1"])') ?? [])
677
+ .filter((el) => !el.closest('[inert]'))
678
+ if (!els.length) return
679
+ const first = els[0]!
680
+ const last = els[els.length - 1]!
681
+ if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus() }
682
+ else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus() }
683
+ }
684
+
685
+ function onImgLoad(src: string, e: Event) {
686
+ loaded.value = new Set(loaded.value).add(src)
687
+ measureRatio(src, e.target as HTMLImageElement)
688
+ }
689
+
690
+ /**
691
+ * An SVG with a viewBox but no width/height has a ratio but no size: inside a shrink-to-fit box it
692
+ * would collapse to 0×0 (and naturalWidth can't be trusted for it). So every image gets an explicit
693
+ * size from its ratio, read from an off-screen copy laid out at a fixed width.
694
+ */
695
+ function measureRatio(src: string, img: HTMLImageElement) {
696
+ if (ratios.value.has(src)) return
697
+ const set = (r: number) => (ratios.value = new Map(ratios.value).set(src, r > 0 && Number.isFinite(r) ? r : 1))
698
+ const natural = img.naturalWidth && img.naturalHeight ? img.naturalWidth / img.naturalHeight : 0
699
+ if (natural && !/^data:image\/svg|\.svg(\?|#|$)/i.test(src)) return set(natural)
700
+ const probe = new Image()
701
+ probe.style.cssText = 'position:fixed;left:-10000px;top:0;width:1000px;height:auto;visibility:hidden;pointer-events:none'
702
+ const done = () => {
703
+ set(probe.offsetHeight ? 1000 / probe.offsetHeight : natural)
704
+ probe.remove()
239
705
  }
706
+ probe.onload = done
707
+ probe.onerror = () => {
708
+ set(natural)
709
+ probe.remove()
710
+ }
711
+ probe.src = src
712
+ document.body.appendChild(probe)
713
+ if (probe.complete && probe.naturalWidth) done()
714
+ }
715
+
716
+ /** The image's size: as large as fits in the box, keeping its ratio. */
717
+ function sizeFor(src: string) {
718
+ const r = ratios.value.get(src)
719
+ const { w, h } = box.value
720
+ if (!r || !w || !h) return undefined
721
+ const width = Math.min(w, h * r)
722
+ return { width: `${width}px`, height: `${width / r}px` }
240
723
  }
241
724
 
242
- // Auto-scan mode: pull <img> elements out of whatever is rendered in the default slot
243
- // (e.g. MMarkdown output, a hand-rolled gallery grid) so this works without building an
244
- // `items` array by hand. Opt an image out with `data-lightbox="false"`.
725
+ // ── Auto-scan ─────────────────────────────────────────────────────────────────────────────────
726
+ // Pull <img> elements out of whatever is rendered in the default slot (e.g. MMarkdown output, a
727
+ // hand-rolled gallery grid) so this works without building an `items` array by hand. Opt an image
728
+ // out with `data-lightbox="false"`.
245
729
  let observer: MutationObserver | null = null
730
+ let resizeObserver: ResizeObserver | null = null
246
731
 
247
732
  function scan() {
248
733
  if (props.items || !containerEl.value) return
249
- const imgs = Array.from(containerEl.value.querySelectorAll('img')).filter(
250
- (img) => img.dataset.lightbox !== 'false',
251
- )
734
+ const imgs = Array.from(containerEl.value.querySelectorAll('img')).filter((img) => img.dataset.lightbox !== 'false')
252
735
  scannedItems.value = imgs.map((img) => ({
253
736
  src: img.currentSrc || img.src,
254
737
  alt: img.alt || undefined,
255
738
  caption: img.dataset.caption || img.title || undefined,
256
739
  }))
740
+ scannedEls.length = 0
257
741
  imgs.forEach((img, i) => {
742
+ scannedEls.push(img)
743
+ origins.set(i, img)
258
744
  img.style.cursor = 'zoom-in'
259
745
  img.onclick = (e) => {
260
746
  e.preventDefault()
@@ -264,142 +750,154 @@ function scan() {
264
750
  }
265
751
 
266
752
  onMounted(() => {
267
- if (props.items || !containerEl.value) return
268
- scan()
269
- observer = new MutationObserver(scan)
270
- observer.observe(containerEl.value, {
271
- childList: true,
272
- subtree: true,
273
- attributes: true,
274
- attributeFilter: ['src'],
275
- })
753
+ if (!props.items && containerEl.value) {
754
+ scan()
755
+ observer = new MutationObserver(scan)
756
+ observer.observe(containerEl.value, { childList: true, subtree: true, attributes: true, attributeFilter: ['src'] })
757
+ }
758
+ })
759
+
760
+ watch(stageEl, (el, old) => {
761
+ if (old) {
762
+ old.removeEventListener('wheel', onWheel)
763
+ resizeObserver?.disconnect()
764
+ }
765
+ if (el) {
766
+ el.addEventListener('wheel', onWheel, { passive: false })
767
+ resizeObserver = new ResizeObserver(() => {
768
+ measure()
769
+ write()
770
+ })
771
+ resizeObserver.observe(el)
772
+ }
276
773
  })
277
774
 
278
775
  onBeforeUnmount(() => {
279
776
  observer?.disconnect()
777
+ resizeObserver?.disconnect()
778
+ stageEl.value?.removeEventListener('wheel', onWheel)
779
+ if (raf) cancelAnimationFrame(raf)
780
+ if (tapTimer) clearTimeout(tapTimer)
280
781
  document.removeEventListener('keydown', onKeydown)
281
- document.body.style.overflow = ''
782
+ if (rendered.value) document.body.style.overflow = ''
282
783
  })
283
784
 
284
785
  defineExpose({ open, close, next, prev })
285
786
  </script>
286
787
 
287
788
  <template>
288
- <div ref="containerEl" class="contents">
789
+ <div ref="containerEl" v-bind="$attrs" class="contents">
289
790
  <slot />
290
791
  </div>
291
792
 
292
793
  <Teleport to="body">
293
- <Transition name="m3-lightbox">
794
+ <div
795
+ v-if="rendered"
796
+ ref="rootEl"
797
+ class="fixed inset-0 z-[100] overflow-hidden text-white"
798
+ role="dialog"
799
+ aria-modal="true"
800
+ :aria-label="current?.alt || current?.caption || positionLabel"
801
+ >
802
+ <div data-lb-backdrop class="absolute inset-0 bg-black" style="opacity: 0" />
803
+
804
+ <!-- Stage: the image track -->
294
805
  <div
295
- v-if="isOpen"
296
- class="fixed inset-0 z-[100] flex flex-col bg-black/90"
297
- @click.self="close"
806
+ ref="stageEl"
807
+ data-lb-stage
808
+ class="absolute inset-0 touch-none select-none"
809
+ :class="zoomed ? 'cursor-grab active:cursor-grabbing' : props.zoom ? 'cursor-zoom-in' : ''"
810
+ @pointerdown="onPointerDown"
811
+ @pointermove="onPointerMove"
812
+ @pointerup="onPointerUp"
813
+ @pointercancel="onPointerUp"
814
+ @dragstart.prevent
298
815
  >
299
- <span
300
- v-if="hasMultiple"
301
- class="absolute left-2 top-2 z-10 rounded-full bg-black/30 px-3 py-1 text-label-large text-white sm:left-4 sm:top-4"
302
- >
303
- {{ currentIndex + 1 }} / {{ galleryItems.length }}
304
- </span>
305
-
306
- <button
307
- type="button"
308
- class="absolute right-2 top-2 z-10 flex h-11 w-11 items-center justify-center rounded-full bg-black/30 text-white transition-colors hover:bg-black/50 sm:right-4 sm:top-4"
309
- :aria-label="closeLabel ?? locale.close"
310
- @click="close"
816
+ <div
817
+ v-for="s in slides"
818
+ :key="s.offset === -1 && s.index === nextIndex ? `prev-${s.index}` : s.index"
819
+ data-lb-slide
820
+ :data-offset="s.offset"
821
+ class="absolute inset-0 flex items-center justify-center p-4 sm:p-12"
822
+ :aria-hidden="s.offset !== 0"
311
823
  >
312
- <MIcon name="close" :size="24" />
313
- </button>
314
-
315
- <div class="relative flex flex-1 items-center justify-center overflow-hidden" @click.self="close">
316
- <button
317
- v-if="hasMultiple"
318
- type="button"
319
- class="absolute left-2 top-1/2 z-10 flex h-11 w-11 -translate-y-1/2 items-center justify-center rounded-full bg-black/30 text-white transition-colors hover:bg-black/50 sm:left-4"
320
- :aria-label="locale.previous"
321
- @click.stop="prev"
322
- >
323
- <MIcon name="chevron_left" :size="28" />
324
- </button>
325
-
326
- <div
327
- class="relative h-full w-full touch-pan-y overflow-hidden"
328
- @pointerdown="onStagePointerDown"
329
- @pointermove="onStagePointerMove"
330
- @pointerup="endDrag"
331
- @pointercancel="endDrag"
332
- >
333
- <Transition
334
- :css="false"
335
- @before-enter="onImageBeforeEnter"
336
- @enter="onImageEnter"
337
- @leave="onImageLeave"
338
- >
339
- <div
340
- v-if="current"
341
- :key="currentIndex"
342
- ref="stageImageEl"
343
- class="absolute inset-0 flex items-center justify-center p-4"
344
- @click="close"
345
- >
346
- <img
347
- :src="current.src"
348
- :alt="current.alt ?? ''"
349
- class="max-h-full max-w-full select-none object-contain"
350
- :class="rounded ? 'rounded-2xl' : ''"
351
- draggable="false"
352
- @click.stop
353
- />
354
- </div>
355
- </Transition>
824
+ <!-- No style binding here: transform / opacity / clip-path are written by write() -->
825
+ <div data-lb-zoom class="flex max-h-full max-w-full items-center justify-center">
826
+ <img
827
+ :src="galleryItems[s.index]!.src"
828
+ :alt="galleryItems[s.index]!.alt ?? ''"
829
+ class="block select-none object-contain"
830
+ :class="[rounded ? 'rounded-2xl' : '', sizeFor(galleryItems[s.index]!.src) ? '' : 'max-h-[calc(100dvh-2rem)] max-w-full sm:max-h-[calc(100dvh-6rem)]']"
831
+ :style="sizeFor(galleryItems[s.index]!.src)"
832
+ draggable="false"
833
+ @load="onImgLoad(galleryItems[s.index]!.src, $event)"
834
+ />
356
835
  </div>
836
+ <MSpinner
837
+ v-if="s.offset === 0 && !loaded.has(galleryItems[s.index]!.src)"
838
+ :size="40"
839
+ class="pointer-events-none absolute text-white/80"
840
+ />
841
+ </div>
842
+ </div>
357
843
 
358
- <button
359
- v-if="hasMultiple"
360
- type="button"
361
- class="absolute right-2 top-1/2 z-10 flex h-11 w-11 -translate-y-1/2 items-center justify-center rounded-full bg-black/30 text-white transition-colors hover:bg-black/50 sm:right-4"
362
- :aria-label="locale.next"
363
- @click.stop="next"
364
- >
365
- <MIcon name="chevron_right" :size="28" />
366
- </button>
844
+ <!-- Top bar -->
845
+ <div
846
+ class="pointer-events-none absolute inset-x-0 top-0 z-10 flex items-center gap-1 bg-gradient-to-b from-black/60 to-transparent px-2 pt-2 pb-8 transition-opacity duration-200 sm:px-4"
847
+ :class="chrome ? 'opacity-100' : 'opacity-0'"
848
+ :inert="!chrome"
849
+ >
850
+ <!-- The bars let touches through (a pinch can start anywhere); only their controls take them -->
851
+ <MIconButton data-lb-close icon="close" :label="closeLabel ?? locale.close" class="pointer-events-auto" style="color: #fff" @click="close" />
852
+ <span v-if="hasMultiple" class="flex-1 px-2 text-title-medium" aria-hidden="true">{{ currentIndex + 1 }} / {{ count }}</span>
853
+ <span v-else class="flex-1" />
854
+ <div v-if="current && $slots.actions" class="pointer-events-auto flex items-center gap-1">
855
+ <slot name="actions" :item="current" :index="currentIndex" />
367
856
  </div>
857
+ </div>
368
858
 
369
- <p
370
- v-if="current?.caption"
371
- class="z-10 px-4 text-center text-body-medium text-white/90"
859
+ <!-- Previous / next, for mouse users -->
860
+ <template v-if="hasMultiple">
861
+ <div
862
+ class="absolute top-1/2 left-2 z-10 -translate-y-1/2 transition-opacity duration-200 sm:left-4 [@media(pointer:coarse)]:hidden"
863
+ :class="chrome && prevIndex !== null ? 'opacity-100' : 'pointer-events-none opacity-0'"
372
864
  >
373
- {{ current.caption }}
374
- </p>
375
-
865
+ <MIconButton icon="chevron_left" :label="locale.previous" variant="tonal" @click="prev" />
866
+ </div>
376
867
  <div
377
- v-if="showThumbnails && hasMultiple"
378
- class="z-10 flex justify-center gap-2 overflow-x-auto p-4"
868
+ class="absolute top-1/2 right-2 z-10 -translate-y-1/2 transition-opacity duration-200 sm:right-4 [@media(pointer:coarse)]:hidden"
869
+ :class="chrome && nextIndex !== null ? 'opacity-100' : 'pointer-events-none opacity-0'"
379
870
  >
871
+ <MIconButton icon="chevron_right" :label="locale.next" variant="tonal" @click="next" />
872
+ </div>
873
+ </template>
874
+
875
+ <!-- Caption and thumbnails -->
876
+ <div
877
+ v-if="current?.caption || (showThumbnails && hasMultiple)"
878
+ class="pointer-events-none absolute inset-x-0 bottom-0 z-10 flex flex-col gap-3 bg-gradient-to-t from-black/70 to-transparent px-4 pt-10 pb-4 transition-opacity duration-200"
879
+ :class="chrome ? 'opacity-100' : 'opacity-0'"
880
+ :inert="!chrome"
881
+ >
882
+ <p v-if="current?.caption" class="mx-auto max-w-3xl text-center text-body-large">{{ current.caption }}</p>
883
+ <div v-if="showThumbnails && hasMultiple" ref="thumbsEl" class="pointer-events-auto flex gap-2 overflow-x-auto px-1 py-1 sm:justify-center" style="scrollbar-width: none">
380
884
  <button
381
885
  v-for="(item, i) in galleryItems"
382
886
  :key="i"
383
887
  type="button"
384
- class="h-14 w-14 shrink-0 overflow-hidden rounded-md ring-2 transition-opacity"
888
+ data-lb-thumb
889
+ class="h-14 w-14 shrink-0 cursor-pointer overflow-hidden rounded-md ring-2 transition-opacity"
385
890
  :class="i === currentIndex ? 'opacity-100 ring-white' : 'opacity-50 ring-transparent hover:opacity-80'"
386
- @click="goTo(i)"
891
+ :aria-label="item.alt || locale.carouselItem.replace('{index}', String(i + 1)).replace('{count}', String(count))"
892
+ :aria-current="i === currentIndex ? 'true' : undefined"
893
+ @click="go(i)"
387
894
  >
388
- <img :src="item.src" :alt="item.alt ?? ''" class="h-full w-full object-cover" draggable="false" />
895
+ <img :src="item.src" :alt="''" class="h-full w-full object-cover" draggable="false" />
389
896
  </button>
390
897
  </div>
391
898
  </div>
392
- </Transition>
899
+
900
+ <span class="sr-only" aria-live="polite">{{ positionLabel }}</span>
901
+ </div>
393
902
  </Teleport>
394
903
  </template>
395
-
396
- <style scoped>
397
- .m3-lightbox-enter-active,
398
- .m3-lightbox-leave-active {
399
- transition: opacity 0.2s ease;
400
- }
401
- .m3-lightbox-enter-from,
402
- .m3-lightbox-leave-to {
403
- opacity: 0;
404
- }
405
- </style>