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

greencubes-iframe-interface

v0.0.4

Published

A TypeScript library for **type-safe communication** between a parent window and one or one ore more iframes containing a basic LuciadRIA application. Supports strict type-checking, autocomplete, and payload validation for all message types. ---

Readme

iframeMessages

A TypeScript library for type-safe communication between a parent window and one or one ore more iframes containing a basic LuciadRIA application.
Supports strict type-checking, autocomplete, and payload validation for all message types.

Features

  • Typed messages from iframe → parent and parent → iframe
  • Autocomplete and type safety for type and data
  • Utility functions for sending and listening to messages
  • Optional frameId support for multiple iframes
  • Debug logging via URL query parameter ?debug=true

Installation

Assuming your project uses npm or yarn:

npm install greencubes-iframe-interface
# or
yarn add greencubes-iframe-interface

Types

Base message

interface BaseMessage<T extends string, D> {
  type: T;
  data: D;
  frameId?: string;
}

Iframe → Parent messages

type IframeToParentMessage =
  | BaseMessage<"LayerTreeChange", { layerId: string; type: "NodeAdded" | "NodeRemoved" | "NodeMoved" }>
  | BaseMessage<"ClickedItem", { feature: Feature }>
  | BaseMessage<"SelectedItems", { features: Feature[] }>
  | BaseMessage<"Ready", { targetLayerId?: string }>
  | BaseMessage<"Error", { message: string }>;

Parent → Iframe messages

type ParentToIframeMessage =
  | BaseMessage<"HighlightFeature", { featureId: FeatureId }>
  | BaseMessage<"SelectFeatures", { featureIds: FeatureId[] }>
  | BaseMessage<"RemoveLayer", { layerId?: string }>
  | BaseMessage<"ZoomToSelection", { featureIds: FeatureId[]; animate?: boolean | MapNavigatorAnimationOptions }>
  | BaseMessage<"ZoomToLayer", { layerId?: string; animate?: boolean | MapNavigatorAnimationOptions }>;

A more detailed example here

import React, { useRef, useEffect } from "react";
import ReactDOM from "react-dom/client";
import { sendToIframe, listenFromIframes, IframeToParentMessage } from "@lib";

function MainApp() {
  const iframeRef = useRef<HTMLIFrameElement>(null);

  // Listen for messages from iframe
  useEffect(() => {
    const stop = listenFromIframes(
      { demo: iframeRef.current },
      (msg: IframeToParentMessage, frameId?: string) => {
        console.log("Parent received:", msg, "from iframe:", frameId);
          switch (msg.type) {
              case "Ready":
                  layer.current = msg.data.targetLayerId;
                  console.log(msg.data.targetLayerId);
                  break;
              case "ClickedItem":
                  console.log(msg.data.feature);
                  if (iframeRef.current){
                      sendToIframe(iframeRef.current, {type: "ZoomToSelection", data: {animate: true, featureIds: [msg.data.feature.id]}})
                  }
                  break;
          }
      }
    );
    return () => stop();
  }, []);

  const handleClick = () => {
    if (iframeRef.current) {
      sendToIframe(iframeRef.current, {
        type: "ZoomToLayer",
        data: { animate: false },
      });
    }
  };

  return (
    <div>
      <h1>Main App (Parent)</h1>
      <button onClick={handleClick}>Send ZoomToLayer → Iframe</button>
      <iframe
        ref={iframeRef}
        src="/iframe.html"
        style={{ width: "100%", height: 480, border: "1px solid black" }}
      />
    </div>
  );
}

ReactDOM.createRoot(document.getElementById("root")!).render(<MainApp />);

Usage

Sending messages

Parent → Iframe

sendToIframe(iframeElement, {
  type: "ZoomToLayer",
  data: { layerId: "roads", animate: false }
});

Iframe → Parent

sendToParent({
  type: "SelectedItems",
  data: { features: selectedFeatures }
});

Listening for messages

Parent listening from iframes

listenFromIframes({ mainFrame: iframeRef.current }, (msg, frameId) => {
  if (msg.type === "SelectedItems") {
    console.log("Selected features from iframe:", msg.data.features);
  }
});

Iframe listening from parent

listenFromParent((msg) => {
  if (msg.type === "HighlightFeature") {
    highlightFeature(msg.data.featureId);
  }
});

Debug Logging

Enable debug logs by adding ?debug=true to the URL:

consoleOnDebugMode("This will appear only if debug=true in URL");

Notes

  • All message types are strictly typed; using an invalid type or incorrect data will result in a TypeScript compile-time error.
  • frameId is optional but recommended if multiple iframes are communicating with the parent.

License

MIT © 2025