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.56 to 1.0.57

140

dist/print.js

@@ -617,31 +617,8 @@ (function webpackUniversalModuleDefinition(root, factory) {

params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable;
params.type = typeof args.type !== 'undefined' ? args.type : params.type;
params.frameId = typeof args.frameId !== 'undefined' ? args.frameId : params.frameId;
params.header = typeof args.header !== 'undefined' ? args.header : params.header;
params.headerStyle = typeof args.headerStyle !== 'undefined' ? args.headerStyle : params.headerStyle;
params.maxWidth = typeof args.maxWidth !== 'undefined' ? args.maxWidth : params.maxWidth;
params.font = typeof args.font !== 'undefined' ? args.font : params.font;
params.font_size = typeof args.font_size !== 'undefined' ? args.font_size : params.font_size;
params.honorMarginPadding = typeof args.honorMarginPadding !== 'undefined' ? args.honorMarginPadding : params.honorMarginPadding;
params.properties = typeof args.properties !== 'undefined' ? args.properties : params.properties;
params.gridHeaderStyle = typeof args.gridHeaderStyle !== 'undefined' ? args.gridHeaderStyle : params.gridHeaderStyle;
params.gridStyle = typeof args.gridStyle !== 'undefined' ? args.gridStyle : params.gridStyle;
params.showModal = typeof args.showModal !== 'undefined' ? args.showModal : params.showModal;
params.onError = typeof args.onError !== 'undefined' ? args.onError : params.onError;
params.onLoadingStart = typeof args.onLoadingStart !== 'undefined' ? args.onLoadingStart : params.onLoadingStart;
params.onLoadingEnd = typeof args.onLoadingEnd !== 'undefined' ? args.onLoadingEnd : params.onLoadingEnd;
params.onPrintDialogClose = typeof args.onPrintDialogClose !== 'undefined' ? args.onPrintDialogClose : params.onPrintDialogClose;
params.onPdfOpen = typeof args.onPdfOpen !== 'undefined' ? args.onPdfOpen : params.onPdfOpen;
params.onBrowserIncompatible = typeof args.onBrowserIncompatible !== 'undefined' ? args.onBrowserIncompatible : params.onBrowserIncompatible;
params.modalMessage = typeof args.modalMessage !== 'undefined' ? args.modalMessage : params.modalMessage;
params.documentTitle = typeof args.documentTitle !== 'undefined' ? args.documentTitle : params.documentTitle;
params.targetStyle = typeof args.targetStyle !== 'undefined' ? args.targetStyle : params.targetStyle;
params.targetStyles = typeof args.targetStyles !== 'undefined' ? args.targetStyles : params.targetStyles;
params.ignoreElements = typeof args.ignoreElements !== 'undefined' ? args.ignoreElements : params.ignoreElements;
params.imageStyle = typeof args.imageStyle !== 'undefined' ? args.imageStyle : params.imageStyle;
params.repeatTableHeader = typeof args.repeatTableHeader !== 'undefined' ? args.repeatTableHeader : params.repeatTableHeader;
params.css = typeof args.css !== 'undefined' ? args.css : params.css;
params.style = typeof args.style !== 'undefined' ? args.style : params.style;
params.scanStyles = typeof args.scanStyles !== 'undefined' ? args.scanStyles : params.scanStyles;
params.base64 = typeof args.base64 !== 'undefined';
for (var k in params) {
if (k === 'printable' || k === 'fallbackPrintable' || k === 'base64') continue;
params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k];
}
break;

@@ -969,3 +946,6 @@ default:

if (params.base64) {
createBlobAndPrint(params, printFrame, params.printable);
var bytesArray = Uint8Array.from(atob(params.printable), function (c) {
return c.charCodeAt(0);
});
createBlobAndPrint(params, printFrame, bytesArray);
return;

@@ -1045,37 +1025,36 @@ }

// Wait for iframe to load all content
if (params.type === 'pdf' && (_browser2.default.isIE() || _browser2.default.isEdge())) {
iframeElement.setAttribute('onload', performPrint(iframeElement, params));
} else {
printFrame.onload = function () {
if (params.type === 'pdf') {
performPrint(iframeElement, params);
} else {
// Get iframe element document
var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;
if (printDocument.document) printDocument = printDocument.document;
iframeElement.onload = function () {
if (params.type === 'pdf') {
performPrint(iframeElement, params);
return;
}
// Inject printable html into iframe body
printDocument.body.innerHTML = params.htmlData;
// Get iframe element document
var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;
if (printDocument.document) printDocument = printDocument.document;
// Add custom style
if (params.type !== 'pdf' && params.style !== null) {
// Create style element
var style = document.createElement('style');
style.innerHTML = params.style;
// Inject printable html into iframe body
printDocument.body.innerHTML = params.htmlData;
// Append style element to iframe's head
printDocument.head.appendChild(style);
}
// Add custom style
if (params.type !== 'pdf' && params.style !== null) {
// Create style element
var style = document.createElement('style');
style.innerHTML = params.style;
// If printing image, wait for it to load inside the iframe
if (params.type === 'image') {
loadIframeImages(printDocument, params).then(function () {
performPrint(iframeElement, params);
});
} else {
performPrint(iframeElement, params);
}
}
};
}
// 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);
}
};
}

