@jay-framework/design-system-validator 0.22.2 → 0.23.1
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/agent-kit/aiditor/settings.template.yaml +2 -0
- package/agent-kit/designer/font-fallback-patterns.md +78 -0
- package/dist/actions/font-fallback.jay-action +12 -0
- package/dist/index.client.d.ts +7 -0
- package/dist/index.client.js +657 -0
- package/dist/index.d.ts +89 -1
- package/dist/index.js +760 -291
- package/dist/pages/settings/page.jay-html +415 -0
- package/dist/pages/settings/page.jay-html.d.ts +74 -0
- package/package.json +24 -8
- package/plugin.yaml +20 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Font Fallback Patterns
|
|
2
|
+
|
|
3
|
+
## Why metric-matched fallbacks matter
|
|
4
|
+
|
|
5
|
+
When a web font loads via `font-display: swap`, the browser renders a system fallback font first. Differences in vertical metrics (ascent, descent, line-gap) and horizontal metrics (character width) between the web font and fallback cause visible layout jumps — known as Flash of Unstyled Text (FOUT) — and degrade Cumulative Layout Shift (CLS).
|
|
6
|
+
|
|
7
|
+
A metric-matched fallback `@font-face` overrides the system font's metrics to match the web font, so the swap is visually seamless.
|
|
8
|
+
|
|
9
|
+
## Using the action
|
|
10
|
+
|
|
11
|
+
Generate a fallback `@font-face` for any known Google Font or system font:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx jay-stack-cli action design-system-validator/fontFallback --input '{"primary":"Inter","fallback":"Arial"}'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This outputs the CSS you need:
|
|
18
|
+
|
|
19
|
+
```css
|
|
20
|
+
@font-face {
|
|
21
|
+
font-family: 'Inter Fallback';
|
|
22
|
+
src: local('Arial'), local('ArialMT');
|
|
23
|
+
ascent-override: 90.44%;
|
|
24
|
+
descent-override: 22.52%;
|
|
25
|
+
line-gap-override: 0%;
|
|
26
|
+
size-adjust: 107.12%;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then add the fallback to your `font-family` stack:
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
body {
|
|
34
|
+
font-family: 'Inter', 'Inter Fallback', sans-serif;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Where to place the fallback CSS
|
|
39
|
+
|
|
40
|
+
- **DESIGN.md**: If your design system defines fonts in the frontmatter, add the fallback `@font-face` to the page's `<style>` block or a shared stylesheet
|
|
41
|
+
- **Page `<head>` styles**: For per-page fonts, place the `@font-face` in the page's `<style>` tag
|
|
42
|
+
|
|
43
|
+
## Common font pairs
|
|
44
|
+
|
|
45
|
+
| Web font | Fallback | Category |
|
|
46
|
+
| ---------------- | -------- | ---------- |
|
|
47
|
+
| Inter | Arial | sans-serif |
|
|
48
|
+
| Roboto | Arial | sans-serif |
|
|
49
|
+
| Open Sans | Arial | sans-serif |
|
|
50
|
+
| Playfair Display | Georgia | serif |
|
|
51
|
+
| Merriweather | Georgia | serif |
|
|
52
|
+
| Lora | Georgia | serif |
|
|
53
|
+
|
|
54
|
+
## Manual pattern
|
|
55
|
+
|
|
56
|
+
If the action doesn't support your font, you can write the fallback manually. The key CSS properties are:
|
|
57
|
+
|
|
58
|
+
- `size-adjust` — scales the fallback to match the web font's character width
|
|
59
|
+
- `ascent-override` — matches the space above the baseline
|
|
60
|
+
- `descent-override` — matches the space below the baseline
|
|
61
|
+
- `line-gap-override` — matches the inter-line spacing
|
|
62
|
+
|
|
63
|
+
```css
|
|
64
|
+
@font-face {
|
|
65
|
+
font-family: 'MyFont-Fallback';
|
|
66
|
+
src: local('Arial');
|
|
67
|
+
size-adjust: <value>%;
|
|
68
|
+
ascent-override: <value>%;
|
|
69
|
+
descent-override: <value>%;
|
|
70
|
+
line-gap-override: <value>%;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Validation
|
|
75
|
+
|
|
76
|
+
The `font-fallbacks` validator detects `@font-face` rules that load from a URL without a companion metric-matched fallback. It checks both page CSS and DESIGN.md typography tokens.
|
|
77
|
+
|
|
78
|
+
To suppress a false positive, use the standard `/* design-system: allow */` comment after the `font-family` declaration.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
name: fontFallback
|
|
2
|
+
description: >
|
|
3
|
+
Generate a metric-matched fallback @font-face for a web font to prevent layout shift (CLS).
|
|
4
|
+
Uses pre-computed metrics from @capsizecss/metrics for known Google and system fonts.
|
|
5
|
+
|
|
6
|
+
inputSchema:
|
|
7
|
+
primary: string
|
|
8
|
+
fallback: string
|
|
9
|
+
|
|
10
|
+
outputSchema:
|
|
11
|
+
fontFamily: string
|
|
12
|
+
fontFaces: string
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _jay_framework_fullstack_component from '@jay-framework/fullstack-component';
|
|
2
|
+
import { Signals, PageProps } from '@jay-framework/fullstack-component';
|
|
3
|
+
import * as _jay_framework_component from '@jay-framework/component';
|
|
4
|
+
|
|
5
|
+
declare const designSystemSettingsPage: _jay_framework_fullstack_component.JayStackComponentDefinition<any, any, any, any, [], [Signals<any>, {}], PageProps, {}, _jay_framework_component.JayComponentCore<PageProps, any>>;
|
|
6
|
+
|
|
7
|
+
export { designSystemSettingsPage };
|