intor 2.5.0 → 2.6.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 (322) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/core/export/index.js +1 -0
  4. package/dist/core/src/client/shared/helpers/get-client-locale.js +5 -20
  5. package/dist/core/src/client/shared/utils/locale/detect-browser-locale.js +2 -8
  6. package/dist/core/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  7. package/dist/core/src/config/constants/cookie.js +9 -9
  8. package/dist/core/src/config/constants/routing.js +13 -14
  9. package/dist/core/src/config/define-intor-config.js +28 -44
  10. package/dist/core/src/config/resolvers/resolve-cookie-options.js +4 -4
  11. package/dist/core/src/config/resolvers/resolve-fallback-locales.js +33 -50
  12. package/dist/core/src/config/resolvers/resolve-routing-options.js +32 -61
  13. package/dist/core/src/config/validators/validate-default-locale.js +8 -13
  14. package/dist/core/src/config/validators/validate-id.js +8 -13
  15. package/dist/core/src/config/validators/validate-supported-locales.js +8 -13
  16. package/dist/core/src/core/constants/locale-placeholder.js +0 -1
  17. package/dist/core/src/core/error/intor-error.js +14 -29
  18. package/dist/core/src/core/locale/canonicalize-locale.js +7 -18
  19. package/dist/core/src/core/locale/match-locale.js +24 -50
  20. package/dist/core/src/core/locale/parse-locale.js +12 -22
  21. package/dist/core/src/core/logger/get-logger.js +26 -31
  22. package/dist/core/src/core/logger/global-logger-pool.js +4 -4
  23. package/dist/core/src/core/messages/internal-metadata.js +1 -1
  24. package/dist/core/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  25. package/dist/core/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  26. package/dist/core/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  27. package/dist/core/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  28. package/dist/core/src/core/messages/merge-messages.js +17 -28
  29. package/dist/core/src/core/messages/utils/is-valid-messages.js +22 -37
  30. package/dist/core/src/core/messages/utils/nest-object-from-path.js +5 -17
  31. package/dist/core/src/core/render/create-html-renderer.js +29 -37
  32. package/dist/core/src/core/render/utils/escape-html.js +1 -6
  33. package/dist/core/src/core/render/utils/render-attributes.js +6 -11
  34. package/dist/core/src/core/translator/create-t-rich.js +6 -15
  35. package/dist/core/src/core/translator/create-translator.js +16 -24
  36. package/dist/core/src/core/utils/deep-merge.js +24 -42
  37. package/dist/core/src/core/utils/normalizers/normalize-cache-key.js +14 -40
  38. package/dist/core/src/core/utils/normalizers/normalize-pathname.js +19 -37
  39. package/dist/core/src/core/utils/normalizers/normalize-query.js +6 -20
  40. package/dist/core/src/core/utils/parse-cookie-header.js +11 -18
  41. package/dist/core/src/core/utils/resolve-loader-options.js +6 -32
  42. package/dist/core/src/edge/helpers/get-translator.js +14 -20
  43. package/dist/core/src/edge/translator/init-translator.js +23 -31
  44. package/dist/core/src/routing/inbound/helpers/resolve-inbound-from-request.js +21 -28
  45. package/dist/core/src/routing/inbound/resolve-inbound.js +22 -37
  46. package/dist/core/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  47. package/dist/core/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  48. package/dist/core/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  49. package/dist/core/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  50. package/dist/core/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  51. package/dist/core/src/routing/locale/get-locale-from-accept-language.js +21 -36
  52. package/dist/core/src/routing/locale/get-locale-from-host.js +5 -28
  53. package/dist/core/src/routing/locale/get-locale-from-pathname.js +11 -37
  54. package/dist/core/src/routing/locale/get-locale-from-query.js +2 -17
  55. package/dist/core/src/routing/pathname/canonicalize-pathname.js +25 -67
  56. package/dist/core/src/routing/pathname/localize-pathname.js +12 -30
  57. package/dist/core/src/routing/pathname/materialize-pathname.js +9 -44
  58. package/dist/core/src/routing/pathname/standardize-pathname.js +6 -30
  59. package/dist/core/src/server/helpers/get-translator.js +26 -23
  60. package/dist/core/src/server/intor/intor.js +20 -25
  61. package/dist/core/src/server/messages/load-local-messages/cache/messages-pool.js +4 -7
  62. package/dist/core/src/server/messages/load-local-messages/load-local-messages.js +76 -92
  63. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +59 -80
  64. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +53 -87
  65. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/utils/json-reader.js +3 -6
  66. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/read-locale-messages.js +23 -35
  67. package/dist/core/src/server/messages/load-messages.js +56 -69
  68. package/dist/core/src/server/translator/init-translator.js +28 -30
  69. package/dist/express/src/adapters/express/create-intor-handler.js +35 -46
  70. package/dist/express/src/adapters/express/get-translator.js +2 -9
  71. package/dist/express/src/core/constants/locale-placeholder.js +0 -1
  72. package/dist/express/src/core/locale/canonicalize-locale.js +7 -18
  73. package/dist/express/src/core/locale/match-locale.js +24 -50
  74. package/dist/express/src/core/locale/parse-locale.js +12 -22
  75. package/dist/express/src/core/utils/normalizers/normalize-pathname.js +19 -37
  76. package/dist/express/src/core/utils/normalizers/normalize-query.js +6 -20
  77. package/dist/express/src/core/utils/parse-cookie-header.js +11 -18
  78. package/dist/express/src/routing/inbound/resolve-inbound.js +22 -37
  79. package/dist/express/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  80. package/dist/express/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  81. package/dist/express/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  82. package/dist/express/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  83. package/dist/express/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  84. package/dist/express/src/routing/locale/get-locale-from-accept-language.js +21 -36
  85. package/dist/express/src/routing/locale/get-locale-from-host.js +5 -28
  86. package/dist/express/src/routing/locale/get-locale-from-pathname.js +11 -37
  87. package/dist/express/src/routing/locale/get-locale-from-query.js +2 -17
  88. package/dist/express/src/routing/pathname/canonicalize-pathname.js +25 -67
  89. package/dist/express/src/routing/pathname/localize-pathname.js +12 -30
  90. package/dist/express/src/routing/pathname/materialize-pathname.js +9 -44
  91. package/dist/express/src/routing/pathname/standardize-pathname.js +6 -30
  92. package/dist/fastify/src/adapters/fastify/create-intor-handler.js +35 -47
  93. package/dist/fastify/src/adapters/fastify/get-translator.js +2 -9
  94. package/dist/fastify/src/adapters/fastify/intor-fastify-plugin.js +29 -38
  95. package/dist/fastify/src/core/constants/locale-placeholder.js +0 -1
  96. package/dist/fastify/src/core/locale/canonicalize-locale.js +7 -18
  97. package/dist/fastify/src/core/locale/match-locale.js +24 -50
  98. package/dist/fastify/src/core/locale/parse-locale.js +12 -22
  99. package/dist/fastify/src/core/utils/normalizers/normalize-pathname.js +19 -37
  100. package/dist/fastify/src/core/utils/normalizers/normalize-query.js +6 -20
  101. package/dist/fastify/src/core/utils/parse-cookie-header.js +11 -18
  102. package/dist/fastify/src/routing/inbound/resolve-inbound.js +22 -37
  103. package/dist/fastify/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  104. package/dist/fastify/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  105. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  106. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  107. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  108. package/dist/fastify/src/routing/locale/get-locale-from-accept-language.js +21 -36
  109. package/dist/fastify/src/routing/locale/get-locale-from-host.js +5 -28
  110. package/dist/fastify/src/routing/locale/get-locale-from-pathname.js +11 -37
  111. package/dist/fastify/src/routing/locale/get-locale-from-query.js +2 -17
  112. package/dist/fastify/src/routing/pathname/canonicalize-pathname.js +25 -67
  113. package/dist/fastify/src/routing/pathname/localize-pathname.js +12 -30
  114. package/dist/fastify/src/routing/pathname/materialize-pathname.js +9 -44
  115. package/dist/fastify/src/routing/pathname/standardize-pathname.js +6 -30
  116. package/dist/hono/src/adapters/hono/create-intor-handler.js +33 -44
  117. package/dist/hono/src/adapters/hono/get-translator.js +2 -9
  118. package/dist/hono/src/core/constants/locale-placeholder.js +0 -1
  119. package/dist/hono/src/core/locale/canonicalize-locale.js +7 -18
  120. package/dist/hono/src/core/locale/match-locale.js +24 -50
  121. package/dist/hono/src/core/locale/parse-locale.js +12 -22
  122. package/dist/hono/src/core/utils/normalizers/normalize-pathname.js +19 -37
  123. package/dist/hono/src/core/utils/normalizers/normalize-query.js +6 -20
  124. package/dist/hono/src/core/utils/parse-cookie-header.js +11 -18
  125. package/dist/hono/src/routing/inbound/resolve-inbound.js +22 -37
  126. package/dist/hono/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  127. package/dist/hono/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  128. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  129. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  130. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  131. package/dist/hono/src/routing/locale/get-locale-from-accept-language.js +21 -36
  132. package/dist/hono/src/routing/locale/get-locale-from-host.js +5 -28
  133. package/dist/hono/src/routing/locale/get-locale-from-pathname.js +11 -37
  134. package/dist/hono/src/routing/locale/get-locale-from-query.js +2 -17
  135. package/dist/hono/src/routing/pathname/canonicalize-pathname.js +25 -67
  136. package/dist/hono/src/routing/pathname/localize-pathname.js +12 -30
  137. package/dist/hono/src/routing/pathname/materialize-pathname.js +9 -44
  138. package/dist/hono/src/routing/pathname/standardize-pathname.js +6 -30
  139. package/dist/next/export/next/server/index.js +1 -0
  140. package/dist/next/src/adapters/next/create-intor-handler.js +39 -48
  141. package/dist/next/src/adapters/next/header-keys.js +9 -0
  142. package/dist/next/src/adapters/next/link.js +33 -28
  143. package/dist/next/src/adapters/next/redirect.js +12 -15
  144. package/dist/next/src/adapters/next/server/get-locale.js +13 -24
  145. package/dist/next/src/adapters/next/server/get-translator.js +2 -9
  146. package/dist/next/src/adapters/next/server/intor.js +5 -13
  147. package/dist/next/src/adapters/next/server/read-intor-url-state.js +13 -0
  148. package/dist/next/src/adapters/next/use-router.js +47 -66
  149. package/dist/next/src/client/shared/navigation/execute-navigation.js +20 -38
  150. package/dist/next/src/client/shared/utils/build-cookie-string.js +18 -27
  151. package/dist/next/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  152. package/dist/next/src/core/constants/locale-placeholder.js +0 -1
  153. package/dist/next/src/core/locale/canonicalize-locale.js +7 -18
  154. package/dist/next/src/core/locale/match-locale.js +24 -50
  155. package/dist/next/src/core/locale/parse-locale.js +12 -22
  156. package/dist/next/src/core/utils/normalizers/normalize-pathname.js +19 -37
  157. package/dist/next/src/core/utils/normalizers/normalize-query.js +6 -20
  158. package/dist/next/src/core/utils/resolve-loader-options.js +6 -29
  159. package/dist/next/src/policies/shoud-full-reload.js +2 -5
  160. package/dist/next/src/policies/should-sync-locale.js +1 -4
  161. package/dist/next/src/routing/inbound/resolve-inbound.js +24 -39
  162. package/dist/next/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  163. package/dist/next/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  164. package/dist/next/src/routing/inbound/resolve-pathname/strategies/all.js +13 -29
  165. package/dist/next/src/routing/inbound/resolve-pathname/strategies/except-default.js +14 -30
  166. package/dist/next/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  167. package/dist/next/src/routing/locale/get-locale-from-accept-language.js +21 -36
  168. package/dist/next/src/routing/locale/get-locale-from-host.js +5 -28
  169. package/dist/next/src/routing/locale/get-locale-from-pathname.js +11 -37
  170. package/dist/next/src/routing/locale/get-locale-from-query.js +2 -17
  171. package/dist/next/src/routing/outbound/decide-strategy.js +9 -9
  172. package/dist/next/src/routing/outbound/determine-target.js +28 -44
  173. package/dist/next/src/routing/outbound/resolve-outbound.js +12 -16
  174. package/dist/next/src/routing/outbound/utils/derive-host-destination.js +5 -9
  175. package/dist/next/src/routing/outbound/utils/derive-query-destination.js +4 -7
  176. package/dist/next/src/routing/outbound/utils/is-external-destination.js +1 -7
  177. package/dist/next/src/routing/pathname/canonicalize-pathname.js +25 -67
  178. package/dist/next/src/routing/pathname/localize-pathname.js +12 -30
  179. package/dist/next/src/routing/pathname/materialize-pathname.js +9 -44
  180. package/dist/next/src/routing/pathname/standardize-pathname.js +6 -30
  181. package/dist/react/src/client/react/helpers/use-intor.js +25 -44
  182. package/dist/react/src/client/react/provider/effects/use-locale-effects.js +20 -25
  183. package/dist/react/src/client/react/provider/effects/use-messages-effects.js +17 -16
  184. package/dist/react/src/client/react/provider/intor-provider.js +63 -66
  185. package/dist/react/src/client/react/provider/use-intor-context.js +4 -4
  186. package/dist/react/src/client/react/render/create-react-renderer.js +18 -24
  187. package/dist/react/src/client/react/translator/create-t-rich.js +9 -22
  188. package/dist/react/src/client/react/translator/use-translator.js +11 -16
  189. package/dist/react/src/client/shared/messages/create-refetch-messages.js +41 -51
  190. package/dist/react/src/client/shared/provider/effective-state.js +2 -6
  191. package/dist/react/src/client/shared/utils/build-cookie-string.js +18 -27
  192. package/dist/react/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  193. package/dist/react/src/client/shared/utils/locale/set-document-locale.js +2 -8
  194. package/dist/react/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  195. package/dist/react/src/core/logger/get-logger.js +26 -31
  196. package/dist/react/src/core/logger/global-logger-pool.js +4 -4
  197. package/dist/react/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  198. package/dist/react/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  199. package/dist/react/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  200. package/dist/react/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  201. package/dist/react/src/core/messages/merge-messages.js +17 -28
  202. package/dist/react/src/core/messages/utils/is-valid-messages.js +22 -37
  203. package/dist/react/src/core/messages/utils/nest-object-from-path.js +5 -17
  204. package/dist/react/src/core/utils/deep-merge.js +24 -42
  205. package/dist/react/src/core/utils/resolve-loader-options.js +6 -29
  206. package/dist/react/src/policies/should-persist-on-first-visit.js +1 -4
  207. package/dist/svelte/export/svelte/index.js +0 -6
  208. package/dist/svelte/src/client/shared/messages/create-refetch-messages.js +41 -51
  209. package/dist/svelte/src/client/shared/provider/effective-state.js +2 -6
  210. package/dist/svelte/src/client/shared/utils/build-cookie-string.js +18 -27
  211. package/dist/svelte/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  212. package/dist/svelte/src/client/shared/utils/locale/set-document-locale.js +2 -8
  213. package/dist/svelte/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  214. package/dist/svelte/src/client/svelte/provider/create-intor-store.js +59 -63
  215. package/dist/svelte/src/client/svelte/provider/effects/attach-locale-effects.js +20 -25
  216. package/dist/svelte/src/client/svelte/provider/effects/attach-messages-effects.js +21 -18
  217. package/dist/svelte/src/client/svelte/provider/get-intor-context.js +4 -4
  218. package/dist/svelte/src/client/svelte/translator/use-translator.js +11 -16
  219. package/dist/svelte/src/core/logger/get-logger.js +26 -31
  220. package/dist/svelte/src/core/logger/global-logger-pool.js +4 -4
  221. package/dist/svelte/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  222. package/dist/svelte/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  223. package/dist/svelte/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  224. package/dist/svelte/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  225. package/dist/svelte/src/core/messages/merge-messages.js +17 -28
  226. package/dist/svelte/src/core/messages/utils/is-valid-messages.js +22 -37
  227. package/dist/svelte/src/core/messages/utils/nest-object-from-path.js +5 -17
  228. package/dist/svelte/src/core/render/create-html-renderer.js +29 -37
  229. package/dist/svelte/src/core/render/utils/escape-html.js +1 -6
  230. package/dist/svelte/src/core/render/utils/render-attributes.js +6 -11
  231. package/dist/svelte/src/core/translator/create-t-rich.js +6 -15
  232. package/dist/svelte/src/core/utils/deep-merge.js +24 -42
  233. package/dist/svelte/src/core/utils/resolve-loader-options.js +6 -29
  234. package/dist/svelte/src/policies/should-persist-on-first-visit.js +1 -4
  235. package/dist/svelte-kit/src/adapters/svelte-kit/create-intor-handler.js +37 -57
  236. package/dist/svelte-kit/src/adapters/svelte-kit/use-navigation.js +29 -27
  237. package/dist/svelte-kit/src/adapters/svelte-kit/utils/is-svelte-kit-ssg.js +4 -11
  238. package/dist/svelte-kit/src/client/shared/navigation/execute-navigation.js +19 -37
  239. package/dist/svelte-kit/src/client/shared/utils/build-cookie-string.js +18 -27
  240. package/dist/svelte-kit/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  241. package/dist/svelte-kit/src/core/constants/locale-placeholder.js +0 -1
  242. package/dist/svelte-kit/src/core/locale/canonicalize-locale.js +7 -18
  243. package/dist/svelte-kit/src/core/locale/match-locale.js +24 -50
  244. package/dist/svelte-kit/src/core/locale/parse-locale.js +12 -22
  245. package/dist/svelte-kit/src/core/utils/normalizers/normalize-pathname.js +19 -37
  246. package/dist/svelte-kit/src/core/utils/normalizers/normalize-query.js +6 -20
  247. package/dist/svelte-kit/src/core/utils/resolve-loader-options.js +6 -29
  248. package/dist/svelte-kit/src/policies/shoud-full-reload.js +2 -5
  249. package/dist/svelte-kit/src/policies/should-sync-locale.js +1 -4
  250. package/dist/svelte-kit/src/routing/inbound/resolve-inbound.js +22 -37
  251. package/dist/svelte-kit/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  252. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  253. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  254. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  255. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  256. package/dist/svelte-kit/src/routing/locale/get-locale-from-accept-language.js +21 -36
  257. package/dist/svelte-kit/src/routing/locale/get-locale-from-host.js +5 -28
  258. package/dist/svelte-kit/src/routing/locale/get-locale-from-pathname.js +11 -37
  259. package/dist/svelte-kit/src/routing/locale/get-locale-from-query.js +2 -17
  260. package/dist/svelte-kit/src/routing/outbound/decide-strategy.js +9 -9
  261. package/dist/svelte-kit/src/routing/outbound/determine-target.js +28 -44
  262. package/dist/svelte-kit/src/routing/outbound/resolve-outbound.js +12 -16
  263. package/dist/svelte-kit/src/routing/outbound/utils/derive-host-destination.js +5 -9
  264. package/dist/svelte-kit/src/routing/outbound/utils/derive-query-destination.js +4 -7
  265. package/dist/svelte-kit/src/routing/outbound/utils/is-external-destination.js +1 -7
  266. package/dist/svelte-kit/src/routing/pathname/canonicalize-pathname.js +25 -67
  267. package/dist/svelte-kit/src/routing/pathname/localize-pathname.js +12 -30
  268. package/dist/svelte-kit/src/routing/pathname/materialize-pathname.js +9 -44
  269. package/dist/svelte-kit/src/routing/pathname/standardize-pathname.js +6 -30
  270. package/dist/types/export/index.d.ts +1 -1
  271. package/dist/types/export/index.d.ts.map +1 -1
  272. package/dist/types/export/next/server/index.d.ts +1 -1
  273. package/dist/types/export/next/server/index.d.ts.map +1 -1
  274. package/dist/types/src/adapters/fastify/intor-fastify-plugin.d.ts.map +1 -1
  275. package/dist/types/src/adapters/next/create-intor-handler.d.ts.map +1 -1
  276. package/dist/types/src/{core/constants/headers.d.ts → adapters/next/header-keys.d.ts} +3 -2
  277. package/dist/types/src/adapters/next/header-keys.d.ts.map +1 -0
  278. package/dist/types/src/adapters/next/server/get-locale.d.ts.map +1 -1
  279. package/dist/types/src/adapters/next/server/index.d.ts +1 -0
  280. package/dist/types/src/adapters/next/server/index.d.ts.map +1 -1
  281. package/dist/types/src/adapters/next/server/read-intor-url-state.d.ts +13 -0
  282. package/dist/types/src/adapters/next/server/read-intor-url-state.d.ts.map +1 -0
  283. package/dist/types/src/core/constants/index.d.ts +0 -1
  284. package/dist/types/src/core/constants/index.d.ts.map +1 -1
  285. package/dist/types/src/core/constants/locale-placeholder.d.ts +5 -0
  286. package/dist/types/src/core/constants/locale-placeholder.d.ts.map +1 -1
  287. package/dist/types/src/core/index.d.ts +1 -1
  288. package/dist/types/src/core/index.d.ts.map +1 -1
  289. package/dist/types/src/edge/translator/init-translator.d.ts.map +1 -1
  290. package/dist/types/src/routing/outbound/decide-strategy.d.ts +1 -1
  291. package/dist/types/src/routing/outbound/decide-strategy.d.ts.map +1 -1
  292. package/dist/types/src/server/translator/init-translator.d.ts.map +1 -1
  293. package/dist/vue/src/client/shared/messages/create-refetch-messages.js +41 -51
  294. package/dist/vue/src/client/shared/provider/effective-state.js +2 -6
  295. package/dist/vue/src/client/shared/utils/build-cookie-string.js +18 -27
  296. package/dist/vue/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  297. package/dist/vue/src/client/shared/utils/locale/set-document-locale.js +2 -8
  298. package/dist/vue/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  299. package/dist/vue/src/client/vue/helpers/use-intor.js +20 -42
  300. package/dist/vue/src/client/vue/provider/effects/use-locale-effects.js +23 -24
  301. package/dist/vue/src/client/vue/provider/effects/use-messages-effects.js +15 -24
  302. package/dist/vue/src/client/vue/provider/inject-intor-context.js +4 -4
  303. package/dist/vue/src/client/vue/provider/intor-provider.js +61 -66
  304. package/dist/vue/src/client/vue/render/create-vue-renderer.js +18 -24
  305. package/dist/vue/src/client/vue/translator/create-t-rich.js +5 -17
  306. package/dist/vue/src/client/vue/translator/trans.js +24 -31
  307. package/dist/vue/src/client/vue/translator/use-translator.js +12 -17
  308. package/dist/vue/src/core/logger/get-logger.js +26 -31
  309. package/dist/vue/src/core/logger/global-logger-pool.js +4 -4
  310. package/dist/vue/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  311. package/dist/vue/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  312. package/dist/vue/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  313. package/dist/vue/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  314. package/dist/vue/src/core/messages/merge-messages.js +17 -28
  315. package/dist/vue/src/core/messages/utils/is-valid-messages.js +22 -37
  316. package/dist/vue/src/core/messages/utils/nest-object-from-path.js +5 -17
  317. package/dist/vue/src/core/utils/deep-merge.js +24 -42
  318. package/dist/vue/src/core/utils/resolve-loader-options.js +6 -29
  319. package/dist/vue/src/policies/should-persist-on-first-visit.js +1 -4
  320. package/package.json +53 -65
  321. package/dist/next/src/core/constants/headers.js +0 -8
  322. package/dist/types/src/core/constants/headers.d.ts.map +0 -1
