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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lite-html

v0.2.4

Published

A re-implementation of lit-html

Downloads

29

Readme

lite-html


Build Status NPM Latest version Code Style: prettier

A modern replacement for VirtualDOM rendering engines


  • Highly Flexible: Use expressive JavaScript templates that can render anything to HTML. Set properties and event listeners directly from the template.
  • Extremely Performant: Using the latest generation of rendering techniques, it easily outperforms contemporary VirtualDOM-based rendering as used in modern frontend frameworks.
  • Lightweight: ~2kb total size.
  • API Compatible with lit-html: Can be used as a drop-in replacement for lit-html in most projects.

Examples

Hello World

const template = name => html`
  <p>Hello ${name}</p>
`;

render(template('World'), document.body);

Simple List

const groceryList = items => html`
  <ul>
    ${items.map(
      item => html`
      <li>
        ${item.name} - ${item.quantity}
      </li>
    `
    )}
  </ul>`;

const groceries = [{ name: 'Apples', quantity: 2 }, { name: 'Oranges', quantity: 4 }];

render(groceryList(groceries), document.getElemenyById('groceryList'));

Installing

With NPM

npm install lite-html

Lite-html exposes an API through ES6 Modules. You can use it from CDN, or from your local node_modules folder after installing.

// From CDN
import { html, render } from 'https://unpkg.com/lite-html';

// From node_modules
import { html, render } from './node_modules/lite-html/lite-html.js';

API

The core API consists of two components.

render(<any>, Node)

The render function will render any type of object into the content of an HTML Node, usually the document body, a container element, or a shadowRoot.

The first argument is the object that will be rendered. It can be one of the following:

  • A TemplateResult (returned by the html tag)
  • A string, number, or boolean
  • An HTML DOM Node
  • An Array-like object
  • A Promise

Any other object is coerced to a String before being rendered.

The second argument is the Node that the object will be rendered into. The previous content of the Node will be removed.

html

The html is a JavaScript template tag that allows creation of flexible templates which will be interpreted as HTML. To use the tag, prepend it to any JavaScript template literal.

const template = () => html`<p>Hello World</p>`;

The contents of the template will be parsed as HTML. The flexibility comes from interpreted values that can be inserted into these templates.

const template = name => html`<p>Hello ${name}</p>`;

These interpreted values can in turn be any kind of object that lite-html can render, including nested templates and arrays.

Dynamic attributes

The html tag can also be used to set attributes on nodes. To set an attribute, assign the value of the attribute with an interpreted value. Lite-html requires that you omit the surrounding " when setting attributes.

const template = source => html`<img src=${source} />`;

// Composite attribute
const template = classString => html`<div class=${`red ${classString}`}></div>`;

Boolean attributes

You can set boolean attributes by prefixing the attribute name with ?

const template = secret => html`<p ?hidden=${secret}></p>`;

Properties

You can set properties on elements by prefixing an attribute name with .

const template = user => html`<user-panel .user=${user}></user-panel>`;

Event handlers

You can attach event handlers by prefixing an attribute name with @

const handleclick = () => {
  alert('clicked the button');
};
const template = () => html`<button @click=${handleClick}></button>`;

Why it is fast

Todo: Explain why it is fast

Differences with lit-html

Todo: Explain what is different

How it works

Todo: Explain all the things

License

MIT

Copyright © 2018-present, Goffert van Gool