Viewport Dimensions Utility

0.2.0 · abandoned · verified Sun Apr 19

This `viewport-dimensions` utility provides a simple API for retrieving and watching browser viewport dimensions (width, height, vmin, vmax). Unlike `window.innerWidth`, it specifically uses `documentElement.clientWidth` and `documentElement.clientHeight` to report dimensions *excluding* scrollbars, which is a key differentiator. This package is currently at version `0.2.0` and appears to be unmaintained, with its last known activity dating back several years. It primarily targets CommonJS environments and does not natively support modern ES module imports. It offers basic functions like `width()`, `height()`, `min()`, `max()`, and `setDimensions()` to update internal references, making it suitable for simple, browser-based dimension tracking without external dependencies. The low version number and lack of recent updates suggest it is no longer actively developed or maintained.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the `viewport-dimensions` module using CommonJS and retrieve the current width, height, maximum, and minimum viewport dimensions. It also shows how to manually update the dimensions using `setDimensions()`.

// This code should be run in a browser environment or with a CommonJS-compatible runtime.

// 1. Install the package: npm install viewport-dimensions
// 2. Use require() to import it.
const viewport = require('viewport');

console.log('Initial Viewport State:');
console.log('Width:', viewport.width());
console.log('Height:', viewport.height());
console.log('Max Dimension (vmin):', viewport.max());
console.log('Min Dimension (vmax):', viewport.min());

// To simulate a resize event and update dimensions
// In a real browser, you would attach this to window.onresize
function updateAndLogDimensions() {
  viewport.setDimensions(); // Manually update internal dimension references
  console.log('\nViewport dimensions updated:');
  console.log('New Width:', viewport.width());
  console.log('New Height:', viewport.height());
}

// Call it once for demonstration, or attach to window.resize in a browser
// window.addEventListener('resize', updateAndLogDimensions);
updateAndLogDimensions();

// Example of retrieving a dimension again after potential changes
console.log('\nFinal Width (example):', viewport.width());

view raw JSON →