@visactor/vutils 0.16.8-alpha.1 → 0.16.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/common/ascending.js +2 -1
- package/cjs/common/getType.js +1 -2
- package/cjs/common/isArrayLike.js +2 -1
- package/cjs/common/isObject.js +1 -2
- package/cjs/common/isShallowEqual.js +2 -1
- package/cjs/common/isUndefined.js +1 -1
- package/cjs/common/isValid.js +1 -1
- package/cjs/common/isValidNumber.js +1 -1
- package/cjs/common/isValidUrl.js +1 -1
- package/cjs/common/lowerFirst.js +1 -1
- package/cjs/data-structure/bounds.js +1 -1
- package/cjs/data-structure/hashTable.js +1 -2
- package/cjs/data-structure/index.js +1 -1
- package/cjs/data-structure/matrix.js +1 -1
- package/cjs/data-structure/point.js +1 -1
- package/es/common/ascending.js +2 -1
- package/es/common/getType.js +1 -2
- package/es/common/isArrayLike.js +2 -1
- package/es/common/isObject.js +1 -2
- package/es/common/isShallowEqual.js +2 -1
- package/es/common/isUndefined.js +1 -1
- package/es/common/isValid.js +1 -1
- package/es/common/isValidNumber.js +1 -1
- package/es/common/isValidUrl.js +1 -1
- package/es/common/lowerFirst.js +1 -1
- package/es/data-structure/bounds.js +1 -1
- package/es/data-structure/hashTable.js +1 -2
- package/es/data-structure/index.js +1 -1
- package/es/data-structure/matrix.js +1 -1
- package/es/data-structure/point.js +1 -1
- package/package.json +3 -3
- package/cjs/graphics/text/measure/test.d.ts +0 -14
- package/cjs/graphics/text/measure/test.js +0 -67
- package/cjs/graphics/text/measure/test.js.map +0 -1
- package/es/graphics/text/measure/test.d.ts +0 -14
- package/es/graphics/text/measure/test.js +0 -65
- package/es/graphics/text/measure/test.js.map +0 -1
package/cjs/common/ascending.js
CHANGED
package/cjs/common/getType.js
CHANGED
package/cjs/common/isObject.js
CHANGED
package/cjs/common/isValid.js
CHANGED
package/cjs/common/isValidUrl.js
CHANGED
|
@@ -7,4 +7,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
const isValidUrl = value => new RegExp(/^(http(s)?:\/\/)\w+[^\s]+(\.[^\s]+){1,}$/).test(value);
|
|
8
8
|
|
|
9
9
|
exports.isValidUrl = isValidUrl, exports.default = exports.isValidUrl;
|
|
10
|
-
//# sourceMappingURL=isValidUrl.js.map
|
|
10
|
+
//# sourceMappingURL=isValidUrl.js.map
|
package/cjs/common/lowerFirst.js
CHANGED
|
@@ -19,4 +19,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
19
19
|
value: !0
|
|
20
20
|
}), __exportStar(require("./hashTable"), exports), __exportStar(require("./point"), exports),
|
|
21
21
|
__exportStar(require("./bounds"), exports), __exportStar(require("./matrix"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
package/es/common/ascending.js
CHANGED
package/es/common/getType.js
CHANGED
package/es/common/isArrayLike.js
CHANGED
package/es/common/isObject.js
CHANGED
package/es/common/isUndefined.js
CHANGED
package/es/common/isValid.js
CHANGED
package/es/common/isValidUrl.js
CHANGED
package/es/common/lowerFirst.js
CHANGED
|
@@ -103,4 +103,4 @@ export function normalTransform(out, origin, x, y, scaleX, scaleY, angle, rotate
|
|
|
103
103
|
out.e = oe + oa * rotateCenterX + oc * rotateCenterY - a1 * offsetX - c1 * offsetY,
|
|
104
104
|
out.f = of + ob * rotateCenterX + od * rotateCenterY - b1 * offsetX - d1 * offsetY;
|
|
105
105
|
}
|
|
106
|
-
//# sourceMappingURL=matrix.js.map
|
|
106
|
+
//# sourceMappingURL=matrix.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vutils",
|
|
3
|
-
"version": "0.16.8
|
|
3
|
+
"version": "0.16.8",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "es/index.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"typescript": "4.9.5",
|
|
29
29
|
"@types/node": "*",
|
|
30
30
|
"@internal/bundler": "0.0.1",
|
|
31
|
-
"@internal/
|
|
31
|
+
"@internal/eslint-config": "0.0.1",
|
|
32
32
|
"@internal/ts-config": "0.0.1",
|
|
33
|
-
"@internal/
|
|
33
|
+
"@internal/jest-config": "0.0.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"eventemitter3": "^4.0.7",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ITextMeasureSpec, ITextSize, TextMeasureMethod } from './interface';
|
|
2
|
-
import { TextMeasure } from './textMeasure';
|
|
3
|
-
export declare const getTestNumbers: (length: number) => string;
|
|
4
|
-
export declare const getTestWord: (length: number) => string;
|
|
5
|
-
export declare class TestTextMeasure<T extends Partial<ITextMeasureSpec>> extends TextMeasure<T> {
|
|
6
|
-
test(methods?: TextMeasureMethod[], getStrCallback?: () => string, count?: number): {
|
|
7
|
-
report: Record<string, {
|
|
8
|
-
errMean?: ITextSize;
|
|
9
|
-
errVar?: ITextSize;
|
|
10
|
-
time: number;
|
|
11
|
-
}>;
|
|
12
|
-
textArr: string[];
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: !0
|
|
5
|
-
}), exports.TestTextMeasure = exports.getTestWord = exports.getTestNumbers = void 0;
|
|
6
|
-
|
|
7
|
-
const common_1 = require("../../../common"), textMeasure_1 = require("./textMeasure"), getNumberChar = () => TestTextMeasure.NUMBERS_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.NUMBERS_CHAR_SET.length)], getTestNumbers = length => Array(length).fill(0).map(getNumberChar).join("");
|
|
8
|
-
|
|
9
|
-
exports.getTestNumbers = getTestNumbers;
|
|
10
|
-
|
|
11
|
-
const getLetterChar = () => TestTextMeasure.ALPHABET_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.ALPHABET_CHAR_SET.length)], getTestWord = length => Array(length).fill(0).map(getLetterChar).join("");
|
|
12
|
-
|
|
13
|
-
exports.getTestWord = getTestWord;
|
|
14
|
-
|
|
15
|
-
class TestTextMeasure extends textMeasure_1.TextMeasure {
|
|
16
|
-
test(methods, getStrCallback, count) {
|
|
17
|
-
const mean = numbers => (numbers => numbers.reduce(((sum, cur) => sum + cur), 0))(numbers) / numbers.length, variance = numbers => {
|
|
18
|
-
const m = mean(numbers);
|
|
19
|
-
return mean(numbers.map((num => Math.pow(num - m, 2))));
|
|
20
|
-
}, callback = null != getStrCallback ? getStrCallback : () => `测试${(0, exports.getTestWord)(8)} ${(0,
|
|
21
|
-
exports.getTestNumbers)(4)}/${(0, exports.getTestNumbers)(2)}-${(0, exports.getTestNumbers)(2)}`, textArr = Array(null != count ? count : 1e5).fill(0).map(callback), methodMap = {
|
|
22
|
-
canopus: this.fullMeasure.bind(this),
|
|
23
|
-
canvas: this.measureWithNaiveCanvas.bind(this),
|
|
24
|
-
simple: this.quickMeasureWithoutCanvas.bind(this),
|
|
25
|
-
quick: this.quickMeasure.bind(this),
|
|
26
|
-
old: text => {
|
|
27
|
-
if ((0, common_1.isNil)(text)) return {
|
|
28
|
-
width: 0,
|
|
29
|
-
height: 0
|
|
30
|
-
};
|
|
31
|
-
const str = text.toString(), {fontSize: fontSize} = this.textSpec;
|
|
32
|
-
return {
|
|
33
|
-
width: .8 * fontSize * str.length,
|
|
34
|
-
height: fontSize
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}, methodList = null != methods ? methods : Object.keys(methodMap), report = {}, timetmp = performance.now(), standardResult = textArr.map(this._standardMethod), standardTime = performance.now() - timetmp;
|
|
38
|
-
return report.standard = {
|
|
39
|
-
time: standardTime
|
|
40
|
-
}, methodList.forEach((method => {
|
|
41
|
-
const testMethod = methodMap[method];
|
|
42
|
-
if (testMethod) {
|
|
43
|
-
const timetmp = performance.now(), testResult = textArr.map(testMethod), testTime = performance.now() - timetmp, errList = textArr.map(((_, i) => ({
|
|
44
|
-
width: testResult[i].width - standardResult[i].width,
|
|
45
|
-
height: testResult[i].height - standardResult[i].height
|
|
46
|
-
})));
|
|
47
|
-
report[method] = {
|
|
48
|
-
errMean: {
|
|
49
|
-
width: mean(errList.map((e => e.width))),
|
|
50
|
-
height: mean(errList.map((e => e.height)))
|
|
51
|
-
},
|
|
52
|
-
errVar: {
|
|
53
|
-
width: variance(errList.map((e => e.width))),
|
|
54
|
-
height: variance(errList.map((e => e.height)))
|
|
55
|
-
},
|
|
56
|
-
time: testTime
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
})), {
|
|
60
|
-
report: report,
|
|
61
|
-
textArr: textArr
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
exports.TestTextMeasure = TestTextMeasure;
|
|
67
|
-
//# sourceMappingURL=test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphics/text/measure/test.ts"],"names":[],"mappings":";;;AAAA,4CAAwC;AAExC,+CAA4C;AAE5C,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,OAAO,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,eAAe,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/G,CAAC,CAAC;AACK,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAAvF,QAAA,cAAc,kBAAyE;AAEpG,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,OAAO,eAAe,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG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AAO;SACR,CAAC;IACJ,CAAC;CACF;AAvFD,0CAuFC","file":"test.js","sourcesContent":["import { isNil } from '../../../common';\nimport type { ITextMeasureSpec, ITextSize, TextMeasureMethod } from './interface';\nimport { TextMeasure } from './textMeasure';\n\nconst getNumberChar = () => {\n return TestTextMeasure.NUMBERS_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.NUMBERS_CHAR_SET.length)];\n};\nexport const getTestNumbers = (length: number) => Array(length).fill(0).map(getNumberChar).join('');\n\nconst getLetterChar = () => {\n return TestTextMeasure.ALPHABET_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.ALPHABET_CHAR_SET.length)];\n};\nexport const getTestWord = (length: number) => Array(length).fill(0).map(getLetterChar).join('');\n\nexport class TestTextMeasure<T extends Partial<ITextMeasureSpec>> extends TextMeasure<T> {\n /** 测试方法 */\n test(methods?: TextMeasureMethod[], getStrCallback?: () => string, count?: number) {\n const sub = (numbers: number[]) => numbers.reduce((sum, cur) => sum + cur, 0);\n const mean = (numbers: number[]) => sub(numbers) / numbers.length;\n const variance = (numbers: number[]) => {\n const m = mean(numbers);\n return mean(numbers.map(num => Math.pow(num - m, 2)));\n };\n\n const callback =\n getStrCallback ?? (() => `测试${getTestWord(8)} ${getTestNumbers(4)}/${getTestNumbers(2)}-${getTestNumbers(2)}`);\n // 测试文本\n const textArr = Array(count ?? 100000)\n .fill(0)\n .map(callback);\n\n const methodMap: Record<string, (text: number | string) => ITextSize> = {\n canopus: this.fullMeasure.bind(this),\n canvas: this.measureWithNaiveCanvas.bind(this),\n simple: this.quickMeasureWithoutCanvas.bind(this),\n quick: this.quickMeasure.bind(this),\n old: (text: number | string) => {\n if (isNil(text)) {\n return { width: 0, height: 0 };\n }\n const str = text.toString();\n const { fontSize } = this.textSpec;\n return {\n width: fontSize * 0.8 * str.length,\n height: fontSize\n };\n }\n };\n const methodList = methods ?? Object.keys(methodMap);\n\n const report: Record<\n keyof typeof methodMap,\n {\n errMean?: ITextSize;\n errVar?: ITextSize;\n time: number;\n }\n > = {} as any;\n\n // 标准方法\n const timetmp = performance.now();\n const standardResult = textArr.map(this._standardMethod);\n const standardTime = performance.now() - timetmp;\n report.standard = {\n time: standardTime\n };\n\n // 测试方法\n methodList.forEach(method => {\n const testMethod = methodMap[method];\n if (testMethod) {\n const timetmp = performance.now();\n const testResult = textArr.map(testMethod as (text: number | string) => ITextSize);\n const testTime = performance.now() - timetmp;\n // 计算误差\n const errList = textArr.map(\n (_, i) =>\n ({\n width: testResult[i].width - standardResult[i].width,\n height: testResult[i].height - standardResult[i].height\n } as ITextSize)\n );\n report[method] = {\n errMean: {\n width: mean(errList.map(e => e.width)),\n height: mean(errList.map(e => e.height))\n },\n errVar: {\n width: variance(errList.map(e => e.width)),\n height: variance(errList.map(e => e.height))\n },\n time: testTime\n };\n }\n });\n\n return {\n report,\n textArr\n };\n }\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ITextMeasureSpec, ITextSize, TextMeasureMethod } from './interface';
|
|
2
|
-
import { TextMeasure } from './textMeasure';
|
|
3
|
-
export declare const getTestNumbers: (length: number) => string;
|
|
4
|
-
export declare const getTestWord: (length: number) => string;
|
|
5
|
-
export declare class TestTextMeasure<T extends Partial<ITextMeasureSpec>> extends TextMeasure<T> {
|
|
6
|
-
test(methods?: TextMeasureMethod[], getStrCallback?: () => string, count?: number): {
|
|
7
|
-
report: Record<string, {
|
|
8
|
-
errMean?: ITextSize;
|
|
9
|
-
errVar?: ITextSize;
|
|
10
|
-
time: number;
|
|
11
|
-
}>;
|
|
12
|
-
textArr: string[];
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { isNil } from "../../../common";
|
|
2
|
-
|
|
3
|
-
import { TextMeasure } from "./textMeasure";
|
|
4
|
-
|
|
5
|
-
const getNumberChar = () => TestTextMeasure.NUMBERS_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.NUMBERS_CHAR_SET.length)];
|
|
6
|
-
|
|
7
|
-
export const getTestNumbers = length => Array(length).fill(0).map(getNumberChar).join("");
|
|
8
|
-
|
|
9
|
-
const getLetterChar = () => TestTextMeasure.ALPHABET_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.ALPHABET_CHAR_SET.length)];
|
|
10
|
-
|
|
11
|
-
export const getTestWord = length => Array(length).fill(0).map(getLetterChar).join("");
|
|
12
|
-
|
|
13
|
-
export class TestTextMeasure extends TextMeasure {
|
|
14
|
-
test(methods, getStrCallback, count) {
|
|
15
|
-
const mean = numbers => (numbers => numbers.reduce(((sum, cur) => sum + cur), 0))(numbers) / numbers.length, variance = numbers => {
|
|
16
|
-
const m = mean(numbers);
|
|
17
|
-
return mean(numbers.map((num => Math.pow(num - m, 2))));
|
|
18
|
-
}, callback = null != getStrCallback ? getStrCallback : () => {
|
|
19
|
-
return `测试${length = 8, Array(length).fill(0).map(getLetterChar).join("")} ${getTestNumbers(4)}/${getTestNumbers(2)}-${getTestNumbers(2)}`;
|
|
20
|
-
var length;
|
|
21
|
-
}, textArr = Array(null != count ? count : 1e5).fill(0).map(callback), methodMap = {
|
|
22
|
-
canopus: this.fullMeasure.bind(this),
|
|
23
|
-
canvas: this.measureWithNaiveCanvas.bind(this),
|
|
24
|
-
simple: this.quickMeasureWithoutCanvas.bind(this),
|
|
25
|
-
quick: this.quickMeasure.bind(this),
|
|
26
|
-
old: text => {
|
|
27
|
-
if (isNil(text)) return {
|
|
28
|
-
width: 0,
|
|
29
|
-
height: 0
|
|
30
|
-
};
|
|
31
|
-
const str = text.toString(), {fontSize: fontSize} = this.textSpec;
|
|
32
|
-
return {
|
|
33
|
-
width: .8 * fontSize * str.length,
|
|
34
|
-
height: fontSize
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}, methodList = null != methods ? methods : Object.keys(methodMap), report = {}, timetmp = performance.now(), standardResult = textArr.map(this._standardMethod), standardTime = performance.now() - timetmp;
|
|
38
|
-
return report.standard = {
|
|
39
|
-
time: standardTime
|
|
40
|
-
}, methodList.forEach((method => {
|
|
41
|
-
const testMethod = methodMap[method];
|
|
42
|
-
if (testMethod) {
|
|
43
|
-
const timetmp = performance.now(), testResult = textArr.map(testMethod), testTime = performance.now() - timetmp, errList = textArr.map(((_, i) => ({
|
|
44
|
-
width: testResult[i].width - standardResult[i].width,
|
|
45
|
-
height: testResult[i].height - standardResult[i].height
|
|
46
|
-
})));
|
|
47
|
-
report[method] = {
|
|
48
|
-
errMean: {
|
|
49
|
-
width: mean(errList.map((e => e.width))),
|
|
50
|
-
height: mean(errList.map((e => e.height)))
|
|
51
|
-
},
|
|
52
|
-
errVar: {
|
|
53
|
-
width: variance(errList.map((e => e.width))),
|
|
54
|
-
height: variance(errList.map((e => e.height)))
|
|
55
|
-
},
|
|
56
|
-
time: testTime
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
})), {
|
|
60
|
-
report: report,
|
|
61
|
-
textArr: textArr
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphics/text/measure/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,OAAO,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,eAAe,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/G,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAEpG,M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,QAAQ;iBACf,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,MAAM;YACN,OAAO;SACR,CAAC;IACJ,CAAC;CACF","file":"test.js","sourcesContent":["import { isNil } from '../../../common';\nimport type { ITextMeasureSpec, ITextSize, TextMeasureMethod } from './interface';\nimport { TextMeasure } from './textMeasure';\n\nconst getNumberChar = () => {\n return TestTextMeasure.NUMBERS_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.NUMBERS_CHAR_SET.length)];\n};\nexport const getTestNumbers = (length: number) => Array(length).fill(0).map(getNumberChar).join('');\n\nconst getLetterChar = () => {\n return TestTextMeasure.ALPHABET_CHAR_SET[Math.floor(Math.random() * TestTextMeasure.ALPHABET_CHAR_SET.length)];\n};\nexport const getTestWord = (length: number) => Array(length).fill(0).map(getLetterChar).join('');\n\nexport class TestTextMeasure<T extends Partial<ITextMeasureSpec>> extends TextMeasure<T> {\n /** 测试方法 */\n test(methods?: TextMeasureMethod[], getStrCallback?: () => string, count?: number) {\n const sub = (numbers: number[]) => numbers.reduce((sum, cur) => sum + cur, 0);\n const mean = (numbers: number[]) => sub(numbers) / numbers.length;\n const variance = (numbers: number[]) => {\n const m = mean(numbers);\n return mean(numbers.map(num => Math.pow(num - m, 2)));\n };\n\n const callback =\n getStrCallback ?? (() => `测试${getTestWord(8)} ${getTestNumbers(4)}/${getTestNumbers(2)}-${getTestNumbers(2)}`);\n // 测试文本\n const textArr = Array(count ?? 100000)\n .fill(0)\n .map(callback);\n\n const methodMap: Record<string, (text: number | string) => ITextSize> = {\n canopus: this.fullMeasure.bind(this),\n canvas: this.measureWithNaiveCanvas.bind(this),\n simple: this.quickMeasureWithoutCanvas.bind(this),\n quick: this.quickMeasure.bind(this),\n old: (text: number | string) => {\n if (isNil(text)) {\n return { width: 0, height: 0 };\n }\n const str = text.toString();\n const { fontSize } = this.textSpec;\n return {\n width: fontSize * 0.8 * str.length,\n height: fontSize\n };\n }\n };\n const methodList = methods ?? Object.keys(methodMap);\n\n const report: Record<\n keyof typeof methodMap,\n {\n errMean?: ITextSize;\n errVar?: ITextSize;\n time: number;\n }\n > = {} as any;\n\n // 标准方法\n const timetmp = performance.now();\n const standardResult = textArr.map(this._standardMethod);\n const standardTime = performance.now() - timetmp;\n report.standard = {\n time: standardTime\n };\n\n // 测试方法\n methodList.forEach(method => {\n const testMethod = methodMap[method];\n if (testMethod) {\n const timetmp = performance.now();\n const testResult = textArr.map(testMethod as (text: number | string) => ITextSize);\n const testTime = performance.now() - timetmp;\n // 计算误差\n const errList = textArr.map(\n (_, i) =>\n ({\n width: testResult[i].width - standardResult[i].width,\n height: testResult[i].height - standardResult[i].height\n } as ITextSize)\n );\n report[method] = {\n errMean: {\n width: mean(errList.map(e => e.width)),\n height: mean(errList.map(e => e.height))\n },\n errVar: {\n width: variance(errList.map(e => e.width)),\n height: variance(errList.map(e => e.height))\n },\n time: testTime\n };\n }\n });\n\n return {\n report,\n textArr\n };\n }\n}\n"]}
|