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

@leptoquark1/openage-pfadfinder

v2.1.0

Published

TypeScript port of the Pathfinding Subsystem

Readme

openage Pfadfinder

npm GitHub license npm

TypeScript port of the Pathfinding Subsystem

A dependency-free, native ESM TypeScript library implementing two-stage hierarchical flow-field pathfinding — a port of the openage pathfinding system based on Crowd Pathfinding and Steering Using Flow Field Tiles by Elijah Emerson.

Learn more about the underlying Pathfinding in openage Documentation or use the interactive Guide in the interactive Demo.

→ Try the interactive Demo

Installation

pnpm add @leptoquark1/openage-pfadfinder
npm install @leptoquark1/openage-pfadfinder
yarn add @leptoquark1/openage-pfadfinder

The package is ESM-only and ships TypeScript declarations.

Usage

import { Pathfinder, Grid, Sector, CostField, COST_MIN, COST_IMPASSABLE } from '@leptoquark1/openage-pfadfinder';

// Create a 4×4 grid with 10×10 sectors
const grid = new Grid(0, { width: 4, height: 4 }, 10);

// Populate sectors with cost fields
let sectorId = 0;
for (let sy = 0; sy < 4; sy++) {
  for (let sx = 0; sx < 4; sx++) {
    const cf = new CostField(10);
    cf.setCosts(new Uint8Array(100).fill(COST_MIN));
    grid.addSector(new Sector(sectorId++, { x: sx, y: sy }, cf));
  }
}

// Initialize portals and portal graph
grid.initPortals();
grid.initPortalNodes();

// Create pathfinder
const pathfinder = new Pathfinder();
pathfinder.addGrid(grid);

// Find a path
const path = pathfinder.getPath({
  gridId: 0,
  start: { ne: 2, se: 3 },
  target: { ne: 35, se: 28 },
});

console.log(path.result); // PathResult.FOUND (0)
console.log(path.waypoints); // [{ ne: 2, se: 3 }, { ne: 12, se: 10 }, ...]

For the full API reference — every class, field and helper with signatures — see docs/API.md.

Architecture

Two-stage hierarchical pathfinding:

  1. High-Level (Portal A*) — A* search on the portal graph to find which sectors to traverse
  2. Low-Level (Flow Fields) — Per-sector cost → integration → flow field pipeline
PathRequest → Grid → identify start/target sectors
  → Portal A* (high-level path through sectors)
  → Flow-Field integration per sector (low-level directions)
  → Waypoint extraction
  → Path returned

Core Concepts

| Component | Description | | -------------------- | --------------------------------------------------------------------------------------------- | | CostField | Per-cell movement cost (Uint8Array, 1–254 passable, 255 impassable) | | IntegrationField | Accumulated cost from target via wavefront + LOS (Uint16Array + Uint8Array flags) | | FlowField | Per-cell movement direction toward lowest-cost neighbor (Uint8Array, 4-bit dir + 4-bit flags) | | Sector | Square grid subdivision with its own CostField + Portals | | Portal | Bidirectional gateway between adjacent sectors | | Grid | Collection of sectors, manages portal graph | | Integrator | Orchestrates field computation with caching | | Pathfinder | Main interface — getPath() coordinates both stages |

Algorithms

  • LOS Integration — Wavefront with Bresenham line-of-sight shadowcasting
  • Cost Integration — Dijkstra-like wavefront expansion (4-connected)
  • Flow Field Build — Gradient descent on integration costs (8-connected)
  • Portal A* — A* on the portal graph with Euclidean heuristic
  • Field Caching — Integration/flow fields cached per portal-sector pair

Performance

All fields use Typed Arrays (Uint8Array/Uint16Array) matching the C++ uint8_t/uint16_t data layout. The BinaryHeap provides O(log n) priority queue operations for A*.

| Aspect | C++ openage | TypeScript | | ----------------- | ------------------- | ---------------------- | | Cost Field | vector<uint8_t> | Uint8Array | | Integration Cost | uint16_t | Uint16Array | | Integration Flags | uint8_t | Uint8Array | | Flow Field | uint8_t (4+4 bit) | Uint8Array (4+4 bit) | | Priority Queue | PairingHeap | BinaryHeap |

Project structure

packages/pfadfinder/                  Published library (@leptoquark1/openage-pfadfinder)
  src/index.ts                        Public package entry point (subpath ".")
  src/lib/core/                       Cost/integration/flow fields, integrator
  src/lib/graph/                      Grid, Sector, Portal
  src/lib/internal/                   BinaryHeap, Bresenham line
  src/lib/pathfinding/                Pathfinder, portal graph A*, field cache, routing
  src/shared/                         Constants, bit ops, coordinates, cost-map helpers, types
  test/                               Vitest test suite
apps/demo/                            Interactive playground (React + Vite, deployed to GitHub Pages)
docs/                                 API reference, release and benchmark documentation
.github/workflows/                    CI and release automation
.changeset/                           Changesets configuration

Development

Requires Node.js >=20.

pnpm install
pnpm build       # library dist/, also needed by the demo's typecheck and tests
pnpm lint
pnpm typecheck
pnpm test
pnpm test:coverage
pnpm test:perf   # timing-sensitive demo benchmarks (excluded from `pnpm test`)
pnpm benchmark   # updateCosts single vs. batched, Markdown table (`--json` for JSON, `--pretty` for a terminal table)
pnpm benchmark latest         # compare the latest release ("Then") with this build ("Now")
pnpm benchmark <other-build>  # compare another build ("Then") with this one ("Now")
pnpm benchmark --docs         # also write the results to docs/BENCHMARK.md
pnpm check:package

Run everything that CI runs:

pnpm check

Demo

An interactive playground showing the flow-field pathfinding in action: targets, roaming mobs, moving obstacles and a live performance panel.

Running the demo requires a built library:

pnpm build

Run demo with:

pnpm --filter @leptoquark1/openage-pfadfinder-demo dev

Watch both with:

pnpm -r --parallel dev

License

GPL-3.0-or-later (same as openage)