Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
116 lines (106 loc) · 2.89 KB
/
Copy pathindex.html
File metadata and controls
116 lines (106 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!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
=> {
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
=> {
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
=> {
this.i++
invalidate(this)
}}
>
Count: ${this.i}
</button>
`
},
}
createRoot(document.body).render(app)<?]><?]></pre>
<button>Count: <?[>0<?]></button>
</main>
<?]>
</body>
</html>