@intlayer/core 9.0.0-canary.17 → 9.0.0-canary.18

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 (484) hide show
  1. package/dist/cjs/deepTransformPlugins/getEditedContent.cjs +2 -1
  2. package/dist/cjs/deepTransformPlugins/getEditedContent.cjs.map +1 -1
  3. package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
  4. package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
  5. package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
  6. package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
  7. package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
  8. package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
  9. package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
  10. package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
  11. package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +1 -1
  12. package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
  13. package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
  14. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
  15. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
  16. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
  17. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
  18. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
  19. package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
  20. package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +1 -2
  21. package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
  22. package/dist/cjs/dictionaryManipulator/mergeQualifiedDictionaries.cjs +0 -1
  23. package/dist/cjs/dictionaryManipulator/mergeQualifiedDictionaries.cjs.map +1 -1
  24. package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
  25. package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +0 -1
  26. package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
  27. package/dist/cjs/dictionaryManipulator/qualifiedDictionary.cjs.map +1 -1
  28. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
  29. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
  30. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
  31. package/dist/cjs/formatters/compact.cjs +1 -2
  32. package/dist/cjs/formatters/compact.cjs.map +1 -1
  33. package/dist/cjs/formatters/currency.cjs +1 -2
  34. package/dist/cjs/formatters/currency.cjs.map +1 -1
  35. package/dist/cjs/formatters/date.cjs +1 -3
  36. package/dist/cjs/formatters/date.cjs.map +1 -1
  37. package/dist/cjs/formatters/list.cjs +1 -2
  38. package/dist/cjs/formatters/list.cjs.map +1 -1
  39. package/dist/cjs/formatters/number.cjs +1 -2
  40. package/dist/cjs/formatters/number.cjs.map +1 -1
  41. package/dist/cjs/formatters/percentage.cjs +1 -2
  42. package/dist/cjs/formatters/percentage.cjs.map +1 -1
  43. package/dist/cjs/formatters/relativeTime.cjs +1 -2
  44. package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
  45. package/dist/cjs/formatters/units.cjs +1 -2
  46. package/dist/cjs/formatters/units.cjs.map +1 -1
  47. package/dist/cjs/interpreter/getCondition.cjs.map +1 -1
  48. package/dist/cjs/interpreter/getContent/deepTransform.cjs +3 -2
  49. package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
  50. package/dist/cjs/interpreter/getContent/getContent.cjs +0 -1
  51. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  52. package/dist/cjs/interpreter/getContent/plugins.cjs +4 -2
  53. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  54. package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
  55. package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
  56. package/dist/cjs/interpreter/getGender.cjs.map +1 -1
  57. package/dist/cjs/interpreter/getHTML.cjs.map +1 -1
  58. package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
  59. package/dist/cjs/interpreter/getIntlayer.cjs +2 -2
  60. package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
  61. package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
  62. package/dist/cjs/interpreter/getPlural.cjs +1 -1
  63. package/dist/cjs/interpreter/getPlural.cjs.map +1 -1
  64. package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
  65. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
  66. package/dist/cjs/localization/comparePaths.cjs.map +1 -1
  67. package/dist/cjs/localization/domainUtils.cjs.map +1 -1
  68. package/dist/cjs/localization/generateSitemap.cjs +2 -1
  69. package/dist/cjs/localization/generateSitemap.cjs.map +1 -1
  70. package/dist/cjs/localization/getBrowserLocale.cjs +7 -4
  71. package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
  72. package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
  73. package/dist/cjs/localization/getLocale.cjs +0 -1
  74. package/dist/cjs/localization/getLocale.cjs.map +1 -1
  75. package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
  76. package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
  77. package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
  78. package/dist/cjs/localization/getLocalizedUrl.cjs +0 -1
  79. package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
  80. package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
  81. package/dist/cjs/localization/getPathWithoutLocale.cjs +0 -1
  82. package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
  83. package/dist/cjs/localization/getPrefix.cjs +0 -1
  84. package/dist/cjs/localization/getPrefix.cjs.map +1 -1
  85. package/dist/cjs/localization/localeDetector.cjs +2 -1
  86. package/dist/cjs/localization/localeDetector.cjs.map +1 -1
  87. package/dist/cjs/localization/localeMapper.cjs +0 -1
  88. package/dist/cjs/localization/localeMapper.cjs.map +1 -1
  89. package/dist/cjs/localization/localeResolver.cjs +0 -1
  90. package/dist/cjs/localization/localeResolver.cjs.map +1 -1
  91. package/dist/cjs/localization/rewriteUtils.cjs +2 -1
  92. package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
  93. package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
  94. package/dist/cjs/markdown/compiler.cjs +2 -1
  95. package/dist/cjs/markdown/compiler.cjs.map +1 -1
  96. package/dist/cjs/markdown/constants.cjs.map +1 -1
  97. package/dist/cjs/markdown/parser.cjs.map +1 -1
  98. package/dist/cjs/markdown/renderer.cjs.map +1 -1
  99. package/dist/cjs/markdown/utils.cjs.map +1 -1
  100. package/dist/cjs/messageFormat/ICU.cjs +15 -9
  101. package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
  102. package/dist/cjs/messageFormat/i18next.cjs +12 -7
  103. package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
  104. package/dist/cjs/messageFormat/navigatePath.cjs.map +1 -1
  105. package/dist/cjs/messageFormat/po.cjs.map +1 -1
  106. package/dist/cjs/messageFormat/resolveMessage.cjs +11 -8
  107. package/dist/cjs/messageFormat/resolveMessage.cjs.map +1 -1
  108. package/dist/cjs/messageFormat/verify-icu-format.cjs.map +1 -1
  109. package/dist/cjs/messageFormat/vue-i18n.cjs +2 -1
  110. package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
  111. package/dist/cjs/transpiler/condition/condition.cjs +0 -1
  112. package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
  113. package/dist/cjs/transpiler/enumeration/enumeration.cjs +0 -1
  114. package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
  115. package/dist/cjs/transpiler/file/file.cjs +2 -2
  116. package/dist/cjs/transpiler/file/file.cjs.map +1 -1
  117. package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
  118. package/dist/cjs/transpiler/gender/gender.cjs +0 -1
  119. package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
  120. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
  121. package/dist/cjs/transpiler/html/html.cjs +0 -1
  122. package/dist/cjs/transpiler/html/html.cjs.map +1 -1
  123. package/dist/cjs/transpiler/html/htmlTags.cjs.map +1 -1
  124. package/dist/cjs/transpiler/html/validateHTML.cjs +1 -1
  125. package/dist/cjs/transpiler/html/validateHTML.cjs.map +1 -1
  126. package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
  127. package/dist/cjs/transpiler/insertion/insertion.cjs +0 -1
  128. package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
  129. package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
  130. package/dist/cjs/transpiler/markdown/markdown.cjs +0 -1
  131. package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
  132. package/dist/cjs/transpiler/markdown/validateMarkdown.cjs.map +1 -1
  133. package/dist/cjs/transpiler/nesting/nesting.cjs +0 -1
  134. package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
  135. package/dist/cjs/transpiler/plural/plural.cjs +0 -1
  136. package/dist/cjs/transpiler/plural/plural.cjs.map +1 -1
  137. package/dist/cjs/transpiler/translation/translation.cjs +0 -1
  138. package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
  139. package/dist/cjs/utils/checkIsURLAbsolute.cjs.map +1 -1
  140. package/dist/cjs/utils/cookieExpiry.cjs.map +1 -1
  141. package/dist/cjs/utils/getCookie.cjs.map +1 -1
  142. package/dist/cjs/utils/intl.cjs +101 -26
  143. package/dist/cjs/utils/intl.cjs.map +1 -1
  144. package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
  145. package/dist/cjs/utils/localeStorage.cjs +0 -1
  146. package/dist/cjs/utils/localeStorage.cjs.map +1 -1
  147. package/dist/cjs/utils/parseYaml.cjs +1 -1
  148. package/dist/cjs/utils/parseYaml.cjs.map +1 -1
  149. package/dist/cjs/utils/stringifyYaml.cjs +1 -1
  150. package/dist/cjs/utils/stringifyYaml.cjs.map +1 -1
  151. package/dist/esm/deepTransformPlugins/getEditedContent.mjs +2 -1
  152. package/dist/esm/deepTransformPlugins/getEditedContent.mjs.map +1 -1
  153. package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
  154. package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
  155. package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
  156. package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
  157. package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
  158. package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
  159. package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
  160. package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
  161. package/dist/esm/deepTransformPlugins/getSplittedContent.mjs +1 -1
  162. package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
  163. package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
  164. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
  165. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
  166. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
  167. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
  168. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
  169. package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
  170. package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +1 -1
  171. package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
  172. package/dist/esm/dictionaryManipulator/mergeQualifiedDictionaries.mjs.map +1 -1
  173. package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
  174. package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
  175. package/dist/esm/dictionaryManipulator/qualifiedDictionary.mjs.map +1 -1
  176. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
  177. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
  178. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
  179. package/dist/esm/formatters/compact.mjs +1 -1
  180. package/dist/esm/formatters/compact.mjs.map +1 -1
  181. package/dist/esm/formatters/currency.mjs +1 -1
  182. package/dist/esm/formatters/currency.mjs.map +1 -1
  183. package/dist/esm/formatters/date.mjs +1 -2
  184. package/dist/esm/formatters/date.mjs.map +1 -1
  185. package/dist/esm/formatters/list.mjs +1 -1
  186. package/dist/esm/formatters/list.mjs.map +1 -1
  187. package/dist/esm/formatters/number.mjs +1 -1
  188. package/dist/esm/formatters/number.mjs.map +1 -1
  189. package/dist/esm/formatters/percentage.mjs +1 -1
  190. package/dist/esm/formatters/percentage.mjs.map +1 -1
  191. package/dist/esm/formatters/relativeTime.mjs +1 -1
  192. package/dist/esm/formatters/relativeTime.mjs.map +1 -1
  193. package/dist/esm/formatters/units.mjs +1 -1
  194. package/dist/esm/formatters/units.mjs.map +1 -1
  195. package/dist/esm/interpreter/getCondition.mjs.map +1 -1
  196. package/dist/esm/interpreter/getContent/deepTransform.mjs +3 -2
  197. package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
  198. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  199. package/dist/esm/interpreter/getContent/plugins.mjs +4 -2
  200. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  201. package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
  202. package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
  203. package/dist/esm/interpreter/getGender.mjs.map +1 -1
  204. package/dist/esm/interpreter/getHTML.mjs.map +1 -1
  205. package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
  206. package/dist/esm/interpreter/getIntlayer.mjs +2 -1
  207. package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
  208. package/dist/esm/interpreter/getNesting.mjs.map +1 -1
  209. package/dist/esm/interpreter/getPlural.mjs +1 -1
  210. package/dist/esm/interpreter/getPlural.mjs.map +1 -1
  211. package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
  212. package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
  213. package/dist/esm/localization/comparePaths.mjs.map +1 -1
  214. package/dist/esm/localization/domainUtils.mjs.map +1 -1
  215. package/dist/esm/localization/generateSitemap.mjs +2 -1
  216. package/dist/esm/localization/generateSitemap.mjs.map +1 -1
  217. package/dist/esm/localization/getBrowserLocale.mjs +7 -3
  218. package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
  219. package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
  220. package/dist/esm/localization/getLocale.mjs.map +1 -1
  221. package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
  222. package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
  223. package/dist/esm/localization/getLocaleName.mjs.map +1 -1
  224. package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
  225. package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
  226. package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
  227. package/dist/esm/localization/getPrefix.mjs.map +1 -1
  228. package/dist/esm/localization/localeDetector.mjs +2 -1
  229. package/dist/esm/localization/localeDetector.mjs.map +1 -1
  230. package/dist/esm/localization/localeMapper.mjs.map +1 -1
  231. package/dist/esm/localization/localeResolver.mjs.map +1 -1
  232. package/dist/esm/localization/rewriteUtils.mjs +2 -1
  233. package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
  234. package/dist/esm/localization/validatePrefix.mjs.map +1 -1
  235. package/dist/esm/markdown/compiler.mjs +2 -1
  236. package/dist/esm/markdown/compiler.mjs.map +1 -1
  237. package/dist/esm/markdown/constants.mjs.map +1 -1
  238. package/dist/esm/markdown/parser.mjs.map +1 -1
  239. package/dist/esm/markdown/renderer.mjs.map +1 -1
  240. package/dist/esm/markdown/utils.mjs.map +1 -1
  241. package/dist/esm/messageFormat/ICU.mjs +15 -9
  242. package/dist/esm/messageFormat/ICU.mjs.map +1 -1
  243. package/dist/esm/messageFormat/i18next.mjs +12 -7
  244. package/dist/esm/messageFormat/i18next.mjs.map +1 -1
  245. package/dist/esm/messageFormat/navigatePath.mjs.map +1 -1
  246. package/dist/esm/messageFormat/po.mjs.map +1 -1
  247. package/dist/esm/messageFormat/resolveMessage.mjs +11 -8
  248. package/dist/esm/messageFormat/resolveMessage.mjs.map +1 -1
  249. package/dist/esm/messageFormat/verify-icu-format.mjs.map +1 -1
  250. package/dist/esm/messageFormat/vue-i18n.mjs +2 -1
  251. package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
  252. package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
  253. package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
  254. package/dist/esm/transpiler/file/file.mjs +2 -1
  255. package/dist/esm/transpiler/file/file.mjs.map +1 -1
  256. package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
  257. package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
  258. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
  259. package/dist/esm/transpiler/html/html.mjs.map +1 -1
  260. package/dist/esm/transpiler/html/htmlTags.mjs.map +1 -1
  261. package/dist/esm/transpiler/html/validateHTML.mjs +1 -1
  262. package/dist/esm/transpiler/html/validateHTML.mjs.map +1 -1
  263. package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
  264. package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
  265. package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
  266. package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
  267. package/dist/esm/transpiler/markdown/validateMarkdown.mjs.map +1 -1
  268. package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
  269. package/dist/esm/transpiler/plural/plural.mjs.map +1 -1
  270. package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
  271. package/dist/esm/utils/checkIsURLAbsolute.mjs.map +1 -1
  272. package/dist/esm/utils/cookieExpiry.mjs.map +1 -1
  273. package/dist/esm/utils/getCookie.mjs.map +1 -1
  274. package/dist/esm/utils/intl.mjs +100 -25
  275. package/dist/esm/utils/intl.mjs.map +1 -1
  276. package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
  277. package/dist/esm/utils/localeStorage.mjs.map +1 -1
  278. package/dist/esm/utils/parseYaml.mjs +1 -1
  279. package/dist/esm/utils/parseYaml.mjs.map +1 -1
  280. package/dist/esm/utils/stringifyYaml.mjs +1 -1
  281. package/dist/esm/utils/stringifyYaml.mjs.map +1 -1
  282. package/dist/types/deepTransformPlugins/getEditedContent.d.ts +0 -1
  283. package/dist/types/deepTransformPlugins/getEditedContent.d.ts.map +1 -1
  284. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +12 -13
  285. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
  286. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +12 -13
  287. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
  288. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +12 -13
  289. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
  290. package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts +1 -1
  291. package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts.map +1 -1
  292. package/dist/types/deepTransformPlugins/getMaskContent.d.ts +1 -1
  293. package/dist/types/deepTransformPlugins/getMaskContent.d.ts.map +1 -1
  294. package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts +1 -1
  295. package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts.map +1 -1
  296. package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts +0 -1
  297. package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts.map +1 -1
  298. package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts +1 -1
  299. package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts.map +1 -1
  300. package/dist/types/deepTransformPlugins/getSplittedContent.d.ts +1 -2
  301. package/dist/types/deepTransformPlugins/getSplittedContent.d.ts.map +1 -1
  302. package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts +1 -2
  303. package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts.map +1 -1
  304. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts +0 -1
  305. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
  306. package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts +0 -1
  307. package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts.map +1 -1
  308. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +0 -1
  309. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
  310. package/dist/types/dictionaryManipulator/getEmptyNode.d.ts +0 -1
  311. package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
  312. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts +0 -1
  313. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
  314. package/dist/types/dictionaryManipulator/getNodeType.d.ts +0 -1
  315. package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
  316. package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts +0 -1
  317. package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts.map +1 -1
  318. package/dist/types/dictionaryManipulator/mergeQualifiedDictionaries.d.ts +0 -1
  319. package/dist/types/dictionaryManipulator/mergeQualifiedDictionaries.d.ts.map +1 -1
  320. package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts +0 -1
  321. package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts.map +1 -1
  322. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +1 -2
  323. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
  324. package/dist/types/dictionaryManipulator/qualifiedDictionary.d.ts +1 -2
  325. package/dist/types/dictionaryManipulator/qualifiedDictionary.d.ts.map +1 -1
  326. package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts +0 -1
  327. package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts.map +1 -1
  328. package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts +1 -2
  329. package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts.map +1 -1
  330. package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts +0 -1
  331. package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -1
  332. package/dist/types/formatters/compact.d.ts +0 -1
  333. package/dist/types/formatters/compact.d.ts.map +1 -1
  334. package/dist/types/formatters/currency.d.ts +0 -1
  335. package/dist/types/formatters/currency.d.ts.map +1 -1
  336. package/dist/types/formatters/date.d.ts +0 -1
  337. package/dist/types/formatters/date.d.ts.map +1 -1
  338. package/dist/types/formatters/index.d.ts +2 -2
  339. package/dist/types/formatters/list.d.ts +0 -1
  340. package/dist/types/formatters/list.d.ts.map +1 -1
  341. package/dist/types/formatters/number.d.ts +1 -5
  342. package/dist/types/formatters/number.d.ts.map +1 -1
  343. package/dist/types/formatters/percentage.d.ts +1 -5
  344. package/dist/types/formatters/percentage.d.ts.map +1 -1
  345. package/dist/types/formatters/relativeTime.d.ts +0 -1
  346. package/dist/types/formatters/relativeTime.d.ts.map +1 -1
  347. package/dist/types/formatters/units.d.ts +0 -1
  348. package/dist/types/formatters/units.d.ts.map +1 -1
  349. package/dist/types/index.d.ts +11 -2
  350. package/dist/types/interpreter/getCondition.d.ts +1 -0
  351. package/dist/types/interpreter/getCondition.d.ts.map +1 -1
  352. package/dist/types/interpreter/getContent/deepTransform.d.ts +0 -1
  353. package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
  354. package/dist/types/interpreter/getContent/getContent.d.ts +0 -1
  355. package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
  356. package/dist/types/interpreter/getContent/plugins.d.ts +4 -4
  357. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  358. package/dist/types/interpreter/getDictionary.d.ts +1 -1
  359. package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
  360. package/dist/types/interpreter/getEnumeration.d.ts +1 -0
  361. package/dist/types/interpreter/getEnumeration.d.ts.map +1 -1
  362. package/dist/types/interpreter/getGender.d.ts +1 -0
  363. package/dist/types/interpreter/getGender.d.ts.map +1 -1
  364. package/dist/types/interpreter/getHTML.d.ts.map +1 -1
  365. package/dist/types/interpreter/getInsertion.d.ts +2 -1
  366. package/dist/types/interpreter/getInsertion.d.ts.map +1 -1
  367. package/dist/types/interpreter/getIntlayer.d.ts +1 -1
  368. package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
  369. package/dist/types/interpreter/getNesting.d.ts +2 -1
  370. package/dist/types/interpreter/getNesting.d.ts.map +1 -1
  371. package/dist/types/interpreter/getPlural.d.ts +0 -1
  372. package/dist/types/interpreter/getPlural.d.ts.map +1 -1
  373. package/dist/types/interpreter/getTranslation.d.ts +0 -1
  374. package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
  375. package/dist/types/interpreter/index.d.ts +1 -0
  376. package/dist/types/interpreter/splitAndJoinInsertion.d.ts.map +1 -1
  377. package/dist/types/localization/comparePaths.d.ts +0 -1
  378. package/dist/types/localization/comparePaths.d.ts.map +1 -1
  379. package/dist/types/localization/domainUtils.d.ts +0 -1
  380. package/dist/types/localization/domainUtils.d.ts.map +1 -1
  381. package/dist/types/localization/generateSitemap.d.ts +6 -4
  382. package/dist/types/localization/generateSitemap.d.ts.map +1 -1
  383. package/dist/types/localization/getBrowserLocale.d.ts +0 -1
  384. package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
  385. package/dist/types/localization/getHTMLTextDir.d.ts +0 -1
  386. package/dist/types/localization/getHTMLTextDir.d.ts.map +1 -1
  387. package/dist/types/localization/getLocale.d.ts +0 -1
  388. package/dist/types/localization/getLocale.d.ts.map +1 -1
  389. package/dist/types/localization/getLocaleFromPath.d.ts +0 -1
  390. package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -1
  391. package/dist/types/localization/getLocaleLang.d.ts +0 -1
  392. package/dist/types/localization/getLocaleLang.d.ts.map +1 -1
  393. package/dist/types/localization/getLocaleName.d.ts +0 -1
  394. package/dist/types/localization/getLocaleName.d.ts.map +1 -1
  395. package/dist/types/localization/getLocalizedUrl.d.ts +0 -1
  396. package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
  397. package/dist/types/localization/getMultilingualUrls.d.ts +0 -1
  398. package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
  399. package/dist/types/localization/getPathWithoutLocale.d.ts +0 -1
  400. package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
  401. package/dist/types/localization/getPrefix.d.ts +2 -3
  402. package/dist/types/localization/getPrefix.d.ts.map +1 -1
  403. package/dist/types/localization/localeDetector.d.ts +0 -1
  404. package/dist/types/localization/localeDetector.d.ts.map +1 -1
  405. package/dist/types/localization/localeMapper.d.ts +3 -4
  406. package/dist/types/localization/localeMapper.d.ts.map +1 -1
  407. package/dist/types/localization/localeResolver.d.ts +0 -1
  408. package/dist/types/localization/localeResolver.d.ts.map +1 -1
  409. package/dist/types/localization/rewriteUtils.d.ts +2 -3
  410. package/dist/types/localization/rewriteUtils.d.ts.map +1 -1
  411. package/dist/types/localization/validatePrefix.d.ts +0 -1
  412. package/dist/types/localization/validatePrefix.d.ts.map +1 -1
  413. package/dist/types/markdown/compiler.d.ts +0 -1
  414. package/dist/types/markdown/compiler.d.ts.map +1 -1
  415. package/dist/types/markdown/constants.d.ts +48 -38
  416. package/dist/types/markdown/constants.d.ts.map +1 -1
  417. package/dist/types/markdown/index.d.ts +2 -1
  418. package/dist/types/markdown/parser.d.ts +0 -1
  419. package/dist/types/markdown/parser.d.ts.map +1 -1
  420. package/dist/types/markdown/renderer.d.ts +0 -1
  421. package/dist/types/markdown/renderer.d.ts.map +1 -1
  422. package/dist/types/markdown/types.d.ts +44 -24
  423. package/dist/types/markdown/types.d.ts.map +1 -1
  424. package/dist/types/markdown/utils.d.ts +3 -4
  425. package/dist/types/markdown/utils.d.ts.map +1 -1
  426. package/dist/types/messageFormat/ICU.d.ts +2 -3
  427. package/dist/types/messageFormat/ICU.d.ts.map +1 -1
  428. package/dist/types/messageFormat/i18next.d.ts +2 -3
  429. package/dist/types/messageFormat/i18next.d.ts.map +1 -1
  430. package/dist/types/messageFormat/navigatePath.d.ts.map +1 -1
  431. package/dist/types/messageFormat/po.d.ts +2 -3
  432. package/dist/types/messageFormat/po.d.ts.map +1 -1
  433. package/dist/types/messageFormat/resolveMessage.d.ts +0 -1
  434. package/dist/types/messageFormat/resolveMessage.d.ts.map +1 -1
  435. package/dist/types/messageFormat/verify-icu-format.d.ts +1 -1
  436. package/dist/types/messageFormat/vue-i18n.d.ts +2 -3
  437. package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -1
  438. package/dist/types/transpiler/condition/condition.d.ts +0 -1
  439. package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
  440. package/dist/types/transpiler/enumeration/enumeration.d.ts +0 -1
  441. package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
  442. package/dist/types/transpiler/file/file.d.ts +0 -1
  443. package/dist/types/transpiler/file/file.d.ts.map +1 -1
  444. package/dist/types/transpiler/file/fileBrowser.d.ts +0 -1
  445. package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -1
  446. package/dist/types/transpiler/gender/gender.d.ts +0 -1
  447. package/dist/types/transpiler/gender/gender.d.ts.map +1 -1
  448. package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -1
  449. package/dist/types/transpiler/html/html.d.ts +0 -1
  450. package/dist/types/transpiler/html/html.d.ts.map +1 -1
  451. package/dist/types/transpiler/html/htmlTags.d.ts +1 -1
  452. package/dist/types/transpiler/html/htmlTags.d.ts.map +1 -1
  453. package/dist/types/transpiler/html/validateHTML.d.ts.map +1 -1
  454. package/dist/types/transpiler/index.d.ts +11 -1
  455. package/dist/types/transpiler/insertion/getInsertionValues.d.ts.map +1 -1
  456. package/dist/types/transpiler/insertion/insertion.d.ts +0 -1
  457. package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -1
  458. package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts.map +1 -1
  459. package/dist/types/transpiler/markdown/index.d.ts +1 -1
  460. package/dist/types/transpiler/markdown/markdown.d.ts +0 -1
  461. package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
  462. package/dist/types/transpiler/markdown/validateMarkdown.d.ts +0 -1
  463. package/dist/types/transpiler/markdown/validateMarkdown.d.ts.map +1 -1
  464. package/dist/types/transpiler/nesting/nesting.d.ts +4 -4
  465. package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
  466. package/dist/types/transpiler/plural/plural.d.ts +0 -1
  467. package/dist/types/transpiler/plural/plural.d.ts.map +1 -1
  468. package/dist/types/transpiler/translation/translation.d.ts +0 -1
  469. package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
  470. package/dist/types/utils/checkIsURLAbsolute.d.ts.map +1 -1
  471. package/dist/types/utils/cookieExpiry.d.ts +1 -2
  472. package/dist/types/utils/cookieExpiry.d.ts.map +1 -1
  473. package/dist/types/utils/getCookie.d.ts.map +1 -1
  474. package/dist/types/utils/index.d.ts +2 -2
  475. package/dist/types/utils/intl.d.ts +49 -5
  476. package/dist/types/utils/intl.d.ts.map +1 -1
  477. package/dist/types/utils/isSameKeyPath.d.ts +0 -1
  478. package/dist/types/utils/isSameKeyPath.d.ts.map +1 -1
  479. package/dist/types/utils/isValidReactElement.d.ts.map +1 -1
  480. package/dist/types/utils/localeStorage.d.ts +1 -2
  481. package/dist/types/utils/localeStorage.d.ts.map +1 -1
  482. package/dist/types/utils/parseYaml.d.ts.map +1 -1
  483. package/dist/types/utils/stringifyYaml.d.ts.map +1 -1
  484. package/package.json +9 -9
