astro-font-loader 0.2.3 → 0.3.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.
Files changed (42) hide show
  1. package/README.md +100 -98
  2. package/components/FontLoader.astro +58 -51
  3. package/dist/astroBuild.d.ts +1 -6
  4. package/dist/astroBuild.d.ts.map +1 -1
  5. package/dist/astroBuild.js +3 -8
  6. package/dist/astroBuild.js.map +1 -1
  7. package/dist/astroConfig.d.ts +3 -14
  8. package/dist/astroConfig.d.ts.map +1 -1
  9. package/dist/astroConfig.js +17 -30
  10. package/dist/astroConfig.js.map +1 -1
  11. package/dist/css/filter.d.ts +12 -8
  12. package/dist/css/filter.d.ts.map +1 -1
  13. package/dist/css/filter.js +48 -18
  14. package/dist/css/filter.js.map +1 -1
  15. package/dist/css/get.d.ts +18 -12
  16. package/dist/css/get.d.ts.map +1 -1
  17. package/dist/css/get.js +12 -20
  18. package/dist/css/get.js.map +1 -1
  19. package/dist/css/transform.d.ts +2 -7
  20. package/dist/css/transform.d.ts.map +1 -1
  21. package/dist/css/transform.js +3 -11
  22. package/dist/css/transform.js.map +1 -1
  23. package/dist/fonts/package.d.ts +2 -1
  24. package/dist/fonts/package.d.ts.map +1 -1
  25. package/dist/fonts/package.js +3 -2
  26. package/dist/fonts/package.js.map +1 -1
  27. package/dist/index.d.ts +2 -5
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/integration.d.ts +3 -35
  32. package/dist/integration.d.ts.map +1 -1
  33. package/dist/integration.js +6 -9
  34. package/dist/integration.js.map +1 -1
  35. package/dist/types.d.ts +60 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js.map +1 -0
  38. package/package.json +6 -2
  39. package/dist/components/types.d.ts +0 -7
  40. package/dist/components/types.d.ts.map +0 -1
  41. package/dist/components/types.js.map +0 -1
  42. /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
- - Applies the filter function (if provided) to select fonts
26
- - Prepares the list of fonts to be copied
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 filtered font files to the output directory
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
- packages: ["@company/design-system-fonts"],
73
- filter: fontFilter,
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
- ### Custom Output Directory
69
+ ### Multiple Font Families
80
70
 
81
- By default, fonts are copied to a `fonts` directory in your build output. You can customize this:
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
- packages: ["@company/design-system-fonts"],
86
- filter: fontFilter,
87
- outputDir: "assets/fonts", // Custom output directory
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
- ### Multiple Font Packages
96
+ ### Custom Style File
92
97
 
93
- You can load fonts from multiple packages:
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
- 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");
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 library provides a `FontLoader` Astro component that generates `<link rel="preload">` tags and inline `@font-face` CSS for your fonts. Use it alongside the integration — the integration copies font files to the build output, while the component injects the HTML needed to load them.
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 packages={['@company/design-system-fonts']} />
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
- The component accepts the same `filter` and `outputDir` options as the integration:
156
+ #### Selective Preloading with Media Queries
130
157
 
