@flourish/pocket-knife
Advanced tools
Comparing version
{ | ||
"name": "@flourish/pocket-knife", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Flourish module with handy tools", | ||
@@ -5,0 +5,0 @@ "main": "pocket-knife.js", |
@@ -0,1 +1,4 @@ | ||
### 0.3.2 | ||
* Change `this` in `getTextWidth()` | ||
### 0.3.1 | ||
@@ -2,0 +5,0 @@ * Export `getTextWidth()` |
@@ -1,8 +0,9 @@ | ||
function getTextWidth(text, font) { | ||
var canvas = this.canvas || (this.canvas = document.createElement("canvas")); | ||
var context = canvas.getContext("2d"); | ||
context.font = font || "10px sans-serif"; | ||
var metrics = context.measureText(text); | ||
return metrics.width; | ||
} | ||
var getTextWidth = (function() { | ||
var context = document.createElement("canvas").getContext("2d"); | ||
return function(text, font) { | ||
context.font = font || "10px sans-serif"; | ||
var metrics = context.measureText(text); | ||
return metrics.width; | ||
}; | ||
})(); | ||
@@ -9,0 +10,0 @@ function isImage(string) { |
2916
1.14%39
2.63%