@podoba/react 0.0.52 → 0.0.53

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 (34) hide show
  1. package/package.json +4 -4
  2. package/src/components/asset-selection-surface.tsx +264 -67
  3. package/src/components/citation.examples.tsx +14 -0
  4. package/src/components/citation.tsx +27 -0
  5. package/src/components/column-layout.examples.tsx +34 -0
  6. package/src/components/column-layout.tsx +36 -0
  7. package/src/components/combobox.tsx +9 -4
  8. package/src/components/compact-settings-dialog.tsx +80 -21
  9. package/src/components/date-picker.tsx +49 -8
  10. package/src/components/delivery/send-to-print-modal.tsx +191 -225
  11. package/src/components/field-appearance.ts +11 -1
  12. package/src/components/icon-button.examples.tsx +16 -0
  13. package/src/components/icon-button.tsx +20 -0
  14. package/src/components/input.tsx +25 -12
  15. package/src/components/island-toolbar.examples.tsx +27 -0
  16. package/src/components/island-toolbar.tsx +39 -0
  17. package/src/components/media-asset-panel.examples.tsx +44 -5
  18. package/src/components/media-asset-panel.tsx +339 -28
  19. package/src/components/media-collection.examples.tsx +18 -0
  20. package/src/components/media-collection.tsx +206 -0
  21. package/src/components/number-field.tsx +18 -9
  22. package/src/components/preview-error.examples.tsx +20 -0
  23. package/src/components/preview-error.tsx +29 -0
  24. package/src/components/preview-metadata-card.examples.tsx +32 -0
  25. package/src/components/preview-metadata-card.tsx +112 -0
  26. package/src/components/search-field.tsx +27 -7
  27. package/src/components/select.tsx +81 -50
  28. package/src/components/settings-dialog-surface.tsx +553 -114
  29. package/src/components/template-catalog-card.tsx +309 -78
  30. package/src/components/textarea.tsx +160 -12
  31. package/src/components/tile.tsx +30 -16
  32. package/src/components/zoomable-image.examples.tsx +33 -0
  33. package/src/components/zoomable-image.tsx +185 -0
  34. package/src/index.ts +96 -78
@@ -1,11 +1,50 @@
1
1
  import { MediaAssetPanel } from './media-asset-panel'
2
- const labels = { heading: 'Assets', emptyDescription: 'No assets yet.', emptyHint: 'Select assets to begin.', selectLabel: 'Select assets', previousLabel: 'Previous asset', nextLabel: 'Next asset' }
3
- const items = ['First', 'Second'].map(id => ({ id, content: <div className="grid h-full place-items-center bg-surface-muted">{id}</div> }))
2
+ const labels = {
3
+ heading: 'Assets',
4
+ emptyDescription: 'No assets yet.',
5
+ emptyHint: 'Select assets to begin.',
6
+ selectLabel: 'Select assets',
7
+ previousLabel: 'Previous asset',
8
+ nextLabel: 'Next asset',
9
+ }
10
+ const items = ['First', 'Second'].map((id) => ({
11
+ id,
12
+ content: <div className="grid h-full place-items-center bg-surface-muted">{id}</div>,
13
+ }))
4
14
  export const examples = {
15
+ readability: () => (
16
+ <MediaAssetPanel
17
+ {...labels}
18
+ items={items}
19
+ mode="media"
20
+ empty={false}
21
+ identity={{
22
+ title: 'Title',
23
+ caption: 'Independent caption',
24
+ count: 1,
25
+ titleAppearance: { color: 'dark', background: 'none' },
26
+ captionAppearance: { color: 'white', background: 'blur' },
27
+ }}
28
+ />
29
+ ),
5
30
  default: () => <MediaAssetPanel {...labels} items={items} mode="media" empty={false} onSelect={() => undefined} />,
6
- variants: () => <MediaAssetPanel {...labels} items={items} mode="carousel" empty={false} onSelect={() => undefined} />,
31
+ variants: () => (
32
+ <MediaAssetPanel {...labels} items={items} mode="carousel" empty={false} onSelect={() => undefined} />
33
+ ),
7
34
  states: () => <MediaAssetPanel {...labels} items={[]} mode="media" empty onSelect={() => undefined} />,
8
35
  readOnly: () => <MediaAssetPanel {...labels} items={items} mode="grid" empty={false} />,
9
- reference: () => <MediaAssetPanel {...labels} items={items.slice(0, 1)} mode="media" empty={false} identity={{ title: 'Annual report', caption: '1 asset reference', count: 1 }} onSelect={() => undefined} />,
36
+ reference: () => (
37
+ <MediaAssetPanel
38
+ {...labels}
39
+ items={items.slice(0, 1)}
40
+ mode="media"
41
+ empty={false}
42
+ identity={{ title: 'Annual report', caption: '1 asset reference', count: 1 }}
43
+ onSelect={() => undefined}
44
+ />
45
+ ),
46
+ }
47
+ export const meta = {
48
+ category: 'Composite',
49
+ description: 'Asset preview panel with centered empty action and independent carousel controls.',
10
50
  }
