fontaine 0.1.3 → 0.2.0

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 CHANGED
@@ -52,6 +52,8 @@ const options = {
52
52
  fallbacks: ['BlinkMacSystemFont', 'Segoe UI', 'Helvetica Neue', 'Arial', 'Noto Sans'],
53
53
  // You may need to resolve assets like `/fonts/Roboto.woff2` to a particular directory
54
54
  resolvePath: (id) => 'file:///path/to/public/dir' + id,
55
+ // overrideName: (originalName) => `${name} override`
56
+ // sourcemap: false
55
57
  }
56
58
 
57
59
  // Vite
@@ -67,6 +69,23 @@ export default {
67
69
  return config
68
70
  },
69
71
  }
72
+
73
+ // Docusaurus plugin - to be provided to the plugins option of docusaurus.config.js
74
+ // n.b. you'll likely need to require fontaine rather than importing it
75
+ const fontaine = require('fontaine')
76
+
77
+ function fontainePlugin(_context, _options) {
78
+ return {
79
+ name: 'fontaine-plugin',
80
+ configureWebpack(_config, _isServer) {
81
+ return {
82
+ plugins: [
83
+ fontaine.FontaineTransform.webpack(options),
84
+ ],
85
+ };
86
+ },
87
+ };
88
+ }
70
89
  ```
71
90
 
72
91
  > **Note**
package/dist/index.cjs CHANGED
@@ -98,9 +98,10 @@ const FontaineTransform = unplugin.createUnplugin(
98
98
  (options) => {
99
99
  const cssContext = options.css = options.css || {};
100
100
  cssContext.value = "";
101
- options.resolvePath = options.resolvePath || ((id) => id);
101
+ const resolvePath = options.resolvePath || ((id) => id);
102
+ const overrideName = options.overrideName || generateOverrideName;
102
103
  function readMetricsFromId(path, importer) {
103
- const resolvedPath = pathe.isAbsolute(importer) && path.startsWith(".") ? pathe.join(importer, path) : options.resolvePath(path);
104
+ const resolvedPath = pathe.isAbsolute(importer) && path.startsWith(".") ? pathe.join(importer, path) : resolvePath(path);
104
105
  return readMetrics(resolvedPath);
105
106
  }
106
107
  return {
@@ -124,7 +125,7 @@ const FontaineTransform = unplugin.createUnplugin(
124
125
  const metrics = await getMetricsForFamily(family) || source && await readMetricsFromId(source, id).catch(() => null);
125
126
  if (metrics) {
126
127
  const fontFace = generateFontFace(metrics, {
127
- name: generateOverrideName(family),
128
+ name: overrideName(family),
128
129
  fallbacks: options.fallbacks
129
130
  });
130
131
  cssContext.value += fontFace;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ interface FontaineTransformOptions {
7
7
  };
8
8
  fallbacks: string[];
9
9
  resolvePath?: (path: string) => string | URL;
10
+ /** this should produce an unquoted font family name */
11
+ overrideName?: (name: string) => string;
10
12
  sourcemap?: boolean;
11
13
  }
12
14
  declare const FontaineTransform: unplugin.UnpluginInstance<FontaineTransformOptions>;
package/dist/index.mjs CHANGED
@@ -96,9 +96,10 @@ const FontaineTransform = createUnplugin(
96
96
  (options) => {
97
97
  const cssContext = options.css = options.css || {};
98
98
  cssContext.value = "";
99
- options.resolvePath = options.resolvePath || ((id) => id);
99
+ const resolvePath = options.resolvePath || ((id) => id);
100
+ const overrideName = options.overrideName || generateOverrideName;
100
101
  function readMetricsFromId(path, importer) {
101
- const resolvedPath = isAbsolute(importer) && path.startsWith(".") ? join(importer, path) : options.resolvePath(path);
102
+ const resolvedPath = isAbsolute(importer) && path.startsWith(".") ? join(importer, path) : resolvePath(path);
102
103
  return readMetrics(resolvedPath);
103
104
  }
104
105
  return {
@@ -122,7 +123,7 @@ const FontaineTransform = createUnplugin(
122
123
  const metrics = await getMetricsForFamily(family) || source && await readMetricsFromId(source, id).catch(() => null);
123
124
  if (metrics) {
124
125
  const fontFace = generateFontFace(metrics, {
125
- name: generateOverrideName(family),
126
+ name: overrideName(family),
126
127
  fallbacks: options.fallbacks
127
128
  });
128
129
  cssContext.value += fontFace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fontaine",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Automatic font fallback based on font metrics",
5
5
  "repository": "unjs/fontaine",
6
6
  "keywords": [
@@ -83,5 +83,5 @@
83
83
  "resolutions": {
84
84
  "fontaine": "link:."
85
85
  },
86
- "packageManager": "pnpm@7.13.4"
86
+ "packageManager": "pnpm@7.13.5"
87
87
  }