@campphillip/widgets 4.0.7 → 4.0.8

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/dist/sanity.js ADDED
@@ -0,0 +1,361 @@
1
+ var b = Object.defineProperty;
2
+ var A = (i, t, r) => t in i ? b(i, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[t] = r;
3
+ var c = (i, t, r) => A(i, typeof t != "symbol" ? t + "" : t, r);
4
+ const w = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
5
+ function x(i) {
6
+ const [, t, r, o] = i.split("-");
7
+ if (!t || !r || !o)
8
+ throw new Error(`Malformed asset _ref '${i}'. Expected an id like "${w}".`);
9
+ const [n, e] = r.split("x"), h = +n, a = +e;
10
+ if (!(isFinite(h) && isFinite(a)))
11
+ throw new Error(`Malformed asset _ref '${i}'. Expected an id like "${w}".`);
12
+ return { id: t, width: h, height: a, format: o };
13
+ }
14
+ const I = (i) => {
15
+ const t = i;
16
+ return t ? typeof t._ref == "string" : !1;
17
+ }, M = (i) => {
18
+ const t = i;
19
+ return t ? typeof t._id == "string" : !1;
20
+ }, C = (i) => {
21
+ const t = i;
22
+ return t && t.asset ? typeof t.asset.url == "string" : !1;
23
+ }, U = (i) => {
24
+ if (typeof i == "object" && i !== null) {
25
+ const t = i;
26
+ return t._upload && (!t.asset || !t.asset._ref);
27
+ }
28
+ return !1;
29
+ };
30
+ function S(i) {
31
+ if (!i)
32
+ return null;
33
+ let t;
34
+ if (typeof i == "string" && E(i))
35
+ t = {
36
+ asset: { _ref: m(i) }
37
+ };
38
+ else if (typeof i == "string")
39
+ t = {
40
+ asset: { _ref: i }
41
+ };
42
+ else if (I(i))
43
+ t = {
44
+ asset: i
45
+ };
46
+ else if (M(i))
47
+ t = {
48
+ asset: {
49
+ _ref: i._id || ""
50
+ }
51
+ };
52
+ else if (C(i))
53
+ t = {
54
+ asset: {
55
+ _ref: m(i.asset.url)
56
+ }
57
+ };
58
+ else if (typeof i.asset == "object")
59
+ t = { ...i };
60
+ else
61
+ return null;
62
+ const r = i;
63
+ return r.crop && (t.crop = r.crop), r.hotspot && (t.hotspot = r.hotspot), P(t);
64
+ }
65
+ function E(i) {
66
+ return /^https?:\/\//.test(`${i}`);
67
+ }
68
+ function m(i) {
69
+ return `image-${i.split("/").slice(-1)[0]}`.replace(/\.([a-z]+)$/, "-$1");
70
+ }
71
+ function P(i) {
72
+ if (i.crop && i.hotspot)
73
+ return i;
74
+ const t = { ...i };
75
+ return t.crop || (t.crop = {
76
+ left: 0,
77
+ top: 0,
78
+ bottom: 0,
79
+ right: 0
80
+ }), t.hotspot || (t.hotspot = {
81
+ x: 0.5,
82
+ y: 0.5,
83
+ height: 1,
84
+ width: 1
85
+ }), t;
86
+ }
87
+ const O = [
88
+ ["width", "w"],
89
+ ["height", "h"],
90
+ ["format", "fm"],
91
+ ["download", "dl"],
92
+ ["blur", "blur"],
93
+ ["sharpen", "sharp"],
94
+ ["invert", "invert"],
95
+ ["orientation", "or"],
96
+ ["minHeight", "min-h"],
97
+ ["maxHeight", "max-h"],
98
+ ["minWidth", "min-w"],
99
+ ["maxWidth", "max-w"],
100
+ ["quality", "q"],
101
+ ["fit", "fit"],
102
+ ["crop", "crop"],
103
+ ["saturation", "sat"],
104
+ ["auto", "auto"],
105
+ ["dpr", "dpr"],
106
+ ["pad", "pad"],
107
+ ["frame", "frame"]
108
+ ];
109
+ function R(i) {
110
+ let t = { ...i || {} };
111
+ const r = t.source;
112
+ delete t.source;
113
+ const o = S(r);
114
+ if (!o) {
115
+ if (r && U(r))
116
+ return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8HwQACfsD/QNViZkAAAAASUVORK5CYII=";
117
+ throw new Error(`Unable to resolve image URL from source (${JSON.stringify(r)})`);
118
+ }
119
+ const n = o.asset._ref || o.asset._id || "", e = x(n), h = Math.round(o.crop.left * e.width), a = Math.round(o.crop.top * e.height), l = {
120
+ left: h,
121
+ top: a,
122
+ width: Math.round(e.width - o.crop.right * e.width - h),
123
+ height: Math.round(e.height - o.crop.bottom * e.height - a)
124
+ }, s = o.hotspot.height * e.height / 2, f = o.hotspot.width * e.width / 2, u = o.hotspot.x * e.width, p = o.hotspot.y * e.height, y = {
125
+ left: u - f,
126
+ top: p - s,
127
+ right: u + f,
128
+ bottom: p + s
129
+ };
130
+ return t.rect || t.focalPoint || t.ignoreImageParams || t.crop || (t = { ...t, ...N({ crop: l, hotspot: y }, t) }), v({ ...t, asset: e });
131
+ }
132
+ function v(i) {
133
+ const t = (i.baseUrl || "https://cdn.sanity.io").replace(/\/+$/, ""), r = i.vanityName ? `/${i.vanityName}` : "", o = `${i.asset.id}-${i.asset.width}x${i.asset.height}.${i.asset.format}${r}`, n = i.mediaLibraryId ? `${t}/media-libraries/${i.mediaLibraryId}/images/${o}` : `${t}/images/${i.projectId}/${i.dataset}/${o}`, e = [];
134
+ if (i.rect) {
135
+ const { left: a, top: l, width: s, height: f } = i.rect;
136
+ (a !== 0 || l !== 0 || f !== i.asset.height || s !== i.asset.width) && e.push(`rect=${a},${l},${s},${f}`);
137
+ }
138
+ i.bg && e.push(`bg=${i.bg}`), i.focalPoint && (e.push(`fp-x=${i.focalPoint.x}`), e.push(`fp-y=${i.focalPoint.y}`));
139
+ const h = [i.flipHorizontal && "h", i.flipVertical && "v"].filter(Boolean).join("");
140
+ return h && e.push(`flip=${h}`), O.forEach((a) => {
141
+ const [l, s] = a;
142
+ typeof i[l] < "u" ? e.push(`${s}=${encodeURIComponent(i[l])}`) : typeof i[s] < "u" && e.push(`${s}=${encodeURIComponent(i[s])}`);
143
+ }), e.length === 0 ? n : `${n}?${e.join("&")}`;
144
+ }
145
+ function N(i, t) {
146
+ let r;
147
+ const o = t.width, n = t.height;
148
+ if (!(o && n))
149
+ return { width: o, height: n, rect: i.crop };
150
+ const e = i.crop, h = i.hotspot, a = o / n;
151
+ if (e.width / e.height > a) {
152
+ const l = Math.round(e.height), s = Math.round(l * a), f = Math.max(0, Math.round(e.top)), u = Math.round((h.right - h.left) / 2 + h.left);
153
+ let p = Math.max(0, Math.round(u - s / 2));
154
+ p < e.left ? p = e.left : p + s > e.left + e.width && (p = e.left + e.width - s), r = { left: p, top: f, width: s, height: l };
155
+ } else {
156
+ const l = e.width, s = Math.round(l / a), f = Math.max(0, Math.round(e.left)), u = Math.round((h.bottom - h.top) / 2 + h.top);
157
+ let p = Math.max(0, Math.round(u - s / 2));
158
+ p < e.top ? p = e.top : p + s > e.top + e.height && (p = e.top + e.height - s), r = { left: f, top: p, width: l, height: s };
159
+ }
160
+ return {
161
+ width: o,
162
+ height: n,
163
+ rect: r
164
+ };
165
+ }
166
+ const _ = ["clip", "crop", "fill", "fillmax", "max", "scale", "min"], H = ["top", "bottom", "left", "right", "center", "focalpoint", "entropy"], j = ["format"];
167
+ function L(i) {
168
+ return i && "config" in i ? typeof i.config == "function" : !1;
169
+ }
170
+ function V(i) {
171
+ return i && "clientConfig" in i ? typeof i.clientConfig == "object" : !1;
172
+ }
173
+ function g(i) {
174
+ const { apiHost: t, projectId: r, dataset: o } = i, n = {
175
+ baseUrl: (t || "https://api.sanity.io").replace(/^https:\/\/api\./, "https://cdn.")
176
+ }, e = i["~experimental_resource"];
177
+ if (e?.type === "media-library") {
178
+ if (typeof e.id != "string" || e.id.length === 0)
179
+ throw new Error('Media library clients must include an id in "~experimental_resource"');
180
+ return { ...n, mediaLibraryId: e.id };
181
+ }
182
+ return { ...n, projectId: r, dataset: o };
183
+ }
184
+ function z(i) {
185
+ const t = O;
186
+ for (const r of t) {
187
+ const [o, n] = r;
188
+ if (i === o || i === n)
189
+ return o;
190
+ }
191
+ return i;
192
+ }
193
+ function $(i) {
194
+ let t = {};
195
+ return L(i) ? t = g(i.config()) : V(i) ? t = g(i.clientConfig) : t = i || {}, t;
196
+ }
197
+ function T(i, t) {
198
+ const r = $(t);
199
+ return new i(null, r);
200
+ }
201
+ function B(i) {
202
+ return T(d, i);
203
+ }
204
+ function W(i, t) {
205
+ const r = t.baseUrl || i.baseUrl, o = { baseUrl: r };
206
+ for (const n in t)
207
+ if (t.hasOwnProperty(n)) {
208
+ const e = z(n);
209
+ o[e] = t[n];
210
+ }
211
+ return { baseUrl: r, ...o };
212
+ }
213
+ class d {
214
+ constructor(t, r) {
215
+ c(this, "options");
216
+ this.options = t ? { ...t.options || {}, ...r || {} } : { ...r || {} };
217
+ }
218
+ withOptions(t) {
219
+ const r = W(this.options, t);
220
+ return new d(this, r);
221
+ }
222
+ // The image to be represented. Accepts a Sanity 'image'-document, 'asset'-document or
223
+ // _id of asset. To get the benefit of automatic hot-spot/crop integration with the content
224
+ // studio, the 'image'-document must be provided.
225
+ image(t) {
226
+ return this.withOptions({ source: t });
227
+ }
228
+ // Specify the dataset
229
+ dataset(t) {
230
+ return this.withOptions({ dataset: t });
231
+ }
232
+ // Specify the projectId
233
+ projectId(t) {
234
+ return this.withOptions({ projectId: t });
235
+ }
236
+ withClient(t) {
237
+ const r = $(t), o = { ...this.options };
238
+ return delete o.baseUrl, delete o.projectId, delete o.dataset, delete o.mediaLibraryId, new d(null, { ...r, ...o });
239
+ }
240
+ // Specify background color
241
+ bg(t) {
242
+ return this.withOptions({ bg: t });
243
+ }
244
+ // Set DPR scaling factor
245
+ dpr(t) {
246
+ return this.withOptions(t && t !== 1 ? { dpr: t } : {});
247
+ }
248
+ // Specify the width of the image in pixels
249
+ width(t) {
250
+ return this.withOptions({ width: t });
251
+ }
252
+ // Specify the height of the image in pixels
253
+ height(t) {
254
+ return this.withOptions({ height: t });
255
+ }
256
+ // Specify focal point in fraction of image dimensions. Each component 0.0-1.0
257
+ focalPoint(t, r) {
258
+ return this.withOptions({ focalPoint: { x: t, y: r } });
259
+ }
260
+ maxWidth(t) {
261
+ return this.withOptions({ maxWidth: t });
262
+ }
263
+ minWidth(t) {
264
+ return this.withOptions({ minWidth: t });
265
+ }
266
+ maxHeight(t) {
267
+ return this.withOptions({ maxHeight: t });
268
+ }
269
+ minHeight(t) {
270
+ return this.withOptions({ minHeight: t });
271
+ }
272
+ // Specify width and height in pixels
273
+ size(t, r) {
274
+ return this.withOptions({ width: t, height: r });
275
+ }
276
+ // Specify blur between 0 and 100
277
+ blur(t) {
278
+ return this.withOptions({ blur: t });
279
+ }
280
+ sharpen(t) {
281
+ return this.withOptions({ sharpen: t });
282
+ }
283
+ // Specify the desired rectangle of the image
284
+ rect(t, r, o, n) {
285
+ return this.withOptions({ rect: { left: t, top: r, width: o, height: n } });
286
+ }
287
+ // Specify the image format of the image. 'jpg', 'pjpg', 'png', 'webp'
288
+ format(t) {
289
+ return this.withOptions({ format: t });
290
+ }
291
+ invert(t) {
292
+ return this.withOptions({ invert: t });
293
+ }
294
+ // Rotation in degrees 0, 90, 180, 270
295
+ orientation(t) {
296
+ return this.withOptions({ orientation: t });
297
+ }
298
+ // Compression quality 0-100
299
+ quality(t) {
300
+ return this.withOptions({ quality: t });
301
+ }
302
+ // Make it a download link. Parameter is default filename.
303
+ forceDownload(t) {
304
+ return this.withOptions({ download: t });
305
+ }
306
+ // Flip image horizontally
307
+ flipHorizontal() {
308
+ return this.withOptions({ flipHorizontal: !0 });
309
+ }
310
+ // Flip image vertically
311
+ flipVertical() {
312
+ return this.withOptions({ flipVertical: !0 });
313
+ }
314
+ // Ignore crop/hotspot from image record, even when present
315
+ ignoreImageParams() {
316
+ return this.withOptions({ ignoreImageParams: !0 });
317
+ }
318
+ fit(t) {
319
+ if (_.indexOf(t) === -1)
320
+ throw new Error(`Invalid fit mode "${t}"`);
321
+ return this.withOptions({ fit: t });
322
+ }
323
+ crop(t) {
324
+ if (H.indexOf(t) === -1)
325
+ throw new Error(`Invalid crop mode "${t}"`);
326
+ return this.withOptions({ crop: t });
327
+ }
328
+ // Saturation
329
+ saturation(t) {
330
+ return this.withOptions({ saturation: t });
331
+ }
332
+ auto(t) {
333
+ if (j.indexOf(t) === -1)
334
+ throw new Error(`Invalid auto mode "${t}"`);
335
+ return this.withOptions({ auto: t });
336
+ }
337
+ // Specify the number of pixels to pad the image
338
+ pad(t) {
339
+ return this.withOptions({ pad: t });
340
+ }
341
+ // Vanity URL for more SEO friendly URLs
342
+ vanityName(t) {
343
+ return this.withOptions({ vanityName: t });
344
+ }
345
+ frame(t) {
346
+ if (t !== 1)
347
+ throw new Error(`Invalid frame value "${t}"`);
348
+ return this.withOptions({ frame: t });
349
+ }
350
+ // Gets the url based on the submitted parameters
351
+ url() {
352
+ return R(this.options);
353
+ }
354
+ // Alias for url()
355
+ toString() {
356
+ return this.url();
357
+ }
358
+ }
359
+ export {
360
+ B as c
361
+ };
@@ -0,0 +1,25 @@
1
+ import { c as h } from "./sanity.js";
2
+ const n = "m5ik5me8", a = "production", d = `https://${n}.api.sanity.io/v1/data/query/${a}`, f = {
3
+ async fetch(r, s) {
4
+ const c = JSON.stringify(s ? { query: r, params: s } : { query: r }), t = await fetch(d, { method: "POST", headers: { "Content-Type": "application/json" }, body: c }), e = await t.text().catch(() => "");
5
+ if (!t.ok)
6
+ try {
7
+ const i = JSON.parse(e)?.error?.description ?? e ?? t.statusText;
8
+ throw new Error(`Sanity fetch failed (${t.status}): ${i}`);
9
+ } catch {
10
+ throw new Error(`Sanity fetch failed (${t.status}): ${e || t.statusText}`);
11
+ }
12
+ let o;
13
+ try {
14
+ o = JSON.parse(e);
15
+ } catch {
16
+ throw new Error("Sanity returned a non-JSON response");
17
+ }
18
+ if (o?.error) throw new Error(`Sanity error: ${JSON.stringify(o.error)}`);
19
+ return o?.result ?? null;
20
+ }
21
+ }, u = h({ projectId: n, dataset: a }), S = (r) => u.image(r);
22
+ export {
23
+ f as s,
24
+ S as u
25
+ };