generaltranslation 8.2.6 → 8.2.8

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 (162) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/ApiError-4zIP-twr.cjs +24 -0
  3. package/dist/ApiError-4zIP-twr.cjs.map +1 -0
  4. package/dist/ApiError-Bv7vlzyQ.mjs +19 -0
  5. package/dist/ApiError-Bv7vlzyQ.mjs.map +1 -0
  6. package/dist/errors.cjs +3 -0
  7. package/dist/errors.d.cts +11 -0
  8. package/dist/errors.d.mts +11 -0
  9. package/dist/errors.mjs +2 -0
  10. package/dist/id-CPbVYREY.mjs +74 -0
  11. package/dist/id-CPbVYREY.mjs.map +1 -0
  12. package/dist/id-VXBgyXu2.cjs +89 -0
  13. package/dist/id-VXBgyXu2.cjs.map +1 -0
  14. package/dist/id.cjs +5 -0
  15. package/dist/{id/hashSource.d.ts → id.d.cts} +20 -5
  16. package/dist/id.d.mts +40 -0
  17. package/dist/id.mjs +2 -0
  18. package/dist/index.cjs +3491 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +1219 -0
  21. package/dist/index.d.mts +1219 -0
  22. package/dist/index.mjs +3441 -0
  23. package/dist/index.mjs.map +1 -0
  24. package/dist/internal-B3QbyI_5.mjs +820 -0
  25. package/dist/internal-B3QbyI_5.mjs.map +1 -0
  26. package/dist/internal-DIHQF9gs.cjs +1070 -0
  27. package/dist/internal-DIHQF9gs.cjs.map +1 -0
  28. package/dist/internal.cjs +45 -0
  29. package/dist/{internal.d.ts → internal.d.cts} +82 -113
  30. package/dist/internal.d.mts +263 -0
  31. package/dist/internal.mjs +3 -0
  32. package/dist/sha2-DKowBr6H.cjs +747 -0
  33. package/dist/sha2-DKowBr6H.cjs.map +1 -0
  34. package/dist/stableStringify-DgDlE_pD.mjs +53 -0
  35. package/dist/stableStringify-DgDlE_pD.mjs.map +1 -0
  36. package/dist/types-BJdoI1d1.d.cts +741 -0
  37. package/dist/types-DazaDJbs.d.mts +741 -0
  38. package/dist/types.cjs +17 -0
  39. package/dist/types.cjs.map +1 -0
  40. package/dist/types.d.cts +2 -0
  41. package/dist/types.d.mts +2 -0
  42. package/dist/types.mjs +16 -0
  43. package/dist/types.mjs.map +1 -0
  44. package/package.json +52 -32
  45. package/dist/backwards-compatability/dataConversion.d.ts +0 -23
  46. package/dist/backwards-compatability/oldHashJsxChildren.d.ts +0 -23
  47. package/dist/backwards-compatability/oldTypes.d.ts +0 -21
  48. package/dist/backwards-compatability/typeChecking.d.ts +0 -21
  49. package/dist/cache/IntlCache.d.ts +0 -26
  50. package/dist/cache/types.d.ts +0 -32
  51. package/dist/derive/condenseVars.d.ts +0 -7
  52. package/dist/derive/declareVar.d.ts +0 -26
  53. package/dist/derive/decodeVars.d.ts +0 -9
  54. package/dist/derive/derive.d.ts +0 -38
  55. package/dist/derive/extractVars.d.ts +0 -9
  56. package/dist/derive/index.d.ts +0 -7
  57. package/dist/derive/indexVars.d.ts +0 -6
  58. package/dist/derive/utils/constants.d.ts +0 -2
  59. package/dist/derive/utils/regex.d.ts +0 -2
  60. package/dist/derive/utils/sanitizeVar.d.ts +0 -12
  61. package/dist/derive/utils/traverseHelpers.d.ts +0 -4
  62. package/dist/derive/utils/traverseIcu.d.ts +0 -20
  63. package/dist/derive/utils/types.d.ts +0 -23
  64. package/dist/errors/ApiError.d.ts +0 -7
  65. package/dist/errors/formattingErrors.d.ts +0 -1
  66. package/dist/errors.cjs.min.cjs +0 -2
  67. package/dist/errors.cjs.min.cjs.map +0 -1
  68. package/dist/errors.d.ts +0 -9
  69. package/dist/errors.esm.min.mjs +0 -2
  70. package/dist/errors.esm.min.mjs.map +0 -1
  71. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  72. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  73. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  74. package/dist/formatting/format.d.ts +0 -1
  75. package/dist/id/hashTemplate.d.ts +0 -4
  76. package/dist/id/types.d.ts +0 -7
  77. package/dist/id.cjs.min.cjs +0 -2
  78. package/dist/id.cjs.min.cjs.map +0 -1
  79. package/dist/id.d.ts +0 -86
  80. package/dist/id.esm.min.mjs +0 -2
  81. package/dist/id.esm.min.mjs.map +0 -1
  82. package/dist/index.cjs.min.cjs +0 -2
  83. package/dist/index.cjs.min.cjs.map +0 -1
  84. package/dist/index.d.ts +0 -1627
  85. package/dist/index.esm.min.mjs +0 -2
  86. package/dist/index.esm.min.mjs.map +0 -1
  87. package/dist/internal.cjs.min.cjs +0 -2
  88. package/dist/internal.cjs.min.cjs.map +0 -1
  89. package/dist/internal.esm.min.mjs +0 -2
  90. package/dist/internal.esm.min.mjs.map +0 -1
  91. package/dist/locales/customLocaleMapping.d.ts +0 -11
  92. package/dist/locales/determineLocale.d.ts +0 -1
  93. package/dist/locales/getLocaleDirection.d.ts +0 -1
  94. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  95. package/dist/locales/getLocaleName.d.ts +0 -1
  96. package/dist/locales/getLocaleProperties.d.ts +0 -32
  97. package/dist/locales/getPluralForm.d.ts +0 -9
  98. package/dist/locales/getRegionProperties.d.ts +0 -7
  99. package/dist/locales/isSameDialect.d.ts +0 -1
  100. package/dist/locales/isSameLanguage.d.ts +0 -1
  101. package/dist/locales/isSupersetLocale.d.ts +0 -1
  102. package/dist/locales/isValidLocale.d.ts +0 -1
  103. package/dist/locales/requiresTranslation.d.ts +0 -1
  104. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  105. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  106. package/dist/logging/errors.d.ts +0 -10
  107. package/dist/logging/logger.d.ts +0 -117
  108. package/dist/logging/warnings.d.ts +0 -2
  109. package/dist/projects/getProjectData.d.ts +0 -1
  110. package/dist/settings/plurals.d.ts +0 -3
  111. package/dist/settings/settings.d.ts +0 -2
  112. package/dist/settings/settingsUrls.d.ts +0 -3
  113. package/dist/translate/api.d.ts +0 -1
  114. package/dist/translate/awaitJobs.d.ts +0 -19
  115. package/dist/translate/checkJobStatus.d.ts +0 -8
  116. package/dist/translate/createBranch.d.ts +0 -10
  117. package/dist/translate/createTag.d.ts +0 -19
  118. package/dist/translate/downloadFileBatch.d.ts +0 -1
  119. package/dist/translate/enqueueFiles.d.ts +0 -8
  120. package/dist/translate/getOrphanedFiles.d.ts +0 -8
  121. package/dist/translate/processFileMoves.d.ts +0 -25
  122. package/dist/translate/publishFiles.d.ts +0 -17
  123. package/dist/translate/queryBranchData.d.ts +0 -3
  124. package/dist/translate/queryFileData.d.ts +0 -42
  125. package/dist/translate/querySourceFile.d.ts +0 -1
  126. package/dist/translate/setupProject.d.ts +0 -11
  127. package/dist/translate/submitUserEditDiffs.d.ts +0 -12
  128. package/dist/translate/translateMany.d.ts +0 -1
  129. package/dist/translate/uploadSourceFiles.d.ts +0 -1
  130. package/dist/translate/uploadTranslations.d.ts +0 -1
  131. package/dist/translate/utils/apiRequest.d.ts +0 -1
  132. package/dist/translate/utils/batch.d.ts +0 -52
  133. package/dist/translate/utils/fetchWithTimeout.d.ts +0 -1
  134. package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
  135. package/dist/translate/utils/handleFetchError.d.ts +0 -1
  136. package/dist/translate/utils/validateResponse.d.ts +0 -1
  137. package/dist/types-dir/api/branch.d.ts +0 -10
  138. package/dist/types-dir/api/checkFileTranslations.d.ts +0 -37
  139. package/dist/types-dir/api/downloadFile.d.ts +0 -3
  140. package/dist/types-dir/api/downloadFileBatch.d.ts +0 -34
  141. package/dist/types-dir/api/enqueueEntries.d.ts +0 -21
  142. package/dist/types-dir/api/enqueueFiles.d.ts +0 -56
  143. package/dist/types-dir/api/entry.d.ts +0 -36
  144. package/dist/types-dir/api/fetchTranslations.d.ts +0 -11
  145. package/dist/types-dir/api/file.d.ts +0 -54
  146. package/dist/types-dir/api/project.d.ts +0 -7
  147. package/dist/types-dir/api/translate.d.ts +0 -34
  148. package/dist/types-dir/api/translateMany.d.ts +0 -5
  149. package/dist/types-dir/api/translationStatus.d.ts +0 -9
  150. package/dist/types-dir/api/uploadFiles.d.ts +0 -43
  151. package/dist/types-dir/jsx/content.d.ts +0 -61
  152. package/dist/types-dir/jsx/variables.d.ts +0 -9
  153. package/dist/types-dir/transformations.d.ts +0 -8
  154. package/dist/types.cjs.min.cjs +0 -2
  155. package/dist/types.cjs.min.cjs.map +0 -1
  156. package/dist/types.d.ts +0 -652
  157. package/dist/types.esm.min.mjs +0 -2
  158. package/dist/types.esm.min.mjs.map +0 -1
  159. package/dist/utils/base64.d.ts +0 -2
  160. package/dist/utils/isVariable.d.ts +0 -2
  161. package/dist/utils/minify.d.ts +0 -2
  162. package/dist/utils/stableStringify.d.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # generaltranslation
