@driveflux/frontend-pdf 3.0.4 → 3.0.5
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/index.js +0 -1
- package/dist/pdf.js +255 -45
- package/package.json +4 -4
package/dist/index.js
CHANGED
package/dist/pdf.js
CHANGED
|
@@ -1,3 +1,159 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _object_spread(target) {
|
|
44
|
+
for(var i = 1; i < arguments.length; i++){
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
function _ts_generator(thisArg, body) {
|
|
59
|
+
var f, y, t, _ = {
|
|
60
|
+
label: 0,
|
|
61
|
+
sent: function() {
|
|
62
|
+
if (t[0] & 1) throw t[1];
|
|
63
|
+
return t[1];
|
|
64
|
+
},
|
|
65
|
+
trys: [],
|
|
66
|
+
ops: []
|
|
67
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
68
|
+
return d(g, "next", {
|
|
69
|
+
value: verb(0)
|
|
70
|
+
}), d(g, "throw", {
|
|
71
|
+
value: verb(1)
|
|
72
|
+
}), d(g, "return", {
|
|
73
|
+
value: verb(2)
|
|
74
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
75
|
+
value: function() {
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
}), g;
|
|
79
|
+
function verb(n) {
|
|
80
|
+
return function(v) {
|
|
81
|
+
return step([
|
|
82
|
+
n,
|
|
83
|
+
v
|
|
84
|
+
]);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function step(op) {
|
|
88
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
89
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
90
|
+
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;
|
|
91
|
+
if (y = 0, t) op = [
|
|
92
|
+
op[0] & 2,
|
|
93
|
+
t.value
|
|
94
|
+
];
|
|
95
|
+
switch(op[0]){
|
|
96
|
+
case 0:
|
|
97
|
+
case 1:
|
|
98
|
+
t = op;
|
|
99
|
+
break;
|
|
100
|
+
case 4:
|
|
101
|
+
_.label++;
|
|
102
|
+
return {
|
|
103
|
+
value: op[1],
|
|
104
|
+
done: false
|
|
105
|
+
};
|
|
106
|
+
case 5:
|
|
107
|
+
_.label++;
|
|
108
|
+
y = op[1];
|
|
109
|
+
op = [
|
|
110
|
+
0
|
|
111
|
+
];
|
|
112
|
+
continue;
|
|
113
|
+
case 7:
|
|
114
|
+
op = _.ops.pop();
|
|
115
|
+
_.trys.pop();
|
|
116
|
+
continue;
|
|
117
|
+
default:
|
|
118
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
119
|
+
_ = 0;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
123
|
+
_.label = op[1];
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
127
|
+
_.label = t[1];
|
|
128
|
+
t = op;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
if (t && _.label < t[2]) {
|
|
132
|
+
_.label = t[2];
|
|
133
|
+
_.ops.push(op);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (t[2]) _.ops.pop();
|
|
137
|
+
_.trys.pop();
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
op = body.call(thisArg, _);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
op = [
|
|
143
|
+
6,
|
|
144
|
+
e
|
|
145
|
+
];
|
|
146
|
+
y = 0;
|
|
147
|
+
} finally{
|
|
148
|
+
f = t = 0;
|
|
149
|
+
}
|
|
150
|
+
if (op[0] & 5) throw op[1];
|
|
151
|
+
return {
|
|
152
|
+
value: op[0] ? op[1] : void 0,
|
|
153
|
+
done: true
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
1
157
|
import html2canvasPro from 'html2canvas-pro';
|
|
2
158
|
import jsPDF from 'jspdf';
|
|
3
159
|
/**
|
|
@@ -8,10 +164,26 @@ import jsPDF from 'jspdf';
|
|
|
8
164
|
*
|
|
9
165
|
* @example
|
|
10
166
|
* prepareElementsToDownload(element, 'receipt.pdf', { unit: 'mm' });
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
167
|
+
*/ export var prepareElementsToDownload = function prepareElementsToDownload(elements) {
|
|
168
|
+
var pdfName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 'print.pdf', options = arguments.length > 2 ? arguments[2] : void 0;
|
|
169
|
+
return _async_to_generator(function() {
|
|
170
|
+
var pdf;
|
|
171
|
+
return _ts_generator(this, function(_state) {
|
|
172
|
+
switch(_state.label){
|
|
173
|
+
case 0:
|
|
174
|
+
return [
|
|
175
|
+
4,
|
|
176
|
+
generatePdf(elements, options)
|
|
177
|
+
];
|
|
178
|
+
case 1:
|
|
179
|
+
pdf = _state.sent();
|
|
180
|
+
pdf.save(pdfName);
|
|
181
|
+
return [
|
|
182
|
+
2
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
})();
|
|
15
187
|
};
|
|
16
188
|
/**
|
|
17
189
|
*
|
|
@@ -21,48 +193,86 @@ export const prepareElementsToDownload = async (elements, pdfName = 'print.pdf',
|
|
|
21
193
|
*
|
|
22
194
|
* @example
|
|
23
195
|
* prepareElementsToPrint(element, 'receipt.pdf', { unit: 'mm' });
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
196
|
+
*/ export var prepareElementsToPrint = function prepareElementsToPrint(elements, options) {
|
|
197
|
+
return _async_to_generator(function() {
|
|
198
|
+
var pdf;
|
|
199
|
+
return _ts_generator(this, function(_state) {
|
|
200
|
+
switch(_state.label){
|
|
201
|
+
case 0:
|
|
202
|
+
return [
|
|
203
|
+
4,
|
|
204
|
+
generatePdf(elements, options)
|
|
205
|
+
];
|
|
206
|
+
case 1:
|
|
207
|
+
pdf = _state.sent();
|
|
208
|
+
pdf.autoPrint();
|
|
209
|
+
window.open(pdf.output('bloburl'), '_blank');
|
|
210
|
+
return [
|
|
211
|
+
2
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
})();
|
|
29
216
|
};
|
|
30
|
-
|
|
217
|
+
var defaultOptions = {
|
|
31
218
|
unit: 'px',
|
|
32
|
-
compress: true
|
|
219
|
+
compress: true
|
|
33
220
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
221
|
+
var generatePdf = function generatePdf(elements, options) {
|
|
222
|
+
return _async_to_generator(function() {
|
|
223
|
+
var pdf, i, _style_sheet, element, originalWidth, style, canvas, data, imgProperties, pdfWidth, pdfHeight;
|
|
224
|
+
return _ts_generator(this, function(_state) {
|
|
225
|
+
switch(_state.label){
|
|
226
|
+
case 0:
|
|
227
|
+
pdf = new jsPDF(_object_spread({}, defaultOptions, options));
|
|
228
|
+
i = 0;
|
|
229
|
+
_state.label = 1;
|
|
230
|
+
case 1:
|
|
231
|
+
if (!(i < elements.length)) return [
|
|
232
|
+
3,
|
|
233
|
+
4
|
|
234
|
+
];
|
|
235
|
+
element = elements[i];
|
|
236
|
+
// set width to container
|
|
237
|
+
originalWidth = element.style.width;
|
|
238
|
+
// const originalHeight = element.style.height
|
|
239
|
+
element.style.width = (options === null || options === void 0 ? void 0 : options.orientation) === 'l' || (options === null || options === void 0 ? void 0 : options.orientation) === 'landscape' ? '1263px' : '892.5px';
|
|
240
|
+
element.style.height = (options === null || options === void 0 ? void 0 : options.orientation) === 'l' || (options === null || options === void 0 ? void 0 : options.orientation) === 'landscape' ? '892.5px' : '1263px';
|
|
241
|
+
// workaround to remove canvas extra space to div
|
|
242
|
+
style = document.createElement('style');
|
|
243
|
+
document.head.appendChild(style);
|
|
244
|
+
(_style_sheet = style.sheet) === null || _style_sheet === void 0 ? void 0 : _style_sheet.insertRule('body > div:last-child img { display: inline-block; }');
|
|
245
|
+
return [
|
|
246
|
+
4,
|
|
247
|
+
html2canvasPro(element, {
|
|
248
|
+
scale: 3.0
|
|
249
|
+
})
|
|
250
|
+
];
|
|
251
|
+
case 2:
|
|
252
|
+
canvas = _state.sent();
|
|
253
|
+
data = canvas.toDataURL('image/jpeg');
|
|
254
|
+
imgProperties = pdf.getImageProperties(data);
|
|
255
|
+
pdfWidth = pdf.internal.pageSize.getWidth();
|
|
256
|
+
pdfHeight = imgProperties.height * pdfWidth / imgProperties.width;
|
|
257
|
+
pdf.addImage(data, 'PNG', 0, 0, pdfWidth, pdfHeight);
|
|
258
|
+
element.style.width = originalWidth;
|
|
259
|
+
// element.style.height = originalHeight
|
|
260
|
+
if (elements.length > 1 && i < elements.length - 1) {
|
|
261
|
+
pdf.addPage();
|
|
262
|
+
}
|
|
263
|
+
_state.label = 3;
|
|
264
|
+
case 3:
|
|
265
|
+
i++;
|
|
266
|
+
return [
|
|
267
|
+
3,
|
|
268
|
+
1
|
|
269
|
+
];
|
|
270
|
+
case 4:
|
|
271
|
+
return [
|
|
272
|
+
2,
|
|
273
|
+
pdf
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
})();
|
|
67
278
|
};
|
|
68
|
-
//# sourceMappingURL=pdf.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/frontend-pdf",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"html2canvas": "^1.4.1",
|
|
16
|
-
"html2canvas-pro": "^2.0.
|
|
16
|
+
"html2canvas-pro": "^2.0.3",
|
|
17
17
|
"jspdf": "^4.2.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@driveflux/fab": "4.0.
|
|
20
|
+
"@driveflux/fab": "4.0.3",
|
|
21
21
|
"@driveflux/tsconfig": "3.0.2",
|
|
22
22
|
"@swc/cli": "^0.8.1",
|
|
23
|
-
"@swc/core": "^1.15.
|
|
23
|
+
"@swc/core": "^1.15.40",
|
|
24
24
|
"@types/lodash": "^4.17.24",
|
|
25
25
|
"@types/node": "^25.9.1",
|
|
26
26
|
"del-cli": "^7.0.0",
|