use-intl 3.0.0-beta.2 → 3.0.0-beta.3

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 (204) hide show
  1. package/_IntlProvider.d.ts +1 -0
  2. package/_useLocale.d.ts +1 -0
  3. package/core.d.ts +1 -1
  4. package/dist/_IntlProvider.js +7 -0
  5. package/dist/_useLocale.js +7 -0
  6. package/dist/core.js +3 -4
  7. package/dist/development/IntlContext-b5cc6be8.js +8 -0
  8. package/dist/development/_IntlProvider.js +27 -0
  9. package/dist/development/_useLocale-321e619f.js +19 -0
  10. package/dist/development/_useLocale.js +11 -0
  11. package/dist/development/core.js +92 -0
  12. package/dist/development/createIntl-dfba4462.js +421 -0
  13. package/dist/development/index.js +31 -0
  14. package/dist/development/initializeConfig-cde42612.js +119 -0
  15. package/dist/development/react.js +160 -0
  16. package/dist/esm/IntlContext-381f3ce4.js +1 -0
  17. package/dist/esm/_IntlProvider.js +1 -0
  18. package/dist/esm/_useLocale-89b32eb9.js +1 -0
  19. package/dist/esm/_useLocale.js +1 -0
  20. package/dist/esm/core.js +1 -0
  21. package/dist/esm/createIntl-164a7766.js +1 -0
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/initializeConfig-c316f266.js +1 -0
  24. package/dist/esm/react.js +1 -0
  25. package/dist/index.js +3 -4
  26. package/dist/production/IntlContext-381f3ce4.js +1 -0
  27. package/dist/production/_IntlProvider.js +1 -0
  28. package/dist/production/_useLocale-8e23751a.js +1 -0
  29. package/dist/production/_useLocale.js +1 -0
  30. package/dist/production/core.js +1 -0
  31. package/dist/production/createIntl-e408cd5c.js +1 -0
  32. package/dist/production/index.js +1 -0
  33. package/dist/production/initializeConfig-984a566d.js +1 -0
  34. package/dist/production/react.js +1 -0
  35. package/dist/react.js +3 -4
  36. package/dist/types/src/_IntlProvider.d.ts +1 -0
  37. package/dist/types/src/_useLocale.d.ts +1 -0
  38. package/dist/{core → types/src/core}/AbstractIntlMessages.d.ts +9 -9
  39. package/dist/{core → types/src/core}/DateTimeFormatOptions.d.ts +73 -73
  40. package/dist/{core → types/src/core}/Formats.d.ts +8 -8
  41. package/dist/{core → types/src/core}/IntlConfig.d.ts +54 -54
  42. package/dist/{core → types/src/core}/IntlError.d.ts +13 -13
  43. package/dist/{core → types/src/core}/MessageFormatCache.d.ts +5 -5
  44. package/dist/{core → types/src/core}/NumberFormatOptions.d.ts +2 -2
  45. package/dist/{core → types/src/core}/TimeZone.d.ts +2 -2
  46. package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -6
  47. package/dist/{core → types/src/core}/convertFormatsToIntlMessageFormat.d.ts +11 -11
  48. package/dist/{core → types/src/core}/createBaseTranslator.d.ts +21 -21
  49. package/dist/{core → types/src/core}/createFormatter.d.ts +19 -19
  50. package/dist/{core → types/src/core}/createIntl.d.ts +7 -7
  51. package/dist/{core → types/src/core}/createTranslator.d.ts +47 -47
  52. package/dist/{core → types/src/core}/createTranslatorImpl.d.ts +13 -13
  53. package/dist/{core → types/src/core}/defaults.d.ts +11 -11
  54. package/dist/{core → types/src/core}/index.d.ts +16 -16
  55. package/dist/{core → types/src/core}/initializeConfig.d.ts +14 -13
  56. package/dist/{core → types/src/core}/resolveNamespace.d.ts +5 -5
  57. package/dist/{core → types/src/core}/utils/MessageKeys.d.ts +5 -5
  58. package/dist/{core → types/src/core}/utils/NamespaceKeys.d.ts +5 -5
  59. package/dist/{core → types/src/core}/utils/NestedKeyOf.d.ts +4 -4
  60. package/dist/{core → types/src/core}/utils/NestedValueOf.d.ts +2 -2
  61. package/dist/{core → types/src/core}/validateMessages.d.ts +3 -3
  62. package/dist/{core.d.ts → types/src/core.d.ts} +1 -1
  63. package/dist/{index.d.ts → types/src/index.d.ts} +2 -2
  64. package/dist/{react → types/src/react}/IntlContext.d.ts +13 -13
  65. package/dist/{react → types/src/react}/IntlProvider.d.ts +7 -7
  66. package/dist/{react → types/src/react}/getInitializedConfig.d.ts +1 -1
  67. package/dist/{react → types/src/react}/index.d.ts +8 -8
  68. package/dist/{react → types/src/react}/useFormatter.d.ts +6 -6
  69. package/dist/{react → types/src/react}/useIntl.d.ts +6 -6
  70. package/dist/{react → types/src/react}/useIntlContext.d.ts +10 -10
  71. package/dist/{react → types/src/react}/useLocale.d.ts +1 -1
  72. package/dist/{react → types/src/react}/useMessages.d.ts +1 -1
  73. package/dist/{react → types/src/react}/useNow.d.ts +23 -23
  74. package/dist/{react → types/src/react}/useTimeZone.d.ts +1 -1
  75. package/dist/{react → types/src/react}/useTranslations.d.ts +44 -44
  76. package/dist/{react → types/src/react}/useTranslationsImpl.d.ts +8 -8
  77. package/dist/{react.d.ts → types/src/react.d.ts} +1 -1
  78. package/dist/types/test/core/createFormatter.test.d.ts +1 -0
  79. package/dist/types/test/core/createIntl.test.d.ts +1 -0
  80. package/dist/types/test/core/createTranslator.test.d.ts +1 -0
  81. package/dist/types/test/react/useFormatter.test.d.ts +1 -0
  82. package/dist/types/test/react/useIntl.test.d.ts +1 -0
  83. package/dist/types/test/react/useLocale.test.d.ts +1 -0
  84. package/dist/types/test/react/useMessages.test.d.ts +1 -0
  85. package/dist/types/test/react/useNow.test.d.ts +1 -0
  86. package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
  87. package/dist/types/test/react/useTranslations.test.d.ts +1 -0
  88. package/dist/{test → types/test}/setup.d.ts +1 -1
  89. package/package.json +33 -21
  90. package/react.d.ts +1 -1
  91. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +0 -102
  92. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  93. package/dist/_virtual/use-intl.esm.js +0 -102
  94. package/dist/_virtual/use-intl.esm.js.map +0 -1
  95. package/dist/core/IntlError.esm.js +0 -33
  96. package/dist/core/IntlError.esm.js.map +0 -1
  97. package/dist/core/convertFormatsToIntlMessageFormat.esm.js +0 -37
  98. package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +0 -1
  99. package/dist/core/createBaseTranslator.esm.js +0 -210
  100. package/dist/core/createBaseTranslator.esm.js.map +0 -1
  101. package/dist/core/createFormatter.esm.js +0 -138
  102. package/dist/core/createFormatter.esm.js.map +0 -1
  103. package/dist/core/createIntl.esm.js +0 -14
  104. package/dist/core/createIntl.esm.js.map +0 -1
  105. package/dist/core/createTranslator.esm.js +0 -37
  106. package/dist/core/createTranslator.esm.js.map +0 -1
  107. package/dist/core/createTranslatorImpl.esm.js +0 -50
  108. package/dist/core/createTranslatorImpl.esm.js.map +0 -1
  109. package/dist/core/defaults.esm.js +0 -15
  110. package/dist/core/defaults.esm.js.map +0 -1
  111. package/dist/core/initializeConfig.esm.js +0 -29
  112. package/dist/core/initializeConfig.esm.js.map +0 -1
  113. package/dist/core/resolveNamespace.esm.js +0 -10
  114. package/dist/core/resolveNamespace.esm.js.map +0 -1
  115. package/dist/core/use-intl.esm.js +0 -33
  116. package/dist/core/use-intl.esm.js.map +0 -1
  117. package/dist/core/use-intl.esm10.js +0 -28
  118. package/dist/core/use-intl.esm10.js.map +0 -1
  119. package/dist/core/use-intl.esm11.js +0 -10
  120. package/dist/core/use-intl.esm11.js.map +0 -1
  121. package/dist/core/use-intl.esm2.js +0 -210
  122. package/dist/core/use-intl.esm2.js.map +0 -1
  123. package/dist/core/use-intl.esm3.js +0 -37
  124. package/dist/core/use-intl.esm3.js.map +0 -1
  125. package/dist/core/use-intl.esm4.js +0 -14
  126. package/dist/core/use-intl.esm4.js.map +0 -1
  127. package/dist/core/use-intl.esm5.js +0 -29
  128. package/dist/core/use-intl.esm5.js.map +0 -1
  129. package/dist/core/use-intl.esm6.js +0 -138
  130. package/dist/core/use-intl.esm6.js.map +0 -1
  131. package/dist/core/use-intl.esm7.js +0 -37
  132. package/dist/core/use-intl.esm7.js.map +0 -1
  133. package/dist/core/use-intl.esm8.js +0 -15
  134. package/dist/core/use-intl.esm8.js.map +0 -1
  135. package/dist/core/use-intl.esm9.js +0 -50
  136. package/dist/core/use-intl.esm9.js.map +0 -1
  137. package/dist/core/validateMessages.esm.js +0 -28
  138. package/dist/core/validateMessages.esm.js.map +0 -1
  139. package/dist/core.cjs.development.js +0 -93
  140. package/dist/core.cjs.development.js.map +0 -1
  141. package/dist/core.cjs.production.min.js +0 -2
  142. package/dist/core.cjs.production.min.js.map +0 -1
  143. package/dist/core.esm.js +0 -7
  144. package/dist/core.esm.js.map +0 -1
  145. package/dist/createIntl-34d4281e.js +0 -592
  146. package/dist/createIntl-34d4281e.js.map +0 -1
  147. package/dist/createIntl-bc325740.js +0 -2
  148. package/dist/createIntl-bc325740.js.map +0 -1
  149. package/dist/react/IntlContext.esm.js +0 -6
  150. package/dist/react/IntlContext.esm.js.map +0 -1
  151. package/dist/react/IntlProvider.esm.js +0 -22
  152. package/dist/react/IntlProvider.esm.js.map +0 -1
  153. package/dist/react/use-intl.esm.js +0 -26
  154. package/dist/react/use-intl.esm.js.map +0 -1
  155. package/dist/react/use-intl.esm10.js +0 -13
  156. package/dist/react/use-intl.esm10.js.map +0 -1
  157. package/dist/react/use-intl.esm11.js +0 -6
  158. package/dist/react/use-intl.esm11.js.map +0 -1
  159. package/dist/react/use-intl.esm2.js +0 -8
  160. package/dist/react/use-intl.esm2.js.map +0 -1
  161. package/dist/react/use-intl.esm3.js +0 -30
  162. package/dist/react/use-intl.esm3.js.map +0 -1
  163. package/dist/react/use-intl.esm4.js +0 -22
  164. package/dist/react/use-intl.esm4.js.map +0 -1
  165. package/dist/react/use-intl.esm5.js +0 -24
  166. package/dist/react/use-intl.esm5.js.map +0 -1
  167. package/dist/react/use-intl.esm6.js +0 -45
  168. package/dist/react/use-intl.esm6.js.map +0 -1
  169. package/dist/react/use-intl.esm7.js +0 -8
  170. package/dist/react/use-intl.esm7.js.map +0 -1
  171. package/dist/react/use-intl.esm8.js +0 -8
  172. package/dist/react/use-intl.esm8.js.map +0 -1
  173. package/dist/react/use-intl.esm9.js +0 -36
  174. package/dist/react/use-intl.esm9.js.map +0 -1
  175. package/dist/react/useFormatter.esm.js +0 -24
  176. package/dist/react/useFormatter.esm.js.map +0 -1
  177. package/dist/react/useIntl.esm.js +0 -30
  178. package/dist/react/useIntl.esm.js.map +0 -1
  179. package/dist/react/useIntlContext.esm.js +0 -13
  180. package/dist/react/useIntlContext.esm.js.map +0 -1
  181. package/dist/react/useLocale.esm.js +0 -8
  182. package/dist/react/useLocale.esm.js.map +0 -1
  183. package/dist/react/useMessages.esm.js +0 -8
  184. package/dist/react/useMessages.esm.js.map +0 -1
  185. package/dist/react/useNow.esm.js +0 -45
  186. package/dist/react/useNow.esm.js.map +0 -1
  187. package/dist/react/useTimeZone.esm.js +0 -8
  188. package/dist/react/useTimeZone.esm.js.map +0 -1
  189. package/dist/react/useTranslations.esm.js +0 -26
  190. package/dist/react/useTranslations.esm.js.map +0 -1
  191. package/dist/react/useTranslationsImpl.esm.js +0 -36
  192. package/dist/react/useTranslationsImpl.esm.js.map +0 -1
  193. package/dist/react.cjs.development.js +0 -190
  194. package/dist/react.cjs.development.js.map +0 -1
  195. package/dist/react.cjs.production.min.js +0 -2
  196. package/dist/react.cjs.production.min.js.map +0 -1
  197. package/dist/react.esm.js +0 -9
  198. package/dist/react.esm.js.map +0 -1
  199. package/dist/use-intl.cjs.development.js +0 -842
  200. package/dist/use-intl.cjs.development.js.map +0 -1
  201. package/dist/use-intl.cjs.production.min.js +0 -2
  202. package/dist/use-intl.cjs.production.min.js.map +0 -1
  203. package/dist/use-intl.esm.js +0 -15
  204. package/dist/use-intl.esm.js.map +0 -1
