@intlayer/cli 6.1.6 → 7.0.0-canary.0

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.
Files changed (287) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +187 -239
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
  4. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/cjs/build.cjs +23 -42
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/cli.cjs +370 -431
  8. package/dist/cjs/cli.cjs.map +1 -1
  9. package/dist/cjs/config.cjs +10 -35
  10. package/dist/cjs/config.cjs.map +1 -1
  11. package/dist/cjs/editor.cjs +51 -66
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/fill/fill.cjs +73 -301
  14. package/dist/cjs/fill/fill.cjs.map +1 -1
  15. package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
  16. package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
  18. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  19. package/dist/cjs/fill/formatFillData.cjs +50 -0
  20. package/dist/cjs/fill/formatFillData.cjs.map +1 -0
  21. package/dist/cjs/fill/groupLimiter.cjs +42 -0
  22. package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
  23. package/dist/cjs/fill/index.cjs +5 -25
  24. package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
  25. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
  26. package/dist/cjs/fill/test-original-case.cjs +10 -0
  27. package/dist/cjs/fill/test-original-case.cjs.map +1 -0
  28. package/dist/cjs/fill/translateDictionary.cjs +148 -0
  29. package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
  30. package/dist/cjs/fill/writeAutoFill.cjs +48 -0
  31. package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
  32. package/dist/cjs/fill/writeFill.cjs +50 -0
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -0
  34. package/dist/cjs/getTargetDictionary.cjs +36 -76
  35. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  36. package/dist/cjs/index.cjs +31 -45
  37. package/dist/cjs/listContentDeclaration.cjs +36 -64
  38. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  39. package/dist/cjs/liveSync.cjs +146 -221
  40. package/dist/cjs/liveSync.cjs.map +1 -1
  41. package/dist/cjs/pull.cjs +132 -195
  42. package/dist/cjs/pull.cjs.map +1 -1
  43. package/dist/cjs/push/pullLog.cjs +101 -144
  44. package/dist/cjs/push/pullLog.cjs.map +1 -1
  45. package/dist/cjs/push/push.cjs +159 -249
  46. package/dist/cjs/push/push.cjs.map +1 -1
  47. package/dist/cjs/pushConfig.cjs +18 -45
  48. package/dist/cjs/pushConfig.cjs.map +1 -1
  49. package/dist/cjs/pushLog.cjs +87 -128
  50. package/dist/cjs/pushLog.cjs.map +1 -1
  51. package/dist/cjs/reviewDoc.cjs +183 -291
  52. package/dist/cjs/reviewDoc.cjs.map +1 -1
  53. package/dist/cjs/test/index.cjs +52 -91
  54. package/dist/cjs/test/index.cjs.map +1 -1
  55. package/dist/cjs/test/listMissingTranslations.cjs +35 -62
  56. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  57. package/dist/cjs/translateDoc.cjs +127 -221
  58. package/dist/cjs/translateDoc.cjs.map +1 -1
  59. package/dist/cjs/utils/calculateChunks.cjs +85 -115
  60. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  61. package/dist/cjs/utils/checkAccess.cjs +33 -72
  62. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  63. package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
  64. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  65. package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
  66. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  67. package/dist/cjs/utils/chunkInference.cjs +28 -47
  68. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  69. package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
  70. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  71. package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
  72. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  73. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
  74. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  75. package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
  76. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  77. package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
  78. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  79. package/dist/cjs/utils/listSpecialChars.cjs +49 -73
  80. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  81. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
  82. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  83. package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
  84. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  85. package/dist/cjs/watch.cjs +21 -39
  86. package/dist/cjs/watch.cjs.map +1 -1
  87. package/dist/esm/IntlayerEventListener.mjs +178 -201
  88. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  89. package/dist/esm/_virtual/_utils_asset.mjs +100 -0
  90. package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
  91. package/dist/esm/build.mjs +20 -23
  92. package/dist/esm/build.mjs.map +1 -1
  93. package/dist/esm/cli.mjs +349 -380
  94. package/dist/esm/cli.mjs.map +1 -1
  95. package/dist/esm/config.mjs +8 -14
  96. package/dist/esm/config.mjs.map +1 -1
  97. package/dist/esm/editor.mjs +47 -41
  98. package/dist/esm/editor.mjs.map +1 -1
  99. package/dist/esm/fill/fill.mjs +68 -300
  100. package/dist/esm/fill/fill.mjs.map +1 -1
  101. package/dist/esm/fill/formatAutoFillData.mjs +47 -81
  102. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
  103. package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
  104. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  105. package/dist/esm/fill/formatFillData.mjs +50 -0
  106. package/dist/esm/fill/formatFillData.mjs.map +1 -0
  107. package/dist/esm/fill/groupLimiter.mjs +40 -0
  108. package/dist/esm/fill/groupLimiter.mjs.map +1 -0
  109. package/dist/esm/fill/index.mjs +4 -3
  110. package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
  111. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
  112. package/dist/esm/fill/test-original-case.mjs +10 -0
  113. package/dist/esm/fill/test-original-case.mjs.map +1 -0
  114. package/dist/esm/fill/translateDictionary.mjs +141 -0
  115. package/dist/esm/fill/translateDictionary.mjs.map +1 -0
  116. package/dist/esm/fill/writeAutoFill.mjs +44 -0
  117. package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
  118. package/dist/esm/fill/writeFill.mjs +45 -0
  119. package/dist/esm/fill/writeFill.mjs.map +1 -0
  120. package/dist/esm/getTargetDictionary.mjs +27 -48
  121. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  122. package/dist/esm/index.mjs +15 -13
  123. package/dist/esm/listContentDeclaration.mjs +28 -43
  124. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/liveSync.mjs +135 -187
  126. package/dist/esm/liveSync.mjs.map +1 -1
  127. package/dist/esm/pull.mjs +125 -178
  128. package/dist/esm/pull.mjs.map +1 -1
  129. package/dist/esm/push/pullLog.mjs +99 -125
  130. package/dist/esm/push/pullLog.mjs.map +1 -1
  131. package/dist/esm/push/push.mjs +149 -221
  132. package/dist/esm/push/push.mjs.map +1 -1
  133. package/dist/esm/pushConfig.mjs +14 -23
  134. package/dist/esm/pushConfig.mjs.map +1 -1
  135. package/dist/esm/pushLog.mjs +85 -109
  136. package/dist/esm/pushLog.mjs.map +1 -1
  137. package/dist/esm/reviewDoc.mjs +167 -264
  138. package/dist/esm/reviewDoc.mjs.map +1 -1
  139. package/dist/esm/test/index.mjs +47 -73
  140. package/dist/esm/test/index.mjs.map +1 -1
  141. package/dist/esm/test/listMissingTranslations.mjs +30 -41
  142. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  143. package/dist/esm/translateDoc.mjs +114 -193
  144. package/dist/esm/translateDoc.mjs.map +1 -1
  145. package/dist/esm/utils/calculateChunks.mjs +83 -91
  146. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  147. package/dist/esm/utils/checkAccess.mjs +28 -46
  148. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  149. package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
  150. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  151. package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
  152. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  153. package/dist/esm/utils/chunkInference.mjs +24 -24
  154. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  155. package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
  156. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  157. package/dist/esm/utils/formatTimeDiff.mjs +16 -19
  158. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  159. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
  160. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  161. package/dist/esm/utils/getOutputFilePath.mjs +70 -62
  162. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  163. package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
  164. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  165. package/dist/esm/utils/listSpecialChars.mjs +48 -49
  166. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  167. package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
  168. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  169. package/dist/esm/utils/reorderParagraphs.mjs +85 -93
  170. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  171. package/dist/esm/watch.mjs +17 -17
  172. package/dist/esm/watch.mjs.map +1 -1
  173. package/dist/types/IntlayerEventListener.d.ts +63 -59
  174. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  175. package/dist/types/build.d.ts +10 -7
  176. package/dist/types/build.d.ts.map +1 -1
  177. package/dist/types/cli.d.ts +13 -10
  178. package/dist/types/cli.d.ts.map +1 -1
  179. package/dist/types/config.d.ts +7 -4
  180. package/dist/types/config.d.ts.map +1 -1
  181. package/dist/types/editor.d.ts +6 -4
  182. package/dist/types/editor.d.ts.map +1 -1
  183. package/dist/types/fill/fill.d.ts +20 -14
  184. package/dist/types/fill/fill.d.ts.map +1 -1
  185. package/dist/types/fill/formatAutoFillData.d.ts +10 -7
  186. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
  187. package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
  188. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
  189. package/dist/types/fill/formatFillData.d.ts +12 -0
  190. package/dist/types/fill/formatFillData.d.ts.map +1 -0
  191. package/dist/types/fill/groupLimiter.d.ts +15 -0
  192. package/dist/types/fill/groupLimiter.d.ts.map +1 -0
  193. package/dist/types/fill/index.d.ts +3 -3
  194. package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
  195. package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
  196. package/dist/types/fill/test-original-case.d.ts +1 -0
  197. package/dist/types/fill/translateDictionary.d.ts +19 -0
  198. package/dist/types/fill/translateDictionary.d.ts.map +1 -0
  199. package/dist/types/fill/writeAutoFill.d.ts +7 -0
  200. package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
  201. package/dist/types/fill/writeFill.d.ts +7 -0
  202. package/dist/types/fill/writeFill.d.ts.map +1 -0
  203. package/dist/types/getTargetDictionary.d.ts +17 -13
  204. package/dist/types/getTargetDictionary.d.ts.map +1 -1
  205. package/dist/types/index.d.ts +15 -14
  206. package/dist/types/listContentDeclaration.d.ts +10 -7
  207. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  208. package/dist/types/liveSync.d.ts +8 -3
  209. package/dist/types/liveSync.d.ts.map +1 -1
  210. package/dist/types/pull.d.ts +9 -6
  211. package/dist/types/pull.d.ts.map +1 -1
  212. package/dist/types/push/pullLog.d.ts +25 -21
  213. package/dist/types/push/pullLog.d.ts.map +1 -1
  214. package/dist/types/push/push.d.ts +13 -9
  215. package/dist/types/push/push.d.ts.map +1 -1
  216. package/dist/types/pushConfig.d.ts +7 -4
  217. package/dist/types/pushConfig.d.ts.map +1 -1
  218. package/dist/types/pushLog.d.ts +23 -20
  219. package/dist/types/pushLog.d.ts.map +1 -1
  220. package/dist/types/reviewDoc.d.ts +34 -17
  221. package/dist/types/reviewDoc.d.ts.map +1 -1
  222. package/dist/types/test/index.d.ts +9 -5
  223. package/dist/types/test/index.d.ts.map +1 -1
  224. package/dist/types/test/listMissingTranslations.d.ts +14 -10
  225. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  226. package/dist/types/translateDoc.d.ts +34 -17
  227. package/dist/types/translateDoc.d.ts.map +1 -1
  228. package/dist/types/utils/calculateChunks.d.ts +10 -7
  229. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  230. package/dist/types/utils/checkAccess.d.ts +8 -4
  231. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  232. package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
  233. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  234. package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
  235. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  236. package/dist/types/utils/chunkInference.d.ts +9 -6
  237. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  238. package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
  239. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  240. package/dist/types/utils/formatTimeDiff.d.ts +4 -1
  241. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  242. package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
  243. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  244. package/dist/types/utils/getOutputFilePath.d.ts +7 -2
  245. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  246. package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
  247. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  248. package/dist/types/utils/listSpecialChars.d.ts +9 -7
  249. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  250. package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
  251. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  252. package/dist/types/utils/reorderParagraphs.d.ts +4 -1
  253. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  254. package/dist/types/watch.d.ts +9 -6
  255. package/dist/types/watch.d.ts.map +1 -1
  256. package/package.json +42 -47
  257. package/LICENSE +0 -202
  258. package/dist/cjs/fill/autoFill.cjs +0 -105
  259. package/dist/cjs/fill/autoFill.cjs.map +0 -1
  260. package/dist/cjs/fill/index.cjs.map +0 -1
  261. package/dist/cjs/index.cjs.map +0 -1
  262. package/dist/cjs/utils/getChunk.cjs +0 -77
  263. package/dist/cjs/utils/getChunk.cjs.map +0 -1
  264. package/dist/cjs/utils/splitTextByLine.cjs +0 -35
  265. package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
  266. package/dist/esm/fill/autoFill.mjs +0 -92
  267. package/dist/esm/fill/autoFill.mjs.map +0 -1
  268. package/dist/esm/fill/index.mjs.map +0 -1
  269. package/dist/esm/index.mjs.map +0 -1
  270. package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
  271. package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
  272. package/dist/esm/utils/calculrateChunkTest.md +0 -9
  273. package/dist/esm/utils/getChunk.mjs +0 -53
  274. package/dist/esm/utils/getChunk.mjs.map +0 -1
  275. package/dist/esm/utils/splitTextByLine.mjs +0 -11
  276. package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
  277. package/dist/types/fill/autoFill.d.ts +0 -4
  278. package/dist/types/fill/autoFill.d.ts.map +0 -1
  279. package/dist/types/fill/index.d.ts.map +0 -1
  280. package/dist/types/index.d.ts.map +0 -1
  281. package/dist/types/utils/getChunk.d.ts +0 -9
  282. package/dist/types/utils/getChunk.d.ts.map +0 -1
  283. package/dist/types/utils/splitTextByLine.d.ts +0 -2
  284. package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
  285. /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
  286. /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
  287. /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
