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

@rgglez/astro-collapsiblecode

v0.1.1

Published

Astro component that highlights a code string with Shiki on the server and shows it in a collapsible panel toggled by your own trigger element.

Readme

astro-collapsiblecode

License GitHub all releases GitHub issues GitHub commit activity GitHub release GitHub stars GitHub forks

astro-collapsiblecode highlights a code string with Shiki on the server and shows it in a collapsible panel. The trigger is yours: put a button, a link or any element in the default slot and the component wires it up.

One use case is a blog post (Markdown or MDX) where a live demo is followed by a "View code" toggle showing the source of that demo.

Installation

npm install @rgglez/astro-collapsiblecode shiki

shiki is a peer dependency, install it in your project.

Usage

import CollapsibleCode from "@rgglez/astro-collapsiblecode";

The first element of the slot becomes the trigger:

<CollapsibleCode code={source}>
  <button type="button">View code</button>
</CollapsibleCode>

Any element works. Links get their default action prevented, and non-interactive elements get role="button", tabindex="0" and Enter/Space handling:

<CollapsibleCode code={source} lang="python">
  <a href="#">Show the source</a>
</CollapsibleCode>

If the trigger is not the first element of the slot, mark it explicitly:

<CollapsibleCode code={source}>
  <p>Curious? <button type="button" data-code-trigger>View code</button></p>
</CollapsibleCode>

Usage in .mdx files

Keeping the code in a separate .ts file lets you run it and list it from the same string:

import CollapsibleCode from "@rgglez/astro-collapsiblecode";
import { demo } from "@/data/demos";

<CollapsibleCode code={demo}>
  <button type="button">View code</button>
</CollapsibleCode>

Props

| Prop | Type | Default | Description | |----------|-------------------------------------|------------------------------------------------|------------------------------------------| | code | string | — | Code to highlight. Required | | lang | BundledLanguage | "javascript" | Shiki language id | | themes | { light: Theme; dark: Theme } | { light: "github-light", dark: "dracula" } | Shiki themes, emitted as CSS variables | | open | boolean | false | Render the panel already expanded | | class | string | "" | Extra classes for the wrapper div |

Languages and themes are loaded lazily from the Shiki bundle, on a single highlighter instance shared by every render.

Styling hooks

The component ships almost no CSS (just margins), so it fits any design system.

| Hook | Where | When | |----------------------------------------|------------------|----------------------------| | .astro-collapsible-code | wrapper | always | | [data-expanded] | wrapper | panel open | | aria-expanded="true" | trigger | panel open | | [data-code-panel] | panel | always |

For example, to rotate a caret inside the trigger:

[aria-expanded="true"] [data-code-icon] {
  transform: rotate(90deg);
}

The highlighted <pre> carries the astro-code class as well, so it inherits the styling Astro applies to its own code blocks.

Notes

  • This is an Astro component (.astro). It cannot be imported into React, Vue, Svelte or other framework components. Use it from .astro or .mdx files.
  • Highlighting uses Shiki's JavaScript regex engine instead of the oniguruma WASM one, so it also works on Cloudflare Workers and other runtimes that disallow WebAssembly compilation.
  • Without JavaScript the panel stays collapsed. Pass open if the code must be visible in that case.

Development

| Target | Description | |--------|-------------| | make tags | List git tags sorted by semver (descending) | | make patch | Bump PATCH version in package.json, commit, tag, and push | | make publish | Publish current version to npm |

Typical release flow: make patch → make publish.

License

Copyright (C) 2026 Rodolfo González González.

Licensed under the Apache v2.0 license. Read the LICENSE file.