inital commit

This commit is contained in:
2026-01-01 15:25:19 +05:30
commit f0ae49465a
36361 changed files with 4894111 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import isAnimated from 'next/dist/compiled/is-animated';
import { optimizeImage } from '../../../../server/image-optimizer';
const BLUR_IMG_SIZE = 8;
const BLUR_QUALITY = 70;
const VALID_BLUR_EXT = [
'jpeg',
'png',
'webp',
'avif'
] // should match other usages
;
export async function getBlurImage(content, extension, imageSize, { basePath, outputPath, isDev, tracing = ()=>({
traceFn: (fn)=>(...args)=>fn(...args),
traceAsyncFn: (fn)=>(...args)=>fn(...args)
}) }) {
let blurDataURL;
let blurWidth = 0;
let blurHeight = 0;
if (VALID_BLUR_EXT.includes(extension) && !isAnimated(content)) {
// Shrink the image's largest dimension
if (imageSize.width >= imageSize.height) {
blurWidth = BLUR_IMG_SIZE;
blurHeight = Math.max(Math.round(imageSize.height / imageSize.width * BLUR_IMG_SIZE), 1);
} else {
blurWidth = Math.max(Math.round(imageSize.width / imageSize.height * BLUR_IMG_SIZE), 1);
blurHeight = BLUR_IMG_SIZE;
}
if (isDev) {
// During `next dev`, we don't want to generate blur placeholders with webpack
// because it can delay starting the dev server. Instead, we inline a
// special url to lazily generate the blur placeholder at request time.
const prefix = 'http://localhost';
const url = new URL(`${basePath || ''}/_next/image`, prefix);
url.searchParams.set('url', outputPath);
url.searchParams.set('w', String(blurWidth));
url.searchParams.set('q', String(BLUR_QUALITY));
blurDataURL = url.href.slice(prefix.length);
} else {
const resizeImageSpan = tracing('image-resize');
const resizedImage = await resizeImageSpan.traceAsyncFn(()=>optimizeImage({
buffer: content,
width: blurWidth,
height: blurHeight,
contentType: `image/${extension}`,
quality: BLUR_QUALITY
}));
const blurDataURLSpan = tracing('image-base64-tostring');
blurDataURL = blurDataURLSpan.traceFn(()=>`data:image/${extension};base64,${resizedImage.toString('base64')}`);
}
}
return {
dataURL: blurDataURL,
width: blurWidth,
height: blurHeight
};
}
//# sourceMappingURL=blur.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-image-loader/blur.ts"],"sourcesContent":["import isAnimated from 'next/dist/compiled/is-animated'\nimport { optimizeImage } from '../../../../server/image-optimizer'\n\nconst BLUR_IMG_SIZE = 8\nconst BLUR_QUALITY = 70\nconst VALID_BLUR_EXT = ['jpeg', 'png', 'webp', 'avif'] // should match other usages\n\nexport async function getBlurImage(\n content: Buffer,\n extension: string,\n imageSize: { width: number; height: number },\n {\n basePath,\n outputPath,\n isDev,\n tracing = () => ({\n traceFn:\n (fn) =>\n (...args: any) =>\n fn(...args),\n traceAsyncFn:\n (fn) =>\n (...args: any) =>\n fn(...args),\n }),\n }: {\n basePath: string\n outputPath: string\n isDev: boolean\n tracing: (name?: string) => {\n traceFn(fn: Function): any\n traceAsyncFn(fn: Function): any\n }\n }\n) {\n let blurDataURL: string | undefined\n let blurWidth: number = 0\n let blurHeight: number = 0\n\n if (VALID_BLUR_EXT.includes(extension) && !isAnimated(content)) {\n // Shrink the image's largest dimension\n if (imageSize.width >= imageSize.height) {\n blurWidth = BLUR_IMG_SIZE\n blurHeight = Math.max(\n Math.round((imageSize.height / imageSize.width) * BLUR_IMG_SIZE),\n 1\n )\n } else {\n blurWidth = Math.max(\n Math.round((imageSize.width / imageSize.height) * BLUR_IMG_SIZE),\n 1\n )\n blurHeight = BLUR_IMG_SIZE\n }\n\n if (isDev) {\n // During `next dev`, we don't want to generate blur placeholders with webpack\n // because it can delay starting the dev server. Instead, we inline a\n // special url to lazily generate the blur placeholder at request time.\n const prefix = 'http://localhost'\n const url = new URL(`${basePath || ''}/_next/image`, prefix)\n url.searchParams.set('url', outputPath)\n url.searchParams.set('w', String(blurWidth))\n url.searchParams.set('q', String(BLUR_QUALITY))\n blurDataURL = url.href.slice(prefix.length)\n } else {\n const resizeImageSpan = tracing('image-resize')\n const resizedImage = await resizeImageSpan.traceAsyncFn(() =>\n optimizeImage({\n buffer: content,\n width: blurWidth,\n height: blurHeight,\n contentType: `image/${extension}`,\n quality: BLUR_QUALITY,\n })\n )\n const blurDataURLSpan = tracing('image-base64-tostring')\n blurDataURL = blurDataURLSpan.traceFn(\n () =>\n `data:image/${extension};base64,${resizedImage.toString('base64')}`\n )\n }\n }\n return {\n dataURL: blurDataURL,\n width: blurWidth,\n height: blurHeight,\n }\n}\n"],"names":["isAnimated","optimizeImage","BLUR_IMG_SIZE","BLUR_QUALITY","VALID_BLUR_EXT","getBlurImage","content","extension","imageSize","basePath","outputPath","isDev","tracing","traceFn","fn","args","traceAsyncFn","blurDataURL","blurWidth","blurHeight","includes","width","height","Math","max","round","prefix","url","URL","searchParams","set","String","href","slice","length","resizeImageSpan","resizedImage","buffer","contentType","quality","blurDataURLSpan","toString","dataURL"],"mappings":"AAAA,OAAOA,gBAAgB,iCAAgC;AACvD,SAASC,aAAa,QAAQ,qCAAoC;AAElE,MAAMC,gBAAgB;AACtB,MAAMC,eAAe;AACrB,MAAMC,iBAAiB;IAAC;IAAQ;IAAO;IAAQ;CAAO,CAAC,4BAA4B;;AAEnF,OAAO,eAAeC,aACpBC,OAAe,EACfC,SAAiB,EACjBC,SAA4C,EAC5C,EACEC,QAAQ,EACRC,UAAU,EACVC,KAAK,EACLC,UAAU,IAAO,CAAA;QACfC,SACE,CAACC,KACD,CAAC,GAAGC,OACFD,MAAMC;QACVC,cACE,CAACF,KACD,CAAC,GAAGC,OACFD,MAAMC;IACZ,CAAA,CAAE,EASH;IAED,IAAIE;IACJ,IAAIC,YAAoB;IACxB,IAAIC,aAAqB;IAEzB,IAAIf,eAAegB,QAAQ,CAACb,cAAc,CAACP,WAAWM,UAAU;QAC9D,uCAAuC;QACvC,IAAIE,UAAUa,KAAK,IAAIb,UAAUc,MAAM,EAAE;YACvCJ,YAAYhB;YACZiB,aAAaI,KAAKC,GAAG,CACnBD,KAAKE,KAAK,CAAC,AAACjB,UAAUc,MAAM,GAAGd,UAAUa,KAAK,GAAInB,gBAClD;QAEJ,OAAO;YACLgB,YAAYK,KAAKC,GAAG,CAClBD,KAAKE,KAAK,CAAC,AAACjB,UAAUa,KAAK,GAAGb,UAAUc,MAAM,GAAIpB,gBAClD;YAEFiB,aAAajB;QACf;QAEA,IAAIS,OAAO;YACT,8EAA8E;YAC9E,qEAAqE;YACrE,uEAAuE;YACvE,MAAMe,SAAS;YACf,MAAMC,MAAM,IAAIC,IAAI,GAAGnB,YAAY,GAAG,YAAY,CAAC,EAAEiB;YACrDC,IAAIE,YAAY,CAACC,GAAG,CAAC,OAAOpB;YAC5BiB,IAAIE,YAAY,CAACC,GAAG,CAAC,KAAKC,OAAOb;YACjCS,IAAIE,YAAY,CAACC,GAAG,CAAC,KAAKC,OAAO5B;YACjCc,cAAcU,IAAIK,IAAI,CAACC,KAAK,CAACP,OAAOQ,MAAM;QAC5C,OAAO;YACL,MAAMC,kBAAkBvB,QAAQ;YAChC,MAAMwB,eAAe,MAAMD,gBAAgBnB,YAAY,CAAC,IACtDf,cAAc;oBACZoC,QAAQ/B;oBACRe,OAAOH;oBACPI,QAAQH;oBACRmB,aAAa,CAAC,MAAM,EAAE/B,WAAW;oBACjCgC,SAASpC;gBACX;YAEF,MAAMqC,kBAAkB5B,QAAQ;YAChCK,cAAcuB,gBAAgB3B,OAAO,CACnC,IACE,CAAC,WAAW,EAAEN,UAAU,QAAQ,EAAE6B,aAAaK,QAAQ,CAAC,WAAW;QAEzE;IACF;IACA,OAAO;QACLC,SAASzB;QACTI,OAAOH;QACPI,QAAQH;IACV;AACF"}

