{"version":3,"sources":["../../../../src/vanilla/scores/consecutive.ts"],"sourcesContent":["import type { HighlightRanges } from \"../types\";\n\nexport function scoreConsecutiveLetters(\n\tindices: HighlightRanges,\n\tnormalizedItem: string,\n): [number, HighlightRanges] | null {\n\t// Score: 2 + sum of chunk scores\n\t// Chunk scores:\n\t// - 0.2 for a full word\n\t// - 0.4 for chunk starting at beginning of word\n\t// - 0.8 for chunk in the middle of the word (if >=3 characters)\n\t// - 1.6 for chunk in the middle of the word (if 1 or 2 characters)\n\tlet score = 2;\n\n\tfor (const [firstIdx, lastIdx] of indices) {\n\t\tconst chunkLength = lastIdx - firstIdx + 1;\n\t\tconst isStartOfWord =\n\t\t\tfirstIdx === 0 ||\n\t\t\tnormalizedItem[firstIdx] === \" \" ||\n\t\t\tnormalizedItem[firstIdx - 1] === \" \";\n\t\tconst isEndOfWord =\n\t\t\tlastIdx === normalizedItem.length - 1 ||\n\t\t\tnormalizedItem[lastIdx] === \" \" ||\n\t\t\tnormalizedItem[lastIdx + 1] === \" \";\n\t\tconst isFullWord = isStartOfWord && isEndOfWord;\n\t\t// DEBUG:\n\t\t// console.log({\n\t\t//   firstIdx,\n\t\t//   lastIdx,\n\t\t//   chunkLength,\n\t\t//   isStartOfWord,\n\t\t//   isEndOfWord,\n\t\t//   isFullWord,\n\t\t//   before: normalizedItem[firstIdx - 1],\n\t\t//   after: normalizedItem[lastIdx + 1],\n\t\t// })\n\t\tif (isFullWord) {\n\t\t\tscore += 0.2;\n\t\t} else if (isStartOfWord) {\n\t\t\tscore += 0.4;\n\t\t} else if (chunkLength >= 3) {\n\t\t\tscore += 0.8;\n\t\t} else {\n\t\t\tscore += 1.6;\n\t\t}\n\t}\n\n\treturn [score, indices];\n}\n"],"mappings":";AAEO,SAAS,wBACf,SACA,gBACmC;AAOnC,MAAI,QAAQ;AAEZ,aAAW,CAAC,UAAU,OAAO,KAAK,SAAS;AAC1C,UAAM,cAAc,UAAU,WAAW;AACzC,UAAM,gBACL,aAAa,KACb,eAAe,QAAQ,MAAM,OAC7B,eAAe,WAAW,CAAC,MAAM;AAClC,UAAM,cACL,YAAY,eAAe,SAAS,KACpC,eAAe,OAAO,MAAM,OAC5B,eAAe,UAAU,CAAC,MAAM;AACjC,UAAM,aAAa,iBAAiB;AAYpC,QAAI,YAAY;AACf,eAAS;AAAA,IACV,WAAW,eAAe;AACzB,eAAS;AAAA,IACV,WAAW,eAAe,GAAG;AAC5B,eAAS;AAAA,IACV,OAAO;AACN,eAAS;AAAA,IACV;AAAA,EACD;AAEA,SAAO,CAAC,OAAO,OAAO;AACvB;","names":[]}