@puzzle-ui/media 0.0.0-stage → 0.17.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 (55) hide show
  1. package/README.md +305 -2
  2. package/ai/instructions.md +70 -0
  3. package/ai/manifest.json +10 -0
  4. package/dist/LICENSE +21 -0
  5. package/dist/adapters-Bon320yF.js +481 -0
  6. package/dist/adapters-Bon320yF.js.map +1 -0
  7. package/dist/adapters-C4N2gqSK.d.cts +63 -0
  8. package/dist/adapters-DXycRsjJ.cjs +492 -0
  9. package/dist/adapters-DXycRsjJ.cjs.map +1 -0
  10. package/dist/adapters-DhPviL_C.d.ts +63 -0
  11. package/dist/browser/index.cjs +200 -0
  12. package/dist/browser/index.cjs.map +1 -0
  13. package/dist/browser/index.d.cts +89 -0
  14. package/dist/browser/index.d.ts +89 -0
  15. package/dist/browser/index.js +195 -0
  16. package/dist/browser/index.js.map +1 -0
  17. package/dist/image-processing-B1lRPpsg.cjs +444 -0
  18. package/dist/image-processing-B1lRPpsg.cjs.map +1 -0
  19. package/dist/image-processing-XkoQ8NT7.js +400 -0
  20. package/dist/image-processing-XkoQ8NT7.js.map +1 -0
  21. package/dist/image-worker.cjs +36 -0
  22. package/dist/image-worker.cjs.map +1 -0
  23. package/dist/image-worker.d.cts +1 -0
  24. package/dist/image-worker.d.ts +1 -0
  25. package/dist/image-worker.js +37 -0
  26. package/dist/image-worker.js.map +1 -0
  27. package/dist/index-8Seqy-LJ.d.ts +297 -0
  28. package/dist/index-BP0ikbAS.d.cts +297 -0
  29. package/dist/index.cjs +38 -0
  30. package/dist/index.d.cts +4 -0
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.js +3 -0
  33. package/dist/media-validation-By6karZu.cjs +361 -0
  34. package/dist/media-validation-By6karZu.cjs.map +1 -0
  35. package/dist/media-validation-OyjGVUq3.js +230 -0
  36. package/dist/media-validation-OyjGVUq3.js.map +1 -0
  37. package/dist/media.types-dzfu0Nep.d.cts +127 -0
  38. package/dist/media.types-dzfu0Nep.d.ts +127 -0
  39. package/dist/processing.types-CPaSB88L.d.ts +238 -0
  40. package/dist/processing.types-Dd2XT8Qr.d.cts +238 -0
  41. package/dist/src-8d6s1iWH.js +1286 -0
  42. package/dist/src-8d6s1iWH.js.map +1 -0
  43. package/dist/src-C7WU7ovP.cjs +1363 -0
  44. package/dist/src-C7WU7ovP.cjs.map +1 -0
  45. package/dist/testing/adapters.cjs +4 -0
  46. package/dist/testing/adapters.d.cts +2 -0
  47. package/dist/testing/adapters.d.ts +2 -0
  48. package/dist/testing/adapters.js +1 -0
  49. package/dist/testing/index.cjs +264 -0
  50. package/dist/testing/index.cjs.map +1 -0
  51. package/dist/testing/index.d.cts +14 -0
  52. package/dist/testing/index.d.ts +14 -0
  53. package/dist/testing/index.js +260 -0
  54. package/dist/testing/index.js.map +1 -0
  55. package/package.json +84 -4
