@cecee/document-flip-book 1.0.18 → 1.0.20
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/AccountingBook/assets/active-line.png +0 -0
- package/dist/cjs/AccountingBook/assets/default-line.png +0 -0
- package/dist/cjs/AccountingBook/assets/filp-bg.png +0 -0
- package/dist/cjs/AccountingBook/components/AccountingVoucher/index.d.ts +26 -0
- package/dist/cjs/AccountingBook/components/AccountingVoucher/index.js +398 -0
- package/dist/cjs/AccountingBook/components/AccountingVoucher/index.less +231 -0
- package/dist/cjs/AccountingBook/components/ExportModal.d.ts +10 -0
- package/dist/cjs/AccountingBook/components/ExportModal.js +96 -0
- package/dist/cjs/AccountingBook/components/FilpPage.d.ts +7 -0
- package/dist/cjs/AccountingBook/components/FilpPage.js +39 -0
- package/dist/cjs/AccountingBook/components/HeaderBar.d.ts +28 -0
- package/dist/cjs/AccountingBook/components/HeaderBar.js +245 -0
- package/dist/cjs/AccountingBook/components/ImagePageRenderer.d.ts +11 -0
- package/dist/cjs/AccountingBook/components/ImagePageRenderer.js +91 -0
- package/dist/cjs/AccountingBook/components/LoadingComponent.d.ts +7 -0
- package/dist/cjs/AccountingBook/components/LoadingComponent.js +54 -0
- package/dist/cjs/AccountingBook/components/PDFPageRenderer.d.ts +13 -0
- package/dist/cjs/AccountingBook/components/PDFPageRenderer.js +259 -0
- package/dist/cjs/AccountingBook/components/index.less +6 -0
- package/dist/cjs/AccountingBook/constants.d.ts +11 -0
- package/dist/cjs/AccountingBook/constants.js +25 -0
- package/dist/cjs/AccountingBook/hooks/useAmountSearch.d.ts +24 -0
- package/dist/cjs/AccountingBook/hooks/useAmountSearch.js +165 -0
- package/dist/cjs/AccountingBook/hooks/usePageFlip.d.ts +15 -0
- package/dist/cjs/AccountingBook/hooks/usePageFlip.js +67 -0
- package/dist/cjs/AccountingBook/index.d.ts +29 -1
- package/dist/cjs/AccountingBook/index.js +1163 -7
- package/dist/cjs/AccountingBook/index.less +188 -0
- package/dist/cjs/AccountingBook/types.d.ts +84 -0
- package/dist/cjs/AccountingBook/types.js +5 -0
- package/dist/cjs/AccountingBook/utils/canvasUtils.d.ts +51 -0
- package/dist/cjs/AccountingBook/utils/canvasUtils.js +499 -0
- package/dist/cjs/AccountingBook/utils/html.d.ts +9 -0
- package/dist/cjs/AccountingBook/utils/html.js +97 -0
- package/dist/cjs/AccountingBook/utils/utils.d.ts +38 -0
- package/dist/cjs/AccountingBook/utils/utils.js +204 -0
- package/dist/cjs/DocumentFlipBook/ExportModal.d.ts +1 -1
- package/dist/cjs/DocumentFlipBook/ExportModal.js +1 -1
- package/dist/cjs/DocumentFlipBook/HeaderBar.d.ts +2 -1
- package/dist/cjs/DocumentFlipBook/HeaderBar.js +13 -11
- package/dist/cjs/DocumentFlipBook/SideTabs.js +111 -6
- package/dist/cjs/DocumentFlipBook/index.d.ts +1 -0
- package/dist/cjs/DocumentFlipBook/index.js +9 -6
- package/dist/cjs/DocumentFlipBook/index.less +239 -12
- package/dist/cjs/declarations.d.ts +21 -0
- package/dist/esm/AccountingBook/assets/active-line.png +0 -0
- package/dist/esm/AccountingBook/assets/default-line.png +0 -0
- package/dist/esm/AccountingBook/assets/filp-bg.png +0 -0
- package/dist/esm/AccountingBook/components/AccountingVoucher/index.d.ts +26 -0
- package/dist/esm/AccountingBook/components/AccountingVoucher/index.js +391 -0
- package/dist/esm/AccountingBook/components/AccountingVoucher/index.less +231 -0
- package/dist/esm/AccountingBook/components/ExportModal.d.ts +10 -0
- package/dist/esm/AccountingBook/components/ExportModal.js +88 -0
- package/dist/esm/AccountingBook/components/FilpPage.d.ts +7 -0
- package/dist/esm/AccountingBook/components/FilpPage.js +33 -0
- package/dist/esm/AccountingBook/components/HeaderBar.d.ts +28 -0
- package/dist/esm/AccountingBook/components/HeaderBar.js +236 -0
- package/dist/esm/AccountingBook/components/ImagePageRenderer.d.ts +11 -0
- package/dist/esm/AccountingBook/components/ImagePageRenderer.js +85 -0
- package/dist/esm/AccountingBook/components/LoadingComponent.d.ts +7 -0
- package/dist/esm/AccountingBook/components/LoadingComponent.js +48 -0
- package/dist/esm/AccountingBook/components/PDFPageRenderer.d.ts +13 -0
- package/dist/esm/AccountingBook/components/PDFPageRenderer.js +252 -0
- package/dist/esm/AccountingBook/components/index.less +6 -0
- package/dist/esm/AccountingBook/constants.d.ts +11 -0
- package/dist/esm/AccountingBook/constants.js +17 -0
- package/dist/esm/AccountingBook/hooks/useAmountSearch.d.ts +24 -0
- package/dist/esm/AccountingBook/hooks/useAmountSearch.js +158 -0
- package/dist/esm/AccountingBook/hooks/usePageFlip.d.ts +15 -0
- package/dist/esm/AccountingBook/hooks/usePageFlip.js +61 -0
- package/dist/esm/AccountingBook/index.d.ts +29 -1
- package/dist/esm/AccountingBook/index.js +1162 -6
- package/dist/esm/AccountingBook/index.less +188 -0
- package/dist/esm/AccountingBook/types.d.ts +84 -0
- package/dist/esm/AccountingBook/types.js +1 -0
- package/dist/esm/AccountingBook/utils/canvasUtils.d.ts +51 -0
- package/dist/esm/AccountingBook/utils/canvasUtils.js +493 -0
- package/dist/esm/AccountingBook/utils/html.d.ts +9 -0
- package/dist/esm/AccountingBook/utils/html.js +89 -0
- package/dist/esm/AccountingBook/utils/utils.d.ts +38 -0
- package/dist/esm/AccountingBook/utils/utils.js +195 -0
- package/dist/esm/DocumentFlipBook/ExportModal.d.ts +1 -1
- package/dist/esm/DocumentFlipBook/ExportModal.js +1 -1
- package/dist/esm/DocumentFlipBook/HeaderBar.d.ts +2 -1
- package/dist/esm/DocumentFlipBook/HeaderBar.js +13 -11
- package/dist/esm/DocumentFlipBook/SideTabs.js +110 -5
- package/dist/esm/DocumentFlipBook/index.d.ts +1 -0
- package/dist/esm/DocumentFlipBook/index.js +9 -6
- package/dist/esm/DocumentFlipBook/index.less +239 -12
- package/dist/esm/declarations.d.ts +21 -0
- package/package.json +8 -2
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.renderPDFPageToImageBase64 = exports.preloadAndConvertImage = exports.extractAttachmentInfo = exports.createVoucherCanvas = exports.createImageElementFromBase64 = exports.createImageElementDirect = exports.createCoverCanvas = exports.createAttachmentCanvasFixed = exports.batchPreloadImages = void 0;
|
|
8
|
+
var _html2canvas = _interopRequireDefault(require("html2canvas"));
|
|
9
|
+
var _reactPdf = require("react-pdf");
|
|
10
|
+
var _PDFPageRenderer = require("../components/PDFPageRenderer");
|
|
11
|
+
var _ImagePageRenderer = require("../components/ImagePageRenderer");
|
|
12
|
+
var _html = require("./html");
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
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; }
|
|
16
|
+
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); } }
|
|
17
|
+
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); }); }; }
|
|
18
|
+
// ====================== 全局工具:图片/PDF/Canvas 处理 ======================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 预加载单张图片并转 Base64
|
|
22
|
+
*/
|
|
23
|
+
var preloadAndConvertImage = exports.preloadAndConvertImage = function preloadAndConvertImage(url) {
|
|
24
|
+
return new Promise(function (resolve) {
|
|
25
|
+
var img = new Image();
|
|
26
|
+
var timeout = setTimeout(function () {
|
|
27
|
+
console.warn('图片加载超时:', url);
|
|
28
|
+
resolve(null);
|
|
29
|
+
}, 30000);
|
|
30
|
+
img.onload = function () {
|
|
31
|
+
clearTimeout(timeout);
|
|
32
|
+
try {
|
|
33
|
+
var canvas = document.createElement('canvas');
|
|
34
|
+
var ctx = canvas.getContext('2d');
|
|
35
|
+
canvas.width = img.naturalWidth;
|
|
36
|
+
canvas.height = img.naturalHeight;
|
|
37
|
+
if (ctx) {
|
|
38
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
39
|
+
ctx.drawImage(img, 0, 0);
|
|
40
|
+
var base64 = canvas.toDataURL('image/png');
|
|
41
|
+
resolve(base64);
|
|
42
|
+
} else {
|
|
43
|
+
resolve(null);
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('图片转换失败:', url, error);
|
|
47
|
+
resolve(null);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
img.onerror = function (error) {
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
console.error('图片加载失败:', url, error);
|
|
53
|
+
resolve(null);
|
|
54
|
+
};
|
|
55
|
+
img.crossOrigin = 'anonymous';
|
|
56
|
+
var imageUrl = url.includes('?') ? "".concat(url, "&_t=").concat(Date.now()) : "".concat(url, "?_t=").concat(Date.now());
|
|
57
|
+
img.src = imageUrl;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 批量预加载图片
|
|
63
|
+
*/
|
|
64
|
+
var batchPreloadImages = exports.batchPreloadImages = /*#__PURE__*/function () {
|
|
65
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(imageUrls) {
|
|
66
|
+
var imageMap, batchSize, i, batch, promises;
|
|
67
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
68
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
69
|
+
case 0:
|
|
70
|
+
console.log("\u5F00\u59CB\u6279\u91CF\u9884\u52A0\u8F7D ".concat(imageUrls.length, " \u5F20\u56FE\u7247"));
|
|
71
|
+
imageMap = new Map();
|
|
72
|
+
batchSize = 3;
|
|
73
|
+
i = 0;
|
|
74
|
+
case 4:
|
|
75
|
+
if (!(i < imageUrls.length)) {
|
|
76
|
+
_context2.next = 15;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
batch = imageUrls.slice(i, i + batchSize);
|
|
80
|
+
promises = batch.map( /*#__PURE__*/function () {
|
|
81
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
|
82
|
+
var base64;
|
|
83
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
84
|
+
while (1) switch (_context.prev = _context.next) {
|
|
85
|
+
case 0:
|
|
86
|
+
_context.next = 2;
|
|
87
|
+
return preloadAndConvertImage(url);
|
|
88
|
+
case 2:
|
|
89
|
+
base64 = _context.sent;
|
|
90
|
+
if (base64) imageMap.set(url, base64);
|
|
91
|
+
return _context.abrupt("return", {
|
|
92
|
+
url: url,
|
|
93
|
+
success: !!base64
|
|
94
|
+
});
|
|
95
|
+
case 5:
|
|
96
|
+
case "end":
|
|
97
|
+
return _context.stop();
|
|
98
|
+
}
|
|
99
|
+
}, _callee);
|
|
100
|
+
}));
|
|
101
|
+
return function (_x2) {
|
|
102
|
+
return _ref2.apply(this, arguments);
|
|
103
|
+
};
|
|
104
|
+
}());
|
|
105
|
+
_context2.next = 9;
|
|
106
|
+
return Promise.all(promises);
|
|
107
|
+
case 9:
|
|
108
|
+
if (!(i + batchSize < imageUrls.length)) {
|
|
109
|
+
_context2.next = 12;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
_context2.next = 12;
|
|
113
|
+
return new Promise(function (resolve) {
|
|
114
|
+
return setTimeout(resolve, 500);
|
|
115
|
+
});
|
|
116
|
+
case 12:
|
|
117
|
+
i += batchSize;
|
|
118
|
+
_context2.next = 4;
|
|
119
|
+
break;
|
|
120
|
+
case 15:
|
|
121
|
+
console.log("\u56FE\u7247\u9884\u52A0\u8F7D\u5B8C\u6210: ".concat(imageMap.size, "/").concat(imageUrls.length));
|
|
122
|
+
return _context2.abrupt("return", imageMap);
|
|
123
|
+
case 17:
|
|
124
|
+
case "end":
|
|
125
|
+
return _context2.stop();
|
|
126
|
+
}
|
|
127
|
+
}, _callee2);
|
|
128
|
+
}));
|
|
129
|
+
return function batchPreloadImages(_x) {
|
|
130
|
+
return _ref.apply(this, arguments);
|
|
131
|
+
};
|
|
132
|
+
}();
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 从 React 节点提取附件信息
|
|
136
|
+
*/
|
|
137
|
+
var extractAttachmentInfo = exports.extractAttachmentInfo = function extractAttachmentInfo(pageElement) {
|
|
138
|
+
try {
|
|
139
|
+
if (pageElement.type === _ImagePageRenderer.ImagePageRenderer) {
|
|
140
|
+
return {
|
|
141
|
+
type: 'image',
|
|
142
|
+
src: pageElement.props.src,
|
|
143
|
+
alt: pageElement.props.alt || '',
|
|
144
|
+
attachmentCount: pageElement.props.attachmentCount || 1,
|
|
145
|
+
amount: pageElement.props.amount || '0.00'
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (pageElement.type === _PDFPageRenderer.PDFPageRenderer) {
|
|
149
|
+
return {
|
|
150
|
+
type: 'pdf',
|
|
151
|
+
src: pageElement.props.pdfPath,
|
|
152
|
+
pageNumber: pageElement.props.pageNumber || 1,
|
|
153
|
+
attachmentCount: pageElement.props.attachmentCount || 1,
|
|
154
|
+
amount: pageElement.props.amount || '0.00'
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
var props = pageElement.props;
|
|
158
|
+
if (props && props.children && /*#__PURE__*/_react.default.isValidElement(props.children)) {
|
|
159
|
+
var childProps = props.children.props;
|
|
160
|
+
if (childProps) {
|
|
161
|
+
if (childProps.src && !childProps.pdfPath) {
|
|
162
|
+
return {
|
|
163
|
+
type: 'image',
|
|
164
|
+
src: childProps.src,
|
|
165
|
+
alt: childProps.alt || '',
|
|
166
|
+
attachmentCount: childProps.attachmentCount || 1,
|
|
167
|
+
amount: childProps.amount || '0.00'
|
|
168
|
+
};
|
|
169
|
+
} else if (childProps.pdfPath) {
|
|
170
|
+
return {
|
|
171
|
+
type: 'pdf',
|
|
172
|
+
src: childProps.pdfPath,
|
|
173
|
+
pageNumber: childProps.pageNumber || 1,
|
|
174
|
+
attachmentCount: childProps.attachmentCount || 1,
|
|
175
|
+
amount: childProps.amount || '0.00'
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error('提取附件信息失败:', error);
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Base64 转图片元素
|
|
189
|
+
*/
|
|
190
|
+
var createImageElementFromBase64 = exports.createImageElementFromBase64 = function createImageElementFromBase64(base64Data) {
|
|
191
|
+
return new Promise(function (resolve) {
|
|
192
|
+
var img = new Image();
|
|
193
|
+
img.onload = function () {
|
|
194
|
+
return resolve(img);
|
|
195
|
+
};
|
|
196
|
+
img.onerror = function () {
|
|
197
|
+
return resolve(null);
|
|
198
|
+
};
|
|
199
|
+
img.src = base64Data;
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 直接通过 URL 创建图片元素
|
|
205
|
+
*/
|
|
206
|
+
var createImageElementDirect = exports.createImageElementDirect = function createImageElementDirect(imageSrc) {
|
|
207
|
+
return new Promise(function (resolve) {
|
|
208
|
+
var img = new Image();
|
|
209
|
+
var timeout = setTimeout(function () {
|
|
210
|
+
console.error('直接图片加载超时:', imageSrc);
|
|
211
|
+
resolve(null);
|
|
212
|
+
}, 15000);
|
|
213
|
+
img.onload = function () {
|
|
214
|
+
clearTimeout(timeout);
|
|
215
|
+
resolve(img);
|
|
216
|
+
};
|
|
217
|
+
img.onerror = function () {
|
|
218
|
+
clearTimeout(timeout);
|
|
219
|
+
resolve(null);
|
|
220
|
+
};
|
|
221
|
+
img.crossOrigin = 'anonymous';
|
|
222
|
+
img.src = imageSrc;
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* PDF 页面转图片 Base64
|
|
228
|
+
*/
|
|
229
|
+
var renderPDFPageToImageBase64 = exports.renderPDFPageToImageBase64 = /*#__PURE__*/function () {
|
|
230
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(pdfPath) {
|
|
231
|
+
var pageNumber,
|
|
232
|
+
pdf,
|
|
233
|
+
page,
|
|
234
|
+
canvas,
|
|
235
|
+
context,
|
|
236
|
+
scale,
|
|
237
|
+
viewport,
|
|
238
|
+
_args3 = arguments;
|
|
239
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
240
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
241
|
+
case 0:
|
|
242
|
+
pageNumber = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 1;
|
|
243
|
+
_context3.prev = 1;
|
|
244
|
+
_context3.next = 4;
|
|
245
|
+
return _reactPdf.pdfjs.getDocument({
|
|
246
|
+
url: pdfPath,
|
|
247
|
+
cMapUrl: "https://unpkg.com/pdfjs-dist@".concat(_reactPdf.pdfjs.version, "/cmaps/"),
|
|
248
|
+
cMapPacked: true
|
|
249
|
+
}).promise;
|
|
250
|
+
case 4:
|
|
251
|
+
pdf = _context3.sent;
|
|
252
|
+
_context3.next = 7;
|
|
253
|
+
return pdf.getPage(pageNumber);
|
|
254
|
+
case 7:
|
|
255
|
+
page = _context3.sent;
|
|
256
|
+
canvas = document.createElement('canvas');
|
|
257
|
+
context = canvas.getContext('2d');
|
|
258
|
+
scale = 2.0;
|
|
259
|
+
viewport = page.getViewport({
|
|
260
|
+
scale: scale
|
|
261
|
+
});
|
|
262
|
+
canvas.width = viewport.width;
|
|
263
|
+
canvas.height = viewport.height;
|
|
264
|
+
if (context) {
|
|
265
|
+
_context3.next = 16;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
throw new Error('Canvas 上下文获取失败');
|
|
269
|
+
case 16:
|
|
270
|
+
_context3.next = 18;
|
|
271
|
+
return page.render({
|
|
272
|
+
canvas: canvas,
|
|
273
|
+
canvasContext: context,
|
|
274
|
+
viewport: viewport
|
|
275
|
+
}).promise;
|
|
276
|
+
case 18:
|
|
277
|
+
return _context3.abrupt("return", canvas.toDataURL('image/jpeg', 0.9));
|
|
278
|
+
case 21:
|
|
279
|
+
_context3.prev = 21;
|
|
280
|
+
_context3.t0 = _context3["catch"](1);
|
|
281
|
+
console.error('PDF转图片失败:', _context3.t0);
|
|
282
|
+
return _context3.abrupt("return", null);
|
|
283
|
+
case 25:
|
|
284
|
+
case "end":
|
|
285
|
+
return _context3.stop();
|
|
286
|
+
}
|
|
287
|
+
}, _callee3, null, [[1, 21]]);
|
|
288
|
+
}));
|
|
289
|
+
return function renderPDFPageToImageBase64(_x3) {
|
|
290
|
+
return _ref3.apply(this, arguments);
|
|
291
|
+
};
|
|
292
|
+
}();
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 创建凭证 Canvas(用于导出)
|
|
296
|
+
*/
|
|
297
|
+
var createVoucherCanvas = exports.createVoucherCanvas = /*#__PURE__*/function () {
|
|
298
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(voucherProps, baseVoucherInfo) {
|
|
299
|
+
var pageDiv;
|
|
300
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
301
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
302
|
+
case 0:
|
|
303
|
+
pageDiv = document.createElement('div');
|
|
304
|
+
pageDiv.style.cssText = "\n position: absolute; left: -9999px; top: -9999px;\n width: 998px; height: 520px; background: #fff;\n ";
|
|
305
|
+
pageDiv.innerHTML = (0, _html.getVoucherCanvasHtml)(voucherProps, baseVoucherInfo);
|
|
306
|
+
document.body.appendChild(pageDiv);
|
|
307
|
+
_context4.prev = 4;
|
|
308
|
+
_context4.next = 7;
|
|
309
|
+
return new Promise(function (r) {
|
|
310
|
+
return setTimeout(r, 200);
|
|
311
|
+
});
|
|
312
|
+
case 7:
|
|
313
|
+
_context4.next = 9;
|
|
314
|
+
return (0, _html2canvas.default)(pageDiv, {
|
|
315
|
+
width: 998,
|
|
316
|
+
height: 520,
|
|
317
|
+
scale: 1.5,
|
|
318
|
+
useCORS: true,
|
|
319
|
+
allowTaint: false,
|
|
320
|
+
backgroundColor: '#fff',
|
|
321
|
+
logging: false
|
|
322
|
+
});
|
|
323
|
+
case 9:
|
|
324
|
+
return _context4.abrupt("return", _context4.sent);
|
|
325
|
+
case 12:
|
|
326
|
+
_context4.prev = 12;
|
|
327
|
+
_context4.t0 = _context4["catch"](4);
|
|
328
|
+
console.error('凭证画布生成失败', _context4.t0);
|
|
329
|
+
return _context4.abrupt("return", null);
|
|
330
|
+
case 16:
|
|
331
|
+
_context4.prev = 16;
|
|
332
|
+
document.body.contains(pageDiv) && document.body.removeChild(pageDiv);
|
|
333
|
+
return _context4.finish(16);
|
|
334
|
+
case 19:
|
|
335
|
+
case "end":
|
|
336
|
+
return _context4.stop();
|
|
337
|
+
}
|
|
338
|
+
}, _callee4, null, [[4, 12, 16, 19]]);
|
|
339
|
+
}));
|
|
340
|
+
return function createVoucherCanvas(_x4, _x5) {
|
|
341
|
+
return _ref4.apply(this, arguments);
|
|
342
|
+
};
|
|
343
|
+
}();
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 创建附件 Canvas
|
|
347
|
+
*/
|
|
348
|
+
var createAttachmentCanvasFixed = exports.createAttachmentCanvasFixed = /*#__PURE__*/function () {
|
|
349
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(attachmentInfo, preloadedImages) {
|
|
350
|
+
var container, attachmentDiv, contentDiv, loadingPlaceholder, imageElement, base64, pdfBase64;
|
|
351
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
352
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
353
|
+
case 0:
|
|
354
|
+
container = document.createElement('div');
|
|
355
|
+
container.style.cssText = "\n position: absolute; left: -9999px; top: -9999px;\n width: 998px; height: 520px; background: white;\n ";
|
|
356
|
+
document.body.appendChild(container);
|
|
357
|
+
_context5.prev = 3;
|
|
358
|
+
attachmentDiv = document.createElement('div');
|
|
359
|
+
attachmentDiv.innerHTML = (0, _html.getAttachmentCanvasHtml)(attachmentInfo);
|
|
360
|
+
container.appendChild(attachmentDiv);
|
|
361
|
+
contentDiv = attachmentDiv.querySelector('#attachment-content');
|
|
362
|
+
loadingPlaceholder = attachmentDiv.querySelector('#loading-placeholder');
|
|
363
|
+
imageElement = null;
|
|
364
|
+
if (!(attachmentInfo.type === 'image')) {
|
|
365
|
+
_context5.next = 23;
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
base64 = preloadedImages.get(attachmentInfo.src);
|
|
369
|
+
if (!base64) {
|
|
370
|
+
_context5.next = 18;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
_context5.next = 15;
|
|
374
|
+
return createImageElementFromBase64(base64);
|
|
375
|
+
case 15:
|
|
376
|
+
imageElement = _context5.sent;
|
|
377
|
+
_context5.next = 21;
|
|
378
|
+
break;
|
|
379
|
+
case 18:
|
|
380
|
+
_context5.next = 20;
|
|
381
|
+
return createImageElementDirect(attachmentInfo.src);
|
|
382
|
+
case 20:
|
|
383
|
+
imageElement = _context5.sent;
|
|
384
|
+
case 21:
|
|
385
|
+
_context5.next = 31;
|
|
386
|
+
break;
|
|
387
|
+
case 23:
|
|
388
|
+
if (!(attachmentInfo.type === 'pdf')) {
|
|
389
|
+
_context5.next = 31;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
_context5.next = 26;
|
|
393
|
+
return renderPDFPageToImageBase64(attachmentInfo.src, attachmentInfo.pageNumber || 1);
|
|
394
|
+
case 26:
|
|
395
|
+
pdfBase64 = _context5.sent;
|
|
396
|
+
if (!pdfBase64) {
|
|
397
|
+
_context5.next = 31;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
_context5.next = 30;
|
|
401
|
+
return createImageElementFromBase64(pdfBase64);
|
|
402
|
+
case 30:
|
|
403
|
+
imageElement = _context5.sent;
|
|
404
|
+
case 31:
|
|
405
|
+
if (!(imageElement && contentDiv)) {
|
|
406
|
+
_context5.next = 37;
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
loadingPlaceholder.style.display = 'none';
|
|
410
|
+
imageElement.style.cssText = "max-width:95%;max-height:95%;object-fit:contain";
|
|
411
|
+
contentDiv.appendChild(imageElement);
|
|
412
|
+
_context5.next = 37;
|
|
413
|
+
return new Promise(function (r) {
|
|
414
|
+
return setTimeout(r, 800);
|
|
415
|
+
});
|
|
416
|
+
case 37:
|
|
417
|
+
_context5.next = 39;
|
|
418
|
+
return (0, _html2canvas.default)(attachmentDiv, {
|
|
419
|
+
width: 998,
|
|
420
|
+
height: 520,
|
|
421
|
+
scale: 1.5,
|
|
422
|
+
useCORS: false,
|
|
423
|
+
allowTaint: true,
|
|
424
|
+
backgroundColor: '#fff',
|
|
425
|
+
logging: false
|
|
426
|
+
});
|
|
427
|
+
case 39:
|
|
428
|
+
return _context5.abrupt("return", _context5.sent);
|
|
429
|
+
case 42:
|
|
430
|
+
_context5.prev = 42;
|
|
431
|
+
_context5.t0 = _context5["catch"](3);
|
|
432
|
+
console.error('附件画布生成失败', _context5.t0);
|
|
433
|
+
return _context5.abrupt("return", null);
|
|
434
|
+
case 46:
|
|
435
|
+
_context5.prev = 46;
|
|
436
|
+
document.body.contains(container) && document.body.removeChild(container);
|
|
437
|
+
return _context5.finish(46);
|
|
438
|
+
case 49:
|
|
439
|
+
case "end":
|
|
440
|
+
return _context5.stop();
|
|
441
|
+
}
|
|
442
|
+
}, _callee5, null, [[3, 42, 46, 49]]);
|
|
443
|
+
}));
|
|
444
|
+
return function createAttachmentCanvasFixed(_x6, _x7) {
|
|
445
|
+
return _ref5.apply(this, arguments);
|
|
446
|
+
};
|
|
447
|
+
}();
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* 创建封面 Canvas
|
|
451
|
+
*/
|
|
452
|
+
var createCoverCanvas = exports.createCoverCanvas = /*#__PURE__*/function () {
|
|
453
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(coverData, companyName) {
|
|
454
|
+
var container, coverDiv;
|
|
455
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
456
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
457
|
+
case 0:
|
|
458
|
+
container = document.createElement('div');
|
|
459
|
+
container.style.cssText = "\n position: absolute; left: -9999px; top: -9999px;\n width: 998px; height: 520px; background: white;\n ";
|
|
460
|
+
document.body.appendChild(container);
|
|
461
|
+
_context6.prev = 3;
|
|
462
|
+
coverDiv = document.createElement('div');
|
|
463
|
+
coverDiv.innerHTML = (0, _html.getCoverCanvasHtml)(coverData, companyName);
|
|
464
|
+
container.appendChild(coverDiv);
|
|
465
|
+
_context6.next = 9;
|
|
466
|
+
return new Promise(function (r) {
|
|
467
|
+
return setTimeout(r, 300);
|
|
468
|
+
});
|
|
469
|
+
case 9:
|
|
470
|
+
_context6.next = 11;
|
|
471
|
+
return (0, _html2canvas.default)(coverDiv, {
|
|
472
|
+
width: 998,
|
|
473
|
+
height: 520,
|
|
474
|
+
scale: 1.5,
|
|
475
|
+
useCORS: true,
|
|
476
|
+
backgroundColor: '#CBA172',
|
|
477
|
+
logging: false
|
|
478
|
+
});
|
|
479
|
+
case 11:
|
|
480
|
+
return _context6.abrupt("return", _context6.sent);
|
|
481
|
+
case 14:
|
|
482
|
+
_context6.prev = 14;
|
|
483
|
+
_context6.t0 = _context6["catch"](3);
|
|
484
|
+
console.error('封面生成失败', _context6.t0);
|
|
485
|
+
return _context6.abrupt("return", null);
|
|
486
|
+
case 18:
|
|
487
|
+
_context6.prev = 18;
|
|
488
|
+
document.body.contains(container) && document.body.removeChild(container);
|
|
489
|
+
return _context6.finish(18);
|
|
490
|
+
case 21:
|
|
491
|
+
case "end":
|
|
492
|
+
return _context6.stop();
|
|
493
|
+
}
|
|
494
|
+
}, _callee6, null, [[3, 14, 18, 21]]);
|
|
495
|
+
}));
|
|
496
|
+
return function createCoverCanvas(_x8, _x9) {
|
|
497
|
+
return _ref6.apply(this, arguments);
|
|
498
|
+
};
|
|
499
|
+
}();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML 模板工具类
|
|
3
|
+
* 所有动态拼接的 HTML 统一抽离在这里
|
|
4
|
+
*/
|
|
5
|
+
export declare function getAttachmentPasteHtml(attachment: any, amount: string, count: number): string;
|
|
6
|
+
export declare function getVoucherCanvasHtml(voucherProps: any, baseVoucherInfo: any): string;
|
|
7
|
+
export declare function getAttachmentCanvasHtml(attachmentInfo: any): string;
|
|
8
|
+
export declare function getCoverCanvasHtml(coverData: any, companyName: string): string;
|
|
9
|
+
export declare function getFullFlipbookHtml(pageDataArray: any[], coverData: any, filpBgBase64: string, defaultLineBase64: string, activeLineBase64: string): string;
|