@@ -1106,20 +1085,37 @@ };

function loadIframeImages(printDocument, params) {
var promises = params.printable.map(function (image, index) {
return loadIframeImage(printDocument, index);
});
function loadIframeImages(images) {
var promises = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = images[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var image = _step.value;
promises.push(loadIframeImage(image));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return Promise.all(promises);
}
function loadIframeImage(printDocument, index) {
function loadIframeImage(image) {
return new Promise(function (resolve) {
var pollImage = function pollImage() {
var image = printDocument ? printDocument.getElementById('printableImage' + index) : null;
if (!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0) {
setTimeout(pollImage, 500);
} else {
resolve();
}
!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage, 500) : resolve();
};

@@ -1126,0 +1122,0 @@ pollImage();

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

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

@@ -8,0 +8,0 @@ "types": "src/index.d.ts",

@@ -65,31 +65,8 @@ 'use strict'

params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable
params.type = typeof args.type !== 'undefined' ? args.type : params.type
params.frameId = typeof args.frameId !== 'undefined' ? args.frameId : params.frameId
params.header = typeof args.header !== 'undefined' ? args.header : params.header
params.headerStyle = typeof args.headerStyle !== 'undefined' ? args.headerStyle : params.headerStyle
params.maxWidth = typeof args.maxWidth !== 'undefined' ? args.maxWidth : params.maxWidth
params.font = typeof args.font !== 'undefined' ? args.font : params.font
params.font_size = typeof args.font_size !== 'undefined' ? args.font_size : params.font_size
params.honorMarginPadding = typeof args.honorMarginPadding !== 'undefined' ? args.honorMarginPadding : params.honorMarginPadding
params.properties = typeof args.properties !== 'undefined' ? args.properties : params.properties
params.gridHeaderStyle = typeof args.gridHeaderStyle !== 'undefined' ? args.gridHeaderStyle : params.gridHeaderStyle
params.gridStyle = typeof args.gridStyle !== 'undefined' ? args.gridStyle : params.gridStyle
params.showModal = typeof args.showModal !== 'undefined' ? args.showModal : params.showModal
params.onError = typeof args.onError !== 'undefined' ? args.onError : params.onError
params.onLoadingStart = typeof args.onLoadingStart !== 'undefined' ? args.onLoadingStart : params.onLoadingStart
params.onLoadingEnd = typeof args.onLoadingEnd !== 'undefined' ? args.onLoadingEnd : params.onLoadingEnd
params.onPrintDialogClose = typeof args.onPrintDialogClose !== 'undefined' ? args.onPrintDialogClose : params.onPrintDialogClose
params.onPdfOpen = typeof args.onPdfOpen !== 'undefined' ? args.onPdfOpen : params.onPdfOpen
params.onBrowserIncompatible = typeof args.onBrowserIncompatible !== 'undefined' ? args.onBrowserIncompatible : params.onBrowserIncompatible
params.modalMessage = typeof args.modalMessage !== 'undefined' ? args.modalMessage : params.modalMessage
params.documentTitle = typeof args.documentTitle !== 'undefined' ? args.documentTitle : params.documentTitle
params.targetStyle = typeof args.targetStyle !== 'undefined' ? args.targetStyle : params.targetStyle
params.targetStyles = typeof args.targetStyles !== 'undefined' ? args.targetStyles : params.targetStyles
params.ignoreElements = typeof args.ignoreElements !== 'undefined' ? args.ignoreElements : params.ignoreElements
params.imageStyle = typeof args.imageStyle !== 'undefined' ? args.imageStyle : params.imageStyle
params.repeatTableHeader = typeof args.repeatTableHeader !== 'undefined' ? args.repeatTableHeader : params.repeatTableHeader
params.css = typeof args.css !== 'undefined' ? args.css : params.css
params.style = typeof args.style !== 'undefined' ? args.style : params.style
params.scanStyles = typeof args.scanStyles !== 'undefined' ? args.scanStyles : params.scanStyles
params.base64 = typeof args.base64 !== 'undefined'
for (var k in params) {
if (k === 'printable' || k === 'fallbackPrintable' || k === 'base64') continue
params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k]
}
break

@@ -96,0 +73,0 @@ default:

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

if (params.base64) {
createBlobAndPrint(params, printFrame, params.printable)
const bytesArray = Uint8Array.from(atob(params.printable), c => c.charCodeAt(0))
createBlobAndPrint(params, printFrame, bytesArray)
return

@@ -11,0 +12,0 @@ }

@@ -10,39 +10,36 @@ import Browser from './browser'

// Get iframe element
let iframeElement = document.getElementById(params.frameId)
const iframeElement = document.getElementById(params.frameId)
// Wait for iframe to load all content
if (params.type === 'pdf' && (Browser.isIE() || Browser.isEdge())) {
iframeElement.setAttribute('onload', performPrint(iframeElement, params))
} else {
printFrame.onload = () => {
if (params.type === 'pdf') {
performPrint(iframeElement, params)
} else {
// Get iframe element document
let printDocument = (iframeElement.contentWindow || iframeElement.contentDocument)
if (printDocument.document) printDocument = printDocument.document
iframeElement.onload = () => {
if (params.type === 'pdf') {
performPrint(iframeElement, params)
return
}
// Inject printable html into iframe body
printDocument.body.innerHTML = params.htmlData
// Get iframe element document
let printDocument = (iframeElement.contentWindow || iframeElement.contentDocument)
if (printDocument.document) printDocument = printDocument.document
// Add custom style
if (params.type !== 'pdf' && params.style !== null) {
// Create style element
const style = document.createElement('style')
style.innerHTML = params.style
// Inject printable html into iframe body
printDocument.body.innerHTML = params.htmlData
// Append style element to iframe's head
printDocument.head.appendChild(style)
}
// Add custom style
if (params.type !== 'pdf' && params.style !== null) {
// Create style element
const style = document.createElement('style')
style.innerHTML = params.style
// If printing image, wait for it to load inside the iframe
if (params.type === 'image') {
loadIframeImages(printDocument, params).then(() => {
performPrint(iframeElement, params)
})
} else {
performPrint(iframeElement, params)
}
}
// Append style element to iframe's head
printDocument.head.appendChild(style)
}
// If printing images, wait for them to load inside the iframe
const images = printDocument.getElementsByTagName('img')
if (images.length > 0) {
loadIframeImages(images).then(() => performPrint(iframeElement, params))
} else {
performPrint(iframeElement, params)
}
}

@@ -74,18 +71,18 @@ }

function loadIframeImages (printDocument, params) {
const promises = params.printable.map((image, index) => loadIframeImage(printDocument, index))
function loadIframeImages (images) {
const promises = []
for (let image of images) {
promises.push(loadIframeImage(image))
}
return Promise.all(promises)
}
function loadIframeImage (printDocument, index) {
function loadIframeImage (image) {
return new Promise(resolve => {
const pollImage = () => {
let image = printDocument ? printDocument.getElementById('printableImage' + index) : null
if (!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0) {
setTimeout(pollImage, 500)
} else {
resolve()
}
!image || typeof image.naturalWidth === 'undefined' || image.naturalWidth === 0 || !image.complete
? setTimeout(pollImage, 500)
: resolve()
}

@@ -92,0 +89,0 @@ pollImage()

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