Skip to content

Commit 9d2efdb

Browse files
committed
Update plugin for Tailwind v4 support
1 parent 3774c91 commit 9d2efdb

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.changeset/thirty-pens-help.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tailwindcss-opentype": minor
3+
---
4+
5+
Update plugin for Tailwind v4 support
6+
7+
CSS output increased slightly for features that rely on the `font-feature-settings` property.

plugin/__tests__/plugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,36 +86,43 @@ describe('Plugin', () => {
8686
8787
.sups {
8888
--ot-sups: "sups" 1;
89+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
8990
font-feature-settings: var(--ot-features);
9091
}
9192
9293
.subs {
9394
--ot-subs: "subs" 1;
95+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
9496
font-feature-settings: var(--ot-features);
9597
}
9698
9799
.sinf {
98100
--ot-sinf: "sinf" 1;
101+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
99102
font-feature-settings: var(--ot-features);
100103
}
101104
102105
.hlig {
103106
--ot-hlig: "hlig" 1;
107+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
104108
font-feature-settings: var(--ot-features);
105109
}
106110
107111
.ss-01 {
108112
--ot-ss01: "ss01" 1;
113+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
109114
font-feature-settings: var(--ot-features);
110115
}
111116
112117
.ss-03 {
113118
--ot-ss03: "ss03" 1;
119+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
114120
font-feature-settings: var(--ot-features);
115121
}
116122
117123
.ss-named {
118124
--ot-ss02: "ss02" 1;
125+
--ot-features: var(--ot-sups), var(--ot-subs), var(--ot-sinf), var(--ot-hlig), var(--ot-salt), var(--ot-ss01), var(--ot-ss02), var(--ot-ss03);
119126
font-feature-settings: var(--ot-features);
120127
}
121128
`)

plugin/src/plugin.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import plugin from 'tailwindcss/plugin.js'
22

33
const JIT_FONT_FEATURE_DEFAULTS = {
4-
'@defaults font-feature-settings': {},
54
'font-feature-settings': 'var(--ot-features)',
65
}
76

@@ -68,7 +67,7 @@ const opentypePlugin = plugin.withOptions(
6867
}
6968

7069
addBase({
71-
'@defaults font-feature-settings': {
70+
':root, :host': {
7271
'--ot-sups': '"sups" 0',
7372
'--ot-subs': '"subs" 0',
7473
'--ot-sinf': '"sinf" 0',
@@ -86,25 +85,41 @@ const opentypePlugin = plugin.withOptions(
8685
},
8786
})
8887

88+
let fontFeatureProperties = {
89+
'--ot-features': [
90+
'var(--ot-sups)',
91+
'var(--ot-subs)',
92+
'var(--ot-sinf)',
93+
'var(--ot-hlig)',
94+
'var(--ot-salt)',
95+
...stylisticSetsProperties,
96+
].join(', '),
97+
}
98+
8999
addUtilities({
90100
'.sups': {
91101
'--ot-sups': '"sups" 1',
102+
...fontFeatureProperties,
92103
...JIT_FONT_FEATURE_DEFAULTS,
93104
},
94105
'.subs': {
95106
'--ot-subs': '"subs" 1',
107+
...fontFeatureProperties,
96108
...JIT_FONT_FEATURE_DEFAULTS,
97109
},
98110
'.sinf': {
99111
'--ot-sinf': '"sinf" 1',
112+
...fontFeatureProperties,
100113
...JIT_FONT_FEATURE_DEFAULTS,
101114
},
102115
'.hlig': {
103116
'--ot-hlig': '"hlig" 1',
117+
...fontFeatureProperties,
104118
...JIT_FONT_FEATURE_DEFAULTS,
105119
},
106120
'.salt': {
107121
'--ot-salt': '"salt" 1',
122+
...fontFeatureProperties,
108123
...JIT_FONT_FEATURE_DEFAULTS,
109124
},
110125
})
@@ -113,6 +128,7 @@ const opentypePlugin = plugin.withOptions(
113128
{
114129
ss: (value: string) => ({
115130
[`--ot-${value}`]: `"${value}" 1`,
131+
...fontFeatureProperties,
116132
...JIT_FONT_FEATURE_DEFAULTS,
117133
}),
118134
},

0 commit comments

Comments
 (0)