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

css-screensize

v1.1.0

Published

Capture CSS `<number>` vars for screen --width and --height. 100% CSS, Zero JS

Downloads

45

Readme

Jane Ori - PropJockey.io

css-screensize

Capture CSS <number> vars for screen --width and --height. 100% CSS, Zero JS

Useful for any 100% CSS game or environment without JS that needs --width and --height vars.

Setup

For small projects, use your favorite NPM CDN and import it either from HTML or CSS:

HTML:

<link rel="stylesheet" type="text/css" href="https://unpkg.com/css-screensize@1/screensize.css">

or CSS:

@import url("https://unpkg.com/css-screensize@1/screensize.css");

For typical projects, install and import:

$ npm install css-screensize Then include the /node_modules/css-screensize/screensize.css file anywhere in the project.

Usage

Place the following HTML anywhere on the page:

<ol class="css-screensize" aria-hidden="true"><li><li><p><p><p><p><li><li></ol>

If you prefer cleaner/less minified markup, or different elements, as long as the dom shape is equivelant, with css-screensize class on the base, any elements will do.

css-screensize will prompt the user to :hover on the page until the size is captured.

Once captured, css-screensize disappears and :root will have --width and --height vars with integer values equivelent to the number of pixels in that dimension.

calc(var(--width) * 1px) is equal to the computed pixel size of 100vw

calc(var(--height) * 1px) is equal to the computed pixel size of 100vh

If the window resizes more than 3px, css-screensize will reappear and prompt for :hover again automatically.

You can (should) customize the appearance of the prompt by adding CSS to your page like so:

.css-screensize {
  --enable: 1;
  --opacity: 0.9;
  --background: hotpink;
  --prompt: "Screensize Required\A~ please :hover ~";
  --confirm: "...Capturing Screensize";
}

The values shown here are the defaults. You can disable it by setting --enable: 0; or set --opacity: 0; so the users can't see that it's happening. (though they will be unable to interact with the screen for about 100ms)

--prompt and --confirm are setting the content property of a pseudo element so they could be url-wrapped images (like a loading spinner gif) if prefered over strings.

Additionally, the default behavior is fixed position and covering the whole screen with a transform: scale(2) too. If you wish to make the user hover in a specific area within your UI, place the markup in your containing element, set your container to position: relative; (or similar) and add a contained class to the css-screensize element:

<div class="my-container">
  <ol class="css-screensize contained" aria-hidden="true"><li><li><p><p><p><p><li><li></ol>
</div>

css-screensize will then render position absolute and inset 0px, without the scale(2).

Here is a gif screen recording of the default, contained, css-screensize setting counter() values to the --width and --height of the window:

gif of css-screensize in action, demonstrates the user hovering in the contained css-screensize area and the numbers updating as well as resizing and being re-prompted to hover again