11
- export const meta = { category: 'Composite', description: 'Asset preview panel with centered empty action and independent carousel controls.' }
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react'
1
+ import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
2
2
  import { Button as AriaButton } from 'react-aria-components'
3
3
  import { uic } from '../utils/uic'
4
4
  import { Button } from './button'
@@ -18,41 +18,352 @@ export type MediaAssetPanelProps = {
18
18
  nextLabel: string
19
19
  onSelect?: () => void
20
20
  /** Optional reference identity; omitted for a media-only gallery. */
21
- identity?: { title: ReactNode; caption: ReactNode; count: ReactNode }
21
+ identity?: {
22
+ title: ReactNode
23
+ caption: ReactNode
24
+ count: ReactNode
25
+ titleAppearance?: MediaTextAppearance
26
+ captionAppearance?: MediaTextAppearance
27
+ captionWidth?: number
28
+ }
22
29
  className?: string
23
30
  }
24
31
  const Surface = uic('div', {
25
32
  displayName: 'MediaAssetPanel',
26
- baseClass: 'group/media-panel relative isolate h-95 w-full shrink-0 overflow-hidden rounded-lg bg-surface-card text-fg',
33
+ baseClass:
34
+ 'group/media-panel relative isolate h-95 w-full shrink-0 overflow-hidden rounded-lg bg-surface-card text-fg',
27
35
  })
28
36
  const PanelAction = uic(AriaButton, {
29
37
  displayName: 'MediaAssetPanelAction',
30
- baseClass: 'absolute inset-0 z-10 cursor-pointer rounded-lg border-0 bg-transparent p-0 outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-inset data-[focus-visible]:ring-ring',
38
+ baseClass:
39
+ 'absolute inset-0 z-10 cursor-pointer rounded-lg border-0 bg-transparent p-0 outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-inset data-[focus-visible]:ring-ring',
31
40
  })
32
41
 
33
42
  /** Full-bleed media with independent selection and carousel controls. */
