fontaine 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,151 +1,118 @@
1
+ import { i as resolveCategoryFallbacks, n as FontCategory, r as ResolveCategoryFallbacksOptions, t as DEFAULT_CATEGORY_FALLBACKS } from "./fallbacks-Cj4LUWhi.cjs";
1
2
  import { Font } from "@capsizecss/unpack";
3
+ import "css-tree";
2
4
  import { createUnplugin } from "unplugin";
3
-
4
5
  //#region src/css.d.ts
5
-
6
6
  /**
7
- * Generates a fallback name based on the first font family specified in the input string.
8
- * @param {string} name - The full font family string.
9
- * @returns {string} - The fallback font name.
10
- */
7
+ * Generates a fallback name based on the first font family specified in the input string.
8
+ * @param {string} name - The full font family string.
9
+ * @returns {string} - The fallback font name.
10
+ */
11
11
  declare function generateFallbackName(name: string): string;
12
12
  interface FallbackOptions {
13
13
  /**
14
- * The name of the fallback font.
15
- */
14
+ * The name of the fallback font.
15
+ */
16
16
  name: string;
17
17
  /**
18
- * The fallback font family name.
19
- */
18
+ * The fallback font family name.
19
+ */
20
20
  font: string;
21
21
  /**
22
- * Metrics for fallback face calculations.
23
- * @optional
24
- */
22
+ * Metrics for fallback face calculations.
23
+ * @optional
24
+ */
25
25
  metrics?: FontFaceMetrics;
26
26
  /**
27
- * Additional properties that may be included dynamically
28
- */
27
+ * Additional properties that may be included dynamically
28
+ */
29
29
  [key: string]: any;
30
30
  }
31
31
  type FontFaceMetrics = Pick<Font, "ascent" | "descent" | "lineGap" | "unitsPerEm" | "xWidthAvg"> & {
32
32
  category?: string;
33
33
  };
