next-font 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/google/loader.d.ts +38 -3
- package/dist/google/loader.js +7 -7
- package/dist/index.d.ts +38 -0
- package/dist/index.js +1 -0
- package/dist/local/fontkit-DX1wsFnK.js +1 -0
- package/dist/local/get-fallback-metrics-from-font-file.d.ts +1 -1
- package/dist/local/loader.d.ts +38 -3
- package/dist/local/loader.js +4 -4
- package/google/index.d.ts +1 -1
- package/google/index.js +2 -2
- package/google/loader.d.ts +1 -1
- package/google/loader.js +1 -1
- package/google/target.css +1 -1
- package/local/index.d.ts +1 -1
- package/local/index.js +2 -2
- package/local/loader.d.ts +1 -1
- package/local/loader.js +1 -1
- package/local/target.css +1 -1
- package/package.json +27 -7
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
## Next Font
|
|
2
2
|
|
|
3
|
-
Derived from `@next/font`.
|
|
3
|
+
Derived from `@next/font`. Aimed to be used in conjunction with [@next-font/plugin- vite](https://npmjs.com/package/@next-font/plugin-vite)
|
|
4
|
+
|
|
5
|
+
> This package is best used with the [@next-font/plugin-vite](https://npmjs.com/package/@next-font/plugin-vite) package or any plugins under the [@next-font](https://npmjs.com/org/next-font) organization.
|
|
4
6
|
|
|
5
7
|
### Install
|
|
6
8
|
|
|
@@ -32,4 +34,18 @@ const myFont = localFont({
|
|
|
32
34
|
}) // { className: '...' }
|
|
33
35
|
```
|
|
34
36
|
|
|
37
|
+
This package also supports accessing the manifest, which contains per-file font information. This can be useful for generating preload or preconnect tags in the `<head>` of your HTML document.
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import nextFontManifest from 'next-font/manifest';
|
|
41
|
+
|
|
42
|
+
// raw manifest
|
|
43
|
+
const manifest = nextFontManifest.manifest;
|
|
44
|
+
|
|
45
|
+
// get fonts with preload enabled
|
|
46
|
+
const preloadableFonts = nextFontManifest.getPreloadableFonts(someFilePath /* ex. import.meta.url */);
|
|
47
|
+
// or skip accessing preloadableFonts and get data for <head>
|
|
48
|
+
const metadata = nextFontManifest.getFontMetadata(someFilePath /* ex. import.meta.url */);
|
|
49
|
+
```
|
|
50
|
+
|
|
35
51
|
See the Next.js [API Page](https://nextjs.org/docs/app/api-reference/components/font) for more options.
|
package/dist/google/loader.d.ts
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
type FontLoaderOptions = Omit<{
|
|
2
|
+
functionName: string;
|
|
3
|
+
variableName: string;
|
|
4
|
+
data: any[];
|
|
5
|
+
emitFontFile: (content: Buffer, ext: string, preload: boolean, isUsingSizeAdjust?: boolean) => string;
|
|
6
|
+
resolve: (src: string) => string;
|
|
7
|
+
isDev: boolean;
|
|
8
|
+
isServer: boolean;
|
|
9
|
+
loaderContext: any;
|
|
10
|
+
}, 'loaderContext'> & {
|
|
11
|
+
loaderContext: {
|
|
12
|
+
fs?: {
|
|
13
|
+
readFile: (...args: any[]) => Promise<Buffer | Uint8Array | string>;
|
|
14
|
+
};
|
|
15
|
+
error: (message: string) => any;
|
|
16
|
+
};
|
|
17
|
+
cache?: {
|
|
18
|
+
css?: Map<string, string | null>;
|
|
19
|
+
font?: Map<string, string | null>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type FontLoader = (options: FontLoaderOptions) => Promise<{
|
|
23
|
+
css: string;
|
|
24
|
+
fallbackFonts?: string[];
|
|
25
|
+
variable?: string;
|
|
26
|
+
adjustFontFallback?: AdjustFontFallback;
|
|
27
|
+
weight?: string;
|
|
28
|
+
style?: string;
|
|
29
|
+
}>;
|
|
30
|
+
type AdjustFontFallback = {
|
|
31
|
+
fallbackFont: string;
|
|
32
|
+
ascentOverride?: string;
|
|
33
|
+
descentOverride?: string;
|
|
34
|
+
lineGapOverride?: string;
|
|
35
|
+
sizeAdjust?: string;
|
|
36
|
+
};
|
|
2
37
|
|
|
3
|
-
declare const
|
|
38
|
+
declare const loader: FontLoader;
|
|
4
39
|
|
|
5
|
-
export {
|
|
40
|
+
export { loader as default };
|
package/dist/google/loader.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{nextFontError as e}from"../next-font-error.js";import{findFontFilesInCss as t}from"./find-font-files-in-css.js";import{getFontAxes as o}from"./get-font-axes.js";import{getGoogleFontsUrl as l}from"./get-google-fonts-url.js";import{validateGoogleFontFunctionCall as a}from"./validate-google-font-function-call.js";let r=e=>{let t;return()=>(t||(t=e().then(e=>(t=e,e))),t)},n=/[|\\{}()[\]^$+*?.-]/,s=/[|\\{}()[\]^$+*?.-]/g,i=e=>n.test(e)?e.replace(s,"\\$&"):e,f=r(()=>import("./get-fallback-font-override-metrics.js").then(e=>e.default||e)),c=r(()=>import("./fetch-css-from-google-fonts.js").then(e=>e.default||e)),d=r(()=>import("./fetch-font-file.js").then(e=>e.default||e)),u=async({functionName:r,data:n,emitFontFile:s,isDev:u,isServer:g,loaderContext:m,cache:{css:h,font:p}={}})=>{let{fontFamily:w,weights:$,styles:v,display:F,preload:j,selectedVariableAxes:y,fallback:b,adjustFontFallback:x,variable:k,subsets:G}=a(r,n[0]),O=o(w,$,v,y),z=l(w,O,F),A=x?await (async()=>{let{getFallbackFontOverrideMetrics:e}=await f();return e(w)})():void 0,E={fallbackFonts:b,weight:1===$.length&&"variable"!==$[0]?$[0]:void 0,style:1===v.length?v[0]:void 0,variable:k,adjustFontFallback:A};try{let o=h?.has(z),l=null!=h&&o?h.get(z):await (async()=>{let{fetchCSSFromGoogleFonts:e}=await c();return await e(z,w,u).catch(e=>(console.error(e),null))})();o?h?.delete(z):h?.set(z,l??null),null==l&&e(`Failed to fetch \`${w}\` from Google Fonts.`),l=l.split("body {",1)[0];let a=t(l,j?G:void 0),r=await Promise.all(a.map(async({googleFontFileUrl:t,preloadFontFile:o})=>{let l=p?.has(t),a=null!=p&&l?p.get(t):await (async()=>{let{fetchFontFile:e}=await d();return await e(t,u).catch(e=>(console.error(e),null))})();l?p?.delete(t):p?.set(t,a??null),null==a&&e(`Failed to fetch \`${w}\` from Google Fonts.`);let r=/\.(woff|woff2|eot|ttf|otf)$/.exec(t)[1],n=s(a,r,o,!!A);return{googleFontFileUrl:t,selfHostedFileUrl:n}})),n=l;for(let{googleFontFileUrl:e,selfHostedFileUrl:t}of r)n=n.replace(RegExp(i(e),"g"),t);return{...E,css:n}}catch(e){if(u){g&&m.error(`Failed to download \`${w}\` from Google Fonts. Using fallback font instead.
|
|
2
2
|
|
|
3
3
|
${e.message}}`);let t=`@font-face {
|
|
4
|
-
font-family: '${
|
|
5
|
-
src: local("${
|
|
6
|
-
ascent-override:${
|
|
7
|
-
descent-override:${
|
|
8
|
-
line-gap-override:${
|
|
9
|
-
size-adjust:${
|
|
4
|
+
font-family: '${w} Fallback';
|
|
5
|
+
src: local("${A?.fallbackFont??"Arial"}");`;return A&&(t+=`
|
|
6
|
+
ascent-override:${A.ascentOverride};
|
|
7
|
+
descent-override:${A.descentOverride};
|
|
8
|
+
line-gap-override:${A.lineGapOverride};
|
|
9
|
+
size-adjust:${A.sizeAdjust};`),t+="\n}",{...E,css:t}}throw e}};export{u as default};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type FontLoaderOptions = Omit<{
|
|
2
|
+
functionName: string;
|
|
3
|
+
variableName: string;
|
|
4
|
+
data: any[];
|
|
5
|
+
emitFontFile: (content: Buffer, ext: string, preload: boolean, isUsingSizeAdjust?: boolean) => string;
|
|
6
|
+
resolve: (src: string) => string;
|
|
7
|
+
isDev: boolean;
|
|
8
|
+
isServer: boolean;
|
|
9
|
+
loaderContext: any;
|
|
10
|
+
}, 'loaderContext'> & {
|
|
11
|
+
loaderContext: {
|
|
12
|
+
fs?: {
|
|
13
|
+
readFile: (...args: any[]) => Promise<Buffer | Uint8Array | string>;
|
|
14
|
+
};
|
|
15
|
+
error: (message: string) => any;
|
|
16
|
+
};
|
|
17
|
+
cache?: {
|
|
18
|
+
css?: Map<string, string | null>;
|
|
19
|
+
font?: Map<string, string | null>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type FontLoader = (options: FontLoaderOptions) => Promise<{
|
|
23
|
+
css: string;
|
|
24
|
+
fallbackFonts?: string[];
|
|
25
|
+
variable?: string;
|
|
26
|
+
adjustFontFallback?: AdjustFontFallback;
|
|
27
|
+
weight?: string;
|
|
28
|
+
style?: string;
|
|
29
|
+
}>;
|
|
30
|
+
type AdjustFontFallback = {
|
|
31
|
+
fallbackFont: string;
|
|
32
|
+
ascentOverride?: string;
|
|
33
|
+
descentOverride?: string;
|
|
34
|
+
lineGapOverride?: string;
|
|
35
|
+
sizeAdjust?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type { AdjustFontFallback, FontLoader };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|