@visactor/vutils 0.16.8-alpha.1 → 0.16.9

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.
Files changed (37) hide show
  1. package/cjs/common/ascending.js +2 -1
  2. package/cjs/common/getType.js +1 -2
  3. package/cjs/common/isArrayLike.js +2 -1
  4. package/cjs/common/isObject.js +1 -2
  5. package/cjs/common/isShallowEqual.js +2 -1
  6. package/cjs/common/isUndefined.js +1 -1
  7. package/cjs/common/isValid.js +1 -1
  8. package/cjs/common/isValidNumber.js +1 -1
  9. package/cjs/common/isValidUrl.js +1 -1
  10. package/cjs/common/lowerFirst.js +1 -1
  11. package/cjs/data-structure/bounds.js +1 -1
  12. package/cjs/data-structure/hashTable.js +1 -2
  13. package/cjs/data-structure/index.js +1 -1
  14. package/cjs/data-structure/matrix.js +1 -1
  15. package/cjs/data-structure/point.js +1 -1
  16. package/es/common/ascending.js +2 -1
  17. package/es/common/getType.js +1 -2
  18. package/es/common/isArrayLike.js +2 -1
  19. package/es/common/isObject.js +1 -2
  20. package/es/common/isShallowEqual.js +2 -1
  21. package/es/common/isUndefined.js +1 -1
  22. package/es/common/isValid.js +1 -1
  23. package/es/common/isValidNumber.js +1 -1
  24. package/es/common/isValidUrl.js +1 -1
  25. package/es/common/lowerFirst.js +1 -1
  26. package/es/data-structure/bounds.js +1 -1
  27. package/es/data-structure/hashTable.js +1 -2
  28. package/es/data-structure/index.js +1 -1
  29. package/es/data-structure/matrix.js +1 -1
  30. package/es/data-structure/point.js +1 -1
  31. package/package.json +3 -3
  32. package/cjs/graphics/text/measure/test.d.ts +0 -14
  33. package/cjs/graphics/text/measure/test.js +0 -67
  34. package/cjs/graphics/text/measure/test.js.map +0 -1
  35. package/es/graphics/text/measure/test.d.ts +0 -14
  36. package/es/graphics/text/measure/test.js +0 -65
  37. package/es/graphics/text/measure/test.js.map +0 -1
