henkan 2.4.9 → 2.4.11

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.cjs.js CHANGED
@@ -2618,13 +2618,17 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2618
2618
  )
2619
2619
  ).values().toArray();
2620
2620
  let kanjiFormExamples = [];
2621
- const readingMatchingKanjiFormExamples = [];
2621
+ let readingMatchingKanjiFormExamples = [];
2622
2622
  let readingExamples = [];
2623
- const readingMatchingKanjiForms = /* @__PURE__ */ new Set();
2623
+ let readingMatchingKanjiForms = /* @__PURE__ */ new Set();
2624
+ const readingMatchingKanjiFormsWithTranslations = /* @__PURE__ */ new Set();
2624
2625
  const seenPhrases = /* @__PURE__ */ new Set();
2625
2626
  for (const example of exampleList)
2626
2627
  for (let i = 0; i < example.parts.length; i++) {
2627
2628
  if (seenPhrases.has(example.phrase)) break;
2629
+ const includesTranslation = meanings.some(
2630
+ (m) => example.translation.includes(m)
2631
+ );
2628
2632
  const part = example.parts[i];
2629
2633
  const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
2630
2634
  const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
@@ -2633,17 +2637,19 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2633
2637
  if (readingAsReadingMatch || readingAsInflectedFormMatch || referenceIDMatch) {
2634
2638
  readingMatchingKanjiFormExamples.push({
2635
2639
  ex: example,
2636
- partIndex: i
2640
+ partIndex: i,
2641
+ form: part.baseForm,
2642
+ ...includesTranslation ? { includesTranslation: true } : {}
2637
2643
  });
2638
2644
  readingMatchingKanjiForms.add(part.baseForm);
2645
+ if (includesTranslation)
2646
+ readingMatchingKanjiFormsWithTranslations.add(part.baseForm);
2639
2647
  } else
2640
2648
  kanjiFormExamples.push({
2641
2649
  ex: example,
2642
2650
  partIndex: i,
2643
2651
  form: part.baseForm,
2644
- ...meanings.some(
2645
- (m) => example.translation.includes(m)
2646
- ) ? { includesTranslation: true } : {}
2652
+ ...includesTranslation ? { includesTranslation: true } : {}
2647
2653
  });
2648
2654
  seenPhrases.add(example.phrase);
2649
2655
  break;
@@ -2654,18 +2660,28 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2654
2660
  ex: example,
2655
2661
  partIndex: i,
2656
2662
  ...referenceIDMatch ? { referenceIDMatch: true } : {},
2657
- ...!referenceIDMatch && meanings.some((m) => example.translation.includes(m)) ? { includesTranslation: true } : {}
2663
+ ...!referenceIDMatch && includesTranslation ? { includesTranslation: true } : {}
2658
2664
  });
2659
2665
  seenPhrases.add(example.phrase);
2660
2666
  break;
2661
2667
  }
2662
2668
  }
2669
+ if (readingMatchingKanjiFormsWithTranslations.size > 0) {
2670
+ readingMatchingKanjiForms = readingMatchingKanjiFormsWithTranslations;
2671
+ readingMatchingKanjiFormExamples = readingMatchingKanjiFormExamples.filter(
2672
+ (ex) => ex.includesTranslation === true || ex.ex.parts.some(
2673
+ (part) => readingMatchingKanjiForms.has(part.baseForm) && part.glossNumber !== void 0
2674
+ )
2675
+ );
2676
+ }
2663
2677
  const hasKfExamplesWithTranslation = kanjiFormExamples.some(
2664
2678
  (ex) => ex.includesTranslation === true
2665
2679
  );
2666
2680
  if (kanjiFormExamples.length > 0 && readingMatchingKanjiForms.size > 0)
2667
2681
  kanjiFormExamples = kanjiFormExamples.filter(
2668
- (ex) => (!hasKfExamplesWithTranslation || ex.includesTranslation === true) && ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
2682
+ (ex) => readingMatchingKanjiForms.has(ex.form) && (!hasKfExamplesWithTranslation || ex.includesTranslation === true || ex.ex.parts.some(
2683
+ (part) => readingMatchingKanjiForms.has(part.baseForm) && part.glossNumber !== void 0
2684
+ ))
2669
2685
  );
2670
2686
  if (readingExamples.length > 0 && readingExamples.some(
2671
2687
  (ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
@@ -2752,7 +2768,7 @@ function isGrammar(entry) {
2752
2768
  }
2753
2769
  var createNotes = (notes, phrase) => `${phrase === true ? "<details><summary>Show translation</summary>" : ""}<ul class="note-list">${notes.map((note) => `<li class="note">${note}</li>`).join("")}</ul>${phrase === true ? "</details>" : ""}`;
2754
2770
  var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific === true ? " gloss-specific" : ""}">${entry}${notes !== void 0 && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
2755
- function generateAnkiNote(entry, customData) {
2771
+ function generateAnkiNote(entry, customData, additionalTags) {
2756
2772
  const fields = [];
2757
2773
  if (isWord(entry)) {
2758
2774
  const firstReading = createEntry(
@@ -2872,12 +2888,7 @@ function generateAnkiNote(entry, customData) {
2872
2888
  kanjiEntry.meanings
2873
2889
  )
2874
2890
  ).join("") : '<span class="word word-kanji" id="no-kanji">(no kanji)</span>',
2875
- searchField,
2876
- ...entry.tags !== void 0 && entry.tags.length > 0 ? [
2877
- entry.tags.map(
2878
- (tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
2879
- ).join(" ")
2880
- ] : []
2891
+ searchField
2881
2892
  );
2882
2893
  }
2883
2894
  if (isRadical(entry))
@@ -2904,12 +2915,7 @@ function generateAnkiNote(entry, customData) {
2904
2915
  entry.strokes !== void 0 ? createEntry(
2905
2916
  `<span class="radical radical-strokes">${entry.strokes}<br>${entry.svg !== void 0 ? `<img class="radical radical-stroke-order" src="${entry.svg}" alt="${entry.radical} stroke order SVG">` : "(no stroke order SVG available)"}</span>`
2906
2917
  ) : '<span class="radical radical-strokes" id="no-strokes">(no stroke number)</span>',
2907
- entry.sources !== void 0 ? `<span class="radical radical-source">${entry.sources.map((source, index) => `<a href="${source}" target="_blank">Source ${index + 1}</a>`).join("<br>")}</span>` : '<span class="radical radical-source" id="no-sources">(no sources)</span>',
2908
- ...entry.tags !== void 0 && entry.tags.length > 0 ? [
2909
- entry.tags.map(
2910
- (tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
2911
- ).join(" ")
2912
- ] : []
2918
+ entry.sources !== void 0 ? `<span class="radical radical-source">${entry.sources.map((source, index) => `<a href="${source}" target="_blank">Source ${index + 1}</a>`).join("<br>")}</span>` : '<span class="radical radical-source" id="no-sources">(no sources)</span>'
2913
2919
  );
2914
2920
  if (isKanji(entry))
2915
2921
  fields.push(
@@ -2950,12 +2956,7 @@ function generateAnkiNote(entry, customData) {
2950
2956
  entry.strokes !== void 0 ? createEntry(
2951
2957
  `<span class="kanji kanji-strokes">${entry.strokes}<br>${entry.svg !== void 0 ? `<img class="kanji kanji-stroke-order" src="${entry.svg}" alt="${entry.kanji} stroke order SVG">` : "(no stroke order SVG available)"}</span>`
2952
2958
  ) : '<span class="kanji kanji-strokes" id="no-strokes">(no stroke number)</span>',
2953
- entry.source !== void 0 ? `<span class="kanji kanji-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="kanji kanji-source" id="no-source">(no components/mnemonic source)</span>',
2954
- ...entry.tags !== void 0 && entry.tags.length > 0 ? [
2955
- entry.tags.map(
2956
- (tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
2957
- ).join(" ")
2958
- ] : []
2959
+ entry.source !== void 0 ? `<span class="kanji kanji-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="kanji kanji-source" id="no-source">(no components/mnemonic source)</span>'
2959
2960
  );
2960
2961
  if (isKana(entry))
2961
2962
  fields.push(
@@ -2965,12 +2966,7 @@ function generateAnkiNote(entry, customData) {
2965
2966
  ),
2966
2967
  entry.svg !== void 0 ? createEntry(
2967
2968
  `<img class="kana kana-stroke-order" src="${entry.svg}" alt="${entry.kana} stroke order SVG">`
2968
- ) : "(no stroke order SVG available)",
2969
- ...entry.tags !== void 0 && entry.tags.length > 0 ? [
2970
- entry.tags.map(
2971
- (tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
2972
- ).join(" ")
2973
- ] : []
2969
+ ) : "(no stroke order SVG available)"
2974
2970
  );
2975
2971
  if (isGrammar(entry))
2976
2972
  fields.push(
@@ -2995,16 +2991,15 @@ function generateAnkiNote(entry, customData) {
2995
2991
  true
2996
2992
  )
2997
2993
  ).join("") : '<span class="grammar grammar-phrase" id="no-phrases">(no phrases)</span>',
2998
- entry.source !== void 0 ? `<span class="grammar grammar-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="grammar grammar-source" id="no-source">(no source)</span>',
2999
- ...entry.tags !== void 0 && entry.tags.length > 0 ? [
3000
- entry.tags.map(
3001
- (tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
3002
- ).join(" ")
3003
- ] : []
2994
+ entry.source !== void 0 ? `<span class="grammar grammar-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="grammar grammar-source" id="no-source">(no source)</span>'
2995
+ );
2996
+ if (entry.tags !== void 0 && entry.tags.length > 0 || additionalTags !== void 0 && additionalTags.length > 0)
2997
+ fields.push(
2998
+ [...entry.tags ?? [], ...additionalTags ?? []].map((tag) => tag.trim().toLowerCase().replaceAll(" ", "::")).join(" ")
3004
2999
  );
3005
3000
  return fields.map((field) => field.replaceAll("\n", "<br>"));
3006
3001
  }
3007
- function generateAnkiNotesFile(list, defaultNoteInfo, customData) {
3002
+ function generateAnkiNotesFile(list, defaultNoteInfo, customData, additionalTags) {
3008
3003
  const headers = [noteHeaderKeys.separator, noteHeaderKeys.html];
3009
3004
  let ankiNotes = "";
3010
3005
  if (list.length > 0) {
@@ -3054,7 +3049,11 @@ function generateAnkiNotesFile(list, defaultNoteInfo, customData) {
3054
3049
  headers.push(`${noteHeaderKeys.deck}${++headerCount}`);
3055
3050
  hasHeader.deckPath = true;
3056
3051
  }
3057
- const note = generateAnkiNote(result, customData);
3052
+ const note = generateAnkiNote(
3053
+ result,
3054
+ customData,
3055
+ additionalTags
3056
+ );
3058
3057
  if (!hasHeader.tags) {
3059
3058
  headers.push(`${noteHeaderKeys.tags}${note.length + headerCount}`);
3060
3059
  hasHeader.tags = true;