import { useMousePressed as Ke, reactive as g, onMounted as de, useMouseInElement as Ue, watch as X, onBeforeUnmount as Fe, ref as O, ColorHash as U, gunAvatar as Je, computed as p, ms as V, refDebounced as De, slugify as re, SEA as F, useStorage as Q, buffer as Ye, Gun as _, urlRegex as Ze, Fuse as ee, YAML as Ee, markdown as qe, lib as We, JSZip as xe, watchEffect as K, exports as He, base32 as me, useNow as Xe, computedAsync as Ve, DateTree as Ce, browser as Qe, useElementBounding as _e, useClamp as et, getArrow as tt, useCycleList as nt, toReactive as at, markRaw as ot, createDrauu as st, nextTick as rt } from "./vendor.es.js";
import { SEA as wa, gunAvatar as ba, mountClass as ya, mountElement as Sa, ms as ka, slugify as ja } from "./vendor.es.js";
function it(e = O(null)) {
  const { pressed: t } = Ke(), n = g({
    x: 0,
    y: 0,
    normX: 0,
    normY: 0,
    pressed: t,
    inside: !1
  });
  de(() => {
    document.addEventListener("mousemove", a);
    const { isOutside: o } = Ue(e);
    X(o, (s) => {
      n.inside = !s;
    });
  }), Fe(() => {
    document.removeEventListener("mousemove", a);
  });
  function a(o, s = e.value) {
    const r = s.closest("svg");
    if (!r)
      return;
    var i = r.createSVGPoint();
    i.x = o.clientX, i.y = o.clientY;
    let c = i.matrixTransform(r.getScreenCTM().inverse());
    n.x = c.x, n.y = c.y;
  }
  return {
    area: e,
    mouse: n
  };
}
const ct = {
  light: new U({
    saturation: [0.05, 0.08, 0.22],
    lightness: [0.85, 0.87, 0.9]
  }),
  pale: new U({
    saturation: [0.05, 0.42, 0.52],
    lightness: [0.75, 0.77, 0.9]
  }),
  regular: new U({
    saturation: [0.1, 0.5, 0.7],
    lightness: [0.3, 0.5, 0.7]
  }),
  deep: new U({
    saturation: [0.5, 0.6, 0.7],
    lightness: [0.5, 0.55, 0.6]
  }),
  dark: new U({
    saturation: [0.02, 0.5, 0.6],
    lightness: [0.18, 0.2, 0.5]
  })
};
function Re(e = "deep") {
  return typeof e == "object" ? new U(e) : ct[e];
}
function Ht({
  pub: e,
  size: t = 200,
  light: n = 0.5,
  overlay: a = 0.5,
  draw: o = "squares",
  attachment: s = "fixed"
} = {}) {
  if (!!e)
    return {
      background: `linear-gradient(hsla(255,0%,${n * 100}%,${a}), hsla(255,0%,${n * 100}%,${a})), url(${Je({
        pub: e,
        draw: o,
        reflect: !1,
        size: t
      })})`,
      backgroundSize: "cover, cover",
      backgroundAttachment: `${s},${s}`
    };
}
const ut = Re("deep");
function lt(e = O(), { TIMEOUT: t = 1e4 } = {}) {
  const n = b();
  return e = O(e), { account: p(() => {
    const o = g({
      pub: e,
      color: p(() => e.value ? ut.hex(e.value) : "gray"),
      profile: {
        name: ""
      },
      pulse: 0,
      lastSeen: p(() => {
        let s = Date.now() - o.pulse;
        return s > t ? V(s) : "online";
      }),
      blink: !1,
      db: n.user(e.value)
    });
    return n.user(e.value).get("pulse").on((s) => {
      o.blink = !o.blink, o.pulse = s;
    }).back().get("profile").map().on((s, r) => {
      o.profile[r] = s;
    }), o;
  }) };
}
function Xt() {
  const e = b(), { user: t } = E(), n = O("general"), a = g({
    general: {}
  }), o = e.user(f.pub).get("chat");
  o.map().on((l, d) => {
    var x;
    const [v, P] = d.split("@");
    a[v] = a[v] || {}, l ? a[v][P] = l : (x = a == null ? void 0 : a[v]) == null || delete x[P];
  });
  function s(l) {
    o.get(`${re(l) || l}@${t.pub}`).put(!0, null, { opt: { cert: f.features.chat } });
  }
  const r = p(() => e.user(f.pub).get("chat/" + n.value)), i = p(() => {
    const l = g({});
    return r.value.map().on((d, v) => {
      const P = v.substring(0, 13), x = v.substring(14);
      l[v] = {
        timestamp: P,
        author: x,
        text: d
      };
    }), l;
  }), c = p(() => Object.values(i.value || {})), u = De(c), m = p(() => u.value.sort((l, d) => l.timestamp > d.timestamp ? 1 : -1));
  function h(l) {
    if (!l)
      return;
    let d = Date.now();
    r.value.get(`${d}@${t.pub}`).put(l, null, { opt: { cert: f.features.chat } });
  }
  return {
    send: h,
    addChat: s,
    currentChat: n,
    chats: a,
    messages: i,
    sorted: m
  };
}
function Vt(e, { parse: t = !0 } = {}) {
  const n = b(), { user: a } = E(), o = g({}), s = O();
  n.user(e).get("epub").once((h) => s.value = h), n.user(e).get("chat").get(a.pub).map().once(function(h, l) {
    r(h, l, e, this);
  }), n.user().get("chat").get(e).map().once(function(h, l) {
    r(h, l, a.pub, this);
  });
  function r(h, l, d, v) {
    v.map().on(async (P, x) => {
      if (P && P.startsWith("SEA")) {
        const M = await F.secret(s.value, a.pair()), L = await F.work(M, l), y = await F.decrypt(P, L);
        if (!y || typeof y != "object")
          return;
        o[x] = {
          timestamp: y.timestamp,
          author: d,
          text: y.text
        };
      }
    });
  }
  async function i(h) {
    if (!h)
      return;
    const l = new Date(), d = {
      timestamp: l.getTime(),
      text: h
    }, v = l.toLocaleDateString("en-CA"), P = await F.secret(s.value, a.pair()), x = await F.work(P, v), M = await F.encrypt(d, x);
    n.user().get("chat").get(e).get(v).set(M);
  }
  const c = p(() => Object.values(o || {})), u = De(c), m = p(() => u.value.sort((h, l) => h.timestamp > l.timestamp ? 1 : -1));
  return {
    send: i,
    messages: o,
    sorted: m
  };
}
function Qt(e) {
  const t = b(), { user: n } = E(), a = g({}), o = O(!1);
  return t.user(e).get("epub").on((r) => o.value = r), t.user(e).get("chat").get(n.pub).map().map().on((r, i) => {
    r && !r.startsWith("SEA") || (a[i] = r);
  }), t.user().get("chat").get(e).map().map().on((r, i) => {
    r && !r.startsWith("SEA") || (a[i] = r);
  }), { count: p(() => Object.keys(a).length), available: o };
}
function _t() {
  const e = b(), { user: t } = E(), n = g({});
  return t.is && (e.user().get("chat").map().on((a, o) => {
    n[o] = a;
  }), e.user().get("mates").map().on(async (a, o) => {
    const s = await e.user(o).get("mates").get(t.pub), r = await e.user(o).get("epub");
    s && r && (n[o] = a);
  })), { list: n };
}
const Ne = "https://etogun.glitch.me/gun", Y = Q("peer", Ne), N = g({
  list: [],
  peer: Y.value,
  host: new URL(Y.value).hostname,
  status: "offline",
  started: 0,
  pulse: 0,
  lag: 0,
  diff: p(() => N.pulse - N.started),
  age: p(() => V(N.diff)),
  delay: p(() => Date.now() - N.pulse),
  blink: !1
});
X(() => N.pulse, (e, t) => {
  N.blink = !N.blink, N.lag = e - t - 500;
});
function ft(e) {
  Y.value = e, window.location.reload();
}
function dt() {
  Y.value = Ne, window.location.reload();
}
function en() {
  const e = b();
  return N.pulse == 0 && e.get(N.host).map().on((t, n) => {
    N[n] = t;
  }), { relay: N, setPeer: ft, resetPeer: dt };
}
window.Buffer = Ye.Buffer;
window.setImmediate = setTimeout;
let k, ne;
function b(e = { localStorage: !1 }) {
  return k || (k = _({ peers: [Y.value], ...e })), k;
}
function mt(e = { localStorage: !1 }) {
  return ne || (ne = _({ peers: [Y.value], ...e })), ne;
}
var je, Ae;
const tn = (Ae = (je = _) == null ? void 0 : je.node) == null ? void 0 : Ae.soul;
var Oe, Pe;
const gt = (Pe = (Oe = _) == null ? void 0 : Oe.text) == null ? void 0 : Pe.random, ie = g({}), ce = g({});
async function pt({
  source: e = "https://raw.githubusercontent.com/wiki/amark/gun/volunteer.dht.md"
} = {}) {
  let a = (await (await fetch(e)).text()).match(Ze());
  return a.push(N.peer), a = Array.from(a), a.forEach((o) => {
    let s = new URL(o);
    if (s.pathname === "/gun" && s.pathname.indexOf("~~") === -1) {
      let r = performance.now();
      fetch(s.href, {
        method: "HEAD",
        mode: "cors",
        redirect: "follow",
        referrerPolicy: "no-referrer"
      }).then((i) => {
        let c = performance.now();
        i.ok ? ie[s.hostname] = {
          host: s.hostname,
          ping: (c - r).toFixed(),
          url: s.href
        } : ce[s.hostname] = i;
      }).catch((i) => {
        ce[s.hostname] = i;
      });
    }
  }), ie;
}
function nn() {
  return { relays: ie, errors: ce, loadRelays: pt };
}
function an(e) {
  return e.length == 44 && e.charAt(43) == "=";
}
async function on(e, t, n) {
  const a = await F.secret(t.epub, n);
  return await F.encrypt(e, a);
}
async function sn(e, t, n) {
  const a = await F.secret(t.epub, n);
  return await F.decrypt(e, a);
}
async function q(e) {
  return await F.work(e, null, null, { name: "SHA-256" });
}
async function H(e) {
  let t = typeof e == "string" ? e : JSON.stringify(e), n = await q(t);
  return { hashed: t, hash: n };
}
async function rn(e, t) {
  return await F.work(e, t, null, { name: "SHA-1", encode: "hex" });
}
function ht(e) {
  if (!e)
    return;
  const t = /[\+=\/]/g;
  return e.replace(t, vt);
}
function vt(e) {
  switch (e) {
    case "+":
      return "-";
    case "=":
      return ".";
    case "/":
      return "_";
  }
}
function cn(e) {
  if (!e)
    return;
  const t = /[\._\-]/g;
  return e.replace(t, wt);
}
function wt(e) {
  switch (e) {
    case "-":
      return "+";
    case ".":
      return "=";
    case "_":
      return "/";
  }
}
function un(e, t) {
  if (e) {
    if (Object.prototype.toString.call(e) === "[object Object]")
      return e;
  } else
    return t || {};
  try {
    return JSON.parse(e);
  } catch {
    return t || {};
  }
}
async function Me({
  pair: e,
  tag: t = "word",
  dot: n = "",
  users: a = "*",
  personal: o = !1
} = {}) {
  let s = { "*": `${t}` };
  n && (s["."] = n), o && (s["+"] = "*");
  try {
    return await F.certify(a, s, e);
  } catch (r) {
    console.log("cert error: ", r);
  }
}
window.issueCert = Me;
async function he({ pair: e, list: t = [] } = {}) {
  const n = {};
  for (let a of t)
    n[a.tag] = await Me({ ...a, pair: e });
  return n;
}
const G = g({
  word: null,
  def: null
}), ue = Q("dict-lang", "en");
X(G, () => {
  G.word && G.def && bt(G);
});
function ln() {
  const e = b();
  E();
  const t = O(""), n = p(() => Te(t.value));
  async function a() {
    const c = await q(n.value);
    e.get("dict").get("#word").get(c).put(n.value), G.word = c, t.value = "";
  }
  const o = g({});
  e.user(f.pub).get("dict").map().on(async (c, u) => {
    if (!c)
      return;
    let m = u.slice(0, 44), h = u.slice(45, 89), l = await e.get("dict").get("#def").get(h).then();
    if (!!l) {
      try {
        l = JSON.parse(l);
      } catch (d) {
        console.log(d, l);
        return;
      }
      (l == null ? void 0 : l.lang) == ue.value && (o[m] = o[m] || await e.get("dict").get("#word").get(m).then());
    }
  });
  const s = g({});
  e.get("dict").get("#word").map().once((c, u) => {
    c.includes(" ") || (s[u] = c);
  });
  const r = p(() => {
    let c = Object.entries(s).map((u) => ({ text: u[1], hash: u[0] }));
    return new ee(c, {
      keys: ["text"],
      includeScore: !0
    });
  }), i = p(() => r.value.search(t.value));
  return { input: t, found: i, words: s, linked: o, word: n, addWord: a };
}
function fn(e) {
  const t = b(), n = O();
  return t.get("dict").get("#word").get(e).once((a, o) => {
    n.value = Te(a);
  }), { word: n };
}
function dn() {
  const e = b(), t = g({
    text: "",
    lang: ue,
    part: "noun"
  });
  async function n() {
    const { hash: i, hashed: c } = await H(t);
    e.get("dict").get("#def").get(i).put(c), G.def = i, t.text = "", t.part = null;
  }
  const a = g({});
  e.user(f.pub).get("dict").map().on(async (i, c) => {
    if (!i)
      return;
    let u = c.slice(45, 89), m = await e.get("dict").get("#def").get(u).then();
    if (!!m)
      try {
        if (m = JSON.parse(m), (m == null ? void 0 : m.lang) != ue.value)
          return;
        a[u] = a[u] || m;
      } catch (h) {
        console.log(h, m);
      }
  });
  const o = g({});
  e.get("dict").get("#def").map().once((i, c) => {
    o[c] = JSON.parse(i);
  });
  const s = p(() => {
    let i = [];
    for (let c in o)
      i.push({ hash: c, ...o[c] });
    return new ee(i, {
      keys: ["text"],
      includeScore: !0
    });
  }), r = p(() => s.value.search(t.text));
  return { def: t, addDef: n, defs: o, found: r, linked: a };
}
async function bt({ word: e, def: t } = {}) {
  var s;
  const n = b(), { user: a } = E();
  let o = await n.user(f.pub).get("dict").get(`${e}:${t}@${a.pub}`).then();
  n.user(f.pub).get("dict").get(`${e}:${t}@${a.pub}`).put(!o, null, { opt: { cert: (s = f.features) == null ? void 0 : s.dict } }), G.word = null, G.def = null;
}
function mn(e) {
  const t = b(), n = g({});
  return t.user(f.pub).get("dict").map().on((a, o) => {
    var m;
    if (o.indexOf(e) == -1)
      return;
    const { from: r, to: i, author: c } = ge(o);
    let u = r == e ? i : r;
    n[u] = n[u] || {}, a ? n[u][c] = a : ((m = n == null ? void 0 : n[u]) == null || delete m[c], Object.keys(n == null ? void 0 : n[u]).length == 0 && (n == null || delete n[u]));
  }), n;
}
function gn(e) {
  const t = b(), n = g({});
  return t.user(f.pub).get("dict").map().on((a, o) => {
    var c;
    const { from: s, to: r, author: i } = ge(o);
    i == e && (n[s] = n[s] || {}, a ? n[s][r] = a : ((c = n == null ? void 0 : n[s]) == null || delete c[r], Object.keys(n[s]).length == 0 && (n == null || delete n[s])));
  }), n;
}
function pn() {
  const e = b(), t = g({});
  return e.user(f.pub).get("dict").map().once(async (n, a) => {
    const { from: o, to: s, author: r } = ge(a);
    t[r] = t[r] || {}, t[r][o] = t[r][o] || {}, t[r][o][s] = n;
  }), t;
}
function hn() {
  const e = b(), t = g({});
  return e.user(f.pub).get("dict").map().once(async (n, a) => {
    let o = a.slice(45, 89), s = await e.get("dict").get("#def").get(o).then();
    if (!!s) {
      try {
        s = JSON.parse(s);
      } catch (r) {
        console.log(s, r);
      }
      !(s != null && s.lang) || (t[s == null ? void 0 : s.lang] = t[s == null ? void 0 : s.lang] || 0, t[s == null ? void 0 : s.lang]++);
    }
  }), t;
}
function ge(e) {
  return {
    from: e.slice(0, 44),
    to: e.slice(45, 89),
    author: e.slice(-87)
  };
}
function vn({ text: e, stress: t } = {}) {
  const n = "&#x301;";
  if (!e)
    return;
  let a = e.slice(0, t + 1) + n + e.slice(t + 1);
  return a[0].toUpperCase() + a.slice(1);
}
function Te(e) {
  if (!e)
    return "";
  let t = e.toLowerCase().matchAll(/\p{L}/gu, "");
  return Array.from(t).map((n) => n[0]).join("");
}
const wn = {
  noun: {
    en: "noun",
    ru: "\u0441\u0443\u0449",
    underline: "solid"
  },
  adj: {
    en: "adjective",
    ru: "\u043F\u0440\u0438\u043B",
    underline: "wavy"
  },
  verb: {
    en: "verb",
    ru: "\u0433\u043B\u0430\u0433",
    underline: "double"
  },
  adv: {
    en: "adverb",
    ru: "\u043D\u0430\u0440\u0435\u0447",
    underline: "dotted"
  }
}, bn = [
  {
    code: "aa",
    name: "Afar",
    native: "Afar"
  },
  {
    code: "ab",
    name: "Abkhazian",
    native: "\u0410\u04A7\u0441\u0443\u0430"
  },
  {
    code: "af",
    name: "Afrikaans",
    native: "Afrikaans"
  },
  {
    code: "ak",
    name: "Akan",
    native: "Akana"
  },
  {
    code: "am",
    name: "Amharic",
    native: "\u12A0\u121B\u122D\u129B"
  },
  {
    code: "an",
    name: "Aragonese",
    native: "Aragon\xE9s"
  },
  {
    code: "ar",
    name: "Arabic",
    native: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629",
    rtl: 1
  },
  {
    code: "as",
    name: "Assamese",
    native: "\u0985\u09B8\u09AE\u09C0\u09AF\u09BC\u09BE"
  },
  {
    code: "av",
    name: "Avar",
    native: "\u0410\u0432\u0430\u0440"
  },
  {
    code: "ay",
    name: "Aymara",
    native: "Aymar"
  },
  {
    code: "az",
    name: "Azerbaijani",
    native: "Az\u0259rbaycanca / \u0622\u0630\u0631\u0628\u0627\u064A\u062C\u0627\u0646"
  },
  {
    code: "ba",
    name: "Bashkir",
    native: "\u0411\u0430\u0448\u04A1\u043E\u0440\u0442"
  },
  {
    code: "be",
    name: "Belarusian",
    native: "\u0411\u0435\u043B\u0430\u0440\u0443\u0441\u043A\u0430\u044F"
  },
  {
    code: "bg",
    name: "Bulgarian",
    native: "\u0411\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438"
  },
  {
    code: "bh",
    name: "Bihari",
    native: "\u092D\u094B\u091C\u092A\u0941\u0930\u0940"
  },
  {
    code: "bi",
    name: "Bislama",
    native: "Bislama"
  },
  {
    code: "bm",
    name: "Bambara",
    native: "Bamanankan"
  },
  {
    code: "bn",
    name: "Bengali",
    native: "\u09AC\u09BE\u0982\u09B2\u09BE"
  },
  {
    code: "bo",
    name: "Tibetan",
    native: "\u0F56\u0F7C\u0F51\u0F0B\u0F61\u0F72\u0F42 / Bod skad"
  },
  {
    code: "br",
    name: "Breton",
    native: "Brezhoneg"
  },
  {
    code: "bs",
    name: "Bosnian",
    native: "Bosanski"
  },
  {
    code: "ca",
    name: "Catalan",
    native: "Catal\xE0"
  },
  {
    code: "ce",
    name: "Chechen",
    native: "\u041D\u043E\u0445\u0447\u0438\u0439\u043D"
  },
  {
    code: "ch",
    name: "Chamorro",
    native: "Chamoru"
  },
  {
    code: "co",
    name: "Corsican",
    native: "Corsu"
  },
  {
    code: "cr",
    name: "Cree",
    native: "Nehiyaw"
  },
  {
    code: "cs",
    name: "Czech",
    native: "\u010Cesky"
  },
  {
    code: "cu",
    name: "Old Church Slavonic / Old Bulgarian",
    native: "\u0441\u043B\u043E\u0432\u0463\u043D\u044C\u0441\u043A\u044A / slov\u011Bn\u012Dsk\u016D"
  },
  {
    code: "cv",
    name: "Chuvash",
    native: "\u0427\u0103\u0432\u0430\u0448"
  },
  {
    code: "cy",
    name: "Welsh",
    native: "Cymraeg"
  },
  {
    code: "da",
    name: "Danish",
    native: "Dansk"
  },
  {
    code: "de",
    name: "German",
    native: "Deutsch"
  },
  {
    code: "dv",
    name: "Divehi",
    native: "\u078B\u07A8\u0788\u07AC\u0780\u07A8\u0784\u07A6\u0790\u07B0",
    rtl: 1
  },
  {
    code: "dz",
    name: "Dzongkha",
    native: "\u0F47\u0F7C\u0F44\u0F0B\u0F41"
  },
  {
    code: "ee",
    name: "Ewe",
    native: "\u0190\u028B\u025B"
  },
  {
    code: "el",
    name: "Greek",
    native: "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC"
  },
  {
    code: "en",
    name: "English",
    native: "English"
  },
  {
    code: "eo",
    name: "Esperanto",
    native: "Esperanto"
  },
  {
    code: "es",
    name: "Spanish",
    native: "Espa\xF1ol"
  },
  {
    code: "et",
    name: "Estonian",
    native: "Eesti"
  },
  {
    code: "eu",
    name: "Basque",
    native: "Euskara"
  },
  {
    code: "fa",
    name: "Persian",
    native: "\u0641\u0627\u0631\u0633\u06CC",
    rtl: 1
  },
  {
    code: "ff",
    name: "Peul",
    native: "Fulfulde"
  },
  {
    code: "fi",
    name: "Finnish",
    native: "Suomi"
  },
  {
    code: "fj",
    name: "Fijian",
    native: "Na Vosa Vakaviti"
  },
  {
    code: "fo",
    name: "Faroese",
    native: "F\xF8royskt"
  },
  {
    code: "fr",
    name: "French",
    native: "Fran\xE7ais"
  },
  {
    code: "fy",
    name: "West Frisian",
    native: "Frysk"
  },
  {
    code: "ga",
    name: "Irish",
    native: "Gaeilge"
  },
  {
    code: "gd",
    name: "Scottish Gaelic",
    native: "G\xE0idhlig"
  },
  {
    code: "gl",
    name: "Galician",
    native: "Galego"
  },
  {
    code: "gn",
    name: "Guarani",
    native: "Ava\xF1e'\u1EBD"
  },
  {
    code: "gu",
    name: "Gujarati",
    native: "\u0A97\u0AC1\u0A9C\u0AB0\u0ABE\u0AA4\u0AC0"
  },
  {
    code: "gv",
    name: "Manx",
    native: "Gaelg"
  },
  {
    code: "ha",
    name: "Hausa",
    native: "\u0647\u064E\u0648\u064F\u0633\u064E",
    rtl: 1
  },
  {
    code: "he",
    name: "Hebrew",
    native: "\u05E2\u05D1\u05E8\u05D9\u05EA",
    rtl: 1
  },
  {
    code: "hi",
    name: "Hindi",
    native: "\u0939\u093F\u0928\u094D\u0926\u0940"
  },
  {
    code: "ho",
    name: "Hiri Motu",
    native: "Hiri Motu"
  },
  {
    code: "hr",
    name: "Croatian",
    native: "Hrvatski"
  },
  {
    code: "ht",
    name: "Haitian",
    native: "Kr\xE8yol ayisyen"
  },
  {
    code: "hu",
    name: "Hungarian",
    native: "Magyar"
  },
  {
    code: "hy",
    name: "Armenian",
    native: "\u0540\u0561\u0575\u0565\u0580\u0565\u0576"
  },
  {
    code: "hz",
    name: "Herero",
    native: "Otsiherero"
  },
  {
    code: "ia",
    name: "Interlingua",
    native: "Interlingua"
  },
  {
    code: "id",
    name: "Indonesian",
    native: "Bahasa Indonesia"
  },
  {
    code: "ie",
    name: "Interlingue",
    native: "Interlingue"
  },
  {
    code: "ig",
    name: "Igbo",
    native: "Igbo"
  },
  {
    code: "ii",
    name: "Sichuan Yi",
    native: "\uA187\uA259 / \u56DB\u5DDD\u5F5D\u8BED"
  },
  {
    code: "ik",
    name: "Inupiak",
    native: "I\xF1upiak"
  },
  {
    code: "io",
    name: "Ido",
    native: "Ido"
  },
  {
    code: "is",
    name: "Icelandic",
    native: "\xCDslenska"
  },
  {
    code: "it",
    name: "Italian",
    native: "Italiano"
  },
  {
    code: "iu",
    name: "Inuktitut",
    native: "\u1403\u14C4\u1483\u144E\u1450\u1466"
  },
  {
    code: "ja",
    name: "Japanese",
    native: "\u65E5\u672C\u8A9E"
  },
  {
    code: "jv",
    name: "Javanese",
    native: "Basa Jawa"
  },
  {
    code: "ka",
    name: "Georgian",
    native: "\u10E5\u10D0\u10E0\u10D7\u10E3\u10DA\u10D8"
  },
  {
    code: "kg",
    name: "Kongo",
    native: "KiKongo"
  },
  {
    code: "ki",
    name: "Kikuyu",
    native: "G\u0129k\u0169y\u0169"
  },
  {
    code: "kj",
    name: "Kuanyama",
    native: "Kuanyama"
  },
  {
    code: "kk",
    name: "Kazakh",
    native: "\u049A\u0430\u0437\u0430\u049B\u0448\u0430"
  },
  {
    code: "kl",
    name: "Greenlandic",
    native: "Kalaallisut"
  },
  {
    code: "km",
    name: "Cambodian",
    native: "\u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A"
  },
  {
    code: "kn",
    name: "Kannada",
    native: "\u0C95\u0CA8\u0CCD\u0CA8\u0CA1"
  },
  {
    code: "ko",
    name: "Korean",
    native: "\uD55C\uAD6D\uC5B4"
  },
  {
    code: "kr",
    name: "Kanuri",
    native: "Kanuri"
  },
  {
    code: "ks",
    name: "Kashmiri",
    native: "\u0915\u0936\u094D\u092E\u0940\u0930\u0940 / \u0643\u0634\u0645\u064A\u0631\u064A",
    rtl: 1
  },
  {
    code: "ku",
    name: "Kurdish",
    native: "Kurd\xEE / \u0643\u0648\u0631\u062F\u06CC",
    rtl: 1
  },
  {
    code: "kv",
    name: "Komi",
    native: "\u041A\u043E\u043C\u0438"
  },
  {
    code: "kw",
    name: "Cornish",
    native: "Kernewek"
  },
  {
    code: "ky",
    name: "Kirghiz",
    native: "K\u0131rg\u0131zca / \u041A\u044B\u0440\u0433\u044B\u0437\u0447\u0430"
  },
  {
    code: "la",
    name: "Latin",
    native: "Latina"
  },
  {
    code: "lb",
    name: "Luxembourgish",
    native: "L\xEBtzebuergesch"
  },
  {
    code: "lg",
    name: "Ganda",
    native: "Luganda"
  },
  {
    code: "li",
    name: "Limburgian",
    native: "Limburgs"
  },
  {
    code: "ln",
    name: "Lingala",
    native: "Ling\xE1la"
  },
  {
    code: "lo",
    name: "Laotian",
    native: "\u0EA5\u0EB2\u0EA7 / Pha xa lao"
  },
  {
    code: "lt",
    name: "Lithuanian",
    native: "Lietuvi\u0173"
  },
  {
    code: "lu",
    name: "Luba-Katanga",
    native: "Tshiluba"
  },
  {
    code: "lv",
    name: "Latvian",
    native: "Latvie\u0161u"
  },
  {
    code: "mg",
    name: "Malagasy",
    native: "Malagasy"
  },
  {
    code: "mh",
    name: "Marshallese",
    native: "Kajin Majel / Ebon"
  },
  {
    code: "mi",
    name: "Maori",
    native: "M\u0101ori"
  },
  {
    code: "mk",
    name: "Macedonian",
    native: "\u041C\u0430\u043A\u0435\u0434\u043E\u043D\u0441\u043A\u0438"
  },
  {
    code: "ml",
    name: "Malayalam",
    native: "\u0D2E\u0D32\u0D2F\u0D3E\u0D33\u0D02"
  },
  {
    code: "mn",
    name: "Mongolian",
    native: "\u041C\u043E\u043D\u0433\u043E\u043B"
  },
  {
    code: "mo",
    name: "Moldovan",
    native: "Moldoveneasc\u0103"
  },
  {
    code: "mr",
    name: "Marathi",
    native: "\u092E\u0930\u093E\u0920\u0940"
  },
  {
    code: "ms",
    name: "Malay",
    native: "Bahasa Melayu"
  },
  {
    code: "mt",
    name: "Maltese",
    native: "bil-Malti"
  },
  {
    code: "my",
    name: "Burmese",
    native: "\u1019\u103C\u1014\u103A\u1019\u102C\u1005\u102C"
  },
  {
    code: "na",
    name: "Nauruan",
    native: "Dorerin Naoero"
  },
  {
    code: "nb",
    name: "Norwegian Bokm\xE5l",
    native: "Norsk bokm\xE5l"
  },
  {
    code: "nd",
    name: "North Ndebele",
    native: "Sindebele"
  },
  {
    code: "ne",
    name: "Nepali",
    native: "\u0928\u0947\u092A\u093E\u0932\u0940"
  },
  {
    code: "ng",
    name: "Ndonga",
    native: "Oshiwambo"
  },
  {
    code: "nl",
    name: "Dutch",
    native: "Nederlands"
  },
  {
    code: "nn",
    name: "Norwegian Nynorsk",
    native: "Norsk nynorsk"
  },
  {
    code: "no",
    name: "Norwegian",
    native: "Norsk"
  },
  {
    code: "nr",
    name: "South Ndebele",
    native: "isiNdebele"
  },
  {
    code: "nv",
    name: "Navajo",
    native: "Din\xE9 bizaad"
  },
  {
    code: "ny",
    name: "Chichewa",
    native: "Chi-Chewa"
  },
  {
    code: "oc",
    name: "Occitan",
    native: "Occitan"
  },
  {
    code: "oj",
    name: "Ojibwa",
    native: "\u140A\u14C2\u1511\u14C8\u142F\u14A7\u140E\u14D0 / Anishinaabemowin"
  },
  {
    code: "om",
    name: "Oromo",
    native: "Oromoo"
  },
  {
    code: "or",
    name: "Oriya",
    native: "\u0B13\u0B21\u0B3C\u0B3F\u0B06"
  },
  {
    code: "os",
    name: "Ossetian / Ossetic",
    native: "\u0418\u0440\u043E\u043D\u0430\u0443"
  },
  {
    code: "pa",
    name: "Panjabi / Punjabi",
    native: "\u0A2A\u0A70\u0A1C\u0A3E\u0A2C\u0A40 / \u092A\u0902\u091C\u093E\u092C\u0940 / \u067E\u0646\u062C\u0627\u0628\u064A"
  },
  {
    code: "pi",
    name: "Pali",
    native: "P\u0101li / \u092A\u093E\u0934\u093F"
  },
  {
    code: "pl",
    name: "Polish",
    native: "Polski"
  },
  {
    code: "ps",
    name: "Pashto",
    native: "\u067E\u069A\u062A\u0648",
    rtl: 1
  },
  {
    code: "pt",
    name: "Portuguese",
    native: "Portugu\xEAs"
  },
  {
    code: "qu",
    name: "Quechua",
    native: "Runa Simi"
  },
  {
    code: "rm",
    name: "Raeto Romance",
    native: "Rumantsch"
  },
  {
    code: "rn",
    name: "Kirundi",
    native: "Kirundi"
  },
  {
    code: "ro",
    name: "Romanian",
    native: "Rom\xE2n\u0103"
  },
  {
    code: "ru",
    name: "Russian",
    native: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439"
  },
  {
    code: "rw",
    name: "Rwandi",
    native: "Kinyarwandi"
  },
  {
    code: "sa",
    name: "Sanskrit",
    native: "\u0938\u0902\u0938\u094D\u0915\u0943\u0924\u092E\u094D"
  },
  {
    code: "sc",
    name: "Sardinian",
    native: "Sardu"
  },
  {
    code: "sd",
    name: "Sindhi",
    native: "\u0938\u093F\u0928\u0927\u093F"
  },
  {
    code: "se",
    name: "Northern Sami",
    native: "S\xE1megiella"
  },
  {
    code: "sg",
    name: "Sango",
    native: "S\xE4ng\xF6"
  },
  {
    code: "sh",
    name: "Serbo-Croatian",
    native: "Srpskohrvatski / \u0421\u0440\u043F\u0441\u043A\u043E\u0445\u0440\u0432\u0430\u0442\u0441\u043A\u0438"
  },
  {
    code: "si",
    name: "Sinhalese",
    native: "\u0DC3\u0DD2\u0D82\u0DC4\u0DBD"
  },
  {
    code: "sk",
    name: "Slovak",
    native: "Sloven\u010Dina"
  },
  {
    code: "sl",
    name: "Slovenian",
    native: "Sloven\u0161\u010Dina"
  },
  {
    code: "sm",
    name: "Samoan",
    native: "Gagana Samoa"
  },
  {
    code: "sn",
    name: "Shona",
    native: "chiShona"
  },
  {
    code: "so",
    name: "Somalia",
    native: "Soomaaliga"
  },
  {
    code: "sq",
    name: "Albanian",
    native: "Shqip"
  },
  {
    code: "sr",
    name: "Serbian",
    native: "\u0421\u0440\u043F\u0441\u043A\u0438"
  },
  {
    code: "ss",
    name: "Swati",
    native: "SiSwati"
  },
  {
    code: "st",
    name: "Southern Sotho",
    native: "Sesotho"
  },
  {
    code: "su",
    name: "Sundanese",
    native: "Basa Sunda"
  },
  {
    code: "sv",
    name: "Swedish",
    native: "Svenska"
  },
  {
    code: "sw",
    name: "Swahili",
    native: "Kiswahili"
  },
  {
    code: "ta",
    name: "Tamil",
    native: "\u0BA4\u0BAE\u0BBF\u0BB4\u0BCD"
  },
  {
    code: "te",
    name: "Telugu",
    native: "\u0C24\u0C46\u0C32\u0C41\u0C17\u0C41"
  },
  {
    code: "tg",
    name: "Tajik",
    native: "\u0422\u043E\u04B7\u0438\u043A\u04E3"
  },
  {
    code: "th",
    name: "Thai",
    native: "\u0E44\u0E17\u0E22 / Phasa Thai"
  },
  {
    code: "ti",
    name: "Tigrinya",
    native: "\u1275\u130D\u122D\u129B"
  },
  {
    code: "tk",
    name: "Turkmen",
    native: "\u0422\u0443\u0440\u043A\u043C\u0435\u043D / \u062A\u0631\u0643\u0645\u0646"
  },
  {
    code: "tl",
    name: "Tagalog / Filipino",
    native: "Tagalog"
  },
  {
    code: "tn",
    name: "Tswana",
    native: "Setswana"
  },
  {
    code: "to",
    name: "Tonga",
    native: "Lea Faka-Tonga"
  },
  {
    code: "tr",
    name: "Turkish",
    native: "T\xFCrk\xE7e"
  },
  {
    code: "ts",
    name: "Tsonga",
    native: "Xitsonga"
  },
  {
    code: "tt",
    name: "Tatar",
    native: "Tatar\xE7a"
  },
  {
    code: "tw",
    name: "Twi",
    native: "Twi"
  },
  {
    code: "ty",
    name: "Tahitian",
    native: "Reo M\u0101`ohi"
  },
  {
    code: "ug",
    name: "Uyghur",
    native: "Uy\u01A3urq\u0259 / \u0626\u06C7\u064A\u063A\u06C7\u0631\u0686\u06D5"
  },
  {
    code: "uk",
    name: "Ukrainian",
    native: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"
  },
  {
    code: "ur",
    name: "Urdu",
    native: "\u0627\u0631\u062F\u0648",
    rtl: 1
  },
  {
    code: "uz",
    name: "Uzbek",
    native: "\u040E\u0437\u0431\u0435\u043A"
  },
  {
    code: "ve",
    name: "Venda",
    native: "Tshiven\u1E13a"
  },
  {
    code: "vi",
    name: "Vietnamese",
    native: "Ti\u1EBFng Vi\u1EC7t"
  },
  {
    code: "vo",
    name: "Volap\xFCk",
    native: "Volap\xFCk"
  },
  {
    code: "wa",
    name: "Walloon",
    native: "Walon"
  },
  {
    code: "wo",
    name: "Wolof",
    native: "Wollof"
  },
  {
    code: "xh",
    name: "Xhosa",
    native: "isiXhosa"
  },
  {
    code: "yi",
    name: "Yiddish",
    native: "\u05D9\u05D9\u05B4\u05D3\u05D9\u05E9",
    rtl: 1
  },
  {
    code: "yo",
    name: "Yoruba",
    native: "Yor\xF9b\xE1"
  },
  {
    code: "za",
    name: "Zhuang",
    native: "Cuengh / T\xF4\xF4 / \u58EE\u8BED"
  },
  {
    code: "zh",
    name: "Chinese",
    native: "\u4E2D\u6587"
  },
  {
    code: "zu",
    name: "Zulu",
    native: "isiZulu"
  }
];
function yt(e, t, n, a = !0) {
  const o = document.createElement("a");
  o.download = n, a ? (o.href = URL.createObjectURL(new Blob([e], { type: t })), setTimeout(function() {
    URL.revokeObjectURL(o.href);
  }, 1500)) : o.href = `data:${t};,${e}`, o.dataset.downloadurl = [t, o.download, o.href].join(":"), o.style.display = "none", document.body.appendChild(o), o.click(), document.body.removeChild(o);
}
function yn(e, t = (n) => console.log(n)) {
  let n = e.target.files[0];
  const a = 2e7;
  if (n.size > a) {
    console.error("File is bigger than " + $e(a)) + "";
    return;
  }
  let o = new FileReader();
  o.readAsText(n), o.onload = () => {
    t(o.result);
  };
}
function Sn({
  preserveRatio: e = !1,
  picSize: t = 100,
  maxSize: n = 1024e4
} = {}) {
  const a = g({
    errors: [],
    status: null,
    output: {}
  });
  function o(d) {
    const v = d.target.files;
    i(), v.length && (a.status = "loading", [...v].map((P) => s(P)));
  }
  function s(d) {
    return r(d).then((v) => {
      a.output = {
        name: h(d.name),
        content: v,
        size: $e(Math.round(v.length * 3 / 4))
      }, a.status = "success";
    }), null;
  }
  function r(d) {
    return new Promise((v, P) => {
      const x = new FileReader(), M = new FileReader(), L = d.slice(0, 4);
      x.readAsArrayBuffer(L), x.onloadend = (y) => {
        let S = u(m(y.target.result));
        if (c(d.size) > c(n) && a.errors.push({
          message: "File size is too large!"
        }), S === !1 && a.errors.push({
          message: "File type is not supported!"
        }), a.errors.length > 0) {
          l(a.errors), i();
          return;
        } else
          M.readAsDataURL(d);
      }, M.onloadend = () => {
        const y = new Image();
        y.src = M.result, y.onload = () => {
          const S = e ? y.naturalWidth / y.naturalHeight : 1, j = document.createElement("canvas");
          j.width = t, j.height = t / S, j.getContext("2d").drawImage(y, 0, 0, j.width, j.height), v(j.toDataURL());
        };
      }, x.onerror = (y) => P(y), M.onerror = (y) => P(y);
    });
  }
  function i() {
    a.status = "", a.errors = [], a.output = {};
  }
  function c(d) {
    return d * Math.pow(10, -6);
  }
  function u(d) {
    return [
      "89504E47",
      "47494638",
      "FFD8FFDB",
      "FFD8FFE0",
      "FFD8FFE1",
      "FFD8FFE2",
      "FFD8FFE3",
      "FFD8FFE8",
      "FFD8FFED",
      "3C3F786D",
      "3C737667"
    ].includes(d);
  }
  function m(d) {
    const v = new Uint8Array(d);
    let P = [];
    return v.forEach((x) => {
      P.push(x.toString(16));
    }), P.join("").toUpperCase();
  }
  function h(d) {
    return d.replace(/\.[^/.]+$/, "").toLowerCase();
  }
  function l(d) {
    d.length === 2 ? console.error("File upload failed due to size and type!") : console.error(d[0].message + d[0].type);
  }
  return {
    state: a,
    handleChange: o
  };
}
const St = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
function $e(e) {
  let t = 0, n = parseInt(e, 10) || 0;
  for (; n >= 1024 && ++t; )
    n = n / 1024;
  return n.toFixed(n < 10 && t > 0 ? 1 : 0) + " " + St[t];
}
function kn(e) {
  var t = null;
  if (typeof e != "string")
    return t;
  var n = e.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);
  return n && n.length && (t = n[1]), t;
}
function kt(e) {
  var t;
  return (t = e.match(/[^:]\w+\/[\w-+\d.]+(?=;|,)/)) == null ? void 0 : t[0];
}
function jt(e) {
  return e.substring(e.indexOf("/") + 1, e.indexOf(";base64"));
}
var ve = {
  JVBERi0: "application/pdf",
  R0lGODdh: "image/gif",
  R0lGODlh: "image/gif",
  iVBORw0KGgo: "image/png",
  "/9j/": "image/jpg"
};
function we(e) {
  for (var t in ve)
    if (e.indexOf(t) === 0)
      return ve[t];
}
function At({ frontmatter: e = null, text: t = "" } = md) {
  let n = "";
  if (typeof e == "object")
    return n = `---
${Ee.stringify(e)}---
 `, n + t;
}
function Ot(e) {
  const n = /^(?:\-\-\-)(.*?)(?:\-\-\-|\.\.\.)(?:\n*\s*)(.*)/s.exec(e.trim());
  let a, o;
  if (n) {
    a = n[1], o = n == null ? void 0 : n[2];
    try {
      a = Ee.parse(a);
    } catch {
      a = {};
    }
    return { frontmatter: a, content: o };
  } else
    return { frontmatter: {}, content: e.trim() };
}
function jn() {
  const e = new qe({
    linkify: !0,
    typographer: !0
  });
  return e.use(We, {
    externalTarget: "_blank"
  }), e;
}
function Pt({ hash: e = "", loadMedia: t = !0 } = {}) {
  const n = b(), a = g({});
  n.get("posts").get("#index").get(e).on(async (r, i) => {
    try {
      Object.assign(a, JSON.parse(r));
    } catch {
      a.raw = r;
    }
    t && ["icon", "cover", "text"].forEach((c) => {
      a[c] && n.get("posts").get(`#${c}`).get(a[c]).on((u) => {
        a[c] = u;
      });
    });
  });
  const o = O(!1);
  async function s() {
    o.value = !0, await Dt(a), o.value = !1;
  }
  return { post: a, download: s, downloading: o };
}
async function Ft(e, t) {
  var s;
  const { user: n } = E();
  t.icon = await ae("icon", t.icon), t.cover = await ae("cover", t.cover), t.text = await ae("text", t.text);
  const { hashed: a, hash: o } = await H(t);
  console.log(o, t, e), k.get("posts").get("#index").get(`${o}`).put(a), k.user(f.pub).get("posts").get(`${e}:${o}@${n.pub}`).put(!0, null, { opt: { cert: (s = f.features) == null ? void 0 : s.posts } });
}
async function Dt(e) {
  let { title: t } = e;
  const { zipPost: n, addFile: a, downloadZip: o } = Le();
  if (t && !e.raw)
    await n({ ...e });
  else {
    t = "file";
    const s = await q(e.raw);
    await a({
      title: ht(s),
      file: e.raw
    });
  }
  return await o({ title: t }), !0;
}
async function be(e, t) {
  return e && t && typeof t == "string" && t.length == 44 && t.slice(0, 5) != "data:" ? await k.get("posts").get(`#${e}`).get(t).then() : t;
}
async function ae(e, t) {
  if (e && t) {
    const n = await q(t);
    return k.get("posts").get(`#${e}`).get(`${n}`).put(t), n;
  } else
    return t;
}
async function An(e) {
  let t;
  try {
    t = JSON.parse(e);
  } catch {
    t = { base64: e };
  }
  return t;
}
function On({ tag: e, hash: t } = {}) {
  const n = O(0), a = p(() => V(Date.now() - n.value || 1e3));
  k.get("posts").get("#index").get(t).on(function(s, r, i) {
    n.value = i.put[">"];
  });
  async function o() {
    let s = await k.get("posts").get("#index").get(t).then();
    k.get("posts").get("#index").get(t).put(s);
  }
  return { timestamp: n, msTime: a, refresh: o };
}
function Pn(e) {
  if (!e)
    return;
  const t = b(), n = g({}), a = g({});
  t.user(f.pub).get("posts").map().on(function(u, m) {
    let h = m.indexOf(e);
    if (h == -1)
      return;
    let l = m.slice(-87), d = m.slice(0, 44), v = m.slice(45, 89);
    h == 0 ? (n[v] = n[v] || {}, n[v][l] = u) : (a[d] = a[d] || {}, a[d][l] = u);
  });
  const o = p(() => {
    let u = 0;
    for (let m in n) {
      e:
        for (let h in n[m])
          if (n[m][h]) {
            u++;
            break e;
          }
    }
    return u;
  }), s = p(() => {
    let u = 0;
    for (let m in a) {
      e:
        for (let h in a[m])
          if (a[m][h]) {
            u++;
            break e;
          }
    }
    return u;
  }), r = O(!1);
  async function i() {
    r.value = !0, r.value = !await Et(e, n);
  }
  function c(u) {
    xt(e, u);
  }
  return {
    posts: n,
    backlinks: a,
    countPosts: o,
    countBacklinks: s,
    downloadPosts: i,
    downloading: r,
    uploadPosts: c
  };
}
async function Et(e, t) {
  if (!t)
    return;
  const { zip: n, zipPost: a, downloadZip: o } = Le(), s = {};
  for (let r in t)
    s[r] = Pt({ tag: e, hash: r }).post, await a({ ...s[r] });
  return await o({ title: `#${e}` }), !0;
}
function xt(e, t) {
  [...t].forEach(async (n) => {
    const a = await xe.loadAsync(n);
    a.comment && console.info("Zip file comment: " + a.comment), a.forEach(async (o, s) => {
      var r;
      if (o.endsWith("index.md")) {
        let i = o.slice(0, -9), c = await s.async("string"), { frontmatter: u, content: m } = Ot(c);
        if (u = u || {}, u.title = (u == null ? void 0 : u.title) || i, u.icon) {
          const l = await a.file(`${i}/${u.icon}`).async("base64"), d = we(l);
          u.icon = `data:${d};base64,${l}`;
        }
        if (u.cover) {
          const l = await ((r = a == null ? void 0 : a.file(`${i}/${u.cover}`)) == null ? void 0 : r.async("base64")), d = we(l);
          u.cover = `data:${d};base64,${l}`;
        }
        let h = { ...u, content: m };
        Ft(e, h);
      }
    });
  });
}
function Fn() {
  const e = b(), t = O(), n = p(() => re(t.value)), a = g({
    list: {},
    all: p(() => {
      const s = [];
      for (let r in a.list)
        s.push({
          hash: r,
          tag: a.list[r]
        });
      return s.sort((r, i) => r && i && r.tag.toLowerCase() < i.tag.toLowerCase() ? -1 : 1);
    }),
    count: p(() => a.all.length),
    fuse: p(() => new ee(a.all, {
      includeScore: !0,
      keys: ["tag"]
    })),
    results: p(() => t.value ? a.fuse.search(n.value) : []),
    minScore: p(() => {
      let s = 100;
      return a.results.forEach((r) => {
        r.score < s && (s = r.score);
      }), s;
    })
  });
  e.get("#tags").map().on((s, r) => {
    if (!!s)
      try {
        data = JSON.parse(s);
      } catch {
        a.list[r] = s;
      }
  });
  async function o(s = n.value) {
    if (!s)
      return;
    let r = re(s);
    const i = await q(r);
    e.get("#tags").get(`${i}`).put(r);
  }
  return { search: t, slug: n, tags: a, addTag: o };
}
async function Dn(e, t, n = currentRoom.pub, a) {
  var r;
  if (a || (a = await gun.get(`~${n}`).get("features").get(e).then()), !a && n == rootRoom.pub && (a = (r = rootRoom.features) == null ? void 0 : r[`#${e}`]), !a && n != user.pub) {
    console.log("No certificate found");
    return;
  }
  const { hashed: o, hash: s } = await hashObj(t);
  gun.get(`~${n}`).get(`#${e}`).get(`${s}@${user.pub}`).put(o, null, { opt: { cert: a } });
}
function En(e, t, n = currentRoom.pub) {
  const a = g({});
  return gun.get(`~${n}`).get(`#${e}`).map().once(function(o, s) {
    s.includes(t) && (a.hash = t, a.tag = e, a.data = safeJSONParse(o), a.authors = a.authors || {}, a.authors[s.slice(-87)] = !0);
  }), { record: a };
}
const Ct = ["rooms"];
function xn({ tag: e, hash: t, back: n } = {}) {
  const { user: a } = E(), o = O("\u{1F44D}"), r = b().user(f.pub);
  K(() => {
    Ct.includes(e) ? r.get(e).get(`${t}@${a.pub}`).on((c) => {
      c && c !== !0 && (o.value = c);
    }) : r.get("posts").get(`${e}:${t}@${a.pub}`).on((c) => {
      c && c !== !0 && (o.value = c);
    });
  });
  function i(c) {
    Rt({ tag: e, hash: t, back: n, reaction: Z(c || o.value) });
  }
  return { reaction: o, react: i };
}
async function Rt({ tag: e, hash: t, back: n, reaction: a = !0 } = {}) {
  var r, i;
  const { user: o } = E(), s = b();
  if (console.log(e, t, a), e == "rooms") {
    let c = s.user(f.pub).get(e).get(`${t}@${o.pub}`), u = await c.then();
    c.put(u ? null : a, null, {
      opt: { cert: (r = f.features) == null ? void 0 : r[e] }
    });
  } else {
    let c = s.user(f.pub).get("posts");
    n ? c = c.get(`${t}:${e}@${o.pub}`) : c = c.get(`${e}:${t}@${o.pub}`);
    let u = await c.then();
    c.put(u ? null : a, null, {
      opt: { cert: (i = f.features) == null ? void 0 : i.posts }
    });
  }
}
function Cn(e) {
  const t = {};
  for (let n in e) {
    let a = e[n];
    a && (t[a] = t[a] || [], t[a].push(n));
  }
  return t;
}
function Rn(e) {
  let t = 0;
  for (let n in e)
    e[n] && e[n] != "\u{1F5D1}" ? t++ : e[n] == "\u{1F5D1}" && t--;
  return t;
}
function Nn(e) {
  const t = b(), n = g({});
  return t.user(f.pub).get("posts").map().on((a, o) => {
    var c;
    let s = o.slice(90), r = o.substring(0, 44), i = o.substring(45, 89);
    s == e && (a ? (n[a] = n[a] || {}, n[a][i] = r) : (c = n == null ? void 0 : n[a]) == null || delete c[i]);
  }), n;
}
function Le() {
  const e = new xe();
  async function t({ title: s, file: r, folder: i = "." } = {}) {
    const c = kt(r), u = jt(r), m = await fetch(r).then((l) => l.blob()), h = `${s}.${u}`;
    return e.file(`${i}/${h}`, m, c), h;
  }
  function n({ md: s, title: r } = {}) {
    e.file(`${r}/index.md`, At(s), "text/markdown");
  }
  async function a(s = {}) {
    let { icon: r, cover: i, text: c, title: u, statement: m } = s;
    s == null || delete s.text, u || (u = m ? m.split(0, 12) : gt());
    const h = ["cover", "icon"];
    for (let l of h) {
      let d = await be(l, s[l]);
      if (d) {
        const v = await t({
          title: l,
          file: d,
          folder: u
        });
        s[l] = v;
      }
    }
    c = await be("text", c), n({
      title: u,
      md: {
        frontmatter: s,
        text: c
      }
    });
  }
  async function o({ title: s = "", addDate: r = !0 } = {}) {
    let i = new Date();
    const c = i.getTimezoneOffset();
    i = new Date(i.getTime() - c * 60 * 1e3);
    const u = i.toISOString().split("T")[0], m = await e.generateAsync({
      type: "blob",
      comment: `Exported from ${s} at ${location} on ${u}`,
      compression: "DEFLATE",
      compressionOptions: {
        level: 9
      }
    }), h = `${s}-${u}.zip`;
    return yt(m, "application/zip", h), !0;
  }
  return { zip: e, zipPost: a, addMd: n, addFile: t, downloadZip: o };
}
const z = {
  pub: "OUlhoY2Eq8QkZE_iWN3l6J2vvbkX33vowcFdqFoCoEQ.a-B1ImQK4aoiEpdW-38MAPc8oi16DHY57bDJ4dEZpX0",
  hosts: {
    "jFjrmOEaRy-GAJlOCdG4SGoaLm_4AGMPP1sfmzYPwwo.mp2H7IQuTWlFSahN6ZnXN9Za0pD3thiIYUyGCaMel-M": {
      enc: 'SEA{"ct":"pvG4zoG5OIM7gyT5Jsh+PuFLAf200NKIpa7X/OxNm+lneWOD6avNS9iEXx9GgTM18iSdE3CBrKydusfLcqiXFFfMZivXsUTnf2Mbe702drcEcr7x9JTRhEqo3ptmunn+a+NUtfOPeExNFSCKoqfdMzSIR/nZFdW/qGcV5DDZOjuYdbV9Sh1rbvDPThJNJERz3WioLv3SodSXo4J5pq+2NujebALBabIZJYw2RXOxPjRMSnaYjT4lAZTA3FCy4mmP9fReVNw46Zjs6GYoZzIer0E4q5thRKyzf9IDFRJLfwpjejYY/fQWW4YFffN+1QBOjDAysCws+nCBSmFeKuAr2vFTvzdUI7gcoeKOc16BRnTC5NF8qQnXMS4XoilvueQ4as2mffG6iEwUiU5TicZO77+fARiUfG5WIgjEdkE=","iv":"a6bjav88otAnmjv6iB/r","s":"W+WzjXaZ4EAu"}',
      profile: 'SEA{"m":{"c":"jFjrmOEaRy-GAJlOCdG4SGoaLm_4AGMPP1sfmzYPwwo.mp2H7IQuTWlFSahN6ZnXN9Za0pD3thiIYUyGCaMel-M","w":{"*":"profile"}},"s":"YIGcs8VXeD4eB21MFPM/wnpJnMkmuxX6wjA/1GD170ATGBob9Ps3WCGtRUyhT2AmCIOe7oXpinZdtd3SCSZh/A=="}',
      features: 'SEA{"m":{"c":"jFjrmOEaRy-GAJlOCdG4SGoaLm_4AGMPP1sfmzYPwwo.mp2H7IQuTWlFSahN6ZnXN9Za0pD3thiIYUyGCaMel-M","w":{"*":"features"}},"s":"vhnmYfslzJm6qWTUBp4meKtlzAkIxyayRJa1KNeCFJT27T7UX4X//+t5giRX6Z/rIz3aWEPZX9UK3LLhc/J91g=="}',
      hosts: 'SEA{"m":{"c":"jFjrmOEaRy-GAJlOCdG4SGoaLm_4AGMPP1sfmzYPwwo.mp2H7IQuTWlFSahN6ZnXN9Za0pD3thiIYUyGCaMel-M","w":{"*":"hosts"}},"s":"2x5ZTh1NYv+eCtRKwlKItC1j9ZV5YhhiWJiaNq8Y+8YBF93aaagY6CT0YzLYFvG/fKTBWN4lldaeI+cFV88AbA=="}'
    }
  },
  features: {
    rooms: 'SEA{"m":{"c":"*","w":{"*":"rooms","+":"*"}},"s":"iJjnFrGvM092KSqH9kUYJm0pBgd6HSg8b9kl9QPjdQYNDAZQe2btfDP6rXIVNPcYFIjEYqBCibuQhcAjODUQFg=="}',
    space: 'SEA{"m":{"c":"*","w":{"*":"space","+":"*"}},"s":"eTZNu+acczsk8ew+UKCseanlVJ4prm+N1cvLXe2T6Bccfk6a7gR5EjvyBat4iCv97HpcoYtfcQO1ImhgVzP/bQ=="}',
    posts: 'SEA{"m":{"c":"*","w":{"*":"posts","+":"*"}},"s":"g94jrn4qvausK0sf5ej+MDIqJr9QOyG6U/fwAfmjxWcxCSiVzra8ZhvwOA3PVsqdcRYMK9YFMZ2cNJhT84ew/w=="}',
    chat: 'SEA{"m":{"c":"*","w":{"*":"chat","+":"*"}},"s":"Nclaw2A61Dzx6wLNeGSFr+od7bdj0jYftz/8XDRTZTUUp42xnD1Hyp2GbmFGKrY8be+60XOxYB0Tcp+ewkPimA=="}',
    dict: 'SEA{"m":{"c":"*","w":{"*":"dict","+":"*"}},"s":"cmnSSjKGrbxEoJ3JyGfgeesLJ3fELC6aIy3nO4MmSLok4ZNxpx2HayQaQmi+8gfgwX86poYUm1WR2bDdUAgzmw=="}',
    projects: 'SEA{"m":{"c":"*","w":{"*":"projects","+":"*"}},"s":"Zx/1sVapPoqx0pVMrMElSWVwBbD1AH0uPP11/tte2qHUmww458tqwRNfC3XMhZVl/fR589I3VWoUXSfNGDPj+g=="}',
    gifts: 'SEA{"m":{"c":"*","w":{"*":"gifts","+":"*"}},"s":"YpWMF8FpZToI4KCc4ZxR4zBChQMF+C6HQF1maNpDyA6g9t/DY9tejELG+mc2CqcV9mDU/km2q7EeaZGnxQsREA=="}'
  }
}, f = g({
  pub: z.pub,
  isRoot: p(() => f.pub == z.pub),
  hosts: {},
  features: {},
  profile: {}
});
K(() => {
  const e = b();
  f.pub == z.pub ? (f.hosts = z.hosts, f.features = z.features) : (f.features = {}, f.hosts = {}, e.user(f.pub).get("hosts").map().once((t, n) => {
    f.hosts[n] = t;
  }), e.user(f.pub).get("features").map().once((t, n) => {
    f.features[n] = t;
  }));
});
function Mn(e = f.pub) {
  const t = g({
    pub: e,
    isRoot: e != z.pub,
    hosts: {},
    features: {},
    profile: {}
  }), n = b();
  return n.user(e).get("profile").map().on((a, o) => {
    t.profile[o] = a;
  }), n.user(e).get("hosts").map().once((a, o) => {
    t.hosts[o] = a;
  }), n.user(e).get("features").map().once((a, o) => {
    t.features[o] = a;
  }), {
    room: t,
    submitRoom: Mt,
    enterRoom: Tt,
    createRoom: pe,
    leaveRoom: $t,
    updateRoomProfile: le
  };
}
function Tn(e = f.pub) {
  const t = O();
  k.user(e).get("profile").get("logo").on((o) => {
    if (!o) {
      t.value = null;
      return;
    }
    k.get("#logos").get(o).once((s) => {
      t.value = s;
    });
  });
  async function n(o) {
    if (o) {
      const s = await q(o);
      k.get("#logos").get(s).put(o), le("logo", s);
    } else
      a();
  }
  function a() {
    le("logo", null);
  }
  return {
    logo: t,
    uploadLogo: n,
    removeLogo: a
  };
}
function $n() {
  return { rooms: p(() => Nt("rooms", f.pub)), createRoom: pe };
}
function Nt(e, t = f.pub) {
  const n = b(), a = g({});
  return n.user(t).get(`${e}`).map().on(function(o, s) {
    let r = s.substring(0, 87);
    a[r] = a[r] || {}, a[r][s.substring(88)] = o;
  }), a;
}
function le(e, t) {
  var s, r;
  const n = b(), { user: a } = E();
  let o = (r = (s = f.hosts) == null ? void 0 : s[a.pub]) == null ? void 0 : r.profile;
  n.user(f.pub).get("profile").get(e).put(t, null, { opt: { cert: o } });
}
async function pe({ pair: e, name: t } = {}) {
  var u;
  const { user: n } = E();
  if (!e)
    return;
  const a = await he({
    pair: e,
    list: [
      { tag: "profile", users: [n.pub] },
      { tag: "features", users: [n.pub] },
      { tag: "hosts", users: [n.pub] }
    ]
  }), o = await he({
    pair: e,
    list: [
      { tag: "rooms", personal: !0 },
      { tag: "space", personal: !0 },
      { tag: "posts", personal: !0 },
      { tag: "chat", personal: !0 },
      { tag: "dict", personal: !0 },
      { tag: "projects", personal: !0 },
      { tag: "gifts", personal: !0 }
    ]
  }), s = await F.encrypt(e, n.pair()), r = await F.decrypt(s, n.pair());
  console.log("COPY THIS ROOM INFO TO USE IT AS A ROOT", {
    pub: r.pub,
    hosts: { [n.pub]: { enc: s, ...a } },
    features: o
  }, "STORE THIS KEY PAIR IN A SAFE PLACE", r);
  const i = b();
  i.user().get("safe").get("rooms").get(r.pub).put(s), i.user(f.pub).get("rooms").get(`${r.pub}@${n.pub}`).put(!0, null, { opt: { cert: (u = f == null ? void 0 : f.features) == null ? void 0 : u.rooms } });
  const c = i.user(r.pub);
  c.get("hosts").get(n.pub).put({
    enc: s,
    ...a
  }, null, { opt: { cert: a.hosts } }), c.get("features").put(o, null, { opt: { cert: a.features } }), t && c.get("profile").put({ name: t }, null, { opt: { cert: a.profile } });
}
async function Ln(e) {
  const t = await F.decrypt(e, w.pair());
  pe({
    pair: t
  });
}
async function Mt(e) {
  var a;
  const t = b(), n = await t.user(f.pub).get("rooms").get(`${e}@${w.pub}`).then();
  t.user(f.pub).get("rooms").get(`${e}@${w.pub}`).put(!n, null, { opt: { cert: (a = f.features) == null ? void 0 : a.rooms } });
}
function Gn() {
  var t;
  b().user(f.pub).get("space").get(w.pub).put(JSON.stringify({ x: Math.random(), y: Math.random() }), null, {
    opt: { cert: (t = f.features) == null ? void 0 : t.space }
  });
}
function Tt(e) {
  f.pub = e;
}
function $t() {
  f.pub = z.pub;
}
async function Bn({
  tag: e,
  key: t,
  text: n,
  pub: a = f.pub,
  cert: o
} = {}) {
  var s;
  if (o || (o = await k.user(a).get("features").get(e).then()), o || (o = (s = f.features) == null ? void 0 : s[`${e}`]), !o && a != w.pub) {
    console.log("No certificate found");
    return;
  }
  k.user(a).get(`${e}`).get(`${t}@${w.pub}`).put(n, null, { opt: { cert: o } });
}
let oe = Date.now();
function In({ TIMEOUT: e = 1e4 } = {}) {
  const t = b(), n = g({}), a = g({}), o = g({}), s = g({
    total: p(() => Object.keys(n).length),
    online: p(() => Object.keys(a).length),
    offline: p(() => Object.keys(o).length)
  });
  return t.user(f.pub).get("space").map().once((r, i) => {
    const { account: c } = lt(i);
    n[i] = c, n[i].order = p(() => oe - c.value.pulse < e ? 1 : oe - c.value.pulse), n[i].online = p(() => oe - c.value.pulse < e);
  }), K(() => {
    for (let r in n)
      n[r].online ? (a[r] = n[r], delete o[r]) : (o[r] = n[r], delete a[r]);
  }), { guests: n, online: a, offline: o, count: s };
}
function zn() {
  E();
  const e = b(), t = g({});
  return e.user(f.pub).get("gifts").map().once((n, a) => {
    e.get("#" + C).get(a.slice(0, -88)).once((o, s) => {
      try {
        const r = JSON.parse(o);
        t[s] = r;
      } catch {
      }
    });
  }), { gifts: t };
}
function Kn() {
  const { user: e } = E(), t = b(), n = g({}), a = g({}), o = g({});
  t.user().get(C).map().on((r, i) => {
    t.get("#" + C).get(i).once((c) => {
      try {
        c = JSON.parse(c), n[i] = c, c.from == e.pub && (a[i] = c), c.to == e.pub && (o[i] = c);
      } catch {
      }
    });
  });
  const s = g({});
  return t.user(f.pub).get(C).map().on(async (r, i) => {
    let c = i.slice(0, -88);
    t.get("#" + C).get(c).once(async (u) => {
      try {
        u = JSON.parse(u), u.to == e.pub && (await t.user().get(C).get(c).then() || (s[c] = u));
      } catch {
      }
    });
  }), { gifts: n, from: a, to: o, newGifts: s };
}
function Un(e) {
  const t = e.slice(-87), n = b(), a = g({});
  n.user(t).get(C).map().on((s, r) => {
    n.get("#" + C).get(r).once((i) => {
      try {
        i = JSON.parse(i), i.project == e && (a[r] = { ...i, state: {} }, n.user(i.from).get(C).get(r).on((c) => {
          a[r].state.from = c;
        }), n.user(i.to).get(C).get(r).on((c) => {
          a[r].state.to = c;
        }));
      } catch {
      }
    });
  });
  const o = g({});
  return K(() => {
    for (let s in a) {
      let r = a[s];
      o[r.ql] = o[r.ql] || { list: {}, sum: 0, from: {} }, o[r.ql].list[s] = r;
    }
    for (let s in o) {
      o[s].sum = 0, o[s].from = {};
      for (let r in o[s].list) {
        let i = o[s].list[r];
        !(i.state.from && i.state.to) || (o[s].sum += Number(i.qn), o[s].from[i.from] = o[s].from[i.from] || 0, o[s].from[i.from] += Number(i.qn));
      }
    }
  }), { gifts: a, collections: o };
}
function Jn(e) {
  e || (e = w.pub);
  const t = g({}), n = b();
  return n.user(e).get("mates").map().once((a, o) => {
    a ? (t[o] = {
      emoji: Z(a),
      text: a
    }, n.user(o).get("mates").get(e).on((s) => {
      s ? t[o].back = Z(s) : delete t[o].back;
    })) : delete t[o];
  }), t;
}
function Z(e, t = "\u{1F44B}") {
  if (!e || typeof e != "string")
    return;
  let n = He.break(e)[0];
  return Lt(n) ? n : t;
}
function Lt(e) {
  return /\p{Extended_Pictographic}/u.test(e);
}
function Yn(e) {
  const t = O("\u{1F44B}"), n = O(!1), a = w.db.get("mates").get(e);
  a.on((s) => {
    n.value = Z(s);
  });
  function o() {
    a.put(n.value ? !1 : Z(t.value));
  }
  return { emoji: t, isMate: n, toggleMate: o };
}
const Gt = Re("deep"), Zn = g({
  pub: null
}), w = g({
  initiated: !1,
  auth: !1,
  is: null,
  name: "",
  pub: p(() => {
    var e;
    return (e = w == null ? void 0 : w.is) == null ? void 0 : e.pub;
  }),
  color: p(() => w.pub ? Gt.hex(w.pub) : "gray"),
  pulse: 0,
  pulser: null,
  blink: !1,
  safe: {
    saved: null,
    password: null
  },
  pair() {
    var e, t, n;
    return (n = (t = (e = k == null ? void 0 : k.user) == null ? void 0 : e.call(k)) == null ? void 0 : t._) == null ? void 0 : n.sea;
  }
});
function E() {
  if (!w.initiated) {
    const e = b();
    w.db = e.user(), e.user().recall({ sessionStorage: !0 }, () => {
      console.log("user was recalled");
    }), e.on("auth", () => {
      Bt(), console.log("user authenticated");
    }), w.initiated = !0;
  }
  return { user: w, auth: te, leave: It };
}
function Bt() {
  w.is = k.user().is, w.pulser && clearInterval(w.pulser), w.pulser = setInterval(() => {
    k.user().get("pulse").put(Date.now());
  }, 1e3), k.user().get("epub").put(w.is.epub), k.user().get("pulse").on((e) => {
    w.blink = !w.blink, w.pulse = e;
  }), k.user().get("safe").map().on((e, t) => {
    w.safe[t] = e;
  }), k.user().get("profile").get("name").on((e) => w.name = e), w.initiated = !0;
}
async function te(e, t = () => {
}) {
  if (!Ge(e)) {
    console.log("incorrect pair", e);
    return;
  }
  k.user().auth(e, async () => {
    t(e), console.log("user is authenticated");
  });
}
function It() {
  var t;
  let e = !!((t = w.is) != null && t.pub);
  w.initiated = !1, clearInterval(w.pulser), k.user().leave(), setTimeout(() => {
    e && !w.pair() && (w.is = null, console.info("User logged out"));
  }, 500);
}
function qn(e) {
  if (!!e)
    return e.slice(1, 88) == w.pub;
}
function Wn(e) {
  k.user().get("profile").get(e).put("");
}
function Hn(e, t) {
  e && t !== void 0 && k.user().get("profile").get(e).put(t);
}
function Ge(e) {
  return e && typeof e == "object" && e.pub && e.epub && e.priv && e.epriv;
}
const A = g({
  input: "",
  show: !1,
  safePair: !1,
  minLength: 5,
  safe: {},
  dec: {},
  links: {
    pass: p(() => {
      var e;
      return ye((e = A.safe) == null ? void 0 : e.enc);
    }),
    pair: p(() => ye(JSON.stringify(w.pair())))
  },
  set() {
    Be(A.input), A.input = "", A.show = !1;
  }
});
function ye(e = "") {
  let t = me.encode(e);
  return window.location.origin + window.location.pathname + "#/auth/" + t;
}
function Xn(e) {
  let t = e.indexOf("#/auth/"), n = e.substr(t + 7);
  return me.decode(n);
}
let Se = !1;
function Vn() {
  return Se || (b().user().get("safe").map().on((t, n) => {
    A.safe[n] = t;
  }), K(async () => {
    var t, n;
    if (!A.show) {
      A.dec = {};
      return;
    }
    (A == null ? void 0 : A.show) && ((t = A == null ? void 0 : A.safe) == null ? void 0 : t.pass) && (A.dec.pass = await F.decrypt(A.safe.pass, w.pair()), A.input = A.dec.pass), A.show && ((n = A == null ? void 0 : A.safe) == null ? void 0 : n.enc) && (A.dec.pair = await F.decrypt(A.safe.enc, A.dec.pass));
  })), Se = !0, { pass: A, setPass: Be, logWithPass: zt };
}
async function Qn(e) {
  return await k.get(`~${e}`).get("safe").get("enc").then();
}
async function zt(e, t) {
  let n = await k.get(`~${e}`).get("safe").get("enc").then(), a = await F.decrypt(n, t);
  te(a);
}
async function Be(e) {
  let t = await F.encrypt(w.pair(), e), n = await F.encrypt(e, w.pair());
  w.db.get("safe").get("enc").put(t), w.db.get("safe").get("pass").put(n);
}
function _n(e, t) {
  if (!e)
    return;
  const n = me.decode(e);
  if (n.substring(0, 3) == "SEA")
    return t && Kt(n, t), "encrypted";
  try {
    let a = JSON.parse(n);
    return Ge(a) && te(a), "success";
  } catch {
    return "incorrect link";
  }
}
async function Kt(e, t) {
  let n = await F.decrypt(e, t);
  te(n);
}
function ea(e) {
  const t = b(), n = g({}), a = g({
    from: !1,
    to: !1,
    complete: p(() => a.from && a.to),
    status: p(() => a.from ? a.to ? "complete" : "proposed" : "canceled")
  });
  return t.get("#" + C).get(e).once((o, s) => {
    try {
      Object.assign(n, JSON.parse(o)), t.user(n.from).get(C).get(s).on((r) => {
        a.from = r;
      }), t.user(n.to).get(C).get(s).on((r) => {
        a.to = r;
      });
    } catch {
    }
  }), { gift: n, state: a };
}
async function ta(e, t = !0) {
  const { user: n } = E();
  n.db.get(C).get(e).put(t);
}
function na(e) {
  const { user: t } = E(), { now: n, pause: a } = Xe({ interval: 1e3, controls: !0 }), o = g({
    from: p(() => t == null ? void 0 : t.pub),
    to: "",
    qn: null,
    ql: null,
    wish: "",
    project: "",
    date: p(() => n.value.toString()),
    room: p(() => f.pub)
  }), s = p(() => {
    let l = Ie(o);
    return l.qn = Number(l.qn), l;
  }), r = ["from", "to", "qn", "ql"], i = p(() => r.reduce((d, v) => d && o[v], !0));
  X(o, (l) => {
    l.project && (o.to = l.project.slice(-87));
  });
  const c = Ve(async () => {
    const { hash: l, hashed: d } = await H(s.value);
    return l;
  }), u = O(!1);
  Object.assign(o, e);
  const m = b();
  async function h() {
    var v;
    const { hash: l, hashed: d } = await H(s.value);
    m.get("#" + C).get(l).put(d), m.user().get(C).get(l).put("proposed", () => {
      a(), u.value = !0;
    }), (v = f.features) != null && v.gifts && m.user(f.pub).get("gifts").get(`${l}@${t.pub}`).put(!0, () => {
      console.log(`gift ${l} published`);
    }, {
      opt: { cert: f.features.gifts }
    });
  }
  return { gift: o, cleanGift: s, valid: i, propose: h, proposed: u, hash: c };
}
function Ie(e) {
  return Object.entries(e).filter(([t, n]) => !!n).reduce((t, [n, a]) => ({ ...t, [n]: a === Object(a) ? Ie(a) : a }), {});
}
const C = "gifts", aa = {
  from: "",
  to: "",
  qn: 0,
  ql: "",
  wish: "",
  project: "",
  room: f.pub,
  date: ""
};
function oa(e) {
  const t = Object.entries(e.data);
  let n = t.sort((a, o) => {
    if (!a || !o)
      return 0;
    let s = Date.parse(a[0]);
    return Date.parse(o[0]) - s;
  });
  postMessage({ sorted: n, count: t.length });
}
const Ut = function(e) {
  var t = URL.createObjectURL(new Blob(["onmessage=", e.toString()], {
    type: "application/javascript"
  })), n = new Worker(t);
  return URL.revokeObjectURL(t), n;
};
function Jt(e) {
  const t = Object.entries(e.data);
  let n = t.sort((a, o) => {
    if (!a || !o)
      return 0;
    let s = Date.parse(a[0]);
    return Date.parse(o[0]) - s;
  });
  postMessage({ sorted: n, count: t.length });
}
function sa({
  name: e = "logs",
  after: t = "2021-01-01",
  before: n = "2023-01-01"
} = {}) {
  const o = b().get(e), s = new Ce(o, "minute"), r = g({}), i = O([]), c = O(0);
  let u;
  de(() => {
    var h = Ut(Jt);
    u = s.on(function(l, d) {
      !(l != null && l.event) || (r[d] = l);
    }, { gte: t, lt: n }), K(() => {
      h.postMessage(JSON.parse(JSON.stringify(r)));
    }), h.onmessage = (l) => {
      i.value = l.data.sorted, c.value = l.data.count;
    };
  }), Fe(() => {
    u.off();
  });
  function m(h) {
    !h || s.get(new Date()).put({ event: "now", data: h });
  }
  return { dateTree: r, sorted: i, count: c, putNow: m };
}
function ra(e = "text", t) {
  if (!t) {
    console.log("No data to log");
    return;
  }
  const n = new Ce(k.get("logs"), "minute");
  let a = { event: e, ...t };
  n.get(new Date()).put(a);
}
function ia(e) {
  if (!e)
    return;
  let t = new Date(e);
  return {
    date: t.toLocaleDateString("en-CA"),
    time: t.toLocaleTimeString("ru-RU"),
    ms: V(Date.now() - t.getTime())
  };
}
const J = g({
  title: "",
  public: !0
});
async function ca({ publish: e = !0 } = {}) {
  const t = b(), { user: n } = E(), a = t.user().get(B).get(J.title).put(J, () => {
    var o;
    !e || (t.user(f.pub).get(B).get(J.title + "@" + n.pub).put(a, null, {
      opt: { cert: (o = f.features) == null ? void 0 : o.projects }
    }), J.title = null);
  });
}
function ua(e, t, n) {
  const a = k.user().get(B).get(e);
  a.get(t).put(n, () => {
    a.get("updatedAt").put(Date.now());
  });
}
function la(e = O()) {
  e = O(e);
  const t = b();
  return { project: p(() => {
    const a = g({});
    return t.user(f.pub).get(B).get(e.value).map().on((o, s) => {
      a[s] = o;
    }), a;
  }) };
}
async function fa(e) {
  var o;
  const t = b(), n = mt(), { user: a } = E();
  if (e.includes(a.pub))
    t.user(f.pub).get(B).get(e).put(null, null, {
      opt: { cert: (o = f.features) == null ? void 0 : o.projects }
    });
  else if (f.hosts[a.pub]) {
    const s = await Qe.exports.SEA.decrypt(f.hosts[a.pub].enc, a.pair());
    n.user().auth(s, () => {
      n.user().get(B).get(e).put(null);
    });
  }
}
function da(e = f.pub) {
  const t = O(""), n = g({}), a = p(() => {
    const r = Object.entries(n).map((i) => ({ ...i[1], path: i[0] }));
    return new ee(r, {
      includeScore: !0,
      ignoreLocation: !0,
      keys: ["title"]
    });
  }), o = p(() => J.title ? a.value.search(J.title) : Object.entries(n).map((r) => ({ item: { ...r[1], path: r[0] } })));
  return b().user(e).get(B).map().on((r, i) => {
    if (r == null) {
      delete n[i];
      return;
    }
    const c = { ...r, path: i };
    delete c._, n[i] = c;
  }), { projects: n, search: t, candidates: o };
}
function ma(e = f.pub) {
  const t = g({});
  return b().user(e).get(B).map().on((a, o) => {
    if (a == null) {
      delete t[o];
      return;
    }
    t[o] = !0;
  }), p(() => Object.keys(t).length);
}
const B = "projects";
function ga({
  TIMEOUT: e = 1e4,
  randomness: t = 0.1
} = {}) {
  const n = O(), { area: a, mouse: o } = it(n), { width: s, height: r } = _e(n), i = g([0, 0]), c = et(1, 0.5, 2), u = b(), m = g({
    title: "space",
    joined: !1,
    db: p(() => u.user(f.pub).get("space")),
    cert: p(() => {
      var y;
      return (y = f.features) == null ? void 0 : y.space;
    }),
    my: {
      mouse: p(() => ({ x: o.x, y: o.y })),
      pos: null
    }
  });
  async function h() {
    m.joined = !0;
  }
  function l({ x: y = o.x, y: S = o.y } = {}) {
    var j;
    !w.pub || (m.joined || h(), i[0] = y, i[1] = S, m.db.get(w.pub).get("pos").put(JSON.stringify({ x: y, y: S }), null, {
      opt: { cert: (j = f.features) == null ? void 0 : j.space }
    }));
  }
  const d = g({}), v = g({}), P = g({}), x = p(() => {
    var S;
    const y = {};
    for (let j in d)
      Date.now() - ((S = d[j]) == null ? void 0 : S.pulse) < e && (y[j] = d[j]);
    return y;
  }), M = p(() => Object.keys(x.value).length);
  m.db.get(w.pub).on((y) => {
    m.my.pos = typeof y == "string" ? JSON.parse(y) : y;
  }), m.db.map().once(async (y, S) => {
    S == w.pub && (m.joined = !0), d[S] = {
      pub: S,
      blink: !1,
      pulse: 0,
      hasPos: !1,
      pos: {
        x: 0,
        y: 0
      }
    }, m.db.get(S).get("pos").on((j, W) => {
      d[S].hasPos = !0, d[S].pos = typeof j == "string" ? JSON.parse(j) : j;
    }), u.user(S).get("pulse").on((j) => {
      d[S].pulse = j, d[S].blink = !d[S].blink;
    }).back().get("mates").map().on((j, W) => {
      v[S] = v[S] || {}, v[S][W] = j;
    }), m.db.get(S).get("draw").on((j) => {
      !j || (d[S].draw = j);
    });
  });
  const L = {};
  return K(() => {
    for (let y in v) {
      L[y] = L[y] || {};
      for (let S in v[y]) {
        let j = L[y][S] = L[y][S] || Math.random() * t;
        if (v[y][S]) {
          const W = v[y][S];
          let T = d[y], $ = d[S], ze = Date.now() * 2 - (T == null ? void 0 : T.pulse) - ($ == null ? void 0 : $.pulse);
          T && $ && (T == null ? void 0 : T.hasPos) && ($ == null ? void 0 : $.hasPos) && ze < e && (P[y + S] = {
            user: y,
            mate: S,
            emoji: Z(W),
            from: T.pos,
            to: $.pos,
            arrow: Yt(T.pos, $.pos, j)
          });
        } else
          delete P[y + S];
      }
    }
  }), {
    space: m,
    allGuests: d,
    guests: x,
    guestCount: M,
    links: P,
    plane: n,
    width: s,
    height: r,
    position: i,
    zoom: c,
    area: a,
    join: h,
    place: l
  };
}
function Yt(e, t, n = 0) {
  let a = tt(e.x, e.y, t.x, t.y, {
    padEnd: 20,
    padStart: 10
  });
  const [o, s, r, i, c, u, m, h, l, d] = a;
  return {
    sx: o,
    sy: s,
    c1x: r * (1 - n + 2 * n),
    c1y: i * (1 - n + 2 * n),
    c2x: c * (1 - n + 2 * n),
    c2y: u * (1 - n + 2 * n),
    ex: m,
    ey: h,
    ae: l,
    as: d
  };
}
const D = g({
  colors: [
    "#000000",
    ...new Array(12).fill(!0).map((e, t) => `hsl(${t * 30}, 100%,50%)`),
    "#ffffff"
  ],
  sizes: nt([4, 8, 16, 24]),
  modes: ["line", "arrow", "stylus", "rectangle", "ellipse"],
  mode: p({
    get() {
      return ke.value;
    },
    set(e) {
      ke.value = e, e === "arrow" ? (I.mode = "line", I.arrowEnd = !0) : (I.mode = e, I.arrowEnd = !1);
    }
  }),
  enabled: !1,
  pinned: Q("drawing-pinned", !1),
  canUndo: !1,
  canRedo: !1,
  canClear: !1,
  ing: !1,
  initiated: !1,
  content: ""
}), I = at(Q("drawing-brush", {
  color: D.colors[0],
  size: 10,
  mode: "stylus"
})), ke = O("stylus");
let fe = !1;
const Zt = g({
  brush: I,
  acceptsInputTypes: p(() => D.enabled ? void 0 : ["pen"]),
  coordinateTransform: !0
}), R = ot(st(Zt));
function se(e) {
  fe = !0, D.content != null ? R.load(D.content) : R.clear(), fe = !1;
}
function qt() {
  var e;
  D.canRedo = R.canRedo(), D.canUndo = R.canUndo(), D.canClear = !!((e = R.el) != null && e.children.length);
}
function pa() {
  if (!D.initiated) {
    const e = b(), { user: t } = E(), n = e.user(f.pub).get("space").get(t.pub).get("draw");
    n.on((a) => {
      D.ing || (D.content = a, se());
    }), R.on("changed", () => {
      var a;
      if (qt(), !fe) {
        let o = R.dump();
        D.content = o, n.put(o, null, { opt: { cert: (a = f.features) == null ? void 0 : a.space } });
      }
    }), de(() => {
      rt(() => {
        se();
      });
    }), R.on("start", () => D.ing = !0), R.on("end", () => D.ing = !1), D.clear = () => {
      var a;
      R.clear(), D.content = "", n.put("", null, { opt: { cert: (a = f.features) == null ? void 0 : a.space } });
    }, window.addEventListener("keydown", (a) => {
      if (!D.enabled)
        return;
      const o = !a.ctrlKey && !a.altKey && !a.shiftKey && !a.metaKey;
      let s = !0;
      a.code === "KeyZ" && (a.ctrlKey || a.metaKey) ? a.shiftKey ? R.redo() : R.undo() : a.code === "Escape" ? D.enabled = !1 : a.code === "KeyC" && (a.ctrlKey || a.metaKey) ? D.clear() : a.code.startsWith("Digit") && o && +a.code[5] <= brushColors.length ? I.color = brushColors[+a.code[5] - 1] : s = !1, s && (a.preventDefault(), a.stopPropagation());
    }, !1);
  }
  return D.initiated = !0, {
    brush: I,
    draw: D,
    drauu: R,
    loadCanvas: se
  };
}
export {
  wa as SEA,
  Dn as addHashedPersonal,
  Bn as addPersonal,
  Ft as addPost,
  Wn as addProfileField,
  te as auth,
  jt as base64Extension,
  kt as base64FileType,
  kn as base64MimeType,
  I as brush,
  ma as countProjects,
  Rn as countRating,
  At as createMd,
  pe as createRoom,
  f as currentRoom,
  sn as decFrom,
  aa as defaultGift,
  Ne as defaultPeer,
  we as detectMimeType,
  ue as dictLang,
  G as dictRecord,
  Et as downloadFeed,
  yt as downloadFile,
  Dt as downloadPost,
  R as drauu,
  Zt as drauuOptions,
  D as draw,
  on as encFor,
  Tt as enterRoom,
  ia as formatDate,
  gt as genUUID,
  he as generateCerts,
  Z as getFirstEmoji,
  En as getHashedPersonal,
  rn as getShortHash,
  C as giftPath,
  ta as giftState,
  k as gun,
  ne as gun2,
  ba as gunAvatar,
  Qn as hasPass,
  H as hashObj,
  q as hashText,
  Lt as isEmoji,
  an as isHash,
  qn as isMine,
  Ge as isPair,
  Me as issueCert,
  Gn as joinRoom,
  wn as langParts,
  bn as languages,
  It as leave,
  $t as leaveRoom,
  Te as letterFilter,
  se as loadCanvas,
  be as loadFromHash,
  pt as loadRelays,
  ra as logEvent,
  ya as mountClass,
  Sa as mountElement,
  ka as ms,
  J as newProject,
  Ut as newWorker,
  ge as parseHashLink,
  Xn as parseLink,
  Ot as parseMd,
  An as parsePost,
  A as pass,
  Y as peer,
  B as projectsPath,
  Rt as reactToPost,
  Ln as recreateRoom,
  N as relay,
  fa as removeProject,
  vn as renderStress,
  z as rootRoom,
  ht as safeHash,
  un as safeJSONParse,
  Zn as selectedUser,
  ja as slugify,
  oa as sortByDate,
  tn as soul,
  Mt as submitRoom,
  cn as unsafeHash,
  Hn as updateProfile,
  ca as updateProject,
  ua as updateProjectField,
  le as updateRoomProfile,
  qt as updateState,
  xt as uploadFeed,
  yn as uploadText,
  lt as useAccount,
  Ht as useBackground,
  Xt as useChat,
  Re as useColor,
  dn as useDefs,
  pn as useDictAuthors,
  hn as useDictLangs,
  gn as useDictRecordsBy,
  mn as useDictRecordsFor,
  pa as useDraw,
  ea as useGift,
  zn as useGifts,
  In as useGuests,
  b as useGun,
  mt as useGun2,
  sa as useLog,
  Yn as useMate,
  Jn as useMates,
  jn as useMd,
  Kn as useMyGifts,
  na as useNewGift,
  Vn as usePass,
  _n as usePassLink,
  Sn as usePictureUpload,
  Pt as usePost,
  On as usePostTimestamp,
  Pn as usePosts,
  Vt as usePrivateChat,
  Qt as usePrivateChatCount,
  _t as usePrivateChatList,
  la as useProject,
  Un as useProjectGifts,
  da as useProjects,
  xn as useReaction,
  Cn as useReactions,
  en as useRelay,
  nn as useRelays,
  Mn as useRoom,
  Tn as useRoomLogo,
  $n as useRooms,
  ga as useSpace,
  it as useSvgMouse,
  Fn as useTagList,
  E as useUser,
  Nn as useUserPosts,
  fn as useWord,
  ln as useWords,
  Le as useZip,
  w as user
};
//# sourceMappingURL=composables.mjs.map