@@ -1,30 +0,0 @@
1
- import { useMemo } from 'react';
2
- import createIntl from '../core/createIntl.esm.js';
3
- import useIntlContext from './useIntlContext.esm.js';
4
-
5
- var hasWarned = false;
6
- /** @deprecated Switch to `useFormatter` instead. */
7
- function useIntl() {
8
- var _useIntlContext = useIntlContext(),
9
- formats = _useIntlContext.formats,
10
- locale = _useIntlContext.locale,
11
- globalNow = _useIntlContext.now,
12
- onError = _useIntlContext.onError,
13
- timeZone = _useIntlContext.timeZone;
14
- if (!hasWarned) {
15
- hasWarned = true;
16
- console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
17
- }
18
- return useMemo(function () {
19
- return createIntl({
20
- formats: formats,
21
- locale: locale,
22
- now: globalNow,
23
- onError: onError,
24
- timeZone: timeZone
25
- });
26
- }, [formats, globalNow, locale, onError, timeZone]);
27
- }
28
-
29
- export { useIntl as default };
30
- //# sourceMappingURL=useIntl.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIntl.esm.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["hasWarned","useIntl","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","console","warn","useMemo","createIntl"],"mappings":";;;;AAIA,IAAIA,SAAS,GAAG,KAAK,CAAA;AAErB;AACc,SAAUC,OAAOA,GAAA;AAC7B,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;EAEzD,IAAI,CAACT,SAAS,EAAE;AACdA,IAAAA,SAAS,GAAG,IAAI,CAAA;AAChBU,IAAAA,OAAO,CAACC,IAAI,CACV,6GAA6G,CAC9G,CAAA;AACF,GAAA;AAED,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTT,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
@@ -1,13 +0,0 @@
1
- import { useContext } from 'react';
2
- import IntlContext from './IntlContext.esm.js';
3
-
4
- function useIntlContext() {
5
- var context = useContext(IntlContext);
6
- if (!context) {
7
- throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
8
- }
9
- return context;
10
- }
11
-
12
- export { useIntlContext as default };
13
- //# sourceMappingURL=useIntlContext.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIntlContext.esm.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","process","env","NODE_ENV","undefined"],"mappings":";;;AAGc,SAAUA,cAAcA,GAAA;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAW,CAAC,CAAA;EAEvC,IAAI,CAACF,OAAO,EAAE;AACZ,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,0DAA0D,GAC1DC,SAAS,CACd,CAAA;AACF,GAAA;AAED,EAAA,OAAOP,OAAO,CAAA;AAChB;;;;"}
@@ -1,8 +0,0 @@
1
- import useIntlContext from './useIntlContext.esm.js';
2
-
3
- function useLocale() {
4
- return useIntlContext().locale;
5
- }
6
-
7
- export { useLocale as default };
8
- //# sourceMappingURL=useLocale.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLocale.esm.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAASA,GAAA;AAC/B,EAAA,OAAOC,cAAc,EAAE,CAACC,MAAM,CAAA;AAChC;;;;"}
@@ -1,8 +0,0 @@
1
- import useIntlContext from './useIntlContext.esm.js';
2
-
3
- function useMessages() {
4
- return useIntlContext().messages;
5
- }
6
-
7
- export { useMessages as default };
8
- //# sourceMappingURL=useMessages.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMessages.esm.js","sources":["../../src/react/useMessages.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useMessages() {\n return useIntlContext().messages;\n}\n"],"names":["useMessages","useIntlContext","messages"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
@@ -1,45 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import useIntlContext from './useIntlContext.esm.js';
3
-
4
- function getNow() {
5
- return new Date();
6
- }
7
- /**
8
- * Reading the current date via `new Date()` in components should be avoided, as
9
- * it causes components to be impure and can lead to flaky tests. Instead, this
10
- * hook can be used.
11
- *
12
- * By default, it returns the time when the component mounts. If `updateInterval`
13
- * is specified, the value will be updated based on the interval.
14
- *
15
- * You can however also return a static value from this hook, if you
16
- * configure the `now` parameter on the context provider. Note however,
17
- * that if `updateInterval` is configured in this case, the component
18
- * will initialize with the global value, but will afterwards update
19
- * continuously based on the interval.
20
- *
21
- * For unit tests, this can be mocked to a constant value. For end-to-end
22
- * testing, an environment parameter can be passed to the `now` parameter
23
- * of the provider to mock this to a static value.
24
- */
25
- function useNow(options) {
26
- var updateInterval = options == null ? void 0 : options.updateInterval;
27
- var _useIntlContext = useIntlContext(),
28
- globalNow = _useIntlContext.now;
29
- var _useState = useState(globalNow || getNow()),
30
- now = _useState[0],
31
- setNow = _useState[1];
32
- useEffect(function () {
33
- if (!updateInterval) return;
34
- var intervalId = setInterval(function () {
35
- setNow(getNow());
36
- }, updateInterval);
37
- return function () {
38
- clearInterval(intervalId);
39
- };
40
- }, [globalNow, updateInterval]);
41
- return now;
42
- }
43
-
44
- export { useNow as default };
45
- //# sourceMappingURL=useNow.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useNow.esm.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","_useIntlContext","useIntlContext","globalNow","now","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAMA,GAAA;EACb,OAAO,IAAIC,IAAI,EAAE,CAAA;AACnB,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACqB,SAAAC,MAAMA,CAACC,OAAiB,EAAA;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAc,CAAA;AAE9C,EAAA,IAAAC,eAAA,GAAyBC,cAAc,EAAE;IAA7BC,SAAS,GAAAF,eAAA,CAAdG,GAAG,CAAA;EACV,IAAAC,SAAA,GAAsBC,QAAQ,CAACH,SAAS,IAAIP,MAAM,EAAE,CAAC;AAA9CQ,IAAAA,GAAG,GAAAC,SAAA,CAAA,CAAA,CAAA;AAAEE,IAAAA,MAAM,GAAAF,SAAA,CAAA,CAAA,CAAA,CAAA;AAElBG,EAAAA,SAAS,CAAC,YAAK;IACb,IAAI,CAACR,cAAc,EAAE,OAAA;AAErB,IAAA,IAAMS,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACX,MAAM,EAAE,CAAC,CAAA;KACjB,EAAEI,cAAc,CAAC,CAAA;AAElB,IAAA,OAAO,YAAK;MACVW,aAAa,CAACF,UAAU,CAAC,CAAA;KAC1B,CAAA;AACH,GAAC,EAAE,CAACN,SAAS,EAAEH,cAAc,CAAC,CAAC,CAAA;AAE/B,EAAA,OAAOI,GAAG,CAAA;AACZ;;;;"}
@@ -1,8 +0,0 @@
1
- import useIntlContext from './useIntlContext.esm.js';
2
-
3
- function useTimeZone() {
4
- return useIntlContext().timeZone;
5
- }
6
-
7
- export { useTimeZone as default };
8
- //# sourceMappingURL=useTimeZone.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTimeZone.esm.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
@@ -1,26 +0,0 @@
1
- import useIntlContext from './useIntlContext.esm.js';
2
- import useTranslationsImpl from './useTranslationsImpl.esm.js';
3
-
4
- /**
5
- * Translates messages from the given namespace by using the ICU syntax.
6
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
7
- *
8
- * If no namespace is provided, all available messages are returned.
9
- * The namespace can also indicate nesting by using a dot
10
- * (e.g. `namespace.Component`).
11
- */
12
- function useTranslations(namespace) {
13
- var context = useIntlContext();
14
- var messages = context.messages;
15
- // We have to wrap the actual hook so the type inference for the optional
16
- // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
17
- // The prefix ("!") is arbitrary.
18
- return useTranslationsImpl({
19
- '!': messages
20
- },
21
- // @ts-ignore
22
- namespace ? "!." + namespace : '!', '!');
23
- }
24
-
25
- export { useTranslations as default };
26
- //# sourceMappingURL=useTranslations.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTranslations.esm.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;AACqB,SAAAA,eAAeA,CAMrCC,SAAqB,EAAA;AA6DrB,EAAA,IAAMC,OAAO,GAAGC,cAAc,EAAE,CAAA;AAChC,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAwB,CAAA;AAEjD;AACA;AACA;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAA,GAAG,EAAED,QAAAA;GAAS;AACf;AACAH,EAAAA,SAAS,UAAQA,SAAS,GAAK,GAAG,EAClC,GAAG,CACJ,CAAA;AACH;;;;"}
@@ -1,36 +0,0 @@
1
- import { useMemo } from 'react';
2
- import createBaseTranslator from '../core/createBaseTranslator.esm.js';
3
- import resolveNamespace from '../core/resolveNamespace.esm.js';
4
- import useIntlContext from './useIntlContext.esm.js';
5
-
6
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
7
- var _useIntlContext = useIntlContext(),
8
- defaultTranslationValues = _useIntlContext.defaultTranslationValues,
9
- globalFormats = _useIntlContext.formats,
10
- getMessageFallback = _useIntlContext.getMessageFallback,
11
- locale = _useIntlContext.locale,
12
- messageFormatCache = _useIntlContext.messageFormatCache,
13
- onError = _useIntlContext.onError,
14
- timeZone = _useIntlContext.timeZone;
15
- // The `namespacePrefix` is part of the type system.
16
- // See the comment in the hook invocation.
17
- allMessages = allMessages[namespacePrefix];
18
- namespace = resolveNamespace(namespace, namespacePrefix);
19
- var translate = useMemo(function () {
20
- return createBaseTranslator({
21
- messageFormatCache: messageFormatCache,
22
- getMessageFallback: getMessageFallback,
23
- messages: allMessages,
24
- defaultTranslationValues: defaultTranslationValues,
25
- namespace: namespace,
26
- onError: onError,
27
- formats: globalFormats,
28
- locale: locale,
29
- timeZone: timeZone
30
- });
31
- }, [messageFormatCache, getMessageFallback, allMessages, namespace, onError, defaultTranslationValues, globalFormats, locale, timeZone]);
32
- return translate;
33
- }
34
-
35
- export { useTranslationsImpl as default };
36
- //# sourceMappingURL=useTranslationsImpl.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTranslationsImpl.esm.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n messageFormatCache,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messages: allMessages,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\n getMessageFallback,\n allMessages,\n namespace,\n onError,\n defaultTranslationValues,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","_useIntlContext","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","messageFormatCache","onError","timeZone","resolveNamespace","translate","useMemo","createBaseTranslator","messages"],"mappings":";;;;;AAOwB,SAAAA,mBAAmBA,CAGzCC,WAAqB,EAAEC,SAAoB,EAAEC,eAAuB,EAAA;AACpE,EAAA,IAAAC,eAAA,GAQIC,cAAc,EAAE;IAPlBC,wBAAwB,GAAAF,eAAA,CAAxBE,wBAAwB;IACfC,aAAa,GAAAH,eAAA,CAAtBI,OAAO;IACPC,kBAAkB,GAAAL,eAAA,CAAlBK,kBAAkB;IAClBC,MAAM,GAAAN,eAAA,CAANM,MAAM;IACNC,kBAAkB,GAAAP,eAAA,CAAlBO,kBAAkB;IAClBC,OAAO,GAAAR,eAAA,CAAPQ,OAAO;IACPC,QAAQ,GAAAT,eAAA,CAARS,QAAQ,CAAA;AAGV;AACA;AACAZ,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAe,CAAa,CAAA;AACtDD,EAAAA,SAAS,GAAGY,gBAAgB,CAACZ,SAAS,EAAEC,eAAe,CAAc,CAAA;EAErE,IAAMY,SAAS,GAAGC,OAAO,CACvB,YAAA;AAAA,IAAA,OACEC,oBAAoB,CAAC;AACnBN,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBF,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBS,MAAAA,QAAQ,EAAEjB,WAAW;AACrBK,MAAAA,wBAAwB,EAAxBA,wBAAwB;AACxBJ,MAAAA,SAAS,EAATA,SAAS;AACTU,MAAAA,OAAO,EAAPA,OAAO;AACPJ,MAAAA,OAAO,EAAED,aAAa;AACtBG,MAAAA,MAAM,EAANA,MAAM;AACNG,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;AAAA,GAAA,EACJ,CACEF,kBAAkB,EAClBF,kBAAkB,EAClBR,WAAW,EACXC,SAAS,EACTU,OAAO,EACPN,wBAAwB,EACxBC,aAAa,EACbG,MAAM,EACNG,QAAQ,CACT,CACF,CAAA;AAED,EAAA,OAAOE,SAAS,CAAA;AAClB;;;;"}
@@ -1,190 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var createIntl = require('./createIntl-34d4281e.js');
6
- var React = require('react');
7
- require('intl-messageformat');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
-
13
- var IntlContext = /*#__PURE__*/React.createContext(undefined);
14
-
15
- var _excluded = ["children"];
16
- function IntlProvider(_ref) {
17
- var children = _ref.children,
18
- config = createIntl._objectWithoutPropertiesLoose(_ref, _excluded);
19
- var _useState = React.useState(function () {
20
- return new Map();
21
- }),
22
- messageFormatCache = _useState[0];
23
- return React__default["default"].createElement(IntlContext.Provider, {
24
- value: createIntl._extends({}, createIntl.initializeConfig(config), {
25
- messageFormatCache: messageFormatCache
26
- })
27
- }, children);
28
- }
29
-
30
- function useIntlContext() {
31
- var context = React.useContext(IntlContext);
32
- if (!context) {
33
- throw new Error('No intl context found. Have you configured the provider?' );
34
- }
35
- return context;
36
- }
37
-
38
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
39
- var _useIntlContext = useIntlContext(),
40
- defaultTranslationValues = _useIntlContext.defaultTranslationValues,
41
- globalFormats = _useIntlContext.formats,
42
- getMessageFallback = _useIntlContext.getMessageFallback,
43
- locale = _useIntlContext.locale,
44
- messageFormatCache = _useIntlContext.messageFormatCache,
45
- onError = _useIntlContext.onError,
46
- timeZone = _useIntlContext.timeZone;
47
- // The `namespacePrefix` is part of the type system.
48
- // See the comment in the hook invocation.
49
- allMessages = allMessages[namespacePrefix];
50
- namespace = createIntl.resolveNamespace(namespace, namespacePrefix);
51
- var translate = React.useMemo(function () {
52
- return createIntl.createBaseTranslator({
53
- messageFormatCache: messageFormatCache,
54
- getMessageFallback: getMessageFallback,
55
- messages: allMessages,
56
- defaultTranslationValues: defaultTranslationValues,
57
- namespace: namespace,
58
- onError: onError,
59
- formats: globalFormats,
60
- locale: locale,
61
- timeZone: timeZone
62
- });
63
- }, [messageFormatCache, getMessageFallback, allMessages, namespace, onError, defaultTranslationValues, globalFormats, locale, timeZone]);
64
- return translate;
65
- }
66
-
67
- /**
68
- * Translates messages from the given namespace by using the ICU syntax.
69
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
70
- *
71
- * If no namespace is provided, all available messages are returned.
72
- * The namespace can also indicate nesting by using a dot
73
- * (e.g. `namespace.Component`).
74
- */
75
- function useTranslations(namespace) {
76
- var context = useIntlContext();
77
- var messages = context.messages;
78
- // We have to wrap the actual hook so the type inference for the optional
79
- // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
80
- // The prefix ("!") is arbitrary.
81
- return useTranslationsImpl({
82
- '!': messages
83
- },
84
- // @ts-ignore
85
- namespace ? "!." + namespace : '!', '!');
86
- }
87
-
88
- function useLocale() {
89
- return useIntlContext().locale;
90
- }
91
-
92
- function getNow() {
93
- return new Date();
94
- }
95
- /**
96
- * Reading the current date via `new Date()` in components should be avoided, as
97
- * it causes components to be impure and can lead to flaky tests. Instead, this
98
- * hook can be used.
99
- *
100
- * By default, it returns the time when the component mounts. If `updateInterval`
101
- * is specified, the value will be updated based on the interval.
102
- *
103
- * You can however also return a static value from this hook, if you
104
- * configure the `now` parameter on the context provider. Note however,
105
- * that if `updateInterval` is configured in this case, the component
106
- * will initialize with the global value, but will afterwards update
107
- * continuously based on the interval.
108
- *
109
- * For unit tests, this can be mocked to a constant value. For end-to-end
110
- * testing, an environment parameter can be passed to the `now` parameter
111
- * of the provider to mock this to a static value.
112
- */
113
- function useNow(options) {
114
- var updateInterval = options == null ? void 0 : options.updateInterval;
115
- var _useIntlContext = useIntlContext(),
116
- globalNow = _useIntlContext.now;
117
- var _useState = React.useState(globalNow || getNow()),
118
- now = _useState[0],
119
- setNow = _useState[1];
120
- React.useEffect(function () {
121
- if (!updateInterval) return;
122
- var intervalId = setInterval(function () {
123
- setNow(getNow());
124
- }, updateInterval);
125
- return function () {
126
- clearInterval(intervalId);
127
- };
128
- }, [globalNow, updateInterval]);
129
- return now;
130
- }
131
-
132
- function useTimeZone() {
133
- return useIntlContext().timeZone;
134
- }
135
-
136
- function useMessages() {
137
- return useIntlContext().messages;
138
- }
139
-
140
- function useFormatter() {
141
- var _useIntlContext = useIntlContext(),
142
- formats = _useIntlContext.formats,
143
- locale = _useIntlContext.locale,
144
- globalNow = _useIntlContext.now,
145
- onError = _useIntlContext.onError,
146
- timeZone = _useIntlContext.timeZone;
147
- return React.useMemo(function () {
148
- return createIntl.createFormatter({
149
- formats: formats,
150
- locale: locale,
151
- now: globalNow,
152
- onError: onError,
153
- timeZone: timeZone
154
- });
155
- }, [formats, globalNow, locale, onError, timeZone]);
156
- }
157
-
158
- var hasWarned = false;
159
- /** @deprecated Switch to `useFormatter` instead. */
160
- function useIntl() {
161
- var _useIntlContext = useIntlContext(),
162
- formats = _useIntlContext.formats,
163
- locale = _useIntlContext.locale,
164
- globalNow = _useIntlContext.now,
165
- onError = _useIntlContext.onError,
166
- timeZone = _useIntlContext.timeZone;
167
- if (!hasWarned) {
168
- hasWarned = true;
169
- console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
170
- }
171
- return React.useMemo(function () {
172
- return createIntl.createIntl({
173
- formats: formats,
174
- locale: locale,
175
- now: globalNow,
176
- onError: onError,
177
- timeZone: timeZone
178
- });
179
- }, [formats, globalNow, locale, onError, timeZone]);
180
- }
181
-
182
- exports.IntlProvider = IntlProvider;
183
- exports.useFormatter = useFormatter;
184
- exports.useIntl = useIntl;
185
- exports.useLocale = useLocale;
186
- exports.useMessages = useMessages;
187
- exports.useNow = useNow;
188
- exports.useTimeZone = useTimeZone;
189
- exports.useTranslations = useTranslations;
190
- //# sourceMappingURL=react.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.cjs.development.js","sources":["../src/react/IntlContext.tsx","../src/react/IntlProvider.tsx","../src/react/useIntlContext.tsx","../src/react/useTranslationsImpl.tsx","../src/react/useTranslations.tsx","../src/react/useLocale.tsx","../src/react/useNow.tsx","../src/react/useTimeZone.tsx","../src/react/useMessages.tsx","../src/react/useFormatter.tsx","../src/react/useIntl.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\nimport MessageFormatCache from '../core/MessageFormatCache';\n\nconst IntlContext = createContext<\n | (InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n })\n | undefined\n>(undefined);\n\nexport default IntlContext;\n","import React, {ReactNode, useState} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport initializeConfig from '../core/initializeConfig';\nimport IntlContext from './IntlContext';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...config}: Props) {\n const [messageFormatCache] = useState(() => new Map());\n\n return (\n <IntlContext.Provider\n value={{\n ...initializeConfig(config),\n messageFormatCache\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n","import {useMemo} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n messageFormatCache,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messages: allMessages,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\n getMessageFallback,\n allMessages,\n namespace,\n onError,\n defaultTranslationValues,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useMessages() {\n return useIntlContext().messages;\n}\n","import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n","import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["IntlContext","createContext","undefined","IntlProvider","_ref","children","config","_objectWithoutPropertiesLoose","_excluded","_useState","useState","Map","messageFormatCache","React","createElement","Provider","value","_extends","initializeConfig","useIntlContext","context","useContext","Error","useTranslationsImpl","allMessages","namespace","namespacePrefix","_useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","translate","useMemo","createBaseTranslator","messages","useTranslations","useLocale","getNow","Date","useNow","options","updateInterval","globalNow","now","setNow","useEffect","intervalId","setInterval","clearInterval","useTimeZone","useMessages","useFormatter","createFormatter","hasWarned","useIntl","console","warn","createIntl"],"mappings":";;;;;;;;;;;;AAIA,IAAMA,WAAW,gBAAGC,mBAAa,CAK/BC,SAAS,CAAC;;;ACAE,SAAUC,YAAYA,CAAAC,IAAA,EAA6B;AAAA,EAAA,IAA3BC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;AAAKC,IAAAA,MAAM,GAAAC,wCAAA,CAAAH,IAAA,EAAAI,SAAA,CAAA,CAAA;EACvD,IAAAC,SAAA,GAA6BC,cAAQ,CAAC,YAAA;MAAA,OAAM,IAAIC,GAAG,EAAE,CAAA;KAAC,CAAA;AAA/CC,IAAAA,kBAAkB,GAAAH,SAAA,CAAA,CAAA,CAAA,CAAA;AAEzB,EAA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AAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACJ,OAAO,EAAEiB,SAAS,EAAEf,MAAM,EAAEC,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;ACdA,IAAIwB,SAAS,GAAG,KAAK,CAAA;AAErB;AACc,SAAUC,OAAOA,GAAA;AAC7B,EAAA,IAAAhC,eAAA,GAA6DR,cAAc,EAAE;IAAtEW,OAAO,GAAAH,eAAA,CAAPG,OAAO;IAAEE,MAAM,GAAAL,eAAA,CAANK,MAAM;IAAOe,SAAS,GAAApB,eAAA,CAAdqB,GAAG;IAAaf,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;EAEzD,IAAI,CAACwB,SAAS,EAAE;AACdA,IAAAA,SAAS,GAAG,IAAI,CAAA;AAChBE,IAAAA,OAAO,CAACC,IAAI,CACV,6GAA6G,CAC9G,CAAA;AACF,GAAA;AAED,EAAA,OAAOxB,aAAO,CACZ,YAAA;AAAA,IAAA,OACEyB,qBAAU,CAAC;AACThC,MAAAA,OAAO,EAAPA,OAAO;AACPE,MAAAA,MAAM,EAANA,MAAM;AACNgB,MAAAA,GAAG,EAAED,SAAS;AACdd,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACJ,OAAO,EAAEiB,SAAS,EAAEf,MAAM,EAAEC,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createIntl-bc325740.js"),r=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("intl-messageformat");var n=t(r),o=r.createContext(void 0),a=["children"];function s(){var e=r.useContext(o);if(!e)throw new Error(void 0);return e}function u(){return new Date}var i=!1;exports.IntlProvider=function(t){var s=t.children,u=e._objectWithoutPropertiesLoose(t,a),i=r.useState((function(){return new Map}))[0];return n.default.createElement(o.Provider,{value:e._extends({},e.initializeConfig(u),{messageFormatCache:i})},s)},exports.useFormatter=function(){var t=s(),n=t.formats,o=t.locale,a=t.now,u=t.onError,i=t.timeZone;return r.useMemo((function(){return e.createFormatter({formats:n,locale:o,now:a,onError:u,timeZone:i})}),[n,a,o,u,i])},exports.useIntl=function(){var t=s(),n=t.formats,o=t.locale,a=t.now,u=t.onError,l=t.timeZone;return i||(i=!0,console.warn("`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.")),r.useMemo((function(){return e.createIntl({formats:n,locale:o,now:a,onError:u,timeZone:l})}),[n,a,o,u,l])},exports.useLocale=function(){return s().locale},exports.useMessages=function(){return s().messages},exports.useNow=function(e){var t=null==e?void 0:e.updateInterval,n=s().now,o=r.useState(n||u()),a=o[0],i=o[1];return r.useEffect((function(){if(t){var e=setInterval((function(){i(u())}),t);return function(){clearInterval(e)}}}),[n,t]),a},exports.useTimeZone=function(){return s().timeZone},exports.useTranslations=function(t){return function(t,n,o){var a=s(),u=a.defaultTranslationValues,i=a.formats,l=a.getMessageFallback,c=a.locale,f=a.messageFormatCache,m=a.onError,v=a.timeZone;return t=t["!"],n=e.resolveNamespace(n,"!"),r.useMemo((function(){return e.createBaseTranslator({messageFormatCache:f,getMessageFallback:l,messages:t,defaultTranslationValues:u,namespace:n,onError:m,formats:i,locale:c,timeZone:v})}),[f,l,t,n,m,u,i,c,v])}({"!":s().messages},t?"!."+t:"!")};
2
- //# sourceMappingURL=react.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.cjs.production.min.js","sources":["../src/react/IntlContext.tsx","../src/react/useIntlContext.tsx","../src/react/useNow.tsx","../src/react/useIntl.tsx","../src/react/IntlProvider.tsx","../src/react/useFormatter.tsx","../src/react/useLocale.tsx","../src/react/useMessages.tsx","../src/react/useTimeZone.tsx","../src/react/useTranslations.tsx","../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\nimport MessageFormatCache from '../core/MessageFormatCache';\n\nconst IntlContext = createContext<\n | (InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n })\n | undefined\n>(undefined);\n\nexport default IntlContext;\n","import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n","import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n","import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n","import React, {ReactNode, useState} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport initializeConfig from '../core/initializeConfig';\nimport IntlContext from './IntlContext';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...config}: Props) {\n const [messageFormatCache] = useState(() => new Map());\n\n return (\n <IntlContext.Provider\n value={{\n ...initializeConfig(config),\n messageFormatCache\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n","import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useMessages() {\n return useIntlContext().messages;\n}\n","import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n","import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n","import {useMemo} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n messageFormatCache,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messages: allMessages,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\n getMessageFallback,\n allMessages,\n namespace,\n onError,\n defaultTranslationValues,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["IntlContext","createContext","undefined","useIntlContext","context","useContext","Error","getNow","Date","hasWarned","_ref","children","config","_objectWithoutPropertiesLoose","_excluded","messageFormatCache","useState","Map","React","createElement","Provider","value","_extends","initializeConfig","_useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter","console","warn","createIntl","messages","options","updateInterval","_useState","setNow","useEffect","intervalId","setInterval","clearInterval","namespace","allMessages","namespacePrefix","defaultTranslationValues","globalFormats","getMessageFallback","resolveNamespace","createBaseTranslator","useTranslationsImpl"],"mappings":"kPAIMA,EAAcC,EAAaA,mBAK/BC,kBCNY,SAAUC,IACtB,IAAMC,EAAUC,aAAWL,GAE3B,IAAKI,EACH,MAAM,IAAIE,WAGJJ,GAIR,OAAOE,CACT,CCRA,SAASG,IACP,OAAO,IAAIC,IACb,CCLA,IAAIC,GAAY,uBCKF,SAAsBC,GAA6B,IAA3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H,OAAO,WACLM,cAAcF,GAPK,CASvB,GAAG,CAACf,EAAWW,IAERV,CACT,sBM9Cc,WACZ,OAAOzB,IAAiB2B,QAC1B,0BCgBwB,SAMtBe,GAmEA,OCtFsB,SAGtBC,EAAuBD,EAAsBE,GAC7C,IAAAvB,EAQIrB,IAPF6C,EAAwBxB,EAAxBwB,yBACSC,EAAazB,EAAtBC,QACAyB,EAAkB1B,EAAlB0B,mBACAxB,EAAMF,EAANE,OACAX,EAAkBS,EAAlBT,mBACAc,EAAOL,EAAPK,QACAC,EAAQN,EAARM,SAkCF,OA7BAgB,EAAcA,ED6EZ,KC5EFD,EAAYM,EAAgBA,iBAACN,ED4E3B,KC1EgBd,EAAAA,SAChB,WAAA,OACEqB,uBAAqB,CACnBrC,mBAAAA,EACAmC,mBAAAA,EACAd,SAAUU,EACVE,yBAAAA,EACAH,UAAAA,EACAhB,QAAAA,EACAJ,QAASwB,EACTvB,OAAAA,EACAI,SAAAA,GACA,GACJ,CACEf,EACAmC,EACAJ,EACAD,EACAhB,EACAmB,EACAC,EACAvB,EACAI,GAKN,CDwCSuB,CAIL,CAAC,IAValD,IACSiC,UAWvBS,OAAiBA,EAAc,IAGnC"}
package/dist/react.esm.js DELETED
@@ -1,9 +0,0 @@
1
- export { default as IntlProvider } from './react/IntlProvider.esm.js';
2
- export { default as useTranslations } from './react/useTranslations.esm.js';
3
- export { default as useLocale } from './react/useLocale.esm.js';
4
- export { default as useNow } from './react/useNow.esm.js';
5
- export { default as useTimeZone } from './react/useTimeZone.esm.js';
6
- export { default as useMessages } from './react/useMessages.esm.js';
7
- export { default as useFormatter } from './react/useFormatter.esm.js';
8
- export { default as useIntl } from './react/useIntl.esm.js';
9
- //# sourceMappingURL=react.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}