astro-font-loader 0.2.3 → 0.3.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 +100 -98
- package/components/FontLoader.astro +58 -51
- package/dist/astroBuild.d.ts +1 -6
- package/dist/astroBuild.d.ts.map +1 -1
- package/dist/astroBuild.js +3 -8
- package/dist/astroBuild.js.map +1 -1
- package/dist/astroConfig.d.ts +3 -14
- package/dist/astroConfig.d.ts.map +1 -1
- package/dist/astroConfig.js +17 -30
- package/dist/astroConfig.js.map +1 -1
- package/dist/css/filter.d.ts +12 -8
- package/dist/css/filter.d.ts.map +1 -1
- package/dist/css/filter.js +48 -18
- package/dist/css/filter.js.map +1 -1
- package/dist/css/get.d.ts +18 -12
- package/dist/css/get.d.ts.map +1 -1
- package/dist/css/get.js +12 -20
- package/dist/css/get.js.map +1 -1
- package/dist/css/transform.d.ts +2 -7
- package/dist/css/transform.d.ts.map +1 -1
- package/dist/css/transform.js +3 -11
- package/dist/css/transform.js.map +1 -1
- package/dist/fonts/package.d.ts +2 -1
- package/dist/fonts/package.d.ts.map +1 -1
- package/dist/fonts/package.js +3 -2
- package/dist/fonts/package.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +3 -35
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +6 -9
- package/dist/integration.js.map +1 -1
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
- package/dist/components/types.d.ts +0 -7
- package/dist/components/types.d.ts.map +0 -1
- package/dist/components/types.js.map +0 -1
- /package/dist/{components/types.js → types.js} +0 -0
package/README.md
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
`astro-font-loader` hooks into the astro build process to copy selected fonts from installed font packages into the local build artifacts.
|
|
7
7
|
|
|
8
|
+
> [!NOTE]
|
|
9
|
+
> **Why use this instead of the built-in Astro Fonts API?** <br><br>
|
|
10
|
+
> `astro-font-loader` was originally designed as a package based font solution, but continues due to two limitations.
|
|
11
|
+
>
|
|
12
|
+
> The first is that there are *no controls over output file paths.* Astro's built-in font handling places font files in hashed, opaque paths. This makes it difficult to configure [Early Hints](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Link) (`103` responses) or `Link` headers since you can't predict the final font URLs ahead of time. You end up writing a custom build script anyways to create predictable paths in this case.
|
|
13
|
+
>
|
|
14
|
+
> The second is that there is *no media query support for font loading.* There is no way to conditionally load fonts based on viewport size (e.g., `min-width` media queries). This means all font weights and variants are downloaded on every device, even if they're only used on larger screens.
|
|
15
|
+
|
|
8
16
|
## Installation
|
|
9
17
|
|
|
10
18
|
```bash
|
|
@@ -22,165 +30,159 @@ pnpm add astro-font-loader
|
|
|
22
30
|
|
|
23
31
|
1. **Setup Phase**: During Astro's config setup, the integration:
|
|
24
32
|
- Locates the specified font packages in your `node_modules`
|
|
25
|
-
-
|
|
26
|
-
- Prepares the list of
|
|
33
|
+
- Matches `@font-face` rules from the package CSS by `font-family`, `font-weight`, and `font-style`
|
|
34
|
+
- Prepares the list of font files to be copied
|
|
27
35
|
|
|
28
36
|
2. **Build Phase**: After Astro completes the build:
|
|
29
|
-
- Copies the
|
|
30
|
-
- Transforms CSS imports to reference the copied fonts
|
|
37
|
+
- Copies the matched font files to the output directory
|
|
31
38
|
- Ensures fonts are available in your production build
|
|
32
39
|
|
|
33
40
|
## Usage
|
|
34
41
|
|
|
35
42
|
### Basic Setup
|
|
36
43
|
|
|
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:
|
|
44
|
+
Add the integration to your `astro.config.mjs` or `astro.config.ts` file. The variant `name` should match the `font-family` value in the package's CSS `@font-face` rules:
|
|
56
45
|
|
|
57
46
|
```typescript
|
|
58
47
|
import { defineConfig } from 'astro/config';
|
|
59
48
|
import { fontsIntegration } from 'astro-font-loader';
|
|
60
49
|
|
|
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
50
|
export default defineConfig({
|
|
69
|
-
site: 'https://example.com',
|
|
70
51
|
integrations: [
|
|
71
52
|
fontsIntegration({
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
outputDirectory: "fonts",
|
|
54
|
+
fonts: [
|
|
55
|
+
{
|
|
56
|
+
family: "Roboto",
|
|
57
|
+
source: { type: "package", package: "@company/design-system-fonts" },
|
|
58
|
+
variants: [
|
|
59
|
+
{ name: "Roboto", weight: 400, styles: ["normal"] },
|
|
60
|
+
{ name: "Roboto", weight: 700, styles: ["normal"] },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
74
64
|
}),
|
|
75
65
|
],
|
|
76
66
|
});
|
|
77
67
|
```
|
|
78
68
|
|
|
79
|
-
###
|
|
69
|
+
### Multiple Font Families
|
|
80
70
|
|
|
81
|
-
|
|
71
|
+
A single package can provide multiple font families. Each family gets its own entry in the `fonts` array:
|
|
82
72
|
|
|
83
73
|
```typescript
|
|
84
74
|
fontsIntegration({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
outputDirectory: "fonts",
|
|
76
|
+
fonts: [
|
|
77
|
+
{
|
|
78
|
+
family: "Berkeley Mono",
|
|
79
|
+
source: { type: "package", package: "@company/design-system-fonts" },
|
|
80
|
+
variants: [
|
|
81
|
+
{ name: "Berkeley Mono v2 Variable", weight: [100, 900], styles: ["normal", "oblique"] },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
family: "EB Garamond",
|
|
86
|
+
source: { type: "package", package: "@company/design-system-fonts" },
|
|
87
|
+
variants: [
|
|
88
|
+
{ name: "EB Garamond", weight: 600, styles: ["normal"] },
|
|
89
|
+
{ name: "EB Garamond", weight: 700, styles: ["normal"] },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
88
93
|
})
|
|
89
94
|
```
|
|
90
95
|
|
|
91
|
-
###
|
|
96
|
+
### Custom Style File
|
|
92
97
|
|
|
93
|
-
You can
|
|
98
|
+
By default, the integration looks for CSS at `src/index.css` within the package. You can override this with `styleFile`:
|
|
94
99
|
|
|
95
100
|
```typescript
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
"@
|
|
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");
|
|
101
|
+
{
|
|
102
|
+
family: "Custom Font",
|
|
103
|
+
source: {
|
|
104
|
+
type: "package",
|
|
105
|
+
package: "@company/fonts",
|
|
106
|
+
styleFile: "dist/fonts.css",
|
|
108
107
|
},
|
|
109
|
-
|
|
108
|
+
variants: [
|
|
109
|
+
{ name: "Custom Font", weight: 400, styles: ["normal"] },
|
|
110
|
+
],
|
|
111
|
+
}
|
|
110
112
|
```
|
|
111
113
|
|
|
112
114
|
### FontLoader Component
|
|
113
115
|
|
|
114
|
-
The
|
|
116
|
+
The `FontLoader` component generates `<link rel="preload">` tags and inline `@font-face` CSS. Use it alongside the integration — the integration copies font files to the build output, while the component injects the HTML needed to load them.
|
|
115
117
|
|
|
116
118
|
```astro
|
|
117
119
|
---
|
|
118
|
-
// src/layouts/Layout.astro
|
|
119
120
|
import FontLoader from 'astro-font-loader/FontLoader.astro';
|
|
121
|
+
|
|
122
|
+
const source = { type: "package" as const, package: "@company/design-system-fonts" };
|
|
120
123
|
---
|
|
121
124
|
<html>
|
|
122
125
|
<head>
|
|
123
|
-
<FontLoader
|
|
126
|
+
<FontLoader
|
|
127
|
+
fonts={[
|
|
128
|
+
{
|
|
129
|
+
family: "Berkeley Mono",
|
|
130
|
+
source,
|
|
131
|
+
variants: [
|
|
132
|
+
{ name: "Berkeley Mono v2 Variable", weight: [100, 900], styles: ["normal", "oblique"] },
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
family: "EB Garamond",
|
|
137
|
+
source,
|
|
138
|
+
variants: [
|
|
139
|
+
{ name: "EB Garamond", weight: 600, styles: ["normal"] },
|
|
140
|
+
{ name: "EB Garamond", weight: 700, styles: ["normal"] },
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
]}
|
|
144
|
+
outputDirectory="fonts"
|
|
145
|
+
preload={[
|
|
146
|
+
{ variant: "Berkeley Mono v2 Variable" },
|
|
147
|
+
{ variant: "EB Garamond", weight: 600 },
|
|
148
|
+
{ variant: "EB Garamond", weight: 700, media: "(min-width: 641px)" },
|
|
149
|
+
]}
|
|
150
|
+
/>
|
|
124
151
|
</head>
|
|
125
152
|
<body><slot /></body>
|
|
126
153
|
</html>
|
|
127
154
|
```
|
|
128
155
|
|
|
129
|
-
|
|
156
|
+
#### Selective Preloading with Media Queries
|
|
130
157
|
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
import FontLoader from 'astro-font-loader/FontLoader.astro';
|
|
158
|
+
The `preload` prop accepts an array of entries that match variants by their CSS `font-family` name, and optionally by `weight` and `styles` for per-variant granularity. Each entry can include an optional `media` query to conditionally preload fonts based on viewport size:
|
|
134
159
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
outputDir="assets/fonts"
|
|
142
|
-
/>
|
|
160
|
+
```typescript
|
|
161
|
+
preload={[
|
|
162
|
+
{ variant: "Berkeley Mono v2 Variable" }, // always preload
|
|
163
|
+
{ variant: "EB Garamond", weight: 600 }, // always preload semibold
|
|
164
|
+
{ variant: "EB Garamond", weight: 700, media: "(min-width: 641px)" }, // bold on desktop only
|
|
165
|
+
]}
|
|
143
166
|
```
|
|
144
167
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
The `preload` prop accepts an array of configurations for fine-grained control over which fonts are preloaded and with what media queries. This is useful for responsive font loading — for example, preloading a bold weight only on desktop:
|
|
148
|
-
|
|
149
|
-
```astro
|
|
150
|
-
---
|
|
151
|
-
import FontLoader from 'astro-font-loader/FontLoader.astro';
|
|
168
|
+
Fonts matched by an entry in `preload` get a `<link rel="preload">` tag. Fonts not listed in `preload` still get their `@font-face` CSS injected — they load normally without being preloaded.
|
|
152
169
|
|
|
153
|
-
|
|
154
|
-
filename.toLowerCase().includes('roboto');
|
|
155
|
-
---
|
|
156
|
-
<FontLoader
|
|
157
|
-
packages={['@company/design-system-fonts']}
|
|
158
|
-
filter={fontFilter}
|
|
159
|
-
preload={[
|
|
160
|
-
{
|
|
161
|
-
filter: (f) => f.includes('roboto-regular'),
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
filter: (f) => f.includes('roboto-bold'),
|
|
165
|
-
media: '(min-width: 641px)',
|
|
166
|
-
},
|
|
167
|
-
]}
|
|
168
|
-
/>
|
|
169
|
-
```
|
|
170
|
+
#### Props
|
|
170
171
|
|
|
171
172
|
| Prop | Type | Default | Description |
|
|
172
173
|
|------|------|---------|-------------|
|
|
173
|
-
| `
|
|
174
|
-
| `
|
|
175
|
-
| `
|
|
176
|
-
| `preload` | `boolean \| PreloadConfig[]` | `true` | Whether/how to generate preload link tags |
|
|
174
|
+
| `fonts` | `FontConfig[]` | (required) | Font configurations to load |
|
|
175
|
+
| `outputDirectory` | `string` | (required) | Output directory name in generated URLs |
|
|
176
|
+
| `preload` | `PreloadEntry[]` | `[]` | Variants to preload, with optional weight/style narrowing |
|
|
177
177
|
| `root` | `string` | `process.cwd()` | Root directory for resolving font packages |
|
|
178
178
|
|
|
179
|
-
**`
|
|
179
|
+
**`PreloadEntry`**
|
|
180
180
|
|
|
181
181
|
| Property | Type | Required | Description |
|
|
182
182
|
|----------|------|----------|-------------|
|
|
183
|
-
| `
|
|
183
|
+
| `variant` | `string` | Yes | CSS font-family name to match for preloading |
|
|
184
|
+
| `weight` | `number \| [number, number]` | No | Narrow to a specific weight. Omit to match all weights |
|
|
185
|
+
| `styles` | `string[]` | No | Narrow to specific styles. Omit to match all styles |
|
|
184
186
|
| `media` | `string` | No | Media query for the preload link |
|
|
185
187
|
|
|
186
188
|
## Additional Documentation
|
|
@@ -1,27 +1,14 @@
|
|
|
1
1
|
---
|
|
2
|
-
import { getFontsPackageInfo,
|
|
3
|
-
|
|
4
|
-
interface PreloadConfig {
|
|
5
|
-
/** Filter function to select which fonts to preload. */
|
|
6
|
-
filter: (filename: string) => boolean;
|
|
7
|
-
/** Optional media query for the preload link (e.g., "(min-width: 641px)"). */
|
|
8
|
-
media?: string;
|
|
9
|
-
}
|
|
2
|
+
import { getFontsPackageInfo, getFontsCss } from 'astro-font-loader';
|
|
3
|
+
import type { FontConfig, PreloadEntry } from 'astro-font-loader';
|
|
10
4
|
|
|
11
5
|
interface Props {
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Controls preload link generation.
|
|
20
|
-
* - `true`: Preload all filtered fonts (default).
|
|
21
|
-
* - `false`: No preload links.
|
|
22
|
-
* - `PreloadConfig[]`: Selective preloading with optional media queries.
|
|
23
|
-
*/
|
|
24
|
-
preload?: boolean | PreloadConfig[];
|
|
6
|
+
/** Font configurations to load. */
|
|
7
|
+
fonts: FontConfig[];
|
|
8
|
+
/** Output directory name used in generated font URLs. */
|
|
9
|
+
outputDirectory: string;
|
|
10
|
+
/** Variants to preload, with optional weight/style narrowing and media queries. */
|
|
11
|
+
preload?: PreloadEntry[];
|
|
25
12
|
/** Root directory to resolve font packages from. Defaults to process.cwd(). */
|
|
26
13
|
root?: string;
|
|
27
14
|
}
|
|
@@ -39,45 +26,65 @@ function getMimeType(filename: string): string {
|
|
|
39
26
|
return MIME_TYPES[ext] ?? 'font/woff2';
|
|
40
27
|
}
|
|
41
28
|
|
|
29
|
+
function weightEquals(
|
|
30
|
+
a: number | [number, number],
|
|
31
|
+
b: number | [number, number],
|
|
32
|
+
): boolean {
|
|
33
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
34
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
35
|
+
}
|
|
36
|
+
return a === b;
|
|
37
|
+
}
|
|
38
|
+
|
|
42
39
|
const {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
preload = true,
|
|
40
|
+
fonts,
|
|
41
|
+
outputDirectory,
|
|
42
|
+
preload = [],
|
|
47
43
|
root = process.cwd(),
|
|
48
44
|
} = Astro.props;
|
|
49
45
|
|
|
50
|
-
let css = '';
|
|
51
|
-
const seen = new Set<string>();
|
|
52
46
|
const preloadHrefs: Array<{ href: string; type: string; media?: string }> = [];
|
|
47
|
+
const seenHrefs = new Set<string>();
|
|
48
|
+
let allCss = '';
|
|
53
49
|
|
|
54
|
-
for (const
|
|
55
|
-
const
|
|
50
|
+
for (const fontConfig of fonts) {
|
|
51
|
+
const { source } = fontConfig;
|
|
52
|
+
const packageInfo = getFontsPackageInfo(source.package, root, source.styleFile);
|
|
56
53
|
if (!packageInfo) continue;
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
for (const variant of fontConfig.variants) {
|
|
56
|
+
const result = getFontsCss(
|
|
57
|
+
{ name: variant.name, variants: [variant], outputDirectory },
|
|
58
|
+
packageInfo,
|
|
59
|
+
);
|
|
60
|
+
allCss += result.css;
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
fonts = fonts.filter((font) => filter(font.filename));
|
|
64
|
-
}
|
|
65
|
-
for (const font of fonts) {
|
|
66
|
-
const href = `/${outputDir}/${font.filename}`;
|
|
67
|
-
if (!seen.has(href)) {
|
|
68
|
-
seen.add(href);
|
|
69
|
-
preloadHrefs.push({ href, type: getMimeType(font.filename) });
|
|
62
|
+
const entry = preload.find((p) => {
|
|
63
|
+
if (p.variant.toLowerCase() !== variant.name.toLowerCase()) {
|
|
64
|
+
return false;
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
|
|
67
|
+
if (p.weight !== undefined && !weightEquals(p.weight, variant.weight)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (p.styles && !p.styles.every((s) => variant.styles.includes(s))) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (entry) {
|
|
79
|
+
for (const filename of result.filenames) {
|
|
80
|
+
const href = `/${outputDirectory}/${filename}`;
|
|
81
|
+
if (!seenHrefs.has(href)) {
|
|
82
|
+
seenHrefs.add(href);
|
|
83
|
+
preloadHrefs.push({
|
|
84
|
+
href,
|
|
85
|
+
type: getMimeType(filename),
|
|
86
|
+
media: entry.media,
|
|
87
|
+
});
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
}
|
|
@@ -88,4 +95,4 @@ for (const packageName of packages) {
|
|
|
88
95
|
{preloadHrefs.map(({ href, type, media }) => (
|
|
89
96
|
<link rel="preload" as="font" crossorigin href={href} type={type} media={media} />
|
|
90
97
|
))}
|
|
91
|
-
{
|
|
98
|
+
{allCss && <style set:html={allCss} is:inline />}
|
package/dist/astroBuild.d.ts
CHANGED
|
@@ -4,11 +4,6 @@ import type { FontInfo } from "./fonts/fontInfo.ts";
|
|
|
4
4
|
* Handles the build completion phase for font loading.
|
|
5
5
|
*
|
|
6
6
|
* Copies all available font files to the output directory.
|
|
7
|
-
*
|
|
8
|
-
* @param {URL} dir - The build output directory URL.
|
|
9
|
-
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
10
|
-
* @param {string} outputDir - The output directory name for font files.
|
|
11
|
-
* @param {FontInfo[]} availableFonts - Array of font files to copy.
|
|
12
7
|
*/
|
|
13
|
-
export declare function astroBuildDone(dir: URL, logger: AstroIntegrationLogger,
|
|
8
|
+
export declare function astroBuildDone(dir: URL, logger: AstroIntegrationLogger, outputDirectory: string, availableFonts: FontInfo[]): void;
|
|
14
9
|
//# sourceMappingURL=astroBuild.d.ts.map
|
package/dist/astroBuild.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astroBuild.d.ts","sourceRoot":"","sources":["../src/astroBuild.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"astroBuild.d.ts","sourceRoot":"","sources":["../src/astroBuild.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,IAAI,CAqBlI"}
|
package/dist/astroBuild.js
CHANGED
|
@@ -5,17 +5,12 @@ import { fileURLToPath } from "url";
|
|
|
5
5
|
* Handles the build completion phase for font loading.
|
|
6
6
|
*
|
|
7
7
|
* Copies all available font files to the output directory.
|
|
8
|
-
*
|
|
9
|
-
* @param {URL} dir - The build output directory URL.
|
|
10
|
-
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
11
|
-
* @param {string} outputDir - The output directory name for font files.
|
|
12
|
-
* @param {FontInfo[]} availableFonts - Array of font files to copy.
|
|
13
8
|
*/
|
|
14
|
-
export function astroBuildDone(dir, logger,
|
|
9
|
+
export function astroBuildDone(dir, logger, outputDirectory, availableFonts) {
|
|
15
10
|
if (availableFonts.length === 0) {
|
|
16
11
|
return;
|
|
17
12
|
}
|
|
18
|
-
const outputPath = fileURLToPath(new URL(
|
|
13
|
+
const outputPath = fileURLToPath(new URL(outputDirectory, dir));
|
|
19
14
|
if (!existsSync(outputPath)) {
|
|
20
15
|
mkdirSync(outputPath, { recursive: true });
|
|
21
16
|
}
|
|
@@ -29,6 +24,6 @@ export function astroBuildDone(dir, logger, outputDir, availableFonts) {
|
|
|
29
24
|
logger.error(`Failed to copy ${font.filename}: ${error}`);
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
|
-
logger.info(`Copied ${availableFonts.length} font file(s) to ${
|
|
27
|
+
logger.info(`Copied ${availableFonts.length} font file(s) to ${outputDirectory}/`);
|
|
33
28
|
}
|
|
34
29
|
//# sourceMappingURL=astroBuild.js.map
|
package/dist/astroBuild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astroBuild.js","sourceRoot":"","sources":["../src/astroBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,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C,IAAI,CAAC,UAAU,cAAc,CAAC,MAAM,oBAAoB,eAAe,GAAG,CAAC,CAAC;AACpF,CAAC"}
|
package/dist/astroConfig.d.ts
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import type { AstroIntegrationLogger } from "astro";
|
|
2
2
|
import type { FontInfo, FontsPackageInfo } from "./fonts/fontInfo.ts";
|
|
3
|
+
import type { FontConfig } from "./types.ts";
|
|
3
4
|
/**
|
|
4
5
|
* Result of the configuration setup for font loading.
|
|
5
|
-
*
|
|
6
|
-
* @property {Array<FontsPackageInfo>} fontsInfoList - List of font package information objects.
|
|
7
|
-
* @property {FontInfo[]} availableFonts - Array of available font files from all packages.
|
|
8
|
-
* @property {string} transformedCss - The combined and transformed CSS from all packages.
|
|
9
6
|
*/
|
|
10
7
|
export type ConfigSetupResult = {
|
|
11
8
|
fontsInfoList: FontsPackageInfo[];
|
|
12
9
|
availableFonts: FontInfo[];
|
|
13
|
-
transformedCss: string;
|
|
14
10
|
};
|
|
15
11
|
/**
|
|
16
12
|
* Sets up font configuration for the Astro integration.
|
|
17
13
|
*
|
|
18
|
-
* Resolves font packages, collects available fonts
|
|
19
|
-
*
|
|
20
|
-
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
21
|
-
* @param {string[]} packages - Array of font package names to load.
|
|
22
|
-
* @param {string} outputDir - The output directory for font files.
|
|
23
|
-
* @param {(filename: string) => boolean} [filter] - Optional filter function to select font files.
|
|
24
|
-
* @param {URL} [root] - Optional root directory to resolve packages from.
|
|
25
|
-
* @returns {ConfigSetupResult} The result containing font info, available fonts, and transformed CSS.
|
|
14
|
+
* Resolves font packages, collects available fonts by matching CSS metadata.
|
|
26
15
|
*/
|
|
27
|
-
export declare function astroConfigSetup(logger: AstroIntegrationLogger,
|
|
16
|
+
export declare function astroConfigSetup(logger: AstroIntegrationLogger, fonts: FontConfig[], outputDirectory: string, root?: URL): ConfigSetupResult;
|
|
28
17
|
//# sourceMappingURL=astroConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astroConfig.d.ts","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"astroConfig.d.ts","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAIpD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC,cAAc,EAAE,QAAQ,EAAE,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,KAAK,EAAE,UAAU,EAAE,EACnB,eAAe,EAAE,MAAM,EACvB,IAAI,CAAC,EAAE,GAAG,GACR,iBAAiB,CAiCnB"}
|
package/dist/astroConfig.js
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { filterCssFontFaces } from "./css/filter.js";
|
|
3
|
-
import { transformCss } from "./css/transform.js";
|
|
1
|
+
import { getFontsCss } from "./css/get.js";
|
|
4
2
|
import { getAvailableFonts } from "./fonts/available.js";
|
|
5
3
|
import { getFontsPackageInfo } from "./fonts/index.js";
|
|
6
4
|
/**
|
|
7
5
|
* Sets up font configuration for the Astro integration.
|
|
8
6
|
*
|
|
9
|
-
* Resolves font packages, collects available fonts
|
|
10
|
-
*
|
|
11
|
-
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
12
|
-
* @param {string[]} packages - Array of font package names to load.
|
|
13
|
-
* @param {string} outputDir - The output directory for font files.
|
|
14
|
-
* @param {(filename: string) => boolean} [filter] - Optional filter function to select font files.
|
|
15
|
-
* @param {URL} [root] - Optional root directory to resolve packages from.
|
|
16
|
-
* @returns {ConfigSetupResult} The result containing font info, available fonts, and transformed CSS.
|
|
7
|
+
* Resolves font packages, collects available fonts by matching CSS metadata.
|
|
17
8
|
*/
|
|
18
|
-
export function astroConfigSetup(logger,
|
|
9
|
+
export function astroConfigSetup(logger, fonts, outputDirectory, root) {
|
|
19
10
|
const fontsInfoList = [];
|
|
20
11
|
let availableFonts = [];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return { fontsInfoList: [], availableFonts, transformedCss };
|
|
12
|
+
if (!fonts || fonts.length === 0) {
|
|
13
|
+
logger.warn("No fonts specified. Fonts will not be copied.");
|
|
14
|
+
return { fontsInfoList: [], availableFonts };
|
|
25
15
|
}
|
|
26
|
-
for (const
|
|
27
|
-
const
|
|
16
|
+
for (const fontConfig of fonts) {
|
|
17
|
+
const { source } = fontConfig;
|
|
18
|
+
const fontsInfo = getFontsPackageInfo(source.package, root, source.styleFile);
|
|
28
19
|
if (!fontsInfo) {
|
|
29
|
-
logger.warn(`${
|
|
20
|
+
logger.warn(`${source.package} package not found. Skipping ${fontConfig.family}.`);
|
|
30
21
|
continue;
|
|
31
22
|
}
|
|
32
23
|
fontsInfoList.push(fontsInfo);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let rawCss = readFileSync(fontsInfo.cssPath, "utf-8");
|
|
40
|
-
rawCss = filterCssFontFaces(rawCss, filter);
|
|
41
|
-
transformedCss += transformCss(rawCss, outputDir, filter);
|
|
24
|
+
for (const variant of fontConfig.variants) {
|
|
25
|
+
const result = getFontsCss({ name: variant.name, variants: [variant], outputDirectory }, fontsInfo);
|
|
26
|
+
const allPackageFonts = getAvailableFonts(fontsInfo.fontsDir);
|
|
27
|
+
const matchedFonts = allPackageFonts.filter((f) => result.filenames.includes(f.filename));
|
|
28
|
+
availableFonts = availableFonts.concat(matchedFonts);
|
|
29
|
+
logger.info(`Loaded ${matchedFonts.length} font file(s) for ${fontConfig.family} (${variant.name}) from ${source.package}`);
|
|
42
30
|
}
|
|
43
|
-
logger.info(`Loaded ${packageFonts.length} font file(s) from ${packageName}`);
|
|
44
31
|
}
|
|
45
32
|
logger.info(`Found ${availableFonts.length} total font file(s) to copy`);
|
|
46
|
-
return { fontsInfoList, availableFonts
|
|
33
|
+
return { fontsInfoList, availableFonts };
|
|
47
34
|
}
|
|
48
35
|
//# sourceMappingURL=astroConfig.js.map
|
package/dist/astroConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astroConfig.js","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"astroConfig.js","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAWvD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAA8B,EAC9B,KAAmB,EACnB,eAAuB,EACvB,IAAU;IAEV,MAAM,aAAa,GAAuB,EAAE,CAAC;IAC7C,IAAI,cAAc,GAAe,EAAE,CAAC;IAEpC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,cAAc,EAAE,CAAC;IAC9C,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,KAAK,EAAE,CAAC;QAChC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;QAC9B,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI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ks against font variants.
|
|
4
|
+
*/
|
|
5
|
+
export type CssMatchResult = {
|
|
6
|
+
css: string;
|
|
7
|
+
filenames: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Filters @font-face blocks by matching their font-family, font-weight, and font-style
|
|
11
|
+
* against the provided variant definitions.
|
|
6
12
|
*
|
|
7
|
-
*
|
|
8
|
-
* @param {(filename: string) => boolean} [filter] - Optional filter function that receives a font filename and returns true to keep the rule, false to remove it.
|
|
9
|
-
* @returns {string} The filtered CSS string with only the allowed @font-face rules.
|
|
13
|
+
* Returns the matched CSS blocks and the font filenames they reference.
|
|
10
14
|
*/
|
|
11
|
-
export declare function
|
|
15
|
+
export declare function matchCssFontFaces(css: string, name: string, variants: FontVariant[]): CssMatchResult;
|
|
12
16
|
//# sourceMappingURL=filter.d.ts.map
|
package/dist/css/filter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAoC/C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,cAAc,CA4BpG"}
|
package/dist/css/filter.js
CHANGED
|
@@ -1,28 +1,58 @@
|
|
|
1
1
|
import { basename } from "node:path";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parses a @font-face block and extracts its metadata.
|
|
4
|
+
*/
|
|
5
|
+
function parseFontFace(block) {
|
|
6
|
+
const familyMatch = block.match(/font-family:\s*["']([^"']+)["']/);
|
|
7
|
+
const weightMatch = block.match(/font-weight:\s*(\d+(?:\s+\d+)?)/);
|
|
8
|
+
const styleMatch = block.match(/font-style:\s*(\w+)/);
|
|
9
|
+
const urlMatches = [...block.matchAll(/url\(["']?\.\/([^"')]+)["']?\)/g)];
|
|
10
|
+
const family = familyMatch?.[1] ?? "";
|
|
11
|
+
const style = styleMatch?.[1] ?? "normal";
|
|
12
|
+
let weight = 400;
|
|
13
|
+
if (weightMatch) {
|
|
14
|
+
const parts = weightMatch[1].split(/\s+/).map(Number);
|
|
15
|
+
weight = parts.length === 2 ? [parts[0], parts[1]] : parts[0];
|
|
16
|
+
}
|
|
17
|
+
const filenames = urlMatches.map((m) => basename(m[1]));
|
|
18
|
+
return { family, weight, style, filenames };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a CSS font-weight matches a variant weight.
|
|
4
22
|
*
|
|
5
|
-
*
|
|
6
|
-
|
|
23
|
+
* A single weight matches if equal. A range matches if any overlap exists.
|
|
24
|
+
*/
|
|
25
|
+
function weightMatches(cssWeight, variantWeight) {
|
|
26
|
+
const [cssMin, cssMax] = Array.isArray(cssWeight) ? cssWeight : [cssWeight, cssWeight];
|
|
27
|
+
const [varMin, varMax] = Array.isArray(variantWeight) ? variantWeight : [variantWeight, variantWeight];
|
|
28
|
+
return cssMin <= varMax && varMin <= cssMax;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Filters @font-face blocks by matching their font-family, font-weight, and font-style
|
|
32
|
+
* against the provided variant definitions.
|
|
7
33
|
*
|
|
8
|
-
*
|
|
9
|
-
* @param {(filename: string) => boolean} [filter] - Optional filter function that receives a font filename and returns true to keep the rule, false to remove it.
|
|
10
|
-
* @returns {string} The filtered CSS string with only the allowed @font-face rules.
|
|
34
|
+
* Returns the matched CSS blocks and the font filenames they reference.
|
|
11
35
|
*/
|
|
12
|
-
export function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
export function matchCssFontFaces(css, name, variants) {
|
|
37
|
+
const filenameSet = new Set();
|
|
38
|
+
const formats = new Set(variants.flatMap((v) => v.formats ?? ["woff2"]));
|
|
39
|
+
const filtered = css.replace(/@font-face\s*\{[^}]*\}/g, (block) => {
|
|
40
|
+
const parsed = parseFontFace(block);
|
|
41
|
+
if (parsed.family.toLowerCase() !== name.toLowerCase()) {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
const matches = variants.some((v) => weightMatches(parsed.weight, v.weight) && v.styles.includes(parsed.style));
|
|
45
|
+
if (!matches) {
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
for (const filename of parsed.filenames) {
|
|
49
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
50
|
+
if (formats.has(ext)) {
|
|
51
|
+
filenameSet.add(filename);
|
|
23
52
|
}
|
|
24
53
|
}
|
|
25
|
-
return
|
|
54
|
+
return block;
|
|
26
55
|
});
|
|
56
|
+
return { css: filtered, filenames: [...filenameSet] };
|
|
27
57
|
}
|
|
28
58
|
//# sourceMappingURL=filter.js.map
|
package/dist/css/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAIrC;;GAEG;AACH,SAAS,aAAa,CAAC,KAAa;IACnC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACnE,MAAM,WAAW,GA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,CAAC,EAAE,CAAC;gBACtB,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,GAAG,WAAW,CAAC,EAAE,CAAC;AACvD,CAAC"}
|
package/dist/css/get.d.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import type { FontsPackageInfo } from "../fonts/index.ts";
|
|
2
|
+
import type { FontVariant } from "../types.ts";
|
|
2
3
|
/**
|
|
3
4
|
* Options for getting CSS for @font-face
|
|
4
5
|
*/
|
|
5
6
|
export type GetFontsCssOptions = {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
7
|
+
/** The CSS font-family name to match. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Variants to match by weight and style. */
|
|
10
|
+
variants: FontVariant[];
|
|
11
|
+
/** Output directory name. */
|
|
12
|
+
outputDirectory: string;
|
|
10
13
|
};
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
* Result of CSS processing, including matched CSS and font filenames.
|
|
16
|
+
*/
|
|
17
|
+
export type GetFontsCssResult = {
|
|
18
|
+
css: string;
|
|
19
|
+
filenames: string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Loads, matches, and transforms the CSS for @font-face rules from a font package.
|
|
16
23
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
* @returns {string} The processed and minified CSS string, or an empty string if the CSS file is missing or no package info is provided.
|
|
24
|
+
* Matches @font-face blocks by font-family name, weight, and style against the provided variants.
|
|
25
|
+
* Returns the processed CSS and the list of matched font filenames.
|
|
20
26
|
*/
|
|
21
|
-
export declare function getFontsCss(options: GetFontsCssOptions
|
|
27
|
+
export declare function getFontsCss(options: GetFontsCssOptions, fontPackageInformation: FontsPackageInfo | null): GetFontsCssResult;
|
|
22
28
|
//# sourceMappingURL=get.d.ts.map
|
package/dist/css/get.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,6BAA6B;IAC7B,eAAe,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAcF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,GAAG,iBAAiB,CAU3H"}
|
package/dist/css/get.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { matchCssFontFaces } from "./filter.js";
|
|
3
3
|
import { transformCss } from "./transform.js";
|
|
4
4
|
/**
|
|
5
5
|
* Minifies a CSS string by removing comments, extra whitespace, and newlines.
|
|
6
|
-
*
|
|
7
|
-
* @param css - The CSS string to minify.
|
|
8
|
-
* @returns The minified CSS string.
|
|
9
6
|
*/
|
|
10
7
|
function minifyCss(css) {
|
|
11
8
|
return css
|
|
@@ -16,24 +13,19 @@ function minifyCss(css) {
|
|
|
16
13
|
.trim();
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
|
-
* Loads,
|
|
20
|
-
*
|
|
21
|
-
* Reads the CSS file specified in the font package information, applies an optional filter to @font-face rules,
|
|
22
|
-
* and transforms the CSS for output. Returns an empty string if no font package information is provided or the CSS file does not exist.
|
|
16
|
+
* Loads, matches, and transforms the CSS for @font-face rules from a font package.
|
|
23
17
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
-
* @returns {string} The processed and minified CSS string, or an empty string if the CSS file is missing or no package info is provided.
|
|
18
|
+
* Matches @font-face blocks by font-family name, weight, and style against the provided variants.
|
|
19
|
+
* Returns the processed CSS and the list of matched font filenames.
|
|
27
20
|
*/
|
|
28
|
-
export function getFontsCss(options
|
|
29
|
-
const {
|
|
30
|
-
if (!fontPackageInformation ||
|
|
31
|
-
|
|
32
|
-
return "";
|
|
21
|
+
export function getFontsCss(options, fontPackageInformation) {
|
|
22
|
+
const { name, variants, outputDirectory } = options;
|
|
23
|
+
if (!fontPackageInformation || !existsSync(fontPackageInformation.cssPath)) {
|
|
24
|
+
return { css: "", filenames: [] };
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const transformedCss = transformCss(
|
|
37
|
-
return minifyCss(transformedCss);
|
|
26
|
+
const rawCss = readFileSync(fontPackageInformation.cssPath, "utf-8");
|
|
27
|
+
const matched = matchCssFontFaces(rawCss, name, variants);
|
|
28
|
+
const transformedCss = transformCss(matched.css, outputDirectory);
|
|
29
|
+
return { css: minifyCss(transformedCss), filenames: matched.filenames };
|
|
38
30
|
}
|
|
39
31
|
//# sourceMappingURL=get.js.map
|
package/dist/css/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAAA,OAAO,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/css/transform.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transforms font-face URLs in a CSS string to point to a specified output directory.
|
|
3
3
|
*
|
|
4
|
-
* Replaces relative font URLs with absolute URLs based on the output directory.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} rawCss - The raw CSS string containing font-face rules.
|
|
7
|
-
* @param {string} outputDir - The output directory to use in the transformed URLs.
|
|
8
|
-
* @param {(filename: string) => boolean} [filter] - Optional filter function to determine which font files to transform.
|
|
9
|
-
* @returns {string} The CSS string with transformed font-face URLs.
|
|
4
|
+
* Replaces relative font URLs with absolute URLs based on the output directory.
|
|
10
5
|
*/
|
|
11
|
-
export declare function transformCss(rawCss: string, outputDir: string
|
|
6
|
+
export declare function transformCss(rawCss: string, outputDir: string): string;
|
|
12
7
|
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/css/transform.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/css/transform.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAKtE"}
|
package/dist/css/transform.js
CHANGED
|
@@ -2,19 +2,11 @@ import { basename } from "node:path";
|
|
|
2
2
|
/**
|
|
3
3
|
* Transforms font-face URLs in a CSS string to point to a specified output directory.
|
|
4
4
|
*
|
|
5
|
-
* Replaces relative font URLs with absolute URLs based on the output directory.
|
|
6
|
-
*
|
|
7
|
-
* @param {string} rawCss - The raw CSS string containing font-face rules.
|
|
8
|
-
* @param {string} outputDir - The output directory to use in the transformed URLs.
|
|
9
|
-
* @param {(filename: string) => boolean} [filter] - Optional filter function to determine which font files to transform.
|
|
10
|
-
* @returns {string} The CSS string with transformed font-face URLs.
|
|
5
|
+
* Replaces relative font URLs with absolute URLs based on the output directory.
|
|
11
6
|
*/
|
|
12
|
-
export function transformCss(rawCss, outputDir
|
|
13
|
-
return rawCss.replace(/url\(["']?\.\/([^"')]+)["']?\)/g, (
|
|
7
|
+
export function transformCss(rawCss, outputDir) {
|
|
8
|
+
return rawCss.replace(/url\(["']?\.\/([^"')]+)["']?\)/g, (_match, relativePath) => {
|
|
14
9
|
const filename = basename(relativePath);
|
|
15
|
-
if (filter && !filter(filename)) {
|
|
16
|
-
return match;
|
|
17
|
-
}
|
|
18
10
|
return `url("/${outputDir}/${filename}")`;
|
|
19
11
|
});
|
|
20
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/css/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/css/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,SAAiB;IAC7D,OAAO,MAAM,CAAC,OAAO,CAAC,iCAAiC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE;QACjF,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;QACxC,OAAO,SAAS,SAAS,IAAI,QAAQ,IAAI,CAAC;IAC3C,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/fonts/package.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import type { FontsPackageInfo } from "./fontInfo.ts";
|
|
|
7
7
|
*
|
|
8
8
|
* @param {string} fontsPackage - The name of the font package to resolve.
|
|
9
9
|
* @param {URL | string} [root] - Optional root directory to resolve packages from. Can be a URL or file path.
|
|
10
|
+
* @param {string} [styleFile] - Optional path to the CSS file relative to the package root. Defaults to "src/index.css".
|
|
10
11
|
* @returns {FontsPackageInfo | null} An object containing the fonts directory and CSS file path, or null if not found.
|
|
11
12
|
*/
|
|
12
|
-
export declare function getFontsPackageInfo(fontsPackage: string, root?: URL | string): FontsPackageInfo | null;
|
|
13
|
+
export declare function getFontsPackageInfo(fontsPackage: string, root?: URL | string, styleFile?: string): FontsPackageInfo | null;
|
|
13
14
|
//# sourceMappingURL=package.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/fonts/package.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD
|
|
1
|
+
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/fonts/package.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAmB1H"}
|
package/dist/fonts/package.js
CHANGED
|
@@ -9,9 +9,10 @@ import { fileURLToPath } from "node:url";
|
|
|
9
9
|
*
|
|
10
10
|
* @param {string} fontsPackage - The name of the font package to resolve.
|
|
11
11
|
* @param {URL | string} [root] - Optional root directory to resolve packages from. Can be a URL or file path.
|
|
12
|
+
* @param {string} [styleFile] - Optional path to the CSS file relative to the package root. Defaults to "src/index.css".
|
|
12
13
|
* @returns {FontsPackageInfo | null} An object containing the fonts directory and CSS file path, or null if not found.
|
|
13
14
|
*/
|
|
14
|
-
export function getFontsPackageInfo(fontsPackage, root) {
|
|
15
|
+
export function getFontsPackageInfo(fontsPackage, root, styleFile) {
|
|
15
16
|
try {
|
|
16
17
|
let requireBase;
|
|
17
18
|
if (root) {
|
|
@@ -24,7 +25,7 @@ export function getFontsPackageInfo(fontsPackage, root) {
|
|
|
24
25
|
const require = createRequire(requireBase);
|
|
25
26
|
const fontsPackagePath = require.resolve(`${fontsPackage}/package.json`);
|
|
26
27
|
const fontsDir = dirname(fontsPackagePath);
|
|
27
|
-
const cssPath = join(fontsDir, "src", "index.css");
|
|
28
|
+
const cssPath = styleFile ? join(fontsDir, styleFile) : join(fontsDir, "src", "index.css");
|
|
28
29
|
return { fontsDir, cssPath };
|
|
29
30
|
}
|
|
30
31
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/fonts/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC
|
|
1
|
+
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/fonts/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAAoB,EAAE,IAAmB,EAAE,SAAkB;IAChG,IAAI,CAAC;QACJ,IAAI,WAAmB,CAAC;QACxB,IAAI,IAAI,EAAE,CAAC;YACV,MAAM,QAAQ,GAAG,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAElE,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACP,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/B,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;QAC3C,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,YAAY,eAAe,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QAC3F,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export { fontsIntegration } from "./integration.ts";
|
|
2
|
-
export type { FontsIntegrationOptions } from "./integration.ts";
|
|
3
2
|
export { getFontsCss } from "./css/index.ts";
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export type { FontInfo, FontsPackageInfo } from "./fonts/index.ts";
|
|
7
|
-
export type { PreloadConfig } from "./components/types.ts";
|
|
3
|
+
export { getFontsPackageInfo } from "./fonts/index.ts";
|
|
4
|
+
export type { FontLoaderConfig, FontConfig, FontSource, PackageProvider, FontVariant, PreloadEntry } from "./types.ts";
|
|
8
5
|
//# 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,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,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,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/integration.d.ts
CHANGED
|
@@ -1,41 +1,9 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
|
-
|
|
3
|
-
* Options for integrating fonts into a build process.
|
|
4
|
-
*
|
|
5
|
-
* Allows specifying font packages to load, a filter function to select which font files to include,
|
|
6
|
-
* and the output directory name for copied fonts.
|
|
7
|
-
* If no filter is provided, all fonts are included. The output directory defaults to "fonts".
|
|
8
|
-
*
|
|
9
|
-
* @property {string[]} [packages] - Array of font package names to load. Required.
|
|
10
|
-
* @property {(filename: string) => boolean} [filter] - Optional filter function to select font files by filename.
|
|
11
|
-
* @property {string} [outputDir] - Optional output directory name within the build folder. Defaults to "fonts".
|
|
12
|
-
*/
|
|
13
|
-
export type FontsIntegrationOptions = {
|
|
14
|
-
/**
|
|
15
|
-
* Array of font package names to load.
|
|
16
|
-
* Each package should export fonts in a standard structure with a src/index.css file.
|
|
17
|
-
* @example ['@iveelsm/fonts', '@fontsource/roboto']
|
|
18
|
-
*/
|
|
19
|
-
packages: string[];
|
|
20
|
-
/**
|
|
21
|
-
* Filter function to select which font files to copy.
|
|
22
|
-
* Receives the font filename and should return true to include the font.
|
|
23
|
-
* If not provided, all fonts are copied.
|
|
24
|
-
*/
|
|
25
|
-
filter?: (filename: string) => boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Output directory name within the build folder.
|
|
28
|
-
* Defaults to "fonts"
|
|
29
|
-
*/
|
|
30
|
-
outputDir?: string;
|
|
31
|
-
};
|
|
2
|
+
import type { FontLoaderConfig } from "./types.ts";
|
|
32
3
|
/**
|
|
33
4
|
* Creates an Astro integration for font loading and transformation.
|
|
34
5
|
*
|
|
35
|
-
* Sets up hooks for Astro's config and build phases to process font files and CSS
|
|
36
|
-
*
|
|
37
|
-
* @param {FontsIntegrationOptions} [options={}] - Options for filtering font files and specifying the output directory.
|
|
38
|
-
* @returns {AstroIntegration} The Astro integration object for font loading.
|
|
6
|
+
* Sets up hooks for Astro's config and build phases to process font files and CSS.
|
|
39
7
|
*/
|
|
40
|
-
export declare function fontsIntegration(
|
|
8
|
+
export declare function fontsIntegration(config: FontLoaderConfig): AstroIntegration;
|
|
41
9
|
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAiB3E"}
|
package/dist/integration.js
CHANGED
|
@@ -3,23 +3,20 @@ import { astroConfigSetup } from "./astroConfig.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates an Astro integration for font loading and transformation.
|
|
5
5
|
*
|
|
6
|
-
* Sets up hooks for Astro's config and build phases to process font files and CSS
|
|
7
|
-
*
|
|
8
|
-
* @param {FontsIntegrationOptions} [options={}] - Options for filtering font files and specifying the output directory.
|
|
9
|
-
* @returns {AstroIntegration} The Astro integration object for font loading.
|
|
6
|
+
* Sets up hooks for Astro's config and build phases to process font files and CSS.
|
|
10
7
|
*/
|
|
11
|
-
export function fontsIntegration(
|
|
12
|
-
const {
|
|
8
|
+
export function fontsIntegration(config) {
|
|
9
|
+
const { fonts, outputDirectory } = config;
|
|
13
10
|
let availableFonts = [];
|
|
14
11
|
return {
|
|
15
12
|
name: "astro-font-loader",
|
|
16
13
|
hooks: {
|
|
17
|
-
"astro:config:setup": ({ config, logger }) => {
|
|
18
|
-
const result = astroConfigSetup(logger,
|
|
14
|
+
"astro:config:setup": ({ config: astroConfig, logger }) => {
|
|
15
|
+
const result = astroConfigSetup(logger, fonts, outputDirectory, astroConfig.root);
|
|
19
16
|
availableFonts = result.availableFonts;
|
|
20
17
|
},
|
|
21
18
|
"astro:build:done": ({ dir, logger }) => {
|
|
22
|
-
astroBuildDone(dir, logger,
|
|
19
|
+
astroBuildDone(dir, logger, outputDirectory, availableFonts);
|
|
23
20
|
},
|
|
24
21
|
},
|
|
25
22
|
};
|
package/dist/integration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIpD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACxD,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAE1C,IAAI,cAAc,GAAe,EAAE,CAAC;IAEpC,OAAO;QACN,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE;YACN,oBAAoB,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE;gBACzD,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;gBAClF,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;YACxC,CAAC;YACD,kBAAkB,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE;gBACvC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,CAAC,CAAC;YAC9D,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Top-level configuration for the font loader integration.
|
|
3
|
+
*/
|
|
4
|
+
export type FontLoaderConfig = {
|
|
5
|
+
outputDirectory: string;
|
|
6
|
+
fonts: FontConfig[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for a single font family.
|
|
10
|
+
*/
|
|
11
|
+
export type FontConfig = {
|
|
12
|
+
family: string;
|
|
13
|
+
source: FontSource;
|
|
14
|
+
variants: FontVariant[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Font source provider. Currently only supports package providers,
|
|
18
|
+
* but will be extended with local and network providers.
|
|
19
|
+
*/
|
|
20
|
+
export type FontSource = PackageProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves font files from an installed npm package.
|
|
23
|
+
*/
|
|
24
|
+
export type PackageProvider = {
|
|
25
|
+
type: "package";
|
|
26
|
+
package: string;
|
|
27
|
+
/** Path to the CSS file relative to the package root. Defaults to "src/index.css". */
|
|
28
|
+
styleFile?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A specific font variant to load.
|
|
32
|
+
*/
|
|
33
|
+
export type FontVariant = {
|
|
34
|
+
/** The CSS font-family name to match in @font-face rules (case-insensitive). */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Font weight as a single value or a [min, max] range for variable fonts. */
|
|
37
|
+
weight: number | [number, number];
|
|
38
|
+
/** Font styles to match, e.g. ["normal", "italic"]. */
|
|
39
|
+
styles: string[];
|
|
40
|
+
/** File formats to include. Defaults to ["woff2"]. */
|
|
41
|
+
formats?: string[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for selectively preloading a font variant.
|
|
45
|
+
*
|
|
46
|
+
* Matches against FontVariant by name, and optionally by weight and styles
|
|
47
|
+
* for per-variant granularity. Omitting weight/styles matches all variants
|
|
48
|
+
* with that name.
|
|
49
|
+
*/
|
|
50
|
+
export type PreloadEntry = {
|
|
51
|
+
/** CSS font-family name to match. */
|
|
52
|
+
variant: string;
|
|
53
|
+
/** Narrow to a specific weight. If omitted, matches all weights for this variant. */
|
|
54
|
+
weight?: number | [number, number];
|
|
55
|
+
/** Narrow to specific styles. If omitted, matches all styles for this variant. */
|
|
56
|
+
styles?: string[];
|
|
57
|
+
/** Optional media query for the preload link. */
|
|
58
|
+
media?: string;
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,uDAAuD;IACvD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IAC1B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface PreloadConfig {
|
|
2
|
-
/** Filter function to select which fonts to preload. */
|
|
3
|
-
filter: (filename: string) => boolean;
|
|
4
|
-
/** Optional media query for the preload link (e.g., "(min-width: 641px)"). */
|
|
5
|
-
media?: string;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC7B,wDAAwD;IACxD,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACtC,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":""}
|
|
File without changes
|