@pracht/image 0.2.0 → 0.3.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.
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
//#region src/loaders.ts
|
|
2
2
|
const DEFAULT_QUALITY = 75;
|
|
3
|
+
function normalizeDeployBase(raw) {
|
|
4
|
+
if (typeof raw !== "string" || raw === "" || raw === "." || raw === "./") return "/";
|
|
5
|
+
if (raw.includes("://") || raw.startsWith("//")) return "/";
|
|
6
|
+
const withLeadingSlash = raw.startsWith("/") ? raw : `/${raw}`;
|
|
7
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
8
|
+
}
|
|
9
|
+
function withDeployBase(path) {
|
|
10
|
+
if (!path.startsWith("/") || path.startsWith("//")) return path;
|
|
11
|
+
const base = normalizeDeployBase(import.meta.env?.BASE_URL);
|
|
12
|
+
return base === "/" ? path : `${base}${path.slice(1)}`;
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* The default optimization endpoint. It maps onto an API route file at
|
|
5
16
|
* `src/api/_pracht/image.ts` that re-exports the handler from
|
|
@@ -11,7 +22,7 @@ const DEFAULT_IMAGE_ENDPOINT = "/api/_pracht/image";
|
|
|
11
22
|
* handler is mounted somewhere other than {@link DEFAULT_IMAGE_ENDPOINT}.
|
|
12
23
|
*/
|
|
13
24
|
function createDefaultLoader(endpoint = DEFAULT_IMAGE_ENDPOINT) {
|
|
14
|
-
return ({ src, width, quality }) => `${endpoint}?url=${encodeURIComponent(src)}&w=${width}&q=${quality ?? 75}`;
|
|
25
|
+
return ({ src, width, quality }) => `${withDeployBase(endpoint)}?url=${encodeURIComponent(src)}&w=${width}&q=${quality ?? 75}`;
|
|
15
26
|
}
|
|
16
27
|
/**
|
|
17
28
|
* Targets the pracht image endpoint served by `createImageHandler()` from
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as resetImageConfig, c as cloudflareLoader, d as passthroughLoader, f as vercelLoader, i as getImageConfig, l as createDefaultLoader, n as DEFAULT_IMAGE_SIZES, o as DEFAULT_IMAGE_ENDPOINT, r as configureImage, s as DEFAULT_QUALITY, t as DEFAULT_DEVICE_SIZES, u as defaultLoader } from "./config-
|
|
1
|
+
import { a as resetImageConfig, c as cloudflareLoader, d as passthroughLoader, f as vercelLoader, i as getImageConfig, l as createDefaultLoader, n as DEFAULT_IMAGE_SIZES, o as DEFAULT_IMAGE_ENDPOINT, r as configureImage, s as DEFAULT_QUALITY, t as DEFAULT_DEVICE_SIZES, u as defaultLoader } from "./config-HOu7M27N.mjs";
|
|
2
2
|
import { h } from "preact";
|
|
3
3
|
//#region src/image.ts
|
|
4
4
|
const FILL_STYLE = {
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as DEFAULT_IMAGE_SIZES, t as DEFAULT_DEVICE_SIZES } from "./config-
|
|
1
|
+
import { n as DEFAULT_IMAGE_SIZES, t as DEFAULT_DEVICE_SIZES } from "./config-HOu7M27N.mjs";
|
|
2
2
|
//#region src/node.ts
|
|
3
3
|
const SHARP_INSTALL_HINT = "Image optimization requires the optional \"sharp\" dependency. Install it in your app with \"pnpm add sharp\" (or npm install / yarn add) to enable the pracht image endpoint.";
|
|
4
4
|
const DEFAULT_CACHE_CONTROL = "public, max-age=14400, must-revalidate";
|