sanity-plugin-utils 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -6,9 +6,9 @@ Object.defineProperty(exports, '__esModule', {
6
6
  value: true
7
7
  });
8
8
  var React = require('react');
9
+ var sanity = require('sanity');
9
10
  var operators = require('rxjs/operators');
10
11
  var isEqual = require('react-fast-compare');
11
- var sanity = require('sanity');
12
12
  var desk = require('sanity/desk');
13
13
  var router = require('sanity/router');
14
14
  var jsxRuntime = require('react/jsx-runtime');
@@ -23,6 +23,663 @@ function _interopDefaultCompat(e) {
23
23
  var React__default = /*#__PURE__*/_interopDefaultCompat(React);
24
24
  var isEqual__default = /*#__PURE__*/_interopDefaultCompat(isEqual);
25
25
  var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
26
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
27
+ var builder = {};
28
+ var urlForImage = {};
29
+ var parseAssetId$1 = {};
30
+ Object.defineProperty(parseAssetId$1, "__esModule", {
31
+ value: true
32
+ });
33
+ var example = 'image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg';
34
+ function parseAssetId(ref) {
35
+ var _a = ref.split('-'),
36
+ id = _a[1],
37
+ dimensionString = _a[2],
38
+ format = _a[3];
39
+ if (!id || !dimensionString || !format) {
40
+ throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
41
+ }
42
+ var _b = dimensionString.split('x'),
43
+ imgWidthStr = _b[0],
44
+ imgHeightStr = _b[1];
45
+ var width = +imgWidthStr;
46
+ var height = +imgHeightStr;
47
+ var isValidAssetId = isFinite(width) && isFinite(height);
48
+ if (!isValidAssetId) {
49
+ throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
50
+ }
51
+ return {
52
+ id: id,
53
+ width: width,
54
+ height: height,
55
+ format: format
56
+ };
57
+ }
58
+ parseAssetId$1.default = parseAssetId;
59
+ var parseSource$1 = {};
60
+ var __assign$1 = commonjsGlobal && commonjsGlobal.__assign || function () {
61
+ __assign$1 = Object.assign || function (t) {
62
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
63
+ s = arguments[i];
64
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
65
+ }
66
+ return t;
67
+ };
68
+ return __assign$1.apply(this, arguments);
69
+ };
70
+ Object.defineProperty(parseSource$1, "__esModule", {
71
+ value: true
72
+ });
73
+ var isRef = function (src) {
74
+ var source = src;
75
+ return source ? typeof source._ref === 'string' : false;
76
+ };
77
+ var isAsset = function (src) {
78
+ var source = src;
79
+ return source ? typeof source._id === 'string' : false;
80
+ };
81
+ var isAssetStub = function (src) {
82
+ var source = src;
83
+ return source && source.asset ? typeof source.asset.url === 'string' : false;
84
+ };
85
+ // Convert an asset-id, asset or image to an image record suitable for processing
86
+ // eslint-disable-next-line complexity
87
+ function parseSource(source) {
88
+ if (!source) {
89
+ return null;
90
+ }
91
+ var image;
92
+ if (typeof source === 'string' && isUrl(source)) {
93
+ // Someone passed an existing image url?
94
+ image = {
95
+ asset: {
96
+ _ref: urlToId(source)
97
+ }
98
+ };
99
+ } else if (typeof source === 'string') {
100
+ // Just an asset id
101
+ image = {
102
+ asset: {
103
+ _ref: source
104
+ }
105
+ };
106
+ } else if (isRef(source)) {
107
+ // We just got passed an asset directly
108
+ image = {
109
+ asset: source
110
+ };
111
+ } else if (isAsset(source)) {
112
+ // If we were passed an image asset document
113
+ image = {
114
+ asset: {
115
+ _ref: source._id || ''
116
+ }
117
+ };
118
+ } else if (isAssetStub(source)) {
119
+ // If we were passed a partial asset (`url`, but no `_id`)
120
+ image = {
121
+ asset: {
122
+ _ref: urlToId(source.asset.url)
123
+ }
124
+ };
125
+ } else if (typeof source.asset === 'object') {
126
+ // Probably an actual image with materialized asset
127
+ image = __assign$1({}, source);
128
+ } else {
129
+ // We got something that does not look like an image, or it is an image
130
+ // that currently isn't sporting an asset.
131
+ return null;
132
+ }
133
+ var img = source;
134
+ if (img.crop) {
135
+ image.crop = img.crop;
136
+ }
137
+ if (img.hotspot) {
138
+ image.hotspot = img.hotspot;
139
+ }
140
+ return applyDefaults(image);
141
+ }
142
+ parseSource$1.default = parseSource;
143
+ function isUrl(url) {
144
+ return /^https?:\/\//.test("".concat(url));
145
+ }
146
+ function urlToId(url) {
147
+ var parts = url.split('/').slice(-1);
148
+ return "image-".concat(parts[0]).replace(/\.([a-z]+)$/, '-$1');
149
+ }
150
+ // Mock crop and hotspot if image lacks it
151
+ function applyDefaults(image) {
152
+ if (image.crop && image.hotspot) {
153
+ return image;
154
+ }
155
+ // We need to pad in default values for crop or hotspot
156
+ var result = __assign$1({}, image);
157
+ if (!result.crop) {
158
+ result.crop = {
159
+ left: 0,
160
+ top: 0,
161
+ bottom: 0,
162
+ right: 0
163
+ };
164
+ }
165
+ if (!result.hotspot) {
166
+ result.hotspot = {
167
+ x: 0.5,
168
+ y: 0.5,
169
+ height: 1.0,
170
+ width: 1.0
171
+ };
172
+ }
173
+ return result;
174
+ }
175
+ (function (exports) {
176
+ var __assign = commonjsGlobal && commonjsGlobal.__assign || function () {
177
+ __assign = Object.assign || function (t) {
178
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
179
+ s = arguments[i];
180
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
181
+ }
182
+ return t;
183
+ };
184
+ return __assign.apply(this, arguments);
185
+ };
186
+ var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
187
+ return mod && mod.__esModule ? mod : {
188
+ "default": mod
189
+ };
190
+ };
191
+ Object.defineProperty(exports, "__esModule", {
192
+ value: true
193
+ });
194
+ exports.parseSource = exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = void 0;
195
+ var parseAssetId_1 = __importDefault(parseAssetId$1);
196
+ var parseSource_1 = __importDefault(parseSource$1);
197
+ exports.parseSource = parseSource_1.default;
198
+ exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = [['width', 'w'], ['height', 'h'], ['format', 'fm'], ['download', 'dl'], ['blur', 'blur'], ['sharpen', 'sharp'], ['invert', 'invert'], ['orientation', 'or'], ['minHeight', 'min-h'], ['maxHeight', 'max-h'], ['minWidth', 'min-w'], ['maxWidth', 'max-w'], ['quality', 'q'], ['fit', 'fit'], ['crop', 'crop'], ['saturation', 'sat'], ['auto', 'auto'], ['dpr', 'dpr'], ['pad', 'pad']];
199
+ function urlForImage(options) {
200
+ var spec = __assign({}, options || {});
201
+ var source = spec.source;
202
+ delete spec.source;
203
+ var image = (0, parseSource_1.default)(source);
204
+ if (!image) {
205
+ throw new Error("Unable to resolve image URL from source (".concat(JSON.stringify(source), ")"));
206
+ }
207
+ var id = image.asset._ref || image.asset._id || '';
208
+ var asset = (0, parseAssetId_1.default)(id);
209
+ // Compute crop rect in terms of pixel coordinates in the raw source image
210
+ var cropLeft = Math.round(image.crop.left * asset.width);
211
+ var cropTop = Math.round(image.crop.top * asset.height);
212
+ var crop = {
213
+ left: cropLeft,
214
+ top: cropTop,
215
+ width: Math.round(asset.width - image.crop.right * asset.width - cropLeft),
216
+ height: Math.round(asset.height - image.crop.bottom * asset.height - cropTop)
217
+ };
218
+ // Compute hot spot rect in terms of pixel coordinates
219
+ var hotSpotVerticalRadius = image.hotspot.height * asset.height / 2;
220
+ var hotSpotHorizontalRadius = image.hotspot.width * asset.width / 2;
221
+ var hotSpotCenterX = image.hotspot.x * asset.width;
222
+ var hotSpotCenterY = image.hotspot.y * asset.height;
223
+ var hotspot = {
224
+ left: hotSpotCenterX - hotSpotHorizontalRadius,
225
+ top: hotSpotCenterY - hotSpotVerticalRadius,
226
+ right: hotSpotCenterX + hotSpotHorizontalRadius,
227
+ bottom: hotSpotCenterY + hotSpotVerticalRadius
228
+ };
229
+ // If irrelevant, or if we are requested to: don't perform crop/fit based on
230
+ // the crop/hotspot.
231
+ if (!(spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop)) {
232
+ spec = __assign(__assign({}, spec), fit({
233
+ crop: crop,
234
+ hotspot: hotspot
235
+ }, spec));
236
+ }
237
+ return specToImageUrl(__assign(__assign({}, spec), {
238
+ asset: asset
239
+ }));
240
+ }
241
+ exports.default = urlForImage;
242
+ // eslint-disable-next-line complexity
243
+ function specToImageUrl(spec) {
244
+ var cdnUrl = (spec.baseUrl || 'https://cdn.sanity.io').replace(/\/+$/, '');
245
+ var filename = "".concat(spec.asset.id, "-").concat(spec.asset.width, "x").concat(spec.asset.height, ".").concat(spec.asset.format);
246
+ var baseUrl = "".concat(cdnUrl, "/images/").concat(spec.projectId, "/").concat(spec.dataset, "/").concat(filename);
247
+ var params = [];
248
+ if (spec.rect) {
249
+ // Only bother url with a crop if it actually crops anything
250
+ var _a = spec.rect,
251
+ left = _a.left,
252
+ top_1 = _a.top,
253
+ width = _a.width,
254
+ height = _a.height;
255
+ var isEffectiveCrop = left !== 0 || top_1 !== 0 || height !== spec.asset.height || width !== spec.asset.width;
256
+ if (isEffectiveCrop) {
257
+ params.push("rect=".concat(left, ",").concat(top_1, ",").concat(width, ",").concat(height));
258
+ }
259
+ }
260
+ if (spec.bg) {
261
+ params.push("bg=".concat(spec.bg));
262
+ }
263
+ if (spec.focalPoint) {
264
+ params.push("fp-x=".concat(spec.focalPoint.x));
265
+ params.push("fp-y=".concat(spec.focalPoint.y));
266
+ }
267
+ var flip = [spec.flipHorizontal && 'h', spec.flipVertical && 'v'].filter(Boolean).join('');
268
+ if (flip) {
269
+ params.push("flip=".concat(flip));
270
+ }
271
+ // Map from spec name to url param name, and allow using the actual param name as an alternative
272
+ exports.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function (mapping) {
273
+ var specName = mapping[0],
274
+ param = mapping[1];
275
+ if (typeof spec[specName] !== 'undefined') {
276
+ params.push("".concat(param, "=").concat(encodeURIComponent(spec[specName])));
277
+ } else if (typeof spec[param] !== 'undefined') {
278
+ params.push("".concat(param, "=").concat(encodeURIComponent(spec[param])));
279
+ }
280
+ });
281
+ if (params.length === 0) {
282
+ return baseUrl;
283
+ }
284
+ return "".concat(baseUrl, "?").concat(params.join('&'));
285
+ }
286
+ function fit(source, spec) {
287
+ var cropRect;
288
+ var imgWidth = spec.width;
289
+ var imgHeight = spec.height;
290
+ // If we are not constraining the aspect ratio, we'll just use the whole crop
291
+ if (!(imgWidth && imgHeight)) {
292
+ return {
293
+ width: imgWidth,
294
+ height: imgHeight,
295
+ rect: source.crop
296
+ };
297
+ }
298
+ var crop = source.crop;
299
+ var hotspot = source.hotspot;
300
+ // If we are here, that means aspect ratio is locked and fitting will be a bit harder
301
+ var desiredAspectRatio = imgWidth / imgHeight;
302
+ var cropAspectRatio = crop.width / crop.height;
303
+ if (cropAspectRatio > desiredAspectRatio) {
304
+ // The crop is wider than the desired aspect ratio. That means we are cutting from the sides
305
+ var height = Math.round(crop.height);
306
+ var width = Math.round(height * desiredAspectRatio);
307
+ var top_2 = Math.max(0, Math.round(crop.top));
308
+ // Center output horizontally over hotspot
309
+ var hotspotXCenter = Math.round((hotspot.right - hotspot.left) / 2 + hotspot.left);
310
+ var left = Math.max(0, Math.round(hotspotXCenter - width / 2));
311
+ // Keep output within crop
312
+ if (left < crop.left) {
313
+ left = crop.left;
314
+ } else if (left + width > crop.left + crop.width) {
315
+ left = crop.left + crop.width - width;
316
+ }
317
+ cropRect = {
318
+ left: left,
319
+ top: top_2,
320
+ width: width,
321
+ height: height
322
+ };
323
+ } else {
324
+ // The crop is taller than the desired ratio, we are cutting from top and bottom
325
+ var width = crop.width;
326
+ var height = Math.round(width / desiredAspectRatio);
327
+ var left = Math.max(0, Math.round(crop.left));
328
+ // Center output vertically over hotspot
329
+ var hotspotYCenter = Math.round((hotspot.bottom - hotspot.top) / 2 + hotspot.top);
330
+ var top_3 = Math.max(0, Math.round(hotspotYCenter - height / 2));
331
+ // Keep output rect within crop
332
+ if (top_3 < crop.top) {
333
+ top_3 = crop.top;
334
+ } else if (top_3 + height > crop.top + crop.height) {
335
+ top_3 = crop.top + crop.height - height;
336
+ }
337
+ cropRect = {
338
+ left: left,
339
+ top: top_3,
340
+ width: width,
341
+ height: height
342
+ };
343
+ }
344
+ return {
345
+ width: imgWidth,
346
+ height: imgHeight,
347
+ rect: cropRect
348
+ };
349
+ }
350
+ })(urlForImage);
351
+ var __assign = commonjsGlobal && commonjsGlobal.__assign || function () {
352
+ __assign = Object.assign || function (t) {
353
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
354
+ s = arguments[i];
355
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
356
+ }
357
+ return t;
358
+ };
359
+ return __assign.apply(this, arguments);
360
+ };
361
+ var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function (o, m, k, k2) {
362
+ if (k2 === undefined) k2 = k;
363
+ Object.defineProperty(o, k2, {
364
+ enumerable: true,
365
+ get: function () {
366
+ return m[k];
367
+ }
368
+ });
369
+ } : function (o, m, k, k2) {
370
+ if (k2 === undefined) k2 = k;
371
+ o[k2] = m[k];
372
+ });
373
+ var __setModuleDefault = commonjsGlobal && commonjsGlobal.__setModuleDefault || (Object.create ? function (o, v) {
374
+ Object.defineProperty(o, "default", {
375
+ enumerable: true,
376
+ value: v
377
+ });
378
+ } : function (o, v) {
379
+ o["default"] = v;
380
+ });
381
+ var __importStar = commonjsGlobal && commonjsGlobal.__importStar || function (mod) {
382
+ if (mod && mod.__esModule) return mod;
383
+ var result = {};
384
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
385
+ __setModuleDefault(result, mod);
386
+ return result;
387
+ };
388
+ Object.defineProperty(builder, "__esModule", {
389
+ value: true
390
+ });
391
+ builder.ImageUrlBuilder = void 0;
392
+ var urlForImage_1 = __importStar(urlForImage);
393
+ var validFits = ['clip', 'crop', 'fill', 'fillmax', 'max', 'scale', 'min'];
394
+ var validCrops = ['top', 'bottom', 'left', 'right', 'center', 'focalpoint', 'entropy'];
395
+ var validAutoModes = ['format'];
396
+ function isSanityModernClientLike(client) {
397
+ return client && 'config' in client ? typeof client.config === 'function' : false;
398
+ }
399
+ function isSanityClientLike(client) {
400
+ return client && 'clientConfig' in client ? typeof client.clientConfig === 'object' : false;
401
+ }
402
+ function rewriteSpecName(key) {
403
+ var specs = urlForImage_1.SPEC_NAME_TO_URL_NAME_MAPPINGS;
404
+ for (var _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
405
+ var entry = specs_1[_i];
406
+ var specName = entry[0],
407
+ param = entry[1];
408
+ if (key === specName || key === param) {
409
+ return specName;
410
+ }
411
+ }
412
+ return key;
413
+ }
414
+ function urlBuilder(options) {
415
+ // Did we get a modernish client?
416
+ if (isSanityModernClientLike(options)) {
417
+ // Inherit config from client
418
+ var _a = options.config(),
419
+ apiUrl = _a.apiHost,
420
+ projectId = _a.projectId,
421
+ dataset = _a.dataset;
422
+ var apiHost = apiUrl || 'https://api.sanity.io';
423
+ return new ImageUrlBuilder(null, {
424
+ baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
425
+ projectId: projectId,
426
+ dataset: dataset
427
+ });
428
+ }
429
+ // Did we get a SanityClient?
430
+ var client = options;
431
+ if (isSanityClientLike(client)) {
432
+ // Inherit config from client
433
+ var _b = client.clientConfig,
434
+ apiUrl = _b.apiHost,
435
+ projectId = _b.projectId,
436
+ dataset = _b.dataset;
437
+ var apiHost = apiUrl || 'https://api.sanity.io';
438
+ return new ImageUrlBuilder(null, {
439
+ baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
440
+ projectId: projectId,
441
+ dataset: dataset
442
+ });
443
+ }
444
+ // Or just accept the options as given
445
+ return new ImageUrlBuilder(null, options);
446
+ }
447
+ builder.default = urlBuilder;
448
+ var ImageUrlBuilder = /** @class */function () {
449
+ function ImageUrlBuilder(parent, options) {
450
+ this.options = parent ? __assign(__assign({}, parent.options || {}), options || {}) : __assign({}, options || {}); // Copy options
451
+ }
452
+
453
+ ImageUrlBuilder.prototype.withOptions = function (options) {
454
+ var baseUrl = options.baseUrl || this.options.baseUrl;
455
+ var newOptions = {
456
+ baseUrl: baseUrl
457
+ };
458
+ for (var key in options) {
459
+ if (options.hasOwnProperty(key)) {
460
+ var specKey = rewriteSpecName(key);
461
+ newOptions[specKey] = options[key];
462
+ }
463
+ }
464
+ return new ImageUrlBuilder(this, __assign({
465
+ baseUrl: baseUrl
466
+ }, newOptions));
467
+ };
468
+ // The image to be represented. Accepts a Sanity 'image'-document, 'asset'-document or
469
+ // _id of asset. To get the benefit of automatic hot-spot/crop integration with the content
470
+ // studio, the 'image'-document must be provided.
471
+ ImageUrlBuilder.prototype.image = function (source) {
472
+ return this.withOptions({
473
+ source: source
474
+ });
475
+ };
476
+ // Specify the dataset
477
+ ImageUrlBuilder.prototype.dataset = function (dataset) {
478
+ return this.withOptions({
479
+ dataset: dataset
480
+ });
481
+ };
482
+ // Specify the projectId
483
+ ImageUrlBuilder.prototype.projectId = function (projectId) {
484
+ return this.withOptions({
485
+ projectId: projectId
486
+ });
487
+ };
488
+ // Specify background color
489
+ ImageUrlBuilder.prototype.bg = function (bg) {
490
+ return this.withOptions({
491
+ bg: bg
492
+ });
493
+ };
494
+ // Set DPR scaling factor
495
+ ImageUrlBuilder.prototype.dpr = function (dpr) {
496
+ // A DPR of 1 is the default - so only include it if we have a different value
497
+ return this.withOptions(dpr && dpr !== 1 ? {
498
+ dpr: dpr
499
+ } : {});
500
+ };
501
+ // Specify the width of the image in pixels
502
+ ImageUrlBuilder.prototype.width = function (width) {
503
+ return this.withOptions({
504
+ width: width
505
+ });
506
+ };
507
+ // Specify the height of the image in pixels
508
+ ImageUrlBuilder.prototype.height = function (height) {
509
+ return this.withOptions({
510
+ height: height
511
+ });
512
+ };
513
+ // Specify focal point in fraction of image dimensions. Each component 0.0-1.0
514
+ ImageUrlBuilder.prototype.focalPoint = function (x, y) {
515
+ return this.withOptions({
516
+ focalPoint: {
517
+ x: x,
518
+ y: y
519
+ }
520
+ });
521
+ };
522
+ ImageUrlBuilder.prototype.maxWidth = function (maxWidth) {
523
+ return this.withOptions({
524
+ maxWidth: maxWidth
525
+ });
526
+ };
527
+ ImageUrlBuilder.prototype.minWidth = function (minWidth) {
528
+ return this.withOptions({
529
+ minWidth: minWidth
530
+ });
531
+ };
532
+ ImageUrlBuilder.prototype.maxHeight = function (maxHeight) {
533
+ return this.withOptions({
534
+ maxHeight: maxHeight
535
+ });
536
+ };
537
+ ImageUrlBuilder.prototype.minHeight = function (minHeight) {
538
+ return this.withOptions({
539
+ minHeight: minHeight
540
+ });
541
+ };
542
+ // Specify width and height in pixels
543
+ ImageUrlBuilder.prototype.size = function (width, height) {
544
+ return this.withOptions({
545
+ width: width,
546
+ height: height
547
+ });
548
+ };
549
+ // Specify blur between 0 and 100
550
+ ImageUrlBuilder.prototype.blur = function (blur) {
551
+ return this.withOptions({
552
+ blur: blur
553
+ });
554
+ };
555
+ ImageUrlBuilder.prototype.sharpen = function (sharpen) {
556
+ return this.withOptions({
557
+ sharpen: sharpen
558
+ });
559
+ };
560
+ // Specify the desired rectangle of the image
561
+ ImageUrlBuilder.prototype.rect = function (left, top, width, height) {
562
+ return this.withOptions({
563
+ rect: {
564
+ left: left,
565
+ top: top,
566
+ width: width,
567
+ height: height
568
+ }
569
+ });
570
+ };
571
+ // Specify the image format of the image. 'jpg', 'pjpg', 'png', 'webp'
572
+ ImageUrlBuilder.prototype.format = function (format) {
573
+ return this.withOptions({
574
+ format: format
575
+ });
576
+ };
577
+ ImageUrlBuilder.prototype.invert = function (invert) {
578
+ return this.withOptions({
579
+ invert: invert
580
+ });
581
+ };
582
+ // Rotation in degrees 0, 90, 180, 270
583
+ ImageUrlBuilder.prototype.orientation = function (orientation) {
584
+ return this.withOptions({
585
+ orientation: orientation
586
+ });
587
+ };
588
+ // Compression quality 0-100
589
+ ImageUrlBuilder.prototype.quality = function (quality) {
590
+ return this.withOptions({
591
+ quality: quality
592
+ });
593
+ };
594
+ // Make it a download link. Parameter is default filename.
595
+ ImageUrlBuilder.prototype.forceDownload = function (download) {
596
+ return this.withOptions({
597
+ download: download
598
+ });
599
+ };
600
+ // Flip image horizontally
601
+ ImageUrlBuilder.prototype.flipHorizontal = function () {
602
+ return this.withOptions({
603
+ flipHorizontal: true
604
+ });
605
+ };
606
+ // Flip image vertically
607
+ ImageUrlBuilder.prototype.flipVertical = function () {
608
+ return this.withOptions({
609
+ flipVertical: true
610
+ });
611
+ };
612
+ // Ignore crop/hotspot from image record, even when present
613
+ ImageUrlBuilder.prototype.ignoreImageParams = function () {
614
+ return this.withOptions({
615
+ ignoreImageParams: true
616
+ });
617
+ };
618
+ ImageUrlBuilder.prototype.fit = function (value) {
619
+ if (validFits.indexOf(value) === -1) {
620
+ throw new Error("Invalid fit mode \"".concat(value, "\""));
621
+ }
622
+ return this.withOptions({
623
+ fit: value
624
+ });
625
+ };
626
+ ImageUrlBuilder.prototype.crop = function (value) {
627
+ if (validCrops.indexOf(value) === -1) {
628
+ throw new Error("Invalid crop mode \"".concat(value, "\""));
629
+ }
630
+ return this.withOptions({
631
+ crop: value
632
+ });
633
+ };
634
+ // Saturation
635
+ ImageUrlBuilder.prototype.saturation = function (saturation) {
636
+ return this.withOptions({
637
+ saturation: saturation
638
+ });
639
+ };
640
+ ImageUrlBuilder.prototype.auto = function (value) {
641
+ if (validAutoModes.indexOf(value) === -1) {
642
+ throw new Error("Invalid auto mode \"".concat(value, "\""));
643
+ }
644
+ return this.withOptions({
645
+ auto: value
646
+ });
647
+ };
648
+ // Specify the number of pixels to pad the image
649
+ ImageUrlBuilder.prototype.pad = function (pad) {
650
+ return this.withOptions({
651
+ pad: pad
652
+ });
653
+ };
654
+ // Gets the url based on the submitted parameters
655
+ ImageUrlBuilder.prototype.url = function () {
656
+ return (0, urlForImage_1.default)(this.options);
657
+ };
658
+ // Alias for url()
659
+ ImageUrlBuilder.prototype.toString = function () {
660
+ return this.url();
661
+ };
662
+ return ImageUrlBuilder;
663
+ }();
664
+ builder.ImageUrlBuilder = ImageUrlBuilder;
665
+ var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
666
+ return mod && mod.__esModule ? mod : {
667
+ "default": mod
668
+ };
669
+ };
670
+ var builder_1 = __importDefault(builder);
671
+ var node = builder_1.default;
672
+ var createImageUrlBuilder = node;
673
+ function useImageUrlBuilder(clientOptions) {
674
+ const client = sanity.useClient(clientOptions);
675
+ const builder = React.useMemo(() => createImageUrlBuilder(client), [client]);
676
+ return builder;
677
+ }
678
+ function useImageUrlBuilderImage(source, clientOptions) {
679
+ const builder = useImageUrlBuilder(clientOptions);
680
+ const image = React.useMemo(() => source && builder ? builder.image(source) : null, [builder, source]);
681
+ return image;
682
+ }
26
683
  const DEFAULT_PARAMS = {};
