{"version":3,"file":"emotes.mjs","names":[],"sources":["../../../src/message/parser/emotes.ts"],"sourcesContent":["import type { TwitchEmoteList } from \"../emotes\";\nimport { TwitchEmote } from \"../emote\";\nimport { parseIntThrowing } from \"./common\";\nimport { ParseError } from \"./parse-error\";\n\nexport function parseEmotes(\n  messageText: string,\n  emotesSource: string,\n): TwitchEmoteList {\n  const emotes: TwitchEmoteList = [];\n\n  if (emotesSource.length <= 0) {\n    return emotes;\n  }\n\n  // eslint-disable-next-line ts/no-misused-spread\n  const messageCharacters = [...messageText];\n\n  for (const emoteInstancesSource of emotesSource.split(\"/\")) {\n    const [emoteId, instancesSource] = emoteInstancesSource.split(\":\", 2) as [\n      string,\n      string,\n    ];\n    for (const instanceSource of instancesSource.split(\",\")) {\n      let [startIndex, endIndex] = instanceSource\n        .split(\"-\", 2)\n        .map((element) => parseIntThrowing(element)) as [\n        number,\n        number | undefined,\n      ];\n\n      if (endIndex == null) {\n        throw new ParseError(\n          `No - found in emote index range \"${instanceSource}\"`,\n        );\n      }\n\n      // to make endIndex exclusive\n      endIndex = endIndex + 1;\n\n      // workaround for Twitch bug: https://github.com/twitchdev/issues/issues/104\n      if (startIndex < 0) {\n        startIndex = 0;\n      }\n      if (endIndex > messageCharacters.length) {\n        endIndex = messageCharacters.length;\n      }\n\n      const emoteText = messageCharacters.slice(startIndex, endIndex).join(\"\");\n\n      emotes.push(new TwitchEmote(emoteId, startIndex, endIndex, emoteText));\n    }\n  }\n\n  // sort by start index\n  emotes.sort((a, b) => a.startIndex - b.startIndex);\n\n  return emotes;\n}\n"],"mappings":";;;;AAKA,SAAgB,YACd,aACA,cACiB;CACjB,MAAM,SAA0B,EAAE;AAElC,KAAI,aAAa,UAAU,EACzB,QAAO;CAIT,MAAM,oBAAoB,CAAC,GAAG,YAAY;AAE1C,MAAK,MAAM,wBAAwB,aAAa,MAAM,IAAI,EAAE;EAC1D,MAAM,CAAC,SAAS,mBAAmB,qBAAqB,MAAM,KAAK,EAAE;AAIrE,OAAK,MAAM,kBAAkB,gBAAgB,MAAM,IAAI,EAAE;GACvD,IAAI,CAAC,YAAY,YAAY,eAC1B,MAAM,KAAK,EAAE,CACb,KAAK,YAAY,iBAAiB,QAAQ,CAAC;AAK9C,OAAI,YAAY,KACd,OAAM,IAAI,WACR,oCAAoC,eAAe,GACpD;AAIH,cAAW,WAAW;AAGtB,OAAI,aAAa,EACf,cAAa;AAEf,OAAI,WAAW,kBAAkB,OAC/B,YAAW,kBAAkB;GAG/B,MAAM,YAAY,kBAAkB,MAAM,YAAY,SAAS,CAAC,KAAK,GAAG;AAExE,UAAO,KAAK,IAAI,YAAY,SAAS,YAAY,UAAU,UAAU,CAAC;;;AAK1E,QAAO,MAAM,GAAG,MAAM,EAAE,aAAa,EAAE,WAAW;AAElD,QAAO"}