@nonphoto/sanity-image 0.0.2

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,499 @@
1
+ var Q = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, P = {}, k = {
2
+ get exports() {
3
+ return P;
4
+ },
5
+ set exports(s) {
6
+ P = s;
7
+ }
8
+ };
9
+ (function(s, u) {
10
+ (function(h, w) {
11
+ s.exports = w();
12
+ })(Q, function() {
13
+ function h() {
14
+ return h = Object.assign || function(t) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var n = arguments[i];
17
+ for (var r in n)
18
+ Object.prototype.hasOwnProperty.call(n, r) && (t[r] = n[r]);
19
+ }
20
+ return t;
21
+ }, h.apply(this, arguments);
22
+ }
23
+ function w(t, i) {
24
+ if (t) {
25
+ if (typeof t == "string")
26
+ return I(t, i);
27
+ var n = Object.prototype.toString.call(t).slice(8, -1);
28
+ if (n === "Object" && t.constructor && (n = t.constructor.name), n === "Map" || n === "Set")
29
+ return Array.from(t);
30
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
31
+ return I(t, i);
32
+ }
33
+ }
34
+ function I(t, i) {
35
+ (i == null || i > t.length) && (i = t.length);
36
+ for (var n = 0, r = new Array(i); n < i; n++)
37
+ r[n] = t[n];
38
+ return r;
39
+ }
40
+ function M(t, i) {
41
+ var n = typeof Symbol < "u" && t[Symbol.iterator] || t["@@iterator"];
42
+ if (n)
43
+ return (n = n.call(t)).next.bind(n);
44
+ if (Array.isArray(t) || (n = w(t)) || i && t && typeof t.length == "number") {
45
+ n && (t = n);
46
+ var r = 0;
47
+ return function() {
48
+ return r >= t.length ? {
49
+ done: !0
50
+ } : {
51
+ done: !1,
52
+ value: t[r++]
53
+ };
54
+ };
55
+ }
56
+ throw new TypeError(`Invalid attempt to iterate non-iterable instance.
57
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
58
+ }
59
+ var c = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
60
+ function p(t) {
61
+ var i = t.split("-"), n = i[1], r = i[2], o = i[3];
62
+ if (!n || !r || !o)
63
+ throw new Error("Malformed asset _ref '" + t + `'. Expected an id like "` + c + '".');
64
+ var e = r.split("x"), a = e[0], f = e[1], m = +a, l = +f, d = isFinite(m) && isFinite(l);
65
+ if (!d)
66
+ throw new Error("Malformed asset _ref '" + t + `'. Expected an id like "` + c + '".');
67
+ return {
68
+ id: n,
69
+ width: m,
70
+ height: l,
71
+ format: o
72
+ };
73
+ }
74
+ var S = function(i) {
75
+ var n = i;
76
+ return n ? typeof n._ref == "string" : !1;
77
+ }, j = function(i) {
78
+ var n = i;
79
+ return n ? typeof n._id == "string" : !1;
80
+ }, O = function(i) {
81
+ var n = i;
82
+ return n && n.asset ? typeof n.asset.url == "string" : !1;
83
+ };
84
+ function A(t) {
85
+ if (!t)
86
+ return null;
87
+ var i;
88
+ if (typeof t == "string" && z(t))
89
+ i = {
90
+ asset: {
91
+ _ref: R(t)
92
+ }
93
+ };
94
+ else if (typeof t == "string")
95
+ i = {
96
+ asset: {
97
+ _ref: t
98
+ }
99
+ };
100
+ else if (S(t))
101
+ i = {
102
+ asset: t
103
+ };
104
+ else if (j(t))
105
+ i = {
106
+ asset: {
107
+ _ref: t._id || ""
108
+ }
109
+ };
110
+ else if (O(t))
111
+ i = {
112
+ asset: {
113
+ _ref: R(t.asset.url)
114
+ }
115
+ };
116
+ else if (typeof t.asset == "object")
117
+ i = h({}, t);
118
+ else
119
+ return null;
120
+ var n = t;
121
+ return n.crop && (i.crop = n.crop), n.hotspot && (i.hotspot = n.hotspot), q(i);
122
+ }
123
+ function z(t) {
124
+ return /^https?:\/\//.test("" + t);
125
+ }
126
+ function R(t) {
127
+ var i = t.split("/").slice(-1);
128
+ return ("image-" + i[0]).replace(/\.([a-z]+)$/, "-$1");
129
+ }
130
+ function q(t) {
131
+ if (t.crop && t.hotspot)
132
+ return t;
133
+ var i = h({}, t);
134
+ return i.crop || (i.crop = {
135
+ left: 0,
136
+ top: 0,
137
+ bottom: 0,
138
+ right: 0
139
+ }), i.hotspot || (i.hotspot = {
140
+ x: 0.5,
141
+ y: 0.5,
142
+ height: 1,
143
+ width: 1
144
+ }), i;
145
+ }
146
+ var E = [["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"]];
147
+ function _(t) {
148
+ var i = h({}, t || {}), n = i.source;
149
+ delete i.source;
150
+ var r = A(n);
151
+ if (!r)
152
+ throw new Error("Unable to resolve image URL from source (" + JSON.stringify(n) + ")");
153
+ var o = r.asset._ref || r.asset._id || "", e = p(o), a = Math.round(r.crop.left * e.width), f = Math.round(r.crop.top * e.height), m = {
154
+ left: a,
155
+ top: f,
156
+ width: Math.round(e.width - r.crop.right * e.width - a),
157
+ height: Math.round(e.height - r.crop.bottom * e.height - f)
158
+ }, l = r.hotspot.height * e.height / 2, d = r.hotspot.width * e.width / 2, g = r.hotspot.x * e.width, b = r.hotspot.y * e.height, v = {
159
+ left: g - d,
160
+ top: b - l,
161
+ right: g + d,
162
+ bottom: b + l
163
+ };
164
+ return i.rect || i.focalPoint || i.ignoreImageParams || i.crop || (i = h({}, i, V({
165
+ crop: m,
166
+ hotspot: v
167
+ }, i))), L(h({}, i, {
168
+ asset: e
169
+ }));
170
+ }
171
+ function L(t) {
172
+ var i = (t.baseUrl || "https://cdn.sanity.io").replace(/\/+$/, ""), n = t.asset.id + "-" + t.asset.width + "x" + t.asset.height + "." + t.asset.format, r = i + "/images/" + t.projectId + "/" + t.dataset + "/" + n, o = [];
173
+ if (t.rect) {
174
+ var e = t.rect, a = e.left, f = e.top, m = e.width, l = e.height, d = a !== 0 || f !== 0 || l !== t.asset.height || m !== t.asset.width;
175
+ d && o.push("rect=" + a + "," + f + "," + m + "," + l);
176
+ }
177
+ t.bg && o.push("bg=" + t.bg), t.focalPoint && (o.push("fp-x=" + t.focalPoint.x), o.push("fp-y=" + t.focalPoint.y));
178
+ var g = [t.flipHorizontal && "h", t.flipVertical && "v"].filter(Boolean).join("");
179
+ return g && o.push("flip=" + g), E.forEach(function(b) {
180
+ var v = b[0], y = b[1];
181
+ typeof t[v] < "u" ? o.push(y + "=" + encodeURIComponent(t[v])) : typeof t[y] < "u" && o.push(y + "=" + encodeURIComponent(t[y]));
182
+ }), o.length === 0 ? r : r + "?" + o.join("&");
183
+ }
184
+ function V(t, i) {
185
+ var n, r = i.width, o = i.height;
186
+ if (!(r && o))
187
+ return {
188
+ width: r,
189
+ height: o,
190
+ rect: t.crop
191
+ };
192
+ var e = t.crop, a = t.hotspot, f = r / o, m = e.width / e.height;
193
+ if (m > f) {
194
+ var l = Math.round(e.height), d = Math.round(l * f), g = Math.max(0, Math.round(e.top)), b = Math.round((a.right - a.left) / 2 + a.left), v = Math.max(0, Math.round(b - d / 2));
195
+ v < e.left ? v = e.left : v + d > e.left + e.width && (v = e.left + e.width - d), n = {
196
+ left: v,
197
+ top: g,
198
+ width: d,
199
+ height: l
200
+ };
201
+ } else {
202
+ var y = e.width, U = Math.round(y / f), Y = Math.max(0, Math.round(e.left)), J = Math.round((a.bottom - a.top) / 2 + a.top), x = Math.max(0, Math.round(J - U / 2));
203
+ x < e.top ? x = e.top : x + U > e.top + e.height && (x = e.top + e.height - U), n = {
204
+ left: Y,
205
+ top: x,
206
+ width: y,
207
+ height: U
208
+ };
209
+ }
210
+ return {
211
+ width: r,
212
+ height: o,
213
+ rect: n
214
+ };
215
+ }
216
+ var B = ["clip", "crop", "fill", "fillmax", "max", "scale", "min"], F = ["top", "bottom", "left", "right", "center", "focalpoint", "entropy"], N = ["format"];
217
+ function $(t) {
218
+ return t && "config" in t ? typeof t.config == "function" : !1;
219
+ }
220
+ function D(t) {
221
+ return t && "clientConfig" in t ? typeof t.clientConfig == "object" : !1;
222
+ }
223
+ function G(t) {
224
+ for (var i = E, n = M(i), r; !(r = n()).done; ) {
225
+ var o = r.value, e = o[0], a = o[1];
226
+ if (t === e || t === a)
227
+ return e;
228
+ }
229
+ return t;
230
+ }
231
+ function X(t) {
232
+ if ($(t)) {
233
+ var i = t.config(), n = i.apiHost, r = i.projectId, o = i.dataset, e = n || "https://api.sanity.io";
234
+ return new H(null, {
235
+ baseUrl: e.replace(/^https:\/\/api\./, "https://cdn."),
236
+ projectId: r,
237
+ dataset: o
238
+ });
239
+ }
240
+ var a = t;
241
+ if (D(a)) {
242
+ var f = a.clientConfig, m = f.apiHost, l = f.projectId, d = f.dataset, g = m || "https://api.sanity.io";
243
+ return new H(null, {
244
+ baseUrl: g.replace(/^https:\/\/api\./, "https://cdn."),
245
+ projectId: l,
246
+ dataset: d
247
+ });
248
+ }
249
+ return new H(null, t);
250
+ }
251
+ var H = /* @__PURE__ */ function() {
252
+ function t(n, r) {
253
+ this.options = void 0, this.options = n ? h({}, n.options || {}, r || {}) : h({}, r || {});
254
+ }
255
+ var i = t.prototype;
256
+ return i.withOptions = function(r) {
257
+ var o = r.baseUrl || this.options.baseUrl, e = {
258
+ baseUrl: o
259
+ };
260
+ for (var a in r)
261
+ if (r.hasOwnProperty(a)) {
262
+ var f = G(a);
263
+ e[f] = r[a];
264
+ }
265
+ return new t(this, h({
266
+ baseUrl: o
267
+ }, e));
268
+ }, i.image = function(r) {
269
+ return this.withOptions({
270
+ source: r
271
+ });
272
+ }, i.dataset = function(r) {
273
+ return this.withOptions({
274
+ dataset: r
275
+ });
276
+ }, i.projectId = function(r) {
277
+ return this.withOptions({
278
+ projectId: r
279
+ });
280
+ }, i.bg = function(r) {
281
+ return this.withOptions({
282
+ bg: r
283
+ });
284
+ }, i.dpr = function(r) {
285
+ return this.withOptions(r && r !== 1 ? {
286
+ dpr: r
287
+ } : {});
288
+ }, i.width = function(r) {
289
+ return this.withOptions({
290
+ width: r
291
+ });
292
+ }, i.height = function(r) {
293
+ return this.withOptions({
294
+ height: r
295
+ });
296
+ }, i.focalPoint = function(r, o) {
297
+ return this.withOptions({
298
+ focalPoint: {
299
+ x: r,
300
+ y: o
301
+ }
302
+ });
303
+ }, i.maxWidth = function(r) {
304
+ return this.withOptions({
305
+ maxWidth: r
306
+ });
307
+ }, i.minWidth = function(r) {
308
+ return this.withOptions({
309
+ minWidth: r
310
+ });
311
+ }, i.maxHeight = function(r) {
312
+ return this.withOptions({
313
+ maxHeight: r
314
+ });
315
+ }, i.minHeight = function(r) {
316
+ return this.withOptions({
317
+ minHeight: r
318
+ });
319
+ }, i.size = function(r, o) {
320
+ return this.withOptions({
321
+ width: r,
322
+ height: o
323
+ });
324
+ }, i.blur = function(r) {
325
+ return this.withOptions({
326
+ blur: r
327
+ });
328
+ }, i.sharpen = function(r) {
329
+ return this.withOptions({
330
+ sharpen: r
331
+ });
332
+ }, i.rect = function(r, o, e, a) {
333
+ return this.withOptions({
334
+ rect: {
335
+ left: r,
336
+ top: o,
337
+ width: e,
338
+ height: a
339
+ }
340
+ });
341
+ }, i.format = function(r) {
342
+ return this.withOptions({
343
+ format: r
344
+ });
345
+ }, i.invert = function(r) {
346
+ return this.withOptions({
347
+ invert: r
348
+ });
349
+ }, i.orientation = function(r) {
350
+ return this.withOptions({
351
+ orientation: r
352
+ });
353
+ }, i.quality = function(r) {
354
+ return this.withOptions({
355
+ quality: r
356
+ });
357
+ }, i.forceDownload = function(r) {
358
+ return this.withOptions({
359
+ download: r
360
+ });
361
+ }, i.flipHorizontal = function() {
362
+ return this.withOptions({
363
+ flipHorizontal: !0
364
+ });
365
+ }, i.flipVertical = function() {
366
+ return this.withOptions({
367
+ flipVertical: !0
368
+ });
369
+ }, i.ignoreImageParams = function() {
370
+ return this.withOptions({
371
+ ignoreImageParams: !0
372
+ });
373
+ }, i.fit = function(r) {
374
+ if (B.indexOf(r) === -1)
375
+ throw new Error('Invalid fit mode "' + r + '"');
376
+ return this.withOptions({
377
+ fit: r
378
+ });
379
+ }, i.crop = function(r) {
380
+ if (F.indexOf(r) === -1)
381
+ throw new Error('Invalid crop mode "' + r + '"');
382
+ return this.withOptions({
383
+ crop: r
384
+ });
385
+ }, i.saturation = function(r) {
386
+ return this.withOptions({
387
+ saturation: r
388
+ });
389
+ }, i.auto = function(r) {
390
+ if (N.indexOf(r) === -1)
391
+ throw new Error('Invalid auto mode "' + r + '"');
392
+ return this.withOptions({
393
+ auto: r
394
+ });
395
+ }, i.pad = function(r) {
396
+ return this.withOptions({
397
+ pad: r
398
+ });
399
+ }, i.url = function() {
400
+ return _(this.options);
401
+ }, i.toString = function() {
402
+ return this.url();
403
+ }, t;
404
+ }();
405
+ return X;
406
+ });
407
+ })(k);
408
+ const C = P, tt = [
409
+ 6016,
410
+ // 6K
411
+ 5120,
412
+ // 5K
413
+ 4480,
414
+ // 4.5K
415
+ 3840,
416
+ // 4K
417
+ 3200,
418
+ // QHD+
419
+ 2560,
420
+ // WQXGA
421
+ 2048,
422
+ // QXGA
423
+ 1920,
424
+ // 1080p
425
+ 1668,
426
+ // iPad
427
+ 1280,
428
+ // 720p
429
+ 1080,
430
+ // iPhone 6-8 Plus
431
+ 960,
432
+ 720,
433
+ // iPhone 6-8
434
+ 640,
435
+ // 480p
436
+ 480,
437
+ 360,
438
+ 240
439
+ ], K = 24, Z = 1200, T = 90;
440
+ function W(s, u, h) {
441
+ return s ? s * (1 - (u ?? 0) - (h ?? 0)) : void 0;
442
+ }
443
+ function rt({
444
+ image: s,
445
+ client: u,
446
+ widths: h,
447
+ quality: w = T
448
+ }) {
449
+ var S, j;
450
+ const I = Array.from(h).sort((O, A) => O - A), M = C(u).image(s).quality(w).auto("format"), c = typeof s == "object" && "asset" in s ? s.asset.metadata : void 0, p = typeof s == "object" && "crop" in s ? s.crop : void 0;
451
+ return {
452
+ src: (c == null ? void 0 : c.lqip) ?? M.width(K).url().toString(),
453
+ srcset: I.map((O) => `${M.width(O).url()} ${O}w`).join(","),
454
+ naturalWidth: W(
455
+ (S = c == null ? void 0 : c.dimensions) == null ? void 0 : S.width,
456
+ p == null ? void 0 : p.left,
457
+ p == null ? void 0 : p.right
458
+ ),
459
+ naturalHeight: W(
460
+ (j = c == null ? void 0 : c.dimensions) == null ? void 0 : j.height,
461
+ p == null ? void 0 : p.top,
462
+ p == null ? void 0 : p.bottom
463
+ )
464
+ };
465
+ }
466
+ function it({
467
+ image: s,
468
+ client: u,
469
+ width: h = Z,
470
+ quality: w = T
471
+ }) {
472
+ return C(u).image(s).quality(w).auto("format").width(h).url();
473
+ }
474
+ function nt({
475
+ naturalWidth: s,
476
+ naturalHeight: u
477
+ }) {
478
+ return s && u ? `${s} / ${u}` : "auto";
479
+ }
480
+ function et({
481
+ naturalWidth: s,
482
+ naturalHeight: u
483
+ }) {
484
+ return s && u ? u / s : void 0;
485
+ }
486
+ function ot(s) {
487
+ return s.sort(([u], [h]) => h - u).map(([u, h]) => `(min-width: ${u}px) ${h}`).concat(["100vw"]).join(", ");
488
+ }
489
+ export {
490
+ et as aspectRatio,
491
+ Z as defaultMetaImageWidth,
492
+ T as defaultQuality,
493
+ tt as defaultWidths,
494
+ rt as imageProps,
495
+ K as lowResWidth,
496
+ it as metaImageUrl,
497
+ ot as sizes,
498
+ nt as styleAspectRatio
499
+ };
@@ -0,0 +1,2 @@
1
+ (function(l,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(l=typeof globalThis<"u"?globalThis:l||self,x(l["sanity-image"]={}))})(this,function(l){"use strict";var x=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},P={},V={get exports(){return P},set exports(s){P=s}};(function(s,u){(function(h,y){s.exports=y()})(x,function(){function h(){return h=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},h.apply(this,arguments)}function y(t,r){if(t){if(typeof t=="string")return S(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return S(t,r)}}function S(t,r){(r==null||r>t.length)&&(r=t.length);for(var n=0,i=new Array(r);n<r;n++)i[n]=t[n];return i}function j(t,r){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=y(t))||r&&t&&typeof t.length=="number"){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
2
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var m="image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";function p(t){var r=t.split("-"),n=r[1],i=r[2],o=r[3];if(!n||!i||!o)throw new Error("Malformed asset _ref '"+t+`'. Expected an id like "`+m+'".');var e=i.split("x"),a=e[0],f=e[1],g=+a,d=+f,c=isFinite(g)&&isFinite(d);if(!c)throw new Error("Malformed asset _ref '"+t+`'. Expected an id like "`+m+'".');return{id:n,width:g,height:d,format:o}}var U=function(r){var n=r;return n?typeof n._ref=="string":!1},A=function(r){var n=r;return n?typeof n._id=="string":!1},I=function(r){var n=r;return n&&n.asset?typeof n.asset.url=="string":!1};function W(t){if(!t)return null;var r;if(typeof t=="string"&&Q(t))r={asset:{_ref:_(t)}};else if(typeof t=="string")r={asset:{_ref:t}};else if(U(t))r={asset:t};else if(A(t))r={asset:{_ref:t._id||""}};else if(I(t))r={asset:{_ref:_(t.asset.url)}};else if(typeof t.asset=="object")r=h({},t);else return null;var n=t;return n.crop&&(r.crop=n.crop),n.hotspot&&(r.hotspot=n.hotspot),X(r)}function Q(t){return/^https?:\/\//.test(""+t)}function _(t){var r=t.split("/").slice(-1);return("image-"+r[0]).replace(/\.([a-z]+)$/,"-$1")}function X(t){if(t.crop&&t.hotspot)return t;var r=h({},t);return r.crop||(r.crop={left:0,top:0,bottom:0,right:0}),r.hotspot||(r.hotspot={x:.5,y:.5,height:1,width:1}),r}var L=[["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"]];function Y(t){var r=h({},t||{}),n=r.source;delete r.source;var i=W(n);if(!i)throw new Error("Unable to resolve image URL from source ("+JSON.stringify(n)+")");var o=i.asset._ref||i.asset._id||"",e=p(o),a=Math.round(i.crop.left*e.width),f=Math.round(i.crop.top*e.height),g={left:a,top:f,width:Math.round(e.width-i.crop.right*e.width-a),height:Math.round(e.height-i.crop.bottom*e.height-f)},d=i.hotspot.height*e.height/2,c=i.hotspot.width*e.width/2,w=i.hotspot.x*e.width,b=i.hotspot.y*e.height,v={left:w-c,top:b-d,right:w+c,bottom:b+d};return r.rect||r.focalPoint||r.ignoreImageParams||r.crop||(r=h({},r,k({crop:g,hotspot:v},r))),J(h({},r,{asset:e}))}function J(t){var r=(t.baseUrl||"https://cdn.sanity.io").replace(/\/+$/,""),n=t.asset.id+"-"+t.asset.width+"x"+t.asset.height+"."+t.asset.format,i=r+"/images/"+t.projectId+"/"+t.dataset+"/"+n,o=[];if(t.rect){var e=t.rect,a=e.left,f=e.top,g=e.width,d=e.height,c=a!==0||f!==0||d!==t.asset.height||g!==t.asset.width;c&&o.push("rect="+a+","+f+","+g+","+d)}t.bg&&o.push("bg="+t.bg),t.focalPoint&&(o.push("fp-x="+t.focalPoint.x),o.push("fp-y="+t.focalPoint.y));var w=[t.flipHorizontal&&"h",t.flipVertical&&"v"].filter(Boolean).join("");return w&&o.push("flip="+w),L.forEach(function(b){var v=b[0],O=b[1];typeof t[v]<"u"?o.push(O+"="+encodeURIComponent(t[v])):typeof t[O]<"u"&&o.push(O+"="+encodeURIComponent(t[O]))}),o.length===0?i:i+"?"+o.join("&")}function k(t,r){var n,i=r.width,o=r.height;if(!(i&&o))return{width:i,height:o,rect:t.crop};var e=t.crop,a=t.hotspot,f=i/o,g=e.width/e.height;if(g>f){var d=Math.round(e.height),c=Math.round(d*f),w=Math.max(0,Math.round(e.top)),b=Math.round((a.right-a.left)/2+a.left),v=Math.max(0,Math.round(b-c/2));v<e.left?v=e.left:v+c>e.left+e.width&&(v=e.left+e.width-c),n={left:v,top:w,width:c,height:d}}else{var O=e.width,R=Math.round(O/f),ot=Math.max(0,Math.round(e.left)),at=Math.round((a.bottom-a.top)/2+a.top),M=Math.max(0,Math.round(at-R/2));M<e.top?M=e.top:M+R>e.top+e.height&&(M=e.top+e.height-R),n={left:ot,top:M,width:O,height:R}}return{width:i,height:o,rect:n}}var K=["clip","crop","fill","fillmax","max","scale","min"],Z=["top","bottom","left","right","center","focalpoint","entropy"],tt=["format"];function it(t){return t&&"config"in t?typeof t.config=="function":!1}function rt(t){return t&&"clientConfig"in t?typeof t.clientConfig=="object":!1}function nt(t){for(var r=L,n=j(r),i;!(i=n()).done;){var o=i.value,e=o[0],a=o[1];if(t===e||t===a)return e}return t}function et(t){if(it(t)){var r=t.config(),n=r.apiHost,i=r.projectId,o=r.dataset,e=n||"https://api.sanity.io";return new E(null,{baseUrl:e.replace(/^https:\/\/api\./,"https://cdn."),projectId:i,dataset:o})}var a=t;if(rt(a)){var f=a.clientConfig,g=f.apiHost,d=f.projectId,c=f.dataset,w=g||"https://api.sanity.io";return new E(null,{baseUrl:w.replace(/^https:\/\/api\./,"https://cdn."),projectId:d,dataset:c})}return new E(null,t)}var E=function(){function t(n,i){this.options=void 0,this.options=n?h({},n.options||{},i||{}):h({},i||{})}var r=t.prototype;return r.withOptions=function(i){var o=i.baseUrl||this.options.baseUrl,e={baseUrl:o};for(var a in i)if(i.hasOwnProperty(a)){var f=nt(a);e[f]=i[a]}return new t(this,h({baseUrl:o},e))},r.image=function(i){return this.withOptions({source:i})},r.dataset=function(i){return this.withOptions({dataset:i})},r.projectId=function(i){return this.withOptions({projectId:i})},r.bg=function(i){return this.withOptions({bg:i})},r.dpr=function(i){return this.withOptions(i&&i!==1?{dpr:i}:{})},r.width=function(i){return this.withOptions({width:i})},r.height=function(i){return this.withOptions({height:i})},r.focalPoint=function(i,o){return this.withOptions({focalPoint:{x:i,y:o}})},r.maxWidth=function(i){return this.withOptions({maxWidth:i})},r.minWidth=function(i){return this.withOptions({minWidth:i})},r.maxHeight=function(i){return this.withOptions({maxHeight:i})},r.minHeight=function(i){return this.withOptions({minHeight:i})},r.size=function(i,o){return this.withOptions({width:i,height:o})},r.blur=function(i){return this.withOptions({blur:i})},r.sharpen=function(i){return this.withOptions({sharpen:i})},r.rect=function(i,o,e,a){return this.withOptions({rect:{left:i,top:o,width:e,height:a}})},r.format=function(i){return this.withOptions({format:i})},r.invert=function(i){return this.withOptions({invert:i})},r.orientation=function(i){return this.withOptions({orientation:i})},r.quality=function(i){return this.withOptions({quality:i})},r.forceDownload=function(i){return this.withOptions({download:i})},r.flipHorizontal=function(){return this.withOptions({flipHorizontal:!0})},r.flipVertical=function(){return this.withOptions({flipVertical:!0})},r.ignoreImageParams=function(){return this.withOptions({ignoreImageParams:!0})},r.fit=function(i){if(K.indexOf(i)===-1)throw new Error('Invalid fit mode "'+i+'"');return this.withOptions({fit:i})},r.crop=function(i){if(Z.indexOf(i)===-1)throw new Error('Invalid crop mode "'+i+'"');return this.withOptions({crop:i})},r.saturation=function(i){return this.withOptions({saturation:i})},r.auto=function(i){if(tt.indexOf(i)===-1)throw new Error('Invalid auto mode "'+i+'"');return this.withOptions({auto:i})},r.pad=function(i){return this.withOptions({pad:i})},r.url=function(){return Y(this.options)},r.toString=function(){return this.url()},t}();return et})})(V);const T=P,B=[6016,5120,4480,3840,3200,2560,2048,1920,1668,1280,1080,960,720,640,480,360,240],C=24,z=1200,H=90;function q(s,u,h){return s?s*(1-(u??0)-(h??0)):void 0}function F({image:s,client:u,widths:h,quality:y=H}){var U,A;const S=Array.from(h).sort((I,W)=>I-W),j=T(u).image(s).quality(y).auto("format"),m=typeof s=="object"&&"asset"in s?s.asset.metadata:void 0,p=typeof s=="object"&&"crop"in s?s.crop:void 0;return{src:(m==null?void 0:m.lqip)??j.width(C).url().toString(),srcset:S.map(I=>`${j.width(I).url()} ${I}w`).join(","),naturalWidth:q((U=m==null?void 0:m.dimensions)==null?void 0:U.width,p==null?void 0:p.left,p==null?void 0:p.right),naturalHeight:q((A=m==null?void 0:m.dimensions)==null?void 0:A.height,p==null?void 0:p.top,p==null?void 0:p.bottom)}}function N({image:s,client:u,width:h=z,quality:y=H}){return T(u).image(s).quality(y).auto("format").width(h).url()}function $({naturalWidth:s,naturalHeight:u}){return s&&u?`${s} / ${u}`:"auto"}function D({naturalWidth:s,naturalHeight:u}){return s&&u?u/s:void 0}function G(s){return s.sort(([u],[h])=>h-u).map(([u,h])=>`(min-width: ${u}px) ${h}`).concat(["100vw"]).join(", ")}l.aspectRatio=D,l.defaultMetaImageWidth=z,l.defaultQuality=H,l.defaultWidths=B,l.imageProps=F,l.lowResWidth=C,l.metaImageUrl=N,l.sizes=G,l.styleAspectRatio=$,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/dist/vite.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@nonphoto/sanity-image",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "files": [
6
+ "dist",
7
+ "index.d.ts"
8
+ ],
9
+ "main": "./dist/counter.umd.cjs",
10
+ "module": "./dist/counter.js",
11
+ "types": "./index.d.ts",
12
+ "exports": {
13
+ "types": "./index.d.ts",
14
+ "import": "./dist/counter.js",
15
+ "require": "./dist/counter.umd.cjs"
16
+ },
17
+ "scripts": {
18
+ "dev": "vite",
19
+ "build": "tsc && vite build"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "18.14.6",
23
+ "auto": "10.43.0",
24
+ "typescript": "^4.9.4",
25
+ "vite": "^4.0.4"
26
+ },
27
+ "dependencies": {
28
+ "@sanity/image-url": "1.0.2"
29
+ },
30
+ "packageManager": "pnpm@7.29.1",
31
+ "repository": "nonphoto/sanity-image",
32
+ "author": "Jonas Luebbers <jonas@jonasluebbers.com>",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "auto": {
37
+ "plugins": [
38
+ "npm"
39
+ ]
40
+ }
41
+ }