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

lithent

v1.14.1

Published

An extensible virtual DOM library for lightweight use in a variety of environments.

Downloads

214

Readme

➿ lithent

An extensible JSX-based virtual DOM library for lightweight use in a variety of environments.

lithent-text

npm npm bundle size npm NPM

Lithent were developed to make it easy to insert Virtual DOM component fragments into pages already drawn with SSR, and are intended to be used lightly in a variety of situations.

(lithent.mjs 14.25 kB │ gzip: 4.49 kB │ map: 59.74 kB) (lithent.umd.js 10.39 kB │ gzip: 4.03 kB │ map: 58.16 kB)

🚩 Table of Contents

Thanks for the introduction

Why use Lithent?

Lithent have the bare minimum of necessary functionality, with no unnecessary features.

In a real-world development environment, you may want to use Virtual DOM lightly, with only the bare minimum of core functionality.

"Lithent" makes it easy to add, remove, and update virtual DOM to specific parts of a pre-drawn SSR page.

"Lithent" has implemented the bare minimum functionality needed to create and update virtual DOM in general (we only need to know 'render', 'mounter', 'updater', 'renewer', 'mountCallback', and 'updateCallback').

We provide code in the form of 'helpers' that extend the basic functionality, but using the helpers is only optional and users can extend and develop custom helpers for their own projects.

Approach with the developer-friendly concept of closures between "component mounter" and "renderer"

JavaScript users are used to using closures and love to develop with them.

"Lithent" provides a familiar approach to my JavaScript development, as it leverages the properties of higher-order functions and closures to define and recycle the state of a component.

Basic Guide

  • https://superlucky84.github.io/lithent/

How To Install

Use NPM

pnpm add lithent

Or Use CDN

It's easier to use lithent with JSX or HTM.

With JSX

With FTAGS

You don't need to use h functions or JSX, you can call functions to mark them up. When creating a component, use fMount instead of mount. When creating a fragment, use fFragment instead of Fragment.

/* ESM */
import { render, h } from 'lithent';
import { fTags, fFragment, fMount } from 'lithent/ftags';

const { section, div, p, br, strong } = fTags;

/* UMD
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/lithent.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/helper/dist/lithentHelper.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/ftags/dist/lithentFTags.umd.js"></script>

const { render } = lithent;
const { fTags, fMount, fFragment } = lithentFTags;
const { section, div, p, br, strong } = fTags;
*/

const fTagComponent = fMount<{ firstProp: number }>((_r, props, children) => {
  return () =>
    fFragment(
      'first inner',
      div({ style: { border: '1px solid red' } }, 'second inner'),
      div('The props argument can be omitted.'),
      props.firstProp,
      ...children
    );
});

render(
  fTagComponent(
    { firstProp: 3 }, // The props argument can be omitted.
    div({ style: { border: '1px solid green' } }, `Fchildren1`),
    'Fchildren2',
    br()
  ),
  document.getElementById('root')
);

With HTM

import { lTag } from 'lithent/tag';
const destroy = render(lTag`<${Component} />`, document.getElementById('root'), document.getElementById('#insert-before-this-element'));

Examples

With ESM

import { h, render, mount, Fragment } from 'lithent';
import { lTag } from 'lithent/tag';
import { state } from 'lithent/helper';

const Component = mount((renew, _props) => {
  const count = state(0, renew);

  const change = () => {
    count.value += 1;
  };

  // Updater
  return () => lTag`
    <${Fragment}>
      <li>count: ${count.value}</li>
      <button onClick=${change}>increase</button>
    <//>
  `;
});

// appendChild or insertBefore
// The third argument is an optional value for insertBefore.
const destroy = render(lTag`<${Component} />`, document.getElementById('root'), document.getElementById('#insert-before-this-element'));

With UMD

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/lithent.umd.js"></script>
<!--script src="https://cdn.jsdelivr.net/npm/[email protected]/helper/dist/lithentHelper.umd.js"></script-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/tag/dist/lithentTag.umd.js"></script>
<!--script src="https://cdn.jsdelivr.net/npm/[email protected]/ftags/dist/lithentFTags.umd.js"></script-->

<div id="root"></div>

<script>
const { h, Fragment, render, mount } = lithent;
const { lTag } = lithentTag;
// const { state } = lithentHelper;

const Component = mount(renew => {
  count = 0;

  const change = () => {
    count += 1;
    renew();
  };

  // Updater
  return () => lTag`
    <${Fragment}>
      <li>count: ${count}</li>
      <button onClick=${change}>increase</button>
    <//>
  `;
});

// appendChild or insertBefore
// The third argument is an optional value for insertBefore.
const destroy = render(lTag`<${Component} />`, document.getElementById('root'), document.getElementById('#insert-before-this-element'));
</script>

Related Projects

  • htm - making Hyperscript Tagged Markup possible

Develop Guide

It's open source, so you can develop and contribute together.

pnpm install (this project was created using pnpm.)

npm install -g pnpm

project install

git clone https://github.com/superlucky84/lithent.git

cd lithent

pnpm install

project build

pnpm build

Running the development environment

pnpm dev // or pnpm dev:core

Test

To fully test everything, including plugins like helper and ftags, a build is required.

pnpm install
pnpm build
pnpm test