Skip to content

Commit 604ba4f

Browse files
committed
fix(is-ligature-icon): rename canvas to canvasContext (#1880)
1 parent 1ff5444 commit 604ba4f

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

lib/commons/text/is-icon-ligature.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ text.isIconLigature = function(
8282
return false;
8383
}
8484

85-
if (!axe._cache.get('context')) {
85+
if (!axe._cache.get('canvasContext')) {
8686
axe._cache.set(
87-
'context',
87+
'canvasContext',
8888
document.createElement('canvas').getContext('2d')
8989
);
9090
}
91-
const context = axe._cache.get('context');
92-
const canvas = context.canvas;
91+
const canvasContext = axe._cache.get('canvasContext');
92+
const canvas = canvasContext.canvas;
9393

9494
// keep track of each font encountered and the number of times it shows up
9595
// as a ligature.
@@ -138,9 +138,9 @@ text.isIconLigature = function(
138138
let fontStyle = `${fontSize}px ${fontFamily}`;
139139

140140
// set the size of the canvas to the width of the first letter
141-
context.font = fontStyle;
141+
canvasContext.font = fontStyle;
142142
const firstChar = nodeValue.charAt(0);
143-
let width = context.measureText(firstChar).width;
143+
let width = canvasContext.measureText(firstChar).width;
144144

145145
// ensure font meets the 30px width requirement (30px font-size doesn't
146146
// necessarily mean its 30px wide when drawn)
@@ -155,12 +155,12 @@ text.isIconLigature = function(
155155

156156
// changing the dimensions of a canvas resets all properties (include font)
157157
// and clears it
158-
context.font = fontStyle;
159-
context.textAlign = 'left';
160-
context.textBaseline = 'top';
161-
context.fillText(firstChar, 0, 0);
158+
canvasContext.font = fontStyle;
159+
canvasContext.textAlign = 'left';
160+
canvasContext.textBaseline = 'top';
161+
canvasContext.fillText(firstChar, 0, 0);
162162
const compareData = new Uint32Array(
163-
context.getImageData(0, 0, width, fontSize).data.buffer
163+
canvasContext.getImageData(0, 0, width, fontSize).data.buffer
164164
);
165165

166166
// if the font doesn't even have character data for a single char then
@@ -170,10 +170,10 @@ text.isIconLigature = function(
170170
return true;
171171
}
172172

173-
context.clearRect(0, 0, width, fontSize);
174-
context.fillText(nodeValue, 0, 0);
173+
canvasContext.clearRect(0, 0, width, fontSize);
174+
canvasContext.fillText(nodeValue, 0, 0);
175175
const compareWith = new Uint32Array(
176-
context.getImageData(0, 0, width, fontSize).data.buffer
176+
canvasContext.getImageData(0, 0, width, fontSize).data.buffer
177177
);
178178

179179
// calculate the number of differences between the first letter and the
@@ -191,9 +191,9 @@ text.isIconLigature = function(
191191
// calculate the difference between the width of each character and the
192192
// combined with of all characters
193193
const expectedWidth = nodeValue.split('').reduce((width, char) => {
194-
return width + context.measureText(char).width;
194+
return width + canvasContext.measureText(char).width;
195195
}, 0);
196-
const actualWidth = context.measureText(nodeValue).width;
196+
const actualWidth = canvasContext.measureText(nodeValue).width;
197197

198198
const pixelDifference = differences / compareData.length;
199199
const sizeDifference = 1 - actualWidth / expectedWidth;

0 commit comments

Comments
 (0)