adnbn 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (608) hide show
  1. package/dist/cli/builders/locale/LocaleBuilder.js +2 -11
  2. package/dist/cli/builders/locale/LocaleBuilder.js.map +1 -1
  3. package/dist/cli/builders/locale/index.js +1 -1
  4. package/dist/cli/builders/locale/index.js.map +1 -1
  5. package/dist/cli/builders/manifest/ManifestBase.d.ts +4 -1
  6. package/dist/cli/builders/manifest/ManifestBase.js +35 -6
  7. package/dist/cli/builders/manifest/ManifestBase.js.map +1 -1
  8. package/dist/cli/builders/manifest/ManifestV2.js +1 -1
  9. package/dist/cli/builders/manifest/ManifestV3.js +12 -5
  10. package/dist/cli/builders/manifest/ManifestV3.js.map +1 -1
  11. package/dist/cli/builders/manifest/utils/data-collection-permissions.d.ts +15 -0
  12. package/dist/cli/builders/manifest/utils/data-collection-permissions.js +26 -0
  13. package/dist/cli/builders/manifest/utils/data-collection-permissions.js.map +1 -0
  14. package/dist/cli/builders/manifest/utils/host-patterns.d.ts +1 -0
  15. package/dist/cli/builders/manifest/utils/host-patterns.js +40 -0
  16. package/dist/cli/builders/manifest/utils/host-patterns.js.map +1 -0
  17. package/dist/cli/builders/manifest/utils/index.d.ts +4 -0
  18. package/dist/cli/builders/manifest/utils/index.js +19 -0
  19. package/dist/cli/builders/manifest/utils/index.js.map +1 -0
  20. package/dist/cli/builders/manifest/utils/permissions.d.ts +14 -0
  21. package/dist/cli/builders/manifest/utils/permissions.js +34 -0
  22. package/dist/cli/builders/manifest/utils/permissions.js.map +1 -0
  23. package/dist/cli/builders/manifest/utils/web-accessible-resources.d.ts +2 -0
  24. package/dist/cli/builders/manifest/utils/web-accessible-resources.js +92 -0
  25. package/dist/cli/builders/manifest/utils/web-accessible-resources.js.map +1 -0
  26. package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.d.ts +14 -0
  27. package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js +523 -0
  28. package/dist/cli/bundler/plugins/build-assets-map/BuildAssetsMapPlugin.js.map +1 -0
  29. package/dist/cli/bundler/plugins/build-assets-map/entrypoint-module.d.ts +13 -0
  30. package/dist/cli/bundler/plugins/build-assets-map/entrypoint-module.js +16 -0
  31. package/dist/cli/bundler/plugins/build-assets-map/entrypoint-module.js.map +1 -0
  32. package/dist/cli/bundler/plugins/build-assets-map/index.d.ts +3 -0
  33. package/dist/cli/bundler/plugins/build-assets-map/index.js +8 -0
  34. package/dist/cli/bundler/plugins/build-assets-map/index.js.map +1 -0
  35. package/dist/cli/bundler/plugins/build-assets-map/usage.d.ts +12 -0
  36. package/dist/cli/bundler/plugins/build-assets-map/usage.js +28 -0
  37. package/dist/cli/bundler/plugins/build-assets-map/usage.js.map +1 -0
  38. package/dist/cli/bundler/plugins/chunk-loader/ChunkLoaderPlugin.d.ts +9 -0
  39. package/dist/cli/bundler/plugins/chunk-loader/ChunkLoaderPlugin.js +43 -0
  40. package/dist/cli/bundler/plugins/chunk-loader/ChunkLoaderPlugin.js.map +1 -0
  41. package/dist/cli/bundler/plugins/chunk-loader/index.d.ts +1 -0
  42. package/dist/cli/bundler/plugins/chunk-loader/index.js +5 -0
  43. package/dist/cli/bundler/plugins/chunk-loader/index.js.map +1 -0
  44. package/dist/cli/bundler/plugins/chunk-loader/templates/runtime.template.d.ts +2 -0
  45. package/dist/cli/bundler/plugins/chunk-loader/templates.d.ts +7 -0
  46. package/dist/cli/bundler/plugins/chunk-loader/templates.js +30 -0
  47. package/dist/cli/bundler/plugins/{EntrypointPlugin.d.ts → entrypoint/EntrypointPlugin.d.ts} +7 -2
  48. package/dist/cli/bundler/plugins/{EntrypointPlugin.js → entrypoint/EntrypointPlugin.js} +46 -26
  49. package/dist/cli/bundler/plugins/entrypoint/EntrypointPlugin.js.map +1 -0
  50. package/dist/cli/bundler/plugins/entrypoint/index.d.ts +1 -0
  51. package/dist/cli/bundler/plugins/entrypoint/index.js +7 -0
  52. package/dist/cli/bundler/plugins/entrypoint/index.js.map +1 -0
  53. package/dist/cli/bundler/plugins/{GenerateJsonPlugin.d.ts → generate-json/GenerateJsonPlugin.d.ts} +1 -0
  54. package/dist/cli/bundler/plugins/generate-json/GenerateJsonPlugin.js +73 -0
  55. package/dist/cli/bundler/plugins/generate-json/GenerateJsonPlugin.js.map +1 -0
  56. package/dist/cli/bundler/plugins/generate-json/index.d.ts +1 -0
  57. package/dist/cli/bundler/plugins/generate-json/index.js +5 -0
  58. package/dist/cli/bundler/plugins/generate-json/index.js.map +1 -0
  59. package/dist/cli/bundler/plugins/generate-module/GenerateModulePlugin.d.ts +23 -0
  60. package/dist/cli/bundler/plugins/generate-module/GenerateModulePlugin.js +88 -0
  61. package/dist/cli/bundler/plugins/generate-module/GenerateModulePlugin.js.map +1 -0
  62. package/dist/cli/bundler/plugins/generate-module/index.d.ts +1 -0
  63. package/dist/cli/bundler/plugins/generate-module/index.js +7 -0
  64. package/dist/cli/bundler/plugins/generate-module/index.js.map +1 -0
  65. package/dist/cli/bundler/plugins/index.d.ts +11 -5
  66. package/dist/cli/bundler/plugins/index.js +32 -10
  67. package/dist/cli/bundler/plugins/index.js.map +1 -1
  68. package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.d.ts +21 -0
  69. package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js +174 -0
  70. package/dist/cli/bundler/plugins/isolated-styles/IsolatedStylesPlugin.js.map +1 -0
  71. package/dist/cli/bundler/plugins/isolated-styles/index.d.ts +1 -0
  72. package/dist/cli/bundler/plugins/isolated-styles/index.js +5 -0
  73. package/dist/cli/bundler/plugins/isolated-styles/index.js.map +1 -0
  74. package/dist/cli/bundler/plugins/isolated-styles/templates/css-loader.template.d.ts +1 -0
  75. package/dist/cli/bundler/plugins/isolated-styles/templates/runtime.template.d.ts +7 -0
  76. package/dist/cli/bundler/plugins/isolated-styles/templates.d.ts +18 -0
  77. package/dist/cli/bundler/plugins/isolated-styles/templates.js +174 -0
  78. package/dist/cli/bundler/plugins/manifest/ManifestPlugin.d.ts +10 -0
  79. package/dist/cli/bundler/plugins/manifest/ManifestPlugin.js +55 -0
  80. package/dist/cli/bundler/plugins/manifest/ManifestPlugin.js.map +1 -0
  81. package/dist/cli/bundler/plugins/manifest/index.d.ts +1 -0
  82. package/dist/cli/bundler/plugins/manifest/index.js +6 -0
  83. package/dist/cli/bundler/plugins/manifest/index.js.map +1 -0
  84. package/dist/cli/bundler/plugins/replace/ReplacePlugin.js.map +1 -0
  85. package/dist/cli/bundler/plugins/replace/index.d.ts +1 -0
  86. package/dist/cli/bundler/plugins/replace/index.js +5 -0
  87. package/dist/cli/bundler/plugins/replace/index.js.map +1 -0
  88. package/dist/cli/bundler/plugins/resource-access/ResourceAccessPlugin.d.ts +19 -0
  89. package/dist/cli/bundler/plugins/resource-access/ResourceAccessPlugin.js +20 -0
  90. package/dist/cli/bundler/plugins/resource-access/ResourceAccessPlugin.js.map +1 -0
  91. package/dist/cli/bundler/plugins/resource-access/index.d.ts +1 -0
  92. package/dist/cli/bundler/plugins/resource-access/index.js +5 -0
  93. package/dist/cli/bundler/plugins/resource-access/index.js.map +1 -0
  94. package/dist/cli/bundler/plugins/resource-access/utils.d.ts +8 -0
  95. package/dist/cli/bundler/plugins/resource-access/utils.js +42 -0
  96. package/dist/cli/bundler/plugins/resource-access/utils.js.map +1 -0
  97. package/dist/cli/bundler/plugins/types.d.ts +4 -0
  98. package/dist/cli/bundler/plugins/types.js +1 -0
  99. package/dist/cli/bundler/plugins/types.js.map +1 -0
  100. package/dist/cli/bundler/plugins/utils/index.d.ts +3 -0
  101. package/dist/cli/bundler/plugins/utils/index.js +9 -0
  102. package/dist/cli/bundler/plugins/utils/index.js.map +1 -0
  103. package/dist/cli/bundler/plugins/utils/manifest-hooks.d.ts +13 -0
  104. package/dist/cli/bundler/plugins/utils/manifest-hooks.js +17 -0
  105. package/dist/cli/bundler/plugins/utils/manifest-hooks.js.map +1 -0
  106. package/dist/cli/bundler/plugins/utils/runtime-template.d.ts +1 -0
  107. package/dist/cli/bundler/plugins/utils/runtime-template.js +18 -0
  108. package/dist/cli/bundler/plugins/utils/runtime-template.js.map +1 -0
  109. package/dist/cli/bundler/plugins/utils/watch-compilation.d.ts +3 -0
  110. package/dist/cli/bundler/plugins/utils/watch-compilation.js +18 -0
  111. package/dist/cli/bundler/plugins/utils/watch-compilation.js.map +1 -0
  112. package/dist/cli/bundler/plugins/watch/WatchPlugin.js +16 -0
  113. package/dist/cli/bundler/plugins/watch/WatchPlugin.js.map +1 -0
  114. package/dist/cli/bundler/plugins/watch/index.d.ts +1 -0
  115. package/dist/cli/bundler/plugins/watch/index.js +5 -0
  116. package/dist/cli/bundler/plugins/watch/index.js.map +1 -0
  117. package/dist/cli/bundler/utils/chunk-filename.d.ts +6 -0
  118. package/dist/cli/bundler/utils/chunk-filename.js +93 -0
  119. package/dist/cli/bundler/utils/chunk-filename.js.map +1 -0
  120. package/dist/cli/bundler/utils/index.d.ts +2 -0
  121. package/dist/cli/bundler/utils/index.js +2 -0
  122. package/dist/cli/bundler/utils/index.js.map +1 -1
  123. package/dist/cli/bundler/utils/layers.d.ts +4 -0
  124. package/dist/cli/bundler/utils/layers.js +10 -0
  125. package/dist/cli/bundler/utils/layers.js.map +1 -0
  126. package/dist/cli/bundler/utils/output.d.ts +6 -2
  127. package/dist/cli/bundler/utils/output.js +165 -7
  128. package/dist/cli/bundler/utils/output.js.map +1 -1
  129. package/dist/cli/bundler/utils/styles.d.ts +5 -0
  130. package/dist/cli/bundler/utils/styles.js +30 -0
  131. package/dist/cli/bundler/utils/styles.js.map +1 -0
  132. package/dist/cli/entrypoint/file/ExpressionFile.d.ts +4 -1
  133. package/dist/cli/entrypoint/file/ExpressionFile.js +11 -0
  134. package/dist/cli/entrypoint/file/ExpressionFile.js.map +1 -1
  135. package/dist/cli/entrypoint/file/OptionFile.d.ts +4 -2
  136. package/dist/cli/entrypoint/file/OptionFile.js +35 -31
  137. package/dist/cli/entrypoint/file/OptionFile.js.map +1 -1
  138. package/dist/cli/entrypoint/file/SourceFile.d.ts +18 -7
  139. package/dist/cli/entrypoint/file/SourceFile.js +260 -156
  140. package/dist/cli/entrypoint/file/SourceFile.js.map +1 -1
  141. package/dist/cli/entrypoint/file/index.d.ts +2 -0
  142. package/dist/cli/entrypoint/file/index.js +2 -0
  143. package/dist/cli/entrypoint/file/index.js.map +1 -1
  144. package/dist/cli/entrypoint/file/injectors/core.js +22 -1
  145. package/dist/cli/entrypoint/file/injectors/core.js.map +1 -1
  146. package/dist/cli/entrypoint/file/parsers/ExportParser.d.ts +14 -0
  147. package/dist/cli/entrypoint/file/parsers/ExportParser.js +71 -0
  148. package/dist/cli/entrypoint/file/parsers/ExportParser.js.map +1 -0
  149. package/dist/cli/entrypoint/file/parsers/NodeFinder.d.ts +2 -0
  150. package/dist/cli/entrypoint/file/parsers/NodeFinder.js +9 -0
  151. package/dist/cli/entrypoint/file/parsers/NodeFinder.js.map +1 -1
  152. package/dist/cli/entrypoint/file/parsers/ObjectParser.js +5 -1
  153. package/dist/cli/entrypoint/file/parsers/ObjectParser.js.map +1 -1
  154. package/dist/cli/entrypoint/file/parsers/index.d.ts +1 -0
  155. package/dist/cli/entrypoint/file/parsers/index.js +2 -0
  156. package/dist/cli/entrypoint/file/parsers/index.js.map +1 -1
  157. package/dist/cli/entrypoint/file/parsers/types.d.ts +16 -0
  158. package/dist/cli/entrypoint/file/parsers/types.js +13 -0
  159. package/dist/cli/entrypoint/file/parsers/types.js.map +1 -1
  160. package/dist/cli/entrypoint/file/resolvers/ImportResolver.d.ts +1 -0
  161. package/dist/cli/entrypoint/file/resolvers/ImportResolver.js +3 -0
  162. package/dist/cli/entrypoint/file/resolvers/ImportResolver.js.map +1 -1
  163. package/dist/cli/entrypoint/file/types.d.ts +26 -1
  164. package/dist/cli/entrypoint/finder/AbstractEntrypointFinder.d.ts +2 -2
  165. package/dist/cli/entrypoint/finder/AbstractEntrypointFinder.js +2 -2
  166. package/dist/cli/entrypoint/finder/AbstractEntrypointFinder.js.map +1 -1
  167. package/dist/cli/entrypoint/finder/{AbstractOptionsFinder.js → AbstractParsedFinder.js} +3 -3
  168. package/dist/cli/entrypoint/finder/AbstractParsedFinder.js.map +1 -0
  169. package/dist/cli/entrypoint/finder/OptionsFinder.d.ts +13 -0
  170. package/dist/cli/entrypoint/finder/OptionsFinder.js +33 -0
  171. package/dist/cli/entrypoint/finder/OptionsFinder.js.map +1 -0
  172. package/dist/cli/entrypoint/finder/PluginFinder.d.ts +4 -4
  173. package/dist/cli/entrypoint/finder/PluginFinder.js +2 -2
  174. package/dist/cli/entrypoint/finder/PluginFinder.js.map +1 -1
  175. package/dist/cli/entrypoint/finder/index.d.ts +2 -1
  176. package/dist/cli/entrypoint/finder/index.js +20 -18
  177. package/dist/cli/entrypoint/finder/index.js.map +1 -1
  178. package/dist/cli/entrypoint/parser/AbstractParser.d.ts +3 -2
  179. package/dist/cli/entrypoint/parser/AbstractParser.js +6 -3
  180. package/dist/cli/entrypoint/parser/AbstractParser.js.map +1 -1
  181. package/dist/cli/entrypoint/parser/CommandParser.js +1 -1
  182. package/dist/cli/entrypoint/parser/CommandParser.js.map +1 -1
  183. package/dist/cli/entrypoint/parser/ContentParser.d.ts +5 -1
  184. package/dist/cli/entrypoint/parser/ContentParser.js +55 -3
  185. package/dist/cli/entrypoint/parser/ContentParser.js.map +1 -1
  186. package/dist/cli/entrypoint/parser/OptionsParser.d.ts +6 -0
  187. package/dist/cli/entrypoint/parser/OptionsParser.js +16 -0
  188. package/dist/cli/entrypoint/parser/OptionsParser.js.map +1 -0
  189. package/dist/cli/entrypoint/parser/RelayParser.d.ts +21 -2
  190. package/dist/cli/entrypoint/parser/RelayParser.js +4 -0
  191. package/dist/cli/entrypoint/parser/RelayParser.js.map +1 -1
  192. package/dist/cli/entrypoint/parser/index.d.ts +1 -0
  193. package/dist/cli/entrypoint/parser/index.js +16 -14
  194. package/dist/cli/entrypoint/parser/index.js.map +1 -1
  195. package/dist/cli/plugins/asset.js +9 -4
  196. package/dist/cli/plugins/asset.js.map +1 -1
  197. package/dist/cli/plugins/background/index.js +1 -1
  198. package/dist/cli/plugins/background/index.js.map +1 -1
  199. package/dist/cli/plugins/content/Content.d.ts +1 -1
  200. package/dist/cli/plugins/content/Content.js +3 -2
  201. package/dist/cli/plugins/content/Content.js.map +1 -1
  202. package/dist/cli/plugins/content/ContentManager.d.ts +8 -5
  203. package/dist/cli/plugins/content/ContentManager.js +79 -28
  204. package/dist/cli/plugins/content/ContentManager.js.map +1 -1
  205. package/dist/cli/plugins/content/ContentName.d.ts +1 -1
  206. package/dist/cli/plugins/content/ContentName.js +8 -7
  207. package/dist/cli/plugins/content/ContentName.js.map +1 -1
  208. package/dist/cli/plugins/content/Relay.d.ts +1 -1
  209. package/dist/cli/plugins/content/Relay.js +3 -2
  210. package/dist/cli/plugins/content/Relay.js.map +1 -1
  211. package/dist/cli/plugins/content/bundler.d.ts +7 -0
  212. package/dist/cli/plugins/content/bundler.js +47 -0
  213. package/dist/cli/plugins/content/bundler.js.map +1 -0
  214. package/dist/cli/plugins/content/index.js +121 -62
  215. package/dist/cli/plugins/content/index.js.map +1 -1
  216. package/dist/cli/plugins/content/relay-module.d.ts +3 -0
  217. package/dist/cli/plugins/content/relay-module.js +11 -0
  218. package/dist/cli/plugins/content/relay-module.js.map +1 -0
  219. package/dist/cli/plugins/content/types.d.ts +1 -1
  220. package/dist/cli/plugins/content/utils.d.ts +2 -0
  221. package/dist/cli/plugins/content/utils.js +8 -1
  222. package/dist/cli/plugins/content/utils.js.map +1 -1
  223. package/dist/cli/plugins/icon/declaration/IconDeclaration.d.ts +1 -1
  224. package/dist/cli/plugins/icon/declaration/IconDeclaration.js +6 -6
  225. package/dist/cli/plugins/icon/declaration/IconDeclaration.js.map +1 -1
  226. package/dist/cli/plugins/icon/declaration/icon.d.ts +3 -5
  227. package/dist/cli/plugins/icon/icon-module.d.ts +2 -0
  228. package/dist/cli/plugins/icon/icon-module.js +11 -0
  229. package/dist/cli/plugins/icon/icon-module.js.map +1 -0
  230. package/dist/cli/plugins/icon/index.js +5 -3
  231. package/dist/cli/plugins/icon/index.js.map +1 -1
  232. package/dist/cli/plugins/index.d.ts +1 -0
  233. package/dist/cli/plugins/index.js +22 -20
  234. package/dist/cli/plugins/index.js.map +1 -1
  235. package/dist/cli/plugins/locale/Locale.d.ts +9 -2
  236. package/dist/cli/plugins/locale/Locale.js +37 -5
  237. package/dist/cli/plugins/locale/Locale.js.map +1 -1
  238. package/dist/cli/plugins/locale/declaration/locale.d.ts +1 -1
  239. package/dist/cli/plugins/locale/index.js +57 -22
  240. package/dist/cli/plugins/locale/index.js.map +1 -1
  241. package/dist/cli/plugins/locale/locale-module.d.ts +4 -0
  242. package/dist/cli/plugins/locale/locale-module.js +16 -0
  243. package/dist/cli/plugins/locale/locale-module.js.map +1 -0
  244. package/dist/cli/plugins/offscreen/Offscreen.d.ts +2 -3
  245. package/dist/cli/plugins/offscreen/Offscreen.js.map +1 -1
  246. package/dist/cli/plugins/offscreen/index.js +5 -4
  247. package/dist/cli/plugins/offscreen/index.js.map +1 -1
  248. package/dist/cli/plugins/offscreen/offscreen-module.d.ts +3 -0
  249. package/dist/cli/plugins/offscreen/offscreen-module.js +11 -0
  250. package/dist/cli/plugins/offscreen/offscreen-module.js.map +1 -0
  251. package/dist/cli/plugins/options/Options.d.ts +10 -0
  252. package/dist/cli/plugins/options/Options.js +24 -0
  253. package/dist/cli/plugins/options/Options.js.map +1 -0
  254. package/dist/cli/plugins/options/index.d.ts +2 -0
  255. package/dist/cli/plugins/options/index.js +41 -0
  256. package/dist/cli/plugins/options/index.js.map +1 -0
  257. package/dist/cli/plugins/output.js +33 -3
  258. package/dist/cli/plugins/output.js.map +1 -1
  259. package/dist/cli/plugins/page/declaration/PageDeclaration.js +4 -4
  260. package/dist/cli/plugins/page/declaration/PageDeclaration.js.map +1 -1
  261. package/dist/cli/plugins/page/declaration/page.d.ts +3 -3
  262. package/dist/cli/plugins/page/index.js +14 -10
  263. package/dist/cli/plugins/page/index.js.map +1 -1
  264. package/dist/cli/plugins/page/page-module.d.ts +2 -0
  265. package/dist/cli/plugins/page/page-module.js +11 -0
  266. package/dist/cli/plugins/page/page-module.js.map +1 -0
  267. package/dist/cli/plugins/popup/Popup.d.ts +1 -1
  268. package/dist/cli/plugins/popup/Popup.js +2 -2
  269. package/dist/cli/plugins/popup/Popup.js.map +1 -1
  270. package/dist/cli/plugins/popup/declaration/PopupDeclaration.d.ts +1 -1
  271. package/dist/cli/plugins/popup/declaration/PopupDeclaration.js +6 -6
  272. package/dist/cli/plugins/popup/declaration/PopupDeclaration.js.map +1 -1
  273. package/dist/cli/plugins/popup/declaration/popup.d.ts +3 -3
  274. package/dist/cli/plugins/popup/index.js +6 -5
  275. package/dist/cli/plugins/popup/index.js.map +1 -1
  276. package/dist/cli/plugins/popup/popup-module.d.ts +3 -0
  277. package/dist/cli/plugins/popup/popup-module.js +11 -0
  278. package/dist/cli/plugins/popup/popup-module.js.map +1 -0
  279. package/dist/cli/plugins/sandbox/Sandbox.d.ts +1 -2
  280. package/dist/cli/plugins/sandbox/Sandbox.js.map +1 -1
  281. package/dist/cli/plugins/sandbox/index.js +5 -4
  282. package/dist/cli/plugins/sandbox/index.js.map +1 -1
  283. package/dist/cli/plugins/sandbox/sandbox-module.d.ts +3 -0
  284. package/dist/cli/plugins/sandbox/sandbox-module.js +11 -0
  285. package/dist/cli/plugins/sandbox/sandbox-module.js.map +1 -0
  286. package/dist/cli/plugins/sidebar/Sidebar.d.ts +1 -1
  287. package/dist/cli/plugins/sidebar/Sidebar.js +2 -2
  288. package/dist/cli/plugins/sidebar/Sidebar.js.map +1 -1
  289. package/dist/cli/plugins/sidebar/declaration/SidebarDeclaration.d.ts +1 -1
  290. package/dist/cli/plugins/sidebar/declaration/SidebarDeclaration.js +6 -6
  291. package/dist/cli/plugins/sidebar/declaration/SidebarDeclaration.js.map +1 -1
  292. package/dist/cli/plugins/sidebar/declaration/sidebar.d.ts +3 -3
  293. package/dist/cli/plugins/sidebar/index.js +6 -5
  294. package/dist/cli/plugins/sidebar/index.js.map +1 -1
  295. package/dist/cli/plugins/sidebar/sidebar-module.d.ts +3 -0
  296. package/dist/cli/plugins/sidebar/sidebar-module.js +11 -0
  297. package/dist/cli/plugins/sidebar/sidebar-module.js.map +1 -0
  298. package/dist/cli/plugins/style/index.d.ts +2 -1
  299. package/dist/cli/plugins/style/index.js +52 -25
  300. package/dist/cli/plugins/style/index.js.map +1 -1
  301. package/dist/cli/plugins/style/types.d.ts +5 -0
  302. package/dist/cli/plugins/style/types.js +1 -0
  303. package/dist/cli/plugins/style/types.js.map +1 -0
  304. package/dist/cli/plugins/view/index.js +1 -1
  305. package/dist/cli/plugins/view/index.js.map +1 -1
  306. package/dist/cli/raw.d.ts +4 -0
  307. package/dist/cli/resolvers/bundler.js +9 -7
  308. package/dist/cli/resolvers/bundler.js.map +1 -1
  309. package/dist/cli/resolvers/config.js +4 -1
  310. package/dist/cli/resolvers/config.js.map +1 -1
  311. package/dist/cli/virtual/index.d.ts +2 -2
  312. package/dist/cli/virtual/index.js +11 -8
  313. package/dist/cli/virtual/virtual.d.ts +8 -10
  314. package/dist/entry/content/adapters/react/Builder.js +1 -1
  315. package/dist/entry/content/adapters/react/Builder.js.map +1 -1
  316. package/dist/entry/content/adapters/react/Node.d.ts +2 -0
  317. package/dist/entry/content/adapters/react/Node.js +10 -2
  318. package/dist/entry/content/adapters/react/Node.js.map +1 -1
  319. package/dist/entry/content/adapters/vanilla/Builder.js +1 -1
  320. package/dist/entry/content/adapters/vanilla/Builder.js.map +1 -1
  321. package/dist/entry/content/adapters/vanilla/Node.d.ts +2 -1
  322. package/dist/entry/content/adapters/vanilla/Node.js +10 -7
  323. package/dist/entry/content/adapters/vanilla/Node.js.map +1 -1
  324. package/dist/entry/content/core/Builder.d.ts +1 -2
  325. package/dist/entry/content/core/Builder.js +9 -5
  326. package/dist/entry/content/core/Builder.js.map +1 -1
  327. package/dist/entry/content/core/MountBuilder.js +14 -6
  328. package/dist/entry/content/core/MountBuilder.js.map +1 -1
  329. package/dist/entry/content/core/{Context.d.ts → context/Context.d.ts} +2 -1
  330. package/dist/entry/content/core/{Context.js → context/Context.js} +7 -0
  331. package/dist/entry/content/core/context/Context.js.map +1 -0
  332. package/dist/entry/content/core/{EventEmitter.d.ts → context/EventEmitter.d.ts} +1 -1
  333. package/dist/entry/content/core/{EventEmitter.js → context/EventEmitter.js} +1 -1
  334. package/dist/entry/content/core/context/EventEmitter.js.map +1 -0
  335. package/dist/entry/content/core/{ManagedContext.d.ts → context/ManagedContext.d.ts} +1 -1
  336. package/dist/entry/content/core/context/ManagedContext.js.map +1 -0
  337. package/dist/entry/content/core/context/index.d.ts +3 -0
  338. package/dist/entry/content/core/context/index.js +9 -0
  339. package/dist/entry/content/core/context/index.js.map +1 -0
  340. package/dist/entry/content/core/{AbstractMarker.d.ts → markers/AbstractMarker.d.ts} +1 -1
  341. package/dist/entry/content/core/{AbstractMarker.js → markers/AbstractMarker.js} +1 -1
  342. package/dist/entry/content/core/markers/AbstractMarker.js.map +1 -0
  343. package/dist/entry/content/core/{AttributeMarker.d.ts → markers/AttributeMarker.d.ts} +1 -1
  344. package/dist/entry/content/core/markers/AttributeMarker.js.map +1 -0
  345. package/dist/entry/content/core/{WeakMarker.d.ts → markers/WeakMarker.d.ts} +1 -1
  346. package/dist/entry/content/core/markers/WeakMarker.js.map +1 -0
  347. package/dist/entry/content/core/markers/index.d.ts +3 -0
  348. package/dist/entry/content/core/markers/index.js +9 -0
  349. package/dist/entry/content/core/markers/index.js.map +1 -0
  350. package/dist/entry/content/core/{EventNode.d.ts → nodes/EventNode.d.ts} +2 -1
  351. package/dist/entry/content/core/{EventNode.js → nodes/EventNode.js} +3 -0
  352. package/dist/entry/content/core/nodes/EventNode.js.map +1 -0
  353. package/dist/entry/content/core/nodes/FrameNode.d.ts +23 -0
  354. package/dist/entry/content/core/nodes/FrameNode.js +125 -0
  355. package/dist/entry/content/core/nodes/FrameNode.js.map +1 -0
  356. package/dist/entry/content/core/{MarkerNode.d.ts → nodes/MarkerNode.d.ts} +2 -1
  357. package/dist/entry/content/core/{MarkerNode.js → nodes/MarkerNode.js} +3 -0
  358. package/dist/entry/content/core/nodes/MarkerNode.js.map +1 -0
  359. package/dist/entry/content/core/{MountNode.d.ts → nodes/MountNode.d.ts} +2 -1
  360. package/dist/entry/content/core/{MountNode.js → nodes/MountNode.js} +3 -0
  361. package/dist/entry/content/core/nodes/MountNode.js.map +1 -0
  362. package/dist/entry/content/core/{Node.d.ts → nodes/Node.d.ts} +2 -1
  363. package/dist/entry/content/core/{Node.js → nodes/Node.js} +3 -0
  364. package/dist/entry/content/core/nodes/Node.js.map +1 -0
  365. package/dist/entry/content/core/nodes/ShadowNode.d.ts +14 -0
  366. package/dist/entry/content/core/nodes/ShadowNode.js +67 -0
  367. package/dist/entry/content/core/nodes/ShadowNode.js.map +1 -0
  368. package/dist/entry/content/core/nodes/index.d.ts +6 -0
  369. package/dist/entry/content/core/nodes/index.js +15 -0
  370. package/dist/entry/content/core/nodes/index.js.map +1 -0
  371. package/dist/entry/content/core/nodes/isolated-styles.d.ts +2 -0
  372. package/dist/entry/content/core/nodes/isolated-styles.js +14 -0
  373. package/dist/entry/content/core/nodes/isolated-styles.js.map +1 -0
  374. package/dist/entry/content/core/resolvers/watch.js +1 -1
  375. package/dist/entry/content/core/resolvers/watch.js.map +1 -1
  376. package/dist/entry/content/frame/Builder.d.ts +7 -0
  377. package/dist/entry/content/frame/Builder.js +14 -0
  378. package/dist/entry/content/frame/Builder.js.map +1 -0
  379. package/dist/entry/content/frame/index.d.ts +4 -0
  380. package/dist/entry/content/frame/index.js +7 -0
  381. package/dist/entry/content/frame/index.js.map +1 -0
  382. package/dist/entry/relay/Builder.js +5 -1
  383. package/dist/entry/relay/Builder.js.map +1 -1
  384. package/dist/entry/relay/index.d.ts +1 -1
  385. package/dist/locale/adapters/react/ReactLocale.d.ts +18 -0
  386. package/dist/locale/adapters/react/ReactLocale.js +41 -0
  387. package/dist/locale/adapters/react/ReactLocale.js.map +1 -0
  388. package/dist/locale/adapters/react/hooks/use-locale-attributes.d.ts +7 -0
  389. package/dist/locale/adapters/react/hooks/use-locale-attributes.js +30 -0
  390. package/dist/locale/adapters/react/hooks/use-locale-attributes.js.map +1 -0
  391. package/dist/locale/adapters/react/hooks/use-locale.d.ts +3 -0
  392. package/dist/locale/adapters/react/hooks/use-locale.js +17 -0
  393. package/dist/locale/adapters/react/hooks/use-locale.js.map +1 -0
  394. package/dist/locale/adapters/react/hooks/use-native-locale.d.ts +3 -0
  395. package/dist/locale/adapters/react/hooks/use-native-locale.js +10 -0
  396. package/dist/locale/adapters/react/hooks/use-native-locale.js.map +1 -0
  397. package/dist/locale/adapters/react/index.d.ts +4 -2
  398. package/dist/locale/adapters/react/index.js +6 -4
  399. package/dist/locale/adapters/react/index.js.map +1 -1
  400. package/dist/locale/adapters/react/types.d.ts +22 -0
  401. package/dist/locale/adapters/react/types.js +1 -0
  402. package/dist/locale/adapters/react/types.js.map +1 -0
  403. package/dist/locale/helpers.d.ts +4 -5
  404. package/dist/locale/helpers.js +1 -1
  405. package/dist/locale/helpers.js.map +1 -1
  406. package/dist/locale/index.d.ts +2 -1
  407. package/dist/locale/index.js +1 -0
  408. package/dist/locale/index.js.map +1 -1
  409. package/dist/locale/providers/AbstractLocale.d.ts +4 -4
  410. package/dist/locale/providers/AbstractLocale.js +13 -94
  411. package/dist/locale/providers/AbstractLocale.js.map +1 -1
  412. package/dist/locale/providers/CustomLocale.d.ts +3 -3
  413. package/dist/locale/providers/CustomLocale.js +6 -5
  414. package/dist/locale/providers/CustomLocale.js.map +1 -1
  415. package/dist/locale/providers/DynamicLocale.d.ts +18 -11
  416. package/dist/locale/providers/DynamicLocale.js +60 -47
  417. package/dist/locale/providers/DynamicLocale.js.map +1 -1
  418. package/dist/locale/providers/NativeLocale.d.ts +4 -7
  419. package/dist/locale/providers/NativeLocale.js +5 -14
  420. package/dist/locale/providers/NativeLocale.js.map +1 -1
  421. package/dist/locale/providers/ObservableLocale.d.ts +35 -0
  422. package/dist/locale/providers/ObservableLocale.js +179 -0
  423. package/dist/locale/providers/ObservableLocale.js.map +1 -0
  424. package/dist/locale/providers/index.d.ts +2 -1
  425. package/dist/locale/providers/index.js +3 -1
  426. package/dist/locale/providers/index.js.map +1 -1
  427. package/dist/locale/storage/LocaleStorage.d.ts +11 -0
  428. package/dist/locale/storage/LocaleStorage.js +40 -0
  429. package/dist/locale/storage/LocaleStorage.js.map +1 -0
  430. package/dist/locale/storage/index.d.ts +1 -0
  431. package/dist/locale/storage/index.js +5 -0
  432. package/dist/locale/storage/index.js.map +1 -0
  433. package/dist/main/entrypoint.d.ts +4 -0
  434. package/dist/main/entrypoint.js +20 -0
  435. package/dist/main/entrypoint.js.map +1 -0
  436. package/dist/main/icon.d.ts +2 -3
  437. package/dist/main/icon.js +2 -1
  438. package/dist/main/icon.js.map +1 -1
  439. package/dist/main/index.d.ts +2 -0
  440. package/dist/main/index.js +2 -0
  441. package/dist/main/index.js.map +1 -1
  442. package/dist/main/offscreen.d.ts +2 -5
  443. package/dist/main/offscreen.js +5 -2
  444. package/dist/main/offscreen.js.map +1 -1
  445. package/dist/main/options.d.ts +3 -0
  446. package/dist/main/options.js +7 -0
  447. package/dist/main/options.js.map +1 -0
  448. package/dist/main/page.d.ts +2 -4
  449. package/dist/main/page.js +2 -1
  450. package/dist/main/page.js.map +1 -1
  451. package/dist/main/popup.d.ts +2 -5
  452. package/dist/main/popup.js +3 -3
  453. package/dist/main/popup.js.map +1 -1
  454. package/dist/main/relay.d.ts +1 -2
  455. package/dist/main/relay.js +2 -1
  456. package/dist/main/relay.js.map +1 -1
  457. package/dist/main/sandbox.d.ts +1 -4
  458. package/dist/main/sandbox.js +2 -1
  459. package/dist/main/sandbox.js.map +1 -1
  460. package/dist/main/service.d.ts +1 -2
  461. package/dist/main/service.js.map +1 -1
  462. package/dist/main/sidebar.d.ts +2 -5
  463. package/dist/main/sidebar.js +3 -3
  464. package/dist/main/sidebar.js.map +1 -1
  465. package/dist/message/index.d.ts +2 -4
  466. package/dist/message/index.js.map +1 -1
  467. package/dist/offscreen/index.d.ts +2 -6
  468. package/dist/offscreen/index.js.map +1 -1
  469. package/dist/relay/index.d.ts +2 -5
  470. package/dist/relay/index.js.map +1 -1
  471. package/dist/sandbox/index.d.ts +1 -5
  472. package/dist/sandbox/index.js.map +1 -1
  473. package/dist/service/index.d.ts +2 -6
  474. package/dist/service/index.js.map +1 -1
  475. package/dist/shared/content/index.d.ts +1 -0
  476. package/dist/shared/content/index.js +6 -0
  477. package/dist/shared/content/index.js.map +1 -0
  478. package/dist/shared/content/isolation.d.ts +4 -0
  479. package/dist/shared/content/isolation.js +70 -0
  480. package/dist/shared/content/isolation.js.map +1 -0
  481. package/dist/shared/locale/index.d.ts +5 -0
  482. package/dist/shared/locale/index.js +21 -0
  483. package/dist/shared/locale/index.js.map +1 -0
  484. package/dist/shared/locale/keys.d.ts +5 -0
  485. package/dist/shared/locale/keys.js +33 -0
  486. package/dist/shared/locale/keys.js.map +1 -0
  487. package/dist/shared/locale/language.d.ts +4 -0
  488. package/dist/shared/locale/language.js +23 -0
  489. package/dist/shared/locale/language.js.map +1 -0
  490. package/dist/shared/locale/messages.d.ts +3 -0
  491. package/dist/shared/locale/messages.js +9 -0
  492. package/dist/shared/locale/messages.js.map +1 -0
  493. package/dist/shared/locale/plural.d.ts +2 -0
  494. package/dist/shared/locale/plural.js +81 -0
  495. package/dist/shared/locale/plural.js.map +1 -0
  496. package/dist/shared/locale/substitutions.d.ts +10 -0
  497. package/dist/shared/locale/substitutions.js +32 -0
  498. package/dist/shared/locale/substitutions.js.map +1 -0
  499. package/dist/types/background.d.ts +1 -1
  500. package/dist/types/background.js.map +1 -1
  501. package/dist/types/command.d.ts +1 -1
  502. package/dist/types/command.js.map +1 -1
  503. package/dist/types/content.d.ts +120 -31
  504. package/dist/types/content.js +22 -1
  505. package/dist/types/content.js.map +1 -1
  506. package/dist/types/entrypoint.d.ts +20 -0
  507. package/dist/types/entrypoint.js +4 -0
  508. package/dist/types/entrypoint.js.map +1 -1
  509. package/dist/types/icon.d.ts +8 -0
  510. package/dist/types/icon.js.map +1 -1
  511. package/dist/types/language.d.ts +57 -0
  512. package/dist/types/language.js +62 -0
  513. package/dist/types/language.js.map +1 -0
  514. package/dist/types/locale.d.ts +34 -63
  515. package/dist/types/locale.js +62 -119
  516. package/dist/types/locale.js.map +1 -1
  517. package/dist/types/manifest.d.ts +24 -7
  518. package/dist/types/manifest.js.map +1 -1
  519. package/dist/types/message.d.ts +7 -0
  520. package/dist/types/message.js.map +1 -1
  521. package/dist/types/offscreen.d.ts +14 -1
  522. package/dist/types/offscreen.js.map +1 -1
  523. package/dist/types/options.d.ts +9 -0
  524. package/dist/types/options.js +1 -0
  525. package/dist/types/options.js.map +1 -0
  526. package/dist/types/page.d.ts +8 -0
  527. package/dist/types/plugin.d.ts +2 -1
  528. package/dist/types/popup.d.ts +9 -0
  529. package/dist/types/relay.d.ts +16 -7
  530. package/dist/types/relay.js.map +1 -1
  531. package/dist/types/sandbox.d.ts +12 -0
  532. package/dist/types/sandbox.js.map +1 -1
  533. package/dist/types/service.d.ts +10 -1
  534. package/dist/types/service.js.map +1 -1
  535. package/dist/types/sidebar.d.ts +9 -0
  536. package/dist/types/sidebar.js.map +1 -1
  537. package/dist/types/transport.d.ts +4 -0
  538. package/dist/virtual/entrypoint.d.ts +5 -0
  539. package/dist/virtual/entrypoint.js +7 -0
  540. package/dist/virtual/entrypoint.js.map +1 -0
  541. package/dist/virtual/icon.d.ts +2 -0
  542. package/dist/virtual/icon.js +5 -0
  543. package/dist/virtual/icon.js.map +1 -0
  544. package/dist/virtual/locale.d.ts +7 -0
  545. package/dist/virtual/locale.js +13 -0
  546. package/dist/virtual/locale.js.map +1 -0
  547. package/dist/virtual/modules.d.ts +40 -0
  548. package/dist/virtual/offscreen.d.ts +3 -0
  549. package/dist/virtual/offscreen.js +5 -0
  550. package/dist/virtual/offscreen.js.map +1 -0
  551. package/dist/virtual/page.d.ts +2 -0
  552. package/dist/virtual/page.js +5 -0
  553. package/dist/virtual/page.js.map +1 -0
  554. package/dist/virtual/popup.d.ts +3 -0
  555. package/dist/virtual/popup.js +5 -0
  556. package/dist/virtual/popup.js.map +1 -0
  557. package/dist/virtual/relay.d.ts +3 -0
  558. package/dist/virtual/relay.js +5 -0
  559. package/dist/virtual/relay.js.map +1 -0
  560. package/dist/virtual/sandbox.d.ts +3 -0
  561. package/dist/virtual/sandbox.js +5 -0
  562. package/dist/virtual/sandbox.js.map +1 -0
  563. package/dist/virtual/sidebar.d.ts +3 -0
  564. package/dist/virtual/sidebar.js +5 -0
  565. package/dist/virtual/sidebar.js.map +1 -0
  566. package/package.json +31 -10
  567. package/scripts/clean-dist.js +7 -0
  568. package/scripts/copy-dts.js +11 -1
  569. package/types/client.d.ts +15 -0
  570. package/dist/cli/builders/manifest/utils.d.ts +0 -32
  571. package/dist/cli/builders/manifest/utils.js +0 -209
  572. package/dist/cli/builders/manifest/utils.js.map +0 -1
  573. package/dist/cli/bundler/plugins/EntrypointPlugin.js.map +0 -1
  574. package/dist/cli/bundler/plugins/GenerateJsonPlugin.js +0 -40
  575. package/dist/cli/bundler/plugins/GenerateJsonPlugin.js.map +0 -1
  576. package/dist/cli/bundler/plugins/ManifestPlugin.d.ts +0 -10
  577. package/dist/cli/bundler/plugins/ManifestPlugin.js +0 -78
  578. package/dist/cli/bundler/plugins/ManifestPlugin.js.map +0 -1
  579. package/dist/cli/bundler/plugins/ReplacePlugin.js.map +0 -1
  580. package/dist/cli/bundler/plugins/WatchPlugin.js +0 -21
  581. package/dist/cli/bundler/plugins/WatchPlugin.js.map +0 -1
  582. package/dist/cli/entrypoint/finder/AbstractOptionsFinder.js.map +0 -1
  583. package/dist/entry/content/core/AbstractMarker.js.map +0 -1
  584. package/dist/entry/content/core/AttributeMarker.js.map +0 -1
  585. package/dist/entry/content/core/Context.js.map +0 -1
  586. package/dist/entry/content/core/EventEmitter.js.map +0 -1
  587. package/dist/entry/content/core/EventNode.js.map +0 -1
  588. package/dist/entry/content/core/ManagedContext.js.map +0 -1
  589. package/dist/entry/content/core/MarkerNode.js.map +0 -1
  590. package/dist/entry/content/core/MountNode.js.map +0 -1
  591. package/dist/entry/content/core/Node.js.map +0 -1
  592. package/dist/entry/content/core/WeakMarker.js.map +0 -1
  593. package/dist/locale/adapters/react/LocaleProvider.d.ts +0 -7
  594. package/dist/locale/adapters/react/LocaleProvider.js +0 -58
  595. package/dist/locale/adapters/react/LocaleProvider.js.map +0 -1
  596. package/dist/locale/adapters/react/context.d.ts +0 -14
  597. package/dist/locale/adapters/react/context.js +0 -25
  598. package/dist/locale/adapters/react/context.js.map +0 -1
  599. package/dist/locale/utils.d.ts +0 -11
  600. package/dist/locale/utils.js +0 -67
  601. package/dist/locale/utils.js.map +0 -1
  602. /package/dist/cli/bundler/plugins/{ReplacePlugin.d.ts → replace/ReplacePlugin.d.ts} +0 -0
  603. /package/dist/cli/bundler/plugins/{ReplacePlugin.js → replace/ReplacePlugin.js} +0 -0
  604. /package/dist/cli/bundler/plugins/{WatchPlugin.d.ts → watch/WatchPlugin.d.ts} +0 -0
  605. /package/dist/cli/entrypoint/finder/{AbstractOptionsFinder.d.ts → AbstractParsedFinder.d.ts} +0 -0
  606. /package/dist/entry/content/core/{ManagedContext.js → context/ManagedContext.js} +0 -0
  607. /package/dist/entry/content/core/{AttributeMarker.js → markers/AttributeMarker.js} +0 -0
  608. /package/dist/entry/content/core/{WeakMarker.js → markers/WeakMarker.js} +0 -0
