hsu-utils 0.0.26 → 0.0.28
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/LICENSE +21 -21
- package/README.md +82 -78
- package/dist/hsu-utils.js +7 -7
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/GetStrSize/index.d.ts +12 -0
- package/es/{GetStrWidth → GetStrSize}/index.js +3 -2
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/lib/GetStrSize/index.d.ts +12 -0
- package/lib/{GetStrWidth → GetStrSize}/index.js +4 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -3
- package/package.json +59 -59
- package/es/GetStrWidth/index.d.ts +0 -9
- package/lib/GetStrWidth/index.d.ts +0 -9
@@ -0,0 +1,12 @@
|
|
1
|
+
interface Font {
|
2
|
+
style?: string;
|
3
|
+
variant?: string;
|
4
|
+
weight?: string;
|
5
|
+
size?: number;
|
6
|
+
family?: string;
|
7
|
+
}
|
8
|
+
export default function get_string_size(str: string, font?: Font, letterSpacing?: number): {
|
9
|
+
width: number;
|
10
|
+
height: number;
|
11
|
+
};
|
12
|
+
export {};
|
@@ -1,11 +1,12 @@
|
|
1
|
-
export default function
|
1
|
+
export default function get_string_size(str, font = {}, letterSpacing = 0) {
|
2
2
|
const { style = 'normal', variant = 'normal', weight = 'normal', size = 12, family: fontFamily = '微软雅黑' } = font;
|
3
3
|
const canvas = document.createElement('canvas');
|
4
4
|
const ctx = canvas.getContext('2d');
|
5
5
|
ctx.font = `${style} ${variant} ${weight} ${size}px ${fontFamily}`;
|
6
6
|
const metrics = ctx.measureText(str);
|
7
7
|
let width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
|
8
|
+
const height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);
|
8
9
|
const _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;
|
9
10
|
width += _letterSpacing;
|
10
|
-
return width;
|
11
|
+
return { width, height };
|
11
12
|
}
|
package/es/index.d.ts
CHANGED
@@ -2,12 +2,12 @@ import console_table from './ConsoleTable';
|
|
2
2
|
import deepCopy from './DeepCopy';
|
3
3
|
import Equal from './Equal';
|
4
4
|
import Typeof from './Typeof';
|
5
|
-
import
|
5
|
+
import get_string_size from './GetStrSize';
|
6
6
|
import ConvertNumbers from './ConvertNumbers';
|
7
7
|
import loadImage from './LoadImage';
|
8
8
|
import RenderPDF from './RenderPDF';
|
9
9
|
import downloadFile from './DownloadFile';
|
10
10
|
import array_is_includes from './ArrayIsIncludes';
|
11
|
-
export { console_table, deepCopy, Equal, Typeof,
|
11
|
+
export { console_table, deepCopy, Equal, Typeof, get_string_size, ConvertNumbers, loadImage, RenderPDF, downloadFile, array_is_includes };
|
12
12
|
import { ConsoleData } from './ConsoleTable';
|
13
13
|
export type { ConsoleData };
|
package/es/index.js
CHANGED
@@ -2,10 +2,10 @@ import console_table from './ConsoleTable';
|
|
2
2
|
import deepCopy from './DeepCopy';
|
3
3
|
import Equal from './Equal';
|
4
4
|
import Typeof from './Typeof';
|
5
|
-
import
|
5
|
+
import get_string_size from './GetStrSize';
|
6
6
|
import ConvertNumbers from './ConvertNumbers';
|
7
7
|
import loadImage from './LoadImage';
|
8
8
|
import RenderPDF from './RenderPDF';
|
9
9
|
import downloadFile from './DownloadFile';
|
10
10
|
import array_is_includes from './ArrayIsIncludes';
|
11
|
-
export { console_table, deepCopy, Equal, Typeof,
|
11
|
+
export { console_table, deepCopy, Equal, Typeof, get_string_size, ConvertNumbers, loadImage, RenderPDF, downloadFile, array_is_includes };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
interface Font {
|
2
|
+
style?: string;
|
3
|
+
variant?: string;
|
4
|
+
weight?: string;
|
5
|
+
size?: number;
|
6
|
+
family?: string;
|
7
|
+
}
|
8
|
+
export default function get_string_size(str: string, font?: Font, letterSpacing?: number): {
|
9
|
+
width: number;
|
10
|
+
height: number;
|
11
|
+
};
|
12
|
+
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
function
|
3
|
+
function get_string_size(str, font, letterSpacing) {
|
4
4
|
if (font === void 0) { font = {}; }
|
5
5
|
if (letterSpacing === void 0) { letterSpacing = 0; }
|
6
6
|
var _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.variant, variant = _b === void 0 ? 'normal' : _b, _c = font.weight, weight = _c === void 0 ? 'normal' : _c, _d = font.size, size = _d === void 0 ? 12 : _d, _e = font.family, fontFamily = _e === void 0 ? '微软雅黑' : _e;
|
@@ -9,8 +9,9 @@ function get_string_width(str, font, letterSpacing) {
|
|
9
9
|
ctx.font = "".concat(style, " ").concat(variant, " ").concat(weight, " ").concat(size, "px ").concat(fontFamily);
|
10
10
|
var metrics = ctx.measureText(str);
|
11
11
|
var width = +(+metrics.width.toFixed(2) + 0.01).toFixed(2);
|
12
|
+
var height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);
|
12
13
|
var _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;
|
13
14
|
width += _letterSpacing;
|
14
|
-
return width;
|
15
|
+
return { width: width, height: height };
|
15
16
|
}
|
16
|
-
exports.default =
|
17
|
+
exports.default = get_string_size;
|
package/lib/index.d.ts
CHANGED
@@ -2,12 +2,12 @@ import console_table from './ConsoleTable';
|
|
2
2
|
import deepCopy from './DeepCopy';
|
3
3
|
import Equal from './Equal';
|
4
4
|
import Typeof from './Typeof';
|
5
|
-
import
|
5
|
+
import get_string_size from './GetStrSize';
|
6
6
|
import ConvertNumbers from './ConvertNumbers';
|
7
7
|
import loadImage from './LoadImage';
|
8
8
|
import RenderPDF from './RenderPDF';
|
9
9
|
import downloadFile from './DownloadFile';
|
10
10
|
import array_is_includes from './ArrayIsIncludes';
|
11
|
-
export { console_table, deepCopy, Equal, Typeof,
|
11
|
+
export { console_table, deepCopy, Equal, Typeof, get_string_size, ConvertNumbers, loadImage, RenderPDF, downloadFile, array_is_includes };
|
12
12
|
import { ConsoleData } from './ConsoleTable';
|
13
13
|
export type { ConsoleData };
|
package/lib/index.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.array_is_includes = exports.downloadFile = exports.RenderPDF = exports.loadImage = exports.ConvertNumbers = exports.
|
6
|
+
exports.array_is_includes = exports.downloadFile = exports.RenderPDF = exports.loadImage = exports.ConvertNumbers = exports.get_string_size = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;
|
7
7
|
var ConsoleTable_1 = __importDefault(require("./ConsoleTable"));
|
8
8
|
exports.console_table = ConsoleTable_1.default;
|
9
9
|
var DeepCopy_1 = __importDefault(require("./DeepCopy"));
|
@@ -12,8 +12,8 @@ var Equal_1 = __importDefault(require("./Equal"));
|
|
12
12
|
exports.Equal = Equal_1.default;
|
13
13
|
var Typeof_1 = __importDefault(require("./Typeof"));
|
14
14
|
exports.Typeof = Typeof_1.default;
|
15
|
-
var
|
16
|
-
exports.
|
15
|
+
var GetStrSize_1 = __importDefault(require("./GetStrSize"));
|
16
|
+
exports.get_string_size = GetStrSize_1.default;
|
17
17
|
var ConvertNumbers_1 = __importDefault(require("./ConvertNumbers"));
|
18
18
|
exports.ConvertNumbers = ConvertNumbers_1.default;
|
19
19
|
var LoadImage_1 = __importDefault(require("./LoadImage"));
|
package/package.json
CHANGED
@@ -1,59 +1,59 @@
|
|
1
|
-
{
|
2
|
-
"name": "hsu-utils",
|
3
|
-
"version": "0.0.
|
4
|
-
"description": "some front-end utils",
|
5
|
-
"repository": "git@github.com:VitaTsui/hsu-utils.git",
|
6
|
-
"author": "VitaHsu <vitahsu7@gmail.com>",
|
7
|
-
"license": "MIT",
|
8
|
-
"main": "lib/index.js",
|
9
|
-
"module": "es/index.js",
|
10
|
-
"unpkg": "dist/hsu-utils.min.js",
|
11
|
-
"files": [
|
12
|
-
"es",
|
13
|
-
"lib",
|
14
|
-
"dist",
|
15
|
-
"package.json",
|
16
|
-
"README.md",
|
17
|
-
"LICENSE"
|
18
|
-
],
|
19
|
-
"sideEffects": [
|
20
|
-
"es/*",
|
21
|
-
"lib/*",
|
22
|
-
"dist/*"
|
23
|
-
],
|
24
|
-
"scripts": {
|
25
|
-
"build": "yarn build:es && yarn build:cjs && rimraf dist && yarn build:umd",
|
26
|
-
"build:es": "rimraf es && tsc -p build/tsconfig.es.json",
|
27
|
-
"build:cjs": "rimraf lib && tsc -p build/tsconfig.cjs.json",
|
28
|
-
"build:umd": "rimraf dist && yarn build:dev && yarn build:prod",
|
29
|
-
"build:dev": "cross-env NODE_ENV=development webpack --config build/webpack.config.js",
|
30
|
-
"build:prod": "cross-env NODE_ENV=production webpack --config build/webpack.config.js",
|
31
|
-
"clear": "rimraf lib && rimraf es && rimraf dist",
|
32
|
-
"test": "jest",
|
33
|
-
"publish:patch": "yarn build && yarn publish --new-version patch",
|
34
|
-
"publish:minor": "yarn build && yarn publish --new-version minor",
|
35
|
-
"publish:major": "yarn build && yarn publish --new-version major",
|
36
|
-
"publish:alpha": "yarn build && yarn publish --tag alpha"
|
37
|
-
},
|
38
|
-
"devDependencies": {
|
39
|
-
"@jest/globals": "^29.5.0",
|
40
|
-
"@testing-library/react-hooks": "^8.0.1",
|
41
|
-
"@types/jest": "^29.5.2",
|
42
|
-
"cross-env": "^7.0.3",
|
43
|
-
"jest": "^29.5.0",
|
44
|
-
"jest-canvas-mock": "^2.5.2",
|
45
|
-
"jest-environment-jsdom": "^29.5.0",
|
46
|
-
"jsdom": "^22.1.0",
|
47
|
-
"rimraf": "^5.0.1",
|
48
|
-
"terser-webpack-plugin": "^5.3.0",
|
49
|
-
"ts-jest": "^29.1.0",
|
50
|
-
"ts-loader": "^9.2.6",
|
51
|
-
"ts-node": "^10.9.1",
|
52
|
-
"typescript": "^5.1.3",
|
53
|
-
"webpack": "^5.65.0",
|
54
|
-
"webpack-cli": "^4.9.1"
|
55
|
-
},
|
56
|
-
"dependencies": {
|
57
|
-
"pdfjs-dist": "2.13.216"
|
58
|
-
}
|
59
|
-
}
|
1
|
+
{
|
2
|
+
"name": "hsu-utils",
|
3
|
+
"version": "0.0.28",
|
4
|
+
"description": "some front-end utils",
|
5
|
+
"repository": "git@github.com:VitaTsui/hsu-utils.git",
|
6
|
+
"author": "VitaHsu <vitahsu7@gmail.com>",
|
7
|
+
"license": "MIT",
|
8
|
+
"main": "lib/index.js",
|
9
|
+
"module": "es/index.js",
|
10
|
+
"unpkg": "dist/hsu-utils.min.js",
|
11
|
+
"files": [
|
12
|
+
"es",
|
13
|
+
"lib",
|
14
|
+
"dist",
|
15
|
+
"package.json",
|
16
|
+
"README.md",
|
17
|
+
"LICENSE"
|
18
|
+
],
|
19
|
+
"sideEffects": [
|
20
|
+
"es/*",
|
21
|
+
"lib/*",
|
22
|
+
"dist/*"
|
23
|
+
],
|
24
|
+
"scripts": {
|
25
|
+
"build": "yarn build:es && yarn build:cjs && rimraf dist && yarn build:umd",
|
26
|
+
"build:es": "rimraf es && tsc -p build/tsconfig.es.json",
|
27
|
+
"build:cjs": "rimraf lib && tsc -p build/tsconfig.cjs.json",
|
28
|
+
"build:umd": "rimraf dist && yarn build:dev && yarn build:prod",
|
29
|
+
"build:dev": "cross-env NODE_ENV=development webpack --config build/webpack.config.js",
|
30
|
+
"build:prod": "cross-env NODE_ENV=production webpack --config build/webpack.config.js",
|
31
|
+
"clear": "rimraf lib && rimraf es && rimraf dist",
|
32
|
+
"test": "jest",
|
33
|
+
"publish:patch": "yarn build && yarn publish --new-version patch",
|
34
|
+
"publish:minor": "yarn build && yarn publish --new-version minor",
|
35
|
+
"publish:major": "yarn build && yarn publish --new-version major",
|
36
|
+
"publish:alpha": "yarn build && yarn publish --tag alpha"
|
37
|
+
},
|
38
|
+
"devDependencies": {
|
39
|
+
"@jest/globals": "^29.5.0",
|
40
|
+
"@testing-library/react-hooks": "^8.0.1",
|
41
|
+
"@types/jest": "^29.5.2",
|
42
|
+
"cross-env": "^7.0.3",
|
43
|
+
"jest": "^29.5.0",
|
44
|
+
"jest-canvas-mock": "^2.5.2",
|
45
|
+
"jest-environment-jsdom": "^29.5.0",
|
46
|
+
"jsdom": "^22.1.0",
|
47
|
+
"rimraf": "^5.0.1",
|
48
|
+
"terser-webpack-plugin": "^5.3.0",
|
49
|
+
"ts-jest": "^29.1.0",
|
50
|
+
"ts-loader": "^9.2.6",
|
51
|
+
"ts-node": "^10.9.1",
|
52
|
+
"typescript": "^5.1.3",
|
53
|
+
"webpack": "^5.65.0",
|
54
|
+
"webpack-cli": "^4.9.1"
|
55
|
+
},
|
56
|
+
"dependencies": {
|
57
|
+
"pdfjs-dist": "2.13.216"
|
58
|
+
}
|
59
|
+
}
|