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.
npm install viewport-dimensionsVerified import paths — ran on the pinned version, not inferred.
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()`.
Consider using a more modern, actively maintained library for viewport dimension tracking or implementing a custom solution using modern browser APIs (e.g., Resize Observer for element dimensions, `window.innerWidth`/`innerHeight` for viewport).
Understand the distinction: `documentElement.clientWidth` provides content area dimensions. If scrollbars are needed in your calculation, directly use `window.innerWidth` and `window.innerHeight`.
In an ESM project, if you must use this library, import CommonJS modules using `import viewport from 'viewport';` (if your build tool supports CJS interop) or `const viewport = require('viewport');` if running directly in Node.js with a CommonJS context or using dynamic `import()`.Ensure your environment supports CommonJS or use a bundler (like Webpack/Rollup) that handles CommonJS modules. If in an ESM project, you might need to configure your bundler for CommonJS interop or use `import()` for dynamic loading.
Verify the package is installed (`npm i -S viewport-dimensions`), the import path is `require('viewport')` (not `viewport-dimensions`), and that the code is executing in a browser-like environment.Ensure the package is installed via `npm i -S viewport-dimensions` and imported specifically as `require('viewport')`, as the internal module name differs from the npm package name.No dependency data recorded yet.