bitboss-ui 3.0.0-beta.69 → 3.0.0-beta.70

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 (407) hide show
  1. package/README.md +20 -11
  2. package/bin/bitboss-ui-mcp.mjs +7 -4
  3. package/bin/bitboss-ui.mjs +0 -0
  4. package/bin/cli.mjs +47 -28
  5. package/dist/ai/BbBaseButton.md +4 -4
  6. package/dist/ai/BbCarousel.md +32 -29
  7. package/dist/ai/BbCheckboxGroup.md +15 -12
  8. package/dist/ai/BbColorInput.md +6 -10
  9. package/dist/ai/BbDropzone.md +3 -3
  10. package/dist/ai/BbGallery.md +2034 -0
  11. package/dist/ai/BbPopover.md +12 -6
  12. package/dist/ai/BbRadioGroup.md +18 -15
  13. package/dist/ai/BbRating.md +3 -7
  14. package/dist/ai/BbSwitchGroup.md +3 -3
  15. package/dist/ai/BbTextInput.md +8 -8
  16. package/dist/ai/OptionsContainer.md +10 -7
  17. package/dist/ai/changelog.json +80 -4
  18. package/dist/ai/components.json +19 -14
  19. package/dist/ai/guides/ai-router.md +3 -2
  20. package/dist/ai/guides/component-picker.md +1 -0
  21. package/dist/ai/guides/eslint-rules.md +3 -3
  22. package/dist/ai/guides/installation-and-plugin-setup.md +5 -5
  23. package/dist/ai/guides/migration/v2-to-v3.md +29 -1
  24. package/dist/ai/guides/migration/v3-beta-tooling.md +25 -15
  25. package/dist/ai/guides/passthrough.md +2 -1
  26. package/dist/ai/guides/preset-components.md +19 -10
  27. package/dist/ai/helpers/definePreset.ts +8 -4
  28. package/dist/ai/helpers/inertia/manifest.json +1 -1
  29. package/dist/ai/index.md +2 -1
  30. package/dist/ai/manifest/components/BbCarousel.json +3 -2
  31. package/dist/ai/manifest/components/BbCarousel.tree.json +7 -0
  32. package/dist/ai/manifest/components/BbCheckboxGroup.tree.json +13 -11
  33. package/dist/ai/manifest/components/BbConfigScope.json +1 -1
  34. package/dist/ai/manifest/components/BbGallery.json +54 -0
  35. package/dist/ai/manifest/components/BbGallery.tree.json +139 -0
  36. package/dist/ai/manifest/components/BbRadioGroup.tree.json +12 -10
  37. package/dist/ai/manifest/components/BbRating.removed.json +1 -1
  38. package/dist/ai/manifest/components/BbSlider.json +1 -1
  39. package/dist/ai/manifest/components/BbSwitchGroup.tree.json +1 -1
  40. package/dist/ai/manifest/components/BbTabs.removed.json +4 -4
  41. package/dist/ai/manifest/components/BbTabsList.removed.json +4 -4
  42. package/dist/ai/manifest/components/OptionsContainer.tree.json +10 -7
  43. package/dist/ai/manifest/index.json +4 -3
  44. package/dist/ai/manifest/meta.json +5 -1
  45. package/dist/ai/manifest/types.advanced.json +3 -1
  46. package/dist/ai/manifest/types.api.json +1 -1
  47. package/dist/ai/manifest/types.wrapper.json +1 -0
  48. package/dist/ai/recipes/inertia/onboarding.md +5 -8
  49. package/dist/ai/recipes/inertia/record-form.md +33 -12
  50. package/dist/ai/recipes/nuxt/onboarding.md +5 -8
  51. package/dist/ai/recipes/nuxt/record-form.md +27 -11
  52. package/dist/ai/recipes/vue/onboarding.md +5 -8
  53. package/dist/ai/recipes/vue/record-form.md +25 -11
  54. package/dist/ai/source/BbCalendar.md +2 -0
  55. package/dist/ai/source/BbCarousel.md +135 -32
  56. package/dist/ai/source/BbDropdown.md +2 -0
  57. package/dist/ai/source/BbDropdownGroup.md +2 -0
  58. package/dist/ai/source/BbGallery.md +2027 -0
  59. package/dist/ai/source/BbRadioGroup.md +2 -2
  60. package/dist/ai/source/BbSelectPopover.md +1 -0
  61. package/dist/ai/source/BbSwitchGroup.md +1 -0
  62. package/dist/ai/source/BbTable.md +11 -7
  63. package/dist/ai/source/BbTree.md +7 -3
  64. package/dist/ai/source/CommonPopover.md +13 -3
  65. package/dist/ai/source/FlatListBox.md +3 -3
  66. package/dist/ai/source/GroupedListBox.md +3 -3
  67. package/dist/ai/source/ListBox.md +4 -4
  68. package/dist/ai/source/OptionsContainer.md +4 -4
  69. package/dist/components/BbCalendar/useDayjsLocale.js +5 -3
  70. package/dist/components/BbCarousel/BbCarousel.vue.d.ts +1 -1
  71. package/dist/components/BbCarousel/BbCarousel.vue_vue_type_script_setup_true_lang.js +506 -481
  72. package/dist/components/BbCarousel/dragRelease.js +14 -0
  73. package/dist/components/BbCarousel/ptKeys.generated.d.ts +4 -0
  74. package/dist/components/BbCarousel/types.d.ts +11 -6
  75. package/dist/components/BbCarousel/types.js +1 -0
  76. package/dist/components/BbGallery/BbGallery.vue.d.ts +50 -0
  77. package/dist/components/BbGallery/BbGallery.vue.js +5 -0
  78. package/dist/components/BbGallery/BbGallery.vue_vue_type_script_setup_true_lang.js +587 -0
  79. package/dist/components/BbGallery/findItem.js +41 -0
  80. package/dist/components/BbGallery/ptKeys.generated.d.ts +112 -0
  81. package/dist/components/BbGallery/types.d.ts +177 -0
  82. package/dist/components/BbGallery/types.js +29 -0
  83. package/dist/components/BbOffCanvas/sheetSnap.d.ts +2 -0
  84. package/dist/components/BbOffCanvas/sheetSnap.js +5 -5
  85. package/dist/components/BbRadioGroup/types.d.ts +2 -2
  86. package/dist/components/BbTable/types.d.ts +7 -7
  87. package/dist/components/BbTree/types.d.ts +3 -3
  88. package/dist/components/CommonPopover/CommonPopover.vue_vue_type_script_setup_true_lang.js +28 -26
  89. package/dist/composables/overlayRegistry.d.ts +17 -0
  90. package/dist/composables/overlayRegistry.js +16 -9
  91. package/dist/composables/useChoiceIndicator.js +1 -1
  92. package/dist/deprecation/ai-deprecations.json.js +1 -1
  93. package/dist/directives/bbGallery.d.ts +64 -0
  94. package/dist/directives/bbGallery.js +38 -0
  95. package/dist/i18n/locales/ar.json +3 -1
  96. package/dist/i18n/locales/cs.json +3 -1
  97. package/dist/i18n/locales/da.json +3 -1
  98. package/dist/i18n/locales/de-CH.json +3 -1
  99. package/dist/i18n/locales/de.json +3 -1
  100. package/dist/i18n/locales/el.json +3 -1
  101. package/dist/i18n/locales/en-GB.json +3 -1
  102. package/dist/i18n/locales/en.json +3 -1
  103. package/dist/i18n/locales/es-MX.json +3 -1
  104. package/dist/i18n/locales/es.json +3 -1
  105. package/dist/i18n/locales/fa.json +3 -1
  106. package/dist/i18n/locales/fi.json +3 -1
  107. package/dist/i18n/locales/fr.json +3 -1
  108. package/dist/i18n/locales/he.json +3 -1
  109. package/dist/i18n/locales/hu.json +3 -1
  110. package/dist/i18n/locales/it.json +3 -1
  111. package/dist/i18n/locales/ja.json +3 -1
  112. package/dist/i18n/locales/ko.json +3 -1
  113. package/dist/i18n/locales/nb.json +3 -1
  114. package/dist/i18n/locales/nl.json +3 -1
  115. package/dist/i18n/locales/pl.json +3 -1
  116. package/dist/i18n/locales/pt-BR.json +3 -1
  117. package/dist/i18n/locales/pt-PT.json +3 -1
  118. package/dist/i18n/locales/ro.json +3 -1
  119. package/dist/i18n/locales/ru.json +3 -1
  120. package/dist/i18n/locales/sv.json +3 -1
  121. package/dist/i18n/locales/tr.json +3 -1
  122. package/dist/i18n/locales/uk.json +3 -1
  123. package/dist/i18n/locales/zh-CN.json +3 -1
  124. package/dist/i18n/locales/zh-HK.json +3 -1
  125. package/dist/i18n/locales/zh-TW.json +3 -1
  126. package/dist/index.d.ts +4 -0
  127. package/dist/index.js +38 -36
  128. package/dist/llms-full.txt +2328 -185
  129. package/dist/llms-medium.txt +10 -7
  130. package/dist/llms.txt +1 -1
  131. package/dist/locale-blueprint.json +3 -1
  132. package/dist/nuxt-auto-imports.js +1 -1
  133. package/dist/plugin.js +18 -17
  134. package/dist/project-dts.js +17 -16
  135. package/dist/runtime/nuxt-plugin.js +22 -21
  136. package/dist/scripts/lib/atomic-write.js +42 -0
  137. package/dist/styles.css +2 -2
  138. package/dist/types/passthrough.d.ts +2 -2
  139. package/dist/types/ptComponentMap.d.ts +2 -1
  140. package/dist/utilities/calendar/canonicalParts.js +10 -2
  141. package/dist/utils/versionCheck.js +1 -1
  142. package/dist/vite.js +361 -331
  143. package/llms.txt +2 -2
  144. package/package.json +2 -1
  145. package/scripts/README.md +25 -25
  146. package/scripts/lib/agent-refresh.mjs +15 -9
  147. package/scripts/lib/agent-setup.mjs +46 -15
  148. package/scripts/lib/atomic-write.d.mts +6 -0
  149. package/scripts/lib/atomic-write.mjs +85 -0
  150. package/scripts/lib/define-preset-copy.mjs +23 -3
  151. package/scripts/lib/eslint-plugin.mjs +74 -36
  152. package/scripts/lib/hand-imported-styles.mjs +44 -99
  153. package/scripts/lib/helpers-add.mjs +3 -1
  154. package/scripts/lib/linked-target.mjs +1 -1
  155. package/scripts/lib/locale-check.mjs +41 -25
  156. package/scripts/lib/mcp-config.mjs +250 -133
  157. package/scripts/lib/mcp-sdk.mjs +24 -0
  158. package/scripts/lib/plugin-options-check.mjs +22 -15
  159. package/scripts/lib/pnp.mjs +1 -1
  160. package/scripts/lib/project-variant-dts.mjs +80 -136
  161. package/scripts/lib/release-results.mjs +331 -0
  162. package/scripts/lib/setup.mjs +53 -3
  163. package/scripts/lib/toolchain-check.mjs +10 -8
  164. package/scripts/lib/tooling-options.mjs +357 -38
  165. package/dist/components/BbBadge/BadgeBodyContent.vue.d.ts +0 -15
  166. package/dist/components/BbBadge/badgeButtonContext.d.ts +0 -55
  167. package/dist/components/BbBaseButton/RouterComponent.vue.d.ts +0 -18
  168. package/dist/components/BbBaseButton/useLinkState.d.ts +0 -43
  169. package/dist/components/BbBreadcrumbs/estimateBreadcrumbItemWidth.d.ts +0 -18
  170. package/dist/components/BbButton/toggleRoving.d.ts +0 -6
  171. package/dist/components/BbCalendar/CalendarMonthPanel.vue.d.ts +0 -5
  172. package/dist/components/BbCalendar/CalendarYearPanel.vue.d.ts +0 -5
  173. package/dist/components/BbCalendar/calendarHost.d.ts +0 -29
  174. package/dist/components/BbCalendar/calendarMath.d.ts +0 -102
  175. package/dist/components/BbCalendar/useCalendarContext.d.ts +0 -116
  176. package/dist/components/BbCalendar/useCalendarGrid.d.ts +0 -411
  177. package/dist/components/BbCalendar/useDayGrid.d.ts +0 -122
  178. package/dist/components/BbCalendar/useDayjsLocale.d.ts +0 -93
  179. package/dist/components/BbCalendar/useToday.d.ts +0 -25
  180. package/dist/components/BbConfirm/BbConfirm.vue.d.ts +0 -4
  181. package/dist/components/BbConfirm/BbConfirmHost.d.ts +0 -10
  182. package/dist/components/BbConfirm/confirmEntry.d.ts +0 -4
  183. package/dist/components/BbDatePickerInput/calendarFields.d.ts +0 -91
  184. package/dist/components/BbDatePickerInput/dateFieldLayout.d.ts +0 -29
  185. package/dist/components/BbDialog/useDialogStack.d.ts +0 -19
  186. package/dist/components/BbDropdown/AdaptiveDropdown.vue.d.ts +0 -26
  187. package/dist/components/BbDropdown/BbDropdownList.vue.d.ts +0 -38
  188. package/dist/components/BbDropdown/DropdownPipelineResolver.vue.d.ts +0 -16
  189. package/dist/components/BbDropdown/DropdownRow.vue.d.ts +0 -41
  190. package/dist/components/BbDropdown/normalizeGroups.d.ts +0 -39
  191. package/dist/components/BbDropdown/pointerTrail.d.ts +0 -5
  192. package/dist/components/BbDropdown/useDropdownContext.d.ts +0 -131
  193. package/dist/components/BbDropdown/useDropdownGroupRegistry.d.ts +0 -170
  194. package/dist/components/BbForm/BbFormCustomField.d.ts +0 -14
  195. package/dist/components/BbForm/bindFormField.d.ts +0 -56
  196. package/dist/components/BbForm/formFields.d.ts +0 -77
  197. package/dist/components/BbHost/BbHostOpening.d.ts +0 -27
  198. package/dist/components/BbHoverCard/hoverCardFocus.d.ts +0 -29
  199. package/dist/components/BbIcon/iconCache.d.ts +0 -63
  200. package/dist/components/BbNumberInput/numberDisplay.d.ts +0 -255
  201. package/dist/components/BbNumberInput/platform.d.ts +0 -7
  202. package/dist/components/BbOffCanvas/hostCloseLabel.d.ts +0 -3
  203. package/dist/components/BbOffCanvas/sheetAttrs.d.ts +0 -9
  204. package/dist/components/BbOffCanvas/useOffCanvasStack.d.ts +0 -37
  205. package/dist/components/BbPagination/paginationFit.d.ts +0 -38
  206. package/dist/components/BbSelectPopover/knownItems.d.ts +0 -65
  207. package/dist/components/BbSelectPopover/reclickClears.d.ts +0 -17
  208. package/dist/components/BbSelectPopover/sheetChipAttrs.d.ts +0 -18
  209. package/dist/components/BbTable/BbTableDataRow.d.ts +0 -204
  210. package/dist/components/BbTable/BbTableEdgeRow.d.ts +0 -112
  211. package/dist/components/BbTable/BbTableExpandRow.d.ts +0 -84
  212. package/dist/components/BbTable/BbTableSelectToggle.d.ts +0 -128
  213. package/dist/components/BbTable/estimatedFloors.golden.d.ts +0 -25
  214. package/dist/components/BbTable/gridWidgets.d.ts +0 -30
  215. package/dist/components/BbTable/measuredFloors.d.ts +0 -46
  216. package/dist/components/BbTable/measuredFloorsTestKit.d.ts +0 -27
  217. package/dist/components/BbTable/textRuler.d.ts +0 -73
  218. package/dist/components/BbTable/useRowReorder.d.ts +0 -60
  219. package/dist/components/BbTable/utils.d.ts +0 -375
  220. package/dist/components/BbTabs/tablistName.d.ts +0 -4
  221. package/dist/components/BbToast/BbToast.vue.d.ts +0 -5
  222. package/dist/components/BbToast/BbToastMessage.vue.d.ts +0 -22
  223. package/dist/components/BbToast/BbToastRegion.vue.d.ts +0 -15
  224. package/dist/components/BbTooltip/tooltipWarmup.d.ts +0 -23
  225. package/dist/components/BbTree/BbTreeLevel.vue.d.ts +0 -19
  226. package/dist/components/BbTree/context.d.ts +0 -25
  227. package/dist/components/ChipsBox/ChipsBox.vue.d.ts +0 -21
  228. package/dist/components/ChipsBox/types.d.ts +0 -28
  229. package/dist/components/ClearableButton/ClearableButton.vue.d.ts +0 -6
  230. package/dist/components/ClearableButton/types.d.ts +0 -9
  231. package/dist/components/CloseIcon/CloseButton.vue.d.ts +0 -7
  232. package/dist/components/CloseIcon/types.d.ts +0 -2
  233. package/dist/components/CommaBox/CommaBox.vue.d.ts +0 -21
  234. package/dist/components/CommaBox/types.d.ts +0 -20
  235. package/dist/components/CommonField/CommonField.vue.d.ts +0 -20
  236. package/dist/components/CommonField/messageHeightMatrix.d.ts +0 -2
  237. package/dist/components/CommonFieldInput/CommonFieldInput.vue.d.ts +0 -22
  238. package/dist/components/CommonFieldInput/boxBorderMatrix.d.ts +0 -10
  239. package/dist/components/CommonFieldInput/types.d.ts +0 -114
  240. package/dist/components/CommonPopover/CommonPopover.vue.d.ts +0 -42
  241. package/dist/components/CommonPopover/resolvePlacement.d.ts +0 -9
  242. package/dist/components/CommonPopover/types.d.ts +0 -120
  243. package/dist/components/CommonTimeSelector/CommonTimeSelector.vue.d.ts +0 -48
  244. package/dist/components/CommonTimeSelector/useMeridiem.d.ts +0 -19
  245. package/dist/components/ErrorIcon/ErrorIcon.vue.d.ts +0 -7
  246. package/dist/components/ErrorIcon/types.d.ts +0 -3
  247. package/dist/components/FlatListBox/FlatListBox.vue.d.ts +0 -39
  248. package/dist/components/FlatListBox/types.d.ts +0 -140
  249. package/dist/components/GroupedListBox/GroupedListBox.vue.d.ts +0 -39
  250. package/dist/components/GroupedListBox/types.d.ts +0 -163
  251. package/dist/components/ListBox/ListBox.vue.d.ts +0 -39
  252. package/dist/components/ListBox/types.d.ts +0 -180
  253. package/dist/components/OptionsContainer/OptionsContainer.vue.d.ts +0 -20
  254. package/dist/components/OptionsContainer/types.d.ts +0 -168
  255. package/dist/components/Transitions/ScaleFade.vue.d.ts +0 -28
  256. package/dist/components/Transitions/Slide.vue.d.ts +0 -39
  257. package/dist/components/WarningIcon/WarningIcon.vue.d.ts +0 -7
  258. package/dist/components/WarningIcon/types.d.ts +0 -3
  259. package/dist/composables/__testResets.d.ts +0 -1
  260. package/dist/composables/autoHost.d.ts +0 -22
  261. package/dist/composables/formSubmitLock.d.ts +0 -48
  262. package/dist/composables/hostOpenings.d.ts +0 -88
  263. package/dist/composables/hostRegistry.d.ts +0 -47
  264. package/dist/composables/ssrMarker.d.ts +0 -15
  265. package/dist/composables/useActiveInactiveState.d.ts +0 -4
  266. package/dist/composables/useArray.d.ts +0 -7
  267. package/dist/composables/useBaseOptions.d.ts +0 -51
  268. package/dist/composables/useBodyScrollLock.d.ts +0 -4
  269. package/dist/composables/useBreakpoint.d.ts +0 -13
  270. package/dist/composables/useCancelableFunction.d.ts +0 -17
  271. package/dist/composables/useChoiceIndicator.d.ts +0 -58
  272. package/dist/composables/useClosingInert.d.ts +0 -28
  273. package/dist/composables/useCoarsePointer.d.ts +0 -9
  274. package/dist/composables/useCoherence.d.ts +0 -21
  275. package/dist/composables/useConfig.d.ts +0 -59
  276. package/dist/composables/useConfigDefaults.d.ts +0 -54
  277. package/dist/composables/useDirection.d.ts +0 -43
  278. package/dist/composables/useEscapeStackEntry.d.ts +0 -13
  279. package/dist/composables/useFrameworkDetection.d.ts +0 -12
  280. package/dist/composables/useHashedWatcher.d.ts +0 -19
  281. package/dist/composables/useHydrated.d.ts +0 -37
  282. package/dist/composables/useImeDismissBlur.d.ts +0 -103
  283. package/dist/composables/useIndexById.d.ts +0 -11
  284. package/dist/composables/useInertiaPage.d.ts +0 -10
  285. package/dist/composables/useItemText.d.ts +0 -17
  286. package/dist/composables/useItemValue.d.ts +0 -7
  287. package/dist/composables/useItemsGetter.d.ts +0 -83
  288. package/dist/composables/useKeyboardInset.d.ts +0 -28
  289. package/dist/composables/useListboxFocus.d.ts +0 -21
  290. package/dist/composables/useLocale.d.ts +0 -5
  291. package/dist/composables/useLogger.d.ts +0 -5
  292. package/dist/composables/useMinimalQueue.d.ts +0 -9
  293. package/dist/composables/useOnFalsy.d.ts +0 -2
  294. package/dist/composables/useOnTruthy.d.ts +0 -7
  295. package/dist/composables/useOverlayNavigation.d.ts +0 -37
  296. package/dist/composables/useOverlayYield.d.ts +0 -23
  297. package/dist/composables/usePrefill.d.ts +0 -44
  298. package/dist/composables/useQuery.d.ts +0 -39
  299. package/dist/composables/useRefusedCloseAnnouncement.d.ts +0 -13
  300. package/dist/composables/useRoute.d.ts +0 -3
  301. package/dist/composables/useRouter.d.ts +0 -2
  302. package/dist/composables/useSegmentedFields.d.ts +0 -129
  303. package/dist/composables/useServerPrefetch.d.ts +0 -28
  304. package/dist/composables/useSheetSurface.d.ts +0 -39
  305. package/dist/composables/useSsrState.d.ts +0 -28
  306. package/dist/composables/useTableWidthContext.d.ts +0 -73
  307. package/dist/composables/useToggleInput.d.ts +0 -44
  308. package/dist/composables/useTopLayer.d.ts +0 -9
  309. package/dist/composables/useTypeahead.d.ts +0 -112
  310. package/dist/composables/useUntil.d.ts +0 -7
  311. package/dist/composables/useUrlQueryParam.d.ts +0 -21
  312. package/dist/composables/useViewportWidth.d.ts +0 -14
  313. package/dist/deprecation/ai-deprecations.json.d.ts +0 -2984
  314. package/dist/deprecation/removedProps.d.ts +0 -3
  315. package/dist/directives/createPopoverDirective.d.ts +0 -111
  316. package/dist/directives/renderingInstance.d.ts +0 -2
  317. package/dist/i18n/eraNames.d.ts +0 -2
  318. package/dist/i18n/regionHints.d.ts +0 -16
  319. package/dist/icons-whitelist.d.ts +0 -9
  320. package/dist/reset.d.ts +0 -0
  321. package/dist/runtime/nuxt-plugin.d.ts +0 -2
  322. package/dist/styles.d.ts +0 -0
  323. package/dist/types/ExtractGenericFromComputedRef.d.ts +0 -2
  324. package/dist/types/ExtractGenericFromRef.d.ts +0 -2
  325. package/dist/types/NestedKeyOf.d.ts +0 -3
  326. package/dist/types/PrefixWith.d.ts +0 -1
  327. package/dist/types/ShapeErased.d.ts +0 -15
  328. package/dist/types/Simplify.d.ts +0 -6
  329. package/dist/utilities/calendar/canonicalParts.d.ts +0 -29
  330. package/dist/utilities/calendar/digits.d.ts +0 -18
  331. package/dist/utilities/calendar/gregorian.d.ts +0 -2
  332. package/dist/utilities/calendar/index.d.ts +0 -3
  333. package/dist/utilities/calendar/international.d.ts +0 -19
  334. package/dist/utilities/calendar/resolve.d.ts +0 -32
  335. package/dist/utilities/calendar/runtime.d.ts +0 -49
  336. package/dist/utilities/functions/animationsSettled.d.ts +0 -7
  337. package/dist/utilities/functions/bytesToUnit.d.ts +0 -2
  338. package/dist/utilities/functions/chunk.d.ts +0 -1
  339. package/dist/utilities/functions/clamp.d.ts +0 -9
  340. package/dist/utilities/functions/clampPrecision.d.ts +0 -1
  341. package/dist/utilities/functions/convertDateValue.d.ts +0 -57
  342. package/dist/utilities/functions/curry.d.ts +0 -6
  343. package/dist/utilities/functions/deburr.d.ts +0 -1
  344. package/dist/utilities/functions/elementLabel.d.ts +0 -8
  345. package/dist/utilities/functions/empty.d.ts +0 -1
  346. package/dist/utilities/functions/extractDomContainer.d.ts +0 -20
  347. package/dist/utilities/functions/findInTree.d.ts +0 -4
  348. package/dist/utilities/functions/flattenTree.d.ts +0 -1
  349. package/dist/utilities/functions/get.d.ts +0 -3
  350. package/dist/utilities/functions/hasVnodeListener.d.ts +0 -16
  351. package/dist/utilities/functions/hash.d.ts +0 -1
  352. package/dist/utilities/functions/head.d.ts +0 -2
  353. package/dist/utilities/functions/identity.d.ts +0 -1
  354. package/dist/utilities/functions/indexBy.d.ts +0 -11
  355. package/dist/utilities/functions/isDateDisabled.d.ts +0 -25
  356. package/dist/utilities/functions/isEqual.d.ts +0 -1
  357. package/dist/utilities/functions/isHex.d.ts +0 -1
  358. package/dist/utilities/functions/isImeComposing.d.ts +0 -7
  359. package/dist/utilities/functions/isNil.d.ts +0 -6
  360. package/dist/utilities/functions/isNotEmpty.d.ts +0 -1
  361. package/dist/utilities/functions/isNotNil.d.ts +0 -6
  362. package/dist/utilities/functions/isTextEntry.d.ts +0 -5
  363. package/dist/utilities/functions/isoWeek.d.ts +0 -36
  364. package/dist/utilities/functions/itemProps.d.ts +0 -46
  365. package/dist/utilities/functions/last.d.ts +0 -2
  366. package/dist/utilities/functions/negative.d.ts +0 -1
  367. package/dist/utilities/functions/noop.d.ts +0 -1
  368. package/dist/utilities/functions/normalizeDateBound.d.ts +0 -69
  369. package/dist/utilities/functions/parsePaginationNumber.d.ts +0 -22
  370. package/dist/utilities/functions/parseSize.d.ts +0 -3
  371. package/dist/utilities/functions/parseWidthString.d.ts +0 -6
  372. package/dist/utilities/functions/percentage.d.ts +0 -26
  373. package/dist/utilities/functions/pickBy.d.ts +0 -1
  374. package/dist/utilities/functions/range.d.ts +0 -1
  375. package/dist/utilities/functions/readableValue.d.ts +0 -6
  376. package/dist/utilities/functions/reject.d.ts +0 -25
  377. package/dist/utilities/functions/resolveEnumProp.d.ts +0 -19
  378. package/dist/utilities/functions/responsiveDefault.d.ts +0 -7
  379. package/dist/utilities/functions/searchRank.d.ts +0 -19
  380. package/dist/utilities/functions/settlesVisible.d.ts +0 -20
  381. package/dist/utilities/functions/snapToStep.d.ts +0 -1
  382. package/dist/utilities/functions/sort.d.ts +0 -6
  383. package/dist/utilities/functions/throttle.d.ts +0 -1
  384. package/dist/utilities/functions/toggleInput.d.ts +0 -114
  385. package/dist/utilities/functions/transpose.d.ts +0 -1
  386. package/dist/utilities/functions/validateDateFormat.d.ts +0 -8
  387. package/dist/utilities/functions/wait.d.ts +0 -2
  388. package/dist/utilities/functions/waitFor.d.ts +0 -9
  389. package/dist/utilities/functions/warnRemovedAttrs.d.ts +0 -49
  390. package/dist/utilities/functions/when.d.ts +0 -9
  391. package/dist/utilities/misc/autofocus.d.ts +0 -20
  392. package/dist/utilities/misc/iconsInjectionKey.d.ts +0 -15
  393. package/dist/utilities/misc/listboxMetrics.d.ts +0 -47
  394. package/dist/utilities/misc/maskaDataOptions.d.ts +0 -12
  395. package/dist/utilities/misc/pageText.d.ts +0 -16
  396. package/dist/utilities/misc/ssrValue.d.ts +0 -20
  397. package/dist/utilities/misc/transitions.d.ts +0 -5
  398. package/dist/utils/configDefaults.d.ts +0 -43
  399. package/dist/utils/configScope.d.ts +0 -43
  400. package/dist/utils/copyData.d.ts +0 -13
  401. package/dist/utils/focusVisibility.d.ts +0 -15
  402. package/dist/utils/injectLibraryStyles.d.ts +0 -8
  403. package/dist/utils/overlayEscapeStack.d.ts +0 -52
  404. package/dist/utils/overlaySurfaceIsolation.d.ts +0 -1
  405. package/dist/utils/passthroughDeduper.d.ts +0 -16
  406. package/dist/utils/releasedActivator.d.ts +0 -20
  407. package/dist/utils/versionCheck.d.ts +0 -19
@@ -0,0 +1,2027 @@
1
+ # BbGallery — Implementation Source
2
+
3
+ > Full implementation for deep dives. For everyday usage read the typed contract: [../BbGallery.md](../BbGallery.md).
4
+
5
+ ## Template & Script
6
+
7
+ ```vue
8
+ <template>
9
+ <!-- Its own modal, not a BbDialog: a native <dialog> shown with showModal()
10
+ for the top layer and the inert page, and nothing else of a dialog's.
11
+ `pt` binds LAST so a consumer listener runs after ours (PASSTHROUGH.md T17). -->
12
+ <!-- eslint-disable vue/attributes-order -->
13
+ <dialog
14
+ ref="root"
15
+ :aria-labelledby="mounted ? titleId : undefined"
16
+ class="bb-gallery"
17
+ :class="{
18
+ 'bb-gallery--open': isOpen,
19
+ 'bb-gallery--visible': visible,
20
+ 'bb-gallery--zoomed': zoomed,
21
+ 'bb-gallery--quiet': quiet,
22
+ 'bb-gallery--dismissing': dismissY > 0,
23
+ 'bb-gallery--gesture': gesturing,
24
+ }"
25
+ :inert="!isOpen || undefined"
26
+ :style="[
27
+ pageStyle,
28
+ dismissY > 0
29
+ ? { '--dismiss': dismissProgress, '--dismiss-y': `${dismissY}px` }
30
+ : undefined,
31
+ ]"
32
+ v-on="overlaySurfaceIsolation"
33
+ @cancel="onCancel"
34
+ @close="onNativeClose"
35
+ @keydown="onKeydown"
36
+ @pointerdown="onRootPointerDown"
37
+ v-bind="passthrough.rootAttrs"
38
+ >
39
+ <!-- eslint-enable vue/attributes-order -->
40
+ <template v-if="mounted">
41
+ <div class="bb-gallery__header" v-bind="passthrough.header">
42
+ <slot
43
+ v-bind="slotProps"
44
+ name="header"
45
+ :title="title"
46
+ :title-id="titleId"
47
+ >
48
+ <p
49
+ :id="titleId"
50
+ class="bb-gallery__title"
51
+ :class="{ 'bb-sr-only': !hasTitle }"
52
+ v-bind="passthrough.title"
53
+ >
54
+ <slot v-bind="slotProps" name="title" :text="title">{{
55
+ name
56
+ }}</slot>
57
+ </p>
58
+ <CloseButton
59
+ :aria-label="t('dialog.closeLabel').value"
60
+ class="bb-gallery__close"
61
+ v-bind="passthrough.close"
62
+ @click="close"
63
+ />
64
+ </slot>
65
+ </div>
66
+
67
+ <div class="bb-gallery__stage" tabindex="-1" @click="onStageClick">
68
+ <div
69
+ ref="track"
70
+ class="bb-gallery__track"
71
+ tabindex="-1"
72
+ @pointercancel="onPointerEnd"
73
+ @pointerdown="onPointerDown"
74
+ @pointermove="onPointerMove"
75
+ @pointerup="onPointerEnd"
76
+ @scroll.passive="onScroll"
77
+ @scrollend="onScrollEnd"
78
+ >
79
+ <figure
80
+ v-for="slide in slides"
81
+ :key="slide.key"
82
+ :aria-hidden="slide.clone || slide.real !== index || undefined"
83
+ :aria-label="slide.clone ? undefined : position(slide.real)"
84
+ :aria-roledescription="slide.clone ? undefined : 'slide'"
85
+ class="bb-gallery__slide"
86
+ :class="{
87
+ 'bb-gallery__slide--active': !slide.clone && slide.real === index,
88
+ }"
89
+ :inert="slide.clone || slide.real !== index || undefined"
90
+ :role="slide.clone ? undefined : 'group'"
91
+ v-bind="
92
+ passthrough.part(
93
+ 'slide',
94
+ { active: !slide.clone && slide.real === index },
95
+ slide.item
96
+ )
97
+ "
98
+ >
99
+ <div class="bb-gallery__frame">
100
+ <p
101
+ v-if="failed.has(slide.item.key)"
102
+ :aria-hidden="!slide.item.alt || undefined"
103
+ class="bb-gallery__missing"
104
+ :class="{ 'bb-gallery__missing--blank': !slide.item.alt }"
105
+ >
106
+ {{ slide.item.alt }}
107
+ </p>
108
+ <img
109
+ v-else
110
+ :alt="slide.item.alt"
111
+ class="bb-gallery__image"
112
+ :class="{
113
+ 'bb-gallery__image--sized': !!(
114
+ slide.item.width && slide.item.height
115
+ ),
116
+ }"
117
+ decoding="async"
118
+ draggable="false"
119
+ :fetchpriority="
120
+ !slide.clone && slide.real === index ? 'high' : undefined
121
+ "
122
+ :height="slide.item.height"
123
+ :loading="near(slide) ? 'eager' : 'lazy'"
124
+ :sizes="
125
+ slide.item.srcset ? (slide.item.sizes ?? '100vw') : undefined
126
+ "
127
+ :src="slide.item.src"
128
+ :srcset="slide.item.srcset"
129
+ :style="imageStyle(slide)"
130
+ :width="slide.item.width"
131
+ v-bind="passthrough.image"
132
+ @error="onError(slide.item.key)"
133
+ @load="onLoad"
134
+ />
135
+ </div>
136
+ </figure>
137
+ </div>
138
+
139
+ <template v-if="items.length > 1">
140
+ <button
141
+ :aria-label="t('gallery.previous').value"
142
+ class="bb-gallery__nav bb-gallery__nav--prev"
143
+ :disabled="atStart"
144
+ type="button"
145
+ v-bind="passthrough.part('prev', { disabled: atStart })"
146
+ @click="step(-1)"
147
+ >
148
+ <BbIcon :icon="chevronLeft" size="24px" />
149
+ </button>
150
+ <button
151
+ :aria-label="t('gallery.next').value"
152
+ class="bb-gallery__nav bb-gallery__nav--next"
153
+ :disabled="atEnd"
154
+ type="button"
155
+ v-bind="passthrough.part('next', { disabled: atEnd })"
156
+ @click="step(1)"
157
+ >
158
+ <BbIcon :icon="chevronRight" size="24px" />
159
+ </button>
160
+ </template>
161
+
162
+ <!-- What a screen reader hears as you step: the position and the photo. -->
163
+ <p aria-live="polite" class="bb-sr-only">{{ announcement }}</p>
164
+ </div>
165
+
166
+ <div
167
+ v-if="$slots.footer || items.length > 1 || anyCaption"
168
+ class="bb-gallery__footer"
169
+ v-bind="passthrough.footer"
170
+ >
171
+ <!-- One line, always the same height: the caption centred (equal
172
+ side columns, so the counter's width never moves it), the
173
+ counter at the end. With a `#footer` slot this row keeps
174
+ the caption — there whenever any photo has one — and the
175
+ slot owns the row below it. Read in full, the caption runs
176
+ on upward from the same line, on the viewer's own plate. -->
177
+ <div v-if="!$slots.footer || anyCaption" class="bb-gallery__bar">
178
+ <p
179
+ v-if="currentCaption"
180
+ :id="captionId"
181
+ class="bb-gallery__caption"
182
+ :class="{ 'bb-gallery__caption--open': captionOpen }"
183
+ :tabindex="captionOpen ? 0 : undefined"
184
+ v-bind="passthrough.caption"
185
+ >
186
+ <span ref="captionEl" class="bb-gallery__caption-text">{{
187
+ currentCaption
188
+ }}</span>
189
+ <button
190
+ v-if="captionOverflows || captionOpen"
191
+ :aria-controls="captionId"
192
+ :aria-expanded="captionOpen"
193
+ class="bb-gallery__more"
194
+ type="button"
195
+ v-bind="passthrough.more"
196
+ @click="captionOpen = !captionOpen"
197
+ >
198
+ {{
199
+ captionOpen ? t('gallery.less').value : t('gallery.more').value
200
+ }}
201
+ </button>
202
+ </p>
203
+ <p
204
+ v-if="!$slots.footer && items.length > 1"
205
+ aria-hidden="true"
206
+ class="bb-gallery__counter"
207
+ v-bind="passthrough.counter"
208
+ >
209
+ {{ index + 1 }} / {{ items.length }}
210
+ </p>
211
+ </div>
212
+ <slot v-if="$slots.footer" v-bind="slotProps" name="footer" />
213
+ </div>
214
+ </template>
215
+ </dialog>
216
+ </template>
217
+
218
+ <script setup lang="ts" generic="T extends BbGalleryItem = BbGalleryItem">
219
+ import {
220
+ computed,
221
+ getCurrentInstance,
222
+ nextTick,
223
+ onBeforeUnmount,
224
+ onMounted,
225
+ reactive,
226
+ ref,
227
+ useAttrs,
228
+ useSlots,
229
+ watch,
230
+ } from 'vue';
231
+ import BbIcon from '../BbIcon/BbIcon.vue';
232
+ import CloseButton from '../CloseIcon/CloseButton.vue';
233
+ import chevronLeft from '@/assets/svgs/chevron_left.svg?raw';
234
+ import chevronRight from '@/assets/svgs/chevron_right.svg?raw';
235
+ import {
236
+ returnFocusToOpener,
237
+ rootElementOf,
238
+ useOverlayHost,
239
+ } from '@/composables/overlayRegistry';
240
+ import { useBodyScrollLock } from '@/composables/useBodyScrollLock';
241
+ import { useId } from '@/composables/useId';
242
+ import { useLocale } from '@/composables/useLocale';
243
+ import { useLogger } from '@/composables/useLogger';
244
+ import { usePassthrough } from '@/composables/usePassthrough';
245
+ import { registerTopLayerHost } from '@/composables/useTopLayer';
246
+ import {
247
+ registerGalleryPreload,
248
+ takeGalleryTrigger,
249
+ } from '@/directives/bbGallery';
250
+ import { animationsSettled } from '@/utilities/functions/animationsSettled';
251
+ import { wait } from '@/utilities/functions/wait';
252
+ import { pageText } from '@/utilities/misc/pageText';
253
+ import { transitions } from '@/utilities/misc/transitions';
254
+ import {
255
+ isTopEscapeEntry,
256
+ pushEscapeEntry,
257
+ removeEscapeEntry,
258
+ } from '@/utils/overlayEscapeStack';
259
+ import { overlaySurfaceIsolation } from '@/utils/overlaySurfaceIsolation';
260
+ import { findGalleryItem, toPhoto, type GalleryPhoto } from './findItem';
261
+ import {
262
+ BB_GALLERY_PT,
263
+ type BbGalleryItem,
264
+ type BbGalleryProps,
265
+ type BbGallerySlotProps,
266
+ type BbGallerySlots,
267
+ } from './types';
268
+ export type {
269
+ BbGalleryEvents,
270
+ BbGalleryHeaderSlotProps,
271
+ BbGalleryItem,
272
+ BbGalleryProps,
273
+ BbGallerySlotProps,
274
+ BbGallerySlots,
275
+ BbGalleryTitleSlotProps,
276
+ } from './types';
277
+
278
+ defineOptions({ inheritAttrs: false });
279
+
280
+ /**
281
+ * The photo in the viewer, `null` while it is closed. Bind it to open the
282
+ * viewer yourself; `v-bb-gallery` opens it without one.
283
+ *
284
+ * @defaultValue `null`
285
+ */
286
+ const model = defineModel<number | null>({ default: null });
287
+
288
+ const props = defineProps<BbGalleryProps<T>>();
289
+ defineSlots<BbGallerySlots<T>>();
290
+ const slots = useSlots();
291
+
292
+ const { t } = useLocale();
293
+
294
+ /** The entries as the viewer uses them (a URL string as `{ src }`). */
295
+ const photos = computed(() => props.items.map(toPhoto));
296
+ const count = computed(() => photos.value.length);
297
+ const isOpen = computed(() => model.value !== null && count.value > 0);
298
+ /** The index shown, clamped; 0 while closed. */
299
+ const index = computed(() =>
300
+ model.value === null
301
+ ? 0
302
+ : Math.min(
303
+ Math.max(Math.trunc(model.value), 0),
304
+ Math.max(count.value - 1, 0)
305
+ )
306
+ );
307
+ const looping = computed(() => !!props.loop && count.value > 1);
308
+ const atStart = computed(() => !looping.value && index.value === 0);
309
+ const atEnd = computed(() => !looping.value && index.value === count.value - 1);
310
+ const hasTitle = computed(() => !!props.title || !!slots.title);
311
+ const name = computed(() => props.title || t('gallery.label').value);
312
+ const position = (i: number) => t('gallery.position', i + 1, count.value).value;
313
+
314
+ const zoom = reactive({ scale: 1, x: 0, y: 0 });
315
+ const zoomed = computed(() => zoom.scale > 1.01);
316
+
317
+ const passthrough = usePassthrough({
318
+ component: 'BbGallery',
319
+ attrs: useAttrs(),
320
+ props,
321
+ parts: BB_GALLERY_PT.parts,
322
+ states: BB_GALLERY_PT.states,
323
+ active: { zoomed: () => zoomed.value },
324
+ });
325
+
326
+ /* ---- Opening: v-model, or `v-bb-gallery` by id ---------------------------- */
327
+
328
+ const instance = getCurrentInstance();
329
+ /** The element the viewer opened from: focus returns there. */
330
+ let opener: HTMLElement | null = null;
331
+ /** Whether the overlay host owns focus return (an opening by `v-bb-gallery`). */
332
+ let hostOpened = false;
333
+
334
+ const warn = (message: string) => {
335
+ if (process.env.NODE_ENV !== 'production') useLogger().warn(message);
336
+ };
337
+
338
+ const overlay = useOverlayHost('gallery', {
339
+ id: () => props.id,
340
+ // The host opens and closes through this; `data` is the trigger's `item`.
341
+ model: computed({
342
+ get: () => isOpen.value,
343
+ set: (open: boolean) => {
344
+ if (!open) return void (model.value = null);
345
+ const item = overlay.data.value as number | string | undefined;
346
+ const found = findGalleryItem(photos.value, item);
347
+ if (found < 0) {
348
+ warn(
349
+ `v-bb-gallery="{ id: '${props.id}', item: ${JSON.stringify(item)} }" opens nothing: no photo of <BbGallery id="${props.id}"> has that ${typeof item === 'number' ? 'index' : 'URL (its src or a srcset candidate)'}. Pass the index, or one of the item's URLs.`
350
+ );
351
+ return;
352
+ }
353
+ hostOpened = true;
354
+ opener = takeGalleryTrigger();
355
+ model.value = found;
356
+ },
357
+ }),
358
+ element: () => rootElementOf(instance),
359
+ });
360
+
361
+ // The viewer's DOM id is the gallery's id (the triggers' `aria-controls`).
362
+ // The inner dialog gets none of its own: it must not answer `v-bb-dialog`.
363
+ const syncDomId = () => {
364
+ const el = rootElementOf(instance);
365
+ if (!el) return;
366
+ if (overlay.domId.value) el.id = overlay.domId.value;
367
+ else el.removeAttribute('id');
368
+ };
369
+ onMounted(syncDomId);
370
+ watch(() => overlay.domId.value, syncDomId);
371
+
372
+ /*
373
+ * A trigger hovered or focused: the photo it names starts loading, with the
374
+ * same `srcset` / `sizes` the viewer asks for (one fetch, reused by the slide).
375
+ */
376
+ const warmed = new Set<string>();
377
+ const warm = (item: number | string | undefined) => {
378
+ if (isOpen.value || typeof Image !== 'function') return;
379
+ const photo = photos.value[findGalleryItem(photos.value, item)];
380
+ if (!photo || warmed.has(photo.key)) return;
381
+ warmed.add(photo.key);
382
+ const img = new Image();
383
+ img.decoding = 'async';
384
+ if (photo.srcset) {
385
+ img.sizes = photo.sizes ?? '100vw';
386
+ img.srcset = photo.srcset;
387
+ }
388
+ if (photo.src) img.src = photo.src;
389
+ };
390
+ let releasePreload: (() => void) | undefined;
391
+ onMounted(() => {
392
+ const el = rootElementOf(instance);
393
+ if (el) releasePreload = registerGalleryPreload(el, warm);
394
+ });
395
+
396
+ watch(isOpen, (open) => {
397
+ if (!open) return;
398
+ failed.clear(); // a reopening retries files that failed before
399
+ if (!hostOpened) {
400
+ // Opened through v-model: focus goes back to what had it.
401
+ const active = document.activeElement;
402
+ opener =
403
+ active instanceof HTMLElement && active !== document.body ? active : null;
404
+ }
405
+ });
406
+
407
+ const close = () => {
408
+ model.value = null;
409
+ };
410
+
411
+ const go = (i: number) => {
412
+ if (Number.isInteger(i) && i >= 0 && i < count.value) model.value = i;
413
+ };
414
+
415
+ const slotProps = computed<BbGallerySlotProps<T>>(() => {
416
+ const { key: _key, ...item } = photos.value[index.value] ?? { key: '' };
417
+ return {
418
+ index: index.value,
419
+ count: count.value,
420
+ item: item as T,
421
+ go,
422
+ close,
423
+ };
424
+ });
425
+
426
+ /* ---- Slides (a clone at each end with `loop`) ----------------------------- */
427
+
428
+ type Slide = { item: GalleryPhoto; real: number; clone: boolean; key: string };
429
+
430
+ /** Keys by the photo's URL (+ occurrence): a reordered list keeps each photo's slide. */
431
+ const slides = computed<Slide[]>(() => {
432
+ const seen = new Map<string, number>();
433
+ const real = photos.value.map((item, i) => {
434
+ const n = seen.get(item.key) ?? 0;
435
+ seen.set(item.key, n + 1);
436
+ return { item, real: i, clone: false, key: `${item.key}#${n}` };
437
+ });
438
+ if (!looping.value) return real;
439
+ const last = real[real.length - 1];
440
+ const first = real[0];
441
+ return [
442
+ { ...last, clone: true, key: `clone-start:${last.key}` },
443
+ ...real,
444
+ { ...first, clone: true, key: `clone-end:${first.key}` },
445
+ ];
446
+ });
447
+
448
+ /** The track position of photo `i` (clones shift it by one). */
449
+ const positionOf = (i: number) => i + (looping.value ? 1 : 0);
450
+ /** The photo at track position `p`. */
451
+ const realOf = (p: number) => {
452
+ const n = count.value;
453
+ if (!looping.value) return Math.min(Math.max(p, 0), n - 1);
454
+ return (((p - 1) % n) + n) % n;
455
+ };
456
+
457
+ /** The shown photo and its neighbours load at once; the rest lazily. */
458
+ const near = (slide: Slide) => {
459
+ const n = count.value;
460
+ const d = Math.abs(slide.real - index.value);
461
+ return d <= 1 || (looping.value && n - d <= 1);
462
+ };
463
+
464
+ /*
465
+ * With `width` / `height` the photo's box exists before the file: the frame
466
+ * is a size container, and the image takes the largest box of its ratio
467
+ * that fits, capped at its own size (never upscaled).
468
+ */
469
+ const imageStyle = (slide: Slide) => {
470
+ const { width, height } = slide.item;
471
+ const shownNow = !slide.clone && slide.real === index.value;
472
+ const style: Record<string, string> = {};
473
+ if (width && height) {
474
+ style['--arw'] = String(width);
475
+ style['--arh'] = String(height);
476
+ style['--w'] = `${width}px`;
477
+ }
478
+ if (shownNow && zoomed.value)
479
+ style.transform = `translate(${zoom.x}px, ${zoom.y}px) scale(${zoom.scale})`;
480
+ return style;
481
+ };
482
+
483
+ /* ---- The track: native scroll-snap, the index follows it ----------------- */
484
+
485
+ const track = ref<HTMLElement | null>(null);
486
+ /** The dialog is in the top layer: before that the track's width is the page's. */
487
+ let shown = false;
488
+ /** The track position a button, a key or the v-model is moving to. */
489
+ let target: number | null = null;
490
+ let pointerDown = false;
491
+
492
+ const rtl = () =>
493
+ !!track.value && getComputedStyle(track.value).direction === 'rtl';
494
+ const width = () => track.value?.clientWidth ?? 0;
495
+ /** The track's position in slides, fractional mid-move. */
496
+ const at = () => {
497
+ const w = width();
498
+ return w ? Math.abs(track.value!.scrollLeft) / w : 0;
499
+ };
500
+ const nearest = () => Math.round(at());
501
+
502
+ const reducedMotion = () =>
503
+ typeof matchMedia === 'function' &&
504
+ matchMedia('(prefers-reduced-motion: reduce)').matches;
505
+
506
+ /** Where our last write left the track, and at what width: a scroll
507
+ * position that has since moved at the same width was moved by the reader
508
+ * (a swipe, a trackpad), not by us or by a relayout. Read at `onShown`. */
509
+ let lastWrite: { left: number; width: number } | null = null;
510
+
511
+ const scrollTo = (p: number) => {
512
+ const el = track.value;
513
+ if (!el) return;
514
+ el.scrollTo({
515
+ left: (rtl() ? -1 : 1) * p * width(),
516
+ behavior: 'instant',
517
+ });
518
+ lastWrite = { left: el.scrollLeft, width: width() };
519
+ };
520
+
521
+ /** Fades the photo now shown in where it stands; still under reduced motion. */
522
+ const fadeIn = () => {
523
+ if (reducedMotion()) return;
524
+ void nextTick(() => {
525
+ track.value
526
+ ?.querySelector('.bb-gallery__slide--active')
527
+ ?.animate([{ opacity: 0 }, { opacity: 1 }], {
528
+ duration: 200,
529
+ easing: 'ease-out',
530
+ });
531
+ });
532
+ };
533
+
534
+ /**
535
+ * Puts the track there at once and fades the photo in: a button, a key or
536
+ * the v-model never slides the photos sideways. Only a swipe moves the track.
537
+ */
538
+ const moveTo = (p: number) => {
539
+ target = p;
540
+ scrollTo(p);
541
+ if (nearest() === p) target = null;
542
+ fadeIn();
543
+ };
544
+
545
+ /** Puts the track on the photo shown at once (opening, a resize). */
546
+ const jump = () => {
547
+ if (!track.value || !width()) return;
548
+ target = null;
549
+ scrollTo(positionOf(index.value));
550
+ };
551
+
552
+ /** At rest on a clone: the same photo, silently, at its real place. */
553
+ const settleClone = () => {
554
+ if (!looping.value || target !== null || pointerDown) return;
555
+ const p = nearest();
556
+ if (p !== 0 && p !== count.value + 1) return;
557
+ if (Math.abs(at() - p) > 0.01) return;
558
+ scrollTo(positionOf(realOf(p)));
559
+ };
560
+
561
+ /*
562
+ * An index the track is not heading to (the v-model, `go`) slides it
563
+ * there. One the track produced, or a move already under way to it, is left
564
+ * alone. A move under way to somewhere else is re-aimed (a second key press
565
+ * mid-slide is never lost).
566
+ */
567
+ watch(index, (i) => {
568
+ if (!track.value || !isOpen.value) return;
569
+ resetZoom();
570
+ if (target !== null ? realOf(target) === i : realOf(nearest()) === i) return;
571
+ moveTo(positionOf(i));
572
+ });
573
+
574
+ /** One step; with `loop`, past an end wraps to the other. */
575
+ const step = (d: number) => {
576
+ const n = count.value;
577
+ go(looping.value ? (((index.value + d) % n) + n) % n : index.value + d);
578
+ };
579
+
580
+ /*
581
+ * The track is the source of truth while it moves: a swipe or a trackpad
582
+ * scroll it, and the nearest slide becomes the index. Read once per frame,
583
+ * and only once the viewer is in the top layer (before that a re-snap to the
584
+ * new width is not a swipe).
585
+ */
586
+ let frame = 0;
587
+ /** `scrollend` where the browser has it (not iOS before 26); a quiet period elsewhere. */
588
+ let endTimer: ReturnType<typeof setTimeout> | undefined;
589
+ const onScroll = () => {
590
+ clearTimeout(endTimer);
591
+ endTimer = setTimeout(onScrollEnd, 150);
592
+ if (frame) return;
593
+ frame = requestAnimationFrame(() => {
594
+ frame = 0;
595
+ if (!track.value || !isOpen.value || !width() || !shown) return;
596
+ const p = nearest();
597
+ if (target !== null) {
598
+ if (p === target) target = null;
599
+ else return;
600
+ }
601
+ const real = realOf(p);
602
+ if (real !== index.value) model.value = real;
603
+ settleClone();
604
+ });
605
+ };
606
+ const onScrollEnd = () => {
607
+ clearTimeout(endTimer);
608
+ if (target !== null && nearest() === target) target = null;
609
+ settleClone();
610
+ };
611
+
612
+ // A width change (rotation, a window drag) keeps the photo; so does the
613
+ // top-layer promotion while opening. Observed from the moment it mounts.
614
+ let resize: ResizeObserver | null = null;
615
+ let lastWidth = 0;
616
+ watch(track, (el) => {
617
+ resize?.disconnect();
618
+ resize = null;
619
+ if (!el) return;
620
+ void nextTick(jump);
621
+ if (typeof ResizeObserver !== 'function') return;
622
+ lastWidth = el.clientWidth;
623
+ resize = new ResizeObserver(() => {
624
+ measureCaption();
625
+ const w = el.clientWidth;
626
+ if (w === lastWidth) return; // a height-only change moves nothing
627
+ lastWidth = w;
628
+ if (pointerDown) return;
629
+ const p = target ?? positionOf(index.value);
630
+ target = null;
631
+ scrollTo(p);
632
+ });
633
+ resize.observe(el);
634
+ });
635
+
636
+ const onShown = () => {
637
+ shown = true;
638
+ // A swipe begun during the fade-in has already moved the track past our
639
+ // last write: the opening correction must not yank it back to the
640
+ // opening photo — adopt where the reader has taken it, as `onScroll`
641
+ // (live from here on) would. At rest where we left it, or at a width
642
+ // that has since changed, the correction still runs.
643
+ const el = track.value;
644
+ if (
645
+ el &&
646
+ lastWrite &&
647
+ width() === lastWrite.width &&
648
+ Math.abs(el.scrollLeft - lastWrite.left) > 1
649
+ ) {
650
+ target = null;
651
+ const real = realOf(nearest());
652
+ if (real !== index.value) model.value = real;
653
+ settleClone();
654
+ } else jump();
655
+ measureCaption(); // before the top layer it measured against the page
656
+ announce();
657
+ };
658
+
659
+ // A focused arrow about to disable (an end reached) hands focus to the stage
660
+ // first: the browser would drop it to the body, where no key reaches us.
661
+ watch(
662
+ [atStart, atEnd],
663
+ ([start, end]) => {
664
+ const active = document.activeElement;
665
+ if (!(active instanceof HTMLElement)) return;
666
+ const stage = active.closest('.bb-gallery__stage');
667
+ if (
668
+ (start && active.classList.contains('bb-gallery__nav--prev')) ||
669
+ (end && active.classList.contains('bb-gallery__nav--next'))
670
+ )
671
+ stage
672
+ ?.querySelector<HTMLElement>(
673
+ end ? '.bb-gallery__nav--prev' : '.bb-gallery__nav--next'
674
+ )
675
+ ?.focus({ preventScroll: true });
676
+ },
677
+ { flush: 'pre' }
678
+ );
679
+
680
+ const onKeydown = (event: KeyboardEvent) => {
681
+ if (event.defaultPrevented || event.altKey || event.metaKey || event.ctrlKey)
682
+ return;
683
+ const forward =
684
+ event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0;
685
+ if (forward) step(rtl() ? -forward : forward);
686
+ else if (event.key === 'Home') go(0);
687
+ else if (event.key === 'End') go(count.value - 1);
688
+ else if (event.key === '+' || event.key === '=') zoomBy(1.5);
689
+ else if (event.key === '-') zoomBy(1 / 1.5);
690
+ else if (event.key === '0') resetZoom();
691
+ else return;
692
+ event.preventDefault();
693
+ };
694
+
695
+ /* ---- items changing while it is open ------------------------------------- */
696
+
697
+ watch(photos, (next, prev) => {
698
+ if (model.value === null) return;
699
+ if (!next.length) return close();
700
+ // Stay on the same photo when the list is reordered or grows around it.
701
+ const shown = prev?.[index.value]?.key;
702
+ const same = shown ? next.findIndex((item) => item.key === shown) : -1;
703
+ const wanted = same >= 0 ? same : Math.min(index.value, next.length - 1);
704
+ if (wanted !== model.value) model.value = wanted;
705
+ void nextTick(jump);
706
+ });
707
+ // An out-of-range v-model is written back clamped (the counter, the slots
708
+ // and the parent agree).
709
+ watch(
710
+ () => [model.value, count.value] as const,
711
+ ([m]) => {
712
+ if (m !== null && count.value && m !== index.value)
713
+ model.value = index.value;
714
+ }
715
+ );
716
+
717
+ /* ---- Files that fail: the alt in the photo's place ----------------------- */
718
+
719
+ const failed = reactive(new Set<string>());
720
+ let failing: string[] = [];
721
+ let failFrame = 0;
722
+ const onError = (src: string) => {
723
+ failing.push(src);
724
+ if (failFrame) return;
725
+ failFrame = requestAnimationFrame(() => {
726
+ failFrame = 0;
727
+ for (const s of failing) failed.add(s);
728
+ failing = [];
729
+ });
730
+ };
731
+
732
+ /*
733
+ * A file that arrives while the viewer is open fades in over its plate; one
734
+ * already there (cached, or loaded while closed) shows with the viewer.
735
+ */
736
+ const onLoad = (event: Event) => {
737
+ if (!isOpen.value || reducedMotion()) return;
738
+ (event.target as HTMLElement).animate([{ opacity: 0 }, { opacity: 1 }], {
739
+ duration: 200,
740
+ easing: 'ease-out',
741
+ });
742
+ };
743
+
744
+ /* ---- Announcements -------------------------------------------------------- */
745
+
746
+ const announcement = ref('');
747
+ let announceTimer: ReturnType<typeof setTimeout> | undefined;
748
+ /** Once the steps stop: "Image 3 of 12: <alt>. <caption>" (never a queue of five). */
749
+ const announce = () => {
750
+ clearTimeout(announceTimer);
751
+ announceTimer = setTimeout(() => {
752
+ const item = photos.value[index.value];
753
+ if (!isOpen.value || !item) return;
754
+ const where = position(index.value);
755
+ announcement.value = [
756
+ item.alt ? `${where}: ${item.alt}` : where,
757
+ item.caption,
758
+ ]
759
+ .filter(Boolean)
760
+ .join('. ');
761
+ }, 350);
762
+ };
763
+ watch(index, () => shown && announce());
764
+
765
+ /* ---- The caption: one line in the bar, a sheet in full ------------------- */
766
+
767
+ const captionEl = ref<HTMLElement | null>(null);
768
+ const captionId = `bb-gallery-caption-${useId().id.value}`;
769
+ const currentCaption = computed(() => photos.value[index.value]?.caption);
770
+ const anyCaption = computed(() => photos.value.some((item) => !!item.caption));
771
+ /** The caption read in full, running upward from its own line. */
772
+ const captionOpen = ref(false);
773
+ const captionOverflows = ref(false);
774
+ const measureCaption = () => {
775
+ if (captionOpen.value) return; // open, it wraps: nothing to measure
776
+ const el = captionEl.value;
777
+ // No box yet (before the top layer) is no overflow, never a false More.
778
+ captionOverflows.value =
779
+ !!el && el.clientWidth > 0 && el.scrollWidth > el.clientWidth + 1;
780
+ };
781
+ watch([index, isOpen, currentCaption], () => {
782
+ captionOpen.value = false;
783
+ // Measured with no button beside it: More appears for the text alone.
784
+ captionOverflows.value = false;
785
+ void nextTick(measureCaption);
786
+ });
787
+ watch(captionOpen, (open) => {
788
+ if (!open) void nextTick(measureCaption);
789
+ });
790
+ // The line's width follows the bar; the words follow the fonts. Either can
791
+ // make a caption overflow (or stop) without a slide change.
792
+ let captionResize: ResizeObserver | null = null;
793
+ watch(captionEl, (el) => {
794
+ captionResize?.disconnect();
795
+ captionResize = null;
796
+ void nextTick(measureCaption);
797
+ if (!el || typeof ResizeObserver !== 'function') return;
798
+ captionResize = new ResizeObserver(measureCaption);
799
+ captionResize.observe(el);
800
+ });
801
+ onMounted(() => void document.fonts?.ready.then(measureCaption));
802
+
803
+ /** A press anywhere but the sheet or its button puts the sheet away. */
804
+ const onRootPointerDown = (event: PointerEvent) => {
805
+ if (!captionOpen.value) return;
806
+ if (
807
+ (event.target as Element).closest('.bb-gallery__caption, .bb-gallery__more')
808
+ )
809
+ return;
810
+ captionOpen.value = false;
811
+ };
812
+
813
+ /* ---- Zoom, pan, pinch, swipe-down, taps ---------------------------------- */
814
+
815
+ const activeImage = () =>
816
+ track.value?.querySelector<HTMLImageElement>(
817
+ '.bb-gallery__slide--active .bb-gallery__image'
818
+ ) ?? null;
819
+
820
+ /** The largest zoom: the file's own pixels, at least 2×, at most 4×. */
821
+ const maxScale = () => {
822
+ const img = activeImage();
823
+ if (!img || !img.clientWidth) return 2;
824
+ const natural = (img.naturalWidth || img.width) / img.clientWidth;
825
+ return Math.min(Math.max(natural, 2), 4);
826
+ };
827
+
828
+ /** Keeps the photo's edges from coming inside the stage while panning. */
829
+ const clampPan = () => {
830
+ const img = activeImage();
831
+ const frameEl = img?.parentElement;
832
+ if (!img || !frameEl) return;
833
+ const w = img.clientWidth * zoom.scale;
834
+ const h = img.clientHeight * zoom.scale;
835
+ const maxX = Math.max(0, (w - frameEl.clientWidth) / 2);
836
+ const maxY = Math.max(0, (h - frameEl.clientHeight) / 2);
837
+ zoom.x = Math.min(maxX, Math.max(-maxX, zoom.x));
838
+ zoom.y = Math.min(maxY, Math.max(-maxY, zoom.y));
839
+ };
840
+
841
+ /** Zooms to `scale`, keeping the screen point (`px`, `py`) still. */
842
+ const zoomTo = (scale: number, px?: number, py?: number) => {
843
+ const img = activeImage();
844
+ if (!img) return;
845
+ const next = Math.min(Math.max(scale, 1), maxScale());
846
+ const box = img.parentElement!.getBoundingClientRect();
847
+ const cx = box.left + box.width / 2;
848
+ const cy = box.top + box.height / 2;
849
+ const x = (px ?? cx) - cx;
850
+ const y = (py ?? cy) - cy;
851
+ const ratio = next / zoom.scale;
852
+ zoom.x = x - (x - zoom.x) * ratio;
853
+ zoom.y = y - (y - zoom.y) * ratio;
854
+ zoom.scale = next;
855
+ if (next <= 1.01) resetZoom();
856
+ else clampPan();
857
+ };
858
+ const zoomBy = (factor: number) => zoomTo(zoom.scale * factor);
859
+ const resetZoom = () => {
860
+ zoom.scale = 1;
861
+ zoom.x = 0;
862
+ zoom.y = 0;
863
+ };
864
+ const toggleZoom = (px: number, py: number) =>
865
+ zoomed.value ? resetZoom() : zoomTo(maxScale(), px, py);
866
+
867
+ // Ctrl + wheel (and a trackpad pinch, which the browser reports as one)
868
+ // zooms; zoomed, a plain wheel or a two-finger scroll pans the photo.
869
+ const onWheel = (event: WheelEvent) => {
870
+ if (!event.ctrlKey) {
871
+ if (!zoomed.value) {
872
+ target = null; // the user takes the track back
873
+ wheelPage(event);
874
+ return;
875
+ }
876
+ event.preventDefault();
877
+ // Lines (Firefox's mouse wheel) and pages, in px.
878
+ const unit =
879
+ event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? width() : 1;
880
+ // Shift + wheel scrolls sideways with a mouse.
881
+ const [dx, dy] =
882
+ event.shiftKey && !event.deltaX
883
+ ? [event.deltaY, 0]
884
+ : [event.deltaX, event.deltaY];
885
+ zoom.x -= dx * unit;
886
+ zoom.y -= dy * unit;
887
+ clampPan();
888
+ return;
889
+ }
890
+ event.preventDefault();
891
+ zoomTo(
892
+ zoom.scale * Math.exp(-event.deltaY * 0.01),
893
+ event.clientX,
894
+ event.clientY
895
+ );
896
+ };
897
+ /*
898
+ * A mouse wheel's sideways notches (a tilt wheel, Shift + wheel) page one
899
+ * photo per burst. Left to the browser, Firefox jumps a snap point per
900
+ * notch and flies to the end. A trackpad (pixel deltas) stays native: it
901
+ * follows the fingers and snaps.
902
+ */
903
+ let lastNotch = -Infinity;
904
+ const wheelPage = (event: WheelEvent) => {
905
+ const sideways =
906
+ Math.abs(event.deltaX) > Math.abs(event.deltaY) || event.shiftKey;
907
+ if (!sideways || event.deltaMode === 0) return;
908
+ event.preventDefault();
909
+ const burst = event.timeStamp - lastNotch < 250;
910
+ lastNotch = event.timeStamp;
911
+ const d = Math.sign(event.deltaX || event.deltaY);
912
+ if (!burst && d) step(rtl() ? -d : d);
913
+ };
914
+ watch(track, (el, old) => {
915
+ old?.removeEventListener('wheel', onWheel);
916
+ el?.addEventListener('wheel', onWheel, { passive: false });
917
+ });
918
+
919
+ const pointers = new Map<number, { x: number; y: number }>();
920
+ let gesture: {
921
+ kind: 'idle' | 'pan' | 'pinch' | 'dismiss';
922
+ startX: number;
923
+ startY: number;
924
+ startT: number;
925
+ zoomX: number;
926
+ zoomY: number;
927
+ pinchDistance: number;
928
+ pinchScale: number;
929
+ moved: boolean;
930
+ } | null = null;
931
+ const dismissY = ref(0);
932
+ /** A finger or the mouse is moving the photo: no easing behind it. */
933
+ const gesturing = ref(false);
934
+ const dismissProgress = computed(() => Math.min(dismissY.value / 320, 1));
935
+ let lastTap = { t: 0, x: 0, y: 0 };
936
+ let tapTimer: ReturnType<typeof setTimeout> | undefined;
937
+ let lastPointerType = '';
938
+
939
+ const distance = () => {
940
+ const [a, b] = [...pointers.values()];
941
+ return Math.hypot(a.x - b.x, a.y - b.y);
942
+ };
943
+
944
+ const onPointerDown = (event: PointerEvent) => {
945
+ lastPointerType = event.pointerType;
946
+ pointerDown = true;
947
+ target = null; // a touch takes the track back from a slide
948
+ pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
949
+ if (pointers.size === 2 && event.pointerType === 'touch') {
950
+ gesture = {
951
+ kind: 'pinch',
952
+ startX: 0,
953
+ startY: 0,
954
+ startT: event.timeStamp,
955
+ zoomX: zoom.x,
956
+ zoomY: zoom.y,
957
+ pinchDistance: distance(),
958
+ pinchScale: zoom.scale,
959
+ moved: true,
960
+ };
961
+ return;
962
+ }
963
+ if (pointers.size > 1) return;
964
+ gesture = {
965
+ kind: zoomed.value ? 'pan' : 'idle',
966
+ startX: event.clientX,
967
+ startY: event.clientY,
968
+ startT: event.timeStamp,
969
+ zoomX: zoom.x,
970
+ zoomY: zoom.y,
971
+ pinchDistance: 0,
972
+ pinchScale: zoom.scale,
973
+ moved: false,
974
+ };
975
+ if (zoomed.value)
976
+ (event.target as Element).setPointerCapture?.(event.pointerId);
977
+ };
978
+
979
+ const onPointerMove = (event: PointerEvent) => {
980
+ if (!pointers.has(event.pointerId) || !gesture) return;
981
+ pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
982
+ const dx = event.clientX - gesture.startX;
983
+ const dy = event.clientY - gesture.startY;
984
+ if (Math.hypot(dx, dy) > 6) gesture.moved = true;
985
+ if (gesture.kind !== 'idle') gesturing.value = true;
986
+ if (gesture.kind === 'pinch' && pointers.size === 2) {
987
+ const [a, b] = [...pointers.values()];
988
+ zoomTo(
989
+ (gesture.pinchScale * distance()) / gesture.pinchDistance,
990
+ (a.x + b.x) / 2,
991
+ (a.y + b.y) / 2
992
+ );
993
+ return;
994
+ }
995
+ if (gesture.kind === 'pan') {
996
+ zoom.x = gesture.zoomX + dx;
997
+ zoom.y = gesture.zoomY + dy;
998
+ clampPan();
999
+ return;
1000
+ }
1001
+ // Touch or pen, not zoomed: a mostly-downward drag takes the photo away.
1002
+ if (
1003
+ gesture.kind === 'idle' &&
1004
+ event.pointerType !== 'mouse' &&
1005
+ dy > 10 &&
1006
+ dy > Math.abs(dx) * 1.2
1007
+ )
1008
+ gesture.kind = 'dismiss';
1009
+ if (gesture.kind === 'dismiss') {
1010
+ gesturing.value = true;
1011
+ dismissY.value = Math.max(0, dy);
1012
+ }
1013
+ };
1014
+
1015
+ const onPointerEnd = (event: PointerEvent) => {
1016
+ pointers.delete(event.pointerId);
1017
+ if (pointers.size) return;
1018
+ pointerDown = false;
1019
+ gesturing.value = false;
1020
+ const g = gesture;
1021
+ gesture = null;
1022
+ if (!g) return;
1023
+ if (g.kind === 'dismiss') {
1024
+ const velocity = dismissY.value / Math.max(event.timeStamp - g.startT, 1);
1025
+ const away =
1026
+ event.type === 'pointerup' && (dismissY.value > 80 || velocity > 0.5);
1027
+ dismissY.value = 0;
1028
+ if (away) close();
1029
+ return;
1030
+ }
1031
+ if (event.type !== 'pointerup' || g.moved || event.pointerType === 'mouse') {
1032
+ settleClone();
1033
+ return;
1034
+ }
1035
+ // A touch tap: twice on the photo zooms there; once toggles the chrome.
1036
+ const onImage = (event.target as Element).closest('.bb-gallery__image');
1037
+ const now = event.timeStamp;
1038
+ const double =
1039
+ now - lastTap.t < 300 &&
1040
+ Math.hypot(event.clientX - lastTap.x, event.clientY - lastTap.y) < 30;
1041
+ lastTap = { t: now, x: event.clientX, y: event.clientY };
1042
+ clearTimeout(tapTimer);
1043
+ if (double) {
1044
+ lastTap.t = 0;
1045
+ if (onImage || zoomed.value) toggleZoom(event.clientX, event.clientY);
1046
+ return;
1047
+ }
1048
+ const onText = (event.target as Element).closest('.bb-gallery__missing');
1049
+ if (!onImage && !onText && !zoomed.value && props.closeOnBackdropClick)
1050
+ return close();
1051
+ if (onText) return;
1052
+ tapTimer = setTimeout(() => (quiet.value = !quiet.value), 300);
1053
+ };
1054
+
1055
+ /**
1056
+ * A mouse click on the dark stage around the photo: back to fit when zoomed,
1057
+ * else closes with `closeOnBackdropClick`.
1058
+ */
1059
+ const onStageClick = (event: MouseEvent) => {
1060
+ if (lastPointerType !== 'mouse' || event.detail > 1) return;
1061
+ const el = event.target as Element;
1062
+ if (el.closest('.bb-gallery__image, .bb-gallery__nav, .bb-gallery__missing'))
1063
+ return;
1064
+ if (zoomed.value) return resetZoom();
1065
+ if (props.closeOnBackdropClick) close();
1066
+ };
1067
+
1068
+ // A double-click on the photo zooms there (and back).
1069
+ const onDblClick = (event: MouseEvent) => {
1070
+ // A double tap fires one too: the touch path already handled it.
1071
+ if (lastPointerType && lastPointerType !== 'mouse') return;
1072
+ if ((event.target as Element).closest('.bb-gallery__image'))
1073
+ toggleZoom(event.clientX, event.clientY);
1074
+ };
1075
+ watch(track, (el, old) => {
1076
+ old?.removeEventListener('dblclick', onDblClick);
1077
+ el?.addEventListener('dblclick', onDblClick);
1078
+ });
1079
+
1080
+ /** A tap on the photo hides the bars and arrows (and brings them back). */
1081
+ const quiet = ref(false);
1082
+
1083
+ /* ---- The modal: open, close, Escape -------------------------------------- *
1084
+ *
1085
+ * A native <dialog> and showModal(): the top layer (above any dialog or
1086
+ * popover it was declared in), the page behind inert, focus kept inside.
1087
+ * The rest is ours: it fades in and out over the whole screen, the page
1088
+ * behind does not scroll, Escape closes the top-most surface only.
1089
+ */
1090
+
1091
+ const root = ref<HTMLDialogElement | null>(null);
1092
+ const titleId = `bb-gallery-title-${useId().id.value}`;
1093
+ /** In the top layer: open, or fading out. */
1094
+ const visible = ref(false);
1095
+ /** The viewer's contents exist while it is open or leaving; closed, nothing. */
1096
+ const mounted = computed(() => isOpen.value || visible.value);
1097
+ const pageStyle = ref<Record<string, string>>();
1098
+ useBodyScrollLock(visible);
1099
+
1100
+ const escapeKey = Symbol('bb-gallery');
1101
+ let releaseTopLayer: (() => void) | null = null;
1102
+ /** Bumped by every opening: a close that finds it moved was overtaken. */
1103
+ let openings = 0;
1104
+
1105
+ const enter = async () => {
1106
+ const opening = ++openings;
1107
+ pageStyle.value = pageText();
1108
+ if (!visible.value) pushEscapeEntry(escapeKey, { element: () => root.value });
1109
+ visible.value = true;
1110
+ await nextTick();
1111
+ const el = root.value;
1112
+ if (!el || opening !== openings) return;
1113
+ if (!el.open) el.showModal();
1114
+ // Toasts move inside it to stay clickable (see useTopLayer).
1115
+ releaseTopLayer ??= registerTopLayerHost(el);
1116
+ el.querySelector<HTMLElement>('.bb-gallery__stage')?.focus({
1117
+ preventScroll: true,
1118
+ });
1119
+ await wait(transitions.medium);
1120
+ await animationsSettled(el);
1121
+ if (opening === openings && isOpen.value) onShown();
1122
+ };
1123
+
1124
+ const leave = async () => {
1125
+ const closing = openings;
1126
+ await wait(transitions.medium);
1127
+ if (closing !== openings || isOpen.value) return; // reopened meanwhile
1128
+ finish();
1129
+ };
1130
+
1131
+ /** Out of the top layer, everything reset, focus back where it came from. */
1132
+ const finish = () => {
1133
+ removeEscapeEntry(escapeKey);
1134
+ if (root.value?.open) root.value.close();
1135
+ releaseTopLayer?.();
1136
+ releaseTopLayer = null;
1137
+ if (!visible.value) return;
1138
+ visible.value = false;
1139
+ onHidden();
1140
+ };
1141
+
1142
+ watch(isOpen, (open) => void (open ? enter() : leave()));
1143
+ onMounted(() => {
1144
+ if (isOpen.value) void enter();
1145
+ });
1146
+
1147
+ /** Escape (and Android's back): ours to animate, and only when on top. */
1148
+ const onCancel = (event: Event) => {
1149
+ event.preventDefault();
1150
+ // The caption sheet first: a second Escape closes the viewer.
1151
+ if (captionOpen.value) return void (captionOpen.value = false);
1152
+ if (isTopEscapeEntry(escapeKey)) close();
1153
+ };
1154
+
1155
+ /** Closed by the browser without a cancel we could hold back: follow it. */
1156
+ const onNativeClose = () => {
1157
+ if (!isOpen.value || !root.value) return; // ours, or after an unmount
1158
+ openings++;
1159
+ model.value = null;
1160
+ finish();
1161
+ };
1162
+
1163
+ const onHidden = () => {
1164
+ shown = false;
1165
+ target = null;
1166
+ captionOpen.value = false;
1167
+ quiet.value = false;
1168
+ dismissY.value = 0;
1169
+ resetZoom();
1170
+ announcement.value = '';
1171
+ const ours = opener;
1172
+ const byHost = hostOpened;
1173
+ opener = null;
1174
+ hostOpened = false;
1175
+ overlay.afterHidden();
1176
+ if (byHost || !ours) return;
1177
+ const active = document.activeElement;
1178
+ if (!active || active === document.body) returnFocusToOpener(ours);
1179
+ };
1180
+
1181
+ onBeforeUnmount(() => {
1182
+ openings++;
1183
+ removeEscapeEntry(escapeKey);
1184
+ if (root.value?.open) root.value.close();
1185
+ releaseTopLayer?.();
1186
+ releasePreload?.();
1187
+ resize?.disconnect();
1188
+ captionResize?.disconnect();
1189
+ if (frame) cancelAnimationFrame(frame);
1190
+ clearTimeout(endTimer);
1191
+ if (failFrame) cancelAnimationFrame(failFrame);
1192
+ clearTimeout(announceTimer);
1193
+ clearTimeout(tapTimer);
1194
+ });
1195
+ </script>
1196
+
1197
+ <style lang="postcss">
1198
+ @import './index.css';
1199
+ </style>
1200
+ ```
1201
+
1202
+ ## Types
1203
+
1204
+ ```ts
1205
+ import type { PtCompoundProps, PtValue } from '@/types/passthrough';
1206
+ import type { BbGalleryPtKeys } from './ptKeys.generated';
1207
+
1208
+ /**
1209
+ * One photo of a `BbGallery`: the same image fields as a `BbCarousel` entry
1210
+ * (`src` or `srcset`, `alt`, `sizes`), plus a caption and the file's size. A
1211
+ * bare URL string in `items` is the same as `{ src }`. `width` / `height`
1212
+ * are the intrinsic size: with them the viewer reserves the photo's box
1213
+ * before it arrives, and never upscales it past that size.
1214
+ */
1215
+ export type BbGalleryItem = {
1216
+ /** The image URL. Optional with `srcset`: the browser picks from it. */
1217
+ src?: string;
1218
+ /** The text alternative, read out with the position. Left out, it is empty. */
1219
+ alt?: string;
1220
+ /** Candidate files by width (`"a.jpg 640w, b.jpg 1280w"`), as on an `img`. */
1221
+ srcset?: string;
1222
+ /**
1223
+ * The slot width per breakpoint for `srcset`, as on an `img`.
1224
+ *
1225
+ * @defaultValue `"100vw"` when `srcset` is set
1226
+ */
1227
+ sizes?: string;
1228
+ /** A line in the bottom bar; a longer one reads in full from its More button. */
1229
+ caption?: string;
1230
+ /** Intrinsic width in px (with `height`: no layout shift, no upscaling). */
1231
+ width?: number;
1232
+ /** Intrinsic height in px. */
1233
+ height?: number;
1234
+ } & ({ src: string } | { srcset: string });
1235
+
1236
+ /**
1237
+ * Passthrough parts of `BbGallery`.
1238
+ *
1239
+ * @part root - The full-screen viewer (a native modal `dialog`).
1240
+ * @part header - The top bar.
1241
+ * @part title - The title line in the bar. Not rendered when a `#header`
1242
+ * slot replaces the bar.
1243
+ * @part close - The close button. Not rendered when a `#header` slot replaces
1244
+ * the bar.
1245
+ * @part slide - Each slide (`figure`), per item (`active` on the one shown).
1246
+ * @part image - Each photo.
1247
+ * @part caption - The caption in the bottom bar: one line, or the full text
1248
+ * running upward from it when opened.
1249
+ * @part prev - The previous button (`disabled` on the first photo, never with
1250
+ * `loop`).
1251
+ * @part next - The next button (`disabled` on the last photo, never with
1252
+ * `loop`).
1253
+ * @part footer - The bottom bar.
1254
+ * @part counter - The "3 / 12" in the bottom bar. Not rendered when a
1255
+ * `#footer` slot replaces it.
1256
+ * @part more - The button that reads a caption too long for its line in
1257
+ * full ("More", and "Less" while it is open). Only there while the photo
1258
+ * shown has such a caption.
1259
+ */
1260
+ export type BbGalleryPtPart =
1261
+ | 'root'
1262
+ | 'header'
1263
+ | 'title'
1264
+ | 'close'
1265
+ | 'slide'
1266
+ | 'image'
1267
+ | 'caption'
1268
+ | 'prev'
1269
+ | 'next'
1270
+ | 'footer'
1271
+ | 'counter'
1272
+ | 'more';
1273
+
1274
+ /**
1275
+ * Passthrough states of `BbGallery`.
1276
+ *
1277
+ * @state disabled - Per node: `prev` on the first photo, `next` on the last.
1278
+ * @state active - Per node: the slide shown.
1279
+ * @state zoomed - Component-wide: the photo shown is zoomed in.
1280
+ */
1281
+ export type BbGalleryPtState = 'disabled' | 'active' | 'zoomed';
1282
+
1283
+ /** The runtime lists the resolver is wired with. */
1284
+ export const BB_GALLERY_PT = {
1285
+ parts: [
1286
+ 'root',
1287
+ 'header',
1288
+ 'title',
1289
+ 'close',
1290
+ 'slide',
1291
+ 'image',
1292
+ 'caption',
1293
+ 'prev',
1294
+ 'next',
1295
+ 'footer',
1296
+ 'counter',
1297
+ 'more',
1298
+ ],
1299
+ states: ['disabled', 'active', 'zoomed'],
1300
+ /** On every part: the zoom is the whole viewer's. */
1301
+ wide: ['zoomed'],
1302
+ /** Per node: what one slide or arrow knows. */
1303
+ node: {
1304
+ slide: ['active'],
1305
+ prev: ['disabled'],
1306
+ next: ['disabled'],
1307
+ },
1308
+ } as const satisfies {
1309
+ parts: readonly BbGalleryPtPart[];
1310
+ states: readonly BbGalleryPtState[];
1311
+ wide: readonly BbGalleryPtState[];
1312
+ node: Partial<Record<BbGalleryPtPart, readonly BbGalleryPtState[]>>;
1313
+ };
1314
+
1315
+ /**
1316
+ * Every `part` / `part:state` key of `BbGallery`: only the pairs that land.
1317
+ * `PtKeysOf<typeof BB_GALLERY_PT>` is the same union; a type test pins them.
1318
+ */
1319
+ export type BbGalleryPtKey =
1320
+ | BbGalleryPtPart
1321
+ | `${BbGalleryPtPart}:zoomed`
1322
+ | 'slide:active'
1323
+ | `${'prev' | 'next'}:disabled`;
1324
+
1325
+ /**
1326
+ * BbGallery's `pt:*` attributes: the documented keys, and the patterns Vue's
1327
+ * SFC resolver skips (compound keys; the vue-ignore marker). This alias keeps
1328
+ * the marker on a member right after its `=`: the declaration emit drops it
1329
+ * at the start of a line or ahead of a whole type.
1330
+ */
1331
+ type BbGalleryPtProps = /* @vue-ignore */ PtCompoundProps<
1332
+ typeof BB_GALLERY_PT
1333
+ > &
1334
+ BbGalleryPtKeys;
1335
+
1336
+ export type BbGalleryProps<T extends BbGalleryItem = BbGalleryItem> =
1337
+ BbGalleryPtProps & {
1338
+ /**
1339
+ * Passthrough, object form: the same keys as the `pt:*` attributes
1340
+ * without the prefix.
1341
+ */
1342
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
1343
+ pt?: { [K in BbGalleryPtKey]?: PtValue };
1344
+ /** The photos, in order: `{ src, alt, caption, … }` entries or image URLs. */
1345
+ items: ReadonlyArray<string | T>;
1346
+ /**
1347
+ * The name `v-bb-gallery` opens it by, nearest to the trigger first. Also
1348
+ * the viewer's DOM id.
1349
+ *
1350
+ * @defaultValue `undefined`
1351
+ */
1352
+ id?: string;
1353
+ /**
1354
+ * A title in the top bar, also the viewer's accessible name. Unset, the
1355
+ * bar shows only the close button and the name is the locale's "Gallery".
1356
+ *
1357
+ * @defaultValue `undefined`
1358
+ */
1359
+ title?: string;
1360
+ /**
1361
+ * Previous on the first photo goes to the last, next on the last to the
1362
+ * first (buttons, keys and a swipe).
1363
+ *
1364
+ * @defaultValue `false`
1365
+ */
1366
+ loop?: boolean;
1367
+ /**
1368
+ * A click (or a tap) on the dark area around the photo closes the viewer.
1369
+ * Off, it does nothing there (a tap still hides the bars); Escape, the
1370
+ * close button and a swipe down always close.
1371
+ *
1372
+ * @defaultValue `false`
1373
+ */
1374
+ closeOnBackdropClick?: boolean;
1375
+ };
1376
+
1377
+ export type BbGalleryEvents = {
1378
+ /** The photo shown changed, or the viewer opened / closed (`null`). */
1379
+ 'update:modelValue': [index: number | null];
1380
+ };
1381
+
1382
+ /** What every slot of `BbGallery` gets. */
1383
+ export type BbGallerySlotProps<T extends BbGalleryItem = BbGalleryItem> = {
1384
+ /** The index of the photo shown. */
1385
+ index: number;
1386
+ /** How many photos there are. */
1387
+ count: number;
1388
+ /** The photo shown, with your entry's own fields (a URL entry comes as `{ src }`). */
1389
+ item: T;
1390
+ /** Shows another photo (by index; out of range does nothing). */
1391
+ go: (index: number) => void;
1392
+ /** Closes the viewer. */
1393
+ close: () => void;
1394
+ };
1395
+
1396
+ /** Props exposed by the `header` slot. */
1397
+ export type BbGalleryHeaderSlotProps<T extends BbGalleryItem = BbGalleryItem> =
1398
+ BbGallerySlotProps<T> & {
1399
+ /** The `id` to put on your title element: it names the viewer. */
1400
+ titleId: string;
1401
+ /** The `title` prop value. */
1402
+ title: string | undefined;
1403
+ };
1404
+
1405
+ /** Props exposed by the `title` slot. */
1406
+ export type BbGalleryTitleSlotProps<T extends BbGalleryItem = BbGalleryItem> =
1407
+ BbGallerySlotProps<T> & {
1408
+ /** The `title` prop value. */
1409
+ text: string | undefined;
1410
+ };
1411
+
1412
+ export type BbGallerySlots<T extends BbGalleryItem = BbGalleryItem> = {
1413
+ /** Replaces the title text in the top bar; it still names the viewer. */
1414
+ title?: (props: BbGalleryTitleSlotProps<T>) => unknown;
1415
+ /**
1416
+ * Replaces the whole top bar (title and close button), so it owns
1417
+ * closing: wire your control to `close`, and `titleId` onto your title.
1418
+ */
1419
+ header?: (props: BbGalleryHeaderSlotProps<T>) => unknown;
1420
+ /**
1421
+ * Replaces the counter with a row of your own across the bottom bar:
1422
+ * your own counter, actions, or a filmstrip that calls `go`. The
1423
+ * caption keeps its own one-line row directly above yours (there
1424
+ * whenever any photo has one), so the photo never jumps.
1425
+ */
1426
+ footer?: (props: BbGallerySlotProps<T>) => unknown;
1427
+ };
1428
+ ```
1429
+
1430
+ ## Styles
1431
+
1432
+ ```css
1433
+ /* @inherit --scrollbar-width — set on <html> by the shared scroll lock (useBodyScrollLock) */
1434
+ @import '../CommonPopover/floating-text.css';
1435
+
1436
+ /* ---- The viewer: its own modal, edge to edge, dark like every photo viewer -- */
1437
+
1438
+ /* @inherit --page-ff --page-fs --page-lh — set inline at each open (pageText) */
1439
+ .bb-gallery {
1440
+ /* The viewer's own: its plate and text, the bars' padding, the buttons.
1441
+ Every colour follows `--viewer-bg` / `--viewer-fg` (the muted text the
1442
+ ink, the arrows' plate the plate colour), so a light viewer is those
1443
+ two plus `color-scheme: light`; a derived local set directly wins. */
1444
+ --viewer-bg: rgb(12 12 12);
1445
+ --viewer-fg: rgb(244 244 242);
1446
+ --viewer-muted: color-mix(in oklab, var(--viewer-fg) 75%, transparent);
1447
+ /* A picker strip inside takes its current and focus marks from here. */
1448
+ --mark: var(--viewer-fg);
1449
+ --mark-bg: var(--viewer-bg);
1450
+ --bar-px: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
1451
+ --nav-size: 44px;
1452
+ --plate: color-mix(in oklab, var(--viewer-bg) 60%, transparent);
1453
+ --dismiss: 0;
1454
+ --dismiss-y: 0px;
1455
+ --d: var(--bb-transition-medium);
1456
+
1457
+ /* The whole screen, whatever the browser's dialog defaults say. */
1458
+ background: transparent;
1459
+ border: 0;
1460
+ box-sizing: border-box;
1461
+ color: var(--viewer-fg);
1462
+ color-scheme: dark;
1463
+ flex-direction: column;
1464
+ height: 100%;
1465
+ inset: 0;
1466
+ margin: 0;
1467
+ max-height: none;
1468
+ max-width: none;
1469
+ /* Faded out, and in again at each opening. Never scaled: a shrunken plate
1470
+ would show the page at its corners. */
1471
+ opacity: 0;
1472
+ outline: none;
1473
+ overflow: hidden;
1474
+ overscroll-behavior: contain;
1475
+ padding: 0;
1476
+ position: fixed;
1477
+ touch-action: manipulation;
1478
+ transition:
1479
+ opacity var(--d) var(--bb-ease, ease),
1480
+ display var(--d) allow-discrete,
1481
+ overlay var(--d) allow-discrete;
1482
+ width: 100%;
1483
+
1484
+ &[open] {
1485
+ display: flex;
1486
+ }
1487
+
1488
+ /* The page behind shows through only while a swipe down takes it away. */
1489
+ &::backdrop {
1490
+ background: transparent;
1491
+ }
1492
+
1493
+ /* The plate: `--viewer-bg`, fading to the page as a swipe down takes the
1494
+ photo away. */
1495
+ &::before {
1496
+ background: var(--viewer-bg);
1497
+ content: '';
1498
+ inset: 0;
1499
+ opacity: calc(1 - var(--dismiss) * 0.85);
1500
+ pointer-events: none;
1501
+ position: absolute;
1502
+ z-index: -1;
1503
+ }
1504
+ }
1505
+
1506
+ .bb-gallery--open {
1507
+ opacity: 1;
1508
+
1509
+ @starting-style {
1510
+ opacity: 0;
1511
+ }
1512
+ }
1513
+
1514
+ /* The page behind does not scroll (the shared lock pads away its bar). */
1515
+ body:has(.bb-gallery--visible) {
1516
+ overflow: hidden;
1517
+ padding-inline-end: var(--scrollbar-width);
1518
+ }
1519
+
1520
+ .bb-gallery__header {
1521
+ align-items: center;
1522
+ display: flex;
1523
+ flex: 0 0 auto;
1524
+ gap: 12px;
1525
+ justify-content: space-between;
1526
+ min-height: calc(var(--nav-size) + 16px);
1527
+ padding: max(8px, env(safe-area-inset-top)) var(--bar-px) 8px;
1528
+ }
1529
+
1530
+ .bb-gallery__footer {
1531
+ display: flex;
1532
+ flex: 0 0 auto;
1533
+ flex-direction: column;
1534
+ justify-content: center;
1535
+ min-height: calc(var(--nav-size) + 8px);
1536
+ padding: 4px var(--bar-px) max(8px, env(safe-area-inset-bottom));
1537
+ /* The caption sheet anchors to the bar's top edge. */
1538
+ position: relative;
1539
+
1540
+ > * {
1541
+ min-width: 0;
1542
+ }
1543
+ }
1544
+
1545
+ /* The caption's line: equal side columns hold the caption at the bar's true
1546
+ centre, so the counter's width (or the More button beside it) can never
1547
+ move it, and the row is one line tall on every photo. */
1548
+ .bb-gallery__bar {
1549
+ align-items: center;
1550
+ column-gap: 12px;
1551
+ display: grid;
1552
+ grid-template-columns: 1fr minmax(0, 62ch) 1fr;
1553
+ min-height: calc((var(--bb-fs) + 1px) * 1.5);
1554
+ position: relative;
1555
+ width: 100%;
1556
+ }
1557
+
1558
+ .bb-gallery__header,
1559
+ .bb-gallery__footer {
1560
+ opacity: calc(1 - var(--dismiss) * 2);
1561
+ transition: opacity var(--bb-transition-medium) var(--bb-ease, ease);
1562
+ }
1563
+
1564
+ .bb-gallery__title {
1565
+ color: var(--viewer-fg);
1566
+ flex: 1 1 auto;
1567
+ font-size: calc(var(--bb-fs) + 1px);
1568
+ font-weight: 500;
1569
+ margin: 0;
1570
+ min-width: 0;
1571
+ overflow: hidden;
1572
+ /* Optically level with the ✕'s glyph, not its 44px box. */
1573
+ padding-inline-start: 4px;
1574
+ text-overflow: ellipsis;
1575
+ white-space: nowrap;
1576
+ }
1577
+
1578
+ /* In the bar's flow, a 44px target around a 24px glyph, round like the arrows.
1579
+ Sized on the button: the glyph is a BbIcon, whose own `--size` would win
1580
+ on the svg. */
1581
+ .bb-gallery__header > .bb-gallery__close {
1582
+ --size: var(--nav-size);
1583
+ --p: 12px;
1584
+ background: transparent;
1585
+ border-radius: 999px;
1586
+ color: var(--viewer-fg);
1587
+ flex: 0 0 auto;
1588
+ margin-inline-start: auto;
1589
+ position: static;
1590
+
1591
+ &:hover,
1592
+ &:focus-visible {
1593
+ background: color-mix(in oklab, var(--viewer-fg) 15%, transparent);
1594
+ color: var(--viewer-fg);
1595
+ }
1596
+
1597
+ &:focus-visible {
1598
+ outline: 2px solid var(--viewer-fg);
1599
+ outline-offset: 2px;
1600
+ }
1601
+ }
1602
+
1603
+ .bb-gallery__counter {
1604
+ color: var(--viewer-muted);
1605
+ font-size: calc(var(--bb-fs) + 1px);
1606
+ font-variant-numeric: tabular-nums;
1607
+ font-weight: 500;
1608
+ grid-column: 3;
1609
+ justify-self: end;
1610
+ letter-spacing: 0.01em;
1611
+ margin: 0;
1612
+ white-space: nowrap;
1613
+ }
1614
+
1615
+ .bb-gallery__stage {
1616
+ flex: 1 1 auto;
1617
+ min-height: 0;
1618
+ outline: none;
1619
+ overflow: hidden;
1620
+ position: relative;
1621
+ }
1622
+
1623
+ .bb-gallery__track {
1624
+ display: flex;
1625
+ height: 100%;
1626
+ outline: none;
1627
+ overflow-x: auto;
1628
+ overflow-y: hidden;
1629
+ overscroll-behavior-x: contain;
1630
+ scroll-snap-type: x mandatory;
1631
+ scrollbar-width: none;
1632
+ /* The browser pans sideways (the swipe between photos); a pinch, a drag
1633
+ down and a double tap come to us. */
1634
+ touch-action: pan-x;
1635
+
1636
+ &::-webkit-scrollbar {
1637
+ display: none;
1638
+ }
1639
+ }
1640
+
1641
+ /* Zoomed: the photo pans, the track holds still. */
1642
+ .bb-gallery--zoomed .bb-gallery__track {
1643
+ overflow-x: hidden;
1644
+ touch-action: none;
1645
+ }
1646
+
1647
+ .bb-gallery__slide {
1648
+ align-items: center;
1649
+ display: flex;
1650
+ flex: 0 0 100%;
1651
+ flex-direction: column;
1652
+ justify-content: center;
1653
+ margin: 0;
1654
+ min-width: 0;
1655
+ padding: 0 var(--bar-px) 8px;
1656
+ scroll-snap-align: center;
1657
+ scroll-snap-stop: always;
1658
+ }
1659
+
1660
+ /* The photo's box: a size container, so a sized photo knows how much room
1661
+ it has before its file arrives. */
1662
+ .bb-gallery__frame {
1663
+ container-type: size;
1664
+ display: grid;
1665
+ flex: 1 1 auto;
1666
+ min-height: 0;
1667
+ place-items: center;
1668
+ width: 100%;
1669
+ }
1670
+
1671
+ .bb-gallery__image {
1672
+ /* A faint plate says "loading" instead of a black hole. */
1673
+ background: color-mix(in oklab, var(--viewer-fg) 8%, transparent);
1674
+ display: block;
1675
+ max-height: 100%;
1676
+ max-width: 100%;
1677
+ object-fit: contain;
1678
+ transform-origin: center;
1679
+ -webkit-user-drag: none;
1680
+ user-select: none;
1681
+ }
1682
+
1683
+ /* Unsized: the file decides once it arrives. */
1684
+ .bb-gallery__image:not(.bb-gallery__image--sized) {
1685
+ height: auto;
1686
+ width: auto;
1687
+ }
1688
+
1689
+ /* Sized: the largest box of its ratio that fits, never past its own pixels.
1690
+ The ratio and the width come inline from the item's width / height. */
1691
+ /* @inherit --arw */
1692
+ /* @inherit --arh */
1693
+ /* @inherit --w */
1694
+ .bb-gallery__image--sized {
1695
+ aspect-ratio: var(--arw) / var(--arh);
1696
+ height: auto;
1697
+ width: min(100cqw, 100cqh * var(--arw) / var(--arh), var(--w));
1698
+ }
1699
+
1700
+ .bb-gallery__slide--active .bb-gallery__image {
1701
+ cursor: zoom-in;
1702
+ transition: transform var(--bb-transition-medium) var(--bb-ease, ease);
1703
+ }
1704
+
1705
+ .bb-gallery--zoomed .bb-gallery__slide--active .bb-gallery__image {
1706
+ cursor: grab;
1707
+ }
1708
+
1709
+ .bb-gallery--gesture .bb-gallery__slide--active .bb-gallery__image {
1710
+ cursor: grabbing;
1711
+ transition: none;
1712
+ }
1713
+
1714
+ /* A drag down takes the photo with the finger; the plate fades behind it. */
1715
+ .bb-gallery--dismissing .bb-gallery__slide--active .bb-gallery__image {
1716
+ transform: translateY(var(--dismiss-y)) scale(calc(1 - var(--dismiss) * 0.2));
1717
+ }
1718
+
1719
+ /* One line in the bar's centre column, cut with an ellipsis: the photo's
1720
+ box never learns how long the caption is. */
1721
+ .bb-gallery__caption {
1722
+ align-items: baseline;
1723
+ color: var(--viewer-muted);
1724
+ display: flex;
1725
+ font-size: calc(var(--bb-fs) + 1px);
1726
+ gap: 8px;
1727
+ grid-column: 2;
1728
+ justify-content: center;
1729
+ line-height: 1.5;
1730
+ margin: 0;
1731
+ min-width: 0;
1732
+ outline: none;
1733
+ white-space: nowrap;
1734
+
1735
+ &:focus-visible {
1736
+ outline: 2px solid var(--viewer-fg);
1737
+ outline-offset: -2px;
1738
+ }
1739
+ }
1740
+
1741
+ .bb-gallery__caption-text {
1742
+ min-width: 0;
1743
+ overflow: hidden;
1744
+ text-overflow: ellipsis;
1745
+ }
1746
+
1747
+ /* In full: the same words from the same line, running upward edge to edge
1748
+ on the viewer's own plate, so where they cross the photo's foot the
1749
+ picture sinks into the plate instead of a box sitting on it. An overlay:
1750
+ the stage never resizes. */
1751
+ .bb-gallery__caption--open {
1752
+ background: linear-gradient(transparent, var(--viewer-bg) 56px);
1753
+ bottom: 0;
1754
+ color: var(--viewer-fg);
1755
+ display: block;
1756
+ /* Every column: an absolute grid child sizes against its own cell. */
1757
+ grid-column: 1 / -1;
1758
+ inset-inline: calc(-1 * var(--bar-px));
1759
+ max-height: 40dvh;
1760
+ overflow-y: auto;
1761
+ overscroll-behavior: contain;
1762
+ /* The side columns' room stays clear: the last line shares the counter's. */
1763
+ padding-block-start: 56px;
1764
+ padding-inline: max(calc(var(--bar-px) + 7ch), calc(50% - 31ch));
1765
+ position: absolute;
1766
+ text-align: center;
1767
+ text-wrap: pretty;
1768
+ white-space: normal;
1769
+ z-index: 2;
1770
+
1771
+ .bb-gallery__caption-text {
1772
+ overflow: visible;
1773
+ }
1774
+
1775
+ .bb-gallery__more {
1776
+ margin-inline-start: 8px;
1777
+ }
1778
+ }
1779
+
1780
+ /* A phone gives the width to the words: the caption takes the whole row
1781
+ but the counter's cell. */
1782
+ @media (max-width: 480px) {
1783
+ .bb-gallery__bar {
1784
+ grid-template-columns: minmax(0, 1fr) auto;
1785
+ }
1786
+
1787
+ .bb-gallery__caption {
1788
+ grid-column: 1;
1789
+ }
1790
+
1791
+ .bb-gallery__counter {
1792
+ grid-column: 2;
1793
+ }
1794
+
1795
+ .bb-gallery__caption--open {
1796
+ grid-column: 1 / -1;
1797
+ padding-inline: var(--bar-px) calc(var(--bar-px) + 7ch);
1798
+ }
1799
+ }
1800
+
1801
+ .bb-gallery__more {
1802
+ appearance: none;
1803
+ background: transparent;
1804
+ border: 0;
1805
+ border-radius: 4px;
1806
+ /* A quiet link in the caption's own colour and size. */
1807
+ color: inherit;
1808
+ cursor: pointer;
1809
+ font: inherit;
1810
+ padding: 0 2px;
1811
+ text-decoration: underline;
1812
+ text-decoration-color: color-mix(in oklab, currentColor 45%, transparent);
1813
+ text-decoration-thickness: 1px;
1814
+ text-underline-offset: 3px;
1815
+ touch-action: manipulation;
1816
+ transition:
1817
+ color var(--bb-transition-fast),
1818
+ text-decoration-color var(--bb-transition-fast);
1819
+ white-space: nowrap;
1820
+
1821
+ &:hover {
1822
+ color: var(--viewer-fg);
1823
+ text-decoration-color: currentColor;
1824
+ }
1825
+
1826
+ &:focus-visible {
1827
+ outline: 2px solid var(--viewer-fg);
1828
+ outline-offset: 2px;
1829
+ }
1830
+ }
1831
+
1832
+ /* A file that failed: its words in the photo's place, never the browser's
1833
+ broken-image glyph. */
1834
+ .bb-gallery__missing {
1835
+ color: var(--viewer-muted);
1836
+ font-size: var(--bb-fs);
1837
+ line-height: 1.4;
1838
+ margin: 0;
1839
+ max-width: 40ch;
1840
+ padding: 8px;
1841
+ text-align: center;
1842
+ }
1843
+
1844
+ /* A failed photo with no alt: an empty plate where it would be. */
1845
+ .bb-gallery__missing--blank {
1846
+ aspect-ratio: 4 / 3;
1847
+ border: 1px solid color-mix(in oklab, var(--viewer-fg) 15%, transparent);
1848
+ border-radius: var(--bb-radius);
1849
+ width: min(60%, 28rem);
1850
+ }
1851
+
1852
+ .bb-gallery ::selection {
1853
+ background: color-mix(in oklab, var(--viewer-fg) 25%, transparent);
1854
+ color: var(--viewer-fg);
1855
+ }
1856
+
1857
+ /* The arrows: a plate of the viewer's own colour and a glyph shadowed in
1858
+ it, legible over any photo (on a light viewer the shadow disappears into
1859
+ the plate it sits on). */
1860
+ .bb-gallery__nav {
1861
+ align-items: center;
1862
+ appearance: none;
1863
+ backdrop-filter: blur(8px);
1864
+ background: var(--plate);
1865
+ border: 0;
1866
+ border-radius: 999px;
1867
+ box-shadow: inset 0 0 0 1px
1868
+ color-mix(in oklab, var(--viewer-fg) 15%, transparent);
1869
+ color: var(--viewer-fg);
1870
+ cursor: pointer;
1871
+ display: flex;
1872
+ height: var(--nav-size);
1873
+ inset-block-start: 50%;
1874
+ justify-content: center;
1875
+ padding: 0;
1876
+ position: absolute;
1877
+ touch-action: manipulation;
1878
+ transform: translateY(-50%);
1879
+ transition:
1880
+ background-color var(--bb-transition-fast) var(--bb-ease, ease),
1881
+ opacity var(--bb-transition-fast) var(--bb-ease, ease),
1882
+ transform var(--bb-transition-fast) var(--bb-ease, ease);
1883
+ width: var(--nav-size);
1884
+
1885
+ svg {
1886
+ filter: drop-shadow(
1887
+ 0 1px 2px color-mix(in oklab, var(--viewer-bg) 60%, transparent)
1888
+ );
1889
+ }
1890
+
1891
+ &:hover:not(:disabled) {
1892
+ background: color-mix(in oklab, var(--viewer-bg) 75%, transparent);
1893
+ }
1894
+
1895
+ /* A press you can feel: the button gives a little. */
1896
+ &:active:not(:disabled) {
1897
+ transform: translateY(-50%) scale(0.94);
1898
+ }
1899
+
1900
+ &:focus-visible {
1901
+ outline: 2px solid var(--viewer-fg);
1902
+ outline-offset: 2px;
1903
+ }
1904
+
1905
+ &:disabled {
1906
+ cursor: default;
1907
+ opacity: 0;
1908
+ pointer-events: none;
1909
+ }
1910
+ }
1911
+
1912
+ .bb-gallery__nav--prev {
1913
+ inset-inline-start: var(--bar-px);
1914
+ }
1915
+
1916
+ .bb-gallery__nav--next {
1917
+ inset-inline-end: var(--bar-px);
1918
+ }
1919
+
1920
+ /* Zoomed or being dismissed: nothing over the photo. */
1921
+ .bb-gallery--zoomed .bb-gallery__nav,
1922
+ .bb-gallery--dismissing .bb-gallery__nav {
1923
+ opacity: 0;
1924
+ pointer-events: none;
1925
+ }
1926
+
1927
+ /* With a mouse and room to spare, the arrows sit beside the photo, not on it. */
1928
+ @media (pointer: fine) and (min-width: 640px) {
1929
+ .bb-gallery__slide {
1930
+ padding-inline: calc(var(--bar-px) + var(--nav-size) + 12px);
1931
+ }
1932
+ }
1933
+
1934
+ /* A mirrored strip mirrors its arrows. */
1935
+ [dir='rtl'] .bb-gallery__nav svg {
1936
+ transform: scaleX(-1);
1937
+ }
1938
+
1939
+ /* On a phone the swipe is the way through; the arrows stay for a keyboard
1940
+ or a switch user, low in the corners, and the slide keeps their row free
1941
+ so the photo never runs under them. */
1942
+ @media (pointer: coarse) {
1943
+ .bb-gallery__nav {
1944
+ inset-block-end: 8px;
1945
+ inset-block-start: auto;
1946
+ transform: none;
1947
+
1948
+ &:active:not(:disabled) {
1949
+ transform: scale(0.94);
1950
+ }
1951
+ }
1952
+
1953
+ .bb-gallery__slide {
1954
+ padding-block-end: calc(var(--nav-size) + 16px);
1955
+ }
1956
+ }
1957
+
1958
+ /* A tap on the photo puts the bars and arrows away (and brings them back).
1959
+ Never while focus is in them. */
1960
+ .bb-gallery--quiet {
1961
+ .bb-gallery__header:not(:focus-within),
1962
+ .bb-gallery__footer:not(:focus-within),
1963
+ .bb-gallery__nav:not(:focus-visible) {
1964
+ opacity: 0;
1965
+ pointer-events: none;
1966
+ }
1967
+ }
1968
+
1969
+ /* A phone on its side: the bars lie over the photo on a scrim instead of
1970
+ taking a third of the height. */
1971
+ @media (max-height: 500px) {
1972
+ .bb-gallery__header,
1973
+ .bb-gallery__footer {
1974
+ inset-inline: 0;
1975
+ position: absolute;
1976
+ z-index: 1;
1977
+ }
1978
+
1979
+ .bb-gallery__header {
1980
+ background: linear-gradient(
1981
+ color-mix(in oklab, var(--viewer-bg) 60%, transparent),
1982
+ transparent
1983
+ );
1984
+ inset-block-start: 0;
1985
+ }
1986
+
1987
+ .bb-gallery__footer {
1988
+ background: linear-gradient(
1989
+ transparent,
1990
+ color-mix(in oklab, var(--viewer-bg) 60%, transparent)
1991
+ );
1992
+ inset-block-end: 0;
1993
+ }
1994
+
1995
+ .bb-gallery__slide {
1996
+ padding-block: 0;
1997
+ }
1998
+ }
1999
+
2000
+ @media (forced-colors: active) {
2001
+ .bb-gallery__nav,
2002
+ .bb-gallery__header > .bb-gallery__close {
2003
+ background: ButtonFace;
2004
+ border: 1px solid ButtonText;
2005
+ color: ButtonText;
2006
+ }
2007
+
2008
+ .bb-gallery__caption--open {
2009
+ background: Canvas;
2010
+ border: 1px solid CanvasText;
2011
+ color: CanvasText;
2012
+ }
2013
+
2014
+ .bb-gallery__more {
2015
+ color: LinkText;
2016
+ }
2017
+ }
2018
+
2019
+ @media (prefers-reduced-motion: reduce) {
2020
+ .bb-gallery__nav,
2021
+ .bb-gallery__slide--active .bb-gallery__image,
2022
+ .bb-gallery__header,
2023
+ .bb-gallery__footer {
2024
+ transition: none;
2025
+ }
2026
+ }
2027
+ ```