@@ -4,73 +4,68 @@ import { resolveEffectiveIsLoading, resolveEffectiveMessages } from '../../share
4
4
  import { useLocaleEffects } from './effects/use-locale-effects.js';
5
5
  import { useMessagesEffects } from './effects/use-messages-effects.js';
6
6
 
7
- const IntorContextKey = Symbol("IntorContext");
8
- /**
9
- * Vue provider for Intor.
10
- *
11
- * @public
12
- */
7
+ const IntorContextKey = /* @__PURE__ */ Symbol("IntorContext");
13
8
  const IntorProvider = defineComponent({
14
- name: "IntorProvider",
15
- props: { value: { type: Object, required: true } },
16
- setup(props, { slots }) {
17
- // ---------------------------------------------------------------------------
18
- // Internal state
19
- // ---------------------------------------------------------------------------
20
- const locale = ref(props.value.locale);
21
- const runtimeMessages = ref(null);
22
- const internalIsLoading = ref(false);
23
- // ---------------------------------------------------------------------------
24
- // Locale transition
25
- // ---------------------------------------------------------------------------
26
- /** Request a locale change. */
27
- const setLocale = (newLocale) => {
28
- if (newLocale === locale.value)
29
- return;
30
- locale.value = newLocale;
31
- void props.value.onLocaleChange?.(newLocale); // Notify external listener (fire-and-forget)
32
- };
33
- // ---------------------------------------------------------------------------
34
- // Effective state
35
- // ---------------------------------------------------------------------------
36
- const effectiveIsLoading = computed(() => resolveEffectiveIsLoading(!!props.value.isLoading?.value, internalIsLoading.value));
37
- const effectiveMessages = computed(() => resolveEffectiveMessages(runtimeMessages.value, props.value.messages?.value, props.value.config.messages));
38
- // ---------------------------------------------------------------------------
39
- // Translator
40
- // ---------------------------------------------------------------------------
41
- const { loadingMessage, missingMessage } = props.value.config.translator ?? {};
42
- const { handlers, hooks } = props.value;
43
- const translator = computed(() => {
44
- return new Translator({
45
- messages: effectiveMessages.value,
46
- locale: locale.value,
47
- isLoading: effectiveIsLoading.value,
48
- fallbackLocales: props.value.config.fallbackLocales,
49
- ...(loadingMessage !== undefined ? { loadingMessage } : {}),
50
- ...(missingMessage !== undefined ? { missingMessage } : {}),
51
- ...(handlers !== undefined ? { handlers } : {}),
52
- ...(hooks !== undefined ? { hooks } : {}),
53
- });
54
- });
55
- // -------------------------------------------------------------------------
56
- // Side effects
57
- // -------------------------------------------------------------------------
58
- useLocaleEffects(props.value.config, locale);
59
- useMessagesEffects(props.value.config, locale, runtimeMessages, internalIsLoading);
60
- // Sync internal locale with external prop
61
- watch(() => props.value.locale, (newLocale) => {
62
- if (newLocale !== locale.value)
63
- locale.value = newLocale;
64
- });
65
- const contextValue = computed(() => ({
66
- config: props.value.config,
67
- locale,
68
- setLocale,
69
- translator,
70
- }));
71
- provide(IntorContextKey, contextValue);
72
- return () => slots["default"]?.();
73
- },
9
+ name: "IntorProvider",
10
+ props: { value: { type: Object, required: true } },
11
+ setup(props, { slots }) {
12
+ const locale = ref(props.value.locale);
13
+ const runtimeMessages = ref(null);
14
+ const internalIsLoading = ref(false);
15
+ const setLocale = (newLocale) => {
16
+ if (newLocale === locale.value) return;
17
+ locale.value = newLocale;
18
+ void props.value.onLocaleChange?.(newLocale);
19
+ };
20
+ const effectiveIsLoading = computed(
21
+ () => resolveEffectiveIsLoading(
22
+ !!props.value.isLoading?.value,
23
+ internalIsLoading.value
24
+ )
25
+ );
26
+ const effectiveMessages = computed(
27
+ () => resolveEffectiveMessages(
28
+ runtimeMessages.value,
29
+ props.value.messages?.value,
30
+ props.value.config.messages
31
+ )
32
+ );
33
+ const { loadingMessage, missingMessage } = props.value.config.translator ?? {};
34
+ const { handlers, hooks } = props.value;
35
+ const translator = computed(() => {
36
+ return new Translator({
37
+ messages: effectiveMessages.value,
38
+ locale: locale.value,
39
+ isLoading: effectiveIsLoading.value,
40
+ fallbackLocales: props.value.config.fallbackLocales,
41
+ ...loadingMessage !== void 0 ? { loadingMessage } : {},
42
+ ...missingMessage !== void 0 ? { missingMessage } : {},
43
+ ...handlers !== void 0 ? { handlers } : {},
44
+ ...hooks !== void 0 ? { hooks } : {}
45
+ });
46
+ });
47
+ useLocaleEffects(props.value.config, locale);
48
+ useMessagesEffects(
49
+ props.value.config,
50
+ locale,
51
+ runtimeMessages,
52
+ internalIsLoading
53
+ );
54
+ watch(
55
+ () => props.value.locale,
56
+ (newLocale) => {
57
+ if (newLocale !== locale.value) locale.value = newLocale;
58
+ }
59
+ );
60
+ const contextValue = computed(() => ({
61
+ config: props.value.config,
62
+ locale,
63
+ setLocale,
64
+ translator
65
+ }));
66
+ provide(IntorContextKey, contextValue);
67
+ return () => slots["default"]?.();
68
+ }
74
69
  });
