@sandeepmvn/react-pdf-annotator-v2 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,5 +48,5 @@ end
48
48
  end`},rl=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return"<"+e.join("")+">"},bi=function(e){return Jr(e,4)},hd=function(e){if(Tu(e))return bi(e);if(Pu(e)){var t=_o(e),r=$o(e);return""+bi(t)+bi(r)}var n=qn(e),i="0x"+n+" is not a valid UTF-8 or UTF-16 codepoint.";throw new Error(i)},dd=function(e){var t=0,r=function(n){t|=1<<n-1};return e.fixedPitch&&r(1),e.serif&&r(2),r(3),e.script&&r(4),e.nonsymbolic&&r(6),e.italic&&r(7),e.allCap&&r(17),e.smallCap&&r(18),e.forceBold&&r(19),t},vd=function(e){var t=e["OS/2"]?e["OS/2"].sFamilyClass:0,r=dd({fixedPitch:e.post.isFixedPitch,serif:1<=t&&t<=7,script:t===10,italic:e.head.macStyle.italic});return r},pe=function(e){M(t,e);function t(r){var n=e.call(this)||this;return n.value=r,n}return t.prototype.asBytes=function(){for(var r=[],n="",i=!1,a=function(h){h!==void 0&&r.push(h),i=!1},o=0,s=this.value.length;o<s;o++){var l=this.value[o],c=Z(l),u=this.value[o+1];i?c===y.Newline||c===y.CarriageReturn?a():c===y.n?a(y.Newline):c===y.r?a(y.CarriageReturn):c===y.t?a(y.Tab):c===y.b?a(y.Backspace):c===y.f?a(y.FormFeed):c===y.LeftParen?a(y.LeftParen):c===y.RightParen?a(y.RightParen):c===y.Backspace?a(y.BackSlash):c>=y.Zero&&c<=y.Seven?(n+=l,(n.length===3||!(u>="0"&&u<="7"))&&(a(parseInt(n,8)),n="")):a(c):c===y.BackSlash?i=!0:a(c)}return new Uint8Array(r)},t.prototype.decodeText=function(){var r=this.asBytes();return as(r)?es(r):Wc(r)},t.prototype.decodeDate=function(){var r=this.decodeText(),n=Jo(r);if(!n)throw new qc(r);return n},t.prototype.asString=function(){return this.value},t.prototype.clone=function(){return t.of(this.value)},t.prototype.toString=function(){return"("+this.value+")"},t.prototype.sizeInBytes=function(){return this.value.length+2},t.prototype.copyBytesInto=function(r,n){return r[n++]=y.LeftParen,n+=Ne(this.value,r,n),r[n++]=y.RightParen,this.value.length+2},t.of=function(r){return new t(r)},t.fromDate=function(r){var n=ft(String(r.getUTCFullYear()),4,"0"),i=ft(String(r.getUTCMonth()+1),2,"0"),a=ft(String(r.getUTCDate()),2,"0"),o=ft(String(r.getUTCHours()),2,"0"),s=ft(String(r.getUTCMinutes()),2,"0"),l=ft(String(r.getUTCSeconds()),2,"0");return new t("D:"+n+i+a+o+s+l+"Z")},t}(Le),Ua=function(){function e(t,r,n,i){var a=this;this.allGlyphsInFontSortedById=function(){for(var o=new Array(a.font.characterSet.length),s=0,l=o.length;s<l;s++){var c=a.font.characterSet[s];o[s]=a.font.glyphForCodePoint(c)}return xu(o.sort(mu),function(u){return u.id})},this.font=t,this.scale=1e3/this.font.unitsPerEm,this.fontData=r,this.fontName=this.font.postscriptName||"Font",this.customName=n,this.fontFeatures=i,this.baseFontName="",this.glyphCache=Ot.populatedBy(this.allGlyphsInFontSortedById)}return e.for=function(t,r,n,i){return _(this,void 0,void 0,function(){var a;return $(this,function(o){switch(o.label){case 0:return[4,t.create(r)];case 1:return a=o.sent(),[2,new e(a,r,n,i)]}})})},e.prototype.encodeText=function(t){for(var r=this.font.layout(t,this.fontFeatures).glyphs,n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=Jr(r[i].id,4);return G.of(n.join(""))},e.prototype.widthOfTextAtSize=function(t,r){for(var n=this.font.layout(t,this.fontFeatures).glyphs,i=0,a=0,o=n.length;a<o;a++)i+=n[a].advanceWidth*this.scale;var s=r/1e3;return i*s},e.prototype.heightOfFontAtSize=function(t,r){r===void 0&&(r={});var n=r.descender,i=n===void 0?!0:n,a=this.font,o=a.ascent,s=a.descent,l=a.bbox,c=(o||l.maxY)*this.scale,u=(s||l.minY)*this.scale,h=c-u;return i||(h-=Math.abs(s)||0),h/1e3*t},e.prototype.sizeOfFontAtHeight=function(t){var r=this.font,n=r.ascent,i=r.descent,a=r.bbox,o=(n||a.maxY)*this.scale,s=(i||a.minY)*this.scale;return 1e3*t/(o-s)},e.prototype.embedIntoContext=function(t,r){return this.baseFontName=this.customName||t.addRandomSuffix(this.fontName),this.embedFontDict(t,r)},e.prototype.embedFontDict=function(t,r){return _(this,void 0,void 0,function(){var n,i,a;return $(this,function(o){switch(o.label){case 0:return[4,this.embedCIDFontDict(t)];case 1:return n=o.sent(),i=this.embedUnicodeCmap(t),a=t.obj({Type:"Font",Subtype:"Type0",BaseFont:this.baseFontName,Encoding:"Identity-H",DescendantFonts:[n],ToUnicode:i}),r?(t.assign(r,a),[2,r]):[2,t.register(a)]}})})},e.prototype.isCFF=function(){return this.font.cff},e.prototype.embedCIDFontDict=function(t){return _(this,void 0,void 0,function(){var r,n;return $(this,function(i){switch(i.label){case 0:return[4,this.embedFontDescriptor(t)];case 1:return r=i.sent(),n=t.obj({Type:"Font",Subtype:this.isCFF()?"CIDFontType0":"CIDFontType2",CIDToGIDMap:"Identity",BaseFont:this.baseFontName,CIDSystemInfo:{Registry:pe.of("Adobe"),Ordering:pe.of("Identity"),Supplement:0},FontDescriptor:r,W:this.computeWidths()}),[2,t.register(n)]}})})},e.prototype.embedFontDescriptor=function(t){return _(this,void 0,void 0,function(){var r,n,i,a,o,s,l,c,u,h,f,d,v,p,m;return $(this,function(b){switch(b.label){case 0:return[4,this.embedFontStream(t)];case 1:return r=b.sent(),n=this.scale,i=this.font,a=i.italicAngle,o=i.ascent,s=i.descent,l=i.capHeight,c=i.xHeight,u=this.font.bbox,h=u.minX,f=u.minY,d=u.maxX,v=u.maxY,p=t.obj((m={Type:"FontDescriptor",FontName:this.baseFontName,Flags:vd(this.font),FontBBox:[h*n,f*n,d*n,v*n],ItalicAngle:a,Ascent:o*n,Descent:s*n,CapHeight:(l||o)*n,XHeight:(c||0)*n,StemV:0},m[this.isCFF()?"FontFile3":"FontFile2"]=r,m)),[2,t.register(p)]}})})},e.prototype.serializeFont=function(){return _(this,void 0,void 0,function(){return $(this,function(t){return[2,this.fontData]})})},e.prototype.embedFontStream=function(t){return _(this,void 0,void 0,function(){var r,n,i;return $(this,function(a){switch(a.label){case 0:return i=(n=t).flateStream,[4,this.serializeFont()];case 1:return r=i.apply(n,[a.sent(),{Subtype:this.isCFF()?"CIDFontType0C":void 0}]),[2,t.register(r)]}})})},e.prototype.embedUnicodeCmap=function(t){var r=ud(this.glyphCache.access(),this.glyphId.bind(this)),n=t.flateStream(r);return t.register(n)},e.prototype.glyphId=function(t){return t?t.id:-1},e.prototype.computeWidths=function(){for(var t=this.glyphCache.access(),r=[],n=[],i=0,a=t.length;i<a;i++){var o=t[i],s=t[i-1],l=this.glyphId(o),c=this.glyphId(s);i===0?r.push(l):l-c!==1&&(r.push(n),r.push(l),n=[]),n.push(o.advanceWidth*this.scale)}return r.push(n),r},e}(),pd=function(e){M(t,e);function t(r,n,i,a){var o=e.call(this,r,n,i,a)||this;return o.subset=o.font.createSubset(),o.glyphs=[],o.glyphCache=Ot.populatedBy(function(){return o.glyphs}),o.glyphIdMap=new Map,o}return t.for=function(r,n,i,a){return _(this,void 0,void 0,function(){var o;return $(this,function(s){switch(s.label){case 0:return[4,r.create(n)];case 1:return o=s.sent(),[2,new t(o,n,i,a)]}})})},t.prototype.encodeText=function(r){for(var n=this.font.layout(r,this.fontFeatures).glyphs,i=new Array(n.length),a=0,o=n.length;a<o;a++){var s=n[a],l=this.subset.includeGlyph(s);this.glyphs[l-1]=s,this.glyphIdMap.set(s.id,l),i[a]=Jr(l,4)}return this.glyphCache.invalidate(),G.of(i.join(""))},t.prototype.isCFF=function(){return this.subset.cff},t.prototype.glyphId=function(r){return r?this.glyphIdMap.get(r.id):-1},t.prototype.serializeFont=function(){var r=this;return new Promise(function(n,i){var a=[];r.subset.encodeStream().on("data",function(o){return a.push(o)}).on("end",function(){return n(bu(a))}).on("error",function(o){return i(o)})})},t}(Ua),La;(function(e){e.Source="Source",e.Data="Data",e.Alternative="Alternative",e.Supplement="Supplement",e.EncryptedPayload="EncryptedPayload",e.FormData="EncryptedPayload",e.Schema="Schema",e.Unspecified="Unspecified"})(La||(La={}));var gd=function(){function e(t,r,n){n===void 0&&(n={}),this.fileData=t,this.fileName=r,this.options=n}return e.for=function(t,r,n){return n===void 0&&(n={}),new e(t,r,n)},e.prototype.embedIntoContext=function(t,r){return _(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u,h;return $(this,function(f){return n=this.options,i=n.mimeType,a=n.description,o=n.creationDate,s=n.modificationDate,l=n.afRelationship,c=t.flateStream(this.fileData,{Type:"EmbeddedFile",Subtype:i??void 0,Params:{Size:this.fileData.length,CreationDate:o?pe.fromDate(o):void 0,ModDate:s?pe.fromDate(s):void 0}}),u=t.register(c),h=t.obj({Type:"Filespec",F:pe.of(this.fileName),UF:G.fromText(this.fileName),EF:{F:u},Desc:a?G.fromText(a):void 0,AFRelationship:l??void 0}),r?(t.assign(r,h),[2,r]):[2,t.register(h)]})})},e}(),nl=[65472,65473,65474,65475,65477,65478,65479,65480,65481,65482,65483,65484,65485,65486,65487],Br;(function(e){e.DeviceGray="DeviceGray",e.DeviceRGB="DeviceRGB",e.DeviceCMYK="DeviceCMYK"})(Br||(Br={}));var yd={1:Br.DeviceGray,3:Br.DeviceRGB,4:Br.DeviceCMYK},il=function(){function e(t,r,n,i,a){this.imageData=t,this.bitsPerComponent=r,this.width=n,this.height=i,this.colorSpace=a}return e.for=function(t){return _(this,void 0,void 0,function(){var r,n,i,a,o,s,l,c,u,h;return $(this,function(f){if(r=new DataView(t.buffer),n=r.getUint16(0),n!==65496)throw new Error("SOI not found in JPEG");for(i=2;i<r.byteLength&&(a=r.getUint16(i),i+=2,!nl.includes(a));)i+=r.getUint16(i);if(!nl.includes(a))throw new Error("Invalid JPEG");if(i+=2,o=r.getUint8(i++),s=r.getUint16(i),i+=2,l=r.getUint16(i),i+=2,c=r.getUint8(i++),u=yd[c],!u)throw new Error("Unknown JPEG channel.");return h=u,[2,new e(t,o,l,s,h)]})})},e.prototype.embedIntoContext=function(t,r){return _(this,void 0,void 0,function(){var n;return $(this,function(i){return n=t.stream(this.imageData,{Type:"XObject",Subtype:"Image",BitsPerComponent:this.bitsPerComponent,Width:this.width,Height:this.height,ColorSpace:this.colorSpace,Filter:"DCTDecode",Decode:this.colorSpace===Br.DeviceCMYK?[1,0,1,0,1,0,1,0]:void 0}),r?(t.assign(r,n),[2,r]):[2,t.register(n)]})})},e}(),R={};R.toRGBA8=function(e){var t=e.width,r=e.height;if(e.tabs.acTL==null)return[R.toRGBA8.decodeImage(e.data,t,r,e).buffer];var n=[];e.frames[0].data==null&&(e.frames[0].data=e.data);for(var i=t*r*4,a=new Uint8Array(i),o=new Uint8Array(i),s=new Uint8Array(i),l=0;l<e.frames.length;l++){var c=e.frames[l],u=c.rect.x,h=c.rect.y,f=c.rect.width,d=c.rect.height,v=R.toRGBA8.decodeImage(c.data,f,d,e);if(l!=0)for(var p=0;p<i;p++)s[p]=a[p];if(c.blend==0?R._copyTile(v,f,d,a,t,r,u,h,0):c.blend==1&&R._copyTile(v,f,d,a,t,r,u,h,1),n.push(a.buffer.slice(0)),c.dispose!=0){if(c.dispose==1)R._copyTile(o,f,d,a,t,r,u,h,0);else if(c.dispose==2)for(var p=0;p<i;p++)a[p]=s[p]}}return n},R.toRGBA8.decodeImage=function(e,t,r,n){var i=t*r,a=R.decode._getBPP(n),o=Math.ceil(t*a/8),s=new Uint8Array(i*4),l=new Uint32Array(s.buffer),c=n.ctype,u=n.depth,h=R._bin.readUshort;if(c==6){var f=i<<2;if(u==8)for(var d=0;d<f;d+=4)s[d]=e[d],s[d+1]=e[d+1],s[d+2]=e[d+2],s[d+3]=e[d+3];if(u==16)for(var d=0;d<f;d++)s[d]=e[d<<1]}else if(c==2){var v=n.tabs.tRNS;if(v==null){if(u==8)for(var d=0;d<i;d++){var p=d*3;l[d]=255<<24|e[p+2]<<16|e[p+1]<<8|e[p]}if(u==16)for(var d=0;d<i;d++){var p=d*6;l[d]=255<<24|e[p+4]<<16|e[p+2]<<8|e[p]}}else{var m=v[0],b=v[1],k=v[2];if(u==8)for(var d=0;d<i;d++){var x=d<<2,p=d*3;l[d]=255<<24|e[p+2]<<16|e[p+1]<<8|e[p],e[p]==m&&e[p+1]==b&&e[p+2]==k&&(s[x+3]=0)}if(u==16)for(var d=0;d<i;d++){var x=d<<2,p=d*6;l[d]=255<<24|e[p+4]<<16|e[p+2]<<8|e[p],h(e,p)==m&&h(e,p+2)==b&&h(e,p+4)==k&&(s[x+3]=0)}}}else if(c==3){var T=n.tabs.PLTE,w=n.tabs.tRNS,F=w?w.length:0;if(u==1)for(var A=0;A<r;A++)for(var D=A*o,O=A*t,d=0;d<t;d++){var x=O+d<<2,B=e[D+(d>>3)]>>7-((d&7)<<0)&1,E=3*B;s[x]=T[E],s[x+1]=T[E+1],s[x+2]=T[E+2],s[x+3]=B<F?w[B]:255}if(u==2)for(var A=0;A<r;A++)for(var D=A*o,O=A*t,d=0;d<t;d++){var x=O+d<<2,B=e[D+(d>>2)]>>6-((d&3)<<1)&3,E=3*B;s[x]=T[E],s[x+1]=T[E+1],s[x+2]=T[E+2],s[x+3]=B<F?w[B]:255}if(u==4)for(var A=0;A<r;A++)for(var D=A*o,O=A*t,d=0;d<t;d++){var x=O+d<<2,B=e[D+(d>>1)]>>4-((d&1)<<2)&15,E=3*B;s[x]=T[E],s[x+1]=T[E+1],s[x+2]=T[E+2],s[x+3]=B<F?w[B]:255}if(u==8)for(var d=0;d<i;d++){var x=d<<2,B=e[d],E=3*B;s[x]=T[E],s[x+1]=T[E+1],s[x+2]=T[E+2],s[x+3]=B<F?w[B]:255}}else if(c==4){if(u==8)for(var d=0;d<i;d++){var x=d<<2,j=d<<1,I=e[j];s[x]=I,s[x+1]=I,s[x+2]=I,s[x+3]=e[j+1]}if(u==16)for(var d=0;d<i;d++){var x=d<<2,j=d<<2,I=e[j];s[x]=I,s[x+1]=I,s[x+2]=I,s[x+3]=e[j+2]}}else if(c==0)for(var m=n.tabs.tRNS?n.tabs.tRNS:-1,A=0;A<r;A++){var L=A*o,z=A*t;if(u==1)for(var P=0;P<t;P++){var I=255*(e[L+(P>>>3)]>>>7-(P&7)&1),U=I==m*255?0:255;l[z+P]=U<<24|I<<16|I<<8|I}else if(u==2)for(var P=0;P<t;P++){var I=85*(e[L+(P>>>2)]>>>6-((P&3)<<1)&3),U=I==m*85?0:255;l[z+P]=U<<24|I<<16|I<<8|I}else if(u==4)for(var P=0;P<t;P++){var I=17*(e[L+(P>>>1)]>>>4-((P&1)<<2)&15),U=I==m*17?0:255;l[z+P]=U<<24|I<<16|I<<8|I}else if(u==8)for(var P=0;P<t;P++){var I=e[L+P],U=I==m?0:255;l[z+P]=U<<24|I<<16|I<<8|I}else if(u==16)for(var P=0;P<t;P++){var I=e[L+(P<<1)],U=h(e,L+(P<<d))==m?0:255;l[z+P]=U<<24|I<<16|I<<8|I}}return s},R.decode=function(e){for(var t=new Uint8Array(e),r=8,n=R._bin,i=n.readUshort,a=n.readUint,o={tabs:{},frames:[]},s=new Uint8Array(t.length),l=0,c,u=0,h=[137,80,78,71,13,10,26,10],f=0;f<8;f++)if(t[f]!=h[f])throw"The input is not a PNG file!";for(;r<t.length;){var d=n.readUint(t,r);r+=4;var v=n.readASCII(t,r,4);if(r+=4,v=="IHDR")R.decode._IHDR(t,r,o);else if(v=="IDAT"){for(var f=0;f<d;f++)s[l+f]=t[r+f];l+=d}else if(v=="acTL")o.tabs[v]={num_frames:a(t,r),num_plays:a(t,r+4)},c=new Uint8Array(t.length);else if(v=="fcTL"){if(u!=0){var p=o.frames[o.frames.length-1];p.data=R.decode._decompress(o,c.slice(0,u),p.rect.width,p.rect.height),u=0}var m={x:a(t,r+12),y:a(t,r+16),width:a(t,r+4),height:a(t,r+8)},b=i(t,r+22);b=i(t,r+20)/(b==0?100:b);var k={rect:m,delay:Math.round(b*1e3),dispose:t[r+24],blend:t[r+25]};o.frames.push(k)}else if(v=="fdAT"){for(var f=0;f<d-4;f++)c[u+f]=t[r+f+4];u+=d-4}else if(v=="pHYs")o.tabs[v]=[n.readUint(t,r),n.readUint(t,r+4),t[r+8]];else if(v=="cHRM"){o.tabs[v]=[];for(var f=0;f<8;f++)o.tabs[v].push(n.readUint(t,r+f*4))}else if(v=="tEXt"){o.tabs[v]==null&&(o.tabs[v]={});var x=n.nextZero(t,r),T=n.readASCII(t,r,x-r),w=n.readASCII(t,x+1,r+d-x-1);o.tabs[v][T]=w}else if(v=="iTXt"){o.tabs[v]==null&&(o.tabs[v]={});var x=0,F=r;x=n.nextZero(t,F);var T=n.readASCII(t,F,x-F);F=x+1,t[F],t[F+1],F+=2,x=n.nextZero(t,F),n.readASCII(t,F,x-F),F=x+1,x=n.nextZero(t,F),n.readUTF8(t,F,x-F),F=x+1;var w=n.readUTF8(t,F,d-(F-r));o.tabs[v][T]=w}else if(v=="PLTE")o.tabs[v]=n.readBytes(t,r,d);else if(v=="hIST"){var A=o.tabs.PLTE.length/3;o.tabs[v]=[];for(var f=0;f<A;f++)o.tabs[v].push(i(t,r+f*2))}else if(v=="tRNS")o.ctype==3?o.tabs[v]=n.readBytes(t,r,d):o.ctype==0?o.tabs[v]=i(t,r):o.ctype==2&&(o.tabs[v]=[i(t,r),i(t,r+2),i(t,r+4)]);else if(v=="gAMA")o.tabs[v]=n.readUint(t,r)/1e5;else if(v=="sRGB")o.tabs[v]=t[r];else if(v=="bKGD")o.ctype==0||o.ctype==4?o.tabs[v]=[i(t,r)]:o.ctype==2||o.ctype==6?o.tabs[v]=[i(t,r),i(t,r+2),i(t,r+4)]:o.ctype==3&&(o.tabs[v]=t[r]);else if(v=="IEND")break;r+=d,n.readUint(t,r),r+=4}if(u!=0){var p=o.frames[o.frames.length-1];p.data=R.decode._decompress(o,c.slice(0,u),p.rect.width,p.rect.height),u=0}return o.data=R.decode._decompress(o,s,o.width,o.height),delete o.compress,delete o.interlace,delete o.filter,o},R.decode._decompress=function(e,t,r,n){var i=R.decode._getBPP(e),a=Math.ceil(r*i/8),o=new Uint8Array((a+1+e.interlace)*n);return t=R.decode._inflate(t,o),e.interlace==0?t=R.decode._filterZero(t,e,0,r,n):e.interlace==1&&(t=R.decode._readInterlace(t,e)),t},R.decode._inflate=function(e,t){var r=R.inflateRaw(new Uint8Array(e.buffer,2,e.length-6),t);return r},R.inflateRaw=function(){var e={};return e.H={},e.H.N=function(t,r){var n=Uint8Array,i=0,a=0,o=0,s=0,l=0,c=0,u=0,h=0,f=0,d,v;if(t[0]==3&&t[1]==0)return r||new n(0);var p=e.H,m=p.b,b=p.e,k=p.R,x=p.n,T=p.A,w=p.Z,F=p.m,A=r==null;for(A&&(r=new n(t.length>>>2<<3));i==0;){if(i=m(t,f,1),a=m(t,f+1,2),f+=3,a==0){f&7&&(f+=8-(f&7));var D=(f>>>3)+4,O=t[D-4]|t[D-3]<<8;A&&(r=e.H.W(r,h+O)),r.set(new n(t.buffer,t.byteOffset+D,O),h),f=D+O<<3,h+=O;continue}if(A&&(r=e.H.W(r,h+(1<<17))),a==1&&(d=F.J,v=F.h,c=511,u=31),a==2){o=b(t,f,5)+257,s=b(t,f+5,5)+1,l=b(t,f+10,4)+4,f+=14;for(var B=1,E=0;E<38;E+=2)F.Q[E]=0,F.Q[E+1]=0;for(var E=0;E<l;E++){var j=b(t,f+E*3,3);F.Q[(F.X[E]<<1)+1]=j,j>B&&(B=j)}f+=3*l,x(F.Q,B),T(F.Q,B,F.u),d=F.w,v=F.d,f=k(F.u,(1<<B)-1,o+s,t,f,F.v);var I=p.V(F.v,0,o,F.C);c=(1<<I)-1;var L=p.V(F.v,o,s,F.D);u=(1<<L)-1,x(F.C,I),T(F.C,I,d),x(F.D,L),T(F.D,L,v)}for(;;){var z=d[w(t,f)&c];f+=z&15;var P=z>>>4;if(!(P>>>8))r[h++]=P;else{if(P==256)break;var U=h+P-254;if(P>264){var ue=F.q[P-257];U=h+(ue>>>3)+b(t,f,ue&7),f+=ue&7}var me=v[w(t,f)&u];f+=me&15;var We=me>>>4,Oe=F.c[We],Re=(Oe>>>4)+m(t,f,Oe&15);for(f+=Oe&15;h<U;)r[h]=r[h++-Re],r[h]=r[h++-Re],r[h]=r[h++-Re],r[h]=r[h++-Re];h=U}}}return r.length==h?r:r.slice(0,h)},e.H.W=function(t,r){var n=t.length;if(r<=n)return t;var i=new Uint8Array(n<<1);return i.set(t,0),i},e.H.R=function(t,r,n,i,a,o){for(var s=e.H.e,l=e.H.Z,c=0;c<n;){var u=t[l(i,a)&r];a+=u&15;var h=u>>>4;if(h<=15)o[c]=h,c++;else{var f=0,d=0;h==16?(d=3+s(i,a,2),a+=2,f=o[c-1]):h==17?(d=3+s(i,a,3),a+=3):h==18&&(d=11+s(i,a,7),a+=7);for(var v=c+d;c<v;)o[c]=f,c++}}return a},e.H.V=function(t,r,n,i){for(var a=0,o=0,s=i.length>>>1;o<n;){var l=t[o+r];i[o<<1]=0,i[(o<<1)+1]=l,l>a&&(a=l),o++}for(;o<s;)i[o<<1]=0,i[(o<<1)+1]=0,o++;return a},e.H.n=function(t,r){for(var n=e.H.m,i=t.length,a,o,s,l,c,u=n.j,l=0;l<=r;l++)u[l]=0;for(l=1;l<i;l+=2)u[t[l]]++;var h=n.K;for(a=0,u[0]=0,o=1;o<=r;o++)a=a+u[o-1]<<1,h[o]=a;for(s=0;s<i;s+=2)c=t[s+1],c!=0&&(t[s]=h[c],h[c]++)},e.H.A=function(t,r,n){for(var i=t.length,a=e.H.m,o=a.r,s=0;s<i;s+=2)if(t[s+1]!=0)for(var l=s>>1,c=t[s+1],u=l<<4|c,h=r-c,f=t[s]<<h,d=f+(1<<h);f!=d;){var v=o[f]>>>15-r;n[v]=u,f++}},e.H.l=function(t,r){for(var n=e.H.m.r,i=15-r,a=0;a<t.length;a+=2){var o=t[a]<<r-t[a+1];t[a]=n[o]>>>i}},e.H.M=function(t,r,n){n=n<<(r&7);var i=r>>>3;t[i]|=n,t[i+1]|=n>>>8},e.H.I=function(t,r,n){n=n<<(r&7);var i=r>>>3;t[i]|=n,t[i+1]|=n>>>8,t[i+2]|=n>>>16},e.H.e=function(t,r,n){return(t[r>>>3]|t[(r>>>3)+1]<<8)>>>(r&7)&(1<<n)-1},e.H.b=function(t,r,n){return(t[r>>>3]|t[(r>>>3)+1]<<8|t[(r>>>3)+2]<<16)>>>(r&7)&(1<<n)-1},e.H.Z=function(t,r){return(t[r>>>3]|t[(r>>>3)+1]<<8|t[(r>>>3)+2]<<16)>>>(r&7)},e.H.i=function(t,r){return(t[r>>>3]|t[(r>>>3)+1]<<8|t[(r>>>3)+2]<<16|t[(r>>>3)+3]<<24)>>>(r&7)},e.H.m=function(){var t=Uint16Array,r=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new r(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new r(286),Y:new r(30),a:new r(19),t:new r(15e3),k:new t(65536),g:new t(32768)}}(),function(){for(var t=e.H.m,r=32768,n=0;n<r;n++){var i=n;i=(i&2863311530)>>>1|(i&1431655765)<<1,i=(i&3435973836)>>>2|(i&858993459)<<2,i=(i&4042322160)>>>4|(i&252645135)<<4,i=(i&4278255360)>>>8|(i&16711935)<<8,t.r[n]=(i>>>16|i<<16)>>>17}function a(o,s,l){for(;s--!=0;)o.push(0,l)}for(var n=0;n<32;n++)t.q[n]=t.S[n]<<3|t.T[n],t.c[n]=t.p[n]<<4|t.z[n];a(t._,144,8),a(t._,112,9),a(t._,24,7),a(t._,8,8),e.H.n(t._,9),e.H.A(t._,9,t.J),e.H.l(t._,9),a(t.$,32,5),e.H.n(t.$,5),e.H.A(t.$,5,t.h),e.H.l(t.$,5),a(t.Q,19,0),a(t.C,286,0),a(t.D,30,0),a(t.v,320,0)}(),e.H.N}(),R.decode._readInterlace=function(e,t){for(var r=t.width,n=t.height,i=R.decode._getBPP(t),a=i>>3,o=Math.ceil(r*i/8),s=new Uint8Array(n*o),l=0,c=[0,0,4,0,2,0,1],u=[0,4,0,2,0,1,0],h=[8,8,8,4,4,2,2],f=[8,8,4,4,2,2,1],d=0;d<7;){for(var v=h[d],p=f[d],m=0,b=0,k=c[d];k<n;)k+=v,b++;for(var x=u[d];x<r;)x+=p,m++;var T=Math.ceil(m*i/8);R.decode._filterZero(e,t,l,m,b);for(var w=0,F=c[d];F<n;){for(var A=u[d],D=l+w*T<<3;A<r;){if(i==1){var O=e[D>>3];O=O>>7-(D&7)&1,s[F*o+(A>>3)]|=O<<7-((A&7)<<0)}if(i==2){var O=e[D>>3];O=O>>6-(D&7)&3,s[F*o+(A>>2)]|=O<<6-((A&3)<<1)}if(i==4){var O=e[D>>3];O=O>>4-(D&7)&15,s[F*o+(A>>1)]|=O<<4-((A&1)<<2)}if(i>=8)for(var B=F*o+A*a,E=0;E<a;E++)s[B+E]=e[(D>>3)+E];D+=i,A+=p}w++,F+=v}m*b!=0&&(l+=b*(1+T)),d=d+1}return s},R.decode._getBPP=function(e){var t=[1,null,3,1,2,null,4][e.ctype];return t*e.depth},R.decode._filterZero=function(e,t,r,n,i){var a=R.decode._getBPP(t),o=Math.ceil(n*a/8),s=R.decode._paeth;a=Math.ceil(a/8);var l=0,c=1,u=e[r],h=0;if(u>1&&(e[r]=[0,0,1][u-2]),u==3)for(h=a;h<o;h++)e[h+1]=e[h+1]+(e[h+1-a]>>>1)&255;for(var f=0;f<i;f++)if(l=r+f*o,c=l+f+1,u=e[c-1],h=0,u==0)for(;h<o;h++)e[l+h]=e[c+h];else if(u==1){for(;h<a;h++)e[l+h]=e[c+h];for(;h<o;h++)e[l+h]=e[c+h]+e[l+h-a]}else if(u==2)for(;h<o;h++)e[l+h]=e[c+h]+e[l+h-o];else if(u==3){for(;h<a;h++)e[l+h]=e[c+h]+(e[l+h-o]>>>1);for(;h<o;h++)e[l+h]=e[c+h]+(e[l+h-o]+e[l+h-a]>>>1)}else{for(;h<a;h++)e[l+h]=e[c+h]+s(0,e[l+h-o],0);for(;h<o;h++)e[l+h]=e[c+h]+s(e[l+h-a],e[l+h-o],e[l+h-a-o])}return e},R.decode._paeth=function(e,t,r){var n=e+t-r,i=n-e,a=n-t,o=n-r;return i*i<=a*a&&i*i<=o*o?e:a*a<=o*o?t:r},R.decode._IHDR=function(e,t,r){var n=R._bin;r.width=n.readUint(e,t),t+=4,r.height=n.readUint(e,t),t+=4,r.depth=e[t],t++,r.ctype=e[t],t++,r.compress=e[t],t++,r.filter=e[t],t++,r.interlace=e[t],t++},R._bin={nextZero:function(e,t){for(;e[t]!=0;)t++;return t},readUshort:function(e,t){return e[t]<<8|e[t+1]},writeUshort:function(e,t,r){e[t]=r>>8&255,e[t+1]=r&255},readUint:function(e,t){return e[t]*(256*256*256)+(e[t+1]<<16|e[t+2]<<8|e[t+3])},writeUint:function(e,t,r){e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255},readASCII:function(e,t,r){for(var n="",i=0;i<r;i++)n+=String.fromCharCode(e[t+i]);return n},writeASCII:function(e,t,r){for(var n=0;n<r.length;n++)e[t+n]=r.charCodeAt(n)},readBytes:function(e,t,r){for(var n=[],i=0;i<r;i++)n.push(e[t+i]);return n},pad:function(e){return e.length<2?"0"+e:e},readUTF8:function(e,t,r){for(var n="",i,a=0;a<r;a++)n+="%"+R._bin.pad(e[t+a].toString(16));try{i=decodeURIComponent(n)}catch{return R._bin.readASCII(e,t,r)}return i}},R._copyTile=function(e,t,r,n,i,a,o,s,l){for(var c=Math.min(t,i),u=Math.min(r,a),h=0,f=0,d=0;d<u;d++)for(var v=0;v<c;v++)if(o>=0&&s>=0?(h=d*t+v<<2,f=(s+d)*i+o+v<<2):(h=(-s+d)*t-o+v<<2,f=d*i+v<<2),l==0)n[f]=e[h],n[f+1]=e[h+1],n[f+2]=e[h+2],n[f+3]=e[h+3];else if(l==1){var p=e[h+3]*.00392156862745098,m=e[h]*p,b=e[h+1]*p,k=e[h+2]*p,x=n[f+3]*(1/255),T=n[f]*x,w=n[f+1]*x,F=n[f+2]*x,A=1-p,D=p+x*A,O=D==0?0:1/D;n[f+3]=255*D,n[f+0]=(m+T*A)*O,n[f+1]=(b+w*A)*O,n[f+2]=(k+F*A)*O}else if(l==2){var p=e[h+3],m=e[h],b=e[h+1],k=e[h+2],x=n[f+3],T=n[f],w=n[f+1],F=n[f+2];p==x&&m==T&&b==w&&k==F?(n[f]=0,n[f+1]=0,n[f+2]=0,n[f+3]=0):(n[f]=m,n[f+1]=b,n[f+2]=k,n[f+3]=p)}else if(l==3){var p=e[h+3],m=e[h],b=e[h+1],k=e[h+2],x=n[f+3],T=n[f],w=n[f+1],F=n[f+2];if(p==x&&m==T&&b==w&&k==F)continue;if(p<220&&x>20)return!1}return!0},R.encode=function(e,t,r,n,i,a,o){n==null&&(n=0),o==null&&(o=!1);var s=R.encode.compress(e,t,r,n,[!1,!1,!1,0,o]);return R.encode.compressPNG(s,-1),R.encode._main(s,t,r,i,a)},R.encodeLL=function(e,t,r,n,i,a,o,s){for(var l={ctype:0+(n==1?0:2)+(i==0?0:4),depth:a,frames:[]},c=(n+i)*a,u=c*t,h=0;h<e.length;h++)l.frames.push({rect:{x:0,y:0,width:t,height:r},img:new Uint8Array(e[h]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(u/8)});R.encode.compressPNG(l,0,!0);var f=R.encode._main(l,t,r,o,s);return f},R.encode._main=function(e,t,r,n,i){i==null&&(i={});var a=R.crc.crc,o=R._bin.writeUint,s=R._bin.writeUshort,l=R._bin.writeASCII,c=8,u=e.frames.length>1,h=!1,f=33+(u?20:0);if(i.sRGB!=null&&(f+=13),i.pHYs!=null&&(f+=21),e.ctype==3){for(var d=e.plte.length,v=0;v<d;v++)e.plte[v]>>>24!=255&&(h=!0);f+=8+d*3+4+(h?8+d*1+4:0)}for(var p=0;p<e.frames.length;p++){var m=e.frames[p];u&&(f+=38),f+=m.cimg.length+12,p!=0&&(f+=4)}f+=12;for(var b=new Uint8Array(f),k=[137,80,78,71,13,10,26,10],v=0;v<8;v++)b[v]=k[v];if(o(b,c,13),c+=4,l(b,c,"IHDR"),c+=4,o(b,c,t),c+=4,o(b,c,r),c+=4,b[c]=e.depth,c++,b[c]=e.ctype,c++,b[c]=0,c++,b[c]=0,c++,b[c]=0,c++,o(b,c,a(b,c-17,17)),c+=4,i.sRGB!=null&&(o(b,c,1),c+=4,l(b,c,"sRGB"),c+=4,b[c]=i.sRGB,c++,o(b,c,a(b,c-5,5)),c+=4),i.pHYs!=null&&(o(b,c,9),c+=4,l(b,c,"pHYs"),c+=4,o(b,c,i.pHYs[0]),c+=4,o(b,c,i.pHYs[1]),c+=4,b[c]=i.pHYs[2],c++,o(b,c,a(b,c-13,13)),c+=4),u&&(o(b,c,8),c+=4,l(b,c,"acTL"),c+=4,o(b,c,e.frames.length),c+=4,o(b,c,i.loop!=null?i.loop:0),c+=4,o(b,c,a(b,c-12,12)),c+=4),e.ctype==3){var d=e.plte.length;o(b,c,d*3),c+=4,l(b,c,"PLTE"),c+=4;for(var v=0;v<d;v++){var x=v*3,T=e.plte[v],w=T&255,F=T>>>8&255,A=T>>>16&255;b[c+x+0]=w,b[c+x+1]=F,b[c+x+2]=A}if(c+=d*3,o(b,c,a(b,c-d*3-4,d*3+4)),c+=4,h){o(b,c,d),c+=4,l(b,c,"tRNS"),c+=4;for(var v=0;v<d;v++)b[c+v]=e.plte[v]>>>24&255;c+=d,o(b,c,a(b,c-d-4,d+4)),c+=4}}for(var D=0,p=0;p<e.frames.length;p++){var m=e.frames[p];u&&(o(b,c,26),c+=4,l(b,c,"fcTL"),c+=4,o(b,c,D++),c+=4,o(b,c,m.rect.width),c+=4,o(b,c,m.rect.height),c+=4,o(b,c,m.rect.x),c+=4,o(b,c,m.rect.y),c+=4,s(b,c,n[p]),c+=2,s(b,c,1e3),c+=2,b[c]=m.dispose,c++,b[c]=m.blend,c++,o(b,c,a(b,c-30,30)),c+=4);var O=m.cimg,d=O.length;o(b,c,d+(p==0?0:4)),c+=4;var B=c;l(b,c,p==0?"IDAT":"fdAT"),c+=4,p!=0&&(o(b,c,D++),c+=4),b.set(O,c),c+=d,o(b,c,a(b,B,c-B)),c+=4}return o(b,c,0),c+=4,l(b,c,"IEND"),c+=4,o(b,c,a(b,c-4,4)),c+=4,b.buffer},R.encode.compressPNG=function(e,t,r){for(var n=0;n<e.frames.length;n++){var i=e.frames[n];i.rect.width;var a=i.rect.height,o=new Uint8Array(a*i.bpl+a);i.cimg=R.encode._filterZero(i.img,a,i.bpp,i.bpl,o,t,r)}},R.encode.compress=function(e,t,r,n,i){for(var a=i[0],o=i[1],s=i[2],l=i[3],c=i[4],u=6,h=8,f=255,d=0;d<e.length;d++)for(var v=new Uint8Array(e[d]),p=v.length,m=0;m<p;m+=4)f&=v[m+3];var b=f!=255,k=R.encode.framize(e,t,r,a,o,s),x={},T=[],w=[];if(n!=0){for(var F=[],m=0;m<k.length;m++)F.push(k[m].img.buffer);for(var A=R.encode.concatRGBA(F),D=R.quantize(A,n),O=0,B=new Uint8Array(D.abuf),m=0;m<k.length;m++){var E=k[m].img,j=E.length;w.push(new Uint8Array(D.inds.buffer,O>>2,j>>2));for(var d=0;d<j;d+=4)E[d]=B[O+d],E[d+1]=B[O+d+1],E[d+2]=B[O+d+2],E[d+3]=B[O+d+3];O+=j}for(var m=0;m<D.plte.length;m++)T.push(D.plte[m].est.rgba)}else for(var d=0;d<k.length;d++){var I=k[d],L=new Uint32Array(I.img.buffer),z=I.rect.width,p=L.length,P=new Uint8Array(p);w.push(P);for(var m=0;m<p;m++){var U=L[m];if(m!=0&&U==L[m-1])P[m]=P[m-1];else if(m>z&&U==L[m-z])P[m]=P[m-z];else{var ue=x[U];if(ue==null&&(x[U]=ue=T.length,T.push(U),T.length>=300))break;P[m]=ue}}}var me=T.length;me<=256&&c==!1&&(me<=2?h=1:me<=4?h=2:me<=16?h=4:h=8,h=Math.max(h,l));for(var d=0;d<k.length;d++){var I=k[d];I.rect.x,I.rect.y;var z=I.rect.width,We=I.rect.height,Oe=I.img;new Uint32Array(Oe.buffer);var Re=4*z,kt=4;if(me<=256&&c==!1){Re=Math.ceil(h*z/8);for(var Ze=new Uint8Array(Re*We),Gr=w[d],er=0;er<We;er++){var m=er*Re,mr=er*z;if(h==8)for(var xe=0;xe<z;xe++)Ze[m+xe]=Gr[mr+xe];else if(h==4)for(var xe=0;xe<z;xe++)Ze[m+(xe>>1)]|=Gr[mr+xe]<<4-(xe&1)*4;else if(h==2)for(var xe=0;xe<z;xe++)Ze[m+(xe>>2)]|=Gr[mr+xe]<<6-(xe&3)*2;else if(h==1)for(var xe=0;xe<z;xe++)Ze[m+(xe>>3)]|=Gr[mr+xe]<<7-(xe&7)*1}Oe=Ze,u=3,kt=1}else if(b==!1&&k.length==1){for(var Ze=new Uint8Array(z*We*3),lo=z*We,m=0;m<lo;m++){var E=m*3,be=m*4;Ze[E]=Oe[be],Ze[E+1]=Oe[be+1],Ze[E+2]=Oe[be+2]}Oe=Ze,u=2,kt=3,Re=3*z}I.img=Oe,I.bpl=Re,I.bpp=kt}return{ctype:u,depth:h,plte:T,frames:k}},R.encode.framize=function(e,t,r,n,i,a){for(var o=[],s=0;s<e.length;s++){var l=new Uint8Array(e[s]),c=new Uint32Array(l.buffer),u,h=0,f=0,d=t,v=r,p=n?1:0;if(s!=0){for(var m=a||n||s==1||o[s-2].dispose!=0?1:2,b=0,k=1e9,x=0;x<m;x++){for(var I=new Uint8Array(e[s-1-x]),T=new Uint32Array(e[s-1-x]),w=t,F=r,A=-1,D=-1,O=0;O<r;O++)for(var B=0;B<t;B++){var E=O*t+B;c[E]!=T[E]&&(B<w&&(w=B),B>A&&(A=B),O<F&&(F=O),O>D&&(D=O))}A==-1&&(w=F=A=D=0),i&&((w&1)==1&&w--,(F&1)==1&&F--);var j=(A-w+1)*(D-F+1);j<k&&(k=j,b=x,h=w,f=F,d=A-w+1,v=D-F+1)}var I=new Uint8Array(e[s-1-b]);b==1&&(o[s-1].dispose=2),u=new Uint8Array(d*v*4),R._copyTile(I,t,r,u,d,v,-h,-f,0),p=R._copyTile(l,t,r,u,d,v,-h,-f,3)?1:0,p==1?R.encode._prepareDiff(l,t,r,u,{x:h,y:f,width:d,height:v}):R._copyTile(l,t,r,u,d,v,-h,-f,0)}else u=l.slice(0);o.push({rect:{x:h,y:f,width:d,height:v},img:u,blend:p,dispose:0})}if(n)for(var s=0;s<o.length;s++){var L=o[s];if(L.blend!=1){var z=L.rect,P=o[s-1].rect,U=Math.min(z.x,P.x),ue=Math.min(z.y,P.y),me=Math.max(z.x+z.width,P.x+P.width),We=Math.max(z.y+z.height,P.y+P.height),Oe={x:U,y:ue,width:me-U,height:We-ue};o[s-1].dispose=1,s-1!=0&&R.encode._updateFrame(e,t,r,o,s-1,Oe,i),R.encode._updateFrame(e,t,r,o,s,Oe,i)}}var Re=0;if(e.length!=1)for(var E=0;E<o.length;E++){var L=o[E];Re+=L.rect.width*L.rect.height}return o},R.encode._updateFrame=function(e,t,r,n,i,a,o){for(var s=Uint8Array,l=Uint32Array,c=new s(e[i-1]),u=new l(e[i-1]),h=i+1<e.length?new s(e[i+1]):null,f=new s(e[i]),d=new l(f.buffer),v=t,p=r,m=-1,b=-1,k=0;k<a.height;k++)for(var x=0;x<a.width;x++){var T=a.x+x,w=a.y+k,F=w*t+T,A=d[F];A==0||n[i-1].dispose==0&&u[F]==A&&(h==null||h[F*4+3]!=0)||(T<v&&(v=T),T>m&&(m=T),w<p&&(p=w),w>b&&(b=w))}m==-1&&(v=p=m=b=0),o&&((v&1)==1&&v--,(p&1)==1&&p--),a={x:v,y:p,width:m-v+1,height:b-p+1};var D=n[i];D.rect=a,D.blend=1,D.img=new Uint8Array(a.width*a.height*4),n[i-1].dispose==0?(R._copyTile(c,t,r,D.img,a.width,a.height,-a.x,-a.y,0),R.encode._prepareDiff(f,t,r,D.img,a)):R._copyTile(f,t,r,D.img,a.width,a.height,-a.x,-a.y,0)},R.encode._prepareDiff=function(e,t,r,n,i){R._copyTile(e,t,r,n,i.width,i.height,-i.x,-i.y,2)},R.encode._filterZero=function(e,t,r,n,i,a,o){var s=[],l=[0,1,2,3,4];a!=-1?l=[a]:(t*n>5e5||r==1)&&(l=[0]);var c;o&&(c={level:0});for(var u=o&&UZIP!=null?UZIP:si,h=0;h<l.length;h++){for(var f=0;f<t;f++)R.encode._filterLine(i,e,f,n,r,l[h]);s.push(u.deflate(i,c))}for(var d,v=1e9,h=0;h<s.length;h++)s[h].length<v&&(d=h,v=s[h].length);return s[d]},R.encode._filterLine=function(e,t,r,n,i,a){var o=r*n,s=o+r,l=R.decode._paeth;if(e[s]=a,s++,a==0)if(n<500)for(var c=0;c<n;c++)e[s+c]=t[o+c];else e.set(new Uint8Array(t.buffer,o,n),s);else if(a==1){for(var c=0;c<i;c++)e[s+c]=t[o+c];for(var c=i;c<n;c++)e[s+c]=t[o+c]-t[o+c-i]+256&255}else if(r==0){for(var c=0;c<i;c++)e[s+c]=t[o+c];if(a==2)for(var c=i;c<n;c++)e[s+c]=t[o+c];if(a==3)for(var c=i;c<n;c++)e[s+c]=t[o+c]-(t[o+c-i]>>1)+256&255;if(a==4)for(var c=i;c<n;c++)e[s+c]=t[o+c]-l(t[o+c-i],0,0)+256&255}else{if(a==2)for(var c=0;c<n;c++)e[s+c]=t[o+c]+256-t[o+c-n]&255;if(a==3){for(var c=0;c<i;c++)e[s+c]=t[o+c]+256-(t[o+c-n]>>1)&255;for(var c=i;c<n;c++)e[s+c]=t[o+c]+256-(t[o+c-n]+t[o+c-i]>>1)&255}if(a==4){for(var c=0;c<i;c++)e[s+c]=t[o+c]+256-l(0,t[o+c-n],0)&255;for(var c=i;c<n;c++)e[s+c]=t[o+c]+256-l(t[o+c-i],t[o+c-n],t[o+c-i-n])&255}}},R.crc={table:function(){for(var e=new Uint32Array(256),t=0;t<256;t++){for(var r=t,n=0;n<8;n++)r&1?r=3988292384^r>>>1:r=r>>>1;e[t]=r}return e}(),update:function(e,t,r,n){for(var i=0;i<n;i++)e=R.crc.table[(e^t[r+i])&255]^e>>>8;return e},crc:function(e,t,r){return R.crc.update(4294967295,e,t,r)^4294967295}},R.quantize=function(e,t){var r=new Uint8Array(e),n=r.slice(0),i=new Uint32Array(n.buffer),a=R.quantize.getKDtree(n,t),o=a[0],s=a[1];R.quantize.planeDst;for(var l=r,c=i,u=l.length,h=new Uint8Array(r.length>>2),f=0;f<u;f+=4){var d=l[f]*.00392156862745098,v=l[f+1]*(1/255),p=l[f+2]*(1/255),m=l[f+3]*(1/255),b=R.quantize.getNearest(o,d,v,p,m);h[f>>2]=b.ind,c[f>>2]=b.est.rgba}return{abuf:n.buffer,inds:h,plte:s}},R.quantize.getKDtree=function(e,t,r){r==null&&(r=1e-4);var n=new Uint32Array(e.buffer),i={i0:0,i1:e.length,bst:null,est:null,tdst:0,left:null,right:null};i.bst=R.quantize.stats(e,i.i0,i.i1),i.est=R.quantize.estats(i.bst);for(var a=[i];a.length<t;){for(var o=0,s=0,l=0;l<a.length;l++)a[l].est.L>o&&(o=a[l].est.L,s=l);if(o<r)break;var c=a[s],u=R.quantize.splitPixels(e,n,c.i0,c.i1,c.est.e,c.est.eMq255),h=c.i0>=u||c.i1<=u;if(h){c.est.L=0;continue}var f={i0:c.i0,i1:u,bst:null,est:null,tdst:0,left:null,right:null};f.bst=R.quantize.stats(e,f.i0,f.i1),f.est=R.quantize.estats(f.bst);var d={i0:u,i1:c.i1,bst:null,est:null,tdst:0,left:null,right:null};d.bst={R:[],m:[],N:c.bst.N-f.bst.N};for(var l=0;l<16;l++)d.bst.R[l]=c.bst.R[l]-f.bst.R[l];for(var l=0;l<4;l++)d.bst.m[l]=c.bst.m[l]-f.bst.m[l];d.est=R.quantize.estats(d.bst),c.left=f,c.right=d,a[s]=f,a.push(d)}a.sort(function(v,p){return p.bst.N-v.bst.N});for(var l=0;l<a.length;l++)a[l].ind=l;return[i,a]},R.quantize.getNearest=function(e,t,r,n,i){if(e.left==null)return e.tdst=R.quantize.dist(e.est.q,t,r,n,i),e;var a=R.quantize.planeDst(e.est,t,r,n,i),o=e.left,s=e.right;a>0&&(o=e.right,s=e.left);var l=R.quantize.getNearest(o,t,r,n,i);if(l.tdst<=a*a)return l;var c=R.quantize.getNearest(s,t,r,n,i);return c.tdst<l.tdst?c:l},R.quantize.planeDst=function(e,t,r,n,i){var a=e.e;return a[0]*t+a[1]*r+a[2]*n+a[3]*i-e.eMq},R.quantize.dist=function(e,t,r,n,i){var a=t-e[0],o=r-e[1],s=n-e[2],l=i-e[3];return a*a+o*o+s*s+l*l},R.quantize.splitPixels=function(e,t,r,n,i,a){var o=R.quantize.vecDot;for(n-=4;r<n;){for(;o(e,r,i)<=a;)r+=4;for(;o(e,n,i)>a;)n-=4;if(r>=n)break;var s=t[r>>2];t[r>>2]=t[n>>2],t[n>>2]=s,r+=4,n-=4}for(;o(e,r,i)>a;)r-=4;return r+4},R.quantize.vecDot=function(e,t,r){return e[t]*r[0]+e[t+1]*r[1]+e[t+2]*r[2]+e[t+3]*r[3]},R.quantize.stats=function(e,t,r){for(var n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i=[0,0,0,0],a=r-t>>2,o=t;o<r;o+=4){var s=e[o]*.00392156862745098,l=e[o+1]*(1/255),c=e[o+2]*(1/255),u=e[o+3]*(1/255);i[0]+=s,i[1]+=l,i[2]+=c,i[3]+=u,n[0]+=s*s,n[1]+=s*l,n[2]+=s*c,n[3]+=s*u,n[5]+=l*l,n[6]+=l*c,n[7]+=l*u,n[10]+=c*c,n[11]+=c*u,n[15]+=u*u}return n[4]=n[1],n[8]=n[2],n[9]=n[6],n[12]=n[3],n[13]=n[7],n[14]=n[11],{R:n,m:i,N:a}},R.quantize.estats=function(e){var t=e.R,r=e.m,n=e.N,i=r[0],a=r[1],o=r[2],s=r[3],l=n==0?0:1/n,c=[t[0]-i*i*l,t[1]-i*a*l,t[2]-i*o*l,t[3]-i*s*l,t[4]-a*i*l,t[5]-a*a*l,t[6]-a*o*l,t[7]-a*s*l,t[8]-o*i*l,t[9]-o*a*l,t[10]-o*o*l,t[11]-o*s*l,t[12]-s*i*l,t[13]-s*a*l,t[14]-s*o*l,t[15]-s*s*l],u=c,h=R.M4,f=[.5,.5,.5,.5],d=0,v=0;if(n!=0)for(var p=0;p<10&&(f=h.multVec(u,f),v=Math.sqrt(h.dot(f,f)),f=h.sml(1/v,f),!(Math.abs(v-d)<1e-9));p++)d=v;var m=[i*l,a*l,o*l,s*l],b=h.dot(h.sml(255,m),f);return{Cov:c,q:m,e:f,L:d,eMq255:b,eMq:h.dot(f,m),rgba:(Math.round(255*m[3])<<24|Math.round(255*m[2])<<16|Math.round(255*m[1])<<8|Math.round(255*m[0])<<0)>>>0}},R.M4={multVec:function(e,t){return[e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],e[4]*t[0]+e[5]*t[1]+e[6]*t[2]+e[7]*t[3],e[8]*t[0]+e[9]*t[1]+e[10]*t[2]+e[11]*t[3],e[12]*t[0]+e[13]*t[1]+e[14]*t[2]+e[15]*t[3]]},dot:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},sml:function(e,t){return[e*t[0],e*t[1],e*t[2],e*t[3]]}},R.encode.concatRGBA=function(e){for(var t=0,r=0;r<e.length;r++)t+=e[r].byteLength;for(var n=new Uint8Array(t),i=0,r=0;r<e.length;r++){for(var a=new Uint8Array(e[r]),o=a.length,s=0;s<o;s+=4){var l=a[s],c=a[s+1],u=a[s+2],h=a[s+3];h==0&&(l=c=u=0),n[i+s]=l,n[i+s+1]=c,n[i+s+2]=u,n[i+s+3]=h}i+=o}return n.buffer};var bd=function(e){if(e===0)return hr.Greyscale;if(e===2)return hr.Truecolour;if(e===3)return hr.IndexedColour;if(e===4)return hr.GreyscaleWithAlpha;if(e===6)return hr.TruecolourWithAlpha;throw new Error("Unknown color type: "+e)},md=function(e){for(var t=Math.floor(e.length/4),r=new Uint8Array(t*3),n=new Uint8Array(t*1),i=0,a=0,o=0;i<e.length;)r[a++]=e[i++],r[a++]=e[i++],r[a++]=e[i++],n[o++]=e[i++];return{rgbChannel:r,alphaChannel:n}},hr;(function(e){e.Greyscale="Greyscale",e.Truecolour="Truecolour",e.IndexedColour="IndexedColour",e.GreyscaleWithAlpha="GreyscaleWithAlpha",e.TruecolourWithAlpha="TruecolourWithAlpha"})(hr||(hr={}));var xd=function(){function e(t){var r=R.decode(t),n=R.toRGBA8(r);if(n.length>1)throw new Error("Animated PNGs are not supported");var i=new Uint8Array(n[0]),a=md(i),o=a.rgbChannel,s=a.alphaChannel;this.rgbChannel=o;var l=s.some(function(c){return c<255});l&&(this.alphaChannel=s),this.type=bd(r.ctype),this.width=r.width,this.height=r.height,this.bitsPerComponent=8}return e.load=function(t){return new e(t)},e}(),al=function(){function e(t){this.image=t,this.bitsPerComponent=t.bitsPerComponent,this.width=t.width,this.height=t.height,this.colorSpace="DeviceRGB"}return e.for=function(t){return _(this,void 0,void 0,function(){var r;return $(this,function(n){return r=xd.load(t),[2,new e(r)]})})},e.prototype.embedIntoContext=function(t,r){return _(this,void 0,void 0,function(){var n,i;return $(this,function(a){return n=this.embedAlphaChannel(t),i=t.flateStream(this.image.rgbChannel,{Type:"XObject",Subtype:"Image",BitsPerComponent:this.image.bitsPerComponent,Width:this.image.width,Height:this.image.height,ColorSpace:this.colorSpace,SMask:n}),r?(t.assign(r,i),[2,r]):[2,t.register(i)]})})},e.prototype.embedAlphaChannel=function(t){if(this.image.alphaChannel){var r=t.flateStream(this.image.alphaChannel,{Type:"XObject",Subtype:"Image",Height:this.image.height,Width:this.image.width,BitsPerComponent:this.image.bitsPerComponent,ColorSpace:"DeviceGray",Decode:[0,1]});return t.register(r)}},e}(),ol=function(){function e(t,r,n){this.bytes=t,this.start=r||0,this.pos=this.start,this.end=r&&n?r+n:this.bytes.length}return Object.defineProperty(e.prototype,"length",{get:function(){return this.end-this.start},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isEmpty",{get:function(){return this.length===0},enumerable:!1,configurable:!0}),e.prototype.getByte=function(){return this.pos>=this.end?-1:this.bytes[this.pos++]},e.prototype.getUint16=function(){var t=this.getByte(),r=this.getByte();return t===-1||r===-1?-1:(t<<8)+r},e.prototype.getInt32=function(){var t=this.getByte(),r=this.getByte(),n=this.getByte(),i=this.getByte();return(t<<24)+(r<<16)+(n<<8)+i},e.prototype.getBytes=function(t,r){r===void 0&&(r=!1);var n=this.bytes,i=this.pos,a=this.end;if(t){var s=i+t;s>a&&(s=a),this.pos=s;var o=n.subarray(i,s);return r?new Uint8ClampedArray(o):o}else{var o=n.subarray(i,a);return r?new Uint8ClampedArray(o):o}},e.prototype.peekByte=function(){var t=this.getByte();return this.pos--,t},e.prototype.peekBytes=function(t,r){r===void 0&&(r=!1);var n=this.getBytes(t,r);return this.pos-=n.length,n},e.prototype.skip=function(t){t||(t=1),this.pos+=t},e.prototype.reset=function(){this.pos=this.start},e.prototype.moveStart=function(){this.start=this.pos},e.prototype.makeSubStream=function(t,r){return new e(this.bytes,t,r)},e.prototype.decode=function(){return this.bytes},e}(),wd=new Uint8Array(0),kn=function(){function e(t){if(this.pos=0,this.bufferLength=0,this.eof=!1,this.buffer=wd,this.minBufferLength=512,t)for(;this.minBufferLength<t;)this.minBufferLength*=2}return Object.defineProperty(e.prototype,"isEmpty",{get:function(){for(;!this.eof&&this.bufferLength===0;)this.readBlock();return this.bufferLength===0},enumerable:!1,configurable:!0}),e.prototype.getByte=function(){for(var t=this.pos;this.bufferLength<=t;){if(this.eof)return-1;this.readBlock()}return this.buffer[this.pos++]},e.prototype.getUint16=function(){var t=this.getByte(),r=this.getByte();return t===-1||r===-1?-1:(t<<8)+r},e.prototype.getInt32=function(){var t=this.getByte(),r=this.getByte(),n=this.getByte(),i=this.getByte();return(t<<24)+(r<<16)+(n<<8)+i},e.prototype.getBytes=function(t,r){r===void 0&&(r=!1);var n,i=this.pos;if(t){for(this.ensureBuffer(i+t),n=i+t;!this.eof&&this.bufferLength<n;)this.readBlock();var a=this.bufferLength;n>a&&(n=a)}else{for(;!this.eof;)this.readBlock();n=this.bufferLength}this.pos=n;var o=this.buffer.subarray(i,n);return r&&!(o instanceof Uint8ClampedArray)?new Uint8ClampedArray(o):o},e.prototype.peekByte=function(){var t=this.getByte();return this.pos--,t},e.prototype.peekBytes=function(t,r){r===void 0&&(r=!1);var n=this.getBytes(t,r);return this.pos-=n.length,n},e.prototype.skip=function(t){t||(t=1),this.pos+=t},e.prototype.reset=function(){this.pos=0},e.prototype.makeSubStream=function(t,r){for(var n=t+r;this.bufferLength<=n&&!this.eof;)this.readBlock();return new ol(this.buffer,t,r)},e.prototype.decode=function(){for(;!this.eof;)this.readBlock();return this.buffer.subarray(0,this.bufferLength)},e.prototype.readBlock=function(){throw new it(this.constructor.name,"readBlock")},e.prototype.ensureBuffer=function(t){var r=this.buffer;if(t<=r.byteLength)return r;for(var n=this.minBufferLength;n<t;)n*=2;var i=new Uint8Array(n);return i.set(r),this.buffer=i},e}(),sl=function(e){return e===32||e===9||e===13||e===10},Sd=function(e){M(t,e);function t(r,n){var i=e.call(this,n)||this;return i.stream=r,i.input=new Uint8Array(5),n&&(n=.8*n),i}return t.prototype.readBlock=function(){for(var r=126,n=122,i=-1,a=this.stream,o=a.getByte();sl(o);)o=a.getByte();if(o===i||o===r){this.eof=!0;return}var s=this.bufferLength,l,c;if(o===n){for(l=this.ensureBuffer(s+4),c=0;c<4;++c)l[s+c]=0;this.bufferLength+=4}else{var u=this.input;for(u[0]=o,c=1;c<5;++c){for(o=a.getByte();sl(o);)o=a.getByte();if(u[c]=o,o===i||o===r)break}if(l=this.ensureBuffer(s+c-1),this.bufferLength+=c-1,c<5){for(;c<5;++c)u[c]=117;this.eof=!0}var h=0;for(c=0;c<5;++c)h=h*85+(u[c]-33);for(c=3;c>=0;--c)l[s+c]=h&255,h>>=8}},t}(kn),Fd=function(e){M(t,e);function t(r,n){var i=e.call(this,n)||this;return i.stream=r,i.firstDigit=-1,n&&(n=.5*n),i}return t.prototype.readBlock=function(){var r=8e3,n=this.stream.getBytes(r);if(!n.length){this.eof=!0;return}for(var i=n.length+1>>1,a=this.ensureBuffer(this.bufferLength+i),o=this.bufferLength,s=this.firstDigit,l=0,c=n.length;l<c;l++){var u=n[l],h=void 0;if(u>=48&&u<=57)h=u&15;else if(u>=65&&u<=70||u>=97&&u<=102)h=(u&15)+9;else if(u===62){this.eof=!0;break}else continue;s<0?s=h:(a[o++]=s<<4|h,s=-1)}s>=0&&this.eof&&(a[o++]=s<<4,s=-1),this.firstDigit=s,this.bufferLength=o},t}(kn),cl=new Int32Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),kd=new Int32Array([3,4,5,6,7,8,9,10,65547,65549,65551,65553,131091,131095,131099,131103,196643,196651,196659,196667,262211,262227,262243,262259,327811,327843,327875,327907,258,258,258]),Cd=new Int32Array([1,2,3,4,65541,65543,131081,131085,196625,196633,262177,262193,327745,327777,393345,393409,459009,459137,524801,525057,590849,591361,657409,658433,724993,727041,794625,798721,868353,876545]),Td=[new Int32Array([459008,524368,524304,524568,459024,524400,524336,590016,459016,524384,524320,589984,524288,524416,524352,590048,459012,524376,524312,589968,459028,524408,524344,590032,459020,524392,524328,59e4,524296,524424,524360,590064,459010,524372,524308,524572,459026,524404,524340,590024,459018,524388,524324,589992,524292,524420,524356,590056,459014,524380,524316,589976,459030,524412,524348,590040,459022,524396,524332,590008,524300,524428,524364,590072,459009,524370,524306,524570,459025,524402,524338,590020,459017,524386,524322,589988,524290,524418,524354,590052,459013,524378,524314,589972,459029,524410,524346,590036,459021,524394,524330,590004,524298,524426,524362,590068,459011,524374,524310,524574,459027,524406,524342,590028,459019,524390,524326,589996,524294,524422,524358,590060,459015,524382,524318,589980,459031,524414,524350,590044,459023,524398,524334,590012,524302,524430,524366,590076,459008,524369,524305,524569,459024,524401,524337,590018,459016,524385,524321,589986,524289,524417,524353,590050,459012,524377,524313,589970,459028,524409,524345,590034,459020,524393,524329,590002,524297,524425,524361,590066,459010,524373,524309,524573,459026,524405,524341,590026,459018,524389,524325,589994,524293,524421,524357,590058,459014,524381,524317,589978,459030,524413,524349,590042,459022,524397,524333,590010,524301,524429,524365,590074,459009,524371,524307,524571,459025,524403,524339,590022,459017,524387,524323,589990,524291,524419,524355,590054,459013,524379,524315,589974,459029,524411,524347,590038,459021,524395,524331,590006,524299,524427,524363,590070,459011,524375,524311,524575,459027,524407,524343,590030,459019,524391,524327,589998,524295,524423,524359,590062,459015,524383,524319,589982,459031,524415,524351,590046,459023,524399,524335,590014,524303,524431,524367,590078,459008,524368,524304,524568,459024,524400,524336,590017,459016,524384,524320,589985,524288,524416,524352,590049,459012,524376,524312,589969,459028,524408,524344,590033,459020,524392,524328,590001,524296,524424,524360,590065,459010,524372,524308,524572,459026,524404,524340,590025,459018,524388,524324,589993,524292,524420,524356,590057,459014,524380,524316,589977,459030,524412,524348,590041,459022,524396,524332,590009,524300,524428,524364,590073,459009,524370,524306,524570,459025,524402,524338,590021,459017,524386,524322,589989,524290,524418,524354,590053,459013,524378,524314,589973,459029,524410,524346,590037,459021,524394,524330,590005,524298,524426,524362,590069,459011,524374,524310,524574,459027,524406,524342,590029,459019,524390,524326,589997,524294,524422,524358,590061,459015,524382,524318,589981,459031,524414,524350,590045,459023,524398,524334,590013,524302,524430,524366,590077,459008,524369,524305,524569,459024,524401,524337,590019,459016,524385,524321,589987,524289,524417,524353,590051,459012,524377,524313,589971,459028,524409,524345,590035,459020,524393,524329,590003,524297,524425,524361,590067,459010,524373,524309,524573,459026,524405,524341,590027,459018,524389,524325,589995,524293,524421,524357,590059,459014,524381,524317,589979,459030,524413,524349,590043,459022,524397,524333,590011,524301,524429,524365,590075,459009,524371,524307,524571,459025,524403,524339,590023,459017,524387,524323,589991,524291,524419,524355,590055,459013,524379,524315,589975,459029,524411,524347,590039,459021,524395,524331,590007,524299,524427,524363,590071,459011,524375,524311,524575,459027,524407,524343,590031,459019,524391,524327,589999,524295,524423,524359,590063,459015,524383,524319,589983,459031,524415,524351,590047,459023,524399,524335,590015,524303,524431,524367,590079]),9],Pd=[new Int32Array([327680,327696,327688,327704,327684,327700,327692,327708,327682,327698,327690,327706,327686,327702,327694,0,327681,327697,327689,327705,327685,327701,327693,327709,327683,327699,327691,327707,327687,327703,327695,0]),5],Ad=function(e){M(t,e);function t(r,n){var i=e.call(this,n)||this;i.stream=r;var a=r.getByte(),o=r.getByte();if(a===-1||o===-1)throw new Error("Invalid header in flate stream: "+a+", "+o);if((a&15)!==8)throw new Error("Unknown compression method in flate stream: "+a+", "+o);if(((a<<8)+o)%31!==0)throw new Error("Bad FCHECK in flate stream: "+a+", "+o);if(o&32)throw new Error("FDICT bit set in flate stream: "+a+", "+o);return i.codeSize=0,i.codeBuf=0,i}return t.prototype.readBlock=function(){var r,n,i=this.stream,a=this.getBits(3);if(a&1&&(this.eof=!0),a>>=1,a===0){var o=void 0;if((o=i.getByte())===-1)throw new Error("Bad block header in flate stream");var s=o;if((o=i.getByte())===-1)throw new Error("Bad block header in flate stream");if(s|=o<<8,(o=i.getByte())===-1)throw new Error("Bad block header in flate stream");var l=o;if((o=i.getByte())===-1)throw new Error("Bad block header in flate stream");if(l|=o<<8,l!==(~s&65535)&&(s!==0||l!==0))throw new Error("Bad uncompressed block length in flate stream");this.codeBuf=0,this.codeSize=0;var c=this.bufferLength;r=this.ensureBuffer(c+s);var u=c+s;if(this.bufferLength=u,s===0)i.peekByte()===-1&&(this.eof=!0);else for(var h=c;h<u;++h){if((o=i.getByte())===-1){this.eof=!0;break}r[h]=o}return}var f,d;if(a===1)f=Td,d=Pd;else if(a===2){var v=this.getBits(5)+257,p=this.getBits(5)+1,m=this.getBits(4)+4,b=new Uint8Array(cl.length),k=void 0;for(k=0;k<m;++k)b[cl[k]]=this.getBits(3);var x=this.generateHuffmanTable(b);n=0,k=0;for(var T=v+p,w=new Uint8Array(T),F=void 0,A=void 0,D=void 0;k<T;){var O=this.getCode(x);if(O===16)F=2,A=3,D=n;else if(O===17)F=3,A=3,D=n=0;else if(O===18)F=7,A=11,D=n=0;else{w[k++]=n=O;continue}for(var B=this.getBits(F)+A;B-- >0;)w[k++]=D}f=this.generateHuffmanTable(w.subarray(0,v)),d=this.generateHuffmanTable(w.subarray(v,T))}else throw new Error("Unknown block type in flate stream");r=this.buffer;for(var E=r?r.length:0,j=this.bufferLength;;){var I=this.getCode(f);if(I<256){j+1>=E&&(r=this.ensureBuffer(j+1),E=r.length),r[j++]=I;continue}if(I===256){this.bufferLength=j;return}I-=257,I=kd[I];var L=I>>16;L>0&&(L=this.getBits(L)),n=(I&65535)+L,I=this.getCode(d),I=Cd[I],L=I>>16,L>0&&(L=this.getBits(L));var z=(I&65535)+L;j+n>=E&&(r=this.ensureBuffer(j+n),E=r.length);for(var P=0;P<n;++P,++j)r[j]=r[j-z]}},t.prototype.getBits=function(r){for(var n=this.stream,i=this.codeSize,a=this.codeBuf,o;i<r;){if((o=n.getByte())===-1)throw new Error("Bad encoding in flate stream");a|=o<<i,i+=8}return o=a&(1<<r)-1,this.codeBuf=a>>r,this.codeSize=i-=r,o},t.prototype.getCode=function(r){for(var n=this.stream,i=r[0],a=r[1],o=this.codeSize,s=this.codeBuf,l;o<a&&(l=n.getByte())!==-1;)s|=l<<o,o+=8;var c=i[s&(1<<a)-1];typeof i=="number"&&console.log("FLATE:",c);var u=c>>16,h=c&65535;if(u<1||o<u)throw new Error("Bad encoding in flate stream");return this.codeBuf=s>>u,this.codeSize=o-u,h},t.prototype.generateHuffmanTable=function(r){var n=r.length,i=0,a;for(a=0;a<n;++a)r[a]>i&&(i=r[a]);for(var o=1<<i,s=new Int32Array(o),l=1,c=0,u=2;l<=i;++l,c<<=1,u<<=1)for(var h=0;h<n;++h)if(r[h]===l){var f=0,d=c;for(a=0;a<l;++a)f=f<<1|d&1,d>>=1;for(a=f;a<o;a+=u)s[a]=l<<16|h;++c}return[s,i]},t}(kn),Dd=function(e){M(t,e);function t(r,n,i){var a=e.call(this,n)||this;a.stream=r,a.cachedData=0,a.bitsCached=0;for(var o=4096,s={earlyChange:i,codeLength:9,nextCode:258,dictionaryValues:new Uint8Array(o),dictionaryLengths:new Uint16Array(o),dictionaryPrevCodes:new Uint16Array(o),currentSequence:new Uint8Array(o),currentSequenceLength:0},l=0;l<256;++l)s.dictionaryValues[l]=l,s.dictionaryLengths[l]=1;return a.lzwState=s,a}return t.prototype.readBlock=function(){var r=512,n=r*2,i=r,a,o,s,l=this.lzwState;if(l){var c=l.earlyChange,u=l.nextCode,h=l.dictionaryValues,f=l.dictionaryLengths,d=l.dictionaryPrevCodes,v=l.codeLength,p=l.prevCode,m=l.currentSequence,b=l.currentSequenceLength,k=0,x=this.bufferLength,T=this.ensureBuffer(this.bufferLength+n);for(a=0;a<r;a++){var w=this.readBits(v),F=b>0;if(!w||w<256)m[0]=w,b=1;else if(w>=258)if(w<u)for(b=f[w],o=b-1,s=w;o>=0;o--)m[o]=h[s],s=d[s];else m[b++]=m[0];else if(w===256){v=9,u=258,b=0;continue}else{this.eof=!0,delete this.lzwState;break}if(F&&(d[u]=p,f[u]=f[p]+1,h[u]=m[0],u++,v=u+c&u+c-1?v:Math.min(Math.log(u+c)/.6931471805599453+1,12)|0),p=w,k+=b,n<k){do n+=i;while(n<k);T=this.ensureBuffer(this.bufferLength+n)}for(o=0;o<b;o++)T[x++]=m[o]}l.nextCode=u,l.codeLength=v,l.prevCode=p,l.currentSequenceLength=b,this.bufferLength=x}},t.prototype.readBits=function(r){for(var n=this.bitsCached,i=this.cachedData;n<r;){var a=this.stream.getByte();if(a===-1)return this.eof=!0,null;i=i<<8|a,n+=8}return this.bitsCached=n-=r,this.cachedData=i,i>>>n&(1<<r)-1},t}(kn),Ed=function(e){M(t,e);function t(r,n){var i=e.call(this,n)||this;return i.stream=r,i}return t.prototype.readBlock=function(){var r=this.stream.getBytes(2);if(!r||r.length<2||r[0]===128){this.eof=!0;return}var n,i=this.bufferLength,a=r[0];if(a<128){if(n=this.ensureBuffer(i+a+1),n[i++]=r[1],a>0){var o=this.stream.getBytes(a);n.set(o,i),i+=a}}else{a=257-a;var s=r[1];n=this.ensureBuffer(i+a+1);for(var l=0;l<a;l++)n[i++]=s}this.bufferLength=i},t}(kn),ll=function(e,t,r){if(t===g.of("FlateDecode"))return new Ad(e);if(t===g.of("LZWDecode")){var n=1;if(r instanceof Q){var i=r.lookup(g.of("EarlyChange"));i instanceof H&&(n=i.asNumber())}return new Dd(e,void 0,n)}if(t===g.of("ASCII85Decode"))return new Sd(e);if(t===g.of("ASCIIHexDecode"))return new Fd(e);if(t===g.of("RunLengthDecode"))return new Ed(e);throw new Uh(t.asString())},ul=function(e){var t=e.dict,r=e.contents,n=new ol(r),i=t.lookup(g.of("Filter")),a=t.lookup(g.of("DecodeParms"));if(i instanceof g)n=ll(n,i,a);else if(i instanceof fe)for(var o=0,s=i.size();o<s;o++)n=ll(n,i.lookup(o,g),a&&a.lookupMaybe(o,Q));else if(i)throw new vi([g,fe],i);return n},Od=function(e){var t=e.MediaBox(),r=t.lookup(2,H).asNumber()-t.lookup(0,H).asNumber(),n=t.lookup(3,H).asNumber()-t.lookup(1,H).asNumber();return{left:0,bottom:0,right:r,top:n}},Rd=function(e){return[1,0,0,1,-e.left,-e.bottom]},fl=function(){function e(t,r,n){this.page=t;var i=r??Od(t);this.width=i.right-i.left,this.height=i.top-i.bottom,this.boundingBox=i,this.transformationMatrix=n??Rd(i)}return e.for=function(t,r,n){return _(this,void 0,void 0,function(){return $(this,function(i){return[2,new e(t,r,n)]})})},e.prototype.embedIntoContext=function(t,r){return _(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u,h,f;return $(this,function(d){if(n=this.page.normalizedEntries(),i=n.Contents,a=n.Resources,!i)throw new Lh;return o=this.decodeContents(i),s=this.boundingBox,l=s.left,c=s.bottom,u=s.right,h=s.top,f=t.flateStream(o,{Type:"XObject",Subtype:"Form",FormType:1,BBox:[l,c,u,h],Matrix:this.transformationMatrix,Resources:a}),r?(t.assign(r,f),[2,r]):[2,t.register(f)]})})},e.prototype.decodeContents=function(t){for(var r=Uint8Array.of(y.Newline),n=[],i=0,a=t.size();i<a;i++){var o=t.lookup(i,Qe),s=void 0;if(o instanceof Sn)s=ul(o).decode();else if(o instanceof Fn)s=o.getUnencodedContents();else throw new Vh(o);n.push(s,r)}return yu.apply(void 0,n)},e}(),mi=function(e,t){if(e!==void 0)return t[e]},Cn;(function(e){e.UseNone="UseNone",e.UseOutlines="UseOutlines",e.UseThumbs="UseThumbs",e.UseOC="UseOC"})(Cn||(Cn={}));var Tn;(function(e){e.L2R="L2R",e.R2L="R2L"})(Tn||(Tn={}));var Pn;(function(e){e.None="None",e.AppDefault="AppDefault"})(Pn||(Pn={}));var xi;(function(e){e.Simplex="Simplex",e.DuplexFlipShortEdge="DuplexFlipShortEdge",e.DuplexFlipLongEdge="DuplexFlipLongEdge"})(xi||(xi={}));var hl=function(){function e(t){this.dict=t}return e.prototype.lookupBool=function(t){var r=this.dict.lookup(g.of(t));if(r instanceof xn)return r},e.prototype.lookupName=function(t){var r=this.dict.lookup(g.of(t));if(r instanceof g)return r},e.prototype.HideToolbar=function(){return this.lookupBool("HideToolbar")},e.prototype.HideMenubar=function(){return this.lookupBool("HideMenubar")},e.prototype.HideWindowUI=function(){return this.lookupBool("HideWindowUI")},e.prototype.FitWindow=function(){return this.lookupBool("FitWindow")},e.prototype.CenterWindow=function(){return this.lookupBool("CenterWindow")},e.prototype.DisplayDocTitle=function(){return this.lookupBool("DisplayDocTitle")},e.prototype.NonFullScreenPageMode=function(){return this.lookupName("NonFullScreenPageMode")},e.prototype.Direction=function(){return this.lookupName("Direction")},e.prototype.PrintScaling=function(){return this.lookupName("PrintScaling")},e.prototype.Duplex=function(){return this.lookupName("Duplex")},e.prototype.PickTrayByPDFSize=function(){return this.lookupBool("PickTrayByPDFSize")},e.prototype.PrintPageRange=function(){var t=this.dict.lookup(g.of("PrintPageRange"));if(t instanceof fe)return t},e.prototype.NumCopies=function(){var t=this.dict.lookup(g.of("NumCopies"));if(t instanceof H)return t},e.prototype.getHideToolbar=function(){var t,r;return(r=(t=this.HideToolbar())===null||t===void 0?void 0:t.asBoolean())!==null&&r!==void 0?r:!1},e.prototype.getHideMenubar=function(){var t,r;return(r=(t=this.HideMenubar())===null||t===void 0?void 0:t.asBoolean())!==null&&r!==void 0?r:!1},e.prototype.getHideWindowUI=function(){var t,r;return(r=(t=this.HideWindowUI())===null||t===void 0?void 0:t.asBoolean())!==null&&r!==void 0?r:!1},e.prototype.getFitWindow=function(){var t,r;return(r=(t=this.FitWindow())===null||t===void 0?void 0:t.asBoolean())!==null&&r!==void 0?r:!1},e.prototype.getCenterWindow=function(){var t,r;return(r=(t=this.CenterWindow())===null||t===void 0?void 0:t.asBoolean())!==null&&r!==void 0?r:!1},e.prototype.getDisplayDocTitle=function(){var t,r;return(r=(t=this.DisplayDocTitle())===null||t===void 0?void 0:t.asBoolean())!==null&&r!==void 0?r:!1},e.prototype.getNonFullScreenPageMode=function(){var t,r,n=(t=this.NonFullScreenPageMode())===null||t===void 0?void 0:t.decodeText();return(r=mi(n,Cn))!==null&&r!==void 0?r:Cn.UseNone},e.prototype.getReadingDirection=function(){var t,r,n=(t=this.Direction())===null||t===void 0?void 0:t.decodeText();return(r=mi(n,Tn))!==null&&r!==void 0?r:Tn.L2R},e.prototype.getPrintScaling=function(){var t,r,n=(t=this.PrintScaling())===null||t===void 0?void 0:t.decodeText();return(r=mi(n,Pn))!==null&&r!==void 0?r:Pn.AppDefault},e.prototype.getDuplex=function(){var t,r=(t=this.Duplex())===null||t===void 0?void 0:t.decodeText();return mi(r,xi)},e.prototype.getPickTrayByPDFSize=function(){var t;return(t=this.PickTrayByPDFSize())===null||t===void 0?void 0:t.asBoolean()},e.prototype.getPrintPageRange=function(){var t=this.PrintPageRange();if(!t)return[];for(var r=[],n=0;n<t.size();n+=2){var i=t.lookup(n,H).asNumber(),a=t.lookup(n+1,H).asNumber();r.push({start:i,end:a})}return r},e.prototype.getNumCopies=function(){var t,r;return(r=(t=this.NumCopies())===null||t===void 0?void 0:t.asNumber())!==null&&r!==void 0?r:1},e.prototype.setHideToolbar=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("HideToolbar"),r)},e.prototype.setHideMenubar=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("HideMenubar"),r)},e.prototype.setHideWindowUI=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("HideWindowUI"),r)},e.prototype.setFitWindow=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("FitWindow"),r)},e.prototype.setCenterWindow=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("CenterWindow"),r)},e.prototype.setDisplayDocTitle=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("DisplayDocTitle"),r)},e.prototype.setNonFullScreenPageMode=function(t){Gt(t,"nonFullScreenPageMode",Cn);var r=g.of(t);this.dict.set(g.of("NonFullScreenPageMode"),r)},e.prototype.setReadingDirection=function(t){Gt(t,"readingDirection",Tn);var r=g.of(t);this.dict.set(g.of("Direction"),r)},e.prototype.setPrintScaling=function(t){Gt(t,"printScaling",Pn);var r=g.of(t);this.dict.set(g.of("PrintScaling"),r)},e.prototype.setDuplex=function(t){Gt(t,"duplex",xi);var r=g.of(t);this.dict.set(g.of("Duplex"),r)},e.prototype.setPickTrayByPDFSize=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("PickTrayByPDFSize"),r)},e.prototype.setPrintPageRange=function(t){Array.isArray(t)||(t=[t]);for(var r=[],n=0,i=t.length;n<i;n++)r.push(t[n].start),r.push(t[n].end);Lc(r,"printPageRange",["number"]);var a=this.dict.context.obj(r);this.dict.set(g.of("PrintPageRange"),a)},e.prototype.setNumCopies=function(t){Je(t,"numCopies",1,Number.MAX_VALUE),zh(t,"numCopies");var r=this.dict.context.obj(t);this.dict.set(g.of("NumCopies"),r)},e.fromDict=function(t){return new e(t)},e.create=function(t){var r=t.obj({});return new e(r)},e}(),Id=/\/([^\0\t\n\f\r\ ]+)[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]+Tf/,dl=function(){function e(t,r){this.dict=t,this.ref=r}return e.prototype.T=function(){return this.dict.lookupMaybe(g.of("T"),pe,G)},e.prototype.Ff=function(){var t=this.getInheritableAttribute(g.of("Ff"));return this.dict.context.lookupMaybe(t,H)},e.prototype.V=function(){var t=this.getInheritableAttribute(g.of("V"));return this.dict.context.lookup(t)},e.prototype.Kids=function(){return this.dict.lookupMaybe(g.of("Kids"),fe)},e.prototype.DA=function(){var t=this.dict.lookup(g.of("DA"));if(t instanceof pe||t instanceof G)return t},e.prototype.setKids=function(t){this.dict.set(g.of("Kids"),this.dict.context.obj(t))},e.prototype.getParent=function(){var t=this.dict.get(g.of("Parent"));if(t instanceof ve){var r=this.dict.lookup(g.of("Parent"),Q);return new e(r,t)}},e.prototype.setParent=function(t){t?this.dict.set(g.of("Parent"),t):this.dict.delete(g.of("Parent"))},e.prototype.getFullyQualifiedName=function(){var t=this.getParent();return t?t.getFullyQualifiedName()+"."+this.getPartialName():this.getPartialName()},e.prototype.getPartialName=function(){var t;return(t=this.T())===null||t===void 0?void 0:t.decodeText()},e.prototype.setPartialName=function(t){t?this.dict.set(g.of("T"),G.fromText(t)):this.dict.delete(g.of("T"))},e.prototype.setDefaultAppearance=function(t){this.dict.set(g.of("DA"),pe.of(t))},e.prototype.getDefaultAppearance=function(){var t=this.DA();return t instanceof G?t.decodeText():t==null?void 0:t.asString()},e.prototype.setFontSize=function(t){var r,n=(r=this.getFullyQualifiedName())!==null&&r!==void 0?r:"",i=this.getDefaultAppearance();if(!i)throw new Kh(n);var a=Qi(i,Id);if(!a.match)throw new Hh(n);var o=i.slice(0,a.pos-a.match[0].length),s=a.pos<=i.length?i.slice(a.pos):"",l=a.match[1],c=o+" /"+l+" "+t+" Tf "+s;this.setDefaultAppearance(c)},e.prototype.getFlags=function(){var t,r;return(r=(t=this.Ff())===null||t===void 0?void 0:t.asNumber())!==null&&r!==void 0?r:0},e.prototype.setFlags=function(t){this.dict.set(g.of("Ff"),H.of(t))},e.prototype.hasFlag=function(t){var r=this.getFlags();return(r&t)!==0},e.prototype.setFlag=function(t){var r=this.getFlags();this.setFlags(r|t)},e.prototype.clearFlag=function(t){var r=this.getFlags();this.setFlags(r&~t)},e.prototype.setFlagTo=function(t,r){r?this.setFlag(t):this.clearFlag(t)},e.prototype.getInheritableAttribute=function(t){var r;return this.ascend(function(n){r||(r=n.dict.get(t))}),r},e.prototype.ascend=function(t){t(this);var r=this.getParent();r&&r.ascend(t)},e}(),Va=function(){function e(t){this.dict=t}return e.prototype.W=function(){var t=this.dict.lookup(g.of("W"));if(t instanceof H)return t},e.prototype.getWidth=function(){var t,r;return(r=(t=this.W())===null||t===void 0?void 0:t.asNumber())!==null&&r!==void 0?r:1},e.prototype.setWidth=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("W"),r)},e.fromDict=function(t){return new e(t)},e}(),Nd=function(){function e(t){this.dict=t}return e.prototype.Rect=function(){return this.dict.lookup(g.of("Rect"),fe)},e.prototype.AP=function(){return this.dict.lookupMaybe(g.of("AP"),Q)},e.prototype.F=function(){var t=this.dict.lookup(g.of("F"));return this.dict.context.lookupMaybe(t,H)},e.prototype.getRectangle=function(){var t,r=this.Rect();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:{x:0,y:0,width:0,height:0}},e.prototype.setRectangle=function(t){var r=t.x,n=t.y,i=t.width,a=t.height,o=this.dict.context.obj([r,n,r+i,n+a]);this.dict.set(g.of("Rect"),o)},e.prototype.getAppearanceState=function(){var t=this.dict.lookup(g.of("AS"));if(t instanceof g)return t},e.prototype.setAppearanceState=function(t){this.dict.set(g.of("AS"),t)},e.prototype.setAppearances=function(t){this.dict.set(g.of("AP"),t)},e.prototype.ensureAP=function(){var t=this.AP();return t||(t=this.dict.context.obj({}),this.dict.set(g.of("AP"),t)),t},e.prototype.getNormalAppearance=function(){var t=this.ensureAP(),r=t.get(g.of("N"));if(r instanceof ve||r instanceof Q)return r;throw new Error("Unexpected N type: "+(r==null?void 0:r.constructor.name))},e.prototype.setNormalAppearance=function(t){var r=this.ensureAP();r.set(g.of("N"),t)},e.prototype.setRolloverAppearance=function(t){var r=this.ensureAP();r.set(g.of("R"),t)},e.prototype.setDownAppearance=function(t){var r=this.ensureAP();r.set(g.of("D"),t)},e.prototype.removeRolloverAppearance=function(){var t=this.AP();t==null||t.delete(g.of("R"))},e.prototype.removeDownAppearance=function(){var t=this.AP();t==null||t.delete(g.of("D"))},e.prototype.getAppearances=function(){var t=this.AP();if(t){var r=t.lookup(g.of("N"),Q,Qe),n=t.lookupMaybe(g.of("R"),Q,Qe),i=t.lookupMaybe(g.of("D"),Q,Qe);return{normal:r,rollover:n,down:i}}},e.prototype.getFlags=function(){var t,r;return(r=(t=this.F())===null||t===void 0?void 0:t.asNumber())!==null&&r!==void 0?r:0},e.prototype.setFlags=function(t){this.dict.set(g.of("F"),H.of(t))},e.prototype.hasFlag=function(t){var r=this.getFlags();return(r&t)!==0},e.prototype.setFlag=function(t){var r=this.getFlags();this.setFlags(r|t)},e.prototype.clearFlag=function(t){var r=this.getFlags();this.setFlags(r&~t)},e.prototype.setFlagTo=function(t,r){r?this.setFlag(t):this.clearFlag(t)},e.fromDict=function(t){return new e(t)},e}(),Wa=function(){function e(t){this.dict=t}return e.prototype.R=function(){var t=this.dict.lookup(g.of("R"));if(t instanceof H)return t},e.prototype.BC=function(){var t=this.dict.lookup(g.of("BC"));if(t instanceof fe)return t},e.prototype.BG=function(){var t=this.dict.lookup(g.of("BG"));if(t instanceof fe)return t},e.prototype.CA=function(){var t=this.dict.lookup(g.of("CA"));if(t instanceof G||t instanceof pe)return t},e.prototype.RC=function(){var t=this.dict.lookup(g.of("RC"));if(t instanceof G||t instanceof pe)return t},e.prototype.AC=function(){var t=this.dict.lookup(g.of("AC"));if(t instanceof G||t instanceof pe)return t},e.prototype.getRotation=function(){var t;return(t=this.R())===null||t===void 0?void 0:t.asNumber()},e.prototype.getBorderColor=function(){var t=this.BC();if(t){for(var r=[],n=0,i=t==null?void 0:t.size();n<i;n++){var a=t.get(n);a instanceof H&&r.push(a.asNumber())}return r}},e.prototype.getBackgroundColor=function(){var t=this.BG();if(t){for(var r=[],n=0,i=t==null?void 0:t.size();n<i;n++){var a=t.get(n);a instanceof H&&r.push(a.asNumber())}return r}},e.prototype.getCaptions=function(){var t=this.CA(),r=this.RC(),n=this.AC();return{normal:t==null?void 0:t.decodeText(),rollover:r==null?void 0:r.decodeText(),down:n==null?void 0:n.decodeText()}},e.prototype.setRotation=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("R"),r)},e.prototype.setBorderColor=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("BC"),r)},e.prototype.setBackgroundColor=function(t){var r=this.dict.context.obj(t);this.dict.set(g.of("BG"),r)},e.prototype.setCaptions=function(t){var r=G.fromText(t.normal);if(this.dict.set(g.of("CA"),r),t.rollover){var n=G.fromText(t.rollover);this.dict.set(g.of("RC"),n)}else this.dict.delete(g.of("RC"));if(t.down){var i=G.fromText(t.down);this.dict.set(g.of("AC"),i)}else this.dict.delete(g.of("AC"))},e.fromDict=function(t){return new e(t)},e}(),qa=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.MK=function(){var r=this.dict.lookup(g.of("MK"));if(r instanceof Q)return r},t.prototype.BS=function(){var r=this.dict.lookup(g.of("BS"));if(r instanceof Q)return r},t.prototype.DA=function(){var r=this.dict.lookup(g.of("DA"));if(r instanceof pe||r instanceof G)return r},t.prototype.P=function(){var r=this.dict.get(g.of("P"));if(r instanceof ve)return r},t.prototype.setP=function(r){this.dict.set(g.of("P"),r)},t.prototype.setDefaultAppearance=function(r){this.dict.set(g.of("DA"),pe.of(r))},t.prototype.getDefaultAppearance=function(){var r=this.DA();return r instanceof G?r.decodeText():r==null?void 0:r.asString()},t.prototype.getAppearanceCharacteristics=function(){var r=this.MK();if(r)return Wa.fromDict(r)},t.prototype.getOrCreateAppearanceCharacteristics=function(){var r=this.MK();if(r)return Wa.fromDict(r);var n=Wa.fromDict(this.dict.context.obj({}));return this.dict.set(g.of("MK"),n.dict),n},t.prototype.getBorderStyle=function(){var r=this.BS();if(r)return Va.fromDict(r)},t.prototype.getOrCreateBorderStyle=function(){var r=this.BS();if(r)return Va.fromDict(r);var n=Va.fromDict(this.dict.context.obj({}));return this.dict.set(g.of("BS"),n.dict),n},t.prototype.getOnValue=function(){var r,n=(r=this.getAppearances())===null||r===void 0?void 0:r.normal;if(n instanceof Q)for(var i=n.keys(),a=0,o=i.length;a<o;a++){var s=i[a];if(s!==g.of("Off"))return s}},t.fromDict=function(r){return new t(r)},t.create=function(r,n){var i=r.obj({Type:"Annot",Subtype:"Widget",Rect:[0,0,0,0],Parent:n});return new t(i)},t}(Nd),Mr=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.FT=function(){var r=this.getInheritableAttribute(g.of("FT"));return this.dict.context.lookup(r,g)},t.prototype.getWidgets=function(){var r=this.Kids();if(!r)return[qa.fromDict(this.dict)];for(var n=new Array(r.size()),i=0,a=r.size();i<a;i++){var o=r.lookup(i,Q);n[i]=qa.fromDict(o)}return n},t.prototype.addWidget=function(r){var n=this.normalizedEntries().Kids;n.push(r)},t.prototype.removeWidget=function(r){var n=this.Kids();if(n){if(r<0||r>n.size())throw new pi(r,0,n.size());n.remove(r)}else{if(r!==0)throw new pi(r,0,0);this.setKids([])}},t.prototype.normalizedEntries=function(){var r=this.Kids();return r||(r=this.dict.context.obj([this.ref]),this.dict.set(g.of("Kids"),r)),{Kids:r}},t.fromDict=function(r,n){return new t(r,n)},t}(dl),Ga=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.Opt=function(){return this.dict.lookupMaybe(g.of("Opt"),pe,G,fe)},t.prototype.setOpt=function(r){this.dict.set(g.of("Opt"),this.dict.context.obj(r))},t.prototype.getExportValues=function(){var r=this.Opt();if(r){if(r instanceof pe||r instanceof G)return[r];for(var n=[],i=0,a=r.size();i<a;i++){var o=r.lookup(i);(o instanceof pe||o instanceof G)&&n.push(o)}return n}},t.prototype.removeExportValue=function(r){var n=this.Opt();if(n)if(n instanceof pe||n instanceof G){if(r!==0)throw new pi(r,0,0);this.setOpt([])}else{if(r<0||r>n.size())throw new pi(r,0,n.size());n.remove(r)}},t.prototype.normalizeExportValues=function(){for(var r,n,i,a,o=(r=this.getExportValues())!==null&&r!==void 0?r:[],s=[],l=this.getWidgets(),c=0,u=l.length;c<u;c++){var h=l[c],f=(n=o[c])!==null&&n!==void 0?n:G.fromText((a=(i=h.getOnValue())===null||i===void 0?void 0:i.decodeText())!==null&&a!==void 0?a:"");s.push(f)}this.setOpt(s)},t.prototype.addOpt=function(r,n){var i;this.normalizeExportValues();var a=r.decodeText(),o;if(n)for(var s=(i=this.getExportValues())!==null&&i!==void 0?i:[],l=0,c=s.length;l<c;l++){var u=s[l];u.decodeText()===a&&(o=l)}var h=this.Opt();return h.push(r),o??h.size()-1},t.prototype.addWidgetWithOpt=function(r,n,i){var a=this.addOpt(n,i),o=g.of(String(a));return this.addWidget(r),o},t}(Mr),wi=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.setValue=function(r){var n,i=(n=this.getOnValue())!==null&&n!==void 0?n:g.of("Yes");if(r!==i&&r!==g.of("Off"))throw new Oa;this.dict.set(g.of("V"),r);for(var a=this.getWidgets(),o=0,s=a.length;o<s;o++){var l=a[o],c=l.getOnValue()===r?r:g.of("Off");l.setAppearanceState(c)}},t.prototype.getValue=function(){var r=this.V();return r instanceof g?r:g.of("Off")},t.prototype.getOnValue=function(){var r=this.getWidgets()[0];return r==null?void 0:r.getOnValue()},t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({FT:"Btn",Kids:[]}),i=r.register(n);return new t(n,i)},t}(Ga),Ce=function(e){return 1<<e},pt;(function(e){e[e.ReadOnly=Ce(0)]="ReadOnly",e[e.Required=Ce(1)]="Required",e[e.NoExport=Ce(2)]="NoExport"})(pt||(pt={}));var ot;(function(e){e[e.NoToggleToOff=Ce(14)]="NoToggleToOff",e[e.Radio=Ce(15)]="Radio",e[e.PushButton=Ce(16)]="PushButton",e[e.RadiosInUnison=Ce(25)]="RadiosInUnison"})(ot||(ot={}));var Se;(function(e){e[e.Multiline=Ce(12)]="Multiline",e[e.Password=Ce(13)]="Password",e[e.FileSelect=Ce(20)]="FileSelect",e[e.DoNotSpellCheck=Ce(22)]="DoNotSpellCheck",e[e.DoNotScroll=Ce(23)]="DoNotScroll",e[e.Comb=Ce(24)]="Comb",e[e.RichText=Ce(25)]="RichText"})(Se||(Se={}));var ge;(function(e){e[e.Combo=Ce(17)]="Combo",e[e.Edit=Ce(18)]="Edit",e[e.Sort=Ce(19)]="Sort",e[e.MultiSelect=Ce(21)]="MultiSelect",e[e.DoNotSpellCheck=Ce(22)]="DoNotSpellCheck",e[e.CommitOnSelChange=Ce(26)]="CommitOnSelChange"})(ge||(ge={}));var vl=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.setValues=function(r){if(this.hasFlag(ge.Combo)&&!this.hasFlag(ge.Edit)&&!this.valuesAreValid(r))throw new Oa;if(r.length===0&&this.dict.delete(g.of("V")),r.length===1&&this.dict.set(g.of("V"),r[0]),r.length>1){if(!this.hasFlag(ge.MultiSelect))throw new Gh;this.dict.set(g.of("V"),this.dict.context.obj(r))}this.updateSelectedIndices(r)},t.prototype.valuesAreValid=function(r){for(var n=this.getOptions(),i=function(l,c){var u=r[l].decodeText();if(!n.find(function(h){return u===(h.display||h.value).decodeText()}))return{value:!1}},a=0,o=r.length;a<o;a++){var s=i(a);if(typeof s=="object")return s.value}return!0},t.prototype.updateSelectedIndices=function(r){if(r.length>1){for(var n=new Array(r.length),i=this.getOptions(),a=function(l,c){var u=r[l].decodeText();n[l]=i.findIndex(function(h){return u===(h.display||h.value).decodeText()})},o=0,s=r.length;o<s;o++)a(o,s);this.dict.set(g.of("I"),this.dict.context.obj(n.sort()))}else this.dict.delete(g.of("I"))},t.prototype.getValues=function(){var r=this.V();if(r instanceof pe||r instanceof G)return[r];if(r instanceof fe){for(var n=[],i=0,a=r.size();i<a;i++){var o=r.lookup(i);(o instanceof pe||o instanceof G)&&n.push(o)}return n}return[]},t.prototype.Opt=function(){return this.dict.lookupMaybe(g.of("Opt"),pe,G,fe)},t.prototype.setOptions=function(r){for(var n=new Array(r.length),i=0,a=r.length;i<a;i++){var o=r[i],s=o.value,l=o.display;n[i]=this.dict.context.obj([s,l||s])}this.dict.set(g.of("Opt"),this.dict.context.obj(n))},t.prototype.getOptions=function(){var r=this.Opt();if(r instanceof pe||r instanceof G)return[{value:r,display:r}];if(r instanceof fe){for(var n=[],i=0,a=r.size();i<a;i++){var o=r.lookup(i);if((o instanceof pe||o instanceof G)&&n.push({value:o,display:o}),o instanceof fe&&o.size()>0){var s=o.lookup(0,pe,G),l=o.lookupMaybe(1,pe,G);n.push({value:s,display:l||s})}}return n}return[]},t}(Mr),Si=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({FT:"Ch",Ff:ge.Combo,Kids:[]}),i=r.register(n);return new t(n,i)},t}(vl),Fi=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.addField=function(r){var n=this.normalizedEntries().Kids;n==null||n.push(r)},t.prototype.normalizedEntries=function(){var r=this.Kids();return r||(r=this.dict.context.obj([]),this.dict.set(g.of("Kids"),r)),{Kids:r}},t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({}),i=r.register(n);return new t(n,i)},t}(dl),Ka=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.fromDict=function(r,n){return new t(r,n)},t}(Mr),ki=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.MaxLen=function(){var r=this.dict.lookup(g.of("MaxLen"));if(r instanceof H)return r},t.prototype.Q=function(){var r=this.dict.lookup(g.of("Q"));if(r instanceof H)return r},t.prototype.setMaxLength=function(r){this.dict.set(g.of("MaxLen"),H.of(r))},t.prototype.removeMaxLength=function(){this.dict.delete(g.of("MaxLen"))},t.prototype.getMaxLength=function(){var r;return(r=this.MaxLen())===null||r===void 0?void 0:r.asNumber()},t.prototype.setQuadding=function(r){this.dict.set(g.of("Q"),H.of(r))},t.prototype.getQuadding=function(){var r;return(r=this.Q())===null||r===void 0?void 0:r.asNumber()},t.prototype.setValue=function(r){this.dict.set(g.of("V"),r)},t.prototype.removeValue=function(){this.dict.delete(g.of("V"))},t.prototype.getValue=function(){var r=this.V();if(r instanceof pe||r instanceof G)return r},t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({FT:"Tx",Kids:[]}),i=r.register(n);return new t(n,i)},t}(Mr),Ci=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({FT:"Btn",Ff:ot.PushButton,Kids:[]}),i=r.register(n);return new t(n,i)},t}(Ga),Ti=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.setValue=function(r){var n=this.getOnValues();if(!n.includes(r)&&r!==g.of("Off"))throw new Oa;this.dict.set(g.of("V"),r);for(var i=this.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a],l=s.getOnValue()===r?r:g.of("Off");s.setAppearanceState(l)}},t.prototype.getValue=function(){var r=this.V();return r instanceof g?r:g.of("Off")},t.prototype.getOnValues=function(){for(var r=this.getWidgets(),n=[],i=0,a=r.length;i<a;i++){var o=r[i].getOnValue();o&&n.push(o)}return n},t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({FT:"Btn",Ff:ot.Radio,Kids:[]}),i=r.register(n);return new t(n,i)},t}(Ga),Pi=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.fromDict=function(r,n){return new t(r,n)},t.create=function(r){var n=r.obj({FT:"Ch",Kids:[]}),i=r.register(n);return new t(n,i)},t}(vl),Ha=function(e){if(!e)return[];for(var t=[],r=0,n=e.size();r<n;r++){var i=e.get(r),a=e.lookup(r);i instanceof ve&&a instanceof Q&&t.push([pl(a,i),i])}return t},pl=function(e,t){var r=Bd(e);return r?Fi.fromDict(e,t):Md(e,t)},Bd=function(e){var t=e.lookup(g.of("Kids"));if(t instanceof fe)for(var r=0,n=t.size();r<n;r++){var i=t.lookup(r),a=i instanceof Q&&i.has(g.of("T"));if(a)return!0}return!1},Md=function(e,t){var r=Za(e,g.of("FT")),n=e.context.lookup(r,g);return n===g.of("Btn")?jd(e,t):n===g.of("Ch")?zd(e,t):n===g.of("Tx")?ki.fromDict(e,t):n===g.of("Sig")?Ka.fromDict(e,t):Mr.fromDict(e,t)},jd=function(e,t){var r,n=Za(e,g.of("Ff")),i=e.context.lookupMaybe(n,H),a=(r=i==null?void 0:i.asNumber())!==null&&r!==void 0?r:0;return Xa(a,ot.PushButton)?Ci.fromDict(e,t):Xa(a,ot.Radio)?Ti.fromDict(e,t):wi.fromDict(e,t)},zd=function(e,t){var r,n=Za(e,g.of("Ff")),i=e.context.lookupMaybe(n,H),a=(r=i==null?void 0:i.asNumber())!==null&&r!==void 0?r:0;return Xa(a,ge.Combo)?Si.fromDict(e,t):Pi.fromDict(e,t)},Xa=function(e,t){return(e&t)!==0},Za=function(e,t){var r;return gl(e,function(n){r||(r=n.get(t))}),r},gl=function(e,t){t(e);var r=e.lookupMaybe(g.of("Parent"),Q);r&&gl(r,t)},Ai=function(){function e(t){this.dict=t}return e.prototype.Fields=function(){var t=this.dict.lookup(g.of("Fields"));if(t instanceof fe)return t},e.prototype.getFields=function(){for(var t=this.normalizedEntries().Fields,r=new Array(t.size()),n=0,i=t.size();n<i;n++){var a=t.get(n),o=t.lookup(n,Q);r[n]=[pl(o,a),a]}return r},e.prototype.getAllFields=function(){var t=[],r=function(n){if(n)for(var i=0,a=n.length;i<a;i++){var o=n[i];t.push(o);var s=o[0];s instanceof Fi&&r(Ha(s.Kids()))}};return r(this.getFields()),t},e.prototype.addField=function(t){var r=this.normalizedEntries().Fields;r==null||r.push(t)},e.prototype.removeField=function(t){var r=t.getParent(),n=r===void 0?this.normalizedEntries().Fields:r.Kids(),i=n==null?void 0:n.indexOf(t.ref);if(n===void 0||i===void 0)throw new Error("Tried to remove inexistent field "+t.getFullyQualifiedName());n.remove(i),r!==void 0&&n.size()===0&&this.removeField(r)},e.prototype.normalizedEntries=function(){var t=this.Fields();return t||(t=this.dict.context.obj([]),this.dict.set(g.of("Fields"),t)),{Fields:t}},e.fromDict=function(t){return new e(t)},e.create=function(t){var r=t.obj({Fields:[]});return new e(r)},e}(),yl=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.Pages=function(){return this.lookup(g.of("Pages"),Q)},t.prototype.AcroForm=function(){return this.lookupMaybe(g.of("AcroForm"),Q)},t.prototype.getAcroForm=function(){var r=this.AcroForm();if(r)return Ai.fromDict(r)},t.prototype.getOrCreateAcroForm=function(){var r=this.getAcroForm();if(!r){r=Ai.create(this.context);var n=this.context.register(r.dict);this.set(g.of("AcroForm"),n)}return r},t.prototype.ViewerPreferences=function(){return this.lookupMaybe(g.of("ViewerPreferences"),Q)},t.prototype.getViewerPreferences=function(){var r=this.ViewerPreferences();if(r)return hl.fromDict(r)},t.prototype.getOrCreateViewerPreferences=function(){var r=this.getViewerPreferences();if(!r){r=hl.create(this.context);var n=this.context.register(r.dict);this.set(g.of("ViewerPreferences"),n)}return r},t.prototype.insertLeafNode=function(r,n){var i=this.get(g.of("Pages")),a=this.Pages().insertLeafNode(r,n);return a||i},t.prototype.removeLeafNode=function(r){this.Pages().removeLeafNode(r)},t.withContextAndPages=function(r,n){var i=new Map;return i.set(g.of("Type"),g.of("Catalog")),i.set(g.of("Pages"),n),new t(i,r)},t.fromMapWithContext=function(r,n){return new t(r,n)},t}(Q),bl=function(e){M(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.Parent=function(){return this.lookup(g.of("Parent"))},t.prototype.Kids=function(){return this.lookup(g.of("Kids"),fe)},t.prototype.Count=function(){return this.lookup(g.of("Count"),H)},t.prototype.pushTreeNode=function(r){var n=this.Kids();n.push(r)},t.prototype.pushLeafNode=function(r){var n=this.Kids();this.insertLeafKid(n.size(),r)},t.prototype.insertLeafNode=function(r,n){var i=this.Kids(),a=this.Count().asNumber();if(n>a)throw new Gc(n,a);for(var o=n,s=0,l=i.size();s<l;s++){if(o===0){this.insertLeafKid(s,r);return}var c=i.get(s),u=this.context.lookup(c);if(u instanceof t){if(u.Count().asNumber()>o)return u.insertLeafNode(r,o)||c;o-=u.Count().asNumber()}u instanceof It&&(o-=1)}if(o===0){this.insertLeafKid(i.size(),r);return}throw new Kc(n,"insertLeafNode")},t.prototype.removeLeafNode=function(r,n){n===void 0&&(n=!0);var i=this.Kids(),a=this.Count().asNumber();if(r>=a)throw new Gc(r,a);for(var o=r,s=0,l=i.size();s<l;s++){var c=i.get(s),u=this.context.lookup(c);if(u instanceof t)if(u.Count().asNumber()>o){u.removeLeafNode(o,n),n&&u.Kids().size()===0&&i.remove(s);return}else o-=u.Count().asNumber();if(u instanceof It)if(o===0){this.removeKid(s);return}else o-=1}throw new Kc(r,"removeLeafNode")},t.prototype.ascend=function(r){r(this);var n=this.Parent();n&&n.ascend(r)},t.prototype.traverse=function(r){for(var n=this.Kids(),i=0,a=n.size();i<a;i++){var o=n.get(i),s=this.context.lookup(o);s instanceof t&&s.traverse(r),r(s,o)}},t.prototype.insertLeafKid=function(r,n){var i=this.Kids();this.ascend(function(a){var o=a.Count().asNumber()+1;a.set(g.of("Count"),H.of(o))}),i.insert(r,n)},t.prototype.removeKid=function(r){var n=this.Kids(),i=n.lookup(r);i instanceof It&&this.ascend(function(a){var o=a.Count().asNumber()-1;a.set(g.of("Count"),H.of(o))}),n.remove(r)},t.withContext=function(r,n){var i=new Map;return i.set(g.of("Type"),g.of("Pages")),i.set(g.of("Kids"),r.obj([])),i.set(g.of("Count"),r.obj(0)),n&&i.set(g.of("Parent"),n),new t(i,r)},t.fromMapWithContext=function(r,n){return new t(r,n)},t}(Q),ze=new Uint8Array(256);ze[y.Zero]=1,ze[y.One]=1,ze[y.Two]=1,ze[y.Three]=1,ze[y.Four]=1,ze[y.Five]=1,ze[y.Six]=1,ze[y.Seven]=1,ze[y.Eight]=1,ze[y.Nine]=1;var Di=new Uint8Array(256);Di[y.Period]=1,Di[y.Plus]=1,Di[y.Minus]=1;for(var Ya=new Uint8Array(256),An=0,Ud=256;An<Ud;An++)Ya[An]=ze[An]||Di[An]?1:0;var ml=y.Newline,xl=y.CarriageReturn,Ld=function(){function e(t,r){r===void 0&&(r=!1),this.bytes=t,this.capNumbers=r}return e.prototype.parseRawInt=function(){for(var t="";!this.bytes.done();){var r=this.bytes.peek();if(!ze[r])break;t+=Pt(this.bytes.next())}var n=Number(t);if(!t||!isFinite(n))throw new Hc(this.bytes.position(),t);return n},e.prototype.parseRawNumber=function(){for(var t="";!this.bytes.done();){var r=this.bytes.peek();if(!Ya[r]||(t+=Pt(this.bytes.next()),r===y.Period))break}for(;!this.bytes.done();){var r=this.bytes.peek();if(!ze[r])break;t+=Pt(this.bytes.next())}var n=Number(t);if(!t||!isFinite(n))throw new Hc(this.bytes.position(),t);if(n>Number.MAX_SAFE_INTEGER)if(this.capNumbers){var i="Parsed number that is too large for some PDF readers: "+t+", using Number.MAX_SAFE_INTEGER instead.";return console.warn(i),Number.MAX_SAFE_INTEGER}else{var i="Parsed number that is too large for some PDF readers: "+t+", not capping.";console.warn(i)}return n},e.prototype.skipWhitespace=function(){for(;!this.bytes.done()&&Rt[this.bytes.peek()];)this.bytes.next()},e.prototype.skipLine=function(){for(;!this.bytes.done();){var t=this.bytes.peek();if(t===ml||t===xl)return;this.bytes.next()}},e.prototype.skipComment=function(){if(this.bytes.peek()!==y.Percent)return!1;for(;!this.bytes.done();){var t=this.bytes.peek();if(t===ml||t===xl)return!0;this.bytes.next()}return!0},e.prototype.skipWhitespaceAndComments=function(){for(this.skipWhitespace();this.skipComment();)this.skipWhitespace()},e.prototype.matchKeyword=function(t){for(var r=this.bytes.offset(),n=0,i=t.length;n<i;n++)if(this.bytes.done()||this.bytes.next()!==t[n])return this.bytes.moveTo(r),!1;return!0},e}(),Ei=function(){function e(t){this.idx=0,this.line=0,this.column=0,this.bytes=t,this.length=this.bytes.length}return e.prototype.moveTo=function(t){this.idx=t},e.prototype.next=function(){var t=this.bytes[this.idx++];return t===y.Newline?(this.line+=1,this.column=0):this.column+=1,t},e.prototype.assertNext=function(t){if(this.peek()!==t)throw new Xh(this.position(),t,this.peek());return this.next()},e.prototype.peek=function(){return this.bytes[this.idx]},e.prototype.peekAhead=function(t){return this.bytes[this.idx+t]},e.prototype.peekAt=function(t){return this.bytes[t]},e.prototype.done=function(){return this.idx>=this.length},e.prototype.offset=function(){return this.idx},e.prototype.slice=function(t,r){return this.bytes.slice(t,r)},e.prototype.position=function(){return{line:this.line,column:this.column,offset:this.idx}},e.of=function(t){return new e(t)},e.fromPDFRawStream=function(t){return e.of(ul(t).decode())},e}(),Vd=y.Space,Dn=y.CarriageReturn,En=y.Newline,On=[y.s,y.t,y.r,y.e,y.a,y.m],Oi=[y.e,y.n,y.d,y.s,y.t,y.r,y.e,y.a,y.m],ye={header:[y.Percent,y.P,y.D,y.F,y.Dash],eof:[y.Percent,y.Percent,y.E,y.O,y.F],obj:[y.o,y.b,y.j],endobj:[y.e,y.n,y.d,y.o,y.b,y.j],xref:[y.x,y.r,y.e,y.f],trailer:[y.t,y.r,y.a,y.i,y.l,y.e,y.r],startxref:[y.s,y.t,y.a,y.r,y.t,y.x,y.r,y.e,y.f],true:[y.t,y.r,y.u,y.e],false:[y.f,y.a,y.l,y.s,y.e],null:[y.n,y.u,y.l,y.l],stream:On,streamEOF1:se(On,[Vd,Dn,En]),streamEOF2:se(On,[Dn,En]),streamEOF3:se(On,[Dn]),streamEOF4:se(On,[En]),endstream:Oi,EOF1endstream:se([Dn,En],Oi),EOF2endstream:se([Dn],Oi),EOF3endstream:se([En],Oi)},wl=function(e){M(t,e);function t(r,n,i){i===void 0&&(i=!1);var a=e.call(this,r,i)||this;return a.context=n,a}return t.prototype.parseObject=function(){if(this.skipWhitespaceAndComments(),this.matchKeyword(ye.true))return xn.True;if(this.matchKeyword(ye.false))return xn.False;if(this.matchKeyword(ye.null))return Xe;var r=this.bytes.peek();if(r===y.LessThan&&this.bytes.peekAhead(1)===y.LessThan)return this.parseDictOrStream();if(r===y.LessThan)return this.parseHexString();if(r===y.LeftParen)return this.parseString();if(r===y.ForwardSlash)return this.parseName();if(r===y.LeftSquareBracket)return this.parseArray();if(Ya[r])return this.parseNumberOrRef();throw new Zh(this.bytes.position(),r)},t.prototype.parseNumberOrRef=function(){var r=this.parseRawNumber();this.skipWhitespaceAndComments();var n=this.bytes.offset();if(ze[this.bytes.peek()]){var i=this.parseRawNumber();if(this.skipWhitespaceAndComments(),this.bytes.peek()===y.R)return this.bytes.assertNext(y.R),ve.of(r,i)}return this.bytes.moveTo(n),H.of(r)},t.prototype.parseHexString=function(){var r="";for(this.bytes.assertNext(y.LessThan);!this.bytes.done()&&this.bytes.peek()!==y.GreaterThan;)r+=Pt(this.bytes.next());return this.bytes.assertNext(y.GreaterThan),G.of(r)},t.prototype.parseString=function(){for(var r=0,n=!1,i="";!this.bytes.done();){var a=this.bytes.next();if(i+=Pt(a),n||(a===y.LeftParen&&(r+=1),a===y.RightParen&&(r-=1)),a===y.BackSlash?n=!n:n&&(n=!1),r===0)return pe.of(i.substring(1,i.length-1))}throw new Qh(this.bytes.position())},t.prototype.parseName=function(){this.bytes.assertNext(y.ForwardSlash);for(var r="";!this.bytes.done();){var n=this.bytes.peek();if(Rt[n]||at[n])break;r+=Pt(n),this.bytes.next()}return g.of(r)},t.prototype.parseArray=function(){this.bytes.assertNext(y.LeftSquareBracket),this.skipWhitespaceAndComments();for(var r=fe.withContext(this.context);this.bytes.peek()!==y.RightSquareBracket;){var n=this.parseObject();r.push(n),this.skipWhitespaceAndComments()}return this.bytes.assertNext(y.RightSquareBracket),r},t.prototype.parseDict=function(){this.bytes.assertNext(y.LessThan),this.bytes.assertNext(y.LessThan),this.skipWhitespaceAndComments();for(var r=new Map;!this.bytes.done()&&this.bytes.peek()!==y.GreaterThan&&this.bytes.peekAhead(1)!==y.GreaterThan;){var n=this.parseName(),i=this.parseObject();r.set(n,i),this.skipWhitespaceAndComments()}this.skipWhitespaceAndComments(),this.bytes.assertNext(y.GreaterThan),this.bytes.assertNext(y.GreaterThan);var a=r.get(g.of("Type"));return a===g.of("Catalog")?yl.fromMapWithContext(r,this.context):a===g.of("Pages")?bl.fromMapWithContext(r,this.context):a===g.of("Page")?It.fromMapWithContext(r,this.context):Q.fromMapWithContext(r,this.context)},t.prototype.parseDictOrStream=function(){var r=this.bytes.position(),n=this.parseDict();if(this.skipWhitespaceAndComments(),!this.matchKeyword(ye.streamEOF1)&&!this.matchKeyword(ye.streamEOF2)&&!this.matchKeyword(ye.streamEOF3)&&!this.matchKeyword(ye.streamEOF4)&&!this.matchKeyword(ye.stream))return n;var i=this.bytes.offset(),a,o=n.get(g.of("Length"));o instanceof H?(a=i+o.asNumber(),this.bytes.moveTo(a),this.skipWhitespaceAndComments(),this.matchKeyword(ye.endstream)||(this.bytes.moveTo(i),a=this.findEndOfStreamFallback(r))):a=this.findEndOfStreamFallback(r);var s=this.bytes.slice(i,a);return Sn.of(n,s)},t.prototype.findEndOfStreamFallback=function(r){for(var n=1,i=this.bytes.offset();!this.bytes.done()&&(i=this.bytes.offset(),this.matchKeyword(ye.stream)?n+=1:this.matchKeyword(ye.EOF1endstream)||this.matchKeyword(ye.EOF2endstream)||this.matchKeyword(ye.EOF3endstream)||this.matchKeyword(ye.endstream)?n-=1:this.bytes.next(),n!==0););if(n!==0)throw new Jh(r);return i},t.forBytes=function(r,n,i){return new t(Ei.of(r),n,i)},t.forByteStream=function(r,n,i){return i===void 0&&(i=!1),new t(r,n,i)},t}(Ld),Wd=function(e){M(t,e);function t(r,n){var i=e.call(this,Ei.fromPDFRawStream(r),r.dict.context)||this,a=r.dict;return i.alreadyParsed=!1,i.shouldWaitForTick=n||function(){return!1},i.firstOffset=a.lookup(g.of("First"),H).asNumber(),i.objectCount=a.lookup(g.of("N"),H).asNumber(),i}return t.prototype.parseIntoContext=function(){return _(this,void 0,void 0,function(){var r,n,i,a,o,s,l,c;return $(this,function(u){switch(u.label){case 0:if(this.alreadyParsed)throw new Ea("PDFObjectStreamParser","parseIntoContext");this.alreadyParsed=!0,r=this.parseOffsetsAndObjectNumbers(),n=0,i=r.length,u.label=1;case 1:return n<i?(a=r[n],o=a.objectNumber,s=a.offset,this.bytes.moveTo(this.firstOffset+s),l=this.parseObject(),c=ve.of(o,0),this.context.assign(c,l),this.shouldWaitForTick()?[4,kr()]:[3,3]):[3,4];case 2:u.sent(),u.label=3;case 3:return n++,[3,1];case 4:return[2]}})})},t.prototype.parseOffsetsAndObjectNumbers=function(){for(var r=[],n=0,i=this.objectCount;n<i;n++){this.skipWhitespaceAndComments();var a=this.parseRawInt();this.skipWhitespaceAndComments();var o=this.parseRawInt();r.push({objectNumber:a,offset:o})}return r},t.forStream=function(r,n){return new t(r,n)},t}(wl),qd=function(){function e(t){this.alreadyParsed=!1,this.dict=t.dict,this.bytes=Ei.fromPDFRawStream(t),this.context=this.dict.context;var r=this.dict.lookup(g.of("Size"),H),n=this.dict.lookup(g.of("Index"));if(n instanceof fe){this.subsections=[];for(var i=0,a=n.size();i<a;i+=2){var o=n.lookup(i+0,H).asNumber(),s=n.lookup(i+1,H).asNumber();this.subsections.push({firstObjectNumber:o,length:s})}}else this.subsections=[{firstObjectNumber:0,length:r.asNumber()}];var l=this.dict.lookup(g.of("W"),fe);this.byteWidths=[-1,-1,-1];for(var i=0,a=l.size();i<a;i++)this.byteWidths[i]=l.lookup(i,H).asNumber()}return e.prototype.parseIntoContext=function(){if(this.alreadyParsed)throw new Ea("PDFXRefStreamParser","parseIntoContext");this.alreadyParsed=!0,this.context.trailerInfo={Root:this.dict.get(g.of("Root")),Encrypt:this.dict.get(g.of("Encrypt")),Info:this.dict.get(g.of("Info")),ID:this.dict.get(g.of("ID"))};var t=this.parseEntries();return t},e.prototype.parseEntries=function(){for(var t=[],r=this.byteWidths,n=r[0],i=r[1],a=r[2],o=0,s=this.subsections.length;o<s;o++)for(var l=this.subsections[o],c=l.firstObjectNumber,u=l.length,h=0;h<u;h++){for(var f=0,d=0,v=n;d<v;d++)f=f<<8|this.bytes.next();for(var p=0,d=0,v=i;d<v;d++)p=p<<8|this.bytes.next();for(var m=0,d=0,v=a;d<v;d++)m=m<<8|this.bytes.next();n===0&&(f=1);var b=c+h,k={ref:ve.of(b,m),offset:p,deleted:f===0,inObjectStream:f===2};t.push(k)}return t},e.forStream=function(t){return new e(t)},e}(),Gd=function(e){M(t,e);function t(r,n,i,a){n===void 0&&(n=1/0),i===void 0&&(i=!1),a===void 0&&(a=!1);var o=e.call(this,Ei.of(r),ja.create(),a)||this;return o.alreadyParsed=!1,o.parsedObjects=0,o.shouldWaitForTick=function(){return o.parsedObjects+=1,o.parsedObjects%o.objectsPerTick===0},o.objectsPerTick=n,o.throwOnInvalidObject=i,o}return t.prototype.parseDocument=function(){return _(this,void 0,void 0,function(){var r,n;return $(this,function(i){switch(i.label){case 0:if(this.alreadyParsed)throw new Ea("PDFParser","parseDocument");this.alreadyParsed=!0,this.context.header=this.parseHeader(),i.label=1;case 1:return this.bytes.done()?[3,3]:[4,this.parseDocumentSection()];case 2:if(i.sent(),n=this.bytes.offset(),n===r)throw new _h(this.bytes.position());return r=n,[3,1];case 3:return this.maybeRecoverRoot(),this.context.lookup(ve.of(0))&&(console.warn("Removing parsed object: 0 0 R"),this.context.delete(ve.of(0))),[2,this.context]}})})},t.prototype.maybeRecoverRoot=function(){var r=function(u){return u instanceof Q&&u.lookup(g.of("Type"))===g.of("Catalog")},n=this.context.lookup(this.context.trailerInfo.Root);if(!r(n))for(var i=this.context.enumerateIndirectObjects(),a=0,o=i.length;a<o;a++){var s=i[a],l=s[0],c=s[1];r(c)&&(this.context.trailerInfo.Root=l)}},t.prototype.parseHeader=function(){for(;!this.bytes.done();){if(this.matchKeyword(ye.header)){var r=this.parseRawInt();this.bytes.assertNext(y.Period);var n=this.parseRawInt(),i=gi.forVersion(r,n);return this.skipBinaryHeaderComment(),i}this.bytes.next()}throw new $h(this.bytes.position())},t.prototype.parseIndirectObjectHeader=function(){this.skipWhitespaceAndComments();var r=this.parseRawInt();this.skipWhitespaceAndComments();var n=this.parseRawInt();if(this.skipWhitespaceAndComments(),!this.matchKeyword(ye.obj))throw new ed(this.bytes.position(),ye.obj);return ve.of(r,n)},t.prototype.matchIndirectObjectHeader=function(){var r=this.bytes.offset();try{return this.parseIndirectObjectHeader(),!0}catch{return this.bytes.moveTo(r),!1}},t.prototype.parseIndirectObject=function(){return _(this,void 0,void 0,function(){var r,n;return $(this,function(i){switch(i.label){case 0:return r=this.parseIndirectObjectHeader(),this.skipWhitespaceAndComments(),n=this.parseObject(),this.skipWhitespaceAndComments(),this.matchKeyword(ye.endobj),n instanceof Sn&&n.dict.lookup(g.of("Type"))===g.of("ObjStm")?[4,Wd.forStream(n,this.shouldWaitForTick).parseIntoContext()]:[3,2];case 1:return i.sent(),[3,3];case 2:n instanceof Sn&&n.dict.lookup(g.of("Type"))===g.of("XRef")?qd.forStream(n).parseIntoContext():this.context.assign(r,n),i.label=3;case 3:return[2,r]}})})},t.prototype.tryToParseInvalidIndirectObject=function(){var r=this.bytes.position(),n="Trying to parse invalid object: "+JSON.stringify(r)+")";if(this.throwOnInvalidObject)throw new Error(n);console.warn(n);var i=this.parseIndirectObjectHeader();console.warn("Invalid object ref: "+i),this.skipWhitespaceAndComments();for(var a=this.bytes.offset(),o=!0;!this.bytes.done()&&(this.matchKeyword(ye.endobj)&&(o=!1),!!o);)this.bytes.next();if(o)throw new Yh(r);var s=this.bytes.offset()-ye.endobj.length,l=tl.of(this.bytes.slice(a,s));return this.context.assign(i,l),i},t.prototype.parseIndirectObjects=function(){return _(this,void 0,void 0,function(){var r;return $(this,function(n){switch(n.label){case 0:this.skipWhitespaceAndComments(),n.label=1;case 1:if(!(!this.bytes.done()&&ze[this.bytes.peek()]))return[3,8];r=this.bytes.offset(),n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this.parseIndirectObject()];case 3:return n.sent(),[3,5];case 4:return n.sent(),this.bytes.moveTo(r),this.tryToParseInvalidIndirectObject(),[3,5];case 5:return this.skipWhitespaceAndComments(),this.skipJibberish(),this.shouldWaitForTick()?[4,kr()]:[3,7];case 6:n.sent(),n.label=7;case 7:return[3,1];case 8:return[2]}})})},t.prototype.maybeParseCrossRefSection=function(){if(this.skipWhitespaceAndComments(),!!this.matchKeyword(ye.xref)){this.skipWhitespaceAndComments();for(var r=-1,n=_c.createEmpty();!this.bytes.done()&&ze[this.bytes.peek()];){var i=this.parseRawInt();this.skipWhitespaceAndComments();var a=this.parseRawInt();this.skipWhitespaceAndComments();var o=this.bytes.peek();if(o===y.n||o===y.f){var s=ve.of(r,a);this.bytes.next()===y.n?n.addEntry(s,i):n.addDeletedEntry(s,i),r+=1}else r=i;this.skipWhitespaceAndComments()}return n}},t.prototype.maybeParseTrailerDict=function(){if(this.skipWhitespaceAndComments(),!!this.matchKeyword(ye.trailer)){this.skipWhitespaceAndComments();var r=this.parseDict(),n=this.context;n.trailerInfo={Root:r.get(g.of("Root"))||n.trailerInfo.Root,Encrypt:r.get(g.of("Encrypt"))||n.trailerInfo.Encrypt,Info:r.get(g.of("Info"))||n.trailerInfo.Info,ID:r.get(g.of("ID"))||n.trailerInfo.ID}}},t.prototype.maybeParseTrailer=function(){if(this.skipWhitespaceAndComments(),!!this.matchKeyword(ye.startxref)){this.skipWhitespaceAndComments();var r=this.parseRawInt();return this.skipWhitespace(),this.matchKeyword(ye.eof),this.skipWhitespaceAndComments(),this.matchKeyword(ye.eof),this.skipWhitespaceAndComments(),za.forLastCrossRefSectionOffset(r)}},t.prototype.parseDocumentSection=function(){return _(this,void 0,void 0,function(){return $(this,function(r){switch(r.label){case 0:return[4,this.parseIndirectObjects()];case 1:return r.sent(),this.maybeParseCrossRefSection(),this.maybeParseTrailerDict(),this.maybeParseTrailer(),this.skipJibberish(),[2]}})})},t.prototype.skipJibberish=function(){for(this.skipWhitespaceAndComments();!this.bytes.done();){var r=this.bytes.offset(),n=this.bytes.peek(),i=n>=y.Space&&n<=y.Tilde;if(i&&(this.matchKeyword(ye.xref)||this.matchKeyword(ye.trailer)||this.matchKeyword(ye.startxref)||this.matchIndirectObjectHeader())){this.bytes.moveTo(r);break}this.bytes.next()}},t.prototype.skipBinaryHeaderComment=function(){this.skipWhitespaceAndComments();try{var r=this.bytes.offset();this.parseIndirectObjectHeader(),this.bytes.moveTo(r)}catch{this.bytes.next(),this.skipWhitespaceAndComments()}},t.forBytesWithOptions=function(r,n,i,a){return new t(r,n,i,a)},t}(wl),St=function(e){return 1<<e},Rn;(function(e){e[e.Invisible=St(0)]="Invisible",e[e.Hidden=St(1)]="Hidden",e[e.Print=St(2)]="Print",e[e.NoZoom=St(3)]="NoZoom",e[e.NoRotate=St(4)]="NoRotate",e[e.NoView=St(5)]="NoView",e[e.ReadOnly=St(6)]="ReadOnly",e[e.Locked=St(7)]="Locked",e[e.ToggleNoView=St(8)]="ToggleNoView",e[e.LockedContents=St(9)]="LockedContents"})(Rn||(Rn={}));var Ri=function(e){return e instanceof g?e:g.of(e)},X=function(e){return e instanceof H?e:H.of(e)},ee=function(e){return e instanceof H?e.asNumber():e},In;(function(e){e.Degrees="degrees",e.Radians="radians"})(In||(In={}));var K=function(e){return S(e,"degreeAngle",["number"]),{type:In.Degrees,angle:e}},Sl=In.Radians,Fl=In.Degrees,kl=function(e){return e*Math.PI/180},Kd=function(e){return e*180/Math.PI},Me=function(e){return e.type===Sl?e.angle:e.type===Fl?kl(e.angle):en("Invalid rotation: "+JSON.stringify(e))},Cl=function(e){return e.type===Sl?Kd(e.angle):e.type===Fl?e.angle:en("Invalid rotation: "+JSON.stringify(e))},Nt=function(e){e===void 0&&(e=0);var t=e/90%4;return t===0?0:t===1?90:t===2?180:t===3?270:0},dr=function(e,t){t===void 0&&(t=0);var r=Nt(t);return r===90||r===270?{width:e.height,height:e.width}:{width:e.width,height:e.height}},Hd=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=0);var n=e.x,i=e.y,a=e.width,o=e.height,s=Nt(r),l=t/2;return s===0?{x:n-l,y:i-l,width:a,height:o}:s===90?{x:n-o+l,y:i-l,width:o,height:a}:s===180?{x:n-a+l,y:i-o+l,width:a,height:o}:s===270?{x:n-l,y:i-a+l,width:o,height:a}:{x:n-l,y:i-l,width:a,height:o}},Tl=function(){return ie.of(le.ClipNonZero)},Ii=Math.cos,Ni=Math.sin,Bi=Math.tan,Mi=function(e,t,r,n,i,a){return ie.of(le.ConcatTransformationMatrix,[X(e),X(t),X(r),X(n),X(i),X(a)])},st=function(e,t){return Mi(1,0,0,1,e,t)},Nn=function(e,t){return Mi(e,0,0,t,0,0)},jr=function(e){return Mi(Ii(ee(e)),Ni(ee(e)),-Ni(ee(e)),Ii(ee(e)),0,0)},ji=function(e){return jr(kl(ee(e)))},Ja=function(e,t){return Mi(1,Bi(ee(e)),Bi(ee(t)),1,0,0)},zi=function(e,t){return ie.of(le.SetLineDashPattern,["["+e.map(X).join(" ")+"]",X(t)])},vr;(function(e){e[e.Butt=0]="Butt",e[e.Round=1]="Round",e[e.Projecting=2]="Projecting"})(vr||(vr={}));var Ui=function(e){return ie.of(le.SetLineCapStyle,[X(e)])},Pl;(function(e){e[e.Miter=0]="Miter",e[e.Round=1]="Round",e[e.Bevel=2]="Bevel"})(Pl||(Pl={}));var pr=function(e){return ie.of(le.SetGraphicsStateParams,[Ri(e)])},Ae=function(){return ie.of(le.PushGraphicsState)},De=function(){return ie.of(le.PopGraphicsState)},Bn=function(e){return ie.of(le.SetLineWidth,[X(e)])},_e=function(e,t,r,n,i,a){return ie.of(le.AppendBezierCurve,[X(e),X(t),X(r),X(n),X(i),X(a)])},Li=function(e,t,r,n){return ie.of(le.CurveToReplicateInitialPoint,[X(e),X(t),X(r),X(n)])},Xt=function(){return ie.of(le.ClosePath)},Ft=function(e,t){return ie.of(le.MoveTo,[X(e),X(t)])},Ie=function(e,t){return ie.of(le.LineTo,[X(e),X(t)])},Mn=function(){return ie.of(le.StrokePath)},Qa=function(){return ie.of(le.FillNonZero)},_a=function(){return ie.of(le.FillNonZeroAndStroke)},Al=function(){return ie.of(le.EndPath)},Xd=function(){return ie.of(le.NextLine)},Dl=function(e){return ie.of(le.ShowText,[e])},El=function(){return ie.of(le.BeginText)},Ol=function(){return ie.of(le.EndText)},$a=function(e,t){return ie.of(le.SetFontAndSize,[Ri(e),X(t)])},Zd=function(e){return ie.of(le.SetTextLineHeight,[X(e)])},Rl;(function(e){e[e.Fill=0]="Fill",e[e.Outline=1]="Outline",e[e.FillAndOutline=2]="FillAndOutline",e[e.Invisible=3]="Invisible",e[e.FillAndClip=4]="FillAndClip",e[e.OutlineAndClip=5]="OutlineAndClip",e[e.FillAndOutlineAndClip=6]="FillAndOutlineAndClip",e[e.Clip=7]="Clip"})(Rl||(Rl={}));var Yd=function(e,t,r,n,i,a){return ie.of(le.SetTextMatrix,[X(e),X(t),X(r),X(n),X(i),X(a)])},Il=function(e,t,r,n,i){return Yd(Ii(ee(e)),Ni(ee(e))+Bi(ee(t)),-Ni(ee(e))+Bi(ee(r)),Ii(ee(e)),n,i)},eo=function(e){return ie.of(le.DrawObject,[Ri(e)])},Jd=function(e){return ie.of(le.NonStrokingColorGray,[X(e)])},Qd=function(e){return ie.of(le.StrokingColorGray,[X(e)])},_d=function(e,t,r){return ie.of(le.NonStrokingColorRgb,[X(e),X(t),X(r)])},$d=function(e,t,r){return ie.of(le.StrokingColorRgb,[X(e),X(t),X(r)])},e0=function(e,t,r,n){return ie.of(le.NonStrokingColorCmyk,[X(e),X(t),X(r),X(n)])},t0=function(e,t,r,n){return ie.of(le.StrokingColorCmyk,[X(e),X(t),X(r),X(n)])},Nl=function(e){return ie.of(le.BeginMarkedContent,[Ri(e)])},Bl=function(){return ie.of(le.EndMarkedContent)},Zt;(function(e){e.Grayscale="Grayscale",e.RGB="RGB",e.CMYK="CMYK"})(Zt||(Zt={}));var Ml=function(e){return Je(e,"gray",0,1),{type:Zt.Grayscale,gray:e}},de=function(e,t,r){return Je(e,"red",0,1),Je(t,"green",0,1),Je(r,"blue",0,1),{type:Zt.RGB,red:e,green:t,blue:r}},jl=function(e,t,r,n){return Je(e,"cyan",0,1),Je(t,"magenta",0,1),Je(r,"yellow",0,1),Je(n,"key",0,1),{type:Zt.CMYK,cyan:e,magenta:t,yellow:r,key:n}},to=Zt.Grayscale,ro=Zt.RGB,no=Zt.CMYK,gr=function(e){return e.type===to?Jd(e.gray):e.type===ro?_d(e.red,e.green,e.blue):e.type===no?e0(e.cyan,e.magenta,e.yellow,e.key):en("Invalid color: "+JSON.stringify(e))},jn=function(e){return e.type===to?Qd(e.gray):e.type===ro?$d(e.red,e.green,e.blue):e.type===no?t0(e.cyan,e.magenta,e.yellow,e.key):en("Invalid color: "+JSON.stringify(e))},Ve=function(e,t){return t===void 0&&(t=1),(e==null?void 0:e.length)===1?Ml(e[0]*t):(e==null?void 0:e.length)===3?de(e[0]*t,e[1]*t,e[2]*t):(e==null?void 0:e.length)===4?jl(e[0]*t,e[1]*t,e[2]*t,e[3]*t):void 0},zl=function(e){return e.type===to?[e.gray]:e.type===ro?[e.red,e.green,e.blue]:e.type===no?[e.cyan,e.magenta,e.yellow,e.key]:en("Invalid color: "+JSON.stringify(e))},V=0,W=0,ae=0,oe=0,zn=0,Un=0,Ul=new Map([["A",7],["a",7],["C",6],["c",6],["H",1],["h",1],["L",2],["l",2],["M",2],["m",2],["Q",4],["q",4],["S",4],["s",4],["T",2],["t",2],["V",1],["v",1],["Z",0],["z",0]]),r0=function(e){for(var t,r=[],n=[],i="",a=!1,o=0,s=0,l=e;s<l.length;s++){var c=l[s];if(Ul.has(c))o=Ul.get(c),t&&(i.length>0&&(n[n.length]=+i),r[r.length]={cmd:t,args:n},n=[],i="",a=!1),t=c;else if([" ",","].includes(c)||c==="-"&&i.length>0&&i[i.length-1]!=="e"||c==="."&&a){if(i.length===0)continue;n.length===o?(r[r.length]={cmd:t,args:n},n=[+i],t==="M"&&(t="L"),t==="m"&&(t="l")):n[n.length]=+i,a=c===".",i=["-","."].includes(c)?c:""}else i+=c,c==="."&&(a=!0)}return i.length>0&&(n.length===o?(r[r.length]={cmd:t,args:n},n=[+i],t==="M"&&(t="L"),t==="m"&&(t="l")):n[n.length]=+i),r[r.length]={cmd:t,args:n},r},n0=function(e){V=W=ae=oe=zn=Un=0;for(var t=[],r=0;r<e.length;r++){var n=e[r];if(n.cmd&&typeof Ll[n.cmd]=="function"){var i=Ll[n.cmd](n.args);Array.isArray(i)?t=t.concat(i):t.push(i)}}return t},Ll={M:function(e){return V=e[0],W=e[1],ae=oe=null,zn=V,Un=W,Ft(V,W)},m:function(e){return V+=e[0],W+=e[1],ae=oe=null,zn=V,Un=W,Ft(V,W)},C:function(e){return V=e[4],W=e[5],ae=e[2],oe=e[3],_e(e[0],e[1],e[2],e[3],e[4],e[5])},c:function(e){var t=_e(e[0]+V,e[1]+W,e[2]+V,e[3]+W,e[4]+V,e[5]+W);return ae=V+e[2],oe=W+e[3],V+=e[4],W+=e[5],t},S:function(e){(ae===null||oe===null)&&(ae=V,oe=W);var t=_e(V-(ae-V),W-(oe-W),e[0],e[1],e[2],e[3]);return ae=e[0],oe=e[1],V=e[2],W=e[3],t},s:function(e){(ae===null||oe===null)&&(ae=V,oe=W);var t=_e(V-(ae-V),W-(oe-W),V+e[0],W+e[1],V+e[2],W+e[3]);return ae=V+e[0],oe=W+e[1],V+=e[2],W+=e[3],t},Q:function(e){return ae=e[0],oe=e[1],V=e[2],W=e[3],Li(e[0],e[1],V,W)},q:function(e){var t=Li(e[0]+V,e[1]+W,e[2]+V,e[3]+W);return ae=V+e[0],oe=W+e[1],V+=e[2],W+=e[3],t},T:function(e){ae===null||oe===null?(ae=V,oe=W):(ae=V-(ae-V),oe=W-(oe-W));var t=Li(ae,oe,e[0],e[1]);return ae=V-(ae-V),oe=W-(oe-W),V=e[0],W=e[1],t},t:function(e){ae===null||oe===null?(ae=V,oe=W):(ae=V-(ae-V),oe=W-(oe-W));var t=Li(ae,oe,V+e[0],W+e[1]);return V+=e[0],W+=e[1],t},A:function(e){var t=Vl(V,W,e);return V=e[5],W=e[6],t},a:function(e){e[5]+=V,e[6]+=W;var t=Vl(V,W,e);return V=e[5],W=e[6],t},L:function(e){return V=e[0],W=e[1],ae=oe=null,Ie(V,W)},l:function(e){return V+=e[0],W+=e[1],ae=oe=null,Ie(V,W)},H:function(e){return V=e[0],ae=oe=null,Ie(V,W)},h:function(e){return V+=e[0],ae=oe=null,Ie(V,W)},V:function(e){return W=e[0],ae=oe=null,Ie(V,W)},v:function(e){return W+=e[0],ae=oe=null,Ie(V,W)},Z:function(){var e=Xt();return V=zn,W=Un,e},z:function(){var e=Xt();return V=zn,W=Un,e}},Vl=function(e,t,r){for(var n=r[0],i=r[1],a=r[2],o=r[3],s=r[4],l=r[5],c=r[6],u=i0(l,c,n,i,o,s,a,e,t),h=[],f=0,d=u;f<d.length;f++){var v=d[f],p=a0.apply(void 0,v);h.push(_e.apply(void 0,p))}return h},i0=function(e,t,r,n,i,a,o,s,l){var c=o*(Math.PI/180),u=Math.sin(c),h=Math.cos(c);r=Math.abs(r),n=Math.abs(n),ae=h*(s-e)*.5+u*(l-t)*.5,oe=h*(l-t)*.5-u*(s-e)*.5;var f=ae*ae/(r*r)+oe*oe/(n*n);f>1&&(f=Math.sqrt(f),r*=f,n*=f);var d=h/r,v=u/r,p=-u/n,m=h/n,b=d*s+v*l,k=p*s+m*l,x=d*e+v*t,T=p*e+m*t,w=(x-b)*(x-b)+(T-k)*(T-k),F=1/w-.25;F<0&&(F=0);var A=Math.sqrt(F);a===i&&(A=-A);var D=.5*(b+x)-A*(T-k),O=.5*(k+T)+A*(x-b),B=Math.atan2(k-O,b-D),E=Math.atan2(T-O,x-D),j=E-B;j<0&&a===1?j+=2*Math.PI:j>0&&a===0&&(j-=2*Math.PI);for(var I=Math.ceil(Math.abs(j/(Math.PI*.5+.001))),L=[],z=0;z<I;z++){var P=B+z*j/I,U=B+(z+1)*j/I;L[z]=[D,O,P,U,r,n,u,h]}return L},a0=function(e,t,r,n,i,a,o,s){var l=s*i,c=-o*a,u=o*i,h=s*a,f=.5*(n-r),d=8/3*Math.sin(f*.5)*Math.sin(f*.5)/Math.sin(f),v=e+Math.cos(r)-d*Math.sin(r),p=t+Math.sin(r)+d*Math.cos(r),m=e+Math.cos(n),b=t+Math.sin(n),k=m+d*Math.sin(n),x=b-d*Math.cos(n),T=[l*v+c*p,u*v+h*p,l*k+c*x,u*k+h*x,l*m+c*b,u*m+h*b];return T},o0=function(e){return n0(r0(e))},s0=function(e,t){for(var r=[Ae(),t.graphicsState&&pr(t.graphicsState),El(),gr(t.color),$a(t.font,t.size),Zd(t.lineHeight),Il(Me(t.rotate),Me(t.xSkew),Me(t.ySkew),t.x,t.y)].filter(Boolean),n=0,i=e.length;n<i;n++)r.push(Dl(e[n]),Xd());return r.push(Ol(),De()),r},Wl=function(e,t){return[Ae(),t.graphicsState&&pr(t.graphicsState),st(t.x,t.y),jr(Me(t.rotate)),Nn(t.width,t.height),Ja(Me(t.xSkew),Me(t.ySkew)),eo(e),De()].filter(Boolean)},c0=function(e,t){return[Ae(),t.graphicsState&&pr(t.graphicsState),st(t.x,t.y),jr(Me(t.rotate)),Nn(t.xScale,t.yScale),Ja(Me(t.xSkew),Me(t.ySkew)),eo(e),De()].filter(Boolean)},l0=function(e){var t,r;return[Ae(),e.graphicsState&&pr(e.graphicsState),e.color&&jn(e.color),Bn(e.thickness),zi((t=e.dashArray)!==null&&t!==void 0?t:[],(r=e.dashPhase)!==null&&r!==void 0?r:0),Ft(e.start.x,e.start.y),e.lineCap&&Ui(e.lineCap),Ft(e.start.x,e.start.y),Ie(e.end.x,e.end.y),Mn(),De()].filter(Boolean)},zr=function(e){var t,r;return[Ae(),e.graphicsState&&pr(e.graphicsState),e.color&&gr(e.color),e.borderColor&&jn(e.borderColor),Bn(e.borderWidth),e.borderLineCap&&Ui(e.borderLineCap),zi((t=e.borderDashArray)!==null&&t!==void 0?t:[],(r=e.borderDashPhase)!==null&&r!==void 0?r:0),st(e.x,e.y),jr(Me(e.rotate)),Ja(Me(e.xSkew),Me(e.ySkew)),Ft(0,0),Ie(0,e.height),Ie(e.width,e.height),Ie(e.width,0),Xt(),e.color&&e.borderWidth?_a():e.color?Qa():e.borderColor?Mn():Xt(),De()].filter(Boolean)},Vi=4*((Math.sqrt(2)-1)/3),u0=function(e){var t=ee(e.x),r=ee(e.y),n=ee(e.xScale),i=ee(e.yScale);t-=n,r-=i;var a=n*Vi,o=i*Vi,s=t+n*2,l=r+i*2,c=t+n,u=r+i;return[Ae(),Ft(t,u),_e(t,u-o,c-a,r,c,r),_e(c+a,r,s,u-o,s,u),_e(s,u+o,c+a,l,c,l),_e(c-a,l,t,u+o,t,u),De()]},f0=function(e){var t=ee(e.x),r=ee(e.y),n=ee(e.xScale),i=ee(e.yScale),a=-n,o=-i,s=n*Vi,l=i*Vi,c=a+n*2,u=o+i*2,h=a+n,f=o+i;return[st(t,r),jr(Me(e.rotate)),Ft(a,f),_e(a,f-l,h-s,o,h,o),_e(h+s,o,c,f-l,c,f),_e(c,f+l,h+s,u,h,u),_e(h-s,u,a,f+l,a,f)]},io=function(e){var t,r,n;return se([Ae(),e.graphicsState&&pr(e.graphicsState),e.color&&gr(e.color),e.borderColor&&jn(e.borderColor),Bn(e.borderWidth),e.borderLineCap&&Ui(e.borderLineCap),zi((t=e.borderDashArray)!==null&&t!==void 0?t:[],(r=e.borderDashPhase)!==null&&r!==void 0?r:0)],e.rotate===void 0?u0({x:e.x,y:e.y,xScale:e.xScale,yScale:e.yScale}):f0({x:e.x,y:e.y,xScale:e.xScale,yScale:e.yScale,rotate:(n=e.rotate)!==null&&n!==void 0?n:K(0)}),[e.color&&e.borderWidth?_a():e.color?Qa():e.borderColor?Mn():Xt(),De()]).filter(Boolean)},h0=function(e,t){var r,n,i;return se([Ae(),t.graphicsState&&pr(t.graphicsState),st(t.x,t.y),jr(Me((r=t.rotate)!==null&&r!==void 0?r:K(0))),t.scale?Nn(t.scale,-t.scale):Nn(1,-1),t.color&&gr(t.color),t.borderColor&&jn(t.borderColor),t.borderWidth&&Bn(t.borderWidth),t.borderLineCap&&Ui(t.borderLineCap),zi((n=t.borderDashArray)!==null&&n!==void 0?n:[],(i=t.borderDashPhase)!==null&&i!==void 0?i:0)],o0(e),[t.color&&t.borderWidth?_a():t.color?Qa():t.borderColor?Mn():Xt(),De()]).filter(Boolean)},d0=function(e){var t=ee(e.size),r=-1+.75,n=-1+.51,i=1-.525,a=1-.31,o=-1+.325,s=.3995/(i-n)+n;return[Ae(),e.color&&jn(e.color),Bn(e.thickness),st(e.x,e.y),Ft(o*t,s*t),Ie(r*t,n*t),Ie(a*t,i*t),Mn(),De()].filter(Boolean)},Yt=function(e){return e.rotation===0?[st(0,0),ji(0)]:e.rotation===90?[st(e.width,0),ji(90)]:e.rotation===180?[st(e.width,e.height),ji(180)]:e.rotation===270?[st(0,e.height),ji(270)]:[]},Wi=function(e){var t=zr({x:e.x,y:e.y,width:e.width,height:e.height,borderWidth:e.borderWidth,color:e.color,borderColor:e.borderColor,rotate:K(0),xSkew:K(0),ySkew:K(0)});if(!e.filled)return t;var r=ee(e.width),n=ee(e.height),i=Math.min(r,n)/2,a=d0({x:r/2,y:n/2,size:i,thickness:e.thickness,color:e.markColor});return se([Ae()],t,a,[De()])},qi=function(e){var t=ee(e.width),r=ee(e.height),n=Math.min(t,r)/2,i=io({x:e.x,y:e.y,xScale:n,yScale:n,color:e.color,borderColor:e.borderColor,borderWidth:e.borderWidth});if(!e.filled)return i;var a=io({x:e.x,y:e.y,xScale:n*.45,yScale:n*.45,color:e.dotColor,borderColor:void 0,borderWidth:0});return se([Ae()],i,a,[De()])},ql=function(e){var t=ee(e.x),r=ee(e.y),n=ee(e.width),i=ee(e.height),a=zr({x:t,y:r,width:n,height:i,borderWidth:e.borderWidth,color:e.color,borderColor:e.borderColor,rotate:K(0),xSkew:K(0),ySkew:K(0)}),o=ao(e.textLines,{color:e.textColor,font:e.font,size:e.fontSize,rotate:K(0),xSkew:K(0),ySkew:K(0)});return se([Ae()],a,o,[De()])},ao=function(e,t){for(var r=[El(),gr(t.color),$a(t.font,t.size)],n=0,i=e.length;n<i;n++){var a=e[n],o=a.encoded,s=a.x,l=a.y;r.push(Il(Me(t.rotate),Me(t.xSkew),Me(t.ySkew),s,l),Dl(o))}return r.push(Ol()),r},Gl=function(e){var t=ee(e.x),r=ee(e.y),n=ee(e.width),i=ee(e.height),a=ee(e.borderWidth),o=ee(e.padding),s=t+a/2+o,l=r+a/2+o,c=n-(a/2+o)*2,u=i-(a/2+o)*2,h=[Ft(s,l),Ie(s,l+u),Ie(s+c,l+u),Ie(s+c,l),Xt(),Tl(),Al()],f=zr({x:t,y:r,width:n,height:i,borderWidth:e.borderWidth,color:e.color,borderColor:e.borderColor,rotate:K(0),xSkew:K(0),ySkew:K(0)}),d=ao(e.textLines,{color:e.textColor,font:e.font,size:e.fontSize,rotate:K(0),xSkew:K(0),ySkew:K(0)}),v=se([Nl("Tx"),Ae()],d,[De(),Bl()]);return se([Ae()],f,h,v,[De()])},v0=function(e){for(var t=ee(e.x),r=ee(e.y),n=ee(e.width),i=ee(e.height),a=ee(e.lineHeight),o=ee(e.borderWidth),s=ee(e.padding),l=t+o/2+s,c=r+o/2+s,u=n-(o/2+s)*2,h=i-(o/2+s)*2,f=[Ft(l,c),Ie(l,c+h),Ie(l+u,c+h),Ie(l+u,c),Xt(),Tl(),Al()],d=zr({x:t,y:r,width:n,height:i,borderWidth:e.borderWidth,color:e.color,borderColor:e.borderColor,rotate:K(0),xSkew:K(0),ySkew:K(0)}),v=[],p=0,m=e.selectedLines.length;p<m;p++){var b=e.textLines[e.selectedLines[p]];v.push.apply(v,zr({x:b.x-s,y:b.y-(a-b.height)/2,width:n-o,height:b.height+(a-b.height)/2,borderWidth:0,color:e.selectedColor,borderColor:void 0,rotate:K(0),xSkew:K(0),ySkew:K(0)}))}var k=ao(e.textLines,{color:e.textColor,font:e.font,size:e.fontSize,rotate:K(0),xSkew:K(0),ySkew:K(0)}),x=se([Nl("Tx"),Ae()],k,[De(),Bl()]);return se([Ae()],d,v,f,x,[De()])},p0=function(e){M(t,e);function t(){var r=this,n="Input document to `PDFDocument.load` is encrypted. You can use `PDFDocument.load(..., { ignoreEncryption: true })` if you wish to load the document anyways.";return r=e.call(this,n)||this,r}return t}(Error),g0=function(e){M(t,e);function t(){var r=this,n="Input to `PDFDocument.embedFont` was a custom font, but no `fontkit` instance was found. You must register a `fontkit` instance with `PDFDocument.registerFontkit(...)` before embedding custom fonts.";return r=e.call(this,n)||this,r}return t}(Error),y0=function(e){M(t,e);function t(){var r=this,n="A `page` passed to `PDFDocument.addPage` or `PDFDocument.insertPage` was from a different (foreign) PDF document. If you want to copy pages from one PDFDocument to another, you must use `PDFDocument.copyPages(...)` to copy the pages before adding or inserting them.";return r=e.call(this,n)||this,r}return t}(Error),b0=function(e){M(t,e);function t(){var r=this,n="PDFDocument has no pages so `PDFDocument.removePage` cannot be called";return r=e.call(this,n)||this,r}return t}(Error),m0=function(e){M(t,e);function t(r){var n=this,i='PDFDocument has no form field with the name "'+r+'"';return n=e.call(this,i)||this,n}return t}(Error),yr=function(e){M(t,e);function t(r,n,i){var a,o,s=this,l=n==null?void 0:n.name,c=(o=(a=i==null?void 0:i.constructor)===null||a===void 0?void 0:a.name)!==null&&o!==void 0?o:i,u='Expected field "'+r+'" to be of type '+l+", "+("but it is actually of type "+c);return s=e.call(this,u)||this,s}return t}(Error);(function(e){M(t,e);function t(r){var n=this,i='Failed to select check box due to missing onValue: "'+r+'"';return n=e.call(this,i)||this,n}return t})(Error);var Kl=function(e){M(t,e);function t(r){var n=this,i='A field already exists with the specified name: "'+r+'"';return n=e.call(this,i)||this,n}return t}(Error),x0=function(e){M(t,e);function t(r){var n=this,i='Field name contains invalid component: "'+r+'"';return n=e.call(this,i)||this,n}return t}(Error);(function(e){M(t,e);function t(r){var n=this,i='A non-terminal field already exists with the specified name: "'+r+'"';return n=e.call(this,i)||this,n}return t})(Error);var w0=function(e){M(t,e);function t(r){var n=this,i="Reading rich text fields is not supported: Attempted to read rich text field: "+r;return n=e.call(this,i)||this,n}return t}(Error),S0=function(e){M(t,e);function t(r,n){var i=this,a="Failed to layout combed text as lineLength="+r+" is greater than cellCount="+n;return i=e.call(this,a)||this,i}return t}(Error),F0=function(e){M(t,e);function t(r,n,i){var a=this,o="Attempted to set text with length="+r+" for TextField with maxLength="+n+" and name="+i;return a=e.call(this,o)||this,a}return t}(Error),k0=function(e){M(t,e);function t(r,n,i){var a=this,o="Attempted to set maxLength="+n+", which is less than "+r+", the length of this field's current value (name="+i+")";return a=e.call(this,o)||this,a}return t}(Error),Ee;(function(e){e[e.Left=0]="Left",e[e.Center=1]="Center",e[e.Right=2]="Right"})(Ee||(Ee={}));var Hl=4,Xl=500,Zl=function(e,t,r,n){n===void 0&&(n=!1);for(var i=Hl;i<Xl;){for(var a=0,o=0,s=e.length;o<s;o++){a+=1;for(var l=e[o],c=l.split(" "),u=r.width,h=0,f=c.length;h<f;h++){var d=h===f-1,v=d?c[h]:c[h]+" ",p=t.widthOfTextAtSize(v,i);u-=p,u<=0&&(a+=1,u=r.width-p)}}if(!n&&a>e.length)return i-1;var m=t.heightAtSize(i),b=m+m*.2,k=b*a;if(k>Math.abs(r.height))return i-1;i+=1}return i},C0=function(e,t,r,n){for(var i=r.width/n,a=r.height,o=Hl,s=du(e);o<Xl;){for(var l=0,c=s.length;l<c;l++){var u=s[l],h=t.widthOfTextAtSize(u,o)>i*.75;if(h)return o-1}var f=t.heightAtSize(o,{descender:!1});if(f>a)return o-1;o+=1}return o},T0=function(e){for(var t=e.length;t>0;t--)if(/\s/.test(e[t]))return t},P0=function(e,t,r,n){for(var i,a=e.length;a>0;){var o=e.substring(0,a),s=r.encodeText(o),l=r.widthOfTextAtSize(o,n);if(l<t){var c=e.substring(a)||void 0;return{line:o,encoded:s,width:l,remainder:c}}a=(i=T0(o))!==null&&i!==void 0?i:0}return{line:e,encoded:r.encodeText(e),width:r.widthOfTextAtSize(e,n),remainder:void 0}},Yl=function(e,t){var r=t.alignment,n=t.fontSize,i=t.font,a=t.bounds,o=Xo(Qr(e));(n===void 0||n===0)&&(n=Zl(o,i,a,!0));for(var s=i.heightAtSize(n),l=s+s*.2,c=[],u=a.x,h=a.y,f=a.x+a.width,d=a.y+a.height,v=a.y+a.height,p=0,m=o.length;p<m;p++)for(var b=o[p];b!==void 0;){var k=P0(b,a.width,i,n),x=k.line,T=k.encoded,w=k.width,F=k.remainder,A=r===Ee.Left?a.x:r===Ee.Center?a.x+a.width/2-w/2:r===Ee.Right?a.x+a.width-w:a.x;v-=l,A<u&&(u=A),v<h&&(h=v),A+w>f&&(f=A+w),v+s>d&&(d=v+s),c.push({text:x,encoded:T,width:w,height:s,x:A,y:v}),b=F==null?void 0:F.trim()}return{fontSize:n,lineHeight:l,lines:c,bounds:{x:u,y:h,width:f-u,height:d-h}}},A0=function(e,t){var r=t.fontSize,n=t.font,i=t.bounds,a=t.cellCount,o=Zo(Qr(e));if(o.length>a)throw new S0(o.length,a);(r===void 0||r===0)&&(r=C0(o,n,i,a));for(var s=i.width/a,l=n.heightAtSize(r,{descender:!1}),c=i.y+(i.height/2-l/2),u=[],h=i.x,f=i.y,d=i.x+i.width,v=i.y+i.height,p=0,m=0;p<a;){var b=Yo(o,m),k=b[0],x=b[1],T=n.encodeText(k),w=n.widthOfTextAtSize(k,r),F=i.x+(s*p+s/2),A=F-w/2;A<h&&(h=A),c<f&&(f=c),A+w>d&&(d=A+w),c+l>v&&(v=c+l),u.push({text:o,encoded:T,width:w,height:l,x:A,y:c}),p+=1,m+=x}return{fontSize:r,cells:u,bounds:{x:h,y:f,width:d-h,height:v-f}}},Gi=function(e,t){var r=t.alignment,n=t.fontSize,i=t.font,a=t.bounds,o=Zo(Qr(e));(n===void 0||n===0)&&(n=Zl([o],i,a));var s=i.encodeText(o),l=i.widthOfTextAtSize(o,n),c=i.heightAtSize(n,{descender:!1}),u=r===Ee.Left?a.x:r===Ee.Center?a.x+a.width/2-l/2:r===Ee.Right?a.x+a.width-l:a.x,h=a.y+(a.height/2-c/2);return{fontSize:n,line:{text:o,encoded:s,width:l,height:c,x:u,y:h},bounds:{x:u,y:h,width:l,height:c}}},Ur=function(e){return"normal"in e?e:{normal:e}},D0=/\/([^\0\t\n\f\r\ ]+)[\0\t\n\f\r\ ]+(\d*\.\d+|\d+)[\0\t\n\f\r\ ]+Tf/,Jt=function(e){var t,r,n=(t=e.getDefaultAppearance())!==null&&t!==void 0?t:"",i=(r=Qi(n,D0).match)!==null&&r!==void 0?r:[],a=Number(i[2]);return isFinite(a)?a:void 0},E0=/(\d*\.\d+|\d+)[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]+(g|rg|k)/,ct=function(e){var t,r=(t=e.getDefaultAppearance())!==null&&t!==void 0?t:"",n=Qi(r,E0).match,i=n??[],a=i[1],o=i[2],s=i[3],l=i[4],c=i[5];if(c==="g"&&a)return Ml(Number(a));if(c==="rg"&&a&&o&&s)return de(Number(a),Number(o),Number(s));if(c==="k"&&a&&o&&s&&l)return jl(Number(a),Number(o),Number(s),Number(l))},lt=function(e,t,r,n){var i;n===void 0&&(n=0);var a=[gr(t).toString(),$a((i=r==null?void 0:r.name)!==null&&i!==void 0?i:"dummy__noop",n).toString()].join(`
49
49
  `);e.setDefaultAppearance(a)},O0=function(e,t){var r,n,i,a=ct(t),o=ct(e.acroField),s=t.getRectangle(),l=t.getAppearanceCharacteristics(),c=t.getBorderStyle(),u=(r=c==null?void 0:c.getWidth())!==null&&r!==void 0?r:0,h=Nt(l==null?void 0:l.getRotation()),f=dr(s,h),d=f.width,v=f.height,p=Yt(Y(Y({},s),{rotation:h})),m=de(0,0,0),b=(n=Ve(l==null?void 0:l.getBorderColor()))!==null&&n!==void 0?n:m,k=Ve(l==null?void 0:l.getBackgroundColor()),x=Ve(l==null?void 0:l.getBackgroundColor(),.8),T=(i=a??o)!==null&&i!==void 0?i:m;lt(a?t:e.acroField,T);var w={x:0+u/2,y:0+u/2,width:d-u,height:v-u,thickness:1.5,borderWidth:u,borderColor:b,markColor:T};return{normal:{on:se(p,Wi(Y(Y({},w),{color:k,filled:!0}))),off:se(p,Wi(Y(Y({},w),{color:k,filled:!1})))},down:{on:se(p,Wi(Y(Y({},w),{color:x,filled:!0}))),off:se(p,Wi(Y(Y({},w),{color:x,filled:!1})))}}},R0=function(e,t){var r,n,i,a=ct(t),o=ct(e.acroField),s=t.getRectangle(),l=t.getAppearanceCharacteristics(),c=t.getBorderStyle(),u=(r=c==null?void 0:c.getWidth())!==null&&r!==void 0?r:0,h=Nt(l==null?void 0:l.getRotation()),f=dr(s,h),d=f.width,v=f.height,p=Yt(Y(Y({},s),{rotation:h})),m=de(0,0,0),b=(n=Ve(l==null?void 0:l.getBorderColor()))!==null&&n!==void 0?n:m,k=Ve(l==null?void 0:l.getBackgroundColor()),x=Ve(l==null?void 0:l.getBackgroundColor(),.8),T=(i=a??o)!==null&&i!==void 0?i:m;lt(a?t:e.acroField,T);var w={x:d/2,y:v/2,width:d-u,height:v-u,borderWidth:u,borderColor:b,dotColor:T};return{normal:{on:se(p,qi(Y(Y({},w),{color:k,filled:!0}))),off:se(p,qi(Y(Y({},w),{color:k,filled:!1})))},down:{on:se(p,qi(Y(Y({},w),{color:x,filled:!0}))),off:se(p,qi(Y(Y({},w),{color:x,filled:!1})))}}},I0=function(e,t,r){var n,i,a,o,s,l=ct(t),c=ct(e.acroField),u=Jt(t),h=Jt(e.acroField),f=t.getRectangle(),d=t.getAppearanceCharacteristics(),v=t.getBorderStyle(),p=d==null?void 0:d.getCaptions(),m=(n=p==null?void 0:p.normal)!==null&&n!==void 0?n:"",b=(a=(i=p==null?void 0:p.down)!==null&&i!==void 0?i:m)!==null&&a!==void 0?a:"",k=(o=v==null?void 0:v.getWidth())!==null&&o!==void 0?o:0,x=Nt(d==null?void 0:d.getRotation()),T=dr(f,x),w=T.width,F=T.height,A=Yt(Y(Y({},f),{rotation:x})),D=de(0,0,0),O=Ve(d==null?void 0:d.getBorderColor()),B=Ve(d==null?void 0:d.getBackgroundColor()),E=Ve(d==null?void 0:d.getBackgroundColor(),.8),j={x:k,y:k,width:w-k*2,height:F-k*2},I=Gi(m,{alignment:Ee.Center,fontSize:u??h,font:r,bounds:j}),L=Gi(b,{alignment:Ee.Center,fontSize:u??h,font:r,bounds:j}),z=Math.min(I.fontSize,L.fontSize),P=(s=l??c)!==null&&s!==void 0?s:D;lt(l||u!==void 0?t:e.acroField,P,r,z);var U={x:0+k/2,y:0+k/2,width:w-k,height:F-k,borderWidth:k,borderColor:O,textColor:P,font:r.name,fontSize:z};return{normal:se(A,ql(Y(Y({},U),{color:B,textLines:[I.line]}))),down:se(A,ql(Y(Y({},U),{color:E,textLines:[L.line]})))}},N0=function(e,t,r){var n,i,a,o,s=ct(t),l=ct(e.acroField),c=Jt(t),u=Jt(e.acroField),h=t.getRectangle(),f=t.getAppearanceCharacteristics(),d=t.getBorderStyle(),v=(n=e.getText())!==null&&n!==void 0?n:"",p=(i=d==null?void 0:d.getWidth())!==null&&i!==void 0?i:0,m=Nt(f==null?void 0:f.getRotation()),b=dr(h,m),k=b.width,x=b.height,T=Yt(Y(Y({},h),{rotation:m})),w=de(0,0,0),F=Ve(f==null?void 0:f.getBorderColor()),A=Ve(f==null?void 0:f.getBackgroundColor()),D,O,B=e.isCombed()?0:1,E={x:p+B,y:p+B,width:k-(p+B)*2,height:x-(p+B)*2};if(e.isMultiline()){var j=Yl(v,{alignment:e.getAlignment(),fontSize:c??u,font:r,bounds:E});D=j.lines,O=j.fontSize}else if(e.isCombed()){var j=A0(v,{fontSize:c??u,font:r,bounds:E,cellCount:(a=e.getMaxLength())!==null&&a!==void 0?a:0});D=j.cells,O=j.fontSize}else{var j=Gi(v,{alignment:e.getAlignment(),fontSize:c??u,font:r,bounds:E});D=[j.line],O=j.fontSize}var I=(o=s??l)!==null&&o!==void 0?o:w;lt(s||c!==void 0?t:e.acroField,I,r,O);var L={x:0+p/2,y:0+p/2,width:k-p,height:x-p,borderWidth:p??0,borderColor:F,textColor:I,font:r.name,fontSize:O,color:A,textLines:D,padding:B};return se(T,Gl(L))},B0=function(e,t,r){var n,i,a,o=ct(t),s=ct(e.acroField),l=Jt(t),c=Jt(e.acroField),u=t.getRectangle(),h=t.getAppearanceCharacteristics(),f=t.getBorderStyle(),d=(n=e.getSelected()[0])!==null&&n!==void 0?n:"",v=(i=f==null?void 0:f.getWidth())!==null&&i!==void 0?i:0,p=Nt(h==null?void 0:h.getRotation()),m=dr(u,p),b=m.width,k=m.height,x=Yt(Y(Y({},u),{rotation:p})),T=de(0,0,0),w=Ve(h==null?void 0:h.getBorderColor()),F=Ve(h==null?void 0:h.getBackgroundColor()),A=1,D={x:v+A,y:v+A,width:b-(v+A)*2,height:k-(v+A)*2},O=Gi(d,{alignment:Ee.Left,fontSize:l??c,font:r,bounds:D}),B=O.line,E=O.fontSize,j=(a=o??s)!==null&&a!==void 0?a:T;lt(o||l!==void 0?t:e.acroField,j,r,E);var I={x:0+v/2,y:0+v/2,width:b-v,height:k-v,borderWidth:v??0,borderColor:w,textColor:j,font:r.name,fontSize:E,color:F,textLines:[B],padding:A};return se(x,Gl(I))},M0=function(e,t,r){var n,i,a=ct(t),o=ct(e.acroField),s=Jt(t),l=Jt(e.acroField),c=t.getRectangle(),u=t.getAppearanceCharacteristics(),h=t.getBorderStyle(),f=(n=h==null?void 0:h.getWidth())!==null&&n!==void 0?n:0,d=Nt(u==null?void 0:u.getRotation()),v=dr(c,d),p=v.width,m=v.height,b=Yt(Y(Y({},c),{rotation:d})),k=de(0,0,0),x=Ve(u==null?void 0:u.getBorderColor()),T=Ve(u==null?void 0:u.getBackgroundColor()),w=e.getOptions(),F=e.getSelected();e.isSorted()&&w.sort();for(var A="",D=0,O=w.length;D<O;D++)A+=w[D],D<O-1&&(A+=`
50
50
  `);for(var B=1,E={x:f+B,y:f+B,width:p-(f+B)*2,height:m-(f+B)*2},j=Yl(A,{alignment:Ee.Left,fontSize:s??l,font:r,bounds:E}),I=j.lines,L=j.fontSize,z=j.lineHeight,P=[],D=0,O=I.length;D<O;D++){var U=I[D];F.includes(U.text)&&P.push(D)}var ue=de(153/255,193/255,218/255),me=(i=a??o)!==null&&i!==void 0?i:k;return lt(a||s!==void 0?t:e.acroField,me,r,L),se(b,v0({x:0+f/2,y:0+f/2,width:p-f,height:m-f,borderWidth:f??0,borderColor:x,textColor:me,font:r.name,fontSize:L,color:T,textLines:I,lineHeight:z,selectedColor:ue,selectedLines:P,padding:B}))},Jl=function(){function e(t,r,n){this.alreadyEmbedded=!1,S(t,"ref",[[ve,"PDFRef"]]),S(r,"doc",[[_t,"PDFDocument"]]),S(n,"embedder",[[fl,"PDFPageEmbedder"]]),this.ref=t,this.doc=r,this.width=n.width,this.height=n.height,this.embedder=n}return e.prototype.scale=function(t){return S(t,"factor",["number"]),{width:this.width*t,height:this.height*t}},e.prototype.size=function(){return this.scale(1)},e.prototype.embed=function(){return _(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return this.alreadyEmbedded?[3,2]:[4,this.embedder.embedIntoContext(this.doc.context,this.ref)];case 1:t.sent(),this.alreadyEmbedded=!0,t.label=2;case 2:return[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),$e=function(){function e(t,r,n){this.modified=!0,S(t,"ref",[[ve,"PDFRef"]]),S(r,"doc",[[_t,"PDFDocument"]]),S(n,"embedder",[[Ua,"CustomFontEmbedder"],[yi,"StandardFontEmbedder"]]),this.ref=t,this.doc=r,this.name=n.fontName,this.embedder=n}return e.prototype.encodeText=function(t){return S(t,"text",["string"]),this.modified=!0,this.embedder.encodeText(t)},e.prototype.widthOfTextAtSize=function(t,r){return S(t,"text",["string"]),S(r,"size",["number"]),this.embedder.widthOfTextAtSize(t,r)},e.prototype.heightAtSize=function(t,r){var n;return S(t,"size",["number"]),N(r==null?void 0:r.descender,"options.descender",["boolean"]),this.embedder.heightOfFontAtSize(t,{descender:(n=r==null?void 0:r.descender)!==null&&n!==void 0?n:!0})},e.prototype.sizeAtHeight=function(t){return S(t,"height",["number"]),this.embedder.sizeOfFontAtHeight(t)},e.prototype.getCharacterSet=function(){return this.embedder instanceof yi?this.embedder.encoding.supportedCodePoints:this.embedder.font.characterSet},e.prototype.embed=function(){return _(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return this.modified?[4,this.embedder.embedIntoContext(this.doc.context,this.ref)]:[3,2];case 1:t.sent(),this.modified=!1,t.label=2;case 2:return[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),oo=function(){function e(t,r,n){S(t,"ref",[[ve,"PDFRef"]]),S(r,"doc",[[_t,"PDFDocument"]]),S(n,"embedder",[[il,"JpegEmbedder"],[al,"PngEmbedder"]]),this.ref=t,this.doc=r,this.width=n.width,this.height=n.height,this.embedder=n}return e.prototype.scale=function(t){return S(t,"factor",["number"]),{width:this.width*t,height:this.height*t}},e.prototype.scaleToFit=function(t,r){S(t,"width",["number"]),S(r,"height",["number"]);var n=t/this.width,i=r/this.height,a=Math.min(n,i);return this.scale(a)},e.prototype.size=function(){return this.scale(1)},e.prototype.embed=function(){return _(this,void 0,void 0,function(){var t,r,n;return $(this,function(i){switch(i.label){case 0:return this.embedder?(this.embedTask||(t=this,r=t.doc,n=t.ref,this.embedTask=this.embedder.embedIntoContext(r.context,n)),[4,this.embedTask]):[2];case 1:return i.sent(),this.embedder=void 0,[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),Qt;(function(e){e[e.Left=0]="Left",e[e.Center=1]="Center",e[e.Right=2]="Right"})(Qt||(Qt={}));var Lr=function(e){N(e==null?void 0:e.x,"options.x",["number"]),N(e==null?void 0:e.y,"options.y",["number"]),N(e==null?void 0:e.width,"options.width",["number"]),N(e==null?void 0:e.height,"options.height",["number"]),N(e==null?void 0:e.textColor,"options.textColor",[[Object,"Color"]]),N(e==null?void 0:e.backgroundColor,"options.backgroundColor",[[Object,"Color"]]),N(e==null?void 0:e.borderColor,"options.borderColor",[[Object,"Color"]]),N(e==null?void 0:e.borderWidth,"options.borderWidth",["number"]),N(e==null?void 0:e.rotate,"options.rotate",[[Object,"Rotation"]])},br=function(){function e(t,r,n){S(t,"acroField",[[Mr,"PDFAcroTerminal"]]),S(r,"ref",[[ve,"PDFRef"]]),S(n,"doc",[[_t,"PDFDocument"]]),this.acroField=t,this.ref=r,this.doc=n}return e.prototype.getName=function(){var t;return(t=this.acroField.getFullyQualifiedName())!==null&&t!==void 0?t:""},e.prototype.isReadOnly=function(){return this.acroField.hasFlag(pt.ReadOnly)},e.prototype.enableReadOnly=function(){this.acroField.setFlagTo(pt.ReadOnly,!0)},e.prototype.disableReadOnly=function(){this.acroField.setFlagTo(pt.ReadOnly,!1)},e.prototype.isRequired=function(){return this.acroField.hasFlag(pt.Required)},e.prototype.enableRequired=function(){this.acroField.setFlagTo(pt.Required,!0)},e.prototype.disableRequired=function(){this.acroField.setFlagTo(pt.Required,!1)},e.prototype.isExported=function(){return!this.acroField.hasFlag(pt.NoExport)},e.prototype.enableExporting=function(){this.acroField.setFlagTo(pt.NoExport,!1)},e.prototype.disableExporting=function(){this.acroField.setFlagTo(pt.NoExport,!0)},e.prototype.needsAppearancesUpdate=function(){throw new it(this.constructor.name,"needsAppearancesUpdate")},e.prototype.defaultUpdateAppearances=function(t){throw new it(this.constructor.name,"defaultUpdateAppearances")},e.prototype.markAsDirty=function(){this.doc.getForm().markFieldAsDirty(this.ref)},e.prototype.markAsClean=function(){this.doc.getForm().markFieldAsClean(this.ref)},e.prototype.isDirty=function(){return this.doc.getForm().fieldIsDirty(this.ref)},e.prototype.createWidget=function(t){var r,n=t.textColor,i=t.backgroundColor,a=t.borderColor,o=t.borderWidth,s=Cl(t.rotate),l=t.caption,c=t.x,u=t.y,h=t.width+o,f=t.height+o,d=!!t.hidden,v=t.page;Vc(s,"degreesAngle",90);var p=qa.create(this.doc.context,this.ref),m=Hd({x:c,y:u,width:h,height:f},o,s);p.setRectangle(m),v&&p.setP(v);var b=p.getOrCreateAppearanceCharacteristics();i&&b.setBackgroundColor(zl(i)),b.setRotation(s),l&&b.setCaptions({normal:l}),a&&b.setBorderColor(zl(a));var k=p.getOrCreateBorderStyle();if(o!==void 0&&k.setWidth(o),p.setFlagTo(Rn.Print,!0),p.setFlagTo(Rn.Hidden,d),p.setFlagTo(Rn.Invisible,!1),n){var x=(r=this.acroField.getDefaultAppearance())!==null&&r!==void 0?r:"",T=x+`
51
- `+gr(n).toString();this.acroField.setDefaultAppearance(T)}return p},e.prototype.updateWidgetAppearanceWithFont=function(t,r,n){var i=n.normal,a=n.rollover,o=n.down;this.updateWidgetAppearances(t,{normal:this.createAppearanceStream(t,i,r),rollover:a&&this.createAppearanceStream(t,a,r),down:o&&this.createAppearanceStream(t,o,r)})},e.prototype.updateOnOffWidgetAppearance=function(t,r,n){var i=n.normal,a=n.rollover,o=n.down;this.updateWidgetAppearances(t,{normal:this.createAppearanceDict(t,i,r),rollover:a&&this.createAppearanceDict(t,a,r),down:o&&this.createAppearanceDict(t,o,r)})},e.prototype.updateWidgetAppearances=function(t,r){var n=r.normal,i=r.rollover,a=r.down;t.setNormalAppearance(n),i?t.setRolloverAppearance(i):t.removeRolloverAppearance(),a?t.setDownAppearance(a):t.removeDownAppearance()},e.prototype.createAppearanceStream=function(t,r,n){var i,a=this.acroField.dict.context,o=t.getRectangle(),s=o.width,l=o.height,c=n&&{Font:(i={},i[n.name]=n.ref,i)},u=a.formXObject(r,{Resources:c,BBox:a.obj([0,0,s,l]),Matrix:a.obj([1,0,0,1,0,0])}),h=a.register(u);return h},e.prototype.createImageAppearanceStream=function(t,r,n){var i,a,o=this.acroField.dict.context,s=t.getRectangle(),l=t.getAppearanceCharacteristics(),c=t.getBorderStyle(),u=(a=c==null?void 0:c.getWidth())!==null&&a!==void 0?a:0,h=Nt(l==null?void 0:l.getRotation()),f=Yt(Y(Y({},s),{rotation:h})),d=dr(s,h),v=r.scaleToFit(d.width-u*2,d.height-u*2),p={x:u,y:u,width:v.width,height:v.height,rotate:K(0),xSkew:K(0),ySkew:K(0)};n===Qt.Center?(p.x+=(d.width-u*2)/2-v.width/2,p.y+=(d.height-u*2)/2-v.height/2):n===Qt.Right&&(p.x=d.width-u-v.width,p.y=d.height-u-v.height);var m=this.doc.context.addRandomSuffix("Image",10),b=se(f,Wl(m,p)),k={XObject:(i={},i[m]=r.ref,i)},x=o.formXObject(b,{Resources:k,BBox:o.obj([0,0,s.width,s.height]),Matrix:o.obj([1,0,0,1,0,0])});return o.register(x)},e.prototype.createAppearanceDict=function(t,r,n){var i=this.acroField.dict.context,a=this.createAppearanceStream(t,r.on),o=this.createAppearanceStream(t,r.off),s=i.obj({});return s.set(n,a),s.set(g.of("Off"),o),s},e}(),Ln=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroCheckBox",[[wi,"PDFAcroCheckBox"]]),a.acroField=r,a}return t.prototype.check=function(){var r,n=(r=this.acroField.getOnValue())!==null&&r!==void 0?r:g.of("Yes");this.markAsDirty(),this.acroField.setValue(n)},t.prototype.uncheck=function(){this.markAsDirty(),this.acroField.setValue(g.of("Off"))},t.prototype.isChecked=function(){var r=this.acroField.getOnValue();return!!r&&r===this.acroField.getValue()},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var u=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:50,height:(s=n.height)!==null&&s!==void 0?s:50,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),h=this.doc.context.register(u.dict);this.acroField.addWidget(h),u.setAppearanceState(g.of("Off")),this.updateWidgetAppearance(u,g.of("Yes")),r.node.addAnnot(h)},t.prototype.needsAppearancesUpdate=function(){for(var r,n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=o.getAppearanceState(),l=(r=o.getAppearances())===null||r===void 0?void 0:r.normal;if(!(l instanceof Q)||s&&!l.has(s))return!0}return!1},t.prototype.defaultUpdateAppearances=function(){this.updateAppearances()},t.prototype.updateAppearances=function(r){var n;N(r,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a],l=(n=s.getOnValue())!==null&&n!==void 0?n:g.of("Yes");l&&this.updateWidgetAppearance(s,l,r)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??O0,o=Ur(a(this,r));this.updateOnOffWidgetAppearance(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Ki=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroComboBox",[[Si,"PDFAcroComboBox"]]),a.acroField=r,a}return t.prototype.getOptions=function(){for(var r=this.acroField.getOptions(),n=new Array(r.length),i=0,a=n.length;i<a;i++){var o=r[i],s=o.display,l=o.value;n[i]=(s??l).decodeText()}return n},t.prototype.getSelected=function(){for(var r=this.acroField.getValues(),n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=r[i].decodeText();return n},t.prototype.setOptions=function(r){S(r,"options",[Array]);for(var n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]={value:G.fromText(r[i])};this.acroField.setOptions(n)},t.prototype.addOptions=function(r){S(r,"options",["string",Array]);for(var n=Array.isArray(r)?r:[r],i=this.acroField.getOptions(),a=new Array(n.length),o=0,s=n.length;o<s;o++)a[o]={value:G.fromText(n[o])};this.acroField.setOptions(i.concat(a))},t.prototype.select=function(r,n){n===void 0&&(n=!1),S(r,"options",["string",Array]),S(n,"merge",["boolean"]);var i=Array.isArray(r)?r:[r],a=this.getOptions(),o=i.find(function(h){return!a.includes(h)});o&&this.enableEditing(),this.markAsDirty(),(i.length>1||i.length===1&&n)&&this.enableMultiselect();for(var s=new Array(i.length),l=0,c=i.length;l<c;l++)s[l]=G.fromText(i[l]);if(n){var u=this.acroField.getValues();this.acroField.setValues(u.concat(s))}else this.acroField.setValues(s)},t.prototype.clear=function(){this.markAsDirty(),this.acroField.setValues([])},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.isEditable=function(){return this.acroField.hasFlag(ge.Edit)},t.prototype.enableEditing=function(){this.acroField.setFlagTo(ge.Edit,!0)},t.prototype.disableEditing=function(){this.acroField.setFlagTo(ge.Edit,!1)},t.prototype.isSorted=function(){return this.acroField.hasFlag(ge.Sort)},t.prototype.enableSorting=function(){this.acroField.setFlagTo(ge.Sort,!0)},t.prototype.disableSorting=function(){this.acroField.setFlagTo(ge.Sort,!1)},t.prototype.isMultiselect=function(){return this.acroField.hasFlag(ge.MultiSelect)},t.prototype.enableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!0)},t.prototype.disableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!1)},t.prototype.isSpellChecked=function(){return!this.acroField.hasFlag(ge.DoNotSpellCheck)},t.prototype.enableSpellChecking=function(){this.acroField.setFlagTo(ge.DoNotSpellCheck,!1)},t.prototype.disableSpellChecking=function(){this.acroField.setFlagTo(ge.DoNotSpellCheck,!0)},t.prototype.isSelectOnClick=function(){return this.acroField.hasFlag(ge.CommitOnSelChange)},t.prototype.enableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!0)},t.prototype.disableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!1)},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c,u;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var h=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:200,height:(s=n.height)!==null&&s!==void 0?s:50,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),f=this.doc.context.register(h.dict);this.acroField.addWidget(f);var d=(u=n.font)!==null&&u!==void 0?u:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(h,d),r.node.addAnnot(f)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??B0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Hi=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroListBox",[[Pi,"PDFAcroListBox"]]),a.acroField=r,a}return t.prototype.getOptions=function(){for(var r=this.acroField.getOptions(),n=new Array(r.length),i=0,a=n.length;i<a;i++){var o=r[i],s=o.display,l=o.value;n[i]=(s??l).decodeText()}return n},t.prototype.getSelected=function(){for(var r=this.acroField.getValues(),n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=r[i].decodeText();return n},t.prototype.setOptions=function(r){S(r,"options",[Array]),this.markAsDirty();for(var n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]={value:G.fromText(r[i])};this.acroField.setOptions(n)},t.prototype.addOptions=function(r){S(r,"options",["string",Array]),this.markAsDirty();for(var n=Array.isArray(r)?r:[r],i=this.acroField.getOptions(),a=new Array(n.length),o=0,s=n.length;o<s;o++)a[o]={value:G.fromText(n[o])};this.acroField.setOptions(i.concat(a))},t.prototype.select=function(r,n){n===void 0&&(n=!1),S(r,"options",["string",Array]),S(n,"merge",["boolean"]);var i=Array.isArray(r)?r:[r],a=this.getOptions();Nh(i,"option",a),this.markAsDirty(),(i.length>1||i.length===1&&n)&&this.enableMultiselect();for(var o=new Array(i.length),s=0,l=i.length;s<l;s++)o[s]=G.fromText(i[s]);if(n){var c=this.acroField.getValues();this.acroField.setValues(c.concat(o))}else this.acroField.setValues(o)},t.prototype.clear=function(){this.markAsDirty(),this.acroField.setValues([])},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.isSorted=function(){return this.acroField.hasFlag(ge.Sort)},t.prototype.enableSorting=function(){this.acroField.setFlagTo(ge.Sort,!0)},t.prototype.disableSorting=function(){this.acroField.setFlagTo(ge.Sort,!1)},t.prototype.isMultiselect=function(){return this.acroField.hasFlag(ge.MultiSelect)},t.prototype.enableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!0)},t.prototype.disableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!1)},t.prototype.isSelectOnClick=function(){return this.acroField.hasFlag(ge.CommitOnSelChange)},t.prototype.enableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!0)},t.prototype.disableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!1)},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c,u;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var h=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:200,height:(s=n.height)!==null&&s!==void 0?s:100,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),f=this.doc.context.register(h.dict);this.acroField.addWidget(f);var d=(u=n.font)!==null&&u!==void 0?u:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(h,d),r.node.addAnnot(f)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??M0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Vn=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroRadioButton",[[Ti,"PDFAcroRadioButton"]]),a.acroField=r,a}return t.prototype.getOptions=function(){var r=this.acroField.getExportValues();if(r){for(var n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=r[i].decodeText();return n}for(var o=this.acroField.getOnValues(),s=new Array(o.length),i=0,a=s.length;i<a;i++)s[i]=o[i].decodeText();return s},t.prototype.getSelected=function(){var r=this.acroField.getValue();if(r!==g.of("Off")){var n=this.acroField.getExportValues();if(n){for(var i=this.acroField.getOnValues(),a=0,o=i.length;a<o;a++)if(i[a]===r)return n[a].decodeText()}return r.decodeText()}},t.prototype.select=function(r){S(r,"option",["string"]);var n=this.getOptions();Gt(r,"option",n),this.markAsDirty();var i=this.acroField.getOnValues(),a=this.acroField.getExportValues();if(a)for(var o=0,s=a.length;o<s;o++)a[o].decodeText()===r&&this.acroField.setValue(i[o]);else for(var o=0,s=i.length;o<s;o++){var l=i[o];l.decodeText()===r&&this.acroField.setValue(l)}},t.prototype.clear=function(){this.markAsDirty(),this.acroField.setValue(g.of("Off"))},t.prototype.isOffToggleable=function(){return!this.acroField.hasFlag(ot.NoToggleToOff)},t.prototype.enableOffToggling=function(){this.acroField.setFlagTo(ot.NoToggleToOff,!1)},t.prototype.disableOffToggling=function(){this.acroField.setFlagTo(ot.NoToggleToOff,!0)},t.prototype.isMutuallyExclusive=function(){return!this.acroField.hasFlag(ot.RadiosInUnison)},t.prototype.enableMutualExclusion=function(){this.acroField.setFlagTo(ot.RadiosInUnison,!1)},t.prototype.disableMutualExclusion=function(){this.acroField.setFlagTo(ot.RadiosInUnison,!0)},t.prototype.addOptionToPage=function(r,n,i){var a,o,s,l,c,u,h,f,d;S(r,"option",["string"]),S(n,"page",[[ut,"PDFPage"]]),Lr(i);var v=this.createWidget({x:(a=i==null?void 0:i.x)!==null&&a!==void 0?a:0,y:(o=i==null?void 0:i.y)!==null&&o!==void 0?o:0,width:(s=i==null?void 0:i.width)!==null&&s!==void 0?s:50,height:(l=i==null?void 0:i.height)!==null&&l!==void 0?l:50,textColor:(c=i==null?void 0:i.textColor)!==null&&c!==void 0?c:de(0,0,0),backgroundColor:(u=i==null?void 0:i.backgroundColor)!==null&&u!==void 0?u:de(1,1,1),borderColor:(h=i==null?void 0:i.borderColor)!==null&&h!==void 0?h:de(0,0,0),borderWidth:(f=i==null?void 0:i.borderWidth)!==null&&f!==void 0?f:1,rotate:(d=i==null?void 0:i.rotate)!==null&&d!==void 0?d:K(0),hidden:i==null?void 0:i.hidden,page:n.ref}),p=this.doc.context.register(v.dict),m=this.acroField.addWidgetWithOpt(p,G.fromText(r),!this.isMutuallyExclusive());v.setAppearanceState(g.of("Off")),this.updateWidgetAppearance(v,m),n.node.addAnnot(p)},t.prototype.needsAppearancesUpdate=function(){for(var r,n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=o.getAppearanceState(),l=(r=o.getAppearances())===null||r===void 0?void 0:r.normal;if(!(l instanceof Q)||s&&!l.has(s))return!0}return!1},t.prototype.defaultUpdateAppearances=function(){this.updateAppearances()},t.prototype.updateAppearances=function(r){N(r,"provider",[Function]);for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=o.getOnValue();s&&this.updateWidgetAppearance(o,s,r)}},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??R0,o=Ur(a(this,r));this.updateOnOffWidgetAppearance(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),so=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroSignature",[[Ka,"PDFAcroSignature"]]),a.acroField=r,a}return t.prototype.needsAppearancesUpdate=function(){return!1},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Xi=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroText",[[ki,"PDFAcroText"]]),a.acroField=r,a}return t.prototype.getText=function(){var r=this.acroField.getValue();if(!r&&this.isRichFormatted())throw new w0(this.getName());return r==null?void 0:r.decodeText()},t.prototype.setText=function(r){N(r,"text",["string"]);var n=this.getMaxLength();if(n!==void 0&&r&&r.length>n)throw new F0(r.length,n,this.getName());this.markAsDirty(),this.disableRichFormatting(),r?this.acroField.setValue(G.fromText(r)):this.acroField.removeValue()},t.prototype.getAlignment=function(){var r=this.acroField.getQuadding();return r===0?Ee.Left:r===1?Ee.Center:r===2?Ee.Right:Ee.Left},t.prototype.setAlignment=function(r){Gt(r,"alignment",Ee),this.markAsDirty(),this.acroField.setQuadding(r)},t.prototype.getMaxLength=function(){return this.acroField.getMaxLength()},t.prototype.setMaxLength=function(r){if(vt(r,"maxLength",0,Number.MAX_SAFE_INTEGER),this.markAsDirty(),r===void 0)this.acroField.removeMaxLength();else{var n=this.getText();if(n&&n.length>r)throw new k0(n.length,r,this.getName());this.acroField.setMaxLength(r)}},t.prototype.removeMaxLength=function(){this.markAsDirty(),this.acroField.removeMaxLength()},t.prototype.setImage=function(r){for(var n=this.getAlignment(),i=n===Ee.Center?Qt.Center:n===Ee.Right?Qt.Right:Qt.Left,a=this.acroField.getWidgets(),o=0,s=a.length;o<s;o++){var l=a[o],c=this.createImageAppearanceStream(l,r,i);this.updateWidgetAppearances(l,{normal:c})}this.markAsClean()},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.isMultiline=function(){return this.acroField.hasFlag(Se.Multiline)},t.prototype.enableMultiline=function(){this.markAsDirty(),this.acroField.setFlagTo(Se.Multiline,!0)},t.prototype.disableMultiline=function(){this.markAsDirty(),this.acroField.setFlagTo(Se.Multiline,!1)},t.prototype.isPassword=function(){return this.acroField.hasFlag(Se.Password)},t.prototype.enablePassword=function(){this.acroField.setFlagTo(Se.Password,!0)},t.prototype.disablePassword=function(){this.acroField.setFlagTo(Se.Password,!1)},t.prototype.isFileSelector=function(){return this.acroField.hasFlag(Se.FileSelect)},t.prototype.enableFileSelection=function(){this.acroField.setFlagTo(Se.FileSelect,!0)},t.prototype.disableFileSelection=function(){this.acroField.setFlagTo(Se.FileSelect,!1)},t.prototype.isSpellChecked=function(){return!this.acroField.hasFlag(Se.DoNotSpellCheck)},t.prototype.enableSpellChecking=function(){this.acroField.setFlagTo(Se.DoNotSpellCheck,!1)},t.prototype.disableSpellChecking=function(){this.acroField.setFlagTo(Se.DoNotSpellCheck,!0)},t.prototype.isScrollable=function(){return!this.acroField.hasFlag(Se.DoNotScroll)},t.prototype.enableScrolling=function(){this.acroField.setFlagTo(Se.DoNotScroll,!1)},t.prototype.disableScrolling=function(){this.acroField.setFlagTo(Se.DoNotScroll,!0)},t.prototype.isCombed=function(){return this.acroField.hasFlag(Se.Comb)&&!this.isMultiline()&&!this.isPassword()&&!this.isFileSelector()&&this.getMaxLength()!==void 0},t.prototype.enableCombing=function(){if(this.getMaxLength()===void 0){var r="PDFTextFields must have a max length in order to be combed";console.warn(r)}this.markAsDirty(),this.disableMultiline(),this.disablePassword(),this.disableFileSelection(),this.acroField.setFlagTo(Se.Comb,!0)},t.prototype.disableCombing=function(){this.markAsDirty(),this.acroField.setFlagTo(Se.Comb,!1)},t.prototype.isRichFormatted=function(){return this.acroField.hasFlag(Se.RichText)},t.prototype.enableRichFormatting=function(){this.acroField.setFlagTo(Se.RichText,!0)},t.prototype.disableRichFormatting=function(){this.acroField.setFlagTo(Se.RichText,!1)},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c,u;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var h=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:200,height:(s=n.height)!==null&&s!==void 0?s:50,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),f=this.doc.context.register(h.dict);this.acroField.addWidget(f);var d=(u=n.font)!==null&&u!==void 0?u:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(h,d),r.node.addAnnot(f)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??N0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Vr;(function(e){e.Courier="Courier",e.CourierBold="Courier-Bold",e.CourierOblique="Courier-Oblique",e.CourierBoldOblique="Courier-BoldOblique",e.Helvetica="Helvetica",e.HelveticaBold="Helvetica-Bold",e.HelveticaOblique="Helvetica-Oblique",e.HelveticaBoldOblique="Helvetica-BoldOblique",e.TimesRoman="Times-Roman",e.TimesRomanBold="Times-Bold",e.TimesRomanItalic="Times-Italic",e.TimesRomanBoldItalic="Times-BoldItalic",e.Symbol="Symbol",e.ZapfDingbats="ZapfDingbats"})(Vr||(Vr={}));var j0=function(){function e(t,r){var n=this;this.embedDefaultFont=function(){return n.doc.embedStandardFont(Vr.Helvetica)},S(t,"acroForm",[[Ai,"PDFAcroForm"]]),S(r,"doc",[[_t,"PDFDocument"]]),this.acroForm=t,this.doc=r,this.dirtyFields=new Set,this.defaultFontCache=Ot.populatedBy(this.embedDefaultFont)}return e.prototype.hasXFA=function(){return this.acroForm.dict.has(g.of("XFA"))},e.prototype.deleteXFA=function(){this.acroForm.dict.delete(g.of("XFA"))},e.prototype.getFields=function(){for(var t=this.acroForm.getAllFields(),r=[],n=0,i=t.length;n<i;n++){var a=t[n],o=a[0],s=a[1],l=z0(o,s,this.doc);l&&r.push(l)}return r},e.prototype.getFieldMaybe=function(t){S(t,"name",["string"]);for(var r=this.getFields(),n=0,i=r.length;n<i;n++){var a=r[n];if(a.getName()===t)return a}},e.prototype.getField=function(t){S(t,"name",["string"]);var r=this.getFieldMaybe(t);if(r)return r;throw new m0(t)},e.prototype.getButton=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Zi)return r;throw new yr(t,Zi,r)},e.prototype.getCheckBox=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Ln)return r;throw new yr(t,Ln,r)},e.prototype.getDropdown=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Ki)return r;throw new yr(t,Ki,r)},e.prototype.getOptionList=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Hi)return r;throw new yr(t,Hi,r)},e.prototype.getRadioGroup=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Vn)return r;throw new yr(t,Vn,r)},e.prototype.getSignature=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof so)return r;throw new yr(t,so,r)},e.prototype.getTextField=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Xi)return r;throw new yr(t,Xi,r)},e.prototype.createButton=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Ci.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Zi.of(i,i.ref,this.doc)},e.prototype.createCheckBox=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=wi.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Ln.of(i,i.ref,this.doc)},e.prototype.createDropdown=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Si.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Ki.of(i,i.ref,this.doc)},e.prototype.createOptionList=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Pi.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Hi.of(i,i.ref,this.doc)},e.prototype.createRadioGroup=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Ti.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Vn.of(i,i.ref,this.doc)},e.prototype.createTextField=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=ki.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Xi.of(i,i.ref,this.doc)},e.prototype.flatten=function(t){t===void 0&&(t={updateFieldAppearances:!0}),t.updateFieldAppearances&&this.updateFieldAppearances();for(var r=this.getFields(),n=0,i=r.length;n<i;n++){for(var a=r[n],o=a.acroField.getWidgets(),s=0,l=o.length;s<l;s++){var c=o[s],u=this.findWidgetPage(c),h=this.findWidgetAppearanceRef(a,c),f=u.node.newXObject("FlatWidget",h),d=c.getRectangle(),v=se([Ae(),st(d.x,d.y)],Yt(Y(Y({},d),{rotation:0})),[eo(f),De()]).filter(Boolean);u.pushOperators.apply(u,v)}this.removeField(a)}},e.prototype.removeField=function(t){for(var r=t.acroField.getWidgets(),n=new Set,i=0,a=r.length;i<a;i++){var o=r[i],s=this.findWidgetAppearanceRef(t,o),l=this.findWidgetPage(o);n.add(l),l.node.removeAnnot(s)}n.forEach(function(d){return d.node.removeAnnot(t.ref)}),this.acroForm.removeField(t.acroField);for(var c=t.acroField.normalizedEntries().Kids,u=c.size(),h=0;h<u;h++){var f=c.get(h);f instanceof ve&&this.doc.context.delete(f)}this.doc.context.delete(t.ref)},e.prototype.updateFieldAppearances=function(t){N(t,"font",[[$e,"PDFFont"]]),t=t??this.getDefaultFont();for(var r=this.getFields(),n=0,i=r.length;n<i;n++){var a=r[n];a.needsAppearancesUpdate()&&a.defaultUpdateAppearances(t)}},e.prototype.markFieldAsDirty=function(t){N(t,"fieldRef",[[ve,"PDFRef"]]),this.dirtyFields.add(t)},e.prototype.markFieldAsClean=function(t){N(t,"fieldRef",[[ve,"PDFRef"]]),this.dirtyFields.delete(t)},e.prototype.fieldIsDirty=function(t){return N(t,"fieldRef",[[ve,"PDFRef"]]),this.dirtyFields.has(t)},e.prototype.getDefaultFont=function(){return this.defaultFontCache.access()},e.prototype.findWidgetPage=function(t){var r=t.P(),n=this.doc.getPages().find(function(a){return a.ref===r});if(n===void 0){var i=this.doc.context.getObjectRef(t.dict);if(i===void 0)throw new Error("Could not find PDFRef for PDFObject");if(n=this.doc.findPageForAnnotationRef(i),n===void 0)throw new Error("Could not find page for PDFRef "+i)}return n},e.prototype.findWidgetAppearanceRef=function(t,r){var n,i=r.getNormalAppearance();if(i instanceof Q&&(t instanceof Ln||t instanceof Vn)){var a=t.acroField.getValue(),o=(n=i.get(a))!==null&&n!==void 0?n:i.get(g.of("Off"));o instanceof ve&&(i=o)}if(!(i instanceof ve)){var s=t.getName();throw new Error("Failed to extract appearance ref for: "+s)}return i},e.prototype.findOrCreateNonTerminals=function(t){for(var r=[this.acroForm],n=0,i=t.length;n<i;n++){var a=t[n];if(!a)throw new x0(a);var o=r[0],s=r[1],l=this.findNonTerminal(a,o);if(l)r=l;else{var c=Fi.create(this.doc.context);c.setPartialName(a),c.setParent(s);var u=this.doc.context.register(c.dict);o.addField(u),r=[c,u]}}return r},e.prototype.findNonTerminal=function(t,r){for(var n=r instanceof Ai?this.acroForm.getFields():Ha(r.Kids()),i=0,a=n.length;i<a;i++){var o=n[i],s=o[0],l=o[1];if(s.getPartialName()===t){if(s instanceof Fi)return[s,l];throw new Kl(t)}}},e.of=function(t,r){return new e(t,r)},e}(),z0=function(e,t,r){if(e instanceof Ci)return Zi.of(e,t,r);if(e instanceof wi)return Ln.of(e,t,r);if(e instanceof Si)return Ki.of(e,t,r);if(e instanceof Pi)return Hi.of(e,t,r);if(e instanceof ki)return Xi.of(e,t,r);if(e instanceof Ti)return Vn.of(e,t,r);if(e instanceof Ka)return so.of(e,t,r)},Wr=function(e){if(e.length===0)throw new Error("PDF field names must not be empty strings");for(var t=e.split("."),r=0,n=t.length;r<n;r++)if(t[r]==="")throw new Error('Periods in PDF field names must be separated by at least one character: "'+e+'"');return t.length===1?{nonTerminal:[],terminal:t[0]}:{nonTerminal:t.slice(0,t.length-1),terminal:t[t.length-1]}},qr=function(e,t,r){for(var n=e[0],i=e[1],a=t[0],o=t[1],s=n.normalizedEntries(),l=Ha("Kids"in s?s.Kids:s.Fields),c=0,u=l.length;c<u;c++)if(l[c][0].getPartialName()===r)throw new Kl(r);n.addField(o),a.setParent(i)},U0={A4:[595.28,841.89]},co;(function(e){e[e.Fastest=1/0]="Fastest",e[e.Fast=1500]="Fast",e[e.Medium=500]="Medium",e[e.Slow=100]="Slow"})(co||(co={}));var L0=function(){function e(t,r,n){this.alreadyEmbedded=!1,this.ref=t,this.doc=r,this.embedder=n}return e.prototype.embed=function(){return _(this,void 0,void 0,function(){var t,r,n,i,a;return $(this,function(o){switch(o.label){case 0:return this.alreadyEmbedded?[3,2]:[4,this.embedder.embedIntoContext(this.doc.context,this.ref)];case 1:t=o.sent(),this.doc.catalog.has(g.of("Names"))||this.doc.catalog.set(g.of("Names"),this.doc.context.obj({})),r=this.doc.catalog.lookup(g.of("Names"),Q),r.has(g.of("EmbeddedFiles"))||r.set(g.of("EmbeddedFiles"),this.doc.context.obj({})),n=r.lookup(g.of("EmbeddedFiles"),Q),n.has(g.of("Names"))||n.set(g.of("Names"),this.doc.context.obj([])),i=n.lookup(g.of("Names"),fe),i.push(G.fromText(this.embedder.fileName)),i.push(t),this.doc.catalog.has(g.of("AF"))||this.doc.catalog.set(g.of("AF"),this.doc.context.obj([])),a=this.doc.catalog.lookup(g.of("AF"),fe),a.push(t),this.alreadyEmbedded=!0,o.label=2;case 2:return[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),V0=function(){function e(t,r,n){this.alreadyEmbedded=!1,this.ref=t,this.doc=r,this.embedder=n}return e.prototype.embed=function(){return _(this,void 0,void 0,function(){var t,r,n,i,a,o,s;return $(this,function(l){switch(l.label){case 0:return this.alreadyEmbedded?[3,2]:(t=this.doc,r=t.catalog,n=t.context,[4,this.embedder.embedIntoContext(this.doc.context,this.ref)]);case 1:i=l.sent(),r.has(g.of("Names"))||r.set(g.of("Names"),n.obj({})),a=r.lookup(g.of("Names"),Q),a.has(g.of("JavaScript"))||a.set(g.of("JavaScript"),n.obj({})),o=a.lookup(g.of("JavaScript"),Q),o.has(g.of("Names"))||o.set(g.of("Names"),n.obj([])),s=o.lookup(g.of("Names"),fe),s.push(G.fromText(this.embedder.scriptName)),s.push(i),this.alreadyEmbedded=!0,l.label=2;case 2:return[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),W0=function(){function e(t,r){this.script=t,this.scriptName=r}return e.for=function(t,r){return new e(t,r)},e.prototype.embedIntoContext=function(t,r){return _(this,void 0,void 0,function(){var n;return $(this,function(i){return n=t.obj({Type:"Action",S:"JavaScript",JS:G.fromText(this.script)}),r?(t.assign(r,n),[2,r]):[2,t.register(n)]})})},e}(),_t=function(){function e(t,r,n){var i=this;if(this.defaultWordBreaks=[" "],this.computePages=function(){var a=[];return i.catalog.Pages().traverse(function(o,s){if(o instanceof It){var l=i.pageMap.get(o);l||(l=ut.of(o,s,i),i.pageMap.set(o,l)),a.push(l)}}),a},this.getOrCreateForm=function(){var a=i.catalog.getOrCreateAcroForm();return j0.of(a,i)},S(t,"context",[[ja,"PDFContext"]]),S(r,"ignoreEncryption",["boolean"]),this.context=t,this.catalog=t.lookup(t.trailerInfo.Root),this.isEncrypted=!!t.lookup(t.trailerInfo.Encrypt),this.pageCache=Ot.populatedBy(this.computePages),this.pageMap=new Map,this.formCache=Ot.populatedBy(this.getOrCreateForm),this.fonts=[],this.images=[],this.embeddedPages=[],this.embeddedFiles=[],this.javaScripts=[],!r&&this.isEncrypted)throw new p0;n&&this.updateInfoDict()}return e.load=function(t,r){return r===void 0&&(r={}),_(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u,h,f,d,v;return $(this,function(p){switch(p.label){case 0:return n=r.ignoreEncryption,i=n===void 0?!1:n,a=r.parseSpeed,o=a===void 0?co.Slow:a,s=r.throwOnInvalidObject,l=s===void 0?!1:s,c=r.updateMetadata,u=c===void 0?!0:c,h=r.capNumbers,f=h===void 0?!1:h,S(t,"pdf",["string",Uint8Array,ArrayBuffer]),S(i,"ignoreEncryption",["boolean"]),S(o,"parseSpeed",["number"]),S(l,"throwOnInvalidObject",["boolean"]),d=_r(t),[4,Gd.forBytesWithOptions(d,o,l,f).parseDocument()];case 1:return v=p.sent(),[2,new e(v,i,u)]}})})},e.create=function(t){return t===void 0&&(t={}),_(this,void 0,void 0,function(){var r,n,i,a,o,s;return $(this,function(l){return r=t.updateMetadata,n=r===void 0?!0:r,i=ja.create(),a=bl.withContext(i),o=i.register(a),s=yl.withContextAndPages(i,o),i.trailerInfo.Root=i.register(s),[2,new e(i,!1,n)]})})},e.prototype.registerFontkit=function(t){this.fontkit=t},e.prototype.getForm=function(){var t=this.formCache.access();return t.hasXFA()&&(console.warn("Removing XFA form data as pdf-lib does not support reading or writing XFA"),t.deleteXFA()),t},e.prototype.getTitle=function(){var t=this.getInfoDict().lookup(g.Title);if(t)return $t(t),t.decodeText()},e.prototype.getAuthor=function(){var t=this.getInfoDict().lookup(g.Author);if(t)return $t(t),t.decodeText()},e.prototype.getSubject=function(){var t=this.getInfoDict().lookup(g.Subject);if(t)return $t(t),t.decodeText()},e.prototype.getKeywords=function(){var t=this.getInfoDict().lookup(g.Keywords);if(t)return $t(t),t.decodeText()},e.prototype.getCreator=function(){var t=this.getInfoDict().lookup(g.Creator);if(t)return $t(t),t.decodeText()},e.prototype.getProducer=function(){var t=this.getInfoDict().lookup(g.Producer);if(t)return $t(t),t.decodeText()},e.prototype.getCreationDate=function(){var t=this.getInfoDict().lookup(g.CreationDate);if(t)return $t(t),t.decodeDate()},e.prototype.getModificationDate=function(){var t=this.getInfoDict().lookup(g.ModDate);if(t)return $t(t),t.decodeDate()},e.prototype.setTitle=function(t,r){S(t,"title",["string"]);var n=g.of("Title");if(this.getInfoDict().set(n,G.fromText(t)),r!=null&&r.showInWindowTitleBar){var i=this.catalog.getOrCreateViewerPreferences();i.setDisplayDocTitle(!0)}},e.prototype.setAuthor=function(t){S(t,"author",["string"]);var r=g.of("Author");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setSubject=function(t){S(t,"author",["string"]);var r=g.of("Subject");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setKeywords=function(t){S(t,"keywords",[Array]);var r=g.of("Keywords");this.getInfoDict().set(r,G.fromText(t.join(" ")))},e.prototype.setCreator=function(t){S(t,"creator",["string"]);var r=g.of("Creator");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setProducer=function(t){S(t,"creator",["string"]);var r=g.of("Producer");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setLanguage=function(t){S(t,"language",["string"]);var r=g.of("Lang");this.catalog.set(r,pe.of(t))},e.prototype.setCreationDate=function(t){S(t,"creationDate",[[Date,"Date"]]);var r=g.of("CreationDate");this.getInfoDict().set(r,pe.fromDate(t))},e.prototype.setModificationDate=function(t){S(t,"modificationDate",[[Date,"Date"]]);var r=g.of("ModDate");this.getInfoDict().set(r,pe.fromDate(t))},e.prototype.getPageCount=function(){return this.pageCount===void 0&&(this.pageCount=this.getPages().length),this.pageCount},e.prototype.getPages=function(){return this.pageCache.access()},e.prototype.getPage=function(t){var r=this.getPages();return Je(t,"index",0,r.length-1),r[t]},e.prototype.getPageIndices=function(){return Su(0,this.getPageCount())},e.prototype.removePage=function(t){var r=this.getPageCount();if(this.pageCount===0)throw new b0;Je(t,"index",0,r-1),this.catalog.removeLeafNode(t),this.pageCount=r-1},e.prototype.addPage=function(t){return S(t,"page",["undefined",[ut,"PDFPage"],Array]),this.insertPage(this.getPageCount(),t)},e.prototype.insertPage=function(t,r){var n=this.getPageCount();if(Je(t,"index",0,n),S(r,"page",["undefined",[ut,"PDFPage"],Array]),!r||Array.isArray(r)){var i=Array.isArray(r)?r:U0.A4;r=ut.create(this),r.setSize.apply(r,i)}else if(r.doc!==this)throw new y0;var a=this.catalog.insertLeafNode(r.ref,t);return r.node.setParent(a),this.pageMap.set(r.node,r),this.pageCache.invalidate(),this.pageCount=n+1,r},e.prototype.copyPages=function(t,r){return _(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u;return $(this,function(h){switch(h.label){case 0:return S(t,"srcDoc",[[e,"PDFDocument"]]),S(r,"indices",[Array]),[4,t.flush()];case 1:for(h.sent(),n=Qc.for(t.context,this.context),i=t.getPages(),a=new Array(r.length),o=0,s=r.length;o<s;o++)l=i[r[o]],c=n.copy(l.node),u=this.context.register(c),a[o]=ut.of(c,u,this);return[2,a]}})})},e.prototype.copy=function(){return _(this,void 0,void 0,function(){var t,r,n,i;return $(this,function(a){switch(a.label){case 0:return[4,e.create()];case 1:return t=a.sent(),[4,t.copyPages(this,this.getPageIndices())];case 2:for(r=a.sent(),n=0,i=r.length;n<i;n++)t.addPage(r[n]);return this.getAuthor()!==void 0&&t.setAuthor(this.getAuthor()),this.getCreationDate()!==void 0&&t.setCreationDate(this.getCreationDate()),this.getCreator()!==void 0&&t.setCreator(this.getCreator()),this.getModificationDate()!==void 0&&t.setModificationDate(this.getModificationDate()),this.getProducer()!==void 0&&t.setProducer(this.getProducer()),this.getSubject()!==void 0&&t.setSubject(this.getSubject()),this.getTitle()!==void 0&&t.setTitle(this.getTitle()),t.defaultWordBreaks=this.defaultWordBreaks,[2,t]}})})},e.prototype.addJavaScript=function(t,r){S(t,"name",["string"]),S(r,"script",["string"]);var n=W0.for(r,t),i=this.context.nextRef(),a=V0.of(i,this,n);this.javaScripts.push(a)},e.prototype.attach=function(t,r,n){return n===void 0&&(n={}),_(this,void 0,void 0,function(){var i,a,o,s;return $(this,function(l){return S(t,"attachment",["string",Uint8Array,ArrayBuffer]),S(r,"name",["string"]),N(n.mimeType,"mimeType",["string"]),N(n.description,"description",["string"]),N(n.creationDate,"options.creationDate",[Date]),N(n.modificationDate,"options.modificationDate",[Date]),nt(n.afRelationship,"options.afRelationship",La),i=_r(t),a=gd.for(i,r,n),o=this.context.nextRef(),s=L0.of(o,this,a),this.embeddedFiles.push(s),[2]})})},e.prototype.embedFont=function(t,r){return r===void 0&&(r={}),_(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u,h,f;return $(this,function(d){switch(d.label){case 0:return n=r.subset,i=n===void 0?!1:n,a=r.customName,o=r.features,S(t,"font",["string",Uint8Array,ArrayBuffer]),S(i,"subset",["boolean"]),zc(t)?(s=yi.for(t,a),[3,7]):[3,1];case 1:return ku(t)?(l=_r(t),c=this.assertFontkit(),i?[4,pd.for(c,l,a,o)]:[3,3]):[3,6];case 2:return u=d.sent(),[3,5];case 3:return[4,Ua.for(c,l,a,o)];case 4:u=d.sent(),d.label=5;case 5:return s=u,[3,7];case 6:throw new TypeError("`font` must be one of `StandardFonts | string | Uint8Array | ArrayBuffer`");case 7:return h=this.context.nextRef(),f=$e.of(h,this,s),this.fonts.push(f),[2,f]}})})},e.prototype.embedStandardFont=function(t,r){if(S(t,"font",["string"]),!zc(t))throw new TypeError("`font` must be one of type `StandardFonts`");var n=yi.for(t,r),i=this.context.nextRef(),a=$e.of(i,this,n);return this.fonts.push(a),a},e.prototype.embedJpg=function(t){return _(this,void 0,void 0,function(){var r,n,i,a;return $(this,function(o){switch(o.label){case 0:return S(t,"jpg",["string",Uint8Array,ArrayBuffer]),r=_r(t),[4,il.for(r)];case 1:return n=o.sent(),i=this.context.nextRef(),a=oo.of(i,this,n),this.images.push(a),[2,a]}})})},e.prototype.embedPng=function(t){return _(this,void 0,void 0,function(){var r,n,i,a;return $(this,function(o){switch(o.label){case 0:return S(t,"png",["string",Uint8Array,ArrayBuffer]),r=_r(t),[4,al.for(r)];case 1:return n=o.sent(),i=this.context.nextRef(),a=oo.of(i,this,n),this.images.push(a),[2,a]}})})},e.prototype.embedPdf=function(t,r){return r===void 0&&(r=[0]),_(this,void 0,void 0,function(){var n,i,a;return $(this,function(o){switch(o.label){case 0:return S(t,"pdf",["string",Uint8Array,ArrayBuffer,[e,"PDFDocument"]]),S(r,"indices",[Array]),t instanceof e?(i=t,[3,3]):[3,1];case 1:return[4,e.load(t)];case 2:i=o.sent(),o.label=3;case 3:return n=i,a=Fu(n.getPages(),r),[2,this.embedPages(a)]}})})},e.prototype.embedPage=function(t,r,n){return _(this,void 0,void 0,function(){var i;return $(this,function(a){switch(a.label){case 0:return S(t,"page",[[ut,"PDFPage"]]),[4,this.embedPages([t],[r],[n])];case 1:return i=a.sent()[0],[2,i]}})})},e.prototype.embedPages=function(t,r,n){return r===void 0&&(r=[]),n===void 0&&(n=[]),_(this,void 0,void 0,function(){var c,u,i,a,o,s,l,c,u,h,f,d,v,p,m;return $(this,function(b){switch(b.label){case 0:if(t.length===0)return[2,[]];for(c=0,u=t.length-1;c<u;c++)if(i=t[c],a=t[c+1],i.node.context!==a.node.context)throw new Wh;o=t[0].node.context,s=o===this.context?function(k){return k}:Qc.for(o,this.context).copy,l=new Array(t.length),c=0,u=t.length,b.label=1;case 1:return c<u?(h=s(t[c].node),f=r[c],d=n[c],[4,fl.for(h,f,d)]):[3,4];case 2:v=b.sent(),p=this.context.nextRef(),l[c]=Jl.of(p,this,v),b.label=3;case 3:return c++,[3,1];case 4:return(m=this.embeddedPages).push.apply(m,l),[2,l]}})})},e.prototype.flush=function(){return _(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,this.embedAll(this.fonts)];case 1:return t.sent(),[4,this.embedAll(this.images)];case 2:return t.sent(),[4,this.embedAll(this.embeddedPages)];case 3:return t.sent(),[4,this.embedAll(this.embeddedFiles)];case 4:return t.sent(),[4,this.embedAll(this.javaScripts)];case 5:return t.sent(),[2]}})})},e.prototype.save=function(t){return t===void 0&&(t={}),_(this,void 0,void 0,function(){var r,n,i,a,o,s,l,c,u,h;return $(this,function(f){switch(f.label){case 0:return r=t.useObjectStreams,n=r===void 0?!0:r,i=t.addDefaultPage,a=i===void 0?!0:i,o=t.objectsPerTick,s=o===void 0?50:o,l=t.updateFieldAppearances,c=l===void 0?!0:l,S(n,"useObjectStreams",["boolean"]),S(a,"addDefaultPage",["boolean"]),S(s,"objectsPerTick",["number"]),S(c,"updateFieldAppearances",["boolean"]),a&&this.getPageCount()===0&&this.addPage(),c&&(u=this.formCache.getValue(),u&&u.updateFieldAppearances()),[4,this.flush()];case 1:return f.sent(),h=n?ld:el,[2,h.forContext(this.context,s).serializeToBuffer()]}})})},e.prototype.saveAsBase64=function(t){return t===void 0&&(t={}),_(this,void 0,void 0,function(){var r,n,i,a,o;return $(this,function(s){switch(s.label){case 0:return r=t.dataUri,n=r===void 0?!1:r,i=au(t,["dataUri"]),S(n,"dataUri",["boolean"]),[4,this.save(i)];case 1:return a=s.sent(),o=ou(a),[2,n?"data:application/pdf;base64,"+o:o]}})})},e.prototype.findPageForAnnotationRef=function(t){for(var r=this.getPages(),n=0,i=r.length;n<i;n++){var a=r[n],o=a.node.Annots();if((o==null?void 0:o.indexOf(t))!==void 0)return a}},e.prototype.embedAll=function(t){return _(this,void 0,void 0,function(){var r,n;return $(this,function(i){switch(i.label){case 0:r=0,n=t.length,i.label=1;case 1:return r<n?[4,t[r].embed()]:[3,4];case 2:i.sent(),i.label=3;case 3:return r++,[3,1];case 4:return[2]}})})},e.prototype.updateInfoDict=function(){var t="pdf-lib (https://github.com/Hopding/pdf-lib)",r=new Date,n=this.getInfoDict();this.setProducer(t),this.setModificationDate(r),n.get(g.of("Creator"))||this.setCreator(t),n.get(g.of("CreationDate"))||this.setCreationDate(r)},e.prototype.getInfoDict=function(){var t=this.context.lookup(this.context.trailerInfo.Info);if(t instanceof Q)return t;var r=this.context.obj({});return this.context.trailerInfo.Info=this.context.register(r),r},e.prototype.assertFontkit=function(){if(!this.fontkit)throw new g0;return this.fontkit},e}();function $t(e){if(!(e instanceof G)&&!(e instanceof pe))throw new vi([G,pe],e)}var Bt;(function(e){e.Normal="Normal",e.Multiply="Multiply",e.Screen="Screen",e.Overlay="Overlay",e.Darken="Darken",e.Lighten="Lighten",e.ColorDodge="ColorDodge",e.ColorBurn="ColorBurn",e.HardLight="HardLight",e.SoftLight="SoftLight",e.Difference="Difference",e.Exclusion="Exclusion"})(Bt||(Bt={}));var ut=function(){function e(t,r,n){this.fontSize=24,this.fontColor=de(0,0,0),this.lineHeight=24,this.x=0,this.y=0,S(t,"leafNode",[[It,"PDFPageLeaf"]]),S(r,"ref",[[ve,"PDFRef"]]),S(n,"doc",[[_t,"PDFDocument"]]),this.node=t,this.ref=r,this.doc=n}return e.prototype.setRotation=function(t){var r=Cl(t);Vc(r,"degreesAngle",90),this.node.set(g.of("Rotate"),this.doc.context.obj(r))},e.prototype.getRotation=function(){var t=this.node.Rotate();return K(t?t.asNumber():0)},e.prototype.setSize=function(t,r){S(t,"width",["number"]),S(r,"height",["number"]);var n=this.getMediaBox();this.setMediaBox(n.x,n.y,t,r);var i=this.getCropBox(),a=this.getBleedBox(),o=this.getTrimBox(),s=this.getArtBox(),l=this.node.CropBox(),c=this.node.BleedBox(),u=this.node.TrimBox(),h=this.node.ArtBox();l&&fi(i,n)&&this.setCropBox(n.x,n.y,t,r),c&&fi(a,n)&&this.setBleedBox(n.x,n.y,t,r),u&&fi(o,n)&&this.setTrimBox(n.x,n.y,t,r),h&&fi(s,n)&&this.setArtBox(n.x,n.y,t,r)},e.prototype.setWidth=function(t){S(t,"width",["number"]),this.setSize(t,this.getSize().height)},e.prototype.setHeight=function(t){S(t,"height",["number"]),this.setSize(this.getSize().width,t)},e.prototype.setMediaBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.MediaBox,a)},e.prototype.setCropBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.CropBox,a)},e.prototype.setBleedBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.BleedBox,a)},e.prototype.setTrimBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.TrimBox,a)},e.prototype.setArtBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.ArtBox,a)},e.prototype.getSize=function(){var t=this.getMediaBox(),r=t.width,n=t.height;return{width:r,height:n}},e.prototype.getWidth=function(){return this.getSize().width},e.prototype.getHeight=function(){return this.getSize().height},e.prototype.getMediaBox=function(){var t=this.node.MediaBox();return t.asRectangle()},e.prototype.getCropBox=function(){var t,r=this.node.CropBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getMediaBox()},e.prototype.getBleedBox=function(){var t,r=this.node.BleedBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getCropBox()},e.prototype.getTrimBox=function(){var t,r=this.node.TrimBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getCropBox()},e.prototype.getArtBox=function(){var t,r=this.node.ArtBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getCropBox()},e.prototype.translateContent=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.node.normalize(),this.getContentStream();var n=this.createContentStream(Ae(),st(t,r)),i=this.doc.context.register(n),a=this.createContentStream(De()),o=this.doc.context.register(a);this.node.wrapContentStreams(i,o)},e.prototype.scale=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.setSize(this.getWidth()*t,this.getHeight()*r),this.scaleContent(t,r),this.scaleAnnotations(t,r)},e.prototype.scaleContent=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.node.normalize(),this.getContentStream();var n=this.createContentStream(Ae(),Nn(t,r)),i=this.doc.context.register(n),a=this.createContentStream(De()),o=this.doc.context.register(a);this.node.wrapContentStreams(i,o)},e.prototype.scaleAnnotations=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]);var n=this.node.Annots();if(n)for(var i=0;i<n.size();i++){var a=n.lookup(i);a instanceof Q&&this.scaleAnnot(a,t,r)}},e.prototype.resetPosition=function(){this.getContentStream(!1),this.x=0,this.y=0},e.prototype.setFont=function(t){S(t,"font",[[$e,"PDFFont"]]),this.font=t,this.fontKey=this.node.newFontDictionary(this.font.name,this.font.ref)},e.prototype.setFontSize=function(t){S(t,"fontSize",["number"]),this.fontSize=t},e.prototype.setFontColor=function(t){S(t,"fontColor",[[Object,"Color"]]),this.fontColor=t},e.prototype.setLineHeight=function(t){S(t,"lineHeight",["number"]),this.lineHeight=t},e.prototype.getPosition=function(){return{x:this.x,y:this.y}},e.prototype.getX=function(){return this.x},e.prototype.getY=function(){return this.y},e.prototype.moveTo=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.x=t,this.y=r},e.prototype.moveDown=function(t){S(t,"yDecrease",["number"]),this.y-=t},e.prototype.moveUp=function(t){S(t,"yIncrease",["number"]),this.y+=t},e.prototype.moveLeft=function(t){S(t,"xDecrease",["number"]),this.x-=t},e.prototype.moveRight=function(t){S(t,"xIncrease",["number"]),this.x+=t},e.prototype.pushOperators=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];Lc(t,"operator",[[ie,"PDFOperator"]]);var n=this.getContentStream();n.push.apply(n,t)},e.prototype.drawText=function(t,r){var n,i,a,o,s,l,c;r===void 0&&(r={}),S(t,"text",["string"]),N(r.color,"options.color",[[Object,"Color"]]),vt(r.opacity,"opacity.opacity",0,1),N(r.font,"options.font",[[$e,"PDFFont"]]),N(r.size,"options.size",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(r.ySkew,"options.ySkew",[[Object,"Rotation"]]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.lineHeight,"options.lineHeight",["number"]),N(r.maxWidth,"options.maxWidth",["number"]),N(r.wordBreaks,"options.wordBreaks",[Array]),nt(r.blendMode,"options.blendMode",Bt);for(var u=this.setOrEmbedFont(r.font),h=u.oldFont,f=u.newFont,d=u.newFontKey,v=r.size||this.fontSize,p=r.wordBreaks||this.doc.defaultWordBreaks,m=function(A){return f.widthOfTextAtSize(A,v)},b=r.maxWidth===void 0?Xo(Qr(t)):pu(t,p,r.maxWidth,m),k=new Array(b.length),x=0,T=b.length;x<T;x++)k[x]=f.encodeText(b[x]);var w=this.maybeEmbedGraphicsState({opacity:r.opacity,blendMode:r.blendMode}),F=this.getContentStream();F.push.apply(F,s0(k,{color:(n=r.color)!==null&&n!==void 0?n:this.fontColor,font:d,size:v,rotate:(i=r.rotate)!==null&&i!==void 0?i:K(0),xSkew:(a=r.xSkew)!==null&&a!==void 0?a:K(0),ySkew:(o=r.ySkew)!==null&&o!==void 0?o:K(0),x:(s=r.x)!==null&&s!==void 0?s:this.x,y:(l=r.y)!==null&&l!==void 0?l:this.y,lineHeight:(c=r.lineHeight)!==null&&c!==void 0?c:this.lineHeight,graphicsState:w})),r.font&&(h?this.setFont(h):this.resetFont())},e.prototype.drawImage=function(t,r){var n,i,a,o,s,l,c;r===void 0&&(r={}),S(t,"image",[[oo,"PDFImage"]]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.width,"options.width",["number"]),N(r.height,"options.height",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(r.ySkew,"options.ySkew",[[Object,"Rotation"]]),vt(r.opacity,"opacity.opacity",0,1),nt(r.blendMode,"options.blendMode",Bt);var u=this.node.newXObject("Image",t.ref),h=this.maybeEmbedGraphicsState({opacity:r.opacity,blendMode:r.blendMode}),f=this.getContentStream();f.push.apply(f,Wl(u,{x:(n=r.x)!==null&&n!==void 0?n:this.x,y:(i=r.y)!==null&&i!==void 0?i:this.y,width:(a=r.width)!==null&&a!==void 0?a:t.size().width,height:(o=r.height)!==null&&o!==void 0?o:t.size().height,rotate:(s=r.rotate)!==null&&s!==void 0?s:K(0),xSkew:(l=r.xSkew)!==null&&l!==void 0?l:K(0),ySkew:(c=r.ySkew)!==null&&c!==void 0?c:K(0),graphicsState:h}))},e.prototype.drawPage=function(t,r){var n,i,a,o,s;r===void 0&&(r={}),S(t,"embeddedPage",[[Jl,"PDFEmbeddedPage"]]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.xScale,"options.xScale",["number"]),N(r.yScale,"options.yScale",["number"]),N(r.width,"options.width",["number"]),N(r.height,"options.height",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(r.ySkew,"options.ySkew",[[Object,"Rotation"]]),vt(r.opacity,"opacity.opacity",0,1),nt(r.blendMode,"options.blendMode",Bt);var l=this.node.newXObject("EmbeddedPdfPage",t.ref),c=this.maybeEmbedGraphicsState({opacity:r.opacity,blendMode:r.blendMode}),u=r.width!==void 0?r.width/t.width:r.xScale!==void 0?r.xScale:1,h=r.height!==void 0?r.height/t.height:r.yScale!==void 0?r.yScale:1,f=this.getContentStream();f.push.apply(f,c0(l,{x:(n=r.x)!==null&&n!==void 0?n:this.x,y:(i=r.y)!==null&&i!==void 0?i:this.y,xScale:u,yScale:h,rotate:(a=r.rotate)!==null&&a!==void 0?a:K(0),xSkew:(o=r.xSkew)!==null&&o!==void 0?o:K(0),ySkew:(s=r.ySkew)!==null&&s!==void 0?s:K(0),graphicsState:c}))},e.prototype.drawSvgPath=function(t,r){var n,i,a,o,s,l,c,u,h;r===void 0&&(r={}),S(t,"path",["string"]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.scale,"options.scale",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.borderWidth,"options.borderWidth",["number"]),N(r.color,"options.color",[[Object,"Color"]]),vt(r.opacity,"opacity.opacity",0,1),N(r.borderColor,"options.borderColor",[[Object,"Color"]]),N(r.borderDashArray,"options.borderDashArray",[Array]),N(r.borderDashPhase,"options.borderDashPhase",["number"]),nt(r.borderLineCap,"options.borderLineCap",vr),vt(r.borderOpacity,"options.borderOpacity",0,1),nt(r.blendMode,"options.blendMode",Bt);var f=this.maybeEmbedGraphicsState({opacity:r.opacity,borderOpacity:r.borderOpacity,blendMode:r.blendMode});!("color"in r)&&!("borderColor"in r)&&(r.borderColor=de(0,0,0));var d=this.getContentStream();d.push.apply(d,h0(t,{x:(n=r.x)!==null&&n!==void 0?n:this.x,y:(i=r.y)!==null&&i!==void 0?i:this.y,scale:r.scale,rotate:(a=r.rotate)!==null&&a!==void 0?a:K(0),color:(o=r.color)!==null&&o!==void 0?o:void 0,borderColor:(s=r.borderColor)!==null&&s!==void 0?s:void 0,borderWidth:(l=r.borderWidth)!==null&&l!==void 0?l:0,borderDashArray:(c=r.borderDashArray)!==null&&c!==void 0?c:void 0,borderDashPhase:(u=r.borderDashPhase)!==null&&u!==void 0?u:void 0,borderLineCap:(h=r.borderLineCap)!==null&&h!==void 0?h:void 0,graphicsState:f}))},e.prototype.drawLine=function(t){var r,n,i,a,o;S(t.start,"options.start",[[Object,"{ x: number, y: number }"]]),S(t.end,"options.end",[[Object,"{ x: number, y: number }"]]),S(t.start.x,"options.start.x",["number"]),S(t.start.y,"options.start.y",["number"]),S(t.end.x,"options.end.x",["number"]),S(t.end.y,"options.end.y",["number"]),N(t.thickness,"options.thickness",["number"]),N(t.color,"options.color",[[Object,"Color"]]),N(t.dashArray,"options.dashArray",[Array]),N(t.dashPhase,"options.dashPhase",["number"]),nt(t.lineCap,"options.lineCap",vr),vt(t.opacity,"opacity.opacity",0,1),nt(t.blendMode,"options.blendMode",Bt);var s=this.maybeEmbedGraphicsState({borderOpacity:t.opacity,blendMode:t.blendMode});"color"in t||(t.color=de(0,0,0));var l=this.getContentStream();l.push.apply(l,l0({start:t.start,end:t.end,thickness:(r=t.thickness)!==null&&r!==void 0?r:1,color:(n=t.color)!==null&&n!==void 0?n:void 0,dashArray:(i=t.dashArray)!==null&&i!==void 0?i:void 0,dashPhase:(a=t.dashPhase)!==null&&a!==void 0?a:void 0,lineCap:(o=t.lineCap)!==null&&o!==void 0?o:void 0,graphicsState:s}))},e.prototype.drawRectangle=function(t){var r,n,i,a,o,s,l,c,u,h,f,d,v;t===void 0&&(t={}),N(t.x,"options.x",["number"]),N(t.y,"options.y",["number"]),N(t.width,"options.width",["number"]),N(t.height,"options.height",["number"]),N(t.rotate,"options.rotate",[[Object,"Rotation"]]),N(t.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(t.ySkew,"options.ySkew",[[Object,"Rotation"]]),N(t.borderWidth,"options.borderWidth",["number"]),N(t.color,"options.color",[[Object,"Color"]]),vt(t.opacity,"opacity.opacity",0,1),N(t.borderColor,"options.borderColor",[[Object,"Color"]]),N(t.borderDashArray,"options.borderDashArray",[Array]),N(t.borderDashPhase,"options.borderDashPhase",["number"]),nt(t.borderLineCap,"options.borderLineCap",vr),vt(t.borderOpacity,"options.borderOpacity",0,1),nt(t.blendMode,"options.blendMode",Bt);var p=this.maybeEmbedGraphicsState({opacity:t.opacity,borderOpacity:t.borderOpacity,blendMode:t.blendMode});!("color"in t)&&!("borderColor"in t)&&(t.color=de(0,0,0));var m=this.getContentStream();m.push.apply(m,zr({x:(r=t.x)!==null&&r!==void 0?r:this.x,y:(n=t.y)!==null&&n!==void 0?n:this.y,width:(i=t.width)!==null&&i!==void 0?i:150,height:(a=t.height)!==null&&a!==void 0?a:100,rotate:(o=t.rotate)!==null&&o!==void 0?o:K(0),xSkew:(s=t.xSkew)!==null&&s!==void 0?s:K(0),ySkew:(l=t.ySkew)!==null&&l!==void 0?l:K(0),borderWidth:(c=t.borderWidth)!==null&&c!==void 0?c:0,color:(u=t.color)!==null&&u!==void 0?u:void 0,borderColor:(h=t.borderColor)!==null&&h!==void 0?h:void 0,borderDashArray:(f=t.borderDashArray)!==null&&f!==void 0?f:void 0,borderDashPhase:(d=t.borderDashPhase)!==null&&d!==void 0?d:void 0,graphicsState:p,borderLineCap:(v=t.borderLineCap)!==null&&v!==void 0?v:void 0}))},e.prototype.drawSquare=function(t){t===void 0&&(t={});var r=t.size;N(r,"size",["number"]),this.drawRectangle(Y(Y({},t),{width:r,height:r}))},e.prototype.drawEllipse=function(t){var r,n,i,a,o,s,l,c,u,h,f;t===void 0&&(t={}),N(t.x,"options.x",["number"]),N(t.y,"options.y",["number"]),N(t.xScale,"options.xScale",["number"]),N(t.yScale,"options.yScale",["number"]),N(t.rotate,"options.rotate",[[Object,"Rotation"]]),N(t.color,"options.color",[[Object,"Color"]]),vt(t.opacity,"opacity.opacity",0,1),N(t.borderColor,"options.borderColor",[[Object,"Color"]]),vt(t.borderOpacity,"options.borderOpacity",0,1),N(t.borderWidth,"options.borderWidth",["number"]),N(t.borderDashArray,"options.borderDashArray",[Array]),N(t.borderDashPhase,"options.borderDashPhase",["number"]),nt(t.borderLineCap,"options.borderLineCap",vr),nt(t.blendMode,"options.blendMode",Bt);var d=this.maybeEmbedGraphicsState({opacity:t.opacity,borderOpacity:t.borderOpacity,blendMode:t.blendMode});!("color"in t)&&!("borderColor"in t)&&(t.color=de(0,0,0));var v=this.getContentStream();v.push.apply(v,io({x:(r=t.x)!==null&&r!==void 0?r:this.x,y:(n=t.y)!==null&&n!==void 0?n:this.y,xScale:(i=t.xScale)!==null&&i!==void 0?i:100,yScale:(a=t.yScale)!==null&&a!==void 0?a:100,rotate:(o=t.rotate)!==null&&o!==void 0?o:void 0,color:(s=t.color)!==null&&s!==void 0?s:void 0,borderColor:(l=t.borderColor)!==null&&l!==void 0?l:void 0,borderWidth:(c=t.borderWidth)!==null&&c!==void 0?c:0,borderDashArray:(u=t.borderDashArray)!==null&&u!==void 0?u:void 0,borderDashPhase:(h=t.borderDashPhase)!==null&&h!==void 0?h:void 0,borderLineCap:(f=t.borderLineCap)!==null&&f!==void 0?f:void 0,graphicsState:d}))},e.prototype.drawCircle=function(t){t===void 0&&(t={});var r=t.size,n=r===void 0?100:r;N(n,"size",["number"]),this.drawEllipse(Y(Y({},t),{xScale:n,yScale:n}))},e.prototype.setOrEmbedFont=function(t){var r=this.font,n=this.fontKey;t?this.setFont(t):this.getFont();var i=this.font,a=this.fontKey;return{oldFont:r,oldFontKey:n,newFont:i,newFontKey:a}},e.prototype.getFont=function(){if(!this.font||!this.fontKey){var t=this.doc.embedStandardFont(Vr.Helvetica);this.setFont(t)}return[this.font,this.fontKey]},e.prototype.resetFont=function(){this.font=void 0,this.fontKey=void 0},e.prototype.getContentStream=function(t){return t===void 0&&(t=!0),t&&this.contentStream?this.contentStream:(this.contentStream=this.createContentStream(),this.contentStreamRef=this.doc.context.register(this.contentStream),this.node.addContentStream(this.contentStreamRef),this.contentStream)},e.prototype.createContentStream=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=this.doc.context.obj({}),i=Fn.of(n,t);return i},e.prototype.maybeEmbedGraphicsState=function(t){var r=t.opacity,n=t.borderOpacity,i=t.blendMode;if(!(r===void 0&&n===void 0&&i===void 0)){var a=this.doc.context.obj({Type:"ExtGState",ca:r,CA:n,BM:i}),o=this.node.newExtGState("GS",a);return o}},e.prototype.scaleAnnot=function(t,r,n){for(var i=["RD","CL","Vertices","QuadPoints","L","Rect"],a=0,o=i.length;a<o;a++){var s=t.lookup(g.of(i[a]));s instanceof fe&&s.scalePDFNumbers(r,n)}var l=t.lookup(g.of("InkList"));if(l instanceof fe)for(var a=0,o=l.size();a<o;a++){var c=l.lookup(a);c instanceof fe&&c.scalePDFNumbers(r,n)}},e.of=function(t,r,n){return new e(t,r,n)},e.create=function(t){S(t,"doc",[[_t,"PDFDocument"]]);var r=ve.of(-1),n=It.withContextAndParent(t.context,r),i=t.context.register(n);return new e(n,i,t)},e}(),Zi=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroButton",[[Ci,"PDFAcroPushButton"]]),a.acroField=r,a}return t.prototype.setImage=function(r,n){n===void 0&&(n=Qt.Center);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a],l=this.createImageAppearanceStream(s,r,n);this.updateWidgetAppearances(s,{normal:l})}this.markAsClean()},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.addToPage=function(r,n,i){var a,o,s,l,c,u,h,f,d,v,p;N(r,"text",["string"]),N(n,"page",[[ut,"PDFPage"]]),Lr(i);var m=this.createWidget({x:((a=i==null?void 0:i.x)!==null&&a!==void 0?a:0)-((o=i==null?void 0:i.borderWidth)!==null&&o!==void 0?o:0)/2,y:((s=i==null?void 0:i.y)!==null&&s!==void 0?s:0)-((l=i==null?void 0:i.borderWidth)!==null&&l!==void 0?l:0)/2,width:(c=i==null?void 0:i.width)!==null&&c!==void 0?c:100,height:(u=i==null?void 0:i.height)!==null&&u!==void 0?u:50,textColor:(h=i==null?void 0:i.textColor)!==null&&h!==void 0?h:de(0,0,0),backgroundColor:(f=i==null?void 0:i.backgroundColor)!==null&&f!==void 0?f:de(.75,.75,.75),borderColor:i==null?void 0:i.borderColor,borderWidth:(d=i==null?void 0:i.borderWidth)!==null&&d!==void 0?d:0,rotate:(v=i==null?void 0:i.rotate)!==null&&v!==void 0?v:K(0),caption:r,hidden:i==null?void 0:i.hidden,page:n.ref}),b=this.doc.context.register(m.dict);this.acroField.addWidget(b);var k=(p=i==null?void 0:i.font)!==null&&p!==void 0?p:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(m,k),n.node.addAnnot(b)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??I0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br);const q0=({fileUrl:e,fileName:t})=>{const[r,n]=te.useState(null),[i,a]=te.useState(0),[o,s]=te.useState(1),[l,c]=te.useState(1),[u,h]=te.useState("SELECT"),[f,d]=te.useState(vo),[v,p]=te.useState(go),[m,b]=te.useState(po),[k,x]=te.useState(!1),[T,w]=te.useState(null),[F,A]=te.useState(null),[D,O]=te.useState(null),[B,E]=te.useState(null),[j,I]=te.useState("APPROVED"),{annotations:L,addAnnotation:z,deleteAnnotation:P,updateAnnotation:U,clearAnnotations:ue,undo:me,redo:We,canUndo:Oe,canRedo:Re}=Go(),kt=te.useRef(null),Ze=te.useRef([]);te.useEffect(()=>{(async()=>{try{const qe=await pdfjsLib.getDocument(e).promise;n(qe),a(qe.numPages),Ze.current=Array(qe.numPages).fill(null),s(1),ue()}catch(re){console.error("Error loading PDF:",re),alert("Failed to load PDF file.")}})()},[e,ue]);const Gr=be=>{var re;be>0&&be<=i&&(s(be),(re=Ze.current[be-1])==null||re.scrollIntoView({behavior:"smooth",block:"start"}))},er=te.useCallback(()=>{if(T)for(const be in L){const re=parseInt(be,10);if(L[re].some(qe=>qe.id===T)){P(re,T),w(null);break}}},[T,L,P]);te.useEffect(()=>{const be=re=>{(re.key==="Delete"||re.key==="Backspace")&&T&&(re.preventDefault(),er()),(re.ctrlKey||re.metaKey)&&re.key==="z"&&(re.preventDefault(),me()),(re.ctrlKey||re.metaKey)&&re.key==="y"&&(re.preventDefault(),We())};return window.addEventListener("keydown",be),()=>window.removeEventListener("keydown",be)},[T,er,me,We]);const mr=te.useCallback(async()=>{if(!r)return null;const be=await fetch(e).then(Xr=>Xr.arrayBuffer()),re=await _t.load(be),qe=await re.embedFont(Vr.Helvetica),Kr=await re.embedFont(Vr.HelveticaBold),je=re.getPages(),Hr={};for(const Xr in L){const xr=parseInt(Xr,10);if(xr<1||xr>je.length)continue;const G0=L[xr],Ct=je[xr-1],{width:K0,height:Ql}=Ct.getSize(),_l=(await r.getPage(xr)).getViewport({scale:1}),Ge=K0/_l.width,wr=Ql/_l.height;for(const q of G0){const tr=de(parseInt(q.color.slice(1,3),16)/255,parseInt(q.color.slice(3,5),16)/255,parseInt(q.color.slice(5,7),16)/255),gt=uo=>Ql-uo*wr;switch(q.type){case"PEN":case"UNDERLINE":case"STRIKETHROUGH":if(q.points.length>1){const Zr=q.points.map((Tt,rr)=>`${rr===0?"M":"L"} ${Tt.x*Ge} ${gt(Tt.y)}`).join(" ");Ct.drawSvgPath(Zr,{borderColor:tr,borderWidth:q.strokeWidth})}break;case"SQUIGGLY":if(q.points.length>1){let Zr=`M ${q.points[0].x*Ge} ${gt(q.points[0].y)}`;for(let Tt=1;Tt<q.points.length;Tt++){const rr=q.points[Tt];Zr+=` Q ${(rr.x-2.5)*Ge} ${gt(rr.y+(Tt%2===0?-1:1)*2)}, ${rr.x*Ge} ${gt(rr.y)}`}Ct.drawSvgPath(Zr,{borderColor:tr,borderWidth:q.strokeWidth})}break;case"HIGHLIGHTER":if(q.points.length>1){const Zr=q.points.map((Tt,rr)=>`${rr===0?"M":"L"} ${Tt.x*Ge} ${gt(Tt.y)}`).join(" ");Ct.drawSvgPath(Zr,{borderColor:tr,borderWidth:q.strokeWidth*5,opacity:.3,borderLineCap:vr.Round})}break;case"RECTANGLE":Ct.drawRectangle({x:q.x*Ge,y:gt(q.y+q.height),width:q.width*Ge,height:q.height*wr,borderColor:tr,borderWidth:q.strokeWidth});break;case"CIRCLE":Ct.drawEllipse({x:q.cx*Ge,y:gt(q.cy),xScale:q.rx*Ge,yScale:q.ry*wr,borderColor:tr,borderWidth:q.strokeWidth});break;case"TEXT":Ct.drawText(q.content,{x:q.x*Ge,y:gt(q.y+q.fontSize),size:q.fontSize*wr,font:qe,color:tr});break;case"STAMP":Ct.drawRectangle({x:q.x*Ge,y:gt(q.y+q.height),width:q.width*Ge,height:q.height*wr,borderColor:tr,borderWidth:2,borderOpacity:.8}),Ct.drawText(q.text,{x:(q.x+q.width/2)*Ge,y:gt(q.y+q.height/2+q.fontSize/3),font:Kr,size:q.fontSize*wr,color:tr,opacity:.8});break;case"SIGNATURE":case"INITIALS":Hr[q.imageData]||(Hr[q.imageData]=await re.embedPng(q.imageData));const uo=Hr[q.imageData];Ct.drawImage(uo,{x:q.x*Ge,y:gt(q.y+q.height),width:q.width*Ge,height:q.height*wr});break}}}return await re.save()},[r,e,L]),xe=te.useCallback(async be=>{x(!0);try{const re=await mr();if(!re){x(!1);return}const qe=new Blob([re],{type:"application/pdf"}),Kr=URL.createObjectURL(qe);if(be==="download"){const je=document.createElement("a");je.href=Kr,je.download=`${t.replace(".pdf","")}-annotated.pdf`,document.body.appendChild(je),je.click(),document.body.removeChild(je),URL.revokeObjectURL(Kr)}else{const je=document.createElement("iframe");je.style.display="none",je.src=Kr,document.body.appendChild(je),je.onload=()=>{setTimeout(()=>{var Hr,Xr;try{(Hr=je.contentWindow)==null||Hr.focus(),(Xr=je.contentWindow)==null||Xr.print()}catch(xr){console.error("Printing failed:",xr),alert("Could not print the document. Your browser might be blocking it.")}setTimeout(()=>{document.body.contains(je)&&(document.body.removeChild(je),URL.revokeObjectURL(Kr))},1e3)},1)}}}catch(re){console.error(`Failed to ${be} annotated PDF:`,re),alert(`An error occurred while preparing the PDF for ${be}.`)}finally{x(!1)}},[mr,t]),lo=()=>{if(!r)return null;const be=[];for(let re=1;re<=i;re++)be.push(C.jsx("div",{ref:qe=>Ze.current[re-1]=qe,"data-page-number":re,children:C.jsx(Wo,{pdf:r,pageNumber:re,zoom:l,activeTool:u,toolColor:f,strokeWidth:v,fontSize:m,annotations:L[re]||[],addAnnotation:qe=>z(re,qe),deleteAnnotation:qe=>P(re,qe),updateAnnotation:U,selectedAnnotationId:T,setSelectedAnnotationId:w,signatureData:F,initialsData:D,activeStamp:j})},re));return be};return C.jsxs("div",{className:"flex flex-col h-screen w-full",children:[B&&C.jsx(qo,{title:B==="SIGNATURE"?"Create Signature":"Create Initials",onClose:()=>E(null),onSave:be=>{B==="SIGNATURE"?A(be):O(be)}}),C.jsx(zo,{fileName:t,currentPage:o,totalPages:i,zoom:l,setZoom:c,setCurrentPage:Gr,activeTool:u,setActiveTool:h,toolColor:f,setToolColor:d,strokeWidth:v,setStrokeWidth:p,fontSize:m,setFontSize:b,onDownload:()=>xe("download"),onPrint:()=>xe("print"),isProcessing:k,onDelete:er,selectedAnnotationId:T,undo:me,redo:We,canUndo:Oe,canRedo:Re,onSignatureClick:()=>E("SIGNATURE"),onInitialsClick:()=>E("INITIALS"),activeStamp:j,setActiveStamp:I}),C.jsx("div",{ref:kt,className:"flex-grow overflow-auto bg-gray-800 p-4",children:C.jsx("div",{id:"pdf-print-area",className:"mx-auto",children:r?lo():C.jsx("div",{className:"flex items-center justify-center h-full",children:C.jsx("p",{className:"text-xl",children:"Loading PDF..."})})})})]})};ne.AnnotationLayer=Uo,ne.CircleIcon=Fo,ne.DEFAULT_COLOR=vo,ne.DEFAULT_FONT_SIZE=po,ne.DEFAULT_STROKE_WIDTH=go,ne.DownloadIcon=Ao,ne.EraserIcon=ko,ne.FONT_SIZES=fo,ne.FreeTextIcon=wo,ne.HighlighterIcon=xo,ne.InitialsIcon=Bo,ne.PdfPage=Wo,ne.PdfViewer=q0,ne.PenIcon=mo,ne.PrintIcon=Do,ne.RectangleIcon=So,ne.RedoIcon=jo,ne.STAMPS=yo,ne.STROKE_WIDTHS=ho,ne.SelectIcon=bo,ne.SignatureIcon=No,ne.SignatureModal=qo,ne.SquigglyIcon=Ro,ne.StampIcon=Io,ne.StrikeoutIcon=Oo,ne.Toolbar=zo,ne.TrashIcon=Co,ne.UnderlineIcon=Eo,ne.UndoIcon=Mo,ne.UploadIcon=$l,ne.ZoomInIcon=To,ne.ZoomOutIcon=Po,ne.useAnnotationHistory=Go,Object.defineProperty(ne,Symbol.toStringTag,{value:"Module"})});
51
+ `+gr(n).toString();this.acroField.setDefaultAppearance(T)}return p},e.prototype.updateWidgetAppearanceWithFont=function(t,r,n){var i=n.normal,a=n.rollover,o=n.down;this.updateWidgetAppearances(t,{normal:this.createAppearanceStream(t,i,r),rollover:a&&this.createAppearanceStream(t,a,r),down:o&&this.createAppearanceStream(t,o,r)})},e.prototype.updateOnOffWidgetAppearance=function(t,r,n){var i=n.normal,a=n.rollover,o=n.down;this.updateWidgetAppearances(t,{normal:this.createAppearanceDict(t,i,r),rollover:a&&this.createAppearanceDict(t,a,r),down:o&&this.createAppearanceDict(t,o,r)})},e.prototype.updateWidgetAppearances=function(t,r){var n=r.normal,i=r.rollover,a=r.down;t.setNormalAppearance(n),i?t.setRolloverAppearance(i):t.removeRolloverAppearance(),a?t.setDownAppearance(a):t.removeDownAppearance()},e.prototype.createAppearanceStream=function(t,r,n){var i,a=this.acroField.dict.context,o=t.getRectangle(),s=o.width,l=o.height,c=n&&{Font:(i={},i[n.name]=n.ref,i)},u=a.formXObject(r,{Resources:c,BBox:a.obj([0,0,s,l]),Matrix:a.obj([1,0,0,1,0,0])}),h=a.register(u);return h},e.prototype.createImageAppearanceStream=function(t,r,n){var i,a,o=this.acroField.dict.context,s=t.getRectangle(),l=t.getAppearanceCharacteristics(),c=t.getBorderStyle(),u=(a=c==null?void 0:c.getWidth())!==null&&a!==void 0?a:0,h=Nt(l==null?void 0:l.getRotation()),f=Yt(Y(Y({},s),{rotation:h})),d=dr(s,h),v=r.scaleToFit(d.width-u*2,d.height-u*2),p={x:u,y:u,width:v.width,height:v.height,rotate:K(0),xSkew:K(0),ySkew:K(0)};n===Qt.Center?(p.x+=(d.width-u*2)/2-v.width/2,p.y+=(d.height-u*2)/2-v.height/2):n===Qt.Right&&(p.x=d.width-u-v.width,p.y=d.height-u-v.height);var m=this.doc.context.addRandomSuffix("Image",10),b=se(f,Wl(m,p)),k={XObject:(i={},i[m]=r.ref,i)},x=o.formXObject(b,{Resources:k,BBox:o.obj([0,0,s.width,s.height]),Matrix:o.obj([1,0,0,1,0,0])});return o.register(x)},e.prototype.createAppearanceDict=function(t,r,n){var i=this.acroField.dict.context,a=this.createAppearanceStream(t,r.on),o=this.createAppearanceStream(t,r.off),s=i.obj({});return s.set(n,a),s.set(g.of("Off"),o),s},e}(),Ln=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroCheckBox",[[wi,"PDFAcroCheckBox"]]),a.acroField=r,a}return t.prototype.check=function(){var r,n=(r=this.acroField.getOnValue())!==null&&r!==void 0?r:g.of("Yes");this.markAsDirty(),this.acroField.setValue(n)},t.prototype.uncheck=function(){this.markAsDirty(),this.acroField.setValue(g.of("Off"))},t.prototype.isChecked=function(){var r=this.acroField.getOnValue();return!!r&&r===this.acroField.getValue()},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var u=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:50,height:(s=n.height)!==null&&s!==void 0?s:50,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),h=this.doc.context.register(u.dict);this.acroField.addWidget(h),u.setAppearanceState(g.of("Off")),this.updateWidgetAppearance(u,g.of("Yes")),r.node.addAnnot(h)},t.prototype.needsAppearancesUpdate=function(){for(var r,n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=o.getAppearanceState(),l=(r=o.getAppearances())===null||r===void 0?void 0:r.normal;if(!(l instanceof Q)||s&&!l.has(s))return!0}return!1},t.prototype.defaultUpdateAppearances=function(){this.updateAppearances()},t.prototype.updateAppearances=function(r){var n;N(r,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a],l=(n=s.getOnValue())!==null&&n!==void 0?n:g.of("Yes");l&&this.updateWidgetAppearance(s,l,r)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??O0,o=Ur(a(this,r));this.updateOnOffWidgetAppearance(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Ki=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroComboBox",[[Si,"PDFAcroComboBox"]]),a.acroField=r,a}return t.prototype.getOptions=function(){for(var r=this.acroField.getOptions(),n=new Array(r.length),i=0,a=n.length;i<a;i++){var o=r[i],s=o.display,l=o.value;n[i]=(s??l).decodeText()}return n},t.prototype.getSelected=function(){for(var r=this.acroField.getValues(),n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=r[i].decodeText();return n},t.prototype.setOptions=function(r){S(r,"options",[Array]);for(var n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]={value:G.fromText(r[i])};this.acroField.setOptions(n)},t.prototype.addOptions=function(r){S(r,"options",["string",Array]);for(var n=Array.isArray(r)?r:[r],i=this.acroField.getOptions(),a=new Array(n.length),o=0,s=n.length;o<s;o++)a[o]={value:G.fromText(n[o])};this.acroField.setOptions(i.concat(a))},t.prototype.select=function(r,n){n===void 0&&(n=!1),S(r,"options",["string",Array]),S(n,"merge",["boolean"]);var i=Array.isArray(r)?r:[r],a=this.getOptions(),o=i.find(function(h){return!a.includes(h)});o&&this.enableEditing(),this.markAsDirty(),(i.length>1||i.length===1&&n)&&this.enableMultiselect();for(var s=new Array(i.length),l=0,c=i.length;l<c;l++)s[l]=G.fromText(i[l]);if(n){var u=this.acroField.getValues();this.acroField.setValues(u.concat(s))}else this.acroField.setValues(s)},t.prototype.clear=function(){this.markAsDirty(),this.acroField.setValues([])},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.isEditable=function(){return this.acroField.hasFlag(ge.Edit)},t.prototype.enableEditing=function(){this.acroField.setFlagTo(ge.Edit,!0)},t.prototype.disableEditing=function(){this.acroField.setFlagTo(ge.Edit,!1)},t.prototype.isSorted=function(){return this.acroField.hasFlag(ge.Sort)},t.prototype.enableSorting=function(){this.acroField.setFlagTo(ge.Sort,!0)},t.prototype.disableSorting=function(){this.acroField.setFlagTo(ge.Sort,!1)},t.prototype.isMultiselect=function(){return this.acroField.hasFlag(ge.MultiSelect)},t.prototype.enableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!0)},t.prototype.disableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!1)},t.prototype.isSpellChecked=function(){return!this.acroField.hasFlag(ge.DoNotSpellCheck)},t.prototype.enableSpellChecking=function(){this.acroField.setFlagTo(ge.DoNotSpellCheck,!1)},t.prototype.disableSpellChecking=function(){this.acroField.setFlagTo(ge.DoNotSpellCheck,!0)},t.prototype.isSelectOnClick=function(){return this.acroField.hasFlag(ge.CommitOnSelChange)},t.prototype.enableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!0)},t.prototype.disableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!1)},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c,u;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var h=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:200,height:(s=n.height)!==null&&s!==void 0?s:50,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),f=this.doc.context.register(h.dict);this.acroField.addWidget(f);var d=(u=n.font)!==null&&u!==void 0?u:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(h,d),r.node.addAnnot(f)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??B0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Hi=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroListBox",[[Pi,"PDFAcroListBox"]]),a.acroField=r,a}return t.prototype.getOptions=function(){for(var r=this.acroField.getOptions(),n=new Array(r.length),i=0,a=n.length;i<a;i++){var o=r[i],s=o.display,l=o.value;n[i]=(s??l).decodeText()}return n},t.prototype.getSelected=function(){for(var r=this.acroField.getValues(),n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=r[i].decodeText();return n},t.prototype.setOptions=function(r){S(r,"options",[Array]),this.markAsDirty();for(var n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]={value:G.fromText(r[i])};this.acroField.setOptions(n)},t.prototype.addOptions=function(r){S(r,"options",["string",Array]),this.markAsDirty();for(var n=Array.isArray(r)?r:[r],i=this.acroField.getOptions(),a=new Array(n.length),o=0,s=n.length;o<s;o++)a[o]={value:G.fromText(n[o])};this.acroField.setOptions(i.concat(a))},t.prototype.select=function(r,n){n===void 0&&(n=!1),S(r,"options",["string",Array]),S(n,"merge",["boolean"]);var i=Array.isArray(r)?r:[r],a=this.getOptions();Nh(i,"option",a),this.markAsDirty(),(i.length>1||i.length===1&&n)&&this.enableMultiselect();for(var o=new Array(i.length),s=0,l=i.length;s<l;s++)o[s]=G.fromText(i[s]);if(n){var c=this.acroField.getValues();this.acroField.setValues(c.concat(o))}else this.acroField.setValues(o)},t.prototype.clear=function(){this.markAsDirty(),this.acroField.setValues([])},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.isSorted=function(){return this.acroField.hasFlag(ge.Sort)},t.prototype.enableSorting=function(){this.acroField.setFlagTo(ge.Sort,!0)},t.prototype.disableSorting=function(){this.acroField.setFlagTo(ge.Sort,!1)},t.prototype.isMultiselect=function(){return this.acroField.hasFlag(ge.MultiSelect)},t.prototype.enableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!0)},t.prototype.disableMultiselect=function(){this.acroField.setFlagTo(ge.MultiSelect,!1)},t.prototype.isSelectOnClick=function(){return this.acroField.hasFlag(ge.CommitOnSelChange)},t.prototype.enableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!0)},t.prototype.disableSelectOnClick=function(){this.acroField.setFlagTo(ge.CommitOnSelChange,!1)},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c,u;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var h=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:200,height:(s=n.height)!==null&&s!==void 0?s:100,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),f=this.doc.context.register(h.dict);this.acroField.addWidget(f);var d=(u=n.font)!==null&&u!==void 0?u:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(h,d),r.node.addAnnot(f)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??M0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Vn=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroRadioButton",[[Ti,"PDFAcroRadioButton"]]),a.acroField=r,a}return t.prototype.getOptions=function(){var r=this.acroField.getExportValues();if(r){for(var n=new Array(r.length),i=0,a=r.length;i<a;i++)n[i]=r[i].decodeText();return n}for(var o=this.acroField.getOnValues(),s=new Array(o.length),i=0,a=s.length;i<a;i++)s[i]=o[i].decodeText();return s},t.prototype.getSelected=function(){var r=this.acroField.getValue();if(r!==g.of("Off")){var n=this.acroField.getExportValues();if(n){for(var i=this.acroField.getOnValues(),a=0,o=i.length;a<o;a++)if(i[a]===r)return n[a].decodeText()}return r.decodeText()}},t.prototype.select=function(r){S(r,"option",["string"]);var n=this.getOptions();Gt(r,"option",n),this.markAsDirty();var i=this.acroField.getOnValues(),a=this.acroField.getExportValues();if(a)for(var o=0,s=a.length;o<s;o++)a[o].decodeText()===r&&this.acroField.setValue(i[o]);else for(var o=0,s=i.length;o<s;o++){var l=i[o];l.decodeText()===r&&this.acroField.setValue(l)}},t.prototype.clear=function(){this.markAsDirty(),this.acroField.setValue(g.of("Off"))},t.prototype.isOffToggleable=function(){return!this.acroField.hasFlag(ot.NoToggleToOff)},t.prototype.enableOffToggling=function(){this.acroField.setFlagTo(ot.NoToggleToOff,!1)},t.prototype.disableOffToggling=function(){this.acroField.setFlagTo(ot.NoToggleToOff,!0)},t.prototype.isMutuallyExclusive=function(){return!this.acroField.hasFlag(ot.RadiosInUnison)},t.prototype.enableMutualExclusion=function(){this.acroField.setFlagTo(ot.RadiosInUnison,!1)},t.prototype.disableMutualExclusion=function(){this.acroField.setFlagTo(ot.RadiosInUnison,!0)},t.prototype.addOptionToPage=function(r,n,i){var a,o,s,l,c,u,h,f,d;S(r,"option",["string"]),S(n,"page",[[ut,"PDFPage"]]),Lr(i);var v=this.createWidget({x:(a=i==null?void 0:i.x)!==null&&a!==void 0?a:0,y:(o=i==null?void 0:i.y)!==null&&o!==void 0?o:0,width:(s=i==null?void 0:i.width)!==null&&s!==void 0?s:50,height:(l=i==null?void 0:i.height)!==null&&l!==void 0?l:50,textColor:(c=i==null?void 0:i.textColor)!==null&&c!==void 0?c:de(0,0,0),backgroundColor:(u=i==null?void 0:i.backgroundColor)!==null&&u!==void 0?u:de(1,1,1),borderColor:(h=i==null?void 0:i.borderColor)!==null&&h!==void 0?h:de(0,0,0),borderWidth:(f=i==null?void 0:i.borderWidth)!==null&&f!==void 0?f:1,rotate:(d=i==null?void 0:i.rotate)!==null&&d!==void 0?d:K(0),hidden:i==null?void 0:i.hidden,page:n.ref}),p=this.doc.context.register(v.dict),m=this.acroField.addWidgetWithOpt(p,G.fromText(r),!this.isMutuallyExclusive());v.setAppearanceState(g.of("Off")),this.updateWidgetAppearance(v,m),n.node.addAnnot(p)},t.prototype.needsAppearancesUpdate=function(){for(var r,n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=o.getAppearanceState(),l=(r=o.getAppearances())===null||r===void 0?void 0:r.normal;if(!(l instanceof Q)||s&&!l.has(s))return!0}return!1},t.prototype.defaultUpdateAppearances=function(){this.updateAppearances()},t.prototype.updateAppearances=function(r){N(r,"provider",[Function]);for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=o.getOnValue();s&&this.updateWidgetAppearance(o,s,r)}},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??R0,o=Ur(a(this,r));this.updateOnOffWidgetAppearance(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),so=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroSignature",[[Ka,"PDFAcroSignature"]]),a.acroField=r,a}return t.prototype.needsAppearancesUpdate=function(){return!1},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Xi=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroText",[[ki,"PDFAcroText"]]),a.acroField=r,a}return t.prototype.getText=function(){var r=this.acroField.getValue();if(!r&&this.isRichFormatted())throw new w0(this.getName());return r==null?void 0:r.decodeText()},t.prototype.setText=function(r){N(r,"text",["string"]);var n=this.getMaxLength();if(n!==void 0&&r&&r.length>n)throw new F0(r.length,n,this.getName());this.markAsDirty(),this.disableRichFormatting(),r?this.acroField.setValue(G.fromText(r)):this.acroField.removeValue()},t.prototype.getAlignment=function(){var r=this.acroField.getQuadding();return r===0?Ee.Left:r===1?Ee.Center:r===2?Ee.Right:Ee.Left},t.prototype.setAlignment=function(r){Gt(r,"alignment",Ee),this.markAsDirty(),this.acroField.setQuadding(r)},t.prototype.getMaxLength=function(){return this.acroField.getMaxLength()},t.prototype.setMaxLength=function(r){if(vt(r,"maxLength",0,Number.MAX_SAFE_INTEGER),this.markAsDirty(),r===void 0)this.acroField.removeMaxLength();else{var n=this.getText();if(n&&n.length>r)throw new k0(n.length,r,this.getName());this.acroField.setMaxLength(r)}},t.prototype.removeMaxLength=function(){this.markAsDirty(),this.acroField.removeMaxLength()},t.prototype.setImage=function(r){for(var n=this.getAlignment(),i=n===Ee.Center?Qt.Center:n===Ee.Right?Qt.Right:Qt.Left,a=this.acroField.getWidgets(),o=0,s=a.length;o<s;o++){var l=a[o],c=this.createImageAppearanceStream(l,r,i);this.updateWidgetAppearances(l,{normal:c})}this.markAsClean()},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.isMultiline=function(){return this.acroField.hasFlag(Se.Multiline)},t.prototype.enableMultiline=function(){this.markAsDirty(),this.acroField.setFlagTo(Se.Multiline,!0)},t.prototype.disableMultiline=function(){this.markAsDirty(),this.acroField.setFlagTo(Se.Multiline,!1)},t.prototype.isPassword=function(){return this.acroField.hasFlag(Se.Password)},t.prototype.enablePassword=function(){this.acroField.setFlagTo(Se.Password,!0)},t.prototype.disablePassword=function(){this.acroField.setFlagTo(Se.Password,!1)},t.prototype.isFileSelector=function(){return this.acroField.hasFlag(Se.FileSelect)},t.prototype.enableFileSelection=function(){this.acroField.setFlagTo(Se.FileSelect,!0)},t.prototype.disableFileSelection=function(){this.acroField.setFlagTo(Se.FileSelect,!1)},t.prototype.isSpellChecked=function(){return!this.acroField.hasFlag(Se.DoNotSpellCheck)},t.prototype.enableSpellChecking=function(){this.acroField.setFlagTo(Se.DoNotSpellCheck,!1)},t.prototype.disableSpellChecking=function(){this.acroField.setFlagTo(Se.DoNotSpellCheck,!0)},t.prototype.isScrollable=function(){return!this.acroField.hasFlag(Se.DoNotScroll)},t.prototype.enableScrolling=function(){this.acroField.setFlagTo(Se.DoNotScroll,!1)},t.prototype.disableScrolling=function(){this.acroField.setFlagTo(Se.DoNotScroll,!0)},t.prototype.isCombed=function(){return this.acroField.hasFlag(Se.Comb)&&!this.isMultiline()&&!this.isPassword()&&!this.isFileSelector()&&this.getMaxLength()!==void 0},t.prototype.enableCombing=function(){if(this.getMaxLength()===void 0){var r="PDFTextFields must have a max length in order to be combed";console.warn(r)}this.markAsDirty(),this.disableMultiline(),this.disablePassword(),this.disableFileSelection(),this.acroField.setFlagTo(Se.Comb,!0)},t.prototype.disableCombing=function(){this.markAsDirty(),this.acroField.setFlagTo(Se.Comb,!1)},t.prototype.isRichFormatted=function(){return this.acroField.hasFlag(Se.RichText)},t.prototype.enableRichFormatting=function(){this.acroField.setFlagTo(Se.RichText,!0)},t.prototype.disableRichFormatting=function(){this.acroField.setFlagTo(Se.RichText,!1)},t.prototype.addToPage=function(r,n){var i,a,o,s,l,c,u;S(r,"page",[[ut,"PDFPage"]]),Lr(n),n||(n={}),"textColor"in n||(n.textColor=de(0,0,0)),"backgroundColor"in n||(n.backgroundColor=de(1,1,1)),"borderColor"in n||(n.borderColor=de(0,0,0)),"borderWidth"in n||(n.borderWidth=1);var h=this.createWidget({x:(i=n.x)!==null&&i!==void 0?i:0,y:(a=n.y)!==null&&a!==void 0?a:0,width:(o=n.width)!==null&&o!==void 0?o:200,height:(s=n.height)!==null&&s!==void 0?s:50,textColor:n.textColor,backgroundColor:n.backgroundColor,borderColor:n.borderColor,borderWidth:(l=n.borderWidth)!==null&&l!==void 0?l:0,rotate:(c=n.rotate)!==null&&c!==void 0?c:K(0),hidden:n.hidden,page:r.ref}),f=this.doc.context.register(h.dict);this.acroField.addWidget(f);var d=(u=n.font)!==null&&u!==void 0?u:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(h,d),r.node.addAnnot(f)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}this.markAsClean()},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??N0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br),Vr;(function(e){e.Courier="Courier",e.CourierBold="Courier-Bold",e.CourierOblique="Courier-Oblique",e.CourierBoldOblique="Courier-BoldOblique",e.Helvetica="Helvetica",e.HelveticaBold="Helvetica-Bold",e.HelveticaOblique="Helvetica-Oblique",e.HelveticaBoldOblique="Helvetica-BoldOblique",e.TimesRoman="Times-Roman",e.TimesRomanBold="Times-Bold",e.TimesRomanItalic="Times-Italic",e.TimesRomanBoldItalic="Times-BoldItalic",e.Symbol="Symbol",e.ZapfDingbats="ZapfDingbats"})(Vr||(Vr={}));var j0=function(){function e(t,r){var n=this;this.embedDefaultFont=function(){return n.doc.embedStandardFont(Vr.Helvetica)},S(t,"acroForm",[[Ai,"PDFAcroForm"]]),S(r,"doc",[[_t,"PDFDocument"]]),this.acroForm=t,this.doc=r,this.dirtyFields=new Set,this.defaultFontCache=Ot.populatedBy(this.embedDefaultFont)}return e.prototype.hasXFA=function(){return this.acroForm.dict.has(g.of("XFA"))},e.prototype.deleteXFA=function(){this.acroForm.dict.delete(g.of("XFA"))},e.prototype.getFields=function(){for(var t=this.acroForm.getAllFields(),r=[],n=0,i=t.length;n<i;n++){var a=t[n],o=a[0],s=a[1],l=z0(o,s,this.doc);l&&r.push(l)}return r},e.prototype.getFieldMaybe=function(t){S(t,"name",["string"]);for(var r=this.getFields(),n=0,i=r.length;n<i;n++){var a=r[n];if(a.getName()===t)return a}},e.prototype.getField=function(t){S(t,"name",["string"]);var r=this.getFieldMaybe(t);if(r)return r;throw new m0(t)},e.prototype.getButton=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Zi)return r;throw new yr(t,Zi,r)},e.prototype.getCheckBox=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Ln)return r;throw new yr(t,Ln,r)},e.prototype.getDropdown=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Ki)return r;throw new yr(t,Ki,r)},e.prototype.getOptionList=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Hi)return r;throw new yr(t,Hi,r)},e.prototype.getRadioGroup=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Vn)return r;throw new yr(t,Vn,r)},e.prototype.getSignature=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof so)return r;throw new yr(t,so,r)},e.prototype.getTextField=function(t){S(t,"name",["string"]);var r=this.getField(t);if(r instanceof Xi)return r;throw new yr(t,Xi,r)},e.prototype.createButton=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Ci.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Zi.of(i,i.ref,this.doc)},e.prototype.createCheckBox=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=wi.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Ln.of(i,i.ref,this.doc)},e.prototype.createDropdown=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Si.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Ki.of(i,i.ref,this.doc)},e.prototype.createOptionList=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Pi.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Hi.of(i,i.ref,this.doc)},e.prototype.createRadioGroup=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=Ti.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Vn.of(i,i.ref,this.doc)},e.prototype.createTextField=function(t){S(t,"name",["string"]);var r=Wr(t),n=this.findOrCreateNonTerminals(r.nonTerminal),i=ki.create(this.doc.context);return i.setPartialName(r.terminal),qr(n,[i,i.ref],r.terminal),Xi.of(i,i.ref,this.doc)},e.prototype.flatten=function(t){t===void 0&&(t={updateFieldAppearances:!0}),t.updateFieldAppearances&&this.updateFieldAppearances();for(var r=this.getFields(),n=0,i=r.length;n<i;n++){for(var a=r[n],o=a.acroField.getWidgets(),s=0,l=o.length;s<l;s++){var c=o[s],u=this.findWidgetPage(c),h=this.findWidgetAppearanceRef(a,c),f=u.node.newXObject("FlatWidget",h),d=c.getRectangle(),v=se([Ae(),st(d.x,d.y)],Yt(Y(Y({},d),{rotation:0})),[eo(f),De()]).filter(Boolean);u.pushOperators.apply(u,v)}this.removeField(a)}},e.prototype.removeField=function(t){for(var r=t.acroField.getWidgets(),n=new Set,i=0,a=r.length;i<a;i++){var o=r[i],s=this.findWidgetAppearanceRef(t,o),l=this.findWidgetPage(o);n.add(l),l.node.removeAnnot(s)}n.forEach(function(d){return d.node.removeAnnot(t.ref)}),this.acroForm.removeField(t.acroField);for(var c=t.acroField.normalizedEntries().Kids,u=c.size(),h=0;h<u;h++){var f=c.get(h);f instanceof ve&&this.doc.context.delete(f)}this.doc.context.delete(t.ref)},e.prototype.updateFieldAppearances=function(t){N(t,"font",[[$e,"PDFFont"]]),t=t??this.getDefaultFont();for(var r=this.getFields(),n=0,i=r.length;n<i;n++){var a=r[n];a.needsAppearancesUpdate()&&a.defaultUpdateAppearances(t)}},e.prototype.markFieldAsDirty=function(t){N(t,"fieldRef",[[ve,"PDFRef"]]),this.dirtyFields.add(t)},e.prototype.markFieldAsClean=function(t){N(t,"fieldRef",[[ve,"PDFRef"]]),this.dirtyFields.delete(t)},e.prototype.fieldIsDirty=function(t){return N(t,"fieldRef",[[ve,"PDFRef"]]),this.dirtyFields.has(t)},e.prototype.getDefaultFont=function(){return this.defaultFontCache.access()},e.prototype.findWidgetPage=function(t){var r=t.P(),n=this.doc.getPages().find(function(a){return a.ref===r});if(n===void 0){var i=this.doc.context.getObjectRef(t.dict);if(i===void 0)throw new Error("Could not find PDFRef for PDFObject");if(n=this.doc.findPageForAnnotationRef(i),n===void 0)throw new Error("Could not find page for PDFRef "+i)}return n},e.prototype.findWidgetAppearanceRef=function(t,r){var n,i=r.getNormalAppearance();if(i instanceof Q&&(t instanceof Ln||t instanceof Vn)){var a=t.acroField.getValue(),o=(n=i.get(a))!==null&&n!==void 0?n:i.get(g.of("Off"));o instanceof ve&&(i=o)}if(!(i instanceof ve)){var s=t.getName();throw new Error("Failed to extract appearance ref for: "+s)}return i},e.prototype.findOrCreateNonTerminals=function(t){for(var r=[this.acroForm],n=0,i=t.length;n<i;n++){var a=t[n];if(!a)throw new x0(a);var o=r[0],s=r[1],l=this.findNonTerminal(a,o);if(l)r=l;else{var c=Fi.create(this.doc.context);c.setPartialName(a),c.setParent(s);var u=this.doc.context.register(c.dict);o.addField(u),r=[c,u]}}return r},e.prototype.findNonTerminal=function(t,r){for(var n=r instanceof Ai?this.acroForm.getFields():Ha(r.Kids()),i=0,a=n.length;i<a;i++){var o=n[i],s=o[0],l=o[1];if(s.getPartialName()===t){if(s instanceof Fi)return[s,l];throw new Kl(t)}}},e.of=function(t,r){return new e(t,r)},e}(),z0=function(e,t,r){if(e instanceof Ci)return Zi.of(e,t,r);if(e instanceof wi)return Ln.of(e,t,r);if(e instanceof Si)return Ki.of(e,t,r);if(e instanceof Pi)return Hi.of(e,t,r);if(e instanceof ki)return Xi.of(e,t,r);if(e instanceof Ti)return Vn.of(e,t,r);if(e instanceof Ka)return so.of(e,t,r)},Wr=function(e){if(e.length===0)throw new Error("PDF field names must not be empty strings");for(var t=e.split("."),r=0,n=t.length;r<n;r++)if(t[r]==="")throw new Error('Periods in PDF field names must be separated by at least one character: "'+e+'"');return t.length===1?{nonTerminal:[],terminal:t[0]}:{nonTerminal:t.slice(0,t.length-1),terminal:t[t.length-1]}},qr=function(e,t,r){for(var n=e[0],i=e[1],a=t[0],o=t[1],s=n.normalizedEntries(),l=Ha("Kids"in s?s.Kids:s.Fields),c=0,u=l.length;c<u;c++)if(l[c][0].getPartialName()===r)throw new Kl(r);n.addField(o),a.setParent(i)},U0={A4:[595.28,841.89]},co;(function(e){e[e.Fastest=1/0]="Fastest",e[e.Fast=1500]="Fast",e[e.Medium=500]="Medium",e[e.Slow=100]="Slow"})(co||(co={}));var L0=function(){function e(t,r,n){this.alreadyEmbedded=!1,this.ref=t,this.doc=r,this.embedder=n}return e.prototype.embed=function(){return _(this,void 0,void 0,function(){var t,r,n,i,a;return $(this,function(o){switch(o.label){case 0:return this.alreadyEmbedded?[3,2]:[4,this.embedder.embedIntoContext(this.doc.context,this.ref)];case 1:t=o.sent(),this.doc.catalog.has(g.of("Names"))||this.doc.catalog.set(g.of("Names"),this.doc.context.obj({})),r=this.doc.catalog.lookup(g.of("Names"),Q),r.has(g.of("EmbeddedFiles"))||r.set(g.of("EmbeddedFiles"),this.doc.context.obj({})),n=r.lookup(g.of("EmbeddedFiles"),Q),n.has(g.of("Names"))||n.set(g.of("Names"),this.doc.context.obj([])),i=n.lookup(g.of("Names"),fe),i.push(G.fromText(this.embedder.fileName)),i.push(t),this.doc.catalog.has(g.of("AF"))||this.doc.catalog.set(g.of("AF"),this.doc.context.obj([])),a=this.doc.catalog.lookup(g.of("AF"),fe),a.push(t),this.alreadyEmbedded=!0,o.label=2;case 2:return[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),V0=function(){function e(t,r,n){this.alreadyEmbedded=!1,this.ref=t,this.doc=r,this.embedder=n}return e.prototype.embed=function(){return _(this,void 0,void 0,function(){var t,r,n,i,a,o,s;return $(this,function(l){switch(l.label){case 0:return this.alreadyEmbedded?[3,2]:(t=this.doc,r=t.catalog,n=t.context,[4,this.embedder.embedIntoContext(this.doc.context,this.ref)]);case 1:i=l.sent(),r.has(g.of("Names"))||r.set(g.of("Names"),n.obj({})),a=r.lookup(g.of("Names"),Q),a.has(g.of("JavaScript"))||a.set(g.of("JavaScript"),n.obj({})),o=a.lookup(g.of("JavaScript"),Q),o.has(g.of("Names"))||o.set(g.of("Names"),n.obj([])),s=o.lookup(g.of("Names"),fe),s.push(G.fromText(this.embedder.scriptName)),s.push(i),this.alreadyEmbedded=!0,l.label=2;case 2:return[2]}})})},e.of=function(t,r,n){return new e(t,r,n)},e}(),W0=function(){function e(t,r){this.script=t,this.scriptName=r}return e.for=function(t,r){return new e(t,r)},e.prototype.embedIntoContext=function(t,r){return _(this,void 0,void 0,function(){var n;return $(this,function(i){return n=t.obj({Type:"Action",S:"JavaScript",JS:G.fromText(this.script)}),r?(t.assign(r,n),[2,r]):[2,t.register(n)]})})},e}(),_t=function(){function e(t,r,n){var i=this;if(this.defaultWordBreaks=[" "],this.computePages=function(){var a=[];return i.catalog.Pages().traverse(function(o,s){if(o instanceof It){var l=i.pageMap.get(o);l||(l=ut.of(o,s,i),i.pageMap.set(o,l)),a.push(l)}}),a},this.getOrCreateForm=function(){var a=i.catalog.getOrCreateAcroForm();return j0.of(a,i)},S(t,"context",[[ja,"PDFContext"]]),S(r,"ignoreEncryption",["boolean"]),this.context=t,this.catalog=t.lookup(t.trailerInfo.Root),this.isEncrypted=!!t.lookup(t.trailerInfo.Encrypt),this.pageCache=Ot.populatedBy(this.computePages),this.pageMap=new Map,this.formCache=Ot.populatedBy(this.getOrCreateForm),this.fonts=[],this.images=[],this.embeddedPages=[],this.embeddedFiles=[],this.javaScripts=[],!r&&this.isEncrypted)throw new p0;n&&this.updateInfoDict()}return e.load=function(t,r){return r===void 0&&(r={}),_(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u,h,f,d,v;return $(this,function(p){switch(p.label){case 0:return n=r.ignoreEncryption,i=n===void 0?!1:n,a=r.parseSpeed,o=a===void 0?co.Slow:a,s=r.throwOnInvalidObject,l=s===void 0?!1:s,c=r.updateMetadata,u=c===void 0?!0:c,h=r.capNumbers,f=h===void 0?!1:h,S(t,"pdf",["string",Uint8Array,ArrayBuffer]),S(i,"ignoreEncryption",["boolean"]),S(o,"parseSpeed",["number"]),S(l,"throwOnInvalidObject",["boolean"]),d=_r(t),[4,Gd.forBytesWithOptions(d,o,l,f).parseDocument()];case 1:return v=p.sent(),[2,new e(v,i,u)]}})})},e.create=function(t){return t===void 0&&(t={}),_(this,void 0,void 0,function(){var r,n,i,a,o,s;return $(this,function(l){return r=t.updateMetadata,n=r===void 0?!0:r,i=ja.create(),a=bl.withContext(i),o=i.register(a),s=yl.withContextAndPages(i,o),i.trailerInfo.Root=i.register(s),[2,new e(i,!1,n)]})})},e.prototype.registerFontkit=function(t){this.fontkit=t},e.prototype.getForm=function(){var t=this.formCache.access();return t.hasXFA()&&(console.warn("Removing XFA form data as pdf-lib does not support reading or writing XFA"),t.deleteXFA()),t},e.prototype.getTitle=function(){var t=this.getInfoDict().lookup(g.Title);if(t)return $t(t),t.decodeText()},e.prototype.getAuthor=function(){var t=this.getInfoDict().lookup(g.Author);if(t)return $t(t),t.decodeText()},e.prototype.getSubject=function(){var t=this.getInfoDict().lookup(g.Subject);if(t)return $t(t),t.decodeText()},e.prototype.getKeywords=function(){var t=this.getInfoDict().lookup(g.Keywords);if(t)return $t(t),t.decodeText()},e.prototype.getCreator=function(){var t=this.getInfoDict().lookup(g.Creator);if(t)return $t(t),t.decodeText()},e.prototype.getProducer=function(){var t=this.getInfoDict().lookup(g.Producer);if(t)return $t(t),t.decodeText()},e.prototype.getCreationDate=function(){var t=this.getInfoDict().lookup(g.CreationDate);if(t)return $t(t),t.decodeDate()},e.prototype.getModificationDate=function(){var t=this.getInfoDict().lookup(g.ModDate);if(t)return $t(t),t.decodeDate()},e.prototype.setTitle=function(t,r){S(t,"title",["string"]);var n=g.of("Title");if(this.getInfoDict().set(n,G.fromText(t)),r!=null&&r.showInWindowTitleBar){var i=this.catalog.getOrCreateViewerPreferences();i.setDisplayDocTitle(!0)}},e.prototype.setAuthor=function(t){S(t,"author",["string"]);var r=g.of("Author");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setSubject=function(t){S(t,"author",["string"]);var r=g.of("Subject");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setKeywords=function(t){S(t,"keywords",[Array]);var r=g.of("Keywords");this.getInfoDict().set(r,G.fromText(t.join(" ")))},e.prototype.setCreator=function(t){S(t,"creator",["string"]);var r=g.of("Creator");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setProducer=function(t){S(t,"creator",["string"]);var r=g.of("Producer");this.getInfoDict().set(r,G.fromText(t))},e.prototype.setLanguage=function(t){S(t,"language",["string"]);var r=g.of("Lang");this.catalog.set(r,pe.of(t))},e.prototype.setCreationDate=function(t){S(t,"creationDate",[[Date,"Date"]]);var r=g.of("CreationDate");this.getInfoDict().set(r,pe.fromDate(t))},e.prototype.setModificationDate=function(t){S(t,"modificationDate",[[Date,"Date"]]);var r=g.of("ModDate");this.getInfoDict().set(r,pe.fromDate(t))},e.prototype.getPageCount=function(){return this.pageCount===void 0&&(this.pageCount=this.getPages().length),this.pageCount},e.prototype.getPages=function(){return this.pageCache.access()},e.prototype.getPage=function(t){var r=this.getPages();return Je(t,"index",0,r.length-1),r[t]},e.prototype.getPageIndices=function(){return Su(0,this.getPageCount())},e.prototype.removePage=function(t){var r=this.getPageCount();if(this.pageCount===0)throw new b0;Je(t,"index",0,r-1),this.catalog.removeLeafNode(t),this.pageCount=r-1},e.prototype.addPage=function(t){return S(t,"page",["undefined",[ut,"PDFPage"],Array]),this.insertPage(this.getPageCount(),t)},e.prototype.insertPage=function(t,r){var n=this.getPageCount();if(Je(t,"index",0,n),S(r,"page",["undefined",[ut,"PDFPage"],Array]),!r||Array.isArray(r)){var i=Array.isArray(r)?r:U0.A4;r=ut.create(this),r.setSize.apply(r,i)}else if(r.doc!==this)throw new y0;var a=this.catalog.insertLeafNode(r.ref,t);return r.node.setParent(a),this.pageMap.set(r.node,r),this.pageCache.invalidate(),this.pageCount=n+1,r},e.prototype.copyPages=function(t,r){return _(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u;return $(this,function(h){switch(h.label){case 0:return S(t,"srcDoc",[[e,"PDFDocument"]]),S(r,"indices",[Array]),[4,t.flush()];case 1:for(h.sent(),n=Qc.for(t.context,this.context),i=t.getPages(),a=new Array(r.length),o=0,s=r.length;o<s;o++)l=i[r[o]],c=n.copy(l.node),u=this.context.register(c),a[o]=ut.of(c,u,this);return[2,a]}})})},e.prototype.copy=function(){return _(this,void 0,void 0,function(){var t,r,n,i;return $(this,function(a){switch(a.label){case 0:return[4,e.create()];case 1:return t=a.sent(),[4,t.copyPages(this,this.getPageIndices())];case 2:for(r=a.sent(),n=0,i=r.length;n<i;n++)t.addPage(r[n]);return this.getAuthor()!==void 0&&t.setAuthor(this.getAuthor()),this.getCreationDate()!==void 0&&t.setCreationDate(this.getCreationDate()),this.getCreator()!==void 0&&t.setCreator(this.getCreator()),this.getModificationDate()!==void 0&&t.setModificationDate(this.getModificationDate()),this.getProducer()!==void 0&&t.setProducer(this.getProducer()),this.getSubject()!==void 0&&t.setSubject(this.getSubject()),this.getTitle()!==void 0&&t.setTitle(this.getTitle()),t.defaultWordBreaks=this.defaultWordBreaks,[2,t]}})})},e.prototype.addJavaScript=function(t,r){S(t,"name",["string"]),S(r,"script",["string"]);var n=W0.for(r,t),i=this.context.nextRef(),a=V0.of(i,this,n);this.javaScripts.push(a)},e.prototype.attach=function(t,r,n){return n===void 0&&(n={}),_(this,void 0,void 0,function(){var i,a,o,s;return $(this,function(l){return S(t,"attachment",["string",Uint8Array,ArrayBuffer]),S(r,"name",["string"]),N(n.mimeType,"mimeType",["string"]),N(n.description,"description",["string"]),N(n.creationDate,"options.creationDate",[Date]),N(n.modificationDate,"options.modificationDate",[Date]),nt(n.afRelationship,"options.afRelationship",La),i=_r(t),a=gd.for(i,r,n),o=this.context.nextRef(),s=L0.of(o,this,a),this.embeddedFiles.push(s),[2]})})},e.prototype.embedFont=function(t,r){return r===void 0&&(r={}),_(this,void 0,void 0,function(){var n,i,a,o,s,l,c,u,h,f;return $(this,function(d){switch(d.label){case 0:return n=r.subset,i=n===void 0?!1:n,a=r.customName,o=r.features,S(t,"font",["string",Uint8Array,ArrayBuffer]),S(i,"subset",["boolean"]),zc(t)?(s=yi.for(t,a),[3,7]):[3,1];case 1:return ku(t)?(l=_r(t),c=this.assertFontkit(),i?[4,pd.for(c,l,a,o)]:[3,3]):[3,6];case 2:return u=d.sent(),[3,5];case 3:return[4,Ua.for(c,l,a,o)];case 4:u=d.sent(),d.label=5;case 5:return s=u,[3,7];case 6:throw new TypeError("`font` must be one of `StandardFonts | string | Uint8Array | ArrayBuffer`");case 7:return h=this.context.nextRef(),f=$e.of(h,this,s),this.fonts.push(f),[2,f]}})})},e.prototype.embedStandardFont=function(t,r){if(S(t,"font",["string"]),!zc(t))throw new TypeError("`font` must be one of type `StandardFonts`");var n=yi.for(t,r),i=this.context.nextRef(),a=$e.of(i,this,n);return this.fonts.push(a),a},e.prototype.embedJpg=function(t){return _(this,void 0,void 0,function(){var r,n,i,a;return $(this,function(o){switch(o.label){case 0:return S(t,"jpg",["string",Uint8Array,ArrayBuffer]),r=_r(t),[4,il.for(r)];case 1:return n=o.sent(),i=this.context.nextRef(),a=oo.of(i,this,n),this.images.push(a),[2,a]}})})},e.prototype.embedPng=function(t){return _(this,void 0,void 0,function(){var r,n,i,a;return $(this,function(o){switch(o.label){case 0:return S(t,"png",["string",Uint8Array,ArrayBuffer]),r=_r(t),[4,al.for(r)];case 1:return n=o.sent(),i=this.context.nextRef(),a=oo.of(i,this,n),this.images.push(a),[2,a]}})})},e.prototype.embedPdf=function(t,r){return r===void 0&&(r=[0]),_(this,void 0,void 0,function(){var n,i,a;return $(this,function(o){switch(o.label){case 0:return S(t,"pdf",["string",Uint8Array,ArrayBuffer,[e,"PDFDocument"]]),S(r,"indices",[Array]),t instanceof e?(i=t,[3,3]):[3,1];case 1:return[4,e.load(t)];case 2:i=o.sent(),o.label=3;case 3:return n=i,a=Fu(n.getPages(),r),[2,this.embedPages(a)]}})})},e.prototype.embedPage=function(t,r,n){return _(this,void 0,void 0,function(){var i;return $(this,function(a){switch(a.label){case 0:return S(t,"page",[[ut,"PDFPage"]]),[4,this.embedPages([t],[r],[n])];case 1:return i=a.sent()[0],[2,i]}})})},e.prototype.embedPages=function(t,r,n){return r===void 0&&(r=[]),n===void 0&&(n=[]),_(this,void 0,void 0,function(){var c,u,i,a,o,s,l,c,u,h,f,d,v,p,m;return $(this,function(b){switch(b.label){case 0:if(t.length===0)return[2,[]];for(c=0,u=t.length-1;c<u;c++)if(i=t[c],a=t[c+1],i.node.context!==a.node.context)throw new Wh;o=t[0].node.context,s=o===this.context?function(k){return k}:Qc.for(o,this.context).copy,l=new Array(t.length),c=0,u=t.length,b.label=1;case 1:return c<u?(h=s(t[c].node),f=r[c],d=n[c],[4,fl.for(h,f,d)]):[3,4];case 2:v=b.sent(),p=this.context.nextRef(),l[c]=Jl.of(p,this,v),b.label=3;case 3:return c++,[3,1];case 4:return(m=this.embeddedPages).push.apply(m,l),[2,l]}})})},e.prototype.flush=function(){return _(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,this.embedAll(this.fonts)];case 1:return t.sent(),[4,this.embedAll(this.images)];case 2:return t.sent(),[4,this.embedAll(this.embeddedPages)];case 3:return t.sent(),[4,this.embedAll(this.embeddedFiles)];case 4:return t.sent(),[4,this.embedAll(this.javaScripts)];case 5:return t.sent(),[2]}})})},e.prototype.save=function(t){return t===void 0&&(t={}),_(this,void 0,void 0,function(){var r,n,i,a,o,s,l,c,u,h;return $(this,function(f){switch(f.label){case 0:return r=t.useObjectStreams,n=r===void 0?!0:r,i=t.addDefaultPage,a=i===void 0?!0:i,o=t.objectsPerTick,s=o===void 0?50:o,l=t.updateFieldAppearances,c=l===void 0?!0:l,S(n,"useObjectStreams",["boolean"]),S(a,"addDefaultPage",["boolean"]),S(s,"objectsPerTick",["number"]),S(c,"updateFieldAppearances",["boolean"]),a&&this.getPageCount()===0&&this.addPage(),c&&(u=this.formCache.getValue(),u&&u.updateFieldAppearances()),[4,this.flush()];case 1:return f.sent(),h=n?ld:el,[2,h.forContext(this.context,s).serializeToBuffer()]}})})},e.prototype.saveAsBase64=function(t){return t===void 0&&(t={}),_(this,void 0,void 0,function(){var r,n,i,a,o;return $(this,function(s){switch(s.label){case 0:return r=t.dataUri,n=r===void 0?!1:r,i=au(t,["dataUri"]),S(n,"dataUri",["boolean"]),[4,this.save(i)];case 1:return a=s.sent(),o=ou(a),[2,n?"data:application/pdf;base64,"+o:o]}})})},e.prototype.findPageForAnnotationRef=function(t){for(var r=this.getPages(),n=0,i=r.length;n<i;n++){var a=r[n],o=a.node.Annots();if((o==null?void 0:o.indexOf(t))!==void 0)return a}},e.prototype.embedAll=function(t){return _(this,void 0,void 0,function(){var r,n;return $(this,function(i){switch(i.label){case 0:r=0,n=t.length,i.label=1;case 1:return r<n?[4,t[r].embed()]:[3,4];case 2:i.sent(),i.label=3;case 3:return r++,[3,1];case 4:return[2]}})})},e.prototype.updateInfoDict=function(){var t="pdf-lib (https://github.com/Hopding/pdf-lib)",r=new Date,n=this.getInfoDict();this.setProducer(t),this.setModificationDate(r),n.get(g.of("Creator"))||this.setCreator(t),n.get(g.of("CreationDate"))||this.setCreationDate(r)},e.prototype.getInfoDict=function(){var t=this.context.lookup(this.context.trailerInfo.Info);if(t instanceof Q)return t;var r=this.context.obj({});return this.context.trailerInfo.Info=this.context.register(r),r},e.prototype.assertFontkit=function(){if(!this.fontkit)throw new g0;return this.fontkit},e}();function $t(e){if(!(e instanceof G)&&!(e instanceof pe))throw new vi([G,pe],e)}var Bt;(function(e){e.Normal="Normal",e.Multiply="Multiply",e.Screen="Screen",e.Overlay="Overlay",e.Darken="Darken",e.Lighten="Lighten",e.ColorDodge="ColorDodge",e.ColorBurn="ColorBurn",e.HardLight="HardLight",e.SoftLight="SoftLight",e.Difference="Difference",e.Exclusion="Exclusion"})(Bt||(Bt={}));var ut=function(){function e(t,r,n){this.fontSize=24,this.fontColor=de(0,0,0),this.lineHeight=24,this.x=0,this.y=0,S(t,"leafNode",[[It,"PDFPageLeaf"]]),S(r,"ref",[[ve,"PDFRef"]]),S(n,"doc",[[_t,"PDFDocument"]]),this.node=t,this.ref=r,this.doc=n}return e.prototype.setRotation=function(t){var r=Cl(t);Vc(r,"degreesAngle",90),this.node.set(g.of("Rotate"),this.doc.context.obj(r))},e.prototype.getRotation=function(){var t=this.node.Rotate();return K(t?t.asNumber():0)},e.prototype.setSize=function(t,r){S(t,"width",["number"]),S(r,"height",["number"]);var n=this.getMediaBox();this.setMediaBox(n.x,n.y,t,r);var i=this.getCropBox(),a=this.getBleedBox(),o=this.getTrimBox(),s=this.getArtBox(),l=this.node.CropBox(),c=this.node.BleedBox(),u=this.node.TrimBox(),h=this.node.ArtBox();l&&fi(i,n)&&this.setCropBox(n.x,n.y,t,r),c&&fi(a,n)&&this.setBleedBox(n.x,n.y,t,r),u&&fi(o,n)&&this.setTrimBox(n.x,n.y,t,r),h&&fi(s,n)&&this.setArtBox(n.x,n.y,t,r)},e.prototype.setWidth=function(t){S(t,"width",["number"]),this.setSize(t,this.getSize().height)},e.prototype.setHeight=function(t){S(t,"height",["number"]),this.setSize(this.getSize().width,t)},e.prototype.setMediaBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.MediaBox,a)},e.prototype.setCropBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.CropBox,a)},e.prototype.setBleedBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.BleedBox,a)},e.prototype.setTrimBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.TrimBox,a)},e.prototype.setArtBox=function(t,r,n,i){S(t,"x",["number"]),S(r,"y",["number"]),S(n,"width",["number"]),S(i,"height",["number"]);var a=this.doc.context.obj([t,r,t+n,r+i]);this.node.set(g.ArtBox,a)},e.prototype.getSize=function(){var t=this.getMediaBox(),r=t.width,n=t.height;return{width:r,height:n}},e.prototype.getWidth=function(){return this.getSize().width},e.prototype.getHeight=function(){return this.getSize().height},e.prototype.getMediaBox=function(){var t=this.node.MediaBox();return t.asRectangle()},e.prototype.getCropBox=function(){var t,r=this.node.CropBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getMediaBox()},e.prototype.getBleedBox=function(){var t,r=this.node.BleedBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getCropBox()},e.prototype.getTrimBox=function(){var t,r=this.node.TrimBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getCropBox()},e.prototype.getArtBox=function(){var t,r=this.node.ArtBox();return(t=r==null?void 0:r.asRectangle())!==null&&t!==void 0?t:this.getCropBox()},e.prototype.translateContent=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.node.normalize(),this.getContentStream();var n=this.createContentStream(Ae(),st(t,r)),i=this.doc.context.register(n),a=this.createContentStream(De()),o=this.doc.context.register(a);this.node.wrapContentStreams(i,o)},e.prototype.scale=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.setSize(this.getWidth()*t,this.getHeight()*r),this.scaleContent(t,r),this.scaleAnnotations(t,r)},e.prototype.scaleContent=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.node.normalize(),this.getContentStream();var n=this.createContentStream(Ae(),Nn(t,r)),i=this.doc.context.register(n),a=this.createContentStream(De()),o=this.doc.context.register(a);this.node.wrapContentStreams(i,o)},e.prototype.scaleAnnotations=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]);var n=this.node.Annots();if(n)for(var i=0;i<n.size();i++){var a=n.lookup(i);a instanceof Q&&this.scaleAnnot(a,t,r)}},e.prototype.resetPosition=function(){this.getContentStream(!1),this.x=0,this.y=0},e.prototype.setFont=function(t){S(t,"font",[[$e,"PDFFont"]]),this.font=t,this.fontKey=this.node.newFontDictionary(this.font.name,this.font.ref)},e.prototype.setFontSize=function(t){S(t,"fontSize",["number"]),this.fontSize=t},e.prototype.setFontColor=function(t){S(t,"fontColor",[[Object,"Color"]]),this.fontColor=t},e.prototype.setLineHeight=function(t){S(t,"lineHeight",["number"]),this.lineHeight=t},e.prototype.getPosition=function(){return{x:this.x,y:this.y}},e.prototype.getX=function(){return this.x},e.prototype.getY=function(){return this.y},e.prototype.moveTo=function(t,r){S(t,"x",["number"]),S(r,"y",["number"]),this.x=t,this.y=r},e.prototype.moveDown=function(t){S(t,"yDecrease",["number"]),this.y-=t},e.prototype.moveUp=function(t){S(t,"yIncrease",["number"]),this.y+=t},e.prototype.moveLeft=function(t){S(t,"xDecrease",["number"]),this.x-=t},e.prototype.moveRight=function(t){S(t,"xIncrease",["number"]),this.x+=t},e.prototype.pushOperators=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];Lc(t,"operator",[[ie,"PDFOperator"]]);var n=this.getContentStream();n.push.apply(n,t)},e.prototype.drawText=function(t,r){var n,i,a,o,s,l,c;r===void 0&&(r={}),S(t,"text",["string"]),N(r.color,"options.color",[[Object,"Color"]]),vt(r.opacity,"opacity.opacity",0,1),N(r.font,"options.font",[[$e,"PDFFont"]]),N(r.size,"options.size",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(r.ySkew,"options.ySkew",[[Object,"Rotation"]]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.lineHeight,"options.lineHeight",["number"]),N(r.maxWidth,"options.maxWidth",["number"]),N(r.wordBreaks,"options.wordBreaks",[Array]),nt(r.blendMode,"options.blendMode",Bt);for(var u=this.setOrEmbedFont(r.font),h=u.oldFont,f=u.newFont,d=u.newFontKey,v=r.size||this.fontSize,p=r.wordBreaks||this.doc.defaultWordBreaks,m=function(A){return f.widthOfTextAtSize(A,v)},b=r.maxWidth===void 0?Xo(Qr(t)):pu(t,p,r.maxWidth,m),k=new Array(b.length),x=0,T=b.length;x<T;x++)k[x]=f.encodeText(b[x]);var w=this.maybeEmbedGraphicsState({opacity:r.opacity,blendMode:r.blendMode}),F=this.getContentStream();F.push.apply(F,s0(k,{color:(n=r.color)!==null&&n!==void 0?n:this.fontColor,font:d,size:v,rotate:(i=r.rotate)!==null&&i!==void 0?i:K(0),xSkew:(a=r.xSkew)!==null&&a!==void 0?a:K(0),ySkew:(o=r.ySkew)!==null&&o!==void 0?o:K(0),x:(s=r.x)!==null&&s!==void 0?s:this.x,y:(l=r.y)!==null&&l!==void 0?l:this.y,lineHeight:(c=r.lineHeight)!==null&&c!==void 0?c:this.lineHeight,graphicsState:w})),r.font&&(h?this.setFont(h):this.resetFont())},e.prototype.drawImage=function(t,r){var n,i,a,o,s,l,c;r===void 0&&(r={}),S(t,"image",[[oo,"PDFImage"]]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.width,"options.width",["number"]),N(r.height,"options.height",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(r.ySkew,"options.ySkew",[[Object,"Rotation"]]),vt(r.opacity,"opacity.opacity",0,1),nt(r.blendMode,"options.blendMode",Bt);var u=this.node.newXObject("Image",t.ref),h=this.maybeEmbedGraphicsState({opacity:r.opacity,blendMode:r.blendMode}),f=this.getContentStream();f.push.apply(f,Wl(u,{x:(n=r.x)!==null&&n!==void 0?n:this.x,y:(i=r.y)!==null&&i!==void 0?i:this.y,width:(a=r.width)!==null&&a!==void 0?a:t.size().width,height:(o=r.height)!==null&&o!==void 0?o:t.size().height,rotate:(s=r.rotate)!==null&&s!==void 0?s:K(0),xSkew:(l=r.xSkew)!==null&&l!==void 0?l:K(0),ySkew:(c=r.ySkew)!==null&&c!==void 0?c:K(0),graphicsState:h}))},e.prototype.drawPage=function(t,r){var n,i,a,o,s;r===void 0&&(r={}),S(t,"embeddedPage",[[Jl,"PDFEmbeddedPage"]]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.xScale,"options.xScale",["number"]),N(r.yScale,"options.yScale",["number"]),N(r.width,"options.width",["number"]),N(r.height,"options.height",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(r.ySkew,"options.ySkew",[[Object,"Rotation"]]),vt(r.opacity,"opacity.opacity",0,1),nt(r.blendMode,"options.blendMode",Bt);var l=this.node.newXObject("EmbeddedPdfPage",t.ref),c=this.maybeEmbedGraphicsState({opacity:r.opacity,blendMode:r.blendMode}),u=r.width!==void 0?r.width/t.width:r.xScale!==void 0?r.xScale:1,h=r.height!==void 0?r.height/t.height:r.yScale!==void 0?r.yScale:1,f=this.getContentStream();f.push.apply(f,c0(l,{x:(n=r.x)!==null&&n!==void 0?n:this.x,y:(i=r.y)!==null&&i!==void 0?i:this.y,xScale:u,yScale:h,rotate:(a=r.rotate)!==null&&a!==void 0?a:K(0),xSkew:(o=r.xSkew)!==null&&o!==void 0?o:K(0),ySkew:(s=r.ySkew)!==null&&s!==void 0?s:K(0),graphicsState:c}))},e.prototype.drawSvgPath=function(t,r){var n,i,a,o,s,l,c,u,h;r===void 0&&(r={}),S(t,"path",["string"]),N(r.x,"options.x",["number"]),N(r.y,"options.y",["number"]),N(r.scale,"options.scale",["number"]),N(r.rotate,"options.rotate",[[Object,"Rotation"]]),N(r.borderWidth,"options.borderWidth",["number"]),N(r.color,"options.color",[[Object,"Color"]]),vt(r.opacity,"opacity.opacity",0,1),N(r.borderColor,"options.borderColor",[[Object,"Color"]]),N(r.borderDashArray,"options.borderDashArray",[Array]),N(r.borderDashPhase,"options.borderDashPhase",["number"]),nt(r.borderLineCap,"options.borderLineCap",vr),vt(r.borderOpacity,"options.borderOpacity",0,1),nt(r.blendMode,"options.blendMode",Bt);var f=this.maybeEmbedGraphicsState({opacity:r.opacity,borderOpacity:r.borderOpacity,blendMode:r.blendMode});!("color"in r)&&!("borderColor"in r)&&(r.borderColor=de(0,0,0));var d=this.getContentStream();d.push.apply(d,h0(t,{x:(n=r.x)!==null&&n!==void 0?n:this.x,y:(i=r.y)!==null&&i!==void 0?i:this.y,scale:r.scale,rotate:(a=r.rotate)!==null&&a!==void 0?a:K(0),color:(o=r.color)!==null&&o!==void 0?o:void 0,borderColor:(s=r.borderColor)!==null&&s!==void 0?s:void 0,borderWidth:(l=r.borderWidth)!==null&&l!==void 0?l:0,borderDashArray:(c=r.borderDashArray)!==null&&c!==void 0?c:void 0,borderDashPhase:(u=r.borderDashPhase)!==null&&u!==void 0?u:void 0,borderLineCap:(h=r.borderLineCap)!==null&&h!==void 0?h:void 0,graphicsState:f}))},e.prototype.drawLine=function(t){var r,n,i,a,o;S(t.start,"options.start",[[Object,"{ x: number, y: number }"]]),S(t.end,"options.end",[[Object,"{ x: number, y: number }"]]),S(t.start.x,"options.start.x",["number"]),S(t.start.y,"options.start.y",["number"]),S(t.end.x,"options.end.x",["number"]),S(t.end.y,"options.end.y",["number"]),N(t.thickness,"options.thickness",["number"]),N(t.color,"options.color",[[Object,"Color"]]),N(t.dashArray,"options.dashArray",[Array]),N(t.dashPhase,"options.dashPhase",["number"]),nt(t.lineCap,"options.lineCap",vr),vt(t.opacity,"opacity.opacity",0,1),nt(t.blendMode,"options.blendMode",Bt);var s=this.maybeEmbedGraphicsState({borderOpacity:t.opacity,blendMode:t.blendMode});"color"in t||(t.color=de(0,0,0));var l=this.getContentStream();l.push.apply(l,l0({start:t.start,end:t.end,thickness:(r=t.thickness)!==null&&r!==void 0?r:1,color:(n=t.color)!==null&&n!==void 0?n:void 0,dashArray:(i=t.dashArray)!==null&&i!==void 0?i:void 0,dashPhase:(a=t.dashPhase)!==null&&a!==void 0?a:void 0,lineCap:(o=t.lineCap)!==null&&o!==void 0?o:void 0,graphicsState:s}))},e.prototype.drawRectangle=function(t){var r,n,i,a,o,s,l,c,u,h,f,d,v;t===void 0&&(t={}),N(t.x,"options.x",["number"]),N(t.y,"options.y",["number"]),N(t.width,"options.width",["number"]),N(t.height,"options.height",["number"]),N(t.rotate,"options.rotate",[[Object,"Rotation"]]),N(t.xSkew,"options.xSkew",[[Object,"Rotation"]]),N(t.ySkew,"options.ySkew",[[Object,"Rotation"]]),N(t.borderWidth,"options.borderWidth",["number"]),N(t.color,"options.color",[[Object,"Color"]]),vt(t.opacity,"opacity.opacity",0,1),N(t.borderColor,"options.borderColor",[[Object,"Color"]]),N(t.borderDashArray,"options.borderDashArray",[Array]),N(t.borderDashPhase,"options.borderDashPhase",["number"]),nt(t.borderLineCap,"options.borderLineCap",vr),vt(t.borderOpacity,"options.borderOpacity",0,1),nt(t.blendMode,"options.blendMode",Bt);var p=this.maybeEmbedGraphicsState({opacity:t.opacity,borderOpacity:t.borderOpacity,blendMode:t.blendMode});!("color"in t)&&!("borderColor"in t)&&(t.color=de(0,0,0));var m=this.getContentStream();m.push.apply(m,zr({x:(r=t.x)!==null&&r!==void 0?r:this.x,y:(n=t.y)!==null&&n!==void 0?n:this.y,width:(i=t.width)!==null&&i!==void 0?i:150,height:(a=t.height)!==null&&a!==void 0?a:100,rotate:(o=t.rotate)!==null&&o!==void 0?o:K(0),xSkew:(s=t.xSkew)!==null&&s!==void 0?s:K(0),ySkew:(l=t.ySkew)!==null&&l!==void 0?l:K(0),borderWidth:(c=t.borderWidth)!==null&&c!==void 0?c:0,color:(u=t.color)!==null&&u!==void 0?u:void 0,borderColor:(h=t.borderColor)!==null&&h!==void 0?h:void 0,borderDashArray:(f=t.borderDashArray)!==null&&f!==void 0?f:void 0,borderDashPhase:(d=t.borderDashPhase)!==null&&d!==void 0?d:void 0,graphicsState:p,borderLineCap:(v=t.borderLineCap)!==null&&v!==void 0?v:void 0}))},e.prototype.drawSquare=function(t){t===void 0&&(t={});var r=t.size;N(r,"size",["number"]),this.drawRectangle(Y(Y({},t),{width:r,height:r}))},e.prototype.drawEllipse=function(t){var r,n,i,a,o,s,l,c,u,h,f;t===void 0&&(t={}),N(t.x,"options.x",["number"]),N(t.y,"options.y",["number"]),N(t.xScale,"options.xScale",["number"]),N(t.yScale,"options.yScale",["number"]),N(t.rotate,"options.rotate",[[Object,"Rotation"]]),N(t.color,"options.color",[[Object,"Color"]]),vt(t.opacity,"opacity.opacity",0,1),N(t.borderColor,"options.borderColor",[[Object,"Color"]]),vt(t.borderOpacity,"options.borderOpacity",0,1),N(t.borderWidth,"options.borderWidth",["number"]),N(t.borderDashArray,"options.borderDashArray",[Array]),N(t.borderDashPhase,"options.borderDashPhase",["number"]),nt(t.borderLineCap,"options.borderLineCap",vr),nt(t.blendMode,"options.blendMode",Bt);var d=this.maybeEmbedGraphicsState({opacity:t.opacity,borderOpacity:t.borderOpacity,blendMode:t.blendMode});!("color"in t)&&!("borderColor"in t)&&(t.color=de(0,0,0));var v=this.getContentStream();v.push.apply(v,io({x:(r=t.x)!==null&&r!==void 0?r:this.x,y:(n=t.y)!==null&&n!==void 0?n:this.y,xScale:(i=t.xScale)!==null&&i!==void 0?i:100,yScale:(a=t.yScale)!==null&&a!==void 0?a:100,rotate:(o=t.rotate)!==null&&o!==void 0?o:void 0,color:(s=t.color)!==null&&s!==void 0?s:void 0,borderColor:(l=t.borderColor)!==null&&l!==void 0?l:void 0,borderWidth:(c=t.borderWidth)!==null&&c!==void 0?c:0,borderDashArray:(u=t.borderDashArray)!==null&&u!==void 0?u:void 0,borderDashPhase:(h=t.borderDashPhase)!==null&&h!==void 0?h:void 0,borderLineCap:(f=t.borderLineCap)!==null&&f!==void 0?f:void 0,graphicsState:d}))},e.prototype.drawCircle=function(t){t===void 0&&(t={});var r=t.size,n=r===void 0?100:r;N(n,"size",["number"]),this.drawEllipse(Y(Y({},t),{xScale:n,yScale:n}))},e.prototype.setOrEmbedFont=function(t){var r=this.font,n=this.fontKey;t?this.setFont(t):this.getFont();var i=this.font,a=this.fontKey;return{oldFont:r,oldFontKey:n,newFont:i,newFontKey:a}},e.prototype.getFont=function(){if(!this.font||!this.fontKey){var t=this.doc.embedStandardFont(Vr.Helvetica);this.setFont(t)}return[this.font,this.fontKey]},e.prototype.resetFont=function(){this.font=void 0,this.fontKey=void 0},e.prototype.getContentStream=function(t){return t===void 0&&(t=!0),t&&this.contentStream?this.contentStream:(this.contentStream=this.createContentStream(),this.contentStreamRef=this.doc.context.register(this.contentStream),this.node.addContentStream(this.contentStreamRef),this.contentStream)},e.prototype.createContentStream=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=this.doc.context.obj({}),i=Fn.of(n,t);return i},e.prototype.maybeEmbedGraphicsState=function(t){var r=t.opacity,n=t.borderOpacity,i=t.blendMode;if(!(r===void 0&&n===void 0&&i===void 0)){var a=this.doc.context.obj({Type:"ExtGState",ca:r,CA:n,BM:i}),o=this.node.newExtGState("GS",a);return o}},e.prototype.scaleAnnot=function(t,r,n){for(var i=["RD","CL","Vertices","QuadPoints","L","Rect"],a=0,o=i.length;a<o;a++){var s=t.lookup(g.of(i[a]));s instanceof fe&&s.scalePDFNumbers(r,n)}var l=t.lookup(g.of("InkList"));if(l instanceof fe)for(var a=0,o=l.size();a<o;a++){var c=l.lookup(a);c instanceof fe&&c.scalePDFNumbers(r,n)}},e.of=function(t,r,n){return new e(t,r,n)},e.create=function(t){S(t,"doc",[[_t,"PDFDocument"]]);var r=ve.of(-1),n=It.withContextAndParent(t.context,r),i=t.context.register(n);return new e(n,i,t)},e}(),Zi=function(e){M(t,e);function t(r,n,i){var a=e.call(this,r,n,i)||this;return S(r,"acroButton",[[Ci,"PDFAcroPushButton"]]),a.acroField=r,a}return t.prototype.setImage=function(r,n){n===void 0&&(n=Qt.Center);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a],l=this.createImageAppearanceStream(s,r,n);this.updateWidgetAppearances(s,{normal:l})}this.markAsClean()},t.prototype.setFontSize=function(r){hi(r,"fontSize"),this.acroField.setFontSize(r),this.markAsDirty()},t.prototype.addToPage=function(r,n,i){var a,o,s,l,c,u,h,f,d,v,p;N(r,"text",["string"]),N(n,"page",[[ut,"PDFPage"]]),Lr(i);var m=this.createWidget({x:((a=i==null?void 0:i.x)!==null&&a!==void 0?a:0)-((o=i==null?void 0:i.borderWidth)!==null&&o!==void 0?o:0)/2,y:((s=i==null?void 0:i.y)!==null&&s!==void 0?s:0)-((l=i==null?void 0:i.borderWidth)!==null&&l!==void 0?l:0)/2,width:(c=i==null?void 0:i.width)!==null&&c!==void 0?c:100,height:(u=i==null?void 0:i.height)!==null&&u!==void 0?u:50,textColor:(h=i==null?void 0:i.textColor)!==null&&h!==void 0?h:de(0,0,0),backgroundColor:(f=i==null?void 0:i.backgroundColor)!==null&&f!==void 0?f:de(.75,.75,.75),borderColor:i==null?void 0:i.borderColor,borderWidth:(d=i==null?void 0:i.borderWidth)!==null&&d!==void 0?d:0,rotate:(v=i==null?void 0:i.rotate)!==null&&v!==void 0?v:K(0),caption:r,hidden:i==null?void 0:i.hidden,page:n.ref}),b=this.doc.context.register(m.dict);this.acroField.addWidget(b);var k=(p=i==null?void 0:i.font)!==null&&p!==void 0?p:this.doc.getForm().getDefaultFont();this.updateWidgetAppearance(m,k),n.node.addAnnot(b)},t.prototype.needsAppearancesUpdate=function(){var r;if(this.isDirty())return!0;for(var n=this.acroField.getWidgets(),i=0,a=n.length;i<a;i++){var o=n[i],s=((r=o.getAppearances())===null||r===void 0?void 0:r.normal)instanceof Qe;if(!s)return!0}return!1},t.prototype.defaultUpdateAppearances=function(r){S(r,"font",[[$e,"PDFFont"]]),this.updateAppearances(r)},t.prototype.updateAppearances=function(r,n){S(r,"font",[[$e,"PDFFont"]]),N(n,"provider",[Function]);for(var i=this.acroField.getWidgets(),a=0,o=i.length;a<o;a++){var s=i[a];this.updateWidgetAppearance(s,r,n)}},t.prototype.updateWidgetAppearance=function(r,n,i){var a=i??I0,o=Ur(a(this,r,n));this.updateWidgetAppearanceWithFont(r,n,o)},t.of=function(r,n,i){return new t(r,n,i)},t}(br);const q0=({fileUrl:e,fileName:t})=>{const[r,n]=te.useState(null),[i,a]=te.useState(0),[o,s]=te.useState(1),[l,c]=te.useState(1),[u,h]=te.useState("SELECT"),[f,d]=te.useState(vo),[v,p]=te.useState(go),[m,b]=te.useState(po),[k,x]=te.useState(!1),[T,w]=te.useState(null),[F,A]=te.useState(null),[D,O]=te.useState(null),[B,E]=te.useState(null),[j,I]=te.useState("APPROVED"),{annotations:L,addAnnotation:z,deleteAnnotation:P,updateAnnotation:U,clearAnnotations:ue,undo:me,redo:We,canUndo:Oe,canRedo:Re}=Go(),kt=te.useRef(null),Ze=te.useRef([]);te.useEffect(()=>{(async()=>{try{const qe=await pdfjsLib.getDocument(e).promise;n(qe),a(qe.numPages),Ze.current=Array(qe.numPages).fill(null),s(1),ue()}catch(re){console.error("Error loading PDF:",re),alert("Failed to load PDF file.")}})()},[e,ue]);const Gr=be=>{var re;be>0&&be<=i&&(s(be),(re=Ze.current[be-1])==null||re.scrollIntoView({behavior:"smooth",block:"start"}))},er=te.useCallback(()=>{if(T)for(const be in L){const re=parseInt(be,10);if(L[re].some(qe=>qe.id===T)){P(re,T),w(null);break}}},[T,L,P]);te.useEffect(()=>{const be=re=>{(re.key==="Delete"||re.key==="Backspace")&&T&&(re.preventDefault(),er()),(re.ctrlKey||re.metaKey)&&re.key==="z"&&(re.preventDefault(),me()),(re.ctrlKey||re.metaKey)&&re.key==="y"&&(re.preventDefault(),We())};return window.addEventListener("keydown",be),()=>window.removeEventListener("keydown",be)},[T,er,me,We]);const mr=te.useCallback(async()=>{if(!r)return null;const be=await fetch(e).then(Xr=>Xr.arrayBuffer()),re=await _t.load(be),qe=await re.embedFont(Vr.Helvetica),Kr=await re.embedFont(Vr.HelveticaBold),je=re.getPages(),Hr={};for(const Xr in L){const xr=parseInt(Xr,10);if(xr<1||xr>je.length)continue;const G0=L[xr],Ct=je[xr-1],{width:K0,height:Ql}=Ct.getSize(),_l=(await r.getPage(xr)).getViewport({scale:1}),Ge=K0/_l.width,wr=Ql/_l.height;for(const q of G0){const tr=de(parseInt(q.color.slice(1,3),16)/255,parseInt(q.color.slice(3,5),16)/255,parseInt(q.color.slice(5,7),16)/255),gt=uo=>Ql-uo*wr;switch(q.type){case"PEN":case"UNDERLINE":case"STRIKETHROUGH":if(q.points.length>1){const Zr=q.points.map((Tt,rr)=>`${rr===0?"M":"L"} ${Tt.x*Ge} ${gt(Tt.y)}`).join(" ");Ct.drawSvgPath(Zr,{borderColor:tr,borderWidth:q.strokeWidth})}break;case"SQUIGGLY":if(q.points.length>1){let Zr=`M ${q.points[0].x*Ge} ${gt(q.points[0].y)}`;for(let Tt=1;Tt<q.points.length;Tt++){const rr=q.points[Tt];Zr+=` Q ${(rr.x-2.5)*Ge} ${gt(rr.y+(Tt%2===0?-1:1)*2)}, ${rr.x*Ge} ${gt(rr.y)}`}Ct.drawSvgPath(Zr,{borderColor:tr,borderWidth:q.strokeWidth})}break;case"HIGHLIGHTER":if(q.points.length>1){const Zr=q.points.map((Tt,rr)=>`${rr===0?"M":"L"} ${Tt.x*Ge} ${gt(Tt.y)}`).join(" ");Ct.drawSvgPath(Zr,{borderColor:tr,borderWidth:q.strokeWidth*5,opacity:.3,borderLineCap:vr.Round})}break;case"RECTANGLE":Ct.drawRectangle({x:q.x*Ge,y:gt(q.y+q.height),width:q.width*Ge,height:q.height*wr,borderColor:tr,borderWidth:q.strokeWidth});break;case"CIRCLE":Ct.drawEllipse({x:q.cx*Ge,y:gt(q.cy),xScale:q.rx*Ge,yScale:q.ry*wr,borderColor:tr,borderWidth:q.strokeWidth});break;case"TEXT":Ct.drawText(q.content,{x:q.x*Ge,y:gt(q.y+q.fontSize),size:q.fontSize*wr,font:qe,color:tr});break;case"STAMP":Ct.drawRectangle({x:q.x*Ge,y:gt(q.y+q.height),width:q.width*Ge,height:q.height*wr,borderColor:tr,borderWidth:2,borderOpacity:.8}),Ct.drawText(q.text,{x:(q.x+q.width/2)*Ge,y:gt(q.y+q.height/2+q.fontSize/3),font:Kr,size:q.fontSize*wr,color:tr,opacity:.8});break;case"SIGNATURE":case"INITIALS":Hr[q.imageData]||(Hr[q.imageData]=await re.embedPng(q.imageData));const uo=Hr[q.imageData];Ct.drawImage(uo,{x:q.x*Ge,y:gt(q.y+q.height),width:q.width*Ge,height:q.height*wr});break}}}return await re.save()},[r,e,L]),xe=te.useCallback(async be=>{x(!0);try{const re=await mr();if(!re){x(!1);return}const qe=new Blob([re],{type:"application/pdf"}),Kr=URL.createObjectURL(qe);if(be==="download"){const je=document.createElement("a");je.href=Kr,je.download=`${t.replace(".pdf","")}-annotated.pdf`,document.body.appendChild(je),je.click(),document.body.removeChild(je),URL.revokeObjectURL(Kr)}else{const je=document.createElement("iframe");je.style.display="none",je.src=Kr,document.body.appendChild(je),je.onload=()=>{setTimeout(()=>{var Hr,Xr;try{(Hr=je.contentWindow)==null||Hr.focus(),(Xr=je.contentWindow)==null||Xr.print()}catch(xr){console.error("Printing failed:",xr),alert("Could not print the document. Your browser might be blocking it.")}setTimeout(()=>{document.body.contains(je)&&(document.body.removeChild(je),URL.revokeObjectURL(Kr))},1e3)},1)}}}catch(re){console.error(`Failed to ${be} annotated PDF:`,re),alert(`An error occurred while preparing the PDF for ${be}.`)}finally{x(!1)}},[mr,t]),lo=()=>{if(!r)return null;const be=[];for(let re=1;re<=i;re++)be.push(C.jsx("div",{ref:qe=>{Ze.current[re-1]=qe},"data-page-number":re,children:C.jsx(Wo,{pdf:r,pageNumber:re,zoom:l,activeTool:u,toolColor:f,strokeWidth:v,fontSize:m,annotations:L[re]||[],addAnnotation:qe=>z(re,qe),deleteAnnotation:qe=>P(re,qe),updateAnnotation:U,selectedAnnotationId:T,setSelectedAnnotationId:w,signatureData:F,initialsData:D,activeStamp:j})},re));return be};return C.jsxs("div",{className:"flex flex-col h-screen w-full",children:[B&&C.jsx(qo,{title:B==="SIGNATURE"?"Create Signature":"Create Initials",onClose:()=>E(null),onSave:be=>{B==="SIGNATURE"?A(be):O(be)}}),C.jsx(zo,{fileName:t,currentPage:o,totalPages:i,zoom:l,setZoom:c,setCurrentPage:Gr,activeTool:u,setActiveTool:h,toolColor:f,setToolColor:d,strokeWidth:v,setStrokeWidth:p,fontSize:m,setFontSize:b,onDownload:()=>xe("download"),onPrint:()=>xe("print"),isProcessing:k,onDelete:er,selectedAnnotationId:T,undo:me,redo:We,canUndo:Oe,canRedo:Re,onSignatureClick:()=>E("SIGNATURE"),onInitialsClick:()=>E("INITIALS"),activeStamp:j,setActiveStamp:I}),C.jsx("div",{ref:kt,className:"flex-grow overflow-auto bg-gray-800 p-4",children:C.jsx("div",{id:"pdf-print-area",className:"mx-auto",children:r?lo():C.jsx("div",{className:"flex items-center justify-center h-full",children:C.jsx("p",{className:"text-xl",children:"Loading PDF..."})})})})]})};ne.AnnotationLayer=Uo,ne.CircleIcon=Fo,ne.DEFAULT_COLOR=vo,ne.DEFAULT_FONT_SIZE=po,ne.DEFAULT_STROKE_WIDTH=go,ne.DownloadIcon=Ao,ne.EraserIcon=ko,ne.FONT_SIZES=fo,ne.FreeTextIcon=wo,ne.HighlighterIcon=xo,ne.InitialsIcon=Bo,ne.PdfPage=Wo,ne.PdfViewer=q0,ne.PenIcon=mo,ne.PrintIcon=Do,ne.RectangleIcon=So,ne.RedoIcon=jo,ne.STAMPS=yo,ne.STROKE_WIDTHS=ho,ne.SelectIcon=bo,ne.SignatureIcon=No,ne.SignatureModal=qo,ne.SquigglyIcon=Ro,ne.StampIcon=Io,ne.StrikeoutIcon=Oo,ne.Toolbar=zo,ne.TrashIcon=Co,ne.UnderlineIcon=Eo,ne.UndoIcon=Mo,ne.UploadIcon=$l,ne.ZoomInIcon=To,ne.ZoomOutIcon=Po,ne.useAnnotationHistory=Go,Object.defineProperty(ne,Symbol.toStringTag,{value:"Module"})});
52
52
  //# sourceMappingURL=react-pdf-annotator.umd.js.map