Socket
Socket
Sign inDemoInstall

@react-pdf-viewer/print

Package Overview
Dependencies
91
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 3.3.1

2

lib/cjs/print.js

@@ -29,3 +29,3 @@ 'use strict';

/*! *****************************************************************************
/******************************************************************************
Copyright (c) Microsoft Corporation.

@@ -32,0 +32,0 @@

@@ -1,15 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@react-pdf-viewer/core"),n=require("react-dom");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var o,a=r(e),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},i.apply(this,arguments)},c=function(){return a.createElement(t.Icon,{size:16},a.createElement("path",{d:"M7.5,19.499h9 M7.5,16.499h9 M5.5,16.5h-3c-1.103-0.003-1.997-0.897-2-2v-6c0.003-1.103,0.897-1.997,2-2h19\n c1.103,0.003,1.997,0.897,2,2v6c-0.003,1.103-0.897,1.997-2,2h-3\n M5.5,4.5v-4h9.586c0.265,0,0.52,0.105,0.707,0.293l2.414,2.414\n C18.395,3.394,18.5,3.649,18.5,3.914V4.5\n M18.5,22.5c0,0.552-0.448,1-1,1h-11c-0.552,0-1-0.448-1-1v-9h13V22.5z\n M3.5,8.499\n c0.552,0,1,0.448,1,1s-0.448,1-1,1s-1-0.448-1-1S2.948,8.499,3.5,8.499z\n M14.5,0.499v4h4"}))},u={left:0,top:8},s=function(e){var n=e.enableShortcuts,r=e.onClick,o=a.useContext(t.LocalizationContext).l10n,i=o&&o.print?o.print.print:"Print",s=n?t.isMac()?"Meta+P":"Ctrl+P":"";return a.createElement(t.Tooltip,{ariaControlsSuffix:"print",position:t.Position.BottomCenter,target:a.createElement(t.MinimalButton,{ariaKeyShortcuts:s,ariaLabel:i,testId:"print__button",onClick:r},a.createElement(c,null)),content:function(){return i},offset:u})};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
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.
***************************************************************************** */!function(e){e.CheckingPermission="CheckingPermission",e.Inactive="Inactive",e.Preparing="Preparing",e.Cancelled="Cancelled",e.Ready="Ready"}(o||(o={}));var l=function(e){var t=e.children,n=e.enableShortcuts,r=e.store;return(t||s)({enableShortcuts:n,onClick:function(){r.update("printStatus",o.CheckingPermission)}})},p=function(e){var n=e.doc,r=e.store,i=a.useContext(t.LocalizationContext).l10n,c=a.useState(!0),u=c[0],s=c[1];return a.useEffect((function(){n.getPermissions().then((function(e){null===e||e.includes(4)||e.includes(2048)?r.update("printStatus",o.Preparing):s(!1)}))}),[]),u?a.createElement(a.Fragment,null):a.createElement(t.Modal,{ariaControlsSuffix:"print-permission",closeOnClickOutside:!1,closeOnEscape:!1,content:function(e){return a.createElement(a.Fragment,null,a.createElement("div",{className:"rpv-print__permission-body"},i&&i.print?i.print.disallowPrint:"The document does not allow to print"),a.createElement("div",{className:"rpv-print__permission-footer"},a.createElement(t.Button,{onClick:function(){e(),r.update("printStatus",o.Cancelled)}},i&&i.print?i.print.close:"Close")))},isOpened:!0})},d=function(e){var n=e.numLoadedPages,r=e.numPages,o=e.onCancel,i=a.useContext(t.LocalizationContext).l10n,c=a.useContext(t.ThemeContext).direction===t.TextDirection.RightToLeft,u=Math.floor(100*n/r);return a.createElement("div",{className:"rpv-print__progress"},a.createElement("div",{className:t.classNames({"rpv-print__progress-body":!0,"rpv-print__progress-body--rtl":c})},a.createElement("div",{className:"rpv-print__progress-message"},i&&i.print?i.print.preparingDocument:"Preparing document ..."),a.createElement("div",{className:"rpv-print__progress-bar"},a.createElement(t.ProgressBar,{progress:u})),a.createElement(t.Button,{onClick:o},i&&i.print?i.print.cancel:"Cancel")))},m=function(e){var t=e.canvas,n=e.page,r=e.pageHeight,o=e.pageWidth,i=e.rotation,c=e.onLoad,u=a.useRef(),s=a.useState(""),l=s[0],p=s[1];return a.useEffect((function(){var e=u.current;e&&e.cancel();var a=150/72;t.height=Math.floor(r*a),t.width=Math.floor(o*a);var c=t.getContext("2d");c.save(),c.fillStyle="rgb(255, 255, 255)",c.fillRect(0,0,t.width,t.height),c.restore();var s=n.getViewport({rotation:i,scale:1});u.current=n.render({canvasContext:c,intent:"print",transform:[a,0,0,a,0,0],viewport:s}),u.current.promise.then((function(){"toBlob"in t?t.toBlob((function(e){p(URL.createObjectURL(e))})):p(t.toDataURL())}),(function(){}))}),[]),l&&a.createElement("div",{className:"rpv-print__page"},a.createElement("img",{src:l,onLoad:function(){return c()}}))},g=function(e){var n=e.canvas,r=e.doc,o=e.pageHeight,i=e.pageIndex,c=e.pageRotation,u=e.pageWidth,s=e.rotation,l=e.onLoad,p=a.useState({height:o,page:null,viewportRotation:0,width:u}),d=p[0],g=p[1],f=d.page,v=d.height,h=d.width,E=Math.abs(s+c)%180==0;a.useEffect((function(){t.getPage(r,i).then((function(e){var t=e.getViewport({scale:1});g({height:t.height,page:e,viewportRotation:t.rotation,width:t.width})}))}),[]);var C=(d.viewportRotation+s+c)%360;return f&&a.createElement(m,{canvas:n,page:f,pageHeight:E?v:h,pageWidth:E?h:v,rotation:C,onLoad:l})},f=function(e){var t=e.doc,r=e.numLoadedPages,i=e.pagesRotation,c=e.pageHeight,u=e.pageWidth,s=e.printStatus,l=e.rotation,p=e.onCancel,d=e.onLoad,m=a.useMemo((function(){return document.createElement("canvas")}),[]),f=a.useMemo((function(){var e=document.querySelector(".rpv-print__zone");if(e)return e;var t=document.createElement("div");return t.classList.add("rpv-print__zone"),document.body.appendChild(t),t}),[]);return a.useEffect((function(){s===o.Ready&&(document.documentElement.classList.add("rpv-print__html-printing"),document.body.classList.add("rpv-print__body-printing"),window.print());var e=function(){if(s===o.Ready){document.documentElement.classList.remove("rpv-print__html-printing"),document.body.classList.remove("rpv-print__body-printing");var t=document.querySelectorAll(".rpv-print__zone");t&&t.forEach((function(e){e.parentElement.removeChild(e)})),m.height=0,m.width=0,document.removeEventListener("mousemove",e),p()}};return document.addEventListener("mousemove",e),function(){return document.removeEventListener("mousemove",e)}}),[s]),n.createPortal(a.createElement(a.Fragment,null,Array(Math.min(r+1,t.numPages)).fill(0).map((function(e,n){return a.createElement(g,{key:n,canvas:m,doc:t,pageHeight:c,pageIndex:n,pageRotation:i.has(n)?i.get(n):0,pageWidth:u,rotation:l,onLoad:d})})),a.createElement("style",{dangerouslySetInnerHTML:{__html:"@page { size: ".concat(u,"pt ").concat(c,"pt }")}})),f)},v=function(e){var t=e.doc,n=e.pagesRotation,r=e.pageHeight,i=e.pageWidth,c=e.rotation,u=e.store,s=a.useState(o.Inactive),l=s[0],m=s[1],g=a.useState(0),v=g[0],h=g[1],E=function(){h(0),m(o.Inactive)},C=function(e){return m(e)};return a.useEffect((function(){return u.subscribe("printStatus",C),function(){u.unsubscribe("printStatus",C)}}),[]),a.createElement(a.Fragment,null,l===o.CheckingPermission&&a.createElement(p,{doc:t,store:u}),l===o.Preparing&&a.createElement(d,{numLoadedPages:v,numPages:t.numPages,onCancel:E}),(l===o.Preparing||l===o.Ready)&&v<=t.numPages&&a.createElement(f,{doc:t,numLoadedPages:v,pagesRotation:n,pageHeight:r,pageWidth:i,printStatus:l,rotation:c,onCancel:E,onLoad:function(){var e=v+1;e<=t.numPages&&(h(e),e===t.numPages&&m(o.Ready))}}))},h=function(e){var n=e.onClick,r=a.useContext(t.LocalizationContext).l10n,o=r&&r.print?r.print.print:"Print";return a.createElement(t.MenuItem,{icon:a.createElement(c,null),testId:"print__menu",onClick:n},o)},E=function(e){var n=e.containerRef,r=e.store,i=function(e){if(!e.shiftKey&&!e.altKey&&"p"===e.key&&(t.isMac()?e.metaKey:e.ctrlKey)){var a=n.current;a&&document.activeElement&&a.contains(document.activeElement)&&(e.preventDefault(),r.update("printStatus",o.Preparing))}};return a.useEffect((function(){if(n.current)return document.addEventListener("keydown",i),function(){document.removeEventListener("keydown",i)}}),[n.current]),a.createElement(a.Fragment,null)};exports.PrintIcon=c,exports.printPlugin=function(e){var n=a.useMemo((function(){return Object.assign({},{enableShortcuts:!0},e)}),[]),r=a.useMemo((function(){return t.createStore({printStatus:o.Inactive})}),[]),c=function(e){return a.createElement(l,i({enableShortcuts:n.enableShortcuts},e,{store:r}))};return{renderViewer:function(e){var t=e.slot,o={children:a.createElement(a.Fragment,null,n.enableShortcuts&&a.createElement(E,{containerRef:e.containerRef,store:r}),a.createElement(v,{doc:e.doc,pagesRotation:e.pagesRotation,pageHeight:e.pageHeight,pageWidth:e.pageWidth,rotation:e.rotation,store:r}),t.children)};return i(i({},t),o)},Print:c,PrintButton:function(){return a.createElement(c,null,(function(e){return a.createElement(s,i({},e))}))},PrintMenuItem:function(e){return a.createElement(c,null,(function(t){return a.createElement(h,{onClick:function(){t.onClick(),e.onClick()}})}))}}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@react-pdf-viewer/core"),n=require("react-dom");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var o,a=r(e),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},i.apply(this,arguments)},c=function(){return a.createElement(t.Icon,{size:16},a.createElement("path",{d:"M7.5,19.499h9 M7.5,16.499h9 M5.5,16.5h-3c-1.103-0.003-1.997-0.897-2-2v-6c0.003-1.103,0.897-1.997,2-2h19\n c1.103,0.003,1.997,0.897,2,2v6c-0.003,1.103-0.897,1.997-2,2h-3\n M5.5,4.5v-4h9.586c0.265,0,0.52,0.105,0.707,0.293l2.414,2.414\n C18.395,3.394,18.5,3.649,18.5,3.914V4.5\n M18.5,22.5c0,0.552-0.448,1-1,1h-11c-0.552,0-1-0.448-1-1v-9h13V22.5z\n M3.5,8.499\n c0.552,0,1,0.448,1,1s-0.448,1-1,1s-1-0.448-1-1S2.948,8.499,3.5,8.499z\n M14.5,0.499v4h4"}))},u={left:0,top:8},s=function(e){var n=e.enableShortcuts,r=e.onClick,o=a.useContext(t.LocalizationContext).l10n,i=o&&o.print?o.print.print:"Print",s=n?t.isMac()?"Meta+P":"Ctrl+P":"";return a.createElement(t.Tooltip,{ariaControlsSuffix:"print",position:t.Position.BottomCenter,target:a.createElement(t.MinimalButton,{ariaKeyShortcuts:s,ariaLabel:i,testId:"print__button",onClick:r},a.createElement(c,null)),content:function(){return i},offset:u})};!function(e){e.CheckingPermission="CheckingPermission",e.Inactive="Inactive",e.Preparing="Preparing",e.Cancelled="Cancelled",e.Ready="Ready"}(o||(o={}));var l=function(e){var t=e.children,n=e.enableShortcuts,r=e.store;return(t||s)({enableShortcuts:n,onClick:function(){r.update("printStatus",o.CheckingPermission)}})},p=function(e){var n=e.doc,r=e.store,i=a.useContext(t.LocalizationContext).l10n,c=a.useState(!0),u=c[0],s=c[1];return a.useEffect((function(){n.getPermissions().then((function(e){null===e||e.includes(4)||e.includes(2048)?r.update("printStatus",o.Preparing):s(!1)}))}),[]),u?a.createElement(a.Fragment,null):a.createElement(t.Modal,{ariaControlsSuffix:"print-permission",closeOnClickOutside:!1,closeOnEscape:!1,content:function(e){return a.createElement(a.Fragment,null,a.createElement("div",{className:"rpv-print__permission-body"},i&&i.print?i.print.disallowPrint:"The document does not allow to print"),a.createElement("div",{className:"rpv-print__permission-footer"},a.createElement(t.Button,{onClick:function(){e(),r.update("printStatus",o.Cancelled)}},i&&i.print?i.print.close:"Close")))},isOpened:!0})},d=function(e){var n=e.numLoadedPages,r=e.numPages,o=e.onCancel,i=a.useContext(t.LocalizationContext).l10n,c=a.useContext(t.ThemeContext).direction===t.TextDirection.RightToLeft,u=Math.floor(100*n/r);return a.createElement("div",{className:"rpv-print__progress"},a.createElement("div",{className:t.classNames({"rpv-print__progress-body":!0,"rpv-print__progress-body--rtl":c})},a.createElement("div",{className:"rpv-print__progress-message"},i&&i.print?i.print.preparingDocument:"Preparing document ..."),a.createElement("div",{className:"rpv-print__progress-bar"},a.createElement(t.ProgressBar,{progress:u})),a.createElement(t.Button,{onClick:o},i&&i.print?i.print.cancel:"Cancel")))},m=function(e){var t=e.canvas,n=e.page,r=e.pageHeight,o=e.pageWidth,i=e.rotation,c=e.onLoad,u=a.useRef(),s=a.useState(""),l=s[0],p=s[1];return a.useEffect((function(){var e=u.current;e&&e.cancel();var a=150/72;t.height=Math.floor(r*a),t.width=Math.floor(o*a);var c=t.getContext("2d");c.save(),c.fillStyle="rgb(255, 255, 255)",c.fillRect(0,0,t.width,t.height),c.restore();var s=n.getViewport({rotation:i,scale:1});u.current=n.render({canvasContext:c,intent:"print",transform:[a,0,0,a,0,0],viewport:s}),u.current.promise.then((function(){"toBlob"in t?t.toBlob((function(e){p(URL.createObjectURL(e))})):p(t.toDataURL())}),(function(){}))}),[]),l&&a.createElement("div",{className:"rpv-print__page"},a.createElement("img",{src:l,onLoad:function(){return c()}}))},g=function(e){var n=e.canvas,r=e.doc,o=e.pageHeight,i=e.pageIndex,c=e.pageRotation,u=e.pageWidth,s=e.rotation,l=e.onLoad,p=a.useState({height:o,page:null,viewportRotation:0,width:u}),d=p[0],g=p[1],f=d.page,v=d.height,h=d.width,E=Math.abs(s+c)%180==0;a.useEffect((function(){t.getPage(r,i).then((function(e){var t=e.getViewport({scale:1});g({height:t.height,page:e,viewportRotation:t.rotation,width:t.width})}))}),[]);var C=(d.viewportRotation+s+c)%360;return f&&a.createElement(m,{canvas:n,page:f,pageHeight:E?v:h,pageWidth:E?h:v,rotation:C,onLoad:l})},f=function(e){var t=e.doc,r=e.numLoadedPages,i=e.pagesRotation,c=e.pageHeight,u=e.pageWidth,s=e.printStatus,l=e.rotation,p=e.onCancel,d=e.onLoad,m=a.useMemo((function(){return document.createElement("canvas")}),[]),f=a.useMemo((function(){var e=document.querySelector(".rpv-print__zone");if(e)return e;var t=document.createElement("div");return t.classList.add("rpv-print__zone"),document.body.appendChild(t),t}),[]);return a.useEffect((function(){s===o.Ready&&(document.documentElement.classList.add("rpv-print__html-printing"),document.body.classList.add("rpv-print__body-printing"),window.print());var e=function(){if(s===o.Ready){document.documentElement.classList.remove("rpv-print__html-printing"),document.body.classList.remove("rpv-print__body-printing");var t=document.querySelectorAll(".rpv-print__zone");t&&t.forEach((function(e){e.parentElement.removeChild(e)})),m.height=0,m.width=0,document.removeEventListener("mousemove",e),p()}};return document.addEventListener("mousemove",e),function(){return document.removeEventListener("mousemove",e)}}),[s]),n.createPortal(a.createElement(a.Fragment,null,Array(Math.min(r+1,t.numPages)).fill(0).map((function(e,n){return a.createElement(g,{key:n,canvas:m,doc:t,pageHeight:c,pageIndex:n,pageRotation:i.has(n)?i.get(n):0,pageWidth:u,rotation:l,onLoad:d})})),a.createElement("style",{dangerouslySetInnerHTML:{__html:"@page { size: ".concat(u,"pt ").concat(c,"pt }")}})),f)},v=function(e){var t=e.doc,n=e.pagesRotation,r=e.pageHeight,i=e.pageWidth,c=e.rotation,u=e.store,s=a.useState(o.Inactive),l=s[0],m=s[1],g=a.useState(0),v=g[0],h=g[1],E=function(){h(0),m(o.Inactive)},C=function(e){return m(e)};return a.useEffect((function(){return u.subscribe("printStatus",C),function(){u.unsubscribe("printStatus",C)}}),[]),a.createElement(a.Fragment,null,l===o.CheckingPermission&&a.createElement(p,{doc:t,store:u}),l===o.Preparing&&a.createElement(d,{numLoadedPages:v,numPages:t.numPages,onCancel:E}),(l===o.Preparing||l===o.Ready)&&v<=t.numPages&&a.createElement(f,{doc:t,numLoadedPages:v,pagesRotation:n,pageHeight:r,pageWidth:i,printStatus:l,rotation:c,onCancel:E,onLoad:function(){var e=v+1;e<=t.numPages&&(h(e),e===t.numPages&&m(o.Ready))}}))},h=function(e){var n=e.onClick,r=a.useContext(t.LocalizationContext).l10n,o=r&&r.print?r.print.print:"Print";return a.createElement(t.MenuItem,{icon:a.createElement(c,null),testId:"print__menu",onClick:n},o)},E=function(e){var n=e.containerRef,r=e.store,i=function(e){if(!e.shiftKey&&!e.altKey&&"p"===e.key&&(t.isMac()?e.metaKey:e.ctrlKey)){var a=n.current;a&&document.activeElement&&a.contains(document.activeElement)&&(e.preventDefault(),r.update("printStatus",o.Preparing))}};return a.useEffect((function(){if(n.current)return document.addEventListener("keydown",i),function(){document.removeEventListener("keydown",i)}}),[n.current]),a.createElement(a.Fragment,null)};exports.PrintIcon=c,exports.printPlugin=function(e){var n=a.useMemo((function(){return Object.assign({},{enableShortcuts:!0},e)}),[]),r=a.useMemo((function(){return t.createStore({printStatus:o.Inactive})}),[]),c=function(e){return a.createElement(l,i({enableShortcuts:n.enableShortcuts},e,{store:r}))};return{renderViewer:function(e){var t=e.slot,o={children:a.createElement(a.Fragment,null,n.enableShortcuts&&a.createElement(E,{containerRef:e.containerRef,store:r}),a.createElement(v,{doc:e.doc,pagesRotation:e.pagesRotation,pageHeight:e.pageHeight,pageWidth:e.pageWidth,rotation:e.rotation,store:r}),t.children)};return i(i({},t),o)},Print:c,PrintButton:function(){return a.createElement(c,null,(function(e){return a.createElement(s,i({},e))}))},PrintMenuItem:function(e){return a.createElement(c,null,(function(t){return a.createElement(h,{onClick:function(){t.onClick(),e.onClick()}})}))}}};
{
"name": "@react-pdf-viewer/print",
"version": "3.3.0",
"version": "3.3.1",
"description": "A React component to view a PDF document",

@@ -36,3 +36,3 @@ "license": "https://react-pdf-viewer.dev/license",

"dependencies": {
"@react-pdf-viewer/core": "3.3.0"
"@react-pdf-viewer/core": "3.3.1"
},

@@ -52,3 +52,3 @@ "peerDependencies": {

},
"gitHead": "fc1c00e3802d538f2f96b6a241e995493a601f61"
"gitHead": "3cffac5b07d0745738913f28797527363c0b0594"
}
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc