Skip to main content
Module

x/tag/examples/index.html

A tiny functionally declarative reactive web programming kernel
Go to Latest
File
<!doctype html><html lang=""> <head> <meta charset="utf-8"> <title>Tag</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css"> @font-face { font-family: 'Fira Code'; src: url('assets/FiraCode-VF.ttf') format("truetype-variations"); font-weight: 1 999; }
@font-face { font-family: 'STIXTwoText'; src: url('assets/STIXTwoText[wght].ttf') format("truetype-variations"); font-weight: 400 700; }
@font-face { font-family: 'STIXTwoText'; src: url('assets/STIXTwoText-Italic[wght].ttf') format("truetype-variations"); font-style: italic; }
html { background: oldlace; font-size: 1.1em; font-family: 'STIXTwoText'; } body { line-height: 1.5; max-width: 45rem; margin: 0 auto; padding: 2rem 1rem; overflow-x: hidden; }
*:focus { border-radius: none; outline: 2px dashed orange; outline-offset: .5rem; }
h2 { margin-top: 5rem; }
h3 { margin-top: 3rem; }
hr { border: none; border-top: 1px dashed orange; margin-top: 3rem; }
nav { border-top: 1px dashed orange; border-bottom: 1px dashed orange; padding: 1rem; margin: 3rem 0; font-style: italic; }
pre, code { background: papayawhip; border: 1px dashed orange; font-family: 'Fira Code'; font-size: 1.1em; }
xmp { font-family: 'Fira Code'; }
pre { padding: 1rem 2rem; margin-bottom: 2rem; overflow-x: auto; }
code { display: inline-block; padding: 2px .5rem; }
dt { margin-bottom: .5rem; }
dd { margin-bottom: 2rem; } </style> </head>
<body> <center> <h1><code>&lt;tag&gt;</code></h1> <p> The portable port-able part of the web for the whole wide world </p>
<rainbow-button> <a href="./tag.zip" class="rainbow-button"> Download Now </a> </rainbow-button>
<nav> View <a href="#documentation" id="details-link">Documentation</a> and <a href="#examples">Examples</a>. Or learn <a href="#author">about the author</a>. </nav> </center>
<p style="font-size: 1.5em"> <strong>Tag provides a unified approach for</strong> <highlighter color="orange">rendering</highlighter>, <highlighter color="rebeccapurple">scoped styles</highlighter>, <highlighter color="lime">event delegation</highlighter>, <highlighter color="dodgerblue">state management</highlighter>, and <strong>only those four things</strong>. Plainly, Tag is a <a href="https://developer.mozilla.org/en-US/docs/Web/javascript">trifecta</a> of <a href="https://developer.mozilla.org/en-US/docs/Web/HTML">fundamental</a> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS">techonolgies</a> designed to build expressive web applications. </p>
<hr />
<h2>Quick Start <a href="./hello/hello-world.html">View Example</a></h2> <p> Hello World is a common program to write when first learning something new. The code below imports <code>tag.js</code>, creates a custom tag, and sets the content to 'Hello World!' </p> <pre><xmp>import tag from 'https://deno.land/x/tag'tag('hello-world').render(() => 'Hello World!')</xmp></pre>
<p><em> <strong>Tip!</strong> View the source of the example page to see &lt;hello-world&gt; in action! </em></p> <a name="documentation"></a> <h2>Documentation</h2> <p> <code> <strong>const $ = tag(selector: string [, state: object]) : object</strong> </code> <p> Creates an custom, scoped HTML tag. Requires a selector: a CSS selector. An optional second argument may be passed for seeding the initial state. </p> <p> It will return an object with the selector as an attribute and the following namespaced functions. </p> </p> <details> <summary class="rainbow-button"> Toggle Visibility of returned object properties. </summary> <br/> <dl> <dt><code>$.render(function(target: EventTarget))</code></dt> <dd> 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. </dd> <dt><code>$.style(stylesheet: string)</code></dt> <dd> Expects a CSS stylesheet as a string. The ampersand (&amp;) symbol may be used to scope rulesets. </dd> <dt><code>$.on(eventType: string, selector: string, function(event)) : function</code></dt> <dd> An event delegator that expects three arguments. A css selector, and a handler. No selector will listen on the tag's root. Returns a function to remove the listener when invoked. </dd> <dt><code>$.read() : object</code></dt> <dd> Returns the current state. </dd> <dt><code>$.write(payload [, function(state, payload)])</code></dt> <dd> 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 </dd> </dl> </details>
<p> <strong>Browser Support:</strong> The tail feature set for this application is ES Modules, which is supported by all modern browsers. For an entertaining summary, please refer to <a href="https://www.youtube.com/watch?v=dAIckpwW9ds">Making Future Interfaces: ES Modules</a>. </p>
<hr />
<a name="examples"></a> <h2>Examples</h2> <h3><code>&lt;hello-name&gt;</code> <a href="./hello/hello-name.html">View Example</a></h3> <p> The Hello Name example shows the fundamentals of incorporating variables into the tag's state. </p>
<pre><xmp><!-- hello-name.html --><hello-name></hello-name>
<script type="module"> import tag from 'https://deno.land/x/tag'
const $ = tag('hello-name', { 'name': 'Earth' })
$.render(() => { const { name } = read()
return `Hello ${name}` })</script></xmp></pre>
<dl> <!-- hello-nickname --> <dt><code>&lt;hello-nickname&gt;</code> <a href="./hello/hello-nickname.html">View Example</a></dt> <dd> Demonstrates local two-way data binding and persisting updates across page reloads. </dd>
<!-- hello-universe --> <dt><code>&lt;hello-universe&gt;</code> <a href="./hello/hello-universe.html">View Example</a></dt> <dd> An application for managing planet information and viewing a sequential representation of our solar system. </dd>
<!-- hello-gallery --> <dt><code>&lt;hello-gallery&gt;</code> <a href="./hello/hello-gallery.html">View Example</a></dt> <dd> A static photo gallery that upgrades to a carousel with progressive enhancement. </dd>
<!-- hello-editor --> <dt><code>&lt;hello-editor&gt;</code> <a href="./hello/hello-editor.html">View Example</a></dt> <dd> What-You-See-Is-What-You-Get style content editing with <a href="https://quilljs.com/">QuillJS</a>. </dd>
<!-- hello-map --> <dt><code>&lt;hello-map&gt;</code> <a href="./hello/hello-map.html">View Example</a></dt> <dd> A <a href="https://maplibre.org">maplibre.org</a> integration that incorporates live realtime data. A direct port of <a href="https://maplibre.org/maplibre-gl-js-docs/example/live-geojson/">this example from their official docs</a>. </dd>
<!-- hello-reddit --> <dt><code>&lt;hello-reddit&gt;</code> <a href="./hello/hello-reddit.html">View Example</a></dt> <dd> A <a href="https://old.reddit.com">reddit</a> integration that exposes their API over HTML. Control which subreddits are queried and how they are sorted with attributes. </dd>
<!-- hello-launcher --> <dt><code>&lt;hello-launcher&gt;</code> <a href="./hello/hello-launcher.html">View Example</a></dt> <dd> An application that opens and manages other applications. Inspired by and a prototype for <a href="https://forum.solidproject.org/t/idea-launcher-app/3468">this forum post</a>. </dd>
<!-- window-pane --> <dt><code>&lt;window-pane&gt;</code> <a href="./fun/window-pane.html">View Example</a></dt> <dd> The foundation for a minimal window manager using a CSS stylesheet that replicates <a href="https://khang-nd.github.io/7.css/">Windows 7</a>. </dd>
<!-- solid-user --> <dt><code>&lt;solid-user&gt;</code> <a href="./solid/solid-user.html">View Example</a></dt> <dd> A <a href="https://solidproject.org">Solid POD</a> authenticator. This allows people to connect to their preferred identity provider. </dd>
<!-- todo-list --> <dt><code>&lt;todo-list&gt;</code> <a href="./todo-list/index.html">View Example</a></dt> <dd> A <a href="https://todomvc.com/">TodoMVC</a> application that utilizes <a href="https://solidproject.org">Solid</a> as a backend. </dd> </dl>
<hr />
<a name="author"></a> <div style="float: right; max-width: 240px; border: 2px orange dashed; padding: 1rem; margin: 4rem 0 1rem 1rem;"> <h3 style="margin-top: 0;">Inspirations</h3> <p> Inspiring people building interesting projects are everywhere. These links helped shape Tag's development by just being cool things on the internet. </p> <ul> <li> <a href="https://small-tech.org">Small Technology Foundation</a> </li> <li> <a href="https://solidproject.org/">Solid Project</a> </li> <li> <a href="https://spritelyproject.org/">Spritely Project</a> </li> <li> <a href="https://100r.co">Hundredrabbits</a> </li> <li> <a href="https://safenetwork.tech/">Safe Network</a> </li> <li> <a href="https://owncast.online/">Owncast</a> </li> </ul> </div>

