@cecee/document-flip-book 1.0.8
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/cjs/ArchiveCover.d.ts +9 -0
- package/dist/cjs/ArchiveCover.js +142 -0
- package/dist/cjs/DocumentFlipBook.d.ts +32 -0
- package/dist/cjs/DocumentFlipBook.js +644 -0
- package/dist/cjs/ExportModal.d.ts +10 -0
- package/dist/cjs/ExportModal.js +96 -0
- package/dist/cjs/HeaderBar.d.ts +25 -0
- package/dist/cjs/HeaderBar.js +220 -0
- package/dist/cjs/PdfPage.d.ts +9 -0
- package/dist/cjs/PdfPage.js +143 -0
- package/dist/cjs/ProjectCover.d.ts +8 -0
- package/dist/cjs/ProjectCover.js +201 -0
- package/dist/cjs/SideTabs.d.ts +8 -0
- package/dist/cjs/SideTabs.js +34 -0
- package/dist/cjs/exportHtml.d.ts +19 -0
- package/dist/cjs/exportHtml.js +189 -0
- package/dist/cjs/exportPdf.d.ts +27 -0
- package/dist/cjs/exportPdf.js +232 -0
- package/dist/cjs/globalCache.d.ts +5 -0
- package/dist/cjs/globalCache.js +20 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.less +637 -0
- package/dist/cjs/printPdf.d.ts +6 -0
- package/dist/cjs/printPdf.js +51 -0
- package/dist/cjs/types.d.ts +31 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/utils.d.ts +17 -0
- package/dist/cjs/utils.js +220 -0
- package/dist/esm/ArchiveCover.d.ts +9 -0
- package/dist/esm/ArchiveCover.js +136 -0
- package/dist/esm/DocumentFlipBook.d.ts +32 -0
- package/dist/esm/DocumentFlipBook.js +630 -0
- package/dist/esm/ExportModal.d.ts +10 -0
- package/dist/esm/ExportModal.js +88 -0
- package/dist/esm/HeaderBar.d.ts +25 -0
- package/dist/esm/HeaderBar.js +211 -0
- package/dist/esm/PdfPage.d.ts +9 -0
- package/dist/esm/PdfPage.js +136 -0
- package/dist/esm/ProjectCover.d.ts +8 -0
- package/dist/esm/ProjectCover.js +195 -0
- package/dist/esm/SideTabs.d.ts +8 -0
- package/dist/esm/SideTabs.js +27 -0
- package/dist/esm/exportHtml.d.ts +19 -0
- package/dist/esm/exportHtml.js +178 -0
- package/dist/esm/exportPdf.d.ts +27 -0
- package/dist/esm/exportPdf.js +223 -0
- package/dist/esm/globalCache.d.ts +5 -0
- package/dist/esm/globalCache.js +15 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.less +637 -0
- package/dist/esm/printPdf.d.ts +6 -0
- package/dist/esm/printPdf.js +45 -0
- package/dist/esm/types.d.ts +31 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +17 -0
- package/dist/esm/utils.js +214 -0
- package/package.json +57 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var _excluded = ["filename"];
|
|
2
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
11
|
+
import { jsPDF } from 'jspdf';
|
|
12
|
+
export function renderPdfPageToDataUrl(_x) {
|
|
13
|
+
return _renderPdfPageToDataUrl.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
function _renderPdfPageToDataUrl() {
|
|
16
|
+
_renderPdfPageToDataUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
17
|
+
var _page$cleanup;
|
|
18
|
+
var getDocument, file, pageNum, scale, doc, page, viewport, canvas, ctx;
|
|
19
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
20
|
+
while (1) switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
getDocument = params.getDocument, file = params.file, pageNum = params.pageNum, scale = params.scale;
|
|
23
|
+
_context.next = 3;
|
|
24
|
+
return getDocument(file);
|
|
25
|
+
case 3:
|
|
26
|
+
doc = _context.sent;
|
|
27
|
+
_context.next = 6;
|
|
28
|
+
return doc.getPage(pageNum);
|
|
29
|
+
case 6:
|
|
30
|
+
page = _context.sent;
|
|
31
|
+
viewport = page.getViewport({
|
|
32
|
+
scale: scale
|
|
33
|
+
});
|
|
34
|
+
canvas = document.createElement('canvas');
|
|
35
|
+
canvas.width = viewport.width;
|
|
36
|
+
canvas.height = viewport.height;
|
|
37
|
+
ctx = canvas.getContext('2d');
|
|
38
|
+
if (ctx) {
|
|
39
|
+
_context.next = 14;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
throw new Error('Canvas 上下文获取失败');
|
|
43
|
+
case 14:
|
|
44
|
+
_context.next = 16;
|
|
45
|
+
return page.render({
|
|
46
|
+
canvasContext: ctx,
|
|
47
|
+
viewport: viewport
|
|
48
|
+
}).promise;
|
|
49
|
+
case 16:
|
|
50
|
+
(_page$cleanup = page.cleanup) === null || _page$cleanup === void 0 || _page$cleanup.call(page);
|
|
51
|
+
return _context.abrupt("return", {
|
|
52
|
+
dataUrl: canvas.toDataURL('image/jpeg', 0.92),
|
|
53
|
+
width: canvas.width,
|
|
54
|
+
height: canvas.height
|
|
55
|
+
});
|
|
56
|
+
case 18:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context.stop();
|
|
59
|
+
}
|
|
60
|
+
}, _callee);
|
|
61
|
+
}));
|
|
62
|
+
return _renderPdfPageToDataUrl.apply(this, arguments);
|
|
63
|
+
}
|
|
64
|
+
export function renderImageToDataUrl(_x2) {
|
|
65
|
+
return _renderImageToDataUrl.apply(this, arguments);
|
|
66
|
+
}
|
|
67
|
+
function _renderImageToDataUrl() {
|
|
68
|
+
_renderImageToDataUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) {
|
|
69
|
+
var img, canvas, ctx;
|
|
70
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
71
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
img = new Image();
|
|
74
|
+
img.crossOrigin = 'anonymous';
|
|
75
|
+
img.src = file;
|
|
76
|
+
_context2.next = 5;
|
|
77
|
+
return new Promise(function (resolve, reject) {
|
|
78
|
+
img.onload = function () {
|
|
79
|
+
return resolve();
|
|
80
|
+
};
|
|
81
|
+
img.onerror = function () {
|
|
82
|
+
return reject(new Error('图片加载失败'));
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
case 5:
|
|
86
|
+
canvas = document.createElement('canvas');
|
|
87
|
+
canvas.width = img.naturalWidth || img.width;
|
|
88
|
+
canvas.height = img.naturalHeight || img.height;
|
|
89
|
+
ctx = canvas.getContext('2d');
|
|
90
|
+
if (ctx) {
|
|
91
|
+
_context2.next = 11;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
throw new Error('Canvas 上下文获取失败');
|
|
95
|
+
case 11:
|
|
96
|
+
ctx.drawImage(img, 0, 0);
|
|
97
|
+
return _context2.abrupt("return", {
|
|
98
|
+
dataUrl: canvas.toDataURL('image/jpeg', 0.92),
|
|
99
|
+
width: canvas.width,
|
|
100
|
+
height: canvas.height
|
|
101
|
+
});
|
|
102
|
+
case 13:
|
|
103
|
+
case "end":
|
|
104
|
+
return _context2.stop();
|
|
105
|
+
}
|
|
106
|
+
}, _callee2);
|
|
107
|
+
}));
|
|
108
|
+
return _renderImageToDataUrl.apply(this, arguments);
|
|
109
|
+
}
|
|
110
|
+
export function buildArchivePdfBlob(_x3) {
|
|
111
|
+
return _buildArchivePdfBlob.apply(this, arguments);
|
|
112
|
+
}
|
|
113
|
+
function _buildArchivePdfBlob() {
|
|
114
|
+
_buildArchivePdfBlob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
115
|
+
var pages, getDocument, _params$scale, scale, pdf, first, _iterator, _step, p, img, pageW, pageH, _img, _pageW, _pageH;
|
|
116
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
117
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
pages = params.pages, getDocument = params.getDocument, _params$scale = params.scale, scale = _params$scale === void 0 ? 2 : _params$scale;
|
|
120
|
+
pdf = new jsPDF({
|
|
121
|
+
unit: 'pt',
|
|
122
|
+
compress: true
|
|
123
|
+
});
|
|
124
|
+
first = true;
|
|
125
|
+
_iterator = _createForOfIteratorHelper(pages);
|
|
126
|
+
_context3.prev = 4;
|
|
127
|
+
_iterator.s();
|
|
128
|
+
case 6:
|
|
129
|
+
if ((_step = _iterator.n()).done) {
|
|
130
|
+
_context3.next = 30;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
p = _step.value;
|
|
134
|
+
if (!(p.type === 'pdf')) {
|
|
135
|
+
_context3.next = 18;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
_context3.next = 11;
|
|
139
|
+
return renderPdfPageToDataUrl({
|
|
140
|
+
getDocument: getDocument,
|
|
141
|
+
file: p.file,
|
|
142
|
+
pageNum: p.pageNum,
|
|
143
|
+
scale: scale
|
|
144
|
+
});
|
|
145
|
+
case 11:
|
|
146
|
+
img = _context3.sent;
|
|
147
|
+
pageW = pdf.internal.pageSize.getWidth();
|
|
148
|
+
pageH = img.height / img.width * pageW;
|
|
149
|
+
if (!first) pdf.addPage();
|
|
150
|
+
pdf.addImage(img.dataUrl, 'JPEG', 0, 0, pageW, pageH);
|
|
151
|
+
first = false;
|
|
152
|
+
return _context3.abrupt("continue", 28);
|
|
153
|
+
case 18:
|
|
154
|
+
if (!(p.type === 'image')) {
|
|
155
|
+
_context3.next = 28;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
_context3.next = 21;
|
|
159
|
+
return renderImageToDataUrl(p.file);
|
|
160
|
+
case 21:
|
|
161
|
+
_img = _context3.sent;
|
|
162
|
+
_pageW = pdf.internal.pageSize.getWidth();
|
|
163
|
+
_pageH = _img.height / _img.width * _pageW;
|
|
164
|
+
if (!first) pdf.addPage();
|
|
165
|
+
pdf.addImage(_img.dataUrl, 'JPEG', 0, 0, _pageW, _pageH);
|
|
166
|
+
first = false;
|
|
167
|
+
return _context3.abrupt("continue", 28);
|
|
168
|
+
case 28:
|
|
169
|
+
_context3.next = 6;
|
|
170
|
+
break;
|
|
171
|
+
case 30:
|
|
172
|
+
_context3.next = 35;
|
|
173
|
+
break;
|
|
174
|
+
case 32:
|
|
175
|
+
_context3.prev = 32;
|
|
176
|
+
_context3.t0 = _context3["catch"](4);
|
|
177
|
+
_iterator.e(_context3.t0);
|
|
178
|
+
case 35:
|
|
179
|
+
_context3.prev = 35;
|
|
180
|
+
_iterator.f();
|
|
181
|
+
return _context3.finish(35);
|
|
182
|
+
case 38:
|
|
183
|
+
return _context3.abrupt("return", pdf.output('blob'));
|
|
184
|
+
case 39:
|
|
185
|
+
case "end":
|
|
186
|
+
return _context3.stop();
|
|
187
|
+
}
|
|
188
|
+
}, _callee3, null, [[4, 32, 35, 38]]);
|
|
189
|
+
}));
|
|
190
|
+
return _buildArchivePdfBlob.apply(this, arguments);
|
|
191
|
+
}
|
|
192
|
+
export function exportArchivePagesToPdf(_x4) {
|
|
193
|
+
return _exportArchivePagesToPdf.apply(this, arguments);
|
|
194
|
+
}
|
|
195
|
+
function _exportArchivePagesToPdf() {
|
|
196
|
+
_exportArchivePagesToPdf = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
197
|
+
var filename, rest, blob, url, a;
|
|
198
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
199
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
200
|
+
case 0:
|
|
201
|
+
filename = params.filename, rest = _objectWithoutProperties(params, _excluded);
|
|
202
|
+
_context4.next = 3;
|
|
203
|
+
return buildArchivePdfBlob(rest);
|
|
204
|
+
case 3:
|
|
205
|
+
blob = _context4.sent;
|
|
206
|
+
url = URL.createObjectURL(blob);
|
|
207
|
+
a = document.createElement('a');
|
|
208
|
+
a.href = url;
|
|
209
|
+
a.download = filename;
|
|
210
|
+
document.body.appendChild(a);
|
|
211
|
+
a.click();
|
|
212
|
+
a.remove();
|
|
213
|
+
setTimeout(function () {
|
|
214
|
+
return URL.revokeObjectURL(url);
|
|
215
|
+
}, 1000);
|
|
216
|
+
case 12:
|
|
217
|
+
case "end":
|
|
218
|
+
return _context4.stop();
|
|
219
|
+
}
|
|
220
|
+
}, _callee4);
|
|
221
|
+
}));
|
|
222
|
+
return _exportArchivePagesToPdf.apply(this, arguments);
|
|
223
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { pdfjs } from 'react-pdf';
|
|
8
|
+
import { createPdfDocumentCache, PDF_OPTIONS, PDF_PRELOAD_TIMEOUT, withTimeout } from "./utils";
|
|
9
|
+
|
|
10
|
+
// 全局 PDF 缓存实例,确保切换路由时不丢失已解析的 PDF 对象
|
|
11
|
+
export var globalPdfCache = createPdfDocumentCache(function (path) {
|
|
12
|
+
return withTimeout(pdfjs.getDocument(_objectSpread({
|
|
13
|
+
url: path
|
|
14
|
+
}, PDF_OPTIONS)).promise, PDF_PRELOAD_TIMEOUT, '加载超时');
|
|
15
|
+
});
|