@nonphoto/sanity-image 0.0.2 → 0.0.4

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,26 +1,26 @@
1
- var Q = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, P = {}, k = {
1
+ var $ = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, P = {}, k = {
2
2
  get exports() {
3
3
  return P;
4
4
  },
5
- set exports(s) {
6
- P = s;
5
+ set exports(f) {
6
+ P = f;
7
7
  }
8
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) {
9
+ (function(f, y) {
10
+ (function(s, v) {
11
+ f.exports = v();
12
+ })($, function() {
13
+ function s() {
14
+ return s = Object.assign || function(t) {
15
15
  for (var i = 1; i < arguments.length; i++) {
16
16
  var n = arguments[i];
17
17
  for (var r in n)
18
18
  Object.prototype.hasOwnProperty.call(n, r) && (t[r] = n[r]);
19
19
  }
20
20
  return t;
21
- }, h.apply(this, arguments);
21
+ }, s.apply(this, arguments);
22
22
  }
23
- function w(t, i) {
23
+ function v(t, i) {
24
24
  if (t) {
25
25
  if (typeof t == "string")
26
26
  return I(t, i);
@@ -41,7 +41,7 @@ var Q = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
41
41
  var n = typeof Symbol < "u" && t[Symbol.iterator] || t["@@iterator"];
42
42
  if (n)
43
43
  return (n = n.call(t)).next.bind(n);
44
- if (Array.isArray(t) || (n = w(t)) || i && t && typeof t.length == "number") {
44
+ if (Array.isArray(t) || (n = v(t)) || i && t && typeof t.length == "number") {
45
45
  n && (t = n);
46
46
  var r = 0;
47
47
  return function() {
@@ -56,17 +56,17 @@ var Q = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
56
56
  throw new TypeError(`Invalid attempt to iterate non-iterable instance.
57
57
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
58
58
  }
59
- var c = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
60
- function p(t) {
59
+ var d = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
60
+ function u(t) {
61
61
  var i = t.split("-"), n = i[1], r = i[2], o = i[3];
62
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 + '".');
63
+ throw new Error("Malformed asset _ref '" + t + `'. Expected an id like "` + d + '".');
64
+ var e = r.split("x"), a = e[0], h = e[1], c = +a, l = +h, p = isFinite(c) && isFinite(l);
65
+ if (!p)
66
+ throw new Error("Malformed asset _ref '" + t + `'. Expected an id like "` + d + '".');
67
67
  return {
68
68
  id: n,
69
- width: m,
69
+ width: c,
70
70
  height: l,
71
71
  format: o
72
72
  };
@@ -74,7 +74,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
74
74
  var S = function(i) {
75
75
  var n = i;
76
76
  return n ? typeof n._ref == "string" : !1;
77
- }, j = function(i) {
77
+ }, U = function(i) {
78
78
  var n = i;
79
79
  return n ? typeof n._id == "string" : !1;
80
80
  }, O = function(i) {
@@ -85,10 +85,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
85
85
  if (!t)
86
86
  return null;
87
87
  var i;
88
- if (typeof t == "string" && z(t))
88
+ if (typeof t == "string" && q(t))
89
89
  i = {
90
90
  asset: {
91
- _ref: R(t)
91
+ _ref: E(t)
92
92
  }
93
93
  };
94
94
  else if (typeof t == "string")
@@ -101,7 +101,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
101
101
  i = {
102
102
  asset: t
103
103
  };
104
- else if (j(t))
104
+ else if (U(t))
105
105
  i = {
106
106
  asset: {
107
107
  _ref: t._id || ""
@@ -110,27 +110,27 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
110
110
  else if (O(t))
111
111
  i = {
112
112
  asset: {
113
- _ref: R(t.asset.url)
113
+ _ref: E(t.asset.url)
114
114
  }
115
115
  };
116
116
  else if (typeof t.asset == "object")
117
- i = h({}, t);
117
+ i = s({}, t);
118
118
  else
119
119
  return null;
120
120
  var n = t;
121
- return n.crop && (i.crop = n.crop), n.hotspot && (i.hotspot = n.hotspot), q(i);
121
+ return n.crop && (i.crop = n.crop), n.hotspot && (i.hotspot = n.hotspot), z(i);
122
122
  }
123
- function z(t) {
123
+ function q(t) {
124
124
  return /^https?:\/\//.test("" + t);
125
125
  }
126
- function R(t) {
126
+ function E(t) {
127
127
  var i = t.split("/").slice(-1);
128
128
  return ("image-" + i[0]).replace(/\.([a-z]+)$/, "-$1");
129
129
  }
130
- function q(t) {
130
+ function z(t) {
131
131
  if (t.crop && t.hotspot)
132
132
  return t;
133
- var i = h({}, t);
133
+ var i = s({}, t);
134
134
  return i.crop || (i.crop = {
135
135
  left: 0,
136
136
  top: 0,
@@ -143,42 +143,42 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
143
143
  width: 1
144
144
  }), i;
145
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"]];
146
+ var R = [["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
147
  function _(t) {
148
- var i = h({}, t || {}), n = i.source;
148
+ var i = s({}, t || {}), n = i.source;
149
149
  delete i.source;
150
150
  var r = A(n);
151
151
  if (!r)
152
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 = {
153
+ var o = r.asset._ref || r.asset._id || "", e = u(o), a = Math.round(r.crop.left * e.width), h = Math.round(r.crop.top * e.height), c = {
154
154
  left: a,
155
- top: f,
155
+ top: h,
156
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
157
+ height: Math.round(e.height - r.crop.bottom * e.height - h)
158
+ }, l = r.hotspot.height * e.height / 2, p = r.hotspot.width * e.width / 2, m = r.hotspot.x * e.width, w = r.hotspot.y * e.height, g = {
159
+ left: m - p,
160
+ top: w - l,
161
+ right: m + p,
162
+ bottom: w + l
163
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, {
164
+ return i.rect || i.focalPoint || i.ignoreImageParams || i.crop || (i = s({}, i, V({
165
+ crop: c,
166
+ hotspot: g
167
+ }, i))), L(s({}, i, {
168
168
  asset: e
169
169
  }));
170
170
  }
171
171
  function L(t) {
172
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
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);
174
+ var e = t.rect, a = e.left, h = e.top, c = e.width, l = e.height, p = a !== 0 || h !== 0 || l !== t.asset.height || c !== t.asset.width;
175
+ p && o.push("rect=" + a + "," + h + "," + c + "," + l);
176
176
  }
177
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]));
178
+ var m = [t.flipHorizontal && "h", t.flipVertical && "v"].filter(Boolean).join("");
179
+ return m && o.push("flip=" + m), R.forEach(function(w) {
180
+ var g = w[0], b = w[1];
181
+ typeof t[g] < "u" ? o.push(b + "=" + encodeURIComponent(t[g])) : typeof t[b] < "u" && o.push(b + "=" + encodeURIComponent(t[b]));
182
182
  }), o.length === 0 ? r : r + "?" + o.join("&");
183
183
  }
184
184
  function V(t, i) {
@@ -189,22 +189,22 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
189
189
  height: o,
190
190
  rect: t.crop
191
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,
192
+ var e = t.crop, a = t.hotspot, h = r / o, c = e.width / e.height;
193
+ if (c > h) {
194
+ var l = Math.round(e.height), p = Math.round(l * h), m = Math.max(0, Math.round(e.top)), w = Math.round((a.right - a.left) / 2 + a.left), g = Math.max(0, Math.round(w - p / 2));
195
+ g < e.left ? g = e.left : g + p > e.left + e.width && (g = e.left + e.width - p), n = {
196
+ left: g,
197
+ top: m,
198
+ width: p,
199
199
  height: l
200
200
  };
201
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,
202
+ var b = e.width, j = Math.round(b / h), J = Math.max(0, Math.round(e.left)), Q = Math.round((a.bottom - a.top) / 2 + a.top), x = Math.max(0, Math.round(Q - j / 2));
203
+ x < e.top ? x = e.top : x + j > e.top + e.height && (x = e.top + e.height - j), n = {
204
+ left: J,
205
205
  top: x,
206
- width: y,
207
- height: U
206
+ width: b,
207
+ height: j
208
208
  };
209
209
  }
210
210
  return {
@@ -214,22 +214,22 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
214
214
  };
215
215
  }
216
216
  var B = ["clip", "crop", "fill", "fillmax", "max", "scale", "min"], F = ["top", "bottom", "left", "right", "center", "focalpoint", "entropy"], N = ["format"];
217
- function $(t) {
217
+ function D(t) {
218
218
  return t && "config" in t ? typeof t.config == "function" : !1;
219
219
  }
220
- function D(t) {
220
+ function G(t) {
221
221
  return t && "clientConfig" in t ? typeof t.clientConfig == "object" : !1;
222
222
  }
223
- function G(t) {
224
- for (var i = E, n = M(i), r; !(r = n()).done; ) {
223
+ function X(t) {
224
+ for (var i = R, n = M(i), r; !(r = n()).done; ) {
225
225
  var o = r.value, e = o[0], a = o[1];
226
226
  if (t === e || t === a)
227
227
  return e;
228
228
  }
229
229
  return t;
230
230
  }
231
- function X(t) {
232
- if ($(t)) {
231
+ function Y(t) {
232
+ if (D(t)) {
233
233
  var i = t.config(), n = i.apiHost, r = i.projectId, o = i.dataset, e = n || "https://api.sanity.io";
234
234
  return new H(null, {
235
235
  baseUrl: e.replace(/^https:\/\/api\./, "https://cdn."),
@@ -238,19 +238,19 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
238
238
  });
239
239
  }
240
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";
241
+ if (G(a)) {
242
+ var h = a.clientConfig, c = h.apiHost, l = h.projectId, p = h.dataset, m = c || "https://api.sanity.io";
243
243
  return new H(null, {
244
- baseUrl: g.replace(/^https:\/\/api\./, "https://cdn."),
244
+ baseUrl: m.replace(/^https:\/\/api\./, "https://cdn."),
245
245
  projectId: l,
246
- dataset: d
246
+ dataset: p
247
247
  });
248
248
  }
249
249
  return new H(null, t);
250
250
  }
251
251
  var H = /* @__PURE__ */ function() {
252
252
  function t(n, r) {
253
- this.options = void 0, this.options = n ? h({}, n.options || {}, r || {}) : h({}, r || {});
253
+ this.options = void 0, this.options = n ? s({}, n.options || {}, r || {}) : s({}, r || {});
254
254
  }
255
255
  var i = t.prototype;
256
256
  return i.withOptions = function(r) {
@@ -259,10 +259,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
259
259
  };
260
260
  for (var a in r)
261
261
  if (r.hasOwnProperty(a)) {
262
- var f = G(a);
263
- e[f] = r[a];
262
+ var h = X(a);
263
+ e[h] = r[a];
264
264
  }
265
- return new t(this, h({
265
+ return new t(this, s({
266
266
  baseUrl: o
267
267
  }, e));
268
268
  }, i.image = function(r) {
@@ -402,7 +402,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
402
402
  return this.url();
403
403
  }, t;
404
404
  }();
405
- return X;
405
+ return Y;
406
406
  });
407
407
  })(k);
408
408
  const C = P, tt = [
@@ -437,63 +437,45 @@ const C = P, tt = [
437
437
  360,
438
438
  240
439
439
  ], K = 24, Z = 1200, T = 90;
440
- function W(s, u, h) {
441
- return s ? s * (1 - (u ?? 0) - (h ?? 0)) : void 0;
440
+ function W(f, y, s) {
441
+ return f ? f * (1 - (y ?? 0) - (s ?? 0)) : void 0;
442
442
  }
443
443
  function rt({
444
- image: s,
445
- client: u,
446
- widths: h,
447
- quality: w = T
444
+ image: f,
445
+ client: y,
446
+ widths: s,
447
+ quality: v = T
448
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;
449
+ var S, U;
450
+ const I = Array.from(s).sort((O, A) => O - A), M = C(y).image(f).quality(v).auto("format"), d = typeof f == "object" && "asset" in f ? f.asset.metadata : void 0, u = typeof f == "object" && "crop" in f ? f.crop : void 0;
451
451
  return {
452
- src: (c == null ? void 0 : c.lqip) ?? M.width(K).url().toString(),
452
+ src: (d == null ? void 0 : d.lqip) ?? M.width(K).url().toString(),
453
453
  srcset: I.map((O) => `${M.width(O).url()} ${O}w`).join(","),
454
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
455
+ (S = d == null ? void 0 : d.dimensions) == null ? void 0 : S.width,
456
+ u == null ? void 0 : u.left,
457
+ u == null ? void 0 : u.right
458
458
  ),
459
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
460
+ (U = d == null ? void 0 : d.dimensions) == null ? void 0 : U.height,
461
+ u == null ? void 0 : u.top,
462
+ u == null ? void 0 : u.bottom
463
463
  )
464
464
  };
465
465
  }
466
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
467
+ image: f,
468
+ client: y,
469
+ width: s = Z,
470
+ quality: v = T
477
471
  }) {
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(", ");
472
+ return C(y).image(f).quality(v).auto("format").width(s).url();
488
473
  }
489
474
  export {
490
- et as aspectRatio,
491
475
  Z as defaultMetaImageWidth,
492
476
  T as defaultQuality,
493
477
  tt as defaultWidths,
494
478
  rt as imageProps,
495
479
  K as lowResWidth,
496
- it as metaImageUrl,
497
- ot as sizes,
498
- nt as styleAspectRatio
480
+ it as metaImageUrl
499
481
  };
@@ -1,2 +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"})});
1
+ (function(c,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(c=typeof globalThis<"u"?globalThis:c||self,x(c["sanity-image"]={}))})(this,function(c){"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(f){P=f}};(function(f,O){(function(s,w){f.exports=w()})(x,function(){function s(){return s=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},s.apply(this,arguments)}function w(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=w(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 d="image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";function u(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 "`+d+'".');var e=i.split("x"),a=e[0],h=e[1],m=+a,l=+h,p=isFinite(m)&&isFinite(l);if(!p)throw new Error("Malformed asset _ref '"+t+`'. Expected an id like "`+d+'".');return{id:n,width:m,height:l,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 R(t){if(!t)return null;var r;if(typeof t=="string"&&D(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=s({},t);else return null;var n=t;return n.crop&&(r.crop=n.crop),n.hotspot&&(r.hotspot=n.hotspot),G(r)}function D(t){return/^https?:\/\//.test(""+t)}function _(t){var r=t.split("/").slice(-1);return("image-"+r[0]).replace(/\.([a-z]+)$/,"-$1")}function G(t){if(t.crop&&t.hotspot)return t;var r=s({},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 Q(t){var r=s({},t||{}),n=r.source;delete r.source;var i=R(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=u(o),a=Math.round(i.crop.left*e.width),h=Math.round(i.crop.top*e.height),m={left:a,top:h,width:Math.round(e.width-i.crop.right*e.width-a),height:Math.round(e.height-i.crop.bottom*e.height-h)},l=i.hotspot.height*e.height/2,p=i.hotspot.width*e.width/2,v=i.hotspot.x*e.width,b=i.hotspot.y*e.height,g={left:v-p,top:b-l,right:v+p,bottom:b+l};return r.rect||r.focalPoint||r.ignoreImageParams||r.crop||(r=s({},r,Y({crop:m,hotspot:g},r))),X(s({},r,{asset:e}))}function X(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,h=e.top,m=e.width,l=e.height,p=a!==0||h!==0||l!==t.asset.height||m!==t.asset.width;p&&o.push("rect="+a+","+h+","+m+","+l)}t.bg&&o.push("bg="+t.bg),t.focalPoint&&(o.push("fp-x="+t.focalPoint.x),o.push("fp-y="+t.focalPoint.y));var v=[t.flipHorizontal&&"h",t.flipVertical&&"v"].filter(Boolean).join("");return v&&o.push("flip="+v),L.forEach(function(b){var g=b[0],y=b[1];typeof t[g]<"u"?o.push(y+"="+encodeURIComponent(t[g])):typeof t[y]<"u"&&o.push(y+"="+encodeURIComponent(t[y]))}),o.length===0?i:i+"?"+o.join("&")}function Y(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,h=i/o,m=e.width/e.height;if(m>h){var l=Math.round(e.height),p=Math.round(l*h),v=Math.max(0,Math.round(e.top)),b=Math.round((a.right-a.left)/2+a.left),g=Math.max(0,Math.round(b-p/2));g<e.left?g=e.left:g+p>e.left+e.width&&(g=e.left+e.width-p),n={left:g,top:v,width:p,height:l}}else{var y=e.width,H=Math.round(y/h),rt=Math.max(0,Math.round(e.left)),nt=Math.round((a.bottom-a.top)/2+a.top),M=Math.max(0,Math.round(nt-H/2));M<e.top?M=e.top:M+H>e.top+e.height&&(M=e.top+e.height-H),n={left:rt,top:M,width:y,height:H}}return{width:i,height:o,rect:n}}var J=["clip","crop","fill","fillmax","max","scale","min"],$=["top","bottom","left","right","center","focalpoint","entropy"],k=["format"];function K(t){return t&&"config"in t?typeof t.config=="function":!1}function Z(t){return t&&"clientConfig"in t?typeof t.clientConfig=="object":!1}function tt(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 it(t){if(K(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(Z(a)){var h=a.clientConfig,m=h.apiHost,l=h.projectId,p=h.dataset,v=m||"https://api.sanity.io";return new E(null,{baseUrl:v.replace(/^https:\/\/api\./,"https://cdn."),projectId:l,dataset:p})}return new E(null,t)}var E=function(){function t(n,i){this.options=void 0,this.options=n?s({},n.options||{},i||{}):s({},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 h=tt(a);e[h]=i[a]}return new t(this,s({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(J.indexOf(i)===-1)throw new Error('Invalid fit mode "'+i+'"');return this.withOptions({fit:i})},r.crop=function(i){if($.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(k.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 Q(this.options)},r.toString=function(){return this.url()},t}();return it})})(V);const T=P,B=[6016,5120,4480,3840,3200,2560,2048,1920,1668,1280,1080,960,720,640,480,360,240],C=24,q=1200,W=90;function z(f,O,s){return f?f*(1-(O??0)-(s??0)):void 0}function F({image:f,client:O,widths:s,quality:w=W}){var U,A;const S=Array.from(s).sort((I,R)=>I-R),j=T(O).image(f).quality(w).auto("format"),d=typeof f=="object"&&"asset"in f?f.asset.metadata:void 0,u=typeof f=="object"&&"crop"in f?f.crop:void 0;return{src:(d==null?void 0:d.lqip)??j.width(C).url().toString(),srcset:S.map(I=>`${j.width(I).url()} ${I}w`).join(","),naturalWidth:z((U=d==null?void 0:d.dimensions)==null?void 0:U.width,u==null?void 0:u.left,u==null?void 0:u.right),naturalHeight:z((A=d==null?void 0:d.dimensions)==null?void 0:A.height,u==null?void 0:u.top,u==null?void 0:u.bottom)}}function N({image:f,client:O,width:s=q,quality:w=W}){return T(O).image(f).quality(w).auto("format").width(s).url()}c.defaultMetaImageWidth=q,c.defaultQuality=W,c.defaultWidths=B,c.imageProps=F,c.lowResWidth=C,c.metaImageUrl=N,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nonphoto/sanity-image",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",