Skip to content

Commit f2d7920

Browse files
committed
fix(fonts): split font size parsing and fit the CLI size budget
1 parent 2ca8b82 commit f2d7920

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

‎packages/core/src/fonts/deterministicFonts.ts‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,23 @@ function maskParens(value: string): string {
279279
});
280280
}
281281

282+
function fontSizeKind(token: string, masked: string): "literal" | "function" | null {
283+
const size = token.split("/")[0] ?? "";
284+
if (FONT_SIZE_KEYWORD.test(size) || FONT_SIZE_LENGTH.test(token)) return "literal";
285+
if (!FONT_SIZE_FUNCTION.test(token)) return null;
286+
return masked.includes("/") ? "literal" : "function";
287+
}
288+
282289
function fontShorthandFamilies(value: string): string {
283-
let functionSizeEnd = -1;
290+
let firstFunctionSizeEnd = -1;
284291
for (const { 0: masked, index } of maskParens(value).matchAll(/\S+/g)) {
285292
const end = index + masked.length;
286-
const token = value.slice(index, end);
287-
const size = token.split("/")[0] ?? "";
288-
const isFunction = FONT_SIZE_FUNCTION.test(token);
289-
if (
290-
FONT_SIZE_KEYWORD.test(size) ||
291-
FONT_SIZE_LENGTH.test(token) ||
292-
(isFunction && masked.includes("/"))
293-
) {
294-
return value.slice(end).trim();
295-
}
296-
if (isFunction && functionSizeEnd < 0) functionSizeEnd = end;
293+
const kind = fontSizeKind(value.slice(index, end), masked);
294+
if (kind === "literal") return value.slice(end).trim();
295+
if (kind === "function" && firstFunctionSizeEnd < 0) firstFunctionSizeEnd = end;
297296
}
298297
// A var() can hold the style or weight, so it is the size only when no literal size follows.
299-
return functionSizeEnd < 0 ? "" : value.slice(functionSizeEnd).trim();
298+
return firstFunctionSizeEnd < 0 ? "" : value.slice(firstFunctionSizeEnd).trim();
300299
}
301300

302301
function* iterateCssRootFontFamilyDeclarations(
@@ -1016,8 +1015,7 @@ function findDeclaredFamilyAlias(
10161015
return match;
10171016
}
10181017

1019-
// Design exports name a family by class, `font-<Family>-<weight>`; serve <Family> under that name.
1020-
// ponytail: every face is emitted, so the element's own font-weight still picks the face.
1018+
// Design exports name a family by class, `font-<Family>-<weight>`; serve all <Family> faces under that name.
10211019
const WEIGHTED_CLASS_FAMILY = /^font-(.+)-[1-9]00$/i;
10221020

10231021
async function resolveWeightedClassFamily(

0 commit comments

Comments
 (0)