Skip to content

Commit f449c09

Browse files
cedric07cursoragent
andcommitted
feat(typography): move type ramp and webfonts to theme.json
Replace Poppins/fontsource with theme.json fluid presets, variable woff2 (latin subset), SCSS tokens from webpack, and metric fallbacks for CLS. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6004d8e commit f449c09

15 files changed

Lines changed: 243 additions & 151 deletions

‎config/webpack-theme-json-plugin.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ class WebpackThemeJsonPlugin {
122122

123123
return result
124124
},
125+
'settings-typography-fontSizes'(key, value) {
126+
let result = ''
127+
128+
for (const fontSize of value) {
129+
const cssSlug = toPresetCssSlug(fontSize.slug)
130+
result += `${getVariableName(
131+
'settings-font-size-' + fontSize.slug
132+
)}: var(--wp--preset--font-size--${cssSlug});\n`
133+
}
134+
135+
return result
136+
},
137+
'settings-typography-fontFamilies'(key, value) {
138+
let result = ''
139+
const families = []
140+
141+
for (const family of value) {
142+
result += `${getVariableName('settings-font-family-' + family.slug)}: var(--wp--preset--font-family--${
143+
family.slug
144+
});\n`
145+
families.push(`${formatMapKey(family.slug)}: ${getVariableName('settings-font-family-' + family.slug)}`)
146+
}
147+
148+
return result + `$settings-font-families: (\n\t${families.join(',\n\t')}\n);\n`
149+
},
125150
}
126151
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
127152
const taskNames = Object.keys(tasks)
@@ -141,6 +166,11 @@ class WebpackThemeJsonPlugin {
141166
return `$${id.replace(/([A-Z])/g, '-$1').toLowerCase()}`
142167
}
143168