@@ -6,4 +6,5 @@ function ascending(a, b) {
6
6
 
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: !0
9
- }), exports.ascending = void 0, exports.ascending = ascending;
9
+ }), exports.ascending = void 0, exports.ascending = ascending;
10
+ //# sourceMappingURL=ascending.js.map
@@ -6,5 +6,4 @@ Object.defineProperty(exports, "__esModule", {
6
6
 
7
7
  const getType = value => ({}.toString.call(value).replace(/^\[object /, "").replace(/]$/, ""));
8
8
 
9
- exports.default = getType;
10
- //# sourceMappingURL=getType.js.map
9
+ exports.default = getType;
@@ -8,4 +8,5 @@ const isArrayLike = function(value) {
8
8
  return null !== value && "function" != typeof value && Number.isFinite(value.length);
9
9
  };
10
10
 
11
- exports.default = isArrayLike;
11
+ exports.default = isArrayLike;
12
+ //# sourceMappingURL=isArrayLike.js.map
@@ -9,5 +9,4 @@ const isObject = value => {
9
9
  return null !== value && "object" === type || "function" === type;
10
10
  };
11
11
 
12
- exports.default = isObject;
13
- //# sourceMappingURL=isObject.js.map
12
+ exports.default = isObject;
@@ -30,4 +30,5 @@ function isShallowEqual(objA, objB) {
30
30
  ret;
31
31
  }
32
32
 
33
- exports.isShallowEqual = isShallowEqual;
33
+ exports.isShallowEqual = isShallowEqual;
34
+ //# sourceMappingURL=isShallowEqual.js.map
@@ -7,4 +7,4 @@ Object.defineProperty(exports, "__esModule", {
7
7
  const isUndefined = value => void 0 === value;
8
8
 
9
9
  exports.default = isUndefined;
10
- //# sourceMappingURL=isUndefined.js.map
10
+ //# sourceMappingURL=isUndefined.js.map
@@ -7,4 +7,4 @@ Object.defineProperty(exports, "__esModule", {
7
7
  const isValid = value => null != value;
8
8
 
9
9
  exports.default = isValid;
10
- //# sourceMappingURL=isValid.js.map
10
+ //# sourceMappingURL=isValid.js.map
@@ -14,4 +14,4 @@ const isNumber_1 = __importDefault(require("./isNumber")), isValidNumber = value
14
14
  isNumber_1.default)(value) && Number.isFinite(value);
15
15
 
16
16
  exports.default = isValidNumber;
17
- //# sourceMappingURL=isValidNumber.js.map
17
+ //# sourceMappingURL=isValidNumber.js.map
@@ -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
@@ -9,4 +9,4 @@ const lowerFirst = function(str) {
9
9
  };
10
10
 
11
11
  exports.default = lowerFirst;
12
- //# sourceMappingURL=lowerFirst.js.map
12
+ //# sourceMappingURL=lowerFirst.js.map
@@ -136,4 +136,4 @@ exports.AABBBounds = AABBBounds;
136
136
  class OBBBounds extends Bounds {}
137
137
 
138
138
  exports.OBBBounds = OBBBounds;
139
- //# sourceMappingURL=bounds.js.map
139
+ //# sourceMappingURL=bounds.js.map
@@ -111,5 +111,4 @@ class HashTable {
111
111
  toImmutableMap() {}
112
112
  }
113
113
 
114
- exports.HashTable = HashTable;
115
- //# sourceMappingURL=hashTable.js.map
114
+ exports.HashTable = HashTable;
@@ -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
@@ -110,4 +110,4 @@ function normalTransform(out, origin, x, y, scaleX, scaleY, angle, rotateCenter)
110
110
  }
111
111
 
112
112
  exports.Matrix = Matrix, exports.normalTransform = normalTransform;
113
- //# sourceMappingURL=matrix.js.map
113
+ //# sourceMappingURL=matrix.js.map
@@ -78,4 +78,4 @@ class PolarPoint {
78
78
  }
79
79
 
80
80
  exports.PolarPoint = PolarPoint;
81
- //# sourceMappingURL=point.js.map
81
+ //# sourceMappingURL=point.js.map
@@ -1,3 +1,4 @@
1
1
  export function ascending(a, b) {
2
2
  return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
3
- }
3
+ }
4
+ //# sourceMappingURL=ascending.js.map
@@ -1,4 +1,3 @@
1
1
  const getType = value => ({}.toString.call(value).replace(/^\[object /, "").replace(/]$/, ""));
2
2
 
3
- export default getType;
4
- //# sourceMappingURL=getType.js.map
3
+ export default getType;
@@ -2,4 +2,5 @@ const isArrayLike = function(value) {
2
2
  return null !== value && "function" != typeof value && Number.isFinite(value.length);
3
3
  };
4
4
 
5
- export default isArrayLike;
5
+ export default isArrayLike;
6
+ //# sourceMappingURL=isArrayLike.js.map
@@ -3,5 +3,4 @@ const isObject = value => {
3
3
  return null !== value && "object" === type || "function" === type;
4
4
  };
5
5
 
6
- export default isObject;
7
- //# sourceMappingURL=isObject.js.map
6
+ export default isObject;
@@ -18,4 +18,5 @@ export function isShallowEqual(objA, objB) {
18
18
  let ret = !0;
19
19
  return Object.keys(objA).forEach((k => !!is(objA[k], objB[k]) || (ret = !1, ret))),
20
20
  ret;
21
- }
21
+ }
22
+ //# sourceMappingURL=isShallowEqual.js.map
@@ -1,4 +1,4 @@
1
1
  const isUndefined = value => void 0 === value;
2
2
 
3
3
  export default isUndefined;
4
- //# sourceMappingURL=isUndefined.js.map
4
+ //# sourceMappingURL=isUndefined.js.map
@@ -1,4 +1,4 @@
1
1
  const isValid = value => null != value;
2
2
 
3
3
  export default isValid;
4
- //# sourceMappingURL=isValid.js.map
4
+ //# sourceMappingURL=isValid.js.map
@@ -3,4 +3,4 @@ import isNumber from "./isNumber";
3
3
  const isValidNumber = value => isNumber(value) && Number.isFinite(value);
4
4
 
5
5
  export default isValidNumber;
6
- //# sourceMappingURL=isValidNumber.js.map
6
+ //# sourceMappingURL=isValidNumber.js.map
@@ -1,4 +1,4 @@
1
1
  export const isValidUrl = value => new RegExp(/^(http(s)?:\/\/)\w+[^\s]+(\.[^\s]+){1,}$/).test(value);
2
2
 
3
3
  export default isValidUrl;
4
- //# sourceMappingURL=isValidUrl.js.map
4
+ //# sourceMappingURL=isValidUrl.js.map
@@ -3,4 +3,4 @@ const lowerFirst = function(str) {
3
3
  };
4
4
 
5
5
  export default lowerFirst;
6
- //# sourceMappingURL=lowerFirst.js.map
6
+ //# sourceMappingURL=lowerFirst.js.map
@@ -124,4 +124,4 @@ export class Bounds {
124
124
  export class AABBBounds extends Bounds {}
125
125
 
126
126
  export class OBBBounds extends Bounds {}
127
- //# sourceMappingURL=bounds.js.map
127
+ //# sourceMappingURL=bounds.js.map
@@ -101,5 +101,4 @@ export class HashTable {
101
101
  return returnArr;
102
102
  }
103
103
  toImmutableMap() {}
104
- }
105
- //# sourceMappingURL=hashTable.js.map
104
+ }
@@ -5,4 +5,4 @@ export * from "./point";
5
5
  export * from "./bounds";
6
6
 
7
7
  export * from "./matrix";
8
- //# sourceMappingURL=index.js.map
8
+ //# sourceMappingURL=index.js.map
@@ -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
@@ -62,4 +62,4 @@ export class PolarPoint {
62
62
  return this.r = r, this.theta = theta, this;
63
63
  }
64
64
  }
