@lediv/fonts
v0.1.0
Published
Web font assets and utilities for Lediv projects
Maintainers
Readme
@lediv/fonts
Variable web font assets and utilities for Lediv projects. Includes 20 curated fonts (Inter, Roboto Flex, Playfair Display, JetBrains Mono, and more) pre-bundled as WOFF2 files, with helpers for CSS @font-face generation, preload link tags, and Vite integration.
Install
npm install @lediv/fontsEntry points
| Import path | Environment | Description |
| ------------------- | ----------- | ---------------------------------------------- |
| @lediv/fonts | any | Font catalog, CSS helpers, used-font detection |
| @lediv/fonts/node | Node.js | Resolves local WOFF2 file paths on disk |
| @lediv/fonts/vite | Vite | Dev-server middleware + build output plugin |
Usage
Font catalog
import { CUSTOM_FONTS, getFontById, CUSTOM_FONT_PATHS } from '@lediv/fonts';
const inter = getFontById('inter');Generate CSS
import { buildFontFaceCSS, buildFontFaceCSSAll, buildFontPreloadLinks } from '@lediv/fonts';
const css = buildFontFaceCSSAll(CUSTOM_FONTS);
const preload = buildFontPreloadLinks([inter]);Detect used fonts
import { getUsedFonts } from '@lediv/fonts';
const used = getUsedFonts(htmlString);Scans <style> blocks and inline style attributes in the given HTML string for any font-family references matching the catalog.
Vite plugin (dev + build)
import { serveFonts } from '@lediv/fonts/vite';
export default {
plugins: [serveFonts()],
};serveFonts() serves /fonts/:id/latin-wght-normal.woff2 requests in dev and copies all font files to the output directory on build.
Node file paths
import { getFontFilePath } from '@lediv/fonts/node';
import { getFontById } from '@lediv/fonts';
const path = getFontFilePath(getFontById('inter'));Types
import type { CustomFont } from '@lediv/fonts';| Field | Type | Description |
| ---------- | --------- | ---------------------------------------------- |
| id | string | URL-safe identifier, e.g. inter |
| label | string | Display name, e.g. Inter |
| fontName | string | CSS font-family value, e.g. Inter Variable |
| weight | string | Weight range, e.g. 100 900 |
| fallback | string? | Generic fallback: serif or monospace |
License
MIT
