main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1 @@
export default function nextFontLoader(this: any): Promise<any>;

View File

@@ -0,0 +1,120 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return nextFontLoader;
}
});
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
const _chalk = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/chalk"));
const _loaderutils3 = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/loader-utils3"));
const _postcssnextfont = /*#__PURE__*/ _interop_require_default(require("./postcss-next-font"));
const _util = require("util");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
async function nextFontLoader() {
const nextFontLoaderSpan = this.currentTraceSpan.traceChild("next-font-loader");
return nextFontLoaderSpan.traceAsyncFn(async ()=>{
const callback = this.async();
/**
* The next-swc plugin next-transform-font turns font function calls into CSS imports.
* At the end of the import, it adds the call arguments and some additional data as a resourceQuery.
* e.g:
* const inter = Inter({ subset: ['latin'] })
* ->
* import inter from 'next/font/google/target.css?{"import":"Inter","subsets":["latin"]}'
*
* Here we parse the resourceQuery to get the font function name, call arguments, and the path to the file that called the font function.
*/ const { path: relativeFilePathFromRoot, import: functionName, arguments: data, variableName } = JSON.parse(this.resourceQuery.slice(1));
// Throw error if @next/font is used in _document.js
if (/pages[\\/]_document\./.test(relativeFilePathFromRoot)) {
const err = new Error(`${_chalk.default.bold("Cannot")} be used within ${_chalk.default.cyan("pages/_document.js")}.`);
err.name = "NextFontError";
callback(err);
return;
}
const { isDev, isServer, assetPrefix, fontLoaderPath, postcss: getPostcss } = this.getOptions();
if (assetPrefix && !/^\/|https?:\/\//.test(assetPrefix)) {
const err = new Error("assetPrefix must start with a leading slash or be an absolute URL(http:// or https://)");
err.name = "NextFontError";
callback(err);
return;
}
/**
* Emit font files to .next/static/media as [hash].[ext].
*
* If the font should be preloaded, add .p to the filename: [hash].p.[ext]
* NextFontManifestPlugin adds these files to the next/font manifest.
*
* If the font is using a size-adjust fallback font, add -s to the filename: [hash]-s.[ext]
* NextFontManifestPlugin uses this to see if fallback fonts are being used.
* This is used to collect stats on fallback fonts usage by the Google Aurora team.
*/ const emitFontFile = (content, ext, preload, isUsingSizeAdjust)=>{
const opts = {
context: this.rootContext,
content
};
const interpolatedName = _loaderutils3.default.interpolateName(this, `static/media/[hash]${isUsingSizeAdjust ? "-s" : ""}${preload ? ".p" : ""}.${ext}`, opts);
const outputPath = `${assetPrefix}/_next/${interpolatedName}`;
// Only the client emits the font file
if (!isServer) {
this.emitFile(interpolatedName, content, null);
}
// But both the server and client must get the resulting path
return outputPath;
};
try {
// Import the font loader function from either next/font/local or next/font/google
// The font loader function emits font files and returns @font-faces and fallback font metrics
const fontLoader = require(fontLoaderPath).default;
let { css, fallbackFonts, adjustFontFallback, weight, style, variable } = await nextFontLoaderSpan.traceChild("font-loader").traceAsyncFn(()=>fontLoader({
functionName,
variableName,
data,
emitFontFile,
resolve: (src)=>(0, _util.promisify)(this.resolve)(_path.default.dirname(_path.default.join(this.rootContext, relativeFilePathFromRoot)), src.startsWith(".") ? src : `./${src}`),
isDev,
isServer,
loaderContext: this
}));
const { postcss } = await getPostcss();
// Exports will be exported as is from css-loader instead of a CSS module export
const exports1 = [];
// Generate a hash from the CSS content. Used to generate classnames and font families
const fontFamilyHash = _loaderutils3.default.getHashDigest(Buffer.from(css), "sha1", "hex", 6);
// Add CSS classes, exports and make the font-family locally scoped by turning it unguessable
const result = await nextFontLoaderSpan.traceChild("postcss").traceAsyncFn(()=>postcss((0, _postcssnextfont.default)({
exports: exports1,
fontFamilyHash,
fallbackFonts,
weight,
style,
adjustFontFallback,
variable
})).process(css, {
from: undefined
}));
const ast = {
type: "postcss",
version: result.processor.version,
root: result.root
};
// Return the resulting CSS and send the postcss ast, font exports and the hash to the css-loader in the meta argument.
callback(null, result.css, null, {
exports: exports1,
ast,
fontFamilyHash
});
} catch (err) {
callback(err);
}
});
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-font-loader/index.ts"],"names":["nextFontLoader","nextFontLoaderSpan","currentTraceSpan","traceChild","traceAsyncFn","callback","async","path","relativeFilePathFromRoot","import","functionName","arguments","data","variableName","JSON","parse","resourceQuery","slice","test","err","Error","chalk","bold","cyan","name","isDev","isServer","assetPrefix","fontLoaderPath","postcss","getPostcss","getOptions","emitFontFile","content","ext","preload","isUsingSizeAdjust","opts","context","rootContext","interpolatedName","loaderUtils","interpolateName","outputPath","emitFile","fontLoader","require","default","css","fallbackFonts","adjustFontFallback","weight","style","variable","resolve","src","promisify","dirname","join","startsWith","loaderContext","exports","fontFamilyHash","getHashDigest","Buffer","from","result","postcssNextFontPlugin","process","undefined","ast","type","version","processor","root"],"mappings":";;;;+BAQA;;;eAA8BA;;;6DANb;8DACC;qEACM;wEACU;sBACR;;;;;;AAEX,eAAeA;IAC5B,MAAMC,qBACJ,IAAI,CAACC,gBAAgB,CAACC,UAAU,CAAC;IACnC,OAAOF,mBAAmBG,YAAY,CAAC;QACrC,MAAMC,WAAW,IAAI,CAACC,KAAK;QAE3B;;;;;;;;;KASC,GACD,MAAM,EACJC,MAAMC,wBAAwB,EAC9BC,QAAQC,YAAY,EACpBC,WAAWC,IAAI,EACfC,YAAY,EACb,GAAGC,KAAKC,KAAK,CAAC,IAAI,CAACC,aAAa,CAACC,KAAK,CAAC;QAExC,oDAAoD;QACpD,IAAI,wBAAwBC,IAAI,CAACV,2BAA2B;YAC1D,MAAMW,MAAM,IAAIC,MACd,CAAC,EAAEC,cAAK,CAACC,IAAI,CAAC,UAAU,gBAAgB,EAAED,cAAK,CAACE,IAAI,CAClD,sBACA,CAAC,CAAC;YAENJ,IAAIK,IAAI,GAAG;YACXnB,SAASc;YACT;QACF;QAEA,MAAM,EACJM,KAAK,E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;oBACAC;oBACAkC,eAAe,IAAI;gBACrB;YAGJ,MAAM,EAAE/B,OAAO,EAAE,GAAG,MAAMC;YAE1B,gFAAgF;YAChF,MAAM+B,WAAuC,EAAE;YAE/C,sFAAsF;YACtF,MAAMC,iBAAiBrB,qBAAW,CAACsB,aAAa,CAC9CC,OAAOC,IAAI,CAACjB,MACZ,QACA,OACA;YAGF,6FAA6F;YAC7F,MAAMkB,SAAS,MAAMjE,mBAClBE,UAAU,CAAC,WACXC,YAAY,CAAC,IACZyB,QACEsC,IAAAA,wBAAqB,EAAC;oBACpBN,SAAAA;oBACAC;oBACAb;oBACAE;oBACAC;oBACAF;oBACAG;gBACF,IACAe,OAAO,CAACpB,KAAK;oBACbiB,MAAMI;gBACR;YAGJ,MAAMC,MAAM;gBACVC,MAAM;gBACNC,SAASN,OAAOO,SAAS,CAACD,OAAO;gBACjCE,MAAMR,OAAOQ,IAAI;YACnB;YAEA,uHAAuH;YACvHrE,SAAS,MAAM6D,OAAOlB,GAAG,EAAE,MAAM;gBAC/Ba,SAAAA;gBACAS;gBACAR;YACF;QACF,EAAE,OAAO3C,KAAU;YACjBd,SAASc;QACX;IACF;AACF"}

View File

@@ -0,0 +1,36 @@
import type { AdjustFontFallback } from '../../../../../font';
/**
* The next/font postcss plugin recieves the @font-face declarations returned from the next/font loaders.
*
* It hashes the font-family name to make it unguessable, it shouldn't be globally accessible.
* If it were global, we wouldn't be able to tell which pages are using which fonts when generating preload tags.
*
* If the font loader returned fallback metrics, generate a fallback @font-face.
*
* If the font loader returned a variable name, add a CSS class that declares a variable containing the font and fallback fonts.
*
* Lastly, it adds the font-family to the exports object.
* This enables you to access the actual font-family name, not just through the CSS class.
* e.g:
* const inter = Inter({ subsets: ['latin'] })
* inter.style.fontFamily // => '__Inter_123456'
*/
declare const postcssNextFontPlugin: {
({ exports, fontFamilyHash, fallbackFonts, adjustFontFallback, variable, weight, style, }: {
exports: {
name: any;
value: any;
}[];
fontFamilyHash: string;
fallbackFonts?: string[] | undefined;
adjustFontFallback?: AdjustFontFallback | undefined;
variable?: string | undefined;
weight?: string | undefined;
style?: string | undefined;
}): {
postcssPlugin: string;
Once(root: any): void;
};
postcss: boolean;
};
export default postcssNextFontPlugin;

View File

@@ -0,0 +1,166 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
/**
* The next/font postcss plugin recieves the @font-face declarations returned from the next/font loaders.
*
* It hashes the font-family name to make it unguessable, it shouldn't be globally accessible.
* If it were global, we wouldn't be able to tell which pages are using which fonts when generating preload tags.
*
* If the font loader returned fallback metrics, generate a fallback @font-face.
*
* If the font loader returned a variable name, add a CSS class that declares a variable containing the font and fallback fonts.
*
* Lastly, it adds the font-family to the exports object.
* This enables you to access the actual font-family name, not just through the CSS class.
* e.g:
* const inter = Inter({ subsets: ['latin'] })
* inter.style.fontFamily // => '__Inter_123456'
*/ const postcssNextFontPlugin = ({ exports: exports1, fontFamilyHash, fallbackFonts = [], adjustFontFallback, variable, weight, style })=>{
return {
postcssPlugin: "postcss-next-font",
Once (root) {
let fontFamily;
const normalizeFamily = (family)=>{
return family.replace(/['"]/g, "");
};
const formatFamily = (family)=>{
// Turn the font family unguessable to make it locally scoped
return `'__${family.replace(/ /g, "_")}_${fontFamilyHash}'`;
};
// Hash font-family names
for (const node of root.nodes){
if (node.type === "atrule" && node.name === "font-face") {
const familyNode = node.nodes.find((decl)=>decl.prop === "font-family");
if (!familyNode) {
continue;
}
if (!fontFamily) {
fontFamily = normalizeFamily(familyNode.value);
}
familyNode.value = formatFamily(fontFamily);
}
}
if (!fontFamily) {
throw new Error("Font loaders must return one or more @font-face's");
}
// Add fallback @font-face with the provided override values
let adjustFontFallbackFamily;
if (adjustFontFallback) {
adjustFontFallbackFamily = formatFamily(`${fontFamily} Fallback`);
const fallbackFontFace = _postcss.default.atRule({
name: "font-face"
});
const { fallbackFont, ascentOverride, descentOverride, lineGapOverride, sizeAdjust } = adjustFontFallback;
fallbackFontFace.nodes = [
new _postcss.default.Declaration({
prop: "font-family",
value: adjustFontFallbackFamily
}),
new _postcss.default.Declaration({
prop: "src",
value: `local("${fallbackFont}")`
}),
...ascentOverride ? [
new _postcss.default.Declaration({
prop: "ascent-override",
value: ascentOverride
})
] : [],
...descentOverride ? [
new _postcss.default.Declaration({
prop: "descent-override",
value: descentOverride
})
] : [],
...lineGapOverride ? [
new _postcss.default.Declaration({
prop: "line-gap-override",
value: lineGapOverride
})
] : [],
...sizeAdjust ? [
new _postcss.default.Declaration({
prop: "size-adjust",
value: sizeAdjust
})
] : []
];
root.nodes.push(fallbackFontFace);
}
// Variable fonts can define ranges of values
const isRange = (value)=>value.trim().includes(" ");
// Format the font families to be used in the CSS
const formattedFontFamilies = [
formatFamily(fontFamily),
...adjustFontFallbackFamily ? [
adjustFontFallbackFamily
] : [],
...fallbackFonts
].join(", ");
// Add class with family, weight and style
const classRule = new _postcss.default.Rule({
selector: ".className"
});
classRule.nodes = [
new _postcss.default.Declaration({
prop: "font-family",
value: formattedFontFamilies
}),
// If the font only has one weight or style, we can set it on the class
...weight && !isRange(weight) ? [
new _postcss.default.Declaration({
prop: "font-weight",
value: weight
})
] : [],
...style && !isRange(style) ? [
new _postcss.default.Declaration({
prop: "font-style",
value: style
})
] : []
];
root.nodes.push(classRule);
// Add CSS class that defines a variable with the font families
if (variable) {
const varialbeRule = new _postcss.default.Rule({
selector: ".variable"
});
varialbeRule.nodes = [
new _postcss.default.Declaration({
prop: variable,
value: formattedFontFamilies
})
];
root.nodes.push(varialbeRule);
}
// Export @font-face values as is
exports1.push({
name: "style",
value: {
fontFamily: formattedFontFamilies,
fontWeight: !Number.isNaN(Number(weight)) ? Number(weight) : undefined,
fontStyle: style && !isRange(style) ? style : undefined
}
});
}
};
};
postcssNextFontPlugin.postcss = true;
const _default = postcssNextFontPlugin;
//# sourceMappingURL=postcss-next-font.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-font-loader/postcss-next-font.ts"],"names":["postcssNextFontPlugin","exports","fontFamilyHash","fallbackFonts","adjustFontFallback","variable","weight","style","postcssPlugin","Once","root","fontFamily","normalizeFamily","family","replace","formatFamily","node","nodes","type","name","familyNode","find","decl","prop","value","Error","adjustFontFallbackFamily","fallbackFontFace","postcss","atRule","fallbackFont","ascentOverride","descentOverride","lineGapOverride","sizeAdjust","Declaration","push","isRange","trim","includes","formattedFontFamilies","join","classRule","Rule","selector","varialbeRule","fontWeight","Number","isNaN","undefined","fontStyle"],"mappings":";;;;+BAmMA;;;eAAA;;;gEAlMqC;;;;;;AAErC;;;;;;;;;;;;;;;CAeC,GACD,MAAMA,wBAAwB,CAAC,EAC7BC,SAAAA,QAAO,EACPC,cAAc,EACdC,gBAAgB,EAAE,EAClBC,kBAAkB,EAClBC,QAAQ,EACRC,MAAM,EACNC,KAAK,EASN;IACC,OAAO;QACLC,eAAe;QACfC,MAAKC,IAAS;YACZ,IAAIC;YAEJ,MAAMC,kBAAkB,CAACC;gBACvB,OAAOA,OAAOC,OAAO,CAAC,SAAS;YACjC;YAEA,MAAMC,eAAe,CAACF;gBACpB,6DAA6D;gBAC7D,OAAO,CAAC,GAAG,EAAEA,OAAOC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAEZ,eAAe,CAAC,CAAC;YAC7D;YAEA,yBAAyB;YACzB,KAAK,MAAMc,QAAQN,KAAKO,KAAK,CAAE;gBAC7B,IAAID,KAAKE,IAAI,KAAK,YAAYF,KAAKG,IAAI,KAAK,aAAa;oBACvD,MAAMC,aAAaJ,KAAKC,KAAK,CAACI,IAAI,CAChC,CAACC,OAAsBA,KAAKC,IAAI,KAAK;oBAEvC,IAAI,CAACH,YAAY;wBACf;oBACF;oBAEA,IAAI,CAACT,YAAY;wBACfA,aAAaC,gBAAgBQ,WAAWI,KAA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