Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: font weight issue and types improvements #13

Merged
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions packages/astro-font/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="astro/astro-jsx" />
rishi-raj-jain marked this conversation as resolved.
Show resolved Hide resolved

import { create } from 'fontkit'
import { join } from 'node:path'
import { relative } from 'pathe'
Expand All @@ -11,25 +13,29 @@ interface Record {

interface Source {
path: string
css?: Record
style: string
css?: astroHTML.JSX.CSSProperties
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-style
style: "normal" | "italic" | "oblique" | `oblique ${number}deg`
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
preload?: boolean
weight?: string | number
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
weight?: "normal" | "bold" | "lighter" | "bolder" | "inherit" | "initial" | "revert" | "revert-layer" | "unset" | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | number
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
}

interface Config {
name: string
src: Source[]
fetch?: boolean
display: string
// https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display
display: "auto" | "block" | "swap" | "fallback" | "optional"
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
selector?: string
preload?: boolean
cacheDir?: string
basePath?: string
fallbackName?: string
googleFontsURL?: string
cssVariable?: string | boolean
fallback: 'serif' | 'sans-serif'
// https://developer.mozilla.org/fr/docs/Web/CSS/font-family
fallback: 'serif' | 'sans-serif' | 'monospace' | 'cursive' | 'fantasy' | 'system-ui' | 'emoji' | 'math' | 'fangsong' | 'inherit' | 'initial' | 'unset'
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
}

export interface Props {
Expand Down Expand Up @@ -255,7 +261,7 @@ async function getFallbackFont(fontCollection: Config): Promise<Record> {
if (res) {
fonts.push({
style: i.style,
weight: i.weight,
weight: i.weight?.toString(),
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
metadata: create(res),
})
}
Expand Down