@lediv/fonts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 EMYL LABS, SL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @lediv/fonts
2
+
3
+ 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.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @lediv/fonts
9
+ ```
10
+
11
+ ## Entry points
12
+
13
+ | Import path | Environment | Description |
14
+ | ------------------- | ----------- | ---------------------------------------------- |
15
+ | `@lediv/fonts` | any | Font catalog, CSS helpers, used-font detection |
16
+ | `@lediv/fonts/node` | Node.js | Resolves local WOFF2 file paths on disk |
17
+ | `@lediv/fonts/vite` | Vite | Dev-server middleware + build output plugin |
18
+
19
+ ## Usage
20
+
21
+ ### Font catalog
22
+
23
+ ```ts
24
+ import { CUSTOM_FONTS, getFontById, CUSTOM_FONT_PATHS } from '@lediv/fonts';
25
+
26
+ const inter = getFontById('inter');
27
+ ```
28
+
29
+ ### Generate CSS
30
+
31
+ ```ts
32
+ import { buildFontFaceCSS, buildFontFaceCSSAll, buildFontPreloadLinks } from '@lediv/fonts';
33
+
34
+ const css = buildFontFaceCSSAll(CUSTOM_FONTS);
35
+ const preload = buildFontPreloadLinks([inter]);
36
+ ```
37
+
38
+ ### Detect used fonts
39
+
40
+ ```ts
41
+ import { getUsedFonts } from '@lediv/fonts';
42
+
43
+ const used = getUsedFonts(htmlString);
44
+ ```
45
+
46
+ Scans `<style>` blocks and inline `style` attributes in the given HTML string for any `font-family` references matching the catalog.
47
+
48
+ ### Vite plugin (dev + build)
49
+
50
+ ```ts
51
+ import { serveFonts } from '@lediv/fonts/vite';
52
+
53
+ export default {
54
+ plugins: [serveFonts()],
55
+ };
56
+ ```
57
+
58
+ `serveFonts()` serves `/fonts/:id/latin-wght-normal.woff2` requests in dev and copies all font files to the output directory on build.
59
+
60
+ ### Node file paths
61
+
62
+ ```ts
63
+ import { getFontFilePath } from '@lediv/fonts/node';
64
+ import { getFontById } from '@lediv/fonts';
65
+
66
+ const path = getFontFilePath(getFontById('inter'));
67
+ ```
68
+
69
+ ## Types
70
+
71
+ ```ts
72
+ import type { CustomFont } from '@lediv/fonts';
73
+ ```
74
+
75
+ | Field | Type | Description |
76
+ | ---------- | --------- | ---------------------------------------------- |
77
+ | `id` | `string` | URL-safe identifier, e.g. `inter` |
78
+ | `label` | `string` | Display name, e.g. `Inter` |
79
+ | `fontName` | `string` | CSS `font-family` value, e.g. `Inter Variable` |
80
+ | `weight` | `string` | Weight range, e.g. `100 900` |
81
+ | `fallback` | `string?` | Generic fallback: `serif` or `monospace` |
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,19 @@
1
+ //#region src/index.d.ts
2
+ declare const UNICODE_RANGE_LATIN = "U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD";
3
+ type CustomFont = {
4
+ label: string;
5
+ id: string;
6
+ fontName: string;
7
+ weight: string;
8
+ fallback?: string;
9
+ };
10
+ declare const CUSTOM_FONTS: CustomFont[];
11
+ declare function buildFontFaceCSS(f: CustomFont): string;
12
+ declare function buildFontFaceCSSAll(fonts: CustomFont[]): string;
13
+ declare function buildFontPreloadLinks(fonts: CustomFont[]): string;
14
+ declare function getUsedFonts(text: string): CustomFont[];
15
+ declare function getFontById(id: string): CustomFont | undefined;
16
+ declare const CUSTOM_FONT_PATHS: Set<string>;
17
+ declare const CUSTOM_FONT_LOCAL_CSS: Record<string, string>;
18
+ //#endregion
19
+ export { CUSTOM_FONTS, CUSTOM_FONT_LOCAL_CSS, CUSTOM_FONT_PATHS, CustomFont, UNICODE_RANGE_LATIN, buildFontFaceCSS, buildFontFaceCSSAll, buildFontPreloadLinks, getFontById, getUsedFonts };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ const e=`U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD`,t=[{label:`Inter`,id:`inter`,fontName:`Inter Variable`,weight:`100 900`},{label:`Open Sans`,id:`open-sans`,fontName:`Open Sans Variable`,weight:`300 800`},{label:`Roboto Flex`,id:`roboto-flex`,fontName:`Roboto Flex Variable`,weight:`100 1000`},{label:`Montserrat`,id:`montserrat`,fontName:`Montserrat Variable`,weight:`100 900`},{label:`Raleway`,id:`raleway`,fontName:`Raleway Variable`,weight:`100 900`},{label:`DM Sans`,id:`dm-sans`,fontName:`DM Sans Variable`,weight:`100 1000`},{label:`Plus Jakarta Sans`,id:`plus-jakarta-sans`,fontName:`Plus Jakarta Sans Variable`,weight:`200 800`},{label:`Space Grotesk`,id:`space-grotesk`,fontName:`Space Grotesk Variable`,weight:`300 700`},{label:`Outfit`,id:`outfit`,fontName:`Outfit Variable`,weight:`100 900`},{label:`Nunito`,id:`nunito`,fontName:`Nunito Variable`,weight:`200 1000`},{label:`Work Sans`,id:`work-sans`,fontName:`Work Sans Variable`,weight:`100 900`},{label:`Quicksand`,id:`quicksand`,fontName:`Quicksand Variable`,weight:`300 700`},{label:`Rubik`,id:`rubik`,fontName:`Rubik Variable`,weight:`300 900`},{label:`Sora`,id:`sora`,fontName:`Sora Variable`,weight:`100 800`},{label:`Playfair Display`,id:`playfair-display`,fontName:`Playfair Display Variable`,weight:`400 900`,fallback:`serif`},{label:`Lora`,id:`lora`,fontName:`Lora Variable`,weight:`400 700`,fallback:`serif`},{label:`Source Serif 4`,id:`source-serif-4`,fontName:`Source Serif 4 Variable`,weight:`200 900`,fallback:`serif`},{label:`EB Garamond`,id:`eb-garamond`,fontName:`EB Garamond Variable`,weight:`400 800`,fallback:`serif`},{label:`JetBrains Mono`,id:`jetbrains-mono`,fontName:`JetBrains Mono Variable`,weight:`100 800`,fallback:`monospace`},{label:`Fira Code`,id:`fira-code`,fontName:`Fira Code Variable`,weight:`300 700`,fallback:`monospace`}];function n(t){return`@font-face{font-family:'${t.fontName}';font-style:normal;font-display:swap;font-weight:${t.weight};src:url('/fonts/${t.id}/latin-wght-normal.woff2') format('woff2-variations');unicode-range:${e}}`}function r(e){return e.map(n).join(`
2
+ `)}function i(e){return e.map(e=>`<link rel="preload" as="font" type="font/woff2" href="/fonts/${e.id}/latin-wght-normal.woff2" crossorigin>`).join(`
3
+ `)}function a(e){let t=[],n=/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi,r=/\sstyle\s*=\s*(["'])([\s\S]*?)\1/gi,i;for(;i=n.exec(e);)t.push(i[1]);for(;i=r.exec(e);)t.push(i[2]);return t.join(`
4
+ `)}function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function s(e){let n=a(e);return n?t.filter(e=>{let t=o(e.fontName).replace(/\s+/g,`\\s+`);return RegExp(`['"]${t}['"]`,`i`).test(n)}):[]}function c(e){return t.find(t=>t.id===e)}const l=new Set(t.map(e=>`/fonts/${e.id}/latin-wght-normal.woff2`)),u=Object.fromEntries(t.map(e=>[e.fontName,n(e)]));export{t as CUSTOM_FONTS,u as CUSTOM_FONT_LOCAL_CSS,l as CUSTOM_FONT_PATHS,e as UNICODE_RANGE_LATIN,n as buildFontFaceCSS,r as buildFontFaceCSSAll,i as buildFontPreloadLinks,c as getFontById,s as getUsedFonts};
package/dist/node.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { CustomFont } from "./index.js";
2
+ //#region src/node.d.ts
3
+ declare function getFontFilePath(font: CustomFont): string;
4
+ //#endregion
5
+ export { getFontFilePath };
package/dist/node.js ADDED
@@ -0,0 +1 @@
1
+ import{dirname as e,join as t}from"node:path";import{fileURLToPath as n}from"node:url";const r=e(n(import.meta.url));function i(e){return t(r,`..`,`fonts`,e.id,`latin-wght-normal.woff2`)}export{i as getFontFilePath};
package/dist/vite.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { Plugin } from "vite";
2
+ //#region src/vite.d.ts
3
+ declare function serveFonts(): Plugin;
4
+ //#endregion
5
+ export { serveFonts };
package/dist/vite.js ADDED
@@ -0,0 +1 @@
1
+ import{CUSTOM_FONTS as e,getFontById as t}from"./index.js";import{getFontFilePath as n}from"./node.js";import{dirname as r,join as i}from"node:path";import{copyFileSync as a,mkdirSync as o,readFileSync as s}from"node:fs";function c(){return{name:`serve-lediv-fonts`,configureServer(e){e.middlewares.use((e,r,i)=>{let a=(e.url?.split(`?`)[0]||`/`).match(/^\/fonts\/([^/]+)\/latin-wght-normal\.woff2$/);if(!a)return i();let o=t(a[1]);if(!o)return i();try{let e=s(n(o));r.setHeader(`Content-Type`,`font/woff2`),r.setHeader(`Cache-Control`,`public, max-age=31536000, immutable`),r.statusCode=200,r.end(e)}catch{i()}})},writeBundle(t){let s=t.dir;if(s)for(let t of e){let e=n(t),c=i(s,`fonts`,t.id,`latin-wght-normal.woff2`);o(r(c),{recursive:!0}),a(e,c)}}}}export{c as serveFonts};
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@lediv/fonts",
3
+ "version": "0.1.0",
4
+ "description": "Web font assets and utilities for Lediv projects",
5
+ "keywords": [
6
+ "lediv",
7
+ "fonts",
8
+ "variable-fonts",
9
+ "woff2",
10
+ "vite",
11
+ "css"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "EMYL LABS, SL",
15
+ "homepage": "https://lediv.com",
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "engines": {
19
+ "node": ">=22"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "fonts/",
24
+ "LICENSE",
25
+ "README.md"
26
+ ],
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./node": {
34
+ "types": "./dist/node.d.ts",
35
+ "import": "./dist/node.js",
36
+ "default": "./dist/node.js"
37
+ },
38
+ "./vite": {
39
+ "types": "./dist/vite.d.ts",
40
+ "import": "./dist/vite.js",
41
+ "default": "./dist/vite.js"
42
+ }
43
+ },
44
+ "types": "dist/index.d.ts",
45
+ "main": "dist/index.js",
46
+ "scripts": {
47
+ "build": "tsdown",
48
+ "dev": "tsdown --watch",
49
+ "prepack": "npm run build"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^22.20.1",
53
+ "fontkit": "^2.0.4",
54
+ "typescript": "^6.0.0",
55
+ "vite": "^8.0.0",
56
+ "wawoff2": "^2.0.1"
57
+ },
58
+ "peerDependencies": {
59
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "vite": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "publishConfig": {
67
+ "access": "public"
68
+ }
69
+ }