@@ -11,14 +11,15 @@ const deepTransformNode = (node, props) => {
11
11
  if (node === null || typeof node !== "object") return node;
12
12
  if (node.$$typeof !== void 0 || node.__v_isVNode !== void 0 || node._isVNode !== void 0 || node.isJSX !== void 0 || typeof node === "function") return node;
13
13
  if (Array.isArray(node)) return node.map((child, index) => {
14
- return deepTransformNode(child, {
14
+ const childProps = {
15
15
  ...props,
16
16
  children: child,
17
17
  keyPath: [...props.keyPath, {
18
18
  type: NodeTypes.ARRAY,
19
19
  key: index
20
20
  }]
21
- });
21
+ };
22
+ return deepTransformNode(child, childProps);
22
23
  });
23
24
  const result = {};
24
25
  for (const key in node) {
@@ -1 +1 @@
1
- {"version":3,"file":"deepTransform.mjs","names":[],"sources":["../../../../src/interpreter/getContent/deepTransform.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { NodeProps } from './plugins';\n\n/**\n * Recursively traverses a node (object/array/primitive).\n * Applies the *first* plugin that can transform a node, then stops descending further.\n * If no plugin transforms it, it recurses into its children.\n */\nexport const deepTransformNode = (node: any, props: NodeProps): any => {\n // Otherwise, if it's an object, check if any plugin can handle it:\n for (const plugin of props.plugins ?? []) {\n if (plugin.canHandle(node)) {\n // Return the transformed node => do NOT recurse further\n return plugin.transform(node, props, (node: any, props: any) =>\n deepTransformNode(node, props)\n );\n }\n }\n\n // If it's null/undefined or not an object, just return it directly:\n if (node === null || typeof node !== 'object') {\n return node;\n }\n\n // If it's a framework-specific virtual node or already a transformed Proxy,\n // return it directly to avoid re-transforming its internal properties.\n if (\n (node as any).$$typeof !== undefined ||\n (node as any).__v_isVNode !== undefined ||\n (node as any)._isVNode !== undefined ||\n (node as any).isJSX !== undefined ||\n typeof node === 'function' // Proxies for html/markdown are functions\n ) {\n return node;\n }\n\n // If it's an array, transform each element:\n if (Array.isArray(node)) {\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ARRAY, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n // If no plugin transforms it, we keep traversing its properties.\n const result: Record<string, any> = {};\n for (const key in node) {\n const childProps = {\n ...props,\n children: node[key],\n keyPath: [...props.keyPath, { type: NodeTypes.OBJECT, key } as KeyPath],\n };\n\n if (props.eager) {\n // Eager mode: recurse immediately so plugins fire on every node, even\n // when the caller discards the returned tree (e.g. side-effect-only\n // plugins like missing-locale detection).\n result[key] = deepTransformNode(node[key], childProps);\n continue;\n }\n\n Object.defineProperty(result, key, {\n enumerable: true,\n configurable: true,\n get: function () {\n const transformed = deepTransformNode(node[key], childProps);\n\n // Memoize the result onto the property to avoid re-calculating on next read\n Object.defineProperty(this, key, {\n value: transformed,\n enumerable: true,\n configurable: true,\n });\n return transformed;\n },\n });\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;AASA,MAAa,qBAAqB,MAAW,UAA0B;AAErE,MAAK,MAAM,UAAU,MAAM,WAAW,EAAE,CACtC,KAAI,OAAO,UAAU,KAAK,CAExB,QAAO,OAAO,UAAU,MAAM,QAAQ,MAAW,UAC/C,kBAAkB,MAAM,MAAM,CAC/B;AAKL,KAAI,SAAS,QAAQ,OAAO,SAAS,SACnC,QAAO;AAKT,KACG,KAAa,aAAa,UAC1B,KAAa,gBAAgB,UAC7B,KAAa,aAAa,UAC1B,KAAa,UAAU,UACxB,OAAO,SAAS,WAEhB,QAAO;AAIT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,OAAO,UAAU;AAShC,SAAO,kBAAkB,OAAO;GAP9B,GAAG;GACH,UAAU;GACV,SAAS,CACP,GAAG,MAAM,SACT;IAAE,MAAM,UAAU;IAAO,KAAK;IAAO,CACtC;GAEuC,CAAC;GAC3C;CAIJ,MAAM,SAA8B,EAAE;AACtC,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,aAAa;GACjB,GAAG;GACH,UAAU,KAAK;GACf,SAAS,CAAC,GAAG,MAAM,SAAS;IAAE,MAAM,UAAU;IAAQ;IAAK,CAAY;GACxE;AAED,MAAI,MAAM,OAAO;AAIf,UAAO,OAAO,kBAAkB,KAAK,MAAM,WAAW;AACtD;;AAGF,SAAO,eAAe,QAAQ,KAAK;GACjC,YAAY;GACZ,cAAc;GACd,KAAK,WAAY;IACf,MAAM,cAAc,kBAAkB,KAAK,MAAM,WAAW;AAG5D,WAAO,eAAe,MAAM,KAAK;KAC/B,OAAO;KACP,YAAY;KACZ,cAAc;KACf,CAAC;AACF,WAAO;;GAEV,CAAC;;AAGJ,QAAO"}
1
+ {"version":3,"file":"deepTransform.mjs","names":[],"sources":["../../../../src/interpreter/getContent/deepTransform.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { NodeProps } from './plugins';\n\n/**\n * Recursively traverses a node (object/array/primitive).\n * Applies the *first* plugin that can transform a node, then stops descending further.\n * If no plugin transforms it, it recurses into its children.\n */\nexport const deepTransformNode = (node: any, props: NodeProps): any => {\n // Otherwise, if it's an object, check if any plugin can handle it:\n for (const plugin of props.plugins ?? []) {\n if (plugin.canHandle(node)) {\n // Return the transformed node => do NOT recurse further\n return plugin.transform(node, props, (node: any, props: any) =>\n deepTransformNode(node, props)\n );\n }\n }\n\n // If it's null/undefined or not an object, just return it directly:\n if (node === null || typeof node !== 'object') {\n return node;\n }\n\n // If it's a framework-specific virtual node or already a transformed Proxy,\n // return it directly to avoid re-transforming its internal properties.\n if (\n (node as any).$$typeof !== undefined ||\n (node as any).__v_isVNode !== undefined ||\n (node as any)._isVNode !== undefined ||\n (node as any).isJSX !== undefined ||\n typeof node === 'function' // Proxies for html/markdown are functions\n ) {\n return node;\n }\n\n // If it's an array, transform each element:\n if (Array.isArray(node)) {\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ARRAY, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n // If no plugin transforms it, we keep traversing its properties.\n const result: Record<string, any> = {};\n for (const key in node) {\n const childProps = {\n ...props,\n children: node[key],\n keyPath: [...props.keyPath, { type: NodeTypes.OBJECT, key } as KeyPath],\n };\n\n if (props.eager) {\n // Eager mode: recurse immediately so plugins fire on every node, even\n // when the caller discards the returned tree (e.g. side-effect-only\n // plugins like missing-locale detection).\n result[key] = deepTransformNode(node[key], childProps);\n continue;\n }\n\n Object.defineProperty(result, key, {\n enumerable: true,\n configurable: true,\n get: function () {\n const transformed = deepTransformNode(node[key], childProps);\n\n // Memoize the result onto the property to avoid re-calculating on next read\n Object.defineProperty(this, key, {\n value: transformed,\n enumerable: true,\n configurable: true,\n });\n return transformed;\n },\n });\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;AASA,MAAa,qBAAqB,MAAW,UAA0B;CAErE,KAAK,MAAM,UAAU,MAAM,WAAW,CAAC,GACrC,IAAI,OAAO,UAAU,IAAI,GAEvB,OAAO,OAAO,UAAU,MAAM,QAAQ,MAAW,UAC/C,kBAAkB,MAAM,KAAK,CAC/B;CAKJ,IAAI,SAAS,QAAQ,OAAO,SAAS,UACnC,OAAO;CAKT,IACG,KAAa,aAAa,UAC1B,KAAa,gBAAgB,UAC7B,KAAa,aAAa,UAC1B,KAAa,UAAU,UACxB,OAAO,SAAS,YAEhB,OAAO;CAIT,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,KAAK,KAAK,OAAO,UAAU;EAChC,MAAM,aAAa;GACjB,GAAG;GACH,UAAU;GACV,SAAS,CACP,GAAG,MAAM,SACT;IAAE,MAAM,UAAU;IAAO,KAAK;GAAM,CACtC;EACF;EACA,OAAO,kBAAkB,OAAO,UAAU;CAC5C,CAAC;CAIH,MAAM,SAA8B,CAAC;CACrC,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,aAAa;GACjB,GAAG;GACH,UAAU,KAAK;GACf,SAAS,CAAC,GAAG,MAAM,SAAS;IAAE,MAAM,UAAU;IAAQ;GAAI,CAAY;EACxE;EAEA,IAAI,MAAM,OAAO;GAIf,OAAO,OAAO,kBAAkB,KAAK,MAAM,UAAU;GACrD;EACF;EAEA,OAAO,eAAe,QAAQ,KAAK;GACjC,YAAY;GACZ,cAAc;GACd,KAAK,WAAY;IACf,MAAM,cAAc,kBAAkB,KAAK,MAAM,UAAU;IAG3D,OAAO,eAAe,MAAM,KAAK;KAC/B,OAAO;KACP,YAAY;KACZ,cAAc;IAChB,CAAC;IACD,OAAO;GACT;EACF,CAAC;CACH;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"getContent.mjs","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] =>\n [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n insertionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n ] as Plugins[];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n const T extends ContentNode,\n const L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;AAqBA,MAAa,kBACX,QACA,WAAoB,SAEpB;CACE,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,OACjD;CACD;CACA;CACA;CACA,aAAa,UAAU,qBAAqB,cAAc;CAC1D;CACA;CACD;;;;;;;AAQH,MAAa,cAIX,MACA,WACA,UAAqB,EAAE,KAEvB,kBAAkB,MAAM;CACtB,GAAG;CACH;CACD,CAAC"}
1
+ {"version":3,"file":"getContent.mjs","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] =>\n [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n insertionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n ] as Plugins[];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n const T extends ContentNode,\n const L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;AAqBA,MAAa,kBACX,QACA,WAAoB,SAEpB;CACE,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,MAClD;CACA;CACA;CACA;CACA,aAAa,UAAU,qBAAqB,aAAa;CACzD;CACA;AACF;;;;;;;AAQF,MAAa,cAIX,MACA,WACA,UAAqB,CAAC,MAEtB,kBAAkB,MAAM;CACtB,GAAG;CACH;AACF,CAAC"}
@@ -58,7 +58,8 @@ const enumerationPlugin = process.env.INTLAYER_NODE_TYPE_ENUMERATION === "false"
58
58
  });
59
59
  }
60
60
  return (arg) => {
61
- const subResult = getEnumeration(result, typeof arg === "number" ? arg : arg.count);
61
+ const quantity = typeof arg === "number" ? arg : arg.count;
62
+ const subResult = getEnumeration(result, quantity);
62
63
  if (typeof subResult === "function" && typeof arg === "object") return subResult(arg);
63
64
  return subResult;
64
65
  };
@@ -136,7 +137,8 @@ const conditionPlugin = process.env.INTLAYER_NODE_TYPE_CONDITION === "false" ? f
136
137
  });
