astro-font-loader 0.1.1 → 0.1.2
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 +96 -0
- package/dist/fonts/index.d.ts +3 -3
- package/dist/fonts/index.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -5
- package/src/index.ts +0 -4
package/README.md
CHANGED
|
@@ -17,3 +17,99 @@ yarn add astro-font-loader
|
|
|
17
17
|
# Using pnpm
|
|
18
18
|
pnpm add astro-font-loader
|
|
19
19
|
```
|
|
20
|
+
|
|
21
|
+
## How It Works
|
|
22
|
+
|
|
23
|
+
1. **Setup Phase**: During Astro's config setup, the integration:
|
|
24
|
+
- Locates the specified font packages in your `node_modules`
|
|
25
|
+
- Applies the filter function (if provided) to select fonts
|
|
26
|
+
- Prepares the list of fonts to be copied
|
|
27
|
+
|
|
28
|
+
2. **Build Phase**: After Astro completes the build:
|
|
29
|
+
- Copies the filtered font files to the output directory
|
|
30
|
+
- Transforms CSS imports to reference the copied fonts
|
|
31
|
+
- Ensures fonts are available in your production build
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Basic Setup
|
|
36
|
+
|
|
37
|
+
Add the integration to your `astro.config.mjs` or `astro.config.ts` file:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { defineConfig } from 'astro/config';
|
|
41
|
+
import { fontsIntegration } from 'astro-font-loader';
|
|
42
|
+
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
site: 'https://example.com',
|
|
45
|
+
integrations: [
|
|
46
|
+
fontsIntegration({
|
|
47
|
+
packages: ["@company/design-system-fonts"],
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Filtering Fonts
|
|
54
|
+
|
|
55
|
+
Use the `filter` option to selectively include only specific fonts from your font packages. This is useful when you have a large font library but only need certain fonts for your project:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { defineConfig } from 'astro/config';
|
|
59
|
+
import { fontsIntegration } from 'astro-font-loader';
|
|
60
|
+
|
|
61
|
+
// Define a filter function to select specific fonts
|
|
62
|
+
const fontFilter = (filename: string) => {
|
|
63
|
+
const name = filename.toLowerCase();
|
|
64
|
+
return name.includes("hatton") ||
|
|
65
|
+
name.includes("berkeleymono");
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
site: 'https://example.com',
|
|
70
|
+
integrations: [
|
|
71
|
+
fontsIntegration({
|
|
72
|
+
packages: ["@company/design-system-fonts"],
|
|
73
|
+
filter: fontFilter,
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Custom Output Directory
|
|
80
|
+
|
|
81
|
+
By default, fonts are copied to a `fonts` directory in your build output. You can customize this:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
fontsIntegration({
|
|
85
|
+
packages: ["@company/design-system-fonts"],
|
|
86
|
+
filter: fontFilter,
|
|
87
|
+
outputDir: "assets/fonts", // Custom output directory
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Multiple Font Packages
|
|
92
|
+
|
|
93
|
+
You can load fonts from multiple packages:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
fontsIntegration({
|
|
97
|
+
packages: [
|
|
98
|
+
"@company/design-system-fonts",
|
|
99
|
+
"@fontsource/roboto",
|
|
100
|
+
"@custom/typefaces"
|
|
101
|
+
],
|
|
102
|
+
filter: (filename) => {
|
|
103
|
+
// Only include specific fonts from all packages
|
|
104
|
+
const name = filename.toLowerCase();
|
|
105
|
+
return name.includes("hatton") ||
|
|
106
|
+
name.includes("berkeleymono") ||
|
|
107
|
+
name.includes("roboto-400");
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Additional Documentation
|
|
113
|
+
|
|
114
|
+
* [API Reference](./docs/API.md)
|
|
115
|
+
* [Examples](./docs/EXAMPLES.md)
|
package/dist/fonts/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAvailableFonts } from "./available.ts";
|
|
2
|
-
import type { FontsPackageInfo } from "./fontInfo.
|
|
3
|
-
import { getFontsPackageInfo } from "./package.
|
|
4
|
-
export type { FontsPackageInfo };
|
|
2
|
+
import type { FontInfo, FontsPackageInfo } from "./fontInfo.ts";
|
|
3
|
+
import { getFontsPackageInfo } from "./package.ts";
|
|
4
|
+
export type { FontInfo, FontsPackageInfo };
|
|
5
5
|
export { getFontsPackageInfo, getAvailableFonts };
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export { getFontsCss } from "./css/index.ts";
|
|
2
1
|
export { fontsIntegration } from "./integration.ts";
|
|
3
|
-
export { getFontsPackageInfo, getAvailableFonts } from "./fonts/index.ts";
|
|
4
2
|
export type { FontsIntegrationOptions } from "./integration.ts";
|
|
3
|
+
export { getFontsCss } from "./css/index.ts";
|
|
4
|
+
export type { GetFontsCssOptions } from "./css/get.ts";
|
|
5
|
+
export { getFontsPackageInfo, getAvailableFonts } from "./fonts/index.ts";
|
|
6
|
+
export type { FontInfo, FontsPackageInfo } from "./fonts/index.ts";
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,15 +4,21 @@
|
|
|
4
4
|
"author": "Mikey Sleevi <development@frogman.simplelogin.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.1.
|
|
8
|
-
"
|
|
9
|
-
|
|
7
|
+
"version": "0.1.2",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18.0.0"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
10
14
|
"exports": {
|
|
11
15
|
".": {
|
|
12
16
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.js"
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
21
|
+
"sideEffects": false,
|
|
16
22
|
"files": [
|
|
17
23
|
"dist"
|
|
18
24
|
],
|
|
@@ -35,7 +41,8 @@
|
|
|
35
41
|
"build": "tsc",
|
|
36
42
|
"test": "node --import tsx --test tests/**/*.test.ts",
|
|
37
43
|
"lint": "prettier --check . && eslint .",
|
|
38
|
-
"lint:fix": "prettier --write . && eslint . --fix"
|
|
44
|
+
"lint:fix": "prettier --write . && eslint . --fix",
|
|
45
|
+
"clean": "rm -rf dist"
|
|
39
46
|
},
|
|
40
47
|
"devDependencies": {
|
|
41
48
|
"@tsconfig/recommended": "^1.0.13",
|
package/src/index.ts
DELETED