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

@ydant/core

v0.2.0

Published

Generator-based DOM rendering DSL

Downloads

352

Readme

@ydant/core

Rendering engine and plugin system for Ydant.

Philosophy

@ydant/core is a pure engine that doesn't know "what" to render.

Core provides only:

  • Generator processing
  • Plugin dispatch
  • Context management

It doesn't assume DOM existence. All concrete operations (DOM manipulation, lifecycle, keyed elements) are delegated to plugins. This separation keeps core's API surface minimal and stable, allowing plugins to extend functionality without modifying core.

For user-facing APIs like element factories and primitives, see @ydant/base.

Installation

pnpm add @ydant/core

Usage

import { mount } from "@ydant/core";
import { createBasePlugin, div, text, type Component } from "@ydant/base";

const App: Component = () => div(() => [text("Hello!")]);

mount(App, document.getElementById("app")!, {
  plugins: [createBasePlugin()],
});

API

Mount

function mount(app: Component, parent: HTMLElement, options?: MountOptions): void;

interface MountOptions {
  plugins?: Plugin[];
}

Plugin System

interface Plugin {
  readonly name: string;
  readonly types: readonly string[];
  /** Plugin names that must be registered before this plugin */
  readonly dependencies?: readonly string[];
  /** Initialize plugin-specific properties in RenderContext */
  initContext?(ctx: RenderContext, parentCtx?: RenderContext): void;
  /** Merge child context state into parent context (called after processChildren) */
  mergeChildContext?(parentCtx: RenderContext, childCtx: RenderContext): void;
  /** Process a request and return a response for the generator */
  process(request: Request, ctx: RenderContext): Response;
}

Types

| Type | Description | | --------------- | --------------------------------------------------------------- | | Tagged<T,P> | Helper type for tagged unions: { type: T } & P | | SpellSchema | Co-locates request and response types per spell operation | | Spell<Key> | Typed generator for a specific spell operation key | | Request | Union of all yieldable types (derived from SpellSchema) | | Response | Union of all response types returned by process() | | Render | Generator for rendering — components, elements, and children | | Builder | () => Render \| Render[] - Element children factory | | Component<P?> | () => Render (no args) or (props: P) => Render (with props) |

Plugin Extension Interfaces

Plugins can extend these interfaces via module augmentation:

declare module "@ydant/core" {
  // Extend RenderContext with custom properties
  interface RenderContext {
    myProperty: MyType;
  }

  // Co-locate request, response, and return types per spell operation
  interface SpellSchema {
    mytype: { request: Tagged<"mytype", { value: string }>; response: MyResultType };
    // return omitted → falls back to response (MyResultType)
    // Use explicit `return` when it differs from response:
    // "other": { request: OtherType; response: Bar; return: Baz };
    // Or for return-only entries (no request):
    // "composite": { return: CompositeHandle };
  }
}

// Use Spell<Key> for typed generators
function* myOperation(): Spell<"mytype"> {
  const result = yield myRequest; // result is MyResultType
  return result;
}

RenderContext

The rendering context holds state and methods during rendering. Core fields include parent, currentElement, plugins, processChildren, and createChildContext. Plugins extend it via declare module:

interface RenderContext {
  parent: Node;
  currentElement: Element | null;
  plugins: Map<string, Plugin>;
  processChildren(builder: Builder, options?: { parent?: Node }): void;
  createChildContext(parent: Node): RenderContext;
}

Utilities

| Function | Description | | ---------------------- | ------------------------------------------------- | | isTagged(value, tag) | Type guard for tagged union types | | toRender(result) | Normalize Render \| Render[] to single Render |

Creating Plugins

import type { Request, Response, Plugin, RenderContext } from "@ydant/core";

// 1. Declare type extensions
declare module "@ydant/core" {
  interface RenderContext {
    myData: Map<string, unknown>;
  }
}

// 2. Create the plugin
export function createMyPlugin(): Plugin {
  return {
    name: "my-plugin",
    types: ["mytype"],
    dependencies: ["base"], // Ensure base plugin is registered first

    // Initialize context properties
    initContext(ctx, parentCtx) {
      ctx.myData = parentCtx?.myData ? new Map(parentCtx.myData) : new Map();
    },

    // Merge child context state into parent context
    mergeChildContext(parentCtx, childCtx) {
      for (const [key, value] of childCtx.myData) {
        parentCtx.myData.set(key, value);
      }
    },

    // Process requests — access ctx properties directly
    process(request: Request, ctx: RenderContext): Response {
      if ((request as { type: string }).type === "mytype") {
        // Access context properties directly: ctx.myData.get(key), ctx.myData.set(key, value)
        return result;
      }
    },
  };
}