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

@basementuniverse/view-port

v1.1.0

Published

A viewport into worldspace, for rendering chunks in games.

Readme

view-port

A viewport into worldspace, for rendering chunks in games.

If you're rendering tile-based worlds, the @basementuniverse/tile-map package is a better choice since it contains tile-map specific functionality.

This package is more general-purpose; it provides a ViewPort class which calculates which chunks are visible, generates new chunks if necessary, and updates/draws them.

Installation

npm install @basementuniverse/view-port

How to use

See the example for a complete example of how to use the ViewPort class.

Create a viewport:

const viewPort = new ViewPort(options);

Update it every frame:

function update(deltaTime) {
  viewPort.update(deltaTime, screenSize, camera);
}

Draw it every frame:

function draw(context) {
  viewPort.draw(context, screenSize, camera);
}

Get the visible chunks:

const visibleChunks = viewPort.getVisibleChunks(camera);

Options

export type ViewPortOptions<T extends ViewPortChunk = any> = {
  /**
   * The size of each grid cell in world units.
   *
   * Default is (100, 100)
   */
  gridSize: vec2;

  /**
   * A function that generates a chunk for a given grid cell coordinate.
   *
   * Default is a function that returns an empty object.
   *
   * `v` is in grid-cell coordinates.
   */
  generator: (v: vec2) => T;

  /**
   * Buffer area around the viewport in grid cells. Chunks within this area
   * will also be generated and updated.
   */
  border: number;

  /**
   * The number of chunks to store in the spatial hash buffer before old chunks
   * are removed. This should be at least the number of chunks that can be
   * visible at once, plus the buffer area.
   */
  bufferAmount: number;

  /**
   * The maximum number of chunks to generate per update. This is to prevent
   * performance issues when the camera moves quickly and many chunks need to
   * be generated at once.
   */
  maxElementsToGenerate: number;

  /**
   * The maximum number of elements to store in the spatial hash.
   */
  spatialHashMaxElements: number;

  /**
   * The maximum number of elements to remove from the spatial hash when it
   * exceeds the maximum number of elements.
   */
  spatialHashMaxElementsToRemove: number;

  /**
   * Optional debug options
   *
   * Can be a boolean value (in which case all sub-options will be set to the
   * same value), or an object allowing specific debug options to be enabled
   * individually
   */
  debug?: Partial<ViewPortDebugOptions> | boolean;
};