gt-react 4.0.11 → 4.0.13

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 (46) hide show
  1. package/dist/cookies/getLocaleCookie.d.ts +8 -0
  2. package/dist/cookies/getLocaleCookie.d.ts.map +1 -0
  3. package/dist/cookies/getLocaleCookie.js +28 -0
  4. package/dist/cookies/getLocaleCookie.js.map +1 -0
  5. package/dist/hooks/useBrowserLocale.d.ts +19 -4
  6. package/dist/hooks/useBrowserLocale.d.ts.map +1 -1
  7. package/dist/hooks/useBrowserLocale.js +24 -27
  8. package/dist/hooks/useBrowserLocale.js.map +1 -1
  9. package/dist/hooks/useDefaultLocale.d.ts +9 -1
  10. package/dist/hooks/useDefaultLocale.d.ts.map +1 -1
  11. package/dist/hooks/useDefaultLocale.js +9 -1
  12. package/dist/hooks/useDefaultLocale.js.map +1 -1
  13. package/dist/hooks/useGT.d.ts +8 -3
  14. package/dist/hooks/useGT.d.ts.map +1 -1
  15. package/dist/hooks/useGT.js +8 -3
  16. package/dist/hooks/useGT.js.map +1 -1
  17. package/dist/hooks/useLocale.d.ts +7 -1
  18. package/dist/hooks/useLocale.d.ts.map +1 -1
  19. package/dist/hooks/useLocale.js +7 -1
  20. package/dist/hooks/useLocale.js.map +1 -1
  21. package/dist/provider/GTProvider.d.ts +14 -0
  22. package/dist/provider/GTProvider.d.ts.map +1 -1
  23. package/dist/provider/GTProvider.js +17 -1
  24. package/dist/provider/GTProvider.js.map +1 -1
  25. package/dist/variables/Currency.d.ts +31 -11
  26. package/dist/variables/Currency.d.ts.map +1 -1
  27. package/dist/variables/Currency.js +24 -2
  28. package/dist/variables/Currency.js.map +1 -1
  29. package/dist/variables/DateTime.d.ts +21 -2
  30. package/dist/variables/DateTime.d.ts.map +1 -1
  31. package/dist/variables/DateTime.js +20 -2
  32. package/dist/variables/DateTime.js.map +1 -1
  33. package/dist/variables/Num.d.ts +30 -10
  34. package/dist/variables/Num.d.ts.map +1 -1
  35. package/dist/variables/Num.js +24 -2
  36. package/dist/variables/Num.js.map +1 -1
  37. package/dist/variables/Var.d.ts +26 -9
  38. package/dist/variables/Var.d.ts.map +1 -1
  39. package/dist/variables/Var.js +21 -2
  40. package/dist/variables/Var.js.map +1 -1
  41. package/package.json +1 -1
  42. package/scratchpad.js +5 -29
  43. package/dist/primitives/settings.d.ts +0 -4
  44. package/dist/primitives/settings.d.ts.map +0 -1
  45. package/dist/primitives/settings.js +0 -7
  46. package/dist/primitives/settings.js.map +0 -1
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Function to get the value of a specific cookie by its name.
3
+ *
4
+ * @param {string} name - The name of the cookie to retrieve.
5
+ * @returns {string|null} - The value of the cookie, or null if not found.
6
+ */
7
+ export default function getLocaleCookie(name?: string): string | null;
8
+ //# sourceMappingURL=getLocaleCookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocaleCookie.d.ts","sourceRoot":"","sources":["../../src/cookies/getLocaleCookie.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,IAAI,GAAE,MAAyB,GAAG,MAAM,GAAG,IAAI,CAkBtF"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getLocaleCookie;
4
+ var primitives_1 = require("../primitives/primitives");
5
+ /**
6
+ * Function to get the value of a specific cookie by its name.
7
+ *
8
+ * @param {string} name - The name of the cookie to retrieve.
9
+ * @returns {string|null} - The value of the cookie, or null if not found.
10
+ */
11
+ function getLocaleCookie(name) {
12
+ if (name === void 0) { name = primitives_1.localeCookieName; }
13
+ var cookieString = document.cookie;
14
+ // Split the cookies string by "; " to get an array of "key=value" strings
15
+ var cookiesArray = cookieString.split("; ");
16
+ // Loop through the array to find the cookie with the specified name
17
+ for (var _i = 0, cookiesArray_1 = cookiesArray; _i < cookiesArray_1.length; _i++) {
18
+ var cookie = cookiesArray_1[_i];
19
+ var _a = cookie.split("="), cookieName = _a[0], cookieValue = _a[1];
20
+ // Check if this cookie has the name we are looking for
21
+ if (cookieName === name) {
22
+ return decodeURIComponent(cookieValue);
23
+ }
24
+ }
25
+ // If the cookie is not found, return null
26
+ return null;
27
+ }
28
+ //# sourceMappingURL=getLocaleCookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocaleCookie.js","sourceRoot":"","sources":["../../src/cookies/getLocaleCookie.ts"],"names":[],"mappings":";;AAQA,kCAkBC;AA1BD,uDAA4D;AAE5D;;;;;GAKG;AACH,SAAwB,eAAe,CAAC,IAA+B;IAA/B,qBAAA,EAAA,OAAe,6BAAgB;IACnE,IAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC;IAErC,0EAA0E;IAC1E,IAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE9C,oEAAoE;IACpE,KAAmB,UAAY,EAAZ,6BAAY,EAAZ,0BAAY,EAAZ,IAAY,EAAE,CAAC;QAA7B,IAAI,MAAM,qBAAA;QACP,IAAA,KAA4B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAA5C,UAAU,QAAA,EAAE,WAAW,QAAqB,CAAC;QAEpD,uDAAuD;QACvD,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,0CAA0C;IAC1C,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -1,7 +1,22 @@
1
1
  /**
2
- * Custom hook to get the browser's default language.
3
- * @param {string} defaultLocale - The default locale to use if browser locale is not available.
4
- * @returns {string} The default language of the browser.
2
+ * Hook to retrieve the browser's default language, with support for a fallback and locale stored in a cookie.
3
+ *
4
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The default locale to use if the browser locale is not available.
5
+ * @param {string} [cookieName=localeCookieName] - The name of the cookie to check for a stored locale. If omitted, no cookie is used.
6
+ * @returns {string} The resolved browser locale, either from the cookie, browser settings, or the default locale.
7
+ *
8
+ * @example
9
+ * const browserLocale = useBrowserLocale('en-US');
10
+ * console.log(browserLocale); // Outputs the browser's locale, or 'en-US' if unavailable
11
+ *
12
+ * @example
13
+ * const browserLocale = useBrowserLocale('fr', 'localeCookie');
14
+ * console.log(browserLocale); // Outputs locale from cookie 'localeCookie' if available, or browser's locale otherwise
15
+ *
16
+ * @description
17
+ * This hook attempts to determine the browser's preferred language. If a locale is stored in a cookie (specified by `cookieName`),
18
+ * it will take precedence. If not, it falls back to the `navigator.language` or `navigator.userLanguage`. If none of these are available,
19
+ * the provided `defaultLocale` is used.
5
20
  */
