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

screen-scaler

v1.3.3

Published

One-size-fit-all web design: Screen-size agnostic development environment.

Downloads

417

Readme

https://github.com/garronej/screen-scaler/assets/6702424/d15945b2-e1ac-4e93-a08f-20120a1e01de

Motivation and Warning

Screen-Scaler is a niche tool designed for very specific use cases. It enables you to design your application as though every user has the same screen size, automating the adjustment process for different screen dimensions by scaling your app to fit. While this can significantly streamline development for certain projects, it is not a replacement for responsive design and is not recommended for general-purpose applications.

Responsive design remains the gold standard for creating web applications that offer the best user experience across a wide range of devices. Screen-Scaler should be considered either a temporary hack or a solution for projects where user screens are highly uniform and predictable.

Features

  • 📏 Automatically scales your app to fit any screen size that differs from your target resolution.
  • 🎭 Fully spoofs DOM APIs to emulate your specified settings.
  • 🔌 Requires no changes to your existing code base; it's a simple function call and integrates seamlessly with any CSS Framework and UI library.
  • 🛠️ Offers flexibility by enabling scaling only for specific screen size ranges. For instance, if your app renders well on large screens but breaks on smaller ones, you can activate scaling only for screen widths below 1000px.
  • ♿ Preserves accessibility features, allowing users to zoom in and out with ctrl + mouse wheel or ⌘ + '+/-', provided you enable this functionality (and you should).

Usage

Make it so that your app is always rendered as if the user had a screen resolution width of 1920.

import { enableScreenScaler } from "screen-scaler";

enableScreenScaler({
    // The zoom factor is for supporting when the user zooms in or out (ctrl + mouse wheel or ⌘ + '+' or ⌘ + '-') ...
    targetWindowInnerWidth: ({ zoomFactor }) => 1920 * zoomFactor,

    // If you don't want to enables your user to zoom you can provide an absolute value
    //targetWindowInnerWidth: 1920

    // This is the id of the root div of your app. With modern frameworks it's usually "root" or "app".
    rootDivId: "app"
});

Run the test App

git clone https://github.com/garronej/screen-scaler
cd screen-scaler
yarn
yarn start-test-app

Screen scaler is setup in the src/index.tsx file.

Limitations and workarounds

Server side rendering

SSR isn't supported, if in Next.js you will have to wrap your all app in a no-ssr component.

vh and vw CSS properties

The use of vh and vw CSS properties is not supported, they can't be spoofed.

If you where using 100vh to make your app take the full height of the screen, you can use the following workaround:

 root.render(
   <React.StrictMode>
     <div style={{
        overflow: "hidden",
-       height: "100vh"
+       height: "100%", // Or height: window.innerHeight
     }}>
     </div>
   </React.StrictMode>
 );

Portrait mode

When your app is rendered in a device in portrait mode, if you haven't accommodated for this your app will appear very tiny at the top of the screen and most of the screen will be unused.

In this case, you have two options:

1: Implement a portrait mode version of your app. 2: Tell your user to rotate their device:

import { enableScreenScaler } from "screen-scaler/react";

const { ScreenScalerOutOfRangeFallbackProvider } = enableScreenScaler({
    rootDivId: "root",
    targetWindowInnerWidth: ({ zoomFactor, isPortraitOrientation }) =>
        isPortraitOrientation ? undefined : 1920 * zoomFactor
});

export function App() {
    return (
        <ScreenScalerOutOfRangeFallbackProvider
            fallback={<h1>Please Rotate your phone, this app does not render well in portrait mode.</h1>}
        >
            {/* Your app here */}
        </ScreenScalerOutOfRangeFallbackProvider>
    );
}

NOTE: We provide this example using the dedicated React adapter. To do that in another framework you will need to replace your app by a fallback element when your targetWindowInnerWidth returns undefined. If you'd like an adapter for your framework of choice, please open an issue.

Readability issues

The issue with scaling down your app is that the text becomes increasingly smaller as the screen size decreases. Conversely, on very large screens, everything appears disproportionately large, creating the impression that the app is designed for children. These issues can be mitigated by dynamically adjusting the target width.

enableScreenScaler({
    // Example: Disabling the scaling for screen width above 1100px
    targetWindowInnerWidth: ({ actualWindowInnerWidth }) => Math.max(windowInnerWidth, 1100)
});

Showcases

This library has been used to build the following projects:

Contributing

git clone https://github.com/garronej/screen-scaler
cd screen-scaler
yarn

# Start the test app in watch mode
yarn start-test-app

# Link in an external project in watch mode
yarn link-in-app YOUR-APP # ../YOUR-APP is supposed to exist