@@ -1,145 +1,103 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var mapChunksBetweenFiles_exports = {};
20
- __export(mapChunksBetweenFiles_exports, {
21
- mapChunksBetweenFiles: () => mapChunksBetweenFiles
22
- });
23
- module.exports = __toCommonJS(mapChunksBetweenFiles_exports);
24
- var import_calculateChunks = require('./calculateChunks.cjs');
25
- var import_splitTextByLine = require('./splitTextByLine.cjs');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_utils_calculateChunks = require('./calculateChunks.cjs');
3
+ let __intlayer_chokidar = require("@intlayer/chokidar");
4
+ __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
5
+
6
+ //#region src/utils/mapChunksBetweenFiles.ts
7
+ /**
8
+ * Maps chunks from base file to corresponding chunks in updated file,
9
+ * handling insertions, deletions, and modifications properly.
10
+ */
26
11
  const mapChunksBetweenFiles = (baseFileContent, updatedFileContent, maxCharsPerChunk = 800, changedLines) => {
27
- const baseChunks = (0, import_calculateChunks.chunkText)(baseFileContent, maxCharsPerChunk, 0);
28
- const baseLines = (0, import_splitTextByLine.splitTextByLines)(baseFileContent);
29
- const updatedLines = (0, import_splitTextByLine.splitTextByLines)(updatedFileContent);
30
- const lineMapping = createLineMapping(baseLines, updatedLines);
31
- return baseChunks.map((baseChunk) => {
32
- const mappedRange = mapLineRange(
33
- baseChunk.lineStart,
34
- baseChunk.lineLength,
35
- lineMapping
36
- );
37
- if (!mappedRange) {
38
- return {
39
- baseChunk,
40
- updatedChunk: null,
41
- hasChanges: true
42
- };
43
- }
44
- const updatedChunk = {
45
- lineStart: mappedRange.start,
46
- lineLength: mappedRange.length,
47
- charStart: 0,
48
- // Will be calculated when needed
49
- charLength: 0,
50
- // Will be calculated when needed
51
- content: extractLinesFromRange(
52
- updatedLines,
53
- mappedRange.start,
54
- mappedRange.length
55
- )
56
- };
57
- updatedChunk.charStart = getCharStartForLine(
58
- updatedFileContent,
59
- updatedChunk.lineStart
60
- );
61
- updatedChunk.charLength = updatedChunk.content.length;
62
- const hasChanges = determineIfChunkHasChanges(
63
- baseChunk,
64
- updatedChunk,
65
- changedLines
66
- );
67
- return {
68
- baseChunk,
69
- updatedChunk,
70
- hasChanges
71
- };
72
- });
12
+ const baseChunks = require_utils_calculateChunks.chunkText(baseFileContent, maxCharsPerChunk, 0);
13
+ const baseLines = (0, __intlayer_chokidar.splitTextByLines)(baseFileContent);
14
+ const updatedLines = (0, __intlayer_chokidar.splitTextByLines)(updatedFileContent);
15
+ const lineMapping = createLineMapping(baseLines, updatedLines);
16
+ return baseChunks.map((baseChunk) => {
17
+ const mappedRange = mapLineRange(baseChunk.lineStart, baseChunk.lineLength, lineMapping);
18
+ if (!mappedRange) return {
19
+ baseChunk,
20
+ updatedChunk: null,
21
+ hasChanges: true
22
+ };
23
+ const updatedChunk = {
24
+ lineStart: mappedRange.start,
25
+ lineLength: mappedRange.length,
26
+ charStart: 0,
27
+ charLength: 0,
28
+ content: extractLinesFromRange(updatedLines, mappedRange.start, mappedRange.length)
29
+ };
30
+ updatedChunk.charStart = getCharStartForLine(updatedFileContent, updatedChunk.lineStart);
31
+ updatedChunk.charLength = updatedChunk.content.length;
32
+ return {
33
+ baseChunk,
34
+ updatedChunk,
35
+ hasChanges: determineIfChunkHasChanges(baseChunk, updatedChunk, changedLines)
36
+ };
37
+ });
73
38
  };
