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

@csszyx/runtime

v0.3.1

Published

Runtime helpers and hydration guards for csszyx

Downloads

722

Readme

@csszyx/runtime

Runtime package for CSSzyx - provides zero-allocation className helpers, recovery token verification, and hydration guards.

Features

  • Zero-Allocation Helpers: Efficient className concatenation with _sz() and variants
  • Token Verification: Runtime validation of recovery tokens
  • Hydration Guards: SSR/CSR consistency with abort protocol
  • Type Safety: Full TypeScript support with strict types

Installation

pnpm add @csszyx/runtime

Usage

Basic Concatenation

import { _sz } from "@csszyx/runtime";

// Basic usage
const className = _sz("a", "b", "c");
// Returns: "a b c"

// With conditionals
const className = _sz("base", isActive && "active", hasError && "error");
// Returns: "base active" (if isActive is true, hasError is false)

// Filters out falsy values
const className = _sz("a", null, "b", undefined, false, "c");
// Returns: "a b c"

Conditional Helpers

import { _szIf, _szSwitch } from "@csszyx/runtime";

// Simple conditional
_szIf(isActive, "active"); // "active" or false

// With fallback
_szIf(isActive, "active", "inactive"); // "active" or "inactive"

// Switch-like
_szSwitch(
  [
    [status === "success", "text-green-500"],
    [status === "error", "text-red-500"],
    [status === "warning", "text-yellow-500"],
  ],
  "text-gray-500",
);

Merging Classes

import { _szMerge } from "@csszyx/runtime";

// Merge with duplicate removal
_szMerge("a b", "b c", "c d");
// Returns: "a b c d"

Runtime Initialization

import { initRuntime } from "@csszyx/runtime";

// Initialize at app startup
initRuntime({
  development: process.env.NODE_ENV === "development",
  allowCSRRecovery: true,
  strictHydration: true,
  debug: false,
});

Recovery Token Verification

import { verifyRecoveryToken, loadManifestFromDOM } from "@csszyx/runtime";

// Load manifest from embedded script
const manifest = loadManifestFromDOM();

if (manifest) {
  const element = document.querySelector("[data-sz-recovery-token]");
  const result = verifyRecoveryToken(element, manifest);

  if (result.valid) {
    console.log("Token verified:", result.tokenData);
  } else {
    console.error("Invalid token:", result.error);
  }
}

Hydration Guard

import {
  guardHydration,
  loadManifestFromDOM,
  enableCSRRecovery,
} from "@csszyx/runtime";

// Enable CSR recovery in development
if (process.env.NODE_ENV === "development") {
  enableCSRRecovery();
}

// Guard hydration process
const manifest = loadManifestFromDOM();
if (manifest && !guardHydration(manifest)) {
  console.error("Hydration guard failed - mangle map mismatch");
}

API Reference

Concatenation Helpers

_sz(...classes): string

Zero-allocation className concatenation. Filters out falsy values.

_sz2(a, b): string

Optimized two-argument version.

_sz3(a, b, c): string

Optimized three-argument version.

_szIf(condition, className, fallback?): string | false

Conditional className application.

_szSwitch(conditions, default?): string

Switch-like className selection.

_szMerge(...classes): string

Merge className strings with duplicate removal.

Verification

verifyRecoveryToken(element, manifest): VerificationResult

Verifies a recovery token against the manifest.

loadManifestFromDOM(): RecoveryManifest | null

Loads the recovery manifest from the DOM.

hasRecoveryToken(element): boolean

Checks if an element has a recovery token.

getRecoveryMode(element): RecoveryMode | null

Gets the recovery mode from an element.

verifyAllTokens(root, manifest): VerificationResult[]

Verifies all tokens in a subtree.

Hydration

guardHydration(manifest): boolean

Guards the hydration process by verifying mangle map integrity.

loadMangleMapFromDOM(): MangleMap | null

Loads the mangle map from the DOM.

verifyMangleChecksum(expectedChecksum): boolean

Verifies the mangle map checksum.

abortHydration(element, error): void

Executes the hydration abort protocol for a subtree.

isHydrationAborted(element): boolean

Checks if a subtree has been aborted.

attemptCSRRecovery(element): boolean

Attempts client-side recovery for an aborted subtree.

enableCSRRecovery(): void

Enables CSR recovery mode (development only).

disableCSRRecovery(): void

Disables CSR recovery mode.

isCSRRecoveryAllowed(): boolean

Checks if CSR recovery is allowed.

getHydrationErrors(): HydrationError[]

Gets all hydration errors.

getAbortedSubtreeCount(): number

Gets the count of aborted subtrees.

Runtime Initialization

initRuntime(config?): void

Initializes the CSSzyx runtime with optional configuration.

getRuntimeConfig(): RuntimeConfig

Gets the current runtime configuration.

isRuntimeInitialized(): boolean

Checks if the runtime has been initialized.

Configuration Options

interface RuntimeConfig {
  development?: boolean; // Enable development mode features
  allowCSRRecovery?: boolean; // Allow CSR recovery in development
  strictHydration?: boolean; // Enable strict hydration checks
  debug?: boolean; // Enable debug logging
}

Performance

The _sz() family of functions are optimized for zero-allocation concatenation:

  • _sz() - Variadic version for any number of arguments
  • _sz2() - 10-15% faster for exactly 2 arguments
  • _sz3() - 10-15% faster for exactly 3 arguments

Use the optimized versions in hot paths when the argument count is known at compile time.

License

MIT