UNPKG

mind-elixir

Version:

Mind elixir is a free open source mind map core.

96 lines (95 loc) 3.63 kB
var d = /* @__PURE__ */ ((r) => (r.LHS = "lhs", r.RHS = "rhs", r))(d || {}); const I = (r) => `<div class="map-container"><div>${r}</div></div>`, v = function(r, c = {}) { const { direction: l = 2 } = c, o = (e) => { const n = { id: e.id, topic: e.topic, direction: e.direction, style: e.style, tags: e.tags, icons: e.icons, hyperLink: e.hyperLink, expanded: e.expanded, image: e.image, branchColor: e.branchColor, dangerouslySetInnerHTML: e.dangerouslySetInnerHTML, note: e.note }; return e.children && e.children.length > 0 && (n.children = e.children.map(o)), n; }, f = o(r), g = r.children || [], p = [], m = []; if (l === 2) { let e = 0, n = 0; g.forEach((t) => { const i = o(t); t.direction === 0 ? (i.direction = 0, p.push(i), e += 1) : t.direction === 1 ? (i.direction = 1, m.push(i), n += 1) : e <= n ? (i.direction = 0, p.push(i), e += 1) : (i.direction = 1, m.push(i), n += 1); }); } else l === 0 ? g.forEach((e) => { const n = o(e); n.direction = 0, p.push(n); }) : g.forEach((e) => { const n = o(e); n.direction = 1, m.push(n); }); return { root: f, leftNodes: p, rightNodes: m, direction: l }; }, W = function(r, c = {}) { const { className: l = "" } = c, o = (t, i = !1) => { const S = `me${t.id}`, T = "me-tpc"; let $ = ""; if (t.style) { const s = []; t.style.color && s.push(`color: ${t.style.color}`), t.style.background && s.push(`background: ${t.style.background}`), t.style.fontSize && s.push(`font-size: ${t.style.fontSize}px`), t.style.fontWeight && s.push(`font-weight: ${t.style.fontWeight}`), s.length > 0 && ($ = ` style="${s.join("; ")}"`); } let h = ""; if (t.dangerouslySetInnerHTML) h = t.dangerouslySetInnerHTML; else { if (h = u(t.topic), t.tags && t.tags.length > 0) { const s = t.tags.map((a) => `<span class="me-tag">${u(a)}</span>`).join(""); h += s; } if (t.icons && t.icons.length > 0) { const s = t.icons.map((a) => `<span class="me-icon">${a}</span>`).join(""); h += s; } if (t.image) { const { url: s, width: a, height: L, fit: E = "cover" } = t.image; h += `<img src="${u(s)}" width="${a}" height="${L}" style="object-fit: ${E}" alt="" />`; } } const H = `<me-tpc class="${T}" data-nodeid="${S}"${$}>${h}</me-tpc>`; if (i) return `<me-root>${H}</me-root>`; let y = ""; return t.children && t.children.length > 0 && t.expanded !== !1 && (y = `<me-children>${t.children.map((a) => f(a)).join("")}</me-children>`), `<me-wrapper>${`<me-parent>${H}</me-parent>`}${y}</me-wrapper>`; }, f = (t) => o(t, !1), g = o(r.root, !0), p = r.leftNodes.map((t) => f(t)).join(""), m = r.rightNodes.map((t) => f(t)).join(""), e = `<me-main class="${d.LHS}">${p}</me-main>`, n = `<me-main class="${d.RHS}">${m}</me-main>`; return I(`<div class="${l}">${e}${g}${n}</div>`); }; function u(r) { const c = typeof document < "u" ? document.createElement("div") : null; return c ? (c.textContent = r, c.innerHTML) : r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"); } const j = function(r) { return JSON.stringify(r, null, 2); }, R = function(r, c, l = {}) { return { nodeData: r, layoutResult: c, options: { direction: c.direction, ...l }, timestamp: Date.now() }; }; export { R as getHydrationData, j as getSSRData, v as layoutSSR, W as renderSSRHTML };