chore(icon_pack): generate icon declarations

This commit is contained in:
Elian Doran 2025-12-26 18:15:46 +02:00
parent 93a3b29677
commit 5f1bdf7264
No known key found for this signature in database
2 changed files with 14 additions and 5 deletions

View File

@ -133,5 +133,7 @@ describe("CSS generation", () => {
expect(css).toContain("@font-face");
expect(css).toContain("font-family: 'trilium-icon-pack-bx' !important;");
expect(css).toContain(".bx.bx-ball::before { content: '\\e9c2'; }");
expect(css).toContain(".bx.bxs-party::before { content: '\\ec92'; }");
});
});

View File

@ -62,17 +62,22 @@ export function determineBestFontAttachment(iconPackNote: BNote) {
return null;
}
export function generateCss(processedIconPack: ProcessResult) {
export function generateCss({ manifest, fontAttachmentId, fontMime }: ProcessResult) {
const iconDeclarations: string[] = [];
for (const [ key, mapping ] of Object.entries(manifest.icons)) {
iconDeclarations.push(`.${manifest.prefix}.${key}::before { content: '\\${mapping.charCodeAt(0).toString(16)}' }`);
}
return `\
@font-face {
font-family: 'trilium-icon-pack-${processedIconPack.manifest.prefix}';
font-family: 'trilium-icon-pack-${manifest.prefix}';
font-weight: normal;
font-style: normal;
src: url('/api/attachments/${processedIconPack.fontAttachmentId}/download') format('${MIME_TO_CSS_FORMAT_MAPPINGS[processedIconPack.fontMime]}');
src: url('/api/attachments/${fontAttachmentId}/download') format('${MIME_TO_CSS_FORMAT_MAPPINGS[fontMime]}');
}
.${processedIconPack.manifest.prefix} {
font-family: 'trilium-icon-pack-${processedIconPack.manifest.prefix}' !important;
.${manifest.prefix} {
font-family: 'trilium-icon-pack-${manifest.prefix}' !important;
font-weight: normal;
font-style: normal;
font-variant: normal;
@ -83,5 +88,7 @@ export function generateCss(processedIconPack: ProcessResult) {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
${iconDeclarations.join("\n")}
`;
}