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

@crup/port

v0.1.4

Published

A lightweight protocol-first iframe runtime for building secure host/child embeds with explicit lifecycle and messaging.

Readme

@crup/port

npm version npm downloads bundle size License CI Docs

Protocol-first iframe runtime for explicit host/child communication.

@crup/port exists for the part of embedded app work that usually rots first: lifecycle, handshake timing, and message discipline. It gives the host page a small runtime for mounting an iframe, opening it inline or in a modal, pinning exact origins, and exchanging request/response/error messages without ad hoc postMessage glue.

Package: https://www.npmjs.com/package/@crup/port

Live demo: https://crup.github.io/port/

Install

npm install @crup/port
pnpm add @crup/port
yarn add @crup/port

Import the host runtime from @crup/port and the child runtime from @crup/port/child.

Quick Links

  • npm package: https://www.npmjs.com/package/@crup/port
  • live demo: https://crup.github.io/port/
  • source: https://github.com/crup/port
  • issues: https://github.com/crup/port/issues

Why This Package Exists

  • Raw postMessage is low-level and easy to drift across products.
  • Iframe lifecycle bugs usually hide in timing and cleanup paths.
  • Cross-window integrations need explicit origin pinning and state transitions.
  • Small embed runtimes should stay tiny, predictable, and framework-agnostic.

Quick Start

Host

import { createPort } from '@crup/port';

const port = createPort({
  url: 'https://example.com/embed',
  allowedOrigin: 'https://example.com',
  target: '#embed-root',
  mode: 'inline',
  minHeight: 360,
  maxHeight: 720
});

await port.mount();

port.on('widget:loaded', (payload) => {
  console.log('child event', payload);
});

const result = await port.call<{ ok: boolean }>('system:ping', {
  requestedAt: Date.now()
});

console.log(result.ok);

Child

import { createChildPort } from '@crup/port/child';

const child = createChildPort({
  allowedOrigin: 'https://host.example.com'
});

child.on('request:system:ping', (message) => {
  const request = message as { messageId: string; payload?: unknown };

  if (!request.payload) {
    child.reject(request.messageId, 'missing ping payload');
    return;
  }

  child.respond(request.messageId, {
    ok: true,
    receivedAt: Date.now()
  });
});

child.emit('widget:loaded', { version: '1' });
child.resize(document.body.scrollHeight);

What You Get

  • Explicit lifecycle: idle -> mounting -> mounted -> handshaking -> ready -> open -> closed -> destroyed
  • Explicit origin pinning on both host and child
  • Inline and modal host modes
  • Event emission plus request/response/error RPC
  • Child-driven height updates
  • Small ESM-only bundle built with tsup

API Surface

createPort(config)

Host runtime with:

  • mount()
  • open()
  • close()
  • destroy()
  • send(type, payload?)
  • call<T>(type, payload?)
  • on(type, handler)
  • off(type, handler)
  • update(partialConfig)
  • getState()

createChildPort(config)

Child runtime with:

  • ready()
  • emit(type, payload?)
  • on(type, handler)
  • respond(messageId, payload)
  • reject(messageId, payload?)
  • resize(height)
  • destroy()

Message Shape

type PortMessage = {
  protocol: 'crup.port';
  version: '1';
  instanceId: string;
  messageId: string;
  replyTo?: string;
  kind: 'event' | 'request' | 'response' | 'error' | 'system';
  type: string;
  payload?: unknown;
};

Demo And Examples

Documentation

Positioning

@crup/port stays intentionally narrow:

  • it is a protocol runtime for iframe lifecycle, handshake, resize, and correlated messaging
  • it is not a framework adapter layer for React, Vue, or Web Components
  • it is not a generic method bridge that reaches into arbitrary child code
  • it is not an automatic DOM sync system beyond explicit child-driven resize()

That scope is what keeps the package small and predictable.

Why Not Penpal, Zoid, Or Postmate?

Those libraries solve adjacent problems, but with a broader or different abstraction:

  • Penpal is strong when you want promise-based remote method calls across iframes, windows, and workers.
  • Zoid is strong when you want full cross-domain components with props, callbacks, and framework-facing integration patterns.
  • Postmate is strong when you want a small promise-based parent/child model API over postMessage.

@crup/port exists for a narrower use case:

  • explicit iframe lifecycle and handshake control
  • exact origin pinning on both sides
  • simple event plus request/response/error messaging
  • explicit child-driven resize instead of a larger component abstraction

If you want a minimal protocol runtime rather than a remote method bridge or cross-domain component toolkit, that is the gap this package is targeting.

Local Development

pnpm install
pnpm lint
pnpm typecheck
pnpm test
pnpm build
pnpm demo:dev

Useful scripts:

  • pnpm docs:build builds the GitHub Pages site into demo-dist/
  • pnpm size reports raw and gzip bundle sizes for dist/
  • pnpm changeset adds a release note entry when you want to track pending package notes
  • pnpm readme:check validates the README install and package links

Release Model

  • ci.yml validates lint, types, tests, package build, demo build, README checks, size output, and package packing.
  • docs.yml deploys the Vite demo to GitHub Pages at https://crup.github.io/port/.
  • release.yml is a guarded manual stable release workflow modeled on crup/react-timer-hook, and it persists the published version back to main.
  • prerelease.yml publishes a manual alpha prerelease from the next branch.

Security

This package helps enforce the runtime boundary, but it cannot secure a weak embed strategy on its own. Always pin allowedOrigin, set restrictive iframe attributes, and validate application-level payloads. The practical guidance lives in docs/security.md.

License

Released under the MIT License.