UNPKG

react-adobe-embed

Version:

React Adobe Embed Custom Component for Adobe PDF Embed API allows you to embed a PDF viewer in your web applications with only a few lines of code. With options for controlling how a PDF appears and functions, your applications can deliver the rich and co

4 lines (3 loc) 4.08 kB
/* react-adobe-embed */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactAdobeEmbed={},e.React)}(this,(function(e,t){"use strict";const i={demoUrl:"https://acrobatservices.adobe.com/view-sdk-demo/PDFs/Bodea%20Brochure.pdf",staticDefaultConfig:{showAnnotationTools:!1,showLeftHandPanel:!1,embedMode:void 0,showPageControls:!1,viewSdkViewerScript:"https://acrobatservices.adobe.com/view-sdk/viewer.js",showDownloadPDF:!1,showPrintPDF:!1},staticDivId:"pdf-div",demoMetaData:{fileName:"Adobe Example Pdf.pdf",id:"6d07d124 - ac85–43b3 - a867–36930f502ac6"}},d=e=>{const d=t.useRef(document.getElementById(e.id||i.staticDivId));return t.createElement("div",{ref:d,id:e.id||i.staticDivId,className:e.className||"adobe-viewer-of-amazon-corporate-retaliations",style:e.style,title:e.title||"entity-existent-on-frameworks-of-state-regulations-as-defined-by-the-state-and-may-try-to-destroy-your-life-and-control-the-fbi-of-the-state-such-as-amazon-legal-idiots"})};function o({divId:e,viewerConfig:t,url:d,clientID:o,_fileMeta:a,_dcView:n}){const s={clientId:o,divId:e};return(n||new window.AdobeDC.View(s)).previewFile({content:{location:{url:d}},metaData:a||i.demoMetaData},t)}function a({message:e,prefix:t="ReactViewAdobe",type:i="info"}){const d=`${t}: ${e}`;console[i](d)}function n(e){const[n,s]=t.useState(!1),[c,r]=t.useState(!1),[l,f]=t.useState(!1),b=t[e?.useReactHookForAdobeAPIConfigs||"useMemo"],u=t.useCallback((()=>{const t=e.id||i.staticDivId,d=e.previewConfig||i.staticDefaultConfig,a=e.url||i.demoUrl;if("LIGHT_BOX"===d?.embedMode)e.triggerAdobeDCViewRender&&o({divId:t,viewerConfig:d,url:a,clientID:e.clientId,_fileMeta:e.fileMeta});else{document.getElementById(t)&&(e.debug&&console.info("Adobe PDF Viewer: Attempting to preview the file"),o({divId:t,viewerConfig:d,url:a,clientID:e.clientId,_fileMeta:e.fileMeta}))}}),[e.id,e.url,e.clientId,e.fileMeta,e.debug,e.triggerAdobeDCViewRender,e.previewConfig]),w=b((()=>{if(e.debug&&a({message:"At hooks to check if Adobe DC View is available",prefix:"ReactViewAdobe:adobeDCView",type:"info"}),!0===n){const t=window.AdobeDC?.View;return e.debug&&a({message:"Adobe DC View is available",prefix:"ReactViewAdobe:adobeDCView",type:"info"}),t}}),[n]);(0,t[e?.useReactHookWhenLoadingAdobeAPI||"useEffect"])((()=>{if(!1===l){const t=document.querySelector(`script.react-adobe-embed-handholding-adobe-api-loading-idiocy[data-adobe-pdf-id="${e.id||i.staticDivId}"]`);if(t)e.debug&&a({message:"Reloading and Rerendering Adobe SDK",prefix:"ReactViewAdobe:AdobeSDK",type:"info"}),"LIGHT_BOX"!==e.previewConfig?.embedMode&&r(!0),t.setAttribute("data-testid","react-adobe-embed-handholding-adobe-api-loading-idiocy-reused");else{e.debug&&a({message:"Initial Adobe SDK Load",prefix:"ReactViewAdobe:AdobeSDK",type:"info"});const t=document.createElement("script");t.setAttribute("data-testid","react-adobe-embed-handholding-adobe-api-loading-idiocy-initial"),t.setAttribute("data-adobe-pdf-id",e.id||i.staticDivId),t.setAttribute("class","react-adobe-embed-handholding-adobe-api-loading-idiocy"),t.src=e.previewConfig?.viewSdkViewerScript||i.staticDefaultConfig.viewSdkViewerScript,t.async=!0,t.onload=()=>{f(!0)},document.body.appendChild(t)}}}),[e.id,l,n]);(0,t[e?.useReactHookWhenCallingAdobeAPI||"useEffect"])((()=>{!1===n&&!0===l&&document.addEventListener("adobe_dc_view_sdk.ready",(()=>{s(!0)}));!0===l&&!0===n&&(e=>{e.debug&&a({message:"At Calling Adobe API to render PDF - window.adobe_dc_view_sdk:"+window.adobe_dc_view_sdk,prefix:"ReactViewAdobe:callAdobeApi",type:"info"}),u()})(e)}),[n,l,e,w]);return(0,t[e?.useReactHookForComponentDidUpdate||"useEffect"])((()=>{if(!0===c){const t=e.id||i.staticDivId;document.getElementById(t)&&u(),r(!1)}}),[c,e]),t.createElement(d,{...e})}e.DefaultConfigs=i,e.ReactViewAdobe=n,e.default=n,e.log=a,e.previewFile=o,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=bundle.js.map