@gigadrive/network-config 4.3.1 → 4.3.2
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.
|
@@ -23,11 +23,12 @@ __export(nextjs_image_loader_exports, {
|
|
|
23
23
|
default: () => gigadriveNextImageLoader
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(nextjs_image_loader_exports);
|
|
26
|
+
var sourcePathname = (source) => source.startsWith("http://") || source.startsWith("https://") ? new URL(source).pathname : source.split(/[?#]/, 1)[0];
|
|
26
27
|
var filenameHint = (source) => {
|
|
27
|
-
const
|
|
28
|
-
const candidate = pathname.split("/").filter(Boolean).at(-1)?.split("?")[0] ?? "image";
|
|
28
|
+
const candidate = sourcePathname(source).split("/").filter(Boolean).at(-1) ?? "image";
|
|
29
29
|
return /\.(?:avif|bmp|gif|hei[cf]|jpe?g|pbm|png|svg|tga|tiff?|webp)$/i.test(candidate) ? candidate : `${candidate || "image"}.png`;
|
|
30
30
|
};
|
|
31
|
+
var isSvgSource = (source) => /\.svg$/i.test(sourcePathname(source));
|
|
31
32
|
var MAXIMUM_OPTIMIZER_URL_LENGTH = 2e3;
|
|
32
33
|
var stripDeploymentMarker = (src) => {
|
|
33
34
|
if (!src.startsWith("/") || !src.includes("?")) return src;
|
|
@@ -38,6 +39,7 @@ var stripDeploymentMarker = (src) => {
|
|
|
38
39
|
return remaining ? `${pathname}?${remaining}` : pathname;
|
|
39
40
|
};
|
|
40
41
|
function gigadriveNextImageLoader({ src, width, quality }) {
|
|
42
|
+
if (isSvgSource(src)) return src;
|
|
41
43
|
const stableSrc = stripDeploymentMarker(src);
|
|
42
44
|
const parameters = new URLSearchParams({ width: String(width) });
|
|
43
45
|
if (quality !== void 0) parameters.set("quality", String(quality));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nextjs-image-loader.ts"],"sourcesContent":["interface NextImageLoaderOptions {\n src: string;\n width: number;\n quality?: number;\n}\n\nconst
|
|
1
|
+
{"version":3,"sources":["../src/nextjs-image-loader.ts"],"sourcesContent":["interface NextImageLoaderOptions {\n src: string;\n width: number;\n quality?: number;\n}\n\n/** The path portion of a source, with any query string or fragment removed. */\nconst sourcePathname = (source: string): string =>\n source.startsWith('http://') || source.startsWith('https://') ? new URL(source).pathname : source.split(/[?#]/, 1)[0];\n\nconst filenameHint = (source: string): string => {\n const candidate = sourcePathname(source).split('/').filter(Boolean).at(-1) ?? 'image';\n return /\\.(?:avif|bmp|gif|hei[cf]|jpe?g|pbm|png|svg|tga|tiff?|webp)$/i.test(candidate)\n ? candidate\n : `${candidate || 'image'}.png`;\n};\n\nconst isSvgSource = (source: string): boolean => /\\.svg$/i.test(sourcePathname(source));\n\n// Conservative bound below common CDN/proxy URL limits (~4-8 KB). The encoded\n// source is embedded in the optimizer path, so an oversized source URL cannot\n// be shortened losslessly — such images are served unoptimized instead.\nconst MAXIMUM_OPTIMIZER_URL_LENGTH = 2000;\n\n/**\n * Removes Next's `dpl` deployment marker from a local source.\n *\n * Next appends `?dpl=<deploymentId>` to local asset sources whenever a\n * deployment id is configured. The Gigadrive optimizer resolves the deployment\n * from the request hostname and never reads `dpl`, so keeping it only changes\n * the optimizer URL on every deploy — invalidating the CDN's image cache for\n * files whose content-hashed names already guarantee freshness, and forcing a\n * full re-optimization burst after each release.\n */\nconst stripDeploymentMarker = (src: string): string => {\n if (!src.startsWith('/') || !src.includes('?')) return src;\n const [pathname, query] = src.split('?', 2);\n const parameters = new URLSearchParams(query);\n parameters.delete('dpl');\n const remaining = parameters.toString();\n return remaining ? `${pathname}?${remaining}` : pathname;\n};\n\n/** Builds the stable app-host URL consumed by Gigadrive's managed image optimizer. */\nexport default function gigadriveNextImageLoader({ src, width, quality }: NextImageLoaderOptions): string {\n // No optimizer backend can rasterize SVG, so routing one through the optimizer\n // is always a pass-through: a wasted redirect and an extra request for bytes\n // the origin already serves. Next's own get-img-props marks `.svg` unoptimized\n // before any loader runs, but that bypass is skipped once a custom loaderFile\n // is configured — which is exactly what this adapter injects.\n if (isSvgSource(src)) return src;\n\n const stableSrc = stripDeploymentMarker(src);\n const parameters = new URLSearchParams({ width: String(width) });\n if (quality !== undefined) parameters.set('quality', String(quality));\n const optimizerUrl = `/_gigadrive/image/${encodeURIComponent(stableSrc)}/${encodeURIComponent(filenameHint(stableSrc))}?${parameters}`;\n return optimizerUrl.length > MAXIMUM_OPTIMIZER_URL_LENGTH ? src : optimizerUrl;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,IAAM,iBAAiB,CAAC,WACtB,OAAO,WAAW,SAAS,KAAK,OAAO,WAAW,UAAU,IAAI,IAAI,IAAI,MAAM,EAAE,WAAW,OAAO,MAAM,QAAQ,CAAC,EAAE,CAAC;AAEtH,IAAM,eAAe,CAAC,WAA2B;AAC/C,QAAM,YAAY,eAAe,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE,KAAK;AAC9E,SAAO,gEAAgE,KAAK,SAAS,IACjF,YACA,GAAG,aAAa,OAAO;AAC7B;AAEA,IAAM,cAAc,CAAC,WAA4B,UAAU,KAAK,eAAe,MAAM,CAAC;AAKtF,IAAM,+BAA+B;AAYrC,IAAM,wBAAwB,CAAC,QAAwB;AACrD,MAAI,CAAC,IAAI,WAAW,GAAG,KAAK,CAAC,IAAI,SAAS,GAAG,EAAG,QAAO;AACvD,QAAM,CAAC,UAAU,KAAK,IAAI,IAAI,MAAM,KAAK,CAAC;AAC1C,QAAM,aAAa,IAAI,gBAAgB,KAAK;AAC5C,aAAW,OAAO,KAAK;AACvB,QAAM,YAAY,WAAW,SAAS;AACtC,SAAO,YAAY,GAAG,QAAQ,IAAI,SAAS,KAAK;AAClD;AAGe,SAAR,yBAA0C,EAAE,KAAK,OAAO,QAAQ,GAAmC;AAMxG,MAAI,YAAY,GAAG,EAAG,QAAO;AAE7B,QAAM,YAAY,sBAAsB,GAAG;AAC3C,QAAM,aAAa,IAAI,gBAAgB,EAAE,OAAO,OAAO,KAAK,EAAE,CAAC;AAC/D,MAAI,YAAY,OAAW,YAAW,IAAI,WAAW,OAAO,OAAO,CAAC;AACpE,QAAM,eAAe,qBAAqB,mBAAmB,SAAS,CAAC,IAAI,mBAAmB,aAAa,SAAS,CAAC,CAAC,IAAI,UAAU;AACpI,SAAO,aAAa,SAAS,+BAA+B,MAAM;AACpE;","names":[]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// src/nextjs-image-loader.ts
|
|
2
|
+
var sourcePathname = (source) => source.startsWith("http://") || source.startsWith("https://") ? new URL(source).pathname : source.split(/[?#]/, 1)[0];
|
|
2
3
|
var filenameHint = (source) => {
|
|
3
|
-
const
|
|
4
|
-
const candidate = pathname.split("/").filter(Boolean).at(-1)?.split("?")[0] ?? "image";
|
|
4
|
+
const candidate = sourcePathname(source).split("/").filter(Boolean).at(-1) ?? "image";
|
|
5
5
|
return /\.(?:avif|bmp|gif|hei[cf]|jpe?g|pbm|png|svg|tga|tiff?|webp)$/i.test(candidate) ? candidate : `${candidate || "image"}.png`;
|
|
6
6
|
};
|
|
7
|
+
var isSvgSource = (source) => /\.svg$/i.test(sourcePathname(source));
|
|
7
8
|
var MAXIMUM_OPTIMIZER_URL_LENGTH = 2e3;
|
|
8
9
|
var stripDeploymentMarker = (src) => {
|
|
9
10
|
if (!src.startsWith("/") || !src.includes("?")) return src;
|
|
@@ -14,6 +15,7 @@ var stripDeploymentMarker = (src) => {
|
|
|
14
15
|
return remaining ? `${pathname}?${remaining}` : pathname;
|
|
15
16
|
};
|
|
16
17
|
function gigadriveNextImageLoader({ src, width, quality }) {
|
|
18
|
+
if (isSvgSource(src)) return src;
|
|
17
19
|
const stableSrc = stripDeploymentMarker(src);
|
|
18
20
|
const parameters = new URLSearchParams({ width: String(width) });
|
|
19
21
|
if (quality !== void 0) parameters.set("quality", String(quality));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nextjs-image-loader.ts"],"sourcesContent":["interface NextImageLoaderOptions {\n src: string;\n width: number;\n quality?: number;\n}\n\nconst
|
|
1
|
+
{"version":3,"sources":["../src/nextjs-image-loader.ts"],"sourcesContent":["interface NextImageLoaderOptions {\n src: string;\n width: number;\n quality?: number;\n}\n\n/** The path portion of a source, with any query string or fragment removed. */\nconst sourcePathname = (source: string): string =>\n source.startsWith('http://') || source.startsWith('https://') ? new URL(source).pathname : source.split(/[?#]/, 1)[0];\n\nconst filenameHint = (source: string): string => {\n const candidate = sourcePathname(source).split('/').filter(Boolean).at(-1) ?? 'image';\n return /\\.(?:avif|bmp|gif|hei[cf]|jpe?g|pbm|png|svg|tga|tiff?|webp)$/i.test(candidate)\n ? candidate\n : `${candidate || 'image'}.png`;\n};\n\nconst isSvgSource = (source: string): boolean => /\\.svg$/i.test(sourcePathname(source));\n\n// Conservative bound below common CDN/proxy URL limits (~4-8 KB). The encoded\n// source is embedded in the optimizer path, so an oversized source URL cannot\n// be shortened losslessly — such images are served unoptimized instead.\nconst MAXIMUM_OPTIMIZER_URL_LENGTH = 2000;\n\n/**\n * Removes Next's `dpl` deployment marker from a local source.\n *\n * Next appends `?dpl=<deploymentId>` to local asset sources whenever a\n * deployment id is configured. The Gigadrive optimizer resolves the deployment\n * from the request hostname and never reads `dpl`, so keeping it only changes\n * the optimizer URL on every deploy — invalidating the CDN's image cache for\n * files whose content-hashed names already guarantee freshness, and forcing a\n * full re-optimization burst after each release.\n */\nconst stripDeploymentMarker = (src: string): string => {\n if (!src.startsWith('/') || !src.includes('?')) return src;\n const [pathname, query] = src.split('?', 2);\n const parameters = new URLSearchParams(query);\n parameters.delete('dpl');\n const remaining = parameters.toString();\n return remaining ? `${pathname}?${remaining}` : pathname;\n};\n\n/** Builds the stable app-host URL consumed by Gigadrive's managed image optimizer. */\nexport default function gigadriveNextImageLoader({ src, width, quality }: NextImageLoaderOptions): string {\n // No optimizer backend can rasterize SVG, so routing one through the optimizer\n // is always a pass-through: a wasted redirect and an extra request for bytes\n // the origin already serves. Next's own get-img-props marks `.svg` unoptimized\n // before any loader runs, but that bypass is skipped once a custom loaderFile\n // is configured — which is exactly what this adapter injects.\n if (isSvgSource(src)) return src;\n\n const stableSrc = stripDeploymentMarker(src);\n const parameters = new URLSearchParams({ width: String(width) });\n if (quality !== undefined) parameters.set('quality', String(quality));\n const optimizerUrl = `/_gigadrive/image/${encodeURIComponent(stableSrc)}/${encodeURIComponent(filenameHint(stableSrc))}?${parameters}`;\n return optimizerUrl.length > MAXIMUM_OPTIMIZER_URL_LENGTH ? src : optimizerUrl;\n}\n"],"mappings":";AAOA,IAAM,iBAAiB,CAAC,WACtB,OAAO,WAAW,SAAS,KAAK,OAAO,WAAW,UAAU,IAAI,IAAI,IAAI,MAAM,EAAE,WAAW,OAAO,MAAM,QAAQ,CAAC,EAAE,CAAC;AAEtH,IAAM,eAAe,CAAC,WAA2B;AAC/C,QAAM,YAAY,eAAe,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE,KAAK;AAC9E,SAAO,gEAAgE,KAAK,SAAS,IACjF,YACA,GAAG,aAAa,OAAO;AAC7B;AAEA,IAAM,cAAc,CAAC,WAA4B,UAAU,KAAK,eAAe,MAAM,CAAC;AAKtF,IAAM,+BAA+B;AAYrC,IAAM,wBAAwB,CAAC,QAAwB;AACrD,MAAI,CAAC,IAAI,WAAW,GAAG,KAAK,CAAC,IAAI,SAAS,GAAG,EAAG,QAAO;AACvD,QAAM,CAAC,UAAU,KAAK,IAAI,IAAI,MAAM,KAAK,CAAC;AAC1C,QAAM,aAAa,IAAI,gBAAgB,KAAK;AAC5C,aAAW,OAAO,KAAK;AACvB,QAAM,YAAY,WAAW,SAAS;AACtC,SAAO,YAAY,GAAG,QAAQ,IAAI,SAAS,KAAK;AAClD;AAGe,SAAR,yBAA0C,EAAE,KAAK,OAAO,QAAQ,GAAmC;AAMxG,MAAI,YAAY,GAAG,EAAG,QAAO;AAE7B,QAAM,YAAY,sBAAsB,GAAG;AAC3C,QAAM,aAAa,IAAI,gBAAgB,EAAE,OAAO,OAAO,KAAK,EAAE,CAAC;AAC/D,MAAI,YAAY,OAAW,YAAW,IAAI,WAAW,OAAO,OAAO,CAAC;AACpE,QAAM,eAAe,qBAAqB,mBAAmB,SAAS,CAAC,IAAI,mBAAmB,aAAa,SAAS,CAAC,CAAC,IAAI,UAAU;AACpI,SAAO,aAAa,SAAS,+BAA+B,MAAM;AACpE;","names":[]}
|