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

@dtgraph/mdx

v0.1.0

Published

Render a live DTCG token graph inline in MDX/Astro content

Readme

@dtgraph/mdx

A <TokenGraph> Astro component that renders a live DTCG token graph inline — in MDX content, or in a plain .astro file — as a static SVG, or as an interactive map you can pan, zoom, search and click through. Built on @dtgraph/core and @dtgraph/viewer.

Install

npm install @dtgraph/mdx @dtgraph/core

Requires an Astro project (astro is a peer dependency, >=5.0.0). To use it from .mdx files, also install and configure @astrojs/mdx.

Usage

import TokenGraph from '@dtgraph/mdx/TokenGraph.astro';

<TokenGraph
  tokens={{
    color: {
      brand: { $type: 'color', $value: '#3311ff' },
      accent: { $value: '{color.brand}' },
    },
  }}
/>

Or read one or more token files from disk at build time, as a path relative to the current working directory (typically the project root — the directory astro dev/astro build runs from):

<TokenGraph file="src/tokens.json" />
<TokenGraph files={['src/color.json', 'src/typography.json']} />

A path relative to the importing file itself (e.g. via import.meta.url) is not reliable here — Astro bundles and relocates frontmatter scripts at build time, which breaks paths resolved that way in the production build even though they may appear to work in astro dev.

Interactive mode

Add interactive to get the @dtgraph/viewer map instead of the static SVG: a WebGL canvas you can drag, zoom, hover (spotlights everything a token relates to), click (opens a detail panel with the raw and resolved value, and what depends on what), and search (/). The graph is still parsed and resolved at build time; only the resolved nodes and edges ship to the browser, as a JSON payload the component hydrates on load.

<TokenGraph file="src/tokens.json" interactive height="360px" />

The map follows your site's theme: <html data-theme="dark|light"> when present (Starlight sets it), else prefers-color-scheme, live. Force one with theme="dark" or theme="light".

Props

| Prop | Type | Description | | ------------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------- | | tokens | unknown | Inline DTCG JSON (already parsed) — for a single-file graph. | | file | string | Path to a DTCG JSON file, read via node:fs at build time, relative to the current working directory (see above). | | files | string[] | Multiple file paths (see file) — aliases resolve across all of them, same as the dtgraph CLI's multi-file support. | | interactive | boolean | Render the interactive map instead of the static SVG. Defaults to false. | | height | string | Interactive only: CSS height of the map. Defaults to "480px". | | theme | "auto" \| "dark" \| "light" | Interactive only: follow the site (default), or force a theme. | | colorBy | "group" \| "type" | Interactive only: color tokens by top-level group (default) or by $type. | | chrome | boolean | Interactive only: show the search box, legend and detail panel. Defaults to true. |

Pass exactly one of tokens, file, or files. Errors (malformed JSON, a dangling alias, an alias cycle, a cross-file token-path collision) throw the same DtcgParseError @dtgraph/core itself throws — nothing is re-wrapped, so the message always includes the offending token path and a link to the relevant part of the DTCG spec.

The rendered SVG is safe to embed as-is: renderTokenGraphToSvg (from @dtgraph/core) escapes every piece of token-derived text before this component injects it, even if the source token file is untrusted. In interactive mode the JSON payload escapes < (so no token text can close its <script type="application/json"> element) and the viewer only ever draws token text on a canvas or sets it as textContent.

Example

See examples/mdx-astro for a minimal runnable Astro + MDX project using this component, or apps/website's own DTCG primer page for a real dogfooded example (two live <TokenGraph> embeds explaining aliases and composite tokens).