-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathlit-html.html
62 lines (60 loc) · 2.54 KB
/
lit-html.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="https://localvoid.github.io/uibench-base/0.1.0/styles.css" rel="stylesheet" />
<title>UI Benchmark: Vanilla [innerHTML]</title>
</head>
<body>
<div id="App"></div>
<script src="https://localvoid.github.io/uibench-base/0.1.0/uibench.js"></script>
<script type="module">
import {html, render, nothing} from 'https://unpkg.com/lit-html?module';
// UI
function tableCellClick(e, prop){
console.log(`Click${prop}`)
e.preventDefault()
e.stopPropagation()
}
const TableCell = prop=>html`<td
class="TableCell"
data-text=${prop}
@click=${e=>tableCellClick(e, prop)}
>${prop}</td>`
const TableRow = data=>html`<tr
class="TableRow ${data.active? 'active' : ''}"
data-id=${data.id}
>${TableCell(`#${data.id}`)} ${data.props.map(TableCell)}</tr>`
const Table = data=>html`<table class="Table"><tbody>${data.table.items.map(TableRow)}</tbody></table>`
const animBoxStyle = time=>`
border-radius:${time % 10}px;
background:rgba(0,0,0,${0.5 + ((time % 10) / 10)});
`
const AnimBox = props=>html`<div class="AnimBox" style=${animBoxStyle(props.time)} data-id=${props.id}></div>`
const Anim =data=>html`<div class="Anim">${data.anim.items.map(AnimBox)}</div>`
const TreeLeaf = props=>html`<li class="TreeLeaf">${props.id}</li>`
const TreeNode = data=>html`<ul class="TreeNode">${data.children.map(n=>n.container? TreeNode(n) : TreeLeaf(n))}</ul>`
const Tree = data=>html`<div class="Tree">${TreeNode(data.tree.root)}</div>`
// test
// uibench.init in the html (one per framework)
function renderState(container, state){
const location = state && state.location
const fs = {
table: Table,
anim: Anim,
tree: Tree,
}
render(html`<div class="Main">${fs[location](state)}</div>`, container)
}
function renderSamples(samples){
document.body.innerHTML = "<pre>" + JSON.stringify(samples, null, " ") + "</pre>"
}
let container
document.addEventListener("DOMContentLoaded", (e) => {
container = document.querySelector("#App")
uibench.run(state=>renderState(container, state), renderSamples)
})
</script>
<script>uibench.init("lit-html", "0.0.1")</script>
</body>
</html>