npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@slithy/react-tessera-gallery

v0.4.2

Published

React justified gallery with optimal line-breaking layout.

Readme

@slithy/react-tessera-gallery

React photo gallery with optimal justified layout. Uses a Knuth-Plass dynamic programming algorithm to break items into rows that minimize deviation from a target row height. Supports incremental loading, unknown aspect ratios, and append-only rendering to prevent layout jumps as new images load.

Installation

npm install @slithy/react-tessera-gallery

Peer dependencies: react@^17 || ^18 || ^19


<TesseraGallery>

The main component. Accepts a list of items and a renderItem function; handles all layout and loading state internally.

import { TesseraGallery } from '@slithy/react-tessera-gallery'

<TesseraGallery
  items={photos}
  rowHeight={200}
  gap={4}
  renderItem={(item, { width, height, loaded }, handlers) => (
    <img
      key={item.key}
      src={item.src}
      width={width}
      height={height}
      onLoad={handlers.onLoad}
      style={{ opacity: loaded ? 1 : 0 }}
    />
  )}
/>

Props:

| Prop | Type | Default | Description | |---|---|---|---| | items | GalleryItem<T>[] | — | Items to display. Each must have a key. aspectRatio is optional — see below. | | renderItem | (item, layout, handlers) => ReactNode | — | Render function called for each item | | rowHeight | number | — | Target row height in pixels | | gap | number | 0 | Gap between items and rows in pixels | | lastRow | 'left' \| 'center' \| 'right' \| 'justify' \| 'hide' | 'left' | Alignment of the last (partial) row | | maxShrink | number | 0.75 | Minimum row height as a fraction of rowHeight | | maxStretch | number | 1.5 | Maximum row height as a multiple of rowHeight | | justifyThreshold | number | 1 | Justify the last row if its natural fill ratio meets this threshold (0–1) |

renderItem arguments:

| Argument | Type | Description | |---|---|---| | item | GalleryItem<T> | The original item | | layout.width | number | Computed pixel width for this item | | layout.height | number | Computed pixel height for this item | | layout.loaded | boolean | Whether the browser has confirmed this image loaded via handlers.onLoad | | handlers.onLoad | ReactEventHandler<HTMLImageElement> | Pass to <img onLoad={...}> to track load state |


GalleryItem<T>

Items passed to TesseraGallery must satisfy GalleryItem<T>:

type GalleryItem<T> = T & {
  key: string | number
  aspectRatio?: number  // optional — discovered via onLoad if omitted
}

Items with a known aspectRatio are laid out immediately. Items without one are held out of the layout until handlers.onLoad fires, at which point their aspect ratio is derived from naturalWidth / naturalHeight and they enter the layout with loaded: true.


useTesseraGallery

The hook underlying <TesseraGallery>. Use this directly for custom rendering or when you need lower-level control.

import { useTesseraGallery } from '@slithy/react-tessera-gallery'

const { containerRef, rows, onLoad } = useTesseraGallery(items, options)

Returns:

| Property | Type | Description | |---|---|---| | containerRef | RefObject<HTMLDivElement \| null> | Attach to your container element to observe its width | | rows | ResolvedRow<T>[] | Computed layout rows, each with height and items | | onLoad | (key, naturalWidth, naturalHeight) => void | Call when an image loads |


computeTesseraLayout

The pure layout function. Takes items with known aspect ratios, a container width, and options; returns row data with pixel dimensions. No React dependency.

import { computeTesseraLayout } from '@slithy/react-tessera-gallery'

const rows = computeTesseraLayout(
  [{ aspectRatio: 1.5 }, { aspectRatio: 1 }, { aspectRatio: 2 }],
  600,
  { rowHeight: 200, gap: 4 },
)