@lonik/oh-image 2.6.0 → 2.7.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.
@@ -1,76 +1,883 @@
1
- import { t as loaderFactory } from "./loader-factory-6EOKnqj1.js";
1
+ import { createContext, useContext } from "react";
2
+ import { jsx } from "react/jsx-runtime";
2
3
 
4
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/qualifier/QualifierValue.js
5
+ /**
6
+ * @summary SDK
7
+ * @memberOf SDK
8
+ */
9
+ var QualifierValue = class {
10
+ /**
11
+ *
12
+ * @param {QualifierValue | QualifierValue[] | any[] | string | number}qualifierValue
13
+ */
14
+ constructor(qualifierValue) {
15
+ this.values = [];
16
+ this.delimiter = ":";
17
+ if (this.hasValue(qualifierValue)) this.addValue(qualifierValue);
18
+ }
19
+ /**
20
+ * @description Joins the provided values with the provided delimiter
21
+ */
22
+ toString() {
23
+ return this.values.join(this.delimiter);
24
+ }
25
+ /**
26
+ * @description Checks if the provided argument has a value
27
+ * @param {any} v
28
+ * @private
29
+ * @return {boolean}
30
+ */
31
+ hasValue(v) {
32
+ return typeof v !== "undefined" && v !== null && v !== "";
33
+ }
34
+ /**
35
+ * @desc Adds a value for the this qualifier instance
36
+ * @param {any} value
37
+ * @return {this}
38
+ */
39
+ addValue(value) {
40
+ if (Array.isArray(value)) this.values = this.values.concat(value);
41
+ else this.values.push(value);
42
+ this.values = this.values.filter((v) => this.hasValue(v));
43
+ return this;
44
+ }
45
+ /**
46
+ * @description Sets the delimiter for this instance
47
+ * @param delimiter
48
+ */
49
+ setDelimiter(delimiter) {
50
+ this.delimiter = delimiter;
51
+ return this;
52
+ }
53
+ };
54
+
55
+ //#endregion
56
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/utils/unsupportedError.js
57
+ var UnsupportedError = class extends Error {
58
+ constructor(message = "Unsupported") {
59
+ super(message);
60
+ }
61
+ };
62
+ /**
63
+ * Creates a new UnsupportedError
64
+ * @param message
65
+ */
66
+ function createUnsupportedError(message) {
67
+ return new UnsupportedError(message);
68
+ }
69
+
70
+ //#endregion
71
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/models/qualifierToJson.js
72
+ /**
73
+ * Returns the action's model
74
+ */
75
+ function qualifierToJson() {
76
+ return this._qualifierModel || { error: createUnsupportedError(`unsupported qualifier ${this.constructor.name}`) };
77
+ }
78
+
79
+ //#endregion
80
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/models/QualifierModel.js
81
+ var QualifierModel = class {
82
+ constructor() {
83
+ this._qualifierModel = {};
84
+ }
85
+ toJson() {
86
+ return qualifierToJson.apply(this);
87
+ }
88
+ };
89
+
90
+ //#endregion
91
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/qualifier/Qualifier.js
92
+ /**
93
+ * @summary SDK
94
+ * @memberOf SDK
95
+ */
96
+ var Qualifier = class extends QualifierModel {
97
+ constructor(key, qualifierValue) {
98
+ super();
99
+ this.delimiter = "_";
100
+ this.key = key;
101
+ if (qualifierValue instanceof QualifierValue) this.qualifierValue = qualifierValue;
102
+ else {
103
+ this.qualifierValue = new QualifierValue();
104
+ this.qualifierValue.addValue(qualifierValue);
105
+ }
106
+ }
107
+ toString() {
108
+ const { key, delimiter, qualifierValue } = this;
109
+ return `${key}${delimiter}${qualifierValue.toString()}`;
110
+ }
111
+ addValue(value) {
112
+ this.qualifierValue.addValue(value);
113
+ return this;
114
+ }
115
+ };
116
+
117
+ //#endregion
118
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/flag/FlagQualifier.js
119
+ /**
120
+ * @memberOf Qualifiers.Flag
121
+ * @extends {SDK.Qualifier}
122
+ * @description the FlagQualifier class
123
+ */
124
+ var FlagQualifier = class extends Qualifier {
125
+ constructor(flagType, flagValue) {
126
+ let qualifierValue;
127
+ if (flagValue) qualifierValue = new QualifierValue([flagType, `${flagValue}`]).setDelimiter(":");
128
+ else qualifierValue = flagType;
129
+ super("fl", qualifierValue);
130
+ this.flagValue = flagValue;
131
+ }
132
+ toString() {
133
+ return super.toString().replace(/\./g, "%2E");
134
+ }
135
+ getFlagValue() {
136
+ return this.flagValue;
137
+ }
138
+ };
139
+
140
+ //#endregion
141
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/utils/dataStructureUtils.js
142
+ /**
143
+ * Sort a map by key
144
+ * @private
145
+ * @param map <string, any>
146
+ * @Return array of map's values sorted by key
147
+ */
148
+ function mapToSortedArray(map, flags) {
149
+ const array = Array.from(map.entries());
150
+ flags.forEach((flag) => {
151
+ array.push(["fl", flag]);
152
+ });
153
+ return array.sort().map((v) => v[1]);
154
+ }
155
+
156
+ //#endregion
157
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/models/actionToJson.js
158
+ /**
159
+ * Returns the action's model
160
+ */
161
+ function actionToJson() {
162
+ var _a, _b, _c;
163
+ const actionModelIsNotEmpty = this._actionModel && Object.keys(this._actionModel).length;
164
+ const sourceTransformationError = (_c = (_b = (_a = this._actionModel) === null || _a === void 0 ? void 0 : _a.source) === null || _b === void 0 ? void 0 : _b.transformation) === null || _c === void 0 ? void 0 : _c.error;
165
+ if (sourceTransformationError && sourceTransformationError instanceof Error) return { error: sourceTransformationError };
166
+ if (actionModelIsNotEmpty) return this._actionModel;
167
+ return { error: createUnsupportedError(`unsupported action ${this.constructor.name}`) };
168
+ }
169
+
170
+ //#endregion
171
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/models/ActionModel.js
172
+ var ActionModel = class {
173
+ constructor() {
174
+ this._actionModel = {};
175
+ }
176
+ toJson() {
177
+ return actionToJson.apply(this);
178
+ }
179
+ };
180
+
181
+ //#endregion
182
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/Action.js
183
+ /**
184
+ * @summary SDK
185
+ * @memberOf SDK
186
+ * @description Defines the category of transformation to perform.
187
+ */
188
+ var Action = class extends ActionModel {
189
+ constructor() {
190
+ super(...arguments);
191
+ this.qualifiers = /* @__PURE__ */ new Map();
192
+ this.flags = [];
193
+ this.delimiter = ",";
194
+ this.actionTag = "";
195
+ }
196
+ prepareQualifiers() {}
197
+ /**
198
+ * @description Returns the custom name tag that was given to this action
199
+ * @return {string}
200
+ */
201
+ getActionTag() {
202
+ return this.actionTag;
203
+ }
204
+ /**
205
+ * @description Sets the custom name tag for this action
206
+ * @return {this}
207
+ */
208
+ setActionTag(tag) {
209
+ this.actionTag = tag;
210
+ return this;
211
+ }
212
+ /**
213
+ * @description Calls toString() on all child qualifiers (implicitly by using .join()).
214
+ * @return {string}
215
+ */
216
+ toString() {
217
+ this.prepareQualifiers();
218
+ return mapToSortedArray(this.qualifiers, this.flags).join(this.delimiter);
219
+ }
220
+ /**
221
+ * @description Adds the parameter to the action.
222
+ * @param {SDK.Qualifier} qualifier
223
+ * @return {this}
224
+ */
225
+ addQualifier(qualifier) {
226
+ if (typeof qualifier === "string") {
227
+ const [key, value] = qualifier.toLowerCase().split("_");
228
+ if (key === "fl") this.flags.push(new FlagQualifier(value));
229
+ else this.qualifiers.set(key, new Qualifier(key, value));
230
+ } else this.qualifiers.set(qualifier.key, qualifier);
231
+ return this;
232
+ }
233
+ /**
234
+ * @description Adds a flag to the current action.
235
+ * @param {Qualifiers.Flag} flag
236
+ * @return {this}
237
+ */
238
+ addFlag(flag) {
239
+ if (typeof flag === "string") this.flags.push(new FlagQualifier(flag));
240
+ else if (flag instanceof FlagQualifier) this.flags.push(flag);
241
+ return this;
242
+ }
243
+ addValueToQualifier(qualifierKey, qualifierValue) {
244
+ this.qualifiers.get(qualifierKey).addValue(qualifierValue);
245
+ return this;
246
+ }
247
+ };
248
+
249
+ //#endregion
250
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/utils/toFloatAsString.js
251
+ /**
252
+ * @description
253
+ * Returns a string representing the float value of the input, if the input was a number-like.
254
+ * Examples:
255
+ * - '1.0' -> '1.0'
256
+ * - 1 -> '1.0'
257
+ * - '5' -> '5.0'
258
+ * - 'auto' -> 'auto'
259
+ * @private
260
+ * @param {string|number} value
261
+ * @return {string}
262
+ */
263
+ function toFloatAsString(value) {
264
+ const returnValue = value.toString();
265
+ if (returnValue.match(/[A-Z]/gi)) return returnValue;
266
+ if (returnValue.length > 1 && returnValue[0] === "0") return returnValue;
267
+ if (!isNaN(parseFloat(returnValue)) && returnValue.indexOf(":") === -1 && returnValue.indexOf(".") === -1) return `${returnValue}.0`;
268
+ else return returnValue;
269
+ }
270
+
271
+ //#endregion
272
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/aspectRatio/AspectRatioQualifierValue.js
273
+ /**
274
+ * @memberOf Qualifiers.AspectRatio
275
+ * @extends {SDK.QualifierValue}
276
+ */
277
+ var AspectRatioQualifierValue = class extends QualifierValue {};
278
+
279
+ //#endregion
280
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/flag.js
281
+ /**
282
+ * @description Defines flags that you can use to alter the default transformation behavior.
283
+ * @namespace Flag
284
+ * @memberOf Qualifiers
285
+ */
286
+ /**
287
+ * @summary qualifier
288
+ * @memberOf Qualifiers.Flag
289
+ * @description * Allows specifying only either width or height so the value of the second axis remains as is, and is not
290
+ * recalculated to maintain the aspect ratio of the original image.
291
+ * @return {Qualifiers.Flag.FlagQualifier}
292
+ */
293
+ function ignoreInitialAspectRatio() {
294
+ return new FlagQualifier("ignore_aspect_ratio");
295
+ }
296
+ /**
297
+ * @summary qualifier
298
+ * @memberOf Qualifiers.Flag
299
+ * @description Automatically use lossy compression when delivering animated GIF files.
300
+ *
301
+ * This flag can also be used as a conditional flag for delivering PNG files: it tells Cloudinary to deliver the
302
+ * image in PNG format (as requested) unless there is no transparency channel - in which case deliver in JPEG
303
+ * format.
304
+ * @return {Qualifiers.Flag.FlagQualifier}
305
+ */
306
+ function lossy() {
307
+ return new FlagQualifier("lossy");
308
+ }
309
+ /**
310
+ * @summary qualifier
311
+ * @memberOf Qualifiers.Flag
312
+ * @description When used with automatic fetch_format (f_auto): ensures that images with a transparency channel will be
313
+ * delivered in PNG format.
314
+ * @return {Qualifiers.Flag.FlagQualifier}
315
+ */
316
+ function preserveTransparency() {
317
+ return new FlagQualifier("preserve_transparency");
318
+ }
319
+ /**
320
+ * @summary qualifier
321
+ * @memberOf Qualifiers.Flag
322
+ * @description Generates a JPG image using the progressive (interlaced) JPG format.
323
+ *
324
+ * This format allows the browser to quickly show a low-quality rendering of the image until the full-quality
325
+ * image is loaded.
326
+ *
327
+ * @param {string} mode? The mode to determine a specific progressive outcome as follows:
328
+ * * semi - A smart optimization of the decoding time, compression level and progressive rendering
329
+ * (less iterations). This is the default mode when using q_auto.
330
+ * * steep - Delivers a preview very quickly, and in a single later phase improves the image to
331
+ * the required resolution.
332
+ * * none - Use this to deliver a non-progressive image. This is the default mode when setting
333
+ * a specific value for quality.
334
+ * @return {Qualifiers.Flag.FlagQualifier}
335
+ */
336
+ function progressive(mode) {
337
+ return new FlagQualifier("progressive", mode);
338
+ }
339
+ /**
340
+ * @summary qualifier
341
+ * @memberOf Qualifiers.Flag
342
+ * @description Modifies percentage-based width & height parameters of overlays and underlays (e.g., 1.0) to be relative to the overlaid region
343
+ * @return {Qualifiers.Flag.FlagQualifier}
344
+ */
345
+ function regionRelative() {
346
+ return new FlagQualifier("region_relative");
347
+ }
348
+ /**
349
+ * @summary qualifier
350
+ * @memberOf Qualifiers.Flag
351
+ * @description Modifies percentage-based width & height parameters of overlays and underlays (e.g., 1.0) to be relative to the containing image instead of the added layer.
352
+ * @return {Qualifiers.Flag.FlagQualifier}
353
+ */
354
+ function relative() {
355
+ return new FlagQualifier("relative");
356
+ }
357
+
358
+ //#endregion
359
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/utils/objectFlip.js
360
+ /**
361
+ * Flip keys and values for given object
362
+ * @param obj
363
+ */
364
+ function objectFlip(obj) {
365
+ const result = {};
366
+ Object.keys(obj).forEach((key) => {
367
+ result[obj[key]] = key;
368
+ });
369
+ return result;
370
+ }
371
+
372
+ //#endregion
373
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/internal/internalConstants.js
374
+ /**
375
+ * This file is for internal constants only.
376
+ * It is not intended for public use and is not part of the public API
377
+ */
378
+ const ACTION_TYPE_TO_CROP_MODE_MAP = {
379
+ limitFit: "limit",
380
+ limitFill: "lfill",
381
+ minimumFit: "mfit",
382
+ thumbnail: "thumb",
383
+ limitPad: "lpad",
384
+ minimumPad: "mpad",
385
+ autoPad: "auto_pad"
386
+ };
387
+ const ACTION_TYPE_TO_DELIVERY_MODE_MAP = {
388
+ colorSpace: "cs",
389
+ dpr: "dpr",
390
+ density: "dn",
391
+ defaultImage: "d",
392
+ format: "f",
393
+ quality: "q"
394
+ };
395
+ const ACTION_TYPE_TO_EFFECT_MODE_MAP = {
396
+ redEye: "redeye",
397
+ advancedRedEye: "adv_redeye",
398
+ oilPaint: "oil_paint",
399
+ unsharpMask: "unsharp_mask",
400
+ makeTransparent: "make_transparent",
401
+ generativeRestore: "gen_restore",
402
+ upscale: "upscale"
403
+ };
404
+ const ACTION_TYPE_TO_QUALITY_MODE_MAP = {
405
+ autoBest: "auto:best",
406
+ autoEco: "auto:eco",
407
+ autoGood: "auto:good",
408
+ autoLow: "auto:low",
409
+ jpegminiHigh: "jpegmini:1",
410
+ jpegminiMedium: "jpegmini:2",
411
+ jpegminiBest: "jpegmini:0"
412
+ };
413
+ const ACTION_TYPE_TO_STREAMING_PROFILE_MODE_MAP = {
414
+ fullHd: "full_hd",
415
+ fullHdWifi: "full_hd_wifi",
416
+ fullHdLean: "full_hd_lean",
417
+ hdLean: "hd_lean"
418
+ };
419
+ const CHROMA_VALUE_TO_CHROMA_MODEL_ENUM = {
420
+ 444: "CHROMA_444",
421
+ 420: "CHROMA_420"
422
+ };
423
+ const COLOR_SPACE_MODEL_MODE_TO_COLOR_SPACE_MODE_MAP = {
424
+ "noCmyk": "no_cmyk",
425
+ "keepCmyk": "keep_cmyk",
426
+ "tinySrgb": "tinysrgb",
427
+ "srgbTrueColor": "srgb:truecolor"
428
+ };
429
+ const CHROMA_MODEL_ENUM_TO_CHROMA_VALUE = objectFlip(CHROMA_VALUE_TO_CHROMA_MODEL_ENUM);
430
+ const COLOR_SPACE_MODE_TO_COLOR_SPACE_MODEL_MODE_MAP = objectFlip(COLOR_SPACE_MODEL_MODE_TO_COLOR_SPACE_MODE_MAP);
431
+ const CROP_MODE_TO_ACTION_TYPE_MAP = objectFlip(ACTION_TYPE_TO_CROP_MODE_MAP);
432
+ const DELIVERY_MODE_TO_ACTION_TYPE_MAP = objectFlip(ACTION_TYPE_TO_DELIVERY_MODE_MAP);
433
+ const EFFECT_MODE_TO_ACTION_TYPE_MAP = objectFlip(ACTION_TYPE_TO_EFFECT_MODE_MAP);
434
+ const QUALITY_MODE_TO_ACTION_TYPE_MAP = objectFlip(ACTION_TYPE_TO_QUALITY_MODE_MAP);
435
+ const STREAMING_PROFILE_TO_ACTION_TYPE_MAP = objectFlip(ACTION_TYPE_TO_STREAMING_PROFILE_MODE_MAP);
436
+
437
+ //#endregion
438
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/resize/ResizeSimpleAction.js
439
+ /**
440
+ * @description Defines a resize using width and height.
441
+ * @extends SDK.Action
442
+ * @memberOf Actions.Resize
443
+ * @see Visit {@link Actions.Resize| Resize} for examples
444
+ */
445
+ var ResizeSimpleAction = class extends Action {
446
+ /**
447
+ * @param {string} cropType
448
+ * @param {number | string} cropWidth The required width of a transformed asset.
449
+ * @param {number | string} cropHeight The required height of a transformed asset.
450
+ */
451
+ constructor(cropType, cropWidth, cropHeight) {
452
+ super();
453
+ this._actionModel = { dimensions: {} };
454
+ this._actionModel.actionType = CROP_MODE_TO_ACTION_TYPE_MAP[cropType] || cropType;
455
+ this.addQualifier(new Qualifier("c", cropType));
456
+ cropWidth && this.width(cropWidth);
457
+ cropHeight && this.height(cropHeight);
458
+ }
459
+ /**
460
+ * @description Sets the height of the resize
461
+ * @param {string | number} x The height in pixels (if an integer is specified) or as a percentage (if a float is specified).
462
+ */
463
+ height(x) {
464
+ this._actionModel.dimensions.height = x;
465
+ return this.addQualifier(new Qualifier("h", x));
466
+ }
467
+ /**
468
+ * @description Sets the width of the resize
469
+ * @param {string | number} x The width in pixels (if an integer is specified) or as a percentage (if a float is specified).
470
+ */
471
+ width(x) {
472
+ this._actionModel.dimensions.width = x;
473
+ return this.addQualifier(new Qualifier("w", x));
474
+ }
475
+ /**
476
+ * @description Sets the aspect ratio of the asset.
477
+ * For a list of supported types see {@link Qualifiers.AspectRatio|
478
+ * AspectRatio values}
479
+ * @param {AspectRatioType|number|string} ratio The new aspect ratio, specified as a percentage or ratio.
480
+ * @return {this}
481
+ */
482
+ aspectRatio(ratio) {
483
+ if (ratio instanceof AspectRatioQualifierValue) {
484
+ this._actionModel.dimensions.aspectRatio = `${ratio}`;
485
+ return this.addQualifier(new Qualifier("ar", ratio));
486
+ }
487
+ if (typeof ratio === "number" || typeof ratio === "string") {
488
+ this._actionModel.dimensions.aspectRatio = toFloatAsString(ratio);
489
+ return this.addQualifier(new Qualifier("ar", toFloatAsString(ratio)));
490
+ }
491
+ if (ratio instanceof FlagQualifier) {
492
+ this._actionModel.dimensions.aspectRatio = `${ratio.qualifierValue}`;
493
+ return this.addFlag(ratio);
494
+ }
495
+ }
496
+ /**
497
+ * @description Modifies percentage-based width & height parameters of overlays and underlays (e.g., 1.0) to be relative to the containing image instead of the added layer.
498
+ * @return {this}
499
+ */
500
+ relative() {
501
+ this._actionModel.relative = true;
502
+ return this.addFlag(relative());
503
+ }
504
+ /**
505
+ * @description Modifies percentage-based width & height parameters of overlays and underlays (e.g., 1.0) to be relative to the overlaid region
506
+ * @return {this}
507
+ */
508
+ regionRelative() {
509
+ this._actionModel.regionRelative = true;
510
+ return this.addFlag(regionRelative());
511
+ }
512
+ static fromJson(actionModel) {
513
+ const { actionType, dimensions, relative: relative$1, regionRelative: regionRelative$1 } = actionModel;
514
+ const { aspectRatio, width, height } = dimensions;
515
+ const cropMode = ACTION_TYPE_TO_CROP_MODE_MAP[actionType] || actionType;
516
+ const result = new this(cropMode, width, height);
517
+ aspectRatio && result.aspectRatio(aspectRatio === "ignore_aspect_ratio" ? ignoreInitialAspectRatio() : aspectRatio);
518
+ relative$1 && result.relative();
519
+ regionRelative$1 && result.regionRelative();
520
+ return result;
521
+ }
522
+ };
523
+
524
+ //#endregion
525
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/gravity/GravityQualifier.js
526
+ /**
527
+ * @memberOf Gravity.GravityQualifier
528
+ * @extends {SDK.Qualifier}
529
+ */
530
+ var GravityQualifier = class extends Qualifier {
531
+ /**
532
+ * @param value, an array containing (GravityObject | AutoGravity | string) or a string;
533
+ */
534
+ constructor(value) {
535
+ super("g", new QualifierValue(value));
536
+ }
537
+ };
538
+
539
+ //#endregion
540
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/quality.js
541
+ /**
542
+ * @memberOf Qualifiers
543
+ * @namespace Quality
544
+ * @see Visit {@link Actions.Delivery.quality|Delivery Quality} for an example
545
+ */
546
+ /**
547
+ * @summary qualifier
548
+ * @description Quality auto
549
+ * @memberOf Qualifiers.Quality
550
+ * @return {string}
551
+ */
552
+ function auto$1() {
553
+ return "auto";
554
+ }
555
+
556
+ //#endregion
557
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/format/FormatQualifier.js
558
+ /**
559
+ * @memberOf Qualifiers.Format
560
+ * @extends {SDK.QualifierValue}
561
+ */
562
+ var FormatQualifier = class extends QualifierValue {
563
+ constructor(val) {
564
+ super(val);
565
+ this.val = val;
566
+ }
567
+ getValue() {
568
+ return this.val;
569
+ }
570
+ };
571
+
572
+ //#endregion
573
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/format.js
574
+ /**
575
+ * @summary qualifier
576
+ * @description Image format auto.
577
+ * @memberOf Qualifiers.Format
578
+ * @return {Qualifiers.Format.FormatQualifier}
579
+ */
580
+ function auto() {
581
+ return new FormatQualifier("auto");
582
+ }
583
+
584
+ //#endregion
585
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/resize/ResizeScaleAction.js
586
+ /**
587
+ * @description Defines a scaling resize action.
588
+ * @extends Actions.Resize.ResizeSimpleAction
589
+ * @memberOf Actions.Resize
590
+ * @see Visit {@link Actions.Resize| Resize} for examples
591
+ */
592
+ var ResizeScaleAction = class extends ResizeSimpleAction {
593
+ /**
594
+ * @description Changes the aspect ratio of an image while retaining all important content and avoiding unnatural
595
+ * distortions.
596
+ * @return {this}
597
+ */
598
+ liquidRescaling() {
599
+ return this.addQualifier(new GravityQualifier("liquid"));
600
+ }
601
+ };
602
+
603
+ //#endregion
604
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/resize.js
605
+ /**
606
+ * @summary action
607
+ * @description
608
+ * Changes the size of the image exactly to the given width and height without necessarily retaining the original aspect ratio:<br/>
609
+ * all original image parts are visible but might be stretched or shrunk.
610
+ * @memberOf Actions.Resize
611
+ * @param {number|string} width The required width of a transformed asset.
612
+ * @param {number|string} height The required height of a transformed asset.
613
+ * @return {Actions.Resize.ScaleAction}
614
+ */
615
+ function scale(width, height) {
616
+ return new ResizeScaleAction("scale", width, height);
617
+ }
618
+
619
+ //#endregion
620
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/delivery/DeliveryAction.js
621
+ /**
622
+ * @description Qualifies the delivery of an asset.
623
+ * @memberOf Actions.Delivery
624
+ * @extends SDK.Action
625
+ */
626
+ var DeliveryAction = class extends Action {
627
+ /**
628
+ * @param {string} deliveryKey A generic Delivery Action Key (such as q, f, dn, etc.)
629
+ * @param {string} deliveryType A Format Qualifiers for the action, such as Quality.auto()
630
+ * @param {string} modelProperty internal model property of the action, for example quality uses `level` while dpr uses `density`
631
+ * @see Visit {@link Actions.Delivery|Delivery} for an example
632
+ */
633
+ constructor(deliveryKey, deliveryType, modelProperty) {
634
+ super();
635
+ this._actionModel = {};
636
+ let deliveryTypeValue;
637
+ if (deliveryType instanceof FormatQualifier) deliveryTypeValue = deliveryType.getValue();
638
+ else deliveryTypeValue = deliveryType;
639
+ this._actionModel.actionType = DELIVERY_MODE_TO_ACTION_TYPE_MAP[deliveryKey];
640
+ this._actionModel[modelProperty] = deliveryTypeValue;
641
+ this.addQualifier(new Qualifier(deliveryKey, deliveryType));
642
+ }
643
+ };
644
+
645
+ //#endregion
646
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/qualifiers/progressive.js
647
+ /**
648
+ * @description Contains functions to select the mode when using a progressive format.
649
+ * <b>Learn more</b>: {@link https://cloudinary.com/documentation/transformation_reference#fl_progressive|Progressive modes}
650
+ * @memberOf Qualifiers
651
+ * @namespace Progressive
652
+ * @example
653
+ * import {Cloudinary} from "@cloudinary/url-gen";
654
+ * import {format} from "@cloudinary/url-gen/actions/delivery";
655
+ * import {jpg} from "@cloudinary/url-gen/qualifiers/format";
656
+ * import {steep} from "@cloudinary/url-gen/qualifiers/progressive";
657
+ *
658
+ * const yourCldInstance = new Cloudinary({cloud: {cloudName: 'demo'}});
659
+ * const image = yourCldInstance.image('woman');
660
+ * image.delivery(format(jpg()).progressive(steep()))
661
+ */
662
+ var ProgressiveQualifier = class extends FlagQualifier {
663
+ constructor(mode) {
664
+ super("progressive", mode);
665
+ }
666
+ };
667
+
668
+ //#endregion
669
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/delivery/DeliveryFormatAction.js
670
+ /**
671
+ * @memberOf Actions.Delivery
672
+ * @extends {Actions.Delivery.DeliveryAction}
673
+ * @see Visit {@link Actions.Delivery|Delivery} for an example
674
+ */
675
+ var DeliveryFormatAction = class extends DeliveryAction {
676
+ constructor(deliveryKey, deliveryType) {
677
+ super(deliveryKey, deliveryType, "formatType");
678
+ }
679
+ /**
680
+ * @description Uses lossy compression when delivering animated GIF files.
681
+ * @return {this}
682
+ */
683
+ lossy() {
684
+ this._actionModel.lossy = true;
685
+ this.addFlag(lossy());
686
+ return this;
687
+ }
688
+ /**
689
+ * @description Uses progressive compression when delivering JPG file format.
690
+ * @return {this}
691
+ */
692
+ progressive(mode) {
693
+ if (mode instanceof ProgressiveQualifier) {
694
+ this._actionModel.progressive = { mode: mode.getFlagValue() };
695
+ this.addFlag(mode);
696
+ } else {
697
+ this._actionModel.progressive = { mode };
698
+ this.addFlag(progressive(mode));
699
+ }
700
+ return this;
701
+ }
702
+ /**
703
+ * @description Ensures that images with a transparency channel are delivered in PNG format.
704
+ */
705
+ preserveTransparency() {
706
+ this._actionModel.preserveTransparency = true;
707
+ this.addFlag(preserveTransparency());
708
+ return this;
709
+ }
710
+ static fromJson(actionModel) {
711
+ const { formatType, lossy: lossy$1, progressive: progressive$1, preserveTransparency: preserveTransparency$1 } = actionModel;
712
+ let result;
713
+ if (formatType) result = new this("f", formatType);
714
+ else result = new this("f");
715
+ if (progressive$1) if (progressive$1.mode) result.progressive(progressive$1.mode);
716
+ else result.progressive();
717
+ lossy$1 && result.lossy();
718
+ preserveTransparency$1 && result.preserveTransparency();
719
+ return result;
720
+ }
721
+ };
722
+
723
+ //#endregion
724
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/delivery/DeliveryQualityAction.js
725
+ /**
726
+ * @description Controls the quality of the delivered image or video.
727
+ * @memberOf Actions.Delivery
728
+ * @extends {Actions.Delivery.DeliveryAction}
729
+ * @see Visit {@link Actions.Delivery|Delivery} for an example
730
+ */
731
+ var DeliveryQualityAction = class extends DeliveryAction {
732
+ /**
733
+ * @param {Qualifiers.Quality} qualityValue a Quality value
734
+ */
735
+ constructor(qualityValue) {
736
+ super("q", qualityValue.toString(), "level");
737
+ }
738
+ /**
739
+ * Selet the Chroma sub sampling</br>
740
+ * <b>Learn more</b>: {@link https://cloudinary.com/documentation/image_optimization#toggle_chroma_subsampling|Toggling chroma subsampling}
741
+ * @param {420 | 444 | number} type The chroma sub sampling type
742
+ */
743
+ chromaSubSampling(type) {
744
+ this._actionModel.chromaSubSampling = CHROMA_VALUE_TO_CHROMA_MODEL_ENUM[type];
745
+ const qualityWithSubSampling = new QualifierValue([this._actionModel.level, type]);
746
+ qualityWithSubSampling.setDelimiter(":");
747
+ return this.addQualifier(new Qualifier("q", qualityWithSubSampling));
748
+ }
749
+ /**
750
+ * Controls the final quality by setting a maximum quantization percentage
751
+ * @param {number} val
752
+ */
753
+ quantization(val) {
754
+ this._actionModel.quantization = val;
755
+ const qualityWithQuantization = new QualifierValue([this._actionModel.level, `qmax_${val}`]).setDelimiter(":");
756
+ return this.addQualifier(new Qualifier("q", qualityWithQuantization));
757
+ }
758
+ static fromJson(actionModel) {
759
+ const { level, chromaSubSampling, quantization } = actionModel;
760
+ const levelType = ACTION_TYPE_TO_QUALITY_MODE_MAP[level] || level;
761
+ const result = new this(levelType);
762
+ if (chromaSubSampling) {
763
+ const chromaValue = CHROMA_MODEL_ENUM_TO_CHROMA_VALUE[chromaSubSampling.toUpperCase()];
764
+ chromaValue && result.chromaSubSampling(+chromaValue);
765
+ }
766
+ quantization && result.quantization(quantization);
767
+ return result;
768
+ }
769
+ };
770
+
771
+ //#endregion
772
+ //#region node_modules/.pnpm/@cloudinary+transformation-builder-sdk@1.21.2/node_modules/@cloudinary/transformation-builder-sdk/actions/delivery.js
773
+ /**
774
+ * @description Defines transformations for delivering your assets without changing the visual or audio experience for the end user.
775
+ * @memberOf Actions
776
+ * @namespace Delivery
777
+ * @example
778
+ * See the examples under every method
779
+ */
780
+ /**
781
+ * @summary action
782
+ * @description Defines the format of the delivered asset.
783
+ *
784
+ * <b>Learn more:</b>
785
+ * {@link https://cloudinary.com/documentation/image_transformations#image_format_support|Image formats}
786
+ * {@link https://cloudinary.com/documentation/video_manipulation_and_delivery#transcoding_video_to_other_formats|Video formats}
787
+ *
788
+ * @memberOf Actions.Delivery
789
+ * @param {string} format The file format. For a list of supported format types see {@link Qualifiers.Format| format types} for
790
+ * possible values
791
+ * @return {Actions.Delivery.DeliveryFormat}
792
+ * @example
793
+ * import {Cloudinary} from "@cloudinary/url-gen";
794
+ * import {format} from "@cloudinary/url-gen/actions/delivery";
795
+ *
796
+ * const yourCldInstance = new Cloudinary({cloud:{cloudName:'demo'}});
797
+ * const image = yourCldInstance.image('woman');
798
+ * image.delivery(
799
+ * format('jpg'),
800
+ * );
801
+ *
802
+ */
803
+ function format(format$1) {
804
+ return new DeliveryFormatAction("f", format$1);
805
+ }
806
+ /**
807
+ * @summary action
808
+ * @description Controls the quality of the delivered image or video.
809
+ *
810
+ * <b>Learn more:</b> {@link https://cloudinary.com/documentation/image_optimization#how_to_optimize_image_quality|Image quality}
811
+ * {@link https://cloudinary.com/documentation/video_optimization#how_to_optimize_video_quality|Video quality}
812
+ * @memberOf Actions.Delivery
813
+ * @param {QualityTypes | string | number | Qualifiers.Quality} qualityType For a list of supported quality types see
814
+ * {@link Qualifiers.Quality| quality types} for
815
+ * possible values.
816
+ * @return {Actions.Delivery.DeliveryQualityAction}
817
+ * @example
818
+ * import {Cloudinary} from "@cloudinary/url-gen";
819
+ * import {quality} from "@cloudinary/url-gen/actions/delivery";
820
+ * import {quality} from "@cloudinary/url-gen/qualifiers/quantity";
821
+ *
822
+ * const yourCldInstance = new Cloudinary({cloud:{cloudName:'demo'}});
823
+ * const image = yourCldInstance.image('woman');
824
+ * image.delivery(
825
+ * quality('auto'),
826
+ * );
827
+ */
828
+ function quality(qualityType) {
829
+ return new DeliveryQualityAction(qualityType);
830
+ }
831
+
832
+ //#endregion
3
833
  //#region src/loaders/cloudinary/cloudinary-loader.tsx
