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

Commit 35d49f0

Browse files
author
mapgrid
committed
add text rendering utilities - fixes #11
1 parent 1e333ea commit 35d49f0

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
@@ -125,6 +125,17 @@ module.exports = plugin.withOptions(function(options = {}) {
125125
})
126126
);
127127

128+
const textRenderingUtilities = _.fromPairs(
129+
_.map(theme('textRendering'), (value, modifier) => {
130+
return [
131+
`.${e(`text-${modifier}`)}`,
132+
{
133+
textRendering: value,
134+
},
135+
];
136+
})
137+
);
138+
128139
const textStylesTheme = theme('textStyles');
129140

130141
const resolveTextStyle = function(styles) {
@@ -168,6 +179,7 @@ module.exports = plugin.withOptions(function(options = {}) {
168179
addUtilities(fontVariantCapsUtilities, variants('fontVariantCaps'));
169180
addUtilities(fontVariantNumericUtilities, variants('fontVariantNumeric'));
170181
addUtilities(fontVariantLigaturesUtilities, variants('fontVariantLigatures'));
182+
addUtilities(textRenderingUtilities, variants('textRendering'));
171183
addComponents(textStyles);
172184
};
173185
}, function() {
@@ -206,6 +218,12 @@ module.exports = plugin.withOptions(function(options = {}) {
206218
'contextual': 'contextual',
207219
'no-contextual': 'no-contextual',
208220
},
221+
textRendering: {
222+
'rendering-auto': 'auto',
223+
'optimize-legibility': 'optimizeLegibility',
224+
'optimize-speed': 'optimizeSpeed',
225+
'geometric-precision': 'geometricPrecision'
226+
},
209227
textStyles: {},
210228
},
211229
variants: {
@@ -217,6 +235,7 @@ module.exports = plugin.withOptions(function(options = {}) {
217235
fontVariantCaps: ['responsive'],
218236
fontVariantNumeric: ['responsive'],
219237
fontVariantLigatures: ['responsive'],
238+
textRendering: ['responsive'],
220239
},
221240
};
222241
});

test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ test('the plugin generates some utilities and responsive variants by default', (
152152
.ligatures-no-contextual {
153153
font-variant-ligatures: no-contextual;
154154
}
155+
.text-rendering-auto {
156+
text-rendering: auto;
157+
}
158+
.text-optimize-legibility {
159+
text-rendering: optimizeLegibility;
160+
}
161+
.text-optimize-speed {
162+
text-rendering: optimizeSpeed;
163+
}
164+
.text-geometric-precision {
165+
text-rendering: geometricPrecision;
166+
}
155167
@media (min-width: 640px) {
156168
.sm\\:ellipsis {
157169
text-overflow: ellipsis;
@@ -270,6 +282,18 @@ test('the plugin generates some utilities and responsive variants by default', (
270282
.sm\\:ligatures-no-contextual {
271283
font-variant-ligatures: no-contextual;
272284
}
285+
.sm\\:text-rendering-auto {
286+
text-rendering: auto;
287+
}
288+
.sm\\:text-optimize-legibility {
289+
text-rendering: optimizeLegibility;
290+
}
291+
.sm\\:text-optimize-speed {
292+
text-rendering: optimizeSpeed;
293+
}
294+
.sm\\:text-geometric-precision {
295+
text-rendering: geometricPrecision;
296+
}
273297
}
274298
`);
275299
});
@@ -281,6 +305,7 @@ test('the font variant utilities can be disabled', () => {
281305
fontVariantCaps: {},
282306
fontVariantNumeric: {},
283307
fontVariantLigatures: {},
308+
textRendering: {},
284309
},
285310
variants: {
286311
ellipsis: [],
@@ -341,6 +366,7 @@ test('the ellipsis, hyphens, and text unset utilities can be disabled', () => {
341366
fontVariantCaps: {},
342367
fontVariantNumeric: {},
343368
fontVariantLigatures: {},
369+
textRendering: {},
344370
},
345371
}, {
346372
ellipsis: false,
@@ -365,6 +391,7 @@ test('the text indent and text shadow utilities can be customized', () => {
365391
fontVariantCaps: {},
366392
fontVariantNumeric: {},
367393
fontVariantLigatures: {},
394+
textRendering: {},
368395
},
369396
variants: {
370397
textIndent: [],
@@ -411,6 +438,7 @@ test('the font variant utilities can be extended', () => {
411438
fontVariantCaps: [],
412439
fontVariantNumeric: [],
413440
fontVariantLigatures: [],
441+
textRendering: [],
414442
},
415443
}, {
416444
ellipsis: false,
@@ -502,6 +530,18 @@ test('the font variant utilities can be extended', () => {
502530
.ligatures-revert {
503531
font-variant-ligatures: revert;
504532
}
533+
.text-rendering-auto {
534+
text-rendering: auto;
535+
}
536+
.text-optimize-legibility {
537+
text-rendering: optimizeLegibility;
538+
}
539+
.text-optimize-speed {
540+
text-rendering: optimizeSpeed;
541+
}
542+
.text-geometric-precision {
543+
text-rendering: geometricPrecision;
544+
}
505545
`);
506546
});
507547
});
@@ -536,6 +576,7 @@ test('text style components can be generated', () => {
536576
fontVariantCaps: {},
537577
fontVariantNumeric: {},
538578
fontVariantLigatures: {},
579+
textRendering: {},
539580
},
540581
}, {
541582
ellipsis: false,
@@ -576,6 +617,7 @@ test('the component prefix can be customized', () => {
576617
fontVariantCaps: {},
577618
fontVariantNumeric: {},
578619
fontVariantLigatures: {},
620+
textRendering: {},
579621
},
580622
}, {
581623
ellipsis: false,
@@ -630,6 +672,7 @@ test('text styles can extend other text styles', () => {
630672
fontVariantCaps: {},
631673
fontVariantNumeric: {},
632674
fontVariantLigatures: {},
675+
textRendering: {},
633676
},
634677
}, {
635678
ellipsis: false,
@@ -708,6 +751,7 @@ test('text styles can extend more than one other text style', () => {
708751
fontVariantCaps: {},
709752
fontVariantNumeric: {},
710753
fontVariantLigatures: {},
754+
textRendering: {},
711755
},
712756
}, {
713757
ellipsis: false,
@@ -803,6 +847,7 @@ test('text style components can style their children', () => {
803847
fontVariantCaps: {},
804848
fontVariantNumeric: {},
805849
fontVariantLigatures: {},
850+
textRendering: {},
806851
},
807852
}, {
808853
ellipsis: false,
@@ -901,6 +946,7 @@ test('text styles can be responsive', () => {
901946
fontVariantCaps: {},
902947
fontVariantNumeric: {},
903948
fontVariantLigatures: {},
949+
textRendering: {},
904950
},
905951
}, {
906952
ellipsis: false,
@@ -979,6 +1025,7 @@ test('text styles can be set to not be output', () => {
9791025
fontVariantCaps: {},
9801026
fontVariantNumeric: {},
9811027
fontVariantLigatures: {},
1028+
textRendering: {},
9821029
},
9831030
}, {
9841031
ellipsis: false,
@@ -1094,6 +1141,7 @@ test('all these options can be used to generate a full-featured rich text compon
10941141
fontVariantCaps: {},
10951142
fontVariantNumeric: {},
10961143
fontVariantLigatures: {},
1144+
textRendering: {},
10971145
},
10981146
}, {
10991147
ellipsis: false,
@@ -1179,6 +1227,7 @@ test('variants can be customized', () => {
11791227
fontVariantCaps: ['focus', 'responsive'],
11801228
fontVariantNumeric: ['group-hover'],
11811229
fontVariantLigatures: [],
1230+
textRendering: [],
11821231
},
11831232
}).then(css => {
11841233
expect(css).toMatchCss(`
@@ -1359,6 +1408,18 @@ test('variants can be customized', () => {
13591408
.ligatures-no-contextual {
13601409
font-variant-ligatures: no-contextual;
13611410
}
1411+
.text-rendering-auto {
1412+
text-rendering: auto;
1413+
}
1414+
.text-optimize-legibility {
1415+
text-rendering: optimizeLegibility;
1416+
}
1417+
.text-optimize-speed {
1418+
text-rendering: optimizeSpeed;
1419+
}
1420+
.text-geometric-precision {
1421+
text-rendering: geometricPrecision;
1422+
}
13621423
@media (min-width: 640px) {
13631424
.sm\\:caps-normal {
13641425
font-variant-caps: normal;

0 commit comments

Comments
 (0)