@react-pdf-viewer/zoom
Advanced tools
Comparing version 2.4.3 to 2.5.0
@@ -130,3 +130,3 @@ 'use strict'; | ||
var isMac = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform); | ||
var isMac = function () { return (typeof window !== "undefined") ? /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) : false; }; | ||
var ShortcutHandler = function (_a) { | ||
@@ -138,3 +138,3 @@ var containerRef = _a.containerRef, store = _a.store; | ||
} | ||
var isCommandPressed = isMac ? e.metaKey : e.ctrlKey; | ||
var isCommandPressed = isMac() ? e.metaKey : e.ctrlKey; | ||
if (!isCommandPressed) { | ||
@@ -291,2 +291,16 @@ return; | ||
var ZoomInMenuItem = function (_a) { | ||
var onClick = _a.onClick; | ||
var l10n = React__namespace.useContext(core.LocalizationContext); | ||
var label = l10n && l10n.zoom ? l10n.zoom.zoomIn : 'Zoom in'; | ||
return (React__namespace.createElement(core.MenuItem, { icon: React__namespace.createElement(ZoomInIcon, null), onClick: onClick }, label)); | ||
}; | ||
var ZoomOutMenuItem = function (_a) { | ||
var onClick = _a.onClick; | ||
var l10n = React__namespace.useContext(core.LocalizationContext); | ||
var label = l10n && l10n.zoom ? l10n.zoom.zoomOut : 'Zoom out'; | ||
return (React__namespace.createElement(core.MenuItem, { icon: React__namespace.createElement(ZoomOutIcon, null), onClick: onClick }, label)); | ||
}; | ||
var zoomPlugin = function () { | ||
@@ -297,4 +311,6 @@ var store = React__namespace.useMemo(function () { return core.createStore({}); }, []); | ||
var ZoomInButtonDecorator = function () { return (React__namespace.createElement(ZoomInDecorator, null, function (props) { return React__namespace.createElement(ZoomInButton, __assign({}, props)); })); }; | ||
var ZoomInMenuItemDecorator = function (props) { return (React__namespace.createElement(ZoomInDecorator, null, function (p) { return React__namespace.createElement(ZoomInMenuItem, { onClick: function () { p.onClick(); props.onClick(); } }); })); }; | ||
var ZoomOutDecorator = function (props) { return (React__namespace.createElement(ZoomOut, __assign({}, props, { store: store }))); }; | ||
var ZoomOutButtonDecorator = function () { return (React__namespace.createElement(ZoomOutDecorator, null, function (props) { return React__namespace.createElement(ZoomOutButton, __assign({}, props)); })); }; | ||
var ZoomOutMenuItemDecorator = function (props) { return (React__namespace.createElement(ZoomOutDecorator, null, function (p) { return React__namespace.createElement(ZoomOutMenuItem, { onClick: function () { p.onClick(); props.onClick(); } }); })); }; | ||
var ZoomDecorator = function (props) { return React__namespace.createElement(Zoom, __assign({}, props, { store: store })); }; | ||
@@ -329,4 +345,6 @@ var ZoomPopoverDecorator = function () { return (React__namespace.createElement(ZoomDecorator, null, function (props) { return React__namespace.createElement(ZoomPopover, __assign({}, props)); })); }; | ||
ZoomInButton: ZoomInButtonDecorator, | ||
ZoomInMenuItem: ZoomInMenuItemDecorator, | ||
ZoomOut: ZoomOutDecorator, | ||
ZoomOutButton: ZoomOutButtonDecorator, | ||
ZoomOutMenuItem: ZoomOutMenuItemDecorator, | ||
Zoom: ZoomDecorator, | ||
@@ -333,0 +351,0 @@ ZoomPopover: ZoomPopoverDecorator, |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@react-pdf-viewer/core");function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var o=n(e),r=function(){return o.createElement(t.Icon,{size:16},o.createElement("path",{d:"M10.5,0.499c5.523,0,10,4.477,10,10s-4.477,10-10,10s-10-4.477-10-10S4.977,0.499,10.5,0.499z\n M23.5,23.499\n l-5.929-5.929\n M5.5,10.499h10\n M10.5,5.499v10"}))},c=function(){return o.createElement(t.Icon,{size:16},o.createElement("path",{d:"M10.5,0.499c5.523,0,10,4.477,10,10s-4.477,10-10,10s-10-4.477-10-10S4.977,0.499,10.5,0.499z\n M23.5,23.499\n l-5.929-5.929\n M5.5,10.499h10"}))},a=function(){return(a=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},u=function(e){var t=o.useState(e.get("scale")||0),n=t[0],r=t[1],c=function(e){r(e)};return o.useEffect((function(){return e.subscribe("scale",c),function(){e.unsubscribe("scale",c)}}),[]),{scale:n}},i=function(e){var t=e.children,n=e.store;return(t||function(e){return o.createElement(o.Fragment,null,Math.round(100*e.scale)+"%")})({scale:u(n).scale})},l=[.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.3,1.5,1.7,1.9,2.1,2.4,2.7,3,3.3,3.7,4.1,4.6,5.1,5.7,6.3,7,7.7,8.5,9.4,10],m=function(e){return l.find((function(t){return t>e}))||e},s=function(e){var t=l.findIndex((function(t){return t>=e}));return-1===t||0===t?e:l[t-1]},f=/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),p=function(e){var t=e.containerRef,n=e.store,r=function(e){if(!e.shiftKey&&!e.altKey&&(f?e.metaKey:e.ctrlKey)){var o=t.current;if(o&&document.activeElement&&document.activeElement.contains(o)){var r=n.get("zoom");if(r){var c=n.get("scale")||1,a=1;switch(e.key){case"-":a=s(c);break;case"=":a=m(c);break;case"0":a=1;break;default:a=c}a!==c&&(e.preventDefault(),r(a))}}}};return o.useEffect((function(){if(t.current)return document.addEventListener("keydown",r),function(){document.removeEventListener("keydown",r)}}),[t.current]),o.createElement(o.Fragment,null)},v=[.5,.75,1,1.25,1.5,2,3,4],E={left:0,top:8},d=function(e){var n=e.scale,r=e.onZoom,c=o.useContext(t.LocalizationContext);return o.createElement(t.Popover,{position:t.Position.BottomCenter,target:function(e){return o.createElement("span",{className:"rpv-zoom-popover-target",onClick:function(){e()}},o.createElement("span",{className:"rpv-zoom-popover-target-scale"},Math.round(100*n),"%"),o.createElement("span",{className:"rpv-zoom-popover-target-arrow"}))},content:function(e){return o.createElement(t.Menu,null,Object.keys(t.SpecialZoomLevel).map((function(n){var a=n;return o.createElement(t.MenuItem,{key:a,onClick:function(){e(),r(a)}},function(e){switch(e){case t.SpecialZoomLevel.ActualSize:return c&&c.zoom?c.zoom.actualSize:"Actual size";case t.SpecialZoomLevel.PageFit:return c&&c.zoom?c.zoom.pageFit:"Page fit";case t.SpecialZoomLevel.PageWidth:return c&&c.zoom?c.zoom.pageWidth:"Page width"}}(a))})),o.createElement(t.MenuDivider,null),v.map((function(n){return o.createElement(t.MenuItem,{key:n,onClick:function(){e(),r(n)}},Math.round(100*n)+"%")})))},offset:E,closeOnClickOutside:!0,closeOnEscape:!0})},z=function(e){var t=e.children,n=e.store;return(t||function(e){return o.createElement(d,{scale:e.scale,onZoom:e.onZoom})})({scale:u(n).scale,onZoom:function(e){var t=n.get("zoom");t&&t(e)}})},g={left:0,top:8},h=function(e){var n=e.onClick,c=o.useContext(t.LocalizationContext),a=c&&c.zoom?c.zoom.zoomIn:"Zoom in";return o.createElement(t.Tooltip,{position:t.Position.BottomCenter,target:o.createElement(t.Button,{onClick:n},o.createElement(r,null)),content:function(){return a},offset:g})},C=function(e){var t=e.children,n=e.store,r=u(n).scale;return(t||function(e){return o.createElement(h,{onClick:e.onClick})})({onClick:function(){var e=n.get("zoom");e&&e(m(r))}})},k={left:0,top:8},M=function(e){var n=e.onClick,r=o.useContext(t.LocalizationContext),a=r&&r.zoom?r.zoom.zoomOut:"Zoom out";return o.createElement(t.Tooltip,{position:t.Position.BottomCenter,target:o.createElement(t.Button,{onClick:n},o.createElement(c,null)),content:function(){return a},offset:k})},O=function(e){var t=e.children,n=e.store,r=u(n).scale;return(t||function(e){return o.createElement(M,{onClick:e.onClick})})({onClick:function(){var e=n.get("zoom");e&&e(s(r))}})};exports.ZoomInIcon=r,exports.ZoomOutIcon=c,exports.zoomPlugin=function(){var e=o.useMemo((function(){return t.createStore({})}),[]),n=function(t){return o.createElement(C,a({},t,{store:e}))},r=function(t){return o.createElement(O,a({},t,{store:e}))},c=function(t){return o.createElement(z,a({},t,{store:e}))};return{renderViewer:function(t){var n=t.slot,r={children:o.createElement(o.Fragment,null,o.createElement(p,{containerRef:t.containerRef,store:e}),n.children)};return a(a({},n),r)},install:function(t){e.update("zoom",t.zoom)},onViewerStateChange:function(t){return e.update("scale",t.scale),t},zoomTo:function(t){var n=e.get("zoom");n&&n(t)},CurrentScale:function(t){return o.createElement(i,a({},t,{store:e}))},ZoomIn:n,ZoomInButton:function(){return o.createElement(n,null,(function(e){return o.createElement(h,a({},e))}))},ZoomOut:r,ZoomOutButton:function(){return o.createElement(r,null,(function(e){return o.createElement(M,a({},e))}))},Zoom:c,ZoomPopover:function(){return o.createElement(c,null,(function(e){return o.createElement(d,a({},e))}))}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@react-pdf-viewer/core");function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var o=n(e),r=function(){return o.createElement(t.Icon,{size:16},o.createElement("path",{d:"M10.5,0.499c5.523,0,10,4.477,10,10s-4.477,10-10,10s-10-4.477-10-10S4.977,0.499,10.5,0.499z\n M23.5,23.499\n l-5.929-5.929\n M5.5,10.499h10\n M10.5,5.499v10"}))},c=function(){return o.createElement(t.Icon,{size:16},o.createElement("path",{d:"M10.5,0.499c5.523,0,10,4.477,10,10s-4.477,10-10,10s-10-4.477-10-10S4.977,0.499,10.5,0.499z\n M23.5,23.499\n l-5.929-5.929\n M5.5,10.499h10"}))},u=function(){return(u=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},a=function(e){var t=o.useState(e.get("scale")||0),n=t[0],r=t[1],c=function(e){r(e)};return o.useEffect((function(){return e.subscribe("scale",c),function(){e.unsubscribe("scale",c)}}),[]),{scale:n}},i=function(e){var t=e.children,n=e.store;return(t||function(e){return o.createElement(o.Fragment,null,Math.round(100*e.scale)+"%")})({scale:a(n).scale})},l=[.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.3,1.5,1.7,1.9,2.1,2.4,2.7,3,3.3,3.7,4.1,4.6,5.1,5.7,6.3,7,7.7,8.5,9.4,10],m=function(e){return l.find((function(t){return t>e}))||e},f=function(e){var t=l.findIndex((function(t){return t>=e}));return-1===t||0===t?e:l[t-1]},s=function(e){var t=e.containerRef,n=e.store,r=function(e){if(!e.shiftKey&&!e.altKey&&("undefined"!=typeof window&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)?e.metaKey:e.ctrlKey)){var o=t.current;if(o&&document.activeElement&&document.activeElement.contains(o)){var r=n.get("zoom");if(r){var c=n.get("scale")||1,u=1;switch(e.key){case"-":u=f(c);break;case"=":u=m(c);break;case"0":u=1;break;default:u=c}u!==c&&(e.preventDefault(),r(u))}}}};return o.useEffect((function(){if(t.current)return document.addEventListener("keydown",r),function(){document.removeEventListener("keydown",r)}}),[t.current]),o.createElement(o.Fragment,null)},p=[.5,.75,1,1.25,1.5,2,3,4],v={left:0,top:8},E=function(e){var n=e.scale,r=e.onZoom,c=o.useContext(t.LocalizationContext);return o.createElement(t.Popover,{position:t.Position.BottomCenter,target:function(e){return o.createElement("span",{className:"rpv-zoom-popover-target",onClick:function(){e()}},o.createElement("span",{className:"rpv-zoom-popover-target-scale"},Math.round(100*n),"%"),o.createElement("span",{className:"rpv-zoom-popover-target-arrow"}))},content:function(e){return o.createElement(t.Menu,null,Object.keys(t.SpecialZoomLevel).map((function(n){var u=n;return o.createElement(t.MenuItem,{key:u,onClick:function(){e(),r(u)}},function(e){switch(e){case t.SpecialZoomLevel.ActualSize:return c&&c.zoom?c.zoom.actualSize:"Actual size";case t.SpecialZoomLevel.PageFit:return c&&c.zoom?c.zoom.pageFit:"Page fit";case t.SpecialZoomLevel.PageWidth:return c&&c.zoom?c.zoom.pageWidth:"Page width"}}(u))})),o.createElement(t.MenuDivider,null),p.map((function(n){return o.createElement(t.MenuItem,{key:n,onClick:function(){e(),r(n)}},Math.round(100*n)+"%")})))},offset:v,closeOnClickOutside:!0,closeOnEscape:!0})},d=function(e){var t=e.children,n=e.store;return(t||function(e){return o.createElement(E,{scale:e.scale,onZoom:e.onZoom})})({scale:a(n).scale,onZoom:function(e){var t=n.get("zoom");t&&t(e)}})},z={left:0,top:8},C=function(e){var n=e.onClick,c=o.useContext(t.LocalizationContext),u=c&&c.zoom?c.zoom.zoomIn:"Zoom in";return o.createElement(t.Tooltip,{position:t.Position.BottomCenter,target:o.createElement(t.Button,{onClick:n},o.createElement(r,null)),content:function(){return u},offset:z})},k=function(e){var t=e.children,n=e.store,r=a(n).scale;return(t||function(e){return o.createElement(C,{onClick:e.onClick})})({onClick:function(){var e=n.get("zoom");e&&e(m(r))}})},g={left:0,top:8},h=function(e){var n=e.onClick,r=o.useContext(t.LocalizationContext),u=r&&r.zoom?r.zoom.zoomOut:"Zoom out";return o.createElement(t.Tooltip,{position:t.Position.BottomCenter,target:o.createElement(t.Button,{onClick:n},o.createElement(c,null)),content:function(){return u},offset:g})},M=function(e){var t=e.children,n=e.store,r=a(n).scale;return(t||function(e){return o.createElement(h,{onClick:e.onClick})})({onClick:function(){var e=n.get("zoom");e&&e(f(r))}})},Z=function(e){var n=e.onClick,c=o.useContext(t.LocalizationContext),u=c&&c.zoom?c.zoom.zoomIn:"Zoom in";return o.createElement(t.MenuItem,{icon:o.createElement(r,null),onClick:n},u)},O=function(e){var n=e.onClick,r=o.useContext(t.LocalizationContext),u=r&&r.zoom?r.zoom.zoomOut:"Zoom out";return o.createElement(t.MenuItem,{icon:o.createElement(c,null),onClick:n},u)};exports.ZoomInIcon=r,exports.ZoomOutIcon=c,exports.zoomPlugin=function(){var e=o.useMemo((function(){return t.createStore({})}),[]),n=function(t){return o.createElement(k,u({},t,{store:e}))},r=function(t){return o.createElement(M,u({},t,{store:e}))},c=function(t){return o.createElement(d,u({},t,{store:e}))};return{renderViewer:function(t){var n=t.slot,r={children:o.createElement(o.Fragment,null,o.createElement(s,{containerRef:t.containerRef,store:e}),n.children)};return u(u({},n),r)},install:function(t){e.update("zoom",t.zoom)},onViewerStateChange:function(t){return e.update("scale",t.scale),t},zoomTo:function(t){var n=e.get("zoom");n&&n(t)},CurrentScale:function(t){return o.createElement(i,u({},t,{store:e}))},ZoomIn:n,ZoomInButton:function(){return o.createElement(n,null,(function(e){return o.createElement(C,u({},e))}))},ZoomInMenuItem:function(e){return o.createElement(n,null,(function(t){return o.createElement(Z,{onClick:function(){t.onClick(),e.onClick()}})}))},ZoomOut:r,ZoomOutButton:function(){return o.createElement(r,null,(function(e){return o.createElement(h,u({},e))}))},ZoomOutMenuItem:function(e){return o.createElement(r,null,(function(t){return o.createElement(O,{onClick:function(){t.onClick(),e.onClick()}})}))},Zoom:c,ZoomPopover:function(){return o.createElement(c,null,(function(e){return o.createElement(E,u({},e))}))}}}; |
@@ -12,2 +12,6 @@ /** | ||
export interface ZoomMenuItemProps { | ||
onClick: () => void; | ||
} | ||
// ------------------------ | ||
@@ -71,4 +75,6 @@ // Render zooming in button | ||
ZoomInButton: () => React.ReactElement; | ||
ZoomInMenuItem: (props: ZoomMenuItemProps) => React.ReactElement; | ||
ZoomOut: (props: ZoomOutProps) => React.ReactElement; | ||
ZoomOutButton: () => React.ReactElement; | ||
ZoomOutMenuItem: (props: ZoomMenuItemProps) => React.ReactElement; | ||
Zoom: (props: ZoomProps) => React.ReactElement; | ||
@@ -75,0 +81,0 @@ ZoomPopover: () => React.ReactElement; |
{ | ||
"name": "@react-pdf-viewer/zoom", | ||
"version": "2.4.3", | ||
"version": "2.5.0", | ||
"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": "2.4.3" | ||
"@react-pdf-viewer/core": "2.5.0" | ||
}, | ||
@@ -53,3 +53,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "d1b21552dea889febca7a3551924a0d3cc7679d0" | ||
"gitHead": "3c7ba1ea082607670f4e2bf69d5312a14baf7057" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25647
433
+ Added@react-pdf-viewer/core@2.5.0(transitive)
- Removed@react-pdf-viewer/core@2.4.3(transitive)
Updated@react-pdf-viewer/core@2.5.0