-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrender.js
More file actions
54 lines (44 loc) · 1.23 KB
/
render.js
File metadata and controls
54 lines (44 loc) · 1.23 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
import decode from "./decoder.js";
/**
*
* Display of One Digit
*
* - using the output from the decoder
*
* __
* |__|
* |__|
*
*
*/
export function display(num = 0) {
// decode `num`
let decodedNum = decode(num);
// check & validate segments with CSS borders
let top = decodedNum.a === 1 ? "top" : "",
middle = decodedNum.g === 1 ? "top" : "",
bottom = decodedNum.d === 1 ? "bottom" : "",
upperLeft = decodedNum.f === 1 ? "left" : "",
lowerLeft = decodedNum.e === 1 ? "left" : "",
upperRight = decodedNum.b === 1 ? "right" : "",
lowerRight = decodedNum.c === 1 ? "right" : "";
// build digit
let template = document.createElement('div')
template.className = "digit";
template.innerHTML = `
<div class="${top} ${upperRight} ${upperLeft}"></div>
<div class="${lowerLeft} ${lowerRight} ${middle} ${bottom}"></div>
`;
// return template
return template;
}
// render digit
export function render(container, ...num) {
if (container instanceof HTMLElement) {
container.innerHTML = "";
for (const n of num) {
container.appendChild(display(n));
}
}
}
export default render;