Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

print-js

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

print-js - npm Package Compare versions

Comparing version 1.0.63 to 1.1.0

758

dist/print.js

@@ -103,8 +103,20 @@ (function webpackUniversalModuleDefinition(root, factory) {

\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\n__webpack_require__(/*! ./sass/index.scss */ \"./src/sass/index.scss\");\n\nvar _init = __webpack_require__(/*! ./js/init */ \"./src/js/init.js\");\n\nvar _init2 = _interopRequireDefault(_init);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar printJS = _init2.default.init;\n\nif (typeof window !== 'undefined') {\n window.printJS = printJS;\n}\n\nexports.default = printJS;\n\n//# sourceURL=webpack://printJS/./src/index.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _sass_index_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sass/index.scss */ "./src/sass/index.scss");
/* harmony import */ var _sass_index_scss__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_sass_index_scss__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _js_init__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./js/init */ "./src/js/init.js");
var printJS = _js_init__WEBPACK_IMPORTED_MODULE_1__["default"].init;
if (typeof window !== 'undefined') {
window.printJS = printJS;
}
/* harmony default export */ __webpack_exports__["default"] = (printJS);
/***/ }),

@@ -116,7 +128,35 @@

\***************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nvar Browser = {\n // Firefox 1.0+\n isFirefox: function isFirefox() {\n return typeof InstallTrigger !== 'undefined';\n },\n // Internet Explorer 6-11\n isIE: function isIE() {\n return navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode;\n },\n // Edge 20+\n isEdge: function isEdge() {\n return !Browser.isIE() && !!window.StyleMedia;\n },\n // Chrome 1+\n isChrome: function isChrome() {\n var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;\n\n return !!context.chrome;\n },\n // At least Safari 3+: \"[object HTMLElementConstructor]\"\n isSafari: function isSafari() {\n return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || navigator.userAgent.toLowerCase().indexOf('safari') !== -1;\n },\n // IOS Chrome\n isIOSChrome: function isIOSChrome() {\n return navigator.userAgent.toLowerCase().indexOf('crios') !== -1;\n }\n};\n\nexports.default = Browser;\n\n//# sourceURL=webpack://printJS/./src/js/browser.js?");
__webpack_require__.r(__webpack_exports__);
var Browser = {
// Firefox 1.0+
isFirefox: function isFirefox() {
return typeof InstallTrigger !== 'undefined';
},
// Internet Explorer 6-11
isIE: function isIE() {
return navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode;
},
// Edge 20+
isEdge: function isEdge() {
return !Browser.isIE() && !!window.StyleMedia;
},
// Chrome 1+
isChrome: function isChrome() {
var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
return !!context.chrome;
},
// At least Safari 3+: "[object HTMLElementConstructor]"
isSafari: function isSafari() {
return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || navigator.userAgent.toLowerCase().indexOf('safari') !== -1;
},
// IOS Chrome
isIOSChrome: function isIOSChrome() {
return navigator.userAgent.toLowerCase().indexOf('crios') !== -1;
}
};
/* harmony default export */ __webpack_exports__["default"] = (Browser);

@@ -129,8 +169,100 @@ /***/ }),

