Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 05c2c6c

Browse files
authored
Merge pull request #14 from mapgrid/feat/text-rendering-next
Add text-rendering utilities
2 parents 5bc33ba + 35d49f0 commit 05c2c6c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ module.exports = plugin.withOptions(function(options = {}) {
138138
})
139139
);
140140

141+
const textRenderingUtilities = _.fromPairs(
142+
_.map(theme('textRendering'), (value, modifier) => {
143+
return [
144+
`.${e(`text-${modifier}`)}`,
145+
{
146+
textRendering: value,
147+
},
148+
];
149+
})
150+
);
151+
141152
const textStylesTheme = theme('textStyles');
142153

143154
const resolveTextStyle = function(styles) {
@@ -182,6 +193,7 @@ module.exports = plugin.withOptions(function(options = {}) {
182193
addUtilities(fontVariantCapsUtilities, variants('fontVariantCaps'));
183194
addUtilities(fontVariantNumericUtilities, variants('fontVariantNumeric'));
184195
addUtilities(fontVariantLigaturesUtilities, variants('fontVariantLigatures'));
196+
addUtilities(textRenderingUtilities, variants('textRendering'));
185197
addComponents(textStyles);
186198
};
187199
}, function() {
@@ -220,6 +232,12 @@ module.exports = plugin.withOptions(function(options = {}) {
220232
'contextual': 'contextual',
221233
'no-contextual': 'no-contextual',
222234
},
235+
textRendering: {
236+
'rendering-auto': 'auto',
237+
'optimize-legibility': 'optimizeLegibility',
238+
'optimize-speed': 'optimizeSpeed',
239+
'geometric-precision': 'geometricPrecision'
240+
},
223241
textStyles: {},
224242
},
225243
variants: {
@@ -232,6 +250,7 @@ module.exports = plugin.withOptions(function(options = {}) {
232250
fontVariantCaps: ['responsive'],
233251
fontVariantNumeric: ['responsive'],
234252
fontVariantLigatures: ['responsive'],
253+
textRendering: ['responsive'],
235254
},
236255
};
237256
});

test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ test('the plugin generates some utilities and responsive variants by default', (
161161
.ligatures-no-contextual {
162162
font-variant-ligatures: no-contextual;
163163
}
164+
.text-rendering-auto {
165+
text-rendering: auto;
166+
}
167+
.text-optimize-legibility {
168+
text-rendering: optimizeLegibility;
169+
}
170+
.text-optimize-speed {
171+
text-rendering: optimizeSpeed;
172+
}
173+
.text-geometric-precision {
174+
text-rendering: geometricPrecision;
175+
}
164176
@media (min-width: 640px) {
165177
.sm\\:ellipsis {
166178
text-overflow: ellipsis;
@@ -288,6 +300,18 @@ test('the plugin generates some utilities and responsive variants by default', (
288300
.sm\\:ligatures-no-contextual {
289301
font-variant-ligatures: no-contextual;
290302
}
303+
.sm\\:text-rendering-auto {
304+
text-rendering: auto;
305+
}
306+
.sm\\:text-optimize-legibility {
307+
text-rendering: optimizeLegibility;
308+
}
309+
.sm\\:text-optimize-speed {
310+
text-rendering: optimizeSpeed;
311+
}
312+
.sm\\:text-geometric-precision {
313+
text-rendering: geometricPrecision;
314+
}
291315
}
292316
`);
293317
});
@@ -299,6 +323,7 @@ test('the font variant utilities can be disabled', () => {
299323
fontVariantCaps: {},
300324
fontVariantNumeric: {},
301325
fontVariantLigatures: {},
326+
textRendering: {},
302327
},
303328
variants: {
304329
ellipsis: [],
@@ -369,6 +394,7 @@ test('the ellipsis, hyphens, and text unset utilities can be disabled', () => {
369394
fontVariantCaps: {},
370395
fontVariantNumeric: {},
371396
fontVariantLigatures: {},
397+
textRendering: {},
372398
},
373399
}, {
374400
ellipsis: false,
@@ -394,6 +420,7 @@ test('the text indent and text shadow utilities can be customized', () => {
394420
fontVariantCaps: {},
395421
fontVariantNumeric: {},
396422
fontVariantLigatures: {},
423+
textRendering: {},
397424
},
398425
variants: {
399426
textIndent: [],
@@ -441,6 +468,7 @@ test('the font variant utilities can be extended', () => {
441468
fontVariantCaps: [],
442469
fontVariantNumeric: [],
443470
fontVariantLigatures: [],
471+
textRendering: [],
444472
},
445473
}, {
446474
ellipsis: false,
@@ -533,6 +561,18 @@ test('the font variant utilities can be extended', () => {
533561
.ligatures-revert {
534562
font-variant-ligatures: revert;
535563
}
564+
.text-rendering-auto {
565+
text-rendering: auto;
566+
}
567+
.text-optimize-legibility {
568+
text-rendering: optimizeLegibility;
569+
}
570+
.text-optimize-speed {
571+
text-rendering: optimizeSpeed;
572+
}
573+
.text-geometric-precision {
574+
text-rendering: geometricPrecision;
575+
}
536576
`);
537577
});
538578
});
@@ -567,6 +607,7 @@ test('text style components can be generated', () => {
567607
fontVariantCaps: {},
568608
fontVariantNumeric: {},
569609
fontVariantLigatures: {},
610+
textRendering: {},
570611
},
571612
}, {
572613
ellipsis: false,
@@ -608,6 +649,7 @@ test('the component prefix can be customized', () => {
608649
fontVariantCaps: {},
609650
fontVariantNumeric: {},
610651
fontVariantLigatures: {},
652+
textRendering: {},
611653
},
612654
}, {
613655
ellipsis: false,
@@ -663,6 +705,7 @@ test('text styles can extend other text styles', () => {
663705
fontVariantCaps: {},
664706
fontVariantNumeric: {},
665707
fontVariantLigatures: {},
708+
textRendering: {},
666709
},
667710
}, {
668711
ellipsis: false,
@@ -742,6 +785,7 @@ test('text styles can extend more than one other text style', () => {
742785
fontVariantCaps: {},
743786
fontVariantNumeric: {},
744787
fontVariantLigatures: {},
788+
textRendering: {},
745789
},
746790
}, {
747791
ellipsis: false,
@@ -838,6 +882,7 @@ test('text style components can style their children', () => {
838882
fontVariantCaps: {},
839883
fontVariantNumeric: {},
840884
fontVariantLigatures: {},
885+
textRendering: {},
841886
},
842887
}, {
843888
ellipsis: false,
@@ -937,6 +982,7 @@ test('text styles can be responsive', () => {
937982
fontVariantCaps: {},
938983
fontVariantNumeric: {},
939984
fontVariantLigatures: {},
985+
textRendering: {},
940986
},
941987
}, {
942988
ellipsis: false,
@@ -1016,6 +1062,7 @@ test('text styles can be set to not be output', () => {
10161062
fontVariantCaps: {},
10171063
fontVariantNumeric: {},
10181064
fontVariantLigatures: {},
1065+
textRendering: {},
10191066
},
10201067
}, {
10211068
ellipsis: false,
@@ -1132,6 +1179,7 @@ test('all these options can be used to generate a full-featured rich text compon
11321179
fontVariantCaps: {},
11331180
fontVariantNumeric: {},
11341181
fontVariantLigatures: {},
1182+
textRendering: {},
11351183
},
11361184
}, {
11371185
ellipsis: false,
@@ -1219,6 +1267,7 @@ test('variants can be customized', () => {
12191267
fontVariantCaps: ['focus', 'responsive'],
12201268
fontVariantNumeric: ['group-hover'],
12211269
fontVariantLigatures: [],
1270+
textRendering: [],
12221271
},
12231272
}).then(css => {
12241273
expect(css).toMatchCss(`
@@ -1417,6 +1466,18 @@ test('variants can be customized', () => {
14171466
.ligatures-no-contextual {
14181467
font-variant-ligatures: no-contextual;
14191468
}
1469+
.text-rendering-auto {
1470+
text-rendering: auto;
1471+
}
1472+
.text-optimize-legibility {
1473+
text-rendering: optimizeLegibility;
1474+
}
1475+
.text-optimize-speed {
1476+
text-rendering: optimizeSpeed;
1477+
}
1478+
.text-geometric-precision {
1479+
text-rendering: geometricPrecision;
1480+
}
14201481
@media (min-width: 640px) {
14211482
.sm\\:caps-normal {
14221483
font-variant-caps: normal;

0 commit comments

Comments
 (0)