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

slidev-addon-dynamic-code

v0.3.1

Published

Slidev addon for live-editable code blocks during presentations

Downloads

1,222

Readme

slidev-addon-dynamic-code

Live-editable code blocks for Slidev presentations. Edit a snippet on the slide during a talk, and every audience browser updates within a second — no rebuild, no reload.

Static-build friendly: works on Cloudflare Pages, Netlify, GitHub Pages, or any plain HTML host.

Requirements

  • Slidev >= 52.15.0 (uses the codeblocks transformer API)
  • A Cloudflare account (free tier is enough) — see the relay deploy guide

Install

pnpm add -D slidev-addon-dynamic-code

Add the addon and config to your deck's slides.md frontmatter:

---
addons:
  - slidev-addon-dynamic-code
dynamicCode:
  relayUrl: https://slidev-dynamic-code-relay.YOUR-SUBDOMAIN.workers.dev
  talkId: my-talk-2026-05
---

| Key | Required | Value | |-----|----------|-------| | relayUrl | yes | URL printed by wrangler deploy (relay deploy guide). http:// / https:// are converted to ws:// / wss:// at runtime. | | talkId | yes | Any stable string per deck. Edits persist in a Durable Object keyed by this id — change it for a fresh slate. |

Mark a code block dynamic

```bash {dynamic id=lab15-deploy}
npx wrangler deploy
curl https://api.example.com/health
```

Rules:

  • id= is required. Use stable, descriptive names like lab15-deploy, install-deps, run-tests.
  • Ids must be unique across the whole deck (build error otherwise).
  • Allowed characters: [a-zA-Z0-9_-].

The block renders normally for everyone until the presenter starts editing.

Click-stepped line reveal (since v0.2.0)

Combine {dynamic} with Slidev's line-highlight grammar to walk through a snippet click-by-click, then edit live:

```bash {dynamic id=install-walkthrough} {2-3|5|all}
mkdir my-app
cd my-app
npm init -y
npm install express
npm start
```

| Phase | Trigger | Highlight | Textarea | |-------|---------|-----------|----------| | Reveal | each click advances to next step | highlighted lines for that step | read-only, edits do not sync | | Final | last step in {...\|...\|...} | last range item (all above) | editable for presenter; edits broadcast |

Unlocking is automatic at the last reveal step.

Caveat — editing then navigating back. If you edit the block then click backward into the reveal phase, line-highlight ranges are reapplied to the edited content. If your edit changed line count, highlighted lines may mis-align. Switch slides and return to reset.

Graceful degrade. Environments without useSlideContext().$clicksContext (old Slidev, admin route) fall back to immediate edit mode.

Not yet supported on dynamic blocks (warned at build time):

  • {at:N} — pinned reveal start
  • {lines:true} / {startLine:N} — line numbering
  • {maxHeight:'…'} — scrollable area
  • Magic Move

Using during a talk

  • Presenter: https://your-deck.example.com/?presenter=YOUR_TOKEN
  • Audience: https://your-deck.example.com/

Click into any {dynamic} block — caret appears, blue focus ring — type freely. Audience sees edits in ~1 second (200 ms debounce).

Connection badge

Presenter-only indicator, top-right of each dynamic block:

| Glyph | Status | Meaning | |-------|--------|---------| | | connected | Green. WebSocket open, edits flowing. | | | reconnecting | Amber. Lost WS mid-talk; retrying (1 s → 30 s backoff). | | | offline | Amber. Couldn't connect on first try; retrying. | | | rejected | Red. 401 — presenter token doesn't match. |

Copy button

Clipboard icon (top-right on hover) copies the currently displayed content. Available to both presenter and audience.

Admin route

https://your-deck.example.com/dynamic-code-admin?presenter=YOUR_TOKEN

Shows every block id in the Durable Object for this talkId, with per-row Reset buttons and a Reset all button. Useful before a fresh run-through.

Theme integration

The addon reuses Slidev's slidev-code-wrapper + slidev-code classes, so background, padding, border-radius, font, and margin follow your active theme. Syntax highlighting uses Shiki dual themes and respects Slidev's dark mode toggle. Caret colour tracks --shiki-light / --shiki-dark.

Persistence

  • Edits persist in the Durable Object's SQLite, keyed by (talkId, blockId).
  • Survives Worker redeploys, DO hibernation, audience refreshes.
  • Reset via admin route (per-block or reset-all).
  • Changed fenced source → origin hash changes → DO entry auto-invalidated on next presenter edit.
  • To wipe state: change talkId and redeploy. Old DO storage stays orphaned but doesn't bill while hibernated.

Multiple decks

One relay serves any number of decks. Each deck sets a unique talkId and points at the same relayUrl. The Durable Object instance is keyed by talkId.

Single PRESENTER_TOKEN works across all talks. For per-talk tokens, extend the Worker — see packages/relay/src/index.ts.

Pre-talk runbook

Five minutes before going live:

  1. Deploy the deck (slidev build + your static host's deploy).
  2. Visit the audience URL on a second device / incognito. Confirm dynamic blocks render like normal code blocks.
  3. Visit the presenter URL with ?presenter=YOUR_TOKEN. Confirm the badge appears.
  4. Type into a dynamic block. Audience window reflects the change within ~1 second.
  5. Visit /dynamic-code-admin?presenter=YOUR_TOKEN. Confirm "Reset all" works.

Troubleshooting

| Symptom | Likely cause | Fix | |---------|-------------|-----| | Build error missing required id=NAME on slide N | Forgot id= | Add id=stable-name | | Build error duplicate id "X" on slides N and M | Same id on two slides | Rename one | | Build error dynamicCode.relayUrl is required | Missing frontmatter config | Add dynamicCode: { relayUrl, talkId } | | No badge in presenter mode | ?presenter=… not in URL, or transformer didn't fire | Check URL query; inspect for <DynamicCode> in DevTools | | Badge shows (red) | Wrong presenter token | Re-check wrangler secret put PRESENTER_TOKEN | | Badge shows and never advances | Relay URL typo, Worker not deployed | curl -i https://YOUR-RELAY.workers.dev/sub?talk=test should return 426 | | Edits not propagating, badge is | Audience on stale cache or different talkId | Hard-reload audience | | Edit appears then disappears on refresh | Origin hash mismatch — fenced source changed between builds | Confirm same deployment | | Block looks like plain text | Slidev < 52.15.0 | Bump @slidev/cli to ^52.15.2 |

Limitations

  • One presenter at a time — no conflict resolution.
  • Display only — the slide does not execute code.
  • 32 KiB per block content (server enforced).
  • 200 block ids per talkId (server enforced).
  • Free-tier Worker handles a few hundred audience devices per talk.

License

MIT © opariffazman