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

pixijs-layout

v0.2.0

Published

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samwho/pixijs-layout/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/pixijs-layout.svg?style=flat)](https://www.npmjs.com/package/pixijs-layout) [![B

Downloads

19

Readme

pixijs-layout

GitHub license npm version Build status Coverage

This library is designed to make laying out elements on a canvas very easy. I've been using PixiJS to write visual explanations of programming concepts over at https://samwho.dev, and this library tailors specifically to my use-case.

I tried https://pixijs.io/layout/ and found it didn't easily suit the work I was trying to do.

Installation

npm install pixijs-layout

Examples

The tests for this project are the best place to find examples. Every test renders a component to a canvas and saves an image of it in the screenshots/ directory. All tests are in tests.ts and each screenshot is named directly after the test.

All of the examples will assume the following structure:

import * as PIXI from "pixi.js";

let canvas = document.createElement("canvas");
canvas.width = 800;
canvas.height = 600;
document.body.appendChild(canvas);

let app = new PIXI.Application({
  autoStart: false,
  forceCanvas: true,
  view: canvas,
  resizeTo: canvas,
  backgroundColor: 0xffffff,
});

app.renderer.resize(800, 600);

let component = null; // <example code goes here>

app.stage.addChild(component);
component.arrange(app.screen);

They also assume the existence of the following helper:

import * as PIXI from "pixi.js";

export function circle({
  x,
  y,
  radius,
}: {
  x?: number;
  y?: number;
  radius?: number;
} = {}): PIXI.Graphics {
  let circle = new PIXI.Graphics();
  circle.beginFill(0xff0000);
  circle.drawCircle(x ?? 0, y ?? 0, radius ?? 50);
  circle.endFill();
  return circle;
}

HStack

import { HStack } from "pixijs-layout";

let component = HStack(circle(), circle(), circle()).leaves((leaf) =>
  leaf.fit().padding("5%"),
);

VStack

import { VStack } from "pixijs-layout";

let component = VStack(circle(), circle(), circle()).leaves((leaf) =>
  leaf.fit().padding("5%"),
);

HStacks in a VStack

import { VStack, HStack } from "pixijs-layout";

let component = VStack(
  HStack(circle(), circle(), circle()),
  HStack(circle(), circle(), circle()),
  HStack(circle(), circle(), circle()),
).leaves((leaf) => leaf.fit().padding("5%"));

Grid

import { Grid } from "pixijs-layout";

let component = Grid(
  circle(),
  circle(),
  circle(),
  circle(),
  circle(),
  circle(),
  circle(),
  circle(),
  circle(),
).leaves((leaf) => leaf.fit().padding("5%"));

Grid within a grid

import { Grid } from "pixijs-layout";

let component = Grid(
  circle(),
  circle(),
  circle(),
  Grid(circle(), circle(), circle(), circle()),
).leaves((leaf) => leaf.fit());

Debugging complex layouts

The .debug() modifier on a stack will add light grey backgrounds to show how the screen is being divided. The more nested the stack, the darker the grey.

import { Grid } from "pixijs-layout";

let component = Grid(
  HStack(circle(), circle()),
  VStack(circle(), HStack(circle(), circle())),
  Grid(
    circle(),
    circle(),
    circle(),
    Grid(circle(), circle(), circle(), circle()),
  ),
  Stack(
    Stack(circle(), circle(), circle()),
    Stack(circle(), circle(), circle()),
    Stack(circle(), circle(), circle()),
  ),
)
  .debug()
  .leaves((leaf) => leaf.fit().padding("10%"));