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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fontline

v1.0.2

Published

Font management system for Next.js applications

Downloads

107

Readme

fontline

A powerful and flexible font management system for Next.js applications.

npm version License: MIT

Features

  • 🎯 Type-safe font configuration
  • 🔄 Automatic font loading and management
  • 💾 Persistent font preferences
  • 🎨 CSS variables integration
  • ⚛️ React hooks for font management
  • 📦 Zero-config integration with Next.js
  • 🌓 Smooth font transitions
  • 🔍 SSR support

Installation

# npm
npm install fontline

# pnpm
pnpm add fontline

# yarn
yarn add fontline

Quick Start

  1. Load your fonts using Next.js font loaders:
// app/fonts.ts
import { Inter, Roboto } from 'next/font/google'
import type { FontProviderProps } from 'fontline'

const inter = Inter({
  subsets: ['latin'],
  variable: '--font-inter',
})

const roboto = Roboto({
  subsets: ['latin'],
  weight: ['400', '700'],
  variable: '--font-roboto',
})

export const fontConfig: FontProviderProps = {
  fonts: {
    inter: {
      className: inter.className,
      style: { fontFamily: inter.style.fontFamily }
    },
    roboto: {
      className: roboto.className,
      style: { fontFamily: roboto.style.fontFamily }
    }
  },
  defaultFont: 'inter',
  // Optional: Custom class mappings
  values: {
    inter: 'my-custom-inter',
    roboto: 'my-custom-roboto'
  },
}
  1. Set up the provider in your layout:
// app/layout.tsx
import { FontProvider } from 'fontline'
import { fontConfig } from './fonts'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body>
        <FontProvider {...fontConfig}>
          {children}
        </FontProvider>
      </body>
    </html>
  )
}
  1. Use the hook in your components:
// components/font-selector.tsx
import { useFont } from 'fontline'

export function FontSelector() {
  const { font, setFont, fonts } = useFont()

  return (
    <select
      value={font}
      onChange={(e) => setFont(e.target.value)}
    >
      {fonts.map((fontName) => (
        <option key={fontName} value={fontName}>
          {fontName}
        </option>
      ))}
    </select>
  )
}

API Reference

FontProvider

The main provider component for font management.

interface FontProviderProps {
  fonts: Record<string, FontConfig>;
  defaultFont: string;
  forcedFont?: string;
  storageKey?: string;
  disableTransitionOnChange?: boolean;
  values?: FontValues;
  nonce?: string;
}

useFont Hook

Hook for accessing font state and controls.

interface UseFontProps {
  font: string;
  setFont: React.Dispatch<React.SetStateAction<string>>;
  fonts: string[];
  forcedFont?: string;
  resolvedFont: string;
}

const { font, setFont, fonts, resolvedFont } = useFont()

Configuration Options

  • fonts: Record of available fonts with their configurations
  • defaultFont: Initial font to use
  • forcedFont: Override user selection (optional)
  • storageKey: LocalStorage key for persistence (default: 'font')
  • disableTransitionOnChange: Disable transitions when changing fonts
  • values: Custom class name mappings
  • nonce: CSP nonce for inline scripts

Advanced Usage

Custom Font Classes

const fontConfig: FontProviderProps = {
  fonts: {
    inter: {
      className: 'font-inter',
      style: { fontFamily: 'Inter' }
    }
  },
  values: {
    inter: 'my-custom-class'
  }
}

Forced Font

<FontProvider
  {...fontConfig}
  forcedFont="inter"
>
  {children}
</FontProvider>

Disable Transitions

<FontProvider
  {...fontConfig}
  disableTransitionOnChange
>
  {children}
</FontProvider>

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • IE 11 (basic support)

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

MIT