\*****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: addWrapper, capitalizePrint, collectStyles, addHeader, cleanUp, isRawHTML */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nexports.addWrapper = addWrapper;\nexports.capitalizePrint = capitalizePrint;\nexports.collectStyles = collectStyles;\nexports.addHeader = addHeader;\nexports.cleanUp = cleanUp;\nexports.isRawHTML = isRawHTML;\n\nvar _modal = __webpack_require__(/*! ./modal */ \"./src/js/modal.js\");\n\nvar _modal2 = _interopRequireDefault(_modal);\n\nvar _browser = __webpack_require__(/*! ./browser */ \"./src/js/browser.js\");\n\nvar _browser2 = _interopRequireDefault(_browser);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction addWrapper(htmlData, params) {\n var bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;';\n return '<div style=\"' + bodyStyle + '\">' + htmlData + '</div>';\n}\n\nfunction capitalizePrint(obj) {\n return obj.charAt(0).toUpperCase() + obj.slice(1);\n}\n\nfunction collectStyles(element, params) {\n var win = document.defaultView || window;\n\n // String variable to hold styling for each element\n var elementStyle = '';\n\n // Loop over computed styles\n var styles = win.getComputedStyle(element, '');\n\n Object.keys(styles).map(function (key) {\n // Check if style should be processed\n if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {\n if (styles.getPropertyValue(styles[key])) elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';';\n }\n });\n\n // Print friendly defaults (deprecated)\n elementStyle += 'max-width: ' + params.maxWidth + 'px !important;' + params.font_size + ' !important;';\n\n return elementStyle;\n}\n\nfunction targetStylesMatch(styles, value) {\n for (var i = 0; i < styles.length; i++) {\n if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value.indexOf(styles[i]) !== -1) return true;\n }\n return false;\n}\n\nfunction addHeader(printElement, params) {\n // Create the header container div\n var headerContainer = document.createElement('div');\n\n // Check if the header is text or raw html\n if (isRawHTML(params.header)) {\n headerContainer.innerHTML = params.header;\n } else {\n // Create header element\n var headerElement = document.createElement('h1');\n\n // Create header text node\n var headerNode = document.createTextNode(params.header);\n\n // Build and style\n headerElement.appendChild(headerNode);\n headerElement.setAttribute('style', params.headerStyle);\n headerContainer.appendChild(headerElement);\n }\n\n printElement.insertBefore(headerContainer, printElement.childNodes[0]);\n}\n\nfunction cleanUp(params) {\n // If we are showing a feedback message to user, remove it\n if (params.showModal) _modal2.default.close();\n\n // Check for a finished loading hook function\n if (params.onLoadingEnd) params.onLoadingEnd();\n\n // If preloading pdf files, clean blob url\n if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable);\n\n // If a onPrintDialogClose callback is given, execute it\n if (params.onPrintDialogClose) {\n var event = 'mouseover';\n\n if (_browser2.default.isChrome() || _browser2.default.isFirefox()) {\n // Ps.: Firefox will require an extra click in the document to fire the focus event.\n event = 'focus';\n }\n var handler = function handler() {\n // Make sure the event only happens once.\n window.removeEventListener(event, handler);\n\n params.onPrintDialogClose();\n };\n\n window.addEventListener(event, handler);\n }\n}\n\nfunction isRawHTML(raw) {\n var regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\\\b[^>]*>(.*?)</\\\\1>');\n return regexHtml.test(raw);\n}\n\n//# sourceURL=webpack://printJS/./src/js/functions.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addWrapper", function() { return addWrapper; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "capitalizePrint", function() { return capitalizePrint; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "collectStyles", function() { return collectStyles; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addHeader", function() { return addHeader; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cleanUp", function() { return cleanUp; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isRawHTML", function() { return isRawHTML; });
/* harmony import */ var _modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modal */ "./src/js/modal.js");
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function addWrapper(htmlData, params) {
var bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;';
return '<div style="' + bodyStyle + '">' + htmlData + '</div>';
}
function capitalizePrint(obj) {
return obj.charAt(0).toUpperCase() + obj.slice(1);
}
function collectStyles(element, params) {
var win = document.defaultView || window; // String variable to hold styling for each element
var elementStyle = ''; // Loop over computed styles
var styles = win.getComputedStyle(element, '');
Object.keys(styles).map(function (key) {
// Check if style should be processed
if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {
if (styles.getPropertyValue(styles[key])) elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';';
}
}); // Print friendly defaults (deprecated)
elementStyle += 'max-width: ' + params.maxWidth + 'px !important;' + params.font_size + ' !important;';
return elementStyle;
}
function targetStylesMatch(styles, value) {
for (var i = 0; i < styles.length; i++) {
if (_typeof(value) === 'object' && value.indexOf(styles[i]) !== -1) return true;
}
return false;
}
function addHeader(printElement, params) {
// Create the header container div
var headerContainer = document.createElement('div'); // Check if the header is text or raw html
if (isRawHTML(params.header)) {
headerContainer.innerHTML = params.header;
} else {
// Create header element
var headerElement = document.createElement('h1'); // Create header text node
var headerNode = document.createTextNode(params.header); // Build and style
headerElement.appendChild(headerNode);
headerElement.setAttribute('style', params.headerStyle);
headerContainer.appendChild(headerElement);
}
printElement.insertBefore(headerContainer, printElement.childNodes[0]);
}
function cleanUp(params) {
// If we are showing a feedback message to user, remove it
if (params.showModal) _modal__WEBPACK_IMPORTED_MODULE_0__["default"].close(); // Check for a finished loading hook function
if (params.onLoadingEnd) params.onLoadingEnd(); // If preloading pdf files, clean blob url
if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable); // If a onPrintDialogClose callback is given, execute it
if (params.onPrintDialogClose) {
var event = 'mouseover';
if (_browser__WEBPACK_IMPORTED_MODULE_1__["default"].isChrome() || _browser__WEBPACK_IMPORTED_MODULE_1__["default"].isFirefox()) {
// Ps.: Firefox will require an extra click in the document to fire the focus event.
event = 'focus';
}
var handler = function handler() {
// Make sure the event only happens once.
window.removeEventListener(event, handler);
params.onPrintDialogClose();
};
window.addEventListener(event, handler);
}
}
function isRawHTML(raw) {
var regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>');
return regexHtml.test(raw);
}
/***/ }),

@@ -142,8 +274,72 @@

\************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Get the DOM printable element\n var printElement = document.getElementById(params.printable);\n\n // Check if the element exists\n if (!printElement) {\n window.console.error('Invalid HTML element id: ' + params.printable);\n return;\n }\n\n // Clone the target element including its children (if available)\n params.printableElement = cloneElement(printElement, params);\n\n // Add header\n if (params.header) {\n (0, _functions.addHeader)(params.printableElement, params);\n }\n\n // Print html element contents\n _print2.default.send(params, printFrame);\n }\n};\n\n\nfunction cloneElement(element, params) {\n // Clone the main node (if not already inside the recursion process)\n var clone = element.cloneNode();\n\n // Loop over and process the children elements / nodes (including text nodes)\n var _iteratorNormalCompletion = true;\n var _didIteratorError = false;\n var _iteratorError = undefined;\n\n try {\n for (var _iterator = element.childNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var child = _step.value;\n\n // Check if we are skiping the current element\n if (params.ignoreElements.indexOf(child.id) !== -1) {\n continue;\n }\n\n // Clone the child element\n var clonedChild = cloneElement(child, params);\n\n // Attach the cloned child to the cloned parent node\n clone.appendChild(clonedChild);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n\n console.log(element.nodeType);\n // Get all styling for print element (for nodes of type element only)\n if (params.scanStyles && element.nodeType === 1) {\n clone.setAttribute('style', (0, _functions.collectStyles)(element, params));\n }\n\n // Check if the element needs any state processing (copy user input data)\n switch (element.tagName) {\n case 'SELECT':\n // Copy the current selection value to its clone\n clone.value = element.value;\n break;\n case 'CANVAS':\n // Copy the canvas content to its clone\n clone.getContext('2d').drawImage(element, 0, 0);\n break;\n }\n\n return clone;\n}\n\n//# sourceURL=webpack://printJS/./src/js/html.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
/* harmony default export */ __webpack_exports__["default"] = ({
print: function print(params, printFrame) {
// Get the DOM printable element
var printElement = document.getElementById(params.printable); // Check if the element exists
if (!printElement) {
window.console.error('Invalid HTML element id: ' + params.printable);
return;
} // Clone the target element including its children (if available)
params.printableElement = cloneElement(printElement, params); // Add header
if (params.header) {
Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
} // Print html element contents
_print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
}
});
function cloneElement(element, params) {
// Clone the main node (if not already inside the recursion process)
var clone = element.cloneNode(); // Loop over and process the children elements / nodes (including text nodes)
var childNodesArray = Array.prototype.slice.call(element.childNodes);
for (var i = 0; i < childNodesArray.length; i++) {
// Check if we are skiping the current element
if (params.ignoreElements.indexOf(childNodesArray[i].id) !== -1) {
continue;
} // Clone the child element
var clonedChild = cloneElement(childNodesArray[i], params); // Attach the cloned child to the cloned parent node
clone.appendChild(clonedChild);
} // Get all styling for print element (for nodes of type element only)
if (params.scanStyles && element.nodeType === 1) {
clone.setAttribute('style', Object(_functions__WEBPACK_IMPORTED_MODULE_0__["collectStyles"])(element, params));
} // Check if the element needs any state processing (copy user input data)
switch (element.tagName) {
case 'SELECT':
// Copy the current selection value to its clone
clone.value = element.value;
break;
case 'CANVAS':
// Copy the canvas content to its clone
clone.getContext('2d').drawImage(element, 0, 0);
break;
}
return clone;
}
/***/ }),

@@ -155,8 +351,42 @@

