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

@mad-core/react

v0.1.7

Published

React components for serving responsive, format-optimized images from a MAD server

Downloads

536

Readme

@mad-core/react

React components for serving responsive, format-optimized images from a MAD (Media Assets Distributor) server.

Features

  • <MadImage> — renders a <picture> element with automatic <source> generation for modern formats (avif, webp)
  • useMadImage — hook for building memoized image URLs and srcSet strings
  • buildMadUrl — low-level utility for constructing MAD image URLs with transforms
  • Art direction — breakpoint-aware responsive sources via the sources prop
  • Tree-shakeable — ESM-only, sideEffects: false
  • TypeScript-first — full type definitions with JSDoc documentation
  • Zero runtime dependencies — only react as a peer dependency

Installation

# npm
npm install @mad-core/react

# bun
bun add @mad-core/react

# pnpm
pnpm add @mad-core/react

# yarn
yarn add @mad-core/react

react 18 or 19 is required as a peer dependency.

Quick Start

import { MadImage } from "@mad-core/react";

function Hero() {
  return (
    <MadImage
      id="clx1abc2300001a2b3c4d5e6f"
      baseUrl="https://cdn.example.com"
      widths={[400, 800, 1200, 1600]}
      sizes="(max-width: 768px) 100vw, 50vw"
      alt="Hero banner"
      loading="lazy"
    />
  );
}

API Reference

<MadImage>

Renders a responsive <picture> element with optimized format sources.

| Prop | Type | Default | Description | |------|------|---------|-------------| | id | string | — | Required. MAD asset ID (CUID2) | | baseUrl | string | — | Required. MAD server base URL | | params | MadTransformParams | {} | Base transform params applied to all URLs | | widths | number[] | — | Responsive srcset widths | | sizes | string | — | HTML sizes attribute | | formats | Array<"avif" \| "webp" \| "jpg" \| "png"> | ["avif", "webp"] | Format priority list | | sources | MadSource[] | — | Art direction sources | | ...rest | ImgHTMLAttributes | — | Passed to the fallback <img> (alt, className, loading, etc.) |

Art direction example

<MadImage
  id="clx1abc2300001a2b3c4d5e6f"
  baseUrl="https://cdn.example.com"
  widths={[400, 800]}
  sizes="100vw"
  sources={[
    {
      media: "(min-width: 1024px)",
      params: { width: 1200, crop: "center" },
      widths: [1200, 1800, 2400],
      sizes: "80vw",
    },
  ]}
  alt="Responsive hero"
/>

useMadImage(params: MadUrlParams): UseMadImageResult

Hook that returns a memoized image URL and a srcSet builder function. Use this when you need full control over the rendered markup.

import { useMadImage } from "@mad-core/react";

function Avatar({ id }: { id: string }) {
  const { url, srcSet } = useMadImage({
    id,
    baseUrl: "https://cdn.example.com",
    width: 128,
    format: "webp",
  });

  return (
    <img
      src={url}
      srcSet={srcSet([128, 256, 384])}
      sizes="128px"
      alt="User avatar"
    />
  );
}

| Return field | Type | Description | |-------------|------|-------------| | url | string | Fully-qualified MAD image URL | | srcSet | (widths: number[]) => string | Generates a srcset string for the given widths |

buildMadUrl(params: MadUrlParams): string

Low-level utility to build a MAD image URL with optional transform query parameters.

import { buildMadUrl } from "@mad-core/react";

const url = buildMadUrl({
  id: "clx1abc2300001a2b3c4d5e6f",
  baseUrl: "https://cdn.example.com",
  width: 800,
  format: "webp",
  quality: 80,
});
// => "https://cdn.example.com/image/clx1abc2300001a2b3c4d5e6f?width=800&format=webp&q=80"

Types

MadTransformParams

| Field | Type | Description | |-------|------|-------------| | width | number | Target width in pixels | | height | number | Target height in pixels | | format | MadImageFormat | Output format | | quality | number | Output quality (1–100) | | crop | MadCrop | Crop strategy | | fit | MadFit | Resize fit mode |

MadUrlParams

Extends MadTransformParams with:

| Field | Type | Description | |-------|------|-------------| | id | string | MAD asset ID (CUID2) | | baseUrl | string | MAD server base URL |

MadSource

| Field | Type | Description | |-------|------|-------------| | media | string | CSS media query, e.g. "(min-width: 1024px)" | | params | MadTransformParams | Transform overrides for this breakpoint | | widths | number[] | srcset widths (overrides global) | | sizes | string | HTML sizes attribute for this source |

MadCrop

"auto" | "center" | "top" | "bottom" | "left" | "right" | [x, y, w, h]

MadFit

"cover" | "contain" | "fill" | "inside" | "outside"

MadImageFormat

"webp" | "avif" | "jpg" | "png" | "gif"

How It Works

<MadImage> renders a standard HTML <picture> element:

  1. For each art direction source (sources prop), it generates <source> elements for every format in the formats list, each with the appropriate media, type, srcSet, and sizes attributes.
  2. For global responsive widths (widths prop), it generates <source> elements for each format (no media attribute).
  3. A fallback <img> element is rendered last with the base URL (no forced format), letting the browser negotiate the best option.

The browser evaluates sources top-to-bottom and picks the first match, giving you automatic format negotiation (avif > webp > fallback) with art-direction breakpoints.

License

MIT