34
34
  /**
35
- * Generates a CSS `@font-face' declaration for a font, taking fallback and resizing into account.
36
- * @param {FontFaceMetrics} metrics - The metrics of the preferred font. See {@link FontFaceMetrics}.
37
- * @param {FallbackOptions} fallback - The fallback options, including name, font and optional metrics. See {@link FallbackOptions}.
38
- * @returns {string} - The full `@font-face` CSS declaration.
39
- */
35
+ * Generates a CSS `@font-face' declaration for a font, taking fallback and resizing into account.
36
+ * @param {FontFaceMetrics} metrics - The metrics of the preferred font. See {@link FontFaceMetrics}.
37
+ * @param {FallbackOptions} fallback - The fallback options, including name, font and optional metrics. See {@link FallbackOptions}.
38
+ * @returns {string} - The full `@font-face` CSS declaration.
39
+ */
40
40
  declare function generateFontFace(metrics: FontFaceMetrics, fallback: FallbackOptions): string;
41
41
  //#endregion
42
- //#region src/fallbacks.d.ts
43
- type FontCategory = "sans-serif" | "serif" | "monospace" | "display" | "handwriting" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong";
44
- /**
45
- * Default fallback font stacks for each font category.
46
- * These are system fonts that work across different platforms.
47
- */
48
- declare const DEFAULT_CATEGORY_FALLBACKS: Partial<Record<FontCategory, string[]>>;
49
- interface ResolveCategoryFallbacksOptions {
50
- /** Font family name to resolve fallbacks for */
51
- fontFamily: string;
52
- /** Global fallbacks (array) or per-family fallbacks (object). Array overrides all category-based resolution. */
53
- fallbacks: string[] | Record<string, string[]>;
54
- /** Font metrics containing category information */
55
- metrics?: {
56
- category?: string;
57
- } | null;
58
- /** User-provided category fallback overrides */
59
- categoryFallbacks?: Partial<Record<FontCategory, string[]>>;
60
- }
61
- /**
62
- * Resolves the appropriate fallback fonts for a given font family.
63
- *
64
- * Resolution order:
65
- * 1. If fallbacks is an array, use it as a global override
66
- * 2. If fallbacks is an object with the font family key, use that override
67
- * 3. If metrics contain a category, use the category-based fallbacks
68
- * 4. Default to sans-serif category fallbacks
69
- *
70
- * @param options - Configuration for fallback resolution
71
- * @returns Array of fallback font family names
72
- */
73
- declare function resolveCategoryFallbacks(options: ResolveCategoryFallbacksOptions): string[];
74
- //#endregion
75
42
  //#region src/metrics.d.ts
76
43
  /**
77
- * Retrieves the font metrics for a given font family from the metrics collection. Uses caching to avoid redundant calculations.
78
- * @param {string} family - The name of the font family for which metrics are requested.
79
- * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves with the filtered font metrics or null if not found. See {@link FontFaceMetrics}.
80
- * @async
81
- */
44
+ * Retrieves the font metrics for a given font family from the metrics collection. Uses caching to avoid redundant calculations.
45
+ * @param {string} family - The name of the font family for which metrics are requested.
46
+ * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves with the filtered font metrics or null if not found. See {@link FontFaceMetrics}.
47
+ * @async
48
+ */
82
49
  declare function getMetricsForFamily(family: string): Promise<FontFaceMetrics | null>;
83
50
  /**
84
- * Reads font metrics from a specified source URL or file path. This function supports both local files and remote URLs.
85
- * It caches the results to optimise subsequent requests for the same source.
86
- * @param {URL | string} _source - The source URL or local file path from which to read the font metrics.
87
- * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves to the filtered font metrics or null if the source cannot be processed.
88
- * @async
89
- */
51
+ * Reads font metrics from a specified source URL or file path. This function supports both local files and remote URLs.
52
+ * It caches the results to optimise subsequent requests for the same source.
53
+ * @param {URL | string} _source - The source URL or local file path from which to read the font metrics.
54
+ * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves to the filtered font metrics or null if the source cannot be processed.
55
+ * @async
56
+ */
90
57
  declare function readMetrics(_source: URL | string): Promise<FontFaceMetrics | null>;
91
58
  //#endregion
92
59
  //#region src/transform.d.ts
93
60
  interface FontaineTransformOptions {
94
61
  /**
95
- * Configuration options for the CSS transformation.
96
- * @optional
97
- */
62
+ * Configuration options for the CSS transformation.
63
+ * @optional
64
+ */
98
65
  css?: {
99
66
  /**
100
- * Holds the current value of the CSS being transformed.
101
- * @optional
102
- */
67
+ * Holds the current value of the CSS being transformed.
68
+ * @optional
69
+ */
103
70
  value?: string;
104
71
  };
105
72
  /**
106
- * Font family fallbacks to use.
107
- * Can be an array of fallback font family names to use for all fonts,
108
- * or an object where keys are font family names and values are arrays of fallback font families.
109
- */
73
+ * Font family fallbacks to use.
74
+ * Can be an array of fallback font family names to use for all fonts,
75
+ * or an object where keys are font family names and values are arrays of fallback font families.
76
+ */
110
77
  fallbacks: string[] | Record<string, string[]>;
111
78
  /**
112
- * Category-specific fallback font stacks.
113
- * When a font's category is detected (serif, sans-serif, monospace, etc.),
114
- * these fallbacks will be used if no explicit per-family override is provided.
115
- * @optional
116
- */
79
+ * Category-specific fallback font stacks.
80
+ * When a font's category is detected (serif, sans-serif, monospace, etc.),
81
+ * these fallbacks will be used if no explicit per-family override is provided.
82
+ * @optional
83
+ */
117
84
  categoryFallbacks?: Partial<Record<FontCategory, string[]>>;
118
85
  /**
119
- * Function to resolve a given path to a valid URL or local path.
120
- * This is typically used to resolve font file paths.
121
- * @optional
122
- */
86
+ * Function to resolve a given path to a valid URL or local path.
87
+ * This is typically used to resolve font file paths.
88
+ * @optional
89
+ */
123
90
  resolvePath?: (path: string) => string | URL;
124
91
  /**
125
- * A function to determine whether to skip font face generation for a given fallback name.
126
- * @optional
127
- */
92
+ * A function to determine whether to skip font face generation for a given fallback name.
93
+ * @optional
94
+ */
128
95
  skipFontFaceGeneration?: (fallbackName: string) => boolean;
129
96
  /**
130
- * Function to generate an unquoted font family name to use as a fallback.
131
- * This should return a valid CSS font family name and should not include quotes.
132
- * @optional
133
- */
97
+ * Function to generate an unquoted font family name to use as a fallback.
98
+ * This should return a valid CSS font family name and should not include quotes.
99
+ * @optional
100
+ */
134
101
  fallbackName?: (name: string) => string;
135
102
  /** @deprecated use fallbackName */
136
103
  overrideName?: (name: string) => string;
137
104
  /**
138
- * Specifies whether to create a source map for the transformation.
139
- * @optional
140
- */
105
+ * Specifies whether to create a source map for the transformation.
106
+ * @optional
107
+ */
141
108
  sourcemap?: boolean;
142
109
  }
143
110
  /**
144
- * Transforms CSS files to include font fallbacks.
145
- *
146
- * @param options - The transformation options. See {@link FontaineTransformOptions}.
147
- * @returns The unplugin instance.
148
- */
111
+ * Transforms CSS files to include font fallbacks.
112
+ *
113
+ * @param options - The transformation options. See {@link FontaineTransformOptions}.
114
+ * @returns The unplugin instance.
115
+ */
149
116
  declare const FontaineTransform: ReturnType<typeof createUnplugin<FontaineTransformOptions>>;
150
117
  //#endregion
151
118
  export { DEFAULT_CATEGORY_FALLBACKS, type FontCategory, FontaineTransform, type FontaineTransformOptions, type ResolveCategoryFallbacksOptions, generateFallbackName, generateFontFace, getMetricsForFamily, readMetrics, resolveCategoryFallbacks };
package/dist/index.d.mts CHANGED
@@ -1,152 +1,118 @@
1
+ import { i as resolveCategoryFallbacks, n as FontCategory, r as ResolveCategoryFallbacksOptions, t as DEFAULT_CATEGORY_FALLBACKS } from "./fallbacks-Cj4LUWhi.mjs";
1
2
  import "css-tree";
2
3
  import { Font } from "@capsizecss/unpack";
3
4
  import { createUnplugin } from "unplugin";
4
-
5
5
  //#region src/css.d.ts
6
-
7
6
  /**
8
- * Generates a fallback name based on the first font family specified in the input string.
9
- * @param {string} name - The full font family string.
10
- * @returns {string} - The fallback font name.
11
- */
7
+ * Generates a fallback name based on the first font family specified in the input string.
8
+ * @param {string} name - The full font family string.
9
+ * @returns {string} - The fallback font name.
10
+ */
12
11
  declare function generateFallbackName(name: string): string;
13
12
  interface FallbackOptions {
14
13
  /**
15
- * The name of the fallback font.
16
- */
14
+ * The name of the fallback font.
15
+ */
17
16
  name: string;
18
17
  /**
19
- * The fallback font family name.
20
- */
18
+ * The fallback font family name.
19
+ */
21
20
  font: string;
22
21
  /**
23
- * Metrics for fallback face calculations.
24
- * @optional
25
- */
22
+ * Metrics for fallback face calculations.
23
+ * @optional
24
+ */
26
25
  metrics?: FontFaceMetrics;
27
26
  /**
28
- * Additional properties that may be included dynamically
29
- */
27
+ * Additional properties that may be included dynamically
28
+ */
30
29
  [key: string]: any;
31
30
  }
32
31
  type FontFaceMetrics = Pick<Font, "ascent" | "descent" | "lineGap" | "unitsPerEm" | "xWidthAvg"> & {
33
32
  category?: string;
34
33
  };
35
34
  /**
36
- * Generates a CSS `@font-face' declaration for a font, taking fallback and resizing into account.
37
- * @param {FontFaceMetrics} metrics - The metrics of the preferred font. See {@link FontFaceMetrics}.
38
- * @param {FallbackOptions} fallback - The fallback options, including name, font and optional metrics. See {@link FallbackOptions}.
39
- * @returns {string} - The full `@font-face` CSS declaration.
40
- */
35
+ * Generates a CSS `@font-face' declaration for a font, taking fallback and resizing into account.
36
+ * @param {FontFaceMetrics} metrics - The metrics of the preferred font. See {@link FontFaceMetrics}.
37
+ * @param {FallbackOptions} fallback - The fallback options, including name, font and optional metrics. See {@link FallbackOptions}.
38
+ * @returns {string} - The full `@font-face` CSS declaration.
39
+ */
41
40
  declare function generateFontFace(metrics: FontFaceMetrics, fallback: FallbackOptions): string;
42
41
  //#endregion
43
- //#region src/fallbacks.d.ts
44
- type FontCategory = "sans-serif" | "serif" | "monospace" | "display" | "handwriting" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong";
45
- /**
46
- * Default fallback font stacks for each font category.
47
- * These are system fonts that work across different platforms.
48
- */
49
- declare const DEFAULT_CATEGORY_FALLBACKS: Partial<Record<FontCategory, string[]>>;
50
- interface ResolveCategoryFallbacksOptions {
51
- /** Font family name to resolve fallbacks for */
52
- fontFamily: string;
53
- /** Global fallbacks (array) or per-family fallbacks (object). Array overrides all category-based resolution. */
54
- fallbacks: string[] | Record<string, string[]>;
55
- /** Font metrics containing category information */
56
- metrics?: {
57
- category?: string;
58
- } | null;
59
- /** User-provided category fallback overrides */
60
- categoryFallbacks?: Partial<Record<FontCategory, string[]>>;
61
- }
62
- /**
63
- * Resolves the appropriate fallback fonts for a given font family.
64
- *
65
- * Resolution order:
66
- * 1. If fallbacks is an array, use it as a global override
67
- * 2. If fallbacks is an object with the font family key, use that override
68
- * 3. If metrics contain a category, use the category-based fallbacks
69
- * 4. Default to sans-serif category fallbacks
70
- *
71
- * @param options - Configuration for fallback resolution
72
- * @returns Array of fallback font family names
73
- */
74
- declare function resolveCategoryFallbacks(options: ResolveCategoryFallbacksOptions): string[];
75
- //#endregion
76
42
  //#region src/metrics.d.ts
77
43
  /**
78
- * Retrieves the font metrics for a given font family from the metrics collection. Uses caching to avoid redundant calculations.
79
- * @param {string} family - The name of the font family for which metrics are requested.
80
- * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves with the filtered font metrics or null if not found. See {@link FontFaceMetrics}.
81
- * @async
82
- */
44
+ * Retrieves the font metrics for a given font family from the metrics collection. Uses caching to avoid redundant calculations.
45
+ * @param {string} family - The name of the font family for which metrics are requested.
46
+ * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves with the filtered font metrics or null if not found. See {@link FontFaceMetrics}.
47
+ * @async
48
+ */
83
49
  declare function getMetricsForFamily(family: string): Promise<FontFaceMetrics | null>;
84
50
  /**
85
- * Reads font metrics from a specified source URL or file path. This function supports both local files and remote URLs.
86
- * It caches the results to optimise subsequent requests for the same source.
87
- * @param {URL | string} _source - The source URL or local file path from which to read the font metrics.
88
- * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves to the filtered font metrics or null if the source cannot be processed.
89
- * @async
90
- */
51
+ * Reads font metrics from a specified source URL or file path. This function supports both local files and remote URLs.
52
+ * It caches the results to optimise subsequent requests for the same source.
53
+ * @param {URL | string} _source - The source URL or local file path from which to read the font metrics.
54
+ * @returns {Promise<FontFaceMetrics | null>} - A promise that resolves to the filtered font metrics or null if the source cannot be processed.
55
+ * @async
56
+ */
91
57
  declare function readMetrics(_source: URL | string): Promise<FontFaceMetrics | null>;
92
58
  //#endregion
93
59
  //#region src/transform.d.ts
94
60
  interface FontaineTransformOptions {
95
61
  /**
96
- * Configuration options for the CSS transformation.
97
- * @optional
98
- */
62
+ * Configuration options for the CSS transformation.
63
+ * @optional
64
+ */
99
65
  css?: {
100
66
  /**
101
- * Holds the current value of the CSS being transformed.
102
- * @optional
103
- */
67
+ * Holds the current value of the CSS being transformed.
68
+ * @optional
69
+ */
104
70
  value?: string;
105
71
  };
106
72
  /**
107
- * Font family fallbacks to use.
108
- * Can be an array of fallback font family names to use for all fonts,
109
- * or an object where keys are font family names and values are arrays of fallback font families.
110
- */
73
+ * Font family fallbacks to use.
74
+ * Can be an array of fallback font family names to use for all fonts,
75
+ * or an object where keys are font family names and values are arrays of fallback font families.
76
+ */
111
77
  fallbacks: string[] | Record<string, string[]>;
112
78
  /**
113
- * Category-specific fallback font stacks.
114
- * When a font's category is detected (serif, sans-serif, monospace, etc.),
115
- * these fallbacks will be used if no explicit per-family override is provided.
116
- * @optional
117
- */
79
+ * Category-specific fallback font stacks.
80
+ * When a font's category is detected (serif, sans-serif, monospace, etc.),
81
+ * these fallbacks will be used if no explicit per-family override is provided.
82
+ * @optional
83
+ */
118
84
  categoryFallbacks?: Partial<Record<FontCategory, string[]>>;
119
85
  /**
120
- * Function to resolve a given path to a valid URL or local path.
121
- * This is typically used to resolve font file paths.
122
- * @optional
123
- */
86
+ * Function to resolve a given path to a valid URL or local path.
87
+ * This is typically used to resolve font file paths.
88
+ * @optional
89
+ */
124
90
  resolvePath?: (path: string) => string | URL;
125
91
  /**
126
- * A function to determine whether to skip font face generation for a given fallback name.
127
- * @optional
128
- */
92
+ * A function to determine whether to skip font face generation for a given fallback name.
93
+ * @optional
94
+ */
129
95
  skipFontFaceGeneration?: (fallbackName: string) => boolean;
130
96
  /**
131
- * Function to generate an unquoted font family name to use as a fallback.
132
- * This should return a valid CSS font family name and should not include quotes.
133
- * @optional
134
- */
97
+ * Function to generate an unquoted font family name to use as a fallback.
98
+ * This should return a valid CSS font family name and should not include quotes.
99
+ * @optional
100
+ */
135
101
  fallbackName?: (name: string) => string;
136
102
  /** @deprecated use fallbackName */
137
103
  overrideName?: (name: string) => string;
138
104
  /**
139
- * Specifies whether to create a source map for the transformation.
140
- * @optional
141
- */
105
+ * Specifies whether to create a source map for the transformation.
106
+ * @optional
107
+ */
142
108
  sourcemap?: boolean;
143
109
  }
144
110
  /**
145
- * Transforms CSS files to include font fallbacks.
146
- *
147
- * @param options - The transformation options. See {@link FontaineTransformOptions}.
148
- * @returns The unplugin instance.
149
- */
111
+ * Transforms CSS files to include font fallbacks.
112
+ *
113
+ * @param options - The transformation options. See {@link FontaineTransformOptions}.
114
+ * @returns The unplugin instance.
115
+ */
150
116
  declare const FontaineTransform: ReturnType<typeof createUnplugin<FontaineTransformOptions>>;
151
117
  //#endregion
152
118
  export { DEFAULT_CATEGORY_FALLBACKS, type FontCategory, FontaineTransform, type FontaineTransformOptions, type ResolveCategoryFallbacksOptions, generateFallbackName, generateFontFace, getMetricsForFamily, readMetrics, resolveCategoryFallbacks };