39
+ /**
40
+ * Creates a mapping between line numbers in base file and updated file
41
+ * Returns a map where key = base line number, value = updated line number (or null if deleted)
42
+ */
74
43
  const createLineMapping = (baseLines, updatedLines) => {
75
- const mapping = /* @__PURE__ */ new Map();
76
- const dp = Array(baseLines.length + 1).fill(null).map(() => Array(updatedLines.length + 1).fill(0));
77
- for (let i2 = 1; i2 <= baseLines.length; i2++) {
78
- for (let j2 = 1; j2 <= updatedLines.length; j2++) {
79
- if (baseLines[i2 - 1] === updatedLines[j2 - 1]) {
80
- dp[i2][j2] = dp[i2 - 1][j2 - 1] + 1;
81
- } else {
82
- dp[i2][j2] = Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
83
- }
84
- }
85
- }
86
- let i = baseLines.length;
87
- let j = updatedLines.length;
88
- while (i > 0 || j > 0) {
89
- if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {
90
- mapping.set(i - 1, j - 1);
91
- i--;
92
- j--;
93
- } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {
94
- mapping.set(i - 1, null);
95
- i--;
96
- } else {
97
- j--;
98
- }
99
- }
100
- return mapping;
44
+ const mapping = /* @__PURE__ */ new Map();
45
+ const dp = Array(baseLines.length + 1).fill(null).map(() => Array(updatedLines.length + 1).fill(0));
46
+ for (let i$1 = 1; i$1 <= baseLines.length; i$1++) for (let j$1 = 1; j$1 <= updatedLines.length; j$1++) if (baseLines[i$1 - 1] === updatedLines[j$1 - 1]) dp[i$1][j$1] = dp[i$1 - 1][j$1 - 1] + 1;
47
+ else dp[i$1][j$1] = Math.max(dp[i$1 - 1][j$1], dp[i$1][j$1 - 1]);
48
+ let i = baseLines.length;
49
+ let j = updatedLines.length;
50
+ while (i > 0 || j > 0) if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {
51
+ mapping.set(i - 1, j - 1);
52
+ i--;
53
+ j--;
54
+ } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {
55
+ mapping.set(i - 1, null);
56
+ i--;
57
+ } else j--;
58
+ return mapping;
101
59
  };
60
+ /**
61
+ * Maps a line range from base file to updated file using the line mapping
62
+ */
102
63
  const mapLineRange = (baseStart, baseLength, lineMapping) => {
103
- const mappedLines = [];
104
- for (let i = baseStart; i < baseStart + baseLength; i++) {
105
- const mappedLine = lineMapping.get(i);
106
- if (mappedLine !== null && mappedLine !== void 0) {
107
- mappedLines.push(mappedLine);
108
- }
109
- }
110
- if (mappedLines.length === 0) {
111
- return null;
112
- }
113
- mappedLines.sort((a, b) => a - b);
114
- const start = mappedLines[0];
115
- const end = mappedLines[mappedLines.length - 1];
116
- return {
117
- start,
118
- length: end - start + 1
119
- };
64
+ const mappedLines = [];
65
+ for (let i = baseStart; i < baseStart + baseLength; i++) {
66
+ const mappedLine = lineMapping.get(i);
67
+ if (mappedLine !== null && mappedLine !== void 0) mappedLines.push(mappedLine);
68
+ }
69
+ if (mappedLines.length === 0) return null;
70
+ mappedLines.sort((a, b) => a - b);
71
+ const start = mappedLines[0];
72
+ return {
73
+ start,
74
+ length: mappedLines[mappedLines.length - 1] - start + 1
75
+ };
120
76
  };
77
+ /**
78
+ * Extracts lines from a range in the lines array
79
+ */
121
80
  const extractLinesFromRange = (lines, start, length) => {
122
- const endIndex = Math.min(start + length, lines.length);
123
- return lines.slice(start, endIndex).join("");
81
+ const endIndex = Math.min(start + length, lines.length);
82
+ return lines.slice(start, endIndex).join("");
124
83
  };
84
+ /**
85
+ * Gets the character position where a line starts in the text
86
+ */
125
87
  const getCharStartForLine = (text, lineNumber) => {
126
- const lines = (0, import_splitTextByLine.splitTextByLines)(text);
127
- let charStart = 0;
128
- for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {
129
- charStart += lines[i].length;
130
- }
131
- return charStart;
88
+ const lines = (0, __intlayer_chokidar.splitTextByLines)(text);
89
+ let charStart = 0;
90
+ for (let i = 0; i < Math.min(lineNumber, lines.length); i++) charStart += lines[i].length;
91
+ return charStart;
132
92
  };