131
- ```astro
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
- const fontFilter = (filename: string) =>
136
- filename.toLowerCase().includes('roboto');
137
- ---
138
- <FontLoader
139
- packages={['@company/design-system-fonts']}
140
- filter={fontFilter}
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
- #### Selective Preloading with Media Queries
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
- const fontFilter = (filename: string) =>
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
- | `packages` | `string[]` | (required) | Font package names to load |
174
- | `filter` | `(filename: string) => boolean` | `undefined` | Filter function to select font files |
175
- | `outputDir` | `string` | `"fonts"` | Output directory name in generated URLs |
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
- **`PreloadConfig`**
179
+ **`PreloadEntry`**
180
180
 
181
181
  | Property | Type | Required | Description |
182
182
  |----------|------|----------|-------------|
183
- | `filter` | `(filename: string) => boolean` | Yes | Filter to select which fonts to preload |
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, getAvailableFonts, getFontsCss } from 'astro-font-loader';
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
- /** Array of font package names to load. */
13
- packages: string[];
14
- /** Optional filter function to select which font files to include in CSS. */
15
- filter?: (filename: string) => boolean;
16
- /** Output directory name used in generated font URLs. Defaults to "fonts". */
17
- outputDir?: string;
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
- packages,
44
- filter,
45
- outputDir = 'fonts',
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 packageName of packages) {
55
- const packageInfo = getFontsPackageInfo(packageName, root);
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
- css += getFontsCss({ filter, outputDir }, packageInfo);
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
- if (preload === true) {
61
- let fonts = getAvailableFonts(packageInfo.fontsDir);
62
- if (filter) {
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
- } else if (Array.isArray(preload)) {
73
- const fonts = getAvailableFonts(packageInfo.fontsDir);
74
- for (const config of preload) {
75
- const matched = fonts.filter((font) => config.filter(font.filename));
76
- for (const font of matched) {
77
- const href = `/${outputDir}/${font.filename}`;
78
- if (!seen.has(href)) {
79
- seen.add(href);
80
- preloadHrefs.push({ href, type: getMimeType(font.filename), media: config.media });
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
- {css && <style set:html={css} is:inline />}
98
+ {allCss && <style set:html={allCss} is:inline />}
@@ -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, outputDir: string, availableFonts: FontInfo[]): void;
8
+ export declare function astroBuildDone(dir: URL, logger: AstroIntegrationLogger, outputDirectory: string, availableFonts: FontInfo[]): void;
14
9
  //# sourceMappingURL=astroBuild.d.ts.map
@@ -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;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,sBAAsB,EAC9B,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,QAAQ,EAAE,GACxB,IAAI,CAuBN"}
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"}
@@ -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, outputDir, availableFonts) {
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(outputDir, dir));
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 ${outputDir}/`);
27
+ logger.info(`Copied ${availableFonts.length} font file(s) to ${outputDirectory}/`);
33
28
  }
34
29
  //# sourceMappingURL=astroBuild.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astroBuild.js","sourceRoot":"","sources":["../src/astroBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAMpC;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC7B,GAAQ,EACR,MAA8B,EAC9B,SAAiB,EACjB,cAA0B;IAE1B,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACR,CAAC;IAED,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;QACnC,MAAM,QAAQ,G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C;QACjD,IAAI,CAAC;YACJ,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,UAAU,cAAc,CAAC,MAAM,oBAAoB,eAAe,GAAG,CAAC,CAAC;AACpF,CAAC"}
