}
const clock = Clock();
+// Returns a promise for a hue based on a hash of the string
+function hashHue(str: string) {
+ // Using crypto for this is overkill
+ return crypto.subtle.digest("SHA-256", new TextEncoder().encode(str)).then((buf) => (new Uint16Array(buf)[0] * 360) / 2 ** 16);
+}
+
const Model = {
addTask: function (timestamp: string, description: string): Element {
const task = document.createElement("div");
tag.appendChild(document.createTextNode(tagName));
tag.classList.add("tag");
tag.setAttribute("tabindex", "0");
+ hashHue(tagName).then((hue) => (tag.style.backgroundColor = `hsl(${hue},90%,45%)`));
task.appendChild(tag);
return tag;
},