hsu-utils 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
package/dist/hsu-utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * hsu-utils v0.0.22
3
+ * hsu-utils v0.0.23
4
4
  *
5
5
  * some front-end utils
6
6
  *
@@ -153,7 +153,7 @@ eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _argument
153
153
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
154
154
 
155
155
  "use strict";
156
- 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 }));\nvar pdf_js_1 = __webpack_require__(/*! pdfjs-dist/legacy/build/pdf.js */ \"./node_modules/pdfjs-dist/legacy/build/pdf.js\");\npdf_js_1.GlobalWorkerOptions.workerSrc = 'https://cdn.bootcss.com/pdf.js/2.13.216/pdf.worker.js';\nvar PDFMap = new Map();\nfunction load(pdfUrl) {\n return __awaiter(this, void 0, void 0, function () {\n var pdf, loadingTask;\n return __generator(this, function (_a) {\n pdf = PDFMap.get(pdfUrl);\n if (!pdf) {\n loadingTask = (0, pdf_js_1.getDocument)({\n url: pdfUrl,\n cMapUrl: 'https://unpkg.com/browse/pdfjs-dist@2.13.216/cmaps/',\n cMapPacked: true\n });\n pdf = loadingTask.promise;\n PDFMap.set(pdfUrl, pdf);\n }\n return [2, pdf];\n });\n });\n}\nfunction getNumPages(pdfUrl) {\n return __awaiter(this, void 0, void 0, function () {\n var pdf;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4, load(pdfUrl)];\n case 1:\n pdf = _a.sent();\n return [2, pdf.numPages];\n }\n });\n });\n}\nfunction clear(containerId) {\n var container = document.getElementById(containerId);\n var pages = document.querySelectorAll(\"[id^=\\\"\".concat(containerId, \"-page-\\\"]\"));\n pages === null || pages === void 0 ? void 0 : pages.forEach(function (item) {\n container === null || container === void 0 ? void 0 : container.removeChild(item);\n });\n}\nfunction render(_a) {\n var pdfUrl = _a.pdfUrl, containerId = _a.containerId, startPageNum = _a.startPageNum, endPageNum = _a.endPageNum, pixelRatio = _a.pixelRatio, scale = _a.scale;\n return __awaiter(this, void 0, void 0, function () {\n var container, pdf, start, end, i;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n clear(containerId);\n container = document.getElementById(containerId);\n if (!container)\n return [2];\n return [4, load(pdfUrl)];\n case 1:\n pdf = _b.sent();\n start = startPageNum !== null && startPageNum !== void 0 ? startPageNum : 1;\n end = endPageNum !== null && endPageNum !== void 0 ? endPageNum : pdf.numPages;\n for (i = start; i <= end; i++) {\n renderPage({ pdf: pdf, container: container, num: i, pixelRatio: pixelRatio, scale: scale });\n }\n return [2];\n }\n });\n });\n}\nfunction renderPage(_a) {\n var pdf = _a.pdf, container = _a.container, num = _a.num, _b = _a.pixelRatio, pixelRatio = _b === void 0 ? 2 : _b, _c = _a.scale, scale = _c === void 0 ? 1 : _c;\n pdf.getPage(num).then(function (page) {\n var pageDiv = document.createElement('div');\n pageDiv.setAttribute('id', \"\".concat(container.id, \"-page-\").concat(num));\n pageDiv.setAttribute('style', 'position: relative; ');\n container.appendChild(pageDiv);\n var canvas = document.createElement('canvas');\n pageDiv.appendChild(canvas);\n var ctx = canvas.getContext('2d');\n var devicePixelRatio = window.devicePixelRatio * pixelRatio;\n var viewport = page.getViewport({ scale: 1 * devicePixelRatio });\n canvas.style.width = \"calc(100% * \".concat(scale, \")\");\n canvas.style.height = '100%';\n canvas.width = viewport.width;\n canvas.height = viewport.height;\n var renderContext = {\n canvasContext: ctx,\n viewport: viewport\n };\n page.render(renderContext);\n });\n}\nvar RenderPDF = {\n load: load,\n getNumPages: getNumPages,\n clear: clear,\n render: render\n};\nexports[\"default\"] = RenderPDF;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/RenderPDF/index.ts?");
156
+ 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 }));\nvar pdf_js_1 = __webpack_require__(/*! pdfjs-dist/legacy/build/pdf.js */ \"./node_modules/pdfjs-dist/legacy/build/pdf.js\");\npdf_js_1.GlobalWorkerOptions.workerSrc = 'https://cdn.bootcss.com/pdf.js/2.13.216/pdf.worker.js';\nvar PDFMap = new Map();\nfunction load(pdfUrl) {\n return __awaiter(this, void 0, void 0, function () {\n var pdf, loadingTask;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n pdf = PDFMap.get(pdfUrl);\n if (!pdf) {\n loadingTask = (0, pdf_js_1.getDocument)({\n url: pdfUrl,\n cMapUrl: 'https://unpkg.com/browse/pdfjs-dist@2.13.216/cmaps/',\n cMapPacked: true\n });\n pdf = loadingTask.promise;\n PDFMap.set(pdfUrl, pdf);\n }\n return [4, pdf];\n case 1: return [2, _a.sent()];\n }\n });\n });\n}\nfunction getNumPages(pdfUrl) {\n return __awaiter(this, void 0, void 0, function () {\n var pdf;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4, load(pdfUrl)];\n case 1:\n pdf = _a.sent();\n return [2, pdf.numPages];\n }\n });\n });\n}\nfunction clear(containerId) {\n var container = document.getElementById(containerId);\n var pages = document.querySelectorAll(\"[id^=\\\"\".concat(containerId, \"-page-\\\"]\"));\n pages === null || pages === void 0 ? void 0 : pages.forEach(function (item) {\n container === null || container === void 0 ? void 0 : container.removeChild(item);\n });\n}\nfunction render(_a) {\n var pdfUrl = _a.pdfUrl, containerId = _a.containerId, startPageNum = _a.startPageNum, endPageNum = _a.endPageNum, pixelRatio = _a.pixelRatio, scale = _a.scale;\n return __awaiter(this, void 0, void 0, function () {\n var container, pdf, start, end, i;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n clear(containerId);\n container = document.getElementById(containerId);\n if (!container)\n return [2];\n return [4, load(pdfUrl)];\n case 1:\n pdf = _b.sent();\n start = startPageNum !== null && startPageNum !== void 0 ? startPageNum : 1;\n end = endPageNum !== null && endPageNum !== void 0 ? endPageNum : pdf.numPages;\n for (i = start; i <= end; i++) {\n renderPage({ pdf: pdf, container: container, num: i, pixelRatio: pixelRatio, scale: scale });\n }\n return [2];\n }\n });\n });\n}\nfunction renderPage(_a) {\n var pdf = _a.pdf, container = _a.container, num = _a.num, _b = _a.pixelRatio, pixelRatio = _b === void 0 ? 2 : _b, _c = _a.scale, scale = _c === void 0 ? 1 : _c;\n pdf.getPage(num).then(function (page) {\n var pageDiv = document.createElement('div');\n pageDiv.setAttribute('id', \"\".concat(container.id, \"-page-\").concat(num));\n pageDiv.setAttribute('style', 'position: relative; ');\n container.appendChild(pageDiv);\n var canvas = document.createElement('canvas');\n pageDiv.appendChild(canvas);\n var ctx = canvas.getContext('2d');\n var devicePixelRatio = window.devicePixelRatio * pixelRatio;\n var viewport = page.getViewport({ scale: 1 * devicePixelRatio });\n canvas.style.width = \"calc(100% * \".concat(scale, \")\");\n canvas.style.height = '100%';\n canvas.width = viewport.width;\n canvas.height = viewport.height;\n var renderContext = {\n canvasContext: ctx,\n viewport: viewport\n };\n page.render(renderContext);\n });\n}\nvar RenderPDF = {\n load: load,\n getNumPages: getNumPages,\n clear: clear,\n render: render\n};\nexports[\"default\"] = RenderPDF;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/RenderPDF/index.ts?");
157
157
 
158
158
  /***/ }),
159
159