75
70
 
76
71
  export { IntorContextKey, IntorProvider };
@@ -1,30 +1,24 @@
1
1
  import { h } from 'vue';
2
2
 
3
- /**
4
- * Create a Vue renderer for semantic rich messages.
5
- */
6
3
  const createVueRenderer = (tagRenderers) => {
7
- return {
8
- /** Render plain text nodes */
9
- text(value) {
10
- return value;
11
- },
12
- /** Render semantic tag nodes */
13
- tag(name, _attributes, children) {
14
- const tagRenderer = tagRenderers?.[name];
15
- if (tagRenderer) {
16
- return typeof tagRenderer === "function"
17
- ? tagRenderer(children)
18
- : tagRenderer;
19
- }
20
- // Default behavior: render as a native Vue element
21
- return h(name, null, children);
22
- },
23
- /** Render raw (non-tokenized) message values */
24
- raw(value) {
25
- return value;
26
- },
27
- };
4
+ return {
5
+ /** Render plain text nodes */
6
+ text(value) {
7
+ return value;
8
+ },
9
+ /** Render semantic tag nodes */
10
+ tag(name, _attributes, children) {
11
+ const tagRenderer = tagRenderers?.[name];
12
+ if (tagRenderer) {
13
+ return typeof tagRenderer === "function" ? tagRenderer(children) : tagRenderer;
14
+ }
15
+ return h(name, null, children);
16
+ },
17
+ /** Render raw (non-tokenized) message values */
18
+ raw(value) {
19
+ return value;
20
+ }
21
+ };
28
22
  };
