/** * Helper */ function getNode(n, v) { n = document.createElementNS("http://www.w3.org/2000/svg", n); for (var p in v) { if (p == '_text') { n.innerHTML = v[p] } else { n.setAttributeNS(null, p, v[p]); } } return n } function cE(str) { return document.createElement(str); } function cENS(str) { return document.createElementNS("http://www.w3.org/2000/svg", str); } function tN(str, par) { if (par) { par.appendChild(document.createTextNode(str)); } return document.createTextNode(str); } function genE(type, obj, par) { let e = cE(type); for (let attr in obj) { if (attr == "_text") { e.appendChild(tN(obj[attr])); continue; } e.setAttribute(attr, obj[attr]); } if (par) { par.appendChild(e); } // e.textContent = ... return e; } function genENS(type, obj, par) { let e = cENS(type); for (attr in obj) { if (attr == "_text") { e.appendChild(tN(obj[attr])); } else { e.setAttribute(attr, obj[attr]); } } if (par) { par.appendChild(e); } // e.textContent = ... return e; } function capFirst(string) { if (!string) return; return string.charAt(0).toUpperCase() + string.slice(1); } function byId(str) { return document.getElementById(str) } // Erzeugt einen vertikalen Abstand. let gap = function (parent, scale) { scale = scale || 1 let newGap = genE('div', { style: 'padding-top: calc(var(--spacing) * ' + scale + ');' }, parent) return newGap } let idStorage = [] function genID() { let newId = Math.floor(Math.random() * 10000000).toString() while (idStorage.indexOf(newId) >= 0) return genID() idStorage.push(newId) return newId } export { genE, tN, gap, genID }