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

@okrapdf/vdom-plugins

v0.1.0

Published

VDOM Plugin System - Chrome Extension-like plugins for document analysis

Downloads

51

Readme

@okrapdf/vdom-plugins

Chrome Extension-like plugin architecture for VDOM document analysis. Plugins declare capabilities via manifest, host renders UI dynamically.

Installation

npm install @okrapdf/vdom-plugins
# or
pnpm add @okrapdf/vdom-plugins

Quick Start

import { 
  pluginManager, 
  orphanDetectorPlugin,
  type VdomPlugin 
} from '@okrapdf/vdom-plugins';

// Register built-in plugin
pluginManager.register(orphanDetectorPlugin);

// Enable it
pluginManager.enable('orphan-detector');

// Run on lifecycle event
const results = await pluginManager.runEvent('interactive', {
  document: {
    id: 'doc-123',
    getAllNodes: () => nodes,
    getNode: (id) => nodes.find(n => n.id === id),
    pages: [nodes],
  },
  $: queryEngine,
});

Architecture

Plugin Interface

Plugins follow a manifest-based pattern inspired by Chrome Extensions:

interface VdomPlugin<TConfig = Record<string, unknown>> {
  name: string;
  description: string;
  version?: string;
  runsOn: VdomLifecycleEvent[];           // When to trigger
  handler: (ctx: PluginContext<TConfig>) => PluginResult | Promise<PluginResult>;
  configSchema?: PluginConfigSchema;       // User-configurable options
  viewControls?: ViewControlSchema[];      // UI controls (toggles, filters)
  defaultEnabled?: boolean;
  cleanup?: () => void | Promise<void>;
  dependencies?: string[];                 // Other plugins this depends on
}

Lifecycle Events

Plugins declare which events they respond to:

  • loading - Document loading started
  • ready - DOM ready, basic structure available
  • interactive - User can interact, OCR may still be running
  • complete - All processing done
  • nodeAdded / nodeRemoved / nodeUpdated - Node mutations
  • selectionChanged - User selection changed
  • pageChanged - Current page changed

Plugin Context

Handlers receive a rich context object:

interface PluginContext<TConfig> {
  document: {
    id: string;
    getAllNodes(): VdomNode[];
    getNode(id: string): VdomNode | undefined;
    pages: VdomNode[][];
  };
  $: QueryEngine;        // jQuery-like selector
  event: VdomLifecycleEvent;
  pageNumber?: number;
  node?: VdomNode;       // For node-specific events
  config: TConfig;       // User configuration
  emit: EmitFunction;    // Emit overlays, badges, annotations
  log: LogFunction;
}

Emit Types

Plugins can emit visual decorations:

  • overlays - Bounding box highlights on the PDF viewer
  • badges - Labels attached to tree nodes
  • annotations - Text annotations (highlight, underline, etc.)
  • stats - Computed statistics for display

Built-in Plugins

Orphan Detector

Detects OCR blocks not covered by semantic entities (tables, figures, etc.).

import { orphanDetectorPlugin } from '@okrapdf/vdom-plugins';

pluginManager.register(orphanDetectorPlugin);
pluginManager.setConfig('orphan-detector', {
  coverageThreshold: 0.5,  // 50% overlap required
  showOverlays: true,
  showBadges: true,
  badgeColor: 'orange',
});

Creating Custom Plugins

import type { VdomPlugin, PluginContext, PluginResult } from '@okrapdf/vdom-plugins';

interface MyConfig {
  threshold: number;
}

const myPlugin: VdomPlugin<MyConfig> = {
  name: 'my-plugin',
  description: 'Does something useful',
  version: '1.0.0',
  runsOn: ['complete'],
  defaultEnabled: false,
  
  configSchema: {
    threshold: {
      type: 'number',
      label: 'Threshold',
      default: 0.8,
      min: 0,
      max: 1,
    },
  },
  
  handler: async (ctx: PluginContext<MyConfig>): Promise<PluginResult> => {
    const { threshold } = ctx.config;
    const nodes = ctx.$('table').toArray();
    
    // Process nodes...
    
    ctx.emit('stats', { tablesFound: nodes.length });
    
    return { success: true };
  },
};

API Reference

VdomPluginManager

class VdomPluginManager {
  register(plugin: VdomPlugin): void;
  unregister(name: string): void;
  enable(name: string): void;
  disable(name: string): void;
  isEnabled(name: string): boolean;
  setConfig(name: string, config: Record<string, unknown>): void;
  getConfig(name: string): Record<string, unknown>;
  getPlugins(): VdomPlugin[];
  getEnabledPlugins(): string[];
  runEvent(event, context): Promise<Map<string, PluginResult>>;
  on(event, handler): () => void;  // Returns unsubscribe function
}

Utilities

import { overlapRatio, bboxContains } from '@okrapdf/vdom-plugins';

// Calculate overlap between two bounding boxes (0-1)
const ratio = overlapRatio(bbox1, bbox2);

// Check if inner bbox is contained by outer (with threshold)
const contained = bboxContains(outer, inner, 0.5);

License

MIT