93
+ /**
94
+ * Determines if a chunk has changes based on git changed lines or content comparison
95
+ */
133
96
  const determineIfChunkHasChanges = (baseChunk, updatedChunk, changedLines) => {
134
- if (changedLines && changedLines.length > 0) {
135
- return changedLines.some(
136
- (line) => line >= updatedChunk.lineStart && line < updatedChunk.lineStart + updatedChunk.lineLength
137
- );
138
- }
139
- return baseChunk.content !== updatedChunk.content;
97
+ if (changedLines && changedLines.length > 0) return changedLines.some((line) => line >= updatedChunk.lineStart && line < updatedChunk.lineStart + updatedChunk.lineLength);
98
+ return baseChunk.content !== updatedChunk.content;
140
99
  };
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- mapChunksBetweenFiles
144
- });
100
+
101
+ //#endregion
102
+ exports.mapChunksBetweenFiles = mapChunksBetweenFiles;
145
103
  //# sourceMappingURL=mapChunksBetweenFiles.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/mapChunksBetweenFiles.ts"],"sourcesContent":["import { ChunkLineResult, chunkText } from './calculateChunks';\nimport { splitTextByLines } from './splitTextByLine';\n\nexport interface ChunkMapping {\n baseChunk: ChunkLineResult;\n updatedChunk: ChunkLineResult | null; // null if the chunk was deleted\n hasChanges: boolean;\n}\n\n/**\n * Maps chunks from base file to corresponding chunks in updated file,\n * handling insertions, deletions, and modifications properly.\n */\nexport const mapChunksBetweenFiles = (\n baseFileContent: string,\n updatedFileContent: string,\n maxCharsPerChunk: number = 800,\n changedLines?: number[]\n): ChunkMapping[] => {\n const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);\n const baseLines = splitTextByLines(baseFileContent);\n const updatedLines = splitTextByLines(updatedFileContent);\n\n // Create a simple line mapping using LCS (Longest Common Subsequence) approach\n const lineMapping = createLineMapping(baseLines, updatedLines);\n\n return baseChunks.map((baseChunk): ChunkMapping => {\n // Map the base chunk's line range to the updated file\n const mappedRange = mapLineRange(\n baseChunk.lineStart,\n baseChunk.lineLength,\n lineMapping\n );\n\n if (!mappedRange) {\n // This chunk was completely deleted\n return {\n baseChunk,\n updatedChunk: null,\n hasChanges: true,\n };\n }\n\n // Create the corresponding chunk in the updated file\n const updatedChunk: ChunkLineResult = {\n lineStart: mappedRange.start,\n lineLength: mappedRange.length,\n charStart: 0, // Will be calculated when needed\n charLength: 0, // Will be calculated when needed\n content: extractLinesFromRange(\n updatedLines,\n mappedRange.start,\n mappedRange.length\n ),\n };\n\n // Calculate character positions\n updatedChunk.charStart = getCharStartForLine(\n updatedFileContent,\n updatedChunk.lineStart\n );\n updatedChunk.charLength = updatedChunk.content.length;\n\n // Determine if this chunk has changes\n const hasChanges = determineIfChunkHasChanges(\n baseChunk,\n updatedChunk,\n changedLines\n );\n\n return {\n baseChunk,\n updatedChunk,\n hasChanges,\n };\n });\n};\n\n/**\n * Creates a mapping between line numbers in base file and updated file\n * Returns a map where key = base line number, value = updated line number (or null if deleted)\n */\nconst createLineMapping = (\n baseLines: string[],\n updatedLines: string[]\n): Map<number, number | null> => {\n const mapping = new Map<number, number | null>();\n\n // Use a simple diff algorithm (similar to Myers algorithm but simplified)\n const dp: number[][] = Array(baseLines.length + 1)\n .fill(null)\n .map(() => Array(updatedLines.length + 1).fill(0));\n\n // Fill the DP table\n for (let i = 1; i <= baseLines.length; i++) {\n for (let j = 1; j <= updatedLines.length; j++) {\n if (baseLines[i - 1] === updatedLines[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1;\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n }\n }\n }\n\n // Backtrack to create the mapping\n let i = baseLines.length;\n let j = updatedLines.length;\n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {\n // Lines match\n mapping.set(i - 1, j - 1);\n i--;\n j--;\n } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {\n // Line was deleted from base\n mapping.set(i - 1, null);\n i--;\n } else {\n // Line was added to updated (no mapping needed for base)\n j--;\n }\n }\n\n return mapping;\n};\n\n/**\n * Maps a line range from base file to updated file using the line mapping\n */\nconst mapLineRange = (\n baseStart: number,\n baseLength: number,\n lineMapping: Map<number, number | null>\n): { start: number; length: number } | null => {\n const mappedLines: number[] = [];\n\n for (let i = baseStart; i < baseStart + baseLength; i++) {\n const mappedLine = lineMapping.get(i);\n if (mappedLine !== null && mappedLine !== undefined) {\n mappedLines.push(mappedLine);\n }\n }\n\n if (mappedLines.length === 0) {\n return null; // All lines were deleted\n }\n\n // Find the continuous range in the mapped lines\n mappedLines.sort((a, b) => a - b);\n const start = mappedLines[0];\n const end = mappedLines[mappedLines.length - 1];\n\n return {\n start,\n length: end - start + 1,\n };\n};\n\n/**\n * Extracts lines from a range in the lines array\n */\nconst extractLinesFromRange = (\n lines: string[],\n start: number,\n length: number\n): string => {\n const endIndex = Math.min(start + length, lines.length);\n return lines.slice(start, endIndex).join('');\n};\n\n/**\n * Gets the character position where a line starts in the text\n */\nconst getCharStartForLine = (text: string, lineNumber: number): number => {\n const lines = splitTextByLines(text);\n let charStart = 0;\n\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n charStart += lines[i].length;\n }\n\n return charStart;\n};\n\n/**\n * Determines if a chunk has changes based on git changed lines or content comparison\n */\nconst determineIfChunkHasChanges = (\n baseChunk: ChunkLineResult,\n updatedChunk: ChunkLineResult,\n changedLines?: number[]\n): boolean => {\n // If we have git changed lines, use them for precise detection\n if (changedLines && changedLines.length > 0) {\n return changedLines.some(\n (line) =>\n line >= updatedChunk.lineStart &&\n line < updatedChunk.lineStart + updatedChunk.lineLength\n );\n }\n\n // Fallback to content comparison\n return baseChunk.content !== updatedChunk.content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA2C;AAC3C,6BAAiC;AAY1B,MAAM,wBAAwB,CACnC,iBACA,oBACA,mBAA2B,KAC3B,iBACmB;AACnB,QAAM,iBAAa,kCAAU,iBAAiB,kBAAkB,CAAC;AACjE,QAAM,gBAAY,yCAAiB,eAAe;AAClD,QAAM,mBAAe,yCAAiB,kBAAkB;AAGxD,QAAM,cAAc,kBAAkB,WAAW,YAAY;AAE7D,SAAO,WAAW,IAAI,CAAC,cAA4B;AAEjD,UAAM,cAAc;AAAA,MAClB,UAAU;AAAA,MACV,UAAU;AAAA,MACV;AAAA,IACF;AAEA,QAAI,CAAC,aAAa;AAEhB,aAAO;AAAA,QACL;AAAA,QACA,cAAc;AAAA,QACd,YAAY;AAAA,MACd;AAAA,IACF;AAGA,UAAM,eAAgC;AAAA,MACpC,WAAW,YAAY;AAAA,MACvB,YAAY,YAAY;AAAA,MACxB,WAAW;AAAA;AAAA,MACX,YAAY;AAAA;AAAA,MACZ,SA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Y,aAAa;AAC5C;","names":["i","j"]}
