1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var values_1 = require("./values");
|
5 | var memoize_1 = require("./memoize");
|
6 | var is_string_1 = require("./is-string");
|
7 | var ctx;
|
8 |
|
9 |
|
10 |
|
11 | exports.default = memoize_1.default(function (text, font) {
|
12 | if (font === void 0) { font = {}; }
|
13 | var fontSize = font.fontSize, fontFamily = font.fontFamily, fontWeight = font.fontWeight, fontStyle = font.fontStyle, fontVariant = font.fontVariant;
|
14 | if (!ctx) {
|
15 | ctx = document.createElement('canvas').getContext('2d');
|
16 | }
|
17 | ctx.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
|
18 | return ctx.measureText(is_string_1.default(text) ? text : '').width;
|
19 | }, function (text, font) {
|
20 | if (font === void 0) { font = {}; }
|
21 | return tslib_1.__spreadArrays([text], values_1.default(font)).join('');
|
22 | });
|
23 |
|
\ | No newline at end of file |