@@ -0,0 +1,361 @@
1
+ // src/errors/media.errors.ts
2
+ var MediaError = class extends Error {
3
+ code;
4
+ cause;
5
+ details;
6
+ constructor(code, message, options) {
7
+ super(message);
8
+ this.name = "MediaError";
9
+ this.code = code;
10
+ this.cause = options?.cause;
11
+ this.details = options?.details;
12
+ }
13
+ };
14
+ var InvalidMediaFileError = class extends MediaError {
15
+ constructor(message, options) {
16
+ super("INVALID_FILE", message, options);
17
+ this.name = "InvalidMediaFileError";
18
+ }
19
+ };
20
+ var MediaQuotaExceededError = class extends MediaError {
21
+ constructor(message = "The media quota has been exceeded.") {
22
+ super("QUOTA_EXCEEDED", message);
23
+ this.name = "MediaQuotaExceededError";
24
+ }
25
+ };
26
+ var UnsupportedMediaError = class extends MediaError {
27
+ constructor(message, options) {
28
+ super("UNSUPPORTED_MEDIA", message, options);
29
+ this.name = "UnsupportedMediaError";
30
+ }
31
+ };
32
+ var MediaUploadExpiredError = class extends MediaError {
33
+ constructor(message = "The media upload session has expired.") {
34
+ super("UPLOAD_EXPIRED", message);
35
+ this.name = "MediaUploadExpiredError";
36
+ }
37
+ };
38
+ var MediaChecksumMismatchError = class extends MediaError {
39
+ constructor(message = "The uploaded object's checksum does not match.") {
40
+ super("CHECKSUM_MISMATCH", message);
41
+ this.name = "MediaChecksumMismatchError";
42
+ }
43
+ };
44
+ var MediaProcessingError = class extends MediaError {
45
+ retryable;
46
+ constructor(message, options) {
47
+ super("PROCESSING_FAILED", message, options);
48
+ this.name = "MediaProcessingError";
49
+ this.retryable = options?.retryable ?? true;
50
+ }
51
+ };
52
+ var MediaPermissionDeniedError = class extends MediaError {
53
+ constructor(message = "The actor is not permitted to perform this operation.") {
54
+ super("PERMISSION_DENIED", message);
55
+ this.name = "MediaPermissionDeniedError";
56
+ }
57
+ };
58
+ var MediaAssetConflictError = class extends MediaError {
59
+ constructor(message, options) {
60
+ super("ASSET_CONFLICT", message, options);
61
+ this.name = "MediaAssetConflictError";
62
+ }
63
+ };
64
+ var MediaNotFoundError = class extends MediaError {
65
+ constructor(resource = "Media resource") {
66
+ super("NOT_FOUND", `${resource} was not found.`);
67
+ this.name = "MediaNotFoundError";
68
+ }
69
+ };
70
+ var MediaValidationError = class extends MediaError {
71
+ constructor(message, details) {
72
+ super("VALIDATION", message, { details });
73
+ this.name = "MediaValidationError";
74
+ }
75
+ };
76
+ var MediaCapabilityError = class extends MediaError {
77
+ capability;
78
+ constructor(capability) {
79
+ super("CAPABILITY", `The configured adapter does not support the required capability: ${capability}.`, { details: { capability } });
80
+ this.name = "MediaCapabilityError";
81
+ this.capability = capability;
82
+ }
83
+ };
84
+ var MediaObjectStorageError = class extends MediaError {
85
+ constructor(message, options) {
86
+ super("OBJECT_STORAGE", message, options);
87
+ this.name = "MediaObjectStorageError";
88
+ }
89
+ };
90
+ // src/utils/media-validation.ts
91
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
92
+ const isFinitePositive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
93
+ const assertNormalizedCoordinate = (value, field) => {
94
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new MediaValidationError(`${field} must be a finite number from 0 to 1.`);
95
+ return value;
96
+ };
97
+ const validateProfileSize = (profile, name) => {
98
+ if (profile.maxWidth === void 0 && profile.maxHeight === void 0) throw new MediaValidationError(`Profile "${name}" must define maxWidth, maxHeight, or both.`);
99
+ for (const [key, value] of [["maxWidth", profile.maxWidth], ["maxHeight", profile.maxHeight]]) if (value !== void 0 && (!Number.isInteger(value) || value < 1)) throw new MediaValidationError(`Profile "${name}" ${key} must be a positive integer.`);
100
+ };
101
+ const normalizeMediaChecksum = (input) => {
102
+ if (!isRecord(input) || input.algorithm !== "sha256" || typeof input.value !== "string") throw new MediaValidationError("Checksum must be a sha256 digest.");
103
+ const value = input.value.toLowerCase();
104
+ if (!/^[a-f0-9]{64}$/.test(value)) throw new MediaValidationError("A sha256 checksum must contain 64 hexadecimal characters.");
105
+ return {
106
+ algorithm: "sha256",
107
+ value
108
+ };
109
+ };
110
+ const normalizeMediaObjectReference = (input) => {
111
+ if (!isRecord(input) || typeof input.key !== "string" || input.key.trim() === "") throw new MediaValidationError("A media object reference requires a non-empty key.");
112
+ if (/[\u0000-\u001f\u007f]/.test(input.key)) throw new MediaValidationError("A media object key cannot contain control characters.");
113
+ if (input.versionId !== void 0 && (typeof input.versionId !== "string" || input.versionId.trim() === "" || /[\u0000-\u001f\u007f]/.test(input.versionId))) throw new MediaValidationError("Object versionId must be a non-empty safe string.");
114
+ return {
115
+ key: input.key,
116
+ ...input.versionId !== void 0 ? { versionId: input.versionId } : {}
117
+ };
118
+ };
119
+ const normalizeMediaCrop = (input) => {
120
+ if (!isRecord(input)) throw new MediaValidationError("A crop must be an object.");
121
+ const x = assertNormalizedCoordinate(input.x, "crop.x");
122
+ const y = assertNormalizedCoordinate(input.y, "crop.y");
123
+ const width = assertNormalizedCoordinate(input.width, "crop.width");
124
+ const height = assertNormalizedCoordinate(input.height, "crop.height");
125
+ if (width <= 0 || height <= 0 || x + width > 1 || y + height > 1) throw new MediaValidationError("A crop must have positive dimensions and remain within the image bounds.");
126
+ return {
127
+ x,
128
+ y,
129
+ width,
130
+ height
131
+ };
132
+ };
133
+ const normalizeMediaFocalPoint = (input) => {
134
+ if (!isRecord(input)) throw new MediaValidationError("A focal point must be an object with x and y coordinates.");
135
+ return {
136
+ x: assertNormalizedCoordinate(input.x, "focalPoint.x"),
137
+ y: assertNormalizedCoordinate(input.y, "focalPoint.y")
138
+ };
139
+ };
140
+ const normalizeMediaHotspots = (input) => {
141
+ if (!Array.isArray(input)) throw new MediaValidationError("Hotspots must be an array.");
142
+ const ids = /* @__PURE__ */ new Set();
143
+ return input.map((item, index) => {
144
+ if (!isRecord(item) || typeof item.id !== "string" || item.id.trim() === "") throw new MediaValidationError(`Hotspot at index ${index} requires an id.`);
145
+ if (ids.has(item.id)) throw new MediaValidationError(`Hotspot id "${item.id}" is duplicated.`);
146
+ ids.add(item.id);
147
+ const x = assertNormalizedCoordinate(item.x, `hotspots[${index}].x`);
148
+ const y = assertNormalizedCoordinate(item.y, `hotspots[${index}].y`);
149
+ const width = item.width === void 0 ? void 0 : assertNormalizedCoordinate(item.width, `hotspots[${index}].width`);
150
+ const height = item.height === void 0 ? void 0 : assertNormalizedCoordinate(item.height, `hotspots[${index}].height`);
151
+ if (width === void 0 !== (height === void 0)) throw new MediaValidationError(`Hotspot "${item.id}" must define both width and height, or neither.`);
152
+ if (width !== void 0 && height !== void 0 && (width === 0 !== (height === 0) || x + width > 1 || y + height > 1)) throw new MediaValidationError(`Hotspot "${item.id}" must be a point or have positive dimensions within image bounds.`);
153
+ if (item.label !== void 0 && typeof item.label !== "string") throw new MediaValidationError(`Hotspot "${item.id}" label must be a string.`);
154
+ if (item.data !== void 0) {
155
+ if (!isRecord(item.data)) throw new MediaValidationError(`Hotspot "${item.id}" data must be an object.`);
156
+ for (const value of Object.values(item.data)) if (value !== null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new MediaValidationError(`Hotspot "${item.id}" data must contain only JSON scalar values.`);
157
+ }
158
+ return {
159
+ id: item.id,
160
+ x,
161
+ y,
162
+ ...width !== void 0 ? {
163
+ width,
164
+ height
165
+ } : {},
166
+ ...typeof item.label === "string" ? { label: item.label } : {},
167
+ ...isRecord(item.data) ? { data: item.data } : {}
168
+ };
169
+ });
170
+ };
171
+ const normalizeMediaTags = (input) => {
172
+ if (!Array.isArray(input) || input.some((tag) => typeof tag !== "string")) throw new MediaValidationError("Tags must be an array of strings.");
173
+ return [...new Set(input.map((tag) => tag.trim()).filter(Boolean))];
174
+ };
175
+ const validateMediaFileMetadata = (input) => {
176
+ if (!isRecord(input)) throw new MediaValidationError("Media metadata must be an object.");
177
+ if (![
178
+ "image",
179
+ "video",
180
+ "audio",
181
+ "document",
182
+ "other"
183
+ ].includes(input.kind)) throw new MediaValidationError("Media kind is not supported.");
184
+ if (typeof input.mimeType !== "string" || !/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i.test(input.mimeType)) throw new MediaValidationError("Media mimeType must be a valid type/subtype.");
185
+ const kind = input.kind;
186
+ if ((kind === "image" || kind === "video" || kind === "audio") && !input.mimeType.toLowerCase().startsWith(`${kind}/`)) throw new MediaValidationError(`A ${kind} asset must have a ${kind}/* MIME type.`);
187
+ if (!Number.isSafeInteger(input.size) || input.size < 1) throw new MediaValidationError("Media size must be a positive safe integer.");
188
+ const dimensionsPresent = input.width !== void 0 || input.height !== void 0;
189
+ if (dimensionsPresent && (!isFinitePositive(input.width) || !isFinitePositive(input.height) || !Number.isSafeInteger(input.width) || !Number.isSafeInteger(input.height))) throw new MediaValidationError("Media dimensions must include positive integer width and height values.");
190
+ if (input.duration !== void 0 && !isFinitePositive(input.duration) && input.duration !== 0) throw new MediaValidationError("Media duration must be a finite non-negative number.");
191
+ if (input.orientation !== void 0 && (typeof input.orientation !== "number" || !Number.isInteger(input.orientation) || input.orientation < 1 || input.orientation > 8)) throw new MediaValidationError("Image orientation must be an integer from 1 to 8.");
192
+ const checksum = input.checksum === void 0 ? void 0 : normalizeMediaChecksum(input.checksum);
193
+ return {
194
+ kind,
195
+ mimeType: input.mimeType.toLowerCase(),
196
+ size: input.size,
197
+ ...checksum ? { checksum } : {},
198
+ ...dimensionsPresent ? {
199
+ width: input.width,
200
+ height: input.height
201
+ } : {},
202
+ ...input.duration !== void 0 ? { duration: input.duration } : {},
203
+ ...input.orientation !== void 0 ? { orientation: input.orientation } : {}
204
+ };
205
+ };
206
+ const validateMediaImageProfiles = (profiles) => {
207
+ if (profiles.length === 0) throw new MediaValidationError("At least one image processing profile is required.");
208
+ const names = /* @__PURE__ */ new Set();
209
+ for (const profile of profiles) {
210
+ if (profile.name.trim() === "" || names.has(profile.name)) throw new MediaValidationError("Image profile names must be non-empty and unique.");
211
+ names.add(profile.name);
212
+ validateProfileSize(profile, profile.name);
213
+ if (profile.quality !== void 0 && (!Number.isFinite(profile.quality) || profile.quality < 0 || profile.quality > 1)) throw new MediaValidationError(`Image profile "${profile.name}" quality must be from 0 to 1.`);
214
+ }
215
+ return profiles;
216
+ };
217
+ const validateMediaVideoProfiles = (profiles) => {
218
+ if (profiles.length === 0) throw new MediaValidationError("At least one video rendition profile is required.");
219
+ const names = /* @__PURE__ */ new Set();
220
+ for (const profile of profiles) {
221
+ if (profile.name.trim() === "" || names.has(profile.name)) throw new MediaValidationError("Video profile names must be non-empty and unique.");
222
+ names.add(profile.name);
223
+ validateProfileSize(profile, profile.name);
224
+ for (const [key, value] of [["videoBitrate", profile.videoBitrate], ["audioBitrate", profile.audioBitrate]]) if (value !== void 0 && (!Number.isInteger(value) || value < 1)) throw new MediaValidationError(`Video profile "${profile.name}" ${key} must be a positive integer.`);
225
+ }
226
+ return profiles;
227
+ };
228
+ Object.defineProperty(exports, "InvalidMediaFileError", {
229
+ enumerable: true,
230
+ get: function() {
231
+ return InvalidMediaFileError;
232
+ }
233
+ });
234
+ Object.defineProperty(exports, "MediaAssetConflictError", {
235
+ enumerable: true,
236
+ get: function() {
237
+ return MediaAssetConflictError;
238
+ }
239
+ });
240
+ Object.defineProperty(exports, "MediaCapabilityError", {
241
+ enumerable: true,
242
+ get: function() {
243
+ return MediaCapabilityError;
244
+ }
245
+ });
246
+ Object.defineProperty(exports, "MediaChecksumMismatchError", {
247
+ enumerable: true,
248
+ get: function() {
249
+ return MediaChecksumMismatchError;
250
+ }
251
+ });
252
+ Object.defineProperty(exports, "MediaError", {
253
+ enumerable: true,
254
+ get: function() {
255
+ return MediaError;
256
+ }
257
+ });
258
+ Object.defineProperty(exports, "MediaNotFoundError", {
259
+ enumerable: true,
260
+ get: function() {
261
+ return MediaNotFoundError;
262
+ }
263
+ });
264
+ Object.defineProperty(exports, "MediaObjectStorageError", {
265
+ enumerable: true,
266
+ get: function() {
267
+ return MediaObjectStorageError;
268
+ }
269
+ });
270
+ Object.defineProperty(exports, "MediaPermissionDeniedError", {
271
+ enumerable: true,
272
+ get: function() {
273
+ return MediaPermissionDeniedError;
274
+ }
275
+ });
276
+ Object.defineProperty(exports, "MediaProcessingError", {
277
+ enumerable: true,
278
+ get: function() {
279
+ return MediaProcessingError;
280
+ }
281
+ });
282
+ Object.defineProperty(exports, "MediaQuotaExceededError", {
283
+ enumerable: true,
284
+ get: function() {
285
+ return MediaQuotaExceededError;
286
+ }
287
+ });
288
+ Object.defineProperty(exports, "MediaUploadExpiredError", {
289
+ enumerable: true,
290
+ get: function() {
291
+ return MediaUploadExpiredError;
292
+ }
293
+ });
294
+ Object.defineProperty(exports, "MediaValidationError", {
295
+ enumerable: true,
296
+ get: function() {
297
+ return MediaValidationError;
298
+ }
299
+ });
300
+ Object.defineProperty(exports, "UnsupportedMediaError", {
301
+ enumerable: true,
302
+ get: function() {
303
+ return UnsupportedMediaError;
304
+ }
305
+ });
306
+ Object.defineProperty(exports, "normalizeMediaChecksum", {
307
+ enumerable: true,
308
+ get: function() {
309
+ return normalizeMediaChecksum;
310
+ }
311
+ });
312
+ Object.defineProperty(exports, "normalizeMediaCrop", {
313
+ enumerable: true,
314
+ get: function() {
315
+ return normalizeMediaCrop;
316
+ }
317
+ });
318
+ Object.defineProperty(exports, "normalizeMediaFocalPoint", {
319
+ enumerable: true,
320
+ get: function() {
321
+ return normalizeMediaFocalPoint;
322
+ }
323
+ });
324
+ Object.defineProperty(exports, "normalizeMediaHotspots", {
325
+ enumerable: true,
326
+ get: function() {
327
+ return normalizeMediaHotspots;
328
+ }
329
+ });
330
+ Object.defineProperty(exports, "normalizeMediaObjectReference", {
331
+ enumerable: true,
332
+ get: function() {
333
+ return normalizeMediaObjectReference;
334
+ }
335
+ });
336
+ Object.defineProperty(exports, "normalizeMediaTags", {
337
+ enumerable: true,
338
+ get: function() {
339
+ return normalizeMediaTags;
340
+ }
341
+ });
342
+ Object.defineProperty(exports, "validateMediaFileMetadata", {
343
+ enumerable: true,
344
+ get: function() {
345
+ return validateMediaFileMetadata;
346
+ }
347
+ });
348
+ Object.defineProperty(exports, "validateMediaImageProfiles", {
349
+ enumerable: true,
350
+ get: function() {
351
+ return validateMediaImageProfiles;
352
+ }
353
+ });
354
+ Object.defineProperty(exports, "validateMediaVideoProfiles", {
355
+ enumerable: true,
356
+ get: function() {
357
+ return validateMediaVideoProfiles;
358
+ }
359
+ });
360
+
361
+ //# sourceMappingURL=media-validation-By6karZu.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-validation-By6karZu.cjs","names":[],"sources":["../src/errors/media.errors.ts","../src/utils/media-validation.ts"],"sourcesContent":["export type MediaErrorCode =\n | \"INVALID_FILE\"\n | \"QUOTA_EXCEEDED\"\n | \"UNSUPPORTED_MEDIA\"\n | \"UPLOAD_EXPIRED\"\n | \"CHECKSUM_MISMATCH\"\n | \"PROCESSING_FAILED\"\n | \"PERMISSION_DENIED\"\n | \"ASSET_CONFLICT\"\n | \"NOT_FOUND\"\n | \"VALIDATION\"\n | \"CAPABILITY\"\n | \"OBJECT_STORAGE\"\n | \"UNKNOWN\";\n\nexport type MediaErrorOptions = {\n readonly cause?: unknown;\n readonly details?: Readonly<Record<string, unknown>>;\n};\n\nexport class MediaError extends Error {\n readonly code: MediaErrorCode;\n override readonly cause?: unknown;\n readonly details?: Readonly<Record<string, unknown>>;\n\n constructor(\n code: MediaErrorCode,\n message: string,\n options?: MediaErrorOptions,\n ) {\n super(message);\n this.name = \"MediaError\";\n this.code = code;\n this.cause = options?.cause;\n this.details = options?.details;\n }\n}\n\nexport class InvalidMediaFileError extends MediaError {\n constructor(message: string, options?: MediaErrorOptions) {\n super(\"INVALID_FILE\", message, options);\n this.name = \"InvalidMediaFileError\";\n }\n}\n\nexport class MediaQuotaExceededError extends MediaError {\n constructor(message = \"The media quota has been exceeded.\") {\n super(\"QUOTA_EXCEEDED\", message);\n this.name = \"MediaQuotaExceededError\";\n }\n}\n\nexport class UnsupportedMediaError extends MediaError {\n constructor(message: string, options?: MediaErrorOptions) {\n super(\"UNSUPPORTED_MEDIA\", message, options);\n this.name = \"UnsupportedMediaError\";\n }\n}\n\nexport class MediaUploadExpiredError extends MediaError {\n constructor(message = \"The media upload session has expired.\") {\n super(\"UPLOAD_EXPIRED\", message);\n this.name = \"MediaUploadExpiredError\";\n }\n}\n\nexport class MediaChecksumMismatchError extends MediaError {\n constructor(message = \"The uploaded object's checksum does not match.\") {\n super(\"CHECKSUM_MISMATCH\", message);\n this.name = \"MediaChecksumMismatchError\";\n }\n}\n\nexport class MediaProcessingError extends MediaError {\n readonly retryable: boolean;\n\n constructor(\n message: string,\n options?: MediaErrorOptions & { readonly retryable?: boolean },\n ) {\n super(\"PROCESSING_FAILED\", message, options);\n this.name = \"MediaProcessingError\";\n this.retryable = options?.retryable ?? true;\n }\n}\n\nexport class MediaPermissionDeniedError extends MediaError {\n constructor(message = \"The actor is not permitted to perform this operation.\") {\n super(\"PERMISSION_DENIED\", message);\n this.name = \"MediaPermissionDeniedError\";\n }\n}\n\nexport class MediaAssetConflictError extends MediaError {\n constructor(message: string, options?: MediaErrorOptions) {\n super(\"ASSET_CONFLICT\", message, options);\n this.name = \"MediaAssetConflictError\";\n }\n}\n\nexport class MediaNotFoundError extends MediaError {\n constructor(resource = \"Media resource\") {\n super(\"NOT_FOUND\", `${resource} was not found.`);\n this.name = \"MediaNotFoundError\";\n }\n}\n\nexport class MediaValidationError extends MediaError {\n constructor(\n message: string,\n details?: Readonly<Record<string, unknown>>,\n ) {\n super(\"VALIDATION\", message, { details });\n this.name = \"MediaValidationError\";\n }\n}\n\nexport class MediaCapabilityError extends MediaError {\n readonly capability: string;\n\n constructor(capability: string) {\n super(\n \"CAPABILITY\",\n `The configured adapter does not support the required capability: ${capability}.`,\n { details: { capability } },\n );\n this.name = \"MediaCapabilityError\";\n this.capability = capability;\n }\n}\n\nexport class MediaObjectStorageError extends MediaError {\n constructor(message: string, options?: MediaErrorOptions) {\n super(\"OBJECT_STORAGE\", message, options);\n this.name = \"MediaObjectStorageError\";\n }\n}\n","import { MediaValidationError } from \"../errors/media.errors\";\nimport type {\n MediaChecksum,\n MediaCrop,\n MediaFocalPoint,\n MediaFileMetadata,\n MediaHotspot,\n MediaKind,\n MediaObjectReference,\n} from \"../types/media.types\";\nimport type {\n MediaImageProfile,\n MediaVideoRenditionProfile,\n} from \"../types/processing.types\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isFinitePositive = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isFinite(value) && value > 0;\n\nconst assertNormalizedCoordinate = (value: unknown, field: string): number => {\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0 || value > 1) {\n throw new MediaValidationError(`${field} must be a finite number from 0 to 1.`);\n }\n return value;\n};\n\nconst validateProfileSize = (\n profile: { readonly maxWidth?: number; readonly maxHeight?: number },\n name: string,\n): void => {\n if (profile.maxWidth === undefined && profile.maxHeight === undefined) {\n throw new MediaValidationError(\n `Profile \"${name}\" must define maxWidth, maxHeight, or both.`,\n );\n }\n for (const [key, value] of [\n [\"maxWidth\", profile.maxWidth],\n [\"maxHeight\", profile.maxHeight],\n ] as const) {\n if (value !== undefined && (!Number.isInteger(value) || value < 1)) {\n throw new MediaValidationError(\n `Profile \"${name}\" ${key} must be a positive integer.`,\n );\n }\n }\n};\n\nexport const normalizeMediaChecksum = (input: unknown): MediaChecksum => {\n if (!isRecord(input) || input.algorithm !== \"sha256\" || typeof input.value !== \"string\") {\n throw new MediaValidationError(\"Checksum must be a sha256 digest.\");\n }\n const value = input.value.toLowerCase();\n if (!/^[a-f0-9]{64}$/.test(value)) {\n throw new MediaValidationError(\"A sha256 checksum must contain 64 hexadecimal characters.\");\n }\n return { algorithm: \"sha256\", value };\n};\n\nexport const normalizeMediaObjectReference = (\n input: unknown,\n): MediaObjectReference => {\n if (!isRecord(input) || typeof input.key !== \"string\" || input.key.trim() === \"\") {\n throw new MediaValidationError(\"A media object reference requires a non-empty key.\");\n }\n if (/[\\u0000-\\u001f\\u007f]/.test(input.key)) {\n throw new MediaValidationError(\"A media object key cannot contain control characters.\");\n }\n if (\n input.versionId !== undefined &&\n (typeof input.versionId !== \"string\" ||\n input.versionId.trim() === \"\" ||\n /[\\u0000-\\u001f\\u007f]/.test(input.versionId))\n ) {\n throw new MediaValidationError(\"Object versionId must be a non-empty safe string.\");\n }\n return {\n key: input.key,\n ...(input.versionId !== undefined ? { versionId: input.versionId } : {}),\n };\n};\n\nexport const normalizeMediaCrop = (input: unknown): MediaCrop => {\n if (!isRecord(input)) {\n throw new MediaValidationError(\"A crop must be an object.\");\n }\n const x = assertNormalizedCoordinate(input.x, \"crop.x\");\n const y = assertNormalizedCoordinate(input.y, \"crop.y\");\n const width = assertNormalizedCoordinate(input.width, \"crop.width\");\n const height = assertNormalizedCoordinate(input.height, \"crop.height\");\n if (width <= 0 || height <= 0 || x + width > 1 || y + height > 1) {\n throw new MediaValidationError(\n \"A crop must have positive dimensions and remain within the image bounds.\",\n );\n }\n return { x, y, width, height };\n};\n\nexport const normalizeMediaFocalPoint = (input: unknown): MediaFocalPoint => {\n if (!isRecord(input)) {\n throw new MediaValidationError(\n \"A focal point must be an object with x and y coordinates.\",\n );\n }\n return {\n x: assertNormalizedCoordinate(input.x, \"focalPoint.x\"),\n y: assertNormalizedCoordinate(input.y, \"focalPoint.y\"),\n };\n};\n\nexport const normalizeMediaHotspots = (input: unknown): readonly MediaHotspot[] => {\n if (!Array.isArray(input)) {\n throw new MediaValidationError(\"Hotspots must be an array.\");\n }\n const ids = new Set<string>();\n return input.map((item, index) => {\n if (!isRecord(item) || typeof item.id !== \"string\" || item.id.trim() === \"\") {\n throw new MediaValidationError(`Hotspot at index ${index} requires an id.`);\n }\n if (ids.has(item.id)) {\n throw new MediaValidationError(`Hotspot id \"${item.id}\" is duplicated.`);\n }\n ids.add(item.id);\n const x = assertNormalizedCoordinate(item.x, `hotspots[${index}].x`);\n const y = assertNormalizedCoordinate(item.y, `hotspots[${index}].y`);\n const width =\n item.width === undefined\n ? undefined\n : assertNormalizedCoordinate(item.width, `hotspots[${index}].width`);\n const height =\n item.height === undefined\n ? undefined\n : assertNormalizedCoordinate(item.height, `hotspots[${index}].height`);\n if ((width === undefined) !== (height === undefined)) {\n throw new MediaValidationError(\n `Hotspot \"${item.id}\" must define both width and height, or neither.`,\n );\n }\n if (\n width !== undefined &&\n height !== undefined &&\n ((width === 0) !== (height === 0) || x + width > 1 || y + height > 1)\n ) {\n throw new MediaValidationError(\n `Hotspot \"${item.id}\" must be a point or have positive dimensions within image bounds.`,\n );\n }\n if (item.label !== undefined && typeof item.label !== \"string\") {\n throw new MediaValidationError(`Hotspot \"${item.id}\" label must be a string.`);\n }\n if (item.data !== undefined) {\n if (!isRecord(item.data)) {\n throw new MediaValidationError(`Hotspot \"${item.id}\" data must be an object.`);\n }\n for (const value of Object.values(item.data)) {\n if (\n value !== null &&\n typeof value !== \"string\" &&\n typeof value !== \"number\" &&\n typeof value !== \"boolean\"\n ) {\n throw new MediaValidationError(\n `Hotspot \"${item.id}\" data must contain only JSON scalar values.`,\n );\n }\n }\n }\n return {\n id: item.id,\n x,\n y,\n ...(width !== undefined ? { width, height } : {}),\n ...(typeof item.label === \"string\" ? { label: item.label } : {}),\n ...(isRecord(item.data)\n ? {\n data: item.data as Readonly<\n Record<string, string | number | boolean | null>\n >,\n }\n : {}),\n };\n });\n};\n\nexport const normalizeMediaTags = (input: unknown): readonly string[] => {\n if (!Array.isArray(input) || input.some((tag) => typeof tag !== \"string\")) {\n throw new MediaValidationError(\"Tags must be an array of strings.\");\n }\n return [...new Set(input.map((tag: string) => tag.trim()).filter(Boolean))];\n};\n\nexport const validateMediaFileMetadata = (\n input: unknown,\n): MediaFileMetadata => {\n if (!isRecord(input)) {\n throw new MediaValidationError(\"Media metadata must be an object.\");\n }\n const kinds: readonly MediaKind[] = [\n \"image\",\n \"video\",\n \"audio\",\n \"document\",\n \"other\",\n ];\n if (!kinds.includes(input.kind as MediaKind)) {\n throw new MediaValidationError(\"Media kind is not supported.\");\n }\n if (\n typeof input.mimeType !== \"string\" ||\n !/^[a-z0-9!#$&^_.+-]+\\/[a-z0-9!#$&^_.+-]+$/i.test(input.mimeType)\n ) {\n throw new MediaValidationError(\"Media mimeType must be a valid type/subtype.\");\n }\n const kind = input.kind as MediaKind;\n if (\n (kind === \"image\" || kind === \"video\" || kind === \"audio\") &&\n !input.mimeType.toLowerCase().startsWith(`${kind}/`)\n ) {\n throw new MediaValidationError(\n `A ${kind} asset must have a ${kind}/* MIME type.`,\n );\n }\n if (!Number.isSafeInteger(input.size) || (input.size as number) < 1) {\n throw new MediaValidationError(\"Media size must be a positive safe integer.\");\n }\n const dimensionsPresent = input.width !== undefined || input.height !== undefined;\n if (\n dimensionsPresent &&\n (!isFinitePositive(input.width) ||\n !isFinitePositive(input.height) ||\n !Number.isSafeInteger(input.width) ||\n !Number.isSafeInteger(input.height))\n ) {\n throw new MediaValidationError(\n \"Media dimensions must include positive integer width and height values.\",\n );\n }\n if (input.duration !== undefined && !isFinitePositive(input.duration) && input.duration !== 0) {\n throw new MediaValidationError(\"Media duration must be a finite non-negative number.\");\n }\n if (\n input.orientation !== undefined &&\n (typeof input.orientation !== \"number\" ||\n !Number.isInteger(input.orientation) ||\n input.orientation < 1 ||\n input.orientation > 8)\n ) {\n throw new MediaValidationError(\"Image orientation must be an integer from 1 to 8.\");\n }\n const checksum =\n input.checksum === undefined\n ? undefined\n : normalizeMediaChecksum(input.checksum);\n return {\n kind,\n mimeType: input.mimeType.toLowerCase(),\n size: input.size as number,\n ...(checksum ? { checksum } : {}),\n ...(dimensionsPresent\n ? { width: input.width as number, height: input.height as number }\n : {}),\n ...(input.duration !== undefined ? { duration: input.duration as number } : {}),\n ...(input.orientation !== undefined\n ? { orientation: input.orientation as number }\n : {}),\n };\n};\n\nexport const validateMediaImageProfiles = (\n profiles: readonly MediaImageProfile[],\n): readonly MediaImageProfile[] => {\n if (profiles.length === 0) {\n throw new MediaValidationError(\"At least one image processing profile is required.\");\n }\n const names = new Set<string>();\n for (const profile of profiles) {\n if (profile.name.trim() === \"\" || names.has(profile.name)) {\n throw new MediaValidationError(\n \"Image profile names must be non-empty and unique.\",\n );\n }\n names.add(profile.name);\n validateProfileSize(profile, profile.name);\n if (\n profile.quality !== undefined &&\n (!Number.isFinite(profile.quality) ||\n profile.quality < 0 ||\n profile.quality > 1)\n ) {\n throw new MediaValidationError(\n `Image profile \"${profile.name}\" quality must be from 0 to 1.`,\n );\n }\n }\n return profiles;\n};\n\nexport const validateMediaVideoProfiles = (\n profiles: readonly MediaVideoRenditionProfile[],\n): readonly MediaVideoRenditionProfile[] => {\n if (profiles.length === 0) {\n throw new MediaValidationError(\"At least one video rendition profile is required.\");\n }\n const names = new Set<string>();\n for (const profile of profiles) {\n if (profile.name.trim() === \"\" || names.has(profile.name)) {\n throw new MediaValidationError(\n \"Video profile names must be non-empty and unique.\",\n );\n }\n names.add(profile.name);\n validateProfileSize(profile, profile.name);\n for (const [key, value] of [\n [\"videoBitrate\", profile.videoBitrate],\n [\"audioBitrate\", profile.audioBitrate],\n ] as const) {\n if (value !== undefined && (!Number.isInteger(value) || value < 1)) {\n throw new MediaValidationError(\n `Video profile \"${profile.name}\" ${key} must be a positive integer.`,\n );\n }\n }\n }\n return profiles;\n};\n"],"mappings":";AAoBA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA;CACA;CAEA,YACE,MACA,SACA,SACA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,QAAQ,SAAS;EACtB,KAAK,UAAU,SAAS;CAC1B;AACF;AAEA,IAAa,wBAAb,cAA2C,WAAW;CACpD,YAAY,SAAiB,SAA6B;EACxD,MAAM,gBAAgB,SAAS,OAAO;EACtC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,0BAAb,cAA6C,WAAW;CACtD,YAAY,UAAU,sCAAsC;EAC1D,MAAM,kBAAkB,OAAO;EAC/B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,wBAAb,cAA2C,WAAW;CACpD,YAAY,SAAiB,SAA6B;EACxD,MAAM,qBAAqB,SAAS,OAAO;EAC3C,KAAK,OAAO;CACd;AACF;AAEA,IAAa,0BAAb,cAA6C,WAAW;CACtD,YAAY,UAAU,yCAAyC;EAC7D,MAAM,kBAAkB,OAAO;EAC/B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,6BAAb,cAAgD,WAAW;CACzD,YAAY,UAAU,kDAAkD;EACtE,MAAM,qBAAqB,OAAO;EAClC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,uBAAb,cAA0C,WAAW;CACnD;CAEA,YACE,SACA,SACA;EACA,MAAM,qBAAqB,SAAS,OAAO;EAC3C,KAAK,OAAO;EACZ,KAAK,YAAY,SAAS,aAAa;CACzC;AACF;AAEA,IAAa,6BAAb,cAAgD,WAAW;CACzD,YAAY,UAAU,yDAAyD;EAC7E,MAAM,qBAAqB,OAAO;EAClC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,0BAAb,cAA6C,WAAW;CACtD,YAAY,SAAiB,SAA6B;EACxD,MAAM,kBAAkB,SAAS,OAAO;EACxC,KAAK,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B,MAAM,IAAI,qBAAqB,oDAAoD;CAErF,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,WAAW,UAAU;EAC9B,IAAI,QAAQ,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI,QAAQ,IAAI,GACtD,MAAM,IAAI,qBACR,mDACF;EAEF,MAAM,IAAI,QAAQ,IAAI;EACtB,oBAAoB,SAAS,QAAQ,IAAI;EACzC,IACE,QAAQ,YAAY,KAAA,MACnB,CAAC,OAAO,SAAS,QAAQ,OAAO,KAC/B,QAAQ,UAAU,KAClB,QAAQ,UAAU,IAEpB,MAAM,IAAI,qBACR,kBAAkB,QAAQ,KAAK,+BACjC;CAEJ;CACA,OAAO;AACT;AAEA,MAAa,8BACX,aAC0C;CAC1C,IAAI,SAAS,WAAW,GACtB,MAAM,IAAI,qBAAqB,mDAAmD;CAEpF,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,WAAW,UAAU;EAC9B,IAAI,QAAQ,KAAK,KAAK,MAAM,MAAM,MAAM,IAAI,QAAQ,IAAI,GACtD,MAAM,IAAI,qBACR,mDACF;EAEF,MAAM,IAAI,QAAQ,IAAI;EACtB,oBAAoB,SAAS,QAAQ,IAAI;EACzC,KAAK,MAAM,CAAC,KAAK,UAAU,CACzB,CAAC,gBAAgB,QAAQ,YAAY,GACrC,CAAC,gBAAgB,QAAQ,YAAY,CACvC,GACE,IAAI,UAAU,KAAA,MAAc,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,IAC9D,MAAM,IAAI,qBACR,kBAAkB,QAAQ,KAAK,IAAI,IAAI,6BACzC;CAGN;CACA,OAAO;AACT"}
@@ -0,0 +1,230 @@
1
+ // src/errors/media.errors.ts
2
+ var MediaError = class extends Error {
3
+ code;
4
+ cause;
5
+ details;
6
+ constructor(code, message, options) {
7
+ super(message);
8
+ this.name = "MediaError";
9
+ this.code = code;
10
+ this.cause = options?.cause;
11
+ this.details = options?.details;
12
+ }
13
+ };
14
+ var InvalidMediaFileError = class extends MediaError {
15
+ constructor(message, options) {
16
+ super("INVALID_FILE", message, options);
17
+ this.name = "InvalidMediaFileError";
18
+ }
19
+ };
20
+ var MediaQuotaExceededError = class extends MediaError {
21
+ constructor(message = "The media quota has been exceeded.") {
22
+ super("QUOTA_EXCEEDED", message);
23
+ this.name = "MediaQuotaExceededError";
24
+ }
25
+ };
26
+ var UnsupportedMediaError = class extends MediaError {
27
+ constructor(message, options) {
28
+ super("UNSUPPORTED_MEDIA", message, options);
29
+ this.name = "UnsupportedMediaError";
30
+ }
31
+ };
32
+ var MediaUploadExpiredError = class extends MediaError {
33
+ constructor(message = "The media upload session has expired.") {
34
+ super("UPLOAD_EXPIRED", message);
35
+ this.name = "MediaUploadExpiredError";
36
+ }
37
+ };
38
+ var MediaChecksumMismatchError = class extends MediaError {
39
+ constructor(message = "The uploaded object's checksum does not match.") {
40
+ super("CHECKSUM_MISMATCH", message);
41
+ this.name = "MediaChecksumMismatchError";
42
+ }
43
+ };
44
+ var MediaProcessingError = class extends MediaError {
45
+ retryable;
46
+ constructor(message, options) {
47
+ super("PROCESSING_FAILED", message, options);
48
+ this.name = "MediaProcessingError";
49
+ this.retryable = options?.retryable ?? true;
50
+ }
51
+ };
52
+ var MediaPermissionDeniedError = class extends MediaError {
53
+ constructor(message = "The actor is not permitted to perform this operation.") {
54
+ super("PERMISSION_DENIED", message);
55
+ this.name = "MediaPermissionDeniedError";
56
+ }
57
+ };
58
+ var MediaAssetConflictError = class extends MediaError {
59
+ constructor(message, options) {
60
+ super("ASSET_CONFLICT", message, options);
61
+ this.name = "MediaAssetConflictError";
62
+ }
63
+ };
64
+ var MediaNotFoundError = class extends MediaError {
65
+ constructor(resource = "Media resource") {
66
+ super("NOT_FOUND", `${resource} was not found.`);
67
+ this.name = "MediaNotFoundError";
68
+ }
69
+ };
70
+ var MediaValidationError = class extends MediaError {
71
+ constructor(message, details) {
72
+ super("VALIDATION", message, { details });
73
+ this.name = "MediaValidationError";
74
+ }
75
+ };
76
+ var MediaCapabilityError = class extends MediaError {
77
+ capability;
78
+ constructor(capability) {
79
+ super("CAPABILITY", `The configured adapter does not support the required capability: ${capability}.`, { details: { capability } });
80
+ this.name = "MediaCapabilityError";
81
+ this.capability = capability;
82
+ }
83
+ };
84
+ var MediaObjectStorageError = class extends MediaError {
85
+ constructor(message, options) {
86
+ super("OBJECT_STORAGE", message, options);
87
+ this.name = "MediaObjectStorageError";
88
+ }
89
+ };
90
+ // src/utils/media-validation.ts
91
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
92
+ const isFinitePositive = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
93
+ const assertNormalizedCoordinate = (value, field) => {
94
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new MediaValidationError(`${field} must be a finite number from 0 to 1.`);
95
+ return value;
96
+ };
97
+ const validateProfileSize = (profile, name) => {
98
+ if (profile.maxWidth === void 0 && profile.maxHeight === void 0) throw new MediaValidationError(`Profile "${name}" must define maxWidth, maxHeight, or both.`);
99
+ for (const [key, value] of [["maxWidth", profile.maxWidth], ["maxHeight", profile.maxHeight]]) if (value !== void 0 && (!Number.isInteger(value) || value < 1)) throw new MediaValidationError(`Profile "${name}" ${key} must be a positive integer.`);
100
+ };
101
+ const normalizeMediaChecksum = (input) => {
102
+ if (!isRecord(input) || input.algorithm !== "sha256" || typeof input.value !== "string") throw new MediaValidationError("Checksum must be a sha256 digest.");
103
+ const value = input.value.toLowerCase();
104
+ if (!/^[a-f0-9]{64}$/.test(value)) throw new MediaValidationError("A sha256 checksum must contain 64 hexadecimal characters.");
105
+ return {
106
+ algorithm: "sha256",
107
+ value
108
+ };
109
+ };
110
+ const normalizeMediaObjectReference = (input) => {
111
+ if (!isRecord(input) || typeof input.key !== "string" || input.key.trim() === "") throw new MediaValidationError("A media object reference requires a non-empty key.");
112
+ if (/[\u0000-\u001f\u007f]/.test(input.key)) throw new MediaValidationError("A media object key cannot contain control characters.");
113
+ if (input.versionId !== void 0 && (typeof input.versionId !== "string" || input.versionId.trim() === "" || /[\u0000-\u001f\u007f]/.test(input.versionId))) throw new MediaValidationError("Object versionId must be a non-empty safe string.");
114
+ return {
115
+ key: input.key,
116
+ ...input.versionId !== void 0 ? { versionId: input.versionId } : {}
117
+ };
118
+ };
119
+ const normalizeMediaCrop = (input) => {
120
+ if (!isRecord(input)) throw new MediaValidationError("A crop must be an object.");
121
+ const x = assertNormalizedCoordinate(input.x, "crop.x");
122
+ const y = assertNormalizedCoordinate(input.y, "crop.y");
123
+ const width = assertNormalizedCoordinate(input.width, "crop.width");
124
+ const height = assertNormalizedCoordinate(input.height, "crop.height");
125
+ if (width <= 0 || height <= 0 || x + width > 1 || y + height > 1) throw new MediaValidationError("A crop must have positive dimensions and remain within the image bounds.");
126
+ return {
127
+ x,
128
+ y,
129
+ width,
130
+ height
131
+ };
132
+ };
133
+ const normalizeMediaFocalPoint = (input) => {
134
+ if (!isRecord(input)) throw new MediaValidationError("A focal point must be an object with x and y coordinates.");
135
+ return {
136
+ x: assertNormalizedCoordinate(input.x, "focalPoint.x"),
137
+ y: assertNormalizedCoordinate(input.y, "focalPoint.y")
138
+ };
139
+ };
140
+ const normalizeMediaHotspots = (input) => {
141
+ if (!Array.isArray(input)) throw new MediaValidationError("Hotspots must be an array.");
142
+ const ids = /* @__PURE__ */ new Set();
143
+ return input.map((item, index) => {
144
+ if (!isRecord(item) || typeof item.id !== "string" || item.id.trim() === "") throw new MediaValidationError(`Hotspot at index ${index} requires an id.`);
145
+ if (ids.has(item.id)) throw new MediaValidationError(`Hotspot id "${item.id}" is duplicated.`);
146
+ ids.add(item.id);
147
+ const x = assertNormalizedCoordinate(item.x, `hotspots[${index}].x`);
148
+ const y = assertNormalizedCoordinate(item.y, `hotspots[${index}].y`);
149
+ const width = item.width === void 0 ? void 0 : assertNormalizedCoordinate(item.width, `hotspots[${index}].width`);
150
+ const height = item.height === void 0 ? void 0 : assertNormalizedCoordinate(item.height, `hotspots[${index}].height`);
151
+ if (width === void 0 !== (height === void 0)) throw new MediaValidationError(`Hotspot "${item.id}" must define both width and height, or neither.`);
152
+ if (width !== void 0 && height !== void 0 && (width === 0 !== (height === 0) || x + width > 1 || y + height > 1)) throw new MediaValidationError(`Hotspot "${item.id}" must be a point or have positive dimensions within image bounds.`);
153
+ if (item.label !== void 0 && typeof item.label !== "string") throw new MediaValidationError(`Hotspot "${item.id}" label must be a string.`);
154
+ if (item.data !== void 0) {
155
+ if (!isRecord(item.data)) throw new MediaValidationError(`Hotspot "${item.id}" data must be an object.`);
156
+ for (const value of Object.values(item.data)) if (value !== null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new MediaValidationError(`Hotspot "${item.id}" data must contain only JSON scalar values.`);
157
+ }
158
+ return {
159
+ id: item.id,
160
+ x,
161
+ y,
162
+ ...width !== void 0 ? {
163
+ width,
164
+ height
165
+ } : {},
166
+ ...typeof item.label === "string" ? { label: item.label } : {},
167
+ ...isRecord(item.data) ? { data: item.data } : {}
168
+ };
169
+ });
170
+ };
171
+ const normalizeMediaTags = (input) => {
172
+ if (!Array.isArray(input) || input.some((tag) => typeof tag !== "string")) throw new MediaValidationError("Tags must be an array of strings.");
173
+ return [...new Set(input.map((tag) => tag.trim()).filter(Boolean))];
174
+ };
175
+ const validateMediaFileMetadata = (input) => {
176
+ if (!isRecord(input)) throw new MediaValidationError("Media metadata must be an object.");
177
+ if (![
178
+ "image",
179
+ "video",
180
+ "audio",
181
+ "document",
182
+ "other"
183
+ ].includes(input.kind)) throw new MediaValidationError("Media kind is not supported.");
184
+ if (typeof input.mimeType !== "string" || !/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i.test(input.mimeType)) throw new MediaValidationError("Media mimeType must be a valid type/subtype.");
185
+ const kind = input.kind;
186
+ if ((kind === "image" || kind === "video" || kind === "audio") && !input.mimeType.toLowerCase().startsWith(`${kind}/`)) throw new MediaValidationError(`A ${kind} asset must have a ${kind}/* MIME type.`);
187
+ if (!Number.isSafeInteger(input.size) || input.size < 1) throw new MediaValidationError("Media size must be a positive safe integer.");
188
+ const dimensionsPresent = input.width !== void 0 || input.height !== void 0;
189
+ if (dimensionsPresent && (!isFinitePositive(input.width) || !isFinitePositive(input.height) || !Number.isSafeInteger(input.width) || !Number.isSafeInteger(input.height))) throw new MediaValidationError("Media dimensions must include positive integer width and height values.");
190
+ if (input.duration !== void 0 && !isFinitePositive(input.duration) && input.duration !== 0) throw new MediaValidationError("Media duration must be a finite non-negative number.");
191
+ if (input.orientation !== void 0 && (typeof input.orientation !== "number" || !Number.isInteger(input.orientation) || input.orientation < 1 || input.orientation > 8)) throw new MediaValidationError("Image orientation must be an integer from 1 to 8.");
192
+ const checksum = input.checksum === void 0 ? void 0 : normalizeMediaChecksum(input.checksum);
193
+ return {
194
+ kind,
195
+ mimeType: input.mimeType.toLowerCase(),
196
+ size: input.size,
197
+ ...checksum ? { checksum } : {},
198
+ ...dimensionsPresent ? {
199
+ width: input.width,
200
+ height: input.height
201
+ } : {},
202
+ ...input.duration !== void 0 ? { duration: input.duration } : {},
203
+ ...input.orientation !== void 0 ? { orientation: input.orientation } : {}
204
+ };
205
+ };
206
+ const validateMediaImageProfiles = (profiles) => {
207
+ if (profiles.length === 0) throw new MediaValidationError("At least one image processing profile is required.");
208
+ const names = /* @__PURE__ */ new Set();
209
+ for (const profile of profiles) {
210
+ if (profile.name.trim() === "" || names.has(profile.name)) throw new MediaValidationError("Image profile names must be non-empty and unique.");
211
+ names.add(profile.name);
212
+ validateProfileSize(profile, profile.name);
213
+ if (profile.quality !== void 0 && (!Number.isFinite(profile.quality) || profile.quality < 0 || profile.quality > 1)) throw new MediaValidationError(`Image profile "${profile.name}" quality must be from 0 to 1.`);
214
+ }
215
+ return profiles;
216
+ };
217
+ const validateMediaVideoProfiles = (profiles) => {
218
+ if (profiles.length === 0) throw new MediaValidationError("At least one video rendition profile is required.");
219
+ const names = /* @__PURE__ */ new Set();
220
+ for (const profile of profiles) {
221
+ if (profile.name.trim() === "" || names.has(profile.name)) throw new MediaValidationError("Video profile names must be non-empty and unique.");
222
+ names.add(profile.name);
223
+ validateProfileSize(profile, profile.name);
224
+ for (const [key, value] of [["videoBitrate", profile.videoBitrate], ["audioBitrate", profile.audioBitrate]]) if (value !== void 0 && (!Number.isInteger(value) || value < 1)) throw new MediaValidationError(`Video profile "${profile.name}" ${key} must be a positive integer.`);
225
+ }
226
+ return profiles;
227
+ };
228
+ export { UnsupportedMediaError as S, MediaPermissionDeniedError as _, normalizeMediaObjectReference as a, MediaUploadExpiredError as b, validateMediaImageProfiles as c, MediaAssetConflictError as d, MediaCapabilityError as f, MediaObjectStorageError as g, MediaNotFoundError as h, normalizeMediaHotspots as i, validateMediaVideoProfiles as l, MediaError as m, normalizeMediaCrop as n, normalizeMediaTags as o, MediaChecksumMismatchError as p, normalizeMediaFocalPoint as r, validateMediaFileMetadata as s, normalizeMediaChecksum as t, InvalidMediaFileError as u, MediaProcessingError as v, MediaValidationError as x, MediaQuotaExceededError as y };
229
+
230
+ //# sourceMappingURL=media-validation-OyjGVUq3.js.map