Socket
Socket
Sign inDemoInstall

@next/font

Package Overview
Dependencies
Maintainers
5
Versions
1035
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@next/font - npm Package Compare versions

Comparing version 12.3.2-canary.23 to 12.3.2-canary.24

dist/fontkit/index.js

9

dist/google/loader.js

@@ -66,8 +66,9 @@ "use strict";

try {
const { ascent, descent, lineGap, fallbackFont } = (0, font_utils_1.calculateOverrideValues)(fontFamily, require('next/dist/server/google-font-metrics.json'));
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,
ascentOverride: `${ascent}%`,
descentOverride: `${descent}%`,
lineGapOverride: `${lineGap}%`,
sizeAdjust: `${sizeAdjust}%`,
};

@@ -74,0 +75,0 @@ }

@@ -1,9 +0,6 @@

import type { AdjustFontFallback, FontModule } from 'next/font';
import type { FontModule } from 'next/font';
declare type Display = 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
declare type CssVariable = `--${string}`;
declare type LocalFont = {
src: string | Array<{
file: string;
unicodeRange: string;
}>;
src: string;
display?: Display;

@@ -23,5 +20,5 @@ weight?: number;

sizeAdjust?: string;
adjustFontFallback?: AdjustFontFallback;
adjustFontFallback?: 'Arial' | 'Times New Roman' | false;
};
export default function localFont(options: LocalFont): FontModule;
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
const font_utils_1 = require("next/dist/server/font-utils");
// @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies
const fontkit_1 = __importDefault(require("@next/font/dist/fontkit"));
const util_1 = require("util");
const utils_1 = require("./utils");
const fetchFonts = async ({ functionName, data, emitFontFile, resolve, fs, }) => {
const { family, files, display, weight, style, fallback, preload, variable, ascentOverride, descentOverride, lineGapOverride, fontStretch, fontFeatureSettings, sizeAdjust, adjustFontFallback, } = (0, utils_1.validateData)(functionName, data);
const fontFaces = await Promise.all(files.map(async ({ file, ext, format, unicodeRange }) => {
const resolved = await resolve(file);
const fileBuffer = await (0, util_1.promisify)(fs.readFile)(resolved);
const fontUrl = emitFontFile(fileBuffer, ext, preload);
const fontFaceProperties = [
['font-family', `'${family}'`],
['src', `url(${fontUrl}) format('${format}')`],
['font-display', display],
...(weight ? [['font-weight', weight]] : []),
...(style ? [['font-style', style]] : []),
...(ascentOverride ? [['ascent-override', ascentOverride]] : []),
...(descentOverride ? [['descent-override', descentOverride]] : []),
...(lineGapOverride ? [['line-gap-override', lineGapOverride]] : []),
...(fontStretch ? [['font-stretch', fontStretch]] : []),
...(fontFeatureSettings
? [['font-feature-settings', fontFeatureSettings]]
: []),
...(sizeAdjust ? [['size-adjust', sizeAdjust]] : []),
...(unicodeRange ? [['unicode-range', unicodeRange]] : ''),
];
return `@font-face {
var _a, _b;
const { family, src, ext, format, display, weight, style, fallback, preload, variable, ascentOverride, descentOverride, lineGapOverride, fontStretch, fontFeatureSettings, sizeAdjust, adjustFontFallback, } = (0, utils_1.validateData)(functionName, data);
const resolved = await resolve(src);
const fileBuffer = await (0, util_1.promisify)(fs.readFile)(resolved);
const fontUrl = emitFontFile(fileBuffer, ext, preload);
let fontMetadata;
try {
fontMetadata = (0, fontkit_1.default)(fileBuffer);
}
catch (e) {
console.error(`Failed to load font file: ${resolved}\n${e}`);
}
// Add fallback font
let adjustFontFallbackMetrics;
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,
});
adjustFontFallbackMetrics = {
fallbackFont,
ascentOverride: `${ascent}%`,
descentOverride: `${descent}%`,
lineGapOverride: `${lineGap}%`,
sizeAdjust: `${fallbackSizeAdjust}%`,
};
}
const fontFaceProperties = [
['font-family', `'${(_b = fontMetadata === null || fontMetadata === void 0 ? void 0 : fontMetadata.familyName) !== null && _b !== void 0 ? _b : family}'`],
['src', `url(${fontUrl}) format('${format}')`],
['font-display', display],
...(weight ? [['font-weight', weight]] : []),
...(style ? [['font-style', style]] : []),
...(ascentOverride ? [['ascent-override', ascentOverride]] : []),
...(descentOverride ? [['descent-override', descentOverride]] : []),
...(lineGapOverride ? [['line-gap-override', lineGapOverride]] : []),
...(fontStretch ? [['font-stretch', fontStretch]] : []),
...(fontFeatureSettings
? [['font-feature-settings', fontFeatureSettings]]
: []),
...(sizeAdjust ? [['size-adjust', sizeAdjust]] : []),
];
const css = `@font-face {
${fontFaceProperties
.map(([property, value]) => `${property}: ${value};`)
.join('\n')}
.map(([property, value]) => `${property}: ${value};`)
.join('\n')}
}`;
}));
return {
css: fontFaces.join('\n'),
css,
fallbackFonts: fallback,

@@ -39,5 +71,5 @@ weight,

variable,
adjustFontFallback,
adjustFontFallback: adjustFontFallbackMetrics,
};
};
exports.default = fetchFonts;

@@ -1,10 +0,6 @@

import { AdjustFontFallback } from 'next/font';
declare type FontOptions = {
family: string;
files: Array<{
file: string;
ext: string;
format: string;
unicodeRange?: string;
}>;
src: string;
ext: string;
format: string;
display: string;

@@ -24,5 +20,5 @@ weight?: number;

sizeAdjust?: string;
adjustFontFallback?: AdjustFontFallback;
adjustFontFallback?: string | false;
};
export declare function validateData(functionName: string, data: any): FontOptions;
export {};

@@ -14,2 +14,3 @@ "use strict";

function validateData(functionName, data) {
var _a;
if (functionName) {

@@ -22,29 +23,15 @@ throw new Error(`@next/font/local has no named exports`);

}
const srcArray = Array.isArray(src) ? src : [{ file: src }];
if (srcArray.length === 0) {
throw new Error('Src must contain one or more files');
if (!src) {
throw new Error('Missing required `src` property');
}
const files = srcArray.map(({ file, unicodeRange }) => {
var _a;
if (!file) {
throw new Error('Src array objects must have a `file` property');
}
if (srcArray.length > 1 && !unicodeRange) {
throw new Error("Files must have a unicode-range if there's more than one");
}
const ext = (_a = /\.(woff|woff2|eot|ttf|otf)$/.exec(file)) === null || _a === void 0 ? void 0 : _a[1];
if (!ext) {
throw new Error(`Unexpected file \`${file}\``);
}
return {
file,
unicodeRange,
ext,
format: extToFormat[ext],
};
});
const family = /.+\/(.+?)\./.exec(files[0].file)[1];
const ext = (_a = /\.(woff|woff2|eot|ttf|otf)$/.exec(src)) === null || _a === void 0 ? void 0 : _a[1];
if (!ext) {
throw new Error(`Unexpected file \`${src}\``);
}
const family = /.+\/(.+?)\./.exec(src)[1];
return {
family,
files,
src,
ext,
format: extToFormat[ext],
display,

@@ -51,0 +38,0 @@ weight,

{
"name": "@next/font",
"version": "12.3.2-canary.23",
"version": "12.3.2-canary.24",
"repository": {

@@ -15,7 +15,13 @@ "url": "vercel/next.js",

"scripts": {
"build": "rm -rf dist && tsc -d -p tsconfig.json",
"build": "rm -rf dist && pnpm ncc-fontkit && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json"
"dev": "pnpm ncc-fontkit && tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json",
"ncc-fontkit": "ncc build ./fontkit.js -o dist/fontkit"
},
"devDependencies": {
"@types/fontkit": "2.0.0",
"@vercel/ncc": "0.34.0",
"fontkit": "2.0.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc