@nonphoto/sanity-image 0.0.4 → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Jonas Luebbers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,41 @@
1
+ import { SanityAsset, SanityImageDimensions, SanityImageCrop, SanityImageHotspot, SanityClientLike, SanityProjectDetails, SanityModernClientLike } from '@sanity/image-url/lib/types/types.js';
2
+
3
+ type SanityAssetWithMetadata = SanityAsset & {
4
+ metadata?: {
5
+ lqip?: string;
6
+ dimensions?: SanityImageDimensions;
7
+ };
8
+ };
9
+ interface SanityImageObjectWithMetadata {
10
+ asset: SanityAssetWithMetadata;
11
+ crop?: SanityImageCrop;
12
+ hotspot?: SanityImageHotspot;
13
+ }
14
+ type Size = {
15
+ width: number;
16
+ height: number;
17
+ };
18
+ declare const defaultWidths: number[];
19
+ declare const lowResWidth = 24;
20
+ declare const defaultMetaImageWidth = 1200;
21
+ declare const defaultQuality = 90;
22
+ declare function imageProps({ image, client, widths, quality, aspectRatio, }: {
23
+ image: SanityImageObjectWithMetadata;
24
+ client: SanityClientLike | SanityProjectDetails | SanityModernClientLike;
25
+ widths: number[];
26
+ quality?: number;
27
+ aspectRatio?: number;
28
+ }): {
29
+ src: string;
30
+ srcset: string;
31
+ naturalWidth?: number;
32
+ naturalHeight?: number;
33
+ };
34
+ declare function metaImageUrl({ image, client, width, quality, }: {
35
+ image: SanityImageObjectWithMetadata;
36
+ client: SanityClientLike | SanityProjectDetails | SanityModernClientLike;
37
+ width: number;
38
+ quality?: number;
39
+ }): string;
40
+
41
+ export { type SanityAssetWithMetadata, type SanityImageObjectWithMetadata, type Size, defaultMetaImageWidth, defaultQuality, defaultWidths, imageProps, lowResWidth, metaImageUrl };
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ // src/index.ts
2
+ import imageUrlBuilder from "@sanity/image-url";
3
+ var defaultWidths = [
4
+ 6016,
5
+ // 6K
6
+ 5120,
7
+ // 5K
8
+ 4480,
9
+ // 4.5K
10
+ 3840,
11
+ // 4K
12
+ 3200,
13
+ // QHD+
14
+ 2560,
15
+ // WQXGA
16
+ 2048,
17
+ // QXGA
18
+ 1920,
19
+ // 1080p
20
+ 1668,
21
+ // iPad
22
+ 1280,
23
+ // 720p
24
+ 1080,
25
+ // iPhone 6-8 Plus
26
+ 960,
27
+ 720,
28
+ // iPhone 6-8
29
+ 640,
30
+ // 480p
31
+ 480,
32
+ 360,
33
+ 240
34
+ ];
35
+ var lowResWidth = 24;
36
+ var defaultMetaImageWidth = 1200;
37
+ var defaultQuality = 90;
38
+ var fitComparators = {
39
+ cover: Math.max,
40
+ contain: Math.min,
41
+ mean: (a, b) => (a + b) / 2
42
+ };
43
+ function fit(containee, container, mode) {
44
+ const sx = container.width / containee.width;
45
+ const sy = container.height / containee.height;
46
+ const s = fitComparators[mode](sx, sy);
47
+ return {
48
+ width: containee.width * s,
49
+ height: containee.height * s
50
+ };
51
+ }
52
+ function buildAspectRatio(builder, width, aspectRatio) {
53
+ if (aspectRatio) {
54
+ return builder.width(width).height(Math.round(width * aspectRatio));
55
+ } else {
56
+ return builder.width(width);
57
+ }
58
+ }
59
+ function imageProps({
60
+ image,
61
+ client,
62
+ widths,
63
+ quality = defaultQuality,
64
+ aspectRatio
65
+ }) {
66
+ const sortedWidths = Array.from(widths).sort((a, b) => a - b);
67
+ const builder = imageUrlBuilder(client).image(image).quality(quality).auto("format");
68
+ const metadata = image.asset.metadata;
69
+ const cropSize = metadata?.dimensions ? image.crop ? {
70
+ width: metadata.dimensions.width - image.crop.left - image.crop.right,
71
+ height: metadata.dimensions.height - image.crop.top - image.crop.bottom
72
+ } : metadata.dimensions : void 0;
73
+ const naturalSize = cropSize ? aspectRatio ? fit({ width: 1, height: aspectRatio }, cropSize, "contain") : cropSize : void 0;
74
+ return {
75
+ src: metadata?.lqip ?? buildAspectRatio(builder, lowResWidth, aspectRatio).url(),
76
+ srcset: sortedWidths.map(
77
+ (width) => `${buildAspectRatio(builder, width, aspectRatio).url()} ${width}w`
78
+ ).join(","),
79
+ naturalWidth: naturalSize?.width,
80
+ naturalHeight: naturalSize?.height
81
+ };
82
+ }
83
+ function metaImageUrl({
84
+ image,
85
+ client,
86
+ width = defaultMetaImageWidth,
87
+ quality = defaultQuality
88
+ }) {
89
+ return imageUrlBuilder(client).image(image).quality(quality).auto("format").width(width).url();
90
+ }
91
+ export {
92
+ defaultMetaImageWidth,
93
+ defaultQuality,
94
+ defaultWidths,
95
+ imageProps,
96
+ lowResWidth,
97
+ metaImageUrl
98
+ };
package/package.json CHANGED
@@ -1,41 +1,48 @@
1
1
  {
2
2
  "name": "@nonphoto/sanity-image",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
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",
5
+ "sideEffects": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
12
9
  "exports": {
13
- "types": "./index.d.ts",
14
- "import": "./dist/counter.js",
15
- "require": "./dist/counter.umd.cjs"
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "./src/*": "./src/*"
16
17
  },
18
+ "files": [
19
+ "./dist/*",
20
+ "./src/*"
21
+ ],
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
17
24
  "scripts": {
18
- "dev": "vite",
19
- "build": "tsc && vite build"
25
+ "prepare": "pnpm build",
26
+ "build": "tsup ./src/index.ts --dts --format esm --clean",
27
+ "release": "semantic-release"
20
28
  },
29
+ "keywords": [
30
+ "spring",
31
+ "physics",
32
+ "animation"
33
+ ],
34
+ "author": "Jonas Luebbers <jonas@jonasluebbers.com> (https://www.jonasluebbers.com)",
35
+ "license": "MIT",
21
36
  "devDependencies": {
22
- "@types/node": "18.14.6",
23
- "auto": "10.43.0",
24
- "typescript": "^4.9.4",
25
- "vite": "^4.0.4"
37
+ "semantic-release": "24.2.3",
38
+ "tsup": "8.4.0",
39
+ "typescript": "5.8.2"
40
+ },
41
+ "engines": {
42
+ "node": ">=20",
43
+ "pnpm": ">=9"
26
44
  },
27
45
  "dependencies": {
28
46
  "@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
47
  }
41
48
  }
package/src/index.ts ADDED
@@ -0,0 +1,164 @@
1
+ import imageUrlBuilder from "@sanity/image-url";
2
+ import { ImageUrlBuilder } from "@sanity/image-url/lib/types/builder";
3
+ import type {
4
+ SanityAsset,
5
+ SanityClientLike,
6
+ SanityImageCrop,
7
+ SanityImageDimensions,
8
+ SanityImageHotspot,
9
+ SanityModernClientLike,
10
+ SanityProjectDetails,
11
+ } from "@sanity/image-url/lib/types/types.js";
12
+
13
+ export type SanityAssetWithMetadata = SanityAsset & {
14
+ metadata?: {
15
+ lqip?: string;
16
+ dimensions?: SanityImageDimensions;
17
+ };
18
+ };
19
+
20
+ export interface SanityImageObjectWithMetadata {
21
+ asset: SanityAssetWithMetadata;
22
+ crop?: SanityImageCrop;
23
+ hotspot?: SanityImageHotspot;
24
+ }
25
+
26
+ export type Size = {
27
+ width: number;
28
+ height: number;
29
+ };
30
+
31
+ export const defaultWidths = [
32
+ 6016, // 6K
33
+ 5120, // 5K
34
+ 4480, // 4.5K
35
+ 3840, // 4K
36
+ 3200, // QHD+
37
+ 2560, // WQXGA
38
+ 2048, // QXGA
39
+ 1920, // 1080p
40
+ 1668, // iPad
41
+ 1280, // 720p
42
+ 1080, // iPhone 6-8 Plus
43
+ 960,
44
+ 720, // iPhone 6-8
45
+ 640, // 480p
46
+ 480,
47
+ 360,
48
+ 240,
49
+ ];
50
+
51
+ export const lowResWidth = 24;
52
+
53
+ export const defaultMetaImageWidth = 1200;
54
+
55
+ export const defaultQuality = 90;
56
+
57
+ const fitComparators = {
58
+ cover: Math.max,
59
+ contain: Math.min,
60
+ mean: (a: number, b: number) => (a + b) / 2,
61
+ };
62
+
63
+ function fit(
64
+ containee: Size,
65
+ container: Size,
66
+ mode: keyof typeof fitComparators
67
+ ) {
68
+ const sx = container.width / containee.width;
69
+ const sy = container.height / containee.height;
70
+ const s = fitComparators[mode](sx, sy);
71
+ return {
72
+ width: containee.width * s,
73
+ height: containee.height * s,
74
+ };
75
+ }
76
+
77
+ function buildAspectRatio(
78
+ builder: ImageUrlBuilder,
79
+ width: number,
80
+ aspectRatio?: number
81
+ ) {
82
+ if (aspectRatio) {
83
+ return builder.width(width).height(Math.round(width * aspectRatio));
84
+ } else {
85
+ return builder.width(width);
86
+ }
87
+ }
88
+
89
+ export function imageProps({
90
+ image,
91
+ client,
92
+ widths,
93
+ quality = defaultQuality,
94
+ aspectRatio,
95
+ }: {
96
+ image: SanityImageObjectWithMetadata;
97
+ client: SanityClientLike | SanityProjectDetails | SanityModernClientLike;
98
+ widths: number[];
99
+ quality?: number;
100
+ aspectRatio?: number;
101
+ }): {
102
+ src: string;
103
+ srcset: string;
104
+ naturalWidth?: number;
105
+ naturalHeight?: number;
106
+ } {
107
+ const sortedWidths = Array.from(widths).sort((a, b) => a - b);
108
+
109
+ const builder = imageUrlBuilder(client)
110
+ .image(image)
111
+ .quality(quality)
112
+ .auto("format");
113
+
114
+ const metadata = image.asset.metadata;
115
+
116
+ const cropSize = metadata?.dimensions
117
+ ? image.crop
118
+ ? {
119
+ width: metadata.dimensions.width - image.crop.left - image.crop.right,
120
+ height:
121
+ metadata.dimensions.height - image.crop.top - image.crop.bottom,
122
+ }
123
+ : metadata.dimensions
124
+ : undefined;
125
+
126
+ const naturalSize = cropSize
127
+ ? aspectRatio
128
+ ? fit({ width: 1, height: aspectRatio }, cropSize, "contain")
129
+ : cropSize
130
+ : undefined;
131
+
132
+ return {
133
+ src:
134
+ metadata?.lqip ??
135
+ buildAspectRatio(builder, lowResWidth, aspectRatio).url(),
136
+ srcset: sortedWidths
137
+ .map(
138
+ (width) =>
139
+ `${buildAspectRatio(builder, width, aspectRatio).url()} ${width}w`
140
+ )
141
+ .join(","),
142
+ naturalWidth: naturalSize?.width,
143
+ naturalHeight: naturalSize?.height,
144
+ };
145
+ }
146
+
147
+ export function metaImageUrl({
148
+ image,
149
+ client,
150
+ width = defaultMetaImageWidth,
151
+ quality = defaultQuality,
152
+ }: {
153
+ image: SanityImageObjectWithMetadata;
154
+ client: SanityClientLike | SanityProjectDetails | SanityModernClientLike;
155
+ width: number;
156
+ quality?: number;
157
+ }) {
158
+ return imageUrlBuilder(client)
159
+ .image(image)
160
+ .quality(quality)
161
+ .auto("format")
162
+ .width(width)
163
+ .url();
164
+ }
@@ -1,481 +0,0 @@
1
- var $ = 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(f) {
6
- P = f;
7
- }
8
- };
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
- 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
- }, s.apply(this, arguments);
22
- }
23
- function v(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 = v(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 d = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
60
- function u(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 "` + 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
- return {
68
- id: n,
69
- width: c,
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
- }, U = 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" && q(t))
89
- i = {
90
- asset: {
91
- _ref: E(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 (U(t))
105
- i = {
106
- asset: {
107
- _ref: t._id || ""
108
- }
109
- };
110
- else if (O(t))
111
- i = {
112
- asset: {
113
- _ref: E(t.asset.url)
114
- }
115
- };
116
- else if (typeof t.asset == "object")
117
- i = s({}, t);
118
- else
119
- return null;
120
- var n = t;
121
- return n.crop && (i.crop = n.crop), n.hotspot && (i.hotspot = n.hotspot), z(i);
122
- }
123
- function q(t) {
124
- return /^https?:\/\//.test("" + t);
125
- }
126
- function E(t) {
127
- var i = t.split("/").slice(-1);
128
- return ("image-" + i[0]).replace(/\.([a-z]+)$/, "-$1");
129
- }
130
- function z(t) {
131
- if (t.crop && t.hotspot)
132
- return t;
133
- var i = s({}, 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 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
- function _(t) {
148
- var i = s({}, 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 = u(o), a = Math.round(r.crop.left * e.width), h = Math.round(r.crop.top * e.height), c = {
154
- left: a,
155
- top: h,
156
- width: Math.round(e.width - r.crop.right * e.width - a),
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
- };
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
- 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, 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
- }
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 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
- }), 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, 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
- height: l
200
- };
201
- } else {
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
- top: x,
206
- width: b,
207
- height: j
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 D(t) {
218
- return t && "config" in t ? typeof t.config == "function" : !1;
219
- }
220
- function G(t) {
221
- return t && "clientConfig" in t ? typeof t.clientConfig == "object" : !1;
222
- }
223
- function X(t) {
224
- for (var i = R, 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 Y(t) {
232
- if (D(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 (G(a)) {
242
- var h = a.clientConfig, c = h.apiHost, l = h.projectId, p = h.dataset, m = c || "https://api.sanity.io";
243
- return new H(null, {
244
- baseUrl: m.replace(/^https:\/\/api\./, "https://cdn."),
245
- projectId: l,
246
- dataset: p
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 ? s({}, n.options || {}, r || {}) : s({}, 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 h = X(a);
263
- e[h] = r[a];
264
- }
265
- return new t(this, s({
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 Y;
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(f, y, s) {
441
- return f ? f * (1 - (y ?? 0) - (s ?? 0)) : void 0;
442
- }
443
- function rt({
444
- image: f,
445
- client: y,
446
- widths: s,
447
- quality: v = T
448
- }) {
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
- return {
452
- src: (d == null ? void 0 : d.lqip) ?? M.width(K).url().toString(),
453
- srcset: I.map((O) => `${M.width(O).url()} ${O}w`).join(","),
454
- naturalWidth: W(
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
- ),
459
- naturalHeight: W(
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
- )
464
- };
465
- }
466
- function it({
467
- image: f,
468
- client: y,
469
- width: s = Z,
470
- quality: v = T
471
- }) {
472
- return C(y).image(f).quality(v).auto("format").width(s).url();
473
- }
474
- export {
475
- Z as defaultMetaImageWidth,
476
- T as defaultQuality,
477
- tt as defaultWidths,
478
- rt as imageProps,
479
- K as lowResWidth,
480
- it as metaImageUrl
481
- };
@@ -1,2 +0,0 @@
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/dist/vite.svg DELETED
@@ -1 +0,0 @@
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>