@miaixz/sdk 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +412 -0
  4. package/dist/api/client.d.ts +223 -0
  5. package/dist/api/client.d.ts.map +1 -0
  6. package/dist/api/client.js +1069 -0
  7. package/dist/api/client.js.map +1 -0
  8. package/dist/api/endpoint.d.ts +10 -0
  9. package/dist/api/endpoint.d.ts.map +1 -0
  10. package/dist/api/endpoint.js +51 -0
  11. package/dist/api/endpoint.js.map +1 -0
  12. package/dist/api/errors.d.ts +180 -0
  13. package/dist/api/errors.d.ts.map +1 -0
  14. package/dist/api/errors.js +173 -0
  15. package/dist/api/errors.js.map +1 -0
  16. package/dist/api/index.d.ts +6 -0
  17. package/dist/api/index.d.ts.map +1 -0
  18. package/dist/api/index.js +5 -0
  19. package/dist/api/index.js.map +1 -0
  20. package/dist/api/request.d.ts +135 -0
  21. package/dist/api/request.d.ts.map +1 -0
  22. package/dist/api/request.js +2 -0
  23. package/dist/api/request.js.map +1 -0
  24. package/dist/api/response.d.ts +69 -0
  25. package/dist/api/response.d.ts.map +1 -0
  26. package/dist/api/response.js +43 -0
  27. package/dist/api/response.js.map +1 -0
  28. package/dist/api/telemetry.d.ts +139 -0
  29. package/dist/api/telemetry.d.ts.map +1 -0
  30. package/dist/api/telemetry.js +2 -0
  31. package/dist/api/telemetry.js.map +1 -0
  32. package/dist/appearance/appearance.d.ts +161 -0
  33. package/dist/appearance/appearance.d.ts.map +1 -0
  34. package/dist/appearance/appearance.js +614 -0
  35. package/dist/appearance/appearance.js.map +1 -0
  36. package/dist/appearance/index.d.ts +3 -0
  37. package/dist/appearance/index.d.ts.map +1 -0
  38. package/dist/appearance/index.js +3 -0
  39. package/dist/appearance/index.js.map +1 -0
  40. package/dist/auth/auth.d.ts +197 -0
  41. package/dist/auth/auth.d.ts.map +1 -0
  42. package/dist/auth/auth.js +314 -0
  43. package/dist/auth/auth.js.map +1 -0
  44. package/dist/auth/index.d.ts +2 -0
  45. package/dist/auth/index.d.ts.map +1 -0
  46. package/dist/auth/index.js +2 -0
  47. package/dist/auth/index.js.map +1 -0
  48. package/dist/config/config.d.ts +117 -0
  49. package/dist/config/config.d.ts.map +1 -0
  50. package/dist/config/config.js +241 -0
  51. package/dist/config/config.js.map +1 -0
  52. package/dist/config/index.d.ts +2 -0
  53. package/dist/config/index.d.ts.map +1 -0
  54. package/dist/config/index.js +2 -0
  55. package/dist/config/index.js.map +1 -0
  56. package/dist/consts/index.d.ts +35 -0
  57. package/dist/consts/index.d.ts.map +1 -0
  58. package/dist/consts/index.js +35 -0
  59. package/dist/consts/index.js.map +1 -0
  60. package/dist/context/context.d.ts +123 -0
  61. package/dist/context/context.d.ts.map +1 -0
  62. package/dist/context/context.js +252 -0
  63. package/dist/context/context.js.map +1 -0
  64. package/dist/context/index.d.ts +2 -0
  65. package/dist/context/index.d.ts.map +1 -0
  66. package/dist/context/index.js +2 -0
  67. package/dist/context/index.js.map +1 -0
  68. package/dist/contracts/host-context.d.ts +132 -0
  69. package/dist/contracts/host-context.d.ts.map +1 -0
  70. package/dist/contracts/host-context.js +2 -0
  71. package/dist/contracts/host-context.js.map +1 -0
  72. package/dist/contracts/index.d.ts +8 -0
  73. package/dist/contracts/index.d.ts.map +1 -0
  74. package/dist/contracts/index.js +2 -0
  75. package/dist/contracts/index.js.map +1 -0
  76. package/dist/contracts/lifecycle.d.ts +49 -0
  77. package/dist/contracts/lifecycle.d.ts.map +1 -0
  78. package/dist/contracts/lifecycle.js +2 -0
  79. package/dist/contracts/lifecycle.js.map +1 -0
  80. package/dist/contracts/module-manifest.d.ts +110 -0
  81. package/dist/contracts/module-manifest.d.ts.map +1 -0
  82. package/dist/contracts/module-manifest.js +317 -0
  83. package/dist/contracts/module-manifest.js.map +1 -0
  84. package/dist/contracts/navigation.d.ts +36 -0
  85. package/dist/contracts/navigation.d.ts.map +1 -0
  86. package/dist/contracts/navigation.js +11 -0
  87. package/dist/contracts/navigation.js.map +1 -0
  88. package/dist/contracts/permission.d.ts +8 -0
  89. package/dist/contracts/permission.d.ts.map +1 -0
  90. package/dist/contracts/permission.js +14 -0
  91. package/dist/contracts/permission.js.map +1 -0
  92. package/dist/contracts/post-message.d.ts +124 -0
  93. package/dist/contracts/post-message.d.ts.map +1 -0
  94. package/dist/contracts/post-message.js +2 -0
  95. package/dist/contracts/post-message.js.map +1 -0
  96. package/dist/contracts/route.d.ts +45 -0
  97. package/dist/contracts/route.d.ts.map +1 -0
  98. package/dist/contracts/route.js +35 -0
  99. package/dist/contracts/route.js.map +1 -0
  100. package/dist/events/events.d.ts +191 -0
  101. package/dist/events/events.d.ts.map +1 -0
  102. package/dist/events/events.js +486 -0
  103. package/dist/events/events.js.map +1 -0
  104. package/dist/events/index.d.ts +2 -0
  105. package/dist/events/index.d.ts.map +1 -0
  106. package/dist/events/index.js +2 -0
  107. package/dist/events/index.js.map +1 -0
  108. package/dist/files/files.d.ts +138 -0
  109. package/dist/files/files.d.ts.map +1 -0
  110. package/dist/files/files.js +144 -0
  111. package/dist/files/files.js.map +1 -0
  112. package/dist/files/index.d.ts +2 -0
  113. package/dist/files/index.d.ts.map +1 -0
  114. package/dist/files/index.js +2 -0
  115. package/dist/files/index.js.map +1 -0
  116. package/dist/formatters/index.d.ts +44 -0
  117. package/dist/formatters/index.d.ts.map +1 -0
  118. package/dist/formatters/index.js +50 -0
  119. package/dist/formatters/index.js.map +1 -0
  120. package/dist/i18n/default-translator.d.ts +17 -0
  121. package/dist/i18n/default-translator.d.ts.map +1 -0
  122. package/dist/i18n/default-translator.js +19 -0
  123. package/dist/i18n/default-translator.js.map +1 -0
  124. package/dist/i18n/i18n.d.ts +248 -0
  125. package/dist/i18n/i18n.d.ts.map +1 -0
  126. package/dist/i18n/i18n.js +617 -0
  127. package/dist/i18n/i18n.js.map +1 -0
  128. package/dist/i18n/index.d.ts +2 -0
  129. package/dist/i18n/index.d.ts.map +1 -0
  130. package/dist/i18n/index.js +2 -0
  131. package/dist/i18n/index.js.map +1 -0
  132. package/dist/index.d.ts +19 -0
  133. package/dist/index.d.ts.map +1 -0
  134. package/dist/index.js +19 -0
  135. package/dist/index.js.map +1 -0
  136. package/dist/models/index.d.ts +2 -0
  137. package/dist/models/index.d.ts.map +1 -0
  138. package/dist/models/index.js +2 -0
  139. package/dist/models/index.js.map +1 -0
  140. package/dist/permissions/index.d.ts +2 -0
  141. package/dist/permissions/index.d.ts.map +1 -0
  142. package/dist/permissions/index.js +2 -0
  143. package/dist/permissions/index.js.map +1 -0
  144. package/dist/permissions/permissions.d.ts +67 -0
  145. package/dist/permissions/permissions.d.ts.map +1 -0
  146. package/dist/permissions/permissions.js +123 -0
  147. package/dist/permissions/permissions.js.map +1 -0
  148. package/dist/runtime/direct-host-bridge.d.ts +11 -0
  149. package/dist/runtime/direct-host-bridge.d.ts.map +1 -0
  150. package/dist/runtime/direct-host-bridge.js +299 -0
  151. package/dist/runtime/direct-host-bridge.js.map +1 -0
  152. package/dist/runtime/index.d.ts +5 -0
  153. package/dist/runtime/index.d.ts.map +1 -0
  154. package/dist/runtime/index.js +3 -0
  155. package/dist/runtime/index.js.map +1 -0
  156. package/dist/runtime/post-message-bridge.d.ts +20 -0
  157. package/dist/runtime/post-message-bridge.d.ts.map +1 -0
  158. package/dist/runtime/post-message-bridge.js +1115 -0
  159. package/dist/runtime/post-message-bridge.js.map +1 -0
  160. package/dist/sdk.d.ts +177 -0
  161. package/dist/sdk.d.ts.map +1 -0
  162. package/dist/sdk.js +214 -0
  163. package/dist/sdk.js.map +1 -0
  164. package/dist/storage/index.d.ts +2 -0
  165. package/dist/storage/index.d.ts.map +1 -0
  166. package/dist/storage/index.js +2 -0
  167. package/dist/storage/index.js.map +1 -0
  168. package/dist/storage/storage.d.ts +246 -0
  169. package/dist/storage/storage.d.ts.map +1 -0
  170. package/dist/storage/storage.js +358 -0
  171. package/dist/storage/storage.js.map +1 -0
  172. package/dist/types/api.d.ts +82 -0
  173. package/dist/types/api.d.ts.map +1 -0
  174. package/dist/types/api.js +2 -0
  175. package/dist/types/api.js.map +1 -0
  176. package/dist/types/appearance.d.ts +85 -0
  177. package/dist/types/appearance.d.ts.map +1 -0
  178. package/dist/types/appearance.js +48 -0
  179. package/dist/types/appearance.js.map +1 -0
  180. package/dist/types/config.d.ts +49 -0
  181. package/dist/types/config.d.ts.map +1 -0
  182. package/dist/types/config.js +2 -0
  183. package/dist/types/config.js.map +1 -0
  184. package/dist/types/context.d.ts +41 -0
  185. package/dist/types/context.d.ts.map +1 -0
  186. package/dist/types/context.js +2 -0
  187. package/dist/types/context.js.map +1 -0
  188. package/dist/types/file.d.ts +48 -0
  189. package/dist/types/file.d.ts.map +1 -0
  190. package/dist/types/file.js +2 -0
  191. package/dist/types/file.js.map +1 -0
  192. package/dist/types/index.d.ts +12 -0
  193. package/dist/types/index.d.ts.map +1 -0
  194. package/dist/types/index.js +12 -0
  195. package/dist/types/index.js.map +1 -0
  196. package/dist/types/organization.d.ts +56 -0
  197. package/dist/types/organization.d.ts.map +1 -0
  198. package/dist/types/organization.js +2 -0
  199. package/dist/types/organization.js.map +1 -0
  200. package/dist/types/pagination.d.ts +55 -0
  201. package/dist/types/pagination.d.ts.map +1 -0
  202. package/dist/types/pagination.js +13 -0
  203. package/dist/types/pagination.js.map +1 -0
  204. package/dist/types/permissions.d.ts +26 -0
  205. package/dist/types/permissions.d.ts.map +1 -0
  206. package/dist/types/permissions.js +2 -0
  207. package/dist/types/permissions.js.map +1 -0
  208. package/dist/types/space.d.ts +43 -0
  209. package/dist/types/space.d.ts.map +1 -0
  210. package/dist/types/space.js +2 -0
  211. package/dist/types/space.js.map +1 -0
  212. package/dist/types/tenant.d.ts +31 -0
  213. package/dist/types/tenant.d.ts.map +1 -0
  214. package/dist/types/tenant.js +2 -0
  215. package/dist/types/tenant.js.map +1 -0
  216. package/dist/types/user.d.ts +48 -0
  217. package/dist/types/user.d.ts.map +1 -0
  218. package/dist/types/user.js +2 -0
  219. package/dist/types/user.js.map +1 -0
  220. package/dist/utils/date.d.ts +9 -0
  221. package/dist/utils/date.d.ts.map +1 -0
  222. package/dist/utils/date.js +11 -0
  223. package/dist/utils/date.js.map +1 -0
  224. package/dist/utils/index.d.ts +5 -0
  225. package/dist/utils/index.d.ts.map +1 -0
  226. package/dist/utils/index.js +5 -0
  227. package/dist/utils/index.js.map +1 -0
  228. package/dist/utils/number.d.ts +11 -0
  229. package/dist/utils/number.d.ts.map +1 -0
  230. package/dist/utils/number.js +13 -0
  231. package/dist/utils/number.js.map +1 -0
  232. package/dist/utils/object.d.ts +9 -0
  233. package/dist/utils/object.d.ts.map +1 -0
  234. package/dist/utils/object.js +11 -0
  235. package/dist/utils/object.js.map +1 -0
  236. package/dist/utils/string.d.ts +9 -0
  237. package/dist/utils/string.d.ts.map +1 -0
  238. package/dist/utils/string.js +11 -0
  239. package/dist/utils/string.js.map +1 -0
  240. package/dist/validators/index.d.ts +8 -0
  241. package/dist/validators/index.d.ts.map +1 -0
  242. package/dist/validators/index.js +8 -0
  243. package/dist/validators/index.js.map +1 -0
  244. package/package.json +156 -0