4
- function customResolver(key, value) {
5
- if (typeof value === "boolean") return value ? key : void 0;
6
- return `${key}:${value}`;
7
- }
8
- const { useLoaderContext: useCloudinaryContext, LoaderProvider: CloudinaryLoaderProvider, useLoader: useCloudinaryLoader } = loaderFactory({
9
- transforms: { f: "webp" },
10
- placeholder: {
11
- q: 10,
12
- f: "webp"
13
- }
14
- }, {
15
- optionSeparator: "_",
16
- paramSeparator: ",",
17
- widthKey: "w",
18
- heightKey: "h",
19
- orders: {
20
- b_auto: { orders: [
21
- "mode",
22
- "number",
23
- "direction",
24
- "color"
25
- ] },
26
- b_gen_fill: { orders: ["prompt", "seed"] }
27
- },
28
- customResolver: {
29
- art: customResolver,
30
- e_accelerate: customResolver,
31
- e_adv_redeye: customResolver,
32
- e_art: customResolver,
33
- e_auto_brightness: customResolver,
34
- e_auto_color: customResolver,
35
- e_auto_contrast: customResolver,
36
- e_auto_enhance: customResolver,
37
- e_background_removal: customResolver,
38
- e_blur: customResolver,
39
- e_blur_faces: customResolver,
40
- e_blur_region: customResolver,
41
- e_brightness: customResolver,
42
- e_cartoonify: customResolver,
43
- e_colorize: customResolver,
44
- e_contrast: customResolver,
45
- e_distort: customResolver,
46
- e_drop_shadow: customResolver,
47
- e_gamma: customResolver,
48
- e_gradient_fade: customResolver,
49
- e_grayscale: customResolver,
50
- e_hue: customResolver,
51
- e_improve: customResolver,
52
- e_make_transparent: customResolver,
53
- e_negate: customResolver,
54
- e_oil_paint: customResolver,
55
- e_pixelate: customResolver,
56
- e_pixelate_faces: customResolver,
57
- e_pixelate_region: customResolver,
58
- e_redeye: customResolver,
59
- e_saturation: customResolver,
60
- e_screen: customResolver,
61
- e_sepia: customResolver,
62
- e_shadow: customResolver,
63
- e_sharpen: customResolver,
64
- e_shear: customResolver,
65
- e_simulate_colorblind: customResolver,
66
- e_tint: customResolver,
67
- e_trim: customResolver,
68
- e_unsharp_mask: customResolver,
69
- e_vectorize: customResolver,
70
- e_vignette: customResolver,
71
- e_volume_mute: customResolver
72
- }
73
- }, ({ path, params, imageOptions }) => `${path}/image/upload/${params}/${imageOptions.src}`);
834
+ const Context = createContext({
835
+ transforms: (img) => img.delivery(quality(auto$1())).delivery(format(auto())),
836
+ placeholder: (img) => img.resize(scale().width(10)).delivery(quality("auto:low")).delivery(format(auto()))
837
+ });
838
+ function CloudinaryLoaderProvider({ client, children, transforms, placeholder }) {
839
+ return /* @__PURE__ */ jsx(Context.Provider, {
840
+ value: {
841
+ cld: client,
842
+ transforms,
843
+ placeholder
844
+ },
845
+ children
846
+ });
847
+ }
848
+ function useCloudinaryLoader(options) {
849
+ const { cld, transforms: defaultTransforms, placeholder: defaultPlaceholder } = useContext(Context);
850
+ if (!cld) throw new Error("Cloudinary client is not provided. Please wrap your app with CloudinaryLoaderProvider.");
851
+ let transforms;
852
+ let placeholder;
853
+ if (typeof options === "function") transforms = options;
854
+ else if (options) {
855
+ transforms = options.transforms;
856
+ placeholder = options.placeholder;
857
+ }
858
+ return (imageOptions) => {
859
+ const img = cld.image(imageOptions.src);
860
+ const isPlaceholder = imageOptions.isPlaceholder;
861
+ if (isPlaceholder) {
862
+ if (defaultPlaceholder) defaultPlaceholder(img);
863
+ } else if (defaultTransforms) defaultTransforms(img);
864
+ if (isPlaceholder && placeholder) placeholder(img);
865
+ else if (!isPlaceholder && transforms) transforms(img);
866
+ const resizeAction = scale();
867
+ let hasResize = false;
868
+ if (imageOptions.width) {
869
+ resizeAction.width(imageOptions.width);
870
+ hasResize = true;
871
+ }
872
+ if (imageOptions.height) {
873
+ resizeAction.height(imageOptions.height);
874
+ hasResize = true;
875
+ }
876
+ if (hasResize) img.resize(resizeAction);
877
+ return img.toURL();
878
+ };
879
+ }
880
+ const useCloudinaryContext = () => useContext(Context);
74
881
 
75
882
  //#endregion
76
883
  export { CloudinaryLoaderProvider, useCloudinaryContext, useCloudinaryLoader };