const template = document.createElement("template");
template.innerHTML = `
`;
class PatekLogo extends HTMLElement {
calculateCircles() {
const inputValue = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek";
const normalizedInputValue = inputValue.normalize("NFD").replace(/[^\x00-\x7F]/g, "");
let outputChar = String.fromCharCode(0);
for (let i = 0; i < normalizedInputValue.length; i++) {
outputChar ^= normalizedInputValue[i].charCodeAt(0);
}
const opacities = outputChar.toString(2);
this.shadow.getElementById("circle0").style.fillOpacity = opacities[0];
this.shadow.getElementById("circle1").style.fillOpacity = opacities[1];
this.shadow.getElementById("circle2").style.fillOpacity = opacities[2];
this.shadow.getElementById("circle3").style.fillOpacity = opacities[3];
this.shadow.getElementById("circle4").style.fillOpacity = opacities[4];
this.shadow.getElementById("circle5").style.fillOpacity = opacities[5];
this.shadow.getElementById("circle6").style.fillOpacity = opacities[6];
}
constructor() {
super();
this.shadow = this.attachShadow({mode: "open"});
const clone = template.content.cloneNode(true);
clone.getElementById("titlePlaceholder").innerText = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek";
clone.getElementById("titleText").innerText = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek";
clone.getElementById("subtitleText").innerText = typeof this.attributes.subtitle !== "undefined" ? this.attributes.subtitle.value : "";
this.shadow.appendChild(clone);
this.shadow.getElementById("wrapper").style.display = "none";
this.calculateCircles();
window.addEventListener("load", () => {
this.shadow.getElementById("wrapper").style.display = "inline-block";
});
}
static get observedAttributes() { return ['title', 'subtitle']; }
attributeChangedCallback(name, oldValue, newValue) {
if (name === 'title') {
this.calculateCircles();
this.shadow.getElementById("titleText").innerText = newValue || "Pátek";
this.shadow.getElementById("titlePlaceholder").innerText = newValue || "Pátek";
} else if (name === 'subtitle') {
this.shadow.getElementById("subtitleText").innerText = newValue;
}
}
}
customElements.define("patek-logo", PatekLogo);