@@ -0,0 +1,138 @@
1
+ import type { MiaixzApiClient } from "../api/index.js";
2
+ import { type MiaixzTranslator } from "../i18n/index.js";
3
+ import type { MiaixzFileDescriptor, MiaixzUploadResult } from "../types/index.js";
4
+ /**
5
+ * Configures a multipart file upload.
6
+ *
7
+ * @public
8
+ */
9
+ export interface MiaixzUploadOptions {
10
+ /**
11
+ * Optional multipart field name used for uploaded files.
12
+ */
13
+ fieldName?: string;
14
+ /**
15
+ * Optional scalar metadata appended to the multipart body.
16
+ */
17
+ metadata?: Readonly<Record<string, string | number | boolean>>;
18
+ /**
19
+ * Optional signal used to cancel the upload.
20
+ */
21
+ signal?: AbortSignal;
22
+ /**
23
+ * Optional request-specific HTTP headers.
24
+ */
25
+ headers?: HeadersInit;
26
+ }
27
+ /**
28
+ * Configures a file download.
29
+ *
30
+ * @public
31
+ */
32
+ export interface MiaixzDownloadOptions {
33
+ /**
34
+ * Optional signal used to cancel the download.
35
+ */
36
+ signal?: AbortSignal;
37
+ /**
38
+ * Optional request-specific HTTP headers.
39
+ */
40
+ headers?: HeadersInit;
41
+ /**
42
+ * Optional filename that overrides response metadata.
43
+ */
44
+ filename?: string;
45
+ }
46
+ /**
47
+ * Describes a file downloaded into memory.
48
+ *
49
+ * @public
50
+ */
51
+ export interface MiaixzDownloadedFile {
52
+ /**
53
+ * Downloaded binary content.
54
+ */
55
+ blob: Blob;
56
+ /**
57
+ * Optional decoded or caller-provided filename.
58
+ */
59
+ filename?: string;
60
+ /**
61
+ * Optional media type returned by the server.
62
+ */
63
+ contentType?: string;
64
+ }
65
+ /**
66
+ * Configures a high-level Miaixz file client.
67
+ *
68
+ * @public
69
+ */
70
+ export interface MiaixzFileClientOptions {
71
+ /**
72
+ * Optional translator used for file-operation errors.
73
+ */
74
+ translate?: MiaixzTranslator;
75
+ }
76
+ /**
77
+ * Extracts and decodes a filename from an HTTP Content-Disposition header.
78
+ *
79
+ * @param headers - Response headers to inspect.
80
+ * @returns Decoded filename when one is present.
81
+ * @public
82
+ */
83
+ export declare function getMiaixzDownloadFilename(headers: Headers): string | undefined;
84
+ /**
85
+ * High-level file upload and download operations built on a Miaixz API client.
86
+ *
87
+ * @public
88
+ */
89
+ export declare class MiaixzFileClient {
90
+ #private;
91
+ /**
92
+ * Configured API client used for file requests.
93
+ */
94
+ readonly api: MiaixzApiClient;
95
+ /**
96
+ * Creates a high-level file client.
97
+ *
98
+ * @param api - Configured API client.
99
+ * @param options - File-specific adapters.
100
+ */
101
+ constructor(api: MiaixzApiClient, options?: MiaixzFileClientOptions);
102
+ /**
103
+ * Uploads one or more files as multipart form data.
104
+ *
105
+ * @param path - API path that accepts the upload.
106
+ * @param files - Single blob or immutable blob collection to upload.
107
+ * @param options - Optional multipart metadata and request controls.
108
+ * @returns The backend's unwrapped upload result.
109
+ */
110
+ upload<TFile extends MiaixzFileDescriptor = MiaixzFileDescriptor>(path: string, files: Blob | readonly Blob[], options?: MiaixzUploadOptions): Promise<MiaixzUploadResult<TFile>>;
111
+ /**
112
+ * Downloads a binary response and derives its filename and content type.
113
+ *
114
+ * @param path - API path of the file to download.
115
+ * @param options - Optional filename and request controls.
116
+ * @returns Downloaded binary content and response metadata.
117
+ */
118
+ download(path: string, options?: MiaixzDownloadOptions): Promise<MiaixzDownloadedFile>;
119
+ }
120
+ /**
121
+ * Creates a high-level file client around an existing API client.
122
+ *
123
+ * @param api - Configured API client used for file requests.
124
+ * @param options - Optional file-client adapters.
125
+ * @returns Configured high-level file client.
126
+ * @public
127
+ */
128
+ export declare function createMiaixzFileClient(api: MiaixzApiClient, options?: MiaixzFileClientOptions): MiaixzFileClient;
129
+ /**
130
+ * Triggers a browser download for an in-memory blob; no-ops during SSR.
131
+ *
132
+ * @param blob - Binary content to download.
133
+ * @param filename - Filename presented to the browser.
134
+ * @param targetDocument - Optional document used to create the download link.
135
+ * @public
136
+ */
137
+ export declare function saveMiaixzBlob(blob: Blob, filename: string, targetDocument?: Document | undefined): void;
138
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/files/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAElF;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAE/D;;OAEG;I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AAG,EAAE,eAAe,EACpB,OAAO,CAAC,EAAE,uBAAuB,GAChC,gBAAgB,CAElB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,cAAc,GAAE,QAAQ,GAAG,SAAkE,GAC5F,IAAI,CAWN"}
@@ -0,0 +1,144 @@
1
+ import { MiaixzSdkError, isMiaixzSdkError } from "../api/errors.js";
2
+ import { miaixzDefaultI18n } from "../i18n/index.js";
3
+ /**
4
+ * Normalizes a single upload blob to the multi-file representation.
5
+ *
6
+ * @param files - Single blob or immutable blob collection.
7
+ * @returns Immutable blob collection.
8
+ */
9
+ function normalizeFiles(files) {
10
+ return files instanceof Blob ? [files] : files;
11
+ }
12
+ /**
13
+ * Extracts and decodes a filename from an HTTP Content-Disposition header.
14
+ *
15
+ * @param headers - Response headers to inspect.
16
+ * @returns Decoded filename when one is present.
17
+ * @public
18
+ */
19
+ export function getMiaixzDownloadFilename(headers) {
20
+ const disposition = headers.get("content-disposition");
21
+ if (!disposition)
22
+ return undefined;
23
+ const encoded = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
24
+ if (encoded) {
25
+ try {
26
+ return decodeURIComponent(encoded.replace(/^"|"$/g, ""));
27
+ }
28
+ catch {
29
+ return encoded;
30
+ }
31
+ }
32
+ return disposition.match(/filename="?([^";]+)"?/i)?.[1]?.trim();
33
+ }
34
+ /**
35
+ * High-level file upload and download operations built on a Miaixz API client.
36
+ *
37
+ * @public
38
+ */
39
+ export class MiaixzFileClient {
40
+ #translate;
41
+ /**
42
+ * Configured API client used for file requests.
43
+ */
44
+ api;
45
+ /**
46
+ * Creates a high-level file client.
47
+ *
48
+ * @param api - Configured API client.
49
+ * @param options - File-specific adapters.
50
+ */
51
+ constructor(api, options = {}) {
52
+ this.api = api;
53
+ this.#translate = options.translate ?? miaixzDefaultI18n.t;
54
+ }
55
+ /**
56
+ * Uploads one or more files as multipart form data.
57
+ *
58
+ * @param path - API path that accepts the upload.
59
+ * @param files - Single blob or immutable blob collection to upload.
60
+ * @param options - Optional multipart metadata and request controls.
61
+ * @returns The backend's unwrapped upload result.
62
+ */
63
+ async upload(path, files, options = {}) {
64
+ const formData = new FormData();
65
+ const fieldName = options.fieldName ?? "files";
66
+ for (const file of normalizeFiles(files)) {
67
+ const filename = typeof File !== "undefined" && file instanceof File ? file.name : "file";
68
+ formData.append(fieldName, file, filename);
69
+ }
70
+ for (const [key, value] of Object.entries(options.metadata ?? {})) {
71
+ formData.append(key, String(value));
72
+ }
73
+ const response = await this.api.post(path, formData, {
74
+ responseType: "json",
75
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
76
+ ...(options.headers === undefined ? {} : { headers: options.headers }),
77
+ });
78
+ return response.data;
79
+ }
80
+ /**
81
+ * Downloads a binary response and derives its filename and content type.
82
+ *
83
+ * @param path - API path of the file to download.
84
+ * @param options - Optional filename and request controls.
85
+ * @returns Downloaded binary content and response metadata.
86
+ */
87
+ async download(path, options = {}) {
88
+ try {
89
+ const response = await this.api.get(path, {
90
+ responseType: "blob",
91
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
92
+ ...(options.headers === undefined ? {} : { headers: options.headers }),
93
+ });
94
+ const filename = options.filename ?? getMiaixzDownloadFilename(response.headers);
95
+ const contentType = response.headers.get("content-type") ?? undefined;
96
+ return {
97
+ blob: response.data,
98
+ ...(filename === undefined ? {} : { filename }),
99
+ ...(contentType === undefined ? {} : { contentType }),
100
+ };
101
+ }
102
+ catch (cause) {
103
+ if (isMiaixzSdkError(cause))
104
+ throw cause;
105
+ throw new MiaixzSdkError(this.#translate("sdk.error.file.download"), {
106
+ code: "FILE_DOWNLOAD_FAILED",
107
+ cause,
108
+ });
109
+ }
110
+ }
111
+ }
112
+ /**
113
+ * Creates a high-level file client around an existing API client.
114
+ *
115
+ * @param api - Configured API client used for file requests.
116
+ * @param options - Optional file-client adapters.
117
+ * @returns Configured high-level file client.
118
+ * @public
119
+ */
120
+ export function createMiaixzFileClient(api, options) {
121
+ return new MiaixzFileClient(api, options);
122
+ }
123
+ /**
124
+ * Triggers a browser download for an in-memory blob; no-ops during SSR.
125
+ *
126
+ * @param blob - Binary content to download.
127
+ * @param filename - Filename presented to the browser.
128
+ * @param targetDocument - Optional document used to create the download link.
129
+ * @public
130
+ */
131
+ export function saveMiaixzBlob(blob, filename, targetDocument = typeof document === "undefined" ? undefined : document) {
132
+ if (!targetDocument || typeof URL === "undefined")
133
+ return;
134
+ const url = URL.createObjectURL(blob);
135
+ const anchor = targetDocument.createElement("a");
136
+ anchor.href = url;
137
+ anchor.download = filename;
138
+ anchor.hidden = true;
139
+ targetDocument.body.append(anchor);
140
+ anchor.click();
141
+ anchor.remove();
142
+ setTimeout(() => URL.revokeObjectURL(url), 0);
143
+ }
144
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/files/files.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAyB,MAAM,kBAAkB,CAAC;AAsF5E;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAA6B;IACnD,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACvD,IAAI,CAAC,WAAW;QAAE,OAAO,SAAS,CAAC;IACnC,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,4BAA4B,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,OAAO,kBAAkB,CAAC,OAAO,CAAC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B,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { MiaixzApiClient } from \"../api/index.js\";\nimport { MiaixzSdkError, isMiaixzSdkError } from \"../api/errors.js\";\nimport { miaixzDefaultI18n, type MiaixzTranslator } from \"../i18n/index.js\";\nimport type { MiaixzFileDescriptor, MiaixzUploadResult } from \"../types/index.js\";\n\n/**\n * Configures a multipart file upload.\n *\n * @public\n */\nexport interface MiaixzUploadOptions {\n /**\n * Optional multipart field name used for uploaded files.\n */\n fieldName?: string;\n\n /**\n * Optional scalar metadata appended to the multipart body.\n */\n metadata?: Readonly<Record<string, string | number | boolean>>;\n\n /**\n * Optional signal used to cancel the upload.\n */\n signal?: AbortSignal;\n\n /**\n * Optional request-specific HTTP headers.\n */\n headers?: HeadersInit;\n}\n\n/**\n * Configures a file download.\n *\n * @public\n */\nexport interface MiaixzDownloadOptions {\n /**\n * Optional signal used to cancel the download.\n */\n signal?: AbortSignal;\n\n /**\n * Optional request-specific HTTP headers.\n */\n headers?: HeadersInit;\n\n /**\n * Optional filename that overrides response metadata.\n */\n filename?: string;\n}\n\n/**\n * Describes a file downloaded into memory.\n *\n * @public\n */\nexport interface MiaixzDownloadedFile {\n /**\n * Downloaded binary content.\n */\n blob: Blob;\n\n /**\n * Optional decoded or caller-provided filename.\n */\n filename?: string;\n\n /**\n * Optional media type returned by the server.\n */\n contentType?: string;\n}\n\n/**\n * Configures a high-level Miaixz file client.\n *\n * @public\n */\nexport interface MiaixzFileClientOptions {\n /**\n * Optional translator used for file-operation errors.\n */\n translate?: MiaixzTranslator;\n}\n\n/**\n * Normalizes a single upload blob to the multi-file representation.\n *\n * @param files - Single blob or immutable blob collection.\n * @returns Immutable blob collection.\n */\nfunction normalizeFiles(files: Blob | readonly Blob[]): readonly Blob[] {\n return files instanceof Blob ? [files] : files;\n}\n\n/**\n * Extracts and decodes a filename from an HTTP Content-Disposition header.\n *\n * @param headers - Response headers to inspect.\n * @returns Decoded filename when one is present.\n * @public\n */\nexport function getMiaixzDownloadFilename(headers: Headers): string | undefined {\n const disposition = headers.get(\"content-disposition\");\n if (!disposition) return undefined;\n const encoded = disposition.match(/filename\\*=UTF-8''([^;]+)/i)?.[1];\n if (encoded) {\n try {\n return decodeURIComponent(encoded.replace(/^\"|\"$/g, \"\"));\n } catch {\n return encoded;\n }\n }\n return disposition.match(/filename=\"?([^\";]+)\"?/i)?.[1]?.trim();\n}\n\n/**\n * High-level file upload and download operations built on a Miaixz API client.\n *\n * @public\n */\nexport class MiaixzFileClient {\n readonly #translate: MiaixzTranslator;\n\n /**\n * Configured API client used for file requests.\n */\n readonly api: MiaixzApiClient;\n\n /**\n * Creates a high-level file client.\n *\n * @param api - Configured API client.\n * @param options - File-specific adapters.\n */\n constructor(api: MiaixzApiClient, options: MiaixzFileClientOptions = {}) {\n this.api = api;\n this.#translate = options.translate ?? miaixzDefaultI18n.t;\n }\n\n /**\n * Uploads one or more files as multipart form data.\n *\n * @param path - API path that accepts the upload.\n * @param files - Single blob or immutable blob collection to upload.\n * @param options - Optional multipart metadata and request controls.\n * @returns The backend's unwrapped upload result.\n */\n async upload<TFile extends MiaixzFileDescriptor = MiaixzFileDescriptor>(\n path: string,\n files: Blob | readonly Blob[],\n options: MiaixzUploadOptions = {},\n ): Promise<MiaixzUploadResult<TFile>> {\n const formData = new FormData();\n const fieldName = options.fieldName ?? \"files\";\n for (const file of normalizeFiles(files)) {\n const filename = typeof File !== \"undefined\" && file instanceof File ? file.name : \"file\";\n formData.append(fieldName, file, filename);\n }\n for (const [key, value] of Object.entries(options.metadata ?? {})) {\n formData.append(key, String(value));\n }\n const response = await this.api.post<MiaixzUploadResult<TFile>, FormData>(path, formData, {\n responseType: \"json\",\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n ...(options.headers === undefined ? {} : { headers: options.headers }),\n });\n return response.data;\n }\n\n /**\n * Downloads a binary response and derives its filename and content type.\n *\n * @param path - API path of the file to download.\n * @param options - Optional filename and request controls.\n * @returns Downloaded binary content and response metadata.\n */\n async download(path: string, options: MiaixzDownloadOptions = {}): Promise<MiaixzDownloadedFile> {\n try {\n const response = await this.api.get<Blob>(path, {\n responseType: \"blob\",\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n ...(options.headers === undefined ? {} : { headers: options.headers }),\n });\n const filename = options.filename ?? getMiaixzDownloadFilename(response.headers);\n const contentType = response.headers.get(\"content-type\") ?? undefined;\n return {\n blob: response.data,\n ...(filename === undefined ? {} : { filename }),\n ...(contentType === undefined ? {} : { contentType }),\n };\n } catch (cause) {\n if (isMiaixzSdkError(cause)) throw cause;\n throw new MiaixzSdkError(this.#translate(\"sdk.error.file.download\"), {\n code: \"FILE_DOWNLOAD_FAILED\",\n cause,\n });\n }\n }\n}\n\n/**\n * Creates a high-level file client around an existing API client.\n *\n * @param api - Configured API client used for file requests.\n * @param options - Optional file-client adapters.\n * @returns Configured high-level file client.\n * @public\n */\nexport function createMiaixzFileClient(\n api: MiaixzApiClient,\n options?: MiaixzFileClientOptions,\n): MiaixzFileClient {\n return new MiaixzFileClient(api, options);\n}\n\n/**\n * Triggers a browser download for an in-memory blob; no-ops during SSR.\n *\n * @param blob - Binary content to download.\n * @param filename - Filename presented to the browser.\n * @param targetDocument - Optional document used to create the download link.\n * @public\n */\nexport function saveMiaixzBlob(\n blob: Blob,\n filename: string,\n targetDocument: Document | undefined = typeof document === \"undefined\" ? undefined : document,\n): void {\n if (!targetDocument || typeof URL === \"undefined\") return;\n const url = URL.createObjectURL(blob);\n const anchor = targetDocument.createElement(\"a\");\n anchor.href = url;\n anchor.download = filename;\n anchor.hidden = true;\n targetDocument.body.append(anchor);\n anchor.click();\n anchor.remove();\n setTimeout(() => URL.revokeObjectURL(url), 0);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./files.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./files.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./files.js\";\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Configures locale-aware Miaixz formatters.
3
+ *
4
+ * @public
5
+ */
6
+ export interface MiaixzFormatOptions {
7
+ /**
8
+ * Optional BCP 47 locale used by the platform formatter.
9
+ */
10
+ locale?: string;
11
+ }
12
+ /**
13
+ * Formats a date with the platform Intl implementation.
14
+ *
15
+ * @param value - Date-compatible value to format.
16
+ * @param options - Locale and date-time formatting options.
17
+ * @returns An empty string for invalid dates.
18
+ * @public
19
+ */
20
+ export declare function formatMiaixzDate(value: Date | string | number, options?: MiaixzFormatOptions & Intl.DateTimeFormatOptions): string;
21
+ /**
22
+ * Formats a numeric value using locale-aware Intl options.
23
+ *
24
+ * @param value - Numeric value to format.
25
+ * @param options - Locale and number formatting options.
26
+ * @returns Locale-aware numeric text.
27
+ * @public
28
+ */
29
+ export declare function formatMiaixzNumber(value: number, options?: MiaixzFormatOptions & Intl.NumberFormatOptions): string;
30
+ /**
31
+ * Formats a byte count with a compact binary unit and localized number.
32
+ *
33
+ * @param bytes - Byte count to format.
34
+ * @param options - Locale and fraction-digit options.
35
+ * @returns Localized byte count or an empty string for non-finite input.
36
+ * @public
37
+ */
38
+ export declare function formatMiaixzBytes(bytes: number, options?: MiaixzFormatOptions & {
39
+ /**
40
+ * Optional maximum number of fractional digits to display.
41
+ */
42
+ maximumFractionDigits?: number;
43
+ }): string;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC7B,OAAO,GAAE,mBAAmB,GAAG,IAAI,CAAC,qBAA0B,GAC7D,MAAM,CAKR;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,mBAAmB,GAAG,IAAI,CAAC,mBAAwB,GAC3D,MAAM,CAGR;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,mBAAmB,GAAG;IAC7B;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC3B,GACL,MAAM,CAaR"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Formats a date with the platform Intl implementation.
3
+ *
4
+ * @param value - Date-compatible value to format.
5
+ * @param options - Locale and date-time formatting options.
6
+ * @returns An empty string for invalid dates.
7
+ * @public
8
+ */
9
+ export function formatMiaixzDate(value, options = {}) {
10
+ const { locale, ...formatOptions } = options;
11
+ const date = value instanceof Date ? value : new Date(value);
12
+ if (Number.isNaN(date.getTime()))
13
+ return "";
14
+ return new Intl.DateTimeFormat(locale, formatOptions).format(date);
15
+ }
16
+ /**
17
+ * Formats a numeric value using locale-aware Intl options.
18
+ *
19
+ * @param value - Numeric value to format.
20
+ * @param options - Locale and number formatting options.
21
+ * @returns Locale-aware numeric text.
22
+ * @public
23
+ */
24
+ export function formatMiaixzNumber(value, options = {}) {
25
+ const { locale, ...formatOptions } = options;
26
+ return new Intl.NumberFormat(locale, formatOptions).format(value);
27
+ }
28
+ /**
29
+ * Formats a byte count with a compact binary unit and localized number.
30
+ *
31
+ * @param bytes - Byte count to format.
32
+ * @param options - Locale and fraction-digit options.
33
+ * @returns Localized byte count or an empty string for non-finite input.
34
+ * @public
35
+ */
36
+ export function formatMiaixzBytes(bytes, options = {}) {
37
+ if (!Number.isFinite(bytes))
38
+ return "";
39
+ const units = ["B", "KB", "MB", "GB", "TB", "PB"];
40
+ const absolute = Math.abs(bytes);
41
+ const index = absolute === 0
42
+ ? 0
43
+ : Math.min(Math.floor(Math.log(absolute) / Math.log(1024)), units.length - 1);
44
+ const value = bytes / 1024 ** index;
45
+ return `${formatMiaixzNumber(value, {
46
+ ...(options.locale === undefined ? {} : { locale: options.locale }),
47
+ maximumFractionDigits: options.maximumFractionDigits ?? 1,
48
+ })} ${units[index]}`;
49
+ }
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAA6B,EAC7B,OAAO,GAAqD,EAAE;IAE9D,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAC7C,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5C,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAa,EACb,OAAO,GAAmD,EAAE;IAE5D,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAC7C,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,OAAO,GAKH,EAAE;IAEN,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAC;IAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,KAAK,GACT,QAAQ,KAAK,CAAC;QACZ,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClF,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,IAAI,KAAK,CAAC;IACpC,OAAO,GAAG,kBAAkB,CAAC,KAAK,EAAE;QAClC,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,qBAAqB,EAAE,OAAO,CAAC,qBAAqB,IAAI,CAAC;KAC1D,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Configures locale-aware Miaixz formatters.\n *\n * @public\n */\nexport interface MiaixzFormatOptions {\n /**\n * Optional BCP 47 locale used by the platform formatter.\n */\n locale?: string;\n}\n\n/**\n * Formats a date with the platform Intl implementation.\n *\n * @param value - Date-compatible value to format.\n * @param options - Locale and date-time formatting options.\n * @returns An empty string for invalid dates.\n * @public\n */\nexport function formatMiaixzDate(\n value: Date | string | number,\n options: MiaixzFormatOptions & Intl.DateTimeFormatOptions = {},\n): string {\n const { locale, ...formatOptions } = options;\n const date = value instanceof Date ? value : new Date(value);\n if (Number.isNaN(date.getTime())) return \"\";\n return new Intl.DateTimeFormat(locale, formatOptions).format(date);\n}\n\n/**\n * Formats a numeric value using locale-aware Intl options.\n *\n * @param value - Numeric value to format.\n * @param options - Locale and number formatting options.\n * @returns Locale-aware numeric text.\n * @public\n */\nexport function formatMiaixzNumber(\n value: number,\n options: MiaixzFormatOptions & Intl.NumberFormatOptions = {},\n): string {\n const { locale, ...formatOptions } = options;\n return new Intl.NumberFormat(locale, formatOptions).format(value);\n}\n\n/**\n * Formats a byte count with a compact binary unit and localized number.\n *\n * @param bytes - Byte count to format.\n * @param options - Locale and fraction-digit options.\n * @returns Localized byte count or an empty string for non-finite input.\n * @public\n */\nexport function formatMiaixzBytes(\n bytes: number,\n options: MiaixzFormatOptions & {\n /**\n * Optional maximum number of fractional digits to display.\n */\n maximumFractionDigits?: number;\n } = {},\n): string {\n if (!Number.isFinite(bytes)) return \"\";\n const units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\"] as const;\n const absolute = Math.abs(bytes);\n const index =\n absolute === 0\n ? 0\n : Math.min(Math.floor(Math.log(absolute) / Math.log(1024)), units.length - 1);\n const value = bytes / 1024 ** index;\n return `${formatMiaixzNumber(value, {\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n maximumFractionDigits: options.maximumFractionDigits ?? 1,\n })} ${units[index]}`;\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { MiaixzTranslator } from "./i18n.js";
2
+ /**
3
+ * Resolves a default SDK message without creating a runtime import cycle.
4
+ *
5
+ * @param key - Translation key to resolve.
6
+ * @param params - Optional interpolation values.
7
+ * @param fallback - Optional explicit fallback text.
8
+ * @returns Message resolved by the currently registered default runtime.
9
+ */
10
+ export declare const translateMiaixzDefaultMessage: MiaixzTranslator;
11
+ /**
12
+ * Registers the translator owned by the fully initialized default runtime.
13
+ *
14
+ * @param translator - Default SDK runtime translator.
15
+ */
16
+ export declare function setMiaixzDefaultTranslator(translator: MiaixzTranslator): void;
17
+ //# sourceMappingURL=default-translator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-translator.d.ts","sourceRoot":"","sources":["../../src/i18n/default-translator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAIlD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,EAAE,gBACH,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAE7E"}
@@ -0,0 +1,19 @@
1
+ let activeTranslator = (key, _params, fallback) => fallback ?? key;
2
+ /**
3
+ * Resolves a default SDK message without creating a runtime import cycle.
4
+ *
5
+ * @param key - Translation key to resolve.
6
+ * @param params - Optional interpolation values.
7
+ * @param fallback - Optional explicit fallback text.
8
+ * @returns Message resolved by the currently registered default runtime.
9
+ */
10
+ export const translateMiaixzDefaultMessage = (key, params, fallback) => activeTranslator(key, params, fallback);
11
+ /**
12
+ * Registers the translator owned by the fully initialized default runtime.
13
+ *
14
+ * @param translator - Default SDK runtime translator.
15
+ */
16
+ export function setMiaixzDefaultTranslator(translator) {
17
+ activeTranslator = translator;
18
+ }
19
+ //# sourceMappingURL=default-translator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-translator.js","sourceRoot":"","sources":["../../src/i18n/default-translator.ts"],"names":[],"mappings":"AAEA,IAAI,gBAAgB,GAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,GAAG,CAAC;AAErF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CACvF,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAA4B;IACrE,gBAAgB,GAAG,UAAU,CAAC;AAChC,CAAC","sourcesContent":["import type { MiaixzTranslator } from \"./i18n.js\";\n\nlet activeTranslator: MiaixzTranslator = (key, _params, fallback) => fallback ?? key;\n\n/**\n * Resolves a default SDK message without creating a runtime import cycle.\n *\n * @param key - Translation key to resolve.\n * @param params - Optional interpolation values.\n * @param fallback - Optional explicit fallback text.\n * @returns Message resolved by the currently registered default runtime.\n */\nexport const translateMiaixzDefaultMessage: MiaixzTranslator = (key, params, fallback) =>\n activeTranslator(key, params, fallback);\n\n/**\n * Registers the translator owned by the fully initialized default runtime.\n *\n * @param translator - Default SDK runtime translator.\n */\nexport function setMiaixzDefaultTranslator(translator: MiaixzTranslator): void {\n activeTranslator = translator;\n}\n"]}