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

@ly-sys/layout-engine

v1.0.3

Published

Core computation, responsive property parser, and utility class conflict resolution engine.

Readme

@ly-sys/layout-engine

Core computation, responsive property parser, and utility class conflict resolution engine.

npm version package manager

The @ly-sys/layout-engine package is the core computational core of the design system. It interprets responsive layout values (such as gap={{ base: 2, md: 4 }}), translates high-level layout properties into atomic utility classes, resolves class name conflicts (prioritizing custom overrides over defaults), and applies prefixing rules cleanly and efficiently at runtime.


Key Features

  • Low-Overhead Parsers: Converts complex declarations into formatted utility class strings inside highly optimized hot paths.
  • Deduplication Engine: Uses a right-most wins resolution algorithm for CSS class conflicts, adhering to a defined priority hierarchy (App-specific overrides > global/neutral classes > library defaults).
  • Sub-Microsecond Resolution: Integrates a Least Recently Used (LRU) Cache to completely bypass calculations on subsequent component rendering cycles.
  • Prefix and Breakpoint Decorator: Seamlessly processes responsive breakpoint prefixes (e.g., md:ly-gap-4) and prefixes according to configuration rules.
  • Zero Style Collisions: Coordinates styling boundaries without external runtimes, producing highly clean utility strings compatible with CSS Cascade Layers.

Architecture

The engine is comprised of three core modules:

┌────────────────────────────────────────────────────────┐
│                      LayoutEngine                      │
├────────────────────────────────────────────────────────┤
│  1. parseResponsive() ──►  [LRU Cache Lookup]          │
│                              │                         │
│                              ├─► Cache Hit  ──► Output │
│                              └─► Cache Miss ──► Parse  │
│                                                        │
│  2. resolve()         ──► Rightmost-wins & Priority     │
│                           App > Neutral > Lib          │
│                                                        │
│  3. prefix()          ──► Prepends prefixes to classes │
└────────────────────────────────────────────────────────┘

1. Responsive Property Parser

Translates atomic layout components' properties into valid responsive and prefixed utility class strings using the current breakpoint configurations.

2. Collision Resolver (resolve)

Resolves layout utility conflicts at runtime. It analyzes class classes, groups them by property family (e.g., flex-direction, gap, padding), and retains only the winning classes according to priority:

  • App (appPrefix, Priority 3): Local application-specific utility classes.
  • Neutral (No prefix, Priority 2): Standard utility classes (e.g. Tailwind or default CSS).
  • Lib (libPrefix, Priority 1): Library-specific default layout classes.

Within the same priority tier, the rightmost class (last declared) wins.


Installation

pnpm add @ly-sys/layout-engine
# or
npm install @ly-sys/layout-engine
# or
yarn add @ly-sys/layout-engine

Usage Guide

1. Instantiating the Engine

Create an engine instance with a customized library prefix and screen breakpoints:

import {createLayoutEngine} from "@ly-sys/layout-engine";

const engine = createLayoutEngine({
    libPrefix: "ly",       // Prefix for layout class names (e.g. ly-flex)
    appPrefix: "app",      // Prefix for application-specific custom overrides
    breakpoints: ["base", "sm", "md", "lg", "xl"] as const
});

2. Parsing Responsive Values

Use parseResponsive to convert responsive objects or singular values into utility strings:

const directionClasses = engine.parseResponsive(
    {base: "column", md: "row"}, // Responsive configuration
    "direction",                  // Layout property name
    (v) => `flex-${v}`            // Utility class mapper function
);

console.log(directionClasses);
// Output: "ly-flex-col md:ly-flex-row"

3. Resolving Conflicts with resolve

Ensure utility overrides behaves predictably when merging user-supplied classes and default generated classes:

// Conflict 1: Overriding same property (e.g. flex-row vs flex-col)
const resolved = engine.resolve(
    "ly-flex ly-flex-row ly-gap-4", // Generated layout classes
    "ly-flex-col"                   // User custom classes
);
console.log(resolved);
// Output: "ly-flex ly-gap-4 ly-flex-col"
// (ly-flex-col overridden ly-flex-row due to rightmost-wins)

// Conflict 2: Prioritizing application overrides
const resolvedPriorities = engine.resolve(
    "ly-gap-4",   // Lib level (Priority 1)
    "app-gap-8"   // App level (Priority 3)
);
console.log(resolvedPriorities);
// Output: "app-gap-8"
// (app-gap-8 takes priority over ly-gap-4 regardless of ordering)

Additional Details

Caching Performance (LRU Cache)

Parsing responsive property configurations involves loops, object serialization, and array joining. To keep runtime overhead near zero, the layout engine integrates a Least Recently Used (LRU) Cache (defaults to 500 entries).

You can also instantiate the cache standalone if needed:

import {createLRUCache} from "@ly-sys/layout-engine";

// Create cache with capacity of 100 items
const cache = createLRUCache<string>(100);

cache.set("flexDirection|base:row;md:column", "ly-flex-row md:ly-flex-col");
console.log(cache.get("flexDirection|base:row;md:column"));
// Output: "ly-flex-row md:ly-flex-col"

License

MIT. See the root LICENSE file.