generaltranslation 8.2.8 → 8.2.9

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 (60) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{ApiError-4zIP-twr.cjs → ApiError-CZ45tkW6.cjs} +1 -1
  3. package/dist/{ApiError-4zIP-twr.cjs.map → ApiError-CZ45tkW6.cjs.map} +1 -1
  4. package/dist/{ApiError-Bv7vlzyQ.mjs → ApiError-IYfaOR30.mjs} +1 -1
  5. package/dist/{ApiError-Bv7vlzyQ.mjs.map → ApiError-IYfaOR30.mjs.map} +1 -1
  6. package/dist/IntlCache-Ccg_cQPR.mjs +195 -0
  7. package/dist/IntlCache-Ccg_cQPR.mjs.map +1 -0
  8. package/dist/IntlCache-k2qfrDqB.cjs +212 -0
  9. package/dist/IntlCache-k2qfrDqB.cjs.map +1 -0
  10. package/dist/base64-C1sogiix.mjs +70 -0
  11. package/dist/base64-C1sogiix.mjs.map +1 -0
  12. package/dist/base64-CUcEPEC5.cjs +111 -0
  13. package/dist/base64-CUcEPEC5.cjs.map +1 -0
  14. package/dist/core-CJMv4fMa.d.cts +209 -0
  15. package/dist/core-DOrYXXpO.mjs +1487 -0
  16. package/dist/core-DOrYXXpO.mjs.map +1 -0
  17. package/dist/core-DtPj_ruw.d.mts +209 -0
  18. package/dist/core-LS3Pia40.cjs +1666 -0
  19. package/dist/core-LS3Pia40.cjs.map +1 -0
  20. package/dist/core.cjs +8 -0
  21. package/dist/core.d.cts +2 -0
  22. package/dist/core.d.mts +2 -0
  23. package/dist/core.mjs +2 -0
  24. package/dist/errors.cjs +1 -1
  25. package/dist/errors.mjs +1 -1
  26. package/dist/{id-CPbVYREY.mjs → id-BmOyfaug.mjs} +2 -2
  27. package/dist/{id-CPbVYREY.mjs.map → id-BmOyfaug.mjs.map} +1 -1
  28. package/dist/{id-VXBgyXu2.cjs → id-COlX5v3V.cjs} +6 -6
  29. package/dist/{id-VXBgyXu2.cjs.map → id-COlX5v3V.cjs.map} +1 -1
  30. package/dist/id.cjs +1 -1
  31. package/dist/id.d.cts +1 -1
  32. package/dist/id.d.mts +1 -1
  33. package/dist/id.mjs +1 -1
  34. package/dist/index.cjs +59 -1518
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +4 -162
  37. package/dist/index.d.mts +4 -162
  38. package/dist/index.mjs +6 -1441
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/internal.cjs +602 -44
  41. package/dist/internal.cjs.map +1 -0
  42. package/dist/internal.d.cts +1 -1
  43. package/dist/internal.d.mts +1 -1
  44. package/dist/internal.mjs +562 -2
  45. package/dist/internal.mjs.map +1 -0
  46. package/dist/{sha2-DKowBr6H.cjs → isVariable-B08mggBy.cjs} +18 -18
  47. package/dist/isVariable-B08mggBy.cjs.map +1 -0
  48. package/dist/{stableStringify-DgDlE_pD.mjs → isVariable-CYsKFHvR.mjs} +19 -19
  49. package/dist/isVariable-CYsKFHvR.mjs.map +1 -0
  50. package/dist/{types-DazaDJbs.d.mts → types-Dfy_sRLD.d.mts} +1 -1
  51. package/dist/{types-BJdoI1d1.d.cts → types-mZeu4HS3.d.cts} +1 -1
  52. package/dist/types.d.cts +1 -1
  53. package/dist/types.d.mts +1 -1
  54. package/package.json +17 -1
  55. package/dist/internal-B3QbyI_5.mjs +0 -820
  56. package/dist/internal-B3QbyI_5.mjs.map +0 -1
  57. package/dist/internal-DIHQF9gs.cjs +0 -1070
  58. package/dist/internal-DIHQF9gs.cjs.map +0 -1
  59. package/dist/sha2-DKowBr6H.cjs.map +0 -1
  60. package/dist/stableStringify-DgDlE_pD.mjs.map +0 -1