34
- export function MediaAssetPanel({ items, mode, empty, heading, emptyDescription, emptyHint, selectLabel, previousLabel, nextLabel, onSelect, identity, className }: MediaAssetPanelProps) {
35
- return <Surface className={className}>
36
- {onSelect ? empty
37
- ? <button type="button" aria-label={selectLabel} aria-hidden="true" tabIndex={-1} onClick={onSelect} className="absolute inset-0 z-10 cursor-pointer rounded-lg border-0 bg-transparent p-0" />
38
- : <PanelAction aria-label={selectLabel} onPress={onSelect} /> : null}
39
- {empty ? <>
40
- <div className="pointer-events-none absolute inset-x-4 top-4 z-20 text-body font-medium leading-5">{heading}</div>
41
- {onSelect ? <div className="pointer-events-none absolute inset-0 z-20 flex items-center justify-center">
42
- <Button className="pointer-events-auto h-14 w-48 p-0" onPress={onSelect}>{selectLabel}</Button>
43
- </div> : null}
44
- <p className="pointer-events-none absolute inset-x-4 bottom-4 z-20 m-0 text-small">
45
- <span className="font-medium text-fg">{emptyDescription}</span><br />
46
- <span className="text-fg-muted">{emptyHint}</span>
47
- </p>
48
- </> : <MediaGallery items={mode === 'media' ? items.slice(0, 1) : items} mode={mode === 'carousel' ? 'carousel' : 'grid'} previousLabel={previousLabel} nextLabel={nextLabel} className="pointer-events-none" />}
49
- {!empty && identity ? <>
50
- <div aria-hidden="true" className="pointer-events-none absolute inset-y-0 left-0 z-[1] hidden w-[min(56%,34rem)] bg-[linear-gradient(90deg,rgba(0,0,0,0.52)_0%,rgba(0,0,0,0.28)_58%,transparent_100%)] group-has-[img]/media-panel:block" />
51
- <div className="pointer-events-none absolute inset-4 z-[2] grid grid-rows-[auto_minmax(0,1fr)_auto] gap-6 text-fg group-has-[img]/media-panel:text-white group-has-[img]/media-panel:[text-shadow:0_1px_3px_rgba(0,0,0,0.5)]">
52
- <div className="mb-2 flex items-start justify-between gap-2 text-body font-medium leading-5"><span>{heading}</span><span className="rounded-full bg-surface-muted px-2.5 py-1 text-caption text-fg [text-shadow:none]">{identity.count}</span></div>
53
- <p className="m-0 max-w-[19ch] pt-2 text-heading1 font-medium leading-[30px]">{identity.title}</p>
54
- <p className="m-0 text-small opacity-80">{identity.caption}</p>
55
- </div>
56
- </> : null}
57
- </Surface>
43
+ export function MediaAssetPanel({
44
+ items,
45
+ mode,
46
+ empty,
47
+ heading,
48
+ emptyDescription,
49
+ emptyHint,
50
+ selectLabel,
51
+ previousLabel,
52
+ nextLabel,
53
+ onSelect,
54
+ identity,
55
+ className,
56
+ }: MediaAssetPanelProps) {
57
+ const panelRef = useRef<HTMLDivElement>(null)
58
+ const [multiply, setMultiply] = useState(false)
59
+ useEffect(() => {
60
+ const panel = panelRef.current
61
+ if (!panel) return
62
+ let disposed = false
63
+ const analyze = async () => {
64
+ const image = panel.querySelector<HTMLImageElement>('img')
65
+ if (!image?.complete || !image.naturalWidth) return
66
+ try {
67
+ const readable = await readableMediaImage(image)
68
+ const canvas = document.createElement('canvas')
69
+ canvas.width = 16
70
+ canvas.height = 16
71
+ const ctx = canvas.getContext('2d', { willReadFrequently: true })
72
+ if (!ctx) return
73
+ ctx.fillStyle = 'white'
74
+ ctx.fillRect(0, 0, 16, 16)
75
+ ctx.drawImage(readable, 0, 0, 16, 16)
76
+ const data = ctx.getImageData(0, 0, 16, 16).data
77
+ const white = (pixel: number) =>
78
+ (data[pixel * 4] ?? 0) >= 245 && (data[pixel * 4 + 1] ?? 0) >= 245 && (data[pixel * 4 + 2] ?? 0) >= 245
79
+ // A white backdrop surrounds the subject. Isolated highlights in a photo do not qualify.
80
+ const corners = [0, 15, 240, 255].filter(white).length
81
+ let whites = 0
82
+ for (let i = 0; i < 256; i++) if (white(i)) whites++
83
+ if (!disposed) setMultiply(corners >= 3 && whites / 256 >= 0.25)
84
+ } catch {
85
+ if (!disposed) setMultiply(false)
86
+ }
87
+ }
88
+ panel.addEventListener('load', analyze, true)
89
+ const observer = new MutationObserver(analyze)
90
+ observer.observe(panel, { childList: true, subtree: true, attributes: true, attributeFilter: ['src'] })
91
+ void analyze()
92
+ return () => {
93
+ disposed = true
94
+ panel.removeEventListener('load', analyze, true)
95
+ observer.disconnect()
96
+ }
97
+ }, [empty, mode, items.map((item) => item.id).join(',')])
98
+ return (
99
+ <Surface ref={panelRef} className={className} data-media-readability data-media-multiply={multiply}>
100
+ {onSelect ? (
101
+ empty ? (
102
+ <button
103
+ type="button"
104
+ aria-label={selectLabel}
105
+ aria-hidden="true"
106
+ tabIndex={-1}
107
+ onClick={onSelect}
108
+ className="absolute inset-0 z-10 cursor-pointer rounded-lg border-0 bg-transparent p-0"
109
+ />
110
+ ) : (
111
+ <PanelAction aria-label={selectLabel} onPress={onSelect} />
112
+ )
113
+ ) : null}
114
+ {empty ? (
115
+ <>
116
+ <div className="pointer-events-none absolute inset-x-4 top-4 z-20 text-body font-medium leading-5">
117
+ {heading}
118
+ </div>
119
+ {onSelect ? (
120
+ <div className="pointer-events-none absolute inset-0 z-20 flex items-center justify-center">
121
+ <Button className="pointer-events-auto h-14 w-48 p-0" onPress={onSelect}>
122
+ {selectLabel}
123
+ </Button>
124
+ </div>
125
+ ) : null}
126
+ <p className="pointer-events-none absolute inset-x-4 bottom-4 z-20 m-0 text-small">
127
+ <span className="font-medium text-fg">{emptyDescription}</span>
128
+ <br />
129
+ <span className="text-fg-muted">{emptyHint}</span>
130
+ </p>
131
+ </>
132
+ ) : (
133
+ <MediaGallery
134
+ items={mode === 'media' ? items.slice(0, 1) : items}
135
+ mode={mode === 'carousel' ? 'carousel' : 'grid'}
136
+ previousLabel={previousLabel}
137
+ nextLabel={nextLabel}
138
+ className={`pointer-events-none bg-transparent ${multiply ? 'mix-blend-multiply' : ''}`}
139
+ />
140
+ )}
141
+ {!empty && identity ? (
142
+ <>
143
+ <div className="pointer-events-none absolute inset-4 z-[2] grid grid-rows-[auto_minmax(0,1fr)_auto] gap-6 text-fg">
144
+ <div className="flex items-start justify-between gap-2 text-body font-medium leading-5">
145
+ <div className="min-w-0 flex-1">
146
+ {heading ? <span className="mb-1 block text-caption">{heading}</span> : null}
147
+ <p className="m-0 text-body font-medium leading-5">
148
+ <MediaReadableText appearance={identity.titleAppearance}>{identity.title}</MediaReadableText>
149
+ </p>
150
+ </div>
151
+ <span className="shrink-0 rounded-full bg-surface-muted px-2.5 py-1 text-caption text-fg [text-shadow:none]">
152
+ {identity.count}
153
+ </span>
154
+ </div>
155
+ <span aria-hidden="true" />
156
+ <p className="m-0 text-small">
157
+ <MediaReadableText appearance={identity.captionAppearance} secondary maxWidth={identity.captionWidth}>
158
+ {identity.caption}
159
+ </MediaReadableText>
160
+ </p>
161
+ </div>
162
+ </>
163
+ ) : null}
164
+ </Surface>
165
+ )
166
+ }
167
+
168
+ export const MEDIA_TEXT_COLORS = ['auto', 'dark', 'white', 'gray'] as const
169
+ export const MEDIA_TEXT_BACKGROUNDS = ['auto', 'none', 'gradient', 'blur'] as const
170
+ export type MediaTextColor = (typeof MEDIA_TEXT_COLORS)[number]
171
+ export type MediaTextBackground = (typeof MEDIA_TEXT_BACKGROUNDS)[number]
172
+ export type MediaTextAppearance = { color?: MediaTextColor; background?: MediaTextBackground }
173
+ type Tone = Exclude<MediaTextColor, 'auto'>
174
+ export type MediaPixel = readonly [number, number, number]
175
+ const inks: Record<Tone, MediaPixel> = { dark: [23, 23, 23], white: [255, 255, 255], gray: [82, 82, 82] }
176
+ const luminance = (rgb: MediaPixel) =>
177
+ rgb
178
+ .map((v) => v / 255)
179
+ .map((v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4))
180
+ .reduce((sum, v, i) => sum + v * ([0.2126, 0.7152, 0.0722][i] ?? 0), 0)
181
+ export function mediaContrast(a: MediaPixel, b: MediaPixel): number {
182
+ const x = luminance(a),
183
+ y = luminance(b)
184
+ return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05)
185
+ }
186
+ /** Conservative local contrast, including the final tint. Blur alone never counts as contrast protection. */
187
+ export function resolveMediaText(
188
+ pixels: readonly MediaPixel[],
189
+ appearance: MediaTextAppearance = {},
190
+ _secondary = false,
191
+ ) {
192
+ const samples = pixels.length ? pixels : [[0, 0, 0] as const, [255, 255, 255] as const]
193
+ const lightness = samples.map(luminance).sort((a, b) => a - b)
194
+ const median = lightness[Math.floor(lightness.length / 2)] ?? 0.5
195
+ const color: Tone =
196
+ appearance.color && appearance.color !== 'auto' ? appearance.color : median >= 0.35 ? 'dark' : 'white'
197
+ const score = Math.min(...samples.map((pixel) => mediaContrast(inks[color], pixel)))
198
+ const range =
199
+ (lightness[Math.floor(lightness.length * 0.9)] ?? median) -
200
+ (lightness[Math.floor(lightness.length * 0.1)] ?? median)
201
+ const busy = range > 0.25
202
+ const requested = appearance.background && appearance.background !== 'auto' ? appearance.background : undefined
203
+ const background = requested ?? (score >= 4.5 && !busy ? 'none' : 'gradient')
204
+ const tint = color === 'white' ? 0 : 255
205
+ const target = busy ? 7 : 4.5
206
+ let opacity = 0
207
+ if (background !== 'none') {
208
+ while (
209
+ opacity < 1 &&
210
+ samples.some(
211
+ (pixel) =>
212
+ mediaContrast(
213
+ inks[color],
214
+ pixel.map((value) => value * (1 - opacity) + tint * opacity) as [number, number, number],
215
+ ) < target,
216
+ )
217
+ )
218
+ opacity = Math.min(1, opacity + 0.01)
219
+ if (busy && color !== 'white') opacity = Math.max(0.8, opacity)
220
+ }
221
+ return { color, background, opacity, tint }
222
+ }
223
+
224
+ const toneClass: Record<Tone, string> = { dark: 'text-neutral-900', white: 'text-white', gray: 'text-neutral-600' }
225
+
226
+ /** Used inside the existing media panel. Each text region measures its own visible image crop. */
227
+ export function MediaReadableText({
228
+ children,
229
+ appearance,
230
+ secondary = false,
231
+ maxWidth,
232
+ }: {
233
+ children: ReactNode
234
+ appearance?: MediaTextAppearance
235
+ secondary?: boolean
236
+ maxWidth?: number
237
+ }) {
238
+ const ref = useRef<HTMLSpanElement>(null)
239
+ const [pixels, setPixels] = useState<MediaPixel[]>([])
240
+ const [panelBox, setPanelBox] = useState<{ left: number; top: number; width: number; height: number } | null>(null)
241
+ const [analysisError, setAnalysisError] = useState<string | null>(null)
242
+ useEffect(() => {
243
+ const text = ref.current,
244
+ panel = text?.closest<HTMLElement>('[data-media-readability]')
245
+ if (!text || !panel) return
246
+ let frame = 0
247
+ const measure = () => {
248
+ cancelAnimationFrame(frame)
249
+ frame = requestAnimationFrame(async () => {
250
+ const image = panel.querySelector<HTMLImageElement>('img')
251
+ if (!image?.complete || !image.naturalWidth) {
252
+ setPixels([])
253
+ return
254
+ }
255
+ const box = text.getBoundingClientRect(),
256
+ rect = image.getBoundingClientRect()
257
+ const bounds = panel.getBoundingClientRect()
258
+ setPanelBox({
259
+ left: bounds.left - box.left,
260
+ top: bounds.top - box.top,
261
+ width: bounds.width,
262
+ height: bounds.height,
263
+ })
264
+ if (!box.width || !box.height || !rect.width || !rect.height) return
265
+ const imageStyle = getComputedStyle(image)
266
+ const scale =
267
+ imageStyle.objectFit === 'contain'
268
+ ? Math.min(rect.width / image.naturalWidth, rect.height / image.naturalHeight)
269
+ : Math.max(rect.width / image.naturalWidth, rect.height / image.naturalHeight)
270
+ const position = imageStyle.objectPosition
271
+ .split(' ')
272
+ .map((part) => (part.endsWith('%') ? parseFloat(part) / 100 : 0.5))
273
+ const sx = (image.naturalWidth - rect.width / scale) * (position[0] ?? 0.5) + (box.left - rect.left) / scale
274
+ const sy = (image.naturalHeight - rect.height / scale) * (position[1] ?? 0.5) + (box.top - rect.top) / scale
275
+ const canvas = document.createElement('canvas')
276
+ canvas.width = 32
277
+ canvas.height = 16
278
+ const ctx = canvas.getContext('2d', { willReadFrequently: true })
279
+ if (!ctx) return
280
+ try {
281
+ ctx.fillStyle = getComputedStyle(panel).backgroundColor
282
+ ctx.fillRect(0, 0, 32, 16)
283
+ ctx.globalCompositeOperation = image.closest('.mix-blend-multiply') ? 'multiply' : 'source-over'
284
+ const readable = await readableMediaImage(image)
285
+ if (!text.isConnected) return
286
+ ctx.drawImage(readable, sx, sy, box.width / scale, box.height / scale, 0, 0, 32, 16)
287
+ const data = ctx.getImageData(0, 0, 32, 16).data,
288
+ next: MediaPixel[] = []
289
+ for (let i = 0; i < data.length; i += 4) next.push([data[i] ?? 255, data[i + 1] ?? 255, data[i + 2] ?? 255])
290
+ setAnalysisError(null)
291
+ setPixels(next)
292
+ } catch (error) {
293
+ setAnalysisError(error instanceof Error ? error.message : 'Unavailable')
294
+ setPixels([
295
+ [0, 0, 0],
296
+ [255, 255, 255],
297
+ ])
298
+ }
299
+ })
300
+ }
301
+ const resize = new ResizeObserver(measure)
302
+ resize.observe(panel)
303
+ resize.observe(text)
304
+ const mutation = new MutationObserver(measure)
305
+ mutation.observe(panel, { childList: true, subtree: true, attributes: true, attributeFilter: ['src', 'class'] })
306
+ panel.addEventListener('load', measure, true)
307
+ panel.addEventListener('error', measure, true)
308
+ measure()
309
+ return () => {
310
+ cancelAnimationFrame(frame)
311
+ resize.disconnect()
312
+ mutation.disconnect()
313
+ panel.removeEventListener('load', measure, true)
314
+ panel.removeEventListener('error', measure, true)
315
+ }
316
+ }, [children])
317
+ const resolved = resolveMediaText(pixels, appearance, secondary)
318
+ const tint = `rgba(${resolved.tint},${resolved.tint},${resolved.tint},${resolved.opacity})`
319
+ const effectStyle: CSSProperties = panelBox
320
+ ? {
321
+ left: panelBox.left,
322
+ top: panelBox.top,
323
+ width: panelBox.width,
324
+ height: panelBox.height,
325
+ background: tint,
326
+ maskImage: `radial-gradient(ellipse 110% 95% at left ${secondary ? 'bottom' : 'top'},black 0%,black 40%,rgba(0,0,0,.8) 55%,rgba(0,0,0,.35) 75%,transparent 100%)`,
327
+ }
328
+ : {
329
+ inset: 'calc(var(--spacing) * -12)',
330
+ background: `radial-gradient(ellipse at center,${tint} 0%,${tint} 35%,transparent 75%)`,
331
+ }
332
+
333
+ return (
334
+ <span
335
+ ref={ref}
336
+ className={`relative isolate block w-fit max-w-full ${toneClass[resolved.color]}`}
337
+ style={{ maxWidth: maxWidth ? `${maxWidth * 100}%` : undefined, textShadow: 'none' }}
338
+ data-media-analysis-error={analysisError ?? undefined}
339
+ data-media-text-color={resolved.color}
340
+ data-media-text-background={resolved.background}
341
+ >
342
+ {resolved.background !== 'none' ? (
343
+ <span
344
+ aria-hidden="true"
345
+ className={`pointer-events-none absolute -z-10 ${panelBox ? '' : ''} ${resolved.background === 'blur' ? 'backdrop-blur-sm' : ''}`}
346
+ style={effectStyle}
347
+ />
348
+ ) : null}
349
+ {children}
350
+ </span>
351
+ )
352
+ }
353
+
354
+ // A CORS-enabled copy keeps image analysis separate from the visible preview.
355
+ const readableMediaImages = new WeakMap<HTMLImageElement, { src: string; image: Promise<HTMLImageElement> }>()
356
+ function readableMediaImage(source: HTMLImageElement): Promise<HTMLImageElement> {
357
+ const src = source.currentSrc || source.src
358
+ const cached = readableMediaImages.get(source)
359
+ if (cached?.src === src) return cached.image
360
+ const image = new Promise<HTMLImageElement>((resolve, reject) => {
361
+ const copy = new Image()
362
+ copy.crossOrigin = 'anonymous'
363
+ copy.onload = () => resolve(copy)
364
+ copy.onerror = () => reject(new Error('Media analysis unavailable'))
365
+ copy.src = src
366
+ })
367
+ readableMediaImages.set(source, { src, image })
368
+ return image
58
369
  }
