brease-client 0.2.0 → 0.2.1
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/README.md +1 -1
- package/dist/image.cjs +5 -27
- package/dist/image.d.cts +3 -4
- package/dist/image.d.ts +3 -4
- package/dist/image.js +6 -27
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,7 +151,7 @@ const props = imageProps(page.content.hero.image, { sizes: '(min-width: 768px) 5
|
|
|
151
151
|
// <img src={props.src} srcSet={props.srcSet} sizes={props.sizes} />
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
Brease files are served as-is from an S3 bucket, which doesn't resize images: the helpers return the URL unchanged with an empty `srcset`. For responsive images, let your framework resize them, e.g. `next/image` with the bucket's host in `images.remotePatterns`.
|
|
155
155
|
|
|
156
156
|
## Without JavaScript
|
|
157
157
|
|
package/dist/image.cjs
CHANGED
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/image.ts
|
|
4
|
-
var OBJECT_PATH = "/storage/v1/object/public/";
|
|
5
|
-
var RENDER_PATH = "/storage/v1/render/image/public/";
|
|
6
4
|
var DEFAULT_WIDTHS = [320, 640, 960, 1280, 1920];
|
|
7
|
-
function
|
|
8
|
-
return src
|
|
5
|
+
function imageUrl(src, _opts = {}) {
|
|
6
|
+
return src;
|
|
9
7
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
let url;
|
|
13
|
-
try {
|
|
14
|
-
url = new URL(src.replace(OBJECT_PATH, RENDER_PATH));
|
|
15
|
-
} catch {
|
|
16
|
-
return src;
|
|
17
|
-
}
|
|
18
|
-
if (opts.width) url.searchParams.set("width", String(Math.round(opts.width)));
|
|
19
|
-
if (opts.height) url.searchParams.set("height", String(Math.round(opts.height)));
|
|
20
|
-
if (opts.quality) url.searchParams.set("quality", String(opts.quality));
|
|
21
|
-
if (opts.resize) url.searchParams.set("resize", opts.resize);
|
|
22
|
-
return url.toString();
|
|
23
|
-
}
|
|
24
|
-
function srcset(src, opts = {}) {
|
|
25
|
-
if (!isSupabaseImage(src)) return "";
|
|
26
|
-
return (opts.widths ?? DEFAULT_WIDTHS).map((w) => `${imageUrl(src, { width: w, quality: opts.quality, resize: opts.resize })} ${w}w`).join(", ");
|
|
8
|
+
function srcset(_src, _opts = {}) {
|
|
9
|
+
return "";
|
|
27
10
|
}
|
|
28
11
|
function imageProps(src, opts = {}) {
|
|
29
|
-
return {
|
|
30
|
-
src: imageUrl(src, { width: opts.width, height: opts.height, quality: opts.quality }),
|
|
31
|
-
srcSet: srcset(src, { widths: opts.widths, quality: opts.quality }),
|
|
32
|
-
sizes: opts.sizes ?? "100vw"
|
|
33
|
-
};
|
|
12
|
+
return { src: imageUrl(src), srcSet: srcset(), sizes: opts.sizes ?? "100vw" };
|
|
34
13
|
}
|
|
35
14
|
|
|
36
15
|
exports.DEFAULT_WIDTHS = DEFAULT_WIDTHS;
|
|
37
16
|
exports.imageProps = imageProps;
|
|
38
17
|
exports.imageUrl = imageUrl;
|
|
39
|
-
exports.isSupabaseImage = isSupabaseImage;
|
|
40
18
|
exports.srcset = srcset;
|
package/dist/image.d.cts
CHANGED
|
@@ -6,9 +6,8 @@ type ImageOptions = {
|
|
|
6
6
|
resize?: Resize;
|
|
7
7
|
};
|
|
8
8
|
declare const DEFAULT_WIDTHS: number[];
|
|
9
|
-
declare function
|
|
10
|
-
declare function
|
|
11
|
-
declare function srcset(src: string, opts?: {
|
|
9
|
+
declare function imageUrl(src: string, _opts?: ImageOptions): string;
|
|
10
|
+
declare function srcset(_src: string, _opts?: {
|
|
12
11
|
widths?: number[];
|
|
13
12
|
quality?: number;
|
|
14
13
|
resize?: Resize;
|
|
@@ -25,4 +24,4 @@ declare function imageProps(src: string, opts?: {
|
|
|
25
24
|
sizes: string;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl,
|
|
27
|
+
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, srcset };
|
package/dist/image.d.ts
CHANGED
|
@@ -6,9 +6,8 @@ type ImageOptions = {
|
|
|
6
6
|
resize?: Resize;
|
|
7
7
|
};
|
|
8
8
|
declare const DEFAULT_WIDTHS: number[];
|
|
9
|
-
declare function
|
|
10
|
-
declare function
|
|
11
|
-
declare function srcset(src: string, opts?: {
|
|
9
|
+
declare function imageUrl(src: string, _opts?: ImageOptions): string;
|
|
10
|
+
declare function srcset(_src: string, _opts?: {
|
|
12
11
|
widths?: number[];
|
|
13
12
|
quality?: number;
|
|
14
13
|
resize?: Resize;
|
|
@@ -25,4 +24,4 @@ declare function imageProps(src: string, opts?: {
|
|
|
25
24
|
sizes: string;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl,
|
|
27
|
+
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, srcset };
|
package/dist/image.js
CHANGED
|
@@ -1,36 +1,15 @@
|
|
|
1
1
|
import './chunk-PKBMQBKP.js';
|
|
2
2
|
|
|
3
3
|
// src/image.ts
|
|
4
|
-
var OBJECT_PATH = "/storage/v1/object/public/";
|
|
5
|
-
var RENDER_PATH = "/storage/v1/render/image/public/";
|
|
6
4
|
var DEFAULT_WIDTHS = [320, 640, 960, 1280, 1920];
|
|
7
|
-
function
|
|
8
|
-
return src
|
|
5
|
+
function imageUrl(src, _opts = {}) {
|
|
6
|
+
return src;
|
|
9
7
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
let url;
|
|
13
|
-
try {
|
|
14
|
-
url = new URL(src.replace(OBJECT_PATH, RENDER_PATH));
|
|
15
|
-
} catch {
|
|
16
|
-
return src;
|
|
17
|
-
}
|
|
18
|
-
if (opts.width) url.searchParams.set("width", String(Math.round(opts.width)));
|
|
19
|
-
if (opts.height) url.searchParams.set("height", String(Math.round(opts.height)));
|
|
20
|
-
if (opts.quality) url.searchParams.set("quality", String(opts.quality));
|
|
21
|
-
if (opts.resize) url.searchParams.set("resize", opts.resize);
|
|
22
|
-
return url.toString();
|
|
23
|
-
}
|
|
24
|
-
function srcset(src, opts = {}) {
|
|
25
|
-
if (!isSupabaseImage(src)) return "";
|
|
26
|
-
return (opts.widths ?? DEFAULT_WIDTHS).map((w) => `${imageUrl(src, { width: w, quality: opts.quality, resize: opts.resize })} ${w}w`).join(", ");
|
|
8
|
+
function srcset(_src, _opts = {}) {
|
|
9
|
+
return "";
|
|
27
10
|
}
|
|
28
11
|
function imageProps(src, opts = {}) {
|
|
29
|
-
return {
|
|
30
|
-
src: imageUrl(src, { width: opts.width, height: opts.height, quality: opts.quality }),
|
|
31
|
-
srcSet: srcset(src, { widths: opts.widths, quality: opts.quality }),
|
|
32
|
-
sizes: opts.sizes ?? "100vw"
|
|
33
|
-
};
|
|
12
|
+
return { src: imageUrl(src), srcSet: srcset(), sizes: opts.sizes ?? "100vw" };
|
|
34
13
|
}
|
|
35
14
|
|
|
36
|
-
export { DEFAULT_WIDTHS, imageProps, imageUrl,
|
|
15
|
+
export { DEFAULT_WIDTHS, imageProps, imageUrl, srcset };
|
package/dist/next.cjs
CHANGED
|
@@ -37,7 +37,7 @@ function toMetadata(seo, opts = {}) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
function breaseFetch(tags = [], revalidate) {
|
|
40
|
-
return (input, init) => fetch(input, {
|
|
40
|
+
return (input, init) => env("BREASE_PREVIEW") ? fetch(input, { ...init, cache: "no-store" }) : fetch(input, {
|
|
41
41
|
...init,
|
|
42
42
|
next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
|
|
43
43
|
});
|
package/dist/next.js
CHANGED
|
@@ -31,7 +31,7 @@ function toMetadata(seo, opts = {}) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
function breaseFetch(tags = [], revalidate) {
|
|
34
|
-
return (input, init) => fetch(input, {
|
|
34
|
+
return (input, init) => env("BREASE_PREVIEW") ? fetch(input, { ...init, cache: "no-store" }) : fetch(input, {
|
|
35
35
|
...init,
|
|
36
36
|
next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
|
|
37
37
|
});
|