@@ -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, applies optional filtering, and transforms CSS.
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, packages: string[], outputDir: string, filter?: (filename: string) => boolean, root?: URL): ConfigSetupResult;
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":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAKpD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGtE;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC,cAAc,EAAE,QAAQ,EAAE,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,EACtC,IAAI,CAAC,EAAE,GAAG,GACR,iBAAiB,CAsCnB"}
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"}
@@ -1,48 +1,35 @@
1
- import { existsSync, readFileSync } from "node:fs";
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, applies optional filtering, and transforms CSS.
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, packages, outputDir, filter, root) {
9
+ export function astroConfigSetup(logger, fonts, outputDirectory, root) {
19
10
  const fontsInfoList = [];
20
11
  let availableFonts = [];
21
- let transformedCss = "";
22
- if (!packages || packages.length === 0) {
23
- logger.warn("No font packages specified. Fonts will not be copied.");
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 packageName of packages) {
27
- const fontsInfo = getFontsPackageInfo(packageName, root);
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(`${packageName} package not found. Skipping.`);
20
+ logger.warn(`${source.package} package not found. Skipping ${fontConfig.family}.`);
30
21
  continue;
31
22
  }
32
23
  fontsInfoList.push(fontsInfo);
33
- let packageFonts = getAvailableFonts(fontsInfo.fontsDir);
34
- if (filter) {
35
- packageFonts = packageFonts.filter((font) => filter(font.filename));
36
- }
37
- availableFonts = availableFonts.concat(packageFonts);
38
- if (existsSync(fontsInfo.cssPath)) {
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, transformedCss };
33
+ return { fontsInfoList, availableFonts };
47
34
  }
48
35
  //# sourceMappingURL=astroConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astroConfig.js","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAevD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAA8B,EAC9B,QAAkB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,CAAC,CAAC;QAE9B,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,EAAE,SAAS,CAAC,CAAC;YAEpG,MAAM,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAC9D,MAAM,YAAY,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC1F,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAErD,MAAM,CAAC,IAAI,CAAC,UAAU,YAAY,CAAC,MAAM,qBAAqB,UAAU,CAAC,MAAM,KAAK,OAAO,CAAC,IAAI,UAAU,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7H,CAAC;IACF,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,SAAS,cAAc,CAAC,MAAM,6BAA6B,CAAC,CAAC;IAEzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AAC1C,CAAC"}
@@ -1,12 +1,16 @@
1
+ import type { FontVariant } from "../types.ts";
1
2
  /**
2
- * Filters @font-face rules in a CSS string based on a filename filter function.
3
- *
4
- * Iterates over all @font-face blocks and removes those for which the filter function returns false
5
- * for any font file referenced in the block. If no filter is provided, returns the original CSS.
3
+ * Result of matching @font-face blocks 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
- * @param {string} css - The CSS string containing @font-face rules.
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 filterCssFontFaces(css: string, filter?: (filename: string) => boolean): string;
15
+ export declare function matchCssFontFaces(css: string, name: string, variants: FontVariant[]): CssMatchResult;
12
16
  //# sourceMappingURL=filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GACpC,MAAM,CAgBR"}
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"}
@@ -1,28 +1,58 @@
1
1
  import { basename } from "node:path";
2
2
  /**
3
- * Filters @font-face rules in a CSS string based on a filename filter function.
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
- * Iterates over all @font-face blocks and removes those for which the filter function returns false
6
- * for any font file referenced in the block. If no filter is provided, returns the original CSS.
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
- * @param {string} css - The CSS string containing @font-face rules.
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 filterCssFontFaces(css, filter) {
13
- if (!filter) {
14
- return css;
15
- }
16
- return css.replace(/@font-face\s*\{[^}]*\}/g, (match) => {
17
- const urlMatches = match.matchAll(/url\(["']?\.\/([^"')]+)["']?\)/g);
18
- for (const urlMatch of urlMatches) {
19
- const relativePath = urlMatch[1];
20
- const filename = basename(relativePath);
21
- if (filter(filename)) {
22
- return match;
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
@@ -1 +1 @@
1
- {"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAW,EACX,MAAsC;IAEtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC,KAAK,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC;QACrE,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,YAAY,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;YACxC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACtB,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC,CAAC,CAAC;AACJ,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,KAA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,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;YAC3D,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,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
- /** Optional filter function to select font files by filename. */
7
- filter?: (filename: string) => boolean;
8
- /** Optional output directory name. Defaults to "fonts". */
9
- outputDir?: string;
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
- * Loads, filters, and transforms the CSS for font-face rules from a font package.
13
- *
14
- * Reads the CSS file specified in the font package information, applies an optional filter to @font-face rules,
15
- * and transforms the CSS for output. Returns an empty string if no font package information is provided or the CSS file does not exist.
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
- * @param {GetFontsCssOptions} [options={}] - Options including filter and output directory.
18
- * @param {FontsPackageInfo | null} fontPackageInformation - Information about the font package, including the CSS file path.
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 | undefined, fontPackageInformation: FontsPackageInfo | null): string;
27
+ export declare function getFontsCss(options: GetFontsCssOptions, fontPackageInformation: FontsPackageInfo | null): GetFontsCssResult;
22
28
  //# sourceMappingURL=get.d.ts.map