169+
// Match WordPress preset CSS custom property segments (e.g. h1 -> h-1).
170+
function toPresetCssSlug(slug) {
171+
return String(slug).replace(/([a-zA-Z])(\d)/g, '$1-$2')
172+
}
173+
144174
// Quote map keys so slugs like black/white are strings, not Sass color literals.
145175
function formatMapKey(slug) {
146176
return JSON.stringify(String(slug))

‎package-lock.json‎

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
},
1717
"license": "GPL-2.0",
1818
"dependencies": {
19-
"@fontsource-utils/scss": "^0.2.4",
20-
"@fontsource/poppins": "^5.3.0",
2119
"lazysizes": "^5.3.2",
2220
"oneloop.js": "^5.3.1",
2321
"swiper": "^14.3.0"
@@ -27,8 +25,8 @@
2725
"@wordpress/browserslist-config": "^6.53.0",
2826
"@wordpress/dependency-extraction-webpack-plugin": "^6.53.0",
2927
"@wordpress/dom-ready": "^3.58.0",
30-
"@wordpress/i18n": "^4.58.0",
3128
"@wordpress/hooks": "^3.58.0",
29+
"@wordpress/i18n": "^4.58.0",
3230
"@wordpress/stylelint-config": "^24.2.0",
3331
"clean-webpack-plugin": "^4.0.0",
3432
"css-loader": "^7.1.4",
35.8 KB
Binary file not shown.
28.2 KB
Binary file not shown.

‎src/scss/01-abstract/_variables.scss‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,18 @@ $base-border-radius: 3px;
7171
// ----
7272
// Font Family
7373
// ----
74-
$font-family-primary: "Poppins", "Poppins-fallback", sans-serif;
74+
$font-family-primary: $settings-font-family-primary;
75+
$font-family-secondary: $settings-font-family-secondary;
7576

7677
// ----
7778
// Font Size
7879
// ----
79-
$font-size-base: var(--paragraph--font-size-default);
80-
$font-size-sm: var(--paragraph--font-size-small);
81-
$font-size-lg: var(--paragraph--font-size-large);
82-
$font-size-xl: var(--paragraph--font-size-huge);
80+
$font-size-base: $settings-font-size-default;
81+
$font-size-sm: $settings-font-size-small;
82+
$font-size-lg: $settings-font-size-large;
83+
$font-size-xl: $settings-font-size-huge;
8384

8485
// ----
8586
// Line Height
8687
// ----
87-
$line-height-base: var(--paragraph--line-height-default);
88+
$line-height-base: $settings-custom-line-height-default;

‎src/scss/02-tools/_m-heading.scss‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use "../01-abstract/variables" as *;
2+
@use "../01-abstract/theme-json" as *;
23

34
/**
45
* Heading - Used in src/scss/06-blocks/core/_heading.scss
@@ -20,8 +21,8 @@
2021
*
2122
* mixin :
2223
* @if $name == h3 {
23-
* font-size: var(--heading--font-size-h3);
24-
* line-height: var(--heading--line-height-h3);
24+
* font-size: $settings-font-size-h3;
25+
* line-height: $settings-custom-line-height-h3;
2526
*
2627
* @if $style == uppercase {
2728
* text-transform: uppercase;
@@ -44,36 +45,41 @@
4445
*/
4546

4647
@mixin heading($name: h1, $style: default) {
47-
font-family: $font-family-primary;
48-
font-weight: 400;
48+
font-family: $font-family-secondary;
4949

5050
@if $name == h1 {
51-
font-size: var(--heading--font-size-h1);
52-
line-height: var(--heading--line-height-h1);
51+
font-size: $settings-font-size-h1;
52+
font-weight: 500;
53+
line-height: $settings-custom-line-height-h1;
5354
}
5455

5556
@if $name == h2 {
56-
font-size: var(--heading--font-size-h2);
57-
line-height: var(--heading--line-height-h2);
57+
font-size: $settings-font-size-h2;
58+
font-weight: 500;
59+
line-height: $settings-custom-line-height-h2;
5860
}
5961

6062
@if $name == h3 {
61-
font-size: var(--heading--font-size-h3);
62-
line-height: var(--heading--line-height-h3);
63+
font-size: $settings-font-size-h3;
64+
font-weight: 500;
65+
line-height: $settings-custom-line-height-h3;
6366
}
6467

6568
@if $name == h4 {
66-
font-size: var(--heading--font-size-h4);
67-
line-height: var(--heading--line-height-h4);
69+
font-size: $settings-font-size-h4;
70+
font-weight: 500;
71+
line-height: $settings-custom-line-height-h4;
6872
}
6973

7074
@if $name == h5 {
71-
font-size: var(--heading--font-size-h5);
72-
line-height: var(--heading--line-height-h5);
75+
font-size: $settings-font-size-h5;
76+
font-weight: 500;
77+
line-height: $settings-custom-line-height-h5;
7378
}
7479

7580
@if $name == h6 {
76-
font-size: var(--heading--font-size-h6);
77-
line-height: var(--heading--line-height-h6);
81+
font-size: $settings-font-size-h6;
82+
font-weight: 500;
83+
line-height: $settings-custom-line-height-h6;
7884
}
7985
}

‎src/scss/02-tools/_m-text.scss‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
@use "../01-abstract/variables" as *;
2+
@use "../01-abstract/theme-json" as *;
3+
14
/**
25
* Text - Used in src/scss/06-blocks/core/_paragraph.scss and src/scss/03-base/_text.scss
36
*
@@ -15,26 +18,26 @@
1518

1619
@mixin text($name: default) {
1720
@if $name == default {
18-
font-size: var(--paragraph--font-size-default);
21+
font-size: $settings-font-size-default;
1922
font-weight: 400;
20-
line-height: var(--paragraph--line-height-default);
23+
line-height: $settings-custom-line-height-default;
2124
}
2225

2326
@if $name == small {
24-
font-size: var(--paragraph--font-size-small);
27+
font-size: $settings-font-size-small;
2528
font-weight: 400;
26-
line-height: var(--paragraph--line-height-small);
29+
line-height: $settings-custom-line-height-default;
2730
}
2831

2932
@if $name == large {
30-
font-size: var(--paragraph--font-size-large);
33+
font-size: $settings-font-size-large;
3134
font-weight: 400;
32-
line-height: var(--paragraph--line-height-large);
35+
line-height: $settings-custom-line-height-default;
3336
}
3437

3538
@if $name == huge {
36-
font-size: var(--paragraph--font-size-huge);
39+
font-size: $settings-font-size-huge;
3740
font-weight: 400;
38-
line-height: var(--paragraph--line-height-huge);
41+
line-height: $settings-custom-line-height-default;
3942
}
4043
}

‎src/scss/03-base/_fonts.scss‎

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,24 @@
11
/**
2-
* Fontsource
2+
* Web fonts
33
*
4-
* Fonts list : https://fontsource.org/
5-
* Documentation : https://fontsource.org/docs/getting-started/faces-mixin
4+
* Primary @font-face rules are declared in theme.json (fontFamilies.fontFace, variable woff2).
5+
* Metric fallbacks for CLS cannot live in theme.json (size-adjust / ascent-override).
66
*
7-
* Examples :
7+
* Project fonts: edit src/theme-json/typography.json (fontFace). Edge cases: @mixin declare-font-face in 02-tools.
88
*
9-
* 1 - Install the font and the utilities by the command :
10-
* yarn add @fontsource-utils/scss
11-
*
12-
* // For Classic font
13-
* yarn add @fontsource/myFont
14-
*
15-
* // For Variable font
16-
* yarn add @fontsource-variable/myFont
17-
*
18-
* 2 - Declare font-face :
19-
* // For Classic font
20-
* @use "@fontsource-utils/scss/src/mixins" as fontsource;
21-
* @use "@fontsource/myFont/scss/mixins" as MyFont;
22-
* @include fontsource.faces($metadata: MyFont.$metadata, $weights: (400, 700));
23-
* ...
24-
*
25-
* // For Variable font
26-
* @use "@fontsource-utils/scss/src/mixins" as fontsource;
27-
* @use "@fontsource-variable/myFont/scss/mixins" as MyFont;
28-
* @include fontsource.faces($metadata: MyFont.$metadata, $axes: wght);
29-
* ...
9+
* @see https://www.industrialempathy.com/perfect-ish-font-fallback/
3010
*/
3111

32-
@use "@fontsource-utils/scss/src/mixins" as fontsource;
33-
@use "@fontsource/poppins/scss/mixins" as Poppins;
34-
35-
@include fontsource.faces($metadata: Poppins.$metadata, $weights: (300, 400, 500, 700), $styles: normal);
36-
@include fontsource.faces($metadata: Poppins.$metadata, $weights: (300, 400, 500, 700), $styles: italic);
37-
38-
// Fallbacks for DM Sans to improve cls
39-
// https://deploy-preview-15--upbeat-shirley-608546.netlify.app/perfect-ish-font-fallback/?font=Poppins
4012
@font-face {
41-
font-family: Poppins-fallback;
13+
font-family: "SourceSans3-fallback";
4214
src: local("Arial");
43-
size-adjust: 112.5%;
44-
ascent-override: 109%;
15+
size-adjust: 100%;
16+
ascent-override: 105%;
4517
}
4618

47-
/**
48-
* Custom font here
49-
*
50-
* Examples :
51-
*
52-
* // For Classic font
53-
* @include declare-font-face("My classic font", "../fonts/gmy-classic-font-regular", 400);
54-
* @include declare-font-face("My classic font", "../fonts/gmy-classic-font-regular-italic", 400, italic);
55-
* @include declare-font-face("My classic font", "../fonts/gmy-classic-font-bold", 700);
56-
* ...
57-
*
58-
* // For Variable font
59-
* @include declare-font-face("My variable font", "../fonts/my-variable-font", 100 950, normal, normal, "woff2-variations");
60-
* ...
61-
*
62-
*/
19+
@font-face {
20+
font-family: Fraunces-fallback;
21+
src: local("Georgia");
22+
size-adjust: 100%;
23+
ascent-override: 95%;
24+
}

‎src/scss/03-base/_variables-css.scss‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@use "sass:map";
22
@use "../01-abstract/variables" as *;
3-
@use "../02-tools/f-fluid-size" as *;
43
@use "../02-tools/m-breakpoint" as *;
54
@use "../02-tools/m-reduced-motion" as *;
65

@@ -10,40 +9,6 @@
109
*/
1110
--breakpoint-mobile-to-desktop-nav: #{map.get($breakpoints, mobile-to-desktop-nav)}; // Used by JavaScript
1211

13-
/*
14-
* Heading
15-
*/
16-
// Font size
17-
--heading--font-size-h1: #{fluid-size(45px, 56px)};
18-
--heading--font-size-h2: #{fluid-size(32px, 48px)};
19-
--heading--font-size-h3: #{fluid-size(24px, 36px)};
20-
--heading--font-size-h4: #{fluid-size(20px, 32px)};
21-
--heading--font-size-h5: #{fluid-size(18px, 24px)};
22-
--heading--font-size-h6: #{fluid-size(16px, 18px)};
23-
24-
// Line height
25-
--heading--line-height-h1: 1.25;
26-
--heading--line-height-h2: 1.25;
27-
--heading--line-height-h3: 1.25;
28-
--heading--line-height-h4: 1.25;
29-
--heading--line-height-h5: 1.25;
30-
--heading--line-height-h6: 1.25;
31-
32-
/*
33-
* paragraph
34-
*/
35-
// Font size
36-
--paragraph--font-size-huge: #{fluid-size(28px, 32px)};
37-
--paragraph--font-size-large: #{fluid-size(20px, 24px)};
38-
--paragraph--font-size-small: #{fluid-size(12px, 14px)};
39-
--paragraph--font-size-default: #{fluid-size(14px, 16px)};
40-
41-
// line height
42-
--paragraph--line-height-huge: 1.4;
43-
--paragraph--line-height-large: 1.4;
44-
--paragraph--line-height-small: 1.4;
45-
--paragraph--line-height-default: 1.4;
46-
4712
/*
4813
* Admin bar
4914
*/

0 commit comments

Comments
 (0)