\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Check if we are printing one image or multiple images\n if (params.printable.constructor !== Array) {\n // Create array with one image\n params.printable = [params.printable];\n }\n\n // Create printable element (container)\n params.printableElement = document.createElement('div');\n\n // Create all image elements and append them to the printable container\n params.printable.forEach(function (src) {\n // Create the image element\n var img = document.createElement('img');\n img.setAttribute('style', params.imageStyle);\n\n // Set image src with the file url\n img.src = src;\n\n // Create the image wrapper\n var imageWrapper = document.createElement('div');\n\n // Append image to the wrapper element\n imageWrapper.appendChild(img);\n\n // Append wrapper to the printable element\n params.printableElement.appendChild(imageWrapper);\n });\n\n // Check if we are adding a print header\n if (params.header) (0, _functions.addHeader)(params.printableElement, params);\n\n // Print image\n _print2.default.send(params, printFrame);\n }\n};\n\n//# sourceURL=webpack://printJS/./src/js/image.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
/* harmony default export */ __webpack_exports__["default"] = ({
print: function print(params, printFrame) {
// Check if we are printing one image or multiple images
if (params.printable.constructor !== Array) {
// Create array with one image
params.printable = [params.printable];
} // Create printable element (container)
params.printableElement = document.createElement('div'); // Create all image elements and append them to the printable container
params.printable.forEach(function (src) {
// Create the image element
var img = document.createElement('img');
img.setAttribute('style', params.imageStyle); // Set image src with the file url
img.src = src; // Create the image wrapper
var imageWrapper = document.createElement('div'); // Append image to the wrapper element
imageWrapper.appendChild(img); // Append wrapper to the printable element
params.printableElement.appendChild(imageWrapper);
}); // Check if we are adding a print header
if (params.header) Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params); // Print image
_print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
}
});
/***/ }),

@@ -168,8 +398,176 @@

