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

@telemok/calc-dom-element-content-size

v0.0.1

Published

JS

Downloads

8

Readme

calc-dom-element-content-size (beta version)

JS bit addressing DataView+Stack+Queue+Buffer with any types: Uint13, Int53, BigInt61, Float17, LSB/MSB, LE/BE, .set(), .get(), .push(), .pop(), .shift(), .unshift()

Features

  • Calculate width and height size of: content, padding, border, margin.
  • Calculate with any css "display": "none", "inline", "block", ...
  • Calculate with any css "box-sizing": "content-box", "border-box".
  • More accuracy, then expression: element.clientWidth - (pl + pr) from https://stackoverflow.com/questions/25197184
  • Fast calls: 112K / second. (block and border-box, Ryzen 5500U, Firefox 109 x64)

Schema

content-padding-border-margin

Examples:

Available in folder /examples/

1. Basic calculation

<div class="container">
    <div id=div1 style="display: block;box-sizing:border-box;">
        block, border-box
    </div>
</div>
<script type="module">
    import {calcElementSize} from "./../lib/calc-dom-element-content-size.js"
    //import { calcElementSize } from '@telemok/calc-dom-element-content-size';
    console.log(calcElementSize(div1));
		
</script>
<style>
.container{
	background:green;
	overflow:auto;
	height: 100%;
}
#div1, #div2, #div3{
	width:200px;
	height:100px;
	padding:20px;
	border:#f70 10px solid;
	background-color:#dab;
	outline:#000 2px solid;
	margin:5px;
}
</style>
</html>

2. Result of example1

let result = calcElementSize(element, throwIfDisplayNone = true);
result === {
    "display": "block",
    "boxSizing": "content-box",
    "wP": 40, /* Width of padding */
    "hP": 40, /* Height of padding */
    "wB": 19.2, /* Width of border */
    "hB": 19.2, /* Height of border */
    "wM": 10, /* Width of margin */
    "hM": 10, /* Height of margin */
    "wC": 200, /* Width of content */
    "hC": 100, /* Height of content */
    "wCP": 240, /* Width of content + padding */
    "hCP": 140, /* Height of content + padding */
    "wCPB": 259.2, /* Width of content + padding + border */
    "hCPB": 159.2, /* Height of content + padding + border */
    "wCPBM": 269.2, /* Width of content + padding + border + margin */
    "hCPBM": 169.2, /* Height of content + padding + border + margin */
    /* return more accuracy next 6 lines float instead of integer*/
    "clientWidth": 240, // https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth
    "clientHeight": 140, // https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight
    "offsetWidth": 259.2, // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth
    "offsetHeight": 159.2, // https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight
    "scrollWidth": 240, // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
    "scrollHeight": 140 // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
}

Source code:

https://npmjs.com/@telemok/calc-dom-element-content-size

Installation #1:

  1. Create your Browser or Webview app.
  2. Run: npm import @telemok/calc-dom-element-content-size
  3. Code: import { calcElementSize } from '@telemok/calc-dom-element-content-size';
  4. Code: calcElementSize(youElement)

Installation #2:

  1. Create your NodeJs, Browser or Webview app.
  2. Code: <SCR(.md bug, del it)IPT type="module">
  3. Code: import { calcElementSize } from "https://cdn.jsdelivr.net/npm/@telemok/calc-dom-element-content-size/lib/calc-dom-element-content-size.js";
  4. Code: calcElementSize(youElement)

Another libs another authors:

300k/week oldest analog, but don't support display:inline, calc only C and CPBM, no debug functions https://npmjs.com/package/get-size

https://plainjs.com/javascript/styles/getting-width-and-height-of-an-element-23/ https://stackoverflow.com/questions/13435604/getting-an-elements-inner-height https://npmjs.com/package/b-box

300k/week crossbrowser getComputedStyle tested with invisibleIframe too. https://npmjs.com/package/computed-style

Only display:block and content-sizing:border-box? https://npmjs.com/package/element-coordinates