29
23
 
30
24
  export { createVueRenderer };
@@ -1,24 +1,12 @@
1
1
  import { renderRichMessage } from 'intor-translator';
2
2
  import { createVueRenderer } from '../render/create-vue-renderer.js';
3
3
 
4
- /**
5
- * Create a Vue-specific rich translation function.
6
- *
7
- * This adapter bridges the core Translator with the Vue rich
8
- * message rendering flow.
9
- *
10
- * - Resolves translated messages via `translator.t`
11
- * - Renders semantic tags using Vue renderers
12
- * - Supports optional scoped keys via `preKey`
13
- *
14
- * Intended for Vue client usage only.
15
- */
16
4
  const createTRich = (t) => {
17
- return (key, tagRenderers, replacements) => {
18
- const message = t(key, replacements);
19
- const vueRenderer = createVueRenderer(tagRenderers);
20
- return renderRichMessage(message, vueRenderer);
21
- };
5
+ return (key, tagRenderers, replacements) => {
6
+ const message = t(key, replacements);
7
+ const vueRenderer = createVueRenderer(tagRenderers);
8
+ return renderRichMessage(message, vueRenderer);
9
+ };
22
10
  };
23
11
 
24
12
  export { createTRich };
@@ -1,40 +1,33 @@
1
1
  import { defineComponent, h, Fragment } from 'vue';