\************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _browser = __webpack_require__(/*! ./browser */ \"./src/js/browser.js\");\n\nvar _browser2 = _interopRequireDefault(_browser);\n\nvar _modal = __webpack_require__(/*! ./modal */ \"./src/js/modal.js\");\n\nvar _modal2 = _interopRequireDefault(_modal);\n\nvar _pdf = __webpack_require__(/*! ./pdf */ \"./src/js/pdf.js\");\n\nvar _pdf2 = _interopRequireDefault(_pdf);\n\nvar _html = __webpack_require__(/*! ./html */ \"./src/js/html.js\");\n\nvar _html2 = _interopRequireDefault(_html);\n\nvar _rawHtml = __webpack_require__(/*! ./raw-html */ \"./src/js/raw-html.js\");\n\nvar _rawHtml2 = _interopRequireDefault(_rawHtml);\n\nvar _image = __webpack_require__(/*! ./image */ \"./src/js/image.js\");\n\nvar _image2 = _interopRequireDefault(_image);\n\nvar _json = __webpack_require__(/*! ./json */ \"./src/js/json.js\");\n\nvar _json2 = _interopRequireDefault(_json);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar printTypes = ['pdf', 'html', 'image', 'json', 'raw-html'];\n\nexports.default = {\n init: function init() {\n var params = {\n printable: null,\n fallbackPrintable: null,\n type: 'pdf',\n header: null,\n headerStyle: 'font-weight: 300;',\n maxWidth: 800,\n font: 'TimesNewRoman',\n font_size: '12pt',\n honorMarginPadding: true,\n honorColor: false,\n properties: null,\n gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;',\n gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;',\n showModal: false,\n onError: function onError(error) {\n throw error;\n },\n onLoadingStart: null,\n onLoadingEnd: null,\n onPrintDialogClose: null,\n onPdfOpen: null,\n onBrowserIncompatible: function onBrowserIncompatible() {\n return true;\n },\n modalMessage: 'Retrieving Document...',\n frameId: 'printJS',\n printableElement: null,\n documentTitle: 'Document',\n targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'],\n targetStyles: ['border', 'box', 'break', 'text-decoration'],\n ignoreElements: [],\n imageStyle: 'max-width: 100%;',\n repeatTableHeader: true,\n css: null,\n style: null,\n scanStyles: true,\n base64: false\n\n // Check if a printable document or object was supplied\n };var args = arguments[0];\n if (args === undefined) throw new Error('printJS expects at least 1 attribute.');\n\n // Process parameters\n switch (typeof args === 'undefined' ? 'undefined' : _typeof(args)) {\n case 'string':\n params.printable = encodeURI(args);\n params.fallbackPrintable = params.printable;\n params.type = arguments[1] || params.type;\n break;\n case 'object':\n params.printable = args.printable;\n params.base64 = typeof args.base64 !== 'undefined';\n params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable;\n params.fallbackPrintable = params.base64 ? 'data:application/pdf;base64,' + params.fallbackPrintable : params.fallbackPrintable;\n for (var k in params) {\n if (k === 'printable' || k === 'fallbackPrintable' || k === 'base64') continue;\n\n params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k];\n }\n break;\n default:\n throw new Error('Unexpected argument type! Expected \"string\" or \"object\", got ' + (typeof args === 'undefined' ? 'undefined' : _typeof(args)));\n }\n\n // Validate printable\n if (!params.printable) throw new Error('Missing printable information.');\n\n // Validate type\n if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) {\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.');\n }\n\n // Check if we are showing a feedback message to the user (useful for large files)\n if (params.showModal) _modal2.default.show(params);\n\n // Check for a print start hook function\n if (params.onLoadingStart) params.onLoadingStart();\n\n // To prevent duplication and issues, remove any used printFrame from the DOM\n var usedFrame = document.getElementById(params.frameId);\n\n if (usedFrame) usedFrame.parentNode.removeChild(usedFrame);\n\n // Create a new iframe or embed element (IE prints blank pdf's if we use iframe)\n var printFrame = void 0;\n\n // Create iframe element\n printFrame = document.createElement('iframe');\n\n // Hide iframe\n printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;');\n\n // Set iframe element id\n printFrame.setAttribute('id', params.frameId);\n\n // For non pdf printing, pass an html document string to srcdoc (force onload callback)\n if (params.type !== 'pdf') {\n printFrame.srcdoc = '<html><head><title>' + params.documentTitle + '</title>';\n\n // Attach css files\n if (params.css) {\n // Add support for single file\n if (!Array.isArray(params.css)) params.css = [params.css];\n\n // Create link tags for each css file\n params.css.forEach(function (file) {\n printFrame.srcdoc += '<link rel=\"stylesheet\" href=\"' + file + '\">';\n });\n }\n\n printFrame.srcdoc += '</head><body></body></html>';\n }\n\n // Check printable type\n switch (params.type) {\n case 'pdf':\n // Check browser support for pdf and if not supported we will just open the pdf file instead\n if (_browser2.default.isFirefox() || _browser2.default.isEdge() || _browser2.default.isIE()) {\n try {\n console.info('PrintJS currently doesn\\'t support PDF printing in Firefox, Internet Explorer and Edge.');\n if (params.onBrowserIncompatible() === true) {\n var win = window.open(params.fallbackPrintable, '_blank');\n win.focus();\n if (params.onPdfOpen) params.onPdfOpen();\n }\n } catch (e) {\n params.onError(e);\n } finally {\n // Make sure there is no loading modal opened\n if (params.showModal) _modal2.default.close();\n if (params.onLoadingEnd) params.onLoadingEnd();\n }\n } else {\n _pdf2.default.print(params, printFrame);\n }\n break;\n case 'image':\n _image2.default.print(params, printFrame);\n break;\n case 'html':\n _html2.default.print(params, printFrame);\n break;\n case 'raw-html':\n _rawHtml2.default.print(params, printFrame);\n break;\n case 'json':\n _json2.default.print(params, printFrame);\n break;\n }\n }\n};\n\n//# sourceURL=webpack://printJS/./src/js/init.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
/* harmony import */ var _modal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modal */ "./src/js/modal.js");
/* harmony import */ var _pdf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pdf */ "./src/js/pdf.js");
/* harmony import */ var _html__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./html */ "./src/js/html.js");
/* harmony import */ var _raw_html__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./raw-html */ "./src/js/raw-html.js");
/* harmony import */ var _image__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./image */ "./src/js/image.js");
/* harmony import */ var _json__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./json */ "./src/js/json.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var printTypes = ['pdf', 'html', 'image', 'json', 'raw-html'];
/* harmony default export */ __webpack_exports__["default"] = ({
init: function init() {
var params = {
printable: null,
fallbackPrintable: null,
type: 'pdf',
header: null,
headerStyle: 'font-weight: 300;',
maxWidth: 800,
font: 'TimesNewRoman',
font_size: '12pt',
honorMarginPadding: true,
honorColor: false,
properties: null,
gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;',
gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;',
showModal: false,
onError: function onError(error) {
throw error;
},
onLoadingStart: null,
onLoadingEnd: null,
onPrintDialogClose: null,
onPdfOpen: null,
onBrowserIncompatible: function onBrowserIncompatible() {
return true;
},
modalMessage: 'Retrieving Document...',
frameId: 'printJS',
printableElement: null,
documentTitle: 'Document',
targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'],
targetStyles: ['border', 'box', 'break', 'text-decoration'],
ignoreElements: [],
imageStyle: 'max-width: 100%;',
repeatTableHeader: true,
css: null,
style: null,
scanStyles: true,
base64: false
}; // Check if a printable document or object was supplied
var args = arguments[0];
if (args === undefined) throw new Error('printJS expects at least 1 attribute.'); // Process parameters
switch (_typeof(args)) {
case 'string':
params.printable = encodeURI(args);
params.fallbackPrintable = params.printable;
params.type = arguments[1] || params.type;
break;
case 'object':
params.printable = args.printable;
params.base64 = typeof args.base64 !== 'undefined';
params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable;
params.fallbackPrintable = params.base64 ? "data:application/pdf;base64,".concat(params.fallbackPrintable) : params.fallbackPrintable;
for (var k in params) {
if (k === 'printable' || k === 'fallbackPrintable' || k === 'base64') continue;
params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k];
}
break;
default:
throw new Error('Unexpected argument type! Expected "string" or "object", got ' + _typeof(args));
} // Validate printable
if (!params.printable) throw new Error('Missing printable information.'); // Validate type
if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) {
throw new Error('Invalid print type. Available types are: pdf, html, image and json.');
} // Check if we are showing a feedback message to the user (useful for large files)
if (params.showModal) _modal__WEBPACK_IMPORTED_MODULE_1__["default"].show(params); // Check for a print start hook function
if (params.onLoadingStart) params.onLoadingStart(); // To prevent duplication and issues, remove any used printFrame from the DOM
var usedFrame = document.getElementById(params.frameId);
if (usedFrame) usedFrame.parentNode.removeChild(usedFrame); // Create a new iframe for the print job
var printFrame = document.createElement('iframe'); // Hide iframe
printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;'); // Set iframe element id
printFrame.setAttribute('id', params.frameId); // For non pdf printing, pass an html document string to srcdoc (force onload callback)
if (params.type !== 'pdf') {
printFrame.srcdoc = '<html><head><title>' + params.documentTitle + '</title>'; // Attach css files
if (params.css) {
// Add support for single file
if (!Array.isArray(params.css)) params.css = [params.css]; // Create link tags for each css file
params.css.forEach(function (file) {
printFrame.srcdoc += '<link rel="stylesheet" href="' + file + '">';
});
}
printFrame.srcdoc += '</head><body></body></html>';
} // Check printable type
switch (params.type) {
case 'pdf':
// Check browser support for pdf and if not supported we will just open the pdf file instead
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox() || _browser__WEBPACK_IMPORTED_MODULE_0__["default"].isEdge() || _browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) {
try {
console.info('PrintJS currently doesn\'t support PDF printing in Firefox, Internet Explorer and Edge.');
if (params.onBrowserIncompatible() === true) {
var win = window.open(params.fallbackPrintable, '_blank');
win.focus();
if (params.onPdfOpen) params.onPdfOpen();
}
} catch (e) {
params.onError(e);
} finally {
// Make sure there is no loading modal opened
if (params.showModal) _modal__WEBPACK_IMPORTED_MODULE_1__["default"].close();
if (params.onLoadingEnd) params.onLoadingEnd();
}
} else {
_pdf__WEBPACK_IMPORTED_MODULE_2__["default"].print(params, printFrame);
}
break;
case 'image':
_image__WEBPACK_IMPORTED_MODULE_5__["default"].print(params, printFrame);
break;
case 'html':
_html__WEBPACK_IMPORTED_MODULE_3__["default"].print(params, printFrame);
break;
case 'raw-html':
_raw_html__WEBPACK_IMPORTED_MODULE_4__["default"].print(params, printFrame);
break;
case 'json':
_json__WEBPACK_IMPORTED_MODULE_6__["default"].print(params, printFrame);
break;
}
}
});
/***/ }),

@@ -181,8 +579,110 @@

