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

scream

v2.11.1

Published

Dynamic viewport management for mobile. Manage viewport in different states of device orientation. Scale document to fit viewport. Calculate the dimensions of the minimal iOS 8 view relative to your viewport width.

Downloads

1,092

Readme

Scream

NPM version

Dynamic viewport management for mobile.

  • Manage viewport in different states of device orientation.
  • Scale document to fit viewport.
  • Calculate the dimensions of the "minimal" iOS 8 view relative to your viewport width.

Demonstration using iOS simulator

Contents

Managing the Viewport

Configure management and dimensions of the viewport at the time of the initialization:

import Scream from 'scream';

const scream = Scream({
    viewport: true,
    width: {
        portrait: screen.width,
        landscape: screen.height
    }
});

If enabled, scream generates the viewport meta tag to reflect the present orientation and in response to the orientationchangeend event.

<meta name="viewport" content="width={width},initial-scale={scale},minimum-scale={scale},maximum-scale={scale},user-scale=0">
  • {width} the width set in the configuration for the current orientation.
  • {scale} calculated scale needed to fit the document in the screen.

Configuration

| Name | Description | Default | | --- | --- | --- | | viewport | Manage the viewport of the page. | true | | width.portrait | Viewport width in the portrait orientation. | screen.width (device-width) | | width.landscape | Viewport width in the landscape orientation. | screen.width (device-width) |

Safe Area Insert

With the introduction of devices with a notch, there is now the concept of viewport-fit=cover and safe-area-inset as explained here:

https://webkit.org/blog/7929/designing-websites-for-iphone-x/

This adds additional complexity as applying the viewport width needed for the minimal view calculation can cause content to clash with the notch in landscape mode. It is possible to calculate the padding required to prevent this clash in JavaScript but this only works if viewport-fit=cover is set and this may have an undesirable effect on the layout of the page.

Scream attempts to calculate the notch padding by first adding viewport-fit=cover to the viewport and then replacing it with the width of the safe area. This works well in most cases but may be undesirable if the notch has already been taken into account in the page design. In this case, it is recommended to manage the viewport tag manually by setting viewport: false and applying the relevant safe-area-inset padding with CSS.

Events

Orientation Change

The orientationchangeend event is fired when the orientation of the device has changed and the associated rotation animation has been complete.

– https://github.com/gajus/orientationchangeend

This is proxy for your convenience to perform operations that must follow the change of the device orientation and in the context of updated viewport tag. This is required when determining the view state.

scream.on('orientationchangeend', () => {
    // Invoked after the orientation change and the associated animation (iOS) has been completed.
});

View Change

Invoked on page load and when view changes.

scream.on('viewchange', (e) => {
    // @var {String} 'full', 'minimal'
    e.viewName;
});

Unregister the event

The on method returns a listener object that you can use to unregister your event handler calling the method off.

const listener = scream.on('viewchange', (e) => { /* your code */ });

// to unregister:

scream.off(listener);

Screen

/**
 * @return {String} portrait|landscape
 */
scream.getOrientation();

/**
 * Screen width relative to the device orientation.
 *
 * @return {Number}
 */
scream.getScreenWidth();

/**
 * Screen width relative to the device orientation.
 *
 * @return {Number}
 */
scream.getScreenHeight();

/**
 * Returns padding needed to prevent content from clashing with notch.
 *
 * @return {Number}
 */
scream.getNotchPadding();

Viewport

/**
 * Viewport width relative to the device orientation.
 *
 * @return {Number}
 */
scream.getViewportWidth();

/**
 * Viewport height relative to the device orientation and to scale with the viewport width.
 *
 * @return {Number}
 */
scream.getViewportHeight();

/**
 * The ratio between screen width and viewport width.
 *
 * @return {Number}
 */
scream.getScale();

Minimal View

This functionality is iOS 8 specific. It has been developed as part of Brim to bring back the minimal-ui.

/**
 * Returns dimensions of the usable viewport in the minimal view relative to the current viewport width and orientation.
 *
 * @return {Object} dimensions
 * @return {Number} dimensions.width
 * @return {Number} dimensions.height
 */
scream.getMinimalViewSize();

/**
 * Returns true if screen is in "minimal" UI.
 *
 * iOS 8 has removed the minimal-ui viewport property.
 * Nevertheless, user can enter minimal-ui using touch-drag-down gesture.
 * This method is used to detect if user is in minimal-ui view.
 *
 * In case of orientation change, the state of the view can be accurately
 * determined only after orientationchangeend event.
 *
 * @return {Boolean}
 */
scream.isMinimalView();

Download

Using NPM:

npm install scream