2
2
  import { useTranslator } from './use-translator.js';
3
3
 
4
- /**
5
- * Vue component for rendering rich translations.
6
- *
7
- * A thin wrapper around `tRich`.
8
- *
9
- * @public
10
- */
11
4
  const Trans = defineComponent({
12
- name: "Trans",
13
- props: {
14
- /** The message key to translate. */
15
- i18nKey: {
16
- type: String,
17
- required: true,
18
- },
19
- /** Optional Vue renderers for semantic tags. */
20
- components: {
21
- type: Object,
22
- required: false,
23
- },
24
- /** Optional replacement values for interpolation. */
25
- values: {
26
- type: Object,
27
- required: false,
28
- },
5
+ name: "Trans",
6
+ props: {
7
+ /** The message key to translate. */
8
+ i18nKey: {
9
+ type: String,
10
+ required: true
29
11
  },
30
- setup(props) {
31
- const { tRich } = useTranslator();
32
- return () => {
33
- const { i18nKey, components, values } = props;
34
- const nodes = tRich(i18nKey, components, values);
35
- return h(Fragment, null, nodes);
36
- };
12
+ /** Optional Vue renderers for semantic tags. */
13
+ components: {
14
+ type: Object,
15
+ required: false
37
16
  },
17
+ /** Optional replacement values for interpolation. */
18
+ values: {
19
+ type: Object,
20
+ required: false
21
+ }
22
+ },
23
+ setup(props) {
24
+ const { tRich } = useTranslator();
25
+ return () => {
26
+ const { i18nKey, components, values } = props;
27
+ const nodes = tRich(i18nKey, components, values);
28
+ return h(Fragment, null, nodes);
29
+ };
30
+ }
38
31
  });
39
32
 
40
33
  export { Trans };
@@ -3,24 +3,19 @@ import '../provider/intor-provider.js';
3
3
  import { injectIntorContext } from '../provider/inject-intor-context.js';
4
4
  import { createTRich } from './create-t-rich.js';
5
5
 
6
- /**
7
- * Vue composable for accessing the active, scope-aware translator instance.
8
- *
9
- * @public
10
- */
11
6
  function useTranslator(preKey) {
12
- const intor = injectIntorContext();
13
- const translator = intor.value.translator;
14
- const scoped = computed(() => translator.value.scoped(preKey));
15
- return {
16
- messages: computed(() => translator.value.messages),
17
- locale: computed(() => translator.value.locale),
18
- isLoading: computed(() => translator.value.isLoading),
19
- setLocale: intor.value.setLocale,
20
- hasKey: (...args) => scoped.value.hasKey(...args),
21
- t: (...args) => scoped.value.t(...args),
22
- tRich: (...args) => createTRich(scoped.value.t)(...args),
23
- };
7
+ const intor = injectIntorContext();
8
+ const translator = intor.value.translator;
9
+ const scoped = computed(() => translator.value.scoped(preKey));
10
+ return {
11
+ messages: computed(() => translator.value.messages),
12
+ locale: computed(() => translator.value.locale),
13
+ isLoading: computed(() => translator.value.isLoading),
14
+ setLocale: intor.value.setLocale,
15
+ hasKey: (...args) => scoped.value.hasKey(...args),
16
+ t: (...args) => scoped.value.t(...args),
17
+ tRich: (...args) => createTRich(scoped.value.t)(...args)
18
+ };
24
19
  }
25
20
 
26
21
  export { useTranslator };
@@ -2,41 +2,36 @@ import { logry } from 'logry';
2
2
  import { getGlobalLoggerPool } from './global-logger-pool.js';
3
3
 
4
4
  const DEFAULT_FORMAT_CONFIG = {
5
- timestamp: { withDate: false },
5
+ timestamp: { withDate: false }
6
6
  };
7
7
  const DEFAULT_RENDER_CONFIG = {
8
- id: { visible: true, prefix: "<", suffix: ">" },
9
- meta: { lineBreaksAfter: 1 },
8
+ id: { visible: true, prefix: "<", suffix: ">" },
9
+ meta: { lineBreaksAfter: 1 }
10
10
  };
11
- /**
12
- * Get a shared logger instance by id.
13
- * - Safe across hot reloads
14
- * - Prevents unbounded memory usage via soft LRU
15
- */
16
- function getLogger({ id = "default", preset, ...options }) {
17
- const pool = getGlobalLoggerPool();
18
- const existing = pool.get(id);
19
- if (existing)
20
- return existing;
21
- const baseConfig = preset === undefined
22
- ? {
23
- formatConfig: DEFAULT_FORMAT_CONFIG,
24
- renderConfig: DEFAULT_RENDER_CONFIG,
25
- }
26
- : { preset };
27
- const logger = logry({
28
- id,
29
- ...baseConfig,
30
- ...options,
31
- });
32
- pool.set(id, logger);
33
- // Soft LRU: keep pool size under control
34
- if (pool.size > 1000) {
35
- for (const key of [...pool.keys()].slice(0, 200)) {
36
- pool.delete(key);
37
- }
11
+ function getLogger({
12
+ id = "default",
13
+ preset,
14
+ ...options
15
+ }) {
16
+ const pool = getGlobalLoggerPool();
17
+ const existing = pool.get(id);
18
+ if (existing) return existing;
19
+ const baseConfig = preset === void 0 ? {
20
+ formatConfig: DEFAULT_FORMAT_CONFIG,
21
+ renderConfig: DEFAULT_RENDER_CONFIG
22
+ } : { preset };
23
+ const logger = logry({
24
+ id,
25
+ ...baseConfig,
26
+ ...options
27
+ });
28
+ pool.set(id, logger);
29
+ if (pool.size > 1e3) {
30
+ for (const key of [...pool.keys()].slice(0, 200)) {
31
+ pool.delete(key);
38
32
  }
39
- return logger;
33
+ }
34
+ return logger;
40
35
  }
41
36
 
42
37
  export { getLogger };
@@ -1,8 +1,8 @@
1
1
  function getGlobalLoggerPool() {
2
- if (!globalThis.__INTOR_LOGGER_POOL__) {
3
- globalThis.__INTOR_LOGGER_POOL__ = new Map();
4
- }
5
- return globalThis.__INTOR_LOGGER_POOL__;
2
+ if (!globalThis.__INTOR_LOGGER_POOL__) {
3
+ globalThis.__INTOR_LOGGER_POOL__ = /* @__PURE__ */ new Map();
4
+ }
5
+ return globalThis.__INTOR_LOGGER_POOL__;
6
6
  }
7
7
 
8
8
  export { getGlobalLoggerPool };
@@ -1,25 +1,16 @@
1
- /**
2
- * Collect remote message resources for a given locale.
3
- *
4
- * - Always includes the root `index.json`
5
- * - Optionally includes namespace-specific resources
6
- * - Produces semantic paths for later message nesting
7
- *
8
- * This function performs no I/O and does not validate resource existence.
9
- */
10
- function collectRemoteResources({ locale, baseUrl, namespaces, }) {
11
- const basePath = `${baseUrl}/${locale}`;
12
- // Root translation resource (always loaded)
13
- const indexResource = { url: `${basePath}/index.json`, path: [] };
14
- // When no namespaces are provided, the locale domain consists of index only
15
- if (!namespaces || namespaces.length === 0)
16
- return [indexResource];
17
- // Namespace-specific resources are nested under their namespace key
18
- const nsResources = namespaces.map((ns) => ({
19
- url: `${basePath}/${ns}.json`,
20
- path: [ns],
21
- }));
22
- return [indexResource, ...nsResources];
1
+ function collectRemoteResources({
2
+ locale,
3
+ baseUrl,
4
+ namespaces
5
+ }) {
6
+ const basePath = `${baseUrl}/${locale}`;
7
+ const indexResource = { url: `${basePath}/index.json`, path: [] };
8
+ if (!namespaces || namespaces.length === 0) return [indexResource];
9
+ const nsResources = namespaces.map((ns) => ({
10
+ url: `${basePath}/${ns}.json`,
11
+ path: [ns]
12
+ }));
13
+ return [indexResource, ...nsResources];
23
14
  }
24
15
 
25
16
  export { collectRemoteResources };
@@ -1,47 +1,38 @@
1
1
  import { getLogger } from '../../logger/get-logger.js';
2
2
  import { isValidMessages } from '../utils/is-valid-messages.js';
3
3
 
4
- /**
5
- * Fetch a single remote messages resource.
6
- *
7
- * This function performs a single HTTP request to retrieve
8
- * a remote translation messages payload.
9
- *
10
- * It is responsible for:
11
- * - Issuing the network request
12
- * - Validating the returned message structure
13
- * - Handling abort and network errors
14
- */
15
- async function fetchRemoteResource({ fetch, url, headers, signal, loggerOptions, }) {
16
- const baseLogger = getLogger(loggerOptions);
17
- const logger = baseLogger.child({ scope: "fetch-locale-messages" });
18
- try {
19
- // Fetch
20
- const response = await fetch(url, {
21
- method: "GET",
22
- headers: { "Content-Type": "application/json", ...headers },
23
- cache: "no-store",
24
- ...(signal !== undefined ? { signal } : {}),
25
- });
26
- if (!response.ok) {
27
- throw new Error(`HTTP ${response.status} ${response.statusText}`);
28
- }
29
- // Parse JSON body
30
- const data = (await response.json());
31
- // Validate messages structure
32
- if (!isValidMessages(data)) {
33
- throw new Error("Invalid messages structure");
34
- }
35
- return data;
4
+ async function fetchRemoteResource({
5
+ fetch,
6
+ url,
7
+ headers,
8
+ signal,
9
+ loggerOptions
10
+ }) {
11
+ const baseLogger = getLogger(loggerOptions);
12
+ const logger = baseLogger.child({ scope: "fetch-locale-messages" });
13
+ try {
14
+ const response = await fetch(url, {
15
+ method: "GET",
16
+ headers: { "Content-Type": "application/json", ...headers },
17
+ cache: "no-store",
18
+ ...signal !== void 0 ? { signal } : {}
19
+ });
20
+ if (!response.ok) {
21
+ throw new Error(`HTTP ${response.status} ${response.statusText}`);
36
22
  }
37
- catch (error) {
38
- if (error instanceof Error && error.name === "AbortError") {
39
- logger.debug("Remote fetch aborted.", { url });
40
- return;
41
- }
42
- logger.warn("Failed to fetch remote messages.", { url, error });
43
- return;
23
+ const data = await response.json();
24
+ if (!isValidMessages(data)) {
25
+ throw new Error("Invalid messages structure");
44
26
  }
27
+ return data;
28
+ } catch (error) {
29
+ if (error instanceof Error && error.name === "AbortError") {
30
+ logger.debug("Remote fetch aborted.", { url });
31
+ return;
32
+ }
33
+ logger.warn("Failed to fetch remote messages.", { url, error });
34
+ return;
35
+ }
45
36
  }
46
37
 
47
38
  export { fetchRemoteResource };