<tag>

The portable port-able part of the web for the whole wide world

Download Now

Tag provides a unified approach for rendering, scoped styles, event delegation, state management, and only those four things. Plainly, Tag is a trifecta of fundamental techonolgies designed to build expressive web applications.


Quick Start View Example

Hello World is a common program to write when first learning something new. The code below imports tag.js, creates a custom tag, and sets to be the content to 'Hello World!'

import tag from 'https://thelanding.page/tag/tag.js'
tag('hello-world').html(() => 'Hello World!')

Tip! View the source of the example page to see <hello-world> in action!

Documentation

tag(slug: string [, state: object]) : object

Creates an custom, scoped HTML tag. Requires a slug, which is a CSS selector as a string. An optional second argument may be passed for seeding the initial state.

It will return an object with the slug as an attribute and the following namespaced functions.

Toggle Visibility of returned object properties.
html(function(target: EventTarget))
Expects a function that returns HTML as a string to be rendered into the provided target. A falsey return will leave the target node untouched. This function will be invoked whenever state changes.
css(stylesheet: string)
Expects a CSS stylesheet as a string. The ampersand (&) symbol may be used to scope rulesets.
on(eventType, selector, function(event)) : function
An event delegator that expects three arguments. An event type, a css selector, and a handler. No selector will listen on the tag's root. Returns a function to remove the listener when invoked.
get() : object
Returns the current state.
set(payload [, function(state, payload)])
Merges the payload into the current state. An optional second argument for managing the state update may be provided. That function will be called with the current state and the payload. It expects the reconciled, complete state to be returned
restore() : promise(state)
Recovers the previous state allowing for persisting data across page refreshes. Called automatically when a new tag is initialized. Returns a promise with the tag's state.

Dependencies: There is one third-party dependency, diffHTML.

Browser Support: The tail feature set for this application is ES Modules, which is supported by all modern browsers. For an entertaining summary, please refer to Making Future Interfaces: ES Modules.


Examples

<hello-name> View Example

The Hello Name example shows the fundamentals of incorporating variables into the tag's state.

<!-- hello-name.html -->
<hello-name></hello-name>

<script type="module">
  import tag from './tag.js'

  const { html, get } = tag('hello-name', {
    'name': 'Earth'
  })

  html(() => {
    const { name } = get()

    return `Hello ${name}`
  })
</script>
<hello-nickname> View Example
Demonstrates local two-way data binding and persisting updates across page reloads.
<hello-universe> View Example
An application for managing planet information and viewing a sequential representation of our solar system.
<hello-gallery> View Example
A static photo gallery that upgrades to a carousel with progressive enhancement.
<hello-editor> View Example
What-You-See-Is-What-You-Get style content editing with QuillJS.
<hello-map> View Example
A maplibre.org integration that incorporates live realtime data. A direct port of this example from their official docs.
<hello-reddit> View Example
A reddit integration that exposes their API over HTML. Control which subreddits are queried and how they are sorted with attributes.
<hello-launcher> View Example
An application that opens and manages other applications. Inspired by and a prototype for this forum post.
<window-pane> View Example
The foundation for a minimal window manager using a CSS stylesheet that replicates Windows 7.
<solid-todo> View Example
A work-in-progress TodoMVC application that utilizes Solid as a backend.
<solid-user> View Example
A Solid POD authenticator. This allows people to connect to their preferred identity provider.
Tip! Enter the Konami Code for a suprise! Enter it again for more!

Inspirations

Inspiring people building interesting projects are everywhere. These links helped shape Tag's development by just being cool things on the internet.

About the Author

Tyler Childs is a netizen with a deep passion for the open web and radical transparency. He believes everyone can go further together and sharing knowledge is critical to group success.

Currently, he's employed by Netflix.

You can reach him via email at yooo@tychi.me for any reason at any time. Response times may vary.

Fun fact! Tag is the final part in a now-complete solo trilogy. Vanilla HTML was a flop in 2013 and Cutestrap was a cult-hit in 2016!

Source Code

Available on Gitea under the MIT license.