65
- //# sourceMappingURL=point.js.map
65
+ //# sourceMappingURL=point.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vutils",
3
- "version": "0.16.8-alpha.1",
3
+ "version": "0.16.9",
4
4
  "main": "cjs/index.js",
5
5
  "module": "es/index.js",
6
6
  "types": "es/index.d.ts",
@@ -29,8 +29,8 @@
29
29
  "@types/node": "*",
30
30
  "@internal/bundler": "0.0.1",
31
31
  "@internal/jest-config": "0.0.1",
32
- "@internal/ts-config": "0.0.1",
33
- "@internal/eslint-config": "0.0.1"
32
+ "@internal/eslint-config": "0.0.1",
33
+ "@internal/ts-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,M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,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;wBAC1C,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;qBAC7C;oBACD,IAAI,EAAE,QAAQ;iBACf,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,MAAM;YACN,OAAO;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,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,OAAO,eAAe,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,eAAe,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;AACjH,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,WAAW,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;AAEjG,MAAM,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O,GAAG,OAAO,CAAC,GAAG,CACzB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACP,CAAC;oBACC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK;oBACpD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM;iBAC1C,CAAA,CAClB,CAAC;gBACF,MAAM,CAAC,MAAM,CAAC,GAAG;oBACf,OAAO,EAAE;wBACP,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;wBACtC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;qBACzC;oBACD,MAAM,EAAE;wBACN,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;wBAC1C,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;qBAC7C;oBACD,IAAI,EAAE,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"]}