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

@excom/detect-media

v0.1.8

Published

<detect-media> custom element

Readme

detect-media

Live media-query facts as attributes — what CSS knows, Quark can now select on. One <detect-media> per query; is-matched follows window.matchMedia and flips as the query does.

<div>
  <detect-media media-query="(prefers-color-scheme: dark)"></detect-media>
  <p>Dark color scheme — <code>is-matched</code> is set.</p>
  <p role="status">Light color scheme — <code>is-matched</code> is absent.</p>
  <small role="note">Live — switch your OS / browser color scheme (or emulate <code>prefers-color-scheme</code> in DevTools) to flip it.</small>
  <style>
    #demo-detect-media-simple {
      &:has(detect-media[is-matched]) p[role="status"] {
        display: none;
      }
      &:has(detect-media:not([is-matched])) p:not([role="status"]) {
        display: none;
      }
    }
  </style>
</div>

Features

  • Live is-matched Follows MediaQueryList.matches and its change event
  • Any media query Color scheme, pointer type, motion, width — whatever matchMedia accepts
  • CSS / Quark selectable Gate content on detect-media[is-matched], no listeners
  • Provision + event .provision is { mediaQuery, isMatched }; detect-media-change fires on every flip

Installation

@excom/detect-media v0.1.8

pnpm add @excom/detect-media
npm install @excom/detect-media
yarn add @excom/detect-media

Import

import "@excom/detect-media";

Usage

One element per query. media-query takes anything window.matchMedia does.

<detect-media media-query="(pointer: coarse)"></detect-media>

Select on is-matched from CSS:

body:has(detect-media[media-query="(pointer: coarse)"][is-matched]) .hover-hint {
  display: none;
}

Or from Quark — the attribute, or the provision:

detect-media[media-query="(pointer: coarse)"][is-matched] ~ nav {
  data-is-touch: "";
}
detect-media[media-query="(pointer: coarse)"]:not([is-matched]) ~ nav {
  data-is-touch: none;
}
detect-media[media-query="(prefers-color-scheme: dark)"] {
  $app-is-dark: prop("provision").isMatched;
}

Missing / empty media-query leaves is-matched unset and provision null; changing it re-subscribes. detect-media-change fires on every flip after mount, never on mount — react to the attribute for the initial state.

API Reference

Attributes

| Name | Surface | Type | Default | Values | Description | | --- | --- | --- | --- | --- | --- | | media-query | option | string | | | Media query to evaluate, in window.matchMedia syntax: (prefers-color-scheme: dark), (pointer: coarse), (width < 600px). Required — missing / empty leaves is-matched unset and provision null. Changing it re-subscribes. | | is-matched | state | boolean | | | Present while media-query matches. Live — follows the query's change event. |

Provision

| Name | Type | Description | | --- | --- | --- | | provision | DetectMediaProvision ({ mediaQuery: string; isMatched: boolean; }) | { mediaQuery, isMatched } — a new object on first evaluation and on every change; null without a query. Not reflected as an attribute. |

Fires

| Name | Type | Description | | --- | --- | --- | | detect-media-change | DetectMediaChangeEvent (CustomEvent & { type: "detect-media-change"; detail: { mediaQuery: string; isMatched: boolean; }; bubbles: true; cancelable: true; composed: true }) | Dispatched every time the query flips (not on mount). event.detail is the .provision payload. |

Examples

Touch vs pointer views

Quark flips is-active on two <include-content> hosts from (pointer: coarse) — a true render, so the inactive view is not in the document. Toggle device emulation in DevTools to switch live.

<div>
  <detect-media media-query="(pointer: coarse)">
    <include-content bind-touch>
      <template>
        <p>Touch layout</p>
      </template>
    </include-content>
    <include-content bind-pointer>
      <template>
        <p>Pointer layout</p>
      </template>
    </include-content>
  </detect-media>
  <quark-sheet>
    detect-media[is-matched] include-content[bind-touch] {
      is-active: "";
    }
    detect-media[is-matched] include-content[bind-pointer] {
      is-active: none;
    }
    detect-media:not([is-matched]) include-content[bind-pointer] {
      is-active: "";
    }
    detect-media:not([is-matched]) include-content[bind-touch] {
      is-active: none;
    }
  </quark-sheet>
</div>

Release notes

0.1.1 (2026-09-23)

  • Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources

Full documentation: https://nucleus.excom.dev/packages/detect-media