-
Notifications
You must be signed in to change notification settings - Fork 68
/
ndef-record.js
122 lines (106 loc) · 3.2 KB
/
ndef-record.js
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
117
118
119
120
121
122
export class NDEFRecord extends HTMLElement {
static get styles() {
return `
* {
width: 100%;
height: 100%;
text-align: center;
font-size: 14px;
}
.byte {
display: inline-flex;
flex-flow: row;
justify-content: center;
outline: 1px solid black;
}
.indices {
outline: none;
}
.TNF {
flex: 1 300%;
background-color: #c27aa0;
}
.MB { background-color: #6fa7dc; }
.ME { background-color: #6fa7dc; }
.CF { background-color: #a2c5c9; }
.SR { background-color: #93c57d; }
.IL { background-color: #ffd966; }
.Payload-length { background-color: #00ff01;}
.Type-length { background-color: #00ffff}
.Id-length { background-color: #ffd966}
.Type { background-color: #00ffff}
.Id { background-color: #ffd966}
.Payload {
background-color: #00ff01;
display: inline-flex;
flex-flow: column;
}
.hidden { display: none; }
.large { height: 4em;}
::slotted(*) {
margin: 6px;
}
.container {
outline: 2px solid black;
}
:host {
display: block;
max-width: 450px;
contain: style layout;
}
`;
}
constructor() {
super();
const header = this.getAttribute('header').split(',');
const content = this.getAttribute('content').split(',');
const short = this.getAttribute('short');
const noindices = this.getAttribute('noindices');
const toggle = (entry) => content[entry] === '_' ? 'hidden' : '';
const label = (entry, text) => content[entry] === '*' ? text : content[entry];
const hlabel = (entry, text) => header[entry] === '*' ? text : header[entry];
this.attachShadow({mode: 'open'});
this.shadowRoot.innerHTML = `
<style>${NDEFRecord.styles}</style>
<div class="byte indices ${noindices === null ? '' : 'hidden'}">
<div>7</div>
<div>6</div>
<div>5</div>
<div>4</div>
<div>3</div>
<div>2</div>
<div>1</div>
<div>0</div>
</div>
<div class="container">
<div class="byte">
<div class="MB">${hlabel(0, "MB")}</div>
<div class="ME">${hlabel(1, "ME")}</div>
<div class="CF">${hlabel(2, "CF")}</div>
<div class="SR">${hlabel(3, "SR")}</div>
<div class="IL">${hlabel(4, "IL")}</div>
<div class="TNF">${hlabel(5, "TNF")}</div>
</div>
<div class="byte Type-length">
${label(0, "TYPE LENGTH")}
</div>
<div class="byte Payload-length ${short !== null ? '' : 'large'}">
${label(1, "PAYLOAD LENGTH")}
</div>
<div class="byte Id-length ${toggle(2)}">
${label(2, "ID LENGTH")}
</div>
<div class="byte Type ${toggle(3)}">
${label(3, "TYPE")}
</div>
<div class="byte Id ${toggle(4)}">
${label(4, "ID")}
</div>
<div class="byte Payload ${toggle(5)}">
<slot name="payload">${label(5,"PAYLOAD")}</slot>
</div>
</div>
`;
}
}
customElements.define('ndef-record', NDEFRecord);