Skip to content

Commit

Permalink
Use a code style closer to trunk branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
lapo-luchini committed May 12, 2024
1 parent 4c1706f commit 0d4d50a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
21 changes: 10 additions & 11 deletions context.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ export function bindContextMenu(node) {
const valueEnabled = type != 'SET' && type != 'SEQUENCE';
node.onclick = function (event) {
// do not show the menu in case of clicking the icon
if (event.srcElement.nodeName === 'SPAN') {
contextMenu.style.left = event.pageX + 'px';
contextMenu.style.top = event.pageY + 'px';
contextMenu.style.visibility = 'visible';
contextMenu.node = this;
btnHideTree.innerText = (node.className == 'node') ? 'Hide subtree' : 'Show subtree';
btnHideTree.style.display = node.className.startsWith('node') ? 'block' : 'none';
btnCopyValue.style.display = valueEnabled ? 'block' : 'none';
event.preventDefault();
event.stopPropagation();
}
if (event.srcElement.nodeName != 'SPAN') return;
contextMenu.style.left = event.pageX + 'px';
contextMenu.style.top = event.pageY + 'px';
contextMenu.style.visibility = 'visible';
contextMenu.node = this;
btnHideTree.innerText = (node.className == 'node') ? 'Hide subtree' : 'Show subtree';
btnHideTree.style.display = node.className.startsWith('node') ? 'block' : 'none';
btnCopyValue.style.display = valueEnabled ? 'block' : 'none';
event.preventDefault();
event.stopPropagation();
};
}

Expand Down
30 changes: 8 additions & 22 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
Expand All @@ -24,7 +24,7 @@ const
ellipsis: '\u2026',
tag: function (tagName, className, text) {
let t = document.createElement(tagName);
t.className = className;
if (className) t.className = className;
if (text) t.innerText = text;
return t;
},
Expand Down Expand Up @@ -53,16 +53,11 @@ const

export class ASN1DOM extends ASN1 {

buf2hex(buffer) {
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join(' ');
}

toDOM(spaces) {
spaces = spaces || '';
let isOID = (typeof oids === 'object') && (this.tag.isUniversal() && (this.tag.tagNumber == 0x06) || (this.tag.tagNumber == 0x0D));
let node;
node = document.createElement('li');
node.asn1 = this;
let node = DOM.tag('li');
node.asn1 = this;
let head = DOM.tag('span', 'head');
const typeName = this.typeName().replace(/_/g, ' ');
if (this.def) {
Expand All @@ -79,8 +74,6 @@ export class ASN1DOM extends ASN1 {
head.appendChild(DOM.space());
}
}
head.setAttribute('pos', this.posStart());
head.setAttribute('end', this.posEnd());
head.appendChild(DOM.text(typeName));
let content;
try {
Expand Down Expand Up @@ -131,13 +124,11 @@ export class ASN1DOM extends ASN1 {
// summary.setAttribute('class', 'node');
contentNode = summary;
childNode = details;
}
else {
} else {
contentNode = node;
contentNode.setAttribute('class', 'node');
contentNode.appendChild(head);
}

this.node = contentNode;
this.head = head;
let value = DOM.tag('div', 'value');
Expand All @@ -162,14 +153,12 @@ export class ASN1DOM extends ASN1 {
}
value.innerHTML = s;
contentNode.appendChild(value);
let sub = DOM.tag('div', 'sub');
if (this.sub !== null) {
let ul = document.createElement('ul');
childNode.appendChild(ul);

let sub = DOM.tag('ul');
childNode.appendChild(sub);
spaces += '\xA0 ';
for (let i = 0, max = this.sub.length; i < max; ++i)
ul.appendChild(this.sub[i].toDOM(spaces));
sub.appendChild(this.sub[i].toDOM(spaces));
}
bindContextMenu(node);
return node;
Expand Down Expand Up @@ -228,9 +217,6 @@ export class ASN1DOM extends ASN1 {
node.appendChild(skip);
}
}
// set the current start and end position as an attribute at the node to know the selected area
node.setAttribute('pos', this.posStart());
node.setAttribute('end', this.posEnd());
this.toHexDOM_sub(node, 'tag', this.stream, this.posStart(), this.posLen());
this.toHexDOM_sub(node, (this.length >= 0) ? 'dlen' : 'ulen', this.stream, this.posLen(), this.posContent());
if (this.sub === null) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ if (window.devicePixelRatio >= 2 ) {
let treecollapse = document.querySelector(':root');
treecollapse.style.setProperty('--zoom-fix', '-1.5px');
}
console.log(window.devicePixelRatio);
console.log(window.devicePixelRatio);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"license": "ISC",
"bugs": { "url": "https://github.com/lapo-luchini/asn1js/issues" },
"homepage": "https://lapo.it/asn1js/",
"files": [ "asn1.js", "base64.js", "hex.js", "int10.js", "defs.js", "oids.js", "rfcdef.js", "dumpASN1.js" ],
"files": [ "asn1.js", "base64.js", "hex.js", "int10.js", "dom.js", "defs.js", "oids.js", "rfcdef.js", "dumpASN1.js" ],
"scripts": {
"lint": "npx eslint asn1.js base64.js hex.js int10.js defs.js oids.js rfcdef.js tags.js context.js index.js parseRFC.js dumpASN1.js test.js testDefs.js vite.config.js theme.js",
"lint": "npx eslint asn1.js base64.js hex.js int10.js dom.js defs.js oids.js rfcdef.js tags.js context.js index.js parseRFC.js dumpASN1.js test.js testDefs.js vite.config.js theme.js",
"lint-action": "npx @action-validator/cli .github/workflows/node.js.yml",
"build": "vite build",
"serve": "echo 'Connect to http://localhost:3000/' ; npx statik --port 3000 .",
Expand Down

0 comments on commit 0d4d50a

Please sign in to comment.