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

json-render-svelte

v0.6.1

Published

Svelte 5 renderer for @json-render/core. JSON becomes Svelte components.

Downloads

761

Readme

@json-render/svelte

Svelte 5 renderer for @json-render/core. JSON becomes Svelte components.

Install

npm install @json-render/core @json-render/svelte

Requires Svelte 5 (^5.0.0).

Quick Start

1. Define Your Catalog

import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/svelte/schema";
import { z } from "zod";

const catalog = defineCatalog(schema, {
  components: {
    Card: {
      props: z.object({ title: z.string() }),
      description: "A card container",
    },
    Button: {
      props: z.object({ label: z.string() }),
      description: "Clickable button",
    },
  },
  actions: {
    refresh: { description: "Refresh data" },
  },
});

2. Create Svelte Components

Components receive ComponentRenderProps -- element, emit, bindings, loading, and a children snippet:

<!-- Card.svelte -->
<script lang="ts">
  import type { ComponentRenderProps } from "@json-render/svelte";

  let { element, children }: ComponentRenderProps<{ title: string }> = $props();
</script>

<div class="card">
  <h3>{element.props.title}</h3>
  {#if children}
    {@render children()}
  {/if}
</div>
<!-- Button.svelte -->
<script lang="ts">
  import type { ComponentRenderProps } from "@json-render/svelte";

  let { element, emit }: ComponentRenderProps<{ label: string }> = $props();
</script>

<button onclick={() => emit("press")}>
  {element.props.label}
</button>

3. Build Registry and Render

import { defineRegistry } from "@json-render/svelte";

const { registry } = defineRegistry(catalog, {
  components: { Card, Button } as any,
});
<script>
  import { CatalogRenderer } from "@json-render/svelte";
  import { registry } from "./registry.js";

  const spec = {
    root: "card-1",
    elements: {
      "card-1": {
        type: "Card",
        props: { title: "Hello" },
        children: ["btn-1"],
      },
      "btn-1": {
        type: "Button",
        props: { label: "Click me" },
      },
    },
  };
</script>

<CatalogRenderer {spec} {registry} />

API

Components

| Export | Description | | ----------------- | ------------------------------------------------------------------------- | | Renderer | Low-level renderer -- requires contexts to be set up via JSONUIProvider | | JSONUIProvider | Sets up all contexts (state, visibility, actions, validation) | | CatalogRenderer | All-in-one: wraps JSONUIProvider + Renderer | | ConfirmDialog | Default confirmation dialog for actions |

Functions

| Export | Description | | -------------------------------------------------- | ------------------------------------- | | defineRegistry(catalog, { components, actions }) | Create a type-safe component registry | | createStateStore(initial, onChange) | Create a reactive state store | | createVisibilityContext() | Create visibility evaluation context | | createActionContext(handlers, navigate) | Create action execution context | | createValidationContext(fns) | Create field validation context |

Context Accessors

| Export | Description | | ----------------------------------------------------- | ----------------------------------- | | getStateContext() / setStateContext() | State context | | getVisibilityContext() / setVisibilityContext() | Visibility context | | getActionContext() / setActionContext() | Action context | | getValidationContext() / setValidationContext() | Validation context | | getRepeatScopeContext() / setRepeatScopeContext() | Repeat scope (for $item/$index) |

Component Contract

Svelte components registered in the registry receive these props:

interface ComponentRenderProps<P> {
  element: UIElement<string, P>; // The element being rendered
  children?: Snippet; // Child elements as a Svelte 5 snippet
  emit: (event: string) => void; // Emit events (resolved to action bindings)
  bindings?: Record<string, string>; // Two-way binding paths
  loading?: boolean; // Whether spec is loading/streaming
}

Schema

import { schema } from "@json-render/svelte/schema";
// Same spec format as @json-render/react (root + elements map)

Features

  • Svelte 5 runes -- reactive state with $state, $derived, $effect
  • Snippets -- children passed via Svelte 5 {@render children()} pattern
  • Error boundaries -- <svelte:boundary> catches per-element rendering errors
  • Dynamic components -- Svelte 5 native dynamic component rendering
  • Same spec format -- identical JSON spec as React/React Native renderers
  • Core resolution -- visibility, props, actions, validation all powered by @json-render/core

License

Apache-2.0