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 🙏

© 2026 – Pkg Stats / Ryan Hefner

element-scale

v1.0.0

Published

A lightweight element scaling library that automatically adjusts element size based on device pixel ratio

Readme

element-scale

npm version License: MIT GitHub stars

A lightweight element scaling library that automatically adjusts element size based on device pixel ratio, designed for high-DPI displays and responsive layouts.

Features

  • 🚀 Automatic scaling based on window.devicePixelRatio
  • 🎯 Supports both CSS transform: scale() and zoom properties
  • 📐 Built-in ResizeObserver for responsive scaling
  • 🖼️ Automatic canvas handling with inverse scaling
  • 📦 Lightweight with zero dependencies
  • 🔒 TypeScript support with full type definitions

Installation

npm install element-scale

or

pnpm add element-scale

or

yarn add element-scale

Usage

Basic Usage

import { startScale, ElementScale } from 'element-scale';

const container = document.getElementById('container') as HTMLElement;

const scaleInstance = startScale({
  elements: ['.box', '#header', document.querySelector('.footer') as HTMLElement],
  container: container
});

With Options

import { startScale } from 'element-scale';

const container = document.getElementById('container') as HTMLElement;

const scaleInstance = startScale({
  elements: ['.box', '#header'],
  container: container,
  useZoom: true,
  minScale: 0.5,
  maxScale: 1,
  targetScale: 1,
  callback: (scale, elements) => {
    console.log(`Current scale: ${scale}`);
  }
});

Class API Usage

import { ElementScale } from 'element-scale';

const container = document.getElementById('container') as HTMLElement;

const scaleManager = new ElementScale({
  elements: ['.box', '#header'],
  container: container,
  useZoom: false,
  minScale: 0.6,
  maxScale: 1,
  targetScale: 1,
  callback: (scale, elements) => {
    console.log('Scale updated:', scale);
  }
});

// Later, to destroy the instance
scaleManager.destroy();

Destroy Scale

import { startScale } from 'element-scale';

const container = document.getElementById('container') as HTMLElement;
const scaleInstance = startScale({
  elements: ['.box'],
  container: container
});

// Destroy after 5 seconds
setTimeout(() => {
  scaleInstance.destroy();
}, 5000);

API

startScale(options)

Creates and starts an ElementScale instance.

startScale(options: ElementScaleOptions): ElementScale

new ElementScale(options)

Class constructor for more control over the scaling instance.

constructor(options: ElementScaleOptions)

ElementScaleOptions

| Property | Type | Default | Description | |----------|------|---------|-------------| | elements | ScaleElement[] | Required | Array of elements to scale (CSS selectors or HTMLElement) | | container | HTMLElement | Required | Container element to observe for resize events | | useZoom | boolean | true | Use CSS zoom instead of transform: scale() | | minScale | number | 0.6 | Minimum scale factor | | maxScale | number | 1 | Maximum scale factor | | targetScale | number | 1 | Target scale factor for calculation | | callback | (scale: number, elements: ScaleItem[]) => void | undefined | Callback function called when scale changes |

ScaleElement

type ScaleElement = string | HTMLElement;
  • string: CSS selector (e.g., .box, #header)
  • HTMLElement: Direct DOM element reference

ScaleItem

interface ScaleItem {
  el: HTMLElement;
  reset: () => void;
  update: (scale: number) => void;
}

Methods

runScale()

Manually trigger scale recalculation.

scaleInstance.runScale(): void

destroy()

Stop scaling, clean up observers, and reset all elements.

scaleInstance.destroy(): void

Properties

isInitialized

Check if the instance is initialized.

scaleInstance.isInitialized: boolean

How It Works

  1. Device Detection: Detects the operating system (Mac or Windows)
  2. DPR Calculation: Gets window.devicePixelRatio with fallback for older browsers
  3. Scale Calculation: Computes scale factor using formula: min(maxScale, max(targetScale / dpr, minScale))
  4. Auto-observation: Uses ResizeObserver to monitor container size changes
  5. Canvas Handling: Automatically applies inverse scaling to canvas elements within the container

Scale Rules

  • Scale ≥ 1: No scaling applied, all styles are reset
  • Scale < 1: Elements are scaled down using either transform: scale() or zoom based on the useZoom option
  • Canvas elements: Inversely scaled (multiplied by 1/scale) to maintain clarity at high DPI

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 13.1+
  • Edge 79+

Requires ResizeObserver support. For older browsers, consider using a polyfill.

Type Definitions

Full TypeScript type definitions are included and exported:

import type { 
  ScaleElement, 
  ScaleItem, 
  ElementScaleOptions, 
  DestroyScale 
} from 'element-scale';

License

MIT © SinJayXie