hsu-utils 0.0.43 → 0.0.44
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/dist/hsu-utils.js +3 -3
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/GetStrSize/index.d.ts +1 -1
- package/es/GetStrSize/index.js +2 -4
- package/es/RenderPDF/index.d.ts +4 -3
- package/es/RenderPDF/index.js +9 -6
- package/lib/GetStrSize/index.d.ts +1 -1
- package/lib/GetStrSize/index.js +2 -5
- package/lib/RenderPDF/index.d.ts +4 -3
- package/lib/RenderPDF/index.js +9 -6
- package/package.json +1 -1
package/es/GetStrSize/index.d.ts
CHANGED
package/es/GetStrSize/index.js
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
export default function get_string_size(str, font = {}
|
1
|
+
export default function get_string_size(str, font = {}) {
|
2
2
|
const { style = 'normal', variant = 'normal', weight = 'normal', size = 10, family: fontFamily = 'sans-serif' } = 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
|
-
let width = +(+metrics.width.toFixed(2)
|
7
|
+
let width = +(+metrics.width.toFixed(2)).toFixed(2);
|
8
8
|
const height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);
|
9
|
-
const _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;
|
10
|
-
width += _letterSpacing;
|
11
9
|
return { width: +width.toFixed(2), height: +height.toFixed(2) };
|
12
10
|
}
|
package/es/RenderPDF/index.d.ts
CHANGED
@@ -6,11 +6,12 @@ interface RenderOption {
|
|
6
6
|
endPageNum?: number;
|
7
7
|
pixelRatio?: number;
|
8
8
|
scale?: number;
|
9
|
+
workerSrc?: string;
|
9
10
|
}
|
10
|
-
declare function load(pdfUrl: string): Promise<PDFDocumentProxy>;
|
11
|
-
declare function getNumPages(pdfUrl: string): Promise<number>;
|
11
|
+
declare function load(pdfUrl: string, workerSrc?: string): Promise<PDFDocumentProxy>;
|
12
|
+
declare function getNumPages(pdfUrl: string, workerSrc?: string): Promise<number>;
|
12
13
|
declare function clear(containerId: string): void;
|
13
|
-
declare function render({ pdfUrl, containerId, startPageNum, endPageNum, pixelRatio, scale }: RenderOption): Promise<void>;
|
14
|
+
declare function render({ pdfUrl, containerId, startPageNum, endPageNum, pixelRatio, scale, workerSrc }: RenderOption): Promise<void>;
|
14
15
|
declare const RenderPDF: {
|
15
16
|
load: typeof load;
|
16
17
|
getNumPages: typeof getNumPages;
|
package/es/RenderPDF/index.js
CHANGED
@@ -8,10 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
});
|
9
9
|
};
|
10
10
|
import { GlobalWorkerOptions, getDocument } from 'pdfjs-dist/legacy/build/pdf.js';
|
11
|
-
GlobalWorkerOptions.workerSrc = 'https://
|
11
|
+
GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.13.216/pdf.worker.min.js';
|
12
12
|
const PDFMap = new Map();
|
13
|
-
function load(pdfUrl) {
|
13
|
+
function load(pdfUrl, workerSrc) {
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
15
|
+
if (workerSrc) {
|
16
|
+
GlobalWorkerOptions.workerSrc = workerSrc;
|
17
|
+
}
|
15
18
|
let pdf = PDFMap.get(pdfUrl);
|
16
19
|
if (!pdf) {
|
17
20
|
const loadingTask = getDocument({
|
@@ -25,9 +28,9 @@ function load(pdfUrl) {
|
|
25
28
|
return yield pdf;
|
26
29
|
});
|
27
30
|
}
|
28
|
-
function getNumPages(pdfUrl) {
|
31
|
+
function getNumPages(pdfUrl, workerSrc) {
|
29
32
|
return __awaiter(this, void 0, void 0, function* () {
|
30
|
-
const pdf = yield load(pdfUrl);
|
33
|
+
const pdf = yield load(pdfUrl, workerSrc);
|
31
34
|
return pdf.numPages;
|
32
35
|
});
|
33
36
|
}
|
@@ -38,13 +41,13 @@ function clear(containerId) {
|
|
38
41
|
container === null || container === void 0 ? void 0 : container.removeChild(item);
|
39
42
|
});
|
40
43
|
}
|
41
|
-
function render({ pdfUrl, containerId, startPageNum, endPageNum, pixelRatio, scale }) {
|
44
|
+
function render({ pdfUrl, containerId, startPageNum, endPageNum, pixelRatio, scale, workerSrc }) {
|
42
45
|
return __awaiter(this, void 0, void 0, function* () {
|
43
46
|
clear(containerId);
|
44
47
|
const container = document.getElementById(containerId);
|
45
48
|
if (!container)
|
46
49
|
return;
|
47
|
-
const pdf = yield load(pdfUrl);
|
50
|
+
const pdf = yield load(pdfUrl, workerSrc);
|
48
51
|
const start = startPageNum !== null && startPageNum !== void 0 ? startPageNum : 1;
|
49
52
|
const end = endPageNum !== null && endPageNum !== void 0 ? endPageNum : pdf.numPages;
|
50
53
|
for (let i = start; i <= end; i++) {
|
package/lib/GetStrSize/index.js
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
function get_string_size(str, font
|
3
|
+
function get_string_size(str, font) {
|
4
4
|
if (font === void 0) { font = {}; }
|
5
|
-
if (letterSpacing === void 0) { letterSpacing = 0; }
|
6
5
|
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 ? 10 : _d, _e = font.family, fontFamily = _e === void 0 ? 'sans-serif' : _e;
|
7
6
|
var canvas = document.createElement('canvas');
|
8
7
|
var ctx = canvas.getContext('2d');
|
9
8
|
ctx.font = "".concat(style, " ").concat(variant, " ").concat(weight, " ").concat(size, "px ").concat(fontFamily);
|
10
9
|
var metrics = ctx.measureText(str);
|
11
|
-
var width = +(+metrics.width.toFixed(2)
|
10
|
+
var width = +(+metrics.width.toFixed(2)).toFixed(2);
|
12
11
|
var height = +(+metrics.actualBoundingBoxAscent.toFixed(2) + +metrics.actualBoundingBoxDescent.toFixed(2)).toFixed(2);
|
13
|
-
var _letterSpacing = (str.length > 0 ? str.length - 1 : 0) * letterSpacing;
|
14
|
-
width += _letterSpacing;
|
15
12
|
return { width: +width.toFixed(2), height: +height.toFixed(2) };
|
16
13
|
}
|
17
14
|
exports.default = get_string_size;
|
package/lib/RenderPDF/index.d.ts
CHANGED
@@ -6,11 +6,12 @@ interface RenderOption {
|
|
6
6
|
endPageNum?: number;
|
7
7
|
pixelRatio?: number;
|
8
8
|
scale?: number;
|
9
|
+
workerSrc?: string;
|
9
10
|
}
|
10
|
-
declare function load(pdfUrl: string): Promise<PDFDocumentProxy>;
|
11
|
-
declare function getNumPages(pdfUrl: string): Promise<number>;
|
11
|
+
declare function load(pdfUrl: string, workerSrc?: string): Promise<PDFDocumentProxy>;
|
12
|
+
declare function getNumPages(pdfUrl: string, workerSrc?: string): Promise<number>;
|
12
13
|
declare function clear(containerId: string): void;
|
13
|
-
declare function render({ pdfUrl, containerId, startPageNum, endPageNum, pixelRatio, scale }: RenderOption): Promise<void>;
|
14
|
+
declare function render({ pdfUrl, containerId, startPageNum, endPageNum, pixelRatio, scale, workerSrc }: RenderOption): Promise<void>;
|
14
15
|
declare const RenderPDF: {
|
15
16
|
load: typeof load;
|
16
17
|
getNumPages: typeof getNumPages;
|
package/lib/RenderPDF/index.js
CHANGED
@@ -37,14 +37,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
37
|
};
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
39
|
var pdf_js_1 = require("pdfjs-dist/legacy/build/pdf.js");
|
40
|
-
pdf_js_1.GlobalWorkerOptions.workerSrc = 'https://
|
40
|
+
pdf_js_1.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.13.216/pdf.worker.min.js';
|
41
41
|
var PDFMap = new Map();
|
42
|
-
function load(pdfUrl) {
|
42
|
+
function load(pdfUrl, workerSrc) {
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
44
44
|
var pdf, loadingTask;
|
45
45
|
return __generator(this, function (_a) {
|
46
46
|
switch (_a.label) {
|
47
47
|
case 0:
|
48
|
+
if (workerSrc) {
|
49
|
+
pdf_js_1.GlobalWorkerOptions.workerSrc = workerSrc;
|
50
|
+
}
|
48
51
|
pdf = PDFMap.get(pdfUrl);
|
49
52
|
if (!pdf) {
|
50
53
|
loadingTask = (0, pdf_js_1.getDocument)({
|
@@ -61,12 +64,12 @@ function load(pdfUrl) {
|
|
61
64
|
});
|
62
65
|
});
|
63
66
|
}
|
64
|
-
function getNumPages(pdfUrl) {
|
67
|
+
function getNumPages(pdfUrl, workerSrc) {
|
65
68
|
return __awaiter(this, void 0, void 0, function () {
|
66
69
|
var pdf;
|
67
70
|
return __generator(this, function (_a) {
|
68
71
|
switch (_a.label) {
|
69
|
-
case 0: return [4, load(pdfUrl)];
|
72
|
+
case 0: return [4, load(pdfUrl, workerSrc)];
|
70
73
|
case 1:
|
71
74
|
pdf = _a.sent();
|
72
75
|
return [2, pdf.numPages];
|
@@ -82,7 +85,7 @@ function clear(containerId) {
|
|
82
85
|
});
|
83
86
|
}
|
84
87
|
function render(_a) {
|
85
|
-
var pdfUrl = _a.pdfUrl, containerId = _a.containerId, startPageNum = _a.startPageNum, endPageNum = _a.endPageNum, pixelRatio = _a.pixelRatio, scale = _a.scale;
|
88
|
+
var pdfUrl = _a.pdfUrl, containerId = _a.containerId, startPageNum = _a.startPageNum, endPageNum = _a.endPageNum, pixelRatio = _a.pixelRatio, scale = _a.scale, workerSrc = _a.workerSrc;
|
86
89
|
return __awaiter(this, void 0, void 0, function () {
|
87
90
|
var container, pdf, start, end, i;
|
88
91
|
return __generator(this, function (_b) {
|
@@ -92,7 +95,7 @@ function render(_a) {
|
|
92
95
|
container = document.getElementById(containerId);
|
93
96
|
if (!container)
|
94
97
|
return [2];
|
95
|
-
return [4, load(pdfUrl)];
|
98
|
+
return [4, load(pdfUrl, workerSrc)];
|
96
99
|
case 1:
|
97
100
|
pdf = _b.sent();
|
98
101
|
start = startPageNum !== null && startPageNum !== void 0 ? startPageNum : 1;
|