6
- export default function useBrowserLocale(defaultLocale?: string): string;
21
+ export default function useBrowserLocale(defaultLocale?: string, cookieName?: string): string;
7
22
  //# sourceMappingURL=useBrowserLocale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBrowserLocale.d.ts","sourceRoot":"","sources":["../../src/hooks/useBrowserLocale.ts"],"names":[],"mappings":"AA+BA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,aAAa,GAAE,MAA6B,GAAG,MAAM,CAQ7F"}
1
+ {"version":3,"file":"useBrowserLocale.d.ts","sourceRoot":"","sources":["../../src/hooks/useBrowserLocale.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,aAAa,GAAE,MAA6B,EAAE,UAAU,GAAE,MAAyB,GAAG,MAAM,CAOpI"}
@@ -1,42 +1,39 @@
1
1
  "use strict";
2
2
  'use client';
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  exports.default = useBrowserLocale;
5
8
  var react_1 = require("react");
6
9
  var primitives_1 = require("../primitives/primitives");
10
+ var getLocaleCookie_1 = __importDefault(require("../cookies/getLocaleCookie"));
7
11
  /**
8
- * Function to get the value of a specific cookie by its name.
12
+ * Hook to retrieve the browser's default language, with support for a fallback and locale stored in a cookie.
9
13
  *
10
- * @param {string} name - The name of the cookie to retrieve.
11
- * @returns {string|null} - The value of the cookie, or null if not found.
12
- */
13
- function getCookieValue(name) {
14
- var cookieString = document.cookie;
15
- // Split the cookies string by "; " to get an array of "key=value" strings
16
- var cookiesArray = cookieString.split("; ");
17
- // Loop through the array to find the cookie with the specified name
18
- for (var _i = 0, cookiesArray_1 = cookiesArray; _i < cookiesArray_1.length; _i++) {
19
- var cookie = cookiesArray_1[_i];
20
- var _a = cookie.split("="), cookieName = _a[0], cookieValue = _a[1];
21
- // Check if this cookie has the name we are looking for
22
- if (cookieName === name) {
23
- return decodeURIComponent(cookieValue);
24
- }
25
- }
26
- // If the cookie is not found, return null
27
- return null;
28
- }
29
- /**
30
- * Custom hook to get the browser's default language.
31
- * @param {string} defaultLocale - The default locale to use if browser locale is not available.
32
- * @returns {string} The default language of the browser.
14
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The default locale to use if the browser locale is not available.
15
+ * @param {string} [cookieName=localeCookieName] - The name of the cookie to check for a stored locale. If omitted, no cookie is used.
16
+ * @returns {string} The resolved browser locale, either from the cookie, browser settings, or the default locale.
17
+ *
18
+ * @example
19
+ * const browserLocale = useBrowserLocale('en-US');
20
+ * console.log(browserLocale); // Outputs the browser's locale, or 'en-US' if unavailable
21
+ *
22
+ * @example
23
+ * const browserLocale = useBrowserLocale('fr', 'localeCookie');
24
+ * console.log(browserLocale); // Outputs locale from cookie 'localeCookie' if available, or browser's locale otherwise
25
+ *
26
+ * @description
27
+ * This hook attempts to determine the browser's preferred language. If a locale is stored in a cookie (specified by `cookieName`),
28
+ * it will take precedence. If not, it falls back to the `navigator.language` or `navigator.userLanguage`. If none of these are available,
29
+ * the provided `defaultLocale` is used.
33
30
  */
34
- function useBrowserLocale(defaultLocale) {
31
+ function useBrowserLocale(defaultLocale, cookieName) {
35
32
  if (defaultLocale === void 0) { defaultLocale = primitives_1.libraryDefaultLocale; }
33
+ if (cookieName === void 0) { cookieName = primitives_1.localeCookieName; }
36
34
  var _a = (0, react_1.useState)(''), locale = _a[0], setLocale = _a[1];
37
35
  (0, react_1.useEffect)(function () {
38
- var localeFromCookie = getCookieValue(primitives_1.localeCookieName);
39
- var browserLocale = localeFromCookie || navigator.language || (navigator === null || navigator === void 0 ? void 0 : navigator.userLanguage) || defaultLocale;
36
+ var browserLocale = (cookieName ? (0, getLocaleCookie_1.default)(cookieName) : undefined) || navigator.language || (navigator === null || navigator === void 0 ? void 0 : navigator.userLanguage) || defaultLocale;
40
37
  setLocale(browserLocale);
41
38
  }, [defaultLocale]);
42
39
  return locale;
@@ -1 +1 @@
1
- {"version":3,"file":"useBrowserLocale.js","sourceRoot":"","sources":["../../src/hooks/useBrowserLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;AAoCZ,mCAQC;AA1CD,+BAA4C;AAC5C,uDAAkF;AAElF;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY;IAChC,IAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC;IAErC,0EAA0E;IAC1E,IAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE9C,oEAAoE;IACpE,KAAmB,UAAY,EAAZ,6BAAY,EAAZ,0BAAY,EAAZ,IAAY,EAAE,CAAC;QAA7B,IAAI,MAAM,qBAAA;QACP,IAAA,KAA4B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAA5C,UAAU,QAAA,EAAE,WAAW,QAAqB,CAAC;QAEpD,uDAAuD;QACvD,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,0CAA0C;IAC1C,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAwB,gBAAgB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CAAC;IACpB,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -1,5 +1,13 @@
1
1
  /**
2
- * @returns {string} The default locale.
2
+ * Retrieves the application's default locale from the `<GTProvider>` context.
3
+ *
4
+ * If no default locale is passed to the `<GTProvider>`, it defaults to providing 'en'.
5
+ *
6
+ * @returns {string} The application's default locale, e.g., 'en-US'.
7
+ *
8
+ * @example
9
+ * const locale = useDefaultLocale();
10
+ * console.log(locale); // 'en-US'
3
11
  */
4
12
  export default function useDefaultLocale(): string;
5
13
  //# sourceMappingURL=useDefaultLocale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDefaultLocale.d.ts","sourceRoot":"","sources":["../../src/hooks/useDefaultLocale.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,IAAI,MAAM,CAIjD"}
1
+ {"version":3,"file":"useDefaultLocale.d.ts","sourceRoot":"","sources":["../../src/hooks/useDefaultLocale.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,IAAI,MAAM,CAIjD"}
@@ -7,7 +7,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.default = useDefaultLocale;
8
8
  var GTContext_1 = __importDefault(require("../provider/GTContext"));
9
9
  /**
10
- * @returns {string} The default locale.
10
+ * Retrieves the application's default locale from the `<GTProvider>` context.
11
+ *
12
+ * If no default locale is passed to the `<GTProvider>`, it defaults to providing 'en'.
13
+ *
14
+ * @returns {string} The application's default locale, e.g., 'en-US'.
15
+ *
16
+ * @example
17
+ * const locale = useDefaultLocale();
18
+ * console.log(locale); // 'en-US'
11
19
  */
12
20
  function useDefaultLocale() {
13
21
  return (0, GTContext_1.default)("useDefaultLocale(): Unable to access default locale outside of a <GTProvider>").defaultLocale;
@@ -1 +1 @@
1
- {"version":3,"file":"useDefaultLocale.js","sourceRoot":"","sources":["../../src/hooks/useDefaultLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAOZ,mCAIC;AATD,oEAAiD;AAEjD;;GAEG;AACH,SAAwB,gBAAgB;IACpC,OAAO,IAAA,mBAAY,EACf,+EAA+E,CAClF,CAAC,aAAa,CAAC;AACpB,CAAC"}
1
+ {"version":3,"file":"useDefaultLocale.js","sourceRoot":"","sources":["../../src/hooks/useDefaultLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAeZ,mCAIC;AAjBD,oEAAiD;AAEjD;;;;;;;;;;GAUG;AACH,SAAwB,gBAAgB;IACpC,OAAO,IAAA,mBAAY,EACf,+EAA+E,CAClF,CAAC,aAAa,CAAC;AACpB,CAAC"}
@@ -1,11 +1,16 @@
1
1
  import { ReactNode } from "react";
2
2
  /**
3
- * Custom hook to provide a translation function using a given context.
4
- *
5
- * This hook allows for optional prefixing of translation keys with a provided `id`.
3
+ * Gets the translation function `t` provided by `<GTProvider>`.
6
4
  *
7
5
  * @param {string} [id] - Optional prefix to prepend to the translation keys.
8
6
  * @returns {Function} A translation function that accepts a key string and returns the translated value.
7
+ *
8
+ * @example
9
+ * const t = useGT('user');
10
+ * console.log(t('name')); // Translates item 'user.name'
11
+ *
12
+ * const t = useTranslation();
13
+ * console.log(t('hello')); // Translates item 'hello'
9
14
  */
10
15
  export default function useGT(id?: string): (id: string, options?: Record<string, any>, f?: Function) => ReactNode;
11
16
  //# sourceMappingURL=useGT.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../src/hooks/useGT.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AAGtD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,GAAE,MAAW,GACzC,CACI,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,CAAC,EAAE,QAAQ,KACX,SAAS,CAuBjB"}
1
+ {"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../src/hooks/useGT.ts"],"names":[],"mappings":"AAEA,OAAc,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AAGtD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,GAAE,MAAW,GACzC,CACI,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,CAAC,EAAE,QAAQ,KACX,SAAS,CAuBjB"}
@@ -7,12 +7,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.default = useGT;
8
8
  var GTContext_1 = __importDefault(require("../provider/GTContext"));
9
9
  /**
10
- * Custom hook to provide a translation function using a given context.
11
- *
12
- * This hook allows for optional prefixing of translation keys with a provided `id`.
10
+ * Gets the translation function `t` provided by `<GTProvider>`.
13
11
  *
14
12
  * @param {string} [id] - Optional prefix to prepend to the translation keys.
15
13
  * @returns {Function} A translation function that accepts a key string and returns the translated value.
14
+ *
15
+ * @example
16
+ * const t = useGT('user');
17
+ * console.log(t('name')); // Translates item 'user.name'
18
+ *
19
+ * const t = useTranslation();
20
+ * console.log(t('hello')); // Translates item 'hello'
16
21
  */
17
22
  function useGT(id) {
18
23
  if (id === void 0) { id = ''; }
@@ -1 +1 @@
1
- {"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../src/hooks/useGT.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAaZ,wBA4BC;AAtCD,oEAAiD;AAEjD;;;;;;;GAOG;AACH,SAAwB,KAAK,CAAC,EAAe;IAAf,mBAAA,EAAA,OAAe;IAOzC,4DAA4D;IAC5D,IAAM,KAAK,GAAG,UAAC,MAAc;QACzB,IAAI,EAAE,IAAI,MAAM;YAAE,OAAO,UAAG,EAAE,cAAI,MAAM,CAAE,CAAC;QAC3C,OAAO,EAAE,CAAC,CAAC,CAAC,EAA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,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAM,WAAW,GAAG,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,IAAI,CAAC,aAAM,EAAE,2DAAiD,UAAU,OAAI,CAAC,CAAA;QACvG,OAAO,WAAW,CAAC;IACvB,CAAC,CAAC;AACN,CAAC"}
@@ -1,5 +1,11 @@
1
1
  /**
2
- * @returns {string} The user's locale.
2
+ * Retrieves the user's locale from the `<GTProvider>` context.
3
+ *
4
+ * @returns {string} The user's locale, e.g., 'en-US'.
5
+ *
6
+ * @example
7
+ * const locale = useLocale();
8
+ * console.log(locale); // 'en-US'
3
9
  */
4
10
  export default function useLocale(): string;
5
11
  //# sourceMappingURL=useLocale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocale.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,IAAI,MAAM,CAI1C"}
1
+ {"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocale.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,IAAI,MAAM,CAI1C"}
@@ -7,7 +7,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.default = useLocale;
8
8
  var GTContext_1 = __importDefault(require("../provider/GTContext"));
9
9
  /**
10
- * @returns {string} The user's locale.
10
+ * Retrieves the user's locale from the `<GTProvider>` context.
11
+ *
12
+ * @returns {string} The user's locale, e.g., 'en-US'.
13
+ *
14
+ * @example
15
+ * const locale = useLocale();
16
+ * console.log(locale); // 'en-US'
11
17
  */
12
18
  function useLocale() {
13
19
  return (0, GTContext_1.default)("useLocale(): Unable to access user's locale outside of a <GTProvider>").locale;
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../src/hooks/useLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAOZ,4BAIC;AATD,oEAAiD;AAEjD;;GAEG;AACH,SAAwB,SAAS;IAC7B,OAAO,IAAA,mBAAY,EACf,uEAAuE,CAC1E,CAAC,MAAM,CAAC;AACb,CAAC"}
1
+ {"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../src/hooks/useLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAaZ,4BAIC;AAfD,oEAAiD;AAEjD;;;;;;;;GAQG;AACH,SAAwB,SAAS;IAC7B,OAAO,IAAA,mBAAY,EACf,uEAAuE,CAC1E,CAAC,MAAM,CAAC;AACb,CAAC"}
@@ -1,4 +1,18 @@
1
1
  import { Dictionary } from "../primitives/types";
2
+ /**
3
+ * Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`.
4
+ *
5
+ * @param {React.ReactNode} children - The children components that will use the translation context.
6
+ * @param {string} [projectID] - The project ID required for General Translation cloud services.
7
+ * @param {Dictionary} [dictionary=defaultDictionary] - The translation dictionary for the project.
8
+ * @param {string} [dictionaryName=defaultDictionaryName] - The name of the translation dictionary.
9
+ * @param {string[]} [approvedLocales] - The list of approved locales for the project.
10
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The default locale to use if no other locale is found.
11
+ * @param {string} [locale] - The current locale, if already set.
12
+ * @param {string} [cacheURL='https://cache.gtx.dev'] - The URL of the cache service for fetching translations.
13
+ *
14
+ * @returns {JSX.Element} The provider component for General Translation context.
15
+ */
2
16
  export default function GTProvider({ children, projectID, dictionary, dictionaryName, approvedLocales, defaultLocale, locale, cacheURL }: {
3
17
  children?: any;
4
18
  projectID?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAgC,MAAM,qBAAqB,CAAC;AAU/E,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,UAA8B,EAC9B,cAAsC,EACtC,eAAe,EACf,aAA4D,EAC5D,MAAM,EACN,QAAkC,EACrC,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CA2Hd"}
1
+ {"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAgC,MAAM,qBAAqB,CAAC;AAQ/E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,UAA8B,EAC9B,cAAsC,EACtC,eAAe,EACf,aAA4D,EAC5D,MAAM,EACN,QAAkC,EACrC,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CA8Hd"}
@@ -53,7 +53,20 @@ var extractEntryMetadata_1 = __importDefault(require("./helpers/extractEntryMeta
53
53
  var renderDefaultChildren_1 = __importDefault(require("./rendering/renderDefaultChildren"));
54
54
  var getPluralBranch_1 = __importDefault(require("../plurals/getPluralBranch"));
55
55
  var renderTranslatedChildren_1 = __importDefault(require("./rendering/renderTranslatedChildren"));
56
- // intended for purely client-side apps, put at the root of the project
56
+ /**
57
+ * Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`.
58
+ *
59
+ * @param {React.ReactNode} children - The children components that will use the translation context.
60
+ * @param {string} [projectID] - The project ID required for General Translation cloud services.
61
+ * @param {Dictionary} [dictionary=defaultDictionary] - The translation dictionary for the project.
62
+ * @param {string} [dictionaryName=defaultDictionaryName] - The name of the translation dictionary.
63
+ * @param {string[]} [approvedLocales] - The list of approved locales for the project.
64
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The default locale to use if no other locale is found.
65
+ * @param {string} [locale] - The current locale, if already set.
66
+ * @param {string} [cacheURL='https://cache.gtx.dev'] - The URL of the cache service for fetching translations.
67
+ *
68
+ * @returns {JSX.Element} The provider component for General Translation context.
69
+ */
57
70
  function GTProvider(_a) {
58
71
  var _this = this;
59
72
  var children = _a.children, projectID = _a.projectID, _b = _a.dictionary, dictionary = _b === void 0 ? primitives_1.defaultDictionary : _b, _c = _a.dictionaryName, dictionaryName = _c === void 0 ? primitives_1.defaultDictionaryName : _c, approvedLocales = _a.approvedLocales, _d = _a.defaultLocale, defaultLocale = _d === void 0 ? (approvedLocales === null || approvedLocales === void 0 ? void 0 : approvedLocales[0]) || primitives_1.libraryDefaultLocale : _d, locale = _a.locale, _e = _a.cacheURL, cacheURL = _e === void 0 ? 'https://cache.gtx.dev' : _e;
@@ -62,6 +75,9 @@ function GTProvider(_a) {
62
75
  }
63
76
  var browserLocale = (0, useBrowserLocale_1.default)(defaultLocale);
64
77
  locale = locale || browserLocale;
78
+ if (approvedLocales) {
79
+ locale = (0, generaltranslation_1.determineLanguage)([locale, browserLocale], approvedLocales) || locale;
80
+ }
65
81
  var translationRequired = (0, generaltranslation_1.isSameLanguage)(locale, defaultLocale) ? false : true;
66
82
  var _f = (0, react_1.useState)(cacheURL ? null : {}), translations = _f[0], setTranslations = _f[1];
67
83
  (0, react_1.useEffect)(function () {
@@ -1 +1 @@
1
- {"version":3,"file":"GTProvider.js","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBZ,6BA6IC;;AA7JD,yDAA2E;AAE3E,+BAAuE;AACvE,+EAAyD;AACzD,uDAA6H;AAC7H,yCAAwC;AAExC,oFAA8D;AAC9D,wCAA8C;AAC9C,wFAAkE;AAClE,4FAAsE;AACtE,+EAAyD;AACzD,kGAA4E;AAE5E,uEAAuE;AAEvE,SAAwB,UAAU,CAAC,EAkBlC;IAlBD,iBA6IC;QA5IG,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,kBAA8B,EAA9B,UAAU,mBAAG,8BAAiB,KAAA,EAC9B,sBAAsC,EAAtC,cAAc,mBAAG,kCAAqB,KAAA,EACtC,eAAe,qBAAA,EACf,qBAA4D,EAA5D,aAAa,mBAAG,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,CAAC,CAAC,KAAI,iCAAoB,KAAA,EAC5D,MAAM,YAAA,EACN,gBAAkC,EAAlC,QAAQ,mBAAG,uBAAuB,KAAA;IAYlC,IAAI,CAAC,SAAS,IAAI,QAAQ,KAAK,uBAAuB,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,8HAA8H,CAAC,CAAA;IACnJ,CAAC;IAED,IAAM,aAAa,GAAG,IAAA,0BAAgB,EAAC,aAAa,CAAC,CAAC;IACtD,MAAM,GAAG,MAAM,IAAI,aAAa,CAAC;IAEjC,IAAM,mBAAmB,GAAG,IAAA,mCAAc,EAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3E,IAAA,KAAkC,IAAA,gBAAQ,EAC5C,QAAQ,CAAC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QAAQ,EAAE,CAAC;gBAClC,OAAO,IAAA,0CAAqB,EACxB,WAAW,CAAC,CAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,EAC7C,SAAS,EAAE,gBAAgB,CAC9B,CAAA;YACL,CAAC;YACD,IAAI,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;YAC3B,IAAI,QAAQ,EAAE,CAAC;gBACX,MAAM,GAAG,IAAA,yBAAe,EACpB,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,CAAW,EACtB,CAAC,MAAM,EAAE,aAAa,CAAC,EACvB,MAAA,MAAC,MAAc,CAAC,KAAK,0CAAG,yBAAyB,CAAC,0CAAE,QAAQ,CAC/D,KAAI,MAAC,MAAc,aAAd,MAAM,uBAAN,MAAM,CAAU,KAAK,0CAAE,QAAQ,CAAA,CAAC;YAC1C,CAAC;YACD,OAAO,IAAA,kCAAwB,EAAC;gBAC5B,MAAM,QAAA;gBACN,MAAM,QAAA;gBACN,SAAS,WAAA;gBAAE,gBAAgB,kBAAA;aAC9B,CAAC,CAAC;QACP,CAAC;IACL,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEpD,OAAO,CACH,uBAAC,qBAAS,CAAC,QAAQ,IAAC,KAAK,EAAE;YACvB,SAAS,WAAA;YAAE,MAAM,QAAA;YAAE,aAAa,eAAA;SACnC,YAEO,YAAY,CAAC,CAAC;YACd,QAAQ,CAAC,CAAC,CAAC,SAAS,GAEP,CACxB,CAAA;AAEL,CAAC"}
@@ -1,13 +1,33 @@
1
- import { ReactNode } from 'react';
2
- declare const Currency: {
3
- ({ children, name, defaultValue, currency, options }?: {
4
- children?: any;
5
- name?: string;
6
- defaultValue?: any;
7
- currency?: string;
8
- options?: Intl.NumberFormatOptions;
9
- }): ReactNode;
10
- gtTransformation: string;
11
- };
1
+ /**
2
+ * The `<Currency>` component renders a formatted currency string, allowing customization of name, default value, currency type, and formatting options.
3
+ * Must be used inside a `<GTProvider>`.
4
+ *
5
+ * @example
6
+ * ```jsx
7
+ * <Currency
8
+ * name="price"
9
+ * currency="USD"
10
+ * >
11
+ * 1000
12
+ * </Currency>
13
+ * ```
14
+ *
15
+ * @param {any} [children] - Optional content to render inside the currency component.
16
+ * @param {string} [name] - Optional name for the currency field.
17
+ * @param {any} [defaultValue] - The default value to be used.
18
+ * @param {string} [currency] - The currency type (e.g., USD, EUR, etc.).
19
+ * @param {Intl.NumberFormatOptions} [options] - Optional formatting options to customize how the currency is displayed.
20
+ * @returns {JSX.Element} The formatted currency component.
21
+ */
22
+ declare function Currency({ children, name, defaultValue, currency, options }?: {
23
+ children?: any;
24
+ name?: string;
25
+ defaultValue?: any;
26
+ currency?: string;
27
+ options?: Intl.NumberFormatOptions;
28
+ }): JSX.Element;
29
+ declare namespace Currency {
30
+ var gtTransformation: string;
31
+ }
12
32
  export default Currency;
13
33
  //# sourceMappingURL=Currency.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Currency.d.ts","sourceRoot":"","sources":["../../src/variables/Currency.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,QAAA,MAAM,QAAQ;2DAA+E;QACzF,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;KACtC,GAAsB,SAAS;;CAiB/B,CAAC;AAKF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"Currency.d.ts","sourceRoot":"","sources":["../../src/variables/Currency.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAa,EAAE,YAAY,EAAE,QAAgB,EAAE,OAAY,EAAE,GAAE;IACzF,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACnB,GAAG,GAAG,CAAC,OAAO,CAiBjC;kBAvBQ,QAAQ;;;AA4BjB,eAAe,QAAQ,CAAC"}
@@ -19,7 +19,28 @@ var jsx_runtime_1 = require("react/jsx-runtime");
19
19
  var generaltranslation_1 = require("generaltranslation");
20
20
  var useLocale_1 = __importDefault(require("../hooks/useLocale"));
21
21
  var useDefaultLocale_1 = __importDefault(require("../hooks/useDefaultLocale"));
22
- var Currency = function (_a) {
22
+ /**
23
+ * The `<Currency>` component renders a formatted currency string, allowing customization of name, default value, currency type, and formatting options.
24
+ * Must be used inside a `<GTProvider>`.
25
+ *
26
+ * @example
27
+ * ```jsx
28
+ * <Currency
29
+ * name="price"
30
+ * currency="USD"
31
+ * >
32
+ * 1000
33
+ * </Currency>
34
+ * ```
35
+ *
36
+ * @param {any} [children] - Optional content to render inside the currency component.
37
+ * @param {string} [name] - Optional name for the currency field.
38
+ * @param {any} [defaultValue] - The default value to be used.
39
+ * @param {string} [currency] - The currency type (e.g., USD, EUR, etc.).
40
+ * @param {Intl.NumberFormatOptions} [options] - Optional formatting options to customize how the currency is displayed.
41
+ * @returns {JSX.Element} The formatted currency component.
42
+ */
43
+ function Currency(_a) {
23
44
  var _b = _a === void 0 ? { name: "cost" } : _a, children = _b.children, _c = _b.name, name = _c === void 0 ? "cost" : _c, defaultValue = _b.defaultValue, _d = _b.currency, currency = _d === void 0 ? "USD" : _d, _e = _b.options, options = _e === void 0 ? {} : _e;
24
45
  var locales = [(0, useLocale_1.default)(), (0, useDefaultLocale_1.default)()];
25
46
  var value = (typeof children !== 'undefined' && typeof defaultValue === 'undefined') ? children : defaultValue;
@@ -29,7 +50,8 @@ var Currency = function (_a) {
29
50
  value = (0, generaltranslation_1.formatCurrency)({ value: value, languages: locales, currency: currency, options: options });
30
51
  }
31
52
  return ((0, jsx_runtime_1.jsx)("span", { "data-gt-variable-name": name, "data-gt-variable-type": "currency", "data-gt-variable-options": __assign({ style: 'currency', currency: currency }, options), children: value }));
32
- };
53
+ }
54
+ ;
33
55
  // Static property to indicate the transformation type
34
56
  Currency.gtTransformation = "variable-currency";
35
57
  exports.default = Currency;
@@ -1 +1 @@
1
- {"version":3,"file":"Currency.js","sourceRoot":"","sources":["../../src/variables/Currency.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;AAGZ,yDAAoD;AACpD,iEAA2C;AAC3C,+EAAyD;AAEzD,IAAM,QAAQ,GAAG,UAAC,EAME;QANF,qBAMd,EAAE,IAAI,EAAE,MAAM,EAAE,KAAA,EANA,QAAQ,cAAA,EAAE,YAAa,EAAb,IAAI,mBAAG,MAAM,KAAA,EAAE,YAAY,kBAAA,EAAE,gBAAgB,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAAE,eAAY,EAAZ,OAAO,mBAAG,EAAE,KAAA;IAQrF,IAAM,OAAO,GAAG,CAAC,IAAA,mBAAS,GAAE,EAAE,IAAA,0BAAgB,GAAE,CAAC,CAAA;IAEjD,IAAI,KAAK,GAAG,CAAC,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAC/G,KAAK,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChE,2CAA2C;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,KAAK,GAAG,IAAA,mCAAc,EAAC,EAAE,KAAK,OAAA,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,UAAA,EA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AE,OAAO,EAAE,QAAQ,UAAA,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,CACH,0DAA6B,IAAI,2BAAyB,UAAU,yCAA8B,KAAK,EAAE,UAAU,EAAE,QAAQ,UAAA,IAAK,OAAO,aACpI,KAAK,GACH,CACV,CAAC;AAEN,CAAC;AAAA,CAAC;AAEF,sDAAsD;AACtD,QAAQ,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;AAEhD,kBAAe,QAAQ,CAAC"}
@@ -1,11 +1,30 @@
1
- import { ReactNode } from 'react';
1
+ /**
2
+ * The `<DateTime>` component renders a formatted date or time string, allowing customization of the name, default value, and formatting options.
3
+ * It utilizes the current locale and optional format settings to display the date.
4
+ * Must be used inside a `<GTProvider>`.
5
+ *
6
+ * @example
7
+ * ```jsx
8
+ * <DateTime
9
+ * name="createdAt"
10
+ * >
11
+ * {new Date()}
12
+ * </DateTime>
13
+ * ```
14
+ *
15
+ * @param {any} [children] - Optional content (typically a date) to render inside the component.
16
+ * @param {string} [name="date"] - Optional name for the date field, used for metadata purposes.
17
+ * @param {string|number|Date} [defaultValue] - The default value for the date. Can be a string, number (timestamp), or `Date` object.
18
+ * @param {Intl.DateTimeFormatOptions} [options={}] - Optional formatting options for the date, following `Intl.DateTimeFormatOptions` specifications.
19
+ * @returns {JSX.Element} The formatted date or time component.
20
+ */
2
21
  declare const DateTime: {
3
22
  ({ children, name, defaultValue, options }?: {
4
23
  children?: any;
5
24
  name?: string;
6
25
  defaultValue?: any;
7
26
  options?: Intl.DateTimeFormatOptions;
8
- }): ReactNode;
27
+ }): JSX.Element;
9
28
  gtTransformation: string;
10
29
  };
11
30
  export default DateTime;
@@ -1 +1 @@
1
- {"version":3,"file":"DateTime.d.ts","sourceRoot":"","sources":["../../src/variables/DateTime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,QAAA,MAAM,QAAQ;iDAA6D;QACvE,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC;KACxC,GAAsB,SAAS;;CA0B/B,CAAC;AAKF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"DateTime.d.ts","sourceRoot":"","sources":["../../src/variables/DateTime.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,QAAA,MAAM,QAAQ;iDAA6D;QACvE,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC;KACxC,GAAsB,GAAG,CAAC,OAAO;;CAyBjC,CAAC;AAKF,eAAe,QAAQ,CAAC"}
@@ -8,14 +8,32 @@ var jsx_runtime_1 = require("react/jsx-runtime");
8
8
  var generaltranslation_1 = require("generaltranslation");
9
9
  var useLocale_1 = __importDefault(require("../hooks/useLocale"));
10
10
  var useDefaultLocale_1 = __importDefault(require("../hooks/useDefaultLocale"));
11
+ /**
12
+ * The `<DateTime>` component renders a formatted date or time string, allowing customization of the name, default value, and formatting options.
13
+ * It utilizes the current locale and optional format settings to display the date.
14
+ * Must be used inside a `<GTProvider>`.
15
+ *
16
+ * @example
17
+ * ```jsx
18
+ * <DateTime
19
+ * name="createdAt"
20
+ * >
21
+ * {new Date()}
22
+ * </DateTime>
23
+ * ```
24
+ *
25
+ * @param {any} [children] - Optional content (typically a date) to render inside the component.
26
+ * @param {string} [name="date"] - Optional name for the date field, used for metadata purposes.
27
+ * @param {string|number|Date} [defaultValue] - The default value for the date. Can be a string, number (timestamp), or `Date` object.
28
+ * @param {Intl.DateTimeFormatOptions} [options={}] - Optional formatting options for the date, following `Intl.DateTimeFormatOptions` specifications.
29
+ * @returns {JSX.Element} The formatted date or time component.
30
+ */
11
31
  var DateTime = function (_a) {
12
32
  var _b = _a === void 0 ? { name: "date" } : _a, children = _b.children, _c = _b.name, name = _c === void 0 ? "date" : _c, defaultValue = _b.defaultValue, _d = _b.options, options = _d === void 0 ? {} : _d;
13
33
  var locales = [(0, useLocale_1.default)(), (0, useDefaultLocale_1.default)()];
14
34
  var final;
15
35
  var dateValue;
16
36
  defaultValue = (typeof children !== 'undefined' && typeof defaultValue === 'undefined') ? children : defaultValue;
17
- if (!defaultValue)
18
- return '';
19
37
  if (typeof defaultValue === 'number') {
20
38
  dateValue = new Date(defaultValue);
21
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DateTime.js","sourceRoot":"","sources":["../../src/variables/DateTime.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;AAGZ,yDAAoD;AACpD,iEAA2C;AAC3C,+EAAyD;AAEzD,IAAM,QAAQ,GAAG,UAAC,EAKE;QALF,qBAKd,EAAE,IAAI,EAAE,MAAM,EAAE,KAAA,EALA,QAAQ,cAAA,EAAE,YAAa,EAAb,IAAI,mBAAG,MAAM,KAAA,EAAE,YAAY,kBAAA,EAAE,eAAY,EAAZ,OAAO,mBAAG,EAAE,KAAA;IAOnE,IAAM,OAAO,GAAG,CAAC,IAAA,mBAAS,GAAE,EAAE,IAAA,0BAAgB,GAAE,CAAC,CAAA;IAEjD,IAAI,KAAK,CAAC;IAEV,IAAI,SAA2B,CAAC;IAChC,YAAY,GAAG,CAAC,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAClH,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IAC7B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACnC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;SAAM,IAAI,OAAO,YAAY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WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAClH,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACnC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;SAAM,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC1C,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;SAAM,IAAI,YAAY,YAAY,IAAI,EAAE,CAAC;QACtC,SAAS,GAAG,YAAY,CAAC;IAC7B,CAAC;IACD,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE,CAAC;QACnC,KAAK,GAAG,CAAC,IAAA,mCAAc,EAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IACrH,CAAC;IAED,kDAAkD;IAClD,OAAO,CACH,0DAA6B,IAAI,2BAAyB,MAAM,8BAA4B,OAAO,YAC9F,KAAK,GACH,CACV,CAAC;AACN,CAAC,CAAC;AAEF,0CAA0C;AAC1C,QAAQ,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;AAEhD,kBAAe,QAAQ,CAAC"}
@@ -1,12 +1,32 @@
1
- import { ReactNode } from 'react';
2
- declare const Num: {
3
- ({ children, name, defaultValue, options }?: {
4
- children?: any;
5
- name?: string;
6
- defaultValue?: any;
7
- options?: Intl.NumberFormatOptions;
8
- }): ReactNode;
9
- gtTransformation: string;
10
- };
1
+ /**
2
+ * The `<Num>` component renders a formatted number string, allowing customization of the name, default value, and formatting options.
3
+ * It formats the number according to the current locale and optionally passed formatting options.
4
+ * Must be used inside a `<GTProvider>`.
5
+ *
6
+ * @example
7
+ * ```jsx
8
+ * <Num
9
+ * name="quantity"
10
+ * options={{ style: "decimal", maximumFractionDigits: 2 }}
11
+ * >
12
+ * 1000
13
+ * </Num>
14
+ * ```
15
+ *
16
+ * @param {any} [children] - Optional content (typically a number) to render inside the component.
17
+ * @param {string} [name="n"] - Optional name for the number field, used for metadata purposes.
18
+ * @param {string|number} [defaultValue] - The default value for the number. Can be a string or number. Strings will be parsed to numbers.
19
+ * @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options for the number, following `Intl.NumberFormatOptions` specifications.
20
+ * @returns {JSX.Element} The formatted number component.
21
+ */
22
+ declare function Num({ children, name, defaultValue, options }?: {
23
+ children?: any;
24
+ name?: string;
25
+ defaultValue?: any;
26
+ options?: Intl.NumberFormatOptions;
27
+ }): JSX.Element;
28
+ declare namespace Num {
29
+ var gtTransformation: string;
30
+ }
11
31
  export default Num;
12
32
  //# sourceMappingURL=Num.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Num.d.ts","sourceRoot":"","sources":["../../src/variables/Num.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,QAAA,MAAM,GAAG;iDAA0D;QAC/D,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAA;KACrC,GAAmB,SAAS;;CAgB5B,CAAC;AAIF,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"Num.d.ts","sourceRoot":"","sources":["../../src/variables/Num.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAU,EAAE,YAAY,EAAE,OAAY,EAAE,GAAE;IAC/D,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAA;CACrB,GAAG,GAAG,CAAC,OAAO,CAgB9B;kBArBQ,GAAG;;;AAyBZ,eAAe,GAAG,CAAC"}
@@ -8,7 +8,28 @@ var jsx_runtime_1 = require("react/jsx-runtime");
8
8
  var generaltranslation_1 = require("generaltranslation");
9
9
  var useLocale_1 = __importDefault(require("../hooks/useLocale"));
10
10
  var useDefaultLocale_1 = __importDefault(require("../hooks/useDefaultLocale"));
11
- var Num = function (_a) {
11
+ /**
12
+ * The `<Num>` component renders a formatted number string, allowing customization of the name, default value, and formatting options.
13
+ * It formats the number according to the current locale and optionally passed formatting options.
14
+ * Must be used inside a `<GTProvider>`.
15
+ *
16
+ * @example
17
+ * ```jsx
18
+ * <Num
19
+ * name="quantity"
20
+ * options={{ style: "decimal", maximumFractionDigits: 2 }}
21
+ * >
22
+ * 1000
23
+ * </Num>
24
+ * ```
25
+ *
26
+ * @param {any} [children] - Optional content (typically a number) to render inside the component.
27
+ * @param {string} [name="n"] - Optional name for the number field, used for metadata purposes.
28
+ * @param {string|number} [defaultValue] - The default value for the number. Can be a string or number. Strings will be parsed to numbers.
29
+ * @param {Intl.NumberFormatOptions} [options={}] - Optional formatting options for the number, following `Intl.NumberFormatOptions` specifications.
30
+ * @returns {JSX.Element} The formatted number component.
31
+ */
32
+ function Num(_a) {
12
33
  var _b = _a === void 0 ? { name: "n" } : _a, children = _b.children, _c = _b.name, name = _c === void 0 ? "n" : _c, defaultValue = _b.defaultValue, _d = _b.options, options = _d === void 0 ? {} : _d;
13
34
  var locales = [(0, useLocale_1.default)(), (0, useDefaultLocale_1.default)()];
14
35
  var value = (typeof children !== 'undefined' && typeof defaultValue === 'undefined') ? children : defaultValue;
@@ -18,7 +39,8 @@ var Num = function (_a) {
18
39
  value = (0, generaltranslation_1.formatNum)({ value: value, languages: locales, options: options });
19
40
  }
20
41
  return ((0, jsx_runtime_1.jsx)("span", { "data-gt-variable-name": name, "data-gt-variable-type": "number", "data-gt-variable-options": JSON.stringify(options), children: value }));
21
- };
42
+ }
43
+ ;
22
44
  Num.gtTransformation = "variable-number";
23
45
  exports.default = Num;
24
46
  //# sourceMappingURL=Num.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Num.js","sourceRoot":"","sources":["../../src/variables/Num.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;AAGZ,yDAA+C;AAC/C,iEAA2C;AAC3C,+EAAyD;AAEzD,IAAM,GAAG,GAAG,UAAC,EAKI;QALJ,qBAKT,EAAE,IAAI,EAAE,GAAG,EAAE,KAAA,EALF,QAAQ,cAAA,EAAE,YAAU,EAAV,IAAI,mBAAG,GAAG,KAAA,EAAE,YAAY,kBAAA,EAAE,eAAY,EAAZ,OAAO,mBAAG,EAAE,KAAA;IAO3D,IAAM,OAAO,GAAG,CAAC,IAAA,mBAAS,GAAE,EAAE,IAAA,0BAAgB,GAAE,CAAC,CAAA;IAEjD,IAAI,KAAK,GAAG,CAAC,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAC/G,KAAK,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,2DAA2D;QAC3D,KAAK,GAAG,IAAA,8BAAS,EAAC,EAAE,KAAK,OAAA,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,CACH,0DAA6B,IAAI,2BAAyB,QAAQ,8BAA4B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAChH,KAAK,GACH,CACV,CAAC;AACN,CAAC,CAAC;AAEF,GAAG,CAAC,gBAAgB,GAAG,iBAAiB,CAAC;AAEzC,kBAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"Num.js","sourceRoot":"","sources":["../../src/variables/Num.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;AAEZ,yDAA+C;AAC/C,iEAA2C;AAC3C,+EAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,GAAG,CAAC,EAKI;QALJ,qBAKT,EAAE,IAAI,EAAE,GAAG,EAAE,KAAA,EALF,QAAQ,cAAA,EAAE,YAAU,EAAV,IAAI,mBAAG,GAAG,KAAA,EAAE,YAAY,kBAAA,EAAE,eAAY,EAAZ,OAAO,mBAAG,EAAE,KAAA;IAO3D,IAAM,OAAO,GAAG,CAAC,IAAA,mBAAS,GAAE,EAAE,IAAA,0BAAgB,GAAE,CAAC,CAAA;IAEjD,IAAI,KAAK,GAAG,CAAC,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAC/G,KAAK,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,2DAA2D;QAC3D,KAAK,GAAG,IAAA,8BAAS,EAAC,EAAE,KAAK,OAAA,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,SAAA,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,CACH,0DAA6B,IAAI,2BAAyB,QAAQ,8BAA4B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAChH,KAAK,GACH,CACV,CAAC;AACN,CAAC;AAAA,CAAC;AAEF,GAAG,CAAC,gBAAgB,GAAG,iBAAiB,CAAC;AAEzC,kBAAe,GAAG,CAAC"}
@@ -1,11 +1,28 @@
1
- import { ReactNode } from 'react';
2
- declare const Var: {
3
- ({ children, name, defaultValue }: {
4
- children?: any;
5
- name?: string;
6
- defaultValue?: any;
7
- }): ReactNode;
8
- gtTransformation: string;
9
- };
1
+ /**
2
+ * The `<Var>` component renders a variable value, which can either be passed as `children` or a `defaultValue`.
3
+ * If `children` is provided, it will be used; otherwise, the `defaultValue` is rendered.
4
+ *
5
+ * @example
6
+ * ```jsx
7
+ * <Var
8
+ * name="username"
9
+ * >
10
+ * John
11
+ * </Var>
12
+ * ```
13
+ *
14
+ * @param {any} [children] - The content to render inside the component. If provided, it will take precedence over `defaultValue`.
15
+ * @param {string} [name] - Optional name for the variable, used for metadata purposes.
16
+ * @param {any} [defaultValue] - The default value to be displayed if `children` is not provided.
17
+ * @returns {JSX.Element} The rendered variable component with either `children` or `defaultValue`.
18
+ */
19
+ declare function Var({ children, name, defaultValue }: {
20
+ children?: any;
21
+ name?: string;
22
+ defaultValue?: any;
23
+ }): JSX.Element;
24
+ declare namespace Var {
25
+ var gtTransformation: string;
26
+ }
10
27
  export default Var;
11
28
  //# sourceMappingURL=Var.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Var.d.ts","sourceRoot":"","sources":["../../src/variables/Var.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,QAAA,MAAM,GAAG;uCAAsC;QAC3C,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,GAAG,CAAC;KACtB,GAAG,SAAS;;CAUZ,CAAC;AAIF,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"Var.d.ts","sourceRoot":"","sources":["../../src/variables/Var.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE;IAC3C,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,GAAG,CAAC;CACtB,GAAG,GAAG,CAAC,OAAO,CAUd;kBAdQ,GAAG;;;AAkBZ,eAAe,GAAG,CAAC"}
@@ -2,11 +2,30 @@
2
2
  'use client';
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  var jsx_runtime_1 = require("react/jsx-runtime");
5
- var Var = function (_a) {
5
+ /**
6
+ * The `<Var>` component renders a variable value, which can either be passed as `children` or a `defaultValue`.
7
+ * If `children` is provided, it will be used; otherwise, the `defaultValue` is rendered.
8
+ *
9
+ * @example
10
+ * ```jsx
11
+ * <Var
12
+ * name="username"
13
+ * >
14
+ * John
15
+ * </Var>
16
+ * ```
17
+ *
18
+ * @param {any} [children] - The content to render inside the component. If provided, it will take precedence over `defaultValue`.
19
+ * @param {string} [name] - Optional name for the variable, used for metadata purposes.
20
+ * @param {any} [defaultValue] - The default value to be displayed if `children` is not provided.
21
+ * @returns {JSX.Element} The rendered variable component with either `children` or `defaultValue`.
22
+ */
23
+ function Var(_a) {
6
24
  var children = _a.children, name = _a.name, defaultValue = _a.defaultValue;
7
25
  var final = typeof children !== 'undefined' ? children : defaultValue;
8
26
  return ((0, jsx_runtime_1.jsx)("span", { "data-gt-variable-name": name, "data-gt-variable-type": "variable", children: final }));
9
- };
27
+ }
28
+ ;
10
29
  Var.gtTransformation = "variable-variable";
11
30
  exports.default = Var;
12
31
  //# sourceMappingURL=Var.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Var.js","sourceRoot":"","sources":["../../src/variables/Var.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;AAIZ,IAAM,GAAG,GAAG,UAAC,EAIZ;QAJc,QAAQ,cAAA,EAAE,IAAI,UAAA,EAAE,YAAY,kBAAA;IAMvC,IAAI,KAAK,GAAG,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAEtE,OAAO,CACH,0DAA6B,IAAI,2BAAyB,UAAU,YAC/D,KAAK,GACH,CACV,CAAC;AAEN,CAAC,CAAC;AAEF,GAAG,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;AAE3C,kBAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"Var.js","sourceRoot":"","sources":["../../src/variables/Var.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;AAEZ;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,GAAG,CAAC,EAIZ;QAJc,QAAQ,cAAA,EAAE,IAAI,UAAA,EAAE,YAAY,kBAAA;IAMvC,IAAI,KAAK,GAAG,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAEtE,OAAO,CACH,0DAA6B,IAAI,2BAAyB,UAAU,YAC/D,KAAK,GACH,CACV,CAAC;AAEN,CAAC;AAAA,CAAC;AAEF,GAAG,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;AAE3C,kBAAe,GAAG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-react",
3
- "version": "4.0.11",
3
+ "version": "4.0.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/scratchpad.js CHANGED
@@ -1,34 +1,10 @@
1
1
  /*
2
2
 
3
- gt-react
4
- - works for client-side React, React native
3
+ Main functions:
5
4
 
6
- import {
7
- GTProvider, useGT, useLocale, useDefaultLocale, useBrowserLocale,
8
- Var, Num, Currency, DateTime
9
- } from 'gt-react'
10
- import { calculateHash, addGTIdentifier, writeChildrenAsObjects } from 'gt-react/internal'
11
-
12
- */
13
- /*
14
-
15
- gt-next
16
- - initGT in next.js plugin
17
-
18
- import { useBrowserLocale } from 'gt-next/client'
19
- import {
20
- getGT, GTProvider, getLocale, getDefaultLocale,
21
- Var, Num, Currency, DateTime
22
- } from 'gt-next'
23
- import { initGT } from 'gt-next/plugin'
24
- import { T, Plural } from 'gt-next/server'
25
- import { createMiddleware } from 'gt-next/middleware'
26
-
27
- */
28
- /*
29
-
30
- generaltranslation
31
-
32
- import { determineLocale }
5
+ Var, Num, Currency, DateTime
6
+ GTProvider,
7
+ useGT, useDefaultLocale, useLocale
8
+ useBrowserLocale
33
9
 
34
10
  */
@@ -1,4 +0,0 @@
1
- export declare const localeCookieName = "generaltranslation-locale";
2
- export declare const libraryDefaultLocale = "en";
3
- export declare const pluralBranchNames: string[];
4
- //# sourceMappingURL=settings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/primitives/settings.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAE5D,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,eAAO,MAAM,iBAAiB,UAA+E,CAAA"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluralBranchNames = exports.libraryDefaultLocale = exports.localeCookieName = void 0;
4
- exports.localeCookieName = "generaltranslation-locale";
5
- exports.libraryDefaultLocale = "en"; // language to use as default if none is provided
6
- exports.pluralBranchNames = ["singular", "plural", "dual", "zero", "one", "two", "few", "many", "other"];
7
- //# sourceMappingURL=settings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/primitives/settings.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,2BAA2B,CAAC;AAE/C,QAAA,oBAAoB,GAAG,IAAI,CAAC,CAAC,iDAAiD;AAE9E,QAAA,iBAAiB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA"}