subfont 6.12.1 → 6.12.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/CHANGELOG.md +4 -0
- package/lib/subsetFonts.js +28 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
### v6.12.2 (2022-11-02)
|
|
2
|
+
|
|
3
|
+
- [Be resilient when an insertion point cannot be found for subfont's preloads and stylesheets Fixes assetgraph\/assetgraph\#1251](https://github.com/Munter/subfont/commit/75beca70fb6cf696cf958326d8ea65b31d125b71) ([Andreas Lind](mailto:andreaslindpetersen@gmail.com))
|
|
4
|
+
|
|
1
5
|
### v6.12.1 (2022-09-11)
|
|
2
6
|
|
|
3
7
|
- [Map font-style: oblique to font-variation-settings: slnt -14](https://github.com/Munter/subfont/commit/ea96284729e0d100fcb87d09c63979641439b169) ([Andreas Lind](mailto:andreaslindpetersen@gmail.com))
|
package/lib/subsetFonts.js
CHANGED
|
@@ -1251,10 +1251,27 @@ async function subsetFonts(
|
|
|
1251
1251
|
fontUsages,
|
|
1252
1252
|
accumulatedFontFaceDeclarations,
|
|
1253
1253
|
} of htmlOrSvgAssetTextsWithProps) {
|
|
1254
|
-
|
|
1254
|
+
let insertionPoint = assetGraph.findRelations({
|
|
1255
1255
|
type: `${htmlOrSvgAsset.type}Style`,
|
|
1256
1256
|
from: htmlOrSvgAsset,
|
|
1257
1257
|
})[0];
|
|
1258
|
+
|
|
1259
|
+
// Hackingly deal with the original stylesheet being located inside <noscript>
|
|
1260
|
+
// https://github.com/assetgraph/assetgraph/issues/1251
|
|
1261
|
+
if (!insertionPoint && htmlOrSvgAsset.type === 'Html') {
|
|
1262
|
+
for (const htmlNoScript of assetGraph.findRelations({
|
|
1263
|
+
type: 'HtmlNoscript',
|
|
1264
|
+
from: htmlOrSvgAsset,
|
|
1265
|
+
})) {
|
|
1266
|
+
if (
|
|
1267
|
+
assetGraph.findRelations({ from: htmlNoScript.to, type: 'HtmlStyle' })
|
|
1268
|
+
.length > 0
|
|
1269
|
+
) {
|
|
1270
|
+
insertionPoint = htmlNoScript;
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1258
1275
|
const subsetFontUsages = fontUsages.filter(
|
|
1259
1276
|
(fontUsage) => fontUsage.subsets
|
|
1260
1277
|
);
|
|
@@ -1291,19 +1308,20 @@ async function subsetFonts(
|
|
|
1291
1308
|
|
|
1292
1309
|
if (unsubsettedFontUsagesToPreload.length > 0) {
|
|
1293
1310
|
// Insert <link rel="preload">
|
|
1294
|
-
|
|
1311
|
+
for (const fontUsage of unsubsettedFontUsagesToPreload) {
|
|
1295
1312
|
// Always preload unsubsetted font files, they might be any format, so can't be clever here
|
|
1296
|
-
|
|
1313
|
+
const preloadRelation = htmlOrSvgAsset.addRelation(
|
|
1297
1314
|
{
|
|
1298
1315
|
type: 'HtmlPreloadLink',
|
|
1299
1316
|
hrefType,
|
|
1300
1317
|
to: fontUsage.fontUrl,
|
|
1301
1318
|
as: 'font',
|
|
1302
1319
|
},
|
|
1303
|
-
'before',
|
|
1320
|
+
insertionPoint ? 'before' : 'firstInHead',
|
|
1304
1321
|
insertionPoint
|
|
1305
1322
|
);
|
|
1306
|
-
|
|
1323
|
+
insertionPoint = insertionPoint || preloadRelation;
|
|
1324
|
+
}
|
|
1307
1325
|
}
|
|
1308
1326
|
|
|
1309
1327
|
if (subsetFontUsages.length === 0) {
|
|
@@ -1433,16 +1451,17 @@ async function subsetFonts(
|
|
|
1433
1451
|
// - https://caniuse.com/#search=preload
|
|
1434
1452
|
|
|
1435
1453
|
if (htmlOrSvgAsset.type === 'Html') {
|
|
1436
|
-
htmlOrSvgAsset.addRelation(
|
|
1454
|
+
const htmlPreloadLink = htmlOrSvgAsset.addRelation(
|
|
1437
1455
|
{
|
|
1438
1456
|
type: 'HtmlPreloadLink',
|
|
1439
1457
|
hrefType,
|
|
1440
1458
|
to: fontAsset,
|
|
1441
1459
|
as: 'font',
|
|
1442
1460
|
},
|
|
1443
|
-
'before',
|
|
1461
|
+
insertionPoint ? 'before' : 'firstInHead',
|
|
1444
1462
|
insertionPoint
|
|
1445
1463
|
);
|
|
1464
|
+
insertionPoint = insertionPoint || htmlPreloadLink;
|
|
1446
1465
|
}
|
|
1447
1466
|
}
|
|
1448
1467
|
}
|
|
@@ -1453,9 +1472,10 @@ async function subsetFonts(
|
|
|
1453
1472
|
inlineCss || htmlOrSvgAsset.type === 'Svg' ? 'inline' : hrefType,
|
|
1454
1473
|
to: cssAsset,
|
|
1455
1474
|
},
|
|
1456
|
-
'before',
|
|
1475
|
+
insertionPoint ? 'before' : 'firstInHead',
|
|
1457
1476
|
insertionPoint
|
|
1458
1477
|
);
|
|
1478
|
+
insertionPoint = insertionPoint || cssRelation;
|
|
1459
1479
|
|
|
1460
1480
|
if (!omitFallbacks && inlineCss && unusedVariantsCss) {
|
|
1461
1481
|
// The fallback CSS for unused variants needs to go into its own stylesheet after the crude version of the JS-based preload "polyfill"
|