authscape 1.0.158 → 1.0.159

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/index.js CHANGED
@@ -1140,34 +1140,50 @@ var PageToPDF = function PageToPDF(_ref) {
1140
1140
  elementById = _ref.elementById,
1141
1141
  _ref$scale = _ref.scale,
1142
1142
  scale = _ref$scale === void 0 ? 2 : _ref$scale,
1143
- _ref$onHideElements = _ref.onHideElements,
1144
- onHideElements = _ref$onHideElements === void 0 ? null : _ref$onHideElements,
1143
+ _ref$showHideClassEle = _ref.showHideClassElements,
1144
+ showHideClassElements = _ref$showHideClassEle === void 0 ? [] : _ref$showHideClassEle,
1145
1145
  _ref$fileName = _ref.fileName,
1146
1146
  fileName = _ref$fileName === void 0 ? "download" : _ref$fileName;
1147
+ var onHideElements = function onHideElements() {
1148
+ for (var index = 0; index < showHideClassElements.length; index++) {
1149
+ var element = showHideClassElements[index];
1150
+ var className = document.getElementsByClassName(element);
1151
+ if (className != null) {
1152
+ className.style.display = "none";
1153
+ }
1154
+ }
1155
+ };
1156
+ var onShowElements = function onShowElements() {
1157
+ for (var index = 0; index < showHideClassElements.length; index++) {
1158
+ var element = showHideClassElements[index];
1159
+ var className = document.getElementsByClassName(element);
1160
+ if (className != null) {
1161
+ className.style.display = "block";
1162
+ }
1163
+ }
1164
+ };
1147
1165
  var printElement = function printElement() {
1148
- onHideElements(true);
1149
- setTimeout(function () {
1150
- var input = document.getElementById(elementById);
1151
- (0, _html2canvas["default"])(input, {
1152
- backgroundColor: null,
1153
- scale: scale
1154
- }).then(function (canvas) {
1155
- var imgData = canvas.toDataURL("image/png", 1.0);
1156
- var pdf = new _jspdf.jsPDF();
1157
- var pdfWidth = pdf.internal.pageSize.getWidth();
1158
- var pdfHeight = pdf.internal.pageSize.getHeight();
1159
- var imgWidth = canvas.width;
1160
- var imgHeight = canvas.height;
1161
- var scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
1162
- var scaledWidth = imgWidth * scaleFactor;
1163
- var scaledHeight = imgHeight * scaleFactor;
1164
- var x = (pdfWidth - scaledWidth) / 2;
1165
- var y = 0; // Set y coordinate to 0 to align to the top
1166
- pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
1167
- pdf.save(fileName + ".pdf");
1168
- });
1169
- }, 2000);
1170
- onHideElements(false);
1166
+ onHideElements();
1167
+ var input = document.getElementById(elementById);
1168
+ (0, _html2canvas["default"])(input, {
1169
+ backgroundColor: null,
1170
+ scale: scale
1171
+ }).then(function (canvas) {
1172
+ var imgData = canvas.toDataURL("image/png", 1.0);
1173
+ var pdf = new _jspdf.jsPDF();
1174
+ var pdfWidth = pdf.internal.pageSize.getWidth();
1175
+ var pdfHeight = pdf.internal.pageSize.getHeight();
1176
+ var imgWidth = canvas.width;
1177
+ var imgHeight = canvas.height;
1178
+ var scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
1179
+ var scaledWidth = imgWidth * scaleFactor;
1180
+ var scaledHeight = imgHeight * scaleFactor;
1181
+ var x = (pdfWidth - scaledWidth) / 2;
1182
+ var y = 0; // Set y coordinate to 0 to align to the top
1183
+ pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
1184
+ pdf.save(fileName + ".pdf");
1185
+ });
1186
+ onShowElements();
1171
1187
  };
1172
1188
  return /*#__PURE__*/_react["default"].createElement(_Box["default"], null, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
1173
1189
  startIcon: startIcon,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.158",
3
+ "version": "1.0.159",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,35 +5,59 @@ import { jsPDF } from "jspdf";
5
5
  import Button from "@mui/material/Button";
6
6
  import DownloadRoundedIcon from '@mui/icons-material/DownloadRounded';
7
7
 
8
- export const PageToPDF = ({buttonText = "Download", startIcon = <DownloadRoundedIcon/>, variant = "contained", elementById, scale = 2, onHideElements = null, fileName = "download"}) => {
8
+ export const PageToPDF = ({buttonText = "Download", startIcon = <DownloadRoundedIcon/>, variant = "contained", elementById, scale = 2, showHideClassElements = [], fileName = "download"}) => {
9
+
10
+
11
+ const onHideElements = () => {
12
+
13
+ for (let index = 0; index < showHideClassElements.length; index++) {
14
+ const element = showHideClassElements[index];
15
+
16
+ let className = document.getElementsByClassName(element);
17
+ if (className != null)
18
+ {
19
+ className.style.display = "none";
20
+ }
21
+ }
22
+ }
23
+
24
+ const onShowElements = () => {
25
+
26
+ for (let index = 0; index < showHideClassElements.length; index++) {
27
+ const element = showHideClassElements[index];
28
+
29
+ let className = document.getElementsByClassName(element);
30
+ if (className != null)
31
+ {
32
+ className.style.display = "block";
33
+ }
34
+ }
35
+ }
36
+
9
37
 
10
38
  const printElement = () => {
11
39
 
12
- onHideElements(true);
13
-
14
- setTimeout(() => {
15
-
16
- const input = document.getElementById(elementById);
17
- html2canvas(input, {backgroundColor: null, scale: scale})
18
- .then((canvas) => {
19
- const imgData = canvas.toDataURL("image/png", 1.0);
20
- const pdf = new jsPDF();
21
- const pdfWidth = pdf.internal.pageSize.getWidth();
22
- const pdfHeight = pdf.internal.pageSize.getHeight();
23
- const imgWidth = canvas.width;
24
- const imgHeight = canvas.height;
25
- const scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
26
- const scaledWidth = imgWidth * scaleFactor;
27
- const scaledHeight = imgHeight * scaleFactor;
28
- const x = (pdfWidth - scaledWidth) / 2;
29
- const y = 0; // Set y coordinate to 0 to align to the top
30
- pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
31
- pdf.save(fileName + ".pdf");
32
- })
33
-
34
- }, 2000);
35
-
36
- onHideElements(false);
40
+ onHideElements();
41
+
42
+ const input = document.getElementById(elementById);
43
+ html2canvas(input, {backgroundColor: null, scale: scale})
44
+ .then((canvas) => {
45
+ const imgData = canvas.toDataURL("image/png", 1.0);
46
+ const pdf = new jsPDF();
47
+ const pdfWidth = pdf.internal.pageSize.getWidth();
48
+ const pdfHeight = pdf.internal.pageSize.getHeight();
49
+ const imgWidth = canvas.width;
50
+ const imgHeight = canvas.height;
51
+ const scaleFactor = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
52
+ const scaledWidth = imgWidth * scaleFactor;
53
+ const scaledHeight = imgHeight * scaleFactor;
54
+ const x = (pdfWidth - scaledWidth) / 2;
55
+ const y = 0; // Set y coordinate to 0 to align to the top
56
+ pdf.addImage(imgData, "PNG", x, y, scaledWidth, scaledHeight);
57
+ pdf.save(fileName + ".pdf");
58
+ });
59
+
60
+ onShowElements();
37
61
  }
38
62
 
39
63