137
138
  }
138
139
  return (arg) => {
139
- const subResult = getCondition(result, typeof arg === "boolean" ? arg : arg.value);
140
+ const value = typeof arg === "boolean" ? arg : arg.value;
141
+ const subResult = getCondition(result, value);
140
142
  if (typeof subResult === "function" && typeof arg === "object") return subResult(arg);
141
143
  return subResult;
142
144
  };
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.mjs","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n PluralContent,\n PluralContentState,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getPlural } from '../getPlural';\nimport { getTranslation } from '../getTranslation';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.TRANSLATION] ?? {};\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const childProps = {\n ...props,\n children: original[key as keyof typeof original],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n original[key as keyof typeof original],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.ENUMERATION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as unknown as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * PLURAL PLUGIN\n * --------------------------------------------- */\n\nexport type PluralCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.PLURAL]: object;\n}\n ? (\n arg: number | { count: number; [key: string]: unknown }\n ) => DeepTransformContent<\n T[typeof NodeTypes.PLURAL][keyof T[typeof NodeTypes.PLURAL]],\n S\n >\n : never;\n\ntype SubResultFunction = (values: Record<string, string | number>) => string;\n\n/**\n * Plural plugin. Replaces node with a function that takes a count (or\n * `{ count, ...values }`) => string, picking the matching CLDR plural form\n * for the active locale and interpolating `{{count}}` (and other values).\n */\nexport const pluralPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_PLURAL === 'false'\n ? fallbackPlugin\n : {\n id: 'plural-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.PLURAL,\n transform: (node: PluralContent, props, deepTransformNode) => {\n const original = node[NodeTypes.PLURAL];\n const result: Record<string, any> = {};\n\n /** String plugin for plural. Replaces string node with a component that renders the insertion. */\n const pluralStringPlugin: Plugins = {\n id: 'plural-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: { [k: string]: string | number }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.PLURAL, key } as KeyPath,\n ],\n plugins: [pluralStringPlugin, ...(props.plugins ?? [])],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n const effectiveLocale = String(locale ?? props.locale ?? 'en');\n\n return (arg: number | { count: number; [key: string]: unknown }) => {\n const count = typeof arg === 'number' ? arg : arg.count;\n const values =\n typeof arg === 'number'\n ? { count: arg }\n : (arg as { count: number; [key: string]: unknown });\n\n const subResult: string | SubResultFunction = getPlural(\n result as PluralContent['plural'] as PluralContentState<string>,\n count,\n effectiveLocale\n );\n\n if (typeof subResult === 'function') {\n return (subResult as SubResultFunction)(values);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const original = node[NodeTypes.CONDITION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result as any, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => I extends string\n ? DeepTransformContent<string, S>\n : DeepTransformContent<I, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const original = node[NodeTypes.GENDER];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result as any, value);\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n getNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? DeepTransformContent<string, S>\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n /**\n * Forces eager traversal of plain objects in `deepTransformNode`. By default\n * traversal is lazy (property getters), so callers that discard the returned\n * value never trigger plugins on nested nodes. Set this when running plugins\n * for their side effects only (e.g. missing-locale detection).\n */\n eager?: boolean;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n plural: PluralCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T, S, L>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n plural: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":";;;;;;;;;;;;;;;AA4DA,MAAa,iBAA0B;CACrC,IAAI;CACJ,iBAAiB;CACjB,YAAY,SAAS;CACtB;;AAmCD,MAAa,qBACX,QACA,aAEA,QAAQ,IAAI,mCAAmC,UAC3C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAA0B,OAAO,sBAAsB;EACjE,MAAM,WAAW,KAAK,UAAU,gBAAgB,EAAE;EAClD,MAAM,SAA8B,EAAE;AAEtC,OAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,aAAa;IACjB,GAAG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,UAAkB,UAAU,QAAe,MAAM;;CAE5D;;AAmBP,MAAa,gBAAgB,WAC3B,QAAQ,IAAI,8BAA8B,UACtC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,aACf,MAAM,aAAa,UAAU,UAAU,MAAM,aAAa;CAC7D,YAAY,MAAqB,UAC/B,WACE,KAAK,UAAU,QAAQ,eACvB,KAAK,UAAU,QAAQ,MACvB;EACE,GAAG;EACH,QAAS,UAAU,MAAM;EAC1B,CACF;CACJ;;AAeP,MAAa,aACX,QAAQ,IAAI,4BAA4B,UACpC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;EAC1B,GAAG;EACH,UAAU,KAAK;EAChB,CAAC;CACL"}
1
+ {"version":3,"file":"plugins.mjs","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n PluralContent,\n PluralContentState,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getPlural } from '../getPlural';\nimport { getTranslation } from '../getTranslation';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.TRANSLATION] ?? {};\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const childProps = {\n ...props,\n children: original[key as keyof typeof original],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n original[key as keyof typeof original],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.ENUMERATION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as unknown as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * PLURAL PLUGIN\n * --------------------------------------------- */\n\nexport type PluralCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.PLURAL]: object;\n}\n ? (\n arg: number | { count: number; [key: string]: unknown }\n ) => DeepTransformContent<\n T[typeof NodeTypes.PLURAL][keyof T[typeof NodeTypes.PLURAL]],\n S\n >\n : never;\n\ntype SubResultFunction = (values: Record<string, string | number>) => string;\n\n/**\n * Plural plugin. Replaces node with a function that takes a count (or\n * `{ count, ...values }`) => string, picking the matching CLDR plural form\n * for the active locale and interpolating `{{count}}` (and other values).\n */\nexport const pluralPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_PLURAL === 'false'\n ? fallbackPlugin\n : {\n id: 'plural-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.PLURAL,\n transform: (node: PluralContent, props, deepTransformNode) => {\n const original = node[NodeTypes.PLURAL];\n const result: Record<string, any> = {};\n\n /** String plugin for plural. Replaces string node with a component that renders the insertion. */\n const pluralStringPlugin: Plugins = {\n id: 'plural-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: { [k: string]: string | number }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.PLURAL, key } as KeyPath,\n ],\n plugins: [pluralStringPlugin, ...(props.plugins ?? [])],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n const effectiveLocale = String(locale ?? props.locale ?? 'en');\n\n return (arg: number | { count: number; [key: string]: unknown }) => {\n const count = typeof arg === 'number' ? arg : arg.count;\n const values =\n typeof arg === 'number'\n ? { count: arg }\n : (arg as { count: number; [key: string]: unknown });\n\n const subResult: string | SubResultFunction = getPlural(\n result as PluralContent['plural'] as PluralContentState<string>,\n count,\n effectiveLocale\n );\n\n if (typeof subResult === 'function') {\n return (subResult as SubResultFunction)(values);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const original = node[NodeTypes.CONDITION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result as any, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => I extends string\n ? DeepTransformContent<string, S>\n : DeepTransformContent<I, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const original = node[NodeTypes.GENDER];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result as any, value);\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n getNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? DeepTransformContent<string, S>\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n /**\n * Forces eager traversal of plain objects in `deepTransformNode`. By default\n * traversal is lazy (property getters), so callers that discard the returned\n * value never trigger plugins on nested nodes. Set this when running plugins\n * for their side effects only (e.g. missing-locale detection).\n */\n eager?: boolean;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n plural: PluralCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T, S, L>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n plural: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":";;;;;;;;;;;;;;;AA4DA,MAAa,iBAA0B;CACrC,IAAI;CACJ,iBAAiB;CACjB,YAAY,SAAS;AACvB;;AAmCA,MAAa,qBACX,QACA,aAEA,QAAQ,IAAI,mCAAmC,UAC3C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAA0B,OAAO,sBAAsB;EACjE,MAAM,WAAW,KAAK,UAAU,gBAAgB,CAAC;EACjD,MAAM,SAA8B,CAAC;EAErC,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,aAAa;IACjB,GAAG;IACH,UAAU,SAAS;IACnB,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAM,UAAU;KAAa;IAAI,CACrC;GACF;GACA,OAAO,OAAO,kBACZ,SAAS,MACT,UACF;EACF;EAEA,OAAO,eAAe,QAAQ,QAAQ,QAAQ;CAChD;AACF;;AAmBN,MAAa,oBACX,QAAQ,IAAI,mCAAmC,UAC3C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAA0B,OAAO,sBAAsB;EACjE,MAAM,WAAW,KAAK,UAAU;EAChC,MAAM,SAA8B,CAAC;EAErC,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,QAAQ,SAAS;GASvB,OAAO,OAAO,kBAAkB,OAAO;IAPrC,GAAG;IACH,UAAU;IACV,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAM,UAAU;KAAa;IAAI,CACrC;GAE8C,C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c,KAAK,SAAS;EAC1B,GAAG;EACH,UAAU,KAAK;CACjB,CAAC;AACL"}
@@ -1 +1 @@
1
- {"version":3,"file":"getDictionary.mjs","names":[],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n parseDictionarySelector,\n resolveQualifiedDictionary,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getBasePlugins, getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n * Also accepts a `QualifiedDictionaryGroup` (collections, variants) together\n * with a selector as second argument — the group is resolved to a single entry\n * (or an ordered array of entries for collections without an `item` selector)\n * before transformation.\n *\n * @param dictionary The dictionary (or qualified dictionary group) to transform.\n * @param localeOrSelector The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins An array of NodeTransformer that define how to transform recognized nodes.\n * If omitted, we’ll use a default set of plugins.\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const { locale, selector } = parseDictionarySelector(localeOrSelector);\n const appliedPlugins = plugins ?? getBasePlugins(locale);\n\n const resolved = resolveQualifiedDictionary(dictionary, selector);\n\n const transformDictionary = (resolvedDictionary: Dictionary) => {\n const props: NodeProps = {\n dictionaryKey: resolvedDictionary.key,\n dictionaryPath: resolvedDictionary.filePath,\n keyPath: [],\n plugins: appliedPlugins,\n };\n\n return getContent(resolvedDictionary.content, props, appliedPlugins);\n };\n\n if (resolved === null) return null as any;\n\n if (Array.isArray(resolved)) {\n return resolved.map(transformDictionary) as any;\n }\n\n return transformDictionary(resolved) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,MAAa,iBAIX,YACA,kBACA,YAKG;CACH,MAAM,EAAE,QAAQ,aAAa,wBAAwB,iBAAiB;CACtE,MAAM,iBAAiB,WAAW,eAAe,OAAO;CAExD,MAAM,WAAW,2BAA2B,YAAY,SAAS;CAEjE,MAAM,uBAAuB,uBAAmC;EAC9D,MAAM,QAAmB;GACvB,eAAe,mBAAmB;GAClC,gBAAgB,mBAAmB;GACnC,SAAS,EAAE;GACX,SAAS;GACV;AAED,SAAO,WAAW,mBAAmB,SAAS,OAAO,eAAe;;AAGtE,KAAI,aAAa,KAAM,QAAO;AAE9B,KAAI,MAAM,QAAQ,SAAS,CACzB,QAAO,SAAS,IAAI,oBAAoB;AAG1C,QAAO,oBAAoB,SAAS"}
1
+ {"version":3,"file":"getDictionary.mjs","names":[],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n parseDictionarySelector,\n resolveQualifiedDictionary,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getBasePlugins, getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n * Also accepts a `QualifiedDictionaryGroup` (collections, variants) together\n * with a selector as second argument — the group is resolved to a single entry\n * (or an ordered array of entries for collections without an `item` selector)\n * before transformation.\n *\n * @param dictionary The dictionary (or qualified dictionary group) to transform.\n * @param localeOrSelector The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins An array of NodeTransformer that define how to transform recognized nodes.\n * If omitted, we’ll use a default set of plugins.\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const { locale, selector } = parseDictionarySelector(localeOrSelector);\n const appliedPlugins = plugins ?? getBasePlugins(locale);\n\n const resolved = resolveQualifiedDictionary(dictionary, selector);\n\n const transformDictionary = (resolvedDictionary: Dictionary) => {\n const props: NodeProps = {\n dictionaryKey: resolvedDictionary.key,\n dictionaryPath: resolvedDictionary.filePath,\n keyPath: [],\n plugins: appliedPlugins,\n };\n\n return getContent(resolvedDictionary.content, props, appliedPlugins);\n };\n\n if (resolved === null) return null as any;\n\n if (Array.isArray(resolved)) {\n return resolved.map(transformDictionary) as any;\n }\n\n return transformDictionary(resolved) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,MAAa,iBAIX,YACA,kBACA,YAKG;CACH,MAAM,EAAE,QAAQ,aAAa,wBAAwB,gBAAgB;CACrE,MAAM,iBAAiB,WAAW,eAAe,MAAM;CAEvD,MAAM,WAAW,2BAA2B,YAAY,QAAQ;CAEhE,MAAM,uBAAuB,uBAAmC;EAC9D,MAAM,QAAmB;GACvB,eAAe,mBAAmB;GAClC,gBAAgB,mBAAmB;GACnC,SAAS,CAAC;GACV,SAAS;EACX;EAEA,OAAO,WAAW,mBAAmB,SAAS,OAAO,cAAc;CACrE;CAEA,IAAI,aAAa,MAAM,OAAO;CAE9B,IAAI,MAAM,QAAQ,QAAQ,GACxB,OAAO,SAAS,IAAI,mBAAmB;CAGzC,OAAO,oBAAoB,QAAQ;AACrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getEnumeration.mjs","names":[],"sources":["../../../src/interpreter/getEnumeration.ts"],"sourcesContent":["import type { EnterFormat, EnumerationContentState } from '../transpiler';\n\n/**\n * Find the matching condition for a quantity.\n *\n * Usage:\n *\n * ```ts\n * const key = findMatchingCondition({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * }, 2);\n * // '2'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const key = findMatchingCondition({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // '<4'\n * ```\n *\n * If no keys match, the default key is '1'.\n */\nexport const findMatchingCondition = <const Content>(\n enumerationContent: EnumerationContentState<Content>,\n quantity: number\n): EnterFormat | undefined => {\n const numericKeys = Object.keys(enumerationContent);\n\n for (const key of numericKeys) {\n const isEqual =\n (!key.startsWith('>') &&\n !key.startsWith('<') &&\n !key.startsWith('=') &&\n parseFloat(key) === quantity) ||\n (key.startsWith('=') && parseFloat(key.slice(1)) === quantity);\n const isSuperior =\n key.startsWith('>') && quantity > parseFloat(key.slice(1));\n const isSuperiorOrEqual =\n key.startsWith('>=') && quantity >= parseFloat(key.slice(2));\n const isInferior =\n key.startsWith('<') && quantity < parseFloat(key.slice(1));\n const isInferiorOrEqual =\n key.startsWith('<=') && quantity <= parseFloat(key.slice(2));\n\n if (\n isEqual ||\n isSuperior ||\n isSuperiorOrEqual ||\n isInferior ||\n isInferiorOrEqual\n ) {\n return key as EnterFormat;\n }\n }\n};\n\n/**\n * Picks content from an enumeration map based on a provided quantity.\n *\n * Supported keys in the enumeration map:\n * - Specific numbers: '0', '1', '2'\n * - Comparison operators: '<5', '>=10', '<=2'\n * - Fallback: 'fallback'\n *\n * The first matching key in the object's iteration order will be selected.\n *\n * @param enumerationContent - A map of conditions/quantities to content.\n * @param quantity - The number to match against the conditions.\n * @returns The matching content.\n *\n * @example\n * ```ts\n * const content = getEnumeration({\n * '0': 'No items',\n * '1': 'One item',\n * '>1': 'Many items',\n * }, 5);\n * // 'Many items'\n * ```\n */\nexport const getEnumeration = <const Content>(\n enumerationContent: EnumerationContentState<Content>,\n quantity: number\n): Content => {\n const key =\n findMatchingCondition<Content>(enumerationContent, quantity) ?? 'fallback';\n\n // Default or error handling if no keys match\n return enumerationContent[key] as Content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,yBACX,oBACA,aAC4B;CAC5B,MAAM,cAAc,OAAO,KAAK,mBAAmB;AAEnD,MAAK,MAAM,OAAO,aAAa;EAC7B,MAAM,UACH,CAAC,IAAI,WAAW,IAAI,IACnB,CAAC,IAAI,WAAW,IAAI,IACpB,CAAC,IAAI,WAAW,IAAI,IACpB,WAAW,IAAI,KAAK,YACrB,IAAI,WAAW,IAAI,IAAI,WAAW,IAAI,MAAM,EAAE,CAAC,KAAK;EACvD,MAAM,aACJ,IAAI,WAAW,IAAI,IAAI,WAAW,WAAW,IAAI,MAAM,EAAE,CAAC;EAC5D,MAAM,oBACJ,IAAI,WAAW,KAAK,IAAI,YAAY,WAAW,IAAI,MAAM,EAAE,CAAC;EAC9D,MAAM,aACJ,IAAI,WAAW,IAAI,IAAI,WAAW,WAAW,IAAI,MAAM,EAAE,CAAC;EAC5D,MAAM,oBACJ,IAAI,WAAW,KAAK,IAAI,YAAY,WAAW,IAAI,MAAM,EAAE,CAAC;AAE9D,MACE,WACA,cACA,qBACA,cACA,kBAEA,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Bb,MAAa,kBACX,oBACA,aACY;AAKZ,QAAO,mBAHL,sBAA+B,oBAAoB,SAAS,IAAI"}
1
+ {"version":3,"file":"getEnumeration.mjs","names":[],"sources":["../../../src/interpreter/getEnumeration.ts"],"sourcesContent":["import type { EnterFormat, EnumerationContentState } from '../transpiler';\n\n/**\n * Find the matching condition for a quantity.\n *\n * Usage:\n *\n * ```ts\n * const key = findMatchingCondition({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * }, 2);\n * // '2'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const key = findMatchingCondition({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // '<4'\n * ```\n *\n * If no keys match, the default key is '1'.\n */\nexport const findMatchingCondition = <const Content>(\n enumerationContent: EnumerationContentState<Content>,\n quantity: number\n): EnterFormat | undefined => {\n const numericKeys = Object.keys(enumerationContent);\n\n for (const key of numericKeys) {\n const isEqual =\n (!key.startsWith('>') &&\n !key.startsWith('<') &&\n !key.startsWith('=') &&\n parseFloat(key) === quantity) ||\n (key.startsWith('=') && parseFloat(key.slice(1)) === quantity);\n const isSuperior =\n key.startsWith('>') && quantity > parseFloat(key.slice(1));\n const isSuperiorOrEqual =\n key.startsWith('>=') && quantity >= parseFloat(key.slice(2));\n const isInferior =\n key.startsWith('<') && quantity < parseFloat(key.slice(1));\n const isInferiorOrEqual =\n key.startsWith('<=') && quantity <= parseFloat(key.slice(2));\n\n if (\n isEqual ||\n isSuperior ||\n isSuperiorOrEqual ||\n isInferior ||\n isInferiorOrEqual\n ) {\n return key as EnterFormat;\n }\n }\n};\n\n/**\n * Picks content from an enumeration map based on a provided quantity.\n *\n * Supported keys in the enumeration map:\n * - Specific numbers: '0', '1', '2'\n * - Comparison operators: '<5', '>=10', '<=2'\n * - Fallback: 'fallback'\n *\n * The first matching key in the object's iteration order will be selected.\n *\n * @param enumerationContent - A map of conditions/quantities to content.\n * @param quantity - The number to match against the conditions.\n * @returns The matching content.\n *\n * @example\n * ```ts\n * const content = getEnumeration({\n * '0': 'No items',\n * '1': 'One item',\n * '>1': 'Many items',\n * }, 5);\n * // 'Many items'\n * ```\n */\nexport const getEnumeration = <const Content>(\n enumerationContent: EnumerationContentState<Content>,\n quantity: number\n): Content => {\n const key =\n findMatchingCondition<Content>(enumerationContent, quantity) ?? 'fallback';\n\n // Default or error handling if no keys match\n return enumerationContent[key] as Content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,yBACX,oBACA,aAC4B;CAC5B,MAAM,cAAc,OAAO,KAAK,kBAAkB;CAElD,KAAK,MAAM,OAAO,aAAa;EAC7B,MAAM,UACH,CAAC,IAAI,WAAW,GAAG,KAClB,CAAC,IAAI,WAAW,GAAG,KACnB,CAAC,IAAI,WAAW,GAAG,KACnB,WAAW,GAAG,MAAM,YACrB,IAAI,WAAW,GAAG,KAAK,WAAW,IAAI,MAAM,CAAC,CAAC,MAAM;EACvD,MAAM,aACJ,IAAI,WAAW,GAAG,KAAK,WAAW,WAAW,IAAI,MAAM,CAAC,CAAC;EAC3D,MAAM,oBACJ,IAAI,WAAW,IAAI,KAAK,YAAY,WAAW,IAAI,MAAM,CAAC,CAAC;EAC7D,MAAM,aACJ,IAAI,WAAW,GAAG,KAAK,WAAW,WAAW,IAAI,MAAM,CAAC,CAAC;EAC3D,MAAM,oBACJ,IAAI,WAAW,IAAI,KAAK,YAAY,WAAW,IAAI,MAAM,CAAC,CAAC;EAE7D,IACE,WACA,cACA,qBACA,cACA,mBAEA,OAAO;CAEX;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBACX,oBACA,aACY;CAKZ,OAAO,mBAHL,sBAA+B,oBAAoB,QAAQ,KAAK;AAIpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"getGender.mjs","names":[],"sources":["../../../src/interpreter/getGender.ts"],"sourcesContent":["import type { Gender, GenderContentStates } from '../transpiler';\n\ntype GenderEntry = Gender | 'm' | 'f';\n\nconst getGenderEntry = (gender: GenderEntry): Gender => {\n if (gender === 'm' || gender === 'male') return 'male';\n if (gender === 'f' || gender === 'female') return 'female';\n return 'fallback';\n};\n\n/**\n * Allow to pick a content based on a gender.\n *\n * Usage:\n *\n * ```ts\n * const content = getGender({\n * 'true': 'The gender is validated',\n * 'false': 'The gender is not validated',\n * }, true);\n * // 'The gender is validated'\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n * ```ts\n * const content = getGender({\n * 'false': 'The gender is not validated',\n * 'true': 'The gender is validated',\n * }, undefined);\n * // 'The gender is validated'\n */\nexport const getGender = <const Content>(\n genderContent: GenderContentStates<Content>,\n gender: GenderEntry\n): Content => {\n const stateList = Object.keys(genderContent);\n\n const fallbackState = stateList[\n stateList.length - 1\n ] as keyof typeof genderContent;\n\n const genderEntry = getGenderEntry(gender);\n\n // Default or error handling if no keys match\n return (\n genderContent[genderEntry as keyof typeof genderContent] ??\n genderContent.fallback ??\n (genderContent[fallbackState] as Content)\n );\n};\n"],"mappings":";AAIA,MAAM,kBAAkB,WAAgC;AACtD,KAAI,WAAW,OAAO,WAAW,OAAQ,QAAO;AAChD,KAAI,WAAW,OAAO,WAAW,SAAU,QAAO;AAClD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyBT,MAAa,aACX,eACA,WACY;CACZ,MAAM,YAAY,OAAO,KAAK,cAAc;CAE5C,MAAM,gBAAgB,UACpB,UAAU,SAAS;AAMrB,QACE,cAJkB,eAAe,OAIR,KACzB,cAAc,YACb,cAAc"}
1
+ {"version":3,"file":"getGender.mjs","names":[],"sources":["../../../src/interpreter/getGender.ts"],"sourcesContent":["import type { Gender, GenderContentStates } from '../transpiler';\n\ntype GenderEntry = Gender | 'm' | 'f';\n\nconst getGenderEntry = (gender: GenderEntry): Gender => {\n if (gender === 'm' || gender === 'male') return 'male';\n if (gender === 'f' || gender === 'female') return 'female';\n return 'fallback';\n};\n\n/**\n * Allow to pick a content based on a gender.\n *\n * Usage:\n *\n * ```ts\n * const content = getGender({\n * 'true': 'The gender is validated',\n * 'false': 'The gender is not validated',\n * }, true);\n * // 'The gender is validated'\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n * ```ts\n * const content = getGender({\n * 'false': 'The gender is not validated',\n * 'true': 'The gender is validated',\n * }, undefined);\n * // 'The gender is validated'\n */\nexport const getGender = <const Content>(\n genderContent: GenderContentStates<Content>,\n gender: GenderEntry\n): Content => {\n const stateList = Object.keys(genderContent);\n\n const fallbackState = stateList[\n stateList.length - 1\n ] as keyof typeof genderContent;\n\n const genderEntry = getGenderEntry(gender);\n\n // Default or error handling if no keys match\n return (\n genderContent[genderEntry as keyof typeof genderContent] ??\n genderContent.fallback ??\n (genderContent[fallbackState] as Content)\n );\n};\n"],"mappings":";AAIA,MAAM,kBAAkB,WAAgC;CACtD,IAAI,WAAW,OAAO,WAAW,QAAQ,OAAO;CAChD,IAAI,WAAW,OAAO,WAAW,UAAU,OAAO;CAClD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,aACX,eACA,WACY;CACZ,MAAM,YAAY,OAAO,KAAK,aAAa;CAE3C,MAAM,gBAAgB,UACpB,UAAU,SAAS;CAMrB,OACE,cAJkB,eAAe,MAIT,MACxB,cAAc,YACb,cAAc;AAEnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"getHTML.mjs","names":[],"sources":["../../../src/interpreter/getHTML.ts"],"sourcesContent":["/**\n * Component function that receives properly typed props\n * Props include:\n * - children?: any[] - Array of child elements (ReactNode[], VNode[], etc.)\n * - [key: string]: any - Any HTML attributes (className, style, href, etc.)\n */\ntype Component = (props: { children?: any[]; [key: string]: any }) => any;\n\n/**\n * Component object that delegates to another component\n */\ntype ComponentObject = {\n tag: string;\n props?: Record<string, any>;\n};\n\n/**\n * Components map:\n * - Function components receive typed props\n * - String components delegate to another tag\n * - Object components delegate with additional props\n */\ntype Components = Record<string, Component | string | ComponentObject>;\n\n/**\n * Helper to parse attributes from a tag string.\n */\nconst parseAttributes = (attributes: string): Record<string, string> => {\n const props: Record<string, string> = {};\n const attrRegex = /([a-zA-Z0-9-]+)=\"([^\"]*)\"/g;\n\n let match = attrRegex.exec(attributes);\n while (match !== null) {\n props[match[1]] = match[2];\n match = attrRegex.exec(attributes);\n }\n return props;\n};\n\ntype ASTNode =\n | string\n | {\n tagName: string;\n props: Record<string, string>;\n children: ASTNode[];\n };\n\nconst astCache = new Map<string, ASTNode[]>();\n\nconst parseHTML = (content: string): ASTNode[] => {\n if (astCache.has(content)) {\n return astCache.get(content)!;\n }\n\n if (typeof content !== 'string') {\n return [];\n }\n\n const tagRegex = /<(\\/)?([a-zA-Z0-9.-]+)([\\s\\S]*?)(\\/?)>/g;\n const elements: ASTNode[] = [];\n const stack: {\n tagName: string;\n children: ASTNode[];\n props: Record<string, string>;\n }[] = [];\n\n let lastIndex = 0;\n let match = tagRegex.exec(content);\n\n const appendChild = (child: ASTNode) => {\n const target =\n stack.length > 0 ? stack[stack.length - 1].children : elements;\n target.push(child);\n };\n\n while (match !== null) {\n const [fullMatch, isClosingRaw, tagName, attributesRaw, isSelfClosingRaw] =\n match;\n const matchIndex = match.index;\n\n if (matchIndex > lastIndex) {\n appendChild(content.slice(lastIndex, matchIndex));\n }\n\n const isClosing = isClosingRaw === '/';\n const isSelfClosing =\n isSelfClosingRaw === '/' ||\n attributesRaw.trim().endsWith('/') ||\n fullMatch.endsWith('/>');\n\n const cleanedAttributes = attributesRaw.trim().replace(/\\/$/, '').trim();\n\n if (isClosing) {\n const last = stack[stack.length - 1];\n\n // Only pop if the tag names match\n if (last && last.tagName === tagName) {\n const popped = stack.pop();\n if (popped) {\n appendChild({\n tagName: popped.tagName,\n props: popped.props,\n children: popped.children,\n });\n }\n }\n // If tags don't match or no open tag, silently ignore the closing tag\n } else if (isSelfClosing) {\n const tagProps = parseAttributes(cleanedAttributes);\n appendChild({\n tagName,\n props: tagProps,\n children: [],\n });\n } else {\n const tagProps = parseAttributes(cleanedAttributes);\n stack.push({ tagName, children: [], props: tagProps });\n }\n\n lastIndex = matchIndex + fullMatch.length;\n match = tagRegex.exec(content);\n }\n\n if (lastIndex < content.length) {\n appendChild(content.slice(lastIndex));\n }\n\n // Handle unclosed tags by appending them to the root or parent\n while (stack.length > 0) {\n const last = stack.pop();\n if (last) {\n appendChild({\n tagName: last.tagName,\n props: last.props,\n children: last.children,\n });\n }\n }\n\n astCache.set(content, elements);\n return elements;\n};\n\n/**\n * Interprets a string containing HTML-like tags and replaces them with provided components or strings.\n */\nexport const getHTML = (content: string, values: Components): any => {\n // Parse into AST (cached)\n const ast = parseHTML(content);\n\n // Render AST\n let keyCounter = 0;\n\n const renderASTNode = (node: ASTNode): any => {\n if (typeof node === 'string') {\n return node;\n }\n\n const { tagName, props, children } = node;\n const renderedChildren = children.flatMap(renderASTNode);\n const index = keyCounter++;\n\n let override = values[tagName];\n\n if (!override) {\n const lowerTagName = tagName.toLowerCase();\n const foundKey = Object.keys(values).find(\n (key) => key.toLowerCase() === lowerTagName\n );\n\n if (foundKey) override = values[foundKey];\n }\n\n const key = `html-tag-${tagName}-${index}`;\n\n if (typeof override === 'function') {\n return override({ ...props, children: renderedChildren, key });\n }\n\n if (typeof override === 'string') {\n const component = values[override];\n\n if (typeof component === 'function') {\n return component({ ...props, children: renderedChildren, key });\n }\n return renderedChildren;\n }\n\n if (\n typeof override === 'object' &&\n override !== null &&\n 'tag' in override\n ) {\n const { tag: targetTag, props: extraProps } = override as ComponentObject;\n const component = values[targetTag];\n\n if (typeof component === 'function') {\n return component({\n ...props,\n ...extraProps,\n children: renderedChildren,\n key,\n });\n }\n return renderedChildren;\n }\n\n // Default: Skip tag, render children\n return renderedChildren;\n };\n\n const result = ast.flatMap(renderASTNode);\n return result.length === 1 ? result[0] : result;\n};\n"],"mappings":";;;;AA2BA,MAAM,mBAAmB,eAA+C;CACtE,MAAM,QAAgC,EAAE;CACxC,MAAM,YAAY;CAElB,IAAI,QAAQ,UAAU,KAAK,WAAW;AACtC,QAAO,UAAU,MAAM;AACrB,QAAM,MAAM,MAAM,MAAM;AACxB,UAAQ,UAAU,KAAK,WAAW;;AAEpC,QAAO;;AAWT,MAAM,2BAAW,IAAI,KAAwB;AAE7C,MAAM,aAAa,YAA+B;AAChD,KAAI,SAAS,IAAI,QAAQ,CACvB,QAAO,SAAS,IAAI,QAAQ;AAG9B,KAAI,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KAAK;GACZ,UAAU,KAAK;GAChB,CAAC;;AAIN,UAAS,IAAI,SAAS,SAAS;AAC/B,QAAO;;;;;AAMT,MAAa,WAAW,SAAiB,WAA4B;CAEnE,MAAM,MAAM,UAAU,QAAQ;CAG9B,IAAI,aAAa;CAEjB,MAAM,iBAAiB,SAAuB;AAC5C,MAAI,OAAO,SAAS,SAClB,QAAO;EAGT,MAAM,EAAE,SAAS,OAAO,aAAa;EACrC,MAAM,mBAAmB,SAAS,QAAQ,cAAc;EACxD,MAAM,QAAQ;EAEd,IAAI,WAAW,OAAO;AAEtB,MAAI,CAAC,UAAU;GACb,MAAM,eAAe,QAAQ,aAAa;GAC1C,MAAM,WAAW,OAAO,KAAK,OAAO,CAAC,MAClC,QAAQ,IAAI,aAAa,KAAK,aAChC;AAED,OAAI,SAAU,YAAW,OAAO;;EAGlC,MAAM,MAAM,YAAY,QAAQ,GAAG;AAEnC,MAAI,OAAO,aAAa,WACtB,QAAO,SAAS;GAAE,GAAG;GAAO,UAAU;GAAkB;GAAK,CAAC;AAGhE,MAAI,OAAO,aAAa,UAAU;GAChC,MAAM,YAAY,OAAO;AAEzB,OAAI,OAAO,cAAc,WACvB,QAAO,UAAU;IAAE,GAAG;IAAO,UAAU;IAAkB;IAAK,CAAC;AAEjE,UAAO;;AAGT,MACE,OAAO,aAAa,YACpB,aAAa,QACb,SAAS,UACT;GACA,MAAM,EAAE,KAAK,WAAW,OAAO,eAAe;GAC9C,MAAM,YAAY,OAAO;AAEzB,OAAI,OAAO,cAAc,WACvB,QAAO,UAAU;IACf,GAAG;IACH,GAAG;IACH,UAAU;IACV;IACD,CAAC;AAEJ,UAAO;;AAIT,SAAO;;CAGT,MAAM,SAAS,IAAI,QAAQ,cAAc;AACzC,QAAO,OAAO,WAAW,IAAI,OAAO,KAAK"}
1
+ {"version":3,"file":"getHTML.mjs","names":[],"sources":["../../../src/interpreter/getHTML.ts"],"sourcesContent":["/**\n * Component function that receives properly typed props\n * Props include:\n * - children?: any[] - Array of child elements (ReactNode[], VNode[], etc.)\n * - [key: string]: any - Any HTML attributes (className, style, href, etc.)\n */\ntype Component = (props: { children?: any[]; [key: string]: any }) => any;\n\n/**\n * Component object that delegates to another component\n */\ntype ComponentObject = {\n tag: string;\n props?: Record<string, any>;\n};\n\n/**\n * Components map:\n * - Function components receive typed props\n * - String components delegate to another tag\n * - Object components delegate with additional props\n */\ntype Components = Record<string, Component | string | ComponentObject>;\n\n/**\n * Helper to parse attributes from a tag string.\n */\nconst parseAttributes = (attributes: string): Record<string, string> => {\n const props: Record<string, string> = {};\n const attrRegex = /([a-zA-Z0-9-]+)=\"([^\"]*)\"/g;\n\n let match = attrRegex.exec(attributes);\n while (match !== null) {\n props[match[1]] = match[2];\n match = attrRegex.exec(attributes);\n }\n return props;\n};\n\ntype ASTNode =\n | string\n | {\n tagName: string;\n props: Record<string, string>;\n children: ASTNode[];\n };\n\nconst astCache = new Map<string, ASTNode[]>();\n\nconst parseHTML = (content: string): ASTNode[] => {\n if (astCache.has(content)) {\n return astCache.get(content)!;\n }\n\n if (typeof content !== 'string') {\n return [];\n }\n\n const tagRegex = /<(\\/)?([a-zA-Z0-9.-]+)([\\s\\S]*?)(\\/?)>/g;\n const elements: ASTNode[] = [];\n const stack: {\n tagName: string;\n children: ASTNode[];\n props: Record<string, string>;\n }[] = [];\n\n let lastIndex = 0;\n let match = tagRegex.exec(content);\n\n const appendChild = (child: ASTNode) => {\n const target =\n stack.length > 0 ? stack[stack.length - 1].children : elements;\n target.push(child);\n };\n\n while (match !== null) {\n const [fullMatch, isClosingRaw, tagName, attributesRaw, isSelfClosingRaw] =\n match;\n const matchIndex = match.index;\n\n if (matchIndex > lastIndex) {\n appendChild(content.slice(lastIndex, matchIndex));\n }\n\n const isClosing = isClosingRaw === '/';\n const isSelfClosing =\n isSelfClosingRaw === '/' ||\n attributesRaw.trim().endsWith('/') ||\n fullMatch.endsWith('/>');\n\n const cleanedAttributes = attributesRaw.trim().replace(/\\/$/, '').trim();\n\n if (isClosing) {\n const last = stack[stack.length - 1];\n\n // Only pop if the tag names match\n if (last && last.tagName === tagName) {\n const popped = stack.pop();\n if (popped) {\n appendChild({\n tagName: popped.tagName,\n props: popped.props,\n children: popped.children,\n });\n }\n }\n // If tags don't match or no open tag, silently ignore the closing tag\n } else if (isSelfClosing) {\n const tagProps = parseAttributes(cleanedAttributes);\n appendChild({\n tagName,\n props: tagProps,\n children: [],\n });\n } else {\n const tagProps = parseAttributes(cleanedAttributes);\n stack.push({ tagName, children: [], props: tagProps });\n }\n\n lastIndex = matchIndex + fullMatch.length;\n match = tagRegex.exec(content);\n }\n\n if (lastIndex < content.length) {\n appendChild(content.slice(lastIndex));\n }\n\n // Handle unclosed tags by appending them to the root or parent\n while (stack.length > 0) {\n const last = stack.pop();\n if (last) {\n appendChild({\n tagName: last.tagName,\n props: last.props,\n children: last.children,\n });\n }\n }\n\n astCache.set(content, elements);\n return elements;\n};\n\n/**\n * Interprets a string containing HTML-like tags and replaces them with provided components or strings.\n */\nexport const getHTML = (content: string, values: Components): any => {\n // Parse into AST (cached)\n const ast = parseHTML(content);\n\n // Render AST\n let keyCounter = 0;\n\n const renderASTNode = (node: ASTNode): any => {\n if (typeof node === 'string') {\n return node;\n }\n\n const { tagName, props, children } = node;\n const renderedChildren = children.flatMap(renderASTNode);\n const index = keyCounter++;\n\n let override = values[tagName];\n\n if (!override) {\n const lowerTagName = tagName.toLowerCase();\n const foundKey = Object.keys(values).find(\n (key) => key.toLowerCase() === lowerTagName\n );\n\n if (foundKey) override = values[foundKey];\n }\n\n const key = `html-tag-${tagName}-${index}`;\n\n if (typeof override === 'function') {\n return override({ ...props, children: renderedChildren, key });\n }\n\n if (typeof override === 'string') {\n const component = values[override];\n\n if (typeof component === 'function') {\n return component({ ...props, children: renderedChildren, key });\n }\n return renderedChildren;\n }\n\n if (\n typeof override === 'object' &&\n override !== null &&\n 'tag' in override\n ) {\n const { tag: targetTag, props: extraProps } = override as ComponentObject;\n const component = values[targetTag];\n\n if (typeof component === 'function') {\n return component({\n ...props,\n ...extraProps,\n children: renderedChildren,\n key,\n });\n }\n return renderedChildren;\n }\n\n // Default: Skip tag, render children\n return renderedChildren;\n };\n\n const result = ast.flatMap(renderASTNode);\n return result.length === 1 ? result[0] : result;\n};\n"],"mappings":";;;;AA2BA,MAAM,mBAAmB,eAA+C;CACtE,MAAM,QAAgC,CAAC;CACvC,MAAM,YAAY;CAElB,IAAI,QAAQ,UAAU,KAAK,UAAU;CACrC,OAAO,UAAU,MAAM;EACrB,MAAM,MAAM,MAAM,MAAM;EACxB,QAAQ,UAAU,KAAK,UAAU;CACnC;CACA,OAAO;AACT;AAUA,MAAM,2BAAW,IAAI,IAAuB;AAE5C,MAAM,aAAa,YAA+B;CAChD,IAAI,SAAS,IAAI,OAAO,GACtB,OAAO,SAAS,IAAI,OAAO;CAG7B,IAAI,OAAO,YAAY,UACrB,OAAO,CAAC;CAGV,MAAM,WAAW;CACjB,MAAM,WAAsB,CAAC;CAC7B,MAAM,QAIA,CAAC;CAEP,IAAI,YAAY;CAChB,IAAI,QAAQ,SAAS,KAAK,OAAO;CAEjC,MAAM,eAAe,UAAmB;EAGtC,CADE,MAAM,SAAS,IAAI,MAAM,MAAM,SAAS,EAAE,CAAC,WAAW,SAClD,CAAC,KAAK,KAAK;CACnB;CAEA,OAAO,UAAU,MAAM;EACrB,MAAM,CAAC,WAAW,cAAc,SAAS,eAAe,oBACtD;EACF,MAAM,aAAa,MAAM;EAEzB,IAAI,aAAa,WACf,YAAY,QAAQ,MAAM,WAAW,UAAU,CAAC;EAGlD,MAAM,YAAY,iBAAiB;EACnC,MAAM,gBACJ,qBAAqB,OACrB,cAAc,KAAK,CAAC,CAAC,SAAS,GAAG,KACjC,UAAU,SAAS,IAAI;EAEzB,MAAM,oBAAoB,cAAc,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,KAAK;EAEvE,IAAI,WAAW;GACb,MAAM,OAAO,MAAM,MAAM,SAAS;GAGlC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AU;GAAkB;EAAI,CAAC;EAG/D,IAAI,OAAO,aAAa,UAAU;GAChC,MAAM,YAAY,OAAO;GAEzB,IAAI,OAAO,cAAc,YACvB,OAAO,UAAU;IAAE,GAAG;IAAO,UAAU;IAAkB;GAAI,CAAC;GAEhE,OAAO;EACT;EAEA,IACE,OAAO,aAAa,YACpB,aAAa,QACb,SAAS,UACT;GACA,MAAM,EAAE,KAAK,WAAW,OAAO,eAAe;GAC9C,MAAM,YAAY,OAAO;GAEzB,IAAI,OAAO,cAAc,YACvB,OAAO,UAAU;IACf,GAAG;IACH,GAAG;IACH,UAAU;IACV;GACF,CAAC;GAEH,OAAO;EACT;EAGA,OAAO;CACT;CAEA,MAAM,SAAS,IAAI,QAAQ,aAAa;CACxC,OAAO,OAAO,WAAW,IAAI,OAAO,KAAK;AAC3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"getInsertion.mjs","names":[],"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string | number }\n) =>\n content.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n return (values[trimmedKey] ?? '').toString();\n });\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAa,gBACX,SACA,WAEA,QAAQ,QAAQ,yBAAyB,GAAG,QAAQ;AAElD,SAAQ,OADW,IAAI,MACE,KAAK,IAAI,UAAU;EAC5C"}
1
+ {"version":3,"file":"getInsertion.mjs","names":[],"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string | number }\n) =>\n content.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, key) => {\n const trimmedKey = key.trim();\n return (values[trimmedKey] ?? '').toString();\n });\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAa,gBACX,SACA,WAEA,QAAQ,QAAQ,yBAAyB,GAAG,QAAQ;CAElD,QAAQ,OADW,IAAI,KACC,MAAM,GAAE,CAAE,SAAS;AAC7C,CAAC"}
@@ -16,7 +16,8 @@ const createSafeFallback = (path = "") => {
16
16
  if (prop === Symbol.iterator) return function* () {
17
17
  yield path;
18
18
  };
19
- return createSafeFallback(path ? `${path}.${String(prop)}` : String(prop));
19
+ const nextPath = path ? `${path}.${String(prop)}` : String(prop);
20
+ return createSafeFallback(nextPath);
20
21
  } });
21
22
  };
22
23
  const dictionaryCache = /* @__PURE__ */ new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\n\n/**\n * Creates a Recursive Proxy that returns the path of the accessed key\n * stringified. This prevents the app from crashing on undefined access.\n */\nconst createSafeFallback = (path = ''): any => {\n return new Proxy({} as Record<string | symbol, unknown>, {\n get: (_target, prop) => {\n if (\n prop === 'toJSON' ||\n prop === Symbol.toPrimitive ||\n prop === 'toString' ||\n prop === 'valueOf'\n ) {\n return () => path;\n }\n if (prop === 'then') {\n return undefined; // Prevent it from being treated as a Promise\n }\n if (prop === Symbol.iterator) {\n return function* () {\n yield path;\n };\n }\n\n // Recursively build the path (e.g., \"myDictionary.home.title\")\n const nextPath = path ? `${path}.${String(prop)}` : String(prop);\n return createSafeFallback(nextPath);\n },\n });\n};\n\nconst dictionaryCache = new Map<string, any>();\nconst warnedMissingDictionaries = new Set<string>();\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const dictionaries = getDictionaries();\n const dictionary = dictionaries[key as T];\n\n if (!dictionary && process.env.NODE_ENV === 'development') {\n if (!warnedMissingDictionaries.has(key as string)) {\n // Log a warning instead of throwing (so developers know it's missing)\n const logger = getAppLogger({ log });\n logger(\n typeof window === 'undefined'\n ? `Dictionary ${colorizeKey(key)} was not found. Using fallback proxy.`\n : `Dictionary ${key} was not found. Using fallback proxy.`,\n {\n level: 'warn',\n }\n );\n warnedMissingDictionaries.add(key as string);\n }\n\n return createSafeFallback(key as string);\n }\n\n let locale: LocalesValues | undefined;\n let selectorCacheKey = '';\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n const parsed = parseDictionarySelector(localeOrSelector);\n locale = parsed.locale;\n selectorCacheKey = getDictionarySelectorCacheKey(parsed.selector);\n } else {\n // Selectors are unused in this project (build-time flag): the second\n // argument can only be a locale, so the selector parsing is dead code.\n locale = localeOrSelector as LocalesValues | undefined;\n }\n\n const cacheKey = `${key}_${locale ?? 'default'}_${selectorCacheKey}_${plugins ? 'custom_plugins' : 'default_plugins'}`;\n\n if (dictionaryCache.has(cacheKey)) {\n return dictionaryCache.get(cacheKey);\n }\n\n const result = getDictionary(dictionary, localeOrSelector, plugins);\n\n dictionaryCache.set(cacheKey, result);\n\n return result as any;\n};\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,sBAAsB,OAAO,OAAY;AAC7C,QAAO,IAAI,MAAM,EAAE,EAAsC,EACvD,MAAM,SAAS,SAAS;AACtB,MACE,SAAS,YACT,SAAS,OAAO,eAChB,SAAS,cACT,SAAS,UAET,cAAa;AAEf,MAAI,SAAS,OACX;AAEF,MAAI,SAAS,OAAO,SAClB,QAAO,aAAa;AAClB,SAAM;;AAMV,SAAO,mBADU,OAAO,GAAG,KAAK,GAAG,OAAO,KAAK,KAAK,OAAO,KAAK,CAC7B;IAEtC,CAAC;;AAGJ,MAAM,kCAAkB,IAAI,KAAkB;AAC9C,MAAM,4CAA4B,IAAI,KAAa;;;;;;;;;;;AAYnD,MAAa,eAIX,KACA,kBACA,YAKG;CAEH,MAAM,aADe,iBACU,CAAC;AAEhC,KAAI,CAAC,cAAc,MAAwC;AACzD,MAAI,CAAC,0BAA0B,IAAI,IAAc,EAAE;AAGjD,GADe,aAAa,EAAE,KAAK,CAC7B,CACJ,OAAO,WAAW,cACd,cAAc,YAAY,IAAI,CAAC,yCAC/B,cAAc,IAAI,wCACtB,EACE,OAAO,QACR,CACF;AACD,6BAA0B,IAAI,IAAc;;AAG9C,SAAO,mBAAmB,IAAc;;CAG1C,IAAI;CACJ,IAAI,mBAAmB;AAEvB,KAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,SAAS,wBAAwB,iBAAiB;AACxD,WAAS,OAAO;AAChB,qBAAmB,8BAA8B,OAAO,SAAS;OAIjE,UAAS;CAGX,MAAM,WAAW,GAAG,IAAI,GAAG,UAAU,UAAU,GAAG,iBAAiB,GAAG,UAAU,mBAAmB;AAEnG,KAAI,gBAAgB,IAAI,SAAS,CAC/B,QAAO,gBAAgB,IAAI,SAAS;CAGtC,MAAM,SAAS,cAAc,YAAY,kBAAkB,QAAQ;AAEnE,iBAAgB,IAAI,UAAU,OAAO;AAErC,QAAO"}
1
+ {"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\n\n/**\n * Creates a Recursive Proxy that returns the path of the accessed key\n * stringified. This prevents the app from crashing on undefined access.\n */\nconst createSafeFallback = (path = ''): any => {\n return new Proxy({} as Record<string | symbol, unknown>, {\n get: (_target, prop) => {\n if (\n prop === 'toJSON' ||\n prop === Symbol.toPrimitive ||\n prop === 'toString' ||\n prop === 'valueOf'\n ) {\n return () => path;\n }\n if (prop === 'then') {\n return undefined; // Prevent it from being treated as a Promise\n }\n if (prop === Symbol.iterator) {\n return function* () {\n yield path;\n };\n }\n\n // Recursively build the path (e.g., \"myDictionary.home.title\")\n const nextPath = path ? `${path}.${String(prop)}` : String(prop);\n return createSafeFallback(nextPath);\n },\n });\n};\n\nconst dictionaryCache = new Map<string, any>();\nconst warnedMissingDictionaries = new Set<string>();\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const dictionaries = getDictionaries();\n const dictionary = dictionaries[key as T];\n\n if (!dictionary && process.env.NODE_ENV === 'development') {\n if (!warnedMissingDictionaries.has(key as string)) {\n // Log a warning instead of throwing (so developers know it's missing)\n const logger = getAppLogger({ log });\n logger(\n typeof window === 'undefined'\n ? `Dictionary ${colorizeKey(key)} was not found. Using fallback proxy.`\n : `Dictionary ${key} was not found. Using fallback proxy.`,\n {\n level: 'warn',\n }\n );\n warnedMissingDictionaries.add(key as string);\n }\n\n return createSafeFallback(key as string);\n }\n\n let locale: LocalesValues | undefined;\n let selectorCacheKey = '';\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n const parsed = parseDictionarySelector(localeOrSelector);\n locale = parsed.locale;\n selectorCacheKey = getDictionarySelectorCacheKey(parsed.selector);\n } else {\n // Selectors are unused in this project (build-time flag): the second\n // argument can only be a locale, so the selector parsing is dead code.\n locale = localeOrSelector as LocalesValues | undefined;\n }\n\n const cacheKey = `${key}_${locale ?? 'default'}_${selectorCacheKey}_${plugins ? 'custom_plugins' : 'default_plugins'}`;\n\n if (dictionaryCache.has(cacheKey)) {\n return dictionaryCache.get(cacheKey);\n }\n\n const result = getDictionary(dictionary, localeOrSelector, plugins);\n\n dictionaryCache.set(cacheKey, result);\n\n return result as any;\n};\n"],"mappings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OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"getNesting.mjs","names":[],"sources":["../../../src/interpreter/getNesting.ts"],"sourcesContent":["import type { GetSubPath } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n} from '@intlayer/types/module_augmentation';\nimport type { ValidDotPathsFor } from '../transpiler';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\n\nexport type GetNestingResult<\n K extends DictionaryKeys,\n P = undefined,\n S = IInterpreterPluginState,\n> = GetSubPath<DeepTransformContent<DictionaryRegistryContent<K>, S>, P>;\n\n/**\n * Extracts content from another dictionary by its key and an optional path.\n *\n * This allows for reusing content across different dictionaries.\n *\n * @param dictionaryKey - The key of the dictionary to nest.\n * @param path - Optional dot-separated path to a specific field within the nested dictionary.\n * @param props - Optional properties like locale and plugins.\n * @returns The nested content.\n *\n * @example\n * ```ts\n * const content = getNesting(\"common\", \"buttons.save\");\n * // 'Save'\n * ```\n */\nexport const getNesting = <const K extends DictionaryKeys, const P>(\n dictionaryKey: K,\n path?: P extends ValidDotPathsFor<K> ? P : never,\n props?: NodeProps\n): GetNestingResult<K, P> => {\n const dictionary = getIntlayer(dictionaryKey, props?.locale, props?.plugins);\n\n if (typeof path === 'string') {\n const pathArray = (path as string).split('.');\n let current: any = dictionary;\n\n for (const key of pathArray) {\n // Safely traverse down the object using the path\n current = current?.[key];\n // If we cannot find the path, return the whole dictionary as a fallback\n if (current === undefined) {\n return dictionary as any;\n }\n }\n\n return current;\n }\n\n // Default or error handling if path is not a string or otherwise undefined\n return dictionary as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,MAAa,cACX,eACA,MACA,UAC2B;CAC3B,MAAM,aAAa,YAAY,eAAe,OAAO,QAAQ,OAAO,QAAQ;AAE5E,KAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,YAAa,KAAgB,MAAM,IAAI;EAC7C,IAAI,UAAe;AAEnB,OAAK,MAAM,OAAO,WAAW;AAE3B,aAAU,UAAU;AAEpB,OAAI,YAAY,OACd,QAAO;;AAIX,SAAO;;AAIT,QAAO"}
1
+ {"version":3,"file":"getNesting.mjs","names":[],"sources":["../../../src/interpreter/getNesting.ts"],"sourcesContent":["import type { GetSubPath } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n} from '@intlayer/types/module_augmentation';\nimport type { ValidDotPathsFor } from '../transpiler';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\n\nexport type GetNestingResult<\n K extends DictionaryKeys,\n P = undefined,\n S = IInterpreterPluginState,\n> = GetSubPath<DeepTransformContent<DictionaryRegistryContent<K>, S>, P>;\n\n/**\n * Extracts content from another dictionary by its key and an optional path.\n *\n * This allows for reusing content across different dictionaries.\n *\n * @param dictionaryKey - The key of the dictionary to nest.\n * @param path - Optional dot-separated path to a specific field within the nested dictionary.\n * @param props - Optional properties like locale and plugins.\n * @returns The nested content.\n *\n * @example\n * ```ts\n * const content = getNesting(\"common\", \"buttons.save\");\n * // 'Save'\n * ```\n */\nexport const getNesting = <const K extends DictionaryKeys, const P>(\n dictionaryKey: K,\n path?: P extends ValidDotPathsFor<K> ? P : never,\n props?: NodeProps\n): GetNestingResult<K, P> => {\n const dictionary = getIntlayer(dictionaryKey, props?.locale, props?.plugins);\n\n if (typeof path === 'string') {\n const pathArray = (path as string).split('.');\n let current: any = dictionary;\n\n for (const key of pathArray) {\n // Safely traverse down the object using the path\n current = current?.[key];\n // If we cannot find the path, return the whole dictionary as a fallback\n if (current === undefined) {\n return dictionary as any;\n }\n }\n\n return current;\n }\n\n // Default or error handling if path is not a string or otherwise undefined\n return dictionary as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,MAAa,cACX,eACA,MACA,UAC2B;CAC3B,MAAM,aAAa,YAAY,eAAe,OAAO,QAAQ,OAAO,OAAO;CAE3E,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,YAAa,KAAgB,MAAM,GAAG;EAC5C,IAAI,UAAe;EAEnB,KAAK,MAAM,OAAO,WAAW;GAE3B,UAAU,UAAU;GAEpB,IAAI,YAAY,QACd,OAAO;EAEX;EAEA,OAAO;CACT;CAGA,OAAO;AACT"}
@@ -17,7 +17,7 @@ import { getCachedIntl } from "../utils/intl.mjs";
17
17
  * ```
18
18
  */
19
19
  const getPlural = (pluralContent, count, locale) => {
20
- return pluralContent[getCachedIntl(Intl.PluralRules, locale).select(count)] ?? pluralContent.other;
20
+ return pluralContent[getCachedIntl("PluralRules", locale).select(count)] ?? pluralContent.other;
21
21
  };
22
22
 
23
23
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"getPlural.mjs","names":[],"sources":["../../../src/interpreter/getPlural.ts"],"sourcesContent":["import type { DeclaredLocales } from '@intlayer/types';\nimport type { LocalesValues } from 'intlayer';\nimport { getCachedIntl } from '../formatters';\nimport type {\n PluralCategory,\n PluralContentState,\n} from '../transpiler/plural/plural';\n\n/**\n * Picks content from a plural map based on a count and locale, using CLDR\n * pluralization rules (`Intl.PluralRules`).\n *\n * Falls back to the `other` category when no specific category matches.\n *\n * @example\n * ```ts\n * getPlural({\n * one: 'one item',\n * other: '{{count}} items',\n * }, 5, 'en');\n * // '{{count}} items'\n * ```\n */\nexport const getPlural = <const L extends LocalesValues = DeclaredLocales>(\n pluralContent: PluralContentState<string>,\n count: number,\n locale: L\n): string => {\n const category = getCachedIntl(Intl.PluralRules, locale).select(\n count\n ) as PluralCategory;\n\n return pluralContent[category] ?? pluralContent.other;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAa,aACX,eACA,OACA,WACW;AAKX,QAAO,cAJU,cAAc,KAAK,aAAa,OAAO,CAAC,OACvD,MAG2B,KAAK,cAAc"}
1
+ {"version":3,"file":"getPlural.mjs","names":[],"sources":["../../../src/interpreter/getPlural.ts"],"sourcesContent":["import type { DeclaredLocales } from '@intlayer/types';\nimport type { LocalesValues } from 'intlayer';\nimport { getCachedIntl } from '../formatters';\nimport type {\n PluralCategory,\n PluralContentState,\n} from '../transpiler/plural/plural';\n\n/**\n * Picks content from a plural map based on a count and locale, using CLDR\n * pluralization rules (`Intl.PluralRules`).\n *\n * Falls back to the `other` category when no specific category matches.\n *\n * @example\n * ```ts\n * getPlural({\n * one: 'one item',\n * other: '{{count}} items',\n * }, 5, 'en');\n * // '{{count}} items'\n * ```\n */\nexport const getPlural = <const L extends LocalesValues = DeclaredLocales>(\n pluralContent: PluralContentState<string>,\n count: number,\n locale: L\n): string => {\n const category = getCachedIntl('PluralRules', locale).select(\n count\n ) as PluralCategory;\n\n return pluralContent[category] ?? pluralContent.other;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAa,aACX,eACA,OACA,WACW;CAKX,OAAO,cAJU,cAAc,eAAe,MAAM,CAAC,CAAC,OACpD,KAG0B,MAAM,cAAc;AAClD"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely merged.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') return false;\n if (typeof (value as any).then === 'function') return false;\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects, skipping undefined source values.\n * First argument takes precedence. Arrays replace rather than merge.\n */\nconst deepMerge = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n if (Array.isArray(target)) return target;\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n\n for (const key of Object.keys(source)) {\n if (\n key === '__proto__' ||\n key === 'constructor' ||\n source[key] === undefined\n )\n continue;\n result[key] =\n target[key] !== undefined\n ? deepMerge(target[key], source[key])\n : source[key];\n }\n return result;\n }\n return target;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <const Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const get = (loc: string): Content | undefined =>\n languageContent[loc as keyof typeof languageContent];\n\n // Build priority-ordered locale candidates (most specific first), deduped\n const seen = new Set<string>();\n const locales: string[] = [];\n const addLocale = (loc: string | undefined) => {\n if (loc && !seen.has(loc)) {\n seen.add(loc);\n locales.push(loc);\n }\n };\n\n addLocale(locale);\n if (locale.includes('-')) addLocale(locale.split('-')[0]);\n\n addLocale(fallback);\n if (fallback?.includes('-')) addLocale(fallback.split('-')[0]);\n\n // Collect results: strings exit early (if no higher-priority object was found),\n // objects are accumulated for deep merging.\n const results: Content[] = [];\n\n for (const loc of locales) {\n const val = get(loc);\n\n if (val === undefined) continue;\n if (typeof val === 'string') {\n if (results.length === 0) return val;\n continue; // an object at higher priority takes precedence\n }\n\n results.push(val);\n }\n\n if (results.length === 0) return undefined as Content;\n if (results.length === 1) return results[0];\n if (Array.isArray(results[0])) return results[0];\n\n // Merge objects: first result (most specific) takes precedence\n return (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IAAI,CAAE,WAAU,SAAS,MAAM,IAAI,CAAC,GAAG;CAI9D,MAAM,UAAqB,EAAE;AAE7B,MAAK,MAAM,OAAO,SAAS;EACzB,MAAM,MAAM,IAAI,IAAI;AAEpB,MAAI,QAAQ,OAAW;AACvB,MAAI,OAAO,QAAQ,UAAU;AAC3B,OAAI,QAAQ,WAAW,EAAG,QAAO;AACjC;;AAGF,UAAQ,KAAK,IAAI;;AAGnB,KAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,KAAI,QAAQ,WAAW,EAAG,QAAO,QAAQ;AACzC,KAAI,MAAM,QAAQ,QAAQ,GAAG,CAAE,QAAO,QAAQ;AAG9C,QAAQ,QAAqB,QAAQ,KAAK,SACxC,UAAU,KAAK,KAAK,CACrB"}
1
+ {"version":3,"file":"getTranslation.mjs","names":[],"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\n\n/**\n * Check if a value is a plain object that can be safely merged.\n * Returns false for Promises, React elements, class instances, etc.\n */\nconst isPlainObject = (value: unknown): boolean => {\n if (value === null || typeof value !== 'object') return false;\n if (typeof (value as any).then === 'function') return false;\n if (\n (value as any).$$typeof !== undefined ||\n (value as any).__v_isVNode !== undefined ||\n (value as any)._isVNode !== undefined ||\n (value as any).isJSX !== undefined\n ) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null || Array.isArray(value);\n};\n\n/**\n * Recursively merges two objects, skipping undefined source values.\n * First argument takes precedence. Arrays replace rather than merge.\n */\nconst deepMerge = (target: any, source: any): any => {\n if (target === undefined) return source;\n if (source === undefined) return target;\n if (Array.isArray(target)) return target;\n if (isPlainObject(target) && isPlainObject(source)) {\n const result = { ...target };\n\n for (const key of Object.keys(source)) {\n if (\n key === '__proto__' ||\n key === 'constructor' ||\n source[key] === undefined\n )\n continue;\n result[key] =\n target[key] !== undefined\n ? deepMerge(target[key], source[key])\n : source[key];\n }\n return result;\n }\n return target;\n};\n\n/**\n * Picks the appropriate content from a locale map based on the provided locale.\n *\n * It handles:\n * 1. Exact locale match (e.g., 'en-US').\n * 2. Generic locale fallback (e.g., 'en' if 'en-US' is not found).\n * 3. Explicit fallback locale.\n * 4. Deep merging of objects to ensure partial translations are complemented by fallbacks.\n *\n * @param languageContent - A map of locales to content.\n * @param locale - The target locale to retrieve.\n * @param fallback - Optional fallback locale if the target is not found.\n * @returns The translated content.\n *\n * @example\n * ```ts\n * const content = getTranslation({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n */\nexport const getTranslation = <const Content = string>(\n languageContent: StrictModeLocaleMap<Content>,\n locale: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n const get = (loc: string): Content | undefined =>\n languageContent[loc as keyof typeof languageContent];\n\n // Build priority-ordered locale candidates (most specific first), deduped\n const seen = new Set<string>();\n const locales: string[] = [];\n const addLocale = (loc: string | undefined) => {\n if (loc && !seen.has(loc)) {\n seen.add(loc);\n locales.push(loc);\n }\n };\n\n addLocale(locale);\n if (locale.includes('-')) addLocale(locale.split('-')[0]);\n\n addLocale(fallback);\n if (fallback?.includes('-')) addLocale(fallback.split('-')[0]);\n\n // Collect results: strings exit early (if no higher-priority object was found),\n // objects are accumulated for deep merging.\n const results: Content[] = [];\n\n for (const loc of locales) {\n const val = get(loc);\n\n if (val === undefined) continue;\n if (typeof val === 'string') {\n if (results.length === 0) return val;\n continue; // an object at higher priority takes precedence\n }\n\n results.push(val);\n }\n\n if (results.length === 0) return undefined as Content;\n if (results.length === 1) return results[0];\n if (Array.isArray(results[0])) return results[0];\n\n // Merge objects: first result (most specific) takes precedence\n return (results as object[]).reduce((acc, curr) =>\n deepMerge(acc, curr)\n ) as Content;\n};\n"],"mappings":";;;;;AASA,MAAM,iBAAiB,UAA4B;CACjD,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CACxD,IAAI,OAAQ,MAAc,SAA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B,IAAI,QAAQ,QAAW;EACvB,IAAI,OAAO,QAAQ,UAAU;GAC3B,IAAI,QAAQ,WAAW,GAAG,OAAO;GACjC;EACF;EAEA,QAAQ,KAAK,GAAG;CAClB;CAEA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,IAAI,QAAQ,WAAW,GAAG,OAAO,QAAQ;CACzC,IAAI,MAAM,QAAQ,QAAQ,EAAE,GAAG,OAAO,QAAQ;CAG9C,OAAQ,QAAqB,QAAQ,KAAK,SACxC,UAAU,KAAK,IAAI,CACrB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"splitAndJoinInsertion.mjs","names":[],"sources":["../../../src/interpreter/splitAndJoinInsertion.ts"],"sourcesContent":["/**\n * Check if a value is a complex object (not a primitive)\n * Used to determine if values need to be wrapped in fragments\n */\nconst isComplexValue = (value: any): boolean =>\n value != null &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean';\n\n// Hoisted: replace/split do not suffer from the stateful lastIndex mutation of .exec()\nconst insertionRegex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n if (!Object.values(values).some(isComplexValue)) {\n return {\n isSimple: true,\n parts: template.replace(insertionRegex, (_, key) =>\n (values[key.trim()] ?? '').toString()\n ),\n };\n }\n\n const chunks = template.split(insertionRegex);\n const parts: any[] = [];\n\n for (let i = 0; i < chunks.length; i++) {\n if (i % 2 === 0) {\n if (chunks[i]) parts.push(chunks[i]);\n } else {\n const val = values[chunks[i].trim()];\n if (val != null) parts.push(val);\n }\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":";;;;;AAIA,MAAM,kBAAkB,UACtB,SAAS,QACT,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAGnB,MAAM,iBAAiB;AAEvB,MAAa,0BACX,UACA,SAA4B,EAAE,KACiB;AAC/C,KAAI,CAAC,OAAO,OAAO,OAAO,CAAC,KAAK,eAAe,CAC7C,QAAO;EACL,UAAU;EACV,OAAO,SAAS,QAAQ,iBAAiB,GAAG,SACzC,OAAO,IAAI,MAAM,KAAK,IAAI,UAAU,CACtC;EACF;CAGH,MAAM,SAAS,SAAS,MAAM,eAAe;CAC7C,MAAM,QAAe,EAAE;AAEvB,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,KAAI,IAAI,MAAM,GACZ;MAAI,OAAO,GAAI,OAAM,KAAK,OAAO,GAAG;QAC/B;EACL,MAAM,MAAM,OAAO,OAAO,GAAG,MAAM;AACnC,MAAI,OAAO,KAAM,OAAM,KAAK,IAAI;;AAIpC,QAAO;EAAE,UAAU;EAAO;EAAO"}
1
+ {"version":3,"file":"splitAndJoinInsertion.mjs","names":[],"sources":["../../../src/interpreter/splitAndJoinInsertion.ts"],"sourcesContent":["/**\n * Check if a value is a complex object (not a primitive)\n * Used to determine if values need to be wrapped in fragments\n */\nconst isComplexValue = (value: any): boolean =>\n value != null &&\n typeof value !== 'string' &&\n typeof value !== 'number' &&\n typeof value !== 'boolean';\n\n// Hoisted: replace/split do not suffer from the stateful lastIndex mutation of .exec()\nconst insertionRegex = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n\nexport const splitInsertionTemplate = <T = any>(\n template: string,\n values: Record<string, T> = {}\n): { isSimple: boolean; parts: string | T[] } => {\n if (!Object.values(values).some(isComplexValue)) {\n return {\n isSimple: true,\n parts: template.replace(insertionRegex, (_, key) =>\n (values[key.trim()] ?? '').toString()\n ),\n };\n }\n\n const chunks = template.split(insertionRegex);\n const parts: any[] = [];\n\n for (let i = 0; i < chunks.length; i++) {\n if (i % 2 === 0) {\n if (chunks[i]) parts.push(chunks[i]);\n } else {\n const val = values[chunks[i].trim()];\n if (val != null) parts.push(val);\n }\n }\n\n return { isSimple: false, parts };\n};\n"],"mappings":";;;;;AAIA,MAAM,kBAAkB,UACtB,SAAS,QACT,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAGnB,MAAM,iBAAiB;AAEvB,MAAa,0BACX,UACA,SAA4B,CAAC,MACkB;CAC/C,IAAI,CAAC,OAAO,OAAO,MAAM,CAAC,CAAC,KAAK,cAAc,GAC5C,OAAO;EACL,UAAU;EACV,OAAO,SAAS,QAAQ,iBAAiB,GAAG,SACzC,OAAO,IAAI,KAAK,MAAM,GAAE,CAAE,SAAS,CACtC;CACF;CAGF,MAAM,SAAS,SAAS,MAAM,cAAc;CAC5C,MAAM,QAAe,CAAC;CAEtB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KACjC,IAAI,IAAI,MAAM,GACZ;MAAI,OAAO,IAAI,MAAM,KAAK,OAAO,EAAE;CAAC,OAC/B;EACL,MAAM,MAAM,OAAO,OAAO,EAAE,CAAC,KAAK;EAClC,IAAI,OAAO,MAAM,MAAM,KAAK,GAAG;CACjC;CAGF,OAAO;EAAE,UAAU;EAAO;CAAM;AAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"comparePaths.mjs","names":[],"sources":["../../../src/localization/comparePaths.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Normalizes a URL or pathname into a canonical, locale-agnostic pathname so\n * that two paths pointing to the same page compare equal — useful for\n * highlighting the active navigation link.\n *\n * The normalization:\n * - strips the locale segment (reusing {@link getPathWithoutLocale})\n * - strips the protocol/host so absolute and relative inputs compare equally\n * - drops the query string and hash\n * - ensures a single leading slash\n * - removes any trailing slash (except for the root path)\n * - falls back to `'/'` for empty values\n *\n * Example:\n *\n * ```ts\n * normalizePath('/ru/path') // '/path'\n * normalizePath('/ru/path/') // '/path'\n * normalizePath('ru/path') // '/path'\n * normalizePath('/ru/') // '/'\n * normalizePath('/ru') // '/'\n * normalizePath('') // '/'\n * normalizePath('https://example.com/ru/path') // '/path'\n * ```\n *\n * @param inputUrl - The URL string or pathname to normalize.\n * @param locales - Optional array of supported locales. Defaults to the\n * configured locales.\n * @returns The normalized, locale-agnostic pathname.\n */\nexport const normalizePath = <const L extends LocalesValues = DeclaredLocales>(\n inputUrl: string,\n locales?: L[]\n): string => {\n const withoutLocale = getPathWithoutLocale(inputUrl || '/', locales);\n\n // Reuse the URL API to isolate the pathname from any host/query/hash.\n const url = checkIsURLAbsolute(withoutLocale)\n ? new URL(withoutLocale)\n : new URL(withoutLocale, 'http://example.com');\n\n const { pathname } = url;\n\n // Remove a trailing slash, keeping the root path intact.\n if (pathname.length > 1 && pathname.endsWith('/')) {\n return pathname.slice(0, -1);\n }\n\n return pathname || '/';\n};\n\n/**\n * Compares two URLs or pathnames for equality, ignoring locale segment,\n * protocol/host, query string, hash and trailing slashes.\n *\n * Both inputs are normalized through {@link normalizePath} before comparison,\n * making this ideal for matching the current pathname against a navigation\n * link's `href`.\n *\n * Example:\n *\n * ```ts\n * comparePaths('/ru/path', '/path') // true\n * comparePaths('/ru/path/', '/path') // true\n * comparePaths('/ru/path', '/path/') // true\n * comparePaths('/ru/', '/') // true\n * comparePaths('/ru', '/') // true\n * comparePaths('ru/path', '/path') // true\n * comparePaths('', '/') // true\n * comparePaths('/ru', '') // true\n * comparePaths('/ru/path', '/other') // false\n * ```\n *\n * @param pathname - The first URL string or pathname to compare.\n * @param href - The second URL string or pathname to compare.\n * @param locales - Optional array of supported locales. Defaults to the\n * configured locales.\n * @returns `true` when both inputs resolve to the same locale-agnostic path.\n */\nexport const comparePaths = <const L extends LocalesValues = DeclaredLocales>(\n pathname: string,\n href: string,\n locales?: L[]\n): boolean => normalizePath(pathname, locales) === normalizePath(href, locales);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,iBACX,UACA,YACW;CACX,MAAM,gBAAgB,qBAAqB,YAAY,KAAK,QAAQ;CAOpE,MAAM,EAAE,aAJI,mBAAmB,cAAc,GACzC,IAAI,IAAI,cAAc,GACtB,IAAI,IAAI,eAAe,qBAAqB;AAKhD,KAAI,SAAS,SAAS,KAAK,SAAS,SAAS,IAAI,CAC/C,QAAO,SAAS,MAAM,GAAG,GAAG;AAG9B,QAAO,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BrB,MAAa,gBACX,UACA,MACA,YACY,cAAc,UAAU,QAAQ,KAAK,cAAc,MAAM,QAAQ"}
1
+ {"version":3,"file":"comparePaths.mjs","names":[],"sources":["../../../src/localization/comparePaths.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Normalizes a URL or pathname into a canonical, locale-agnostic pathname so\n * that two paths pointing to the same page compare equal — useful for\n * highlighting the active navigation link.\n *\n * The normalization:\n * - strips the locale segment (reusing {@link getPathWithoutLocale})\n * - strips the protocol/host so absolute and relative inputs compare equally\n * - drops the query string and hash\n * - ensures a single leading slash\n * - removes any trailing slash (except for the root path)\n * - falls back to `'/'` for empty values\n *\n * Example:\n *\n * ```ts\n * normalizePath('/ru/path') // '/path'\n * normalizePath('/ru/path/') // '/path'\n * normalizePath('ru/path') // '/path'\n * normalizePath('/ru/') // '/'\n * normalizePath('/ru') // '/'\n * normalizePath('') // '/'\n * normalizePath('https://example.com/ru/path') // '/path'\n * ```\n *\n * @param inputUrl - The URL string or pathname to normalize.\n * @param locales - Optional array of supported locales. Defaults to the\n * configured locales.\n * @returns The normalized, locale-agnostic pathname.\n */\nexport const normalizePath = <const L extends LocalesValues = DeclaredLocales>(\n inputUrl: string,\n locales?: L[]\n): string => {\n const withoutLocale = getPathWithoutLocale(inputUrl || '/', locales);\n\n // Reuse the URL API to isolate the pathname from any host/query/hash.\n const url = checkIsURLAbsolute(withoutLocale)\n ? new URL(withoutLocale)\n : new URL(withoutLocale, 'http://example.com');\n\n const { pathname } = url;\n\n // Remove a trailing slash, keeping the root path intact.\n if (pathname.length > 1 && pathname.endsWith('/')) {\n return pathname.slice(0, -1);\n }\n\n return pathname || '/';\n};\n\n/**\n * Compares two URLs or pathnames for equality, ignoring locale segment,\n * protocol/host, query string, hash and trailing slashes.\n *\n * Both inputs are normalized through {@link normalizePath} before comparison,\n * making this ideal for matching the current pathname against a navigation\n * link's `href`.\n *\n * Example:\n *\n * ```ts\n * comparePaths('/ru/path', '/path') // true\n * comparePaths('/ru/path/', '/path') // true\n * comparePaths('/ru/path', '/path/') // true\n * comparePaths('/ru/', '/') // true\n * comparePaths('/ru', '/') // true\n * comparePaths('ru/path', '/path') // true\n * comparePaths('', '/') // true\n * comparePaths('/ru', '') // true\n * comparePaths('/ru/path', '/other') // false\n * ```\n *\n * @param pathname - The first URL string or pathname to compare.\n * @param href - The second URL string or pathname to compare.\n * @param locales - Optional array of supported locales. Defaults to the\n * configured locales.\n * @returns `true` when both inputs resolve to the same locale-agnostic path.\n */\nexport const comparePaths = <const L extends LocalesValues = DeclaredLocales>(\n pathname: string,\n href: string,\n locales?: L[]\n): boolean => normalizePath(pathname, locales) === normalizePath(href, locales);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,iBACX,UACA,YACW;CACX,MAAM,gBAAgB,qBAAqB,YAAY,KAAK,OAAO;CAOnE,MAAM,EAAE,aAJI,mBAAmB,aAAa,IACxC,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;CAK/C,IAAI,SAAS,SAAS,KAAK,SAAS,SAAS,GAAG,GAC9C,OAAO,SAAS,MAAM,GAAG,EAAE;CAG7B,OAAO,YAAY;AACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,gBACX,UACA,MACA,YACY,cAAc,UAAU,OAAO,MAAM,cAAc,MAAM,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"domainUtils.mjs","names":[],"sources":["../../../src/localization/domainUtils.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * The locale → domain map configured under `routing.domains`\n * (e.g. `{ en: 'intlayer.org', zh: 'intlayer.cn' }`).\n */\nexport type LocaleDomainMap = RoutingConfig['domains'];\n\n/**\n * Strips the protocol from a domain string and returns only the hostname.\n *\n * Example:\n *\n * ```ts\n * getDomainHostname('https://intlayer.cn') // 'intlayer.cn'\n * getDomainHostname('intlayer.cn') // 'intlayer.cn'\n * ```\n *\n * @param domain - A domain value from `routing.domains`, with or without protocol.\n * @returns The bare hostname.\n */\nexport const getDomainHostname = (domain: string): string => {\n try {\n return /^https?:\\/\\//.test(domain) ? new URL(domain).hostname : domain;\n } catch {\n return domain;\n }\n};\n\n/**\n * Returns the absolute origin for a domain value, prepending `https://`\n * when no protocol is present.\n *\n * Example:\n *\n * ```ts\n * getDomainOrigin('intlayer.cn') // 'https://intlayer.cn'\n * getDomainOrigin('http://intlayer.cn') // 'http://intlayer.cn'\n * ```\n *\n * @param domain - A domain value from `routing.domains`, with or without protocol.\n * @returns The origin usable as a URL base.\n */\nexport const getDomainOrigin = (domain: string): string =>\n /^https?:\\/\\//.test(domain) ? domain : `https://${domain}`;\n\n/**\n * Returns the locale exclusively mapped to a given hostname via `routing.domains`,\n * or `undefined` when zero or more than one locale share that hostname.\n *\n * Example: with `domains = { zh: 'intlayer.cn', en: 'intlayer.org', fr: 'intlayer.org' }`\n *\n * ```ts\n * getLocaleFromDomain('intlayer.cn', domains) // 'zh'\n * getLocaleFromDomain('intlayer.org', domains) // undefined (en and fr share it)\n * getLocaleFromDomain('example.com', domains) // undefined (not mapped)\n * ```\n *\n * @param hostname - The bare hostname of the incoming request.\n * @param domains - The configured locale → domain map.\n * @returns The exclusively mapped locale, or `undefined`.\n */\nexport const getLocaleFromDomain = (\n hostname: string,\n domains: LocaleDomainMap\n): Locale | undefined => {\n if (!domains) return undefined;\n\n const matchingLocales = Object.entries(domains).filter(\n ([, domain]) =>\n typeof domain === 'string' && getDomainHostname(domain) === hostname\n );\n\n return matchingLocales.length === 1\n ? (matchingLocales[0]?.[0] as Locale)\n : undefined;\n};\n\n/**\n * Checks whether a locale is the only locale mapped to its configured domain.\n * When true, the domain alone identifies the locale and no URL prefix is needed.\n * Hostnames are compared after protocol stripping, so\n * `{ en: 'https://intlayer.org', fr: 'intlayer.org' }` counts as a shared domain.\n *\n * @param locale - The locale to check.\n * @param domains - The configured locale → domain map.\n * @returns `true` when the locale has a domain shared with no other locale.\n */\nexport const isLocaleExclusiveOnDomain = (\n locale: LocalesValues,\n domains: LocaleDomainMap\n): boolean => {\n const localeDomain = domains?.[locale];\n\n if (!localeDomain) return false;\n\n const localeHostname = getDomainHostname(localeDomain);\n\n const localesOnSameDomain = Object.values(domains).filter(\n (domain) =>\n typeof domain === 'string' && getDomainHostname(domain) === localeHostname\n ).length;\n\n return localesOnSameDomain === 1;\n};\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,qBAAqB,WAA2B;AAC3D,KAAI;AACF,SAAO,eAAe,KAAK,OAAO,GAAG,IAAI,IAAI,OAAO,CAAC,WAAW;SAC1D;AACN,SAAO;;;;;;;;;;;;;;;;;AAkBX,MAAa,mBAAmB,WAC9B,eAAe,KAAK,OAAO,GAAG,SAAS,WAAW;;;;;;;;;;;;;;;;;AAkBpD,MAAa,uBACX,UACA,YACuB;AACvB,KAAI,CAAC,QAAS,QAAO;CAErB,MAAM,kBAAkB,OAAO,QAAQ,QAAQ,CAAC,QAC7C,GAAG,YACF,OAAO,WAAW,YAAY,kBAAkB,OAAO,KAAK,SAC/D;AAED,QAAO,gBAAgB,WAAW,IAC7B,gBAAgB,KAAK,KACtB;;;;;;;;;;;;AAaN,MAAa,6BACX,QACA,YACY;CACZ,MAAM,eAAe,UAAU;AAE/B,KAAI,CAAC,aAAc,QAAO;CAE1B,MAAM,iBAAiB,kBAAkB,aAAa;AAOtD,QAL4B,OAAO,OAAO,QAAQ,CAAC,QAChD,WACC,OAAO,WAAW,YAAY,kBAAkB,OAAO,KAAK,eAC/D,CAAC,WAE6B"}
1
+ {"version":3,"file":"domainUtils.mjs","names":[],"sources":["../../../src/localization/domainUtils.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * The locale → domain map configured under `routing.domains`\n * (e.g. `{ en: 'intlayer.org', zh: 'intlayer.cn' }`).\n */\nexport type LocaleDomainMap = RoutingConfig['domains'];\n\n/**\n * Strips the protocol from a domain string and returns only the hostname.\n *\n * Example:\n *\n * ```ts\n * getDomainHostname('https://intlayer.cn') // 'intlayer.cn'\n * getDomainHostname('intlayer.cn') // 'intlayer.cn'\n * ```\n *\n * @param domain - A domain value from `routing.domains`, with or without protocol.\n * @returns The bare hostname.\n */\nexport const getDomainHostname = (domain: string): string => {\n try {\n return /^https?:\\/\\//.test(domain) ? new URL(domain).hostname : domain;\n } catch {\n return domain;\n }\n};\n\n/**\n * Returns the absolute origin for a domain value, prepending `https://`\n * when no protocol is present.\n *\n * Example:\n *\n * ```ts\n * getDomainOrigin('intlayer.cn') // 'https://intlayer.cn'\n * getDomainOrigin('http://intlayer.cn') // 'http://intlayer.cn'\n * ```\n *\n * @param domain - A domain value from `routing.domains`, with or without protocol.\n * @returns The origin usable as a URL base.\n */\nexport const getDomainOrigin = (domain: string): string =>\n /^https?:\\/\\//.test(domain) ? domain : `https://${domain}`;\n\n/**\n * Returns the locale exclusively mapped to a given hostname via `routing.domains`,\n * or `undefined` when zero or more than one locale share that hostname.\n *\n * Example: with `domains = { zh: 'intlayer.cn', en: 'intlayer.org', fr: 'intlayer.org' }`\n *\n * ```ts\n * getLocaleFromDomain('intlayer.cn', domains) // 'zh'\n * getLocaleFromDomain('intlayer.org', domains) // undefined (en and fr share it)\n * getLocaleFromDomain('example.com', domains) // undefined (not mapped)\n * ```\n *\n * @param hostname - The bare hostname of the incoming request.\n * @param domains - The configured locale → domain map.\n * @returns The exclusively mapped locale, or `undefined`.\n */\nexport const getLocaleFromDomain = (\n hostname: string,\n domains: LocaleDomainMap\n): Locale | undefined => {\n if (!domains) return undefined;\n\n const matchingLocales = Object.entries(domains).filter(\n ([, domain]) =>\n typeof domain === 'string' && getDomainHostname(domain) === hostname\n );\n\n return matchingLocales.length === 1\n ? (matchingLocales[0]?.[0] as Locale)\n : undefined;\n};\n\n/**\n * Checks whether a locale is the only locale mapped to its configured domain.\n * When true, the domain alone identifies the locale and no URL prefix is needed.\n * Hostnames are compared after protocol stripping, so\n * `{ en: 'https://intlayer.org', fr: 'intlayer.org' }` counts as a shared domain.\n *\n * @param locale - The locale to check.\n * @param domains - The configured locale → domain map.\n * @returns `true` when the locale has a domain shared with no other locale.\n */\nexport const isLocaleExclusiveOnDomain = (\n locale: LocalesValues,\n domains: LocaleDomainMap\n): boolean => {\n const localeDomain = domains?.[locale];\n\n if (!localeDomain) return false;\n\n const localeHostname = getDomainHostname(localeDomain);\n\n const localesOnSameDomain = Object.values(domains).filter(\n (domain) =>\n typeof domain === 'string' && getDomainHostname(domain) === localeHostname\n ).length;\n\n return localesOnSameDomain === 1;\n};\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,qBAAqB,WAA2B;CAC3D,IAAI;EACF,OAAO,eAAe,KAAK,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,WAAW;CAClE,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;;;;;AAgBA,MAAa,mBAAmB,WAC9B,eAAe,KAAK,MAAM,IAAI,SAAS,WAAW;;;;;;;;;;;;;;;;;AAkBpD,MAAa,uBACX,UACA,YACuB;CACvB,IAAI,CAAC,SAAS,OAAO;CAErB,MAAM,kBAAkB,OAAO,QAAQ,OAAO,CAAC,CAAC,QAC7C,GAAG,YACF,OAAO,WAAW,YAAY,kBAAkB,MAAM,MAAM,QAChE;CAEA,OAAO,gBAAgB,WAAW,IAC7B,gBAAgB,EAAE,GAAG,KACtB;AACN;;;;;;;;;;;AAYA,MAAa,6BACX,QACA,YACY;CACZ,MAAM,eAAe,UAAU;CAE/B,IAAI,CAAC,cAAc,OAAO;CAE1B,MAAM,iBAAiB,kBAAkB,YAAY;CAOrD,OAL4B,OAAO,OAAO,OAAO,CAAC,CAAC,QAChD,WACC,OAAO,WAAW,YAAY,kBAAkB,MAAM,MAAM,cAChE,CAAC,CAAC,WAE6B;AACjC"}
@@ -90,7 +90,8 @@ const generateSitemapUrl = (path, options) => {
90
90
  */
91
91
  const generateSitemap = (entries, options) => {
92
92
  const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;
93
- const includeAlternates = shouldIncludeAlternates(resolveRoutingConfig(routingOptions).mode, xhtmlLinks);
93
+ const resolved = resolveRoutingConfig(routingOptions);
94
+ const includeAlternates = shouldIncludeAlternates(resolved.mode, xhtmlLinks);
94
95
  const xmlEntries = entries.map((entry) => generateSitemapUrl(entry.path, {
95
96
  ...entry,
96
97
  siteUrl,
@@ -1 +1 @@
1
- {"version":3,"file":"generateSitemap.mjs","names":[],"sources":["../../../src/localization/generateSitemap.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getMultilingualUrls } from './getMultilingualUrls';\nimport { type RoutingOptions, resolveRoutingConfig } from './getPrefix';\n\nexport type SitemapUrlEntry = {\n /** The canonical path, e.g. '/dashboard' */\n path: string;\n changefreq?: string;\n priority?: number;\n /** ISO date string, e.g. '2024-01-15' */\n lastmod?: string;\n};\n\nexport type GenerateSitemapOptions = {\n /** Base site URL without trailing slash, e.g. 'https://example.com' */\n siteUrl: string;\n /**\n * Whether to include xhtml:link alternate tags for multilingual support.\n *\n * When enabled, alternate links are only generated for modes where URLs\n * differ per locale:\n * - 'prefix-no-default': included\n * - 'prefix-all': included\n * - 'search-params': included\n * - 'no-prefix': excluded (all locales share the same URL)\n *\n * @default true\n */\n xhtmlLinks?: boolean;\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n};\n\n/**\n * Returns whether xhtml:link alternate tags should be generated for the given routing mode.\n *\n * Alternates are meaningful only when locale URLs are distinct:\n * - 'no-prefix' produces identical URLs for all locales → no alternates\n * - all other modes produce distinct URLs → alternates are generated\n */\nconst shouldIncludeAlternates = (\n mode: RoutingConfig['mode'],\n xhtmlLinks: boolean\n): boolean => xhtmlLinks && mode !== 'no-prefix';\n\n/**\n * Generates a single `<url>` sitemap entry for the given path.\n *\n * Example:\n *\n * ```ts\n * generateSitemapUrl('/dashboard', {\n * siteUrl: 'https://example.com',\n * changefreq: 'weekly',\n * priority: 0.8,\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * });\n * // Returns:\n * // <url>\n * // <loc>https://example.com/dashboard</loc>\n * // <changefreq>weekly</changefreq>\n * // <priority>0.8</priority>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"en\" href=\"https://example.com/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"fr\" href=\"https://example.com/fr/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"x-default\" href=\"https://example.com/dashboard\"/>\n * // </url>\n * ```\n *\n * @param path - The canonical path to generate the entry for.\n * @param options - Configuration options.\n * @returns A `<url>` XML string.\n */\nexport const generateSitemapUrl = (\n path: string,\n options: SitemapUrlEntry & GenerateSitemapOptions\n): string => {\n const {\n siteUrl,\n changefreq,\n priority,\n lastmod,\n xhtmlLinks = true,\n ...routingOptions\n } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const fullUrl = `${siteUrl}${path}`;\n\n const lines: (string | null)[] = [\n ' <url>',\n ` <loc>${fullUrl}</loc>`,\n lastmod ? ` <lastmod>${lastmod}</lastmod>` : null,\n changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,\n priority !== undefined ? ` <priority>${priority}</priority>` : null,\n ];\n\n const hasFileExtension = /\\.[a-z0-9]+$/i.test(path);\n if (shouldIncludeAlternates(resolved.mode, xhtmlLinks) && !hasFileExtension) {\n const alternates = getMultilingualUrls(\n path,\n routingOptions as RoutingOptions\n );\n\n for (const [lang, localePath] of Object.entries(alternates)) {\n lines.push(\n ` <xhtml:link rel=\"alternate\" hreflang=\"${lang}\" href=\"${siteUrl}${localePath}\"/>`\n );\n }\n\n lines.push(\n ` <xhtml:link rel=\"alternate\" hreflang=\"x-default\" href=\"${fullUrl}\"/>`\n );\n }\n\n lines.push(' </url>');\n\n return lines.filter(Boolean).join('\\n');\n};\n\n/**\n * Generates a full XML sitemap string from an array of URL entries.\n *\n * Automatically adds `xmlns:xhtml` to the `<urlset>` declaration when\n * xhtml:link alternate tags are included.\n *\n * Example:\n *\n * ```ts\n * generateSitemap(\n * [\n * { path: '/', changefreq: 'daily', priority: 1.0 },\n * { path: '/about', changefreq: 'monthly', priority: 0.5 },\n * ],\n * {\n * siteUrl: 'https://example.com',\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * }\n * );\n * ```\n *\n * @param entries - Array of URL entries to include in the sitemap.\n * @param options - Sitemap generation options.\n * @returns A full XML sitemap string.\n */\nexport const generateSitemap = (\n entries: SitemapUrlEntry[],\n options: GenerateSitemapOptions\n): string => {\n const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const includeAlternates = shouldIncludeAlternates(resolved.mode, xhtmlLinks);\n\n const xmlEntries = entries.map((entry) =>\n generateSitemapUrl(entry.path, {\n ...entry,\n siteUrl,\n xhtmlLinks,\n ...routingOptions,\n })\n );\n\n const xmlns = includeAlternates\n ? '\\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"'\n : '';\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"${xmlns}\n>\n${xmlEntries.join('\\n')}\n</urlset>`;\n};\n"],"mappings":";;;;;;;;;;;AA2CA,MAAM,2BACJ,MACA,eACY,cAAc,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCrC,MAAa,sBACX,MACA,YACW;CACX,MAAM,EACJ,SACA,YACA,UACA,SACA,aAAa,MACb,GAAG,mBACD;CAEJ,MAAM,WAAW,qBAAqB,eAAiC;CACvE,MAAM,UAAU,GAAG,UAAU;CAE7B,MAAM,QAA2B;EAC/B;EACA,YAAY,QAAQ;EACpB,UAAU,gBAAgB,QAAQ,cAAc;EAChD,aAAa,mBAAmB,WAAW,iBAAiB;EAC5D,aAAa,SAAY,iBAAiB,SAAS,eAAe;EACnE;CAED,MAAM,mBAAmB,gBAAgB,KAAK,KAAK;AACnD,KAAI,wBAAwB,SAAS,MAAM,WAAW,IAAI,CAAC,kBAAkB;EAC3E,MAAM,aAAa,oBACjB,MACA,eACD;AAED,OAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,WAAW,CACzD,OAAM,KACJ,6CAA6C,KAAK,UAAU,UAAU,WAAW,KAClF;AAGH,QAAM,KACJ,8DAA8D,QAAQ,KACvE;;AAGH,OAAM,KAAK,WAAW;AAEtB,QAAO,MAAM,OAAO,QAAQ,CAAC,KAAK,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BzC,MAAa,mBACX,SACA,YACW;CACX,MAAM,EAAE,SAAS,aAAa,MAAM,GAAG,mBAAmB;CAG1D,MAAM,oBAAoB,wBADT,qBAAqB,eACoB,CAAC,MAAM,WAAW;CAE5E,MAAM,aAAa,QAAQ,KAAK,UAC9B,mBAAmB,MAAM,MAAM;EAC7B,GAAG;EACH;EACA;EACA,GAAG;EACJ,CAAC,CACH;AAMD,QAAO;;uDAJO,oBACV,qDACA,GAIuD;;EAE3D,WAAW,KAAK,KAAK,CAAC"}
1
+ {"version":3,"file":"generateSitemap.mjs","names":[],"sources":["../../../src/localization/generateSitemap.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getMultilingualUrls } from './getMultilingualUrls';\nimport { type RoutingOptions, resolveRoutingConfig } from './getPrefix';\n\nexport type SitemapUrlEntry = {\n /** The canonical path, e.g. '/dashboard' */\n path: string;\n changefreq?: string;\n priority?: number;\n /** ISO date string, e.g. '2024-01-15' */\n lastmod?: string;\n};\n\nexport type GenerateSitemapOptions = {\n /** Base site URL without trailing slash, e.g. 'https://example.com' */\n siteUrl: string;\n /**\n * Whether to include xhtml:link alternate tags for multilingual support.\n *\n * When enabled, alternate links are only generated for modes where URLs\n * differ per locale:\n * - 'prefix-no-default': included\n * - 'prefix-all': included\n * - 'search-params': included\n * - 'no-prefix': excluded (all locales share the same URL)\n *\n * @default true\n */\n xhtmlLinks?: boolean;\n locales?: LocalesValues[];\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n rewrite?: RoutingConfig['rewrite'];\n};\n\n/**\n * Returns whether xhtml:link alternate tags should be generated for the given routing mode.\n *\n * Alternates are meaningful only when locale URLs are distinct:\n * - 'no-prefix' produces identical URLs for all locales → no alternates\n * - all other modes produce distinct URLs → alternates are generated\n */\nconst shouldIncludeAlternates = (\n mode: RoutingConfig['mode'],\n xhtmlLinks: boolean\n): boolean => xhtmlLinks && mode !== 'no-prefix';\n\n/**\n * Generates a single `<url>` sitemap entry for the given path.\n *\n * Example:\n *\n * ```ts\n * generateSitemapUrl('/dashboard', {\n * siteUrl: 'https://example.com',\n * changefreq: 'weekly',\n * priority: 0.8,\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * });\n * // Returns:\n * // <url>\n * // <loc>https://example.com/dashboard</loc>\n * // <changefreq>weekly</changefreq>\n * // <priority>0.8</priority>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"en\" href=\"https://example.com/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"fr\" href=\"https://example.com/fr/dashboard\"/>\n * // <xhtml:link rel=\"alternate\" hrefLang=\"x-default\" href=\"https://example.com/dashboard\"/>\n * // </url>\n * ```\n *\n * @param path - The canonical path to generate the entry for.\n * @param options - Configuration options.\n * @returns A `<url>` XML string.\n */\nexport const generateSitemapUrl = (\n path: string,\n options: SitemapUrlEntry & GenerateSitemapOptions\n): string => {\n const {\n siteUrl,\n changefreq,\n priority,\n lastmod,\n xhtmlLinks = true,\n ...routingOptions\n } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const fullUrl = `${siteUrl}${path}`;\n\n const lines: (string | null)[] = [\n ' <url>',\n ` <loc>${fullUrl}</loc>`,\n lastmod ? ` <lastmod>${lastmod}</lastmod>` : null,\n changefreq ? ` <changefreq>${changefreq}</changefreq>` : null,\n priority !== undefined ? ` <priority>${priority}</priority>` : null,\n ];\n\n const hasFileExtension = /\\.[a-z0-9]+$/i.test(path);\n if (shouldIncludeAlternates(resolved.mode, xhtmlLinks) && !hasFileExtension) {\n const alternates = getMultilingualUrls(\n path,\n routingOptions as RoutingOptions\n );\n\n for (const [lang, localePath] of Object.entries(alternates)) {\n lines.push(\n ` <xhtml:link rel=\"alternate\" hreflang=\"${lang}\" href=\"${siteUrl}${localePath}\"/>`\n );\n }\n\n lines.push(\n ` <xhtml:link rel=\"alternate\" hreflang=\"x-default\" href=\"${fullUrl}\"/>`\n );\n }\n\n lines.push(' </url>');\n\n return lines.filter(Boolean).join('\\n');\n};\n\n/**\n * Generates a full XML sitemap string from an array of URL entries.\n *\n * Automatically adds `xmlns:xhtml` to the `<urlset>` declaration when\n * xhtml:link alternate tags are included.\n *\n * Example:\n *\n * ```ts\n * generateSitemap(\n * [\n * { path: '/', changefreq: 'daily', priority: 1.0 },\n * { path: '/about', changefreq: 'monthly', priority: 0.5 },\n * ],\n * {\n * siteUrl: 'https://example.com',\n * xhtmlLinks: true,\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * mode: 'prefix-no-default',\n * }\n * );\n * ```\n *\n * @param entries - Array of URL entries to include in the sitemap.\n * @param options - Sitemap generation options.\n * @returns A full XML sitemap string.\n */\nexport const generateSitemap = (\n entries: SitemapUrlEntry[],\n options: GenerateSitemapOptions\n): string => {\n const { siteUrl, xhtmlLinks = true, ...routingOptions } = options;\n\n const resolved = resolveRoutingConfig(routingOptions as RoutingOptions);\n const includeAlternates = shouldIncludeAlternates(resolved.mode, xhtmlLinks);\n\n const xmlEntries = entries.map((entry) =>\n generateSitemapUrl(entry.path, {\n ...entry,\n siteUrl,\n xhtmlLinks,\n ...routingOptions,\n })\n );\n\n const xmlns = includeAlternates\n ? '\\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"'\n : '';\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"${xmlns}\n>\n${xmlEntries.join('\\n')}\n</urlset>`;\n};\n"],"mappings":";;;;;;;;;;;AA2CA,MAAM,2BACJ,MACA,eACY,cAAc,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCrC,MAAa,sBACX,MACA,YACW;CACX,MAAM,EACJ,SACA,YACA,UACA,SACA,aAAa,MACb,GAAG,mBACD;CAEJ,MAAM,WAAW,qBAAqB,cAAgC;CACtE,MAAM,UAAU,GAAG,UAAU;CAE7B,MAAM,QAA2B;EAC/B;EACA,YAAY,QAAQ;EACpB,UAAU,gBAAgB,QAAQ,cAAc;EAChD,aAAa,mBAAmB,WAAW,iBAAiB;EAC5D,aAAa,SAAY,iBAAiB,SAAS,eAAe;CACpE;CAEA,MAAM,mBAAmB,gBAAgB,KAAK,IAAI;CAClD,IAAI,wBAAwB,SAAS,MAAM,UAAU,KAAK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