OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-editor-parser / src / display / to-display-partial.js

24 lines · javascript ref:
const { DISPLAY_TYPES: t } = require("../constants.js")
function n({ text: n, display: a = [] }, s = {}) {
  const e = n.length
  let { start: i = 0, end: o = e } = s
  ;((i = Math.max(0, Math.min(0 | i, e))), (o = Math.max(i, Math.min(0 | o, e))))
  let h = o
  const l = []
  for (const n of a) {
    const a = 0 | n.start,
      s = a + (0 | n.length),
      e = Math.max(a, i),
      r = Math.min(s, o)
    if (!(r <= e)) {
      if (n.type === t.EMOJI && (e > a || r < s)) {
        h = Math.min(h, a)
        continue
      }
      l.push({ ...n, start: e - i, length: r - e })
    }
  }
  return { text: n.slice(i, h), display: l }
}
module.exports = { displayPartial: n }