anthropic-fonts 1.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/CHANGELOG.md +83 -0
- package/LICENSE +21 -0
- package/README.md +682 -0
- package/cdn/v1/css/advanced.css +37 -0
- package/cdn/v1/css/all-ie.css +108 -0
- package/cdn/v1/css/all.css +125 -0
- package/cdn/v1/css/all.min.css +18 -0
- package/cdn/v1/css/anthropicmono.css +13 -0
- package/cdn/v1/css/anthropicsans.css +61 -0
- package/cdn/v1/css/anthropicserif.css +61 -0
- package/cdn/v1/data.json +150 -0
- package/cdn/v1/fonts/AnthropicMono@400.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@300.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@400.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@500.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@600.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@700.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@800.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSans@900.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@300.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@400.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@500.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@600.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@700.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@800.woff2 +0 -0
- package/cdn/v1/fonts/AnthropicSerif@900.woff2 +0 -0
- package/docs/API.md +477 -0
- package/docs/DEPLOYMENT.md +622 -0
- package/docs/PERFORMANCE.md +545 -0
- package/docs/USAGE.md +682 -0
- package/index.js +149 -0
- package/package.json +61 -0
package/docs/API.md
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
# 🔗 API Reference
|
|
2
|
+
|
|
3
|
+
Dynamic CSS generation API for Anthropic Fonts CDN.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Anthropic Fonts API generates custom CSS on-demand based on query parameters. Load only the fonts and weights you need.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Base URL
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For local development:
|
|
18
|
+
```
|
|
19
|
+
http://localhost:3000/api
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Endpoints
|
|
25
|
+
|
|
26
|
+
### GET /css
|
|
27
|
+
|
|
28
|
+
Generate dynamic CSS for specified fonts and weights.
|
|
29
|
+
|
|
30
|
+
#### Parameters
|
|
31
|
+
|
|
32
|
+
| Parameter | Type | Required | Example | Description |
|
|
33
|
+
|-----------|------|----------|---------|-------------|
|
|
34
|
+
| `family` | string | Yes | `AnthropicSans` | Font family name |
|
|
35
|
+
| `weights` | string | Yes | `400;700` | Semicolon-separated weights |
|
|
36
|
+
|
|
37
|
+
#### Font Families
|
|
38
|
+
|
|
39
|
+
- `AnthropicSans` (or `sans`)
|
|
40
|
+
- `AnthropicSerif` (or `serif`)
|
|
41
|
+
- `AnthropicMono` (or `mono`)
|
|
42
|
+
|
|
43
|
+
#### Valid Weights
|
|
44
|
+
|
|
45
|
+
- `AnthropicSans`: 300, 400, 500, 600, 700, 800, 900
|
|
46
|
+
- `AnthropicSerif`: 300, 400, 500, 600, 700, 800, 900
|
|
47
|
+
- `AnthropicMono`: 400
|
|
48
|
+
|
|
49
|
+
#### Examples
|
|
50
|
+
|
|
51
|
+
##### Basic Request
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
curl "https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=AnthropicSans&weights=400;700"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
##### Multiple Weights
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
curl "https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=AnthropicSans&weights=300;400;500;700"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
##### Serif Font
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
curl "https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=AnthropicSerif&weights=400;700"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
##### Short Name
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
curl "https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=sans&weights=400"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Response Format
|
|
78
|
+
|
|
79
|
+
### Success Response (200)
|
|
80
|
+
|
|
81
|
+
**Content-Type:** `text/css; charset=utf-8`
|
|
82
|
+
|
|
83
|
+
```css
|
|
84
|
+
/* Anthropic Fonts - Dynamic CSS API */
|
|
85
|
+
/* Family: Anthropic Sans, Weights: 400,700 */
|
|
86
|
+
/* Generated: 2026-04-01T12:00:00.000Z */
|
|
87
|
+
|
|
88
|
+
@font-face {
|
|
89
|
+
font-family: 'Anthropic Sans';
|
|
90
|
+
src: url('/v1/fonts/AnthropicSans@400.woff2') format('woff2');
|
|
91
|
+
font-weight: 400;
|
|
92
|
+
font-style: normal;
|
|
93
|
+
font-display: swap;
|
|
94
|
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, ...;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@font-face {
|
|
98
|
+
font-family: 'Anthropic Sans';
|
|
99
|
+
src: url('/v1/fonts/AnthropicSans@700.woff2') format('woff2');
|
|
100
|
+
font-weight: 700;
|
|
101
|
+
font-style: normal;
|
|
102
|
+
font-display: swap;
|
|
103
|
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, ...;
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Error Responses
|
|
108
|
+
|
|
109
|
+
#### 400 - Bad Request
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"error": "Font not found",
|
|
114
|
+
"available": ["AnthropicSans", "AnthropicSerif", "AnthropicMono"]
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### 400 - Invalid Weights
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"error": "Invalid weights parameter"
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### 500 - Server Error
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"error": "Internal server error"
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Caching
|
|
137
|
+
|
|
138
|
+
All responses are cached aggressively:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
Cache-Control: public, max-age=31536000, immutable
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This caches CSS for **1 year** safely because:
|
|
145
|
+
- URLs are versioned in the CDN path
|
|
146
|
+
- Query parameters are permanent
|
|
147
|
+
- Content never changes
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Usage Examples
|
|
152
|
+
|
|
153
|
+
### HTML
|
|
154
|
+
|
|
155
|
+
```html
|
|
156
|
+
<link rel="stylesheet"
|
|
157
|
+
href="https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=AnthropicSans&weights=400;700">
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### CSS
|
|
161
|
+
|
|
162
|
+
```css
|
|
163
|
+
@import url('https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=AnthropicSans&weights=400;700');
|
|
164
|
+
|
|
165
|
+
body {
|
|
166
|
+
font-family: 'Anthropic Sans', sans-serif;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### JavaScript
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
const fontUrl = new URL('https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css');
|
|
174
|
+
fontUrl.searchParams.set('family', 'AnthropicSans');
|
|
175
|
+
fontUrl.searchParams.set('weights', '400;700');
|
|
176
|
+
|
|
177
|
+
const link = document.createElement('link');
|
|
178
|
+
link.rel = 'stylesheet';
|
|
179
|
+
link.href = fontUrl.toString();
|
|
180
|
+
document.head.appendChild(link);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### React
|
|
184
|
+
|
|
185
|
+
```jsx
|
|
186
|
+
export function FontLoader() {
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
const params = new URLSearchParams({
|
|
189
|
+
family: 'AnthropicSans',
|
|
190
|
+
weights: '400;700'
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const link = document.createElement('link');
|
|
194
|
+
link.rel = 'stylesheet';
|
|
195
|
+
link.href = `https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?${params}`;
|
|
196
|
+
document.head.appendChild(link);
|
|
197
|
+
}, []);
|
|
198
|
+
|
|
199
|
+
return <h1 style={{ fontFamily: 'Anthropic Sans' }}>Hello</h1>;
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Alternative Endpoint: /fonts
|
|
206
|
+
|
|
207
|
+
Legacy format endpoint (maps to `/css`):
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# Query format: FontName@weight1;weight2
|
|
211
|
+
curl "https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/fonts?query=AnthropicSans@400;700"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Metadata Endpoint
|
|
217
|
+
|
|
218
|
+
### GET /v1/metadata
|
|
219
|
+
|
|
220
|
+
Get font family information and available variants.
|
|
221
|
+
|
|
222
|
+
**Response:**
|
|
223
|
+
|
|
224
|
+
```json
|
|
225
|
+
{
|
|
226
|
+
"version": "1.0.0",
|
|
227
|
+
"updated": "2026-04-01T06:04:30.100Z",
|
|
228
|
+
"fonts": [
|
|
229
|
+
{
|
|
230
|
+
"family": "Anthropic Sans",
|
|
231
|
+
"category": "sans-serif",
|
|
232
|
+
"variants": [
|
|
233
|
+
{
|
|
234
|
+
"weight": 300,
|
|
235
|
+
"style": "normal",
|
|
236
|
+
"file": "AnthropicSans@300.woff2",
|
|
237
|
+
"unicodeRanges": {
|
|
238
|
+
"latin": "U+0000-00FF, ...",
|
|
239
|
+
"latin-ext": "U+0100-024F, ..."
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
...
|
|
243
|
+
],
|
|
244
|
+
"unicodeRange": "U+0000-00FF, U+0131, ..."
|
|
245
|
+
},
|
|
246
|
+
...
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Usage:**
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
fetch('https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/v1/metadata')
|
|
255
|
+
.then(r => r.json())
|
|
256
|
+
.then(meta => {
|
|
257
|
+
console.log('Available fonts:', meta.fonts);
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Static Endpoints
|
|
264
|
+
|
|
265
|
+
### All Fonts CSS
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
GET /v1/css/all.css
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Includes all font families and weights.
|
|
272
|
+
|
|
273
|
+
### Individual Font CSS
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
GET /v1/css/anthropicsans.css
|
|
277
|
+
GET /v1/css/anthropicserif.css
|
|
278
|
+
GET /v1/css/anthropicmono.css
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Individual font family CSS files.
|
|
282
|
+
|
|
283
|
+
### Minified CSS
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
GET /v1/css/all.min.css
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Minified version of all.css (saves ~60%).
|
|
290
|
+
|
|
291
|
+
### Font Files
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
GET /v1/fonts/AnthropicSans@400.woff2
|
|
295
|
+
GET /v1/fonts/AnthropicSans@700.woff2
|
|
296
|
+
GET /v1/fonts/AnthropicSerif@400.woff2
|
|
297
|
+
... (all weights available)
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Health Check
|
|
303
|
+
|
|
304
|
+
### GET /health
|
|
305
|
+
|
|
306
|
+
Check if API is running.
|
|
307
|
+
|
|
308
|
+
**Response:**
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{
|
|
312
|
+
"status": "ok",
|
|
313
|
+
"timestamp": "2026-04-01T12:00:00.000Z"
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Performance Tips
|
|
320
|
+
|
|
321
|
+
### 1. Load Only Needed Weights
|
|
322
|
+
|
|
323
|
+
```html
|
|
324
|
+
<!-- ❌ Load all (5.63 KB) -->
|
|
325
|
+
<link rel="stylesheet" href="...all.css">
|
|
326
|
+
|
|
327
|
+
<!-- ✅ Load specific (1.5 KB) -->
|
|
328
|
+
<link rel="stylesheet" href="...api/css?family=AnthropicSans&weights=400;700">
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### 2. Use Preconnect
|
|
332
|
+
|
|
333
|
+
```html
|
|
334
|
+
<link rel="preconnect" href="https://cdn.jsdelivr.net">
|
|
335
|
+
<link rel="stylesheet" href="...api/css?family=AnthropicSans&weights=400">
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### 3. Cache Aggressively
|
|
339
|
+
|
|
340
|
+
Responses include `immutable` cache header - safe to cache forever.
|
|
341
|
+
|
|
342
|
+
### 4. Combine with Preload
|
|
343
|
+
|
|
344
|
+
```html
|
|
345
|
+
<link rel="preload" as="font" type="font/woff2"
|
|
346
|
+
href="https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/v1/fonts/AnthropicSans@400.woff2"
|
|
347
|
+
crossorigin>
|
|
348
|
+
|
|
349
|
+
<link rel="stylesheet"
|
|
350
|
+
href="https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css?family=AnthropicSans&weights=400">
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## API Conventions
|
|
356
|
+
|
|
357
|
+
### URL Format
|
|
358
|
+
|
|
359
|
+
```
|
|
360
|
+
https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.1.0/cdn/api/css
|
|
361
|
+
?family=AnthropicSans ← Font family
|
|
362
|
+
&weights=400;700 ← Semicolon-separated weights
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Allowed Characters
|
|
366
|
+
|
|
367
|
+
- Font names: Alphanumeric (AnthropicSans, sans, serif)
|
|
368
|
+
- Weights: Numbers 100-900 separated by semicolons (300;400;700)
|
|
369
|
+
|
|
370
|
+
### Query Parameter Validation
|
|
371
|
+
|
|
372
|
+
- Missing `family`: Returns 400 error
|
|
373
|
+
- Invalid `family`: Returns 400 with available list
|
|
374
|
+
- Invalid `weights`: Returns 400 error
|
|
375
|
+
- Missing `weights`: Defaults to 400
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## Rate Limiting
|
|
380
|
+
|
|
381
|
+
The API respects jsDelivr's rate limits:
|
|
382
|
+
|
|
383
|
+
- **Per IP:** 1000 requests per hour
|
|
384
|
+
- **Per file:** 5000 requests per minute
|
|
385
|
+
|
|
386
|
+
For most use cases, static CDN URLs are cached, so minimal requests.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## CORS Headers
|
|
391
|
+
|
|
392
|
+
All API responses include:
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
Access-Control-Allow-Origin: *
|
|
396
|
+
Access-Control-Allow-Methods: GET, OPTIONS
|
|
397
|
+
Access-Control-Allow-Headers: Content-Type
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Safe for cross-origin requests from any domain.
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
## Content Negotiation
|
|
405
|
+
|
|
406
|
+
### Content-Type
|
|
407
|
+
|
|
408
|
+
API responds with appropriate content types:
|
|
409
|
+
|
|
410
|
+
- **CSS endpoint:** `text/css; charset=utf-8`
|
|
411
|
+
- **JSON endpoints:** `application/json`
|
|
412
|
+
- **Font files:** `application/font-woff2`
|
|
413
|
+
|
|
414
|
+
### Accept Header
|
|
415
|
+
|
|
416
|
+
The API ignores Accept headers and serves based on endpoint:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
# Always returns CSS regardless of Accept header
|
|
420
|
+
GET /api/css?family=AnthropicSans&weights=400
|
|
421
|
+
|
|
422
|
+
# Always returns JSON
|
|
423
|
+
GET /v1/metadata
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
## Versioning
|
|
429
|
+
|
|
430
|
+
API versions in CDN path:
|
|
431
|
+
|
|
432
|
+
```
|
|
433
|
+
/v1/css/... ← Version 1 CSS
|
|
434
|
+
/v1/fonts/... ← Version 1 fonts
|
|
435
|
+
/api/css?... ← Latest API
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
To lock to specific version, use Git tags:
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
https://cdn.jsdelivr.net/gh/devchauhann/fonts@v1.0.0/cdn/api/css?...
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
---
|
|
445
|
+
|
|
446
|
+
## Changelog
|
|
447
|
+
|
|
448
|
+
### v1.0.0 (Current)
|
|
449
|
+
|
|
450
|
+
- ✅ Dynamic CSS generation
|
|
451
|
+
- ✅ Multiple weights support
|
|
452
|
+
- ✅ All three font families (Sans, Serif, Mono)
|
|
453
|
+
- ✅ Metadata endpoint
|
|
454
|
+
- ✅ CORS support
|
|
455
|
+
- ✅ Aggressive caching
|
|
456
|
+
|
|
457
|
+
### Planned Features
|
|
458
|
+
|
|
459
|
+
- [ ] Font subsetting by character range
|
|
460
|
+
- [ ] Italic style support
|
|
461
|
+
- [ ] Variable font format (single file, any weight)
|
|
462
|
+
- [ ] WebP image format for fallback
|
|
463
|
+
- [ ] Usage analytics
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## Support & Issues
|
|
468
|
+
|
|
469
|
+
Report issues or request features:
|
|
470
|
+
- GitHub Issues: https://github.com/devchauhann/fonts/issues
|
|
471
|
+
- Documentation: See [USAGE.md](./USAGE.md) and [PERFORMANCE.md](./PERFORMANCE.md)
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## License
|
|
476
|
+
|
|
477
|
+
API and fonts are provided as-is. See [LICENSE](../LICENSE) file.
|