=this.end?-1:(a>=this.progressiveDataLength&&this.ensureByte(a),this.bytes[this.pos++])}getBytes(a){const v=this.bytes,A=this.pos,T=this.end;if(!a)return T>this.progressiveDataLength&&this.ensureRange(A,T),v.subarray(A,T);let d=A+a;return d>T&&(d=T),d>this.progressiveDataLength&&this.ensureRange(A,d),this.pos=d,v.subarray(A,d)}getByteRange(a,v){return a<0&&(a=0),v>this.end&&(v=this.end),v>this.progressiveDataLength&&this.ensureRange(a,v),this.bytes.subarray(a,v)}makeSubStream(a,v,A=null){v?a+v>this.progressiveDataLength&&this.ensureRange(a,a+v):a>=this.progressiveDataLength&&this.ensureByte(a);function T(){}T.prototype=Object.create(this),T.prototype.getMissingChunks=function(){const i=this.chunkSize,C=Math.floor(this.start/i),p=Math.floor((this.end-1)/i)+1,b=[];for(let F=C;F{const p=({value:b,done:F})=>{try{if(F){const u=(0,n.arrayBuffersToBytes)(T);T=null,i(u);return}d+=b.byteLength,A.isStreamingSupported&&this.onProgress({loaded:d}),T.push(b),A.read().then(p,C)}catch(u){C(u)}};A.read().then(p,C)}).then(i=>{this.aborted||this.onReceiveData({chunk:i,begin:a})})}requestAllChunks(a=!1){if(!a){const v=this.stream.getMissingChunks();this._requestChunks(v)}return this._loadedStreamCapability.promise}_requestChunks(a){const v=this.currRequestId++,A=new Set;this._chunksNeededByRequest.set(v,A);for(const i of a)this.stream.hasChunk(i)||A.add(i);if(A.size===0)return Promise.resolve();const T=new _.PromiseCapability;this._promisesByRequest.set(v,T);const d=[];for(const i of A){let C=this._requestsByChunk.get(i);C||(C=[],this._requestsByChunk.set(i,C),d.push(i)),C.push(v)}if(d.length>0){const i=this.groupChunks(d);for(const C of i){const p=C.beginChunk*this.chunkSize,b=Math.min(C.endChunk*this.chunkSize,this.length);this.sendRequest(p,b).catch(T.reject)}}return T.promise.catch(i=>{if(!this.aborted)throw i})}getStream(){return this.stream}requestRange(a,v){v=Math.min(v,this.length);const A=this.getBeginChunk(a),T=this.getEndChunk(v),d=[];for(let i=A;i=0&&T+1!==C&&(v.push({beginChunk:A,endChunk:T+1}),A=C),d+1===a.length&&v.push({beginChunk:A,endChunk:C+1}),T=C}return v}onProgress(a){this.msgHandler.send("DocProgress",{loaded:this.stream.numChunksLoaded*this.chunkSize+a.loaded,total:this.length})}onReceiveData(a){const v=a.chunk,A=a.begin===void 0,T=A?this.progressiveDataLength:a.begin,d=T+v.byteLength,i=Math.floor(T/this.chunkSize),C=d0||p.push(u)}}}if(!this.disableAutoFetch&&this._requestsByChunk.size===0){let b;if(this.stream.numChunksLoaded===1){const F=this.stream.numChunks-1;this.stream.hasChunk(F)||(b=F)}else b=this.stream.nextEmptyChunk(C);Number.isInteger(b)&&this._requestChunks([b])}for(const b of p){const F=this._promisesByRequest.get(b);this._promisesByRequest.delete(b),F.resolve()}this.msgHandler.send("DocProgress",{loaded:this.stream.numChunksLoaded*this.chunkSize,total:this.length})}onError(a){this._loadedStreamCapability.reject(a)}getBeginChunk(a){return Math.floor(a/this.chunkSize)}getEndChunk(a){return Math.floor((a-1)/this.chunkSize)+1}abort(a){var v;this.aborted=!0,(v=this.pdfNetworkStream)==null||v.cancelAllRequests(a);for(const A of this._promisesByRequest.values())A.reject(a)}}},(vt,M,Z)=>{Object.defineProperty(M,"__esModule",{value:!0}),M.StringStream=M.Stream=M.NullStream=void 0;var n=Z(5),_=Z(2);class L extends n.BaseStream{constructor(e,a,v,A){super(),this.bytes=e instanceof Uint8Array?e:new Uint8Array(e),this.start=a||0,this.pos=this.start,this.end=a+v||this.bytes.length,this.dict=A}get length(){return this.end-this.start}get isEmpty(){return this.length===0}getByte(){return this.pos>=this.end?-1:this.bytes[this.pos++]}getBytes(e){const a=this.bytes,v=this.pos,A=this.end;if(!e)return a.subarray(v,A);let T=v+e;return T>A&&(T=A),this.pos=T,a.subarray(v,T)}getByteRange(e,a){return e<0&&(e=0),a>this.end&&(a=this.end),this.bytes.subarray(e,a)}reset(){this.pos=this.start}moveStart(){this.start=this.pos}makeSubStream(e,a,v=null){return new L(this.bytes.buffer,e,a,v)}}M.Stream=L,M.StringStream=class extends L{constructor(e){super((0,_.stringToBytes)(e))}},M.NullStream=class extends L{constructor(){super(new Uint8Array(0))}}},(vt,M,Z)=>{var E,zi,q,Gi,w;Object.defineProperty(M,"__esModule",{value:!0}),M.Page=M.PDFDocument=void 0;var n=Z(2),_=Z(10),L=Z(3),t=Z(4),e=Z(51),a=Z(5),v=Z(74),A=Z(66),T=Z(68),d=Z(102),i=Z(16),C=Z(8),p=Z(76),b=Z(64),F=Z(13),u=Z(18),l=Z(72),y=Z(73),N=Z(77),U=Z(103);const $=[0,0,612,792];class P{constructor({pdfManager:c,xref:S,pageIndex:h,pageDict:m,ref:k,globalIdFactory:I,fontCache:B,builtInCMapCache:tt,standardFontDataCache:it,globalImageCache:st,systemFontCache:X,nonBlendModesSet:J,xfaFactory:j}){_t(this,E);this.pdfManager=c,this.pageIndex=h,this.pageDict=m,this.xref=S,this.ref=k,this.fontCache=B,this.builtInCMapCache=tt,this.standardFontDataCache=it,this.globalImageCache=st,this.systemFontCache=X,this.nonBlendModesSet=J,this.evaluatorOptions=c.evaluatorOptions,this.resourcesPromise=null,this.xfaFactory=j;const O={obj:0};this._localIdFactory=class extends I{static createObjId(){return`p${h}_${++O.obj}`}static getPageObjId(){return`p${k.toString()}`}}}_getInheritableProperty(c,S=!1){const h=(0,L.getInheritableProperty)({dict:this.pageDict,key:c,getArray:S,stopWhenFound:!1});return Array.isArray(h)?h.length!==1&&h[0]instanceof t.Dict?t.Dict.merge({xref:this.xref,dictArray:h}):h[0]:h}get content(){return this.pageDict.getArray("Contents")}get resources(){const c=this._getInheritableProperty("Resources");return(0,n.shadow)(this,"resources",c instanceof t.Dict?c:t.Dict.empty)}_getBoundingBox(c){if(this.xfaData)return this.xfaData.bbox;let S=this._getInheritableProperty(c,!0);if(Array.isArray(S)&&S.length===4){if(S=n.Util.normalizeRect(S),S[2]-S[0]>0&&S[3]-S[1]>0)return S;(0,n.warn)(`Empty, or invalid, /${c} entry.`)}return null}get mediaBox(){return(0,n.shadow)(this,"mediaBox",this._getBoundingBox("MediaBox")||$)}get cropBox(){return(0,n.shadow)(this,"cropBox",this._getBoundingBox("CropBox")||this.mediaBox)}get userUnit(){let c=this.pageDict.get("UserUnit");return(typeof c!="number"||c<=0)&&(c=1),(0,n.shadow)(this,"userUnit",c)}get view(){const{cropBox:c,mediaBox:S}=this;if(c!==S&&!(0,n.isArrayEqual)(c,S)){const h=n.Util.intersect(c,S);if(h&&h[2]-h[0]>0&&h[3]-h[1]>0)return(0,n.shadow)(this,"view",h);(0,n.warn)("Empty /CropBox and /MediaBox intersection.")}return(0,n.shadow)(this,"view",S)}get rotate(){let c=this._getInheritableProperty("Rotate")||0;return c%90!=0?c=0:c>=360?c%=360:c<0&&(c=(c%360+360)%360),(0,n.shadow)(this,"rotate",c)}_onSubStreamError(c,S){if(!this.evaluatorOptions.ignoreErrors)throw c;(0,n.warn)(`getContentStream - ignoring sub-stream (${S}): "${c}".`)}getContentStream(){return this.pdfManager.ensure(this,"content").then(c=>c instanceof a.BaseStream?c:Array.isArray(c)?new u.StreamsSequenceStream(c,this._onSubStreamError.bind(this)):new C.NullStream)}get xfaData(){return(0,n.shadow)(this,"xfaData",this.xfaFactory?{bbox:this.xfaFactory.getBoundingBox(this.pageIndex)}:null)}async saveNewAnnotations(c,S,h,m){if(this.xfaFactory)throw new Error("XFA: Cannot save new annotations.");const k=new F.PartialEvaluator({xref:this.xref,handler:c,pageIndex:this.pageIndex,idFactory:this._localIdFactory,fontCache:this.fontCache,builtInCMapCache:this.builtInCMapCache,standardFontDataCache:this.standardFontDataCache,globalImageCache:this.globalImageCache,systemFontCache:this.systemFontCache,options:this.evaluatorOptions}),I=new t.RefSet,B=new t.RefSet;Lt(this,E,zi).call(this,h,I,B);const tt=this.pageDict,it=this.annotations.filter(O=>!(O instanceof t.Ref&&I.has(O))),st=await _.AnnotationFactory.saveNewAnnotations(k,S,h,m);for(const{ref:O}of st.annotations)O instanceof t.Ref&&!B.has(O)&&it.push(O);const X=tt.get("Annots");tt.set("Annots",it);const J=[];await(0,y.writeObject)(this.ref,tt,J,this.xref),X&&tt.set("Annots",X);const j=st.dependencies;return j.push({ref:this.ref,data:J.join("")},...st.annotations),j}save(c,S,h){const m=new F.PartialEvaluator({xref:this.xref,handler:c,pageIndex:this.pageIndex,idFactory:this._localIdFactory,fontCache:this.fontCache,builtInCMapCache:this.builtInCMapCache,standardFontDataCache:this.standardFontDataCache,globalImageCache:this.globalImageCache,systemFontCache:this.systemFontCache,options:this.evaluatorOptions});return this._parsedAnnotations.then(function(k){const I=[];for(const B of k)B.mustBePrinted(h)&&I.push(B.save(m,S,h).catch(function(tt){return(0,n.warn)(`save - ignoring annotation data during "${S.name}" task: "${tt}".`),null}));return Promise.all(I).then(function(B){return B.filter(tt=>!!tt)})})}loadResources(c){return this.resourcesPromise||(this.resourcesPromise=this.pdfManager.ensure(this,"resources")),this.resourcesPromise.then(()=>new p.ObjectLoader(this.resources,c,this.xref).load())}getOperatorList({handler:c,sink:S,task:h,intent:m,cacheKey:k,annotationStorage:I=null}){const B=this.getContentStream(),tt=this.loadResources(["ColorSpace","ExtGState","Font","Pattern","Properties","Shading","XObject"]),it=new F.PartialEvaluator({xref:this.xref,handler:c,pageIndex:this.pageIndex,idFactory:this._localIdFactory,fontCache:this.fontCache,builtInCMapCache:this.builtInCMapCache,standardFontDataCache:this.standardFontDataCache,globalImageCache:this.globalImageCache,systemFontCache:this.systemFontCache,options:this.evaluatorOptions}),st=this.xfaFactory?null:(0,L.getNewAnnotationsMap)(I);let X=null,J=Promise.resolve(null);if(st){const O=st.get(this.pageIndex);if(O){const H=this.pdfManager.ensureDoc("annotationGlobals");let V;const z=new Set;for(const{bitmapId:G,bitmap:K}of O)!G||K||z.has(G)||z.add(G);const{isOffscreenCanvasSupported:Y}=this.evaluatorOptions;if(z.size>0){const G=O.slice();for(const[K,et]of I)K.startsWith(n.AnnotationEditorPrefix)&&et.bitmap&&z.has(et.bitmapId)&&G.push(et);V=_.AnnotationFactory.generateImages(G,this.xref,Y)}else V=_.AnnotationFactory.generateImages(O,this.xref,Y);X=new t.RefSet,Lt(this,E,zi).call(this,O,X,null),J=H.then(G=>G?_.AnnotationFactory.printNewAnnotations(G,it,h,O,V):null)}}const j=Promise.all([B,tt]).then(([O])=>{const H=new b.OperatorList(m,S);return c.send("StartRenderPage",{transparency:it.hasBlendModes(this.resources,this.nonBlendModesSet),pageIndex:this.pageIndex,cacheKey:k}),it.getOperatorList({stream:O,task:h,resources:this.resources,operatorList:H}).then(function(){return H})});return Promise.all([j,this._parsedAnnotations,J]).then(function([O,H,V]){if(V){H=H.filter(nt=>!(nt.ref&&X.has(nt.ref)));for(let nt=0,at=V.length;ntut.ref&&(0,t.isRefsEqual)(ut.ref,Q.refToReplace));lt>=0&&(H.splice(lt,1,Q),V.splice(nt--,1),at--)}}H=H.concat(V)}if(H.length===0||m&n.RenderingIntentFlag.ANNOTATIONS_DISABLE)return O.flush(!0),{length:O.totalLength};const z=!!(m&n.RenderingIntentFlag.ANNOTATIONS_FORMS),Y=!!(m&n.RenderingIntentFlag.ANY),G=!!(m&n.RenderingIntentFlag.DISPLAY),K=!!(m&n.RenderingIntentFlag.PRINT),et=[];for(const nt of H)(Y||G&&nt.mustBeViewed(I,z)||K&&nt.mustBePrinted(I))&&et.push(nt.getOperatorList(it,h,m,z,I).catch(function(at){return(0,n.warn)(`getOperatorList - ignoring annotation data during "${h.name}" task: "${at}".`),{opList:null,separateForm:!1,separateCanvas:!1}}));return Promise.all(et).then(function(nt){let at=!1,Q=!1;for(const{opList:lt,separateForm:ut,separateCanvas:pt}of nt)O.addOpList(lt),at||(at=ut),Q||(Q=pt);return O.flush(!0,{form:at,canvas:Q}),{length:O.totalLength}})})}extractTextContent({handler:c,task:S,includeMarkedContent:h,disableNormalization:m,sink:k}){const I=this.getContentStream(),B=this.loadResources(["ExtGState","Font","Properties","XObject"]);return Promise.all([I,B]).then(([tt])=>new F.PartialEvaluator({xref:this.xref,handler:c,pageIndex:this.pageIndex,idFactory:this._localIdFactory,fontCache:this.fontCache,builtInCMapCache:this.builtInCMapCache,standardFontDataCache:this.standardFontDataCache,globalImageCache:this.globalImageCache,systemFontCache:this.systemFontCache,options:this.evaluatorOptions}).getTextContent({stream:tt,task:S,resources:this.resources,includeMarkedContent:h,disableNormalization:m,sink:k,viewBox:this.view}))}async getStructTree(){const c=await this.pdfManager.ensureCatalog("structTreeRoot");return c?(await this._parsedAnnotations,(await this.pdfManager.ensure(this,"_parseStructTree",[c])).serializable):null}_parseStructTree(c){const S=new l.StructTreePage(c,this.pageDict);return S.parse(this.ref),S}async getAnnotationsData(c,S,h){const m=await this._parsedAnnotations;if(m.length===0)return m;const k=[],I=[];let B;const tt=!!(h&n.RenderingIntentFlag.ANY),it=!!(h&n.RenderingIntentFlag.DISPLAY),st=!!(h&n.RenderingIntentFlag.PRINT);for(const X of m){const J=tt||it&&X.viewable;(J||st&&X.printable)&&k.push(X.data),X.hasTextContent&&J&&(B||(B=new F.PartialEvaluator({xref:this.xref,handler:c,pageIndex:this.pageIndex,idFactory:this._localIdFactory,fontCache:this.fontCache,builtInCMapCache:this.builtInCMapCache,standardFontDataCache:this.standardFontDataCache,globalImageCache:this.globalImageCache,systemFontCache:this.systemFontCache,options:this.evaluatorOptions})),I.push(X.extractTextContent(B,S,[-1/0,-1/0,1/0,1/0]).catch(function(j){(0,n.warn)(`getAnnotationsData - ignoring textContent during "${S.name}" task: "${j}".`)})))}return await Promise.all(I),k}get annotations(){const c=this._getInheritableProperty("Annots");return(0,n.shadow)(this,"annotations",Array.isArray(c)?c:[])}get _parsedAnnotations(){const c=this.pdfManager.ensure(this,"annotations").then(async S=>{if(S.length===0)return S;const h=await this.pdfManager.ensureDoc("annotationGlobals");if(!h)return[];const m=[];for(const B of S)m.push(_.AnnotationFactory.create(this.xref,B,h,this._localIdFactory,!1,this.ref).catch(function(tt){return(0,n.warn)(`_parsedAnnotations: "${tt}".`),null}));const k=[];let I;for(const B of await Promise.all(m))B&&(B instanceof _.PopupAnnotation?(I||(I=[])).push(B):k.push(B));return I&&k.push(...I),k});return(0,n.shadow)(this,"_parsedAnnotations",c)}get jsActions(){const c=(0,L.collectActions)(this.xref,this.pageDict,n.PageActionEventType);return(0,n.shadow)(this,"jsActions",c)}}E=new WeakSet,zi=function(c,S,h){for(const m of c)if(m.id){const k=t.Ref.fromString(m.id);if(!k){(0,n.warn)(`A non-linked annotation cannot be modified: ${m.id}`);continue}if(m.deleted){S.put(k);continue}h==null||h.put(k),m.ref=k,delete m.id}},M.Page=P;const R=new Uint8Array([37,80,68,70,45]),o=new Uint8Array([115,116,97,114,116,120,114,101,102]),g=new Uint8Array([101,110,100,111,98,106]);function x(s,c,S=1024,h=!1){const m=c.length,k=s.peekBytes(S),I=k.length-m;if(I<=0)return!1;if(h){const B=m-1;let tt=k.length-1;for(;tt>=B;){let it=0;for(;it=m)return s.pos+=tt-B,!0;tt--}}else{let B=0;for(;B<=I;){let tt=0;for(;tt=m)return s.pos+=B,!0;B++}}return!1}M.PDFDocument=(w=class{constructor(c,S){_t(this,q);if(S.length<=0)throw new n.InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes.");this.pdfManager=c,this.stream=S,this.xref=new U.XRef(S,c),this._pagePromises=new Map,this._version=null;const h={font:0};this._globalIdFactory=class{static getDocId(){return`g_${c.docId}`}static createFontId(){return"f"+ ++h.font}static createObjId(){(0,n.unreachable)("Abstract method `createObjId` called.")}static getPageObjId(){(0,n.unreachable)("Abstract method `getPageObjId` called.")}}}parse(c){this.xref.parse(c),this.catalog=new A.Catalog(this.pdfManager,this.xref)}get linearization(){let c=null;try{c=i.Linearization.create(this.stream)}catch(S){if(S instanceof L.MissingDataException)throw S;(0,n.info)(S)}return(0,n.shadow)(this,"linearization",c)}get startXRef(){const c=this.stream;let S=0;if(this.linearization)c.reset(),x(c,g)&&(S=c.pos+6-c.start);else{const m=o.length;let k=!1,I=c.end;for(;!k&&I>0;)I-=1024-m,I<0&&(I=0),c.pos=I,k=x(c,o,1024,!0);if(k){c.skip(9);let B;do B=c.getByte();while((0,L.isWhiteSpace)(B));let tt="";for(;B>=32&&B<=57;)tt+=String.fromCharCode(B),B=c.getByte();S=parseInt(tt,10),isNaN(S)&&(S=0)}}return(0,n.shadow)(this,"startXRef",S)}checkHeader(){const c=this.stream;if(c.reset(),!x(c,R))return;c.moveStart(),c.skip(R.length);let S,h="";for(;(S=c.getByte())>32&&h.length<7;)h+=String.fromCharCode(S);L.PDF_VERSION_REGEXP.test(h)?this._version=h:(0,n.warn)(`Invalid PDF header version: ${h}`)}parseStartXRef(){this.xref.setStartXRef(this.startXRef)}get numPages(){let c=0;return c=this.catalog.hasActualNumPages?this.catalog.numPages:this.xfaFactory?this.xfaFactory.getNumPages():this.linearization?this.linearization.numPages:this.catalog.numPages,(0,n.shadow)(this,"numPages",c)}_hasOnlyDocumentSignatures(c,S=0){return!!Array.isArray(c)&&c.every(h=>{if(!((h=this.xref.fetchIfRef(h))instanceof t.Dict))return!1;if(h.has("Kids"))return++S>10?((0,n.warn)("_hasOnlyDocumentSignatures: maximum recursion depth reached"),!1):this._hasOnlyDocumentSignatures(h.get("Kids"),S);const m=(0,t.isName)(h.get("FT"),"Sig"),k=h.get("Rect"),I=Array.isArray(k)&&k.every(B=>B===0);return m&&I})}get _xfaStreams(){const c=this.catalog.acroForm;if(!c)return null;const S=c.get("XFA"),h={"xdp:xdp":"",template:"",datasets:"",config:"",connectionSet:"",localeSet:"",stylesheet:"","/xdp:xdp":""};if(S instanceof a.BaseStream&&!S.isEmpty)return h["xdp:xdp"]=S,h;if(!Array.isArray(S)||S.length===0)return null;for(let m=0,k=S.length;m{J.set(V,z)});const j=[];for(const[V,z]of J){const Y=z.get("FontDescriptor");if(!(Y instanceof t.Dict))continue;let G=Y.get("FontFamily");G=G.replaceAll(/[ ]+(\d)/g,"$1");const K={fontFamily:G,fontWeight:Y.get("FontWeight"),italicAngle:-Y.get("ItalicAngle")};(0,L.validateCSSFont)(K)&&j.push(tt.handleSetFont(m,[t.Name.get(V),1],null,it,S,X,null,K).catch(function(et){return(0,n.warn)(`loadXfaFonts: "${et}".`),null}))}await Promise.all(j);const O=this.xfaFactory.setFonts(st);if(!O)return;B.ignoreErrors=!0,j.length=0,st.length=0;const H=new Set;for(const V of O)(0,e.getXfaFontName)(`${V}-Regular`)||H.add(V);H.size&&O.push("PdfJS-Fallback");for(const V of O)if(!H.has(V))for(const z of[{name:"Regular",fontWeight:400,italicAngle:0},{name:"Bold",fontWeight:700,italicAngle:0},{name:"Italic",fontWeight:400,italicAngle:12},{name:"BoldItalic",fontWeight:700,italicAngle:12}]){const Y=`${V}-${z.name}`,G=(0,e.getXfaFontDict)(Y);j.push(tt.handleSetFont(m,[t.Name.get(Y),1],null,it,S,X,G,{fontFamily:V,fontWeight:z.fontWeight,italicAngle:z.italicAngle}).catch(function(K){return(0,n.warn)(`loadXfaFonts: "${K}".`),null}))}await Promise.all(j),this.xfaFactory.appendFonts(st,H)}async serializeXfaData(c){return this.xfaFactory?this.xfaFactory.serializeData(c):null}get version(){return this.catalog.version||this._version}get formInfo(){const c={hasFields:!1,hasAcroForm:!1,hasXfa:!1,hasSignatures:!1},S=this.catalog.acroForm;if(!S)return(0,n.shadow)(this,"formInfo",c);try{const h=S.get("Fields"),m=Array.isArray(h)&&h.length>0;c.hasFields=m;const k=S.get("XFA");c.hasXfa=Array.isArray(k)&&k.length>0||k instanceof a.BaseStream&&!k.isEmpty;const I=!!(1&S.get("SigFlags")),B=I&&this._hasOnlyDocumentSignatures(h);c.hasAcroForm=m&&!B,c.hasSignatures=I}catch(h){if(h instanceof L.MissingDataException)throw h;(0,n.warn)(`Cannot fetch form information: "${h}".`)}return(0,n.shadow)(this,"formInfo",c)}get documentInfo(){const c={PDFFormatVersion:this.version,Language:this.catalog.lang,EncryptFilterName:this.xref.encrypt?this.xref.encrypt.filterName:null,IsLinearized:!!this.linearization,IsAcroFormPresent:this.formInfo.hasAcroForm,IsXFAPresent:this.formInfo.hasXfa,IsCollectionPresent:!!this.catalog.collection,IsSignaturesPresent:this.formInfo.hasSignatures};let S;try{S=this.xref.trailer.get("Info")}catch(h){if(h instanceof L.MissingDataException)throw h;(0,n.info)("The document information dictionary is invalid.")}if(!(S instanceof t.Dict))return(0,n.shadow)(this,"documentInfo",c);for(const h of S.getKeys()){const m=S.get(h);switch(h){case"Title":case"Author":case"Subject":case"Keywords":case"Creator":case"Producer":case"CreationDate":case"ModDate":if(typeof m=="string"){c[h]=(0,n.stringToPDFString)(m);continue}break;case"Trapped":if(m instanceof t.Name){c[h]=m;continue}break;default:let k;switch(typeof m){case"string":k=(0,n.stringToPDFString)(m);break;case"number":case"boolean":k=m;break;default:m instanceof t.Name&&(k=m)}if(k===void 0){(0,n.warn)(`Bad value, for custom key "${h}", in Info: ${m}.`);continue}c.Custom||(c.Custom=Object.create(null)),c.Custom[h]=k;continue}(0,n.warn)(`Bad value, for key "${h}", in Info: ${m}.`)}return(0,n.shadow)(this,"documentInfo",c)}get fingerprints(){function c(I){return typeof I=="string"&&I.length>0&&I!=="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}function S(I){const B=[];for(const tt of I){const it=tt.toString(16);B.push(it.padStart(2,"0"))}return B.join("")}const h=this.xref.trailer.get("ID");let m,k;return Array.isArray(h)&&c(h[0])?(m=(0,n.stringToBytes)(h[0]),h[1]!==h[0]&&c(h[1])&&(k=(0,n.stringToBytes)(h[1]))):m=(0,v.calculateMD5)(this.stream.getByteRange(0,1024),0,1024),(0,n.shadow)(this,"fingerprints",[S(m),k?S(k):null])}async _getLinearizationPage(c){const{catalog:S,linearization:h,xref:m}=this,k=t.Ref.get(h.objectNumberFirst,0);try{const I=await m.fetchAsync(k);if(I instanceof t.Dict){let B=I.getRaw("Type");if(B instanceof t.Ref&&(B=await m.fetchAsync(B)),(0,t.isName)(B,"Page")||!I.has("Type")&&!I.has("Kids"))return S.pageKidsCountCache.has(k)||S.pageKidsCountCache.put(k,1),S.pageIndexCache.has(k)||S.pageIndexCache.put(k,0),[I,k]}throw new n.FormatError("The Linearization dictionary doesn't point to a valid Page dictionary.")}catch(I){return(0,n.warn)(`_getLinearizationPage: "${I.message}".`),S.getPageDict(c)}}getPage(c){const S=this._pagePromises.get(c);if(S)return S;const{catalog:h,linearization:m,xfaFactory:k}=this;let I;return I=k?Promise.resolve([t.Dict.empty,null]):(m==null?void 0:m.pageFirst)===c?this._getLinearizationPage(c):h.getPageDict(c),I=I.then(([B,tt])=>new P({pdfManager:this.pdfManager,xref:this.xref,pageIndex:c,pageDict:B,ref:tt,globalIdFactory:this._globalIdFactory,fontCache:h.fontCache,builtInCMapCache:h.builtInCMapCache,standardFontDataCache:h.standardFontDataCache,globalImageCache:h.globalImageCache,systemFontCache:h.systemFontCache,nonBlendModesSet:h.nonBlendModesSet,xfaFactory:k})),this._pagePromises.set(c,I),I}async checkFirstPage(c=!1){if(!c)try{await this.getPage(0)}catch(S){if(S instanceof L.XRefEntryException)throw this._pagePromises.delete(0),await this.cleanup(),new L.XRefParseException}}async checkLastPage(c=!1){const{catalog:S,pdfManager:h}=this;S.setActualNumPages();let m;try{if(await Promise.all([h.ensureDoc("xfaFactory"),h.ensureDoc("linearization"),h.ensureCatalog("numPages")]),this.xfaFactory)return;if(m=this.linearization?this.linearization.numPages:S.numPages,!Number.isInteger(m))throw new n.FormatError("Page count is not an integer.");if(m<=1)return;await this.getPage(m-1)}catch(k){if(this._pagePromises.delete(m-1),await this.cleanup(),k instanceof L.XRefEntryException&&!c)throw new L.XRefParseException;(0,n.warn)(`checkLastPage - invalid /Pages tree /Count: ${m}.`);let I;try{I=await S.getAllPageDicts(c)}catch(B){if(B instanceof L.XRefEntryException&&!c)throw new L.XRefParseException;S.setActualNumPages(1);return}for(const[B,[tt,it]]of I){let st;tt instanceof Error?(st=Promise.reject(tt),st.catch(()=>{})):st=Promise.resolve(new P({pdfManager:h,xref:this.xref,pageIndex:B,pageDict:tt,ref:it,globalIdFactory:this._globalIdFactory,fontCache:S.fontCache,builtInCMapCache:S.builtInCMapCache,standardFontDataCache:S.standardFontDataCache,globalImageCache:S.globalImageCache,systemFontCache:S.systemFontCache,nonBlendModesSet:S.nonBlendModesSet,xfaFactory:null})),this._pagePromises.set(B,st)}S.setActualNumPages(I.size)}}fontFallback(c,S){return this.catalog.fontFallback(c,S)}async cleanup(c=!1){return this.catalog?this.catalog.cleanup(c):(0,T.clearGlobalCaches)()}get fieldObjects(){if(!this.formInfo.hasFields)return(0,n.shadow)(this,"fieldObjects",Promise.resolve(null));const c=this.pdfManager.ensureDoc("annotationGlobals").then(async S=>{if(!S)return null;const h=Object.create(null),m=new Map;for(const I of this.catalog.acroForm.get("Fields"))Lt(this,q,Gi).call(this,"",I,m,S);const k=[];for(const[I,B]of m)k.push(Promise.all(B).then(tt=>{(tt=tt.filter(it=>!!it)).length>0&&(h[I]=tt)}));return await Promise.all(k),h});return(0,n.shadow)(this,"fieldObjects",c)}get hasJSActions(){const c=this.pdfManager.ensureDoc("_parseHasJSActions");return(0,n.shadow)(this,"hasJSActions",c)}async _parseHasJSActions(){const[c,S]=await Promise.all([this.pdfManager.ensureCatalog("jsActions"),this.pdfManager.ensureDoc("fieldObjects")]);return!!c||!!S&&Object.values(S).some(h=>h.some(m=>m.actions!==null))}get calculationOrderIds(){const c=this.catalog.acroForm;if(!(c!=null&&c.has("CO")))return(0,n.shadow)(this,"calculationOrderIds",null);const S=c.get("CO");if(!Array.isArray(S)||S.length===0)return(0,n.shadow)(this,"calculationOrderIds",null);const h=[];for(const m of S)m instanceof t.Ref&&h.push(m.toString());return h.length===0?(0,n.shadow)(this,"calculationOrderIds",null):(0,n.shadow)(this,"calculationOrderIds",h)}get annotationGlobals(){return(0,n.shadow)(this,"annotationGlobals",_.AnnotationFactory.createGlobals(this.pdfManager))}},q=new WeakSet,Gi=function(c,S,h,m){const k=this.xref.fetchIfRef(S);if(k.has("T")){const I=(0,n.stringToPDFString)(k.get("T"));c=c===""?I:`${c}.${I}`}if(h.has(c)||h.set(c,[]),h.get(c).push(_.AnnotationFactory.create(this.xref,S,m,this._localIdFactory,!0,null).then(I=>I==null?void 0:I.getFieldObject()).catch(function(I){return(0,n.warn)(`#collectFieldObjects: "${I}".`),null})),k.has("Kids"))for(const I of k.get("Kids"))Lt(this,q,Gi).call(this,c,I,h,m)},w)},(vt,M,Z)=>{Object.defineProperty(M,"__esModule",{value:!0}),M.PopupAnnotation=M.MarkupAnnotation=M.AnnotationFactory=M.AnnotationBorderStyle=M.Annotation=void 0,M.getQuadPoints=y;var n=Z(2),_=Z(3),L=Z(11),t=Z(4),e=Z(8),a=Z(5),v=Z(60),A=Z(66),T=Z(12),d=Z(69),i=Z(26),C=Z(76),p=Z(64),b=Z(73),F=Z(77);M.AnnotationFactory=class{static createGlobals(O){return Promise.all([O.ensureCatalog("acroForm"),O.ensureDoc("xfaDatasets"),O.ensureCatalog("structTreeRoot"),O.ensureCatalog("baseUrl"),O.ensureCatalog("attachments")]).then(([H,V,z,Y,G])=>({pdfManager:O,acroForm:H instanceof t.Dict?H:t.Dict.empty,xfaDatasets:V,structTreeRoot:z,baseUrl:Y,attachments:G}),H=>((0,n.warn)(`createGlobals: "${H}".`),null))}static async create(O,H,V,z,Y,G){const K=Y?await this._getPageIndex(O,H,V.pdfManager):null;return V.pdfManager.ensure(this,"_create",[O,H,V,z,Y,K,G])}static _create(O,H,V,z,Y=!1,G=null,K=null){const et=O.fetchIfRef(H);if(!(et instanceof t.Dict))return;const{acroForm:nt,pdfManager:at}=V,Q=H instanceof t.Ref?H.toString():`annot_${z.createObjId()}`;let lt=et.get("Subtype");lt=lt instanceof t.Name?lt.name:null;const ut={xref:O,ref:H,dict:et,subtype:lt,id:Q,annotationGlobals:V,collectFields:Y,needAppearances:!Y&&nt.get("NeedAppearances")===!0,pageIndex:G,evaluatorOptions:at.evaluatorOptions,pageRef:K};switch(lt){case"Link":return new q(ut);case"Text":return new D(ut);case"Widget":let pt=(0,_.getInheritableProperty)({dict:et,key:"FT"});switch(pt=pt instanceof t.Name?pt.name:null,pt){case"Tx":return new o(ut);case"Btn":return new g(ut);case"Ch":return new x(ut);case"Sig":return new E(ut)}return(0,n.warn)(`Unimplemented widget field type "${pt}", falling back to base field type.`),new R(ut);case"Popup":return new W(ut);case"FreeText":return new w(ut);case"Line":return new s(ut);case"Square":return new c(ut);case"Circle":return new S(ut);case"PolyLine":return new h(ut);case"Polygon":return new m(ut);case"Caret":return new k(ut);case"Ink":return new I(ut);case"Highlight":return new B(ut);case"Underline":return new tt(ut);case"Squiggly":return new it(ut);case"StrikeOut":return new st(ut);case"Stamp":return new X(ut);case"FileAttachment":return new J(ut);default:return Y||(lt?(0,n.warn)(`Unimplemented annotation type "${lt}", falling back to base annotation.`):(0,n.warn)("Annotation is missing the required /Subtype.")),new U(ut)}}static async _getPageIndex(O,H,V){try{const z=await O.fetchIfRefAsync(H);if(!(z instanceof t.Dict))return-1;const Y=z.getRaw("P");if(Y instanceof t.Ref)try{return await V.ensureCatalog("getPageIndex",[Y])}catch(K){(0,n.info)(`_getPageIndex -- not a valid page reference: "${K}".`)}if(z.has("Kids"))return-1;const G=await V.ensureDoc("numPages");for(let K=0;KO/255)}function y(j,O){const H=j.getArray("QuadPoints");if(!Array.isArray(H)||H.length===0||H.length%8>0)return null;const V=[];for(let z=0,Y=H.length/8;zO[2]||etO[3]))return null;V.push([{x:G,y:nt},{x:K,y:nt},{x:G,y:et},{x:K,y:et}])}return V}function N(j,O,H){const[V,z,Y,G]=n.Util.getAxialAlignedBoundingBox(O,H);if(V===Y||z===G)return[1,0,0,1,j[0],j[1]];const K=(j[2]-j[0])/(Y-V),et=(j[3]-j[1])/(G-z);return[K,0,0,et,j[0]-V*K,j[1]-z*et]}class U{constructor(O){const{dict:H,xref:V,annotationGlobals:z}=O;this.setTitle(H.get("T")),this.setContents(H.get("Contents")),this.setModificationDate(H.get("M")),this.setFlags(H.get("F")),this.setRectangle(H.getArray("Rect")),this.setColor(H.getArray("C")),this.setBorderStyle(H),this.setAppearance(H),this.setOptionalContent(H);const Y=H.get("MK");this.setBorderAndBackgroundColors(Y),this.setRotation(Y,H),this.ref=O.ref instanceof t.Ref?O.ref:null,this._streams=[],this.appearance&&this._streams.push(this.appearance);const G=!!(this.flags&n.AnnotationFlag.LOCKED),K=!!(this.flags&n.AnnotationFlag.LOCKEDCONTENTS);if(z.structTreeRoot){let et=H.get("StructParent");et=Number.isInteger(et)&&et>=0?et:-1,z.structTreeRoot.addAnnotationIdToPage(O.pageRef,et)}if(this.data={annotationFlags:this.flags,borderStyle:this.borderStyle,color:this.color,backgroundColor:this.backgroundColor,borderColor:this.borderColor,rotation:this.rotation,contentsObj:this._contents,hasAppearance:!!this.appearance,id:O.id,modificationDate:this.modificationDate,rect:this.rectangle,subtype:O.subtype,hasOwnCanvas:!1,noRotate:!!(this.flags&n.AnnotationFlag.NOROTATE),noHTML:G&&K},O.collectFields){const et=H.get("Kids");if(Array.isArray(et)){const nt=[];for(const at of et)at instanceof t.Ref&&nt.push(at.toString());nt.length!==0&&(this.data.kidIds=nt)}this.data.actions=(0,_.collectActions)(V,H,n.AnnotationActionEventType),this.data.fieldName=this._constructFieldName(H),this.data.pageIndex=O.pageIndex}this._isOffscreenCanvasSupported=O.evaluatorOptions.isOffscreenCanvasSupported,this._fallbackFontDict=null,this._needAppearances=!1}_hasFlag(O,H){return!!(O&H)}_isViewable(O){return!this._hasFlag(O,n.AnnotationFlag.INVISIBLE)&&!this._hasFlag(O,n.AnnotationFlag.NOVIEW)}_isPrintable(O){return this._hasFlag(O,n.AnnotationFlag.PRINT)&&!this._hasFlag(O,n.AnnotationFlag.HIDDEN)&&!this._hasFlag(O,n.AnnotationFlag.INVISIBLE)}mustBeViewed(O,H){var z;const V=(z=O==null?void 0:O.get(this.data.id))==null?void 0:z.noView;return V!==void 0?!V:this.viewable&&!this._hasFlag(this.flags,n.AnnotationFlag.HIDDEN)}mustBePrinted(O){var V;const H=(V=O==null?void 0:O.get(this.data.id))==null?void 0:V.noPrint;return H!==void 0?!H:this.printable}get viewable(){return this.data.quadPoints!==null&&(this.flags===0||this._isViewable(this.flags))}get printable(){return this.data.quadPoints!==null&&this.flags!==0&&this._isPrintable(this.flags)}_parseStringHelper(O){const H=typeof O=="string"?(0,n.stringToPDFString)(O):"";return{str:H,dir:H&&(0,v.bidi)(H).dir==="rtl"?"rtl":"ltr"}}setDefaultAppearance(O){const{dict:H,annotationGlobals:V}=O,z=(0,_.getInheritableProperty)({dict:H,key:"DA"})||V.acroForm.get("DA");this._defaultAppearance=typeof z=="string"?z:"",this.data.defaultAppearanceData=(0,L.parseDefaultAppearance)(this._defaultAppearance)}setTitle(O){this._title=this._parseStringHelper(O)}setContents(O){this._contents=this._parseStringHelper(O)}setModificationDate(O){this.modificationDate=typeof O=="string"?O:null}setFlags(O){this.flags=Number.isInteger(O)&&O>0?O:0}hasFlag(O){return this._hasFlag(this.flags,O)}setRectangle(O){this.rectangle=Array.isArray(O)&&O.length===4?n.Util.normalizeRect(O):[0,0,0,0]}setColor(O){this.color=u(O)}setLineEndings(O){if(this.lineEndings=["None","None"],Array.isArray(O)&&O.length===2)for(let H=0;H<2;H++){const V=O[H];if(V instanceof t.Name)switch(V.name){case"None":continue;case"Square":case"Circle":case"Diamond":case"OpenArrow":case"ClosedArrow":case"Butt":case"ROpenArrow":case"RClosedArrow":case"Slash":this.lineEndings[H]=V.name;continue}(0,n.warn)(`Ignoring invalid lineEnding: ${V}`)}}setRotation(O,H){this.rotation=0;let V=O instanceof t.Dict?O.get("R")||0:H.get("Rotate")||0;Number.isInteger(V)&&V!==0&&(V%=360,V<0&&(V+=360),V%90==0&&(this.rotation=V))}setBorderAndBackgroundColors(O){O instanceof t.Dict?(this.borderColor=u(O.getArray("BC"),null),this.backgroundColor=u(O.getArray("BG"),null)):this.borderColor=this.backgroundColor=null}setBorderStyle(O){if(this.borderStyle=new $,O instanceof t.Dict)if(O.has("BS")){const H=O.get("BS"),V=H.get("Type");(!V||(0,t.isName)(V,"Border"))&&(this.borderStyle.setWidth(H.get("W"),this.rectangle),this.borderStyle.setStyle(H.get("S")),this.borderStyle.setDashArray(H.getArray("D")))}else if(O.has("Border")){const H=O.getArray("Border");Array.isArray(H)&&H.length>=3&&(this.borderStyle.setHorizontalCornerRadius(H[0]),this.borderStyle.setVerticalCornerRadius(H[1]),this.borderStyle.setWidth(H[2],this.rectangle),H.length===4&&this.borderStyle.setDashArray(H[3],!0))}else this.borderStyle.setWidth(0)}setAppearance(O){this.appearance=null;const H=O.get("AP");if(!(H instanceof t.Dict))return;const V=H.get("N");if(V instanceof a.BaseStream){this.appearance=V;return}if(!(V instanceof t.Dict))return;const z=O.get("AS");if(!(z instanceof t.Name&&V.has(z.name)))return;const Y=V.get(z.name);Y instanceof a.BaseStream&&(this.appearance=Y)}setOptionalContent(O){this.oc=null;const H=O.get("OC");H instanceof t.Name?(0,n.warn)("setOptionalContent: Support for /Name-entry is not implemented."):H instanceof t.Dict&&(this.oc=H)}loadResources(O,H){return H.dict.getAsync("Resources").then(V=>{if(V)return new C.ObjectLoader(V,O,V.xref).load().then(function(){return V})})}async getOperatorList(O,H,V,z,Y){const G=this.data;let K=this.appearance;const et=!!(this.data.hasOwnCanvas&&V&n.RenderingIntentFlag.DISPLAY);if(!K){if(!et)return{opList:new p.OperatorList,separateForm:!1,separateCanvas:!1};K=new e.StringStream(""),K.dict=new t.Dict}const nt=K.dict,at=await this.loadResources(["ExtGState","ColorSpace","Pattern","Shading","XObject","Font"],K),Q=nt.getArray("BBox")||[0,0,1,1],lt=nt.getArray("Matrix")||[1,0,0,1,0,0],ut=N(G.rect,Q,lt),pt=new p.OperatorList;let yt;return this.oc&&(yt=await O.parseMarkedContentProps(this.oc,null)),yt!==void 0&&pt.addOp(n.OPS.beginMarkedContentProps,["OC",yt]),pt.addOp(n.OPS.beginAnnotation,[G.id,G.rect,ut,lt,et]),await O.getOperatorList({stream:K,task:H,resources:at,operatorList:pt,fallbackFontDict:this._fallbackFontDict}),pt.addOp(n.OPS.endAnnotation,[]),yt!==void 0&&pt.addOp(n.OPS.endMarkedContent,[]),this.reset(),{opList:pt,separateForm:!1,separateCanvas:et}}async save(O,H,V){return null}get hasTextContent(){return!1}async extractTextContent(O,H,V){if(!this.appearance)return;const z=await this.loadResources(["ExtGState","Font","Properties","XObject"],this.appearance),Y=[],G=[];let K=null;const et={desiredSize:Math.Infinity,ready:!0,enqueue(nt,at){for(const Q of nt.items)Q.str!==void 0&&(K||(K=Q.transform.slice(-2)),G.push(Q.str),Q.hasEOL&&(Y.push(G.join("")),G.length=0))}};if(await O.getTextContent({stream:this.appearance,task:H,resources:z,includeMarkedContent:!0,sink:et,viewBox:V}),this.reset(),G.length&&Y.push(G.join("")),Y.length>1||Y[0]){const nt=this.appearance.dict,at=nt.getArray("BBox")||[0,0,1,1],Q=nt.getArray("Matrix")||[1,0,0,1,0,0],lt=this.data.rect,ut=N(lt,at,Q);ut[4]-=lt[0],ut[5]-=lt[1],K=n.Util.applyTransform(K,ut),K=n.Util.applyTransform(K,Q),this.data.textPosition=K,this.data.textContent=Y}}getFieldObject(){return this.data.kidIds?{id:this.data.id,actions:this.data.actions,name:this.data.fieldName,strokeColor:this.data.borderColor,fillColor:this.data.backgroundColor,type:"",kidIds:this.data.kidIds,page:this.data.pageIndex,rotation:this.rotation}:null}reset(){for(const O of this._streams)O.reset()}_constructFieldName(O){if(!O.has("T")&&!O.has("Parent"))return(0,n.warn)("Unknown field name, falling back to empty field name."),"";if(!O.has("Parent"))return(0,n.stringToPDFString)(O.get("T"));const H=[];O.has("T")&&H.unshift((0,n.stringToPDFString)(O.get("T")));let V=O;const z=new t.RefSet;for(O.objId&&z.put(O.objId);V.has("Parent")&&(V=V.get("Parent"),!(!(V instanceof t.Dict)||V.objId&&z.has(V.objId)));)V.objId&&z.put(V.objId),V.has("T")&&H.unshift((0,n.stringToPDFString)(V.get("T")));return H.join(".")}}M.Annotation=U;class ${constructor(){this.width=1,this.style=n.AnnotationBorderStyleType.SOLID,this.dashArray=[3],this.horizontalCornerRadius=0,this.verticalCornerRadius=0}setWidth(O,H=[0,0,0,0]){if(O instanceof t.Name)this.width=0;else if(typeof O=="number"){if(O>0){const V=(H[2]-H[0])/2,z=(H[3]-H[1])/2;V>0&&z>0&&(O>V||O>z)&&((0,n.warn)(`AnnotationBorderStyle.setWidth - ignoring width: ${O}`),O=1)}this.width=O}}setStyle(O){if(O instanceof t.Name)switch(O.name){case"S":this.style=n.AnnotationBorderStyleType.SOLID;break;case"D":this.style=n.AnnotationBorderStyleType.DASHED;break;case"B":this.style=n.AnnotationBorderStyleType.BEVELED;break;case"I":this.style=n.AnnotationBorderStyleType.INSET;break;case"U":this.style=n.AnnotationBorderStyleType.UNDERLINE}}setDashArray(O,H=!1){if(Array.isArray(O)&&O.length>0){let V=!0,z=!0;for(const Y of O){if(!(+Y>=0)){V=!1;break}Y>0&&(z=!1)}V&&!z?(this.dashArray=O,H&&this.setStyle(t.Name.get("D"))):this.width=0}else O&&(this.width=0)}setHorizontalCornerRadius(O){Number.isInteger(O)&&(this.horizontalCornerRadius=O)}setVerticalCornerRadius(O){Number.isInteger(O)&&(this.verticalCornerRadius=O)}}M.AnnotationBorderStyle=$;class P extends U{constructor(O){super(O);const{dict:H}=O;if(H.has("IRT")){const z=H.getRaw("IRT");this.data.inReplyTo=z instanceof t.Ref?z.toString():null;const Y=H.get("RT");this.data.replyType=Y instanceof t.Name?Y.name:n.AnnotationReplyType.REPLY}let V=null;if(this.data.replyType===n.AnnotationReplyType.GROUP){const z=H.get("IRT");this.setTitle(z.get("T")),this.data.titleObj=this._title,this.setContents(z.get("Contents")),this.data.contentsObj=this._contents,z.has("CreationDate")?(this.setCreationDate(z.get("CreationDate")),this.data.creationDate=this.creationDate):this.data.creationDate=null,z.has("M")?(this.setModificationDate(z.get("M")),this.data.modificationDate=this.modificationDate):this.data.modificationDate=null,V=z.getRaw("Popup"),z.has("C")?(this.setColor(z.getArray("C")),this.data.color=this.color):this.data.color=null}else this.data.titleObj=this._title,this.setCreationDate(H.get("CreationDate")),this.data.creationDate=this.creationDate,V=H.getRaw("Popup"),H.has("C")||(this.data.color=null);this.data.popupRef=V instanceof t.Ref?V.toString():null,H.has("RC")&&(this.data.richText=F.XFAFactory.getRichTextAsHtml(H.get("RC")))}setCreationDate(O){this.creationDate=typeof O=="string"?O:null}_setDefaultAppearance({xref:O,extra:H,strokeColor:V,fillColor:z,blendMode:Y,strokeAlpha:G,fillAlpha:K,pointsCallback:et}){let nt=Number.MAX_VALUE,at=Number.MAX_VALUE,Q=Number.MIN_VALUE,lt=Number.MIN_VALUE;const ut=["q"];H&&ut.push(H),V&&ut.push(`${V[0]} ${V[1]} ${V[2]} RG`),z&&ut.push(`${z[0]} ${z[1]} ${z[2]} rg`);let pt=this.data.quadPoints;pt||(pt=[[{x:this.rectangle[0],y:this.rectangle[3]},{x:this.rectangle[2],y:this.rectangle[3]},{x:this.rectangle[0],y:this.rectangle[1]},{x:this.rectangle[2],y:this.rectangle[1]}]]);for(const Gt of pt){const[Zt,Ft,Ut,Vt]=et(ut,Gt);nt=Math.min(nt,Zt),Q=Math.max(Q,Ft),at=Math.min(at,Ut),lt=Math.max(lt,Vt)}ut.push("Q");const yt=new t.Dict(O),Et=new t.Dict(O);Et.set("Subtype",t.Name.get("Form"));const Tt=new e.StringStream(ut.join(" "));Tt.dict=Et,yt.set("Fm0",Tt);const xt=new t.Dict(O);Y&&xt.set("BM",t.Name.get(Y)),typeof G=="number"&&xt.set("CA",G),typeof K=="number"&&xt.set("ca",K);const wt=new t.Dict(O);wt.set("GS0",xt);const St=new t.Dict(O);St.set("ExtGState",wt),St.set("XObject",yt);const Rt=new t.Dict(O);Rt.set("Resources",St);const Ct=this.data.rect=[nt,at,Q,lt];Rt.set("BBox",Ct),this.appearance=new e.StringStream("/GS0 gs /Fm0 Do"),this.appearance.dict=Rt,this._streams.push(this.appearance,Tt)}static async createNewAnnotation(O,H,V,z){const Y=H.ref||(H.ref=O.getNewTemporaryRef()),G=await this.createNewAppearanceStream(H,O,z),K=[];let et;if(G){const nt=O.getNewTemporaryRef();et=this.createNewDict(H,O,{apRef:nt}),await(0,b.writeObject)(nt,G,K,O),V.push({ref:nt,data:K.join("")})}else et=this.createNewDict(H,O,{});return Number.isInteger(H.parentTreeId)&&et.set("StructParent",H.parentTreeId),K.length=0,await(0,b.writeObject)(Y,et,K,O),{ref:Y,data:K.join("")}}static async createNewPrintAnnotation(O,H,V,z){const Y=await this.createNewAppearanceStream(V,H,z),G=this.createNewDict(V,H,{ap:Y}),K=new this.prototype.constructor({dict:G,xref:H,annotationGlobals:O,evaluatorOptions:z.evaluatorOptions});return V.ref&&(K.ref=K.refToReplace=V.ref),K}}M.MarkupAnnotation=P;class R extends U{constructor(O){var lt;super(O);const{dict:H,xref:V,annotationGlobals:z}=O,Y=this.data;this._needAppearances=O.needAppearances,Y.annotationType=n.AnnotationType.WIDGET,Y.fieldName===void 0&&(Y.fieldName=this._constructFieldName(H)),Y.actions===void 0&&(Y.actions=(0,_.collectActions)(V,H,n.AnnotationActionEventType));let G=(0,_.getInheritableProperty)({dict:H,key:"V",getArray:!0});Y.fieldValue=this._decodeFormValue(G);const K=(0,_.getInheritableProperty)({dict:H,key:"DV",getArray:!0});if(Y.defaultFieldValue=this._decodeFormValue(K),G===void 0&&z.xfaDatasets){const ut=this._title.str;ut&&(this._hasValueFromXFA=!0,Y.fieldValue=G=z.xfaDatasets.getValue(ut))}G===void 0&&Y.defaultFieldValue!==null&&(Y.fieldValue=Y.defaultFieldValue),Y.alternativeText=(0,n.stringToPDFString)(H.get("TU")||""),this.setDefaultAppearance(O),Y.hasAppearance||(Y.hasAppearance=this._needAppearances&&Y.fieldValue!==void 0&&Y.fieldValue!==null);const et=(0,_.getInheritableProperty)({dict:H,key:"FT"});Y.fieldType=et instanceof t.Name?et.name:null;const nt=(0,_.getInheritableProperty)({dict:H,key:"DR"}),at=z.acroForm.get("DR"),Q=(lt=this.appearance)==null?void 0:lt.dict.get("Resources");this._fieldResources={localResources:nt,acroFormResources:at,appearanceResources:Q,mergedResources:t.Dict.merge({xref:V,dictArray:[nt,Q,at],mergeSubDicts:!0})},Y.fieldFlags=(0,_.getInheritableProperty)({dict:H,key:"Ff"}),(!Number.isInteger(Y.fieldFlags)||Y.fieldFlags<0)&&(Y.fieldFlags=0),Y.readOnly=this.hasFieldFlag(n.AnnotationFieldFlag.READONLY),Y.required=this.hasFieldFlag(n.AnnotationFieldFlag.REQUIRED),Y.hidden=this._hasFlag(Y.annotationFlags,n.AnnotationFlag.HIDDEN)||this._hasFlag(Y.annotationFlags,n.AnnotationFlag.NOVIEW)}_decodeFormValue(O){return Array.isArray(O)?O.filter(H=>typeof H=="string").map(H=>(0,n.stringToPDFString)(H)):O instanceof t.Name?(0,n.stringToPDFString)(O.name):typeof O=="string"?(0,n.stringToPDFString)(O):null}hasFieldFlag(O){return!!(this.data.fieldFlags&O)}_isViewable(O){return!this._hasFlag(O,n.AnnotationFlag.INVISIBLE)}mustBeViewed(O,H){return H?this.viewable:super.mustBeViewed(O,H)&&!this._hasFlag(this.flags,n.AnnotationFlag.NOVIEW)}getRotationMatrix(O){var Y;let H=(Y=O==null?void 0:O.get(this.data.id))==null?void 0:Y.rotation;if(H===void 0&&(H=this.rotation),H===0)return n.IDENTITY_MATRIX;const V=this.data.rect[2]-this.data.rect[0],z=this.data.rect[3]-this.data.rect[1];return(0,_.getRotationMatrix)(H,V,z)}getBorderAndBackgroundAppearances(O){var K;let H=(K=O==null?void 0:O.get(this.data.id))==null?void 0:K.rotation;if(H===void 0&&(H=this.rotation),!this.backgroundColor&&!this.borderColor)return"";const V=this.data.rect[2]-this.data.rect[0],z=this.data.rect[3]-this.data.rect[1],Y=H===0||H===180?`0 0 ${V} ${z} re`:`0 0 ${z} ${V} re`;let G="";return this.backgroundColor&&(G=`${(0,L.getPdfColor)(this.backgroundColor,!0)} ${Y} f `),this.borderColor&&(G+=`${this.borderStyle.width||1} w ${(0,L.getPdfColor)(this.borderColor,!1)} ${Y} S `),G}async getOperatorList(O,H,V,z,Y){if(z&&!(this instanceof E)&&!this.data.noHTML&&!this.data.hasOwnCanvas)return{opList:new p.OperatorList,separateForm:!0,separateCanvas:!1};if(!this._hasText)return super.getOperatorList(O,H,V,z,Y);const G=await this._getAppearance(O,H,V,Y);if(this.appearance&&G===null)return super.getOperatorList(O,H,V,z,Y);const K=new p.OperatorList;if(!this._defaultAppearance||G===null)return{opList:K,separateForm:!1,separateCanvas:!1};const et=!!(this.data.hasOwnCanvas&&V&n.RenderingIntentFlag.DISPLAY),nt=[0,0,this.data.rect[2]-this.data.rect[0],this.data.rect[3]-this.data.rect[1]],at=N(this.data.rect,nt,[1,0,0,1,0,0]);let Q;this.oc&&(Q=await O.parseMarkedContentProps(this.oc,null)),Q!==void 0&&K.addOp(n.OPS.beginMarkedContentProps,["OC",Q]),K.addOp(n.OPS.beginAnnotation,[this.data.id,this.data.rect,at,this.getRotationMatrix(Y),et]);const lt=new e.StringStream(G);return await O.getOperatorList({stream:lt,task:H,resources:this._fieldResources.mergedResources,operatorList:K}),K.addOp(n.OPS.endAnnotation,[]),Q!==void 0&&K.addOp(n.OPS.endMarkedContent,[]),{opList:K,separateForm:!1,separateCanvas:et}}_getMKDict(O){const H=new t.Dict(null);return O&&H.set("R",O),this.borderColor&&H.set("BC",l(this.borderColor)),this.backgroundColor&&H.set("BG",l(this.backgroundColor)),H.size>0?H:null}amendSavedDict(O,H){}async save(O,H,V){const z=V==null?void 0:V.get(this.data.id);let Y=z==null?void 0:z.value,G=z==null?void 0:z.rotation;if(Y===this.data.fieldValue||Y===void 0){if(!this._hasValueFromXFA&&G===void 0)return null;Y||(Y=this.data.fieldValue)}if(G===void 0&&!this._hasValueFromXFA&&Array.isArray(Y)&&Array.isArray(this.data.fieldValue)&&Y.length===this.data.fieldValue.length&&Y.every((Tt,xt)=>Tt===this.data.fieldValue[xt]))return null;G===void 0&&(G=this.rotation);let K=null;if(!this._needAppearances&&(K=await this._getAppearance(O,H,n.RenderingIntentFlag.SAVE,V),K===null))return null;let et=!1;K!=null&&K.needAppearances&&(et=!0,K=null);const{xref:nt}=O,at=nt.fetchIfRef(this.ref);if(!(at instanceof t.Dict))return null;const Q=new t.Dict(nt);for(const Tt of at.getKeys())Tt!=="AP"&&Q.set(Tt,at.getRaw(Tt));const lt={path:this.data.fieldName,value:Y},ut=Tt=>(0,_.isAscii)(Tt)?Tt:(0,_.stringToUTF16String)(Tt,!0);Q.set("V",Array.isArray(Y)?Y.map(ut):ut(Y)),this.amendSavedDict(V,Q);const pt=this._getMKDict(G);pt&&Q.set("MK",pt);const yt=[],Et=[{ref:this.ref,data:"",xfa:lt,needAppearances:et}];if(K!==null){const Tt=nt.getNewTemporaryRef(),xt=new t.Dict(nt);Q.set("AP",xt),xt.set("N",Tt);const wt=this._getSaveFieldResources(nt),St=new e.StringStream(K),Rt=St.dict=new t.Dict(nt);Rt.set("Subtype",t.Name.get("Form")),Rt.set("Resources",wt),Rt.set("BBox",[0,0,this.data.rect[2]-this.data.rect[0],this.data.rect[3]-this.data.rect[1]]);const Ct=this.getRotationMatrix(V);Ct!==n.IDENTITY_MATRIX&&Rt.set("Matrix",Ct),await(0,b.writeObject)(Tt,St,yt,nt),Et.push({ref:Tt,data:yt.join(""),xfa:null,needAppearances:!1}),yt.length=0}return Q.set("M",`D:${(0,n.getModificationDate)()}`),await(0,b.writeObject)(this.ref,Q,yt,nt),Et[0].data=yt.join(""),Et}async _getAppearance(O,H,V,z){if(this.hasFieldFlag(n.AnnotationFieldFlag.PASSWORD))return null;const Y=z==null?void 0:z.get(this.data.id);let G,K;if(Y&&(G=Y.formattedValue||Y.value,K=Y.rotation),K===void 0&&G===void 0&&!this._needAppearances&&(!this._hasValueFromXFA||this.appearance))return null;const et=this.getBorderAndBackgroundAppearances(z);if(G===void 0&&(G=this.data.fieldValue,!G))return`/Tx BMC q ${et}Q EMC`;if(Array.isArray(G)&&G.length===1&&(G=G[0]),(0,n.assert)(typeof G=="string","Expected `value` to be a string."),G=G.trim(),this.data.combo){const Gt=this.data.options.find(({exportValue:Zt})=>G===Zt);G=(Gt==null?void 0:Gt.displayValue)||G}if(G==="")return`/Tx BMC q ${et}Q EMC`;K===void 0&&(K=this.rotation);let nt,at=-1;this.data.multiLine?(nt=G.split(/\r\n?|\n/).map(Gt=>Gt.normalize("NFC")),at=nt.length):nt=[G.replace(/\r\n?|\n/,"").normalize("NFC")];let Q=this.data.rect[3]-this.data.rect[1],lt=this.data.rect[2]-this.data.rect[0];K!==90&&K!==270||([lt,Q]=[Q,lt]),this._defaultAppearance||(this.data.defaultAppearanceData=(0,L.parseDefaultAppearance)(this._defaultAppearance="/Helvetica 0 Tf 0 g"));let ut,pt,yt,Et=await R._getFontData(O,H,this.data.defaultAppearanceData,this._fieldResources.mergedResources);const Tt=[];let xt=!1;for(const Gt of nt){const Zt=Et.encodeString(Gt);Zt.length>1&&(xt=!0),Tt.push(Zt.join(""))}if(xt&&V&n.RenderingIntentFlag.SAVE)return{needAppearances:!0};if(xt&&this._isOffscreenCanvasSupported){const Gt=this.data.comb?"monospace":"sans-serif",Zt=new L.FakeUnicodeFont(O.xref,Gt),Ft=Zt.createFontResources(nt.join("")),Ut=Ft.getRaw("Font");if(this._fieldResources.mergedResources.has("Font")){const Yt=this._fieldResources.mergedResources.get("Font");for(const re of Ut.getKeys())Yt.set(re,Ut.getRaw(re))}else this._fieldResources.mergedResources.set("Font",Ut);const Vt=Zt.fontName.name;Et=await R._getFontData(O,H,{fontName:Vt,fontSize:0},Ft);for(let Yt=0,re=Tt.length;Yt2?`/Tx BMC q ${et}BT `+ut+` 1 0 0 1 ${(0,_.numberToString)(2)} ${(0,_.numberToString)(Ct)} Tm (${(0,_.escapeString)(Tt[0])}) Tj ET Q EMC`:`/Tx BMC q ${et}BT `+ut+` 1 0 0 1 0 0 Tm ${this._renderText(Tt[0],Et,pt,lt,Rt,{shift:0},2,Ct)} ET Q EMC`}static async _getFontData(O,H,V,z){const Y=new p.OperatorList,G={font:null,clone(){return this}},{fontName:K,fontSize:et}=V;return await O.handleSetFont(z,[K&&t.Name.get(K),et],null,Y,H,G,null),G.font}_getTextWidth(O,H){return H.charsToGlyphs(O).reduce((V,z)=>V+z.width,0)/1e3}_computeFontSize(O,H,V,z,Y){let{fontSize:G}=this.data.defaultAppearanceData,K=(G||12)*n.LINE_FACTOR,et=Math.round(O/K);if(!G){const nt=lt=>Math.floor(100*lt)/100;if(Y===-1){const lt=this._getTextWidth(V,z);G=nt(Math.min(O/n.LINE_FACTOR,lt>H?H/lt:1/0)),et=1}else{const lt=V.split(/\r\n?|\n/),ut=[];for(const yt of lt){const Et=z.encodeString(yt).join(""),Tt=z.charsToGlyphs(Et),xt=z.getCharPositions(Et);ut.push({line:Et,glyphs:Tt,positions:xt})}const pt=yt=>{let Et=0;for(const Tt of ut)if(Et+=this._splitLine(null,z,yt,H,Tt).length*yt,Et>O)return!0;return!1};for(et=Math.max(et,Y);K=O/et,G=nt(K/n.LINE_FACTOR),!!pt(G);)et++}const{fontName:at,fontColor:Q}=this.data.defaultAppearanceData;this._defaultAppearance=(0,L.createDefaultAppearance)({fontSize:G,fontName:at,fontColor:Q})}return[this._defaultAppearance,G,O/et]}_renderText(O,H,V,z,Y,G,K,et){let nt;Y===1?nt=(z-this._getTextWidth(O,H)*V)/2:Y===2?nt=z-this._getTextWidth(O,H)*V-K:nt=K;const at=(0,_.numberToString)(nt-G.shift);return G.shift=nt,`${at} ${et=(0,_.numberToString)(et)} Td (${(0,_.escapeString)(O)}) Tj`}_getSaveFieldResources(O){var G;const{localResources:H,appearanceResources:V,acroFormResources:z}=this._fieldResources,Y=(G=this.data.defaultAppearanceData)==null?void 0:G.fontName;if(!Y)return H||t.Dict.empty;for(const K of[H,V])if(K instanceof t.Dict){const et=K.get("Font");if(et instanceof t.Dict&&et.has(Y))return K}if(z instanceof t.Dict){const K=z.get("Font");if(K instanceof t.Dict&&K.has(Y)){const et=new t.Dict(O);et.set(Y,K.getRaw(Y));const nt=new t.Dict(O);return nt.set("Font",et),t.Dict.merge({xref:O,dictArray:[nt,H],mergeSubDicts:!0})}}return H||t.Dict.empty}getFieldObject(){return null}}class o extends R{constructor(O){super(O),this.data.hasOwnCanvas=this.data.readOnly&&!this.data.noHTML,this._hasText=!0;const H=O.dict;typeof this.data.fieldValue!="string"&&(this.data.fieldValue="");let V=(0,_.getInheritableProperty)({dict:H,key:"Q"});(!Number.isInteger(V)||V<0||V>2)&&(V=null),this.data.textAlignment=V;let z=(0,_.getInheritableProperty)({dict:H,key:"MaxLen"});(!Number.isInteger(z)||z<0)&&(z=0),this.data.maxLen=z,this.data.multiLine=this.hasFieldFlag(n.AnnotationFieldFlag.MULTILINE),this.data.comb=this.hasFieldFlag(n.AnnotationFieldFlag.COMB)&&!this.hasFieldFlag(n.AnnotationFieldFlag.MULTILINE)&&!this.hasFieldFlag(n.AnnotationFieldFlag.PASSWORD)&&!this.hasFieldFlag(n.AnnotationFieldFlag.FILESELECT)&&this.data.maxLen!==0,this.data.doNotScroll=this.hasFieldFlag(n.AnnotationFieldFlag.DONOTSCROLL)}get hasTextContent(){return!!this.appearance&&!this._needAppearances}_getCombAppearance(O,H,V,z,Y,G,K,et,nt,at,Q){const lt=Y/this.data.maxLen,ut=this.getBorderAndBackgroundAppearances(Q),pt=[],yt=H.getCharPositions(V);for(const[Tt,xt]of yt)pt.push(`(${(0,_.escapeString)(V.substring(Tt,xt))}) Tj`);const Et=pt.join(` ${(0,_.numberToString)(lt)} 0 Td `);return`/Tx BMC q ${ut}BT `+O+` 1 0 0 1 ${(0,_.numberToString)(K)} ${(0,_.numberToString)(et+nt)} Tm ${Et} ET Q EMC`}_getMultilineAppearance(O,H,V,z,Y,G,K,et,nt,at,Q,lt){const ut=[],pt=Y-2*et,yt={shift:0};for(let xt=0,wt=H.length;xtz?(nt.push(O.substring(ut,Tt)),ut=Tt,pt=St,at=-1,lt=-1):(pt+=St,at=Tt,Q=xt,lt=yt):pt+St>z?at!==-1?(nt.push(O.substring(ut,Q)),ut=Q,yt=lt+1,at=-1,pt=0):(nt.push(O.substring(ut,Tt)),ut=Tt,pt=St):pt+=St}return utat!=="Off");G.length=0,G.push("Off",nt)}G.includes(this.data.fieldValue)||(this.data.fieldValue="Off"),this.data.exportValue=G[1];const K=V.get(this.data.exportValue);this.checkedAppearance=K instanceof a.BaseStream?K:null;const et=V.get("Off");this.uncheckedAppearance=et instanceof a.BaseStream?et:null,this.checkedAppearance?this._streams.push(this.checkedAppearance):this._getDefaultCheckedAppearance(O,"check"),this.uncheckedAppearance&&this._streams.push(this.uncheckedAppearance),this._fallbackFontDict=this.fallbackFontDict,this.data.defaultFieldValue===null&&(this.data.defaultFieldValue="Off")}_processRadioButton(O){this.data.fieldValue=this.data.buttonValue=null;const H=O.dict.get("Parent");if(H instanceof t.Dict){this.parent=O.dict.getRaw("Parent");const K=H.get("V");K instanceof t.Name&&(this.data.fieldValue=this._decodeFormValue(K))}const V=O.dict.get("AP");if(!(V instanceof t.Dict))return;const z=V.get("N");if(!(z instanceof t.Dict))return;for(const K of z.getKeys())if(K!=="Off"){this.data.buttonValue=this._decodeFormValue(K);break}const Y=z.get(this.data.buttonValue);this.checkedAppearance=Y instanceof a.BaseStream?Y:null;const G=z.get("Off");this.uncheckedAppearance=G instanceof a.BaseStream?G:null,this.checkedAppearance?this._streams.push(this.checkedAppearance):this._getDefaultCheckedAppearance(O,"disc"),this.uncheckedAppearance&&this._streams.push(this.uncheckedAppearance),this._fallbackFontDict=this.fallbackFontDict,this.data.defaultFieldValue===null&&(this.data.defaultFieldValue="Off")}_processPushButton(O){const{dict:H,annotationGlobals:V}=O;H.has("A")||H.has("AA")||this.data.alternativeText?(this.data.isTooltipOnly=!H.has("A")&&!H.has("AA"),A.Catalog.parseDestDictionary({destDict:H,resultObj:this.data,docBaseUrl:V.baseUrl,docAttachments:V.attachments})):(0,n.warn)("Push buttons without action dictionaries are not supported")}getFieldObject(){let O,H="button";return this.data.checkBox?(H="checkbox",O=this.data.exportValue):this.data.radioButton&&(H="radiobutton",O=this.data.buttonValue),{id:this.data.id,value:this.data.fieldValue||"Off",defaultValue:this.data.defaultFieldValue,exportValues:O,editable:!this.data.readOnly,name:this.data.fieldName,rect:this.data.rect,hidden:this.data.hidden,actions:this.data.actions,page:this.data.pageIndex,strokeColor:this.data.borderColor,fillColor:this.data.backgroundColor,rotation:this.rotation,type:H}}get fallbackFontDict(){const O=new t.Dict;return O.set("BaseFont",t.Name.get("ZapfDingbats")),O.set("Type",t.Name.get("FallbackType")),O.set("Subtype",t.Name.get("FallbackType")),O.set("Encoding",t.Name.get("ZapfDingbatsEncoding")),(0,n.shadow)(this,"fallbackFontDict",O)}}class x extends R{constructor(O){super(O);const{dict:H,xref:V}=O;this.indices=H.getArray("I"),this.hasIndices=Array.isArray(this.indices)&&this.indices.length>0,this.data.options=[];const z=(0,_.getInheritableProperty)({dict:H,key:"Opt"});if(Array.isArray(z))for(let Y=0,G=z.length;Y=0&&G0?this.data.fieldValue[0]:null;return{id:this.data.id,value:H,defaultValue:this.data.defaultFieldValue,editable:!this.data.readOnly,name:this.data.fieldName,rect:this.data.rect,numItems:this.data.fieldValue.length,multipleSelection:this.data.multiSelect,hidden:this.data.hidden,actions:this.data.actions,items:this.data.options,page:this.data.pageIndex,strokeColor:this.data.borderColor,fillColor:this.data.backgroundColor,rotation:this.rotation,type:O}}amendSavedDict(O,H){var G;if(!this.hasIndices)return;let V=(G=O==null?void 0:O.get(this.data.id))==null?void 0:G.value;Array.isArray(V)||(V=[V]);const z=[],{options:Y}=this.data;for(let K=0,et=0,nt=Y.length;KZt&&(Zt=Ut,Gt=Ft)}[ut,pt]=this._computeFontSize(Ct,nt-4,Gt,lt,-1)}const yt=pt*n.LINE_FACTOR,Et=(yt-pt)/2,Tt=Math.floor(et/yt);let xt=0;if(Q.length>0){const Ct=Math.min(...Q),Gt=Math.max(...Q);xt=Math.max(0,Gt-Tt+1),xt>Ct&&(xt=Ct)}const wt=Math.min(xt+Tt+1,at),St=["/Tx BMC q",`1 1 ${nt} ${et} re W n`];if(Q.length){St.push("0.600006 0.756866 0.854904 rg");for(const Ct of Q)xt<=Ct&&Ct1)return null;bt=Pt.join(""),Zt.push(bt);let It=0;const Nt=pt.charsToGlyphs(bt);for(const Kt of Nt)It+=Kt.width*Ct;Gt=Math.max(Gt,It)}let Ft=1;Gt>wt&&(Ft=wt/Gt);let Ut=1;const Vt=n.LINE_FACTOR*et,Wt=(n.LINE_FACTOR-n.LINE_DESCENT_FACTOR)*et,Yt=Vt*Rt.length;Yt>St&&(Ut=St/Yt);const re=et*Math.min(Ft,Ut);let Jt,Bt,Xt;switch(at){case 0:Xt=[1,0,0,1],Bt=[nt[0],nt[1],wt,St],Jt=[nt[0],nt[3]-Wt];break;case 90:Xt=[0,1,-1,0],Bt=[nt[1],-nt[2],wt,St],Jt=[nt[1],-nt[0]-Wt];break;case 180:Xt=[-1,0,0,-1],Bt=[-nt[2],-nt[3],wt,St],Jt=[-nt[2],-nt[1]-Wt];break;case 270:Xt=[0,-1,1,0],Bt=[-nt[3],nt[0],wt,St],Jt=[-nt[3],nt[2]-Wt]}const jt=["q",`${Xt.join(" ")} 0 0 cm`,`${Bt.join(" ")} re W n`,"BT",`${(0,L.getPdfColor)(K,!0)}`,`0 Tc /Helv ${(0,_.numberToString)(re)} Tf`];jt.push(`${Jt.join(" ")} Td (${(0,_.escapeString)(Zt[0])}) Tj`);const mt=(0,_.numberToString)(Vt);for(let bt=1,Pt=Zt.length;bt(ut.push(`${z[0]} ${z[1]} m`,`${z[2]} ${z[3]} l`,"S"),[pt[0].x-at,pt[1].x+at,pt[3].y-at,pt[1].y+at])})}}}class c extends P{constructor(O){super(O);const{dict:H,xref:V}=O;if(this.data.annotationType=n.AnnotationType.SQUARE,this.data.hasOwnCanvas=this.data.noRotate,!this.appearance){const z=this.color?l(this.color):[0,0,0],Y=H.get("CA"),G=u(H.getArray("IC"),null),K=G?l(G):null,et=K?Y:null;if(this.borderStyle.width===0&&!K)return;this._setDefaultAppearance({xref:V,extra:`${this.borderStyle.width} w`,strokeColor:z,fillColor:K,strokeAlpha:Y,fillAlpha:et,pointsCallback:(nt,at)=>{const Q=at[2].x+this.borderStyle.width/2,lt=at[2].y+this.borderStyle.width/2,ut=at[3].x-at[2].x-this.borderStyle.width,pt=at[1].y-at[3].y-this.borderStyle.width;return nt.push(`${Q} ${lt} ${ut} ${pt} re`),K?nt.push("B"):nt.push("S"),[at[0].x,at[1].x,at[3].y,at[1].y]}})}}}class S extends P{constructor(O){super(O);const{dict:H,xref:V}=O;if(this.data.annotationType=n.AnnotationType.CIRCLE,!this.appearance){const z=this.color?l(this.color):[0,0,0],Y=H.get("CA"),G=u(H.getArray("IC"),null),K=G?l(G):null,et=K?Y:null;if(this.borderStyle.width===0&&!K)return;const nt=4/3*Math.tan(Math.PI/8);this._setDefaultAppearance({xref:V,extra:`${this.borderStyle.width} w`,strokeColor:z,fillColor:K,strokeAlpha:Y,fillAlpha:et,pointsCallback:(at,Q)=>{const lt=Q[0].x+this.borderStyle.width/2,ut=Q[0].y-this.borderStyle.width/2,pt=Q[3].x-this.borderStyle.width/2,yt=Q[3].y+this.borderStyle.width/2,Et=lt+(pt-lt)/2,Tt=ut+(yt-ut)/2,xt=(pt-lt)/2*nt,wt=(yt-ut)/2*nt;return at.push(`${Et} ${yt} m`,`${Et+xt} ${yt} ${pt} ${Tt+wt} ${pt} ${Tt} c`,`${pt} ${Tt-wt} ${Et+xt} ${ut} ${Et} ${ut} c`,`${Et-xt} ${ut} ${lt} ${Tt-wt} ${lt} ${Tt} c`,`${lt} ${Tt+wt} ${Et-xt} ${yt} ${Et} ${yt} c`,"h"),K?at.push("B"):at.push("S"),[Q[0].x,Q[1].x,Q[3].y,Q[1].y]}})}}}class h extends P{constructor(O){super(O);const{dict:H,xref:V}=O;this.data.annotationType=n.AnnotationType.POLYLINE,this.data.hasOwnCanvas=this.data.noRotate,this.data.vertices=[],this instanceof m||(this.setLineEndings(H.getArray("LE")),this.data.lineEndings=this.lineEndings);const z=H.getArray("Vertices");if(Array.isArray(z)){for(let Y=0,G=z.length;Y{const lt=this.data.vertices;for(let ut=0,pt=lt.length;ut{for(const lt of this.data.inkLists){for(let ut=0,pt=lt.length;utpt.points)),Q.set("F",4),Q.set("Rotate",nt);const lt=new t.Dict(H);Q.set("BS",lt),lt.set("W",at),Q.set("C",Array.from(Y,pt=>pt/255)),Q.set("CA",G);const ut=new t.Dict(H);return Q.set("AP",ut),V?ut.set("N",V):ut.set("N",z),Q}static async createNewAppearanceStream(O,H,V){const{color:z,rect:Y,paths:G,thickness:K,opacity:et}=O,nt=[`${K} w 1 J 1 j`,`${(0,L.getPdfColor)(z,!1)}`];et!==1&&nt.push("/R0 gs");const at=[];for(const{bezier:pt}of G){at.length=0,at.push(`${(0,_.numberToString)(pt[0])} ${(0,_.numberToString)(pt[1])} m`);for(let yt=2,Et=pt.length;yt(et.push(`${nt[0].x} ${nt[0].y} m`,`${nt[1].x} ${nt[1].y} l`,`${nt[3].x} ${nt[3].y} l`,`${nt[2].x} ${nt[2].y} l`,"f"),[nt[0].x,nt[1].x,nt[3].y,nt[1].y])})}}else this.data.popupRef=null}}class tt extends P{constructor(O){super(O);const{dict:H,xref:V}=O;if(this.data.annotationType=n.AnnotationType.UNDERLINE,this.data.quadPoints=y(H,null)){if(!this.appearance){const z=this.color?l(this.color):[0,0,0],Y=H.get("CA");this._setDefaultAppearance({xref:V,extra:"[] 0 d 0.571 w",strokeColor:z,strokeAlpha:Y,pointsCallback:(G,K)=>(G.push(`${K[2].x} ${K[2].y+1.3} m`,`${K[3].x} ${K[3].y+1.3} l`,"S"),[K[0].x,K[1].x,K[3].y,K[1].y])})}}else this.data.popupRef=null}}class it extends P{constructor(O){super(O);const{dict:H,xref:V}=O;if(this.data.annotationType=n.AnnotationType.SQUIGGLY,this.data.quadPoints=y(H,null)){if(!this.appearance){const z=this.color?l(this.color):[0,0,0],Y=H.get("CA");this._setDefaultAppearance({xref:V,extra:"[] 0 d 1 w",strokeColor:z,strokeAlpha:Y,pointsCallback:(G,K)=>{const et=(K[0].y-K[2].y)/6;let nt=et,at=K[2].x;const Q=K[2].y,lt=K[3].x;G.push(`${at} ${Q+nt} m`);do at+=2,nt=nt===0?et:0,G.push(`${at} ${Q+nt} l`);while(at(G.push((K[0].x+K[2].x)/2+" "+(K[0].y+K[2].y)/2+" m",(K[1].x+K[3].x)/2+" "+(K[1].y+K[3].y)/2+" l","S"),[K[0].x,K[1].x,K[3].y,K[1].y])})}}else this.data.popupRef=null}}class X extends P{constructor(O){super(O),this.data.annotationType=n.AnnotationType.STAMP,this.data.hasOwnCanvas=this.data.noRotate}static async createImage(O,H){const{width:V,height:z}=O,Y=new OffscreenCanvas(V,z),G=Y.getContext("2d",{alpha:!0});G.drawImage(O,0,0);const K=G.getImageData(0,0,V,z).data,et=new Uint32Array(K.buffer),nt=et.some(n.FeatureTest.isLittleEndian?yt=>yt>>>24!=255:yt=>(255&yt)!=255);nt&&(G.fillStyle="white",G.fillRect(0,0,V,z),G.drawImage(O,0,0));const at=Y.convertToBlob({type:"image/jpeg",quality:1}).then(yt=>yt.arrayBuffer()),Q=t.Name.get("XObject"),lt=t.Name.get("Image"),ut=new t.Dict(H);ut.set("Type",Q),ut.set("Subtype",lt),ut.set("BitsPerComponent",8),ut.set("ColorSpace",t.Name.get("DeviceRGB")),ut.set("Filter",t.Name.get("DCTDecode")),ut.set("BBox",[0,0,V,z]),ut.set("Width",V),ut.set("Height",z);let pt=null;if(nt){const yt=new Uint8Array(et.length);if(n.FeatureTest.isLittleEndian)for(let Tt=0,xt=et.length;Tt>>24;else for(let Tt=0,xt=et.length;Tt=0&&G<=1?G:null}}},(vt,M,Z)=>{Object.defineProperty(M,"__esModule",{value:!0}),M.FakeUnicodeFont=void 0,M.createDefaultAppearance=function({fontSize:b,fontName:F,fontColor:u}){return`/${(0,_.escapePDFName)(F)} ${b} Tf ${i(u,!0)}`},M.getPdfColor=i,M.parseAppearanceStream=function(b,F,u){return new d(b,F,u).parse()},M.parseDefaultAppearance=function(b){return new T(b).parse()};var n=Z(4),_=Z(3),L=Z(2),t=Z(12),e=Z(13),a=Z(59),v=Z(57),A=Z(8);class T extends e.EvaluatorPreprocessor{constructor(b){super(new A.StringStream(b))}parse(){const b={fn:0,args:[]},F={fontSize:0,fontName:"",fontColor:new Uint8ClampedArray(3)};try{for(;b.args.length=0,!!this.read(b);){if(this.savedStatesDepth!==0)continue;const{fn:u,args:l}=b;switch(0|u){case L.OPS.setFont:const[y,N]=l;y instanceof n.Name&&(F.fontName=y.name),typeof N=="number"&&N>0&&(F.fontSize=N);break;case L.OPS.setFillRGBColor:t.ColorSpace.singletons.rgb.getRgbItem(l,0,F.fontColor,0);break;case L.OPS.setFillGray:t.ColorSpace.singletons.gray.getRgbItem(l,0,F.fontColor,0);break;case L.OPS.setFillCMYKColor:t.ColorSpace.singletons.cmyk.getRgbItem(l,0,F.fontColor,0)}}}catch(u){(0,L.warn)(`parseDefaultAppearance - ignoring errors: "${u}".`)}return F}}class d extends e.EvaluatorPreprocessor{constructor(b,F,u){var l;super(b),this.stream=b,this.evaluatorOptions=F,this.xref=u,this.resources=(l=b.dict)==null?void 0:l.get("Resources")}parse(){const b={fn:0,args:[]};let F={scaleFactor:1,fontSize:0,fontName:"",fontColor:new Uint8ClampedArray(3),fillColorSpace:t.ColorSpace.singletons.gray},u=!1;const l=[];try{for(;b.args.length=0,!(u||!this.read(b));){const{fn:y,args:N}=b;switch(0|y){case L.OPS.save:l.push({scaleFactor:F.scaleFactor,fontSize:F.fontSize,fontName:F.fontName,fontColor:F.fontColor.slice(),fillColorSpace:F.fillColorSpace});break;case L.OPS.restore:F=l.pop()||F;break;case L.OPS.setTextMatrix:F.scaleFactor*=Math.hypot(N[0],N[1]);break;case L.OPS.setFont:const[U,$]=N;U instanceof n.Name&&(F.fontName=U.name),typeof $=="number"&&$>0&&(F.fontSize=$*F.scaleFactor);break;case L.OPS.setFillColorSpace:F.fillColorSpace=t.ColorSpace.parse({cs:N[0],xref:this.xref,resources:this.resources,pdfFunctionFactory:this._pdfFunctionFactory,localColorSpaceCache:this._localColorSpaceCache});break;case L.OPS.setFillColor:F.fillColorSpace.getRgbItem(N,0,F.fontColor,0);break;case L.OPS.setFillRGBColor:t.ColorSpace.singletons.rgb.getRgbItem(N,0,F.fontColor,0);break;case L.OPS.setFillGray:t.ColorSpace.singletons.gray.getRgbItem(N,0,F.fontColor,0);break;case L.OPS.setFillCMYKColor:t.ColorSpace.singletons.cmyk.getRgbItem(N,0,F.fontColor,0);break;case L.OPS.showText:case L.OPS.showSpacedText:case L.OPS.nextLineShowText:case L.OPS.nextLineSetSpacingShowText:u=!0}}}catch(y){(0,L.warn)(`parseAppearanceStream - ignoring errors: "${y}".`)}return this.stream.reset(),delete F.scaleFactor,delete F.fillColorSpace,F}get _localColorSpaceCache(){return(0,L.shadow)(this,"_localColorSpaceCache",new a.LocalColorSpaceCache)}get _pdfFunctionFactory(){const b=new v.PDFFunctionFactory({xref:this.xref,isEvalSupported:this.evaluatorOptions.isEvalSupported});return(0,L.shadow)(this,"_pdfFunctionFactory",b)}}function i(p,b){if(p[0]===p[1]&&p[1]===p[2]){const F=p[0]/255;return`${(0,_.numberToString)(F)} ${b?"g":"G"}`}return Array.from(p,F=>(0,_.numberToString)(F/255)).join(" ")+" "+(b?"rg":"RG")}class C{constructor(b,F){this.xref=b,this.widths=null,this.firstChar=1/0,this.lastChar=-1/0,this.fontFamily=F;const u=new OffscreenCanvas(1,1);this.ctxMeasure=u.getContext("2d"),C._fontNameId||(C._fontNameId=1),this.fontName=n.Name.get(`InvalidPDFjsFont_${F}_${C._fontNameId++}`)}get toUnicodeRef(){if(!C._toUnicodeRef){const b=`/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<< /Registry (Adobe)
/Ordering (UCS) /Supplement 0 >> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000>
endcodespacerange
1 beginbfrange
<0000> <0000>
endbfrange
endcmap CMapName currentdict /CMap defineresource pop end end`,F=C.toUnicodeStream=new A.StringStream(b),u=new n.Dict(this.xref);F.dict=u,u.set("Length",b.length),C._toUnicodeRef=this.xref.getNewPersistentRef(F)}return C._toUnicodeRef}get fontDescriptorRef(){if(!C._fontDescriptorRef){const b=new n.Dict(this.xref);b.set("Type",n.Name.get("FontDescriptor")),b.set("FontName",this.fontName),b.set("FontFamily","MyriadPro Regular"),b.set("FontBBox",[0,0,0,0]),b.set("FontStretch",n.Name.get("Normal")),b.set("FontWeight",400),b.set("ItalicAngle",0),C._fontDescriptorRef=this.xref.getNewPersistentRef(b)}return C._fontDescriptorRef}get descendantFontRef(){const b=new n.Dict(this.xref);b.set("BaseFont",this.fontName),b.set("Type",n.Name.get("Font")),b.set("Subtype",n.Name.get("CIDFontType0")),b.set("CIDToGIDMap",n.Name.get("Identity")),b.set("FirstChar",this.firstChar),b.set("LastChar",this.lastChar),b.set("FontDescriptor",this.fontDescriptorRef),b.set("DW",1e3);const F=[],u=[...this.widths.entries()].sort();let l=null,y=null;for(const[U,$]of u)l?U===l+y.length?y.push($):(F.push(l,y),l=U,y=[$]):(l=U,y=[$]);l&&F.push(l,y),b.set("W",F);const N=new n.Dict(this.xref);return N.set("Ordering","Identity"),N.set("Registry","Adobe"),N.set("Supplement",0),b.set("CIDSystemInfo",N),this.xref.getNewPersistentRef(b)}get baseFontRef(){const b=new n.Dict(this.xref);return b.set("BaseFont",this.fontName),b.set("Type",n.Name.get("Font")),b.set("Subtype",n.Name.get("Type0")),b.set("Encoding",n.Name.get("Identity-H")),b.set("DescendantFonts",[this.descendantFontRef]),b.set("ToUnicode",this.toUnicodeRef),this.xref.getNewPersistentRef(b)}get resources(){const b=new n.Dict(this.xref),F=new n.Dict(this.xref);return F.set(this.fontName.name,this.baseFontRef),b.set("Font",F),b}_createContext(){return this.widths=new Map,this.ctxMeasure.font=`1000px ${this.fontFamily}`,this.ctxMeasure}createFontResources(b){const F=this._createContext();for(const u of b.split(/\r\n?|\n/))for(const l of u.split("")){const y=l.charCodeAt(0);if(this.widths.has(y))continue;const N=F.measureText(l),U=Math.ceil(N.width);this.widths.set(y,U),this.firstChar=Math.min(y,this.firstChar),this.lastChar=Math.max(y,this.lastChar)}return this.resources}createAppearance(b,F,u,l,y,N){const U=this._createContext(),$=[];let P=-1/0;for(const it of b.split(/\r\n?|\n/)){$.push(it);const st=U.measureText(it).width;P=Math.max(P,st);for(const X of it.split("")){const J=X.charCodeAt(0);let j=this.widths.get(J);if(j===void 0){const O=U.measureText(X);j=Math.ceil(O.width),this.widths.set(J,j),this.firstChar=Math.min(J,this.firstChar),this.lastChar=Math.max(J,this.lastChar)}}}P*=l/1e3;const[R,o,g,x]=F;let E=g-R,D=x-o;u%180!=0&&([E,D]=[D,E]);let q=1;P>E&&(q=E/P);let W=1;const w=L.LINE_FACTOR*l,s=L.LINE_DESCENT_FACTOR*l,c=w*$.length;c>D&&(W=D/c);const S=l*Math.min(q,W),h=["q",`0 0 ${(0,_.numberToString)(E)} ${(0,_.numberToString)(D)} re W n`,"BT",`1 0 0 1 0 ${(0,_.numberToString)(D+s)} Tm 0 Tc ${i(y,!0)}`,`/${this.fontName.name} ${(0,_.numberToString)(S)} Tf`],{resources:m}=this;if((N=typeof N=="number"&&N>=0&&N<=1?N:1)!==1){h.push("/R0 gs");const it=new n.Dict(this.xref),st=new n.Dict(this.xref);st.set("ca",N),st.set("CA",N),st.set("Type",n.Name.get("ExtGState")),it.set("R0",st),m.set("ExtGState",it)}const k=(0,_.numberToString)(w);for(const it of $)h.push(`0 -${k} Td <${(0,_.stringToUTF16HexString)(it)}> Tj`);h.push("ET","Q");const I=h.join(`
`),B=new n.Dict(this.xref);if(B.set("Subtype",n.Name.get("Form")),B.set("Type",n.Name.get("XObject")),B.set("BBox",[0,0,E,D]),B.set("Length",I.length),B.set("Resources",m),u){const it=(0,_.getRotationMatrix)(u,E,D);B.set("Matrix",it)}const tt=new A.StringStream(I);return tt.dict=B,tt}}M.FakeUnicodeFont=C},(vt,M,Z)=>{var F,Wi,l,Vi,N,U,$,P,R,o,g,x,E,Je,q,Rr,w,Dr,c,Mn,h,Ze,k,Qe,B,Lr,it,Nr,X,Br,j,Ki,V,Rn,Y,Dn,K,Yi;Object.defineProperty(M,"__esModule",{value:!0}),M.ColorSpace=void 0;var n=Z(2),_=Z(4),L=Z(5),t=Z(3);class e{constructor(at,Q){this.constructor===e&&(0,n.unreachable)("Cannot initialize ColorSpace."),this.name=at,this.numComps=Q}getRgb(at,Q){const lt=new Uint8ClampedArray(3);return this.getRgbItem(at,Q,lt,0),lt}getRgbItem(at,Q,lt,ut){(0,n.unreachable)("Should not call ColorSpace.getRgbItem")}getRgbBuffer(at,Q,lt,ut,pt,yt,Et){(0,n.unreachable)("Should not call ColorSpace.getRgbBuffer")}getOutputLength(at,Q){(0,n.unreachable)("Should not call ColorSpace.getOutputLength")}isPassthrough(at){return!1}isDefaultDecode(at,Q){return e.isDefaultDecode(at,this.numComps)}fillRgb(at,Q,lt,ut,pt,yt,Et,Tt,xt){const wt=Q*lt;let St=null;const Rt=1<Rt&&this.name!=="DeviceGray"&&this.name!=="DeviceRGB"){const Gt=Et<=8?new Uint8Array(Rt):new Uint16Array(Rt);for(let Ft=0;Ft