@kujoforall/paper-ui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +252 -2
  4. package/dist/components/editor/block-text.d.ts +8 -0
  5. package/dist/components/editor/block-text.d.ts.map +1 -0
  6. package/dist/components/editor/block-text.js +213 -0
  7. package/dist/components/editor/block-text.js.map +1 -0
  8. package/dist/components/editor/blocks.d.ts +33 -0
  9. package/dist/components/editor/blocks.d.ts.map +1 -0
  10. package/dist/components/editor/blocks.js +187 -0
  11. package/dist/components/editor/blocks.js.map +1 -0
  12. package/dist/components/editor/document-editor.d.ts +27 -0
  13. package/dist/components/editor/document-editor.d.ts.map +1 -0
  14. package/dist/components/editor/document-editor.js +40 -0
  15. package/dist/components/editor/document-editor.js.map +1 -0
  16. package/dist/components/editor/document-view.d.ts +22 -0
  17. package/dist/components/editor/document-view.d.ts.map +1 -0
  18. package/dist/components/editor/document-view.js +105 -0
  19. package/dist/components/editor/document-view.js.map +1 -0
  20. package/dist/components/editor/editor-state.d.ts +100 -0
  21. package/dist/components/editor/editor-state.d.ts.map +1 -0
  22. package/dist/components/editor/editor-state.js +192 -0
  23. package/dist/components/editor/editor-state.js.map +1 -0
  24. package/dist/components/editor/extensions/spoiler.d.ts +8 -0
  25. package/dist/components/editor/extensions/spoiler.d.ts.map +1 -0
  26. package/dist/components/editor/extensions/spoiler.js +36 -0
  27. package/dist/components/editor/extensions/spoiler.js.map +1 -0
  28. package/dist/components/editor/index.d.ts +9 -0
  29. package/dist/components/editor/index.d.ts.map +1 -0
  30. package/dist/components/editor/index.js +9 -0
  31. package/dist/components/editor/index.js.map +1 -0
  32. package/dist/components/editor/kinds.d.ts +99 -0
  33. package/dist/components/editor/kinds.d.ts.map +1 -0
  34. package/dist/components/editor/kinds.js +74 -0
  35. package/dist/components/editor/kinds.js.map +1 -0
  36. package/dist/components/sketch/rough.d.ts +38 -0
  37. package/dist/components/sketch/rough.d.ts.map +1 -0
  38. package/dist/components/sketch/rough.js +57 -0
  39. package/dist/components/sketch/rough.js.map +1 -0
  40. package/dist/components/ui/accent-picker.d.ts +2 -0
  41. package/dist/components/ui/accent-picker.d.ts.map +1 -0
  42. package/dist/components/ui/accent-picker.js +44 -0
  43. package/dist/components/ui/accent-picker.js.map +1 -0
  44. package/dist/components/ui/address-field.d.ts +10 -0
  45. package/dist/components/ui/address-field.d.ts.map +1 -0
  46. package/dist/components/ui/address-field.js +24 -0
  47. package/dist/components/ui/address-field.js.map +1 -0
  48. package/dist/components/ui/app-shell.d.ts +25 -0
  49. package/dist/components/ui/app-shell.d.ts.map +1 -0
  50. package/dist/components/ui/app-shell.js +69 -0
  51. package/dist/components/ui/app-shell.js.map +1 -0
  52. package/dist/components/ui/badge.d.ts +19 -0
  53. package/dist/components/ui/badge.d.ts.map +1 -0
  54. package/dist/components/ui/badge.js +62 -0
  55. package/dist/components/ui/badge.js.map +1 -0
  56. package/dist/components/ui/breadcrumbs.d.ts +10 -0
  57. package/dist/components/ui/breadcrumbs.d.ts.map +1 -0
  58. package/dist/components/ui/breadcrumbs.js +9 -0
  59. package/dist/components/ui/breadcrumbs.js.map +1 -0
  60. package/dist/components/ui/button.d.ts +13 -0
  61. package/dist/components/ui/button.d.ts.map +1 -0
  62. package/dist/components/ui/button.js +45 -0
  63. package/dist/components/ui/button.js.map +1 -0
  64. package/dist/components/ui/calendar.d.ts +5 -0
  65. package/dist/components/ui/calendar.d.ts.map +1 -0
  66. package/dist/components/ui/calendar.js +64 -0
  67. package/dist/components/ui/calendar.js.map +1 -0
  68. package/dist/components/ui/callout.d.ts +13 -0
  69. package/dist/components/ui/callout.d.ts.map +1 -0
  70. package/dist/components/ui/callout.js +27 -0
  71. package/dist/components/ui/callout.js.map +1 -0
  72. package/dist/components/ui/card.d.ts +13 -0
  73. package/dist/components/ui/card.d.ts.map +1 -0
  74. package/dist/components/ui/card.js +27 -0
  75. package/dist/components/ui/card.js.map +1 -0
  76. package/dist/components/ui/checkbox.d.ts +6 -0
  77. package/dist/components/ui/checkbox.d.ts.map +1 -0
  78. package/dist/components/ui/checkbox.js +10 -0
  79. package/dist/components/ui/checkbox.js.map +1 -0
  80. package/dist/components/ui/command-menu.d.ts +15 -0
  81. package/dist/components/ui/command-menu.d.ts.map +1 -0
  82. package/dist/components/ui/command-menu.js +24 -0
  83. package/dist/components/ui/command-menu.js.map +1 -0
  84. package/dist/components/ui/date-picker.d.ts +35 -0
  85. package/dist/components/ui/date-picker.d.ts.map +1 -0
  86. package/dist/components/ui/date-picker.js +56 -0
  87. package/dist/components/ui/date-picker.js.map +1 -0
  88. package/dist/components/ui/date-time-picker.d.ts +19 -0
  89. package/dist/components/ui/date-time-picker.d.ts.map +1 -0
  90. package/dist/components/ui/date-time-picker.js +32 -0
  91. package/dist/components/ui/date-time-picker.js.map +1 -0
  92. package/dist/components/ui/dialog.d.ts +17 -0
  93. package/dist/components/ui/dialog.d.ts.map +1 -0
  94. package/dist/components/ui/dialog.js +33 -0
  95. package/dist/components/ui/dialog.js.map +1 -0
  96. package/dist/components/ui/dropdown-menu.d.ts +20 -0
  97. package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
  98. package/dist/components/ui/dropdown-menu.js +56 -0
  99. package/dist/components/ui/dropdown-menu.js.map +1 -0
  100. package/dist/components/ui/editable-text.d.ts +17 -0
  101. package/dist/components/ui/editable-text.d.ts.map +1 -0
  102. package/dist/components/ui/editable-text.js +68 -0
  103. package/dist/components/ui/editable-text.js.map +1 -0
  104. package/dist/components/ui/field-button.d.ts +14 -0
  105. package/dist/components/ui/field-button.d.ts.map +1 -0
  106. package/dist/components/ui/field-button.js +16 -0
  107. package/dist/components/ui/field-button.js.map +1 -0
  108. package/dist/components/ui/file-preview.d.ts +5 -0
  109. package/dist/components/ui/file-preview.d.ts.map +1 -0
  110. package/dist/components/ui/file-preview.js +66 -0
  111. package/dist/components/ui/file-preview.js.map +1 -0
  112. package/dist/components/ui/file-uploader.d.ts +39 -0
  113. package/dist/components/ui/file-uploader.d.ts.map +1 -0
  114. package/dist/components/ui/file-uploader.js +110 -0
  115. package/dist/components/ui/file-uploader.js.map +1 -0
  116. package/dist/components/ui/handle-row.d.ts +15 -0
  117. package/dist/components/ui/handle-row.d.ts.map +1 -0
  118. package/dist/components/ui/handle-row.js +41 -0
  119. package/dist/components/ui/handle-row.js.map +1 -0
  120. package/dist/components/ui/image-block.d.ts +31 -0
  121. package/dist/components/ui/image-block.d.ts.map +1 -0
  122. package/dist/components/ui/image-block.js +103 -0
  123. package/dist/components/ui/image-block.js.map +1 -0
  124. package/dist/components/ui/image-card.d.ts +17 -0
  125. package/dist/components/ui/image-card.d.ts.map +1 -0
  126. package/dist/components/ui/image-card.js +38 -0
  127. package/dist/components/ui/image-card.js.map +1 -0
  128. package/dist/components/ui/image-viewer.d.ts +31 -0
  129. package/dist/components/ui/image-viewer.d.ts.map +1 -0
  130. package/dist/components/ui/image-viewer.js +81 -0
  131. package/dist/components/ui/image-viewer.js.map +1 -0
  132. package/dist/components/ui/image.d.ts +11 -0
  133. package/dist/components/ui/image.d.ts.map +1 -0
  134. package/dist/components/ui/image.js +32 -0
  135. package/dist/components/ui/image.js.map +1 -0
  136. package/dist/components/ui/index.d.ts +49 -0
  137. package/dist/components/ui/index.d.ts.map +1 -0
  138. package/dist/components/ui/index.js +49 -0
  139. package/dist/components/ui/index.js.map +1 -0
  140. package/dist/components/ui/input.d.ts +16 -0
  141. package/dist/components/ui/input.d.ts.map +1 -0
  142. package/dist/components/ui/input.js +32 -0
  143. package/dist/components/ui/input.js.map +1 -0
  144. package/dist/components/ui/link-block.d.ts +13 -0
  145. package/dist/components/ui/link-block.d.ts.map +1 -0
  146. package/dist/components/ui/link-block.js +21 -0
  147. package/dist/components/ui/link-block.js.map +1 -0
  148. package/dist/components/ui/mac-card.d.ts +15 -0
  149. package/dist/components/ui/mac-card.d.ts.map +1 -0
  150. package/dist/components/ui/mac-card.js +9 -0
  151. package/dist/components/ui/mac-card.js.map +1 -0
  152. package/dist/components/ui/nav-tree.d.ts +16 -0
  153. package/dist/components/ui/nav-tree.d.ts.map +1 -0
  154. package/dist/components/ui/nav-tree.js +34 -0
  155. package/dist/components/ui/nav-tree.js.map +1 -0
  156. package/dist/components/ui/page.d.ts +12 -0
  157. package/dist/components/ui/page.d.ts.map +1 -0
  158. package/dist/components/ui/page.js +15 -0
  159. package/dist/components/ui/page.js.map +1 -0
  160. package/dist/components/ui/popover.d.ts +8 -0
  161. package/dist/components/ui/popover.d.ts.map +1 -0
  162. package/dist/components/ui/popover.js +18 -0
  163. package/dist/components/ui/popover.js.map +1 -0
  164. package/dist/components/ui/progress.d.ts +9 -0
  165. package/dist/components/ui/progress.d.ts.map +1 -0
  166. package/dist/components/ui/progress.js +9 -0
  167. package/dist/components/ui/progress.js.map +1 -0
  168. package/dist/components/ui/property.d.ts +15 -0
  169. package/dist/components/ui/property.d.ts.map +1 -0
  170. package/dist/components/ui/property.js +34 -0
  171. package/dist/components/ui/property.js.map +1 -0
  172. package/dist/components/ui/segmented.d.ts +13 -0
  173. package/dist/components/ui/segmented.d.ts.map +1 -0
  174. package/dist/components/ui/segmented.js +10 -0
  175. package/dist/components/ui/segmented.js.map +1 -0
  176. package/dist/components/ui/select-menu.d.ts +10 -0
  177. package/dist/components/ui/select-menu.d.ts.map +1 -0
  178. package/dist/components/ui/select-menu.js +10 -0
  179. package/dist/components/ui/select-menu.js.map +1 -0
  180. package/dist/components/ui/select.d.ts +11 -0
  181. package/dist/components/ui/select.d.ts.map +1 -0
  182. package/dist/components/ui/select.js +31 -0
  183. package/dist/components/ui/select.js.map +1 -0
  184. package/dist/components/ui/selection-bar.d.ts +12 -0
  185. package/dist/components/ui/selection-bar.d.ts.map +1 -0
  186. package/dist/components/ui/selection-bar.js +15 -0
  187. package/dist/components/ui/selection-bar.js.map +1 -0
  188. package/dist/components/ui/separator.d.ts +4 -0
  189. package/dist/components/ui/separator.d.ts.map +1 -0
  190. package/dist/components/ui/separator.js +12 -0
  191. package/dist/components/ui/separator.js.map +1 -0
  192. package/dist/components/ui/spotlight.d.ts +23 -0
  193. package/dist/components/ui/spotlight.d.ts.map +1 -0
  194. package/dist/components/ui/spotlight.js +107 -0
  195. package/dist/components/ui/spotlight.js.map +1 -0
  196. package/dist/components/ui/stat-tile.d.ts +8 -0
  197. package/dist/components/ui/stat-tile.d.ts.map +1 -0
  198. package/dist/components/ui/stat-tile.js +9 -0
  199. package/dist/components/ui/stat-tile.js.map +1 -0
  200. package/dist/components/ui/step-dialog.d.ts +20 -0
  201. package/dist/components/ui/step-dialog.d.ts.map +1 -0
  202. package/dist/components/ui/step-dialog.js +36 -0
  203. package/dist/components/ui/step-dialog.js.map +1 -0
  204. package/dist/components/ui/table.d.ts +8 -0
  205. package/dist/components/ui/table.d.ts.map +1 -0
  206. package/dist/components/ui/table.js +23 -0
  207. package/dist/components/ui/table.js.map +1 -0
  208. package/dist/components/ui/theme-toggle.d.ts +2 -0
  209. package/dist/components/ui/theme-toggle.d.ts.map +1 -0
  210. package/dist/components/ui/theme-toggle.js +49 -0
  211. package/dist/components/ui/theme-toggle.js.map +1 -0
  212. package/dist/components/ui/time-picker.d.ts +21 -0
  213. package/dist/components/ui/time-picker.d.ts.map +1 -0
  214. package/dist/components/ui/time-picker.js +63 -0
  215. package/dist/components/ui/time-picker.js.map +1 -0
  216. package/dist/components/ui/tooltip.d.ts +15 -0
  217. package/dist/components/ui/tooltip.d.ts.map +1 -0
  218. package/dist/components/ui/tooltip.js +21 -0
  219. package/dist/components/ui/tooltip.js.map +1 -0
  220. package/dist/components/ui/typography.d.ts +34 -0
  221. package/dist/components/ui/typography.d.ts.map +1 -0
  222. package/dist/components/ui/typography.js +72 -0
  223. package/dist/components/ui/typography.js.map +1 -0
  224. package/dist/components/ui/video-block.d.ts +14 -0
  225. package/dist/components/ui/video-block.d.ts.map +1 -0
  226. package/dist/components/ui/video-block.js +18 -0
  227. package/dist/components/ui/video-block.js.map +1 -0
  228. package/dist/hooks/use-save-queue.d.ts +13 -0
  229. package/dist/hooks/use-save-queue.d.ts.map +1 -0
  230. package/dist/hooks/use-save-queue.js +45 -0
  231. package/dist/hooks/use-save-queue.js.map +1 -0
  232. package/dist/hooks/use-selection.d.ts +10 -0
  233. package/dist/hooks/use-selection.d.ts.map +1 -0
  234. package/dist/hooks/use-selection.js +43 -0
  235. package/dist/hooks/use-selection.js.map +1 -0
  236. package/dist/hooks/use-shared-transition.d.ts +3 -0
  237. package/dist/hooks/use-shared-transition.d.ts.map +1 -0
  238. package/dist/hooks/use-shared-transition.js +38 -0
  239. package/dist/hooks/use-shared-transition.js.map +1 -0
  240. package/dist/hooks/use-upload-queue.d.ts +22 -0
  241. package/dist/hooks/use-upload-queue.d.ts.map +1 -0
  242. package/dist/hooks/use-upload-queue.js +78 -0
  243. package/dist/hooks/use-upload-queue.js.map +1 -0
  244. package/dist/lib/accent.d.ts +5 -0
  245. package/dist/lib/accent.d.ts.map +1 -0
  246. package/dist/lib/accent.js +10 -0
  247. package/dist/lib/accent.js.map +1 -0
  248. package/dist/lib/bento.d.ts +17 -0
  249. package/dist/lib/bento.d.ts.map +1 -0
  250. package/dist/lib/bento.js +92 -0
  251. package/dist/lib/bento.js.map +1 -0
  252. package/dist/lib/dates.d.ts +14 -0
  253. package/dist/lib/dates.d.ts.map +1 -0
  254. package/dist/lib/dates.js +34 -0
  255. package/dist/lib/dates.js.map +1 -0
  256. package/dist/lib/document.d.ts +79 -0
  257. package/dist/lib/document.d.ts.map +1 -0
  258. package/dist/lib/document.js +11 -0
  259. package/dist/lib/document.js.map +1 -0
  260. package/dist/lib/embed.d.ts +14 -0
  261. package/dist/lib/embed.d.ts.map +1 -0
  262. package/dist/lib/embed.js +63 -0
  263. package/dist/lib/embed.js.map +1 -0
  264. package/dist/lib/files.d.ts +23 -0
  265. package/dist/lib/files.d.ts.map +1 -0
  266. package/dist/lib/files.js +69 -0
  267. package/dist/lib/files.js.map +1 -0
  268. package/dist/lib/justified.d.ts +50 -0
  269. package/dist/lib/justified.d.ts.map +1 -0
  270. package/dist/lib/justified.js +78 -0
  271. package/dist/lib/justified.js.map +1 -0
  272. package/dist/lib/rich-text-dom.d.ts +14 -0
  273. package/dist/lib/rich-text-dom.d.ts.map +1 -0
  274. package/dist/lib/rich-text-dom.js +143 -0
  275. package/dist/lib/rich-text-dom.js.map +1 -0
  276. package/dist/lib/rich-text.d.ts +15 -0
  277. package/dist/lib/rich-text.d.ts.map +1 -0
  278. package/dist/lib/rich-text.js +35 -0
  279. package/dist/lib/rich-text.js.map +1 -0
  280. package/dist/lib/spotlight.d.ts +22 -0
  281. package/dist/lib/spotlight.d.ts.map +1 -0
  282. package/dist/lib/spotlight.js +66 -0
  283. package/dist/lib/spotlight.js.map +1 -0
  284. package/dist/lib/tree.d.ts +17 -0
  285. package/dist/lib/tree.d.ts.map +1 -0
  286. package/dist/lib/tree.js +35 -0
  287. package/dist/lib/tree.js.map +1 -0
  288. package/dist/lib/utils.d.ts +3 -0
  289. package/dist/lib/utils.d.ts.map +1 -0
  290. package/dist/lib/utils.js +6 -0
  291. package/dist/lib/utils.js.map +1 -0
  292. package/dist/styles/notion.css +526 -0
  293. package/package.json +106 -5
  294. package/src/components/editor/block-text.tsx +230 -0
  295. package/src/components/editor/blocks.tsx +368 -0
  296. package/src/components/editor/document-editor.tsx +101 -0
  297. package/src/components/editor/document-view.tsx +192 -0
  298. package/src/components/editor/editor-state.tsx +270 -0
  299. package/src/components/editor/extensions/spoiler.tsx +76 -0
  300. package/src/components/editor/index.ts +9 -0
  301. package/src/components/editor/kinds.ts +158 -0
  302. package/src/components/sketch/rough.tsx +90 -0
  303. package/src/components/ui/accent-picker.tsx +72 -0
  304. package/src/components/ui/address-field.tsx +57 -0
  305. package/src/components/ui/app-shell.tsx +138 -0
  306. package/src/components/ui/badge.tsx +81 -0
  307. package/src/components/ui/breadcrumbs.tsx +25 -0
  308. package/src/components/ui/button.tsx +73 -0
  309. package/src/components/ui/calendar.tsx +100 -0
  310. package/src/components/ui/callout.tsx +62 -0
  311. package/src/components/ui/card.tsx +90 -0
  312. package/src/components/ui/checkbox.tsx +32 -0
  313. package/src/components/ui/command-menu.tsx +72 -0
  314. package/src/components/ui/date-picker.tsx +170 -0
  315. package/src/components/ui/date-time-picker.tsx +117 -0
  316. package/src/components/ui/dialog.tsx +124 -0
  317. package/src/components/ui/dropdown-menu.tsx +183 -0
  318. package/src/components/ui/editable-text.tsx +109 -0
  319. package/src/components/ui/field-button.tsx +68 -0
  320. package/src/components/ui/file-preview.tsx +80 -0
  321. package/src/components/ui/file-uploader.tsx +376 -0
  322. package/src/components/ui/handle-row.tsx +116 -0
  323. package/src/components/ui/image-block.tsx +238 -0
  324. package/src/components/ui/image-card.tsx +102 -0
  325. package/src/components/ui/image-viewer.tsx +187 -0
  326. package/src/components/ui/image.tsx +96 -0
  327. package/src/components/ui/index.ts +83 -0
  328. package/src/components/ui/input.tsx +99 -0
  329. package/src/components/ui/link-block.tsx +82 -0
  330. package/src/components/ui/mac-card.tsx +46 -0
  331. package/src/components/ui/nav-tree.tsx +86 -0
  332. package/src/components/ui/page.tsx +25 -0
  333. package/src/components/ui/popover.tsx +42 -0
  334. package/src/components/ui/progress.tsx +36 -0
  335. package/src/components/ui/property.tsx +64 -0
  336. package/src/components/ui/segmented.tsx +42 -0
  337. package/src/components/ui/select-menu.tsx +46 -0
  338. package/src/components/ui/select.tsx +124 -0
  339. package/src/components/ui/selection-bar.tsx +50 -0
  340. package/src/components/ui/separator.tsx +30 -0
  341. package/src/components/ui/spotlight.tsx +222 -0
  342. package/src/components/ui/stat-tile.tsx +25 -0
  343. package/src/components/ui/step-dialog.tsx +104 -0
  344. package/src/components/ui/table.tsx +42 -0
  345. package/src/components/ui/theme-toggle.tsx +101 -0
  346. package/src/components/ui/time-picker.tsx +173 -0
  347. package/src/components/ui/tooltip.tsx +64 -0
  348. package/src/components/ui/typography.tsx +168 -0
  349. package/src/components/ui/video-block.tsx +60 -0
  350. package/src/hooks/use-save-queue.ts +66 -0
  351. package/src/hooks/use-selection.ts +44 -0
  352. package/src/hooks/use-shared-transition.ts +40 -0
  353. package/src/hooks/use-upload-queue.ts +111 -0
  354. package/src/lib/accent.ts +11 -0
  355. package/src/lib/bento.ts +87 -0
  356. package/src/lib/dates.ts +39 -0
  357. package/src/lib/document.ts +55 -0
  358. package/src/lib/embed.ts +62 -0
  359. package/src/lib/files.ts +73 -0
  360. package/src/lib/justified.ts +106 -0
  361. package/src/lib/rich-text-dom.ts +136 -0
  362. package/src/lib/rich-text.ts +50 -0
  363. package/src/lib/spotlight.ts +78 -0
  364. package/src/lib/tree.ts +41 -0
  365. package/src/lib/utils.ts +6 -0
  366. package/src/styles/notion.css +526 -0
