Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

2.3 KB
Raw Blame
// Shared data, i18n, and DOM helpers for the rich-text editor.
import { I18n } from '../i18n.js';

export const i18n = new I18n((typeof window !== 'undefined' && window._LM_I18N) || {});
export const t = (k) => i18n.t(k);

// Nearest element matching `sel` at the editor's current selection
export function closestInSelection(ed, root, sel) {
  const range = ed.getSelection();
  if (!range) {
    return null;
  }

  let node = range.commonAncestorContainer;
  if (node.nodeType === 3) {
    node = node.parentNode;
  }
  const el = node?.closest(sel);
  if (el && root.contains(el)) {
    return el;
  }

  // Selection wrapping an element.
  const at = range.startContainer.nodeType === 1
    ? range.startContainer.childNodes[range.startOffset] : null;
  if (at?.nodeType !== 1) {
    return null;
  }
  const inner = at.matches(sel) ? at : at.querySelector(sel);
  return inner && root.contains(inner) ? inner : null;
}

// Colour swatches for the fore/highlight colour pickers (applied inline for email).
export const PALETTE = [
  '#BFEDD2', '#FBEEB8', '#F8CAC6', '#C2E0F4', '#2DC26B',
  '#F1C40F', '#E03E2D', '#B96AD9', '#3598DB', '#169179', '#E67E23',
  '#BA372A', '#843FA1', '#236FA1', '#ECF0F1', '#CED4D9', '#95A5A6',
  '#7E8C8D', '#34495E', '#000000', '#ffffff', '#D95757', '#C80707',
];

export const EMOJIS = [
  '๐Ÿ˜€', '๐Ÿ˜ƒ', '๐Ÿ˜„', '๐Ÿ˜', '๐Ÿ˜†', '๐Ÿ˜…', '๐Ÿ˜‚', '๐Ÿ™‚', '๐Ÿ˜‰', '๐Ÿ˜Š', '๐Ÿ˜', '๐Ÿ˜˜', '๐Ÿ˜Ž', '๐Ÿค”', '๐Ÿ˜', '๐Ÿ˜ด',
  '๐Ÿ˜ฎ', '๐Ÿ˜ข', '๐Ÿ˜ญ', '๐Ÿ˜ก', '๐Ÿ‘', '๐Ÿ‘Ž', '๐Ÿ‘Œ', '๐Ÿ™', '๐Ÿ‘', '๐Ÿ’ช', '๐Ÿ™Œ', '๐Ÿ‘‹', '๐Ÿค', 'โœŒ๏ธ', 'โค๏ธ', '๐Ÿงก',
  '๐Ÿ’›', '๐Ÿ’š', '๐Ÿ’™', '๐Ÿ’œ', '๐Ÿ–ค', 'โญ', '๐ŸŒŸ', 'โœจ', '๐Ÿ”ฅ', '๐Ÿ’ฏ', 'โœ…', 'โŒ', 'โš ๏ธ', 'โ“', 'โ—', '๐Ÿ’ก',
  '๐Ÿ“ง', '๐Ÿ“จ', '๐Ÿ“ฉ', '๐Ÿ“ข', '๐ŸŽ‰', '๐ŸŽŠ', '๐ŸŽ', '๐Ÿš€', '๐Ÿ“ˆ', '๐Ÿ“‰', '๐Ÿ’ฐ', '๐Ÿ›’', '๐Ÿ“…', 'โฐ', '๐Ÿ””', '๐Ÿ”—',
];

export const CHARS = [
  'ยฉ', 'ยฎ', 'โ„ข', 'โ‚ฌ', 'ยฃ', 'ยฅ', 'ยข', 'ยง', 'ยถ', 'โ€ ', 'โ€ก', 'โ€ข', 'ยท', 'โ€ฆ', 'โ€ฐ', 'โ€ฒ',
  'โ€ณ', 'ยซ', 'ยป', 'โ€น', 'โ€บ', 'โ€œ', 'โ€', 'โ€˜', 'โ€™', 'โ€“', 'โ€”', 'ยก', 'ยฟ', 'ร—', 'รท', 'ยฑ',
  'โ‰ ', 'โ‰ค', 'โ‰ฅ', 'โ‰ˆ', 'โˆž', 'ยฐ', 'ยต', 'ฮฑ', 'ฮฒ', 'ฮณ', 'ฯ€', 'ฮฉ', 'โ†', 'โ†’', 'โ†‘', 'โ†“',
  'ยผ', 'ยฝ', 'ยพ', 'โ…“', 'โ…”', 'ยช', 'ยบ', 'โ„–', 'โ˜‘', 'โ˜', 'โ˜…', 'โ˜†', 'โ™ฅ', 'โ™ฆ', 'โ™ฃ', 'โ™ ',
];