create project
This commit is contained in:
10331
kitabcitab/node_modules/@next/font/dist/google/font-data.json
generated
vendored
Normal file
10331
kitabcitab/node_modules/@next/font/dist/google/font-data.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14825
kitabcitab/node_modules/@next/font/dist/google/index.d.ts
generated
vendored
Normal file
14825
kitabcitab/node_modules/@next/font/dist/google/index.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
kitabcitab/node_modules/@next/font/dist/google/index.js
generated
vendored
Normal file
2
kitabcitab/node_modules/@next/font/dist/google/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
3
kitabcitab/node_modules/@next/font/dist/google/loader.d.ts
generated
vendored
Normal file
3
kitabcitab/node_modules/@next/font/dist/google/loader.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { FontLoader } from 'next/font';
|
||||
declare const downloadGoogleFonts: FontLoader;
|
||||
export default downloadGoogleFonts;
|
||||
181
kitabcitab/node_modules/@next/font/dist/google/loader.js
generated
vendored
Normal file
181
kitabcitab/node_modules/@next/font/dist/google/loader.js
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
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
|
||||
const Log = __importStar(require("next/dist/build/output/log"));
|
||||
// @ts-ignore
|
||||
const chalk_1 = __importDefault(require("next/dist/compiled/chalk"));
|
||||
const utils_1 = require("./utils");
|
||||
const utils_2 = require("../utils");
|
||||
const cssCache = new Map();
|
||||
const fontCache = new Map();
|
||||
// regexp is based on https://github.com/sindresorhus/escape-string-regexp
|
||||
const reHasRegExp = /[|\\{}()[\]^$+*?.-]/;
|
||||
const reReplaceRegExp = /[|\\{}()[\]^$+*?.-]/g;
|
||||
function escapeStringRegexp(str) {
|
||||
// see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23
|
||||
if (reHasRegExp.test(str)) {
|
||||
return str.replace(reReplaceRegExp, '\\$&');
|
||||
}
|
||||
return str;
|
||||
}
|
||||
const downloadGoogleFonts = async ({ functionName, data, config, emitFontFile, isDev, isServer, loaderContext, }) => {
|
||||
var _a, _b, _c;
|
||||
const subsets = (config === null || config === void 0 ? void 0 : config.subsets) || [];
|
||||
const { fontFamily, weights, styles, display, preload, selectedVariableAxes, fallback, adjustFontFallback, variable, subsets: callSubsets, } = (0, utils_1.validateData)(functionName, data);
|
||||
if (isServer && preload && !callSubsets && !(config === null || config === void 0 ? void 0 : config.subsets)) {
|
||||
Log.warn(`The ${chalk_1.default.bold('@next/font/google')} font ${chalk_1.default.bold(fontFamily)} has no selected subsets. Please specify subsets in the function call or in your ${chalk_1.default.bold('next.config.js')}, otherwise no fonts will be preloaded. Read more: https://nextjs.org/docs/messages/google-fonts-missing-subsets`);
|
||||
}
|
||||
const fontAxes = (0, utils_1.getFontAxes)(fontFamily, weights, styles, selectedVariableAxes);
|
||||
const url = (0, utils_1.getUrl)(fontFamily, fontAxes, display);
|
||||
// Find fallback font metrics
|
||||
let adjustFontFallbackMetrics;
|
||||
if (adjustFontFallback) {
|
||||
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}%`,
|
||||
};
|
||||
}
|
||||
catch {
|
||||
Log.error(`Failed to find font override values for font \`${fontFamily}\``);
|
||||
}
|
||||
}
|
||||
const result = {
|
||||
fallbackFonts: fallback,
|
||||
weight: weights.length === 1 && weights[0] !== 'variable'
|
||||
? weights[0]
|
||||
: undefined,
|
||||
style: styles.length === 1 ? styles[0] : undefined,
|
||||
variable,
|
||||
adjustFontFallback: adjustFontFallbackMetrics,
|
||||
};
|
||||
try {
|
||||
const hasCachedCSS = cssCache.has(url);
|
||||
let fontFaceDeclarations = hasCachedCSS
|
||||
? cssCache.get(url)
|
||||
: await (0, utils_1.fetchCSSFromGoogleFonts)(url, fontFamily).catch(() => null);
|
||||
if (!hasCachedCSS) {
|
||||
cssCache.set(url, fontFaceDeclarations);
|
||||
}
|
||||
else {
|
||||
cssCache.delete(url);
|
||||
}
|
||||
if (fontFaceDeclarations === null) {
|
||||
(0, utils_2.nextFontError)(`Failed to fetch \`${fontFamily}\` from Google Fonts.`);
|
||||
}
|
||||
// CSS Variables may be set on a body tag, ignore them to keep the CSS module pure
|
||||
fontFaceDeclarations = fontFaceDeclarations.split('body {')[0];
|
||||
// Find font files to download
|
||||
const fontFiles = [];
|
||||
let currentSubset = '';
|
||||
for (const line of fontFaceDeclarations.split('\n')) {
|
||||
// Each @font-face has the subset above it in a comment
|
||||
const newSubset = (_a = /\/\* (.+?) \*\//.exec(line)) === null || _a === void 0 ? void 0 : _a[1];
|
||||
if (newSubset) {
|
||||
currentSubset = newSubset;
|
||||
}
|
||||
else {
|
||||
const googleFontFileUrl = (_b = /src: url\((.+?)\)/.exec(line)) === null || _b === void 0 ? void 0 : _b[1];
|
||||
if (googleFontFileUrl &&
|
||||
!fontFiles.some((foundFile) => foundFile.googleFontFileUrl === googleFontFileUrl)) {
|
||||
fontFiles.push({
|
||||
googleFontFileUrl,
|
||||
preloadFontFile: !!preload && (callSubsets !== null && callSubsets !== void 0 ? callSubsets : subsets).includes(currentSubset),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// Download font files
|
||||
const downloadedFiles = await Promise.all(fontFiles.map(async ({ googleFontFileUrl, preloadFontFile }) => {
|
||||
const hasCachedFont = fontCache.has(googleFontFileUrl);
|
||||
const fontFileBuffer = hasCachedFont
|
||||
? fontCache.get(googleFontFileUrl)
|
||||
: await (0, utils_1.fetchFontFile)(googleFontFileUrl).catch(() => null);
|
||||
if (!hasCachedFont) {
|
||||
fontCache.set(googleFontFileUrl, fontFileBuffer);
|
||||
}
|
||||
else {
|
||||
fontCache.delete(googleFontFileUrl);
|
||||
}
|
||||
if (fontFileBuffer === null) {
|
||||
(0, utils_2.nextFontError)(`Failed to fetch \`${fontFamily}\` from Google Fonts.`);
|
||||
}
|
||||
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(googleFontFileUrl)[1];
|
||||
// Emit font file to .next/static/media
|
||||
const selfHostedFileUrl = emitFontFile(fontFileBuffer, ext, preloadFontFile);
|
||||
return {
|
||||
googleFontFileUrl,
|
||||
selfHostedFileUrl,
|
||||
};
|
||||
}));
|
||||
// Replace @font-face sources with self-hosted files
|
||||
let updatedCssResponse = fontFaceDeclarations;
|
||||
for (const { googleFontFileUrl, selfHostedFileUrl } of downloadedFiles) {
|
||||
updatedCssResponse = updatedCssResponse.replace(new RegExp(escapeStringRegexp(googleFontFileUrl), 'g'), selfHostedFileUrl);
|
||||
}
|
||||
return {
|
||||
...result,
|
||||
css: updatedCssResponse,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
loaderContext.cacheable(false);
|
||||
if (isDev) {
|
||||
if (isServer) {
|
||||
Log.error(`Failed to download \`${fontFamily}\` from Google Fonts. Using fallback font instead.`);
|
||||
}
|
||||
// In dev we should return the fallback font instead of throwing an error
|
||||
let css = `@font-face {
|
||||
font-family: '${fontFamily} Fallback';
|
||||
src: local("${(_c = adjustFontFallbackMetrics === null || adjustFontFallbackMetrics === void 0 ? void 0 : adjustFontFallbackMetrics.fallbackFont) !== null && _c !== void 0 ? _c : 'Arial'}");`;
|
||||
if (adjustFontFallbackMetrics) {
|
||||
css += `
|
||||
ascent-override:${adjustFontFallbackMetrics.ascentOverride};
|
||||
descent-override:${adjustFontFallbackMetrics.descentOverride};
|
||||
line-gap-override:${adjustFontFallbackMetrics.lineGapOverride};
|
||||
size-adjust:${adjustFontFallbackMetrics.sizeAdjust};`;
|
||||
}
|
||||
css += '\n}';
|
||||
return {
|
||||
...result,
|
||||
css,
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.default = downloadGoogleFonts;
|
||||
27
kitabcitab/node_modules/@next/font/dist/google/utils.d.ts
generated
vendored
Normal file
27
kitabcitab/node_modules/@next/font/dist/google/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/// <reference types="node" />
|
||||
declare type FontOptions = {
|
||||
fontFamily: string;
|
||||
weights: string[];
|
||||
styles: string[];
|
||||
display: string;
|
||||
preload: boolean;
|
||||
selectedVariableAxes?: string[];
|
||||
fallback?: string[];
|
||||
adjustFontFallback: boolean;
|
||||
variable?: string;
|
||||
subsets?: string[];
|
||||
};
|
||||
export declare function validateData(functionName: string, data: any): FontOptions;
|
||||
export declare function getUrl(fontFamily: string, axes: {
|
||||
wght?: string[];
|
||||
ital?: string[];
|
||||
variableAxes?: [string, string][];
|
||||
}, display: string): string;
|
||||
export declare function fetchCSSFromGoogleFonts(url: string, fontFamily: string): Promise<any>;
|
||||
export declare function fetchFontFile(url: string): Promise<Buffer>;
|
||||
export declare function getFontAxes(fontFamily: string, weights: string[], styles: string[], selectedVariableAxes?: string[]): {
|
||||
wght?: string[];
|
||||
ital?: string[];
|
||||
variableAxes?: [string, string][];
|
||||
};
|
||||
export {};
|
||||
219
kitabcitab/node_modules/@next/font/dist/google/utils.js
generated
vendored
Normal file
219
kitabcitab/node_modules/@next/font/dist/google/utils.js
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFontAxes = exports.fetchFontFile = exports.fetchCSSFromGoogleFonts = exports.getUrl = exports.validateData = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
// @ts-ignore
|
||||
const node_fetch_1 = __importDefault(require("next/dist/compiled/node-fetch"));
|
||||
const utils_1 = require("../utils");
|
||||
const font_data_json_1 = __importDefault(require("./font-data.json"));
|
||||
const allowedDisplayValues = ['auto', 'block', 'swap', 'fallback', 'optional'];
|
||||
const formatValues = (values) => values.map((val) => `\`${val}\``).join(', ');
|
||||
function validateData(functionName, data) {
|
||||
let { weight, style, display = 'optional', preload = true, axes, fallback, adjustFontFallback = true, variable, subsets, } = data[0] || {};
|
||||
if (functionName === '') {
|
||||
(0, utils_1.nextFontError)(`@next/font/google has no default export`);
|
||||
}
|
||||
const fontFamily = functionName.replace(/_/g, ' ');
|
||||
const fontFamilyData = font_data_json_1.default[fontFamily];
|
||||
const fontWeights = fontFamilyData === null || fontFamilyData === void 0 ? void 0 : fontFamilyData.weights;
|
||||
if (!fontWeights) {
|
||||
(0, utils_1.nextFontError)(`Unknown font \`${fontFamily}\``);
|
||||
}
|
||||
const fontStyles = fontFamilyData.styles;
|
||||
const weights = !weight
|
||||
? []
|
||||
: [...new Set(Array.isArray(weight) ? weight : [weight])];
|
||||
const styles = !style
|
||||
? []
|
||||
: [...new Set(Array.isArray(style) ? style : [style])];
|
||||
if (weights.length === 0) {
|
||||
// Set variable as default, throw if not available
|
||||
if (fontWeights.includes('variable')) {
|
||||
weights.push('variable');
|
||||
}
|
||||
else {
|
||||
(0, utils_1.nextFontError)(`Missing weight for font \`${fontFamily}\`.\nAvailable weights: ${formatValues(fontWeights)}`);
|
||||
}
|
||||
}
|
||||
if (weights.length > 1 && weights.includes('variable')) {
|
||||
(0, utils_1.nextFontError)(`Unexpected \`variable\` in weight array for font \`${fontFamily}\`. You only need \`variable\`, it includes all available weights.`);
|
||||
}
|
||||
weights.forEach((selectedWeight) => {
|
||||
if (!fontWeights.includes(selectedWeight)) {
|
||||
(0, utils_1.nextFontError)(`Unknown weight \`${selectedWeight}\` for font \`${fontFamily}\`.\nAvailable weights: ${formatValues(fontWeights)}`);
|
||||
}
|
||||
});
|
||||
if (styles.length === 0) {
|
||||
if (fontStyles.length === 1) {
|
||||
styles.push(fontStyles[0]);
|
||||
}
|
||||
else {
|
||||
styles.push('normal');
|
||||
}
|
||||
}
|
||||
styles.forEach((selectedStyle) => {
|
||||
if (!fontStyles.includes(selectedStyle)) {
|
||||
(0, utils_1.nextFontError)(`Unknown style \`${selectedStyle}\` for font \`${fontFamily}\`.\nAvailable styles: ${formatValues(fontStyles)}`);
|
||||
}
|
||||
});
|
||||
if (!allowedDisplayValues.includes(display)) {
|
||||
(0, utils_1.nextFontError)(`Invalid display value \`${display}\` for font \`${fontFamily}\`.\nAvailable display values: ${formatValues(allowedDisplayValues)}`);
|
||||
}
|
||||
if (weights[0] !== 'variable' && axes) {
|
||||
(0, utils_1.nextFontError)('Axes can only be defined for variable fonts');
|
||||
}
|
||||
return {
|
||||
fontFamily,
|
||||
weights,
|
||||
styles,
|
||||
display,
|
||||
preload,
|
||||
selectedVariableAxes: axes,
|
||||
fallback,
|
||||
adjustFontFallback,
|
||||
variable,
|
||||
subsets,
|
||||
};
|
||||
}
|
||||
exports.validateData = validateData;
|
||||
function getUrl(fontFamily, axes, display) {
|
||||
var _a, _b;
|
||||
// Variants are all combinations of weight and style, each variant will result in a separate font file
|
||||
const variants = [];
|
||||
if (axes.wght) {
|
||||
for (const wgth of axes.wght) {
|
||||
if (!axes.ital) {
|
||||
variants.push([['wght', wgth], ...((_a = axes.variableAxes) !== null && _a !== void 0 ? _a : [])]);
|
||||
}
|
||||
else {
|
||||
for (const ital of axes.ital) {
|
||||
variants.push([
|
||||
['ital', ital],
|
||||
['wght', wgth],
|
||||
...((_b = axes.variableAxes) !== null && _b !== void 0 ? _b : []),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (axes.variableAxes) {
|
||||
// Variable fonts might not have a range of weights, just add optional variable axes in that case
|
||||
variants.push([...axes.variableAxes]);
|
||||
}
|
||||
// Google api requires the axes to be sorted, starting with lowercase words
|
||||
if (axes.variableAxes) {
|
||||
variants.forEach((variant) => {
|
||||
variant.sort(([a], [b]) => {
|
||||
const aIsLowercase = a.charCodeAt(0) > 96;
|
||||
const bIsLowercase = b.charCodeAt(0) > 96;
|
||||
if (aIsLowercase && !bIsLowercase)
|
||||
return -1;
|
||||
if (bIsLowercase && !aIsLowercase)
|
||||
return 1;
|
||||
return a > b ? 1 : -1;
|
||||
});
|
||||
});
|
||||
}
|
||||
let url = `https://fonts.googleapis.com/css2?family=${fontFamily.replace(/ /g, '+')}`;
|
||||
if (variants.length > 0) {
|
||||
url = `${url}:${variants[0].map(([key]) => key).join(',')}@${variants
|
||||
.map((variant) => variant.map(([, val]) => val).join(','))
|
||||
.sort()
|
||||
.join(';')}`;
|
||||
}
|
||||
url = `${url}&display=${display}`;
|
||||
return url;
|
||||
}
|
||||
exports.getUrl = getUrl;
|
||||
async function fetchCSSFromGoogleFonts(url, fontFamily) {
|
||||
let mockedResponse;
|
||||
if (process.env.NEXT_FONT_GOOGLE_MOCKED_RESPONSES) {
|
||||
const mockFile = require(process.env.NEXT_FONT_GOOGLE_MOCKED_RESPONSES);
|
||||
mockedResponse = mockFile[url];
|
||||
if (!mockedResponse) {
|
||||
(0, utils_1.nextFontError)('Missing mocked response for URL: ' + url);
|
||||
}
|
||||
}
|
||||
let cssResponse;
|
||||
if (mockedResponse) {
|
||||
cssResponse = mockedResponse;
|
||||
}
|
||||
else {
|
||||
const res = await (0, node_fetch_1.default)(url, {
|
||||
headers: {
|
||||
// The file format is based off of the user agent, make sure woff2 files are fetched
|
||||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
|
||||
},
|
||||
});
|
||||
if (!res.ok) {
|
||||
(0, utils_1.nextFontError)(`Failed to fetch font \`${fontFamily}\`.\nURL: ${url}`);
|
||||
}
|
||||
cssResponse = await res.text();
|
||||
}
|
||||
return cssResponse;
|
||||
}
|
||||
exports.fetchCSSFromGoogleFonts = fetchCSSFromGoogleFonts;
|
||||
async function fetchFontFile(url) {
|
||||
if (process.env.NEXT_FONT_GOOGLE_MOCKED_RESPONSES) {
|
||||
if (url.startsWith('/')) {
|
||||
return fs_1.default.readFileSync(url);
|
||||
}
|
||||
return Buffer.from(url);
|
||||
}
|
||||
const arrayBuffer = await (0, node_fetch_1.default)(url).then((r) => r.arrayBuffer());
|
||||
return Buffer.from(arrayBuffer);
|
||||
}
|
||||
exports.fetchFontFile = fetchFontFile;
|
||||
function getFontAxes(fontFamily, weights, styles, selectedVariableAxes) {
|
||||
const allAxes = font_data_json_1.default[fontFamily].axes;
|
||||
const hasItalic = styles.includes('italic');
|
||||
const hasNormal = styles.includes('normal');
|
||||
const ital = hasItalic ? [...(hasNormal ? ['0'] : []), '1'] : undefined;
|
||||
// Weights will always contain one element if it's a variable font
|
||||
if (weights[0] === 'variable') {
|
||||
if (selectedVariableAxes) {
|
||||
const defineAbleAxes = allAxes
|
||||
.map(({ tag }) => tag)
|
||||
.filter((tag) => tag !== 'wght');
|
||||
if (defineAbleAxes.length === 0) {
|
||||
(0, utils_1.nextFontError)(`Font \`${fontFamily}\` has no definable \`axes\``);
|
||||
}
|
||||
if (!Array.isArray(selectedVariableAxes)) {
|
||||
(0, utils_1.nextFontError)(`Invalid axes value for font \`${fontFamily}\`, expected an array of axes.\nAvailable axes: ${formatValues(defineAbleAxes)}`);
|
||||
}
|
||||
selectedVariableAxes.forEach((key) => {
|
||||
if (!defineAbleAxes.some((tag) => tag === key)) {
|
||||
(0, utils_1.nextFontError)(`Invalid axes value \`${key}\` for font \`${fontFamily}\`.\nAvailable axes: ${formatValues(defineAbleAxes)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
let weightAxis;
|
||||
let variableAxes;
|
||||
for (const { tag, min, max } of allAxes) {
|
||||
if (tag === 'wght') {
|
||||
weightAxis = `${min}..${max}`;
|
||||
}
|
||||
else if (selectedVariableAxes === null || selectedVariableAxes === void 0 ? void 0 : selectedVariableAxes.includes(tag)) {
|
||||
if (!variableAxes) {
|
||||
variableAxes = [];
|
||||
}
|
||||
variableAxes.push([tag, `${min}..${max}`]);
|
||||
}
|
||||
}
|
||||
return {
|
||||
wght: weightAxis ? [weightAxis] : undefined,
|
||||
ital,
|
||||
variableAxes,
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
ital,
|
||||
wght: weights,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getFontAxes = getFontAxes;
|
||||
Reference in New Issue
Block a user