\************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Check if we received proper data\n if (_typeof(params.printable) !== 'object') {\n throw new Error('Invalid javascript data object (JSON).');\n }\n\n // Validate repeatTableHeader\n if (typeof params.repeatTableHeader !== 'boolean') {\n throw new Error('Invalid value for repeatTableHeader attribute (JSON).');\n }\n\n // Validate properties\n if (!params.properties || !Array.isArray(params.properties)) {\n throw new Error('Invalid properties array for your JSON data.');\n }\n\n // We will format the property objects to keep the JSON api compatible with older releases\n params.properties = params.properties.map(function (property) {\n return {\n field: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' ? property.field : property,\n displayName: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' ? property.displayName : property,\n columnSize: (typeof property === 'undefined' ? 'undefined' : _typeof(property)) === 'object' && property.columnSize ? property.columnSize + ';' : 100 / params.properties.length + '%;'\n };\n });\n\n // Create a print container element\n params.printableElement = document.createElement('div');\n\n // Check if we are adding a print header\n if (params.header) {\n (0, _functions.addHeader)(params.printableElement, params);\n }\n\n // Build the printable html data\n params.printableElement.innerHTML += jsonToHTML(params);\n\n // Print the json data\n _print2.default.send(params, printFrame);\n }\n};\n\n\nfunction jsonToHTML(params) {\n // Get the row and column data\n var data = params.printable;\n var properties = params.properties;\n\n // Create a html table\n var htmlData = '<table style=\"border-collapse: collapse; width: 100%;\">';\n\n // Check if the header should be repeated\n if (params.repeatTableHeader) {\n htmlData += '<thead>';\n }\n\n // Add the table header row\n htmlData += '<tr>';\n\n // Add the table header columns\n for (var a = 0; a < properties.length; a++) {\n htmlData += '<th style=\"width:' + properties[a].columnSize + ';' + params.gridHeaderStyle + '\">' + (0, _functions.capitalizePrint)(properties[a].displayName) + '</th>';\n }\n\n // Add the closing tag for the table header row\n htmlData += '</tr>';\n\n // If the table header is marked as repeated, add the closing tag\n if (params.repeatTableHeader) {\n htmlData += '</thead>';\n }\n\n // Create the table body\n htmlData += '<tbody>';\n\n // Add the table data rows\n for (var i = 0; i < data.length; i++) {\n // Add the row starting tag\n htmlData += '<tr>';\n\n // Print selected properties only\n for (var n = 0; n < properties.length; n++) {\n var stringData = data[i];\n\n // Support nested objects\n var property = properties[n].field.split('.');\n if (property.length > 1) {\n for (var p = 0; p < property.length; p++) {\n stringData = stringData[property[p]];\n }\n } else {\n stringData = stringData[properties[n].field];\n }\n\n // Add the row contents and styles\n htmlData += '<td style=\"width:' + properties[n].columnSize + params.gridStyle + '\">' + stringData + '</td>';\n }\n\n // Add the row closing tag\n htmlData += '</tr>';\n }\n\n // Add the table and body closing tags\n htmlData += '</tbody></table>';\n\n return htmlData;\n}\n\n//# sourceURL=webpack://printJS/./src/js/json.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/* harmony default export */ __webpack_exports__["default"] = ({
print: function print(params, printFrame) {
// Check if we received proper data
if (_typeof(params.printable) !== 'object') {
throw new Error('Invalid javascript data object (JSON).');
} // Validate repeatTableHeader
if (typeof params.repeatTableHeader !== 'boolean') {
throw new Error('Invalid value for repeatTableHeader attribute (JSON).');
} // Validate properties
if (!params.properties || !Array.isArray(params.properties)) {
throw new Error('Invalid properties array for your JSON data.');
} // We will format the property objects to keep the JSON api compatible with older releases
params.properties = params.properties.map(function (property) {
return {
field: _typeof(property) === 'object' ? property.field : property,
displayName: _typeof(property) === 'object' ? property.displayName : property,
columnSize: _typeof(property) === 'object' && property.columnSize ? property.columnSize + ';' : 100 / params.properties.length + '%;'
};
}); // Create a print container element
params.printableElement = document.createElement('div'); // Check if we are adding a print header
if (params.header) {
Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
} // Build the printable html data
params.printableElement.innerHTML += jsonToHTML(params); // Print the json data
_print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
}
});
function jsonToHTML(params) {
// Get the row and column data
var data = params.printable;
var properties = params.properties; // Create a html table
var htmlData = '<table style="border-collapse: collapse; width: 100%;">'; // Check if the header should be repeated
if (params.repeatTableHeader) {
htmlData += '<thead>';
} // Add the table header row
htmlData += '<tr>'; // Add the table header columns
for (var a = 0; a < properties.length; a++) {
htmlData += '<th style="width:' + properties[a].columnSize + ';' + params.gridHeaderStyle + '">' + Object(_functions__WEBPACK_IMPORTED_MODULE_0__["capitalizePrint"])(properties[a].displayName) + '</th>';
} // Add the closing tag for the table header row
htmlData += '</tr>'; // If the table header is marked as repeated, add the closing tag
if (params.repeatTableHeader) {
htmlData += '</thead>';
} // Create the table body
htmlData += '<tbody>'; // Add the table data rows
for (var i = 0; i < data.length; i++) {
// Add the row starting tag
htmlData += '<tr>'; // Print selected properties only
for (var n = 0; n < properties.length; n++) {
var stringData = data[i]; // Support nested objects
var property = properties[n].field.split('.');
if (property.length > 1) {
for (var p = 0; p < property.length; p++) {
stringData = stringData[property[p]];
}
} else {
stringData = stringData[properties[n].field];
} // Add the row contents and styles
htmlData += '<td style="width:' + properties[n].columnSize + params.gridStyle + '">' + stringData + '</td>';
} // Add the row closing tag
htmlData += '</tr>';
} // Add the table and body closing tags
htmlData += '</tbody></table>';
return htmlData;
}
/***/ }),

@@ -194,8 +694,46 @@

\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nvar Modal = {\n show: function show(params) {\n // Build modal\n var modalStyle = 'font-family:sans-serif; ' + 'display:table; ' + 'text-align:center; ' + 'font-weight:300; ' + 'font-size:30px; ' + 'left:0; top:0;' + 'position:fixed; ' + 'z-index: 9990;' + 'color: #0460B5; ' + 'width: 100%; ' + 'height: 100%; ' + 'background-color:rgba(255,255,255,.9);' + 'transition: opacity .3s ease;';\n\n // Create wrapper\n var printModal = document.createElement('div');\n printModal.setAttribute('style', modalStyle);\n printModal.setAttribute('id', 'printJS-Modal');\n\n // Create content div\n var contentDiv = document.createElement('div');\n contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;');\n\n // Add close button (requires print.css)\n var closeButton = document.createElement('div');\n closeButton.setAttribute('class', 'printClose');\n closeButton.setAttribute('id', 'printClose');\n contentDiv.appendChild(closeButton);\n\n // Add spinner (requires print.css)\n var spinner = document.createElement('span');\n spinner.setAttribute('class', 'printSpinner');\n contentDiv.appendChild(spinner);\n\n // Add message\n var messageNode = document.createTextNode(params.modalMessage);\n contentDiv.appendChild(messageNode);\n\n // Add contentDiv to printModal\n printModal.appendChild(contentDiv);\n\n // Append print modal element to document body\n document.getElementsByTagName('body')[0].appendChild(printModal);\n\n // Add event listener to close button\n document.getElementById('printClose').addEventListener('click', function () {\n Modal.close();\n });\n },\n close: function close() {\n var printFrame = document.getElementById('printJS-Modal');\n\n printFrame.parentNode.removeChild(printFrame);\n }\n};\n\nexports.default = Modal;\n\n//# sourceURL=webpack://printJS/./src/js/modal.js?");
__webpack_require__.r(__webpack_exports__);
var Modal = {
show: function show(params) {
// Build modal
var modalStyle = 'font-family:sans-serif; ' + 'display:table; ' + 'text-align:center; ' + 'font-weight:300; ' + 'font-size:30px; ' + 'left:0; top:0;' + 'position:fixed; ' + 'z-index: 9990;' + 'color: #0460B5; ' + 'width: 100%; ' + 'height: 100%; ' + 'background-color:rgba(255,255,255,.9);' + 'transition: opacity .3s ease;'; // Create wrapper
var printModal = document.createElement('div');
printModal.setAttribute('style', modalStyle);
printModal.setAttribute('id', 'printJS-Modal'); // Create content div
var contentDiv = document.createElement('div');
contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;'); // Add close button (requires print.css)
var closeButton = document.createElement('div');
closeButton.setAttribute('class', 'printClose');
closeButton.setAttribute('id', 'printClose');
contentDiv.appendChild(closeButton); // Add spinner (requires print.css)
var spinner = document.createElement('span');
spinner.setAttribute('class', 'printSpinner');
contentDiv.appendChild(spinner); // Add message
var messageNode = document.createTextNode(params.modalMessage);
contentDiv.appendChild(messageNode); // Add contentDiv to printModal
printModal.appendChild(contentDiv); // Append print modal element to document body
document.getElementsByTagName('body')[0].appendChild(printModal); // Add event listener to close button
document.getElementById('printClose').addEventListener('click', function () {
Modal.close();
});
},
close: function close() {
var printFrame = document.getElementById('printJS-Modal');
printFrame.parentNode.removeChild(printFrame);
}
};
/* harmony default export */ __webpack_exports__["default"] = (Modal);
/***/ }),

@@ -207,8 +745,55 @@

\***********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Check if we have base64 data\n if (params.base64) {\n var bytesArray = Uint8Array.from(atob(params.printable), function (c) {\n return c.charCodeAt(0);\n });\n createBlobAndPrint(params, printFrame, bytesArray);\n return;\n }\n\n // Format pdf url\n params.printable = /^(blob|http)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable);\n\n // Get the file through a http request (Preload)\n var req = new window.XMLHttpRequest();\n req.responseType = 'arraybuffer';\n\n req.addEventListener('load', function () {\n // Check for errors\n if ([200, 201].indexOf(req.status) === -1) {\n (0, _functions.cleanUp)(params);\n params.onError(req.statusText);\n\n // Since we don't have a pdf document available, we will stop the print job\n return;\n }\n\n // Print requested document\n createBlobAndPrint(params, printFrame, req.response);\n });\n\n req.open('GET', params.printable, true);\n req.send();\n }\n};\n\n\nfunction createBlobAndPrint(params, printFrame, data) {\n // Pass response or base64 data to a blob and create a local object url\n var localPdf = new window.Blob([data], { type: 'application/pdf' });\n localPdf = window.URL.createObjectURL(localPdf);\n\n // Set iframe src with pdf document url\n printFrame.setAttribute('src', localPdf);\n\n _print2.default.send(params, printFrame);\n}\n\n//# sourceURL=webpack://printJS/./src/js/pdf.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
/* harmony default export */ __webpack_exports__["default"] = ({
print: function print(params, printFrame) {
// Check if we have base64 data
if (params.base64) {
var bytesArray = Uint8Array.from(atob(params.printable), function (c) {
return c.charCodeAt(0);
});
createBlobAndPrint(params, printFrame, bytesArray);
return;
} // Format pdf url
params.printable = /^(blob|http|\/\/)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable); // Get the file through a http request (Preload)
var req = new window.XMLHttpRequest();
req.responseType = 'arraybuffer';
req.addEventListener('load', function () {
// Check for errors
if ([200, 201].indexOf(req.status) === -1) {
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
params.onError(req.statusText); // Since we don't have a pdf document available, we will stop the print job
return;
} // Print requested document
createBlobAndPrint(params, printFrame, req.response);
});
req.open('GET', params.printable, true);
req.send();
}
});
function createBlobAndPrint(params, printFrame, data) {
// Pass response or base64 data to a blob and create a local object url
var localPdf = new window.Blob([data], {
type: 'application/pdf'
});
localPdf = window.URL.createObjectURL(localPdf); // Set iframe src with pdf document url
printFrame.setAttribute('src', localPdf);
_print__WEBPACK_IMPORTED_MODULE_0__["default"].send(params, printFrame);
}
/***/ }),

@@ -220,8 +805,94 @@

\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _browser = __webpack_require__(/*! ./browser */ \"./src/js/browser.js\");\n\nvar _browser2 = _interopRequireDefault(_browser);\n\nvar _functions = __webpack_require__(/*! ./functions */ \"./src/js/functions.js\");\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar Print = {\n send: function send(params, printFrame) {\n // Append iframe element to document body\n document.getElementsByTagName('body')[0].appendChild(printFrame);\n\n // Get iframe element\n var iframeElement = document.getElementById(params.frameId);\n\n // Wait for iframe to load all content\n iframeElement.onload = function () {\n if (params.type === 'pdf') {\n performPrint(iframeElement, params);\n return;\n }\n\n // Get iframe element document\n var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;\n if (printDocument.document) printDocument = printDocument.document;\n\n // Append printable element to the iframe body\n printDocument.body.appendChild(params.printableElement);\n\n // Add custom style\n if (params.type !== 'pdf' && params.style) {\n // Create style element\n var style = document.createElement('style');\n style.innerHTML = params.style;\n\n // Append style element to iframe's head\n printDocument.head.appendChild(style);\n }\n\n // If printing images, wait for them to load inside the iframe\n var images = printDocument.getElementsByTagName('img');\n\n if (images.length > 0) {\n loadIframeImages(images).then(function () {\n return performPrint(iframeElement, params);\n });\n } else {\n performPrint(iframeElement, params);\n }\n };\n }\n};\n\nfunction performPrint(iframeElement, params) {\n try {\n iframeElement.focus();\n\n // If Edge or IE, try catch with execCommand\n if (_browser2.default.isEdge() || _browser2.default.isIE()) {\n try {\n iframeElement.contentWindow.document.execCommand('print', false, null);\n } catch (e) {\n iframeElement.contentWindow.print();\n }\n } else {\n // Other browsers\n iframeElement.contentWindow.print();\n }\n } catch (error) {\n params.onError(error);\n } finally {\n (0, _functions.cleanUp)(params);\n }\n}\n\nfunction loadIframeImages(images) {\n var promises = [];\n\n var _iteratorNormalCompletion = true;\n var _didIteratorError = false;\n var _iteratorError = undefined;\n\n try {\n for (var _iterator = images[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var image = _step.value;\n\n promises.push(loadIframeImage(image));\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n\n return Promise.all(promises);\n}\n\nfunction loadIframeImage(image) {\n return new Promise(function (resolve) {\n var pollImage = function pollImage() {\n !image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage, 500) : resolve();\n };\n pollImage();\n });\n}\n\nexports.default = Print;\n\n//# sourceURL=webpack://printJS/./src/js/print.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _browser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./browser */ "./src/js/browser.js");
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./functions */ "./src/js/functions.js");
var Print = {
send: function send(params, printFrame) {
// Append iframe element to document body
document.getElementsByTagName('body')[0].appendChild(printFrame); // Get iframe element
var iframeElement = document.getElementById(params.frameId); // Wait for iframe to load all content
iframeElement.onload = function () {
if (params.type === 'pdf') {
performPrint(iframeElement, params);
return;
} // Get iframe element document
var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;
if (printDocument.document) printDocument = printDocument.document; // Append printable element to the iframe body
printDocument.body.appendChild(params.printableElement); // Add custom style
if (params.type !== 'pdf' && params.style) {
// Create style element
var style = document.createElement('style');
style.innerHTML = params.style; // Append style element to iframe's head
printDocument.head.appendChild(style);
} // If printing images, wait for them to load inside the iframe
var images = printDocument.getElementsByTagName('img');
if (images.length > 0) {
loadIframeImages(images).then(function () {
return performPrint(iframeElement, params);
});
} else {
performPrint(iframeElement, params);
}
};
}
};
function performPrint(iframeElement, params) {
try {
iframeElement.focus(); // If Edge or IE, try catch with execCommand
if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isEdge() || _browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) {
try {
iframeElement.contentWindow.document.execCommand('print', false, null);
} catch (e) {
iframeElement.contentWindow.print();
}
} else {
// Other browsers
iframeElement.contentWindow.print();
}
} catch (error) {
params.onError(error);
} finally {
Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
}
}
function loadIframeImages(images) {
var promises = images.map(function (image) {
if (image.src && image.src !== window.location.href) {
return loadIframeImage(image);
}
});
return Promise.all(promises);
}
function loadIframeImage(image) {
return new Promise(function (resolve) {
var pollImage = function pollImage() {
!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage, 500) : resolve();
};
pollImage();
});
}
/* harmony default export */ __webpack_exports__["default"] = (Print);
/***/ }),

@@ -233,8 +904,21 @@

\****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _print = __webpack_require__(/*! ./print */ \"./src/js/print.js\");\n\nvar _print2 = _interopRequireDefault(_print);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nexports.default = {\n print: function print(params, printFrame) {\n // Create printable element (container)\n params.printableElement = document.createElement('div');\n params.printableElement.setAttribute('style', 'width:100%');\n\n // Set our raw html as the printable element inner html content\n params.printableElement.innerHTML = params.printable;\n\n // Print html contents\n _print2.default.send(params, printFrame);\n }\n};\n\n//# sourceURL=webpack://printJS/./src/js/raw-html.js?");
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _print__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./print */ "./src/js/print.js");
/* harmony default export */ __webpack_exports__["default"] = ({
print: function print(params, printFrame) {
// Create printable element (container)
params.printableElement = document.createElement('div');
params.printableElement.setAttribute('style', 'width:100%'); // Set our raw html as the printable element inner html content
params.printableElement.innerHTML = params.printable; // Print html contents
_print__WEBPACK_IMPORTED_MODULE_0__["default"].send(params, printFrame);
}
});
/***/ }),

@@ -249,3 +933,3 @@

eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack://printJS/./src/sass/index.scss?");
// extracted by mini-css-extract-plugin

@@ -261,7 +945,9 @@ /***/ }),

eval("module.exports = __webpack_require__(/*! ./src/index.js */\"./src/index.js\");\n\n\n//# sourceURL=webpack://printJS/multi_./src/index.js?");
module.exports = __webpack_require__(/*! ./src/index.js */"./src/index.js");
/***/ })
/******/ })["default"];
});
});
//# sourceMappingURL=print.map

45

package.json