@@ -1,5 +1,4 @@
1
- import { LocaleNativeStructure } from "./providers/index.js";
2
- import { LocaleNonPluralKeys, LocalePluralKeys, LocaleSubstitutionArgs } from "../types/locale.js";
1
+ import type { LocaleNonPluralKeys, LocalePluralKeys, LocaleRegistry, LocaleSubstitutionArgs } from "../types/locale.js";
3
2
  /**
4
3
  * Translates a non-plural locale key.
5
4
  *
@@ -17,7 +16,7 @@ import { LocaleNonPluralKeys, LocalePluralKeys, LocaleSubstitutionArgs } from ".
17
16
  * @param args
18
17
  * @returns The translated string.
19
18
  */
20
- export declare const t: <K extends LocaleNonPluralKeys<LocaleNativeStructure>>(key: K, ...args: LocaleSubstitutionArgs<LocaleNativeStructure, K>) => string;
19
+ export declare const t: <K extends LocaleNonPluralKeys<LocaleRegistry>>(key: K, ...args: LocaleSubstitutionArgs<LocaleRegistry, K>) => string;
21
20
  /**
22
21
  * Translates a plural locale key using the provided count.
23
22
  *
@@ -35,7 +34,7 @@ export declare const t: <K extends LocaleNonPluralKeys<LocaleNativeStructure>>(k
35
34
  * @param args
36
35
  * @returns The translated string.
37
36
  */
