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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@docyrus/dom-selector-client

v0.0.3

Published

DOM selector CLI client

Readme

@docyrus/dom-selector-client

A simple CLI that prepares your Vite or Astro project for interactive element selection during development. It injects a lightweight helper script and annotates elements with useful data attributes so external tools can highlight and reference them.

  • Adds a dev-only Vite plugin that serves and injects dom-selector-helper.js
  • For React projects, adds a Babel plugin to annotate JSX elements with data-component-*
  • For Astro/vanilla projects, adds an HTML transform to annotate tags with data-component-*
  • Touches only config and adds helper files; no runtime dependency in production

Install

  • pnpm: pnpm add -D @docyrus/dom-selector-client
  • npm: npm i -D @docyrus/dom-selector-client
  • yarn: yarn add -D @docyrus/dom-selector-client

Requires Node 18+.

Quick Start

  • npx: npx dom-selector install
  • pnpm: pnpm dlx dom-selector install or add it as a dev dep and run dom-selector install

The installer will:

  • Detect Astro vs. Vite and framework flavor (React or vanilla)
  • Copy dom-selector-helper.js to your project root (if not present)
  • Update astro.config.* or vite.config.* to inject a dev-only plugin that includes the helper
  • For React projects, copy babel-plugin-component-annotate.ts to your project root and register a Babel transform in Vite to add data-component-name and data-component-path attributes to JSX elements during dev

No changes are made if your config is already set up.

What It Adds

  • Dev-only Vite plugin: injects <script type="module" src="/dom-selector-helper.js"></script> into HTML and serves the file from the project root
  • React: Babel plugin that annotates all JSX opening elements with:
    • data-component-name: The element/component name
    • data-component-path: Relative file path with line:column (e.g. src/App.tsx:12:5)
  • Astro/vanilla: A Vite transform that annotates HTML tags (outside frontmatter/script/style blocks) with the same attributes

Annotations are added only in development. The helper and plugins are inert in production builds.

Using The Helper

The injected dom-selector-helper.js listens for postMessage events:

  • Enable: window.postMessage({ type: 'DOCY_SELECTOR', action: 'enable' }, '*')
  • Disable: window.postMessage({ type: 'DOCY_SELECTOR', action: 'disable' }, '*')

When enabled, hovering highlights elements, and clicking sends a message to window.parent:

  • { type: 'DOCY_SELECTOR', action: 'elementSelected', payload: { rect, componentName, componentPath, tagName, className, hasTextContent, textContent, src } }

This is designed to work inside iframes or dev UIs that consume the selection signal.

Files Touched

  • Project root:
    • dom-selector-helper.js (copied if missing)
    • babel-plugin-component-annotate.ts (React projects, copied if missing)
  • Config:
    • astro.config.* or vite.config.* updated to register dev-only plugins

You can remove these changes by deleting the two files and reverting the plugin additions in your config.

Notes

  • React requires @babel/core for the inline transform. If it’s not found, the installer will warn you to install it: npm i -D @babel/core.
  • Vue support: the helper is injected, but element annotation is not yet implemented for Vue components.

CLI

  • dom-selector install
    • Options: -d, --directory <dir> target project directory (defaults to CWD)

License

MIT