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

react-to-print

Package Overview
Dependencies
Maintainers
2
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-to-print - npm Package Compare versions

Comparing version 2.12.3 to 2.12.4

9

CHANGELOG.md
# CHANGELOG
## 2.12.3 (Feb 5th, 2021)
## 2.12.4 (April 10th, 2021)
- CHORE: Upgraded all `devDependencies`
- DOCS: Added a section to the README about workarounds for functional components as the `ComponentToPrint`
## 2.12.3 (February 5th, 2021)
- FIX [344](https://github.com/gregnb/react-to-print/pull/344): Remove the single use of [`ParentNode.append`](https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append) in favor of [`Node.appendChild`](https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild). `append` is not supported by IE11, and polyfilling it within the context of an iframe can be difficult

@@ -9,3 +14,3 @@ - FIX [344](https://github.com/gregnb/react-to-print/pull/344): While testing the above I realized that trying to print out a bare string didn't work. This has been fixed

## 2.12.2 (Jan 1st, 2021)
## 2.12.2 (January 1st, 2021)

@@ -12,0 +17,0 @@ Happy new years!

/*! For license information please see index.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("lib",["react","react-dom"],t):"object"==typeof exports?exports.lib=t(require("react"),require("react-dom")):e.lib=t(e.react,e["react-dom"])}("undefined"!=typeof self?self:this,(function(e,t){return function(){"use strict";var n={629:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.useReactToPrint=t.PrintContextConsumer=void 0;var r=n(655),o=n(297),i=n(268),a=Object.prototype.hasOwnProperty.call(o,"createContext"),l=Object.prototype.hasOwnProperty.call(o,"useMemo")&&Object.prototype.hasOwnProperty.call(o,"useCallback"),c=a?o.createContext({}):null;t.PrintContextConsumer=c?c.Consumer:function(){return null};var u={copyStyles:!0,pageStyle:"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }",removeAfterPrint:!1,suppressErrors:!1},s=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.startPrint=function(e){var n=t.props,r=n.onAfterPrint,o=n.onPrintError,i=n.print,a=n.suppressErrors,l=n.documentTitle;setTimeout((function(){if(e.contentWindow){if(e.contentWindow.focus(),i)i(e).then(t.handleRemoveIframe).catch((function(e){o?o("print",e):a||console.error("An error was thrown by the specified `print` function",e)}));else if(e.contentWindow.print){var n=document.title;l&&(document.title=l),e.contentWindow.print(),l&&(document.title=n),r&&r()}else a||console.error("Printing for this browser is not currently possible: the browser does not have a `print` method available for iframes.");t.handleRemoveIframe()}else a||console.error("Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/gregnb/react-to-print/issues/")}),500)},t.triggerPrint=function(e){var n=t.props,r=n.onBeforePrint,o=n.onPrintError;if(r){var i=r();i&&"function"==typeof i.then?i.then((function(){t.startPrint(e)})).catch((function(e){o&&o("onBeforePrint",e)})):t.startPrint(e)}else t.startPrint(e)},t.handleClick=function(){var e=t.props,n=e.onBeforeGetContent,r=e.onPrintError;if(n){var o=n();o&&"function"==typeof o.then?o.then(t.handlePrint).catch((function(e){r&&r("onBeforeGetContent",e)})):t.handlePrint()}else t.handlePrint()},t.handlePrint=function(){var e=t.props,n=e.bodyClass,o=e.content,a=e.copyStyles,l=e.fonts,c=e.pageStyle,u=e.suppressErrors,s=o();if(void 0!==s)if(null!==s){var f=document.createElement("iframe");f.style.position="absolute",f.style.top="-1000px",f.style.left="-1000px",f.id="printWindow",f.title="Print Window";var p=i.findDOMNode(s);if(p){var d=p instanceof Text,h=document.querySelectorAll("link[rel='stylesheet']"),y=d?[]:p.querySelectorAll("img");t.linkTotal=h.length+y.length,t.linksLoaded=[],t.linksErrored=[],t.fontsLoaded=[],t.fontsErrored=[];var v=function(e,n){n?t.linksLoaded.push(e):(u||console.error('"react-to-print" was unable to load a linked node. It may be invalid. "react-to-print" will continue attempting to print the page. The linked node that errored was:',e),t.linksErrored.push(e)),t.linksLoaded.length+t.linksErrored.length+t.fontsLoaded.length+t.fontsErrored.length===t.linkTotal&&t.triggerPrint(f)};f.onload=function(){var e,o,i,s;f.onload=null;var h=f.contentDocument||(null===(o=f.contentWindow)||void 0===o?void 0:o.document);if(h){h.body.appendChild(p.cloneNode(!0)),l&&((null===(i=f.contentDocument)||void 0===i?void 0:i.fonts)&&(null===(s=f.contentWindow)||void 0===s?void 0:s.FontFace)?l.forEach((function(e){var n=new FontFace(e.family,e.source);f.contentDocument.fonts.add(n),n.loaded.then((function(e){t.fontsLoaded.push(e)})).catch((function(e){t.fontsErrored.push(n),u||console.error('"react-to-print" was unable to load a font. "react-to-print" will continue attempting to print the page. The font that failed to load is:',n,"The error from loading the font is:",e)}))})):u||console.error('"react-to-print" is not able to load custom fonts because the browser does not support the FontFace API'));var b="function"==typeof c?c():c;if("string"!=typeof b)u||console.error('"react-to-print" expected a "string" from `pageStyle` but received "'+typeof b+'". Styles from `pageStyle` will not be applied.');else{var m=h.createElement("style");m.appendChild(h.createTextNode(b)),h.head.appendChild(m)}if(n&&(e=h.body.classList).add.apply(e,r.__spread(n.split(" "))),!d){for(var g=h.querySelectorAll("canvas"),w=p.querySelectorAll("canvas"),_=0,P=g.length;_<P;++_){var S=(L=g[_]).getContext("2d");S&&S.drawImage(w[_],0,0)}for(_=0;_<y.length;_++){var x=y[_],O=x.getAttribute("src");if(O){var k=new Image;k.onload=v.bind(null,x,!0),k.onerror=v.bind(null,x,!1),k.src=O}else u||console.warn('"react-to-print" encountered an <img> tag with an empty "src" attribute. It will not attempt to pre-load it. The <img> is:',x)}var T="input",E=p.querySelectorAll(T),j=h.querySelectorAll(T);for(_=0;_<E.length;_++)j[_].value=E[_].value;var C="input[type=checkbox],input[type=radio]",A=p.querySelectorAll(C),I=h.querySelectorAll(C);for(_=0;_<A.length;_++)I[_].checked=A[_].checked;var R="select",q=p.querySelectorAll(R),M=h.querySelectorAll(R);for(_=0;_<q.length;_++)M[_].value=q[_].value}if(a)for(var W=document.querySelectorAll("style, link[rel='stylesheet']"),F=(_=0,W.length);_<F;++_){var L;if("STYLE"===(L=W[_]).tagName){var D=h.createElement(L.tagName),N=L.sheet;if(N){for(var B="",G=0,V=N.cssRules.length;G<V;++G)"string"==typeof N.cssRules[G].cssText&&(B+=N.cssRules[G].cssText+"\r\n");D.setAttribute("id","react-to-print-"+_),D.appendChild(h.createTextNode(B)),h.head.appendChild(D)}}else if(L.getAttribute("href")){D=h.createElement(L.tagName),G=0;for(var z=L.attributes.length;G<z;++G){var H=L.attributes[G];H&&D.setAttribute(H.nodeName,H.nodeValue||"")}D.onload=v.bind(null,D,!0),D.onerror=v.bind(null,D,!1),h.head.appendChild(D)}else u||console.warn('"react-to-print" encountered a <link> tag with an empty "href" attribute. In addition to being invalid HTML, this can cause problems in many browsers, and so the <link> was not loaded. The <link> is:',L),v(L,!0)}}0!==t.linkTotal&&a||t.triggerPrint(f)},t.handleRemoveIframe(!0),document.body.appendChild(f)}else u||console.error('"react-to-print" could not locate the DOM node corresponding with the `content` prop')}else u||console.error('There is nothing to print because the "content" prop returned "null". Please ensure "content" is renderable before allowing "react-to-print" to be called.');else u||console.error('For "react-to-print" to work only Class based components can be printed.')},t.handleRemoveIframe=function(e){var n=t.props.removeAfterPrint;if(e||n){var r=document.getElementById("printWindow");r&&document.body.removeChild(r)}},t}return r.__extends(t,e),t.prototype.render=function(){var e=this.props,t=e.children,n=e.suppressErrors,r=e.trigger;if(r)return o.cloneElement(r(),{onClick:this.handleClick});if(!c)return n||console.error('"react-to-print" requires React ^16.3.0 to be able to use "PrintContext"'),null;var i={handlePrint:this.handleClick};return o.createElement(c.Provider,{value:i},t)},t.defaultProps=u,t}(o.Component);t.default=s,t.useReactToPrint=l?function(e){var t=o.useMemo((function(){return new s(r.__assign(r.__assign({},u),e))}),[e]);return o.useCallback((function(){return t.handleClick()}),[t])}:function(e){e.suppressErrors||console.warn('"react-to-print" requires React ^16.8.0 to be able to use "useReactToPrint"')}},655:function(e,t,n){n.r(t),n.d(t,{__extends:function(){return o},__assign:function(){return i},__rest:function(){return a},__decorate:function(){return l},__param:function(){return c},__metadata:function(){return u},__awaiter:function(){return s},__generator:function(){return f},__exportStar:function(){return p},__values:function(){return d},__read:function(){return h},__spread:function(){return y},__spreadArrays:function(){return v},__await:function(){return b},__asyncGenerator:function(){return m},__asyncDelegator:function(){return g},__asyncValues:function(){return w},__makeTemplateObject:function(){return _},__importStar:function(){return P},__importDefault:function(){return S},__classPrivateFieldGet:function(){return x},__classPrivateFieldSet:function(){return O}});var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function c(e,t){return function(n,r){t(n,r,e)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function l(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}c((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}function p(e,t){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}function d(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function y(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(h(arguments[t]));return e}function v(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,l=i.length;a<l;a++,o++)r[o]=i[a];return r}function b(e){return this instanceof b?(this.v=e,this):new b(e)}function m(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r={},a("next"),a("throw"),a("return"),r[Symbol.asyncIterator]=function(){return this},r;function a(e){o[e]&&(r[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||l(e,t)}))})}function l(e,t){try{(n=o[e](t)).value instanceof b?Promise.resolve(n.value.v).then(c,u):s(i[0][2],n)}catch(e){s(i[0][3],e)}var n}function c(e){l("next",e)}function u(e){l("throw",e)}function s(e,t){e(t),i.shift(),i.length&&l(i[0][0],i[0][1])}}function g(e){var t,n;return t={},r("next"),r("throw",(function(e){throw e})),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,o){t[r]=e[r]?function(t){return(n=!n)?{value:b(e[r](t)),done:"return"===r}:o?o(t):t}:o}}function w(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=d(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){!function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)}(r,o,(t=e[n](t)).done,t.value)}))}}}function _(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function P(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function S(e){return e&&e.__esModule?e:{default:e}}function x(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}function O(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n}},297:function(t){t.exports=e},268:function(e){e.exports=t}},r={};function o(e){if(r[e])return r[e].exports;var t=r[e]={exports:{}};return n[e](t,t.exports,o),t.exports}return o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o(629)}()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("lib",["react","react-dom"],t):"object"==typeof exports?exports.lib=t(require("react"),require("react-dom")):e.lib=t(e.react,e["react-dom"])}("undefined"!=typeof self?self:this,(function(e,t){return function(){"use strict";var n={655:function(e,t,n){n.r(t),n.d(t,{__extends:function(){return o},__assign:function(){return i},__rest:function(){return a},__decorate:function(){return l},__param:function(){return c},__metadata:function(){return u},__awaiter:function(){return s},__generator:function(){return f},__createBinding:function(){return d},__exportStar:function(){return p},__values:function(){return h},__read:function(){return y},__spread:function(){return v},__spreadArrays:function(){return b},__spreadArray:function(){return m},__await:function(){return w},__asyncGenerator:function(){return g},__asyncDelegator:function(){return _},__asyncValues:function(){return P},__makeTemplateObject:function(){return O},__importStar:function(){return x},__importDefault:function(){return j},__classPrivateFieldGet:function(){return T},__classPrivateFieldSet:function(){return E}});var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function c(e,t){return function(n,r){t(n,r,e)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function l(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}c((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}var d=Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]};function p(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||d(t,e,n)}function h(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function v(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(y(arguments[t]));return e}function b(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,l=i.length;a<l;a++,o++)r[o]=i[a];return r}function m(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e}function w(e){return this instanceof w?(this.v=e,this):new w(e)}function g(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r={},a("next"),a("throw"),a("return"),r[Symbol.asyncIterator]=function(){return this},r;function a(e){o[e]&&(r[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||l(e,t)}))})}function l(e,t){try{(n=o[e](t)).value instanceof w?Promise.resolve(n.value.v).then(c,u):s(i[0][2],n)}catch(e){s(i[0][3],e)}var n}function c(e){l("next",e)}function u(e){l("throw",e)}function s(e,t){e(t),i.shift(),i.length&&l(i[0][0],i[0][1])}}function _(e){var t,n;return t={},r("next"),r("throw",(function(e){throw e})),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,o){t[r]=e[r]?function(t){return(n=!n)?{value:w(e[r](t)),done:"return"===r}:o?o(t):t}:o}}function P(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=h(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){!function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)}(r,o,(t=e[n](t)).done,t.value)}))}}}function O(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var S=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function x(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&d(t,e,n);return S(t,e),t}function j(e){return e&&e.__esModule?e:{default:e}}function T(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function E(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}},297:function(t){t.exports=e},268:function(e){e.exports=t}},r={};function o(e){var t=r[e];if(void 0!==t)return t.exports;var i=r[e]={exports:{}};return n[e](i,i.exports,o),i.exports}o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.useReactToPrint=e.PrintContextConsumer=void 0;var t=o(655),n=o(297),r=o(268),a=Object.prototype.hasOwnProperty.call(n,"createContext"),l=Object.prototype.hasOwnProperty.call(n,"useMemo")&&Object.prototype.hasOwnProperty.call(n,"useCallback"),c=a?n.createContext({}):null;e.PrintContextConsumer=c?c.Consumer:function(){return null};var u={copyStyles:!0,pageStyle:"@page { size: auto; margin: 0mm; } @media print { body { -webkit-print-color-adjust: exact; } }",removeAfterPrint:!1,suppressErrors:!1},s=function(e){function o(){var n=null!==e&&e.apply(this,arguments)||this;return n.startPrint=function(e){var t=n.props,r=t.onAfterPrint,o=t.onPrintError,i=t.print,a=t.suppressErrors,l=t.documentTitle;setTimeout((function(){if(e.contentWindow){if(e.contentWindow.focus(),i)i(e).then(n.handleRemoveIframe).catch((function(e){o?o("print",e):a||console.error("An error was thrown by the specified `print` function",e)}));else if(e.contentWindow.print){var t=document.title;l&&(document.title=l),e.contentWindow.print(),l&&(document.title=t),r&&r()}else a||console.error("Printing for this browser is not currently possible: the browser does not have a `print` method available for iframes.");n.handleRemoveIframe()}else a||console.error("Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/gregnb/react-to-print/issues/")}),500)},n.triggerPrint=function(e){var t=n.props,r=t.onBeforePrint,o=t.onPrintError;if(r){var i=r();i&&"function"==typeof i.then?i.then((function(){n.startPrint(e)})).catch((function(e){o&&o("onBeforePrint",e)})):n.startPrint(e)}else n.startPrint(e)},n.handleClick=function(){var e=n.props,t=e.onBeforeGetContent,r=e.onPrintError;if(t){var o=t();o&&"function"==typeof o.then?o.then(n.handlePrint).catch((function(e){r&&r("onBeforeGetContent",e)})):n.handlePrint()}else n.handlePrint()},n.handlePrint=function(){var e=n.props,o=e.bodyClass,i=e.content,a=e.copyStyles,l=e.fonts,c=e.pageStyle,u=e.suppressErrors,s=i();if(void 0!==s)if(null!==s){var f=document.createElement("iframe");f.style.position="absolute",f.style.top="-1000px",f.style.left="-1000px",f.id="printWindow",f.title="Print Window";var d=r.findDOMNode(s);if(d){var p=d instanceof Text,h=document.querySelectorAll("link[rel='stylesheet']"),y=p?[]:d.querySelectorAll("img");n.linkTotal=h.length+y.length,n.linksLoaded=[],n.linksErrored=[],n.fontsLoaded=[],n.fontsErrored=[];var v=function(e,t){t?n.linksLoaded.push(e):(u||console.error('"react-to-print" was unable to load a linked node. It may be invalid. "react-to-print" will continue attempting to print the page. The linked node that errored was:',e),n.linksErrored.push(e)),n.linksLoaded.length+n.linksErrored.length+n.fontsLoaded.length+n.fontsErrored.length===n.linkTotal&&n.triggerPrint(f)};f.onload=function(){var e,r,i,s;f.onload=null;var h=f.contentDocument||(null===(r=f.contentWindow)||void 0===r?void 0:r.document);if(h){h.body.appendChild(d.cloneNode(!0)),l&&((null===(i=f.contentDocument)||void 0===i?void 0:i.fonts)&&(null===(s=f.contentWindow)||void 0===s?void 0:s.FontFace)?l.forEach((function(e){var t=new FontFace(e.family,e.source);f.contentDocument.fonts.add(t),t.loaded.then((function(e){n.fontsLoaded.push(e)})).catch((function(e){n.fontsErrored.push(t),u||console.error('"react-to-print" was unable to load a font. "react-to-print" will continue attempting to print the page. The font that failed to load is:',t,"The error from loading the font is:",e)}))})):u||console.error('"react-to-print" is not able to load custom fonts because the browser does not support the FontFace API'));var b="function"==typeof c?c():c;if("string"!=typeof b)u||console.error('"react-to-print" expected a "string" from `pageStyle` but received "'+typeof b+'". Styles from `pageStyle` will not be applied.');else{var m=h.createElement("style");m.appendChild(h.createTextNode(b)),h.head.appendChild(m)}if(o&&(e=h.body.classList).add.apply(e,t.__spreadArray([],t.__read(o.split(" ")))),!p){for(var w=h.querySelectorAll("canvas"),g=d.querySelectorAll("canvas"),_=0,P=w.length;_<P;++_){var O=(L=w[_]).getContext("2d");O&&O.drawImage(g[_],0,0)}for(_=0;_<y.length;_++){var S=y[_],x=S.getAttribute("src");if(x){var j=new Image;j.onload=v.bind(null,S,!0),j.onerror=v.bind(null,S,!1),j.src=x}else u||console.warn('"react-to-print" encountered an <img> tag with an empty "src" attribute. It will not attempt to pre-load it. The <img> is:',S)}var T="input",E=d.querySelectorAll(T),k=h.querySelectorAll(T);for(_=0;_<E.length;_++)k[_].value=E[_].value;var C="input[type=checkbox],input[type=radio]",A=d.querySelectorAll(C),I=h.querySelectorAll(C);for(_=0;_<A.length;_++)I[_].checked=A[_].checked;var R="select",q=d.querySelectorAll(R),M=h.querySelectorAll(R);for(_=0;_<q.length;_++)M[_].value=q[_].value}if(a)for(var W=document.querySelectorAll("style, link[rel='stylesheet']"),F=(_=0,W.length);_<F;++_){var L;if("STYLE"===(L=W[_]).tagName){var D=h.createElement(L.tagName),N=L.sheet;if(N){for(var B="",G=0,V=N.cssRules.length;G<V;++G)"string"==typeof N.cssRules[G].cssText&&(B+=N.cssRules[G].cssText+"\r\n");D.setAttribute("id","react-to-print-"+_),D.appendChild(h.createTextNode(B)),h.head.appendChild(D)}}else if(L.getAttribute("href")){D=h.createElement(L.tagName),G=0;for(var z=L.attributes.length;G<z;++G){var H=L.attributes[G];H&&D.setAttribute(H.nodeName,H.nodeValue||"")}D.onload=v.bind(null,D,!0),D.onerror=v.bind(null,D,!1),h.head.appendChild(D)}else u||console.warn('"react-to-print" encountered a <link> tag with an empty "href" attribute. In addition to being invalid HTML, this can cause problems in many browsers, and so the <link> was not loaded. The <link> is:',L),v(L,!0)}}0!==n.linkTotal&&a||n.triggerPrint(f)},n.handleRemoveIframe(!0),document.body.appendChild(f)}else u||console.error('"react-to-print" could not locate the DOM node corresponding with the `content` prop')}else u||console.error('There is nothing to print because the "content" prop returned "null". Please ensure "content" is renderable before allowing "react-to-print" to be called.');else u||console.error('For "react-to-print" to work only Class based components can be printed.')},n.handleRemoveIframe=function(e){var t=n.props.removeAfterPrint;if(e||t){var r=document.getElementById("printWindow");r&&document.body.removeChild(r)}},n}return t.__extends(o,e),o.prototype.render=function(){var e=this.props,t=e.children,r=e.suppressErrors,o=e.trigger;if(o)return n.cloneElement(o(),{onClick:this.handleClick});if(!c)return r||console.error('"react-to-print" requires React ^16.3.0 to be able to use "PrintContext"'),null;var i={handlePrint:this.handleClick};return n.createElement(c.Provider,{value:i},t)},o.defaultProps=u,o}(n.Component);e.default=s,e.useReactToPrint=l?function(e){var r=n.useMemo((function(){return new s(t.__assign(t.__assign({},u),e))}),[e]);return n.useCallback((function(){return r.handleClick()}),[r])}:function(e){e.suppressErrors||console.warn('"react-to-print" requires React ^16.8.0 to be able to use "useReactToPrint"')}}(),i}()}));
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
{
"name": "react-to-print",
"version": "2.12.3",
"version": "2.12.4",
"description": "Print React components in the browser",

@@ -11,6 +11,6 @@ "main": "lib/index.js",

"scripts": {
"start": "NODE_ENV=development webpack serve",
"build": "NODE_ENV=production webpack --progress",
"prepare": "npm run build",
"lint": "eslint src/**/*.{ts,tsx}"
"lint": "eslint src/**/*.{ts,tsx}",
"prepare": "npm run build && husky install",
"start": "NODE_ENV=development webpack serve"
},

@@ -44,12 +44,12 @@ "repository": {

"devDependencies": {
"@types/react": "^17.0.1",
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"acorn": "^8.0.5",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"acorn": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^5.0.1",
"eslint": "^7.19.0",
"html-webpack-plugin": "^5.0.0",
"husky": "^4.3.8",
"css-loader": "^5.2.1",
"eslint": "^7.24.0",
"html-webpack-plugin": "^5.3.1",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",

@@ -59,14 +59,10 @@ "react": "^17.0.1",

"style-loader": "^2.0.0",
"ts-loader": "^8.0.15",
"typescript": "^4.1.3",
"ts-loader": "^8.1.0",
"tslib": "^2.2.0",
"typescript": "^4.2.4",
"url-loader": "^4.1.1",
"webpack": "^5.21.0",
"webpack-cli": "^4.5.0",
"webpack": "^5.31.2",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {

@@ -73,0 +69,0 @@ "*.{ts,tsx}": [

@@ -61,6 +61,2 @@ <p align="center">

## Known Issues
- `onAfterPrint` may fire immediately (before the print dialog is closed) on newer versions of Safari where [`window.print`](https://developer.mozilla.org/en-US/docs/Web/API/Window/print) does not block
## Examples

@@ -192,2 +188,6 @@

## Known Issues
- `onAfterPrint` may fire immediately (before the print dialog is closed) on newer versions of Safari where [`window.print`](https://developer.mozilla.org/en-US/docs/Web/API/Window/print) does not block
## Common Pitfalls

@@ -201,2 +201,6 @@

### Can the `ComponentToPrint` be a functional component?
Officially no, but there are workarounds using the `useRef` hook. See [#96](https://github.com/gregnb/react-to-print/issues/96) and [#181](https://github.com/gregnb/react-to-print/issues/181) for examples. We will officially support this once we release the next major version which will drop React 15 support.
### Why does `onAfterPrint` fire even if the user cancels printing

@@ -203,0 +207,0 @@

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