2
2
 
3
+ ## 8.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1248](https://github.com/generaltranslation/gt/pull/1248) [`b12d57d`](https://github.com/generaltranslation/gt/commit/b12d57dab1d5cb1f602c5ac24a702b48cda7f11e) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add PO/POT file format support and transformFormat plumbing for API uploads and CLI file downloads.
8
+
9
+ ## 8.2.7
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1246](https://github.com/generaltranslation/gt/pull/1246) [`e3a8008`](https://github.com/generaltranslation/gt/commit/e3a8008ed0a3ab82d053f549265f9de7829e94c5) Thanks [@bgub](https://github.com/bgub)! - Migrate build tooling from Rollup to tsdown (Rolldown). No public API changes. Output filenames simplified (e.g. `index.cjs.min.cjs` → `index.cjs`), minification removed (consumers bundle with their own minifier).
14
+
15
+ - [#1251](https://github.com/generaltranslation/gt/pull/1251) [`fc3c699`](https://github.com/generaltranslation/gt/commit/fc3c699d2c952710cc975e26629ac309063dcbc7) Thanks [@bgub](https://github.com/bgub)! - Declare `sideEffects` in each package's `package.json` to enable tree-shaking in consumer bundlers (webpack, esbuild, Rollup). Packages with no module-scope side effects are marked `"sideEffects": false`. Packages with intentional side-effect entry points (`gt-react/browser`, `gt-react/macros`, `gt-next` server entries, `gt-react-native` TurboModule spec) list those files explicitly so they are preserved.
16
+
3
17
  ## 8.2.6
4
18
 
5
19
  ### Patch Changes
@@ -0,0 +1,24 @@
1
+ //#region src/errors/ApiError.ts
2
+ var ApiError = class extends Error {
3
+ constructor(error, code, message) {
4
+ super(error);
5
+ this.name = "ApiError";
6
+ this.code = code;
7
+ this.message = message;
8
+ }
9
+ getCode() {
10
+ return this.code;
11
+ }
12
+ getMessage() {
13
+ return this.message;
14
+ }
15
+ };
16
+ //#endregion
17
+ Object.defineProperty(exports, "ApiError", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return ApiError;
21
+ }
22
+ });
23
+
24
+ //# sourceMappingURL=ApiError-4zIP-twr.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiError-4zIP-twr.cjs","names":[],"sources":["../src/errors/ApiError.ts"],"sourcesContent":["export class ApiError extends Error {\n public code: number;\n public message: string;\n\n constructor(error: string, code: number, message: string) {\n super(error);\n this.name = 'ApiError';\n this.code = code;\n this.message = message;\n }\n\n getCode() {\n return this.code;\n }\n\n getMessage() {\n return this.message;\n }\n}\n"],"mappings":";AAAA,IAAa,WAAb,cAA8B,MAAM;CAIlC,YAAY,OAAe,MAAc,SAAiB;AACxD,QAAM,MAAM;AACZ,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGjB,UAAU;AACR,SAAO,KAAK;;CAGd,aAAa;AACX,SAAO,KAAK"}
@@ -0,0 +1,19 @@
1
+ //#region src/errors/ApiError.ts
2
+ var ApiError = class extends Error {
3
+ constructor(error, code, message) {
4
+ super(error);
5
+ this.name = "ApiError";
6
+ this.code = code;
7
+ this.message = message;
8
+ }
9
+ getCode() {
10
+ return this.code;
11
+ }
12
+ getMessage() {
13
+ return this.message;
14
+ }
15
+ };
16
+ //#endregion
17
+ export { ApiError as t };
18
+
19
+ //# sourceMappingURL=ApiError-Bv7vlzyQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiError-Bv7vlzyQ.mjs","names":[],"sources":["../src/errors/ApiError.ts"],"sourcesContent":["export class ApiError extends Error {\n public code: number;\n public message: string;\n\n constructor(error: string, code: number, message: string) {\n super(error);\n this.name = 'ApiError';\n this.code = code;\n this.message = message;\n }\n\n getCode() {\n return this.code;\n }\n\n getMessage() {\n return this.message;\n }\n}\n"],"mappings":";AAAA,IAAa,WAAb,cAA8B,MAAM;CAIlC,YAAY,OAAe,MAAc,SAAiB;AACxD,QAAM,MAAM;AACZ,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGjB,UAAU;AACR,SAAO,KAAK;;CAGd,aAAa;AACX,SAAO,KAAK"}
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_ApiError = require("./ApiError-4zIP-twr.cjs");
3
+ exports.ApiError = require_ApiError.ApiError;
@@ -0,0 +1,11 @@
1
+ //#region src/errors/ApiError.d.ts
2
+ declare class ApiError extends Error {
3
+ code: number;
4
+ message: string;
5
+ constructor(error: string, code: number, message: string);
6
+ getCode(): number;
7
+ getMessage(): string;
8
+ }
9
+ //#endregion
10
+ export { ApiError };
11
+ //# sourceMappingURL=errors.d.cts.map
@@ -0,0 +1,11 @@
1
+ //#region src/errors/ApiError.d.ts
2
+ declare class ApiError extends Error {
3
+ code: number;
4
+ message: string;
5
+ constructor(error: string, code: number, message: string);
6
+ getCode(): number;
7
+ getMessage(): string;
8
+ }
9
+ //#endregion
10
+ export { ApiError };
11
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1,2 @@
1
+ import { t as ApiError } from "./ApiError-Bv7vlzyQ.mjs";
2
+ export { ApiError };
@@ -0,0 +1,74 @@
1
+ import { n as isVariable, t as stableStringify } from "./stableStringify-DgDlE_pD.mjs";
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
+ import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
4
+ //#region src/id/hashSource.ts
5
+ /**
6
+ * Calculates a unique hash for a given string using sha256.
7
+ *
8
+ * First 16 characters of hash, hex encoded.
9
+ *
10
+ * @param {string} string - The string to be hashed.
11
+ * @returns {string} - The resulting hash as a hexadecimal string.
12
+ */
13
+ function hashString(string) {
14
+ return bytesToHex(sha256(utf8ToBytes(string))).slice(0, 16);
15
+ }
16
+ /**
17
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
18
+ *
19
+ * @param {any} childrenAsObjects - The children objects to be hashed.
20
+ * @param {string} [context] - The context for the children
21
+ * @param {string} [id] - The id for the JSX Children object
22
+ * @param {number} [maxChars] - The maxChars for the JSX Children object
23
+ * @param {string} [dataFormat] - The data format of the sources
24
+ * @param {function} [hashFunction] custom hash function
25
+ * @returns {string} - The unique has of the children.
26
+ */
27
+ function hashSource({ source, context, id, maxChars, dataFormat }, hashFunction = hashString) {
28
+ let sanitizedSource;
29
+ if (dataFormat === "JSX") sanitizedSource = sanitizeJsxChildren(source);
30
+ else sanitizedSource = source;
31
+ return hashFunction(stableStringify({
32
+ source: sanitizedSource,
33
+ ...id && { id },
34
+ ...context && { context },
35
+ ...maxChars != null && { maxChars: Math.abs(maxChars) },
36
+ ...dataFormat && { dataFormat }
37
+ }));
38
+ }
39
+ /**
40
+ * Sanitizes a child object by removing the data-_gt attribute and its branches.
41
+ *
42
+ * @param child - The child object to sanitize.
43
+ * @returns The sanitized child object.
44
+ *
45
+ */
46
+ const sanitizeChild = (child) => {
47
+ if (child && typeof child === "object") {
48
+ const newChild = {};
49
+ if ("c" in child && child.c) newChild.c = sanitizeJsxChildren(child.c);
50
+ if ("d" in child) {
51
+ const generaltranslation = child?.d;
52
+ if (generaltranslation?.b) newChild.b = Object.fromEntries(Object.entries(generaltranslation.b).map(([key, value]) => [key, sanitizeJsxChildren(value)]));
53
+ if (generaltranslation?.t) newChild.t = generaltranslation.t;
54
+ }
55
+ if (isVariable(child)) return {
56
+ k: child.k,
57
+ ...child.v && { v: child.v }
58
+ };
59
+ return newChild;
60
+ }
61
+ return child;
62
+ };
63
+ function sanitizeJsxChildren(childrenAsObjects) {
64
+ return Array.isArray(childrenAsObjects) ? childrenAsObjects.map(sanitizeChild) : sanitizeChild(childrenAsObjects);
65
+ }
66
+ //#endregion
67
+ //#region src/id/hashTemplate.ts
68
+ function hashTemplate(template, hashFunction = hashString) {
69
+ return hashFunction(stableStringify(template));
70
+ }
71
+ //#endregion
72
+ export { hashSource as n, hashString as r, hashTemplate as t };
73
+
74
+ //# sourceMappingURL=id-CPbVYREY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-CPbVYREY.mjs","names":["stringify","stringify"],"sources":["../src/id/hashSource.ts","../src/id/hashTemplate.ts"],"sourcesContent":["// Functions provided to other GT libraries\n\nimport { JsxChild, JsxChildren, Variable } from '../types';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\nimport isVariable from '../utils/isVariable';\nimport { HashMetadata } from './types';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using sha256.\n *\n * First 16 characters of hash, hex encoded.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} - The resulting hash as a hexadecimal string.\n */\nexport function hashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string))).slice(0, 16);\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} [context] - The context for the children\n * @param {string} [id] - The id for the JSX Children object\n * @param {number} [maxChars] - The maxChars for the JSX Children object\n * @param {string} [dataFormat] - The data format of the sources\n * @param {function} [hashFunction] custom hash function\n * @returns {string} - The unique has of the children.\n */\nexport function hashSource(\n {\n source,\n context,\n id,\n maxChars,\n dataFormat,\n }: {\n source: JsxChildren | string;\n } & HashMetadata,\n hashFunction: (string: string) => string = hashString\n): string {\n let sanitizedSource: SanitizedChildren | string;\n if (dataFormat === 'JSX') {\n sanitizedSource = sanitizeJsxChildren(source);\n } else {\n sanitizedSource = source as string;\n }\n const sanitizedData: {\n source?: SanitizedChildren;\n } & HashMetadata = {\n source: sanitizedSource,\n ...(id && { id }),\n ...(context && { context }),\n ...(maxChars != null && { maxChars: Math.abs(maxChars) }),\n ...(dataFormat && { dataFormat }),\n };\n const stringifiedData = stringify(sanitizedData);\n return hashFunction(stringifiedData);\n}\n\ntype SanitizedVariable = Omit<Variable, 'i'>;\n\ntype SanitizedElement = {\n b?: {\n [k: string]: SanitizedChildren; // Branches\n };\n c?: SanitizedChildren; // Children\n t?: string; // Branch Transformation\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\n/**\n * Sanitizes a child object by removing the data-_gt attribute and its branches.\n *\n * @param child - The child object to sanitize.\n * @returns The sanitized child object.\n *\n */\nconst sanitizeChild = (child: JsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n const newChild: SanitizedChild = {};\n if ('c' in child && child.c) {\n newChild.c = sanitizeJsxChildren(child.c);\n }\n if ('d' in child) {\n const generaltranslation = child?.d;\n if (generaltranslation?.b) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.b = Object.fromEntries(\n Object.entries(generaltranslation.b).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as JsxChildren),\n ])\n );\n }\n if (generaltranslation?.t) {\n newChild.t = generaltranslation.t;\n }\n }\n if (isVariable(child)) {\n return {\n k: child.k,\n ...(child.v && {\n v: child.v,\n }),\n };\n }\n return newChild;\n }\n return child;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: JsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n","import { hashString } from './hashSource';\nimport { stableStringify as stringify } from '../utils/stableStringify';\n\nexport default function hashTemplate(\n template: {\n [key: string]: string;\n },\n hashFunction = hashString\n): string {\n return hashFunction(stringify(template));\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAgB,WAAW,QAAwB;AACjD,QAAO,WAAW,OAAO,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG;;;;;;;;;;;;;AAc7D,SAAgB,WACd,EACE,QACA,SACA,IACA,UACA,cAIF,eAA2C,YACnC;CACR,IAAI;AACJ,KAAI,eAAe,MACjB,mBAAkB,oBAAoB,OAAO;KAE7C,mBAAkB;AAYpB,QAAO,aADiBA,gBAAU;EANhC,QAAQ;EACR,GAAI,MAAM,EAAE,IAAI;EAChB,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,YAAY,QAAQ,EAAE,UAAU,KAAK,IAAI,SAAS,EAAE;EACxD,GAAI,cAAc,EAAE,YAAY;EAEa,CACZ,CAAC;;;;;;;;;AAsBtC,MAAM,iBAAiB,UAAoC;AACzD,KAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,WAA2B,EAAE;AACnC,MAAI,OAAO,SAAS,MAAM,EACxB,UAAS,IAAI,oBAAoB,MAAM,EAAE;AAE3C,MAAI,OAAO,OAAO;GAChB,MAAM,qBAAqB,OAAO;AAClC,OAAI,oBAAoB,EAItB,UAAS,IAAI,OAAO,YAClB,OAAO,QAAQ,mBAAmB,EAAE,CAAC,KAAK,CAAC,KAAK,WAAW,CACzD,KACA,oBAAoB,MAAqB,CAC1C,CAAC,CACH;AAEH,OAAI,oBAAoB,EACtB,UAAS,IAAI,mBAAmB;;AAGpC,MAAI,WAAW,MAAM,CACnB,QAAO;GACL,GAAG,MAAM;GACT,GAAI,MAAM,KAAK,EACb,GAAG,MAAM,GACV;GACF;AAEH,SAAO;;AAET,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB;;;;ACzHtC,SAAwB,aACtB,UAGA,eAAe,YACP;AACR,QAAO,aAAaC,gBAAU,SAAS,CAAC"}
@@ -0,0 +1,89 @@
1
+ const require_sha2 = require("./sha2-DKowBr6H.cjs");
2
+ //#region src/id/hashSource.ts
3
+ /**
4
+ * Calculates a unique hash for a given string using sha256.
5
+ *
6
+ * First 16 characters of hash, hex encoded.
7
+ *
8
+ * @param {string} string - The string to be hashed.
9
+ * @returns {string} - The resulting hash as a hexadecimal string.
10
+ */
11
+ function hashString(string) {
12
+ return require_sha2.bytesToHex(require_sha2.sha256(require_sha2.utf8ToBytes(string))).slice(0, 16);
13
+ }
14
+ /**
15
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
16
+ *
17
+ * @param {any} childrenAsObjects - The children objects to be hashed.
18
+ * @param {string} [context] - The context for the children
19
+ * @param {string} [id] - The id for the JSX Children object
20
+ * @param {number} [maxChars] - The maxChars for the JSX Children object
21
+ * @param {string} [dataFormat] - The data format of the sources
22
+ * @param {function} [hashFunction] custom hash function
23
+ * @returns {string} - The unique has of the children.
24
+ */
25
+ function hashSource({ source, context, id, maxChars, dataFormat }, hashFunction = hashString) {
26
+ let sanitizedSource;
27
+ if (dataFormat === "JSX") sanitizedSource = sanitizeJsxChildren(source);
28
+ else sanitizedSource = source;
29
+ return hashFunction(require_sha2.stableStringify({
30
+ source: sanitizedSource,
31
+ ...id && { id },
32
+ ...context && { context },
33
+ ...maxChars != null && { maxChars: Math.abs(maxChars) },
34
+ ...dataFormat && { dataFormat }
35
+ }));
36
+ }
37
+ /**
38
+ * Sanitizes a child object by removing the data-_gt attribute and its branches.
39
+ *
40
+ * @param child - The child object to sanitize.
41
+ * @returns The sanitized child object.
42
+ *
43
+ */
44
+ const sanitizeChild = (child) => {
45
+ if (child && typeof child === "object") {
46
+ const newChild = {};
47
+ if ("c" in child && child.c) newChild.c = sanitizeJsxChildren(child.c);
48
+ if ("d" in child) {
49
+ const generaltranslation = child?.d;
50
+ if (generaltranslation?.b) newChild.b = Object.fromEntries(Object.entries(generaltranslation.b).map(([key, value]) => [key, sanitizeJsxChildren(value)]));
51
+ if (generaltranslation?.t) newChild.t = generaltranslation.t;
52
+ }
53
+ if (require_sha2.isVariable(child)) return {
54
+ k: child.k,
55
+ ...child.v && { v: child.v }
56
+ };
57
+ return newChild;
58
+ }
59
+ return child;
60
+ };
61
+ function sanitizeJsxChildren(childrenAsObjects) {
62
+ return Array.isArray(childrenAsObjects) ? childrenAsObjects.map(sanitizeChild) : sanitizeChild(childrenAsObjects);
63
+ }
64
+ //#endregion
65
+ //#region src/id/hashTemplate.ts
66
+ function hashTemplate(template, hashFunction = hashString) {
67
+ return hashFunction(require_sha2.stableStringify(template));
68
+ }
69
+ //#endregion
70
+ Object.defineProperty(exports, "hashSource", {
71
+ enumerable: true,
72
+ get: function() {
73
+ return hashSource;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, "hashString", {
77
+ enumerable: true,
78
+ get: function() {
79
+ return hashString;
80
+ }
81
+ });
82
+ Object.defineProperty(exports, "hashTemplate", {
83
+ enumerable: true,
84
+ get: function() {
85
+ return hashTemplate;
86
+ }
87
+ });
88
+
89
+ //# sourceMappingURL=id-VXBgyXu2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-VXBgyXu2.cjs","names":["bytesToHex","sha256","utf8ToBytes","stringify","isVariable","stringify"],"sources":["../src/id/hashSource.ts","../src/id/hashTemplate.ts"],"sourcesContent":["// Functions provided to other GT libraries\n\nimport { JsxChild, JsxChildren, Variable } from '../types';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\nimport isVariable from '../utils/isVariable';\nimport { HashMetadata } from './types';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using sha256.\n *\n * First 16 characters of hash, hex encoded.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} - The resulting hash as a hexadecimal string.\n */\nexport function hashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string))).slice(0, 16);\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} [context] - The context for the children\n * @param {string} [id] - The id for the JSX Children object\n * @param {number} [maxChars] - The maxChars for the JSX Children object\n * @param {string} [dataFormat] - The data format of the sources\n * @param {function} [hashFunction] custom hash function\n * @returns {string} - The unique has of the children.\n */\nexport function hashSource(\n {\n source,\n context,\n id,\n maxChars,\n dataFormat,\n }: {\n source: JsxChildren | string;\n } & HashMetadata,\n hashFunction: (string: string) => string = hashString\n): string {\n let sanitizedSource: SanitizedChildren | string;\n if (dataFormat === 'JSX') {\n sanitizedSource = sanitizeJsxChildren(source);\n } else {\n sanitizedSource = source as string;\n }\n const sanitizedData: {\n source?: SanitizedChildren;\n } & HashMetadata = {\n source: sanitizedSource,\n ...(id && { id }),\n ...(context && { context }),\n ...(maxChars != null && { maxChars: Math.abs(maxChars) }),\n ...(dataFormat && { dataFormat }),\n };\n const stringifiedData = stringify(sanitizedData);\n return hashFunction(stringifiedData);\n}\n\ntype SanitizedVariable = Omit<Variable, 'i'>;\n\ntype SanitizedElement = {\n b?: {\n [k: string]: SanitizedChildren; // Branches\n };\n c?: SanitizedChildren; // Children\n t?: string; // Branch Transformation\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\n/**\n * Sanitizes a child object by removing the data-_gt attribute and its branches.\n *\n * @param child - The child object to sanitize.\n * @returns The sanitized child object.\n *\n */\nconst sanitizeChild = (child: JsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n const newChild: SanitizedChild = {};\n if ('c' in child && child.c) {\n newChild.c = sanitizeJsxChildren(child.c);\n }\n if ('d' in child) {\n const generaltranslation = child?.d;\n if (generaltranslation?.b) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.b = Object.fromEntries(\n Object.entries(generaltranslation.b).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as JsxChildren),\n ])\n );\n }\n if (generaltranslation?.t) {\n newChild.t = generaltranslation.t;\n }\n }\n if (isVariable(child)) {\n return {\n k: child.k,\n ...(child.v && {\n v: child.v,\n }),\n };\n }\n return newChild;\n }\n return child;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: JsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n","import { hashString } from './hashSource';\nimport { stableStringify as stringify } from '../utils/stableStringify';\n\nexport default function hashTemplate(\n template: {\n [key: string]: string;\n },\n hashFunction = hashString\n): string {\n return hashFunction(stringify(template));\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,WAAW,QAAwB;AACjD,QAAOA,aAAAA,WAAWC,aAAAA,OAAOC,aAAAA,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG;;;;;;;;;;;;;AAc7D,SAAgB,WACd,EACE,QACA,SACA,IACA,UACA,cAIF,eAA2C,YACnC;CACR,IAAI;AACJ,KAAI,eAAe,MACjB,mBAAkB,oBAAoB,OAAO;KAE7C,mBAAkB;AAYpB,QAAO,aADiBC,aAAAA,gBAAU;EANhC,QAAQ;EACR,GAAI,MAAM,EAAE,IAAI;EAChB,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,YAAY,QAAQ,EAAE,UAAU,KAAK,IAAI,SAAS,EAAE;EACxD,GAAI,cAAc,EAAE,YAAY;EAEa,CACZ,CAAC;;;;;;;;;AAsBtC,MAAM,iBAAiB,UAAoC;AACzD,KAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,WAA2B,EAAE;AACnC,MAAI,OAAO,SAAS,MAAM,EACxB,UAAS,IAAI,oBAAoB,MAAM,EAAE;AAE3C,MAAI,OAAO,OAAO;GAChB,MAAM,qBAAqB,OAAO;AAClC,OAAI,oBAAoB,EAItB,UAAS,IAAI,OAAO,YAClB,OAAO,QAAQ,mBAAmB,EAAE,CAAC,KAAK,CAAC,KAAK,WAAW,CACzD,KACA,oBAAoB,MAAqB,CAC1C,CAAC,CACH;AAEH,OAAI,oBAAoB,EACtB,UAAS,IAAI,mBAAmB;;AAGpC,MAAIC,aAAAA,WAAW,MAAM,CACnB,QAAO;GACL,GAAG,MAAM;GACT,GAAI,MAAM,KAAK,EACb,GAAG,MAAM,GACV;GACF;AAEH,SAAO;;AAET,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB;;;;ACzHtC,SAAwB,aACtB,UAGA,eAAe,YACP;AACR,QAAO,aAAaC,aAAAA,gBAAU,SAAS,CAAC"}
package/dist/id.cjs ADDED
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_id = require("./id-VXBgyXu2.cjs");
3
+ exports.hashSource = require_id.hashSource;
4
+ exports.hashString = require_id.hashString;
5
+ exports.hashTemplate = require_id.hashTemplate;
@@ -1,5 +1,6 @@
1
- import { JsxChildren } from '../types';
2
- import { HashMetadata } from './types';
1
+ import { ut as HashMetadata, wt as JsxChildren } from "./types-BJdoI1d1.cjs";
2
+
3
+ //#region src/id/hashSource.d.ts
3
4
  /**
4
5
  * Calculates a unique hash for a given string using sha256.
5
6
  *
@@ -8,7 +9,7 @@ import { HashMetadata } from './types';
8
9
  * @param {string} string - The string to be hashed.
9
10
  * @returns {string} - The resulting hash as a hexadecimal string.
10
11
  */
11
- export declare function hashString(string: string): string;
12
+ declare function hashString(string: string): string;
12
13
  /**
13
14
  * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
14
15
  *
@@ -20,6 +21,20 @@ export declare function hashString(string: string): string;
20
21
  * @param {function} [hashFunction] custom hash function
21
22
  * @returns {string} - The unique has of the children.
22
23
  */
23
- export declare function hashSource({ source, context, id, maxChars, dataFormat, }: {
24
- source: JsxChildren | string;
24
+ declare function hashSource({
25
+ source,
26
+ context,
27
+ id,
28
+ maxChars,
29
+ dataFormat
30
+ }: {
31
+ source: JsxChildren | string;
25
32
  } & HashMetadata, hashFunction?: (string: string) => string): string;
33
+ //#endregion
34
+ //#region src/id/hashTemplate.d.ts
35
+ declare function hashTemplate(template: {
36
+ [key: string]: string;
37
+ }, hashFunction?: typeof hashString): string;
38
+ //#endregion
39
+ export { hashSource, hashString, hashTemplate };
40
+ //# sourceMappingURL=id.d.cts.map
package/dist/id.d.mts ADDED
@@ -0,0 +1,40 @@
1
+ import { ut as HashMetadata, wt as JsxChildren } from "./types-DazaDJbs.mjs";
2
+
3
+ //#region src/id/hashSource.d.ts
4
+ /**
5
+ * Calculates a unique hash for a given string using sha256.
6
+ *
7
+ * First 16 characters of hash, hex encoded.
8
+ *
9
+ * @param {string} string - The string to be hashed.
10
+ * @returns {string} - The resulting hash as a hexadecimal string.
11
+ */
12
+ declare function hashString(string: string): string;
13
+ /**
14
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
15
+ *
16
+ * @param {any} childrenAsObjects - The children objects to be hashed.
17
+ * @param {string} [context] - The context for the children
18
+ * @param {string} [id] - The id for the JSX Children object
19
+ * @param {number} [maxChars] - The maxChars for the JSX Children object
20
+ * @param {string} [dataFormat] - The data format of the sources
21
+ * @param {function} [hashFunction] custom hash function
22
+ * @returns {string} - The unique has of the children.
23
+ */
24
+ declare function hashSource({
25
+ source,
26
+ context,
27
+ id,
28
+ maxChars,
29
+ dataFormat
30
+ }: {
31
+ source: JsxChildren | string;
32
+ } & HashMetadata, hashFunction?: (string: string) => string): string;
33
+ //#endregion
34
+ //#region src/id/hashTemplate.d.ts
35
+ declare function hashTemplate(template: {
36
+ [key: string]: string;
37
+ }, hashFunction?: typeof hashString): string;
38
+ //#endregion
39
+ export { hashSource, hashString, hashTemplate };
40
+ //# sourceMappingURL=id.d.mts.map
package/dist/id.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { n as hashSource, r as hashString, t as hashTemplate } from "./id-CPbVYREY.mjs";
2
+ export { hashSource, hashString, hashTemplate };