27
684
  const DEFAULT_OPTIONS = {
28
685
  apiVersion: "v2022-05-09"
@@ -169,7 +826,7 @@ const TableWrapper = function () {
169
826
  ...props
170
827
  });
171
828
  };
172
- const StyledTable = styled__default.default(TableWrapper)(() => styled.css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: table;\n width: 100%;\n border-collapase: collapse;\n\n &:not([hidden]) {\n display: table;\n }\n "]))));
829
+ const StyledTable = styled__default.default(TableWrapper)(() => styled.css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: table;\n width: 100%;\n border-collapse: collapse;\n\n &:not([hidden]) {\n display: table;\n border-collapse: collapse;\n }\n "]))));
173
830
  function Table(props) {
174
831
  const {
175
832
  children,
@@ -330,6 +987,8 @@ exports.Feedback = Feedback;
330
987
  exports.Row = Row;
331
988
  exports.Table = Table;
332
989
  exports.UserSelectMenu = UserSelectMenu;
990
+ exports.useImageUrlBuilder = useImageUrlBuilder;
991
+ exports.useImageUrlBuilderImage = useImageUrlBuilderImage;
333
992
  exports.useListeningQuery = useListeningQuery;
334
993
  exports.useOpenInNewPane = useOpenInNewPane;
335
994
  exports.useProjectUsers = useProjectUsers;