1
+ {"version":3,"file":"mapChunksBetweenFiles.cjs","names":["chunkText","updatedChunk: ChunkLineResult","dp: number[][]","i","j","mappedLines: number[]"],"sources":["../../../src/utils/mapChunksBetweenFiles.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar';\nimport { type ChunkLineResult, chunkText } from './calculateChunks';\n\nexport interface ChunkMapping {\n baseChunk: ChunkLineResult;\n updatedChunk: ChunkLineResult | null; // null if the chunk was deleted\n hasChanges: boolean;\n}\n\n/**\n * Maps chunks from base file to corresponding chunks in updated file,\n * handling insertions, deletions, and modifications properly.\n */\nexport const mapChunksBetweenFiles = (\n baseFileContent: string,\n updatedFileContent: string,\n maxCharsPerChunk: number = 800,\n changedLines?: number[]\n): ChunkMapping[] => {\n const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);\n const baseLines = splitTextByLines(baseFileContent);\n const updatedLines = splitTextByLines(updatedFileContent);\n\n // Create a simple line mapping using LCS (Longest Common Subsequence) approach\n const lineMapping = createLineMapping(baseLines, updatedLines);\n\n return baseChunks.map((baseChunk): ChunkMapping => {\n // Map the base chunk's line range to the updated file\n const mappedRange = mapLineRange(\n baseChunk.lineStart,\n baseChunk.lineLength,\n lineMapping\n );\n\n if (!mappedRange) {\n // This chunk was completely deleted\n return {\n baseChunk,\n updatedChunk: null,\n hasChanges: true,\n };\n }\n\n // Create the corresponding chunk in the updated file\n const updatedChunk: ChunkLineResult = {\n lineStart: mappedRange.start,\n lineLength: mappedRange.length,\n charStart: 0, // Will be calculated when needed\n charLength: 0, // Will be calculated when needed\n content: extractLinesFromRange(\n updatedLines,\n mappedRange.start,\n mappedRange.length\n ),\n };\n\n // Calculate character positions\n updatedChunk.charStart = getCharStartForLine(\n updatedFileContent,\n updatedChunk.lineStart\n );\n updatedChunk.charLength = updatedChunk.content.length;\n\n // Determine if this chunk has changes\n const hasChanges = determineIfChunkHasChanges(\n baseChunk,\n updatedChunk,\n changedLines\n );\n\n return {\n baseChunk,\n updatedChunk,\n hasChanges,\n };\n });\n};\n\n/**\n * Creates a mapping between line numbers in base file and updated file\n * Returns a map where key = base line number, value = updated line number (or null if deleted)\n */\nconst createLineMapping = (\n baseLines: string[],\n updatedLines: string[]\n): Map<number, number | null> => {\n const mapping = new Map<number, number | null>();\n\n // Use a simple diff algorithm (similar to Myers algorithm but simplified)\n const dp: number[][] = Array(baseLines.length + 1)\n .fill(null)\n .map(() => Array(updatedLines.length + 1).fill(0));\n\n // Fill the DP table\n for (let i = 1; i <= baseLines.length; i++) {\n for (let j = 1; j <= updatedLines.length; j++) {\n if (baseLines[i - 1] === updatedLines[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1;\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n }\n }\n }\n\n // Backtrack to create the mapping\n let i = baseLines.length;\n let j = updatedLines.length;\n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {\n // Lines match\n mapping.set(i - 1, j - 1);\n i--;\n j--;\n } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {\n // Line was deleted from base\n mapping.set(i - 1, null);\n i--;\n } else {\n // Line was added to updated (no mapping needed for base)\n j--;\n }\n }\n\n return mapping;\n};\n\n/**\n * Maps a line range from base file to updated file using the line mapping\n */\nconst mapLineRange = (\n baseStart: number,\n baseLength: number,\n lineMapping: Map<number, number | null>\n): { start: number; length: number } | null => {\n const mappedLines: number[] = [];\n\n for (let i = baseStart; i < baseStart + baseLength; i++) {\n const mappedLine = lineMapping.get(i);\n if (mappedLine !== null && mappedLine !== undefined) {\n mappedLines.push(mappedLine);\n }\n }\n\n if (mappedLines.length === 0) {\n return null; // All lines were deleted\n }\n\n // Find the continuous range in the mapped lines\n mappedLines.sort((a, b) => a - b);\n const start = mappedLines[0];\n const end = mappedLines[mappedLines.length - 1];\n\n return {\n start,\n length: end - start + 1,\n };\n};\n\n/**\n * Extracts lines from a range in the lines array\n */\nconst extractLinesFromRange = (\n lines: string[],\n start: number,\n length: number\n): string => {\n const endIndex = Math.min(start + length, lines.length);\n return lines.slice(start, endIndex).join('');\n};\n\n/**\n * Gets the character position where a line starts in the text\n */\nconst getCharStartForLine = (text: string, lineNumber: number): number => {\n const lines = splitTextByLines(text);\n let charStart = 0;\n\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n charStart += lines[i].length;\n }\n\n return charStart;\n};\n\n/**\n * Determines if a chunk has changes based on git changed lines or content comparison\n */\nconst determineIfChunkHasChanges = (\n baseChunk: ChunkLineResult,\n updatedChunk: ChunkLineResult,\n changedLines?: number[]\n): boolean => {\n // If we have git changed lines, use them for precise detection\n if (changedLines && changedLines.length > 0) {\n return changedLines.some(\n (line) =>\n line >= updatedChunk.lineStart &&\n line < updatedChunk.lineStart + updatedChunk.lineLength\n );\n }\n\n // Fallback to content comparison\n return baseChunk.content !== updatedChunk.content;\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAa,yBACX,iBACA,oBACA,mBAA2B,KAC3B,iBACmB;CACnB,MAAM,aAAaA,wCAAU,iBAAiB,kBAAkB,EAAE;CAClE,MAAM,sDAA6B,gBAAgB;CACnD,MAAM,yDAAgC,mBAAmB;CAGzD,MAAM,cAAc,kBAAkB,WAAW,aAAa;AAE9D,QAAO,WAAW,KAAK,cAA4B;EAEjD,MAAM,cAAc,aAClB,UAAU,WACV,UAAU,YACV,YACD;AAED,MAAI,CAAC,YAEH,QAAO;GACL;GACA,cAAc;GACd,YAAY;GACb;EAIH,MAAMC,eAAgC;GACpC,WAAW,YAAY;GACvB,YAAY,YAAY;GACxB,WAAW;GACX,YAAY;GACZ,SAAS,sBACP,cACA,YAAY,OACZ,YAAY,OACb;GACF;AAGD,eAAa,YAAY,oBACvB,oBACA,aAAa,UACd;AACD,eAAa,aAAa,aAAa,QAAQ;AAS/C,SAAO;GACL;GACA;GACA,YATiB,2BACjB,WACA,cACA,aACD;GAMA;GACD;;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B;;;;;AAMH,MAAM,yBACJ,OACA,OACA,WACW;CACX,MAAM,WAAW,KAAK,IAAI,QAAQ,QAAQ,MAAM,OAAO;AACvD,QAAO,MAAM,MAAM,OAAO,SAAS,CAAC,KAAK,GAAG;;;;;AAM9C,MAAM,uBAAuB,MAAc,eAA+B;CACxE,MAAM,kDAAyB,KAAK;CACpC,IAAI,YAAY;AAEhB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,YAAY,MAAM,OAAO,EAAE,IACtD,cAAa,MAAM,GAAG;AAGxB,QAAO;;;;;AAMT,MAAM,8BACJ,WACA,cACA,iBACY;AAEZ,KAAI,gBAAgB,aAAa,SAAS,EACxC,QAAO,aAAa,MACjB,SACC,QAAQ,aAAa,aACrB,OAAO,aAAa,YAAY,aAAa,WAChD;AAIH,QAAO,UAAU,YAAY,aAAa"}
@@ -1,125 +1,93 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var reorderParagraphs_exports = {};
20
- __export(reorderParagraphs_exports, {
21
- reorderParagraphs: () => reorderParagraphs
22
- });
23
- module.exports = __toCommonJS(reorderParagraphs_exports);
24
- var import_listSpecialChars = require('./listSpecialChars.cjs');
1
+ const require_utils_listSpecialChars = require('./listSpecialChars.cjs');
2
+
3
+ //#region src/utils/reorderParagraphs.ts
4
+ /**
5
+ * Split a text into paragraphs.
6
+ *
7
+ * We consider a paragraph boundary to be a block of at least two consecutive
8
+ * new-lines that is immediately followed by a non-white-space character. This
9
+ * way, internal blank lines that are part of the same paragraph (e.g. a list
10
+ * item that purposely contains a visual break) are preserved while true
11
+ * paragraph breaks the ones generated when calling `arr.join("\n\n")` in
12
+ * the tests are still detected.
13
+ */
25
14
  const splitByParagraph = (text) => {
26
- const paragraphs = [];
27
- const tokens = text.split(/(\n{2,})/);
28
- for (let i = 0; i < tokens.length; i++) {
29
- const token = tokens[i];
30
- if (i % 2 === 0) {
31
- if (token) paragraphs.push(token);
32
- continue;
33
- }
34
- const pairsOfNewlines = Math.floor(token.length / 2);
35
- const blankParagraphs = Math.max(0, pairsOfNewlines - 2);
36
- for (let j = 0; j < blankParagraphs; j++) {
37
- paragraphs.push("\n\n");
38
- }
39
- }
40
- return paragraphs;
15
+ const paragraphs = [];
16
+ const tokens = text.split(/(\n{2,})/);
17
+ for (let i = 0; i < tokens.length; i++) {
18
+ const token = tokens[i];
19
+ if (i % 2 === 0) {
20
+ if (token) paragraphs.push(token);
21
+ continue;
22
+ }
23
+ const pairsOfNewlines = Math.floor(token.length / 2);
24
+ const blankParagraphs = Math.max(0, pairsOfNewlines - 2);
25
+ for (let j = 0; j < blankParagraphs; j++) paragraphs.push("\n\n");
26
+ }
27
+ return paragraphs;
41
28
  };
29
+ /**
30
+ * Determine whether two paragraphs match – either exactly, or by sharing the
31
+ * same "special-character signature".
32
+ */
42
33
  const paragraphMatches = (paragraph, baseParagraph, paragraphSignature, baseSignature) => {
43
- if (paragraph === baseParagraph) return true;
44
- if (paragraphSignature.length !== baseSignature.length) return false;
45
- for (let i = 0; i < paragraphSignature.length; i++) {
46
- if (paragraphSignature[i].char !== baseSignature[i].char) {
47
- return false;
48
- }
49
- }
50
- return true;
34
+ if (paragraph === baseParagraph) return true;
35
+ if (paragraphSignature.length !== baseSignature.length) return false;
36
+ for (let i = 0; i < paragraphSignature.length; i++) if (paragraphSignature[i].char !== baseSignature[i].char) return false;
37
+ return true;
51
38
  };
39
+ /**
40
+ * Re-order `textToReorder` so that its paragraphs follow the ordering found in
41
+ * `baseFileContent`, while preserving any extra paragraphs (those not present
42
+ * in the base file) in a position that is intuitive for a human reader: right
43
+ * after the closest preceding paragraph coming from the base file.
44
+ */
52
45
  const reorderParagraphs = (textToReorder, baseFileContent) => {
53
- const baseFileParagraphs = splitByParagraph(baseFileContent);
54
- const textToReorderParagraphs = splitByParagraph(textToReorder);
55
- const baseSignatures = baseFileParagraphs.map((p) => (0, import_listSpecialChars.listSpecialChars)(p));
56
- const textSignatures = textToReorderParagraphs.map(
57
- (p) => (0, import_listSpecialChars.listSpecialChars)(p)
58
- );
59
- const firstMatchIndexForBase = Array(
60
- baseFileParagraphs.length
61
- ).fill(-1);
62
- const paragraphMatchedBaseIdx = Array(
63
- textToReorderParagraphs.length
64
- ).fill(null);
65
- for (let i = 0; i < textToReorderParagraphs.length; i++) {
66
- const paragraph = textToReorderParagraphs[i];
67
- const sig = textSignatures[i];
68
- let foundIdx = baseFileParagraphs.findIndex(
69
- (baseParagraph, idx) => firstMatchIndexForBase[idx] === -1 && paragraph === baseParagraph
70
- );
71
- if (foundIdx === -1) {
72
- foundIdx = baseFileParagraphs.findIndex(
73
- (baseParagraph, idx) => firstMatchIndexForBase[idx] === -1 && paragraphMatches(paragraph, baseParagraph, sig, baseSignatures[idx])
74
- );
75
- }
76
- if (foundIdx !== -1) {
77
- firstMatchIndexForBase[foundIdx] = i;
78
- paragraphMatchedBaseIdx[i] = foundIdx;
79
- }
80
- }
81
- const insertAfterBaseIdx = Array(
82
- textToReorderParagraphs.length
83
- ).fill(-1);
84
- let maxBaseIdxEncountered = -1;
85
- for (let i = 0; i < textToReorderParagraphs.length; i++) {
86
- const matchedBase = paragraphMatchedBaseIdx[i];
87
- if (matchedBase !== null) {
88
- if (matchedBase > maxBaseIdxEncountered) {
89
- maxBaseIdxEncountered = matchedBase;
90
- }
91
- } else {
92
- insertAfterBaseIdx[i] = maxBaseIdxEncountered;
93
- }
94
- }
95
- const result = [];
96
- const extraParagraphsBuckets = {};
97
- insertAfterBaseIdx.forEach((afterIdx, paragraphIdx) => {
98
- if (afterIdx === -1) return;
99
- extraParagraphsBuckets[afterIdx] = extraParagraphsBuckets[afterIdx] || [];
100
- extraParagraphsBuckets[afterIdx].push(paragraphIdx);
101
- });
102
- for (let bIdx = 0; bIdx < baseFileParagraphs.length; bIdx++) {
103
- const matchedParagraphIdx = firstMatchIndexForBase[bIdx];
104
- if (matchedParagraphIdx !== -1) {
105
- result.push(textToReorderParagraphs[matchedParagraphIdx]);
106
- }
107
- if (extraParagraphsBuckets[bIdx]) {
108
- extraParagraphsBuckets[bIdx].forEach((pIdx) => {
109
- result.push(textToReorderParagraphs[pIdx]);
110
- });
111
- }
112
- }
113
- const leadingExtras = [];
114
- insertAfterBaseIdx.forEach((afterIdx, pIdx) => {
115
- if (afterIdx === -1 && paragraphMatchedBaseIdx[pIdx] === null) {
116
- leadingExtras.push(textToReorderParagraphs[pIdx]);
117
- }
118
- });
119
- return [...leadingExtras, ...result].join("\n\n");
46
+ const baseFileParagraphs = splitByParagraph(baseFileContent);
47
+ const textToReorderParagraphs = splitByParagraph(textToReorder);
48
+ const baseSignatures = baseFileParagraphs.map((p) => require_utils_listSpecialChars.listSpecialChars(p));
49
+ const textSignatures = textToReorderParagraphs.map((p) => require_utils_listSpecialChars.listSpecialChars(p));
50
+ const firstMatchIndexForBase = Array(baseFileParagraphs.length).fill(-1);
51
+ const paragraphMatchedBaseIdx = Array(textToReorderParagraphs.length).fill(null);
52
+ for (let i = 0; i < textToReorderParagraphs.length; i++) {
53
+ const paragraph = textToReorderParagraphs[i];
54
+ const sig = textSignatures[i];
55
+ let foundIdx = baseFileParagraphs.findIndex((baseParagraph, idx) => firstMatchIndexForBase[idx] === -1 && paragraph === baseParagraph);
56
+ if (foundIdx === -1) foundIdx = baseFileParagraphs.findIndex((baseParagraph, idx) => firstMatchIndexForBase[idx] === -1 && paragraphMatches(paragraph, baseParagraph, sig, baseSignatures[idx]));
57
+ if (foundIdx !== -1) {
58
+ firstMatchIndexForBase[foundIdx] = i;
59
+ paragraphMatchedBaseIdx[i] = foundIdx;
60
+ }
61
+ }
62
+ const insertAfterBaseIdx = Array(textToReorderParagraphs.length).fill(-1);
63
+ let maxBaseIdxEncountered = -1;
64
+ for (let i = 0; i < textToReorderParagraphs.length; i++) {
65
+ const matchedBase = paragraphMatchedBaseIdx[i];
66
+ if (matchedBase !== null) {
67
+ if (matchedBase > maxBaseIdxEncountered) maxBaseIdxEncountered = matchedBase;
68
+ } else insertAfterBaseIdx[i] = maxBaseIdxEncountered;
69
+ }
70
+ const result = [];
71
+ const extraParagraphsBuckets = {};
72
+ insertAfterBaseIdx.forEach((afterIdx, paragraphIdx) => {
73
+ if (afterIdx === -1) return;
74
+ extraParagraphsBuckets[afterIdx] = extraParagraphsBuckets[afterIdx] || [];
75
+ extraParagraphsBuckets[afterIdx].push(paragraphIdx);
76
+ });
77
+ for (let bIdx = 0; bIdx < baseFileParagraphs.length; bIdx++) {
78
+ const matchedParagraphIdx = firstMatchIndexForBase[bIdx];
79
+ if (matchedParagraphIdx !== -1) result.push(textToReorderParagraphs[matchedParagraphIdx]);
80
+ if (extraParagraphsBuckets[bIdx]) extraParagraphsBuckets[bIdx].forEach((pIdx) => {
81
+ result.push(textToReorderParagraphs[pIdx]);
82
+ });
83
+ }
84
+ const leadingExtras = [];
85
+ insertAfterBaseIdx.forEach((afterIdx, pIdx) => {
86
+ if (afterIdx === -1 && paragraphMatchedBaseIdx[pIdx] === null) leadingExtras.push(textToReorderParagraphs[pIdx]);
87
+ });
88
+ return [...leadingExtras, ...result].join("\n\n");
120
89
  };
121
- // Annotate the CommonJS export names for ESM import in node:
122
- 0 && (module.exports = {
123
- reorderParagraphs
124
- });
90
+
91
+ //#endregion
92
+ exports.reorderParagraphs = reorderParagraphs;
125
93
  //# sourceMappingURL=reorderParagraphs.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/reorderParagraphs.ts"],"sourcesContent":["import { listSpecialChars } from './listSpecialChars';\n\n/**\n * Split a text into paragraphs.\n *\n * We consider a paragraph boundary to be a block of at least two consecutive\n * new-lines that is immediately followed by a non-white-space character. This\n * way, internal blank lines that are part of the same paragraph (e.g. a list\n * item that purposely contains a visual break) are preserved while true\n * paragraph breaks – the ones generated when calling `arr.join(\"\\n\\n\")` in\n * the tests – are still detected.\n */\nconst splitByParagraph = (text: string): string[] => {\n const paragraphs: string[] = [];\n\n // Capture the delimiter so that we can inspect how many new-lines it\n // contains. We know that the test strings only use LF, so we keep the\n // regex simple here.\n const tokens = text.split(/(\\n{2,})/);\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n\n // Even-indexed tokens are the actual paragraph contents.\n if (i % 2 === 0) {\n if (token) paragraphs.push(token);\n continue;\n }\n\n // Odd-indexed tokens are the delimiters (>= two consecutive new-lines).\n // The first and last pairs represent the natural separators that are\n // added when paragraphs are later joined with \"\\n\\n\". Any additional\n // pairs in between correspond to *explicit* blank paragraphs that were\n // present in the original text and must therefore be preserved.\n const pairsOfNewlines = Math.floor(token.length / 2);\n const blankParagraphs = Math.max(0, pairsOfNewlines - 2);\n\n for (let j = 0; j < blankParagraphs; j++) {\n paragraphs.push('\\n\\n');\n }\n }\n\n return paragraphs;\n};\n\n/**\n * Determine whether two paragraphs match – either exactly, or by sharing the\n * same \"special-character signature\".\n */\nconst paragraphMatches = (\n paragraph: string,\n baseParagraph: string,\n paragraphSignature: ReturnType<typeof listSpecialChars>,\n baseSignature: ReturnType<typeof listSpecialChars>\n): boolean => {\n if (paragraph === baseParagraph) return true;\n // fallback to special-character signature comparison\n if (paragraphSignature.length !== baseSignature.length) return false;\n\n for (let i = 0; i < paragraphSignature.length; i++) {\n if (paragraphSignature[i].char !== baseSignature[i].char) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Re-order `textToReorder` so that its paragraphs follow the ordering found in\n * `baseFileContent`, while preserving any extra paragraphs (those not present\n * in the base file) in a position that is intuitive for a human reader: right\n * after the closest preceding paragraph coming from the base file.\n */\nexport const reorderParagraphs = (\n textToReorder: string,\n baseFileContent: string\n): string => {\n // 1. Split both texts into paragraphs and pre-compute their signatures.\n const baseFileParagraphs = splitByParagraph(baseFileContent);\n const textToReorderParagraphs = splitByParagraph(textToReorder);\n\n const baseSignatures = baseFileParagraphs.map((p) => listSpecialChars(p));\n const textSignatures = textToReorderParagraphs.map((p) =>\n listSpecialChars(p)\n );\n\n // 2. For every paragraph in the text to reorder, find the *first* base\n // paragraph it matches. We only allow each base paragraph to be matched\n // once. Any further identical paragraphs will be treated as \"extra\" and\n // will be positioned later on, next to their closest neighbour.\n const firstMatchIndexForBase: number[] = Array(\n baseFileParagraphs.length\n ).fill(-1);\n const paragraphMatchedBaseIdx: (number | null)[] = Array(\n textToReorderParagraphs.length\n ).fill(null);\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const paragraph = textToReorderParagraphs[i];\n const sig = textSignatures[i];\n\n // exact match pass first for performance\n let foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 && paragraph === baseParagraph\n );\n\n if (foundIdx === -1) {\n // fallback to the signature comparison\n foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 &&\n paragraphMatches(paragraph, baseParagraph, sig, baseSignatures[idx])\n );\n }\n\n if (foundIdx !== -1) {\n firstMatchIndexForBase[foundIdx] = i;\n paragraphMatchedBaseIdx[i] = foundIdx;\n }\n }\n\n // 3. For the paragraphs that *didn't* get matched to a base paragraph, we\n // record the highest-numbered base paragraph that was matched *before* it\n // in the original text. The extra paragraph will later be placed right\n // after that paragraph in the final ordering.\n const insertAfterBaseIdx: number[] = Array(\n textToReorderParagraphs.length\n ).fill(-1);\n let maxBaseIdxEncountered = -1;\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const matchedBase = paragraphMatchedBaseIdx[i];\n\n if (matchedBase !== null) {\n if (matchedBase > maxBaseIdxEncountered) {\n maxBaseIdxEncountered = matchedBase;\n }\n } else {\n insertAfterBaseIdx[i] = maxBaseIdxEncountered;\n }\n }\n\n // 4. Build the final, reordered list of paragraphs.\n const result: string[] = [];\n\n // Helper: quickly retrieve all indices of paragraphs that should be inserted\n // after a given base index, while keeping their original order.\n const extraParagraphsBuckets: Record<number, number[]> = {};\n insertAfterBaseIdx.forEach((afterIdx, paragraphIdx) => {\n if (afterIdx === -1) return; // will be handled later (if any)\n extraParagraphsBuckets[afterIdx] = extraParagraphsBuckets[afterIdx] || [];\n extraParagraphsBuckets[afterIdx].push(paragraphIdx);\n });\n\n for (let bIdx = 0; bIdx < baseFileParagraphs.length; bIdx++) {\n const matchedParagraphIdx = firstMatchIndexForBase[bIdx];\n\n if (matchedParagraphIdx !== -1) {\n result.push(textToReorderParagraphs[matchedParagraphIdx]);\n }\n\n if (extraParagraphsBuckets[bIdx]) {\n extraParagraphsBuckets[bIdx].forEach((pIdx) => {\n result.push(textToReorderParagraphs[pIdx]);\n });\n }\n }\n\n // Finally, if there were extra paragraphs appearing *before* any matched\n // base paragraph (insertAfterBaseIdx === -1), we prepend them to the output\n // in their original order.\n const leadingExtras: string[] = [];\n insertAfterBaseIdx.forEach((afterIdx, pIdx) => {\n if (afterIdx === -1 && paragraphMatchedBaseIdx[pIdx] === null) {\n leadingExtras.push(textToReorderParagraphs[pIdx]);\n }\n });\n\n return [...leadingExtras, ...result].join('\\n\\n');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiC;AAYjC,MAAM,mBAAmB,CAAC,SAA2B;AACnD,QAAM,aAAuB,CAAC;AAK9B,QAAM,SAAS,KAAK,MAAM,UAAU;AAEpC,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,QAA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MAAM,wBAAwB,IAAI,MAAM,MAAM;AAC7D,oBAAc,KAAK,wBAAwB,IAAI,CAAC;AAAA,IAClD;AAAA,EACF,CAAC;AAED,SAAO,CAAC,GAAG,eAAe,GAAG,MAAM,EAAE,KAAK,MAAM;AAClD;","names":[]}
1
+ {"version":3,"file":"reorderParagraphs.cjs","names":["paragraphs: string[]","listSpecialChars","firstMatchIndexForBase: number[]","paragraphMatchedBaseIdx: (number | null)[]","insertAfterBaseIdx: number[]","result: string[]","extraParagraphsBuckets: Record<number, number[]>","leadingExtras: string[]"],"sources":["../../../src/utils/reorderParagraphs.ts"],"sourcesContent":["import { listSpecialChars } from './listSpecialChars';\n\n/**\n * Split a text into paragraphs.\n *\n * We consider a paragraph boundary to be a block of at least two consecutive\n * new-lines that is immediately followed by a non-white-space character. This\n * way, internal blank lines that are part of the same paragraph (e.g. a list\n * item that purposely contains a visual break) are preserved while true\n * paragraph breaks – the ones generated when calling `arr.join(\"\\n\\n\")` in\n * the tests – are still detected.\n */\nconst splitByParagraph = (text: string): string[] => {\n const paragraphs: string[] = [];\n\n // Capture the delimiter so that we can inspect how many new-lines it\n // contains. We know that the test strings only use LF, so we keep the\n // regex simple here.\n const tokens = text.split(/(\\n{2,})/);\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n\n // Even-indexed tokens are the actual paragraph contents.\n if (i % 2 === 0) {\n if (token) paragraphs.push(token);\n continue;\n }\n\n // Odd-indexed tokens are the delimiters (>= two consecutive new-lines).\n // The first and last pairs represent the natural separators that are\n // added when paragraphs are later joined with \"\\n\\n\". Any additional\n // pairs in between correspond to *explicit* blank paragraphs that were\n // present in the original text and must therefore be preserved.\n const pairsOfNewlines = Math.floor(token.length / 2);\n const blankParagraphs = Math.max(0, pairsOfNewlines - 2);\n\n for (let j = 0; j < blankParagraphs; j++) {\n paragraphs.push('\\n\\n');\n }\n }\n\n return paragraphs;\n};\n\n/**\n * Determine whether two paragraphs match – either exactly, or by sharing the\n * same \"special-character signature\".\n */\nconst paragraphMatches = (\n paragraph: string,\n baseParagraph: string,\n paragraphSignature: ReturnType<typeof listSpecialChars>,\n baseSignature: ReturnType<typeof listSpecialChars>\n): boolean => {\n if (paragraph === baseParagraph) return true;\n // fallback to special-character signature comparison\n if (paragraphSignature.length !== baseSignature.length) return false;\n\n for (let i = 0; i < paragraphSignature.length; i++) {\n if (paragraphSignature[i].char !== baseSignature[i].char) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Re-order `textToReorder` so that its paragraphs follow the ordering found in\n * `baseFileContent`, while preserving any extra paragraphs (those not present\n * in the base file) in a position that is intuitive for a human reader: right\n * after the closest preceding paragraph coming from the base file.\n */\nexport const reorderParagraphs = (\n textToReorder: string,\n baseFileContent: string\n): string => {\n // 1. Split both texts into paragraphs and pre-compute their signatures.\n const baseFileParagraphs = splitByParagraph(baseFileContent);\n const textToReorderParagraphs = splitByParagraph(textToReorder);\n\n const baseSignatures = baseFileParagraphs.map((p) => listSpecialChars(p));\n const textSignatures = textToReorderParagraphs.map((p) =>\n listSpecialChars(p)\n );\n\n // 2. For every paragraph in the text to reorder, find the *first* base\n // paragraph it matches. We only allow each base paragraph to be matched\n // once. Any further identical paragraphs will be treated as \"extra\" and\n // will be positioned later on, next to their closest neighbour.\n const firstMatchIndexForBase: number[] = Array(\n baseFileParagraphs.length\n ).fill(-1);\n const paragraphMatchedBaseIdx: (number | null)[] = Array(\n textToReorderParagraphs.length\n ).fill(null);\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const paragraph = textToReorderParagraphs[i];\n const sig = textSignatures[i];\n\n // exact match pass first for performance\n let foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 && paragraph === baseParagraph\n );\n\n if (foundIdx === -1) {\n // fallback to the signature comparison\n foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 &&\n paragraphMatches(paragraph, baseParagraph, sig, baseSignatures[idx])\n );\n }\n\n if (foundIdx !== -1) {\n firstMatchIndexForBase[foundIdx] = i;\n paragraphMatchedBaseIdx[i] = foundIdx;\n }\n }\n\n // 3. For the paragraphs that *didn't* get matched to a base paragraph, we\n // record the highest-numbered base paragraph that was matched *before* it\n // in the original text. The extra paragraph will later be placed right\n // after that paragraph in the final ordering.\n const insertAfterBaseIdx: number[] = Array(\n textToReorderParagraphs.length\n ).fill(-1);\n let maxBaseIdxEncountered = -1;\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const matchedBase = paragraphMatchedBaseIdx[i];\n\n if (matchedBase !== null) {\n if (matchedBase > maxBaseIdxEncountered) {\n maxBaseIdxEncountered = matchedBase;\n }\n } else {\n insertAfterBaseIdx[i] = maxBaseIdxEncountered;\n }\n }\n\n // 4. Build the final, reordered list of paragraphs.\n const result: string[] = [];\n\n // Helper: quickly retrieve all indices of paragraphs that should be inserted\n // after a given base index, while keeping their original order.\n const extraParagraphsBuckets: Record<number, number[]> = {};\n insertAfterBaseIdx.forEach((afterIdx, paragraphIdx) => {\n if (afterIdx === -1) return; // will be handled later (if any)\n extraParagraphsBuckets[afterIdx] = extraParagraphsBuckets[afterIdx] || [];\n extraParagraphsBuckets[afterIdx].push(paragraphIdx);\n });\n\n for (let bIdx = 0; bIdx < baseFileParagraphs.length; bIdx++) {\n const matchedParagraphIdx = firstMatchIndexForBase[bIdx];\n\n if (matchedParagraphIdx !== -1) {\n result.push(textToReorderParagraphs[matchedParagraphIdx]);\n }\n\n if (extraParagraphsBuckets[bIdx]) {\n extraParagraphsBuckets[bIdx].forEach((pIdx) => {\n result.push(textToReorderParagraphs[pIdx]);\n });\n }\n }\n\n // Finally, if there were extra paragraphs appearing *before* any matched\n // base paragraph (insertAfterBaseIdx === -1), we prepend them to the output\n // in their original order.\n const leadingExtras: string[] = [];\n insertAfterBaseIdx.forEach((afterIdx, pIdx) => {\n if (afterIdx === -1 && paragraphMatchedBaseIdx[pIdx] === null) {\n leadingExtras.push(textToRe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Descriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var watch_exports = {};
20
- __export(watch_exports, {
21
- watchContentDeclaration: () => watchContentDeclaration
22
- });
23
- module.exports = __toCommonJS(watch_exports);
24
- var import_chokidar = require("@intlayer/chokidar");
25
- var import_config = require("@intlayer/config");
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let __intlayer_chokidar = require("@intlayer/chokidar");
3
+ __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
4
+ let __intlayer_config = require("@intlayer/config");
5
+ __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
6
+
7
+ //#region src/watch.ts
8
+ /**
9
+ * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.
10
+ * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}
11
+ */
26
12
  const watchContentDeclaration = async (options) => {
27
- const config = (0, import_config.getConfiguration)(options?.configOptions);
28
- const appLogger = (0, import_config.getAppLogger)(config);
29
- if (options?.with) {
30
- (0, import_chokidar.runParallel)(options.with);
31
- }
32
- appLogger("Watching Intlayer content declarations");
33
- (0, import_chokidar.watch)({
34
- persistent: true,
35
- skipPrepare: options?.skipPrepare ?? false
36
- });
13
+ const appLogger = (0, __intlayer_config.getAppLogger)((0, __intlayer_config.getConfiguration)(options?.configOptions));
14
+ if (options?.with) (0, __intlayer_chokidar.runParallel)(options.with);
15
+ appLogger("Watching Intlayer content declarations");
16
+ (0, __intlayer_chokidar.watch)({
17
+ persistent: true,
18
+ skipPrepare: options?.skipPrepare ?? false
19
+ });
37
20
  };
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- watchContentDeclaration
41
- });
21
+
22
+ //#endregion
23
+ exports.watchContentDeclaration = watchContentDeclaration;
42
24
  //# sourceMappingURL=watch.cjs.map