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

viewport-truth

v1.0.7

Published

Tiny zero‑config VisualViewport-first store for accurate visible viewport size in CSS pixels. Detects virtual keyboard, stabilizes resize/scroll jitter, and is SSR-safe across frameworks.

Readme

viewport-truth

Fastest way to measure the real visible mobile viewport without 100vh glitches, resize/scroll jitter, or keyboard hacks.

npm version npm downloads license tests Boosty Crypto

Stop guessing mobile viewport sizes. viewport-truth delivers stable, keyboard-aware visible viewport metrics (VisualViewport-first) across iOS Safari, Android Chrome, PWAs, and webviews—framework adapters included, SSR-safe, zero runtime deps.

Demo: tracks the visible viewport (VisualViewport), keeping UI stable when the URL bar / keyboard changes the viewport.

npm i viewport-truth
# or: yarn add viewport-truth
# or: pnpm add viewport-truth

Quick Start

Minimal flow: import → create → subscribe → get { width, height, isKeyboardOpen, isStable }.

import { createViewportTruth } from "viewport-truth/vanilla";

const vt = createViewportTruth();

const unsub = vt.subscribe((v) => {
    if (!v) return;

    console.log(
        `visible=${v.width}x${v.height} keyboard=${v.isKeyboardOpen} stable=${v.isStable}`
    );
});

// later:
// unsub();
// vt.destroy();

Demo snippet (keyboard + URL bar)

Use this in a real page (Vite/Parcel/Next). On mobile: scroll a bit (URL bar), then focus the input (keyboard).

<div id="app" style="padding:16px 16px 96px">
  <input
    placeholder="Focus me to open keyboard"
    style="width:100%;padding:12px;font-size:16px;box-sizing:border-box"
  />
  <p style="margin:12px 0 0;color:#444">
    Tip: scroll a bit (URL bar animates), then focus the input.
  </p>

  <div style="height:120vh"></div>
  <div id="bar"></div>
</div>

<script type="module">
  import { createViewportTruth } from "viewport-truth/vanilla";

  const bar = document.getElementById("bar");
  Object.assign(bar.style, {
    position: "fixed",
    left: "0",
    right: "0",
    bottom: "0",
    padding: "10px 12px",
    font: "12px/1.35 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
    background: "rgba(0,0,0,.86)",
    color: "white",
    zIndex: "9999",
    whiteSpace: "pre",
  });

  const vt = createViewportTruth();

  vt.subscribe((v) => {
    if (!v) return;

    // Fallback keeps the snippet working even if layoutWidth/layoutHeight aren't present.
    const layoutW = v.layoutWidth ?? v.width;
    const layoutH = v.layoutHeight ?? v.height;

    const lost = Math.max(0, layoutH - v.height);

    bar.textContent =
`visible:  ${v.width}×${v.height}
layout:   ${layoutW}×${layoutH}
lost:     ${lost}px
keyboard: ${v.isKeyboardOpen}
stable:   ${v.isStable}`;
  });
</script>

Features

A few concrete, technical reasons it behaves well on mobile:

  • Tiny: ~< 2 KB min+gzip (check the Bundlephobia badge).
  • Fast updates: emits at most 1 update per animation frame (rAF throttling).
  • Zero runtime deps: 0 dependencies at runtime (tree-shakeable ESM).
  • Stable signal: isStable flips after 150ms (default) without geometry changes.

API (short)

Core snapshot fields you’ll typically use:

  • width, height — visible viewport size (CSS px)
  • layoutWidth, layoutHeight — layout viewport (basis for keyboard detection)
  • isKeyboardOpen — geometry-based keyboard inference
  • isStable — “animations settled” signal for UI decisions

Vanilla store:

  • createViewportTruth() from viewport-truth/vanilla → creates a store with subscribe() and destroy()

Framework adapters:

  • React: useViewportTruth from viewport-truth/react
  • Vue: useViewportTruth from viewport-truth/vue
  • Svelte: viewportTruth from viewport-truth/svelte
  • Solid: createViewportTruth from viewport-truth/solid
  • Angular: ViewportTruthDirective from viewport-truth/angular

Full types and signatures: see dist/*.d.ts (or TypeScript IntelliSense).

Adapter Docs: ReactVueSvelteSolidAngular

Tip: Open links in a new tab with Ctrl+Click (Windows/Linux) or Cmd+Click (macOS).

Links

FAQCommon pitfallsSmoke test (clean environment)Versioning policy

Support the project

“We ate the Geometry Hell for you: jumping 100vh, jittery resize, modals under the keyboard.
You saved hours (and sanity). A donation is a fair trade for a rock-solid UI and weekends free from debugging.”

If this library saved you time, please consider supporting the development:

  1. Fiat (Cards/PayPal): via Boosty (one-time or monthly).
  2. Crypto (USDT/BTC/ETH): view wallet addresses on Telegram.

Support on Boosty Crypto via Telegram

License

MIT