@next/font
Advanced tools
Comparing version 12.3.2-canary.39 to 12.3.2-canary.40
@@ -30,8 +30,10 @@ "use strict"; | ||
// @ts-ignore | ||
const font_utils_1 = require("next/dist/server/font-utils"); | ||
// @ts-ignore | ||
const Log = __importStar(require("next/dist/build/output/log")); | ||
// @ts-ignore | ||
const chalk_1 = __importDefault(require("next/dist/compiled/chalk")); | ||
// @ts-ignore | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const fontkit_1 = __importDefault(require("@next/font/dist/fontkit")); | ||
const utils_1 = require("./utils"); | ||
const utils_2 = require("../utils"); | ||
const cssCache = new Map(); | ||
@@ -71,2 +73,3 @@ const fontCache = new Map(); | ||
preloadFontFile: !!preload && (callSubsets !== null && callSubsets !== void 0 ? callSubsets : subsets).includes(currentSubset), | ||
isLatin: currentSubset === 'latin', | ||
}); | ||
@@ -77,5 +80,12 @@ } | ||
// Download font files | ||
const downloadedFiles = await Promise.all(fontFiles.map(async ({ googleFontFileUrl, preloadFontFile }) => { | ||
let latinFont; | ||
const downloadedFiles = await Promise.all(fontFiles.map(async ({ googleFontFileUrl, preloadFontFile, isLatin }) => { | ||
let cachedFontRequest = fontCache.get(googleFontFileUrl); | ||
const fontFileBuffer = cachedFontRequest !== null && cachedFontRequest !== void 0 ? cachedFontRequest : (await (0, utils_1.fetchFontFile)(googleFontFileUrl)); | ||
if (isLatin) { | ||
try { | ||
latinFont = (0, fontkit_1.default)(fontFileBuffer); | ||
} | ||
catch { } | ||
} | ||
if (!cachedFontRequest) { | ||
@@ -102,12 +112,6 @@ fontCache.set(googleFontFileUrl, fontFileBuffer); | ||
let adjustFontFallbackMetrics; | ||
if (adjustFontFallback) { | ||
if (adjustFontFallback && latinFont) { | ||
try { | ||
const { ascent, descent, lineGap, fallbackFont, sizeAdjust } = (0, font_utils_1.calculateSizeAdjustValues)(require('next/dist/server/google-font-metrics.json')[fontFamily]); | ||
adjustFontFallbackMetrics = { | ||
fallbackFont, | ||
ascentOverride: `${ascent}%`, | ||
descentOverride: `${descent}%`, | ||
lineGapOverride: `${lineGap}%`, | ||
sizeAdjust: `${sizeAdjust}%`, | ||
}; | ||
adjustFontFallbackMetrics = (0, utils_2.calculateFallbackFontValues)(latinFont, require('next/dist/server/google-font-metrics.json')[fontFamily] | ||
.category); | ||
} | ||
@@ -114,0 +118,0 @@ catch { |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.getFontAxes = exports.fetchFontFile = exports.fetchCSSFromGoogleFonts = exports.getUrl = exports.validateData = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
// @ts-ignore | ||
@@ -114,2 +115,5 @@ const node_fetch_1 = __importDefault(require("next/dist/compiled/node-fetch")); | ||
if (process.env.NEXT_FONT_GOOGLE_MOCKED_RESPONSES) { | ||
if (url.startsWith('/')) { | ||
return fs_1.default.readFileSync(url); | ||
} | ||
return Buffer.from(url); | ||
@@ -116,0 +120,0 @@ } |
@@ -7,4 +7,2 @@ "use strict"; | ||
// @ts-ignore | ||
const font_utils_1 = require("next/dist/server/font-utils"); | ||
// @ts-ignore | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
@@ -14,4 +12,5 @@ const fontkit_1 = __importDefault(require("@next/font/dist/fontkit")); | ||
const utils_1 = require("./utils"); | ||
const utils_2 = require("../utils"); | ||
const fetchFonts = async ({ functionName, data, emitFontFile, resolve, fs, }) => { | ||
var _a, _b; | ||
var _a; | ||
const { family, src, ext, format, display, weight, style, fallback, preload, variable, adjustFontFallback, declarations, } = (0, utils_1.validateData)(functionName, data); | ||
@@ -31,18 +30,3 @@ const resolved = await resolve(src); | ||
if (fontMetadata && adjustFontFallback !== false) { | ||
const { ascent, descent, lineGap, fallbackFont, sizeAdjust: fallbackSizeAdjust, } = (0, font_utils_1.calculateSizeAdjustValues)({ | ||
category: adjustFontFallback === 'Times New Roman' ? 'serif' : 'sans-serif', | ||
ascent: fontMetadata.ascent, | ||
descent: fontMetadata.descent, | ||
lineGap: fontMetadata.lineGap, | ||
unitsPerEm: fontMetadata.unitsPerEm, | ||
xAvgCharWidth: (_a = fontMetadata['OS/2']) === null || _a === void 0 ? void 0 : _a.xAvgCharWidth, | ||
azAvgWidth: (0, utils_1.calcAzWidth)(fontMetadata), | ||
}); | ||
adjustFontFallbackMetrics = { | ||
fallbackFont, | ||
ascentOverride: `${ascent}%`, | ||
descentOverride: `${descent}%`, | ||
lineGapOverride: `${lineGap}%`, | ||
sizeAdjust: `${fallbackSizeAdjust}%`, | ||
}; | ||
adjustFontFallbackMetrics = (0, utils_2.calculateFallbackFontValues)(fontMetadata, adjustFontFallback === 'Times New Roman' ? 'serif' : 'sans-serif'); | ||
} | ||
@@ -53,3 +37,3 @@ const fontFaceProperties = [ | ||
: []), | ||
['font-family', `'${(_b = fontMetadata === null || fontMetadata === void 0 ? void 0 : fontMetadata.familyName) !== null && _b !== void 0 ? _b : family}'`], | ||
['font-family', `'${(_a = fontMetadata === null || fontMetadata === void 0 ? void 0 : fontMetadata.familyName) !== null && _a !== void 0 ? _a : family}'`], | ||
['src', `url(${fontUrl}) format('${format}')`], | ||
@@ -56,0 +40,0 @@ ['font-display', display], |
@@ -1,2 +0,1 @@ | ||
import type { Font } from 'fontkit'; | ||
declare type FontOptions = { | ||
@@ -20,3 +19,2 @@ family: string; | ||
export declare function validateData(functionName: string, data: any): FontOptions; | ||
export declare function calcAzWidth(font: Font): number; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calcAzWidth = exports.validateData = void 0; | ||
exports.validateData = void 0; | ||
const allowedDisplayValues = ['auto', 'block', 'swap', 'fallback', 'optional']; | ||
@@ -59,10 +59,1 @@ const formatValues = (values) => values.map((val) => `\`${val}\``).join(', '); | ||
exports.validateData = validateData; | ||
// Calculating the a-z average width | ||
function calcAzWidth(font) { | ||
const widths = font | ||
.glyphsForString('abcdefghijklmnopqrstuvwxyz') | ||
.map((glyph) => glyph.advanceWidth); | ||
const totalWidth = widths.reduce((sum, width) => sum + width, 0); | ||
return totalWidth / widths.length; | ||
} | ||
exports.calcAzWidth = calcAzWidth; |
{ | ||
"name": "@next/font", | ||
"version": "12.3.2-canary.39", | ||
"version": "12.3.2-canary.40", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "url": "vercel/next.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2157431
28
51942
6