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

@livetemplate/client

v0.7.7

Published

TypeScript client for LiveTemplate tree-based updates

Readme

@livetemplate/client

TypeScript/JavaScript client library for LiveTemplate - reactive HTML over the wire.

Overview

The LiveTemplate client enables reactive web applications by efficiently applying tree-based HTML updates from the server. It uses DOM morphing, intelligent static content caching, and WebSocket transport for real-time interactivity.

Features

  • Tree-based Updates: Efficiently applies minimal JSON updates to the DOM
  • Static Structure Caching: Client caches static HTML, receives only dynamic changes
  • DOM Morphing: Uses morphdom for efficient, minimal DOM updates
  • WebSocket Transport: Real-time bidirectional communication
  • Focus Management: Preserves focus during updates
  • Form Lifecycle: Automatic form state management
  • Event Delegation: Efficient event handling
  • Modal Management: Built-in modal support
  • TypeScript: Full type safety and IDE support

Installation

npm

npm install @livetemplate/client

CDN

<script src="https://cdn.jsdelivr.net/npm/@livetemplate/[email protected]/dist/livetemplate-client.browser.js"></script>

Quick Start

Browser (via CDN)

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdn.jsdelivr.net/npm/@livetemplate/[email protected]/dist/livetemplate-client.browser.js"></script>
</head>
<body>
    <div id="app"></div>
    <script>
        const client = new LiveTemplateClient.LiveTemplateClient({
            targetSelector: "#app",
            wsUrl: "ws://localhost:8080/ws",
            httpUrl: "http://localhost:8080"
        });

        client.connect();
    </script>
</body>
</html>

TypeScript/ES Modules

import { LiveTemplateClient } from "@livetemplate/client";

const client = new LiveTemplateClient({
    targetSelector: "#app",
    wsUrl: "ws://localhost:8080/ws",
    httpUrl: "http://localhost:8080"
});

client.connect();

Configuration Options

interface LiveTemplateClientOptions {
    // Required
    targetSelector: string;      // CSS selector for target element
    wsUrl: string;                // WebSocket URL
    httpUrl: string;              // HTTP URL for initial render

    // Optional
    debug?: boolean;              // Enable debug logging (default: false)
    reconnectInterval?: number;   // Reconnect interval in ms (default: 3000)
    maxReconnectAttempts?: number;// Max reconnect attempts (default: 10)
}

API

Client Methods

// Connect to server
client.connect(): void

// Disconnect from server
client.disconnect(): void

// Send event to server
client.sendEvent(event: string, data: any): void

// Set debug mode
client.setDebug(enabled: boolean): void

Events

The client emits events you can listen to:

// Connection established
window.addEventListener("livetemplate:connected", (e) => {
    console.log("Connected to server");
});

// Connection closed
window.addEventListener("livetemplate:disconnected", (e) => {
    console.log("Disconnected from server");
});

// Update received
window.addEventListener("livetemplate:update", (e) => {
    console.log("Received update:", e.detail);
});

How It Works

  1. Initial Render: Client fetches full HTML from server, caches static structure
  2. Updates: Server sends only changed dynamic values as tree updates
  3. DOM Morphing: Client applies updates using morphdom for minimal DOM changes
  4. Caching: Static HTML structure is cached, never re-transmitted

This results in ~75% reduction in update payload sizes compared to full HTML updates.

Development

Setup

# Clone repository
git clone https://github.com/livetemplate/client.git
cd client

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

Project Structure

client/
├── livetemplate-client.ts       # Main client
├── dom/                         # DOM utilities
│   ├── directives.ts
│   ├── event-delegation.ts
│   ├── focus-manager.ts
│   ├── form-disabler.ts
│   ├── loading-indicator.ts
│   ├── modal-manager.ts
│   └── observer-manager.ts
├── state/                       # State management
│   ├── form-lifecycle-manager.ts
│   └── tree-renderer.ts
├── transport/                   # Network layer
│   └── websocket.ts
├── utils/                       # Utilities
│   ├── logger.ts
│   ├── rate-limit.ts
│   └── testing.ts
└── tests/                       # Test suite

Running Tests

# Run all tests
npm test

# Run specific test
npm test -- focus-manager

# Run with coverage
npm test -- --coverage

Building

# Build TypeScript and browser bundle
npm run build

# Build browser bundle only
npm run build:browser

# Clean build artifacts
npm run clean

Related Projects

Version Synchronization

This client library follows the LiveTemplate core library's major.minor version. For example:

  • Core: v0.1.5 → Client: v0.1.x (any patch version)
  • Core: v0.2.0 → Client: v0.2.0 (must match major.minor)

Patch versions are independent and can be incremented for client-specific fixes.

Contributing

See CONTRIBUTING.md for development guidelines.

License

MIT License - see LICENSE for details.

Support