npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

astro-typekit

v0.1.0

Published

Astro-native font loading for Google Fonts and local font files.

Readme

astro-typekit gives Astro projects a small, typed font API at astro/font/google and astro/font/local. Add the integration once, import fonts directly inside your Astro components, and let the middleware inject the generated @font-face rules into the rendered page.

Features

  • Astro integration with first-class astro.config.ts setup
  • astro/font/google helpers for popular Google Fonts
  • astro/font/local for one file, many weights, or variable font families
  • Generated class names and optional CSS variable classes
  • Local font files emitted through Vite/Astro as hashed assets when possible
  • Automatic font preloads for emitted local font files
  • Google Font CSS cached in node_modules/.cache/astro-typekit
  • Google font loading strategies: keep fonts hosted by Google or inline them
  • Optional selector rules for app-wide font application
  • Type declarations injected automatically for Astro projects

Install

npm install astro-typekit

Add The Integration

// astro.config.ts
import { defineConfig } from "astro/config";
import font from "astro-typekit";

export default defineConfig({
  integrations: [font()],
});

The integration registers Astro middleware, configures virtual font modules for Vite, rewrites static local font paths to asset imports, and injects TypeScript declarations for both import paths.

Use A Google Font

---
import { Inter } from "astro/font/google";

const inter = Inter({
  subsets: ["latin"],
  weight: ["400", "700"],
  display: "swap",
  strategy: "external",
  variable: "--font-inter",
  fallback: ["system-ui", "sans-serif"],
});
---

<html lang="en" class={inter.variable}>
  <body class={inter.className}>
    <h1>Astro pages with crisp, optimized type.</h1>
  </body>
</html>

Use A Local Font

---
import localFont from "astro/font/local";

const brand = localFont({
  src: [
    { path: "../fonts/Brand-Regular.woff2", weight: "400", style: "normal" },
    { path: "../fonts/Brand-Bold.woff2", weight: "700", style: "normal" },
  ],
  display: "swap",
  variable: "--font-brand",
  fallback: ["system-ui", "sans-serif"],
});
---

<main class={`${brand.className} ${brand.variable}`}>
  <h1>Your Astro site, in your own typeface.</h1>
</main>

Static relative local paths in Astro, TypeScript, and JavaScript files are rewritten to Vite ?url imports so Astro can fingerprint and emit the files. Public URLs such as /fonts/Brand.woff2 are kept as URLs. During production builds, any local file that cannot be rewritten is copied into Astro's asset directory with a content hash as a fallback.

API

astro/font/google

Exports named Google font helpers such as:

import {
  Inter,
  Lato,
  Merriweather,
  Montserrat,
  Open_Sans,
  Playfair_Display,
  Poppins,
  Raleway,
  Roboto,
  Source_Sans_3,
  Work_Sans,
  createGoogleFont,
} from "astro/font/google";
const heading = Playfair_Display({
  subsets: ["latin"],
  weight: ["400", "700"],
  style: ["normal", "italic"],
  display: "swap",
  variable: "--font-heading",
  fallback: ["Georgia", "serif"],
});

Need a Google Font helper that is not exported yet? Create one by family name:

import { createGoogleFont } from "astro/font/google";

const DM_Sans = createGoogleFont("DM Sans");

const body = DM_Sans({
  subsets: ["latin"],
  weight: ["400", "500", "700"],
});

By default, Google font CSS keeps its fonts.gstatic.com URLs intact, so the browser loads font files from Google at runtime. If you want a fully inlined response instead, opt in per font:

---
import { Inter } from "astro/font/google";

const inter = Inter({
  weight: ["400", "700"],
  strategy: "inline",
});
---

To apply a font globally, pass one or more selectors. The generated class names are still returned, but the middleware also emits selector rules:

---
import { createGoogleFont } from "astro/font/google";

const Cairo = createGoogleFont("Cairo");

const cairo = Cairo({
  subsets: ["arabic", "latin"],
  weight: ["400", "600", "700"],
  variable: "--font-cairo",
  fallback: ["Tahoma", "Arial", "sans-serif"],
  variableSelector: ":root",
  selector: ["html[lang='ar']", "body[dir='rtl']"],
});
---

Use variableSelector when you only want to expose the CSS variable, such as on :root. Use selector when that selector should actually receive the font-family declaration too.

astro/font/local

The default export accepts a single source or an array of sources:

import localFont from "astro/font/local";

const mono = localFont({
  src: "../fonts/MonoVariable.woff2",
  weight: "100 900",
  display: "swap",
  variable: "--font-mono",
});

Returned Object

Both font modules return the same shape:

type AstroFont = {
  className: string;
  variable?: string;
  family: string;
  style: {
    fontFamily: string;
    fontStyle?: string;
    fontWeight?: string;
  };
};

Use className directly on Astro elements, apply variable to expose a CSS custom property, read family for a resolved font-family value, or read style when you need inline style values.

How It Works

astro-typekit collects font usage while Astro renders, downloads and caches Google Font CSS when needed, optionally inlines Google font files, emits local font files as hashed assets, injects preload links for emitted local fonts, and appends the final CSS to the HTML response. Your components stay clean, and the generated font rules travel with the page Astro builds.