@bk2k/ui 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/USAGE.md +20 -9
  3. package/custom-elements.json +1 -1
  4. package/dist/charts/frame.d.ts +2 -0
  5. package/dist/components/bk-alert.js +1 -1
  6. package/dist/components/bk-button.d.ts +5 -0
  7. package/dist/components/bk-button.js +15 -4
  8. package/dist/components/bk-card.d.ts +6 -3
  9. package/dist/components/bk-card.js +15 -9
  10. package/dist/components/bk-chart-area.d.ts +4 -0
  11. package/dist/components/bk-chart-line.d.ts +15 -0
  12. package/dist/components/bk-chart-line.js +16 -6
  13. package/dist/components/bk-chip.d.ts +2 -0
  14. package/dist/components/bk-chip.js +3 -1
  15. package/dist/components/bk-combobox.d.ts +2 -2
  16. package/dist/components/bk-combobox.js +7 -20
  17. package/dist/components/bk-footnotes-item.d.ts +2 -2
  18. package/dist/components/bk-image-compare.d.ts +36 -1
  19. package/dist/components/bk-image-compare.js +47 -11
  20. package/dist/components/bk-image-viewer.d.ts +74 -3
  21. package/dist/components/bk-image-viewer.js +115 -28
  22. package/dist/components/bk-input-color.d.ts +2 -5
  23. package/dist/components/bk-input-color.js +0 -14
  24. package/dist/components/bk-input-file.d.ts +17 -0
  25. package/dist/components/bk-input-file.js +18 -8
  26. package/dist/components/bk-input-tags.d.ts +219 -0
  27. package/dist/components/bk-input-tags.js +293 -0
  28. package/dist/components/bk-input-text.d.ts +9 -0
  29. package/dist/components/bk-input-text.js +18 -2
  30. package/dist/components/bk-lightbox.d.ts +25 -1
  31. package/dist/components/bk-lightbox.js +7 -0
  32. package/dist/components/bk-page-cta.d.ts +2 -0
  33. package/dist/components/bk-page-cta.js +8 -1
  34. package/dist/components/bk-split-grid.js +7 -2
  35. package/dist/components/bk-stat.d.ts +2 -0
  36. package/dist/components/bk-stat.js +1 -1
  37. package/dist/components/bk-table.d.ts +2 -0
  38. package/dist/components/bk-table.js +1 -1
  39. package/dist/components/bk-tabs.d.ts +2 -1
  40. package/dist/components/bk-tabs.js +15 -3
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.js +1 -0
  43. package/dist/internal/announcer.d.ts +6 -0
  44. package/dist/internal/announcer.js +7 -2
  45. package/dist/internal/cloak.js +1 -0
  46. package/dist/internal/define.d.ts +9 -0
  47. package/dist/internal/define.js +47 -1
  48. package/dist/internal/elements.d.ts +6 -0
  49. package/dist/internal/elements.js +5 -0
  50. package/dist/internal/hue.d.ts +8 -0
  51. package/dist/internal/hue.js +15 -4
  52. package/dist/internal/late/bk-tabs.d.ts +4 -0
  53. package/dist/internal/late/bk-tabs.js +8 -0
  54. package/dist/internal/late.js +3 -3
  55. package/dist/internal/tags.d.ts +15 -0
  56. package/dist/internal/tags.js +44 -0
  57. package/dist/internal/text-field.d.ts +2 -0
  58. package/dist/internal/text-field.js +8 -0
  59. package/dist/internal/toggle-control.js +3 -1
  60. package/dist/jsx.d.ts +85 -6
  61. package/dist/kit.d.ts +1 -0
  62. package/dist/kit.js +3 -0
  63. package/dist/reset.css +1 -1
  64. package/dist/standalone/all.js +106 -105
  65. package/dist/standalone/bk-accordion-item.js +3 -3
  66. package/dist/standalone/bk-accordion.js +1 -1
  67. package/dist/standalone/bk-action-bar.js +1 -1
  68. package/dist/standalone/bk-alert-offline.js +1 -1
  69. package/dist/standalone/bk-alert.js +7 -4
  70. package/dist/standalone/bk-app-state.js +1 -1
  71. package/dist/standalone/bk-attachment.js +2 -2
  72. package/dist/standalone/bk-avatar-group.js +1 -1
  73. package/dist/standalone/bk-avatar.js +3 -3
  74. package/dist/standalone/bk-badge.js +1 -1
  75. package/dist/standalone/bk-bar.js +1 -1
  76. package/dist/standalone/bk-brand.js +1 -1
  77. package/dist/standalone/bk-breadcrumbs.js +2 -2
  78. package/dist/standalone/bk-button-copy.js +4 -4
  79. package/dist/standalone/bk-button-group.js +2 -2
  80. package/dist/standalone/bk-button-share.js +4 -4
  81. package/dist/standalone/bk-button-top.js +1 -1
  82. package/dist/standalone/bk-button.js +14 -6
  83. package/dist/standalone/bk-calendar-event.js +1 -1
  84. package/dist/standalone/bk-calendar-week.js +1 -1
  85. package/dist/standalone/bk-calendar.js +2 -2
  86. package/dist/standalone/bk-card.js +17 -11
  87. package/dist/standalone/bk-carousel-controls.js +2 -2
  88. package/dist/standalone/bk-carousel-item.js +1 -1
  89. package/dist/standalone/bk-carousel.js +1 -1
  90. package/dist/standalone/bk-chart-area.js +1 -1
  91. package/dist/standalone/bk-chart-bar-list.js +2 -2
  92. package/dist/standalone/bk-chart-bar.js +1 -1
  93. package/dist/standalone/bk-chart-bridge.js +1 -1
  94. package/dist/standalone/bk-chart-bullet.js +1 -1
  95. package/dist/standalone/bk-chart-calendar.js +1 -1
  96. package/dist/standalone/bk-chart-heatmap.js +1 -1
  97. package/dist/standalone/bk-chart-histogram.js +1 -1
  98. package/dist/standalone/bk-chart-legend.js +1 -1
  99. package/dist/standalone/bk-chart-line.js +16 -8
  100. package/dist/standalone/bk-chart-mark.js +1 -1
  101. package/dist/standalone/bk-chart-scatter.js +1 -1
  102. package/dist/standalone/bk-chart-sparkline.js +1 -1
  103. package/dist/standalone/bk-chart-stacked-bar.js +1 -1
  104. package/dist/standalone/bk-chart-tracker.js +1 -1
  105. package/dist/standalone/bk-chart-waterfall.js +2 -2
  106. package/dist/standalone/bk-checkbox-group.js +5 -5
  107. package/dist/standalone/bk-checkbox.js +3 -3
  108. package/dist/standalone/bk-chip-group.js +4 -4
  109. package/dist/standalone/bk-chip.js +5 -3
  110. package/dist/standalone/bk-cluster.js +1 -1
  111. package/dist/standalone/bk-code-diff.js +2 -2
  112. package/dist/standalone/bk-code-stack.js +1 -1
  113. package/dist/standalone/bk-code.js +1 -1
  114. package/dist/standalone/bk-color-panel.js +2 -2
  115. package/dist/standalone/bk-columns.js +1 -1
  116. package/dist/standalone/bk-combobox.js +21 -30
  117. package/dist/standalone/bk-command-menu.js +3 -3
  118. package/dist/standalone/bk-command-palette.js +4 -4
  119. package/dist/standalone/bk-composer.js +4 -4
  120. package/dist/standalone/bk-delta.js +1 -1
  121. package/dist/standalone/bk-diagram.js +1 -1
  122. package/dist/standalone/bk-dialog.js +1 -1
  123. package/dist/standalone/bk-disclosure.js +2 -2
  124. package/dist/standalone/bk-divider.js +4 -4
  125. package/dist/standalone/bk-drawer.js +2 -2
  126. package/dist/standalone/bk-drop-target.js +1 -1
  127. package/dist/standalone/bk-empty-state.js +2 -2
  128. package/dist/standalone/bk-error-summary.js +1 -1
  129. package/dist/standalone/bk-facts-item.js +1 -1
  130. package/dist/standalone/bk-facts.js +1 -1
  131. package/dist/standalone/bk-feature.js +2 -2
  132. package/dist/standalone/bk-fieldset.js +1 -1
  133. package/dist/standalone/bk-filter-bar.js +2 -2
  134. package/dist/standalone/bk-folder-browser.js +2 -2
  135. package/dist/standalone/bk-footnote.js +1 -1
  136. package/dist/standalone/bk-footnotes-item.js +2 -2
  137. package/dist/standalone/bk-footnotes.js +1 -1
  138. package/dist/standalone/bk-form-guard.js +1 -1
  139. package/dist/standalone/bk-form-steps.js +1 -1
  140. package/dist/standalone/bk-grid.js +1 -1
  141. package/dist/standalone/bk-icon-tile.js +2 -2
  142. package/dist/standalone/bk-icon.js +1 -1
  143. package/dist/standalone/bk-image-compare.js +55 -27
  144. package/dist/standalone/bk-image-crop.js +3 -3
  145. package/dist/standalone/bk-image-editor.js +1 -1
  146. package/dist/standalone/bk-image-viewer.js +127 -57
  147. package/dist/standalone/bk-input-code.js +2 -2
  148. package/dist/standalone/bk-input-color.js +3 -13
  149. package/dist/standalone/bk-input-date-range.js +2 -2
  150. package/dist/standalone/bk-input-date.js +2 -2
  151. package/dist/standalone/bk-input-file.js +20 -13
  152. package/dist/standalone/bk-input-group.js +2 -2
  153. package/dist/standalone/bk-input-inline.js +1 -1
  154. package/dist/standalone/bk-input-number.js +4 -4
  155. package/dist/standalone/bk-input-rating.js +4 -4
  156. package/dist/standalone/bk-input-rich.js +1 -1
  157. package/dist/standalone/bk-input-search.js +4 -4
  158. package/dist/standalone/bk-input-slider-range.js +2 -2
  159. package/dist/standalone/bk-input-slider.js +2 -2
  160. package/dist/standalone/bk-input-tags.js +224 -0
  161. package/dist/standalone/bk-input-text.js +1 -1
  162. package/dist/standalone/bk-input-time-zone.js +1 -1
  163. package/dist/standalone/bk-input-time.js +4 -4
  164. package/dist/standalone/bk-item-group.js +2 -2
  165. package/dist/standalone/bk-item.js +2 -2
  166. package/dist/standalone/bk-kbd-shortcuts.js +1 -1
  167. package/dist/standalone/bk-kbd.js +1 -1
  168. package/dist/standalone/bk-lightbox.js +16 -3
  169. package/dist/standalone/bk-lines.js +1 -1
  170. package/dist/standalone/bk-link.js +2 -2
  171. package/dist/standalone/bk-listbox-columns.js +6 -6
  172. package/dist/standalone/bk-listbox-item.js +1 -1
  173. package/dist/standalone/bk-listbox-search.js +5 -5
  174. package/dist/standalone/bk-listbox-transfer.js +4 -4
  175. package/dist/standalone/bk-listbox.js +5 -5
  176. package/dist/standalone/bk-logo-wall.js +1 -1
  177. package/dist/standalone/bk-logo.js +2 -2
  178. package/dist/standalone/bk-menu-bar.js +1 -1
  179. package/dist/standalone/bk-menu-context.js +1 -1
  180. package/dist/standalone/bk-menu-divider.js +1 -1
  181. package/dist/standalone/bk-menu-item.js +2 -2
  182. package/dist/standalone/bk-menu-label.js +1 -1
  183. package/dist/standalone/bk-menu-list.js +1 -1
  184. package/dist/standalone/bk-menu.js +4 -4
  185. package/dist/standalone/bk-message-approval.js +2 -2
  186. package/dist/standalone/bk-message-branches.js +1 -1
  187. package/dist/standalone/bk-message-citation.js +1 -1
  188. package/dist/standalone/bk-message-feedback.js +2 -2
  189. package/dist/standalone/bk-message-list.js +2 -2
  190. package/dist/standalone/bk-message-reasoning.js +3 -3
  191. package/dist/standalone/bk-message-source.js +1 -1
  192. package/dist/standalone/bk-message-tool-group.js +3 -3
  193. package/dist/standalone/bk-message-tool.js +3 -3
  194. package/dist/standalone/bk-message.js +2 -2
  195. package/dist/standalone/bk-meter.js +1 -1
  196. package/dist/standalone/bk-model-viewer.js +1 -1
  197. package/dist/standalone/bk-nav-divider.js +1 -1
  198. package/dist/standalone/bk-nav-group.js +5 -5
  199. package/dist/standalone/bk-nav-item.js +2 -2
  200. package/dist/standalone/bk-nav-toc.js +1 -1
  201. package/dist/standalone/bk-nav.js +1 -1
  202. package/dist/standalone/bk-overflow.js +1 -1
  203. package/dist/standalone/bk-page-cta.js +10 -3
  204. package/dist/standalone/bk-page-footer-column.js +1 -1
  205. package/dist/standalone/bk-page-footer.js +1 -1
  206. package/dist/standalone/bk-page-header.js +2 -2
  207. package/dist/standalone/bk-page-hero.js +2 -2
  208. package/dist/standalone/bk-page-pager.js +2 -2
  209. package/dist/standalone/bk-page-section.js +2 -2
  210. package/dist/standalone/bk-pagination.js +3 -3
  211. package/dist/standalone/bk-pane.js +2 -2
  212. package/dist/standalone/bk-panel.js +2 -2
  213. package/dist/standalone/bk-period-nav.js +2 -2
  214. package/dist/standalone/bk-picture.js +1 -175
  215. package/dist/standalone/bk-popover-help.js +1 -1
  216. package/dist/standalone/bk-popover.js +1 -1
  217. package/dist/standalone/bk-presence-cursor.js +2 -2
  218. package/dist/standalone/bk-preview.js +2 -2
  219. package/dist/standalone/bk-progress.js +1 -1
  220. package/dist/standalone/bk-prose.js +1 -1
  221. package/dist/standalone/bk-qr-code.js +1 -1
  222. package/dist/standalone/bk-radio-group.js +5 -5
  223. package/dist/standalone/bk-radio.js +2 -2
  224. package/dist/standalone/bk-rating.js +3 -3
  225. package/dist/standalone/bk-scroll.js +1 -1
  226. package/dist/standalone/bk-segmented-item.js +2 -2
  227. package/dist/standalone/bk-segmented.js +4 -4
  228. package/dist/standalone/bk-select-cascade.js +3 -3
  229. package/dist/standalone/bk-select-tree.js +4 -4
  230. package/dist/standalone/bk-select.js +4 -4
  231. package/dist/standalone/bk-shell-app.js +1 -1
  232. package/dist/standalone/bk-shell-centered.js +1 -1
  233. package/dist/standalone/bk-shell-sites.js +1 -1
  234. package/dist/standalone/bk-skeleton.js +1 -1
  235. package/dist/standalone/bk-sortable.js +2 -2
  236. package/dist/standalone/bk-spinner.js +1 -1
  237. package/dist/standalone/bk-split-grid.js +10 -7
  238. package/dist/standalone/bk-split.js +6 -6
  239. package/dist/standalone/bk-stack.js +1 -1
  240. package/dist/standalone/bk-stat-group.js +1 -1
  241. package/dist/standalone/bk-stat.js +3 -3
  242. package/dist/standalone/bk-status-dot.js +2 -2
  243. package/dist/standalone/bk-steps-item.js +2 -2
  244. package/dist/standalone/bk-steps.js +1 -1
  245. package/dist/standalone/bk-surface.js +1 -1
  246. package/dist/standalone/bk-swatch-group.js +6 -6
  247. package/dist/standalone/bk-swatch-palette.js +1 -1
  248. package/dist/standalone/bk-swatch.js +1 -1
  249. package/dist/standalone/bk-switch.js +2 -2
  250. package/dist/standalone/bk-table.js +1 -1
  251. package/dist/standalone/bk-tabs-item.js +2 -2
  252. package/dist/standalone/bk-tabs-panel.js +1 -1
  253. package/dist/standalone/bk-tabs.js +3 -414
  254. package/dist/standalone/bk-tasks-item.js +2 -2
  255. package/dist/standalone/bk-tasks.js +1 -1
  256. package/dist/standalone/bk-testimonial.js +2 -2
  257. package/dist/standalone/bk-text.js +3 -3
  258. package/dist/standalone/bk-time-countdown.js +2 -2
  259. package/dist/standalone/bk-time-relative.js +1 -1
  260. package/dist/standalone/bk-timeline-item.js +2 -2
  261. package/dist/standalone/bk-timeline.js +1 -1
  262. package/dist/standalone/bk-toast-group.js +1 -1
  263. package/dist/standalone/bk-toast.js +2 -2
  264. package/dist/standalone/bk-toolbar.js +1 -1
  265. package/dist/standalone/bk-tooltip.js +1 -1
  266. package/dist/standalone/bk-tree-item.js +3 -3
  267. package/dist/standalone/bk-tree.js +4 -4
  268. package/dist/standalone/bk-video.js +2 -2
  269. package/dist/standalone/bk-visually-hidden.js +1 -1
  270. package/dist/standalone/bk-zoom.js +3 -3
  271. package/dist/standalone/chunks/{announcer-D1zrRWwO.js → announcer-6tMlCOq1.js} +9 -4
  272. package/dist/standalone/chunks/{bk-alert-offline-Clw0ZSsH.js → bk-alert-offline-hCLuG-RM.js} +1 -1
  273. package/dist/standalone/chunks/{bk-carousel-Biz7t8sL.js → bk-carousel-_dudBMVq.js} +2 -2
  274. package/dist/standalone/chunks/{bk-diagram-D_fQf6SF.js → bk-diagram-BB2odomE.js} +2 -2
  275. package/dist/standalone/chunks/{bk-dialog-DwZyUUHh.js → bk-dialog-DcvwnOtN.js} +2 -2
  276. package/dist/standalone/chunks/{bk-icon-Bp_flKdv.js → bk-icon-D4kI4F18.js} +1 -1
  277. package/dist/standalone/chunks/{bk-image-editor-BADsoLRL.js → bk-image-editor-SRVkHI-4.js} +2 -2
  278. package/dist/standalone/chunks/{bk-input-date-range-DHcJ8-5g.js → bk-input-date-range-C0Vd-p0T.js} +2 -2
  279. package/dist/standalone/chunks/{bk-input-rich-CFhW6vRa.js → bk-input-rich-AmDv87E5.js} +3 -3
  280. package/dist/standalone/chunks/{bk-input-text-DviyLBqj.js → bk-input-text-2n89GDIT.js} +15 -5
  281. package/dist/standalone/chunks/{bk-model-viewer-w_Ah4Tvs.js → bk-model-viewer-BoNYBd6W.js} +2 -2
  282. package/dist/standalone/chunks/bk-picture-CA5gLxgZ.js +186 -0
  283. package/dist/standalone/chunks/{bk-qr-code-CYMovNVl.js → bk-qr-code-CSFfc8As.js} +1 -1
  284. package/dist/standalone/chunks/{bk-shell-app-B2lxHit8.js → bk-shell-app-BlCOG25y.js} +31 -30
  285. package/dist/standalone/chunks/{bk-surface-D7e0tErs.js → bk-surface-BULRdKam.js} +1 -1
  286. package/dist/standalone/chunks/{bk-swatch-palette-x13JgJQi.js → bk-swatch-palette-Cqj85tSW.js} +1 -1
  287. package/dist/standalone/chunks/{bk-table-CP8n_jy7.js → bk-table-DWlD7yoM.js} +72 -71
  288. package/dist/standalone/chunks/bk-tabs-STkr3-E1.js +422 -0
  289. package/dist/standalone/chunks/{bk-toast-group-CoL6W7uk.js → bk-toast-group-5nZg7BaJ.js} +2 -2
  290. package/dist/standalone/chunks/{busy-BUB22mGY.js → busy-eG3uHonz.js} +1 -1
  291. package/dist/standalone/chunks/{choice-field-poOTerh1.js → choice-field-B0oe_9fI.js} +4 -4
  292. package/dist/standalone/chunks/{date-field-B-fCXa2D.js → date-field-Dy1_qxNv.js} +2 -2
  293. package/dist/standalone/chunks/define-6OfuRn5c.js +60 -0
  294. package/dist/standalone/chunks/{form-control-CHpfKAKa.js → form-control-Bmk0SRDX.js} +1 -1
  295. package/dist/standalone/chunks/{handle-menu-BgYUbGO2.js → handle-menu-BAe9fPYJ.js} +10 -36
  296. package/dist/standalone/chunks/{heading-text-CgnCa_q2.js → heading-text-B2kF-b8p.js} +1 -1
  297. package/dist/standalone/chunks/hue-vLbNdAEl.js +20 -0
  298. package/dist/standalone/chunks/late-CPQ_RbU-.js +30 -0
  299. package/dist/standalone/chunks/{options-BdC8-KKM.js → options-ySaDL-dW.js} +1 -1
  300. package/dist/standalone/chunks/{stars-BgKEjDQx.js → stars-BAUc_LqI.js} +1 -1
  301. package/dist/standalone/chunks/tags-CMLAGsVw.js +37 -0
  302. package/dist/standalone/chunks/{text-field-CqhJSAwZ.js → text-field-CufOGdfr.js} +16 -10
  303. package/dist/standalone/chunks/{toggle-control-lvZbQtGW.js → toggle-control-Cgqp1jhf.js} +4 -2
  304. package/dist/standalone/chunks/{virtual-C_h6sHnm.js → virtual-D-qgACnE.js} +1 -1
  305. package/dist/standalone/confirm.js +2 -2
  306. package/dist/standalone/reset.css +1 -1
  307. package/dist/standalone/toast.js +1 -1
  308. package/dist/standalone/tokens.css +1 -1
  309. package/dist/tokens.css +1 -1
  310. package/package.json +2 -2
  311. package/dist/standalone/chunks/define-DkVeu7e9.js +0 -30
  312. package/dist/standalone/chunks/hue-Jvb-141g.js +0 -14
  313. package/dist/standalone/chunks/keyed-CZ2AaouM.js +0 -16
