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 🙏

© 2024 – Pkg Stats / Ryan Hefner

element-size-reporter

v0.14.6

Published

Reports width, height, and top for selected DOM elements

Downloads

220

Readme

Element Size Reporter

npm version Verify Coverage Status

Reports rendered size (width, height, also top) for a DOM element or group of elements.

No dependencies.

Use in a component to report on a DOM element's size. Can use in concert with other components to calculate a region composed of multiple component's DOM elements. This is especially useful for calculating image dimensions that span multiple DOM elements in multiple components.

Use with React/Flux

I use this in a React flux flow to calculate background image dimensions and position spanning multiple components and elements for calls to an image service (Cloudinary) in conjunction with react-element-size-reporter.

API

createSizeReporter (selector, reporter, options)

Returns a size reporter function that creates a Size Report of the rendered element found for given selector. Sends the report to reporter when executed.

Parameters

selector - {String} A CSS selector that finds the DOM element to report size on.

reporter - {Function} The function that receives the Size Report.

options - {Object} See Options.

Size Report

A single object that contains the following properties:

width - {Number} The width of the DOM element selected. Computed as the difference of the selected element bounding client rect (left from right).

height - {Number} The height of the DOM element selected. Computed as the difference of the selected element bounding client rect (top from bottom).

top - {Number} The top to the DOM element selected. Computed as:

  selectedElement.getBoundingClientRect().top + window.pageYOffset - document.documentElement.clientTop;

accumulate - {Boolean} True if the data should be combined with previous data sent. Ignore this flag if you are not using grouped, multiple DOM elements.

Options

group - {String} An identifier that uniquely names a group of size reporters. This allows widths, heights, and/or tops from multiple components to be accumulated. Element Size Reporter tracks these groups and sends along an accumulate flag in the report for multiple reporting. Defaults to 'global'. If you don't care about grouping multiple DOM elements, just ignore the accumulate flag in the report.

reportWidth - {Boolean} True to have the reporter include width in the report data.

reportHeight - {Boolean} True to have the reporter include height in the report data.

reportTop - {Boolean} True to have the reporter include top in the report data.

grow - {Object} Options that control the arbitrary expansion the reported sizes. Specifically, width and height are increased, top is decreased. Use to reduce/conform image requests, or just otherwise smooth or adjust the reported size.

grow.width - {Number} The nearest multiple to expand the width to. Example: If this is 10, then 92 gets expanded to 100, the next highest multiple of 10.

grow.height - {Number} The nearest multiple to expand the height to.

grow.top - {Number} The nearest multiple to expand the top to.