View File

@@ -0,0 +1,53 @@
import path from 'path';
import loaderUtils from 'next/dist/compiled/loader-utils3';
import { getImageSize } from '../../../../server/image-optimizer';
import { getBlurImage } from './blur';
function nextImageLoader(content) {
const imageLoaderSpan = this.currentTraceSpan.traceChild('next-image-loader');
return imageLoaderSpan.traceAsyncFn(async ()=>{
const options = this.getOptions();
const { compilerType, isDev, assetPrefix, basePath } = options;
const context = this.rootContext;
const opts = {
context,
content
};
const interpolatedName = loaderUtils.interpolateName(this, '/static/media/[name].[hash:8].[ext]', opts);
const outputPath = assetPrefix + '/_next' + interpolatedName;
let extension = loaderUtils.interpolateName(this, '[ext]', opts);
if (extension === 'jpg') {
extension = 'jpeg';
}
const imageSizeSpan = imageLoaderSpan.traceChild('image-size-calculation');
const imageSize = await imageSizeSpan.traceAsyncFn(()=>getImageSize(content).catch((err)=>err));
if (imageSize instanceof Error) {
const err = imageSize;
err.name = 'InvalidImageFormatError';
throw err;
}
const { dataURL: blurDataURL, width: blurWidth, height: blurHeight } = await getBlurImage(content, extension, imageSize, {
basePath,
outputPath,
isDev,
tracing: imageLoaderSpan.traceChild.bind(imageLoaderSpan)
});
const stringifiedData = imageLoaderSpan.traceChild('image-data-stringify').traceFn(()=>JSON.stringify({
src: outputPath,
height: imageSize.height,
width: imageSize.width,
blurDataURL,
blurWidth,
blurHeight
}));
if (compilerType === 'client') {
this.emitFile(interpolatedName, content, null);
} else {
this.emitFile(path.join('..', isDev || compilerType === 'edge-server' ? '' : '..', interpolatedName), content, null);
}
return `export default ${stringifiedData};`;
});
}
export const raw = true;
export default nextImageLoader;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-image-loader/index.ts"],"sourcesContent":["import type { CompilerNameValues } from '../../../../shared/lib/constants'\n\nimport path from 'path'\nimport loaderUtils from 'next/dist/compiled/loader-utils3'\nimport { getImageSize } from '../../../../server/image-optimizer'\nimport { getBlurImage } from './blur'\n\ninterface Options {\n compilerType: CompilerNameValues\n isDev: boolean\n assetPrefix: string\n basePath: string\n}\n\nfunction nextImageLoader(this: any, content: Buffer) {\n const imageLoaderSpan = this.currentTraceSpan.traceChild('next-image-loader')\n return imageLoaderSpan.traceAsyncFn(async () => {\n const options: Options = this.getOptions()\n const { compilerType, isDev, assetPrefix, basePath } = options\n const context = this.rootContext\n\n const opts = { context, content }\n const interpolatedName = loaderUtils.interpolateName(\n this,\n '/static/media/[name].[hash:8].[ext]',\n opts\n )\n const outputPath = assetPrefix + '/_next' + interpolatedName\n let extension = loaderUtils.interpolateName(this, '[ext]', opts)\n if (extension === 'jpg') {\n extension = 'jpeg'\n }\n\n const imageSizeSpan = imageLoaderSpan.traceChild('image-size-calculation')\n const imageSize = await imageSizeSpan.traceAsyncFn(() =>\n getImageSize(content).catch((err) => err)\n )\n\n if (imageSize instanceof Error) {\n const err = imageSize\n err.name = 'InvalidImageFormatError'\n throw err\n }\n\n const {\n dataURL: blurDataURL,\n width: blurWidth,\n height: blurHeight,\n } = await getBlurImage(content, extension, imageSize, {\n basePath,\n outputPath,\n isDev,\n tracing: imageLoaderSpan.traceChild.bind(imageLoaderSpan),\n })\n\n const stringifiedData = imageLoaderSpan\n .traceChild('image-data-stringify')\n .traceFn(() =>\n JSON.stringify({\n src: outputPath,\n height: imageSize.height,\n width: imageSize.width,\n blurDataURL,\n blurWidth,\n blurHeight,\n })\n )\n\n if (compilerType === 'client') {\n this.emitFile(interpolatedName, content, null)\n } else {\n this.emitFile(\n path.join(\n '..',\n isDev || compilerType === 'edge-server' ? '' : '..',\n interpolatedName\n ),\n content,\n null\n )\n }\n\n return `export default ${stringifiedData};`\n })\n}\nexport const raw = true\nexport default nextImageLoader\n"],"names":["path","loaderUtils","getImageSize","getBlurImage","nextImageLoader","content","imageLoaderSpan","currentTraceSpan","traceChild","traceAsyncFn","options","getOptions","compilerType","isDev","assetPrefix","basePath","context","rootContext","opts","interpolatedName","interpolateName","outputPath","extension","imageSizeSpan","imageSize","catch","err","Error","name","dataURL","blurDataURL","width","blurWidth","height","blurHeight","tracing","bind","stringifiedData","traceFn","JSON","stringify","src","emitFile","join","raw"],"mappings":"AAEA,OAAOA,UAAU,OAAM;AACvB,OAAOC,iBAAiB,mCAAkC;AAC1D,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,YAAY,QAAQ,SAAQ;AASrC,SAASC,gBAA2BC,OAAe;IACjD,MAAMC,kBAAkB,IAAI,CAACC,gBAAgB,CAACC,UAAU,CAAC;IACzD,OAAOF,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