package/dist/internal.cjs CHANGED
@@ -1,45 +1,603 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_internal = require("./internal-DIHQF9gs.cjs");
3
- const require_sha2 = require("./sha2-DKowBr6H.cjs");
4
- exports.VAR_IDENTIFIER = require_internal.VAR_IDENTIFIER;
5
- exports.VAR_NAME_IDENTIFIER = require_internal.VAR_NAME_IDENTIFIER;
6
- exports.condenseVars = require_internal.condenseVars;
7
- exports.declareStatic = require_internal.declareStatic;
8
- exports.declareVar = require_internal.declareVar;
9
- exports.decode = require_internal.decode;
10
- exports.decodeVars = require_internal.decodeVars;
11
- exports.defaultBaseUrl = require_internal.defaultBaseUrl;
12
- exports.defaultCacheUrl = require_internal.defaultCacheUrl;
13
- exports.defaultRuntimeApiUrl = require_internal.defaultRuntimeApiUrl;
14
- exports.defaultTimeout = require_internal.defaultTimeout;
15
- exports.derive = require_internal.derive;
16
- exports.encode = require_internal.encode;
17
- exports.extractVars = require_internal.extractVars;
18
- exports.getNewBranchType = require_internal.getNewBranchType;
19
- exports.getNewGTProp = require_internal.getNewGTProp;
20
- exports.getNewJsxChild = require_internal.getNewJsxChild;
21
- exports.getNewJsxChildren = require_internal.getNewJsxChildren;
22
- exports.getNewJsxElement = require_internal.getNewJsxElement;
23
- exports.getNewVariableObject = require_internal.getNewVariableObject;
24
- exports.getNewVariableType = require_internal.getNewVariableType;
25
- exports.getOldBranchType = require_internal.getOldBranchType;
26
- exports.getOldGTProp = require_internal.getOldGTProp;
27
- exports.getOldJsxChild = require_internal.getOldJsxChild;
28
- exports.getOldJsxChildren = require_internal.getOldJsxChildren;
29
- exports.getOldJsxElement = require_internal.getOldJsxElement;
30
- exports.getOldVariableObject = require_internal.getOldVariableObject;
31
- exports.getOldVariableType = require_internal.getOldVariableType;
32
- exports.getPluralForm = require_internal._getPluralForm;
33
- exports.indexVars = require_internal.indexVars;
34
- exports.isAcceptedPluralForm = require_internal.isAcceptedPluralForm;
35
- exports.isNewVariableObject = require_internal.isNewVariableObject;
36
- exports.isOldJsxChildren = require_internal.isOldJsxChildren;
37
- exports.isOldVariableObject = require_internal.isOldVariableObject;
38
- exports.isSupportedFileFormatTransform = require_internal.isSupportedFileFormatTransform;
39
- exports.isVariable = require_sha2.isVariable;
40
- exports.libraryDefaultLocale = require_internal.libraryDefaultLocale;
41
- exports.minifyVariableType = require_internal.minifyVariableType;
42
- exports.oldHashJsxChildren = require_internal.oldHashJsxChildren;
43
- exports.oldHashString = require_internal.oldHashString;
44
- exports.pluralForms = require_internal.pluralForms;
45
- exports.validateFileFormatTransforms = require_internal.validateFileFormatTransforms;
2
+ const require_IntlCache = require("./IntlCache-k2qfrDqB.cjs");
3
+ const require_base64 = require("./base64-CUcEPEC5.cjs");
4
+ const require_isVariable = require("./isVariable-B08mggBy.cjs");
5
+ let _formatjs_icu_messageformat_parser = require("@formatjs/icu-messageformat-parser");
6
+ let _formatjs_icu_messageformat_parser_types_js = require("@formatjs/icu-messageformat-parser/types.js");
7
+ let _formatjs_icu_messageformat_parser_printer_js = require("@formatjs/icu-messageformat-parser/printer.js");
8
+ //#region src/settings/plurals.ts
9
+ const pluralForms = [
10
+ "singular",
11
+ "plural",
12
+ "dual",
13
+ "zero",
14
+ "one",
15
+ "two",
16
+ "few",
17
+ "many",
18
+ "other"
19
+ ];
20
+ function isAcceptedPluralForm(form) {
21
+ return pluralForms.includes(form);
22
+ }
23
+ //#endregion
24
+ //#region src/locales/getPluralForm.ts
25
+ /**
26
+ * Given a number and a list of allowed plural forms, return the plural form that best fits the number.
27
+ *
28
+ * @param {number} n - The number to determine the plural form for.
29
+ * @param {locales[]} forms - The allowed plural forms.
30
+ * @returns {PluralType} The determined plural form, or an empty string if none fit.
31
+ */
32
+ function _getPluralForm(n, forms = pluralForms, locales = ["en"]) {
33
+ const provisionalBranchName = require_IntlCache.intlCache.get("PluralRules", locales).select(n);
34
+ const absN = Math.abs(n);
35
+ if (absN === 0 && forms.includes("zero")) return "zero";
36
+ if (absN === 1) {
37
+ if (forms.includes("singular")) return "singular";
38
+ if (forms.includes("one")) return "one";
39
+ }
40
+ if (provisionalBranchName === "one" && forms.includes("singular")) return "singular";
41
+ if (absN === 2) {
42
+ if (forms.includes("dual")) return "dual";
43
+ if (forms.includes("two")) return "two";
44
+ }
45
+ if (provisionalBranchName === "two" && forms.includes("dual")) return "dual";
46
+ if (forms.includes(provisionalBranchName)) return provisionalBranchName;
47
+ if (provisionalBranchName === "two" && forms.includes("dual")) return "dual";
48
+ if (provisionalBranchName === "two" && forms.includes("plural")) return "plural";
49
+ if (provisionalBranchName === "two" && forms.includes("other")) return "other";
50
+ if (provisionalBranchName === "few" && forms.includes("plural")) return "plural";
51
+ if (provisionalBranchName === "few" && forms.includes("other")) return "other";
52
+ if (provisionalBranchName === "many" && forms.includes("plural")) return "plural";
53
+ if (provisionalBranchName === "many" && forms.includes("other")) return "other";
54
+ if (provisionalBranchName === "other" && forms.includes("plural")) return "plural";
55
+ return "";
56
+ }
57
+ //#endregion
58
+ //#region src/utils/minify.ts
59
+ const VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {
60
+ variable: "v",
61
+ number: "n",
62
+ datetime: "d",
63
+ currency: "c",
64
+ "relative-time": "rt"
65
+ };
66
+ function minifyVariableType(variableType) {
67
+ return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];
68
+ }
69
+ //#endregion
70
+ //#region src/derive/utils/traverseIcu.ts
71
+ /**
72
+ * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T
73
+ * @param icu - The ICU string to traverse
74
+ * @param shouldVisit - A function that returns true if the element should be visited
75
+ * @param visitor - A function that is called for each element that matches the type T
76
+ * @returns The modified AST of the ICU string
77
+ *
78
+ * @note This function is a heavy operation, use sparingly
79
+ */
80
+ function traverseIcu({ icuString, shouldVisit, visitor, options: { recurseIntoVisited = true, ...otherOptions } }) {
81
+ const ast = (0, _formatjs_icu_messageformat_parser.parse)(icuString, otherOptions);
82
+ handleChildren(ast);
83
+ return ast;
84
+ function handleChildren(children) {
85
+ children.map(handleChild);
86
+ }
87
+ function handleChild(child) {
88
+ let visited = false;
89
+ if (shouldVisit(child)) {
90
+ visitor(child);
91
+ visited = true;
92
+ }
93
+ if (!visited || recurseIntoVisited) {
94
+ if (child.type === _formatjs_icu_messageformat_parser.TYPE.select || child.type === _formatjs_icu_messageformat_parser.TYPE.plural) Object.values(child.options).map((option) => option.value).map(handleChildren);
95
+ else if (child.type === _formatjs_icu_messageformat_parser.TYPE.tag) handleChildren(child.children);
96
+ }
97
+ }
98
+ }
99
+ //#endregion
100
+ //#region src/derive/utils/constants.ts
101
+ const VAR_IDENTIFIER = "_gt_";
102
+ const VAR_NAME_IDENTIFIER = "_gt_var_name";
103
+ //#endregion
104
+ //#region src/derive/utils/regex.ts
105
+ const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}\\d+$`);
106
+ const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);
107
+ //#endregion
108
+ //#region src/derive/utils/traverseHelpers.ts
109
+ function isGTIndexedSelectElement(child) {
110
+ return child.type === _formatjs_icu_messageformat_parser_types_js.TYPE.select && GT_INDEXED_IDENTIFIER_REGEX.test(child.value) && !!child.options.other && (child.options.other.value.length === 0 || child.options.other.value.length > 0 && child.options.other.value[0]?.type === _formatjs_icu_messageformat_parser_types_js.TYPE.literal);
111
+ }
112
+ function isGTUnindexedSelectElement(child) {
113
+ return child.type === _formatjs_icu_messageformat_parser_types_js.TYPE.select && GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) && !!child.options.other && (child.options.other.value.length === 0 || child.options.other.value.length > 0 && child.options.other.value[0]?.type === _formatjs_icu_messageformat_parser_types_js.TYPE.literal);
114
+ }
115
+ //#endregion
116
+ //#region src/derive/decodeVars.ts
117
+ /**
118
+ * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()
119
+ * @example
120
+ * const encodedIcu = "Hi" + declareVar("Brian") + ", my name is {name}"
121
+ * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'
122
+ * decodeVars(encodedIcu)
123
+ * // 'Hi Brian, my name is {name}'
124
+ */
125
+ function decodeVars(icuString) {
126
+ if (!icuString.includes("_gt_")) return icuString;
127
+ const variableLocations = [];
128
+ function visitor(child) {
129
+ variableLocations.push({
130
+ start: child.location?.start.offset ?? 0,
131
+ end: child.location?.end.offset ?? 0,
132
+ value: child.options.other.value.length > 0 ? child.options.other.value[0].value : ""
133
+ });
134
+ }
135
+ traverseIcu({
136
+ icuString,
137
+ shouldVisit: isGTUnindexedSelectElement,
138
+ visitor,
139
+ options: {
140
+ recurseIntoVisited: false,
141
+ captureLocation: true
142
+ }
143
+ });
144
+ let previousIndex = 0;
145
+ const outputList = [];
146
+ for (let i = 0; i < variableLocations.length; i++) {
147
+ outputList.push(icuString.slice(previousIndex, variableLocations[i].start));
148
+ outputList.push(variableLocations[i].value);
149
+ previousIndex = variableLocations[i].end;
150
+ }
151
+ if (previousIndex < icuString.length) outputList.push(icuString.slice(previousIndex));
152
+ return outputList.join("");
153
+ }
154
+ //#endregion
155
+ //#region src/derive/utils/sanitizeVar.ts
156
+ /**
157
+ * Sanitizes string by escaping ICU syntax
158
+ *
159
+ * Sanitize arbitrary string so it does not break the following ICU message syntax:
160
+ * {_gt_, select, other {string_here}}
161
+ *
162
+ * Escapes ICU special characters by:
163
+ * 1. Doubling all single quotes (U+0027 ')
164
+ * 2. Adding a single quote before the first special character ({}<>)
165
+ * 3. Adding a single quote after the last special character ({}<>)
166
+ */
167
+ function sanitizeVar(string) {
168
+ let result = string.replace(/['\']/g, "''");
169
+ const specialChars = /[{}<>]/;
170
+ const firstSpecialIndex = result.search(specialChars);
171
+ if (firstSpecialIndex === -1) return result;
172
+ let lastSpecialIndex = -1;
173
+ for (let i = result.length - 1; i >= 0; i--) if (specialChars.test(result[i])) {
174
+ lastSpecialIndex = i;
175
+ break;
176
+ }
177
+ result = result.slice(0, firstSpecialIndex) + "'" + result.slice(firstSpecialIndex, lastSpecialIndex + 1) + "'" + result.slice(lastSpecialIndex + 1);
178
+ return result;
179
+ }
180
+ //#endregion
181
+ //#region src/derive/declareVar.ts
182
+ /**
183
+ * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).
184
+ *
185
+ * @example
186
+ * function nonDerivableFunction() {
187
+ * return Math.random();
188
+ * }
189
+ *
190
+ * function derivableFunction() {
191
+ * if (condition) {
192
+ * return declareVar(nonDerivableFunction())
193
+ * }
194
+ * return 'John Doe';
195
+ * }
196
+ *
197
+ * const gt = useGT();
198
+ * gt(`My name is ${derive(derivableFunction())}`);
199
+ *
200
+ * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.
201
+ * @param {Object} [options] - The options for the sanitization.
202
+ * @param {string} [options.$name] - The name of the variable.
203
+ * @returns {string} The sanitized value.
204
+ */
205
+ function declareVar(variable, options) {
206
+ const variableSection = ` other {${sanitizeVar(String(variable ?? ""))}}`;
207
+ let nameSection = "";
208
+ if (options?.$name) nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizeVar(options.$name)}}`;
209
+ return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;
210
+ }
211
+ //#endregion
212
+ //#region src/derive/derive.ts
213
+ /**
214
+ * derive() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.
215
+ *
216
+ * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.
217
+ *
218
+ * @example
219
+ * ```jsx
220
+ * function getSubject() {
221
+ * return (Math.random() > 0.5) ? "Alice" : "Brian";
222
+ * }
223
+ * ...
224
+ * gt(`My name is ${derive(getSubject())}`);
225
+ * ```
226
+ *
227
+ * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.
228
+ * @returns content
229
+ */
230
+ function derive(content) {
231
+ return content;
232
+ }
233
+ /**
234
+ * @deprecated Use derive() instead.
235
+ *
236
+ * declareStatic() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.
237
+ *
238
+ * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.
239
+ *
240
+ * @example
241
+ * ```jsx
242
+ * function getSubject() {
243
+ * return (Math.random() > 0.5) ? "Alice" : "Brian";
244
+ * }
245
+ * ...
246
+ * gt(`My name is ${declareStatic(getSubject())}`);
247
+ * ```
248
+ *
249
+ * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.
250
+ * @returns content
251
+ */
252
+ const declareStatic = derive;
253
+ //#endregion
254
+ //#region src/derive/indexVars.ts
255
+ /**
256
+ * Given an ICU string adds identifiers to each _gt_ placeholder
257
+ * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'
258
+ */
259
+ function indexVars(icuString) {
260
+ if (!icuString.includes("_gt_")) return icuString;
261
+ const variableLocations = [];
262
+ function visitor(child) {
263
+ variableLocations.push({
264
+ start: child.location?.start.offset ?? 0,
265
+ end: child.location?.end.offset ?? 0,
266
+ otherStart: child.options.other.location?.start.offset ?? 0,
267
+ otherEnd: child.options.other.location?.end.offset ?? 0
268
+ });
269
+ }
270
+ traverseIcu({
271
+ icuString,
272
+ shouldVisit: isGTUnindexedSelectElement,
273
+ visitor,
274
+ options: {
275
+ recurseIntoVisited: false,
276
+ captureLocation: true
277
+ }
278
+ });
279
+ const result = [];
280
+ let current = 0;
281
+ for (let i = 0; i < variableLocations.length; i++) {
282
+ const { start, end, otherStart, otherEnd } = variableLocations[i];
283
+ result.push(icuString.slice(current, start));
284
+ result.push(icuString.slice(start, start + 4 + 1));
285
+ result.push(String(i + 1));
286
+ result.push(icuString.slice(start + 4 + 1, otherStart));
287
+ result.push("{}");
288
+ result.push(icuString.slice(otherEnd, end));
289
+ current = end;
290
+ }
291
+ result.push(icuString.slice(current, icuString.length));
292
+ return result.join("");
293
+ }
294
+ //#endregion
295
+ //#region src/derive/extractVars.ts
296
+ /**
297
+ * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values
298
+ *
299
+ * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }
300
+ *
301
+ * @param {string} icuString - The ICU string to extract variables from.
302
+ * @returns {Record<string, string>} A mapping of the variable to the value.
303
+ */
304
+ function extractVars(icuString) {
305
+ if (!icuString.includes("_gt_")) return {};
306
+ let index = 1;
307
+ const variables = {};
308
+ function visitor(child) {
309
+ variables[child.value + index] = child.options.other.value.length ? child.options.other.value[0]?.value : "";
310
+ index += 1;
311
+ }
312
+ traverseIcu({
313
+ icuString,
314
+ shouldVisit: isGTUnindexedSelectElement,
315
+ visitor,
316
+ options: { recurseIntoVisited: false }
317
+ });
318
+ return variables;
319
+ }
320
+ //#endregion
321
+ //#region src/derive/condenseVars.ts
322
+ /**
323
+ * Given an indexed ICU string, condenses any select to an argument
324
+ * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
325
+ * @param {string} icuString - The ICU string to condense.
326
+ * @returns {string} The condensed ICU string.
327
+ */
328
+ function condenseVars(icuString) {
329
+ if (!icuString.includes("_gt_")) return icuString;
330
+ function visitor(child) {
331
+ child.type = _formatjs_icu_messageformat_parser_types_js.TYPE.argument;
332
+ delete child.options;
333
+ }
334
+ return (0, _formatjs_icu_messageformat_parser_printer_js.printAST)(traverseIcu({
335
+ icuString,
336
+ shouldVisit: isGTIndexedSelectElement,
337
+ visitor,
338
+ options: { recurseIntoVisited: false }
339
+ }));
340
+ }
341
+ //#endregion
342
+ //#region src/backwards-compatability/typeChecking.ts
343
+ /**
344
+ * Checks if a JSX child is an old variable object format
345
+ * @param child - The JSX child to check
346
+ * @returns True if the child is an old variable object (has 'key' property)
347
+ */
348
+ function isOldVariableObject(child) {
349
+ return typeof child === "object" && child != null && "key" in child;
350
+ }
351
+ /**
352
+ * Checks if a JSX child is a new variable object format
353
+ * @param child - The JSX child to check
354
+ * @returns True if the child is a new variable object (has 'k' property)
355
+ */
356
+ function isNewVariableObject(child) {
357
+ return typeof child === "object" && child != null && "k" in child;
358
+ }
359
+ /**
360
+ * Checks if a JSX child is an old JSX element format
361
+ * @param child - The JSX child to check
362
+ * @returns True if the child is an old JSX element (has 'type' and 'props' properties)
363
+ */
364
+ function isOldJsxElement(child) {
365
+ return typeof child === "object" && child != null && "type" in child && "props" in child;
366
+ }
367
+ /**
368
+ * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)
369
+ * @param child - The JSX child to check
370
+ * @returns True if the child is in the old format
371
+ */
372
+ function isOldJsxChild(child) {
373
+ if (typeof child === "string") return true;
374
+ if (isOldVariableObject(child)) return true;
375
+ return isOldJsxElement(child);
376
+ }
377
+ /**
378
+ * Checks if JSX children follow the old format
379
+ * @param children - The JSX children to check (can be string, array, or single child)
380
+ * @returns True if all children are in the old format
381
+ */
382
+ function isOldJsxChildren(children) {
383
+ if (typeof children === "string") return true;
384
+ if (Array.isArray(children)) return !children.some((child) => !isOldJsxChild(child));
385
+ return isOldJsxChild(children);
386
+ }
387
+ //#endregion
388
+ //#region src/backwards-compatability/dataConversion.ts
389
+ /**
390
+ * Convert request data from old format to new format
391
+ */
392
+ function getNewJsxChild(child) {
393
+ if (typeof child === "string") return child;
394
+ if (isOldVariableObject(child)) return getNewVariableObject(child);
395
+ return getNewJsxElement(child);
396
+ }
397
+ function getNewJsxChildren(children) {
398
+ if (typeof children === "string") return children;
399
+ if (Array.isArray(children)) return children.map(getNewJsxChild);
400
+ return getNewJsxChild(children);
401
+ }
402
+ function getNewJsxElement(element) {
403
+ if (typeof element === "string") return element;
404
+ let t = void 0;
405
+ if (element.type != null) t = element.type;
406
+ let c = void 0;
407
+ if (element.props?.children != null) c = getNewJsxChildren(element.props.children);
408
+ return {
409
+ ...t && { t },
410
+ ...c && { c },
411
+ d: getNewGTProp(element.props["data-_gt"]),
412
+ i: element.props["data-_gt"].id
413
+ };
414
+ }
415
+ function getNewBranchType(branch) {
416
+ if (branch === "branch") return "b";
417
+ return "p";
418
+ }
419
+ function getNewVariableType(variable) {
420
+ switch (variable) {
421
+ case "number": return "n";
422
+ case "variable": return "v";
423
+ case "datetime": return "d";
424
+ case "currency": return "c";
425
+ default: return "v";
426
+ }
427
+ }
428
+ function getNewVariableObject(variable) {
429
+ let v = void 0;
430
+ if (variable.variable != null) v = getNewVariableType(variable.variable);
431
+ let i = void 0;
432
+ if (variable.id != null) i = variable.id;
433
+ return {
434
+ k: variable.key,
435
+ ...v && { v },
436
+ ...i && { i }
437
+ };
438
+ }
439
+ function getNewGTProp(dataGT) {
440
+ let b = void 0;
441
+ if (dataGT.branches) b = Object.fromEntries(Object.entries(dataGT.branches).map(([key, value]) => [key, getNewJsxChildren(value)]));
442
+ let t;
443
+ if (dataGT.transformation) t = getNewBranchType(dataGT.transformation);
444
+ return {
445
+ ...b && { b },
446
+ ...t && { t }
447
+ };
448
+ }
449
+ /**
450
+ * Convert response data from old format to new format
451
+ */
452
+ function getOldJsxChild(child) {
453
+ if (typeof child === "string") return child;
454
+ if (isNewVariableObject(child)) return getOldVariableObject(child);
455
+ return getOldJsxElement(child);
456
+ }
457
+ function getOldJsxChildren(children) {
458
+ if (isOldJsxChildren(children)) return children;
459
+ if (typeof children === "string") return children;
460
+ if (Array.isArray(children)) return children.map(getOldJsxChild);
461
+ return getOldJsxChild(children);
462
+ }
463
+ function getOldJsxElement(element) {
464
+ const type = element.t;
465
+ let children = void 0;
466
+ if (element.c != null) children = getOldJsxChildren(element.c);
467
+ const dataGT = getOldGTProp(element.d || {}, element.i);
468
+ return {
469
+ type,
470
+ props: {
471
+ children,
472
+ "data-_gt": dataGT
473
+ }
474
+ };
475
+ }
476
+ function getOldBranchType(branch) {
477
+ if (branch === "b") return "branch";
478
+ return "plural";
479
+ }
480
+ function getOldVariableType(variable) {
481
+ switch (variable) {
482
+ case "n": return "number";
483
+ case "v": return "variable";
484
+ case "d": return "datetime";
485
+ case "c": return "currency";
486
+ default: return "variable";
487
+ }
488
+ }
489
+ function getOldVariableObject(variable) {
490
+ let v = void 0;
491
+ if (variable.v != null) v = getOldVariableType(variable.v);
492
+ let i = void 0;
493
+ if (variable.i != null) i = variable.i;
494
+ return {
495
+ key: variable.k,
496
+ ...v && { variable: v },
497
+ ...i && { id: i }
498
+ };
499
+ }
500
+ function getOldGTProp(dataGT, i) {
501
+ let transformation = void 0;
502
+ if (dataGT.t != null) transformation = getOldBranchType(dataGT.t);
503
+ let branches = void 0;
504
+ if (dataGT.b != null) branches = Object.fromEntries(Object.entries(dataGT.b).map(([key, value]) => [key, getOldJsxChildren(value)]));
505
+ return {
506
+ id: i,
507
+ ...transformation && { transformation },
508
+ ...branches && { branches }
509
+ };
510
+ }
511
+ //#endregion
512
+ //#region src/backwards-compatability/oldHashJsxChildren.ts
513
+ /**
514
+ * Calculates a unique hash for a given string using sha256.
515
+ *
516
+ * @param {string} string - The string to be hashed.
517
+ * @returns {string} - The resulting hash as a hexadecimal string.
518
+ */
519
+ function oldHashString(string) {
520
+ return require_isVariable.bytesToHex(require_isVariable.sha256(require_isVariable.utf8ToBytes(string)));
521
+ }
522
+ /**
523
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
524
+ *
525
+ * @param {any} childrenAsObjects - The children objects to be hashed.
526
+ * @param {string} context - The context for the children
527
+ * @param {string} id - The id for the JSX Children object
528
+ * @param {function} hashFunction custom hash function
529
+ * @returns {string} - The unique has of the children.
530
+ */
531
+ function oldHashJsxChildren({ source, context, id, dataFormat }, hashFunction = oldHashString) {
532
+ return hashFunction(require_isVariable.stableStringify({
533
+ source: sanitizeJsxChildren(source),
534
+ ...id && { id },
535
+ ...context && { context },
536
+ ...dataFormat && { dataFormat }
537
+ }));
538
+ }
539
+ const sanitizeChild = (child) => {
540
+ if (child && typeof child === "object") {
541
+ if ("props" in child) {
542
+ const newChild = {};
543
+ const dataGt = child?.props?.["data-_gt"];
544
+ if (dataGt?.branches) newChild.branches = Object.fromEntries(Object.entries(dataGt.branches).map(([key, value]) => [key, sanitizeJsxChildren(value)]));
545
+ if (child?.props?.children) newChild.children = sanitizeJsxChildren(child.props.children);
546
+ if (child?.props?.["data-_gt"]?.transformation) newChild.transformation = child.props["data-_gt"].transformation;
547
+ return newChild;
548
+ }
549
+ if ("key" in child) return {
550
+ key: child.key,
551
+ ...child.variable && { variable: child.variable }
552
+ };
553
+ }
554
+ return child;
555
+ };
556
+ function sanitizeJsxChildren(childrenAsObjects) {
557
+ return Array.isArray(childrenAsObjects) ? childrenAsObjects.map(sanitizeChild) : sanitizeChild(childrenAsObjects);
558
+ }
559
+ //#endregion
560
+ exports.VAR_IDENTIFIER = VAR_IDENTIFIER;
561
+ exports.VAR_NAME_IDENTIFIER = VAR_NAME_IDENTIFIER;
562
+ exports.condenseVars = condenseVars;
563
+ exports.declareStatic = declareStatic;
564
+ exports.declareVar = declareVar;
565
+ exports.decode = require_base64.decode;
566
+ exports.decodeVars = decodeVars;
567
+ exports.defaultBaseUrl = require_base64.defaultBaseUrl;
568
+ exports.defaultCacheUrl = require_base64.defaultCacheUrl;
569
+ exports.defaultRuntimeApiUrl = require_base64.defaultRuntimeApiUrl;
570
+ exports.defaultTimeout = require_IntlCache.defaultTimeout;
571
+ exports.derive = derive;
572
+ exports.encode = require_base64.encode;
573
+ exports.extractVars = extractVars;
574
+ exports.getNewBranchType = getNewBranchType;
575
+ exports.getNewGTProp = getNewGTProp;
576
+ exports.getNewJsxChild = getNewJsxChild;
577
+ exports.getNewJsxChildren = getNewJsxChildren;
578
+ exports.getNewJsxElement = getNewJsxElement;
579
+ exports.getNewVariableObject = getNewVariableObject;
580
+ exports.getNewVariableType = getNewVariableType;
581
+ exports.getOldBranchType = getOldBranchType;
582
+ exports.getOldGTProp = getOldGTProp;
583
+ exports.getOldJsxChild = getOldJsxChild;
584
+ exports.getOldJsxChildren = getOldJsxChildren;
585
+ exports.getOldJsxElement = getOldJsxElement;
586
+ exports.getOldVariableObject = getOldVariableObject;
587
+ exports.getOldVariableType = getOldVariableType;
588
+ exports.getPluralForm = _getPluralForm;
589
+ exports.indexVars = indexVars;
590
+ exports.isAcceptedPluralForm = isAcceptedPluralForm;
591
+ exports.isNewVariableObject = isNewVariableObject;
592
+ exports.isOldJsxChildren = isOldJsxChildren;
593
+ exports.isOldVariableObject = isOldVariableObject;
594
+ exports.isSupportedFileFormatTransform = require_base64.isSupportedFileFormatTransform;
595
+ exports.isVariable = require_isVariable.isVariable;
596
+ exports.libraryDefaultLocale = require_IntlCache.libraryDefaultLocale;
597
+ exports.minifyVariableType = minifyVariableType;
598
+ exports.oldHashJsxChildren = oldHashJsxChildren;
599
+ exports.oldHashString = oldHashString;
600
+ exports.pluralForms = pluralForms;
601
+ exports.validateFileFormatTransforms = require_base64.validateFileFormatTransforms;
602
+
603
+ //# sourceMappingURL=internal.cjs.map