const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfViewer-BQwV6TUc.js","assets/index-DT8qTvyx.js","assets/index-We5Babj5.css"])))=>i.map(i=>d[i]);
import{f as _,o as x,s as P,V as S,w as g,aF as u,E as v,G as w,h as F,j as f,z as d,P as c,Q as i,T as E,D as V}from"./index-DT8qTvyx.js";var R=_.lazy(function(){return x(()=>import("./PdfViewer-BQwV6TUc.js"),__vite__mapDeps([0,1,2]))}),j=function(p){P(t,p);function t(e){var r=p.call(this,e)||this;return r.wrapper=_.createRef(),r.state={inited:!1,loading:!1,error:!1},r}return t.prototype.componentDidMount=function(){this.wrapper.current&&this.setState({width:this.wrapper.current.clientWidth-100}),this.renderPdf()},t.prototype.componentDidUpdate=function(e){var r=this,n=this.props;(S(e.src,n.src,e.data,n.data)||g(n.src,n.data,"| raw")!==g(e.src,e.data,"| raw"))&&(this.abortLoad(),setTimeout(function(){r.fetchPdf()},0)),u(n.data,n.name)&&u(e.data,e.name)!==u(n.data,n.name)&&(this.abortLoad(),this.renderPdf())},t.prototype.componentWillUnmount=function(){this.abortLoad()},t.prototype.abortLoad=function(){this.fetchCancel&&(this.fetchCancel("load canceled"),this.fetchCancel=void 0),this.reader&&(this.reader.abort(),this.reader=void 0)},t.prototype.renderPdf=function(){return v(this,void 0,void 0,function(){var e,r,n,s;return w(this,function(a){switch(a.label){case 0:return e=this.props,r=e.src,n=e.name,s=e.data,this.setState({error:!1}),r?this.file?[3,2]:[4,this.fetchPdf()]:[3,3];case 1:a.sent(),a.label=2;case 2:return[3,5];case 3:return u(s,n)?[4,this.renderFormFile()]:[3,5];case 4:a.sent(),a.label=5;case 5:return[2]}})})},t.prototype.fetchPdf=function(){return v(this,void 0,void 0,function(){var e,r,n,s,a,o,y,h,m=this;return w(this,function(l){switch(l.label){case 0:if(e=this.props,r=e.env,n=e.src,s=e.data,e.translate,n&&(o=g(n,s,"| raw"),typeof o=="string"?a=o:typeof o=="object"&&typeof o.value=="string"&&(a=o.value)),!a)return console.warn("file src is empty"),[2];this.setState({inited:!0,loading:!0,error:!1}),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,r.fetcher(a,s,{responseType:"arraybuffer",cancelExecutor:function(b){return m.fetchCancel=b}})];case 2:return y=l.sent(),this.file=y.data,this.forceUpdate(),[3,5];case 3:return h=l.sent(),this.setState({error:!0}),console.error(h),[3,5];case 4:return this.setState({loading:!1}),[7];case 5:return[2]}})})},t.prototype.renderFormFile=function(){return v(this,void 0,void 0,function(){var e,r,n,s,a,o=this;return w(this,function(y){return e=this.props,r=e.name,n=e.data,s=u(n,r),this.setState({inited:!0,loading:!0}),s instanceof File&&(a=new FileReader,a.onload=function(h){var m=a.result;o.file=m,o.setState({loading:!1}),o.forceUpdate()},a.onerror=function(h){o.setState({error:!0})},a.readAsArrayBuffer(s),this.reader=a),[2]})})},t.prototype.renderEmpty=function(){var e=this.props,r=e.src,n=e.name;return!r&&!n?F("svg",{width:"100%",height:"100",xmlns:"http://www.w3.org/2000/svg",children:[f("rect",{x:"0",y:"0",width:"100%",height:"100",style:{fill:"#F7F7F9"}}),f("text",{x:"50%",y:"50%",fontSize:"18",textAnchor:"middle",alignmentBaseline:"middle",fontFamily:"monospace, sans-serif",fill:"#555555",children:"PDF viewer"})]}):null},t.prototype.renderError=function(){var e=this.props,r=e.src,n=e.translate,s=this.state.error;return s&&r?f("div",{children:n("loadingFailed")+" url:"+r}):null},t.prototype.renderTip=function(){return f("div",{children:f("p",{children:"[PdfViewer]: pdfjsWorkerSrc is required, Please set the `pdfjsWorkerSrc` in setGlobalOptions function."})})},t.prototype.render=function(){var e=this.props;e.className,e.classnames,e.translate,e.height,e.background;var r=this.state;return r.loading,r.inited,r.error,Math.max(this.props.width||this.state.width,300),F("div",{ref:this.wrapper,children:[this.renderEmpty(),this.renderTip(),this.renderError()]})},d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],t.prototype,"abortLoad",null),d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",Promise)],t.prototype,"renderPdf",null),d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",Promise)],t.prototype,"fetchPdf",null),d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",Promise)],t.prototype,"renderFormFile",null),d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],t.prototype,"renderEmpty",null),d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],t.prototype,"renderError",null),d([c,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],t.prototype,"renderTip",null),t}(_.Component),T=function(p){P(t,p);function t(e,r){var n=p.call(this,e)||this,s=r;return s.registerComponent(n),n}return t.prototype.componentWillUnmount=function(){var e;(e=p.prototype.componentWillUnmount)===null||e===void 0||e.call(this);var r=this.context;r.unRegisterComponent(this)},t.contextType=E,t=d([V({type:"pdf-viewer"}),i("design:paramtypes",[Object,Object])],t),t}(j);export{R as PdfView,T as PdfViewerRenderer,j as default};