@@ -5,3 +5,3 @@ {

"description": "A tiny javascript library to help printing from the web.",
"version": "1.0.63",
"version": "1.1.0",
"main": "dist/print.js",

@@ -11,27 +11,26 @@ "types": "src/index.d.ts",

"license": "MIT",
"dependencies": {},
"devDependencies": {
"@babel/core": "7.4.5",
"@babel/preset-env": "7.4.5",
"babel-loader": "8.0.6",
"coveralls": "3.0.4",
"css-loader": "2.1.1",
"@babel/core": "7.11.6",
"@babel/preset-env": "7.11.5",
"babel-loader": "8.1.0",
"coveralls": "3.1.0",
"css-loader": "4.2.2",
"istanbul-instrumenter-loader": "3.0.1",
"jasmine-core": "3.4.0",
"karma": "4.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.2",
"karma-jasmine": "2.0.1",
"jasmine-core": "3.6.0",
"karma": "5.2.1",
"karma-chrome-launcher": "3.1.0",
"karma-coverage": "2.0.3",
"karma-jasmine": "4.0.1",
"karma-phantomjs-launcher": "1.0.4",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "3.0.5",
"mini-css-extract-plugin": "0.7.0",
"node-sass": "4.12.0",
"optimize-css-assets-webpack-plugin": "5.0.1",
"sass-loader": "7.1.0",
"standard": "12.0.1",
"uglifyjs-webpack-plugin": "2.1.3",
"webpack": "4.33.0",
"webpack-cli": "3.3.3",
"webpack-dev-server": "3.7.1"
"karma-sourcemap-loader": "0.3.8",
"karma-webpack": "4.0.2",
"mini-css-extract-plugin": "0.11.0",
"node-sass": "4.14.1",
"optimize-css-assets-webpack-plugin": "5.0.4",
"sass-loader": "10.0.2",
"standard": "14.3.4",
"terser-webpack-plugin": "4.1.0",
"webpack": "4.44.1",
"webpack-cli": "3.3.12",
"webpack-dev-server": "3.11.0"
},

@@ -38,0 +37,0 @@ "scripts": {

@@ -5,3 +5,3 @@ import Modal from './modal'

export function addWrapper (htmlData, params) {
let bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;'
const bodyStyle = 'font-family:' + params.font + ' !important; font-size: ' + params.font_size + ' !important; width:100%;'
return '<div style="' + bodyStyle + '">' + htmlData + '</div>'

@@ -15,3 +15,3 @@ }

export function collectStyles (element, params) {
let win = document.defaultView || window
const win = document.defaultView || window

@@ -22,3 +22,3 @@ // String variable to hold styling for each element

// Loop over computed styles
let styles = win.getComputedStyle(element, '')
const styles = win.getComputedStyle(element, '')

@@ -47,3 +47,3 @@ Object.keys(styles).map(key => {

// Create the header container div
let headerContainer = document.createElement('div')
const headerContainer = document.createElement('div')

@@ -55,6 +55,6 @@ // Check if the header is text or raw html

// Create header element
let headerElement = document.createElement('h1')
const headerElement = document.createElement('h1')
// Create header text node
let headerNode = document.createTextNode(params.header)
const headerNode = document.createTextNode(params.header)

@@ -100,4 +100,4 @@ // Build and style

export function isRawHTML (raw) {
let regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>')
const regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>')
return regexHtml.test(raw)
}

@@ -7,3 +7,3 @@ import { collectStyles, addHeader } from './functions'

// Get the DOM printable element
let printElement = document.getElementById(params.printable)
const printElement = document.getElementById(params.printable)

@@ -10,0 +10,0 @@ // Check if the element exists

@@ -18,3 +18,3 @@ import { addHeader } from './functions'

// Create the image element
let img = document.createElement('img')
const img = document.createElement('img')
img.setAttribute('style', params.imageStyle)

@@ -26,3 +26,3 @@

// Create the image wrapper
let imageWrapper = document.createElement('div')
const imageWrapper = document.createElement('div')

@@ -29,0 +29,0 @@ // Append image to the wrapper element

@@ -15,3 +15,3 @@ 'use strict'

init () {
let params = {
const params = {
printable: null,

@@ -53,3 +53,3 @@ fallbackPrintable: null,

// Check if a printable document or object was supplied
let args = arguments[0]
const args = arguments[0]
if (args === undefined) throw new Error('printJS expects at least 1 attribute.')

@@ -94,12 +94,9 @@

// To prevent duplication and issues, remove any used printFrame from the DOM
let usedFrame = document.getElementById(params.frameId)
const usedFrame = document.getElementById(params.frameId)
if (usedFrame) usedFrame.parentNode.removeChild(usedFrame)
// Create a new iframe or embed element (IE prints blank pdf's if we use iframe)
let printFrame
// Create a new iframe for the print job
const printFrame = document.createElement('iframe')
// Create iframe element
printFrame = document.createElement('iframe')
// Hide iframe

@@ -137,3 +134,3 @@ printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute;')

if (params.onBrowserIncompatible() === true) {
let win = window.open(params.fallbackPrintable, '_blank')
const win = window.open(params.fallbackPrintable, '_blank')
win.focus()

@@ -140,0 +137,0 @@ if (params.onPdfOpen) params.onPdfOpen()

@@ -48,4 +48,4 @@ import { capitalizePrint, addHeader } from './functions'

// Get the row and column data
let data = params.printable
let properties = params.properties
const data = params.printable
const properties = params.properties

@@ -89,3 +89,3 @@ // Create a html table

// Support nested objects
let property = properties[n].field.split('.')
const property = properties[n].field.split('.')
if (property.length > 1) {

@@ -92,0 +92,0 @@ for (let p = 0; p < property.length; p++) {

const Modal = {
show (params) {
// Build modal
let modalStyle = 'font-family:sans-serif; ' +
const modalStyle = 'font-family:sans-serif; ' +
'display:table; ' +

@@ -19,3 +19,3 @@ 'text-align:center; ' +

// Create wrapper
let printModal = document.createElement('div')
const printModal = document.createElement('div')
printModal.setAttribute('style', modalStyle)

@@ -25,7 +25,7 @@ printModal.setAttribute('id', 'printJS-Modal')

// Create content div
let contentDiv = document.createElement('div')
const contentDiv = document.createElement('div')
contentDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; padding-bottom:100px;')
// Add close button (requires print.css)
let closeButton = document.createElement('div')
const closeButton = document.createElement('div')
closeButton.setAttribute('class', 'printClose')

@@ -36,3 +36,3 @@ closeButton.setAttribute('id', 'printClose')

// Add spinner (requires print.css)
let spinner = document.createElement('span')
const spinner = document.createElement('span')
spinner.setAttribute('class', 'printSpinner')

@@ -42,3 +42,3 @@ contentDiv.appendChild(spinner)

// Add message
let messageNode = document.createTextNode(params.modalMessage)
const messageNode = document.createTextNode(params.modalMessage)
contentDiv.appendChild(messageNode)

@@ -58,3 +58,3 @@

close () {
let printFrame = document.getElementById('printJS-Modal')
const printFrame = document.getElementById('printJS-Modal')

@@ -61,0 +61,0 @@ printFrame.parentNode.removeChild(printFrame)

@@ -14,3 +14,3 @@ import Print from './print'

// Format pdf url
params.printable = /^(blob|http)/i.test(params.printable)
params.printable = /^(blob|http|\/\/)/i.test(params.printable)
? params.printable

@@ -20,3 +20,3 @@ : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable)

// Get the file through a http request (Preload)
let req = new window.XMLHttpRequest()
const req = new window.XMLHttpRequest()
req.responseType = 'arraybuffer'

@@ -23,0 +23,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc