henkan 2.4.6 → 2.4.8
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 +41 -18
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.mjs +41 -18
- package/dist/index.mjs.map +2 -2
- package/dist/types/utils.d.ts +4 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/functions/generateAnkiNote.md +8 -2
- package/docs/api/functions/generateAnkiNotesFile.md +8 -2
- package/package.json +4 -4
- package/src/utils.ts +75 -16
package/dist/index.cjs.js
CHANGED
|
@@ -2607,9 +2607,19 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2607
2607
|
rkf.readings.map((r) => r.reading)
|
|
2608
2608
|
);
|
|
2609
2609
|
const kanjiForms = rkf.kanjiForms !== void 0 ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
2610
|
+
const meanings = new Set(
|
|
2611
|
+
dictWord.meanings.flatMap(
|
|
2612
|
+
(m) => m.translations.map((t) => {
|
|
2613
|
+
if (typeof t === "string")
|
|
2614
|
+
return t.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
|
|
2615
|
+
else
|
|
2616
|
+
return t.translation.replaceAll(/\([^)]*\)|\[[^\]]*\]|\{[^}]*\}/g, "").trim();
|
|
2617
|
+
})
|
|
2618
|
+
)
|
|
2619
|
+
).values().toArray();
|
|
2610
2620
|
let kanjiFormExamples = [];
|
|
2611
2621
|
const readingMatchingKanjiFormExamples = [];
|
|
2612
|
-
|
|
2622
|
+
let readingExamples = [];
|
|
2613
2623
|
const readingMatchingKanjiForms = /* @__PURE__ */ new Set();
|
|
2614
2624
|
const seenPhrases = /* @__PURE__ */ new Set();
|
|
2615
2625
|
for (const example of exampleList)
|
|
@@ -2630,29 +2640,42 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2630
2640
|
kanjiFormExamples.push({
|
|
2631
2641
|
ex: example,
|
|
2632
2642
|
partIndex: i,
|
|
2633
|
-
form: part.baseForm
|
|
2643
|
+
form: part.baseForm,
|
|
2644
|
+
...meanings.some(
|
|
2645
|
+
(m) => example.translation.includes(m)
|
|
2646
|
+
) ? { includesTranslation: true } : {}
|
|
2634
2647
|
});
|
|
2635
2648
|
seenPhrases.add(example.phrase);
|
|
2636
2649
|
break;
|
|
2637
2650
|
}
|
|
2638
2651
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
2639
2652
|
if ((readingAsBaseFormMatch || referenceIDMatch) && kanjiForms === void 0) {
|
|
2640
|
-
readingExamples.push({
|
|
2653
|
+
readingExamples.push({
|
|
2654
|
+
ex: example,
|
|
2655
|
+
partIndex: i,
|
|
2656
|
+
...referenceIDMatch ? { referenceIDMatch: true } : {},
|
|
2657
|
+
...!referenceIDMatch && meanings.some((m) => example.translation.includes(m)) ? { includesTranslation: true } : {}
|
|
2658
|
+
});
|
|
2641
2659
|
seenPhrases.add(example.phrase);
|
|
2642
2660
|
break;
|
|
2643
2661
|
}
|
|
2644
2662
|
}
|
|
2645
|
-
if (readingMatchingKanjiForms.size > 0)
|
|
2663
|
+
if (kanjiFormExamples.length > 0 && readingMatchingKanjiForms.size > 0)
|
|
2646
2664
|
kanjiFormExamples = kanjiFormExamples.filter(
|
|
2647
|
-
(ex) => ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
|
|
2665
|
+
(ex) => ex.includesTranslation === true && ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
|
|
2666
|
+
);
|
|
2667
|
+
else kanjiFormExamples.length = 0;
|
|
2668
|
+
if (readingExamples.length > 0 && readingExamples.some(
|
|
2669
|
+
(ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
|
|
2670
|
+
))
|
|
2671
|
+
readingExamples = readingExamples.filter(
|
|
2672
|
+
(ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
|
|
2648
2673
|
);
|
|
2649
|
-
const includeKanjiFormExamples = word.kanjiForms !== void 0;
|
|
2650
2674
|
let wordExamples = [
|
|
2651
|
-
...
|
|
2675
|
+
...word.kanjiForms !== void 0 ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
|
|
2652
2676
|
].toSorted(
|
|
2653
2677
|
(a, b) => a.ex.phrase.length - b.ex.phrase.length
|
|
2654
2678
|
);
|
|
2655
|
-
readingMatchingKanjiForms.clear();
|
|
2656
2679
|
seenPhrases.clear();
|
|
2657
2680
|
const glossSpecificExamples = [];
|
|
2658
2681
|
for (let i = 0; i < word.translations.length; i++)
|
|
@@ -2727,7 +2750,7 @@ function isGrammar(entry) {
|
|
|
2727
2750
|
}
|
|
2728
2751
|
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>" : ""}`;
|
|
2729
2752
|
var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific === true ? " gloss-specific" : ""}">${entry}${notes !== void 0 && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
2730
|
-
function generateAnkiNote(entry) {
|
|
2753
|
+
function generateAnkiNote(entry, customData) {
|
|
2731
2754
|
const fields = [];
|
|
2732
2755
|
if (isWord(entry)) {
|
|
2733
2756
|
const firstReading = createEntry(
|
|
@@ -2831,10 +2854,10 @@ function generateAnkiNote(entry) {
|
|
|
2831
2854
|
const searchField = `${entry.readings.map((r) => r.reading).join(" ")}${entry.kanjiForms !== void 0 ? ` ${entry.kanjiForms.map((kf) => kf.kanjiForm).join(" ")}` : ""} ${entry.id}`;
|
|
2832
2855
|
fields.push(
|
|
2833
2856
|
...entry.kanjiForms !== void 0 && !entry.usuallyInKana ? [
|
|
2834
|
-
`${kanjiFormsField}<div id="kf-pos" style="display: none" data-pos="1"></div>`,
|
|
2857
|
+
`${customData !== void 0 ? `<div id="custom-data" style="display: none" data-custom="${customData}"></div>` : ""}${kanjiFormsField}<div id="kf-pos" style="display: none" data-pos="1"></div>`,
|
|
2835
2858
|
`${hasAudio ? readingsFieldWithoutAudio : readingsField}<div id="r-pos" style="display: none" data-pos="2"></div>`
|
|
2836
2859
|
] : [
|
|
2837
|
-
`${kanjiFormsField}<div id="kf-pos" style="display: none" data-pos="2"></div>`,
|
|
2860
|
+
`${customData !== void 0 ? `<div id="custom-data" style="display: none" data-custom="${customData}"></div>` : ""}${kanjiFormsField}<div id="kf-pos" style="display: none" data-pos="2"></div>`,
|
|
2838
2861
|
`${hasAudio ? readingsFieldWithoutAudio : readingsField}<div id="r-pos" style="display: none" data-pos="1"></div>`
|
|
2839
2862
|
],
|
|
2840
2863
|
`${hasAudio ? readingsField : readingsFieldWithoutAudio}<div id="r-pos" style="display: none" data-pos="${entry.kanjiForms !== void 0 && !entry.usuallyInKana ? "2" : "1"}"></div>`,
|
|
@@ -2857,9 +2880,9 @@ function generateAnkiNote(entry) {
|
|
|
2857
2880
|
}
|
|
2858
2881
|
if (isRadical(entry))
|
|
2859
2882
|
fields.push(
|
|
2860
|
-
createEntry(
|
|
2883
|
+
`${customData !== void 0 ? `<div id="custom-data" style="display: none" data-custom="${customData}"></div>` : ""}${createEntry(
|
|
2861
2884
|
`<span class="radical radical-character">${entry.radical}</span>`
|
|
2862
|
-
)
|
|
2885
|
+
)}`,
|
|
2863
2886
|
createEntry(
|
|
2864
2887
|
`<span class="radical radical-reading">${entry.reading}</span>`
|
|
2865
2888
|
),
|
|
@@ -2888,7 +2911,7 @@ function generateAnkiNote(entry) {
|
|
|
2888
2911
|
);
|
|
2889
2912
|
if (isKanji(entry))
|
|
2890
2913
|
fields.push(
|
|
2891
|
-
createEntry(`<span class="kanji kanji-character">${entry.kanji}</span>`)
|
|
2914
|
+
`${customData !== void 0 ? `<div id="custom-data" style="display: none" data-custom="${customData}"></div>` : ""}${createEntry(`<span class="kanji kanji-character">${entry.kanji}</span>`)}`,
|
|
2892
2915
|
entry.meanings !== void 0 ? entry.meanings.map(
|
|
2893
2916
|
(meaningEntry) => createEntry(
|
|
2894
2917
|
`<span class="kanji kanji-meaning">${meaningEntry}</span>`
|
|
@@ -2934,7 +2957,7 @@ function generateAnkiNote(entry) {
|
|
|
2934
2957
|
);
|
|
2935
2958
|
if (isKana(entry))
|
|
2936
2959
|
fields.push(
|
|
2937
|
-
createEntry(`<span class="kana kana-character">${entry.kana}</span>`)
|
|
2960
|
+
`${customData !== void 0 ? `<div id="custom-data" style="display: none" data-custom="${customData}"></div>` : ""}${createEntry(`<span class="kana kana-character">${entry.kana}</span>`)}`,
|
|
2938
2961
|
createEntry(
|
|
2939
2962
|
`<span class="kana kana-reading">${entry.reading}${entry.audio !== void 0 ? `<br>[sound:${entry.audio}]` : ""}</span>`
|
|
2940
2963
|
),
|
|
@@ -2949,7 +2972,7 @@ function generateAnkiNote(entry) {
|
|
|
2949
2972
|
);
|
|
2950
2973
|
if (isGrammar(entry))
|
|
2951
2974
|
fields.push(
|
|
2952
|
-
createEntry(`<span class="grammar grammar-point">${entry.point}</span>`)
|
|
2975
|
+
`${customData !== void 0 ? `<div id="custom-data" style="display: none" data-custom="${customData}"></div>` : ""}${createEntry(`<span class="grammar grammar-point">${entry.point}</span>`)}`,
|
|
2953
2976
|
entry.readings !== void 0 ? entry.readings.map(
|
|
2954
2977
|
(readingEntry) => createEntry(
|
|
2955
2978
|
`<span class="grammar grammar-reading">${readingEntry.reading}</span>`
|
|
@@ -2979,7 +3002,7 @@ function generateAnkiNote(entry) {
|
|
|
2979
3002
|
);
|
|
2980
3003
|
return fields.map((field) => field.replaceAll("\n", "<br>"));
|
|
2981
3004
|
}
|
|
2982
|
-
function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
3005
|
+
function generateAnkiNotesFile(list, defaultNoteInfo, customData) {
|
|
2983
3006
|
const headers = [noteHeaderKeys.separator, noteHeaderKeys.html];
|
|
2984
3007
|
let ankiNotes = "";
|
|
2985
3008
|
if (list.length > 0) {
|
|
@@ -3029,7 +3052,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
3029
3052
|
headers.push(`${noteHeaderKeys.deck}${++headerCount}`);
|
|
3030
3053
|
hasHeader.deckPath = true;
|
|
3031
3054
|
}
|
|
3032
|
-
const note = generateAnkiNote(result);
|
|
3055
|
+
const note = generateAnkiNote(result, customData);
|
|
3033
3056
|
if (!hasHeader.tags) {
|
|
3034
3057
|
headers.push(`${noteHeaderKeys.tags}${note.length + headerCount}`);
|
|
3035
3058
|
hasHeader.tags = true;
|