@@ -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;AAI1D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,iEAAiE;IACjE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACvC,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAiBF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAC1B,OAAO,EAAE,kBAAkB,YAAK,EAChC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,GAC7C,MAAM,CAaR"}
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 { filterCssFontFaces } from "./filter.js";
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, filters, and transforms the CSS for font-face rules from a font package.
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
- * @param {GetFontsCssOptions} [options={}] - Options including filter and output directory.
25
- * @param {FontsPackageInfo | null} fontPackageInformation - Information about the font package, including the CSS file path.
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 = {}, fontPackageInformation) {
29
- const { filter, outputDir = "fonts" } = options;
30
- if (!fontPackageInformation ||
31
- !existsSync(fontPackageInformation.cssPath)) {
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
- let rawCss = readFileSync(fontPackageInformation.cssPath, "utf-8");
35
- rawCss = filterCssFontFaces(rawCss, filter);
36
- const transformedCss = transformCss(rawCss, outputDir, filter);
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
@@ -1 +1 @@
1
- {"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAY9C;;;;;GAKG;AACH,SAAS,SAAS,CAAC,GAAW;IAC7B,OAAO,GAAG;SACR,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC;SACjC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,IAAI,EAAE,CAAC;AACV,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAC1B,UAA8B,EAAE,EAChC,sBAA+C;IAE/C,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IAChD,IACC,CAAC,sBAAsB;QACvB,CAAC,UAAU,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAC1C,CAAC;QACF,OAAO,EAAE,CAAC;IACX,CAAC;IAED,IAAI,MAAM,GAAG,YAAY,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACnE,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC/D,OAAO,SAAS,CAAC,cAAc,CAAC,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAsB9C;;GAEG;AACH,SAAS,SAAS,CAAC,GAAW;IAC7B,OAAO,GAAG;SACR,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC;SACjC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,IAAI,EAAE,CAAC;AACV,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B,EAAE,sBAA+C;IACvG,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACpD,IAAI,CAAC,sBAAsB,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5E,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1D,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAClE,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;AACzE,CAAC"}
@@ -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. Optionally filters font files by filename.
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, filter?: (filename: string) => boolean): 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;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GACpC,MAAM,CAWR"}
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"}
@@ -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. Optionally filters font files by filename.
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, filter) {
13
- return rawCss.replace(/url\(["']?\.\/([^"')]+)["']?\)/g, (match, relativePath) => {
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;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC3B,MAAc,EACd,SAAiB,EACjB,MAAsC;IAEtC,OAAO,MAAM,CAAC,OAAO,CACpB,iCAAiC,EACjC,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QACvB,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;QACxC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,SAAS,SAAS,IAAI,QAAQ,IAAI,CAAC;IAC3C,CAAC,CACD,CAAC;AACH,CAAC"}
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"}
@@ -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;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAClC,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM,GACjB,gBAAgB,GAAG,IAAI,CAqBzB"}
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"}
@@ -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;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAClC,YAAoB,EACpB,IAAmB;IAEnB,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,CACvC,GAAG,YAAY,eAAe,CAC9B,CAAC;QACF,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,I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E,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 type { GetFontsCssOptions } from "./css/get.ts";
5
- export { getFontsPackageInfo, getAvailableFonts } from "./fonts/index.ts";
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
@@ -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,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;AAEnE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
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
@@ -1,4 +1,4 @@
1
1
  export { fontsIntegration } from "./integration.js";
2
2
  export { getFontsCss } from "./css/index.js";
3
- export { getFontsPackageInfo, getAvailableFonts } from "./fonts/index.js";
3
+ export { getFontsPackageInfo } from "./fonts/index.js";
4
4
  //# sourceMappingURL=index.js.map
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;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,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"}
@@ -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, using provided options for filtering and output directory.
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(options: FontsIntegrationOptions): AstroIntegration;
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;AAM9C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACrC;;;;OAIG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACvC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,uBAAuB,GAC9B,gBAAgB,CAuBlB"}
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"}
@@ -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, using provided options for filtering and output directory.
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(options) {
12
- const { packages, filter, outputDir = "fonts" } = options;
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, packages, outputDir, filter, config.root);
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, outputDir, availableFonts);
19
+ astroBuildDone(dir, logger, outputDirectory, availableFonts);
23
20
  },
24
21
  },
25
22
  };
@@ -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;AAkCpD;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC/B,OAAgC;IAEhC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IAE1D,IAAI,cAAc,GAAe,EAAE,CAAC;IAEpC,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,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
@@ -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,10 +1,10 @@
1
1
  {
2
2
  "name": "astro-font-loader",
3
- "description": "Loads fonts into astro build artifacts from custom fonts packages",
3
+ "description": "Astro integration for loading fonts into build artifacts with configurable output paths and media query-based conditional preloading.",
4
4
  "author": "Mikey Sleevi <development@frogman.simplelogin.com>",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.2.3",
7
+ "version": "0.3.2",
8
8
  "engines": {
9
9
  "node": ">=18.0.0"
10
10
  },
@@ -28,7 +28,11 @@
28
28
  "astro-component",
29
29
  "astro-loader",
30
30
  "astro",
31
+ "font",
31
32
  "fonts",
33
+ "optimization",
34
+ "perf",
35
+ "performance",
32
36
  "plugin"
33
37
  ],
34
38
  "homepage": "https://github.com/iveelsm/astro-font-loader#readme",
@@ -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