@@ -7,8 +7,10 @@ import { emit, emitDetail } from "../internal/events.js";
7
7
  import { PanZoom, capture } from "../internal/pan-zoom.js";
8
8
  import { base, srOnly } from "../internal/styles.js";
9
9
  import { SlotController } from "../internal/slots.js";
10
+ import { setHostVars } from "../internal/host-vars.js";
10
11
  import "./bk-icon.js";
11
12
  import "./bk-segmented.js";
13
+ import "./bk-segmented-item.js";
12
14
  import "./bk-button.js";
13
15
  import "./bk-zoom.js";
14
16
  import "../icons/set/chevron-left.js";
@@ -31,7 +33,9 @@ class BkImageCompare extends LitElement {
31
33
  position: { type: Number },
32
34
  show: { reflect: true, useDefault: true },
33
35
  zoomable: { type: Boolean, reflect: true },
36
+ shaped: { type: Boolean, reflect: true },
34
37
  ratio: { state: true },
38
+ naturalSize: { state: true },
35
39
  sliding: { state: true }
36
40
  };
37
41
  i18n = new LocalizeController(this);
@@ -52,7 +56,9 @@ class BkImageCompare extends LitElement {
52
56
  this.position = 50;
53
57
  this.show = "after";
54
58
  this.zoomable = false;
59
+ this.shaped = false;
55
60
  this.ratio = 0;
61
+ this.naturalSize = 0;
56
62
  this.sliding = false;
57
63
  this.internals.role = "group";
58
64
  }