@@ -0,0 +1,238 @@
1
+ "use client";
2
+
3
+ import { ImagePlus, Link2, LoaderCircle } from "lucide-react";
4
+ import { useRef, useState, type KeyboardEvent, type PointerEvent, type ReactNode } from "react";
5
+ import { Image } from "./image.tsx";
6
+ import { cn } from "../../lib/utils.ts";
7
+
8
+ /** The narrowest a picture can be made, as a share of the page. */
9
+ export const MIN_IMAGE_WIDTH = 0.2;
10
+
11
+ const clampWidth = (w: number) => Math.min(1, Math.max(MIN_IMAGE_WIDTH, Math.round(w * 100) / 100));
12
+
13
+ /* A picture in a document, as Notion has it: centred, as wide as you drag it, with
14
+ a caption under it. Before it has a picture it is an invitation to add one:
15
+ choose a file, drop one on it, paste one, or paste a link to one on the web.
16
+
17
+ It holds no picture itself. The owner decides what a file becomes (an upload,
18
+ a data URL) and passes back `src`; `busy` shows while that is under way. Width
19
+ is a share of the column, so a picture reads the same on a phone and a wide
20
+ screen; it changes live while a side handle is dragged and is reported once,
21
+ when the handle is let go. The arrow keys move a focused handle by 5%. */
22
+ export function ImageBlock({
23
+ src,
24
+ placeholder,
25
+ aspect,
26
+ alt = "",
27
+ width,
28
+ onWidthChange,
29
+ onFile,
30
+ onLink,
31
+ busy,
32
+ error,
33
+ caption,
34
+ onOpen,
35
+ actions,
36
+ more,
37
+ className,
38
+ }: {
39
+ src?: string;
40
+ /** A small version of the same picture, shown blurred while `src` loads. */
41
+ placeholder?: string;
42
+ /** Width over height, when known, so nothing below moves as it loads. */
43
+ aspect?: number;
44
+ alt?: string;
45
+ /** Share of the column, from MIN_IMAGE_WIDTH to 1. */
46
+ width: number;
47
+ onWidthChange?: (width: number) => void;
48
+ /** A file chosen, dropped or pasted onto the empty block. */
49
+ onFile?: (file: File) => void;
50
+ /** A link to a picture, pasted into the empty block. */
51
+ onLink?: (url: string) => void;
52
+ /** True, or progress from 0 to 1, while a picture is being made ready. */
53
+ busy?: boolean | number;
54
+ error?: string;
55
+ /** Under the picture: usually an EditableText. */
56
+ caption?: ReactNode;
57
+ /** A click on the picture: open it larger. */
58
+ onOpen?: () => void;
59
+ /** Buttons for the picture's top right corner, shown on hover. */
60
+ actions?: ReactNode;
61
+ /** More ways to find a picture, offered beside the file button when empty. */
62
+ more?: ReactNode;
63
+ className?: string;
64
+ }) {
65
+ const [dragging, setDragging] = useState<number | null>(null);
66
+ const [dropping, setDropping] = useState(false);
67
+ const [link, setLink] = useState("");
68
+ const input = useRef<HTMLInputElement>(null);
69
+ const frame = useRef<HTMLDivElement>(null);
70
+ const shown = dragging ?? width;
71
+
72
+ if (src === undefined) {
73
+ const working = busy !== undefined && busy !== false;
74
+ return (
75
+ <div
76
+ tabIndex={-1}
77
+ className={cn(
78
+ "flex flex-col gap-3 rounded-surface bg-tint-hover p-4 text-sm text-ink-secondary transition-shadow duration-150 outline-none sm:flex-row sm:items-center",
79
+ dropping && "shadow-[0_0_0_2px_var(--accent)]",
80
+ className,
81
+ )}
82
+ onDragOver={(e) => {
83
+ if (!onFile || !e.dataTransfer.types.includes("Files")) return;
84
+ e.preventDefault();
85
+ e.stopPropagation();
86
+ setDropping(true);
87
+ }}
88
+ onDragLeave={() => setDropping(false)}
89
+ onDrop={(e) => {
90
+ const file = [...e.dataTransfer.files].find((f) => f.type.startsWith("image/"));
91
+ if (!onFile || !file) return;
92
+ e.preventDefault();
93
+ e.stopPropagation();
94
+ setDropping(false);
95
+ onFile(file);
96
+ }}
97
+ onPaste={(e) => {
98
+ const file = [...e.clipboardData.files].find((f) => f.type.startsWith("image/"));
99
+ if (file && onFile) {
100
+ e.preventDefault();
101
+ onFile(file);
102
+ }
103
+ }}
104
+ >
105
+ {working ? (
106
+ <span className="flex items-center gap-2">
107
+ <LoaderCircle className="size-4 animate-spin" />
108
+ {typeof busy === "number" ? `Adding the picture… ${Math.round(busy * 100)}%` : "Adding the picture…"}
109
+ </span>
110
+ ) : (
111
+ <>
112
+ {onFile && (
113
+ <>
114
+ <button
115
+ type="button"
116
+ onClick={() => input.current?.click()}
117
+ className="flex h-8 shrink-0 items-center gap-2 rounded-control bg-surface px-3 font-medium text-ink shadow-xs transition-colors duration-100 hover:bg-surface-overlay [&_svg]:size-4"
118
+ >
119
+ <ImagePlus />
120
+ Choose a picture
121
+ </button>
122
+ <input
123
+ ref={input}
124
+ type="file"
125
+ accept="image/*"
126
+ hidden
127
+ onChange={(e) => {
128
+ const file = e.target.files?.[0];
129
+ e.target.value = "";
130
+ if (file) onFile(file);
131
+ }}
132
+ />
133
+ </>
134
+ )}
135
+ {more}
136
+ {onLink && (
137
+ <form
138
+ className="flex min-w-0 flex-1 items-center gap-2"
139
+ onSubmit={(e) => {
140
+ e.preventDefault();
141
+ if (/^https?:\/\//i.test(link.trim())) onLink(link.trim());
142
+ }}
143
+ >
144
+ <Link2 className="size-4 shrink-0 text-ink-tertiary" />
145
+ <input
146
+ value={link}
147
+ onChange={(e) => setLink(e.target.value)}
148
+ placeholder={onFile ? "or paste a link to a picture" : "Paste a link to a picture, then Enter"}
149
+ aria-label="Link to a picture"
150
+ className="h-8 min-w-0 flex-1 bg-transparent text-ink outline-none placeholder:text-ink-tertiary"
151
+ />
152
+ </form>
153
+ )}
154
+ </>
155
+ )}
156
+ {error && <span className="text-danger">{error}</span>}
157
+ </div>
158
+ );
159
+ }
160
+
161
+ // Dragging one side moves both, since the picture stays centred: the change in
162
+ // width is twice how far the pointer moved.
163
+ const drag = (side: -1 | 1) => ({
164
+ onPointerDown: (e: PointerEvent<HTMLSpanElement>) => {
165
+ if (!onWidthChange || !frame.current) return;
166
+ e.preventDefault();
167
+ const handle = e.currentTarget;
168
+ // Captured, so the drag keeps coming here however far the pointer strays.
169
+ handle.setPointerCapture(e.pointerId);
170
+ const column = frame.current.parentElement!.getBoundingClientRect().width;
171
+ const start = { x: e.clientX, width };
172
+ let last = width;
173
+ const move = (ev: globalThis.PointerEvent) => {
174
+ last = clampWidth(start.width + (side * (ev.clientX - start.x) * 2) / column);
175
+ setDragging(last);
176
+ };
177
+ // A cancelled drag (the browser took the pointer for a scroll or a drag of
178
+ // its own) keeps the width reached, rather than snapping back.
179
+ const end = () => {
180
+ handle.removeEventListener("pointermove", move);
181
+ handle.removeEventListener("pointerup", end);
182
+ handle.removeEventListener("pointercancel", end);
183
+ setDragging(null);
184
+ if (last !== width) onWidthChange(last);
185
+ };
186
+ handle.addEventListener("pointermove", move);
187
+ handle.addEventListener("pointerup", end);
188
+ handle.addEventListener("pointercancel", end);
189
+ },
190
+ onKeyDown: (e: KeyboardEvent<HTMLSpanElement>) => {
191
+ const step = e.key === "ArrowRight" ? side * 0.05 : e.key === "ArrowLeft" ? -side * 0.05 : 0;
192
+ if (step === 0 || !onWidthChange) return;
193
+ e.preventDefault();
194
+ const next = clampWidth(width + step);
195
+ if (next !== width) onWidthChange(next);
196
+ },
197
+ });
198
+
199
+ const handle = (side: -1 | 1) =>
200
+ onWidthChange && (
201
+ <span
202
+ role="slider"
203
+ tabIndex={0}
204
+ aria-label="Picture width"
205
+ aria-valuemin={MIN_IMAGE_WIDTH * 100}
206
+ aria-valuemax={100}
207
+ aria-valuenow={Math.round(shown * 100)}
208
+ aria-valuetext={`${Math.round(shown * 100)}% of the page`}
209
+ {...drag(side)}
210
+ className={cn(
211
+ "absolute top-1/2 z-10 flex h-16 max-h-[60%] w-3 -translate-y-1/2 cursor-ew-resize touch-none items-center justify-center opacity-0 transition-opacity duration-100 group-hover/image:opacity-100 focus-visible:opacity-100 max-md:hidden",
212
+ side === -1 ? "left-1" : "right-1",
213
+ dragging !== null && "opacity-100",
214
+ )}
215
+ >
216
+ {/* A pill that reads on any picture: a dark core with a light edge. */}
217
+ <span className="h-full w-1.5 rounded-full bg-black/55 shadow-[0_0_0_1px_rgb(255_255_255/0.7)]" />
218
+ </span>
219
+ );
220
+
221
+ return (
222
+ <figure className={cn("flex flex-col items-center", className)}>
223
+ {/* No native drag: the browser picking up the picture would steal the pointer from a handle. */}
224
+ <div ref={frame} className="group/image relative max-w-full select-none" style={{ width: `${shown * 100}%` }} onDragStart={(e) => e.preventDefault()}>
225
+ {handle(-1)}
226
+ <button type="button" onClick={onOpen} disabled={!onOpen} aria-label={alt === "" ? "Open the picture" : `Open ${alt}`} className="block w-full cursor-zoom-in overflow-hidden rounded-surface disabled:cursor-default">
227
+ <Image src={src} placeholder={placeholder} aspect={aspect} alt={alt} fit="cover" draggable={false} className="w-full" />
228
+ </button>
229
+ {handle(1)}
230
+ {actions && <div className="absolute top-2 right-2 flex gap-1 opacity-0 transition-opacity duration-100 group-hover/image:opacity-100 focus-within:opacity-100 max-md:opacity-100">{actions}</div>}
231
+ {dragging !== null && (
232
+ <span className="numeric absolute top-2 left-2 rounded-control bg-black/60 px-1.5 py-0.5 text-caption text-white">{Math.round(dragging * 100)}%</span>
233
+ )}
234
+ </div>
235
+ {caption !== undefined && <figcaption className="mt-1.5 w-full max-w-full text-sm text-ink-secondary" style={{ width: `${shown * 100}%` }}>{caption}</figcaption>}
236
+ </figure>
237
+ );
238
+ }
@@ -0,0 +1,102 @@
1
+ "use client";
2
+
3
+ import { Check } from "lucide-react";
4
+ import type { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
5
+ import { cn } from "../../lib/utils.ts";
6
+
7
+ /* A picture as a card: the image is the whole card, and anything else sits on
8
+ top of it in a corner. Rounded, with a slight dim on hover.
9
+
10
+ It can also be picked. While `selecting` is set, a press picks the card
11
+ instead of doing whatever its content would do, a tick shows in the corner,
12
+ and a picked card shrinks a little inside an accent ring. Shift is passed
13
+ through so a run of cards can be picked at once (see `useSelection`).
14
+
15
+ Put `group` to use: children can react to `group-hover`, and the corner
16
+ controls made with `ImageCardButton` stay hidden until then. */
17
+ export function ImageCard({
18
+ children,
19
+ topRight,
20
+ bottomLeft,
21
+ selecting = false,
22
+ selected = false,
23
+ onSelect,
24
+ className,
25
+ ...props
26
+ }: Omit<ComponentPropsWithoutRef<"div">, "onSelect"> & {
27
+ /** Controls for the top-right corner, usually an `ImageCardButton`. */
28
+ topRight?: ReactNode;
29
+ /** Markers for the bottom-left corner, usually an `ImageCardBadge`. */
30
+ bottomLeft?: ReactNode;
31
+ selecting?: boolean;
32
+ selected?: boolean;
33
+ onSelect?: (event: { range: boolean }) => void;
34
+ }) {
35
+ return (
36
+ <div
37
+ className={cn(
38
+ "group relative overflow-hidden rounded-[10px] bg-surface-sunken transition-[scale,box-shadow] duration-150 ease-out-notion",
39
+ "[&_img]:transition-[filter,opacity,scale] hover:[&_img]:brightness-[0.94]",
40
+ selecting && selected && "scale-[0.94] shadow-[0_0_0_3px_var(--accent)]",
41
+ className,
42
+ )}
43
+ // Capture, so the press never reaches a link or button inside.
44
+ onClickCapture={
45
+ selecting
46
+ ? (event: MouseEvent) => {
47
+ event.preventDefault();
48
+ event.stopPropagation();
49
+ onSelect?.({ range: event.shiftKey });
50
+ }
51
+ : undefined
52
+ }
53
+ aria-selected={selecting ? selected : undefined}
54
+ {...props}
55
+ >
56
+ {children}
57
+ {selecting && (
58
+ <span
59
+ aria-hidden
60
+ className={cn(
61
+ "pointer-events-none absolute top-2 left-2 z-10 flex size-6 items-center justify-center rounded-full shadow-sm transition-colors duration-100",
62
+ selected ? "bg-accent text-accent-ink" : "bg-white/70 text-transparent backdrop-blur-sm",
63
+ )}
64
+ >
65
+ <Check className="size-4" />
66
+ </span>
67
+ )}
68
+ {bottomLeft !== undefined && <div className="pointer-events-none absolute bottom-2 left-2 flex gap-1">{bottomLeft}</div>}
69
+ {topRight !== undefined && !selecting && <div className="absolute top-2 right-2 flex gap-1">{topRight}</div>}
70
+ </div>
71
+ );
72
+ }
73
+
74
+ /* A control on top of a picture. White on a soft dark disc in both themes,
75
+ because it has to read against the picture, not the page: a bright sky as
76
+ well as a dark one. Hidden until the card is hovered or it takes focus,
77
+ unless `always` is set (for a state that is on, like a favourite). */
78
+ export function ImageCardButton({ always = false, className, ...props }: ComponentPropsWithoutRef<"button"> & { always?: boolean }) {
79
+ return (
80
+ <button
81
+ type="button"
82
+ className={cn(
83
+ "flex size-7 items-center justify-center rounded-full bg-black/35 text-white backdrop-blur-sm",
84
+ "transition-[opacity,scale,background-color] duration-100 hover:bg-black/55 active:scale-90 [&_svg]:size-4",
85
+ !always && "affordance",
86
+ className,
87
+ )}
88
+ {...props}
89
+ />
90
+ );
91
+ }
92
+
93
+ /* A marker on top of a picture that is always shown: a fact about it that
94
+ should not take a hover to find out. */
95
+ export function ImageCardBadge({ className, ...props }: ComponentPropsWithoutRef<"span">) {
96
+ return (
97
+ <span
98
+ className={cn("flex size-6 items-center justify-center rounded-full bg-black/35 text-white backdrop-blur-sm [&_svg]:size-3.5", className)}
99
+ {...props}
100
+ />
101
+ );
102
+ }
@@ -0,0 +1,187 @@
1
+ "use client";
2
+
3
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
4
+ import { ChevronLeft, ChevronRight, X } from "lucide-react";
5
+ import { useEffect, useRef, type CSSProperties, type ReactNode } from "react";
6
+ import { Button } from "./button.tsx";
7
+ import { cn } from "../../lib/utils.ts";
8
+
9
+ export type ViewerItem = {
10
+ id: string;
11
+ /** The large picture. */
12
+ src: string;
13
+ /** A small one already on screen or in the cache, shown until the large one arrives. */
14
+ placeholder?: string;
15
+ alt: string;
16
+ /** Width over height. Needed: the picture is sized from it before it loads. */
17
+ aspect: number;
18
+ };
19
+
20
+ /* One picture at a time, as large as the room allows, with a way to the next:
21
+ a carousel that is also a lightbox.
22
+
23
+ - Left and right arrows step; each picture slides in from the side it came
24
+ from. Its neighbours are fetched ahead.
25
+ - The picture is sized with container units from its aspect ratio, so it
26
+ fills the space both ways without distorting and before it has loaded.
27
+ - `toolbar` goes at the right of the header, `panel` beside the picture.
28
+ The panel slides open and shut like a sidebar; you own `panelOpen`.
29
+ - `transitionName` puts a view-transition name on the picture, so opening
30
+ and closing can grow it out of, and shrink it into, the element it was
31
+ opened from (see `useSharedTransition`).
32
+ - Pass `modal={false}` and a `className` with an inset to lay it beside a
33
+ sidebar that should stay usable; keys typed into a field elsewhere are
34
+ ignored either way. */
35
+ export function ImageViewer({
36
+ items,
37
+ id,
38
+ onShow,
39
+ onClose,
40
+ title,
41
+ toolbar,
42
+ panel,
43
+ panelOpen = false,
44
+ overlay,
45
+ modal = true,
46
+ transitionName,
47
+ filter,
48
+ className,
49
+ }: {
50
+ items: ViewerItem[];
51
+ /** Which item is showing. */
52
+ id: string;
53
+ onShow: (id: string) => void;
54
+ onClose: () => void;
55
+ /** For screen readers; defaults to the item's alt text. */
56
+ title?: string;
57
+ toolbar?: ReactNode;
58
+ panel?: ReactNode;
59
+ panelOpen?: boolean;
60
+ /** Anything to lay over the picture's area: a label, a notice. */
61
+ overlay?: ReactNode;
62
+ modal?: boolean;
63
+ transitionName?: string;
64
+ /** A CSS filter for the picture, eased when it changes. */
65
+ filter?: string;
66
+ className?: string;
67
+ }) {
68
+ const index = items.findIndex((item) => item.id === id);
69
+ const item = items[index];
70
+ const before = index > 0 ? items[index - 1] : undefined;
71
+ const after = index !== -1 ? items[index + 1] : undefined;
72
+
73
+ // Which way the last step went, so the new picture arrives from that side.
74
+ const last = useRef(index);
75
+ const from = index >= last.current ? 1 : -1;
76
+ const stepped = last.current !== index;
77
+ useEffect(() => {
78
+ last.current = index;
79
+ }, [index]);
80
+
81
+ useEffect(() => {
82
+ const onKey = (event: KeyboardEvent) => {
83
+ const target = event.target as HTMLElement | null;
84
+ // A slider is not typing: the arrows still step from it.
85
+ const slider = target instanceof HTMLInputElement && target.type === "range";
86
+ if (target !== null && !slider && (target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName))) return;
87
+ if (event.metaKey || event.ctrlKey || event.altKey) return;
88
+ if (event.key === "ArrowLeft" && before !== undefined) onShow(before.id);
89
+ else if (event.key === "ArrowRight" && after !== undefined) onShow(after.id);
90
+ };
91
+ window.addEventListener("keydown", onKey);
92
+ return () => window.removeEventListener("keydown", onKey);
93
+ });
94
+
95
+ // The neighbours are the likeliest next request; have them in the cache.
96
+ useEffect(() => {
97
+ for (const next of [after, before]) if (next !== undefined) new window.Image().src = next.src;
98
+ }, [before, after]);
99
+
100
+ const arrow =
101
+ "affordance absolute top-1/2 -translate-y-1/2 rounded-full bg-surface-overlay shadow-sm hover:bg-surface-overlay max-md:opacity-100";
102
+
103
+ return (
104
+ <DialogPrimitive.Root open modal={modal} onOpenChange={(open) => !open && onClose()}>
105
+ <DialogPrimitive.Portal>
106
+ <DialogPrimitive.Content
107
+ aria-describedby={undefined}
108
+ // Focus the sheet, not its first button: a focused button shows its
109
+ // tooltip, and the picture should be all there is to look at.
110
+ onOpenAutoFocus={(event) => {
111
+ event.preventDefault();
112
+ (event.currentTarget as HTMLElement).focus();
113
+ }}
114
+ // Not modal means a sidebar, a menu or a tray outside it may be
115
+ // used; using them must not close it.
116
+ onInteractOutside={(event) => !modal && event.preventDefault()}
117
+ className={cn("fixed inset-0 z-30 flex flex-col bg-surface text-ink outline-none", className)}
118
+ >
119
+ <DialogPrimitive.Title className="sr-only">{title ?? item?.alt ?? "Picture"}</DialogPrimitive.Title>
120
+
121
+ <header className="flex h-12 shrink-0 items-center gap-1 px-2">
122
+ <Button variant="ghost" size="icon" aria-label="Close" onClick={onClose}>
123
+ <X />
124
+ </Button>
125
+ <span className="min-w-0 flex-1 truncate px-1 text-sm text-ink-secondary tabular-nums">
126
+ {index !== -1 && `${(index + 1).toLocaleString()} of ${items.length.toLocaleString()}`}
127
+ </span>
128
+ {toolbar}
129
+ </header>
130
+
131
+ <div className="flex min-h-0 flex-1 flex-col md:flex-row">
132
+ {/* A size container, so the picture can be told to be as large as
133
+ fits both ways while keeping its shape. */}
134
+ <div className="group relative flex min-h-0 min-w-0 flex-1 items-center justify-center p-3 [container-type:size] md:p-6">
135
+ {item !== undefined && (
136
+ <img
137
+ key={item.id}
138
+ src={item.src}
139
+ alt={item.alt}
140
+ style={
141
+ {
142
+ width: `min(100cqw, calc(100cqh * ${item.aspect}))`,
143
+ aspectRatio: item.aspect,
144
+ backgroundImage: item.placeholder !== undefined ? `url(${item.placeholder})` : undefined,
145
+ backgroundSize: "cover",
146
+ viewTransitionName: transitionName,
147
+ filter: filter ?? "none",
148
+ "--from": from,
149
+ } as CSSProperties
150
+ }
151
+ // Only a step slides in. The first picture may arrive by a
152
+ // view transition, and must not also slide.
153
+ className={cn("rounded-[6px] shadow-md transition-[filter] duration-150 ease-out-notion", stepped && "animate-step-in")}
154
+ />
155
+ )}
156
+ {overlay}
157
+ {before !== undefined && (
158
+ <Button variant="subtle" size="icon" aria-label="Previous" onClick={() => onShow(before.id)} className={cn(arrow, "left-3")}>
159
+ <ChevronLeft />
160
+ </Button>
161
+ )}
162
+ {after !== undefined && (
163
+ <Button variant="subtle" size="icon" aria-label="Next" onClick={() => onShow(after.id)} className={cn(arrow, "right-3")}>
164
+ <ChevronRight />
165
+ </Button>
166
+ )}
167
+ </div>
168
+
169
+ {panel !== undefined && (
170
+ <aside
171
+ inert={!panelOpen}
172
+ className={cn(
173
+ "shrink-0 overflow-hidden bg-surface-sunken transition-[width,max-height] duration-150 ease-out-notion",
174
+ "max-md:shadow-[inset_0_1px_0_var(--hairline)] md:shadow-[inset_1px_0_0_var(--hairline)]",
175
+ panelOpen ? "max-md:max-h-[46dvh] md:w-80" : "max-md:max-h-0 md:w-0",
176
+ )}
177
+ >
178
+ {/* A fixed width inside, so the content does not reflow while the column slides. */}
179
+ <div className="h-full overflow-y-auto md:w-80">{panel}</div>
180
+ </aside>
181
+ )}
182
+ </div>
183
+ </DialogPrimitive.Content>
184
+ </DialogPrimitive.Portal>
185
+ </DialogPrimitive.Root>
186
+ );
187
+ }
@@ -0,0 +1,96 @@
1
+ "use client";
2
+
3
+ import { useState, type ComponentPropsWithoutRef, type CSSProperties } from "react";
4
+ import { ImageOff } from "lucide-react";
5
+ import { cn } from "../../lib/utils.ts";
6
+
7
+ /* An image that arrives gracefully. Until it has loaded the box holds its
8
+ shape and shows a blurred, tiny stand-in (or just the sunken surface);
9
+ then the real picture fades and settles in over it.
10
+
11
+ One already in the browser's cache is shown at once: scrolling back to
12
+ images already seen must not replay the fade.
13
+
14
+ Give it `aspect` (width over height) whenever it is known, so nothing below
15
+ it moves when it loads. */
16
+ export function Image({
17
+ src,
18
+ alt,
19
+ placeholder,
20
+ aspect,
21
+ fit = "cover",
22
+ className,
23
+ imgClassName,
24
+ style,
25
+ onLoad,
26
+ ...props
27
+ }: Omit<ComponentPropsWithoutRef<"img">, "placeholder"> & {
28
+ /** A very small version of the same picture, shown blurred while the real one loads. */
29
+ placeholder?: string;
30
+ /** Width over height. */
31
+ aspect?: number;
32
+ fit?: "cover" | "contain";
33
+ /** Extra classes for the <img> itself; `className` goes on the box. */
34
+ imgClassName?: string;
35
+ }) {
36
+ const [loaded, setLoaded] = useState(false);
37
+ // A picture on someone else's site can vanish; say so rather than leave an empty box.
38
+ const [failed, setFailed] = useState<string | null>(null);
39
+
40
+ if (failed !== null && failed === src) {
41
+ return (
42
+ <span
43
+ role="img"
44
+ aria-label={alt ? `${alt} (could not be loaded)` : "A picture that could not be loaded"}
45
+ className={cn("@container flex flex-col items-center justify-center gap-1.5 bg-surface-sunken p-1 text-center text-caption text-ink-tertiary", className)}
46
+ style={{ ...(aspect !== undefined ? { aspectRatio: aspect } : null), ...style } as CSSProperties}
47
+ >
48
+ <ImageOff className="size-5 shrink-0" />
49
+ {/* Words only where there is room for them; a thumbnail gets the icon alone. */}
50
+ <span className="hidden px-2 @min-[9rem]:inline">This picture couldn't be loaded</span>
51
+ </span>
52
+ );
53
+ }
54
+
55
+ return (
56
+ <span
57
+ className={cn("relative block overflow-hidden bg-surface-sunken", className)}
58
+ style={{ ...(aspect !== undefined ? { aspectRatio: aspect } : null), ...style } as CSSProperties}
59
+ >
60
+ {placeholder !== undefined && (
61
+ // Scaled up a touch so the blur's soft edge falls outside the box.
62
+ <img
63
+ src={placeholder}
64
+ alt=""
65
+ aria-hidden
66
+ draggable={false}
67
+ className={cn(
68
+ "absolute inset-0 h-full w-full scale-110 blur-lg transition-opacity duration-300",
69
+ fit === "cover" ? "object-cover" : "object-contain",
70
+ loaded && "opacity-0",
71
+ )}
72
+ />
73
+ )}
74
+ <img
75
+ ref={(img) => {
76
+ if (img?.complete && img.naturalWidth > 0) setLoaded(true);
77
+ }}
78
+ src={src}
79
+ alt={alt}
80
+ decoding="async"
81
+ onLoad={(event) => {
82
+ setLoaded(true);
83
+ onLoad?.(event);
84
+ }}
85
+ onError={() => setFailed(typeof src === "string" ? src : null)}
86
+ className={cn(
87
+ "relative h-full w-full transition-[opacity,scale,filter] duration-300 ease-out-notion",
88
+ fit === "cover" ? "object-cover" : "object-contain",
89
+ loaded ? "opacity-100" : "scale-[1.02] opacity-0",
90
+ imgClassName,
91
+ )}
92
+ {...props}
93
+ />
94
+ </span>
95
+ );
96
+ }