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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pixi-scale-manager

v1.0.0

Published

A lightweight scaling manager for PixiJS

Readme

PixiScaleManager

PixiScaleManager is a lightweight library for scaling and resizing your PixiJS applications. It maintains aspect ratio, supports black bars (letterboxing), stretch mode, and handles orientation changes with callbacks.

Features

  • Responsive Canvas: Automatically resizes your PixiJS canvas to fit the screen.
  • Aspect Ratio Maintenance: Adds black bars (letterboxing or pillarboxing) to maintain proportions.
  • Stretch Mode: Optionally stretch the canvas to fill the screen.
  • Orientation Change Detection: Detects changes in device orientation (landscape or portrait) and triggers callbacks.
  • Custom Callbacks: Notify your application during resizing or orientation changes.

Installation

Install via npm:

npm install pixi-scale-manager

Or include the script directly:

<script src="path/to/pixi-scale-manager.js"></script>

Usage

Basic Example

import PixiScaleManager from 'pixi-scale-manager';

// Initialize your PixiJS application
const app = new PIXI.Application({
    width: 800,
    height: 500,
    backgroundColor: 0x1099bb,
});
document.body.appendChild(app.view);

// Initialize PixiScaleManager
const scaleManager = new PixiScaleManager(app, {
    gameWidth: 800,      // Fixed game width
    gameHeight: 500,     // Fixed game height
    enableBars: true,    // Add black bars (default: true)
    stretch: false,      // Stretch to fill screen (default: false)
    onResize: ({ scaledWidth, scaledHeight }) => {
        console.log(`Canvas resized to: ${scaledWidth}x${scaledHeight}`);
    },
    onOrientationChange: (orientation) => {
        console.log(`Orientation changed to: ${orientation}`);
    },
});

// Add example content
const sprite = PIXI.Sprite.from('path/to/image.png');
sprite.anchor.set(0.5);
sprite.x = 400;
sprite.y = 250;
app.stage.addChild(sprite);

Handling Orientation Changes

To notify users to rotate their device, you can use the onOrientationChange callback:

const rotateMessage = document.createElement('div');
rotateMessage.textContent = 'Please rotate your device for the best experience!';
rotateMessage.style.position = 'absolute';
rotateMessage.style.top = '50%';
rotateMessage.style.left = '50%';
rotateMessage.style.transform = 'translate(-50%, -50%)';
rotateMessage.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
rotateMessage.style.color = 'white';
rotateMessage.style.padding = '20px';
rotateMessage.style.borderRadius = '10px';
rotateMessage.style.fontSize = '18px';
rotateMessage.style.display = 'none';
document.body.appendChild(rotateMessage');

const scaleManager = new PixiScaleManager(app, {
    gameWidth: 800,
    gameHeight: 500,
    enableBars: true,
    onOrientationChange: (orientation) => {
        if (orientation === 'portrait') {
            rotateMessage.style.display = 'block';
        } else {
            rotateMessage.style.display = 'none';
        }
    },
});

Options

| Option | Type | Default | Description | |------------------------|------------|----------|-------------| | gameWidth | number | 800 | Fixed width of the game. | | gameHeight | number | 500 | Fixed height of the game. | | enableBars | boolean | true | Whether to add black bars for maintaining aspect ratio. | | stretch | boolean | false | Whether to stretch the canvas to fill the screen. | | onResize | Function | () => {} | Callback triggered when resizing occurs. | | onOrientationChange | Function | () => {} | Callback triggered when orientation changes. |

License

This project is licensed under the MIT License. See the LICENSE file for details.


Happy coding! 🎉