@@ -65,6 +71,15 @@ class BkImageCompare extends LitElement {
65
71
  --_bk-image-compare-control-fg: var(--bk-image-compare-control-fg, var(--bk-on-media));
66
72
  --_bk-image-compare-radius: var(--bk-image-compare-radius, var(--bk-radius-md));
67
73
  }
74
+ /* shaped: the width follows the ratio under the cap, never wider than the container or the natural pictures. With
75
+ side, the width is two boxes and the gap. */
76
+ :host([shaped]:not(:state(content))) {
77
+ --_bk-image-compare-cap: var(--bk-image-compare-max-height, calc(infinity * 1px));
78
+ --_bk-image-compare-shape: var(--bk-image-compare-ratio, var(--_bk-image-compare-ratio, 4 / 3));
79
+ inline-size: min(100%,
80
+ calc(var(--_bk-image-compare-cols, 1) * var(--_bk-image-compare-natural, calc(infinity * 1px)) + (var(--_bk-image-compare-cols, 1) - 1) * var(--_bk-image-compare-gap)),
81
+ calc(var(--_bk-image-compare-cols, 1) * var(--_bk-image-compare-cap) * var(--_bk-image-compare-shape) + (var(--_bk-image-compare-cols, 1) - 1) * var(--_bk-image-compare-gap)));
82
+ }
68
83
  .compare { display: grid; gap: var(--_bk-image-compare-gap); min-width: 0; }
