@unocss/preset-web-fonts 66.2.3 → 66.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.
Files changed (2) hide show
  1. package/dist/index.mjs +51 -26
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -82,8 +82,9 @@ function createFontSourceProvider(name, host) {
82
82
  throw new Error(`Failed to fetch font: ${font.name}`);
83
83
  }
84
84
  }
85
- const { weights } = metadata;
85
+ const { weights, unicodeRange, variants, family } = metadata;
86
86
  const subsets = metadata.subsets.filter((subset) => font.subsets ? font.subsets.includes(subset) : true);
87
+ const style = font.italic ? "italic" : "normal";
87
88
  if (metadata.variable && !font.preferStatic) {
88
89
  let variableData = variablesMap.get(id);
89
90
  const url = `https://api.fontsource.org/v1/variable/${id}`;
@@ -95,42 +96,66 @@ function createFontSourceProvider(name, host) {
95
96
  }
96
97
  const mergeAxes = mergeDeep(variableData.axes, font.variable ?? {});
97
98
  for (const subset of subsets) {
98
- const url2 = `${host}/fontsource/fonts/${metadata.id}:vf@latest/${subset}-${font.italic ? "wght-italic" : "wght-normal"}.woff2`;
99
- const fontObj = {
100
- family: `${metadata.family}`,
101
- display: "swap",
102
- style: font.italic ? "italic" : "normal",
103
- weight: 400,
104
- src: [{
105
- url: url2,
106
- format: "woff2-variations"
107
- }],
108
- variable: {
109
- wght: mergeAxes.wght ?? void 0,
110
- wdth: mergeAxes.wdth ?? void 0,
111
- slnt: mergeAxes.slnt ?? void 0
112
- },
113
- unicodeRange: metadata.unicodeRange[subset],
114
- comment: `${metadata.id}-${subset}-wght-normal`
115
- };
116
- css.push(generateFontFace(fontObj));
99
+ if (unicodeRange[subset]) {
100
+ const url2 = `${host}/fontsource/fonts/${metadata.id}:vf@latest/${subset}-wght-${style}.woff2`;
101
+ const fontObj = {
102
+ family,
103
+ display: "swap",
104
+ style,
105
+ weight: 400,
106
+ src: [{
107
+ url: url2,
108
+ format: "woff2-variations"
109
+ }],
110
+ variable: {
111
+ wght: mergeAxes.wght ?? void 0,
112
+ wdth: mergeAxes.wdth ?? void 0,
113
+ slnt: mergeAxes.slnt ?? void 0
114
+ },
115
+ unicodeRange: unicodeRange[subset],
116
+ comment: `${metadata.id}-${subset}-wght-normal`
117
+ };
118
+ css.push(generateFontFace(fontObj));
119
+ } else {
120
+ Object.entries(unicodeRange).filter(([subKey]) => !metadata.subsets.includes(subKey)).forEach(([subKey, range]) => {
121
+ const url2 = `${host}/fontsource/fonts/${metadata.id}:vf@latest/${subKey.slice(1, -1)}-wght-${style}.woff2`;
122
+ const fontObj = {
123
+ family,
124
+ display: "swap",
125
+ style,
126
+ weight: 400,
127
+ src: [{
128
+ url: url2,
129
+ format: "woff2-variations"
130
+ }],
131
+ variable: {
132
+ wght: mergeAxes.wght ?? void 0,
133
+ wdth: mergeAxes.wdth ?? void 0,
134
+ slnt: mergeAxes.slnt ?? void 0
135
+ },
136
+ unicodeRange: range,
137
+ comment: `${metadata.id}-${subKey}-wght-normal`
138
+ };
139
+ css.push(generateFontFace(fontObj));
140
+ });
141
+ }
117
142
  }
118
143
  } else {
119
144
  const _weights = font.weights && font.weights.length > 0 ? font.weights : weights;
120
145
  for (const subset of subsets) {
121
146
  for (const weight of _weights) {
122
- const url = `${host}/fontsource/fonts/${metadata.id}@latest/${subset}-${weight}-${font.italic ? "italic" : "normal"}`;
147
+ const url = variants[weight][style][subset].url;
123
148
  const fontObj = {
124
- family: metadata.family,
149
+ family,
125
150
  display: "swap",
126
- style: font.italic ? "italic" : "normal",
151
+ style,
127
152
  weight: Number(weight),
128
153
  src: [{
129
- url: `${url}.woff2`,
154
+ url: url.woff2,
130
155
  format: "woff2"
131
156
  }],
132
- unicodeRange: metadata.unicodeRange[subset],
133
- comment: `${metadata.id}-${subset}-${weight}${font.italic ? "-italic" : "-normal"}`
157
+ unicodeRange: unicodeRange[subset],
158
+ comment: `${metadata.id}-${subset}-${weight}-${style}`
134
159
  };
135
160
  css.push(generateFontFace(fontObj));
136
161
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/preset-web-fonts",
3
3
  "type": "module",
4
- "version": "66.2.3",
4
+ "version": "66.3.1",
5
5
  "description": "Web Fonts support for Uno CSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "ofetch": "^1.4.1",
53
- "@unocss/core": "66.2.3"
53
+ "@unocss/core": "66.3.1"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "unbuild",