@intlayer/chokidar 8.12.5-canary.0 → 9.0.0-canary.1
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/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +21 -4
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +94 -0
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -1
- package/dist/cjs/createType/createType.cjs.map +1 -1
- package/dist/cjs/docReview/alignBlocks.cjs +79 -0
- package/dist/cjs/docReview/alignBlocks.cjs.map +1 -0
- package/dist/cjs/docReview/computeSimilarity.cjs +42 -0
- package/dist/cjs/docReview/computeSimilarity.cjs.map +1 -0
- package/dist/cjs/docReview/fingerprintBlock.cjs +35 -0
- package/dist/cjs/docReview/fingerprintBlock.cjs.map +1 -0
- package/dist/cjs/docReview/index.cjs +25 -0
- package/dist/cjs/docReview/mapChangedLinesToBlocks.cjs +27 -0
- package/dist/cjs/docReview/mapChangedLinesToBlocks.cjs.map +1 -0
- package/dist/cjs/docReview/normalizeBlock.cjs +34 -0
- package/dist/cjs/docReview/normalizeBlock.cjs.map +1 -0
- package/dist/cjs/docReview/pipeline.cjs +144 -0
- package/dist/cjs/docReview/pipeline.cjs.map +1 -0
- package/dist/cjs/docReview/planActions.cjs +58 -0
- package/dist/cjs/docReview/planActions.cjs.map +1 -0
- package/dist/cjs/docReview/rebuildDocument.cjs +65 -0
- package/dist/cjs/docReview/rebuildDocument.cjs.map +1 -0
- package/dist/cjs/docReview/reviewReport.cjs +200 -0
- package/dist/cjs/docReview/reviewReport.cjs.map +1 -0
- package/dist/cjs/docReview/segmentDocument.cjs +134 -0
- package/dist/cjs/docReview/segmentDocument.cjs.map +1 -0
- package/dist/cjs/docReview/types.cjs +0 -0
- package/dist/cjs/init/index.cjs +80 -9
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/init/utils/configManipulation.cjs +196 -0
- package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
- package/dist/cjs/init/utils/fileSystem.cjs +84 -0
- package/dist/cjs/init/utils/fileSystem.cjs.map +1 -1
- package/dist/cjs/init/utils/githubActions.cjs +159 -0
- package/dist/cjs/init/utils/githubActions.cjs.map +1 -0
- package/dist/cjs/init/utils/index.cjs +16 -0
- package/dist/cjs/init/utils/packageManager.cjs +187 -0
- package/dist/cjs/init/utils/packageManager.cjs.map +1 -0
- package/dist/cjs/scan/analyzeBundleContent.cjs +182 -0
- package/dist/cjs/scan/analyzeBundleContent.cjs.map +1 -0
- package/dist/cjs/scan/calculateScore.cjs +65 -0
- package/dist/cjs/scan/calculateScore.cjs.map +1 -0
- package/dist/cjs/scan/checks.cjs +274 -0
- package/dist/cjs/scan/checks.cjs.map +1 -0
- package/dist/cjs/scan/index.cjs +31 -0
- package/dist/cjs/scan/parseHtml.cjs +127 -0
- package/dist/cjs/scan/parseHtml.cjs.map +1 -0
- package/dist/cjs/scan/scanWebsite.cjs +205 -0
- package/dist/cjs/scan/scanWebsite.cjs.map +1 -0
- package/dist/cjs/scan/types.cjs +0 -0
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +22 -5
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +93 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -1
- package/dist/esm/createType/createType.mjs.map +1 -1
- package/dist/esm/docReview/alignBlocks.mjs +78 -0
- package/dist/esm/docReview/alignBlocks.mjs.map +1 -0
- package/dist/esm/docReview/computeSimilarity.mjs +39 -0
- package/dist/esm/docReview/computeSimilarity.mjs.map +1 -0
- package/dist/esm/docReview/fingerprintBlock.mjs +32 -0
- package/dist/esm/docReview/fingerprintBlock.mjs.map +1 -0
- package/dist/esm/docReview/index.mjs +12 -0
- package/dist/esm/docReview/mapChangedLinesToBlocks.mjs +25 -0
- package/dist/esm/docReview/mapChangedLinesToBlocks.mjs.map +1 -0
- package/dist/esm/docReview/normalizeBlock.mjs +32 -0
- package/dist/esm/docReview/normalizeBlock.mjs.map +1 -0
- package/dist/esm/docReview/pipeline.mjs +142 -0
- package/dist/esm/docReview/pipeline.mjs.map +1 -0
- package/dist/esm/docReview/planActions.mjs +56 -0
- package/dist/esm/docReview/planActions.mjs.map +1 -0
- package/dist/esm/docReview/rebuildDocument.mjs +62 -0
- package/dist/esm/docReview/rebuildDocument.mjs.map +1 -0
- package/dist/esm/docReview/reviewReport.mjs +196 -0
- package/dist/esm/docReview/reviewReport.mjs.map +1 -0
- package/dist/esm/docReview/segmentDocument.mjs +131 -0
- package/dist/esm/docReview/segmentDocument.mjs.map +1 -0
- package/dist/esm/docReview/types.mjs +0 -0
- package/dist/esm/init/index.mjs +82 -11
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/init/utils/configManipulation.mjs +190 -1
- package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
- package/dist/esm/init/utils/fileSystem.mjs +83 -1
- package/dist/esm/init/utils/fileSystem.mjs.map +1 -1
- package/dist/esm/init/utils/githubActions.mjs +155 -0
- package/dist/esm/init/utils/githubActions.mjs.map +1 -0
- package/dist/esm/init/utils/index.mjs +5 -3
- package/dist/esm/init/utils/packageManager.mjs +183 -0
- package/dist/esm/init/utils/packageManager.mjs.map +1 -0
- package/dist/esm/scan/analyzeBundleContent.mjs +180 -0
- package/dist/esm/scan/analyzeBundleContent.mjs.map +1 -0
- package/dist/esm/scan/calculateScore.mjs +61 -0
- package/dist/esm/scan/calculateScore.mjs.map +1 -0
- package/dist/esm/scan/checks.mjs +265 -0
- package/dist/esm/scan/checks.mjs.map +1 -0
- package/dist/esm/scan/index.mjs +7 -0
- package/dist/esm/scan/parseHtml.mjs +115 -0
- package/dist/esm/scan/parseHtml.mjs.map +1 -0
- package/dist/esm/scan/scanWebsite.mjs +203 -0
- package/dist/esm/scan/scanWebsite.mjs.map +1 -0
- package/dist/esm/scan/types.mjs +0 -0
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +31 -4
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +13 -3
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/createType/createType.d.ts +3 -3
- package/dist/types/createType/createType.d.ts.map +1 -1
- package/dist/types/docReview/alignBlocks.d.ts +18 -0
- package/dist/types/docReview/alignBlocks.d.ts.map +1 -0
- package/dist/types/docReview/computeSimilarity.d.ts +22 -0
- package/dist/types/docReview/computeSimilarity.d.ts.map +1 -0
- package/dist/types/docReview/fingerprintBlock.d.ts +18 -0
- package/dist/types/docReview/fingerprintBlock.d.ts.map +1 -0
- package/dist/types/docReview/index.d.ts +12 -0
- package/dist/types/docReview/mapChangedLinesToBlocks.d.ts +15 -0
- package/dist/types/docReview/mapChangedLinesToBlocks.d.ts.map +1 -0
- package/dist/types/docReview/normalizeBlock.d.ts +18 -0
- package/dist/types/docReview/normalizeBlock.d.ts.map +1 -0
- package/dist/types/docReview/pipeline.d.ts +46 -0
- package/dist/types/docReview/pipeline.d.ts.map +1 -0
- package/dist/types/docReview/planActions.d.ts +18 -0
- package/dist/types/docReview/planActions.d.ts.map +1 -0
- package/dist/types/docReview/rebuildDocument.d.ts +46 -0
- package/dist/types/docReview/rebuildDocument.d.ts.map +1 -0
- package/dist/types/docReview/reviewReport.d.ts +82 -0
- package/dist/types/docReview/reviewReport.d.ts.map +1 -0
- package/dist/types/docReview/segmentDocument.d.ts +40 -0
- package/dist/types/docReview/segmentDocument.d.ts.map +1 -0
- package/dist/types/docReview/types.d.ts +73 -0
- package/dist/types/docReview/types.d.ts.map +1 -0
- package/dist/types/formatDictionary.d.ts +6 -0
- package/dist/types/formatDictionary.d.ts.map +1 -1
- package/dist/types/init/index.d.ts +2 -1
- package/dist/types/init/index.d.ts.map +1 -1
- package/dist/types/init/utils/configManipulation.d.ts +42 -1
- package/dist/types/init/utils/configManipulation.d.ts.map +1 -1
- package/dist/types/init/utils/fileSystem.d.ts +31 -1
- package/dist/types/init/utils/fileSystem.d.ts.map +1 -1
- package/dist/types/init/utils/githubActions.d.ts +19 -0
- package/dist/types/init/utils/githubActions.d.ts.map +1 -0
- package/dist/types/init/utils/index.d.ts +5 -3
- package/dist/types/init/utils/packageManager.d.ts +59 -0
- package/dist/types/init/utils/packageManager.d.ts.map +1 -0
- package/dist/types/scan/analyzeBundleContent.d.ts +16 -0
- package/dist/types/scan/analyzeBundleContent.d.ts.map +1 -0
- package/dist/types/scan/calculateScore.d.ts +65 -0
- package/dist/types/scan/calculateScore.d.ts.map +1 -0
- package/dist/types/scan/checks.d.ts +38 -0
- package/dist/types/scan/checks.d.ts.map +1 -0
- package/dist/types/scan/index.d.ts +7 -0
- package/dist/types/scan/parseHtml.d.ts +54 -0
- package/dist/types/scan/parseHtml.d.ts.map +1 -0
- package/dist/types/scan/scanWebsite.d.ts +18 -0
- package/dist/types/scan/scanWebsite.d.ts.map +1 -0
- package/dist/types/scan/types.d.ts +76 -0
- package/dist/types/scan/types.d.ts.map +1 -0
- package/package.json +26 -10
|
@@ -5,7 +5,9 @@ const require_buildIntlayerDictionary_writeDynamicDictionary = require('./writeD
|
|
|
5
5
|
const require_buildIntlayerDictionary_writeFetchDictionary = require('./writeFetchDictionary.cjs');
|
|
6
6
|
const require_buildIntlayerDictionary_writeMergedDictionary = require('./writeMergedDictionary.cjs');
|
|
7
7
|
const require_buildIntlayerDictionary_writeUnmergedDictionary = require('./writeUnmergedDictionary.cjs');
|
|
8
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
8
9
|
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
10
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
9
11
|
|
|
10
12
|
//#region src/buildIntlayerDictionary/buildIntlayerDictionary.ts
|
|
11
13
|
const defaultOptions = {
|
|
@@ -28,22 +30,37 @@ const buildDictionary = async (localDictionariesEntries, configuration, options)
|
|
|
28
30
|
for (const dictionaryToWrite of localDictionariesEntries) {
|
|
29
31
|
const allPrebuiltUnmergedDictionaries = prevUnmergedDictionaries[dictionaryToWrite.key];
|
|
30
32
|
if (allPrebuiltUnmergedDictionaries?.length > 0) {
|
|
31
|
-
const otherUnmergedDictionaries = allPrebuiltUnmergedDictionaries
|
|
32
|
-
unmergedDictionariesToUpdate.push(...otherUnmergedDictionaries);
|
|
33
|
+
const otherUnmergedDictionaries = allPrebuiltUnmergedDictionaries?.filter((unmergedDictionary) => unmergedDictionary.localId !== dictionaryToWrite.localId);
|
|
34
|
+
unmergedDictionariesToUpdate.push(...otherUnmergedDictionaries ?? []);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
const unmergedDictionaries = await require_buildIntlayerDictionary_writeUnmergedDictionary.writeUnmergedDictionaries(unmergedDictionariesToUpdate, configuration, env);
|
|
37
39
|
const mergedDictionaries = await require_buildIntlayerDictionary_writeMergedDictionary.writeMergedDictionaries(unmergedDictionaries, configuration);
|
|
38
40
|
const dictionariesToBuildDynamic = {};
|
|
41
|
+
const qualifiedDictionariesToBuildDynamic = {};
|
|
39
42
|
const keysToBuildFetch = /* @__PURE__ */ new Set();
|
|
40
43
|
for (const [key, mergedResult] of Object.entries(mergedDictionaries)) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
44
|
+
const dictionary = mergedResult.dictionary;
|
|
45
|
+
if ((0, _intlayer_core_dictionaryManipulator.isQualifiedDictionaryGroup)(dictionary)) {
|
|
46
|
+
const entryMode = dictionary.importMode ?? importMode;
|
|
47
|
+
if (entryMode === "dynamic") qualifiedDictionariesToBuildDynamic[key] = {
|
|
48
|
+
dictionaryPath: mergedResult.dictionaryPath,
|
|
49
|
+
dictionary
|
|
50
|
+
};
|
|
51
|
+
else if (entryMode === "fetch") (0, _intlayer_config_logger.getAppLogger)(configuration)(`Dictionary ${(0, _intlayer_config_logger.colorizeKey)(key)} uses 'fetch' import mode with (${dictionary.qualifierTypes.join(", ")}) entries — fetch mode is not qualifier-aware yet, falling back to static import.`, { level: "warn" });
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const mode = dictionary.importMode ?? importMode;
|
|
55
|
+
if (mode === "dynamic" || mode === "fetch") dictionariesToBuildDynamic[key] = {
|
|
56
|
+
dictionaryPath: mergedResult.dictionaryPath,
|
|
57
|
+
dictionary
|
|
58
|
+
};
|
|
43
59
|
if (mode === "fetch") keysToBuildFetch.add(key);
|
|
44
60
|
}
|
|
45
61
|
let dynamicDictionaries = null;
|
|
46
62
|
if (Object.keys(dictionariesToBuildDynamic).length > 0) dynamicDictionaries = await require_buildIntlayerDictionary_writeDynamicDictionary.writeDynamicDictionary(dictionariesToBuildDynamic, configuration, formats);
|
|
63
|
+
if (Object.keys(qualifiedDictionariesToBuildDynamic).length > 0) await require_buildIntlayerDictionary_writeDynamicDictionary.writeDynamicQualifiedDictionaries(qualifiedDictionariesToBuildDynamic, configuration, formats);
|
|
47
64
|
let fetchDictionaries = null;
|
|
48
65
|
if (dynamicDictionaries && keysToBuildFetch.size > 0) {
|
|
49
66
|
const dictionariesToBuildFetch = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildIntlayerDictionary.cjs","names":["OUTPUT_FORMAT","IMPORT_MODE","readDictionariesFromDisk","writeUnmergedDictionaries","writeMergedDictionaries","writeDynamicDictionary","writeFetchDictionary"],"sources":["../../../src/buildIntlayerDictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { IMPORT_MODE, OUTPUT_FORMAT } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { readDictionariesFromDisk } from '../utils/readDictionariesFromDisk';\nimport {\n type LocalizedDictionaryOutput,\n writeDynamicDictionary,\n} from './writeDynamicDictionary';\nimport { writeFetchDictionary } from './writeFetchDictionary';\nimport { writeMergedDictionaries
|
|
1
|
+
{"version":3,"file":"buildIntlayerDictionary.cjs","names":["OUTPUT_FORMAT","IMPORT_MODE","readDictionariesFromDisk","writeUnmergedDictionaries","writeMergedDictionaries","writeDynamicDictionary","writeDynamicQualifiedDictionaries","writeFetchDictionary"],"sources":["../../../src/buildIntlayerDictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { IMPORT_MODE, OUTPUT_FORMAT } from '@intlayer/config/defaultValues';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { isQualifiedDictionaryGroup } from '@intlayer/core/dictionaryManipulator';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { readDictionariesFromDisk } from '../utils/readDictionariesFromDisk';\nimport {\n type LocalizedDictionaryOutput,\n type QualifiedMergedDictionaryOutput,\n writeDynamicDictionary,\n writeDynamicQualifiedDictionaries,\n} from './writeDynamicDictionary';\nimport { writeFetchDictionary } from './writeFetchDictionary';\nimport {\n type PlainMergedDictionaryOutput,\n writeMergedDictionaries,\n} from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\nexport type BuildDictionariesOptions = Partial<{\n formats: typeof OUTPUT_FORMAT;\n importOtherDictionaries: boolean;\n env: 'prod' | 'dev';\n}>;\n\nconst defaultOptions = {\n formats: OUTPUT_FORMAT,\n importOtherDictionaries: true,\n env: 'dev',\n} as const satisfies BuildDictionariesOptions;\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildDictionary = async (\n localDictionariesEntries: Dictionary[],\n configuration: IntlayerConfig,\n options?: BuildDictionariesOptions\n) => {\n const importMode =\n configuration?.build?.importMode ??\n configuration?.dictionary?.importMode ??\n IMPORT_MODE;\n\n const { importOtherDictionaries, env, formats } = {\n ...defaultOptions,\n ...options,\n };\n\n const unmergedDictionariesToUpdate: Dictionary[] = [\n ...localDictionariesEntries,\n ];\n\n if (importOtherDictionaries) {\n const prevUnmergedDictionaries: Record<string, Dictionary[]> =\n readDictionariesFromDisk(configuration.system.unmergedDictionariesDir);\n\n // Reinsert other dictionaries with the same key to avoid merging errors\n for (const dictionaryToWrite of localDictionariesEntries) {\n const allPrebuiltUnmergedDictionaries =\n prevUnmergedDictionaries[dictionaryToWrite.key]!;\n\n if (allPrebuiltUnmergedDictionaries?.length > 0) {\n // Do not add the same dictionary again by filtering out the one with the same localId\n const otherUnmergedDictionaries =\n allPrebuiltUnmergedDictionaries?.filter(\n (unmergedDictionary) =>\n unmergedDictionary.localId !== dictionaryToWrite.localId\n );\n\n unmergedDictionariesToUpdate.push(...(otherUnmergedDictionaries ?? []));\n }\n }\n }\n\n const unmergedDictionaries = await writeUnmergedDictionaries(\n unmergedDictionariesToUpdate,\n configuration,\n env\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n const dictionariesToBuildDynamic: PlainMergedDictionaryOutput = {};\n const qualifiedDictionariesToBuildDynamic: QualifiedMergedDictionaryOutput =\n {};\n const keysToBuildFetch = new Set<string>();\n\n for (const [key, mergedResult] of Object.entries(mergedDictionaries)) {\n const dictionary = mergedResult.dictionary;\n\n if (isQualifiedDictionaryGroup(dictionary)) {\n // Collections / variants / meta records resolve their qualifier at\n // runtime from a selector. Static mode keeps every entry in one JSON;\n // dynamic mode splits them into one chunk per (locale, qualifierId).\n const entryMode = dictionary.importMode ?? importMode;\n\n if (entryMode === 'dynamic') {\n qualifiedDictionariesToBuildDynamic[key] = {\n dictionaryPath: mergedResult.dictionaryPath,\n dictionary,\n };\n } else if (entryMode === 'fetch') {\n const appLogger = getAppLogger(configuration);\n appLogger(\n `Dictionary ${colorizeKey(key)} uses 'fetch' import mode with (${dictionary.qualifierTypes.join(', ')}) entries — fetch mode is not qualifier-aware yet, falling back to static import.`,\n { level: 'warn' }\n );\n }\n\n continue;\n }\n\n const mode = dictionary.importMode ?? importMode;\n\n if (mode === 'dynamic' || mode === 'fetch') {\n dictionariesToBuildDynamic[key] = {\n dictionaryPath: mergedResult.dictionaryPath,\n dictionary,\n };\n }\n\n if (mode === 'fetch') {\n keysToBuildFetch.add(key);\n }\n }\n\n let dynamicDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (Object.keys(dictionariesToBuildDynamic).length > 0) {\n dynamicDictionaries = await writeDynamicDictionary(\n dictionariesToBuildDynamic,\n configuration,\n formats\n );\n }\n\n if (Object.keys(qualifiedDictionariesToBuildDynamic).length > 0) {\n await writeDynamicQualifiedDictionaries(\n qualifiedDictionariesToBuildDynamic,\n configuration,\n formats\n );\n }\n\n let fetchDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (dynamicDictionaries && keysToBuildFetch.size > 0) {\n const dictionariesToBuildFetch: LocalizedDictionaryOutput = {};\n\n for (const key of keysToBuildFetch) {\n if (dynamicDictionaries[key]) {\n dictionariesToBuildFetch[key] = dynamicDictionaries[key];\n }\n }\n\n if (Object.keys(dictionariesToBuildFetch).length > 0) {\n fetchDictionaries = await writeFetchDictionary(\n dictionariesToBuildFetch,\n configuration,\n formats\n );\n }\n }\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n fetchDictionaries,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,iBAAiB;CACrB,SAASA;CACT,yBAAyB;CACzB,KAAK;CACN;;;;AAKD,MAAa,kBAAkB,OAC7B,0BACA,eACA,YACG;CACH,M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MAAMC,8EAC1B,4BACA,eACA,QACD;AAGH,KAAI,OAAO,KAAK,oCAAoC,CAAC,SAAS,EAC5D,OAAMC,yFACJ,qCACA,eACA,QACD;CAGH,IAAI,oBAAsD;AAE1D,KAAI,uBAAuB,iBAAiB,OAAO,GAAG;EACpD,MAAM,2BAAsD,EAAE;AAE9D,OAAK,MAAM,OAAO,iBAChB,KAAI,oBAAoB,KACtB,0BAAyB,OAAO,oBAAoB;AAIxD,MAAI,OAAO,KAAK,yBAAyB,CAAC,SAAS,EACjD,qBAAoB,MAAMC,0EACxB,0BACA,eACA,QACD;;AAIL,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -8,6 +8,7 @@ let node_path = require("node:path");
|
|
|
8
8
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
9
9
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
10
10
|
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
11
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
11
12
|
let _intlayer_core_plugins = require("@intlayer/core/plugins");
|
|
12
13
|
|
|
13
14
|
//#region src/buildIntlayerDictionary/writeDynamicDictionary.ts
|
|
@@ -20,6 +21,51 @@ const generateDictionaryEntryPoint = (key, locales, format = "esm") => {
|
|
|
20
21
|
if (format === "esm") return `const content = {\n${localeEntries}\n};\n\nexport default content;\n`;
|
|
21
22
|
return `module.exports = {\n${localeEntries}\n};\n`;
|
|
22
23
|
};
|
|
24
|
+
const buildLoaderExpression = (key, segments, locale, format) => {
|
|
25
|
+
const path = `./${DICTIONARIES_SUBDIR}/${key}/${segments.join("/")}/${locale}.json`;
|
|
26
|
+
return format === "esm" ? `() => import('${path}').then(m => m.default)` : `() => Promise.resolve(require('${path}'))`;
|
|
27
|
+
};
|
|
28
|
+
const buildLoaderTree = (key, entriesSegments, locale, format) => {
|
|
29
|
+
const root = {};
|
|
30
|
+
for (const segments of entriesSegments) {
|
|
31
|
+
let node = root;
|
|
32
|
+
segments.forEach((segment, index) => {
|
|
33
|
+
if (index === segments.length - 1) {
|
|
34
|
+
node[segment] = buildLoaderExpression(key, segments, locale, format);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
node[segment] = node[segment] ?? {};
|
|
38
|
+
node = node[segment];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return root;
|
|
42
|
+
};
|
|
43
|
+
const serializeLoaderTree = (tree, indentLevel) => {
|
|
44
|
+
const pad = " ".repeat(indentLevel);
|
|
45
|
+
const innerPad = " ".repeat(indentLevel + 1);
|
|
46
|
+
return `{\n${Object.keys(tree).sort((a, b) => a.localeCompare(b)).map((segment) => {
|
|
47
|
+
const value = tree[segment];
|
|
48
|
+
return `${innerPad}'${segment}': ${typeof value === "string" ? value : serializeLoaderTree(value, indentLevel + 1)}`;
|
|
49
|
+
}).join(",\n")}\n${pad}}`;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Generates the entry point of a qualified dictionary (collection / variant /
|
|
53
|
+
* meta record, possibly combined). Under each locale the loader map nests one
|
|
54
|
+
* level per declared dimension (canonical order) and carries a marker listing
|
|
55
|
+
* those dimensions so the runtime can walk the tree.
|
|
56
|
+
*
|
|
57
|
+
* One static `import()` is emitted per leaf `(locale, …segments)` chunk, which
|
|
58
|
+
* keeps the output compatible with bundlers that reject template-literal
|
|
59
|
+
* dynamic imports (Turbopack).
|
|
60
|
+
*/
|
|
61
|
+
const generateQualifiedDictionaryEntryPoint = (key, qualifierTypes, entriesSegments, locales, format = "esm") => {
|
|
62
|
+
const localeEntries = [...locales].sort((a, b) => String(a).localeCompare(String(b))).map((locale) => {
|
|
63
|
+
return ` '${locale}': ${serializeLoaderTree(buildLoaderTree(key, entriesSegments, locale, format), 1)}`;
|
|
64
|
+
}).join(",\n");
|
|
65
|
+
const marker = ` '${_intlayer_core_dictionaryManipulator.QUALIFIER_DYNAMIC_TYPES_KEY}': ${JSON.stringify(qualifierTypes)}`;
|
|
66
|
+
if (format === "esm") return `const content = {\n${marker},\n${localeEntries}\n};\n\nexport default content;\n`;
|
|
67
|
+
return `module.exports = {\n${marker},\n${localeEntries}\n};\n`;
|
|
68
|
+
};
|
|
23
69
|
/**
|
|
24
70
|
* Write the localized dictionaries to the dictionariesDir
|
|
25
71
|
* @param mergedDictionaries - The merged dictionaries
|
|
@@ -72,8 +118,56 @@ const writeDynamicDictionary = async (mergedDictionaries, configuration, formats
|
|
|
72
118
|
});
|
|
73
119
|
return resultDictionariesPaths;
|
|
74
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* Writes the dynamic chunks and entry points of qualified dictionaries
|
|
123
|
+
* (collections, variants, meta records — possibly combined) in
|
|
124
|
+
* `importMode: 'dynamic'`.
|
|
125
|
+
*
|
|
126
|
+
* Each entry is reduced to one per-locale chunk written to a path nested by
|
|
127
|
+
* dimension — `json/{key}/{seg1}/{seg2}/{locale}.json` — and a single
|
|
128
|
+
* `{key}.{ext}` entry point exposes the matching nested loader tree, so the
|
|
129
|
+
* entry point is discovered and aggregated exactly like a plain dynamic one.
|
|
130
|
+
*/
|
|
131
|
+
const writeDynamicQualifiedDictionaries = async (qualifiedDictionaries, configuration, formats = _intlayer_config_defaultValues.OUTPUT_FORMAT) => {
|
|
132
|
+
const { locales, defaultLocale } = configuration.internationalization;
|
|
133
|
+
const { dynamicDictionariesDir } = configuration.system;
|
|
134
|
+
const dictDir = (0, node_path.resolve)(dynamicDictionariesDir, DICTIONARIES_SUBDIR);
|
|
135
|
+
await (0, node_fs_promises.mkdir)(dictDir, { recursive: true });
|
|
136
|
+
await require_utils_parallelize.parallelize(Object.entries(qualifiedDictionaries).sort(([a], [b]) => String(a).localeCompare(String(b))), async ([key, { dictionary: group }]) => {
|
|
137
|
+
if (key === "undefined") return;
|
|
138
|
+
const entryIds = Object.keys(group.content);
|
|
139
|
+
const keyDir = (0, node_path.resolve)(dictDir, key);
|
|
140
|
+
(0, _intlayer_config_utils.assertPathWithin)(keyDir, dictDir);
|
|
141
|
+
const entriesSegments = [];
|
|
142
|
+
await require_utils_parallelize.parallelize(entryIds, async (entryId) => {
|
|
143
|
+
const entry = (0, _intlayer_core_dictionaryManipulator.reconstructQualifiedEntry)(group, entryId);
|
|
144
|
+
const segments = entryId.split(_intlayer_core_dictionaryManipulator.COMPOSITE_ID_SEPARATOR);
|
|
145
|
+
entriesSegments.push(segments);
|
|
146
|
+
const entryDir = (0, node_path.resolve)(keyDir, ...segments);
|
|
147
|
+
(0, _intlayer_config_utils.assertPathWithin)(entryDir, keyDir);
|
|
148
|
+
await (0, node_fs_promises.mkdir)(entryDir, { recursive: true });
|
|
149
|
+
await require_utils_parallelize.parallelize(locales, async (locale) => {
|
|
150
|
+
const localizedDictionary = (0, _intlayer_core_plugins.getPerLocaleDictionary)(entry, locale, defaultLocale);
|
|
151
|
+
await require_writeJsonIfChanged.writeJsonIfChanged((0, node_path.resolve)(entryDir, `${locale}.json`), localizedDictionary).catch((err) => {
|
|
152
|
+
console.error(`Error creating localized ${key}/${segments.join("/")}/${locale}.json:`, err);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
await require_utils_parallelize.parallelize(formats, async (format) => {
|
|
157
|
+
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
158
|
+
const content = generateQualifiedDictionaryEntryPoint(key, group.qualifierTypes, entriesSegments, locales, format);
|
|
159
|
+
const dynEntryPath = (0, node_path.resolve)(dynamicDictionariesDir, `${key}.${extension}`);
|
|
160
|
+
(0, _intlayer_config_utils.assertPathWithin)(dynEntryPath, dynamicDictionariesDir);
|
|
161
|
+
await require_writeFileIfChanged.writeFileIfChanged(dynEntryPath, content).catch((err) => {
|
|
162
|
+
console.error(`Error creating dynamic ${(0, _intlayer_config_logger.colorizePath)(dynEntryPath)}:`, err);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
75
167
|
|
|
76
168
|
//#endregion
|
|
77
169
|
exports.generateDictionaryEntryPoint = generateDictionaryEntryPoint;
|
|
170
|
+
exports.generateQualifiedDictionaryEntryPoint = generateQualifiedDictionaryEntryPoint;
|
|
78
171
|
exports.writeDynamicDictionary = writeDynamicDictionary;
|
|
172
|
+
exports.writeDynamicQualifiedDictionaries = writeDynamicQualifiedDictionaries;
|
|
79
173
|
//# sourceMappingURL=writeDynamicDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeDynamicDictionary.cjs","names":["OUTPUT_FORMAT","parallelize","writeJsonIfChanged","writeFileIfChanged"],"sources":["../../../src/buildIntlayerDictionary/writeDynamicDictionary.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { OUTPUT_FORMAT } from '@intlayer/config/defaultValues';\nimport { colorizePath } from '@intlayer/config/logger';\nimport { assertPathWithin } from '@intlayer/config/utils';\nimport { getPerLocaleDictionary } from '@intlayer/core/plugins';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\nimport type { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locale, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\n\nconst DICTIONARIES_SUBDIR = 'json'; // Necessary to add a static first dir for Turbopack\n\n/**\n * Generates the content of a dictionary entry point file.\n */\nexport const generateDictionaryEntryPoint = (\n key: string,\n locales: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n const sortedLocales = [...locales].sort((a, b) =>\n String(a).localeCompare(String(b))\n );\n\n const localeEntries = sortedLocales\n .map((locale) =>\n format === 'esm'\n ? ` '${locale}': () => import('./${DICTIONARIES_SUBDIR}/${key}/${locale}.json').then(m => m.default)`\n : ` '${locale}': () => Promise.resolve(require('./${DICTIONARIES_SUBDIR}/${key}/${locale}.json'))`\n )\n .join(',\\n');\n\n if (format === 'esm') {\n return (\n `const content = {\\n${localeEntries}\\n};\\n\\n` +\n `export default content;\\n`\n );\n }\n return `module.exports = {\\n${localeEntries}\\n};\\n`;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dynamic_dictionary/dictionaries/en_home.json\n * // .intlayer/dynamic_dictionary/dictionaries/fr_home.json\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration: IntlayerConfig,\n formats: ('cjs' | 'esm')[] = OUTPUT_FORMAT\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.system;\n\n const dictDir = resolve(dynamicDictionariesDir, DICTIONARIES_SUBDIR);\n await mkdir(dictDir, { recursive: true });\n\n const resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n Object.entries(mergedDictionaries).sort(([a], [b]) =>\n String(a).localeCompare(String(b))\n ),\n async ([key, dictionaryEntry]) => {\n if (key === 'undefined') return;\n\n const localizedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n const keyDir = resolve(dictDir, key);\n assertPathWithin(keyDir, dictDir);\n await mkdir(keyDir, { recursive: true });\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = getPerLocaleDictionary(\n dictionaryEntry.dictionary,\n locale,\n defaultLocale\n );\n\n // Directory structure: json/key/locale.json\n const resultFilePath = resolve(keyDir, `${locale}.json`);\n\n await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(\n (err) => {\n console.error(\n `Error creating localized ${key}/${locale}.json:`,\n err\n );\n }\n );\n\n localizedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n });\n\n resultDictionariesPaths[key] = localizedDictionariesPathsRecord;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(key, locales, format);\n\n const dynEntryPath = resolve(\n dynamicDictionariesDir,\n `${key}.${extension}`\n );\n assertPathWithin(dynEntryPath, dynamicDictionariesDir);\n\n await writeFileIfChanged(dynEntryPath, content).catch((err) => {\n console.error(\n `Error creating dynamic ${colorizePath(dynEntryPath)}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,sBAAsB;;;;AAK5B,MAAa,gCACX,KACA,SACA,SAAwB,UACb;CAKX,MAAM,gBAJgB,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,MAC1C,OAAO,EAAE,CAAC,cAAc,OAAO,EAAE,CAAC,CAGD,CAChC,KAAK,WACJ,WAAW,QACP,MAAM,OAAO,qBAAqB,oBAAoB,GAAG,IAAI,GAAG,OAAO,gCACvE,MAAM,OAAO,sCAAsC,oBAAoB,GAAG,IAAI,GAAG,OAAO,UAC7F,CACA,KAAK,MAAM;AAEd,KAAI,WAAW,MACb,QACE,sBAAsB,cAAc;AAIxC,QAAO,uBAAuB,cAAc;;;;;;;;;;;;;;;;;;AAmB9C,MAAa,yBAAyB,OACpC,oBACA,eACA,UAA6BA,iDACU;CACvC,MAAM,EAAE,SAAS,kBAAkB,cAAc;CACjD,MAAM,EAAE,2BAA2B,cAAc;CAEjD,MAAM,iCAAkB,wBAAwB,oBAAoB;AACpE,mCAAY,SAAS,EAAE,WAAW,MAAM,CAAC;CAEzC,MAAM,0BAAqD,EAAE;AAG7D,OAAMC,sCACJ,OAAO,QAAQ,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,OAC7C,OAAO,EAAE,CAAC,cAAc,OAAO,EAAE,CAAC,CACnC,EACD,OAAO,CAAC,KAAK,qBAAqB;AAChC,MAAI,QAAQ,YAAa;EAEzB,MAAM,mCAA8D,EAAE;EAEtE,MAAM,gCAAiB,SAAS,IAAI;AACpC,+CAAiB,QAAQ,QAAQ;AACjC,oCAAY,QAAQ,EAAE,WAAW,MAAM,CAAC;AAExC,QAAMA,sCAAY,SAAS,OAAO,WAAW;GAC3C,MAAM,yEACJ,gBAAgB,YAChB,QACA,cACD;GAGD,MAAM,wCAAyB,QAAQ,GAAG,OAAO,OAAO;AAExD,SAAMC,8CAAmB,gBAAgB,oBAAoB,CAAC,OAC3D,QAAQ;AACP,YAAQ,MACN,4BAA4B,IAAI,GAAG,OAAO,SAC1C,IACD;KAEJ;AAED,oCAAiC,UAAU;IACzC,gBAAgB;IAChB,YAAY;IACb;IACD;AAEF,0BAAwB,OAAO;AAE/B,QAAMD,sCAAY,SAAS,OAAO,WAAW;GAC3C,MAAM,YAAY,WAAW,QAAQ,QAAQ;GAC7C,MAAM,UAAU,6BAA6B,KAAK,SAAS,OAAO;GAElE,MAAM,sCACJ,wBACA,GAAG,IAAI,GAAG,YACX;AACD,gDAAiB,cAAc,uBAAuB;AAEtD,SAAME,8CAAmB,cAAc,QAAQ,CAAC,OAAO,QAAQ;AAC7D,YAAQ,MACN,oEAAuC,aAAa,CAAC,IACrD,IACD;KACD;IACF;GAEL;AAED,QAAO"}
|
|
1
|
+
{"version":3,"file":"writeDynamicDictionary.cjs","names":["QUALIFIER_DYNAMIC_TYPES_KEY","OUTPUT_FORMAT","parallelize","writeJsonIfChanged","writeFileIfChanged","COMPOSITE_ID_SEPARATOR"],"sources":["../../../src/buildIntlayerDictionary/writeDynamicDictionary.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { OUTPUT_FORMAT } from '@intlayer/config/defaultValues';\nimport { colorizePath } from '@intlayer/config/logger';\nimport { assertPathWithin } from '@intlayer/config/utils';\nimport {\n COMPOSITE_ID_SEPARATOR,\n QUALIFIER_DYNAMIC_TYPES_KEY,\n reconstructQualifiedEntry,\n} from '@intlayer/core/dictionaryManipulator';\nimport { getPerLocaleDictionary } from '@intlayer/core/plugins';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n Dictionary,\n DictionaryQualifierType,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\nimport type { PlainMergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locale, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\n\nconst DICTIONARIES_SUBDIR = 'json'; // Necessary to add a static first dir for Turbopack\n\n/**\n * Generates the content of a dictionary entry point file.\n */\nexport const generateDictionaryEntryPoint = (\n key: string,\n locales: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n const sortedLocales = [...locales].sort((a, b) =>\n String(a).localeCompare(String(b))\n );\n\n const localeEntries = sortedLocales\n .map((locale) =>\n format === 'esm'\n ? ` '${locale}': () => import('./${DICTIONARIES_SUBDIR}/${key}/${locale}.json').then(m => m.default)`\n : ` '${locale}': () => Promise.resolve(require('./${DICTIONARIES_SUBDIR}/${key}/${locale}.json'))`\n )\n .join(',\\n');\n\n if (format === 'esm') {\n return (\n `const content = {\\n${localeEntries}\\n};\\n\\n` +\n `export default content;\\n`\n );\n }\n return `module.exports = {\\n${localeEntries}\\n};\\n`;\n};\n\n/**\n * A nested loader tree: one level per declared dimension, leaves are loader\n * expression strings.\n */\ntype LoaderTree = { [segment: string]: LoaderTree | string };\n\nconst buildLoaderExpression = (\n key: string,\n segments: string[],\n locale: string,\n format: 'cjs' | 'esm'\n): string => {\n const path = `./${DICTIONARIES_SUBDIR}/${key}/${segments.join('/')}/${locale}.json`;\n\n return format === 'esm'\n ? `() => import('${path}').then(m => m.default)`\n : `() => Promise.resolve(require('${path}'))`;\n};\n\nconst buildLoaderTree = (\n key: string,\n entriesSegments: string[][],\n locale: string,\n format: 'cjs' | 'esm'\n): LoaderTree => {\n const root: LoaderTree = {};\n\n for (const segments of entriesSegments) {\n let node = root;\n\n segments.forEach((segment, index) => {\n if (index === segments.length - 1) {\n node[segment] = buildLoaderExpression(key, segments, locale, format);\n return;\n }\n\n node[segment] = (node[segment] as LoaderTree | undefined) ?? {};\n node = node[segment] as LoaderTree;\n });\n }\n\n return root;\n};\n\nconst serializeLoaderTree = (tree: LoaderTree, indentLevel: number): string => {\n const pad = ' '.repeat(indentLevel);\n const innerPad = ' '.repeat(indentLevel + 1);\n\n const lines = Object.keys(tree)\n .sort((a, b) => a.localeCompare(b))\n .map((segment) => {\n const value = tree[segment]!;\n const serialized =\n typeof value === 'string'\n ? value\n : serializeLoaderTree(value, indentLevel + 1);\n\n return `${innerPad}'${segment}': ${serialized}`;\n });\n\n return `{\\n${lines.join(',\\n')}\\n${pad}}`;\n};\n\n/**\n * Generates the entry point of a qualified dictionary (collection / variant /\n * meta record, possibly combined). Under each locale the loader map nests one\n * level per declared dimension (canonical order) and carries a marker listing\n * those dimensions so the runtime can walk the tree.\n *\n * One static `import()` is emitted per leaf `(locale, …segments)` chunk, which\n * keeps the output compatible with bundlers that reject template-literal\n * dynamic imports (Turbopack).\n */\nexport const generateQualifiedDictionaryEntryPoint = (\n key: string,\n qualifierTypes: DictionaryQualifierType[],\n entriesSegments: string[][],\n locales: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n const sortedLocales = [...locales].sort((a, b) =>\n String(a).localeCompare(String(b))\n );\n\n const localeEntries = sortedLocales\n .map((locale) => {\n const tree = buildLoaderTree(key, entriesSegments, locale, format);\n return ` '${locale}': ${serializeLoaderTree(tree, 1)}`;\n })\n .join(',\\n');\n\n const marker = ` '${QUALIFIER_DYNAMIC_TYPES_KEY}': ${JSON.stringify(qualifierTypes)}`;\n\n if (format === 'esm') {\n return (\n `const content = {\\n${marker},\\n${localeEntries}\\n};\\n\\n` +\n `export default content;\\n`\n );\n }\n return `module.exports = {\\n${marker},\\n${localeEntries}\\n};\\n`;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dynamic_dictionary/dictionaries/en_home.json\n * // .intlayer/dynamic_dictionary/dictionaries/fr_home.json\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: PlainMergedDictionaryOutput,\n configuration: IntlayerConfig,\n formats: ('cjs' | 'esm')[] = OUTPUT_FORMAT\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.system;\n\n const dictDir = resolve(dynamicDictionariesDir, DICTIONARIES_SUBDIR);\n await mkdir(dictDir, { recursive: true });\n\n const resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n Object.entries(mergedDictionaries).sort(([a], [b]) =>\n String(a).localeCompare(String(b))\n ),\n async ([key, dictionaryEntry]) => {\n if (key === 'undefined') return;\n\n const localizedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n const keyDir = resolve(dictDir, key);\n assertPathWithin(keyDir, dictDir);\n await mkdir(keyDir, { recursive: true });\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = getPerLocaleDictionary(\n dictionaryEntry.dictionary,\n locale,\n defaultLocale\n );\n\n // Directory structure: json/key/locale.json\n const resultFilePath = resolve(keyDir, `${locale}.json`);\n\n await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(\n (err) => {\n console.error(\n `Error creating localized ${key}/${locale}.json:`,\n err\n );\n }\n );\n\n localizedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n });\n\n resultDictionariesPaths[key] = localizedDictionariesPathsRecord;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(key, locales, format);\n\n const dynEntryPath = resolve(\n dynamicDictionariesDir,\n `${key}.${extension}`\n );\n assertPathWithin(dynEntryPath, dynamicDictionariesDir);\n\n await writeFileIfChanged(dynEntryPath, content).catch((err) => {\n console.error(\n `Error creating dynamic ${colorizePath(dynEntryPath)}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n\nexport type QualifiedMergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: QualifiedDictionaryGroup;\n};\n\nexport type QualifiedMergedDictionaryOutput = Record<\n string,\n QualifiedMergedDictionaryResult\n>;\n\n/**\n * Writes the dynamic chunks and entry points of qualified dictionaries\n * (collections, variants, meta records — possibly combined) in\n * `importMode: 'dynamic'`.\n *\n * Each entry is reduced to one per-locale chunk written to a path nested by\n * dimension — `json/{key}/{seg1}/{seg2}/{locale}.json` — and a single\n * `{key}.{ext}` entry point exposes the matching nested loader tree, so the\n * entry point is discovered and aggregated exactly like a plain dynamic one.\n */\nexport const writeDynamicQualifiedDictionaries = async (\n qualifiedDictionaries: QualifiedMergedDictionaryOutput,\n configuration: IntlayerConfig,\n formats: ('cjs' | 'esm')[] = OUTPUT_FORMAT\n): Promise<void> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.system;\n\n const dictDir = resolve(dynamicDictionariesDir, DICTIONARIES_SUBDIR);\n await mkdir(dictDir, { recursive: true });\n\n await parallelize(\n Object.entries(qualifiedDictionaries).sort(([a], [b]) =>\n String(a).localeCompare(String(b))\n ),\n async ([key, { dictionary: group }]) => {\n if (key === 'undefined') return;\n\n const entryIds = Object.keys(group.content);\n\n const keyDir = resolve(dictDir, key);\n assertPathWithin(keyDir, dictDir);\n\n // Per-entry segment lists (one segment per declared dimension), reused for\n // both the chunk paths and the generated loader tree.\n const entriesSegments: string[][] = [];\n\n await parallelize(entryIds, async (entryId) => {\n // Rebuild a resolvable dictionary from the content node + composite id\n // so per-locale extraction sees the same `{ key, content, meta? }` shape.\n const entry = reconstructQualifiedEntry(group, entryId);\n\n const segments = entryId.split(COMPOSITE_ID_SEPARATOR);\n entriesSegments.push(segments);\n\n const entryDir = resolve(keyDir, ...segments);\n assertPathWithin(entryDir, keyDir);\n await mkdir(entryDir, { recursive: true });\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = getPerLocaleDictionary(\n entry,\n locale,\n defaultLocale\n );\n\n // Directory structure: json/key/<…segments>/locale.json\n const resultFilePath = resolve(entryDir, `${locale}.json`);\n\n await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(\n (err) => {\n console.error(\n `Error creating localized ${key}/${segments.join('/')}/${locale}.json:`,\n err\n );\n }\n );\n });\n });\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateQualifiedDictionaryEntryPoint(\n key,\n group.qualifierTypes,\n entriesSegments,\n locales,\n format\n );\n\n const dynEntryPath = resolve(\n dynamicDictionariesDir,\n `${key}.${extension}`\n );\n assertPathWithin(dynEntryPath, dynamicDictionariesDir);\n\n await writeFileIfChanged(dynEntryPath, content).catch((err) => {\n console.error(\n `Error creating dynamic ${colorizePath(dynEntryPath)}:`,\n err\n );\n });\n });\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAqCA,MAAM,sBAAsB;;;;AAK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AS;AAC7C,gDAAiB,UAAU,OAAO;AAClC,qCAAY,UAAU,EAAE,WAAW,MAAM,CAAC;AAE1C,SAAMH,sCAAY,SAAS,OAAO,WAAW;IAC3C,MAAM,yEACJ,OACA,QACA,cACD;AAKD,UAAMC,qEAFyB,UAAU,GAAG,OAAO,OAEZ,EAAE,oBAAoB,CAAC,OAC3D,QAAQ;AACP,aAAQ,MACN,4BAA4B,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,OAAO,SAChE,IACD;MAEJ;KACD;IACF;AAEF,QAAMD,sCAAY,SAAS,OAAO,WAAW;GAC3C,MAAM,YAAY,WAAW,QAAQ,QAAQ;GAC7C,MAAM,UAAU,sCACd,KACA,MAAM,gBACN,iBACA,SACA,OACD;GAED,MAAM,sCACJ,wBACA,GAAG,IAAI,GAAG,YACX;AACD,gDAAiB,cAAc,uBAAuB;AAEtD,SAAME,8CAAmB,cAAc,QAAQ,CAAC,OAAO,QAAQ;AAC7D,YAAQ,MACN,oEAAuC,aAAa,CAAC,IACrD,IACD;KACD;IACF;GAEL"}
|
|
@@ -30,7 +30,7 @@ const writeMergedDictionaries = async (groupedDictionaries, configuration) => {
|
|
|
30
30
|
await (0, node_fs_promises.mkdir)((0, node_path.resolve)(dictionariesDir), { recursive: true });
|
|
31
31
|
const results = await require_utils_parallelize.parallelize(Object.entries(groupedDictionaries), async ([key, dictionariesEntry]) => {
|
|
32
32
|
if (key === "undefined") return;
|
|
33
|
-
const mergedDictionary = (0, _intlayer_core_dictionaryManipulator.
|
|
33
|
+
const mergedDictionary = (0, _intlayer_core_dictionaryManipulator.mergeQualifiedDictionaries)((0, _intlayer_core_dictionaryManipulator.normalizeDictionaries)(dictionariesEntry.dictionaries, configuration));
|
|
34
34
|
const resultFilePath = (0, node_path.resolve)(dictionariesDir, `${key}.json`);
|
|
35
35
|
(0, _intlayer_config_utils.assertPathWithin)(resultFilePath, dictionariesDir);
|
|
36
36
|
await require_writeJsonIfChanged.writeJsonIfChanged(resultFilePath, mergedDictionary).catch((err) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeMergedDictionary.cjs","names":["parallelize","writeJsonIfChanged"],"sources":["../../../src/buildIntlayerDictionary/writeMergedDictionary.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { colorizePath } from '@intlayer/config/logger';\nimport { assertPathWithin } from '@intlayer/config/utils';\nimport {\n
|
|
1
|
+
{"version":3,"file":"writeMergedDictionary.cjs","names":["parallelize","writeJsonIfChanged"],"sources":["../../../src/buildIntlayerDictionary/writeMergedDictionary.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { colorizePath } from '@intlayer/config/logger';\nimport { assertPathWithin } from '@intlayer/config/utils';\nimport {\n mergeQualifiedDictionaries,\n normalizeDictionaries,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n Dictionary,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport { parallelize } from '../utils/parallelize';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\nimport type { UnmergedDictionaryOutput } from './writeUnmergedDictionary';\n\nexport type MergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary | QualifiedDictionaryGroup;\n};\n\nexport type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;\n\n/**\n * Merged output restricted to plain (unqualified) dictionaries — qualified\n * groups (collections, variants, meta records) are static-only and filtered\n * out before the dynamic/fetch build steps.\n */\nexport type PlainMergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type PlainMergedDictionaryOutput = Record<\n string,\n PlainMergedDictionaryResult\n>;\n\n/**\n * Write the merged dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The merged dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionary/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeMergedDictionaries = async (\n groupedDictionaries: UnmergedDictionaryOutput,\n configuration: IntlayerConfig\n): Promise<MergedDictionaryOutput> => {\n const { dictionariesDir } = configuration.system;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const results = await parallelize(\n Object.entries(groupedDictionaries),\n async ([key, dictionariesEntry]) => {\n if (key === 'undefined') {\n return undefined as unknown as readonly [\n string,\n MergedDictionaryResult,\n ];\n }\n\n const normalizedDictionaries = normalizeDictionaries(\n dictionariesEntry.dictionaries,\n configuration\n );\n\n const mergedDictionary = mergeQualifiedDictionaries(\n normalizedDictionaries\n );\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n assertPathWithin(resultFilePath, dictionariesDir);\n\n // Write the merged dictionary\n await writeJsonIfChanged(resultFilePath, mergedDictionary).catch(\n (err) => {\n console.error(\n `Error creating merged ${colorizePath(resultFilePath)}:`,\n err\n );\n }\n );\n\n return [\n key,\n {\n dictionaryPath: resultFilePath,\n dictionary: mergedDictionary,\n } as MergedDictionaryResult,\n ] as const;\n }\n );\n\n return Object.fromEntries(\n results.filter(Boolean) as Array<readonly [string, MergedDictionaryResult]>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,0BAA0B,OACrC,qBACA,kBACoC;CACpC,MAAM,EAAE,oBAAoB,cAAc;AAG1C,0DAAoB,gBAAgB,EAAE,EAAE,WAAW,MAAM,CAAC;CAE1D,MAAM,UAAU,MAAMA,sCACpB,OAAO,QAAQ,oBAAoB,EACnC,OAAO,CAAC,KAAK,uBAAuB;AAClC,MAAI,QAAQ,YACV;EAWF,MAAM,wJAJJ,kBAAkB,cAClB,cAIsB,CACvB;EAGD,MAAM,wCAAyB,iBAAiB,GADtB,IAAI,OACiC;AAE/D,+CAAiB,gBAAgB,gBAAgB;AAGjD,QAAMC,8CAAmB,gBAAgB,iBAAiB,CAAC,OACxD,QAAQ;AACP,WAAQ,MACN,mEAAsC,eAAe,CAAC,IACtD,IACD;IAEJ;AAED,SAAO,CACL,KACA;GACE,gBAAgB;GAChB,YAAY;GACb,CACF;GAEJ;AAED,QAAO,OAAO,YACZ,QAAQ,OAAO,QAAQ,CACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createType.cjs","names":["parallelize"],"sources":["../../../src/createType/createType.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {
|
|
1
|
+
{"version":3,"file":"createType.cjs","names":["parallelize"],"sources":["../../../src/createType/createType.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n Dictionary,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport { parallelize } from '../utils/parallelize';\n\nexport const generateTypeScriptType = (\n dictionary: Dictionary | QualifiedDictionaryGroup\n) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionaries: (Dictionary | QualifiedDictionaryGroup)[],\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const { system } = configuration;\n const { typesDir } = system;\n\n // Create type folders if they don't exist\n await mkdir(typesDir, { recursive: true });\n\n const results = await parallelize(\n dictionaries,\n async (dictionary): Promise<string | undefined> => {\n if (!dictionary.key) {\n return undefined;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n await writeFile(outputPath, typeDefinition);\n\n return outputPath;\n }\n );\n\n return results.filter(Boolean) as string[];\n};\n"],"mappings":";;;;;;;AASA,MAAa,0BACX,eACG;AAGH,QAAO,wCAFY,KAAK,UAAU,YAAY,MAAM,EAEK,CAAC;;;;;AAK5D,MAAa,cAAc,OACzB,cACA,kBACsB;CACtB,MAAM,EAAE,WAAW;CACnB,MAAM,EAAE,aAAa;AAGrB,mCAAY,UAAU,EAAE,WAAW,MAAM,CAAC;AAmB1C,SAAO,MAjBeA,sCACpB,cACA,OAAO,eAA4C;AACjD,MAAI,CAAC,WAAW,IACd;EAGF,MAAM,iBAAyB,uBAAuB,WAAW;EAEjE,MAAM,oCAA6B,UAAU,GAAG,WAAW,IAAI,KAAK;AAEpE,wCAAgB,YAAY,eAAe;AAE3C,SAAO;GAEV,EAEc,OAAO,QAAQ"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_docReview_computeSimilarity = require('./computeSimilarity.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/docReview/alignBlocks.ts
|
|
5
|
+
/**
|
|
6
|
+
* Align the blocks of a base document with the blocks of its translation using a
|
|
7
|
+
* Needleman–Wunsch global alignment over anchor similarity and block type.
|
|
8
|
+
*
|
|
9
|
+
* Because prose differs across languages, the score is weighted toward the
|
|
10
|
+
* structural anchor (digits and symbols) rather than the words themselves.
|
|
11
|
+
*
|
|
12
|
+
* @param baseBlocks - Blocks of the base (source) document.
|
|
13
|
+
* @param targetBlocks - Blocks of the target (translated) document.
|
|
14
|
+
* @returns The ordered list of alignment pairs, including insertions and deletions.
|
|
15
|
+
*/
|
|
16
|
+
const alignBaseAndTargetBlocks = (baseBlocks, targetBlocks) => {
|
|
17
|
+
const baseLength = baseBlocks.length;
|
|
18
|
+
const targetLength = targetBlocks.length;
|
|
19
|
+
const scoreMatrix = Array.from({ length: baseLength + 1 }, () => Array.from({ length: targetLength + 1 }, () => 0));
|
|
20
|
+
const traceMatrix = Array.from({ length: baseLength + 1 }, () => Array.from({ length: targetLength + 1 }, () => "diagonal"));
|
|
21
|
+
const gapPenalty = -2;
|
|
22
|
+
const computeMatchScore = (baseIndex, targetIndex) => {
|
|
23
|
+
const baseBlock = baseBlocks[baseIndex];
|
|
24
|
+
const targetBlock = targetBlocks[targetIndex];
|
|
25
|
+
const typeBonus = baseBlock.type === targetBlock.type ? 2 : 0;
|
|
26
|
+
const anchorSimilarity = require_docReview_computeSimilarity.computeJaccardSimilarity(baseBlock.anchorText, targetBlock.anchorText, 3);
|
|
27
|
+
return typeBonus + (Math.min(baseBlock.content.length, targetBlock.content.length) / Math.max(baseBlock.content.length, targetBlock.content.length) > .75 ? 1 : 0) + anchorSimilarity * 8;
|
|
28
|
+
};
|
|
29
|
+
for (let i = 1; i <= baseLength; i += 1) {
|
|
30
|
+
scoreMatrix[i][0] = scoreMatrix[i - 1][0] + gapPenalty;
|
|
31
|
+
traceMatrix[i][0] = "up";
|
|
32
|
+
}
|
|
33
|
+
for (let j = 1; j <= targetLength; j += 1) {
|
|
34
|
+
scoreMatrix[0][j] = scoreMatrix[0][j - 1] + gapPenalty;
|
|
35
|
+
traceMatrix[0][j] = "left";
|
|
36
|
+
}
|
|
37
|
+
for (let i = 1; i <= baseLength; i += 1) for (let j = 1; j <= targetLength; j += 1) {
|
|
38
|
+
const match = scoreMatrix[i - 1][j - 1] + computeMatchScore(i - 1, j - 1);
|
|
39
|
+
const deleteGap = scoreMatrix[i - 1][j] + gapPenalty;
|
|
40
|
+
const insertGap = scoreMatrix[i][j - 1] + gapPenalty;
|
|
41
|
+
const best = Math.max(match, deleteGap, insertGap);
|
|
42
|
+
scoreMatrix[i][j] = best;
|
|
43
|
+
traceMatrix[i][j] = best === match ? "diagonal" : best === deleteGap ? "up" : "left";
|
|
44
|
+
}
|
|
45
|
+
const result = [];
|
|
46
|
+
let i = baseLength;
|
|
47
|
+
let j = targetLength;
|
|
48
|
+
while (i > 0 || j > 0) if (i > 0 && j > 0 && traceMatrix[i][j] === "diagonal") {
|
|
49
|
+
const baseIndex = i - 1;
|
|
50
|
+
const targetIndex = j - 1;
|
|
51
|
+
const similarityScore = require_docReview_computeSimilarity.computeJaccardSimilarity(baseBlocks[baseIndex].anchorText, targetBlocks[targetIndex].anchorText, 3);
|
|
52
|
+
result.unshift({
|
|
53
|
+
baseIndex,
|
|
54
|
+
targetIndex,
|
|
55
|
+
similarityScore
|
|
56
|
+
});
|
|
57
|
+
i -= 1;
|
|
58
|
+
j -= 1;
|
|
59
|
+
} else if (i > 0 && (j === 0 || traceMatrix[i][j] === "up")) {
|
|
60
|
+
result.unshift({
|
|
61
|
+
baseIndex: i - 1,
|
|
62
|
+
targetIndex: null,
|
|
63
|
+
similarityScore: 0
|
|
64
|
+
});
|
|
65
|
+
i -= 1;
|
|
66
|
+
} else if (j > 0 && (i === 0 || traceMatrix[i][j] === "left")) {
|
|
67
|
+
result.unshift({
|
|
68
|
+
baseIndex: -1,
|
|
69
|
+
targetIndex: j - 1,
|
|
70
|
+
similarityScore: 0
|
|
71
|
+
});
|
|
72
|
+
j -= 1;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.alignBaseAndTargetBlocks = alignBaseAndTargetBlocks;
|
|
79
|
+
//# sourceMappingURL=alignBlocks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alignBlocks.cjs","names":["computeJaccardSimilarity"],"sources":["../../../src/docReview/alignBlocks.ts"],"sourcesContent":["import { computeJaccardSimilarity } from './computeSimilarity';\nimport type { AlignmentPair, FingerprintedBlock } from './types';\n\n/**\n * Align the blocks of a base document with the blocks of its translation using a\n * Needleman–Wunsch global alignment over anchor similarity and block type.\n *\n * Because prose differs across languages, the score is weighted toward the\n * structural anchor (digits and symbols) rather than the words themselves.\n *\n * @param baseBlocks - Blocks of the base (source) document.\n * @param targetBlocks - Blocks of the target (translated) document.\n * @returns The ordered list of alignment pairs, including insertions and deletions.\n */\nexport const alignBaseAndTargetBlocks = (\n baseBlocks: FingerprintedBlock[],\n targetBlocks: FingerprintedBlock[]\n): AlignmentPair[] => {\n const baseLength = baseBlocks.length;\n const targetLength = targetBlocks.length;\n\n const scoreMatrix: number[][] = Array.from({ length: baseLength + 1 }, () =>\n Array.from({ length: targetLength + 1 }, () => 0)\n );\n const traceMatrix: ('diagonal' | 'up' | 'left')[][] = Array.from(\n { length: baseLength + 1 },\n () => Array.from({ length: targetLength + 1 }, () => 'diagonal')\n );\n\n const gapPenalty = -2;\n\n const computeMatchScore = (\n baseIndex: number,\n targetIndex: number\n ): number => {\n const baseBlock = baseBlocks[baseIndex];\n const targetBlock = targetBlocks[targetIndex];\n const typeBonus = baseBlock.type === targetBlock.type ? 2 : 0;\n const anchorSimilarity = computeJaccardSimilarity(\n baseBlock.anchorText,\n targetBlock.anchorText,\n 3\n );\n const lengthRatio =\n Math.min(baseBlock.content.length, targetBlock.content.length) /\n Math.max(baseBlock.content.length, targetBlock.content.length);\n const lengthBonus = lengthRatio > 0.75 ? 1 : 0;\n return typeBonus + lengthBonus + anchorSimilarity * 8; // weighted toward anchor similarity\n };\n\n // initialize first row and column\n for (let i = 1; i <= baseLength; i += 1) {\n scoreMatrix[i][0] = scoreMatrix[i - 1][0] + gapPenalty;\n traceMatrix[i][0] = 'up';\n }\n for (let j = 1; j <= targetLength; j += 1) {\n scoreMatrix[0][j] = scoreMatrix[0][j - 1] + gapPenalty;\n traceMatrix[0][j] = 'left';\n }\n\n // fill\n for (let i = 1; i <= baseLength; i += 1) {\n for (let j = 1; j <= targetLength; j += 1) {\n const match = scoreMatrix[i - 1][j - 1] + computeMatchScore(i - 1, j - 1);\n const deleteGap = scoreMatrix[i - 1][j] + gapPenalty;\n const insertGap = scoreMatrix[i][j - 1] + gapPenalty;\n\n const best = Math.max(match, deleteGap, insertGap);\n scoreMatrix[i][j] = best;\n traceMatrix[i][j] =\n best === match ? 'diagonal' : best === deleteGap ? 'up' : 'left';\n }\n }\n\n // traceback\n const result: AlignmentPair[] = [];\n let i = baseLength;\n let j = targetLength;\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && traceMatrix[i][j] === 'diagonal') {\n const baseIndex = i - 1;\n const targetIndex = j - 1;\n const similarityScore = computeJaccardSimilarity(\n baseBlocks[baseIndex].anchorText,\n targetBlocks[targetIndex].anchorText,\n 3\n );\n result.unshift({ baseIndex, targetIndex, similarityScore });\n i -= 1;\n j -= 1;\n } else if (i > 0 && (j === 0 || traceMatrix[i][j] === 'up')) {\n result.unshift({\n baseIndex: i - 1,\n targetIndex: null,\n similarityScore: 0,\n });\n i -= 1;\n } else if (j > 0 && (i === 0 || traceMatrix[i][j] === 'left')) {\n // target block has no corresponding base block (deleted)\n result.unshift({\n baseIndex: -1,\n targetIndex: j - 1,\n similarityScore: 0,\n });\n j -= 1;\n }\n }\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,4BACX,YACA,iBACoB;CACpB,MAAM,aAAa,WAAW;CAC9B,MAAM,eAAe,aAAa;CAElC,MAAM,cAA0B,MAAM,KAAK,EAAE,QAAQ,aAAa,GAAG,QACnE,MAAM,KAAK,EAAE,QAAQ,eAAe,GAAG,QAAQ,EAAE,CAClD;CACD,MAAM,cAAgD,MAAM,KAC1D,EAAE,QAAQ,aAAa,GAAG,QACpB,MAAM,KAAK,EAAE,QAAQ,eAAe,GAAG,QAAQ,WAAW,CACjE;CAED,MAAM,aAAa;CAEnB,MAAM,qBACJ,WACA,gBACW;EACX,MAAM,YAAY,WAAW;EAC7B,MAAM,cAAc,aAAa;EACjC,MAAM,YAAY,UAAU,SAAS,YAAY,OAAO,IAAI;EAC5D,MAAM,mBAAmBA,6DACvB,UAAU,YACV,YAAY,YACZ,EACD;AAKD,SAAO,aAHL,KAAK,IAAI,UAAU,QAAQ,QAAQ,YAAY,QAAQ,OAAO,GAC9D,KAAK,IAAI,UAAU,QAAQ,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,YAAY,GAAG,OAAO,SAAS;AAE7D,SAAO,QAAQ;GACb,WAAW;GACX,aAAa,IAAI;GACjB,iBAAiB;GAClB,CAAC;AACF,OAAK;;AAGT,QAAO"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/docReview/computeSimilarity.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate the set of character shingles (substrings of a fixed length) for a
|
|
6
|
+
* piece of text. Whitespace is collapsed so the result is language agnostic.
|
|
7
|
+
*
|
|
8
|
+
* @param text - The text to shingle.
|
|
9
|
+
* @param shingleLength - The length of each shingle.
|
|
10
|
+
* @returns The set of unique shingles found in the text.
|
|
11
|
+
*/
|
|
12
|
+
const generateCharacterShingles = (text, shingleLength) => {
|
|
13
|
+
const normalized = text.replace(/\s+/g, " ").trim();
|
|
14
|
+
const set = /* @__PURE__ */ new Set();
|
|
15
|
+
if (normalized.length < shingleLength) {
|
|
16
|
+
if (normalized.length > 0) set.add(normalized);
|
|
17
|
+
return set;
|
|
18
|
+
}
|
|
19
|
+
for (let index = 0; index <= normalized.length - shingleLength; index += 1) set.add(normalized.slice(index, index + shingleLength));
|
|
20
|
+
return set;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Compute the Jaccard similarity between two strings using character shingles.
|
|
24
|
+
*
|
|
25
|
+
* @param a - First string.
|
|
26
|
+
* @param b - Second string.
|
|
27
|
+
* @param shingleLength - The shingle length (defaults to 3).
|
|
28
|
+
* @returns A score between 0 (disjoint) and 1 (identical).
|
|
29
|
+
*/
|
|
30
|
+
const computeJaccardSimilarity = (a, b, shingleLength = 3) => {
|
|
31
|
+
const setA = generateCharacterShingles(a, shingleLength);
|
|
32
|
+
const setB = generateCharacterShingles(b, shingleLength);
|
|
33
|
+
if (setA.size === 0 && setB.size === 0) return 1;
|
|
34
|
+
const intersectionSize = Array.from(setA).filter((token) => setB.has(token)).length;
|
|
35
|
+
const unionSize = new Set([...Array.from(setA), ...Array.from(setB)]).size;
|
|
36
|
+
return unionSize === 0 ? 0 : intersectionSize / unionSize;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.computeJaccardSimilarity = computeJaccardSimilarity;
|
|
41
|
+
exports.generateCharacterShingles = generateCharacterShingles;
|
|
42
|
+
//# sourceMappingURL=computeSimilarity.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeSimilarity.cjs","names":[],"sources":["../../../src/docReview/computeSimilarity.ts"],"sourcesContent":["/**\n * Generate the set of character shingles (substrings of a fixed length) for a\n * piece of text. Whitespace is collapsed so the result is language agnostic.\n *\n * @param text - The text to shingle.\n * @param shingleLength - The length of each shingle.\n * @returns The set of unique shingles found in the text.\n */\nexport const generateCharacterShingles = (\n text: string,\n shingleLength: number\n): Set<string> => {\n const normalized = text.replace(/\\s+/g, ' ').trim();\n const set = new Set<string>();\n if (normalized.length < shingleLength) {\n if (normalized.length > 0) {\n set.add(normalized);\n }\n return set;\n }\n for (let index = 0; index <= normalized.length - shingleLength; index += 1) {\n set.add(normalized.slice(index, index + shingleLength));\n }\n return set;\n};\n\n/**\n * Compute the Jaccard similarity between two strings using character shingles.\n *\n * @param a - First string.\n * @param b - Second string.\n * @param shingleLength - The shingle length (defaults to 3).\n * @returns A score between 0 (disjoint) and 1 (identical).\n */\nexport const computeJaccardSimilarity = (\n a: string,\n b: string,\n shingleLength: number = 3\n): number => {\n const setA = generateCharacterShingles(a, shingleLength);\n const setB = generateCharacterShingles(b, shingleLength);\n if (setA.size === 0 && setB.size === 0) return 1;\n const intersectionSize = Array.from(setA).filter((token) =>\n setB.has(token)\n ).length;\n const unionSize = new Set([...Array.from(setA), ...Array.from(setB)]).size;\n return unionSize === 0 ? 0 : intersectionSize / unionSize;\n};\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,6BACX,MACA,kBACgB;CAChB,MAAM,aAAa,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;CACnD,MAAM,sBAAM,IAAI,KAAa;AAC7B,KAAI,WAAW,SAAS,eAAe;AACrC,MAAI,WAAW,SAAS,EACtB,KAAI,IAAI,WAAW;AAErB,SAAO;;AAET,MAAK,IAAI,QAAQ,GAAG,SAAS,WAAW,SAAS,eAAe,SAAS,EACvE,KAAI,IAAI,WAAW,MAAM,OAAO,QAAQ,cAAc,CAAC;AAEzD,QAAO;;;;;;;;;;AAWT,MAAa,4BACX,GACA,GACA,gBAAwB,MACb;CACX,MAAM,OAAO,0BAA0B,GAAG,cAAc;CACxD,MAAM,OAAO,0BAA0B,GAAG,cAAc;AACxD,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,EAAG,QAAO;CAC/C,MAAM,mBAAmB,MAAM,KAAK,KAAK,CAAC,QAAQ,UAChD,KAAK,IAAI,MAAM,CAChB,CAAC;CACF,MAAM,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,KAAK,KAAK,EAAE,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC;AACtE,QAAO,cAAc,IAAI,IAAI,mBAAmB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let node_crypto = require("node:crypto");
|
|
4
|
+
node_crypto = require_runtime.__toESM(node_crypto);
|
|
5
|
+
|
|
6
|
+
//#region src/docReview/fingerprintBlock.ts
|
|
7
|
+
const computeStringDigest = (text) => node_crypto.default.createHash("sha256").update(text).digest("hex");
|
|
8
|
+
/**
|
|
9
|
+
* Compute content and context digests for a normalized block.
|
|
10
|
+
*
|
|
11
|
+
* The context key (digest of the surrounding blocks) lets the planner tell apart
|
|
12
|
+
* two blocks that share the same content but live in different sections.
|
|
13
|
+
*
|
|
14
|
+
* @param block - The block to fingerprint.
|
|
15
|
+
* @param previousBlock - The block immediately before, or `null` at the start.
|
|
16
|
+
* @param nextBlock - The block immediately after, or `null` at the end.
|
|
17
|
+
* @returns The block enriched with its digests.
|
|
18
|
+
*/
|
|
19
|
+
const fingerprintBlock = (block, previousBlock, nextBlock) => {
|
|
20
|
+
const semanticDigest = computeStringDigest(block.semanticText);
|
|
21
|
+
const anchorDigest = computeStringDigest(block.anchorText);
|
|
22
|
+
const compositeKey = `${semanticDigest}:${anchorDigest}`;
|
|
23
|
+
const contextKey = computeStringDigest(`${computeStringDigest(previousBlock?.semanticText ?? "")}:${computeStringDigest(nextBlock?.semanticText ?? "")}`);
|
|
24
|
+
return {
|
|
25
|
+
...block,
|
|
26
|
+
semanticDigest,
|
|
27
|
+
anchorDigest,
|
|
28
|
+
compositeKey,
|
|
29
|
+
contextKey
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.fingerprintBlock = fingerprintBlock;
|
|
35
|
+
//# sourceMappingURL=fingerprintBlock.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprintBlock.cjs","names":["crypto"],"sources":["../../../src/docReview/fingerprintBlock.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport type { FingerprintedBlock, NormalizedBlock } from './types';\n\nconst computeStringDigest = (text: string): string =>\n crypto.createHash('sha256').update(text).digest('hex');\n\n/**\n * Compute content and context digests for a normalized block.\n *\n * The context key (digest of the surrounding blocks) lets the planner tell apart\n * two blocks that share the same content but live in different sections.\n *\n * @param block - The block to fingerprint.\n * @param previousBlock - The block immediately before, or `null` at the start.\n * @param nextBlock - The block immediately after, or `null` at the end.\n * @returns The block enriched with its digests.\n */\nexport const fingerprintBlock = (\n block: NormalizedBlock,\n previousBlock: NormalizedBlock | null,\n nextBlock: NormalizedBlock | null\n): FingerprintedBlock => {\n const semanticDigest = computeStringDigest(block.semanticText);\n const anchorDigest = computeStringDigest(block.anchorText);\n const compositeKey = `${semanticDigest}:${anchorDigest}`;\n\n const previousDigest = computeStringDigest(previousBlock?.semanticText ?? '');\n const nextDigest = computeStringDigest(nextBlock?.semanticText ?? '');\n const contextKey = computeStringDigest(`${previousDigest}:${nextDigest}`);\n\n return {\n ...block,\n semanticDigest,\n anchorDigest,\n compositeKey,\n contextKey,\n };\n};\n"],"mappings":";;;;;;AAGA,MAAM,uBAAuB,SAC3BA,oBAAO,WAAW,SAAS,CAAC,OAAO,KAAK,CAAC,OAAO,MAAM;;;;;;;;;;;;AAaxD,MAAa,oBACX,OACA,eACA,cACuB;CACvB,MAAM,iBAAiB,oBAAoB,MAAM,aAAa;CAC9D,MAAM,eAAe,oBAAoB,MAAM,WAAW;CAC1D,MAAM,eAAe,GAAG,eAAe,GAAG;CAI1C,MAAM,aAAa,oBAAoB,GAFhB,oBAAoB,eAAe,gBAAgB,GAElB,CAAC,GADtC,oBAAoB,WAAW,gBAAgB,GACI,GAAG;AAEzE,QAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_docReview_planActions = require('./planActions.cjs');
|
|
3
|
+
const require_docReview_normalizeBlock = require('./normalizeBlock.cjs');
|
|
4
|
+
const require_docReview_fingerprintBlock = require('./fingerprintBlock.cjs');
|
|
5
|
+
const require_docReview_computeSimilarity = require('./computeSimilarity.cjs');
|
|
6
|
+
const require_docReview_mapChangedLinesToBlocks = require('./mapChangedLinesToBlocks.cjs');
|
|
7
|
+
const require_docReview_alignBlocks = require('./alignBlocks.cjs');
|
|
8
|
+
const require_docReview_rebuildDocument = require('./rebuildDocument.cjs');
|
|
9
|
+
const require_docReview_segmentDocument = require('./segmentDocument.cjs');
|
|
10
|
+
const require_docReview_pipeline = require('./pipeline.cjs');
|
|
11
|
+
const require_docReview_reviewReport = require('./reviewReport.cjs');
|
|
12
|
+
|
|
13
|
+
exports.alignBaseAndTargetBlocks = require_docReview_alignBlocks.alignBaseAndTargetBlocks;
|
|
14
|
+
exports.buildAlignmentPlan = require_docReview_pipeline.buildAlignmentPlan;
|
|
15
|
+
exports.buildReviewReport = require_docReview_reviewReport.buildReviewReport;
|
|
16
|
+
exports.computeJaccardSimilarity = require_docReview_computeSimilarity.computeJaccardSimilarity;
|
|
17
|
+
exports.fingerprintBlock = require_docReview_fingerprintBlock.fingerprintBlock;
|
|
18
|
+
exports.formatReviewReport = require_docReview_reviewReport.formatReviewReport;
|
|
19
|
+
exports.generateCharacterShingles = require_docReview_computeSimilarity.generateCharacterShingles;
|
|
20
|
+
exports.identifySegmentsToReview = require_docReview_rebuildDocument.identifySegmentsToReview;
|
|
21
|
+
exports.mapChangedLinesToBlocks = require_docReview_mapChangedLinesToBlocks.mapChangedLinesToBlocks;
|
|
22
|
+
exports.mergeReviewedSegments = require_docReview_rebuildDocument.mergeReviewedSegments;
|
|
23
|
+
exports.normalizeBlock = require_docReview_normalizeBlock.normalizeBlock;
|
|
24
|
+
exports.planAlignmentActions = require_docReview_planActions.planAlignmentActions;
|
|
25
|
+
exports.segmentDocument = require_docReview_segmentDocument.segmentDocument;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/docReview/mapChangedLinesToBlocks.ts
|
|
4
|
+
/**
|
|
5
|
+
* Map a set of changed line numbers onto the indexes of the blocks that contain
|
|
6
|
+
* them.
|
|
7
|
+
*
|
|
8
|
+
* @param blocks - The ordered blocks of the base document.
|
|
9
|
+
* @param changedLines - 1-based line numbers that changed in the base document.
|
|
10
|
+
* @returns The set of block indexes touched by at least one changed line.
|
|
11
|
+
*/
|
|
12
|
+
const mapChangedLinesToBlocks = (blocks, changedLines) => {
|
|
13
|
+
const changedSet = /* @__PURE__ */ new Set();
|
|
14
|
+
if (!changedLines || changedLines.length === 0) return changedSet;
|
|
15
|
+
const changedLookup = new Set(changedLines);
|
|
16
|
+
blocks.forEach((block, index) => {
|
|
17
|
+
for (let line = block.lineStart; line <= block.lineEnd; line += 1) if (changedLookup.has(line)) {
|
|
18
|
+
changedSet.add(index);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return changedSet;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.mapChangedLinesToBlocks = mapChangedLinesToBlocks;
|
|
27
|
+
//# sourceMappingURL=mapChangedLinesToBlocks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapChangedLinesToBlocks.cjs","names":[],"sources":["../../../src/docReview/mapChangedLinesToBlocks.ts"],"sourcesContent":["import type { Block, LineChange } from './types';\n\n/**\n * Map a set of changed line numbers onto the indexes of the blocks that contain\n * them.\n *\n * @param blocks - The ordered blocks of the base document.\n * @param changedLines - 1-based line numbers that changed in the base document.\n * @returns The set of block indexes touched by at least one changed line.\n */\nexport const mapChangedLinesToBlocks = (\n blocks: Block[],\n changedLines: LineChange[]\n): Set<number> => {\n const changedSet = new Set<number>();\n if (!changedLines || changedLines.length === 0) return changedSet;\n\n const changedLookup = new Set<number>(changedLines);\n\n blocks.forEach((block, index) => {\n for (let line = block.lineStart; line <= block.lineEnd; line += 1) {\n if (changedLookup.has(line)) {\n changedSet.add(index);\n break;\n }\n }\n });\n\n return changedSet;\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,2BACX,QACA,iBACgB;CAChB,MAAM,6BAAa,IAAI,KAAa;AACpC,KAAI,CAAC,gBAAgB,aAAa,WAAW,EAAG,QAAO;CAEvD,MAAM,gBAAgB,IAAI,IAAY,aAAa;AAEnD,QAAO,SAAS,OAAO,UAAU;AAC/B,OAAK,IAAI,OAAO,MAAM,WAAW,QAAQ,MAAM,SAAS,QAAQ,EAC9D,KAAI,cAAc,IAAI,KAAK,EAAE;AAC3B,cAAW,IAAI,MAAM;AACrB;;GAGJ;AAEF,QAAO"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/docReview/normalizeBlock.ts
|
|
4
|
+
const removeMarkdownFormatting = (text) => {
|
|
5
|
+
return text.replace(/`{1,3}[^`]*`{1,3}/g, " ").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/_([^_]+)_/g, "$1").replace(/~~([^~]+)~~/g, "$1").replace(/!?\[[^\]]*\]\([^)]*\)/g, " ").replace(/^\s*#{1,6}\s+/gm, "").replace(/^\s*>\s?/gm, "").replace(/^\s*[-*+]\s+/gm, "").replace(/^\s*\d+\.\s+/gm, "");
|
|
6
|
+
};
|
|
7
|
+
const collapseWhitespace = (text) => text.replace(/\s+/g, " ").trim();
|
|
8
|
+
const stripLettersKeepDigitsAndSymbols = (text) => {
|
|
9
|
+
return text.replace(/\p{L}+/gu, "");
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Derive the normalized representations of a block used for matching.
|
|
13
|
+
*
|
|
14
|
+
* - `semanticText`: markdown-stripped, lower-cased text (used to detect identical
|
|
15
|
+
* content across versions of the same language).
|
|
16
|
+
* - `anchorText`: only digits/symbols (used to align blocks across languages, as
|
|
17
|
+
* prose differs but structure such as numbers and punctuation is preserved).
|
|
18
|
+
*
|
|
19
|
+
* @param block - The block to normalize.
|
|
20
|
+
* @returns The block enriched with its normalized texts.
|
|
21
|
+
*/
|
|
22
|
+
const normalizeBlock = (block) => {
|
|
23
|
+
const semanticCollapsed = collapseWhitespace(removeMarkdownFormatting(block.content).toLowerCase());
|
|
24
|
+
const anchorCollapsed = collapseWhitespace(stripLettersKeepDigitsAndSymbols(block.content));
|
|
25
|
+
return {
|
|
26
|
+
...block,
|
|
27
|
+
semanticText: semanticCollapsed,
|
|
28
|
+
anchorText: anchorCollapsed
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.normalizeBlock = normalizeBlock;
|
|
34
|
+
//# sourceMappingURL=normalizeBlock.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeBlock.cjs","names":[],"sources":["../../../src/docReview/normalizeBlock.ts"],"sourcesContent":["import type { Block, NormalizedBlock } from './types';\n\nconst removeMarkdownFormatting = (text: string): string => {\n return text\n .replace(/`{1,3}[^`]*`{1,3}/g, ' ')\n .replace(/\\*\\*([^*]+)\\*\\*/g, '$1')\n .replace(/\\*([^*]+)\\*/g, '$1')\n .replace(/_([^_]+)_/g, '$1')\n .replace(/~~([^~]+)~~/g, '$1')\n .replace(/!?\\[[^\\]]*\\]\\([^)]*\\)/g, ' ')\n .replace(/^\\s*#{1,6}\\s+/gm, '')\n .replace(/^\\s*>\\s?/gm, '')\n .replace(/^\\s*[-*+]\\s+/gm, '')\n .replace(/^\\s*\\d+\\.\\s+/gm, '');\n};\n\nconst collapseWhitespace = (text: string): string =>\n text.replace(/\\s+/g, ' ').trim();\n\nconst stripLettersKeepDigitsAndSymbols = (text: string): string => {\n // Keep digits and non-letter characters, remove all letters (including accents)\n return text.replace(/\\p{L}+/gu, '');\n};\n\n/**\n * Derive the normalized representations of a block used for matching.\n *\n * - `semanticText`: markdown-stripped, lower-cased text (used to detect identical\n * content across versions of the same language).\n * - `anchorText`: only digits/symbols (used to align blocks across languages, as\n * prose differs but structure such as numbers and punctuation is preserved).\n *\n * @param block - The block to normalize.\n * @returns The block enriched with its normalized texts.\n */\nexport const normalizeBlock = (block: Block): NormalizedBlock => {\n const contentWithoutMarkdown = removeMarkdownFormatting(block.content);\n const semanticLowercased = contentWithoutMarkdown.toLowerCase();\n const semanticCollapsed = collapseWhitespace(semanticLowercased);\n\n const anchorOnlySymbols = stripLettersKeepDigitsAndSymbols(block.content);\n const anchorCollapsed = collapseWhitespace(anchorOnlySymbols);\n\n return {\n ...block,\n semanticText: semanticCollapsed,\n anchorText: anchorCollapsed,\n };\n};\n"],"mappings":";;;AAEA,MAAM,4BAA4B,SAAyB;AACzD,QAAO,KACJ,QAAQ,sBAAsB,IAAI,CAClC,QAAQ,oBAAoB,KAAK,CACjC,QAAQ,gBAAgB,KAAK,CAC7B,QAAQ,cAAc,KAAK,CAC3B,QAAQ,gBAAgB,KAAK,CAC7B,QAAQ,0BAA0B,IAAI,CACtC,QAAQ,mBAAmB,GAAG,CAC9B,QAAQ,cAAc,GAAG,CACzB,QAAQ,kBAAkB,GAAG,CAC7B,QAAQ,kBAAkB,GAAG;;AAGlC,MAAM,sBAAsB,SAC1B,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAElC,MAAM,oCAAoC,SAAyB;AAEjE,QAAO,KAAK,QAAQ,YAAY,GAAG;;;;;;;;;;;;;AAcrC,MAAa,kBAAkB,UAAkC;CAG/D,MAAM,oBAAoB,mBAFK,yBAAyB,MAAM,QACb,CAAC,aACa,CAAC;CAGhE,MAAM,kBAAkB,mBADE,iCAAiC,MAAM,QACL,CAAC;AAE7D,QAAO;EACL,GAAG;EACH,cAAc;EACd,YAAY;EACb"}
|