38
- export declare const choice: <K extends LocalePluralKeys<LocaleNativeStructure>>(key: K, count: number, ...args: LocaleSubstitutionArgs<LocaleNativeStructure, K>) => string;
37
+ export declare const choice: <K extends LocalePluralKeys<LocaleRegistry>>(key: K, count: number, ...args: LocaleSubstitutionArgs<LocaleRegistry, K>) => string;
39
38
  /**
40
39
  * Converts a locale key to a browser message reference.
41
40
  *
@@ -52,7 +51,7 @@ export declare const choice: <K extends LocalePluralKeys<LocaleNativeStructure>>
52
51
  * @param value - The locale key to convert.
53
52
  * @returns The browser message reference.
54
53
  */
55
- export declare const key: (value: keyof LocaleNativeStructure & string) => string;
54
+ export declare const key: (value: keyof LocaleRegistry & string) => string;
56
55
  /**
57
56
  * Resolves a string that may contain a locale marker.
58
57
  *
@@ -1,5 +1,5 @@
1
1
  import { NativeLocale } from "./../locale/providers/index.js";
2
- import { convertLocaleMessageKey, extractLocaleKey } from "./../locale/utils.js";
2
+ import { convertLocaleMessageKey, extractLocaleKey } from "./../shared/locale/index.js";
3
3
  const t = (key2, ...args) => {
4
4
  return NativeLocale.getInstance().trans(key2, ...args);
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/locale/helpers.ts"],"sourcesContent":["import {LocaleNativeStructure, NativeLocale} from \"@locale/providers\";\nimport {convertLocaleMessageKey, extractLocaleKey} from \"@locale/utils\";\nimport {LocaleNonPluralKeys, LocalePluralKeys, LocaleSubstitutionArgs} from \"@typing/locale\";\n\n/**\n * Translates a non-plural locale key.\n *\n * Substitutions are type-checked from the generated locale structure:\n * keys without placeholders do not accept substitutions, while keys with\n * placeholders require all declared substitution values.\n *\n * @example\n * ```ts\n * t(\"app.name\");\n * t(\"app.greeting\", {name: \"Alice\"});\n * ```\n *\n * @param key - The locale key to translate.\n * @param args\n * @returns The translated string.\n */\nexport const t = <K extends LocaleNonPluralKeys<LocaleNativeStructure>>(\n key: K,\n ...args: LocaleSubstitutionArgs<LocaleNativeStructure, K>\n): string => {\n return NativeLocale.getInstance().trans(key, ...args);\n};\n\n/**\n * Translates a plural locale key using the provided count.\n *\n * Substitutions are type-checked from the generated locale structure:\n * keys without placeholders do not accept substitutions, while keys with\n * placeholders require all declared substitution values.\n *\n * @example\n * ```ts\n * choice(\"cart.items\", count, {count});\n * ```\n *\n * @param key - The locale key to translate.\n * @param count - The count used to select the plural form.\n * @param args\n * @returns The translated string.\n */\nexport const choice = <K extends LocalePluralKeys<LocaleNativeStructure>>(\n key: K,\n count: number,\n ...args: LocaleSubstitutionArgs<LocaleNativeStructure, K>\n): string => {\n return NativeLocale.getInstance().choice(key, count, ...args);\n};\n\n/**\n * Converts a locale key to a browser message reference.\n *\n * This is useful for browser-managed extension fields that expect\n * `__MSG_name__` references instead of already translated text.\n *\n * A warning is logged when the key does not exist in the generated locale keys.\n *\n * @example\n * ```ts\n * key(\"app.name\"); // \"__MSG_app_name__\"\n * ```\n *\n * @param value - The locale key to convert.\n * @returns The browser message reference.\n */\nexport const key = (value: keyof LocaleNativeStructure & string): string => {\n const locale = NativeLocale.getInstance();\n\n if (!locale.keys().has(value)) {\n console.warn(`Locale key \"${value}\" not found in \"${locale.lang()}\" language.`);\n }\n\n return convertLocaleMessageKey(value);\n};\n\n/**\n * Resolves a string that may contain a locale marker.\n *\n * When the input contains a locale marker, the marker is extracted and translated.\n * Plain strings are returned unchanged.\n *\n * @example\n * ```ts\n * resolve(\"@app.name\");\n * resolve(\"Plain title\");\n * ```\n *\n * @param input - A plain string or a marked locale key string.\n * @returns The translated text when a marker is found, otherwise the original input.\n */\nexport const resolve = (input: string): string => {\n const localeKey = extractLocaleKey(input);\n\n if (localeKey) {\n // Markers are runtime strings without substitutions; keep t() strict for typed callers.\n return (t as (key: string) => string)(localeKey);\n }\n\n return input;\n};\n"],"mappings":"AAAA,SAA+B,oBAAmB;AAClD,SAAQ,yBAAyB,wBAAuB;AAoBjD,MAAM,IAAI,CACbA,SACG,SACM;AACT,SAAO,aAAa,YAAY,EAAE,MAAMA,MAAK,GAAG,IAAI;AACxD;AAmBO,MAAM,SAAS,CAClBA,MACA,UACG,SACM;AACT,SAAO,aAAa,YAAY,EAAE,OAAOA,MAAK,OAAO,GAAG,IAAI;AAChE;AAkBO,MAAM,MAAM,CAAC,UAAwD;AACxE,QAAM,SAAS,aAAa,YAAY;AAExC,MAAI,CAAC,OAAO,KAAK,EAAE,IAAI,KAAK,GAAG;AAC3B,YAAQ,KAAK,eAAe,KAAK,mBAAmB,OAAO,KAAK,CAAC,aAAa;AAAA,EAClF;AAEA,SAAO,wBAAwB,KAAK;AACxC;AAiBO,MAAM,UAAU,CAAC,UAA0B;AAC9C,QAAM,YAAY,iBAAiB,KAAK;AAExC,MAAI,WAAW;AAEX,WAAQ,EAA8B,SAAS;AAAA,EACnD;AAEA,SAAO;AACX;","names":["key"]}
1
+ {"version":3,"sources":["../../src/locale/helpers.ts"],"sourcesContent":["import {NativeLocale} from \"@locale/providers\";\nimport {convertLocaleMessageKey, extractLocaleKey} from \"@shared/locale\";\nimport type {LocaleNonPluralKeys, LocalePluralKeys, LocaleRegistry, LocaleSubstitutionArgs} from \"@typing/locale\";\n\n/**\n * Translates a non-plural locale key.\n *\n * Substitutions are type-checked from the generated locale structure:\n * keys without placeholders do not accept substitutions, while keys with\n * placeholders require all declared substitution values.\n *\n * @example\n * ```ts\n * t(\"app.name\");\n * t(\"app.greeting\", {name: \"Alice\"});\n * ```\n *\n * @param key - The locale key to translate.\n * @param args\n * @returns The translated string.\n */\nexport const t = <K extends LocaleNonPluralKeys<LocaleRegistry>>(\n key: K,\n ...args: LocaleSubstitutionArgs<LocaleRegistry, K>\n): string => {\n return NativeLocale.getInstance().trans(key, ...args);\n};\n\n/**\n * Translates a plural locale key using the provided count.\n *\n * Substitutions are type-checked from the generated locale structure:\n * keys without placeholders do not accept substitutions, while keys with\n * placeholders require all declared substitution values.\n *\n * @example\n * ```ts\n * choice(\"cart.items\", count, {count});\n * ```\n *\n * @param key - The locale key to translate.\n * @param count - The count used to select the plural form.\n * @param args\n * @returns The translated string.\n */\nexport const choice = <K extends LocalePluralKeys<LocaleRegistry>>(\n key: K,\n count: number,\n ...args: LocaleSubstitutionArgs<LocaleRegistry, K>\n): string => {\n return NativeLocale.getInstance().choice(key, count, ...args);\n};\n\n/**\n * Converts a locale key to a browser message reference.\n *\n * This is useful for browser-managed extension fields that expect\n * `__MSG_name__` references instead of already translated text.\n *\n * A warning is logged when the key does not exist in the generated locale keys.\n *\n * @example\n * ```ts\n * key(\"app.name\"); // \"__MSG_app_name__\"\n * ```\n *\n * @param value - The locale key to convert.\n * @returns The browser message reference.\n */\nexport const key = (value: keyof LocaleRegistry & string): string => {\n const locale = NativeLocale.getInstance();\n\n if (!locale.keys().has(value)) {\n console.warn(`Locale key \"${value}\" not found in \"${locale.lang()}\" language.`);\n }\n\n return convertLocaleMessageKey(value);\n};\n\n/**\n * Resolves a string that may contain a locale marker.\n *\n * When the input contains a locale marker, the marker is extracted and translated.\n * Plain strings are returned unchanged.\n *\n * @example\n * ```ts\n * resolve(\"@app.name\");\n * resolve(\"Plain title\");\n * ```\n *\n * @param input - A plain string or a marked locale key string.\n * @returns The translated text when a marker is found, otherwise the original input.\n */\nexport const resolve = (input: string): string => {\n const localeKey = extractLocaleKey(input);\n\n if (localeKey) {\n // Markers are runtime strings without substitutions; keep t() strict for typed callers.\n return (t as (key: string) => string)(localeKey);\n }\n\n return input;\n};\n"],"mappings":"AAAA,SAAQ,oBAAmB;AAC3B,SAAQ,yBAAyB,wBAAuB;AAoBjD,MAAM,IAAI,CACbA,SACG,SACM;AACT,SAAO,aAAa,YAAY,EAAE,MAAMA,MAAK,GAAG,IAAI;AACxD;AAmBO,MAAM,SAAS,CAClBA,MACA,UACG,SACM;AACT,SAAO,aAAa,YAAY,EAAE,OAAOA,MAAK,OAAO,GAAG,IAAI;AAChE;AAkBO,MAAM,MAAM,CAAC,UAAiD;AACjE,QAAM,SAAS,aAAa,YAAY;AAExC,MAAI,CAAC,OAAO,KAAK,EAAE,IAAI,KAAK,GAAG;AAC3B,YAAQ,KAAK,eAAe,KAAK,mBAAmB,OAAO,KAAK,CAAC,aAAa;AAAA,EAClF;AAEA,SAAO,wBAAwB,KAAK;AACxC;AAiBO,MAAM,UAAU,CAAC,UAA0B;AAC9C,QAAM,YAAY,iBAAiB,KAAK;AAExC,MAAI,WAAW;AAEX,WAAQ,EAA8B,SAAS;AAAA,EACnD;AAEA,SAAO;AACX;","names":["key"]}
@@ -1,3 +1,4 @@
1
1
  export * from "./providers/index.js";
2
2
  export * from "./helpers.js";
3
- export { Language, LanguageCodes, LocaleDir, type LocaleStructure, type LocaleProvider, type LocaleDynamicProvider, type LocaleKeys, type LocaleSubstitutionArgs, type LocaleSubstitutionKeys, type LocaleSubstitutionValue, type LocaleNonPluralKeys, type LocalePluralKeys, } from "../types/locale.js";
3
+ export * from "./storage/index.js";
4
+ export { Language, LanguageCodes, LocaleDir, type LocaleStructure, type LocaleRegistry, type LocaleProvider, type LocaleDynamicProvider, type LocaleSnapshot, type LocaleStorageDriver, type LocaleKeys, type LocaleSubstitutionArgs, type LocaleSubstitutionKeys, type LocaleSubstitutionValue, type LocaleNonPluralKeys, type LocalePluralKeys, } from "../types/locale.js";
@@ -1,5 +1,6 @@
1
1
  export * from "./providers/index.js";
2
2
  export * from "./helpers.js";
3
+ export * from "./storage/index.js";
3
4
  import {
4
5
  Language,
5
6
  LanguageCodes,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/locale/index.ts"],"sourcesContent":["export * from \"./providers\";\nexport * from \"./helpers\";\n\nexport {\n Language,\n LanguageCodes,\n LocaleDir,\n type LocaleStructure,\n type LocaleProvider,\n type LocaleDynamicProvider,\n type LocaleKeys,\n type LocaleSubstitutionArgs,\n type LocaleSubstitutionKeys,\n type LocaleSubstitutionValue,\n type LocaleNonPluralKeys,\n type LocalePluralKeys,\n} from \"@typing/locale\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AAEd;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAUG;","names":[]}
1
+ {"version":3,"sources":["../../src/locale/index.ts"],"sourcesContent":["export * from \"./providers\";\nexport * from \"./helpers\";\nexport * from \"./storage\";\n\nexport {\n Language,\n LanguageCodes,\n LocaleDir,\n type LocaleStructure,\n type LocaleRegistry,\n type LocaleProvider,\n type LocaleDynamicProvider,\n type LocaleSnapshot,\n type LocaleStorageDriver,\n type LocaleKeys,\n type LocaleSubstitutionArgs,\n type LocaleSubstitutionKeys,\n type LocaleSubstitutionValue,\n type LocaleNonPluralKeys,\n type LocalePluralKeys,\n} from \"@typing/locale\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AAEd;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAaG;","names":[]}
@@ -1,13 +1,13 @@
1
1
  import { Language, LocaleNonPluralKeys, LocalePluralKeys, LocaleProvider, LocaleStructure, LocaleSubstitutionArgs, LocaleSubstitutionValue } from "../../types/locale.js";
2
- export default abstract class<S extends object = LocaleStructure> implements LocaleProvider<S> {
2
+ export default abstract class AbstractLocale<S extends object = LocaleStructure> implements LocaleProvider<S> {
3
3
  abstract lang(): Language;
4
4
  abstract keys(): Set<keyof S>;
5
- abstract languages(): Set<Language>;
5
+ abstract langs(): ReadonlySet<Language>;
6
6
  /** Returns native names for this provider's languages, preserving their order. */
7
- languageNames(): Map<Language, string>;
7
+ langNames(): ReadonlyMap<Language, string>;
8
8
  protected abstract value(key: keyof S & string): string | undefined;
9
9
  trans<K extends LocaleNonPluralKeys<S>>(key: K, ...args: LocaleSubstitutionArgs<S, K>): string;
10
10
  choice<K extends LocalePluralKeys<S>>(key: K, count: number, ...args: LocaleSubstitutionArgs<S, K>): string;
11
11
  get<K extends keyof S & string>(key: K, substitutions?: Record<string, LocaleSubstitutionValue>): string;
12
- private getPluralIndex;
12
+ private substitute;
13
13
  }
@@ -1,12 +1,11 @@
1
+ import { selectPluralForm, applySubstitutions } from "./../../shared/locale/index.js";
1
2
  import {
2
- Language,
3
- LanguageNames,
4
- LocaleValuesSeparator
3
+ LanguageNames
5
4
  } from "./../../types/locale.js";
6
- class AbstractLocale_default {
5
+ class AbstractLocale {
7
6
  /** Returns native names for this provider's languages, preserving their order. */
8
- languageNames() {
9
- return new Map([...this.languages()].map((language) => [language, LanguageNames[language]]));
7
+ langNames() {
8
+ return new Map([...this.langs()].map((language) => [language, LanguageNames[language]]));
10
9
  }
11
10
  trans(key, ...args) {
12
11
  const [substitutions] = args;
@@ -14,9 +13,8 @@ class AbstractLocale_default {
14
13
  }
15
14
  choice(key, count, ...args) {
16
15
  const [substitutions] = args;
17
- const parts = this.get(key, substitutions).split(LocaleValuesSeparator);
18
- const idx = this.getPluralIndex(count);
19
- return parts[idx] ?? parts[0] ?? key;
16
+ const message = selectPluralForm(this.get(key), this.lang(), count);
17
+ return this.substitute(message, key, substitutions);
20
18
  }
21
19
  get(key, substitutions) {
22
20
  const template = this.value(key);
@@ -24,94 +22,15 @@ class AbstractLocale_default {
24
22
  console.warn(`Locale key "${key}" not found in "${this.lang()}" language.`);
25
23
  return key;
26
24
  }
27
- if (substitutions) {
28
- return template.replace(/{{(.*?)}}/g, (_, placeholder) => {
29
- const substitution = placeholder.trim();
30
- if (substitution in substitutions) {
31
- return substitutions[substitution].toString();
32
- }
33
- console.warn(
34
- `Locale substitution "${substitution}" not found for key "${key}" in "${this.lang()}" language.`
35
- );
36
- return substitution;
37
- });
38
- }
39
- return template;
25
+ return this.substitute(template, key, substitutions);
40
26
  }
41
- getPluralIndex(count) {
42
- switch (this.lang()) {
43
- case Language.Indonesian:
44
- case Language.Japanese:
45
- case Language.Kannada:
46
- case Language.Korean:
47
- case Language.Malay:
48
- case Language.Thai:
49
- case Language.Turkish:
50
- case Language.Vietnamese:
51
- return 0;
52
- case Language.Bengali:
53
- case Language.Bulgarian:
54
- case Language.Catalan:
55
- case Language.Danish:
56
- case Language.German:
57
- case Language.Greek:
58
- case Language.English:
59
- case Language.EnglishAustralia:
60
- case Language.EnglishGreatBritain:
61
- case Language.EnglishUSA:
62
- case Language.Spanish:
63
- case Language.SpanishLatinAmericaAndCaribbean:
64
- case Language.Estonian:
65
- case Language.Persian:
66
- case Language.Finnish:
67
- case Language.Gujarati:
68
- case Language.Hebrew:
69
- case Language.Hungarian:
70
- case Language.Italian:
71
- case Language.Malayalam:
72
- case Language.Marathi:
73
- case Language.Dutch:
74
- case Language.Norwegian:
75
- case Language.Swedish:
76
- case Language.Swahili:
77
- case Language.Tamil:
78
- case Language.Telugu:
79
- case Language.ChineseChina:
80
- case Language.ChineseTaiwan:
81
- case Language.PortugueseBrazil:
82
- case Language.PortuguesePortugal:
83
- return count == 1 ? 0 : 1;
84
- case Language.Amharic:
85
- case Language.Filipino:
86
- case Language.French:
87
- case Language.Hindi:
88
- return count == 0 || count == 1 ? 0 : 1;
89
- case Language.Croatian:
90
- case Language.Russian:
91
- case Language.Serbian:
92
- case Language.Ukrainian:
93
- return count % 10 == 1 && count % 100 != 11 ? 0 : count % 10 >= 2 && count % 10 <= 4 && (count % 100 < 10 || count % 100 >= 20) ? 1 : 2;
94
- case Language.Czech:
95
- case Language.Slovak:
96
- return count == 1 ? 0 : count >= 2 && count <= 4 ? 1 : 2;
97
- case Language.Lithuanian:
98
- return count % 10 == 1 && count % 100 != 11 ? 0 : count % 10 >= 2 && (count % 100 < 10 || count % 100 >= 20) ? 1 : 2;
99
- case Language.Slovenian:
100
- return count % 100 == 1 ? 0 : count % 100 == 2 ? 1 : count % 100 == 3 || count % 100 == 4 ? 2 : 3;
101
- case Language.Latvian:
102
- return count == 0 ? 0 : count % 10 == 1 && count % 100 != 11 ? 1 : 2;
103
- case Language.Polish:
104
- return count == 1 ? 0 : count % 10 >= 2 && count % 10 <= 4 && (count % 100 < 12 || count % 100 > 14) ? 1 : 2;
105
- case Language.Romanian:
106
- return count == 1 ? 0 : count == 0 || count % 100 > 0 && count % 100 < 20 ? 1 : 2;
107
- case Language.Arabic:
108
- return count == 0 ? 0 : count == 1 ? 1 : count == 2 ? 2 : count % 100 >= 3 && count % 100 <= 10 ? 3 : count % 100 >= 11 && count % 100 <= 99 ? 4 : 5;
109
- default:
110
- return 0;
111
- }
27
+ substitute(message, key, substitutions) {
28
+ return applySubstitutions(message, substitutions, (name) => {
29
+ console.warn(`Locale substitution "${name}" not found for key "${key}" in "${this.lang()}" language.`);
30
+ }).join("");
112
31
  }
113
32
  }
114
33
  export {
115
- AbstractLocale_default as default
34
+ AbstractLocale as default
116
35
  };
117
36
  //# sourceMappingURL=AbstractLocale.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/locale/providers/AbstractLocale.ts"],"sourcesContent":["import {\n Language,\n LanguageNames,\n LocaleNonPluralKeys,\n LocalePluralKeys,\n LocaleProvider,\n LocaleStructure,\n LocaleSubstitutionArgs,\n LocaleSubstitutionValue,\n LocaleValuesSeparator,\n} from \"@typing/locale\";\n\nexport default abstract class<S extends object = LocaleStructure> implements LocaleProvider<S> {\n public abstract lang(): Language;\n\n public abstract keys(): Set<keyof S>;\n\n public abstract languages(): Set<Language>;\n\n /** Returns native names for this provider's languages, preserving their order. */\n public languageNames(): Map<Language, string> {\n return new Map([...this.languages()].map(language => [language, LanguageNames[language]]));\n }\n\n protected abstract value(key: keyof S & string): string | undefined;\n\n public trans<K extends LocaleNonPluralKeys<S>>(key: K, ...args: LocaleSubstitutionArgs<S, K>): string {\n const [substitutions] = args;\n\n return this.get(key, substitutions);\n }\n\n public choice<K extends LocalePluralKeys<S>>(key: K, count: number, ...args: LocaleSubstitutionArgs<S, K>): string {\n const [substitutions] = args;\n const parts = this.get(key, substitutions).split(LocaleValuesSeparator);\n\n const idx = this.getPluralIndex(count);\n\n return parts[idx] ?? parts[0] ?? (key as string);\n }\n\n public get<K extends keyof S & string>(key: K, substitutions?: Record<string, LocaleSubstitutionValue>): string {\n const template = this.value(key);\n\n if (template === undefined) {\n console.warn(`Locale key \"${key}\" not found in \"${this.lang()}\" language.`);\n\n return key as string;\n }\n\n if (substitutions) {\n return template.replace(/{{(.*?)}}/g, (_, placeholder: string) => {\n const substitution = placeholder.trim();\n\n if (substitution in substitutions) {\n return substitutions[substitution]!.toString();\n }\n\n console.warn(\n `Locale substitution \"${substitution}\" not found for key \"${key}\" in \"${this.lang()}\" language.`\n );\n\n return substitution;\n });\n }\n\n return template;\n }\n\n private getPluralIndex(count: number): number {\n switch (this.lang()) {\n case Language.Indonesian:\n case Language.Japanese:\n case Language.Kannada:\n case Language.Korean:\n case Language.Malay:\n case Language.Thai:\n case Language.Turkish:\n case Language.Vietnamese:\n return 0;\n\n case Language.Bengali:\n case Language.Bulgarian:\n case Language.Catalan:\n case Language.Danish:\n case Language.German:\n case Language.Greek:\n case Language.English:\n case Language.EnglishAustralia:\n case Language.EnglishGreatBritain:\n case Language.EnglishUSA:\n case Language.Spanish:\n case Language.SpanishLatinAmericaAndCaribbean:\n case Language.Estonian:\n case Language.Persian:\n case Language.Finnish:\n case Language.Gujarati:\n case Language.Hebrew:\n case Language.Hungarian:\n case Language.Italian:\n case Language.Malayalam:\n case Language.Marathi:\n case Language.Dutch:\n case Language.Norwegian:\n case Language.Swedish:\n case Language.Swahili:\n case Language.Tamil:\n case Language.Telugu:\n case Language.ChineseChina:\n case Language.ChineseTaiwan:\n case Language.PortugueseBrazil:\n case Language.PortuguesePortugal:\n return count == 1 ? 0 : 1;\n\n case Language.Amharic:\n case Language.Filipino:\n case Language.French:\n case Language.Hindi:\n return count == 0 || count == 1 ? 0 : 1;\n\n case Language.Croatian:\n case Language.Russian:\n case Language.Serbian:\n case Language.Ukrainian:\n return count % 10 == 1 && count % 100 != 11\n ? 0\n : count % 10 >= 2 && count % 10 <= 4 && (count % 100 < 10 || count % 100 >= 20)\n ? 1\n : 2;\n\n case Language.Czech:\n case Language.Slovak:\n return count == 1 ? 0 : count >= 2 && count <= 4 ? 1 : 2;\n\n case Language.Lithuanian:\n return count % 10 == 1 && count % 100 != 11\n ? 0\n : count % 10 >= 2 && (count % 100 < 10 || count % 100 >= 20)\n ? 1\n : 2;\n\n case Language.Slovenian:\n return count % 100 == 1 ? 0 : count % 100 == 2 ? 1 : count % 100 == 3 || count % 100 == 4 ? 2 : 3;\n\n case Language.Latvian:\n return count == 0 ? 0 : count % 10 == 1 && count % 100 != 11 ? 1 : 2;\n\n case Language.Polish:\n return count == 1\n ? 0\n : count % 10 >= 2 && count % 10 <= 4 && (count % 100 < 12 || count % 100 > 14)\n ? 1\n : 2;\n\n case Language.Romanian:\n return count == 1 ? 0 : count == 0 || (count % 100 > 0 && count % 100 < 20) ? 1 : 2;\n\n case Language.Arabic:\n return count == 0\n ? 0\n : count == 1\n ? 1\n : count == 2\n ? 2\n : count % 100 >= 3 && count % 100 <= 10\n ? 3\n : count % 100 >= 11 && count % 100 <= 99\n ? 4\n : 5;\n\n default:\n return 0;\n }\n }\n}\n"],"mappings":"AAAA;AAAA,EACI;AAAA,EACA;AAAA,EAOA;AAAA,OACG;AAEP,MAAO,uBAAwF;AAAA;AAAA,EAQpF,gBAAuC;AAC1C,WAAO,IAAI,IAAI,CAAC,GAAG,KAAK,UAAU,CAAC,EAAE,IAAI,cAAY,CAAC,UAAU,cAAc,QAAQ,CAAC,CAAC,CAAC;AAAA,EAC7F;AAAA,EAIO,MAAwC,QAAW,MAA4C;AAClG,UAAM,CAAC,aAAa,IAAI;AAExB,WAAO,KAAK,IAAI,KAAK,aAAa;AAAA,EACtC;AAAA,EAEO,OAAsC,KAAQ,UAAkB,MAA4C;AAC/G,UAAM,CAAC,aAAa,IAAI;AACxB,UAAM,QAAQ,KAAK,IAAI,KAAK,aAAa,EAAE,MAAM,qBAAqB;AAEtE,UAAM,MAAM,KAAK,eAAe,KAAK;AAErC,WAAO,MAAM,GAAG,KAAK,MAAM,CAAC,KAAM;AAAA,EACtC;AAAA,EAEO,IAAgC,KAAQ,eAAiE;AAC5G,UAAM,WAAW,KAAK,MAAM,GAAG;AAE/B,QAAI,aAAa,QAAW;AACxB,cAAQ,KAAK,eAAe,GAAG,mBAAmB,KAAK,KAAK,CAAC,aAAa;AAE1E,aAAO;AAAA,IACX;AAEA,QAAI,eAAe;AACf,aAAO,SAAS,QAAQ,cAAc,CAAC,GAAG,gBAAwB;AAC9D,cAAM,eAAe,YAAY,KAAK;AAEtC,YAAI,gBAAgB,eAAe;AAC/B,iBAAO,cAAc,YAAY,EAAG,SAAS;AAAA,QACjD;AAEA,gBAAQ;AAAA,UACJ,wBAAwB,YAAY,wBAAwB,GAAG,SAAS,KAAK,KAAK,CAAC;AAAA,QACvF;AAEA,eAAO;AAAA,MACX,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACX;AAAA,EAEQ,eAAe,OAAuB;AAC1C,YAAQ,KAAK,KAAK,GAAG;AAAA,MACjB,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AACV,eAAO;AAAA,MAEX,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AACV,eAAO,SAAS,IAAI,IAAI;AAAA,MAE5B,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AACV,eAAO,SAAS,KAAK,SAAS,IAAI,IAAI;AAAA,MAE1C,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AACV,eAAO,QAAQ,MAAM,KAAK,QAAQ,OAAO,KACnC,IACA,QAAQ,MAAM,KAAK,QAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,QAAQ,OAAO,MACxE,IACA;AAAA,MAEZ,KAAK,SAAS;AAAA,MACd,KAAK,SAAS;AACV,eAAO,SAAS,IAAI,IAAI,SAAS,KAAK,SAAS,IAAI,IAAI;AAAA,MAE3D,KAAK,SAAS;AACV,eAAO,QAAQ,MAAM,KAAK,QAAQ,OAAO,KACnC,IACA,QAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,QAAQ,OAAO,MACrD,IACA;AAAA,MAEZ,KAAK,SAAS;AACV,eAAO,QAAQ,OAAO,IAAI,IAAI,QAAQ,OAAO,IAAI,IAAI,QAAQ,OAAO,KAAK,QAAQ,OAAO,IAAI,IAAI;AAAA,MAEpG,KAAK,SAAS;AACV,eAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,OAAO,KAAK,IAAI;AAAA,MAEvE,KAAK,SAAS;AACV,eAAO,SAAS,IACV,IACA,QAAQ,MAAM,KAAK,QAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,QAAQ,MAAM,MACvE,IACA;AAAA,MAEZ,KAAK,SAAS;AACV,eAAO,SAAS,IAAI,IAAI,SAAS,KAAM,QAAQ,MAAM,KAAK,QAAQ,MAAM,KAAM,IAAI;AAAA,MAEtF,KAAK,SAAS;AACV,eAAO,SAAS,IACV,IACA,SAAS,IACP,IACA,SAAS,IACP,IACA,QAAQ,OAAO,KAAK,QAAQ,OAAO,KACjC,IACA,QAAQ,OAAO,MAAM,QAAQ,OAAO,KAClC,IACA;AAAA,MAElB;AACI,eAAO;AAAA,IACf;AAAA,EACJ;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/locale/providers/AbstractLocale.ts"],"sourcesContent":["import {selectPluralForm, applySubstitutions} from \"@shared/locale\";\n\nimport {\n Language,\n LanguageNames,\n LocaleNonPluralKeys,\n LocalePluralKeys,\n LocaleProvider,\n LocaleStructure,\n LocaleSubstitutionArgs,\n LocaleSubstitutionValue,\n} from \"@typing/locale\";\n\nexport default abstract class AbstractLocale<S extends object = LocaleStructure> implements LocaleProvider<S> {\n public abstract lang(): Language;\n\n public abstract keys(): Set<keyof S>;\n\n public abstract langs(): ReadonlySet<Language>;\n\n /** Returns native names for this provider's languages, preserving their order. */\n public langNames(): ReadonlyMap<Language, string> {\n return new Map([...this.langs()].map(language => [language, LanguageNames[language]]));\n }\n\n protected abstract value(key: keyof S & string): string | undefined;\n\n public trans<K extends LocaleNonPluralKeys<S>>(key: K, ...args: LocaleSubstitutionArgs<S, K>): string {\n const [substitutions] = args;\n\n return this.get(key, substitutions);\n }\n\n public choice<K extends LocalePluralKeys<S>>(key: K, count: number, ...args: LocaleSubstitutionArgs<S, K>): string {\n const [substitutions] = args;\n const message = selectPluralForm(this.get(key), this.lang(), count);\n\n return this.substitute(message, key, substitutions);\n }\n\n public get<K extends keyof S & string>(key: K, substitutions?: Record<string, LocaleSubstitutionValue>): string {\n const template = this.value(key);\n\n if (template === undefined) {\n console.warn(`Locale key \"${key}\" not found in \"${this.lang()}\" language.`);\n\n return key as string;\n }\n\n return this.substitute(template, key, substitutions);\n }\n\n private substitute(message: string, key: string, substitutions?: Record<string, LocaleSubstitutionValue>): string {\n return applySubstitutions(message, substitutions, name => {\n console.warn(`Locale substitution \"${name}\" not found for key \"${key}\" in \"${this.lang()}\" language.`);\n }).join(\"\");\n }\n}\n"],"mappings":"AAAA,SAAQ,kBAAkB,0BAAyB;AAEnD;AAAA,EAEI;AAAA,OAOG;AAEP,MAAO,eAAuG;AAAA;AAAA,EAQnG,YAA2C;AAC9C,WAAO,IAAI,IAAI,CAAC,GAAG,KAAK,MAAM,CAAC,EAAE,IAAI,cAAY,CAAC,UAAU,cAAc,QAAQ,CAAC,CAAC,CAAC;AAAA,EACzF;AAAA,EAIO,MAAwC,QAAW,MAA4C;AAClG,UAAM,CAAC,aAAa,IAAI;AAExB,WAAO,KAAK,IAAI,KAAK,aAAa;AAAA,EACtC;AAAA,EAEO,OAAsC,KAAQ,UAAkB,MAA4C;AAC/G,UAAM,CAAC,aAAa,IAAI;AACxB,UAAM,UAAU,iBAAiB,KAAK,IAAI,GAAG,GAAG,KAAK,KAAK,GAAG,KAAK;AAElE,WAAO,KAAK,WAAW,SAAS,KAAK,aAAa;AAAA,EACtD;AAAA,EAEO,IAAgC,KAAQ,eAAiE;AAC5G,UAAM,WAAW,KAAK,MAAM,GAAG;AAE/B,QAAI,aAAa,QAAW;AACxB,cAAQ,KAAK,eAAe,GAAG,mBAAmB,KAAK,KAAK,CAAC,aAAa;AAE1E,aAAO;AAAA,IACX;AAEA,WAAO,KAAK,WAAW,UAAU,KAAK,aAAa;AAAA,EACvD;AAAA,EAEQ,WAAW,SAAiB,KAAa,eAAiE;AAC9G,WAAO,mBAAmB,SAAS,eAAe,UAAQ;AACtD,cAAQ,KAAK,wBAAwB,IAAI,wBAAwB,GAAG,SAAS,KAAK,KAAK,CAAC,aAAa;AAAA,IACzG,CAAC,EAAE,KAAK,EAAE;AAAA,EACd;AACJ;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import AbstractLocale from "./AbstractLocale.js";
2
2
  import { Language, LocaleStructure } from "../../types/locale.js";
3
- export type CustomLocaleData = Record<string, string>;
4
- export default class<T extends object = LocaleStructure> extends AbstractLocale<T> {
3
+ export type CustomLocaleData = Readonly<Record<string, string>>;
4
+ export default class CustomLocale<T extends object = LocaleStructure> extends AbstractLocale<T> {
5
5
  protected language: Language;
6
6
  protected data: CustomLocaleData;
7
7
  constructor(language?: Language, data?: CustomLocaleData);
@@ -9,6 +9,6 @@ export default class<T extends object = LocaleStructure> extends AbstractLocale<
9
9
  setData(data: CustomLocaleData): this;
10
10
  lang(): Language;
11
11
  keys(): Set<keyof T>;
12
- languages(): Set<Language>;
12
+ langs(): ReadonlySet<Language>;
13
13
  protected value(key: string): string | undefined;
14
14
  }
@@ -1,7 +1,7 @@
1
- import { convertLocaleKey } from "../utils.js";
1
+ import { convertLocaleKey } from "./../../shared/locale/index.js";
2
2
  import AbstractLocale from "./AbstractLocale.js";
3
3
  import { Language } from "./../../types/locale.js";
4
- class CustomLocale_default extends AbstractLocale {
4
+ class CustomLocale extends AbstractLocale {
5
5
  constructor(language = Language.English, data = {}) {
6
6
  super();
7
7
  this.language = language;
@@ -23,11 +23,12 @@ class CustomLocale_default extends AbstractLocale {
23
23
  keys() {
24
24
  return new Set(Object.keys(this.data));
25
25
  }
26
- languages() {
26
+ langs() {
27
27
  return /* @__PURE__ */ new Set([this.lang()]);
28
28
  }
29
29
  value(key) {
30
- const value = this.data[convertLocaleKey(key)];
30
+ const name = convertLocaleKey(key);
31
+ const value = Object.hasOwn(this.data, name) ? this.data[name] : void 0;
31
32
  if (value === void 0) {
32
33
  return void 0;
33
34
  }
@@ -35,6 +36,6 @@ class CustomLocale_default extends AbstractLocale {
35
36
  }
36
37
  }
37
38
  export {
38
- CustomLocale_default as default
39
+ CustomLocale as default
39
40
  };
40
41
  //# sourceMappingURL=CustomLocale.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/locale/providers/CustomLocale.ts"],"sourcesContent":["import {convertLocaleKey} from \"../utils\";\n\nimport AbstractLocale from \"./AbstractLocale\";\n\nimport {Language, LocaleStructure} from \"@typing/locale\";\n\nexport type CustomLocaleData = Record<string, string>;\n\nexport default class<T extends object = LocaleStructure> extends AbstractLocale<T> {\n constructor(\n protected language: Language = Language.English,\n protected data: CustomLocaleData = {}\n ) {\n super();\n }\n\n public setLang(lang: Language): this {\n this.language = lang;\n\n return this;\n }\n\n public setData(data: CustomLocaleData): this {\n this.data = data;\n\n return this;\n }\n\n public lang(): Language {\n return this.language;\n }\n\n public keys(): Set<keyof T> {\n return new Set(Object.keys(this.data)) as Set<keyof T>;\n }\n\n public languages(): Set<Language> {\n return new Set([this.lang()]);\n }\n\n protected value(key: string): string | undefined {\n const value = this.data[convertLocaleKey(key)];\n\n if (value === undefined) {\n return undefined;\n }\n\n return value;\n }\n}\n"],"mappings":"AAAA,SAAQ,wBAAuB;AAE/B,OAAO,oBAAoB;AAE3B,SAAQ,gBAAgC;AAIxC,MAAO,6BAA0D,eAAkB;AAAA,EAC/E,YACc,WAAqB,SAAS,SAC9B,OAAyB,CAAC,GACtC;AACE,UAAM;AAHI;AACA;AAAA,EAGd;AAAA,EAJc;AAAA,EACA;AAAA,EAKP,QAAQ,MAAsB;AACjC,SAAK,WAAW;AAEhB,WAAO;AAAA,EACX;AAAA,EAEO,QAAQ,MAA8B;AACzC,SAAK,OAAO;AAEZ,WAAO;AAAA,EACX;AAAA,EAEO,OAAiB;AACpB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,OAAqB;AACxB,WAAO,IAAI,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC;AAAA,EACzC;AAAA,EAEO,YAA2B;AAC9B,WAAO,oBAAI,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;AAAA,EAChC;AAAA,EAEU,MAAM,KAAiC;AAC7C,UAAM,QAAQ,KAAK,KAAK,iBAAiB,GAAG,CAAC;AAE7C,QAAI,UAAU,QAAW;AACrB,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/locale/providers/CustomLocale.ts"],"sourcesContent":["import {convertLocaleKey} from \"@shared/locale\";\n\nimport AbstractLocale from \"./AbstractLocale\";\n\nimport {Language, LocaleStructure} from \"@typing/locale\";\n\nexport type CustomLocaleData = Readonly<Record<string, string>>;\n\nexport default class CustomLocale<T extends object = LocaleStructure> extends AbstractLocale<T> {\n constructor(\n protected language: Language = Language.English,\n protected data: CustomLocaleData = {}\n ) {\n super();\n }\n\n public setLang(lang: Language): this {\n this.language = lang;\n\n return this;\n }\n\n public setData(data: CustomLocaleData): this {\n this.data = data;\n\n return this;\n }\n\n public lang(): Language {\n return this.language;\n }\n\n public keys(): Set<keyof T> {\n return new Set(Object.keys(this.data)) as Set<keyof T>;\n }\n\n public langs(): ReadonlySet<Language> {\n return new Set([this.lang()]);\n }\n\n protected value(key: string): string | undefined {\n const name = convertLocaleKey(key);\n const value = Object.hasOwn(this.data, name) ? this.data[name] : undefined;\n\n if (value === undefined) {\n return undefined;\n }\n\n return value;\n }\n}\n"],"mappings":"AAAA,SAAQ,wBAAuB;AAE/B,OAAO,oBAAoB;AAE3B,SAAQ,gBAAgC;AAIxC,MAAO,qBAAuE,eAAkB;AAAA,EAC5F,YACc,WAAqB,SAAS,SAC9B,OAAyB,CAAC,GACtC;AACE,UAAM;AAHI;AACA;AAAA,EAGd;AAAA,EAJc;AAAA,EACA;AAAA,EAKP,QAAQ,MAAsB;AACjC,SAAK,WAAW;AAEhB,WAAO;AAAA,EACX;AAAA,EAEO,QAAQ,MAA8B;AACzC,SAAK,OAAO;AAEZ,WAAO;AAAA,EACX;AAAA,EAEO,OAAiB;AACpB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,OAAqB;AACxB,WAAO,IAAI,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC;AAAA,EACzC;AAAA,EAEO,QAA+B;AAClC,WAAO,oBAAI,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;AAAA,EAChC;AAAA,EAEU,MAAM,KAAiC;AAC7C,UAAM,OAAO,iBAAiB,GAAG;AACjC,UAAM,QAAQ,OAAO,OAAO,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI;AAEjE,QAAI,UAAU,QAAW;AACrB,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
@@ -1,19 +1,26 @@
1
- import { type StorageProvider } from "@addon-core/storage";
2
- import NativeLocale, { LocaleNativeStructure } from "./NativeLocale.js";
3
- import CustomLocale, { CustomLocaleData } from "./CustomLocale.js";
4
- import { Language, LocaleDynamicProvider } from "../../types/locale.js";
5
- export default class<T extends object = LocaleNativeStructure> extends NativeLocale<T> implements LocaleDynamicProvider<T> {
6
- protected cache: Map<Language, CustomLocaleData>;
7
- protected locale?: CustomLocale<T>;
8
- protected storage?: StorageProvider<Record<string, Language>>;
9
- protected storageKey?: string;
1
+ import AbstractLocale from "./AbstractLocale.js";
2
+ import { Language, type LocaleDynamicProvider, type LocaleRegistry, type LocaleStorageDriver } from "../../types/locale.js";
3
+ export default class DynamicLocale<T extends object = LocaleRegistry> extends AbstractLocale<T> implements LocaleDynamicProvider<T> {
4
+ private language;
5
+ private data;
6
+ protected storage?: LocaleStorageDriver;
10
7
  protected unsubscribe?: () => void;
11
- constructor(storage?: string | false);
8
+ constructor(storage?: LocaleStorageDriver | false);
9
+ /**
10
+ * Selects a language synchronously without saving it.
11
+ * With storage enabled, a later sync() or watched storage update can replace this local selection.
12
+ * @throws If the language is absent from the catalogue.
13
+ */
14
+ select(lang: Language): Language;
15
+ /** Selects a language immediately and saves it when storage is enabled. */
12
16
  change(lang: Language): Promise<Language>;
13
17
  sync(): Promise<Language>;
14
18
  watch(handler?: (lang: Language) => void): () => void;
15
19
  unwatch(): void;
16
20
  lang(): Language;
21
+ /** Completed messages for the current language, with underscore keys and no substitutions applied. */
22
+ messages(): Readonly<Record<string, string>>;
23
+ keys(): Set<keyof T>;
24
+ langs(): ReadonlySet<Language>;
17
25
  protected value(key: Extract<keyof T, string>): string | undefined;
18
- protected fetch(lang: Language): Promise<CustomLocaleData>;
19
26
  }
@@ -1,58 +1,74 @@
1
- import { flattenLocaleMessages, getLocaleFilename } from "../utils.js";
2
- import { Storage } from "@addon-core/storage";
3
- import NativeLocale from "./NativeLocale.js";
4
- import CustomLocale from "./CustomLocale.js";
5
- import { LanguageCodes } from "./../../types/locale.js";
6
- class DynamicLocale_default extends NativeLocale {
7
- cache = /* @__PURE__ */ new Map();
8
- locale;
1
+ import { getI18nMessage } from "@addon-core/browser";
2
+ import catalogue, { keys, lang as defaultLanguage, languages } from "#adnbn/locale";
3
+ import AbstractLocale from "./AbstractLocale.js";
4
+ import { LocaleStorage } from "../storage/index.js";
5
+ import { convertLocaleKey, resolveLanguage } from "./../../shared/locale/index.js";
6
+ import {
7
+ LocaleCustomKeyForLanguage
8
+ } from "./../../types/locale.js";
9
+ class DynamicLocale extends AbstractLocale {
10
+ language;
11
+ data;
9
12
  storage;
10
- storageKey;
11
13
  unsubscribe;
12
- constructor(storage = "lang") {
14
+ constructor(storage) {
13
15
  super();
14
- if (storage) {
15
- this.storageKey = storage;
16
- this.storage = Storage.Local();
16
+ let marker;
17
+ try {
18
+ marker = getI18nMessage(LocaleCustomKeyForLanguage);
19
+ } catch {
17
20
  }
21
+ this.select(resolveLanguage(marker) ?? defaultLanguage);
22
+ this.storage = storage === false ? void 0 : storage ?? new LocaleStorage();
18
23
  }
19
- async change(lang) {
20
- if (lang === this.lang()) {
21
- return lang;
24
+ /**
25
+ * Selects a language synchronously without saving it.
26
+ * With storage enabled, a later sync() or watched storage update can replace this local selection.
27
+ * @throws If the language is absent from the catalogue.
28
+ */
29
+ select(lang) {
30
+ if (!Object.hasOwn(catalogue, lang)) {
31
+ throw new Error(`[DynamicLocale] Language "${lang}" is not available in the catalogue.`);
22
32
  }
23
- const messages = await this.fetch(lang);
24
- (this.locale ?? (this.locale = new CustomLocale())).setLang(lang).setData(messages);
25
- if (this.storage && this.storageKey) {
26
- await this.storage.set(this.storageKey, lang);
33
+ this.language = lang;
34
+ this.data = catalogue[lang];
35
+ return lang;
36
+ }
37
+ /** Selects a language immediately and saves it when storage is enabled. */
38
+ async change(lang) {
39
+ this.select(lang);
40
+ if (this.storage) {
41
+ await this.storage.set(lang);
27
42
  }
28
43
  return lang;
29
44
  }
30
45
  async sync() {
31
- if (!this.storage || !this.storageKey) {
46
+ if (!this.storage) {
32
47
  throw new Error("Language is not saving in storage");
33
48
  }
34
- const lang = await this.storage.get(this.storageKey);
49
+ const lang = await this.storage.get();
35
50
  if (!lang) {
36
51
  return this.lang();
37
52
  }
38
- if (!LanguageCodes.has(lang)) {
53
+ if (!Object.hasOwn(catalogue, lang)) {
39
54
  console.warn(`Incorrect language code in storage - "${lang}"`);
40
55
  return this.lang();
41
56
  }
42
- return this.change(lang);
57
+ return this.select(lang);
43
58
  }
44
59
  watch(handler) {
45
- if (!this.storage || !this.storageKey) {
60
+ if (!this.storage) {
46
61
  throw new Error("Language is not saved in storage");
47
62
  }
48
63
  if (this.unsubscribe) {
49
64
  throw new Error("Already subscribed to language changes in storage");
50
65
  }
51
- this.unsubscribe = this.storage.watch({
52
- [this.storageKey]: (newValue) => {
53
- if (newValue) {
54
- this.change(newValue).then(() => handler && handler(newValue)).catch((err) => console.error("Error while changing language:", err));
55
- }
66
+ this.unsubscribe = this.storage.watch((lang) => {
67
+ try {
68
+ this.select(lang);
69
+ handler == null ? void 0 : handler(lang);
70
+ } catch (error) {
71
+ console.error("Error while changing language:", error);
56
72
  }
57
73
  });
58
74
  return this.unwatch.bind(this);
@@ -63,27 +79,24 @@ class DynamicLocale_default extends NativeLocale {
63
79
  this.unsubscribe = void 0;
64
80
  }
65
81
  lang() {
66
- var _a;
67
- return ((_a = this.locale) == null ? void 0 : _a.lang()) || super.lang();
82
+ return this.language;
68
83
  }
69
- value(key) {
70
- var _a;
71
- return ((_a = this.locale) == null ? void 0 : _a.get(key)) ?? super.value(key);
84
+ /** Completed messages for the current language, with underscore keys and no substitutions applied. */
85
+ messages() {
86
+ return this.data;
72
87
  }
73
- async fetch(lang) {
74
- let messages = this.cache.get(lang);
75
- if (!messages) {
76
- const response = await (await fetch(getLocaleFilename(lang))).json();
77
- if (!response || typeof response !== "object") {
78
- throw new Error(`Invalid or empty locale data for "${lang}"`);
79
- }
80
- messages = flattenLocaleMessages(response);
81
- this.cache.set(lang, messages);
82
- }
83
- return messages;
88
+ keys() {
89
+ return new Set(keys);
90
+ }
91
+ langs() {
92
+ return new Set(languages);
93
+ }
94
+ value(key) {
95
+ const name = convertLocaleKey(key);
96
+ return Object.hasOwn(this.data, name) ? this.data[name] : void 0;
84
97
  }
85
98
  }
86
99
  export {
87
- DynamicLocale_default as default
100
+ DynamicLocale as default
88
101
  };
89
102
  //# sourceMappingURL=DynamicLocale.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/locale/providers/DynamicLocale.ts"],"sourcesContent":["import {flattenLocaleMessages, getLocaleFilename} from \"../utils\";\n\nimport {Storage, type StorageProvider} from \"@addon-core/storage\";\n\nimport NativeLocale, {LocaleNativeStructure} from \"./NativeLocale\";\nimport CustomLocale, {CustomLocaleData} from \"./CustomLocale\";\n\nimport {Language, LanguageCodes, LocaleDynamicProvider, LocaleMessages} from \"@typing/locale\";\n\nexport default class<T extends object = LocaleNativeStructure>\n extends NativeLocale<T>\n implements LocaleDynamicProvider<T>\n{\n protected cache = new Map<Language, CustomLocaleData>();\n\n protected locale?: CustomLocale<T>;\n\n protected storage?: StorageProvider<Record<string, Language>>;\n protected storageKey?: string;\n\n protected unsubscribe?: () => void;\n\n constructor(storage: string | false = \"lang\") {\n super();\n\n if (storage) {\n this.storageKey = storage;\n this.storage = Storage.Local();\n }\n }\n\n public async change(lang: Language): Promise<Language> {\n if (lang === this.lang()) {\n return lang;\n }\n\n const messages = await this.fetch(lang);\n\n (this.locale ??= new CustomLocale()).setLang(lang).setData(messages);\n\n if (this.storage && this.storageKey) {\n await this.storage.set(this.storageKey, lang);\n }\n\n return lang;\n }\n\n public async sync(): Promise<Language> {\n if (!this.storage || !this.storageKey) {\n throw new Error(\"Language is not saving in storage\");\n }\n\n const lang = await this.storage.get(this.storageKey);\n\n if (!lang) {\n return this.lang();\n }\n\n if (!LanguageCodes.has(lang)) {\n console.warn(`Incorrect language code in storage - \"${lang}\"`);\n\n return this.lang();\n }\n\n return this.change(lang);\n }\n\n public watch(handler?: (lang: Language) => void): () => void {\n if (!this.storage || !this.storageKey) {\n throw new Error(\"Language is not saved in storage\");\n }\n\n if (this.unsubscribe) {\n throw new Error(\"Already subscribed to language changes in storage\");\n }\n\n this.unsubscribe = this.storage.watch({\n [this.storageKey]: newValue => {\n if (newValue) {\n this.change(newValue)\n .then(() => handler && handler(newValue))\n .catch(err => console.error(\"Error while changing language:\", err));\n }\n },\n });\n\n return this.unwatch.bind(this);\n }\n\n public unwatch(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n public lang(): Language {\n return this.locale?.lang() || super.lang();\n }\n\n protected value(key: Extract<keyof T, string>): string | undefined {\n return this.locale?.get(key) ?? super.value(key);\n }\n\n protected async fetch(lang: Language): Promise<CustomLocaleData> {\n let messages = this.cache.get(lang);\n\n if (!messages) {\n const response: LocaleMessages = await (await fetch(getLocaleFilename(lang))).json();\n\n if (!response || typeof response !== \"object\") {\n throw new Error(`Invalid or empty locale data for \"${lang}\"`);\n }\n\n messages = flattenLocaleMessages(response);\n\n this.cache.set(lang, messages);\n }\n\n return messages;\n }\n}\n"],"mappings":"AAAA,SAAQ,uBAAuB,yBAAwB;AAEvD,SAAQ,eAAoC;AAE5C,OAAO,kBAA2C;AAClD,OAAO,kBAAsC;AAE7C,SAAkB,qBAA2D;AAE7E,MAAO,8BACK,aAEZ;AAAA,EACc,QAAQ,oBAAI,IAAgC;AAAA,EAE5C;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EAEV,YAAY,UAA0B,QAAQ;AAC1C,UAAM;AAEN,QAAI,SAAS;AACT,WAAK,aAAa;AAClB,WAAK,UAAU,QAAQ,MAAM;AAAA,IACjC;AAAA,EACJ;AAAA,EAEA,MAAa,OAAO,MAAmC;AACnD,QAAI,SAAS,KAAK,KAAK,GAAG;AACtB,aAAO;AAAA,IACX;AAEA,UAAM,WAAW,MAAM,KAAK,MAAM,IAAI;AAEtC,KAAC,KAAK,WAAL,KAAK,SAAW,IAAI,aAAa,IAAG,QAAQ,IAAI,EAAE,QAAQ,QAAQ;AAEnE,QAAI,KAAK,WAAW,KAAK,YAAY;AACjC,YAAM,KAAK,QAAQ,IAAI,KAAK,YAAY,IAAI;AAAA,IAChD;AAEA,WAAO;AAAA,EACX;AAAA,EAEA,MAAa,OAA0B;AACnC,QAAI,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY;AACnC,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACvD;AAEA,UAAM,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,UAAU;AAEnD,QAAI,CAAC,MAAM;AACP,aAAO,KAAK,KAAK;AAAA,IACrB;AAEA,QAAI,CAAC,cAAc,IAAI,IAAI,GAAG;AAC1B,cAAQ,KAAK,yCAAyC,IAAI,GAAG;AAE7D,aAAO,KAAK,KAAK;AAAA,IACrB;AAEA,WAAO,KAAK,OAAO,IAAI;AAAA,EAC3B;AAAA,EAEO,MAAM,SAAgD;AACzD,QAAI,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY;AACnC,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACtD;AAEA,QAAI,KAAK,aAAa;AAClB,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACvE;AAEA,SAAK,cAAc,KAAK,QAAQ,MAAM;AAAA,MAClC,CAAC,KAAK,UAAU,GAAG,cAAY;AAC3B,YAAI,UAAU;AACV,eAAK,OAAO,QAAQ,EACf,KAAK,MAAM,WAAW,QAAQ,QAAQ,CAAC,EACvC,MAAM,SAAO,QAAQ,MAAM,kCAAkC,GAAG,CAAC;AAAA,QAC1E;AAAA,MACJ;AAAA,IACJ,CAAC;AAED,WAAO,KAAK,QAAQ,KAAK,IAAI;AAAA,EACjC;AAAA,EAEO,UAAgB;AAzF3B;AA0FQ,eAAK,gBAAL;AACA,SAAK,cAAc;AAAA,EACvB;AAAA,EAEO,OAAiB;AA9F5B;AA+FQ,aAAO,UAAK,WAAL,mBAAa,WAAU,MAAM,KAAK;AAAA,EAC7C;AAAA,EAEU,MAAM,KAAmD;AAlGvE;AAmGQ,aAAO,UAAK,WAAL,mBAAa,IAAI,SAAQ,MAAM,MAAM,GAAG;AAAA,EACnD;AAAA,EAEA,MAAgB,MAAM,MAA2C;AAC7D,QAAI,WAAW,KAAK,MAAM,IAAI,IAAI;AAElC,QAAI,CAAC,UAAU;AACX,YAAM,WAA2B,OAAO,MAAM,MAAM,kBAAkB,IAAI,CAAC,GAAG,KAAK;AAEnF,UAAI,CAAC,YAAY,OAAO,aAAa,UAAU;AAC3C,cAAM,IAAI,MAAM,qCAAqC,IAAI,GAAG;AAAA,MAChE;AAEA,iBAAW,sBAAsB,QAAQ;AAEzC,WAAK,MAAM,IAAI,MAAM,QAAQ;AAAA,IACjC;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/locale/providers/DynamicLocale.ts"],"sourcesContent":["import {getI18nMessage} from \"@addon-core/browser\";\n\nimport catalogue, {keys, lang as defaultLanguage, languages} from \"#adnbn/locale\";\n\nimport AbstractLocale from \"./AbstractLocale\";\nimport {LocaleStorage} from \"../storage\";\n\nimport {convertLocaleKey, resolveLanguage} from \"@shared/locale\";\nimport {\n Language,\n LocaleCustomKeyForLanguage,\n type LocaleDynamicProvider,\n type LocaleRegistry,\n type LocaleStorageDriver,\n} from \"@typing/locale\";\n\nexport default class DynamicLocale<T extends object = LocaleRegistry>\n extends AbstractLocale<T>\n implements LocaleDynamicProvider<T>\n{\n private language!: Language;\n private data!: Readonly<Record<string, string>>;\n\n protected storage?: LocaleStorageDriver;\n protected unsubscribe?: () => void;\n\n constructor(storage?: LocaleStorageDriver | false) {\n super();\n\n let marker: string | undefined;\n\n try {\n marker = getI18nMessage(LocaleCustomKeyForLanguage);\n } catch {\n // MAIN has no extension i18n; use the configured language from the bundled catalogue.\n }\n\n this.select(resolveLanguage(marker) ?? defaultLanguage);\n\n this.storage = storage === false ? undefined : (storage ?? new LocaleStorage());\n }\n\n /**\n * Selects a language synchronously without saving it.\n * With storage enabled, a later sync() or watched storage update can replace this local selection.\n * @throws If the language is absent from the catalogue.\n */\n public select(lang: Language): Language {\n if (!Object.hasOwn(catalogue, lang)) {\n throw new Error(`[DynamicLocale] Language \"${lang}\" is not available in the catalogue.`);\n }\n\n this.language = lang;\n this.data = catalogue[lang]!;\n\n return lang;\n }\n\n /** Selects a language immediately and saves it when storage is enabled. */\n public async change(lang: Language): Promise<Language> {\n this.select(lang);\n\n if (this.storage) {\n await this.storage.set(lang);\n }\n\n return lang;\n }\n\n public async sync(): Promise<Language> {\n if (!this.storage) {\n throw new Error(\"Language is not saving in storage\");\n }\n\n const lang = await this.storage.get();\n\n if (!lang) {\n return this.lang();\n }\n\n if (!Object.hasOwn(catalogue, lang)) {\n console.warn(`Incorrect language code in storage - \"${lang}\"`);\n\n return this.lang();\n }\n\n return this.select(lang);\n }\n\n public watch(handler?: (lang: Language) => void): () => void {\n if (!this.storage) {\n throw new Error(\"Language is not saved in storage\");\n }\n\n if (this.unsubscribe) {\n throw new Error(\"Already subscribed to language changes in storage\");\n }\n\n this.unsubscribe = this.storage.watch(lang => {\n try {\n this.select(lang);\n handler?.(lang);\n } catch (error) {\n console.error(\"Error while changing language:\", error);\n }\n });\n\n return this.unwatch.bind(this);\n }\n\n public unwatch(): void {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n }\n\n public lang(): Language {\n return this.language;\n }\n\n /** Completed messages for the current language, with underscore keys and no substitutions applied. */\n public messages(): Readonly<Record<string, string>> {\n return this.data;\n }\n\n public keys(): Set<keyof T> {\n return new Set(keys) as Set<keyof T>;\n }\n\n public langs(): ReadonlySet<Language> {\n return new Set(languages);\n }\n\n protected value(key: Extract<keyof T, string>): string | undefined {\n const name = convertLocaleKey(key);\n\n return Object.hasOwn(this.data, name) ? this.data[name] : undefined;\n }\n}\n"],"mappings":"AAAA,SAAQ,sBAAqB;AAE7B,OAAO,aAAY,MAAM,QAAQ,iBAAiB,iBAAgB;AAElE,OAAO,oBAAoB;AAC3B,SAAQ,qBAAoB;AAE5B,SAAQ,kBAAkB,uBAAsB;AAChD;AAAA,EAEI;AAAA,OAIG;AAEP,MAAO,sBACK,eAEZ;AAAA,EACY;AAAA,EACA;AAAA,EAEE;AAAA,EACA;AAAA,EAEV,YAAY,SAAuC;AAC/C,UAAM;AAEN,QAAI;AAEJ,QAAI;AACA,eAAS,eAAe,0BAA0B;AAAA,IACtD,QAAQ;AAAA,IAER;AAEA,SAAK,OAAO,gBAAgB,MAAM,KAAK,eAAe;AAEtD,SAAK,UAAU,YAAY,QAAQ,SAAa,WAAW,IAAI,cAAc;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,OAAO,MAA0B;AACpC,QAAI,CAAC,OAAO,OAAO,WAAW,IAAI,GAAG;AACjC,YAAM,IAAI,MAAM,6BAA6B,IAAI,sCAAsC;AAAA,IAC3F;AAEA,SAAK,WAAW;AAChB,SAAK,OAAO,UAAU,IAAI;AAE1B,WAAO;AAAA,EACX;AAAA;AAAA,EAGA,MAAa,OAAO,MAAmC;AACnD,SAAK,OAAO,IAAI;AAEhB,QAAI,KAAK,SAAS;AACd,YAAM,KAAK,QAAQ,IAAI,IAAI;AAAA,IAC/B;AAEA,WAAO;AAAA,EACX;AAAA,EAEA,MAAa,OAA0B;AACnC,QAAI,CAAC,KAAK,SAAS;AACf,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACvD;AAEA,UAAM,OAAO,MAAM,KAAK,QAAQ,IAAI;AAEpC,QAAI,CAAC,MAAM;AACP,aAAO,KAAK,KAAK;AAAA,IACrB;AAEA,QAAI,CAAC,OAAO,OAAO,WAAW,IAAI,GAAG;AACjC,cAAQ,KAAK,yCAAyC,IAAI,GAAG;AAE7D,aAAO,KAAK,KAAK;AAAA,IACrB;AAEA,WAAO,KAAK,OAAO,IAAI;AAAA,EAC3B;AAAA,EAEO,MAAM,SAAgD;AACzD,QAAI,CAAC,KAAK,SAAS;AACf,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACtD;AAEA,QAAI,KAAK,aAAa;AAClB,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACvE;AAEA,SAAK,cAAc,KAAK,QAAQ,MAAM,UAAQ;AAC1C,UAAI;AACA,aAAK,OAAO,IAAI;AAChB,2CAAU;AAAA,MACd,SAAS,OAAO;AACZ,gBAAQ,MAAM,kCAAkC,KAAK;AAAA,MACzD;AAAA,IACJ,CAAC;AAED,WAAO,KAAK,QAAQ,KAAK,IAAI;AAAA,EACjC;AAAA,EAEO,UAAgB;AA9G3B;AA+GQ,eAAK,gBAAL;AACA,SAAK,cAAc;AAAA,EACvB;AAAA,EAEO,OAAiB;AACpB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA,EAGO,WAA6C;AAChD,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,OAAqB;AACxB,WAAO,IAAI,IAAI,IAAI;AAAA,EACvB;AAAA,EAEO,QAA+B;AAClC,WAAO,IAAI,IAAI,SAAS;AAAA,EAC5B;AAAA,EAEU,MAAM,KAAmD;AAC/D,UAAM,OAAO,iBAAiB,GAAG;AAEjC,WAAO,OAAO,OAAO,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI;AAAA,EAC9D;AACJ;","names":[]}
@@ -1,15 +1,12 @@
1
1
  import AbstractLocale from "./AbstractLocale.js";
2
- import { Language, LocaleProvider } from "../../types/locale.js";
3
- /** Augmented by the generated .adnbn/locale.d.ts for the current app. */
4
- export interface LocaleNativeStructure {
5
- }
6
- export default class NativeLocale<S extends object = LocaleNativeStructure> extends AbstractLocale<S> {
2
+ import { Language, type LocaleRegistry } from "../../types/locale.js";
3
+ export default class NativeLocale<S extends object = LocaleRegistry> extends AbstractLocale<S> {
7
4
  private static instance?;
8
- static getInstance(): LocaleProvider<LocaleNativeStructure>;
5
+ static getInstance(): NativeLocale<LocaleRegistry>;
9
6
  private readonly language?;
10
7
  constructor();
11
8
  lang(): Language;
12
9
  keys(): Set<keyof S>;
13
- languages(): Set<Language>;
10
+ langs(): ReadonlySet<Language>;
14
11
  protected value(key: Extract<keyof S, string>): string | undefined;
15
12
  }
@@ -1,6 +1,7 @@
1
1
  import { getI18nMessage } from "@addon-core/browser";
2
+ import { keys, languages } from "#adnbn/locale";
2
3
  import AbstractLocale from "./AbstractLocale.js";
3
- import { convertLocaleKey, resolveLanguage } from "./../../locale/utils.js";
4
+ import { convertLocaleKey, resolveLanguage } from "./../../shared/locale/index.js";
4
5
  import { LocaleCustomKeyForLanguage } from "./../../types/locale.js";
5
6
  class NativeLocale extends AbstractLocale {
6
7
  static instance;
@@ -27,20 +28,10 @@ class NativeLocale extends AbstractLocale {
27
28
  return this.language;
28
29
  }
29
30
  keys() {
30
- try {
31
- return new Set(__ADNBN_LOCALE_KEYS__);
32
- } catch (e) {
33
- console.error("[NativeLocale] Failed to access locale keys. Ensure the bundler plugin is active.", e);
34
- return /* @__PURE__ */ new Set();
35
- }
31
+ return new Set(keys);
36
32
  }
37
- languages() {
38
- try {
39
- return new Set(__ADNBN_DEFINED_LOCALES__);
40
- } catch (e) {
41
- console.error("[NativeLocale] Failed to access defined locales. Check virtual variables configuration.", e);
42
- return /* @__PURE__ */ new Set();
43
- }
33
+ langs() {
34
+ return new Set(languages);
44
35
  }
45
36
  value(key) {
46
37
  const value = getI18nMessage(convertLocaleKey(key));