@imagekit/javascript 5.0.0-beta.3

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.
@@ -0,0 +1,619 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var errorMessages = {
6
+ MANDATORY_INITIALIZATION_MISSING: {
7
+ message: "Missing urlEndpoint during SDK initialization"
8
+ },
9
+ INVALID_TRANSFORMATION_POSITION: {
10
+ message: "Invalid transformationPosition parameter"
11
+ },
12
+ PRIVATE_KEY_CLIENT_SIDE: {
13
+ message: "privateKey should not be passed on the client side"
14
+ },
15
+ MISSING_UPLOAD_DATA: {
16
+ message: "Missing data for upload"
17
+ },
18
+ MISSING_UPLOAD_FILE_PARAMETER: {
19
+ message: "Missing file parameter for upload"
20
+ },
21
+ MISSING_UPLOAD_FILENAME_PARAMETER: {
22
+ message: "Missing fileName parameter for upload"
23
+ },
24
+ MISSING_AUTHENTICATION_ENDPOINT: {
25
+ message: "Missing authentication endpoint for upload"
26
+ },
27
+ MISSING_PUBLIC_KEY: {
28
+ message: "Missing public key for upload"
29
+ },
30
+ AUTH_ENDPOINT_TIMEOUT: {
31
+ message: "The authenticationEndpoint you provided timed out in 60 seconds"
32
+ },
33
+ AUTH_ENDPOINT_NETWORK_ERROR: {
34
+ message: "Request to authenticationEndpoint failed due to network error"
35
+ },
36
+ AUTH_INVALID_RESPONSE: {
37
+ message: "Invalid response from authenticationEndpoint. The SDK expects a JSON response with three fields i.e. signature, token and expire."
38
+ },
39
+ UPLOAD_ENDPOINT_NETWORK_ERROR: {
40
+ message: "Request to ImageKit upload endpoint failed due to network error"
41
+ },
42
+ INVALID_UPLOAD_OPTIONS: {
43
+ message: "Invalid uploadOptions parameter"
44
+ },
45
+ MISSING_SIGNATURE: {
46
+ message: "Missing signature for upload. The SDK expects token, signature and expire for authentication."
47
+ },
48
+ MISSING_TOKEN: {
49
+ message: "Missing token for upload. The SDK expects token, signature and expire for authentication."
50
+ },
51
+ MISSING_EXPIRE: {
52
+ message: "Missing expire for upload. The SDK expects token, signature and expire for authentication."
53
+ },
54
+ INVALID_TRANSFORMATION: {
55
+ message: "Invalid transformation parameter. Please include at least pre, post, or both."
56
+ },
57
+ INVALID_PRE_TRANSFORMATION: {
58
+ message: "Invalid pre transformation parameter."
59
+ },
60
+ INVALID_POST_TRANSFORMATION: {
61
+ message: "Invalid post transformation parameter."
62
+ },
63
+ UPLOAD_ABORTED: {
64
+ message: "Request aborted by the user"
65
+ }
66
+ };
67
+
68
+ class ImageKitInvalidRequestError extends Error {
69
+ constructor(message, responseMetadata) {
70
+ super(message);
71
+ this.$ResponseMetadata = void 0;
72
+ this.name = "ImageKitInvalidRequestError";
73
+ this.$ResponseMetadata = responseMetadata;
74
+ }
75
+ }
76
+ class ImageKitAbortError extends Error {
77
+ constructor(message, reason) {
78
+ super(message);
79
+ this.reason = void 0;
80
+ this.name = "ImageKitAbortError";
81
+ this.reason = reason;
82
+ }
83
+ }
84
+ class ImageKitUploadNetworkError extends Error {
85
+ constructor(message) {
86
+ super(message);
87
+ this.name = "ImageKitUploadNetworkError";
88
+ }
89
+ }
90
+ class ImageKitServerError extends Error {
91
+ constructor(message, responseMetadata) {
92
+ super(message);
93
+ this.$ResponseMetadata = void 0;
94
+ this.name = "ImageKitServerError";
95
+ this.$ResponseMetadata = responseMetadata;
96
+ }
97
+ }
98
+ const upload = uploadOptions => {
99
+ if (!uploadOptions) {
100
+ return Promise.reject(new ImageKitInvalidRequestError("Invalid options provided for upload"));
101
+ }
102
+ return new Promise((resolve, reject) => {
103
+ const {
104
+ xhr: userProvidedXHR
105
+ } = uploadOptions || {};
106
+ delete uploadOptions.xhr;
107
+ const xhr = userProvidedXHR || new XMLHttpRequest();
108
+ if (!uploadOptions.file) {
109
+ return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_UPLOAD_FILE_PARAMETER.message));
110
+ }
111
+ if (!uploadOptions.fileName) {
112
+ return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_UPLOAD_FILENAME_PARAMETER.message));
113
+ }
114
+ if (!uploadOptions.publicKey || uploadOptions.publicKey.length === 0) {
115
+ return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_PUBLIC_KEY.message));
116
+ }
117
+ if (!uploadOptions.token) {
118
+ return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_TOKEN.message));
119
+ }
120
+ if (!uploadOptions.signature) {
121
+ return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_SIGNATURE.message));
122
+ }
123
+ if (!uploadOptions.expire) {
124
+ return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_EXPIRE.message));
125
+ }
126
+ if (uploadOptions.transformation) {
127
+ if (!(Object.keys(uploadOptions.transformation).includes("pre") || Object.keys(uploadOptions.transformation).includes("post"))) {
128
+ return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_TRANSFORMATION.message));
129
+ }
130
+ if (Object.keys(uploadOptions.transformation).includes("pre") && !uploadOptions.transformation.pre) {
131
+ return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_PRE_TRANSFORMATION.message));
132
+ }
133
+ if (Object.keys(uploadOptions.transformation).includes("post")) {
134
+ if (Array.isArray(uploadOptions.transformation.post)) {
135
+ for (let transformation of uploadOptions.transformation.post) {
136
+ if (transformation.type === "abs" && !(transformation.protocol || transformation.value)) {
137
+ return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_POST_TRANSFORMATION.message));
138
+ } else if (transformation.type === "transformation" && !transformation.value) {
139
+ return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_POST_TRANSFORMATION.message));
140
+ }
141
+ }
142
+ } else {
143
+ return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_POST_TRANSFORMATION.message));
144
+ }
145
+ }
146
+ }
147
+ var formData = new FormData();
148
+ let key;
149
+ for (key in uploadOptions) {
150
+ if (key) {
151
+ if (key === "file" && typeof uploadOptions.file != "string") {
152
+ formData.append('file', uploadOptions.file, String(uploadOptions.fileName));
153
+ } else if (key === "tags" && Array.isArray(uploadOptions.tags)) {
154
+ formData.append('tags', uploadOptions.tags.join(","));
155
+ } else if (key === 'signature') {
156
+ formData.append("signature", uploadOptions.signature);
157
+ } else if (key === 'expire') {
158
+ formData.append("expire", String(uploadOptions.expire));
159
+ } else if (key === 'token') {
160
+ formData.append("token", uploadOptions.token);
161
+ } else if (key === "responseFields" && Array.isArray(uploadOptions.responseFields)) {
162
+ formData.append('responseFields', uploadOptions.responseFields.join(","));
163
+ } else if (key === "extensions" && Array.isArray(uploadOptions.extensions)) {
164
+ formData.append('extensions', JSON.stringify(uploadOptions.extensions));
165
+ } else if (key === "customMetadata" && typeof uploadOptions.customMetadata === "object" && !Array.isArray(uploadOptions.customMetadata) && uploadOptions.customMetadata !== null) {
166
+ formData.append('customMetadata', JSON.stringify(uploadOptions.customMetadata));
167
+ } else if (key === "transformation" && typeof uploadOptions.transformation === "object" && uploadOptions.transformation !== null) {
168
+ formData.append(key, JSON.stringify(uploadOptions.transformation));
169
+ } else if (key === 'checks' && uploadOptions.checks) {
170
+ formData.append("checks", uploadOptions.checks);
171
+ } else if (uploadOptions[key] !== undefined) {
172
+ if (["onProgress", "abortSignal"].includes(key)) continue;
173
+ formData.append(key, String(uploadOptions[key]));
174
+ }
175
+ }
176
+ }
177
+ formData.append("publicKey", uploadOptions.publicKey);
178
+ if (uploadOptions.onProgress) {
179
+ xhr.upload.onprogress = function (event) {
180
+ if (uploadOptions.onProgress) uploadOptions.onProgress(event);
181
+ };
182
+ }
183
+ function onAbortHandler() {
184
+ var _uploadOptions$abortS;
185
+ xhr.abort();
186
+ return reject(new ImageKitAbortError("Upload aborted", (_uploadOptions$abortS = uploadOptions.abortSignal) === null || _uploadOptions$abortS === void 0 ? void 0 : _uploadOptions$abortS.reason));
187
+ }
188
+ if (uploadOptions.abortSignal) {
189
+ if (uploadOptions.abortSignal.aborted) {
190
+ var _uploadOptions$abortS2;
191
+ return reject(new ImageKitAbortError("Upload aborted", (_uploadOptions$abortS2 = uploadOptions.abortSignal) === null || _uploadOptions$abortS2 === void 0 ? void 0 : _uploadOptions$abortS2.reason));
192
+ }
193
+ uploadOptions.abortSignal.addEventListener("abort", onAbortHandler);
194
+ xhr.addEventListener("loadend", () => {
195
+ if (uploadOptions.abortSignal) {
196
+ uploadOptions.abortSignal.removeEventListener("abort", onAbortHandler);
197
+ }
198
+ });
199
+ }
200
+ xhr.open('POST', 'https://upload.imagekit.io/api/v1/files/upload');
201
+ xhr.onerror = function (e) {
202
+ return reject(new ImageKitUploadNetworkError(errorMessages.UPLOAD_ENDPOINT_NETWORK_ERROR.message));
203
+ };
204
+ xhr.onload = function () {
205
+ if (xhr.status >= 200 && xhr.status < 300) {
206
+ try {
207
+ var body = JSON.parse(xhr.responseText);
208
+ var uploadResponse = addResponseHeadersAndBody(body, xhr);
209
+ return resolve(uploadResponse);
210
+ } catch (ex) {
211
+ return reject(ex);
212
+ }
213
+ } else if (xhr.status >= 400 && xhr.status < 500) {
214
+ try {
215
+ var body = JSON.parse(xhr.responseText);
216
+ return reject(new ImageKitInvalidRequestError(body.message ?? "Invalid request. Please check the parameters.", getResponseMetadata(xhr)));
217
+ } catch (ex) {
218
+ return reject(ex);
219
+ }
220
+ } else {
221
+ try {
222
+ var body = JSON.parse(xhr.responseText);
223
+ return reject(new ImageKitServerError(body.message ?? "Server error occurred while uploading the file. This is rare and usually temporary.", getResponseMetadata(xhr)));
224
+ } catch (ex) {
225
+ return reject(new ImageKitServerError("Server error occurred while uploading the file. This is rare and usually temporary.", getResponseMetadata(xhr)));
226
+ }
227
+ }
228
+ };
229
+ xhr.send(formData);
230
+ });
231
+ };
232
+ const addResponseHeadersAndBody = (body, xhr) => {
233
+ let response = {
234
+ ...body
235
+ };
236
+ const responseMetadata = getResponseMetadata(xhr);
237
+ Object.defineProperty(response, "$ResponseMetadata", {
238
+ value: responseMetadata,
239
+ enumerable: false,
240
+ writable: false
241
+ });
242
+ return response;
243
+ };
244
+ const getResponseMetadata = xhr => {
245
+ const headers = getResponseHeaderMap(xhr);
246
+ const responseMetadata = {
247
+ statusCode: xhr.status,
248
+ headers: headers,
249
+ requestId: headers["x-request-id"]
250
+ };
251
+ return responseMetadata;
252
+ };
253
+ function getResponseHeaderMap(xhr) {
254
+ const headers = {};
255
+ const responseHeaders = xhr.getAllResponseHeaders();
256
+ if (Object.keys(responseHeaders).length) {
257
+ responseHeaders.trim().split(/[\r\n]+/).map(value => value.split(/: /)).forEach(keyValue => {
258
+ headers[keyValue[0].trim().toLowerCase()] = keyValue[1].trim();
259
+ });
260
+ }
261
+ return headers;
262
+ }
263
+
264
+ const supportedTransforms = {
265
+ width: "w",
266
+ height: "h",
267
+ aspectRatio: "ar",
268
+ background: "bg",
269
+ border: "b",
270
+ crop: "c",
271
+ cropMode: "cm",
272
+ dpr: "dpr",
273
+ focus: "fo",
274
+ quality: "q",
275
+ x: "x",
276
+ xCenter: "xc",
277
+ y: "y",
278
+ yCenter: "yc",
279
+ format: "f",
280
+ videoCodec: "vc",
281
+ audioCodec: "ac",
282
+ radius: "r",
283
+ rotation: "rt",
284
+ blur: "bl",
285
+ named: "n",
286
+ defaultImage: "di",
287
+ flip: "fl",
288
+ original: "orig",
289
+ startOffset: "so",
290
+ endOffset: "eo",
291
+ duration: "du",
292
+ streamingResolutions: "sr",
293
+ grayscale: "e-grayscale",
294
+ aiUpscale: "e-upscale",
295
+ aiRetouch: "e-retouch",
296
+ aiVariation: "e-genvar",
297
+ aiDropShadow: "e-dropshadow",
298
+ aiChangeBackground: "e-changebg",
299
+ aiRemoveBackground: "e-bgremove",
300
+ aiRemoveBackgroundExternal: "e-removedotbg",
301
+ contrastStretch: "e-contrast",
302
+ shadow: "e-shadow",
303
+ sharpen: "e-sharpen",
304
+ unsharpMask: "e-usm",
305
+ gradient: "e-gradient",
306
+ progressive: "pr",
307
+ lossless: "lo",
308
+ colorProfile: "cp",
309
+ metadata: "md",
310
+ opacity: "o",
311
+ trim: "t",
312
+ zoom: "z",
313
+ page: "pg",
314
+ fontSize: "fs",
315
+ fontFamily: "ff",
316
+ fontColor: "co",
317
+ innerAlignment: "ia",
318
+ padding: "pa",
319
+ alpha: "al",
320
+ typography: "tg",
321
+ lineHeight: "lh",
322
+ fontOutline: "fol",
323
+ fontShadow: "fsh",
324
+ raw: "raw"
325
+ };
326
+
327
+ const QUERY_TRANSFORMATION_POSITION = "query";
328
+ const CHAIN_TRANSFORM_DELIMITER = ":";
329
+ const TRANSFORM_DELIMITER = ",";
330
+ const TRANSFORM_KEY_VALUE_DELIMITER = "-";
331
+ var transformationUtils = {
332
+ addAsQueryParameter: options => {
333
+ return options.transformationPosition === QUERY_TRANSFORMATION_POSITION;
334
+ },
335
+ getTransformKey: function (transform) {
336
+ if (!transform) {
337
+ return "";
338
+ }
339
+ return supportedTransforms[transform] || supportedTransforms[transform.toLowerCase()] || "";
340
+ },
341
+ getChainTransformDelimiter: function () {
342
+ return CHAIN_TRANSFORM_DELIMITER;
343
+ },
344
+ getTransformDelimiter: function () {
345
+ return TRANSFORM_DELIMITER;
346
+ },
347
+ getTransformKeyValueDelimiter: function () {
348
+ return TRANSFORM_KEY_VALUE_DELIMITER;
349
+ }
350
+ };
351
+ const safeBtoa = function (str) {
352
+ if (typeof window !== "undefined") {
353
+ return btoa(str);
354
+ } else {
355
+ return Buffer.from(str, "utf8").toString("base64");
356
+ }
357
+ };
358
+
359
+ const TRANSFORMATION_PARAMETER = "tr";
360
+ const SIMPLE_OVERLAY_PATH_REGEX = new RegExp('^[a-zA-Z0-9-._/ ]*$');
361
+ const SIMPLE_OVERLAY_TEXT_REGEX = new RegExp('^[a-zA-Z0-9-._ ]*$');
362
+ function removeTrailingSlash(str) {
363
+ if (typeof str == "string" && str[str.length - 1] == "/") {
364
+ str = str.substring(0, str.length - 1);
365
+ }
366
+ return str;
367
+ }
368
+ function removeLeadingSlash(str) {
369
+ if (typeof str == "string" && str[0] == "/") {
370
+ str = str.slice(1);
371
+ }
372
+ return str;
373
+ }
374
+ function pathJoin(parts, sep) {
375
+ var separator = sep || "/";
376
+ var replace = new RegExp(separator + "{1,}", "g");
377
+ return parts.join(separator).replace(replace, separator);
378
+ }
379
+ const buildSrc = opts => {
380
+ opts.urlEndpoint = opts.urlEndpoint || "";
381
+ opts.src = opts.src || "";
382
+ opts.transformationPosition = opts.transformationPosition || "query";
383
+ if (!opts.src) {
384
+ return "";
385
+ }
386
+ const isAbsoluteURL = opts.src.startsWith("http://") || opts.src.startsWith("https://");
387
+ var urlObj, isSrcParameterUsedForURL, urlEndpointPattern;
388
+ try {
389
+ if (!isAbsoluteURL) {
390
+ urlEndpointPattern = new URL(opts.urlEndpoint).pathname;
391
+ urlObj = new URL(pathJoin([opts.urlEndpoint.replace(urlEndpointPattern, ""), opts.src]));
392
+ } else {
393
+ urlObj = new URL(opts.src);
394
+ isSrcParameterUsedForURL = true;
395
+ }
396
+ } catch (e) {
397
+ console.error(e);
398
+ return "";
399
+ }
400
+ for (var i in opts.queryParameters) {
401
+ urlObj.searchParams.append(i, String(opts.queryParameters[i]));
402
+ }
403
+ var transformationString = buildTransformationString(opts.transformation);
404
+ if (transformationString && transformationString.length) {
405
+ if (!transformationUtils.addAsQueryParameter(opts) && !isSrcParameterUsedForURL) {
406
+ urlObj.pathname = pathJoin([TRANSFORMATION_PARAMETER + transformationUtils.getChainTransformDelimiter() + transformationString, urlObj.pathname]);
407
+ }
408
+ }
409
+ if (urlEndpointPattern) {
410
+ urlObj.pathname = pathJoin([urlEndpointPattern, urlObj.pathname]);
411
+ } else {
412
+ urlObj.pathname = pathJoin([urlObj.pathname]);
413
+ }
414
+ if (transformationString && transformationString.length) {
415
+ if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
416
+ if (urlObj.searchParams.toString() !== "") {
417
+ return `${urlObj.href}&${TRANSFORMATION_PARAMETER}=${transformationString}`;
418
+ } else {
419
+ return `${urlObj.href}?${TRANSFORMATION_PARAMETER}=${transformationString}`;
420
+ }
421
+ }
422
+ }
423
+ return urlObj.href;
424
+ };
425
+ function processInputPath(str, enccoding) {
426
+ str = removeTrailingSlash(removeLeadingSlash(str));
427
+ if (enccoding === "plain") {
428
+ return `i-${str.replace(/\//g, "@@")}`;
429
+ }
430
+ if (enccoding === "base64") {
431
+ return `ie-${encodeURIComponent(safeBtoa(str))}`;
432
+ }
433
+ if (SIMPLE_OVERLAY_PATH_REGEX.test(str)) {
434
+ return `i-${str.replace(/\//g, "@@")}`;
435
+ } else {
436
+ return `ie-${encodeURIComponent(safeBtoa(str))}`;
437
+ }
438
+ }
439
+ function processText(str, enccoding) {
440
+ if (enccoding === "plain") {
441
+ return `i-${encodeURIComponent(str)}`;
442
+ }
443
+ if (enccoding === "base64") {
444
+ return `ie-${encodeURIComponent(safeBtoa(str))}`;
445
+ }
446
+ if (SIMPLE_OVERLAY_TEXT_REGEX.test(str)) {
447
+ return `i-${encodeURIComponent(str)}`;
448
+ }
449
+ return `ie-${encodeURIComponent(safeBtoa(str))}`;
450
+ }
451
+ function processOverlay(overlay) {
452
+ const entries = [];
453
+ const {
454
+ type,
455
+ position = {},
456
+ timing = {},
457
+ transformation = []
458
+ } = overlay || {};
459
+ if (!type) {
460
+ return;
461
+ }
462
+ switch (type) {
463
+ case "text":
464
+ {
465
+ const textOverlay = overlay;
466
+ if (!textOverlay.text) {
467
+ return;
468
+ }
469
+ const enccoding = textOverlay.encoding || "auto";
470
+ entries.push("l-text");
471
+ entries.push(processText(textOverlay.text, enccoding));
472
+ }
473
+ break;
474
+ case "image":
475
+ entries.push("l-image");
476
+ {
477
+ const imageOverlay = overlay;
478
+ const enccoding = imageOverlay.encoding || "auto";
479
+ if (imageOverlay.input) {
480
+ entries.push(processInputPath(imageOverlay.input, enccoding));
481
+ } else {
482
+ return;
483
+ }
484
+ }
485
+ break;
486
+ case "video":
487
+ entries.push("l-video");
488
+ {
489
+ const videoOverlay = overlay;
490
+ const enccoding = videoOverlay.encoding || "auto";
491
+ if (videoOverlay.input) {
492
+ entries.push(processInputPath(videoOverlay.input, enccoding));
493
+ } else {
494
+ return;
495
+ }
496
+ }
497
+ break;
498
+ case "subtitle":
499
+ entries.push("l-subtitle");
500
+ {
501
+ const subtitleOverlay = overlay;
502
+ const enccoding = subtitleOverlay.encoding || "auto";
503
+ if (subtitleOverlay.input) {
504
+ entries.push(processInputPath(subtitleOverlay.input, enccoding));
505
+ } else {
506
+ return;
507
+ }
508
+ }
509
+ break;
510
+ case "solidColor":
511
+ entries.push("l-image");
512
+ entries.push(`i-ik_canvas`);
513
+ {
514
+ const solidColorOverlay = overlay;
515
+ if (solidColorOverlay.color) {
516
+ entries.push(`bg-${solidColorOverlay.color}`);
517
+ } else {
518
+ return;
519
+ }
520
+ }
521
+ break;
522
+ }
523
+ const {
524
+ x,
525
+ y,
526
+ focus
527
+ } = position;
528
+ if (x) {
529
+ entries.push(`lx-${x}`);
530
+ }
531
+ if (y) {
532
+ entries.push(`ly-${y}`);
533
+ }
534
+ if (focus) {
535
+ entries.push(`lfo-${focus}`);
536
+ }
537
+ const {
538
+ start,
539
+ end,
540
+ duration
541
+ } = timing;
542
+ if (start) {
543
+ entries.push(`lso-${start}`);
544
+ }
545
+ if (end) {
546
+ entries.push(`leo-${end}`);
547
+ }
548
+ if (duration) {
549
+ entries.push(`ldu-${duration}`);
550
+ }
551
+ const transformationString = buildTransformationString(transformation);
552
+ if (transformationString && transformationString.trim() !== "") entries.push(transformationString);
553
+ entries.push("l-end");
554
+ return entries.join(transformationUtils.getTransformDelimiter());
555
+ }
556
+ const buildTransformationString = function (transformation) {
557
+ if (!Array.isArray(transformation)) {
558
+ return "";
559
+ }
560
+ var parsedTransforms = [];
561
+ for (var i = 0, l = transformation.length; i < l; i++) {
562
+ var parsedTransformStep = [];
563
+ for (var key in transformation[i]) {
564
+ let value = transformation[i][key];
565
+ if (value === undefined || value === null) {
566
+ continue;
567
+ }
568
+ if (key === "overlay" && typeof value === "object") {
569
+ var rawString = processOverlay(value);
570
+ if (rawString && rawString.trim() !== "") {
571
+ parsedTransformStep.push(rawString);
572
+ }
573
+ continue;
574
+ }
575
+ var transformKey = transformationUtils.getTransformKey(key);
576
+ if (!transformKey) {
577
+ transformKey = key;
578
+ }
579
+ if (transformKey === "") {
580
+ continue;
581
+ }
582
+ if (["e-grayscale", "e-contrast", "e-removedotbg", "e-bgremove", "e-upscale", "e-retouch", "e-genvar"].includes(transformKey)) {
583
+ if (value === true || value === "-" || value === "true") {
584
+ parsedTransformStep.push(transformKey);
585
+ } else {
586
+ continue;
587
+ }
588
+ } else if (["e-sharpen", "e-shadow", "e-gradient", "e-usm", "e-dropshadow"].includes(transformKey) && (value.toString().trim() === "" || value === true || value === "true")) {
589
+ parsedTransformStep.push(transformKey);
590
+ } else if (key === "raw") {
591
+ parsedTransformStep.push(transformation[i][key]);
592
+ } else {
593
+ if (transformKey === "di") {
594
+ value = removeTrailingSlash(removeLeadingSlash(value || ""));
595
+ value = value.replace(/\//g, "@@");
596
+ }
597
+ if (transformKey === "sr" && Array.isArray(value)) {
598
+ value = value.join("_");
599
+ }
600
+ if (transformKey === "t" && value.toString().trim() === "") {
601
+ value = "true";
602
+ }
603
+ parsedTransformStep.push([transformKey, value].join(transformationUtils.getTransformKeyValueDelimiter()));
604
+ }
605
+ }
606
+ if (parsedTransformStep.length) {
607
+ parsedTransforms.push(parsedTransformStep.join(transformationUtils.getTransformDelimiter()));
608
+ }
609
+ }
610
+ return parsedTransforms.join(transformationUtils.getChainTransformDelimiter());
611
+ };
612
+
613
+ exports.ImageKitAbortError = ImageKitAbortError;
614
+ exports.ImageKitInvalidRequestError = ImageKitInvalidRequestError;
615
+ exports.ImageKitServerError = ImageKitServerError;
616
+ exports.ImageKitUploadNetworkError = ImageKitUploadNetworkError;
617
+ exports.buildSrc = buildSrc;
618
+ exports.buildTransformationString = buildTransformationString;
619
+ exports.upload = upload;