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

@usirin/layout-tree

v0.2.0

Published

Layout tree management for UI components

Downloads

24

Readme

@usirin/layout-tree

Data structure for tiled window layouts.

pnpm add @usirin/layout-tree

Example

Create a layout like this:

*---------*---------*---------*
|         |    B    |         |
|         *---------*         |
|    A    |    C    |    E    |
|         *---------*         |
|         |    D    |         |
*---------*---------*---------*
import { createTree, createStack, createWindow } from '@usirin/layout-tree'

const tree = createTree(
  createStack('horizontal', [     // children flow left-to-right: A -> (BCD) -> E
    createWindow('A'),
    createStack('vertical', [     // children flow top-to-bottom: B -> C -> D
      createWindow('B'),
      createWindow('C'),
      createWindow('D')
    ]),
    createWindow('E')
  ])
)

Types

Orientation

type Orientation =
  | 'vertical'    // stack children top-to-bottom
  | 'horizontal'  // stack children left-to-right

Direction

type Direction =
  | 'up'     // sibling above
  | 'down'   // sibling below
  | 'left'   // sibling to the left
  | 'right'  // sibling to the right

Window

interface Window extends Entity<"window"> {
  key: string;
}

Stack

interface Stack extends Entity<"stack"> {
  orientation: Orientation;
  children: (Window | Stack)[];
}

Tree

interface Tree extends Entity<"tree"> {
  root: Stack;
}

Operations

Split

Split a window vertically (create new window below) or horizontally (create new window to the right):

import { split } from '@usirin/layout-tree'

// vertical split (top-to-bottom)
let newTree = split(tree, [0], 'vertical')

/*
Before:          After:
*---------*     *---------*
|         |     |    A    |
|    A    |     *---------*
|         |     |    B    |
*---------*     *---------*
*/

// horizontal split (left-to-right)
newTree = split(tree, [1], 'horizontal')

/*
Before:          After:
*---------*     *---------*---------*
|    A    |     |         A         |
*---------*     |-------------------|
|    B    |     |    B    |    C    |
*---------*     *---------*---------*
*/

Find

Get a window by path or find siblings in any direction:

import { getAt, findSibling } from '@usirin/layout-tree'

// get window at path [0, 1]
const window = getAt(tree.root, [0, 1])

// find siblings
const up = findSibling(tree, [0], 'up')      // sibling above
const right = findSibling(tree, [0], 'right') // sibling to the right

Move & Swap

Move windows around or swap their positions:

import { moveBefore, moveAfter, swap } from '@usirin/layout-tree'

// move B before A
let newTree = moveBefore(tree, [1], [0])

/*
Before:          After:
*-----*-----*   *-----*-----*
|  A  |  B  |   |  B  |  A  |
*-----*-----*   *-----*-----*
*/

// swap A and B
newTree = swap(tree, [0], [1])

Remove

Remove a window from the tree:

import { remove } from '@usirin/layout-tree'

const newTree = remove(tree, [0, 1])

/*
Before:             After:
*-----*-----*      *---------*
|  A  |  B  |      |    A    |
*-----*-----*      *---------*
*/

Path Navigation

Paths are arrays of indices that describe the location of a window in the tree:

// In this layout:
// *---------*---------*
// |    A    |    B    |
// *----*----*---------*
// | C  | D  |    E    |
// *----*----*---------*

[0]     // window A
[1]     // window B
[0, 0]  // window C
[0, 1]  // window D
[1, 0]  // window E

License

MIT