@andamento/react 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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx","../src/TileLayout.tsx","../src/useTileLayout.ts","../src/SvgTileLayout.tsx","../src/useImageFill.ts","../src/useImageAspects.ts","../src/useImageFocus.ts"],"sourcesContent":["/**\n * React bindings: `<TileLayout>` (any children, clipped to the tiles), `<SvgTileLayout>` and hooks.\n *\n * @module @andamento/react\n */\nexport { TileLayout, coverStyle } from \"./TileLayout\";\nexport type { CellState, TileLayoutProps } from \"./TileLayout\";\nexport { SvgTileLayout, SvgCellImage } from \"./SvgTileLayout\";\nexport type { SvgTileLayoutProps, SvgCellImageProps, SvgCellRenderContext } from \"./SvgTileLayout\";\nexport { useFitCount, useTileLayout } from \"./useTileLayout\";\nexport { useImageFill } from \"./useImageFill\";\nexport { useImageAspects } from \"./useImageAspects\";\nexport { useImageFocus } from \"./useImageFocus\";\nexport { cellFromPointer } from \"@andamento/dom\";\nexport type { PerCell, PointerLike } from \"@andamento/dom\";\nexport type { FitProp } from \"./useTileLayout\";\nexport type { Cell, ContentCells, ContentPlacement, Focus, Layout, LayoutOptions, MatchOptions, SafeAreaOptions, HitOptions } from \"@andamento/core\";\nexport { defaultPalette, neutralPalette } from \"@andamento/svg\";\nexport type { FillSource, ReliefOptions } from \"@andamento/svg\";\n","import {\n Children,\n cloneElement,\n isValidElement,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type KeyboardEvent,\n type CSSProperties,\n type HTMLAttributes,\n type Key,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { cellsInRect, type Cell, type ContentCells, type ContentPlacement, type Focus, type Layout, type LayoutOptions, type Rect } from \"@andamento/core\";\nimport {\n backdropStyle,\n backgroundStyle,\n containerStyle,\n coverStyle as sharedCoverStyle,\n frameBuilder,\n keyAction,\n overlayStyle,\n resolvePerCell as resolve,\n ringStrokes,\n safeBoxStyle,\n sameRect,\n shadowShape,\n tileSheet,\n tileStyle,\n tileViewBox,\n viewRect,\n watchView,\n type CellState,\n type SafeAreaProp,\n type PerCell,\n} from \"@andamento/dom\";\nimport type { FillSource, ReliefOptions } from \"@andamento/svg\";\nimport { useResolvedLayout, type FitProp } from \"./useTileLayout\";\n\nexport type { CellState };\n\nconst isEmpty = (n: ReactNode) => n == null || n === false || n === true || n === \"\";\nconst css = (s: object) => s as CSSProperties;\n\nexport interface TileLayoutProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Layout options; or pass a precomputed `layout` instead. */\n options?: LayoutOptions;\n layout?: Layout;\n /**\n * Any React content. Each top-level child fills one tile, in reading order\n * (top-to-bottom, left-to-right), and is clipped to the tile's shape.\n * Extra children beyond the number of tiles are not rendered.\n */\n children?: ReactNode;\n /**\n * Alternative to `children`: compute each tile's content from its cell. Takes precedence.\n * `slot` numbers the cells allowed by `contentCells` in reading order (-1 for the rest).\n */\n renderCell?: (cell: Cell, state: { slot: number }) => ReactNode;\n /**\n * Which tiles may hold children: \"all\" (default), \"whole\" (only tiles not cut by the\n * region outline), or a test per cell. The others are left empty.\n */\n contentCells?: ContentCells;\n /**\n * Where children go when there are fewer than tiles: \"reading\" (default; the first\n * tiles in reading order), \"center\" (the middle of the region) or \"spread\" (evenly\n * over it). Children always run in reading order across the tiles chosen.\n */\n placement?: ContentPlacement;\n /**\n * Width / height of each child, in order. When given, each child goes in a tile of\n * similar shape, so `object-fit: cover` crops as little as possible (landscape photos in\n * wide tiles, portraits in tall ones); see `matchSlots`. Featured tiles still take the\n * first children. Missing entries count as square. Ignored with `renderCell`.\n */\n aspects?: readonly number[];\n /**\n * Keep content out of the tiles' clipped corners: each tile's content goes in a box at\n * the tile's safe area (see `safeArea`), the largest rectangle that fits inside its shape,\n * instead of filling the tile's bounding box. Useful for text in triangles or hexagons.\n * With `aspects`, each child's box has the child's shape, so it shows whole and uncropped.\n * The box has `data-safe-area`; style its contents to fill it. Tiles show `fill` around\n * their content. For tiles an `edges: \"window\"` layout cuts, `true` or \"tile\" fits the\n * whole tile (content near the edge is partly hidden, like the tile) and \"visible\" the\n * part that shows.\n */\n safeArea?: SafeAreaProp;\n /** With `aspects`: \"shape\" also picks which tiles hold children by their shape, ignoring `placement`. */\n choose?: \"placement\" | \"shape\";\n /**\n * Focal point of each child (fractions of its width and height; see `estimateFocus`): what\n * a photo keeps in view as its tile crops it. Each tile sets `--andamento-object-position`,\n * which `coverStyle` uses as `object-position`; exact when the photo's shape is known (`aspects`, or the focus's `aspect`).\n */\n focalPoints?: readonly (Focus | undefined)[];\n /**\n * How many tiles each child spans (1 for an ordinary child; rounded): heavier childs get a\n * featured tile of that many merged tiles, where they fall in reading order (see\n * `weightedLayout`). With `fit`, the tiles are sized to fit everything. Needs `options`.\n */\n weights?: readonly number[];\n /**\n * Color of empty tiles: a color, a palette (neighboring tiles get different entries),\n * or a function per cell. Defaults to `neutralPalette`; use \"transparent\" for none.\n */\n fill?: FillSource;\n /**\n * Size the tiles to the children: scales the pattern so there are about as many tiles\n * (counted by `contentCells`) as children. `true`/\"atLeast\" makes sure every child gets\n * a tile; \"nearest\" gets as close as possible. Ignored with `layout` or `renderCell`.\n */\n fit?: FitProp;\n /**\n * One picture across all the tiles: rendered in every tile, sized and positioned to the\n * whole layout, so each tile shows its own piece. Use an element that fills its box,\n * e.g. `<img src=… style={coverStyle} />`. It sits behind the tile's content, and empty\n * tiles show it instead of `fill`. (Each tile gets its own copy, so a video would play\n * out of sync; images are loaded once.)\n */\n backdrop?: ReactNode;\n /**\n * Raised tiles: a bevel round each tile, lit from one side and drawn over its content,\n * and optionally a soft shadow each tile casts into the grout (set `shadow`). `true` for\n * the defaults. With `gap` as the grout width and `background` as its color or texture,\n * it looks like a tiled surface. See `ReliefOptions`.\n */\n relief?: boolean | ReliefOptions;\n /**\n * Keyboard navigation: tiles with content become focusable as one tab stop (roving\n * tabindex). Arrow keys move to the nearest tile in that direction, whatever the tiling;\n * Home and End go to the first and last. The focused tile shows `focusRing`.\n */\n navigable?: boolean;\n /**\n * Called when a tile with content is activated: clicked, or Enter or Space while it has\n * focus (with `navigable`).\n */\n onCellActivate?: (cell: Cell, state: CellState) => void;\n /** Accessible name for each tile (its `aria-label`), e.g. a photo's description. */\n cellLabel?: PerCell<string | undefined>;\n /**\n * Color of the focus outline drawn inside the focused tile's shape (a CSS outline would be\n * clipped away), with a white inner line so it shows on any content. `false` for none,\n * if you style `[data-cell-id]:focus-visible` yourself. Defaults to \"#1a56db\".\n */\n focusRing?: string | false;\n /**\n * Animate changes: when the layout changes (a resize, another tiling, a new gap) or the\n * children do, tiles glide and morph into their new places and shapes, a child keeping\n * its tile as it moves; new tiles fade in and removed ones fade out. Pure CSS\n * transitions, skipped when the user prefers reduced motion. `true` for 400 ms, or\n * `{ duration, easing }`.\n */\n animate?: boolean | { duration?: number; easing?: string };\n /**\n * Mount only the tiles in view (plus `overscan` pixels round it, default 300), for\n * layouts with thousands of tiles. Tiles mount and unmount as the page or any scrolling\n * container scrolls, or the layout resizes. Keyboard navigation still reaches every\n * tile (the focused one stays mounted and is scrolled to), and list items carry\n * `aria-setsize` and `aria-posinset`. With `renderCell`, every cell `contentCells`\n * allows counts as having content. On the server no tiles are rendered.\n */\n virtualize?: boolean | { overscan?: number };\n /** Content for empty tiles. */\n fallback?: PerCell<ReactNode>;\n /** Class name for each tile wrapper (fixed or per cell). */\n cellClassName?: PerCell<string>;\n /** Extra style for each tile wrapper (fixed or per cell), e.g. a background color. */\n cellStyle?: PerCell<CSSProperties>;\n /** Color painted across the whole region, visible through the gaps. */\n background?: string;\n}\n\n/**\n * Renders a tiling as HTML: one absolutely positioned, `clip-path`-ed element per tile,\n * holding whatever you put in it (images, video, text, components). Everything is sized\n * in percentages, so the layout scales with the container's width.\n *\n * Each tile wrapper has `data-cell-id` and `data-index`, plus `data-empty` (no content)\n * and `data-boundary` (cut by the region outline) for styling.\n *\n * Clipping also applies to pointer events, so hover and clicks follow the tile shapes.\n */\nexport function TileLayout(props: TileLayoutProps) {\n const {\n options,\n layout: given,\n children,\n renderCell,\n contentCells,\n placement,\n aspects,\n choose,\n focalPoints,\n weights,\n safeArea,\n fill,\n fit,\n backdrop,\n relief,\n navigable,\n onCellActivate,\n cellLabel,\n focusRing = \"#1a56db\",\n animate,\n virtualize,\n fallback,\n cellClassName,\n cellStyle,\n background,\n style,\n role,\n onKeyDown,\n ...rest\n } = props;\n const uid = \"andamento\" + useId().replace(/:/g, \"\");\n const items = renderCell ? [] : Children.toArray(children);\n const layout = useResolvedLayout(\"TileLayout\", options, given, {\n fit: !renderCell && fit,\n count: items.length,\n cells: contentCells,\n weights: renderCell ? undefined : weights,\n placement,\n });\n const { bounds } = layout;\n // Slots, fills and bevels, reused from the last render where nothing they depend on changed.\n const buildFrame = useRef<ReturnType<typeof frameBuilder>>();\n buildFrame.current ??= frameBuilder();\n const frame = buildFrame.current(layout, {\n count: renderCell ? Infinity : items.length,\n aspects: renderCell ? undefined : aspects,\n contentCells,\n placement,\n choose,\n fill,\n relief,\n animate,\n });\n const { slots, anim } = frame;\n\n // Key by child where possible, so a child keeps its state (video position, inputs,\n // animations) when the layout changes underneath it.\n const keyOf = (i: number): Key => {\n const slot = slots[i]!;\n if (!renderCell && slot >= 0) {\n const child = items[slot];\n return isValidElement(child) && child.key != null ? `child:${child.key}` : `child:${slot}`;\n }\n return `cell:${layout.cells[i]!.id}`;\n };\n // What a tile holds.\n const makeEntry = (i: number) => {\n const cell = layout.cells[i]!;\n const slot = slots[i]!;\n let content: ReactNode = null;\n if (renderCell) content = renderCell(cell, { slot });\n else if (slot >= 0) content = items[slot];\n const empty = isEmpty(content);\n const state: CellState = { empty, slot: empty && !renderCell ? -1 : slot };\n if (empty) content = resolve(fallback, cell, state);\n return { i, cell, content, key: keyOf(i), empty, state };\n };\n\n // Virtualization: the part of the layout in view, in layout units (null until measured).\n const virtual = !!virtualize;\n const overscan = Math.max(0, (typeof virtualize === \"object\" ? virtualize.overscan : undefined) ?? 300);\n const container = useRef<HTMLDivElement>(null);\n const [view, setView] = useState<Rect | null>(null);\n // Without virtualization, every tile's entry is worked out before rendering, so navigation\n // knows which have content. With it, only the tiles in view are; whether others have\n // content is judged without rendering them.\n const allEntries = virtual ? undefined : layout.cells.map((_, i) => makeEntry(i));\n const hasContent = (i: number) =>\n allEntries ? !allEntries[i]!.empty : renderCell ? slots[i]! >= 0 : slots[i]! >= 0 && !isEmpty(items[slots[i]!]);\n\n // Animation: enter / exit animations for tiles that come and go (the tiles' own\n // transitions are in their style).\n const mounted = useRef(false);\n const lastKeys = useRef(new Set<Key>());\n const entering = useRef(new Set<Key>());\n const lastTiles = useRef(new Map<Key, ReactElement>());\n const [exiting, setExiting] = useState(() => new Map<Key, ReactElement>());\n const timers = useRef(new Set<ReturnType<typeof setTimeout>>());\n\n // Roving tabindex: one tile is the tab stop; arrow keys move it.\n const focusable = new Set(navigable ? layout.cells.filter((c) => hasContent(c.index)).map((c) => c.id) : []);\n const [activeId, setActiveId] = useState<string>();\n const firstFocusable = layout.cells.find((c) => focusable.has(c.id))?.id;\n const active = activeId !== undefined && focusable.has(activeId) ? activeId : firstFocusable;\n const tiles = useRef(new Map<string, HTMLDivElement>());\n const pendingFocus = useRef<string>();\n const list = (role ?? \"list\") === \"list\";\n\n // The tiles to render: all of them, or those in view plus the tab stop (so Tab finds it).\n let entries: ReturnType<typeof makeEntry>[];\n if (allEntries) entries = allEntries;\n else {\n const shown = new Set(view && view.width >= 0 ? cellsInRect(layout, view).map((c) => c.index) : []);\n const activeCell = active !== undefined ? layout.cells.find((c) => c.id === active) : undefined;\n if (activeCell) shown.add(activeCell.index);\n entries = [...shown].sort((a, b) => a - b).map(makeEntry);\n }\n // List positions, as screen readers can't count tiles that aren't there.\n let positions: Map<number, number> | undefined;\n if (virtual) {\n positions = new Map();\n for (const c of layout.cells) if (hasContent(c.index)) positions.set(c.index, positions.size + 1);\n }\n\n // Animation bookkeeping uses every tile's key, so tiles scrolling in and out of view\n // don't count as coming and going.\n const allKeys = anim ? new Set(layout.cells.map((_, i) => keyOf(i))) : undefined;\n for (const e of entries) if (anim && mounted.current && !lastKeys.current.has(e.key)) entering.current.add(e.key);\n\n const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented || !navigable || e.altKey || e.ctrlKey || e.metaKey) return;\n // Only when a tile itself has focus, not an input or button inside it.\n const entry = entries.find((x) => tiles.current.get(x.cell.id) === e.target);\n if (!entry || !focusable.has(entry.cell.id)) return;\n const action = keyAction(layout, entry.cell, e.key, (c: Cell) => focusable.has(c.id), !!onCellActivate);\n if (!action) return;\n // Arrow keys at the edge are still ours: don't scroll the page.\n e.preventDefault();\n if (\"activate\" in action) onCellActivate!(entry.cell, entry.state);\n else if (\"move\" in action) {\n setActiveId(action.move.id);\n const el = tiles.current.get(action.move.id);\n // A tile out of view isn't mounted yet: focus it once it is.\n if (el) el.focus();\n else pendingFocus.current = action.move.id;\n }\n };\n\n const rendered = entries.map(({ i, cell, content, key, empty, state }) => {\n const slot = slots[i]!;\n const bevel = frame.bevel(i);\n const tile = tileStyle(frame, cell, {\n empty,\n safeArea,\n backdrop: backdrop != null,\n clickable: !!onCellActivate && !empty,\n focus: !renderCell && slot >= 0 ? focalPoints?.[slot] : undefined,\n aspect: !renderCell && slot >= 0 ? aspects?.[slot] : undefined,\n });\n // Tiles with nothing in them are decoration: hidden from assistive technology.\n const silent = empty && isEmpty(content);\n const canFocus = focusable.has(cell.id);\n const viewBox = tileViewBox(cell);\n return (\n <div\n key={key}\n ref={(el) => {\n if (el) tiles.current.set(cell.id, el);\n else tiles.current.delete(cell.id);\n }}\n role={silent ? undefined : list ? \"listitem\" : undefined}\n aria-hidden={silent ? true : undefined}\n aria-label={silent ? undefined : resolve(cellLabel, cell, state)}\n aria-setsize={positions && list && !silent ? positions.size : undefined}\n aria-posinset={positions && list && !silent ? positions.get(i) : undefined}\n tabIndex={canFocus ? (cell.id === active ? 0 : -1) : undefined}\n onFocus={canFocus ? (e) => e.target === e.currentTarget && setActiveId(cell.id) : undefined}\n onClick={onCellActivate && !empty ? () => onCellActivate(cell, state) : undefined}\n className={resolve(cellClassName, cell, state)}\n data-cell-id={cell.id}\n data-index={cell.index}\n data-empty={empty ? \"\" : undefined}\n data-boundary={cell.boundary ? \"\" : undefined}\n data-entering={entering.current.has(key) ? \"\" : undefined}\n style={{ ...css(tile), ...resolve(cellStyle, cell, state) }}\n >\n {backdrop != null && (\n // z-index -1 puts it behind the content but inside the tile: the tile's\n // clip-path makes it a stacking context.\n <div aria-hidden style={css(backdropStyle(frame, cell))}>\n {backdrop}\n </div>\n )}\n {safeArea && content != null && !isEmpty(content) ? (\n <div data-safe-area=\"\" style={css(safeBoxStyle(frame, cell, !renderCell && !empty && aspects ? (aspects[slot] ?? 1) : undefined, safeArea))}>\n {content}\n </div>\n ) : (\n content\n )}\n {bevel && bevel.length > 0 && (\n // Over the content; the tile's box is its bounding box, so map that to the viewBox.\n // When animating, the bevel is for the new shape, so it fades in as the tile arrives.\n <svg\n key={anim ? String(tile.clipPath) : undefined}\n aria-hidden\n data-bevel=\"\"\n data-late={anim ? \"\" : undefined}\n viewBox={viewBox}\n preserveAspectRatio=\"none\"\n style={css(overlayStyle)}\n >\n {bevel.map((p, k) => (\n <path key={k} d={p.d} fill={p.fill} fillOpacity={p.opacity} />\n ))}\n </svg>\n )}\n {canFocus && focusRing !== false && (\n // The tile's outline, stroked across its edge; the clip keeps the inner half.\n <svg aria-hidden data-focus-ring=\"\" viewBox={viewBox} preserveAspectRatio=\"none\" style={css(overlayStyle)}>\n {ringStrokes(frame, cell, focusRing).map((p, k) => (\n <path key={k} d={p.d} fill=\"none\" stroke={p.stroke} strokeWidth={p.width} vectorEffect=\"non-scaling-stroke\" />\n ))}\n </svg>\n )}\n </div>\n );\n });\n\n // After each commit: tiles that just went away stay a moment to fade out.\n useIsomorphicLayoutEffect(() => {\n const current = new Map<Key, ReactElement>(rendered.map((el) => [el.key!, el]));\n const present = allKeys ?? current;\n if (anim && mounted.current) {\n const gone = [...lastTiles.current].filter(([k]) => !present.has(k));\n if (gone.length) {\n setExiting((prev) => new Map([...prev, ...gone]));\n const timer = setTimeout(() => {\n timers.current.delete(timer);\n setExiting((prev) => {\n const next = new Map(prev);\n for (const [k, el] of gone) if (next.get(k) === el) next.delete(k);\n return next;\n });\n }, anim.duration);\n timers.current.add(timer);\n }\n }\n for (const k of entering.current) if (!present.has(k)) entering.current.delete(k);\n lastKeys.current = new Set(present.keys());\n lastTiles.current = current;\n mounted.current = true;\n if (pendingFocus.current) {\n const el = tiles.current.get(pendingFocus.current);\n if (el) {\n pendingFocus.current = undefined;\n el.focus();\n }\n }\n });\n\n // Virtualization: measure what's in view, again on scroll (of the page or any container)\n // and resize, at most once a frame.\n useIsomorphicLayoutEffect(() => {\n if (!virtual) return;\n const el = container.current;\n if (!el) return;\n return watchView(el, () => {\n const next = viewRect(el, layout, overscan);\n setView((v) => (sameRect(v ?? undefined, next) ? v : next));\n });\n }, [virtual, layout, overscan]);\n useEffect(() => {\n const set = timers.current;\n return () => set.forEach(clearTimeout);\n }, []);\n const leaving = anim\n ? [...exiting].filter(([k]) => !lastKeys.current.has(k) && !rendered.some((el) => el.key === k))\n : [];\n\n const sheet = tileSheet({ focusRing: !!navigable && focusRing !== false, anim });\n const shadow = shadowShape(frame, entries.map((e) => e.cell));\n return (\n <div\n data-andamento=\"\"\n ref={container}\n role={role ?? \"list\"}\n {...rest}\n onKeyDown={handleKeyDown}\n style={{ ...css(containerStyle(layout)), ...style }}\n >\n {sheet && <style>{sheet}</style>}\n {background && <div aria-hidden style={css(backgroundStyle(frame, background))} />}\n {shadow && (\n <svg aria-hidden data-andamento-shadow=\"\" viewBox={shadow.viewBox} preserveAspectRatio=\"none\" style={css(shadow.style)}>\n <filter id={`${uid}-shadow`} x=\"-10%\" y=\"-10%\" width=\"120%\" height=\"120%\">\n <feGaussianBlur stdDeviation={shadow.blur} />\n </filter>\n <path d={shadow.d} fillRule=\"evenodd\" transform={shadow.transform} fill=\"#000\" fillOpacity={shadow.opacity} filter={`url(#${uid}-shadow)`} />\n </svg>\n )}\n {rendered}\n {leaving.map(([k, el]) =>\n // Fades out through the [data-exiting] rule in the style sheet.\n cloneElement(el as ReactElement<Record<string, unknown>>, {\n key: k,\n ref: null,\n role: undefined,\n tabIndex: undefined,\n onClick: undefined,\n onFocus: undefined,\n \"aria-hidden\": true,\n \"data-entering\": undefined,\n \"data-exiting\": \"\",\n }),\n )}\n </div>\n );\n}\n\nconst useIsomorphicLayoutEffect = typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\n/** Style that makes an <img> or <video> cover its tile, like `object-fit: cover`. */\nexport const coverStyle: CSSProperties = css(sharedCoverStyle);\n","import { useMemo, useRef } from \"react\";\nimport { createLayout, fitCount, type ContentCells, type FitOptions, type Layout, type LayoutOptions } from \"@andamento/core\";\nimport { layoutResolver, type FitProp, type LayoutNeeds } from \"@andamento/dom\";\n\n/**\n * Compute a layout, recomputing only when the (serializable) options change.\n * Inline object literals are fine: options are compared by value.\n */\nexport function useTileLayout(options: LayoutOptions): Layout {\n const key = JSON.stringify(options);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => createLayout(options), [key]);\n}\n\n/**\n * Compute a layout whose tiles are sized to give about `count` usable cells (see\n * `fitCount` in @andamento/core). Options are compared by value; a `cells` function by\n * identity.\n */\nexport function useFitCount(options: LayoutOptions, count: number, fit: FitOptions = {}): Layout {\n const key = JSON.stringify(options);\n const { cells, mode } = fit;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => fitCount(options, count, { cells, mode }).layout, [key, count, cells, mode]);\n}\n\nexport type { FitProp };\n\n/**\n * Use `layout` if given, otherwise compute one from `options` (compared by value), fitted to\n * `count` items when `fit` is set.\n */\nexport function useResolvedLayout(\n component: string,\n options?: LayoutOptions,\n layout?: Layout,\n fit?: LayoutNeeds,\n): Layout {\n const resolver = useRef<ReturnType<typeof layoutResolver>>();\n resolver.current ??= layoutResolver(`<${component}>`);\n return resolver.current(options, layout, fit);\n}\n","import { useId, useMemo, type ReactNode, type SVGProps } from \"react\";\nimport { cellShape, coverRect, safeArea, type Cell, type Focus, type ContentCells, type ContentPlacement, type Layout, type LayoutOptions, type Rect } from \"@andamento/core\";\nimport { cellA11y, cellPath, defaultBevel, regionPath, viewPath, reliefPaths, resolveCellStyles, shadowOffset, type FillSource, type ImageSource, type ReliefOptions } from \"@andamento/svg\";\nimport { useResolvedLayout, type FitProp } from \"./useTileLayout\";\n\nexport interface SvgCellRenderContext {\n /** `d` attribute of the cell outline. */\n path: string;\n /** Id of a <clipPath> with the cell's shape, already in the SVG. */\n clipPathId: string;\n /** Ready-made `clipPath` prop value: `url(#…)`. */\n clipPath: string;\n /** The fill/image the default renderer would have used. */\n fill: string;\n image?: string;\n /** Which item of `images` the cell shows (-1 if none or if `images` is a function). */\n slot: number;\n}\n\nexport interface SvgTileLayoutProps extends Omit<SVGProps<SVGSVGElement>, \"children\" | \"fill\" | \"stroke\" | \"strokeWidth\"> {\n /** Layout options; or pass a precomputed `layout` instead. */\n options?: LayoutOptions;\n layout?: Layout;\n images?: ImageSource;\n repeatImages?: boolean;\n /** Which cells may hold an image from the `images` array: \"all\" (default), \"whole\" or a test. */\n contentCells?: ContentCells;\n /** Where images go when there are fewer than cells: \"reading\" (default), \"center\" or \"spread\". */\n placement?: ContentPlacement;\n /** Width / height of each image, to put images in cells of similar shape (see `matchSlots`). */\n imageAspects?: readonly number[];\n /** With `imageAspects`: \"shape\" also picks which cells get images by their shape. */\n choose?: \"placement\" | \"shape\";\n /**\n * \"cover\" (default) fills each cell's bounding box, cropped to its shape; \"contain\" shows\n * each image whole inside the cell's safe area (see `safeArea`), at its `imageAspects` shape.\n */\n imageFit?: \"cover\" | \"contain\";\n /**\n * With `imageFit: \"contain\"`, for cells an `edges: \"window\"` layout cuts: fit the image in\n * the whole tile (\"tile\", the default) or in the part that shows (\"visible\").\n */\n containWithin?: \"tile\" | \"visible\";\n /**\n * Focal point of each image (by position; fractions of its width and height, see\n * `estimateFocus`), kept in view when \"cover\" crops it (see `coverRect`). Needs each image's\n * shape, from `imageAspects` or the focus's `aspect`.\n */\n imageFocus?: readonly (Focus | undefined)[];\n /**\n * How many tiles each image in `images` spans (1 for most): heavier images get featured\n * tiles where they fall in reading order (see `weightedLayout`). Needs `options`.\n */\n imageWeights?: readonly number[];\n /**\n * Size the tiles to the `images` array (counted by `contentCells`): `true`/\"atLeast\" or\n * \"nearest\". Ignored with `layout`, `repeatImages` or an `images` function.\n */\n fit?: FitProp;\n /** Cell color under (or instead of) images. Defaults to `defaultPalette`. */\n fill?: FillSource;\n stroke?: string;\n strokeWidth?: number;\n /** Color painted across the whole region, behind the cells. */\n background?: string;\n /**\n * One image across all the cells (a URL), cropped to cover the layout and clipped to the\n * cells. The default cell rendering then skips `fill`; per-cell `images` go on top.\n */\n backdrop?: string;\n /**\n * Raised tiles: a lit bevel over each cell, and optionally a shadow cast into the grout.\n * `true` for the defaults. See `ReliefOptions`. Drawn over `renderCell` content too.\n */\n relief?: boolean | ReliefOptions;\n /** Replace the default cell rendering with SVG content. Rendered inside a <g> per cell. */\n renderCell?: (cell: Cell, ctx: SvgCellRenderContext) => ReactNode;\n /** Accessible title. */\n title?: string;\n /** Text alternative per image in `images`: those cells become labeled images; the rest decoration. */\n imageAlts?: readonly string[];\n}\n\n/**\n * Renders a tiling as a single <svg>: colored cells, optionally with images clipped\n * to each cell. Use this when you need pure SVG (export, print, embedding in other SVG);\n * use <TileLayout> to put arbitrary HTML/React content in the tiles.\n */\nexport function SvgTileLayout(props: SvgTileLayoutProps) {\n const {\n options,\n layout: given,\n images,\n repeatImages,\n contentCells,\n placement,\n imageAspects,\n choose,\n imageFit,\n containWithin,\n imageFocus,\n imageWeights,\n fit,\n fill,\n stroke,\n strokeWidth = 1,\n background,\n backdrop,\n relief: reliefProp,\n renderCell,\n title,\n imageAlts,\n ...svgProps\n } = props;\n const fitTo = Array.isArray(images) && !repeatImages ? images.length : 0;\n const layout = useResolvedLayout(\"SvgTileLayout\", options, given, {\n fit,\n count: fitTo,\n cells: contentCells,\n weights: Array.isArray(images) ? imageWeights : undefined,\n placement,\n });\n const prefix = \"andamento\" + useId().replace(/:/g, \"\");\n const styles = useMemo(\n () => resolveCellStyles(layout, { images, repeatImages, fill, contentCells, placement, imageAspects, choose }),\n [layout, images, repeatImages, fill, contentCells, placement, imageAspects, choose],\n );\n const { x, y, width, height } = layout.bounds;\n const relief = reliefProp === true ? {} : reliefProp || undefined;\n const reliefKey = relief ? JSON.stringify(relief) : \"\";\n const bevels = useMemo(() => {\n if (!relief) return undefined;\n const bevel = relief.bevel ?? defaultBevel(layout);\n return bevel > 0 ? layout.cells.map((c) => reliefPaths(layout, c, relief, bevel)) : undefined;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [layout, reliefKey]);\n const cast = relief && shadowOffset(relief);\n\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox={`${x} ${y} ${width} ${height}`} role={imageAlts?.length ? \"group\" : title ? \"img\" : undefined} {...svgProps}>\n {title && <title>{title}</title>}\n {background && <path className=\"andamento-region\" d={regionPath(layout)} fill={background} fillRule=\"evenodd\" />}\n {layout.view && (\n <clipPath id={`${prefix}-view`}>\n <path d={viewPath(layout)} clipRule=\"evenodd\" />\n </clipPath>\n )}\n <g className={layout.view ? \"andamento-view\" : undefined} clipPath={layout.view ? `url(#${prefix}-view)` : undefined}>\n {backdrop && (\n <>\n <clipPath id={`${prefix}-backdrop`}>\n {layout.cells.map((cell) => (\n <path key={cell.id} d={cellPath(layout, cell)} clipRule=\"evenodd\" />\n ))}\n </clipPath>\n <image\n className=\"andamento-backdrop\"\n href={backdrop}\n x={x}\n y={y}\n width={width}\n height={height}\n preserveAspectRatio=\"xMidYMid slice\"\n clipPath={`url(#${prefix}-backdrop)`}\n />\n </>\n )}\n {cast && (\n <g className=\"andamento-shadow\" clipPath={`url(#${prefix}-region)`}>\n <clipPath id={`${prefix}-region`}>\n <path d={regionPath(layout)} clipRule=\"evenodd\" />\n </clipPath>\n <filter id={`${prefix}-shadow`} x=\"-10%\" y=\"-10%\" width=\"120%\" height=\"120%\">\n <feGaussianBlur stdDeviation={cast.blur} />\n </filter>\n <path\n d={layout.cells.map((c) => cellPath(layout, c)).join(\"\")}\n fillRule=\"evenodd\"\n transform={`translate(${cast.dx} ${cast.dy})`}\n fill=\"#000\"\n fillOpacity={cast.opacity}\n filter={`url(#${prefix}-shadow)`}\n />\n </g>\n )}\n {layout.cells.map((cell, i) => {\n const d = cellPath(layout, cell);\n const clipPathId = `${prefix}-clip-${cell.index}`;\n const style = styles[i]!;\n const ctx: SvgCellRenderContext = { path: d, clipPathId, clipPath: `url(#${clipPathId})`, ...style };\n return (\n <g\n key={cell.id}\n className=\"andamento-cell\"\n data-cell-id={cell.id}\n data-index={cell.index}\n data-empty={style.image ? undefined : \"\"}\n data-boundary={cell.boundary ? \"\" : undefined}\n {...cellA11y(style, imageAlts)}\n >\n <clipPath id={clipPathId}>\n <path d={d} clipRule=\"evenodd\" />\n </clipPath>\n {renderCell ? renderCell(cell, ctx) : <DefaultCell\n cell={cell}\n ctx={ctx}\n noFill={!!backdrop}\n box={\n imageFit === \"contain\" && style.image\n ? safeArea(cell, layout, { aspect: imageAspects && style.slot >= 0 ? imageAspects[style.slot] : undefined, within: containWithin })\n : undefined\n }\n cover={(() => {\n const focus = imageFit !== \"contain\" && style.image && style.slot >= 0 ? (Array.isArray(images) ? imageFocus?.[style.slot % images.length] : undefined) : undefined;\n const aspect = focus ? (imageAspects?.[style.slot % imageAspects.length] ?? focus.aspect) : undefined;\n return focus && aspect ? coverRect(cell, layout, { aspect, focus }) : undefined;\n })()}\n />}\n {bevels?.[i]!.map((p, k) => <path key={k} className=\"andamento-bevel\" d={p.d} fill={p.fill} fillOpacity={p.opacity} />)}\n {stroke && <path d={d} fill=\"none\" stroke={stroke} strokeWidth={strokeWidth} />}\n </g>\n );\n })}\n </g>\n </svg>\n );\n}\n\nfunction DefaultCell({ cell, ctx, noFill, box, cover }: { cell: Cell; ctx: SvgCellRenderContext; noFill: boolean; box?: Rect; cover?: Rect }) {\n return (\n <>\n {!noFill && <path d={ctx.path} fill={ctx.fill} fillRule=\"evenodd\" />}\n {ctx.image && <SvgCellImage cell={cell} href={ctx.image} clipPath={ctx.clipPath} box={box} cover={cover} />}\n </>\n );\n}\n\nexport interface SvgCellImageProps extends Omit<SVGProps<SVGImageElement>, \"href\" | \"x\" | \"y\" | \"width\" | \"height\"> {\n cell: Cell;\n href: string;\n /** Pass `ctx.clipPath` from `renderCell`. */\n clipPath: string;\n /**\n * Draw the image whole inside this box (e.g. `safeArea(cell, layout)`) instead of\n * covering the cell.\n */\n box?: Rect;\n /** Cover this rectangle instead of the cell's box (e.g. `coverRect(cell, layout, { aspect, focus })`). */\n cover?: Rect;\n}\n\n/**\n * An SVG <image> that covers the cell (like CSS `object-fit: cover`), clipped to its shape;\n * or, with `box`, shown whole inside the box (like `object-fit: contain`).\n */\nexport function SvgCellImage({ cell, href, clipPath, box, cover, ...rest }: SvgCellImageProps) {\n const b = box ?? cover ?? cellShape(cell).bbox;\n return (\n <image\n href={href}\n x={b.x}\n y={b.y}\n width={b.width}\n height={b.height}\n preserveAspectRatio={box ? \"xMidYMid meet\" : \"xMidYMid slice\"}\n clipPath={clipPath}\n {...rest}\n />\n );\n}\n","import { useEffect, useMemo, useState } from \"react\";\nimport { imageFill, loadImagePixels, type CellFill, type ImageFillOptions, type Pixels } from \"@andamento/core\";\n\n/**\n * Load an image and color tiles from it (see `imageFill`): returns a fill to pass as\n * `fill`, or `undefined` while the image loads (or if it fails), so the default fill shows\n * meanwhile. `maxSize` caps the size the image is read at (default 256 px on the long side).\n */\nexport function useImageFill(src: string | undefined, options: ImageFillOptions & { maxSize?: number } = {}): CellFill | undefined {\n const { fit, palette, fallback, samples, maxSize = 256 } = options;\n const [pixels, setPixels] = useState<{ src: string; pixels: Pixels }>();\n useEffect(() => {\n if (!src) return;\n let live = true;\n loadImagePixels(src, maxSize).then(\n (p) => live && setPixels({ src, pixels: p }),\n (e) => console.warn(`useImageFill: ${(e as Error).message}`),\n );\n return () => {\n live = false;\n };\n }, [src, maxSize]);\n const paletteKey = palette?.join(\",\");\n return useMemo(\n () => (pixels && pixels.src === src ? imageFill(pixels.pixels, { fit, palette, fallback, samples }) : undefined),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [pixels, src, fit, paletteKey, fallback, samples],\n );\n}\n","import { useEffect, useState } from \"react\";\n\n/**\n * Measure images' aspect ratios (width / height) by loading them, for the `aspects` and\n * `imageAspects` props. Returns `undefined` until every image has loaded or failed (failed\n * ones count as square), so content isn't reshuffled image by image as they arrive.\n */\nexport function useImageAspects(srcs: readonly string[] | undefined): number[] | undefined {\n const key = srcs?.join(\"\\n\");\n const [result, setResult] = useState<{ key: string; aspects: number[] }>();\n useEffect(() => {\n if (!srcs || key === undefined || typeof Image === \"undefined\") return;\n let live = true;\n Promise.all(\n srcs.map(\n (src) =>\n new Promise<number>((resolve) => {\n const img = new Image();\n img.onload = () => resolve(img.naturalWidth && img.naturalHeight ? img.naturalWidth / img.naturalHeight : 1);\n img.onerror = () => resolve(1);\n img.src = src;\n }),\n ),\n ).then((aspects) => live && setResult({ key, aspects }));\n return () => {\n live = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key]);\n return result && result.key === key ? result.aspects : undefined;\n}\n","import { useEffect, useState } from \"react\";\nimport { estimateFocus, loadImagePixels, type Focus } from \"@andamento/core\";\n\n/**\n * Guess each image's focal point (see `estimateFocus`) by loading it, for the `focus` and\n * `imageFocus` props. Returns `undefined` until every image has been looked at; images that\n * fail to load (or that the browser won't let a canvas read) get the middle.\n */\nexport function useImageFocus(srcs: readonly string[] | undefined): Focus[] | undefined {\n const key = srcs?.join(\"\\n\");\n const [result, setResult] = useState<{ key: string; focus: Focus[] }>();\n useEffect(() => {\n if (!srcs || key === undefined || typeof document === \"undefined\") return;\n let live = true;\n Promise.all(\n srcs.map((src) =>\n loadImagePixels(src, 128)\n .then(estimateFocus)\n .catch(() => ({ x: 0.5, y: 0.5 })),\n ),\n ).then((focus) => live && setResult({ key, focus }));\n return () => {\n live = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key]);\n return result && result.key === key ? result.focus : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAeO;AACP,IAAAC,eAAyI;AACzI,IAAAC,cAqBO;;;ACtCP,mBAAgC;AAChC,kBAA4G;AAC5G,iBAA+D;AAMxD,SAAS,cAAc,SAAgC;AAC5D,QAAM,MAAM,KAAK,UAAU,OAAO;AAElC,aAAO,sBAAQ,UAAM,0BAAa,OAAO,GAAG,CAAC,GAAG,CAAC;AACnD;AAOO,SAAS,YAAY,SAAwB,OAAe,MAAkB,CAAC,GAAW;AAC/F,QAAM,MAAM,KAAK,UAAU,OAAO;AAClC,QAAM,EAAE,OAAO,KAAK,IAAI;AAExB,aAAO,sBAAQ,UAAM,sBAAS,SAAS,OAAO,EAAE,OAAO,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,OAAO,OAAO,IAAI,CAAC;AAClG;AAQO,SAAS,kBACd,WACA,SACA,QACA,KACQ;AACR,QAAM,eAAW,qBAA0C;AAC3D,WAAS,YAAT,SAAS,cAAY,2BAAe,IAAI,SAAS,GAAG;AACpD,SAAO,SAAS,QAAQ,SAAS,QAAQ,GAAG;AAC9C;;;ADyTM;AAtTN,IAAM,UAAU,CAAC,MAAiB,KAAK,QAAQ,MAAM,SAAS,MAAM,QAAQ,MAAM;AAClF,IAAM,MAAM,CAAC,MAAc;AA8IpB,SAAS,WAAW,OAAwB;AACjD,QAAM;AAAA,IACJ;AAAA,IACA,QAAQ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,cAAI,UAAU,MAAMA,SAAQ,CAAC;AAC7B,cAAI,MAAM;AAAA,QACZ,CAAC;AAAA,MACL;AAAA,IACF,EAAE,KAAK,CAAC,YAAY,QAAQ,UAAU,EAAE,KAAK,QAAQ,CAAC,CAAC;AACvD,WAAO,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EAEF,GAAG,CAAC,GAAG,CAAC;AACR,SAAO,UAAU,OAAO,QAAQ,MAAM,OAAO,UAAU;AACzD;;;AC9BA,IAAAC,gBAAoC;AACpC,IAAAC,eAA2D;AAOpD,SAAS,cAAc,MAA0D;AACtF,QAAM,MAAM,MAAM,KAAK,IAAI;AAC3B,QAAM,CAAC,QAAQ,SAAS,QAAI,wBAA0C;AACtE,+BAAU,MAAM;AACd,QAAI,CAAC,QAAQ,QAAQ,UAAa,OAAO,aAAa,YAAa;AACnE,QAAI,OAAO;AACX,YAAQ;AAAA,MACN,KAAK;AAAA,QAAI,CAAC,YACR,8BAAgB,KAAK,GAAG,EACrB,KAAK,0BAAa,EAClB,MAAM,OAAO,EAAE,GAAG,KAAK,GAAG,IAAI,EAAE;AAAA,MACrC;AAAA,IACF,EAAE,KAAK,CAAC,UAAU,QAAQ,UAAU,EAAE,KAAK,MAAM,CAAC,CAAC;AACnD,WAAO,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EAEF,GAAG,CAAC,GAAG,CAAC;AACR,SAAO,UAAU,OAAO,QAAQ,MAAM,OAAO,QAAQ;AACvD;;;ANdA,IAAAC,cAAgC;AAIhC,IAAAC,cAA+C;","names":["import_react","import_core","import_dom","safeArea","resolve","sharedCoverStyle","import_react","import_core","import_jsx_runtime","import_react","import_core","import_react","resolve","import_react","import_core","import_dom","import_svg"]}
@@ -0,0 +1,296 @@
1
+ import * as react from 'react';
2
+ import { HTMLAttributes, ReactNode, CSSProperties, SVGProps } from 'react';
3
+ import { LayoutOptions, FitOptions, Layout, Cell, ContentCells, ContentPlacement, Focus, Rect, ImageFillOptions, CellFill } from '@andamento/core';
4
+ export { Cell, ContentCells, ContentPlacement, Focus, HitOptions, Layout, LayoutOptions, MatchOptions, SafeAreaOptions } from '@andamento/core';
5
+ import { SafeAreaProp, FitProp, CellState, PerCell } from '@andamento/dom';
6
+ export { CellState, FitProp, PerCell, PointerLike, cellFromPointer } from '@andamento/dom';
7
+ import { FillSource, ReliefOptions, ImageSource } from '@andamento/svg';
8
+ export { FillSource, ReliefOptions, defaultPalette, neutralPalette } from '@andamento/svg';
9
+
10
+ /**
11
+ * Compute a layout, recomputing only when the (serializable) options change.
12
+ * Inline object literals are fine: options are compared by value.
13
+ */
14
+ declare function useTileLayout(options: LayoutOptions): Layout;
15
+ /**
16
+ * Compute a layout whose tiles are sized to give about `count` usable cells (see
17
+ * `fitCount` in @andamento/core). Options are compared by value; a `cells` function by
18
+ * identity.
19
+ */
20
+ declare function useFitCount(options: LayoutOptions, count: number, fit?: FitOptions): Layout;
21
+
22
+ interface TileLayoutProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
23
+ /** Layout options; or pass a precomputed `layout` instead. */
24
+ options?: LayoutOptions;
25
+ layout?: Layout;
26
+ /**
27
+ * Any React content. Each top-level child fills one tile, in reading order
28
+ * (top-to-bottom, left-to-right), and is clipped to the tile's shape.
29
+ * Extra children beyond the number of tiles are not rendered.
30
+ */
31
+ children?: ReactNode;
32
+ /**
33
+ * Alternative to `children`: compute each tile's content from its cell. Takes precedence.
34
+ * `slot` numbers the cells allowed by `contentCells` in reading order (-1 for the rest).
35
+ */
36
+ renderCell?: (cell: Cell, state: {
37
+ slot: number;
38
+ }) => ReactNode;
39
+ /**
40
+ * Which tiles may hold children: "all" (default), "whole" (only tiles not cut by the
41
+ * region outline), or a test per cell. The others are left empty.
42
+ */
43
+ contentCells?: ContentCells;
44
+ /**
45
+ * Where children go when there are fewer than tiles: "reading" (default; the first
46
+ * tiles in reading order), "center" (the middle of the region) or "spread" (evenly
47
+ * over it). Children always run in reading order across the tiles chosen.
48
+ */
49
+ placement?: ContentPlacement;
50
+ /**
51
+ * Width / height of each child, in order. When given, each child goes in a tile of
52
+ * similar shape, so `object-fit: cover` crops as little as possible (landscape photos in
53
+ * wide tiles, portraits in tall ones); see `matchSlots`. Featured tiles still take the
54
+ * first children. Missing entries count as square. Ignored with `renderCell`.
55
+ */
56
+ aspects?: readonly number[];
57
+ /**
58
+ * Keep content out of the tiles' clipped corners: each tile's content goes in a box at
59
+ * the tile's safe area (see `safeArea`), the largest rectangle that fits inside its shape,
60
+ * instead of filling the tile's bounding box. Useful for text in triangles or hexagons.
61
+ * With `aspects`, each child's box has the child's shape, so it shows whole and uncropped.
62
+ * The box has `data-safe-area`; style its contents to fill it. Tiles show `fill` around
63
+ * their content. For tiles an `edges: "window"` layout cuts, `true` or "tile" fits the
64
+ * whole tile (content near the edge is partly hidden, like the tile) and "visible" the
65
+ * part that shows.
66
+ */
67
+ safeArea?: SafeAreaProp;
68
+ /** With `aspects`: "shape" also picks which tiles hold children by their shape, ignoring `placement`. */
69
+ choose?: "placement" | "shape";
70
+ /**
71
+ * Focal point of each child (fractions of its width and height; see `estimateFocus`): what
72
+ * a photo keeps in view as its tile crops it. Each tile sets `--andamento-object-position`,
73
+ * which `coverStyle` uses as `object-position`; exact when the photo's shape is known (`aspects`, or the focus's `aspect`).
74
+ */
75
+ focalPoints?: readonly (Focus | undefined)[];
76
+ /**
77
+ * How many tiles each child spans (1 for an ordinary child; rounded): heavier childs get a
78
+ * featured tile of that many merged tiles, where they fall in reading order (see
79
+ * `weightedLayout`). With `fit`, the tiles are sized to fit everything. Needs `options`.
80
+ */
81
+ weights?: readonly number[];
82
+ /**
83
+ * Color of empty tiles: a color, a palette (neighboring tiles get different entries),
84
+ * or a function per cell. Defaults to `neutralPalette`; use "transparent" for none.
85
+ */
86
+ fill?: FillSource;
87
+ /**
88
+ * Size the tiles to the children: scales the pattern so there are about as many tiles
89
+ * (counted by `contentCells`) as children. `true`/"atLeast" makes sure every child gets
90
+ * a tile; "nearest" gets as close as possible. Ignored with `layout` or `renderCell`.
91
+ */
92
+ fit?: FitProp;
93
+ /**
94
+ * One picture across all the tiles: rendered in every tile, sized and positioned to the
95
+ * whole layout, so each tile shows its own piece. Use an element that fills its box,
96
+ * e.g. `<img src=… style={coverStyle} />`. It sits behind the tile's content, and empty
97
+ * tiles show it instead of `fill`. (Each tile gets its own copy, so a video would play
98
+ * out of sync; images are loaded once.)
99
+ */
100
+ backdrop?: ReactNode;
101
+ /**
102
+ * Raised tiles: a bevel round each tile, lit from one side and drawn over its content,
103
+ * and optionally a soft shadow each tile casts into the grout (set `shadow`). `true` for
104
+ * the defaults. With `gap` as the grout width and `background` as its color or texture,
105
+ * it looks like a tiled surface. See `ReliefOptions`.
106
+ */
107
+ relief?: boolean | ReliefOptions;
108
+ /**
109
+ * Keyboard navigation: tiles with content become focusable as one tab stop (roving
110
+ * tabindex). Arrow keys move to the nearest tile in that direction, whatever the tiling;
111
+ * Home and End go to the first and last. The focused tile shows `focusRing`.
112
+ */
113
+ navigable?: boolean;
114
+ /**
115
+ * Called when a tile with content is activated: clicked, or Enter or Space while it has
116
+ * focus (with `navigable`).
117
+ */
118
+ onCellActivate?: (cell: Cell, state: CellState) => void;
119
+ /** Accessible name for each tile (its `aria-label`), e.g. a photo's description. */
120
+ cellLabel?: PerCell<string | undefined>;
121
+ /**
122
+ * Color of the focus outline drawn inside the focused tile's shape (a CSS outline would be
123
+ * clipped away), with a white inner line so it shows on any content. `false` for none,
124
+ * if you style `[data-cell-id]:focus-visible` yourself. Defaults to "#1a56db".
125
+ */
126
+ focusRing?: string | false;
127
+ /**
128
+ * Animate changes: when the layout changes (a resize, another tiling, a new gap) or the
129
+ * children do, tiles glide and morph into their new places and shapes, a child keeping
130
+ * its tile as it moves; new tiles fade in and removed ones fade out. Pure CSS
131
+ * transitions, skipped when the user prefers reduced motion. `true` for 400 ms, or
132
+ * `{ duration, easing }`.
133
+ */
134
+ animate?: boolean | {
135
+ duration?: number;
136
+ easing?: string;
137
+ };
138
+ /**
139
+ * Mount only the tiles in view (plus `overscan` pixels round it, default 300), for
140
+ * layouts with thousands of tiles. Tiles mount and unmount as the page or any scrolling
141
+ * container scrolls, or the layout resizes. Keyboard navigation still reaches every
142
+ * tile (the focused one stays mounted and is scrolled to), and list items carry
143
+ * `aria-setsize` and `aria-posinset`. With `renderCell`, every cell `contentCells`
144
+ * allows counts as having content. On the server no tiles are rendered.
145
+ */
146
+ virtualize?: boolean | {
147
+ overscan?: number;
148
+ };
149
+ /** Content for empty tiles. */
150
+ fallback?: PerCell<ReactNode>;
151
+ /** Class name for each tile wrapper (fixed or per cell). */
152
+ cellClassName?: PerCell<string>;
153
+ /** Extra style for each tile wrapper (fixed or per cell), e.g. a background color. */
154
+ cellStyle?: PerCell<CSSProperties>;
155
+ /** Color painted across the whole region, visible through the gaps. */
156
+ background?: string;
157
+ }
158
+ /**
159
+ * Renders a tiling as HTML: one absolutely positioned, `clip-path`-ed element per tile,
160
+ * holding whatever you put in it (images, video, text, components). Everything is sized
161
+ * in percentages, so the layout scales with the container's width.
162
+ *
163
+ * Each tile wrapper has `data-cell-id` and `data-index`, plus `data-empty` (no content)
164
+ * and `data-boundary` (cut by the region outline) for styling.
165
+ *
166
+ * Clipping also applies to pointer events, so hover and clicks follow the tile shapes.
167
+ */
168
+ declare function TileLayout(props: TileLayoutProps): react.JSX.Element;
169
+ /** Style that makes an <img> or <video> cover its tile, like `object-fit: cover`. */
170
+ declare const coverStyle: CSSProperties;
171
+
172
+ interface SvgCellRenderContext {
173
+ /** `d` attribute of the cell outline. */
174
+ path: string;
175
+ /** Id of a <clipPath> with the cell's shape, already in the SVG. */
176
+ clipPathId: string;
177
+ /** Ready-made `clipPath` prop value: `url(#…)`. */
178
+ clipPath: string;
179
+ /** The fill/image the default renderer would have used. */
180
+ fill: string;
181
+ image?: string;
182
+ /** Which item of `images` the cell shows (-1 if none or if `images` is a function). */
183
+ slot: number;
184
+ }
185
+ interface SvgTileLayoutProps extends Omit<SVGProps<SVGSVGElement>, "children" | "fill" | "stroke" | "strokeWidth"> {
186
+ /** Layout options; or pass a precomputed `layout` instead. */
187
+ options?: LayoutOptions;
188
+ layout?: Layout;
189
+ images?: ImageSource;
190
+ repeatImages?: boolean;
191
+ /** Which cells may hold an image from the `images` array: "all" (default), "whole" or a test. */
192
+ contentCells?: ContentCells;
193
+ /** Where images go when there are fewer than cells: "reading" (default), "center" or "spread". */
194
+ placement?: ContentPlacement;
195
+ /** Width / height of each image, to put images in cells of similar shape (see `matchSlots`). */
196
+ imageAspects?: readonly number[];
197
+ /** With `imageAspects`: "shape" also picks which cells get images by their shape. */
198
+ choose?: "placement" | "shape";
199
+ /**
200
+ * "cover" (default) fills each cell's bounding box, cropped to its shape; "contain" shows
201
+ * each image whole inside the cell's safe area (see `safeArea`), at its `imageAspects` shape.
202
+ */
203
+ imageFit?: "cover" | "contain";
204
+ /**
205
+ * With `imageFit: "contain"`, for cells an `edges: "window"` layout cuts: fit the image in
206
+ * the whole tile ("tile", the default) or in the part that shows ("visible").
207
+ */
208
+ containWithin?: "tile" | "visible";
209
+ /**
210
+ * Focal point of each image (by position; fractions of its width and height, see
211
+ * `estimateFocus`), kept in view when "cover" crops it (see `coverRect`). Needs each image's
212
+ * shape, from `imageAspects` or the focus's `aspect`.
213
+ */
214
+ imageFocus?: readonly (Focus | undefined)[];
215
+ /**
216
+ * How many tiles each image in `images` spans (1 for most): heavier images get featured
217
+ * tiles where they fall in reading order (see `weightedLayout`). Needs `options`.
218
+ */
219
+ imageWeights?: readonly number[];
220
+ /**
221
+ * Size the tiles to the `images` array (counted by `contentCells`): `true`/"atLeast" or
222
+ * "nearest". Ignored with `layout`, `repeatImages` or an `images` function.
223
+ */
224
+ fit?: FitProp;
225
+ /** Cell color under (or instead of) images. Defaults to `defaultPalette`. */
226
+ fill?: FillSource;
227
+ stroke?: string;
228
+ strokeWidth?: number;
229
+ /** Color painted across the whole region, behind the cells. */
230
+ background?: string;
231
+ /**
232
+ * One image across all the cells (a URL), cropped to cover the layout and clipped to the
233
+ * cells. The default cell rendering then skips `fill`; per-cell `images` go on top.
234
+ */
235
+ backdrop?: string;
236
+ /**
237
+ * Raised tiles: a lit bevel over each cell, and optionally a shadow cast into the grout.
238
+ * `true` for the defaults. See `ReliefOptions`. Drawn over `renderCell` content too.
239
+ */
240
+ relief?: boolean | ReliefOptions;
241
+ /** Replace the default cell rendering with SVG content. Rendered inside a <g> per cell. */
242
+ renderCell?: (cell: Cell, ctx: SvgCellRenderContext) => ReactNode;
243
+ /** Accessible title. */
244
+ title?: string;
245
+ /** Text alternative per image in `images`: those cells become labeled images; the rest decoration. */
246
+ imageAlts?: readonly string[];
247
+ }
248
+ /**
249
+ * Renders a tiling as a single <svg>: colored cells, optionally with images clipped
250
+ * to each cell. Use this when you need pure SVG (export, print, embedding in other SVG);
251
+ * use <TileLayout> to put arbitrary HTML/React content in the tiles.
252
+ */
253
+ declare function SvgTileLayout(props: SvgTileLayoutProps): react.JSX.Element;
254
+ interface SvgCellImageProps extends Omit<SVGProps<SVGImageElement>, "href" | "x" | "y" | "width" | "height"> {
255
+ cell: Cell;
256
+ href: string;
257
+ /** Pass `ctx.clipPath` from `renderCell`. */
258
+ clipPath: string;
259
+ /**
260
+ * Draw the image whole inside this box (e.g. `safeArea(cell, layout)`) instead of
261
+ * covering the cell.
262
+ */
263
+ box?: Rect;
264
+ /** Cover this rectangle instead of the cell's box (e.g. `coverRect(cell, layout, { aspect, focus })`). */
265
+ cover?: Rect;
266
+ }
267
+ /**
268
+ * An SVG <image> that covers the cell (like CSS `object-fit: cover`), clipped to its shape;
269
+ * or, with `box`, shown whole inside the box (like `object-fit: contain`).
270
+ */
271
+ declare function SvgCellImage({ cell, href, clipPath, box, cover, ...rest }: SvgCellImageProps): react.JSX.Element;
272
+
273
+ /**
274
+ * Load an image and color tiles from it (see `imageFill`): returns a fill to pass as
275
+ * `fill`, or `undefined` while the image loads (or if it fails), so the default fill shows
276
+ * meanwhile. `maxSize` caps the size the image is read at (default 256 px on the long side).
277
+ */
278
+ declare function useImageFill(src: string | undefined, options?: ImageFillOptions & {
279
+ maxSize?: number;
280
+ }): CellFill | undefined;
281
+
282
+ /**
283
+ * Measure images' aspect ratios (width / height) by loading them, for the `aspects` and
284
+ * `imageAspects` props. Returns `undefined` until every image has loaded or failed (failed
285
+ * ones count as square), so content isn't reshuffled image by image as they arrive.
286
+ */
287
+ declare function useImageAspects(srcs: readonly string[] | undefined): number[] | undefined;
288
+
289
+ /**
290
+ * Guess each image's focal point (see `estimateFocus`) by loading it, for the `focus` and
291
+ * `imageFocus` props. Returns `undefined` until every image has been looked at; images that
292
+ * fail to load (or that the browser won't let a canvas read) get the middle.
293
+ */
294
+ declare function useImageFocus(srcs: readonly string[] | undefined): Focus[] | undefined;
295
+
296
+ export { SvgCellImage, type SvgCellImageProps, type SvgCellRenderContext, SvgTileLayout, type SvgTileLayoutProps, TileLayout, type TileLayoutProps, coverStyle, useFitCount, useImageAspects, useImageFill, useImageFocus, useTileLayout };