@reportwright/pdf 0.1.0-beta.10 → 0.1.0-beta.11

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.
package/dist/write.js ADDED
@@ -0,0 +1,108 @@
1
+ var oa=Object.defineProperty;var l=(e,t)=>oa(e,"name",{value:t,configurable:!0});function an(e,t){return t?t.aborted?(e.catch(()=>{}),Promise.reject(t.reason)):new Promise((n,r)=>{let o=l(()=>r(t.reason),"on");t.addEventListener("abort",o,{once:!0}),e.then(s=>{t.removeEventListener("abort",o),n(s)},s=>{t.removeEventListener("abort",o),r(s)})}):e}l(an,"raced");function Xr(e,t){return new Promise((n,r)=>{let o=l(()=>{for(let c of t)e.off?.(c,s);e.off?.("error",i),e.off?.("close",a)},"off"),s=l(()=>{o(),n()},"done"),i=l(c=>{o(),r(c)},"onError"),a=l(()=>{o(),r(Object.assign(new Error("The sink closed before the PDF was written"),{code:"ERR_STREAM_PREMATURE_CLOSE"}))},"onClose");for(let c of t)e.once(c,s);e.once("error",i),e.once("close",a)})}l(Xr,"nodeWait");function Gr(e){if(!e||typeof e.write!="function"&&typeof e.getWriter!="function")throw new TypeError("createPdf: the sink must be a Node Writable, a WritableStream or an object with write(bytes)");if(typeof e.getWriter=="function"){let t=e.getWriter();return{async write(n){await t.ready,await t.write(n)},close:l(()=>t.close().finally(()=>t.releaseLock()),"close"),abort:l(n=>{t.abort(n).catch(()=>{}),t.releaseLock()},"abort")}}if(typeof e.once=="function"&&typeof e.end=="function"){let t=null,n=l(s=>{t??=s},"onError");e.on("error",n);let r=l(()=>e.off?.("error",n),"off"),o=l(()=>t||e.errored||(e.destroyed||e.writableEnded)&&Object.assign(new Error("The sink closed before the PDF was written"),{code:"ERR_STREAM_PREMATURE_CLOSE"}),"dead");return{write:l(s=>{let i=o();return i?Promise.reject(i):e.write(s)===!1?Xr(e,["drain"]):Promise.resolve()},"write"),close:l(()=>{let s=o();if(s)return r(),Promise.reject(s);let i=Xr(e,["finish"]);return e.end(),i.finally(r)},"close"),abort:r}}return{write:l(async t=>{await e.write(t)},"write"),close:l(async()=>{await e.close?.()},"close"),abort:l(()=>{},"abort")}}l(Gr,"openSink");var F=l(e=>{if(typeof e!="number"||!(Math.abs(e)<1e9))throw new RangeError(`Not a usable number: ${e}`);let t=Math.round(e*1e3)/1e3;return t===0?"0":String(t)},"num"),zn=l(e=>e.toString(16).padStart(4,"0"),"hex4"),_n=l(e=>{let t="";for(let n=0;n<e.length;n++)t+=zn(e.charCodeAt(n));return t},"utf16"),q=l(e=>`<feff${_n(String(e??""))}>`,"text"),ke=l(e=>{let t=String(e).replace(/[^\x21-\x7e]/g,r=>encodeURIComponent(r)),n="<";for(let r=0;r<t.length;r++)n+=t.charCodeAt(r).toString(16).padStart(2,"0");return`${n}>`},"ascii"),pe=l((e,t="X")=>{let n="",r=0;for(let o of String(e??"")){let s=sa.encode(o);if(r+s.length>127)break;r+=s.length;for(let i of s)n+=i===0?"":i<33||i>126||ia.has(i)?`#${i.toString(16).toUpperCase().padStart(2,"0")}`:String.fromCharCode(i)}return`/${n||t}`},"pdfName"),sa=new TextEncoder,ia=new Set([..."()<>[]{}/%#"].map(e=>e.charCodeAt(0))),cn=l((e,t="Font")=>`/${String(e??"").replace(/[^A-Za-z0-9_.+-]/g,"-").slice(0,63)||t}`,"fontName"),ht=l(e=>ke(`D:${e.toISOString().replace(/\D/g,"").slice(0,14)}+00'00'`),"pdfDate");function $e(e){let t=globalThis.Buffer;if(t)return t.from(e,"latin1");let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}l($e,"latin1");var bt=l(e=>e===40||e===41||e===92?"\\"+String.fromCharCode(e):e===13?"\\r":String.fromCharCode(e),"esc");var Xn=new Map;function Re(e){return Xn.has(e)||Xn.set(e,globalThis.process?.getBuiltinModule?.(e)),Xn.get(e)}l(Re,"builtin");var Wr=null;async function qe(){return Wr??=await import("./fflate.js")}l(qe,"fflate");var Gn=l(()=>Wr,"fflateNow");var ln=l(()=>Re("node:zlib"),"nodeZlib"),aa=32*1024,ca=0,Lt={free:4,wait:[]};async function et(e,t=6){if(ln()&&e.length<=aa)return++ca%8===0&&await new Promise(n=>(globalThis.setImmediate??setTimeout)(n)),new Uint8Array(ln().deflateSync(e,{level:t}));Lt.free>0?Lt.free--:await new Promise(n=>Lt.wait.push(n));try{return await la(e,t)}finally{let n=Lt.wait.shift();n?n():Lt.free++}}l(et,"deflate");async function la(e,t){let n=ln();return n?new Promise((r,o)=>n.deflate(e,{level:t},(s,i)=>s?o(s):r(i))):typeof CompressionStream>"u"||t!==6?(await qe()).zlibSync(e,{level:t}):new Uint8Array(await new Response(new Blob([e]).stream().pipeThrough(new CompressionStream("deflate"))).arrayBuffer())}l(la,"now");function Vr(e=6){let t=[],n=l(()=>{let a=0;for(let f of t)a+=f.length;let c=new Uint8Array(a);a=0;for(let f of t)c.set(f,a),a+=f.length;return c},"join"),r=ln();if(r){let a=r.createDeflate({level:e,chunkSize:1048576}),c=new Promise((f,h)=>{a.on("data",u=>t.push(u)),a.on("end",f),a.on("error",h)});return c.catch(()=>{}),{push:l(f=>Promise.race([new Promise((h,u)=>a.write(f,p=>p?u(p):h(void 0))),c]).then(()=>{}),"push"),async end(){return a.end(),await c,n()},abort(){a.destroy()}}}if(typeof CompressionStream>"u")return{async push(a){t.push(a.slice())},async end(){return(await qe()).zlibSync(n(),{level:e})},abort(){}};if(e!==6)return{async push(a){t.push(a.slice())},async end(){return(await qe()).zlibSync(n(),{level:e})},abort(){}};let o=new CompressionStream("deflate"),s=o.writable.getWriter(),i=new Response(o.readable).arrayBuffer();return i.catch(()=>{}),{async push(a){await s.ready,await s.write(a)},async end(){return await s.close(),new Uint8Array(await i)},abort(){s.abort().catch(()=>{})}}}l(Vr,"deflateStream");var qr=64*1024,fa=100,Wn=14,Ce=1<<Wn,fn=`/ByteRange [0 ${"0".repeat(10)} ${"0".repeat(10)} ${"0".repeat(10)}]`;function Jr(e,t){let n=0,r=0,o=[],s=new Map,i=0,a=l((O,R,x,b=0)=>{let E=o[O>>>Wn];if(E instanceof Uint8Array){s.set(O,R*2**48+x*2**16+b);return}let C=O&Ce-1;E.kind[C]=R,E.loc[C]=x,E.idx[C]=b},"place"),c=l(O=>{let R=Re("node:zlib");return R?new Uint8Array(R.deflateSync(O,{level:1})):Gn()?.deflateSync(O,{level:1})??null},"pack"),f=l(O=>{let R=Re("node:zlib");return R?new Uint8Array(R.inflateSync(O)):Gn().inflateSync(O)},"unpack");Re("node:zlib")||qe().catch(()=>{});let h=l(O=>({kind:new Uint8Array(O),loc:new Uint32Array(O),idx:new Uint16Array(O)}),"block"),u=l(()=>{let O=r++;if(O&&O<Ce&&O>=o[0].kind.length){let R=o[0],x=h(R.kind.length*2);x.kind.set(R.kind),x.loc.set(R.loc),x.idx.set(R.idx),o[0]=x}if(!(O&Ce-1)){o.push(h(O?Ce:64));let R=o.length-3,x=o[R];if(R>0&&!(x instanceof Uint8Array)){let b=new Uint8Array(Ce*7);b.set(x.kind),b.set(new Uint8Array(x.loc.buffer),Ce),b.set(new Uint8Array(x.idx.buffer),Ce*5);let E=c(b);if(E){for(let C=0;C<Ce;C++)x.kind[C]!==1&&x.kind[C]!==2&&s.set(R*Ce+C,x.kind[C]*2**48);i+=(o[R]=E).length}}}return O},"reserve"),p=[-1,null],m=l(O=>{let R=s.get(O);if(R!==void 0)return[Math.floor(R/2**48),Math.floor(R/2**16)%2**32,R%2**16];let x=O>>>Wn,b=O&Ce-1,E=o[x];if(E instanceof Uint8Array&&p[0]!==x){let v=f(E);p=[x,{kind:v.subarray(0,Ce),loc:new Uint32Array(v.buffer,v.byteOffset+Ce,Ce),idx:new Uint16Array(v.buffer,v.byteOffset+Ce*5,Ce)}]}let C=E instanceof Uint8Array?p[1]:E;return[C.kind[b],C.loc[b],C.idx[b]]},"where");u();let d=[],g=0,w=t.hash||null,y=new Uint32Array([2166136261,16777619,3421674724,2216829733]),$=l(O=>{let R=y[0],x=y[1],b=y[2],E=y[3];for(let C=0;C<O.length;C++){let v=O[C];R=Math.imul(R^v,16777619),x=Math.imul(x^v,16777619)+R,b=Math.imul(b^v,16777619)^x,E=Math.imul(E^v,16777619)+b}y[0]=R,y[1]=x,y[2]=b,y[3]=E},"hash"),A=l(async()=>{if(!g)return;let O=new Uint8Array(g),R=0;for(let x of d)O.set(x,R),R+=x.length;d=[],g=0,t.encrypt?.id||$(O),w?.update(O),await an(e.write(O),t.signal)},"flush"),D=l(O=>{let R=typeof O=="string"?$e(O):g+O.length>=qr?O:O.slice();return d.push(R),g+=R.length,n+=R.length,g>=qr?A():void 0},"put"),N=[],M=l(async()=>{if(!N.length)return;let O=N;N=[];let R=u(),x="",b="";O.forEach(([C,v],L)=>{x+=`${C} ${b.length} `,b+=`${v}
2
+ `,a(C,2,R,L)});let E=$e(x+b);await j(R,`<< /Type /ObjStm /N ${O.length} /First ${x.length}${t.compress?" /Filter /FlateDecode":""} >>`,t.compress?await et(E,t.objectStreamLevel??6):E)},"writeBatch"),j=l(async(O,R,x)=>{let b=t.encrypt;if(x&&b?.stream){let E=b.stream(O,x,R);x=E instanceof Uint8Array?E:await E}if(b?.dict){let E=b.dict(O,R);R=typeof E=="string"?E:await E}if(a(O,1,n),!x){await D(`${O} 0 obj
3
+ ${R}
4
+ endobj
5
+ `);return}await D(`${O} 0 obj
6
+ ${R.replace(/>>\s*$/,`/Length ${x.length} >>`)}
7
+ stream
8
+ `),await D(x),await D(`
9
+ endstream
10
+ endobj
11
+ `)},"writeDirect");return D(`%PDF-${t.classic?"1.4":"1.7"}
12
+ %âãÏÓ
13
+ `),{get pos(){return n},get xrefBytes(){return o.reduce((O,R)=>O+(R instanceof Uint8Array?0:R.kind.length*7),i+s.size*40)},reserve:u,write(O,R,x){return x||t.classic||R.length>4096||O===t.encrypt?.ref?j(O,R,x):(N.push([O,R]),a(O,3,0),N.length>=fa?M():void 0)},async writeBig(O,R,x,b){if(t.encrypt?.dict){let E=R;for(let C of x)E+=C;return j(O,E+b)}a(O,1,n),await D(`${O} 0 obj
14
+ ${R}`);for(let E of x)await D(E);await D(`${b}
15
+ endobj
16
+ `)},async finish(O){let R=O.last;for(let S=1;S<r;S++)!m(S)[0]&&S!==R?.n&&await this.write(S,"null");await M(),await A();let x=t.encrypt?.id||O.id||[...y].map(S=>S.toString(16).padStart(8,"0")).join(""),b=t.classic?0:u(),E=r,C=null;if(R){a(R.n,1,n);let S=t.encrypt?.dict?await t.encrypt.dict(R.n,R.after):R.after;C={head:`${R.n} 0 obj
17
+ ${R.head}`,rest:`${S}
18
+ endobj
19
+ `}}let v=C?n+C.head.length+2*R.size+2+C.rest.length:n,L=`/Root ${O.root} 0 R /Info ${O.info} 0 R /ID [<${x}> <${x}>]${t.encrypt?.trailer||""}`,H=[];if(t.classic){H.push($e(`xref
20
+ 0 ${E}
21
+ `));for(let S=0;S<E;S+=65536){let P="";for(let U=S;U<Math.min(E,S+65536);U++){if(U===0){P+=`0000000000 65535 f\r
22
+ `;continue}let[I,_]=m(U);if(I!==1)throw new Error(`internal: object ${U} is not written directly in a classic xref`);P+=`${String(_).padStart(10,"0")} 00000 n\r
23
+ `}H.push($e(P))}H.push($e(`trailer
24
+ << /Size ${E} ${L} >>
25
+ startxref
26
+ ${v}
27
+ %%EOF
28
+ `))}else{a(b,1,v);let S=new Uint8Array(E*8),P=new Uint8Array(7),U=new Uint8Array(7);for(let _=0;_<E;_++){if(U.fill(0),_===0)U[5]=255,U[6]=255;else{let[X,T,k]=m(_);U[0]=X,U[1]=T>>>24&255,U[2]=T>>>16&255,U[3]=T>>>8&255,U[4]=T&255,X===2&&(U[5]=k>>8,U[6]=k&255)}let Y=_*8;S[Y]=2;for(let X=0;X<7;X++)S[Y+1+X]=U[X]-P[X]&255,P[X]=U[X]}let I=t.objectStreamLevel!=null?await et(S,t.objectStreamLevel):(await qe()).zlibSync(S,{level:6});H.push($e(`${b} 0 obj
29
+ << /Type /XRef /Size ${E} /W [1 4 2] /DecodeParms << /Columns 7 /Predictor 12 >> ${L} /Filter /FlateDecode /Length ${I.length} >>
30
+ stream
31
+ `),I,$e(`
32
+ endstream
33
+ endobj
34
+ startxref
35
+ ${v}
36
+ %%EOF
37
+ `))}if(C&&R){let S=w;if(!S)throw new Error("internal: a signature without its digest");w=null;let P=n+C.head.length,U=P+2*R.size+2,I=[$e(C.rest),...H],_=0;for(let B of I)_+=B.length;let Y=`/ByteRange [0 ${P} ${U} ${_}]`,X=C.head.replace(fn,Y.padEnd(fn.length));if(X.length!==C.head.length)throw new Error("internal: the /ByteRange does not fit its placeholder");S.update($e(X));for(let B of I)S.update(B);let T=await R.sign(await S.digest());if(T.length>R.size)throw new RangeError(`sign: the signature (CMS, ${T.length} bytes) is larger than the space reserved for it (${R.size} bytes): pass a larger reserve`);let k="";for(let B of T)k+=B.toString(16).padStart(2,"0");await D(`${X}<${k.padEnd(2*R.size,"0")}>`);for(let B of I)await D(B);return await A(),{bytes:n,objects:E}}for(let S of H)await D(S);return await A(),{bytes:n,objects:E}}}}l(Jr,"createObjects");var Bt="@reportwright/pdf",He=l(e=>String(e).replace(/[\0-\x08\x0b\x0c\x0e-\x1f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g,"").replace(/[<>&"']/g,t=>({"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&apos;"})[t]),"xml"),Kr=/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;function ha(e){if(!Kr.test(e.prefix))throw new TypeError(`XMP: the schema prefix ${JSON.stringify(e.prefix)} is not an XML name`);if(typeof e.ns!="string"||!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"'&]{1,256}$/.test(e.ns))throw new TypeError(`XMP: the namespace ${JSON.stringify(e.ns)} is not a URI`);if(e.props.length>64)throw new RangeError("XMP: at most 64 properties a schema");for(let t of e.props){if(!Kr.test(t.name))throw new TypeError(`XMP: the property name ${JSON.stringify(t.name)} is not an XML name`);if(t.type!=="Text"&&t.type!=="Integer")throw new TypeError("XMP: a property is Text or Integer");if(t.category!=="internal"&&t.category!=="external")throw new TypeError("XMP: a property is internal or external")}}l(ha,"checkExt");var ua={schema:"PDF/UA identification schema",ns:"http://www.aiim.org/pdfua/ns/id/",prefix:"pdfuaid",props:[{name:"part",type:"Integer",category:"internal",description:"PDF/UA version identifier",value:1}]};function Zr({title:e,author:t,subject:n,keywords:r,stamp:o,pdfa:s=null,ua:i=!1,extensions:a=[]}){let c=[...i?[ua]:[],...a];c.forEach(ha);let f=`${e!=null?`<dc:title><rdf:Alt><rdf:li xml:lang="x-default">${He(e)}</rdf:li></rdf:Alt></dc:title>`:""}${t!=null?`<dc:creator><rdf:Seq><rdf:li>${He(t)}</rdf:li></rdf:Seq></dc:creator>`:""}${n!=null?`<dc:description><rdf:Alt><rdf:li xml:lang="x-default">${He(n)}</rdf:li></rdf:Alt></dc:description>`:""}`,h=c.map(p=>`<rdf:Description rdf:about="" xmlns:${p.prefix}="${He(p.ns)}">${p.props.filter(m=>m.value!=null).map(m=>`<${p.prefix}:${m.name}>${He(m.value)}</${p.prefix}:${m.name}>`).join("")}</rdf:Description>
38
+ `).join(""),u=s&&c.length?`<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#"><pdfaExtension:schemas><rdf:Bag>${c.map(p=>`<rdf:li rdf:parseType="Resource"><pdfaSchema:schema>${He(p.schema)}</pdfaSchema:schema><pdfaSchema:namespaceURI>${He(p.ns)}</pdfaSchema:namespaceURI><pdfaSchema:prefix>${p.prefix}</pdfaSchema:prefix><pdfaSchema:property><rdf:Seq>${p.props.map(m=>`<rdf:li rdf:parseType="Resource"><pdfaProperty:name>${m.name}</pdfaProperty:name><pdfaProperty:valueType>${m.type}</pdfaProperty:valueType><pdfaProperty:category>${m.category}</pdfaProperty:category><pdfaProperty:description>${He(m.description)}</pdfaProperty:description></rdf:li>`).join("")}</rdf:Seq></pdfaSchema:property></rdf:li>`).join("")}</rdf:Bag></pdfaExtension:schemas></rdf:Description>
39
+ `:"";return`<?xpacket begin="\uFEFF" id="W5M0MpCehiHzreSzNTczkc9d"?>
40
+ <x:xmpmeta xmlns:x="adobe:ns:meta/">
41
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
42
+ ${s?`<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/"><pdfaid:part>${Number(s.part)}</pdfaid:part><pdfaid:conformance>${He(s.conformance.toUpperCase())}</pdfaid:conformance></rdf:Description>
43
+ `:""}${h}${u}<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:format>application/pdf</dc:format>${f}</rdf:Description>
44
+ <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/"><xmp:CreatorTool>${Bt}</xmp:CreatorTool><xmp:CreateDate>${o}</xmp:CreateDate><xmp:ModifyDate>${o}</xmp:ModifyDate><xmp:MetadataDate>${o}</xmp:MetadataDate></rdf:Description>
45
+ <rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/"><pdf:Producer>${Bt}</pdf:Producer>${r!=null?`<pdf:Keywords>${He(r)}</pdf:Keywords>`:""}</rdf:Description>
46
+ </rdf:RDF>
47
+ </x:xmpmeta>
48
+ <?xpacket end="w"?>`}l(Zr,"xmpPacket");var un=new WeakMap;function ye(e,t,n,r){return un.set(e,{kind:t,doc:n,data:r}),e}l(ye,"brand");var ze=l(e=>e!==null&&typeof e=="object"?un.get(e)?.kind:void 0,"kindOf");function he(e,t,n,r){let o=e!==null&&typeof e=="object"?un.get(e):void 0;if(!o||o.kind!==t)throw new TypeError(`Not ${/^[aeiou]/i.test(r)?"an":"a"} ${r} made by this library`);if(o.doc!==n)throw new TypeError(`That ${r} belongs to another PDF`);return o.data}l(he,"unbrand");var hn=16e6;function At(e){let t=0,n=null,r=l(o=>{if(o===null||typeof o!="object"||un.has(o))return o;let s=Array.isArray(o);if(!s&&!pa(o)){if(o instanceof Date)try{return new Date(Date.prototype.getTime.call(o))}catch{throw new TypeError("A date is not a real Date")}return o}n??=new Map;let i=n.get(o);if(i)return i;if(s){let f=o.length;if((t+=f)>hn)throw new RangeError(`An argument has more than ${hn} values`);let h=new Array(f);n.set(o,h);for(let u=0;u<f;u++)h[u]=r(o[u]);return h}let a=Object.keys(o);if((t+=a.length)>hn)throw new RangeError(`An argument has more than ${hn} values`);let c={};n.set(o,c);for(let f of a){let h=r(o[f]);f==="__proto__"?Object.defineProperty(c,f,{value:h,enumerable:!0,writable:!0,configurable:!0}):c[f]=h}return c},"copy");return r(e)}l(At,"snapshot");function pa(e){for(let t=Object.getPrototypeOf(e);t!==null&&t!==Object.prototype;t=Object.getPrototypeOf(t))if(Object.hasOwn(t,"constructor"))return!1;return!0}l(pa,"plain");function pn(e){for(let[t,n]of Object.entries(e))typeof n=="function"&&(e[t]=(...r)=>n.apply(e,r.map(At)));return e}l(pn,"guarded");var Je=64,da=8;function Yr(e,t){let n=t.pdfaLevel??(t.pdfa?{part:2,conformance:"b",unicode:!1}:null),r=Jr(e,{compress:t.compress,objectStreamLevel:t.objectStreamLevel,signal:t.signal,encrypt:t.encrypt,hash:t.hash,classic:n?.part===1}),o=new Map,s=new Map,i=[],a=[],c=new Set,f=[],h=[],u=[],p=new Set,m=[],d=[],g=r.reserve(),w=!1,y=Promise.resolve(),$=null;async function A(){let M=m.shift(),j=he(M,"page",N,"page"),O=N.pageRef(j),R=await M.z;M.z=null;let x=M.own&&!M.content.s?0:r.reserve();x&&await r.write(x,t.compress?"<< /Filter /FlateDecode >>":"<< >>",R);for(let C of M.writers)await C(M);let b=[];for(let C of M.annots){let v=C.make(C.ref,!1);v===void 0?d.push(C):await r.write(C.ref,v),b.push(`${C.ref} 0 R`)}let E="";for(let[C,v]of M.entries)E+=` ${pe(C)} ${v}`;M.own?await r.write(O,await M.own(u[Math.floor(j/Je)],x,b)):await r.write(O,`<< /Type /Page /Parent ${u[Math.floor(j/Je)]} 0 R /MediaBox [0 0 ${F(M.width)} ${F(M.height)}] /Resources ${g} 0 R /Contents ${x} 0 R${b.length?` /Annots [${b.join(" ")}]`:""}${E} >>`),M.annots=[],M.writers=[],M.entries=new Map,M.content=null}l(A,"writeNext");async function D(M){for(let j of M)await r.write(j.ref,`<< /Type /Pages${j.parent?` /Parent ${j.parent} 0 R`:""} /Kids [${j.kids.map(O=>`${O} 0 R`).join(" ")}] /Count ${j.count} >>`)}l(D,"writeNodes");let N={compress:t.compress,pdfa:t.pdfa,pdfaLevel:n,tagged:t.tagged,xmpExtensions:[],signal:t.signal,xmp:null,info:null,signing:!!t.hash,sigFlags:0,last:null,tags:null,resourcesRef:g,reserve:l(()=>r.reserve(),"reserve"),write:l((M,j,O)=>r.write(M,j,O),"write"),async writeStream(M,j,O){return t.compress?r.write(M,j.replace(/>>\s*$/,"/Filter /FlateDecode >>"),await et(O)):r.write(M,j,O)},writeBig:l((M,j,O,R)=>r.writeBig(M,j,O,R),"writeBig"),async object(M,j){let O=r.reserve();return await r.write(O,M,j),O},resource(M,j,O){let R=o.get(M);R||o.set(M,R=new Map);let x=R.get(j);return x||R.set(j,x=pe(O||`${M==="ExtGState"?"GS":M==="Properties"?"MC":M[0]}${R.size+1}`).slice(1)),x},imageResource(M){let j=he(M,"image",N,"image (pdf.embedImage)");return{name:N.resource("XObject",`${j.ref} 0 R`),ref:j.ref,alpha:j.alpha,orientation:[...j.orient]}},catalog(M,j){s.set(M,j)},onFinish(M){if(w)throw new Error("The PDF has ended");i.push(M)},addFont(M){a.push(M)},pageRef:l(M=>f[M]??=r.reserve(),"pageRef"),pageHeight:l(M=>h[M],"pageHeight"),get pageCount(){return h.length},warn(M){c.size<1e3&&c.add(M)},serial(M){let j=y.then(()=>{if($)throw $;return M()});return y=j.catch(O=>{$??=O}),j},get failed(){return $},newPage(M){if(w)throw new Error("The PDF has ended");let j=h.length;return h.push(M.height),j%Je===0&&u.push(r.reserve()),j},opened(M){p.add(M)},queuePage(M){p.delete(M);let j=$e(M.content.end());return M.z=t.compress&&!(M.own&&!M.content.s)?et(j):Promise.resolve(j),M.z.catch(()=>{}),m.push(M),N.serial(async()=>{for(;m.length>da;)await A()})},async finish(M){if(w)throw new Error("The PDF has ended");for(let j of[...p].sort((O,R)=>O.index-R.index))j.end();return h.length||M().end(),N.serial(async()=>{for(;m.length;)await A();for(let P of d)await r.write(P.ref,P.make(P.ref,!0));for(let P=0;P<i.length;P++)await i[P]();w=!0;for(let P of a)await P.write(),P.missing.size&&c.add(`${P.key} has no glyph for ${[...P.missing].map(U=>JSON.stringify(U)).join(", ")}${P.missing.size>=100?"…":""}`);let j="<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]";for(let[P,U]of o)j+=` ${pe(P)} << ${[...U].map(([I,_])=>`/${_} ${I}`).join(" ")} >>`;await r.write(g,j+" >>");let O=h.length,R=u.map((P,U)=>({ref:P,kids:f.slice(U*Je,Math.min(O,(U+1)*Je)),count:Math.min(Je,O-U*Je)}));for(;R.length>1;){let P=[];for(let U=0;U<R.length;U+=Je){let I=R.slice(U,U+Je);P.push({ref:r.reserve(),kids:I.map(_=>_.ref),count:I.reduce((_,Y)=>_+Y.count,0),below:I})}for(let U of P)for(let I of U.below)I.parent=U.ref;await D(R),R=P}await D(R);let x=t.info,b=x.creationDate,E=t.metadata===!1?null:N.xmp??new TextEncoder().encode(Zr({title:x.title,author:x.author,subject:x.subject,keywords:x.keywords,stamp:b.toISOString().replace(/\.\d+Z$/,"Z"),pdfa:N.pdfaLevel,ua:t.tagged,extensions:N.xmpExtensions})),C=E?r.reserve():0;E&&await r.write(C,"<< /Type /Metadata /Subtype /XML >>",E);let v=r.reserve();N.info!=null?await r.write(v,N.info):await r.write(v,`<< /Producer ${q(Bt)} /Creator ${q(Bt)}${x.title!=null?` /Title ${q(x.title)}`:""}${x.author!=null?` /Author ${q(x.author)}`:""}${x.subject!=null?` /Subject ${q(x.subject)}`:""}${x.keywords!=null?` /Keywords ${q(x.keywords)}`:""} /CreationDate ${ht(b)} /ModDate ${ht(b)} >>`);let L=r.reserve(),H=`<< /Type /Catalog /Pages ${R[0].ref} 0 R${C?` /Metadata ${C} 0 R`:""}`;for(let[P,U]of s)H+=` ${pe(P)} ${U}`;await r.write(L,H+" >>");let S=await r.finish({root:L,info:v,id:t.id,last:N.last});return{pages:O,bytes:S.bytes,warnings:[...c]}})}};return N}l(Yr,"createDoc");var tt=class{static{l(this,"Content")}constructor(){this.s="",this.bt=!1,this.tx=0,this.ty=0,this.st={fill:"0 g",stroke:"0 G",lw:1,dash:"[] 0",font:"",size:0,Tc:0,Tw:0,Tz:100,Ts:0,Tr:0},this.saved=[],this.marker=null,this.mc=null}draw(){let t=this.marker;if(!t)return;let n=t.current();n!==this.mc&&(this.closeMarked(),this.et(),this.s+=t.open(n),this.mc=n)}closeMarked(){this.mc!==null&&(this.et(),this.s+=`EMC
49
+ `,this.mc=null)}et(){this.bt&&(this.s+=`ET
50
+ `,this.bt=!1)}op(t){this.draw(),this.et(),this.s+=t.endsWith(`
51
+ `)?t:t+`
52
+ `}q(){this.draw(),this.et(),this.s+=`q
53
+ `,this.saved.push({...this.st})}Q(){this.et(),this.s+=`Q
54
+ `,this.st=this.saved.pop()||this.st}fill(t){t!==this.st.fill&&(this.s+=`${t}
55
+ `,this.st.fill=t)}stroke(t){t!==this.st.stroke&&(this.s+=`${t}
56
+ `,this.st.stroke=t)}lineWidth(t){t!==this.st.lw&&(this.s+=`${F(t)} w
57
+ `,this.st.lw=t)}dash(t){let n=`[${(t||[]).map(F).join(" ")}] 0`;n!==this.st.dash&&(this.s+=`${n} d
58
+ `,this.st.dash=n)}text(t,n,r,o,s){this.run(t,n,r,o,`(${s}) Tj
59
+ `)}run(t,n,r,o,s,i={}){this.draw(),this.bt||(this.s+=`BT
60
+ `,this.bt=!0,this.tx=0,this.ty=0);let a=this.st,{Tc:c=0,Tw:f=0,Tz:h=100,Ts:u=0,Tr:p=0}=i;c!==a.Tc&&(this.s+=`${F(c)} Tc
61
+ `,a.Tc=c),f!==a.Tw&&(this.s+=`${F(f)} Tw
62
+ `,a.Tw=f),h!==a.Tz&&(this.s+=`${F(h)} Tz
63
+ `,a.Tz=h),u!==a.Ts&&(this.s+=`${F(u)} Ts
64
+ `,a.Ts=u),p!==a.Tr&&(this.s+=`${F(p)} Tr
65
+ `,a.Tr=p),(t!==this.st.font||n!==this.st.size)&&(this.s+=`${pe(t)} ${F(n)} Tf
66
+ `,this.st.font=t,this.st.size=n);let m=Math.round(Number(F(r))*100),d=Math.round(Number(F(o))*100);this.s+=`${(m-this.tx)/100} ${(d-this.ty)/100} Td ${s}`,this.tx=m,this.ty=d}end(){for(this.closeMarked(),this.et();this.saved.length;)this.Q();return this.s}};var ga=new Map([["GRAY",1],["RGB ",3],["CMYK",4]]);function dn(e,t){let n=qn(e,t),r=l(f=>new TypeError(`${t}: not a usable ICC profile (${f})`),"bad");if(n.length<132)throw r(`${n.length} bytes; a profile has at least 132`);if(n.length>33554432)throw r("over 32 MB");let o=new DataView(n.buffer,n.byteOffset,n.byteLength),s=o.getUint32(0);if(s!==n.length)throw r(`its header says ${s} bytes, but ${n.length} were given`);if(Vn(n,36)!=="acsp")throw r("no 'acsp' signature");if(n[8]<2||n[8]>4)throw r(`version ${n[8]}; PDF takes ICC versions 2 to 4`);let i=Vn(n,16),a=ga.get(i);if(!a)throw r(`colour space ${JSON.stringify(i.trim())}; gray, RGB and CMYK are supported`);let c=o.getUint32(128);if(c>(s-132)/12)throw r(`${c} tags do not fit in ${s} bytes`);for(let f=0;f<c;f++){let h=o.getUint32(132+12*f+4),u=o.getUint32(132+12*f+8);if(h+u>s)throw r(`tag ${f} lies outside the profile`)}return{bytes:n,n:a,space:i.trim(),cls:Vn(n,12)}}l(dn,"parseIcc");var Vn=l((e,t)=>String.fromCharCode(e[t],e[t+1],e[t+2],e[t+3]),"tag");function qn(e,t){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new TypeError(`${t}: bytes are a Uint8Array or an ArrayBuffer`)}l(qn,"toBytes");var be={1:"/DeviceGray",3:"/DeviceRGB",4:"/DeviceCMYK"},xt=l(e=>typeof e=="number"&&e>=0&&e<=1,"unit"),ma=/^rgb\(\s*(\d{1,3}(?:\.\d+)?%?)\s*(?:,\s*|\s+)(\d{1,3}(?:\.\d+)?%?)\s*(?:,\s*|\s+)(\d{1,3}(?:\.\d+)?%?)\s*\)$/i;function wa(e,t,n,r){let o=[e,t,n,r];if(!o.every(xt))throw new RangeError(`cmyk(c, m, y, k): each is 0–1, not ${o.join(", ")}`);return Object.freeze(o)}l(wa,"cmyk");var eo=l(e=>e?.base??e,"base");function nt(e,t){let n=eo(e);if(!n?.pdfa)return;let r=n.outputIntent??"RGB";if(t===be[4]&&r!=="CMYK")throw new TypeError("PDF/A: CMYK colour (DeviceCMYK) needs a CMYK output intent: createPdf(sink, { pdfa: { outputIntent: cmykProfileBytes } }). Or use RGB, an ICC-based colour, or a spot colour with an RGB alternate");if(t===be[3]&&r==="CMYK")throw new TypeError("PDF/A: with a CMYK output intent, RGB colour (DeviceRGB) is not allowed; use CMYK, gray, an ICC-based colour or a spot colour with a CMYK alternate")}l(nt,"checkDevice");function _e(e){if(typeof e=="number"){if(!xt(e))throw new RangeError(`A gray level is 0–1, not ${e}`);return{cs:be[1],comps:[e]}}if(Array.isArray(e)&&(e.length===3||e.length===4)&&e.every(xt))return{cs:be[e.length],comps:[...e]};if(typeof e=="string"&&e.length<=64){if(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e)){let n=e.length===4?[...e.slice(1)].map(r=>r+r).join(""):e.slice(1);return{cs:be[3],comps:[0,2,4].map(r=>parseInt(n.slice(r,r+2),16)/255)}}let t=ma.exec(e);if(t){let n=t.slice(1).map(r=>r.endsWith("%")?Number(r.slice(0,-1))/100:Number(r)/255);if(n.every(xt))return{cs:be[3],comps:n};throw new RangeError(`rgb(): each is 0–255 or 0%–100%, in ${JSON.stringify(e)}`)}}return null}l(_e,"device");function Jn(e,t){let n=_e(e);if(n)return nt(t,n.cs),n;let r=ze(e);if(r==="spot"||r==="color")return he(e,r,eo(t),"colour (pdf.spotColor / pdf.iccColorSpace)");throw new TypeError(`Not a colour: ${JSON.stringify(e)} (use '#rrggbb', 'rgb(r, g, b)', [r, g, b] or cmyk(c, m, y, k) in 0–1, a gray level 0–1, a spot colour or an ICC colour)`)}l(Jn,"resolve");function Oe(e,t,n){let{cs:r,comps:o}=Jn(e,n),s=o.map(F).join(" ");if(r===be[1])return`${s} ${t?"G":"g"}`;if(r===be[3])return`${s} ${t?"RG":"rg"}`;if(r===be[4])return`${s} ${t?"K":"k"}`;let i=n.resource("ColorSpace",r);return t?`/${i} CS ${s} SCN`:`/${i} cs ${s} scn`}l(Oe,"colorOp");var Qr=new WeakMap;function to(e,t,n){if(typeof t!="string"||!t||t.length>127)throw new TypeError("spotColor(name, alternate): name is a string of 1–127 characters");let r=_e(n);if(!r)throw new TypeError(`spotColor: the alternate is a device colour (gray, '#rrggbb', [r, g, b], cmyk(c, m, y, k)), not ${JSON.stringify(n)}`);nt(e,r.cs);let o=pe(t),s=r.comps.length===4?"0 0 0 0":r.comps.map(()=>"1").join(" "),i=`[/Separation ${o} ${r.cs} << /FunctionType 2 /Domain [0 1] /C0 [${s}] /C1 [${r.comps.map(F).join(" ")}] /N 1 >>]`,a=Qr.get(e);if(a||Qr.set(e,a=new Map),a.has(o)&&a.get(o)!==i)throw new TypeError(`spotColor: ${o} is already defined with another alternate in this PDF (one name, one definition)`);return a.set(o,i),ye(Object.freeze({type:"spot",name:t,tint:l(f=>{if(!xt(f))throw new RangeError(`A tint is 0–1, not ${f}`);return ye(Object.freeze({type:"color"}),"color",e,{cs:i,comps:[f]})},"tint")}),"spot",e,{cs:i,comps:[1]})}l(to,"spotColor");async function no(e,t){let n=dn(t,"iccColorSpace"),r=e.reserve();await e.serial(()=>e.writeStream(r,`<< /N ${n.n} >>`,n.bytes));let o=`[/ICCBased ${r} 0 R]`,s=l((...i)=>{if(i.length!==n.n||!i.every(xt))throw new RangeError(`This ICC colour space takes ${n.n} components, each 0–1, not ${i.join(", ")}`);return ye(Object.freeze({type:"color"}),"color",e,{cs:o,comps:i})},"color");return ye(Object.freeze({type:"iccColorSpace",components:n.n,color:s}),"icc",e,{cs:o,n:n.n})}l(no,"iccColorSpace");function Ht(e){let t=e?.characterSpacing??0,n=e?.wordSpacing??0,r=e?.horizontalScaling??100;if(F(t),F(n),F(r),!(r>0))throw new RangeError(`horizontalScaling is a percentage above 0, not ${r}`);return{tc:t,tw:n,tz:r}}l(Ht,"spacing");var ya=/^\s$/u,oo="֐-ࣿיִ-﷿ﹰ-\uFEFF",ro=l((e,t)=>!t.rtl&&$a(e)&&ba.test(e)&&!Aa.test(e)?{...t,rtl:!0}:t,"dirOf"),$a=l(e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=1424)return!0;return!1},"maybeRtl"),ba=new RegExp(`[${oo}]`,"u"),Aa=new RegExp(`(?![${oo}])[\\p{L}\\p{Nd}]`,"u");function Tt(e,t,n){if(t.length===1){let c=t[0];return[{font:c.font,impl:c.impl,run:c.impl.items(e,ro(e,n))}]}let r=[],o=-1,s=0,i=0;for(let c of e){let f=c.codePointAt(0),h=o>=0&&ya.test(c)&&t[o].impl.has(f)?o:t.findIndex(u=>u.impl.has(f));h<0&&(h=o>=0?o:0),h!==o&&(o>=0&&r.push([o,s,i]),o=h,s=i),i+=c.length}o>=0&&r.push([o,s,i]);let a=r.map(([c,f,h])=>{let u=e.slice(f,h),p=t[c];return{font:p.font,impl:p.impl,run:p.impl.items(u,ro(u,n))}});return n.rtl?a.reverse():a}l(Tt,"segments");function rt(e,t,n){let r=0,o=0,s=0;if(Array.isArray(e))for(let i of e)r+=i.a,i.sp&&s++,i.c||o++;else({a:r,n:o,sp:s}=e);return(r*t/1e3+o*n.tc+s*n.tw)*n.tz/100}l(rt,"runWidth");function gn(e,t,n,r){F(n);let o=Ht(r);return rt(e.items(t,{kerning:r?.kerning,rtl:r?.direction==="rtl",ws:o.tw,measure:!0}),n,o)}l(gn,"measure");function so(e,t,n,r,o,s=0){if(!Array.isArray(e))return e.body?`(${e.body}) Tj
67
+ `:"";let i=o?0:r*1e3/t,a=s*1e3/t,c="",f="",h="",u=0,p=0,m=n,d=0,g=!1,w=!1,y=l(()=>{h&&(f+=`(${h})`,h="")},"endLit"),$=l(()=>{y(),f&&(c+=g?`[${f}] TJ
68
+ `:`${f} Tj
69
+ `,f="",g=!1)},"flush"),A=l(D=>{let N=n+D.dy*t/1e3;Math.abs(N-m)>=5e-4&&($(),c+=`${F(N)} Ts
70
+ `,m=N);let M=u-(p+D.dx);if(Math.abs(M)>=5e-4){let j=F(M);y(),f+=` ${j} `,g=!0,u-=Number(j)}h+=D.b,u+=D.w},"put");for(let D of e){if(D.c){p+=D.a,w=!0;continue}D.at!==void 0&&($(),c+=`/Span << /ActualText ${q(D.at)} >> BDC
71
+ `,d=D.n||1),A(D),p+=D.a+(D.sp?i:0),d&&--d===0&&($(),c+=`EMC
72
+ `)}if($(),w){c+=`/Span << /ActualText ${q("")} >> BDC
73
+ 0 0 Td
74
+ `,u=p=0;for(let D of e){if(!D.c){p+=D.a+(D.sp?i:0)+a;continue}A(D),u+=a,p+=D.a}$(),c+=`EMC
75
+ `}return m!==n&&(c+=`${F(n)} Ts
76
+ `),c}l(so,"runOps");var zt=1e7,Kn={fill:0,stroke:1,fillStroke:2,invisible:3,fillClip:4,strokeClip:5,fillStrokeClip:6,clip:7};function _t(e,t,n){let r=t?.font;if(!r||typeof r.encode!="function")throw new TypeError(`${n}: options.font is required (pdf.standardFont(name) or await pdf.embedFont(bytes))`);let o=t.fallback??[];if(!Array.isArray(o)||o.length>16)throw new TypeError(`${n}: fallback is an array of at most 16 fonts`);return[r,...o].map(s=>({font:s,impl:he(s,"font",e.doc,"font")}))}l(_t,"fontsOf");var io=Object.freeze({sp:Object.freeze({tc:0,tw:0,tz:100}),rise:0,Tr:0}),xa=Object.freeze({});function Xt(e){if(e.characterSpacing==null&&e.wordSpacing==null&&e.horizontalScaling==null&&e.rise==null&&e.renderMode==null)return io;let t=Ht(e),n=e?.rise??0;F(n);let r=e?.renderMode??0,o=typeof r=="string"?Object.hasOwn(Kn,r)?Kn[r]:-1:r;if(!Number.isInteger(o)||o<0||o>7)throw new RangeError(`renderMode is 0–7 or one of ${Object.keys(Kn).join(", ")}, not ${JSON.stringify(r)}`);return{sp:t,rise:n,Tr:o}}l(Xt,"textState");function Et(e,t,n,r,o,s,i,a){let c=Tt(n,t,{kerning:a.kerning,rtl:a.direction==="rtl",ws:i.sp.tw}),f=e.content;if(f.draw(),f.fill(Oe(a.color??0,!1,e.doc)),i.Tr%4===1||i.Tr%4===2){f.stroke(Oe(a.strokeColor??a.color??0,!0,e.doc));let u=a.strokeWidth??1;if(F(u),u<0)throw new RangeError(`strokeWidth is 0 or more, not ${u}`);f.lineWidth(u)}let h=r;for(let u of c){let p=so(u.run,s,i.rise,i.sp.tw,u.impl.standard,i.sp.tc);p&&f.run(u.font.name,s,h,e.height-o,p,i===io?xa:{Tc:i.sp.tc,Tw:u.impl.standard?i.sp.tw:0,Tz:i.sp.tz,Ts:i.rise,Tr:i.Tr}),c.length>1&&(h+=rt(u.run,s,i.sp))}return c.length===1?rt(c[0].run,s,i.sp):h-r}l(Et,"drawLine");function ao(e,t){let n=_t(this,t,"page.text"),r=t.size??12,o=t.x??0,s=t.y??0;F(o),F(s),F(r);let i=Xt(t),a=String(e??"");if(a.length>zt)throw new RangeError(`page.text: the text is ${a.length} characters, more than ${zt}`);if(!a)return this;if(t.rotate){F(t.rotate);let c=this;c.save(),c.translate(o,s),c.rotate(t.rotate);try{Et(this,n,a,0,n[0].impl.ascent*r,r,i,t)}finally{c.restore()}}else Et(this,n,a,o,s+n[0].impl.ascent*r,r,i,t);return this}l(ao,"text");var Ta=1e5;function co(e,t){let n=_t(this,t,"page.textBox"),r=t.size??12,o=t.x??0,s=t.y??0,i=t.width;if(F(o),F(s),F(r),F(i),!(i>0))throw new RangeError(`page.textBox: width is above 0, not ${i}`);let a=Xt(t),c=a.sp,f=n[0].impl,h=t.lineHeight??f.lineHeight*r;if(F(h),!(h>0))throw new RangeError(`page.textBox: lineHeight is above 0, not ${h}`);let u=t.align??(t.direction==="rtl"?"right":"left");if(!["left","right","center","justify"].includes(u))throw new RangeError(`page.textBox: align is left, right, center or justify, not ${JSON.stringify(u)}`);if(t.height!=null&&F(t.height),t.maxLines!=null&&!(Number.isInteger(t.maxLines)&&t.maxLines>=0))throw new RangeError(`page.textBox: maxLines is a whole number, not ${t.maxLines}`);let p=t.height!=null?Math.max(0,Math.floor(t.height/h+1e-9)):1/0,m=Math.min(t.maxLines??1/0,p),d={kerning:t.kerning,rtl:t.direction==="rtl",ws:c.tw,measure:!0},g=new Map,w=l(b=>{let E=g.get(b);if(E===void 0){E=0;for(let C of Tt(b,n,d))E+=rt(C.run,r,c);b.length<=64&&g.size<1e4&&g.set(b,E)}return E},"width"),y=String(e??"");if(y.length>zt)throw new RangeError(`page.textBox: the text is ${y.length} characters, more than ${zt}`);let $=Math.min(m,Ta),A=[],D=1e-6,N=0;e:for(let b of y.split(`
77
+ `)){if(A.length>$)break;let E=N,C=A.length,v=b.endsWith("\r")?b.slice(0,-1):b;N+=b.length+1;let L=-1,H=0,S=0,P=0,U=l(I=>{A.push(L<0?{s:E+P,e:E+P,last:I}:{s:E+L,e:E+H,last:I}),L=-1,S=0},"commit");for(let I of v.split(" ")){if(A.length>$)break e;let _=P,Y=P+I.length;if(P=Y+1,!I&&L<0)continue;let X=w(I);if(L>=0){let k=w(" ")+X;if(S+k<=i+D){H=Y,S+=k;continue}if(U(!1),!I)continue}if(L=_,H=Y,S=X,S<=i+D)continue;let T=0;H=L;for(let k of I){let B=w(k);if(T+B>i+D&&H>L){if(A.length>$)break e;let z=H;U(!1),L=H=z,T=0}T+=B,H+=k.length}S=T}P=v.length,L<0&&A.length>C?A[A.length-1].last=!0:U(!0)}for(let b of A)for(;b.e>b.s&&y[b.e-1]===" ";)b.e--;let M=A.slice(0,$),j=A.length>M.length?y.slice(A[M.length].s):"",O=j&&t.maxLines!=null&&M.length===t.maxLines&&M.length>0&&t.ellipsis!==!1,R=M.map(b=>y.slice(b.s,b.e));if(O){let b=n.some(S=>S.impl.has(8230))?"…":"...",E=M[M.length-1],C=i-w(b)+D,v=E.s,L=0;for(let S of y.slice(E.s,E.e)){if(L+=w(S),L>C)break;v+=S.length}let H=y.slice(E.s,v).trimEnd();R[R.length-1]=H+b,j=y.slice(E.s+H.length).replace(/^ +/,""),E.last=!0}let x=f.ascent*r;return R.forEach((b,E)=>{let C=M[E];if(!b)return;let v=w(b),L=0,H=a;if(u==="right")L=i-v;else if(u==="center")L=(i-v)/2;else if(u==="justify"&&!C.last){let S=b.split(" ").length-1;S&&i>v&&(H={...a,sp:{...c,tw:c.tw+(i-v)/S/(c.tz/100)}})}Et(this,n,b,o+L,s+E*h+x,r,H,t)}),{height:M.length*h,lines:M.length,overflow:j}}l(co,"textBox");var lo=10*1024*1024,Ea={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7,z:0};function fo(e,t){if(typeof e!="string")throw new TypeError("svgPath: the path data is a string");if(e.length>lo)throw new RangeError(`svgPath: the path data is ${e.length} characters; at most ${lo} (10 MB)`);let n=e.length,r=0,o="",s=!1,i=0,a=0,c=0,f=0,h=0,u=0,p=0,m=0,d="",g=l(N=>{throw new SyntaxError(`svgPath: ${N} at character ${r} of the path data`)},"fail"),w=l(()=>{for(let N;r<n&&((N=e.charCodeAt(r))===32||N===9||N===10||N===13||N===12);)r++},"space"),y=l(()=>{w(),e[r]===","&&(r++,w())},"sep"),$=l(()=>{let N=r;for(let M;r<n&&(M=e.charCodeAt(r))>=48&&M<=57;)r++;return r-N},"digits"),A=l(()=>{y();let N=r;(e[r]==="+"||e[r]==="-")&&r++;let M=$();if(e[r]==="."&&(r++,M+=$()),M||(r=N,g("a number was expected")),e[r]==="e"||e[r]==="E"){let j=r++;(e[r]==="+"||e[r]==="-")&&r++,$()||(r=j,g("an exponent was expected"))}return Number(e.slice(N,r))},"number"),D=l(()=>{y();let N=e[r];return N!=="0"&&N!=="1"&&g("an arc flag (0 or 1) was expected"),r++,N==="1"},"flag");for(;w(),!(r>=n);){let N=e[r],M=N.toLowerCase();Object.hasOwn(Ea,M)?(o=N,r++):o?(o==="z"||o==="Z")&&g("a command was expected"):g("the path data must start with M or m"),!s&&o!=="M"&&o!=="m"&&g("the path data must start with M or m");let j=o.toLowerCase(),O=o===j,R=O?i:0,x=O?a:0;if(j==="z"){t.closePath(),i=c,a=f,d="z";continue}if(j==="m"){i=R+A(),a=x+A(),t.moveTo(i,a),c=i,f=a,s=!0,o=O?"l":"L",d="m";continue}if(j==="l")i=R+A(),a=x+A(),t.lineTo(i,a);else if(j==="h")i=R+A(),t.lineTo(i,a);else if(j==="v")a=(O?a:0)+A(),t.lineTo(i,a);else if(j==="c"||j==="s"){let b,E;j==="c"?(b=R+A(),E=x+A()):d==="c"||d==="s"?(b=2*i-h,E=2*a-u):(b=i,E=a),h=R+A(),u=x+A(),i=R+A(),a=x+A(),t.bezierCurveTo(b,E,h,u,i,a)}else if(j==="q"||j==="t")j==="q"?(p=R+A(),m=x+A()):d==="q"||d==="t"?(p=2*i-p,m=2*a-m):(p=i,m=a),i=R+A(),a=x+A(),t.quadraticCurveTo(p,m,i,a);else{let b=Math.abs(A()),E=Math.abs(A()),C=A(),v=D(),L=D(),H=i,S=a;Fe(b,"svgPath arc radius"),Fe(E,"svgPath arc radius"),Fe(C,"svgPath arc rotation"),i=R+A(),a=x+A(),Sa(t,H,S,b,E,C*Math.PI/180,v,L,i,a)}d=j}}l(fo,"parseSvgPath");function Sa(e,t,n,r,o,s,i,a,c,f){if(t===c&&n===f)return;if(!r||!o){e.lineTo(c,f);return}let h=Math.cos(s),u=Math.sin(s),p=(t-c)/2,m=(n-f)/2,d=h*p+u*m,g=-u*p+h*m,w=d*d/(r*r)+g*g/(o*o);w>1&&(r*=Math.sqrt(w),o*=Math.sqrt(w));let y=r*r*g*g+o*o*d*d,$=(i!==a?1:-1)*Math.sqrt(Math.max(0,(r*r*o*o-y)/y)),A=$*r*g/o,D=-$*o*d/r,N=h*A-u*D+(t+c)/2,M=u*A+h*D+(n+f)/2,j=(d-A)/r,O=(g-D)/o,R=(-d-A)/r,x=(-g-D)/o,b=Math.atan2(O,j),E=Math.atan2(x,R)-b;!a&&E>0?E-=2*Math.PI:a&&E<0&&(E+=2*Math.PI),e.arcSegment(N,M,r,o,s,b,E,!1)}l(Sa,"arc");var ho=1e6,De=2*Math.PI;function Fe(e,t){if(typeof e!="number"||!(Math.abs(e)<1e9))throw new RangeError(`${t}: ${e} is not a usable number (finite, under 1e9 in size)`);return e}l(Fe,"coord");var ot=class{static{l(this,"Path")}constructor(){this.ops=[],this.v=[],this.x=0,this.y=0,this.sx=0,this.sy=0,this.has=!1}get segments(){return this.ops.length}#e(t,n){if(this.ops.length>=ho)throw new RangeError(`A path has at most ${ho.toLocaleString("en")} segments`);this.ops.push(t);for(let r of n)this.v.push(r)}moveTo(t,n){return Fe(t,"moveTo"),Fe(n,"moveTo"),this.#e("m",[t,n]),this.x=this.sx=t,this.y=this.sy=n,this.has=!0,this}lineTo(t,n){return Fe(t,"lineTo"),Fe(n,"lineTo"),this.has?(this.#e("l",[t,n]),this.x=t,this.y=n,this):this.moveTo(t,n)}bezierCurveTo(t,n,r,o,s,i){for(let a of[t,n,r,o,s,i])Fe(a,"bezierCurveTo");return this.has||this.moveTo(t,n),this.#e("c",[t,n,r,o,s,i]),this.x=s,this.y=i,this}quadraticCurveTo(t,n,r,o){for(let a of[t,n,r,o])Fe(a,"quadraticCurveTo");this.has||this.moveTo(t,n);let s=this.x,i=this.y;return this.bezierCurveTo(s+2/3*(t-s),i+2/3*(n-i),r+2/3*(t-r),o+2/3*(n-o),r,o)}closePath(){return this.has?(this.#e("h",[]),this.x=this.sx,this.y=this.sy,this):this}arcSegment(t,n,r,o,s,i,a,c=!0){let f=Math.cos(s),h=Math.sin(s),u=l((y,$=Math.cos(y),A=Math.sin(y))=>[t+r*$*f-o*A*h,n+r*$*h+o*A*f],"at"),[p,m]=u(i);if((c||!this.has)&&(this.has?this.lineTo(p,m):this.moveTo(p,m)),a===0)return this;let d=Math.min(4,Math.ceil(Math.abs(a)/(Math.PI/2)-1e-9)),g=a/d,w=4/3*Math.tan(g/4);for(let y=0;y<d;y++){let $=i+y*g,A=$+g,D=Math.cos($),N=Math.sin($),M=Math.cos(A),j=Math.sin(A),[O,R]=u(0,D-w*N,N+w*D),[x,b]=u(0,M+w*j,j-w*M),[E,C]=u(0,M,j);this.bezierCurveTo(O,R,x,b,E,C)}return this}arc(t,n,r,o,s,i=!1){return this.ellipse(t,n,r,r,0,o,s,i)}ellipse(t,n,r,o,s,i,a,c=!1){for(let h of[t,n,r,o,s,i,a])Fe(h,"arc");if(r<0||o<0)throw new RangeError(`arc: a radius cannot be negative (${r<0?r:o})`);let f;return c?f=i-a>=De?-De:-(((i-a)%De+De)%De):f=a-i>=De?De:((a-i)%De+De)%De,this.arcSegment(t,n,r,o,s,i,f)}arcTo(t,n,r,o,s){for(let b of[t,n,r,o,s])Fe(b,"arcTo");if(s<0)throw new RangeError(`arcTo: the radius cannot be negative (${s})`);if(!this.has)return this.moveTo(t,n);let i=this.x-t,a=this.y-n,c=r-t,f=o-n,h=Math.hypot(i,a),u=Math.hypot(c,f),p=i*f-a*c;if(s===0||h===0||u===0||Math.abs(p)<=1e-9*h*u)return this.lineTo(t,n);let m=Math.acos(Math.max(-1,Math.min(1,(i*c+a*f)/(h*u)))),d=s/Math.tan(m/2),g=i/h+c/u,w=a/h+f/u,y=Math.hypot(g,w),$=s/Math.sin(m/2),A=t+g/y*$,D=n+w/y*$,N=t+i/h*d,M=n+a/h*d,j=t+c/u*d,O=n+f/u*d,R=Math.atan2(M-D,N-A),x=Math.atan2(O-D,j-A)-R;return x>Math.PI?x-=De:x<-Math.PI&&(x+=De),this.arcSegment(A,D,s,s,0,R,x)}rect(t,n,r,o){for(let s of[t,n,r,o])Fe(s,"rect");return this.moveTo(t,n).lineTo(t+r,n).lineTo(t+r,n+o).lineTo(t,n+o).closePath().moveTo(t,n)}roundedRect(t,n,r,o,s=0){for(let m of[t,n,r,o])Fe(m,"roundedRect");let i=typeof s=="number"?[s]:s;if(!Array.isArray(i)||i.length<1||i.length>4)throw new TypeError("roundedRect: radii is a number or an array of 1–4 numbers");for(let m of i)if(Fe(m,"roundedRect"),m<0)throw new RangeError(`roundedRect: a radius cannot be negative (${m})`);let[a,c,f,h]=i.length===1?[i[0],i[0],i[0],i[0]]:i.length===2?[i[0],i[1],i[0],i[1]]:i.length===3?[i[0],i[1],i[2],i[1]]:i;r<0&&(t+=r,r=-r),o<0&&(n+=o,o=-o);let u=Math.min(1,r/(a+c)||1,r/(h+f)||1,o/(a+h)||1,o/(c+f)||1);a*=u,c*=u,f*=u,h*=u;let p=Math.PI/2;return this.moveTo(t+a,n).lineTo(t+r-c,n),c&&this.arcSegment(t+r-c,n+c,c,c,0,-p,p,!1),this.lineTo(t+r,n+o-f),f&&this.arcSegment(t+r-f,n+o-f,f,f,0,0,p,!1),this.lineTo(t+h,n+o),h&&this.arcSegment(t+h,n+o-h,h,h,0,p,p,!1),this.lineTo(t,n+a),a&&this.arcSegment(t+a,n+a,a,a,0,Math.PI,p,!1),this.closePath().moveTo(t,n)}svg(t){return fo(t,this),this}pdf(t,n=0,r=0){let{ops:o,v:s}=this,i=t-r,a="",c=0,f=!1;for(let h=0;h<o.length;h++){let u=o[h];if(u==="h"){a+="h ";continue}if(u==="c"){a+=`${F(s[c]-n)} ${F(i-s[c+1])} ${F(s[c+2]-n)} ${F(i-s[c+3])} ${F(s[c+4]-n)} ${F(i-s[c+5])} c `,c+=6,f=!0;continue}if(u==="m"&&(h===o.length-1||o[h+1]==="m")){c+=2;continue}a+=`${F(s[c]-n)} ${F(i-s[c+1])} ${u} `,c+=2,u==="l"&&(f=!0)}return f?a:""}};function ka(e,t={}){let n=t?.scaleY??1;if(typeof n!="number"||!Number.isFinite(n))throw new TypeError("svgPathOps: scaleY is a finite number");let r;try{r=new ot().svg(e)}catch(c){throw c instanceof SyntaxError?new TypeError(c.message):c}let{ops:o,v:s}=r,i=[],a=0;for(let c of o){if(c==="h"){i.push("h");continue}let f=c==="c"?6:2;for(let h=0;h<f;h+=2)i.push(`${F(s[a+h])} ${F(s[a+h+1]*n)}`);i.push(c),a+=f}return i.join(" ")}l(ka,"svgPathOps");var uo=256;function Ca(e,t){let n=e.map(r=>Jn(r,t));if(n.every(r=>r.cs===be[1]||r.cs===be[3])&&n.some(r=>r.cs===be[3]))return nt(t,be[3]),{cs:be[3],comps:n.map(r=>(r.comps.length===1?[r.comps[0],r.comps[0],r.comps[0]]:r.comps).map(F).join(" "))};if(n.some(r=>r.cs!==n[0].cs))throw new TypeError("A gradient's colours share one colour space (gray and RGB mix; CMYK, a spot colour's tints or one ICC space do not mix with others)");return{cs:n[0].cs,comps:n.map(r=>r.comps.map(F).join(" "))}}l(Ca,"oneSpace");function po(e,t,n,r,o={}){if(n.forEach(g=>F(g)),t===3&&(n[2]<0||n[5]<0))throw new RangeError("radialGradient: a radius cannot be negative");if(!Array.isArray(r)||!r.length||r.length>uo)throw new RangeError(`A gradient has 1–${uo} colour stops: [[offset, colour], …]`);let s=r.map(g=>Array.isArray(g)?g:[g?.offset,g?.color]),i=Ca(s.map(g=>g[1]),e),a=s.map(([g],w)=>{if(typeof g!="number"||Number.isNaN(g))throw new RangeError(`A colour stop's offset is a number 0–1, not ${g}`);return{o:Math.round(Math.min(1,Math.max(0,g))*1e6)/1e6,c:i.comps[w],i:w}}).sort((g,w)=>g.o-w.o||g.i-w.i);a[0].o>0&&a.unshift({o:0,c:a[0].c,i:-1}),a[a.length-1].o<1&&a.push({o:1,c:a[a.length-1].c,i:-1});let c=[],f=[];for(let g=0;g+1<a.length;g++)a[g+1].o<=a[g].o||(c.length&&f.push(Qn(a[g].o)),c.push(`<< /FunctionType 2 /Domain [0 1] /C0 [${a[g].c}] /C1 [${a[g+1].c}] /N 1 >>`));let h=c.length===1?c[0]:`<< /FunctionType 3 /Domain [0 1] /Functions [${c.join(" ")}] /Bounds [${f.join(" ")}] /Encode [${c.map(()=>"0 1").join(" ")}] >>`,u=o.extend??!0,[p,m]=Array.isArray(u)?u:[u,u],d=`<< /ShadingType ${t} /ColorSpace ${i.cs} /Coords [${n.map(F).join(" ")}] /Function ${h} /Extend [${!!p} ${!!m}] >>`;return ye(Object.freeze({type:"gradient"}),"gradient",e,d)}l(po,"gradient");function go(e,t,n,r,o,s){return po(Gt(this.doc),2,[e,t,n,r],o,s)}l(go,"linearGradient");function mo(e,t,n,r,o,s,i,a){return po(Gt(this.doc),3,[e,t,n,r,o,s],i,a)}l(mo,"radialGradient");var wo=l((e,t)=>he(t,"gradient",Gt(e.doc),"gradient (page.linearGradient / radialGradient)"),"shading"),Gt=l(e=>e.base??e,"base");function Yn(e,t,n){if(t===null||typeof t!="object"||Array.isArray(t)||ze(t)==="spot"||ze(t)==="color")return Oe(t,n,e.doc);let r=Gt(e.doc),o="gradient or pattern (page.linearGradient / radialGradient / tilingPattern)",s=St(Ne(e).m,Zn(e.height)),i;if(ze(t)!=="tiling")i=`<< /Type /Pattern /PatternType 2 /Shading ${he(t,"gradient",r,o)} /Matrix [${kt(s)}] >>`;else{t=he(t,"tiling",r,o);let c=kt(St(Zn(t.h),s)),f=c,h=t.refs.get(f);if(h===void 0){t.refs.set(f,h=r.reserve());let u=l((g,w)=>F(g)===F(w)?F(g+.001):F(g),"edge"),p=`<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 1 /BBox [0 0 ${u(t.w,t.xs)} ${u(t.h,t.ys)}] /XStep ${F(t.xs)} /YStep ${F(t.ys)} /Resources ${t.res} /Matrix [${c}] >>`,m=t.content,d=h;e.onWrite(()=>r.writeStream(d,p,$e(m)))}i=`${h} 0 R`,t.transparent&&Wt(e)}let a=e.doc.resource("Pattern",i);return n?`/Pattern CS /${a} SCN`:`/Pattern cs /${a} scn`}l(Yn,"paintOp");function yo(e,t){let n=this,r=Gt(n.doc),o=e?.width,s=e?.height,i=e?.spacing??0,[a,c]=Array.isArray(i)?i:[i,i];for(let y of[o,s])if(typeof y!="number"||!(y>0&&y<1e6))throw new RangeError(`tilingPattern: width and height are numbers > 0, not ${y}`);for(let y of[a,c])if(typeof y!="number"||!(y>=0&&y<1e6))throw new RangeError(`tilingPattern: spacing is a number ≥ 0, not ${y}`);if(typeof t!="function")throw new TypeError("tilingPattern(options, draw): draw(cell) draws one cell");let f=new Map,h=Object.create(r,{base:{value:r},tags:{value:null},resource:{value(y,$,A){let D=r.resource(y,$,A),N=f.get(y);return N||f.set(y,N=new Map),N.set(D,$),D}}}),u=new n.constructor(h,n.index,o,s),p=l(y=>()=>{throw new TypeError(`page.${y} cannot be used in a tiling pattern's cell (shapes, gradients and patterns can)`)},"no");Object.assign(u,{cell:!0,number:n.number,entries:n.entries,onWrite:l(y=>n.onWrite(y),"onWrite"),text:p("text"),link:p("link"),annotate:p("annotate"),end:p("end"),tag:l((y,$)=>$(),"tag"),figure:l((y,$)=>$(),"figure")});let m=t(u);if(m&&typeof m.then=="function")throw new TypeError("tilingPattern: draw must be synchronous (no async function)");let d=Ne(u).stack.length;d&&r.warn(`A tiling pattern's cell: ${d} save() without a restore(); restored at the end of the cell`);let g=`<< ${[...f].map(([y,$])=>`${pe(y)} << ${[...$].map(([A,D])=>`/${A} ${D}`).join(" ")} >>`).join(" ")} >>`,w={w:o,h:s,xs:o+a,ys:s+c,content:u.content.end(),res:g,transparent:Ne(u).transparent,refs:new Map};return ye(Object.freeze({type:"tiling"}),"tiling",r,w)}l(yo,"tilingPattern");function $o(e,t){if(e==null||e===!1)return null;if(e===!0)return{part:2,conformance:"b",unicode:!1};if(typeof e!="object")throw new TypeError("createPdf: pdfa is true or { part: 1 | 2 | 3, conformance: 'a' | 'b' | 'u', outputIntent? }");let n=e.part??2,r=e.conformance??"b";if(n!==1&&n!==2&&n!==3)throw new TypeError(`createPdf: pdfa.part is 1, 2 or 3, not ${JSON.stringify(n)}`);if(r!=="a"&&r!=="b"&&r!=="u")throw new TypeError(`createPdf: pdfa.conformance is 'a', 'b' or 'u', not ${JSON.stringify(r)}`);if(n===1&&r!=="b")throw new TypeError(`createPdf: PDF/A-1${r} is not offered: use PDF/A-1b, or PDF/A-2${r} / PDF/A-3${r}`);if(r==="a"&&!t)throw new TypeError(`createPdf: PDF/A-${n}a is tagged PDF: pass tagged: { lang } too`);return{part:n,conformance:r,unicode:r!=="b"}}l($o,"pdfaLevel");function Ke(e,t,n){if((e.base??e).pdfaLevel?.part===1)throw new TypeError(`${t}: PDF/A-1 (ISO 19005-1) ${n}; use PDF/A-2 or 3 (pdfa: { part: 2 })`)}l(Ke,"refuseInA1");var Fa=1e3,va=27,bo=100,To=["Normal","Multiply","Screen","Overlay","Darken","Lighten","ColorDodge","ColorBurn","HardLight","SoftLight","Difference","Exclusion","Hue","Saturation","Color","Luminosity"],Ma=new Map(To.map(e=>[e.toLowerCase(),e])),Pa=["butt","round","square"],Ra=["miter","round","bevel"],Ao="<< /Type /Group /S /Transparency /CS /DeviceRGB >>",xo=new WeakMap;function Ne(e){let t=xo.get(e);return t||xo.set(e,t={m:[1,0,0,1,0,0],stack:[],transparent:!1,watched:!1}),t}l(Ne,"state");var St=l((e,t)=>[e[0]*t[0]+e[1]*t[2],e[0]*t[1]+e[1]*t[3],e[2]*t[0]+e[3]*t[2],e[2]*t[1]+e[3]*t[3],e[4]*t[0]+e[5]*t[2]+t[4],e[4]*t[1]+e[5]*t[3]+t[5]],"mul"),Zn=l(e=>[1,0,0,-1,0,e],"flip"),Qn=l(e=>(F(e),String(Math.round(e*1e6)/1e6||0)),"num6"),kt=l(e=>e.map(Qn).join(" "),"matrix");function Wt(e){Ke(e.doc,"Transparency (opacity, blend modes, soft masks)","forbids transparency"),Ne(e).transparent=!0,e.entries.set("Group",(e.doc.base??e.doc).outputIntent==="CMYK"?Ao.replace("DeviceRGB","DeviceCMYK"):Ao)}l(Wt,"transparent");function Ct(e,t){let n=l((c,f)=>{if(c==null)return 1;if(typeof c!="number"||!(c>=0&&c<=1))throw new RangeError(`${f} is 0–1, not ${c}`);return c},"unit"),r=n(t.opacity,"opacity"),o=r*n(t.fillOpacity,"fillOpacity"),s=r*n(t.strokeOpacity,"strokeOpacity"),i="Normal";if(t.blendMode!=null&&(i=Ma.get(String(t.blendMode).replace(/-/g,"").toLowerCase())??"",!i))throw new TypeError(`blendMode is one of ${To.join(", ")} (or as canvas: 'multiply', 'color-dodge'…), not ${JSON.stringify(t.blendMode)}`);if(o===1&&s===1&&i==="Normal")return"";let a=e.doc.resource("ExtGState",`<< /Type /ExtGState${o!==1?` /ca ${F(o)}`:""}${s!==1?` /CA ${F(s)}`:""}${i!=="Normal"?` /BM ${pe(i)}`:""} >>`);return Wt(e),`/${a} gs
78
+ `}l(Ct,"gstate");function Oa(e,t){let n=t.width??1;if(typeof n!="number"||!(n>=0&&n<1e9))throw new RangeError(`stroke width is a number ≥ 0, not ${n}`);let r="[] 0";if(t.dash!=null&&t.dash.length){if(!Array.isArray(t.dash)||t.dash.length>bo)throw new RangeError(`dash is an array of at most ${bo} lengths`);let a=0;for(let c of t.dash){if(typeof c!="number"||!(c>=0&&c<1e9))throw new RangeError(`a dash length is a number ≥ 0, not ${c}`);a+=c}if(!(a>0))throw new RangeError("dash: the lengths cannot all be 0 (PDF forbids it)");r=`[${t.dash.map(F).join(" ")}] ${F(t.dashPhase??0)}`}else t.dashPhase!=null&&F(t.dashPhase);let o=Pa.indexOf(t.cap??"butt"),s=Ra.indexOf(t.join??"miter"),i=t.miterLimit??10;if(o<0)throw new TypeError(`cap is butt, round or square, not ${JSON.stringify(t.cap)}`);if(s<0)throw new TypeError(`join is miter, round or bevel, not ${JSON.stringify(t.join)}`);if(typeof i!="number"||!(i>=1&&i<1e9))throw new RangeError(`miterLimit is a number ≥ 1, not ${i}`);return()=>{e.lineWidth(n),r!==e.st.dash&&(e.s+=`${r} d
79
+ `,e.st.dash=r),o!==(e.st.cap??0)&&(e.s+=`${o} J
80
+ `,e.st.cap=o),s!==(e.st.join??0)&&(e.s+=`${s} j
81
+ `,e.st.join=s),i!==(e.st.ml??10)&&(e.s+=`${F(i)} M
82
+ `,e.st.ml=i)}}l(Oa,"strokeStyle");function mn(e,t,n,r={}){if(!(t instanceof ot))throw new TypeError("Not a path: use page.path() (or page.svgPath(d, options))");let o=Eo(r.rule),s=e.height,i=t.ops.length>=3,a=i?Math.round(t.v[0]*1e3)/1e3:0,c=i?Math.round((s-t.v[1])*1e3)/1e3:0,f=t.pdf(s,a,c),h=e.content,u=n!=="S"?Yn(e,r.fill??r.color??0,!1):"",p=n!=="f"?Oa(h,r):null,m=n!=="f"?Yn(e,r.stroke??r.color??0,!0):"",d=Ct(e,r);if(!f)return e;h.draw(),h.et(),d&&(h.q(),h.s+=d),u&&h.fill(u),m&&h.stroke(m),p?.();let g=i&&(a||c)?`1 0 0 1 ${F(a)} ${F(c)} cm `:"",w=g&&!d;return h.s+=`${w?"q ":""}${g}${f}${n}${o&&n!=="S"?"*":""}${w?" Q":""}
83
+ `,d&&h.Q(),e}l(mn,"paint");var Eo=l(e=>{if(e!=null&&e!=="nonzero"&&e!=="evenodd")throw new TypeError(`rule is 'nonzero' or 'evenodd', not ${JSON.stringify(e)}`);return e==="evenodd"},"rule");function So(){return new ot}l(So,"path");function ko(e,t){return mn(this,e,"f",t)}l(ko,"fill");function Co(e,t){return mn(this,e,"S",t)}l(Co,"stroke");function Fo(e,t){return mn(this,e,"B",t)}l(Fo,"fillAndStroke");function vo(e,t={}){let n=new ot().svg(e);return mn(this,n,t.fill!=null&&t.stroke!=null?"B":t.stroke!=null?"S":"f",t)}l(vo,"svgPath");function Mo(e,t){if(!(e instanceof ot))throw new TypeError("clip: not a path (use page.path())");let n=Eo(t);return this.content.op(`${e.pdf(this.height)||"0 0 0 0 re "}W${n?"*":""} n`),this}l(Mo,"clip");function Po(e){let t=this.doc.resource("Shading",wo(this,e));return this.content.op(`q 1 0 0 -1 0 ${F(this.height)} cm /${t} sh Q`),this}l(Po,"shade");function Ro(){let e=Ne(this),t=this.doc.pdfa?va:Fa;if(e.stack.length>=t)throw new RangeError(`page.save: at most ${t} nested saves${this.doc.pdfa?" in PDF/A":""}; restore() some first`);return!e.watched&&this.ref!=null&&!this.cell&&(e.watched=!0,this.onWrite(()=>{e.stack.length&&this.doc.warn(`Page ${this.number}: ${e.stack.length} page.save() without a page.restore(); restored at the end of the page`)})),this.content.q(),e.stack.push(e.m),this}l(Ro,"save");function Oo(){let e=Ne(this);if(!e.stack.length)throw new Error("page.restore: there is no page.save() to restore");return this.content.Q(),e.m=e.stack.pop(),this}l(Oo,"restore");function Ft(e,t,n,r,o,s){let i=[e,t,n,r,o,s];i.forEach(u=>{if(typeof u!="number"||!(Math.abs(u)<1e9))throw new RangeError(`transform: ${u} is not a usable number`)});let a=this.height,c=[e,-t,-n,r,n*a+o,a-r*a-s],f=Ne(this),h=St(i,f.m);return this.content.op(`${kt(c)} cm`),f.m=h,this}l(Ft,"transform");function Do(e,t){return Ft.call(this,1,0,0,1,e,t)}l(Do,"translate");function Io(e){return F(e),Ft.call(this,Math.cos(e),Math.sin(e),-Math.sin(e),Math.cos(e),0,0)}l(Io,"rotate");function No(e,t=e){return Ft.call(this,e,0,0,t,0,0)}l(No,"scale");function Uo(e,t=0){return F(e),F(t),Ft.call(this,1,Math.tan(t),Math.tan(e),1,0,0)}l(Uo,"skew");function jo(e,t){if(typeof t!="function")throw new TypeError("page.figure({ alt }, fn): fn draws the figure");if(this.doc.tagged&&!(typeof e?.alt=="string"&&e.alt.trim()))throw new TypeError('page.figure: a tagged PDF needs alt text for a figure ({ alt: "…" })');return this.tag("Figure",t,{alt:e?.alt})}l(jo,"figure");function Lo(e,t,n,r,o={}){let s=this.content,i=this.height,a=Ct(this,o);return s.draw(),s.et(),a&&(s.q(),s.s+=a),s.stroke(Oe(o.color??0,!0,this.doc)),s.lineWidth(o.width??1),s.dash(o.dash),s.s+=`${F(e)} ${F(i-t)} m ${F(n)} ${F(i-r)} l S
84
+ `,a&&s.Q(),this}l(Lo,"line");function Bo(e,t,n,r,o={}){let s=this.content,i=o.fill??(o.stroke==null?0:null),a=o.stroke??null,c=Ct(this,o);return s.draw(),s.et(),c&&(s.q(),s.s+=c),i!=null&&s.fill(Oe(i,!1,this.doc)),a!=null&&(s.stroke(Oe(a,!0,this.doc)),s.lineWidth(o.width??1),s.dash(o.dash)),s.s+=`${F(e)} ${F(this.height-t-r)} ${F(n)} ${F(r)} re ${i!=null&&a!=null?"B":i!=null?"f":"S"}
85
+ `,c&&s.Q(),this}l(Bo,"rect");var wn=64;async function st(e,t,n){let r=[];for(let s=0;s<n.length;s+=wn){let i=n.slice(s,s+wn);r.push({ref:e.reserve(),first:i[0][0],last:i[i.length-1][0],body:`/${t} [${i.map(([a,c])=>`${a} ${c}`).join(" ")}]`})}for(;r.length>1;){let s=[];for(let i=0;i<r.length;i+=wn){let a=r.slice(i,i+wn);s.push({ref:e.reserve(),first:a[0].first,last:a[a.length-1].last,body:`/Kids [${a.map(c=>`${c.ref} 0 R`).join(" ")}]`})}for(let i of r)await e.write(i.ref,`<< ${i.body} /Limits [${i.first} ${i.last}] >>`);r=s}let o=r[0]??{ref:e.reserve(),body:`/${t} []`};return await e.write(o.ref,`<< ${o.body} >>`),o.ref}l(st,"writeTree");var Ho=new WeakMap;function yn(e,t,n){let r=Ho.get(e);r||Ho.set(e,r=new Map),r.set(t,n),e.catalog("Names",`<< ${[...r].map(([o,s])=>`${pe(o)} ${s} 0 R`).join(" ")} >>`)}l(yn,"setNames");var zo=["XYZ","Fit","FitH","FitV","FitR","FitB","FitBH","FitBV"],er=1e5,$n=1024;function ut(e,t,n){if(typeof t=="number"){if(!(Number.isInteger(t)&&t>=1))throw new RangeError(`${n}: page is a whole number from 1`);return t-1}return he(t,"page",e,"page")}l(ut,"pageIndex");function pt(e,t){typeof e=="string"&&(e={fit:e});let n=e?.fit??(e?.left!=null||e?.top!=null||e?.zoom!=null?"XYZ":"Fit");if(!zo.includes(n))throw new TypeError(`${t}: fit is one of ${zo.join(", ")}, not ${JSON.stringify(n)}`);let r=l(s=>{let i=e?.[s];return i==null?null:(F(i),i)},"n"),o={fit:n,left:r("left"),top:r("top"),right:r("right"),bottom:r("bottom"),zoom:r("zoom")};if(o.zoom!=null&&!(o.zoom>=0&&o.zoom<=64))throw new RangeError(`${t}: zoom is a factor 0–64 (1 = 100%, 0 = keep), not ${o.zoom}`);if(n==="FitR"&&!(o.left!=null&&o.top!=null&&o.right!=null&&o.bottom!=null&&o.right>o.left&&o.bottom>o.top))throw new RangeError(`${t}: FitR needs left < right and top < bottom (top-left space)`);return o}l(pt,"fitOf");function dt(e,t,n){let r=e.pageHeight(t);if(r===void 0)return null;let o=l(a=>a==null?"null":F(a),"x"),s=l(a=>a==null?"null":F(r-a),"y"),i=`${e.pageRef(t)} 0 R /${n.fit}`;switch(n.fit){case"XYZ":return`[${i} ${o(n.left)} ${s(n.top)} ${n.zoom?F(n.zoom):"null"}]`;case"FitH":case"FitBH":return`[${i} ${s(n.top)}]`;case"FitV":case"FitBV":return`[${i} ${o(n.left)}]`;case"FitR":return`[${i} ${o(n.left)} ${s(n.bottom)} ${o(n.right)} ${s(n.top)}]`;default:return`[${i}]`}}l(dt,"destArray");var Da=new TextEncoder;function _o(e,t){if(typeof e!="string"||!e)throw new TypeError(`${t}: a destination name is a non-empty string`);if(e.length>$n)throw new RangeError(`${t}: a destination name is at most ${$n} bytes (UTF-8)`);let n=Da.encode(e);if(n.length>$n)throw new RangeError(`${t}: a destination name is at most ${$n} bytes (UTF-8)`);let r="";for(let o of n)r+=String.fromCharCode(o);return r}l(_o,"keyOf");var Xo=l(e=>{let t="<";for(let n=0;n<e.length;n++)t+=e.charCodeAt(n).toString(16).padStart(2,"0");return`${t}>`},"hexOf"),Go=new WeakMap;function vt(e){let t=Go.get(e);return t||Go.set(e,t=Ia(e)),t}l(vt,"namedDests");function Ia(e){let t=new Map,n=new Map;return e.onFinish(async()=>{for(let[o,s]of n)t.has(o)||e.warn(`"${s}" is used as a destination but was never defined (pdf.destination)`);let r=[];for(let o of[...t.keys()].sort()){let s=t.get(o),i=dt(e,s.i,s.d);i?r.push([Xo(o),i]):e.warn(`The destination "${s.name}" points to page ${s.i+1}, but the PDF has ${e.pageCount} pages`)}r.length&&yn(e,"Dests",await st(e,"Names",r))}),{define(r,o,s){let i="pdf.destination",a=_o(r,i);if(t.has(a))throw new TypeError(`${i}: "${r}" is already defined (names are unique)`);if(t.size>=er)throw new RangeError(`${i}: at most ${er} named destinations`);t.set(a,{name:r,i:ut(e,o,i),d:pt(s,i)})},use(r,o){let s=_o(r,o);return n.size<er&&n.set(s,r),Xo(s)}}}l(Ia,"create");var Wo=new Set(["javascript","vbscript","data","file"]),Na=["http","https","mailto"],Ua=/^(javascript|js|launch|file|gotor|gotoe|submit|submitform|importdata|resetform|action|actions|rendition|movie|sound|hide|setocgstate|trans|goto3dview|richmediaexecute)$/i,Vo=["NextPage","PrevPage","FirstPage","LastPage"],qo=32768,Jo=1e4,tr={none:"N",invert:"I",outline:"O",push:"P"},nr={solid:"S",dashed:"D",beveled:"B",inset:"I",underline:"U"};function ja(e,t,n){if(typeof e!="string")throw new TypeError(`${n}: url is a string`);if(e.length>qo)throw new RangeError(`${n}: a URL is at most ${qo} characters`);if(/[\x00-\x1f\x7f]/.test(e))throw new TypeError(`${n}: the URL has a control character (refused: browsers drop them, which hides schemes like java\\tscript:)`);let r=e.replace(/^ +| +$/g,""),o=/^([a-z][a-z0-9+.-]*):/i.exec(r);if(!o)throw new TypeError(`${n}: the URL needs a scheme (https:, http: or mailto:), not ${JSON.stringify(r.slice(0,80))}`);let s=o[1].toLowerCase();if(Wo.has(s))throw new TypeError(`${n}: ${s}: URLs are never written (active content or local files)`);let i=[...Na];if(t!=null){if(!Array.isArray(t)||t.length>64)throw new TypeError(`${n}: allowSchemes is an array of scheme names`);for(let c of t){if(typeof c!="string"||!/^[a-z][a-z0-9+.-]{0,31}$/i.test(c))throw new TypeError(`${n}: allowSchemes: ${JSON.stringify(c)} is not a scheme name`);if(Wo.has(c.toLowerCase()))throw new TypeError(`${n}: allowSchemes cannot allow ${c}: (javascript:, vbscript:, data: and file: are never written)`);i.push(c.toLowerCase())}}if(!i.includes(s))throw new TypeError(`${n}: ${s}: URLs are not allowed (http, https and mailto are; widen with { allowSchemes: ['${s}'] })`);let a;try{a=new URL(r)}catch{throw new TypeError(`${n}: not a valid URL: ${JSON.stringify(r.slice(0,80))}`)}if(a.protocol!==`${s}:`)throw new TypeError(`${n}: the URL's scheme changed when normalised`);return a.href.replace(/[()'"<>\\`{}|^]/g,c=>`%${c.charCodeAt(0).toString(16).toUpperCase()}`)}l(ja,"checkUrl");function Ko(e,t){for(let n of Object.keys(e))if(Ua.test(n))throw new TypeError(`${t}: ${n}: JavaScript, Launch, GoToR, GoToE, SubmitForm, ImportData and other actions are never written (a PDF writer must not carry active content); targets are { url }, { page, fit… }, { dest } or { named }`)}l(Ko,"refuseActive");function Ue(e,t,n){let r=_e(e);if(!r)throw new TypeError(`${n}: an annotation colour is a gray level, '#rrggbb', [r, g, b] or [c, m, y, k] (not a spot or ICC colour)`);return nt(t,r.cs),`[${r.comps.map(F).join(" ")}]`}l(Ue,"colorArray");function rr(e,t,n){let r=Array.isArray(e)?e:[e];if(!r.length||r.length>Jo)throw new RangeError(`${n}: 1–${Jo} rectangles`);let o="",s=1/0,i=1/0,a=-1/0,c=-1/0;for(let f of r){let h=f?.x,u=f?.y,p=f?.width,m=f?.height;for(let $ of[h,u,p,m])F($);if(!(p>0&&m>0))throw new RangeError(`${n}: a rectangle's width and height are above 0`);let d=F(t-u),g=F(t-u-m),w=F(h),y=F(h+p);o+=`${w} ${d} ${y} ${d} ${w} ${g} ${y} ${g} `,s=Math.min(s,h),i=Math.min(i,u),a=Math.max(a,h+p),c=Math.max(c,u+m)}return{q:`[${o.trim()}]`,box:[s,i,a-s,c-i],list:r}}l(rr,"quadPoints");function Zo(e,t,n,r,o,s={}){let i=this.doc,a=this.height,c="page.link";for(let $ of[e,t,n,r])F($);let f=`[${F(e)} ${F(a-t-r)} ${F(e+n)} ${F(a-t)}]`;if(!o||typeof o!="object")throw new TypeError(`${c}: the target is { url }, { page, fit… }, { dest } or { named }`);Ko(o,c),Ko(s,c);let h=null,u=s.alt??null,p=-1,m=null;if(o.url!=null)h=`/A << /Type /Action /S /URI /URI ${ke(ja(o.url,Object.hasOwn(s,"allowSchemes")?s.allowSchemes:null,c))} >>`,u??=o.url;else if(o.dest!=null)h=`/Dest ${vt(i).use(o.dest,c)}`,u??=`Go to ${o.dest}`;else if(o.named!=null){let $=String(o.named);if(!Vo.includes($))throw new TypeError(`${c}: named is one of ${Vo.join(", ")}`);h=`/A << /Type /Action /S /Named /N /${$} >>`,u??=$.replace(/(?=[A-Z])/g," ").trim()}else if(o.page!=null){if(p=ut(i,o.page,`${c}: target.page`),!(Number.isInteger(p)&&p>=0))throw new RangeError(`${c}: target.page is a whole number from 1`);m=pt(o,c),u??=`Page ${p+1}`}else throw new TypeError(`${c}: the target is { url }, { page, fit… }, { dest } or { named }`);let d=" /Border [0 0 0]";if(s.border!=null){let $=s.border,A=$.width??1,D=$.style??"solid";if(F(A),!(A>=0&&A<=100))throw new RangeError(`${c}: border width is 0–100`);if(!Object.hasOwn(nr,D))throw new TypeError(`${c}: border style is one of ${Object.keys(nr).join(", ")}`);let N=$.dash!=null?or($.dash,c):"";d=` /BS << /Type /Border /W ${F(A)} /S /${nr[D]}${N?` /D ${N}`:""} >>${$.color!=null?` /C ${Ue($.color,i,c)}`:""}`}if(s.highlight!=null){if(!Object.hasOwn(tr,s.highlight))throw new TypeError(`${c}: highlight is one of ${Object.keys(tr).join(", ")}`);d+=` /H /${tr[s.highlight]}`}s.quadPoints!=null&&(d+=` /QuadPoints ${rr(s.quadPoints,a,c).q}`);let g=q(u),w=-1,y=this.annotate(($,A)=>{let D=h;if(!D){let N=dt(i,p,m);if(N===null&&!A)return;N===null&&i.warn(`A link points to page ${p+1}, but the PDF has ${i.pageCount} pages`),D=N===null?"":`/Dest ${N}`}return`<< /Type /Annot /Subtype /Link /F 4 /Rect ${f}${d} ${D} /Contents ${g}${w>=0?` /StructParent ${w}`:""} >>`});return i.tags&&(w=i.tags.link(this,y)),this}l(Zo,"link");function or(e,t){if(!Array.isArray(e)||!e.length||e.length>16||!e.every(n=>typeof n=="number"&&n>=0&&n<1e6)||!e.some(n=>n>0))throw new RangeError(`${t}: dash is 1–16 lengths ≥ 0, not all 0`);return`[${e.map(F).join(" ")}]`}l(or,"dashArray");var sr=65535,Vt=1e8,ar=64<<20,ir=1024,cr=l(()=>Re("node:zlib"),"nodeZlib"),La=32<<20,Ba={0:[1,2,4,8,16],2:[8,16],3:[1,2,4,8],4:[8,16],6:[8,16]},Ha={0:1,2:3,3:1,4:2,6:4},za=[[0,0,8,8],[4,0,8,8],[0,4,4,8],[2,0,4,4],[0,2,2,4],[1,0,2,2],[0,1,1,2]],bn=null;function _a(e,t,n){let r=cr();if(r?.crc32)return r.crc32(e.subarray(t,n));if(!bn){bn=new Uint32Array(256);for(let s=0;s<256;s++){let i=s;for(let a=0;a<8;a++)i=i&1?3988292384^i>>>1:i>>>1;bn[s]=i>>>0}}let o=4294967295;for(let s=t;s<n;s++)o=bn[(o^e[s])&255]^o>>>8;return(o^4294967295)>>>0}l(_a,"crc32");var lr=l(e=>e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10,"isPng"),Yo=l((e,t,n)=>e&&t?t*(1+Math.ceil(e*n/8)):0,"rawSize");function es(e){let t=l(i=>new TypeError(`PNG: ${i}`),"bad");if(!lr(e))throw t("no PNG signature");let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=null,o=8,s=!1;for(;!s;){if(o+12>e.length)throw t("truncated (the file ends inside a chunk, before IEND)");let i=n.getUint32(o),a=String.fromCharCode(e[o+4],e[o+5],e[o+6],e[o+7]);if(i>2147483647||o+12+i>e.length)throw t(`truncated or corrupt: the ${JSON.stringify(a)} chunk claims ${i} bytes, past the end of the file`);if(!/^[A-Za-z]{4}$/.test(a))throw t("corrupt chunk type");let c=e.subarray(o+8,o+8+i);if(_a(e,o+4,o+8+i)!==n.getUint32(o+8+i))throw t(`bad CRC in the ${a} chunk`);if(o+=12+i,!r&&a!=="IHDR")throw t("IHDR is not the first chunk");if(a==="IHDR"){if(r)throw t("two IHDR chunks");if(i!==13)throw t("IHDR is 13 bytes");let f=n.getUint32(o-i-4),h=n.getUint32(o-i),u=c[8],p=c[9];if(!(f>=1&&h>=1&&f<=sr&&h<=sr))throw t(`${f} × ${h} pixels: each side is 1–${sr}`);if(f*h>Vt)throw t(`${f} × ${h} is over ${Vt/1e6} megapixels`);let m=Ba[p];if(!m)throw t(`colour type ${p} does not exist (0, 2, 3, 4, 6)`);if(!m.includes(u))throw t(`bit depth ${u} is not allowed with colour type ${p} (${m.join(", ")})`);if(c[10]!==0||c[11]!==0||c[12]>1)throw t("unknown compression, filter or interlace method");r={w:f,h,depth:u,type:p,interlace:c[12]===1,palette:null,trns:null,idat:[]}}else if(a==="PLTE"){if(i%3||i===0||i>768)throw t("PLTE is 1–256 RGB entries");r.palette=c}else if(a==="tRNS"){let f=r.type===0?2:r.type===2?6:-1;if(r.type===3?!r.palette||i>r.palette.length/3:i!==f)throw t("tRNS does not fit the colour type");r.trns=c}else a==="IDAT"?r.idat.push(c):a==="IEND"&&(s=!0)}if(!r)throw t("no IHDR");if(r.type===3&&!r.palette)throw t("a palette image without PLTE");if(!r.idat.length)throw t("no image data (IDAT)");return r}l(es,"readPng");async function Qo(e,t,n,r=null){if(cr()&&t<=La)return Xa(e,t,n,r);let{Unzlib:o}=await qe(),s=0,i=!1,a=0,c=new o((u,p)=>{if(s+u.length>t)throw new TypeError(`PNG: the image data inflates past the ${t.toLocaleString("en")} bytes its header allows (corrupt, or a zip bomb)`);n&&n(u,s),s+=u.length,p&&(i=!0)});for(let u=0;u<e.length;u++){let p=e[u];a+=p.length;for(let m=0;m<p.length;m+=ir){try{c.push(p.subarray(m,Math.min(p.length,m+ir)),u===e.length-1&&m+ir>=p.length)}catch(d){throw d instanceof TypeError&&d.message.startsWith("PNG:")?d:new TypeError(`PNG: corrupt image data (${d.message})`)}r&&await r()}}if(!i||s!==t)throw new TypeError(`PNG: truncated image data (${s.toLocaleString("en")} of ${t.toLocaleString("en")} bytes)`);let f=c.p,h=c.s?.p;if(!(f instanceof Uint8Array)||typeof h!="number")throw new Error("PNG: internal: the inflater does not report where the zlib stream ends");return a-f.length+(h?1:0)}l(Qo,"inflateExact");async function Xa(e,t,n,r=null){let o=0;for(let c of e)o+=c.length;let s=e[0];if(e.length>1){s=new Uint8Array(o);let c=0;for(let f of e)s.set(f,c),c+=f.length}let i;try{i=cr().inflateSync(s,{info:!0,maxOutputLength:Math.max(1,t)})}catch(c){let f=c.code;throw f==="ERR_BUFFER_TOO_LARGE"?new TypeError(`PNG: the image data inflates past the ${t.toLocaleString("en")} bytes its header allows (corrupt, or a zip bomb)`):f==="Z_BUF_ERROR"?new TypeError("PNG: truncated image data (the zlib stream ends early)"):new TypeError(`PNG: corrupt image data (${c.message})`)}let a=new Uint8Array(i.buffer.buffer,i.buffer.byteOffset,i.buffer.length);if(a.length!==t)throw new TypeError(`PNG: truncated image data (${a.length.toLocaleString("en")} of ${t.toLocaleString("en")} bytes)`);return n&&n(a,0),r&&await r(),i.engine.bytesWritten}l(Xa,"inflateNode");var Ga=l(e=>{let t=0;return(n,r)=>{for(;t<r+n.length;t+=e+1)if(n[t-r]>4)throw new TypeError(`PNG: unknown row filter ${n[t-r]}`)}},"filterBytes");function Wa(e,t,n,r){let o=t.length;if(e>4)throw new TypeError(`PNG: unknown row filter ${e}`);if(!(e===0||e===2&&!n)){if(e===1||!n){for(let s=r;s<o;s++)t[s]+=e===3?t[s-r]>>1:t[s-r];return}if(e===2){for(let s=0;s<o;s++)t[s]+=n[s];return}if(e===3){for(let s=0;s<r;s++)t[s]+=n[s]>>1;for(let s=r;s<o;s++)t[s]+=t[s-r]+n[s]>>1;return}for(let s=0;s<r;s++)t[s]+=n[s];for(let s=r;s<o;s++){let i=t[s-r],a=n[s],c=n[s-r],f=a-c,h=i-c,u=f+h,p;p=f>>31,f=(f^p)-p,p=h>>31,h=(h^p)-p,p=u>>31,u=(u^p)-p,t[s]+=i^(i^(a^(a^c)&u-h>>31))&(h-f|u-f)>>31}}}l(Wa,"unfilterRow");function ts(e,t,n,r,o,s){let i=e.length,a=Math.min(n,i),c=0,f=0,h,u;for(let p=0;p<i;p++)h=e[p]<<24>>24,u=h>>31,f+=(h^u)-u;r[o]=0,r.set(e,o+1),c=f,f=0;for(let p=0;p<a;p++){let m=e[p];s[p]=m,h=m<<24>>24,u=h>>31,f+=(h^u)-u}for(let p=a;p<i;p++)h=e[p]-e[p-n]<<24>>24,s[p]=h,u=h>>31,f+=(h^u)-u;if(f<c&&(c=f,r[o]=1,r.set(s,o+1)),!!t){f=0;for(let p=0;p<i;p++)h=e[p]-t[p]<<24>>24,s[p]=h,u=h>>31,f+=(h^u)-u;f<c&&(c=f,r[o]=2,r.set(s,o+1)),f=0;for(let p=0;p<a;p++)h=e[p]-t[p]<<24>>24,s[p]=h,u=h>>31,f+=(h^u)-u;for(let p=a;p<i;p++){let m=e[p-n],d=t[p],g=t[p-n],w=d-g,y=m-g,$=w+y;u=w>>31,w=(w^u)-u,u=y>>31,y=(y^u)-u,u=$>>31,$=($^u)-u;let A=(y-w|$-w)>>31,D=d^(d^g)&$-y>>31;h=e[p]-(m^(m^D)&A)<<24>>24,s[p]=h,u=h>>31,f+=(h^u)-u}f<c&&(r[o]=4,r.set(s,o+1))}}l(ts,"filterRow");async function ns(e,t=ar){let{w:n,h:r,depth:o,type:s}=e,i=Ha[s],a=i*o,c=Math.max(1,a>>3),f=s===0||s===4||s===3?1:3,h=s===3?"indexed":f===1?"gray":"rgb",u=s===3&&e.trns?e.trns:null,p=e.trns&&(s===0||s===2)&&o===16?e.trns:null,m=s===4||s===6||!!u||!!p,d=null;if(e.trns&&(s===0||s===2)&&o<=8){let b=(1<<o)-1;d=[];for(let E=0;E<e.trns.length;E+=2){let C=Math.min(b,e.trns[E]<<8|e.trns[E+1]);d.push(C,C)}}let g={w:n,h:r,colors:f,bpc:o,abpc:u||p?8:o,space:h,palette:e.palette,mask:d};if(!m&&!e.interlace){let b=await Qo(e.idat,Yo(n,r,a),Ga(Math.ceil(n*a/8))),E=new Uint8Array(b),C=0;for(let v of e.idat){if(C>=b)break;E.set(v.subarray(0,b-C),C),C+=v.length}return{...g,filtered:!0,data:E}}let w=0,y=e.interlace?za.map(([b,E,C,v])=>[Math.ceil((n-b)/C),Math.ceil((r-E)/v),b,E,C,v]).filter(([b,E])=>b&&E):[[n,r,0,0,1,1]];for(let[b,E]of y)w+=Yo(b,E,a);let $=Math.ceil(n*a/8),A=Math.max(w,$*r);if(A>t)throw new TypeError(`PNG: ${n} × ${r} needs ${Math.round(A/1e6)} MB decoded; at most ${Math.round(t/1e6)} MB for an image with alpha or interlacing (embedImage's maxDecodedBytes)`);let D=o>>3,N=f*D,M=s===4||s===6,j=M?new Uint8Array(n*N):null,O=m?new Uint8Array(M?n*D:n):null,R=l((b,E)=>{if(!O)return E(b,null);if(p){let v=i*2;for(let L=0;L<n;L++){let H=0;for(;H<v&&b[L*v+H]===p[H];)H++;O[L]=H===v?0:255}return E(b,O)}if(u){let v=(1<<o)-1;for(let L=0;L<n;L++){let H=b[L*o>>3]>>8-o-(L*o&7)&v;O[L]=H<u.length?u[H]:255}return E(b,O)}let C=j;for(let v=0,L=0,H=0,S=0;v<n;v++){for(let P=0;P<N;P++)C[H++]=b[L++];for(let P=0;P<D;P++)O[S++]=b[L++]}return E(C,O)},"emit");return{...g,filtered:!1,alpha:m,rows:l(async b=>{let E=[],C=e.interlace?new Uint8Array($*r):null,v=0,L=0,H=0,S=Math.ceil(y[0][0]*a/8),P=new Uint8Array(S+1),U=new Uint8Array(S+1),I=l(async()=>{for(let _ of E.splice(0))for(let Y=0;Y<_.length;){let X=Math.min(_.length-Y,P.length-H);if(P.set(_.subarray(Y,Y+X),H),H+=X,Y+=X,H<P.length)break;let T=P.subarray(1);Wa(P[0],T,L?U.subarray(1):null,c);let[k,B,z,G,J,ee]=y[v];if(!C)await R(T,b);else{let te=(G+L*ee)*$;for(let ne=0;ne<k;ne++){let K=z+ne*J;if(a>=8)for(let Q=0,W=ne*c,Z=te+K*c;Q<c;Q++)C[Z+Q]=T[W+Q];else C[te+(K*a>>3)]|=(T[ne*a>>3]>>8-a-(ne*a&7)&(1<<a)-1)<<8-a-(K*a&7)}}[P,U]=[U,P],H=0,++L===B&&++v<y.length&&(L=0,S=Math.ceil(y[v][0]*a/8),P=new Uint8Array(S+1),U=new Uint8Array(S+1))}},"drain");if(await Qo(e.idat,w,_=>{E.push(_)},I),C)for(let _=0;_<r;_++)await R(C.subarray(_*$,(_+1)*$),b)},"rows")}}l(ns,"decodePng");var fr=l(e=>e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255,"isJpeg");function rs(e){let t=l(c=>new TypeError(`JPEG: ${c}`),"bad");if(!fr(e))throw t("no JPEG signature (FF D8)");let n=2,r=0,o=0,s=0,i=!1,a=1;for(;;){if(n>=e.length)throw t("truncated before the image data (no SOS marker)");if(e[n]!==255)throw t(`expected a marker at byte ${n}`);for(;n<e.length&&e[n]===255;)n++;if(n>=e.length)throw t("truncated");let c=e[n++];if(c===216||c===1||c>=208&&c<=215)continue;if(c===217)throw t("the image ends (EOI) before any image data");if(n+2>e.length)throw t("truncated inside a marker");let f=e[n]<<8|e[n+1];if(f<2||n+f>e.length)throw t(`marker FF${c.toString(16).toUpperCase()} claims ${f} bytes, past the end of the file (bogus length)`);let h=n+2,u=n+f;if(c>=192&&c<=207&&c!==196&&c!==200&&c!==204){if(s)throw t("two frame headers (SOF)");if(c>194)throw t(`frame type SOF${c-192} (lossless, hierarchical or arithmetic-coded) is not supported; baseline and progressive are`);if(f<8)throw t("SOF is too short");if(e[h]!==8)throw t(`${e[h]}-bit samples; PDF's DCTDecode takes 8-bit JPEGs`);if(o=e[h+1]<<8|e[h+2],r=e[h+3]<<8|e[h+4],s=e[h+5],f!==8+3*s)throw t(`SOF's length ${f} does not match its ${s} components`);if(s!==1&&s!==3&&s!==4)throw t(`${s} components; gray (1), RGB (3) and CMYK (4) are supported`);if(!r||!o)throw t(`${r} × ${o} pixels (a height set later by DNL is not supported)`);if(r*o>Vt)throw t(`${r} × ${o} is over ${Vt/1e6} megapixels`)}else if(c===238&&f>=7&&String.fromCharCode(...e.subarray(h,h+5))==="Adobe")i=!0;else if(c===225&&f>=16&&String.fromCharCode(...e.subarray(h,h+6))==="Exif\0\0")a=qa(e,h+6,u);else if(c===218){if(!s)throw t("image data (SOS) before the frame header (SOF)");return{w:r,h:o,comps:s,adobe:i,orientation:a,end:Va(e,u)}}n=u}}l(rs,"readJpeg");function Va(e,t){for(let n=e.indexOf(255,t);n>=0&&n+1<e.length;n=e.indexOf(255,n+1)){let r=e[n+1];if(!(r===0||r===255||r>=208&&r<=215)){if(r===217)return n+2;if(n+4>e.length)break;n+=1+(e[n+2]<<8|e[n+3])}}return e.length}l(Va,"imageEnd");function qa(e,t,n){let r=e[t]===73&&e[t+1]===73;if(!r&&!(e[t]===77&&e[t+1]===77))return 1;let o=l(c=>c+2<=n?r?e[c]|e[c+1]<<8:e[c]<<8|e[c+1]:-1,"u16"),i=l(c=>c+4<=n?r?(e[c]|e[c+1]<<8|e[c+2]<<16)+e[c+3]*2**24:e[c]*2**24+(e[c+1]<<16|e[c+2]<<8|e[c+3]):-1,"u32")(t+4);if(i<8||t+i+2>n)return 1;let a=o(t+i);for(let c=0;c<a;c++){let f=t+i+2+12*c;if(f+12>n)return 1;if(o(f)===274){let h=o(f+8);return h>=1&&h<=8?h:1}}return 1}l(qa,"exifOrientation");var os=256<<20,Ja=[null,[1,0,0,1,0,0],[-1,0,0,1,1,0],[-1,0,0,-1,1,1],[1,0,0,-1,0,1],[0,-1,-1,0,1,1],[0,-1,1,0,0,1],[0,1,1,0,0,0],[0,1,-1,0,1,0]];async function ls(e,t,n={}){let r=qn(t,"embedImage"),o=l(p=>n!=null&&Object.hasOwn(n,p)?n[p]:void 0,"own"),s={colorSpace:o("colorSpace"),maxDecodedBytes:o("maxDecodedBytes")??ar,compression:o("compression")??"default"};if(!(s.compression==="default"||s.compression==="fast"||Number.isInteger(s.compression)&&s.compression>=1&&s.compression<=9))throw new TypeError("embedImage: compression is 'default', 'fast' or a zlib level 1–9");if(!(Number.isSafeInteger(s.maxDecodedBytes)&&s.maxDecodedBytes>0))throw new TypeError("embedImage: maxDecodedBytes is a whole number of bytes > 0");if(r.length>os)throw new RangeError(`embedImage: at most ${os>>20} MB`);let i=ss.get(e);i||ss.set(e,i=new Map);let{key:a,copy:c}=await Za(r),f=`${a} ${s.colorSpace==null?"-":Ka(s.colorSpace)} ${s.maxDecodedBytes} ${s.compression}`,h=i.get(f);if(h&&(!h.copy||Ya(h.copy,r)))return h.img;let u=Qa(e,r,s);return h||i.set(f,{img:u,copy:c}),u.catch(()=>{i.get(f)?.img===u&&i.delete(f)}),u}l(ls,"embedImage");var ss=new WeakMap,is=new WeakMap,as=0,Ka=l(e=>e!==null&&typeof e=="object"?is.get(e)??(is.set(e,++as),as):`?${String(e)}`,"idOf");async function Za(e){let t=Re("node:crypto");if(t)return{key:t.createHash("sha256").update(e).digest("hex"),copy:null};let n=globalThis.crypto?.subtle;if(n)return{key:Array.from(new Uint8Array(await n.digest("SHA-256",e.slice())),s=>s.toString(16).padStart(2,"0")).join(""),copy:null};let r=2166136261,o=2538058380;for(let s=0;s<e.length;s++)r=Math.imul(r^e[s],16777619),o=Math.imul(o^e[s],1540483477)^o>>>15;return{key:`f${e.length}:${(r>>>0).toString(16)}${(o>>>0).toString(16)}`,copy:e.slice()}}l(Za,"digest");var Ya=l((e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},"same");async function Qa(e,t,n){let r=l(u=>{if(n.colorSpace!=null){let p=he(n.colorSpace,"icc",e,"ICC colour space (pdf.iccColorSpace)");if(p.n!==u)throw new TypeError(`embedImage: the image has ${u} colour components, the ICC colour space ${p.n}`);return p.cs}return nt(e,be[u]),be[u]},"space"),o=e.reserve(),s=[],i,a,c=1,f=!1;if(fr(t)){let u=rs(t);({w:i,h:a,orientation:c}=u);let p=u.comps===4&&u.adobe?" /Decode [1 0 1 0 1 0 1 0]":"";s.push([o,`<< /Type /XObject /Subtype /Image /Width ${i} /Height ${a} /ColorSpace ${r(u.comps)} /BitsPerComponent 8 /Filter /DCTDecode${p} >>`,t.subarray(0,u.end)])}else if(lr(t)){let u=await ns(es(t),n.maxDecodedBytes);({w:i,h:a}=u);let p;if(u.space==="indexed"){let R=u.palette,x=1<<u.bpc,b="";for(let E=0;E<x*3;E++)b+=(E<R.length?R[E]:0).toString(16).padStart(2,"0");p=`[/Indexed ${r(3)} ${x-1} <${b}>]`}else p=r(u.colors);let m=u.space==="rgb"?3:1,d=Math.ceil(i*m*u.bpc/8),g=Math.max(1,m*u.bpc>>3),w=l((R,x)=>` /DecodeParms << /Predictor 15${R!==1?` /Colors ${R}`:""}${x!==8?` /BitsPerComponent ${x}`:""} /Columns ${i} >>`,"parms"),y=u.abpc,$=i*y>>3,A,D=null;if(u.filtered)A=[u.data,w(m,u.bpc)];else{let R=n.compression==="fast"?1:n.compression==="default"?i*a>2e6?3:6:n.compression,x=cs(a,d,g,w(m,u.bpc),R),b=u.alpha?cs(a,$,Math.max(1,y>>3),w(1,y),R):null;try{await u.rows(async(E,C)=>{await Promise.all([x.row(E),b&&C?b.row(C):null])}),[A,D]=await Promise.all([x.end(),b?b.end():null])}catch(E){throw x.abort(),b?.abort(),E}}let[N,M]=A,j="";if(D&&Ke(e,"embedImage: an image with transparency (an alpha channel)","forbids soft masks (transparency); flatten the image onto its background first"),(u.bpc===16||u.abpc===16)&&Ke(e,"embedImage: a 16-bit image","is PDF 1.4, which has 8 bits a component at most"),D){let R=e.reserve();s.push([R,`<< /Type /XObject /Subtype /Image /Width ${i} /Height ${a} /ColorSpace /DeviceGray /BitsPerComponent ${y} /Filter /FlateDecode${D[1]} >>`,D[0]]),j=` /SMask ${R} 0 R`,f=!0}let O=u.mask?` /Mask [${u.mask.join(" ")}]`:"";s.push([o,`<< /Type /XObject /Subtype /Image /Width ${i} /Height ${a} /ColorSpace ${p} /BitsPerComponent ${u.bpc} /Filter /FlateDecode${M}${j}${O} >>`,N])}else throw new TypeError("embedImage: not a JPEG or PNG file");await e.serial(async()=>{for(let[u,p,m]of s)await e.write(u,p,m)});let h=c>=5;return ye(Object.freeze({type:"image",width:h?a:i,height:h?i:a}),"image",e,{ref:o,w:h?a:i,h:h?i:a,orient:Ja[c],alpha:f})}l(Qa,"embed");function cs(e,t,n,r,o){let s=Vr(o),i=Math.max(1,Math.floor((1<<20)/(t+1))),a=new Uint8Array(t),c=e*t<=262144?new Uint8Array(e*t):null,f=[new Uint8Array(i*(t+1)),new Uint8Array(i*(t+1))],h=[Promise.resolve(),Promise.resolve()],u=0,p=f[0],m=0,d=0,g=new Uint8Array(t);return{async row(w){ts(w,d?g:null,n,p,m*(t+1),a),g.set(w),c&&c.set(w,d*t),d++,++m===i&&(h[u]=s.push(p),u^=1,m=0,await h[u],p=f[u])},async end(){m&&await s.push(p.subarray(0,m*(t+1))),await h[u^1];let w=await s.end();if(!c)return[w,r];let y=await et(c,o);return y.length<=w.length+r.length?[y,""]:[w,r]},abort:l(()=>s.abort(),"abort")}}l(cs,"encoder");function fs(e,t={}){let n=this,r=n.doc.base??n.doc,o=he(e,"image",r,"image (pdf.embedImage)"),s=t.x??0,i=t.y??0;for(let A of[s,i,t.width??1,t.height??1])F(A);if(t.width!=null&&!(t.width>0)||t.height!=null&&!(t.height>0))throw new RangeError("page.image: width and height are > 0");let a=t.width??(t.height!=null?t.height*o.w/o.h:o.w),c=t.height??(t.width!=null?t.width*o.h/o.w:o.h),f=t.fit??"fill";if(f!=="fill"&&f!=="contain"&&f!=="cover")throw new TypeError(`page.image: fit is 'fill', 'contain' or 'cover', not ${JSON.stringify(f)}`);let h=a,u=c;if(f!=="fill"){let A=(f==="contain"?Math.min:Math.max)(a/o.w,c/o.h);h=o.w*A,u=o.h*A}let p=s+(a-h)/2,m=i+(c-u)/2;if(this.doc.tagged&&t.alt!=null&&!(typeof t.alt=="string"&&t.alt.trim()))throw new TypeError("page.image: alt is a non-empty string");let d=Ct(n,{opacity:t.opacity});o.alpha&&Wt(n);let g=n.doc.resource("XObject",`${o.ref} 0 R`),w=kt(St(o.orient,[h,0,0,u,p,n.height-m-u])),y=f==="cover"?`${F(s)} ${F(n.height-i-c)} ${F(a)} ${F(c)} re W n `:"",$=l(()=>n.content.op(`q ${d.trim()}${d?" ":""}${y}${w} cm /${g} Do Q`),"draw");return t.alt!=null&&n.doc.tagged?n.tag("Figure",$,{alt:t.alt}):$(),n}l(fs,"image");var Te={invisible:1,hidden:2,print:4,noZoom:8,noRotate:16,noView:32,readOnly:64,locked:128,toggleNoView:256,lockedContents:512},hs=1e6;function gt(e,t){if(!(e instanceof Date)||isNaN(+e))throw new TypeError(`${t}: a date is a valid Date`);return ht(e)}l(gt,"dateOf");function it(e,t,n,r={}){let o=r.flags??Te.print;if(t.flags!=null){if(typeof t.flags!="object")throw new TypeError(`${n}: flags is { print, hidden, noView, locked, … }`);for(let[a,c]of Object.entries(t.flags)){if(!Object.hasOwn(Te,a))throw new TypeError(`${n}: unknown flag ${JSON.stringify(a)} (${Object.keys(Te).join(", ")})`);let f=Te[a];o=c?o|f:o&~f}}if(e.pdfa&&(!(o&Te.print)||o&(Te.invisible|Te.hidden|Te.noView|Te.toggleNoView)))throw new TypeError(`${n}: PDF/A annotations are printed and visible (print on; hidden, invisible, noView and toggleNoView off)`);let s=t.contents??r.contents;if(s!=null&&(typeof s!="string"||s.length>hs))throw new TypeError(`${n}: contents is a string of at most ${hs} characters`);if(e.tagged&&!s?.trim())throw new TypeError(`${n}: a tagged PDF (PDF/UA) needs contents (the annotation's description) for every annotation`);if(t.author!=null&&(typeof t.author!="string"||t.author.length>4096))throw new TypeError(`${n}: author is a string of at most 4096 characters`);let i=t.color??r.color;return`/F ${o}${i!=null?` /C ${Ue(i,e,n)}`:""}${s!=null?` /Contents ${q(s)}`:""}${t.author!=null?` /T ${q(t.author)}`:""}${t.modified!=null?` /M ${gt(t.modified,n)}`:""}`}l(it,"shared");var hr=l(e=>()=>{throw new TypeError(`page.${e} cannot be used in an annotation's appearance`)},"no");function Ze(e,t,n,r){let o=e.doc,s=Object.create(Object.getPrototypeOf(e));Object.assign(s,{doc:o,index:e.index,number:e.number,width:t,height:n,ref:e.ref,content:new tt,entries:new Map,annots:[],writers:[],ended:!1,cell:!0,onWrite:l(u=>e.onWrite(u),"onWrite"),tag:l((u,p)=>p(),"tag"),figure:l((u,p)=>p(),"figure"),link:hr("link"),annotate:hr("annotate"),end:hr("end")});let i=r(s);if(i&&typeof i.then=="function")throw new TypeError("An appearance is drawn synchronously (no async function)");let a=s.content.end(),c=s.entries.get("Group"),f=o.reserve(),h=`<< /Type /XObject /Subtype /Form /BBox [0 0 ${F(t)} ${F(n)}] /Resources ${o.resourcesRef} 0 R${c?` /Group ${c}`:""} >>`;return e.onWrite(()=>o.writeStream(f,h,$e(a))),f}l(Ze,"appearance");function Ye(e,t,n,r,o,s){let i=e.doc,a=e.height,[c,f,h,u]=n;for(let w of n)F(w);if(!(h>0&&u>0))throw new RangeError("page: an annotation's width and height are above 0");let p=`[${F(c)} ${F(a-f-u)} ${F(c+h)} ${F(a-f)}]`,m=s?Ze(e,h,u,s):0,d=-1,g=e.annotate(()=>`<< /Type /Annot /Subtype /${t} /Rect ${p} /P ${e.ref} 0 R ${o}${r}${m?` /AP << /N ${m} 0 R >>`:""}${d>=0?` /StructParent ${d}`:""} >>`);return i.tags&&(d=i.tags.link(e,g,"Annot")),ye(Object.freeze({type:"annotation",subtype:t}),"annotation",i,{ref:g})}l(Ye,"addAnnot");var us=["Comment","Key","Note","Help","NewParagraph","Paragraph","Insert"],ps=["Approved","Experimental","NotApproved","AsIs","Expired","NotForPublicRelease","Confidential","Final","Sold","Departmental","ForComment","TopSecret","Draft","ForPublicRelease"],ds=["None","Square","Circle","Diamond","OpenArrow","ClosedArrow","Butt","ROpenArrow","RClosedArrow","Slash"],ys=1e5,gs=1e4,ur=l((e,t,n)=>e.outputIntent==="CMYK"?n:t,"dflt");function pr(e,t){let n=[e?.x??0,e?.y??0,e?.width,e?.height];for(let r of n)if(typeof r!="number")throw new TypeError(`${t}: x, y, width and height are numbers`);return n}l(pr,"boxOf");function $s(e,t,n=1){let r=e??n;if(F(r),!(r>=0&&r<=100))throw new RangeError(`${t}: lineWidth is 0–100`);return r}l($s,"widthOf");function bs(e,t,n={}){let r="page.note",o=this.doc,s=n.icon??"Note";if(!us.includes(s))throw new TypeError(`${r}: icon is one of ${us.join(", ")}`);let i=n.replyTo!=null?` /IRT ${he(n.replyTo,"annotation",o,"annotation").ref} 0 R /RT /R`:"",a=n.color??ur(o,"#ffd84d",[0,.12,.75,0]),c=it(o,n,r,{flags:Te.print|Te.noZoom|Te.noRotate,color:a});return Ye(this,"Text",[e,t,20,20],` /Name /${s}${n.open?" /Open true":" /Open false"}${i}`,c,f=>{let h={stroke:.2,width:1};s==="Comment"?f.fillAndStroke(f.path().roundedRect(1.5,1.5,17,12,2).moveTo(5,13.5).lineTo(5,18.5).lineTo(10,13.5),{fill:a,...h,join:"round"}):s==="Help"?f.fillAndStroke(f.path().arc(10,10,8.5,0,2*Math.PI),{fill:a,...h}):f.fillAndStroke(f.path().moveTo(1.5,1.5).lineTo(18.5,1.5).lineTo(18.5,13.5).lineTo(13.5,18.5).lineTo(1.5,18.5).closePath(),{fill:a,...h,join:"round"}),s==="Help"?f.stroke(f.path().moveTo(7.2,7.5).bezierCurveTo(7.2,3.8,12.8,3.8,12.8,7.5).bezierCurveTo(12.8,9.8,10,9.8,10,12.2).moveTo(10,14).lineTo(10,15.6),{...h,width:1.6}):f.stroke(f.path().moveTo(4.5,5.5).lineTo(15.5,5.5).moveTo(4.5,8.5).lineTo(15.5,8.5).moveTo(4.5,11.5).lineTo(s==="Comment"?15.5:12,11.5),h)})}l(bs,"note");function An(e,t,n){let r=`page.${e[0].toLowerCase()}${e.slice(1)}`;return function(o,s={}){let i=this.doc,{q:a,box:c,list:f}=rr(o,this.height,r),h=s.color??ur(i,t,n),u=it(i,s,r,{color:h}),[p,m,,d]=c;return Ye(this,e,c,` /QuadPoints ${a}`,u,g=>{let w=g.path();for(let y of f){let $=y.x-p,A=y.y-m,D=y.width,N=y.height,M=Math.max(.5,N/14);if(e==="Highlight")w.rect($,A,D,N);else if(e==="Underline")w.rect($,A+N-M*1.5,D,M);else if(e==="StrikeOut")w.rect($,A+N*.55-M/2,D,M);else{let j=Math.min(2e3,Math.max(1,Math.round(D/Math.max(1,N/5)))),O=D/j,R=A+N-M*2,x=Math.max(.75,N/16);w.moveTo($,R);for(let b=1;b<=j;b++)w.lineTo($+b*O,R+(b%2?x:-x)/2)}}e==="Highlight"?g.fill(w,{fill:h,blendMode:"Multiply"}):e==="Squiggly"?g.stroke(w,{stroke:h,width:Math.max(.5,d/28)}):g.fill(w,{fill:h})})}}l(An,"textMarkup");var As=An("Highlight","#ffeb3b",[0,0,.8,0]),xs=An("Underline","#1a9a1a",[.8,0,1,.1]),Ts=An("StrikeOut","#d32f2f",[0,.9,.85,.1]),Es=An("Squiggly","#d32f2f",[0,.9,.85,.1]);function Ss(e,t){let n="page.freeText",r=this.doc;if(typeof e!="string")throw new TypeError(`${n}: the text is a string`);let o=pr(t,n),[,,s,i]=o;he(t?.font,"font",r,"font");let a=t.size??12;if(F(a),!(a>0))throw new RangeError(`${n}: size is above 0`);let c=t.align??"left",f=["left","center","right"].indexOf(c);if(f<0)throw new TypeError(`${n}: align is left, center or right`);let h=t.border===!1?0:$s(t.border?.width,n),u=(t.border&&t.border.color)??0,p=t.padding??2;F(p);let m=t.textColor??0,d=`${pe(t.font.name)} ${F(a)} Tf ${_e(m)?Oe(m,!1,r):"0 g"}`,g=it(r,t,n,{contents:e,color:t.background??void 0}),w=h+p;return Ye(this,"FreeText",o,` /DA ${e0(d)} /Q ${f} /BS << /W ${F(h)} >>`,g,y=>{t.background!=null&&y.fill(y.path().rect(0,0,s,i),{fill:t.background}),h>0&&y.stroke(y.path().rect(h/2,h/2,s-h,i-h),{stroke:u,width:h}),e&&s-2*w>0&&(y.save(),y.clip(y.path().rect(h,h,s-2*h,i-2*h)),y.textBox(e,{x:w,y:w,width:s-2*w,height:Math.max(0,i-2*w),font:t.font,size:a,color:m,align:c}),y.restore())})}l(Ss,"freeText");var e0=l(e=>{let t="<";for(let n=0;n<e.length;n++)t+=(e.charCodeAt(n)&255).toString(16).padStart(2,"0");return`${t}>`},"asciiHex");function ms(e,t,n,r){if(!Array.isArray(e)||e.length<n)throw new TypeError(`${t}: at least ${n} points [[x, y], …]`);if((r.left-=e.length)<0)throw new RangeError(`${t}: at most ${ys} points`);return e.map(o=>{let s=Array.isArray(o)?o[0]:o?.x,i=Array.isArray(o)?o[1]:o?.y;return F(s),F(i),[s,i]})}l(ms,"pointsOf");function ws(e,t,n,r,o,s,i,a,c){let f=-s,h=o,u=e.path(),p=t==="ClosedArrow"||t==="RClosedArrow"||t==="Square"||t==="Circle"||t==="Diamond";if(t==="OpenArrow"||t==="ClosedArrow")u.moveTo(n-i*o+i/2*f,r-i*s+i/2*h).lineTo(n,r).lineTo(n-i*o-i/2*f,r-i*s-i/2*h);else if(t==="ROpenArrow"||t==="RClosedArrow")u.moveTo(n+i*o+i/2*f,r+i*s+i/2*h).lineTo(n,r).lineTo(n+i*o-i/2*f,r+i*s-i/2*h);else if(t==="Square")u.rect(n-i/2,r-i/2,i,i);else if(t==="Circle")u.arc(n,r,i/2,0,2*Math.PI);else if(t==="Diamond")u.moveTo(n,r-i/2).lineTo(n+i/2,r).lineTo(n,r+i/2).lineTo(n-i/2,r);else if(t==="Butt")u.moveTo(n+i/2*f,r+i/2*h).lineTo(n-i/2*f,r-i/2*h);else if(t==="Slash"){let m=Math.cos(Math.PI/6),d=Math.sin(Math.PI/6),g=m*f+d*o,w=m*h+d*s;u.moveTo(n+i/2*g,r+i/2*w).lineTo(n-i/2*g,r-i/2*w)}else return;p&&u.closePath(),p&&c!=null?e.fillAndStroke(u,{...a,fill:c}):e.stroke(u,a)}l(ws,"ending");function ks(e,t,n={}){let r=`page.markup('${e}')`,o=this.doc,s=this.height,i=$s(n.lineWidth,r),a=n.dash!=null?or(n.dash,r):"",c=n.color??0,f=it(o,n,r,{color:c}),h=n.interior!=null?` /IC ${Ue(n.interior,o,r)}`:"",u=` /BS << /W ${F(i)} /S /${a?"D":"S"}${a?` /D ${a}`:""} >>`,p={stroke:c,width:i,dash:n.dash??void 0,join:"round",cap:"round"},m=n.interior??null;if(e==="Square"||e==="Circle"){let x=pr(t,r),[,,b,E]=x;return Ye(this,e,x,`${u}${h}`,f,C=>{let v=e==="Square"?C.path().rect(i/2,i/2,b-i,E-i):C.path().ellipse(b/2,E/2,Math.max(0,(b-i)/2),Math.max(0,(E-i)/2),0,0,2*Math.PI);m!=null?C.fillAndStroke(v,{...p,fill:m}):i>0&&C.stroke(v,p)})}let d,g={left:ys};if(e==="Line"){let x=[t?.x1,t?.y1,t?.x2,t?.y2];for(let b of x)F(b);d=[[[x[0],x[1]],[x[2],x[3]]]]}else if(e==="Polygon"||e==="PolyLine")d=[ms(t,r,e==="Polygon"?3:2,g)];else if(e==="Ink"){if(!Array.isArray(t)||!t.length||t.length>gs)throw new TypeError(`${r}: 1–${gs} strokes [[[x, y], …], …]`);d=t.map(x=>ms(x,r,1,g))}else throw new TypeError(`page.markup: type is Square, Circle, Line, Polygon, PolyLine or Ink, not ${JSON.stringify(e)}`);let w=n.lineEndings??["None","None"];if(n.lineEndings!=null&&(e==="Polygon"||e==="Ink"))throw new TypeError(`${r}: lineEndings are for Line and PolyLine`);if(!Array.isArray(w)||w.length!==2||!w.every(x=>ds.includes(x)))throw new TypeError(`${r}: lineEndings is [start, end], each one of ${ds.join(", ")}`);let y=4+3*i,$=i+(w[0]!=="None"||w[1]!=="None"?y:0)+1,A=1/0,D=1/0,N=-1/0,M=-1/0;for(let x of d)for(let[b,E]of x)A=Math.min(A,b),D=Math.min(D,E),N=Math.max(N,b),M=Math.max(M,E);A-=$,D-=$,N+=$,M+=$;let j=l(x=>x.map(([b,E])=>`${F(b)} ${F(s-E)}`).join(" "),"list"),O=e==="Line"?` /L [${j(d[0])}]`:e==="Ink"?` /InkList [${d.map(x=>`[${j(x)}]`).join(" ")}]`:` /Vertices [${j(d[0])}]`,R=e==="Line"||e==="PolyLine"?` /LE [/${w[0]} /${w[1]}]`:"";return Ye(this,e,[A,D,N-A,M-D],`${O}${R}${u}${e!=="Ink"?h:""}`,f,x=>{for(let b of d){let E=x.path().moveTo(b[0][0]-A,b[0][1]-D);b.length===1&&E.lineTo(b[0][0]-A+.01,b[0][1]-D);for(let C=1;C<b.length;C++)E.lineTo(b[C][0]-A,b[C][1]-D);e==="Polygon"&&E.closePath(),e==="Polygon"&&m!=null?x.fillAndStroke(E,{...p,fill:m}):i>0&&x.stroke(E,p)}if(R){let b=d[0],E=b.length,C=l((P,U)=>{let I=U[0]-P[0],_=U[1]-P[1],Y=Math.hypot(I,_)||1;return[I/Y,_/Y]},"dir"),[v,L]=C(b[1],b[0]),[H,S]=C(b[E-2],b[E-1]);ws(x,w[0],b[0][0]-A,b[0][1]-D,v,L,y,{...p,dash:void 0},m),ws(x,w[1],b[E-1][0]-A,b[E-1][1]-D,H,S,y,{...p,dash:void 0},m)}})}l(ks,"markup");function Cs(e){let t="page.stamp",n=this.doc,r=pr(e,t),[,,o,s]=r,i=e.name??(e.draw?null:"Draft");if(i!=null&&!ps.includes(i))throw new TypeError(`${t}: name is one of ${ps.join(", ")}`);let a=i?i.replace(/(?<=[a-z])(?=[A-Z])/g," ").toUpperCase():"",c=e.color??ur(n,"#c62828",[0,.9,.85,.15]),f=e.draw;if(f!=null&&typeof f!="function")throw new TypeError(`${t}: draw is a function (ap) => { … }`);if(!f){let u=he(e.font,"font",n,"font (a standard stamp draws its label: pass font, or draw your own appearance)"),p=Math.max(1,Math.min(o,s)/14);f=l(m=>{m.stroke(m.path().roundedRect(p,p,o-2*p,s-2*p,Math.min(o,s)*.15),{stroke:c,width:p});let d=Math.min(s*.5,(o-6*p)/Math.max(.01,e.font.widthOf(a,1)));d>0&&m.text(a,{x:(o-e.font.widthOf(a,d))/2,y:s/2+.35*d-u.ascent*d,font:e.font,size:d,color:c})},"draw")}let h=it(n,e,t,{color:c,contents:a?a[0]+a.slice(1).toLowerCase():void 0});return Ye(this,"Stamp",r,i?` /Name /${i}`:"",h,f)}l(Cs,"stamp");var t0=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}<>:"|?*]/u,n0=/[^\S ]| {3}/,r0=/[\u2215\u2044\u29F8\uFF0F\u29F5\uFF3C\u2216\u2571\u2572\u27CB\u27CD\u3033\u3035]/,o0=/[։۔܁܂።᙮᠃᠉․⸳⸼。ꓸ꘎︒﹒.。··‧]/,s0=/^(con|prn|aux|nul|conin\$|conout\$|clock\$|com[0-9¹²³]|lpt[0-9¹²³])$/i,dr=["pdf","png","jpg","jpeg","gif","webp","tif","tiff","txt","csv","tsv","json","md","odt","ods","odp","docx","xlsx","pptx","ics","vcf","eml"],xn={pdf:["application/pdf"],png:["image/png"],jpg:["image/jpeg","image/pjpeg"],jpeg:["image/jpeg","image/pjpeg"],gif:["image/gif"],webp:["image/webp"],tif:["image/tiff"],tiff:["image/tiff"],txt:["text/plain"],csv:["text/csv"],tsv:["text/tab-separated-values"],json:["application/json"],md:["text/markdown","text/x-markdown"],odt:["application/vnd.oasis.opendocument.text"],ods:["application/vnd.oasis.opendocument.spreadsheet"],odp:["application/vnd.oasis.opendocument.presentation"],docx:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],xlsx:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pptx:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],ics:["text/calendar"],vcf:["text/vcard","text/x-vcard"],eml:["message/rfc822"],zip:["application/zip","application/x-zip-compressed"]},i0=new TextEncoder;function qt(e,t,n,r=!1){if(typeof e!="string")throw new TypeError(`${n}: name (the file name) is a string`);if(e.length>4096)throw new RangeError(`${n}: a file name is at most 255 bytes (UTF-8)`);let o=new Set(dr),s=new Set,i=Object.hasOwn(t,"allowTypes")?t.allowTypes:null;if(Object.hasOwn(t,"allowArchives")&&t.allowArchives===!0&&o.add("zip"),i!=null){if(!Array.isArray(i)||i.length>64)throw new TypeError(`${n}: allowTypes is an array of extensions`);for(let h of i){if(typeof h!="string"||!/^[a-z0-9]{1,16}$/i.test(h))throw new TypeError(`${n}: allowTypes: ${JSON.stringify(h)} is not an extension (letters and digits, no dot)`);o.add(h.toLowerCase()),!dr.includes(h.toLowerCase())&&h.toLowerCase()!=="zip"&&s.add(h.toLowerCase())}}vs(e,n);let a=(e.split(/[/\\]/).pop()??"").normalize("NFC").replace(/[. ]+$/,"");Fs(a,o,s,t,n);let c="",f="<";for(let h of a){let u=h.codePointAt(0)??95,p=u>=32&&u<127?u:95;c+=String.fromCharCode(p),f+=p.toString(16).padStart(2,"0")}if(Fs(c,o,s,t,`${n} (its ASCII form ${JSON.stringify(c)})`),!r&&qt(a,t,n,!0).name!==a)throw new Error(`${n}: internal: the checked name is not stable`);return{name:a,ascii:`${f}>`}}l(qt,"checkFileName");function vs(e,t){let n=l(s=>`U+${(s.codePointAt(0)??0).toString(16).toUpperCase().padStart(4,"0")}`,"u"),r=t0.exec(e);if(r)throw new TypeError(`${t}: the file name has a control, format, bidi or Windows-invalid character (${n(r[0])}), which can make it display or save as another name`);let o=n0.exec(e);if(o)throw new TypeError(`${t}: the file name has ${o[0]===" "?"3 spaces in a row (padding that can push the real extension out of view)":`a space other than U+0020 (${n(o[0])})`}`);for(let s of e){if(s==="."||s==="/"||s==="\\")continue;let i=s.normalize("NFKC");if(r0.test(s)||i.includes("/")||i.includes("\\"))throw new TypeError(`${t}: the file name has a character that looks like a slash (${n(s)})`);if(o0.test(s)||i.includes("."))throw new TypeError(`${t}: the file name has a character that looks like a dot (${n(s)})`)}}l(vs,"chars");function Fs(e,t,n,r,o){if(vs(e,o),/[/\\]/.test(e))throw new TypeError(`${o}: internal: a separator in the final name`);if(!e)throw new TypeError(`${o}: the file name is empty (after its directory and trailing dots and spaces are dropped)`);if(i0.encode(e).length>255)throw new RangeError(`${o}: a file name is at most 255 bytes (UTF-8)`);if(e.startsWith("."))throw new TypeError(`${o}: ${JSON.stringify(e)} starts with a dot (a hidden file or only an extension)`);let s=e.split(".");if(s0.test(s[0].replace(/ +$/,"")))throw new TypeError(`${o}: ${JSON.stringify(s[0])} is a Windows device name, not a file name`);let i=s.length>1?s[s.length-1].toLowerCase():"";if(!t.has(i))throw new TypeError(`${o}: ${i?`.${i}`:"a name without an extension"} is not an allowed type (${dr.join(", ")}; zip with allowArchives); pass allowTypes: ['${i||"ext"}'] to accept the risk of that type`);for(let c of s.slice(1,-1))if(/^[a-z][a-z0-9-]{0,15}$/i.test(c)&&!/^\d+$/.test(c)&&!t.has(c.toLowerCase()))throw new TypeError(`${o}: ${JSON.stringify(e)} has an inner extension .${c} that is not allowed (a double extension)`);let a=r.mimeType?.toLowerCase();if(a&&!n.has(i)&&!(Object.hasOwn(xn,i)?xn[i]:[]).includes(a))throw new TypeError(`${o}: the MIME type ${a} does not match the extension .${i} of ${JSON.stringify(e)} (${(Object.hasOwn(xn,i)?xn[i]:[]).join(" or ")||"no MIME type"}; a type in allowTypes takes any, at your risk)`)}l(Fs,"check");var Ms=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],a0=Array.from({length:64},(e,t)=>Math.floor(Math.abs(Math.sin(t+1))*2**32)|0);function Mt(e){let t=e.length,n=(t+8>>>6)+1<<6,r=new Uint8Array(n-(t&-64));r.set(e.subarray(t&-64)),r[t&63]=128;let o=new DataView(r.buffer);o.setUint32(r.length-8,t*8>>>0,!0),o.setUint32(r.length-4,Math.floor(t/2**29),!0);let s=1732584193,i=-271733879,a=-1732584194,c=271733878,f=new Int32Array(16),h=l((p,m)=>{for(let $=0;$<16;$++){let A=m+$*4;f[$]=p[A]|p[A+1]<<8|p[A+2]<<16|p[A+3]<<24}let d=s,g=i,w=a,y=c;for(let $=0;$<64;$++){let A,D;$<16?(A=g&w|~g&y,D=$):$<32?(A=y&g|~y&w,D=5*$+1&15):$<48?(A=g^w^y,D=3*$+5&15):(A=w^(g|~y),D=7*$&15);let N=d+A+a0[$]+f[D]|0;d=y,y=w,w=g,g=g+(N<<Ms[$]|N>>>32-Ms[$])|0}s=s+d|0,i=i+g|0,a=a+w|0,c=c+y|0},"block");for(let p=0;p+64<=(t&-64);p+=64)h(e,p);for(let p=0;p<r.length;p+=64)h(r,p);let u="";for(let p of[s,i,a,c])for(let m=0;m<4;m++)u+=(p>>>8*m&255).toString(16).padStart(2,"0");return u}l(Mt,"md5");var Ps=["PushPin","Paperclip","Graph","Tag"],Rs=256<<20;function Os(e,t={}){let n="page.attachFile",r=this,o=this.doc,s=o.pdfaLevel?.part;if(s===2)throw new TypeError(`${n}: PDF/A-2 does not allow attachments that are not themselves PDF/A files (which this library cannot check); attach files without pdfa`);if(s)throw new TypeError(`${n}: not in PDF/A-${s}: ${s===1?"PDF/A-1 forbids embedded files":"use pdf.attach, which lists the file in the catalog's /AF with its relationship"}`);let i=e instanceof ArrayBuffer?new Uint8Array(e.slice(0)):ArrayBuffer.isView(e)?new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)):null;if(!i)throw new TypeError(`${n}: the file is a Uint8Array, Buffer or ArrayBuffer`);if(i.length>Rs)throw new RangeError(`${n}: an attachment is at most ${Rs>>20} MB`);let a=t.mimeType;if(a!=null&&!(typeof a=="string"&&a.length<=127&&/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i.test(a)))throw new TypeError(`${n}: mimeType is type/subtype, like application/pdf`);let{name:c,ascii:f}=qt(t?.name,{mimeType:a,allowTypes:Object.hasOwn(t,"allowTypes")?t.allowTypes:null,allowArchives:Object.hasOwn(t,"allowArchives")&&t.allowArchives===!0},n);if(t.description!=null&&(typeof t.description!="string"||t.description.length>65536))throw new TypeError(`${n}: description is a string`);let h=t.icon??"PushPin";if(!Ps.includes(h))throw new TypeError(`${n}: icon is one of ${Ps.join(", ")}`);let u=`${t.created!=null?` /CreationDate ${gt(t.created,n)}`:""}${t.modified!=null?` /ModDate ${gt(t.modified,n)}`:""}`,p=t.x??0,m=t.y??0;F(p),F(m);let d=it(o,t,n,{flags:Te.print|Te.noZoom|Te.noRotate,contents:t.description??c,color:t.color??.25}),g=o.reserve(),w=o.reserve(),y=Mt(i),$=a?` /Subtype ${pe(a)}`:"";r.onWrite(async()=>{await o.writeStream(g,`<< /Type /EmbeddedFile${$} /Params << /Size ${i.length} /CheckSum <${y}>${u} >> >>`,i),await o.write(w,`<< /Type /Filespec /F ${f} /UF ${q(c)}${t.description!=null?` /Desc ${q(t.description)}`:""} /EF << /F ${g} 0 R /UF ${g} 0 R >> >>`)});let A=t.color??.25;return Ye(this,"FileAttachment",[p,m,14,20],` /FS ${w} 0 R /Name /${h}`,d,D=>{D.stroke(D.path().moveTo(9.5,6).lineTo(9.5,15).bezierCurveTo(9.5,17.5,4.5,17.5,4.5,15).lineTo(4.5,4).bezierCurveTo(4.5,.8,11.5,.8,11.5,4).lineTo(11.5,15.5).bezierCurveTo(11.5,20,2.5,20,2.5,15.5).lineTo(2.5,6),{stroke:A,width:1.2,cap:"round"})})}l(Os,"attachFile");var Ds=1e4,Is=32;function Ns(e){let t=[];return e.onFinish(async()=>{if(!t.length)return;let n=l(a=>a.map(c=>`${c.ref} 0 R`).join(" "),"refs"),r=t.filter(a=>!a.visible),o=t.filter(a=>a.locked),s=t.filter(a=>a.visible!==a.printable),i=s.length?` /AS [<< /Event /View /OCGs [${n(s)}] /Category [/View] >> << /Event /Print /OCGs [${n(s)}] /Category [/Print] >>]`:"";e.catalog("OCProperties",`<< /OCGs [${n(t)}] /D << /Name ${q("Default")} /Order [${n(t)}] /ON [${n(t.filter(a=>a.visible))}] /OFF [${n(r)}]${o.length?` /Locked [${n(o)}]`:""}${i} >> >>`)}),l(function(r,o={}){let s="pdf.layer";if(Ke(e,s,"forbids optional content (layers)"),typeof r!="string"||!r.trim()||r.length>1024)throw new TypeError(`${s}: name is a non-empty string of at most 1,024 characters`);if(o==null||typeof o!="object")throw new TypeError(`${s}: options are { visible, printable, locked }`);for(let m of["visible","printable","locked"])if(o[m]!=null&&typeof o[m]!="boolean")throw new TypeError(`${s}: ${m} is true or false`);let i=o.visible??!0,a=o.printable??i,c=o.locked??!1;if(e.pdfa&&i!==a)throw new TypeError(`${s}: PDF/A forbids the auto-states (/AS) that make a layer print-only or screen-only (ISO 19005-2 6.9): visible and printable must agree`);if(t.length>=Ds)throw new RangeError(`${s}: at most ${Ds} layers`);let f=e.reserve(),h=i!==a?` /Usage << /View << /ViewState /${i?"ON":"OFF"} >> /Print << /PrintState /${a?"ON":"OFF"} >> >>`:"",u=`<< /Type /OCG /Name ${q(r)}${h} >>`;e.serial(async()=>{await e.write(f,u)}).catch(()=>{}),t.push({ref:f,visible:i,printable:a,locked:c});let p=e.resource("Properties",`${f} 0 R`);return ye(Object.freeze({type:"layer",name:r}),"layer",e,{res:p})},"layer")}l(Ns,"createLayers");var gr=new WeakMap;function Us(e,t){let{res:n}=he(e,"layer",this.doc,"layer (pdf.layer)");if(typeof t!="function")throw new TypeError("page.layer: fn is a function that draws");let r=gr.get(this)??0;if(r>=Is)throw new RangeError(`page.layer: at most ${Is} nested layers`);let o=this.content,s=Ne(this).stack.length;o.closeMarked(),o.et(),o.s+=`/OC /${n} BDC
86
+ `,gr.set(this,r+1);try{let i=t();if(i&&typeof i.then=="function")throw new TypeError("page.layer: fn must draw synchronously (no async function)");if(Ne(this).stack.length!==s)throw new TypeError("page.layer: save() and restore() must balance inside fn (marked content and the graphics state nest)");return i}finally{gr.set(this,r),o.closeMarked(),o.et(),o.s+=`EMC
87
+ `}}l(Us,"pageLayer");var c0=new Set(["Document","Part","Art","Sect","Div","BlockQuote","Caption","TOC","TOCI","Index","NonStruct","Private","P","H","H1","H2","H3","H4","H5","H6","L","LI","Lbl","LBody","Table","TR","TH","TD","THead","TBody","TFoot","Span","Quote","Note","Reference","BibEntry","Code","Link","Annot","Ruby","RB","RT","RP","Warichu","WT","WP","Figure","Formula","Form"]),js="artifact",Ls={TR:["Table","THead","TBody","TFoot"],TH:["TR"],TD:["TR"],THead:["Table"],TBody:["Table"],TFoot:["Table"],LI:["L"],Lbl:["LI"],LBody:["LI"],TOCI:["TOC"],RB:["Ruby"],RT:["Ruby"],RP:["Ruby","Warichu"],WT:["Warichu"],WP:["Warichu"]},Bs=["None","Disc","Circle","Square","Decimal","UpperRoman","LowerRoman","UpperAlpha","LowerAlpha"],Hs=["Pagination","Layout","Page"],zs=["Header","Footer","Watermark"],_s=65536,mr=1e5,l0=l((e,t)=>{if(typeof e!="string"||e.length>_s)throw new TypeError(`page.tag: ${t} is a string of at most ${_s} characters`);return e},"str"),Xs=l(e=>{if(typeof e!="string"||!/^[A-Za-z0-9_.:-]{1,64}$/.test(e))throw new TypeError(`page.tag: an id is 1–64 letters, digits, _ . : or -, not ${JSON.stringify(e)}`);return e},"idOf");function Gs(e,t){let n=e.reserve(),r=e.reserve(),o=[],s=new Int32Array(1024),i=0,a=0,c=l((d,g)=>{if(i+2>s.length){let w=new Int32Array(s.length*2);w.set(s),s=w}s[i++]=d,s[i++]=g},"num"),f=new WeakMap,h=new Map,u=new Set,p=0,m=!1;return e.onFinish(async()=>{await e.write(r,`<< /Type /StructElem /S /Document /P ${n} 0 R /K [${o.map(w=>`${w} 0 R`).join(" ")}] >>`);let d=e.reserve();await e.writeBig(d,"<< /Nums [",h0(s,i),"] >>");for(let w of u)if(!h.has(w))throw new TypeError(`page.tag: headers names ${JSON.stringify(w)}, which no element has as its id`);let g=h.size?` /IDTree ${await st(e,"Names",[...h].sort(([w],[y])=>w<y?-1:w>y?1:0).map(([w,y])=>[ke(w),`${y} 0 R`]))} 0 R`:"";await e.write(n,`<< /Type /StructTreeRoot /K ${r} 0 R /ParentTree ${d} 0 R /ParentTreeNextKey ${a}${g} >>`),e.catalog("StructTreeRoot",`${n} 0 R`),e.catalog("MarkInfo","<< /Marked true >>"),e.catalog("Lang",ke(String(t.lang||"en").replace(/[^A-Za-z0-9-]/g,"")||"en")),e.catalog("ViewerPreferences","<< /DisplayDocTitle true >>")}),{attach(d){let g={stack:[],mcids:[],els:[],links:!1};f.set(d,g),d.content.marker={current:l(()=>g.stack[g.stack.length-1]||js,"current"),open(w){if(w===js)return`/Artifact BMC
88
+ `;if(w.art)return`/Artifact ${w.art} BDC
89
+ `;let y=g.mcids.length;return g.mcids.push(w.ref),w.kids.push(y),`${pe(w.S)} <</MCID ${y}>> BDC
90
+ `}},d.onWrite(async()=>{for(let w of g.els){let y=w.kids.map(N=>typeof N=="number"?N:"objr"in N?`<< /Type /OBJR /Obj ${N.objr} 0 R >>`:`${N.ref} 0 R`).join(" "),$=w.o||{},A=`${$.scope?` /Scope ${pe($.scope)}`:""}${$.headers?` /Headers [${$.headers.map(ke).join(" ")}]`:""}${$.rowSpan?` /RowSpan ${$.rowSpan}`:""}${$.colSpan?` /ColSpan ${$.colSpan}`:""}`,D=`${$.alt!=null?` /Alt ${q($.alt)}`:""}${$.actualText!=null?` /ActualText ${q($.actualText)}`:""}${$.expansion!=null?` /E ${q($.expansion)}`:""}${$.lang?` /Lang ${ke($.lang)}`:""}${$.id?` /ID ${ke($.id)}`:""}${A?` /A << /O /Table${A} >>`:""}${$.listNumbering?` /A << /O /List /ListNumbering ${pe($.listNumbering)} >>`:""}`;await e.write(w.ref,`<< /S ${pe(w.S)} /P ${w.parent} 0 R /Pg ${e.pageRef(he(d,"page",e,"page"))} 0 R /K [${y}]${D} >>`)}if(g.mcids.length){let w=e.reserve();await e.write(w,`[${g.mcids.map(y=>`${y} 0 R`).join(" ")}]`),c(a,w),d.entries.set("StructParents",String(a++))}g.links&&d.entries.set("Tabs","/S"),f.delete(d)})},tag(d,g,w,y){if(!c0.has(g))throw new TypeError(`page.tag: "${g}" is not a standard structure type (P, H1…H6, Table, TR, TH, TD, L, LI, Link, Figure…)`);if(y?.scope&&!["Row","Column","Both"].includes(y.scope))throw new TypeError("page.tag: scope is Row, Column or Both");let $=f.get(d),A=$.stack[$.stack.length-1];if(A?.art)throw new TypeError(`page.tag: ${g} inside page.artifact: an artifact is not content and holds no structure`);y=f0(g,y);let D=Object.hasOwn(Ls,g)?Ls[g]:void 0;if(D&&!D.includes(A?.S))throw new TypeError(`page.tag: ${g} belongs inside ${D.join(", ")}, not ${A?A.S:"the Document"}`);if(/^H[1-6]?$/.test(g)){let M=Number(g[1]??0);if(M&&m||!M&&p)throw new TypeError("page.tag: a document uses H or H1–H6 for its headings, not both (PDF/UA 7.4.4)");if(M&&M>p+1)throw new TypeError(p?`page.tag: ${g} after H${p} skips a level (PDF/UA 7.4.2: headings go down one level at a time)`:`page.tag: the first heading is H1, not ${g} (PDF/UA 7.4.2)`);M?p=M:m=!0}let N={ref:e.reserve(),S:g,parent:A?A.ref:r,kids:[],o:y};if(y?.id){if(h.has(y.id))throw new TypeError(`page.tag: the id ${JSON.stringify(y.id)} is already used`);if(h.size>=mr)throw new RangeError(`page.tag: at most ${mr} ids`);h.set(y.id,N.ref)}if(y?.headers)for(let M of y.headers)u.size<mr&&u.add(M);A?A.kids.push(N):o.push(N.ref),$.els.push(N),$.stack.push(N);try{let M=w();if(M&&typeof M.then=="function")throw new TypeError("page.tag: fn must draw synchronously (no async function)");return M}finally{$.stack.pop()}},link(d,g,w="Link"){let y=f.get(d),$=y.stack[y.stack.length-1];if($?.art)throw new TypeError("An annotation inside page.artifact: annotations are content in a tagged PDF; draw it outside the artifact");if(!$||$.S!==w){let A=$;$={ref:e.reserve(),S:w,parent:A?A.ref:r,kids:[]},A?A.kids.push($):o.push($.ref),y.els.push($)}return $.kids.push({objr:g}),y.links=!0,c(a,$.ref),a++},artifact(d,g,w){let y=g?.type??"Pagination",$=g?.subtype;if(!Hs.includes(y))throw new TypeError(`page.artifact: type is ${Hs.join(", ")}`);if($!=null&&(y!=="Pagination"||!zs.includes($)))throw new TypeError(`page.artifact: subtype (${zs.join(", ")}) is for type Pagination`);let A=f.get(d);if(A.stack.length)throw new TypeError("page.artifact: inside page.tag: an artifact is not part of the structure; draw it outside any tag");A.stack.push({art:`<< /Type /${y}${$?` /Subtype /${$}`:""} >>`});try{let D=w();if(D&&typeof D.then=="function")throw new TypeError("page.artifact: fn must draw synchronously (no async function)");return D}finally{A.stack.pop()}}}}l(Gs,"createTagger");function f0(e,t){if(t==null)return t;if(typeof t!="object")throw new TypeError("page.tag: options are an object");for(let n of["alt","actualText","expansion"])t[n]!=null&&l0(t[n],n);if(t.lang!=null&&(typeof t.lang!="string"||!/^[A-Za-z]{1,8}(-[A-Za-z0-9]{1,8}){0,8}$/.test(t.lang)))throw new TypeError(`page.tag: lang is a language tag like "en" or "fr-CA", not ${JSON.stringify(t.lang)}`);if(t.id!=null&&Xs(t.id),t.scope!=null&&e!=="TH")throw new TypeError("page.tag: scope is for TH");if(t.headers!=null){if(e!=="TH"&&e!=="TD")throw new TypeError("page.tag: headers is for TD and TH");if(!Array.isArray(t.headers)||!t.headers.length||t.headers.length>64)throw new TypeError("page.tag: headers is an array of 1–64 TH ids");t.headers.forEach(Xs)}for(let n of["rowSpan","colSpan"])if(t[n]!=null){if(e!=="TH"&&e!=="TD")throw new TypeError(`page.tag: ${n} is for TD and TH`);if(!Number.isInteger(t[n])||t[n]<1||t[n]>1e4)throw new RangeError(`page.tag: ${n} is a whole number 1–10000`);F(t[n])}if(t.listNumbering!=null&&(e!=="L"||!Bs.includes(t.listNumbering)))throw new TypeError(`page.tag: listNumbering is for L, one of ${Bs.join(", ")}`);return{...t,headers:t.headers?[...t.headers]:void 0}}l(f0,"checkOptions");function*h0(e,t){for(let n=0;n<t;n+=4096){let r="";for(let o=n;o<Math.min(t,n+4096);o+=2)r+=`${e[o]} ${e[o+1]} 0 R `;yield r}}l(h0,"pairs");function Ws(e,t){if(typeof t!="function")throw new TypeError("page.artifact: fn is a function that draws");return this.doc.tags?this.doc.tags.artifact(this,e,t):t()}l(Ws,"artifact");var Vs=1e5,Pt=class{static{l(this,"Page")}constructor(t,n,r,o){this.doc=t,this.index=n,this.number=n+1,this.width=r,this.height=o,this.ref=t.pageRef(n),this.content=new tt,this.entries=new Map,this.annots=[],this.writers=[],this.ended=!1,t.tags?.attach(this),ye(this,"page",t,n)}annotate(t){if(this.#e(),this.annots.length>=Vs)throw new RangeError(`Page ${this.number}: at most ${Vs} annotations a page`);let n=this.doc.reserve();return this.annots.push({ref:n,make:t}),n}onWrite(t){this.#e(),this.writers.push(t)}tag(t,n,r){return this.#e(),this.doc.tags?this.doc.tags.tag(this,t,n,At(r)):n()}end(){return this.ended?Promise.resolve():(this.ended=!0,this.doc.queuePage(this))}#e(){if(this.ended)throw new Error(`Page ${this.number} has ended: nothing more can be drawn on it`)}};function Rt(e){for(let[t,n]of Object.entries(e))Pt.prototype[t]=function(...r){if(this.ended)throw new Error(`Page ${this.number} has ended: nothing more can be drawn on it`);return n.apply(this,r.map(At))}}l(Rt,"install");Rt({text:ao,line:Lo,rect:Bo,link:Zo});Rt({path:So,fill:ko,stroke:Co,fillAndStroke:Fo,svgPath:vo,clip:Mo,shade:Po,save:Ro,restore:Oo,transform:Ft,translate:Do,rotate:Io,scale:No,skew:Uo,figure:jo,linearGradient:go,radialGradient:mo,tilingPattern:yo});Rt({image:fs});Rt({textBox:co});Rt({note:bs,highlight:As,underline:xs,strikeOut:Ts,squiggly:Es,freeText:Ss,markup:ks,stamp:Cs,attachFile:Os});Rt({layer:Us,artifact:Ws});var qs={WinAnsi:[32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63,64,64,65,65,66,66,67,67,68,68,69,69,70,70,71,71,72,72,73,73,74,74,75,75,76,76,77,77,78,78,79,79,80,80,81,81,82,82,83,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,91,91,92,92,93,93,94,94,95,95,96,96,97,97,98,98,99,99,100,100,101,101,102,102,103,103,104,104,105,105,106,106,107,107,108,108,109,109,110,110,111,111,112,112,113,113,114,114,115,115,116,116,117,117,118,118,119,119,120,120,121,121,122,122,123,123,124,124,125,125,126,126,160,160,161,161,162,162,163,163,164,164,165,165,166,166,167,167,168,168,169,169,170,170,171,171,172,172,174,174,175,175,176,176,177,177,178,178,179,179,180,180,181,181,182,182,183,183,184,184,185,185,186,186,187,187,188,188,189,189,190,190,191,191,192,192,193,193,194,194,195,195,196,196,197,197,198,198,199,199,200,200,201,201,202,202,203,203,204,204,205,205,206,206,207,207,208,208,209,209,210,210,211,211,212,212,213,213,214,214,215,215,216,216,217,217,218,218,219,219,220,220,221,221,222,222,223,223,224,224,225,225,226,226,227,227,228,228,229,229,230,230,231,231,232,232,233,233,234,234,235,235,236,236,237,237,238,238,239,239,240,240,241,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255,338,140,339,156,352,138,353,154,376,159,381,142,382,158,402,131,710,136,732,152,8211,150,8212,151,8216,145,8217,146,8218,130,8220,147,8221,148,8222,132,8224,134,8225,135,8226,149,8230,133,8240,137,8249,139,8250,155,8364,128,8482,153],Symbol:[32,32,33,33,35,35,37,37,38,38,40,40,41,41,43,43,44,44,46,46,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63,91,91,93,93,95,95,123,123,124,124,125,125,160,32,172,216,176,176,177,177,181,109,215,180,247,184,402,166,913,65,914,66,915,71,916,68,917,69,918,90,919,72,920,81,921,73,922,75,923,76,924,77,925,78,926,88,927,79,928,80,929,82,931,83,932,84,933,85,934,70,935,67,936,89,937,87,945,97,946,98,947,103,948,100,949,101,950,122,951,104,952,113,953,105,954,107,955,108,956,109,957,110,958,120,959,111,960,112,961,114,962,86,963,115,964,116,965,117,966,102,967,99,968,121,969,119,977,74,978,161,981,106,982,118,8226,183,8230,188,8242,162,8243,178,8260,164,8364,160,8465,193,8472,195,8476,194,8486,87,8501,192,8592,172,8593,173,8594,174,8595,175,8596,171,8629,191,8656,220,8657,221,8658,222,8659,223,8660,219,8704,34,8706,182,8707,36,8709,198,8710,68,8711,209,8712,206,8713,207,8715,39,8719,213,8721,229,8722,45,8725,164,8727,42,8730,214,8733,181,8734,165,8736,208,8743,217,8744,218,8745,199,8746,200,8747,242,8756,92,8764,126,8773,64,8776,187,8800,185,8801,186,8804,163,8805,179,8834,204,8835,201,8836,203,8838,205,8839,202,8853,197,8855,196,8869,94,8901,215,8992,243,8993,245,9001,225,9002,241,9674,224,9824,170,9827,167,9829,169,9830,168,63193,211,63194,210,63195,212,63717,96,63718,189,63719,190,63720,226,63721,227,63722,228,63723,230,63724,231,63725,232,63726,233,63727,234,63728,235,63729,236,63730,237,63731,238,63732,239,63733,244,63734,246,63735,247,63736,248,63737,249,63738,250,63739,251,63740,252,63741,253,63742,254],ZapfDingbats:[32,32,160,32,8594,213,8596,214,8597,215,9312,172,9313,173,9314,174,9315,175,9316,176,9317,177,9318,178,9319,179,9320,180,9321,181,9632,110,9650,115,9660,116,9670,117,9679,108,9687,119,9733,72,9742,37,9755,42,9758,43,9824,171,9827,168,9829,170,9830,169,9985,33,9986,34,9987,35,9988,36,9990,38,9991,39,9992,40,9993,41,9996,44,9997,45,9998,46,9999,47,1e4,48,10001,49,10002,50,10003,51,10004,52,10005,53,10006,54,10007,55,10008,56,10009,57,10010,58,10011,59,10012,60,10013,61,10014,62,10015,63,10016,64,10017,65,10018,66,10019,67,10020,68,10021,69,10022,70,10023,71,10025,73,10026,74,10027,75,10028,76,10029,77,10030,78,10031,79,10032,80,10033,81,10034,82,10035,83,10036,84,10037,85,10038,86,10039,87,10040,88,10041,89,10042,90,10043,91,10044,92,10045,93,10046,94,10047,95,10048,96,10049,97,10050,98,10051,99,10052,100,10053,101,10054,102,10055,103,10056,104,10057,105,10058,106,10059,107,10061,109,10063,111,10064,112,10065,113,10066,114,10070,118,10072,120,10073,121,10074,122,10075,123,10076,124,10077,125,10078,126,10081,161,10082,162,10083,163,10084,164,10085,165,10086,166,10087,167,10102,182,10103,183,10104,184,10105,185,10106,186,10107,187,10108,188,10109,189,10110,190,10111,191,10112,192,10113,193,10114,194,10115,195,10116,196,10117,197,10118,198,10119,199,10120,200,10121,201,10122,202,10123,203,10124,204,10125,205,10126,206,10127,207,10128,208,10129,209,10130,210,10131,211,10132,212,10136,216,10137,217,10138,218,10139,219,10140,220,10141,221,10142,222,10143,223,10144,224,10145,225,10146,226,10147,227,10148,228,10149,229,10150,230,10151,231,10152,232,10153,233,10154,234,10155,235,10156,236,10157,237,10158,238,10159,239,10161,241,10162,242,10163,243,10164,244,10165,245,10166,246,10167,247,10168,248,10169,249,10170,250,10171,251,10172,252,10173,253,10174,254,63703,128,63704,129,63705,130,63706,131,63707,132,63708,133,63709,134,63710,135,63711,136,63712,137,63713,138,63714,139,63715,140,63716,141]},Tn={Helvetica:{encoding:"WinAnsi",familyName:"Helvetica",ascent:718,descent:-207,capHeight:718,xHeight:523,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-166,-225,1e3,931],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584,0,556,0,222,556,333,1e3,556,556,333,1e3,667,333,1e3,0,611,0,0,222,222,333,333,350,556,1e3,333,1e3,500,333,944,0,500,500,278,333,556,556,556,556,260,556,333,737,370,556,584,0,737,333,400,584,333,333,333,556,537,278,333,333,365,556,834,834,834,611,667,667,667,667,667,667,1e3,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,722,667,667,611,556,556,556,556,556,556,889,500,556,556,556,556,278,278,278,278,556,556,556,556,556,556,556,584,611,556,556,556,556,500,556,500]},"Helvetica-Bold":{encoding:"WinAnsi",familyName:"Helvetica",ascent:718,descent:-207,capHeight:718,xHeight:532,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-170,-228,1003,962],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584,0,556,0,278,556,500,1e3,556,556,333,1e3,667,333,1e3,0,611,0,0,278,278,500,500,350,556,1e3,333,1e3,556,333,944,0,500,556,278,333,556,556,556,556,280,556,333,737,370,556,584,0,737,333,400,584,333,333,333,611,556,278,333,333,365,556,834,834,834,611,722,722,722,722,722,722,1e3,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,722,667,667,611,556,556,556,556,556,556,889,556,556,556,556,556,278,278,278,278,611,611,611,611,611,611,611,584,611,611,611,611,611,556,611,556]},"Helvetica-Oblique":{encoding:"WinAnsi",familyName:"Helvetica",ascent:718,descent:-207,capHeight:718,xHeight:523,italicAngle:-12,underlinePosition:-100,underlineThickness:50,bbox:[-170,-225,1116,931],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584,0,556,0,222,556,333,1e3,556,556,333,1e3,667,333,1e3,0,611,0,0,222,222,333,333,350,556,1e3,333,1e3,500,333,944,0,500,500,278,333,556,556,556,556,260,556,333,737,370,556,584,0,737,333,400,584,333,333,333,556,537,278,333,333,365,556,834,834,834,611,667,667,667,667,667,667,1e3,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,722,667,667,611,556,556,556,556,556,556,889,500,556,556,556,556,278,278,278,278,556,556,556,556,556,556,556,584,611,556,556,556,556,500,556,500]},"Helvetica-BoldOblique":{encoding:"WinAnsi",familyName:"Helvetica",ascent:718,descent:-207,capHeight:718,xHeight:532,italicAngle:-12,underlinePosition:-100,underlineThickness:50,bbox:[-174,-228,1114,962],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584,0,556,0,278,556,500,1e3,556,556,333,1e3,667,333,1e3,0,611,0,0,278,278,500,500,350,556,1e3,333,1e3,556,333,944,0,500,556,278,333,556,556,556,556,280,556,333,737,370,556,584,0,737,333,400,584,333,333,333,611,556,278,333,333,365,556,834,834,834,611,722,722,722,722,722,722,1e3,722,667,667,667,667,278,278,278,278,722,722,778,778,778,778,778,584,778,722,722,722,722,667,667,611,556,556,556,556,556,556,889,556,556,556,556,556,278,278,278,278,611,611,611,611,611,611,611,584,611,611,611,611,611,556,611,556]},"Times-Roman":{encoding:"WinAnsi",familyName:"Times",ascent:683,descent:-217,capHeight:662,xHeight:450,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-168,-218,1e3,898],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,333,408,500,500,833,778,180,333,333,500,564,250,333,250,278,500,500,500,500,500,500,500,500,500,500,278,278,564,564,564,444,921,722,667,667,722,611,556,722,722,333,389,722,611,889,722,722,556,722,667,556,611,722,722,944,722,722,611,333,278,333,469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,541,0,500,0,333,500,444,1e3,500,500,333,1e3,556,333,889,0,611,0,0,333,333,444,444,350,500,1e3,333,980,389,333,722,0,444,500,250,333,500,500,500,500,200,500,333,760,276,500,564,0,760,333,400,564,300,300,333,500,453,250,333,300,310,500,750,750,750,444,722,722,722,722,722,722,889,667,611,611,611,611,333,333,333,333,722,722,722,722,722,722,722,564,722,722,722,722,722,722,556,500,444,444,444,444,444,444,667,444,444,444,444,444,278,278,278,278,500,500,500,500,500,500,500,564,500,500,500,500,500,500,500,500]},"Times-Bold":{encoding:"WinAnsi",familyName:"Times",ascent:683,descent:-217,capHeight:676,xHeight:461,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-168,-218,1e3,935],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,333,555,500,500,1e3,833,278,333,333,500,570,250,333,250,278,500,500,500,500,500,500,500,500,500,500,333,333,570,570,570,500,930,722,667,722,722,667,611,778,778,389,500,778,667,944,722,778,611,778,722,556,667,722,722,1e3,722,722,667,333,278,333,581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,520,0,500,0,333,500,500,1e3,500,500,333,1e3,556,333,1e3,0,667,0,0,333,333,500,500,350,500,1e3,333,1e3,389,333,722,0,444,500,250,333,500,500,500,500,220,500,333,747,300,500,570,0,747,333,400,570,300,300,333,556,540,250,333,300,330,500,750,750,750,500,722,722,722,722,722,722,1e3,722,667,667,667,667,389,389,389,389,722,722,778,778,778,778,778,570,778,722,722,722,722,722,611,556,500,500,500,500,500,500,722,444,444,444,444,444,278,278,278,278,500,556,500,500,500,500,500,570,500,556,556,556,556,500,556,500]},"Times-Italic":{encoding:"WinAnsi",familyName:"Times",ascent:683,descent:-217,capHeight:653,xHeight:441,italicAngle:-15.5,underlinePosition:-100,underlineThickness:50,bbox:[-169,-217,1010,883],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,333,420,500,500,833,778,214,333,333,500,675,250,333,250,278,500,500,500,500,500,500,500,500,500,500,333,333,675,675,675,500,920,611,611,667,722,611,611,722,722,333,444,667,556,833,667,722,611,722,611,500,556,722,611,833,611,556,556,389,278,389,422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,541,0,500,0,333,500,556,889,500,500,333,1e3,500,333,944,0,556,0,0,333,333,556,556,350,500,889,333,980,389,333,667,0,389,444,250,389,500,500,500,500,275,500,333,760,276,500,675,0,760,333,400,675,300,300,333,500,523,250,333,300,310,500,750,750,750,500,611,611,611,611,611,611,889,667,611,611,611,611,333,333,333,333,722,667,722,722,722,722,722,675,722,722,722,722,722,556,611,500,500,500,500,500,500,500,667,444,444,444,444,444,278,278,278,278,500,500,500,500,500,500,500,675,500,500,500,500,500,444,500,444]},"Times-BoldItalic":{encoding:"WinAnsi",familyName:"Times",ascent:683,descent:-217,capHeight:669,xHeight:462,italicAngle:-15,underlinePosition:-100,underlineThickness:50,bbox:[-200,-218,996,921],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,389,555,500,500,833,778,278,333,333,500,570,250,333,250,278,500,500,500,500,500,500,500,500,500,500,333,333,570,570,570,500,832,667,667,667,722,667,667,722,778,389,500,667,611,889,722,722,611,722,667,556,611,722,667,889,667,611,611,333,278,333,570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,570,0,500,0,333,500,500,1e3,500,500,333,1e3,556,333,944,0,611,0,0,333,333,500,500,350,500,1e3,333,1e3,389,333,722,0,389,444,250,389,500,500,500,500,220,500,333,747,266,500,606,0,747,333,400,570,300,300,333,576,500,250,333,300,300,500,750,750,750,500,667,667,667,667,667,667,944,667,667,667,667,667,389,389,389,389,722,722,722,722,722,722,722,570,722,722,722,722,722,611,611,500,500,500,500,500,500,500,722,444,444,444,444,444,278,278,278,278,500,556,500,500,500,500,500,570,500,556,556,556,556,444,500,444]},Courier:{encoding:"WinAnsi",familyName:"Courier",ascent:629,descent:-157,capHeight:562,xHeight:426,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-23,-250,715,805],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,0,600,600,600,600,600,600,600,600,600,600,600,0,600,0,0,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600]},"Courier-Bold":{encoding:"WinAnsi",familyName:"Courier",ascent:629,descent:-157,capHeight:562,xHeight:439,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-113,-250,749,801],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,0,600,600,600,600,600,600,600,600,600,600,600,0,600,0,0,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600]},"Courier-Oblique":{encoding:"WinAnsi",familyName:"Courier",ascent:629,descent:-157,capHeight:562,xHeight:426,italicAngle:-12,underlinePosition:-100,underlineThickness:50,bbox:[-27,-250,849,805],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,0,600,600,600,600,600,600,600,600,600,600,600,0,600,0,0,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600]},"Courier-BoldOblique":{encoding:"WinAnsi",familyName:"Courier",ascent:629,descent:-157,capHeight:562,xHeight:439,italicAngle:-12,underlinePosition:-100,underlineThickness:50,bbox:[-57,-250,869,801],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,0,600,600,600,600,600,600,600,600,600,600,600,0,600,0,0,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,0,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600]},Symbol:{encoding:"Symbol",familyName:"Symbol",ascent:1010,descent:-293,capHeight:1010,xHeight:0,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-180,-293,1090,1010],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,333,713,500,549,833,778,439,333,333,500,549,250,549,250,278,500,500,500,500,500,500,500,500,500,500,278,278,549,549,549,444,549,722,667,722,612,611,763,603,722,333,631,722,686,889,722,722,768,741,556,592,611,690,439,768,645,795,611,333,863,333,658,500,500,631,549,549,494,439,521,411,603,329,603,549,549,576,521,549,549,521,549,603,439,576,713,686,493,686,494,480,200,480,549,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,750,620,247,549,167,713,500,753,753,753,753,1042,987,603,987,603,400,549,411,549,549,713,494,460,549,549,549,549,1e3,603,1e3,658,823,686,795,987,768,768,823,768,768,713,713,713,713,713,713,713,768,713,790,790,890,823,549,250,713,603,603,1042,987,603,987,603,494,329,790,790,786,713,384,384,384,384,384,384,494,494,494,494,0,329,274,686,686,686,384,384,384,384,384,384,494,494,494,0]},ZapfDingbats:{encoding:"ZapfDingbats",familyName:"ZapfDingbats",ascent:820,descent:-143,capHeight:820,xHeight:0,italicAngle:0,underlinePosition:-100,underlineThickness:50,bbox:[-1,-143,981,820],widths:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,278,974,961,974,980,719,789,790,791,690,960,939,549,855,911,933,911,945,974,755,846,762,761,571,677,763,760,759,754,494,552,537,577,692,786,788,788,790,793,794,816,823,789,841,823,833,816,831,923,744,723,749,790,792,695,776,768,792,759,707,708,682,701,826,815,789,789,707,687,696,689,786,787,713,791,785,791,873,761,762,762,759,759,892,892,788,784,438,138,277,415,392,392,668,668,0,390,390,317,317,276,276,509,509,410,410,234,234,334,334,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,732,544,544,910,667,760,760,776,595,694,626,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,894,838,1016,458,748,924,748,918,927,928,928,834,873,828,924,924,917,930,931,463,883,836,836,867,867,696,696,874,0,874,760,946,771,865,771,888,967,888,831,873,927,970,918,0]}};var Js=Object.keys(Tn),u0={"\\(":40,"\\)":41,"\\\\":92,"\\r":13};function Ks(e,t){let n=typeof t=="string"&&Object.hasOwn(Tn,t)?Tn[t]:null;if(!n)throw new TypeError(`Not a standard font: ${t} (one of ${Js.join(", ")})`);if(e.pdfa||e.tagged)throw new TypeError(`PDF/A and PDF/UA need embedded fonts: ${t} is a standard font, which is not embedded. Use pdf.embedFont(bytes).`);let r=qs[n.encoding],o=new Map;for(let g=0;g<r.length;g+=2)o.set(r[g],r[g+1]);let s=n.widths,i=new Float64Array(256),a=new Uint8Array(256);for(let g=0;g<256;g++){let w=o.get(g);i[g]=w===void 0?-1:s[w]||0,a[g]=w===g&&bt(w)===String.fromCharCode(g)?1:0}let c=o.get(32)===32,f=e.reserve(),h=new Set,u=new Map,p=l(g=>{let w=u.get(g);if(w===void 0){let y=o.get(g.codePointAt(0));u.set(g,w=y===void 0?"":bt(y))}return w},"byte"),m={doc:e,ref:f,key:t,standard:!0,missing:h,name:e.resource("Font",`${f} 0 R`),ascent:n.ascent/1e3,descent:n.descent/1e3,widthOf(g,w){let y=0;for(let $ of String(g)){let A=o.get($.codePointAt(0));A!==void 0&&(y+=s[A]||0)}return y*w/1e3},widthOfText:l((g,w,y)=>gn(d,String(g??""),w,y),"widthOfText"),lineHeight:l(g=>1.2*g,"lineHeight"),encode(g){let w="";for(let y of g){let $=p(y);!$&&h.size<100&&h.add(y),w+=$}return w},async write(){await e.write(f,`<< /Type /Font /Subtype /Type1 /BaseFont ${cn(t)}${n.encoding==="WinAnsi"?" /Encoding /WinAnsiEncoding":""} /FirstChar 32 /LastChar 255 /Widths [${s.slice(32,256).map(g=>g||0).join(" ")}] >>`)}},d={standard:!0,ascent:n.ascent/1e3,lineHeight:1.2,has:l(g=>o.has(g),"has"),items(g,w){let y=!w.measure;if(!w.rtl){let M=0,j=0,O=0,R=!0;for(let x=0;x<g.length;x++){let b=g.charCodeAt(x);if(b>255){R=!1;break}let E=i[b];if(E<0){R=!1;break}if(M+=E,j++,b===32&&c&&O++,!a[b]){R=!1;break}}if(R)return{body:y?g:"",a:M,n:j,sp:O}}let $="",A=0,D=0,N=0;for(let M of w.rtl?[...g].reverse():g){let j=p(M);if(!j){y&&h.size<100&&h.add(M);continue}let O=j.length===1?j.charCodeAt(0):u0[j];y&&($+=j),D++,A+=s[O]||0,O===32&&N++}return{body:$,a:A,n:D,sp:N}}};return e.addFont(m),ye(Object.freeze(m),"font",e,d)}l(Ks,"standardFont");var Se=l(e=>new TypeError(`Broken font: ${e}`),"broken"),Zs=l((e,t)=>String.fromCharCode(e[t],e[t+1],e[t+2],e[t+3]),"tagOf");function at(e){if(e.length<12)throw new TypeError("Not a font: too short");let t=Zs(e,0);if(t==="ttcf")throw new TypeError("Font collections (.ttc) are not supported: pass a single font");if(t==="wOFF"||t==="wOF2")throw new TypeError("WOFF fonts are not supported: pass the TrueType or OpenType file");if(t!=="\0\0\0"&&t!=="OTTO"&&t!=="true")throw new TypeError("Not a TrueType or OpenType font");let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=new Map,o=n.getUint16(4);if(o===0||o>256||12+o*16>e.length)throw Se(`a directory of ${o} tables does not fit the file`);for(let s=0;s<o;s++){let i=12+s*16,a=Zs(e,i),c=n.getUint32(i+8),f=n.getUint32(i+12);if(c<12+o*16||c+f>e.length)throw Se(`table ${JSON.stringify(a)} lies outside the file`);if(r.has(a))throw Se(`table ${JSON.stringify(a)} appears twice`);r.set(a,e.subarray(c,c+f))}return r}l(at,"sfntTables");var Jt=l(e=>new DataView(e.buffer,e.byteOffset,e.byteLength),"view");function Kt(e,t=!0){let n=at(e),r=l((y,$)=>{let A=n.get(y);if(!A)throw Se(`no ${y} table`);if(A.length<$)throw Se(`the ${y} table is too short`);return Jt(A)},"need"),o=r("head",54),s=r("hhea",36),i=r("maxp",6),a=t?r("cmap",4):null,c=n.get("OS/2")?.length>=10?Jt(n.get("OS/2")):null,f=n.get("post")?.length>=16?Jt(n.get("post")):null,h=o.getUint16(18);if(h<16||h>16384)throw Se(`unitsPerEm ${h} is outside 16–16384`);let u=i.getUint16(4);if(!u)throw Se("it has no glyphs");let p=s.getUint16(34);if(!p||p>u)throw Se(`numberOfHMetrics ${p} does not fit ${u} glyphs`);let m=r("hmtx",4*p),d=l(y=>y<u?m.getUint16(4*Math.min(y,p-1)):0,"advance"),g=n.has("CFF ")||n.has("CFF2");if(!g&&!(n.has("glyf")&&n.has("loca")))throw Se("no glyf/loca and no CFF table");g||wr(n.get("loca"),o.getInt16(50),u,n.get("glyf").length);let w=a?d0(a):()=>0;return{tables:n,unitsPerEm:h,numGlyphs:u,cff:g,indexToLocFormat:o.getInt16(50),bbox:[o.getInt16(36),o.getInt16(38),o.getInt16(40),o.getInt16(42)],ascent:s.getInt16(4),descent:s.getInt16(6),lineGap:s.getInt16(8),capHeight:c&&c.byteLength>=90&&c.getUint16(0)>=2?c.getInt16(88):s.getInt16(4),xHeight:c&&c.byteLength>=88&&c.getUint16(0)>=2?c.getInt16(86):0,fsType:c?c.getUint16(8):0,italicAngle:f?f.getInt32(4)/65536:0,fixedPitch:f?f.getUint32(12)!==0:!1,postscriptName:p0(n.get("name")),advance:d,glyphFor:l(y=>{let $=w(y);return $<u?$:0},"glyphFor")}}l(Kt,"parseFont");function wr(e,t,n,r){if(t!==0&&t!==1)throw Se(`indexToLocFormat ${t} is neither 0 nor 1`);let o=Jt(e),s=t?4:2;if(e.length<(n+1)*s)throw Se(`loca has room for fewer than ${n+1} offsets`);let i=0;for(let a=0;a<=n;a++){let c=t?o.getUint32(a*4):o.getUint16(a*2)*2;if(c<i)throw Se(`loca goes backwards at glyph ${a}`);if(c>r)throw Se(`loca points past the end of glyf at glyph ${a}`);i=c}}l(wr,"checkLoca");function p0(e){if(!e||e.length<6)return"Font";let t=Jt(e),n=Math.min(t.getUint16(2),Math.floor((e.length-6)/12)),r=t.getUint16(4);for(let o=0;o<n;o++){let s=6+12*o;if(t.getUint16(s+6)!==6)continue;let i=t.getUint16(s),a=t.getUint16(s+8),c=r+t.getUint16(s+10),f=e.subarray(c,c+a),h="";if(i===1)for(let u of f)h+=String.fromCharCode(u);else for(let u=0;u+1<f.length;u+=2)h+=String.fromCharCode(f[u]<<8|f[u+1]);if(h)return h.slice(0,127)}return"Font"}l(p0,"psName");function d0(e){let t=e.byteLength,n=Math.min(e.getUint16(2),Math.floor((t-4)/8)),r={score:0,off:0};for(let m=0;m<n;m++){let d=e.getUint16(4+m*8),g=e.getUint16(6+m*8),w=e.getUint32(8+m*8);if(w+16>t)continue;let y=e.getUint16(w),$=d===0||d===3&&(g===1||g===10),D=y===12&&$?4:y===4&&$?3:y===4&&(d===3&&g===0)?2:0;D>r.score&&(r={score:D,off:w})}if(!r.score)throw new TypeError("The font has no Unicode character map (cmap format 4 or 12)");let o=r.off,s=new Map;if(e.getUint16(o)===12){let m=e.getUint32(o+12);if(o+16+m*12>t)throw Se("its cmap (format 12) runs past the table");return d=>{let g=s.get(d);if(g!==void 0)return g;let w=0,y=m-1;for(g=0;w<=y;){let $=w+y>>1,A=o+16+$*12;if(d<e.getUint32(A))y=$-1;else if(d>e.getUint32(A+4))w=$+1;else{g=e.getUint32(A+8)+d-e.getUint32(A);break}}return s.set(d,g),g}}let i=e.getUint16(o+6);if(i&1)throw Se(`its cmap (format 4) has an odd segCountX2 (${i})`);let a=i>>1,c=o+14,f=c+a*2+2,h=f+a*2,u=h+a*2;if(!a||u+a*2>t)throw Se("its cmap (format 4) runs past the table");let p=r.score===2;return m=>{let d=s.get(m);if(d!==void 0)return d;let g=p&&m<256?61440+m:m;if(d=0,g<=65535){let w=0,y=a-1;for(;w<y;){let A=w+y>>1;e.getUint16(c+A*2)<g?w=A+1:y=A}let $=e.getUint16(f+w*2);if(g>=$&&g<=e.getUint16(c+w*2)){let A=e.getUint16(h+w*2),D=e.getUint16(u+w*2);if(!D)d=g+A&65535;else{let N=u+w*2+D+(g-$)*2;d=N+2<=e.byteLength?e.getUint16(N):0,d&&(d=d+A&65535)}}}return s.set(m,d),d}}l(d0,"cmapLookup");var g0=["head","hhea","hmtx","maxp","cvt ","fpgm","prep","OS/2","name","gasp"],m0=["cvt ","fpgm","prep"];function Qs(e,t){return w0(e,t,!0)}l(Qs,"compactGlyf");function w0(e,t,n){let r=at(e),o=r.get("head"),s=r.get("loca"),i=r.get("glyf"),a=r.get("maxp"),c=r.get("hhea"),f=r.get("hmtx");if(!o||o.length<54||!s||!i||!a||a.length<6)throw new TypeError("Broken font: not a TrueType (glyf) font");let h=new DataView(o.buffer,o.byteOffset,o.byteLength),u=new DataView(s.buffer,s.byteOffset,s.byteLength),p=new DataView(i.buffer,i.byteOffset,i.byteLength),m=h.getInt16(50)===1,d=new DataView(a.buffer,a.byteOffset,a.byteLength).getUint16(4);wr(s,h.getInt16(50),d,i.length);let g=l(v=>m?u.getUint32(v*4):u.getUint16(v*2)*2,"at"),w=new Set([0]),y=[0],$=new Map;for(let v of t)Number.isInteger(v)&&v>=0&&v<d&&!w.has(v)&&(w.add(v),y.push(v));for(;y.length;){let v=y.pop(),L=g(v),H=g(v+1);if(H-L<10||p.getInt16(L)>=0)continue;let S=[];$.set(v,S);let P=L+10,U;do{if(P+4>H)throw new TypeError(`Broken font: composite glyph ${v} runs past its end`);U=p.getUint16(P);let I=p.getUint16(P+2);if(I>=d)throw new TypeError(`Broken font: composite glyph ${v} uses glyph ${I}, past the ${d} glyphs`);S.push(P+2-L),w.has(I)||(w.add(I),y.push(I)),P+=4+(U&1?4:2)+(U&8?2:U&64?4:U&128?8:0)}while(U&32)}let A=[...w].sort((v,L)=>v-L),D=new Map(A.map((v,L)=>[v,n?L:v])),N=0;for(let v of w)N+=g(v+1)-g(v)+3&-4;if(N>i.length+3*w.size)throw new TypeError("Broken font: its glyphs add up to more than glyf");let M=n?A.length:d,j=new Uint8Array(N),O=new Uint8Array((M+1)*4),R=new DataView(O.buffer),x=new DataView(j.buffer),b=0;for(let v=0,L=0;v<d;v++){if(!w.has(v)){n||R.setUint32(v*4,b);continue}R.setUint32((n?L++:v)*4,b);let H=g(v),S=g(v+1);j.set(i.subarray(H,S),b);for(let P of $.get(v)??[])x.setUint16(b+P,D.get(x.getUint16(b+P)));b+=S-H+3&-4}R.setUint32(M*4,b);let E=new Map;for(let v of n?m0:g0){let L=r.get(v);L&&E.set(v,L)}let C=new Uint8Array(o);if(new DataView(C.buffer).setInt16(50,1),E.set("head",C),E.set("loca",O),E.set("glyf",j),n){if(!c||c.length<36||!f)throw new TypeError("Broken font: no hhea or hmtx table");let v=new DataView(c.buffer,c.byteOffset,c.byteLength).getUint16(34);if(!v||v>d||f.length<4*v)throw new TypeError("Broken font: hmtx does not fit numberOfHMetrics");let L=new DataView(f.buffer,f.byteOffset,f.byteLength),H=new Uint8Array(4*M),S=new DataView(H.buffer);A.forEach((I,_)=>{let Y=I<v?4*I+2:4*v+2*(I-v);S.setUint16(4*_,L.getUint16(4*Math.min(I,v-1))),S.setInt16(4*_+2,Y+2<=f.length?L.getInt16(Y):0)});let P=new Uint8Array(c);new DataView(P.buffer).setUint16(34,M);let U=new Uint8Array(a);new DataView(U.buffer).setUint16(4,M),E.set("hhea",P),E.set("hmtx",H),E.set("maxp",U)}return{file:En(E),gid:D}}l(w0,"glyfSubset");function En(e,t=[0,1,0,0]){let n=[...e.keys()].sort(),r=n.length,o=2**Math.floor(Math.log2(r)),s=new Map,i=12+16*r;for(let f of n)s.set(f,i),i+=e.get(f).length+3&-4;let a=new Uint8Array(i),c=new DataView(a.buffer);return a.set(t,0),c.setUint16(4,r),c.setUint16(6,o*16),c.setUint16(8,Math.log2(o)),c.setUint16(10,r*16-o*16),n.forEach((f,h)=>{let u=12+16*h,p=e.get(f),m=s.get(f);for(let d=0;d<4;d++)a[u+d]=f.charCodeAt(d);a.set(p,m),f==="head"&&c.setUint32(m+8,0),c.setUint32(u+4,Ys(a,m,p.length+3&-4)),c.setUint32(u+8,m),c.setUint32(u+12,p.length)}),s.has("head")&&c.setUint32(s.get("head")+8,2981146554-Ys(a,0,a.length)>>>0),a}l(En,"buildSfnt");var Ys=l((e,t,n)=>{let r=new DataView(e.buffer,e.byteOffset+t,n),o=0;for(let s=0;s<n;s+=4)o=o+r.getUint32(s)>>>0;return o},"tableSum");var ce=l(e=>new TypeError(`Broken font: ${e}`),"broken"),$r=48,ei=10,Sn=65535,y0=1e6,Zt=32e6;function mt(e,t,n){if(t+2>e.length)throw ce(`the CFF ${n} INDEX lies outside the table`);let r=e[t]<<8|e[t+1];if(!r)return{count:r,os:0,p:t,at:l(()=>[0,0],"at"),end:t+2};let o=e[t+2];if(o<1||o>4)throw ce(`the CFF ${n} INDEX has offset size ${o}`);let s=t+3,i=s+(r+1)*o-1;if(s+(r+1)*o>e.length)throw ce(`the CFF ${n} INDEX says ${r} entries, more than the table holds`);let a=l(f=>{let h=0;for(let u=0;u<o;u++)h=h*256+e[s+f*o+u];return h},"off");if(a(0)!==1)throw ce(`the CFF ${n} INDEX does not start at offset 1`);let c=1;for(let f=1;f<=r;f++){let h=a(f);if(h<c)throw ce(`the CFF ${n} INDEX goes backwards at entry ${f}`);c=h}if(i+c>e.length)throw ce(`the CFF ${n} INDEX runs past the table`);return{count:r,os:o,p:t,at:l(f=>[i+a(f),i+a(f+1)],"at"),end:i+c}}l(mt,"readIndex");function yr(e,t,n){let r=new Map,o=[];for(let s=t;s<n;){let i=e[s];if(i<=21){let a=i===12?1200+e[s+1]:i;s+=i===12?2:1,r.set(a,o),o=[];continue}if(o.length>=$r)throw ce("a CFF DICT has more than 48 operands");if(s+(i===28?3:i===29?5:i>=247?2:1)>n)throw ce("a CFF DICT runs past its end");if(i===28)o.push((e[s+1]<<24|e[s+2]<<16)>>16),s+=3;else if(i===29)o.push(e[s+1]<<24|e[s+2]<<16|e[s+3]<<8|e[s+4]),s+=5;else if(i===30){for(s++;s<n&&(e[s]&15)!==15&&e[s]>>4!==15;)s++;s++,o.push(0)}else if(i>=32&&i<=246)o.push(i-139),s++;else if(i>=247&&i<=250)o.push((i-247)*256+e[s+1]+108),s+=2;else if(i>=251&&i<=254)o.push(-(i-251)*256-e[s+1]-108),s+=2;else throw ce(`a CFF DICT has the reserved byte ${i}`)}return r}l(yr,"readDict");var $0=l(e=>e<1240?107:e<33900?1131:32768,"bias");function Yt(e,t){if(e.length<4||e[0]!==1)throw ce(`the CFF table is not version 1 (${e[0]})`);let n=mt(e,e[2],"Name"),r=mt(e,n.end,"Top DICT");if(r.count<1)throw ce("the CFF table has no Top DICT");let o=mt(e,r.end,"String"),s=mt(e,o.end,"Global Subr"),i=yr(e,...r.at(0));if((i.get(1206)?.[0]??2)!==2)throw ce("the CFF charstrings are not Type 2");let a=i.get(17)?.[0];if(a==null||a<4)throw ce("the CFF table has no CharStrings");let c=mt(e,a,"CharStrings");if(t>=0&&c.count!==t)throw ce(`the CFF CharStrings has ${c.count} glyphs, maxp says ${t}`);let f=c.count,h=l(m=>{if(!m||m.length<2)return null;let[d,g]=m;if(d<0||g<0||g+d>e.length)throw ce("a CFF Private DICT lies outside the table");let w=yr(e,g,g+d).get(19)?.[0];return w?mt(e,g+w,"Subrs"):null},"localSubrs"),u=null,p;if(i.has(1230)){let m=i.get(1236)?.[0],d=i.get(1237)?.[0];if(m==null||d==null)throw ce("a CID-keyed CFF without FDArray or FDSelect");let g=mt(e,m,"FDArray"),w=[];for(let $=0;$<g.count;$++)w.push(h(yr(e,...g.at($)).get(18)));let y=b0(e,d,f,g.count);p=l($=>w[y($)],"subrsFor"),u=A0(e,i.get(15)?.[0]??0,f)}else{let m=h(i.get(18));p=l(()=>m,"subrsFor")}return{cs:c,gsubrs:s,subrsFor:p,cids:u,charset:u?i.get(15)?.[0]:-1}}l(Yt,"parseCff");function b0(e,t,n,r){if(t>=e.length)throw ce("the CFF FDSelect lies outside the table");let o=e[t];if(o===0){if(t+1+n>e.length)throw ce("the CFF FDSelect runs past the table");for(let a=0;a<n;a++)if(e[t+1+a]>=r)throw ce("the CFF FDSelect names a font DICT that does not exist");return a=>e[t+1+a]}if(o!==3)throw ce(`the CFF FDSelect has format ${o}`);let s=e[t+1]<<8|e[t+2];if(!s||t+5+s*3>e.length)throw ce("the CFF FDSelect runs past the table");let i=l(a=>e[t+3+a*3]<<8|e[t+4+a*3],"first");if(i(0)!==0)throw ce("the CFF FDSelect does not start at glyph 0");for(let a=0;a<s;a++){if(e[t+5+a*3]>=r)throw ce("the CFF FDSelect names a font DICT that does not exist");if(i(a+1)<=i(a)&&a+1<s)throw ce("the CFF FDSelect goes backwards")}return a=>{let c=0,f=s-1;for(;c<f;){let h=c+f+1>>1;i(h)<=a?c=h:f=h-1}return e[t+5+c*3]}}l(b0,"fdSelect");function A0(e,t,n){if(t<3||t>=e.length)throw ce("a CID-keyed CFF without a charset");let r=e[t],o=new Uint16Array(n),s=new Uint8Array(65536);s[0]=1;let i=1,a=t+1,c=l(u=>e[u]<<8|e[u+1],"u16"),f=l(u=>{if(u>65535||s[u])throw ce(`the CFF charset gives CID ${u} twice or past 65535`);s[u]=1,o[i++]=u},"set");if(r===0){if(a+(n-1)*2>e.length)throw ce("the CFF charset runs past the table");for(;i<n;)f(c(a)),a+=2;return o}if(r!==1&&r!==2)throw ce(`the CFF charset has format ${r}`);let h=r===1?3:4;for(;i<n;){if(a+h>e.length)throw ce("the CFF charset runs past the table");let u=c(a),p=r===1?e[a+2]:c(a+2);for(let m=0;m<=p&&i<n;m++)f(u+m);a+=h}return o}l(A0,"charsetCids");function br(e,t,n,r={left:Zt}){let o=t.subrsFor(n),[s,i]=t.cs.at(n);if(i-s>Sn)throw ce(`the charstring of glyph ${n} is ${i-s} bytes (at most ${Sn})`);let a=[],c=0,f=0,h=y0,u=0;for(;;){if(s>=i){if(!a.length)return!1;[s,i]=a.pop();continue}if(--h<0)throw ce(`the charstring of glyph ${n} runs too long (a subroutine loop?)`);if(--r.left<0)throw Object.assign(new RangeError(`Broken font: its CFF charstrings walk more than ${Zt} bytes in all (a font made to be slow?)`),{code:"E_FONT_BUDGET"});let p=e[s];if(p>=32||p===28){if(++c>$r)throw ce(`the charstring of glyph ${n} pushes more than ${$r} operands`);u=p===28?(e[s+1]<<24|e[s+2]<<16)>>16:p<=246?p-139:p<=250?(p-247)*256+e[s+1]+108:p<=254?-(p-251)*256-e[s+1]-108:0,s+=p===28?3:p<=246?1:p<=254?2:5;continue}if(s++,p===10||p===29){let m=p===10?o:t.gsubrs;if(!c)throw ce(`glyph ${n} calls a subroutine without its number`);if(!m||!m.count)throw ce(`glyph ${n} calls a subroutine that does not exist`);let d=u+$0(m.count);if(!(d>=0&&d<m.count))throw ce(`glyph ${n} calls subroutine ${d}, past the ${m.count}`);if(a.length>=ei)throw ce(`glyph ${n} nests subroutines deeper than ${ei}`);if(c--,a.push([s,i]),[s,i]=m.at(d),i-s>Sn)throw ce(`a subroutine of glyph ${n} is ${i-s} bytes (at most ${Sn})`);continue}if(p===11){if(!a.length)throw ce(`glyph ${n} returns from no subroutine`);[s,i]=a.pop();continue}if(p===14)return c>=4;p===1||p===3||p===18||p===23?f+=c>>1:p===19||p===20?(f+=c>>1,s+=f+7>>3):p===12&&s++,c=0}}l(br,"scanGlyph");function ti(e,t,n,r){let o=Yt(e,t),s=new Set([0]);for(let m of n)m<t&&s.add(m);if(r==null){let m={left:Zt};r=[...s].some(d=>br(e,o,d,m))}if(r)return null;let{cs:i}=o,a=i.os,c=o.cids?Ar(e,t):new Uint8Array(e),f=i.p+3,h=f+(i.count+1)*a,u=1,p=l((m,d)=>{for(let g=a-1;g>=0;g--,d=Math.floor(d/256))c[f+m*a+g]=d&255},"put");for(let m=0;m<i.count;m++){p(m,u);let[d,g]=i.at(m),w=s.has(m)||g===d?g-d:1;w===1&&!s.has(m)?c[h]=14:c.set(e.subarray(d,g),h),h+=w,u+=w}return p(i.count,u),c.fill(0,h,i.end),c}l(ti,"subsetCff");function Ar(e,t){let n=Yt(e,t),r=n.charset,o=new Uint8Array(e);if(t=n.cs.count,t<2)return o;if(e[r]===0)for(let s=1;s<t;s++)o[r+1+(s-1)*2]=s>>8,o[r+2+(s-1)*2]=s&255;else t-1<=256?o.set([1,0,1,t-2],r):o.set([2,0,1,t-2>>8,t-2&255],r);return o}l(Ar,"identityCharset");var Xe=l(e=>new TypeError(`Broken font: ${e}`),"broken"),kn=64,x0=4e6,xr=l(e=>{let t=0;for(let n=e&255;n;n>>=1)t+=n&1;return t*2},"vsize");function oi(e,t,n){let r=e.get("GPOS"),o=e.get("kern");if(r)try{let s=S0(r);if(s)return ni(s)}catch(s){n(`${s.message}: GPOS kerning is off`)}if(o)try{let s=k0(o,t);if(s)return ni(s)}catch(s){n(`${s.message}: kern-table kerning is off`)}return null}l(oi,"kerning");function ni(e){let t=new Map;return(n,r)=>{let o=n*65536+r,s=t.get(o);return s===void 0&&(t.size>65536&&t.clear(),t.set(o,s=e(n,r))),s}}l(ni,"memo");function si(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=x0;return{dv:n,need:l((s,i,a)=>{if((r-=1+(i>>6))<0)throw Xe(`${t} is too complex to check`);if(!(s>=0&&s+i<=e.length))throw Xe(`${t} ${a} lies outside the table`);return s},"need"),u16:l(s=>n.getUint16(s),"u16"),i16:l(s=>n.getInt16(s),"i16"),u32:l(s=>n.getUint32(s),"u32")}}l(si,"reader");function T0(e,t){let{u16:n,need:r}=e;r(t,4,"a coverage table");let o=n(t),s=n(t+2);if(o===1)return r(t+4,s*2,"a coverage table"),i=>{let a=0,c=s-1;for(;a<=c;){let f=a+c>>1,h=n(t+4+f*2);if(h<i)a=f+1;else if(h>i)c=f-1;else return f}return-1};if(o!==2)throw Xe(`GPOS has a coverage table of format ${o}`);return r(t+4,s*6,"a coverage table"),i=>{let a=0,c=s-1;for(;a<=c;){let f=a+c>>1,h=t+4+f*6;if(n(h+2)<i)a=f+1;else if(n(h)>i)c=f-1;else return n(h+4)+i-n(h)}return-1}}l(T0,"coverage");function ri(e,t){let{u16:n,need:r}=e;r(t,4,"a class definition");let o=n(t);if(o===1){r(t,6,"a class definition");let i=n(t+2),a=n(t+4);return r(t+6,a*2,"a class definition"),c=>c>=i&&c<i+a?n(t+6+(c-i)*2):0}if(o!==2)throw Xe(`GPOS has a class definition of format ${o}`);let s=n(t+2);return r(t+4,s*6,"a class definition"),i=>{let a=0,c=s-1;for(;a<=c;){let f=a+c>>1,h=t+4+f*6;if(n(h+2)<i)a=f+1;else if(n(h)>i)c=f-1;else return n(h+4)}return 0}}l(ri,"classDef");function E0(e,t){let{u16:n,i16:r,need:o}=e;o(t,10,"a pair adjustment");let s=n(t),i=T0(e,t+n(t+2)),a=n(t+4),c=n(t+6),f=xr(a),h=f+xr(c),u=a&4?xr(a&3):-1;if(s===1){let w=n(t+8);o(t+10,w*2,"a pair adjustment");for(let y=0;y<w;y++){let $=t+n(t+10+y*2);o($,2,"a pair set"),o($+2,n($)*(2+h),"a pair set")}return(y,$)=>{let A=i(y);if(A<0||A>=w)return;let D=t+n(t+10+A*2),N=n(D),M=0,j=N-1;for(;M<=j;){let O=M+j>>1,R=D+2+O*(2+h),x=n(R);if(x<$)M=O+1;else if(x>$)j=O-1;else return u<0?0:r(R+2+u)}}}if(s!==2)throw Xe(`GPOS has a pair adjustment of format ${s}`);o(t,16,"a pair adjustment");let p=ri(e,t+n(t+8)),m=ri(e,t+n(t+10)),d=n(t+12),g=n(t+14);return o(t+16,d*g*h,"a class pair adjustment"),(w,y)=>{if(i(w)<0)return;let $=p(w),A=m(y);return $>=d||A>=g||u<0?0:r(t+16+($*g+A)*h+u)}}l(E0,"pairPos");function S0(e){let t=si(e,"GPOS"),{u16:n,u32:r,need:o}=t;if(o(0,10,"header"),n(0)!==1)throw Xe(`GPOS version ${n(0)}`);let s=o(n(6),2,"feature list"),i=o(n(8),2,"lookup list"),a=n(s),c=n(i);o(s+2,a*6,"feature list"),o(i+2,c*2,"lookup list");let f=new Set;for(let m=0;m<a;m++){let d=s+2+m*6;if(String.fromCharCode(e[d],e[d+1],e[d+2],e[d+3])!=="kern")continue;let g=o(s+n(d+4),4,"a feature"),w=n(g+2);o(g+4,w*2,"a feature");for(let y=0;y<w;y++){let $=n(g+4+y*2);if($>=c)throw Xe(`GPOS 'kern' names lookup ${$}, past the ${c} lookups`);f.add($)}}let h=[],u=new Map,p=0;for(let m of[...f].sort((d,g)=>d-g)){let d=o(i+n(i+2+m*2),6,"a lookup"),g=n(d),w=n(d+4);if(g!==2&&g!==9)continue;o(d+6,w*2,"a lookup");let y=[];for(let $=0;$<w;$++){if(++p>kn)throw Xe(`GPOS kerning has more than ${kn} subtables`);let A=d+n(d+6+$*2);if(g===9){if(o(A,8,"an extension lookup"),n(A)!==1||n(A+2)!==2)continue;A+=r(A+4)}u.has(A)||u.set(A,E0(t,A)),y.push(u.get(A))}y.length&&h.push(y)}return h.length?(m,d)=>{let g=0;for(let w of h)for(let y of w){let $=y(m,d);if($!==void 0){g+=$;break}}return g}:null}l(S0,"gposKerning");function k0(e,t){let n=si(e,"kern"),{u16:r,i16:o,need:s}=n;if(s(0,4,"header"),r(0)!==0)return null;let i=r(2),a=[],c=4;for(let f=0;f<i&&c<e.length;f++){if(f>=kn)throw Xe(`kern has more than ${kn} subtables`);s(c,6,"a subtable");let h=r(c+2),u=r(c+4);if(u>>8===0&&(u&7)===1){s(c+6,8,"a subtable");let p=r(c+6);s(c+14,p*6,"a subtable"),a.push([c+14,p]),c+=14+p*6}else{if(h<6)throw Xe("kern has a subtable shorter than its header");c+=h}}return!a.length||t<2?null:(f,h)=>{let u=f*65536+h,p=0;for(let[m,d]of a){let g=0,w=d-1;for(;g<=w;){let y=g+w>>1,$=m+y*6,A=r($)*65536+r($+2);if(A<u)g=y+1;else if(A>u)w=y-1;else{p+=o($+4);break}}}return p}}l(k0,"kernTable");function ii(e,t,n={}){let r=t instanceof Uint8Array?t:new Uint8Array(t),o=Kt(r),s=n.shaper;if(s!=null&&typeof s!="function")throw new TypeError("embedFont: shaper is a function (text, font, { direction, kerning }) => glyphs");let i=n.textMapping??"carrier";if(i!=="carrier"&&i!=="actualText")throw new TypeError(`embedFont: textMapping is 'carrier' or 'actualText', not ${JSON.stringify(i)}`);let a=o.tables.get("CFF "),c=a?Yt(a,o.numGlyphs):null,f=!!c?.cids,h=n.subset??!0,u=c&&h&&typeof h!="function"&&!(o.fsType&256)?{left:Zt}:null,p=!1,m=l(T=>{u&&br(a,c,T,u)&&(p=!0)},"use");m(0);let d=l(T=>bt(T>>8)+bt(T&255),"two"),g=oi(o.tables,o.numGlyphs,T=>e.warn(`${o.postscriptName.slice(0,63)}: ${T}`)),w=P0(o.tables.get("fvar"));w&&e.warn(`${o.postscriptName.slice(0,63)} is a variable font: it is drawn at its default instance (${w}); to draw another weight or width, embed a static instance of it (fonttools varLib.instancer, or HarfBuzz's hb-subset --instance)`);let y=1e3/o.unitsPerEm,$=e.reserve(),A=new Map,D=new Map,N=!o.cff,M=[],j=o.numGlyphs,O=new Set,R=new Map,x=new Map,b=e.pdfa||e.tagged,E=l(T=>{if(e.pdfaLevel?.unicode)throw new TypeError(`PDF/A-${e.pdfaLevel.part}${e.pdfaLevel.conformance}: ${o.postscriptName.slice(0,63)} has no glyph for ${JSON.stringify(T)} (U+${(T.codePointAt(0)??0).toString(16).toUpperCase().padStart(4,"0")}), and every character drawn must map to Unicode: use a font that has it, or a fallback font`)},"lack"),C=new Map,v=l(T=>{let k=C.get(T);return k===void 0&&C.set(T,k=Number(F(o.advance(T)*y))),k},"W"),L=l(T=>{let k=R.get(T);if(k===void 0){let B=o.glyphFor(T.codePointAt(0));B||E(T),!B&&O.size<100&&O.add(T),R.set(T,k=!B&&b?"":d(H(B,T)[0]))}return k},"pair"),H=l((T,k)=>{let B=k.length<=32?k:String.fromCodePoint(k.codePointAt(0));if(A.get(T)?.t===B)return B===k?M[T]??=[T,!0]:[T,!1];let z=D.get(`${T}:${B}`);if(z===void 0){if(!A.has(T))m(T),z=T;else if(N&&j<=65535)z=j++;else return[T,A.get(T).t===k];A.set(z,{g:T,t:B}),D.set(`${T}:${B}`,z)}return[z,B===k]},"code"),S,P=l((T,k)=>{let B=k.kerning!==!1&&g;if(s)return U(T,k);if(!B&&!k.ws){let J="",ee=0,te=0,ne=0;for(let K of k.rtl?[...T].reverse():T){let Q=o.glyphFor(K.codePointAt(0));if(!Q&&b){k.measure||L(K);continue}k.measure||(J+=L(K)),te++,ee+=v(Q),K===" "&&ne++}return{body:J,a:ee,n:te,sp:ne}}if(k.measure){let J=0,ee=0,te=0,ne=-1;for(let K of k.rtl?[...T].reverse():T){let Q=o.glyphFor(K.codePointAt(0));!Q&&b||(J+=v(Q)+(B&&ne>=0?g(ne,Q)*y:0),ee++,ne=Q,K===" "&&te++)}return{body:"",a:J,n:ee,sp:te}}let z=[],G=-1;for(let J of k.rtl?[...T].reverse():T){let ee=x.get(J);if(ee===void 0){let K=o.glyphFor(J.codePointAt(0));if(!K&&(E(J),O.size<100&&O.add(J),b))continue;let[Q,W]=H(K,J);ee={g:K,b:d(Q),w:v(K),ok:W},K&&x.set(J,ee)}let{g:te,w:ne}=ee;B&&G>=0&&(z[z.length-1].a+=g(G,te)*y),z.push({b:ee.b,w:ne,a:ne,dx:0,dy:0,sp:J===" ",at:ee.ok?void 0:J,n:1}),G=te}return z},"items"),U=l((T,k)=>{let B=s(T,S,{direction:k.rtl?"rtl":"ltr",kerning:k.kerning!==!1});if(!Array.isArray(B)||B.length>4*T.length+64)throw new TypeError(`The shaper returned ${Array.isArray(B)?`${B.length} glyphs for ${T.length} characters`:"no array"}`);let z=l((W,Z)=>{let ae=W??0;if(typeof ae!="number"||!(Math.abs(ae)<1e6))throw new TypeError(`The shaper returned a bad ${Z}: ${W}`);return ae},"fin"),G=B.map(W=>{let Z=W?.g,ae=W?.cl;if(!Number.isInteger(Z)||Z<0||Z>=o.numGlyphs)throw new TypeError(`The shaper returned glyph ${Z}, not one of the font's ${o.numGlyphs}`);if(!Number.isInteger(ae)||ae<0||ae>=Math.max(1,T.length))throw new TypeError(`The shaper returned cluster ${ae}, outside the text`);return{g:Z,cl:ae,ax:z(W.ax,"advance"),dx:z(W.dx,"offset"),dy:z(W.dy,"offset")}}),J=[...new Set(G.map(W=>W.cl))].sort((W,Z)=>W-Z),ee=new Map(J.map((W,Z)=>[W,J[Z+1]??T.length])),te=[],ne=new Set,K=l(W=>{let Z=W;for(;Z<G.length&&G[Z].cl===G[W].cl;)Z++;return[Z,ne.has(G[W].cl)?"":T.slice(G[W].cl,ee.get(G[W].cl))]},"at"),Q=null;for(let W=0;W<G.length;){let[Z,ae]=K(W),ue=G[W].cl,re=te.length;if(Q&&ae===" "&&Z-W===1){let{g:oe,ax:me,dx:ie,dy:de}=G[W];te.push({b:d(k.measure?oe:H(oe,"⁠")[0]),w:v(oe),a:me*y,dx:ie*y,dy:de*y,sp:!0}),Q.n&&Q.n++,Q=null,ne.add(ue),W=Z;continue}Q=null;let V=!k.rtl&&!!ae&&ae!==" "&&Z<G.length&&K(Z)[1]===" "&&K(Z)[0]-Z===1&&K(Z)[0]<G.length&&I.test(K(K(Z)[0])[1]),fe=V?`${ae} `:ae,se=-1,le=-1,we=V;if(ae)for(let oe=W;oe<Z;oe++)(G[oe].g||!b)&&(se<0||G[oe].ax>G[se].ax)&&(se=oe);for(let oe=W;oe<Z;oe++){let{g:me,ax:ie,dx:de,dy:Ie}=G[oe];if(!me&&(k.measure||E(fe),O.size<100&&!k.measure&&fe&&O.add(fe),b)){te.length>re&&(te[te.length-1].a+=ie*y);continue}let[Pe,Be]=k.measure?[me,!0]:H(me,oe!==se?"⁠":k.rtl&&_.test(fe)?[...fe].reverse().join(""):fe);Be||(we=!0),oe===se&&(le=te.length),oe!==se&&Math.abs(ie*y)>=1&&(we||=!k.rtl),te.push({b:d(Pe),w:v(me),a:ie*y,dx:de*y,dy:Ie*y,sp:oe===se&&fe===" ",c:oe!==se&&Math.abs(ie*y)<1||void 0})}if(te.length>re&&ne.add(ue),we&&!k.measure){let oe=te.slice(re).filter(me=>!me.c);oe.length&&(oe[0].at=fe,oe[0].n=oe.length,V&&(Q=oe[0])),i==="actualText"&&le>=0&&!te[le].c&&(te[le].b=d(H(G[se].g,"⁠")[0]))}else V&&(Q={});W=Z}return te},"shaped"),I=/\p{Mn}/u,_=/[\u0590-\u08ff\ufb1d-\ufdff\ufe70-\ufeff]/,Y={standard:!1,items:P,has:l(T=>o.glyphFor(T)!==0,"has"),ascent:o.ascent/o.unitsPerEm,lineHeight:(o.ascent-o.descent+Math.max(0,o.lineGap))/o.unitsPerEm},X={doc:e,ref:$,key:o.postscriptName,standard:!1,missing:O,name:e.resource("Font",`${$} 0 R`),ascent:o.ascent/o.unitsPerEm,descent:o.descent/o.unitsPerEm,widthOf(T,k){let B=0;for(let z of String(T))B+=o.advance(o.glyphFor(z.codePointAt(0)));return B*k/o.unitsPerEm},widthOfText:l((T,k,B)=>gn(Y,String(T??""),k,B),"widthOfText"),lineHeight:l(T=>Y.lineHeight*T,"lineHeight"),encode(T){let k="";for(let B of T)k+=L(B);return k},async write(){let T=[...A.keys()].sort((ie,de)=>ie-de),k=[...new Set([0,...[...A.values()].map(ie=>ie.g)])].sort((ie,de)=>ie-de),B=[...new Set([...A.values()].flatMap(ie=>[...ie.t].map(de=>de.codePointAt(0))))],z=r,G=null;if(h&&!(o.fsType&256))if(typeof h=="function")try{let ie=await h(r,B,{glyphs:k});Kt(ie,!1).numGlyphs>k[k.length-1]&&(z=ie)}catch{}else a?z=v0(r,o.numGlyphs,k,p):o.cff||({file:z,gid:G}=Qs(r,k));let J=z!==r;f&&(z=C0(z,z===r?o.numGlyphs:-1));let ee=cn(`${J?`${R0(z)}+`:""}${o.postscriptName}`,"Font"),te=e.reserve(),ne=e.reserve(),K=e.reserve(),Q=e.reserve(),W=o.cff&&at(z).has("CFF "),Z=W&&e.pdfaLevel?.part===1;await e.writeStream(ne,Z?"<< /Subtype /CIDFontType0C >>":W?"<< /Subtype /OpenType >>":`<< /Length1 ${z.length} >>`,Z?at(z).get("CFF "):z);let ae="";if(J&&e.pdfaLevel?.part===1){let ie=[...new Set([...k,...T])],de=new Uint8Array((Math.max(...ie)>>3)+1),Ie=e.reserve();for(let Pe of ie)de[Pe>>3]|=128>>(Pe&7);await e.writeStream(Ie,"<< >>",de),ae=` /CIDSet ${Ie} 0 R`}let ue=l(ie=>F(ie*y),"s"),re=(o.fixedPitch?1:0)|4|(o.italicAngle?64:0),[V,fe,se,le]=o.bbox;await e.write(te,`<< /Type /FontDescriptor /FontName ${ee} /Flags ${re} /FontBBox [${ue(V)} ${ue(fe)} ${ue(se)} ${ue(le)}] /ItalicAngle ${F(o.italicAngle)} /Ascent ${ue(o.ascent)} /Descent ${ue(o.descent)} /CapHeight ${ue(o.capHeight)} /XHeight ${ue(o.xHeight)} /StemV 0 /${W?"FontFile3":"FontFile2"} ${ne} 0 R${ae} >>`);let we=(T.length?T:[0]).map(ie=>[ie,A.get(ie)?.g??0]),oe="";for(let ie=0;ie<we.length;){let de=ie;for(;de+1<we.length&&we[de+1][0]===we[de][0]+1;)de++;oe+=`${we[ie][0]} [${we.slice(ie,de+1).map(([,Ie])=>ue(o.advance(Ie))).join(" ")}] `,ie=de+1}let me=" /CIDToGIDMap /Identity";if(!W&&(G||j>o.numGlyphs)){let ie=G?(T.at(-1)??0)+1:j,de=new Uint8Array(2*ie),Ie=e.reserve();for(let Pe=0;Pe<ie;Pe++){let Be=Pe<o.numGlyphs?Pe:A.get(Pe)?.g??0;G&&(Be=G.get(Be)??0),de[2*Pe]=Be>>8,de[2*Pe+1]=Be&255}await e.writeStream(Ie,"<< >>",de),me=` /CIDToGIDMap ${Ie} 0 R`}await e.write(K,`<< /Type /Font /Subtype /${W?"CIDFontType0":"CIDFontType2"} /BaseFont ${ee} /CIDSystemInfo << /Registry ${ke("Adobe")} /Ordering ${ke("Identity")} /Supplement 0 >> /FontDescriptor ${te} 0 R /W [${oe}]${W?"":me} >>`),await e.writeStream(Q,"<< >>",$e(M0(A))),await e.write($,`<< /Type /Font /Subtype /Type0 /BaseFont ${ee} /Encoding /Identity-H /DescendantFonts [${K} 0 R] /ToUnicode ${Q} 0 R >>`)}};return e.addFont(X),S=ye(Object.freeze(X),"font",e,Y),S}l(ii,"embedFont");function C0(e,t){let n=at(e),r=n.get("CFF ");return!r||!Yt(r,t).cids?e:(n.set("CFF ",Ar(r,t)),En(n,[79,84,84,79]))}l(C0,"identityOtf");var F0=["CFF ","head","hhea","hmtx","maxp"];function v0(e,t,n,r){let o=at(e),s=ti(o.get("CFF "),t,n,r);if(!s)return e;let i=new Map;for(let a of F0){let c=o.get(a);c&&i.set(a,c)}return i.set("CFF ",s),En(i,[79,84,84,79])}l(v0,"subsetOtf");function M0(e){let t=[...e].map(([r,o])=>[r,o.t]).sort((r,o)=>r[0]-o[0]),n="";for(let r=0;r<t.length;r+=100){let o=t.slice(r,r+100);n+=`${o.length} beginbfchar
91
+ ${o.map(([s,i])=>`<${zn(s)}> <${_n(i)}>`).join(`
92
+ `)}
93
+ endbfchar
94
+ `}return`/CIDInit /ProcSet findresource begin
95
+ 12 dict begin
96
+ begincmap
97
+ /CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
98
+ /CMapName /Adobe-Identity-UCS def
99
+ /CMapType 2 def
100
+ 1 begincodespacerange
101
+ <0000> <ffff>
102
+ endcodespacerange
103
+ ${n}endcmap
104
+ CMapName currentdict /CMap defineresource pop
105
+ end
106
+ end
107
+ `}l(M0,"toUnicode");function P0(e){if(!e||e.length<16)return"";let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint16(4),r=t.getUint16(8),o=t.getUint16(10),s=[];for(let i=0;i<Math.min(r,16)&&o>=20&&n+i*o+20<=e.length;i++){let a=n+i*o;s.push(`${String.fromCharCode(...e.subarray(a,a+4)).replace(/[^\x20-\x7e]/g,"?")} ${Math.round(t.getInt32(a+8)/655.36)/100}`)}return s.join(", ")||"no axes read"}l(P0,"variation");function R0(e){let t=2166136261;for(let r=0;r<e.length;r++)t=Math.imul(t^e[r],16777619);let n="";for(let r=0;r<6;r++)n+=String.fromCharCode(65+(t>>>0)%26),t=Math.imul(t^r,16777619)>>>0;return n}l(R0,"tag");var ai=1e5,ci=63,li=4096;function O0(e){if(e==null)return"";let t=_e(e);if(!t||t.comps.length===4)throw new TypeError("pdf.outline: color is RGB ('#rrggbb', [r, g, b]) or a gray level");return` /C [${(t.comps.length===1?[t.comps[0],t.comps[0],t.comps[0]]:t.comps).map(r=>String(Math.round(r*1e3)/1e3)).join(" ")}]`}l(O0,"colorOf");function fi(e){let t=[];return e.onFinish(async()=>{let n={ref:0,level:-1,kids:[],vis:0},r=[],o=[n];for(let i of t){let a;if(i.named)a=i.named;else if(a=dt(e,i.i,i.d),!a){e.warn(`The outline entry "${i.title.slice(0,80)}" points to page ${i.i+1}, but the PDF has ${e.pageCount} pages`);continue}for(;o[o.length-1].level>=i.level;)o.pop();let c={ref:e.reserve(),level:i.level,kids:[],e:i,dest:a,vis:0};o[o.length-1].kids.push(c),o.push(c),r.push(c)}if(!n.kids.length)return;n.ref=e.reserve();for(let i=r.length-1;i>=-1;i--){let a=i<0?n:r[i];for(let c of a.kids)a.vis+=1+(c.e?.open?c.vis:0)}let s=l(i=>i.kids.length?` /First ${i.kids[0].ref} 0 R /Last ${i.kids[i.kids.length-1].ref} 0 R /Count ${i===n||i.e?.open?i.vis:-i.vis}`:"","children");for(let i of[n,...r])for(let a=0;a<i.kids.length;a++){let c=i.kids[a],f=c.e;await e.write(c.ref,`<< /Title ${q(f.title)} /Parent ${i.ref} 0 R /Dest ${c.dest}${a?` /Prev ${i.kids[a-1].ref} 0 R`:""}${a<i.kids.length-1?` /Next ${i.kids[a+1].ref} 0 R`:""}${s(c)}${f.C}${f.F?` /F ${f.F}`:""} >>`)}await e.write(n.ref,`<< /Type /Outlines${s(n)} >>`),e.catalog("Outlines",`${n.ref} 0 R`),e.catalog("PageMode","/UseOutlines")}),n=>{let r=Array.isArray(n)?n:[n];if(t.length+r.length>ai)throw new RangeError(`pdf.outline: at most ${ai} entries`);let o=[];for(let s of r){if(!s||typeof s.title!="string"||s.page==null&&s.dest==null)throw new TypeError("pdf.outline: an entry is { title, page, top?, level? } or { title, dest: name }");if(s.title.length>li)throw new RangeError(`pdf.outline: a title is at most ${li} characters`);let i=s.level??0;if(!(Number.isInteger(i)&&i>=0&&i<=ci))throw new RangeError(`pdf.outline: level is a whole number 0–${ci}, not ${i}`);let a=s.dest!=null?vt(e).use(s.dest,"pdf.outline"):null;o.push({title:s.title,level:i,named:a,open:s.open!==!1,C:O0(s.color),F:(s.italic?1:0)|(s.bold?2:0),i:a?-1:ut(e,s.page,"pdf.outline"),d:a?null:pt(s,"pdf.outline")})}for(let s of o)t.push(s)}}l(fi,"createOutline");var hi=["D","r","R","a","A"],ui=1e4,pi=1024;function di(e){let t=null;return e.onFinish(async()=>{if(!t)return;let n=t[0][0]===0?t:[[0,"<< /S /D >>"],...t];e.catalog("PageLabels",`${await st(e,"Nums",n.map(([r,o])=>[String(r),o]))} 0 R`)}),n=>{let r="pdf.pageLabels";if(!Array.isArray(n)||!n.length||n.length>ui)throw new TypeError(`${r}: an array of 1–${ui} ranges { start, style, prefix, first }`);let o=[];for(let s of n){let i=s?.start;if(!(Number.isInteger(i)&&i>=0&&i<1e8))throw new RangeError(`${r}: start is a 0-based page index, not ${i}`);if(s.style!=null&&!hi.includes(s.style))throw new TypeError(`${r}: style is one of ${hi.join(", ")} (or none), not ${JSON.stringify(s.style)}`);if(s.prefix!=null&&(typeof s.prefix!="string"||s.prefix.length>pi))throw new TypeError(`${r}: prefix is a string of at most ${pi} characters`);if(s.first!=null&&!(Number.isInteger(s.first)&&s.first>=1&&s.first<1e8))throw new RangeError(`${r}: first is a whole number from 1, not ${s.first}`);o.push([i,`<< /Type /PageLabel${s.style?` /S /${s.style}`:""}${s.prefix?` /P ${q(s.prefix)}`:""}${s.first!=null&&s.first!==1?` /St ${F(s.first)}`:""} >>`])}o.sort((s,i)=>s[0]-i[0]);for(let s=1;s<o.length;s++)if(o[s][0]===o[s-1][0])throw new RangeError(`${r}: two ranges start at page index ${o[s][0]}`);t=o}}l(di,"createPageLabels");var Tr={hideToolbar:"HideToolbar",hideMenubar:"HideMenubar",hideWindowUI:"HideWindowUI",fitWindow:"FitWindow",centerWindow:"CenterWindow",displayDocTitle:"DisplayDocTitle",pickTrayByPDFSize:"PickTrayByPDFSize"},Er={direction:["L2R","R2L"],printScaling:["None","AppDefault"],duplex:["Simplex","DuplexFlipShortEdge","DuplexFlipLongEdge"],pageMode:["UseNone","UseOutlines","UseThumbs","FullScreen","UseOC","UseAttachments"],pageLayout:["SinglePage","OneColumn","TwoColumnLeft","TwoColumnRight","TwoPageLeft","TwoPageRight"]},gi={direction:"Direction",printScaling:"PrintScaling",duplex:"Duplex"};function mi(e){let t=new Map,n=!1,r=l(()=>{let o=[];for(let[i,a]of t)Object.hasOwn(Tr,i)?o.push(`/${Tr[i]} ${a}`):Object.hasOwn(gi,i)?o.push(`/${gi[i]} /${a}`):i==="numCopies"&&o.push(`/NumCopies ${a}`);e.tagged&&!t.has("displayDocTitle")&&o.push("/DisplayDocTitle true"),o.length&&e.catalog("ViewerPreferences",`<< ${o.join(" ")} >>`),t.has("pageMode")&&e.catalog("PageMode",`/${t.get("pageMode")}`),t.has("pageLayout")&&e.catalog("PageLayout",`/${t.get("pageLayout")}`);let s=t.get("openAt");if(s){let i=dt(e,s.i,s.d);i?e.catalog("OpenAction",i):e.warn(`viewer openAt points to page ${s.i+1}, but the PDF has ${e.pageCount} pages`)}},"finish");return o=>{let s="pdf.viewer";if(!o||typeof o!="object")throw new TypeError(`${s}(options): an object`);let i=[];for(let[a,c]of Object.entries(o))if(Object.hasOwn(Tr,a)){if(typeof c!="boolean")throw new TypeError(`${s}: ${a} is true or false`);if(a==="displayDocTitle"&&!c&&e.tagged)throw new TypeError(`${s}: a tagged PDF (PDF/UA) shows its title: displayDocTitle cannot be false`);i.push([a,c])}else if(Object.hasOwn(Er,a)){if(!Er[a].includes(c))throw new TypeError(`${s}: ${a} is one of ${Er[a].join(", ")}, not ${JSON.stringify(c)}`);i.push([a,c])}else if(a==="numCopies"){if(!(Number.isInteger(c)&&c>=1&&c<=5))throw new RangeError(`${s}: numCopies is 1–5, not ${c}`);i.push([a,c])}else if(a==="openAt"){if(!c||typeof c!="object"||c.page==null)throw new TypeError(`${s}: openAt is { page, fit?, left?, top?, zoom? } (a destination: the only open action written)`);i.push([a,{i:ut(e,c.page,`${s} openAt`),d:pt(c,`${s} openAt`)}])}else throw new TypeError(`${s}: unknown option ${JSON.stringify(a)} (the open action is openAt, a page destination; JavaScript and other actions are never written)`);for(let[a,c]of i)t.set(a,c);n||(n=!0,e.onFinish(r))}}l(mi,"createViewer");var D0="AAAC4GxjbXMCEAAAbW50clJHQiBYWVogB+IAAwAUAAkADgAdYWNzcE1TRlQAAAAAc2F3c2N0cmwAAAAAAAAAAAAAAAAAAPbWAAEAAAAA0y1oYW5kk7I0qQ6wIoqY/Zqvo2eJmwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJZGVzYwAAAPAAAABfY3BydAAAAQwAAAAMd3RwdAAAARgAAAAUclhZWgAAASwAAAAUZ1hZWgAAAUAAAAAUYlhZWgAAAVQAAAAUclRSQwAAAWgAAAF4Z1RSQwAAAWgAAAF4YlRSQwAAAWgAAAF4ZGVzYwAAAAAAAAAFc1JHQgAAAAAAAAAAAAAAAHRleHQAAAAAQ0MwAFhZWiAAAAAAAADzVAABAAAAARbJWFlaIAAAAAAAAG+gAAA48gAAA49YWVogAAAAAAAAYpYAALeJAAAY2lhZWiAAAAAAAAAkoAAAD4UAALbEY3VydgAAAAAAAAC2AAAAHAA4AFQAcACMAKgAxADhAQABIgFGAW0BlQHBAfACIAJVAosCxAMBAz8DggPGBA4EWQSnBPkFTAWkBf4GXAa+ByEHigf0CGMI1QlJCcMKPwq/C0ILyQxUDOENdA4JDqIPQA/gEIURLRHaEooTPhP2FLIVcRY2Fv0XyhiZGW4aRhsiHAMc5x3QHr0friCkIZ4inCOfJKUlsSbAJ9Uo7SoKKyssUS18Lqov3jEWMlIzlDTZNiQ3czjGOiA7fDzfPkU/sEEhQpZEEEWPRxJIm0ooS7tNUU7uUI9SNVPgVZBXRVkAWr5chF5MYBth72PHZaZniWlxa19tUW9KcUZzSnVRd155cXuIfaZ/yIHwhB6GUIiJisWNCY9RkZ+T85ZLmKubDp14n+eiW6TWp1ap26xnrvexj7Qqtsy5dLwhvtXBjcRMxxDJ2syrz3/SXNU92CTbEt4E4P7j/OcB6gztHPA081D2c/mb/Mr//w==",I0=l(e=>{let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},"unbase64");function wi(e,t){let n=t&&typeof t=="object"&&t.outputIntent!=null?dn(t.outputIntent,"pdfa.outputIntent"):null;if(n&&n.n===1)throw new TypeError("pdfa.outputIntent: an RGB or CMYK profile (not gray)");if(n&&n.cls!=="prtr"&&n.cls!=="mntr")throw new TypeError(`pdfa.outputIntent: an output (prtr) or monitor (mntr) profile, not ${JSON.stringify(n.cls)}`);e.outputIntent=n?.n===4?"CMYK":"RGB",e.onFinish(async()=>{let r=e.reserve(),o=e.reserve();await e.writeStream(r,`<< /N ${n?n.n:3} >>`,n?n.bytes:I0(D0));let s=n?`${ke("Custom")} /Info ${ke(`Custom ${n.space} profile`)}`:"<73524742> /Info <735247422049454336313936362d322e31>";await e.write(o,`<< /Type /OutputIntent /S /GTS_PDFA1 /OutputConditionIdentifier ${s} /DestOutputProfile ${r} 0 R >>`),e.catalog("OutputIntents",`[${o} 0 R]`)})}l(wi,"addOutputIntent");var yi=["Source","Data","Alternative","Supplement","Unspecified"],Sr=256<<20,$i=1e4,N0=/^[a-z0-9!#$&^_.+-]{1,63}\/[a-z0-9!#$&^_.+-]{1,63}$/i;function bi(e,t){let n=new Map,r=[];return e.onFinish(async()=>{if(!n.size)return;let o=[...n].sort(([s],[i])=>s<i?-1:s>i?1:0);yn(e,"EmbeddedFiles",await st(e,"Names",o.map(([s,i])=>[s,`${i} 0 R`]))),r.length&&e.catalog("AF",`[${r.map(s=>`${s} 0 R`).join(" ")}]`)}),l(async function(s,i,a="pdf.attach"){if(i==null||typeof i!="object")throw new TypeError(`${a}: options with the file's name: { name: 'data.csv' }`);let c=e.pdfaLevel;if(c&&c.part!==3)throw new TypeError(`${a}: PDF/A-${c.part} ${c.part===1?"forbids embedded files":"allows only PDF/A files as attachments, which this library cannot check"}; use PDF/A-3 (pdfa: { part: 3 })`);let f=i.maxBytes??Sr;if(typeof f!="number"||!(f>0&&f<=Sr))throw new RangeError(`${a}: maxBytes is 1 to ${Sr} bytes`);let h=s instanceof ArrayBuffer||ArrayBuffer.isView(s)?s.byteLength:-1;if(h<0)throw new TypeError(`${a}: the file is a Uint8Array, Buffer or ArrayBuffer`);if(h>f)throw new RangeError(`${a}: the file is ${h} bytes, over maxBytes (${f})`);if(n.size>=$i)throw new RangeError(`${a}: at most ${$i} embedded files`);let u=i.mimeType;if(u!=null&&!(typeof u=="string"&&N0.test(u)))throw new TypeError(`${a}: mimeType is type/subtype, like text/csv`);if(c&&u==null)throw new TypeError(`${a}: PDF/A-3 needs each embedded file's mimeType (ISO 19005-3 6.8)`);let{name:p,ascii:m}=qt(i.name,{mimeType:u,allowTypes:Object.hasOwn(i,"allowTypes")?i.allowTypes:null,allowArchives:Object.hasOwn(i,"allowArchives")&&i.allowArchives===!0},a);if(i.description!=null&&(typeof i.description!="string"||i.description.length>65536))throw new TypeError(`${a}: description is a string of at most 65,536 characters`);let d=i.relationship??(c?"Unspecified":null);if(d!=null&&!yi.includes(d))throw new TypeError(`${a}: relationship is one of ${yi.join(", ")}`);let g=` /CreationDate ${gt(i.created??t,a)} /ModDate ${gt(i.modified??t,a)}`,w=q(p);if(n.has(w))throw new TypeError(`${a}: a file named ${JSON.stringify(p)} is already attached`);let y=new Uint8Array(h);y.set(s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,h));let $=e.reserve(),A=e.reserve();n.set(w,A),c&&r.push(A);let N=`<< /Type /EmbeddedFile${u?` /Subtype ${pe(u)}`:""} /Params << /Size ${h} /CheckSum <${Mt(y)}>${g} >> >>`,M=`<< /Type /Filespec /F ${m} /UF ${q(p)}${i.description!=null?` /Desc ${q(i.description)}`:""}${d?` /AFRelationship /${d}`:""} /EF << /F ${$} 0 R /UF ${$} 0 R >> >>`;await e.serial(async()=>{await e.writeStream($,N,y),await e.write(A,M)})},"attach")}l(bi,"createFiles");var Fr=10<<20,kr={MINIMUM:["urn:factur-x.eu:1p0:minimum","Data"],"BASIC WL":["urn:factur-x.eu:1p0:basicwl","Data"],BASIC:["urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic","Alternative"],"EN 16931":["urn:cen.eu:en16931:2017","Alternative"],EXTENDED:["urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended","Alternative"],XRECHNUNG:["urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_","Alternative"]},U0="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";function j0(e){if(e.length>Fr)throw new RangeError(`pdf.facturX: the XML is ${e.length} bytes, over ${Fr>>20} MB`);let t;try{t=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!1}).decode(e)}catch{throw new TypeError("pdf.facturX: the XML is not UTF-8 (Factur-X invoices are UTF-8)")}let n=/<!--|<!\[CDATA\[|<\?|<!/g,r="",o=0;for(let f=n.exec(t);f;f=n.exec(t)){let h=f[0],u=h==="<!--"?"-->":h==="<?"?"?>":h==="<!"?"":"]]>";if(!u)throw new TypeError(`pdf.facturX: the XML has a markup declaration (${JSON.stringify(t.slice(f.index,f.index+10))}…): a DOCTYPE or ENTITY is refused (entity expansion); a Factur-X invoice has none`);let p=t.indexOf(u,f.index+h.length);if(p<0)throw new TypeError(`pdf.facturX: the XML has an unterminated ${h==="<?"?"processing instruction":h==="<!--"?"comment":"CDATA section"}`);r+=`${t.slice(o,f.index)} `,o=n.lastIndex=p+u.length}r+=t.slice(o);let s=/^\s*<(?:[A-Za-z_][\w.-]{0,63}:)?([A-Za-z_][\w.-]{0,63})[\s/>]/.exec(r.slice(0,4096))?.[1]??"",i=[];for(let f of Cr(r,"ExchangedDocumentContext"))for(let h of Cr(f,"GuidelineSpecifiedDocumentContextParameter"))i.push(...Cr(h,"ID"));let a={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"},c=i.length===1&&!i[0].includes("<")?i[0].replace(/&(amp|lt|gt|quot|apos);/g,(f,h)=>a[h]).trim():null;return{root:s,guideline:c}}l(j0,"readInvoice");function Cr(e,t){let n=[],r=new RegExp(`<((?:[A-Za-z_][\\w.-]{0,63}:)?${t})(?=[\\s/>])[^<>]{0,4096}>`,"g");for(let o=r.exec(e);o;o=r.exec(e)){if(o[0].endsWith("/>")){n.push("");continue}let s=new RegExp(`</${o[1].replace(/\./g,"\\.")}\\s{0,4096}>`,"g");s.lastIndex=r.lastIndex;let i=s.exec(e);if(!i)break;n.push(e.slice(r.lastIndex,i.index)),r.lastIndex=s.lastIndex}return n}l(Cr,"elements");function Ai(e,t){let n=!1;return l(async function(o,s){let i="pdf.facturX";if(e.pdfaLevel?.part!==3)throw new TypeError(`${i}: a Factur-X / ZUGFeRD invoice is a PDF/A-3 file: createPdf(sink, { pdfa: { part: 3, conformance: 'b' } })`);if(n)throw new TypeError(`${i}: one invoice a document`);let c=s?.profile,f=s?.version??"1.0",h=typeof c=="string"&&Object.hasOwn(kr,c)?kr[c]:null;if(typeof c!="string"||!h)throw new TypeError(`${i}: profile is one of ${Object.keys(kr).map(g=>`'${g}'`).join(", ")}`);if(f!=="1.0")throw new TypeError(`${i}: version is '1.0' (Factur-X 1.0, ZUGFeRD 2.1 and later)`);if(!(o instanceof ArrayBuffer||ArrayBuffer.isView(o)))throw new TypeError(`${i}: the XML is bytes (a Uint8Array, Buffer or ArrayBuffer)`);let u=o instanceof ArrayBuffer?new Uint8Array(o):new Uint8Array(o.buffer,o.byteOffset,o.byteLength),p=j0(u);if(p.root!=="CrossIndustryInvoice")throw new TypeError(`${i}: the XML's root is ${JSON.stringify(p.root)}, not CrossIndustryInvoice (a UN/CEFACT CII invoice)`);if(!(c==="XRECHNUNG"?p.guideline?.startsWith(h[0]):p.guideline===h[0]))throw new TypeError(`${i}: the XML's GuidelineSpecifiedDocumentContextParameter ID is ${JSON.stringify(p.guideline)}, which is not the ${c} profile (${h[0]}${c==="XRECHNUNG"?"…":""})`);let d=c==="XRECHNUNG"?"xrechnung.xml":"factur-x.xml";await t(u,{name:d,mimeType:"text/xml",allowTypes:["xml"],relationship:h[1],description:c==="XRECHNUNG"?"XRechnung invoice":"Factur-X invoice",maxBytes:Fr},i),n=!0,e.xmpExtensions.push({schema:"Factur-X PDFA Extension Schema",ns:U0,prefix:"fx",props:[{name:"DocumentFileName",type:"Text",category:"external",description:"The name of the embedded XML document",value:d},{name:"DocumentType",type:"Text",category:"external",description:"The type of the hybrid document in capital letters, e.g. INVOICE or ORDER",value:"INVOICE"},{name:"Version",type:"Text",category:"external",description:"The actual version of the standard applying to the embedded XML document",value:f},{name:"ConformanceLevel",type:"Text",category:"external",description:"The conformance level of the embedded XML document",value:c}]})},"facturX")}l(Ai,"createFacturX");var xi=["cropBox","bleedBox","trimBox","artBox"],ct=1e-6;function Ti(e,t){let n=e.width,r=e.height,o="addPage",s={};for(let a of xi){let c=t[a];if(c==null)continue;if(!Array.isArray(c)||c.length!==4)throw new TypeError(`${o}: ${a} is [x, y, width, height]`);let[f,h,u,p]=c.map(m=>(F(m),m));if(!(u>0&&p>0))throw new RangeError(`${o}: ${a} has a positive width and height`);if(f<-ct||h<-ct||f+u>n+ct||h+p>r+ct)throw new RangeError(`${o}: ${a} [${c.join(", ")}] lies outside the page (the MediaBox, ${n} × ${r})`);s[a]=[f,h,f+u,h+p]}let i=l((a,c)=>{let f=s[a],h=s[c];if(f&&h&&(f[0]<h[0]-ct||f[1]<h[1]-ct||f[2]>h[2]+ct||f[3]>h[3]+ct))throw new RangeError(`${o}: ${a} lies outside ${c}`)},"inside");i("trimBox","bleedBox"),i("artBox","bleedBox");for(let a of xi){let c=s[a];c&&e.entries.set(a[0].toUpperCase()+a.slice(1).replace("box","Box"),`[${F(c[0])} ${F(r-c[3])} ${F(c[2])} ${F(r-c[1])}]`)}if(t.rotate!=null){if(![0,90,180,270].includes(t.rotate))throw new RangeError(`${o}: rotate is 0, 90, 180 or 270`);t.rotate&&e.entries.set("Rotate",String(t.rotate))}if(t.userUnit!=null){if(typeof t.userUnit!="number"||!(t.userUnit>0&&t.userUnit<=75e3))throw new RangeError(`${o}: userUnit is a number above 0, at most 75,000`);Ke(e.doc,o,"is PDF 1.4, which has no UserUnit"),t.userUnit!==1&&e.entries.set("UserUnit",F(t.userUnit))}}l(Ti,"pageBoxes");var en={check:"4",cross:"8",circle:"l",square:"n",diamond:"u",star:"H"},L0=Ht({}),Mr=12,B0=4,Ei=l((e,t,n)=>{let r=0;for(let o of Tt(t,e.fonts,{measure:!0}))r+=rt(o.run,n,L0);return r},"widthOf");function Ot(e,t,n,r,o=r.bg){o!=null&&e.fill(e.path().rect(0,0,t,n),{fill:o}),r.bw>0&&e.stroke(e.path().rect(r.bw/2,r.bw/2,t-r.bw,n-r.bw),{stroke:r.bc,width:r.bw})}l(Ot,"frame");function Cn(e,t,n,r,o){if(!(t-2*r.bw<=0||n-2*r.bw<=0)){e.save(),e.clip(e.path().rect(r.bw,r.bw,t-2*r.bw,n-2*r.bw));try{o()}finally{e.restore()}}}l(Cn,"inside");function vr(e,t,n,r){if(e.size)return e.size;let o=Math.min(Mr,r/(e.ascent-e.descent)),s=t?Ei(e,t,o):0;return s>n&&(o*=n/s),Math.max(1,Math.floor(o*100)/100)}l(vr,"lineSize");function Qt(e,t,n,r,o,s,i,a,c){if(!n)return;let f=a===0?0:(s-Ei(t,n,c))/(a===1?2:1),h=o+i/2+(t.ascent+t.descent)/2*c;Et(e,t.fonts,n,r+f,h,c,Xt({}),{color:t.color})}l(Qt,"line");function Pr(e,t,n,r,o,s,i){Ot(e,t,n,r);let a=r.bw+2,c=t-2*a,f=n-2*r.bw;if(i.comb){let h=t/i.comb;if(r.bw>0){let p=e.path();for(let m=1;m<i.comb;m++)p.moveTo(m*h,0).lineTo(m*h,n);e.stroke(p,{stroke:r.bc,width:r.bw})}if(!s)return;let u=o.size||vr(o,"W",h-2,f);Cn(e,t,n,r,()=>{let p=0;for(let m of s)Qt(e,o,m,p*h,0,h,n,1,u),p++});return}!s||c<=0||Cn(e,t,n,r,()=>{if(!i.multiline)return Qt(e,o,s,a,0,c,n,i.q,vr(o,s,c,f));let h={x:a,y:a,width:c,height:Math.max(0,n-2*a),font:o.fonts[0].font,fallback:o.fonts.slice(1).map(p=>p.font),color:o.color,align:["left","center","right"][i.q]},u=o.size;if(!u)for(u=Mr;u>B0;u--){let p=Object.create(e);if(p.content=new tt,!p.textBox(s,{...h,size:u}).overflow)break}e.textBox(s,{...h,size:u})})}l(Pr,"textValue");function Si(e,t,n,r,o,s,i,a,c,f){Ot(e,t,n,r);let h=o.size||Mr,u=o.impl.lineHeight*h,p=r.bw+2;Cn(e,t,n,r,()=>{for(let m=a,d=r.bw;m<s.length&&d<n-r.bw;m++,d+=u)i.has(m)&&e.fill(e.path().rect(r.bw,d,t-2*r.bw,u),{fill:f}),Qt(e,o,s[m],p,d,t-2*p,u,c,h)})}l(Si,"listRows");function Rr(e,t,n,r,o){let s=Math.min(t,n)*.7,i=(t-s)/2,a=(n-s)/2,c=e.path(),f=l((h,u)=>[i+h*s,a+u*s],"at");if(r==="check")return c.moveTo(...f(.12,.55)).lineTo(...f(.4,.82)).lineTo(...f(.9,.18)),e.stroke(c,{stroke:o,width:s*.14,cap:"round",join:"round"});if(r==="cross")return c.moveTo(...f(.15,.15)).lineTo(...f(.85,.85)).moveTo(...f(.85,.15)).lineTo(...f(.15,.85)),e.stroke(c,{stroke:o,width:s*.14,cap:"round"});if(r==="circle")c.arc(t/2,n/2,s*.32,0,2*Math.PI);else if(r==="square")c.rect(...f(.2,.2),s*.6,s*.6);else if(r==="diamond")c.moveTo(...f(.5,.08)).lineTo(...f(.92,.5)).lineTo(...f(.5,.92)).lineTo(...f(.08,.5)).closePath();else{for(let h=0;h<10;h++){let u=h%2?.19:.46,p=-Math.PI/2+h*Math.PI/5,m=.5+u*Math.cos(p),d=.52+u*Math.sin(p);h?c.lineTo(...f(m,d)):c.moveTo(...f(m,d))}c.closePath()}e.fill(c,{fill:o})}l(Rr,"drawMark");function ki(e,t,n,r){let o=Math.min(t,n)/2-r.bw/2;if(o<=0)return;let s=e.path().arc(t/2,n/2,o,0,2*Math.PI);r.bg!=null&&r.bw>0?e.fillAndStroke(s,{fill:r.bg,stroke:r.bc,width:r.bw}):r.bg!=null?e.fill(s,{fill:r.bg}):r.bw>0&&e.stroke(s,{stroke:r.bc,width:r.bw})}l(ki,"roundFrame");function Ci(e,t,n,r,o,s,i,a){Ot(e,t,n,r,o);let c=r.bw+2,f=t-2*c,h=n-2*c;f<=0||h<=0||Cn(e,t,n,r,()=>{let u=0;if(s&&i){let p=vr(s,i,f,a?h/3:h);u=a?(s.ascent-s.descent)*p+2:0,a?Qt(e,s,i,c,n-c-u,f,u,1,p):Qt(e,s,i,c,0,f,n,1,p)}a&&e.image(a,{x:c,y:c,width:f,height:Math.max(1,h-u),fit:"contain"})})}l(Ci,"buttonFace");var Or=1e4,Fi=1e3,Fn=1e4,vi=1e6,Mi=5e4,vn=1e5,nn=256,Dr=32,Ir=4096,Pi=1e3,Ri=["NextPage","PrevPage","FirstPage","LastPage"],H0=/^(aa|additionalactions|actions?|js|javascript|script|format|keystroke|validate|calculate|calculation|calculationorder|co|onclick|onblur|onfocus|onchange|submit|submitform|importdata|launch|uri|url|gotor|gotoe|hide|rendition|sound|movie)$/i,ve={readOnly:1,required:2,multiline:4096,password:8192,noToggleToOff:16384,radio:32768,pushButton:65536,combo:1<<17,edit:1<<18,multiSelect:1<<21,doNotSpellCheck:1<<22,doNotScroll:1<<23,comb:1<<24,radiosInUnison:1<<25},Dt=["page","x","y","width","height"],It=["border","background","tooltip","readOnly","required"],Nr=["font","fallback","size","textColor","align"],Ni=/[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u,Oi=["appearance","da","structParent"],Di=16e6,Ii=l(e=>{let t="<";for(let n=0;n<e.length;n++)t+=(e.charCodeAt(n)&255).toString(16).padStart(2,"0");return`${t}>`},"hexAscii");function Ge(e,t,n){if(e==null||typeof e!="object")throw new TypeError(`${n}: options are an object`);for(let r of Object.keys(e))if(!t.includes(r))throw H0.test(r)?new TypeError(`${n}: ${r}: form fields never carry JavaScript, additional actions (/AA), format, keystroke, validate or calculate scripts, SubmitForm or ImportData (a PDF writer must not carry active content); a push button's action is { reset } or { named }`):new TypeError(`${n}: unknown option ${JSON.stringify(r.slice(0,40))} (${t.join(", ")})`)}l(Ge,"keys");function Me(e,t,n){if(e!=null&&typeof e!="boolean")throw new TypeError(`${n}: ${t} is true or false`);return!!e}l(Me,"bool");function Ur(e,t){if(typeof e!="string"||!e)throw new TypeError(`${t}: a field name is a non-empty string`);if(e.length>nn)throw new RangeError(`${t}: a field name is at most ${nn} characters`);if(e.includes("."))throw new TypeError(`${t}: a field name cannot contain '.' (it separates the levels of a full name: use pdf.form.group('a').textField('b', …) for "a.b")`);if(Ni.test(e))throw new TypeError(`${t}: a field name cannot contain control, format, bidi or separator characters (they hide or reorder what a reader shows)`);return e}l(Ur,"partial");function tn(e,t,n,r){if(typeof e!="string")throw new TypeError(`${r}: ${t} is a string`);if(e.length>n)throw new RangeError(`${r}: ${t} is at most ${n} characters`);return e}l(tn,"str");function Mn(e,t,n,r){for(let o of t){let s=o.codePointAt(0);if(!(s===10||s===13)&&!e.some(i=>i.impl.has(s)))throw new TypeError(`${r}: the font has no glyph for ${JSON.stringify(o)} (U+${s.toString(16).toUpperCase().padStart(4,"0")}) in the ${n}; use a font that has it, or add one as fallback`)}}l(Mn,"glyphs");function Ui(e,t={}){if(t==null||typeof t!="object")throw new TypeError("createPdf: form is { flatten }");for(let S of Object.keys(t))if(S!=="flatten")throw new TypeError(`createPdf: form: unknown option ${JSON.stringify(S)} (flatten)`);let n=Me(t.flatten,"form.flatten","createPdf"),r=new Map,o=[],s=[],i=[],a=[],c=0,f=0,h=!1,u=l(()=>{h||(h=!0,e.onFinish(async()=>{for(let P of a)for(let U of P.list)if(!r.has(U))throw new TypeError(`${P.who}: ${JSON.stringify(U.slice(0,80))} is not a field of this form`);if(n)return;for(let P of s)await e.write(P.ref,`<< /T ${q(P.name)}${P.parent?` /Parent ${P.parent.ref} 0 R`:""} /Kids [${P.kids.map(U=>`${U} 0 R`).join(" ")}] >>`);for(let P of i)await P();let S=await e.object(`<< /Fields [${o.map(P=>`${P} 0 R`).join(" ")}] /NeedAppearances false /DR ${e.resourcesRef} 0 R${e.sigFlags?` /SigFlags ${e.sigFlags}`:""} >>`);e.catalog("AcroForm",`${S} 0 R`)}))},"start"),p=l((S,P,U)=>{let I=S.prefix?`${S.prefix}.${Ur(P,U)}`:Ur(P,U);if(r.has(I))throw new TypeError(`${U}: a field or group named ${JSON.stringify(I.slice(0,200))} already exists (full names are unique)`);if(c>=Or)throw new RangeError(`${U}: at most ${Or} fields and groups a document`);return I},"fullName"),m=l((S,P,U,I)=>{u(),c++,r.set(P,I),U&&(S.group?S.group.kids:o).push(U)},"commit"),d=l((S,P)=>{let U=S.page,I=he(U,"page",e,"page"),_=S.x??0,Y=S.y??0,X=S.width,T=S.height;for(let k of[_,Y,X,T])if(typeof k!="number")throw new TypeError(`${P}: x, y, width and height are numbers`);for(let k of[_,Y,X,T])F(k);if(!(X>0&&T>0))throw new RangeError(`${P}: width and height are above 0`);return{page:U,ref:e.pageRef(I),H:e.pageHeight(I),x:_,y:Y,w:X,h:T}},"placeOf"),g=l((S,P,U={})=>{let I=S.border===!1?null:S.border??(U.border!=null?{width:U.border}:null);if(I!=null&&typeof I!="object")throw new TypeError(`${P}: border is { width, color } or false`);let _=I?I.width??1:0,Y=I?.color??0;if(F(_),!(_>=0&&_<=100))throw new RangeError(`${P}: border width is 0–100`);let X=S.background??U.background??null,T=`${_>0?` /BC ${Ue(Y,e,P)}`:""}${X!=null?` /BG ${Ue(X,e,P)}`:""}`;return{f:{bw:_,bc:Y,bg:X},mk:T,bs:` /BS << /W ${F(_)} /S /S >>`}},"lookOf"),w=l((S,P)=>{if(S.tooltip==null){if(e.tagged)throw new TypeError(`${P}: a tagged PDF (PDF/UA) needs a tooltip for every field (its accessible name, /TU)`);return""}if(e.tagged&&!String(S.tooltip).trim())throw new TypeError(`${P}: the tooltip is the field's accessible name: not empty`);return tn(S.tooltip,"tooltip",Ir,P)},"tipOf"),y=l((S,P,U)=>{let I=S.appearance;if(I==null)return null;Ge(I,[...P,"resources"],`${U}: appearance`);let _={};for(let Y of P){let X=I[Y];if(typeof X!="string"||X.length>Di||/[^\x00-\xff]/.test(X))throw new TypeError(`${U}: appearance.${Y} is a content stream's operators (a string of Latin-1 characters, at most ${Di})`);_[Y]=X}if(I.resources!=null&&!(typeof I.resources=="string"&&/^[1-9]\d{0,9} 0 R$/.test(I.resources)))throw new TypeError(`${U}: appearance.resources is an object reference ("12 0 R") written through pdf.core`);return _.resources=I.resources??`${e.resourcesRef} 0 R`,_},"rawOf"),$=l((S,P,U)=>{let I=e.reserve(),_=`<< /Type /XObject /Subtype /Form /BBox [0 0 ${F(S.w)} ${F(S.h)}] /Resources ${U} >>`;return S.page.onWrite(()=>e.writeStream(I,_,$e(P))),I},"rawAp"),A=l((S,P)=>{if(typeof S!="string"||!/^[\x20-\x7e]{1,1024}$/.test(S)||!/\bTf\b/.test(S))throw new TypeError(`${P}: da is a default appearance ("/F1 12 Tf 0 g"): printable ASCII with a Tf operator`);return Ii(S)},"daOf"),D=l((S,P)=>{if(S==null)return"";if(!(Number.isInteger(S)&&S>=0&&S<2**31))throw new TypeError(`${P}: structParent is a whole number 0–2147483647`);if(e.tags)throw new TypeError(`${P}: structParent is for a caller's own structure tree; a tagged PDF links fields itself`);return` /StructParent ${S}`},"spOf"),N=l((S,P,U,I)=>{if(U&&P.da!=null&&P.font==null)return{t:null,da:A(P.da,I)};let _=M(S.page,P,I);return P.da!=null?{t:_.t,da:A(P.da,I)}:_},"lookText"),M=l((S,P,U)=>{let I=_t(S,P,U),_=I[0].font,Y=P.size??0;if(F(Y),!(Y===0||Y>=1&&Y<=1e3))throw new RangeError(`${U}: size is 0 (auto) or 1–1000`);let X=P.textColor??0;if(!_e(X))throw new TypeError(`${U}: textColor is a gray level, '#rrggbb', [r, g, b] or [c, m, y, k]`);let T=Ii(`${pe(_.name)} ${F(Y)} Tf ${Oe(X,!1,e)}`);return{t:{fonts:I,impl:I[0].impl,ascent:_.ascent,descent:_.descent,size:Y,color:X},da:T}},"textOf"),j=l((S,P)=>{let U=["left","center","right"].indexOf(S??"left");if(U<0)throw new TypeError(`${P}: align is left, center or right`);return U},"qOf"),O=l((S,P)=>(Me(S.readOnly,"readOnly",P)?ve.readOnly:0)|(Me(S.required,"required",P)?ve.required:0),"ffOf"),R=l((S,P)=>{if(!Array.isArray(S)||!S.length||S.length>Or)throw new TypeError(`${P}: fields is a non-empty array of field names or fields`);let U=S.map(I=>{if(ze(I)==="field")return he(I,"field",e,"field").full;if(typeof I!="string"||!I||I.length>nn*Dr)throw new TypeError(`${P}: a field is a full name ("address.city") or a field this form made`);for(let _ of I.split("."))Ur(_,P);return I});return a.push({who:P,list:U}),`[${U.map(q).join(" ")}]`},"nameList"),x=l((S,P,U,I,_)=>{let{page:Y}=S;if(n){let k=e.resource("XObject",`${U} 0 R`),B=l(()=>Y.content.op(`q 1 0 0 1 ${F(S.x)} ${F(S.H-S.y-S.h)} cm /${k} Do Q`),"draw");return e.tagged?Y.tag("Figure",B,{alt:_?`${I}: ${_}`:I}):B(),0}let X=-1,T=l(()=>{let k=Y.annotate((B,z)=>P(X,z));return e.tags&&(X=e.tags.link(Y,k,"Form")),k},"add");return e.tagged?Y.tag("Form",T,{alt:I}):T()},"place"),b=l((S,P)=>`/Type /Annot /Subtype /Widget /Rect [${F(S.x)} ${F(S.H-S.y-S.h)} ${F(S.x+S.w)} ${F(S.H-S.y)}] /P ${S.ref} 0 R /F 4${P}`,"widget"),E=l(S=>S>=0?` /StructParent ${S}`:"","sp"),C=l((S,P,U)=>ye(Object.freeze({type:"field",kind:S,name:P,...S!=="radio"?{widgetRef:U.ref}:{}}),"field",e,{kind:S,full:P,...U}),"handle"),v=l((S,P,U)=>{let I={group:S,prefix:P},_=S?` /Parent ${S.ref} 0 R`:"";return Object.freeze(pn({group(X){let T="form.group";if(U>=Dr)throw new RangeError(`${T}: at most ${Dr} levels of groups`);let k=p(I,X,T);if(n)return m(I,k,0,{kind:"group"}),v(null,k,U+1);let B={ref:e.reserve(),name:X,parent:S,kids:[]};return s.push(B),m(I,k,B.ref,{kind:"group"}),v(B,k,U+1)},textField(X,T){let k="form.textField";Ge(T,[...Dt,...It,...Nr,"value","defaultValue","multiline","password","comb","maxLen","doNotSpellCheck","doNotScroll",...Oi],k);let B=p(I,X,k),z=d(T,k),G=g(T,k,{border:1}),J=w(T,k),ee=y(T,["normal"],k),te=D(T.structParent,k),{t:ne,da:K}=N(z,T,ee,k),Q=j(T.align,k),W=Me(T.multiline,"multiline",k),Z=Me(T.password,"password",k),ae=Me(T.comb,"comb",k),ue=O(T,k)|(W?ve.multiline:0)|(Z?ve.password:0)|(ae?ve.comb:0)|(Me(T.doNotSpellCheck,"doNotSpellCheck",k)?ve.doNotSpellCheck:0)|(Me(T.doNotScroll,"doNotScroll",k)?ve.doNotScroll:0),re=T.maxLen;if(re!=null&&!(Number.isInteger(re)&&re>=1&&re<=vn))throw new RangeError(`${k}: maxLen is a whole number 1–${vn}`);if(ae&&(re==null||re>Pi||W||Z))throw new TypeError(`${k}: comb needs maxLen (1–${Pi}) and is not multiline or password`);if(Z&&(T.value!=null||T.defaultValue!=null))throw new TypeError(`${k}: a password field takes no value (readers must never store a password in the file)`);let V=l((oe,me)=>{if(oe==null)return null;if(tn(oe,me,vn,k),re!=null&&[...oe].length>re)throw new RangeError(`${k}: the ${me} is longer than maxLen (${re})`);if(!W&&/[\r\n]/.test(oe))throw new TypeError(`${k}: the ${me} has a line break: set multiline`);return ne&&Mn(ne.fonts,oe,me,k),oe},"check"),fe=V(T.value,"value"),se=V(T.defaultValue,"defaultValue"),le=ee?$(z,ee.normal,ee.resources):Ze(z.page,z.w,z.h,oe=>Pr(oe,z.w,z.h,G.f,ne,fe??"",{q:Q,multiline:W,comb:ae?re:0}));m(I,B,0,{kind:"text"});let we=x(z,oe=>`<< ${b(z,`${_} /FT /Tx /T ${q(X)}${J?` /TU ${q(J)}`:""} /Ff ${ue}${fe!=null?` /V ${q(fe)}`:""}${se!=null?` /DV ${q(se)}`:""} /DA ${K} /Q ${Q}${re!=null?` /MaxLen ${re}`:""}${G.mk?` /MK <<${G.mk} >>`:""}${G.bs} /AP << /N ${le} 0 R >>`)}${E(oe)}${te} >>`,le,J,fe??"");return we&&(I.group?I.group.kids:o).push(we),C("text",B,{ref:we})},checkbox(X,T){let k="form.checkbox";Ge(T,[...Dt,...It,"checked","value","style","color","appearance","structParent"],k);let B=p(I,X,k),z=d(T,k),G=g(T,k,{border:1}),J=w(T,k),ee=L(T.value??"Yes",k),te=H(T.style??"check",k),ne=T.color??0;Ue(ne,e,k);let K=Me(T.checked,"checked",k),Q=O(T,k),W=y(T,["on","off"],k),Z=D(T.structParent,k),ae=l(se=>W?$(z,se?W.on:W.off,W.resources):Ze(z.page,z.w,z.h,le=>{Ot(le,z.w,z.h,G.f),se&&Rr(le,z.w,z.h,te,ne)}),"draw"),ue=!n||K?ae(!0):0,re=!n||!K?ae(!1):0;m(I,B,0,{kind:"checkbox"});let V=K?ee:"/Off",fe=x(z,se=>`<< ${b(z,`${_} /FT /Btn /T ${q(X)}${J?` /TU ${q(J)}`:""} /Ff ${Q} /V ${V} /AS ${V} /MK << /CA ${q(en[te])}${G.mk} >>${G.bs} /AP << /N << ${ee} ${ue} 0 R /Off ${re} 0 R >> >>`)}${E(se)}${Z} >>`,K?ue:re,J,K?"checked":"not checked");return fe&&(I.group?I.group.kids:o).push(fe),C("checkbox",B,{ref:fe})},radioGroup(X,T){let k="form.radioGroup";Ge(T,["buttons","value","noToggleToOff","radiosInUnison","style","color",...It],k);let B=p(I,X,k),z=w(T,k),G=g(T,k,{border:1}),J=H(T.style??"circle",k),ee=T.color??0;Ue(ee,e,k);let te=Me(T.radiosInUnison,"radiosInUnison",k),ne=O(T,k)|ve.radio|(T.noToggleToOff===!1?0:ve.noToggleToOff)|(te?ve.radiosInUnison:0);Me(T.noToggleToOff,"noToggleToOff",k);let K=T.buttons;if(!Array.isArray(K)||!K.length||K.length>Fi)throw new TypeError(`${k}: buttons is an array of 1–${Fi} { page, x, y, width, height, value }`);let Q=new Map;if(f+K.length>Mi)throw new RangeError(`${k}: at most ${Mi} radio buttons a document`);let W=K.map(V=>{Ge(V,[...Dt,"value"],k);let fe=d(V,k),se=L(V.value,k),le=String(V.value);if(Q.has(se)&&(!te||Q.get(se)!==le))throw new TypeError(`${k}: two buttons have the export value ${JSON.stringify(le.slice(0,80))}${te?" written alike":" (each button has its own, unless radiosInUnison)"}`);return Q.set(se,le),{P:fe,on:se,v:le}}),Z="/Off";if(T.value!=null){let V=W.find(fe=>fe.v===T.value);if(!V)throw new TypeError(`${k}: value ${JSON.stringify(String(T.value).slice(0,80))} is not one of the buttons' values`);Z=V.on}let ae=n?null:{ref:e.reserve()},ue=W.map(({P:V,on:fe})=>{let se=fe===Z,le=l(me=>Ze(V.page,V.w,V.h,ie=>{ki(ie,V.w,V.h,G.f),me&&Rr(ie,V.w,V.h,J,ee)}),"draw"),we=!n||se?le(!0):0,oe=!n||!se?le(!1):0;return{P:V,on:fe,yes:we,off:oe,shown:se}});m(I,B,ae?ae.ref:0,{kind:"radio"}),f+=K.length;let re=ue.map(({P:V,on:fe,yes:se,off:le,shown:we})=>x(V,oe=>`<< ${b(V,` /Parent ${ae?.ref} 0 R /AS ${we?fe:"/Off"} /MK << /CA ${q(en[J])}${G.mk} >>${G.bs} /AP << /N << ${fe} ${se} 0 R /Off ${le} 0 R >> >>`)}${E(oe)} >>`,we?se:le,z,we?"selected":"not selected"));return ae&&i.push(()=>e.write(ae.ref,`<< /FT /Btn /T ${q(X)}${z?` /TU ${q(z)}`:""} /Ff ${ne} /V ${Z}${_} /Kids [${re.map(V=>`${V} 0 R`).join(" ")}] >>`)),C("radio",B,{ref:ae?.ref??0})},comboBox(X,T){return Y(X,T,!0)},listBox(X,T){return Y(X,T,!1)},button(X,T){let k="form.button";Ge(T,[...Dt,...It,...Nr,"label","icon","action","pressedBackground"],k);let B=p(I,X,k),z=d(T,k),G=w(T,k),J=g(T,k,{border:1,background:e.outputIntent==="CMYK"?[0,0,0,.25]:.75}),ee=T.label!=null?tn(T.label,"label",Ir,k):"",te=ee?M(z.page,T,k):null;te&&Mn(te.t.fonts,ee,"label",k);let ne=T.icon!=null?(he(T.icon,"image",e,"image (pdf.embedImage)"),T.icon):null;if(!ee&&!ne)throw new TypeError(`${k}: a button needs a label or an icon`);let K=T.pressedBackground??(e.outputIntent==="CMYK"?[0,0,0,.5]:.5);Ue(K,e,k);let Q="";if(T.action!=null){let V=T.action;if(Ge(V,["reset","exclude","named"],`${k}: action`),e.pdfa)throw new TypeError(`${k}: PDF/A-2 allows no action on a widget (ISO 19005-2 6.4.1: no /A or /AA; and 6.5.1 forbids ResetForm); leave the action out`);if(V.named!=null){if(V.reset!=null||V.exclude!=null||!Ri.includes(V.named))throw new TypeError(`${k}: action is { named: ${Ri.join(" | ")} } or { reset }`);Q=` /A << /Type /Action /S /Named /N /${V.named} >>`}else if(V.reset===!0)Q=" /A << /Type /Action /S /ResetForm >>";else if(V.reset!=null)Q=` /A << /Type /Action /S /ResetForm /Fields ${R(V.reset,`${k}: action.reset`)}${Me(V.exclude,"exclude",k)?" /Flags 1":""} >>`;else throw new TypeError(`${k}: action is { reset: true }, { reset: [names], exclude? } or { named }; nothing else (no JavaScript, SubmitForm, ImportData, URI or Launch)`)}let W=l(V=>Ze(z.page,z.w,z.h,fe=>Ci(fe,z.w,z.h,J.f,V,te?.t??null,ee,ne)),"face"),Z=W(J.f.bg),ae=n||e.pdfa?0:W(K),ue=ne&&!n?` /I ${Ze(z.page,100,100,V=>V.image(ne,{width:100,height:100,fit:"contain"}))} 0 R /TP ${ee?2:1}`:"";m(I,B,0,{kind:"button"});let re=x(z,V=>`<< ${b(z,`${_} /FT /Btn /T ${q(X)}${G?` /TU ${q(G)}`:""} /Ff ${O(T,k)|ve.pushButton}${te?` /DA ${te.da}`:""} /MK <<${ee?` /CA ${q(ee)}`:""}${ue}${J.mk} >>${J.bs}${Q} ${e.pdfa?`/AS /Push /AP << /N << /Push ${Z} 0 R >> >>`:`/AP << /N ${Z} 0 R /D ${ae} 0 R >>`}`)}${E(V)} >>`,Z,G,ee);return re&&(I.group?I.group.kids:o).push(re),C("button",B,{ref:re})},signature(X,T){let k="form.signature";Ge(T,[...Dt,...It,"lock"],k);let B=T.width==null&&T.height==null;if(B&&(T.x!=null||T.y!=null||T.border!=null||T.background!=null))throw new TypeError(`${k}: an invisible field (no width and height) has no x, y, border or background`);let z=p(I,X,k),G=B?T.page!=null?{page:T.page,ref:e.pageRef(he(T.page,"page",e,"page")),x:0,y:0,w:0,h:0,H:0}:null:d(T,k),J=B?null:g(T,k,{border:1}),ee=w(T,k),te="";if(T.lock!=null){let re=T.lock;Ge(re,["action","fields"],`${k}: lock`);let V=re.action??"All";if(!["All","Include","Exclude"].includes(V))throw new TypeError(`${k}: lock.action is All, Include or Exclude`);if(V==="All"!=(re.fields==null))throw new TypeError(`${k}: lock.fields is given for Include and Exclude (only)`);te=`<< /Type /SigFieldLock /Action /${V}${re.fields!=null?` /Fields ${R(re.fields,`${k}: lock.fields`)}`:""} >>`}if(B&&n)return m(I,z,0,{kind:"signature"}),C("signature",z,{ref:0,sig:{v:0}});let ne=J&&G?Ze(G.page,G.w,G.h,re=>Ot(re,G.w,G.h,J.f)):0,K=te&&!n?e.reserve():0;K&&i.push(()=>e.write(K,te)),m(I,z,0,{kind:"signature"});let Q={v:0},W=O(T,k),Z=`${_} /FT /Sig /T ${q(X)}${ee?` /TU ${q(ee)}`:""} /Ff ${W}`,ae=l((re,V)=>!Q.v&&!V&&e.signing?void 0:B?`<< /Type /Annot /Subtype /Widget /Rect [0 0 0 0]${G?` /P ${G.ref} 0 R`:""} /F 132${Z}${Q.v?` /V ${Q.v} 0 R`:""}${K?` /Lock ${K} 0 R`:""}${E(re)} >>`:`<< ${b(G,`${Z}${Q.v?` /V ${Q.v} 0 R`:""}${K?` /Lock ${K} 0 R`:""}${J?.mk?` /MK <<${J.mk} >>`:""}${J?.bs} /AP << /N ${ne} 0 R >>`)}${E(re)} >>`,"dict"),ue;if(G)ue=x(G,ae,ne,ee,"");else{let re=ue=e.reserve();i.push(()=>e.write(re,ae(-1,!0)))}return ue&&(I.group?I.group.kids:o).push(ue),C("signature",z,{ref:ue,page:G?.page,rect:[G?.x??0,G?.y??0,G?.w??0,G?.h??0],sig:Q})}}));function Y(X,T,k){let B=k?"form.comboBox":"form.listBox";Ge(T,[...Dt,...It,...Nr,"options","value",k?"editable":"multiSelect",...k?["doNotSpellCheck"]:[],...Oi],B);let z=p(I,X,B),G=T.options;if(!Array.isArray(G)||G.length>Fn)throw new RangeError(`${B}: options is an array of at most ${Fn} options`);let J=d(T,B),ee=g(T,B,{border:1}),te=w(T,B),ne=y(T,["normal"],B),K=D(T.structParent,B),{t:Q,da:W}=N(J,T,ne,B),Z=j(T.align,B),ae=0,ue=new Map,re=G.map((ge,Qe)=>{let jt=Array.isArray(ge)?ge:[ge,ge];if(jt.length!==2)throw new TypeError(`${B}: an option is a string or [export, display]`);let[ft,$t]=jt.map(Hn=>tn(Hn,"an option",Ir,B));if((ae+=ft.length+$t.length)>vi)throw new RangeError(`${B}: the options have more than ${vi} characters in all`);if(ue.has(ft))throw new TypeError(`${B}: two options have the export value ${JSON.stringify(ft.slice(0,80))}`);return ue.set(ft,Qe),{ex:ft,dp:$t}}),V=k&&Me(T.editable,"editable",B),fe=!k&&Me(T.multiSelect,"multiSelect",B),se=T.value==null?[]:Array.isArray(T.value)?T.value:[T.value];if(se.length>1&&!fe)throw new TypeError(`${B}: one value (several only with multiSelect)`);if(se.length>Fn)throw new RangeError(`${B}: at most ${Fn} values`);for(let ge of se)tn(ge,"value",vn,B);let le=se.map(ge=>ue.get(ge)??-1);if(le.some(ge=>ge<0)&&!V)throw new TypeError(`${B}: value ${JSON.stringify(String(se[le.indexOf(-1)]).slice(0,80))} is not one of the options' export values${k?" (an editable combo box takes any value)":""}`);if(new Set(se).size!==se.length)throw new TypeError(`${B}: a value is selected twice`);let we=O(T,B)|(k?ve.combo:0)|(V?ve.edit:0)|(fe?ve.multiSelect:0)|(k&&Me(T.doNotSpellCheck,"doNotSpellCheck",B)?ve.doNotSpellCheck:0),oe=se.length?le[0]>=0?re[le[0]].dp:se[0]:"",me,ie=0;if(ne)me=null;else if(k)Mn(Q.fonts,oe,"value",B),me=l(ge=>Pr(ge,J.w,J.h,ee.f,Q,oe,{q:Z}),"draw");else{for(let $t of re)Mn(Q.fonts,$t.dp,"options",B);let ge=Q.impl.lineHeight*(Q.size||12),Qe=Math.max(1,Math.floor((J.h-2*ee.f.bw)/ge)),jt=le.length?Math.min(...le):0;jt>=Qe&&(ie=jt);let ft=e.outputIntent==="CMYK"?[.3,.13,0,.14]:[.6,.75,.86];me=l($t=>Si($t,J.w,J.h,ee.f,Q,re.map(Hn=>Hn.dp),new Set(le),ie,Z,ft),"draw")}let de=ne?$(J,ne.normal,ne.resources):Ze(J.page,J.w,J.h,me);m(I,z,0,{kind:k?"combo":"list"});let Ie=`[${re.map(ge=>ge.ex===ge.dp?q(ge.ex):`[${q(ge.ex)} ${q(ge.dp)}]`).join(" ")}]`,Pe=se.length===0?"":fe?` /V [${se.map(q).join(" ")}] /I [${[...le].sort((ge,Qe)=>ge-Qe).join(" ")}]`:` /V ${q(se[0])}${le[0]>=0&&!k?` /I [${le[0]}]`:""}`,Be=x(J,ge=>`<< ${b(J,`${_} /FT /Ch /T ${q(X)}${te?` /TU ${q(te)}`:""} /Ff ${we} /Opt ${Ie}${Pe}${ie?` /TI ${ie}`:""} /DA ${W} /Q ${Z}${ee.mk?` /MK <<${ee.mk} >>`:""}${ee.bs} /AP << /N ${de} 0 R >>`)}${E(ge)}${K} >>`,de,te,k?oe:se.map((ge,Qe)=>le[Qe]>=0?re[le[Qe]].dp:ge).join(", "));return Be&&(I.group?I.group.kids:o).push(Be),C(k?"combo":"list",z,{ref:Be})}},"scope");function L(S,P){if(typeof S!="string"||!S||S.length>nn)throw new TypeError(`${P}: an export value is a non-empty string of at most ${nn} characters`);if(Ni.test(S))throw new TypeError(`${P}: an export value cannot contain control, format, bidi or separator characters`);let U=pe(S);if(U==="/Off")throw new TypeError(`${P}: "Off" is the off state, not an export value`);return U}l(L,"onName");function H(S,P){if(!Object.hasOwn(en,S))throw new TypeError(`${P}: style is one of ${Object.keys(en).join(", ")}`);return S}return l(H,"markOf"),v(null,"",0)}l(Ui,"createForm");var We=l(()=>Re("node:crypto"),"node"),jr=l((e,t)=>{if(![16,24,32].includes(e.length)||t.length!==16)throw new RangeError(`internal: AES-CBC needs a 16/24/32-byte key and a 16-byte IV, not ${e.length} and ${t.length}`);return`aes-${e.length*8}-cbc`},"cbc"),Pn=l(()=>globalThis.crypto,"web"),lt=l(e=>Pn().getRandomValues(new Uint8Array(e)),"random");function Ee(e){let t=0;for(let r of e)t+=r.length;let n=new Uint8Array(t);t=0;for(let r of e)n.set(r,t),t+=r.length;return n}l(Ee,"concat");async function Nt(e,t,n,r=!0){if(!We())return z0(e,t,n,r);let o=We().createCipheriv(jr(e,t),e,t);return o.setAutoPadding(r),Ee([o.update(n),o.final()])}l(Nt,"aesCbc");function ji(e,t,n){if(!We())return null;let r=We().createCipheriv(jr(e,t),e,t),o=new Uint8Array(16+(n.length&-16)+16);o.set(t);let s=r.update(n);return o.set(s,16),o.set(r.final(),16+s.length),o}l(ji,"sealSync");async function z0(e,t,n,r=!0){if(!r&&n.length%16)throw new RangeError("internal: unpadded AES-CBC needs whole blocks");jr(e,t);let o=await Pn().subtle.importKey("raw",e,"AES-CBC",!1,["encrypt"]),s=new Uint8Array(await Pn().subtle.encrypt({name:"AES-CBC",iv:t},o,n));return r?s:s.subarray(0,n.length)}l(z0,"aesCbcWeb");var Lr=["SHA-256","SHA-384","SHA-512"],Li=l(e=>e.replace("-","").toLowerCase(),"nodeName");async function rn(e,t){return We()?new Uint8Array(We().createHash(Li(e)).update(t).digest()):Bi(e,t)}l(rn,"sha");async function Bi(e,t){return new Uint8Array(await Pn().subtle.digest(e,t))}l(Bi,"shaWeb");function wt(e){if(We())return new Uint8Array(We().createHash("md5").update(e).digest());let t=Mt(e),n=new Uint8Array(16);for(let r=0;r<16;r++)n[r]=parseInt(t.slice(2*r,2*r+2),16);return n}l(wt,"md5");function Hi(e){if(We()){let n=We().createHash(Li(e));return{update:l(r=>{n.update(r)},"update"),digest:l(async()=>new Uint8Array(n.digest()),"digest")}}let t=[];return{update:l(n=>{t.push(n.slice())},"update"),digest:l(()=>Bi(e,Ee(t)),"digest")}}l(Hi,"hasher");var je=l(e=>{let t="";for(let n of e)t+=n.toString(16).padStart(2,"0");return t},"hex"),Rn=l(e=>{let t=new Uint8Array(e.length>>1);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(2*n,2*n+2),16);return t},"unhex");var zi=1024,_0={print:3,modify:4,copy:5,annotate:6,fillForms:9,accessibility:10,assemble:11,printHighQuality:12},Wi=Rn("28bf4e5e4e758a4164004e56fffa01082e2e00b6d0683e802f0ca9fe6453697a"),X0=new TextEncoder;function G0(e){let t=4294963392;for(let[n,r]of Object.entries(_0))e[n]&&(t|=1<<r-1);return t|0}l(G0,"permBits");function _i(e,t){let n=e.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g," ").replace(/[\u00AD\u034F\u1806\u180B-\u180D\u200B-\u200D\u2060\uFE00-\uFE0F\uFEFF]/g,"").normalize("NFKC");if(/[\p{Cc}\p{Co}\p{Cs}\p{Cn}\u0340\u0341\u06DD\u070F\u180E\u200E\u200F\u2028-\u202E\u2061-\u2063\u206A-\u206F\uFFF9-\uFFFD\u2FF0-\u2FFB]|[\u{E0001}\u{E0020}-\u{E007F}\u{1D173}-\u{1D17A}]/u.test(n))throw new TypeError(`${t}: the password has a control, private-use, unassigned or bidi character, which SASLprep (ISO 32000-2 §7.6.4.3.3) prohibits`);return X0.encode(n).subarray(0,127)}l(_i,"saslprep");function Br(e,t){let n=new Uint8Array(32),r=0;for(let o of e){let s=o.codePointAt(0);if(s<32||s>255||s>=127&&s<160)throw new TypeError(`${t}: an AES-128 password is printable Latin-1 only (use AES-256 for any Unicode password)`);r<32&&(n[r++]=s)}return n.set(Wi.subarray(0,32-r),r),n}l(Br,"pad32");function Xi(e,t){let n=new Uint8Array(256);for(let o=0;o<256;o++)n[o]=o;for(let o=0,s=0;o<256;o++)s=s+n[o]+e[o%e.length]&255,[n[o],n[s]]=[n[s],n[o]];let r=new Uint8Array(t.length);for(let o=0,s=0,i=0;o<t.length;o++)s=s+1&255,i=i+n[s]&255,[n[s],n[i]]=[n[i],n[s]],r[o]=t[o]^n[n[s]+n[i]&255];return r}l(Xi,"rc4");function Gi(e,t){let n=Xi(e,t);for(let r=1;r<=19;r++)n=Xi(e.map(o=>o^r),n);return n}l(Gi,"rc4x20");async function On(e,t,n){let r=await rn("SHA-256",Ee([e,t,n])),o=new Uint8Array(0);for(let s=0;s<64||o[o.length-1]>s-32;s++){let i=Ee([e,r,n]),a=new Uint8Array(i.length*64);for(let f=0;f<64;f++)a.set(i,f*i.length);o=await Nt(r.subarray(0,16),r.subarray(16,32),a,!1);let c=0;for(let f=0;f<16;f++)c+=o[f];r=await rn(["SHA-256","SHA-384","SHA-512"][c%3],o)}return r.subarray(0,32)}l(On,"hash2B");async function W0(e,t,n,r,o,s=lt(36)){let i=new Uint8Array(16),a=Ee([await On(e,s.subarray(0,8),new Uint8Array(0)),s.subarray(0,16)]),c=await Nt(await On(e,s.subarray(8,16),new Uint8Array(0)),i,n,!1),f=Ee([await On(t,s.subarray(16,24),a),s.subarray(16,32)]),h=await Nt(await On(t,s.subarray(24,32),a),i,n,!1),u=new Uint8Array(16);new DataView(u.buffer).setInt32(0,r,!0),u.set([255,255,255,255,o?84:70,97,100,98],4),u.set(s.subarray(32,36),12);let p=await Nt(n,i,u,!1);return{U:a,UE:c,O:f,OE:h,Perms:p}}l(W0,"r6");function V0(e,t,n,r,o,s=lt(16)){let i=wt(t);for(let u=0;u<50;u++)i=wt(i);let a=Gi(i,e),c=new Uint8Array(4);new DataView(c.buffer).setInt32(0,n,!0);let f=wt(Ee([e,a,c,r,o?new Uint8Array(0):Uint8Array.of(255,255,255,255)]));for(let u=0;u<50;u++)f=wt(f);let h=Ee([Gi(f,wt(Ee([Wi,r]))),s]);return{O:a,U:h,key:f}}l(V0,"r4");function Vi(e,t){let n="createPdf: encrypt";if(t.pdfa)throw new TypeError(`${n}: PDF/A forbids encryption (ISO 19005-2 §6.1.3): a PDF/A file must open in any reader, forever, without a password`);if(e===!0&&(e={}),e==null||typeof e!="object")throw new TypeError(`${n} is { userPassword, ownerPassword, algorithm, permissions, encryptMetadata }`);for(let x of Object.keys(e))if(!["userPassword","ownerPassword","algorithm","permissions","encryptMetadata"].includes(x))throw new TypeError(`${n}: unknown option ${JSON.stringify(x.slice(0,40))} (userPassword, ownerPassword, algorithm, permissions, encryptMetadata)`);let r=e.algorithm??"aes-256";if(typeof r=="string"&&/rc4|40|v1|v2|r2|r3/i.test(r))throw new TypeError(`${n}: RC4 (40- and 128-bit) is refused: it is broken (its key stream is biased and its 40-bit keys are brute-forced in minutes), so it would only look like protection. Use 'aes-256' (the default) or 'aes-128' for old readers`);if(r!=="aes-256"&&r!=="aes-128")throw new TypeError(`${n}: algorithm is 'aes-256' (default) or 'aes-128'`);let o=l((x,b)=>{if(typeof x!="string")throw new TypeError(`${n}: ${b} is a string`);if(x.length>zi)throw new RangeError(`${n}: ${b} is at most ${zi} characters (the PDF keeps ${r==="aes-256"?"127 bytes":"32 characters"})`);return x},"pw"),s=o(e.userPassword??"","userPassword");if(e.ownerPassword==="")throw new TypeError(`${n}: an empty ownerPassword would give everyone full access; leave it out for a random one (nobody can then change the permissions)`);let i=e.ownerPassword==null?null:o(e.ownerPassword,"ownerPassword"),a={print:!0,printHighQuality:!0,modify:!0,copy:!0,annotate:!0,fillForms:!0,accessibility:!0,assemble:!0};if(e.permissions!=null){if(typeof e.permissions!="object")throw new TypeError(`${n}: permissions is an object of booleans`);for(let[x,b]of Object.entries(e.permissions)){if(!Object.hasOwn(a,x))throw new TypeError(`${n}: permissions: unknown ${JSON.stringify(x.slice(0,40))} (${Object.keys(a).join(", ")})`);if(typeof b!="boolean")throw new TypeError(`${n}: permissions.${x} is true or false`);a[x]=b}}t.tagged&&!a.accessibility&&(a.accessibility=!0,t.warn("encrypt: the accessibility permission was turned back on: PDF/UA (ISO 14289-1 §7.16) needs assistive technology to read the content")),i!=null&&i===s&&s!==""&&t.warn("encrypt: the owner password is the user password, so whoever opens the file has full access and the permissions do not apply");let c=e.encryptMetadata??!0;if(typeof c!="boolean")throw new TypeError(`${n}: encryptMetadata is true or false`);let f=G0(a),h=r==="aes-256",u=h?_i(s,`${n}: userPassword`):Br(s,`${n}: userPassword`),p=i==null?h?lt(32).map(x=>33+x%94):Br(String.fromCharCode(...lt(32).map(x=>33+x%94)),n):h?_i(i,`${n}: ownerPassword`):Br(i,`${n}: ownerPassword`),m=t.id??je(lt(16)),d=new Uint8Array(0),g=(async()=>{let x=c?"":" /EncryptMetadata false";if(h){d=lt(32);let E=await W0(u,p,d,f,c);return`<< /Filter /Standard /V 5 /R 6 /Length 256 /CF << /StdCF << /Type /CryptFilter /CFM /AESV3 /AuthEvent /DocOpen /Length 32 >> >> /StmF /StdCF /StrF /StdCF /O <${je(E.O)}> /U <${je(E.U)}> /OE <${je(E.OE)}> /UE <${je(E.UE)}> /P ${f} /Perms <${je(E.Perms)}>${x} >>`}let b=V0(u,p,f,Rn(m),c);return d=b.key,`<< /Filter /Standard /V 4 /R 4 /Length 128 /CF << /StdCF << /Type /CryptFilter /CFM /AESV2 /AuthEvent /DocOpen /Length 16 >> >> /StmF /StdCF /StrF /StdCF /O <${je(b.O)}> /U <${je(b.U)}> /P ${f}${x} >>`})();g.catch(()=>{});let w=l(x=>h?d:wt(Ee([d,Uint8Array.of(x&255,x>>8&255,x>>16&255,0,0),Uint8Array.of(115,65,108,84)])),"keyOf"),y=new Uint8Array(0),$=0,A=l(()=>($+16>y.length&&(y=lt(4096),$=0),y.subarray($,$+=16)),"iv"),D=l((x,b)=>{let E=A();return ji(x,E,b)??Nt(x,E,b).then(C=>Ee([E,C]))},"seal"),N=!1;g.then(()=>{N=!0},()=>{});let M=l(x=>new Error(`An object's ${x} cannot be encrypted: it would be left in the clear, so nothing is written`),"bad"),j=l(x=>{let b=[];for(let E=0;E<x.length;){let C=x.charCodeAt(E);if(C===60){if(x.charCodeAt(E+1)===60){E+=2;continue}let v=x.indexOf(">",E);if(v<0)throw M("unterminated hex string");let L=x.slice(E+1,v).replace(/[\0\t\n\f\r ]/g,"");if(!/^[0-9A-Fa-f]*$/.test(L))throw M("hex string with a character that is not a hex digit");L.length&1&&(L+="0"),b.push([E,v+1,Rn(L)]),E=v+1}else if(C===40){let v=[],L=1,H=E+1;for(;H<x.length&&L;H++){let S=x.charCodeAt(H);if(S===92){S=x.charCodeAt(++H);let P={110:10,114:13,116:9,98:8,102:12}[S];if(P!==void 0)v.push(P);else if(S>=48&&S<=55){let U=S-48;for(let I=0;I<2&&x.charCodeAt(H+1)>=48&&x.charCodeAt(H+1)<=55;I++)U=U*8+x.charCodeAt(++H)-48;v.push(U&255)}else if(S===13)x.charCodeAt(H+1)===10&&H++;else{if(S>255)throw M("literal string with a character past 0xFF");S!==10&&H<x.length&&v.push(S)}continue}if(S===40)L++;else if(S===41&&!--L)break;if(S===13&&(x.charCodeAt(H+1)===10&&H++,S=10),S>255)throw M("literal string with a character past 0xFF");v.push(S)}if(L)throw M("unterminated literal string");b.push([E,H+1,Uint8Array.from(v)]),E=H+1}else{if(C===37)throw M("comment");if(C===41||C===62){if(C===41||x.charCodeAt(E+1)!==62)throw M(`unbalanced ${x[E]}`);E+=2}else E++}}return b},"strings"),O=l((x,b)=>{if(!/[<(%)]/.test(b))return b;let E=j(b);if(!E.length)return b;let C=w(x),v=[],L=null,H=0;for(let[P,U,I]of E){let _=D(C,I);v.push(b.slice(H,P),_ instanceof Uint8Array?`<${je(_)}>`:""),_ instanceof Uint8Array||((L??=[])[v.length-1]=_),H=U}if(v.push(b.slice(H)),!L)return v.join("");let S=L;return Promise.all(S.map((P,U)=>P.then(I=>{v[U]=`<${je(I)}>`}))).then(()=>v.join(""))},"dictNow"),R={id:m,ref:0,setup:g,trailer:"",extensions:h?"<< /ADBE << /BaseVersion /1.7 /ExtensionLevel 8 >> >>":"",dict(x,b){return x===R.ref?b:!c&&/^<< \/Type \/Metadata\b/.test(b)&&!b.includes("/Filter")?b.replace(/>>\s*$/,"/Filter /Crypt /DecodeParms << /Name /Identity >> >>"):N?O(x,b):g.then(()=>O(x,b))},stream(x,b,E){return!c&&/\/Type\s*\/Metadata\b/.test(E)?b:N?D(w(x),b):g.then(()=>D(w(x),b))}};return R}l(Vi,"encryptor");var q0=l(e=>e<128?[e]:e<256?[129,e]:e<65536?[130,e>>8,e&255]:e<16777216?[131,e>>16,e>>8&255,e&255]:[132,e>>>24,e>>16&255,e>>8&255,e&255],"lenBytes"),Ve=l((e,...t)=>{let n=Ee(t);return Ee([Uint8Array.of(e,...q0(n.length)),n])},"tlv"),Ae=l((...e)=>Ve(48,...e),"seq"),on=l((...e)=>Ve(49,...[...e].sort(J0)),"set"),yt=l((e,...t)=>Ve(160+e,...t),"ctx"),Dn=l(e=>Ve(4,e),"octets"),qi=Uint8Array.of(5,0),In=l(e=>{let t=[];do t.unshift(e&255),e=Math.floor(e/256);while(e>0);return t[0]&128&&t.unshift(0),Ve(2,Uint8Array.from(t))},"int");function Le(e){let t=e.split(".").map(Number),n=[40*t[0]+t[1]];for(let r of t.slice(2)){let o=[r&127];for(let s=Math.floor(r/128);s>0;s=Math.floor(s/128))o.unshift(s&127|128);n.push(...o)}return Ve(6,Uint8Array.from(n))}l(Le,"oid");function Ji(e){let t=e.toISOString().replace(/\D/g,"").slice(0,14),n=e.getUTCFullYear();return n>=1950&&n<2050?Ve(23,new TextEncoder().encode(`${t.slice(2)}Z`)):Ve(24,new TextEncoder().encode(`${t}Z`))}l(Ji,"time");function J0(e,t){for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e[n]-t[n];return e.length-t.length}l(J0,"cmp");function Nn(e,t,n=e.length){if(t+2>n)throw new RangeError("DER: truncated");let r=e[t];if((r&31)===31)throw new RangeError("DER: multi-byte tags are not supported");let o=e[t+1],s=t+2;if(o===128)throw new RangeError("DER: an indefinite length is not DER");if(o>128){let a=o&127;if(a>4||s+a>n)throw new RangeError("DER: a bad length");o=0;for(let c=0;c<a;c++)o=o*256+e[s+c];s+=a}let i=s+o;if(i>n)throw new RangeError("DER: a length past the end of its value");return{tag:r,start:s,end:i,whole:e.subarray(t,i)}}l(Nn,"read");function Un(e,t){let n=[];for(let r=t.start;r<t.end;){let o=Nn(e,r,t.end);n.push(o),r=o.end}return n}l(Un,"kids");var Ut=l(()=>Re("node:crypto"),"node"),jn=10,Hr=64*1024,Ki=16*1024,K0=64*1024,Z0={"SHA-256":"2.16.840.1.101.3.4.2.1","SHA-384":"2.16.840.1.101.3.4.2.2","SHA-512":"2.16.840.1.101.3.4.2.3"},Y0={"SHA-256":"1.2.840.113549.1.1.11","SHA-384":"1.2.840.113549.1.1.12","SHA-512":"1.2.840.113549.1.1.13"},Q0={"SHA-256":"1.2.840.10045.4.3.2","SHA-384":"1.2.840.10045.4.3.3","SHA-512":"1.2.840.10045.4.3.4"},Yi="1.2.840.113549.1.7.2",Zi="1.2.840.113549.1.7.1",sn=l((e,t)=>Ae(Le(e),on(t)),"attr"),Ln=l(e=>Ae(Le(Z0[e])),"algId");function Qi(e,t){let n=Array.isArray(e)?e:[e],r=[];for(let o of n){if(o instanceof Uint8Array)r.push(o);else if(typeof o=="string"){if(o.length>jn*Hr*2)throw new RangeError(`${t}: certs is too long`);for(let s of o.matchAll(/-----BEGIN CERTIFICATE-----([A-Za-z0-9+/=\s]+?)-----END CERTIFICATE-----/g))if(r.push(Uint8Array.from(atob(s[1].replace(/\s+/g,"")),i=>i.charCodeAt(0))),r.length>jn)break}else throw new TypeError(`${t}: certs is PEM text, DER bytes or an array of them (the signer's certificate first)`);if(r.length>jn)throw new RangeError(`${t}: at most ${jn} certificates`)}if(!r.length)throw new TypeError(`${t}: no certificate (PEM "-----BEGIN CERTIFICATE-----" or DER bytes)`);return r.map(o=>{if(o.length>Hr)throw new RangeError(`${t}: a certificate is at most ${Hr} bytes`);try{let s=Nn(o,0);if(s.tag!==48||s.end!==o.length)throw new Error;let i=Un(o,s)[0],a=Un(o,i),c=a[0].tag===160?1:0;if(a[c].tag!==2||a[c+2].tag!==48)throw new Error;return{der:o,serial:a[c].whole,issuer:a[c+2].whole}}catch{throw new TypeError(`${t}: a certificate is not a DER X.509 certificate`)}})}l(Qi,"readCerts");function ea(e){let t="cmsSigner";if(e==null||typeof e.sign!="function")throw new TypeError(`${t}: sign(bytes, hash) is a function giving the raw signature`);if(!["rsa","rsa-pss","ecdsa"].includes(e.keyAlgorithm))throw new TypeError(`${t}: keyAlgorithm is 'rsa' (PKCS#1 v1.5), 'rsa-pss' or 'ecdsa'`);let n=Qi(e.certs,t),r=e.keyAlgorithm,o=e.sign;return async s=>{let i=s.hash,a=n[0],c=on(sn("1.2.840.113549.1.9.3",Le(Zi)),sn("1.2.840.113549.1.9.4",Dn(s.digest)),sn("1.2.840.113549.1.9.16.2.47",Ae(Ae(Ae(Dn(await rn("SHA-256",a.der)),Ae(Ae(yt(4,a.issuer)),a.serial))))),...s.subFilter==="adbe.pkcs7.detached"?[sn("1.2.840.113549.1.9.5",Ji(s.date))]:[]),f=await o(c,i);if(!(f instanceof Uint8Array)||!f.length||f.length>Ki)throw new TypeError(`${t}: sign() gave ${f instanceof Uint8Array?`${f.length} bytes`:"no bytes"}: a signature is 1–${Ki} bytes`);s.signal?.throwIfAborted();let h=r==="ecdsa"?Ae(Le(Q0[i])):r==="rsa"?Ae(Le(Y0[i]),qi):Ae(Le("1.2.840.113549.1.1.10"),Ae(yt(0,Ln(i)),yt(1,Ae(Le("1.2.840.113549.1.1.8"),Ln(i))),yt(2,In({"SHA-256":32,"SHA-384":48,"SHA-512":64}[i])))),u=new Uint8Array(0);if(s.timestamp){let d=await s.timestamp(f);zr(d,K0,"timestamp: the TimeStampToken"),u=yt(1,sn("1.2.840.113549.1.9.16.2.14",d))}let p=Ae(In(1),Ae(a.issuer,a.serial),Ln(i),Ee([Uint8Array.of(160),c.subarray(1)]),h,Dn(f),u),m=Ve(160,...n.map(d=>d.der).sort((d,g)=>{for(let w=0;w<Math.min(d.length,g.length);w++)if(d[w]!==g[w])return d[w]-g[w];return d.length-g.length}));return Ae(Le(Yi),yt(0,Ae(In(1),on(Ln(i)),Ae(Le(Zi)),m,on(p))))}}l(ea,"cmsSigner");function zr(e,t,n){if(!(e instanceof Uint8Array))throw new TypeError(`${n} is not bytes (a Uint8Array)`);if(e.length>t)throw new RangeError(`${n} is ${e.length} bytes, more than ${t}`);try{let r=Nn(e,0);if(r.tag!==48||r.end!==e.length)throw new Error;let o=Un(e,r);if(o[0].tag!==6||!ec(o[0].whole,Le(Yi))||o[1]?.tag!==160)throw new Error}catch{throw new TypeError(`${n} is not a DER CMS ContentInfo of SignedData`)}}l(zr,"checkContentInfo");var ec=l((e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]),"eq");function tc(e){let t="nodeSigner";if(!Ut())throw new TypeError(`${t} needs Node (node:crypto); elsewhere use cmsSigner with WebCrypto or your HSM`);if(e==null||typeof e!="object")throw new TypeError(`${t}: options are { key, certs, pss }`);let n;try{n=e.key instanceof Ut().KeyObject?e.key:Ut().createPrivateKey(e.key)}catch{throw new TypeError(`${t}: key is not a private key (PEM, DER, { key, passphrase } or a KeyObject)`)}if(n.type!=="private")throw new TypeError(`${t}: key is not a private key`);let r=n.asymmetricKeyType,o=n.asymmetricKeyDetails?.namedCurve;if(!["rsa","rsa-pss","ec"].includes(r)||r==="ec"&&!["prime256v1","secp384r1"].includes(o))throw new TypeError(`${t}: the key is RSA or ECDSA P-256 / P-384`);let s=Qi(e.certs,t),i=!1;try{i=new(Ut()).X509Certificate(s[0].der).checkPrivateKey(n)}catch{}if(!i)throw new TypeError(`${t}: the key does not match the first certificate (the signer's)`);let a=r==="rsa-pss"||r==="rsa"&&!!e.pss;return ea({certs:s.map(c=>c.der),keyAlgorithm:r==="ec"?"ecdsa":a?"rsa-pss":"rsa",sign:l((c,f)=>new Uint8Array(Ut().sign(f.replace("-","").toLowerCase(),c,a?{key:n,padding:Ut().constants.RSA_PKCS1_PSS_PADDING,saltLength:{"SHA-256":32,"SHA-384":48,"SHA-512":64}[f]}:{key:n,dsaEncoding:"der"})),"sign")})}l(tc,"nodeSigner");var nc=16*1024,_r=1024*1024,rc=Uint8Array.of(6,11,42,134,72,134,247,13,1,9,16,2,14),oc=l((e,t)=>{e:for(let n=0;n+t.length<=e.length;n++){for(let r=0;r<t.length;r++)if(e[n+r]!==t[r])continue e;return!0}return!1},"has"),ta=["signer","reason","location","contactInfo","name","date","certify","timestamp","subFilter","reserve"];function na(e,t,n){let r=!1;return l(function(s,i){let a="pdf.sign";if(!n.hash)throw new TypeError(`${a}: create the PDF with { sign: true } (or { sign: { hash: 'SHA-384' } }): every byte is hashed as it streams out, from the first`);if(r)throw new Error(`${a}: one signature per document as it is created (more need an incremental update)`);if(i==null||typeof i!="object")throw new TypeError(`${a}: options are { signer, reason, location, contactInfo, name, date, certify, timestamp, subFilter, reserve }`);for(let $ of Object.keys(i))if(!ta.includes($))throw new TypeError(`${a}: unknown option ${JSON.stringify($.slice(0,40))} (${ta.join(", ")})`);if(typeof i.signer!="function")throw new TypeError(`${a}: signer is an async function ({ digest, hash, … }) → CMS bytes (nodeSigner and cmsSigner make one)`);if(i.timestamp!=null&&typeof i.timestamp!="function")throw new TypeError(`${a}: timestamp is an async function (signature value) → RFC 3161 TimeStampToken bytes`);let c=i.subFilter??"ETSI.CAdES.detached";if(c!=="ETSI.CAdES.detached"&&c!=="adbe.pkcs7.detached")throw new TypeError(`${a}: subFilter is 'ETSI.CAdES.detached' (PAdES, the default) or 'adbe.pkcs7.detached'`);let f=i.reserve??nc;if(!(Number.isInteger(f)&&f>=1024&&f<=_r))throw new RangeError(`${a}: reserve (bytes for the CMS) is a whole number 1024–${_r}`);let h=i.date??n.when;if(!(h instanceof Date)||isNaN(+h))throw new TypeError(`${a}: date is a valid Date`);let u=i.certify;if(u!=null&&![1,2,3].includes(u))throw new TypeError(`${a}: certify is 1 (no changes), 2 (form filling and signing) or 3 (also annotations)`);let p="";for(let[$,A]of[["name","Name"],["reason","Reason"],["location","Location"],["contactInfo","ContactInfo"]]){let D=i[$];if(D!=null){if(typeof D!="string"||D.length>4096)throw new TypeError(`${a}: ${$} is a string of at most 4096 characters`);p+=` /${A} ${q(D)}`}}let m;if(ze(s)==="field"||s?.type==="field")m=he(s,"field",e,"field");else if(s!=null&&typeof s=="object"&&typeof s.name=="string"){let{name:$,...A}=s;m=he(t.signature($,A),"field",e,"field")}else throw new TypeError(`${a}: field is a signature field from pdf.form.signature, or { name, page, x, y, width, height } to make one`);if(m.kind!=="signature")throw new TypeError(`${a}: ${JSON.stringify(m.full)} is not a signature field`);if(!m.ref||!m.sig)throw new TypeError(`${a}: a flattened form has no fields to sign`);if(m.sig.v)throw new Error(`${a}: that field is signed already`);r=!0;let d=e.reserve();m.sig.v=d,e.sigFlags=3;let g=u?` /Reference [<< /Type /SigRef /TransformMethod /DocMDP /TransformParams << /Type /TransformParams /P ${u} /V /1.2 >> >>]`:"";u&&e.catalog("Perms",`<< /DocMDP ${d} 0 R >>`);let w=i.signer,y=i.timestamp;return e.last={n:d,size:f,head:`<< /Type /Sig /Filter /Adobe.PPKLite /SubFilter /${c} ${fn} /Contents `,after:` /M ${ht(h)}${p}${g} >>`,async sign($){let A=await an(Promise.resolve().then(()=>w({digest:$,hash:n.hash,subFilter:c,date:h,timestamp:y??void 0,signal:e.signal})),e.signal);if(A instanceof Uint8Array&&A.length>f)throw new RangeError(`${a}: the signer's CMS is ${A.length} bytes, more than the ${f} reserved: pass a larger reserve (at most ${_r})`);if(zr(A,f,`${a}: the signer's CMS`),y&&!oc(A,rc))throw new Error(`${a}: a timestamp was asked for but the signer's CMS has no id-aa-timeStampToken (nodeSigner and cmsSigner add it; a custom signer must call r.timestamp)`);return A}},Promise.resolve()},"sign")}l(na,"createSigning");function ra(e,t={}){let n=At(t);if(n==null||typeof n!="object")throw new TypeError("createPdf: options are an object");if(n.tagged&&(n.title==null||n.title===""))throw new TypeError("createPdf: a tagged PDF (PDF/UA) needs a title");if(n.creationDate!=null&&!(n.creationDate instanceof Date&&!isNaN(+n.creationDate)))throw new TypeError("createPdf: creationDate must be a valid Date");if(n.id!=null&&!/^[0-9a-f]{32}$/i.test(n.id))throw new TypeError("createPdf: id is 32 hex digits");for(let C of["title","author","subject","keywords"])if(n[C]!=null&&(typeof n[C]!="string"||n[C].length>65536))throw new TypeError(`createPdf: ${C} is a string of at most 65,536 characters`);if(n.objectStreamLevel!=null&&!(Number.isInteger(n.objectStreamLevel)&&n.objectStreamLevel>=0&&n.objectStreamLevel<=9))throw new TypeError("createPdf: objectStreamLevel is a zlib level, an integer 0–9 (default 6)");if(n.metadata!=null&&typeof n.metadata!="boolean")throw new TypeError("createPdf: metadata is true (the default: an XMP stream) or false (Info only)");if(n.metadata===!1&&(n.pdfa||n.tagged))throw new TypeError("createPdf: metadata: false cannot be combined with pdfa or tagged: PDF/A and PDF/UA require the XMP metadata stream");let r=$o(n.pdfa,n.tagged);n.signal?.throwIfAborted();let o=new AbortController,s=l(()=>o.abort(n.signal?.reason),"onAbort");n.signal?.addEventListener("abort",s,{once:!0});let i=Number(n.timeoutMs),a=i>0?setTimeout(()=>o.abort(Object.assign(new Error(`The PDF took longer than ${i} ms (timeoutMs)`),{name:"TimeoutError",code:"ETIMEDOUT"})),i):null;a?.unref?.();let c=l(()=>{a&&clearTimeout(a),n.signal?.removeEventListener("abort",s)},"cleanup"),f=[],h=n.encrypt!=null&&n.encrypt!==!1?Vi(n.encrypt,{id:n.id,tagged:!!n.tagged,pdfa:!!n.pdfa,warn:l(C=>f.push(C),"warn")}):null,u=n.sign==null||n.sign===!1?null:n.sign===!0?"SHA-256":typeof n.sign=="object"?n.sign.hash??"SHA-256":"";if(u!=null&&!Lr.includes(u))throw new TypeError(`createPdf: sign is true or { hash: ${Lr.map(C=>`'${C}'`).join(" | ")} }`);let p=Gr(e),m=new Date(Math.floor((n.creationDate??new Date).getTime()/1e3)*1e3),d=Yr(p,{compress:n.compress!==!1,objectStreamLevel:n.objectStreamLevel,pdfa:!!n.pdfa,pdfaLevel:r,tagged:!!n.tagged,metadata:n.metadata!==!1,signal:o.signal,encrypt:h,hash:u?Hi(u):null,info:{title:n.title,author:n.author,subject:n.subject,keywords:n.keywords,creationDate:m},id:n.id});n.tagged&&(d.tags=Gs(d,typeof n.tagged=="object"?n.tagged:{})),n.pdfa&&wi(d,n.pdfa),h&&(h.ref=d.reserve(),h.trailer=` /Encrypt ${h.ref} 0 R`,h.extensions&&d.catalog("Extensions",h.extensions),d.onFinish(async()=>d.write(h.ref,await h.setup)));for(let C of f)d.warn(C);let g=fi(d),w=di(d),y=mi(d),$=Ui(d,n.form??{}),A=na(d,$,{hash:u,when:m}),D=bi(d,m),N=Ai(d,D),M=Ns(d),j=new Map,O=l(C=>C.catch(v=>{let L=o.signal.aborted?o.signal.reason:v;throw c(),p.abort(L),L}),"guard"),R=!1,x=l(()=>{if(o.signal.aborted&&(c(),p.abort(o.signal.reason)),o.signal.throwIfAborted(),d.failed)throw d.failed},"live"),b=l(()=>{if(x(),R)throw new Error("The PDF has ended")},"open"),E=l((C={})=>{let{width:v=595.28,height:L=841.89}=C;if(x(),!(v>0&&L>0&&v<=14400&&L<=14400))throw new RangeError("addPage: width and height are 1–14400 points");let H=new Map;Ti({width:v,height:L,doc:d,entries:H},C);let S=new Pt(d,d.newPage({height:L}),v,L);for(let[U,I]of H)S.entries.set(U,I);d.opened(S);let P=S.end.bind(S);return S.end=()=>(x(),O(P())),S},"addPage");return pn({core:d,standardFont(C){x();let v=j.get(C);return v||j.set(C,v=Ks(d,C)),v},async embedFont(C,v){return x(),ii(d,C,v)},async embedImage(C,v){return b(),ls(d,C,v)},spotColor(C,v){return b(),to(d,C,v)},async iccColorSpace(C){return b(),no(d,C)},addPage:E,outline(C){x(),g(C)},destination(C,v,L){b(),vt(d).define(C,v,L)},pageLabels(C){b(),w(C)},viewer(C){b(),y(C)},form:$,sign(C,v){return b(),A(C,v)},async attach(C,v){return b(),D(C,v)},async facturX(C,v){return b(),N(C,v)},layer(C,v){return b(),M(C,v)},async end(){x(),R=!0;let C=await O(d.finish(()=>E()));return await O(p.close()),c(),C}})}l(ra,"createPdf");async function sc(e,t){let n=[],r=0,o=ra({write(a){n.push(a),r+=a.length}},t);await e(o),await o.end();let s=new Uint8Array(r),i=0;for(let a of n)s.set(a,i),i+=a.length;return s}l(sc,"toBytes");function ic(e){if(!(e instanceof Uint8Array))throw new TypeError("readFont: bytes must be a Uint8Array");let t;try{t=Kt(e)}catch(n){throw n instanceof RangeError?new TypeError("Broken font: a read ran past the end of the file"):n}return{numGlyphs:t.numGlyphs,postscriptName:t.postscriptName,fsType:t.fsType,unitsPerEm:t.unitsPerEm,ascent:t.ascent,descent:t.descent,isCFF:t.cff,advance:t.advance,hasGlyph:l(n=>t.glyphFor(n)!==0,"hasGlyph"),glyphForCodePoint:t.glyphFor}}l(ic,"readFont");var Bn=class{static{l(this,"Problem")}constructor(t){this.m=t}},xe=l(e=>{throw new Bn(e)},"fail");function ac(e){try{return e instanceof Uint8Array?(cc(e),null):"it is not a byte array"}catch(t){return t instanceof Bn?t.m:"it could not be read"}}l(ac,"checkSubset");function cc(e){let t=e.byteLength;t<12&&xe("it is too short to be a font");let n=new DataView(e.buffer,e.byteOffset,t),r=n.getUint32(0);r!==65536&&r!==1953658213&&r!==1330926671&&xe("it is not a TrueType or OpenType font");let o=n.getUint16(4);12+16*o>t&&xe("its table directory runs past the end");let s=new Map;for(let f=0;f<o;f++){let h=12+16*f,u=String.fromCharCode(e[h],e[h+1],e[h+2],e[h+3]),p=n.getUint32(h+8),m=n.getUint32(h+12);p+m>t&&xe(`its ${u.trim()} table runs past the end`),s.set(u,{off:p,length:m})}let i=s.get("glyf"),a=s.get("loca");if(i||a){let f=s.get("head"),h=s.get("maxp");(!i||!a||!f||!h)&&xe("glyf, loca, head or maxp is missing"),(f.length<54||h.length<6)&&xe("head or maxp is too short");let u=n.getUint16(h.off+4),p=n.getInt16(f.off+50)===1,m=p?4:2;a.length<(u+1)*m&&xe("loca is too short for the glyph count"),u>0&&i.length===0&&xe("glyf is empty but the font has glyphs");let d=0;for(let g=0;g<=u;g++){let w=p?n.getUint32(a.off+4*g):2*n.getUint16(a.off+2*g);w<d&&xe(`loca goes backwards at entry ${g}`),w>i.length&&xe(`loca entry ${g} lies beyond glyf`),d=w}}let c=s.get("CFF ")??s.get("CFF2");if(c){let f=c.off,h=f+c.length;c.length<4&&xe("the CFF table is too short");let u=e[f],p=e[f+2];if(u!==(s.has("CFF ")?1:2)&&xe(`the CFF header version is ${u}`),(p<4||p>c.length)&&xe(`the CFF header size ${p} is out of range`),s.has("CFF ")){let m=f+p;for(let d of["Name","Top DICT"]){m+2>h&&xe(`the CFF ${d} INDEX lies outside the table`);let g=n.getUint16(m);if(!g){m+=2;continue}m+3>h&&xe(`the CFF ${d} INDEX lies outside the table`);let w=e[m+2];(w<1||w>4)&&xe(`the CFF ${d} INDEX has offset size ${w}`);let y=m+3+g*w;y+w>h&&xe(`the CFF ${d} INDEX offsets lie outside the table`);let $=0;for(let A=0;A<w;A++)$=$*256+e[y+A];m=y+w-1+$,m>h&&xe(`the CFF ${d} INDEX data runs past the table`)}}}}l(cc,"check");export{Pt as Page,Js as STANDARD_NAMES,ac as checkSubset,ea as cmsSigner,wa as cmyk,ra as createPdf,tc as nodeSigner,ic as readFont,ka as svgPathOps,sc as toBytes};
108
+ //# sourceMappingURL=write.js.map