<h2>About the Author</h2> <p> <a href="https://tylerchilds.com">Tyler Childs</a> 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. </p>
<p> You can reach him via email at <a href="mailto:yooo@tychi.me">yooo@tychi.me</a> for any reason at any time. Response times may vary. </p> <p><strong>Fun fact!</strong> <a href="https://thelanding.page/tag">Tag</a> is the final part in a now-complete solo trilogy. <a href="https://www.tylerchilds.com/projects/vanilla-html/">Vanilla HTML</a> was a flop in 2013 and <a href="https://www.cutestrap.com/">Cutestrap</a> was a cult-hit in 2016! <h2>Source Code</h2> <p> Available on <a href="https://github.com/tylerchilds/tag">GitHub</a> under the <a href="https://creativecommons.org/licenses/by-sa/4.0/legalcode">CC BY-SA 4.0</a> </p>
<footer> <center style="font-style: italic; color: grey;"> Established: 2021. Last updated: 2022/06/13 (YYYY/MM/DD) </center> </footer>
<script type="module"> import tag from '../mod.js'
tag('#details-link').on('click', '', openAccordion)
const accordion = tag('details')
accordion.on('click', 'summary', function toggle() { const { open } = accordion.read() accordion.write({ open: ! open }) })
function openAccordion () { accordion.write({ open: true }) document.querySelector(accordion.selector) .setAttribute('open', 'true') } </script> <script src="../src/tags/highlighter.js" type="module"></script> <script src="../src/tags/rainbow-button.js" type="module"></script> <script type="module"> import handleKonami from '../src/tags/konami-kid.js' handleKonami(async () => { document.body.innerHTML = ` <guitar-hero></guitar-hero> `
const { default: guitarHero } = await import('../src/games/guitar-hero.js')
guitarHero.style(` * { box-sizing: border-box; padding: 0; margin: 0; } body { all: unset; } & { display: grid; height: 100vh; width: 100vw; } `) }) </script> </body></html>