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

@layoutit/polycss-core

v0.0.1

Published

Pure math engine for CSS polygon mesh rendering. Zero browser globals.

Readme

Status: pre-1.0. APIs may still change before a stable 1.0 release.

@layoutit/polycss-core

Framework-agnostic math, parsers, and helpers for CSS polygon-mesh rendering. Zero browser globals: runs in Node, workers, or any JS environment.

This package contains the entire non-rendering side of polycss: OBJ / glTF / GLB / MagicaVoxel parsers, polygon normalization, coplanar merge, Lambert lighting, isometric camera state, and all shared TypeScript types.

When to use directly

Most users install @layoutit/polycss-react, @layoutit/polycss-vue, or @layoutit/polycss (vanilla). Those packages include @layoutit/polycss-core as a transitive runtime dependency and re-export its public types and functions, so you never need to write import ... from "@layoutit/polycss-core" in application code.

Install @layoutit/polycss-core directly when you:

  • Build custom rendering outside React / Vue / vanilla (e.g., a Svelte wrapper, a server-side OBJ validator, a CLI mesh processor).
  • Want only the parsers / math without any rendering layer.
  • Are writing a polycss plugin or tooling that must remain framework-neutral.
npm install @layoutit/polycss-core

Public surface

Types

| Type | Description | |---|---| | Vec2 | [number, number]: 2D point or UV coordinate | | Vec3 | [number, number, number]: 3D point or direction | | Polygon | Single renderable polygon: vertices, optional color, texture, uvs, data | | PolyDirectionalLight | Directional light: direction, optional color, optional intensity | | PolyAmbientLight | Ambient fill light: optional color, optional intensity | | ParseResult | Unified parser return: polygons, objectUrls, dispose(), warnings | | ObjParseOptions | Options for parseObj | | GltfParseOptions | Options for parseGltf | | VoxParseOptions | Options for parseVox | | MtlParseResult | { colors, textures } from parseMtl | | NormalizeResult | { polygons, warnings } from normalizePolygons | | CameraState | Camera target, angles, zoom, and dolly distance | | CameraHandle | Mutable camera object from createIsometricCamera | | AutoRotateOption | boolean | number | { axis, speed, pauseOnInteraction } |

Functions

| Function | Description | |---|---| | normalizePolygons(input) | Validates polygons. Drops degenerate ones, auto-triangulates non-coplanar N-gons, strips mismatched UVs. Returns { polygons, warnings }. | | mergePolygons(polygons) | Coplanar same-material adjacent merge. Reduces DOM element count on flat surfaces. | | computeSceneBbox(polygons) | Computes min/max bounds across all polygon vertices. | | createIsometricCamera(initial?) | Creates a mutable camera handle with state, update(partial), and getStyle(). | | parseObj(text, options?) | Parses OBJ text into ParseResult. Supports UV (vt), materials, map_Kd textures. | | parseMtl(text) | Parses MTL text into { colors, textures }. | | parseGltf(buffer, options?) | Parses GLB or glTF ArrayBuffer into ParseResult. Extracts embedded textures as blob URLs. | | parseVox(buffer, options?) | Parses MagicaVoxel .vox ArrayBuffer into ParseResult. Face-culls interior voxel faces and fan-triangulates exposed quads. | | loadMesh(url, options?) | Fetches a URL, dispatches to the right parser by extension (.obj, .glb, .gltf, .vox). Returns Promise<ParseResult>. | | parseColor(input) | Parse any CSS color string to { r, g, b, a }. | | shadeColor(input, lambert, ...) | Apply Lambert shading factor to a color. | | computeShapeLighting(normal, baseColor, light?) | Compute shaded color for a polygon face given a directional light and surface normal. |

Examples

Parse an OBJ file

import { parseObj } from "@layoutit/polycss-core";

const text = await fetch("/cottage.obj").then(r => r.text());
const { polygons, warnings, dispose } = parseObj(text, {
  targetSize: 40,
  defaultColor: "#cccccc",
});

console.log(polygons.length, "polygons");
warnings.forEach(w => console.warn(w));

// Revoke any blob URLs created during parse (OBJ rarely creates them,
// but always call dispose() for correctness):
dispose();

Normalize a polygon list

import { normalizePolygons } from "@layoutit/polycss-core";
import type { Polygon } from "@layoutit/polycss-core";

const raw: Polygon[] = [
  { vertices: [[0,0,0], [1,0,0], [0,1,0]], color: "#f00" },
  { vertices: [[0,0,0], [0,0,0], [0,0,0]] }, // degenerate: will be dropped
  { vertices: [[0,0,0], [1,0,0], [0.5,1,0], [0.5,1,0.1]] }, // non-coplanar quad → triangulated
];

const { polygons, warnings } = normalizePolygons(raw);
console.log(polygons.length); // 2 (degenerate dropped; quad fan-triangulated into 2)
warnings.forEach(w => console.warn(w));

Merge coplanar polygons

import { parseGltf, mergePolygons } from "@layoutit/polycss-core";

const buf = await fetch("/cottage.glb").then(r => r.arrayBuffer());
const { polygons, dispose } = parseGltf(buf, { targetSize: 60 });

// Merge coplanar same-material triangles to reduce DOM element count
const merged = mergePolygons(polygons);
console.log(`${polygons.length} triangles → ${merged.length} merged polygons`);

dispose(); // always revoke GLB blob URLs when done