Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All changes included in 1.9:

### `html`

- ([#11929](https://github.com/quarto-dev/quarto-cli/issues/11929)): Import all `brand.typography.fonts` in CSS, whether or not fonts are referenced by typography elements.
- ([#13413](https://github.com/quarto-dev/quarto-cli/issues/13413)): Fix uncentered play button in `video` shortcodes from cross-reference divs. (author: @bruvellu)

### `typst`
Expand Down
157 changes: 47 additions & 110 deletions src/core/sass/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from "../../config/types.ts";
import { ProjectContext } from "../../project/types.ts";
import {
BrandFont,
// BrandFontBunny,
BrandFontCommon,
BrandFontFile,
Expand Down Expand Up @@ -338,104 +337,6 @@ const brandTypographyLayer = (
const typographyImports: Set<string> = new Set();
const fonts = brand.data?.typography?.fonts ?? [];

const getFontFamilies = (family: string | undefined) => {
return fonts.filter((font) =>
typeof font !== "string" && font.family === family
);
};

const resolveGoogleFontFamily = (
font: BrandFont[],
): string | undefined => {
let googleFamily = "";
for (const _resolvedFont of font) {
const safeResolvedFont = Zod.BrandFontGoogle.safeParse(_resolvedFont);
if (!safeResolvedFont.success) {
return undefined;
}
const resolvedFont = safeResolvedFont.data;
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
}
if (googleFamily === "") {
googleFamily = thisFamily;
} else if (googleFamily !== thisFamily) {
throw new Error(
`Inconsistent Google font families found: ${googleFamily} and ${thisFamily}`,
);
}
typographyImports.add(googleFontImportString(resolvedFont));
}
if (googleFamily === "") {
return undefined;
}
return googleFamily;
};

const resolveBunnyFontFamily = (
font: BrandFont[],
): string | undefined => {
let bunnyFamily = "";
for (const _resolvedFont of font) {
const safeResolvedFont = Zod.BrandFontBunny.safeParse(_resolvedFont);
if (!safeResolvedFont.success) {
return undefined;
}
const resolvedFont = safeResolvedFont.data;
// Typescript's type checker doesn't understand that it's ok to attempt
// to access a property that might not exist on a type when you're
// only testing for its existence.

const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
}
if (bunnyFamily === "") {
bunnyFamily = thisFamily;
} else if (bunnyFamily !== thisFamily) {
throw new Error(
`Inconsistent Bunny font families found: ${bunnyFamily} and ${thisFamily}`,
);
}
typographyImports.add(bunnyFontImportString(resolvedFont));
}
if (bunnyFamily === "") {
return undefined;
}
return bunnyFamily;
};

const resolveFileFontFamily = (
brand: Brand,
font: BrandFont[],
): string | undefined => {
let fileFamily = "";
for (const _resolvedFont of font) {
const safeResolvedFont = Zod.BrandFontFile.safeParse(_resolvedFont);
if (!safeResolvedFont.success) {
return undefined;
}
const resolvedFont = safeResolvedFont.data;
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
}
if (fileFamily === "") {
fileFamily = thisFamily;
} else if (fileFamily !== thisFamily) {
throw new Error(
`Inconsistent Files font families found: ${fileFamily} and ${thisFamily}`,
);
}
typographyImports.add(fileFontImportString(brand, resolvedFont));
}
if (fileFamily === "") {
return undefined;
}
return fileFamily;
};

type HTMLFontInformation = { [key: string]: unknown };

type FontKind =
Expand All @@ -455,17 +356,9 @@ const brandTypographyLayer = (
resolvedFontOptions = { family: resolvedFontOptions };
}
const result: HTMLFontInformation = {};
// This is an ugly hack:
// resolvedFontOptions doesn't always have 'family', but at this
// point in the code we know resolvedFontOptions is an object
// that we can attempt to extract the family from.
const family =
(resolvedFontOptions as Record<string, string | undefined>).family;
const font = getFontFamilies(family);
result.family = resolveGoogleFontFamily(font) ??
resolveBunnyFontFamily(font) ??
resolveFileFontFamily(brand, font) ??
family;
if ("family" in resolvedFontOptions) {
result.family = resolvedFontOptions.family;
}
for (
const entry of [
"line-height",
Expand Down Expand Up @@ -576,6 +469,50 @@ const brandTypographyLayer = (
],
};

for (const font of fonts) {
switch (font.source) {
case "google": {
const safeResolvedFont = Zod.BrandFontGoogle.safeParse(font);
if (!safeResolvedFont.success) {
continue;
}
const resolvedFont = safeResolvedFont.data;
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
}
typographyImports.add(googleFontImportString(resolvedFont));
break;
}
case "bunny": {
const safeResolvedFont = Zod.BrandFontBunny.safeParse(font);
if (!safeResolvedFont.success) {
continue;
}
const resolvedFont = safeResolvedFont.data;
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
}
typographyImports.add(bunnyFontImportString(resolvedFont));
break;
}
case "file": {
const safeResolvedFont = Zod.BrandFontFile.safeParse(font);
if (!safeResolvedFont.success) {
continue;
}
const resolvedFont = safeResolvedFont.data;
const thisFamily = resolvedFont.family;
if (!thisFamily) {
continue;
}
typographyImports.add(fileFontImportString(brand, resolvedFont));
break;
}
}
}

for (
const kind of [
// more specific entries go first
Expand Down
26 changes: 16 additions & 10 deletions src/resources/editor/tools/vs-code.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12806,9 +12806,6 @@ var require_yaml_intelligence_resources = __commonJS({
},
{
ref: "brand-font-system"
},
{
ref: "brand-font-common"
}
]
},
Expand Down Expand Up @@ -12910,7 +12907,10 @@ var require_yaml_intelligence_resources = __commonJS({
"system"
]
}
}
},
required: [
"source"
]
}
},
{
Expand All @@ -12927,7 +12927,10 @@ var require_yaml_intelligence_resources = __commonJS({
"google"
]
}
}
},
required: [
"source"
]
}
},
{
Expand All @@ -12944,7 +12947,10 @@ var require_yaml_intelligence_resources = __commonJS({
"bunny"
]
}
}
},
required: [
"source"
]
}
},
{
Expand Down Expand Up @@ -21908,7 +21914,7 @@ var require_yaml_intelligence_resources = __commonJS({
"The path to an XML stylesheet (XSL file) used to style the RSS\nfeed.",
{
short: "The date format to use when displaying dates (e.g.&nbsp;d-M-yyy).",
long: 'The date format to use when displaying dates (e.g.&nbsp;d-M-yyy). Learn\nmore about supported date formatting values <a href="https://deno.land/[email protected]/datetime">here</a>.'
long: 'The date format to use when displaying dates (e.g.&nbsp;d-M-yyy). Learn\nmore about supported date formatting values <a href="https://quarto.org/docs/reference/dates.html">here</a>.'
},
{
short: "The maximum length (in characters) of the description displayed in\nthe listing.",
Expand Down Expand Up @@ -24927,12 +24933,12 @@ var require_yaml_intelligence_resources = __commonJS({
mermaid: "%%"
},
"handlers/mermaid/schema.yml": {
_internalId: 197477,
_internalId: 197474,
type: "object",
description: "be an object",
properties: {
"mermaid-format": {
_internalId: 197469,
_internalId: 197466,
type: "enum",
enum: [
"png",
Expand All @@ -24948,7 +24954,7 @@ var require_yaml_intelligence_resources = __commonJS({
exhaustiveCompletions: true
},
theme: {
_internalId: 197476,
_internalId: 197473,
type: "anyOf",
anyOf: [
{
Expand Down

Large diffs are not rendered by default.

26 changes: 16 additions & 10 deletions src/resources/editor/tools/yaml/web-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading