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

native-sfc

v0.0.3

Published

Load a single HTML file as a Web Component.

Readme

Native-SFC

Load a single HTML file as a Web Component.

<!-- index.html -->
<my-counter></my-counter>
<script type="module">
  import { loadComponent } from "https://esm.sh/native-sfc";
  loadComponent("my-counter", "./my-counter.html");
</script>

Use export default to declare the component class.

<!-- my-counter.html -->
<button @click="setCount(count() + 1)">Count is: {{ count() }}</button>
<script type="module">
  import { signal } from "https://esm.sh/native-sfc";
  export default class MyCounter extends HTMLElement {
    setup() {
      const [count, setCount] = signal(0);
      return { count, setCount };
    }
    connectedCallback() {/* TODO */}
  }
  // OR
  import { defineComponent } from "https://esm.sh/native-sfc";
  export default defineComponent(({ onConnected }) => {
    const [count, setCount] = signal(0);
    onConnected(() => {/* TODO */});
    return { count, setCount };
   });
</script>

How it works

The component loader fetches everything (HTML, JS, CSS) as text, then processes them to create a Web Component.

  1. HTML Parsing: The HTML file is parsed and processed
  2. Style Handling: All <style> and <link rel="stylesheet"> are collected and converted to adoptedStyleSheets of the component's shadow root (avoids FOUC)
  3. Script Handling: ESM modules (<script type="module">) are evaluated and their exports are merged. The default export, if it's a class extending HTMLElement, becomes the base class of the component
  4. Global Styles: Styles with global attribute are moved to the outer document instead of the shadow root
  5. URL Rewriting: All relative URLs in src and href attributes are rewritten to absolute URLs based on the component file location

Component API

loadComponent(name: string, url: string)

Load a component from a HTML file and register it as a custom element.

  • name: The custom element name (e.g., "my-component")
  • url: The URL to the component HTML file (relative to the importer)

defineComponent(setup: ({ onConnected?, onDisconnected? }) => void)

A helper function for dual-mode component definition:

  • When used inside a loadComponent-imported module, it defines a web component class with lifecycle callbacks
  • When used in normal document context, it runs the setup function with document as root
  • The setup function receives { onConnected, onDisconnected } callbacks
  • Return an object from setup to expose reactive state to the template

Signals API

signal<T>(initialValue: T): [() => T, (v: T) => void]

Creates a reactive signal with a getter and setter.

  • Returns a tuple: [getter, setter]
  • getter(): Returns the current value
  • setter(value): Updates the signal value and triggers reactivity

computed<T>(fn: () => T): () => T

Creates a computed value that automatically tracks dependencies.

  • fn: Function that computes and returns the value
  • Returns a getter function that returns the computed result
  • Automatically updates when dependencies change

effect(fn: VoidFunction): VoidFunction

Creates a reactive effect that runs whenever its dependencies change.

  • fn: Function to execute
  • Returns a cleanup function to stop the effect
  • Useful for side effects and subscriptions

effectScope(fn: VoidFunction): VoidFunction

Creates an effect scope to batch multiple effects together.

  • fn: Function containing effect definitions
  • Returns a cleanup function to stop all effects in the scope
  • Useful for organizing related effects

HTML Template API

.property

Binds a DOM property to a reactive expression.

<input .value="someSignal()" />

:attribute

Binds a DOM attribute to a reactive expression.

<img :src="imageUrl()" />

@event

Binds a DOM event to a reactive expression.

<button @click="handleClick()" />

{{ expression }}

Embeds a reactive expression inside text content.

<p>Total: {{ total() }}</p>

#if="condition"

Conditionally renders an element based on a reactive expression.

<div #if="isVisible()">This content is visible only if isVisible() is true.</div>

#for="arrayExpression"

Renders a list of elements based on a reactive array expression.

<li #for="items().map(item => ({ item }))">{{ item.name }}</li>

Limitations

  • Dynamic imports with relative paths are NOT supported.
  • Inside the ESM modules, the from syntax in import statements are rewritten to absolute URL, since all modules are actually loaded as blob URLs.
  • Since all styles are moved to adoptedStyleSheets in component's shadow root, we CANNOT use @import rules in styles.
  • Relative URLs in CSS (e.g., background-image: url(./bg.png)) are resolved relative to the main document (the page URL), not the component file URL.
  • Components loaded with the same name and URL are cached and reused.
  • Only script[src]'s src' link[rel="stylesheet"]'s href will be rewritten. Warn that a[href]/img[src]/etc with relative URLs in the HTML body will NOT be rewritten.

Next Steps

  • Implement component debugger
  • Implement component bundler in both runtime and server-side
  • Consider to support rewriting relative URLs in CSS