-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdiff-simple.html
More file actions
62 lines (55 loc) · 1.84 KB
/
diff-simple.html
File metadata and controls
62 lines (55 loc) · 1.84 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
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🤖</text></svg>">
<title>Diff App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.row { display: flex; }
.column {
width: 500px;
margin: 2px;
}
.column textarea {
box-sizing: border-box;
width: 100%;
}
.add { background-color: #B5EFDB; }
.remove {
background-color: #FFC4C1;
text-decoration: line-through;
}
</style>
</head>
<body>
<script type="text/javascript" src="diff.min.js"></script>
<script type="text/javascript" src="van-latest.nomodule.min.js"></script>
<script>
const {button, div, span, textarea} = van.tags
const autoGrow = e => {
e.target.style.height = "5px"
e.target.style.height = (e.target.scrollHeight + 5) + "px"
}
const DiffApp = () => {
const oldTextDom = textarea({oninput: autoGrow, rows: 1})
const newTextDom = textarea({oninput: autoGrow, rows: 1})
const diff = van.state([])
return div(
div({class: "row"},
div({class: "column"}, oldTextDom), div({class: "column"}, newTextDom),
),
div({class: "row"},
button({onclick: () => diff.val = Diff.diffWords(oldTextDom.value, newTextDom.value)},
"Diff",
),
),
div({class: "row"}, () => div({class: "column", style: "white-space: pre-wrap;"},
diff.val.map(d => span({class: d.added ? "add" : (d.removed ? "remove" : "")}, d.value)),
)),
)
}
document.body.appendChild(DiffApp())
</script>
</body>
</html>