hsu-utils 0.0.45 → 0.0.47
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/README.md +35 -26
- package/dist/hsu-utils.js +15 -4
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/GetStrSize/index.d.ts +4 -1
- package/es/GetStrSize/index.js +25 -2
- package/es/LoadFont/index.d.ts +13 -0
- package/es/LoadFont/index.js +20 -0
- package/es/index.d.ts +3 -2
- package/es/index.js +3 -2
- package/lib/GetStrSize/index.d.ts +4 -1
- package/lib/GetStrSize/index.js +63 -2
- package/lib/LoadFont/index.d.ts +13 -0
- package/lib/LoadFont/index.js +61 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +28 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,25 +14,27 @@ yarn add hsu-utils
|
|
|
14
14
|
|
|
15
15
|
## 功能
|
|
16
16
|
|
|
17
|
-
| 方法 | 子方法
|
|
18
|
-
| ----------------- |
|
|
19
|
-
| array_is_includes | -
|
|
20
|
-
| console_table | -
|
|
21
|
-
| ConvertNumbers | toChineseNum
|
|
22
|
-
| deepCopy | -
|
|
23
|
-
| downloadFile | -
|
|
24
|
-
| Equal | ValEqual
|
|
25
|
-
| | TypeEqual
|
|
26
|
-
| | ObjEqual
|
|
27
|
-
| get_string_size | -
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
| |
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
17
|
+
| 方法 | 子方法 | 说明 | 类型 | 备注 |
|
|
18
|
+
| ----------------- | --------------------- | ------------------------------- | ---------------------------------------------------------------------------------------- | -------------------------------- |
|
|
19
|
+
| array_is_includes | - | 判断一个数组是否包含另一个数组 | \<T>(arr1: Array\<T>, arr2: Array\<T>) => boolean | - |
|
|
20
|
+
| console_table | - | 在控制台打印像 MySql 一样的表格 | (data: [ConsoleData](#consoledata), callBack?: (str: string) => void) => void | - |
|
|
21
|
+
| ConvertNumbers | toChineseNum | 数字转中文 | (num: number, options?: [C_Options](#c_options)) => string | - |
|
|
22
|
+
| deepCopy | - | 深拷贝 | \<T>(data: T) => T | - |
|
|
23
|
+
| downloadFile | - | 文件下载 | (file: ArrayBuffer \| string, fileName?: string, signal?: AbortSignal) => Promise\<void> | string 为 http(s) 地址或本地地址 |
|
|
24
|
+
| Equal | ValEqual | 判断值相等 | <T = unknown>(obj1: T, obj2: T) => boolean | - |
|
|
25
|
+
| | TypeEqual | 判断类型相同 | <T = unknown>(obj1: T, obj2: T) => boolean | - |
|
|
26
|
+
| | ObjEqual | 判断对象相等 | <T = object>(obj1: T, obj2: T) => boolean | - |
|
|
27
|
+
| get_string_size | - | 获取字符串大小 | (str: string, font?: [Font](#font)) => { width: number; height: number } | - |
|
|
28
|
+
| | get_string_size_async | 异步获取字符串大小 | (str: string, font?: [Font](#font)) => Promise<{ width: number; height: number }> | - |
|
|
29
|
+
| loadImage | - | 异步加载图片并缓存 | (url: string) => Promise\<HTMLImageElement> | - |
|
|
30
|
+
| loadFont | - | 异步加载字体 | (options: [LoadFontOptions](#loadfontoptions)) => Promise\<void> | - |
|
|
31
|
+
| RenderPDF | load | 用于预加载 PDF | (pdfUrl: string) => Promise\<PDFDocumentProxy> | - |
|
|
32
|
+
| | getNumPages | 获取 PDF 页数 | (pdfUrl: string): Promise\<number> | - |
|
|
33
|
+
| | clear | 删除已渲染的 PDF | (containerId: string) => void | - |
|
|
34
|
+
| | render | 渲染 PDF | (options: [RenderOption](#renderoption)) => Promise\<void> | - |
|
|
35
|
+
| Typeof | - | 获取类型或判断类型 | \<T>(value: T, isType?: [Type](#type)) => boolean \| Type | - |
|
|
36
|
+
| generateRandomStr | - | 生成随机字符串 | (length:number) => string | - |
|
|
37
|
+
| getTimeDifference | - | 获取时间差 | (start: string, end: string) => [TimeDifference](#timedifference) | - |
|
|
36
38
|
|
|
37
39
|
## 类型
|
|
38
40
|
|
|
@@ -54,13 +56,20 @@ yarn add hsu-utils
|
|
|
54
56
|
|
|
55
57
|
### Font
|
|
56
58
|
|
|
57
|
-
| 参数
|
|
58
|
-
|
|
|
59
|
-
| size
|
|
60
|
-
| style
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
59
|
+
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
|
60
|
+
| ------ | -------- | ------ | ---------- | ---- |
|
|
61
|
+
| size | 字体大小 | number | 10 | - |
|
|
62
|
+
| style | 字体样式 | string | normal | - |
|
|
63
|
+
| weight | 字体粗细 | string | normal | - |
|
|
64
|
+
| family | 字体系列 | string | sans-serif | - |
|
|
65
|
+
|
|
66
|
+
### LoadFontOptions
|
|
67
|
+
|
|
68
|
+
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
|
69
|
+
| ---- | ----------------------- | ------------------------- | ------ | ---- |
|
|
70
|
+
| ctx | Canvas 上下文 | CanvasRenderingContext2D | - | - |
|
|
71
|
+
| font | 字体配置 | [Font](#font) | - | - |
|
|
72
|
+
| text | 文本内容 | string | - | - |
|
|
64
73
|
|
|
65
74
|
### RenderOption
|
|
66
75
|
|
package/dist/hsu-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
*
|
|
3
|
-
* hsu-utils v0.0.
|
|
3
|
+
* hsu-utils v0.0.46
|
|
4
4
|
*
|
|
5
5
|
* some front-end utils
|
|
6
6
|
*
|
|
@@ -139,10 +139,10 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
|
|
|
139
139
|
/*!***********************************!*\
|
|
140
140
|
!*** ./tools/GetStrSize/index.ts ***!
|
|
141
141
|
\***********************************/
|
|
142
|
-
/***/ ((__unused_webpack_module, exports)
|
|
142
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
143
143
|
|
|
144
144
|
"use strict";
|
|
145
|
-
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction
|
|
145
|
+
eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.get_string_size_async = void 0;\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction get_string_size_async(str, font) {\n if (font === void 0) { font = {}; }\n return __awaiter(this, void 0, void 0, function () {\n var _a, style, _b, weight, _c, size, _d, fontFamily, canvas, ctx, metrics, width, height;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.weight, weight = _b === void 0 ? 'normal' : _b, _c = font.size, size = _c === void 0 ? 10 : _c, _d = font.family, fontFamily = _d === void 0 ? 'sans-serif' : _d;\n canvas = document.createElement('canvas');\n ctx = canvas.getContext('2d');\n return [4, (0, __1.loadFont)({ ctx: ctx, font: font, text: str })];\n case 1:\n _e.sent();\n ctx.font = \"\".concat(style, \" \").concat(weight, \" \").concat(size, \"px \").concat(fontFamily);\n metrics = ctx.measureText(str);\n width = +(+metrics.width.toFixed(2)).toFixed(2);\n height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);\n return [2, { width: +width.toFixed(2), height: +height.toFixed(2) }];\n }\n });\n });\n}\nexports.get_string_size_async = get_string_size_async;\nfunction get_string_size(str, font) {\n if (font === void 0) { font = {}; }\n var _a = font.style, style = _a === void 0 ? 'normal' : _a, _b = font.weight, weight = _b === void 0 ? 'normal' : _b, _c = font.size, size = _c === void 0 ? 10 : _c, _d = font.family, fontFamily = _d === void 0 ? 'sans-serif' : _d;\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n ctx.font = \"\".concat(style, \" \").concat(weight, \" \").concat(size, \"px \").concat(fontFamily);\n var metrics = ctx.measureText(str);\n var width = +(+metrics.width.toFixed(2)).toFixed(2);\n var height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);\n return { width: +width.toFixed(2), height: +height.toFixed(2) };\n}\nexports[\"default\"] = get_string_size;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/GetStrSize/index.ts?");
|
|
146
146
|
|
|
147
147
|
/***/ }),
|
|
148
148
|
|
|
@@ -157,6 +157,17 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
|
|
|
157
157
|
|
|
158
158
|
/***/ }),
|
|
159
159
|
|
|
160
|
+
/***/ "./tools/LoadFont/index.ts":
|
|
161
|
+
/*!*********************************!*\
|
|
162
|
+
!*** ./tools/LoadFont/index.ts ***!
|
|
163
|
+
\*********************************/
|
|
164
|
+
/***/ (function(__unused_webpack_module, exports) {
|
|
165
|
+
|
|
166
|
+
"use strict";
|
|
167
|
+
eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunction loadFont(options) {\n return __awaiter(this, void 0, void 0, function () {\n var ctx, _a, font, text, _b, style, _c, weight, _d, size, _e, fontFamily, _ctx;\n return __generator(this, function (_f) {\n switch (_f.label) {\n case 0:\n ctx = options.ctx, _a = options.font, font = _a === void 0 ? {} : _a, text = options.text;\n _b = font.style, style = _b === void 0 ? 'normal' : _b, _c = font.weight, weight = _c === void 0 ? 'normal' : _c, _d = font.size, size = _d === void 0 ? 10 : _d, _e = font.fontFamily, fontFamily = _e === void 0 ? 'sans-serif' : _e;\n return [4, document.fonts.load(\"\".concat(style, \" \").concat(weight, \" \").concat(size, \"px \").concat(fontFamily))];\n case 1:\n _f.sent();\n _ctx = ctx || document.createElement('canvas').getContext('2d');\n _ctx.font = \"\".concat(style, \" \").concat(weight, \" \").concat(size, \"px \").concat(fontFamily);\n _ctx.fillText(text || '', -999, -999);\n return [4, new Promise(requestAnimationFrame)];\n case 2:\n _f.sent();\n return [2];\n }\n });\n });\n}\nexports[\"default\"] = loadFont;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/LoadFont/index.ts?");
|
|
168
|
+
|
|
169
|
+
/***/ }),
|
|
170
|
+
|
|
160
171
|
/***/ "./tools/LoadImage/index.ts":
|
|
161
172
|
/*!**********************************!*\
|
|
162
173
|
!*** ./tools/LoadImage/index.ts ***!
|
|
@@ -197,7 +208,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
|
|
|
197
208
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
198
209
|
|
|
199
210
|
"use strict";
|
|
200
|
-
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.getTimeDifference = exports.generateRandomStr = 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;\nvar ConsoleTable_1 = __importDefault(__webpack_require__(/*! ./ConsoleTable */ \"./tools/ConsoleTable/index.ts\"));\nexports.console_table = ConsoleTable_1.default;\nvar DeepCopy_1 = __importDefault(__webpack_require__(/*! ./DeepCopy */ \"./tools/DeepCopy/index.ts\"));\nexports.deepCopy = DeepCopy_1.default;\nvar Equal_1 = __importDefault(__webpack_require__(/*! ./Equal */ \"./tools/Equal/index.ts\"));\nexports.Equal = Equal_1.default;\nvar Typeof_1 = __importDefault(__webpack_require__(/*! ./Typeof */ \"./tools/Typeof/index.ts\"));\nexports.Typeof = Typeof_1.default;\nvar GetStrSize_1 =
|
|
211
|
+
eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.getTimeDifference = exports.generateRandomStr = exports.array_is_includes = exports.downloadFile = exports.RenderPDF = exports.loadImage = exports.ConvertNumbers = exports.loadFont = exports.get_string_size_async = exports.get_string_size = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;\nvar ConsoleTable_1 = __importDefault(__webpack_require__(/*! ./ConsoleTable */ \"./tools/ConsoleTable/index.ts\"));\nexports.console_table = ConsoleTable_1.default;\nvar DeepCopy_1 = __importDefault(__webpack_require__(/*! ./DeepCopy */ \"./tools/DeepCopy/index.ts\"));\nexports.deepCopy = DeepCopy_1.default;\nvar Equal_1 = __importDefault(__webpack_require__(/*! ./Equal */ \"./tools/Equal/index.ts\"));\nexports.Equal = Equal_1.default;\nvar Typeof_1 = __importDefault(__webpack_require__(/*! ./Typeof */ \"./tools/Typeof/index.ts\"));\nexports.Typeof = Typeof_1.default;\nvar GetStrSize_1 = __importStar(__webpack_require__(/*! ./GetStrSize */ \"./tools/GetStrSize/index.ts\"));\nexports.get_string_size = GetStrSize_1.default;\nObject.defineProperty(exports, \"get_string_size_async\", ({ enumerable: true, get: function () { return GetStrSize_1.get_string_size_async; } }));\nvar ConvertNumbers_1 = __importDefault(__webpack_require__(/*! ./ConvertNumbers */ \"./tools/ConvertNumbers/index.ts\"));\nexports.ConvertNumbers = ConvertNumbers_1.default;\nvar LoadImage_1 = __importDefault(__webpack_require__(/*! ./LoadImage */ \"./tools/LoadImage/index.ts\"));\nexports.loadImage = LoadImage_1.default;\nvar RenderPDF_1 = __importDefault(__webpack_require__(/*! ./RenderPDF */ \"./tools/RenderPDF/index.ts\"));\nexports.RenderPDF = RenderPDF_1.default;\nvar DownloadFile_1 = __importDefault(__webpack_require__(/*! ./DownloadFile */ \"./tools/DownloadFile/index.ts\"));\nexports.downloadFile = DownloadFile_1.default;\nvar ArrayIsIncludes_1 = __importDefault(__webpack_require__(/*! ./ArrayIsIncludes */ \"./tools/ArrayIsIncludes/index.ts\"));\nexports.array_is_includes = ArrayIsIncludes_1.default;\nvar GenerateRandomStr_1 = __importDefault(__webpack_require__(/*! ./GenerateRandomStr */ \"./tools/GenerateRandomStr/index.ts\"));\nexports.generateRandomStr = GenerateRandomStr_1.default;\nvar GetTimeDifference_1 = __importDefault(__webpack_require__(/*! ./GetTimeDifference */ \"./tools/GetTimeDifference/index.ts\"));\nexports.getTimeDifference = GetTimeDifference_1.default;\nvar LoadFont_1 = __importDefault(__webpack_require__(/*! ./LoadFont */ \"./tools/LoadFont/index.ts\"));\nexports.loadFont = LoadFont_1.default;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/index.ts?");
|
|
201
212
|
|
|
202
213
|
/***/ }),
|
|
203
214
|
|