@chipmobilesdk/rn-i18n 0.2.0 → 0.4.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 (201) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/README.md +48 -17
  3. package/lib/commonjs/config/catalog.js +29 -0
  4. package/lib/commonjs/config/catalog.js.map +1 -0
  5. package/lib/commonjs/config/diagnostics.js +56 -0
  6. package/lib/commonjs/config/diagnostics.js.map +1 -0
  7. package/lib/commonjs/config/errors.js +35 -0
  8. package/lib/commonjs/config/errors.js.map +1 -0
  9. package/lib/commonjs/config/types.js +13 -0
  10. package/lib/commonjs/config/types.js.map +1 -0
  11. package/lib/commonjs/config/validateConfig.js +134 -0
  12. package/lib/commonjs/config/validateConfig.js.map +1 -0
  13. package/lib/commonjs/format/currency.js +35 -0
  14. package/lib/commonjs/format/currency.js.map +1 -0
  15. package/lib/commonjs/format/date.js +36 -0
  16. package/lib/commonjs/format/date.js.map +1 -0
  17. package/lib/commonjs/format/invalid.js +24 -0
  18. package/lib/commonjs/format/invalid.js.map +1 -0
  19. package/lib/commonjs/format/number.js +29 -0
  20. package/lib/commonjs/format/number.js.map +1 -0
  21. package/lib/commonjs/format/units.js +184 -0
  22. package/lib/commonjs/format/units.js.map +1 -0
  23. package/lib/commonjs/i18n.js +234 -0
  24. package/lib/commonjs/i18n.js.map +1 -0
  25. package/lib/commonjs/index.js +93 -0
  26. package/lib/commonjs/index.js.map +1 -0
  27. package/lib/commonjs/locale/activeLocale.js +37 -0
  28. package/lib/commonjs/locale/activeLocale.js.map +1 -0
  29. package/lib/commonjs/locale/deviceLocale.js +52 -0
  30. package/lib/commonjs/locale/deviceLocale.js.map +1 -0
  31. package/lib/commonjs/locale/keyValueStorage.js +29 -0
  32. package/lib/commonjs/locale/keyValueStorage.js.map +1 -0
  33. package/lib/commonjs/locale/persistence.js +74 -0
  34. package/lib/commonjs/locale/persistence.js.map +1 -0
  35. package/lib/commonjs/package.json +1 -0
  36. package/lib/commonjs/react/I18nProvider.js +36 -0
  37. package/lib/commonjs/react/I18nProvider.js.map +1 -0
  38. package/lib/commonjs/react/hooks.js +47 -0
  39. package/lib/commonjs/react/hooks.js.map +1 -0
  40. package/lib/commonjs/translation/interpolate.js +24 -0
  41. package/lib/commonjs/translation/interpolate.js.map +1 -0
  42. package/lib/commonjs/translation/plurals.js +122 -0
  43. package/lib/commonjs/translation/plurals.js.map +1 -0
  44. package/lib/commonjs/translation/resolver.js +124 -0
  45. package/lib/commonjs/translation/resolver.js.map +1 -0
  46. package/lib/commonjs/translation/runtimeKeys.js +55 -0
  47. package/lib/commonjs/translation/runtimeKeys.js.map +1 -0
  48. package/lib/module/config/catalog.js +25 -0
  49. package/lib/module/config/catalog.js.map +1 -0
  50. package/lib/module/config/diagnostics.js +51 -0
  51. package/lib/module/config/diagnostics.js.map +1 -0
  52. package/lib/module/config/errors.js +30 -0
  53. package/lib/module/config/errors.js.map +1 -0
  54. package/lib/module/config/types.js +26 -0
  55. package/lib/module/config/types.js.map +1 -0
  56. package/lib/module/config/validateConfig.js +131 -0
  57. package/lib/module/config/validateConfig.js.map +1 -0
  58. package/lib/module/format/currency.js +32 -0
  59. package/lib/module/format/currency.js.map +1 -0
  60. package/lib/module/format/date.js +33 -0
  61. package/lib/module/format/date.js.map +1 -0
  62. package/lib/module/format/invalid.js +21 -0
  63. package/lib/module/format/invalid.js.map +1 -0
  64. package/lib/module/format/number.js +26 -0
  65. package/lib/module/format/number.js.map +1 -0
  66. package/lib/module/format/units.js +171 -0
  67. package/lib/module/format/units.js.map +1 -0
  68. package/lib/module/i18n.js +230 -0
  69. package/lib/module/i18n.js.map +1 -0
  70. package/lib/module/index.js +23 -0
  71. package/lib/module/index.js.map +1 -0
  72. package/lib/module/locale/activeLocale.js +33 -0
  73. package/lib/module/locale/activeLocale.js.map +1 -0
  74. package/lib/module/locale/deviceLocale.js +46 -0
  75. package/lib/module/locale/deviceLocale.js.map +1 -0
  76. package/lib/module/locale/keyValueStorage.js +25 -0
  77. package/lib/module/locale/keyValueStorage.js.map +1 -0
  78. package/lib/module/locale/persistence.js +66 -0
  79. package/lib/module/locale/persistence.js.map +1 -0
  80. package/lib/module/package.json +1 -0
  81. package/lib/module/react/I18nProvider.js +29 -0
  82. package/lib/module/react/I18nProvider.js.map +1 -0
  83. package/lib/module/react/hooks.js +42 -0
  84. package/lib/module/react/hooks.js.map +1 -0
  85. package/lib/module/translation/interpolate.js +20 -0
  86. package/lib/module/translation/interpolate.js.map +1 -0
  87. package/lib/module/translation/plurals.js +114 -0
  88. package/lib/module/translation/plurals.js.map +1 -0
  89. package/lib/module/translation/resolver.js +118 -0
  90. package/lib/module/translation/resolver.js.map +1 -0
  91. package/lib/module/translation/runtimeKeys.js +50 -0
  92. package/lib/module/translation/runtimeKeys.js.map +1 -0
  93. package/lib/typescript/commonjs/config/catalog.d.ts +18 -0
  94. package/lib/typescript/commonjs/config/catalog.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/config/diagnostics.d.ts +21 -0
  96. package/lib/typescript/commonjs/config/diagnostics.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/config/errors.d.ts +16 -0
  98. package/lib/typescript/commonjs/config/errors.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/config/types.d.ts +127 -0
  100. package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/config/validateConfig.d.ts +8 -0
  102. package/lib/typescript/commonjs/config/validateConfig.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/format/currency.d.ts +12 -0
  104. package/lib/typescript/commonjs/format/currency.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/format/date.d.ts +14 -0
  106. package/lib/typescript/commonjs/format/date.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/format/invalid.d.ts +12 -0
  108. package/lib/typescript/commonjs/format/invalid.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/format/number.d.ts +8 -0
  110. package/lib/typescript/commonjs/format/number.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/format/units.d.ts +23 -0
  112. package/lib/typescript/commonjs/format/units.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/i18n.d.ts +46 -0
  114. package/lib/typescript/commonjs/i18n.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/index.d.ts +27 -0
  116. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/locale/activeLocale.d.ts +17 -0
  118. package/lib/typescript/commonjs/locale/activeLocale.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/locale/deviceLocale.d.ts +19 -0
  120. package/lib/typescript/commonjs/locale/deviceLocale.d.ts.map +1 -0
  121. package/lib/typescript/commonjs/locale/keyValueStorage.d.ts +13 -0
  122. package/lib/typescript/commonjs/locale/keyValueStorage.d.ts.map +1 -0
  123. package/lib/typescript/commonjs/locale/persistence.d.ts +24 -0
  124. package/lib/typescript/commonjs/locale/persistence.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/package.json +1 -0
  126. package/lib/typescript/commonjs/react/I18nProvider.d.ts +16 -0
  127. package/lib/typescript/commonjs/react/I18nProvider.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/react/hooks.d.ts +21 -0
  129. package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/translation/interpolate.d.ts +8 -0
  131. package/lib/typescript/commonjs/translation/interpolate.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/translation/plurals.d.ts +13 -0
  133. package/lib/typescript/commonjs/translation/plurals.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/translation/resolver.d.ts +24 -0
  135. package/lib/typescript/commonjs/translation/resolver.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/translation/runtimeKeys.d.ts +16 -0
  137. package/lib/typescript/commonjs/translation/runtimeKeys.d.ts.map +1 -0
  138. package/lib/typescript/module/config/catalog.d.ts +18 -0
  139. package/lib/typescript/module/config/catalog.d.ts.map +1 -0
  140. package/lib/typescript/module/config/diagnostics.d.ts +21 -0
  141. package/lib/typescript/module/config/diagnostics.d.ts.map +1 -0
  142. package/lib/typescript/module/config/errors.d.ts +16 -0
  143. package/lib/typescript/module/config/errors.d.ts.map +1 -0
  144. package/lib/typescript/module/config/types.d.ts +127 -0
  145. package/lib/typescript/module/config/types.d.ts.map +1 -0
  146. package/lib/typescript/module/config/validateConfig.d.ts +8 -0
  147. package/lib/typescript/module/config/validateConfig.d.ts.map +1 -0
  148. package/lib/typescript/module/format/currency.d.ts +12 -0
  149. package/lib/typescript/module/format/currency.d.ts.map +1 -0
  150. package/lib/typescript/module/format/date.d.ts +14 -0
  151. package/lib/typescript/module/format/date.d.ts.map +1 -0
  152. package/lib/typescript/module/format/invalid.d.ts +12 -0
  153. package/lib/typescript/module/format/invalid.d.ts.map +1 -0
  154. package/lib/typescript/module/format/number.d.ts +8 -0
  155. package/lib/typescript/module/format/number.d.ts.map +1 -0
  156. package/lib/typescript/module/format/units.d.ts +23 -0
  157. package/lib/typescript/module/format/units.d.ts.map +1 -0
  158. package/lib/typescript/module/i18n.d.ts +46 -0
  159. package/lib/typescript/module/i18n.d.ts.map +1 -0
  160. package/lib/typescript/module/index.d.ts +27 -0
  161. package/lib/typescript/module/index.d.ts.map +1 -0
  162. package/lib/typescript/module/locale/activeLocale.d.ts +17 -0
  163. package/lib/typescript/module/locale/activeLocale.d.ts.map +1 -0
  164. package/lib/typescript/module/locale/deviceLocale.d.ts +19 -0
  165. package/lib/typescript/module/locale/deviceLocale.d.ts.map +1 -0
  166. package/lib/typescript/module/locale/keyValueStorage.d.ts +13 -0
  167. package/lib/typescript/module/locale/keyValueStorage.d.ts.map +1 -0
  168. package/lib/typescript/module/locale/persistence.d.ts +24 -0
  169. package/lib/typescript/module/locale/persistence.d.ts.map +1 -0
  170. package/lib/typescript/module/package.json +1 -0
  171. package/lib/typescript/module/react/I18nProvider.d.ts +16 -0
  172. package/lib/typescript/module/react/I18nProvider.d.ts.map +1 -0
  173. package/lib/typescript/module/react/hooks.d.ts +21 -0
  174. package/lib/typescript/module/react/hooks.d.ts.map +1 -0
  175. package/lib/typescript/module/translation/interpolate.d.ts +8 -0
  176. package/lib/typescript/module/translation/interpolate.d.ts.map +1 -0
  177. package/lib/typescript/module/translation/plurals.d.ts +13 -0
  178. package/lib/typescript/module/translation/plurals.d.ts.map +1 -0
  179. package/lib/typescript/module/translation/resolver.d.ts +24 -0
  180. package/lib/typescript/module/translation/resolver.d.ts.map +1 -0
  181. package/lib/typescript/module/translation/runtimeKeys.d.ts +16 -0
  182. package/lib/typescript/module/translation/runtimeKeys.d.ts.map +1 -0
  183. package/package.json +41 -18
  184. package/skills/sdk-rn-i18n/SKILL.md +27 -0
  185. package/src/config/diagnostics.ts +2 -0
  186. package/src/format/currency.ts +5 -0
  187. package/src/format/date.ts +10 -4
  188. package/src/i18n.ts +93 -9
  189. package/src/index.ts +5 -3
  190. package/src/locale/activeLocale.ts +10 -0
  191. package/src/locale/persistence.ts +19 -0
  192. package/src/translation/plurals.ts +74 -5
  193. package/src/translation/runtimeKeys.ts +28 -1
  194. package/src/tooling/cli.ts +0 -76
  195. package/src/tooling/generateKeys.ts +0 -62
  196. package/src/tooling/index.ts +0 -27
  197. package/src/tooling/report.ts +0 -109
  198. package/src/tooling/runner.ts +0 -111
  199. package/src/tooling/scan.ts +0 -193
  200. package/src/tooling/sync.ts +0 -193
  201. package/src/tooling/types.ts +0 -119
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatDateValue = formatDateValue;
7
+ var _rnCore = require("@chipmobilesdk/rn-core");
8
+ var _invalid = require("./invalid.js");
9
+ /**
10
+ * Locale-aware date formatting through the Hermes built-in
11
+ * Intl.DateTimeFormat.
12
+ *
13
+ * Options are **merged** over the locale's configured default, the way
14
+ * `formatNumber` has always worked: `{ month: 'long' }` changes the month and
15
+ * keeps the year and day. Replacing the default wholesale, which this used to
16
+ * do, meant one option silently dropped every other component — and the two
17
+ * formatters disagreed about what an option meant (I18N-09). Pass
18
+ * `{ replaceDefaults: true }` for the old behaviour.
19
+ */
20
+ function formatDateValue(value, localeCode, defaults, override, invalidFormat, replaceDefaults = false) {
21
+ const date = value instanceof Date ? value : new Date(value);
22
+ if (Number.isNaN(date.getTime())) {
23
+ return (0, _invalid.applyInvalidFormatPolicy)(invalidFormat, `Cannot format invalid date value "${String(value)}" for locale "${localeCode}".`);
24
+ }
25
+ const options = replaceDefaults ? override ?? defaults : {
26
+ ...defaults,
27
+ ...override
28
+ };
29
+ // rn-core's cached formatter (I18N-03); a bad option is a format problem (I18N-08).
30
+ try {
31
+ return (0, _rnCore.getDateTimeFormat)(localeCode, options).format(date);
32
+ } catch (error) {
33
+ return (0, _invalid.applyInvalidFormatPolicy)(invalidFormat, `Cannot format a date: ${String(error)}`);
34
+ }
35
+ }
36
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_rnCore","require","_invalid","formatDateValue","value","localeCode","defaults","override","invalidFormat","replaceDefaults","date","Date","Number","isNaN","getTime","applyInvalidFormatPolicy","String","options","getDateTimeFormat","format","error"],"sourceRoot":"../../../src","sources":["format/date.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAC9BC,KAAoB,EACpBC,UAAkB,EAClBC,QAAoC,EACpCC,QAAgD,EAChDC,aAAkC,EAClCC,eAAe,GAAG,KAAK,EACd;EACT,MAAMC,IAAI,GAAGN,KAAK,YAAYO,IAAI,GAAGP,KAAK,GAAG,IAAIO,IAAI,CAACP,KAAK,CAAC;EAC5D,IAAIQ,MAAM,CAACC,KAAK,CAACH,IAAI,CAACI,OAAO,CAAC,CAAC,CAAC,EAAE;IACjC,OAAO,IAAAC,iCAAwB,EAC9BP,aAAa,EACb,qCAAqCQ,MAAM,CAACZ,KAAK,CAAC,iBAAiBC,UAAU,IAC9E,CAAC;EACF;EACA,MAAMY,OAAO,GAAGR,eAAe,GAAIF,QAAQ,IAAID,QAAQ,GAAI;IAAE,GAAGA,QAAQ;IAAE,GAAGC;EAAS,CAAC;EACvF;EACA,IAAI;IACH,OAAO,IAAAW,yBAAiB,EAACb,UAAU,EAAEY,OAAO,CAAC,CAACE,MAAM,CAACT,IAAI,CAAC;EAC3D,CAAC,CAAC,OAAOU,KAAK,EAAE;IACf,OAAO,IAAAL,iCAAwB,EAACP,aAAa,EAAE,yBAAyBQ,MAAM,CAACI,KAAK,CAAC,EAAE,CAAC;EACzF;AACD","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyInvalidFormatPolicy = applyInvalidFormatPolicy;
7
+ var _diagnostics = require("../config/diagnostics.js");
8
+ /** The policy as an i18n instance resolves it: with the instance's reporter. */
9
+
10
+ /**
11
+ * Applies the configured invalid-format behavior: return the placeholder, or
12
+ * throw a clear formatting error in `error` mode (FR-037, FR-045).
13
+ */
14
+ function applyInvalidFormatPolicy(policy, message) {
15
+ (policy.report ?? _diagnostics.defaultReporter)({
16
+ code: 'invalid_format',
17
+ message
18
+ });
19
+ if (policy.mode === 'error') {
20
+ throw new RangeError(`[rn-i18n] ${message}`);
21
+ }
22
+ return policy.text;
23
+ }
24
+ //# sourceMappingURL=invalid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_diagnostics","require","applyInvalidFormatPolicy","policy","message","report","defaultReporter","code","mode","RangeError","text"],"sourceRoot":"../../../src","sources":["format/invalid.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA;;AAKA;AACA;AACA;AACA;AACO,SAASC,wBAAwBA,CACvCC,MAAmC,EACnCC,OAAe,EACN;EACT,CAACD,MAAM,CAACE,MAAM,IAAIC,4BAAe,EAAE;IAAEC,IAAI,EAAE,gBAAgB;IAAEH;EAAQ,CAAC,CAAC;EACvE,IAAID,MAAM,CAACK,IAAI,KAAK,OAAO,EAAE;IAC5B,MAAM,IAAIC,UAAU,CAAC,aAAaL,OAAO,EAAE,CAAC;EAC7C;EACA,OAAOD,MAAM,CAACO,IAAI;AACnB","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatNumberValue = formatNumberValue;
7
+ var _rnCore = require("@chipmobilesdk/rn-core");
8
+ var _invalid = require("./invalid.js");
9
+ /**
10
+ * Locale-aware number formatting through the Hermes built-in
11
+ * Intl.NumberFormat. The locale default options apply unless the caller
12
+ * passes explicit overrides (FR-019).
13
+ */
14
+ function formatNumberValue(value, localeCode, defaults, override, invalidFormat) {
15
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
16
+ return (0, _invalid.applyInvalidFormatPolicy)(invalidFormat, `Cannot format invalid number value "${String(value)}" for locale "${localeCode}".`);
17
+ }
18
+ // rn-core's cached formatter (I18N-03); a bad option is a format problem, not a
19
+ // crash in render (I18N-08).
20
+ try {
21
+ return (0, _rnCore.getNumberFormat)(localeCode, {
22
+ ...defaults,
23
+ ...override
24
+ }).format(value);
25
+ } catch (error) {
26
+ return (0, _invalid.applyInvalidFormatPolicy)(invalidFormat, `Cannot format a number: ${String(error)}`);
27
+ }
28
+ }
29
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_rnCore","require","_invalid","formatNumberValue","value","localeCode","defaults","override","invalidFormat","Number","isFinite","applyInvalidFormatPolicy","String","getNumberFormat","format","error"],"sourceRoot":"../../../src","sources":["format/number.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,iBAAiBA,CAChCC,KAAa,EACbC,UAAkB,EAClBC,QAAkC,EAClCC,QAA8C,EAC9CC,aAAkC,EACzB;EACT,IAAI,OAAOJ,KAAK,KAAK,QAAQ,IAAI,CAACK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,EAAE;IACzD,OAAO,IAAAO,iCAAwB,EAC9BH,aAAa,EACb,uCAAuCI,MAAM,CAACR,KAAK,CAAC,iBAAiBC,UAAU,IAChF,CAAC;EACF;EACA;EACA;EACA,IAAI;IACH,OAAO,IAAAQ,uBAAe,EAACR,UAAU,EAAE;MAAE,GAAGC,QAAQ;MAAE,GAAGC;IAAS,CAAC,CAAC,CAACO,MAAM,CAACV,KAAK,CAAC;EAC/E,CAAC,CAAC,OAAOW,KAAK,EAAE;IACf,OAAO,IAAAJ,iCAAwB,EAACH,aAAa,EAAE,2BAA2BI,MAAM,CAACG,KAAK,CAAC,EAAE,CAAC;EAC3F;AACD","ignoreList":[]}
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SUPPORTED_UNITS = exports.KNOWN_UNIT_IDS = void 0;
7
+ Object.defineProperty(exports, "UnitConversionError", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _errors.UnitConversionError;
11
+ }
12
+ });
13
+ exports.convertUnitValue = convertUnitValue;
14
+ exports.formatUnitValue = formatUnitValue;
15
+ exports.getUnitSymbol = getUnitSymbol;
16
+ var _invalid = require("./invalid.js");
17
+ var _number = require("./number.js");
18
+ var _errors = require("../config/errors.js");
19
+ /**
20
+ * Package-owned unit registry and conversion tables. Intl.NumberFormat unit
21
+ * style is not consistently available under Hermes, so the numeric part is
22
+ * formatted through Intl and the unit symbol is appended from this registry
23
+ * (research R4). Base units: meter, kilogram, liter, celsius.
24
+ */
25
+ const UNIT_REGISTRY = {
26
+ millimeter: {
27
+ dimension: 'length',
28
+ factor: 0.001,
29
+ symbol: 'mm'
30
+ },
31
+ centimeter: {
32
+ dimension: 'length',
33
+ factor: 0.01,
34
+ symbol: 'cm'
35
+ },
36
+ meter: {
37
+ dimension: 'length',
38
+ factor: 1,
39
+ symbol: 'm'
40
+ },
41
+ kilometer: {
42
+ dimension: 'length',
43
+ factor: 1000,
44
+ symbol: 'km'
45
+ },
46
+ inch: {
47
+ dimension: 'length',
48
+ factor: 0.0254,
49
+ symbol: 'in'
50
+ },
51
+ foot: {
52
+ dimension: 'length',
53
+ factor: 0.3048,
54
+ symbol: 'ft'
55
+ },
56
+ mile: {
57
+ dimension: 'length',
58
+ factor: 1609.344,
59
+ symbol: 'mi'
60
+ },
61
+ gram: {
62
+ dimension: 'mass',
63
+ factor: 0.001,
64
+ symbol: 'g'
65
+ },
66
+ kilogram: {
67
+ dimension: 'mass',
68
+ factor: 1,
69
+ symbol: 'kg'
70
+ },
71
+ ounce: {
72
+ dimension: 'mass',
73
+ factor: 0.028349523125,
74
+ symbol: 'oz'
75
+ },
76
+ pound: {
77
+ dimension: 'mass',
78
+ factor: 0.45359237,
79
+ symbol: 'lb'
80
+ },
81
+ milliliter: {
82
+ dimension: 'volume',
83
+ factor: 0.001,
84
+ symbol: 'ml'
85
+ },
86
+ liter: {
87
+ dimension: 'volume',
88
+ factor: 1,
89
+ symbol: 'l'
90
+ },
91
+ gallon: {
92
+ dimension: 'volume',
93
+ factor: 3.785411784,
94
+ symbol: 'gal'
95
+ },
96
+ celsius: {
97
+ dimension: 'temperature',
98
+ factor: 1,
99
+ symbol: '°C'
100
+ },
101
+ fahrenheit: {
102
+ dimension: 'temperature',
103
+ factor: 1,
104
+ symbol: '°F'
105
+ },
106
+ kelvin: {
107
+ dimension: 'temperature',
108
+ factor: 1,
109
+ symbol: 'K'
110
+ }
111
+ };
112
+ const SUPPORTED_UNITS = exports.SUPPORTED_UNITS = Object.keys(UNIT_REGISTRY);
113
+ const KNOWN_UNIT_IDS = exports.KNOWN_UNIT_IDS = new Set(SUPPORTED_UNITS);
114
+
115
+ // Kept importable from here for compatibility; the errors live in config/errors.ts.
116
+
117
+ function getUnitSymbol(unit) {
118
+ return UNIT_REGISTRY[unit].symbol;
119
+ }
120
+ function toCelsius(value, from) {
121
+ switch (from) {
122
+ case 'fahrenheit':
123
+ return (value - 32) * 5 / 9;
124
+ case 'kelvin':
125
+ return value - 273.15;
126
+ default:
127
+ return value;
128
+ }
129
+ }
130
+ function fromCelsius(value, to) {
131
+ switch (to) {
132
+ case 'fahrenheit':
133
+ return value * 9 / 5 + 32;
134
+ case 'kelvin':
135
+ return value + 273.15;
136
+ default:
137
+ return value;
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Converts between compatible supported units. Unknown units or conversions
143
+ * across dimensions throw a UnitConversionError (FR-044/FR-045).
144
+ */
145
+ function convertUnitValue(value, from, to) {
146
+ const fromDef = UNIT_REGISTRY[from];
147
+ const toDef = UNIT_REGISTRY[to];
148
+ if (!fromDef || !toDef) {
149
+ throw new _errors.UnitConversionError(`Unknown unit in conversion "${from}" -> "${to}".`);
150
+ }
151
+ if (fromDef.dimension !== toDef.dimension) {
152
+ throw new _errors.UnitConversionError(`Cannot convert between incompatible dimensions "${fromDef.dimension}" (${from}) and "${toDef.dimension}" (${to}).`);
153
+ }
154
+ if (!Number.isFinite(value)) {
155
+ throw new _errors.UnitConversionError(`Cannot convert invalid value "${String(value)}" from "${from}" to "${to}".`);
156
+ }
157
+ if (from === to) {
158
+ return value;
159
+ }
160
+ if (fromDef.dimension === 'temperature') {
161
+ return fromCelsius(toCelsius(value, from), to);
162
+ }
163
+ return value * fromDef.factor / toDef.factor;
164
+ }
165
+ /**
166
+ * Converts (when requested) and formats a measurement value: locale-aware
167
+ * numeric part via Intl.NumberFormat plus the package-owned unit symbol.
168
+ */
169
+ function formatUnitValue(value, localeCode, localeDefaultUnit, numberDefaults, options, invalidFormat) {
170
+ const {
171
+ from = localeDefaultUnit,
172
+ to = from,
173
+ ...numberOptions
174
+ } = options ?? {};
175
+ let converted;
176
+ try {
177
+ converted = convertUnitValue(value, from, to);
178
+ } catch (error) {
179
+ return (0, _invalid.applyInvalidFormatPolicy)(invalidFormat, error instanceof Error ? error.message : String(error));
180
+ }
181
+ const formatted = (0, _number.formatNumberValue)(converted, localeCode, numberDefaults, numberOptions, invalidFormat);
182
+ return `${formatted} ${getUnitSymbol(to)}`;
183
+ }
184
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_invalid","require","_number","_errors","UNIT_REGISTRY","millimeter","dimension","factor","symbol","centimeter","meter","kilometer","inch","foot","mile","gram","kilogram","ounce","pound","milliliter","liter","gallon","celsius","fahrenheit","kelvin","SUPPORTED_UNITS","exports","Object","keys","KNOWN_UNIT_IDS","Set","getUnitSymbol","unit","toCelsius","value","from","fromCelsius","to","convertUnitValue","fromDef","toDef","UnitConversionError","Number","isFinite","String","formatUnitValue","localeCode","localeDefaultUnit","numberDefaults","options","invalidFormat","numberOptions","converted","error","applyInvalidFormatPolicy","Error","message","formatted","formatNumberValue"],"sourceRoot":"../../../src","sources":["format/units.ts"],"mappings":";;;;;;;;;;;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAwCA,IAAAE,OAAA,GAAAF,OAAA;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,aAA6C,GAAG;EACrDC,UAAU,EAAE;IAAEC,SAAS,EAAE,QAAQ;IAAEC,MAAM,EAAE,KAAK;IAAEC,MAAM,EAAE;EAAK,CAAC;EAChEC,UAAU,EAAE;IAAEH,SAAS,EAAE,QAAQ;IAAEC,MAAM,EAAE,IAAI;IAAEC,MAAM,EAAE;EAAK,CAAC;EAC/DE,KAAK,EAAE;IAAEJ,SAAS,EAAE,QAAQ;IAAEC,MAAM,EAAE,CAAC;IAAEC,MAAM,EAAE;EAAI,CAAC;EACtDG,SAAS,EAAE;IAAEL,SAAS,EAAE,QAAQ;IAAEC,MAAM,EAAE,IAAI;IAAEC,MAAM,EAAE;EAAK,CAAC;EAC9DI,IAAI,EAAE;I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,GAAGO,SAAS,IAAI1B,aAAa,CAACM,EAAE,CAAC,EAAE;AAC3C","ignoreList":[]}
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createI18n = createI18n;
7
+ var _diagnostics = require("./config/diagnostics.js");
8
+ var _validateConfig = require("./config/validateConfig.js");
9
+ var _activeLocale = require("./locale/activeLocale.js");
10
+ var _deviceLocale = require("./locale/deviceLocale.js");
11
+ var _persistence = require("./locale/persistence.js");
12
+ var _plurals = require("./translation/plurals.js");
13
+ var _resolver = require("./translation/resolver.js");
14
+ var _runtimeKeys = require("./translation/runtimeKeys.js");
15
+ var _currency = require("./format/currency.js");
16
+ var _date = require("./format/date.js");
17
+ var _number = require("./format/number.js");
18
+ var _units = require("./format/units.js");
19
+ const DEFAULT_MISSING = {
20
+ mode: 'key'
21
+ };
22
+ const DEFAULT_INVALID = {
23
+ mode: 'placeholder',
24
+ text: '—'
25
+ };
26
+
27
+ /**
28
+ * Creates an I18n instance from an app-owned configuration. Validation runs
29
+ * eagerly and throws an I18nConfigError before any localized content can be
30
+ * served (FR-003). Pass the app's generated key type for typed lookups:
31
+ * `createI18n<AppI18nKey>(config)`.
32
+ */
33
+ function createI18n(config) {
34
+ (0, _validateConfig.validateConfig)(config, _units.KNOWN_UNIT_IDS);
35
+ const locales = [...config.locales];
36
+ const localesByCode = new Map(locales.map(locale => [locale.code, locale]));
37
+ const missingTranslation = config.missingTranslation ?? DEFAULT_MISSING;
38
+ const report = (0, _diagnostics.createReporter)(config.onDiagnostic);
39
+ const invalidFormat = {
40
+ ...(config.invalidFormat ?? DEFAULT_INVALID),
41
+ report
42
+ };
43
+ const persistenceEnabled = config.persistLocale !== false && !!config.storage;
44
+ const runtimeEntries = (0, _runtimeKeys.createRuntimeRegistry)(config.runtimeEntries);
45
+ const store = (0, _activeLocale.createActiveLocaleStore)({
46
+ code: config.primaryLocale,
47
+ source: 'primaryFallback',
48
+ recovered: false
49
+ }, report);
50
+
51
+ // A language this package has no plural rule for falls back to
52
+ // `count === 1 ? one : other`, which is wrong for most of the world. Said
53
+ // once per locale, at creation, rather than never (I18N-12).
54
+ for (const locale of locales) {
55
+ if (!(0, _plurals.hasPluralRule)(locale)) {
56
+ report({
57
+ code: 'plural_rule_default',
58
+ locale: locale.code,
59
+ message: `No plural rule for "${locale.code}"; falling back to "count === 1 selects one". ` + 'Declare `pluralRule` on the locale if that is not how the language works.'
60
+ });
61
+ }
62
+ }
63
+ const resolverContext = {
64
+ localesByCode,
65
+ resources: config.resources,
66
+ runtimeEntries,
67
+ missingTranslation,
68
+ warned: new Set(),
69
+ report
70
+ };
71
+ const activeLocale = () => {
72
+ const locale = localesByCode.get(store.get().code);
73
+ if (!locale) {
74
+ // Unreachable after validation; guards against external mutation.
75
+ throw new Error(`[rn-i18n] Active locale "${store.get().code}" is not configured.`);
76
+ }
77
+ return locale;
78
+ };
79
+
80
+ /** persisted → device → primary fallback; shared by `init` and `initSync`. */
81
+ const resolveInitialLocale = persisted => {
82
+ if (persisted) {
83
+ if (localesByCode.has(persisted)) {
84
+ store.set({
85
+ code: persisted,
86
+ source: 'persisted',
87
+ recovered: false
88
+ });
89
+ return;
90
+ }
91
+ report({
92
+ code: 'locale_unsupported',
93
+ locale: persisted,
94
+ message: `Persisted locale "${persisted}" is no longer supported; recovering to "${config.primaryLocale}".`
95
+ });
96
+ store.set({
97
+ code: config.primaryLocale,
98
+ source: 'primaryFallback',
99
+ recovered: true
100
+ });
101
+ return;
102
+ }
103
+ const provider = config.deviceLocale ?? _deviceLocale.defaultDeviceLocaleProvider;
104
+ const match = (0, _deviceLocale.matchSupportedLocale)(provider(), locales);
105
+ store.set(match ? {
106
+ code: match.code,
107
+ source: match.source,
108
+ recovered: false
109
+ } : {
110
+ code: config.primaryLocale,
111
+ source: 'primaryFallback',
112
+ recovered: false
113
+ });
114
+ };
115
+
116
+ /**
117
+ * `init()` runs once, and loses to the user.
118
+ *
119
+ * It used to be re-run by every caller (StrictMode mounts an effect twice),
120
+ * and the persisted value it had awaited was written in unconditionally — so
121
+ * a locale the user picked, or a deep link set, while the read was in flight
122
+ * was overwritten by the old one (I18N-07).
123
+ */
124
+ let initialized;
125
+ let switched = false;
126
+ const runInit = async () => {
127
+ const persisted = persistenceEnabled && config.storage ? await (0, _persistence.readPersistedLocale)(config.storage, report) : null;
128
+ if (switched) {
129
+ // The user chose while the read was in flight; their choice stands.
130
+ return;
131
+ }
132
+ resolveInitialLocale(persisted);
133
+ };
134
+ return {
135
+ init() {
136
+ initialized ??= runInit();
137
+ return initialized;
138
+ },
139
+ initSync() {
140
+ if (!persistenceEnabled || !config.storage) {
141
+ resolveInitialLocale(null);
142
+ return true;
143
+ }
144
+ const {
145
+ storage
146
+ } = config;
147
+ if (typeof storage.getItemSync !== 'function') {
148
+ return false;
149
+ }
150
+ resolveInitialLocale((0, _persistence.readPersistedLocaleSync)(storage, report));
151
+ return true;
152
+ },
153
+ t(key, vars, options) {
154
+ return (0, _resolver.translate)(resolverContext, store.get().code, key, vars, options);
155
+ },
156
+ getLocale() {
157
+ return store.get();
158
+ },
159
+ async setLocale(code) {
160
+ if (!localesByCode.has(code)) {
161
+ throw new Error(`[rn-i18n] Cannot switch to unsupported locale "${code}".`);
162
+ }
163
+ switched = true;
164
+ const current = store.get();
165
+ if (current.code === code && current.source === 'runtimeSwitch') {
166
+ // Already this locale, by this route: re-rendering the whole tree and
167
+ // rewriting storage would change nothing (I18N-07).
168
+ return;
169
+ }
170
+ store.set({
171
+ code,
172
+ source: 'runtimeSwitch',
173
+ recovered: false
174
+ });
175
+ if (persistenceEnabled && config.storage) {
176
+ await (0, _persistence.writePersistedLocale)(config.storage, code, report);
177
+ }
178
+ },
179
+ async useDeviceLocale() {
180
+ switched = true;
181
+ if (persistenceEnabled && config.storage) {
182
+ await (0, _persistence.clearPersistedLocale)(config.storage, report);
183
+ }
184
+ const provider = config.deviceLocale ?? _deviceLocale.defaultDeviceLocaleProvider;
185
+ const match = (0, _deviceLocale.matchSupportedLocale)(provider(), locales);
186
+ store.set(match ? {
187
+ code: match.code,
188
+ source: match.source,
189
+ recovered: false
190
+ } : {
191
+ code: config.primaryLocale,
192
+ source: 'primaryFallback',
193
+ recovered: false
194
+ });
195
+ return store.get();
196
+ },
197
+ getSupportedLocales() {
198
+ return locales;
199
+ },
200
+ formatNumber(value, options) {
201
+ const locale = activeLocale();
202
+ return (0, _number.formatNumberValue)(value, locale.code, locale.defaultNumberFormat, options, invalidFormat);
203
+ },
204
+ formatDate(value, options, formatting) {
205
+ const locale = activeLocale();
206
+ return (0, _date.formatDateValue)(value, locale.code, locale.defaultDateFormat, options, invalidFormat, formatting?.replaceDefaults === true);
207
+ },
208
+ formatCurrency(value, currency, options) {
209
+ const locale = activeLocale();
210
+ return (0, _currency.formatCurrencyValue)(value, locale.code, locale.defaultCurrency, currency, options, invalidFormat);
211
+ },
212
+ formatUnit(value, options) {
213
+ const locale = activeLocale();
214
+ return (0, _units.formatUnitValue)(value, locale.code, locale.defaultUnit, locale.defaultNumberFormat, options, invalidFormat);
215
+ },
216
+ convertUnit(value, from, to) {
217
+ return (0, _units.convertUnitValue)(value, from, to);
218
+ },
219
+ registerRuntimeEntries(entries) {
220
+ (0, _runtimeKeys.registerRuntimeEntries)(runtimeEntries, entries);
221
+ // What `t()` answers has changed, so every subscriber has to read again:
222
+ // a feature that registered its entries after mounting used to leave the
223
+ // screen showing the key (I18N-06).
224
+ store.bump();
225
+ },
226
+ subscribe(listener) {
227
+ return store.subscribe(listener);
228
+ },
229
+ getVersion() {
230
+ return store.getVersion();
231
+ }
232
+ };
233
+ }
234
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_diagnostics","require","_validateConfig","_activeLocale","_deviceLocale","_persistence","_plurals","_resolver","_runtimeKeys","_currency","_date","_number","_units","DEFAULT_MISSING","mode","DEFAULT_INVALID","text","createI18n","config","validateConfig","KNOWN_UNIT_IDS","locales","localesByCode","Map","map","locale","code","missingTranslation","report","createReporter","onDiagnostic","invalidFormat","persistenceEnabled","persistLocale","storage","runtimeEntries","createRuntimeRegistry","store","createActiveLocaleStore","primaryLocale","source","recovered","hasPluralRule","message","resolverContext","resources","warned","Set","activeLocale","get","Error","resolveInitialLocale","persisted","has","set","provider","deviceLocale","defaultDeviceLocaleProvider","match","matchSupportedLocale","initialized","switched","runInit","readPersistedLocale","init","initSync","getItemSync","readPersistedLocaleSync","t","key","vars","options","translate","getLocale","setLocale","current","writePersistedLocale","useDeviceLocale","clearPersistedLocale","getSupportedLocales","formatNumber","value","formatNumberValue","defaultNumberFormat","formatDate","formatting","formatDateValue","defaultDateFormat","replaceDefaults","formatCurrency","currency","formatCurrencyValue","defaultCurrency","formatUnit","formatUnitValue","defaultUnit","convertUnit","from","to","convertUnitValue","registerRuntimeEntries","entries","bump","subscribe","listener","getVersion"],"sourceRoot":"../../src","sources":["i18n.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAaA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAMA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAEA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,KAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA;AACA,IAAAW,MAAA,GAAAX,OAAA;AA0CA,MAAMY,eAAyC,GAAG;EAAEC,IAAI,EAAE;AAAM,CAAC;AACjE,MAAMC,eAAoC,GAAG;EAAED,IAAI,EAAE,aAAa;EAAEE,IAAI,EAAE;AAAI,CAAC;;AAE/E;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAA+BC,MAAkB,EAAc;EACxF,IAAAC,8BAAc,EAACD,MAAM,EAAEE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KAAK,EAAEgB,IAAI,EAAEC,EAAE,EAAE;MAC5B,OAAO,IAAAC,uBAAgB,EAAClB,KAAK,EAAEgB,IAAI,EAAEC,EAAE,CAAC;IACzC,CAAC;IAEDE,sBAAsBA,CAACC,OAAO,EAAE;MAC/B,IAAAD,mCAAsB,EAACjE,cAAc,EAAEkE,OAAO,CAAC;MAC/C;MACA;MACA;MACAhE,KAAK,CAACiE,IAAI,CAAC,CAAC;IACb,CAAC;IAEDC,SAASA,CAACC,QAAQ,EAAE;MACnB,OAAOnE,KAAK,CAACkE,SAAS,CAACC,QAAQ,CAAC;IACjC,CAAC;IAEDC,UAAUA,CAAA,EAAG;MACZ,OAAOpE,KAAK,CAACoE,UAAU,CAAC,CAAC;IAC1B;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "I18nConfigError", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _types.I18nConfigError;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "I18nProvider", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _I18nProvider.I18nProvider;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "LOCALE_STORAGE_KEY", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _persistence.LOCALE_STORAGE_KEY;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "SUPPORTED_UNITS", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _units.SUPPORTED_UNITS;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "UnitConversionError", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _units.UnitConversionError;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "convertUnit", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _units.convertUnitValue;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "createI18n", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _i18n.createI18n;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "defaultDeviceLocaleProvider", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _deviceLocale.defaultDeviceLocaleProvider;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "getUnitSymbol", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _units.getUnitSymbol;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "localeStorageFromKeyValue", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _keyValueStorage.localeStorageFromKeyValue;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "runtimeEntriesFromCatalog", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _catalog.runtimeEntriesFromCatalog;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "useLocale", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _hooks.useLocale;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "useTranslation", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _hooks.useTranslation;
82
+ }
83
+ });
84
+ var _i18n = require("./i18n.js");
85
+ var _types = require("./config/types.js");
86
+ var _catalog = require("./config/catalog.js");
87
+ var _keyValueStorage = require("./locale/keyValueStorage.js");
88
+ var _persistence = require("./locale/persistence.js");
89
+ var _deviceLocale = require("./locale/deviceLocale.js");
90
+ var _units = require("./format/units.js");
91
+ var _I18nProvider = require("./react/I18nProvider.js");
92
+ var _hooks = require("./react/hooks.js");
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_types","_catalog","_keyValueStorage","_persistence","_deviceLocale","_units","_I18nProvider","_hooks"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AA6BA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAQA,IAAAO,aAAA,GAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA","ignoreList":[]}