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

@matatbread/ai-ui

v0.15.4

Published

A tiny, genuinely functional UI framework for building dynamic HTML pages

Downloads

157

Readme

AI-UI

AI-UI ("Async Iterator User Interface") is a tiny, genuinely functional, UI framework for building dynamic HTML pages

It has 4 main features:

  • A simple mechanism for defining and using standard DOM elements, encouraging both composition and inheritance
  • A super-cool syntax (when) for inter-component communication using standard DOM events, avoiding the spaghetti of event listeners and state management
  • Dynamic DOM attributes and contents via standard JS async constructs - set your styles & content with Promises and async iterables.
  • A set of extensions to the standard browser/JS async iterables & generators, like map, filter, multi...

Design goals for AI-UI are:

  • Specify dynamic content in a static, declaritive DOM layout
  • Full use and compatability with all standard DOM elements, events and JS async constructs like Promises, generators & iterators - no special compilation steps, additional syntax, virtual DOM or complex API to learn. Freely mix and match with any existing UI toolkit which renders HTML or generates DOM nodes.
  • Tiny footprint (8Kb minified + gzipped), zero dependencies
  • Purely client-side, but of course being bullt with standard JS & DOM Elements, can be generated by your favourite server-side dev tools.
  • First-class support for Typescript (it is written in Typescript), prompting you with a rich set interfaces for your newly defined tags, and it supports tsx if you're a fan.

Think of it as a "spreadsheet" in your browser - you define the elements, styles and contents by referencing other elements and data sources in-situ, and you can encapsulate your dynamic tags for instant re-use.

Spreadsheet? How does that work?

Consider the static DOM layout, using a functional JS snippet:

  function now() {
    return new Date().toString();
  }

  div(
    "The time is:", now()
  )

What if the expression for the time could be truly dynamic, without any external rendering, diffing or "reaction"? If you could just enter the expression once, and the framework did the DOM updates, event handling and everything else?

That's what AI-UI does. Child elements and attributes can be living, changing expressions through the use of JavaScripts async iterators:

  const sleep = (t) => new Promise(resolve => setTimeout(resolve, t));

  async function *now() {
    while (true) {
      yield new Date().toString();
      await sleep(1000);
    }
  }

  div(
    "The time is:", now()
  )

That's it! A working clock, just by changing the second child in the <div> to an async iterator! See for yourself

AI-UI comes with a core set of functions & methods to turn DOM events into async iterators (via when), so your content can be derived from other elements, and a toolkit for mapping, filtering and processing async iterators in a natural way so your data flows throughout your system, filtered down to do the most minimal, performant DOM updates possible.

Use in a browser

Distibution files are included in the package as ESM (.mjs), CommonJS (.cjs) and HTML script tags (.js). Debug versions with inline sourcemaps and minified versions are placed in the /dist directory.

The naming convention is:

  /dist/ai-ui(.min).mjs   // ESM format
  /dist/ai-ui(.min).js    // <script> format
  /dist/ai-ui(.min).cjs   // CommonJS format

The /esm directory contains unbundled ESM files with inline sourcemaps and TypeScript .d.ts definitions for development.

ES6 import

  import * as AIUI from 'https://cdn.jsdelivr.net/npm/@matatbread/ai-ui/dist/ai-ui.mjs'; // or .min.mjs
  // You can, of course, just import the members you need...
  import { tag } from 'https://cdn.jsdelivr.net/npm/@matatbread/ai-ui/dist/ai-ui.mjs'; // or .min.mjs

HTML <script> tag

  <script src="https://cdn.jsdelivr.net/npm/@matatbread/ai-ui/dist/ai-ui.js"></script>
  <!-- defines global AIUI -->
  <script>
    const { tag } = AIUI;
    ...
  </script>

CommonJS (for bundling or other environments)

  npm i @matatbread/ai-ui
  const { tag } = require('@matatbread/ai-ui');

Get Started

Get started with simple, easy to maintain web pages that work seamlessly with user-input, remote data sources and other dynamic sources of data and interaction without the complexity of a bespoke build or execution framework.

Interested in contributing? Please check out the developers page.

AI-UI and it's closed-source precursors have been used in used a variety production contexts for years by thousands of end users:

  • Home Automation UI
  • Advanced analytics UI
  • Embedded Webcam UI
  • Internet dating Single Page Applications for mobile & desktop