aboutsummaryrefslogtreecommitdiff
path: root/static/js/conversation.js
blob: 30a431fe406e173a1af85be3adab0d3e165237ee (plain)
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
import { g, h, x } from "./xeact.min.js";
import { div, span } from "./xeact-html.min.js";

export const mkConversation = (who, mood, message, extraClasses = "") =>
      h("div", {className: "conversation gruvbox-dark " + extraClasses}, [
          h("div", {className: "conversation-picture conversation-smol"}, [
              h("picture", {}, [
                  h("source", {type: "image/avif", srcset: `https://cdn.christine.website/file/christine-static/stickers/${who.toLowerCase()}/${mood}.avif`}),
                  h("source", {type: "image/webp", srcset: `https://cdn.christine.website/file/christine-static/stickers/${who.toLowerCase()}/${mood}.webp`}),
                  h("img", {alt: `${who} is ${mood}`, src: `https://cdn.christine.website/file/christine-static/stickers/${who.toLowerCase()}/${mood}.png`})
              ])
          ]),
          h("div", {className: "conversation-chat"}, [
              h("span", {innerText: "<"}),
              h("b", {innerText: who}),
              h("span", {innerText: "> "}),
              span({}, Array.from(message))
          ])
      ]);

export class Conversation extends HTMLElement {
    constructor() {
        super();

        let root = this.attachShadow({mode: "open"});
        let who = this.getAttribute("name");
        let mood = this.getAttribute("mood");

        root.appendChild(h("link", {rel: "stylesheet", href: "/css/hack.css"}));
        root.appendChild(h("link", {rel: "stylesheet", href: "/css/gruvbox-dark.css"}));
        root.appendChild(h("link", {rel: "stylesheet", href: "/css/shim.css"}));
        root.appendChild(mkConversation(who, mood, this.childNodes));
    }
}

window.customElements.define("xeblog-conv", Conversation);