{"version":3,"file":"pages/TreeShaking/open-tag.mjs","sources":["../../../src/pages/TreeShaking/open-tag.ts"],"sourcesContent":["import { SDK } from '@rsdoctor/types';\n\nexport enum AttributeKey {\n  Module = 'data-module',\n  Range = 'data-range',\n}\n\nexport interface OpenTagData {\n  module: number;\n  range: SDK.SourceRange;\n}\n\nexport function getOpenTagText(\n  module: number,\n  range: SDK.SourceRange,\n  text: string,\n) {\n  return `<a data-href=\"${AttributeKey.Module}=${module}&${\n    AttributeKey.Range\n  }=${encodeURIComponent(JSON.stringify(range))}\">${text}</a>`;\n}\n\nexport function parseOpenTag(dom: HTMLElement): OpenTagData | undefined {\n  if (dom.tagName.toLocaleLowerCase() !== 'a') {\n    return;\n  }\n\n  const hrefString = dom.getAttribute('data-href') ?? '';\n  const result: OpenTagData = {\n    module: -1,\n    range: {\n      start: {\n        line: 1,\n        column: 0,\n      },\n      end: {\n        line: 1,\n        column: 0,\n      },\n    },\n  };\n\n  for (const item of hrefString.split('&')) {\n    const [key, value] = item.split('=');\n\n    if (key === AttributeKey.Module) {\n      result.module = Number.parseInt(value, 10);\n      continue;\n    }\n\n    if (key === AttributeKey.Range) {\n      result.range = JSON.parse(decodeURIComponent(value));\n    }\n  }\n\n  return result;\n}\n"],"names":["AttributeKey","getOpenTagText","module","range","text","encodeURIComponent","JSON","parseOpenTag","dom","hrefString","result","item","key","value","Number","decodeURIComponent"],"mappings":"AAEO,IAAKA,wBAAYA,WAAAA,GAAAA,SAAZA,YAAY;;;WAAZA;;AAUL,SAASC,eACdC,MAAc,EACdC,KAAsB,EACtBC,IAAY;IAEZ,OAAO,6BAAwCF,qBAE3CG,mBAAmBC,KAAK,SAAS,CAACH,YAAYC,UAAU;AAC9D;AAEO,SAASG,aAAaC,GAAgB;IAC3C,IAAIA,AAAoC,QAApCA,IAAI,OAAO,CAAC,iBAAiB,IAC/B;IAGF,MAAMC,aAAaD,IAAI,YAAY,CAAC,gBAAgB;IACpD,MAAME,SAAsB;QAC1B,QAAQ;QACR,OAAO;YACL,OAAO;gBACL,MAAM;gBACN,QAAQ;YACV;YACA,KAAK;gBACH,MAAM;gBACN,QAAQ;YACV;QACF;IACF;IAEA,KAAK,MAAMC,QAAQF,WAAW,KAAK,CAAC,KAAM;QACxC,MAAM,CAACG,KAAKC,MAAM,GAAGF,KAAK,KAAK,CAAC;QAEhC,IAAIC,AAAQ,kBAARA,KAA6B;YAC/BF,OAAO,MAAM,GAAGI,OAAO,QAAQ,CAACD,OAAO;YACvC;QACF;QAEA,IAAID,AAAQ,iBAARA,KACFF,OAAO,KAAK,GAAGJ,KAAK,KAAK,CAACS,mBAAmBF;IAEjD;IAEA,OAAOH;AACT"}