69
84
  .view { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--_bk-image-compare-gap); border-radius: var(--_bk-image-compare-radius); }
70
85
  .view.side { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@@ -77,6 +92,8 @@ class BkImageCompare extends LitElement {
77
92
  .stage {
78
93
  position: relative; grid-row: 1; grid-column: 1; overflow: hidden; isolation: isolate;
79
94
  aspect-ratio: var(--bk-image-compare-ratio, var(--_bk-image-compare-ratio, 4 / 3));
95
+ /* Under the cap the box keeps the full width: stretch, not the width from the ratio of a grid item. */
96
+ max-block-size: var(--bk-image-compare-max-height, none); justify-self: stretch;
80
97
  border-radius: var(--_bk-image-compare-radius); user-select: none; -webkit-user-select: none;
81
98
  }
82
99
  /* The backdrop stays a hairline inside the edge: the smoothed edge of a picture never mixes with it. */
@@ -86,7 +103,7 @@ class BkImageCompare extends LitElement {
86
103
  background: var(--bk-image-compare-bg, var(--bk-media-backdrop));
87
104
  }
88
105
  /* Content: the sides lie in one grid cell, and the larger side gives the size of the box. */
89
- .stage.content { display: grid; aspect-ratio: auto; user-select: text; -webkit-user-select: text; }
106
+ .stage.content { display: grid; aspect-ratio: auto; max-block-size: none; user-select: text; -webkit-user-select: text; }
90
107
  .stage.content::before { display: none; }
91
108
  .stage.content > .layer { position: relative; inset: auto; grid-area: 1 / 1; min-inline-size: 0; }
92
109
  .layer.slotted {
@@ -115,9 +132,12 @@ class BkImageCompare extends LitElement {
115
132
  .tag {
116
133
  position: absolute; inset-block-start: var(--_bk-image-compare-pad); max-inline-size: 40%;
117
134
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
118
- padding: var(--bk-space-1) var(--bk-space-2); border-radius: var(--bk-radius-full);
135
+ /* Letter spacing also follows the last letter: the end padding gives it back, so the text stays centred. */
136
+ padding-block: var(--bk-space-1); padding-inline: var(--bk-space-2) calc(var(--bk-space-2) - var(--bk-image-compare-label-tracking, 0em));
137
+ border-radius: var(--bk-radius-full);
119
138
  background: var(--_bk-image-compare-control-bg); color: var(--_bk-image-compare-control-fg); backdrop-filter: var(--bk-glass);
120
139
  font-size: var(--bk-type-small); line-height: var(--bk-line-height-tight);
140
+ text-transform: var(--bk-image-compare-label-transform, none); letter-spacing: var(--bk-image-compare-label-tracking, 0em);
121
141
  }
122
142
  .tags.before .tag { inset-inline-start: var(--_bk-image-compare-pad); }
123
143
  .tags.after .tag { inset-inline-end: var(--_bk-image-compare-pad); }
@@ -177,6 +197,8 @@ class BkImageCompare extends LitElement {
177
197
  .caption {
178
198
  min-width: 0; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
179
199
  font-size: var(--bk-type-small); color: var(--bk-image-compare-caption-color, var(--bk-text-muted));
200
+ text-transform: var(--bk-image-compare-label-transform, none); letter-spacing: var(--bk-image-compare-label-tracking, 0em);
201
+ padding-inline-start: var(--bk-image-compare-label-tracking, 0em);
180
202
  }
181
203
  .switch { justify-self: center; }
182
204
  @media (prefers-reduced-motion: reduce) { .frame, .line, .handle { transition: none; } }
@@ -220,8 +242,10 @@ class BkImageCompare extends LitElement {
220
242
  willUpdate(changed) {
221
243
  if (changed.has("position"))
222
244
  this.position = clamp(Number(this.position) || 0, 0, 100);
223
- if (changed.has("afterSrc") || changed.has("beforeSrc"))
245
+ if (changed.has("afterSrc") || changed.has("beforeSrc")) {
224
246
  this.ratio = 0;
247
+ this.naturalSize = 0;
248
+ }
225
249
  const zoom = this.zoomable && !this.content;
226
250
  if (this.pz.enabled !== zoom) {
227
251
  this.pz.enabled = zoom;
@@ -231,6 +255,15 @@ class BkImageCompare extends LitElement {
231
255
  if (changed.has("label") || changed.has("beforeLabel") || changed.has("afterLabel")) {
232
256
  this.internals.ariaLabel = this.label || this.i18n.t("imageCompare");
233
257
  }
258
+ if (this.content)
259
+ this.internals.states?.add("content");
260
+ else
261
+ this.internals.states?.delete("content");
262
+ setHostVars(this, {
263
+ "--_bk-image-compare-ratio": this.ratio ? String(this.ratio) : "",
264
+ "--_bk-image-compare-natural": this.naturalSize && this.ratio ? `${this.naturalSize}px` : "",
265
+ "--_bk-image-compare-cols": this.mode === "side" ? "2" : ""
266
+ });
234
267
  }
235
268
  get content() {
236
269
  return this.slots.has("before") || this.slots.has("after");
@@ -246,8 +279,11 @@ class BkImageCompare extends LitElement {
246
279
  }
247
280
  onLoad(side, e) {
248
281
  const img = e.target;
249
- if ((side === "after" || !this.afterSrc) && img.naturalWidth && img.naturalHeight)
282
+ if ((side === "after" || !this.afterSrc) && img.naturalWidth && img.naturalHeight) {
250
283
  this.ratio = img.naturalWidth / img.naturalHeight;
284
+ this.naturalSize = img.naturalWidth;
285
+ }
286
+ emitDetail(this, "load", { side, naturalWidth: img.naturalWidth, naturalHeight: img.naturalHeight });
251
287
  }
252
288
  // ---- the divider ----
253
289
  setPosition(p, commit) {
@@ -353,8 +389,8 @@ class BkImageCompare extends LitElement {
353
389
  const pct = Math.round(this.position);
354
390
  const percent = new Intl.NumberFormat(this.i18n.locale, { style: "percent", maximumFractionDigits: 0 }).format(pct / 100);
355
391
  const slider = mode === "slider" ? html`
356
- ${content ? nothing : html`<div class="tags before"><span class="tag" part="tag">${this.labelOf("before")}</span></div>
357
- <div class="tags after"><span class="tag" part="tag">${this.labelOf("after")}</span></div>`}
392
+ ${content ? nothing : html`<div class="tags before"><span class="tag" part="tag label">${this.labelOf("before")}</span></div>
393
+ <div class="tags after"><span class="tag" part="tag label">${this.labelOf("after")}</span></div>`}
358
394
  <div class="divider" part="divider" role="slider" tabindex="0"
359
395
  aria-label=${this.i18n.t("compareDivider", { before: this.labelOf("before"), after: this.labelOf("after") })}
360
396
  aria-orientation="horizontal" aria-valuemin="0" aria-valuemax="100" aria-valuenow=${pct}
@@ -372,7 +408,7 @@ class BkImageCompare extends LitElement {
372
408
  </bk-zoom></span>` : nothing;
373
409
  return html`<div class="compare">
374
410
  <div class="view ${mode} ${content ? "has-content" : ""} ${zoomable ? "zoomable" : ""} ${zoomed ? "zoomed" : ""}" part="view"
375
- style=${styleMap({ "--_bk-image-compare-ratio": this.ratio || void 0, "--_bk-image-compare-pos": `${this.position}%` })}
411
+ style=${styleMap({ "--_bk-image-compare-pos": `${this.position}%` })}
376
412
  tabindex=${ifDefined(zoomable ? "0" : void 0)} role=${ifDefined(zoomable ? "group" : void 0)}
377
413
  aria-label=${ifDefined(zoomable ? this.label || this.i18n.t("imageCompare") : void 0)}
378
414
  aria-describedby=${ifDefined(zoomable ? "zoom-help" : void 0)}
@@ -385,13 +421,13 @@ class BkImageCompare extends LitElement {
385
421
  </div>
386
422
  ${zoomable ? html`<span class="sr-only" id="zoom-help">${this.i18n.t("compareZoomHelp")}</span>` : nothing}
387
423
  ${mode === "side" ? html`<div class="captions">
388
- <span class="caption" part="caption" aria-hidden="true">${this.labelOf("before")}</span>
389
- <span class="caption" part="caption" aria-hidden="true">${this.labelOf("after")}</span>
424
+ <span class="caption" part="caption label" aria-hidden="true">${this.labelOf("before")}</span>
425
+ <span class="caption" part="caption label" aria-hidden="true">${this.labelOf("after")}</span>
390
426
  </div>` : nothing}
391
427
  ${mode === "toggle" ? html`<bk-segmented class="switch" part="switch" size="sm" aria-label=${this.i18n.t("compareShow")}
392
428
  .value=${shown} @input=${this.onShow} @change=${this.onShow}>
393
- <bk-segmented-item value="before">${this.labelOf("before")}</bk-segmented-item>
394
- <bk-segmented-item value="after">${this.labelOf("after")}</bk-segmented-item>
429
+ <bk-segmented-item part="label" value="before">${this.labelOf("before")}</bk-segmented-item>
430
+ <bk-segmented-item part="label" value="after">${this.labelOf("after")}</bk-segmented-item>
395
431
  </bk-segmented>` : nothing}
396
432
  </div>`;
397
433
  }
@@ -34,6 +34,10 @@ export interface ImageViewerChangeDetail {
34
34
  /** Index of the image now shown. */
35
35
  index: number;
36
36
  }
37
+ /** Detail of the `page` event: the picture that the user asks for in the list of the app. */
38
+ export interface ImageViewerPageDetail {
39
+ direction: "previous" | "next";
40
+ }
37
41
  /**
38
42
  * The zoom and the visible part of the image: `zoom` is a factor of the fitted size (1 shows the whole image).
39
43
  * `x` and `y` are the point in the centre of the view, as fractions of the width and the height of the image.
@@ -71,6 +75,26 @@ export interface ImageViewerView {
71
75
  * left or right switches images. The full image loads only when it is shown. The viewer preloads the neighbouring images.
72
76
  * Previous and next stop at the first and the last image. With `loop` they wrap around.
73
77
  *
78
+ * **Paging.** While the next image loads, the last image stays in view, so paging through large images shows no empty
79
+ * frame. If the load takes longer than `--bk-loading-delay`, a spinner shows over the last image. The thumbnail of
80
+ * `src` shows only when there is no last image.
81
+ *
82
+ * **The shape of the image.** With `shaped` the box of the viewer takes the shape of the image. The width follows the
83
+ * ratio of the image under the cap `--bk-image-viewer-max-height`. The box is never wider than its container and never
84
+ * larger than the natural size of the image (`width` of the item, else the loaded image). The toolbar lies over the top
85
+ * of the image, and the caption and the filmstrip stay under it. Give the viewer no height. A 400 × 1200 image in a
86
+ * 1200 px container with a cap of 600 px gives a box of 200 × 600 px.
87
+ *
88
+ * **The list of the app.** Set `pageable` when the app shows one picture and has the list itself. The previous and
89
+ * next buttons then show also for one item, and the viewer fires `page` when the user asks for the previous or next
90
+ * picture: with the buttons, the arrow keys or a swipe. The app then sets `items` to the other picture. Set `first`
91
+ * and `last` at the ends of the list: they turn off the previous or the next button. With several items, the viewer
92
+ * pages its own items first and fires `page` at their ends (not with `loop`).
93
+ *
94
+ * ```js
95
+ * viewer.addEventListener("page", (e) => show(position + (e.detail.direction === "next" ? 1 : -1)));
96
+ * ```
97
+ *
74
98
  * **Immersive.** Set `immersive` when the viewer is the main content of the screen or of a dialog
75
99
  * (`<bk-lightbox>` sets it). Then the plain wheel always zooms, because there is no page to scroll. A click
76
100
  * (mouse or pen) steps the zoom at the pointer: 2×, 4×, then back to the fitted size. A double tap stays the zoom
@@ -111,7 +135,7 @@ export interface ImageViewerView {
111
135
  * @csspart caption - The caption under the image.
112
136
  * @csspart filmstrip - The row of thumbnails (with `filmstrip`).
113
137
  * @csspart thumb - One filmstrip button.
114
- * @cssprop --bk-image-viewer-max-height - Maximum height of the viewer, for a viewer without a height that takes the shape of the image (default none).
138
+ * @cssprop --bk-image-viewer-max-height - Maximum height of the viewer, for a viewer without a height that takes the shape of the image (default none). With `shaped` it is the maximum height of the image: a length, and the width follows.
115
139
  * @cssprop --bk-image-viewer-color-scheme - Colour scheme inside; global tokens resolve in it (default dark).
116
140
  * @cssprop --bk-image-viewer-bg - Background (default --bk-media-backdrop).
117
141
  * @cssprop --bk-image-viewer-fg - Text and icon colour (default --bk-on-media).
@@ -133,16 +157,17 @@ export interface ImageViewerView {
133
157
  * @fires {CustomEvent<ImageViewerChangeDetail>} change - The user moved to another image. `event.detail.index` is the new index. The event bubbles and is composed.
134
158
  * @fires {Event} dismiss - A single tap or click beside the (unzoomed) image. `<bk-lightbox>` closes on this event. The event bubbles and is composed.
135
159
  * @fires {CustomEvent<ImageViewerView>} viewchange - The user changed the zoom or the visible part (at most once per frame). `event.detail` is the new `view`. Setting `view`, `resetZoom()`, `actualSize()` and a change of the image fire no event. The event bubbles and is composed.
160
+ * @fires {CustomEvent<ImageViewerPageDetail>} page - With `pageable`: the user asks for the previous or the next picture of the list of the app (a button, ← →, a swipe), and the viewer has no own item in that direction. `event.detail.direction` is `previous` or `next`. The app sets `items` to that picture. The event bubbles, is composed and is cancelable, as every event that navigates: `defaultPrevented` tells a later listener that a handler took the request. The viewer itself has no default action.
136
161
  * @fires {Event} load - The shown image has loaded (once for each image, also from the cache of the browser). `naturalWidth` and `naturalHeight` are known. The event does not bubble, as the `load` of an `<img>`.
137
162
  *
138
163
  * @tag bk-image-viewer
139
- * @keyboard ←, → - The previous or next image (they stop at the ends without `loop`). In a zoomed image: pan.
164
+ * @keyboard ←, → - The previous or next image (they stop at the ends without `loop`; with `pageable` they fire `page`). In a zoomed image: pan.
140
165
  * @keyboard ↑, ↓ - In a zoomed image: pan.
141
166
  * @keyboard Home, End - The first or last image.
142
167
  * @keyboard Plus, Minus - Zoom in or out.
143
168
  * @keyboard 0 - Fit the image to the view.
144
169
  * @keyboard 1 - Show the image at its actual size.
145
- * @a11y The viewer is a focusable `region` with a name (`label`, otherwise the text of the library). A polite live region announces the position ("2 of 5"). Every pointer gesture has a button and a key. Without `loop`, the previous button is off on the first image and the next button on the last; the region gets the focus of an off button. With `immersive` the keys also work from the other controls of the surrounding dialog, except from fields and widgets that use the key.
170
+ * @a11y The viewer is a focusable `region` with a name (`label`, otherwise the text of the library). A polite live region announces the position ("2 of 5"). Every pointer gesture has a button and a key. Without `loop`, the previous button is off on the first image and the next button on the last (with `pageable`: with `first` and `last`); the region gets the focus of an off button. With `immersive` the keys also work from the other controls of the surrounding dialog, except from fields and widgets that use the key.
146
171
  */
147
172
  export declare class BkImageViewer extends LitElement {
148
173
  static shadowRootOptions: ShadowRootInit;
@@ -165,6 +190,22 @@ export declare class BkImageViewer extends LitElement {
165
190
  type: BooleanConstructor;
166
191
  reflect: boolean;
167
192
  };
193
+ shaped: {
194
+ type: BooleanConstructor;
195
+ reflect: boolean;
196
+ };
197
+ pageable: {
198
+ type: BooleanConstructor;
199
+ reflect: boolean;
200
+ };
201
+ first: {
202
+ type: BooleanConstructor;
203
+ reflect: boolean;
204
+ };
205
+ last: {
206
+ type: BooleanConstructor;
207
+ reflect: boolean;
208
+ };
168
209
  label: {};
169
210
  prevLabel: {
170
211
  attribute: string;
@@ -205,6 +246,9 @@ export declare class BkImageViewer extends LitElement {
205
246
  thumbRatio: {
206
247
  state: boolean;
207
248
  };
249
+ naturalSize: {
250
+ state: boolean;
251
+ };
208
252
  };
209
253
  /** The images. */
210
254
  items: ImageViewerItem[];
@@ -219,6 +263,20 @@ export declare class BkImageViewer extends LitElement {
219
263
  * a click steps the zoom, and the keys of the viewer work while the focus is anywhere in the surrounding dialog.
220
264
  */
221
265
  immersive: boolean;
266
+ /**
267
+ * The box takes the shape of the image: under `--bk-image-viewer-max-height` the width follows the ratio of the image.
268
+ * The box is never wider than its container and never larger than the natural size of the image.
269
+ */
270
+ shaped: boolean;
271
+ /**
272
+ * The app has the list of pictures. The previous and next buttons show also for one item, and the viewer fires `page`
273
+ * when the user asks for a picture beyond its own items.
274
+ */
275
+ pageable: boolean;
276
+ /** With `pageable`: the shown picture is the first of the list of the app. The previous button is off. */
277
+ first: boolean;
278
+ /** With `pageable`: the shown picture is the last of the list of the app. The next button is off. */
279
+ last: boolean;
222
280
  /** Accessible name of the viewer region (default: i18n `imageViewer`). */
223
281
  label: string;
224
282
  /** Accessible name of the previous button (default from i18n). */
@@ -244,6 +302,8 @@ export declare class BkImageViewer extends LitElement {
244
302
  private ratio;
245
303
  /** Aspect ratio of the thumbnail. It gives the height of the viewer until the shape of the full image is known. */
246
304
  private thumbRatio;
305
+ /** Width of the full image in image pixels (`width` of the item, else the loaded image). It is 0 while unknown. */
306
+ private naturalSize;
247
307
  private pz;
248
308
  /** While true, a change of the view is not a change of the user: no `viewchange`. */
249
309
  private quiet;
@@ -270,6 +330,10 @@ export declare class BkImageViewer extends LitElement {
270
330
  private lastTap;
271
331
  private preloaded;
272
332
  private observed;
333
+ /** The picture in the frame, and the last picture while it loads. */
334
+ private shot;
335
+ private previousShot;
336
+ private loader;
273
337
  private resizer;
274
338
  private i18n;
275
339
  constructor();
@@ -325,6 +389,13 @@ export declare class BkImageViewer extends LitElement {
325
389
  private preloadNeighbours;
326
390
  /** Moves to image `i`. It wraps around with `loop`, else it stops at the ends. Returns false when the image stays. */
327
391
  private go;
392
+ /**
393
+ * Where a step in direction `dir` goes: `own` to an item of the viewer, `app` to the list of the app (`pageable`),
394
+ * false when there is nothing in that direction.
395
+ */
396
+ private canStep;
397
+ /** The previous (-1) or next (1) picture: an item of the viewer, else a `page` event for the list of the app. */
398
+ private step;
328
399
  /** How far a key or a pan button moves the image, in px. */
329
400
  private get panStep();
330
401
  private onKey;
@@ -1,6 +1,6 @@
1
1
  import { LitElement, css, html, isServer, nothing } from "lit";
2
- import { styleMap } from "../internal/style-map.js";
3
- import { keyed } from "lit/directives/keyed.js";
2
+ import { repeat } from "lit/directives/repeat.js";
3
+ import { ifDefined } from "lit/directives/if-defined.js";
4
4
  import { define } from "../internal/define.js";
5
5
  import { LocalizeController } from "../i18n.js";
6
6
  import { emit, emitDetail } from "../internal/events.js";
@@ -9,6 +9,8 @@ import "./bk-icon.js";
9
9
  import "./bk-button.js";
10
10
  import "./bk-spinner.js";
11
11
  import { revealInside } from "../internal/scroll.js";
12
+ import { LoadingController } from "../internal/loading.js";
13
+ import { setHostVars } from "../internal/host-vars.js";
12
14
  import { resizeObserver } from "../internal/server.js";
13
15
  import { PanZoom, capture } from "../internal/pan-zoom.js";
14
16
  import "../icons/set/actual-size.js";
@@ -40,6 +42,10 @@ class BkImageViewer extends LitElement {
40
42
  filmstrip: { type: Boolean, reflect: true },
41
43
  loop: { type: Boolean, reflect: true },
42
44
  immersive: { type: Boolean, reflect: true },
45
+ shaped: { type: Boolean, reflect: true },
46
+ pageable: { type: Boolean, reflect: true },
47
+ first: { type: Boolean, reflect: true },
48
+ last: { type: Boolean, reflect: true },
43
49
  label: {},
44
50
  prevLabel: { attribute: "prev-label" },
45
51
  nextLabel: { attribute: "next-label" },
@@ -53,7 +59,8 @@ class BkImageViewer extends LitElement {
53
59
  failed: { state: true },
54
60
  zoomed: { state: true },
55
61
  ratio: { state: true },
56
- thumbRatio: { state: true }
62
+ thumbRatio: { state: true },
63
+ naturalSize: { state: true }
57
64
  };
58
65
  // Zoom and pan live outside Lit's update cycle: gestures write one transform per frame.
59
66
  pz = new PanZoom(this, {
@@ -88,6 +95,10 @@ class BkImageViewer extends LitElement {
88
95
  lastTap = { t: 0, x: 0, y: 0 };
89
96
  preloaded = /* @__PURE__ */ new Set();
90
97
  observed = null;
98
+ /** The picture in the frame, and the last picture while it loads. */
99
+ shot = null;
100
+ previousShot = null;
101
+ loader = new LoadingController(this);
91
102
  resizer = resizeObserver(() => {
92
103
  this.measure();
93
104
  this.clampPan();
@@ -101,6 +112,10 @@ class BkImageViewer extends LitElement {
101
112
  this.filmstrip = false;
102
113
  this.loop = false;
103
114
  this.immersive = false;
115
+ this.shaped = false;
116
+ this.pageable = false;
117
+ this.first = false;
118
+ this.last = false;
104
119
  this.label = "";
105
120
  this.prevLabel = "";
106
121
  this.nextLabel = "";
@@ -115,6 +130,7 @@ class BkImageViewer extends LitElement {
115
130
  this.zoomed = false;
116
131
  this.ratio = 0;
117
132
  this.thumbRatio = 0;
133
+ this.naturalSize = 0;
118
134
  }
119
135
  static styles = [base, srOnly, css`
120
136
  :host { display: block; height: 100%; min-height: 0; max-block-size: var(--bk-image-viewer-max-height, none); }
@@ -136,6 +152,25 @@ class BkImageViewer extends LitElement {
136
152
  .viewer:focus-visible { outline: var(--bk-focus-ring); outline-offset: var(--bk-focus-offset-inset); }
137
153
  .empty { height: 100%; background: var(--bk-image-viewer-bg, var(--bk-media-backdrop)); }
138
154
 
155
+ /* shaped: the box takes the shape of the image. The width follows the ratio under the cap, never wider than
156
+ the container and never wider than the natural image. The height comes from the ratio. */
157
+ :host([shaped]) {
158
+ height: auto; max-block-size: none;
159
+ inline-size: min(100%, var(--_bk-image-viewer-natural, 100%), calc(var(--bk-image-viewer-max-height, calc(infinity * 1px)) * var(--_bk-image-viewer-ratio, 4 / 3)));
160
+ }
161
+ :host([shaped]) .viewer { height: auto; grid-template-rows: auto auto; container-type: inline-size; }
162
+ :host([shaped]) .empty { height: auto; aspect-ratio: 4 / 3; }
163
+ :host([shaped]) .main { aspect-ratio: var(--_bk-image-viewer-ratio, 4 / 3); }
164
+ :host([shaped]) .sizer { display: none; }
165
+ :host([shaped]) .frame { inset: 0; }
166
+ /* The toolbar lies over the top of the image. Only its controls take the pointer. */
167
+ :host([shaped]) .bar { position: absolute; z-index: 4; inset-block-start: 0; inset-inline: 0; pointer-events: none; }
168
+ :host([shaped]) :is(.tools, .actions) { pointer-events: auto; }
169
+ :host([shaped]) .counter:not(:empty) {
170
+ display: inline-flex; align-items: center; min-block-size: var(--_bk-image-viewer-control);
171
+ border-radius: var(--_bk-image-viewer-control-radius); background: var(--_bk-image-viewer-control-bg); backdrop-filter: var(--bk-glass);
172
+ }
173
+
139
174
  .control {
140
175
  --bk-button-ghost-bg: var(--_bk-image-viewer-control-bg);
141
176
  --bk-button-neutral-text: var(--bk-image-viewer-control-fg, var(--_bk-image-viewer-fg));
@@ -197,13 +232,17 @@ class BkImageViewer extends LitElement {
197
232
  width: min(100cqw, 100cqh * var(--_bk-image-viewer-ratio)); height: min(100cqh, 100cqw / var(--_bk-image-viewer-ratio));
198
233
  }
199
234
  .image.loaded ~ .placeholder { visibility: hidden; transition: visibility 0s var(--bk-duration); }
235
+ /* The last image stays in view while the next one loads; the next one fades in over it. */
236
+ .previous { z-index: 0; }
237
+ .previous.gone { visibility: hidden; transition: visibility 0s var(--bk-duration); }
238
+ .frame.swap .placeholder { visibility: hidden; }
239
+ /* The LoadingController shows it only if loading takes longer than --bk-loading-delay. */
200
240
  .spinner {
201
241
  position: absolute; inset: 0; margin: auto; z-index: 2; width: fit-content; height: fit-content; display: flex;
202
242
  padding: var(--bk-space-2); border-radius: var(--bk-radius-full); background: var(--_bk-image-viewer-control-bg); color: var(--_bk-image-viewer-fg);
203
- /* Appears only if loading takes a moment, so cached images don't flash it. */
204
- opacity: 0; animation: bk-image-viewer-appear var(--bk-duration) var(--bk-ease) 250ms forwards;
243
+ animation: bk-image-viewer-appear var(--bk-duration) var(--bk-ease);
205
244
  }
206
- @keyframes bk-image-viewer-appear { to { opacity: 1; } }
245
+ @keyframes bk-image-viewer-appear { from { opacity: 0; } }
207
246
  .error {
208
247
  position: absolute; inset: 0; margin: auto; z-index: 2; width: fit-content; height: fit-content;
209
248
  display: flex; align-items: center; gap: var(--bk-space-2); font-size: var(--bk-type-body);
@@ -256,7 +295,11 @@ class BkImageViewer extends LitElement {
256
295
  @media (max-width: 480px) {
257
296
  .level, .fit, .actual { display: none; }
258
297
  }
259
- @media (prefers-reduced-motion: reduce) { .frame.animate, .image { transition: none; } }
298
+ /* A shaped box can be narrow on a wide screen: its own width counts. */
299
+ @container (max-width: 480px) {
300
+ :host([shaped]) :is(.level, .fit, .actual) { display: none; }
301
+ }
302
+ @media (prefers-reduced-motion: reduce) { .frame.animate, .image, .previous.gone { transition: none; } .spinner { animation: none; } }
260
303
  @media (forced-colors: active) {
261
304
  .viewer { background: Canvas; color: CanvasText; }
262
305
  .spinner { background: Canvas; }
@@ -353,17 +396,30 @@ class BkImageViewer extends LitElement {
353
396
  const n = this.items.length;
354
397
  this.index = clamp(Math.trunc(this.index) || 0, 0, Math.max(0, n - 1));
355
398
  const active = this.hasUpdated && this.renderRoot instanceof ShadowRoot ? this.renderRoot.activeElement : null;
356
- if (active && !this.loop && (active.matches(".prev") && this.index <= 0 || active.matches(".next") && this.index >= n - 1))
399
+ if (active && (active.matches(".prev") && !this.canStep(-1) || active.matches(".next") && !this.canStep(1)))
357
400
  this.focus();
358
401
  if (changed.has("index") || changed.has("items")) {
402
+ const item = this.items[this.index];
403
+ const shot = item ? { key: `${this.index}|${item.full || item.src}`, src: item.full || item.src, thumb: item.src, alt: item.alt } : null;
404
+ if (!shot)
405
+ this.previousShot = null;
406
+ else if (this.shot && this.shot.key !== shot.key) {
407
+ if (this.failed)
408
+ this.previousShot = null;
409
+ else if (!this.loading)
410
+ this.previousShot = this.shot;
411
+ }
412
+ if (this.previousShot?.key === shot?.key)
413
+ this.previousShot = null;
414
+ this.shot = shot;
359
415
  this.loading = n > 0;
360
416
  this.failed = false;
361
417
  this.swipeX = 0;
362
418
  this.silently(() => this.pz.set({ zoom: 1, x: 0.5, y: 0.5 }));
363
419
  this.zoomed = false;
364
420
  this.natural = { w: 0, h: 0 };
365
- const item = this.items[this.index];
366
421
  this.ratio = item?.width && item.height ? item.width / item.height : 0;
422
+ this.naturalSize = item?.width && item.height ? item.width : 0;
367
423
  this.thumbRatio = 0;
368
424
  if (item && !isServer) {
369
425
  const probe = new Image();
@@ -371,9 +427,15 @@ class BkImageViewer extends LitElement {
371
427
  if (probe.complete && probe.naturalWidth && probe.naturalHeight) {
372
428
  this.loading = false;
373
429
  this.ratio = probe.naturalWidth / probe.naturalHeight;
430
+ this.naturalSize = probe.naturalWidth;
374
431
  }
375
432
  }
376
433
  }
434
+ this.loader.set(this.loading);
435
+ setHostVars(this, {
436
+ "--_bk-image-viewer-ratio": String(this.ratio || this.thumbRatio || ""),
437
+ "--_bk-image-viewer-natural": this.naturalSize && this.ratio ? `${this.naturalSize}px` : ""
438
+ });
377
439
  }
378
440
  updated(changed) {
379
441
  const frame = this.frame;
@@ -478,6 +540,7 @@ class BkImageViewer extends LitElement {
478
540
  return;
479
541
  if (img.naturalWidth && img.naturalHeight) {
480
542
  this.ratio = img.naturalWidth / img.naturalHeight;
543
+ this.naturalSize = img.naturalWidth;
481
544
  this.measure();
482
545
  this.apply(false);
483
546
  this.applyPendingView();
@@ -517,6 +580,27 @@ class BkImageViewer extends LitElement {
517
580
  emitDetail(this, "change", { index: next });
518
581
  return true;
519
582
  }
583
+ /**
584
+ * Where a step in direction `dir` goes: `own` to an item of the viewer, `app` to the list of the app (`pageable`),
585
+ * false when there is nothing in that direction.
586
+ */
587
+ canStep(dir) {
588
+ const n = this.items.length;
589
+ if (n > 1 && (this.loop || (dir < 0 ? this.index > 0 : this.index < n - 1)))
590
+ return "own";
591
+ if (this.pageable && !(dir < 0 ? this.first : this.last))
592
+ return "app";
593
+ return false;
594
+ }
595
+ /** The previous (-1) or next (1) picture: an item of the viewer, else a `page` event for the list of the app. */
596
+ step(dir) {
597
+ const to = this.canStep(dir);
598
+ if (to === "own")
599
+ this.go(this.index + dir);
600
+ else if (to === "app")
601
+ emitDetail(this, "page", { direction: dir < 0 ? "previous" : "next" }, true);
602
+ return to;
603
+ }
520
604
  /** How far a key or a pan button moves the image, in px. */
521
605
  get panStep() {
522
606
  return Math.max(40, this.box.w * 0.1);
@@ -530,7 +614,7 @@ class BkImageViewer extends LitElement {
530
614
  ArrowRight: () => this.panBy(-pan, 0),
531
615
  ArrowUp: () => this.panBy(0, pan),
532
616
  ArrowDown: () => this.panBy(0, -pan)
533
- } : { ArrowLeft: () => this.go(this.index - 1), ArrowRight: () => this.go(this.index + 1) };
617
+ } : { ArrowLeft: () => this.step(-1), ArrowRight: () => this.step(1) };
534
618
  Object.assign(keys, {
535
619
  Home: () => this.go(0),
536
620
  End: () => this.go(this.items.length - 1),
@@ -674,7 +758,7 @@ class BkImageViewer extends LitElement {
674
758
  if (this.zoomed) {
675
759
  const z = this.pz.zoom;
676
760
  this.pz.set({ x: this.drag.vx - dx / (this.box.w * z), y: this.drag.vy - dy / (this.box.h * z) });
677
- } else if (this.items.length > 1) {
761
+ } else if (this.items.length > 1 || this.pageable) {
678
762
  this.swipeX = dx;
679
763
  }
680
764
  this.apply(false);
@@ -693,7 +777,7 @@ class BkImageViewer extends LitElement {
693
777
  const dx = this.swipeX;
694
778
  if (dx) {
695
779
  this.swipeX = 0;
696
- if (e.type === "pointercancel" || Math.abs(dx) <= SWIPE_DISTANCE || !this.go(this.index + (dx < 0 ? 1 : -1)))
780
+ if (e.type === "pointercancel" || Math.abs(dx) <= SWIPE_DISTANCE || this.step(dx < 0 ? 1 : -1) !== "own")
697
781
  this.apply(true);
698
782
  return;
699
783
  }
@@ -737,8 +821,10 @@ class BkImageViewer extends LitElement {
737
821
  return;
738
822
  this.loading = false;
739
823
  const img = this.image;
740
- if (img?.naturalWidth && img.naturalHeight)
824
+ if (img?.naturalWidth && img.naturalHeight) {
741
825
  this.ratio = img.naturalWidth / img.naturalHeight;
826
+ this.naturalSize = img.naturalWidth;
827
+ }
742
828
  this.placeImage();
743
829
  }
744
830
  /** Fits the loaded image into the frame. It does not change reactive state. */
@@ -773,15 +859,14 @@ class BkImageViewer extends LitElement {
773
859
  renderViewer(item) {
774
860
  const n = this.items.length;
775
861
  const many = n > 1;
776
- const full = item.full || item.src;
777
862
  const strip = this.filmstrip && many;
778
- const atStart = !this.loop && this.index <= 0;
779
- const atEnd = !this.loop && this.index >= n - 1;
863
+ const shot = this.shot ?? { key: `${this.index}|${item.full || item.src}`, src: item.full || item.src, thumb: item.src, alt: item.alt };
864
+ const shots = this.previousShot ? [this.previousShot, shot] : [shot];
865
+ const swap = !!this.previousShot && this.loading;
780
866
  return html`<div class="viewer" part="base" role="region" tabindex="0"
781
- style=${styleMap({ "--_bk-image-viewer-ratio": this.ratio || this.thumbRatio || void 0 })}
782
867
  aria-label=${this.label || this.i18n.t("imageViewer")} @keydown=${this.onKey}>
783
868
  <div class="bar" part="toolbar">
784
- <span class="counter" part="counter" aria-live="polite" aria-atomic="true">${many ? html`<span aria-hidden="true">${this.index + 1} / ${n}</span><span class="sr-only">${this.i18n.t("imageCounter", { index: this.index + 1, total: n })}</span>` : ""}</span>
869
+ <span class="counter" part="counter" aria-live="polite" aria-atomic="true">${many ? html`<span aria-hidden="true">${this.index + 1} / ${n}</span><span class="sr-only">${this.i18n.t("imageCounter", { index: this.index + 1, total: n })}</span>` : nothing}</span>
785
870
  <span class="tools">
786
871
  <bk-button variant="ghost" class="control" size="lg" label=${this.zoomOutLabel || this.i18n.t("zoomOut")} icon="zoom-out" @click=${() => this.zoomTo(this.pz.zoom / ZOOM_STEP)}></bk-button>
787
872
  <output class="level" part="zoom-level" aria-live="off" aria-label=${this.i18n.t("zoomLevel")}></output>
@@ -796,13 +881,15 @@ class BkImageViewer extends LitElement {
796
881
  <div class="stage ${this.zoomed ? "zoomed" : ""} ${this.immersive ? "steps" : ""}" part="stage" @wheel=${this.onWheel}
797
882
  @pointerdown=${this.onPointerDown} @pointermove=${this.onPointerMove}
798
883
  @pointerup=${this.onPointerUp} @pointercancel=${this.onPointerUp}>
799
- <div class="frame">${keyed(`${this.index}|${full}`, html`
800
- <img class="image ${this.loading ? "" : "loaded"} ${this.failed ? "failed" : ""}" part="image" src=${full} alt=${item.alt} decoding="async"
801
- draggable="false" @load=${this.onImageLoad} @error=${this.onImageError}>
802
- ${full !== item.src ? html`<img class="placeholder ${this.ratio ? "shaped" : ""}"
803
- src=${item.src} alt="" aria-hidden="true" decoding="async" draggable="false" @load=${this.onThumbLoad}>` : nothing}`)}
804
- </div>
805
- ${this.loading ? html`<span class="spinner"><bk-spinner size="lg"></bk-spinner></span>` : nothing}
884
+ <div class="frame ${swap ? "swap" : ""}">${repeat(shots, (s) => s.key, (s) => {
885
+ const shown = s === shot;
886
+ const classes = shown ? `image ${this.loading ? "" : "loaded"} ${this.failed ? "failed" : ""}` : `previous ${swap ? "" : "gone"}`;
887
+ return html`<img class=${classes}
888
+ part=${ifDefined(shown ? "image" : void 0)} src=${s.src} alt=${shown ? s.alt : ""} aria-hidden=${ifDefined(shown ? void 0 : "true")}
889
+ decoding="async" draggable="false" @load=${this.onImageLoad} @error=${this.onImageError}>${shown && s.src !== s.thumb ? html`<img
890
+ class="placeholder ${this.ratio ? "shaped" : ""}" src=${s.thumb} alt="" aria-hidden="true" decoding="async" draggable="false" @load=${this.onThumbLoad}>` : nothing}`;
891
+ })}</div>
892
+ ${this.loader.visible ? html`<span class="spinner"><bk-spinner size="lg"></bk-spinner></span>` : nothing}
806
893
  ${this.failed ? html`<p class="error" role="alert"><bk-icon name="error" size="md"></bk-icon>${this.errorLabel || this.i18n.t("imageError")}</p>` : nothing}
807
894
  </div>
808
895
  <span class="pan" part="pan" role="group" aria-label=${this.panLabel || this.i18n.t("panGroup")} ?hidden=${!this.zoomed}>
@@ -811,9 +898,9 @@ class BkImageViewer extends LitElement {
811
898
  <bk-button variant="ghost" class="control" size="sm" icon="chevron-down" label=${this.i18n.t("panDown")} @click=${() => this.panBy(0, -this.panStep)}></bk-button>
812
899
  <bk-button variant="ghost" class="control" size="sm" icon="chevron-right" label=${this.i18n.t("panRight")} @click=${() => this.panBy(-this.panStep, 0)}></bk-button>
813
900
  </span>
814
- ${many ? html`
815
- <bk-button variant="ghost" class="control nav prev" part="nav" size="lg" icon="chevron-left" label=${this.prevLabel || this.i18n.t("previousImage")} ?disabled=${atStart} @click=${() => this.go(this.index - 1)}></bk-button>
816
- <bk-button variant="ghost" class="control nav next" part="nav" size="lg" icon="chevron-right" label=${this.nextLabel || this.i18n.t("nextImage")} ?disabled=${atEnd} @click=${() => this.go(this.index + 1)}></bk-button>` : nothing}
901
+ ${many || this.pageable ? html`
902
+ <bk-button variant="ghost" class="control nav prev" part="nav" size="lg" icon="chevron-left" label=${this.prevLabel || this.i18n.t("previousImage")} ?disabled=${!this.canStep(-1)} @click=${() => this.step(-1)}></bk-button>
903
+ <bk-button variant="ghost" class="control nav next" part="nav" size="lg" icon="chevron-right" label=${this.nextLabel || this.i18n.t("nextImage")} ?disabled=${!this.canStep(1)} @click=${() => this.step(1)}></bk-button>` : nothing}
817
904
  </div>
818
905
  <div class="foot" ?hidden=${!item.caption && !strip}>
819
906
  ${item.caption ? html`<p class="caption" part="caption">${item.caption}</p>` : nothing}