@@ -0,0 +1,18 @@
1
+ import { MediaCarousel, MediaPanelCard, MediaPreviewScene } from './media-collection'
2
+ const items = [
3
+ { id: 'a', title: 'Artwork', preview: <div className="h-full w-full bg-brand-green" /> },
4
+ { id: 'b', title: 'Second artwork', preview: <div className="h-full w-full bg-accent-yellow" /> },
5
+ ]
6
+ export const examples = {
7
+ default: () => <MediaCarousel items={items} label="Artwork" previousLabel="Previous" nextLabel="Next" />,
8
+ variants: () => <MediaPanelCard title="Artwork" caption="Caption" preview={items[0]!.preview} onOpen={() => {}} />,
9
+ states: () => (
10
+ <MediaPreviewScene>
11
+ <MediaCarousel items={items.slice(0, 1)} label="Single artwork" previousLabel="Previous" nextLabel="Next" />
12
+ </MediaPreviewScene>
13
+ ),
14
+ }
15
+ export const meta = {
16
+ category: 'Composite',
17
+ description: 'Asset panels, contained carousel and lightweight media detail.',
18
+ }
@@ -0,0 +1,206 @@
1
+ import { useState, type ReactNode } from 'react'
2
+ import { Button as RACButton } from 'react-aria-components'
3
+ import { Button } from './button'
4
+ import { MediaReadableText, type MediaTextAppearance } from './media-asset-panel'
5
+ import { IslandToolbar, IslandToolbarButton } from './island-toolbar'
6
+ import { ModalOverlay, ModalSurface, ModalDialog } from './dialog'
7
+ import { uic } from '../utils/uic'
8
+
9
+ export const MediaPreviewScene = uic('div', {
10
+ displayName: 'MediaPreviewScene',
11
+ baseClass: 'relative grid min-h-0 min-w-0 place-items-center overflow-hidden p-5',
12
+ style: {
13
+ background:
14
+ 'radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--color-surface) 8%, transparent) 0, transparent 42%), color-mix(in srgb, var(--color-fg) 84%, var(--color-surface))',
15
+ },
16
+ })
17
+ const Panel = uic(RACButton, {
18
+ displayName: 'MediaPanelCard',
19
+ baseClass:
20
+ 'relative isolate flex min-h-60 w-full cursor-pointer flex-col justify-between overflow-hidden rounded-lg bg-surface-card p-5 text-start outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring',
21
+ })
22
+ /** Asset-dashboard panel composition. Text and crop are measured together. */
23
+ export function MediaPanelCard({
24
+ title,
25
+ caption,
26
+ preview,
27
+ onOpen,
28
+ textAppearance,
29
+ }: {
30
+ title: string
31
+ caption?: string
32
+ textAppearance?: { title?: MediaTextAppearance; caption?: MediaTextAppearance }
33
+ preview: ReactNode
34
+ onOpen: () => void
35
+ }) {
36
+ return (
37
+ <Panel onPress={onOpen} aria-label={title} data-media-readability>
38
+ <div aria-hidden="true" className="absolute inset-0 -z-20">
39
+ {preview}
40
+ </div>
41
+ <MediaReadableText appearance={textAppearance?.title}>
42
+ <strong className="text-panel-heading font-medium">{title}</strong>
43
+ </MediaReadableText>
44
+ {caption ? (
45
+ <MediaReadableText secondary appearance={textAppearance?.caption}>
46
+ <span className="text-label font-normal">{caption}</span>
47
+ </MediaReadableText>
48
+ ) : null}
49
+ </Panel>
50
+ )
51
+ }
52
+ export interface MediaCarouselItem {
53
+ id: string
54
+ title: string
55
+ caption?: string
56
+ preview: ReactNode
57
+ }
58
+ export function MediaCarousel({
59
+ items,
60
+ label,
61
+ previousLabel,
62
+ nextLabel,
63
+ onOpen,
64
+ }: {
65
+ items: readonly MediaCarouselItem[]
66
+ label: string
67
+ previousLabel: string
68
+ nextLabel: string
69
+ onOpen?: (index: number) => void
70
+ }) {
71
+ const [picked, setPicked] = useState(0),
72
+ index = Math.min(picked, Math.max(0, items.length - 1)),
73
+ item = items[index]
74
+ if (!item) return null
75
+ const go = (next: number) => setPicked(Math.max(0, Math.min(items.length - 1, next)))
76
+ return (
77
+ <div
78
+ role="group"
79
+ aria-label={label}
80
+ tabIndex={0}
81
+ className="relative overflow-hidden rounded-lg bg-surface-muted outline-none focus-visible:ring-2 focus-visible:ring-ring"
82
+ onKeyDown={(event) => {
83
+ if (event.key === 'ArrowLeft') {
84
+ event.preventDefault()
85
+ go(index - 1)
86
+ }
87
+ if (event.key === 'ArrowRight') {
88
+ event.preventDefault()
89
+ go(index + 1)
90
+ }
91
+ }}
92
+ >
93
+ <div className="grid aspect-3/2 min-w-0 place-items-center px-12 py-8">
94
+ {onOpen ? (
95
+ <Button
96
+ variant="ghost"
97
+ aria-label={item.title}
98
+ onPress={() => onOpen(index)}
99
+ className="h-full min-h-0 w-full p-0 hover:bg-transparent"
100
+ >
101
+ {item.preview}
102
+ </Button>
103
+ ) : (
104
+ item.preview
105
+ )}
106
+ </div>
107
+ <div className="pointer-events-none absolute bottom-5 start-5 max-w-3/4 rounded-lg bg-surface p-4 text-fg">
108
+ <p className="m-0 text-label font-normal text-fg-muted">{item.caption ?? label}</p>
109
+ <p className="m-0 mt-2 text-small font-medium">{item.title}</p>
110
+ <p className="m-0 mt-2 text-label text-fg-muted" aria-live="polite">
111
+ {index + 1} / {items.length}
112
+ </p>
113
+ </div>
114
+ {index > 0 ? (
115
+ <Button
116
+ variant="ghost"
117
+ aria-label={previousLabel}
118
+ onPress={() => go(index - 1)}
119
+ className="absolute start-3 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full bg-surface p-0 text-fg-muted shadow-md"
120
+ >
121
+ ‹
122
+ </Button>
123
+ ) : null}
124
+ {index < items.length - 1 ? (
125
+ <Button
126
+ variant="ghost"
127
+ aria-label={nextLabel}
128
+ onPress={() => go(index + 1)}
129
+ className="absolute end-3 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full bg-surface p-0 text-fg-muted shadow-md"
130
+ >
131
+ ›
132
+ </Button>
133
+ ) : null}
134
+ </div>
135
+ )
136
+ }
137
+ export function MediaLightbox({
138
+ isOpen,
139
+ onOpenChange,
140
+ title,
141
+ caption,
142
+ preview,
143
+ index,
144
+ total,
145
+ onPrevious,
146
+ onNext,
147
+ previousLabel,
148
+ nextLabel,
149
+ closeLabel,
150
+ }: {
151
+ isOpen: boolean
152
+ onOpenChange: (open: boolean) => void
153
+ title: string
154
+ caption?: string
155
+ preview: ReactNode
156
+ index: number
157
+ total: number
158
+ onPrevious: () => void
159
+ onNext: () => void
160
+ previousLabel: string
161
+ nextLabel: string
162
+ closeLabel: string
163
+ }) {
164
+ return (
165
+ <ModalOverlay isOpen={isOpen} onOpenChange={onOpenChange} isDismissable>
166
+ <ModalSurface className="h-[90dvh] w-24/25 max-w-360 overflow-hidden p-0">
167
+ <ModalDialog aria-label={title} className="relative h-full outline-none">
168
+ <MediaPreviewScene className="h-full px-6 pb-32 pt-6">{preview}</MediaPreviewScene>
169
+ <div className="absolute bottom-6 start-6 max-w-3/4 rounded-lg bg-surface p-4 text-fg">
170
+ <p className="m-0 text-label text-fg-muted">
171
+ {index + 1} / {total}
172
+ </p>
173
+ <p className="m-0 mt-2 text-panel-heading font-medium">{title}</p>
174
+ {caption ? <p className="m-0 mt-2 text-label">{caption}</p> : null}
175
+ </div>
176
+ <div className="absolute end-6 top-6 flex items-center gap-2">
177
+ {total > 1 ? (
178
+ <IslandToolbar aria-label={title}>
179
+ <IslandToolbarButton
180
+ label={previousLabel}
181
+ icon={<span>‹</span>}
182
+ isDisabled={index === 0}
183
+ onPress={onPrevious}
184
+ />
185
+ <IslandToolbarButton
186
+ label={nextLabel}
187
+ icon={<span>›</span>}
188
+ isDisabled={index === total - 1}
189
+ onPress={onNext}
190
+ />
191
+ </IslandToolbar>
192
+ ) : null}
193
+ <Button
194
+ variant="ghost"
195
+ className="h-9 w-9 rounded-full bg-surface-inverted p-0 text-fg-inverted"
196
+ aria-label={closeLabel}
197
+ onPress={() => onOpenChange(false)}
198
+ >
199
+ ×
200
+ </Button>
201
+ </div>
202
+ </ModalDialog>
203
+ </ModalSurface>
204
+ </ModalOverlay>
205
+ )
206
+ }