henkan 2.4.7 → 2.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2544,9 +2544,19 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2544
2544
  rkf.readings.map((r) => r.reading)
2545
2545
  );
2546
2546
  const kanjiForms = rkf.kanjiForms !== void 0 ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
2547
+ const meanings = new Set(
2548
+ dictWord.meanings.flatMap(
2549
+ (m) => m.translations.map((t) => {
2550
+ if (typeof t === "string")
2551
+ return t.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
2552
+ else
2553
+ return t.translation.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
2554
+ })
2555
+ )
2556
+ ).values().toArray();
2547
2557
  let kanjiFormExamples = [];
2548
2558
  const readingMatchingKanjiFormExamples = [];
2549
- const readingExamples = [];
2559
+ let readingExamples = [];
2550
2560
  const readingMatchingKanjiForms = /* @__PURE__ */ new Set();
2551
2561
  const seenPhrases = /* @__PURE__ */ new Set();
2552
2562
  for (const example of exampleList)
@@ -2567,29 +2577,44 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2567
2577
  kanjiFormExamples.push({
2568
2578
  ex: example,
2569
2579
  partIndex: i,
2570
- form: part.baseForm
2580
+ form: part.baseForm,
2581
+ ...meanings.some(
2582
+ (m) => example.translation.includes(m)
2583
+ ) ? { includesTranslation: true } : {}
2571
2584
  });
2572
2585
  seenPhrases.add(example.phrase);
2573
2586
  break;
2574
2587
  }
2575
2588
  const readingAsBaseFormMatch = readings.has(part.baseForm);
2576
2589
  if ((readingAsBaseFormMatch || referenceIDMatch) && kanjiForms === void 0) {
2577
- readingExamples.push({ ex: example, partIndex: i });
2590
+ readingExamples.push({
2591
+ ex: example,
2592
+ partIndex: i,
2593
+ ...referenceIDMatch ? { referenceIDMatch: true } : {},
2594
+ ...!referenceIDMatch && meanings.some((m) => example.translation.includes(m)) ? { includesTranslation: true } : {}
2595
+ });
2578
2596
  seenPhrases.add(example.phrase);
2579
2597
  break;
2580
2598
  }
2581
2599
  }
2582
- if (readingMatchingKanjiForms.size > 0)
2600
+ const hasKfExamplesWithTranslation = kanjiFormExamples.some(
2601
+ (ex) => ex.includesTranslation === true
2602
+ );
2603
+ if (kanjiFormExamples.length > 0 && readingMatchingKanjiForms.size > 0)
2583
2604
  kanjiFormExamples = kanjiFormExamples.filter(
2584
- (ex) => ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
2605
+ (ex) => (!hasKfExamplesWithTranslation || ex.includesTranslation === true) && ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
2606
+ );
2607
+ if (readingExamples.length > 0 && readingExamples.some(
2608
+ (ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
2609
+ ))
2610
+ readingExamples = readingExamples.filter(
2611
+ (ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
2585
2612
  );
2586
- const includeKanjiFormExamples = word.kanjiForms !== void 0;
2587
2613
  let wordExamples = [
2588
- ...includeKanjiFormExamples ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
2614
+ ...word.kanjiForms !== void 0 ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
2589
2615
  ].toSorted(
2590
2616
  (a, b) => a.ex.phrase.length - b.ex.phrase.length
2591
2617
  );
2592
- readingMatchingKanjiForms.clear();
2593
2618
  seenPhrases.clear();
2594
2619
  const glossSpecificExamples = [];
2595
2620
  for (let i = 0; i < word.translations.length; i++)