Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117<!doctype html><html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="icon" type="image/svg+xml" href="data:" /> <link rel="stylesheet" href="reset.css" /> <title>dhtml</title> <script type="module"> import { html } from './dist/index.js' import { createRoot, hydrate, invalidate } from './dist/client.js' import { renderToString } from './dist/server.js'
const url = ({ href }) => html`<a href=${href}>${href}</a>`
const code = [ `import { html } from '`, url(new URL('dist/index.js', location.href)), `'import { createRoot, invalidate } from '`, url(new URL('dist/client.js', location.href)), `'
const app = { i: 0, render() { return html\` <button onclick=\${() => { this.i++ invalidate(this) }} > Count: \${this.i} </button> \` },}
createRoot(document.body).render(app)`, ]
const app = { i: 0, render() { return html` <main style="padding: 1rem; display: flex; flex-direction: column; gap: 1rem"> <header> <h1><code>dhtml</code></h1> <p>a post-component library for building user interfaces on the web.</p> <p><a href="https://github.com/tombl/dhtml">github</a></p> </header> <pre style="tab-size: 2">${code}</pre> <button onclick=${() => { this.i++ invalidate(this) }} > Count: ${this.i} </button> </main> ` }, }
if (new URLSearchParams(location.search).has('ssr')) { navigator.clipboard.writeText(renderToString(app).replaceAll(location.origin, 'https://tombl.github.io/dhtml')) }
let root if (document.body.childElementCount === 0) { root = createRoot(document.body) root.render(app) } else { root = hydrate(document.body, app) }
Object.assign(globalThis, { createRoot, html, root }) </script> </head> <body> <?[> <main style="padding: 1rem; display: flex; flex-direction: column; gap: 1rem"> <header> <h1><code>dhtml</code></h1> <p>a post-component library for building user interfaces on the web.</p> <p><a href="https://github.com/tombl/dhtml">github</a></p> </header> <pre style="tab-size: 2" ><?[><?[>import { html } from '<?]><?[><a href="https://tombl.github.io/dhtml/dist/index.js"><?[>https://tombl.github.io/dhtml/dist/index.js<?]></a><?]><?[>'import { createRoot, invalidate } from '<?]><?[><a href="https://tombl.github.io/dhtml/dist/client.js"><?[>https://tombl.github.io/dhtml/dist/client.js<?]></a><?]><?[>'
const app = { i: 0, render() { return html` <button onclick=${() => { this.i++ invalidate(this) }} > Count: ${this.i} </button> ` },}
createRoot(document.body).render(app)<?]><?]></pre> <button>Count: <?[>0<?]></button> </main> <?]> </body></html>